@workglow/ai 0.2.8 → 0.2.9
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/browser.js +652 -209
- package/dist/browser.js.map +14 -12
- package/dist/bun.js +652 -209
- package/dist/bun.js.map +14 -12
- package/dist/execution/QueuedExecutionStrategy.d.ts +14 -5
- package/dist/execution/QueuedExecutionStrategy.d.ts.map +1 -1
- package/dist/node.js +652 -209
- package/dist/node.js.map +14 -12
- package/dist/task/AiChatTask.d.ts +666 -0
- package/dist/task/AiChatTask.d.ts.map +1 -0
- package/dist/task/ChatMessage.d.ts +356 -0
- package/dist/task/ChatMessage.d.ts.map +1 -0
- package/dist/task/MessageConversion.d.ts +1 -9
- package/dist/task/MessageConversion.d.ts.map +1 -1
- package/dist/task/StructuredGenerationTask.d.ts +50 -3
- package/dist/task/StructuredGenerationTask.d.ts.map +1 -1
- package/dist/task/ToolCallingTask.d.ts +162 -8
- package/dist/task/ToolCallingTask.d.ts.map +1 -1
- package/dist/task/index.d.ts +6 -3
- package/dist/task/index.d.ts.map +1 -1
- package/dist/worker.js +42 -91
- package/dist/worker.js.map +3 -3
- package/package.json +11 -11
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
export type ContentBlockText = {
|
|
7
|
+
readonly type: "text";
|
|
8
|
+
readonly text: string;
|
|
9
|
+
};
|
|
10
|
+
export type ContentBlockImage = {
|
|
11
|
+
readonly type: "image";
|
|
12
|
+
readonly mimeType: string;
|
|
13
|
+
readonly data: string;
|
|
14
|
+
};
|
|
15
|
+
export type ContentBlockToolUse = {
|
|
16
|
+
readonly type: "tool_use";
|
|
17
|
+
readonly id: string;
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly input: Record<string, unknown>;
|
|
20
|
+
};
|
|
21
|
+
export type ContentBlockToolResult = {
|
|
22
|
+
readonly type: "tool_result";
|
|
23
|
+
readonly tool_use_id: string;
|
|
24
|
+
readonly content: ReadonlyArray<ContentBlock>;
|
|
25
|
+
readonly is_error: boolean | undefined;
|
|
26
|
+
};
|
|
27
|
+
export type ContentBlock = ContentBlockText | ContentBlockImage | ContentBlockToolUse | ContentBlockToolResult;
|
|
28
|
+
export type ChatRole = "user" | "assistant" | "tool" | "system";
|
|
29
|
+
export interface ChatMessage {
|
|
30
|
+
readonly role: ChatRole;
|
|
31
|
+
readonly content: ReadonlyArray<ContentBlock>;
|
|
32
|
+
}
|
|
33
|
+
export declare const ContentBlockSchema: {
|
|
34
|
+
readonly oneOf: readonly [{
|
|
35
|
+
readonly type: "object";
|
|
36
|
+
readonly properties: {
|
|
37
|
+
readonly type: {
|
|
38
|
+
readonly type: "string";
|
|
39
|
+
readonly enum: readonly ["text"];
|
|
40
|
+
};
|
|
41
|
+
readonly text: {
|
|
42
|
+
readonly type: "string";
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
readonly required: readonly ["type", "text"];
|
|
46
|
+
readonly additionalProperties: false;
|
|
47
|
+
}, {
|
|
48
|
+
readonly type: "object";
|
|
49
|
+
readonly properties: {
|
|
50
|
+
readonly type: {
|
|
51
|
+
readonly type: "string";
|
|
52
|
+
readonly enum: readonly ["image"];
|
|
53
|
+
};
|
|
54
|
+
readonly mimeType: {
|
|
55
|
+
readonly type: "string";
|
|
56
|
+
};
|
|
57
|
+
readonly data: {
|
|
58
|
+
readonly type: "string";
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
readonly required: readonly ["type", "mimeType", "data"];
|
|
62
|
+
readonly additionalProperties: false;
|
|
63
|
+
}, {
|
|
64
|
+
readonly type: "object";
|
|
65
|
+
readonly properties: {
|
|
66
|
+
readonly type: {
|
|
67
|
+
readonly type: "string";
|
|
68
|
+
readonly enum: readonly ["tool_use"];
|
|
69
|
+
};
|
|
70
|
+
readonly id: {
|
|
71
|
+
readonly type: "string";
|
|
72
|
+
};
|
|
73
|
+
readonly name: {
|
|
74
|
+
readonly type: "string";
|
|
75
|
+
};
|
|
76
|
+
readonly input: {
|
|
77
|
+
readonly type: "object";
|
|
78
|
+
readonly additionalProperties: true;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
readonly required: readonly ["type", "id", "name", "input"];
|
|
82
|
+
readonly additionalProperties: false;
|
|
83
|
+
}, {
|
|
84
|
+
readonly type: "object";
|
|
85
|
+
readonly properties: {
|
|
86
|
+
readonly type: {
|
|
87
|
+
readonly type: "string";
|
|
88
|
+
readonly enum: readonly ["tool_result"];
|
|
89
|
+
};
|
|
90
|
+
readonly tool_use_id: {
|
|
91
|
+
readonly type: "string";
|
|
92
|
+
};
|
|
93
|
+
readonly content: {
|
|
94
|
+
readonly type: "array";
|
|
95
|
+
readonly items: {
|
|
96
|
+
readonly $ref: "#/definitions/ContentBlock";
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
readonly is_error: {
|
|
100
|
+
readonly type: "boolean";
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
readonly required: readonly ["type", "tool_use_id", "content"];
|
|
104
|
+
readonly additionalProperties: false;
|
|
105
|
+
}];
|
|
106
|
+
readonly definitions: {
|
|
107
|
+
readonly ContentBlock: {
|
|
108
|
+
readonly oneOf: readonly [{
|
|
109
|
+
readonly type: "object";
|
|
110
|
+
readonly properties: {
|
|
111
|
+
readonly type: {
|
|
112
|
+
readonly type: "string";
|
|
113
|
+
readonly enum: readonly ["text"];
|
|
114
|
+
};
|
|
115
|
+
readonly text: {
|
|
116
|
+
readonly type: "string";
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
readonly required: readonly ["type", "text"];
|
|
120
|
+
readonly additionalProperties: false;
|
|
121
|
+
}, {
|
|
122
|
+
readonly type: "object";
|
|
123
|
+
readonly properties: {
|
|
124
|
+
readonly type: {
|
|
125
|
+
readonly type: "string";
|
|
126
|
+
readonly enum: readonly ["image"];
|
|
127
|
+
};
|
|
128
|
+
readonly mimeType: {
|
|
129
|
+
readonly type: "string";
|
|
130
|
+
};
|
|
131
|
+
readonly data: {
|
|
132
|
+
readonly type: "string";
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
readonly required: readonly ["type", "mimeType", "data"];
|
|
136
|
+
readonly additionalProperties: false;
|
|
137
|
+
}, {
|
|
138
|
+
readonly type: "object";
|
|
139
|
+
readonly properties: {
|
|
140
|
+
readonly type: {
|
|
141
|
+
readonly type: "string";
|
|
142
|
+
readonly enum: readonly ["tool_use"];
|
|
143
|
+
};
|
|
144
|
+
readonly id: {
|
|
145
|
+
readonly type: "string";
|
|
146
|
+
};
|
|
147
|
+
readonly name: {
|
|
148
|
+
readonly type: "string";
|
|
149
|
+
};
|
|
150
|
+
readonly input: {
|
|
151
|
+
readonly type: "object";
|
|
152
|
+
readonly additionalProperties: true;
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
readonly required: readonly ["type", "id", "name", "input"];
|
|
156
|
+
readonly additionalProperties: false;
|
|
157
|
+
}, {
|
|
158
|
+
readonly type: "object";
|
|
159
|
+
readonly properties: {
|
|
160
|
+
readonly type: {
|
|
161
|
+
readonly type: "string";
|
|
162
|
+
readonly enum: readonly ["tool_result"];
|
|
163
|
+
};
|
|
164
|
+
readonly tool_use_id: {
|
|
165
|
+
readonly type: "string";
|
|
166
|
+
};
|
|
167
|
+
readonly content: {
|
|
168
|
+
readonly type: "array";
|
|
169
|
+
readonly items: {
|
|
170
|
+
readonly $ref: "#/definitions/ContentBlock";
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
readonly is_error: {
|
|
174
|
+
readonly type: "boolean";
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
readonly required: readonly ["type", "tool_use_id", "content"];
|
|
178
|
+
readonly additionalProperties: false;
|
|
179
|
+
}];
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
readonly title: "ContentBlock";
|
|
183
|
+
readonly description: "A single content block within a chat message";
|
|
184
|
+
};
|
|
185
|
+
export declare const ChatMessageSchema: {
|
|
186
|
+
readonly type: "object";
|
|
187
|
+
readonly properties: {
|
|
188
|
+
readonly role: {
|
|
189
|
+
readonly type: "string";
|
|
190
|
+
readonly enum: readonly ["user", "assistant", "tool", "system"];
|
|
191
|
+
};
|
|
192
|
+
readonly content: {
|
|
193
|
+
readonly type: "array";
|
|
194
|
+
readonly items: {
|
|
195
|
+
readonly oneOf: readonly [{
|
|
196
|
+
readonly type: "object";
|
|
197
|
+
readonly properties: {
|
|
198
|
+
readonly type: {
|
|
199
|
+
readonly type: "string";
|
|
200
|
+
readonly enum: readonly ["text"];
|
|
201
|
+
};
|
|
202
|
+
readonly text: {
|
|
203
|
+
readonly type: "string";
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
readonly required: readonly ["type", "text"];
|
|
207
|
+
readonly additionalProperties: false;
|
|
208
|
+
}, {
|
|
209
|
+
readonly type: "object";
|
|
210
|
+
readonly properties: {
|
|
211
|
+
readonly type: {
|
|
212
|
+
readonly type: "string";
|
|
213
|
+
readonly enum: readonly ["image"];
|
|
214
|
+
};
|
|
215
|
+
readonly mimeType: {
|
|
216
|
+
readonly type: "string";
|
|
217
|
+
};
|
|
218
|
+
readonly data: {
|
|
219
|
+
readonly type: "string";
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
readonly required: readonly ["type", "mimeType", "data"];
|
|
223
|
+
readonly additionalProperties: false;
|
|
224
|
+
}, {
|
|
225
|
+
readonly type: "object";
|
|
226
|
+
readonly properties: {
|
|
227
|
+
readonly type: {
|
|
228
|
+
readonly type: "string";
|
|
229
|
+
readonly enum: readonly ["tool_use"];
|
|
230
|
+
};
|
|
231
|
+
readonly id: {
|
|
232
|
+
readonly type: "string";
|
|
233
|
+
};
|
|
234
|
+
readonly name: {
|
|
235
|
+
readonly type: "string";
|
|
236
|
+
};
|
|
237
|
+
readonly input: {
|
|
238
|
+
readonly type: "object";
|
|
239
|
+
readonly additionalProperties: true;
|
|
240
|
+
};
|
|
241
|
+
};
|
|
242
|
+
readonly required: readonly ["type", "id", "name", "input"];
|
|
243
|
+
readonly additionalProperties: false;
|
|
244
|
+
}, {
|
|
245
|
+
readonly type: "object";
|
|
246
|
+
readonly properties: {
|
|
247
|
+
readonly type: {
|
|
248
|
+
readonly type: "string";
|
|
249
|
+
readonly enum: readonly ["tool_result"];
|
|
250
|
+
};
|
|
251
|
+
readonly tool_use_id: {
|
|
252
|
+
readonly type: "string";
|
|
253
|
+
};
|
|
254
|
+
readonly content: {
|
|
255
|
+
readonly type: "array";
|
|
256
|
+
readonly items: {
|
|
257
|
+
readonly $ref: "#/definitions/ContentBlock";
|
|
258
|
+
};
|
|
259
|
+
};
|
|
260
|
+
readonly is_error: {
|
|
261
|
+
readonly type: "boolean";
|
|
262
|
+
};
|
|
263
|
+
};
|
|
264
|
+
readonly required: readonly ["type", "tool_use_id", "content"];
|
|
265
|
+
readonly additionalProperties: false;
|
|
266
|
+
}];
|
|
267
|
+
readonly definitions: {
|
|
268
|
+
readonly ContentBlock: {
|
|
269
|
+
readonly oneOf: readonly [{
|
|
270
|
+
readonly type: "object";
|
|
271
|
+
readonly properties: {
|
|
272
|
+
readonly type: {
|
|
273
|
+
readonly type: "string";
|
|
274
|
+
readonly enum: readonly ["text"];
|
|
275
|
+
};
|
|
276
|
+
readonly text: {
|
|
277
|
+
readonly type: "string";
|
|
278
|
+
};
|
|
279
|
+
};
|
|
280
|
+
readonly required: readonly ["type", "text"];
|
|
281
|
+
readonly additionalProperties: false;
|
|
282
|
+
}, {
|
|
283
|
+
readonly type: "object";
|
|
284
|
+
readonly properties: {
|
|
285
|
+
readonly type: {
|
|
286
|
+
readonly type: "string";
|
|
287
|
+
readonly enum: readonly ["image"];
|
|
288
|
+
};
|
|
289
|
+
readonly mimeType: {
|
|
290
|
+
readonly type: "string";
|
|
291
|
+
};
|
|
292
|
+
readonly data: {
|
|
293
|
+
readonly type: "string";
|
|
294
|
+
};
|
|
295
|
+
};
|
|
296
|
+
readonly required: readonly ["type", "mimeType", "data"];
|
|
297
|
+
readonly additionalProperties: false;
|
|
298
|
+
}, {
|
|
299
|
+
readonly type: "object";
|
|
300
|
+
readonly properties: {
|
|
301
|
+
readonly type: {
|
|
302
|
+
readonly type: "string";
|
|
303
|
+
readonly enum: readonly ["tool_use"];
|
|
304
|
+
};
|
|
305
|
+
readonly id: {
|
|
306
|
+
readonly type: "string";
|
|
307
|
+
};
|
|
308
|
+
readonly name: {
|
|
309
|
+
readonly type: "string";
|
|
310
|
+
};
|
|
311
|
+
readonly input: {
|
|
312
|
+
readonly type: "object";
|
|
313
|
+
readonly additionalProperties: true;
|
|
314
|
+
};
|
|
315
|
+
};
|
|
316
|
+
readonly required: readonly ["type", "id", "name", "input"];
|
|
317
|
+
readonly additionalProperties: false;
|
|
318
|
+
}, {
|
|
319
|
+
readonly type: "object";
|
|
320
|
+
readonly properties: {
|
|
321
|
+
readonly type: {
|
|
322
|
+
readonly type: "string";
|
|
323
|
+
readonly enum: readonly ["tool_result"];
|
|
324
|
+
};
|
|
325
|
+
readonly tool_use_id: {
|
|
326
|
+
readonly type: "string";
|
|
327
|
+
};
|
|
328
|
+
readonly content: {
|
|
329
|
+
readonly type: "array";
|
|
330
|
+
readonly items: {
|
|
331
|
+
readonly $ref: "#/definitions/ContentBlock";
|
|
332
|
+
};
|
|
333
|
+
};
|
|
334
|
+
readonly is_error: {
|
|
335
|
+
readonly type: "boolean";
|
|
336
|
+
};
|
|
337
|
+
};
|
|
338
|
+
readonly required: readonly ["type", "tool_use_id", "content"];
|
|
339
|
+
readonly additionalProperties: false;
|
|
340
|
+
}];
|
|
341
|
+
};
|
|
342
|
+
};
|
|
343
|
+
readonly title: "ContentBlock";
|
|
344
|
+
readonly description: "A single content block within a chat message";
|
|
345
|
+
};
|
|
346
|
+
};
|
|
347
|
+
};
|
|
348
|
+
readonly required: readonly ["role", "content"];
|
|
349
|
+
readonly additionalProperties: false;
|
|
350
|
+
readonly title: "ChatMessage";
|
|
351
|
+
readonly description: "A single chat message with role and structured content blocks";
|
|
352
|
+
};
|
|
353
|
+
export declare function isContentBlock(value: unknown): value is ContentBlock;
|
|
354
|
+
export declare function isChatMessage(value: unknown): value is ChatMessage;
|
|
355
|
+
export declare function textMessage(role: ChatRole, text: string): ChatMessage;
|
|
356
|
+
//# sourceMappingURL=ChatMessage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatMessage.d.ts","sourceRoot":"","sources":["../../src/task/ChatMessage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAQH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IAC9C,QAAQ,CAAC,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAC;CACxC,CA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;;iCAE7C,QAAQ;qCAAI,IAAI,EAAE,SAAS;;;iDAElB,MAAM,EAAE,aAAa,EAAE,SAAS;;;;6BAczC,YAAY;iCACV,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gCAQF,cAAc;sCACR,8CAA8C;;;;;;oBAcpD,aAAa;0BACP,+DAA+D;CAC3C,CAAC;AAMpC,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAwBpE;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAMlE;AAMD,wBAAgB,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,WAAW,CAErE"}
|
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright
|
|
3
|
+
* Copyright 2026 Steven Roussey <sroussey@gmail.com>
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
/**
|
|
7
|
-
* Shared message conversion utilities for converting provider-agnostic
|
|
8
|
-
* ChatMessage arrays to provider-specific formats.
|
|
9
|
-
*
|
|
10
|
-
* These are pure functions safe for both main-thread and worker contexts.
|
|
11
|
-
* Providers with unique requirements (Anthropic, Gemini, LlamaCpp)
|
|
12
|
-
* maintain their own conversion logic.
|
|
13
|
-
*/
|
|
14
6
|
import type { ToolCallingTaskInput } from "./ToolCallingTask";
|
|
15
7
|
export interface OpenAICompatMessage {
|
|
16
8
|
role: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageConversion.d.ts","sourceRoot":"","sources":["../../src/task/MessageConversion.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"MessageConversion.d.ts","sourceRoot":"","sources":["../../src/task/MessageConversion.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAYH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAoB9D,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC,CAAC;IACzE,UAAU,CAAC,EAAE,KAAK,CAAC;QACjB,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,UAAU,CAAC;QACjB,QAAQ,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,SAAS,EAAE,MAAM,CAAA;SAAE,CAAC;KAC/C,CAAC,CAAC;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,oBAAoB,GAAG,mBAAmB,EAAE,CAyGnF;AAMD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,oBAAoB,GAAG,eAAe,EAAE,CA2DjF"}
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import { CreateWorkflow } from "@workglow/task-graph";
|
|
7
|
-
import type { TaskConfig } from "@workglow/task-graph";
|
|
8
|
-
import { DataPortSchema, FromSchema } from "@workglow/util/schema";
|
|
6
|
+
import { CreateWorkflow, TaskError } from "@workglow/task-graph";
|
|
7
|
+
import type { IExecuteContext, StreamEvent, TaskConfig } from "@workglow/task-graph";
|
|
8
|
+
import type { DataPortSchema, FromSchema } from "@workglow/util/schema";
|
|
9
9
|
import { StreamingAiTask } from "./base/StreamingAiTask";
|
|
10
10
|
export declare const StructuredGenerationInputSchema: {
|
|
11
11
|
readonly type: "object";
|
|
@@ -102,6 +102,15 @@ export declare const StructuredGenerationInputSchema: {
|
|
|
102
102
|
readonly maximum: 2;
|
|
103
103
|
readonly "x-ui-group": "Configuration";
|
|
104
104
|
};
|
|
105
|
+
readonly maxRetries: {
|
|
106
|
+
readonly type: "integer";
|
|
107
|
+
readonly title: "Max Retries";
|
|
108
|
+
readonly description: "Number of times to re-prompt the model with validation errors when its output doesn't match the schema. 0 disables retries (fail on first mismatch).";
|
|
109
|
+
readonly minimum: 0;
|
|
110
|
+
readonly maximum: 10;
|
|
111
|
+
readonly default: 2;
|
|
112
|
+
readonly "x-ui-group": "Configuration";
|
|
113
|
+
};
|
|
105
114
|
};
|
|
106
115
|
readonly required: readonly ["model", "prompt", "outputSchema"];
|
|
107
116
|
readonly additionalProperties: false;
|
|
@@ -124,6 +133,27 @@ export declare const StructuredGenerationOutputSchema: {
|
|
|
124
133
|
export type StructuredGenerationTaskInput = FromSchema<typeof StructuredGenerationInputSchema>;
|
|
125
134
|
export type StructuredGenerationTaskOutput = FromSchema<typeof StructuredGenerationOutputSchema>;
|
|
126
135
|
export type StructuredGenerationTaskConfig = TaskConfig<StructuredGenerationTaskInput>;
|
|
136
|
+
/**
|
|
137
|
+
* One round of validation errors from a failed attempt.
|
|
138
|
+
*/
|
|
139
|
+
export interface StructuredOutputValidationAttempt {
|
|
140
|
+
readonly attempt: number;
|
|
141
|
+
readonly errors: ReadonlyArray<{
|
|
142
|
+
readonly path: string;
|
|
143
|
+
readonly message: string;
|
|
144
|
+
}>;
|
|
145
|
+
/** The invalid object the model produced on this attempt. */
|
|
146
|
+
readonly object: Record<string, unknown> | undefined;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Thrown when the model's output fails schema validation on every attempt
|
|
150
|
+
* (including retries).
|
|
151
|
+
*/
|
|
152
|
+
export declare class StructuredOutputValidationError extends TaskError {
|
|
153
|
+
static readonly type: string;
|
|
154
|
+
readonly attempts: ReadonlyArray<StructuredOutputValidationAttempt>;
|
|
155
|
+
constructor(attempts: ReadonlyArray<StructuredOutputValidationAttempt>);
|
|
156
|
+
}
|
|
127
157
|
export declare class StructuredGenerationTask extends StreamingAiTask<StructuredGenerationTaskInput, StructuredGenerationTaskOutput, StructuredGenerationTaskConfig> {
|
|
128
158
|
static type: string;
|
|
129
159
|
static category: string;
|
|
@@ -131,6 +161,23 @@ export declare class StructuredGenerationTask extends StreamingAiTask<Structured
|
|
|
131
161
|
static description: string;
|
|
132
162
|
static inputSchema(): DataPortSchema;
|
|
133
163
|
static outputSchema(): DataPortSchema;
|
|
164
|
+
/**
|
|
165
|
+
* Runs the provider, validates the resulting object against `input.outputSchema`,
|
|
166
|
+
* and retries with validation-error feedback up to `input.maxRetries` times if
|
|
167
|
+
* the model's output doesn't match. Between attempts, emits an empty
|
|
168
|
+
* object-delta so downstream accumulators reset.
|
|
169
|
+
*
|
|
170
|
+
* Throws:
|
|
171
|
+
* - `TaskConfigurationError` if `input.outputSchema` isn't a compilable JSON Schema.
|
|
172
|
+
* - `StructuredOutputValidationError` if every attempt fails validation.
|
|
173
|
+
*/
|
|
174
|
+
executeStream(input: StructuredGenerationTaskInput, context: IExecuteContext): AsyncIterable<StreamEvent<StructuredGenerationTaskOutput>>;
|
|
175
|
+
/**
|
|
176
|
+
* Drains executeStream so non-streaming callers get the validated output.
|
|
177
|
+
* Without this override, `execute()` would route through the base class's
|
|
178
|
+
* non-streaming path and bypass validation + retry entirely.
|
|
179
|
+
*/
|
|
180
|
+
execute(input: StructuredGenerationTaskInput, context: IExecuteContext): Promise<StructuredGenerationTaskOutput | undefined>;
|
|
134
181
|
}
|
|
135
182
|
/**
|
|
136
183
|
* Task for generating structured JSON output using a language model
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StructuredGenerationTask.d.ts","sourceRoot":"","sources":["../../src/task/StructuredGenerationTask.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAY,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"StructuredGenerationTask.d.ts","sourceRoot":"","sources":["../../src/task/StructuredGenerationTask.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAA0B,SAAS,EAAY,MAAM,sBAAsB,CAAC;AACnG,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAErF,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAc,MAAM,uBAAuB,CAAC;AAEpF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAIzD,eAAO,MAAM,+BAA+B;mBACpC,QAAQ;;iBAEZ,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBACL,MAAM;qBACJ,IAAI,EAAE,QAAQ;qBACd,KAAK,EAAE,QAAQ;qBACf,WAAW,EAAE,+CAA+C;;iBAE9D,YAAY;qBACV,IAAI,EAAE,QAAQ;qBACd,KAAK,EAAE,eAAe;qBACtB,WAAW,EAAE,qDAAqD;qBAClE,oBAAoB;;iBAEtB,SAAS;qBACP,IAAI,EAAE,QAAQ;qBACd,KAAK,EAAE,YAAY;qBACnB,WAAW,EAAE,0CAA0C;qBACvD,OAAO,EAAE,CAAC;qBACV,OAAO,EAAE,IAAI;qBACb,YAAY,EAAE,eAAe;;iBAE/B,WAAW;qBACT,IAAI,EAAE,QAAQ;qBACd,KAAK,EAAE,aAAa;qBACpB,WAAW,EAAE,qCAAqC;qBAClD,OAAO,EAAE,CAAC;qBACV,OAAO,EAAE,CAAC;qBACV,YAAY,EAAE,eAAe;;iBAE/B,UAAU;qBACR,IAAI,EAAE,SAAS;qBACf,KAAK,EAAE,aAAa;qBACpB,WAAW,EACT,sJAAsJ;qBACxJ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