mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-04 06:12:10 +03:00
feat: Add requested model to logs, enhance background task detection, and introduce AI SDK compatibility utilities.
This commit is contained in:
64
src/shared/services/opencodeConfig.ts
Normal file
64
src/shared/services/opencodeConfig.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
type OpenCodeConfigInput = {
|
||||
baseUrl?: string;
|
||||
apiKey?: string;
|
||||
model?: string;
|
||||
};
|
||||
|
||||
type OpenCodeProviderConfig = {
|
||||
name: string;
|
||||
api: "openai";
|
||||
baseURL: string;
|
||||
apiKey: string;
|
||||
models: string[];
|
||||
};
|
||||
|
||||
const OPENCODE_DEFAULT_MODELS = [
|
||||
"claude-opus-4-5-thinking",
|
||||
"claude-sonnet-4-5-thinking",
|
||||
"gemini-3.1-pro-high",
|
||||
"gemini-3-flash",
|
||||
] as const;
|
||||
|
||||
const normalizeValue = (value: unknown) =>
|
||||
String(value || "")
|
||||
.trim()
|
||||
.replace(/^\/+/, "");
|
||||
|
||||
export const buildOpenCodeProviderConfig = ({
|
||||
baseUrl,
|
||||
apiKey,
|
||||
model,
|
||||
}: OpenCodeConfigInput): OpenCodeProviderConfig => {
|
||||
const normalizedBaseUrl = String(baseUrl || "")
|
||||
.trim()
|
||||
.replace(/\/+$/, "");
|
||||
const normalizedModel = normalizeValue(model);
|
||||
|
||||
const uniqueModels = [...new Set([normalizedModel, ...OPENCODE_DEFAULT_MODELS].filter(Boolean))];
|
||||
|
||||
return {
|
||||
name: "OmniRoute",
|
||||
api: "openai",
|
||||
baseURL: normalizedBaseUrl,
|
||||
apiKey: apiKey || "sk_omniroute",
|
||||
models: uniqueModels,
|
||||
};
|
||||
};
|
||||
|
||||
export const mergeOpenCodeConfig = (
|
||||
existingConfig: Record<string, any> | null | undefined,
|
||||
input: OpenCodeConfigInput
|
||||
) => {
|
||||
const safeConfig =
|
||||
existingConfig && typeof existingConfig === "object" && !Array.isArray(existingConfig)
|
||||
? existingConfig
|
||||
: {};
|
||||
|
||||
return {
|
||||
...safeConfig,
|
||||
providers: {
|
||||
...((safeConfig as any).providers || {}),
|
||||
omniroute: buildOpenCodeProviderConfig(input),
|
||||
},
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user