@workglow/ai 0.2.32 → 0.2.34

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.
@@ -0,0 +1,710 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Steven Roussey <sroussey@gmail.com>
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type { IExecuteContext, StreamEvent } from "@workglow/task-graph";
7
+ import type { DataPortSchema, FromSchema } from "@workglow/util/schema";
8
+ import type { AiJobInput } from "../job/AiJob";
9
+ import { StreamingAiTask } from "./base/StreamingAiTask";
10
+ import type { ChatMessage } from "./ChatMessage";
11
+ export interface ChatChunkReference {
12
+ readonly kbId: string;
13
+ readonly kbLabel: string;
14
+ readonly title: string;
15
+ readonly url: string | undefined;
16
+ readonly snippet: string;
17
+ readonly score: number;
18
+ /**
19
+ * 1-based position of this chunk in the prompt the model sees, so the
20
+ * model's reply citing `[N]` maps back to this entry. `0` for
21
+ * author-supplied `noMatchReferences` (which don't correspond to any
22
+ * prompt chunk).
23
+ */
24
+ readonly index: number;
25
+ }
26
+ export declare const AiChatWithKbInputSchema: {
27
+ readonly type: "object";
28
+ readonly properties: {
29
+ readonly model: {
30
+ readonly oneOf: readonly [{
31
+ readonly title: "Model";
32
+ readonly description: `The model ${string}`;
33
+ } & {
34
+ readonly format: import(".").TypeModelSemantic;
35
+ readonly type: "string";
36
+ }, {
37
+ readonly type: "object";
38
+ readonly properties: {
39
+ readonly model_id: {
40
+ readonly type: "string";
41
+ };
42
+ readonly tasks: {
43
+ readonly type: "array";
44
+ readonly items: {
45
+ readonly type: "string";
46
+ };
47
+ readonly "x-ui-editor": "multiselect";
48
+ };
49
+ readonly title: {
50
+ readonly type: "string";
51
+ };
52
+ readonly description: {
53
+ readonly type: "string";
54
+ readonly "x-ui-editor": "textarea";
55
+ };
56
+ readonly provider: {
57
+ readonly type: "string";
58
+ };
59
+ readonly provider_config: {
60
+ readonly type: "object";
61
+ readonly properties: {
62
+ readonly credential_key: {
63
+ readonly type: "string";
64
+ readonly format: "credential";
65
+ readonly "x-ui-hidden": true;
66
+ };
67
+ readonly native_dimensions: {
68
+ readonly type: "integer";
69
+ readonly description: "Native output vector dimensions for embedding models";
70
+ };
71
+ readonly mrl: {
72
+ readonly type: "boolean";
73
+ readonly description: "Whether the model supports Matryoshka Representation Learning";
74
+ };
75
+ };
76
+ readonly additionalProperties: true;
77
+ readonly default: {};
78
+ };
79
+ readonly metadata: {
80
+ readonly type: "object";
81
+ readonly default: {};
82
+ readonly "x-ui-hidden": true;
83
+ };
84
+ };
85
+ readonly required: readonly ["provider", "provider_config"];
86
+ readonly format: "model";
87
+ readonly additionalProperties: true;
88
+ } & {
89
+ readonly format: import(".").TypeModelSemantic;
90
+ }];
91
+ } & {
92
+ readonly format: import(".").TypeModelSemantic;
93
+ };
94
+ readonly prompt: {
95
+ readonly oneOf: readonly [{
96
+ readonly type: "string";
97
+ readonly title: "Prompt";
98
+ readonly description: "The initial user message";
99
+ }, {
100
+ readonly type: "array";
101
+ readonly title: "Prompt";
102
+ readonly description: "The initial user message as structured content blocks";
103
+ readonly items: {
104
+ readonly oneOf: readonly [{
105
+ readonly type: "object";
106
+ readonly properties: {
107
+ readonly type: {
108
+ readonly type: "string";
109
+ readonly enum: readonly ["text"];
110
+ };
111
+ readonly text: {
112
+ readonly type: "string";
113
+ };
114
+ };
115
+ readonly required: readonly ["type", "text"];
116
+ readonly additionalProperties: false;
117
+ }, {
118
+ readonly type: "object";
119
+ readonly properties: {
120
+ readonly type: {
121
+ readonly type: "string";
122
+ readonly enum: readonly ["image"];
123
+ };
124
+ readonly mimeType: {
125
+ readonly type: "string";
126
+ };
127
+ readonly data: {
128
+ readonly type: "string";
129
+ };
130
+ };
131
+ readonly required: readonly ["type", "mimeType", "data"];
132
+ readonly additionalProperties: false;
133
+ }, {
134
+ readonly type: "object";
135
+ readonly properties: {
136
+ readonly type: {
137
+ readonly type: "string";
138
+ readonly enum: readonly ["tool_use"];
139
+ };
140
+ readonly id: {
141
+ readonly type: "string";
142
+ };
143
+ readonly name: {
144
+ readonly type: "string";
145
+ };
146
+ readonly input: {
147
+ readonly type: "object";
148
+ readonly additionalProperties: true;
149
+ };
150
+ };
151
+ readonly required: readonly ["type", "id", "name", "input"];
152
+ readonly additionalProperties: false;
153
+ }, {
154
+ readonly type: "object";
155
+ readonly properties: {
156
+ readonly type: {
157
+ readonly type: "string";
158
+ readonly enum: readonly ["tool_result"];
159
+ };
160
+ readonly tool_use_id: {
161
+ readonly type: "string";
162
+ };
163
+ readonly content: {
164
+ readonly type: "array";
165
+ readonly items: {
166
+ readonly oneOf: readonly [{
167
+ readonly type: "object";
168
+ readonly properties: {
169
+ readonly type: {
170
+ readonly type: "string";
171
+ readonly enum: readonly ["text"];
172
+ };
173
+ readonly text: {
174
+ readonly type: "string";
175
+ };
176
+ };
177
+ readonly required: readonly ["type", "text"];
178
+ readonly additionalProperties: false;
179
+ }, {
180
+ readonly type: "object";
181
+ readonly properties: {
182
+ readonly type: {
183
+ readonly type: "string";
184
+ readonly enum: readonly ["image"];
185
+ };
186
+ readonly mimeType: {
187
+ readonly type: "string";
188
+ };
189
+ readonly data: {
190
+ readonly type: "string";
191
+ };
192
+ };
193
+ readonly required: readonly ["type", "mimeType", "data"];
194
+ readonly additionalProperties: false;
195
+ }, {
196
+ readonly type: "object";
197
+ readonly properties: {
198
+ readonly type: {
199
+ readonly type: "string";
200
+ readonly enum: readonly ["tool_use"];
201
+ };
202
+ readonly id: {
203
+ readonly type: "string";
204
+ };
205
+ readonly name: {
206
+ readonly type: "string";
207
+ };
208
+ readonly input: {
209
+ readonly type: "object";
210
+ readonly additionalProperties: true;
211
+ };
212
+ };
213
+ readonly required: readonly ["type", "id", "name", "input"];
214
+ readonly additionalProperties: false;
215
+ }];
216
+ };
217
+ };
218
+ readonly is_error: {
219
+ readonly type: "boolean";
220
+ };
221
+ };
222
+ readonly required: readonly ["type", "tool_use_id", "content"];
223
+ readonly additionalProperties: false;
224
+ }];
225
+ readonly title: "ContentBlock";
226
+ readonly description: "A single content block within a chat message";
227
+ };
228
+ }];
229
+ readonly title: "Prompt";
230
+ readonly description: "The first user message to start the conversation";
231
+ };
232
+ readonly messages: {
233
+ readonly type: "array";
234
+ readonly title: "Messages";
235
+ readonly description: "Conversation history (managed internally by the chat loop; not a user-facing input)";
236
+ readonly items: {
237
+ readonly type: "object";
238
+ readonly properties: {
239
+ readonly role: {
240
+ readonly type: "string";
241
+ readonly enum: readonly ["user", "assistant", "tool", "system"];
242
+ };
243
+ readonly content: {
244
+ readonly type: "array";
245
+ readonly items: {
246
+ readonly oneOf: readonly [{
247
+ readonly type: "object";
248
+ readonly properties: {
249
+ readonly type: {
250
+ readonly type: "string";
251
+ readonly enum: readonly ["text"];
252
+ };
253
+ readonly text: {
254
+ readonly type: "string";
255
+ };
256
+ };
257
+ readonly required: readonly ["type", "text"];
258
+ readonly additionalProperties: false;
259
+ }, {
260
+ readonly type: "object";
261
+ readonly properties: {
262
+ readonly type: {
263
+ readonly type: "string";
264
+ readonly enum: readonly ["image"];
265
+ };
266
+ readonly mimeType: {
267
+ readonly type: "string";
268
+ };
269
+ readonly data: {
270
+ readonly type: "string";
271
+ };
272
+ };
273
+ readonly required: readonly ["type", "mimeType", "data"];
274
+ readonly additionalProperties: false;
275
+ }, {
276
+ readonly type: "object";
277
+ readonly properties: {
278
+ readonly type: {
279
+ readonly type: "string";
280
+ readonly enum: readonly ["tool_use"];
281
+ };
282
+ readonly id: {
283
+ readonly type: "string";
284
+ };
285
+ readonly name: {
286
+ readonly type: "string";
287
+ };
288
+ readonly input: {
289
+ readonly type: "object";
290
+ readonly additionalProperties: true;
291
+ };
292
+ };
293
+ readonly required: readonly ["type", "id", "name", "input"];
294
+ readonly additionalProperties: false;
295
+ }, {
296
+ readonly type: "object";
297
+ readonly properties: {
298
+ readonly type: {
299
+ readonly type: "string";
300
+ readonly enum: readonly ["tool_result"];
301
+ };
302
+ readonly tool_use_id: {
303
+ readonly type: "string";
304
+ };
305
+ readonly content: {
306
+ readonly type: "array";
307
+ readonly items: {
308
+ readonly oneOf: readonly [{
309
+ readonly type: "object";
310
+ readonly properties: {
311
+ readonly type: {
312
+ readonly type: "string";
313
+ readonly enum: readonly ["text"];
314
+ };
315
+ readonly text: {
316
+ readonly type: "string";
317
+ };
318
+ };
319
+ readonly required: readonly ["type", "text"];
320
+ readonly additionalProperties: false;
321
+ }, {
322
+ readonly type: "object";
323
+ readonly properties: {
324
+ readonly type: {
325
+ readonly type: "string";
326
+ readonly enum: readonly ["image"];
327
+ };
328
+ readonly mimeType: {
329
+ readonly type: "string";
330
+ };
331
+ readonly data: {
332
+ readonly type: "string";
333
+ };
334
+ };
335
+ readonly required: readonly ["type", "mimeType", "data"];
336
+ readonly additionalProperties: false;
337
+ }, {
338
+ readonly type: "object";
339
+ readonly properties: {
340
+ readonly type: {
341
+ readonly type: "string";
342
+ readonly enum: readonly ["tool_use"];
343
+ };
344
+ readonly id: {
345
+ readonly type: "string";
346
+ };
347
+ readonly name: {
348
+ readonly type: "string";
349
+ };
350
+ readonly input: {
351
+ readonly type: "object";
352
+ readonly additionalProperties: true;
353
+ };
354
+ };
355
+ readonly required: readonly ["type", "id", "name", "input"];
356
+ readonly additionalProperties: false;
357
+ }];
358
+ };
359
+ };
360
+ readonly is_error: {
361
+ readonly type: "boolean";
362
+ };
363
+ };
364
+ readonly required: readonly ["type", "tool_use_id", "content"];
365
+ readonly additionalProperties: false;
366
+ }];
367
+ readonly title: "ContentBlock";
368
+ readonly description: "A single content block within a chat message";
369
+ };
370
+ };
371
+ };
372
+ readonly required: readonly ["role", "content"];
373
+ readonly additionalProperties: false;
374
+ readonly title: "ChatMessage";
375
+ readonly description: "A single chat message with role and structured content blocks";
376
+ };
377
+ readonly "x-ui-hidden": true;
378
+ };
379
+ readonly systemPrompt: {
380
+ readonly type: "string";
381
+ readonly title: "System Prompt";
382
+ readonly description: "Optional system instructions for the model";
383
+ };
384
+ readonly maxTokens: {
385
+ readonly type: "number";
386
+ readonly title: "Max Tokens";
387
+ readonly description: "Per-turn token limit";
388
+ readonly minimum: 1;
389
+ readonly "x-ui-group": "Configuration";
390
+ };
391
+ readonly temperature: {
392
+ readonly type: "number";
393
+ readonly title: "Temperature";
394
+ readonly description: "Sampling temperature";
395
+ readonly minimum: 0;
396
+ readonly maximum: 2;
397
+ readonly "x-ui-group": "Configuration";
398
+ };
399
+ readonly maxIterations: {
400
+ readonly type: "number";
401
+ readonly title: "Max Iterations";
402
+ readonly description: "Safety cap on conversation turns";
403
+ readonly minimum: 1;
404
+ readonly default: 100;
405
+ readonly "x-ui-group": "Configuration";
406
+ };
407
+ readonly knowledgeBaseIds: {
408
+ readonly type: "array";
409
+ readonly title: "Knowledge Base IDs";
410
+ readonly description: "Knowledge bases to retrieve from on each turn";
411
+ readonly items: {
412
+ readonly type: "string";
413
+ };
414
+ };
415
+ readonly topKPerKb: {
416
+ readonly type: "number";
417
+ readonly title: "Top K per KB";
418
+ readonly description: "Top results per KB before threshold filtering";
419
+ readonly minimum: 1;
420
+ readonly default: 4;
421
+ readonly "x-ui-group": "Configuration";
422
+ };
423
+ readonly minScore: {
424
+ readonly type: "number";
425
+ readonly title: "Min score";
426
+ readonly description: "Score floor for a chunk to count as a useful match";
427
+ readonly minimum: 0;
428
+ readonly maximum: 1;
429
+ readonly default: 0.3;
430
+ readonly "x-ui-group": "Configuration";
431
+ };
432
+ readonly maxReferences: {
433
+ readonly type: "number";
434
+ readonly title: "Max references";
435
+ readonly description: "Cap on the chunk references emitted per turn";
436
+ readonly minimum: 1;
437
+ readonly default: 6;
438
+ readonly "x-ui-group": "Configuration";
439
+ };
440
+ readonly noMatchReply: {
441
+ readonly type: "string";
442
+ readonly title: "No-match reply";
443
+ readonly description: "When set and zero chunks match: emit this verbatim and skip the provider";
444
+ readonly "x-ui-group": "Configuration";
445
+ };
446
+ readonly noMatchReferences: {
447
+ readonly type: "array";
448
+ readonly title: "No-match references";
449
+ readonly description: "When set and zero chunks match: emit these verbatim on the references port";
450
+ readonly items: {
451
+ readonly type: "object";
452
+ readonly properties: {
453
+ readonly kbId: {
454
+ readonly type: "string";
455
+ };
456
+ readonly kbLabel: {
457
+ readonly type: "string";
458
+ };
459
+ readonly title: {
460
+ readonly type: "string";
461
+ };
462
+ readonly url: {
463
+ readonly type: "string";
464
+ };
465
+ readonly snippet: {
466
+ readonly type: "string";
467
+ };
468
+ readonly score: {
469
+ readonly type: "number";
470
+ };
471
+ readonly index: {
472
+ readonly type: "number";
473
+ };
474
+ };
475
+ readonly required: readonly ["kbId", "kbLabel", "title", "snippet", "score", "index"];
476
+ };
477
+ readonly "x-ui-group": "Configuration";
478
+ };
479
+ readonly responseFormat: {
480
+ readonly type: "string";
481
+ readonly enum: readonly ["text", "markdown"];
482
+ readonly default: "text";
483
+ readonly title: "Response format";
484
+ readonly description: string;
485
+ readonly "x-ui-group": "Configuration";
486
+ };
487
+ };
488
+ readonly required: readonly ["model", "prompt", "knowledgeBaseIds"];
489
+ readonly additionalProperties: false;
490
+ };
491
+ export declare const AiChatWithKbOutputSchema: {
492
+ readonly type: "object";
493
+ readonly properties: {
494
+ readonly text: {
495
+ readonly type: "string";
496
+ readonly title: "Text";
497
+ readonly description: "Full streamed transcript across all assistant turns";
498
+ readonly "x-stream": "append";
499
+ };
500
+ readonly messages: {
501
+ readonly type: "array";
502
+ readonly title: "Messages";
503
+ readonly description: "Full conversation history";
504
+ readonly items: {
505
+ readonly type: "object";
506
+ readonly properties: {
507
+ readonly role: {
508
+ readonly type: "string";
509
+ readonly enum: readonly ["user", "assistant", "tool", "system"];
510
+ };
511
+ readonly content: {
512
+ readonly type: "array";
513
+ readonly items: {
514
+ readonly oneOf: readonly [{
515
+ readonly type: "object";
516
+ readonly properties: {
517
+ readonly type: {
518
+ readonly type: "string";
519
+ readonly enum: readonly ["text"];
520
+ };
521
+ readonly text: {
522
+ readonly type: "string";
523
+ };
524
+ };
525
+ readonly required: readonly ["type", "text"];
526
+ readonly additionalProperties: false;
527
+ }, {
528
+ readonly type: "object";
529
+ readonly properties: {
530
+ readonly type: {
531
+ readonly type: "string";
532
+ readonly enum: readonly ["image"];
533
+ };
534
+ readonly mimeType: {
535
+ readonly type: "string";
536
+ };
537
+ readonly data: {
538
+ readonly type: "string";
539
+ };
540
+ };
541
+ readonly required: readonly ["type", "mimeType", "data"];
542
+ readonly additionalProperties: false;
543
+ }, {
544
+ readonly type: "object";
545
+ readonly properties: {
546
+ readonly type: {
547
+ readonly type: "string";
548
+ readonly enum: readonly ["tool_use"];
549
+ };
550
+ readonly id: {
551
+ readonly type: "string";
552
+ };
553
+ readonly name: {
554
+ readonly type: "string";
555
+ };
556
+ readonly input: {
557
+ readonly type: "object";
558
+ readonly additionalProperties: true;
559
+ };
560
+ };
561
+ readonly required: readonly ["type", "id", "name", "input"];
562
+ readonly additionalProperties: false;
563
+ }, {
564
+ readonly type: "object";
565
+ readonly properties: {
566
+ readonly type: {
567
+ readonly type: "string";
568
+ readonly enum: readonly ["tool_result"];
569
+ };
570
+ readonly tool_use_id: {
571
+ readonly type: "string";
572
+ };
573
+ readonly content: {
574
+ readonly type: "array";
575
+ readonly items: {
576
+ readonly oneOf: readonly [{
577
+ readonly type: "object";
578
+ readonly properties: {
579
+ readonly type: {
580
+ readonly type: "string";
581
+ readonly enum: readonly ["text"];
582
+ };
583
+ readonly text: {
584
+ readonly type: "string";
585
+ };
586
+ };
587
+ readonly required: readonly ["type", "text"];
588
+ readonly additionalProperties: false;
589
+ }, {
590
+ readonly type: "object";
591
+ readonly properties: {
592
+ readonly type: {
593
+ readonly type: "string";
594
+ readonly enum: readonly ["image"];
595
+ };
596
+ readonly mimeType: {
597
+ readonly type: "string";
598
+ };
599
+ readonly data: {
600
+ readonly type: "string";
601
+ };
602
+ };
603
+ readonly required: readonly ["type", "mimeType", "data"];
604
+ readonly additionalProperties: false;
605
+ }, {
606
+ readonly type: "object";
607
+ readonly properties: {
608
+ readonly type: {
609
+ readonly type: "string";
610
+ readonly enum: readonly ["tool_use"];
611
+ };
612
+ readonly id: {
613
+ readonly type: "string";
614
+ };
615
+ readonly name: {
616
+ readonly type: "string";
617
+ };
618
+ readonly input: {
619
+ readonly type: "object";
620
+ readonly additionalProperties: true;
621
+ };
622
+ };
623
+ readonly required: readonly ["type", "id", "name", "input"];
624
+ readonly additionalProperties: false;
625
+ }];
626
+ };
627
+ };
628
+ readonly is_error: {
629
+ readonly type: "boolean";
630
+ };
631
+ };
632
+ readonly required: readonly ["type", "tool_use_id", "content"];
633
+ readonly additionalProperties: false;
634
+ }];
635
+ readonly title: "ContentBlock";
636
+ readonly description: "A single content block within a chat message";
637
+ };
638
+ };
639
+ };
640
+ readonly required: readonly ["role", "content"];
641
+ readonly additionalProperties: false;
642
+ readonly title: "ChatMessage";
643
+ readonly description: "A single chat message with role and structured content blocks";
644
+ };
645
+ readonly "x-stream": "object";
646
+ };
647
+ readonly iterations: {
648
+ readonly type: "number";
649
+ readonly title: "Iterations";
650
+ readonly description: "Number of completed turns";
651
+ };
652
+ readonly references: {
653
+ readonly type: "array";
654
+ readonly title: "References";
655
+ readonly description: "Per-chunk citation references emitted each turn (one entry per surviving chunk; not deduped)";
656
+ readonly items: {
657
+ readonly type: "object";
658
+ readonly properties: {
659
+ readonly kbId: {
660
+ readonly type: "string";
661
+ };
662
+ readonly kbLabel: {
663
+ readonly type: "string";
664
+ };
665
+ readonly title: {
666
+ readonly type: "string";
667
+ };
668
+ readonly url: {
669
+ readonly type: "string";
670
+ };
671
+ readonly snippet: {
672
+ readonly type: "string";
673
+ };
674
+ readonly score: {
675
+ readonly type: "number";
676
+ };
677
+ readonly index: {
678
+ readonly type: "number";
679
+ };
680
+ };
681
+ readonly required: readonly ["kbId", "kbLabel", "title", "snippet", "score", "index"];
682
+ };
683
+ readonly "x-stream": "object";
684
+ };
685
+ };
686
+ readonly required: readonly ["text", "messages", "iterations", "references"];
687
+ readonly additionalProperties: false;
688
+ };
689
+ export type AiChatWithKbTaskInput = Omit<FromSchema<typeof AiChatWithKbInputSchema>, "messages" | "noMatchReferences"> & {
690
+ readonly messages?: ReadonlyArray<ChatMessage>;
691
+ readonly noMatchReferences?: ReadonlyArray<ChatChunkReference>;
692
+ };
693
+ export type AiChatWithKbTaskOutput = Omit<FromSchema<typeof AiChatWithKbOutputSchema>, "references"> & {
694
+ readonly references: readonly ChatChunkReference[];
695
+ };
696
+ export declare class AiChatWithKbTask extends StreamingAiTask<AiChatWithKbTaskInput, AiChatWithKbTaskOutput> {
697
+ static type: string;
698
+ protected static readonly streamingPhaseLabel = "Replying";
699
+ static category: string;
700
+ static title: string;
701
+ static description: string;
702
+ static cacheable: boolean;
703
+ static configSchema(): DataPortSchema;
704
+ static inputSchema(): DataPortSchema;
705
+ static outputSchema(): DataPortSchema;
706
+ private _sessionId;
707
+ protected getJobInput(input: AiChatWithKbTaskInput): Promise<AiJobInput<AiChatWithKbTaskInput>>;
708
+ executeStream(input: AiChatWithKbTaskInput, context: IExecuteContext): AsyncIterable<StreamEvent<AiChatWithKbTaskOutput>>;
709
+ }
710
+ //# sourceMappingURL=AiChatWithKbTask.d.ts.map