Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,16 @@ function resolveOpenCodeModelId(vendor: RuntimeCatalogVendor, model: string): st
return model;
}

function resolveOpenCodeProviderModelId(vendor: RuntimeCatalogVendor, model: string): string {
const openCodeProviderId = resolveOpenCodeProviderId(vendor);
const openCodeModel = resolveOpenCodeModelId(vendor, model);
const providerPrefix = `${openCodeProviderId}/`;

return openCodeModel.startsWith(providerPrefix)
? openCodeModel.slice(providerPrefix.length)
: openCodeModel;
}

function resolveOpenCodeProxyBaseUrl(vendor: RuntimeCatalogVendor, proxyUrl: string): string {
// OpenCode's native providers resolve request paths against a base that
// already contains the SDK path prefix. @ai-sdk/anthropic defaults to
Expand All @@ -225,17 +235,20 @@ function buildOpenCodeProviderConfig(input: OpenCodeProviderConfigInput): OpenCo
const options: Record<string, string> = {
apiKey: `{env:${input.vendor.apiKeyEnvVar}}`,
};
const models =
input.credential.models === null
? undefined
: Object.fromEntries(input.credential.models.map((modelId) => [modelId, { name: modelId }]));
// OpenCode removes configured providers that have no models. An unrestricted
// Mosoo credential still needs the active model rendered for ACP startup.
const declaredModelIds = new Set(input.credential.models ?? []);
declaredModelIds.add(resolveOpenCodeProviderModelId(input.vendor, input.model));
const models = Object.fromEntries(
[...declaredModelIds].map((modelId) => [modelId, { name: modelId }]),
);
const provider = input.vendor.openCodeProvider;

if (provider === undefined) {
options["baseURL"] = resolveOpenCodeProxyBaseUrl(input.vendor, input.proxyUrl);

return {
...(models === undefined ? {} : { models }),
models,
options,
};
}
Expand All @@ -246,7 +259,7 @@ function buildOpenCodeProviderConfig(input: OpenCodeProviderConfigInput): OpenCo
);

return {
...(models === undefined ? {} : { models }),
models,
name: provider.name,
npm: provider.npmPackage,
options,
Expand Down
36 changes: 36 additions & 0 deletions apps/api/tests/runtime-vendor-env-vars.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,11 @@ describe("runtime vendor proxy env vars", () => {
small_model: `${providerId}/${model}`,
provider: {
[providerId]: {
models: {
[model]: {
name: model,
},
},
name,
npm,
options: {
Expand Down Expand Up @@ -548,4 +553,35 @@ describe("runtime vendor proxy env vars", () => {
},
});
});

test("declares the selected custom OpenCode model for an unrestricted credential", async () => {
const envVars = await buildVendorProxyEnvVars({
bindings: BINDINGS,
driverGeneration: DRIVER_GENERATION,
driverInstanceId: DRIVER_INSTANCE_ID,
profile: {
model: "deepseek-v4-flash",
runtimeId: "acp-fallback",
vendorCredential: vendorCredential({
apiBase: "https://api.deepseek.com",
vendorId: "openai-compatible",
}),
},
requestUrl: REQUEST_URL,
});

expect(parseOpenCodeConfig(envVars)).toMatchObject({
enabled_providers: ["openai-compatible"],
model: "openai-compatible/deepseek-v4-flash",
provider: {
"openai-compatible": {
models: {
"deepseek-v4-flash": {
name: "deepseek-v4-flash",
},
},
},
},
});
});
});
Loading