@godspeedai/cognate-continuations

中文文档
0.10.0发布于 2026/11/16Apache-2.0ES Module构建来源已验证近 30 天下载 3589

持久延续和长期储存的外部承诺(第9.3节,第12节).

中文使用文档
文档目录6 节
  1. 安装
  2. 继续快速启动
  3. 承诺迅速开始
  4. 限制
  5. 相关软件包
  6. 许可证

@godspideai/ cognate- continuation 页面存档备份,存于互联网档案馆

对Cognate应用的持久暂停和持久外部影响. ContinuationService 将工作流程停放,直到外界回复(人类认可、召回); CommitmentService 记录影响外部系统的意图,并将其驱动至 已知结果。 都把每一个转变都当作你 @godspeedai/cognate-events 存储器,所以它们能幸存 崩溃和重启.

何时使用此软件包 : 您的运行必须等待稍后到来的输入, 或者它必须 给一个系统打电话,“它是否发生?” 续 以审计线索暂停;承诺是消防和遗忘HTTP呼叫的替代办法.

安装

bun add @godspeedai/cognate-continuations

要求数 阿宝 1.4.0和一家商店: @godspeedai/cognate-store-sqlite 耐久性或耐久性 @godspeedai/cognate-store-memory 测试。 SDK号飞船 Bun-native TypeScript源, 所以添加 @types/bun 财务报告和审定财务报表 @types/node 在检查您的工程时, 作为非依赖性 .

继续快速启动

import { openSqliteStore } from "@godspeedai/cognate-store-sqlite";
import { ContinuationService } from "@godspeedai/cognate-continuations";

const store = openSqliteStore({ path: "./app.sqlite" });
const continuations = new ContinuationService(store, {
  policy: {
    authorize: ({ actor }) =>
      actor.kind === "user" ? { allow: true, reason: "approver" } : { allow: false, reason: "not an approver" },
  },
});

// Register the code that runs when a continuation of this type is resumed.
const unregister = continuations.registerHandler({
  id: "refund.resume",
  version: "1.0.0",
  supports: (storedVersion) => storedVersion.startsWith("1."),
  handle: async (record) => {
    // continue the workflow with record.resolution.input
  },
});

const request = await continuations.open({
  type: "refund-approval",
  tenant: "tenant-a",
  runId: "run-1",
  scopeId: "root",
  correlationId: "corr-1",
  condition: { kind: "human_approval", role: "manager" },
  payload: { amount: 42 },
  handler: { id: "refund.resume", version: "1.0.0" },
  expiresAt: Date.now() + 7 * 24 * 60 * 60 * 1000, // optional
});

// Later — when the approval arrives:
const outcome = await continuations.resume(request.id, {
  actor: { id: "alice", kind: "user" },
  idempotencyKey: "approval-form-8123",
  input: { approved: true },
});
// outcome.kind is one of:
//   "transitioned" | "duplicate" | "already_terminal" | "denied" | "version_mismatch" | "not_found"

// From a background loop: deliver resumed continuations to handlers, expire due ones.
await continuations.dispatchResumes();
await continuations.expireDue();

继续移动 OPEN → RESUMED | CANCELLED | EXPIRED | FAILED,准确的一次: 同时恢复/中止/终止尝试决定单一终端过渡,失败者 起来 already_terminal。用相同的行为者重复请求,并返回偶能键 duplicate 与原始结果。 复出续作,其注册处理者 不支持存储的处理器版本到 BLOCKED 而不是交付; unblock 返回到 RESUMED 在注册兼容的处理器后交付.

承诺迅速开始

import { CommitmentService } from "@godspeedai/cognate-continuations";

const commitments = new CommitmentService(store);

commitments.registerTarget({
  id: "payment-api",
  idempotent: true, // true only if the target deduplicates retries by idempotency key
  async dispatch({ idempotencyKey, payload }) {
    const remoteRef = await chargeCard(idempotencyKey, payload); // your call
    return { remoteRef, result: { charged: true } };
  },
  // optional: lets reconcile() ask the target what happened
  async status({ idempotencyKey }) {
    return { state: "succeeded", remoteRef: "ch_123", result: { charged: true } };
  },
});

await commitments.intend({
  targetId: "payment-api",
  operation: "charge",
  idempotencyKey: "order-42",
  payload: { cents: 1999 },
  tenant: "tenant-a",
  scopeId: "root",
  correlationId: "corr-1",
});

// From a background loop:
await commitments.dispatch();

承诺行动 INTENDED → DISPATCHING → SUCCEEDED | FAILED | UNKNOWN_RECONCILIATION_REQUIRED。 。 。 . dispatch 记录 DISPATCHING 在此之前 呼唤 因此,坠机永远不会失去一个尝试开始的事实。 最终拒绝 (掷出) CommitmentRejectedError 从 dispatch)是终端 FAILED; 任何其他错误是 UNKNOWN ——只有在目标具有同位素时才自动复试,否则留作 reconcile() (任务) target.status)或(或) resolveManually()为了推翻一项成功的承诺, compensate() 创建一个 新设 承诺 compensates 设定; 原作从不 已变相.

限制

  • 处理器和目标在程序内注册。 在重启前重新登记 dispatchResumes()编号 :dispatch() 将会成功; 无法完成的工作重复进行备份 (默认基础 1 s, 最大 30 s, 8 个尝试) 然后等待操作者的注意 .
  • 送货是至少一次:处理者必须容忍不止一次被叫来.
  • 这里没有计时器 打电话 expireDue() 财务报告和审定财务报表 dispatch()编号 :dispatchResumes() 从你的 自己的背景循环( 引用运行时间为您做此操作) .
  • 承诺不会使外部系统发生交易。 它们产生结果 可识可知数字 : UNKNOWN_RECONCILIATION_REQUIRED 还需要 reconcile 或者说 resolveManually 解决.

许可证

阿帕奇 - 2.0

版本与发布记录

@godspeedai/cognate-continuations 共发布 20 个版本,首次发布于 2026/10/09;过去 12 个月发布了 20 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.10.0latest2026/11/16今天
0.9.22026/11/152 天前
0.9.12026/11/143 天前
0.9.02026/11/0610 天前
0.8.02026/10/2720 天前
0.7.12026/10/2523 天前

关于 @godspeedai/cognate-continuations 的常见问题

@godspeedai/cognate-continuations 是什么?

持久延续和长期储存的外部承诺(第9.3节,第12节).

如何安装 @godspeedai/cognate-continuations?

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

@godspeedai/cognate-continuations 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/godspeedai__cognate-continuations 是否存在。

@godspeedai/cognate-continuations 支持 ESM 还是 CommonJS?

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

@godspeedai/cognate-continuations 可以商用吗?

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

@godspeedai/cognate-continuations 的下载量有多少?

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

@godspeedai/cognate-continuations 还在维护吗?

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