Something went wrong. Try again.
Something went wrong. Try again.
1.1 kB · 27 lines
TypeScript
at main
12345678910111213141516171819202122232425262728import crypto from "node:crypto"
/** * OpenCode Go rejects any completion that does not carry a routing session: * * 400 MissingSessionID "Request is missing x-opencode-session and cannot be * routed efficiently." * * The docs ask for "a stable session ID in `x-opencode-session` for each * conversation so we can optimize routing and prompt caching", so callers pass * the conversation identity the bridge already derives for account affinity. */export const OPENCODE_SESSION_HEADER = "x-opencode-session"
/** * Session header for one OpenCode request. Without a conversation identity the * account path keeps the value stable per account, which still routes * consistently and never varies between retries. */export function opencodeSessionHeaders( identity: string | undefined, authPath: string | undefined,): Record<string, string> { if (identity) return { [OPENCODE_SESSION_HEADER]: identity } const scope = authPath ? crypto.createHash("sha256").update(authPath).digest("hex").slice(0, 32) : "env-key" return { [OPENCODE_SESSION_HEADER]: `account:${scope}` }}