@@ -22,6 +22,7 @@ import {
2222import { OpencodeGoHandler } from "../opencode-go"
2323import { getModels } from "../fetchers/modelCache"
2424import { ApiHandlerOptions } from "../../../shared/api"
25+ import { Package } from "../../../shared/package"
2526import { asyncStreamFrom, collectStream } from "../../../test-utils/stream"
2627import { clearAllMocks } from "../../../test-utils/reset"
2728
@@ -94,6 +95,7 @@ describe("OpencodeGoHandler", () => {
9495 expect.objectContaining({
9596 baseURL: "https://opencode.ai/zen/go/v1",
9697 apiKey: "test-key",
98+ defaultHeaders: expect.objectContaining({ "User-Agent": `ZooCode/${Package.version}` }),
9799 }),
98100 )
99101 })
@@ -106,6 +108,7 @@ describe("OpencodeGoHandler", () => {
106108 // NOT include the trailing `/v1` used by the OpenAI client.
107109 baseURL: "https://opencode.ai/zen/go",
108110 apiKey: "test-key",
111+ defaultHeaders: expect.objectContaining({ "User-Agent": `ZooCode/${Package.version}` }),
109112 }),
110113 )
111114 })
@@ -208,6 +211,17 @@ describe("OpencodeGoHandler", () => {
208211 )
209212 })
210213
214+ it("sends the stable conversation ID to chat completions", async () => {
215+ const handler = new OpencodeGoHandler(mockOptions)
216+ const messages: Anthropic.Messages.MessageParam[] = [{ role: "user", content: "Hi" }]
217+
218+ await collectStream(handler.createMessage("sys", messages, { taskId: "conversation-123" }))
219+
220+ expect(mockCreate.mock.calls[0][1]?.headers).toMatchObject({
221+ "x-opencode-session": "conversation-123",
222+ })
223+ })
224+
211225 it("forwards the model's default reasoning_effort for reasoning-capable models", async () => {
212226 const handler = new OpencodeGoHandler(mockOptions)
213227 const messages: Anthropic.Messages.MessageParam[] = [{ role: "user", content: "Hi" }]
@@ -478,6 +492,17 @@ describe("OpencodeGoHandler", () => {
478492 expect(mockCreate).not.toHaveBeenCalled()
479493 })
480494
495+ it("sends the stable conversation ID to the Anthropic messages endpoint", async () => {
496+ const handler = new OpencodeGoHandler(anthropicOptions)
497+ const messages: Anthropic.Messages.MessageParam[] = [{ role: "user", content: "Hi" }]
498+
499+ await collectStream(handler.createMessage("sys", messages, { taskId: "conversation-123" }))
500+
501+ expect(mockAnthropicCreate.mock.calls[0][1]?.headers).toMatchObject({
502+ "x-opencode-session": "conversation-123",
503+ })
504+ })
505+
481506 it("streams text, tool-call, usage and cost chunks from the Anthropic stream", async () => {
482507 const handler = new OpencodeGoHandler(anthropicOptions)
483508 const messages: Anthropic.Messages.MessageParam[] = [{ role: "user", content: "Hi" }]
@@ -845,7 +870,10 @@ describe("OpencodeGoHandler", () => {
845870 handler.createMessage("sys", messages, { taskId: "test-task", abortSignal: controller.signal }),
846871 )
847872
848- expect(mockResponsesCreate.mock.calls[0][1]).toEqual({ signal: controller.signal })
873+ expect(mockResponsesCreate.mock.calls[0][1]).toEqual({
874+ signal: controller.signal,
875+ headers: { "x-opencode-session": "test-task" },
876+ })
849877 })
850878
851879 it("closes the Responses iterator when the consumer stops early", async () => {
0 commit comments