@workglow/ai 0.2.6 → 0.2.8

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.
Files changed (96) hide show
  1. package/dist/browser.js +679 -1036
  2. package/dist/browser.js.map +14 -16
  3. package/dist/bun.js +679 -1036
  4. package/dist/bun.js.map +14 -16
  5. package/dist/job/AiJob.d.ts +2 -0
  6. package/dist/job/AiJob.d.ts.map +1 -1
  7. package/dist/model/ModelRepository.d.ts +2 -0
  8. package/dist/model/ModelRepository.d.ts.map +1 -1
  9. package/dist/model/ModelSchema.d.ts +16 -0
  10. package/dist/model/ModelSchema.d.ts.map +1 -1
  11. package/dist/node.js +679 -1036
  12. package/dist/node.js.map +14 -16
  13. package/dist/provider/AiProvider.d.ts +21 -0
  14. package/dist/provider/AiProvider.d.ts.map +1 -1
  15. package/dist/provider/AiProviderRegistry.d.ts +18 -2
  16. package/dist/provider/AiProviderRegistry.d.ts.map +1 -1
  17. package/dist/task/BackgroundRemovalTask.d.ts +8 -0
  18. package/dist/task/BackgroundRemovalTask.d.ts.map +1 -1
  19. package/dist/task/ChunkRetrievalTask.d.ts +8 -0
  20. package/dist/task/ChunkRetrievalTask.d.ts.map +1 -1
  21. package/dist/task/ContextBuilderTask.d.ts +8 -0
  22. package/dist/task/ContextBuilderTask.d.ts.map +1 -1
  23. package/dist/task/CountTokensTask.d.ts +8 -0
  24. package/dist/task/CountTokensTask.d.ts.map +1 -1
  25. package/dist/task/DocumentEnricherTask.d.ts +16 -0
  26. package/dist/task/DocumentEnricherTask.d.ts.map +1 -1
  27. package/dist/task/DownloadModelTask.d.ts +18 -0
  28. package/dist/task/DownloadModelTask.d.ts.map +1 -1
  29. package/dist/task/FaceDetectorTask.d.ts +8 -0
  30. package/dist/task/FaceDetectorTask.d.ts.map +1 -1
  31. package/dist/task/FaceLandmarkerTask.d.ts +8 -0
  32. package/dist/task/FaceLandmarkerTask.d.ts.map +1 -1
  33. package/dist/task/GestureRecognizerTask.d.ts +8 -0
  34. package/dist/task/GestureRecognizerTask.d.ts.map +1 -1
  35. package/dist/task/HandLandmarkerTask.d.ts +8 -0
  36. package/dist/task/HandLandmarkerTask.d.ts.map +1 -1
  37. package/dist/task/HierarchicalChunkerTask.d.ts +8 -0
  38. package/dist/task/HierarchicalChunkerTask.d.ts.map +1 -1
  39. package/dist/task/ImageClassificationTask.d.ts +8 -0
  40. package/dist/task/ImageClassificationTask.d.ts.map +1 -1
  41. package/dist/task/ImageEmbeddingTask.d.ts +8 -0
  42. package/dist/task/ImageEmbeddingTask.d.ts.map +1 -1
  43. package/dist/task/ImageSegmentationTask.d.ts +8 -0
  44. package/dist/task/ImageSegmentationTask.d.ts.map +1 -1
  45. package/dist/task/ImageToTextTask.d.ts +8 -0
  46. package/dist/task/ImageToTextTask.d.ts.map +1 -1
  47. package/dist/task/KbToDocumentsTask.d.ts +98 -0
  48. package/dist/task/KbToDocumentsTask.d.ts.map +1 -0
  49. package/dist/task/ModelInfoTask.d.ts +29 -1
  50. package/dist/task/ModelInfoTask.d.ts.map +1 -1
  51. package/dist/task/ObjectDetectionTask.d.ts +8 -0
  52. package/dist/task/ObjectDetectionTask.d.ts.map +1 -1
  53. package/dist/task/PoseLandmarkerTask.d.ts +8 -0
  54. package/dist/task/PoseLandmarkerTask.d.ts.map +1 -1
  55. package/dist/task/RerankerTask.d.ts +8 -0
  56. package/dist/task/RerankerTask.d.ts.map +1 -1
  57. package/dist/task/StructuredGenerationTask.d.ts +8 -0
  58. package/dist/task/StructuredGenerationTask.d.ts.map +1 -1
  59. package/dist/task/TextClassificationTask.d.ts +8 -0
  60. package/dist/task/TextClassificationTask.d.ts.map +1 -1
  61. package/dist/task/TextEmbeddingTask.d.ts +8 -0
  62. package/dist/task/TextEmbeddingTask.d.ts.map +1 -1
  63. package/dist/task/TextFillMaskTask.d.ts +8 -0
  64. package/dist/task/TextFillMaskTask.d.ts.map +1 -1
  65. package/dist/task/TextGenerationTask.d.ts +8 -0
  66. package/dist/task/TextGenerationTask.d.ts.map +1 -1
  67. package/dist/task/TextLanguageDetectionTask.d.ts +8 -0
  68. package/dist/task/TextLanguageDetectionTask.d.ts.map +1 -1
  69. package/dist/task/TextNamedEntityRecognitionTask.d.ts +8 -0
  70. package/dist/task/TextNamedEntityRecognitionTask.d.ts.map +1 -1
  71. package/dist/task/TextQuestionAnswerTask.d.ts +8 -0
  72. package/dist/task/TextQuestionAnswerTask.d.ts.map +1 -1
  73. package/dist/task/TextRewriterTask.d.ts +8 -0
  74. package/dist/task/TextRewriterTask.d.ts.map +1 -1
  75. package/dist/task/TextSummaryTask.d.ts +8 -0
  76. package/dist/task/TextSummaryTask.d.ts.map +1 -1
  77. package/dist/task/TextTranslationTask.d.ts +8 -0
  78. package/dist/task/TextTranslationTask.d.ts.map +1 -1
  79. package/dist/task/ToolCallingTask.d.ts +23 -2
  80. package/dist/task/ToolCallingTask.d.ts.map +1 -1
  81. package/dist/task/UnloadModelTask.d.ts +18 -0
  82. package/dist/task/UnloadModelTask.d.ts.map +1 -1
  83. package/dist/task/base/AiTask.d.ts.map +1 -1
  84. package/dist/task/base/AiTaskSchemas.d.ts +16 -0
  85. package/dist/task/base/AiTaskSchemas.d.ts.map +1 -1
  86. package/dist/task/index.d.ts +3 -5
  87. package/dist/task/index.d.ts.map +1 -1
  88. package/dist/worker.js +42 -9
  89. package/dist/worker.js.map +6 -6
  90. package/package.json +11 -11
  91. package/dist/task/AgentTask.d.ts +0 -525
  92. package/dist/task/AgentTask.d.ts.map +0 -1
  93. package/dist/task/AgentTypes.d.ts +0 -183
  94. package/dist/task/AgentTypes.d.ts.map +0 -1
  95. package/dist/task/AgentUtils.d.ts +0 -55
  96. package/dist/task/AgentUtils.d.ts.map +0 -1
package/dist/bun.js CHANGED
@@ -56,6 +56,19 @@ class AiProviderRegistry {
56
56
  }
57
57
  return this.defaultStrategy;
58
58
  }
59
+ createSession(providerName, model) {
60
+ const provider = this.providers.get(providerName);
61
+ if (!provider) {
62
+ throw new Error(`No provider found for "${providerName}". Register the provider before creating sessions.`);
63
+ }
64
+ return provider.createSession(model);
65
+ }
66
+ async disposeSession(providerName, sessionId) {
67
+ const provider = this.providers.get(providerName);
68
+ if (provider) {
69
+ await provider.disposeSession(sessionId);
70
+ }
71
+ }
59
72
  getProviderIdsForTask(taskType) {
60
73
  const taskMap = this.runFnRegistry.get(taskType);
61
74
  if (!taskMap)
@@ -69,9 +82,9 @@ class AiProviderRegistry {
69
82
  this.runFnRegistry.get(taskType).set(modelProvider, runFn);
70
83
  }
71
84
  registerAsWorkerRunFn(modelProvider, taskType) {
72
- const workerFn = async (input, model, update_progress, signal, outputSchema) => {
85
+ const workerFn = async (input, model, update_progress, signal, outputSchema, sessionId) => {
73
86
  const workerManager = globalServiceRegistry.get(WORKER_MANAGER);
74
- const result = await workerManager.callWorkerFunction(modelProvider, taskType, [input, model, outputSchema], {
87
+ const result = await workerManager.callWorkerFunction(modelProvider, taskType, [input, model, outputSchema, sessionId], {
75
88
  signal,
76
89
  onProgress: update_progress
77
90
  });
@@ -86,9 +99,9 @@ class AiProviderRegistry {
86
99
  this.streamFnRegistry.get(taskType).set(modelProvider, streamFn);
87
100
  }
88
101
  registerAsWorkerStreamFn(modelProvider, taskType) {
89
- const streamFn = async function* (input, model, signal, outputSchema) {
102
+ const streamFn = async function* (input, model, signal, outputSchema, sessionId) {
90
103
  const workerManager = globalServiceRegistry.get(WORKER_MANAGER);
91
- yield* workerManager.callWorkerStreamFunction(modelProvider, taskType, [input, model, outputSchema], { signal });
104
+ yield* workerManager.callWorkerStreamFunction(modelProvider, taskType, [input, model, outputSchema, sessionId], { signal });
92
105
  };
93
106
  this.registerStreamFn(modelProvider, taskType, streamFn);
94
107
  }
@@ -216,7 +229,7 @@ class AiJob extends Job {
216
229
  const timeoutMs = resolveAiJobTimeoutMs(input.aiProvider, input.timeoutMs);
217
230
  const timeoutSignal = AbortSignal.timeout(timeoutMs);
218
231
  const combinedSignal = AbortSignal.any([context.signal, timeoutSignal]);
219
- return await fn(input.taskInput, model, context.updateProgress, combinedSignal, input.outputSchema);
232
+ return await fn(input.taskInput, model, context.updateProgress, combinedSignal, input.outputSchema, input.sessionId);
220
233
  };
221
234
  const runFnPromise = runFn();
222
235
  return await Promise.race([runFnPromise, abortPromise]);
@@ -244,7 +257,7 @@ class AiJob extends Job {
244
257
  const timeoutSignal = AbortSignal.timeout(timeoutMs);
245
258
  const combinedSignal = AbortSignal.any([context.signal, timeoutSignal]);
246
259
  try {
247
- for await (const event of streamFn(input.taskInput, model, combinedSignal, input.outputSchema)) {
260
+ for await (const event of streamFn(input.taskInput, model, combinedSignal, input.outputSchema, input.sessionId)) {
248
261
  if (event.type === "finish") {
249
262
  lastFinishData = event.data;
250
263
  }
@@ -455,7 +468,15 @@ var ModelConfigSchema = {
455
468
  provider_config: {
456
469
  type: "object",
457
470
  properties: {
458
- credential_key: { type: "string", format: "credential", "x-ui-hidden": true }
471
+ credential_key: { type: "string", format: "credential", "x-ui-hidden": true },
472
+ native_dimensions: {
473
+ type: "integer",
474
+ description: "Native output vector dimensions for embedding models"
475
+ },
476
+ mrl: {
477
+ type: "boolean",
478
+ description: "Whether the model supports Matryoshka Representation Learning"
479
+ }
459
480
  },
460
481
  additionalProperties: true,
461
482
  default: {}
@@ -649,6 +670,7 @@ registerInputCompactor("model", async (value, _format, registry) => {
649
670
 
650
671
  // src/provider/AiProvider.ts
651
672
  import { globalServiceRegistry as globalServiceRegistry3, WORKER_MANAGER as WORKER_MANAGER2 } from "@workglow/util/worker";
673
+ var DEFAULT_AI_PROVIDER_WORKER_IDLE_TIMEOUT_MS = 15 * 60 * 1000;
652
674
  function resolveAiProviderGpuQueueConcurrency(concurrency) {
653
675
  if (concurrency === undefined) {
654
676
  return 1;
@@ -696,7 +718,13 @@ class AiProvider {
696
718
  const registry = getAiProviderRegistry();
697
719
  if (!isInline && options.worker) {
698
720
  const workerManager = globalServiceRegistry3.get(WORKER_MANAGER2);
699
- workerManager.registerWorker(this.name, options.worker);
721
+ if (typeof options.worker === "function") {
722
+ workerManager.registerWorker(this.name, options.worker, {
723
+ idleTimeoutMs: options.workerIdleTimeoutMs ?? DEFAULT_AI_PROVIDER_WORKER_IDLE_TIMEOUT_MS
724
+ });
725
+ } else {
726
+ workerManager.registerWorker(this.name, options.worker);
727
+ }
700
728
  for (const taskType of this.taskTypes) {
701
729
  registry.registerAsWorkerRunFn(this.name, taskType);
702
730
  registry.registerAsWorkerStreamFn(this.name, taskType);
@@ -745,6 +773,10 @@ class AiProvider {
745
773
  }
746
774
  async onInitialize(_options) {}
747
775
  async dispose() {}
776
+ createSession(_model) {
777
+ return crypto.randomUUID();
778
+ }
779
+ async disposeSession(_sessionId) {}
748
780
  async afterRegister(_options) {}
749
781
  }
750
782
 
@@ -768,74 +800,8 @@ class QueuedAiProvider extends AiProvider {
768
800
  // src/task/index.ts
769
801
  import { TaskRegistry } from "@workglow/task-graph";
770
802
 
771
- // src/task/AgentTask.ts
772
- import { CreateWorkflow as CreateWorkflow2, Task as Task2, Workflow as Workflow2 } from "@workglow/task-graph";
773
- import { getLogger as getLogger4 } from "@workglow/util";
774
-
775
- // src/task/AgentTypes.ts
776
- import { parseDataUri } from "@workglow/util/media";
777
- function imageBlock(mimeType, data) {
778
- return { type: "image", mimeType, data };
779
- }
780
- function audioBlock(mimeType, data) {
781
- return { type: "audio", mimeType, data };
782
- }
783
- function imageBlockFromDataUri(dataUri) {
784
- const { mimeType, base64 } = parseDataUri(dataUri);
785
- return { type: "image", mimeType, data: base64 };
786
- }
787
- function audioBlockFromDataUri(dataUri) {
788
- const { mimeType, base64 } = parseDataUri(dataUri);
789
- return { type: "audio", mimeType, data: base64 };
790
- }
791
- function userMessage(prompt) {
792
- return { role: "user", content: prompt };
793
- }
794
- function assistantMessage(text, toolCalls) {
795
- const content = [];
796
- if (text) {
797
- content.push({ type: "text", text });
798
- }
799
- if (toolCalls) {
800
- for (const tc of toolCalls) {
801
- content.push({
802
- type: "tool_use",
803
- id: tc.id,
804
- name: tc.name,
805
- input: tc.input
806
- });
807
- }
808
- }
809
- return { role: "assistant", content };
810
- }
811
- function toolMessage(results) {
812
- return {
813
- role: "tool",
814
- content: results.map((r) => {
815
- const jsonText = JSON.stringify(r.output);
816
- const content = r.mediaContent && r.mediaContent.length > 0 ? [{ type: "text", text: jsonText }, ...r.mediaContent] : jsonText;
817
- return {
818
- type: "tool_result",
819
- tool_use_id: r.toolCallId,
820
- content,
821
- is_error: r.isError || undefined
822
- };
823
- })
824
- };
825
- }
826
- function toolSourceDefinitions(sources) {
827
- return sources.map((s) => s.definition);
828
- }
829
- function findToolSource(sources, name) {
830
- return sources.find((s) => s.definition.name === name);
831
- }
832
-
833
- // src/task/AgentUtils.ts
834
- import { getTaskConstructors as getTaskConstructors2, TaskAbortedError } from "@workglow/task-graph";
835
- import { getLogger as getLogger3 } from "@workglow/util";
836
-
837
- // src/task/ToolCallingTask.ts
838
- import { CreateWorkflow, getTaskConstructors, Workflow } from "@workglow/task-graph";
803
+ // src/task/BackgroundRemovalTask.ts
804
+ import { CreateWorkflow, Workflow } from "@workglow/task-graph";
839
805
 
840
806
  // src/task/base/AiTaskSchemas.ts
841
807
  var TypeLanguage = (annotations = {}) => ({
@@ -994,8 +960,8 @@ var TypeCategory = {
994
960
  description: "Classification category with label and score"
995
961
  };
996
962
 
997
- // src/task/base/StreamingAiTask.ts
998
- import { getStreamingPorts, TaskConfigurationError as TaskConfigurationError3 } from "@workglow/task-graph";
963
+ // src/task/base/AiVisionTask.ts
964
+ import { convertImageDataToUseableForm } from "@workglow/util/media";
999
965
 
1000
966
  // src/task/base/AiTask.ts
1001
967
  import {
@@ -1050,6 +1016,18 @@ class AiTask extends Task {
1050
1016
  const jobInput = await this.getJobInput(input);
1051
1017
  const strategy = getAiProviderRegistry().getStrategy(model);
1052
1018
  const output = await strategy.execute(jobInput, executeContext, this.runConfig.runnerId);
1019
+ if (executeContext.resourceScope) {
1020
+ const registry = getAiProviderRegistry();
1021
+ const provider = registry.getProvider(model.provider);
1022
+ const unloadFn = provider?.getRunFn("UnloadModelTask");
1023
+ if (unloadFn) {
1024
+ const modelPath = model.provider_config?.model_path ?? model.model;
1025
+ const resourceKey = `ai:${model.provider}:${modelPath}`;
1026
+ executeContext.resourceScope.register(resourceKey, async () => {
1027
+ await unloadFn({ model }, model, () => {}, AbortSignal.timeout(30000));
1028
+ });
1029
+ }
1030
+ }
1053
1031
  return output;
1054
1032
  }
1055
1033
  async getJobInput(input) {
@@ -1073,6 +1051,10 @@ class AiTask extends Task {
1073
1051
  jobInput.outputSchema = taskOutputSchema;
1074
1052
  }
1075
1053
  }
1054
+ const sessionId = input.sessionId;
1055
+ if (sessionId) {
1056
+ jobInput.sessionId = sessionId;
1057
+ }
1076
1058
  return jobInput;
1077
1059
  }
1078
1060
  async createJob(input, queueName) {
@@ -1088,786 +1070,84 @@ class AiTask extends Task {
1088
1070
  });
1089
1071
  return job;
1090
1072
  }
1091
- async getDefaultQueueName(input) {
1092
- const model = input.model;
1093
- return model?.provider;
1094
- }
1095
- async executeReactive(input, output, context) {
1096
- const model = input.model;
1097
- if (model && typeof model === "object" && model.provider) {
1098
- const taskType = this.constructor.runtype ?? this.constructor.type;
1099
- const reactiveFn = getAiProviderRegistry().getReactiveRunFn(model.provider, taskType);
1100
- if (reactiveFn) {
1101
- return reactiveFn(input, output, model);
1102
- }
1103
- }
1104
- return super.executeReactive(input, output, context);
1105
- }
1106
- async validateInput(input) {
1107
- const inputSchema = this.inputSchema();
1108
- if (typeof inputSchema === "boolean") {
1109
- if (inputSchema === false) {
1110
- throw new TaskConfigurationError2(`AiTask: Input schema is 'false' and accepts no inputs`);
1111
- }
1112
- return true;
1113
- }
1114
- const modelTaskProperties = Object.entries(inputSchema.properties || {}).filter(([key, schema]) => schemaFormat(schema)?.startsWith("model:"));
1115
- for (const [key] of modelTaskProperties) {
1116
- const model = input[key];
1117
- if (typeof model === "object" && model !== null) {
1118
- const tasks = model.tasks;
1119
- if (Array.isArray(tasks) && tasks.length > 0 && !tasks.includes(this.type)) {
1120
- const modelId = model.model_id ?? "(inline config)";
1121
- throw new TaskConfigurationError2(`AiTask: Model "${modelId}" for '${key}' is not compatible with task '${this.type}'. ` + `Model supports: [${tasks.join(", ")}]`);
1122
- }
1123
- } else if (model !== undefined && model !== null) {
1124
- throw new TaskConfigurationError2(`AiTask: Invalid model for '${key}' - expected ModelConfig object but got ${typeof model}. ` + `Ensure the model ID was registered in the ModelRepository before running the task.`);
1125
- }
1126
- }
1127
- const modelPlainProperties = Object.entries(inputSchema.properties || {}).filter(([key, schema]) => schemaFormat(schema) === "model");
1128
- for (const [key] of modelPlainProperties) {
1129
- const model = input[key];
1130
- if (model !== undefined && model !== null && typeof model !== "object") {
1131
- throw new TaskConfigurationError2(`AiTask: Invalid model for '${key}' - expected ModelConfig object but got ${typeof model}. ` + `Ensure the model ID was registered in the ModelRepository before running the task.`);
1132
- }
1133
- }
1134
- return super.validateInput(input);
1135
- }
1136
- async narrowInput(input, registry) {
1137
- const inputSchema = this.inputSchema();
1138
- if (typeof inputSchema === "boolean") {
1139
- if (inputSchema === false) {
1140
- throw new TaskConfigurationError2(`AiTask: Input schema is 'false' and accepts no inputs`);
1141
- }
1142
- return input;
1143
- }
1144
- const modelTaskProperties = Object.entries(inputSchema.properties || {}).filter(([key, schema]) => schemaFormat(schema)?.startsWith("model:"));
1145
- if (modelTaskProperties.length > 0) {
1146
- const modelRepo = registry.get(MODEL_REPOSITORY);
1147
- const taskModels = await modelRepo.findModelsByTask(this.type) ?? [];
1148
- for (const [key] of modelTaskProperties) {
1149
- const requestedModel = input[key];
1150
- if (typeof requestedModel === "string") {
1151
- const found = taskModels?.find((m) => m.model_id === requestedModel);
1152
- if (!found) {
1153
- input[key] = undefined;
1154
- }
1155
- } else if (typeof requestedModel === "object" && requestedModel !== null) {
1156
- const model = requestedModel;
1157
- const tasks = model.tasks;
1158
- if (Array.isArray(tasks) && tasks.length > 0 && !tasks.includes(this.type)) {
1159
- input[key] = undefined;
1160
- }
1161
- }
1162
- }
1163
- }
1164
- return input;
1165
- }
1166
- }
1167
-
1168
- // src/task/base/StreamingAiTask.ts
1169
- class StreamingAiTask extends AiTask {
1170
- static type = "StreamingAiTask";
1171
- async* executeStream(input, context) {
1172
- const model = input.model;
1173
- if (!model || typeof model !== "object") {
1174
- throw new TaskConfigurationError3("StreamingAiTask: Model was not resolved to ModelConfig - this indicates a bug in the resolution system");
1175
- }
1176
- const jobInput = await this.getJobInput(input);
1177
- const strategy = getAiProviderRegistry().getStrategy(model);
1178
- const outSchema = this.outputSchema();
1179
- const ports = getStreamingPorts(outSchema);
1180
- let defaultPort = "text";
1181
- if (ports.length > 0) {
1182
- defaultPort = ports[0].port;
1183
- } else {
1184
- if (typeof outSchema === "object" && outSchema.properties) {
1185
- const firstProp = Object.keys(outSchema.properties)[0];
1186
- if (firstProp)
1187
- defaultPort = firstProp;
1188
- }
1189
- }
1190
- for await (const event of strategy.executeStream(jobInput, context, this.runConfig.runnerId)) {
1191
- if (event.type === "text-delta") {
1192
- yield { ...event, port: event.port ?? defaultPort };
1193
- } else if (event.type === "object-delta") {
1194
- yield { ...event, port: event.port ?? defaultPort };
1195
- } else {
1196
- yield event;
1197
- }
1198
- }
1199
- }
1200
- }
1201
-
1202
- // src/task/ToolCallingTask.ts
1203
- function taskTypesToTools(taskNames, registry) {
1204
- const constructors = getTaskConstructors(registry);
1205
- return taskNames.map((name) => {
1206
- const ctor = constructors.get(name);
1207
- if (!ctor) {
1208
- throw new Error(`taskTypesToTools: Unknown task type "${name}" \u2014 not found in task constructors registry (ServiceRegistry: ${registry ? "custom" : "default"})`);
1209
- }
1210
- const configSchema = "configSchema" in ctor && typeof ctor.configSchema === "function" ? ctor.configSchema() : undefined;
1211
- return {
1212
- name: ctor.type,
1213
- description: ctor.description ?? "",
1214
- inputSchema: ctor.inputSchema(),
1215
- outputSchema: ctor.outputSchema(),
1216
- ...configSchema ? { configSchema } : {},
1217
- taskType: name
1218
- };
1219
- });
1220
- }
1221
- var ToolDefinitionSchema = {
1222
- type: "object",
1223
- properties: {
1224
- name: {
1225
- type: "string",
1226
- title: "Name",
1227
- description: "The tool name"
1228
- },
1229
- description: {
1230
- type: "string",
1231
- title: "Description",
1232
- description: "A description of what the tool does"
1233
- },
1234
- inputSchema: {
1235
- type: "object",
1236
- title: "Input Schema",
1237
- description: "JSON Schema describing the tool's input parameters",
1238
- additionalProperties: true
1239
- },
1240
- outputSchema: {
1241
- type: "object",
1242
- title: "Output Schema",
1243
- description: "JSON Schema describing what the tool returns",
1244
- additionalProperties: true
1245
- },
1246
- configSchema: {
1247
- type: "object",
1248
- title: "Config Schema",
1249
- description: "JSON Schema describing the task's configuration options (not sent to the LLM)",
1250
- additionalProperties: true
1251
- },
1252
- config: {
1253
- type: "object",
1254
- title: "Config",
1255
- description: "Concrete configuration values for the backing task (not sent to the LLM)",
1256
- additionalProperties: true
1257
- }
1258
- },
1259
- required: ["name", "description", "inputSchema"],
1260
- additionalProperties: true
1261
- };
1262
- var ToolCallSchema = {
1263
- type: "object",
1264
- properties: {
1265
- id: {
1266
- type: "string",
1267
- title: "ID",
1268
- description: "Unique identifier for this tool call"
1269
- },
1270
- name: {
1271
- type: "string",
1272
- title: "Name",
1273
- description: "The name of the tool to invoke"
1274
- },
1275
- input: {
1276
- type: "object",
1277
- title: "Input",
1278
- description: "The input arguments for the tool call",
1279
- additionalProperties: true
1280
- }
1281
- },
1282
- required: ["id", "name", "input"],
1283
- additionalProperties: false
1284
- };
1285
- var modelSchema = TypeModel("model:ToolCallingTask");
1286
- var ToolCallingInputSchema = {
1287
- type: "object",
1288
- properties: {
1289
- model: modelSchema,
1290
- prompt: {
1291
- oneOf: [
1292
- { type: "string", title: "Prompt", description: "The prompt to send to the model" },
1293
- {
1294
- type: "array",
1295
- title: "Prompt",
1296
- description: "The prompt as an array of strings or content blocks",
1297
- items: {
1298
- oneOf: [
1299
- { type: "string" },
1300
- {
1301
- type: "object",
1302
- properties: {
1303
- type: { type: "string", enum: ["text", "image", "audio"] }
1304
- },
1305
- required: ["type"],
1306
- additionalProperties: true
1307
- }
1308
- ]
1309
- }
1310
- }
1311
- ],
1312
- title: "Prompt",
1313
- description: "The prompt to send to the model"
1314
- },
1315
- systemPrompt: {
1316
- type: "string",
1317
- title: "System Prompt",
1318
- description: "Optional system instructions for the model"
1319
- },
1320
- messages: {
1321
- type: "array",
1322
- title: "Messages",
1323
- description: "Full conversation history for multi-turn interactions. When provided, used instead of prompt to construct the messages array sent to the provider.",
1324
- items: {
1325
- type: "object",
1326
- properties: {
1327
- role: { type: "string", enum: ["user", "assistant", "tool"] },
1328
- content: {}
1329
- },
1330
- required: ["role", "content"],
1331
- additionalProperties: true
1332
- }
1333
- },
1334
- tools: {
1335
- type: "array",
1336
- format: "tasks",
1337
- title: "Tools",
1338
- description: "Tool definitions available for the model to call",
1339
- items: {
1340
- oneOf: [
1341
- { type: "string", format: "tasks", description: "Task type name" },
1342
- ToolDefinitionSchema
1343
- ]
1344
- }
1345
- },
1346
- toolChoice: {
1347
- type: "string",
1348
- title: "Tool Choice",
1349
- description: 'Controls tool selection: "auto" (model decides), "none" (no tools), "required" (must call a tool), or a specific tool name',
1350
- "x-ui-group": "Configuration"
1351
- },
1352
- maxTokens: {
1353
- type: "number",
1354
- title: "Max Tokens",
1355
- description: "The maximum number of tokens to generate",
1356
- minimum: 1,
1357
- "x-ui-group": "Configuration"
1358
- },
1359
- temperature: {
1360
- type: "number",
1361
- title: "Temperature",
1362
- description: "The temperature to use for sampling",
1363
- minimum: 0,
1364
- maximum: 2,
1365
- "x-ui-group": "Configuration"
1366
- }
1367
- },
1368
- required: ["model", "prompt", "tools"],
1369
- additionalProperties: false
1370
- };
1371
- var ToolCallingOutputSchema = {
1372
- type: "object",
1373
- properties: {
1374
- text: {
1375
- type: "string",
1376
- title: "Text",
1377
- description: "Any text content generated by the model",
1378
- "x-stream": "append"
1379
- },
1380
- toolCalls: {
1381
- type: "array",
1382
- items: ToolCallSchema,
1383
- title: "Tool Calls",
1384
- description: "Tool calls requested by the model",
1385
- "x-stream": "object"
1386
- }
1387
- },
1388
- required: ["text", "toolCalls"],
1389
- additionalProperties: false
1390
- };
1391
-
1392
- class ToolCallingTask extends StreamingAiTask {
1393
- static type = "ToolCallingTask";
1394
- static category = "AI Text Model";
1395
- static title = "Tool Calling";
1396
- static description = "Sends a prompt with tool definitions to a language model and returns text along with any tool calls the model requests";
1397
- static inputSchema() {
1398
- return ToolCallingInputSchema;
1399
- }
1400
- static outputSchema() {
1401
- return ToolCallingOutputSchema;
1402
- }
1403
- }
1404
- var toolCalling = (input, config) => {
1405
- return new ToolCallingTask(config).run(input);
1406
- };
1407
- Workflow.prototype.toolCalling = CreateWorkflow(ToolCallingTask);
1408
-
1409
- // src/task/AgentUtils.ts
1410
- function resolveToolConfig(toolName, config, taskConfigSchema) {
1411
- if (config && !taskConfigSchema) {
1412
- getLogger3().warn(`AgentTask: Tool "${toolName}" provided config but task has no configSchema \u2014 config ignored`);
1413
- return {};
1414
- }
1415
- return config;
1416
- }
1417
- function buildToolSources(tools, registry) {
1418
- if (!tools || tools.length === 0)
1419
- return [];
1420
- const stringNames = tools.filter((t) => typeof t === "string");
1421
- const resolvedDefs = new Map(taskTypesToTools(stringNames, registry).map((d) => [d.taskType, d]));
1422
- const constructors = getTaskConstructors2(registry);
1423
- const sources = [];
1424
- for (const tool of tools) {
1425
- if (typeof tool === "string") {
1426
- const def = resolvedDefs.get(tool);
1427
- if (def) {
1428
- const { taskType, ...definition } = def;
1429
- sources.push({
1430
- type: "registry",
1431
- definition,
1432
- taskType
1433
- });
1434
- }
1435
- } else if (tool.type === "function" || !tool.type && tool.execute) {
1436
- if (!tool.execute) {
1437
- getLogger3().warn(`AgentTask: Tool "${tool.name}" has type "function" but no execute function \u2014 will throw on invocation`);
1438
- }
1439
- const { execute, configSchema: _cs, config: _c, type: _t, ...definition } = tool;
1440
- sources.push({
1441
- type: "function",
1442
- definition,
1443
- run: execute ?? (async () => {
1444
- throw new Error(`No execute function for tool "${tool.name}"`);
1445
- })
1446
- });
1447
- } else if (tool.type === "task") {
1448
- const ctor = constructors.get(tool.name);
1449
- if (!ctor) {
1450
- getLogger3().warn(`AgentTask: Tool "${tool.name}" has type "task" but is not in TaskRegistry \u2014 will throw on invocation`);
1451
- const { execute: _e, configSchema: _cs, config: _c, type: _t, ...definition } = tool;
1452
- sources.push({
1453
- type: "function",
1454
- definition,
1455
- run: async () => {
1456
- throw new Error(`Task "${tool.name}" not found in TaskRegistry`);
1457
- }
1458
- });
1459
- } else {
1460
- const safeConfig = resolveToolConfig(tool.name, tool.config, ctor.configSchema?.());
1461
- const { execute: _e, configSchema: _cs, config: _c, type: _t, ...definition } = tool;
1462
- sources.push({
1463
- type: "registry",
1464
- definition,
1465
- taskType: tool.name,
1466
- config: safeConfig
1467
- });
1468
- }
1469
- } else {
1470
- const ctor = constructors.get(tool.name);
1471
- if (ctor) {
1472
- const safeConfig = resolveToolConfig(tool.name, tool.config, ctor.configSchema?.());
1473
- const { execute: _e, configSchema: _cs, config: _c, type: _t, ...definition } = tool;
1474
- sources.push({
1475
- type: "registry",
1476
- definition,
1477
- taskType: tool.name,
1478
- config: safeConfig
1479
- });
1480
- } else {
1481
- const { execute: _e, configSchema: _cs, config: _c, type: _t, ...definition } = tool;
1482
- sources.push({
1483
- type: "function",
1484
- definition,
1485
- run: async () => {
1486
- throw new Error(`No executor registered for tool "${tool.name}"`);
1487
- }
1488
- });
1489
- }
1490
- }
1491
- }
1492
- return sources;
1493
- }
1494
- async function executeToolCall(toolCall, sources, context, hooks) {
1495
- const source = findToolSource(sources, toolCall.name);
1496
- if (!source) {
1497
- getLogger3().warn(`AgentTask: Unknown tool "${toolCall.name}" \u2014 not found in tool sources`);
1498
- return {
1499
- toolCallId: toolCall.id,
1500
- toolName: toolCall.name,
1501
- output: { error: `Unknown tool: ${toolCall.name}` },
1502
- isError: true
1503
- };
1504
- }
1505
- let effectiveCall = toolCall;
1506
- if (hooks?.beforeToolCall) {
1507
- const decision = await hooks.beforeToolCall(toolCall, source);
1508
- if (decision.action === "deny") {
1509
- return {
1510
- toolCallId: toolCall.id,
1511
- toolName: toolCall.name,
1512
- output: { error: decision.reason ?? "Tool call denied by hook" },
1513
- isError: true
1514
- };
1515
- }
1516
- if (decision.action === "modify") {
1517
- effectiveCall = { ...toolCall, input: decision.input };
1518
- }
1519
- }
1520
- try {
1521
- let output;
1522
- switch (source.type) {
1523
- case "registry": {
1524
- const ctor = getTaskConstructors2(context.registry).get(source.taskType);
1525
- if (!ctor) {
1526
- throw new Error(`Task type "${source.taskType}" not found in TaskRegistry`);
1527
- }
1528
- const taskConfig = source.config ?? {};
1529
- const task = context.own(new ctor({}, taskConfig));
1530
- output = await task.run(effectiveCall.input) ?? {};
1531
- break;
1532
- }
1533
- case "function": {
1534
- output = await source.run(effectiveCall.input);
1535
- break;
1536
- }
1537
- }
1538
- let result = {
1539
- toolCallId: toolCall.id,
1540
- toolName: toolCall.name,
1541
- output,
1542
- isError: false
1543
- };
1544
- if (hooks?.afterToolCall) {
1545
- result = await hooks.afterToolCall(toolCall, result);
1546
- }
1547
- return result;
1548
- } catch (err) {
1549
- const error = err instanceof Error ? err : new Error(String(err));
1550
- if (hooks?.onToolError) {
1551
- const action = await hooks.onToolError(toolCall, error);
1552
- if (action.action === "result") {
1553
- return {
1554
- toolCallId: toolCall.id,
1555
- toolName: toolCall.name,
1556
- output: action.output,
1557
- isError: false
1558
- };
1559
- }
1560
- }
1561
- getLogger3().warn(`AgentTask: Tool "${toolCall.name}" failed: ${error.message}`);
1562
- return {
1563
- toolCallId: toolCall.id,
1564
- toolName: toolCall.name,
1565
- output: { error: error.message },
1566
- isError: true
1567
- };
1568
- }
1569
- }
1570
- async function executeToolCalls(toolCalls, sources, context, hooks, maxConcurrency = 5) {
1571
- const calls = toolCalls;
1572
- if (calls.length === 0)
1573
- return [];
1574
- const concurrency = Math.max(1, Math.min(maxConcurrency, calls.length));
1575
- const results = new Array(calls.length);
1576
- let cursor = 0;
1577
- const workers = Array.from({ length: concurrency }, async () => {
1578
- while (true) {
1579
- if (context.signal.aborted) {
1580
- throw context.signal.reason ?? new TaskAbortedError("The operation was aborted");
1581
- }
1582
- const position = cursor;
1583
- cursor += 1;
1584
- if (position >= calls.length)
1585
- return;
1586
- results[position] = await executeToolCall(calls[position], sources, context, hooks);
1587
- }
1588
- });
1589
- await Promise.all(workers);
1590
- return results;
1591
- }
1592
- function hasToolCalls(toolCalls) {
1593
- return toolCalls !== undefined && toolCalls.length > 0;
1594
- }
1595
- function countAssistantToolUses(messages) {
1596
- let n = 0;
1597
- for (const m of messages) {
1598
- if (m.role !== "assistant")
1599
- continue;
1600
- for (const block of m.content) {
1601
- if (block.type === "tool_use")
1602
- n += 1;
1603
- }
1604
- }
1605
- return n;
1606
- }
1607
-
1608
- // src/task/AgentTask.ts
1609
- var MAX_CONTEXT_MESSAGES = 1000;
1610
- var modelSchema2 = TypeModel("model:ToolCallingTask");
1611
- var AgentInputSchema = {
1612
- type: "object",
1613
- properties: {
1614
- model: modelSchema2,
1615
- prompt: {
1616
- oneOf: [
1617
- { type: "string" },
1618
- {
1619
- type: "array",
1620
- items: {
1621
- type: "object",
1622
- properties: {
1623
- type: { type: "string", enum: ["text", "image", "audio"] }
1624
- },
1625
- required: ["type"],
1626
- additionalProperties: true
1627
- }
1628
- }
1629
- ],
1630
- title: "Prompt",
1631
- description: "The user prompt to start the agent loop. Can be a string or an array of content blocks (text, image, audio)."
1632
- },
1633
- systemPrompt: {
1634
- type: "string",
1635
- title: "System Prompt",
1636
- description: "Optional system instructions for the agent"
1637
- },
1638
- tools: {
1639
- type: "array",
1640
- format: "tasks",
1641
- title: "Tools",
1642
- description: "Tools available to the agent. Each entry is a task type name (string, resolved from TaskRegistry) or a full ToolDefinition object with optional config for configurable tasks.",
1643
- items: {
1644
- oneOf: [
1645
- { type: "string", format: "tasks", description: "Task type name" },
1646
- ToolDefinitionSchema
1647
- ]
1648
- }
1649
- },
1650
- stopTool: {
1651
- type: "string",
1652
- title: "Stop Tool",
1653
- description: "Name of a tool that signals agent completion. When called, the loop ends and the tool input becomes structuredOutput.",
1654
- "x-ui-group": "Configuration"
1655
- },
1656
- maxIterations: {
1657
- type: "number",
1658
- title: "Max Iterations",
1659
- description: "Maximum number of agent loop iterations (default: 10)",
1660
- minimum: 1,
1661
- "x-ui-group": "Configuration"
1662
- },
1663
- maxContextMessages: {
1664
- type: "number",
1665
- title: "Max Context Messages",
1666
- description: "Maximum messages in conversation history. Older messages are trimmed to prevent context overflow.",
1667
- minimum: 3,
1668
- "x-ui-group": "Configuration"
1669
- },
1670
- maxTokens: {
1671
- type: "number",
1672
- title: "Max Tokens",
1673
- description: "Maximum tokens per LLM call",
1674
- minimum: 1,
1675
- "x-ui-group": "Configuration"
1676
- },
1677
- temperature: {
1678
- type: "number",
1679
- title: "Temperature",
1680
- description: "Sampling temperature for LLM calls",
1681
- minimum: 0,
1682
- maximum: 2,
1683
- "x-ui-group": "Configuration"
1684
- }
1685
- },
1686
- required: ["model", "prompt"],
1687
- additionalProperties: false
1688
- };
1689
- var AgentOutputSchema = {
1690
- type: "object",
1691
- properties: {
1692
- text: {
1693
- type: "string",
1694
- title: "Text",
1695
- description: "The final text response from the agent",
1696
- "x-stream": "append"
1697
- },
1698
- messages: {
1699
- type: "array",
1700
- title: "Messages",
1701
- description: "Full conversation history including all tool calls and results",
1702
- items: {
1703
- type: "object",
1704
- additionalProperties: true
1705
- }
1706
- },
1707
- iterations: {
1708
- type: "number",
1709
- title: "Iterations",
1710
- description: "Number of LLM calls made during the agent loop"
1711
- },
1712
- toolCallCount: {
1713
- type: "number",
1714
- title: "Tool Call Count",
1715
- description: "Total number of tool calls the assistant requested (tool_use blocks in assistant messages)"
1716
- },
1717
- structuredOutput: {
1718
- type: "object",
1719
- title: "Structured Output",
1720
- description: "Present when the agent terminated via a stop tool",
1721
- additionalProperties: true
1722
- }
1723
- },
1724
- required: ["text", "messages", "iterations", "toolCallCount"],
1725
- additionalProperties: false
1726
- };
1727
-
1728
- class AgentTask extends Task2 {
1729
- static type = "AgentTask";
1730
- static category = "AI Agent";
1731
- static title = "Agent";
1732
- static description = "Multi-turn agentic loop that calls an LLM with tools, executes tool calls, and iterates until done";
1733
- static cacheable = false;
1734
- static inputSchema() {
1735
- return AgentInputSchema;
1736
- }
1737
- static outputSchema() {
1738
- return AgentOutputSchema;
1073
+ async getDefaultQueueName(input) {
1074
+ const model = input.model;
1075
+ return model?.provider;
1739
1076
  }
1740
- async execute(input, context) {
1741
- let result;
1742
- for await (const event of this.agentLoop(input, context)) {
1743
- if (event.type === "finish") {
1744
- result = event.data;
1077
+ async executeReactive(input, output, context) {
1078
+ const model = input.model;
1079
+ if (model && typeof model === "object" && model.provider) {
1080
+ const taskType = this.constructor.runtype ?? this.constructor.type;
1081
+ const reactiveFn = getAiProviderRegistry().getReactiveRunFn(model.provider, taskType);
1082
+ if (reactiveFn) {
1083
+ return reactiveFn(input, output, model);
1745
1084
  }
1746
1085
  }
1747
- if (!result) {
1748
- throw new Error("AgentTask: loop ended without producing output");
1749
- }
1750
- return result;
1086
+ return super.executeReactive(input, output, context);
1751
1087
  }
1752
- async* executeStream(input, context) {
1753
- yield* this.agentLoop(input, context);
1754
- }
1755
- async* agentLoop(input, context) {
1756
- const maxIterations = input.maxIterations ?? 10;
1757
- const hooks = this.config.hooks;
1758
- const maxConcurrency = this.config.maxConcurrency ?? 5;
1759
- const toolSources = this.resolveToolSources(input, context);
1760
- const toolDefs = this.resolveToolDefs(toolSources, input.stopTool);
1761
- const messages = [userMessage(input.prompt)];
1762
- let finalText = "";
1763
- let structuredOutput;
1764
- for (let iteration = 0;iteration < maxIterations; iteration++) {
1765
- if (context.signal.aborted)
1766
- break;
1767
- if (hooks?.onIteration) {
1768
- const action = await hooks.onIteration(iteration, messages, {
1769
- totalToolCalls: countAssistantToolUses(messages)
1770
- });
1771
- if (action.action === "stop")
1772
- break;
1773
- }
1774
- await context.updateProgress(Math.round(iteration / maxIterations * 100), `Agent iteration ${iteration + 1}`);
1775
- const contextMessages = this.trimMessages(messages, input.maxContextMessages ?? MAX_CONTEXT_MESSAGES);
1776
- const llmTask = context.own(new ToolCallingTask);
1777
- let iterationText = "";
1778
- let toolCalls = [];
1779
- for await (const event of llmTask.executeStream({
1780
- model: input.model,
1781
- prompt: input.prompt,
1782
- systemPrompt: input.systemPrompt,
1783
- tools: toolDefs,
1784
- messages: contextMessages,
1785
- maxTokens: input.maxTokens,
1786
- temperature: input.temperature
1787
- }, context)) {
1788
- if (event.type === "text-delta") {
1789
- yield { type: "text-delta", port: "text", textDelta: event.textDelta };
1790
- iterationText += event.textDelta;
1791
- } else if (event.type === "object-delta" && event.port === "toolCalls") {
1792
- const items = event.objectDelta;
1793
- for (const item of items) {
1794
- const idx = toolCalls.findIndex((tc) => tc.id === item.id);
1795
- if (idx >= 0)
1796
- toolCalls[idx] = item;
1797
- else
1798
- toolCalls.push(item);
1799
- }
1800
- } else if (event.type === "finish") {
1801
- const data = event.data;
1802
- iterationText = data?.text ?? iterationText;
1803
- if (data?.toolCalls && data.toolCalls.length > 0) {
1804
- toolCalls = data.toolCalls;
1805
- }
1806
- }
1088
+ async validateInput(input) {
1089
+ const inputSchema = this.inputSchema();
1090
+ if (typeof inputSchema === "boolean") {
1091
+ if (inputSchema === false) {
1092
+ throw new TaskConfigurationError2(`AiTask: Input schema is 'false' and accepts no inputs`);
1807
1093
  }
1808
- finalText = iterationText;
1809
- messages.push(assistantMessage(iterationText, toolCalls));
1810
- if (input.stopTool) {
1811
- const stopCall = toolCalls.find((tc) => tc.name === input.stopTool);
1812
- if (stopCall) {
1813
- structuredOutput = stopCall.input;
1814
- break;
1094
+ return true;
1095
+ }
1096
+ const modelTaskProperties = Object.entries(inputSchema.properties || {}).filter(([key, schema]) => schemaFormat(schema)?.startsWith("model:"));
1097
+ for (const [key] of modelTaskProperties) {
1098
+ const model = input[key];
1099
+ if (typeof model === "object" && model !== null) {
1100
+ const tasks = model.tasks;
1101
+ if (Array.isArray(tasks) && tasks.length > 0 && !tasks.includes(this.type)) {
1102
+ const modelId = model.model_id ?? "(inline config)";
1103
+ throw new TaskConfigurationError2(`AiTask: Model "${modelId}" for '${key}' is not compatible with task '${this.type}'. ` + `Model supports: [${tasks.join(", ")}]`);
1815
1104
  }
1105
+ } else if (model !== undefined && model !== null) {
1106
+ throw new TaskConfigurationError2(`AiTask: Invalid model for '${key}' - expected ModelConfig object but got ${typeof model}. ` + `Ensure the model ID was registered in the ModelRepository before running the task.`);
1816
1107
  }
1817
- if (!hasToolCalls(toolCalls)) {
1818
- break;
1819
- }
1820
- const results = await executeToolCalls(toolCalls, toolSources, context, hooks, maxConcurrency);
1821
- messages.push(toolMessage(results));
1822
1108
  }
1823
- const output = {
1824
- text: finalText,
1825
- messages,
1826
- iterations: messages.filter((m) => m.role === "assistant").length,
1827
- toolCallCount: countAssistantToolUses(messages),
1828
- ...structuredOutput !== undefined ? { structuredOutput } : {}
1829
- };
1830
- yield { type: "finish", data: output };
1831
- }
1832
- resolveToolSources(input, context) {
1833
- return buildToolSources(input.tools, context.registry);
1834
- }
1835
- resolveToolDefs(toolSources, stopTool) {
1836
- const defs = toolSourceDefinitions(toolSources);
1837
- if (stopTool && !defs.some((d) => d.name === stopTool)) {
1838
- defs.push({
1839
- name: stopTool,
1840
- description: "Call this tool when you have completed the task. Pass your final structured result as the input.",
1841
- inputSchema: { type: "object", additionalProperties: true }
1842
- });
1109
+ const modelPlainProperties = Object.entries(inputSchema.properties || {}).filter(([key, schema]) => schemaFormat(schema) === "model");
1110
+ for (const [key] of modelPlainProperties) {
1111
+ const model = input[key];
1112
+ if (model !== undefined && model !== null && typeof model !== "object") {
1113
+ throw new TaskConfigurationError2(`AiTask: Invalid model for '${key}' - expected ModelConfig object but got ${typeof model}. ` + `Ensure the model ID was registered in the ModelRepository before running the task.`);
1114
+ }
1843
1115
  }
1844
- return defs;
1116
+ return super.validateInput(input);
1845
1117
  }
1846
- trimMessages(messages, maxContextMessages) {
1847
- if (!maxContextMessages || messages.length <= maxContextMessages) {
1848
- return messages;
1118
+ async narrowInput(input, registry) {
1119
+ const inputSchema = this.inputSchema();
1120
+ if (typeof inputSchema === "boolean") {
1121
+ if (inputSchema === false) {
1122
+ throw new TaskConfigurationError2(`AiTask: Input schema is 'false' and accepts no inputs`);
1123
+ }
1124
+ return input;
1849
1125
  }
1850
- getLogger4().debug(`AgentTask: Trimming context from ${messages.length} to ${maxContextMessages} messages`);
1851
- const tail = messages.slice(1);
1852
- let startIdx = tail.length - (maxContextMessages - 1);
1853
- if (startIdx < 0)
1854
- startIdx = 0;
1855
- while (startIdx > 0 && startIdx < tail.length && tail[startIdx].role === "tool") {
1856
- startIdx -= 1;
1126
+ const modelTaskProperties = Object.entries(inputSchema.properties || {}).filter(([key, schema]) => schemaFormat(schema)?.startsWith("model:"));
1127
+ if (modelTaskProperties.length > 0) {
1128
+ const modelRepo = registry.get(MODEL_REPOSITORY);
1129
+ const taskModels = await modelRepo.findModelsByTask(this.type) ?? [];
1130
+ for (const [key] of modelTaskProperties) {
1131
+ const requestedModel = input[key];
1132
+ if (typeof requestedModel === "string") {
1133
+ const found = taskModels?.find((m) => m.model_id === requestedModel);
1134
+ if (!found) {
1135
+ input[key] = undefined;
1136
+ }
1137
+ } else if (typeof requestedModel === "object" && requestedModel !== null) {
1138
+ const model = requestedModel;
1139
+ const tasks = model.tasks;
1140
+ if (Array.isArray(tasks) && tasks.length > 0 && !tasks.includes(this.type)) {
1141
+ input[key] = undefined;
1142
+ }
1143
+ }
1144
+ }
1857
1145
  }
1858
- return [messages[0], ...tail.slice(startIdx)];
1146
+ return input;
1859
1147
  }
1860
1148
  }
1861
- var agent = (input, config) => {
1862
- return new AgentTask(config).run(input);
1863
- };
1864
- Workflow2.prototype.agent = CreateWorkflow2(AgentTask);
1865
-
1866
- // src/task/BackgroundRemovalTask.ts
1867
- import { CreateWorkflow as CreateWorkflow3, Workflow as Workflow3 } from "@workglow/task-graph";
1868
1149
 
1869
1150
  // src/task/base/AiVisionTask.ts
1870
- import { convertImageDataToUseableForm } from "@workglow/util/media";
1871
1151
  class AiVisionTask extends AiTask {
1872
1152
  static type = "AiVisionTask";
1873
1153
  async getJobInput(input) {
@@ -1888,7 +1168,7 @@ class AiVisionTask extends AiTask {
1888
1168
  }
1889
1169
 
1890
1170
  // src/task/BackgroundRemovalTask.ts
1891
- var modelSchema3 = TypeModel("model:BackgroundRemovalTask");
1171
+ var modelSchema = TypeModel("model:BackgroundRemovalTask");
1892
1172
  var processedImageSchema = {
1893
1173
  type: "string",
1894
1174
  contentEncoding: "base64",
@@ -1900,7 +1180,7 @@ var BackgroundRemovalInputSchema = {
1900
1180
  type: "object",
1901
1181
  properties: {
1902
1182
  image: TypeImageInput,
1903
- model: modelSchema3
1183
+ model: modelSchema
1904
1184
  },
1905
1185
  required: ["image", "model"],
1906
1186
  additionalProperties: false
@@ -1929,22 +1209,22 @@ class BackgroundRemovalTask extends AiVisionTask {
1929
1209
  var backgroundRemoval = (input, config) => {
1930
1210
  return new BackgroundRemovalTask(config).run(input);
1931
1211
  };
1932
- Workflow3.prototype.backgroundRemoval = CreateWorkflow3(BackgroundRemovalTask);
1212
+ Workflow.prototype.backgroundRemoval = CreateWorkflow(BackgroundRemovalTask);
1933
1213
 
1934
1214
  // src/task/ChunkRetrievalTask.ts
1935
1215
  import { TypeKnowledgeBase } from "@workglow/knowledge-base";
1936
- import { CreateWorkflow as CreateWorkflow5, Task as Task3, Workflow as Workflow5 } from "@workglow/task-graph";
1216
+ import { CreateWorkflow as CreateWorkflow3, Task as Task2, Workflow as Workflow3 } from "@workglow/task-graph";
1937
1217
  import {
1938
1218
  isTypedArray,
1939
1219
  TypedArraySchema as TypedArraySchema2
1940
1220
  } from "@workglow/util/schema";
1941
1221
 
1942
1222
  // src/task/TextEmbeddingTask.ts
1943
- import { CreateWorkflow as CreateWorkflow4, Workflow as Workflow4 } from "@workglow/task-graph";
1223
+ import { CreateWorkflow as CreateWorkflow2, Workflow as Workflow2 } from "@workglow/task-graph";
1944
1224
  import {
1945
1225
  TypedArraySchema
1946
1226
  } from "@workglow/util/schema";
1947
- var modelSchema4 = TypeModel("model:TextEmbeddingTask");
1227
+ var modelSchema2 = TypeModel("model:TextEmbeddingTask");
1948
1228
  var TextEmbeddingInputSchema = {
1949
1229
  type: "object",
1950
1230
  properties: {
@@ -1953,7 +1233,7 @@ var TextEmbeddingInputSchema = {
1953
1233
  title: "Text",
1954
1234
  description: "The text to embed"
1955
1235
  }),
1956
- model: modelSchema4
1236
+ model: modelSchema2
1957
1237
  },
1958
1238
  required: ["text", "model"],
1959
1239
  additionalProperties: false
@@ -1985,7 +1265,7 @@ class TextEmbeddingTask extends AiTask {
1985
1265
  var textEmbedding = async (input, config) => {
1986
1266
  return new TextEmbeddingTask(config).run(input);
1987
1267
  };
1988
- Workflow4.prototype.textEmbedding = CreateWorkflow4(TextEmbeddingTask);
1268
+ Workflow2.prototype.textEmbedding = CreateWorkflow2(TextEmbeddingTask);
1989
1269
 
1990
1270
  // src/task/ChunkRetrievalTask.ts
1991
1271
  var inputSchema = {
@@ -2110,7 +1390,7 @@ var outputSchema = {
2110
1390
  additionalProperties: false
2111
1391
  };
2112
1392
 
2113
- class ChunkRetrievalTask extends Task3 {
1393
+ class ChunkRetrievalTask extends Task2 {
2114
1394
  static type = "ChunkRetrievalTask";
2115
1395
  static category = "RAG";
2116
1396
  static title = "Chunk Retrieval";
@@ -2177,11 +1457,11 @@ class ChunkRetrievalTask extends Task3 {
2177
1457
  var chunkRetrieval = (input, config) => {
2178
1458
  return new ChunkRetrievalTask(config).run(input);
2179
1459
  };
2180
- Workflow5.prototype.chunkRetrieval = CreateWorkflow5(ChunkRetrievalTask);
1460
+ Workflow3.prototype.chunkRetrieval = CreateWorkflow3(ChunkRetrievalTask);
2181
1461
 
2182
1462
  // src/task/ChunkToVectorTask.ts
2183
1463
  import { ChunkRecordSchema } from "@workglow/knowledge-base";
2184
- import { CreateWorkflow as CreateWorkflow6, Task as Task4, Workflow as Workflow6 } from "@workglow/task-graph";
1464
+ import { CreateWorkflow as CreateWorkflow4, Task as Task3, Workflow as Workflow4 } from "@workglow/task-graph";
2185
1465
  import {
2186
1466
  TypedArraySchema as TypedArraySchema3
2187
1467
  } from "@workglow/util/schema";
@@ -2256,7 +1536,7 @@ var outputSchema2 = {
2256
1536
  additionalProperties: false
2257
1537
  };
2258
1538
 
2259
- class ChunkToVectorTask extends Task4 {
1539
+ class ChunkToVectorTask extends Task3 {
2260
1540
  static type = "ChunkToVectorTask";
2261
1541
  static category = "Document";
2262
1542
  static title = "Chunk to Vector";
@@ -2307,11 +1587,11 @@ class ChunkToVectorTask extends Task4 {
2307
1587
  var chunkToVector = (input, config) => {
2308
1588
  return new ChunkToVectorTask(config).run(input);
2309
1589
  };
2310
- Workflow6.prototype.chunkToVector = CreateWorkflow6(ChunkToVectorTask);
1590
+ Workflow4.prototype.chunkToVector = CreateWorkflow4(ChunkToVectorTask);
2311
1591
 
2312
1592
  // src/task/ChunkVectorHybridSearchTask.ts
2313
1593
  import { TypeKnowledgeBase as TypeKnowledgeBase2 } from "@workglow/knowledge-base";
2314
- import { CreateWorkflow as CreateWorkflow7, Task as Task5, Workflow as Workflow7 } from "@workglow/task-graph";
1594
+ import { CreateWorkflow as CreateWorkflow5, Task as Task4, Workflow as Workflow5 } from "@workglow/task-graph";
2315
1595
  import {
2316
1596
  TypedArraySchema as TypedArraySchema4
2317
1597
  } from "@workglow/util/schema";
@@ -2424,7 +1704,7 @@ var outputSchema3 = {
2424
1704
  additionalProperties: false
2425
1705
  };
2426
1706
 
2427
- class ChunkVectorHybridSearchTask extends Task5 {
1707
+ class ChunkVectorHybridSearchTask extends Task4 {
2428
1708
  static type = "ChunkVectorHybridSearchTask";
2429
1709
  static category = "RAG";
2430
1710
  static title = "Hybrid Search";
@@ -2477,11 +1757,11 @@ class ChunkVectorHybridSearchTask extends Task5 {
2477
1757
  var hybridSearch = async (input, config) => {
2478
1758
  return new ChunkVectorHybridSearchTask(config).run(input);
2479
1759
  };
2480
- Workflow7.prototype.hybridSearch = CreateWorkflow7(ChunkVectorHybridSearchTask);
1760
+ Workflow5.prototype.hybridSearch = CreateWorkflow5(ChunkVectorHybridSearchTask);
2481
1761
 
2482
1762
  // src/task/ChunkVectorSearchTask.ts
2483
1763
  import { TypeKnowledgeBase as TypeKnowledgeBase3 } from "@workglow/knowledge-base";
2484
- import { CreateWorkflow as CreateWorkflow8, Task as Task6, Workflow as Workflow8 } from "@workglow/task-graph";
1764
+ import { CreateWorkflow as CreateWorkflow6, Task as Task5, Workflow as Workflow6 } from "@workglow/task-graph";
2485
1765
  import {
2486
1766
  TypedArraySchema as TypedArraySchema5
2487
1767
  } from "@workglow/util/schema";
@@ -2564,7 +1844,7 @@ var outputSchema4 = {
2564
1844
  additionalProperties: false
2565
1845
  };
2566
1846
 
2567
- class ChunkVectorSearchTask extends Task6 {
1847
+ class ChunkVectorSearchTask extends Task5 {
2568
1848
  static type = "ChunkVectorSearchTask";
2569
1849
  static category = "Vector Store";
2570
1850
  static title = "Vector Store Search";
@@ -2596,11 +1876,11 @@ class ChunkVectorSearchTask extends Task6 {
2596
1876
  var vectorStoreSearch = (input, config) => {
2597
1877
  return new ChunkVectorSearchTask(config).run(input);
2598
1878
  };
2599
- Workflow8.prototype.vectorStoreSearch = CreateWorkflow8(ChunkVectorSearchTask);
1879
+ Workflow6.prototype.vectorStoreSearch = CreateWorkflow6(ChunkVectorSearchTask);
2600
1880
 
2601
1881
  // src/task/ChunkVectorUpsertTask.ts
2602
1882
  import { TypeKnowledgeBase as TypeKnowledgeBase4 } from "@workglow/knowledge-base";
2603
- import { CreateWorkflow as CreateWorkflow9, Task as Task7, Workflow as Workflow9 } from "@workglow/task-graph";
1883
+ import { CreateWorkflow as CreateWorkflow7, Task as Task6, Workflow as Workflow7 } from "@workglow/task-graph";
2604
1884
  import {
2605
1885
  TypedArraySchema as TypedArraySchema6
2606
1886
  } from "@workglow/util/schema";
@@ -2654,7 +1934,7 @@ var outputSchema5 = {
2654
1934
  additionalProperties: false
2655
1935
  };
2656
1936
 
2657
- class ChunkVectorUpsertTask extends Task7 {
1937
+ class ChunkVectorUpsertTask extends Task6 {
2658
1938
  static type = "ChunkVectorUpsertTask";
2659
1939
  static category = "Vector Store";
2660
1940
  static title = "Add to Vector Store";
@@ -2714,15 +1994,15 @@ class ChunkVectorUpsertTask extends Task7 {
2714
1994
  var chunkVectorUpsert = (input, config) => {
2715
1995
  return new ChunkVectorUpsertTask(config).run(input);
2716
1996
  };
2717
- Workflow9.prototype.chunkVectorUpsert = CreateWorkflow9(ChunkVectorUpsertTask);
1997
+ Workflow7.prototype.chunkVectorUpsert = CreateWorkflow7(ChunkVectorUpsertTask);
2718
1998
 
2719
1999
  // src/task/ContextBuilderTask.ts
2720
2000
  import { estimateTokens } from "@workglow/knowledge-base";
2721
- import { CreateWorkflow as CreateWorkflow11, Task as Task8, Workflow as Workflow11 } from "@workglow/task-graph";
2001
+ import { CreateWorkflow as CreateWorkflow9, Task as Task7, Workflow as Workflow9 } from "@workglow/task-graph";
2722
2002
 
2723
2003
  // src/task/CountTokensTask.ts
2724
- import { CreateWorkflow as CreateWorkflow10, Workflow as Workflow10 } from "@workglow/task-graph";
2725
- var modelSchema5 = TypeModel("model");
2004
+ import { CreateWorkflow as CreateWorkflow8, Workflow as Workflow8 } from "@workglow/task-graph";
2005
+ var modelSchema3 = TypeModel("model");
2726
2006
  var CountTokensInputSchema = {
2727
2007
  type: "object",
2728
2008
  properties: {
@@ -2731,7 +2011,7 @@ var CountTokensInputSchema = {
2731
2011
  title: "Text",
2732
2012
  description: "The text to count tokens for"
2733
2013
  },
2734
- model: modelSchema5
2014
+ model: modelSchema3
2735
2015
  },
2736
2016
  required: ["text", "model"],
2737
2017
  additionalProperties: false
@@ -2765,7 +2045,7 @@ class CountTokensTask extends AiTask {
2765
2045
  var countTokens = async (input, config) => {
2766
2046
  return new CountTokensTask(config).run(input);
2767
2047
  };
2768
- Workflow10.prototype.countTokens = CreateWorkflow10(CountTokensTask);
2048
+ Workflow8.prototype.countTokens = CreateWorkflow8(CountTokensTask);
2769
2049
 
2770
2050
  // src/task/ContextBuilderTask.ts
2771
2051
  var ContextFormat = {
@@ -2775,7 +2055,7 @@ var ContextFormat = {
2775
2055
  MARKDOWN: "markdown",
2776
2056
  JSON: "json"
2777
2057
  };
2778
- var modelSchema6 = TypeModel("model", {
2058
+ var modelSchema4 = TypeModel("model", {
2779
2059
  title: "Model",
2780
2060
  description: "Model to use for token counting (optional, falls back to estimation)"
2781
2061
  });
@@ -2839,7 +2119,7 @@ var inputSchema6 = {
2839
2119
 
2840
2120
  `
2841
2121
  },
2842
- model: modelSchema6
2122
+ model: modelSchema4
2843
2123
  },
2844
2124
  required: ["chunks"],
2845
2125
  additionalProperties: false
@@ -2872,7 +2152,7 @@ var outputSchema6 = {
2872
2152
  additionalProperties: false
2873
2153
  };
2874
2154
 
2875
- class ContextBuilderTask extends Task8 {
2155
+ class ContextBuilderTask extends Task7 {
2876
2156
  static type = "ContextBuilderTask";
2877
2157
  static category = "RAG";
2878
2158
  static title = "Context Builder";
@@ -3065,15 +2345,15 @@ class ContextBuilderTask extends Task8 {
3065
2345
  var contextBuilder = (input, config) => {
3066
2346
  return new ContextBuilderTask(config).run(input);
3067
2347
  };
3068
- Workflow11.prototype.contextBuilder = CreateWorkflow11(ContextBuilderTask);
2348
+ Workflow9.prototype.contextBuilder = CreateWorkflow9(ContextBuilderTask);
3069
2349
 
3070
2350
  // src/task/DocumentEnricherTask.ts
3071
2351
  import { getChildren, hasChildren } from "@workglow/knowledge-base";
3072
- import { CreateWorkflow as CreateWorkflow14, Task as Task9, Workflow as Workflow14 } from "@workglow/task-graph";
2352
+ import { CreateWorkflow as CreateWorkflow12, Task as Task8, Workflow as Workflow12 } from "@workglow/task-graph";
3073
2353
 
3074
2354
  // src/task/TextNamedEntityRecognitionTask.ts
3075
- import { CreateWorkflow as CreateWorkflow12, Workflow as Workflow12 } from "@workglow/task-graph";
3076
- var modelSchema7 = TypeModel("model:TextNamedEntityRecognitionTask");
2355
+ import { CreateWorkflow as CreateWorkflow10, Workflow as Workflow10 } from "@workglow/task-graph";
2356
+ var modelSchema5 = TypeModel("model:TextNamedEntityRecognitionTask");
3077
2357
  var TextNamedEntityRecognitionInputSchema = {
3078
2358
  type: "object",
3079
2359
  properties: {
@@ -3092,7 +2372,7 @@ var TextNamedEntityRecognitionInputSchema = {
3092
2372
  "x-ui-group": "Configuration",
3093
2373
  "x-ui-group-open": false
3094
2374
  },
3095
- model: modelSchema7
2375
+ model: modelSchema5
3096
2376
  },
3097
2377
  required: ["text", "model"],
3098
2378
  additionalProperties: false
@@ -3147,11 +2427,48 @@ class TextNamedEntityRecognitionTask extends AiTask {
3147
2427
  var textNamedEntityRecognition = (input, config) => {
3148
2428
  return new TextNamedEntityRecognitionTask(config).run(input);
3149
2429
  };
3150
- Workflow12.prototype.textNamedEntityRecognition = CreateWorkflow12(TextNamedEntityRecognitionTask);
2430
+ Workflow10.prototype.textNamedEntityRecognition = CreateWorkflow10(TextNamedEntityRecognitionTask);
2431
+
2432
+ // src/task/TextSummaryTask.ts
2433
+ import { CreateWorkflow as CreateWorkflow11, Workflow as Workflow11 } from "@workglow/task-graph";
2434
+
2435
+ // src/task/base/StreamingAiTask.ts
2436
+ import { getStreamingPorts, TaskConfigurationError as TaskConfigurationError3 } from "@workglow/task-graph";
2437
+ class StreamingAiTask extends AiTask {
2438
+ static type = "StreamingAiTask";
2439
+ async* executeStream(input, context) {
2440
+ const model = input.model;
2441
+ if (!model || typeof model !== "object") {
2442
+ throw new TaskConfigurationError3("StreamingAiTask: Model was not resolved to ModelConfig - this indicates a bug in the resolution system");
2443
+ }
2444
+ const jobInput = await this.getJobInput(input);
2445
+ const strategy = getAiProviderRegistry().getStrategy(model);
2446
+ const outSchema = this.outputSchema();
2447
+ const ports = getStreamingPorts(outSchema);
2448
+ let defaultPort = "text";
2449
+ if (ports.length > 0) {
2450
+ defaultPort = ports[0].port;
2451
+ } else {
2452
+ if (typeof outSchema === "object" && outSchema.properties) {
2453
+ const firstProp = Object.keys(outSchema.properties)[0];
2454
+ if (firstProp)
2455
+ defaultPort = firstProp;
2456
+ }
2457
+ }
2458
+ for await (const event of strategy.executeStream(jobInput, context, this.runConfig.runnerId)) {
2459
+ if (event.type === "text-delta") {
2460
+ yield { ...event, port: event.port ?? defaultPort };
2461
+ } else if (event.type === "object-delta") {
2462
+ yield { ...event, port: event.port ?? defaultPort };
2463
+ } else {
2464
+ yield event;
2465
+ }
2466
+ }
2467
+ }
2468
+ }
3151
2469
 
3152
2470
  // src/task/TextSummaryTask.ts
3153
- import { CreateWorkflow as CreateWorkflow13, Workflow as Workflow13 } from "@workglow/task-graph";
3154
- var modelSchema8 = TypeModel("model:TextSummaryTask");
2471
+ var modelSchema6 = TypeModel("model:TextSummaryTask");
3155
2472
  var TextSummaryInputSchema = {
3156
2473
  type: "object",
3157
2474
  properties: {
@@ -3160,7 +2477,7 @@ var TextSummaryInputSchema = {
3160
2477
  title: "Text",
3161
2478
  description: "The text to summarize"
3162
2479
  },
3163
- model: modelSchema8
2480
+ model: modelSchema6
3164
2481
  },
3165
2482
  required: ["text", "model"],
3166
2483
  additionalProperties: false
@@ -3194,7 +2511,7 @@ class TextSummaryTask extends StreamingAiTask {
3194
2511
  var textSummary = async (input, config) => {
3195
2512
  return new TextSummaryTask(config).run(input);
3196
2513
  };
3197
- Workflow13.prototype.textSummary = CreateWorkflow13(TextSummaryTask);
2514
+ Workflow11.prototype.textSummary = CreateWorkflow11(TextSummaryTask);
3198
2515
 
3199
2516
  // src/task/DocumentEnricherTask.ts
3200
2517
  var inputSchema7 = {
@@ -3268,7 +2585,7 @@ var outputSchema7 = {
3268
2585
  additionalProperties: false
3269
2586
  };
3270
2587
 
3271
- class DocumentEnricherTask extends Task9 {
2588
+ class DocumentEnricherTask extends Task8 {
3272
2589
  static type = "DocumentEnricherTask";
3273
2590
  static category = "Document";
3274
2591
  static title = "Document Enricher";
@@ -3427,12 +2744,12 @@ class DocumentEnricherTask extends Task9 {
3427
2744
  var documentEnricher = (input, config) => {
3428
2745
  return new DocumentEnricherTask(config).run(input);
3429
2746
  };
3430
- Workflow14.prototype.documentEnricher = CreateWorkflow14(DocumentEnricherTask);
2747
+ Workflow12.prototype.documentEnricher = CreateWorkflow12(DocumentEnricherTask);
3431
2748
 
3432
2749
  // src/task/DocumentUpsertTask.ts
3433
2750
  import { Document, TypeKnowledgeBase as TypeKnowledgeBase5 } from "@workglow/knowledge-base";
3434
2751
  import { DocumentMetadataSchema } from "@workglow/knowledge-base";
3435
- import { CreateWorkflow as CreateWorkflow15, Task as Task10, Workflow as Workflow15 } from "@workglow/task-graph";
2752
+ import { CreateWorkflow as CreateWorkflow13, Task as Task9, Workflow as Workflow13 } from "@workglow/task-graph";
3436
2753
  var inputSchema8 = {
3437
2754
  type: "object",
3438
2755
  properties: {
@@ -3477,7 +2794,7 @@ var outputSchema8 = {
3477
2794
  additionalProperties: false
3478
2795
  };
3479
2796
 
3480
- class DocumentUpsertTask extends Task10 {
2797
+ class DocumentUpsertTask extends Task9 {
3481
2798
  static type = "DocumentUpsertTask";
3482
2799
  static category = "Vector Store";
3483
2800
  static title = "Add Document";
@@ -3510,15 +2827,15 @@ class DocumentUpsertTask extends Task10 {
3510
2827
  var documentUpsert = (input, config) => {
3511
2828
  return new DocumentUpsertTask(config).run(input);
3512
2829
  };
3513
- Workflow15.prototype.documentUpsert = CreateWorkflow15(DocumentUpsertTask);
2830
+ Workflow13.prototype.documentUpsert = CreateWorkflow13(DocumentUpsertTask);
3514
2831
 
3515
2832
  // src/task/DownloadModelTask.ts
3516
- import { CreateWorkflow as CreateWorkflow16, Workflow as Workflow16 } from "@workglow/task-graph";
3517
- var modelSchema9 = TypeModel("model");
2833
+ import { CreateWorkflow as CreateWorkflow14, Workflow as Workflow14 } from "@workglow/task-graph";
2834
+ var modelSchema7 = TypeModel("model");
3518
2835
  var DownloadModelInputSchema = {
3519
2836
  type: "object",
3520
2837
  properties: {
3521
- model: modelSchema9
2838
+ model: modelSchema7
3522
2839
  },
3523
2840
  required: ["model"],
3524
2841
  additionalProperties: false
@@ -3526,7 +2843,7 @@ var DownloadModelInputSchema = {
3526
2843
  var DownloadModelOutputSchema = {
3527
2844
  type: "object",
3528
2845
  properties: {
3529
- model: modelSchema9
2846
+ model: modelSchema7
3530
2847
  },
3531
2848
  required: ["model"],
3532
2849
  additionalProperties: false
@@ -3580,11 +2897,11 @@ class DownloadModelTask extends AiTask {
3580
2897
  var downloadModel = (input, config) => {
3581
2898
  return new DownloadModelTask(config).run(input);
3582
2899
  };
3583
- Workflow16.prototype.downloadModel = CreateWorkflow16(DownloadModelTask);
2900
+ Workflow14.prototype.downloadModel = CreateWorkflow14(DownloadModelTask);
3584
2901
 
3585
2902
  // src/task/FaceDetectorTask.ts
3586
- import { CreateWorkflow as CreateWorkflow17, Workflow as Workflow17 } from "@workglow/task-graph";
3587
- var modelSchema10 = TypeModel("model:FaceDetectorTask");
2903
+ import { CreateWorkflow as CreateWorkflow15, Workflow as Workflow15 } from "@workglow/task-graph";
2904
+ var modelSchema8 = TypeModel("model:FaceDetectorTask");
3588
2905
  var TypeBoundingBox2 = {
3589
2906
  type: "object",
3590
2907
  properties: {
@@ -3657,7 +2974,7 @@ var FaceDetectorInputSchema = {
3657
2974
  type: "object",
3658
2975
  properties: {
3659
2976
  image: TypeImageInput,
3660
- model: modelSchema10,
2977
+ model: modelSchema8,
3661
2978
  minDetectionConfidence: {
3662
2979
  type: "number",
3663
2980
  minimum: 0,
@@ -3711,11 +3028,11 @@ class FaceDetectorTask extends AiVisionTask {
3711
3028
  var faceDetector = (input, config) => {
3712
3029
  return new FaceDetectorTask(config).run(input);
3713
3030
  };
3714
- Workflow17.prototype.faceDetector = CreateWorkflow17(FaceDetectorTask);
3031
+ Workflow15.prototype.faceDetector = CreateWorkflow15(FaceDetectorTask);
3715
3032
 
3716
3033
  // src/task/FaceLandmarkerTask.ts
3717
- import { CreateWorkflow as CreateWorkflow18, Workflow as Workflow18 } from "@workglow/task-graph";
3718
- var modelSchema11 = TypeModel("model:FaceLandmarkerTask");
3034
+ import { CreateWorkflow as CreateWorkflow16, Workflow as Workflow16 } from "@workglow/task-graph";
3035
+ var modelSchema9 = TypeModel("model:FaceLandmarkerTask");
3719
3036
  var TypeLandmark = {
3720
3037
  type: "object",
3721
3038
  properties: {
@@ -3787,7 +3104,7 @@ var FaceLandmarkerInputSchema = {
3787
3104
  type: "object",
3788
3105
  properties: {
3789
3106
  image: TypeImageInput,
3790
- model: modelSchema11,
3107
+ model: modelSchema9,
3791
3108
  numFaces: {
3792
3109
  type: "number",
3793
3110
  minimum: 1,
@@ -3873,11 +3190,11 @@ class FaceLandmarkerTask extends AiVisionTask {
3873
3190
  var faceLandmarker = (input, config) => {
3874
3191
  return new FaceLandmarkerTask(config).run(input);
3875
3192
  };
3876
- Workflow18.prototype.faceLandmarker = CreateWorkflow18(FaceLandmarkerTask);
3193
+ Workflow16.prototype.faceLandmarker = CreateWorkflow16(FaceLandmarkerTask);
3877
3194
 
3878
3195
  // src/task/GestureRecognizerTask.ts
3879
- import { CreateWorkflow as CreateWorkflow19, Workflow as Workflow19 } from "@workglow/task-graph";
3880
- var modelSchema12 = TypeModel("model:GestureRecognizerTask");
3196
+ import { CreateWorkflow as CreateWorkflow17, Workflow as Workflow17 } from "@workglow/task-graph";
3197
+ var modelSchema10 = TypeModel("model:GestureRecognizerTask");
3881
3198
  var TypeLandmark2 = {
3882
3199
  type: "object",
3883
3200
  properties: {
@@ -3969,7 +3286,7 @@ var GestureRecognizerInputSchema = {
3969
3286
  type: "object",
3970
3287
  properties: {
3971
3288
  image: TypeImageInput,
3972
- model: modelSchema12,
3289
+ model: modelSchema10,
3973
3290
  numHands: {
3974
3291
  type: "number",
3975
3292
  minimum: 1,
@@ -4041,11 +3358,11 @@ class GestureRecognizerTask extends AiVisionTask {
4041
3358
  var gestureRecognizer = (input, config) => {
4042
3359
  return new GestureRecognizerTask(config).run(input);
4043
3360
  };
4044
- Workflow19.prototype.gestureRecognizer = CreateWorkflow19(GestureRecognizerTask);
3361
+ Workflow17.prototype.gestureRecognizer = CreateWorkflow17(GestureRecognizerTask);
4045
3362
 
4046
3363
  // src/task/HandLandmarkerTask.ts
4047
- import { CreateWorkflow as CreateWorkflow20, Workflow as Workflow20 } from "@workglow/task-graph";
4048
- var modelSchema13 = TypeModel("model:HandLandmarkerTask");
3364
+ import { CreateWorkflow as CreateWorkflow18, Workflow as Workflow18 } from "@workglow/task-graph";
3365
+ var modelSchema11 = TypeModel("model:HandLandmarkerTask");
4049
3366
  var TypeLandmark3 = {
4050
3367
  type: "object",
4051
3368
  properties: {
@@ -4114,7 +3431,7 @@ var HandLandmarkerInputSchema = {
4114
3431
  type: "object",
4115
3432
  properties: {
4116
3433
  image: TypeImageInput,
4117
- model: modelSchema13,
3434
+ model: modelSchema11,
4118
3435
  numHands: {
4119
3436
  type: "number",
4120
3437
  minimum: 1,
@@ -4186,7 +3503,7 @@ class HandLandmarkerTask extends AiVisionTask {
4186
3503
  var handLandmarker = (input, config) => {
4187
3504
  return new HandLandmarkerTask(config).run(input);
4188
3505
  };
4189
- Workflow20.prototype.handLandmarker = CreateWorkflow20(HandLandmarkerTask);
3506
+ Workflow18.prototype.handLandmarker = CreateWorkflow18(HandLandmarkerTask);
4190
3507
 
4191
3508
  // src/task/HierarchicalChunkerTask.ts
4192
3509
  import {
@@ -4195,9 +3512,9 @@ import {
4195
3512
  getChildren as getChildren2,
4196
3513
  hasChildren as hasChildren2
4197
3514
  } from "@workglow/knowledge-base";
4198
- import { CreateWorkflow as CreateWorkflow21, Task as Task11, Workflow as Workflow21 } from "@workglow/task-graph";
3515
+ import { CreateWorkflow as CreateWorkflow19, Task as Task10, Workflow as Workflow19 } from "@workglow/task-graph";
4199
3516
  import { uuid4 } from "@workglow/util";
4200
- var modelSchema14 = TypeModel("model", {
3517
+ var modelSchema12 = TypeModel("model", {
4201
3518
  title: "Model",
4202
3519
  description: "Model to use for token counting"
4203
3520
  });
@@ -4243,7 +3560,7 @@ var inputSchema9 = {
4243
3560
  description: "Strategy for chunking",
4244
3561
  default: "hierarchical"
4245
3562
  },
4246
- model: modelSchema14
3563
+ model: modelSchema12
4247
3564
  },
4248
3565
  required: ["doc_id", "documentTree"],
4249
3566
  additionalProperties: false
@@ -4278,7 +3595,7 @@ var outputSchema9 = {
4278
3595
  additionalProperties: false
4279
3596
  };
4280
3597
 
4281
- class HierarchicalChunkerTask extends Task11 {
3598
+ class HierarchicalChunkerTask extends Task10 {
4282
3599
  static type = "HierarchicalChunkerTask";
4283
3600
  static category = "Document";
4284
3601
  static title = "Hierarchical Chunker";
@@ -4422,11 +3739,11 @@ class HierarchicalChunkerTask extends Task11 {
4422
3739
  var hierarchicalChunker = (input, config) => {
4423
3740
  return new HierarchicalChunkerTask(config).run(input);
4424
3741
  };
4425
- Workflow21.prototype.hierarchicalChunker = CreateWorkflow21(HierarchicalChunkerTask);
3742
+ Workflow19.prototype.hierarchicalChunker = CreateWorkflow19(HierarchicalChunkerTask);
4426
3743
 
4427
3744
  // src/task/HierarchyJoinTask.ts
4428
3745
  import { ChunkRecordArraySchema, TypeKnowledgeBase as TypeKnowledgeBase6 } from "@workglow/knowledge-base";
4429
- import { CreateWorkflow as CreateWorkflow22, Task as Task12, Workflow as Workflow22 } from "@workglow/task-graph";
3746
+ import { CreateWorkflow as CreateWorkflow20, Task as Task11, Workflow as Workflow20 } from "@workglow/task-graph";
4430
3747
  var inputSchema10 = {
4431
3748
  type: "object",
4432
3749
  properties: {
@@ -4501,7 +3818,7 @@ var outputSchema10 = {
4501
3818
  additionalProperties: false
4502
3819
  };
4503
3820
 
4504
- class HierarchyJoinTask extends Task12 {
3821
+ class HierarchyJoinTask extends Task11 {
4505
3822
  static type = "HierarchyJoinTask";
4506
3823
  static category = "RAG";
4507
3824
  static title = "Hierarchy Join";
@@ -4595,16 +3912,105 @@ class HierarchyJoinTask extends Task12 {
4595
3912
  var hierarchyJoin = (input, config) => {
4596
3913
  return new HierarchyJoinTask(config).run(input);
4597
3914
  };
4598
- Workflow22.prototype.hierarchyJoin = CreateWorkflow22(HierarchyJoinTask);
3915
+ Workflow20.prototype.hierarchyJoin = CreateWorkflow20(HierarchyJoinTask);
3916
+
3917
+ // src/task/KbToDocumentsTask.ts
3918
+ import { TypeKnowledgeBase as TypeKnowledgeBase7 } from "@workglow/knowledge-base";
3919
+ import { CreateWorkflow as CreateWorkflow21, Task as Task12, Workflow as Workflow21 } from "@workglow/task-graph";
3920
+ var inputSchema11 = {
3921
+ type: "object",
3922
+ properties: {
3923
+ knowledgeBase: TypeKnowledgeBase7({
3924
+ title: "Knowledge Base",
3925
+ description: "The knowledge base instance to list documents from"
3926
+ }),
3927
+ onlyStale: {
3928
+ type: "boolean",
3929
+ title: "Only Stale",
3930
+ description: "If true, only return documents that have no chunks (need embedding)",
3931
+ default: true
3932
+ }
3933
+ },
3934
+ required: ["knowledgeBase"],
3935
+ additionalProperties: false
3936
+ };
3937
+ var outputSchema11 = {
3938
+ type: "object",
3939
+ properties: {
3940
+ doc_id: {
3941
+ type: "array",
3942
+ items: { type: "string" },
3943
+ title: "Document IDs",
3944
+ description: "Array of document IDs"
3945
+ },
3946
+ documentTree: {
3947
+ type: "array",
3948
+ items: { type: "object", additionalProperties: true },
3949
+ title: "Document Trees",
3950
+ description: "Array of document root nodes (parallel to doc_id)"
3951
+ },
3952
+ title: {
3953
+ type: "array",
3954
+ items: { type: "string" },
3955
+ title: "Titles",
3956
+ description: "Array of document titles (parallel to doc_id)"
3957
+ }
3958
+ },
3959
+ required: ["doc_id", "documentTree", "title"],
3960
+ additionalProperties: false
3961
+ };
3962
+
3963
+ class KbToDocumentsTask extends Task12 {
3964
+ static type = "KbToDocumentsTask";
3965
+ static category = "Vector Store";
3966
+ static title = "Knowledge Base to Documents";
3967
+ static description = "List documents from a knowledge base, optionally filtering to only those that need embedding";
3968
+ static cacheable = false;
3969
+ static inputSchema() {
3970
+ return inputSchema11;
3971
+ }
3972
+ static outputSchema() {
3973
+ return outputSchema11;
3974
+ }
3975
+ async execute(input, context) {
3976
+ const { knowledgeBase, onlyStale = true } = input;
3977
+ const kb = knowledgeBase;
3978
+ await context.updateProgress(1, "Listing documents");
3979
+ const allDocIds = await kb.listDocuments();
3980
+ const doc_id = [];
3981
+ const documentTree = [];
3982
+ const title = [];
3983
+ for (const id of allDocIds) {
3984
+ if (onlyStale) {
3985
+ const chunks = await kb.getChunksForDocument(id);
3986
+ if (chunks.length > 0) {
3987
+ continue;
3988
+ }
3989
+ }
3990
+ const doc = await kb.getDocument(id);
3991
+ if (!doc) {
3992
+ continue;
3993
+ }
3994
+ doc_id.push(id);
3995
+ documentTree.push(doc.root);
3996
+ title.push(doc.metadata.title);
3997
+ }
3998
+ return { doc_id, documentTree, title };
3999
+ }
4000
+ }
4001
+ var kbToDocuments = (input, config) => {
4002
+ return new KbToDocumentsTask(config).run(input);
4003
+ };
4004
+ Workflow21.prototype.kbToDocuments = CreateWorkflow21(KbToDocumentsTask);
4599
4005
 
4600
4006
  // src/task/ImageClassificationTask.ts
4601
- import { CreateWorkflow as CreateWorkflow23, Workflow as Workflow23 } from "@workglow/task-graph";
4602
- var modelSchema15 = TypeModel("model:ImageClassificationTask");
4007
+ import { CreateWorkflow as CreateWorkflow22, Workflow as Workflow22 } from "@workglow/task-graph";
4008
+ var modelSchema13 = TypeModel("model:ImageClassificationTask");
4603
4009
  var ImageClassificationInputSchema = {
4604
4010
  type: "object",
4605
4011
  properties: {
4606
4012
  image: TypeImageInput,
4607
- model: modelSchema15,
4013
+ model: modelSchema13,
4608
4014
  categories: {
4609
4015
  type: "array",
4610
4016
  items: {
@@ -4658,19 +4064,19 @@ class ImageClassificationTask extends AiVisionTask {
4658
4064
  var imageClassification = (input, config) => {
4659
4065
  return new ImageClassificationTask(config).run(input);
4660
4066
  };
4661
- Workflow23.prototype.imageClassification = CreateWorkflow23(ImageClassificationTask);
4067
+ Workflow22.prototype.imageClassification = CreateWorkflow22(ImageClassificationTask);
4662
4068
 
4663
4069
  // src/task/ImageEmbeddingTask.ts
4664
- import { CreateWorkflow as CreateWorkflow24, Workflow as Workflow24 } from "@workglow/task-graph";
4070
+ import { CreateWorkflow as CreateWorkflow23, Workflow as Workflow23 } from "@workglow/task-graph";
4665
4071
  import {
4666
4072
  TypedArraySchema as TypedArraySchema7
4667
4073
  } from "@workglow/util/schema";
4668
- var modelSchema16 = TypeModel("model:ImageEmbeddingTask");
4074
+ var modelSchema14 = TypeModel("model:ImageEmbeddingTask");
4669
4075
  var ImageEmbeddingInputSchema = {
4670
4076
  type: "object",
4671
4077
  properties: {
4672
4078
  image: TypeSingleOrArray(TypeImageInput),
4673
- model: modelSchema16
4079
+ model: modelSchema14
4674
4080
  },
4675
4081
  required: ["image", "model"],
4676
4082
  additionalProperties: false
@@ -4702,16 +4108,16 @@ class ImageEmbeddingTask extends AiVisionTask {
4702
4108
  var imageEmbedding = (input, config) => {
4703
4109
  return new ImageEmbeddingTask(config).run(input);
4704
4110
  };
4705
- Workflow24.prototype.imageEmbedding = CreateWorkflow24(ImageEmbeddingTask);
4111
+ Workflow23.prototype.imageEmbedding = CreateWorkflow23(ImageEmbeddingTask);
4706
4112
 
4707
4113
  // src/task/ImageSegmentationTask.ts
4708
- import { CreateWorkflow as CreateWorkflow25, Workflow as Workflow25 } from "@workglow/task-graph";
4709
- var modelSchema17 = TypeModel("model:ImageSegmentationTask");
4114
+ import { CreateWorkflow as CreateWorkflow24, Workflow as Workflow24 } from "@workglow/task-graph";
4115
+ var modelSchema15 = TypeModel("model:ImageSegmentationTask");
4710
4116
  var ImageSegmentationInputSchema = {
4711
4117
  type: "object",
4712
4118
  properties: {
4713
4119
  image: TypeImageInput,
4714
- model: modelSchema17,
4120
+ model: modelSchema15,
4715
4121
  threshold: {
4716
4122
  type: "number",
4717
4123
  title: "Threshold",
@@ -4790,11 +4196,11 @@ class ImageSegmentationTask extends AiVisionTask {
4790
4196
  var imageSegmentation = (input, config) => {
4791
4197
  return new ImageSegmentationTask(config).run(input);
4792
4198
  };
4793
- Workflow25.prototype.imageSegmentation = CreateWorkflow25(ImageSegmentationTask);
4199
+ Workflow24.prototype.imageSegmentation = CreateWorkflow24(ImageSegmentationTask);
4794
4200
 
4795
4201
  // src/task/ImageToTextTask.ts
4796
- import { CreateWorkflow as CreateWorkflow26, Workflow as Workflow26 } from "@workglow/task-graph";
4797
- var modelSchema18 = TypeModel("model:ImageToTextTask");
4202
+ import { CreateWorkflow as CreateWorkflow25, Workflow as Workflow25 } from "@workglow/task-graph";
4203
+ var modelSchema16 = TypeModel("model:ImageToTextTask");
4798
4204
  var generatedTextSchema = {
4799
4205
  type: "string",
4800
4206
  title: "Text",
@@ -4804,7 +4210,7 @@ var ImageToTextInputSchema = {
4804
4210
  type: "object",
4805
4211
  properties: {
4806
4212
  image: TypeImageInput,
4807
- model: modelSchema18,
4213
+ model: modelSchema16,
4808
4214
  maxTokens: {
4809
4215
  type: "number",
4810
4216
  title: "Max Tokens",
@@ -4845,18 +4251,18 @@ class ImageToTextTask extends AiVisionTask {
4845
4251
  var imageToText = (input, config) => {
4846
4252
  return new ImageToTextTask(config).run(input);
4847
4253
  };
4848
- Workflow26.prototype.imageToText = CreateWorkflow26(ImageToTextTask);
4254
+ Workflow25.prototype.imageToText = CreateWorkflow25(ImageToTextTask);
4849
4255
 
4850
4256
  // src/task/ModelInfoTask.ts
4851
- import { CreateWorkflow as CreateWorkflow27, Workflow as Workflow27 } from "@workglow/task-graph";
4852
- var modelSchema19 = TypeModel("model");
4257
+ import { CreateWorkflow as CreateWorkflow26, Workflow as Workflow26 } from "@workglow/task-graph";
4258
+ var modelSchema17 = TypeModel("model");
4853
4259
  var ModelInfoInputSchema = {
4854
4260
  type: "object",
4855
4261
  properties: {
4856
- model: modelSchema19,
4262
+ model: modelSchema17,
4857
4263
  detail: {
4858
4264
  type: "string",
4859
- enum: ["cached_status", "files", "files_with_metadata"],
4265
+ enum: ["cached_status", "files", "files_with_metadata", "dimensions"],
4860
4266
  default: "files_with_metadata"
4861
4267
  }
4862
4268
  },
@@ -4866,7 +4272,7 @@ var ModelInfoInputSchema = {
4866
4272
  var ModelInfoOutputSchema = {
4867
4273
  type: "object",
4868
4274
  properties: {
4869
- model: modelSchema19,
4275
+ model: modelSchema17,
4870
4276
  is_local: { type: "boolean" },
4871
4277
  is_remote: { type: "boolean" },
4872
4278
  supports_browser: { type: "boolean" },
@@ -4878,6 +4284,14 @@ var ModelInfoOutputSchema = {
4878
4284
  type: "array",
4879
4285
  items: { type: "string" },
4880
4286
  description: "Available quantization variants (e.g. fp32, fp16, q8). Only present for models with quantization options."
4287
+ },
4288
+ native_dimensions: {
4289
+ type: "integer",
4290
+ description: "Native output vector dimensions. Only present when detail is 'dimensions' and the provider can determine them."
4291
+ },
4292
+ mrl: {
4293
+ type: "boolean",
4294
+ description: "Whether the model supports Matryoshka Representation Learning. Only present when detail is 'dimensions'."
4881
4295
  }
4882
4296
  },
4883
4297
  required: [
@@ -4916,10 +4330,10 @@ class ModelInfoTask extends AiTask {
4916
4330
  var modelInfo = (input, config) => {
4917
4331
  return new ModelInfoTask(config).run(input);
4918
4332
  };
4919
- Workflow27.prototype.modelInfo = CreateWorkflow27(ModelInfoTask);
4333
+ Workflow26.prototype.modelInfo = CreateWorkflow26(ModelInfoTask);
4920
4334
 
4921
4335
  // src/task/ModelSearchTask.ts
4922
- import { CreateWorkflow as CreateWorkflow28, Task as Task13, Workflow as Workflow28 } from "@workglow/task-graph";
4336
+ import { CreateWorkflow as CreateWorkflow27, Task as Task13, Workflow as Workflow27 } from "@workglow/task-graph";
4923
4337
  var ModelSearchInputSchema = {
4924
4338
  type: "object",
4925
4339
  properties: {
@@ -5010,11 +4424,11 @@ class ModelSearchTask extends Task13 {
5010
4424
  var modelSearch = (input, config) => {
5011
4425
  return new ModelSearchTask(config).run(input);
5012
4426
  };
5013
- Workflow28.prototype.modelSearch = CreateWorkflow28(ModelSearchTask);
4427
+ Workflow27.prototype.modelSearch = CreateWorkflow27(ModelSearchTask);
5014
4428
 
5015
4429
  // src/task/ObjectDetectionTask.ts
5016
- import { CreateWorkflow as CreateWorkflow29, Workflow as Workflow29 } from "@workglow/task-graph";
5017
- var modelSchema20 = TypeModel("model:ObjectDetectionTask");
4430
+ import { CreateWorkflow as CreateWorkflow28, Workflow as Workflow28 } from "@workglow/task-graph";
4431
+ var modelSchema18 = TypeModel("model:ObjectDetectionTask");
5018
4432
  var detectionSchema = {
5019
4433
  type: "object",
5020
4434
  properties: {
@@ -5039,7 +4453,7 @@ var ObjectDetectionInputSchema = {
5039
4453
  type: "object",
5040
4454
  properties: {
5041
4455
  image: TypeImageInput,
5042
- model: modelSchema20,
4456
+ model: modelSchema18,
5043
4457
  labels: {
5044
4458
  type: "array",
5045
4459
  items: {
@@ -5093,11 +4507,11 @@ class ObjectDetectionTask extends AiVisionTask {
5093
4507
  var objectDetection = (input, config) => {
5094
4508
  return new ObjectDetectionTask(config).run(input);
5095
4509
  };
5096
- Workflow29.prototype.objectDetection = CreateWorkflow29(ObjectDetectionTask);
4510
+ Workflow28.prototype.objectDetection = CreateWorkflow28(ObjectDetectionTask);
5097
4511
 
5098
4512
  // src/task/PoseLandmarkerTask.ts
5099
- import { CreateWorkflow as CreateWorkflow30, Workflow as Workflow30 } from "@workglow/task-graph";
5100
- var modelSchema21 = TypeModel("model:PoseLandmarkerTask");
4513
+ import { CreateWorkflow as CreateWorkflow29, Workflow as Workflow29 } from "@workglow/task-graph";
4514
+ var modelSchema19 = TypeModel("model:PoseLandmarkerTask");
5101
4515
  var TypePoseLandmark = {
5102
4516
  type: "object",
5103
4517
  properties: {
@@ -5176,7 +4590,7 @@ var PoseLandmarkerInputSchema = {
5176
4590
  type: "object",
5177
4591
  properties: {
5178
4592
  image: TypeImageInput,
5179
- model: modelSchema21,
4593
+ model: modelSchema19,
5180
4594
  numPoses: {
5181
4595
  type: "number",
5182
4596
  minimum: 1,
@@ -5255,17 +4669,17 @@ class PoseLandmarkerTask extends AiVisionTask {
5255
4669
  var poseLandmarker = (input, config) => {
5256
4670
  return new PoseLandmarkerTask(config).run(input);
5257
4671
  };
5258
- Workflow30.prototype.poseLandmarker = CreateWorkflow30(PoseLandmarkerTask);
4672
+ Workflow29.prototype.poseLandmarker = CreateWorkflow29(PoseLandmarkerTask);
5259
4673
 
5260
4674
  // src/task/QueryExpanderTask.ts
5261
- import { CreateWorkflow as CreateWorkflow31, Task as Task14, Workflow as Workflow31 } from "@workglow/task-graph";
4675
+ import { CreateWorkflow as CreateWorkflow30, Task as Task14, Workflow as Workflow30 } from "@workglow/task-graph";
5262
4676
  var QueryExpansionMethod = {
5263
4677
  MULTI_QUERY: "multi-query",
5264
4678
  HYDE: "hyde",
5265
4679
  SYNONYMS: "synonyms",
5266
4680
  PARAPHRASE: "paraphrase"
5267
4681
  };
5268
- var inputSchema11 = {
4682
+ var inputSchema12 = {
5269
4683
  type: "object",
5270
4684
  properties: {
5271
4685
  query: {
@@ -5297,7 +4711,7 @@ var inputSchema11 = {
5297
4711
  required: ["query"],
5298
4712
  additionalProperties: false
5299
4713
  };
5300
- var outputSchema11 = {
4714
+ var outputSchema12 = {
5301
4715
  type: "object",
5302
4716
  properties: {
5303
4717
  query: {
@@ -5333,10 +4747,10 @@ class QueryExpanderTask extends Task14 {
5333
4747
  static description = "Expand queries to improve retrieval coverage";
5334
4748
  static cacheable = true;
5335
4749
  static inputSchema() {
5336
- return inputSchema11;
4750
+ return inputSchema12;
5337
4751
  }
5338
4752
  static outputSchema() {
5339
- return outputSchema11;
4753
+ return outputSchema12;
5340
4754
  }
5341
4755
  async execute(input, context) {
5342
4756
  const { query, method = QueryExpansionMethod.MULTI_QUERY, numVariations = 3 } = input;
@@ -5468,14 +4882,14 @@ class QueryExpanderTask extends Task14 {
5468
4882
  var queryExpander = (input, config) => {
5469
4883
  return new QueryExpanderTask(config).run(input);
5470
4884
  };
5471
- Workflow31.prototype.queryExpander = CreateWorkflow31(QueryExpanderTask);
4885
+ Workflow30.prototype.queryExpander = CreateWorkflow30(QueryExpanderTask);
5472
4886
 
5473
4887
  // src/task/RerankerTask.ts
5474
- import { CreateWorkflow as CreateWorkflow33, Task as Task15, Workflow as Workflow33 } from "@workglow/task-graph";
4888
+ import { CreateWorkflow as CreateWorkflow32, Task as Task15, Workflow as Workflow32 } from "@workglow/task-graph";
5475
4889
 
5476
4890
  // src/task/TextClassificationTask.ts
5477
- import { CreateWorkflow as CreateWorkflow32, Workflow as Workflow32 } from "@workglow/task-graph";
5478
- var modelSchema22 = TypeModel("model:TextClassificationTask");
4891
+ import { CreateWorkflow as CreateWorkflow31, Workflow as Workflow31 } from "@workglow/task-graph";
4892
+ var modelSchema20 = TypeModel("model:TextClassificationTask");
5479
4893
  var TextClassificationInputSchema = {
5480
4894
  type: "object",
5481
4895
  properties: {
@@ -5502,7 +4916,7 @@ var TextClassificationInputSchema = {
5502
4916
  description: "The maximum number of categories to return",
5503
4917
  "x-ui-group": "Configuration"
5504
4918
  },
5505
- model: modelSchema22
4919
+ model: modelSchema20
5506
4920
  },
5507
4921
  required: ["text", "model"],
5508
4922
  additionalProperties: false
@@ -5552,10 +4966,10 @@ class TextClassificationTask extends AiTask {
5552
4966
  var textClassification = (input, config) => {
5553
4967
  return new TextClassificationTask(config).run(input);
5554
4968
  };
5555
- Workflow32.prototype.textClassification = CreateWorkflow32(TextClassificationTask);
4969
+ Workflow31.prototype.textClassification = CreateWorkflow31(TextClassificationTask);
5556
4970
 
5557
4971
  // src/task/RerankerTask.ts
5558
- var inputSchema12 = {
4972
+ var inputSchema13 = {
5559
4973
  type: "object",
5560
4974
  properties: {
5561
4975
  query: {
@@ -5606,7 +5020,7 @@ var inputSchema12 = {
5606
5020
  required: ["query", "chunks"],
5607
5021
  additionalProperties: false
5608
5022
  };
5609
- var outputSchema12 = {
5023
+ var outputSchema13 = {
5610
5024
  type: "object",
5611
5025
  properties: {
5612
5026
  chunks: {
@@ -5654,10 +5068,10 @@ class RerankerTask extends Task15 {
5654
5068
  static description = "Rerank retrieved chunks to improve relevance";
5655
5069
  static cacheable = true;
5656
5070
  static inputSchema() {
5657
- return inputSchema12;
5071
+ return inputSchema13;
5658
5072
  }
5659
5073
  static outputSchema() {
5660
- return outputSchema12;
5074
+ return outputSchema13;
5661
5075
  }
5662
5076
  async execute(input, context) {
5663
5077
  const { query, chunks, scores = [], metadata = [], topK, method = "simple", model } = input;
@@ -5775,13 +5189,13 @@ class RerankerTask extends Task15 {
5775
5189
  var reranker = (input, config) => {
5776
5190
  return new RerankerTask(config).run(input);
5777
5191
  };
5778
- Workflow33.prototype.reranker = CreateWorkflow33(RerankerTask);
5192
+ Workflow32.prototype.reranker = CreateWorkflow32(RerankerTask);
5779
5193
 
5780
5194
  // src/task/StructuralParserTask.ts
5781
5195
  import { StructuralParser } from "@workglow/knowledge-base";
5782
- import { CreateWorkflow as CreateWorkflow34, Task as Task16, Workflow as Workflow34 } from "@workglow/task-graph";
5196
+ import { CreateWorkflow as CreateWorkflow33, Task as Task16, Workflow as Workflow33 } from "@workglow/task-graph";
5783
5197
  import { uuid4 as uuid42 } from "@workglow/util";
5784
- var inputSchema13 = {
5198
+ var inputSchema14 = {
5785
5199
  type: "object",
5786
5200
  properties: {
5787
5201
  text: {
@@ -5815,7 +5229,7 @@ var inputSchema13 = {
5815
5229
  required: ["text", "title"],
5816
5230
  additionalProperties: false
5817
5231
  };
5818
- var outputSchema13 = {
5232
+ var outputSchema14 = {
5819
5233
  type: "object",
5820
5234
  properties: {
5821
5235
  doc_id: {
@@ -5846,10 +5260,10 @@ class StructuralParserTask extends Task16 {
5846
5260
  static description = "Parse documents into hierarchical tree structure";
5847
5261
  static cacheable = true;
5848
5262
  static inputSchema() {
5849
- return inputSchema13;
5263
+ return inputSchema14;
5850
5264
  }
5851
5265
  static outputSchema() {
5852
- return outputSchema13;
5266
+ return outputSchema14;
5853
5267
  }
5854
5268
  async execute(input, context) {
5855
5269
  const { text, title, format = "auto", sourceUri, doc_id: providedDocId } = input;
@@ -5882,15 +5296,15 @@ class StructuralParserTask extends Task16 {
5882
5296
  var structuralParser = (input, config) => {
5883
5297
  return new StructuralParserTask(config).run(input);
5884
5298
  };
5885
- Workflow34.prototype.structuralParser = CreateWorkflow34(StructuralParserTask);
5299
+ Workflow33.prototype.structuralParser = CreateWorkflow33(StructuralParserTask);
5886
5300
 
5887
5301
  // src/task/StructuredGenerationTask.ts
5888
- import { CreateWorkflow as CreateWorkflow35, Workflow as Workflow35 } from "@workglow/task-graph";
5889
- var modelSchema23 = TypeModel("model:StructuredGenerationTask");
5302
+ import { CreateWorkflow as CreateWorkflow34, Workflow as Workflow34 } from "@workglow/task-graph";
5303
+ var modelSchema21 = TypeModel("model:StructuredGenerationTask");
5890
5304
  var StructuredGenerationInputSchema = {
5891
5305
  type: "object",
5892
5306
  properties: {
5893
- model: modelSchema23,
5307
+ model: modelSchema21,
5894
5308
  prompt: {
5895
5309
  type: "string",
5896
5310
  title: "Prompt",
@@ -5953,17 +5367,17 @@ class StructuredGenerationTask extends StreamingAiTask {
5953
5367
  var structuredGeneration = (input, config) => {
5954
5368
  return new StructuredGenerationTask(config).run(input);
5955
5369
  };
5956
- Workflow35.prototype.structuredGeneration = CreateWorkflow35(StructuredGenerationTask);
5370
+ Workflow34.prototype.structuredGeneration = CreateWorkflow34(StructuredGenerationTask);
5957
5371
 
5958
5372
  // src/task/TextChunkerTask.ts
5959
- import { CreateWorkflow as CreateWorkflow36, Task as Task17, Workflow as Workflow36 } from "@workglow/task-graph";
5373
+ import { CreateWorkflow as CreateWorkflow35, Task as Task17, Workflow as Workflow35 } from "@workglow/task-graph";
5960
5374
  var ChunkingStrategy = {
5961
5375
  FIXED: "fixed",
5962
5376
  SENTENCE: "sentence",
5963
5377
  PARAGRAPH: "paragraph",
5964
5378
  SEMANTIC: "semantic"
5965
5379
  };
5966
- var inputSchema14 = {
5380
+ var inputSchema15 = {
5967
5381
  type: "object",
5968
5382
  properties: {
5969
5383
  text: {
@@ -5996,7 +5410,7 @@ var inputSchema14 = {
5996
5410
  required: ["text"],
5997
5411
  additionalProperties: false
5998
5412
  };
5999
- var outputSchema14 = {
5413
+ var outputSchema15 = {
6000
5414
  type: "object",
6001
5415
  properties: {
6002
5416
  chunks: {
@@ -6032,10 +5446,10 @@ class TextChunkerTask extends Task17 {
6032
5446
  static description = "Splits text into chunks using various strategies (fixed, sentence, paragraph)";
6033
5447
  static cacheable = true;
6034
5448
  static inputSchema() {
6035
- return inputSchema14;
5449
+ return inputSchema15;
6036
5450
  }
6037
5451
  static outputSchema() {
6038
- return outputSchema14;
5452
+ return outputSchema15;
6039
5453
  }
6040
5454
  async execute(input, context) {
6041
5455
  const { text, chunkSize = 512, chunkOverlap = 50, strategy = ChunkingStrategy.FIXED } = input;
@@ -6205,11 +5619,11 @@ class TextChunkerTask extends Task17 {
6205
5619
  var textChunker = (input, config) => {
6206
5620
  return new TextChunkerTask(config).run(input);
6207
5621
  };
6208
- Workflow36.prototype.textChunker = CreateWorkflow36(TextChunkerTask);
5622
+ Workflow35.prototype.textChunker = CreateWorkflow35(TextChunkerTask);
6209
5623
 
6210
5624
  // src/task/TextFillMaskTask.ts
6211
- import { CreateWorkflow as CreateWorkflow37, Workflow as Workflow37 } from "@workglow/task-graph";
6212
- var modelSchema24 = TypeModel("model:TextFillMaskTask");
5625
+ import { CreateWorkflow as CreateWorkflow36, Workflow as Workflow36 } from "@workglow/task-graph";
5626
+ var modelSchema22 = TypeModel("model:TextFillMaskTask");
6213
5627
  var TextFillMaskInputSchema = {
6214
5628
  type: "object",
6215
5629
  properties: {
@@ -6218,7 +5632,7 @@ var TextFillMaskInputSchema = {
6218
5632
  title: "Text",
6219
5633
  description: "The text with a mask token to fill"
6220
5634
  },
6221
- model: modelSchema24
5635
+ model: modelSchema22
6222
5636
  },
6223
5637
  required: ["text", "model"],
6224
5638
  additionalProperties: false
@@ -6273,21 +5687,21 @@ class TextFillMaskTask extends AiTask {
6273
5687
  var textFillMask = (input, config) => {
6274
5688
  return new TextFillMaskTask(config).run(input);
6275
5689
  };
6276
- Workflow37.prototype.textFillMask = CreateWorkflow37(TextFillMaskTask);
5690
+ Workflow36.prototype.textFillMask = CreateWorkflow36(TextFillMaskTask);
6277
5691
 
6278
5692
  // src/task/TextGenerationTask.ts
6279
- import { CreateWorkflow as CreateWorkflow38, Workflow as Workflow38 } from "@workglow/task-graph";
5693
+ import { CreateWorkflow as CreateWorkflow37, Workflow as Workflow37 } from "@workglow/task-graph";
6280
5694
  var generatedTextSchema2 = {
6281
5695
  type: "string",
6282
5696
  title: "Text",
6283
5697
  description: "The generated text",
6284
5698
  "x-stream": "append"
6285
5699
  };
6286
- var modelSchema25 = TypeModel("model:TextGenerationTask");
5700
+ var modelSchema23 = TypeModel("model:TextGenerationTask");
6287
5701
  var TextGenerationInputSchema = {
6288
5702
  type: "object",
6289
5703
  properties: {
6290
- model: modelSchema25,
5704
+ model: modelSchema23,
6291
5705
  prompt: {
6292
5706
  type: "string",
6293
5707
  title: "Prompt",
@@ -6361,11 +5775,11 @@ class TextGenerationTask extends StreamingAiTask {
6361
5775
  var textGeneration = (input, config) => {
6362
5776
  return new TextGenerationTask(config).run(input);
6363
5777
  };
6364
- Workflow38.prototype.textGeneration = CreateWorkflow38(TextGenerationTask);
5778
+ Workflow37.prototype.textGeneration = CreateWorkflow37(TextGenerationTask);
6365
5779
 
6366
5780
  // src/task/TextLanguageDetectionTask.ts
6367
- import { CreateWorkflow as CreateWorkflow39, Workflow as Workflow39 } from "@workglow/task-graph";
6368
- var modelSchema26 = TypeModel("model:TextLanguageDetectionTask");
5781
+ import { CreateWorkflow as CreateWorkflow38, Workflow as Workflow38 } from "@workglow/task-graph";
5782
+ var modelSchema24 = TypeModel("model:TextLanguageDetectionTask");
6369
5783
  var TextLanguageDetectionInputSchema = {
6370
5784
  type: "object",
6371
5785
  properties: {
@@ -6382,7 +5796,7 @@ var TextLanguageDetectionInputSchema = {
6382
5796
  title: "Max Languages",
6383
5797
  description: "The maximum number of languages to return"
6384
5798
  },
6385
- model: modelSchema26
5799
+ model: modelSchema24
6386
5800
  },
6387
5801
  required: ["text", "model"],
6388
5802
  additionalProperties: false
@@ -6432,10 +5846,10 @@ class TextLanguageDetectionTask extends AiTask {
6432
5846
  var textLanguageDetection = (input, config) => {
6433
5847
  return new TextLanguageDetectionTask(config).run(input);
6434
5848
  };
6435
- Workflow39.prototype.textLanguageDetection = CreateWorkflow39(TextLanguageDetectionTask);
5849
+ Workflow38.prototype.textLanguageDetection = CreateWorkflow38(TextLanguageDetectionTask);
6436
5850
 
6437
5851
  // src/task/TextQuestionAnswerTask.ts
6438
- import { CreateWorkflow as CreateWorkflow40, Workflow as Workflow40 } from "@workglow/task-graph";
5852
+ import { CreateWorkflow as CreateWorkflow39, Workflow as Workflow39 } from "@workglow/task-graph";
6439
5853
  var contextSchema = {
6440
5854
  type: "string",
6441
5855
  title: "Context",
@@ -6452,13 +5866,13 @@ var textSchema = {
6452
5866
  description: "The generated text",
6453
5867
  "x-stream": "append"
6454
5868
  };
6455
- var modelSchema27 = TypeModel("model:TextQuestionAnswerTask");
5869
+ var modelSchema25 = TypeModel("model:TextQuestionAnswerTask");
6456
5870
  var TextQuestionAnswerInputSchema = {
6457
5871
  type: "object",
6458
5872
  properties: {
6459
5873
  context: contextSchema,
6460
5874
  question: questionSchema,
6461
- model: modelSchema27
5875
+ model: modelSchema25
6462
5876
  },
6463
5877
  required: ["context", "question", "model"],
6464
5878
  additionalProperties: false
@@ -6487,11 +5901,11 @@ class TextQuestionAnswerTask extends StreamingAiTask {
6487
5901
  var textQuestionAnswer = (input, config) => {
6488
5902
  return new TextQuestionAnswerTask(config).run(input);
6489
5903
  };
6490
- Workflow40.prototype.textQuestionAnswer = CreateWorkflow40(TextQuestionAnswerTask);
5904
+ Workflow39.prototype.textQuestionAnswer = CreateWorkflow39(TextQuestionAnswerTask);
6491
5905
 
6492
5906
  // src/task/TextRewriterTask.ts
6493
- import { CreateWorkflow as CreateWorkflow41, Workflow as Workflow41 } from "@workglow/task-graph";
6494
- var modelSchema28 = TypeModel("model:TextRewriterTask");
5907
+ import { CreateWorkflow as CreateWorkflow40, Workflow as Workflow40 } from "@workglow/task-graph";
5908
+ var modelSchema26 = TypeModel("model:TextRewriterTask");
6495
5909
  var TextRewriterInputSchema = {
6496
5910
  type: "object",
6497
5911
  properties: {
@@ -6505,7 +5919,7 @@ var TextRewriterInputSchema = {
6505
5919
  title: "Prompt",
6506
5920
  description: "The prompt to direct the rewriting"
6507
5921
  },
6508
- model: modelSchema28
5922
+ model: modelSchema26
6509
5923
  },
6510
5924
  required: ["text", "prompt", "model"],
6511
5925
  additionalProperties: false
@@ -6539,11 +5953,11 @@ class TextRewriterTask extends StreamingAiTask {
6539
5953
  var textRewriter = (input, config) => {
6540
5954
  return new TextRewriterTask(config).run(input);
6541
5955
  };
6542
- Workflow41.prototype.textRewriter = CreateWorkflow41(TextRewriterTask);
5956
+ Workflow40.prototype.textRewriter = CreateWorkflow40(TextRewriterTask);
6543
5957
 
6544
5958
  // src/task/TextTranslationTask.ts
6545
- import { CreateWorkflow as CreateWorkflow42, Workflow as Workflow42 } from "@workglow/task-graph";
6546
- var modelSchema29 = TypeModel("model:TextTranslationTask");
5959
+ import { CreateWorkflow as CreateWorkflow41, Workflow as Workflow41 } from "@workglow/task-graph";
5960
+ var modelSchema27 = TypeModel("model:TextTranslationTask");
6547
5961
  var translationTextSchema = {
6548
5962
  type: "string",
6549
5963
  title: "Text",
@@ -6570,7 +5984,7 @@ var TextTranslationInputSchema = {
6570
5984
  minLength: 2,
6571
5985
  maxLength: 2
6572
5986
  }),
6573
- model: modelSchema29
5987
+ model: modelSchema27
6574
5988
  },
6575
5989
  required: ["text", "source_lang", "target_lang", "model"],
6576
5990
  additionalProperties: false
@@ -6605,7 +6019,250 @@ class TextTranslationTask extends StreamingAiTask {
6605
6019
  var textTranslation = (input, config) => {
6606
6020
  return new TextTranslationTask(config).run(input);
6607
6021
  };
6608
- Workflow42.prototype.textTranslation = CreateWorkflow42(TextTranslationTask);
6022
+ Workflow41.prototype.textTranslation = CreateWorkflow41(TextTranslationTask);
6023
+
6024
+ // src/task/ToolCallingTask.ts
6025
+ import { CreateWorkflow as CreateWorkflow42, getTaskConstructors, Workflow as Workflow42 } from "@workglow/task-graph";
6026
+ import { makeFingerprint } from "@workglow/util";
6027
+ function taskTypesToTools(taskNames, registry) {
6028
+ const constructors = getTaskConstructors(registry);
6029
+ return taskNames.map((name) => {
6030
+ const ctor = constructors.get(name);
6031
+ if (!ctor) {
6032
+ throw new Error(`taskTypesToTools: Unknown task type "${name}" \u2014 not found in task constructors registry (ServiceRegistry: ${registry ? "custom" : "default"})`);
6033
+ }
6034
+ const configSchema = "configSchema" in ctor && typeof ctor.configSchema === "function" ? ctor.configSchema() : undefined;
6035
+ return {
6036
+ name: ctor.type,
6037
+ description: ctor.description ?? "",
6038
+ inputSchema: ctor.inputSchema(),
6039
+ outputSchema: ctor.outputSchema(),
6040
+ ...configSchema ? { configSchema } : {},
6041
+ taskType: name
6042
+ };
6043
+ });
6044
+ }
6045
+ var ToolDefinitionSchema = {
6046
+ type: "object",
6047
+ properties: {
6048
+ name: {
6049
+ type: "string",
6050
+ title: "Name",
6051
+ description: "The tool name"
6052
+ },
6053
+ description: {
6054
+ type: "string",
6055
+ title: "Description",
6056
+ description: "A description of what the tool does"
6057
+ },
6058
+ inputSchema: {
6059
+ type: "object",
6060
+ title: "Input Schema",
6061
+ description: "JSON Schema describing the tool's input parameters",
6062
+ additionalProperties: true
6063
+ },
6064
+ outputSchema: {
6065
+ type: "object",
6066
+ title: "Output Schema",
6067
+ description: "JSON Schema describing what the tool returns",
6068
+ additionalProperties: true
6069
+ },
6070
+ configSchema: {
6071
+ type: "object",
6072
+ title: "Config Schema",
6073
+ description: "JSON Schema describing the task's configuration options (not sent to the LLM)",
6074
+ additionalProperties: true
6075
+ },
6076
+ config: {
6077
+ type: "object",
6078
+ title: "Config",
6079
+ description: "Concrete configuration values for the backing task (not sent to the LLM)",
6080
+ additionalProperties: true
6081
+ }
6082
+ },
6083
+ required: ["name", "description", "inputSchema"],
6084
+ additionalProperties: true
6085
+ };
6086
+ var ToolCallSchema = {
6087
+ type: "object",
6088
+ properties: {
6089
+ id: {
6090
+ type: "string",
6091
+ title: "ID",
6092
+ description: "Unique identifier for this tool call"
6093
+ },
6094
+ name: {
6095
+ type: "string",
6096
+ title: "Name",
6097
+ description: "The name of the tool to invoke"
6098
+ },
6099
+ input: {
6100
+ type: "object",
6101
+ title: "Input",
6102
+ description: "The input arguments for the tool call",
6103
+ additionalProperties: true
6104
+ }
6105
+ },
6106
+ required: ["id", "name", "input"],
6107
+ additionalProperties: false
6108
+ };
6109
+ var modelSchema28 = TypeModel("model:ToolCallingTask");
6110
+ var ToolCallingInputSchema = {
6111
+ type: "object",
6112
+ properties: {
6113
+ model: modelSchema28,
6114
+ prompt: {
6115
+ oneOf: [
6116
+ { type: "string", title: "Prompt", description: "The prompt to send to the model" },
6117
+ {
6118
+ type: "array",
6119
+ title: "Prompt",
6120
+ description: "The prompt as an array of strings or content blocks",
6121
+ items: {
6122
+ oneOf: [
6123
+ { type: "string" },
6124
+ {
6125
+ type: "object",
6126
+ properties: {
6127
+ type: { type: "string", enum: ["text", "image", "audio"] }
6128
+ },
6129
+ required: ["type"],
6130
+ additionalProperties: true
6131
+ }
6132
+ ]
6133
+ }
6134
+ }
6135
+ ],
6136
+ title: "Prompt",
6137
+ description: "The prompt to send to the model"
6138
+ },
6139
+ systemPrompt: {
6140
+ type: "string",
6141
+ title: "System Prompt",
6142
+ description: "Optional system instructions for the model"
6143
+ },
6144
+ messages: {
6145
+ type: "array",
6146
+ title: "Messages",
6147
+ description: "Full conversation history for multi-turn interactions. When provided, used instead of prompt to construct the messages array sent to the provider.",
6148
+ items: {
6149
+ type: "object",
6150
+ properties: {
6151
+ role: { type: "string", enum: ["user", "assistant", "tool"] },
6152
+ content: {}
6153
+ },
6154
+ required: ["role", "content"],
6155
+ additionalProperties: true
6156
+ }
6157
+ },
6158
+ tools: {
6159
+ type: "array",
6160
+ format: "tasks",
6161
+ title: "Tools",
6162
+ description: "Tool definitions available for the model to call",
6163
+ items: {
6164
+ oneOf: [
6165
+ { type: "string", format: "tasks", description: "Task type name" },
6166
+ ToolDefinitionSchema
6167
+ ]
6168
+ }
6169
+ },
6170
+ toolChoice: {
6171
+ type: "string",
6172
+ title: "Tool Choice",
6173
+ description: 'Controls tool selection: "auto" (model decides), "none" (no tools), "required" (must call a tool), or a specific tool name',
6174
+ "x-ui-group": "Configuration"
6175
+ },
6176
+ maxTokens: {
6177
+ type: "number",
6178
+ title: "Max Tokens",
6179
+ description: "The maximum number of tokens to generate",
6180
+ minimum: 1,
6181
+ "x-ui-group": "Configuration"
6182
+ },
6183
+ temperature: {
6184
+ type: "number",
6185
+ title: "Temperature",
6186
+ description: "The temperature to use for sampling",
6187
+ minimum: 0,
6188
+ maximum: 2,
6189
+ "x-ui-group": "Configuration"
6190
+ }
6191
+ },
6192
+ required: ["model", "prompt", "tools"],
6193
+ additionalProperties: false
6194
+ };
6195
+ var ToolCallingOutputSchema = {
6196
+ type: "object",
6197
+ properties: {
6198
+ text: {
6199
+ type: "string",
6200
+ title: "Text",
6201
+ description: "Any text content generated by the model",
6202
+ "x-stream": "append"
6203
+ },
6204
+ toolCalls: {
6205
+ type: "array",
6206
+ items: ToolCallSchema,
6207
+ title: "Tool Calls",
6208
+ description: "Tool calls requested by the model",
6209
+ "x-stream": "object"
6210
+ }
6211
+ },
6212
+ required: ["text", "toolCalls"],
6213
+ additionalProperties: false
6214
+ };
6215
+
6216
+ class ToolCallingTask extends StreamingAiTask {
6217
+ static type = "ToolCallingTask";
6218
+ static category = "AI Text Model";
6219
+ static title = "Tool Calling";
6220
+ static description = "Sends a prompt with tool definitions to a language model and returns text along with any tool calls the model requests";
6221
+ static inputSchema() {
6222
+ return ToolCallingInputSchema;
6223
+ }
6224
+ static outputSchema() {
6225
+ return ToolCallingOutputSchema;
6226
+ }
6227
+ _computedSessionId;
6228
+ async getJobInput(input) {
6229
+ const jobInput = await super.getJobInput(input);
6230
+ if (!jobInput.sessionId && input.tools && input.tools.length > 0) {
6231
+ jobInput.sessionId = await makeFingerprint({
6232
+ tools: input.tools,
6233
+ systemPrompt: input.systemPrompt,
6234
+ runnerId: this.runConfig.runnerId
6235
+ });
6236
+ this._computedSessionId = jobInput.sessionId;
6237
+ }
6238
+ return jobInput;
6239
+ }
6240
+ registerSessionDispose(input, context) {
6241
+ const sessionId = this._computedSessionId;
6242
+ if (!sessionId || !context.resourceScope)
6243
+ return;
6244
+ const model = input.model;
6245
+ if (!model || typeof model !== "object")
6246
+ return;
6247
+ const providerName = model.provider;
6248
+ context.resourceScope.register(`ai:session:${sessionId}`, async () => {
6249
+ await getAiProviderRegistry().disposeSession(providerName, sessionId);
6250
+ });
6251
+ }
6252
+ async execute(input, executeContext) {
6253
+ const result = await super.execute(input, executeContext);
6254
+ this.registerSessionDispose(input, executeContext);
6255
+ return result;
6256
+ }
6257
+ async* executeStream(input, context) {
6258
+ yield* super.executeStream(input, context);
6259
+ this.registerSessionDispose(input, context);
6260
+ }
6261
+ }
6262
+ var toolCalling = (input, config) => {
6263
+ return new ToolCallingTask(config).run(input);
6264
+ };
6265
+ Workflow42.prototype.toolCalling = CreateWorkflow42(ToolCallingTask);
6609
6266
 
6610
6267
  // src/task/TopicSegmenterTask.ts
6611
6268
  import { CreateWorkflow as CreateWorkflow43, Task as Task18, Workflow as Workflow43 } from "@workglow/task-graph";
@@ -6614,7 +6271,7 @@ var SegmentationMethod = {
6614
6271
  EMBEDDING_SIMILARITY: "embedding-similarity",
6615
6272
  HYBRID: "hybrid"
6616
6273
  };
6617
- var inputSchema15 = {
6274
+ var inputSchema16 = {
6618
6275
  type: "object",
6619
6276
  properties: {
6620
6277
  text: {
@@ -6655,7 +6312,7 @@ var inputSchema15 = {
6655
6312
  required: ["text"],
6656
6313
  additionalProperties: false
6657
6314
  };
6658
- var outputSchema15 = {
6315
+ var outputSchema16 = {
6659
6316
  type: "object",
6660
6317
  properties: {
6661
6318
  segments: {
@@ -6691,10 +6348,10 @@ class TopicSegmenterTask extends Task18 {
6691
6348
  static cacheable = true;
6692
6349
  static EMBEDDING_DIMENSIONS = 256;
6693
6350
  static inputSchema() {
6694
- return inputSchema15;
6351
+ return inputSchema16;
6695
6352
  }
6696
6353
  static outputSchema() {
6697
- return outputSchema15;
6354
+ return outputSchema16;
6698
6355
  }
6699
6356
  async execute(input, context) {
6700
6357
  const {
@@ -6892,11 +6549,11 @@ Workflow43.prototype.topicSegmenter = CreateWorkflow43(TopicSegmenterTask);
6892
6549
 
6893
6550
  // src/task/UnloadModelTask.ts
6894
6551
  import { CreateWorkflow as CreateWorkflow44, Workflow as Workflow44 } from "@workglow/task-graph";
6895
- var modelSchema30 = TypeModel("model");
6552
+ var modelSchema29 = TypeModel("model");
6896
6553
  var UnloadModelInputSchema = {
6897
6554
  type: "object",
6898
6555
  properties: {
6899
- model: modelSchema30
6556
+ model: modelSchema29
6900
6557
  },
6901
6558
  required: ["model"],
6902
6559
  additionalProperties: false
@@ -6904,7 +6561,7 @@ var UnloadModelInputSchema = {
6904
6561
  var UnloadModelOutputSchema = {
6905
6562
  type: "object",
6906
6563
  properties: {
6907
- model: modelSchema30
6564
+ model: modelSchema29
6908
6565
  },
6909
6566
  required: ["model"],
6910
6567
  additionalProperties: false
@@ -6935,7 +6592,7 @@ import {
6935
6592
  TensorType,
6936
6593
  TypedArraySchema as TypedArraySchema8
6937
6594
  } from "@workglow/util/schema";
6938
- var inputSchema16 = {
6595
+ var inputSchema17 = {
6939
6596
  type: "object",
6940
6597
  properties: {
6941
6598
  vector: {
@@ -6972,7 +6629,7 @@ var inputSchema16 = {
6972
6629
  required: ["vector", "targetType"],
6973
6630
  additionalProperties: false
6974
6631
  };
6975
- var outputSchema16 = {
6632
+ var outputSchema17 = {
6976
6633
  type: "object",
6977
6634
  properties: {
6978
6635
  vector: {
@@ -7016,10 +6673,10 @@ class VectorQuantizeTask extends Task19 {
7016
6673
  static description = "Quantize vectors to reduce storage and improve performance";
7017
6674
  static cacheable = true;
7018
6675
  static inputSchema() {
7019
- return inputSchema16;
6676
+ return inputSchema17;
7020
6677
  }
7021
6678
  static outputSchema() {
7022
- return outputSchema16;
6679
+ return outputSchema17;
7023
6680
  }
7024
6681
  async executeReactive(input) {
7025
6682
  const { vector, targetType, normalize = true } = input;
@@ -7219,6 +6876,7 @@ var similarity = (input, config) => {
7219
6876
  return new VectorSimilarityTask(config).run(input);
7220
6877
  };
7221
6878
  Workflow46.prototype.similarity = CreateWorkflow46(VectorSimilarityTask);
6879
+
7222
6880
  // src/task/MessageConversion.ts
7223
6881
  function getInputMessages(input) {
7224
6882
  const messages = input.messages;
@@ -7419,7 +7077,6 @@ function toTextFlatMessages(input) {
7419
7077
  // src/task/index.ts
7420
7078
  var registerAiTasks = () => {
7421
7079
  const tasks = [
7422
- AgentTask,
7423
7080
  BackgroundRemovalTask,
7424
7081
  ChunkToVectorTask,
7425
7082
  CountTokensTask,
@@ -7437,6 +7094,7 @@ var registerAiTasks = () => {
7437
7094
  HandLandmarkerTask,
7438
7095
  HierarchicalChunkerTask,
7439
7096
  HierarchyJoinTask,
7097
+ KbToDocumentsTask,
7440
7098
  ImageClassificationTask,
7441
7099
  ImageEmbeddingTask,
7442
7100
  ImageSegmentationTask,
@@ -7472,11 +7130,8 @@ var registerAiTasks = () => {
7472
7130
  export {
7473
7131
  vectorStoreSearch,
7474
7132
  vectorQuantize,
7475
- userMessage,
7476
7133
  unloadModel,
7477
7134
  topicSegmenter,
7478
- toolSourceDefinitions,
7479
- toolMessage,
7480
7135
  toolCalling,
7481
7136
  toTextFlatMessages,
7482
7137
  toOpenAIMessages,
@@ -7505,43 +7160,32 @@ export {
7505
7160
  objectDetection,
7506
7161
  modelSearch,
7507
7162
  modelInfo,
7163
+ kbToDocuments,
7508
7164
  isAllowedToolName,
7509
7165
  imageToText,
7510
7166
  imageSegmentation,
7511
7167
  imageEmbedding,
7512
7168
  imageClassification,
7513
- imageBlockFromDataUri,
7514
- imageBlock,
7515
7169
  hybridSearch,
7516
7170
  hierarchyJoin,
7517
7171
  hierarchicalChunker,
7518
- hasToolCalls,
7519
7172
  handLandmarker,
7520
7173
  getGlobalModelRepository,
7521
7174
  getAiProviderRegistry,
7522
7175
  gestureRecognizer,
7523
- findToolSource,
7524
7176
  filterValidToolCalls,
7525
7177
  faceLandmarker,
7526
7178
  faceDetector,
7527
- executeToolCalls,
7528
- executeToolCall,
7529
7179
  downloadModel,
7530
7180
  documentUpsert,
7531
7181
  documentEnricher,
7532
7182
  countTokens,
7533
- countAssistantToolUses,
7534
7183
  contextBuilder,
7535
7184
  chunkVectorUpsert,
7536
7185
  chunkToVector,
7537
7186
  chunkRetrieval,
7538
- buildToolSources,
7539
7187
  buildToolDescription,
7540
7188
  backgroundRemoval,
7541
- audioBlockFromDataUri,
7542
- audioBlock,
7543
- assistantMessage,
7544
- agent,
7545
7189
  VectorSimilarityTask,
7546
7190
  VectorQuantizeTask,
7547
7191
  UnloadModelTask,
@@ -7615,6 +7259,7 @@ export {
7615
7259
  ModelInfoTask,
7616
7260
  ModelConfigSchema,
7617
7261
  MODEL_REPOSITORY,
7262
+ KbToDocumentsTask,
7618
7263
  InMemoryModelRepository,
7619
7264
  ImageToTextTask,
7620
7265
  ImageToTextOutputSchema,
@@ -7646,6 +7291,7 @@ export {
7646
7291
  DocumentUpsertTask,
7647
7292
  DocumentEnricherTask,
7648
7293
  DirectExecutionStrategy,
7294
+ DEFAULT_AI_PROVIDER_WORKER_IDLE_TIMEOUT_MS,
7649
7295
  CountTokensTask,
7650
7296
  CountTokensOutputSchema,
7651
7297
  CountTokensInputSchema,
@@ -7663,10 +7309,7 @@ export {
7663
7309
  AiTask,
7664
7310
  AiProviderRegistry,
7665
7311
  AiProvider,
7666
- AiJob,
7667
- AgentTask,
7668
- AgentOutputSchema,
7669
- AgentInputSchema
7312
+ AiJob
7670
7313
  };
7671
7314
 
7672
- //# debugId=3A8ABD53CB039BD464756E2164756E21
7315
+ //# debugId=F0E9DA50FF60D85564756E2164756E21