@cogitator-ai/tetsu 0.3.1 → 0.3.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 +18 -5
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -123,12 +123,15 @@ Every error is answered in Tetsu's envelope:
|
|
|
123
123
|
| 404 | `AGENT_NOT_FOUND`, `WORKFLOW_NOT_FOUND`, `SWARM_NOT_FOUND` | No such name |
|
|
124
124
|
| 409 | `BLACKBOARD_DISABLED` | The swarm has no blackboard |
|
|
125
125
|
| 409 | `RUN_NOT_PAUSED` | A resume named a thread without a paused run |
|
|
126
|
+
| 499 | `CLIENT_CLOSED_REQUEST` | The client left before a `/run` or `/resume` answer was ready |
|
|
126
127
|
| 422 | `VALIDATION_FAILED` | The body or the path failed its schema; `issues` lists every problem |
|
|
127
128
|
| 501 | `PACKAGE_NOT_INSTALLED` | `@cogitator-ai/workflows` or `@cogitator-ai/swarms` is missing |
|
|
128
|
-
| 503 | `MEMORY_NOT_CONFIGURED` | A thread endpoint was called on a runtime
|
|
129
|
+
| 503 | `MEMORY_NOT_CONFIGURED` | A thread endpoint was called on a runtime with no `memory` config |
|
|
129
130
|
| 4xx/5xx | the `CogitatorError` code | The run failed, e.g. `429 LLM_RATE_LIMITED` with `Retry-After` |
|
|
130
131
|
| 500 | `INTERNAL_SERVER_ERROR` | Anything else; the detail goes to `reportError`, never to the client |
|
|
131
132
|
|
|
133
|
+
Only a `CogitatorError` keeps its message and code. Any other error reaches the client only as a generic internal error: `500 INTERNAL_SERVER_ERROR` in JSON, and `Internal server error` in stream `error` events, WebSocket errors and the `error` field of workflow `node_error` and swarm `agent_error` events. Its text, which can carry connection strings or file paths, never leaves the server.
|
|
134
|
+
|
|
132
135
|
Every route mounts an `onError` hook made by `cogitatorErrors()`. Mount another on the application to answer `CogitatorError`s from your own routes the same way:
|
|
133
136
|
|
|
134
137
|
```typescript
|
|
@@ -159,6 +162,7 @@ To have the OpenAPI document describe the scheme and the `401`, build the hook w
|
|
|
159
162
|
|
|
160
163
|
```typescript
|
|
161
164
|
import { callerHook, cogitatorController } from '@cogitator-ai/tetsu';
|
|
165
|
+
import { controller, createApp, group, route } from '@tetsujs/core';
|
|
162
166
|
import { secured } from '@tetsujs/openapi';
|
|
163
167
|
|
|
164
168
|
const signedIn = secured(callerHook(authenticate), {
|
|
@@ -190,6 +194,7 @@ createApp({
|
|
|
190
194
|
|
|
191
195
|
A thread belongs to the user whose run or message created it, recorded as its `userId`. Runs and the thread endpoints only let that user in: another user's `threadId` answers `403 THREAD_ACCESS_DENIED` and leaves the thread untouched. Callers without a `userId` share the threads that have no owner, and cannot open an owned one.
|
|
192
196
|
|
|
197
|
+
- The thread endpoints use `cogitator.getMemory()`, which connects the configured memory adapter on first use, so they work on a fresh server before any agent has run.
|
|
193
198
|
- `GET` and `DELETE /threads/:id` check the owner first; a thread that does not exist yet reads as empty.
|
|
194
199
|
- `POST /threads/:id/messages` creates a missing thread owned by the caller.
|
|
195
200
|
- A run or stream on another user's thread is refused before the model is called; a stream ends with an `error` event carrying `THREAD_ACCESS_DENIED`.
|
|
@@ -263,7 +268,7 @@ data: [DONE]
|
|
|
263
268
|
|
|
264
269
|
An agent with `reasoning: { summary: true }` also streams its reasoning summary as `reasoning-start`, `reasoning-delta` and `reasoning-end` events. A text or reasoning part opens with its first delta and is closed before a part of the other kind, a tool call or `finish`, so parts never overlap. `POST /agents/:name/run` returns the summary as `reasoning`, and `usage` gains `reasoningTokens`, `cachedInputTokens` and `cacheWriteTokens` when the provider reports them.
|
|
265
270
|
|
|
266
|
-
A run that fails ends with `{"type":"error","message":"…","code":"…"}` instead of `finish`.
|
|
271
|
+
A run that fails ends with `{"type":"error","message":"…","code":"…"}` instead of `finish`. A `CogitatorError` keeps its message and code; anything else is sent as `"message":"Internal server error","code":"INTERNAL_SERVER_ERROR"` and reported to the application's `reportError` with `source: "stream"`. Workflow streams send `workflow` events (`node_started`, `node_completed`, `node_error`, `node_progress`, `workflow_completed`), swarm streams send `swarm` events (`agent_start`, `agent_complete`, `agent_error`, `message`, `swarm_completed`).
|
|
267
272
|
|
|
268
273
|
Validation, `401`, `403` and `404` are answered as JSON before the stream opens.
|
|
269
274
|
|
|
@@ -273,7 +278,7 @@ Validation, `401`, `403` and `404` are answered as JSON before the stream opens.
|
|
|
273
278
|
cogitatorController({ cogitator, agents, auth, websocket: true });
|
|
274
279
|
```
|
|
275
280
|
|
|
276
|
-
The handshake runs `auth` like any route. Each socket runs one agent, workflow or swarm at a time
|
|
281
|
+
The handshake runs `auth` like any route. Each socket runs one agent, workflow or swarm at a time; a `run` or `resume` sent while one is in progress gets an error with `code: 'RUN_IN_PROGRESS'`.
|
|
277
282
|
|
|
278
283
|
| Client sends | Server answers |
|
|
279
284
|
| ------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
|
|
@@ -282,7 +287,7 @@ The handshake runs `auth` like any route. Each socket runs one agent, workflow o
|
|
|
282
287
|
| `{ type: 'stop' }` | cancels the current run |
|
|
283
288
|
| `{ type: 'ping', id? }` | `{ type: 'pong', id }` |
|
|
284
289
|
|
|
285
|
-
Errors arrive as `{ type: 'error', id, error, code }` and leave the socket open; an invalid frame gets `code: 'INVALID_MESSAGE'`. Closing the socket cancels its run. Bun's server-level options such as `maxPayloadLength` are set where the app is served:
|
|
290
|
+
Errors arrive as `{ type: 'error', id, error, code }` and leave the socket open; an invalid frame gets `code: 'INVALID_MESSAGE'`, and an error that is not a `CogitatorError` is sent as `Internal server error` with `code: 'INTERNAL_SERVER_ERROR'`. Closing the socket cancels its run. Bun's server-level options such as `maxPayloadLength` are set where the app is served:
|
|
286
291
|
|
|
287
292
|
```typescript
|
|
288
293
|
Bun.serve({ ...app, websocket: { ...app.websocket, maxPayloadLength: 1024 * 1024 } });
|
|
@@ -293,6 +298,8 @@ Bun.serve({ ...app, websocket: { ...app.websocket, maxPayloadLength: 1024 * 1024
|
|
|
293
298
|
Streams and sockets can stay open for minutes. Pass the `draining` signal of `@tetsujs/lifecycle` so a stopping server ends them and clients reconnect to one that stays:
|
|
294
299
|
|
|
295
300
|
```typescript
|
|
301
|
+
import { onShutdownSignals } from '@tetsujs/lifecycle';
|
|
302
|
+
|
|
296
303
|
let shutdown: ReturnType<typeof onShutdownSignals> | undefined;
|
|
297
304
|
|
|
298
305
|
const app = createApp({
|
|
@@ -306,6 +313,8 @@ shutdown = onShutdownSignals(server);
|
|
|
306
313
|
|
|
307
314
|
Request and response schemas are Zod, so `docs()` and `openapi()` from `@tetsujs/openapi` describe every route, the run failures a `CogitatorError` can produce, and the schemes of a `secured()` caller hook. SSE and WebSocket endpoints are documented by their description only, since OpenAPI cannot describe what follows the headers.
|
|
308
315
|
|
|
316
|
+
The request and response schemas (`RunBody`, `ResumeBody`, `AgentRunResponse`, `SocketMessage`, …) and their TypeScript types (`AgentRunRequest`, `AgentRunResponseBody`, `WebSocketClientMessage`, …) are exported for clients and your own routes, along with the error helpers `cogitatorErrorResponse()`, `cogitatorErrorStatus()` and `describeError()`.
|
|
317
|
+
|
|
309
318
|
## Testing
|
|
310
319
|
|
|
311
320
|
The package is tested with `bun test`: handlers called with `testCtx()`, and the full pipeline through `serve()` from `@tetsujs/core/testing`, including SSE, WebSocket and `assertDescribed()` checks against the OpenAPI document.
|
|
@@ -316,12 +325,16 @@ pnpm --filter @cogitator-ai/tetsu test
|
|
|
316
325
|
|
|
317
326
|
## Example
|
|
318
327
|
|
|
319
|
-
[`examples/integrations/08-tetsu-server.ts`](
|
|
328
|
+
[`examples/integrations/08-tetsu-server.ts`](https://github.com/cogitator-ai/Cogitator-AI/blob/main/examples/integrations/08-tetsu-server.ts) — an app with its own users, its own MCP server for its domain tools, and an agent that acts for the signed-in user:
|
|
320
329
|
|
|
321
330
|
```bash
|
|
322
331
|
bun examples/integrations/08-tetsu-server.ts
|
|
323
332
|
```
|
|
324
333
|
|
|
334
|
+
## Documentation
|
|
335
|
+
|
|
336
|
+
Full guide: [cogitator.app/docs/server-adapters/tetsu](https://cogitator.app/docs/server-adapters/tetsu)
|
|
337
|
+
|
|
325
338
|
## License
|
|
326
339
|
|
|
327
340
|
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cogitator-ai/tetsu",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Tetsu server adapter for Cogitator AI runtime — a controller with agents, threads, workflows, swarms, SSE and WebSocket on Bun",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
"bun": ">=1.4"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@cogitator-ai/core": "0.
|
|
22
|
-
"@cogitator-ai/memory": "0.
|
|
23
|
-
"@cogitator-ai/types": "0.
|
|
24
|
-
"@cogitator-ai/server-shared": "0.3.
|
|
21
|
+
"@cogitator-ai/core": "0.26.0",
|
|
22
|
+
"@cogitator-ai/memory": "0.11.0",
|
|
23
|
+
"@cogitator-ai/types": "0.29.0",
|
|
24
|
+
"@cogitator-ai/server-shared": "0.3.1",
|
|
25
25
|
"zod": "^4.6.5"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
"@tetsujs/sse": "^0.6.1"
|
|
30
30
|
},
|
|
31
31
|
"optionalDependencies": {
|
|
32
|
-
"@cogitator-ai/workflows": "0.
|
|
33
|
-
"@cogitator-ai/swarms": "0.
|
|
32
|
+
"@cogitator-ai/workflows": "0.10.0",
|
|
33
|
+
"@cogitator-ai/swarms": "0.9.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@cogitator-ai/workflows": "0.
|
|
37
|
-
"@cogitator-ai/swarms": "0.
|
|
36
|
+
"@cogitator-ai/workflows": "0.10.0",
|
|
37
|
+
"@cogitator-ai/swarms": "0.9.0",
|
|
38
38
|
"@tetsujs/core": "^0.6.1",
|
|
39
39
|
"@tetsujs/openapi": "^0.6.1",
|
|
40
40
|
"@tetsujs/sse": "^0.6.1",
|