/** * The single role/context/policy gate every action exposure and execution path * consults before an action may be surfaced to the planner or run — composing * the private-action gate, the operator role policy, the context gate, and the * top-level role gate in a fixed precedence. */ import type { Action } from "../types/components.js"; import type { AgentContext, RoleGateRole } from "../types/contexts.js"; import type { Memory } from "../types/memory.js"; import type { IAgentRuntime } from "../types/runtime.js"; /** * The subset of {@link Action} fields the unified gate reads. Keeping the * parameter structural (rather than a full `Action`) lets non-runtime callers * gate a plain descriptor without constructing a handler. */ export type GateableAction = Pick; /** * Everything the gate needs about the current turn/actor. Deliberately a * structural subset of `ExecutePlannedToolCallContext` so the executor can pass * its context straight through. */ export interface ActionGateContext { message?: Memory; userRoles?: readonly RoleGateRole[]; activeContexts?: readonly AgentContext[]; /** * Skip the private-action gate. Only static exposure/selection paths that do * not correspond to a concrete turn (e.g. building a coding sub-agent's * candidate-action set) may set this — the eventual execution still runs * through the executor, which enforces the private gate. Execution paths MUST * leave it `false` so a hallucinated or forced tool call cannot run a private * (autonomy-only) action on a user turn. */ skipPrivateGate?: boolean; } export type ActionGateRejectionKind = "private" | "disclosure" | "role" | "context"; export interface ActionGateRejection { kind: ActionGateRejectionKind; reason: string; } export declare function withActionGatePolicy(policy: (action: GateableAction, context: ActionGateContext) => string | undefined, run: () => Promise): Promise; /** * The host's product allowlist from `ELIZA_ACTION_ALLOWLIST`: a JSON array of * exact action names, or `null` when the setting is unset (every action stays * subject to its own gates). Unlike `ACTION_ROLE_POLICY`, which can only set * minimum roles, the allowlist also refuses an OWNER caller and the agent's * own autonomous and trigger turns. An empty value, malformed JSON or a * non-string entry throws, so a broken setting never disables the allowlist. */ export declare function readActionAllowlist(env?: NodeJS.ProcessEnv): ReadonlySet | null; /** * Throw when an `ELIZA_ACTION_ALLOWLIST` entry names no registered action, so * an action renamed upstream fails the boot instead of silently leaving the * product without it. Names are exact: a simile never matches. The check sees * only the actions passed in: the agent runs it once, when the deferred boot * ends, so an action a plugin registers later (a runtime hot-apply) is not * checked. */ export declare function assertActionAllowlistMatchesActions(actions: readonly Pick[]): void; /** * The single role/context/policy gate deciding whether `action` may run for * `ctx`. Composes, in order: * * 1. the private-action gate (unless `skipPrivateGate`), * 2. the non-overridable destination disclosure gate, * 3. the host's `ELIZA_ACTION_ALLOWLIST`, for every caller including the * agent itself, * 4. the request-scoped {@link withActionGatePolicy} restriction, * 5. the operator `ACTION_ROLE_POLICY` override — when set for this action it * **replaces** the declared gates and access is decided solely by the * policy role, * 6. the contextGate (derived from `contextGate ?? {contexts, roleGate}`), * 7. the top-level roleGate. * * Returns a human-readable failure reason, or `undefined` when the action is * allowed. Every exposure and execution path — planner selection, sub-planner * child filtering, the tool-call executor, and the shortcut gate — routes * through this one function so their outcomes cannot drift apart. */ export declare function actionGateRejection(action: GateableAction, ctx: ActionGateContext): ActionGateRejection | undefined; /** Human-readable compatibility form of {@link actionGateRejection}. */ export declare function actionGateFailure(action: GateableAction, ctx: ActionGateContext): string | undefined; /** Boolean form of {@link actionGateFailure}. */ export declare function canActionRun(action: GateableAction, ctx: ActionGateContext): boolean; /** * Resolve the caller's canonical role for gate evaluation. The agent itself is * OWNER; a missing canonical room/world is GUEST (the non-authorizing floor); * a role-store failure throws rather than guessing a role. */ export declare function resolveActionCallerRoles(runtime: IAgentRuntime, message: Memory): Promise; /** True when evaluating `action` needs the caller's resolved role. */ export declare function actionGateNeedsCallerRoles(action: GateableAction): boolean; /** * {@link actionGateFailure} for a concrete turn, resolving the caller's role * only when the action declares a role requirement. Used by execution paths * that do not come through the planned tool-call executor (mode hooks, plan * steps) so every path applies the same gate. */ export declare function resolveActionGateFailure(runtime: IAgentRuntime, action: GateableAction, ctx: Omit & { message: Memory; /** * `false` for paths that never selected contexts for this execution * (non-CONTEXT mode hooks, plan steps): context declarations are routing * metadata there, while private/disclosure/role requirements still apply. */ evaluateContexts?: boolean; }): Promise;