@flop-labs/contracts

中文文档
0.1.2发布于 2026/11/08MIT OR Apache-2.0TypeScriptES Module零依赖近 30 天下载 2960

Generated structural contracts for FLOP's public inference HTTP API

原始使用文档

@flop-labs/contracts

Structural types, JSON Schema exports, and assertion validators for the FLOP public HTTP API. Version 0.1.0 covers listModels, getModel, and JSON createChatCompletion payloads and streaming frames from services/rest-gateway/openapi.yaml. The unreleased surface also includes exact-ID credential receipt lookup.

npm install @flop-labs/contracts
import { assertModelList, type ModelList } from "@flop-labs/contracts";

const response = await fetch("https://api.flop.network/v1/models");
const value: unknown = await response.json();
assertModelList(value);
const models: ModelList = value;

Exports: Model, ModelList (also ModelListResponse), ModelResponse, ChatCompletionRequest, ChatCompletionResponse, ChatCompletionChunk, and ChatCompletionStreamError; their assert* functions and *Schema objects. Invalid data throws ContractValidationError; its message contains the contract name, never the submitted values.

CredentialReceipt, CredentialReceiptError and CredentialReceiptRequestId also export assert* functions and *Schema objects, generated from GET /keys/me/receipts/{request_id}. A receipt is a current scoped ledger observation; it does not rewrite the original completion checkpoint. Exact terminal allocations use settled_spend_raw decimal strings in raw FLOP units (10^18 raw = 1 FLOP). Unavailable values remain null. A pooled channel event is not a separate payment or burn transaction for each request. See the client's recovery example for authority, state, retention and manual replay rules.

Validation checks structure without coercion, default insertion, or removal of fields. Responses allow extensions, including receipt evidence, exactly as the source schemas allow. Validating an envelope does not authenticate its evidence, verify a receipt, or establish settlement/finality. Request validation follows the API schema. ChatCompletionStreamUsage and ChatCompletionToolCallFragment also have types, assert* functions and *Schema objects. assertChatCompletionStreamError covers in-band broker errors (including estimated usage and retry hints), session expiry, and receipt reconciliation failures; it does not validate arbitrary HTTP error bodies.

OpenAPI 3.1 models the SSE wire body as a string and references decoded data schemas through x-sse-data-schema. The literal [DONE] is a framing sentinel rather than a JSON chunk. Structural assertions validate individual frames; @flop-labs/client additionally enforces ordering, identity consistency, complete tool-call assembly, and terminal behavior. Estimated error usage does not become receipt evidence by passing validation.

The published ESM package has no runtime dependencies. Types are generated with json-schema-to-typescript; AJV generates standalone JSON Schema 2020-12 validators. Generation fails if validators start requiring runtime helpers, so a schema change cannot silently introduce a dependency.

From the repository root:

pnpm --filter @flop-labs/contracts generate
pnpm --filter @flop-labs/contracts check:generated
pnpm --filter @flop-labs/contracts build
pnpm --filter @flop-labs/contracts test

Generated files are checked in. Edit the canonical OpenAPI schemas, regenerate, and review their consumer impact together. Schema identities and package versions describe this contract artifact; they do not assert server or runtime compatibility.

版本与发布记录

@flop-labs/contracts 共发布 3 个版本,首次发布于 2026/10/29;过去 12 个月发布了 3 个版本。

版本发布日期距今
0.1.2latest2026/11/087 天前
0.1.12026/10/2917 天前
0.0.0-stage2026/10/2917 天前

关于 @flop-labs/contracts 的常见问题

@flop-labs/contracts 是什么?

Generated structural contracts for FLOP's public inference HTTP API

如何安装 @flop-labs/contracts?

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

@flop-labs/contracts 支持 TypeScript 吗?

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

@flop-labs/contracts 支持 ESM 还是 CommonJS?

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

@flop-labs/contracts 需要什么版本的 Node.js?

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

@flop-labs/contracts 可以商用吗?

@flop-labs/contracts 使用 MIT OR Apache-2.0 许可。可在 MIT、Apache-2.0 中任选其一遵守。选择 MIT 时,宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@flop-labs/contracts 的下载量有多少?

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

@flop-labs/contracts 还在维护吗?

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