2026-08-13 01:11:59 -04:00
|
|
|
import crypto from "crypto";
|
2026-04-06 06:32:44 -04:00
|
|
|
import { BaseExecutor } from "./base.js";
|
|
|
|
|
import { PROVIDERS } from "../config/providers.js";
|
# v0.4.66 (2026-05-29)
## Features
- Add Qoder provider: device-flow OAuth, COSY signing, WAF-bypass body encoding, live model catalog, dashboard quota tracker, 11 models (#1372)
- Add new models: Claude Opus 4.8 (Claude Code), GPT 5.4 Mini (Codex)
## Fixes
- DeepSeek thinking mode: echo `reasoning_content` back on follow-up/tool-call turns so OpenCode-free and custom providers no longer 400 with "reasoning_content must be passed back" (#1543)
- Reasoning injector: match deepseek/kimi model ids case-insensitively (covers custom providers using capitalized model names)
- OpenCode suggested-models: include free models without the `-free` suffix, e.g. `big-pickle` (#1535)
## Improvements
- Codex: trim sunset models, keep gpt-5.5 / gpt-5.4 / gpt-5.3-codex family, add gpt-5.4-mini
- volcengine-ark: refresh model list (add DeepSeek-V4-Flash/Pro, drop EOL entries)
- Lower stream stall timeout 35s → 30s for faster hang detection
2026-05-29 06:48:01 -04:00
|
|
|
import { injectReasoningContent } from "../utils/reasoningContentInjector.js";
|
2026-08-13 01:11:59 -04:00
|
|
|
import { resolveSessionId } from "../utils/sessionManager.js";
|
2026-04-06 06:32:44 -04:00
|
|
|
|
2026-08-13 01:11:59 -04:00
|
|
|
const OPENCODE_UA = "opencode";
|
# v0.4.66 (2026-05-29)
## Features
- Add Qoder provider: device-flow OAuth, COSY signing, WAF-bypass body encoding, live model catalog, dashboard quota tracker, 11 models (#1372)
- Add new models: Claude Opus 4.8 (Claude Code), GPT 5.4 Mini (Codex)
## Fixes
- DeepSeek thinking mode: echo `reasoning_content` back on follow-up/tool-call turns so OpenCode-free and custom providers no longer 400 with "reasoning_content must be passed back" (#1543)
- Reasoning injector: match deepseek/kimi model ids case-insensitively (covers custom providers using capitalized model names)
- OpenCode suggested-models: include free models without the `-free` suffix, e.g. `big-pickle` (#1535)
## Improvements
- Codex: trim sunset models, keep gpt-5.5 / gpt-5.4 / gpt-5.3-codex family, add gpt-5.4-mini
- volcengine-ark: refresh model list (add DeepSeek-V4-Flash/Pro, drop EOL entries)
- Lower stream stall timeout 35s → 30s for faster hang detection
2026-05-29 06:48:01 -04:00
|
|
|
const MESSAGES_MODELS = new Set();
|
2026-04-06 06:32:44 -04:00
|
|
|
|
2026-08-13 01:11:59 -04:00
|
|
|
function generateRequestId() {
|
|
|
|
|
return `msg_${crypto.randomUUID().replace(/-/g, "")}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function generateSessionId() {
|
|
|
|
|
return `ses_${crypto.randomUUID().replace(/-/g, "")}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Normalize any resolved id into opencode's ses_ format (stable per-conversation)
|
|
|
|
|
function toOpencodeSession(id) {
|
|
|
|
|
const stripped = String(id || "").replace(/^ses_/, "").replace(/-/g, "");
|
|
|
|
|
return stripped ? `ses_${stripped}` : null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function resolveOpencodeSession(body, credentials) {
|
|
|
|
|
return toOpencodeSession(resolveSessionId({
|
|
|
|
|
headers: credentials?.rawHeaders,
|
|
|
|
|
body,
|
|
|
|
|
connectionId: credentials?.connectionId,
|
|
|
|
|
scope: "opencode",
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-06 06:32:44 -04:00
|
|
|
export class OpenCodeExecutor extends BaseExecutor {
|
|
|
|
|
constructor() {
|
|
|
|
|
super("opencode", PROVIDERS.opencode);
|
2026-08-13 01:11:59 -04:00
|
|
|
this._currentSessionId = null;
|
2026-04-06 06:32:44 -04:00
|
|
|
}
|
|
|
|
|
|
2026-08-13 01:11:59 -04:00
|
|
|
transformRequest(model, body, stream, credentials) {
|
|
|
|
|
this._currentSessionId = resolveOpencodeSession(body, credentials);
|
# v0.4.66 (2026-05-29)
## Features
- Add Qoder provider: device-flow OAuth, COSY signing, WAF-bypass body encoding, live model catalog, dashboard quota tracker, 11 models (#1372)
- Add new models: Claude Opus 4.8 (Claude Code), GPT 5.4 Mini (Codex)
## Fixes
- DeepSeek thinking mode: echo `reasoning_content` back on follow-up/tool-call turns so OpenCode-free and custom providers no longer 400 with "reasoning_content must be passed back" (#1543)
- Reasoning injector: match deepseek/kimi model ids case-insensitively (covers custom providers using capitalized model names)
- OpenCode suggested-models: include free models without the `-free` suffix, e.g. `big-pickle` (#1535)
## Improvements
- Codex: trim sunset models, keep gpt-5.5 / gpt-5.4 / gpt-5.3-codex family, add gpt-5.4-mini
- volcengine-ark: refresh model list (add DeepSeek-V4-Flash/Pro, drop EOL entries)
- Lower stream stall timeout 35s → 30s for faster hang detection
2026-05-29 06:48:01 -04:00
|
|
|
return injectReasoningContent({ provider: this.provider, model, body });
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-06 06:32:44 -04:00
|
|
|
buildUrl(model) {
|
2026-06-13 09:40:43 -04:00
|
|
|
const base = this.config.baseUrl;
|
2026-04-06 06:32:44 -04:00
|
|
|
return MESSAGES_MODELS.has(model)
|
|
|
|
|
? `${base}/zen/v1/messages`
|
|
|
|
|
: `${base}/zen/v1/chat/completions`;
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-13 01:11:59 -04:00
|
|
|
buildHeaders(credentials, stream = true) {
|
|
|
|
|
const raw = credentials?.rawHeaders || {};
|
|
|
|
|
const lower = {};
|
|
|
|
|
for (const [k, v] of Object.entries(raw)) lower[k.toLowerCase()] = v;
|
|
|
|
|
|
|
|
|
|
const downstreamUa = lower["user-agent"] || "";
|
|
|
|
|
const isOpencodeDownstream = downstreamUa.toLowerCase().includes("opencode");
|
|
|
|
|
|
2026-04-06 06:32:44 -04:00
|
|
|
return {
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
"Authorization": "Bearer public",
|
2026-08-13 01:11:59 -04:00
|
|
|
"User-Agent": isOpencodeDownstream ? downstreamUa : OPENCODE_UA,
|
|
|
|
|
"x-opencode-client": lower["x-opencode-client"] || "desktop",
|
|
|
|
|
"x-opencode-session": lower["x-opencode-session"] || this._currentSessionId || generateSessionId(),
|
|
|
|
|
"x-opencode-request": lower["x-opencode-request"] || generateRequestId(),
|
|
|
|
|
"x-opencode-project": lower["x-opencode-project"] || "global",
|
|
|
|
|
"Accept": stream ? "text/event-stream" : "*/*",
|
2026-04-06 06:32:44 -04:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|