Files
OmniRoute/open-sse/executors/codebuddy-cn.ts
Diego Rodrigues de Sa e Souza 2d09f72b29 feat(provider): CodeBuddy CN (copilot.tencent.com) — full stack (#4664)
Integrated into release/v3.8.36 — CodeBuddy CN provider (port efd20be8); usage.ts import + public-creds allowlist line reconciled; release-green
2026-06-23 22:09:04 -03:00

49 lines
1.7 KiB
TypeScript

import { DefaultExecutor } from "./default.ts";
import type { ProviderCredentials } from "./base.ts";
/**
* CodeBuddyCnExecutor — talks to https://copilot.tencent.com/v2/chat/completions
*
* CodeBuddy CN is an OpenAI-compatible Tencent gateway but it rejects non-stream
* chat requests (HTTP 400, code 11101 "Non-stream chat request is currently not
* supported"). The same-format (openai→openai) translator path leaves body.stream
* as the client sent it, so we force it true here — OmniRoute still re-aggregates
* the SSE into a JSON response for non-streaming clients.
*
* CodeBuddy CN only surfaces model reasoning when the request carries the
* official CLI's OpenAI-style params: reasoning_effort + reasoning_summary:"auto".
* Mirror the CLI here. When the caller explicitly asks for "none"/"off" we drop
* the field entirely (the gateway has no "none" value).
*/
export class CodeBuddyCnExecutor extends DefaultExecutor {
constructor() {
super("codebuddy-cn");
}
transformRequest(
model: string,
body: unknown,
stream: boolean,
credentials: ProviderCredentials
): unknown {
const transformed = super.transformRequest(model, body, stream, credentials);
if (!transformed || typeof transformed !== "object" || Array.isArray(transformed)) {
return transformed;
}
const out = transformed as Record<string, unknown>;
out.stream = true;
const eff = out.reasoning_effort;
if (eff === "none" || eff === "off") {
// Gateway has no "none" — just omit. Do NOT set reasoning_summary.
delete out.reasoning_effort;
} else {
if (!eff) out.reasoning_effort = "medium";
out.reasoning_summary = "auto";
}
return out;
}
}
export default CodeBuddyCnExecutor;