@byok-sdk/cloud-do

中文文档
0.40.0发布于 2026/11/08MITTypeScriptES Module近 30 天下载 4498

Cloudflare Durable Object session host for native pi-durable storage and execution

原始使用文档
文档目录5 节
  1. Install and subclass
  2. Identity and caller access
  3. Platform keys and execution
  4. Storage and the public types
  5. Package checks

@byok-sdk/cloud-do

This package hosts a pi-durable session in a Cloudflare Durable Object. It provides native SQLite storage, inline tools, wake and inbox processing, usage limits, settlement hooks, and transcript reads.

The current stable release is 0.39.0, in the nine-package release set, published on npm latest. From 0.28.2, keys carries the same version. The npm registry read of 2026-11-06 (UTC) lists 0.39.0 as latest for all nine packages. See the release notes. The earlier stable releases were 0.38.0 and 0.37.0 (published 2026-11-04, UTC), 0.36.0 (published 2026-11-03, UTC), 0.35.0 and 0.34.0 (published 2026-11-02, UTC), 0.33.0 and 0.32.0 (published 2026-11-01, UTC), 0.31.0 (published 2026-10-29, UTC), 0.30.2 (published 2026-10-26, UTC), 0.30.1 and 0.30.0 (published 2026-10-24, UTC), 0.29.0 (published 2026-10-23, UTC), 0.28.3 and 0.28.2 (published 2026-10-22, UTC), 0.28.1 / keys 0.13.1 (published 2026-10-21, UTC) and 0.28.0 / keys 0.13.0 (published 2026-10-20, UTC); see the 0.38.0 release notes, the 0.37.0 release notes, the 0.36.0 release notes, the 0.35.0 release notes, the 0.34.0 release notes, the 0.33.0 release notes, the 0.32.0 release notes, the 0.31.0 release notes, the 0.30.2 release notes, the 0.30.1 release notes, the 0.30.0 release notes, the 0.29.0 release notes, the 0.28.3 release notes, the 0.28.2 release notes, the 0.28.1 release notes and the 0.28.0 release notes.

The stable release before them was 0.27.0, with keys 0.12.0. Complete registry readback and isolated installation passed. See the publication record. The rc channel remains 0.27.0-rc.2 / keys 0.12.0-rc.2. See the release notes for the Host upgrade steps. Host acceptance (#195) remains separate and open.

The latest release before 0.27.0 was 0.26.1, in the nine-package release set with keys 0.11.1. Registry readback and isolated installation passed on 2026-10-12. See the publication record. The earlier stable release was 0.26.0 / keys 0.11.0; its publication record remains historical. The earlier published 0.26.0-rc.4 (see the rc.4 publication record) is superseded by 0.27.0-rc.2; 0.26.0-rc.1 to rc.3 are superseded. See the release notes. Live Host acceptance remains separate. The package needs Node 24.22.1 or later for build tooling.

Install and subclass

The following install example names the 0.40.0 source candidate, pending publication. Use an installed package to verify the consumer path.

npm install @byok-sdk/[email protected]
npm install --save-dev @cloudflare/workers-types

The package is ESM. Its root entry imports cloudflare:workers. Run it in workerd. It cannot load in a Node process.

import { AgentDO, getAgentObject, getSessionObject } from '@byok-sdk/cloud-do';

export class ProductAgentDO extends AgentDO {
  protected instructions(): string {
    return 'Use the configured platform tools.';
  }
}

export default {
  fetch(): Response {
    return new Response('Not found', { status: 404 });
  },
};

Configure the subclass binding and SQLite migration in wrangler.jsonc:

{
  "name": "product-agent",
  "main": "src/index.ts",
  "compatibility_date": "2026-08-18",
  "compatibility_flags": ["no_nodejs_compat", "no_nodejs_compat_v2"],
  "durable_objects": {
    "bindings": [{ "name": "AGENTS", "class_name": "ProductAgentDO" }]
  },
  "migrations": [
    { "tag": "v1", "new_sqlite_classes": ["ProductAgentDO"] }
  ]
}

Consumers need @cloudflare/workers-types to resolve the ambient Workers module and the Durable Object types. Use ES2022 and Bundler module resolution. The installed-package smoke uses skipLibCheck: true, as the SDK does. Node compatibility is off in the tested configuration. A consumer with other flags must verify its complete Worker graph.

Identity and caller access

The platform must authorize the tenant, workspace, agent, and session before it calls getSessionObject(). It must authorize the three agent identity fields before it calls getAgentObject().

Names route storage. They do not authorize callers. The helper names use SHA-256 over JSON identity tuples. One session owns one named Durable Object. Public HTTP routing and caller access checks belong to the consumer. The default Worker returns HTTP 404.

Platform keys and execution

Set AIPHABEE_ZAI_API_KEY and AIPHABEE_DEEPSEEK_API_KEY as Worker secrets for the profiles your platform uses. Each environment has its own secrets and Durable Object namespace. Never put key values in source or request data.

The supported profiles are zai_openai and deepseek_direct. The model URLs and model names are fixed in this package. Cloud execution uses platform keys. Local BYOK keys do not enter this runtime.

A task with #654 sealed payload sealing must not go to this runtime. It runs the model with platform keys, so it reads the instruction and the output in plaintext. See protocol §2.5.

Configure the session and supply a dispatcher before tool execution. The subclass can supply instructions, createDispatcher, admitWake, renew, settleRun, projectInvocation, and onInvocationSettled hooks. The platform owns entitlement checks, billing, and external settlement. A terminal run precedes the settlement hook. Failed settlement is retried through the Durable Object alarm. The consumer must make settlement idempotent.

The provider transport guards text before it enters durable storage. Keys are used only in auth headers. The transport rejects redirects. The guard checks exact keys and defined encodings. It cannot detect every obfuscation or short fragment. Do not treat it as caller authorization.

Storage and the public types

DurableObjectSqliteDatabase adapts the Durable Object SQLite connection. openDurableObjectStorage has the local structural factory type (location: DurableObjectStorage) => Promise. Storage is pi-durable's native interface. The package does not import client source or keys types. Its three runtime dependencies are pi-durable, pi-ai, and chord, each pinned to 1.5.0.

The Durable Object owns the physical connection. Closing the adapter invalidates that adapter. It does not close the Durable Object database.

This follows the async adapter in Cloudflare Agents d6656161. Current upstream uses a different synchronous pi contract. Pinned pi 1.5.0 takes async callbacks, so transactionSync() cannot host its transaction callback. Cloudflare documents async SQL transactions on the SQLite storage API.

RunRow and InboxRow are public as they are. They include internal state, revision, admission, settlement, usage, and text-handoff fields. The API golden locks these types. A later breaking type cut requires a MINOR release under the SDK's pre-1.0 policy.

Package checks

The library build emits dist/index.js and a local declaration closure. The dist check rejects missing or escaped declaration paths and undeclared external type imports. The entry dependency contract enforces runtime builtin policy. A separate Wrangler dry run writes dist-worker. That Worker output is not in the npm package.

Release verification installs a real tarball in a temporary consumer. It typechecks the subclass, bundles it with Wrangler, and runs its hook, Durable Object RPC, identity helper, and SQLite adapter in real workerd. The same smoke runs in the Linux, macOS, and Windows release-pack jobs.

Runtime dependencies and size budgets: entry dependency contract.

版本与发布记录

@byok-sdk/cloud-do 共发布 31 个版本,首次发布于 2026/10/07;过去 12 个月发布了 31 个版本。

版本发布日期距今
0.40.0latest2026/11/08今天
0.39.02026/11/072 天前
0.38.02026/11/054 天前
0.37.02026/11/044 天前
0.36.02026/11/035 天前
0.35.02026/11/026 天前

其他发布通道:rc → 0.27.0-rc.2。

关于 @byok-sdk/cloud-do 的常见问题

@byok-sdk/cloud-do 是什么?

Cloudflare Durable Object session host for native pi-durable storage and execution

如何安装 @byok-sdk/cloud-do?

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

@byok-sdk/cloud-do 支持 TypeScript 吗?

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

@byok-sdk/cloud-do 支持 ESM 还是 CommonJS?

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

@byok-sdk/cloud-do 需要什么版本的 Node.js?

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

@byok-sdk/cloud-do 可以商用吗?

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

@byok-sdk/cloud-do 的下载量有多少?

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

@byok-sdk/cloud-do 还在维护吗?

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