@cogitator-ai/koa 0.1.3 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -24
- package/dist/swagger/index.d.ts.map +1 -1
- package/dist/swagger/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,7 +15,9 @@ import Koa from 'koa';
|
|
|
15
15
|
import { Cogitator, Agent } from '@cogitator-ai/core';
|
|
16
16
|
import { cogitatorApp } from '@cogitator-ai/koa';
|
|
17
17
|
|
|
18
|
-
const cogitator = new Cogitator({
|
|
18
|
+
const cogitator = new Cogitator({
|
|
19
|
+
/* ... */
|
|
20
|
+
});
|
|
19
21
|
const chatAgent = new Agent({ name: 'chat', instructions: 'You are a helpful assistant.' });
|
|
20
22
|
|
|
21
23
|
const app = new Koa();
|
|
@@ -39,17 +41,17 @@ Creates a Koa Router with all Cogitator endpoints.
|
|
|
39
41
|
|
|
40
42
|
**Options:**
|
|
41
43
|
|
|
42
|
-
| Option | Type
|
|
43
|
-
| ----------------- |
|
|
44
|
-
| `cogitator` | `Cogitator`
|
|
45
|
-
| `agents` | `Record<string, Agent>`
|
|
46
|
-
| `workflows` | `Record<string, Workflow>`
|
|
47
|
-
| `swarms` | `Record<string, SwarmConfig>`
|
|
44
|
+
| Option | Type | Description |
|
|
45
|
+
| ----------------- | ------------------------------- | ---------------------------------------------- |
|
|
46
|
+
| `cogitator` | `Cogitator` | **Required.** Cogitator runtime instance |
|
|
47
|
+
| `agents` | `Record<string, Agent>` | Named agents to expose |
|
|
48
|
+
| `workflows` | `Record<string, Workflow>` | Named workflows |
|
|
49
|
+
| `swarms` | `Record<string, SwarmConfig>` | Named swarms |
|
|
48
50
|
| `auth` | `(ctx: Context) => AuthContext` | Authentication function (receives Koa Context) |
|
|
49
|
-
| `enableSwagger` | `boolean`
|
|
50
|
-
| `swagger` | `SwaggerConfig`
|
|
51
|
-
| `enableWebSocket` | `boolean`
|
|
52
|
-
| `websocket` | `WebSocketConfig`
|
|
51
|
+
| `enableSwagger` | `boolean` | Enable Swagger/OpenAPI docs |
|
|
52
|
+
| `swagger` | `SwaggerConfig` | Swagger configuration |
|
|
53
|
+
| `enableWebSocket` | `boolean` | Enable WebSocket support |
|
|
54
|
+
| `websocket` | `WebSocketConfig` | WebSocket configuration |
|
|
53
55
|
|
|
54
56
|
## Endpoints
|
|
55
57
|
|
|
@@ -137,27 +139,31 @@ app.use(router.routes());
|
|
|
137
139
|
app.use(router.allowedMethods());
|
|
138
140
|
|
|
139
141
|
const server = createServer(app.callback());
|
|
140
|
-
await setupWebSocket(
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
142
|
+
await setupWebSocket(
|
|
143
|
+
server,
|
|
144
|
+
{ runtime: cogitator, agents, workflows: {}, swarms: {} },
|
|
145
|
+
{
|
|
146
|
+
path: '/ws',
|
|
147
|
+
pingInterval: 30000,
|
|
148
|
+
}
|
|
149
|
+
);
|
|
144
150
|
|
|
145
151
|
server.listen(3000);
|
|
146
152
|
```
|
|
147
153
|
|
|
148
154
|
**Message types:**
|
|
149
155
|
|
|
150
|
-
| Client sends | Description
|
|
151
|
-
| ------------ |
|
|
156
|
+
| Client sends | Description |
|
|
157
|
+
| ------------ | --------------------------------- |
|
|
152
158
|
| `run` | Start an agent/workflow/swarm run |
|
|
153
|
-
| `stop` | Cancel the current run
|
|
154
|
-
| `ping` | Heartbeat ping
|
|
159
|
+
| `stop` | Cancel the current run |
|
|
160
|
+
| `ping` | Heartbeat ping |
|
|
155
161
|
|
|
156
|
-
| Server sends | Description
|
|
157
|
-
| ------------ |
|
|
162
|
+
| Server sends | Description |
|
|
163
|
+
| ------------ | ----------------------------------------------- |
|
|
158
164
|
| `event` | Stream event (token, tool-call, complete, etc.) |
|
|
159
|
-
| `error` | Error response
|
|
160
|
-
| `pong` | Heartbeat pong
|
|
165
|
+
| `error` | Error response |
|
|
166
|
+
| `pong` | Heartbeat pong |
|
|
161
167
|
|
|
162
168
|
## SSE Streaming
|
|
163
169
|
|
|
@@ -207,7 +213,7 @@ Built-in middleware stack (applied automatically by `cogitatorApp`):
|
|
|
207
213
|
|
|
208
214
|
```typescript
|
|
209
215
|
import type {
|
|
210
|
-
RouteContext,
|
|
216
|
+
RouteContext, // { runtime, agents, workflows, swarms }
|
|
211
217
|
CogitatorAppOptions,
|
|
212
218
|
AuthContext,
|
|
213
219
|
AuthFunction,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/swagger/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAGL,KAAK,aAAa,EAEnB,MAAM,6BAA6B,CAAC;AAErC,wBAAgB,mBAAmB,CAAC,MAAM,CAAC,EAAE,aAAa,GAAG,MAAM,CAAC,cAAc,CAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/swagger/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAGL,KAAK,aAAa,EAEnB,MAAM,6BAA6B,CAAC;AAErC,wBAAgB,mBAAmB,CAAC,MAAM,CAAC,EAAE,aAAa,GAAG,MAAM,CAAC,cAAc,CAAC,CAkClF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/swagger/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC,OAAO,EACL,mBAAmB,EACnB,mBAAmB,GAGpB,MAAM,6BAA6B,CAAC;AAErC,MAAM,UAAU,mBAAmB,CAAC,MAAsB;IACxD,MAAM,MAAM,GAAG,IAAI,MAAM,EAAkB,CAAC;IAE5C,IAAI,UAA8D,C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