UNPKG

@adonis-agora/agent

Version:

Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.

69 lines • 3.23 kB
import type { AgentService } from './agent-service.js'; import type { Actor } from './types.js'; /** Why a HITL decision was not delivered: the HTTP status the routes answer, and the message. */ export interface DecisionRefusal { status: 403 | 404 | 409 | 410 | 501; message: string; code?: string; } /** The approve or reject a person makes on a parked tool call. */ export type ToolCallDecision = { kind: 'approve'; remember?: boolean; via?: string; } | { kind: 'reject'; reason?: string; via?: string; }; export type ToolCallDecisionOutcome = { ok: true; runId: string; } | { ok: false; refusal: DecisionRefusal; }; /** * Deliver one approve/reject to a parked tool call, under the HITL rules every surface shares * (`POST <path>/tool-call/approve|reject`, the console's approvals inbox, `agent:approvals:*`): * * 1. The run is the given `runId`, else the call's own row (unknown call → `404`). * 2. The call's recorded approver decides who may answer: the requester (the default) is the run's * own actor, or a caller `privileged` says may act across actors; any other approver goes through * the approval policy's `canDecide` (by default: holds that role) → `403`. * 3. A request that already lapsed (recorded `expired`, or past its `expiresAt`) → `410`. * 4. `fromAnotherProcess`: the caller is not the process running the turns (the CLI). Unless the * runner's signals reach other processes (the durable runner), nothing there could resume the * run → `501`, before anything is written. (Steps 2–4: {@link decisionRefusal}.) * 5. Delivered through `AgentService.approve`/`reject`; a run that has ended or a reply of the wrong * kind → `409`. * * `privileged` is asked only for a requester-approved call. */ export declare function decideToolCall(service: AgentService, input: { actor: Actor; toolCallId: string; runId?: string | undefined; privileged: () => Promise<boolean>; decision: ToolCallDecision; fromAnotherProcess?: boolean; }): Promise<ToolCallDecisionOutcome>; /** * May `actor` settle this call, and is it still open? `null` when so, else the refusal. The call's * recorded approver decides who: the requester (the default, and every call recorded before * approvers existed) is the run's own actor, or a caller `privileged` says may act across actors; * any other approver goes through the policy's `canDecide` (by default: holds that role) → `403`. * A request that already lapsed — recorded `expired`, or past its `expiresAt` with the run's own * timer about to fire — is `410`: signalling it anyway would race the timeout, and a late approval * must not be what a later replay of the run reads back. `fromAnotherProcess` (the CLI): unless the * runner's signals reach other processes (the durable runner), nothing there could resume the run * → `501`, before anything is written. */ export declare function decisionRefusal(service: AgentService, input: { actor: Actor; runId: string; toolCallId: string; privileged: () => Promise<boolean>; fromAnotherProcess?: boolean; }): Promise<DecisionRefusal | null>; //# sourceMappingURL=tool-call-decision.d.ts.map