import { PolicyInputMap } from "../policy-input.js"; import { ArcjetMetadata } from "../metadata.js"; import { DecisionAllow, DecisionDeny, RuleWithInput } from "../types.js"; import { ArcjetAgentClient } from "./capture.js"; //#region src/agents/guarded.d.ts /** * The guard → deny → execute → capture sequence shared by `guardTool()` and * `guardAction()`. Callers resolve `rules`, `metadata`, and `correlationId` * (including any per-input functions and overrides) and pass the final values; * a helper with per-call callbacks resolves them with `resolveCallPolicy` and * `resolveActorInputs` and passes the first failure here as `degraded`. This * runs the common flow: * * 1. Call `guard()` — always, including when `rules` is omitted or empty, which * is sent as `[]`. Both guard-unavailable signals (threw and failed-open) * are governed by `onGuardError`: with `"deny"` (the default), both trigger * `onUnavailable` without executing; with `"allow"`, both fail open and * proceed to execute. * 2. On DENY, capture `outcome: "denied"` and return `onDeny(decision)`. * Otherwise, when `degraded` is set — a policy callback failed, and its * resolver left the value out of the call — `onGuardError` decides as for * the signals above: `"deny"` captures `outcome: "unavailable"` with the * decision ID and returns * `onUnavailable({ kind: "threw", error: degraded })`; `"allow"` proceeds * unjudged. * 3. Otherwise run `execute()`, capturing `outcome: "success"` when policy * judged the action, or `outcome: "degraded"` when `"allow"` let it run * unjudged — or, if it throws, `outcome: "error"` before rethrowing. * * `onDeny` returns the value the caller hands back on denial. Model-facing * helpers wrap the shared `ArcjetDenialResult` in a framework-idiomatic * envelope; `guardAction` throws `ArcjetDeniedError`. Those are different * handlers — they must not be the same function. */ export declare function runGuarded(client: ArcjetAgentClient, params: { action: string; rules: RuleWithInput[] | undefined; correlationId: string | undefined; metadata: ArcjetMetadata; actor?: string; inputs?: PolicyInputMap; degraded?: Error | undefined; onDeny: (decision: DecisionDeny) => T; onUnavailable: (unavailable: { kind: "threw"; error: unknown; } | { kind: "failed-open"; decision: DecisionAllow; }) => T; execute: () => Promise; onGuardError?: "allow" | "deny"; }): Promise; //#endregion