Examples
TypeScript SDK example
A support agent that refunds orders through a fake payments API
(payments.ts). Every refund goes through guard() from the TypeScript SDK
first (agent.ts).
Run it#
Start the local stack and get an agent key first: see ../README.md.
The SDK is used from this repo, so build it once:
cd sdk && npm install && npm run build && cd ..Then, from this folder:
cd examples/typescript-sdk
npm install
RISKBOUND_API_KEY=$RISKBOUND_AGENT_KEY npm startYou see:
[payments] refunded 40.00 USD on ord_1001
40.00 USD on ord_1001: allow, refund re_0001
900.00 USD on ord_1002: blocked (refund-hard-cap)
Refunds issued: 1To see a refund wait for a person, run this and approve it as
../README.md shows:
ASK_FOR_APPROVAL=1 RISKBOUND_API_KEY=$RISKBOUND_AGENT_KEY npm startRISKBOUND_URL changes the backend address. The default is
http://localhost:8200.
What to copy into your own agent#
const riskbound = createRiskbound({ apiKey, baseUrl });
const guardedRefund = riskbound.guard('refund', { agent: 'support-bot' });
await guardedRefund(
{ order_id: orderId, amount_minor: amountMinor, currency: 'USD' },
() => payments.refund(orderId, amountMinor, 'USD'),
);The action runs only on allow, or on ask_human after a person approves.
On block the guard throws RiskboundBlockedError and the action never runs.
If Riskbound cannot be reached, it throws RiskboundUnavailableError and the
action never runs.