mirror of
https://github.com/hanzoai/agent.git
synced 2026-09-11 21:08:51 +00:00
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.
38 lines
1013 B
Go
38 lines
1013 B
Go
package storage
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"log"
|
|
"strings"
|
|
)
|
|
|
|
// safeJSONRawMessage safely creates a json.RawMessage from a potentially corrupted string
|
|
// It validates the JSON and provides a safe fallback if the data is corrupted
|
|
func safeJSONRawMessage(data string, fallback string, context string) json.RawMessage {
|
|
if data == "" {
|
|
return json.RawMessage(fallback)
|
|
}
|
|
|
|
// Validate JSON before creating RawMessage
|
|
if json.Valid([]byte(data)) {
|
|
return json.RawMessage(data)
|
|
}
|
|
|
|
// Log corruption warning with context
|
|
log.Printf("WARNING: Corrupted JSON data detected in %s, using fallback. Data preview: %.100s", context, data)
|
|
|
|
// Return safe fallback with error indication
|
|
errorFallback := fmt.Sprintf(`{"error": "corrupted_json_data", "context": "%s", "preview": "%s"}`,
|
|
context, strings.ReplaceAll(data[:min(50, len(data))], `"`, `\"`))
|
|
return json.RawMessage(errorFallback)
|
|
}
|
|
|
|
// min returns the minimum of two integers
|
|
func min(a, b int) int {
|
|
if a < b {
|
|
return a
|
|
}
|
|
return b
|
|
}
|