@everruns/sdk

中文文档
0.3.1发布于 2026/10/12MITTypeScriptES Module构建来源已验证近 30 天下载 2829

TypeScript SDK for Everruns API

原始使用文档
文档目录14 节
  1. Installation
  2. Call your agent from code
  3. Management Quick Start
  4. Agent Harness
  5. Harnesses & Models
  6. Initial Files
  7. Agent Versions
  8. Workspaces
  9. Memories
  10. Authentication
  11. Change Reasons
  12. Streaming Events
  13. Error Handling
  14. License

@everruns/sdk

TypeScript SDK for the Everruns API.

Installation

npm install @everruns/sdk

Call your agent from code

Use AgentClient to call one agent from an application. It holds an agent key (evr_ak_...) that reaches that agent's sessions and nothing else.

import { AgentClient } from "@everruns/sdk";

// Reads EVERRUNS_AGENT_URL and EVERRUNS_AGENT_KEY
const agent = new AgentClient();
// or: new AgentClient({ agentUrl: "https://app.everruns.com/api/v1/channels/apichan_...", credential: "evr_ak_..." })

// One call: creates a session, sends the message, waits for the turn
console.log(await agent.run("What can you do?"));

// Act for one of your application's users (the key needs the `end_user` permission)
const alice = agent.forEndUser("customer-42");
console.log(await alice.run("Where is my order?"));

// For a browser or mobile app, never ship the key: mint a short-lived runtime token
const { access_token } = await alice.runtimeToken();
// ...then, in the browser:
const browser = new AgentClient({
  agentUrl: "https://app.everruns.com/api/v1/channels/apichan_...",
  credential: access_token,
});

For more control use createSession, sendMessage, streamEvents, listEvents, getSession, cancel, answerQuestions and submitToolApprovals.

The management client below (Everruns, with a personal access token) is for managing Everruns: agents, harnesses, workspaces. Its sessions.create and messages.create are deprecated for calling an agent; use AgentClient instead.

Management Quick Start

import { Everruns } from "@everruns/sdk";

// Uses EVERRUNS_API_KEY and optional EVERRUNS_ORG_ID environment variables
const client = Everruns.fromEnv();

// Create an agent
const agent = await client.agents.create({
name: "Assistant",
systemPrompt: "You are a helpful assistant."
});

// Create a session
const session = await client.sessions.create({ agentId: agent.id });

// Send a message
await client.messages.create(session.id, "Hello!");

// Stream events
for await (const event of client.events.stream(session.id)) {
console.log(event.type, event.data);
}

Agent Harness

Each agent owns a harness. Set it on create/update with harnessName (preferred) or harnessId (mutually exclusive); omit both to default to the org's generic harness. A session created from the agent runs on the agent's harness.

// Create an agent on a specific harness
const agent = await client.agents.create({
  name: "researcher",
  systemPrompt: "You do deep research.",
  harnessName: "deep-research",
});

// Agent-first session: runs on the agent's harness
const session = await client.sessions.create({ agentName: "researcher" });

Harnesses & Models

Discover and manage harnesses, and browse available models to choose a defaultModelId.

// Browse harnesses, then create one
const harnesses = await client.harnesses.list(); // or .search("research")
const harness = await client.harnesses.get(harnesses.data[0].id);
const custom = await client.harnesses.create({
  name: "my-harness",
  systemPrompt: "Base instructions for every session.",
});
const examples = await client.harnesses.listExamples();

// List models to pick a default for an agent
const models = await client.models.list();

Initial Files

const session = await client.sessions.create({
agentId: "agent_...",
initialFiles: [
{
path: "/workspace/README.md",
content: "# Demo Project\n",
encoding: "text",
isReadonly: true,
},
{
path: "/workspace/src/app.py",
content: 'print("hello")\n',
encoding: "text",
},
],
});

Runnable example: examples/initial-files.ts Run locally from this repo with npx tsx examples/initial-files.ts.

Agent Versions

const version = await client.agents.createVersion("agent_...", {
changeKind: "manual",
summary: "Baseline",
});

const versions = await client.agents.listVersions("agent_...");
const diff = await client.agents.diffVersions("agent_...", "agentver_1", version.id);
const fork = await client.agents.forkVersion("agent_...", version.id, {
name: "forked-agent",
});
const rollback = await client.agents.rollbackVersion("agent_...", version.id, {
saveVersion: true,
});

Workspaces

Workspaces hold files shared across sessions.

const workspace = await client.workspaces.create({ name: "team-docs" });

await client.workspaceFiles.create(
workspace.id,
"/notes/welcome.md",
"# Welcome\n",
{ encoding: "text" },
);
const file = await client.workspaceFiles.read(workspace.id, "/notes/welcome.md");
const files = await client.workspaceFiles.list(workspace.id, { recursive: true });

Runnable example: examples/workspaces.ts Run locally from this repo with npx tsx examples/workspaces.ts.

Memories

Memories are long-term, searchable knowledge stores for agents.

const memory = await client.memories.create({ name: "product-knowledge" });

await client.memories.createFile(memory.id, "/facts/product.md", {
content: "# Product\n",
encoding: "text",
});
const results = await client.memories.grepFiles(memory.id, "product");
await client.memories.sync(memory.id);

Runnable example: examples/memories.ts Run locally from this repo with npx tsx examples/memories.ts.

Authentication

The SDK uses personal access token authentication. Set the EVERRUNS_API_KEY environment variable or pass the token explicitly. For personal access tokens with access to multiple organizations, set EVERRUNS_ORG_ID or pass orgId explicitly:

// From environment variable
const client = Everruns.fromEnv();

Or with an explicit token and organization:

const client = new Everruns({
apiKey: "evr_pat_...",
orgId: "org_..."
});

Change Reasons

Record why a change was made. withReason derives a client that sends the reason with every API request it makes; the server stores it in the changed entity's history. The original client stays unchanged:

await client.withReason("retire the unused agent").agents.delete("agent_123");

const scoped = client.withReason("rotate prompts for the Q3 launch");
await scoped.agents.delete("agent_456");

The reason travels in the Everruns-Change-Reason header, UTF-8 percent-encoded. A blank reason sends no header. The server trims the reason and rejects it with HTTP 400 (invalid_change_reason) when it is longer than 1000 characters, contains control characters other than newline and tab, or looks like it contains a credential.

Streaming Events

The SDK supports SSE streaming with automatic reconnection:

const stream = client.events.stream(session.id, {
exclude: ["output.message.delta"], // Filter out delta events
sinceId: "evt_..." // Resume from event ID
});

for await (const event of stream) {
switch (event.type) {
case "output.message.completed":
console.log("Message:", event.data);
break;
case "turn.completed":
console.log("Turn completed");
stream.abort(); // Stop streaming
break;
case "turn.failed":
console.error("Turn failed:", event.data);
break;
}
}

Error Handling

import { ApiError, AuthenticationError, RateLimitError } from "@everruns/sdk";

try {
await client.agents.get("invalid-id");
} catch (error) {
if (error instanceof AuthenticationError) {
console.error("Invalid personal access token");
} else if (error instanceof RateLimitError) {
console.log(`Retry after ${error.retryAfter} seconds`);
} else if (error instanceof ApiError) {
console.error(`API error ${error.statusCode}: ${error.message}`);
}
}

License

MIT

版本与发布记录

@everruns/sdk 共发布 13 个版本,首次发布于 2026/01/29;过去 12 个月发布了 13 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.3.1latest2026/10/121 个月前
0.3.02026/10/111 个月前
0.2.12026/08/202 个月前
0.2.02026/07/114 个月前
0.1.102026/06/194 个月前
0.1.92026/05/096 个月前

关于 @everruns/sdk 的常见问题

@everruns/sdk 是什么?

TypeScript SDK for Everruns API

如何安装 @everruns/sdk?

在项目目录运行 npm install @everruns/sdk,或使用 pnpm add / yarn add / bun add。

@everruns/sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@everruns/sdk 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@everruns/sdk 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@everruns/sdk 可以商用吗?

@everruns/sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@everruns/sdk 的下载量有多少?

根据 npm 官方下载统计,@everruns/sdk 在 2026/10/14 – 2026/11/12 这 30 天内被下载 2,829 次,日均约 94 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@everruns/sdk 还在维护吗?

最新版本 0.3.1 发布于 2026/10/12(1 个月前);至今共发布 13 个版本,其中过去 12 个月发布了 13 个;首次发布于 2026/01/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。