# @godspeedai/cognate-runtime-bun 中文文档

规范地址：https://npmcn.com/package/%40godspeedai/cognate-runtime-bun/

版本：0\.10\.0
npm 元数据更新时间：2026-11-16T03:51:26.514Z
中文译文更新时间：2026-11-16T18:48:02.472Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40godspeedai/cognate-runtime-bun
原文对照：https://npmcn.com/package/%40godspeedai/cognate-runtime-bun/?lang=original
项目主页：https://github.com/GodSpeedAI/Cognate#readme
源码仓库：https://github.com/GodSpeedAI/Cognate

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：227 kB，19 个文件
- 模块格式：ES Module
- TypeScript 类型：未声明
- 运行依赖：12 个
- 首次发布：2026-10-09T02:31:03.614Z
- 最新版本发布：2026-11-16T03:51:26.155Z
- 近 30 天下载量：3532（2026-10-17 至 2026-11-15，npm 官方下载统计）
- 已发布版本数：20（近 12 个月 20 个）

## 中文简介

Bun 参考运行时间:由内核,耐用存储,运行,续作,承诺,出品,以及RuntimeService背后的认知.

## 安装

```sh
npm install @godspeedai/cognate-runtime-bun
```

也可以使用：`pnpm add @godspeedai/cognate-runtime-bun`、`yarn add @godspeedai/cognate-runtime-bun`、`bun add @godspeedai/cognate-runtime-bun`

## README

# @godspideai/cognate-runtime-bun (英语)

Bun的Cognate参考运行时间:耐用剂运行,人行后继, 工艺品、预测和可选认知,由单项工艺组成 `RuntimeService`。将其指向一个 SQLite 文件, 您应用程序的历史可以重新开始; 将其指向 PostgreSQL (或一个 pg0 管理的本地实例) , 多个进程安全地共享同一历史 .

**何时使用此软件包 :** 在服务器、工人或脚本中运行代理。 说对了 与 [`@godspeedai/cognate-client`](https://www.npmjs.com/package/@godspeedai/cognate-client) 改为 或用一个运输适配器在网络上服务.

## 安装

```sh
bun add @godspeedai/cognate-runtime-bun
```

要求数 [阿宝](https://bun.sh/) >= 1. 4.0 (默认商店使用 Bun 内置) `bun:sqlite`) (中文(简体) ).

## 快开始

```ts
import { createRuntime } from "@godspeedai/cognate-runtime-bun";
import type { AgentDefinition } from "@godspeedai/cognate-runtime-api";

const agent: AgentDefinition = {
  id: "agent.order",
  version: "1.0.0",
  async run(_input, ctx) {
    // Shared state: a snapshot, then JSON Patch deltas — clients derive the same state.
    await ctx.emit("state.changed", { snapshot: { order: { id: "o-1", status: "open", total: 0 } } });
    await ctx.emit("state.changed", { patch: [{ op: "replace", path: "/order/status", value: "paid" }] });
    await ctx.emit("state.changed", { patch: [{ op: "replace", path: "/order/total", value: 42 }] });
    return { done: true };
  },
};

const caller = { actor: { id: "alice", kind: "user" }, tenant: "tenant-a" } as const;

const runtime = await createRuntime({
  store: "./app.sqlite", // a durable file; use ":memory:" for an ephemeral runtime
  // policy authorizes capability invocations; actions authorizes run/continuation actions.
  policy: { authorize: () => ({ allow: true, policyId: "p", reason: "allowed" }) },
  actions: { authorize: () => ({ allow: true, reason: "allowed" }) },
  agents: [agent],
});

const started = await runtime.service.startRun(caller, {
  agent: "agent.order",
  input: {},
  idempotencyKey: "order-1", // repeating the key returns the same run, never a duplicate
});

await runtime.idle(); // background work queued so far has been processed

const run = await runtime.service.getRun(caller, { runId: started.runId });
console.log(run.status, run.output); // completed { done: true }

await runtime.close();
```

## 持续拖延

`ctx.waitFor` 暂停运行直到有人解决其打开的续作。 跑步的进展 具有耐用性:它可以通过重启来坐等.

```ts
const refundAgent: AgentDefinition = {
  id: "agent.refund",
  version: "1.0.0",
  async run(input, ctx) {
    const { amount } = input as { amount: number };
    const decision = (await ctx.waitFor("approve", {
      type: "refund-approval",
      condition: { kind: "human_approval" },
      payload: { amount },
    })) as { approved: boolean };
    return { amount, approved: decision.approved };
  },
};

const waiting = await runtime.service.startRun(caller, {
  agent: "agent.refund",
  input: { amount: 75 },
  idempotencyKey: "refund-1",
});

// Meanwhile — from a webhook, an admin UI, a shell — list and resolve open continuations.
const [continuation] = await runtime.service.listContinuations(caller, {
  runId: waiting.runId,
  status: "OPEN",
});
await runtime.service.resolveContinuation(caller, {
  continuationId: continuation!.id,
  action: "resume",
  input: { approved: true },
  idempotencyKey: "approve-1",
});
```

跑道从上而下再入代理,接取有记录的决定,并完成. 重放 从未重复记录的工作: 每 `ctx.step`, (中文(简体) ), `emit`, (中文(简体) ), `invoke`, (中文(简体) ), `artifact`,以及 `waitFor` 结果是 返回这些结果而不是重新生效.

## 你从哪里得到的 `createRuntime`

回来的 `Runtime` 揭露:

-   `service` - 满分 `RuntimeService`: 启动/ 获得/ 取消/ 列表运行, 可重新连接的事件流 (单位:千美元)`service.events(caller, { follow: true })`),继续,直接能力 `invoke`, (中文(简体) ), `getArtifact`,公共投影读取,共享运行/线程状态读取和更新.
-   `store` - 基础 `DurableStore`如果您需要直接访问事件日志.
-   `kernel` ——嵌入能力内核.
-   `inspect(correlationId)` 关联的因果链 id:运行,事件,引用, 文物,观测.
-   `erase(eventId, reason, actor)` ——去除事件的有效载荷;衍生观点和认知指数 也放下来.
-   `rebuildCognition()`, (中文(简体) ), `pollApprovals()`, (中文(简体) ), `idle(timeoutMs?)`,以及 `close()`。 。 。 .

快速启动后的显著选项 : `components` (能力提供内核组件 探员可以 `ctx.invoke`, (中文(简体) ), `projections` (单位:千美元)[`@godspeedai/cognate-projections`](https://www.npmjs.com/package/@godspeedai/cognate-projections) 自动保持当前 , `cognition` (索引完成运行后通过 `ctx.recall`, (中文(简体) ), `outboxFor` (在每次运行中,在解剖学上犯下了极端的放行意图), `governance`,以及 `tickMs` (背景回路间隔,默认为10ms).

## 限制

-   **每家店有一位执行人.** PostgreSQL 支持多个可持久存储的写法; 并不确定分布式经营所有权。 运行执行默认为串行 。 选入 `execution.maxConcurrentRuns` 承认受限独立运行在一个过程中,需要 信赖 `execution.resourceKeys` 资格政策高于1。 共享资源密钥序列化; 呼叫者必须化作化名。 切勿与同一可运行的工作相竞争.
-   **台阶至少是一档.** 一个在飞机失事期间 重新开始飞行的阶段. 保持同位素步骤,并使用本地承诺收款和外部明确调节 行动。 仅凭一个延续或许可门并不能确定实际效果.
-   **投票,而不是推动,在过程内部.** 背景工作(执行、恢复交付、, 续行已过期)在环行中运行 `tickMs`。 。 。 .
-   **Erasure有副本.** `runtime.erase` 从日志中去除事件的有效载荷, 衍生视图, 和认知指数——但内容被复制成延续有效载荷、一能快照, 或召回结果留下.
-   **公共预测由租户分担.** 关键状态的登记册预测 `<tenant>/<key>`· ; `service.readProjection` 只返回呼叫者的租户分区.
-   **拒绝意味着看不见.** 阅读文物时,不允许您看到同样的返回 "没有找到"作为一个缺失的.
-   **召回 优雅地贬低.** 没有 `cognition` 组合, `ctx.recall` 返回时 `{ status: "degraded" }` 而不是失败运行.

## 相关软件包

-   [`@godspeedai/cognate-client`](https://www.npmjs.com/package/@godspeedai/cognate-client) - 那个 消耗这个运行时间的无头客户端; 为你获取运行状态 .
-   [`@godspeedai/cognate-runtime-api`](https://www.npmjs.com/package/@godspeedai/cognate-runtime-api) —— 说 服务与代理授权合同 此套件工具.
-   [`@godspeedai/cognate-store-sqlite`](https://www.npmjs.com/package/@godspeedai/cognate-store-sqlite) —— 说 后面的耐用仓库 `store: "<path>"`。 。 。 .
-   [`@godspeedai/cognate-store-memory`](https://www.npmjs.com/package/@godspeedai/cognate-store-memory) —— 说 带自己的麻黄店过来 `store: { store }`。 。 。 .
-   [`@godspeedai/cognate`](https://www.npmjs.com/package/@godspeedai/cognate) - SDK伞; 用于运行时间和客户端的安装.

## 许可证

阿帕奇 - 2.0

## 常见问题

### @godspeedai/cognate-runtime-bun 是什么？

Bun 参考运行时间:由内核,耐用存储,运行,续作,承诺,出品,以及RuntimeService背后的认知\.

### 如何安装 @godspeedai/cognate-runtime-bun？

在项目目录运行 npm install @godspeedai/cognate-runtime-bun，或使用 pnpm add / yarn add / bun add。

### @godspeedai/cognate-runtime-bun 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/godspeedai\_\_cognate-runtime-bun 是否存在。

### @godspeedai/cognate-runtime-bun 支持 ESM 还是 CommonJS？

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

### @godspeedai/cognate-runtime-bun 可以商用吗？

@godspeedai/cognate-runtime-bun 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @godspeedai/cognate-runtime-bun 的下载量有多少？

根据 npm 官方下载统计，@godspeedai/cognate-runtime-bun 在 2026/10/17 – 2026/11/15 这 30 天内被下载 3,532 次，日均约 118 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @godspeedai/cognate-runtime-bun 还在维护吗？

最新版本 0\.10\.0 发布于 2026/11/16（今天）；至今共发布 20 个版本，其中过去 12 个月发布了 20 个；首次发布于 2026/10/09。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

