MCPcopy Create free account
hub / github.com/compozy/agh / ValidateConversationID

Function ValidateConversationID

internal/network/validate.go:144–164  ·  view source on GitHub ↗

ValidateConversationID reports whether a container identifier matches its field grammar.

(id string, field string)

Source from the content-addressed store, hash-verified

142
143// ValidateConversationID reports whether a container identifier matches its field grammar.
144func ValidateConversationID(id string, field string) error {
145 trimmed := strings.TrimSpace(id)
146 if trimmed == "" {
147 return fmt.Errorf("%w: %s is required", ErrMissingField, field)
148 }
149 switch field {
150 case validateThreadIDKey:
151 if !threadIDPattern.MatchString(trimmed) {
152 return fmt.Errorf("%w: thread_id=%q", ErrInvalidField, id)
153 }
154 case validateDirectIDKey:
155 if !directIDPattern.MatchString(trimmed) {
156 return fmt.Errorf("%w: direct_id=%q", ErrInvalidField, id)
157 }
158 default:
159 if strings.ContainsAny(trimmed, `/\`) || containsControlCharacter(trimmed) || len(trimmed) > 128 {
160 return fmt.Errorf("%w: %s=%q", ErrInvalidField, field, id)
161 }
162 }
163 return nil
164}
165
166// ValidateWorkID reports whether a work id can safely cross the network boundary.
167func ValidateWorkID(id string) error {

Callers 10

NetworkThreadMethod · 0.92
NetworkDirectRoomMethod · 0.92
ValidateWorkIDFunction · 0.85
ValidateMethod · 0.85

Calls 1

containsControlCharacterFunction · 0.70