Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions open-sse/executors/opencode-zen.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,29 @@ const MAX_SESSION_LENGTH = 256;

const RESPONSES_BASE_URL = "https://opencode.ai/zen/v1/responses";
const MAX_TOOL_NAME_LEN = 128;
const OPENCODE_UA = "opencode/1.18.31";
const OPENCODE_UA = "opencode/latest/2.0.29/cli";
export const OPENCODE_SESSION_RE = /^ses_[0-9a-f]{12}[0-9A-Za-z]{14}$/;
const BASE62_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
// Free-tier fingerprint (mirrors opencode executor, PR #4132): upstream 403s
// requests without the file-search quartet and without stream:true.
const OPENCODE_FINGERPRINT_TOOLS = ["bash", "glob", "grep", "read"];

function hasValidOpencodeVersion(ua) {
const m = String(ua || "").match(/opencode\/(\d+)\.(\d+)(?:\.(\d+))?/i);
if (!m) return false;
const major = parseInt(m[1], 10);
const minor = parseInt(m[2], 10);
return major > 1 || (major === 1 && minor >= 17);
// Accept both legacy "opencode/1.18.31" and channel form
// "opencode/latest/2.0.29/cli" (official CLI since 2.0, issue #4837/#4861).
const legacy = String(ua || "").match(/opencode\/(\d+)\.(\d+)(?:\.(\d+))?/i);
if (legacy) {
const major = parseInt(legacy[1], 10);
const minor = parseInt(legacy[2], 10);
return major > 1 || (major === 1 && minor >= 17);
}
const channel = String(ua || "").match(/opencode\/[a-z-]+\/(\d+)\.(\d+)(?:\.(\d+))?/i);
if (channel) {
const major = parseInt(channel[1], 10);
const minor = parseInt(channel[2], 10);
return major > 1 || (major === 1 && minor >= 17);
}
return false;
}

function unstableRandom() {
Expand Down
24 changes: 17 additions & 7 deletions open-sse/executors/opencode.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
coerceResponsesOutput,
} from "../translator/formats/responsesApi.js";

const OPENCODE_UA = "opencode/1.18.31";
const OPENCODE_UA = "opencode/latest/2.0.29/cli";
const MAX_SESSION_LENGTH = 256;
const MAX_TOOL_NAME_LEN = 128;
const SESSION_HEADER = "x-opencode-session";
Expand All @@ -26,11 +26,21 @@ export const OPENCODE_REQUEST_RE = /^msg_[0-9a-f]{12}[0-9A-Za-z]{14}$/;
const BASE62_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

function hasValidOpencodeVersion(ua) {
const m = String(ua || "").match(/opencode\/(\d+)\.(\d+)(?:\.(\d+))?/i);
if (!m) return false;
const major = parseInt(m[1], 10);
const minor = parseInt(m[2], 10);
return major > 1 || (major === 1 && minor >= 17);
// Accept both legacy "opencode/1.18.31" and channel form
// "opencode/latest/2.0.29/cli" (official CLI since 2.0, issue #4837/#4861).
const legacy = String(ua || "").match(/opencode\/(\d+)\.(\d+)(?:\.(\d+))?/i);
if (legacy) {
const major = parseInt(legacy[1], 10);
const minor = parseInt(legacy[2], 10);
return major > 1 || (major === 1 && minor >= 17);
}
const channel = String(ua || "").match(/opencode\/[a-z-]+\/(\d+)\.(\d+)(?:\.(\d+))?/i);
if (channel) {
const major = parseInt(channel[1], 10);
const minor = parseInt(channel[2], 10);
return major > 1 || (major === 1 && minor >= 17);
}
return false;
}
// Models served by /zen/v1/responses; every other model stays on /chat/completions.
const RESPONSES_MODELS = new Set([
Expand Down Expand Up @@ -475,7 +485,7 @@ export class OpenCodeExecutor extends BaseExecutor {
"Content-Type": "application/json",
"Authorization": "Bearer public",
"User-Agent": isOpencodeDownstream ? downstreamUa : OPENCODE_UA,
"x-opencode-client": lower["x-opencode-client"] || "desktop",
"x-opencode-client": lower["x-opencode-client"] || "cli",
"x-opencode-session": session,
"x-opencode-request": requestId,
"x-opencode-project": lower["x-opencode-project"] || "global",
Expand Down
2 changes: 1 addition & 1 deletion open-sse/providers/registry/opencode-zen.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export default {
baseUrl: "https://opencode.ai/zen/v1/systemone",
headers: {
"x-opencode-client": "desktop",
"User-Agent": "opencode/1.18.31",
"User-Agent": "opencode/latest/2.0.29/cli",
},
},
modelsFetcher: { url: "https://opencode.ai/zen/v1/models", type: "opencode-free" },
Expand Down
2 changes: 1 addition & 1 deletion open-sse/providers/registry/opencode.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default {
baseUrl: "https://opencode.ai/zen/v1/systemone",
headers: {
"x-opencode-client": "desktop",
"User-Agent": "opencode/1.18.31",
"User-Agent": "opencode/latest/2.0.29/cli",
},
},
modelsFetcher: { url: "https://opencode.ai/zen/v1/models", type: "opencode-free" },
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/providers/[id]/test/testUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ async function testApiKeyConnection(connection, effectiveProxy = null) {
}
case "opencode": {
const res = await fetchWithConnectionProxy("https://opencode.ai/zen/v1/models", {
headers: { Authorization: "Bearer public", "User-Agent": "opencode/1.18.31" },
headers: { Authorization: "Bearer public", "User-Agent": "opencode/latest/2.0.29/cli" },
}, effectiveProxy);
return { valid: res.ok, error: res.ok ? null : "OpenCode free tier unavailable" };
}
Expand Down