@godspeedai/cognate-protocol-connect

中文文档
0.10.0发布于 2026/11/16Apache-2.0ES Module构建来源已验证近 30 天下载 3489

Maps RuntimeService to the generated Connect service (server routes and a remote client). Transport-agnostic.

原始使用文档
文档目录6 节
  1. Installation
  2. Quick start
  3. API surface
  4. Limitations
  5. Related packages
  6. License

@godspeedai/cognate-protocol-connect

Maps the Cognate RuntimeService onto the generated Connect service (cognate.v1.RuntimeService), independent of any HTTP server. It provides the server-side route registration and a remote client that behaves like an in-process service.

When to use this package: install it when you host the Connect router yourself (any fetch-based server can drive it) or when you need a typed RuntimeService backed by a remote endpoint. If you serve from Bun, @godspeedai/cognate-protocol-connect-bun wraps this package with a ready-made Bun.serve transport, payload limits, and deadlines — install that instead and you get this one automatically.

Installation

bun add @godspeedai/cognate-protocol-connect

Requires Bun >= 1.4.0. Depends on @connectrpc/connect, @bufbuild/protobuf, @godspeedai/cognate-proto, and the RuntimeService/ServiceError types from @godspeedai/cognate-runtime-api.

Quick start

Turn a Connect transport into a full remote RuntimeService — the returned object satisfies the same interface as an in-process runtime's service:

import { createConnectTransport } from "@connectrpc/connect-web";
import { createRemoteRuntimeService } from "@godspeedai/cognate-protocol-connect";

const service = createRemoteRuntimeService(
  createConnectTransport({ baseUrl: "http://127.0.0.1:3000" }),
  (caller) => issueToken(caller), // Bearer credential for this caller
);

const caller = { actor: { id: "alice", kind: "user" }, tenant: "tenant-a" };
const run = await service.startRun(caller, { agent: "agent.echo", input: { text: "hi" } });
for await (const event of service.events(caller, { runId: run.runId, follow: true })) {
  console.log(event.eventType);
}

Plain JSON works for input and other value-typed fields — the adapter converts to and from protobuf Value for you — and a ServiceError raised by the server arrives with the same code, so service is a drop-in for an in-process service.

On the server side, register the routes on a Connect router:

import { registerRuntimeService } from "@godspeedai/cognate-protocol-connect";

registerRuntimeService(router, runtime.service, {
  // Caller identity comes from request headers, never from message bodies.
  authenticate: (headers) => myBearerAuth(headers.get("authorization")),
  maxJsonDepth: 32, // reject over-deep JSON values from clients
});

A missing or invalid credential fails every route with unauthenticated. If you are serving from Bun, serveRuntime does this registration for you and adds body-size and deadline enforcement.

API surface

  • registerRuntimeService(router, service, { authenticate, maxJsonDepth }) — server routes for every RuntimeService method.
  • createRemoteRuntimeService(transport, tokenFor) — a client-side RuntimeService over any Connect transport; tokenFor supplies the Bearer credential for each caller.
  • errorCodes — the ServiceError code to Connect code table (for example not_found → NotFound), exported so other transports can reuse the exact mapping.

Limitations

  • The service defines unary and server-streaming methods only; there are no client-streaming or bidirectional methods on the wire.
  • Observation ingestion is an in-process mechanism: the remote client's observe always fails with failed_precondition rather than exposing it over the wire.
  • Requests are bounded by your authenticate implementation and maxJsonDepth only; body-size limits and call deadlines are transport concerns (the Bun package adds both).

License

Apache-2.0

版本与发布记录

@godspeedai/cognate-protocol-connect 共发布 20 个版本,首次发布于 2026/10/09;过去 12 个月发布了 20 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.10.0latest2026/11/16今天
0.9.22026/11/152 天前
0.9.12026/11/143 天前
0.9.02026/11/0610 天前
0.8.02026/10/2720 天前
0.7.12026/10/2523 天前

关于 @godspeedai/cognate-protocol-connect 的常见问题

@godspeedai/cognate-protocol-connect 是什么?

Maps RuntimeService to the generated Connect service (server routes and a remote client). Transport-agnostic.

如何安装 @godspeedai/cognate-protocol-connect?

在项目目录运行 npm install @godspeedai/cognate-protocol-connect,或使用 pnpm add / yarn add / bun add。

@godspeedai/cognate-protocol-connect 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/godspeedai__cognate-protocol-connect 是否存在。

@godspeedai/cognate-protocol-connect 支持 ESM 还是 CommonJS?

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

@godspeedai/cognate-protocol-connect 可以商用吗?

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

@godspeedai/cognate-protocol-connect 的下载量有多少?

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

@godspeedai/cognate-protocol-connect 还在维护吗?

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