Connect
Point the Agents SDK at a Runtime, from the environment or explicitly.
import { createClient } from "@nylorun/agents";
const client = await createClient(); // environment, then the project link
const deployed = createClient({
url: process.env.NYLORUN_RUNTIME_URL!,
key: process.env.NYLORUN_SERVER_KEY!,
});With a destination, createClient() returns the client at once. Without one,
it returns a promise and resolves the connection in this order:
NYLORUN_RUNTIME_URLandNYLORUN_SERVER_KEY, both set- The project link that
nylorun startwrote
There is no tenant option: a Runtime serves one Tenant. When nothing
resolves, createClient() throws ConnectionError (connection_missing).
Destination
Prop
Type
Pass key or token, not both. The first request checks the Runtime's
/health and throws IncompatibleRuntimeError when its protocol is outside
the client's range. A client with a token skips that check.
Act for a person
const forUser = client.as(user.id, { scopes: ["sessions:own"] });
const sessions = await forUser.sessions.page();client.as(subject) sends Nylorun-Subject and Nylorun-Scopes on every
call. The Runtime limits it to those scopes and to that person's own sessions
and vaults. Your server signs the person in; nothing is minted or cached.
resolveConnection
import { resolveConnection } from "@nylorun/agents";
const { url, key, source } = await resolveConnection();
// source: "options" | "environment" | "project-link"The same resolution as createClient(), without building a client. It takes
{ url?, key?, cwd? }; cwd is where to look for the project link.