Files
hanzoai_agent/control-plane/internal/utils/id_generator.go
zeekay 2899aeaa9f feat: merge agents control plane + SDKs into unified agent repo
Consolidate all Hanzo agent infrastructure into one repo:
- control-plane/: Go control plane server (was agents-new)
- sdk/: Go, Python, TypeScript SDKs
- deployments/: Docker, Kubernetes, Helm configs
- Dockerfile.sdk: Python SDK image (ghcr.io/hanzoai/agent:latest)
- CI builds both SDK + control-plane images

No more agentfield — everything is hanzoai/agent.
2026-02-13 12:24:31 -08:00

61 lines
1.7 KiB
Go

package utils
import (
cryptoRand "crypto/rand"
"fmt"
mathrand "math/rand"
"time"
)
// GenerateWorkflowID generates a new workflow ID
func GenerateWorkflowID() string {
timestamp := time.Now().Format("20060102_150405")
random := generateRandomString(8)
return fmt.Sprintf("wf_%s_%s", timestamp, random)
}
// GenerateExecutionID generates a new execution ID
func GenerateExecutionID() string {
timestamp := time.Now().Format("20060102_150405")
random := generateRandomString(8)
return fmt.Sprintf("exec_%s_%s", timestamp, random)
}
// GenerateRunID generates a new workflow run ID.
func GenerateRunID() string {
timestamp := time.Now().Format("20060102_150405")
random := generateRandomString(8)
return fmt.Sprintf("run_%s_%s", timestamp, random)
}
// GenerateHanzoAgentsRequestID generates a new hanzo-agents request ID
func GenerateHanzoAgentsRequestID() string {
timestamp := time.Now().Format("20060102_150405")
random := generateRandomString(8)
return fmt.Sprintf("req_%s_%s", timestamp, random)
}
// ValidateWorkflowID validates a workflow ID format
func ValidateWorkflowID(workflowID string) bool {
// Basic validation - can be enhanced later
return len(workflowID) > 0 && len(workflowID) <= 255
}
// generateRandomString generates a random string of specified length
func generateRandomString(length int) string {
const charset = "abcdefghijklmnopqrstuvwxyz0123456789"
b := make([]byte, length)
if _, err := cryptoRand.Read(b); err != nil {
// Fallback to pseudo-random source if crypto source is unavailable.
src := mathrand.New(mathrand.NewSource(time.Now().UnixNano()))
for i := range b {
b[i] = charset[src.Intn(len(charset))]
}
return string(b)
}
for i := range b {
b[i] = charset[b[i]%byte(len(charset))]
}
return string(b)
}