diff --git a/src/main/acp/acp-dialects/omp-dialect.ts b/src/main/acp/acp-dialects/omp-dialect.ts index 1714184b35f..0e38a7c2db5 100644 --- a/src/main/acp/acp-dialects/omp-dialect.ts +++ b/src/main/acp/acp-dialects/omp-dialect.ts @@ -9,6 +9,8 @@ import type { AcpDialect } from './acp-dialect' // background launch results do not establish a process exit. const textBlockSchema = z.looseObject({ type: z.literal('text'), text: z.string() }) const promptErrorDataSchema = z.looseObject({ details: z.string() }) +// OMP's prompt check: no usable model (nothing signed in), or the selected model's provider has no key. +const SIGNED_OUT_DETAIL_PREFIXES = ['No model selected.\n\nUse /login', 'No API key found for '] const toolResultSchema = z.looseObject({ content: z.array(z.unknown()), details: z @@ -95,9 +97,12 @@ function normalizeToolUpdate(update: ToolCallUpdate): ToolCallUpdate { export const OMP_ACP_DIALECT: AcpDialect = { normalizeToolUpdate, promptErrorDetail: (error) => promptErrorDataSchema.safeParse(error.data).data?.details, - authenticationRequired: (error) => - error.code === -32603 && - promptErrorDataSchema - .safeParse(error.data) - .data?.details.startsWith('No API key found for ') === true + authenticationRequired: (error) => { + const details = promptErrorDataSchema.safeParse(error.data).data?.details + return ( + error.code === -32603 && + details !== undefined && + SIGNED_OUT_DETAIL_PREFIXES.some((prefix) => details.startsWith(prefix)) + ) + } } diff --git a/src/main/acp/acp-structured-sign-in.test.ts b/src/main/acp/acp-structured-sign-in.test.ts index 06c4b8294d1..f7349b78470 100644 --- a/src/main/acp/acp-structured-sign-in.test.ts +++ b/src/main/acp/acp-structured-sign-in.test.ts @@ -99,6 +99,11 @@ it.each([ 'No API key found for anthropic.\n\nUse /login, set an API key environment variable, or create /host/agent.db', 'notSignedIn' ], + [ + 'No model selected.\n\nUse /login, set an API key environment variable, or create /host/agent.db\n\nThen use /model to select a model.', + 'notSignedIn' + ], + ['No model selected', undefined], ['Rate limit exceeded', undefined], ['Network connection failed', undefined], ['No API key found elsewhere', undefined]