fix(opencode): keep model switching runtime-hot
This commit is contained in:
@@ -278,7 +278,12 @@ export function createOpencodeClient(options: OpencodeClientOptions) {
|
||||
): Promise<void> =>
|
||||
request<void>(`/api/session/${encodeURIComponent(sessionID)}/model`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ model }),
|
||||
body: JSON.stringify({
|
||||
model: {
|
||||
providerID: model.providerID,
|
||||
id: model.modelID,
|
||||
},
|
||||
}),
|
||||
signal: options?.signal,
|
||||
}),
|
||||
executeSessionCommand: (
|
||||
|
||||
@@ -23,6 +23,7 @@ const OPENAI_COMPATIBLE_PACKAGE = '@ai-sdk/openai-compatible';
|
||||
const OPENAI_PACKAGE = '@ai-sdk/openai';
|
||||
const ANTHROPIC_PACKAGE = '@ai-sdk/anthropic';
|
||||
const WORKS_SQUARE_AI_GATEWAY_CREDENTIAL_MODE = 'works_square_ai_gateway';
|
||||
const WORKS_SQUARE_AI_GATEWAY_PROXY_CREDENTIAL_MODE = 'works_square_ai_gateway_proxy';
|
||||
|
||||
const OPENCODE_BUILTIN_PROVIDER_IDS = new Set([
|
||||
'anthropic',
|
||||
@@ -120,6 +121,7 @@ export interface BuildOpencodeRuntimeConfigOptions {
|
||||
accounts: ProviderAccount[];
|
||||
defaultAccountId?: string | null;
|
||||
resolveApiKey: ResolveOpencodeProviderApiKey;
|
||||
localProxyApiKey?: string;
|
||||
mcpServers?: Record<string, OpencodeMcpServerEntry>;
|
||||
}
|
||||
|
||||
@@ -303,7 +305,11 @@ export async function buildOpencodeRuntimeConfig(
|
||||
continue;
|
||||
}
|
||||
|
||||
const apiKey = await options.resolveApiKey(account, opencodeProviderId);
|
||||
const localProxyApiKey = account.id === NIANCODE_USER_MODEL_ACCOUNT_ID
|
||||
&& account.metadata?.worksSquareCredentialMode === WORKS_SQUARE_AI_GATEWAY_PROXY_CREDENTIAL_MODE
|
||||
? options.localProxyApiKey
|
||||
: undefined;
|
||||
const apiKey = localProxyApiKey ?? await options.resolveApiKey(account, opencodeProviderId);
|
||||
if (!apiKey && accountNeedsApiKey(account)) {
|
||||
continue;
|
||||
}
|
||||
@@ -367,6 +373,7 @@ async function resolveNianCodeApiKey(
|
||||
}
|
||||
|
||||
export interface BuildOpencodeRuntimeConfigFromNianCodeProvidersOptions {
|
||||
localProxyApiKey?: string;
|
||||
mcpServers?: Record<string, OpencodeMcpServerEntry>;
|
||||
}
|
||||
|
||||
@@ -383,6 +390,7 @@ export async function buildOpencodeRuntimeConfigFromNianCodeProviders(
|
||||
accounts,
|
||||
defaultAccountId,
|
||||
resolveApiKey: resolveNianCodeApiKey,
|
||||
localProxyApiKey: options.localProxyApiKey,
|
||||
mcpServers: options.mcpServers,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user