UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

26 lines (25 loc) • 1.26 kB
import { thrownLabel } from "../thrown-value.js"; import { egressText, egressThrownText } from "../untrusted-egress.js"; import { inlineUntrusted, PROBE_REASON_MAX } from "../untrusted-text.js"; export function policyThrowLine(err) { const line = inlineUntrusted(egressThrownText("same-principal", err), PROBE_REASON_MAX); return line === "" ? "(no message)" : line; } export function policyCheckAbortedDeny() { return { action: "deny", message: "policy check aborted (task timed out or cancelled)" }; } export function failedJudgmentDeny(err, signal, report, seat, call) { if (signal?.aborted === true) return policyCheckAbortedDeny(); reportPolicyThrow(report, seat, call, err); return { action: "deny", message: `policy check threw — the tool policy chain failed while judging this call (not a timeout or cancellation), so it was denied fail-closed: ${policyThrowLine(err)}` }; } export function reportPolicyThrow(report, seat, call, err, signal) { if (signal?.aborted === true) return; try { report(new Error(`${seat} threw while judging "${call.toolName}" (toolCallId ${call.toolCallId}); the call was denied fail-closed: ${egressText("same-principal", thrownLabel(err))}`)); } catch { } }