Skip to content

Commit a5183ab

Browse files
committed
fix(providers): update opencode-free static headers to official CLI markers
1 parent bcc77c0 commit a5183ab

3 files changed

Lines changed: 35 additions & 10 deletions

File tree

‎src/providers/registry.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2403,7 +2403,9 @@ export const PROVIDER_REGISTRY: readonly ProviderRegistryEntry[] = [
24032403
note: "No key needed — public desktop tier. OpenCode currently advertises about 200 Big Pickle/free-model requests per 5 hours. The same Zen gateway can also short-window rate-limit free models at roughly 15-20 requests/minute, and may return generic 429s without Retry-After (opencodex synthesizes backoff only when that header is omitted). Free models are discovered live from Zen. Data use: per OpenCode's Zen docs (https://opencode.ai/docs/zen/), prompts sent to free models may be retained and used for training/improvement — do not send confidential material through this provider.",
24042404
dashboardUrl: "https://opencode.ai",
24052405
staticHeaders: {
2406-
"x-opencode-client": "desktop",
2406+
"User-Agent": "opencode-cli/1.0.0",
2407+
"x-opencode-client": "cli",
2408+
"x-opencode-project": "default",
24072409
},
24082410
modelReasoningEfforts: Object.fromEntries(OPENCODE_FREE_DEEPSEEK_MODELS.map(id => [id, deepseekThinkingEffortsFor(id)])),
24092411
modelReasoningEffortMap: Object.fromEntries(OPENCODE_FREE_DEEPSEEK_MODELS.map(id => [id, deepseekReasoningMapFor(id)])),

‎tests/management-provider-validation.test.ts‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2871,7 +2871,12 @@ describe("provider management validation", () => {
28712871
baseUrl: "https://opencode.ai/zen/v1",
28722872
authMode: "key",
28732873
allowPrivateNetwork: true,
2874-
headers: { "x-opencode-client": "desktop", "X-User": "v1" },
2874+
headers: {
2875+
"User-Agent": "opencode-cli/1.0.0",
2876+
"x-opencode-client": "cli",
2877+
"x-opencode-project": "default",
2878+
"X-User": "v1",
2879+
},
28752880
},
28762881
},
28772882
};
@@ -2890,9 +2895,17 @@ describe("provider management validation", () => {
28902895
// Clearing user-managed headers must not delete the registry-owned static
28912896
// metadata (opencode-free's x-opencode-client marker) the transport relies on.
28922897
expect((await patch("opencode-free", { headers: null }))?.status).toBe(200);
2893-
expect(liveConfig.providers["opencode-free"].headers).toEqual({ "x-opencode-client": "desktop" });
2898+
expect(liveConfig.providers["opencode-free"].headers).toEqual({
2899+
"User-Agent": "opencode-cli/1.0.0",
2900+
"x-opencode-client": "cli",
2901+
"x-opencode-project": "default",
2902+
});
28942903
const saved = JSON.parse(readFileSync(join(TEST_DIR, "config.json"), "utf8")) as OcxConfig;
2895-
expect(saved.providers["opencode-free"]?.headers).toEqual({ "x-opencode-client": "desktop" });
2904+
expect(saved.providers["opencode-free"]?.headers).toEqual({
2905+
"User-Agent": "opencode-cli/1.0.0",
2906+
"x-opencode-client": "cli",
2907+
"x-opencode-project": "default",
2908+
});
28962909
});
28972910
test("concurrent provider PATCHes merge different headers", async () => {
28982911
if (existsSync(TEST_DIR)) rmSync(TEST_DIR, { recursive: true });

‎tests/opencode-free-provider.test.ts‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,19 @@ describe("opencode-free provider", () => {
2727
expect(entry?.models).toBeUndefined();
2828
});
2929

30-
test("static headers include only the public client marker", () => {
30+
test("static headers include CLI client markers", () => {
3131
expect(entry?.staticHeaders?.["Authorization"]).toBeUndefined();
32-
expect(entry?.staticHeaders?.["x-opencode-client"]).toBe("desktop");
32+
expect(entry?.staticHeaders?.["User-Agent"]).toBe("opencode-cli/1.0.0");
33+
expect(entry?.staticHeaders?.["x-opencode-client"]).toBe("cli");
34+
expect(entry?.staticHeaders?.["x-opencode-project"]).toBe("default");
3335
});
3436

3537
test("providerConfigSeed propagates static headers", () => {
3638
const seed = providerConfigSeed(entry!);
3739
expect(seed.headers?.["Authorization"]).toBeUndefined();
38-
expect(seed.headers?.["x-opencode-client"]).toBe("desktop");
40+
expect(seed.headers?.["User-Agent"]).toBe("opencode-cli/1.0.0");
41+
expect(seed.headers?.["x-opencode-client"]).toBe("cli");
42+
expect(seed.headers?.["x-opencode-project"]).toBe("default");
3943
expect(seed.keyOptional).toBe(true);
4044
expect(seed.liveModels).toBe(true);
4145
});
@@ -55,7 +59,9 @@ describe("opencode-free provider", () => {
5559
const req = adapter.buildRequest(minimalRequest());
5660
const headers = req.headers as Record<string, string>;
5761
expect(headers["Authorization"]).toBeUndefined();
58-
expect(headers["x-opencode-client"]).toBe("desktop");
62+
expect(headers["User-Agent"]).toBe("opencode-cli/1.0.0");
63+
expect(headers["x-opencode-client"]).toBe("cli");
64+
expect(headers["x-opencode-project"]).toBe("default");
5965
expect(req.url).toBe("https://opencode.ai/zen/v1/chat/completions");
6066
});
6167

@@ -68,7 +74,9 @@ describe("opencode-free provider", () => {
6874
const req = adapter.buildRequest(minimalRequest());
6975
const headers = req.headers as Record<string, string>;
7076
expect(headers["Authorization"]).toBe("Bearer user-secret-key");
71-
expect(headers["x-opencode-client"]).toBe("desktop");
77+
expect(headers["User-Agent"]).toBe("opencode-cli/1.0.0");
78+
expect(headers["x-opencode-client"]).toBe("cli");
79+
expect(headers["x-opencode-project"]).toBe("default");
7280
});
7381

7482
test("the provider client marker still applies when a user apiKey is present", () => {
@@ -80,7 +88,9 @@ describe("opencode-free provider", () => {
8088
const req = adapter.buildRequest(minimalRequest());
8189
const headers = req.headers as Record<string, string>;
8290
expect(headers["Authorization"]).toBe("Bearer user-secret-key");
83-
expect(headers["x-opencode-client"]).toBe("desktop");
91+
expect(headers["User-Agent"]).toBe("opencode-cli/1.0.0");
92+
expect(headers["x-opencode-client"]).toBe("cli");
93+
expect(headers["x-opencode-project"]).toBe("default");
8494
expect(Object.keys(headers)).toContain("Authorization");
8595
});
8696

0 commit comments

Comments
 (0)