@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
27 lines • 1.6 kB
JavaScript
import { answeredUiRequestId, refusedExtensionUiResponse, settleExtensionUiResponse, } from "./extension-ui-response.js";
/**
* The `answer`-class entry point: settles one `extension_ui_response` and returns its reply, or undefined when
* a single-session stdio connection ignores an unnamed response that matches none of its requests. The first
* answer to settle a request wins; a later one is refused (see `SessionExtensionUiRequests.resolve`).
*/
export function answerExtensionUiResponse(response, targets) {
// The grant rules apply to the request this response answers (`uiRequestId`, or `id` in the
// short form), the same request `settleExtensionUiResponse` settles.
const answered = answeredUiRequestId(response);
if ((answered !== undefined && targets.secretInputs.has(answered)) ||
("secret" in response && response.secret === true))
return targets.secretInputs.respond(response);
if (!targets.workerSecurityBridge && answered !== undefined && targets.grantRequests.has(answered)) {
// The sender hears the refusal, so its dialog does not vanish as if the answer had counted.
if (targets.grantRequests.get(answered) !== targets.sender || !targets.grantCapable())
return refusedExtensionUiResponse(response.id, "grant_answer_refused");
}
return settleExtensionUiResponse(response, {
questions: targets.questions,
dialogs: targets.dialogs,
routed: targets.routed,
ledger: targets.ledger,
beforeAnswer: targets.beforeAnswer,
});
}
//# sourceMappingURL=handlers-answer.js.map