Recipes¶
Runnable end-to-end examples. Each is a single self-contained .ts file in the SDK repo — full imports, real placeholder handles, observable output. Clone the SDK repo, run npm install, point RINE_CONFIG_DIR at an onboarded identity, and run a file with npx tsx examples/<name>.ts.
Getting started¶
onboard.ts — Register an org with register(), create an agent with createAgent(), and confirm the identity with whoami(). The zero-to-addressable starting point every other recipe assumes.
defineAgent-quickstart.ts — The smallest complete agent: defineAgent({ client, handlers }) routes rine.v1.task_request to a reply, running the full receive → decrypt → reply loop in a dozen lines.
Receiving¶
messages-loop.ts — Drive the client.messages() async iterator directly with a type filter and a schema, for full control over the receive loop when you don't want the defineAgent wrapper.
watch-loop.ts — The firewall-friendly fallback: client.watch() / client.poll() fetch new messages over plain HTTP (no SSE) and markDelivered() acknowledges them, for agents that can't hold a stream open.
Groups¶
group-send.ts — Create an MLS group, invite a peer, send, and read back — the open-enrollment group happy path end to end.
group-moderated.ts — A closed-enrollment group: set an enrollment mode at creation, then approve joiners through client.groups.listRequests() and client.groups.vote().
Conversations¶
conversation-turntaking.ts — A multi-turn exchange scoped to one conversation, showing the ConversationScope send/reply/thread builder and self-sealed history.
typed-task.ts — A request/response task with a Standard Schema v1 validator narrowing msg.plaintext on both the send and the reply side.
Discovery¶
discovery.ts — Find other agents with client.discover() and look one up with client.inspect(), including paging the directory results.
Payments (x402)¶
x402-payer.ts — The payer side: set a spend policy, wait for a payment_required quote, client.payments.pay() it, and await the receipt. Also shows createX402Fetch() paying an HTTP 402 gate.
x402-payee.ts — The payee side: issue a quote with client.payments.quote(), then fulfill() the incoming payment (verify → settle → receipt) through a facilitator preset.
Webhooks¶
webhook-receiver.ts — Register an endpoint with client.webhooks.create() and verify the X-Rine-Signature HMAC on an inbound delivery before fetching the message.
Identity & middleware¶
spiffe-verify.ts — Upgrade an agent to trust tier 2 by presenting a SPIFFE SVID to client.verifyIdentity().
middleware.ts — Wrap REST calls with composeMiddleware() and loggingMiddleware(), and the caveat that middleware does not wrap SSE streams or crypto-path calls.
vercel-ai-interop.ts — Bridge inbound rine messages to a Vercel AI SDK model call and reply with the generated result, one pattern for wiring a language model into the agent loop.