@cogitator-ai/koa 0.1.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 (79) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +112 -0
  3. package/dist/app.d.ts +4 -0
  4. package/dist/app.d.ts.map +1 -0
  5. package/dist/app.js +29 -0
  6. package/dist/app.js.map +1 -0
  7. package/dist/index.d.ts +9 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +7 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/middleware/auth.d.ts +4 -0
  12. package/dist/middleware/auth.d.ts.map +1 -0
  13. package/dist/middleware/auth.js +19 -0
  14. package/dist/middleware/auth.js.map +1 -0
  15. package/dist/middleware/body-parser.d.ts +3 -0
  16. package/dist/middleware/body-parser.d.ts.map +1 -0
  17. package/dist/middleware/body-parser.js +21 -0
  18. package/dist/middleware/body-parser.js.map +1 -0
  19. package/dist/middleware/context.d.ts +4 -0
  20. package/dist/middleware/context.d.ts.map +1 -0
  21. package/dist/middleware/context.js +17 -0
  22. package/dist/middleware/context.js.map +1 -0
  23. package/dist/middleware/error-handler.d.ts +3 -0
  24. package/dist/middleware/error-handler.d.ts.map +1 -0
  25. package/dist/middleware/error-handler.js +29 -0
  26. package/dist/middleware/error-handler.js.map +1 -0
  27. package/dist/middleware/index.d.ts +5 -0
  28. package/dist/middleware/index.d.ts.map +1 -0
  29. package/dist/middleware/index.js +5 -0
  30. package/dist/middleware/index.js.map +1 -0
  31. package/dist/routes/agents.d.ts +4 -0
  32. package/dist/routes/agents.d.ts.map +1 -0
  33. package/dist/routes/agents.js +115 -0
  34. package/dist/routes/agents.js.map +1 -0
  35. package/dist/routes/health.d.ts +4 -0
  36. package/dist/routes/health.d.ts.map +1 -0
  37. package/dist/routes/health.js +18 -0
  38. package/dist/routes/health.js.map +1 -0
  39. package/dist/routes/index.d.ts +7 -0
  40. package/dist/routes/index.d.ts.map +1 -0
  41. package/dist/routes/index.js +7 -0
  42. package/dist/routes/index.js.map +1 -0
  43. package/dist/routes/swarms.d.ts +4 -0
  44. package/dist/routes/swarms.d.ts.map +1 -0
  45. package/dist/routes/swarms.js +176 -0
  46. package/dist/routes/swarms.js.map +1 -0
  47. package/dist/routes/threads.d.ts +4 -0
  48. package/dist/routes/threads.d.ts.map +1 -0
  49. package/dist/routes/threads.js +96 -0
  50. package/dist/routes/threads.js.map +1 -0
  51. package/dist/routes/tools.d.ts +4 -0
  52. package/dist/routes/tools.d.ts.map +1 -0
  53. package/dist/routes/tools.js +30 -0
  54. package/dist/routes/tools.js.map +1 -0
  55. package/dist/routes/workflows.d.ts +4 -0
  56. package/dist/routes/workflows.d.ts.map +1 -0
  57. package/dist/routes/workflows.js +110 -0
  58. package/dist/routes/workflows.js.map +1 -0
  59. package/dist/streaming/index.d.ts +3 -0
  60. package/dist/streaming/index.d.ts.map +1 -0
  61. package/dist/streaming/index.js +3 -0
  62. package/dist/streaming/index.js.map +1 -0
  63. package/dist/streaming/koa-stream-writer.d.ts +24 -0
  64. package/dist/streaming/koa-stream-writer.d.ts.map +1 -0
  65. package/dist/streaming/koa-stream-writer.js +74 -0
  66. package/dist/streaming/koa-stream-writer.js.map +1 -0
  67. package/dist/types.d.ts +164 -0
  68. package/dist/types.d.ts.map +1 -0
  69. package/dist/types.js +2 -0
  70. package/dist/types.js.map +1 -0
  71. package/dist/websocket/handler.d.ts +6 -0
  72. package/dist/websocket/handler.d.ts.map +1 -0
  73. package/dist/websocket/handler.js +161 -0
  74. package/dist/websocket/handler.js.map +1 -0
  75. package/dist/websocket/index.d.ts +2 -0
  76. package/dist/websocket/index.d.ts.map +1 -0
  77. package/dist/websocket/index.js +2 -0
  78. package/dist/websocket/index.js.map +1 -0
  79. package/package.json +67 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Cogitator Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,112 @@
1
+ # @cogitator-ai/koa
2
+
3
+ Koa server adapter for [Cogitator AI](https://github.com/cogitator-ai/Cogitator-AI) runtime. Exposes agents, workflows, swarms, and threads as a REST API with SSE streaming.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @cogitator-ai/koa koa @koa/router
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import Koa from 'koa';
15
+ import { cogitatorApp } from '@cogitator-ai/koa';
16
+ import { Cogitator, Agent } from '@cogitator-ai/core';
17
+
18
+ const cogitator = new Cogitator({ backend: 'openai' });
19
+ const chatAgent = new Agent({ name: 'chat', instructions: 'You are helpful.' });
20
+
21
+ const app = new Koa();
22
+ const router = cogitatorApp({
23
+ cogitator,
24
+ agents: { chat: chatAgent },
25
+ });
26
+
27
+ app.use(router.routes());
28
+ app.use(router.allowedMethods());
29
+
30
+ app.listen(3000);
31
+ ```
32
+
33
+ ## API Endpoints
34
+
35
+ | Method | Path | Description |
36
+ | -------- | -------------------------- | ---------------------------- |
37
+ | `GET` | `/health` | Health check |
38
+ | `GET` | `/ready` | Readiness check |
39
+ | `GET` | `/agents` | List all agents |
40
+ | `POST` | `/agents/:name/run` | Run an agent |
41
+ | `POST` | `/agents/:name/stream` | Stream agent response (SSE) |
42
+ | `GET` | `/threads/:id` | Get thread messages |
43
+ | `POST` | `/threads/:id/messages` | Add message to thread |
44
+ | `DELETE` | `/threads/:id` | Delete thread |
45
+ | `GET` | `/tools` | List all tools |
46
+ | `GET` | `/workflows` | List workflows |
47
+ | `POST` | `/workflows/:name/run` | Execute workflow |
48
+ | `POST` | `/workflows/:name/stream` | Stream workflow events (SSE) |
49
+ | `GET` | `/swarms` | List swarms |
50
+ | `POST` | `/swarms/:name/run` | Run swarm |
51
+ | `POST` | `/swarms/:name/stream` | Stream swarm events (SSE) |
52
+ | `GET` | `/swarms/:name/blackboard` | Get swarm blackboard |
53
+
54
+ ## Authentication
55
+
56
+ ```typescript
57
+ const router = cogitatorApp({
58
+ cogitator,
59
+ agents: { chat: chatAgent },
60
+ auth: async (ctx) => {
61
+ const token = ctx.get('authorization')?.replace('Bearer ', '');
62
+ if (!token) throw new Error('No token');
63
+ const user = await validateToken(token);
64
+ return { userId: user.id, roles: user.roles };
65
+ },
66
+ });
67
+ ```
68
+
69
+ ## With Prefix
70
+
71
+ ```typescript
72
+ import Koa from 'koa';
73
+ import Router from '@koa/router';
74
+ import { cogitatorApp } from '@cogitator-ai/koa';
75
+
76
+ const app = new Koa();
77
+ const main = new Router();
78
+ const cogitator = cogitatorApp({ cogitator, agents });
79
+
80
+ main.use('/api/v1', cogitator.routes(), cogitator.allowedMethods());
81
+ app.use(main.routes());
82
+ ```
83
+
84
+ ## WebSocket
85
+
86
+ ```typescript
87
+ import { createServer } from 'http';
88
+ import { cogitatorApp, setupWebSocket } from '@cogitator-ai/koa';
89
+
90
+ const app = new Koa();
91
+ const router = cogitatorApp({ cogitator, agents, enableWebSocket: true });
92
+ app.use(router.routes());
93
+
94
+ const server = createServer(app.callback());
95
+ await setupWebSocket(server, { cogitator, agents, workflows: {}, swarms: {} });
96
+
97
+ server.listen(3000);
98
+ ```
99
+
100
+ ## Features
101
+
102
+ - Full REST API for agents, workflows, swarms, and threads
103
+ - Server-Sent Events (SSE) streaming
104
+ - Authentication middleware
105
+ - Built-in JSON body parser
106
+ - Error handling with Cogitator error codes
107
+ - WebSocket support via `ws`
108
+ - TypeScript-first with full type safety
109
+
110
+ ## License
111
+
112
+ MIT
package/dist/app.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import Router from '@koa/router';
2
+ import type { CogitatorAppOptions, CogitatorState } from './types.js';
3
+ export declare function cogitatorApp(opts: CogitatorAppOptions): Router<CogitatorState>;
4
+ //# sourceMappingURL=app.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,KAAK,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAWtE,wBAAgB,YAAY,CAAC,IAAI,EAAE,mBAAmB,GAAG,MAAM,CAAC,cAAc,CAAC,CA8B9E"}
package/dist/app.js ADDED
@@ -0,0 +1,29 @@
1
+ import Router from '@koa/router';
2
+ import { createContextMiddleware, createAuthMiddleware, createBodyParser, createErrorHandler } from './middleware/index.js';
3
+ import { createHealthRoutes, createAgentRoutes, createThreadRoutes, createToolRoutes, createWorkflowRoutes, createSwarmRoutes, } from './routes/index.js';
4
+ export function cogitatorApp(opts) {
5
+ const router = new Router();
6
+ router.use(createErrorHandler());
7
+ router.use(createBodyParser());
8
+ router.use(createContextMiddleware(opts));
9
+ if (opts.auth) {
10
+ router.use(createAuthMiddleware(opts.auth));
11
+ }
12
+ const subrouters = [
13
+ createHealthRoutes(),
14
+ createAgentRoutes(),
15
+ createThreadRoutes(),
16
+ createToolRoutes(),
17
+ createWorkflowRoutes(),
18
+ createSwarmRoutes(),
19
+ ];
20
+ for (const sub of subrouters) {
21
+ router.use(sub.routes());
22
+ router.use(sub.allowedMethods());
23
+ }
24
+ if (opts.enableWebSocket) {
25
+ console.log('[CogitatorKoa] WebSocket support enabled — call setupWebSocket() with your HTTP server');
26
+ }
27
+ return router;
28
+ }
29
+ //# sourceMappingURL=app.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC5H,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,UAAU,YAAY,CAAC,IAAyB;IACpD,MAAM,MAAM,GAAG,IAAI,MAAM,EAAkB,CAAC;IAE5C,MAAM,CAAC,GAAG,CAAC,kBAAkB,EAAE,CAAC,CAAC;IACjC,MAAM,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC,CAAC;IAC/B,MAAM,CAAC,GAAG,CAAC,uBAAuB,CAAC,IAAI,CAAC,CAAC,CAAC;IAE1C,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;QACd,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9C,CAAC;IAED,MAAM,UAAU,GAAG;QACjB,kBAAkB,EAAE;QACpB,iBAAiB,EAAE;QACnB,kBAAkB,EAAE;QACpB,gBAAgB,EAAE;QAClB,oBAAoB,EAAE;QACtB,iBAAiB,EAAE;KACpB,CAAC;IAEF,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;QAC7B,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;QACzB,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC,CAAC;IACnC,CAAC;IAED,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;QACzB,OAAO,CAAC,GAAG,CAAC,wFAAwF,CAAC,CAAC;IACxG,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,9 @@
1
+ export { cogitatorApp } from './app.js';
2
+ export type { AuthContext, AuthFunction, CogitatorAppOptions, CogitatorState, RouteContext, WebSocketConfig, AgentListResponse, AgentRunRequest, AgentRunResponse, ThreadResponse, AddMessageRequest, ToolListResponse, WorkflowListResponse, WorkflowRunRequest, WorkflowRunResponse, SwarmListResponse, SwarmRunRequest, SwarmRunResponse, BlackboardResponse, HealthResponse, ErrorResponse, WebSocketMessage, WebSocketResponse, } from './types.js';
3
+ export { createContextMiddleware, createAuthMiddleware, createBodyParser, createErrorHandler, } from './middleware/index.js';
4
+ export { createHealthRoutes, createAgentRoutes, createThreadRoutes, createToolRoutes, createWorkflowRoutes, createSwarmRoutes, } from './routes/index.js';
5
+ export { KoaStreamWriter, setupSSEHeaders } from './streaming/koa-stream-writer.js';
6
+ export { generateId, encodeSSE, encodeDone } from '@cogitator-ai/server-shared';
7
+ export type { StreamEvent, StartEvent, TextStartEvent, TextDeltaEvent, TextEndEvent, ToolCallStartEvent, ToolCallDeltaEvent, ToolCallEndEvent, ToolResultEvent, ErrorEvent, FinishEvent, Usage, } from '@cogitator-ai/server-shared';
8
+ export { setupWebSocket } from './websocket/index.js';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,YAAY,EACV,WAAW,EACX,YAAY,EACZ,mBAAmB,EACnB,cAAc,EACd,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAEpF,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAEhF,YAAY,EACV,WAAW,EACX,UAAU,EACV,cAAc,EACd,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,WAAW,EACX,KAAK,GACN,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ export { cogitatorApp } from './app.js';
2
+ export { createContextMiddleware, createAuthMiddleware, createBodyParser, createErrorHandler, } from './middleware/index.js';
3
+ export { createHealthRoutes, createAgentRoutes, createThreadRoutes, createToolRoutes, createWorkflowRoutes, createSwarmRoutes, } from './routes/index.js';
4
+ export { KoaStreamWriter, setupSSEHeaders } from './streaming/koa-stream-writer.js';
5
+ export { generateId, encodeSSE, encodeDone } from '@cogitator-ai/server-shared';
6
+ export { setupWebSocket } from './websocket/index.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AA4BxC,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAEpF,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAiBhF,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { Context, Next } from 'koa';
2
+ import type { AuthFunction } from '../types.js';
3
+ export declare function createAuthMiddleware(authFn: AuthFunction): (ctx: Context, next: Next) => Promise<void>;
4
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/middleware/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AACzC,OAAO,KAAK,EAAE,YAAY,EAAkB,MAAM,aAAa,CAAC;AAEhE,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,YAAY,IACzC,KAAK,OAAO,EAAE,MAAM,IAAI,mBAevC"}
@@ -0,0 +1,19 @@
1
+ export function createAuthMiddleware(authFn) {
2
+ return async (ctx, next) => {
3
+ try {
4
+ const auth = await authFn(ctx);
5
+ ctx.state.auth = auth;
6
+ await next();
7
+ }
8
+ catch {
9
+ ctx.status = 401;
10
+ ctx.body = {
11
+ error: {
12
+ message: 'Unauthorized',
13
+ code: 'UNAUTHORIZED',
14
+ },
15
+ };
16
+ }
17
+ };
18
+ }
19
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/middleware/auth.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,oBAAoB,CAAC,MAAoB;IACvD,OAAO,KAAK,EAAE,GAAY,EAAE,IAAU,EAAE,EAAE;QACxC,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,CAAC;YAC9B,GAAG,CAAC,KAAwB,CAAC,IAAI,GAAG,IAAI,CAAC;YAC1C,MAAM,IAAI,EAAE,CAAC;QACf,CAAC;QAAC,MAAM,CAAC;YACP,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC;YACjB,GAAG,CAAC,IAAI,GAAG;gBACT,KAAK,EAAE;oBACL,OAAO,EAAE,cAAc;oBACvB,IAAI,EAAE,cAAc;iBACrB;aACF,CAAC;QACJ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Context, Next } from 'koa';
2
+ export declare function createBodyParser(): (ctx: Context, next: Next) => Promise<void>;
3
+ //# sourceMappingURL=body-parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"body-parser.d.ts","sourceRoot":"","sources":["../../src/middleware/body-parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAEzC,wBAAgB,gBAAgB,KAChB,KAAK,OAAO,EAAE,MAAM,IAAI,mBAYvC"}
@@ -0,0 +1,21 @@
1
+ export function createBodyParser() {
2
+ return async (ctx, next) => {
3
+ if (ctx.method === 'POST' &&
4
+ ctx.is('application/json')) {
5
+ const body = await readBody(ctx);
6
+ if (body) {
7
+ ctx.request.body = JSON.parse(body);
8
+ }
9
+ }
10
+ await next();
11
+ };
12
+ }
13
+ function readBody(ctx) {
14
+ return new Promise((resolve, reject) => {
15
+ const chunks = [];
16
+ ctx.req.on('data', (chunk) => chunks.push(chunk));
17
+ ctx.req.on('end', () => resolve(Buffer.concat(chunks).toString()));
18
+ ctx.req.on('error', reject);
19
+ });
20
+ }
21
+ //# sourceMappingURL=body-parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"body-parser.js","sourceRoot":"","sources":["../../src/middleware/body-parser.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,gBAAgB;IAC9B,OAAO,KAAK,EAAE,GAAY,EAAE,IAAU,EAAE,EAAE;QACxC,IACE,GAAG,CAAC,MAAM,KAAK,MAAM;YACrB,GAAG,CAAC,EAAE,CAAC,kBAAkB,CAAC,EAC1B,CAAC;YACD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,CAAC;YACjC,IAAI,IAAI,EAAE,CAAC;gBACR,GAAG,CAAC,OAAwC,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACxE,CAAC;QACH,CAAC;QACD,MAAM,IAAI,EAAE,CAAC;IACf,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CAAC,GAAY;IAC5B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,MAAM,GAAa,EAAE,CAAC;QAC5B,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAC1D,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;QACnE,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { Context, Next } from 'koa';
2
+ import type { CogitatorAppOptions } from '../types.js';
3
+ export declare function createContextMiddleware(opts: CogitatorAppOptions): (ctx: Context, next: Next) => Promise<void>;
4
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/middleware/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AACzC,OAAO,KAAK,EAAE,mBAAmB,EAAgC,MAAM,aAAa,CAAC;AAGrF,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,mBAAmB,IAQjD,KAAK,OAAO,EAAE,MAAM,IAAI,mBAOvC"}
@@ -0,0 +1,17 @@
1
+ import { generateId } from '@cogitator-ai/server-shared';
2
+ export function createContextMiddleware(opts) {
3
+ const routeCtx = {
4
+ cogitator: opts.cogitator,
5
+ agents: opts.agents || {},
6
+ workflows: opts.workflows || {},
7
+ swarms: opts.swarms || {},
8
+ };
9
+ return async (ctx, next) => {
10
+ const state = ctx.state;
11
+ state.cogitator = routeCtx;
12
+ state.requestId = generateId('req');
13
+ state.startTime = Date.now();
14
+ await next();
15
+ };
16
+ }
17
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/middleware/context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAEzD,MAAM,UAAU,uBAAuB,CAAC,IAAyB;IAC/D,MAAM,QAAQ,GAAiB;QAC7B,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,EAAE;QACzB,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,EAAE;QAC/B,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,EAAE;KAC1B,CAAC;IAEF,OAAO,KAAK,EAAE,GAAY,EAAE,IAAU,EAAE,EAAE;QACxC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAuB,CAAC;QAC1C,KAAK,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC3B,KAAK,CAAC,SAAS,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;QACpC,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC7B,MAAM,IAAI,EAAE,CAAC;IACf,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Context, Next } from 'koa';
2
+ export declare function createErrorHandler(): (ctx: Context, next: Next) => Promise<void>;
3
+ //# sourceMappingURL=error-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-handler.d.ts","sourceRoot":"","sources":["../../src/middleware/error-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAGzC,wBAAgB,kBAAkB,KAClB,KAAK,OAAO,EAAE,MAAM,IAAI,mBA0BvC"}
@@ -0,0 +1,29 @@
1
+ import { CogitatorError, ERROR_STATUS_CODES, ErrorCode } from '@cogitator-ai/types';
2
+ export function createErrorHandler() {
3
+ return async (ctx, next) => {
4
+ try {
5
+ await next();
6
+ }
7
+ catch (err) {
8
+ if (CogitatorError.isCogitatorError(err)) {
9
+ ctx.status = ERROR_STATUS_CODES[err.code] || 500;
10
+ ctx.body = {
11
+ error: {
12
+ message: err.message,
13
+ code: err.code,
14
+ },
15
+ };
16
+ return;
17
+ }
18
+ console.error('[CogitatorKoa] Unhandled error:', err);
19
+ ctx.status = 500;
20
+ ctx.body = {
21
+ error: {
22
+ message: 'Internal server error',
23
+ code: ErrorCode.INTERNAL_ERROR,
24
+ },
25
+ };
26
+ }
27
+ };
28
+ }
29
+ //# sourceMappingURL=error-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-handler.js","sourceRoot":"","sources":["../../src/middleware/error-handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEpF,MAAM,UAAU,kBAAkB;IAChC,OAAO,KAAK,EAAE,GAAY,EAAE,IAAU,EAAE,EAAE;QACxC,IAAI,CAAC;YACH,MAAM,IAAI,EAAE,CAAC;QACf,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,cAAc,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE,CAAC;gBACzC,GAAG,CAAC,MAAM,GAAG,kBAAkB,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC;gBACjD,GAAG,CAAC,IAAI,GAAG;oBACT,KAAK,EAAE;wBACL,OAAO,EAAE,GAAG,CAAC,OAAO;wBACpB,IAAI,EAAE,GAAG,CAAC,IAAI;qBACf;iBACF,CAAC;gBACF,OAAO;YACT,CAAC;YAED,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,GAAG,CAAC,CAAC;YAEtD,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC;YACjB,GAAG,CAAC,IAAI,GAAG;gBACT,KAAK,EAAE;oBACL,OAAO,EAAE,uBAAuB;oBAChC,IAAI,EAAE,SAAS,CAAC,cAAc;iBAC/B;aACF,CAAC;QACJ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { createContextMiddleware } from './context.js';
2
+ export { createAuthMiddleware } from './auth.js';
3
+ export { createBodyParser } from './body-parser.js';
4
+ export { createErrorHandler } from './error-handler.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { createContextMiddleware } from './context.js';
2
+ export { createAuthMiddleware } from './auth.js';
3
+ export { createBodyParser } from './body-parser.js';
4
+ export { createErrorHandler } from './error-handler.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import Router from '@koa/router';
2
+ import type { CogitatorState } from '../types.js';
3
+ export declare function createAgentRoutes(): Router<CogitatorState>;
4
+ //# sourceMappingURL=agents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../../src/routes/agents.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,KAAK,EACV,cAAc,EAIf,MAAM,aAAa,CAAC;AAKrB,wBAAgB,iBAAiB,IAAI,MAAM,CAAC,cAAc,CAAC,CA4H1D"}
@@ -0,0 +1,115 @@
1
+ import Router from '@koa/router';
2
+ import { KoaStreamWriter, setupSSEHeaders } from '../streaming/index.js';
3
+ import { generateId } from '@cogitator-ai/server-shared';
4
+ export function createAgentRoutes() {
5
+ const router = new Router();
6
+ router.get('/agents', (ctx) => {
7
+ const { agents } = ctx.state.cogitator;
8
+ const agentList = Object.entries(agents).map(([name, agent]) => ({
9
+ name,
10
+ description: agent.config.instructions?.slice(0, 100),
11
+ tools: agent.config.tools?.map((t) => t.name) || [],
12
+ }));
13
+ const response = { agents: agentList };
14
+ ctx.body = response;
15
+ });
16
+ router.post('/agents/:name/run', async (ctx) => {
17
+ const { agents, cogitator } = ctx.state.cogitator;
18
+ const { name } = ctx.params;
19
+ const agent = agents[name];
20
+ if (!agent) {
21
+ ctx.status = 404;
22
+ ctx.body = { error: { message: `Agent '${name}' not found`, code: 'NOT_FOUND' } };
23
+ return;
24
+ }
25
+ const body = ctx.request.body;
26
+ if (!body?.input) {
27
+ ctx.status = 400;
28
+ ctx.body = { error: { message: 'Missing required field: input', code: 'INVALID_INPUT' } };
29
+ return;
30
+ }
31
+ try {
32
+ const result = await cogitator.run(agent, {
33
+ input: body.input,
34
+ context: body.context,
35
+ threadId: body.threadId,
36
+ });
37
+ const response = {
38
+ output: result.output,
39
+ threadId: result.threadId,
40
+ usage: {
41
+ inputTokens: result.usage.inputTokens,
42
+ outputTokens: result.usage.outputTokens,
43
+ totalTokens: result.usage.totalTokens,
44
+ },
45
+ toolCalls: [...result.toolCalls],
46
+ };
47
+ ctx.body = response;
48
+ }
49
+ catch (error) {
50
+ const message = error instanceof Error ? error.message : 'Unknown error';
51
+ ctx.status = 500;
52
+ ctx.body = { error: { message, code: 'INTERNAL' } };
53
+ }
54
+ });
55
+ router.post('/agents/:name/stream', async (ctx) => {
56
+ const { agents, cogitator } = ctx.state.cogitator;
57
+ const { name } = ctx.params;
58
+ const agent = agents[name];
59
+ if (!agent) {
60
+ ctx.status = 404;
61
+ ctx.body = { error: { message: `Agent '${name}' not found`, code: 'NOT_FOUND' } };
62
+ return;
63
+ }
64
+ const body = ctx.request.body;
65
+ if (!body?.input) {
66
+ ctx.status = 400;
67
+ ctx.body = { error: { message: 'Missing required field: input', code: 'INVALID_INPUT' } };
68
+ return;
69
+ }
70
+ setupSSEHeaders(ctx);
71
+ const writer = new KoaStreamWriter(ctx);
72
+ const messageId = generateId('msg');
73
+ ctx.req.on('close', () => {
74
+ writer.close();
75
+ });
76
+ try {
77
+ writer.start(messageId);
78
+ const textId = generateId('txt');
79
+ writer.textStart(textId);
80
+ const result = await cogitator.run(agent, {
81
+ input: body.input,
82
+ context: body.context,
83
+ threadId: body.threadId,
84
+ stream: true,
85
+ onToken: (token) => {
86
+ writer.textDelta(textId, token);
87
+ },
88
+ onToolCall: (toolCall) => {
89
+ const toolId = generateId('tool');
90
+ writer.toolCallStart(toolId, toolCall.name);
91
+ writer.toolCallEnd(toolId);
92
+ },
93
+ onToolResult: (toolResult) => {
94
+ const resultId = generateId('res');
95
+ writer.toolResult(resultId, toolResult.callId, toolResult.result);
96
+ },
97
+ });
98
+ writer.textEnd(textId);
99
+ writer.finish(messageId, {
100
+ inputTokens: result.usage.inputTokens,
101
+ outputTokens: result.usage.outputTokens,
102
+ totalTokens: result.usage.totalTokens,
103
+ });
104
+ }
105
+ catch (error) {
106
+ const message = error instanceof Error ? error.message : 'Unknown error';
107
+ writer.error(message, 'INTERNAL');
108
+ }
109
+ finally {
110
+ writer.close();
111
+ }
112
+ });
113
+ return router;
114
+ }
115
+ //# sourceMappingURL=agents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agents.js","sourceRoot":"","sources":["../../src/routes/agents.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AAOjC,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAGzD,MAAM,UAAU,iBAAiB;IAC/B,MAAM,MAAM,GAAG,IAAI,MAAM,EAAkB,CAAC;IAE5C,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,EAAE;QAC5B,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC;QACvC,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;YAC/D,IAAI;YACJ,WAAW,EAAE,K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AAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;oBAClC,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;oBAC5C,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;gBAC7B,CAAC;gBACD,YAAY,EAAE,CAAC,UAA+C,EAAE,EAAE;oBAChE,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;oBACnC,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;gBACpE,CAAC;aACF,CAAC,CAAC;YAEH,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACvB,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE;gBACvB,WAAW,EAAE,MAAM,CAAC,KAAK,CAAC,WAAW;gBACrC,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC,YAAY;gBACvC,WAAW,EAAE,MAAM,CAAC,KAAK,CAAC,WAAW;aACtC,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC;YACzE,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QACpC,CAAC;gBAAS,CAAC;YACT,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import Router from '@koa/router';
2
+ import type { CogitatorState } from '../types.js';
3
+ export declare function createHealthRoutes(): Router<CogitatorState>;
4
+ //# sourceMappingURL=health.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../src/routes/health.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,KAAK,EAAE,cAAc,EAAkB,MAAM,aAAa,CAAC;AAIlE,wBAAgB,kBAAkB,IAAI,MAAM,CAAC,cAAc,CAAC,CAiB3D"}
@@ -0,0 +1,18 @@
1
+ import Router from '@koa/router';
2
+ const startTime = Date.now();
3
+ export function createHealthRoutes() {
4
+ const router = new Router();
5
+ router.get('/health', (ctx) => {
6
+ const response = {
7
+ status: 'ok',
8
+ uptime: Date.now() - startTime,
9
+ timestamp: Date.now(),
10
+ };
11
+ ctx.body = response;
12
+ });
13
+ router.get('/ready', (ctx) => {
14
+ ctx.body = { status: 'ok' };
15
+ });
16
+ return router;
17
+ }
18
+ //# sourceMappingURL=health.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.js","sourceRoot":"","sources":["../../src/routes/health.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AAGjC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;AAE7B,MAAM,UAAU,kBAAkB;IAChC,MAAM,MAAM,GAAG,IAAI,MAAM,EAAkB,CAAC;IAE5C,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,EAAE;QAC5B,MAAM,QAAQ,GAAmB;YAC/B,MAAM,EAAE,IAAI;YACZ,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;YAC9B,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACtB,CAAC;QACF,GAAG,CAAC,IAAI,GAAG,QAAQ,CAAC;IACtB,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,EAAE;QAC3B,GAAG,CAAC,IAAI,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IAC9B,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,7 @@
1
+ export { createHealthRoutes } from './health.js';
2
+ export { createAgentRoutes } from './agents.js';
3
+ export { createThreadRoutes } from './threads.js';
4
+ export { createToolRoutes } from './tools.js';
5
+ export { createWorkflowRoutes } from './workflows.js';
6
+ export { createSwarmRoutes } from './swarms.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/routes/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,7 @@
1
+ export { createHealthRoutes } from './health.js';
2
+ export { createAgentRoutes } from './agents.js';
3
+ export { createThreadRoutes } from './threads.js';
4
+ export { createToolRoutes } from './tools.js';
5
+ export { createWorkflowRoutes } from './workflows.js';
6
+ export { createSwarmRoutes } from './swarms.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/routes/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,4 @@
1
+ import Router from '@koa/router';
2
+ import type { CogitatorState } from '../types.js';
3
+ export declare function createSwarmRoutes(): Router<CogitatorState>;
4
+ //# sourceMappingURL=swarms.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"swarms.d.ts","sourceRoot":"","sources":["../../src/routes/swarms.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,KAAK,EACV,cAAc,EAKf,MAAM,aAAa,CAAC;AAKrB,wBAAgB,iBAAiB,IAAI,MAAM,CAAC,cAAc,CAAC,CA+L1D"}