UNPKG

@adonis-agora/agent

Version:

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

28 lines • 1.44 kB
import { DefaultApprovalPolicy } from './spi/approval-policy.js'; /** Journal this result on the trusted producer before choosing strict proposal preparation. */ export async function resolveActionProposalApproval(input) { const policy = input.policy ?? new DefaultApprovalPolicy(); const requirement = await policy.requirementFor(input.tool, input.actor, input.thread); if (!requirement.required) return { mode: 'auto' }; const remembered = (await input.store.rememberedApprovals?.(input.thread.threadId)) ?? []; if (remembered.includes(input.tool.name)) return { mode: 'remembered', approver: requirement.approver }; // The tool's own lifetime (a sign-in link's) over the policy's. const ttl = input.tool.spec?.approvalTtlMs ?? requirement.ttlMs; const roundedTtl = ttl !== undefined && Number.isFinite(ttl) ? Math.floor(ttl) : 0; if (roundedTtl <= 0) return { mode: 'ask', approver: requirement.approver }; const now = (input.clock ?? Date.now)(); if (!Number.isSafeInteger(now) || !Number.isSafeInteger(roundedTtl) || !Number.isSafeInteger(now + roundedTtl)) throw new RangeError('Invalid action approval deadline'); return { mode: 'ask', approver: requirement.approver, ttlMs: roundedTtl, expiresAt: new Date(now + roundedTtl).toISOString(), }; } //# sourceMappingURL=action-proposal-approval.js.map