@flow-state-dev/contracts

中文文档
0.4.0发布于 2026/11/06MITTypeScriptES Module零依赖近 30 天下载 3735

Zero-dependency shared contracts layer (item taxonomy, leaf types, block-instance-id) for the flow-state-dev block framework.

原始使用文档
文档目录3 节
  1. The zero-dependency invariant
  2. What it exports
  3. Who depends on it

@flow-state-dev/contracts

The zero-dependency shared layer at the bottom of the framework spine.

core is the full authoring runtime — it carries heavy dependencies (zod, picomatch, liquidjs, gray-matter, cron-parser). Browser packages and the wider block-authoring ecosystem need the item taxonomy and a handful of pure helpers, but not that weight. contracts is that minimal, dependency-free foundation.

The zero-dependency invariant

This package declares no dependencies and imports nothing outside its own relative module graph. That is the whole point: any consumer can value-import it without pulling the authoring runtime into a browser bundle. The invariant is machine-checked by test/contracts-zero-dep.spec.ts (empty dependencies + a no-non-relative-import scan over src/), so it cannot silently regress.

What it exports

  • Item taxonomy (@flow-state-dev/contracts/items) — the OutputItem union and its members, the RuntimeItem union (OutputItem plus trace rows), Content parts, stream-event types, and the pure resolution helpers: resolveItemVisibility, collapseToCanonicalLog, resolveBlockValue / buildItemLookup / inlineBlockValue / isBlockValue / structureBlockValue, task-attribution and predicate helpers.
  • Internal item surface (@flow-state-dev/contracts/items/internal) — RuntimeItem (also exported from @flow-state-dev/contracts/items), BlockValueInternal, refBlockValue, resolveBlockValueInternal, and parseBlockInstanceId.
  • Block-instance-id helpers (@flow-state-dev/contracts/block-instance-id) — deterministic buildBlockInstanceId / parseBlockInstanceId and the blockPath* segment builders.
  • Pure helpers (@flow-state-dev/contracts/helpers) — deepEqual / looseDeepEqual, cloneValue (structural deep copy), mapLimit (bounded-concurrency map), toError (unknown-throw coercion), the string-case utilities camelToKebab / normalizeTagName, isWindowsReservedName, and the resource-state version rule every ResourceStateStore adapter shares: assertSetExpectedVersion and assertDeleteExpectedVersion refuse a version the verb can't act on by throwing a TypeError, and resourceStateConflict builds the conflict a losing write returns. A custom adapter calls these rather than restating them. Re-exported from @flow-state-dev/core/helpers.
  • Pure leaf types — ModelIdentity, SuspensionReason, SuspensionStatus, RequestStatus.
  • Agent discovery (@flow-state-dev/contracts/types/manifest) — the shared record an agent plans against, ManifestEntry ({ id, kind, purpose, contract? }), the ManifestSource type that projects one domain's existing reader into those entries, and the pinned domain names MANIFEST_DOMAINS / ManifestDomain / isManifestDomain. It lives here because core, orchestration and workforce each project into it and none of them should depend on another to agree on the record. ManifestSource is generic over its context type, since this layer knows nothing of BlockContext; core binds it.
  • Change notices (@flow-state-dev/contracts/types/change-notice) — the kinds a change notice names (ChangeKind: items, request, run, state, resource, resync) and the wire topic a client watches: topic.session(id), topic.user() and topic.org(), each with an optional { resource }. A wire topic names no user, org or tenant id; the server fills those from the caller it verified. Client and engine share it, so it lives here.

The package barrel (@flow-state-dev/contracts) re-exports the item taxonomy, the block-instance-id helpers, the suspension leaf types, the manifest entry/source surface, and the change-notice kinds and wire topics.

Who depends on it

core, client, react, and ui all depend on contracts. core re-exports every symbol from its original path (@flow-state-dev/core, @flow-state-dev/core/items, @flow-state-dev/core/items/internal, the leaf types), so importing these from core is unchanged for end users — the declaration simply lives here now. Browser packages value-import the canonical helpers directly from contracts instead of hand-mirroring them.

版本与发布记录

@flow-state-dev/contracts 共发布 6 个版本,首次发布于 2026/09/18;过去 12 个月发布了 6 个版本。

版本发布日期距今
0.4.0latest2026/11/069 天前
0.3.02026/11/0312 天前
0.2.02026/10/3115 天前
0.1.22026/09/231 个月前
0.1.12026/09/181 个月前
0.1.02026/09/181 个月前

关于 @flow-state-dev/contracts 的常见问题

@flow-state-dev/contracts 是什么?

Zero-dependency shared contracts layer (item taxonomy, leaf types, block-instance-id) for the flow-state-dev block framework.

如何安装 @flow-state-dev/contracts?

在项目目录运行 npm install @flow-state-dev/contracts,或使用 pnpm add / yarn add / bun add。

@flow-state-dev/contracts 支持 TypeScript 吗?

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

@flow-state-dev/contracts 支持 ESM 还是 CommonJS?

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

@flow-state-dev/contracts 需要什么版本的 Node.js?

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

@flow-state-dev/contracts 可以商用吗?

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

@flow-state-dev/contracts 的下载量有多少?

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

@flow-state-dev/contracts 还在维护吗?

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