UNPKG

@adonis-agora/agent

Version:

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

108 lines • 4.97 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; import { args, flags } from '@adonisjs/core/ace'; import { AgentCommand, opt } from '../src/cli/agent_command.js'; import { decideToolCall, decisionRefusal, } from '../src/tool-call-decision.js'; /** * A shell on the app is the operator: it may decide any requester-approved call, like a console * viewer `authorize` lets act across actors. A call routed to an approver role still needs that * role (the approval policy's `canDecide`), which a CLI actor does not hold. */ const OPERATOR = async () => true; /** * Approve or reject a parked tool call through the same rules as the console's approvals inbox * (`decideToolCall`): ownership or the recorded approver's role, expiry, a run that already ended. * The decision is recorded as made by `cli:<os user>`, through `cli`. */ class DecideCommand extends AgentCommand { /** Refuse (exit `1`); with `--json`, first print `{ ok: false, toolCallId, status, message }`. */ refuseDecision(refusal) { if (this.json) { this.logger.log(JSON.stringify({ ok: false, toolCallId: this.toolCallId, ...refusal }, null, 2)); } return this.refuse(refusal.message); } async execute() { const service = await this.agentService(); const actor = this.cliActor(); const runId = opt(this.runId) ?? (await service.toolCallRun(this.toolCallId)); if (runId === null) { return this.refuseDecision({ status: 404, message: `Unknown tool call "${this.toolCallId}".`, }); } // Refuse before asking: the same checks the decision itself runs (and runs again). const refusal = await decisionRefusal(service, { actor, runId, toolCallId: this.toolCallId, privileged: OPERATOR, fromAnotherProcess: true, }); if (refusal !== null) return this.refuseDecision(refusal); if (!(await this.confirmed(this.force, `${this.verb} tool call ${this.toolCallId}?`))) { return this.refuse('Cancelled.'); } const outcome = await decideToolCall(service, { actor, toolCallId: this.toolCallId, runId, decision: this.decision(), privileged: OPERATOR, fromAnotherProcess: true, }); if (!outcome.ok) return this.refuseDecision(outcome.refusal); const result = { ok: true, toolCallId: this.toolCallId, runId: outcome.runId, by: actor.id, }; return this.output(result, () => this.logger.success(`${this.verb === 'approve' ? 'Approved' : 'Rejected'} ${this.toolCallId}`)); } } __decorate([ args.string({ description: 'Tool call id' }) ], DecideCommand.prototype, "toolCallId", void 0); __decorate([ flags.string({ flagName: 'run', description: 'The run the call belongs to (default: read off the call)', }) ], DecideCommand.prototype, "runId", void 0); __decorate([ flags.boolean({ description: 'Skip the confirmation' }) ], DecideCommand.prototype, "force", void 0); /** `agent:approvals:approve <toolCallId>` — release a call waiting for a human approval. */ export class AgentApprovalsApprove extends DecideCommand { static commandName = 'agent:approvals:approve'; static description = 'Approve a tool call waiting for a human approval'; verb = 'approve'; decision() { return { kind: 'approve', remember: this.remember === true, via: 'cli' }; } } __decorate([ flags.boolean({ description: 'Also approve later calls of this tool in the same thread' }) ], AgentApprovalsApprove.prototype, "remember", void 0); /** `agent:approvals:reject <toolCallId>` — deny a call waiting for a human approval. */ export class AgentApprovalsReject extends DecideCommand { static commandName = 'agent:approvals:reject'; static description = 'Reject a tool call waiting for a human approval'; verb = 'reject'; decision() { const note = opt(this.note); return { kind: 'reject', ...(note !== undefined ? { reason: note } : {}), via: 'cli' }; } } __decorate([ flags.string({ description: 'Why: recorded with the rejection and shown to the model' }) ], AgentApprovalsReject.prototype, "note", void 0); //# sourceMappingURL=agent_approvals.js.map