@godspeedai/cognate-protocol-connect 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +67 -6
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,11 +1,72 @@
|
|
|
1
1
|
# @godspeedai/cognate-protocol-connect
|
|
2
2
|
|
|
3
|
-
Maps `RuntimeService`
|
|
3
|
+
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.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
- `createRemoteRuntimeService(transport, tokenFor)` — a `RuntimeService` over any Connect transport; ServiceError codes round-trip exactly.
|
|
7
|
-
- `errorCodes` — ServiceError ↔ Connect code table.
|
|
5
|
+
**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`](https://www.npmjs.com/package/@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.
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
## Installation
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
```sh
|
|
10
|
+
bun add @godspeedai/cognate-protocol-connect
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Requires [Bun](https://bun.sh) >= 1.4.0. Depends on `@connectrpc/connect`, `@bufbuild/protobuf`, [`@godspeedai/cognate-proto`](https://www.npmjs.com/package/@godspeedai/cognate-proto), and the `RuntimeService`/`ServiceError` types from [`@godspeedai/cognate-runtime-api`](https://www.npmjs.com/package/@godspeedai/cognate-runtime-api).
|
|
14
|
+
|
|
15
|
+
## Quick start
|
|
16
|
+
|
|
17
|
+
Turn a Connect transport into a full remote `RuntimeService` — the returned object satisfies the same interface as an in-process runtime's service:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { createConnectTransport } from "@connectrpc/connect-web";
|
|
21
|
+
import { createRemoteRuntimeService } from "@godspeedai/cognate-protocol-connect";
|
|
22
|
+
|
|
23
|
+
const service = createRemoteRuntimeService(
|
|
24
|
+
createConnectTransport({ baseUrl: "http://127.0.0.1:3000" }),
|
|
25
|
+
(caller) => issueToken(caller), // Bearer credential for this caller
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const caller = { actor: { id: "alice", kind: "user" }, tenant: "tenant-a" };
|
|
29
|
+
const run = await service.startRun(caller, { agent: "agent.echo", input: { text: "hi" } });
|
|
30
|
+
for await (const event of service.events(caller, { runId: run.runId, follow: true })) {
|
|
31
|
+
console.log(event.eventType);
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
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.
|
|
36
|
+
|
|
37
|
+
On the server side, register the routes on a Connect router:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { registerRuntimeService } from "@godspeedai/cognate-protocol-connect";
|
|
41
|
+
|
|
42
|
+
registerRuntimeService(router, runtime.service, {
|
|
43
|
+
// Caller identity comes from request headers, never from message bodies.
|
|
44
|
+
authenticate: (headers) => myBearerAuth(headers.get("authorization")),
|
|
45
|
+
maxJsonDepth: 32, // reject over-deep JSON values from clients
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
A missing or invalid credential fails every route with `unauthenticated`. If you are serving from Bun, [`serveRuntime`](https://www.npmjs.com/package/@godspeedai/cognate-protocol-connect-bun) does this registration for you and adds body-size and deadline enforcement.
|
|
50
|
+
|
|
51
|
+
## API surface
|
|
52
|
+
|
|
53
|
+
- `registerRuntimeService(router, service, { authenticate, maxJsonDepth })` — server routes for every `RuntimeService` method.
|
|
54
|
+
- `createRemoteRuntimeService(transport, tokenFor)` — a client-side `RuntimeService` over any Connect transport; `tokenFor` supplies the Bearer credential for each caller.
|
|
55
|
+
- `errorCodes` — the `ServiceError` code to Connect code table (for example `not_found` → `NotFound`), exported so other transports can reuse the exact mapping.
|
|
56
|
+
|
|
57
|
+
## Limitations
|
|
58
|
+
|
|
59
|
+
- The service defines unary and server-streaming methods only; there are no client-streaming or bidirectional methods on the wire.
|
|
60
|
+
- Observation ingestion is an in-process mechanism: the remote client's `observe` always fails with `failed_precondition` rather than exposing it over the wire.
|
|
61
|
+
- Requests are bounded by your `authenticate` implementation and `maxJsonDepth` only; body-size limits and call deadlines are transport concerns (the Bun package adds both).
|
|
62
|
+
|
|
63
|
+
## Related packages
|
|
64
|
+
|
|
65
|
+
- [`@godspeedai/cognate-protocol-connect-bun`](https://www.npmjs.com/package/@godspeedai/cognate-protocol-connect-bun) — `Bun.serve` transport, limits, deadlines, and the fetch transport factory.
|
|
66
|
+
- [`@godspeedai/cognate-proto`](https://www.npmjs.com/package/@godspeedai/cognate-proto) — the generated messages and service descriptor this package maps to.
|
|
67
|
+
- [`@godspeedai/cognate-runtime-api`](https://www.npmjs.com/package/@godspeedai/cognate-runtime-api) — the `RuntimeService` contract and `ServiceError` type.
|
|
68
|
+
- [`@godspeedai/cognate`](https://www.npmjs.com/package/@godspeedai/cognate) — the SDK umbrella.
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
|
|
72
|
+
Apache-2.0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@godspeedai/cognate-protocol-connect",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Maps RuntimeService to the generated Connect service (server routes and a remote client). Transport-agnostic.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@bufbuild/protobuf": "2.15.0",
|
|
26
|
-
"@godspeedai/cognate-events": "^0.1.
|
|
27
|
-
"@godspeedai/cognate-kernel-api": "^0.1.
|
|
28
|
-
"@godspeedai/cognate-proto": "^0.1.
|
|
29
|
-
"@godspeedai/cognate-runtime-api": "^0.1.
|
|
26
|
+
"@godspeedai/cognate-events": "^0.1.2",
|
|
27
|
+
"@godspeedai/cognate-kernel-api": "^0.1.2",
|
|
28
|
+
"@godspeedai/cognate-proto": "^0.1.2",
|
|
29
|
+
"@godspeedai/cognate-runtime-api": "^0.1.2",
|
|
30
30
|
"@connectrpc/connect": "2.2.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|