MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / serializeMessage

Function serializeMessage

src/llm/cache-layout.ts:28–39  ·  view source on GitHub ↗
(m: Message)

Source from the content-addressed store, hash-verified

26/** Canonical, stable serialization of a single message for prefix comparison.
27 * Includes exactly the fields that go on the wire and affect the KV cache. */
28export function serializeMessage(m: Message): string {
29 const parts: string[] = [`role:${m.role}`];
30 parts.push(`content:${m.content ?? ''}`);
31 if (m.tool_call_id) parts.push(`tcid:${m.tool_call_id}`);
32 if (m.name) parts.push(`name:${m.name}`);
33 if (m.tool_calls && m.tool_calls.length) {
34 for (const tc of m.tool_calls) {
35 parts.push(`tc:${tc.function.name}(${tc.function.arguments})`);
36 }
37 }
38 return parts.join('');
39}
40
41/** Number of leading messages that are byte-identical between two message arrays.
42 * This is the prefix the inference server can serve from KV cache. */

Callers 3

commonPrefixLengthFunction · 0.85
prefixCharsFunction · 0.85

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected