ComposablePolicy
@totemsdk/agent-policy / ComposablePolicy
Class: ComposablePolicy
ComposablePolicy chains multiple PolicyMiddleware layers into a single
evaluation pipeline. Layers are evaluated in registration order with
short-circuit semantics: if any layer returns rejected, subsequent
layers are skipped and the rejection is returned immediately.
ComposablePolicy also implements the legacy AgentPolicy interface
(canAutoApprove / requiresUserApproval) so it can be used anywhere
the old interface is expected (e.g. @totemsdk/omnia's executeIntent).
Middleware contract
approved→ continue to next layerrejected→ short-circuit, return rejectionrequires_human→ short-circuit, return requires_human
An empty middleware list approves all proposals (pass-through).
Implements
Constructors
Constructor
new ComposablePolicy(
layers):ComposablePolicy
Parameters
layers
Returns
ComposablePolicy
Methods
canAutoApprove()
canAutoApprove(
proposal):Promise<boolean>
Return true if the wallet should sign the intent without user interaction. Implementations typically check risk, amount thresholds, and known agents.
Parameters
proposal
Returns
Promise<boolean>
Implementation of
commit()
commit(
operationId):Promise<void>
Commit a prior reservation after execution succeeds.
Parameters
operationId
string
Returns
Promise<void>
Implementation of
evaluate()
evaluate(
proposal):Promise<PolicyEvalResult>
Evaluate a proposal. Called in sequence by ComposablePolicy.
Parameters
proposal
Returns
Promise<PolicyEvalResult>
Implementation of
release()
release(
operationId):Promise<void>
Release a prior reservation after execution fails or is cancelled.
Parameters
operationId
string
Returns
Promise<void>
Implementation of
requiresUserApproval()
requiresUserApproval(
proposal):Promise<boolean>
Return true if the wallet must show a user-approval UI before signing. Generally the complement of canAutoApprove, but may have independent logic (e.g. always require approval for settlements regardless of risk).
Parameters
proposal
Returns
Promise<boolean>
Implementation of
AgentPolicy.requiresUserApproval
reserve()
reserve(
proposal):Promise<PolicyEvalResult>
Optional reservation lifecycle for stateful policies.
The execution boundary calls reserve before executing, then commit
after a successful execution or release on any failure path. When
implemented, quota is only consumed through reserve/commit — a read-only
evaluate / canAutoApprove never touches the limits.
Parameters
proposal
Returns
Promise<PolicyEvalResult>
Implementation of
reset()
reset():
Promise<void>
Optional: reset internal state (useful in tests or at midnight rollover).
Returns
Promise<void>