MCPcopy Create free account
hub / github.com/ephraimduncan/opencode-cursor / deriveConversationKey

Function deriveConversationKey

src/proxy.ts:1122–1129  ·  view source on GitHub ↗

Derive a key for conversation state. Model-independent so context survives model switches.

(messages: OpenAIMessage[])

Source from the content-addressed store, hash-verified

1120
1121/** Derive a key for conversation state. Model-independent so context survives model switches. */
1122function deriveConversationKey(messages: OpenAIMessage[]): string {
1123 const firstUserMsg = messages.find((m) => m.role === "user");
1124 const firstUserText = firstUserMsg ? textContent(firstUserMsg.content) : "";
1125 return createHash("sha256")
1126 .update(`conv:${firstUserText.slice(0, 200)}`)
1127 .digest("hex")
1128 .slice(0, 16);
1129}
1130
1131/** Deterministic UUID derived from convKey so Cursor's server-side conversation
1132 * persists across proxy restarts. Formats 16 bytes of SHA-256 as a v4-shaped UUID. */

Callers 1

handleChatCompletionFunction · 0.85

Calls 1

textContentFunction · 0.85

Tested by

no test coverage detected