mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-03 13:52:09 +03:00
fix(cli): align OpenCode config preview and add multi-model selection (#1602)
Integrated into release/v3.7.0
This commit is contained in:
@@ -2,6 +2,7 @@ type OpenCodeConfigInput = {
|
||||
baseUrl?: string;
|
||||
apiKey?: string;
|
||||
model?: string;
|
||||
models?: string[];
|
||||
};
|
||||
|
||||
const OPENCODE_DEFAULT_MODELS = [
|
||||
@@ -16,17 +17,27 @@ const normalizeValue = (value: unknown) =>
|
||||
.trim()
|
||||
.replace(/^\/+/, "");
|
||||
|
||||
const normalizeModels = (models: unknown): string[] => {
|
||||
if (!Array.isArray(models)) return [];
|
||||
return [...new Set(models.map((model) => normalizeValue(model)).filter(Boolean))];
|
||||
};
|
||||
|
||||
export const buildOpenCodeProviderConfig = ({
|
||||
baseUrl,
|
||||
apiKey,
|
||||
model,
|
||||
models,
|
||||
}: OpenCodeConfigInput): Record<string, any> => {
|
||||
const normalizedBaseUrl = String(baseUrl || "")
|
||||
.trim()
|
||||
.replace(/\/+$/, "");
|
||||
const normalizedModel = normalizeValue(model);
|
||||
const normalizedModels = normalizeModels(models);
|
||||
|
||||
const uniqueModels = [...new Set([normalizedModel, ...OPENCODE_DEFAULT_MODELS].filter(Boolean))];
|
||||
const uniqueModels =
|
||||
normalizedModels.length > 0
|
||||
? normalizedModels
|
||||
: [...new Set([normalizedModel, ...OPENCODE_DEFAULT_MODELS].filter(Boolean))];
|
||||
|
||||
const modelsRecord: Record<string, { name: string }> = {};
|
||||
for (const m of uniqueModels) {
|
||||
@@ -46,6 +57,13 @@ export const buildOpenCodeProviderConfig = ({
|
||||
};
|
||||
};
|
||||
|
||||
export const buildOpenCodeConfigDocument = (input: OpenCodeConfigInput) => ({
|
||||
$schema: "https://opencode.ai/config.json",
|
||||
provider: {
|
||||
omniroute: buildOpenCodeProviderConfig(input),
|
||||
},
|
||||
});
|
||||
|
||||
export const mergeOpenCodeConfig = (
|
||||
existingConfig: Record<string, any> | null | undefined,
|
||||
input: OpenCodeConfigInput
|
||||
@@ -57,6 +75,7 @@ export const mergeOpenCodeConfig = (
|
||||
|
||||
return {
|
||||
...safeConfig,
|
||||
$schema: safeConfig.$schema || "https://opencode.ai/config.json",
|
||||
provider: {
|
||||
...((safeConfig as any).provider || {}),
|
||||
omniroute: buildOpenCodeProviderConfig(input),
|
||||
|
||||
Reference in New Issue
Block a user