OmniRoute/open-sse/executors/codebuddy-intl.ts
Junior-HJ f966efb9ba
feat(providers): add CodeBuddy international (codebuddy-intl, cbai) provider (#15173) (#15799)
Thanks @Junior-HJ! This adds CodeBuddy international (codebuddy-intl / cbai), splitting the CN and intl modules over shared executor, OAuth, usage and token-refresh helpers. Your commits are kept intact. Maintainer fix-up commits on top: restored the 'N AI providers' wording that the count bump had turned into bare numbers in 67 llm.txt files, README alt texts and SVGs; synced the total to 372, since the tip had meanwhile added typesafe without regenerating the reference; typed the two `any` casts in codebuddyDeviceAuth.ts; and regenerated the executor-map and translate-path goldens. The translate-path golden had been generated on win32. Protected surfaces (AGENTS.md, llm.txt) carry the count change only, approved by the owner. Validated: typecheck:core, open-sse typecheck, file-size, t11 any-budget, ESLint, check:docs-all, provider consistency/assets/order/provenance, and 195/195 focused tests across 13 files.
2026-10-09 22:03:05 -03:00

38 lines
1.3 KiB
TypeScript

import { CodeBuddyBaseExecutor, NEUTRAL_PROMPT } from "./codebuddy/shared.ts";
import type { ProviderCredentials } from "./base.ts";
/**
* CodeBuddyIntlExecutor — talks to https://www.codebuddy.ai/v2/chat/completions
*
* CodeBuddy International gateway strictly requires the first message in the
* request to be a system prompt (rejects with 400 "first message is not system
* prompt" otherwise). Inherits all shared CodeBuddy gateway behavior and
* prepends a neutral system prompt when callers/probes send none.
*/
export class CodeBuddyIntlExecutor extends CodeBuddyBaseExecutor {
constructor(providerId: string = "codebuddy-intl") {
super(providerId);
}
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>;
if (Array.isArray(out.messages)) {
const first = out.messages[0] as Record<string, unknown> | undefined;
if (!first || first.role !== "system") {
out.messages = [{ role: "system", content: NEUTRAL_PROMPT }, ...out.messages];
}
}
return out;
}
}