PermDock
Adapters

Eve

permdock/eve turns PermDock decisions into Eve tool approval policies and approval response policies, takes principal and actor from the durable session's auth, and stores pending approvals in a pluggable ApprovalStore.

permdock/eve connects the Decision model to Eve's approval hook on defineTool. Eve already pauses a session durably and renders the approval on every channel; what it asks the application for is the policy that decides whether a call may run, must wait for a person, or is refused, and a second policy that decides who may press Approve. Both come out of one createPermDock call, typed against your permissions, fail-closed.

Purpose

Eve's human-in-the-loop hook receives the session context plus { abortSignal, callId, toolAnnotations?, toolInput?, toolName } and returns an approval status: "not-applicable" to continue, "user-approval" to pause, "approved" or "denied" (optionally { type, reason }) to decide in code. It offers always(), auto(), never() and once() helpers from eve/tools/approval and leaves anything input- or caller-dependent to a custom function. Its response policy receives the request (callId, interactionId, the requesting principal, toolInput, toolName), the submitted response (decision of approve or deny plus the authenticated principal), the session and auth, and decides whether that person may approve this call, and the docs note that a shared request stays pending when a responder is rejected so another eligible approver can act. That is a policy decision point with an approval store missing in the middle; permdock/eve supplies both from the application's PermDock policy and an ApprovalStore. It needs eve 1.2.0 or later (eve peer >=1.2.0), which needs Node.js 24.

API

import { defineTool } from "eve/tools";
import { defineOperations } from "permdock";
import { createPermDock } from "permdock/eve";

const DeleteInput = z.object({ id: z.string() });
const RefundInput = z.object({ chargeId: z.string(), amount: z.number() });

const { approval, approvalFor, getPermDock } = createPermDock(policy, {
  operations: defineOperations(permissions, {
    delete_post: {
      permission: permissions.post.delete,
      data: (input) => loadPost(DeleteInput.parse(input).id),
    },
    refund: {
      permission: permissions.charge.refund,
      data: (input) => loadCharge(RefundInput.parse(input).chargeId),
    },
  }),
  store, // ApprovalStore; memoryApprovalStore() when omitted
  approvers: { roles: ["finance-admin"] }, // who may resolve; see below
  delegation: () => ({
    scopes: [permissions.post.delete.scope, permissions.charge.refund.scope],
  }),
});

export default defineTool({
  description: "Refund a charge.",
  inputSchema: RefundInput,
  approval, // { request, response } built from `operations`
  async execute(input, ctx) {
    // getPermDock(ctx) is the request-scoped PermDock for checks inside the tool
    (await getPermDock(ctx)).assert(
      permissions.charge.refund,
      await loadCharge(input.chargeId),
    );
    return refund(input);
  },
});

// Or gate a single tool without the map:
approval: approvalFor(permissions.charge.refund, (input) =>
  loadCharge(RefundInput.parse(input).chargeId),
);
  • approval is an Eve { request, response } pair, each taking the one context object Eve passes (EveApprovalContext for request, EveResponseContext for response; both are structural, so the adapter never imports eve). request looks the tool name up in operations (own keys only), resolves the resource, calls decide and maps the outcome. response checks the responder against the approval record and the approvers rule.
  • approvalFor(permission, data?) builds the same pair for one tool inline.
  • unmapped: 'allow' answers not-applicable for a tool operations does not name, so Eve runs it without asking; the default 'deny' denies it. context, otel, wrap and deniedText behave as on permdock/ai-sdk.
  • data receives the tool input as unknown; parse it with the tool's schema before loading the resource.
  • getPermDock(ctx) returns a request-scoped PermDock from ctx.session for checks inside execute or in other Eve code. It builds a fresh frozen instance on every call, so a replayed step never sees state from an earlier one.
  • tenant resolves the active tenant from the same context on every call; operations has no tenant dimension, because the tenant is part of the subject, not of the tool.
  • store is the ApprovalStore. approvers is either { roles } (approver must hold one of these roles in the PermDock policy) or a function (responder, request) => boolean. It is an extra restriction on top of grant.approval.by; both must pass. The actor rule (an agent never approves its own call) is enforced regardless.

Subject from the session

Eve exposes two authenticated principals on ctx.session.auth: initiator, who created the session, and current, who sent this turn. Each has principalId, principalType, authenticator and attributes. permdock/eve maps them:

PermDock subject partEve sourceNotes
principalsession.auth.current, or session.auth.initiator when the turn has no callerThe caller of this turn; roles come from policy.subject or attributes you declare as server-set
actorThe Eve app, { id: 'eve:app', kind: 'eve' }Every turn, whoever sent it
delegationThe delegation option, resolved from the same contextNo default. Every eve turn has an actor, so without delegation every tool is denied with reason no-delegation (delegation)

In a shared session, eve replaces current when another person sends a follow-up, so each turn is decided with the grants of the person who sent it, never with the initiator's. A schedule-dispatched turn has the app as its caller (authenticator: 'app', principalId: 'eve:app'), which holds no role, so its tools deny until subject maps it to a principal.

Up to 0.30.0, the principal was always the initiator and a different current became the actor. An app whose policy names actor.id of an eve turn reads the caller from principal now.

The subject and actor options override these defaults when an application encodes identity differently. Model output, toolInput and attributes that Eve marks as user-supplied never build a subject (authentication).

Request lifecycle

  1. Eve is about to execute a tool and calls approval.request with the session and toolInput.
  2. The adapter validates toolInput against the resource schema when a data resolver exists, loads the resource and calls decide.
  3. The outcome maps to Eve's vocabulary:
Decision outcomeapproval.request returnsEve behaviour
granted"not-applicable"Tool runs without a prompt
approval-required"user-approval"Eve opens an interaction.opened event of kind approval and parks the session; an ApprovalRequest with token is written to the store
denied{ type: "denied", reason }Tool does not run; the model receives reason built from denials and alternatives
unmapped tool, invalid input, thrown resolver{ type: "denied", reason }Fail closed
  1. A person presses Approve or Cancel on a channel. Eve calls approval.response with response.decision (approve or deny) and the authenticated response.principal (the responder). The adapter finds the record for the call (from this instance's bounded session cache, or by recomputing the token from request.principal, the caller of the turn that made the call, so any replica can answer), refuses a responder whose principalId is the request's actor, applies approvers, maps the responder through the same subject as a caller so grant.approval.by sees their roles, memberships and tenant, and calls resolveApproval (approved for approve, rejected for deny, so the re-check denies), returning { status: "allowed" }. Otherwise it returns { status: "rejected", reason } and Eve keeps the request pending for another responder. The caller who made the call cannot approve their own request unless the grant sets approval: { mode: "confirm" }.
  2. Eve re-runs approval.request for the same call before execute (the AI SDK re-check) and runs the tool unless the answer is a denial. The adapter recomputes the token: an approved record is consumed and the answer is "not-applicable", so the tool runs once; a record still pending means nobody approved and the answer is a denial with approval-pending; a consumed, rejected or expired record is a denial too.
  3. Every step emits on('decision'); the ask, the answer and the resumed decision share token.

"not-applicable" is used only for granted. It is Eve's word for "continue", and the adapter never reaches it without a positive decision, so the fail-open path @ai-sdk/policy-opa has does not exist here.

What it validates

  • toolInput against the resource's Standard Schema when data is declared; Eve's toolInput may be undefined, which is a validation failure and therefore a denial.
  • The subject comes from session.auth, never from toolInput or the model.
  • The responder in approval.response is Eve's authenticated principal; it must not be the actor, must satisfy approvers, and its verdict is recorded in the store.
  • Replays: the token is recomputed on resume. Eve's remembered decisions (once()) are never consulted; each call has its own request, which is also what Eve's docs recommend for non-idempotent side effects across replays.

How denials surface

  • { type: "denied", reason } with reason built from the Decision: the failing roles, the reason kind and the alternatives list, phrased for the model ("charge.refund denied: member (condition). Alternatives: charge.read.").
  • A rejected responder gets { status: "rejected", reason: "approver is the actor of this request" } (or the approvers reason); the request stays pending, matching Eve's semantics.
  • Expired or mismatched approvals on resume are denials with detail approval-expired or approval-mismatch.

Connections, agent-wide gates, subagents and schedules

Connection tools. A connection's approval takes the same { request, response } pair as a tool. Eve names each connection tool <connection>__<tool>, so key operations by that name and put the pair on the connection:

agent/connections/linear.ts
import { defineMcpClientConnection } from "eve/connections";

const { approval } = createPermDock(policy, {
  operations: defineOperations(permissions, {
    linear__create_issue: { permission: permissions.issue.create },
    linear__delete_comment: { permission: permissions.comment.delete },
  }),
  delegation,
});

export default defineMcpClientConnection({
  url: "https://mcp.linear.app/mcp",
  description: "Linear workspace.",
  approval,
});

A tool the map does not name is denied; unmapped: 'allow' lets the connection's read tools through. Approval never changes who the call runs as: the connection token stays the requester's.

Agent-wide policy. approval in agent.ts runs on every call, including connection tools and subagents, and eve keeps the stricter of it and the tool's own answer. An agent-wide rule can add a gate on top of a PermDock decision but never turn a PermDock denial into a run. Keep PermDock's pair on the tools and connections, where its response policy checks the approver; when only the agent-wide policy asks, eve has no tool-level response to apply.

Subagents. Eve runs each message to a subagent with the sender's auth, so the principal is the same person, and local subagents run under the root agent's policy. session.parent (sessionId, rootSessionId, callId) marks a subagent's session. Give it its own actor id and a narrower delegation, so audit tells the agents apart and a research child cannot delete:

createPermDock(policy, {
  operations,
  actor: (ctx) =>
    ctx.session?.parent === undefined
      ? { id: "eve:app", kind: "eve" }
      : { id: `eve:session:${ctx.session.id ?? ""}`, kind: "eve" },
  delegation: (ctx) =>
    ctx.session?.parent === undefined
      ? { scopes: [permissions.post.list.scope, permissions.post.delete.scope] }
      : { scopes: [permissions.post.list.scope] },
});

Approvals from a child appear on the parent session, and the child's response policy decides who may answer. Parallel agents covers the pattern outside eve.

Schedules. A defineSchedule handler sends with appAuth (principalId: 'eve:app'), which holds no role, so its tools deny until subject maps it; pass a user's auth instead when the work needs that user's grants. Eve's experimental dynamic schedules call their auth callback on each occurrence to turn the stored creator into current access; look the creator up there and return null for a removed member, and that occurrence fails without running. For a recurring job that PermDock decides at fire time, see Automations.

Use with better-supabase

better-supabase 0.81.0 or later exports strictestApproval, approvalPolicy, tenantToolApproval, supabaseTool and eveContext from better-supabase/eve. strictestApproval combines approvals for one tool: the strictest request answer wins (denied, then user-approval, then approved, then not-applicable) and every response must allow the answer. approvalFor returns an approval of that shape, so PermDock's decision, the approvals block and the tenant's tool policies all apply to one call.

import { defineTool } from "eve/tools";
import {
  approvalPolicy,
  strictestApproval,
  supabaseTool,
  tenantToolApproval,
} from "better-supabase/eve";

const { approvalFor } = createPermDock(policy, { operations });

export default defineTool(
  supabaseTool({
    agent: "support",
    server,
    description: "Refund a charge.",
    inputSchema: RefundInput,
    permission: permissions.charge.refund.key,
    approval: strictestApproval(
      approvalFor(permissions.charge.refund, (input) =>
        loadCharge(RefundInput.parse(input).chargeId),
      ),
      approvalPolicy({
        agent: "support",
        server,
        permission: permissions.charge.refund.key,
      }),
      tenantToolApproval(policies),
    ),
    execute: (input, { db }) => refund(db, input),
  }),
);
  • permissions.charge.refund.key is the permission's key. Pass the same permission to approvalFor and to permission: supabaseTool adds the key to the agent's scopes, and eveContext derives the scope claim from them.
  • approvalFor runs the PermDock decision. approvalPolicy files the request in the approvals block, and tenantToolApproval applies the tenant's deny, ask and auto policies.
  • The pair type-checks against strictestApproval in tests/better-supabase/eve.test-d.ts. permdock/eve reads only session.id and session.initiator from the response context, so better-supabase's narrower EveApprovalResponseContext is accepted.
  • Needs better-supabase 0.81.0 or later and eve 1.3.0 or later.

Example app

apps/examples/eve-agent: HTTP harness on 127.0.0.1:3474 with GET /health, driving the pair with Eve's session shapes. GET /list_posts returns not-applicable. GET /delete_post?call=… returns user-approval; POST /approve?call=… answers as an admin reviewer; the next GET /delete_post for that call is the re-check and returns not-applicable once, and a further one is denied. No model API key. tests/integration also drives the pair with eve 1.2.0's ApprovalContext and ApprovalResponseContext (gate, responder check, re-check) against a Postgres ApprovalStore; eve exports no function that evaluates an approval outside a running session, so the test follows its three steps. This example is also the deploy template for the PermDock Cloud listing on the Vercel Marketplace. src/cloud.ts uses cloud() when PERMDOCK_CLOUD_URL and PERMDOCK_CLOUD_KEY are set and memoryApprovalStore() otherwise: store is cloud().approvals, sink is cloud().sink, POST /webhooks/permdock is a cloudApprovalWaiter endpoint, /approvals/* mounts approvalsHandler, GET /delete_post links the inbox, and policies is hostedPolicies(cloud().policies), refreshed at start and every minute, for hosted grants on the hostable post.publish (Cloud adapter).

Last updated on

On this page