@cogitator-ai/tetsu 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.
- package/LICENSE +21 -0
- package/README.md +268 -0
- package/dist/auth.d.ts +25 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +30 -0
- package/dist/auth.js.map +1 -0
- package/dist/controller.d.ts +804 -0
- package/dist/controller.d.ts.map +1 -0
- package/dist/controller.js +476 -0
- package/dist/controller.js.map +1 -0
- package/dist/errors.d.ts +32 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +70 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/operations.d.ts +41 -0
- package/dist/operations.d.ts.map +1 -0
- package/dist/operations.js +162 -0
- package/dist/operations.js.map +1 -0
- package/dist/schemas.d.ts +305 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +185 -0
- package/dist/schemas.js.map +1 -0
- package/dist/socket.d.ts +40 -0
- package/dist/socket.d.ts.map +1 -0
- package/dist/socket.js +120 -0
- package/dist/socket.js.map +1 -0
- package/dist/streaming.d.ts +16 -0
- package/dist/streaming.d.ts.map +1 -0
- package/dist/streaming.js +82 -0
- package/dist/streaming.js.map +1 -0
- package/dist/types.d.ts +84 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +72 -0
package/dist/schemas.js
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ERROR_STATUS_CODES } from '@cogitator-ai/types';
|
|
3
|
+
const JsonObject = z.record(z.string(), z.unknown());
|
|
4
|
+
export const NameParams = z.object({ name: z.string().min(1) });
|
|
5
|
+
export const ThreadParams = z.object({ id: z.string().min(1) });
|
|
6
|
+
export const RunBody = z.object({
|
|
7
|
+
input: z.string().min(1).describe('The message for the agent'),
|
|
8
|
+
context: JsonObject.optional().describe('Extra values passed to the run as context'),
|
|
9
|
+
threadId: z.string().min(1).optional().describe('Conversation thread kept in memory'),
|
|
10
|
+
});
|
|
11
|
+
export const SwarmRunBody = RunBody.extend({
|
|
12
|
+
timeout: z.number().positive().optional().describe('Run timeout in milliseconds'),
|
|
13
|
+
});
|
|
14
|
+
export const WorkflowRunBody = z.object({
|
|
15
|
+
input: JsonObject.optional().describe('Initial workflow state'),
|
|
16
|
+
options: z
|
|
17
|
+
.object({
|
|
18
|
+
maxConcurrency: z.number().int().positive().optional(),
|
|
19
|
+
maxIterations: z.number().int().positive().optional(),
|
|
20
|
+
checkpoint: z.boolean().optional(),
|
|
21
|
+
})
|
|
22
|
+
.optional(),
|
|
23
|
+
});
|
|
24
|
+
export const AddMessageBody = z.object({
|
|
25
|
+
role: z.enum(['user', 'assistant', 'system']),
|
|
26
|
+
content: z.string().min(1),
|
|
27
|
+
metadata: JsonObject.optional(),
|
|
28
|
+
});
|
|
29
|
+
export const ToolCallSchema = z.object({
|
|
30
|
+
id: z.string(),
|
|
31
|
+
name: z.string(),
|
|
32
|
+
arguments: JsonObject,
|
|
33
|
+
});
|
|
34
|
+
const ContentPartSchema = z.union([
|
|
35
|
+
z.object({ type: z.literal('text'), text: z.string() }),
|
|
36
|
+
z.object({
|
|
37
|
+
type: z.literal('image_url'),
|
|
38
|
+
image_url: z.object({ url: z.string(), detail: z.enum(['auto', 'low', 'high']).optional() }),
|
|
39
|
+
}),
|
|
40
|
+
z.object({
|
|
41
|
+
type: z.literal('image_base64'),
|
|
42
|
+
image_base64: z.object({ data: z.string(), media_type: z.string() }),
|
|
43
|
+
}),
|
|
44
|
+
]);
|
|
45
|
+
export const MessageSchema = z.object({
|
|
46
|
+
role: z.enum(['system', 'user', 'assistant', 'tool']),
|
|
47
|
+
content: z.union([z.string(), z.array(ContentPartSchema)]),
|
|
48
|
+
name: z.string().optional(),
|
|
49
|
+
toolCallId: z.string().optional(),
|
|
50
|
+
toolCalls: z.array(ToolCallSchema).optional(),
|
|
51
|
+
});
|
|
52
|
+
export const UsageSchema = z.object({
|
|
53
|
+
inputTokens: z.number(),
|
|
54
|
+
outputTokens: z.number(),
|
|
55
|
+
totalTokens: z.number(),
|
|
56
|
+
});
|
|
57
|
+
export const HealthResponse = z.object({
|
|
58
|
+
status: z.literal('ok'),
|
|
59
|
+
uptime: z.number().describe('Milliseconds since the controller was built'),
|
|
60
|
+
timestamp: z.number(),
|
|
61
|
+
});
|
|
62
|
+
export const ReadyResponse = z.object({ status: z.literal('ok') });
|
|
63
|
+
export const AgentListResponse = z.object({
|
|
64
|
+
agents: z.array(z.object({
|
|
65
|
+
name: z.string(),
|
|
66
|
+
description: z.string().optional(),
|
|
67
|
+
tools: z.array(z.string()),
|
|
68
|
+
})),
|
|
69
|
+
});
|
|
70
|
+
export const AgentRunResponse = z.object({
|
|
71
|
+
output: z.string(),
|
|
72
|
+
structured: z.unknown().optional(),
|
|
73
|
+
threadId: z.string(),
|
|
74
|
+
usage: UsageSchema,
|
|
75
|
+
toolCalls: z.array(ToolCallSchema),
|
|
76
|
+
});
|
|
77
|
+
export const ThreadResponse = z.object({
|
|
78
|
+
id: z.string(),
|
|
79
|
+
messages: z.array(MessageSchema),
|
|
80
|
+
createdAt: z.number(),
|
|
81
|
+
updatedAt: z.number(),
|
|
82
|
+
});
|
|
83
|
+
export const AddMessageResponse = z.object({ success: z.literal(true) });
|
|
84
|
+
export const ToolListResponse = z.object({
|
|
85
|
+
tools: z.array(z.object({
|
|
86
|
+
name: z.string(),
|
|
87
|
+
description: z.string().optional(),
|
|
88
|
+
parameters: JsonObject,
|
|
89
|
+
})),
|
|
90
|
+
});
|
|
91
|
+
export const WorkflowListResponse = z.object({
|
|
92
|
+
workflows: z.array(z.object({
|
|
93
|
+
name: z.string(),
|
|
94
|
+
entryPoint: z.string(),
|
|
95
|
+
nodes: z.array(z.string()),
|
|
96
|
+
})),
|
|
97
|
+
});
|
|
98
|
+
export const WorkflowRunResponse = z.object({
|
|
99
|
+
workflowId: z.string(),
|
|
100
|
+
workflowName: z.string(),
|
|
101
|
+
state: JsonObject,
|
|
102
|
+
duration: z.number(),
|
|
103
|
+
nodeResults: z.record(z.string(), z.object({ output: z.unknown(), duration: z.number() })),
|
|
104
|
+
});
|
|
105
|
+
export const SwarmListResponse = z.object({
|
|
106
|
+
swarms: z.array(z.object({
|
|
107
|
+
name: z.string(),
|
|
108
|
+
strategy: z.string(),
|
|
109
|
+
agents: z.array(z.string()),
|
|
110
|
+
})),
|
|
111
|
+
});
|
|
112
|
+
export const SwarmRunResponse = z.object({
|
|
113
|
+
swarmId: z.string(),
|
|
114
|
+
swarmName: z.string(),
|
|
115
|
+
strategy: z.string(),
|
|
116
|
+
output: z.unknown(),
|
|
117
|
+
agentResults: z.record(z.string(), z.object({
|
|
118
|
+
output: z.string(),
|
|
119
|
+
usage: UsageSchema.extend({ cost: z.number(), duration: z.number() }),
|
|
120
|
+
})),
|
|
121
|
+
usage: z.object({
|
|
122
|
+
totalTokens: z.number(),
|
|
123
|
+
totalCost: z.number(),
|
|
124
|
+
elapsedTime: z.number(),
|
|
125
|
+
}),
|
|
126
|
+
});
|
|
127
|
+
export const BlackboardResponse = z.object({ sections: JsonObject });
|
|
128
|
+
export const SocketMessage = z.discriminatedUnion('type', [
|
|
129
|
+
z.object({ type: z.literal('ping'), id: z.string().optional() }),
|
|
130
|
+
z.object({ type: z.literal('stop'), id: z.string().optional() }),
|
|
131
|
+
z.object({
|
|
132
|
+
type: z.literal('run'),
|
|
133
|
+
id: z.string().optional(),
|
|
134
|
+
payload: z.object({
|
|
135
|
+
type: z.enum(['agent', 'workflow', 'swarm']),
|
|
136
|
+
name: z.string().min(1),
|
|
137
|
+
input: z.string().min(1),
|
|
138
|
+
context: JsonObject.optional(),
|
|
139
|
+
threadId: z.string().min(1).optional(),
|
|
140
|
+
}),
|
|
141
|
+
}),
|
|
142
|
+
]);
|
|
143
|
+
export function errorEnvelope(error, description) {
|
|
144
|
+
return z
|
|
145
|
+
.object({
|
|
146
|
+
status: z.number().int(),
|
|
147
|
+
message: z.string(),
|
|
148
|
+
error: z.literal(error),
|
|
149
|
+
})
|
|
150
|
+
.describe(description);
|
|
151
|
+
}
|
|
152
|
+
function codesFor(status) {
|
|
153
|
+
return Object.entries(ERROR_STATUS_CODES)
|
|
154
|
+
.filter(([, codeStatus]) => codeStatus === status)
|
|
155
|
+
.map(([code]) => code);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* The envelope of every `CogitatorError` that maps to `status`, plus `extra` codes
|
|
159
|
+
* the adapter answers with itself.
|
|
160
|
+
*/
|
|
161
|
+
export function failureEnvelope(status, description, extra = []) {
|
|
162
|
+
const codes = [...new Set([...codesFor(status), ...extra])];
|
|
163
|
+
const [first, ...rest] = codes;
|
|
164
|
+
if (first === undefined)
|
|
165
|
+
throw new Error(`No error codes map to status ${status}`);
|
|
166
|
+
return z
|
|
167
|
+
.object({
|
|
168
|
+
status: z.number().int(),
|
|
169
|
+
message: z.string(),
|
|
170
|
+
error: z.enum([first, ...rest]),
|
|
171
|
+
})
|
|
172
|
+
.describe(description);
|
|
173
|
+
}
|
|
174
|
+
/** What a run of an agent, a workflow or a swarm can fail with, besides its own refusals. */
|
|
175
|
+
export const RUN_FAILURES = {
|
|
176
|
+
400: failureEnvelope(400, 'The model, a tool or a guardrail refused the request (context too long, content filtered, invalid tool arguments, prompt injection)'),
|
|
177
|
+
409: failureEnvelope(409, 'The agent is already running'),
|
|
178
|
+
429: failureEnvelope(429, 'The model provider is rate limiting requests; see Retry-After'),
|
|
179
|
+
500: failureEnvelope(500, 'A tool, a workflow step or the sandbox failed'),
|
|
180
|
+
502: failureEnvelope(502, 'The model provider answered with something unusable'),
|
|
181
|
+
503: failureEnvelope(503, 'The model provider, the sandbox or a circuit breaker is unavailable'),
|
|
182
|
+
504: failureEnvelope(504, 'The model, a tool or the sandbox timed out'),
|
|
183
|
+
507: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GAAG,EAAE,eAAe,CAAC,GAAG,EAAE,qEAAqE,CAAC;IAChG,GAAG,EAAE,eAAe,CAAC,GAAG,EAAE,4CAA4C,CAAC;IACvE,GAAG,EAAE,eAAe,CAAC,GAAG,EAAE,+BAA+B,CAAC;CAClD,CAAC"}
|
package/dist/socket.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { callerHook } from './auth.js';
|
|
3
|
+
import type { CogitatorDeps } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* The WebSocket endpoint of `cogitatorController()`.
|
|
6
|
+
*
|
|
7
|
+
* The handshake runs the same `auth` as the HTTP routes. Each socket runs one
|
|
8
|
+
* agent, workflow or swarm at a time; `stop` cancels it, and so does closing the
|
|
9
|
+
* socket.
|
|
10
|
+
*/
|
|
11
|
+
export declare function cogitatorSocket(deps: CogitatorDeps, caller: ReturnType<typeof callerHook>, path?: `/${string}`): import("@tetsujs/core").WsDef<`/${string}`, {
|
|
12
|
+
readonly message: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
13
|
+
type: z.ZodLiteral<"ping">;
|
|
14
|
+
id: z.ZodOptional<z.ZodString>;
|
|
15
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
16
|
+
type: z.ZodLiteral<"stop">;
|
|
17
|
+
id: z.ZodOptional<z.ZodString>;
|
|
18
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
19
|
+
type: z.ZodLiteral<"run">;
|
|
20
|
+
id: z.ZodOptional<z.ZodString>;
|
|
21
|
+
payload: z.ZodObject<{
|
|
22
|
+
type: z.ZodEnum<{
|
|
23
|
+
agent: "agent";
|
|
24
|
+
workflow: "workflow";
|
|
25
|
+
swarm: "swarm";
|
|
26
|
+
}>;
|
|
27
|
+
name: z.ZodString;
|
|
28
|
+
input: z.ZodString;
|
|
29
|
+
context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
30
|
+
threadId: z.ZodOptional<z.ZodString>;
|
|
31
|
+
}, z.core.$strip>;
|
|
32
|
+
}, z.core.$strip>], "type">;
|
|
33
|
+
}, {
|
|
34
|
+
readonly beforeParse: readonly [import("@tetsujs/core").Hook<"beforeParse", import("@tetsujs/core").BaseCtx & {
|
|
35
|
+
readonly params: {
|
|
36
|
+
[x: string]: string;
|
|
37
|
+
};
|
|
38
|
+
}, Pick<import("./auth.js").CallerFields, "cogitatorAuth">>];
|
|
39
|
+
}>;
|
|
40
|
+
//# sourceMappingURL=socket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socket.d.ts","sourceRoot":"","sources":["../src/socket.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAgB5C,OAAO,KAAK,EAAe,aAAa,EAA0B,MAAM,YAAY,CAAC;AAarF;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,aAAa,EACnB,MAAM,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,EACrC,IAAI,GAAE,IAAI,MAAM,EAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDlC"}
|
package/dist/socket.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { ws } from '@tetsujs/core';
|
|
2
|
+
import { describeError } from './errors.js';
|
|
3
|
+
import { checkThreadAccess, executeSwarm, executeWorkflow, findAgent, findSwarm, findWorkflow, runAgent, toAgentRunResponse, toSwarmRunResponse, toWorkflowRunResponse, } from './operations.js';
|
|
4
|
+
import { SocketMessage } from './schemas.js';
|
|
5
|
+
import { resolveSignal } from './streaming.js';
|
|
6
|
+
const OPEN = 1;
|
|
7
|
+
const DEFAULT_PATH = '/ws';
|
|
8
|
+
/**
|
|
9
|
+
* The WebSocket endpoint of `cogitatorController()`.
|
|
10
|
+
*
|
|
11
|
+
* The handshake runs the same `auth` as the HTTP routes. Each socket runs one
|
|
12
|
+
* agent, workflow or swarm at a time; `stop` cancels it, and so does closing the
|
|
13
|
+
* socket.
|
|
14
|
+
*/
|
|
15
|
+
export function cogitatorSocket(deps, caller, path = DEFAULT_PATH) {
|
|
16
|
+
const running = new WeakMap();
|
|
17
|
+
return ws({
|
|
18
|
+
path,
|
|
19
|
+
hooks: { beforeParse: [caller] },
|
|
20
|
+
schema: { message: SocketMessage },
|
|
21
|
+
docs: {
|
|
22
|
+
summary: 'Run agents, workflows and swarms over a WebSocket',
|
|
23
|
+
description: 'Send `{ type: "run", id, payload: { type, name, input } }`, `{ type: "stop" }` or `{ type: "ping" }`.',
|
|
24
|
+
},
|
|
25
|
+
until: () => resolveSignal(deps.until),
|
|
26
|
+
message: (socket, message) => {
|
|
27
|
+
switch (message.type) {
|
|
28
|
+
case 'ping':
|
|
29
|
+
send(socket, { type: 'pong', id: message.id });
|
|
30
|
+
return;
|
|
31
|
+
case 'stop':
|
|
32
|
+
running.get(socket)?.abort();
|
|
33
|
+
return;
|
|
34
|
+
case 'run': {
|
|
35
|
+
if (running.has(socket)) {
|
|
36
|
+
send(socket, {
|
|
37
|
+
type: 'error',
|
|
38
|
+
id: message.id,
|
|
39
|
+
error: 'A run is already in progress',
|
|
40
|
+
code: 'RUN_IN_PROGRESS',
|
|
41
|
+
});
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const controller = new AbortController();
|
|
45
|
+
running.set(socket, controller);
|
|
46
|
+
return handleRun(deps, socket, message.id, message.payload, socket.data.cogitatorAuth, {
|
|
47
|
+
signal: controller.signal,
|
|
48
|
+
}).finally(() => {
|
|
49
|
+
if (running.get(socket) === controller)
|
|
50
|
+
running.delete(socket);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
invalid: (socket, issues) => {
|
|
56
|
+
send(socket, {
|
|
57
|
+
type: 'error',
|
|
58
|
+
error: issues[0]?.message ?? 'Invalid message',
|
|
59
|
+
code: 'INVALID_MESSAGE',
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
close: (socket) => {
|
|
63
|
+
running.get(socket)?.abort();
|
|
64
|
+
running.delete(socket);
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
async function handleRun(deps, socket, id, payload, auth, { signal }) {
|
|
69
|
+
const emit = (event) => send(socket, { type: 'event', id, payload: event });
|
|
70
|
+
try {
|
|
71
|
+
const result = await execute(deps, payload, auth, signal, emit);
|
|
72
|
+
emit(signal.aborted ? { type: 'cancelled' } : { type: 'complete', result });
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
if (signal.aborted) {
|
|
76
|
+
emit({ type: 'cancelled' });
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const described = describeError(error);
|
|
80
|
+
send(socket, { type: 'error', id, error: described.message, code: described.code });
|
|
81
|
+
if (described.unexpected)
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async function execute(deps, payload, auth, signal, emit) {
|
|
86
|
+
switch (payload.type) {
|
|
87
|
+
case 'agent': {
|
|
88
|
+
const agent = findAgent(deps, payload.name);
|
|
89
|
+
await checkThreadAccess(deps, auth, payload.threadId);
|
|
90
|
+
const result = await runAgent(deps, agent, {
|
|
91
|
+
input: payload.input,
|
|
92
|
+
context: payload.context,
|
|
93
|
+
threadId: payload.threadId,
|
|
94
|
+
stream: true,
|
|
95
|
+
signal,
|
|
96
|
+
onToken: (delta) => emit({ type: 'token', delta }),
|
|
97
|
+
onToolCall: (call) => emit({ type: 'tool-call', id: call.id, name: call.name, arguments: call.arguments }),
|
|
98
|
+
onToolResult: (toolResult) => emit({ type: 'tool-result', ...toolResult }),
|
|
99
|
+
}, auth);
|
|
100
|
+
return toAgentRunResponse(result);
|
|
101
|
+
}
|
|
102
|
+
case 'workflow': {
|
|
103
|
+
const workflow = findWorkflow(deps, payload.name);
|
|
104
|
+
const result = await executeWorkflow(deps, workflow, { input: payload.input }, {}, signal);
|
|
105
|
+
return toWorkflowRunResponse(result);
|
|
106
|
+
}
|
|
107
|
+
case 'swarm': {
|
|
108
|
+
const config = findSwarm(deps, payload.name);
|
|
109
|
+
await checkThreadAccess(deps, auth, payload.threadId);
|
|
110
|
+
const { swarm, result } = await executeSwarm(deps, config, { input: payload.input, context: payload.context, threadId: payload.threadId }, signal);
|
|
111
|
+
return toSwarmRunResponse(swarm, result);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function send(socket, message) {
|
|
116
|
+
if (socket.readyState !== OPEN)
|
|
117
|
+
return;
|
|
118
|
+
socket.send(JSON.stringify(message));
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=socket.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socket.js","sourceRoot":"","sources":["../src/socket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;AAInC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,SAAS,EACT,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,kBAAkB,EAClB,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAW/C,MAAM,IAAI,GAAG,CAAC,CAAC;AACf,MAAM,YAAY,GAAG,KAAc,CAAC;AAEpC;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAC7B,IAAmB,EACnB,MAAqC,EACrC,OAAqB,YAAY;IAEjC,MAAM,OAAO,GAAG,IAAI,OAAO,EAA2B,CAAC;IAEvD,OAAO,EAAE,CAAC;QACR,IAAI;QACJ,KAAK,EAAE,EAAE,WAAW,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vent } from '@tetsujs/sse';
|
|
2
|
+
import type { StreamEvent } from '@cogitator-ai/server-shared';
|
|
3
|
+
import type { ShutdownSignal } from './types.js';
|
|
4
|
+
/** The last event of every successful stream, kept for clients of the other Cogitator adapters. */
|
|
5
|
+
export declare const DONE_EVENT: ServerSentEvent;
|
|
6
|
+
export declare function sseEvent(event: StreamEvent): ServerSentEvent;
|
|
7
|
+
export declare function resolveSignal(until: ShutdownSignal | undefined): AbortSignal | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Runs `task`, yielding every event it emits as soon as the reader asks for it.
|
|
10
|
+
*
|
|
11
|
+
* Ends when the task settles and its events are drained, rethrowing its error, or
|
|
12
|
+
* at once when `signal` aborts: a task that was given the signal stops by itself,
|
|
13
|
+
* and nobody is left to read what it would emit.
|
|
14
|
+
*/
|
|
15
|
+
export declare function eventsOf<T>(signal: AbortSignal, task: (emit: (event: T) => void) => Promise<void>): AsyncGenerator<T, void, undefined>;
|
|
16
|
+
//# sourceMappingURL=streaming.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../src/streaming.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,mGAAmG;AACnG,eAAO,MAAM,UAAU,EAAE,eAAoC,CAAC;AAE9D,wBAAgB,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,eAAe,CAE5D;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,cAAc,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,CAExF;AA+CD;;;;;;GAMG;AACH,wBAAuB,QAAQ,CAAC,CAAC,EAC/B,MAAM,EAAE,WAAW,EACnB,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,GAChD,cAAc,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,CAuBpC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/** The last event of every successful stream, kept for clients of the other Cogitator adapters. */
|
|
2
|
+
export const DONE_EVENT = { data: '[DONE]' };
|
|
3
|
+
export function sseEvent(event) {
|
|
4
|
+
return { data: event };
|
|
5
|
+
}
|
|
6
|
+
export function resolveSignal(until) {
|
|
7
|
+
return typeof until === 'function' ? until() : until;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A queue between callbacks that push events and a generator that pulls them.
|
|
11
|
+
*
|
|
12
|
+
* Callbacks of a run fire whenever the runtime gets there; the generator behind
|
|
13
|
+
* `sse()` asks for one event at a time, as the client reads. The queue holds what
|
|
14
|
+
* was pushed in between, and `end()` wakes a reader that is waiting.
|
|
15
|
+
*/
|
|
16
|
+
class EventQueue {
|
|
17
|
+
items = [];
|
|
18
|
+
ended = false;
|
|
19
|
+
wake;
|
|
20
|
+
push(item) {
|
|
21
|
+
if (this.ended)
|
|
22
|
+
return;
|
|
23
|
+
this.items.push(item);
|
|
24
|
+
this.notify();
|
|
25
|
+
}
|
|
26
|
+
end() {
|
|
27
|
+
this.ended = true;
|
|
28
|
+
this.notify();
|
|
29
|
+
}
|
|
30
|
+
async *drain() {
|
|
31
|
+
for (;;) {
|
|
32
|
+
const item = this.items.shift();
|
|
33
|
+
if (item !== undefined) {
|
|
34
|
+
yield item;
|
|
35
|
+
}
|
|
36
|
+
else if (this.ended) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
await new Promise((resolve) => {
|
|
41
|
+
this.wake = resolve;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
notify() {
|
|
47
|
+
const wake = this.wake;
|
|
48
|
+
this.wake = undefined;
|
|
49
|
+
wake?.();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Runs `task`, yielding every event it emits as soon as the reader asks for it.
|
|
54
|
+
*
|
|
55
|
+
* Ends when the task settles and its events are drained, rethrowing its error, or
|
|
56
|
+
* at once when `signal` aborts: a task that was given the signal stops by itself,
|
|
57
|
+
* and nobody is left to read what it would emit.
|
|
58
|
+
*/
|
|
59
|
+
export async function* eventsOf(signal, task) {
|
|
60
|
+
const queue = new EventQueue();
|
|
61
|
+
const stop = () => queue.end();
|
|
62
|
+
signal.addEventListener('abort', stop, { once: true });
|
|
63
|
+
if (signal.aborted)
|
|
64
|
+
stop();
|
|
65
|
+
let failure;
|
|
66
|
+
const settled = task((event) => queue.push(event)).then(() => queue.end(), (error) => {
|
|
67
|
+
failure = { error };
|
|
68
|
+
queue.end();
|
|
69
|
+
});
|
|
70
|
+
try {
|
|
71
|
+
yield* queue.drain();
|
|
72
|
+
if (signal.aborted)
|
|
73
|
+
return;
|
|
74
|
+
await settled;
|
|
75
|
+
if (failure)
|
|
76
|
+
throw failure.error;
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
signal.removeEventListener('abort', stop);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=streaming.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming.js","sourceRoot":"","sources":["../src/streaming.ts"],"names":[],"mappings":"AAIA,mGAAmG;AACnG,MAAM,CAAC,MAAM,UAAU,GAAoB,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;AAE9D,MAAM,UAAU,QAAQ,CAAC,KAAkB;IACzC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AACzB,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,KAAiC;IAC7D,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;AACvD,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AAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IACvD,IAAI,MAAM,CAAC,OAAO;QAAE,IAAI,EAAE,CAAC;IAE3B,IAAI,OAAuC,CAAC;IAC5C,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CACrD,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,EACjB,CAAC,KAAc,EAAE,EAAE;QACjB,OAAO,GAAG,EAAE,KAAK,EAAE,CAAC;QACpB,KAAK,CAAC,GAAG,EAAE,CAAC;IACd,CAAC,CACF,CAAC;IAEF,IAAI,CAAC;QACH,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACrB,IAAI,MAAM,CAAC,OAAO;YAAE,OAAO;QAC3B,MAAM,OAAO,CAAC;QACd,IAAI,OAAO;YAAE,MAAM,OAAO,CAAC,KAAK,CAAC;IACnC,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAC5C,CAAC;AACH,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { BaseCtx } from '@tetsujs/core';
|
|
2
|
+
import type { CallerHook } from './auth.js';
|
|
3
|
+
import type { z } from 'zod';
|
|
4
|
+
import type { Agent, Cogitator } from '@cogitator-ai/core';
|
|
5
|
+
import type { SwarmConfig, Workflow, WorkflowState } from '@cogitator-ai/types';
|
|
6
|
+
import type { AddMessageBody, AgentListResponse, AgentRunResponse, BlackboardResponse, HealthResponse, RunBody, SocketMessage, SwarmListResponse, SwarmRunBody, SwarmRunResponse, ThreadResponse, ToolListResponse, WorkflowListResponse, WorkflowRunBody, WorkflowRunResponse } from './schemas.js';
|
|
7
|
+
/**
|
|
8
|
+
* Who is calling, as the `auth` function established it.
|
|
9
|
+
*
|
|
10
|
+
* `userId` is passed to every agent run, so memory and cost tracking are
|
|
11
|
+
* attributed to the caller.
|
|
12
|
+
*/
|
|
13
|
+
export interface AuthContext {
|
|
14
|
+
userId?: string;
|
|
15
|
+
roles?: string[];
|
|
16
|
+
permissions?: string[];
|
|
17
|
+
metadata?: Record<string, unknown>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Establishes the caller before the request body is read.
|
|
21
|
+
*
|
|
22
|
+
* Return the caller to let the request through, or `undefined` to refuse it
|
|
23
|
+
* with `401 UNAUTHORIZED`. Throw an `HttpError` to answer with another status.
|
|
24
|
+
* Return an empty object to accept anonymous callers.
|
|
25
|
+
*/
|
|
26
|
+
export type Authenticate = (ctx: BaseCtx) => AuthContext | undefined | Promise<AuthContext | undefined>;
|
|
27
|
+
/**
|
|
28
|
+
* Decides whether the caller may read or write a memory thread.
|
|
29
|
+
*
|
|
30
|
+
* Checked on the thread routes and on every run, stream and WebSocket run
|
|
31
|
+
* that names a `threadId`. A refusal answers `403 THREAD_FORBIDDEN`.
|
|
32
|
+
*/
|
|
33
|
+
export type AuthorizeThread = (auth: AuthContext | undefined, threadId: string) => boolean | Promise<boolean>;
|
|
34
|
+
/**
|
|
35
|
+
* A signal that ends open SSE streams and WebSocket connections, such as
|
|
36
|
+
* `draining` from `@tetsujs/lifecycle`, or a function that returns it.
|
|
37
|
+
*/
|
|
38
|
+
export type ShutdownSignal = AbortSignal | (() => AbortSignal | undefined);
|
|
39
|
+
export interface WebSocketOptions {
|
|
40
|
+
/** Path of the handshake. Default: `/ws`. */
|
|
41
|
+
path?: `/${string}`;
|
|
42
|
+
}
|
|
43
|
+
/** What `cogitatorController()` is built from. */
|
|
44
|
+
export interface CogitatorDeps {
|
|
45
|
+
cogitator: Cogitator;
|
|
46
|
+
agents?: Record<string, Agent>;
|
|
47
|
+
workflows?: Record<string, Workflow<WorkflowState>>;
|
|
48
|
+
swarms?: Record<string, SwarmConfig>;
|
|
49
|
+
/**
|
|
50
|
+
* Establishes the caller before every route except `/health` and `/ready`, and
|
|
51
|
+
* before the WebSocket handshake: a function, or a `callerHook()` wrapped in
|
|
52
|
+
* `secured()` from `@tetsujs/openapi` to document it.
|
|
53
|
+
*/
|
|
54
|
+
auth?: Authenticate | CallerHook;
|
|
55
|
+
authorizeThread?: AuthorizeThread;
|
|
56
|
+
/** Serve the WebSocket endpoint. Default: `false`. */
|
|
57
|
+
websocket?: boolean | WebSocketOptions;
|
|
58
|
+
/** Ends streams and sockets when the server starts draining. */
|
|
59
|
+
until?: ShutdownSignal;
|
|
60
|
+
}
|
|
61
|
+
export type AgentRunRequest = z.input<typeof RunBody>;
|
|
62
|
+
export type SwarmRunRequest = z.input<typeof SwarmRunBody>;
|
|
63
|
+
export type WorkflowRunRequest = z.input<typeof WorkflowRunBody>;
|
|
64
|
+
export type AddMessageRequest = z.input<typeof AddMessageBody>;
|
|
65
|
+
export type HealthResponseBody = z.output<typeof HealthResponse>;
|
|
66
|
+
export type AgentListResponseBody = z.output<typeof AgentListResponse>;
|
|
67
|
+
export type AgentRunResponseBody = z.output<typeof AgentRunResponse>;
|
|
68
|
+
export type ThreadResponseBody = z.output<typeof ThreadResponse>;
|
|
69
|
+
export type ToolListResponseBody = z.output<typeof ToolListResponse>;
|
|
70
|
+
export type WorkflowListResponseBody = z.output<typeof WorkflowListResponse>;
|
|
71
|
+
export type WorkflowRunResponseBody = z.output<typeof WorkflowRunResponse>;
|
|
72
|
+
export type SwarmListResponseBody = z.output<typeof SwarmListResponse>;
|
|
73
|
+
export type SwarmRunResponseBody = z.output<typeof SwarmRunResponse>;
|
|
74
|
+
export type BlackboardResponseBody = z.output<typeof BlackboardResponse>;
|
|
75
|
+
export type WebSocketClientMessage = z.input<typeof SocketMessage>;
|
|
76
|
+
/** A frame the server sends over the WebSocket. */
|
|
77
|
+
export interface WebSocketServerMessage {
|
|
78
|
+
type: 'event' | 'error' | 'pong';
|
|
79
|
+
id?: string;
|
|
80
|
+
payload?: unknown;
|
|
81
|
+
error?: string;
|
|
82
|
+
code?: string;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,KAAK,EACV,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,EACd,OAAO,EACP,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,eAAe,EACf,mBAAmB,EACpB,MAAM,cAAc,CAAC;AAEtB;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG,CACzB,GAAG,EAAE,OAAO,KACT,WAAW,GAAG,SAAS,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAAC;AAEhE;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,CAC5B,IAAI,EAAE,WAAW,GAAG,SAAS,EAC7B,QAAQ,EAAE,MAAM,KACb,OAAO,GAAG,OAAO,C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AoB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,gBAAgB,CAAC,CAAC;AACrE,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,cAAc,CAAC,CAAC;AACjE,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,gBAAgB,CAAC,CAAC;AACrE,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAC7E,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAC3E,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,iBAAiB,CAAC,CAAC;AACvE,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,gBAAgB,CAAC,CAAC;AACrE,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,kBAAkB,CAAC,CAAC;AACzE,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAEnE,mDAAmD;AACnD,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC;IACjC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cogitator-ai/tetsu",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Tetsu server adapter for Cogitator AI runtime — a controller with agents, threads, workflows, swarms, SSE and WebSocket on Bun",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.js"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"engines": {
|
|
18
|
+
"bun": ">=1.4"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@cogitator-ai/core": "0.21.1",
|
|
22
|
+
"@cogitator-ai/memory": "0.8.0",
|
|
23
|
+
"@cogitator-ai/types": "0.24.0",
|
|
24
|
+
"@cogitator-ai/server-shared": "0.2.0",
|
|
25
|
+
"zod": "^4.6.5"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@tetsujs/core": "^0.6.1",
|
|
29
|
+
"@tetsujs/sse": "^0.6.1"
|
|
30
|
+
},
|
|
31
|
+
"optionalDependencies": {
|
|
32
|
+
"@cogitator-ai/workflows": "0.7.1",
|
|
33
|
+
"@cogitator-ai/swarms": "0.6.1"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@cogitator-ai/workflows": "0.7.1",
|
|
37
|
+
"@cogitator-ai/swarms": "0.6.1",
|
|
38
|
+
"@tetsujs/core": "^0.6.1",
|
|
39
|
+
"@tetsujs/openapi": "^0.6.1",
|
|
40
|
+
"@tetsujs/sse": "^0.6.1",
|
|
41
|
+
"@types/bun": "^1.4.2",
|
|
42
|
+
"typescript": "^6.0.3"
|
|
43
|
+
},
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "https://github.com/cogitator-ai/Cogitator-AI.git",
|
|
47
|
+
"directory": "packages/tetsu"
|
|
48
|
+
},
|
|
49
|
+
"license": "MIT",
|
|
50
|
+
"keywords": [
|
|
51
|
+
"cogitator",
|
|
52
|
+
"ai",
|
|
53
|
+
"agents",
|
|
54
|
+
"tetsu",
|
|
55
|
+
"bun",
|
|
56
|
+
"server",
|
|
57
|
+
"api",
|
|
58
|
+
"streaming",
|
|
59
|
+
"sse",
|
|
60
|
+
"websocket",
|
|
61
|
+
"openapi",
|
|
62
|
+
"llm"
|
|
63
|
+
],
|
|
64
|
+
"scripts": {
|
|
65
|
+
"build": "tsc && tsx ../../scripts/fix-esm-imports.ts .",
|
|
66
|
+
"dev": "tsc --watch",
|
|
67
|
+
"test": "bun test",
|
|
68
|
+
"test:watch": "bun test --watch",
|
|
69
|
+
"typecheck": "tsc --noEmit -p tsconfig.test.json",
|
|
70
|
+
"clean": "rm -rf dist"
|
|
71
|
+
}
|
|
72
|
+
}
|