MCPcopy Create free account
hub / github.com/coder/coder / isFantasyEnvelopeFormat

Function isFantasyEnvelopeFormat

coderd/x/chatd/chatprompt/chatprompt.go:1213–1228  ·  view source on GitHub ↗

isFantasyEnvelopeFormat checks whether raw message content uses the fantasy envelope format (legacy) vs SDK parts (new). It examines the first array element for a "data" field containing a JSON object (starts with '{'). Fantasy always serializes Data from json.Marshal(struct{...}), producing a JSON

(raw json.RawMessage)

Source from the content-addressed store, hash-verified

1211// means a "data" field starting with '{' can only come from
1212// fantasy.
1213func isFantasyEnvelopeFormat(raw json.RawMessage) bool {
1214 var arr []json.RawMessage
1215 if err := json.Unmarshal(raw, &arr); err != nil || len(arr) == 0 {
1216 return false
1217 }
1218 var fields map[string]json.RawMessage
1219 if err := json.Unmarshal(arr[0], &fields); err != nil {
1220 return false
1221 }
1222 data, ok := fields["data"]
1223 if !ok {
1224 return false
1225 }
1226 trimmed := bytes.TrimSpace(data)
1227 return len(trimmed) > 0 && trimmed[0] == '{'
1228}
1229
1230// marshalProviderMetadata converts fantasy provider metadata to raw
1231// JSON for storage in SDK parts.

Callers 2

parseAssistantRoleFunction · 0.85
parseUserRoleFunction · 0.85

Calls 1

UnmarshalMethod · 0.45

Tested by

no test coverage detected