@cogitator-ai/fastify 0.8.6 → 0.10.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 +77 -27
  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 +28 -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 +66 -34
  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 +7 -7
package/README.md CHANGED
@@ -49,10 +49,11 @@ console.log('Server running on http://localhost:3000');
49
49
  ### Agents
50
50
 
51
51
  ```
52
- GET /api/agents - List all agents
53
- POST /api/agents/:name/run - Run agent (JSON response)
54
- POST /api/agents/:name/stream - Run agent (SSE stream)
55
- POST /api/agents/:name/resume - Resume a run paused for tool approvals
52
+ GET /api/agents - List all agents
53
+ POST /api/agents/:name/run - Run agent (JSON response)
54
+ POST /api/agents/:name/stream - Run agent (SSE stream)
55
+ POST /api/agents/:name/resume - Resume a run paused for tool approvals
56
+ POST /api/agents/:name/resume/stream - Resume a paused run (SSE stream)
56
57
  ```
57
58
 
58
59
  Bodies are validated with JSON Schema (`input` must contain more than whitespace, the same rule the other adapters share from `@cogitator-ai/server-shared`); validation failures return `400 INVALID_INPUT` before the model is called. The `usage` of a run answer carries `inputTokens`, `outputTokens` and `totalTokens`, plus `reasoningTokens`, `cachedInputTokens` and `cacheWriteTokens` when the model reported them, the same shape as every other adapter. The `finish` event of an agent stream carries the same `usage` (never the run's cost or duration). The agent list exposes `config.description`, never the instructions. The authenticated `userId` is passed to the run, and runs are aborted when the client disconnects.
@@ -60,13 +61,25 @@ Bodies are validated with JSON Schema (`input` must contain more than whitespace
60
61
  ### Threads (Memory)
61
62
 
62
63
  ```
63
- GET /api/threads/:id - Get thread messages
64
+ GET /api/threads/:id - Get thread messages, a page at a time with ?limit&cursor
64
65
  POST /api/threads/:id/messages - Add message to thread
65
66
  DELETE /api/threads/:id - Delete thread
66
67
  ```
67
68
 
68
69
  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
70
 
71
+ `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.
72
+
73
+ ```typescript
74
+ let cursor: string | undefined;
75
+ do {
76
+ const query = new URLSearchParams({ limit: '50', ...(cursor && { cursor }) });
77
+ const page = await (await fetch(`/api/threads/${threadId}?${query}`)).json();
78
+ render(page.messages);
79
+ cursor = page.nextCursor;
80
+ } while (cursor);
81
+ ```
82
+
70
83
  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
84
 
72
85
  - 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 +96,7 @@ POST /api/workflows/:name/run - Run workflow
83
96
  POST /api/workflows/:name/stream - Stream workflow events
84
97
  ```
85
98
 
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`.
99
+ 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
100
 
88
101
  ### Swarms
89
102
 
@@ -94,7 +107,7 @@ POST /api/swarms/:name/stream - Stream swarm events
94
107
  GET /api/swarms/:name/blackboard - Get configured blackboard sections
95
108
  ```
96
109
 
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.
110
+ `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
111
 
99
112
  ### Tools & Docs
100
113
 
@@ -106,7 +119,7 @@ GET /api/docs - Swagger UI (enableSwagger)
106
119
  GET /api/docs/json - OpenAPI spec (enableSwagger)
107
120
  ```
108
121
 
109
- The OpenAPI document is generated by `@fastify/swagger` from the route schemas.
122
+ 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
123
 
111
124
  ## Configuration
112
125
 
@@ -146,6 +159,21 @@ await fastify.register(cogitatorPlugin, {
146
159
  websocket: {
147
160
  path: '/ws',
148
161
  },
162
+
163
+ // Caps on what a request may ask a run for. A larger value is held to the cap,
164
+ // a request without one gets the cap. Checked when the plugin is registered.
165
+ limits: { swarmTimeout: 120_000, workflowMaxIterations: 50, workflowMaxConcurrency: 4 },
166
+
167
+ // 'deny' answers 401 to callers without a userId. Health, ready and the docs stay open.
168
+ anonymous: 'deny',
169
+
170
+ // Called with the auth context and the thread of every request that names one.
171
+ // false answers 403 THREAD_FORBIDDEN and no run starts.
172
+ authorizeThread: (auth, threadId) => threadId.startsWith(`${auth?.userId}:`),
173
+
174
+ // Dependencies for the tools of agent runs, streams and resumes (context.deps).
175
+ // Built from the request on the server, never read from the body.
176
+ deps: async (request) => ({ db: await tenantDb(request.headers['x-tenant']) }),
149
177
  });
150
178
  ```
151
179
 
@@ -157,6 +185,14 @@ When `auth` returns a `userId`, everything a caller does with threads is scoped
157
185
  - `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
186
  - Another user's thread answers `403` with code `THREAD_ACCESS_DENIED`, and its messages are neither returned nor changed.
159
187
  - Threads created earlier without an owner (no `userId`) stay open only to callers without a `userId`, such as servers with no `auth` configured.
188
+ - `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.
189
+ - `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.
190
+
191
+ ### Limits and deps
192
+
193
+ `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.
194
+
195
+ `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
196
 
161
197
  ### Approvals
162
198
 
@@ -180,6 +216,8 @@ await fetch('/api/agents/support/resume', {
180
216
 
181
217
  The body is `{ threadId, decisions?, defaultDecision? }`, where a decision is `{ approved: boolean, reason?: string }`; malformed bodies get `400 INVALID_INPUT`. The response has the same shape as `/run` and may pause again for calls left without a decision. The run resumes as the authenticated `userId`: a thread with no paused run answers `409 RUN_NOT_PAUSED`, and another user's paused run `403 THREAD_ACCESS_DENIED`. Over WebSocket, send `{ type: 'resume', id, payload: { name, threadId, decisions?, defaultDecision? } }`; a paused run's `complete` event carries `status` and `pendingApprovals`.
182
218
 
219
+ `POST /agents/:name/resume/stream` takes the same body and streams the rest of the run like `/stream`. `start` and `finish` name the resumed thread, and a body, agent or thread refused before the stream opens is answered as JSON, just like `/resume`. A thread with no paused run ends the open stream with an `error` event, `code: 'RUN_NOT_PAUSED'`, and disconnecting aborts the resume.
220
+
183
221
  ## SSE Streaming
184
222
 
185
223
  The `/agents/:name/stream` endpoint returns Server-Sent Events:
@@ -236,7 +274,7 @@ Text is emitted in `text-start`/`text-delta`/`text-end` blocks that are closed a
236
274
 
237
275
  ## WebSocket Support
238
276
 
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.
277
+ 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
278
 
241
279
  ```typescript
242
280
  await fastify.register(cogitatorPlugin, {
@@ -280,21 +318,23 @@ ws.send(JSON.stringify({ type: 'ping' }));
280
318
 
281
319
  ### WebSocket Message Types
282
320
 
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`.
321
+ | Type | Direction | Description |
322
+ | -------------- | ------------- | ----------------------------------------------------------------------------------------------------------------------------- |
323
+ | `ping` | Client→Server | Heartbeat |
324
+ | `pong` | Server→Client | Heartbeat response |
325
+ | `subscribe` | Client→Server | Subscribe to `agent:<name>`: receive events of the same user's runs on other connections, on threads `authorizeThread` allows |
326
+ | `subscribed` | Server→Client | Subscription confirmed |
327
+ | `unsubscribe` | Client→Server | Unsubscribe from channel |
328
+ | `unsubscribed` | Server→Client | Unsubscription confirmed |
329
+ | `run` | Client→Server | Run an agent (`payload: { type: 'agent', name, input, context?, threadId? }`), one run per connection at a time |
330
+ | `resume` | Client→Server | Resume a run paused for tool approvals (`payload: { name, threadId, decisions?, defaultDecision? }`) |
331
+ | `stop` | Client→Server | Abort the running agent |
332
+ | `event` | Server→Client | Run event: `token`, `reasoning`, `tool-call`, `tool-result`, `complete`, `cancelled` |
333
+ | `error` | Server→Client | `{ type: 'error', id?, error }`: invalid message, unknown agent, run already in progress, or a failed run |
334
+
335
+ 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`.
336
+
337
+ 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
338
 
299
339
  ## Custom Streaming
300
340
 
@@ -372,6 +412,10 @@ interface CogitatorPluginOptions {
372
412
  sseHeartbeatMs?: number; // Default: 5000, 0 turns SSE heartbeats off
373
413
  acceptContext?: boolean | string[]; // context keys clients may send: none by default, a list, or true for any
374
414
  threadMessageRoles?: ('user' | 'assistant' | 'system')[]; // roles of POST /threads/:id/messages, default user and assistant
415
+ limits?: RunLimits; // { swarmTimeout?, workflowMaxIterations?, workflowMaxConcurrency? }
416
+ anonymous?: 'allow' | 'deny'; // Default: 'allow'
417
+ authorizeThread?: (auth: AuthContext | undefined, threadId: string) => boolean | Promise<boolean>;
418
+ deps?: (request: FastifyRequest) => unknown | Promise<unknown>;
375
419
  }
376
420
  ```
377
421
 
@@ -411,6 +455,7 @@ fastify.cogitator.runtime; // Cogitator instance
411
455
  fastify.cogitator.agents; // Registered agents
412
456
  fastify.cogitator.workflows; // Registered workflows
413
457
  fastify.cogitator.swarms; // Registered swarms
458
+ fastify.cogitator.limits; // The checked run limits
414
459
 
415
460
  // Request decorators (in handlers)
416
461
  request.cogitatorAuth; // Auth context from auth hook
@@ -436,16 +481,17 @@ Error codes map to HTTP status codes:
436
481
  - `INVALID_INPUT` → 400 (schema validation and malformed JSON; `details` carries the validation errors)
437
482
  - `UNAUTHORIZED` → 401
438
483
  - `THREAD_ACCESS_DENIED` → 403 (another user's thread)
484
+ - `THREAD_FORBIDDEN` → 403 (`authorizeThread` refused the thread)
439
485
  - `NOT_FOUND` → 404
440
486
  - `RUN_NOT_PAUSED` → 409 (resume of a thread without a paused run)
441
487
  - `PAYLOAD_TOO_LARGE` → 413
442
488
  - `RATE_LIMIT_EXCEEDED` → 429
443
- - `WORKFLOW_FAILED` → 500
444
489
  - `INTERNAL_ERROR` → 500
445
490
  - `UNIMPLEMENTED` → 501 (optional workflows/swarms package missing)
446
491
  - `UNAVAILABLE` → 503 (no memory configured)
492
+ - `RUN_TIMEOUT` → 504 (a swarm ran out of time)
447
493
 
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.
494
+ 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
495
 
450
496
  ## JSON Schema Validation
451
497
 
@@ -459,10 +505,14 @@ import {
459
505
  AddMessageRequestSchema,
460
506
  WorkflowRunRequestSchema,
461
507
  SwarmRunRequestSchema,
508
+ ThreadPageQuerySchema,
509
+ ThreadResponseSchema,
510
+ workflowRunRequestSchema,
511
+ swarmRunRequestSchema,
462
512
  } from '@cogitator-ai/fastify';
463
513
  ```
464
514
 
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.
515
+ `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
516
 
467
517
  ## Documentation
468
518
 
@@ -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/hoo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- {"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;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,CAA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AC,OAAO;SACvB,CAAC,CAAC;QACH,OAAO;IACT,CAAC;IAED,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":"AASA,OAAO,KAAK,EAAE,kBAAkB,EAAgB,MAAM,SAAS,CAAC;AAChE,OAAO,KAAK,EAAE,sBAAsB,EAAoB,MAAM,YAAY,CAAC;AA0J3E,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, documentStreamEvents, 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');
@@ -95,6 +102,9 @@ const cogitatorPluginImpl = async (fastify, opts) => {
95
102
  { name: 'health', description: 'Health check endpoints' },
96
103
  ],
97
104
  },
105
+ transformObject: (documentObject) => 'openapiObject' in documentObject
106
+ ? documentStreamEvents(documentObject.openapiObject)
107
+ : documentObject.swaggerObject,
98
108
  });
99
109
  await instance.register(swaggerUiModule.default, {
100
110
  routePrefix: '/docs',
@@ -110,15 +120,18 @@ const cogitatorPluginImpl = async (fastify, opts) => {
110
120
  }
111
121
  }
112
122
  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
- }
123
+ await instance.register(async (api) => {
124
+ api.addHook('onRequest', createAnonymousHook(opts.anonymous));
125
+ await api.register(agentRoutes);
126
+ await api.register(threadRoutes);
127
+ await api.register(toolRoutes);
128
+ await api.register(workflowRoutes);
129
+ await api.register(swarmRoutes);
130
+ if (websocketEnabled) {
131
+ const { websocketRoutes } = await import('./websocket/handler.js');
132
+ await api.register(websocketRoutes, { path: opts.websocket?.path });
133
+ }
134
+ });
122
135
  }, { prefix });
123
136
  };
124
137
  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,6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,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;YACpC,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,mBAAmB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;YAE9D,MAAM,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;YAChC,MAAM,GAAG,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;YACjC,MAAM,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;YAC/B,MAAM,GAAG,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;YACnC,MAAM,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;YAEhC,IAAI,gBAAgB,EAAE,CAAC;gBACrB,MAAM,EAAE,eAAe,EAAE,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,EAAgC,MAAM,SAAS,CAAC;AA+BhF,eAAO,MAAM,WAAW,EAAE,kBAsLzB,CAAC"}