@cogitator-ai/server-shared 0.4.0 → 0.5.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/dist/body.d.ts +46 -0
- package/dist/body.d.ts.map +1 -0
- package/dist/body.js +110 -0
- package/dist/body.js.map +1 -0
- package/dist/conformance.d.ts +140 -0
- package/dist/conformance.d.ts.map +1 -0
- package/dist/conformance.js +449 -0
- package/dist/conformance.js.map +1 -0
- package/dist/index.d.ts +13 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/openapi.d.ts.map +1 -1
- package/dist/openapi.js +106 -18
- package/dist/openapi.js.map +1 -1
- package/dist/protocol.d.ts +19 -3
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +4 -4
- package/dist/protocol.js.map +1 -1
- package/dist/response.d.ts +55 -0
- package/dist/response.d.ts.map +1 -0
- package/dist/response.js +41 -0
- package/dist/response.js.map +1 -0
- package/dist/stream-session.d.ts +42 -0
- package/dist/stream-session.d.ts.map +1 -0
- package/dist/stream-session.js +108 -0
- package/dist/stream-session.js.map +1 -0
- package/dist/swarm.d.ts +51 -0
- package/dist/swarm.d.ts.map +1 -0
- package/dist/swarm.js +37 -0
- package/dist/swarm.js.map +1 -0
- package/dist/validation.d.ts +68 -2
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +130 -3
- package/dist/validation.js.map +1 -1
- package/package.json +6 -2
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { generateId } from './helpers.js';
|
|
2
|
+
import { createApprovalRequiredEvent, createErrorEvent, createFinishEvent, createReasoningDeltaEvent, createReasoningEndEvent, createReasoningStartEvent, createStartEvent, createTextDeltaEvent, createTextEndEvent, createTextStartEvent, createToolCallDeltaEvent, createToolCallEndEvent, createToolCallStartEvent, createToolResultEvent, } from './protocol.js';
|
|
3
|
+
import { toAgentRunOutcome, toPendingApprovals } from './response.js';
|
|
4
|
+
const PART_EVENTS = {
|
|
5
|
+
text: {
|
|
6
|
+
prefix: 'txt',
|
|
7
|
+
start: createTextStartEvent,
|
|
8
|
+
delta: createTextDeltaEvent,
|
|
9
|
+
end: createTextEndEvent,
|
|
10
|
+
},
|
|
11
|
+
reasoning: {
|
|
12
|
+
prefix: 'rsn',
|
|
13
|
+
start: createReasoningStartEvent,
|
|
14
|
+
delta: createReasoningDeltaEvent,
|
|
15
|
+
end: createReasoningEndEvent,
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
/** A thread id nobody can guess, since a thread without an owner is open to whoever names it */
|
|
19
|
+
export function createThreadId() {
|
|
20
|
+
return `thread_${globalThis.crypto.randomUUID()}`;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The events of one streamed agent run or resume, the same in every adapter.
|
|
24
|
+
*
|
|
25
|
+
* `start` announces the message and the thread. Text and reasoning arrive as parts: a part
|
|
26
|
+
* opens with its first delta and closes before anything else is sent, so a client never sees
|
|
27
|
+
* two parts open at once, and a tool call never lands inside a text part. `complete` sends
|
|
28
|
+
* what the run did not stream (an answer the model gave in one piece), the approvals a paused
|
|
29
|
+
* run waits on, and `finish` with the usage, the thread and how the run ended. `fail` closes
|
|
30
|
+
* the open part and sends `error`.
|
|
31
|
+
*
|
|
32
|
+
* Pass the thread to the run (`threadId: session.threadId`) and spread `callbacks` into its
|
|
33
|
+
* options together with `stream: true`.
|
|
34
|
+
*/
|
|
35
|
+
export class AgentStreamSession {
|
|
36
|
+
emit;
|
|
37
|
+
messageId = generateId('msg');
|
|
38
|
+
threadId;
|
|
39
|
+
callbacks;
|
|
40
|
+
open;
|
|
41
|
+
streamedText = false;
|
|
42
|
+
streamedReasoning = false;
|
|
43
|
+
constructor(emit, options = {}) {
|
|
44
|
+
this.emit = emit;
|
|
45
|
+
this.threadId = options.threadId ?? createThreadId();
|
|
46
|
+
this.callbacks = {
|
|
47
|
+
onToken: (token) => {
|
|
48
|
+
if (!token)
|
|
49
|
+
return;
|
|
50
|
+
this.streamedText = true;
|
|
51
|
+
this.delta('text', token);
|
|
52
|
+
},
|
|
53
|
+
onReasoning: (delta) => {
|
|
54
|
+
if (!delta)
|
|
55
|
+
return;
|
|
56
|
+
this.streamedReasoning = true;
|
|
57
|
+
this.delta('reasoning', delta);
|
|
58
|
+
},
|
|
59
|
+
onToolCall: (call) => {
|
|
60
|
+
this.endPart();
|
|
61
|
+
this.emit(createToolCallStartEvent(call.id, call.name));
|
|
62
|
+
this.emit(createToolCallDeltaEvent(call.id, JSON.stringify(call.arguments)));
|
|
63
|
+
this.emit(createToolCallEndEvent(call.id));
|
|
64
|
+
},
|
|
65
|
+
onToolResult: (toolResult) => {
|
|
66
|
+
this.emit(createToolResultEvent(generateId('res'), toolResult.callId, toolResult.result));
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
start() {
|
|
71
|
+
this.emit(createStartEvent(this.messageId, this.threadId));
|
|
72
|
+
}
|
|
73
|
+
complete(result) {
|
|
74
|
+
if (!this.streamedReasoning && result.reasoning)
|
|
75
|
+
this.delta('reasoning', result.reasoning);
|
|
76
|
+
if (!this.streamedText && result.output)
|
|
77
|
+
this.delta('text', result.output);
|
|
78
|
+
this.endPart();
|
|
79
|
+
if (result.status === 'paused') {
|
|
80
|
+
this.emit(createApprovalRequiredEvent(result.threadId, toPendingApprovals(result.pendingApprovals ?? [])));
|
|
81
|
+
}
|
|
82
|
+
this.emit(createFinishEvent(this.messageId, result.usage, {
|
|
83
|
+
threadId: result.threadId,
|
|
84
|
+
...toAgentRunOutcome(result),
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
fail(message, code) {
|
|
88
|
+
this.endPart();
|
|
89
|
+
this.emit(createErrorEvent(message, code));
|
|
90
|
+
}
|
|
91
|
+
delta(kind, delta) {
|
|
92
|
+
const part = PART_EVENTS[kind];
|
|
93
|
+
if (this.open?.kind !== kind) {
|
|
94
|
+
this.endPart();
|
|
95
|
+
this.open = { kind, id: generateId(part.prefix) };
|
|
96
|
+
this.emit(part.start(this.open.id));
|
|
97
|
+
}
|
|
98
|
+
this.emit(part.delta(this.open.id, delta));
|
|
99
|
+
}
|
|
100
|
+
endPart() {
|
|
101
|
+
const open = this.open;
|
|
102
|
+
if (!open)
|
|
103
|
+
return;
|
|
104
|
+
this.open = undefined;
|
|
105
|
+
this.emit(PART_EVENTS[open.kind].end(open.id));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=stream-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-session.js","sourceRoot":"","sources":["../src/stream-session.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EACL,2BAA2B,EAC3B,gBAAgB,EAChB,iBAAiB,EACjB,yBAAyB,EACzB,uBAAuB,EACvB,yBAAyB,EACzB,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EACpB,wBAAwB,EACxB,sBAAsB,EACtB,wBAAwB,EACxB,qBAAqB,GAEtB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAiBtE,MAAM,WAAW,GAAG;IAClB,IAAI,EAAE;QACJ,MAAM,EAAE,KAAK;QACb,KAAK,EAAE,oBAAoB;QAC3B,KAAK,EAAE,oBAAoB;QAC3B,GAAG,EAAE,kBAAkB;KACxB;IACD,SAAS,EAAE;QACT,MAAM,EAAE,KAAK;QACb,KAAK,EAAE,yBAAyB;QAChC,KAAK,EAAE,yBAAyB;QAChC,GAAG,EAAE,uBAAuB;KAC7B;CACO,CAAC;AAEX,gGAAgG;AAChG,MAAM,UAAU,cAAc;IAC5B,OAAO,UAAU,UAAU,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,CAAC;AACpD,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,kBAAk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AI,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;QAC/B,IAAI,IAAI,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,EAAE,CAAC;YAC7B,IAAI,CAAC,OAAO,EAAE,CAAC;YACf,IAAI,CAAC,IAAI,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;YAClD,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;QACtC,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC;IAC7C,CAAC;IAEO,OAAO;QACb,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,IAAI;YAAE,OAAO;QAClB,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;QACtB,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;IACjD,CAAC;CACF"}
|
package/dist/swarm.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** The part of a `Swarm` that releases what it holds; distributed swarms hold Redis connections */
|
|
2
|
+
export interface ClosableSwarm {
|
|
3
|
+
close(): Promise<void>;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Runs `task` with a swarm the request created, and closes the swarm when the task settles:
|
|
7
|
+
* after success, failure or abort alike.
|
|
8
|
+
*
|
|
9
|
+
* A distributed swarm opens two Redis connections and keeps its state in Redis until it is
|
|
10
|
+
* closed, which also gives that state its expiry (`distributed.cleanupAfter`). A server that
|
|
11
|
+
* built one per request without closing it would leak connections until Redis refuses new
|
|
12
|
+
* clients. Closing an in-process swarm does nothing. A failure to close is logged, not
|
|
13
|
+
* thrown, so it never replaces the run's own result or error.
|
|
14
|
+
*/
|
|
15
|
+
export declare function withSwarm<S extends ClosableSwarm, T>(swarm: S, task: (swarm: S) => Promise<T>): Promise<T>;
|
|
16
|
+
/** The slots of a swarm config that hold agents, as `GET /swarms` reads them */
|
|
17
|
+
export interface SwarmAgentSlots {
|
|
18
|
+
supervisor?: {
|
|
19
|
+
name: string;
|
|
20
|
+
};
|
|
21
|
+
workers?: readonly {
|
|
22
|
+
name: string;
|
|
23
|
+
}[];
|
|
24
|
+
agents?: readonly {
|
|
25
|
+
name: string;
|
|
26
|
+
}[];
|
|
27
|
+
moderator?: {
|
|
28
|
+
name: string;
|
|
29
|
+
};
|
|
30
|
+
router?: {
|
|
31
|
+
name: string;
|
|
32
|
+
};
|
|
33
|
+
stages?: readonly {
|
|
34
|
+
agent: {
|
|
35
|
+
name: string;
|
|
36
|
+
};
|
|
37
|
+
}[];
|
|
38
|
+
pipeline?: {
|
|
39
|
+
stages: readonly {
|
|
40
|
+
agent: {
|
|
41
|
+
name: string;
|
|
42
|
+
};
|
|
43
|
+
}[];
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The names of every agent a swarm runs, in the order the swarm registers them: supervisor,
|
|
48
|
+
* workers, agents, moderator, router, then the pipeline stages. Each name appears once.
|
|
49
|
+
*/
|
|
50
|
+
export declare function swarmAgentNames(config: SwarmAgentSlots): string[];
|
|
51
|
+
//# sourceMappingURL=swarm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swarm.d.ts","sourceRoot":"","sources":["../src/swarm.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,MAAM,WAAW,aAAa;IAC5B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED;;;;;;;;;GASG;AACH,wBAAsB,SAAS,CAAC,CAAC,SAAS,aAAa,EAAE,CAAC,EACxD,KAAK,EAAE,CAAC,EACR,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAC7B,OAAO,CAAC,CAAC,CAAC,CAQZ;AAED,gFAAgF;AAChF,MAAM,WAAW,eAAe;IAC9B,UAAU,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAC9B,OAAO,CAAC,EAAE,SAAS;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACtC,MAAM,CAAC,EAAE,SAAS;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACrC,SAAS,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7B,MAAM,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAC1B,MAAM,CAAC,EAAE,SAAS;QAAE,KAAK,EAAE;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,EAAE,CAAC;IAChD,QAAQ,CAAC,EAAE;QAAE,MAAM,EAAE,SAAS;YAAE,KAAK,EAAE;gBAAE,IAAI,EAAE,MAAM,CAAA;aAAE,CAAA;SAAE,EAAE,CAAA;KAAE,CAAC;CAC/D;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,EAAE,CAWjE"}
|
package/dist/swarm.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs `task` with a swarm the request created, and closes the swarm when the task settles:
|
|
3
|
+
* after success, failure or abort alike.
|
|
4
|
+
*
|
|
5
|
+
* A distributed swarm opens two Redis connections and keeps its state in Redis until it is
|
|
6
|
+
* closed, which also gives that state its expiry (`distributed.cleanupAfter`). A server that
|
|
7
|
+
* built one per request without closing it would leak connections until Redis refuses new
|
|
8
|
+
* clients. Closing an in-process swarm does nothing. A failure to close is logged, not
|
|
9
|
+
* thrown, so it never replaces the run's own result or error.
|
|
10
|
+
*/
|
|
11
|
+
export async function withSwarm(swarm, task) {
|
|
12
|
+
try {
|
|
13
|
+
return await task(swarm);
|
|
14
|
+
}
|
|
15
|
+
finally {
|
|
16
|
+
await swarm.close().catch((error) => {
|
|
17
|
+
console.warn('[cogitator] Failed to close a swarm:', error);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The names of every agent a swarm runs, in the order the swarm registers them: supervisor,
|
|
23
|
+
* workers, agents, moderator, router, then the pipeline stages. Each name appears once.
|
|
24
|
+
*/
|
|
25
|
+
export function swarmAgentNames(config) {
|
|
26
|
+
const names = [
|
|
27
|
+
config.supervisor?.name,
|
|
28
|
+
...(config.workers ?? []).map((agent) => agent.name),
|
|
29
|
+
...(config.agents ?? []).map((agent) => agent.name),
|
|
30
|
+
config.moderator?.name,
|
|
31
|
+
config.router?.name,
|
|
32
|
+
...(config.stages ?? []).map((stage) => stage.agent.name),
|
|
33
|
+
...(config.pipeline?.stages ?? []).map((stage) => stage.agent.name),
|
|
34
|
+
];
|
|
35
|
+
return [...new Set(names.filter((name) => name !== undefined))];
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=swarm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swarm.js","sourceRoot":"","sources":["../src/swarm.ts"],"names":[],"mappings":"AAKA;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,KAAQ,EACR,IAA8B;IAE9B,IAAI,CAAC;QACH,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC;YAAS,CAAC;QACT,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;YAC3C,OAAO,CAAC,IAAI,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;QAC9D,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAaD;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,MAAuB;IACrD,MAAM,KAAK,GAAG;QACZ,MAAM,CAAC,UAAU,EAAE,IAAI;QACvB,GAAG,CAAC,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC;QACpD,GAAG,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC;QACnD,MAAM,CAAC,SAAS,EAAE,IAAI;QACtB,MAAM,CAAC,MAAM,EAAE,IAAI;QACnB,GAAG,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC;QACzD,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC;KACpE,CAAC;IACF,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC;AAClF,CAAC"}
|
package/dist/validation.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ToolApprovalDecision } from '@cogitator-ai/types';
|
|
1
2
|
/** The outcome of parsing a request body: the typed value, or why it was refused */
|
|
2
3
|
export type ParseResult<T> = {
|
|
3
4
|
ok: true;
|
|
@@ -29,6 +30,22 @@ export interface RunRequestBody {
|
|
|
29
30
|
context?: Record<string, unknown>;
|
|
30
31
|
threadId?: string;
|
|
31
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Which keys of a request's `context` a server hands to the run.
|
|
35
|
+
*
|
|
36
|
+
* The run puts `context` into the system prompt, below the agent's instructions, so a
|
|
37
|
+
* client that can set it speaks with the operator's voice. `false` (the default) refuses
|
|
38
|
+
* every key, a list accepts only those keys, and `true` accepts any key, for clients the
|
|
39
|
+
* server trusts as much as its own code.
|
|
40
|
+
*/
|
|
41
|
+
export type ContextPolicy = boolean | readonly string[];
|
|
42
|
+
/** How a server reads run requests */
|
|
43
|
+
export interface RunRequestOptions {
|
|
44
|
+
/** Keys of `context` the server accepts from clients. Default: none */
|
|
45
|
+
acceptContext?: ContextPolicy;
|
|
46
|
+
}
|
|
47
|
+
/** The longest `timeout` a run accepts: the largest delay a JavaScript timer can hold (about 24.8 days) */
|
|
48
|
+
export declare const MAX_RUN_TIMEOUT_MS = 2147483647;
|
|
32
49
|
/** The body of `POST /swarms/:name/run` and `/swarms/:name/stream` */
|
|
33
50
|
export interface SwarmRunRequestBody extends RunRequestBody {
|
|
34
51
|
timeout?: number;
|
|
@@ -40,7 +57,56 @@ export interface SwarmRunRequestBody extends RunRequestBody {
|
|
|
40
57
|
* says nothing is refused before the model is called (and billed). Every adapter
|
|
41
58
|
* answers a refusal with `400 { error: { message, code: 'INVALID_INPUT' } }`.
|
|
42
59
|
*/
|
|
43
|
-
export declare function parseRunRequest(body: unknown): ParseResult<RunRequestBody>;
|
|
60
|
+
export declare function parseRunRequest(body: unknown, options?: RunRequestOptions): ParseResult<RunRequestBody>;
|
|
44
61
|
/** Validates the body of a swarm run or stream: a run body plus an optional `timeout` in ms */
|
|
45
|
-
export declare function parseSwarmRunRequest(body: unknown): ParseResult<SwarmRunRequestBody>;
|
|
62
|
+
export declare function parseSwarmRunRequest(body: unknown, options?: RunRequestOptions): ParseResult<SwarmRunRequestBody>;
|
|
63
|
+
/** The body of `POST /agents/:name/resume` and `/agents/:name/resume/stream` */
|
|
64
|
+
export interface ResumeRequestBody {
|
|
65
|
+
/** The thread of the paused run */
|
|
66
|
+
threadId: string;
|
|
67
|
+
/** Decisions by tool call id; calls left out pause the run again */
|
|
68
|
+
decisions?: Record<string, ToolApprovalDecision>;
|
|
69
|
+
/** The decision for every paused call that `decisions` leaves out */
|
|
70
|
+
defaultDecision?: ToolApprovalDecision;
|
|
71
|
+
}
|
|
72
|
+
/** Validates the body of a resume: the thread of the paused run and the decisions for it */
|
|
73
|
+
export declare function parseResumeRequest(body: unknown): ParseResult<ResumeRequestBody>;
|
|
74
|
+
/** The roles a message added to a memory thread can have */
|
|
75
|
+
export type ThreadMessageRole = 'user' | 'assistant' | 'system';
|
|
76
|
+
/**
|
|
77
|
+
* The roles a server accepts on `POST /threads/:id/messages` unless told otherwise. A
|
|
78
|
+
* `system` message in a thread is read by the model as the operator's instructions, so a
|
|
79
|
+
* client may add one only where the server allows it explicitly.
|
|
80
|
+
*/
|
|
81
|
+
export declare const DEFAULT_THREAD_MESSAGE_ROLES: readonly ThreadMessageRole[];
|
|
82
|
+
/** The body of `POST /threads/:id/messages` */
|
|
83
|
+
export interface AddMessageRequestBody {
|
|
84
|
+
role: ThreadMessageRole;
|
|
85
|
+
content: string;
|
|
86
|
+
metadata?: Record<string, unknown>;
|
|
87
|
+
}
|
|
88
|
+
/** How a server reads messages added to threads */
|
|
89
|
+
export interface AddMessageRequestOptions {
|
|
90
|
+
/** The roles clients may add. Default: {@link DEFAULT_THREAD_MESSAGE_ROLES} */
|
|
91
|
+
roles?: readonly ThreadMessageRole[];
|
|
92
|
+
}
|
|
93
|
+
/** Validates a message added to a thread, refusing the roles the server does not accept */
|
|
94
|
+
export declare function parseAddMessageRequest(body: unknown, options?: AddMessageRequestOptions): ParseResult<AddMessageRequestBody>;
|
|
95
|
+
/** The body of `POST /workflows/:name/run` and `/workflows/:name/stream` */
|
|
96
|
+
export interface WorkflowRunRequestBody {
|
|
97
|
+
/** The initial workflow state */
|
|
98
|
+
input?: Record<string, unknown>;
|
|
99
|
+
options?: {
|
|
100
|
+
maxConcurrency?: number;
|
|
101
|
+
maxIterations?: number;
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Validates the body of a workflow run; no body at all runs the workflow from an empty state.
|
|
106
|
+
*
|
|
107
|
+
* `options.checkpoint: true` is refused: a server runs each workflow on a fresh executor and
|
|
108
|
+
* keeps no checkpoint store, so a checkpoint would be lost with the request. Run the
|
|
109
|
+
* workflow with `WorkflowExecutor` and a `CheckpointStore` to resume it later.
|
|
110
|
+
*/
|
|
111
|
+
export declare function parseWorkflowRunRequest(body: unknown): ParseResult<WorkflowRunRequestBody>;
|
|
46
112
|
//# sourceMappingURL=validation.d.ts.map
|
package/dist/validation.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAErF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,QAAQ,CAAC;AAEvC,8DAA8D;AAC9D,eAAO,MAAM,gBAAgB;;;;;CAKnB,CAAC;AAIX,2EAA2E;AAC3E,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAEhE;AAED,8DAA8D;AAC9D,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAE7E;AAED,sEAAsE;AACtE,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,sEAAsE;AACtE,MAAM,WAAW,mBAAoB,SAAQ,cAAc;IACzD,OAAO,CA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jC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE;QACR,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,CAAC;CACH;AAMD;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,OAAO,GAAG,WAAW,CAAC,sBAAsB,CAAC,CA+B1F"}
|
package/dist/validation.js
CHANGED
|
@@ -20,6 +20,8 @@ export function isNonBlankString(value) {
|
|
|
20
20
|
export function isJsonObject(value) {
|
|
21
21
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
22
22
|
}
|
|
23
|
+
/** The longest `timeout` a run accepts: the largest delay a JavaScript timer can hold (about 24.8 days) */
|
|
24
|
+
export const MAX_RUN_TIMEOUT_MS = 2_147_483_647;
|
|
23
25
|
function fail(message) {
|
|
24
26
|
return { ok: false, message };
|
|
25
27
|
}
|
|
@@ -30,7 +32,7 @@ function fail(message) {
|
|
|
30
32
|
* says nothing is refused before the model is called (and billed). Every adapter
|
|
31
33
|
* answers a refusal with `400 { error: { message, code: 'INVALID_INPUT' } }`.
|
|
32
34
|
*/
|
|
33
|
-
export function parseRunRequest(body) {
|
|
35
|
+
export function parseRunRequest(body, options = {}) {
|
|
34
36
|
if (!isJsonObject(body) || body.input === undefined || body.input === null) {
|
|
35
37
|
return fail('Missing required field: input');
|
|
36
38
|
}
|
|
@@ -41,6 +43,10 @@ export function parseRunRequest(body) {
|
|
|
41
43
|
if (body.context !== undefined && !isJsonObject(body.context)) {
|
|
42
44
|
return fail('Field "context" must be an object');
|
|
43
45
|
}
|
|
46
|
+
const refusedKey = body.context === undefined ? undefined : refusedContextKey(body.context, options.acceptContext);
|
|
47
|
+
if (refusedKey !== undefined) {
|
|
48
|
+
return fail(`Key "${refusedKey}" of field "context" is not accepted by this server`);
|
|
49
|
+
}
|
|
44
50
|
if (body.threadId !== undefined && !isNonBlankString(body.threadId)) {
|
|
45
51
|
return fail('Field "threadId" must be a non-empty string');
|
|
46
52
|
}
|
|
@@ -53,9 +59,15 @@ export function parseRunRequest(body) {
|
|
|
53
59
|
},
|
|
54
60
|
};
|
|
55
61
|
}
|
|
62
|
+
function refusedContextKey(context, policy = false) {
|
|
63
|
+
if (policy === true)
|
|
64
|
+
return undefined;
|
|
65
|
+
const accepted = policy === false ? [] : policy;
|
|
66
|
+
return Object.keys(context).find((key) => !accepted.includes(key));
|
|
67
|
+
}
|
|
56
68
|
/** Validates the body of a swarm run or stream: a run body plus an optional `timeout` in ms */
|
|
57
|
-
export function parseSwarmRunRequest(body) {
|
|
58
|
-
const parsed = parseRunRequest(body);
|
|
69
|
+
export function parseSwarmRunRequest(body, options = {}) {
|
|
70
|
+
const parsed = parseRunRequest(body, options);
|
|
59
71
|
if (!parsed.ok)
|
|
60
72
|
return parsed;
|
|
61
73
|
const timeout = isJsonObject(body) ? body.timeout : undefined;
|
|
@@ -64,6 +76,121 @@ export function parseSwarmRunRequest(body) {
|
|
|
64
76
|
if (typeof timeout !== 'number' || !Number.isFinite(timeout) || timeout <= 0) {
|
|
65
77
|
return fail('Field "timeout" must be a positive number');
|
|
66
78
|
}
|
|
79
|
+
if (timeout > MAX_RUN_TIMEOUT_MS) {
|
|
80
|
+
return fail(`Field "timeout" must be at most ${MAX_RUN_TIMEOUT_MS} ms`);
|
|
81
|
+
}
|
|
67
82
|
return { ok: true, value: { ...parsed.value, timeout } };
|
|
68
83
|
}
|
|
84
|
+
const DECISION_SHAPE = '{ approved: boolean, reason?: string }';
|
|
85
|
+
function parseDecision(value) {
|
|
86
|
+
if (!isJsonObject(value) || typeof value.approved !== 'boolean')
|
|
87
|
+
return undefined;
|
|
88
|
+
if (value.reason !== undefined && typeof value.reason !== 'string')
|
|
89
|
+
return undefined;
|
|
90
|
+
if (value.approved)
|
|
91
|
+
return { approved: true };
|
|
92
|
+
return value.reason === undefined
|
|
93
|
+
? { approved: false }
|
|
94
|
+
: { approved: false, reason: value.reason };
|
|
95
|
+
}
|
|
96
|
+
/** Validates the body of a resume: the thread of the paused run and the decisions for it */
|
|
97
|
+
export function parseResumeRequest(body) {
|
|
98
|
+
if (!isJsonObject(body) || body.threadId === undefined || body.threadId === null) {
|
|
99
|
+
return fail('Missing required field: threadId');
|
|
100
|
+
}
|
|
101
|
+
if (!isNonBlankString(body.threadId)) {
|
|
102
|
+
return fail('Field "threadId" must be a non-empty string');
|
|
103
|
+
}
|
|
104
|
+
const request = { threadId: body.threadId };
|
|
105
|
+
if (body.decisions !== undefined) {
|
|
106
|
+
if (!isJsonObject(body.decisions))
|
|
107
|
+
return fail('Field "decisions" must be an object');
|
|
108
|
+
const decisions = {};
|
|
109
|
+
for (const [toolCallId, value] of Object.entries(body.decisions)) {
|
|
110
|
+
const decision = parseDecision(value);
|
|
111
|
+
if (!decision)
|
|
112
|
+
return fail(`Each entry of "decisions" must be ${DECISION_SHAPE}`);
|
|
113
|
+
decisions[toolCallId] = decision;
|
|
114
|
+
}
|
|
115
|
+
request.decisions = decisions;
|
|
116
|
+
}
|
|
117
|
+
if (body.defaultDecision !== undefined) {
|
|
118
|
+
const decision = parseDecision(body.defaultDecision);
|
|
119
|
+
if (!decision)
|
|
120
|
+
return fail(`Field "defaultDecision" must be ${DECISION_SHAPE}`);
|
|
121
|
+
request.defaultDecision = decision;
|
|
122
|
+
}
|
|
123
|
+
return { ok: true, value: request };
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* The roles a server accepts on `POST /threads/:id/messages` unless told otherwise. A
|
|
127
|
+
* `system` message in a thread is read by the model as the operator's instructions, so a
|
|
128
|
+
* client may add one only where the server allows it explicitly.
|
|
129
|
+
*/
|
|
130
|
+
export const DEFAULT_THREAD_MESSAGE_ROLES = ['user', 'assistant'];
|
|
131
|
+
/** Validates a message added to a thread, refusing the roles the server does not accept */
|
|
132
|
+
export function parseAddMessageRequest(body, options = {}) {
|
|
133
|
+
const roles = options.roles ?? DEFAULT_THREAD_MESSAGE_ROLES;
|
|
134
|
+
if (!isJsonObject(body) || body.role === undefined || body.content === undefined) {
|
|
135
|
+
return fail('Missing required fields: role, content');
|
|
136
|
+
}
|
|
137
|
+
const role = roles.find((accepted) => accepted === body.role);
|
|
138
|
+
if (role === undefined) {
|
|
139
|
+
return fail(`Field "role" must be one of: ${roles.join(', ')}`);
|
|
140
|
+
}
|
|
141
|
+
if (!isNonBlankString(body.content))
|
|
142
|
+
return fail('Field "content" must be a non-empty string');
|
|
143
|
+
if (body.metadata !== undefined && !isJsonObject(body.metadata)) {
|
|
144
|
+
return fail('Field "metadata" must be an object');
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
ok: true,
|
|
148
|
+
value: {
|
|
149
|
+
role,
|
|
150
|
+
content: body.content,
|
|
151
|
+
...(body.metadata !== undefined && { metadata: body.metadata }),
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
function isPositiveInteger(value) {
|
|
156
|
+
return typeof value === 'number' && Number.isInteger(value) && value > 0;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Validates the body of a workflow run; no body at all runs the workflow from an empty state.
|
|
160
|
+
*
|
|
161
|
+
* `options.checkpoint: true` is refused: a server runs each workflow on a fresh executor and
|
|
162
|
+
* keeps no checkpoint store, so a checkpoint would be lost with the request. Run the
|
|
163
|
+
* workflow with `WorkflowExecutor` and a `CheckpointStore` to resume it later.
|
|
164
|
+
*/
|
|
165
|
+
export function parseWorkflowRunRequest(body) {
|
|
166
|
+
if (body === undefined || body === null)
|
|
167
|
+
return { ok: true, value: {} };
|
|
168
|
+
if (!isJsonObject(body))
|
|
169
|
+
return fail('Request body must be a JSON object');
|
|
170
|
+
if (body.input !== undefined && !isJsonObject(body.input)) {
|
|
171
|
+
return fail('Field "input" must be an object');
|
|
172
|
+
}
|
|
173
|
+
const request = {};
|
|
174
|
+
if (body.input !== undefined)
|
|
175
|
+
request.input = body.input;
|
|
176
|
+
if (body.options !== undefined) {
|
|
177
|
+
if (!isJsonObject(body.options))
|
|
178
|
+
return fail('Field "options" must be an object');
|
|
179
|
+
const { maxConcurrency, maxIterations, checkpoint } = body.options;
|
|
180
|
+
if (maxConcurrency !== undefined && !isPositiveInteger(maxConcurrency)) {
|
|
181
|
+
return fail('Field "options.maxConcurrency" must be a positive integer');
|
|
182
|
+
}
|
|
183
|
+
if (maxIterations !== undefined && !isPositiveInteger(maxIterations)) {
|
|
184
|
+
return fail('Field "options.maxIterations" must be a positive integer');
|
|
185
|
+
}
|
|
186
|
+
if (checkpoint !== undefined && checkpoint !== false) {
|
|
187
|
+
return fail('Field "options.checkpoint" is not supported: the server keeps no checkpoint store');
|
|
188
|
+
}
|
|
189
|
+
request.options = {
|
|
190
|
+
...(maxConcurrency !== undefined && { maxConcurrency }),
|
|
191
|
+
...(maxIterations !== undefined && { maxIterations }),
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
return { ok: true, value: request };
|
|
195
|
+
}
|
|
69
196
|
//# sourceMappingURL=validation.js.map
|
package/dist/validation.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,CAAC;AAEvC,8DAA8D;AAC9D,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,IAAI,EAAE,QAAQ;IACd,SAAS,EAAE,CAAC;IACZ,OAAO,EAAE,iBAAiB;IAC1B,WAAW,EAAE,4DAA4D;CACjE,CAAC;AAEX,MAAM,SAAS,GAAG,IAAI,MAAM,CAAC,iBAAiB,CAAC,CAAC;AAEhD,2EAA2E;AAC3E,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,OAAO,OAAO,KAAK,KAAK,QAAQ,IA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OAAO,GAAG;YAChB,GAAG,CAAC,cAAc,KAAK,SAAS,IAAI,EAAE,cAAc,EAAE,CAAC;YACvD,GAAG,CAAC,aAAa,KAAK,SAAS,IAAI,EAAE,aAAa,EAAE,CAAC;SACtD,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AACtC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cogitator-ai/server-shared",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Shared streaming protocol and utilities for Cogitator server adapters",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
|
-
"import": "./dist/index.js"
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"default": "./dist/index.js"
|
|
10
11
|
}
|
|
11
12
|
},
|
|
12
13
|
"main": "./dist/index.js",
|
|
@@ -17,6 +18,9 @@
|
|
|
17
18
|
"engines": {
|
|
18
19
|
"node": ">=22.12.0"
|
|
19
20
|
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@cogitator-ai/types": "0.36.0"
|
|
23
|
+
},
|
|
20
24
|
"devDependencies": {
|
|
21
25
|
"typescript": "^6.0.3",
|
|
22
26
|
"vitest": "^5.0.3"
|