refactor(coding-agent/modes): added ACP type guards for elicitation narrowing

- Added `isAcceptedElicitation` in the ACP agent to narrow accepted elicitations before accessing response content.
- Added `isFormElicitation` in ACP tests and used it to narrow form-mode requests before assertions.
This commit is contained in:
can1357
2026-07-13 18:53:19 +02:00
parent c69c048361
commit 59ecd2a4d8
2 changed files with 19 additions and 5 deletions
@@ -351,12 +351,19 @@ async function elicitFromAcpClient(
finish(undefined);
});
const response = await promise;
if (response?.action !== "accept" || !response.content) {
if (!isAcceptedElicitation(response) || !response.content) {
return undefined;
}
return response.content.value;
}
/** Narrows a `CreateElicitationResponse` to the accepted-with-content branch; the SDK's `action: string` catch-all arm otherwise defeats literal narrowing on `action !== "accept"`. */
function isAcceptedElicitation(
response: CreateElicitationResponse | undefined,
): response is Extract<CreateElicitationResponse, { action: "accept" }> {
return response?.action === "accept";
}
/**
* Build an {@link ExtensionUIContext} that translates skill/extension UI
* requests into ACP elicitations against `connection` for the session