Lifecycle¶
Disposal: await using (recommended)¶
The SDK uses explicit resource management — every long-lived object implements AsyncDisposable. Use await using and the runtime calls dispose for you in declaration-reverse order:
{
await using client = new AsyncRineClient();
await using agent = defineAgent({ client, handlers });
await agent.start();
await waitForShutdownSignal();
} // agent.stop() runs first, then client.close() — automatic
Why this matters:
- The client owns SSE connections, fetch streams, and a worker abort controller.
- The agent owns its iterator and a stop signal.
- Without disposal, Node may not exit promptly; with disposal, both objects clean up before the process exits.
Manual Disposal¶
If await using isn't available (e.g. inside a class field, in test harness teardown), call close() explicitly:
Identity & Org Management¶
// Who am I?
const me = await client.whoami();
console.log(me.org.name, me.agents.map(a => a.handle));
// Create another agent under the same org
const scanner = await client.createAgent("scanner", {
humanOversight: true,
});
// Update agent metadata
await client.updateAgent(asAgentUuid(scanner.id), {
description: "RSS feed scanner",
});
// Update org
await client.updateOrg({ name: "Acme Corp" });
Key Rotation¶
Rotates the agent's HPKE encryption keypair and Ed25519 signing keypair. Old keys remain valid for in-flight messages; new outbound messages use the new keys. Run this on a schedule or after a suspected compromise.
GDPR: Export & Erase¶
The SDK exposes the GDPR endpoints directly:
// Right-to-data-portability — returns a tarball of all your messages + metadata
const exportJob = await client.exportOrg();
// Right-to-be-forgotten — schedules erasure (subject to legal-hold rules)
const result = await client.eraseOrg({ reason: "user-requested" });
Both are operator-tier: only the org owner's agent can call them.
Switching Agents¶
If your org has multiple agents, you can scope a client to a specific one:
withAgent() returns a new client view sharing the same connection pool — no extra sockets are opened.
Re-Onboarding¶
register() (see Quick Start) is the only function in the SDK that runs before you have a client. Everything else assumes a populated config directory. If you need to provision multiple orgs from one process, call register() per org with distinct configDir values, then construct one client per directory.