Skip to main content

wrap()

The single execution primitive in AgentRein. Pass any API client and AgentRein intercepts every method call automatically.
import { AgentRein } from 'agentrein';
import { Octokit } from '@octokit/rest';

const agentrein = new AgentRein({ apiKey: '...' });
const octokit = new Octokit({ auth: '...' });

const agentOctokit = agentrein.wrap(octokit, session, { connector: 'github' });

// Use exactly as before — rollback is automatic on any failure
await agentOctokit.issues.create({ owner: 'my-org', repo: 'my-repo', title: 'Task' });

Approval Gates with wrap()

Pass requiresApproval with a list of method paths that need human sign-off before executing.
const agentStripe = agentrein.wrap(stripe, session, {
    connector: 'stripe',
    requiresApproval: ['subscriptions.cancel', 'invoices.del'],
    pollIntervalMs: 2000,
    timeoutMs: 300000,
});

// Executes immediately — no approval needed
await agentStripe.invoices.create({ customer: 'cus_123', amount: 500 });

// Pauses here until a reviewer approves from the dashboard
await agentStripe.subscriptions.cancel({ id: 'sub_123' });
If rejected, ApprovalRejectedError is thrown and the session is automatically rolled back.