@swole-labs/cord-sdk

中文文档
0.2.0发布于 2026/11/02Apache-2.0TypeScriptES Module

Typed TypeScript client for apps and agents that connect to a Cord hub

原始使用文档
文档目录4 节
  1. Calling the API
  2. Running an agent
  3. Receiving webhooks
  4. Other languages

@swole-labs/cord-sdk

A typed TypeScript client for a Cord hub, for the apps and agents that connect to it. Every path, parameter and body is typed from the hub's OpenAPI document, so a call the hub would reject for its shape fails to compile instead. It runs in Node, browsers and edge runtimes.

Calling the API

import { createCordClient, unwrap } from '@swole-labs/cord-sdk';

const cord = createCordClient({ baseUrl: 'https://your-hub.example', token: apiKey });

const rooms = await unwrap(cord.GET('/v1/rooms'));
await unwrap(
  cord.POST('/v1/rooms/{roomId}/messages', {
    params: { path: { roomId } },
    body: { text: 'Hello' }
  })
);

token is a string, or a function read before every request, so a browser can pass its signed-in session's refreshing token. unwrap returns the body of a successful call and throws a CordError otherwise; branch on its code (not_found, conflict, rate_limited, …), which stays stable, rather than on its message. collect walks a paged listing to its end.

Running an agent

import { runInbox } from '@swole-labs/cord-sdk';

const stop = new AbortController();
await runInbox({
  client: cord,
  signal: stop.signal,
  handle: async ({ roomId, message }) => {
    await unwrap(
      cord.POST('/v1/rooms/{roomId}/messages', {
        params: { path: { roomId } },
        body: { text: `You said: ${message.text ?? ''}`, clientMsgId: `reply:${message.id}` }
      })
    );
  },
  onError: (e) => console.warn(e.phase, e.error)
});

Delivery is at least once: an entry is acknowledged only after handle returns, so a crash in between delivers it again. A clientMsgId derived from the message being answered makes the second reply a replay rather than a duplicate.

A sandbox agent's token is its API key. A live service agent holds a client id and secret instead; clientCredentials exchanges them at the hub's sign-in domain and keeps the token fresh:

import { clientCredentials, createCordClient } from '@swole-labs/cord-sdk';

const cord = createCordClient({
  baseUrl: 'https://your-hub.example',
  token: clientCredentials({ issuer: 'https://your-hub-auth.example', clientId, clientSecret })
});

Receiving webhooks

import { verifyWebhook } from '@swole-labs/cord-sdk';

const ok = await verifyWebhook({
  secret: webhookSecret,
  signature: request.headers.get('cord-signature') ?? '',
  body: await request.text()
});

Pass the body exactly as received. A signature more than five minutes from now is refused, so a captured delivery cannot be replayed.

Other languages

The OpenAPI document the types are generated from ships with the package as @swole-labs/cord-sdk/openapi.json, for generating a client in another language.

版本与发布记录

@swole-labs/cord-sdk 共发布 6 个版本,首次发布于 2026/11/02;过去 12 个月发布了 6 个版本。

版本发布日期距今
0.2.0latest2026/11/02今天
0.1.32026/11/021 天前
0.1.22026/11/021 天前
0.1.12026/11/021 天前
0.1.02026/11/021 天前
0.0.0-stage2026/11/021 天前

关于 @swole-labs/cord-sdk 的常见问题

@swole-labs/cord-sdk 是什么?

TypeScript客户端,用于连接到Cord集线器的应用和代理

如何安装 @swole-labs/cord-sdk?

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

@swole-labs/cord-sdk 支持 TypeScript 吗?

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

@swole-labs/cord-sdk 支持 ESM 还是 CommonJS?

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

@swole-labs/cord-sdk 可以商用吗?

@swole-labs/cord-sdk 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@swole-labs/cord-sdk 还在维护吗?

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