@workglow/ai 0.0.126 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/README.md +214 -47
  2. package/dist/browser.js +562 -1274
  3. package/dist/browser.js.map +55 -60
  4. package/dist/bun.js +562 -1274
  5. package/dist/bun.js.map +55 -60
  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 +562 -1274
  17. package/dist/node.js.map +55 -60
  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/ObjectDetectionTask.d.ts +4 -4
  67. package/dist/task/ObjectDetectionTask.d.ts.map +1 -1
  68. package/dist/task/PoseLandmarkerTask.d.ts +4 -4
  69. package/dist/task/PoseLandmarkerTask.d.ts.map +1 -1
  70. package/dist/task/QueryExpanderTask.d.ts +4 -4
  71. package/dist/task/QueryExpanderTask.d.ts.map +1 -1
  72. package/dist/task/RerankerTask.d.ts +4 -4
  73. package/dist/task/RerankerTask.d.ts.map +1 -1
  74. package/dist/task/StructuralParserTask.d.ts +4 -4
  75. package/dist/task/StructuralParserTask.d.ts.map +1 -1
  76. package/dist/task/StructuredGenerationTask.d.ts +4 -4
  77. package/dist/task/StructuredGenerationTask.d.ts.map +1 -1
  78. package/dist/task/TextChunkerTask.d.ts +4 -4
  79. package/dist/task/TextChunkerTask.d.ts.map +1 -1
  80. package/dist/task/TextClassificationTask.d.ts +24 -62
  81. package/dist/task/TextClassificationTask.d.ts.map +1 -1
  82. package/dist/task/TextEmbeddingTask.d.ts +3 -3
  83. package/dist/task/TextEmbeddingTask.d.ts.map +1 -1
  84. package/dist/task/TextFillMaskTask.d.ts +29 -73
  85. package/dist/task/TextFillMaskTask.d.ts.map +1 -1
  86. package/dist/task/TextGenerationTask.d.ts +13 -32
  87. package/dist/task/TextGenerationTask.d.ts.map +1 -1
  88. package/dist/task/TextLanguageDetectionTask.d.ts +24 -62
  89. package/dist/task/TextLanguageDetectionTask.d.ts.map +1 -1
  90. package/dist/task/TextNamedEntityRecognitionTask.d.ts +29 -73
  91. package/dist/task/TextNamedEntityRecognitionTask.d.ts.map +1 -1
  92. package/dist/task/TextQuestionAnswerTask.d.ts +17 -45
  93. package/dist/task/TextQuestionAnswerTask.d.ts.map +1 -1
  94. package/dist/task/TextRewriterTask.d.ts +12 -31
  95. package/dist/task/TextRewriterTask.d.ts.map +1 -1
  96. package/dist/task/TextSummaryTask.d.ts +12 -31
  97. package/dist/task/TextSummaryTask.d.ts.map +1 -1
  98. package/dist/task/TextTranslationTask.d.ts +12 -31
  99. package/dist/task/TextTranslationTask.d.ts.map +1 -1
  100. package/dist/task/TopicSegmenterTask.d.ts +4 -4
  101. package/dist/task/TopicSegmenterTask.d.ts.map +1 -1
  102. package/dist/task/UnloadModelTask.d.ts +4 -4
  103. package/dist/task/UnloadModelTask.d.ts.map +1 -1
  104. package/dist/task/VectorQuantizeTask.d.ts +4 -4
  105. package/dist/task/VectorQuantizeTask.d.ts.map +1 -1
  106. package/dist/task/VectorSimilarityTask.d.ts +4 -4
  107. package/dist/task/VectorSimilarityTask.d.ts.map +1 -1
  108. package/dist/task/base/AiTask.d.ts +12 -31
  109. package/dist/task/base/AiTask.d.ts.map +1 -1
  110. package/dist/task/base/AiVisionTask.d.ts +7 -12
  111. package/dist/task/base/AiVisionTask.d.ts.map +1 -1
  112. package/dist/task/base/StreamingAiTask.d.ts +7 -4
  113. package/dist/task/base/StreamingAiTask.d.ts.map +1 -1
  114. package/dist/task/index.d.ts +1 -13
  115. package/dist/task/index.d.ts.map +1 -1
  116. package/dist/worker.d.ts +0 -2
  117. package/dist/worker.d.ts.map +1 -1
  118. package/dist/worker.js +217 -233
  119. package/dist/worker.js.map +7 -7
  120. package/package.json +11 -11
  121. package/dist/queue/createDefaultQueue.d.ts +0 -17
  122. package/dist/queue/createDefaultQueue.d.ts.map +0 -1
  123. package/dist/task/AgentTask.d.ts +0 -524
  124. package/dist/task/AgentTask.d.ts.map +0 -1
  125. package/dist/task/AgentTypes.d.ts +0 -181
  126. package/dist/task/AgentTypes.d.ts.map +0 -1
  127. package/dist/task/AgentUtils.d.ts +0 -50
  128. package/dist/task/AgentUtils.d.ts.map +0 -1
  129. package/dist/task/MessageConversion.d.ts +0 -52
  130. package/dist/task/MessageConversion.d.ts.map +0 -1
  131. package/dist/task/ToolCallingTask.d.ts +0 -385
  132. package/dist/task/ToolCallingTask.d.ts.map +0 -1
  133. package/dist/task/ToolCallingUtils.d.ts +0 -65
  134. 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,61 @@ function setAiProviderRegistry(pr) {
108
137
  }
109
138
 
110
139
  // src/job/AiJob.ts
140
+ var DEFAULT_AI_TIMEOUT_MS = 120000;
141
+ var LOCAL_LLAMACPP_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_LLAMACPP_DEFAULT_TIMEOUT_MS;
148
+ }
149
+ return DEFAULT_AI_TIMEOUT_MS;
150
+ }
151
+ function classifyProviderError(err, taskType, provider) {
152
+ if (err instanceof PermanentJobError || err instanceof RetryableJobError || err instanceof AbortSignalJobError) {
153
+ return err;
154
+ }
155
+ const message = err instanceof Error ? err.message : String(err);
156
+ const status = typeof err?.status === "number" ? err.status : typeof err?.statusCode === "number" ? err.statusCode : (() => {
157
+ const m = message.match(/\b([45]\d{2})\b/);
158
+ return m ? parseInt(m[1], 10) : undefined;
159
+ })();
160
+ if (err instanceof DOMException && err.name === "AbortError") {
161
+ return new AbortSignalJobError(`Provider call aborted for ${taskType} (${provider})`);
162
+ }
163
+ if (err instanceof DOMException && err.name === "TimeoutError") {
164
+ return new AbortSignalJobError(`Provider call timed out for ${taskType} (${provider})`);
165
+ }
166
+ if (message.includes("Pipeline download aborted") || message.includes("Operation aborted") || message.includes("operation was aborted") || message.includes("The operation was aborted")) {
167
+ return new AbortSignalJobError(`Provider call aborted for ${taskType} (${provider}): ${message}`);
168
+ }
169
+ if (message.startsWith("HFT_NULL_PROCESSOR:")) {
170
+ return new RetryableJobError(message);
171
+ }
172
+ if (status === 429) {
173
+ const retryAfterMatch = message.match(/retry.after[:\s]*(\d+)/i);
174
+ const retryMs = retryAfterMatch ? parseInt(retryAfterMatch[1], 10) * 1000 : 30000;
175
+ return new RetryableJobError(`Rate limited by ${provider} for ${taskType}: ${message}`, new Date(Date.now() + retryMs));
176
+ }
177
+ if (status === 401 || status === 403) {
178
+ return new PermanentJobError(`Authentication failed for ${provider} (${taskType}): ${message}`);
179
+ }
180
+ if (status === 400 || status === 404) {
181
+ return new PermanentJobError(`Invalid request to ${provider} for ${taskType}: ${message}`);
182
+ }
183
+ if (status && status >= 500) {
184
+ return new RetryableJobError(`Server error from ${provider} for ${taskType} (HTTP ${status}): ${message}`);
185
+ }
186
+ if (message.includes("ECONNREFUSED") || message.includes("ECONNRESET") || message.includes("ETIMEDOUT") || message.includes("fetch failed") || message.includes("network") || err instanceof TypeError && message.includes("fetch")) {
187
+ return new RetryableJobError(`Network error calling ${provider} for ${taskType}: ${message}`);
188
+ }
189
+ if (message.includes("timed out") || message.includes("timeout")) {
190
+ return new RetryableJobError(`Timeout calling ${provider} for ${taskType}: ${message}`);
191
+ }
192
+ return new PermanentJobError(`Provider ${provider} failed for ${taskType}: ${message}`);
193
+ }
194
+
111
195
  class AiJob extends Job {
112
196
  async execute(input, context) {
113
197
  if (context.signal.aborted || this.status === JobStatus.ABORTING) {
@@ -124,17 +208,19 @@ class AiJob extends Job {
124
208
  });
125
209
  const runFn = async () => {
126
210
  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
211
  const model = input.taskInput.model;
131
- if (context.signal?.aborted) {
212
+ if (context.signal.aborted) {
132
213
  throw new AbortSignalJobError("Job aborted");
133
214
  }
134
- return await fn(input.taskInput, model, context.updateProgress, context.signal, input.outputSchema);
215
+ const timeoutMs = resolveAiJobTimeoutMs(input.aiProvider, input.timeoutMs);
216
+ const timeoutSignal = AbortSignal.timeout(timeoutMs);
217
+ const combinedSignal = AbortSignal.any([context.signal, timeoutSignal]);
218
+ return await fn(input.taskInput, model, context.updateProgress, combinedSignal, input.outputSchema);
135
219
  };
136
220
  const runFnPromise = runFn();
137
221
  return await Promise.race([runFnPromise, abortPromise]);
222
+ } catch (err) {
223
+ throw classifyProviderError(err, input.taskType, input.aiProvider);
138
224
  } finally {
139
225
  if (abortHandler) {
140
226
  abortHandler();
@@ -152,35 +238,172 @@ class AiJob extends Job {
152
238
  return;
153
239
  }
154
240
  const model = input.taskInput.model;
155
- yield* streamFn(input.taskInput, model, context.signal, input.outputSchema);
241
+ let lastFinishData;
242
+ const timeoutMs = resolveAiJobTimeoutMs(input.aiProvider, input.timeoutMs);
243
+ const timeoutSignal = AbortSignal.timeout(timeoutMs);
244
+ const combinedSignal = AbortSignal.any([context.signal, timeoutSignal]);
245
+ try {
246
+ for await (const event of streamFn(input.taskInput, model, combinedSignal, input.outputSchema)) {
247
+ if (event.type === "finish") {
248
+ lastFinishData = event.data;
249
+ }
250
+ yield event;
251
+ }
252
+ } catch (err) {
253
+ const logger = getLogger();
254
+ logger.warn(`AiJob: Stream error for ${input.taskType} (${input.aiProvider}): ${err instanceof Error ? err.message : String(err)}`);
255
+ if (lastFinishData === undefined) {
256
+ yield { type: "finish", data: {} };
257
+ }
258
+ throw classifyProviderError(err, input.taskType, input.aiProvider);
259
+ }
156
260
  }
157
261
  }
158
262
 
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)}`;
263
+ // src/execution/DirectExecutionStrategy.ts
264
+ class DirectExecutionStrategy {
265
+ async execute(jobInput, context, runnerId) {
266
+ const job = new AiJob({
267
+ queueName: jobInput.aiProvider,
268
+ jobRunId: runnerId,
269
+ input: jobInput
270
+ });
271
+ const cleanup = job.onJobProgress((progress, message, details) => {
272
+ context.updateProgress(progress, message, details);
273
+ });
274
+ try {
275
+ return await job.execute(jobInput, {
276
+ signal: context.signal,
277
+ updateProgress: context.updateProgress
278
+ });
279
+ } finally {
280
+ cleanup();
281
+ }
167
282
  }
168
- return desc;
169
- }
170
- function isAllowedToolName(name, allowedTools) {
171
- return allowedTools.some((t) => t.name === name);
283
+ async* executeStream(jobInput, context, runnerId) {
284
+ const job = new AiJob({
285
+ queueName: jobInput.aiProvider,
286
+ jobRunId: runnerId,
287
+ input: jobInput
288
+ });
289
+ yield* job.executeStream(jobInput, {
290
+ signal: context.signal,
291
+ updateProgress: context.updateProgress
292
+ });
293
+ }
294
+ abort() {}
172
295
  }
173
- function filterValidToolCalls(toolCalls, allowedTools) {
174
- return toolCalls.filter((tc) => {
175
- if (tc.name && isAllowedToolName(tc.name, allowedTools)) {
176
- return true;
296
+
297
+ // src/execution/QueuedExecutionStrategy.ts
298
+ import { ConcurrencyLimiter, JobQueueClient, JobQueueServer } from "@workglow/job-queue";
299
+ import { InMemoryQueueStorage } from "@workglow/storage";
300
+ import {
301
+ getTaskQueueRegistry,
302
+ TaskConfigurationError
303
+ } from "@workglow/task-graph";
304
+ class QueuedExecutionStrategy {
305
+ queueName;
306
+ concurrency;
307
+ autoCreate;
308
+ initPromise = null;
309
+ constructor(queueName, concurrency = 1, autoCreate = true) {
310
+ this.queueName = queueName;
311
+ this.concurrency = concurrency;
312
+ this.autoCreate = autoCreate;
313
+ }
314
+ async execute(jobInput, context, runnerId) {
315
+ if (context.signal.aborted) {
316
+ throw context.signal.reason ?? new DOMException("The operation was aborted", "AbortError");
317
+ }
318
+ const registeredQueue = await this.ensureQueue();
319
+ const { client } = registeredQueue;
320
+ const handle = await client.submit(jobInput, {
321
+ jobRunId: runnerId,
322
+ maxRetries: 10
323
+ });
324
+ const onAbort = () => {
325
+ handle.abort().catch((err) => {
326
+ console.warn(`Failed to abort queued job`, err);
327
+ });
328
+ };
329
+ context.signal.addEventListener("abort", onAbort);
330
+ const cleanupProgress = handle.onProgress((progress, message, details) => {
331
+ context.updateProgress(progress, message, details);
332
+ });
333
+ try {
334
+ if (context.signal.aborted) {
335
+ throw context.signal.reason ?? new DOMException("The operation was aborted", "AbortError");
336
+ }
337
+ const output = await handle.waitFor();
338
+ return output;
339
+ } finally {
340
+ cleanupProgress();
341
+ context.signal.removeEventListener("abort", onAbort);
177
342
  }
178
- getLogger().warn(`Filtered out tool call with unknown name "${tc.name ?? "(missing)"}"`, {
179
- callId: tc.id,
180
- toolName: tc.name
343
+ }
344
+ abort() {}
345
+ async* executeStream(jobInput, context, runnerId) {
346
+ const result = await this.execute(jobInput, context, runnerId);
347
+ yield { type: "finish", data: result };
348
+ }
349
+ ensureQueue() {
350
+ if (!this.initPromise) {
351
+ this.initPromise = this.createQueue().catch((err) => {
352
+ this.initPromise = null;
353
+ throw err;
354
+ });
355
+ }
356
+ return this.initPromise;
357
+ }
358
+ async createQueue() {
359
+ const registry = getTaskQueueRegistry();
360
+ const existing = registry.getQueue(this.queueName);
361
+ if (existing) {
362
+ if (!existing.server.isRunning()) {
363
+ await existing.server.start();
364
+ }
365
+ return existing;
366
+ }
367
+ if (!this.autoCreate) {
368
+ throw new TaskConfigurationError(`Queue "${this.queueName}" is not registered and autoCreate is disabled. ` + `Register the queue before executing tasks with this provider.`);
369
+ }
370
+ const storage = new InMemoryQueueStorage(this.queueName);
371
+ await storage.setupDatabase();
372
+ const server = new JobQueueServer(AiJob, {
373
+ storage,
374
+ queueName: this.queueName,
375
+ limiter: new ConcurrencyLimiter(this.concurrency)
376
+ });
377
+ const client = new JobQueueClient({
378
+ storage,
379
+ queueName: this.queueName
181
380
  });
182
- return false;
183
- });
381
+ client.attach(server);
382
+ const registeredQueue = {
383
+ server,
384
+ client,
385
+ storage
386
+ };
387
+ try {
388
+ registry.registerQueue(registeredQueue);
389
+ } catch (err) {
390
+ if (err instanceof Error && err.message.includes("already exists")) {
391
+ server.stop().catch((stopErr) => {
392
+ console.warn("QueuedExecutionStrategy: failed to stop raced-out queue server", stopErr);
393
+ });
394
+ const raced = registry.getQueue(this.queueName);
395
+ if (raced) {
396
+ if (!raced.server.isRunning()) {
397
+ await raced.server.start();
398
+ }
399
+ return raced;
400
+ }
401
+ }
402
+ throw err;
403
+ }
404
+ await server.start();
405
+ return registeredQueue;
406
+ }
184
407
  }
185
408
 
186
409
  // src/model/InMemoryModelRepository.ts
@@ -353,6 +576,16 @@ import {
353
576
  globalServiceRegistry as globalServiceRegistry3,
354
577
  WORKER_MANAGER as WORKER_MANAGER2
355
578
  } from "@workglow/util/worker";
579
+ function resolveAiProviderGpuQueueConcurrency(concurrency) {
580
+ if (concurrency === undefined) {
581
+ return 1;
582
+ }
583
+ if (typeof concurrency === "number") {
584
+ return concurrency;
585
+ }
586
+ return concurrency.gpu ?? 1;
587
+ }
588
+
356
589
  class AiProvider {
357
590
  tasks;
358
591
  streamTasks;
@@ -412,7 +645,12 @@ class AiProvider {
412
645
  }
413
646
  }
414
647
  registry.registerProvider(this);
415
- await this.afterRegister(options);
648
+ try {
649
+ await this.afterRegister(options);
650
+ } catch (err) {
651
+ registry.unregisterProvider(this.name);
652
+ throw err;
653
+ }
416
654
  }
417
655
  registerOnWorkerServer(workerServer) {
418
656
  if (!this.tasks) {
@@ -437,115 +675,28 @@ class AiProvider {
437
675
  async afterRegister(_options) {}
438
676
  }
439
677
 
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
678
  // src/provider/QueuedAiProvider.ts
462
679
  class QueuedAiProvider extends AiProvider {
680
+ queuedStrategy;
463
681
  async afterRegister(options) {
464
- if (options.queue?.autoCreate !== false) {
465
- await createDefaultQueue(this.name, options.queue?.concurrency ?? 1);
466
- }
682
+ const autoCreate = options.queue?.autoCreate !== false;
683
+ this.queuedStrategy = new QueuedExecutionStrategy(`${this.name}_gpu`, resolveAiProviderGpuQueueConcurrency(options.queue?.concurrency), autoCreate);
684
+ getAiProviderRegistry().registerStrategyResolver(this.name, (model) => this.getStrategyForModel(model));
685
+ }
686
+ createQueuedStrategy(queueName, concurrency, options) {
687
+ const autoCreate = options.queue?.autoCreate !== false;
688
+ return new QueuedExecutionStrategy(queueName, concurrency, autoCreate);
689
+ }
690
+ getStrategyForModel(_model) {
691
+ return this.queuedStrategy;
467
692
  }
468
693
  }
469
694
 
470
695
  // src/task/index.ts
471
696
  import { TaskRegistry } from "@workglow/task-graph";
472
697
 
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";
698
+ // src/task/BackgroundRemovalTask.ts
699
+ import { CreateWorkflow, Workflow } from "@workglow/task-graph";
549
700
 
550
701
  // src/task/base/AiTaskSchemas.ts
551
702
  var TypeLanguage = (annotations = {}) => ({
@@ -704,32 +855,44 @@ var TypeCategory = {
704
855
  description: "Classification category with label and score"
705
856
  };
706
857
 
707
- // src/task/base/StreamingAiTask.ts
708
- import {
709
- getStreamingPorts
710
- } from "@workglow/task-graph";
858
+ // src/task/base/AiVisionTask.ts
859
+ import { convertImageDataToUseableForm } from "@workglow/util/media";
711
860
 
712
861
  // src/task/base/AiTask.ts
713
862
  import {
714
- JobQueueTask,
715
- TaskConfigurationError,
863
+ Task,
864
+ TaskConfigSchema,
865
+ TaskConfigurationError as TaskConfigurationError2,
716
866
  hasStructuredOutput
717
867
  } from "@workglow/task-graph";
718
868
  function schemaFormat(schema) {
719
869
  return typeof schema === "object" && schema !== null && "format" in schema ? schema.format : undefined;
720
870
  }
871
+ var aiTaskConfigSchema = {
872
+ type: "object",
873
+ properties: {
874
+ ...TaskConfigSchema["properties"]
875
+ },
876
+ additionalProperties: false
877
+ };
721
878
 
722
- class AiTask extends JobQueueTask {
879
+ class AiTask extends Task {
723
880
  static type = "AiTask";
724
- constructor(input = {}, config = {}) {
725
- super(input, config);
726
- this.jobClass = AiJob;
881
+ static configSchema() {
882
+ return aiTaskConfigSchema;
727
883
  }
728
- async getJobInput(input) {
884
+ async execute(input, executeContext) {
729
885
  const model = input.model;
730
886
  if (!model || typeof model !== "object") {
731
- throw new TaskConfigurationError("AiTask: Model was not resolved to ModelConfig - this indicates a bug in the resolution system");
887
+ throw new TaskConfigurationError2("AiTask: Model was not resolved to ModelConfig - this indicates a bug in the resolution system");
732
888
  }
889
+ const jobInput = await this.getJobInput(input);
890
+ const strategy = getAiProviderRegistry().getStrategy(model);
891
+ const output = await strategy.execute(jobInput, executeContext, this.runConfig.runnerId);
892
+ return output;
893
+ }
894
+ async getJobInput(input) {
895
+ const model = input.model;
733
896
  const runtype = this.constructor.runtype ?? this.constructor.type;
734
897
  const jobInput = {
735
898
  taskType: runtype,
@@ -737,7 +900,7 @@ class AiTask extends JobQueueTask {
737
900
  taskInput: input
738
901
  };
739
902
  const inputOutputSchema = input.outputSchema;
740
- if (inputOutputSchema && typeof inputOutputSchema === "object") {
903
+ if (inputOutputSchema && typeof inputOutputSchema === "object" && !Array.isArray(inputOutputSchema) && typeof inputOutputSchema.type === "string") {
741
904
  jobInput.outputSchema = inputOutputSchema;
742
905
  } else {
743
906
  const taskOutputSchema = this.outputSchema();
@@ -751,7 +914,7 @@ class AiTask extends JobQueueTask {
751
914
  const jobInput = await this.getJobInput(input);
752
915
  const resolvedQueueName = queueName ?? await this.getDefaultQueueName(input);
753
916
  if (!resolvedQueueName) {
754
- throw new TaskConfigurationError("JobQueueTask: Unable to determine queue for AI provider");
917
+ throw new TaskConfigurationError2("AiTask: Unable to determine queue for AI provider");
755
918
  }
756
919
  const job = new AiJob({
757
920
  queueName: resolvedQueueName,
@@ -779,7 +942,7 @@ class AiTask extends JobQueueTask {
779
942
  const inputSchema = this.inputSchema();
780
943
  if (typeof inputSchema === "boolean") {
781
944
  if (inputSchema === false) {
782
- throw new TaskConfigurationError(`AiTask: Input schema is 'false' and accepts no inputs`);
945
+ throw new TaskConfigurationError2(`AiTask: Input schema is 'false' and accepts no inputs`);
783
946
  }
784
947
  return true;
785
948
  }
@@ -789,17 +952,18 @@ class AiTask extends JobQueueTask {
789
952
  if (typeof model === "object" && model !== null) {
790
953
  const tasks = model.tasks;
791
954
  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}'`);
955
+ const modelId = model.model_id ?? "(inline config)";
956
+ throw new TaskConfigurationError2(`AiTask: Model "${modelId}" for '${key}' is not compatible with task '${this.type}'. ` + `Model supports: [${tasks.join(", ")}]`);
793
957
  }
794
958
  } else if (model !== undefined && model !== null) {
795
- throw new TaskConfigurationError(`AiTask: Invalid model for '${key}' - expected ModelConfig object`);
959
+ 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
960
  }
797
961
  }
798
962
  const modelPlainProperties = Object.entries(inputSchema.properties || {}).filter(([key, schema]) => schemaFormat(schema) === "model");
799
963
  for (const [key] of modelPlainProperties) {
800
964
  const model = input[key];
801
965
  if (model !== undefined && model !== null && typeof model !== "object") {
802
- 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.`);
803
967
  }
804
968
  }
805
969
  return super.validateInput(input);
@@ -808,14 +972,14 @@ class AiTask extends JobQueueTask {
808
972
  const inputSchema = this.inputSchema();
809
973
  if (typeof inputSchema === "boolean") {
810
974
  if (inputSchema === false) {
811
- throw new TaskConfigurationError(`AiTask: Input schema is 'false' and accepts no inputs`);
975
+ throw new TaskConfigurationError2(`AiTask: Input schema is 'false' and accepts no inputs`);
812
976
  }
813
977
  return input;
814
978
  }
815
979
  const modelTaskProperties = Object.entries(inputSchema.properties || {}).filter(([key, schema]) => schemaFormat(schema)?.startsWith("model:"));
816
980
  if (modelTaskProperties.length > 0) {
817
981
  const modelRepo = registry.get(MODEL_REPOSITORY);
818
- const taskModels = await modelRepo.findModelsByTask(this.type);
982
+ const taskModels = await modelRepo.findModelsByTask(this.type) ?? [];
819
983
  for (const [key, propSchema] of modelTaskProperties) {
820
984
  const requestedModel = input[key];
821
985
  if (typeof requestedModel === "string") {
@@ -827,666 +991,29 @@ class AiTask extends JobQueueTask {
827
991
  const model = requestedModel;
828
992
  const tasks = model.tasks;
829
993
  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;
994
+ input[key] = undefined;
995
+ }
1419
996
  }
1420
997
  }
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
998
  }
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)];
999
+ return input;
1464
1000
  }
1465
1001
  }
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
1002
 
1474
1003
  // src/task/base/AiVisionTask.ts
1475
- import { convertImageDataToUseableForm } from "@workglow/util/media";
1476
1004
  class AiVisionTask extends AiTask {
1477
1005
  static type = "AiVisionTask";
1478
1006
  async getJobInput(input) {
1479
1007
  const jobInput = await super.getJobInput(input);
1480
- const registeredQueue = await this.resolveQueue(input);
1481
- const queueName = registeredQueue?.server.queueName;
1008
+ const providerName = input.model.provider;
1482
1009
  const supports = ["Blob"];
1483
1010
  if (input.image) {
1484
- if (typeof queueName === "string" && queueName.startsWith("TENSORFLOW_MEDIAPIPE") && "ImageBitmap" in globalThis) {
1011
+ if (typeof providerName === "string" && providerName.startsWith("TENSORFLOW_MEDIAPIPE") && "ImageBitmap" in globalThis) {
1485
1012
  supports.push("ImageBitmap");
1486
- } else if (typeof queueName === "string" && queueName.startsWith("TENSORFLOW_MEDIAPIPE") && "VideoFrame" in globalThis) {
1013
+ } else if (typeof providerName === "string" && providerName.startsWith("TENSORFLOW_MEDIAPIPE") && "VideoFrame" in globalThis) {
1487
1014
  supports.push("VideoFrame");
1488
1015
  }
1489
- const image = await convertImageDataToUseableForm(input.image, supports);
1016
+ const image = Array.isArray(input.image) ? await Promise.all(input.image.map((img) => convertImageDataToUseableForm(img, supports))) : await convertImageDataToUseableForm(input.image, supports);
1490
1017
  jobInput.taskInput.image = image;
1491
1018
  }
1492
1019
  return jobInput;
@@ -1494,7 +1021,7 @@ class AiVisionTask extends AiTask {
1494
1021
  }
1495
1022
 
1496
1023
  // src/task/BackgroundRemovalTask.ts
1497
- var modelSchema3 = TypeModel("model:BackgroundRemovalTask");
1024
+ var modelSchema = TypeModel("model:BackgroundRemovalTask");
1498
1025
  var processedImageSchema = {
1499
1026
  type: "string",
1500
1027
  contentEncoding: "base64",
@@ -1506,7 +1033,7 @@ var BackgroundRemovalInputSchema = {
1506
1033
  type: "object",
1507
1034
  properties: {
1508
1035
  image: TypeImageInput,
1509
- model: modelSchema3
1036
+ model: modelSchema
1510
1037
  },
1511
1038
  required: ["image", "model"],
1512
1039
  additionalProperties: false
@@ -1535,26 +1062,22 @@ class BackgroundRemovalTask extends AiVisionTask {
1535
1062
  var backgroundRemoval = (input, config) => {
1536
1063
  return new BackgroundRemovalTask({}, config).run(input);
1537
1064
  };
1538
- Workflow3.prototype.backgroundRemoval = CreateWorkflow3(BackgroundRemovalTask);
1065
+ Workflow.prototype.backgroundRemoval = CreateWorkflow(BackgroundRemovalTask);
1539
1066
 
1540
1067
  // src/task/ChunkRetrievalTask.ts
1541
1068
  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";
1069
+ import { CreateWorkflow as CreateWorkflow3, Task as Task2, Workflow as Workflow3 } from "@workglow/task-graph";
1547
1070
  import {
1548
1071
  isTypedArray,
1549
1072
  TypedArraySchema as TypedArraySchema2
1550
1073
  } from "@workglow/util/schema";
1551
1074
 
1552
1075
  // src/task/TextEmbeddingTask.ts
1553
- import { CreateWorkflow as CreateWorkflow4, Workflow as Workflow4 } from "@workglow/task-graph";
1076
+ import { CreateWorkflow as CreateWorkflow2, Workflow as Workflow2 } from "@workglow/task-graph";
1554
1077
  import {
1555
1078
  TypedArraySchema
1556
1079
  } from "@workglow/util/schema";
1557
- var modelSchema4 = TypeModel("model:TextEmbeddingTask");
1080
+ var modelSchema2 = TypeModel("model:TextEmbeddingTask");
1558
1081
  var TextEmbeddingInputSchema = {
1559
1082
  type: "object",
1560
1083
  properties: {
@@ -1563,7 +1086,7 @@ var TextEmbeddingInputSchema = {
1563
1086
  title: "Text",
1564
1087
  description: "The text to embed"
1565
1088
  }),
1566
- model: modelSchema4
1089
+ model: modelSchema2
1567
1090
  },
1568
1091
  required: ["text", "model"],
1569
1092
  additionalProperties: false
@@ -1595,7 +1118,7 @@ class TextEmbeddingTask extends AiTask {
1595
1118
  var textEmbedding = async (input, config) => {
1596
1119
  return new TextEmbeddingTask({}, config).run(input);
1597
1120
  };
1598
- Workflow4.prototype.textEmbedding = CreateWorkflow4(TextEmbeddingTask);
1121
+ Workflow2.prototype.textEmbedding = CreateWorkflow2(TextEmbeddingTask);
1599
1122
 
1600
1123
  // src/task/ChunkRetrievalTask.ts
1601
1124
  var inputSchema = {
@@ -1787,15 +1310,11 @@ class ChunkRetrievalTask extends Task2 {
1787
1310
  var chunkRetrieval = (input, config) => {
1788
1311
  return new ChunkRetrievalTask({}, config).run(input);
1789
1312
  };
1790
- Workflow5.prototype.chunkRetrieval = CreateWorkflow5(ChunkRetrievalTask);
1313
+ Workflow3.prototype.chunkRetrieval = CreateWorkflow3(ChunkRetrievalTask);
1791
1314
 
1792
1315
  // src/task/ChunkToVectorTask.ts
1793
1316
  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";
1317
+ import { CreateWorkflow as CreateWorkflow4, Task as Task3, Workflow as Workflow4 } from "@workglow/task-graph";
1799
1318
  import {
1800
1319
  TypedArraySchema as TypedArraySchema3
1801
1320
  } from "@workglow/util/schema";
@@ -1921,15 +1440,11 @@ class ChunkToVectorTask extends Task3 {
1921
1440
  var chunkToVector = (input, config) => {
1922
1441
  return new ChunkToVectorTask({}, config).run(input);
1923
1442
  };
1924
- Workflow6.prototype.chunkToVector = CreateWorkflow6(ChunkToVectorTask);
1443
+ Workflow4.prototype.chunkToVector = CreateWorkflow4(ChunkToVectorTask);
1925
1444
 
1926
1445
  // src/task/ChunkVectorHybridSearchTask.ts
1927
1446
  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";
1447
+ import { CreateWorkflow as CreateWorkflow5, Task as Task4, Workflow as Workflow5 } from "@workglow/task-graph";
1933
1448
  import {
1934
1449
  TypedArraySchema as TypedArraySchema4
1935
1450
  } from "@workglow/util/schema";
@@ -2095,15 +1610,11 @@ class ChunkVectorHybridSearchTask extends Task4 {
2095
1610
  var hybridSearch = async (input, config) => {
2096
1611
  return new ChunkVectorHybridSearchTask({}, config).run(input);
2097
1612
  };
2098
- Workflow7.prototype.hybridSearch = CreateWorkflow7(ChunkVectorHybridSearchTask);
1613
+ Workflow5.prototype.hybridSearch = CreateWorkflow5(ChunkVectorHybridSearchTask);
2099
1614
 
2100
1615
  // src/task/ChunkVectorSearchTask.ts
2101
1616
  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";
1617
+ import { CreateWorkflow as CreateWorkflow6, Task as Task5, Workflow as Workflow6 } from "@workglow/task-graph";
2107
1618
  import {
2108
1619
  TypedArraySchema as TypedArraySchema5
2109
1620
  } from "@workglow/util/schema";
@@ -2218,15 +1729,11 @@ class ChunkVectorSearchTask extends Task5 {
2218
1729
  var vectorStoreSearch = (input, config) => {
2219
1730
  return new ChunkVectorSearchTask({}, config).run(input);
2220
1731
  };
2221
- Workflow8.prototype.vectorStoreSearch = CreateWorkflow8(ChunkVectorSearchTask);
1732
+ Workflow6.prototype.vectorStoreSearch = CreateWorkflow6(ChunkVectorSearchTask);
2222
1733
 
2223
1734
  // src/task/ChunkVectorUpsertTask.ts
2224
1735
  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";
1736
+ import { CreateWorkflow as CreateWorkflow7, Task as Task6, Workflow as Workflow7 } from "@workglow/task-graph";
2230
1737
  import {
2231
1738
  TypedArraySchema as TypedArraySchema6
2232
1739
  } from "@workglow/util/schema";
@@ -2340,28 +1847,28 @@ class ChunkVectorUpsertTask extends Task6 {
2340
1847
  var chunkVectorUpsert = (input, config) => {
2341
1848
  return new ChunkVectorUpsertTask({}, config).run(input);
2342
1849
  };
2343
- Workflow9.prototype.chunkVectorUpsert = CreateWorkflow9(ChunkVectorUpsertTask);
1850
+ Workflow7.prototype.chunkVectorUpsert = CreateWorkflow7(ChunkVectorUpsertTask);
2344
1851
 
2345
1852
  // src/task/ContextBuilderTask.ts
2346
1853
  import { estimateTokens } from "@workglow/knowledge-base";
2347
1854
  import {
2348
- CreateWorkflow as CreateWorkflow11,
1855
+ CreateWorkflow as CreateWorkflow9,
2349
1856
  Task as Task7,
2350
- Workflow as Workflow11
1857
+ Workflow as Workflow9
2351
1858
  } from "@workglow/task-graph";
2352
1859
 
2353
1860
  // src/task/CountTokensTask.ts
2354
- import { CreateWorkflow as CreateWorkflow10, Workflow as Workflow10 } from "@workglow/task-graph";
2355
- var modelSchema5 = TypeModel("model");
1861
+ import { CreateWorkflow as CreateWorkflow8, Workflow as Workflow8 } from "@workglow/task-graph";
1862
+ var modelSchema3 = TypeModel("model");
2356
1863
  var CountTokensInputSchema = {
2357
1864
  type: "object",
2358
1865
  properties: {
2359
- text: TypeSingleOrArray({
1866
+ text: {
2360
1867
  type: "string",
2361
1868
  title: "Text",
2362
1869
  description: "The text to count tokens for"
2363
- }),
2364
- model: modelSchema5
1870
+ },
1871
+ model: modelSchema3
2365
1872
  },
2366
1873
  required: ["text", "model"],
2367
1874
  additionalProperties: false
@@ -2369,11 +1876,11 @@ var CountTokensInputSchema = {
2369
1876
  var CountTokensOutputSchema = {
2370
1877
  type: "object",
2371
1878
  properties: {
2372
- count: TypeSingleOrArray({
1879
+ count: {
2373
1880
  type: "number",
2374
1881
  title: "Token Count",
2375
1882
  description: "The number of tokens in the text"
2376
- })
1883
+ }
2377
1884
  },
2378
1885
  required: ["count"],
2379
1886
  additionalProperties: false
@@ -2395,7 +1902,7 @@ class CountTokensTask extends AiTask {
2395
1902
  var countTokens = async (input, config) => {
2396
1903
  return new CountTokensTask({}, config).run(input);
2397
1904
  };
2398
- Workflow10.prototype.countTokens = CreateWorkflow10(CountTokensTask);
1905
+ Workflow8.prototype.countTokens = CreateWorkflow8(CountTokensTask);
2399
1906
 
2400
1907
  // src/task/ContextBuilderTask.ts
2401
1908
  var ContextFormat = {
@@ -2405,7 +1912,7 @@ var ContextFormat = {
2405
1912
  MARKDOWN: "markdown",
2406
1913
  JSON: "json"
2407
1914
  };
2408
- var modelSchema6 = TypeModel("model", {
1915
+ var modelSchema4 = TypeModel("model", {
2409
1916
  title: "Model",
2410
1917
  description: "Model to use for token counting (optional, falls back to estimation)"
2411
1918
  });
@@ -2469,7 +1976,7 @@ var inputSchema6 = {
2469
1976
 
2470
1977
  `
2471
1978
  },
2472
- model: modelSchema6
1979
+ model: modelSchema4
2473
1980
  },
2474
1981
  required: ["chunks"],
2475
1982
  additionalProperties: false
@@ -2695,30 +2202,26 @@ class ContextBuilderTask extends Task7 {
2695
2202
  var contextBuilder = (input, config) => {
2696
2203
  return new ContextBuilderTask({}, config).run(input);
2697
2204
  };
2698
- Workflow11.prototype.contextBuilder = CreateWorkflow11(ContextBuilderTask);
2205
+ Workflow9.prototype.contextBuilder = CreateWorkflow9(ContextBuilderTask);
2699
2206
 
2700
2207
  // src/task/DocumentEnricherTask.ts
2701
2208
  import {
2702
2209
  getChildren,
2703
2210
  hasChildren
2704
2211
  } from "@workglow/knowledge-base";
2705
- import {
2706
- CreateWorkflow as CreateWorkflow14,
2707
- Task as Task8,
2708
- Workflow as Workflow14
2709
- } from "@workglow/task-graph";
2212
+ import { CreateWorkflow as CreateWorkflow12, Task as Task8, Workflow as Workflow12 } from "@workglow/task-graph";
2710
2213
 
2711
2214
  // src/task/TextNamedEntityRecognitionTask.ts
2712
- import { CreateWorkflow as CreateWorkflow12, Workflow as Workflow12 } from "@workglow/task-graph";
2713
- var modelSchema7 = TypeModel("model:TextNamedEntityRecognitionTask");
2215
+ import { CreateWorkflow as CreateWorkflow10, Workflow as Workflow10 } from "@workglow/task-graph";
2216
+ var modelSchema5 = TypeModel("model:TextNamedEntityRecognitionTask");
2714
2217
  var TextNamedEntityRecognitionInputSchema = {
2715
2218
  type: "object",
2716
2219
  properties: {
2717
- text: TypeSingleOrArray({
2220
+ text: {
2718
2221
  type: "string",
2719
2222
  title: "Text",
2720
2223
  description: "The text to extract named entities from"
2721
- }),
2224
+ },
2722
2225
  blockList: {
2723
2226
  type: "array",
2724
2227
  items: {
@@ -2729,7 +2232,7 @@ var TextNamedEntityRecognitionInputSchema = {
2729
2232
  "x-ui-group": "Configuration",
2730
2233
  "x-ui-group-open": false
2731
2234
  },
2732
- model: modelSchema7
2235
+ model: modelSchema5
2733
2236
  },
2734
2237
  required: ["text", "model"],
2735
2238
  additionalProperties: false
@@ -2737,7 +2240,7 @@ var TextNamedEntityRecognitionInputSchema = {
2737
2240
  var TextNamedEntityRecognitionOutputSchema = {
2738
2241
  type: "object",
2739
2242
  properties: {
2740
- entities: TypeSingleOrArray({
2243
+ entities: {
2741
2244
  type: "array",
2742
2245
  items: {
2743
2246
  type: "object",
@@ -2763,7 +2266,7 @@ var TextNamedEntityRecognitionOutputSchema = {
2763
2266
  },
2764
2267
  title: "Entities",
2765
2268
  description: "The extracted named entities with their types, scores, and text"
2766
- })
2269
+ }
2767
2270
  },
2768
2271
  required: ["entities"],
2769
2272
  additionalProperties: false
@@ -2784,20 +2287,60 @@ class TextNamedEntityRecognitionTask extends AiTask {
2784
2287
  var textNamedEntityRecognition = (input, config) => {
2785
2288
  return new TextNamedEntityRecognitionTask({}, config).run(input);
2786
2289
  };
2787
- Workflow12.prototype.textNamedEntityRecognition = CreateWorkflow12(TextNamedEntityRecognitionTask);
2290
+ Workflow10.prototype.textNamedEntityRecognition = CreateWorkflow10(TextNamedEntityRecognitionTask);
2788
2291
 
2789
2292
  // src/task/TextSummaryTask.ts
2790
- import { CreateWorkflow as CreateWorkflow13, Workflow as Workflow13 } from "@workglow/task-graph";
2791
- var modelSchema8 = TypeModel("model:TextSummaryTask");
2293
+ import { CreateWorkflow as CreateWorkflow11, Workflow as Workflow11 } from "@workglow/task-graph";
2294
+
2295
+ // src/task/base/StreamingAiTask.ts
2296
+ import {
2297
+ getStreamingPorts,
2298
+ TaskConfigurationError as TaskConfigurationError3
2299
+ } from "@workglow/task-graph";
2300
+ class StreamingAiTask extends AiTask {
2301
+ static type = "StreamingAiTask";
2302
+ async* executeStream(input, context) {
2303
+ const model = input.model;
2304
+ if (!model || typeof model !== "object") {
2305
+ throw new TaskConfigurationError3("StreamingAiTask: Model was not resolved to ModelConfig - this indicates a bug in the resolution system");
2306
+ }
2307
+ const jobInput = await this.getJobInput(input);
2308
+ const strategy = getAiProviderRegistry().getStrategy(model);
2309
+ const outSchema = this.outputSchema();
2310
+ const ports = getStreamingPorts(outSchema);
2311
+ let defaultPort = "text";
2312
+ if (ports.length > 0) {
2313
+ defaultPort = ports[0].port;
2314
+ } else {
2315
+ if (typeof outSchema === "object" && outSchema.properties) {
2316
+ const firstProp = Object.keys(outSchema.properties)[0];
2317
+ if (firstProp)
2318
+ defaultPort = firstProp;
2319
+ }
2320
+ }
2321
+ for await (const event of strategy.executeStream(jobInput, context, this.runConfig.runnerId)) {
2322
+ if (event.type === "text-delta") {
2323
+ yield { ...event, port: event.port ?? defaultPort };
2324
+ } else if (event.type === "object-delta") {
2325
+ yield { ...event, port: event.port ?? defaultPort };
2326
+ } else {
2327
+ yield event;
2328
+ }
2329
+ }
2330
+ }
2331
+ }
2332
+
2333
+ // src/task/TextSummaryTask.ts
2334
+ var modelSchema6 = TypeModel("model:TextSummaryTask");
2792
2335
  var TextSummaryInputSchema = {
2793
2336
  type: "object",
2794
2337
  properties: {
2795
- text: TypeSingleOrArray({
2338
+ text: {
2796
2339
  type: "string",
2797
2340
  title: "Text",
2798
2341
  description: "The text to summarize"
2799
- }),
2800
- model: modelSchema8
2342
+ },
2343
+ model: modelSchema6
2801
2344
  },
2802
2345
  required: ["text", "model"],
2803
2346
  additionalProperties: false
@@ -2805,12 +2348,12 @@ var TextSummaryInputSchema = {
2805
2348
  var TextSummaryOutputSchema = {
2806
2349
  type: "object",
2807
2350
  properties: {
2808
- text: TypeSingleOrArray({
2351
+ text: {
2809
2352
  type: "string",
2810
2353
  title: "Text",
2811
2354
  description: "The summarized text",
2812
2355
  "x-stream": "append"
2813
- })
2356
+ }
2814
2357
  },
2815
2358
  required: ["text"],
2816
2359
  additionalProperties: false
@@ -2831,7 +2374,7 @@ class TextSummaryTask extends StreamingAiTask {
2831
2374
  var textSummary = async (input, config) => {
2832
2375
  return new TextSummaryTask({}, config).run(input);
2833
2376
  };
2834
- Workflow13.prototype.textSummary = CreateWorkflow13(TextSummaryTask);
2377
+ Workflow11.prototype.textSummary = CreateWorkflow11(TextSummaryTask);
2835
2378
 
2836
2379
  // src/task/DocumentEnricherTask.ts
2837
2380
  var inputSchema7 = {
@@ -3062,15 +2605,15 @@ class DocumentEnricherTask extends Task8 {
3062
2605
  var documentEnricher = (input, config) => {
3063
2606
  return new DocumentEnricherTask({}, config).run(input);
3064
2607
  };
3065
- Workflow14.prototype.documentEnricher = CreateWorkflow14(DocumentEnricherTask);
2608
+ Workflow12.prototype.documentEnricher = CreateWorkflow12(DocumentEnricherTask);
3066
2609
 
3067
2610
  // src/task/DownloadModelTask.ts
3068
- import { CreateWorkflow as CreateWorkflow15, Workflow as Workflow15 } from "@workglow/task-graph";
3069
- var modelSchema9 = TypeModel("model");
2611
+ import { CreateWorkflow as CreateWorkflow13, Workflow as Workflow13 } from "@workglow/task-graph";
2612
+ var modelSchema7 = TypeModel("model");
3070
2613
  var DownloadModelInputSchema = {
3071
2614
  type: "object",
3072
2615
  properties: {
3073
- model: modelSchema9
2616
+ model: modelSchema7
3074
2617
  },
3075
2618
  required: ["model"],
3076
2619
  additionalProperties: false
@@ -3078,7 +2621,7 @@ var DownloadModelInputSchema = {
3078
2621
  var DownloadModelOutputSchema = {
3079
2622
  type: "object",
3080
2623
  properties: {
3081
- model: modelSchema9
2624
+ model: modelSchema7
3082
2625
  },
3083
2626
  required: ["model"],
3084
2627
  additionalProperties: false
@@ -3132,11 +2675,11 @@ class DownloadModelTask extends AiTask {
3132
2675
  var downloadModel = (input, config) => {
3133
2676
  return new DownloadModelTask({}, config).run(input);
3134
2677
  };
3135
- Workflow15.prototype.downloadModel = CreateWorkflow15(DownloadModelTask);
2678
+ Workflow13.prototype.downloadModel = CreateWorkflow13(DownloadModelTask);
3136
2679
 
3137
2680
  // src/task/FaceDetectorTask.ts
3138
- import { CreateWorkflow as CreateWorkflow16, Workflow as Workflow16 } from "@workglow/task-graph";
3139
- var modelSchema10 = TypeModel("model:FaceDetectorTask");
2681
+ import { CreateWorkflow as CreateWorkflow14, Workflow as Workflow14 } from "@workglow/task-graph";
2682
+ var modelSchema8 = TypeModel("model:FaceDetectorTask");
3140
2683
  var TypeBoundingBox2 = {
3141
2684
  type: "object",
3142
2685
  properties: {
@@ -3209,7 +2752,7 @@ var FaceDetectorInputSchema = {
3209
2752
  type: "object",
3210
2753
  properties: {
3211
2754
  image: TypeImageInput,
3212
- model: modelSchema10,
2755
+ model: modelSchema8,
3213
2756
  minDetectionConfidence: {
3214
2757
  type: "number",
3215
2758
  minimum: 0,
@@ -3263,11 +2806,11 @@ class FaceDetectorTask extends AiVisionTask {
3263
2806
  var faceDetector = (input, config) => {
3264
2807
  return new FaceDetectorTask({}, config).run(input);
3265
2808
  };
3266
- Workflow16.prototype.faceDetector = CreateWorkflow16(FaceDetectorTask);
2809
+ Workflow14.prototype.faceDetector = CreateWorkflow14(FaceDetectorTask);
3267
2810
 
3268
2811
  // src/task/FaceLandmarkerTask.ts
3269
- import { CreateWorkflow as CreateWorkflow17, Workflow as Workflow17 } from "@workglow/task-graph";
3270
- var modelSchema11 = TypeModel("model:FaceLandmarkerTask");
2812
+ import { CreateWorkflow as CreateWorkflow15, Workflow as Workflow15 } from "@workglow/task-graph";
2813
+ var modelSchema9 = TypeModel("model:FaceLandmarkerTask");
3271
2814
  var TypeLandmark = {
3272
2815
  type: "object",
3273
2816
  properties: {
@@ -3339,7 +2882,7 @@ var FaceLandmarkerInputSchema = {
3339
2882
  type: "object",
3340
2883
  properties: {
3341
2884
  image: TypeImageInput,
3342
- model: modelSchema11,
2885
+ model: modelSchema9,
3343
2886
  numFaces: {
3344
2887
  type: "number",
3345
2888
  minimum: 1,
@@ -3425,11 +2968,11 @@ class FaceLandmarkerTask extends AiVisionTask {
3425
2968
  var faceLandmarker = (input, config) => {
3426
2969
  return new FaceLandmarkerTask({}, config).run(input);
3427
2970
  };
3428
- Workflow17.prototype.faceLandmarker = CreateWorkflow17(FaceLandmarkerTask);
2971
+ Workflow15.prototype.faceLandmarker = CreateWorkflow15(FaceLandmarkerTask);
3429
2972
 
3430
2973
  // src/task/GestureRecognizerTask.ts
3431
- import { CreateWorkflow as CreateWorkflow18, Workflow as Workflow18 } from "@workglow/task-graph";
3432
- var modelSchema12 = TypeModel("model:GestureRecognizerTask");
2974
+ import { CreateWorkflow as CreateWorkflow16, Workflow as Workflow16 } from "@workglow/task-graph";
2975
+ var modelSchema10 = TypeModel("model:GestureRecognizerTask");
3433
2976
  var TypeLandmark2 = {
3434
2977
  type: "object",
3435
2978
  properties: {
@@ -3521,7 +3064,7 @@ var GestureRecognizerInputSchema = {
3521
3064
  type: "object",
3522
3065
  properties: {
3523
3066
  image: TypeImageInput,
3524
- model: modelSchema12,
3067
+ model: modelSchema10,
3525
3068
  numHands: {
3526
3069
  type: "number",
3527
3070
  minimum: 1,
@@ -3593,11 +3136,11 @@ class GestureRecognizerTask extends AiVisionTask {
3593
3136
  var gestureRecognizer = (input, config) => {
3594
3137
  return new GestureRecognizerTask({}, config).run(input);
3595
3138
  };
3596
- Workflow18.prototype.gestureRecognizer = CreateWorkflow18(GestureRecognizerTask);
3139
+ Workflow16.prototype.gestureRecognizer = CreateWorkflow16(GestureRecognizerTask);
3597
3140
 
3598
3141
  // src/task/HandLandmarkerTask.ts
3599
- import { CreateWorkflow as CreateWorkflow19, Workflow as Workflow19 } from "@workglow/task-graph";
3600
- var modelSchema13 = TypeModel("model:HandLandmarkerTask");
3142
+ import { CreateWorkflow as CreateWorkflow17, Workflow as Workflow17 } from "@workglow/task-graph";
3143
+ var modelSchema11 = TypeModel("model:HandLandmarkerTask");
3601
3144
  var TypeLandmark3 = {
3602
3145
  type: "object",
3603
3146
  properties: {
@@ -3666,7 +3209,7 @@ var HandLandmarkerInputSchema = {
3666
3209
  type: "object",
3667
3210
  properties: {
3668
3211
  image: TypeImageInput,
3669
- model: modelSchema13,
3212
+ model: modelSchema11,
3670
3213
  numHands: {
3671
3214
  type: "number",
3672
3215
  minimum: 1,
@@ -3738,7 +3281,7 @@ class HandLandmarkerTask extends AiVisionTask {
3738
3281
  var handLandmarker = (input, config) => {
3739
3282
  return new HandLandmarkerTask({}, config).run(input);
3740
3283
  };
3741
- Workflow19.prototype.handLandmarker = CreateWorkflow19(HandLandmarkerTask);
3284
+ Workflow17.prototype.handLandmarker = CreateWorkflow17(HandLandmarkerTask);
3742
3285
 
3743
3286
  // src/task/HierarchicalChunkerTask.ts
3744
3287
  import {
@@ -3747,13 +3290,9 @@ import {
3747
3290
  getChildren as getChildren2,
3748
3291
  hasChildren as hasChildren2
3749
3292
  } from "@workglow/knowledge-base";
3750
- import {
3751
- CreateWorkflow as CreateWorkflow20,
3752
- Task as Task9,
3753
- Workflow as Workflow20
3754
- } from "@workglow/task-graph";
3293
+ import { CreateWorkflow as CreateWorkflow18, Task as Task9, Workflow as Workflow18 } from "@workglow/task-graph";
3755
3294
  import { uuid4 } from "@workglow/util";
3756
- var modelSchema14 = TypeModel("model", {
3295
+ var modelSchema12 = TypeModel("model", {
3757
3296
  title: "Model",
3758
3297
  description: "Model to use for token counting"
3759
3298
  });
@@ -3797,7 +3336,7 @@ var inputSchema8 = {
3797
3336
  description: "Strategy for chunking",
3798
3337
  default: "hierarchical"
3799
3338
  },
3800
- model: modelSchema14
3339
+ model: modelSchema12
3801
3340
  },
3802
3341
  required: ["doc_id", "documentTree"],
3803
3342
  additionalProperties: false
@@ -3976,18 +3515,14 @@ class HierarchicalChunkerTask extends Task9 {
3976
3515
  var hierarchicalChunker = (input, config) => {
3977
3516
  return new HierarchicalChunkerTask({}, config).run(input);
3978
3517
  };
3979
- Workflow20.prototype.hierarchicalChunker = CreateWorkflow20(HierarchicalChunkerTask);
3518
+ Workflow18.prototype.hierarchicalChunker = CreateWorkflow18(HierarchicalChunkerTask);
3980
3519
 
3981
3520
  // src/task/HierarchyJoinTask.ts
3982
3521
  import {
3983
3522
  ChunkRecordArraySchema,
3984
3523
  TypeKnowledgeBase as TypeKnowledgeBase5
3985
3524
  } from "@workglow/knowledge-base";
3986
- import {
3987
- CreateWorkflow as CreateWorkflow21,
3988
- Task as Task10,
3989
- Workflow as Workflow21
3990
- } from "@workglow/task-graph";
3525
+ import { CreateWorkflow as CreateWorkflow19, Task as Task10, Workflow as Workflow19 } from "@workglow/task-graph";
3991
3526
  var inputSchema9 = {
3992
3527
  type: "object",
3993
3528
  properties: {
@@ -4156,16 +3691,16 @@ class HierarchyJoinTask extends Task10 {
4156
3691
  var hierarchyJoin = (input, config) => {
4157
3692
  return new HierarchyJoinTask({}, config).run(input);
4158
3693
  };
4159
- Workflow21.prototype.hierarchyJoin = CreateWorkflow21(HierarchyJoinTask);
3694
+ Workflow19.prototype.hierarchyJoin = CreateWorkflow19(HierarchyJoinTask);
4160
3695
 
4161
3696
  // src/task/ImageClassificationTask.ts
4162
- import { CreateWorkflow as CreateWorkflow22, Workflow as Workflow22 } from "@workglow/task-graph";
4163
- var modelSchema15 = TypeModel("model:ImageClassificationTask");
3697
+ import { CreateWorkflow as CreateWorkflow20, Workflow as Workflow20 } from "@workglow/task-graph";
3698
+ var modelSchema13 = TypeModel("model:ImageClassificationTask");
4164
3699
  var ImageClassificationInputSchema = {
4165
3700
  type: "object",
4166
3701
  properties: {
4167
3702
  image: TypeImageInput,
4168
- model: modelSchema15,
3703
+ model: modelSchema13,
4169
3704
  categories: {
4170
3705
  type: "array",
4171
3706
  items: {
@@ -4219,23 +3754,19 @@ class ImageClassificationTask extends AiVisionTask {
4219
3754
  var imageClassification = (input, config) => {
4220
3755
  return new ImageClassificationTask({}, config).run(input);
4221
3756
  };
4222
- Workflow22.prototype.imageClassification = CreateWorkflow22(ImageClassificationTask);
3757
+ Workflow20.prototype.imageClassification = CreateWorkflow20(ImageClassificationTask);
4223
3758
 
4224
3759
  // src/task/ImageEmbeddingTask.ts
4225
- import { CreateWorkflow as CreateWorkflow23, Workflow as Workflow23 } from "@workglow/task-graph";
3760
+ import { CreateWorkflow as CreateWorkflow21, Workflow as Workflow21 } from "@workglow/task-graph";
4226
3761
  import {
4227
3762
  TypedArraySchema as TypedArraySchema7
4228
3763
  } from "@workglow/util/schema";
4229
- var modelSchema16 = TypeModel("model:ImageEmbeddingTask");
4230
- var embeddingSchema = TypedArraySchema7({
4231
- title: "Embedding",
4232
- description: "The image embedding vector"
4233
- });
3764
+ var modelSchema14 = TypeModel("model:ImageEmbeddingTask");
4234
3765
  var ImageEmbeddingInputSchema = {
4235
3766
  type: "object",
4236
3767
  properties: {
4237
- image: TypeImageInput,
4238
- model: modelSchema16
3768
+ image: TypeSingleOrArray(TypeImageInput),
3769
+ model: modelSchema14
4239
3770
  },
4240
3771
  required: ["image", "model"],
4241
3772
  additionalProperties: false
@@ -4243,7 +3774,10 @@ var ImageEmbeddingInputSchema = {
4243
3774
  var ImageEmbeddingOutputSchema = {
4244
3775
  type: "object",
4245
3776
  properties: {
4246
- vector: embeddingSchema
3777
+ vector: TypeSingleOrArray(TypedArraySchema7({
3778
+ title: "Embedding",
3779
+ description: "The image embedding vector"
3780
+ }))
4247
3781
  },
4248
3782
  required: ["vector"],
4249
3783
  additionalProperties: false
@@ -4264,16 +3798,16 @@ class ImageEmbeddingTask extends AiVisionTask {
4264
3798
  var imageEmbedding = (input, config) => {
4265
3799
  return new ImageEmbeddingTask({}, config).run(input);
4266
3800
  };
4267
- Workflow23.prototype.imageEmbedding = CreateWorkflow23(ImageEmbeddingTask);
3801
+ Workflow21.prototype.imageEmbedding = CreateWorkflow21(ImageEmbeddingTask);
4268
3802
 
4269
3803
  // src/task/ImageSegmentationTask.ts
4270
- import { CreateWorkflow as CreateWorkflow24, Workflow as Workflow24 } from "@workglow/task-graph";
4271
- var modelSchema17 = TypeModel("model:ImageSegmentationTask");
3804
+ import { CreateWorkflow as CreateWorkflow22, Workflow as Workflow22 } from "@workglow/task-graph";
3805
+ var modelSchema15 = TypeModel("model:ImageSegmentationTask");
4272
3806
  var ImageSegmentationInputSchema = {
4273
3807
  type: "object",
4274
3808
  properties: {
4275
3809
  image: TypeImageInput,
4276
- model: modelSchema17,
3810
+ model: modelSchema15,
4277
3811
  threshold: {
4278
3812
  type: "number",
4279
3813
  title: "Threshold",
@@ -4352,11 +3886,11 @@ class ImageSegmentationTask extends AiVisionTask {
4352
3886
  var imageSegmentation = (input, config) => {
4353
3887
  return new ImageSegmentationTask({}, config).run(input);
4354
3888
  };
4355
- Workflow24.prototype.imageSegmentation = CreateWorkflow24(ImageSegmentationTask);
3889
+ Workflow22.prototype.imageSegmentation = CreateWorkflow22(ImageSegmentationTask);
4356
3890
 
4357
3891
  // src/task/ImageToTextTask.ts
4358
- import { CreateWorkflow as CreateWorkflow25, Workflow as Workflow25 } from "@workglow/task-graph";
4359
- var modelSchema18 = TypeModel("model:ImageToTextTask");
3892
+ import { CreateWorkflow as CreateWorkflow23, Workflow as Workflow23 } from "@workglow/task-graph";
3893
+ var modelSchema16 = TypeModel("model:ImageToTextTask");
4360
3894
  var generatedTextSchema = {
4361
3895
  type: "string",
4362
3896
  title: "Text",
@@ -4366,7 +3900,7 @@ var ImageToTextInputSchema = {
4366
3900
  type: "object",
4367
3901
  properties: {
4368
3902
  image: TypeImageInput,
4369
- model: modelSchema18,
3903
+ model: modelSchema16,
4370
3904
  maxTokens: {
4371
3905
  type: "number",
4372
3906
  title: "Max Tokens",
@@ -4407,18 +3941,15 @@ class ImageToTextTask extends AiVisionTask {
4407
3941
  var imageToText = (input, config) => {
4408
3942
  return new ImageToTextTask({}, config).run(input);
4409
3943
  };
4410
- Workflow25.prototype.imageToText = CreateWorkflow25(ImageToTextTask);
3944
+ Workflow23.prototype.imageToText = CreateWorkflow23(ImageToTextTask);
4411
3945
 
4412
3946
  // src/task/ModelInfoTask.ts
4413
- import {
4414
- CreateWorkflow as CreateWorkflow26,
4415
- Workflow as Workflow26
4416
- } from "@workglow/task-graph";
4417
- var modelSchema19 = TypeModel("model");
3947
+ import { CreateWorkflow as CreateWorkflow24, Workflow as Workflow24 } from "@workglow/task-graph";
3948
+ var modelSchema17 = TypeModel("model");
4418
3949
  var ModelInfoInputSchema = {
4419
3950
  type: "object",
4420
3951
  properties: {
4421
- model: modelSchema19,
3952
+ model: modelSchema17,
4422
3953
  detail: {
4423
3954
  type: "string",
4424
3955
  enum: ["cached_status", "files", "files_with_metadata"],
@@ -4431,7 +3962,7 @@ var ModelInfoInputSchema = {
4431
3962
  var ModelInfoOutputSchema = {
4432
3963
  type: "object",
4433
3964
  properties: {
4434
- model: modelSchema19,
3965
+ model: modelSchema17,
4435
3966
  is_local: { type: "boolean" },
4436
3967
  is_remote: { type: "boolean" },
4437
3968
  supports_browser: { type: "boolean" },
@@ -4481,10 +4012,10 @@ class ModelInfoTask extends AiTask {
4481
4012
  var modelInfo = (input, config) => {
4482
4013
  return new ModelInfoTask({}, config).run(input);
4483
4014
  };
4484
- Workflow26.prototype.modelInfo = CreateWorkflow26(ModelInfoTask);
4015
+ Workflow24.prototype.modelInfo = CreateWorkflow24(ModelInfoTask);
4485
4016
 
4486
4017
  // src/task/ModelSearchTask.ts
4487
- import { CreateWorkflow as CreateWorkflow27, Task as Task11, Workflow as Workflow27 } from "@workglow/task-graph";
4018
+ import { CreateWorkflow as CreateWorkflow25, Task as Task11, Workflow as Workflow25 } from "@workglow/task-graph";
4488
4019
  var ModelSearchInputSchema = {
4489
4020
  type: "object",
4490
4021
  properties: {
@@ -4575,11 +4106,11 @@ class ModelSearchTask extends Task11 {
4575
4106
  var modelSearch = (input, config) => {
4576
4107
  return new ModelSearchTask({}, config).run(input);
4577
4108
  };
4578
- Workflow27.prototype.modelSearch = CreateWorkflow27(ModelSearchTask);
4109
+ Workflow25.prototype.modelSearch = CreateWorkflow25(ModelSearchTask);
4579
4110
 
4580
4111
  // src/task/ObjectDetectionTask.ts
4581
- import { CreateWorkflow as CreateWorkflow28, Workflow as Workflow28 } from "@workglow/task-graph";
4582
- var modelSchema20 = TypeModel("model:ObjectDetectionTask");
4112
+ import { CreateWorkflow as CreateWorkflow26, Workflow as Workflow26 } from "@workglow/task-graph";
4113
+ var modelSchema18 = TypeModel("model:ObjectDetectionTask");
4583
4114
  var detectionSchema = {
4584
4115
  type: "object",
4585
4116
  properties: {
@@ -4604,7 +4135,7 @@ var ObjectDetectionInputSchema = {
4604
4135
  type: "object",
4605
4136
  properties: {
4606
4137
  image: TypeImageInput,
4607
- model: modelSchema20,
4138
+ model: modelSchema18,
4608
4139
  labels: {
4609
4140
  type: "array",
4610
4141
  items: {
@@ -4658,11 +4189,11 @@ class ObjectDetectionTask extends AiVisionTask {
4658
4189
  var objectDetection = (input, config) => {
4659
4190
  return new ObjectDetectionTask({}, config).run(input);
4660
4191
  };
4661
- Workflow28.prototype.objectDetection = CreateWorkflow28(ObjectDetectionTask);
4192
+ Workflow26.prototype.objectDetection = CreateWorkflow26(ObjectDetectionTask);
4662
4193
 
4663
4194
  // src/task/PoseLandmarkerTask.ts
4664
- import { CreateWorkflow as CreateWorkflow29, Workflow as Workflow29 } from "@workglow/task-graph";
4665
- var modelSchema21 = TypeModel("model:PoseLandmarkerTask");
4195
+ import { CreateWorkflow as CreateWorkflow27, Workflow as Workflow27 } from "@workglow/task-graph";
4196
+ var modelSchema19 = TypeModel("model:PoseLandmarkerTask");
4666
4197
  var TypePoseLandmark = {
4667
4198
  type: "object",
4668
4199
  properties: {
@@ -4741,7 +4272,7 @@ var PoseLandmarkerInputSchema = {
4741
4272
  type: "object",
4742
4273
  properties: {
4743
4274
  image: TypeImageInput,
4744
- model: modelSchema21,
4275
+ model: modelSchema19,
4745
4276
  numPoses: {
4746
4277
  type: "number",
4747
4278
  minimum: 1,
@@ -4820,14 +4351,10 @@ class PoseLandmarkerTask extends AiVisionTask {
4820
4351
  var poseLandmarker = (input, config) => {
4821
4352
  return new PoseLandmarkerTask({}, config).run(input);
4822
4353
  };
4823
- Workflow29.prototype.poseLandmarker = CreateWorkflow29(PoseLandmarkerTask);
4354
+ Workflow27.prototype.poseLandmarker = CreateWorkflow27(PoseLandmarkerTask);
4824
4355
 
4825
4356
  // src/task/QueryExpanderTask.ts
4826
- import {
4827
- CreateWorkflow as CreateWorkflow30,
4828
- Task as Task12,
4829
- Workflow as Workflow30
4830
- } from "@workglow/task-graph";
4357
+ import { CreateWorkflow as CreateWorkflow28, Task as Task12, Workflow as Workflow28 } from "@workglow/task-graph";
4831
4358
  var QueryExpansionMethod = {
4832
4359
  MULTI_QUERY: "multi-query",
4833
4360
  HYDE: "hyde",
@@ -5037,26 +4564,22 @@ class QueryExpanderTask extends Task12 {
5037
4564
  var queryExpander = (input, config) => {
5038
4565
  return new QueryExpanderTask({}, config).run(input);
5039
4566
  };
5040
- Workflow30.prototype.queryExpander = CreateWorkflow30(QueryExpanderTask);
4567
+ Workflow28.prototype.queryExpander = CreateWorkflow28(QueryExpanderTask);
5041
4568
 
5042
4569
  // src/task/RerankerTask.ts
5043
- import {
5044
- CreateWorkflow as CreateWorkflow32,
5045
- Task as Task13,
5046
- Workflow as Workflow32
5047
- } from "@workglow/task-graph";
4570
+ import { CreateWorkflow as CreateWorkflow30, Task as Task13, Workflow as Workflow30 } from "@workglow/task-graph";
5048
4571
 
5049
4572
  // src/task/TextClassificationTask.ts
5050
- import { CreateWorkflow as CreateWorkflow31, Workflow as Workflow31 } from "@workglow/task-graph";
5051
- var modelSchema22 = TypeModel("model:TextClassificationTask");
4573
+ import { CreateWorkflow as CreateWorkflow29, Workflow as Workflow29 } from "@workglow/task-graph";
4574
+ var modelSchema20 = TypeModel("model:TextClassificationTask");
5052
4575
  var TextClassificationInputSchema = {
5053
4576
  type: "object",
5054
4577
  properties: {
5055
- text: TypeSingleOrArray({
4578
+ text: {
5056
4579
  type: "string",
5057
4580
  title: "Text",
5058
4581
  description: "The text to classify"
5059
- }),
4582
+ },
5060
4583
  candidateLabels: {
5061
4584
  type: "array",
5062
4585
  items: {
@@ -5075,7 +4598,7 @@ var TextClassificationInputSchema = {
5075
4598
  description: "The maximum number of categories to return",
5076
4599
  "x-ui-group": "Configuration"
5077
4600
  },
5078
- model: modelSchema22
4601
+ model: modelSchema20
5079
4602
  },
5080
4603
  required: ["text", "model"],
5081
4604
  additionalProperties: false
@@ -5083,7 +4606,7 @@ var TextClassificationInputSchema = {
5083
4606
  var TextClassificationOutputSchema = {
5084
4607
  type: "object",
5085
4608
  properties: {
5086
- categories: TypeSingleOrArray({
4609
+ categories: {
5087
4610
  type: "array",
5088
4611
  items: {
5089
4612
  type: "object",
@@ -5104,7 +4627,7 @@ var TextClassificationOutputSchema = {
5104
4627
  },
5105
4628
  title: "Categories",
5106
4629
  description: "The classification categories with their scores"
5107
- })
4630
+ }
5108
4631
  },
5109
4632
  required: ["categories"],
5110
4633
  additionalProperties: false
@@ -5125,7 +4648,7 @@ class TextClassificationTask extends AiTask {
5125
4648
  var textClassification = (input, config) => {
5126
4649
  return new TextClassificationTask({}, config).run(input);
5127
4650
  };
5128
- Workflow31.prototype.textClassification = CreateWorkflow31(TextClassificationTask);
4651
+ Workflow29.prototype.textClassification = CreateWorkflow29(TextClassificationTask);
5129
4652
 
5130
4653
  // src/task/RerankerTask.ts
5131
4654
  var inputSchema11 = {
@@ -5349,15 +4872,11 @@ class RerankerTask extends Task13 {
5349
4872
  var reranker = (input, config) => {
5350
4873
  return new RerankerTask({}, config).run(input);
5351
4874
  };
5352
- Workflow32.prototype.reranker = CreateWorkflow32(RerankerTask);
4875
+ Workflow30.prototype.reranker = CreateWorkflow30(RerankerTask);
5353
4876
 
5354
4877
  // src/task/StructuralParserTask.ts
5355
4878
  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";
4879
+ import { CreateWorkflow as CreateWorkflow31, Task as Task14, Workflow as Workflow31 } from "@workglow/task-graph";
5361
4880
  import { uuid4 as uuid42 } from "@workglow/util";
5362
4881
  var inputSchema12 = {
5363
4882
  type: "object",
@@ -5458,15 +4977,15 @@ class StructuralParserTask extends Task14 {
5458
4977
  var structuralParser = (input, config) => {
5459
4978
  return new StructuralParserTask({}, config).run(input);
5460
4979
  };
5461
- Workflow33.prototype.structuralParser = CreateWorkflow33(StructuralParserTask);
4980
+ Workflow31.prototype.structuralParser = CreateWorkflow31(StructuralParserTask);
5462
4981
 
5463
4982
  // src/task/StructuredGenerationTask.ts
5464
- import { CreateWorkflow as CreateWorkflow34, Workflow as Workflow34 } from "@workglow/task-graph";
5465
- var modelSchema23 = TypeModel("model:StructuredGenerationTask");
4983
+ import { CreateWorkflow as CreateWorkflow32, Workflow as Workflow32 } from "@workglow/task-graph";
4984
+ var modelSchema21 = TypeModel("model:StructuredGenerationTask");
5466
4985
  var StructuredGenerationInputSchema = {
5467
4986
  type: "object",
5468
4987
  properties: {
5469
- model: modelSchema23,
4988
+ model: modelSchema21,
5470
4989
  prompt: {
5471
4990
  type: "string",
5472
4991
  title: "Prompt",
@@ -5529,14 +5048,10 @@ class StructuredGenerationTask extends StreamingAiTask {
5529
5048
  var structuredGeneration = (input, config) => {
5530
5049
  return new StructuredGenerationTask({}, config).run(input);
5531
5050
  };
5532
- Workflow34.prototype.structuredGeneration = CreateWorkflow34(StructuredGenerationTask);
5051
+ Workflow32.prototype.structuredGeneration = CreateWorkflow32(StructuredGenerationTask);
5533
5052
 
5534
5053
  // src/task/TextChunkerTask.ts
5535
- import {
5536
- CreateWorkflow as CreateWorkflow35,
5537
- Task as Task15,
5538
- Workflow as Workflow35
5539
- } from "@workglow/task-graph";
5054
+ import { CreateWorkflow as CreateWorkflow33, Task as Task15, Workflow as Workflow33 } from "@workglow/task-graph";
5540
5055
  var ChunkingStrategy = {
5541
5056
  FIXED: "fixed",
5542
5057
  SENTENCE: "sentence",
@@ -5785,20 +5300,20 @@ class TextChunkerTask extends Task15 {
5785
5300
  var textChunker = (input, config) => {
5786
5301
  return new TextChunkerTask({}, config).run(input);
5787
5302
  };
5788
- Workflow35.prototype.textChunker = CreateWorkflow35(TextChunkerTask);
5303
+ Workflow33.prototype.textChunker = CreateWorkflow33(TextChunkerTask);
5789
5304
 
5790
5305
  // src/task/TextFillMaskTask.ts
5791
- import { CreateWorkflow as CreateWorkflow36, Workflow as Workflow36 } from "@workglow/task-graph";
5792
- var modelSchema24 = TypeModel("model:TextFillMaskTask");
5306
+ import { CreateWorkflow as CreateWorkflow34, Workflow as Workflow34 } from "@workglow/task-graph";
5307
+ var modelSchema22 = TypeModel("model:TextFillMaskTask");
5793
5308
  var TextFillMaskInputSchema = {
5794
5309
  type: "object",
5795
5310
  properties: {
5796
- text: TypeSingleOrArray({
5311
+ text: {
5797
5312
  type: "string",
5798
5313
  title: "Text",
5799
5314
  description: "The text with a mask token to fill"
5800
- }),
5801
- model: modelSchema24
5315
+ },
5316
+ model: modelSchema22
5802
5317
  },
5803
5318
  required: ["text", "model"],
5804
5319
  additionalProperties: false
@@ -5806,7 +5321,7 @@ var TextFillMaskInputSchema = {
5806
5321
  var TextFillMaskOutputSchema = {
5807
5322
  type: "object",
5808
5323
  properties: {
5809
- predictions: TypeSingleOrArray({
5324
+ predictions: {
5810
5325
  type: "array",
5811
5326
  items: {
5812
5327
  type: "object",
@@ -5832,7 +5347,7 @@ var TextFillMaskOutputSchema = {
5832
5347
  },
5833
5348
  title: "Predictions",
5834
5349
  description: "The predicted tokens to fill the mask with their scores and complete sequences"
5835
- })
5350
+ }
5836
5351
  },
5837
5352
  required: ["predictions"],
5838
5353
  additionalProperties: false
@@ -5853,26 +5368,26 @@ class TextFillMaskTask extends AiTask {
5853
5368
  var textFillMask = (input, config) => {
5854
5369
  return new TextFillMaskTask({}, config).run(input);
5855
5370
  };
5856
- Workflow36.prototype.textFillMask = CreateWorkflow36(TextFillMaskTask);
5371
+ Workflow34.prototype.textFillMask = CreateWorkflow34(TextFillMaskTask);
5857
5372
 
5858
5373
  // src/task/TextGenerationTask.ts
5859
- import { CreateWorkflow as CreateWorkflow37, Workflow as Workflow37 } from "@workglow/task-graph";
5860
- var generatedTextSchema2 = TypeSingleOrArray({
5374
+ import { CreateWorkflow as CreateWorkflow35, Workflow as Workflow35 } from "@workglow/task-graph";
5375
+ var generatedTextSchema2 = {
5861
5376
  type: "string",
5862
5377
  title: "Text",
5863
5378
  description: "The generated text",
5864
5379
  "x-stream": "append"
5865
- });
5866
- var modelSchema25 = TypeModel("model:TextGenerationTask");
5380
+ };
5381
+ var modelSchema23 = TypeModel("model:TextGenerationTask");
5867
5382
  var TextGenerationInputSchema = {
5868
5383
  type: "object",
5869
5384
  properties: {
5870
- model: modelSchema25,
5871
- prompt: TypeSingleOrArray({
5385
+ model: modelSchema23,
5386
+ prompt: {
5872
5387
  type: "string",
5873
5388
  title: "Prompt",
5874
5389
  description: "The prompt to generate text from"
5875
- }),
5390
+ },
5876
5391
  maxTokens: {
5877
5392
  type: "number",
5878
5393
  title: "Max Tokens",
@@ -5941,19 +5456,19 @@ class TextGenerationTask extends StreamingAiTask {
5941
5456
  var textGeneration = (input, config) => {
5942
5457
  return new TextGenerationTask({}, config).run(input);
5943
5458
  };
5944
- Workflow37.prototype.textGeneration = CreateWorkflow37(TextGenerationTask);
5459
+ Workflow35.prototype.textGeneration = CreateWorkflow35(TextGenerationTask);
5945
5460
 
5946
5461
  // src/task/TextLanguageDetectionTask.ts
5947
- import { CreateWorkflow as CreateWorkflow38, Workflow as Workflow38 } from "@workglow/task-graph";
5948
- var modelSchema26 = TypeModel("model:TextLanguageDetectionTask");
5462
+ import { CreateWorkflow as CreateWorkflow36, Workflow as Workflow36 } from "@workglow/task-graph";
5463
+ var modelSchema24 = TypeModel("model:TextLanguageDetectionTask");
5949
5464
  var TextLanguageDetectionInputSchema = {
5950
5465
  type: "object",
5951
5466
  properties: {
5952
- text: TypeSingleOrArray({
5467
+ text: {
5953
5468
  type: "string",
5954
5469
  title: "Text",
5955
5470
  description: "The text to detect the language of"
5956
- }),
5471
+ },
5957
5472
  maxLanguages: {
5958
5473
  type: "number",
5959
5474
  minimum: 0,
@@ -5962,7 +5477,7 @@ var TextLanguageDetectionInputSchema = {
5962
5477
  title: "Max Languages",
5963
5478
  description: "The maximum number of languages to return"
5964
5479
  },
5965
- model: modelSchema26
5480
+ model: modelSchema24
5966
5481
  },
5967
5482
  required: ["text", "model"],
5968
5483
  additionalProperties: false
@@ -5970,7 +5485,7 @@ var TextLanguageDetectionInputSchema = {
5970
5485
  var TextLanguageDetectionOutputSchema = {
5971
5486
  type: "object",
5972
5487
  properties: {
5973
- languages: TypeSingleOrArray({
5488
+ languages: {
5974
5489
  type: "array",
5975
5490
  items: {
5976
5491
  type: "object",
@@ -5991,7 +5506,7 @@ var TextLanguageDetectionOutputSchema = {
5991
5506
  },
5992
5507
  title: "Languages",
5993
5508
  description: "The languages with their scores"
5994
- })
5509
+ }
5995
5510
  },
5996
5511
  required: ["languages"],
5997
5512
  additionalProperties: false
@@ -6012,33 +5527,33 @@ class TextLanguageDetectionTask extends AiTask {
6012
5527
  var textLanguageDetection = (input, config) => {
6013
5528
  return new TextLanguageDetectionTask({}, config).run(input);
6014
5529
  };
6015
- Workflow38.prototype.textLanguageDetection = CreateWorkflow38(TextLanguageDetectionTask);
5530
+ Workflow36.prototype.textLanguageDetection = CreateWorkflow36(TextLanguageDetectionTask);
6016
5531
 
6017
5532
  // src/task/TextQuestionAnswerTask.ts
6018
- import { CreateWorkflow as CreateWorkflow39, Workflow as Workflow39 } from "@workglow/task-graph";
6019
- var contextSchema = TypeSingleOrArray({
5533
+ import { CreateWorkflow as CreateWorkflow37, Workflow as Workflow37 } from "@workglow/task-graph";
5534
+ var contextSchema = {
6020
5535
  type: "string",
6021
5536
  title: "Context",
6022
5537
  description: "The context of the question"
6023
- });
6024
- var questionSchema = TypeSingleOrArray({
5538
+ };
5539
+ var questionSchema = {
6025
5540
  type: "string",
6026
5541
  title: "Question",
6027
5542
  description: "The question to answer"
6028
- });
6029
- var textSchema = TypeSingleOrArray({
5543
+ };
5544
+ var textSchema = {
6030
5545
  type: "string",
6031
5546
  title: "Text",
6032
5547
  description: "The generated text",
6033
5548
  "x-stream": "append"
6034
- });
6035
- var modelSchema27 = TypeModel("model:TextQuestionAnswerTask");
5549
+ };
5550
+ var modelSchema25 = TypeModel("model:TextQuestionAnswerTask");
6036
5551
  var TextQuestionAnswerInputSchema = {
6037
5552
  type: "object",
6038
5553
  properties: {
6039
5554
  context: contextSchema,
6040
5555
  question: questionSchema,
6041
- model: modelSchema27
5556
+ model: modelSchema25
6042
5557
  },
6043
5558
  required: ["context", "question", "model"],
6044
5559
  additionalProperties: false
@@ -6067,25 +5582,25 @@ class TextQuestionAnswerTask extends StreamingAiTask {
6067
5582
  var textQuestionAnswer = (input, config) => {
6068
5583
  return new TextQuestionAnswerTask({}, config).run(input);
6069
5584
  };
6070
- Workflow39.prototype.textQuestionAnswer = CreateWorkflow39(TextQuestionAnswerTask);
5585
+ Workflow37.prototype.textQuestionAnswer = CreateWorkflow37(TextQuestionAnswerTask);
6071
5586
 
6072
5587
  // src/task/TextRewriterTask.ts
6073
- import { CreateWorkflow as CreateWorkflow40, Workflow as Workflow40 } from "@workglow/task-graph";
6074
- var modelSchema28 = TypeModel("model:TextRewriterTask");
5588
+ import { CreateWorkflow as CreateWorkflow38, Workflow as Workflow38 } from "@workglow/task-graph";
5589
+ var modelSchema26 = TypeModel("model:TextRewriterTask");
6075
5590
  var TextRewriterInputSchema = {
6076
5591
  type: "object",
6077
5592
  properties: {
6078
- text: TypeSingleOrArray({
5593
+ text: {
6079
5594
  type: "string",
6080
5595
  title: "Text",
6081
5596
  description: "The text to rewrite"
6082
- }),
5597
+ },
6083
5598
  prompt: {
6084
5599
  type: "string",
6085
5600
  title: "Prompt",
6086
5601
  description: "The prompt to direct the rewriting"
6087
5602
  },
6088
- model: modelSchema28
5603
+ model: modelSchema26
6089
5604
  },
6090
5605
  required: ["text", "prompt", "model"],
6091
5606
  additionalProperties: false
@@ -6093,12 +5608,12 @@ var TextRewriterInputSchema = {
6093
5608
  var TextRewriterOutputSchema = {
6094
5609
  type: "object",
6095
5610
  properties: {
6096
- text: TypeSingleOrArray({
5611
+ text: {
6097
5612
  type: "string",
6098
5613
  title: "Text",
6099
5614
  description: "The rewritten text",
6100
5615
  "x-stream": "append"
6101
- })
5616
+ }
6102
5617
  },
6103
5618
  required: ["text"],
6104
5619
  additionalProperties: false
@@ -6119,25 +5634,25 @@ class TextRewriterTask extends StreamingAiTask {
6119
5634
  var textRewriter = (input, config) => {
6120
5635
  return new TextRewriterTask({}, config).run(input);
6121
5636
  };
6122
- Workflow40.prototype.textRewriter = CreateWorkflow40(TextRewriterTask);
5637
+ Workflow38.prototype.textRewriter = CreateWorkflow38(TextRewriterTask);
6123
5638
 
6124
5639
  // 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({
5640
+ import { CreateWorkflow as CreateWorkflow39, Workflow as Workflow39 } from "@workglow/task-graph";
5641
+ var modelSchema27 = TypeModel("model:TextTranslationTask");
5642
+ var translationTextSchema = {
6128
5643
  type: "string",
6129
5644
  title: "Text",
6130
5645
  description: "The translated text",
6131
5646
  "x-stream": "replace"
6132
- });
5647
+ };
6133
5648
  var TextTranslationInputSchema = {
6134
5649
  type: "object",
6135
5650
  properties: {
6136
- text: TypeSingleOrArray({
5651
+ text: {
6137
5652
  type: "string",
6138
5653
  title: "Text",
6139
5654
  description: "The text to translate"
6140
- }),
5655
+ },
6141
5656
  source_lang: TypeLanguage({
6142
5657
  title: "Source Language",
6143
5658
  description: "The source language",
@@ -6150,7 +5665,7 @@ var TextTranslationInputSchema = {
6150
5665
  minLength: 2,
6151
5666
  maxLength: 2
6152
5667
  }),
6153
- model: modelSchema29
5668
+ model: modelSchema27
6154
5669
  },
6155
5670
  required: ["text", "source_lang", "target_lang", "model"],
6156
5671
  additionalProperties: false
@@ -6185,14 +5700,10 @@ class TextTranslationTask extends StreamingAiTask {
6185
5700
  var textTranslation = (input, config) => {
6186
5701
  return new TextTranslationTask({}, config).run(input);
6187
5702
  };
6188
- Workflow41.prototype.textTranslation = CreateWorkflow41(TextTranslationTask);
5703
+ Workflow39.prototype.textTranslation = CreateWorkflow39(TextTranslationTask);
6189
5704
 
6190
5705
  // src/task/TopicSegmenterTask.ts
6191
- import {
6192
- CreateWorkflow as CreateWorkflow42,
6193
- Task as Task16,
6194
- Workflow as Workflow42
6195
- } from "@workglow/task-graph";
5706
+ import { CreateWorkflow as CreateWorkflow40, Task as Task16, Workflow as Workflow40 } from "@workglow/task-graph";
6196
5707
  var SegmentationMethod = {
6197
5708
  HEURISTIC: "heuristic",
6198
5709
  EMBEDDING_SIMILARITY: "embedding-similarity",
@@ -6472,15 +5983,15 @@ class TopicSegmenterTask extends Task16 {
6472
5983
  var topicSegmenter = (input, config) => {
6473
5984
  return new TopicSegmenterTask({}, config).run(input);
6474
5985
  };
6475
- Workflow42.prototype.topicSegmenter = CreateWorkflow42(TopicSegmenterTask);
5986
+ Workflow40.prototype.topicSegmenter = CreateWorkflow40(TopicSegmenterTask);
6476
5987
 
6477
5988
  // src/task/UnloadModelTask.ts
6478
- import { CreateWorkflow as CreateWorkflow43, Workflow as Workflow43 } from "@workglow/task-graph";
6479
- var modelSchema30 = TypeModel("model");
5989
+ import { CreateWorkflow as CreateWorkflow41, Workflow as Workflow41 } from "@workglow/task-graph";
5990
+ var modelSchema28 = TypeModel("model");
6480
5991
  var UnloadModelInputSchema = {
6481
5992
  type: "object",
6482
5993
  properties: {
6483
- model: modelSchema30
5994
+ model: modelSchema28
6484
5995
  },
6485
5996
  required: ["model"],
6486
5997
  additionalProperties: false
@@ -6488,7 +5999,7 @@ var UnloadModelInputSchema = {
6488
5999
  var UnloadModelOutputSchema = {
6489
6000
  type: "object",
6490
6001
  properties: {
6491
- model: modelSchema30
6002
+ model: modelSchema28
6492
6003
  },
6493
6004
  required: ["model"],
6494
6005
  additionalProperties: false
@@ -6510,10 +6021,10 @@ class UnloadModelTask extends AiTask {
6510
6021
  var unloadModel = (input, config) => {
6511
6022
  return new UnloadModelTask({}, config).run(input);
6512
6023
  };
6513
- Workflow43.prototype.unloadModel = CreateWorkflow43(UnloadModelTask);
6024
+ Workflow41.prototype.unloadModel = CreateWorkflow41(UnloadModelTask);
6514
6025
 
6515
6026
  // src/task/VectorQuantizeTask.ts
6516
- import { CreateWorkflow as CreateWorkflow44, Task as Task17, Workflow as Workflow44 } from "@workglow/task-graph";
6027
+ import { CreateWorkflow as CreateWorkflow42, Task as Task17, Workflow as Workflow42 } from "@workglow/task-graph";
6517
6028
  import {
6518
6029
  normalizeNumberArray,
6519
6030
  TensorType,
@@ -6693,10 +6204,10 @@ class VectorQuantizeTask extends Task17 {
6693
6204
  var vectorQuantize = (input, config) => {
6694
6205
  return new VectorQuantizeTask({}, config).run(input);
6695
6206
  };
6696
- Workflow44.prototype.vectorQuantize = CreateWorkflow44(VectorQuantizeTask);
6207
+ Workflow42.prototype.vectorQuantize = CreateWorkflow42(VectorQuantizeTask);
6697
6208
 
6698
6209
  // src/task/VectorSimilarityTask.ts
6699
- import { CreateWorkflow as CreateWorkflow45, GraphAsTask, Workflow as Workflow45 } from "@workglow/task-graph";
6210
+ import { CreateWorkflow as CreateWorkflow43, GraphAsTask, Workflow as Workflow43 } from "@workglow/task-graph";
6700
6211
  import {
6701
6212
  cosineSimilarity,
6702
6213
  hammingSimilarity,
@@ -6802,208 +6313,11 @@ class VectorSimilarityTask extends GraphAsTask {
6802
6313
  var similarity = (input, config) => {
6803
6314
  return new VectorSimilarityTask({}, config).run(input);
6804
6315
  };
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
- }
6316
+ Workflow43.prototype.similarity = CreateWorkflow43(VectorSimilarityTask);
7002
6317
 
7003
6318
  // src/task/index.ts
7004
6319
  var registerAiTasks = () => {
7005
6320
  const tasks = [
7006
- AgentTask,
7007
6321
  BackgroundRemovalTask,
7008
6322
  ChunkToVectorTask,
7009
6323
  CountTokensTask,
@@ -7043,7 +6357,6 @@ var registerAiTasks = () => {
7043
6357
  TextRewriterTask,
7044
6358
  TextSummaryTask,
7045
6359
  TextTranslationTask,
7046
- ToolCallingTask,
7047
6360
  TopicSegmenterTask,
7048
6361
  UnloadModelTask,
7049
6362
  VectorQuantizeTask,
@@ -7055,14 +6368,8 @@ var registerAiTasks = () => {
7055
6368
  export {
7056
6369
  vectorStoreSearch,
7057
6370
  vectorQuantize,
7058
- userMessage,
7059
6371
  unloadModel,
7060
6372
  topicSegmenter,
7061
- toolSourceDefinitions,
7062
- toolMessage,
7063
- toolCalling,
7064
- toTextFlatMessages,
7065
- toOpenAIMessages,
7066
6373
  textTranslation,
7067
6374
  textSummary,
7068
6375
  textRewriter,
@@ -7074,12 +6381,12 @@ export {
7074
6381
  textEmbedding,
7075
6382
  textClassification,
7076
6383
  textChunker,
7077
- taskTypesToTools,
7078
6384
  structuredGeneration,
7079
6385
  structuralParser,
7080
6386
  similarity,
7081
6387
  setGlobalModelRepository,
7082
6388
  setAiProviderRegistry,
6389
+ resolveAiProviderGpuQueueConcurrency,
7083
6390
  reranker,
7084
6391
  registerAiTasks,
7085
6392
  queryExpander,
@@ -7087,27 +6394,19 @@ export {
7087
6394
  objectDetection,
7088
6395
  modelSearch,
7089
6396
  modelInfo,
7090
- isAllowedToolName,
7091
6397
  imageToText,
7092
6398
  imageSegmentation,
7093
6399
  imageEmbedding,
7094
6400
  imageClassification,
7095
- imageBlockFromDataUri,
7096
- imageBlock,
7097
6401
  hybridSearch,
7098
6402
  hierarchyJoin,
7099
6403
  hierarchicalChunker,
7100
- hasToolCalls,
7101
6404
  handLandmarker,
7102
6405
  getGlobalModelRepository,
7103
6406
  getAiProviderRegistry,
7104
6407
  gestureRecognizer,
7105
- findToolSource,
7106
- filterValidToolCalls,
7107
6408
  faceLandmarker,
7108
6409
  faceDetector,
7109
- executeToolCalls,
7110
- executeToolCall,
7111
6410
  downloadModel,
7112
6411
  documentEnricher,
7113
6412
  countTokens,
@@ -7115,13 +6414,7 @@ export {
7115
6414
  chunkVectorUpsert,
7116
6415
  chunkToVector,
7117
6416
  chunkRetrieval,
7118
- buildToolSources,
7119
- buildToolDescription,
7120
6417
  backgroundRemoval,
7121
- audioBlockFromDataUri,
7122
- audioBlock,
7123
- assistantMessage,
7124
- agent,
7125
6418
  VectorSimilarityTask,
7126
6419
  VectorQuantizeTask,
7127
6420
  UnloadModelTask,
@@ -7135,10 +6428,6 @@ export {
7135
6428
  TypeBoundingBox,
7136
6429
  TypeAudioInput,
7137
6430
  TopicSegmenterTask,
7138
- ToolDefinitionSchema,
7139
- ToolCallingTask,
7140
- ToolCallingOutputSchema,
7141
- ToolCallingInputSchema,
7142
6431
  TextTranslationTask,
7143
6432
  TextTranslationOutputSchema,
7144
6433
  TextTranslationInputSchema,
@@ -7178,6 +6467,7 @@ export {
7178
6467
  SimilarityFn,
7179
6468
  SegmentationMethod,
7180
6469
  RerankerTask,
6470
+ QueuedExecutionStrategy,
7181
6471
  QueuedAiProvider,
7182
6472
  QueryExpansionMethod,
7183
6473
  QueryExpanderTask,
@@ -7223,6 +6513,7 @@ export {
7223
6513
  FaceDetectorInputSchema,
7224
6514
  DownloadModelTask,
7225
6515
  DocumentEnricherTask,
6516
+ DirectExecutionStrategy,
7226
6517
  CountTokensTask,
7227
6518
  CountTokensOutputSchema,
7228
6519
  CountTokensInputSchema,
@@ -7240,10 +6531,7 @@ export {
7240
6531
  AiTask,
7241
6532
  AiProviderRegistry,
7242
6533
  AiProvider,
7243
- AiJob,
7244
- AgentTask,
7245
- AgentOutputSchema,
7246
- AgentInputSchema
6534
+ AiJob
7247
6535
  };
7248
6536
 
7249
- //# debugId=18D97536243F610A64756E2164756E21
6537
+ //# debugId=B0C9F29E92462AAF64756E2164756E21