Files
OmniRoute/open-sse/executors/qoder.ts
Diego Rodrigues de Sa e Souza 1442c47bbb chore(release): v3.5.6 — email masking, model toggle, OpenRouter registries & bug fixes (#1080)
* fix(minimax): switch auth from x-api-key to Authorization Bearer (#1076)

Integrated into release/v3.5.6 — MiniMax auth fix with authHeader consistency normalization

* feat(CI,i18n): autogenerate language files + Add missing strings (#1071)

Integrated into release/v3.5.6 — i18n translations for memory, skills, and missing keys across 31 languages

* fix(ci): restore i18n continue-on-error, remove auto-commit race condition

* fix(husky): load nvm in hooks for VS Code compatibility

* fix(husky): gracefully skip hooks when npm is not in PATH

* fix: convert OpenAI function tool_choice to Claude tool format (#1072)

* fix: prevent EPIPE feedback loop filling logs at GB/s (#1006)

* fix: fallback to native fetch when undici dispatcher fails (#1054)

* fix: improve Qoder PAT validation with actionable error messages (#966)

- Add QODER_PERSONAL_ACCESS_TOKEN env var fallback for both validation and execution
- Pre-flight ping check to diagnose connectivity issues (Docker/proxy)
- Detect encrypted auth blobs from ~/.qoder/.auth/user and guide to website PAT
- Clear error messages for auth failures with link to integrations page
- Treat non-auth 4xx as auth-pass (request format issue, not token issue)
- Update tests to cover new validation paths (23 tests, all passing)

* feat: Improve the Chinese translation (#1079)

Integrated into release/v3.5.6

* chore(release): v3.5.6 — i18n updates and credential security fixes

* fix(ci): resolve e2e and docs-sync pipeline failures

* fix(security): bump next to 16.2.3 to resolve SNYK-JS-NEXT-15954202

* fix: guard Memory/Cache UI against null toLocaleString crash (#1083)

* fix: translate OpenAI tool_choice type 'function' to Claude 'tool' format (#1072)

* fix: pass custom baseUrl in provider API key validation (#1078)

* docs: update CHANGELOG with v3.5.6 bug fixes and security patches

* docs: rewrite implement-features workflow with 5-phase harvest-research-report-plan-execute pipeline

* docs: organize _ideia/ into viable/defer/notfit + add Phase 2.5 auto-response workflow

* docs: implementation plans for #1025, #750, #960, #1046 + close already-implemented #833, #973, #982

* feat: mask email addresses in dashboard for privacy (#1025)

* feat: add OpenRouter and GitHub to embedding/image provider registries (#960)

* feat: add model visibility toggle and search filter to provider page (#750)

* docs: move implemented features to notfit, update task plans status

* chore: untrack _ideia/ and _tasks/ from git — private/internal only

* chore(release): bump to v3.5.6 — changelog, docs, version sync & any-budget fix

* fix: remove explicit .ts extension in qoderCli import that caused 500 error in production build

---------

Co-authored-by: Jean Brito <jeanfbrito@gmail.com>
Co-authored-by: zenobit <zenobit@disroot.org>
Co-authored-by: diegosouzapw <diegosouzapw@users.noreply.github.com>
Co-authored-by: Ethan Hunt <136065060+only4copilot@users.noreply.github.com>
2026-04-09 15:55:59 -03:00

162 lines
5.3 KiB
TypeScript

import {
BaseExecutor,
mergeUpstreamExtraHeaders,
type ExecuteInput,
type ProviderCredentials,
} from "./base.ts";
import { PROVIDERS } from "../config/constants.ts";
function getAuthToken(credentials: ProviderCredentials): string {
if (typeof credentials.apiKey === "string" && credentials.apiKey.trim()) {
return credentials.apiKey.trim();
}
if (typeof credentials.accessToken === "string" && credentials.accessToken.trim()) {
return credentials.accessToken.trim();
}
if (typeof credentials.refreshToken === "string" && credentials.refreshToken.trim()) {
return credentials.refreshToken.trim();
}
// Fallback: QODER_PERSONAL_ACCESS_TOKEN env var (#966)
const envToken = String(process.env.QODER_PERSONAL_ACCESS_TOKEN || "").trim();
if (envToken) return envToken;
return "";
}
export class QoderExecutor extends BaseExecutor {
constructor() {
super("qoder", PROVIDERS.qoder);
}
async execute({ model, body, stream, credentials, signal, upstreamExtraHeaders }: ExecuteInput) {
const token = getAuthToken(credentials);
if (!token) {
return {
response: new Response(
JSON.stringify({
error: {
message: "Qoder access token or API Key is required. Please sign in or set a PAT.",
type: "authentication_error",
code: "token_required",
},
}),
{ status: 401, headers: { "Content-Type": "application/json" } }
),
url: "https://dashscope.aliyuncs.com",
headers: { "Content-Type": "application/json" },
transformedBody: body,
};
}
const resolvedModel = model || "qwen3-coder-plus";
// Check if it's a model-alias matching QwenCode
let mappedModel = resolvedModel;
if (resolvedModel === "qwen3.5-plus" || resolvedModel === "qwen3.6-plus") {
mappedModel = "coder-model"; // Translate alias to what DashScope compatible endpoint accepts via QwenCode tokens
} else if (resolvedModel === "vision-model") {
mappedModel = "qwen3-vl-plus";
}
// Determine the resource URL: Qwen CLI tokens usually target portal.qwen.ai natively,
// but the DashScope compatible endpoint works out of the box when authtype is set.
// If the token was mapped to a custom `resource_url`, we should use it. Otherwise default to dashscope Aliyun.
let endpointUrl = "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions";
// We allow setting custom API base via credentials
let credentialsApiBase: unknown;
if (typeof credentials === "object" && credentials !== null) {
const credsObj = credentials as Record<string, unknown>;
credentialsApiBase = credsObj.customApiBase || credsObj.resourceUrl;
}
if (typeof credentialsApiBase === "string" && credentialsApiBase.trim()) {
let base = credentialsApiBase.trim();
if (!base.startsWith("http")) base = `https://${base}`;
if (!base.endsWith("/v1")) base = base.endsWith("/") ? `${base}v1` : `${base}/v1`;
endpointUrl = `${base}/chat/completions`;
}
const headers: Record<string, string> = {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
"x-dashscope-authtype": "qwen-oauth",
"x-dashscope-cachecontrol": "enable",
"user-agent": "QwenCode/0.11.1 (linux; x64)",
"x-dashscope-useragent": "QwenCode/0.11.1 (linux; x64)",
"x-stainless-arch": "x64",
"x-stainless-lang": "js",
"x-stainless-os": "Linux",
};
mergeUpstreamExtraHeaders(headers, upstreamExtraHeaders);
const payload = {
...(typeof body === "object" && body !== null ? body : {}),
model: mappedModel,
};
const bodyStr = JSON.stringify(payload);
try {
const response = await fetch(endpointUrl, {
method: "POST",
headers,
body: bodyStr,
signal,
});
const newHeaders = new Headers(response.headers);
if (!response.ok) {
let errText = await response.text();
return {
response: new Response(
JSON.stringify({
error: {
message: `Qoder API failed with status ${response.status}: ${errText}`,
type: response.status === 401 ? "authentication_error" : "provider_error",
},
}),
{ status: response.status, headers: { "Content-Type": "application/json" } }
),
url: endpointUrl,
headers,
transformedBody: payload,
};
}
return {
response: new Response(response.body, {
status: response.status,
statusText: response.statusText,
headers: newHeaders,
}),
url: endpointUrl,
headers,
transformedBody: payload,
};
} catch (e: unknown) {
const error = e as Error;
if (error.name === "AbortError") {
throw error;
}
return {
response: new Response(
JSON.stringify({
error: {
message: `Qoder fetch error: ${error.message}`,
type: "provider_error",
},
}),
{ status: 502, headers: { "Content-Type": "application/json" } }
),
url: endpointUrl,
headers,
transformedBody: payload,
};
}
}
}
export default QoderExecutor;