@byok-sdk/cloud

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

BYOK SDK hosted device surface: stateless frozen-v1 HTTP handlers over tenant-first @byok-sdk/core ports

原始使用文档
文档目录3 节
  1. Immutable offer readback
  2. Mailbox wake composition
  3. Hosted Host contract

@byok-sdk/cloud

Stateless hosted BYOK HTTP handlers and an in-memory reference composition over tenant-first @byok-sdk/core ports. It owns device-facing protocol/auth/policy logic but no durable database or object-storage driver.

Pair it with @byok-sdk/cloud-dataplane for Postgres + R2 production storage.

authenticateHostedDeviceAssertion() is the hosted connector-binding auth composition. It adapts the current DeviceDirectory row and CloudCrypto to core's single-use authenticator; callers must inject a replay authority and trusted deployment bindings. Create durable connector state only after it returns a principal. OAuth refresh tokens and the resulting long-lived profile remain host-owned and are never stored by this API.

const authenticated = await authenticateHostedDeviceAssertion(assertion, {
  devices,
  crypto,
  replay,
  clock,
  expected: { issuer, productId, audience: 'connector-binding' },
});
if (authenticated === undefined) throw new Error('unauthorized');
await connectorProfiles.bind(authenticated.device, providerLogin);

Hosted compositions name the toolsets on an Agent offer, which the device must admit with toolset-selection:

await cloud.enqueueAgentOffer(tenantId, deviceId, {
  taskId,
  payload: {
    instruction: 'Research the account and prepare the next sales action.',
    runtime: 'claude',
    agentRef,
    sessionRef,
    requiredToolsets: ['salesko.prospecting'],
  },
});

Unlike the live self-hosted coordinator, this stateless enqueue API cannot infer current device capabilities; the host must route to a device known to advertise toolset-selection. listPresence(tenant) includes the optional configuredToolsets reported by each live daemon, so the host can narrow candidate devices before enqueue. This is TTL-bounded discovery, not execution authority: the daemon still resolves every required ID locally and declines fail-closed if its configuration changed.

Reading a task's outcome goes through the same first terminal fact twice: readTerminalReceipt(tenant, taskId) returns the stored envelope raw (after redactTasks it throws task_content_redacted), and readTaskResult(tenant, taskId) decodes that same receipt into a typed TerminalResult — the state, plus summary/sessionRef/artifactRefs/ document on a completion or reason/retryable on a failure — projected verbatim with no re-validation:

const result = await cloud.readTaskResult(tenantId, taskId);
if (result === undefined) {
  // No terminal fact and no Host cancellation yet. A decline is a terminal:
  // it reads back as `failed` with its `code`.
} else if (result.state === 'failed' && result.retryable) {
  // re-offer
}

document is absent, never null, when the daemon sent none; a receipt whose stored body is not a terminal envelope throws ByokCloudError rather than returning a best-effort shape.

MIT licensed. Node.js 24.22.1 or newer.

Immutable offer readback

readTaskOffer(tenant, taskId) reads the immutable offer receipt using the TaskAttempt target and stable message identity. It validates the protocol payload, target/Agent binding and delivered marker. Corrupt receipts throw; missing attempt or missing offer receipt returns undefined. The returned recordedAt is receipt time, not transport time; no mailbox sequence is invented. A delivered=false read is not evidence that append never happened. Host-only message context is a separate authority, not part of this offer projection. The API's persistence is that of the injected receipts store: in-memory restart and Postgres generic receipt retention are not upgraded by this read method.

Mailbox wake composition

createByokCloud and tenantStoresFor require a mailboxWake port. It is a lossy hint: mailbox reads remain the only event/cursor authority. A held poll subscribes before its first read, re-reads after a hint or the fallback interval, and closes its subscription on response, error or request abort. Every live empty response follows a final read, including the replay-floor check.

createInMemoryByokCloud defaults to createInProcessMailboxWake() and exposes that same instance as mailboxWake for hosts building tenant facades directly. Direct compositions inject createInProcessMailboxWake({ fallbackMs: 5_000 }), or the Node/Postgres listener from @byok-sdk/cloud-dataplane. The default fallback is DEFAULT_MAILBOX_WAKE_FALLBACK_MS (5 seconds). There is no interval option or alternate polling hold. Append and cancellation hints are emitted only after their store commits; direct writes to naked stores rely on fallback.

Hosted Host contract

A Topology H Host on Cloudflare Workers follows the hosted Host contract. It maps each task state to a Host action. It also gives the rescan, wake, message consume, idle cost and retention rules.

Runtime dependencies and size budgets: entry dependency contract.

版本与发布记录

@byok-sdk/cloud 共发布 61 个版本,首次发布于 2026/08/09;过去 12 个月发布了 61 个版本。

版本发布日期距今
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 天前

其他发布通道:beta → 0.8.0-beta.0,rc → 0.27.0-rc.2。

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

@byok-sdk/cloud 是什么?

BYOK SDK hosted device surface: stateless frozen-v1 HTTP handlers over tenant-first @byok-sdk/core ports

如何安装 @byok-sdk/cloud?

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

@byok-sdk/cloud 支持 TypeScript 吗?

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

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

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

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

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

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

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

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

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

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

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