MCPcopy Index your code
hub / github.com/coder/coder / messageJSONByteCount

Function messageJSONByteCount

coderd/x/chatd/chatadvisor/handoff.go:194–208  ·  view source on GitHub ↗

messageJSONByteCount approximates the message's contribution to the advisor prompt using the length of its JSON serialization. The JSON wrapping ({"role":"...","content":[{"type":"text","text":"..."}]}) is counted alongside the user-visible text; the measurement is intended for budget accounting, no

(msg fantasy.Message)

Source from the content-addressed store, hash-verified

192// counted alongside the user-visible text; the measurement is intended
193// for budget accounting, not for reporting visible character counts.
194func messageJSONByteCount(msg fantasy.Message) int {
195 data, err := json.Marshal(msg)
196 if err == nil {
197 return len(data)
198 }
199
200 total := 0
201 for _, part := range msg.Content {
202 partData, partErr := json.Marshal(part)
203 if partErr == nil {
204 total += len(partData)
205 }
206 }
207 return total
208}

Callers 1

BuildAdvisorMessagesFunction · 0.85

Calls 1

MarshalMethod · 0.45

Tested by

no test coverage detected