@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解决.
相关软件包
@godspeedai/cognate-events—— 说 商店合同,发包箱, 和一能机械 两种服务都使用.@godspeedai/cognate-store-sqlite财务报告和审定财务报表@godspeedai/cognate-store-memory—— 说 存储执行.@godspeedai/cognate-runtime-bun—— 说 参考运行时间;waitFor和它的背景 循环排出队列.@godspeedai/cognateSDK伞.
许可证
阿帕奇 - 2.0