feat(providers): add trae/windsurf/zed/workbuddy/codebuddy-intl + icons
- New providers: trae, windsurf, zed, workbuddy, codebuddy-intl
(registry + executor, wired into executors/index.js + registry/index.js)
- zed: port hosted cloud proxy from OmniRoute — RSA access-token → short-lived
LLM token exchange (shared/zedAuth.js) + NDJSON {event}/{status}/[DONE]
stream translated back to OpenAI via Claude/Gemini/OpenAI-Responses translators
- Provider icons (128x128 png) for the 5 new providers
- qoder + tokenRefresh provider tweaks
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
30
open-sse/executors/codebuddy-intl.js
Normal file
30
open-sse/executors/codebuddy-intl.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import { DefaultExecutor } from "./default.js";
|
||||
|
||||
/**
|
||||
* CodeBuddyIntlExecutor — talks to https://www.codebuddy.ai/v2/chat/completions
|
||||
*
|
||||
* Same OpenAI-compatible-but-stream-only gateway behavior as codebuddy-cn:
|
||||
* non-stream requests are rejected, and reasoning is surfaced only when the
|
||||
* request carries the IDE's OpenAI-style reasoning params. Force stream and
|
||||
* mirror reasoning_summary exactly like CodeBuddyExecutor.
|
||||
*/
|
||||
export class CodeBuddyIntlExecutor extends DefaultExecutor {
|
||||
constructor() {
|
||||
super("codebuddy-intl");
|
||||
}
|
||||
|
||||
transformRequest(model, body, stream, credentials) {
|
||||
const transformed = super.transformRequest(model, body, stream, credentials);
|
||||
transformed.stream = true;
|
||||
|
||||
const eff = transformed.reasoning_effort;
|
||||
if (eff === "none" || eff === "off") {
|
||||
delete transformed.reasoning_effort;
|
||||
} else if (eff) {
|
||||
transformed.reasoning_summary = "auto";
|
||||
}
|
||||
return transformed;
|
||||
}
|
||||
}
|
||||
|
||||
export default CodeBuddyIntlExecutor;
|
||||
@@ -20,6 +20,11 @@ import { CommandCodeExecutor } from "./commandcode.js";
|
||||
import { XiaomiTokenplanExecutor } from "./xiaomi-tokenplan.js";
|
||||
import { MimoFreeExecutor } from "./mimo-free.js";
|
||||
import { CodeBuddyExecutor } from "./codebuddy-cn.js";
|
||||
import { CodeBuddyIntlExecutor } from "./codebuddy-intl.js";
|
||||
import { WorkBuddyExecutor } from "./workbuddy.js";
|
||||
import TraeExecutor from "./trae.js";
|
||||
import ZedExecutor from "./zed.js";
|
||||
import WindsurfExecutor from "./windsurf.js";
|
||||
import { DefaultExecutor } from "./default.js";
|
||||
|
||||
const executors = {
|
||||
@@ -50,6 +55,11 @@ const executors = {
|
||||
"mimo-free": new MimoFreeExecutor(),
|
||||
mmf: new MimoFreeExecutor(), // Alias for mimo-free
|
||||
"codebuddy-cn": new CodeBuddyExecutor(),
|
||||
"codebuddy-intl": new CodeBuddyIntlExecutor(),
|
||||
workbuddy: new WorkBuddyExecutor(),
|
||||
trae: new TraeExecutor(),
|
||||
zed: new ZedExecutor(),
|
||||
windsurf: new WindsurfExecutor(),
|
||||
};
|
||||
|
||||
const defaultCache = new Map();
|
||||
@@ -88,3 +98,8 @@ export { CommandCodeExecutor } from "./commandcode.js";
|
||||
export { XiaomiTokenplanExecutor } from "./xiaomi-tokenplan.js";
|
||||
export { MimoFreeExecutor } from "./mimo-free.js";
|
||||
export { CodeBuddyExecutor } from "./codebuddy-cn.js";
|
||||
export { CodeBuddyIntlExecutor } from "./codebuddy-intl.js";
|
||||
export { WorkBuddyExecutor } from "./workbuddy.js";
|
||||
export { default as TraeExecutor } from "./trae.js";
|
||||
export { default as ZedExecutor } from "./zed.js";
|
||||
export { default as WindsurfExecutor } from "./windsurf.js";
|
||||
|
||||
22
open-sse/executors/trae.js
Normal file
22
open-sse/executors/trae.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import { DefaultExecutor } from "./default.js";
|
||||
|
||||
// Trae executor — inject x-cloudide-token (raw access token) + Authorization Bearer.
|
||||
// Mirrors trae_account.rs request_trae_json header set.
|
||||
export default class TraeExecutor extends DefaultExecutor {
|
||||
constructor() {
|
||||
super("trae");
|
||||
}
|
||||
|
||||
buildHeaders(credentials, stream = true) {
|
||||
const headers = super.buildHeaders(credentials, stream);
|
||||
const token = credentials?.accessToken;
|
||||
if (token) {
|
||||
// Raw token (no Bearer prefix) on x-cloudide-token — matches official client.
|
||||
headers["x-cloudide-token"] = token;
|
||||
headers["Authorization"] = `Bearer ${token}`;
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
|
||||
// TODO verify: if Chat is JSON-RPC shaped, override transformRequest here.
|
||||
}
|
||||
42
open-sse/executors/windsurf.js
Normal file
42
open-sse/executors/windsurf.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import { DefaultExecutor } from "./default.js";
|
||||
|
||||
// Windsurf chat = Codeium binary protobuf gRPC-Web.
|
||||
// The .proto schema for exa.server_pb.ServerService is NOT in either source
|
||||
// repo, so request/response encode+decode cannot be implemented truthfully.
|
||||
// Auth, headers, quota are wired; the chat payload is intentionally a hard
|
||||
// failure rather than a fabricated protobuf body.
|
||||
export class WindsurfExecutor extends DefaultExecutor {
|
||||
constructor() {
|
||||
super("windsurf");
|
||||
}
|
||||
|
||||
buildHeaders(credentials, stream = true) {
|
||||
const headers = {
|
||||
"Content-Type": "application/proto",
|
||||
"Connect-Protocol-Version": "1",
|
||||
ideName: "Windsurf",
|
||||
extensionName: "codeium.windsurf",
|
||||
...(this.config.headers || {}),
|
||||
};
|
||||
// apiKey from RegisterUser (sk-ws-..., Firebase-derived, or Devin ide_token).
|
||||
const token = credentials?.apiKey || credentials?.accessToken;
|
||||
if (token) headers["Authorization"] = `Bearer ${token}`;
|
||||
return headers;
|
||||
}
|
||||
|
||||
// TODO(proto): implement once Codeium server_pb .proto is recovered.
|
||||
// - encode request: chat history + model + system → protobuf bytes
|
||||
// - decode response: stream protobuf frames → OpenAI-shaped chunks
|
||||
async execute() {
|
||||
throw new Error(
|
||||
"Windsurf chat (Codeium protobuf) not yet implemented — needs .proto schema. Auth/quota wired."
|
||||
);
|
||||
}
|
||||
|
||||
async refreshCredentials() {
|
||||
// Windsurf apiKey is long-lived (like cursor); refresh handled out-of-band.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export default WindsurfExecutor;
|
||||
31
open-sse/executors/workbuddy.js
Normal file
31
open-sse/executors/workbuddy.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import { DefaultExecutor } from "./default.js";
|
||||
|
||||
/**
|
||||
* WorkBuddyExecutor — talks to https://www.codebuddy.cn/v2/chat/completions
|
||||
*
|
||||
* WorkBuddy is a B2B/enterprise skin of CodeBuddy CN (same codebuddy.cn
|
||||
* OpenAI-compatible gateway). Behavior mirrors CodeBuddyExecutor:
|
||||
* gateway rejects non-stream requests, and reasoning must be surfaced via
|
||||
* OpenAI-style reasoning_effort + reasoning_summary:"auto" (vendor-native
|
||||
* thinking shapes are not honored by the unified gateway).
|
||||
*/
|
||||
export class WorkBuddyExecutor extends DefaultExecutor {
|
||||
constructor() {
|
||||
super("workbuddy");
|
||||
}
|
||||
|
||||
transformRequest(model, body, stream, credentials) {
|
||||
const transformed = super.transformRequest(model, body, stream, credentials);
|
||||
transformed.stream = true;
|
||||
|
||||
const eff = transformed.reasoning_effort;
|
||||
if (eff === "none" || eff === "off") {
|
||||
delete transformed.reasoning_effort;
|
||||
} else if (eff) {
|
||||
transformed.reasoning_summary = "auto";
|
||||
}
|
||||
return transformed;
|
||||
}
|
||||
}
|
||||
|
||||
export default WorkBuddyExecutor;
|
||||
305
open-sse/executors/zed.js
Normal file
305
open-sse/executors/zed.js
Normal file
@@ -0,0 +1,305 @@
|
||||
// ZedHostedExecutor — routes requests to Zed's hosted LLM aggregator
|
||||
// (cloud.zed.dev/completions), a multi-format proxy fronting
|
||||
// Anthropic/OpenAI/Google/xAI depending on the requested model.
|
||||
//
|
||||
// Wire protocol: POST /completions with an NDJSON/SSE-ish body-per-line
|
||||
// response stream (`{"event": <provider-shaped-chunk>}` / `{"status": ...}` /
|
||||
// `[DONE]`), authenticated with a short-lived LLM bearer token exchanged from
|
||||
// the RSA-decrypted access_token (see open-sse/shared/zedAuth.js). The
|
||||
// provider-shaped chunk is Claude/Gemini/OpenAI-Responses/xAI(OpenAI-shaped)
|
||||
// depending on which upstream Zed fronts for the model — translated back to
|
||||
// OpenAI Chat Completions by reusing the existing translators.
|
||||
//
|
||||
// Ported from OmniRoute open-sse/executors/zed-hosted.ts. Overrides execute()
|
||||
// entirely (does NOT use DefaultExecutor's pipeline) because the Zed wire
|
||||
// shape (thread envelope, LLM-token exchange, NDJSON status frames) doesn't
|
||||
// fit the generic transformRequest/buildUrl contract.
|
||||
|
||||
import { BaseExecutor } from "./base.js";
|
||||
import { FORMATS } from "../translator/formats.js";
|
||||
import { initState } from "../translator/index.js";
|
||||
import { openaiToClaudeRequest } from "../translator/request/openai-to-claude.js";
|
||||
import { openaiToGeminiRequest } from "../translator/request/openai-to-gemini.js";
|
||||
import { openaiToOpenAIResponsesRequest } from "../translator/request/openai-responses.js";
|
||||
import { claudeToOpenAIResponse } from "../translator/response/claude-to-openai.js";
|
||||
import { geminiToOpenAIResponse } from "../translator/response/gemini-to-openai.js";
|
||||
import { openaiResponsesToOpenAIResponse } from "../translator/response/openai-responses.js";
|
||||
import {
|
||||
ZED_HEADERS,
|
||||
resolveZedModels,
|
||||
zedLlmFetch,
|
||||
} from "../shared/zedAuth.js";
|
||||
|
||||
const ZED_PROVIDER = {
|
||||
anthropic: "Anthropic",
|
||||
openai: "OpenAi",
|
||||
google: "Google",
|
||||
xai: "XAi",
|
||||
};
|
||||
|
||||
function normalizeZedProvider(value, model) {
|
||||
const raw = String(value || "").toLowerCase();
|
||||
if (raw === "anthropic") return ZED_PROVIDER.anthropic;
|
||||
if (raw === "openai" || raw === "open_ai") return ZED_PROVIDER.openai;
|
||||
if (raw === "google" || raw === "gemini") return ZED_PROVIDER.google;
|
||||
if (raw === "xai" || raw === "x_ai" || raw === "x-ai") return ZED_PROVIDER.xai;
|
||||
|
||||
const m = String(model || "").toLowerCase();
|
||||
if (m.includes("claude")) return ZED_PROVIDER.anthropic;
|
||||
if (m.includes("gemini")) return ZED_PROVIDER.google;
|
||||
if (m.includes("grok") || m.includes("xai")) return ZED_PROVIDER.xai;
|
||||
return ZED_PROVIDER.openai;
|
||||
}
|
||||
|
||||
function buildProviderRequest(provider, model, body, stream, credentials) {
|
||||
if (provider === ZED_PROVIDER.anthropic) {
|
||||
return openaiToClaudeRequest(model, body, true);
|
||||
}
|
||||
if (provider === ZED_PROVIDER.google) {
|
||||
return openaiToGeminiRequest(model, body, true);
|
||||
}
|
||||
if (provider === ZED_PROVIDER.openai) {
|
||||
return openaiToOpenAIResponsesRequest(model, body, true, credentials);
|
||||
}
|
||||
// xAI is OpenAI-shaped — forward as-is.
|
||||
return { ...(body || {}), model, stream: stream !== false };
|
||||
}
|
||||
|
||||
function initProviderState(provider, model) {
|
||||
if (provider === ZED_PROVIDER.anthropic) return initState(FORMATS.CLAUDE);
|
||||
if (provider === ZED_PROVIDER.google) return initState(FORMATS.GEMINI);
|
||||
if (provider === ZED_PROVIDER.openai) return initState(FORMATS.OPENAI_RESPONSES);
|
||||
const state = initState(FORMATS.OPENAI);
|
||||
state.model = model;
|
||||
return state;
|
||||
}
|
||||
|
||||
function convertProviderEvent(provider, event, state) {
|
||||
if (provider === ZED_PROVIDER.anthropic) return claudeToOpenAIResponse(event, state);
|
||||
if (provider === ZED_PROVIDER.google) return geminiToOpenAIResponse(event, state);
|
||||
if (provider === ZED_PROVIDER.openai) return openaiResponsesToOpenAIResponse(event, state);
|
||||
return event;
|
||||
}
|
||||
|
||||
function createErrorChunk(model, message) {
|
||||
return {
|
||||
id: `chatcmpl-zed-error-${Date.now()}`,
|
||||
object: "chat.completion.chunk",
|
||||
created: Math.floor(Date.now() / 1000),
|
||||
model,
|
||||
choices: [
|
||||
{ index: 0, delta: { content: `[Zed error] ${message}` }, finish_reason: "stop" },
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
function enqueueSseObject(controller, encoder, chunk) {
|
||||
if (!chunk) return;
|
||||
const items = Array.isArray(chunk) ? chunk : [chunk];
|
||||
for (const item of items) {
|
||||
if (!item) continue;
|
||||
controller.enqueue(encoder.encode(`data: ${JSON.stringify(item)}\n\n`));
|
||||
}
|
||||
}
|
||||
|
||||
function unwrapZedLine(line) {
|
||||
let text = line.replace(/\r$/, "").trim();
|
||||
if (!text) return null;
|
||||
if (text.startsWith("data:")) text = text.slice(5).trimStart();
|
||||
if (text === "[DONE]") return { done: true };
|
||||
try {
|
||||
const parsed = JSON.parse(text);
|
||||
if (parsed && Object.prototype.hasOwnProperty.call(parsed, "event")) {
|
||||
return { event: parsed.event };
|
||||
}
|
||||
if (parsed && Object.prototype.hasOwnProperty.call(parsed, "status")) {
|
||||
return { status: parsed.status };
|
||||
}
|
||||
return { event: parsed };
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeStatus(status) {
|
||||
if (!status) return null;
|
||||
if (typeof status === "string") return { type: status };
|
||||
if (typeof status === "object") {
|
||||
const key = Object.keys(status)[0];
|
||||
if (key && typeof status[key] === "object") return { type: key, ...status[key] };
|
||||
return status;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function wrapZedCompletionStream(response, provider, model) {
|
||||
if (!response.ok || !response.body) return response;
|
||||
|
||||
const decoder = new TextDecoder();
|
||||
const encoder = new TextEncoder();
|
||||
const state = initProviderState(provider, model);
|
||||
let buffer = "";
|
||||
let done = false;
|
||||
|
||||
const finish = (controller) => {
|
||||
if (done) return;
|
||||
const finalChunk = convertProviderEvent(provider, null, state);
|
||||
enqueueSseObject(controller, encoder, finalChunk);
|
||||
controller.enqueue(encoder.encode("data: [DONE]\n\n"));
|
||||
done = true;
|
||||
};
|
||||
|
||||
const processLine = (line, controller) => {
|
||||
if (done) return;
|
||||
const payload = unwrapZedLine(line);
|
||||
if (!payload) return;
|
||||
if (payload.done) {
|
||||
finish(controller);
|
||||
return;
|
||||
}
|
||||
if (payload.status) {
|
||||
const status = normalizeStatus(payload.status);
|
||||
if (status?.type === "failed" || status?.failed) {
|
||||
const failed = status.failed || status;
|
||||
const message = String(failed.message || failed.error || failed.code || "request failed");
|
||||
enqueueSseObject(controller, encoder, createErrorChunk(model, message));
|
||||
finish(controller);
|
||||
} else if (status?.type === "stream_ended" || status === "stream_ended") {
|
||||
finish(controller);
|
||||
}
|
||||
return;
|
||||
}
|
||||
const converted = convertProviderEvent(provider, payload.event, state);
|
||||
enqueueSseObject(controller, encoder, converted);
|
||||
};
|
||||
|
||||
const transformed = response.body.pipeThrough(
|
||||
new TransformStream({
|
||||
transform(chunk, controller) {
|
||||
buffer += decoder.decode(chunk, { stream: true });
|
||||
let nl;
|
||||
while ((nl = buffer.indexOf("\n")) !== -1) {
|
||||
const line = buffer.slice(0, nl);
|
||||
buffer = buffer.slice(nl + 1);
|
||||
processLine(line, controller);
|
||||
}
|
||||
},
|
||||
flush(controller) {
|
||||
buffer += decoder.decode();
|
||||
if (buffer) {
|
||||
processLine(buffer, controller);
|
||||
buffer = "";
|
||||
}
|
||||
finish(controller);
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
return new Response(transformed, {
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
headers: {
|
||||
"Content-Type": "text/event-stream",
|
||||
"Cache-Control": "no-cache",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
class ZedExecutor extends BaseExecutor {
|
||||
constructor() {
|
||||
super("zed");
|
||||
}
|
||||
|
||||
async resolveModel(model, credentials, signal, log) {
|
||||
try {
|
||||
const catalog = await resolveZedModels(credentials, { config: this.config, signal });
|
||||
let raw = catalog?.rawById?.get(model) ?? null;
|
||||
if (!raw) {
|
||||
const refreshed = await resolveZedModels(credentials, {
|
||||
config: this.config,
|
||||
signal,
|
||||
forceRefresh: true,
|
||||
});
|
||||
raw = refreshed?.rawById?.get(model) ?? null;
|
||||
}
|
||||
return { raw, provider: normalizeZedProvider(raw?.provider, model) };
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
log?.warn?.("ZED", `model catalog unavailable, inferring provider for ${model}: ${message}`);
|
||||
return { raw: null, provider: normalizeZedProvider(null, model) };
|
||||
}
|
||||
}
|
||||
|
||||
async execute({ model, body, stream, credentials, signal, log, proxyOptions = null }) {
|
||||
const { provider } = await this.resolveModel(model, credentials, signal, log);
|
||||
const providerRequest = buildProviderRequest(provider, model, body, stream, credentials);
|
||||
const bodyRecord = body || {};
|
||||
const payload = {
|
||||
thread_id: bodyRecord.thread_id || credentials?._clientSessionId,
|
||||
prompt_id: bodyRecord.prompt_id,
|
||||
provider,
|
||||
model,
|
||||
provider_request: providerRequest,
|
||||
};
|
||||
|
||||
const response = await zedLlmFetch(credentials, "/completions", {
|
||||
config: this.config,
|
||||
signal,
|
||||
fetchOptions: {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/x-ndjson, text/event-stream, */*",
|
||||
"User-Agent": "9router/zed",
|
||||
"x-zed-version": this.config?.appVersion?.toString() || "0.200.0",
|
||||
[ZED_HEADERS.clientSupportsStatus]: "true",
|
||||
[ZED_HEADERS.clientSupportsStreamEnded]: "true",
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
},
|
||||
});
|
||||
|
||||
const wrapped = response.ok ? wrapZedCompletionStream(response, provider, model) : response;
|
||||
return {
|
||||
response: wrapped,
|
||||
url: `${this.config?.llmBaseUrl || "https://cloud.zed.dev"}/completions`,
|
||||
headers: { "Content-Type": "application/json", Authorization: "Bearer <zed-llm-token>" },
|
||||
transformedBody: payload,
|
||||
};
|
||||
}
|
||||
|
||||
parseError(response, bodyText) {
|
||||
let parsed = null;
|
||||
try {
|
||||
parsed = JSON.parse(bodyText || "{}");
|
||||
} catch {
|
||||
parsed = null;
|
||||
}
|
||||
|
||||
const errorObj = parsed?.error || undefined;
|
||||
const code = parsed?.code || errorObj?.code || "";
|
||||
const rawMessage =
|
||||
parsed?.message || errorObj?.message || bodyText || response.statusText;
|
||||
if (code === "trial_blocked") {
|
||||
return {
|
||||
status: response.status,
|
||||
message: `Zed trial access is blocked upstream. The account can list hosted models, but Zed is refusing completions until trial/billing access is enabled or unblocked. Zed says: ${rawMessage}`,
|
||||
};
|
||||
}
|
||||
if (code) {
|
||||
return { status: response.status, message: `Zed ${code}: ${rawMessage}` };
|
||||
}
|
||||
return { status: response.status, message: rawMessage || `Zed upstream error: ${response.status}` };
|
||||
}
|
||||
|
||||
async refreshCredentials() {
|
||||
// Zed uses a long-lived RSA-decrypted access_token — no OAuth refresh.
|
||||
return null;
|
||||
}
|
||||
|
||||
needsRefresh() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export default ZedExecutor;
|
||||
Reference in New Issue
Block a user