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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user