TypeScript SDK

Build the public client checkout with npm ci && npm run build, then run npm pack and install the resulting tarball in your application. Source setup does not assume an npm registry release. Use Node.js 22 or newer.

1import { AgentTrunk } from "@agenttrunk/sdk";
2
3const client = new AgentTrunk({
4 token: () => {
5 const token = process.env.AGENTTRUNK_ACCESS_TOKEN;
6 if (!token) throw new Error("AgentTrunk authentication is required");
7 return token;
8 },
9});
10
11// These values come from your explicit workspace/context selection.
12const workspaceId = process.env.AGENTTRUNK_WORKSPACE_ID;
13const contextKey = process.env.AGENTTRUNK_CONTEXT_KEY;
14if (!workspaceId || !contextKey) throw new Error("Select a workspace and context");
15
16const { revision } = await client.inspect(workspaceId, contextKey, "production");
17const file = revision.files.find((item) => item.path === "SKILL.md");
18if (!file) throw new Error("SKILL.md is not in this package");
19const bytes = await client.readFile(workspaceId, contextKey, revision.id, file);
20const instructions = new TextDecoder().decode(bytes);
21// Pass instructions to your harness as reviewed input, not executable code.
22// Retain revision.id and revision.packageDigest with the run.

readFile verifies the returned bytes against the pinned manifest. Keep tokens out of frontend bundles and logs. Your runtime owns credential refresh; the callback retrieves its current token for each request.

The convenience client above uses token; the Fern-generated TypeScript client uses accessToken. Do not interchange the constructors. See the language reference and runnable examples.