Files
agent-radar 2ed3415fb7
Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
2026-09-01 20:17:27 +08:00

64 lines
1.6 KiB
Go

package eventstream
import (
"encoding/json"
"fmt"
)
func requireJSONFields(raw json.RawMessage, objectKey string, fields ...string) error {
var root map[string]json.RawMessage
if err := json.Unmarshal(raw, &root); err != nil {
return fmt.Errorf("decode data presence: %w", err)
}
object := root
path := "data"
if objectKey != "" {
value, ok := root[objectKey]
if !ok {
return fmt.Errorf("data.%s is required", objectKey)
}
if err := json.Unmarshal(value, &object); err != nil {
return fmt.Errorf("data.%s must be an object", objectKey)
}
path += "." + objectKey
}
for _, field := range fields {
if _, ok := object[field]; !ok {
return fmt.Errorf("%s.%s is required", path, field)
}
}
return nil
}
func requireJSONArrayItemFields(raw json.RawMessage, arrayKey string, fields ...string) error {
var root map[string]json.RawMessage
if err := json.Unmarshal(raw, &root); err != nil {
return fmt.Errorf("decode data presence: %w", err)
}
value, ok := root[arrayKey]
if !ok {
return fmt.Errorf("data.%s is required", arrayKey)
}
var items []map[string]json.RawMessage
if err := json.Unmarshal(value, &items); err != nil {
return fmt.Errorf("data.%s must be an array of objects", arrayKey)
}
for index, item := range items {
for _, field := range fields {
if _, ok := item[field]; !ok {
return fmt.Errorf("data.%s[%d].%s is required", arrayKey, index, field)
}
}
}
return nil
}
func isOneOf(value string, allowed ...string) bool {
for _, candidate := range allowed {
if value == candidate {
return true
}
}
return false
}