@anchrd/colab-sdk

中文文档
0.1.42发布于 2026/11/07UNLICENSEDTypeScriptES Module近 30 天下载 5542

Types, Zod schemas and the service client of Colab, the contract between its UI, backends and outside services.

原始使用文档
文档目录4 节
  1. Install
  2. What it exports
  3. The service client
  4. License

@anchrd/colab-sdk

The contract of Colab: TypeScript types and Zod schemas for everything that crosses between Colab's UI, its backends and outside services, and the client an outside service uses to ask a Colab installation who a person is and what they may do.

It carries no server framework and reads no environment; its only dependencies are zod and ulid. It is released together with @anchrd/colab under the same version number: use the @anchrd/colab-sdk whose version equals the @anchrd/colab your installation runs.

Install

npm install @anchrd/colab-sdk

ES modules only, with type declarations.

What it exports

  • Schemas and their types, one name each, for the input and answer of every tool of Colab's API and MCP. A schema is named after its tool: access_invitation_create takes InvitationCreateInput, access_user_list takes UserListInput. The schema validates at runtime (UserListInput.parse(body)), the type of the same name describes the parsed value.
  • Ids: idSchema(resource) accepts only an id of that resource (user_01J…, node_01J…), and createId(resource) makes one.
  • The error shape ErrorResponse: { error: { code, message } }, with code one of not_found, invalid, conflict, unauthenticated and unavailable (errorCodes).
  • The naming grammar: every capability has one three-part name, package · resource · action, and toolRoute, toolPermission and toolEvent derive its route, right and protocol event.
  • createServiceClient, the client of an outside service.

The service client

A service registered under Settings › Services holds a service key. With it, the service checks the caller's token once per request and decides locally what they may call. Colab accepts only a token it issued for this service (an Operator's, or a person's for the service's OAuth resource); a Colab session and a token for Colab's own /mcp get 401:

import { createServiceClient } from "@anchrd/colab-sdk";

const colab = createServiceClient({
  url: "https://<customer>.anchrd.sh",
  serviceKey: process.env.COLAB_SERVICE_KEY,
});

// Declare the service's interfaces once; they become rights under Settings › Roles.
await colab.interfaces.set("reports", ["read", "export"]);

// Once per request, with the person's token.
const answer = await colab.authorize(token);
if (answer.ok && answer.can("reports", "export")) {
  // answer.identity names the person or machine
}

can() decides on the rules that came back, without another call. Every failure is a result with ok: false, status and error, never a thrown error, and every answer is validated against the schemas above. The client uses the standard fetch, so it runs in Workers, Node, Bun and the browser; fetch and timeoutMs can be passed in.

The service key is a secret: it travels only in the authorization header. Keep it out of logs and answers.

License

UNLICENSED.

版本与发布记录

@anchrd/colab-sdk 共发布 43 个版本,首次发布于 2026/10/16;过去 12 个月发布了 43 个版本。

版本发布日期距今
0.1.42latest2026/11/07今天
0.1.412026/11/071 天前
0.1.402026/11/071 天前
0.1.392026/11/061 天前
0.1.382026/11/061 天前
0.1.372026/11/062 天前

关于 @anchrd/colab-sdk 的常见问题

@anchrd/colab-sdk 是什么?

Types, Zod schemas and the service client of Colab, the contract between its UI, backends and outside services.

如何安装 @anchrd/colab-sdk?

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

@anchrd/colab-sdk 支持 TypeScript 吗?

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

@anchrd/colab-sdk 支持 ESM 还是 CommonJS?

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

@anchrd/colab-sdk 可以商用吗?

@anchrd/colab-sdk 使用 UNLICENSED 许可。作者声明为 UNLICENSED,即不授予公开使用许可(与公共领域的 Unlicense 不同)。使用前需获得作者授权。以上为概括,不构成法律意见,请以许可原文为准。

@anchrd/colab-sdk 的下载量有多少?

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

@anchrd/colab-sdk 还在维护吗?

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