fix: remove unshifted current modelId and add auth error response

This commit is contained in:
mingholy.lmh 2026-01-27 10:08:49 +08:00
parent 889c49f0f4
commit 6fa11a7bae
3 changed files with 22 additions and 22 deletions

View file

@ -286,6 +286,10 @@ class Connection {
return RequestError.authRequired(details).toResult();
}
if (details?.includes('/auth')) {
return RequestError.authRequired(details).toResult();
}
return RequestError.internalError(details).toResult();
}
}

View file

@ -380,10 +380,10 @@ class GeminiAgent {
const allConfiguredModels = config.getAllConfiguredModels();
const baseCurrentModelId = parseAcpBaseModelId(rawCurrentModelId);
const currentModelId =
currentAuthType && baseCurrentModelId
? formatAcpModelId(baseCurrentModelId, currentAuthType)
: baseCurrentModelId;
const currentModelId = this.formatCurrentModelId(
baseCurrentModelId,
currentAuthType,
);
const availableModels = allConfiguredModels;
@ -396,26 +396,20 @@ class GeminiAgent {
},
}));
if (
currentModelId &&
!mappedAvailableModels.some((model) => model.modelId === currentModelId)
) {
const currentContextWindowSize =
config.getContentGeneratorConfig()?.contextWindowSize ??
tokenLimit(currentModelId);
mappedAvailableModels.unshift({
modelId: currentModelId,
name: currentModelId,
description: null,
_meta: {
contextLimit: currentContextWindowSize,
},
});
}
return {
currentModelId,
availableModels: mappedAvailableModels,
};
}
private formatCurrentModelId(
baseModelId: string,
authType?: AuthType,
): string {
if (!baseModelId) {
return baseModelId;
}
return authType ? formatAcpModelId(baseModelId, authType) : baseModelId;
}
}

View file

@ -371,7 +371,9 @@ export class Session implements SessionContext {
const selectedAuthType = parsed.authType ?? previousAuthType;
if (!selectedAuthType) {
throw acp.RequestError.invalidParams('authType cannot be determined');
throw acp.RequestError.invalidParams(
`authType cannot be determined for modelId "${parsed.modelId}"`,
);
}
await this.config.switchModel(