import { PolicyInputMap } from "../policy-input.js"; import { ArcjetMetadata } from "../metadata.js"; import { RuleWithInput } from "../types.js"; //#region src/agents/actor-inputs.d.ts /** * Trusted actor identity, or a resolver over the adapter's native call. * Arguments match that framework's execute / invoke / hook — typically the * parsed tool input plus the trusted runtime or context object, the same * shape Vercel AI uses as `(input, ctx)`. * * Derive the actor from authenticated server-side context; never trust a * model-produced tool input as the actor identity — a policy can be * conditioned on the actor, so a model-controlled value could escape scope. */ export type ActorResolver = string | ((...args: TArgs) => string | Promise); /** * Typed remote-policy inputs, or a resolver over the adapter's native call. * Build each value with {@link ../policy-input.ts}. */ export type InputsResolver = PolicyInputMap | ((...args: TArgs) => PolicyInputMap | Promise); /** Optional `actor` / `inputs` fields shared by vendor wrapper policies. */ export interface ActorInputsPolicy { actor?: ActorResolver; inputs?: InputsResolver; } /** The `actor` and `inputs` a guard call is made with, after their callbacks have run. */ export interface ResolvedActorInputs { /** * The fields to spread into the guard call. A field the policy omits, or * whose callback failed, is absent rather than `undefined`, so it is not * sent under `exactOptionalPropertyTypes`. */ fields: { actor?: string; inputs?: PolicyInputMap; }; /** * The first of the two callbacks that threw, rejected, or returned a value * Guard cannot use, or `undefined` when both succeeded. Pass it on after * `resolveCallPolicy`'s, as `call.degraded ?? remote.degraded`, so the * first failure in the call is the one reported. */ degraded: Error | undefined; } /** * Resolve a helper policy's `actor` and `inputs` without letting a failing * callback skip the guard call. * * A value given directly is passed through unchanged. A function is awaited * with the adapter's native arguments; if it throws, rejects, or returns * something Guard cannot use, its field is left out of the call and the * failure is returned as `degraded`, as `resolveCallPolicy` does for the * other callbacks. Only type and shape are checked: `actor` must be a string, * and `inputs` a plain object whose every value was built with `policyInput`. * The service judges a call that lacks them: a policy that requires the actor * or a missing input is INCOMPLETE there and denies. * * @param policy - The helper's policy; only `actor` and `inputs` are read. * @param action - The label the call is sent under, named in a failure. * @param args - The adapter's native arguments for the two callbacks. */ export declare function resolveActorInputs(policy: ActorInputsPolicy, action: string, ...args: TArgs): Promise; /** * The per-call fields a helper policy may give as a value or as a function of * the call. Each helper passes its own policy: the argument is whatever that * helper hands its callbacks (the tool input, or a `{ toolName, input }` call). */ export interface CallPolicy { action?: string | ((arg: TArg) => string) | undefined; rules?: RuleWithInput[] | ((arg: TArg) => RuleWithInput[]) | undefined; metadata?: ArcjetMetadata | ((arg: TArg) => ArcjetMetadata) | undefined; sessionId?: string | ((arg: TArg) => string | undefined) | undefined; } /** The values a guard call is made with, after every callback has run. */ export interface ResolvedCallPolicy { /** The guard label and capture action. */ action: string; /** Local rules, or `undefined` when there are none to submit. */ rules: RuleWithInput[] | undefined; /** The policy's metadata, to merge over what the helper derives itself. */ metadata: ArcjetMetadata | undefined; /** A session ID that overrides the one the helper derives, if any. */ sessionId: string | undefined; /** * The first callback that threw or returned a value Guard cannot use, or * `undefined` when every callback succeeded. Pass it to `runGuarded` or * `runGate` as `degraded`, ahead of `resolveActorInputs`'s: Guard is still * called without the failed value, and `onGuardError` decides whether the * action proceeds. A capture-only hook records the capture without the * failed value and passes it to `warnCaptureDegraded`. */ degraded: Error | undefined; } /** * Run a helper policy's per-call callbacks without letting one skip the guard * call or the capture. * * A callback that throws, or returns something Guard cannot use, is replaced * by what the helper would send without it: no local rules, no policy * metadata, no session override, and `fallbackAction` for the label. The first * such failure is returned as `degraded`, so remote policy still evaluates the * call and `onGuardError` decides the outcome. `resolveActorInputs` does the * same for the `actor` and `inputs` callbacks. * * Only the return value of a callback is checked, and only for its type and * shape. An `action` callback's string is not run through the guard label * check: the service judges a call-time label, and a rejected one reaches * `onGuardError` as AJ1023. A value given directly is passed through * unchanged, as it always was. * * @param policy - The helper's policy; only the four per-call fields are read. * @param arg - The argument the helper passes to its callbacks. * @param fallbackAction - The label when `action` is not a function, and when * the `action` callback fails. Helpers compute it the way they resolved a * static `action` before, so a static label is unchanged. */ export declare function resolveCallPolicy(policy: CallPolicy, arg: TArg, fallbackAction: string): ResolvedCallPolicy; /** * Warn that Guard judged a call without a callback's value, and what * `onGuardError` did about it. Shared by `runGuarded` and `runGate`. */ export declare function warnDegraded(action: string, failClosed: boolean, error: Error): void; /** * Warn that a capture-only hook recorded a call without a callback's value. * Those hooks make no Guard call, so there is no fail-open or fail-closed * choice to report. */ export declare function warnCaptureDegraded(action: string, error: Error): void; //#endregion