@workglow/ai 0.0.126 → 0.1.1

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 (135) hide show
  1. package/README.md +214 -47
  2. package/dist/browser.js +569 -1274
  3. package/dist/browser.js.map +56 -61
  4. package/dist/bun.js +569 -1274
  5. package/dist/bun.js.map +56 -61
  6. package/dist/common.d.ts +3 -1
  7. package/dist/common.d.ts.map +1 -1
  8. package/dist/execution/DirectExecutionStrategy.d.ts +20 -0
  9. package/dist/execution/DirectExecutionStrategy.d.ts.map +1 -0
  10. package/dist/execution/IAiExecutionStrategy.d.ts +33 -0
  11. package/dist/execution/IAiExecutionStrategy.d.ts.map +1 -0
  12. package/dist/execution/QueuedExecutionStrategy.d.ts +50 -0
  13. package/dist/execution/QueuedExecutionStrategy.d.ts.map +1 -0
  14. package/dist/job/AiJob.d.ts +6 -0
  15. package/dist/job/AiJob.d.ts.map +1 -1
  16. package/dist/node.js +569 -1274
  17. package/dist/node.js.map +56 -61
  18. package/dist/provider/AiProvider.d.ts +16 -2
  19. package/dist/provider/AiProvider.d.ts.map +1 -1
  20. package/dist/provider/AiProviderRegistry.d.ts +20 -0
  21. package/dist/provider/AiProviderRegistry.d.ts.map +1 -1
  22. package/dist/provider/QueuedAiProvider.d.ts +23 -2
  23. package/dist/provider/QueuedAiProvider.d.ts.map +1 -1
  24. package/dist/task/BackgroundRemovalTask.d.ts +3 -3
  25. package/dist/task/BackgroundRemovalTask.d.ts.map +1 -1
  26. package/dist/task/ChunkRetrievalTask.d.ts +4 -4
  27. package/dist/task/ChunkRetrievalTask.d.ts.map +1 -1
  28. package/dist/task/ChunkToVectorTask.d.ts +4 -4
  29. package/dist/task/ChunkToVectorTask.d.ts.map +1 -1
  30. package/dist/task/ChunkVectorHybridSearchTask.d.ts +4 -4
  31. package/dist/task/ChunkVectorHybridSearchTask.d.ts.map +1 -1
  32. package/dist/task/ChunkVectorSearchTask.d.ts +4 -4
  33. package/dist/task/ChunkVectorSearchTask.d.ts.map +1 -1
  34. package/dist/task/ChunkVectorUpsertTask.d.ts +4 -4
  35. package/dist/task/ChunkVectorUpsertTask.d.ts.map +1 -1
  36. package/dist/task/ContextBuilderTask.d.ts +4 -4
  37. package/dist/task/ContextBuilderTask.d.ts.map +1 -1
  38. package/dist/task/CountTokensTask.d.ts +11 -29
  39. package/dist/task/CountTokensTask.d.ts.map +1 -1
  40. package/dist/task/DocumentEnricherTask.d.ts +4 -4
  41. package/dist/task/DocumentEnricherTask.d.ts.map +1 -1
  42. package/dist/task/DownloadModelTask.d.ts +5 -5
  43. package/dist/task/DownloadModelTask.d.ts.map +1 -1
  44. package/dist/task/FaceDetectorTask.d.ts +4 -4
  45. package/dist/task/FaceDetectorTask.d.ts.map +1 -1
  46. package/dist/task/FaceLandmarkerTask.d.ts +4 -4
  47. package/dist/task/FaceLandmarkerTask.d.ts.map +1 -1
  48. package/dist/task/GestureRecognizerTask.d.ts +4 -4
  49. package/dist/task/GestureRecognizerTask.d.ts.map +1 -1
  50. package/dist/task/HandLandmarkerTask.d.ts +4 -4
  51. package/dist/task/HandLandmarkerTask.d.ts.map +1 -1
  52. package/dist/task/HierarchicalChunkerTask.d.ts +4 -4
  53. package/dist/task/HierarchicalChunkerTask.d.ts.map +1 -1
  54. package/dist/task/HierarchyJoinTask.d.ts +4 -4
  55. package/dist/task/HierarchyJoinTask.d.ts.map +1 -1
  56. package/dist/task/ImageClassificationTask.d.ts +4 -4
  57. package/dist/task/ImageClassificationTask.d.ts.map +1 -1
  58. package/dist/task/ImageEmbeddingTask.d.ts +203 -89
  59. package/dist/task/ImageEmbeddingTask.d.ts.map +1 -1
  60. package/dist/task/ImageSegmentationTask.d.ts +4 -4
  61. package/dist/task/ImageSegmentationTask.d.ts.map +1 -1
  62. package/dist/task/ImageToTextTask.d.ts +4 -4
  63. package/dist/task/ImageToTextTask.d.ts.map +1 -1
  64. package/dist/task/ModelInfoTask.d.ts +5 -5
  65. package/dist/task/ModelInfoTask.d.ts.map +1 -1
  66. package/dist/task/ModelSearchTask.d.ts.map +1 -1
  67. package/dist/task/ObjectDetectionTask.d.ts +4 -4
  68. package/dist/task/ObjectDetectionTask.d.ts.map +1 -1
  69. package/dist/task/PoseLandmarkerTask.d.ts +4 -4
  70. package/dist/task/PoseLandmarkerTask.d.ts.map +1 -1
  71. package/dist/task/QueryExpanderTask.d.ts +4 -4
  72. package/dist/task/QueryExpanderTask.d.ts.map +1 -1
  73. package/dist/task/RerankerTask.d.ts +4 -4
  74. package/dist/task/RerankerTask.d.ts.map +1 -1
  75. package/dist/task/StructuralParserTask.d.ts +4 -4
  76. package/dist/task/StructuralParserTask.d.ts.map +1 -1
  77. package/dist/task/StructuredGenerationTask.d.ts +4 -4
  78. package/dist/task/StructuredGenerationTask.d.ts.map +1 -1
  79. package/dist/task/TextChunkerTask.d.ts +4 -4
  80. package/dist/task/TextChunkerTask.d.ts.map +1 -1
  81. package/dist/task/TextClassificationTask.d.ts +24 -62
  82. package/dist/task/TextClassificationTask.d.ts.map +1 -1
  83. package/dist/task/TextEmbeddingTask.d.ts +3 -3
  84. package/dist/task/TextEmbeddingTask.d.ts.map +1 -1
  85. package/dist/task/TextFillMaskTask.d.ts +29 -73
  86. package/dist/task/TextFillMaskTask.d.ts.map +1 -1
  87. package/dist/task/TextGenerationTask.d.ts +13 -32
  88. package/dist/task/TextGenerationTask.d.ts.map +1 -1
  89. package/dist/task/TextLanguageDetectionTask.d.ts +24 -62
  90. package/dist/task/TextLanguageDetectionTask.d.ts.map +1 -1
  91. package/dist/task/TextNamedEntityRecognitionTask.d.ts +29 -73
  92. package/dist/task/TextNamedEntityRecognitionTask.d.ts.map +1 -1
  93. package/dist/task/TextQuestionAnswerTask.d.ts +17 -45
  94. package/dist/task/TextQuestionAnswerTask.d.ts.map +1 -1
  95. package/dist/task/TextRewriterTask.d.ts +12 -31
  96. package/dist/task/TextRewriterTask.d.ts.map +1 -1
  97. package/dist/task/TextSummaryTask.d.ts +12 -31
  98. package/dist/task/TextSummaryTask.d.ts.map +1 -1
  99. package/dist/task/TextTranslationTask.d.ts +12 -31
  100. package/dist/task/TextTranslationTask.d.ts.map +1 -1
  101. package/dist/task/TopicSegmenterTask.d.ts +4 -4
  102. package/dist/task/TopicSegmenterTask.d.ts.map +1 -1
  103. package/dist/task/UnloadModelTask.d.ts +4 -4
  104. package/dist/task/UnloadModelTask.d.ts.map +1 -1
  105. package/dist/task/VectorQuantizeTask.d.ts +4 -4
  106. package/dist/task/VectorQuantizeTask.d.ts.map +1 -1
  107. package/dist/task/VectorSimilarityTask.d.ts +4 -4
  108. package/dist/task/VectorSimilarityTask.d.ts.map +1 -1
  109. package/dist/task/base/AiTask.d.ts +12 -31
  110. package/dist/task/base/AiTask.d.ts.map +1 -1
  111. package/dist/task/base/AiVisionTask.d.ts +7 -12
  112. package/dist/task/base/AiVisionTask.d.ts.map +1 -1
  113. package/dist/task/base/StreamingAiTask.d.ts +7 -4
  114. package/dist/task/base/StreamingAiTask.d.ts.map +1 -1
  115. package/dist/task/index.d.ts +1 -13
  116. package/dist/task/index.d.ts.map +1 -1
  117. package/dist/worker.d.ts +0 -2
  118. package/dist/worker.d.ts.map +1 -1
  119. package/dist/worker.js +220 -233
  120. package/dist/worker.js.map +7 -7
  121. package/package.json +11 -11
  122. package/dist/queue/createDefaultQueue.d.ts +0 -17
  123. package/dist/queue/createDefaultQueue.d.ts.map +0 -1
  124. package/dist/task/AgentTask.d.ts +0 -524
  125. package/dist/task/AgentTask.d.ts.map +0 -1
  126. package/dist/task/AgentTypes.d.ts +0 -181
  127. package/dist/task/AgentTypes.d.ts.map +0 -1
  128. package/dist/task/AgentUtils.d.ts +0 -50
  129. package/dist/task/AgentUtils.d.ts.map +0 -1
  130. package/dist/task/MessageConversion.d.ts +0 -52
  131. package/dist/task/MessageConversion.d.ts.map +0 -1
  132. package/dist/task/ToolCallingTask.d.ts +0 -385
  133. package/dist/task/ToolCallingTask.d.ts.map +0 -1
  134. package/dist/task/ToolCallingUtils.d.ts +0 -65
  135. package/dist/task/ToolCallingUtils.d.ts.map +0 -1
package/dist/bun.js CHANGED
@@ -4,20 +4,36 @@ import {
4
4
  AbortSignalJobError,
5
5
  Job,
6
6
  JobStatus,
7
- PermanentJobError
7
+ PermanentJobError,
8
+ RetryableJobError
8
9
  } from "@workglow/job-queue";
10
+ import { getLogger } from "@workglow/util/worker";
9
11
 
10
12
  // src/provider/AiProviderRegistry.ts
11
13
  import { globalServiceRegistry, WORKER_MANAGER } from "@workglow/util/worker";
12
-
13
14
  class AiProviderRegistry {
14
15
  runFnRegistry = new Map;
15
16
  streamFnRegistry = new Map;
16
17
  reactiveRunFnRegistry = new Map;
17
18
  providers = new Map;
19
+ strategyResolvers = new Map;
20
+ defaultStrategy;
18
21
  registerProvider(provider) {
19
22
  this.providers.set(provider.name, provider);
20
23
  }
24
+ unregisterProvider(name) {
25
+ this.providers.delete(name);
26
+ this.strategyResolvers.delete(name);
27
+ for (const [, providerMap] of this.runFnRegistry) {
28
+ providerMap.delete(name);
29
+ }
30
+ for (const [, providerMap] of this.streamFnRegistry) {
31
+ providerMap.delete(name);
32
+ }
33
+ for (const [, providerMap] of this.reactiveRunFnRegistry) {
34
+ providerMap.delete(name);
35
+ }
36
+ }
21
37
  getProvider(name) {
22
38
  return this.providers.get(name);
23
39
  }
@@ -27,6 +43,18 @@ class AiProviderRegistry {
27
43
  getInstalledProviderIds() {
28
44
  return [...this.providers.keys()].sort();
29
45
  }
46
+ registerStrategyResolver(providerName, resolver) {
47
+ this.strategyResolvers.set(providerName, resolver);
48
+ }
49
+ getStrategy(model) {
50
+ const resolver = this.strategyResolvers.get(model.provider);
51
+ if (resolver)
52
+ return resolver(model);
53
+ if (!this.defaultStrategy) {
54
+ this.defaultStrategy = new DirectExecutionStrategy;
55
+ }
56
+ return this.defaultStrategy;
57
+ }
30
58
  getProviderIdsForTask(taskType) {
31
59
  const taskMap = this.runFnRegistry.get(taskType);
32
60
  if (!taskMap)
@@ -92,15 +120,16 @@ class AiProviderRegistry {
92
120
  const taskTypeMap = this.runFnRegistry.get(taskType);
93
121
  const runFn = taskTypeMap?.get(modelProvider);
94
122
  if (!runFn) {
95
- throw new Error(`No run function found for task type ${taskType} and model provider ${modelProvider}`);
123
+ const installedProviders = this.getInstalledProviderIds();
124
+ const providersForTask = this.getProviderIdsForTask(taskType);
125
+ const hint = providersForTask.length > 0 ? ` Providers supporting "${taskType}": [${providersForTask.join(", ")}].` : installedProviders.length > 0 ? ` Installed providers: [${installedProviders.join(", ")}] (none support "${taskType}").` : " No providers are registered. Call provider.register() before running AI tasks.";
126
+ throw new Error(`No run function found for task type "${taskType}" and provider "${modelProvider}".${hint}`);
96
127
  }
97
128
  return runFn;
98
129
  }
99
130
  }
100
- var providerRegistry;
131
+ var providerRegistry = new AiProviderRegistry;
101
132
  function getAiProviderRegistry() {
102
- if (!providerRegistry)
103
- providerRegistry = new AiProviderRegistry;
104
133
  return providerRegistry;
105
134
  }
106
135
  function setAiProviderRegistry(pr) {
@@ -108,6 +137,64 @@ function setAiProviderRegistry(pr) {
108
137
  }
109
138
 
110
139
  // src/job/AiJob.ts
140
+ var DEFAULT_AI_TIMEOUT_MS = 120000;
141
+ var LOCAL_MODEL_DEFAULT_TIMEOUT_MS = 600000;
142
+ function resolveAiJobTimeoutMs(aiProvider, explicitMs) {
143
+ if (explicitMs !== undefined) {
144
+ return explicitMs;
145
+ }
146
+ if (aiProvider === "LOCAL_LLAMACPP") {
147
+ return LOCAL_MODEL_DEFAULT_TIMEOUT_MS;
148
+ }
149
+ if (aiProvider === "HF_TRANSFORMERS_ONNX" || aiProvider.startsWith("HF_TRANSFORMERS_ONNX")) {
150
+ return LOCAL_MODEL_DEFAULT_TIMEOUT_MS;
151
+ }
152
+ return DEFAULT_AI_TIMEOUT_MS;
153
+ }
154
+ function classifyProviderError(err, taskType, provider) {
155
+ if (err instanceof PermanentJobError || err instanceof RetryableJobError || err instanceof AbortSignalJobError) {
156
+ return err;
157
+ }
158
+ const message = err instanceof Error ? err.message : String(err);
159
+ const status = typeof err?.status === "number" ? err.status : typeof err?.statusCode === "number" ? err.statusCode : (() => {
160
+ const m = message.match(/\b([45]\d{2})\b/);
161
+ return m ? parseInt(m[1], 10) : undefined;
162
+ })();
163
+ if (err instanceof DOMException && err.name === "AbortError") {
164
+ return new AbortSignalJobError(`Provider call aborted for ${taskType} (${provider})`);
165
+ }
166
+ if (err instanceof DOMException && err.name === "TimeoutError") {
167
+ return new AbortSignalJobError(`Provider call timed out for ${taskType} (${provider})`);
168
+ }
169
+ if (message.includes("Pipeline download aborted") || message.includes("Operation aborted") || message.includes("operation was aborted") || message.includes("The operation was aborted")) {
170
+ return new AbortSignalJobError(`Provider call aborted for ${taskType} (${provider}): ${message}`);
171
+ }
172
+ if (message.startsWith("HFT_NULL_PROCESSOR:")) {
173
+ return new RetryableJobError(message);
174
+ }
175
+ if (status === 429) {
176
+ const retryAfterMatch = message.match(/retry.after[:\s]*(\d+)/i);
177
+ const retryMs = retryAfterMatch ? parseInt(retryAfterMatch[1], 10) * 1000 : 30000;
178
+ return new RetryableJobError(`Rate limited by ${provider} for ${taskType}: ${message}`, new Date(Date.now() + retryMs));
179
+ }
180
+ if (status === 401 || status === 403) {
181
+ return new PermanentJobError(`Authentication failed for ${provider} (${taskType}): ${message}`);
182
+ }
183
+ if (status === 400 || status === 404) {
184
+ return new PermanentJobError(`Invalid request to ${provider} for ${taskType}: ${message}`);
185
+ }
186
+ if (status && status >= 500) {
187
+ return new RetryableJobError(`Server error from ${provider} for ${taskType} (HTTP ${status}): ${message}`);
188
+ }
189
+ if (message.includes("ECONNREFUSED") || message.includes("ECONNRESET") || message.includes("ETIMEDOUT") || message.includes("fetch failed") || message.includes("network") || err instanceof TypeError && message.includes("fetch")) {
190
+ return new RetryableJobError(`Network error calling ${provider} for ${taskType}: ${message}`);
191
+ }
192
+ if (message.includes("timed out") || message.includes("timeout")) {
193
+ return new RetryableJobError(`Timeout calling ${provider} for ${taskType}: ${message}`);
194
+ }
195
+ return new PermanentJobError(`Provider ${provider} failed for ${taskType}: ${message}`);
196
+ }
197
+
111
198
  class AiJob extends Job {
112
199
  async execute(input, context) {
113
200
  if (context.signal.aborted || this.status === JobStatus.ABORTING) {
@@ -124,17 +211,19 @@ class AiJob extends Job {
124
211
  });
125
212
  const runFn = async () => {
126
213
  const fn = getAiProviderRegistry().getDirectRunFn(input.aiProvider, input.taskType);
127
- if (!fn) {
128
- throw new PermanentJobError(`No run function found for task type ${input.taskType} and model provider ${input.aiProvider}`);
129
- }
130
214
  const model = input.taskInput.model;
131
- if (context.signal?.aborted) {
215
+ if (context.signal.aborted) {
132
216
  throw new AbortSignalJobError("Job aborted");
133
217
  }
134
- return await fn(input.taskInput, model, context.updateProgress, context.signal, input.outputSchema);
218
+ const timeoutMs = resolveAiJobTimeoutMs(input.aiProvider, input.timeoutMs);
219
+ const timeoutSignal = AbortSignal.timeout(timeoutMs);
220
+ const combinedSignal = AbortSignal.any([context.signal, timeoutSignal]);
221
+ return await fn(input.taskInput, model, context.updateProgress, combinedSignal, input.outputSchema);
135
222
  };
136
223
  const runFnPromise = runFn();
137
224
  return await Promise.race([runFnPromise, abortPromise]);
225
+ } catch (err) {
226
+ throw classifyProviderError(err, input.taskType, input.aiProvider);
138
227
  } finally {
139
228
  if (abortHandler) {
140
229
  abortHandler();
@@ -152,35 +241,172 @@ class AiJob extends Job {
152
241
  return;
153
242
  }
154
243
  const model = input.taskInput.model;
155
- yield* streamFn(input.taskInput, model, context.signal, input.outputSchema);
244
+ let lastFinishData;
245
+ const timeoutMs = resolveAiJobTimeoutMs(input.aiProvider, input.timeoutMs);
246
+ const timeoutSignal = AbortSignal.timeout(timeoutMs);
247
+ const combinedSignal = AbortSignal.any([context.signal, timeoutSignal]);
248
+ try {
249
+ for await (const event of streamFn(input.taskInput, model, combinedSignal, input.outputSchema)) {
250
+ if (event.type === "finish") {
251
+ lastFinishData = event.data;
252
+ }
253
+ yield event;
254
+ }
255
+ } catch (err) {
256
+ const logger = getLogger();
257
+ logger.warn(`AiJob: Stream error for ${input.taskType} (${input.aiProvider}): ${err instanceof Error ? err.message : String(err)}`);
258
+ if (lastFinishData === undefined) {
259
+ yield { type: "finish", data: {} };
260
+ }
261
+ throw classifyProviderError(err, input.taskType, input.aiProvider);
262
+ }
156
263
  }
157
264
  }
158
265
 
159
- // src/task/ToolCallingUtils.ts
160
- import { getLogger } from "@workglow/util/worker";
161
- function buildToolDescription(tool) {
162
- let desc = tool.description;
163
- if (tool.outputSchema && typeof tool.outputSchema === "object") {
164
- desc += `
165
-
166
- Returns: ${JSON.stringify(tool.outputSchema)}`;
266
+ // src/execution/DirectExecutionStrategy.ts
267
+ class DirectExecutionStrategy {
268
+ async execute(jobInput, context, runnerId) {
269
+ const job = new AiJob({
270
+ queueName: jobInput.aiProvider,
271
+ jobRunId: runnerId,
272
+ input: jobInput
273
+ });
274
+ const cleanup = job.onJobProgress((progress, message, details) => {
275
+ context.updateProgress(progress, message, details);
276
+ });
277
+ try {
278
+ return await job.execute(jobInput, {
279
+ signal: context.signal,
280
+ updateProgress: context.updateProgress
281
+ });
282
+ } finally {
283
+ cleanup();
284
+ }
167
285
  }
168
- return desc;
169
- }
170
- function isAllowedToolName(name, allowedTools) {
171
- return allowedTools.some((t) => t.name === name);
286
+ async* executeStream(jobInput, context, runnerId) {
287
+ const job = new AiJob({
288
+ queueName: jobInput.aiProvider,
289
+ jobRunId: runnerId,
290
+ input: jobInput
291
+ });
292
+ yield* job.executeStream(jobInput, {
293
+ signal: context.signal,
294
+ updateProgress: context.updateProgress
295
+ });
296
+ }
297
+ abort() {}
172
298
  }
173
- function filterValidToolCalls(toolCalls, allowedTools) {
174
- return toolCalls.filter((tc) => {
175
- if (tc.name && isAllowedToolName(tc.name, allowedTools)) {
176
- return true;
299
+
300
+ // src/execution/QueuedExecutionStrategy.ts
301
+ import { ConcurrencyLimiter, JobQueueClient, JobQueueServer } from "@workglow/job-queue";
302
+ import { InMemoryQueueStorage } from "@workglow/storage";
303
+ import {
304
+ getTaskQueueRegistry,
305
+ TaskConfigurationError
306
+ } from "@workglow/task-graph";
307
+ class QueuedExecutionStrategy {
308
+ queueName;
309
+ concurrency;
310
+ autoCreate;
311
+ initPromise = null;
312
+ constructor(queueName, concurrency = 1, autoCreate = true) {
313
+ this.queueName = queueName;
314
+ this.concurrency = concurrency;
315
+ this.autoCreate = autoCreate;
316
+ }
317
+ async execute(jobInput, context, runnerId) {
318
+ if (context.signal.aborted) {
319
+ throw context.signal.reason ?? new DOMException("The operation was aborted", "AbortError");
320
+ }
321
+ const registeredQueue = await this.ensureQueue();
322
+ const { client } = registeredQueue;
323
+ const handle = await client.submit(jobInput, {
324
+ jobRunId: runnerId,
325
+ maxRetries: 10
326
+ });
327
+ const onAbort = () => {
328
+ handle.abort().catch((err) => {
329
+ console.warn(`Failed to abort queued job`, err);
330
+ });
331
+ };
332
+ context.signal.addEventListener("abort", onAbort);
333
+ const cleanupProgress = handle.onProgress((progress, message, details) => {
334
+ context.updateProgress(progress, message, details);
335
+ });
336
+ try {
337
+ if (context.signal.aborted) {
338
+ throw context.signal.reason ?? new DOMException("The operation was aborted", "AbortError");
339
+ }
340
+ const output = await handle.waitFor();
341
+ return output;
342
+ } finally {
343
+ cleanupProgress();
344
+ context.signal.removeEventListener("abort", onAbort);
177
345
  }
178
- getLogger().warn(`Filtered out tool call with unknown name "${tc.name ?? "(missing)"}"`, {
179
- callId: tc.id,
180
- toolName: tc.name
346
+ }
347
+ abort() {}
348
+ async* executeStream(jobInput, context, runnerId) {
349
+ const result = await this.execute(jobInput, context, runnerId);
350
+ yield { type: "finish", data: result };
351
+ }
352
+ ensureQueue() {
353
+ if (!this.initPromise) {
354
+ this.initPromise = this.createQueue().catch((err) => {
355
+ this.initPromise = null;
356
+ throw err;
357
+ });
358
+ }
359
+ return this.initPromise;
360
+ }
361
+ async createQueue() {
362
+ const registry = getTaskQueueRegistry();
363
+ const existing = registry.getQueue(this.queueName);
364
+ if (existing) {
365
+ if (!existing.server.isRunning()) {
366
+ await existing.server.start();
367
+ }
368
+ return existing;
369
+ }
370
+ if (!this.autoCreate) {
371
+ throw new TaskConfigurationError(`Queue "${this.queueName}" is not registered and autoCreate is disabled. ` + `Register the queue before executing tasks with this provider.`);
372
+ }
373
+ const storage = new InMemoryQueueStorage(this.queueName);
374
+ await storage.setupDatabase();
375
+ const server = new JobQueueServer(AiJob, {
376
+ storage,
377
+ queueName: this.queueName,
378
+ limiter: new ConcurrencyLimiter(this.concurrency)
379
+ });
380
+ const client = new JobQueueClient({
381
+ storage,
382
+ queueName: this.queueName
181
383
  });
182
- return false;
183
- });
384
+ client.attach(server);
385
+ const registeredQueue = {
386
+ server,
387
+ client,
388
+ storage
389
+ };
390
+ try {
391
+ registry.registerQueue(registeredQueue);
392
+ } catch (err) {
393
+ if (err instanceof Error && err.message.includes("already exists")) {
394
+ server.stop().catch((stopErr) => {
395
+ console.warn("QueuedExecutionStrategy: failed to stop raced-out queue server", stopErr);
396
+ });
397
+ const raced = registry.getQueue(this.queueName);
398
+ if (raced) {
399
+ if (!raced.server.isRunning()) {
400
+ await raced.server.start();
401
+ }
402
+ return raced;
403
+ }
404
+ }
405
+ throw err;
406
+ }
407
+ await server.start();
408
+ return registeredQueue;
409
+ }
184
410
  }
185
411
 
186
412
  // src/model/InMemoryModelRepository.ts
@@ -353,6 +579,16 @@ import {
353
579
  globalServiceRegistry as globalServiceRegistry3,
354
580
  WORKER_MANAGER as WORKER_MANAGER2
355
581
  } from "@workglow/util/worker";
582
+ function resolveAiProviderGpuQueueConcurrency(concurrency) {
583
+ if (concurrency === undefined) {
584
+ return 1;
585
+ }
586
+ if (typeof concurrency === "number") {
587
+ return concurrency;
588
+ }
589
+ return concurrency.gpu ?? 1;
590
+ }
591
+
356
592
  class AiProvider {
357
593
  tasks;
358
594
  streamTasks;
@@ -412,7 +648,12 @@ class AiProvider {
412
648
  }
413
649
  }
414
650
  registry.registerProvider(this);
415
- await this.afterRegister(options);
651
+ try {
652
+ await this.afterRegister(options);
653
+ } catch (err) {
654
+ registry.unregisterProvider(this.name);
655
+ throw err;
656
+ }
416
657
  }
417
658
  registerOnWorkerServer(workerServer) {
418
659
  if (!this.tasks) {
@@ -437,115 +678,28 @@ class AiProvider {
437
678
  async afterRegister(_options) {}
438
679
  }
439
680
 
440
- // src/queue/createDefaultQueue.ts
441
- import { ConcurrencyLimiter, JobQueueClient, JobQueueServer } from "@workglow/job-queue";
442
- import { InMemoryQueueStorage } from "@workglow/storage";
443
- import { getTaskQueueRegistry } from "@workglow/task-graph";
444
- async function createDefaultQueue(providerName, concurrency) {
445
- const storage = new InMemoryQueueStorage(providerName);
446
- await storage.setupDatabase();
447
- const server = new JobQueueServer(AiJob, {
448
- storage,
449
- queueName: providerName,
450
- limiter: new ConcurrencyLimiter(concurrency)
451
- });
452
- const client = new JobQueueClient({
453
- storage,
454
- queueName: providerName
455
- });
456
- client.attach(server);
457
- getTaskQueueRegistry().registerQueue({ server, client, storage });
458
- await server.start();
459
- }
460
-
461
681
  // src/provider/QueuedAiProvider.ts
462
682
  class QueuedAiProvider extends AiProvider {
683
+ queuedStrategy;
463
684
  async afterRegister(options) {
464
- if (options.queue?.autoCreate !== false) {
465
- await createDefaultQueue(this.name, options.queue?.concurrency ?? 1);
466
- }
685
+ const autoCreate = options.queue?.autoCreate !== false;
686
+ this.queuedStrategy = new QueuedExecutionStrategy(`${this.name}_gpu`, resolveAiProviderGpuQueueConcurrency(options.queue?.concurrency), autoCreate);
687
+ getAiProviderRegistry().registerStrategyResolver(this.name, (model) => this.getStrategyForModel(model));
688
+ }
689
+ createQueuedStrategy(queueName, concurrency, options) {
690
+ const autoCreate = options.queue?.autoCreate !== false;
691
+ return new QueuedExecutionStrategy(queueName, concurrency, autoCreate);
692
+ }
693
+ getStrategyForModel(_model) {
694
+ return this.queuedStrategy;
467
695
  }
468
696
  }
469
697
 
470
698
  // src/task/index.ts
471
699
  import { TaskRegistry } from "@workglow/task-graph";
472
700
 
473
- // src/task/AgentTask.ts
474
- import {
475
- CreateWorkflow as CreateWorkflow2,
476
- Task,
477
- Workflow as Workflow2
478
- } from "@workglow/task-graph";
479
- import { getLogger as getLogger3 } from "@workglow/util";
480
-
481
- // src/task/AgentTypes.ts
482
- import { parseDataUri } from "@workglow/util/media";
483
- function imageBlock(mimeType, data) {
484
- return { type: "image", mimeType, data };
485
- }
486
- function audioBlock(mimeType, data) {
487
- return { type: "audio", mimeType, data };
488
- }
489
- function imageBlockFromDataUri(dataUri) {
490
- const { mimeType, base64 } = parseDataUri(dataUri);
491
- return { type: "image", mimeType, data: base64 };
492
- }
493
- function audioBlockFromDataUri(dataUri) {
494
- const { mimeType, base64 } = parseDataUri(dataUri);
495
- return { type: "audio", mimeType, data: base64 };
496
- }
497
- function userMessage(prompt) {
498
- return { role: "user", content: prompt };
499
- }
500
- function assistantMessage(text, toolCalls) {
501
- const content = [];
502
- if (text) {
503
- content.push({ type: "text", text });
504
- }
505
- if (toolCalls) {
506
- for (const tc of toolCalls) {
507
- content.push({
508
- type: "tool_use",
509
- id: tc.id,
510
- name: tc.name,
511
- input: tc.input
512
- });
513
- }
514
- }
515
- return { role: "assistant", content };
516
- }
517
- function toolMessage(results) {
518
- return {
519
- role: "tool",
520
- content: results.map((r) => {
521
- const jsonText = JSON.stringify(r.output);
522
- const content = r.mediaContent && r.mediaContent.length > 0 ? [{ type: "text", text: jsonText }, ...r.mediaContent] : jsonText;
523
- return {
524
- type: "tool_result",
525
- tool_use_id: r.toolCallId,
526
- content,
527
- is_error: r.isError || undefined
528
- };
529
- })
530
- };
531
- }
532
- function toolSourceDefinitions(sources) {
533
- return sources.map((s) => s.definition);
534
- }
535
- function findToolSource(sources, name) {
536
- return sources.find((s) => s.definition.name === name);
537
- }
538
-
539
- // src/task/AgentUtils.ts
540
- import { getTaskConstructors as getTaskConstructors2 } from "@workglow/task-graph";
541
- import { getLogger as getLogger2 } from "@workglow/util";
542
-
543
- // src/task/ToolCallingTask.ts
544
- import {
545
- CreateWorkflow,
546
- getTaskConstructors,
547
- Workflow
548
- } from "@workglow/task-graph";
701
+ // src/task/BackgroundRemovalTask.ts
702
+ import { CreateWorkflow, Workflow } from "@workglow/task-graph";
549
703
 
550
704
  // src/task/base/AiTaskSchemas.ts
551
705
  var TypeLanguage = (annotations = {}) => ({
@@ -704,40 +858,56 @@ var TypeCategory = {
704
858
  description: "Classification category with label and score"
705
859
  };
706
860
 
707
- // src/task/base/StreamingAiTask.ts
708
- import {
709
- getStreamingPorts
710
- } from "@workglow/task-graph";
861
+ // src/task/base/AiVisionTask.ts
862
+ import { convertImageDataToUseableForm } from "@workglow/util/media";
711
863
 
712
864
  // src/task/base/AiTask.ts
713
865
  import {
714
- JobQueueTask,
715
- TaskConfigurationError,
866
+ Task,
867
+ TaskConfigSchema,
868
+ TaskConfigurationError as TaskConfigurationError2,
716
869
  hasStructuredOutput
717
870
  } from "@workglow/task-graph";
718
871
  function schemaFormat(schema) {
719
872
  return typeof schema === "object" && schema !== null && "format" in schema ? schema.format : undefined;
720
873
  }
874
+ var aiTaskConfigSchema = {
875
+ type: "object",
876
+ properties: {
877
+ ...TaskConfigSchema["properties"]
878
+ },
879
+ additionalProperties: false
880
+ };
721
881
 
722
- class AiTask extends JobQueueTask {
882
+ class AiTask extends Task {
723
883
  static type = "AiTask";
724
- constructor(input = {}, config = {}) {
725
- super(input, config);
726
- this.jobClass = AiJob;
884
+ static configSchema() {
885
+ return aiTaskConfigSchema;
727
886
  }
728
- async getJobInput(input) {
887
+ async execute(input, executeContext) {
729
888
  const model = input.model;
730
889
  if (!model || typeof model !== "object") {
731
- throw new TaskConfigurationError("AiTask: Model was not resolved to ModelConfig - this indicates a bug in the resolution system");
890
+ throw new TaskConfigurationError2("AiTask: Model was not resolved to ModelConfig - this indicates a bug in the resolution system");
732
891
  }
892
+ const jobInput = await this.getJobInput(input);
893
+ const strategy = getAiProviderRegistry().getStrategy(model);
894
+ const output = await strategy.execute(jobInput, executeContext, this.runConfig.runnerId);
895
+ return output;
896
+ }
897
+ async getJobInput(input) {
898
+ const model = input.model;
733
899
  const runtype = this.constructor.runtype ?? this.constructor.type;
734
900
  const jobInput = {
735
901
  taskType: runtype,
736
902
  aiProvider: model.provider,
737
903
  taskInput: input
738
904
  };
905
+ const taskTimeoutMs = this.config.timeout;
906
+ if (typeof taskTimeoutMs === "number" && taskTimeoutMs > 0) {
907
+ jobInput.timeoutMs = taskTimeoutMs;
908
+ }
739
909
  const inputOutputSchema = input.outputSchema;
740
- if (inputOutputSchema && typeof inputOutputSchema === "object") {
910
+ if (inputOutputSchema && typeof inputOutputSchema === "object" && !Array.isArray(inputOutputSchema) && typeof inputOutputSchema.type === "string") {
741
911
  jobInput.outputSchema = inputOutputSchema;
742
912
  } else {
743
913
  const taskOutputSchema = this.outputSchema();
@@ -751,7 +921,7 @@ class AiTask extends JobQueueTask {
751
921
  const jobInput = await this.getJobInput(input);
752
922
  const resolvedQueueName = queueName ?? await this.getDefaultQueueName(input);
753
923
  if (!resolvedQueueName) {
754
- throw new TaskConfigurationError("JobQueueTask: Unable to determine queue for AI provider");
924
+ throw new TaskConfigurationError2("AiTask: Unable to determine queue for AI provider");
755
925
  }
756
926
  const job = new AiJob({
757
927
  queueName: resolvedQueueName,
@@ -779,7 +949,7 @@ class AiTask extends JobQueueTask {
779
949
  const inputSchema = this.inputSchema();
780
950
  if (typeof inputSchema === "boolean") {
781
951
  if (inputSchema === false) {
782
- throw new TaskConfigurationError(`AiTask: Input schema is 'false' and accepts no inputs`);
952
+ throw new TaskConfigurationError2(`AiTask: Input schema is 'false' and accepts no inputs`);
783
953
  }
784
954
  return true;
785
955
  }
@@ -789,17 +959,18 @@ class AiTask extends JobQueueTask {
789
959
  if (typeof model === "object" && model !== null) {
790
960
  const tasks = model.tasks;
791
961
  if (Array.isArray(tasks) && tasks.length > 0 && !tasks.includes(this.type)) {
792
- throw new TaskConfigurationError(`AiTask: Model for '${key}' is not compatible with task '${this.type}'`);
962
+ const modelId = model.model_id ?? "(inline config)";
963
+ throw new TaskConfigurationError2(`AiTask: Model "${modelId}" for '${key}' is not compatible with task '${this.type}'. ` + `Model supports: [${tasks.join(", ")}]`);
793
964
  }
794
965
  } else if (model !== undefined && model !== null) {
795
- throw new TaskConfigurationError(`AiTask: Invalid model for '${key}' - expected ModelConfig object`);
966
+ 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.`);
796
967
  }
797
968
  }
798
969
  const modelPlainProperties = Object.entries(inputSchema.properties || {}).filter(([key, schema]) => schemaFormat(schema) === "model");
799
970
  for (const [key] of modelPlainProperties) {
800
971
  const model = input[key];
801
972
  if (model !== undefined && model !== null && typeof model !== "object") {
802
- throw new TaskConfigurationError(`AiTask: Invalid model for '${key}' - expected ModelConfig object`);
973
+ 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.`);
803
974
  }
804
975
  }
805
976
  return super.validateInput(input);
@@ -808,14 +979,14 @@ class AiTask extends JobQueueTask {
808
979
  const inputSchema = this.inputSchema();
809
980
  if (typeof inputSchema === "boolean") {
810
981
  if (inputSchema === false) {
811
- throw new TaskConfigurationError(`AiTask: Input schema is 'false' and accepts no inputs`);
982
+ throw new TaskConfigurationError2(`AiTask: Input schema is 'false' and accepts no inputs`);
812
983
  }
813
984
  return input;
814
985
  }
815
986
  const modelTaskProperties = Object.entries(inputSchema.properties || {}).filter(([key, schema]) => schemaFormat(schema)?.startsWith("model:"));
816
987
  if (modelTaskProperties.length > 0) {
817
988
  const modelRepo = registry.get(MODEL_REPOSITORY);
818
- const taskModels = await modelRepo.findModelsByTask(this.type);
989
+ const taskModels = await modelRepo.findModelsByTask(this.type) ?? [];
819
990
  for (const [key, propSchema] of modelTaskProperties) {
820
991
  const requestedModel = input[key];
821
992
  if (typeof requestedModel === "string") {
@@ -827,666 +998,29 @@ class AiTask extends JobQueueTask {
827
998
  const model = requestedModel;
828
999
  const tasks = model.tasks;
829
1000
  if (Array.isArray(tasks) && tasks.length > 0 && !tasks.includes(this.type)) {
830
- input[key] = undefined;
831
- }
832
- }
833
- }
834
- }
835
- return input;
836
- }
837
- }
838
-
839
- // src/task/base/StreamingAiTask.ts
840
- class StreamingAiTask extends AiTask {
841
- static type = "StreamingAiTask";
842
- async* executeStream(input, context) {
843
- const jobInput = await this.getJobInput(input);
844
- const queueName = await this.getDefaultQueueName(input);
845
- const job = new AiJob({
846
- queueName: queueName ?? this.type,
847
- jobRunId: this.runConfig.runnerId,
848
- input: jobInput
849
- });
850
- const ports = getStreamingPorts(this.outputSchema());
851
- const defaultPort = ports.length > 0 ? ports[0].port : "text";
852
- for await (const event of job.executeStream(jobInput, {
853
- signal: context.signal,
854
- updateProgress: context.updateProgress.bind(this)
855
- })) {
856
- if (event.type === "text-delta") {
857
- yield { ...event, port: event.port ?? defaultPort };
858
- } else if (event.type === "object-delta") {
859
- yield { ...event, port: event.port ?? defaultPort };
860
- } else {
861
- yield event;
862
- }
863
- }
864
- }
865
- }
866
-
867
- // src/task/ToolCallingTask.ts
868
- function taskTypesToTools(taskNames, registry) {
869
- const constructors = getTaskConstructors(registry);
870
- return taskNames.map((name) => {
871
- const ctor = constructors.get(name);
872
- if (!ctor) {
873
- throw new Error(`taskTypesToTools: Unknown task type "${name}" \u2014 not found in task constructors registry (ServiceRegistry: ${registry ? "custom" : "default"})`);
874
- }
875
- const configSchema = "configSchema" in ctor && typeof ctor.configSchema === "function" ? ctor.configSchema() : undefined;
876
- return {
877
- name: ctor.type,
878
- description: ctor.description ?? "",
879
- inputSchema: ctor.inputSchema(),
880
- outputSchema: ctor.outputSchema(),
881
- ...configSchema ? { configSchema } : {},
882
- taskType: name
883
- };
884
- });
885
- }
886
- var ToolDefinitionSchema = {
887
- type: "object",
888
- properties: {
889
- name: {
890
- type: "string",
891
- title: "Name",
892
- description: "The tool name"
893
- },
894
- description: {
895
- type: "string",
896
- title: "Description",
897
- description: "A description of what the tool does"
898
- },
899
- inputSchema: {
900
- type: "object",
901
- title: "Input Schema",
902
- description: "JSON Schema describing the tool's input parameters",
903
- additionalProperties: true
904
- },
905
- outputSchema: {
906
- type: "object",
907
- title: "Output Schema",
908
- description: "JSON Schema describing what the tool returns",
909
- additionalProperties: true
910
- },
911
- configSchema: {
912
- type: "object",
913
- title: "Config Schema",
914
- description: "JSON Schema describing the task's configuration options (not sent to the LLM)",
915
- additionalProperties: true
916
- },
917
- config: {
918
- type: "object",
919
- title: "Config",
920
- description: "Concrete configuration values for the backing task (not sent to the LLM)",
921
- additionalProperties: true
922
- }
923
- },
924
- required: ["name", "description", "inputSchema"],
925
- additionalProperties: true
926
- };
927
- var ToolCallSchema = {
928
- type: "object",
929
- properties: {
930
- id: {
931
- type: "string",
932
- title: "ID",
933
- description: "Unique identifier for this tool call"
934
- },
935
- name: {
936
- type: "string",
937
- title: "Name",
938
- description: "The name of the tool to invoke"
939
- },
940
- input: {
941
- type: "object",
942
- title: "Input",
943
- description: "The input arguments for the tool call",
944
- additionalProperties: true
945
- }
946
- },
947
- required: ["id", "name", "input"],
948
- additionalProperties: false
949
- };
950
- var modelSchema = TypeModel("model:ToolCallingTask");
951
- var ToolCallingInputSchema = {
952
- type: "object",
953
- properties: {
954
- model: modelSchema,
955
- prompt: {
956
- oneOf: [
957
- { type: "string", title: "Prompt", description: "The prompt to send to the model" },
958
- {
959
- type: "array",
960
- title: "Prompt",
961
- description: "The prompt as an array of strings or content blocks",
962
- items: {
963
- oneOf: [
964
- { type: "string" },
965
- {
966
- type: "object",
967
- properties: {
968
- type: { type: "string", enum: ["text", "image", "audio"] }
969
- },
970
- required: ["type"],
971
- additionalProperties: true
972
- }
973
- ]
974
- }
975
- }
976
- ],
977
- title: "Prompt",
978
- description: "The prompt to send to the model"
979
- },
980
- systemPrompt: {
981
- type: "string",
982
- title: "System Prompt",
983
- description: "Optional system instructions for the model"
984
- },
985
- messages: {
986
- type: "array",
987
- title: "Messages",
988
- description: "Full conversation history for multi-turn interactions. When provided, used instead of prompt to construct the messages array sent to the provider.",
989
- items: {
990
- type: "object",
991
- properties: {
992
- role: { type: "string", enum: ["user", "assistant", "tool"] },
993
- content: {}
994
- },
995
- required: ["role", "content"],
996
- additionalProperties: true
997
- }
998
- },
999
- tools: {
1000
- type: "array",
1001
- format: "tasks",
1002
- title: "Tools",
1003
- description: "Tool definitions available for the model to call",
1004
- items: {
1005
- oneOf: [
1006
- { type: "string", format: "tasks", description: "Task type name" },
1007
- ToolDefinitionSchema
1008
- ]
1009
- }
1010
- },
1011
- toolChoice: {
1012
- type: "string",
1013
- title: "Tool Choice",
1014
- description: 'Controls tool selection: "auto" (model decides), "none" (no tools), "required" (must call a tool), or a specific tool name',
1015
- "x-ui-group": "Configuration"
1016
- },
1017
- maxTokens: {
1018
- type: "number",
1019
- title: "Max Tokens",
1020
- description: "The maximum number of tokens to generate",
1021
- minimum: 1,
1022
- "x-ui-group": "Configuration"
1023
- },
1024
- temperature: {
1025
- type: "number",
1026
- title: "Temperature",
1027
- description: "The temperature to use for sampling",
1028
- minimum: 0,
1029
- maximum: 2,
1030
- "x-ui-group": "Configuration"
1031
- }
1032
- },
1033
- required: ["model", "prompt", "tools"],
1034
- additionalProperties: false
1035
- };
1036
- var ToolCallingOutputSchema = {
1037
- type: "object",
1038
- properties: {
1039
- text: TypeSingleOrArray({
1040
- type: "string",
1041
- title: "Text",
1042
- description: "Any text content generated by the model",
1043
- "x-stream": "append"
1044
- }),
1045
- toolCalls: TypeSingleOrArray({
1046
- ...ToolCallSchema,
1047
- "x-stream": "object"
1048
- })
1049
- },
1050
- required: ["text", "toolCalls"],
1051
- additionalProperties: false
1052
- };
1053
-
1054
- class ToolCallingTask extends StreamingAiTask {
1055
- static type = "ToolCallingTask";
1056
- static category = "AI Text Model";
1057
- static title = "Tool Calling";
1058
- static description = "Sends a prompt with tool definitions to a language model and returns text along with any tool calls the model requests";
1059
- static inputSchema() {
1060
- return ToolCallingInputSchema;
1061
- }
1062
- static outputSchema() {
1063
- return ToolCallingOutputSchema;
1064
- }
1065
- }
1066
- var toolCalling = (input, config) => {
1067
- return new ToolCallingTask({}, config).run(input);
1068
- };
1069
- Workflow.prototype.toolCalling = CreateWorkflow(ToolCallingTask);
1070
-
1071
- // src/task/AgentUtils.ts
1072
- function buildToolSources(tools, registry) {
1073
- if (!tools || tools.length === 0)
1074
- return [];
1075
- const stringNames = tools.filter((t) => typeof t === "string");
1076
- const resolvedDefs = new Map(taskTypesToTools(stringNames, registry).map((d) => [d.taskType, d]));
1077
- const constructors = getTaskConstructors2(registry);
1078
- const sources = [];
1079
- for (const tool of tools) {
1080
- if (typeof tool === "string") {
1081
- const def = resolvedDefs.get(tool);
1082
- if (def) {
1083
- const { taskType, ...definition } = def;
1084
- sources.push({
1085
- type: "registry",
1086
- definition,
1087
- taskType
1088
- });
1089
- }
1090
- } else if (tool.execute) {
1091
- const { execute, configSchema: _cs, config: _c, ...definition } = tool;
1092
- sources.push({
1093
- type: "function",
1094
- definition,
1095
- run: execute
1096
- });
1097
- } else {
1098
- const ctor = constructors.get(tool.name);
1099
- if (ctor) {
1100
- const { execute: _e, configSchema: _cs, config: _c, ...definition } = tool;
1101
- sources.push({
1102
- type: "registry",
1103
- definition,
1104
- taskType: tool.name,
1105
- config: tool.config
1106
- });
1107
- } else {
1108
- const { execute: _e, configSchema: _cs, config: _c, ...definition } = tool;
1109
- sources.push({
1110
- type: "function",
1111
- definition,
1112
- run: async () => {
1113
- throw new Error(`No executor registered for tool "${tool.name}"`);
1114
- }
1115
- });
1116
- }
1117
- }
1118
- }
1119
- return sources;
1120
- }
1121
- async function executeToolCall(toolCall, sources, context, hooks) {
1122
- const source = findToolSource(sources, toolCall.name);
1123
- if (!source) {
1124
- getLogger2().warn(`AgentTask: Unknown tool "${toolCall.name}" \u2014 not found in tool sources`);
1125
- return {
1126
- toolCallId: toolCall.id,
1127
- toolName: toolCall.name,
1128
- output: { error: `Unknown tool: ${toolCall.name}` },
1129
- isError: true
1130
- };
1131
- }
1132
- let effectiveCall = toolCall;
1133
- if (hooks?.beforeToolCall) {
1134
- const decision = await hooks.beforeToolCall(toolCall, source);
1135
- if (decision.action === "deny") {
1136
- return {
1137
- toolCallId: toolCall.id,
1138
- toolName: toolCall.name,
1139
- output: { error: decision.reason ?? "Tool call denied by hook" },
1140
- isError: true
1141
- };
1142
- }
1143
- if (decision.action === "modify") {
1144
- effectiveCall = { ...toolCall, input: decision.input };
1145
- }
1146
- }
1147
- try {
1148
- let output;
1149
- switch (source.type) {
1150
- case "registry": {
1151
- const ctor = getTaskConstructors2(context.registry).get(source.taskType);
1152
- if (!ctor) {
1153
- throw new Error(`Task type "${source.taskType}" not found in TaskRegistry`);
1154
- }
1155
- const taskConfig = source.config ?? {};
1156
- const task = context.own(new ctor({}, taskConfig));
1157
- output = await task.run(effectiveCall.input) ?? {};
1158
- break;
1159
- }
1160
- case "function": {
1161
- output = await source.run(effectiveCall.input);
1162
- break;
1163
- }
1164
- }
1165
- let result = {
1166
- toolCallId: toolCall.id,
1167
- toolName: toolCall.name,
1168
- output,
1169
- isError: false
1170
- };
1171
- if (hooks?.afterToolCall) {
1172
- result = await hooks.afterToolCall(toolCall, result);
1173
- }
1174
- return result;
1175
- } catch (err) {
1176
- const error = err instanceof Error ? err : new Error(String(err));
1177
- if (hooks?.onToolError) {
1178
- const action = await hooks.onToolError(toolCall, error);
1179
- if (action.action === "result") {
1180
- return {
1181
- toolCallId: toolCall.id,
1182
- toolName: toolCall.name,
1183
- output: action.output,
1184
- isError: false
1185
- };
1186
- }
1187
- }
1188
- getLogger2().warn(`AgentTask: Tool "${toolCall.name}" failed: ${error.message}`);
1189
- return {
1190
- toolCallId: toolCall.id,
1191
- toolName: toolCall.name,
1192
- output: { error: error.message },
1193
- isError: true
1194
- };
1195
- }
1196
- }
1197
- async function executeToolCalls(toolCalls, sources, context, hooks, maxConcurrency = 5) {
1198
- const calls = toolCalls;
1199
- if (calls.length === 0)
1200
- return [];
1201
- const concurrency = Math.max(1, Math.min(maxConcurrency, calls.length));
1202
- const results = new Array(calls.length);
1203
- let cursor = 0;
1204
- const workers = Array.from({ length: concurrency }, async () => {
1205
- while (true) {
1206
- if (context.signal.aborted) {
1207
- throw context.signal.reason ?? new DOMException("The operation was aborted", "AbortError");
1208
- }
1209
- const position = cursor;
1210
- cursor += 1;
1211
- if (position >= calls.length)
1212
- return;
1213
- results[position] = await executeToolCall(calls[position], sources, context, hooks);
1214
- }
1215
- });
1216
- await Promise.all(workers);
1217
- return results;
1218
- }
1219
- function hasToolCalls(toolCalls) {
1220
- return toolCalls !== undefined && toolCalls.length > 0;
1221
- }
1222
-
1223
- // src/task/AgentTask.ts
1224
- var modelSchema2 = TypeModel("model:ToolCallingTask");
1225
- var AgentInputSchema = {
1226
- type: "object",
1227
- properties: {
1228
- model: modelSchema2,
1229
- prompt: {
1230
- oneOf: [
1231
- { type: "string" },
1232
- {
1233
- type: "array",
1234
- items: {
1235
- type: "object",
1236
- properties: {
1237
- type: { type: "string", enum: ["text", "image", "audio"] }
1238
- },
1239
- required: ["type"],
1240
- additionalProperties: true
1241
- }
1242
- }
1243
- ],
1244
- title: "Prompt",
1245
- description: "The user prompt to start the agent loop. Can be a string or an array of content blocks (text, image, audio)."
1246
- },
1247
- systemPrompt: {
1248
- type: "string",
1249
- title: "System Prompt",
1250
- description: "Optional system instructions for the agent"
1251
- },
1252
- tools: {
1253
- type: "array",
1254
- format: "tasks",
1255
- title: "Tools",
1256
- 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.",
1257
- items: {
1258
- oneOf: [
1259
- { type: "string", format: "tasks", description: "Task type name" },
1260
- ToolDefinitionSchema
1261
- ]
1262
- }
1263
- },
1264
- stopTool: {
1265
- type: "string",
1266
- title: "Stop Tool",
1267
- description: "Name of a tool that signals agent completion. When called, the loop ends and the tool input becomes structuredOutput.",
1268
- "x-ui-group": "Configuration"
1269
- },
1270
- maxIterations: {
1271
- type: "number",
1272
- title: "Max Iterations",
1273
- description: "Maximum number of agent loop iterations (default: 10)",
1274
- minimum: 1,
1275
- "x-ui-group": "Configuration"
1276
- },
1277
- maxContextMessages: {
1278
- type: "number",
1279
- title: "Max Context Messages",
1280
- description: "Maximum messages in conversation history. Older messages are trimmed to prevent context overflow.",
1281
- minimum: 3,
1282
- "x-ui-group": "Configuration"
1283
- },
1284
- maxTokens: {
1285
- type: "number",
1286
- title: "Max Tokens",
1287
- description: "Maximum tokens per LLM call",
1288
- minimum: 1,
1289
- "x-ui-group": "Configuration"
1290
- },
1291
- temperature: {
1292
- type: "number",
1293
- title: "Temperature",
1294
- description: "Sampling temperature for LLM calls",
1295
- minimum: 0,
1296
- maximum: 2,
1297
- "x-ui-group": "Configuration"
1298
- }
1299
- },
1300
- required: ["model", "prompt"],
1301
- additionalProperties: false
1302
- };
1303
- var AgentOutputSchema = {
1304
- type: "object",
1305
- properties: {
1306
- text: {
1307
- type: "string",
1308
- title: "Text",
1309
- description: "The final text response from the agent",
1310
- "x-stream": "append"
1311
- },
1312
- messages: {
1313
- type: "array",
1314
- title: "Messages",
1315
- description: "Full conversation history including all tool calls and results",
1316
- items: {
1317
- type: "object",
1318
- additionalProperties: true
1319
- }
1320
- },
1321
- iterations: {
1322
- type: "number",
1323
- title: "Iterations",
1324
- description: "Number of LLM calls made during the agent loop"
1325
- },
1326
- toolCallCount: {
1327
- type: "number",
1328
- title: "Tool Call Count",
1329
- description: "Total number of tool calls executed"
1330
- },
1331
- structuredOutput: {
1332
- type: "object",
1333
- title: "Structured Output",
1334
- description: "Present when the agent terminated via a stop tool",
1335
- additionalProperties: true
1336
- }
1337
- },
1338
- required: ["text", "messages", "iterations", "toolCallCount"],
1339
- additionalProperties: false
1340
- };
1341
-
1342
- class AgentTask extends Task {
1343
- static type = "AgentTask";
1344
- static category = "AI Agent";
1345
- static title = "Agent";
1346
- static description = "Multi-turn agentic loop that calls an LLM with tools, executes tool calls, and iterates until done";
1347
- static cacheable = false;
1348
- static inputSchema() {
1349
- return AgentInputSchema;
1350
- }
1351
- static outputSchema() {
1352
- return AgentOutputSchema;
1353
- }
1354
- async execute(input, context) {
1355
- let result;
1356
- for await (const event of this.agentLoop(input, context)) {
1357
- if (event.type === "finish") {
1358
- result = event.data;
1359
- }
1360
- }
1361
- if (!result) {
1362
- throw new Error("AgentTask: loop ended without producing output");
1363
- }
1364
- return result;
1365
- }
1366
- async* executeStream(input, context) {
1367
- yield* this.agentLoop(input, context);
1368
- }
1369
- async* agentLoop(input, context) {
1370
- const maxIterations = input.maxIterations ?? 10;
1371
- const hooks = this.config.hooks;
1372
- const maxConcurrency = this.config.maxConcurrency ?? 5;
1373
- const toolSources = this.resolveToolSources(input, context);
1374
- const toolDefs = this.resolveToolDefs(toolSources, input.stopTool);
1375
- const messages = [userMessage(input.prompt)];
1376
- let totalToolCalls = 0;
1377
- let finalText = "";
1378
- let structuredOutput;
1379
- for (let iteration = 0;iteration < maxIterations; iteration++) {
1380
- if (context.signal.aborted)
1381
- break;
1382
- if (hooks?.onIteration) {
1383
- const action = await hooks.onIteration(iteration, messages, { totalToolCalls });
1384
- if (action.action === "stop")
1385
- break;
1386
- }
1387
- await context.updateProgress(Math.round(iteration / maxIterations * 100), `Agent iteration ${iteration + 1}`);
1388
- const contextMessages = this.trimMessages(messages, input.maxContextMessages);
1389
- const llmTask = context.own(new ToolCallingTask({}, {}));
1390
- let iterationText = "";
1391
- let toolCalls = [];
1392
- for await (const event of llmTask.executeStream({
1393
- model: input.model,
1394
- prompt: input.prompt,
1395
- systemPrompt: input.systemPrompt,
1396
- tools: toolDefs,
1397
- messages: contextMessages,
1398
- maxTokens: input.maxTokens,
1399
- temperature: input.temperature
1400
- }, context)) {
1401
- if (event.type === "text-delta") {
1402
- yield { type: "text-delta", port: "text", textDelta: event.textDelta };
1403
- iterationText += event.textDelta;
1404
- } else if (event.type === "finish") {
1405
- const data = event.data;
1406
- iterationText = data?.text ?? iterationText;
1407
- if (data?.toolCalls) {
1408
- toolCalls = data.toolCalls ?? [];
1409
- }
1410
- }
1411
- }
1412
- finalText = iterationText;
1413
- messages.push(assistantMessage(iterationText, toolCalls));
1414
- if (input.stopTool) {
1415
- const stopCall = toolCalls.find((tc) => tc.name === input.stopTool);
1416
- if (stopCall) {
1417
- structuredOutput = stopCall.input;
1418
- break;
1001
+ input[key] = undefined;
1002
+ }
1419
1003
  }
1420
1004
  }
1421
- if (!hasToolCalls(toolCalls)) {
1422
- break;
1423
- }
1424
- const results = await executeToolCalls(toolCalls, toolSources, context, hooks, maxConcurrency);
1425
- totalToolCalls += results.length;
1426
- messages.push(toolMessage(results));
1427
- }
1428
- const output = {
1429
- text: finalText,
1430
- messages,
1431
- iterations: messages.filter((m) => m.role === "assistant").length,
1432
- toolCallCount: totalToolCalls,
1433
- ...structuredOutput !== undefined ? { structuredOutput } : {}
1434
- };
1435
- yield { type: "finish", data: output };
1436
- }
1437
- resolveToolSources(input, context) {
1438
- return buildToolSources(input.tools, context.registry);
1439
- }
1440
- resolveToolDefs(toolSources, stopTool) {
1441
- const defs = toolSourceDefinitions(toolSources);
1442
- if (stopTool && !defs.some((d) => d.name === stopTool)) {
1443
- defs.push({
1444
- name: stopTool,
1445
- description: "Call this tool when you have completed the task. Pass your final structured result as the input.",
1446
- inputSchema: { type: "object", additionalProperties: true }
1447
- });
1448
1005
  }
1449
- return defs;
1450
- }
1451
- trimMessages(messages, maxContextMessages) {
1452
- if (!maxContextMessages || messages.length <= maxContextMessages) {
1453
- return messages;
1454
- }
1455
- getLogger3().debug(`AgentTask: Trimming context from ${messages.length} to ${maxContextMessages} messages`);
1456
- const tail = messages.slice(1);
1457
- let startIdx = tail.length - (maxContextMessages - 1);
1458
- if (startIdx < 0)
1459
- startIdx = 0;
1460
- if (startIdx > 0 && startIdx < tail.length && tail[startIdx].role === "tool") {
1461
- startIdx -= 1;
1462
- }
1463
- return [messages[0], ...tail.slice(startIdx)];
1006
+ return input;
1464
1007
  }
1465
1008
  }
1466
- var agent = (input, config) => {
1467
- return new AgentTask({}, config).run(input);
1468
- };
1469
- Workflow2.prototype.agent = CreateWorkflow2(AgentTask);
1470
-
1471
- // src/task/BackgroundRemovalTask.ts
1472
- import { CreateWorkflow as CreateWorkflow3, Workflow as Workflow3 } from "@workglow/task-graph";
1473
1009
 
1474
1010
  // src/task/base/AiVisionTask.ts
1475
- import { convertImageDataToUseableForm } from "@workglow/util/media";
1476
1011
  class AiVisionTask extends AiTask {
1477
1012
  static type = "AiVisionTask";
1478
1013
  async getJobInput(input) {
1479
1014
  const jobInput = await super.getJobInput(input);
1480
- const registeredQueue = await this.resolveQueue(input);
1481
- const queueName = registeredQueue?.server.queueName;
1015
+ const providerName = input.model.provider;
1482
1016
  const supports = ["Blob"];
1483
1017
  if (input.image) {
1484
- if (typeof queueName === "string" && queueName.startsWith("TENSORFLOW_MEDIAPIPE") && "ImageBitmap" in globalThis) {
1018
+ if (typeof providerName === "string" && providerName.startsWith("TENSORFLOW_MEDIAPIPE") && "ImageBitmap" in globalThis) {
1485
1019
  supports.push("ImageBitmap");
1486
- } else if (typeof queueName === "string" && queueName.startsWith("TENSORFLOW_MEDIAPIPE") && "VideoFrame" in globalThis) {
1020
+ } else if (typeof providerName === "string" && providerName.startsWith("TENSORFLOW_MEDIAPIPE") && "VideoFrame" in globalThis) {
1487
1021
  supports.push("VideoFrame");
1488
1022
  }
1489
- const image = await convertImageDataToUseableForm(input.image, supports);
1023
+ const image = Array.isArray(input.image) ? await Promise.all(input.image.map((img) => convertImageDataToUseableForm(img, supports))) : await convertImageDataToUseableForm(input.image, supports);
1490
1024
  jobInput.taskInput.image = image;
1491
1025
  }
1492
1026
  return jobInput;
@@ -1494,7 +1028,7 @@ class AiVisionTask extends AiTask {
1494
1028
  }
1495
1029
 
1496
1030
  // src/task/BackgroundRemovalTask.ts
1497
- var modelSchema3 = TypeModel("model:BackgroundRemovalTask");
1031
+ var modelSchema = TypeModel("model:BackgroundRemovalTask");
1498
1032
  var processedImageSchema = {
1499
1033
  type: "string",
1500
1034
  contentEncoding: "base64",
@@ -1506,7 +1040,7 @@ var BackgroundRemovalInputSchema = {
1506
1040
  type: "object",
1507
1041
  properties: {
1508
1042
  image: TypeImageInput,
1509
- model: modelSchema3
1043
+ model: modelSchema
1510
1044
  },
1511
1045
  required: ["image", "model"],
1512
1046
  additionalProperties: false
@@ -1535,26 +1069,22 @@ class BackgroundRemovalTask extends AiVisionTask {
1535
1069
  var backgroundRemoval = (input, config) => {
1536
1070
  return new BackgroundRemovalTask({}, config).run(input);
1537
1071
  };
1538
- Workflow3.prototype.backgroundRemoval = CreateWorkflow3(BackgroundRemovalTask);
1072
+ Workflow.prototype.backgroundRemoval = CreateWorkflow(BackgroundRemovalTask);
1539
1073
 
1540
1074
  // src/task/ChunkRetrievalTask.ts
1541
1075
  import { TypeKnowledgeBase } from "@workglow/knowledge-base";
1542
- import {
1543
- CreateWorkflow as CreateWorkflow5,
1544
- Task as Task2,
1545
- Workflow as Workflow5
1546
- } from "@workglow/task-graph";
1076
+ import { CreateWorkflow as CreateWorkflow3, Task as Task2, Workflow as Workflow3 } from "@workglow/task-graph";
1547
1077
  import {
1548
1078
  isTypedArray,
1549
1079
  TypedArraySchema as TypedArraySchema2
1550
1080
  } from "@workglow/util/schema";
1551
1081
 
1552
1082
  // src/task/TextEmbeddingTask.ts
1553
- import { CreateWorkflow as CreateWorkflow4, Workflow as Workflow4 } from "@workglow/task-graph";
1083
+ import { CreateWorkflow as CreateWorkflow2, Workflow as Workflow2 } from "@workglow/task-graph";
1554
1084
  import {
1555
1085
  TypedArraySchema
1556
1086
  } from "@workglow/util/schema";
1557
- var modelSchema4 = TypeModel("model:TextEmbeddingTask");
1087
+ var modelSchema2 = TypeModel("model:TextEmbeddingTask");
1558
1088
  var TextEmbeddingInputSchema = {
1559
1089
  type: "object",
1560
1090
  properties: {
@@ -1563,7 +1093,7 @@ var TextEmbeddingInputSchema = {
1563
1093
  title: "Text",
1564
1094
  description: "The text to embed"
1565
1095
  }),
1566
- model: modelSchema4
1096
+ model: modelSchema2
1567
1097
  },
1568
1098
  required: ["text", "model"],
1569
1099
  additionalProperties: false
@@ -1595,7 +1125,7 @@ class TextEmbeddingTask extends AiTask {
1595
1125
  var textEmbedding = async (input, config) => {
1596
1126
  return new TextEmbeddingTask({}, config).run(input);
1597
1127
  };
1598
- Workflow4.prototype.textEmbedding = CreateWorkflow4(TextEmbeddingTask);
1128
+ Workflow2.prototype.textEmbedding = CreateWorkflow2(TextEmbeddingTask);
1599
1129
 
1600
1130
  // src/task/ChunkRetrievalTask.ts
1601
1131
  var inputSchema = {
@@ -1787,15 +1317,11 @@ class ChunkRetrievalTask extends Task2 {
1787
1317
  var chunkRetrieval = (input, config) => {
1788
1318
  return new ChunkRetrievalTask({}, config).run(input);
1789
1319
  };
1790
- Workflow5.prototype.chunkRetrieval = CreateWorkflow5(ChunkRetrievalTask);
1320
+ Workflow3.prototype.chunkRetrieval = CreateWorkflow3(ChunkRetrievalTask);
1791
1321
 
1792
1322
  // src/task/ChunkToVectorTask.ts
1793
1323
  import { ChunkRecordSchema } from "@workglow/knowledge-base";
1794
- import {
1795
- CreateWorkflow as CreateWorkflow6,
1796
- Task as Task3,
1797
- Workflow as Workflow6
1798
- } from "@workglow/task-graph";
1324
+ import { CreateWorkflow as CreateWorkflow4, Task as Task3, Workflow as Workflow4 } from "@workglow/task-graph";
1799
1325
  import {
1800
1326
  TypedArraySchema as TypedArraySchema3
1801
1327
  } from "@workglow/util/schema";
@@ -1921,15 +1447,11 @@ class ChunkToVectorTask extends Task3 {
1921
1447
  var chunkToVector = (input, config) => {
1922
1448
  return new ChunkToVectorTask({}, config).run(input);
1923
1449
  };
1924
- Workflow6.prototype.chunkToVector = CreateWorkflow6(ChunkToVectorTask);
1450
+ Workflow4.prototype.chunkToVector = CreateWorkflow4(ChunkToVectorTask);
1925
1451
 
1926
1452
  // src/task/ChunkVectorHybridSearchTask.ts
1927
1453
  import { TypeKnowledgeBase as TypeKnowledgeBase2 } from "@workglow/knowledge-base";
1928
- import {
1929
- CreateWorkflow as CreateWorkflow7,
1930
- Task as Task4,
1931
- Workflow as Workflow7
1932
- } from "@workglow/task-graph";
1454
+ import { CreateWorkflow as CreateWorkflow5, Task as Task4, Workflow as Workflow5 } from "@workglow/task-graph";
1933
1455
  import {
1934
1456
  TypedArraySchema as TypedArraySchema4
1935
1457
  } from "@workglow/util/schema";
@@ -2095,15 +1617,11 @@ class ChunkVectorHybridSearchTask extends Task4 {
2095
1617
  var hybridSearch = async (input, config) => {
2096
1618
  return new ChunkVectorHybridSearchTask({}, config).run(input);
2097
1619
  };
2098
- Workflow7.prototype.hybridSearch = CreateWorkflow7(ChunkVectorHybridSearchTask);
1620
+ Workflow5.prototype.hybridSearch = CreateWorkflow5(ChunkVectorHybridSearchTask);
2099
1621
 
2100
1622
  // src/task/ChunkVectorSearchTask.ts
2101
1623
  import { TypeKnowledgeBase as TypeKnowledgeBase3 } from "@workglow/knowledge-base";
2102
- import {
2103
- CreateWorkflow as CreateWorkflow8,
2104
- Task as Task5,
2105
- Workflow as Workflow8
2106
- } from "@workglow/task-graph";
1624
+ import { CreateWorkflow as CreateWorkflow6, Task as Task5, Workflow as Workflow6 } from "@workglow/task-graph";
2107
1625
  import {
2108
1626
  TypedArraySchema as TypedArraySchema5
2109
1627
  } from "@workglow/util/schema";
@@ -2218,15 +1736,11 @@ class ChunkVectorSearchTask extends Task5 {
2218
1736
  var vectorStoreSearch = (input, config) => {
2219
1737
  return new ChunkVectorSearchTask({}, config).run(input);
2220
1738
  };
2221
- Workflow8.prototype.vectorStoreSearch = CreateWorkflow8(ChunkVectorSearchTask);
1739
+ Workflow6.prototype.vectorStoreSearch = CreateWorkflow6(ChunkVectorSearchTask);
2222
1740
 
2223
1741
  // src/task/ChunkVectorUpsertTask.ts
2224
1742
  import { TypeKnowledgeBase as TypeKnowledgeBase4 } from "@workglow/knowledge-base";
2225
- import {
2226
- CreateWorkflow as CreateWorkflow9,
2227
- Task as Task6,
2228
- Workflow as Workflow9
2229
- } from "@workglow/task-graph";
1743
+ import { CreateWorkflow as CreateWorkflow7, Task as Task6, Workflow as Workflow7 } from "@workglow/task-graph";
2230
1744
  import {
2231
1745
  TypedArraySchema as TypedArraySchema6
2232
1746
  } from "@workglow/util/schema";
@@ -2340,28 +1854,28 @@ class ChunkVectorUpsertTask extends Task6 {
2340
1854
  var chunkVectorUpsert = (input, config) => {
2341
1855
  return new ChunkVectorUpsertTask({}, config).run(input);
2342
1856
  };
2343
- Workflow9.prototype.chunkVectorUpsert = CreateWorkflow9(ChunkVectorUpsertTask);
1857
+ Workflow7.prototype.chunkVectorUpsert = CreateWorkflow7(ChunkVectorUpsertTask);
2344
1858
 
2345
1859
  // src/task/ContextBuilderTask.ts
2346
1860
  import { estimateTokens } from "@workglow/knowledge-base";
2347
1861
  import {
2348
- CreateWorkflow as CreateWorkflow11,
1862
+ CreateWorkflow as CreateWorkflow9,
2349
1863
  Task as Task7,
2350
- Workflow as Workflow11
1864
+ Workflow as Workflow9
2351
1865
  } from "@workglow/task-graph";
2352
1866
 
2353
1867
  // src/task/CountTokensTask.ts
2354
- import { CreateWorkflow as CreateWorkflow10, Workflow as Workflow10 } from "@workglow/task-graph";
2355
- var modelSchema5 = TypeModel("model");
1868
+ import { CreateWorkflow as CreateWorkflow8, Workflow as Workflow8 } from "@workglow/task-graph";
1869
+ var modelSchema3 = TypeModel("model");
2356
1870
  var CountTokensInputSchema = {
2357
1871
  type: "object",
2358
1872
  properties: {
2359
- text: TypeSingleOrArray({
1873
+ text: {
2360
1874
  type: "string",
2361
1875
  title: "Text",
2362
1876
  description: "The text to count tokens for"
2363
- }),
2364
- model: modelSchema5
1877
+ },
1878
+ model: modelSchema3
2365
1879
  },
2366
1880
  required: ["text", "model"],
2367
1881
  additionalProperties: false
@@ -2369,11 +1883,11 @@ var CountTokensInputSchema = {
2369
1883
  var CountTokensOutputSchema = {
2370
1884
  type: "object",
2371
1885
  properties: {
2372
- count: TypeSingleOrArray({
1886
+ count: {
2373
1887
  type: "number",
2374
1888
  title: "Token Count",
2375
1889
  description: "The number of tokens in the text"
2376
- })
1890
+ }
2377
1891
  },
2378
1892
  required: ["count"],
2379
1893
  additionalProperties: false
@@ -2395,7 +1909,7 @@ class CountTokensTask extends AiTask {
2395
1909
  var countTokens = async (input, config) => {
2396
1910
  return new CountTokensTask({}, config).run(input);
2397
1911
  };
2398
- Workflow10.prototype.countTokens = CreateWorkflow10(CountTokensTask);
1912
+ Workflow8.prototype.countTokens = CreateWorkflow8(CountTokensTask);
2399
1913
 
2400
1914
  // src/task/ContextBuilderTask.ts
2401
1915
  var ContextFormat = {
@@ -2405,7 +1919,7 @@ var ContextFormat = {
2405
1919
  MARKDOWN: "markdown",
2406
1920
  JSON: "json"
2407
1921
  };
2408
- var modelSchema6 = TypeModel("model", {
1922
+ var modelSchema4 = TypeModel("model", {
2409
1923
  title: "Model",
2410
1924
  description: "Model to use for token counting (optional, falls back to estimation)"
2411
1925
  });
@@ -2469,7 +1983,7 @@ var inputSchema6 = {
2469
1983
 
2470
1984
  `
2471
1985
  },
2472
- model: modelSchema6
1986
+ model: modelSchema4
2473
1987
  },
2474
1988
  required: ["chunks"],
2475
1989
  additionalProperties: false
@@ -2695,30 +2209,26 @@ class ContextBuilderTask extends Task7 {
2695
2209
  var contextBuilder = (input, config) => {
2696
2210
  return new ContextBuilderTask({}, config).run(input);
2697
2211
  };
2698
- Workflow11.prototype.contextBuilder = CreateWorkflow11(ContextBuilderTask);
2212
+ Workflow9.prototype.contextBuilder = CreateWorkflow9(ContextBuilderTask);
2699
2213
 
2700
2214
  // src/task/DocumentEnricherTask.ts
2701
2215
  import {
2702
2216
  getChildren,
2703
2217
  hasChildren
2704
2218
  } from "@workglow/knowledge-base";
2705
- import {
2706
- CreateWorkflow as CreateWorkflow14,
2707
- Task as Task8,
2708
- Workflow as Workflow14
2709
- } from "@workglow/task-graph";
2219
+ import { CreateWorkflow as CreateWorkflow12, Task as Task8, Workflow as Workflow12 } from "@workglow/task-graph";
2710
2220
 
2711
2221
  // src/task/TextNamedEntityRecognitionTask.ts
2712
- import { CreateWorkflow as CreateWorkflow12, Workflow as Workflow12 } from "@workglow/task-graph";
2713
- var modelSchema7 = TypeModel("model:TextNamedEntityRecognitionTask");
2222
+ import { CreateWorkflow as CreateWorkflow10, Workflow as Workflow10 } from "@workglow/task-graph";
2223
+ var modelSchema5 = TypeModel("model:TextNamedEntityRecognitionTask");
2714
2224
  var TextNamedEntityRecognitionInputSchema = {
2715
2225
  type: "object",
2716
2226
  properties: {
2717
- text: TypeSingleOrArray({
2227
+ text: {
2718
2228
  type: "string",
2719
2229
  title: "Text",
2720
2230
  description: "The text to extract named entities from"
2721
- }),
2231
+ },
2722
2232
  blockList: {
2723
2233
  type: "array",
2724
2234
  items: {
@@ -2729,7 +2239,7 @@ var TextNamedEntityRecognitionInputSchema = {
2729
2239
  "x-ui-group": "Configuration",
2730
2240
  "x-ui-group-open": false
2731
2241
  },
2732
- model: modelSchema7
2242
+ model: modelSchema5
2733
2243
  },
2734
2244
  required: ["text", "model"],
2735
2245
  additionalProperties: false
@@ -2737,7 +2247,7 @@ var TextNamedEntityRecognitionInputSchema = {
2737
2247
  var TextNamedEntityRecognitionOutputSchema = {
2738
2248
  type: "object",
2739
2249
  properties: {
2740
- entities: TypeSingleOrArray({
2250
+ entities: {
2741
2251
  type: "array",
2742
2252
  items: {
2743
2253
  type: "object",
@@ -2763,7 +2273,7 @@ var TextNamedEntityRecognitionOutputSchema = {
2763
2273
  },
2764
2274
  title: "Entities",
2765
2275
  description: "The extracted named entities with their types, scores, and text"
2766
- })
2276
+ }
2767
2277
  },
2768
2278
  required: ["entities"],
2769
2279
  additionalProperties: false
@@ -2784,20 +2294,60 @@ class TextNamedEntityRecognitionTask extends AiTask {
2784
2294
  var textNamedEntityRecognition = (input, config) => {
2785
2295
  return new TextNamedEntityRecognitionTask({}, config).run(input);
2786
2296
  };
2787
- Workflow12.prototype.textNamedEntityRecognition = CreateWorkflow12(TextNamedEntityRecognitionTask);
2297
+ Workflow10.prototype.textNamedEntityRecognition = CreateWorkflow10(TextNamedEntityRecognitionTask);
2788
2298
 
2789
2299
  // src/task/TextSummaryTask.ts
2790
- import { CreateWorkflow as CreateWorkflow13, Workflow as Workflow13 } from "@workglow/task-graph";
2791
- var modelSchema8 = TypeModel("model:TextSummaryTask");
2300
+ import { CreateWorkflow as CreateWorkflow11, Workflow as Workflow11 } from "@workglow/task-graph";
2301
+
2302
+ // src/task/base/StreamingAiTask.ts
2303
+ import {
2304
+ getStreamingPorts,
2305
+ TaskConfigurationError as TaskConfigurationError3
2306
+ } from "@workglow/task-graph";
2307
+ class StreamingAiTask extends AiTask {
2308
+ static type = "StreamingAiTask";
2309
+ async* executeStream(input, context) {
2310
+ const model = input.model;
2311
+ if (!model || typeof model !== "object") {
2312
+ throw new TaskConfigurationError3("StreamingAiTask: Model was not resolved to ModelConfig - this indicates a bug in the resolution system");
2313
+ }
2314
+ const jobInput = await this.getJobInput(input);
2315
+ const strategy = getAiProviderRegistry().getStrategy(model);
2316
+ const outSchema = this.outputSchema();
2317
+ const ports = getStreamingPorts(outSchema);
2318
+ let defaultPort = "text";
2319
+ if (ports.length > 0) {
2320
+ defaultPort = ports[0].port;
2321
+ } else {
2322
+ if (typeof outSchema === "object" && outSchema.properties) {
2323
+ const firstProp = Object.keys(outSchema.properties)[0];
2324
+ if (firstProp)
2325
+ defaultPort = firstProp;
2326
+ }
2327
+ }
2328
+ for await (const event of strategy.executeStream(jobInput, context, this.runConfig.runnerId)) {
2329
+ if (event.type === "text-delta") {
2330
+ yield { ...event, port: event.port ?? defaultPort };
2331
+ } else if (event.type === "object-delta") {
2332
+ yield { ...event, port: event.port ?? defaultPort };
2333
+ } else {
2334
+ yield event;
2335
+ }
2336
+ }
2337
+ }
2338
+ }
2339
+
2340
+ // src/task/TextSummaryTask.ts
2341
+ var modelSchema6 = TypeModel("model:TextSummaryTask");
2792
2342
  var TextSummaryInputSchema = {
2793
2343
  type: "object",
2794
2344
  properties: {
2795
- text: TypeSingleOrArray({
2345
+ text: {
2796
2346
  type: "string",
2797
2347
  title: "Text",
2798
2348
  description: "The text to summarize"
2799
- }),
2800
- model: modelSchema8
2349
+ },
2350
+ model: modelSchema6
2801
2351
  },
2802
2352
  required: ["text", "model"],
2803
2353
  additionalProperties: false
@@ -2805,12 +2355,12 @@ var TextSummaryInputSchema = {
2805
2355
  var TextSummaryOutputSchema = {
2806
2356
  type: "object",
2807
2357
  properties: {
2808
- text: TypeSingleOrArray({
2358
+ text: {
2809
2359
  type: "string",
2810
2360
  title: "Text",
2811
2361
  description: "The summarized text",
2812
2362
  "x-stream": "append"
2813
- })
2363
+ }
2814
2364
  },
2815
2365
  required: ["text"],
2816
2366
  additionalProperties: false
@@ -2831,7 +2381,7 @@ class TextSummaryTask extends StreamingAiTask {
2831
2381
  var textSummary = async (input, config) => {
2832
2382
  return new TextSummaryTask({}, config).run(input);
2833
2383
  };
2834
- Workflow13.prototype.textSummary = CreateWorkflow13(TextSummaryTask);
2384
+ Workflow11.prototype.textSummary = CreateWorkflow11(TextSummaryTask);
2835
2385
 
2836
2386
  // src/task/DocumentEnricherTask.ts
2837
2387
  var inputSchema7 = {
@@ -3062,15 +2612,15 @@ class DocumentEnricherTask extends Task8 {
3062
2612
  var documentEnricher = (input, config) => {
3063
2613
  return new DocumentEnricherTask({}, config).run(input);
3064
2614
  };
3065
- Workflow14.prototype.documentEnricher = CreateWorkflow14(DocumentEnricherTask);
2615
+ Workflow12.prototype.documentEnricher = CreateWorkflow12(DocumentEnricherTask);
3066
2616
 
3067
2617
  // src/task/DownloadModelTask.ts
3068
- import { CreateWorkflow as CreateWorkflow15, Workflow as Workflow15 } from "@workglow/task-graph";
3069
- var modelSchema9 = TypeModel("model");
2618
+ import { CreateWorkflow as CreateWorkflow13, Workflow as Workflow13 } from "@workglow/task-graph";
2619
+ var modelSchema7 = TypeModel("model");
3070
2620
  var DownloadModelInputSchema = {
3071
2621
  type: "object",
3072
2622
  properties: {
3073
- model: modelSchema9
2623
+ model: modelSchema7
3074
2624
  },
3075
2625
  required: ["model"],
3076
2626
  additionalProperties: false
@@ -3078,7 +2628,7 @@ var DownloadModelInputSchema = {
3078
2628
  var DownloadModelOutputSchema = {
3079
2629
  type: "object",
3080
2630
  properties: {
3081
- model: modelSchema9
2631
+ model: modelSchema7
3082
2632
  },
3083
2633
  required: ["model"],
3084
2634
  additionalProperties: false
@@ -3132,11 +2682,11 @@ class DownloadModelTask extends AiTask {
3132
2682
  var downloadModel = (input, config) => {
3133
2683
  return new DownloadModelTask({}, config).run(input);
3134
2684
  };
3135
- Workflow15.prototype.downloadModel = CreateWorkflow15(DownloadModelTask);
2685
+ Workflow13.prototype.downloadModel = CreateWorkflow13(DownloadModelTask);
3136
2686
 
3137
2687
  // src/task/FaceDetectorTask.ts
3138
- import { CreateWorkflow as CreateWorkflow16, Workflow as Workflow16 } from "@workglow/task-graph";
3139
- var modelSchema10 = TypeModel("model:FaceDetectorTask");
2688
+ import { CreateWorkflow as CreateWorkflow14, Workflow as Workflow14 } from "@workglow/task-graph";
2689
+ var modelSchema8 = TypeModel("model:FaceDetectorTask");
3140
2690
  var TypeBoundingBox2 = {
3141
2691
  type: "object",
3142
2692
  properties: {
@@ -3209,7 +2759,7 @@ var FaceDetectorInputSchema = {
3209
2759
  type: "object",
3210
2760
  properties: {
3211
2761
  image: TypeImageInput,
3212
- model: modelSchema10,
2762
+ model: modelSchema8,
3213
2763
  minDetectionConfidence: {
3214
2764
  type: "number",
3215
2765
  minimum: 0,
@@ -3263,11 +2813,11 @@ class FaceDetectorTask extends AiVisionTask {
3263
2813
  var faceDetector = (input, config) => {
3264
2814
  return new FaceDetectorTask({}, config).run(input);
3265
2815
  };
3266
- Workflow16.prototype.faceDetector = CreateWorkflow16(FaceDetectorTask);
2816
+ Workflow14.prototype.faceDetector = CreateWorkflow14(FaceDetectorTask);
3267
2817
 
3268
2818
  // src/task/FaceLandmarkerTask.ts
3269
- import { CreateWorkflow as CreateWorkflow17, Workflow as Workflow17 } from "@workglow/task-graph";
3270
- var modelSchema11 = TypeModel("model:FaceLandmarkerTask");
2819
+ import { CreateWorkflow as CreateWorkflow15, Workflow as Workflow15 } from "@workglow/task-graph";
2820
+ var modelSchema9 = TypeModel("model:FaceLandmarkerTask");
3271
2821
  var TypeLandmark = {
3272
2822
  type: "object",
3273
2823
  properties: {
@@ -3339,7 +2889,7 @@ var FaceLandmarkerInputSchema = {
3339
2889
  type: "object",
3340
2890
  properties: {
3341
2891
  image: TypeImageInput,
3342
- model: modelSchema11,
2892
+ model: modelSchema9,
3343
2893
  numFaces: {
3344
2894
  type: "number",
3345
2895
  minimum: 1,
@@ -3425,11 +2975,11 @@ class FaceLandmarkerTask extends AiVisionTask {
3425
2975
  var faceLandmarker = (input, config) => {
3426
2976
  return new FaceLandmarkerTask({}, config).run(input);
3427
2977
  };
3428
- Workflow17.prototype.faceLandmarker = CreateWorkflow17(FaceLandmarkerTask);
2978
+ Workflow15.prototype.faceLandmarker = CreateWorkflow15(FaceLandmarkerTask);
3429
2979
 
3430
2980
  // src/task/GestureRecognizerTask.ts
3431
- import { CreateWorkflow as CreateWorkflow18, Workflow as Workflow18 } from "@workglow/task-graph";
3432
- var modelSchema12 = TypeModel("model:GestureRecognizerTask");
2981
+ import { CreateWorkflow as CreateWorkflow16, Workflow as Workflow16 } from "@workglow/task-graph";
2982
+ var modelSchema10 = TypeModel("model:GestureRecognizerTask");
3433
2983
  var TypeLandmark2 = {
3434
2984
  type: "object",
3435
2985
  properties: {
@@ -3521,7 +3071,7 @@ var GestureRecognizerInputSchema = {
3521
3071
  type: "object",
3522
3072
  properties: {
3523
3073
  image: TypeImageInput,
3524
- model: modelSchema12,
3074
+ model: modelSchema10,
3525
3075
  numHands: {
3526
3076
  type: "number",
3527
3077
  minimum: 1,
@@ -3593,11 +3143,11 @@ class GestureRecognizerTask extends AiVisionTask {
3593
3143
  var gestureRecognizer = (input, config) => {
3594
3144
  return new GestureRecognizerTask({}, config).run(input);
3595
3145
  };
3596
- Workflow18.prototype.gestureRecognizer = CreateWorkflow18(GestureRecognizerTask);
3146
+ Workflow16.prototype.gestureRecognizer = CreateWorkflow16(GestureRecognizerTask);
3597
3147
 
3598
3148
  // src/task/HandLandmarkerTask.ts
3599
- import { CreateWorkflow as CreateWorkflow19, Workflow as Workflow19 } from "@workglow/task-graph";
3600
- var modelSchema13 = TypeModel("model:HandLandmarkerTask");
3149
+ import { CreateWorkflow as CreateWorkflow17, Workflow as Workflow17 } from "@workglow/task-graph";
3150
+ var modelSchema11 = TypeModel("model:HandLandmarkerTask");
3601
3151
  var TypeLandmark3 = {
3602
3152
  type: "object",
3603
3153
  properties: {
@@ -3666,7 +3216,7 @@ var HandLandmarkerInputSchema = {
3666
3216
  type: "object",
3667
3217
  properties: {
3668
3218
  image: TypeImageInput,
3669
- model: modelSchema13,
3219
+ model: modelSchema11,
3670
3220
  numHands: {
3671
3221
  type: "number",
3672
3222
  minimum: 1,
@@ -3738,7 +3288,7 @@ class HandLandmarkerTask extends AiVisionTask {
3738
3288
  var handLandmarker = (input, config) => {
3739
3289
  return new HandLandmarkerTask({}, config).run(input);
3740
3290
  };
3741
- Workflow19.prototype.handLandmarker = CreateWorkflow19(HandLandmarkerTask);
3291
+ Workflow17.prototype.handLandmarker = CreateWorkflow17(HandLandmarkerTask);
3742
3292
 
3743
3293
  // src/task/HierarchicalChunkerTask.ts
3744
3294
  import {
@@ -3747,13 +3297,9 @@ import {
3747
3297
  getChildren as getChildren2,
3748
3298
  hasChildren as hasChildren2
3749
3299
  } from "@workglow/knowledge-base";
3750
- import {
3751
- CreateWorkflow as CreateWorkflow20,
3752
- Task as Task9,
3753
- Workflow as Workflow20
3754
- } from "@workglow/task-graph";
3300
+ import { CreateWorkflow as CreateWorkflow18, Task as Task9, Workflow as Workflow18 } from "@workglow/task-graph";
3755
3301
  import { uuid4 } from "@workglow/util";
3756
- var modelSchema14 = TypeModel("model", {
3302
+ var modelSchema12 = TypeModel("model", {
3757
3303
  title: "Model",
3758
3304
  description: "Model to use for token counting"
3759
3305
  });
@@ -3797,7 +3343,7 @@ var inputSchema8 = {
3797
3343
  description: "Strategy for chunking",
3798
3344
  default: "hierarchical"
3799
3345
  },
3800
- model: modelSchema14
3346
+ model: modelSchema12
3801
3347
  },
3802
3348
  required: ["doc_id", "documentTree"],
3803
3349
  additionalProperties: false
@@ -3976,18 +3522,14 @@ class HierarchicalChunkerTask extends Task9 {
3976
3522
  var hierarchicalChunker = (input, config) => {
3977
3523
  return new HierarchicalChunkerTask({}, config).run(input);
3978
3524
  };
3979
- Workflow20.prototype.hierarchicalChunker = CreateWorkflow20(HierarchicalChunkerTask);
3525
+ Workflow18.prototype.hierarchicalChunker = CreateWorkflow18(HierarchicalChunkerTask);
3980
3526
 
3981
3527
  // src/task/HierarchyJoinTask.ts
3982
3528
  import {
3983
3529
  ChunkRecordArraySchema,
3984
3530
  TypeKnowledgeBase as TypeKnowledgeBase5
3985
3531
  } from "@workglow/knowledge-base";
3986
- import {
3987
- CreateWorkflow as CreateWorkflow21,
3988
- Task as Task10,
3989
- Workflow as Workflow21
3990
- } from "@workglow/task-graph";
3532
+ import { CreateWorkflow as CreateWorkflow19, Task as Task10, Workflow as Workflow19 } from "@workglow/task-graph";
3991
3533
  var inputSchema9 = {
3992
3534
  type: "object",
3993
3535
  properties: {
@@ -4156,16 +3698,16 @@ class HierarchyJoinTask extends Task10 {
4156
3698
  var hierarchyJoin = (input, config) => {
4157
3699
  return new HierarchyJoinTask({}, config).run(input);
4158
3700
  };
4159
- Workflow21.prototype.hierarchyJoin = CreateWorkflow21(HierarchyJoinTask);
3701
+ Workflow19.prototype.hierarchyJoin = CreateWorkflow19(HierarchyJoinTask);
4160
3702
 
4161
3703
  // src/task/ImageClassificationTask.ts
4162
- import { CreateWorkflow as CreateWorkflow22, Workflow as Workflow22 } from "@workglow/task-graph";
4163
- var modelSchema15 = TypeModel("model:ImageClassificationTask");
3704
+ import { CreateWorkflow as CreateWorkflow20, Workflow as Workflow20 } from "@workglow/task-graph";
3705
+ var modelSchema13 = TypeModel("model:ImageClassificationTask");
4164
3706
  var ImageClassificationInputSchema = {
4165
3707
  type: "object",
4166
3708
  properties: {
4167
3709
  image: TypeImageInput,
4168
- model: modelSchema15,
3710
+ model: modelSchema13,
4169
3711
  categories: {
4170
3712
  type: "array",
4171
3713
  items: {
@@ -4219,23 +3761,19 @@ class ImageClassificationTask extends AiVisionTask {
4219
3761
  var imageClassification = (input, config) => {
4220
3762
  return new ImageClassificationTask({}, config).run(input);
4221
3763
  };
4222
- Workflow22.prototype.imageClassification = CreateWorkflow22(ImageClassificationTask);
3764
+ Workflow20.prototype.imageClassification = CreateWorkflow20(ImageClassificationTask);
4223
3765
 
4224
3766
  // src/task/ImageEmbeddingTask.ts
4225
- import { CreateWorkflow as CreateWorkflow23, Workflow as Workflow23 } from "@workglow/task-graph";
3767
+ import { CreateWorkflow as CreateWorkflow21, Workflow as Workflow21 } from "@workglow/task-graph";
4226
3768
  import {
4227
3769
  TypedArraySchema as TypedArraySchema7
4228
3770
  } from "@workglow/util/schema";
4229
- var modelSchema16 = TypeModel("model:ImageEmbeddingTask");
4230
- var embeddingSchema = TypedArraySchema7({
4231
- title: "Embedding",
4232
- description: "The image embedding vector"
4233
- });
3771
+ var modelSchema14 = TypeModel("model:ImageEmbeddingTask");
4234
3772
  var ImageEmbeddingInputSchema = {
4235
3773
  type: "object",
4236
3774
  properties: {
4237
- image: TypeImageInput,
4238
- model: modelSchema16
3775
+ image: TypeSingleOrArray(TypeImageInput),
3776
+ model: modelSchema14
4239
3777
  },
4240
3778
  required: ["image", "model"],
4241
3779
  additionalProperties: false
@@ -4243,7 +3781,10 @@ var ImageEmbeddingInputSchema = {
4243
3781
  var ImageEmbeddingOutputSchema = {
4244
3782
  type: "object",
4245
3783
  properties: {
4246
- vector: embeddingSchema
3784
+ vector: TypeSingleOrArray(TypedArraySchema7({
3785
+ title: "Embedding",
3786
+ description: "The image embedding vector"
3787
+ }))
4247
3788
  },
4248
3789
  required: ["vector"],
4249
3790
  additionalProperties: false
@@ -4264,16 +3805,16 @@ class ImageEmbeddingTask extends AiVisionTask {
4264
3805
  var imageEmbedding = (input, config) => {
4265
3806
  return new ImageEmbeddingTask({}, config).run(input);
4266
3807
  };
4267
- Workflow23.prototype.imageEmbedding = CreateWorkflow23(ImageEmbeddingTask);
3808
+ Workflow21.prototype.imageEmbedding = CreateWorkflow21(ImageEmbeddingTask);
4268
3809
 
4269
3810
  // src/task/ImageSegmentationTask.ts
4270
- import { CreateWorkflow as CreateWorkflow24, Workflow as Workflow24 } from "@workglow/task-graph";
4271
- var modelSchema17 = TypeModel("model:ImageSegmentationTask");
3811
+ import { CreateWorkflow as CreateWorkflow22, Workflow as Workflow22 } from "@workglow/task-graph";
3812
+ var modelSchema15 = TypeModel("model:ImageSegmentationTask");
4272
3813
  var ImageSegmentationInputSchema = {
4273
3814
  type: "object",
4274
3815
  properties: {
4275
3816
  image: TypeImageInput,
4276
- model: modelSchema17,
3817
+ model: modelSchema15,
4277
3818
  threshold: {
4278
3819
  type: "number",
4279
3820
  title: "Threshold",
@@ -4352,11 +3893,11 @@ class ImageSegmentationTask extends AiVisionTask {
4352
3893
  var imageSegmentation = (input, config) => {
4353
3894
  return new ImageSegmentationTask({}, config).run(input);
4354
3895
  };
4355
- Workflow24.prototype.imageSegmentation = CreateWorkflow24(ImageSegmentationTask);
3896
+ Workflow22.prototype.imageSegmentation = CreateWorkflow22(ImageSegmentationTask);
4356
3897
 
4357
3898
  // src/task/ImageToTextTask.ts
4358
- import { CreateWorkflow as CreateWorkflow25, Workflow as Workflow25 } from "@workglow/task-graph";
4359
- var modelSchema18 = TypeModel("model:ImageToTextTask");
3899
+ import { CreateWorkflow as CreateWorkflow23, Workflow as Workflow23 } from "@workglow/task-graph";
3900
+ var modelSchema16 = TypeModel("model:ImageToTextTask");
4360
3901
  var generatedTextSchema = {
4361
3902
  type: "string",
4362
3903
  title: "Text",
@@ -4366,7 +3907,7 @@ var ImageToTextInputSchema = {
4366
3907
  type: "object",
4367
3908
  properties: {
4368
3909
  image: TypeImageInput,
4369
- model: modelSchema18,
3910
+ model: modelSchema16,
4370
3911
  maxTokens: {
4371
3912
  type: "number",
4372
3913
  title: "Max Tokens",
@@ -4407,18 +3948,15 @@ class ImageToTextTask extends AiVisionTask {
4407
3948
  var imageToText = (input, config) => {
4408
3949
  return new ImageToTextTask({}, config).run(input);
4409
3950
  };
4410
- Workflow25.prototype.imageToText = CreateWorkflow25(ImageToTextTask);
3951
+ Workflow23.prototype.imageToText = CreateWorkflow23(ImageToTextTask);
4411
3952
 
4412
3953
  // src/task/ModelInfoTask.ts
4413
- import {
4414
- CreateWorkflow as CreateWorkflow26,
4415
- Workflow as Workflow26
4416
- } from "@workglow/task-graph";
4417
- var modelSchema19 = TypeModel("model");
3954
+ import { CreateWorkflow as CreateWorkflow24, Workflow as Workflow24 } from "@workglow/task-graph";
3955
+ var modelSchema17 = TypeModel("model");
4418
3956
  var ModelInfoInputSchema = {
4419
3957
  type: "object",
4420
3958
  properties: {
4421
- model: modelSchema19,
3959
+ model: modelSchema17,
4422
3960
  detail: {
4423
3961
  type: "string",
4424
3962
  enum: ["cached_status", "files", "files_with_metadata"],
@@ -4431,7 +3969,7 @@ var ModelInfoInputSchema = {
4431
3969
  var ModelInfoOutputSchema = {
4432
3970
  type: "object",
4433
3971
  properties: {
4434
- model: modelSchema19,
3972
+ model: modelSchema17,
4435
3973
  is_local: { type: "boolean" },
4436
3974
  is_remote: { type: "boolean" },
4437
3975
  supports_browser: { type: "boolean" },
@@ -4481,10 +4019,10 @@ class ModelInfoTask extends AiTask {
4481
4019
  var modelInfo = (input, config) => {
4482
4020
  return new ModelInfoTask({}, config).run(input);
4483
4021
  };
4484
- Workflow26.prototype.modelInfo = CreateWorkflow26(ModelInfoTask);
4022
+ Workflow24.prototype.modelInfo = CreateWorkflow24(ModelInfoTask);
4485
4023
 
4486
4024
  // src/task/ModelSearchTask.ts
4487
- import { CreateWorkflow as CreateWorkflow27, Task as Task11, Workflow as Workflow27 } from "@workglow/task-graph";
4025
+ import { CreateWorkflow as CreateWorkflow25, Task as Task11, Workflow as Workflow25 } from "@workglow/task-graph";
4488
4026
  var ModelSearchInputSchema = {
4489
4027
  type: "object",
4490
4028
  properties: {
@@ -4575,11 +4113,11 @@ class ModelSearchTask extends Task11 {
4575
4113
  var modelSearch = (input, config) => {
4576
4114
  return new ModelSearchTask({}, config).run(input);
4577
4115
  };
4578
- Workflow27.prototype.modelSearch = CreateWorkflow27(ModelSearchTask);
4116
+ Workflow25.prototype.modelSearch = CreateWorkflow25(ModelSearchTask);
4579
4117
 
4580
4118
  // src/task/ObjectDetectionTask.ts
4581
- import { CreateWorkflow as CreateWorkflow28, Workflow as Workflow28 } from "@workglow/task-graph";
4582
- var modelSchema20 = TypeModel("model:ObjectDetectionTask");
4119
+ import { CreateWorkflow as CreateWorkflow26, Workflow as Workflow26 } from "@workglow/task-graph";
4120
+ var modelSchema18 = TypeModel("model:ObjectDetectionTask");
4583
4121
  var detectionSchema = {
4584
4122
  type: "object",
4585
4123
  properties: {
@@ -4604,7 +4142,7 @@ var ObjectDetectionInputSchema = {
4604
4142
  type: "object",
4605
4143
  properties: {
4606
4144
  image: TypeImageInput,
4607
- model: modelSchema20,
4145
+ model: modelSchema18,
4608
4146
  labels: {
4609
4147
  type: "array",
4610
4148
  items: {
@@ -4658,11 +4196,11 @@ class ObjectDetectionTask extends AiVisionTask {
4658
4196
  var objectDetection = (input, config) => {
4659
4197
  return new ObjectDetectionTask({}, config).run(input);
4660
4198
  };
4661
- Workflow28.prototype.objectDetection = CreateWorkflow28(ObjectDetectionTask);
4199
+ Workflow26.prototype.objectDetection = CreateWorkflow26(ObjectDetectionTask);
4662
4200
 
4663
4201
  // src/task/PoseLandmarkerTask.ts
4664
- import { CreateWorkflow as CreateWorkflow29, Workflow as Workflow29 } from "@workglow/task-graph";
4665
- var modelSchema21 = TypeModel("model:PoseLandmarkerTask");
4202
+ import { CreateWorkflow as CreateWorkflow27, Workflow as Workflow27 } from "@workglow/task-graph";
4203
+ var modelSchema19 = TypeModel("model:PoseLandmarkerTask");
4666
4204
  var TypePoseLandmark = {
4667
4205
  type: "object",
4668
4206
  properties: {
@@ -4741,7 +4279,7 @@ var PoseLandmarkerInputSchema = {
4741
4279
  type: "object",
4742
4280
  properties: {
4743
4281
  image: TypeImageInput,
4744
- model: modelSchema21,
4282
+ model: modelSchema19,
4745
4283
  numPoses: {
4746
4284
  type: "number",
4747
4285
  minimum: 1,
@@ -4820,14 +4358,10 @@ class PoseLandmarkerTask extends AiVisionTask {
4820
4358
  var poseLandmarker = (input, config) => {
4821
4359
  return new PoseLandmarkerTask({}, config).run(input);
4822
4360
  };
4823
- Workflow29.prototype.poseLandmarker = CreateWorkflow29(PoseLandmarkerTask);
4361
+ Workflow27.prototype.poseLandmarker = CreateWorkflow27(PoseLandmarkerTask);
4824
4362
 
4825
4363
  // src/task/QueryExpanderTask.ts
4826
- import {
4827
- CreateWorkflow as CreateWorkflow30,
4828
- Task as Task12,
4829
- Workflow as Workflow30
4830
- } from "@workglow/task-graph";
4364
+ import { CreateWorkflow as CreateWorkflow28, Task as Task12, Workflow as Workflow28 } from "@workglow/task-graph";
4831
4365
  var QueryExpansionMethod = {
4832
4366
  MULTI_QUERY: "multi-query",
4833
4367
  HYDE: "hyde",
@@ -5037,26 +4571,22 @@ class QueryExpanderTask extends Task12 {
5037
4571
  var queryExpander = (input, config) => {
5038
4572
  return new QueryExpanderTask({}, config).run(input);
5039
4573
  };
5040
- Workflow30.prototype.queryExpander = CreateWorkflow30(QueryExpanderTask);
4574
+ Workflow28.prototype.queryExpander = CreateWorkflow28(QueryExpanderTask);
5041
4575
 
5042
4576
  // src/task/RerankerTask.ts
5043
- import {
5044
- CreateWorkflow as CreateWorkflow32,
5045
- Task as Task13,
5046
- Workflow as Workflow32
5047
- } from "@workglow/task-graph";
4577
+ import { CreateWorkflow as CreateWorkflow30, Task as Task13, Workflow as Workflow30 } from "@workglow/task-graph";
5048
4578
 
5049
4579
  // src/task/TextClassificationTask.ts
5050
- import { CreateWorkflow as CreateWorkflow31, Workflow as Workflow31 } from "@workglow/task-graph";
5051
- var modelSchema22 = TypeModel("model:TextClassificationTask");
4580
+ import { CreateWorkflow as CreateWorkflow29, Workflow as Workflow29 } from "@workglow/task-graph";
4581
+ var modelSchema20 = TypeModel("model:TextClassificationTask");
5052
4582
  var TextClassificationInputSchema = {
5053
4583
  type: "object",
5054
4584
  properties: {
5055
- text: TypeSingleOrArray({
4585
+ text: {
5056
4586
  type: "string",
5057
4587
  title: "Text",
5058
4588
  description: "The text to classify"
5059
- }),
4589
+ },
5060
4590
  candidateLabels: {
5061
4591
  type: "array",
5062
4592
  items: {
@@ -5075,7 +4605,7 @@ var TextClassificationInputSchema = {
5075
4605
  description: "The maximum number of categories to return",
5076
4606
  "x-ui-group": "Configuration"
5077
4607
  },
5078
- model: modelSchema22
4608
+ model: modelSchema20
5079
4609
  },
5080
4610
  required: ["text", "model"],
5081
4611
  additionalProperties: false
@@ -5083,7 +4613,7 @@ var TextClassificationInputSchema = {
5083
4613
  var TextClassificationOutputSchema = {
5084
4614
  type: "object",
5085
4615
  properties: {
5086
- categories: TypeSingleOrArray({
4616
+ categories: {
5087
4617
  type: "array",
5088
4618
  items: {
5089
4619
  type: "object",
@@ -5104,7 +4634,7 @@ var TextClassificationOutputSchema = {
5104
4634
  },
5105
4635
  title: "Categories",
5106
4636
  description: "The classification categories with their scores"
5107
- })
4637
+ }
5108
4638
  },
5109
4639
  required: ["categories"],
5110
4640
  additionalProperties: false
@@ -5125,7 +4655,7 @@ class TextClassificationTask extends AiTask {
5125
4655
  var textClassification = (input, config) => {
5126
4656
  return new TextClassificationTask({}, config).run(input);
5127
4657
  };
5128
- Workflow31.prototype.textClassification = CreateWorkflow31(TextClassificationTask);
4658
+ Workflow29.prototype.textClassification = CreateWorkflow29(TextClassificationTask);
5129
4659
 
5130
4660
  // src/task/RerankerTask.ts
5131
4661
  var inputSchema11 = {
@@ -5349,15 +4879,11 @@ class RerankerTask extends Task13 {
5349
4879
  var reranker = (input, config) => {
5350
4880
  return new RerankerTask({}, config).run(input);
5351
4881
  };
5352
- Workflow32.prototype.reranker = CreateWorkflow32(RerankerTask);
4882
+ Workflow30.prototype.reranker = CreateWorkflow30(RerankerTask);
5353
4883
 
5354
4884
  // src/task/StructuralParserTask.ts
5355
4885
  import { StructuralParser } from "@workglow/knowledge-base";
5356
- import {
5357
- CreateWorkflow as CreateWorkflow33,
5358
- Task as Task14,
5359
- Workflow as Workflow33
5360
- } from "@workglow/task-graph";
4886
+ import { CreateWorkflow as CreateWorkflow31, Task as Task14, Workflow as Workflow31 } from "@workglow/task-graph";
5361
4887
  import { uuid4 as uuid42 } from "@workglow/util";
5362
4888
  var inputSchema12 = {
5363
4889
  type: "object",
@@ -5458,15 +4984,15 @@ class StructuralParserTask extends Task14 {
5458
4984
  var structuralParser = (input, config) => {
5459
4985
  return new StructuralParserTask({}, config).run(input);
5460
4986
  };
5461
- Workflow33.prototype.structuralParser = CreateWorkflow33(StructuralParserTask);
4987
+ Workflow31.prototype.structuralParser = CreateWorkflow31(StructuralParserTask);
5462
4988
 
5463
4989
  // src/task/StructuredGenerationTask.ts
5464
- import { CreateWorkflow as CreateWorkflow34, Workflow as Workflow34 } from "@workglow/task-graph";
5465
- var modelSchema23 = TypeModel("model:StructuredGenerationTask");
4990
+ import { CreateWorkflow as CreateWorkflow32, Workflow as Workflow32 } from "@workglow/task-graph";
4991
+ var modelSchema21 = TypeModel("model:StructuredGenerationTask");
5466
4992
  var StructuredGenerationInputSchema = {
5467
4993
  type: "object",
5468
4994
  properties: {
5469
- model: modelSchema23,
4995
+ model: modelSchema21,
5470
4996
  prompt: {
5471
4997
  type: "string",
5472
4998
  title: "Prompt",
@@ -5529,14 +5055,10 @@ class StructuredGenerationTask extends StreamingAiTask {
5529
5055
  var structuredGeneration = (input, config) => {
5530
5056
  return new StructuredGenerationTask({}, config).run(input);
5531
5057
  };
5532
- Workflow34.prototype.structuredGeneration = CreateWorkflow34(StructuredGenerationTask);
5058
+ Workflow32.prototype.structuredGeneration = CreateWorkflow32(StructuredGenerationTask);
5533
5059
 
5534
5060
  // src/task/TextChunkerTask.ts
5535
- import {
5536
- CreateWorkflow as CreateWorkflow35,
5537
- Task as Task15,
5538
- Workflow as Workflow35
5539
- } from "@workglow/task-graph";
5061
+ import { CreateWorkflow as CreateWorkflow33, Task as Task15, Workflow as Workflow33 } from "@workglow/task-graph";
5540
5062
  var ChunkingStrategy = {
5541
5063
  FIXED: "fixed",
5542
5064
  SENTENCE: "sentence",
@@ -5785,20 +5307,20 @@ class TextChunkerTask extends Task15 {
5785
5307
  var textChunker = (input, config) => {
5786
5308
  return new TextChunkerTask({}, config).run(input);
5787
5309
  };
5788
- Workflow35.prototype.textChunker = CreateWorkflow35(TextChunkerTask);
5310
+ Workflow33.prototype.textChunker = CreateWorkflow33(TextChunkerTask);
5789
5311
 
5790
5312
  // src/task/TextFillMaskTask.ts
5791
- import { CreateWorkflow as CreateWorkflow36, Workflow as Workflow36 } from "@workglow/task-graph";
5792
- var modelSchema24 = TypeModel("model:TextFillMaskTask");
5313
+ import { CreateWorkflow as CreateWorkflow34, Workflow as Workflow34 } from "@workglow/task-graph";
5314
+ var modelSchema22 = TypeModel("model:TextFillMaskTask");
5793
5315
  var TextFillMaskInputSchema = {
5794
5316
  type: "object",
5795
5317
  properties: {
5796
- text: TypeSingleOrArray({
5318
+ text: {
5797
5319
  type: "string",
5798
5320
  title: "Text",
5799
5321
  description: "The text with a mask token to fill"
5800
- }),
5801
- model: modelSchema24
5322
+ },
5323
+ model: modelSchema22
5802
5324
  },
5803
5325
  required: ["text", "model"],
5804
5326
  additionalProperties: false
@@ -5806,7 +5328,7 @@ var TextFillMaskInputSchema = {
5806
5328
  var TextFillMaskOutputSchema = {
5807
5329
  type: "object",
5808
5330
  properties: {
5809
- predictions: TypeSingleOrArray({
5331
+ predictions: {
5810
5332
  type: "array",
5811
5333
  items: {
5812
5334
  type: "object",
@@ -5832,7 +5354,7 @@ var TextFillMaskOutputSchema = {
5832
5354
  },
5833
5355
  title: "Predictions",
5834
5356
  description: "The predicted tokens to fill the mask with their scores and complete sequences"
5835
- })
5357
+ }
5836
5358
  },
5837
5359
  required: ["predictions"],
5838
5360
  additionalProperties: false
@@ -5853,26 +5375,26 @@ class TextFillMaskTask extends AiTask {
5853
5375
  var textFillMask = (input, config) => {
5854
5376
  return new TextFillMaskTask({}, config).run(input);
5855
5377
  };
5856
- Workflow36.prototype.textFillMask = CreateWorkflow36(TextFillMaskTask);
5378
+ Workflow34.prototype.textFillMask = CreateWorkflow34(TextFillMaskTask);
5857
5379
 
5858
5380
  // src/task/TextGenerationTask.ts
5859
- import { CreateWorkflow as CreateWorkflow37, Workflow as Workflow37 } from "@workglow/task-graph";
5860
- var generatedTextSchema2 = TypeSingleOrArray({
5381
+ import { CreateWorkflow as CreateWorkflow35, Workflow as Workflow35 } from "@workglow/task-graph";
5382
+ var generatedTextSchema2 = {
5861
5383
  type: "string",
5862
5384
  title: "Text",
5863
5385
  description: "The generated text",
5864
5386
  "x-stream": "append"
5865
- });
5866
- var modelSchema25 = TypeModel("model:TextGenerationTask");
5387
+ };
5388
+ var modelSchema23 = TypeModel("model:TextGenerationTask");
5867
5389
  var TextGenerationInputSchema = {
5868
5390
  type: "object",
5869
5391
  properties: {
5870
- model: modelSchema25,
5871
- prompt: TypeSingleOrArray({
5392
+ model: modelSchema23,
5393
+ prompt: {
5872
5394
  type: "string",
5873
5395
  title: "Prompt",
5874
5396
  description: "The prompt to generate text from"
5875
- }),
5397
+ },
5876
5398
  maxTokens: {
5877
5399
  type: "number",
5878
5400
  title: "Max Tokens",
@@ -5941,19 +5463,19 @@ class TextGenerationTask extends StreamingAiTask {
5941
5463
  var textGeneration = (input, config) => {
5942
5464
  return new TextGenerationTask({}, config).run(input);
5943
5465
  };
5944
- Workflow37.prototype.textGeneration = CreateWorkflow37(TextGenerationTask);
5466
+ Workflow35.prototype.textGeneration = CreateWorkflow35(TextGenerationTask);
5945
5467
 
5946
5468
  // src/task/TextLanguageDetectionTask.ts
5947
- import { CreateWorkflow as CreateWorkflow38, Workflow as Workflow38 } from "@workglow/task-graph";
5948
- var modelSchema26 = TypeModel("model:TextLanguageDetectionTask");
5469
+ import { CreateWorkflow as CreateWorkflow36, Workflow as Workflow36 } from "@workglow/task-graph";
5470
+ var modelSchema24 = TypeModel("model:TextLanguageDetectionTask");
5949
5471
  var TextLanguageDetectionInputSchema = {
5950
5472
  type: "object",
5951
5473
  properties: {
5952
- text: TypeSingleOrArray({
5474
+ text: {
5953
5475
  type: "string",
5954
5476
  title: "Text",
5955
5477
  description: "The text to detect the language of"
5956
- }),
5478
+ },
5957
5479
  maxLanguages: {
5958
5480
  type: "number",
5959
5481
  minimum: 0,
@@ -5962,7 +5484,7 @@ var TextLanguageDetectionInputSchema = {
5962
5484
  title: "Max Languages",
5963
5485
  description: "The maximum number of languages to return"
5964
5486
  },
5965
- model: modelSchema26
5487
+ model: modelSchema24
5966
5488
  },
5967
5489
  required: ["text", "model"],
5968
5490
  additionalProperties: false
@@ -5970,7 +5492,7 @@ var TextLanguageDetectionInputSchema = {
5970
5492
  var TextLanguageDetectionOutputSchema = {
5971
5493
  type: "object",
5972
5494
  properties: {
5973
- languages: TypeSingleOrArray({
5495
+ languages: {
5974
5496
  type: "array",
5975
5497
  items: {
5976
5498
  type: "object",
@@ -5991,7 +5513,7 @@ var TextLanguageDetectionOutputSchema = {
5991
5513
  },
5992
5514
  title: "Languages",
5993
5515
  description: "The languages with their scores"
5994
- })
5516
+ }
5995
5517
  },
5996
5518
  required: ["languages"],
5997
5519
  additionalProperties: false
@@ -6012,33 +5534,33 @@ class TextLanguageDetectionTask extends AiTask {
6012
5534
  var textLanguageDetection = (input, config) => {
6013
5535
  return new TextLanguageDetectionTask({}, config).run(input);
6014
5536
  };
6015
- Workflow38.prototype.textLanguageDetection = CreateWorkflow38(TextLanguageDetectionTask);
5537
+ Workflow36.prototype.textLanguageDetection = CreateWorkflow36(TextLanguageDetectionTask);
6016
5538
 
6017
5539
  // src/task/TextQuestionAnswerTask.ts
6018
- import { CreateWorkflow as CreateWorkflow39, Workflow as Workflow39 } from "@workglow/task-graph";
6019
- var contextSchema = TypeSingleOrArray({
5540
+ import { CreateWorkflow as CreateWorkflow37, Workflow as Workflow37 } from "@workglow/task-graph";
5541
+ var contextSchema = {
6020
5542
  type: "string",
6021
5543
  title: "Context",
6022
5544
  description: "The context of the question"
6023
- });
6024
- var questionSchema = TypeSingleOrArray({
5545
+ };
5546
+ var questionSchema = {
6025
5547
  type: "string",
6026
5548
  title: "Question",
6027
5549
  description: "The question to answer"
6028
- });
6029
- var textSchema = TypeSingleOrArray({
5550
+ };
5551
+ var textSchema = {
6030
5552
  type: "string",
6031
5553
  title: "Text",
6032
5554
  description: "The generated text",
6033
5555
  "x-stream": "append"
6034
- });
6035
- var modelSchema27 = TypeModel("model:TextQuestionAnswerTask");
5556
+ };
5557
+ var modelSchema25 = TypeModel("model:TextQuestionAnswerTask");
6036
5558
  var TextQuestionAnswerInputSchema = {
6037
5559
  type: "object",
6038
5560
  properties: {
6039
5561
  context: contextSchema,
6040
5562
  question: questionSchema,
6041
- model: modelSchema27
5563
+ model: modelSchema25
6042
5564
  },
6043
5565
  required: ["context", "question", "model"],
6044
5566
  additionalProperties: false
@@ -6067,25 +5589,25 @@ class TextQuestionAnswerTask extends StreamingAiTask {
6067
5589
  var textQuestionAnswer = (input, config) => {
6068
5590
  return new TextQuestionAnswerTask({}, config).run(input);
6069
5591
  };
6070
- Workflow39.prototype.textQuestionAnswer = CreateWorkflow39(TextQuestionAnswerTask);
5592
+ Workflow37.prototype.textQuestionAnswer = CreateWorkflow37(TextQuestionAnswerTask);
6071
5593
 
6072
5594
  // src/task/TextRewriterTask.ts
6073
- import { CreateWorkflow as CreateWorkflow40, Workflow as Workflow40 } from "@workglow/task-graph";
6074
- var modelSchema28 = TypeModel("model:TextRewriterTask");
5595
+ import { CreateWorkflow as CreateWorkflow38, Workflow as Workflow38 } from "@workglow/task-graph";
5596
+ var modelSchema26 = TypeModel("model:TextRewriterTask");
6075
5597
  var TextRewriterInputSchema = {
6076
5598
  type: "object",
6077
5599
  properties: {
6078
- text: TypeSingleOrArray({
5600
+ text: {
6079
5601
  type: "string",
6080
5602
  title: "Text",
6081
5603
  description: "The text to rewrite"
6082
- }),
5604
+ },
6083
5605
  prompt: {
6084
5606
  type: "string",
6085
5607
  title: "Prompt",
6086
5608
  description: "The prompt to direct the rewriting"
6087
5609
  },
6088
- model: modelSchema28
5610
+ model: modelSchema26
6089
5611
  },
6090
5612
  required: ["text", "prompt", "model"],
6091
5613
  additionalProperties: false
@@ -6093,12 +5615,12 @@ var TextRewriterInputSchema = {
6093
5615
  var TextRewriterOutputSchema = {
6094
5616
  type: "object",
6095
5617
  properties: {
6096
- text: TypeSingleOrArray({
5618
+ text: {
6097
5619
  type: "string",
6098
5620
  title: "Text",
6099
5621
  description: "The rewritten text",
6100
5622
  "x-stream": "append"
6101
- })
5623
+ }
6102
5624
  },
6103
5625
  required: ["text"],
6104
5626
  additionalProperties: false
@@ -6119,25 +5641,25 @@ class TextRewriterTask extends StreamingAiTask {
6119
5641
  var textRewriter = (input, config) => {
6120
5642
  return new TextRewriterTask({}, config).run(input);
6121
5643
  };
6122
- Workflow40.prototype.textRewriter = CreateWorkflow40(TextRewriterTask);
5644
+ Workflow38.prototype.textRewriter = CreateWorkflow38(TextRewriterTask);
6123
5645
 
6124
5646
  // src/task/TextTranslationTask.ts
6125
- import { CreateWorkflow as CreateWorkflow41, Workflow as Workflow41 } from "@workglow/task-graph";
6126
- var modelSchema29 = TypeModel("model:TextTranslationTask");
6127
- var translationTextSchema = TypeSingleOrArray({
5647
+ import { CreateWorkflow as CreateWorkflow39, Workflow as Workflow39 } from "@workglow/task-graph";
5648
+ var modelSchema27 = TypeModel("model:TextTranslationTask");
5649
+ var translationTextSchema = {
6128
5650
  type: "string",
6129
5651
  title: "Text",
6130
5652
  description: "The translated text",
6131
5653
  "x-stream": "replace"
6132
- });
5654
+ };
6133
5655
  var TextTranslationInputSchema = {
6134
5656
  type: "object",
6135
5657
  properties: {
6136
- text: TypeSingleOrArray({
5658
+ text: {
6137
5659
  type: "string",
6138
5660
  title: "Text",
6139
5661
  description: "The text to translate"
6140
- }),
5662
+ },
6141
5663
  source_lang: TypeLanguage({
6142
5664
  title: "Source Language",
6143
5665
  description: "The source language",
@@ -6150,7 +5672,7 @@ var TextTranslationInputSchema = {
6150
5672
  minLength: 2,
6151
5673
  maxLength: 2
6152
5674
  }),
6153
- model: modelSchema29
5675
+ model: modelSchema27
6154
5676
  },
6155
5677
  required: ["text", "source_lang", "target_lang", "model"],
6156
5678
  additionalProperties: false
@@ -6185,14 +5707,10 @@ class TextTranslationTask extends StreamingAiTask {
6185
5707
  var textTranslation = (input, config) => {
6186
5708
  return new TextTranslationTask({}, config).run(input);
6187
5709
  };
6188
- Workflow41.prototype.textTranslation = CreateWorkflow41(TextTranslationTask);
5710
+ Workflow39.prototype.textTranslation = CreateWorkflow39(TextTranslationTask);
6189
5711
 
6190
5712
  // src/task/TopicSegmenterTask.ts
6191
- import {
6192
- CreateWorkflow as CreateWorkflow42,
6193
- Task as Task16,
6194
- Workflow as Workflow42
6195
- } from "@workglow/task-graph";
5713
+ import { CreateWorkflow as CreateWorkflow40, Task as Task16, Workflow as Workflow40 } from "@workglow/task-graph";
6196
5714
  var SegmentationMethod = {
6197
5715
  HEURISTIC: "heuristic",
6198
5716
  EMBEDDING_SIMILARITY: "embedding-similarity",
@@ -6472,15 +5990,15 @@ class TopicSegmenterTask extends Task16 {
6472
5990
  var topicSegmenter = (input, config) => {
6473
5991
  return new TopicSegmenterTask({}, config).run(input);
6474
5992
  };
6475
- Workflow42.prototype.topicSegmenter = CreateWorkflow42(TopicSegmenterTask);
5993
+ Workflow40.prototype.topicSegmenter = CreateWorkflow40(TopicSegmenterTask);
6476
5994
 
6477
5995
  // src/task/UnloadModelTask.ts
6478
- import { CreateWorkflow as CreateWorkflow43, Workflow as Workflow43 } from "@workglow/task-graph";
6479
- var modelSchema30 = TypeModel("model");
5996
+ import { CreateWorkflow as CreateWorkflow41, Workflow as Workflow41 } from "@workglow/task-graph";
5997
+ var modelSchema28 = TypeModel("model");
6480
5998
  var UnloadModelInputSchema = {
6481
5999
  type: "object",
6482
6000
  properties: {
6483
- model: modelSchema30
6001
+ model: modelSchema28
6484
6002
  },
6485
6003
  required: ["model"],
6486
6004
  additionalProperties: false
@@ -6488,7 +6006,7 @@ var UnloadModelInputSchema = {
6488
6006
  var UnloadModelOutputSchema = {
6489
6007
  type: "object",
6490
6008
  properties: {
6491
- model: modelSchema30
6009
+ model: modelSchema28
6492
6010
  },
6493
6011
  required: ["model"],
6494
6012
  additionalProperties: false
@@ -6510,10 +6028,10 @@ class UnloadModelTask extends AiTask {
6510
6028
  var unloadModel = (input, config) => {
6511
6029
  return new UnloadModelTask({}, config).run(input);
6512
6030
  };
6513
- Workflow43.prototype.unloadModel = CreateWorkflow43(UnloadModelTask);
6031
+ Workflow41.prototype.unloadModel = CreateWorkflow41(UnloadModelTask);
6514
6032
 
6515
6033
  // src/task/VectorQuantizeTask.ts
6516
- import { CreateWorkflow as CreateWorkflow44, Task as Task17, Workflow as Workflow44 } from "@workglow/task-graph";
6034
+ import { CreateWorkflow as CreateWorkflow42, Task as Task17, Workflow as Workflow42 } from "@workglow/task-graph";
6517
6035
  import {
6518
6036
  normalizeNumberArray,
6519
6037
  TensorType,
@@ -6693,10 +6211,10 @@ class VectorQuantizeTask extends Task17 {
6693
6211
  var vectorQuantize = (input, config) => {
6694
6212
  return new VectorQuantizeTask({}, config).run(input);
6695
6213
  };
6696
- Workflow44.prototype.vectorQuantize = CreateWorkflow44(VectorQuantizeTask);
6214
+ Workflow42.prototype.vectorQuantize = CreateWorkflow42(VectorQuantizeTask);
6697
6215
 
6698
6216
  // src/task/VectorSimilarityTask.ts
6699
- import { CreateWorkflow as CreateWorkflow45, GraphAsTask, Workflow as Workflow45 } from "@workglow/task-graph";
6217
+ import { CreateWorkflow as CreateWorkflow43, GraphAsTask, Workflow as Workflow43 } from "@workglow/task-graph";
6700
6218
  import {
6701
6219
  cosineSimilarity,
6702
6220
  hammingSimilarity,
@@ -6802,208 +6320,11 @@ class VectorSimilarityTask extends GraphAsTask {
6802
6320
  var similarity = (input, config) => {
6803
6321
  return new VectorSimilarityTask({}, config).run(input);
6804
6322
  };
6805
- Workflow45.prototype.similarity = CreateWorkflow45(VectorSimilarityTask);
6806
- // src/task/MessageConversion.ts
6807
- function getInputMessages(input) {
6808
- const messages = input.messages;
6809
- if (!messages || messages.length === 0)
6810
- return;
6811
- return messages;
6812
- }
6813
- function toOpenAIMessages(input) {
6814
- const messages = [];
6815
- if (input.systemPrompt) {
6816
- messages.push({ role: "system", content: input.systemPrompt });
6817
- }
6818
- const inputMessages = getInputMessages(input);
6819
- if (!inputMessages) {
6820
- if (!Array.isArray(input.prompt)) {
6821
- messages.push({ role: "user", content: input.prompt });
6822
- } else if (input.prompt.every((item) => typeof item === "string")) {
6823
- messages.push({ role: "user", content: input.prompt.join(`
6824
- `) });
6825
- } else {
6826
- const parts = [];
6827
- for (const item of input.prompt) {
6828
- if (typeof item === "string") {
6829
- parts.push({ type: "text", text: item });
6830
- } else {
6831
- const b = item;
6832
- if (b.type === "text") {
6833
- parts.push({ type: "text", text: b.text });
6834
- } else if (b.type === "image") {
6835
- parts.push({
6836
- type: "image_url",
6837
- image_url: { url: `data:${b.mimeType};base64,${b.data}` }
6838
- });
6839
- } else if (b.type === "audio") {
6840
- const format = b.mimeType.replace(/^audio\//, "");
6841
- parts.push({
6842
- type: "input_audio",
6843
- input_audio: { data: b.data, format }
6844
- });
6845
- }
6846
- }
6847
- }
6848
- messages.push({ role: "user", content: parts });
6849
- }
6850
- return messages;
6851
- }
6852
- for (const msg of inputMessages) {
6853
- if (msg.role === "user") {
6854
- if (typeof msg.content === "string") {
6855
- messages.push({ role: "user", content: msg.content });
6856
- } else if (Array.isArray(msg.content) && msg.content.length > 0 && typeof msg.content[0]?.type === "string") {
6857
- const parts = [];
6858
- for (const block of msg.content) {
6859
- const b = block;
6860
- if (b.type === "text") {
6861
- parts.push({ type: "text", text: b.text });
6862
- } else if (b.type === "image") {
6863
- parts.push({
6864
- type: "image_url",
6865
- image_url: { url: `data:${b.mimeType};base64,${b.data}` }
6866
- });
6867
- } else if (b.type === "audio") {
6868
- const format = b.mimeType.replace(/^audio\//, "");
6869
- parts.push({
6870
- type: "input_audio",
6871
- input_audio: { data: b.data, format }
6872
- });
6873
- }
6874
- }
6875
- messages.push({ role: "user", content: parts });
6876
- } else {
6877
- try {
6878
- messages.push({ role: "user", content: JSON.stringify(msg.content) });
6879
- } catch {
6880
- messages.push({ role: "user", content: String(msg.content) });
6881
- }
6882
- }
6883
- } else if (msg.role === "assistant") {
6884
- if (typeof msg.content === "string") {
6885
- messages.push({ role: "assistant", content: msg.content.length > 0 ? msg.content : null });
6886
- } else if (Array.isArray(msg.content)) {
6887
- const textParts = msg.content.filter((b) => b.type === "text").map((b) => b.text).join("");
6888
- const toolCalls = msg.content.filter((b) => b.type === "tool_use").map((b) => ({
6889
- id: b.id,
6890
- type: "function",
6891
- function: {
6892
- name: b.name,
6893
- arguments: JSON.stringify(b.input)
6894
- }
6895
- }));
6896
- const entry = {
6897
- role: "assistant",
6898
- content: textParts.length > 0 ? textParts : null
6899
- };
6900
- if (toolCalls.length > 0) {
6901
- entry.tool_calls = toolCalls;
6902
- }
6903
- messages.push(entry);
6904
- }
6905
- } else if (msg.role === "tool" && Array.isArray(msg.content)) {
6906
- for (const block of msg.content) {
6907
- const b = block;
6908
- let content;
6909
- if (typeof b.content === "string") {
6910
- content = b.content;
6911
- } else if (Array.isArray(b.content)) {
6912
- const parts = [];
6913
- for (const inner of b.content) {
6914
- if (inner.type === "text") {
6915
- parts.push({ type: "text", text: inner.text });
6916
- } else if (inner.type === "image") {
6917
- parts.push({
6918
- type: "image_url",
6919
- image_url: { url: `data:${inner.mimeType};base64,${inner.data}` }
6920
- });
6921
- }
6922
- }
6923
- content = parts;
6924
- } else {
6925
- content = "";
6926
- }
6927
- messages.push({
6928
- role: "tool",
6929
- content,
6930
- tool_call_id: b.tool_use_id
6931
- });
6932
- }
6933
- }
6934
- }
6935
- return messages;
6936
- }
6937
- function toTextFlatMessages(input) {
6938
- const messages = [];
6939
- if (input.systemPrompt) {
6940
- messages.push({ role: "system", content: input.systemPrompt });
6941
- }
6942
- const inputMessages = getInputMessages(input);
6943
- if (!inputMessages) {
6944
- let promptContent;
6945
- if (!Array.isArray(input.prompt)) {
6946
- promptContent = input.prompt;
6947
- } else {
6948
- promptContent = input.prompt.map((item) => {
6949
- if (typeof item === "string")
6950
- return item;
6951
- const b = item;
6952
- return b.type === "text" ? b.text : "";
6953
- }).filter((s) => s !== "").join(`
6954
- `);
6955
- }
6956
- messages.push({ role: "user", content: promptContent });
6957
- return messages;
6958
- }
6959
- for (const msg of inputMessages) {
6960
- if (msg.role === "user") {
6961
- let content = "";
6962
- if (typeof msg.content === "string") {
6963
- content = msg.content;
6964
- } else if (Array.isArray(msg.content) && msg.content.length > 0 && typeof msg.content[0]?.type === "string") {
6965
- content = msg.content.filter((b) => b.type === "text").map((b) => b.text).join("");
6966
- } else if (msg.content != null) {
6967
- try {
6968
- content = JSON.stringify(msg.content);
6969
- } catch {
6970
- content = String(msg.content);
6971
- }
6972
- }
6973
- messages.push({ role: "user", content });
6974
- } else if (msg.role === "assistant") {
6975
- if (typeof msg.content === "string") {
6976
- if (msg.content) {
6977
- messages.push({ role: "assistant", content: msg.content });
6978
- }
6979
- } else if (Array.isArray(msg.content)) {
6980
- const text = msg.content.filter((b) => b.type === "text").map((b) => b.text).join("");
6981
- if (text) {
6982
- messages.push({ role: "assistant", content: text });
6983
- }
6984
- }
6985
- } else if (msg.role === "tool" && Array.isArray(msg.content)) {
6986
- for (const block of msg.content) {
6987
- const b = block;
6988
- let content;
6989
- if (typeof b.content === "string") {
6990
- content = b.content;
6991
- } else if (Array.isArray(b.content)) {
6992
- content = b.content.filter((inner) => inner.type === "text").map((inner) => inner.text).join("");
6993
- } else {
6994
- content = "";
6995
- }
6996
- messages.push({ role: "tool", content });
6997
- }
6998
- }
6999
- }
7000
- return messages;
7001
- }
6323
+ Workflow43.prototype.similarity = CreateWorkflow43(VectorSimilarityTask);
7002
6324
 
7003
6325
  // src/task/index.ts
7004
6326
  var registerAiTasks = () => {
7005
6327
  const tasks = [
7006
- AgentTask,
7007
6328
  BackgroundRemovalTask,
7008
6329
  ChunkToVectorTask,
7009
6330
  CountTokensTask,
@@ -7043,7 +6364,6 @@ var registerAiTasks = () => {
7043
6364
  TextRewriterTask,
7044
6365
  TextSummaryTask,
7045
6366
  TextTranslationTask,
7046
- ToolCallingTask,
7047
6367
  TopicSegmenterTask,
7048
6368
  UnloadModelTask,
7049
6369
  VectorQuantizeTask,
@@ -7055,14 +6375,8 @@ var registerAiTasks = () => {
7055
6375
  export {
7056
6376
  vectorStoreSearch,
7057
6377
  vectorQuantize,
7058
- userMessage,
7059
6378
  unloadModel,
7060
6379
  topicSegmenter,
7061
- toolSourceDefinitions,
7062
- toolMessage,
7063
- toolCalling,
7064
- toTextFlatMessages,
7065
- toOpenAIMessages,
7066
6380
  textTranslation,
7067
6381
  textSummary,
7068
6382
  textRewriter,
@@ -7074,12 +6388,12 @@ export {
7074
6388
  textEmbedding,
7075
6389
  textClassification,
7076
6390
  textChunker,
7077
- taskTypesToTools,
7078
6391
  structuredGeneration,
7079
6392
  structuralParser,
7080
6393
  similarity,
7081
6394
  setGlobalModelRepository,
7082
6395
  setAiProviderRegistry,
6396
+ resolveAiProviderGpuQueueConcurrency,
7083
6397
  reranker,
7084
6398
  registerAiTasks,
7085
6399
  queryExpander,
@@ -7087,27 +6401,19 @@ export {
7087
6401
  objectDetection,
7088
6402
  modelSearch,
7089
6403
  modelInfo,
7090
- isAllowedToolName,
7091
6404
  imageToText,
7092
6405
  imageSegmentation,
7093
6406
  imageEmbedding,
7094
6407
  imageClassification,
7095
- imageBlockFromDataUri,
7096
- imageBlock,
7097
6408
  hybridSearch,
7098
6409
  hierarchyJoin,
7099
6410
  hierarchicalChunker,
7100
- hasToolCalls,
7101
6411
  handLandmarker,
7102
6412
  getGlobalModelRepository,
7103
6413
  getAiProviderRegistry,
7104
6414
  gestureRecognizer,
7105
- findToolSource,
7106
- filterValidToolCalls,
7107
6415
  faceLandmarker,
7108
6416
  faceDetector,
7109
- executeToolCalls,
7110
- executeToolCall,
7111
6417
  downloadModel,
7112
6418
  documentEnricher,
7113
6419
  countTokens,
@@ -7115,13 +6421,7 @@ export {
7115
6421
  chunkVectorUpsert,
7116
6422
  chunkToVector,
7117
6423
  chunkRetrieval,
7118
- buildToolSources,
7119
- buildToolDescription,
7120
6424
  backgroundRemoval,
7121
- audioBlockFromDataUri,
7122
- audioBlock,
7123
- assistantMessage,
7124
- agent,
7125
6425
  VectorSimilarityTask,
7126
6426
  VectorQuantizeTask,
7127
6427
  UnloadModelTask,
@@ -7135,10 +6435,6 @@ export {
7135
6435
  TypeBoundingBox,
7136
6436
  TypeAudioInput,
7137
6437
  TopicSegmenterTask,
7138
- ToolDefinitionSchema,
7139
- ToolCallingTask,
7140
- ToolCallingOutputSchema,
7141
- ToolCallingInputSchema,
7142
6438
  TextTranslationTask,
7143
6439
  TextTranslationOutputSchema,
7144
6440
  TextTranslationInputSchema,
@@ -7178,6 +6474,7 @@ export {
7178
6474
  SimilarityFn,
7179
6475
  SegmentationMethod,
7180
6476
  RerankerTask,
6477
+ QueuedExecutionStrategy,
7181
6478
  QueuedAiProvider,
7182
6479
  QueryExpansionMethod,
7183
6480
  QueryExpanderTask,
@@ -7223,6 +6520,7 @@ export {
7223
6520
  FaceDetectorInputSchema,
7224
6521
  DownloadModelTask,
7225
6522
  DocumentEnricherTask,
6523
+ DirectExecutionStrategy,
7226
6524
  CountTokensTask,
7227
6525
  CountTokensOutputSchema,
7228
6526
  CountTokensInputSchema,
@@ -7240,10 +6538,7 @@ export {
7240
6538
  AiTask,
7241
6539
  AiProviderRegistry,
7242
6540
  AiProvider,
7243
- AiJob,
7244
- AgentTask,
7245
- AgentOutputSchema,
7246
- AgentInputSchema
6541
+ AiJob
7247
6542
  };
7248
6543
 
7249
- //# debugId=18D97536243F610A64756E2164756E21
6544
+ //# debugId=833980E5CCD244A264756E2164756E21