@cogitator-ai/fastify 0.8.5 → 0.9.0

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.
Files changed (43) hide show
  1. package/README.md +70 -23
  2. package/dist/hooks/auth.d.ts +6 -0
  3. package/dist/hooks/auth.d.ts.map +1 -1
  4. package/dist/hooks/auth.js +14 -6
  5. package/dist/hooks/auth.js.map +1 -1
  6. package/dist/hooks/error-handler.d.ts.map +1 -1
  7. package/dist/hooks/error-handler.js +12 -25
  8. package/dist/hooks/error-handler.js.map +1 -1
  9. package/dist/hooks/index.d.ts +1 -1
  10. package/dist/hooks/index.d.ts.map +1 -1
  11. package/dist/hooks/index.js +1 -1
  12. package/dist/hooks/index.js.map +1 -1
  13. package/dist/index.d.ts +2 -2
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +1 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/plugin.d.ts.map +1 -1
  18. package/dist/plugin.js +25 -15
  19. package/dist/plugin.js.map +1 -1
  20. package/dist/routes/agents.d.ts.map +1 -1
  21. package/dist/routes/agents.js +13 -1
  22. package/dist/routes/agents.js.map +1 -1
  23. package/dist/routes/swarms.d.ts.map +1 -1
  24. package/dist/routes/swarms.js +12 -7
  25. package/dist/routes/swarms.js.map +1 -1
  26. package/dist/routes/threads.d.ts.map +1 -1
  27. package/dist/routes/threads.js +15 -17
  28. package/dist/routes/threads.js.map +1 -1
  29. package/dist/routes/utils.d.ts +18 -10
  30. package/dist/routes/utils.d.ts.map +1 -1
  31. package/dist/routes/utils.js +39 -15
  32. package/dist/routes/utils.js.map +1 -1
  33. package/dist/routes/workflows.d.ts.map +1 -1
  34. package/dist/routes/workflows.js +15 -10
  35. package/dist/routes/workflows.js.map +1 -1
  36. package/dist/types.d.ts +147 -1
  37. package/dist/types.d.ts.map +1 -1
  38. package/dist/types.js +81 -21
  39. package/dist/types.js.map +1 -1
  40. package/dist/websocket/handler.d.ts.map +1 -1
  41. package/dist/websocket/handler.js +100 -19
  42. package/dist/websocket/handler.js.map +1 -1
  43. package/package.json +8 -8
package/README.md CHANGED
@@ -60,13 +60,25 @@ Bodies are validated with JSON Schema (`input` must contain more than whitespace
60
60
  ### Threads (Memory)
61
61
 
62
62
  ```
63
- GET /api/threads/:id - Get thread messages
63
+ GET /api/threads/:id - Get thread messages, a page at a time with ?limit&cursor
64
64
  POST /api/threads/:id/messages - Add message to thread
65
65
  DELETE /api/threads/:id - Delete thread
66
66
  ```
67
67
 
68
68
  The routes use `cogitator.getMemory()`, which connects the configured memory adapter on first use, so threads can be read on a fresh server before any agent has run. Only a `Cogitator` without `memory` configured answers `503 UNAVAILABLE`. Messages take `role` `user` or `assistant` (more with `threadMessageRoles`), and `metadata` is stored on the memory entry.
69
69
 
70
+ `GET /threads/:id` answers the whole thread by default. With `?limit=50` it answers the newest 50 messages (oldest first within the page) and a `nextCursor`, and `?limit=50&cursor=<nextCursor>` the 50 before them, until an answer has no `nextCursor`. Messages written in the same millisecond are never skipped or repeated across pages. A `limit` outside 1 to 1000 or a cursor the server never gave is refused with `400 INVALID_INPUT`, with the message every adapter gives.
71
+
72
+ ```typescript
73
+ let cursor: string | undefined;
74
+ do {
75
+ const query = new URLSearchParams({ limit: '50', ...(cursor && { cursor }) });
76
+ const page = await (await fetch(`/api/threads/${threadId}?${query}`)).json();
77
+ render(page.messages);
78
+ cursor = page.nextCursor;
79
+ } while (cursor);
80
+ ```
81
+
70
82
  Request bodies go through the validators of `@cogitator-ai/server-shared` in a `preValidation` hook, before the JSON schema could coerce `input: 42` into `"42"`, so Fastify refuses exactly what the other adapters refuse, and the schemas document the bodies.
71
83
 
72
84
  - A run sends `context` to the model as data the application supplied, and the model reads a `system` thread message as operator instructions, so clients may set neither unless the server allows it: `acceptContext` lists the `context` keys clients may send (`true` accepts any key, for clients trusted like your own code), and `threadMessageRoles` the roles of `POST /threads/:id/messages` (`user` and `assistant` by default). Anything else is refused with `400 INVALID_INPUT`, over HTTP and WebSocket alike.
@@ -83,7 +95,7 @@ POST /api/workflows/:name/run - Run workflow
83
95
  POST /api/workflows/:name/stream - Stream workflow events
84
96
  ```
85
97
 
86
- Options are limited to `maxConcurrency`/`maxIterations` (positive integers), and `checkpoint: true` is refused, since the server keeps no checkpoint store to resume from. A failed workflow returns `500 WORKFLOW_FAILED` (the stream ends with an `error` event instead of `workflow_completed`). Disconnecting aborts the workflow. Stream events are `{ type: 'workflow', event, data }` with `event` one of `node_started`, `node_completed`, `node_error`, `node_progress`, `workflow_completed`.
98
+ Options are limited to `maxConcurrency`/`maxIterations` (positive integers, held to `limits.workflowMaxConcurrency` and `limits.workflowMaxIterations` when set, which a request that asks for nothing gets), and `checkpoint: true` is refused, since the server keeps no checkpoint store to resume from. A failed workflow answers the error it failed with, mapped like any other run error (a node that hit `LLM_RATE_LIMITED` answers `429` with `Retry-After`, an internal error `500 INTERNAL_ERROR`), and its stream ends with an `error` event carrying that code instead of `workflow_completed`. Disconnecting aborts the workflow. Stream events are `{ type: 'workflow', event, data }` with `event` one of `node_started`, `node_completed`, `node_error`, `node_progress`, `workflow_completed`.
87
99
 
88
100
  ### Swarms
89
101
 
@@ -94,7 +106,7 @@ POST /api/swarms/:name/stream - Stream swarm events
94
106
  GET /api/swarms/:name/blackboard - Get configured blackboard sections
95
107
  ```
96
108
 
97
- `timeout` must be positive. Disconnecting aborts the swarm. Stream events are `{ type: 'swarm', event, data }`: `agent_start`, `agent_complete`, `agent_error`, `message`, the swarm's own events, and finally `swarm_completed` with the output and usage. Each run creates a fresh swarm, so the blackboard endpoint returns the configured initial sections.
109
+ `timeout` must be positive. With `limits.swarmTimeout` set, a longer timeout is held to it and a run without one gets it, and a swarm that runs out of time answers `504 RUN_TIMEOUT`. Disconnecting aborts the swarm. Stream events are `{ type: 'swarm', event, data }`: `agent_start`, `agent_complete`, `agent_error`, `message`, the swarm's own events, and finally `swarm_completed` with the output and usage. Each run creates a fresh swarm, so the blackboard endpoint returns the configured initial sections.
98
110
 
99
111
  ### Tools & Docs
100
112
 
@@ -106,7 +118,7 @@ GET /api/docs - Swagger UI (enableSwagger)
106
118
  GET /api/docs/json - OpenAPI spec (enableSwagger)
107
119
  ```
108
120
 
109
- The OpenAPI document is generated by `@fastify/swagger` from the route schemas.
121
+ The OpenAPI document is generated by `@fastify/swagger` from the route schemas, which show the operator's `limits` as the defaults of the capped fields.
110
122
 
111
123
  ## Configuration
112
124
 
@@ -146,6 +158,21 @@ await fastify.register(cogitatorPlugin, {
146
158
  websocket: {
147
159
  path: '/ws',
148
160
  },
161
+
162
+ // Caps on what a request may ask a run for. A larger value is held to the cap,
163
+ // a request without one gets the cap. Checked when the plugin is registered.
164
+ limits: { swarmTimeout: 120_000, workflowMaxIterations: 50, workflowMaxConcurrency: 4 },
165
+
166
+ // 'deny' answers 401 to callers without a userId. Health, ready and the docs stay open.
167
+ anonymous: 'deny',
168
+
169
+ // Called with the auth context and the thread of every request that names one.
170
+ // false answers 403 THREAD_FORBIDDEN and no run starts.
171
+ authorizeThread: (auth, threadId) => threadId.startsWith(`${auth?.userId}:`),
172
+
173
+ // Dependencies for the tools of agent runs, streams and resumes (context.deps).
174
+ // Built from the request on the server, never read from the body.
175
+ deps: async (request) => ({ db: await tenantDb(request.headers['x-tenant']) }),
149
176
  });
150
177
  ```
151
178
 
@@ -157,6 +184,14 @@ When `auth` returns a `userId`, everything a caller does with threads is scoped
157
184
  - `GET /threads/:id`, `POST /threads/:id/messages` and `DELETE /threads/:id` check the thread's owner first; `POST` to an unknown id creates the thread owned by the caller.
158
185
  - Another user's thread answers `403` with code `THREAD_ACCESS_DENIED`, and its messages are neither returned nor changed.
159
186
  - Threads created earlier without an owner (no `userId`) stay open only to callers without a `userId`, such as servers with no `auth` configured.
187
+ - `authorizeThread(auth, threadId)` adds your own rule on top of ownership, for shared or team threads. It runs on every route that names a thread (agent run, stream and resume, swarm run and stream, `GET`, `DELETE` and `POST /threads/:id/messages`) and on WebSocket runs with a `threadId`, after the body is validated and before core checks the owner. Answering `false` refuses with `403 THREAD_FORBIDDEN`, and no run starts.
188
+ - `anonymous: 'deny'` refuses every caller whose `auth` gave no `userId` with `401 UNAUTHORIZED`, WebSocket upgrades included. `/health`, `/ready` and `/docs` stay open. An unknown path under the prefix answers `401` too, so an anonymous caller cannot probe which routes exist, and `404 NOT_FOUND` once the caller has a `userId`. The default, `'allow'`, lets anonymous callers in as before, and an unknown path answers `404 NOT_FOUND` in the error envelope.
189
+
190
+ ### Limits and deps
191
+
192
+ `limits` caps what a client may ask a run for: `swarmTimeout` (ms), `workflowMaxIterations` and `workflowMaxConcurrency`. A request is never refused over a limit: it gets the smaller of what it asked for and the limit, or the limit when it asked for nothing, over HTTP and SSE alike. The route schemas give each limit as the default of its field, without a `maximum`, so Fastify does not refuse a larger value. Each limit must be a positive integer, or registering the plugin fails.
193
+
194
+ `deps: (request) => deps` builds the dependencies agent tools read as `context.deps` (a database handle, a tenant, a client), and the run, stream or resume gets them as `deps`. They are built on the server for each request and never come from the body. Over WebSocket the hook gets the upgrade's `FastifyRequest`, which went through your hooks like any request, and is called for each run. An error the hook throws is answered like a run error, before a stream starts, and over WebSocket (like an error `authorizeThread` throws) with `{ type: 'error', id, error }`, starting no run.
160
195
 
161
196
  ### Approvals
162
197
 
@@ -236,7 +271,7 @@ Text is emitted in `text-start`/`text-delta`/`text-end` blocks that are closed a
236
271
 
237
272
  ## WebSocket Support
238
273
 
239
- Enable real-time bidirectional communication (requires `@fastify/websocket`; without it the plugin logs a warning and skips the endpoint). The endpoint is `<prefix>/ws` unless `websocket.path` says otherwise, and the `auth` hook runs on the upgrade request.
274
+ Enable real-time bidirectional communication (requires `@fastify/websocket`, without it the plugin logs a warning and skips the endpoint). The endpoint is `<prefix>/ws` unless `websocket.path` says otherwise, and the `auth` hook runs on the upgrade request, which `anonymous: 'deny'` refuses with 401 when it gives no `userId`. A `run` or `resume` on a thread `authorizeThread` refuses answers `{ type: 'error', id, error }` without starting, and `deps` is called with the upgrade request.
240
275
 
241
276
  ```typescript
242
277
  await fastify.register(cogitatorPlugin, {
@@ -280,21 +315,23 @@ ws.send(JSON.stringify({ type: 'ping' }));
280
315
 
281
316
  ### WebSocket Message Types
282
317
 
283
- | Type | Direction | Description |
284
- | -------------- | ------------- | --------------------------------------------------------------------------------------------------------------- |
285
- | `ping` | Client→Server | Heartbeat |
286
- | `pong` | Server→Client | Heartbeat response |
287
- | `subscribe` | Client→Server | Subscribe to `agent:<name>`: receive events of the same user's runs on other connections |
288
- | `subscribed` | Server→Client | Subscription confirmed |
289
- | `unsubscribe` | Client→Server | Unsubscribe from channel |
290
- | `unsubscribed` | Server→Client | Unsubscription confirmed |
291
- | `run` | Client→Server | Run an agent (`payload: { type: 'agent', name, input, context?, threadId? }`); one run per connection at a time |
292
- | `resume` | Client→Server | Resume a run paused for tool approvals (`payload: { name, threadId, decisions?, defaultDecision? }`) |
293
- | `stop` | Client→Server | Abort the running agent |
294
- | `event` | Server→Client | Run event: `token`, `reasoning`, `tool-call`, `tool-result`, `complete`, `cancelled` |
295
- | `error` | Server→Client | `{ type: 'error', id?, error }`: invalid message, unknown agent, run already in progress, or a failed run |
296
-
297
- Only agent runs are supported over WebSocket; use the HTTP endpoints for workflows and swarms. A second `run` while one is active is refused with `A run is already in progress`; send `stop` first. A connection may subscribe to at most 64 channels. A failed run reports a `CogitatorError`'s message; any other error is logged and sent as `Internal server error`.
318
+ | Type | Direction | Description |
319
+ | -------------- | ------------- | ----------------------------------------------------------------------------------------------------------------------------- |
320
+ | `ping` | Client→Server | Heartbeat |
321
+ | `pong` | Server→Client | Heartbeat response |
322
+ | `subscribe` | Client→Server | Subscribe to `agent:<name>`: receive events of the same user's runs on other connections, on threads `authorizeThread` allows |
323
+ | `subscribed` | Server→Client | Subscription confirmed |
324
+ | `unsubscribe` | Client→Server | Unsubscribe from channel |
325
+ | `unsubscribed` | Server→Client | Unsubscription confirmed |
326
+ | `run` | Client→Server | Run an agent (`payload: { type: 'agent', name, input, context?, threadId? }`), one run per connection at a time |
327
+ | `resume` | Client→Server | Resume a run paused for tool approvals (`payload: { name, threadId, decisions?, defaultDecision? }`) |
328
+ | `stop` | Client→Server | Abort the running agent |
329
+ | `event` | Server→Client | Run event: `token`, `reasoning`, `tool-call`, `tool-result`, `complete`, `cancelled` |
330
+ | `error` | Server→Client | `{ type: 'error', id?, error }`: invalid message, unknown agent, run already in progress, or a failed run |
331
+
332
+ Only agent runs are supported over WebSocket, use the HTTP endpoints for workflows and swarms. A second `run` while one is active is refused with `A run is already in progress`, send `stop` first. A connection may subscribe to at most 64 channels. A failed run reports a `CogitatorError`'s message, any other error is logged and sent as `Internal server error`.
333
+
334
+ A subscriber gets the events of a run only when it has the `userId` of the caller who started it and, with `authorizeThread` set, when `authorizeThread(subscriberAuth, threadId)` allows it on the run's thread (the `threadId` of the run, or the one core created for it). The answer is asked once per subscriber and run, and a subscriber it refuses, or throws for, gets none of the run's events. Without `authorizeThread`, callers without a `userId` share the events of each other's runs, so set `authorizeThread` or `anonymous: 'deny'` when anonymous callers must not see each other.
298
335
 
299
336
  ## Custom Streaming
300
337
 
@@ -372,6 +409,10 @@ interface CogitatorPluginOptions {
372
409
  sseHeartbeatMs?: number; // Default: 5000, 0 turns SSE heartbeats off
373
410
  acceptContext?: boolean | string[]; // context keys clients may send: none by default, a list, or true for any
374
411
  threadMessageRoles?: ('user' | 'assistant' | 'system')[]; // roles of POST /threads/:id/messages, default user and assistant
412
+ limits?: RunLimits; // { swarmTimeout?, workflowMaxIterations?, workflowMaxConcurrency? }
413
+ anonymous?: 'allow' | 'deny'; // Default: 'allow'
414
+ authorizeThread?: (auth: AuthContext | undefined, threadId: string) => boolean | Promise<boolean>;
415
+ deps?: (request: FastifyRequest) => unknown | Promise<unknown>;
375
416
  }
376
417
  ```
377
418
 
@@ -411,6 +452,7 @@ fastify.cogitator.runtime; // Cogitator instance
411
452
  fastify.cogitator.agents; // Registered agents
412
453
  fastify.cogitator.workflows; // Registered workflows
413
454
  fastify.cogitator.swarms; // Registered swarms
455
+ fastify.cogitator.limits; // The checked run limits
414
456
 
415
457
  // Request decorators (in handlers)
416
458
  request.cogitatorAuth; // Auth context from auth hook
@@ -436,16 +478,17 @@ Error codes map to HTTP status codes:
436
478
  - `INVALID_INPUT` → 400 (schema validation and malformed JSON; `details` carries the validation errors)
437
479
  - `UNAUTHORIZED` → 401
438
480
  - `THREAD_ACCESS_DENIED` → 403 (another user's thread)
481
+ - `THREAD_FORBIDDEN` → 403 (`authorizeThread` refused the thread)
439
482
  - `NOT_FOUND` → 404
440
483
  - `RUN_NOT_PAUSED` → 409 (resume of a thread without a paused run)
441
484
  - `PAYLOAD_TOO_LARGE` → 413
442
485
  - `RATE_LIMIT_EXCEEDED` → 429
443
- - `WORKFLOW_FAILED` → 500
444
486
  - `INTERNAL_ERROR` → 500
445
487
  - `UNIMPLEMENTED` → 501 (optional workflows/swarms package missing)
446
488
  - `UNAVAILABLE` → 503 (no memory configured)
489
+ - `RUN_TIMEOUT` → 504 (a swarm ran out of time)
447
490
 
448
- A `CogitatorError` keeps its message and code and uses the code's mapped status (for example `LLM_RATE_LIMITED` → 429). Any other error is logged through the Fastify logger and answered as `500 Internal server error`, so internals never reach the client. The same masking applies to SSE `error` events, the `node_error`/`agent_error` stream events, `Workflow failed: …` messages and WebSocket run errors.
491
+ A `CogitatorError` keeps its message and code and answers with its own `statusCode`, which is the code's mapped status unless the error was given another (for example `LLM_RATE_LIMITED` → 429). When it says when to retry (`retryAfter`, as provider rate limits do), the answer carries `Retry-After` in whole seconds. The mapping is `describeHttpError` of `@cogitator-ai/server-shared`, so Express, Fastify, Hono, Koa and Next answer the same error the same way. Any other error is logged through the Fastify logger and answered as `500 Internal server error`, so internals never reach the client. The same mapping applies to a failed workflow, and the same masking to SSE `error` events, the `node_error`/`agent_error` stream events and WebSocket run errors.
449
492
 
450
493
  ## JSON Schema Validation
451
494
 
@@ -459,10 +502,14 @@ import {
459
502
  AddMessageRequestSchema,
460
503
  WorkflowRunRequestSchema,
461
504
  SwarmRunRequestSchema,
505
+ ThreadPageQuerySchema,
506
+ ThreadResponseSchema,
507
+ workflowRunRequestSchema,
508
+ swarmRunRequestSchema,
462
509
  } from '@cogitator-ai/fastify';
463
510
  ```
464
511
 
465
- `AgentResumeRequestSchema` requires a non-blank `threadId` and validates each decision as `{ approved: boolean, reason?: string }`. `AgentRunRequestSchema` and `SwarmRunRequestSchema` require a non-blank `input` (the swarm `timeout` must be greater than 0), `AddMessageRequestSchema` requires a non-blank `content` and a `user`/`assistant`/`system` role (the routes accept `system` only with `threadMessageRoles`), and `WorkflowRunRequestSchema.options` only allows `maxConcurrency`/`maxIterations` (integers ≥ 1) and `checkpoint: false` (`additionalProperties: false`). The routes validate bodies with the shared validators first, so the schemas describe what they accept.
512
+ `AgentResumeRequestSchema` requires a non-blank `threadId` and validates each decision as `{ approved: boolean, reason?: string }`. `AgentRunRequestSchema` and `SwarmRunRequestSchema` require a non-blank `input` (the swarm `timeout` must be greater than 0), `AddMessageRequestSchema` requires a non-blank `content` and a `user`/`assistant`/`system` role (the routes accept `system` only with `threadMessageRoles`), and `WorkflowRunRequestSchema.options` only allows `maxConcurrency`/`maxIterations` (integers ≥ 1) and `checkpoint: false` (`additionalProperties: false`). The routes validate bodies with the shared validators first, so the schemas describe what they accept. `workflowRunRequestSchema(limits)` and `swarmRunRequestSchema(limits)` build the same schemas with the operator's limits as defaults, as the routes use them. `ThreadPageQuerySchema` and `ThreadResponseSchema` describe `GET /threads/:id`.
466
513
 
467
514
  ## Documentation
468
515
 
@@ -1,4 +1,10 @@
1
1
  import type { onRequestHookHandler } from 'fastify';
2
+ import { type AnonymousPolicy } from '@cogitator-ai/server-shared';
2
3
  import type { AuthFunction } from '../types.js';
3
4
  export declare function createAuthHook(authFn?: AuthFunction): onRequestHookHandler;
5
+ /**
6
+ * Answers `401 UNAUTHORIZED` to a caller without a user id when `anonymous` is `'deny'`.
7
+ * Added to the API routes only, so health, ready and the docs stay open.
8
+ */
9
+ export declare function createAnonymousHook(anonymous: AnonymousPolicy | undefined): onRequestHookHandler;
4
10
  //# sourceMappingURL=auth.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/hooks/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgC,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAClF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGhD,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,oBAAoB,CAuB1E"}
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/hooks/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgC,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAClF,OAAO,EAAe,KAAK,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAChF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIhD,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,oBAAoB,CAkB1E;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,eAAe,GAAG,SAAS,GAAG,oBAAoB,CAKhG"}
@@ -1,4 +1,6 @@
1
+ import { admitCaller } from '@cogitator-ai/server-shared';
1
2
  import { generateId } from '../streaming/helpers.js';
3
+ import { sendError, sendFailure } from '../routes/utils.js';
2
4
  export function createAuthHook(authFn) {
3
5
  return async (request, reply) => {
4
6
  request.cogitatorRequestId = generateId('req');
@@ -14,13 +16,19 @@ export function createAuthHook(authFn) {
14
16
  request.log.warn({ err }, 'auth rejected request');
15
17
  if (reply.sent)
16
18
  return;
17
- return reply.status(401).send({
18
- error: {
19
- message: 'Unauthorized',
20
- code: 'UNAUTHORIZED',
21
- },
22
- });
19
+ return sendError(reply, 401, 'Unauthorized', 'UNAUTHORIZED');
23
20
  }
24
21
  };
25
22
  }
23
+ /**
24
+ * Answers `401 UNAUTHORIZED` to a caller without a user id when `anonymous` is `'deny'`.
25
+ * Added to the API routes only, so health, ready and the docs stay open.
26
+ */
27
+ export function createAnonymousHook(anonymous) {
28
+ return async (request, reply) => {
29
+ const refusal = admitCaller(request.cogitatorAuth?.userId, anonymous);
30
+ if (refusal && !reply.sent)
31
+ return sendFailure(reply, refusal);
32
+ };
33
+ }
26
34
  //# sourceMappingURL=auth.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/hooks/auth.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,MAAM,UAAU,cAAc,CAAC,MAAqB;IAClD,OAAO,KAAK,EAAE,OAAuB,EAAE,KAAmB,EAAE,EAAE;QAC5D,OAAO,CAAC,kBAAkB,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;QAC/C,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAExC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO;QACT,CAAC;QAED,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC;YACnC,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;QAC/B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,EAAE,uBAAuB,CAAC,CAAC;YACnD,IAAI,KAAK,CAAC,IAAI;gBAAE,OAAO;YACvB,OAAO,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBAC5B,KAAK,EAAE;oBACL,OAAO,EAAE,cAAc;oBACvB,IAAI,EAAE,cAAc;iBACrB;aACF,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/hooks/auth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAwB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handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAa1E,wBAAgB,YAAY,CAC1B,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,YAAY,GAClB,IAAI,CA8CN"}
1
+ {"version":3,"file":"error-handler.d.ts","sourceRoot":"","sources":["../../src/hooks/error-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAc1E,wBAAgB,YAAY,CAC1B,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,YAAY,GAClB,IAAI,CA+BN"}
@@ -1,4 +1,5 @@
1
- import { CogitatorError, ERROR_STATUS_CODES, ErrorCode } from '@cogitator-ai/types';
1
+ import { INTERNAL_ERROR, describeHttpError, errorEnvelope } from '@cogitator-ai/server-shared';
2
+ import { sendFailure } from '../routes/utils.js';
2
3
  const CLIENT_ERROR_CODES = {
3
4
  400: 'INVALID_INPUT',
4
5
  401: 'UNAUTHORIZED',
@@ -12,42 +13,28 @@ export function errorHandler(error, request, reply) {
12
13
  if (reply.sent) {
13
14
  return;
14
15
  }
15
- if (CogitatorError.isCogitatorError(error)) {
16
- const statusCode = ERROR_STATUS_CODES[error.code] || 500;
17
- reply.status(statusCode).send({
18
- error: {
19
- message: error.message,
20
- code: error.code,
21
- },
22
- });
16
+ const described = describeHttpError(error);
17
+ if (described) {
18
+ sendFailure(reply, described);
23
19
  return;
24
20
  }
25
21
  if (error.validation) {
22
+ const refusal = { status: 400, code: 'INVALID_INPUT', message: error.message };
26
23
  reply.status(400).send({
27
- error: {
28
- message: error.message,
29
- code: 'INVALID_INPUT',
30
- details: error.validation,
31
- },
24
+ error: { ...errorEnvelope(refusal).error, details: error.validation },
32
25
  });
33
26
  return;
34
27
  }
35
28
  const statusCode = error.statusCode;
36
29
  if (typeof statusCode === 'number' && statusCode >= 400 && statusCode < 500) {
37
- reply.status(statusCode).send({
38
- error: {
39
- message: error.message,
40
- code: CLIENT_ERROR_CODES[statusCode] ?? error.code ?? 'BAD_REQUEST',
41
- },
30
+ sendFailure(reply, {
31
+ status: statusCode,
32
+ code: CLIENT_ERROR_CODES[statusCode] ?? error.code ?? 'BAD_REQUEST',
33
+ message: error.message,
42
34
  });
43
35
  return;
44
36
  }
45
37
  request.log.error({ err: error }, 'unhandled error in cogitator plugin');
46
- reply.status(500).send({
47
- error: {
48
- message: 'Internal server error',
49
- code: ErrorCode.INTERNAL_ERROR,
50
- },
51
- });
38
+ sendFailure(reply, INTERNAL_ERROR);
52
39
  }
53
40
  //# sourceMappingURL=error-handler.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"error-handler.js","sourceRoot":"","sources":["../../src/hooks/error-handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEpF,MAAM,kBAAkB,GAA2B;IACjD,GAAG,EAAE,eAAe;IACpB,GAAG,EAAE,cAAc;IACnB,GAAG,EAAE,WAAW;IAChB,GAAG,EAAE,WAAW;IAChB,GAAG,EAAE,mBAAmB;IACxB,GAAG,EAAE,wBAAwB;IAC7B,GAAG,EAAE,qBAAqB;CAC3B,CAAC;AAEF,MAAM,UAAU,YAAY,CAC1B,KAAmB,EACnB,OAAuB,EACvB,KAAmB;IAEnB,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;QACf,OAAO;IACT,CAAC;IAED,IAAI,cAAc,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3C,MAAM,UAAU,GAAG,kBAAkB,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC;QACzD,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC;YAC5B,KAAK,EAAE;gBACL,OAAO,EAAE,K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,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,qCAAqC,CAAC,CAAC;IACzE,WAAW,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;AACrC,CAAC"}
@@ -1,3 +1,3 @@
1
- export { createAuthHook } from './auth.js';
1
+ export { createAnonymousHook, createAuthHook } from './auth.js';
2
2
  export { errorHandler } from './error-handler.js';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
@@ -1,3 +1,3 @@
1
- export { createAuthHook } from './auth.js';
1
+ export { createAnonymousHook, createAuthHook } from './auth.js';
2
2
  export { errorHandler } from './error-handler.js';
3
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { cogitatorPlugin } from './plugin.js';
2
- export type { CogitatorPluginOptions, CogitatorContext, AuthContext, AuthFunction, RateLimitConfig, SwaggerConfig, WebSocketConfig, AgentListResponse, AgentRunRequest, AgentRunResponse, AgentResumeRequest, PendingApproval, ThreadResponse, AddMessageRequest, ToolListResponse, WorkflowListResponse, WorkflowRunRequest, WorkflowRunResponse, WorkflowStatusResponse, SwarmListResponse, SwarmRunRequest, SwarmRunResponse, BlackboardResponse, HealthResponse, ReadinessResponse, ReadinessCheckStatus, ErrorResponse, WebSocketMessage, WebSocketResponse, OpenAPISpec, } from './types.js';
3
- export { AgentRunRequestSchema, AgentRunResponseSchema, AgentResumeRequestSchema, AddMessageRequestSchema, WorkflowRunRequestSchema, SwarmRunRequestSchema, } from './types.js';
2
+ export type { CogitatorPluginOptions, CogitatorContext, AuthContext, AuthFunction, RateLimitConfig, SwaggerConfig, WebSocketConfig, AgentListResponse, AgentRunRequest, AgentRunResponse, AgentResumeRequest, PendingApproval, ThreadResponse, ThreadPageQuery, AddMessageRequest, ToolListResponse, WorkflowListResponse, WorkflowRunRequest, WorkflowRunResponse, WorkflowStatusResponse, SwarmListResponse, SwarmRunRequest, SwarmRunResponse, BlackboardResponse, HealthResponse, ReadinessResponse, ReadinessCheckStatus, ErrorResponse, WebSocketMessage, WebSocketResponse, OpenAPISpec, } from './types.js';
3
+ export { AgentRunRequestSchema, AgentRunResponseSchema, AgentResumeRequestSchema, AddMessageRequestSchema, WorkflowRunRequestSchema, SwarmRunRequestSchema, ThreadPageQuerySchema, ThreadResponseSchema, workflowRunRequestSchema, swarmRunRequestSchema, } from './types.js';
4
4
  export { FastifyStreamWriter } from './streaming/index.js';
5
5
  export type { FastifyStreamWriterOptions } from './streaming/index.js';
6
6
  export type { StreamEvent, Usage } from './streaming/protocol.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,YAAY,EACV,sBAAsB,EACtB,gBAAgB,EAChB,WAAW,EACX,YAAY,EACZ,eAAe,EACf,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,sBAAsB,EACtB,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,EACd,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,GACZ,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,wBAAwB,EACxB,uBAAuB,EACvB,wBAAwB,EACxB,qBAAqB,GACtB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,YAAY,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAEvE,YAAY,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAElE,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,yBAAyB,EACzB,yBAAyB,EACzB,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,sBAAsB,EACtB,qBAAqB,EACrB,2BAA2B,EAC3B,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,YAAY,EACV,sBAAsB,EACtB,gBAAgB,EAChB,WAAW,EACX,YAAY,EACZ,eAAe,EACf,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,sBAAsB,EACtB,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,EACd,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,GACZ,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,wBAAwB,EACxB,uBAAuB,EACvB,wBAAwB,EACxB,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,wBAAwB,EACxB,qBAAqB,GACtB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,YAAY,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAEvE,YAAY,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAElE,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,yBAAyB,EACzB,yBAAyB,EACzB,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,sBAAsB,EACtB,qBAAqB,EACrB,2BAA2B,EAC3B,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC"}
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { cogitatorPlugin } from './plugin.js';
2
- export { AgentRunRequestSchema, AgentRunResponseSchema, AgentResumeRequestSchema, AddMessageRequestSchema, WorkflowRunRequestSchema, SwarmRunRequestSchema, } from './types.js';
2
+ export { AgentRunRequestSchema, AgentRunResponseSchema, AgentResumeRequestSchema, AddMessageRequestSchema, WorkflowRunRequestSchema, SwarmRunRequestSchema, ThreadPageQuerySchema, ThreadResponseSchema, workflowRunRequestSchema, swarmRunRequestSchema, } from './types.js';
3
3
  export { FastifyStreamWriter } from './streaming/index.js';
4
4
  export { createStartEvent, createTextStartEvent, createTextDeltaEvent, createTextEndEvent, createReasoningStartEvent, createReasoningDeltaEvent, createReasoningEndEvent, createToolCallStartEvent, createToolCallDeltaEvent, createToolCallEndEvent, createToolResultEvent, createApprovalRequiredEvent, createErrorEvent, createFinishEvent, createWorkflowEvent, createSwarmEvent, } from './streaming/protocol.js';
5
5
  export { generateId, encodeSSE, encodeDone } from './streaming/helpers.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAmC9C,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,wBAAwB,EACxB,uBAAuB,EACvB,wBAAwB,EACxB,qBAAqB,GACtB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAK3D,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,yBAAyB,EACzB,yBAAyB,EACzB,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,sBAAsB,EACtB,qBAAqB,EACrB,2BAA2B,EAC3B,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAoC9C,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,wBAAwB,EACxB,uBAAuB,EACvB,wBAAwB,EACxB,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,wBAAwB,EACxB,qBAAqB,GACtB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAK3D,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,yBAAyB,EACzB,yBAAyB,EACzB,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,sBAAsB,EACtB,qBAAqB,EACrB,2BAA2B,EAC3B,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,kBAAkB,EAAgB,MAAM,SAAS,CAAC;AAChE,OAAO,KAAK,EAAE,sBAAsB,EAAoB,MAAM,YAAY,CAAC;AA0I3E,eAAO,MAAM,eAAe,4CAG1B,CAAC"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,kBAAkB,EAAgB,MAAM,SAAS,CAAC;AAChE,OAAO,KAAK,EAAE,sBAAsB,EAAoB,MAAM,YAAY,CAAC;AAsJ3E,eAAO,MAAM,eAAe,4CAG1B,CAAC"}
package/dist/plugin.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import fp from 'fastify-plugin';
2
- import { DEFAULT_THREAD_MESSAGE_ROLES, refuseNonJsonBody, resolveSseHeartbeatMs, } from '@cogitator-ai/server-shared';
3
- import { createAuthHook, errorHandler } from './hooks/index.js';
2
+ import { DEFAULT_THREAD_MESSAGE_ROLES, admitCaller, checkRunLimits, refuseNonJsonBody, resolveSseHeartbeatMs, } from '@cogitator-ai/server-shared';
3
+ import { createAnonymousHook, createAuthHook, errorHandler } from './hooks/index.js';
4
4
  import { healthRoutes, agentRoutes, threadRoutes, toolRoutes, workflowRoutes, swarmRoutes, } from './routes/index.js';
5
- import { isModuleNotFound } from './routes/utils.js';
5
+ import { isModuleNotFound, sendError, sendFailure } from './routes/utils.js';
6
6
  const cogitatorPluginImpl = async (fastify, opts) => {
7
7
  const context = {
8
8
  runtime: opts.cogitator,
@@ -12,6 +12,9 @@ const cogitatorPluginImpl = async (fastify, opts) => {
12
12
  sseHeartbeatMs: resolveSseHeartbeatMs(opts.sseHeartbeatMs),
13
13
  acceptContext: opts.acceptContext ?? false,
14
14
  threadMessageRoles: opts.threadMessageRoles ?? DEFAULT_THREAD_MESSAGE_ROLES,
15
+ limits: checkRunLimits(opts.limits),
16
+ authorizeThread: opts.authorizeThread,
17
+ deps: opts.deps,
15
18
  };
16
19
  fastify.decorate('cogitator', context);
17
20
  fastify.decorateRequest('cogitatorAuth', undefined);
@@ -39,9 +42,7 @@ const cogitatorPluginImpl = async (fastify, opts) => {
39
42
  const refusal = refuseNonJsonBody(request.method, request.headers);
40
43
  if (!refusal)
41
44
  return;
42
- return reply
43
- .status(refusal.status)
44
- .send({ error: { message: refusal.message, code: refusal.code } });
45
+ return sendFailure(reply, refusal);
45
46
  });
46
47
  instance.addHook('onRequest', createAuthHook(opts.auth));
47
48
  if (opts.rateLimit) {
@@ -66,6 +67,12 @@ const cogitatorPluginImpl = async (fastify, opts) => {
66
67
  instance.setErrorHandler((error, request, reply) => {
67
68
  errorHandler(error, request, reply);
68
69
  });
70
+ instance.setNotFoundHandler((request, reply) => {
71
+ const refusal = admitCaller(request.cogitatorAuth?.userId, opts.anonymous);
72
+ return refusal
73
+ ? sendFailure(reply, refusal)
74
+ : sendError(reply, 404, 'Not found', 'NOT_FOUND');
75
+ });
69
76
  if (opts.enableSwagger) {
70
77
  try {
71
78
  const swaggerModule = await import('@fastify/swagger');
@@ -110,15 +117,18 @@ const cogitatorPluginImpl = async (fastify, opts) => {
110
117
  }
111
118
  }
112
119
  await instance.register(healthRoutes);
113
- await instance.register(agentRoutes);
114
- await instance.register(threadRoutes);
115
- await instance.register(toolRoutes);
116
- await instance.register(workflowRoutes);
117
- await instance.register(swarmRoutes);
118
- if (websocketEnabled) {
119
- const { websocketRoutes } = await import('./websocket/handler.js');
120
- await instance.register(websocketRoutes, { path: opts.websocket?.path });
121
- }
120
+ await instance.register(async (api) => {
121
+ api.addHook('onRequest', createAnonymousHook(opts.anonymous));
122
+ await api.register(agentRoutes);
123
+ await api.register(threadRoutes);
124
+ await api.register(toolRoutes);
125
+ await api.register(workflowRoutes);
126
+ await api.register(swarmRoutes);
127
+ if (websocketEnabled) {
128
+ const { websocketRoutes } = await import('./websocket/handler.js');
129
+ await api.register(websocketRoutes, { path: opts.websocket?.path });
130
+ }
131
+ });
122
132
  }, { prefix });
123
133
  };
124
134
  export const cogitatorPlugin = fp(cogitatorPluginImpl, {
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAChC,OAAO,EACL,4BAA4B,EAC5B,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,6BAA6B,CAAC;AAGrC,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EACL,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,UAAU,EACV,cAAc,EACd,WAAW,GACZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,MAAM,mBAAmB,GAA+C,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;I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,GAAG,MAAM,MAAM,CAAC,wBAAwB,CAAC,CAAC;gBACnE,MAAM,GAAG,CAAC,QAAQ,CAAC,eAAe,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YACtE,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,EACD,EAAE,MAAM,EAAE,CACX,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC,mBAAmB,EAAE;IACrD,OAAO,EAAE,KAAK;IACd,IAAI,EAAE,uBAAuB;CAC9B,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../../src/routes/agents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AA4BlD,eAAO,MAAM,WAAW,EAAE,kBA+HzB,CAAC"}
1
+ {"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../../src/routes/agents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AA8BlD,eAAO,MAAM,WAAW,EAAE,kBA2IzB,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { AgentResumeRequestSchema, AgentRunRequestSchema } from '../types.js';
2
2
  import { AgentStreamSession, parseResumeRequest, parseRunRequest, toAgentRunResponse, } from '@cogitator-ai/server-shared';
3
3
  import { FastifyStreamWriter } from '../streaming/index.js';
4
- import { onClientDisconnect, resolveError, sendError, sendRouteError, validateBody, } from './utils.js';
4
+ import { onClientDisconnect, refuseThread, requestDeps, resolveError, sendError, sendRouteError, validateBody, } from './utils.js';
5
5
  const paramsSchema = {
6
6
  type: 'object',
7
7
  properties: { name: { type: 'string' } },
@@ -26,6 +26,9 @@ export const agentRoutes = async (fastify) => {
26
26
  if (!agent) {
27
27
  return sendError(reply, 404, `Agent '${name}' not found`, 'NOT_FOUND');
28
28
  }
29
+ if (await refuseThread(request, reply, request.body.threadId))
30
+ return reply;
31
+ const deps = await requestDeps(request);
29
32
  const abortController = new AbortController();
30
33
  onClientDisconnect(reply, () => abortController.abort());
31
34
  try {
@@ -35,6 +38,7 @@ export const agentRoutes = async (fastify) => {
35
38
  threadId: request.body.threadId,
36
39
  userId: request.cogitatorAuth?.userId,
37
40
  signal: abortController.signal,
41
+ ...deps,
38
42
  });
39
43
  return toAgentRunResponse(result);
40
44
  }
@@ -48,6 +52,9 @@ export const agentRoutes = async (fastify) => {
48
52
  if (!agent) {
49
53
  return sendError(reply, 404, `Agent '${name}' not found`, 'NOT_FOUND');
50
54
  }
55
+ if (await refuseThread(request, reply, request.body.threadId))
56
+ return reply;
57
+ const deps = await requestDeps(request);
51
58
  const abortController = new AbortController();
52
59
  onClientDisconnect(reply, () => abortController.abort());
53
60
  try {
@@ -56,6 +63,7 @@ export const agentRoutes = async (fastify) => {
56
63
  decisions: request.body.decisions,
57
64
  defaultDecision: request.body.defaultDecision,
58
65
  signal: abortController.signal,
66
+ ...deps,
59
67
  });
60
68
  return toAgentRunResponse(result);
61
69
  }
@@ -69,6 +77,9 @@ export const agentRoutes = async (fastify) => {
69
77
  if (!agent) {
70
78
  return sendError(reply, 404, `Agent '${name}' not found`, 'NOT_FOUND');
71
79
  }
80
+ if (await refuseThread(request, reply, request.body.threadId))
81
+ return reply;
82
+ const deps = await requestDeps(request);
72
83
  const writer = new FastifyStreamWriter(reply, {
73
84
  heartbeatMs: fastify.cogitator.sseHeartbeatMs,
74
85
  });
@@ -90,6 +101,7 @@ export const agentRoutes = async (fastify) => {
90
101
  signal: abortController.signal,
91
102
  stream: true,
92
103
  ...session.callbacks,
104
+ ...deps,
93
105
  });
94
106
  session.complete(result);
95
107
  }
@@ -1 +1 @@
1
- {"version":3,"file":"agents.js","sourceRoot":"","sources":["../../src/routes/agents.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,aAA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H,OAAO,CAAC,KAAK,EAAE,CAAC;YAChB,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE;gBACxD,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK;gBACzB,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,OAAO;gBAC7B,QAAQ,EAAE,OAAO,CAAC,QAAQ;gBAC1B,MAAM,EAAE,OAAO,CAAC,aAAa,EAAE,MAAM;gBACrC,MAAM,EAAE,eAAe,CAAC,MAAM;gBAC9B,MAAM,EAAE,IAAI;gBACZ,GAAG,OAAO,CAAC,SAAS;gBACpB,GAAG,IAAI;aACR,CAAC,CAAC;YACH,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC3B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBACpC,MAAM,QAAQ,GAAG,YAAY,CAAC,OAAO,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC;gBACpE,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;YAChD,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CACF,CAAC;AACJ,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"swarms.d.ts","sourceRoot":"","sources":["../../src/routes/swarms.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAgClD,eAAO,MAAM,WAAW,EAAE,kBA0MzB,CAAC"}
1
+ {"version":3,"file":"swarms.d.ts","sourceRoot":"","sources":["../../src/routes/swarms.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAsClD,eAAO,MAAM,WAAW,EAAE,kBA+MzB,CAAC"}