@workglow/ai 0.2.7 → 0.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/dist/browser.js +887 -929
  2. package/dist/browser.js.map +15 -16
  3. package/dist/bun.js +887 -929
  4. package/dist/bun.js.map +15 -16
  5. package/dist/execution/QueuedExecutionStrategy.d.ts +14 -5
  6. package/dist/execution/QueuedExecutionStrategy.d.ts.map +1 -1
  7. package/dist/job/AiJob.d.ts +2 -0
  8. package/dist/job/AiJob.d.ts.map +1 -1
  9. package/dist/node.js +887 -929
  10. package/dist/node.js.map +15 -16
  11. package/dist/provider/AiProvider.d.ts +15 -0
  12. package/dist/provider/AiProvider.d.ts.map +1 -1
  13. package/dist/provider/AiProviderRegistry.d.ts +16 -2
  14. package/dist/provider/AiProviderRegistry.d.ts.map +1 -1
  15. package/dist/task/AiChatTask.d.ts +666 -0
  16. package/dist/task/AiChatTask.d.ts.map +1 -0
  17. package/dist/task/ChatMessage.d.ts +356 -0
  18. package/dist/task/ChatMessage.d.ts.map +1 -0
  19. package/dist/task/MessageConversion.d.ts +1 -9
  20. package/dist/task/MessageConversion.d.ts.map +1 -1
  21. package/dist/task/StructuredGenerationTask.d.ts +50 -3
  22. package/dist/task/StructuredGenerationTask.d.ts.map +1 -1
  23. package/dist/task/ToolCallingTask.d.ts +177 -10
  24. package/dist/task/ToolCallingTask.d.ts.map +1 -1
  25. package/dist/task/base/AiTask.d.ts.map +1 -1
  26. package/dist/task/index.d.ts +6 -7
  27. package/dist/task/index.d.ts.map +1 -1
  28. package/dist/worker.js +65 -97
  29. package/dist/worker.js.map +6 -6
  30. package/package.json +11 -11
  31. package/dist/task/AgentTask.d.ts +0 -541
  32. package/dist/task/AgentTask.d.ts.map +0 -1
  33. package/dist/task/AgentTypes.d.ts +0 -183
  34. package/dist/task/AgentTypes.d.ts.map +0 -1
  35. package/dist/task/AgentUtils.d.ts +0 -55
  36. package/dist/task/AgentUtils.d.ts.map +0 -1
package/dist/bun.js CHANGED
@@ -56,6 +56,19 @@ class AiProviderRegistry {
56
56
  }
57
57
  return this.defaultStrategy;
58
58
  }
59
+ createSession(providerName, model) {
60
+ const provider = this.providers.get(providerName);
61
+ if (!provider) {
62
+ throw new Error(`No provider found for "${providerName}". Register the provider before creating sessions.`);
63
+ }
64
+ return provider.createSession(model);
65
+ }
66
+ async disposeSession(providerName, sessionId) {
67
+ const provider = this.providers.get(providerName);
68
+ if (provider) {
69
+ await provider.disposeSession(sessionId);
70
+ }
71
+ }
59
72
  getProviderIdsForTask(taskType) {
60
73
  const taskMap = this.runFnRegistry.get(taskType);
61
74
  if (!taskMap)
@@ -69,9 +82,9 @@ class AiProviderRegistry {
69
82
  this.runFnRegistry.get(taskType).set(modelProvider, runFn);
70
83
  }
71
84
  registerAsWorkerRunFn(modelProvider, taskType) {
72
- const workerFn = async (input, model, update_progress, signal, outputSchema) => {
85
+ const workerFn = async (input, model, update_progress, signal, outputSchema, sessionId) => {
73
86
  const workerManager = globalServiceRegistry.get(WORKER_MANAGER);
74
- const result = await workerManager.callWorkerFunction(modelProvider, taskType, [input, model, outputSchema], {
87
+ const result = await workerManager.callWorkerFunction(modelProvider, taskType, [input, model, outputSchema, sessionId], {
75
88
  signal,
76
89
  onProgress: update_progress
77
90
  });
@@ -86,9 +99,9 @@ class AiProviderRegistry {
86
99
  this.streamFnRegistry.get(taskType).set(modelProvider, streamFn);
87
100
  }
88
101
  registerAsWorkerStreamFn(modelProvider, taskType) {
89
- const streamFn = async function* (input, model, signal, outputSchema) {
102
+ const streamFn = async function* (input, model, signal, outputSchema, sessionId) {
90
103
  const workerManager = globalServiceRegistry.get(WORKER_MANAGER);
91
- yield* workerManager.callWorkerStreamFunction(modelProvider, taskType, [input, model, outputSchema], { signal });
104
+ yield* workerManager.callWorkerStreamFunction(modelProvider, taskType, [input, model, outputSchema, sessionId], { signal });
92
105
  };
93
106
  this.registerStreamFn(modelProvider, taskType, streamFn);
94
107
  }
@@ -216,7 +229,7 @@ class AiJob extends Job {
216
229
  const timeoutMs = resolveAiJobTimeoutMs(input.aiProvider, input.timeoutMs);
217
230
  const timeoutSignal = AbortSignal.timeout(timeoutMs);
218
231
  const combinedSignal = AbortSignal.any([context.signal, timeoutSignal]);
219
- return await fn(input.taskInput, model, context.updateProgress, combinedSignal, input.outputSchema);
232
+ return await fn(input.taskInput, model, context.updateProgress, combinedSignal, input.outputSchema, input.sessionId);
220
233
  };
221
234
  const runFnPromise = runFn();
222
235
  return await Promise.race([runFnPromise, abortPromise]);
@@ -244,7 +257,7 @@ class AiJob extends Job {
244
257
  const timeoutSignal = AbortSignal.timeout(timeoutMs);
245
258
  const combinedSignal = AbortSignal.any([context.signal, timeoutSignal]);
246
259
  try {
247
- for await (const event of streamFn(input.taskInput, model, combinedSignal, input.outputSchema)) {
260
+ for await (const event of streamFn(input.taskInput, model, combinedSignal, input.outputSchema, input.sessionId)) {
248
261
  if (event.type === "finish") {
249
262
  lastFinishData = event.data;
250
263
  }
@@ -309,6 +322,7 @@ class QueuedExecutionStrategy {
309
322
  concurrency;
310
323
  autoCreate;
311
324
  initPromise = null;
325
+ limiter;
312
326
  constructor(queueName, concurrency = 1, autoCreate = true) {
313
327
  this.queueName = queueName;
314
328
  this.concurrency = concurrency;
@@ -346,8 +360,42 @@ class QueuedExecutionStrategy {
346
360
  }
347
361
  abort() {}
348
362
  async* executeStream(jobInput, context, runnerId) {
349
- const result = await this.execute(jobInput, context, runnerId);
350
- yield { type: "finish", data: result };
363
+ if (context.signal.aborted) {
364
+ throw context.signal.reason ?? new AbortSignalJobError2("The operation was aborted");
365
+ }
366
+ await this.ensureQueue();
367
+ const limiter = this.limiter;
368
+ if (!limiter) {
369
+ throw new TaskConfigurationError(`QueuedExecutionStrategy: limiter was not initialized for queue "${this.queueName}"`);
370
+ }
371
+ await this.acquireLimiterSlot(limiter, context.signal);
372
+ try {
373
+ const job = new AiJob({
374
+ queueName: jobInput.aiProvider,
375
+ jobRunId: runnerId,
376
+ input: jobInput
377
+ });
378
+ yield* job.executeStream(jobInput, {
379
+ signal: context.signal,
380
+ updateProgress: context.updateProgress
381
+ });
382
+ } finally {
383
+ await limiter.recordJobCompletion();
384
+ }
385
+ }
386
+ async acquireLimiterSlot(limiter, signal) {
387
+ const poll = async () => {
388
+ while (!await limiter.canProceed()) {
389
+ if (signal.aborted) {
390
+ throw signal.reason ?? new AbortSignalJobError2("The operation was aborted");
391
+ }
392
+ const next = await limiter.getNextAvailableTime();
393
+ const delay = Math.max(0, next.getTime() - Date.now());
394
+ await new Promise((resolve) => setTimeout(resolve, Math.min(delay, 50)));
395
+ }
396
+ };
397
+ await poll();
398
+ await limiter.recordJobStart();
351
399
  }
352
400
  ensureQueue() {
353
401
  if (!this.initPromise) {
@@ -365,6 +413,7 @@ class QueuedExecutionStrategy {
365
413
  if (!existing.server.isRunning()) {
366
414
  await existing.server.start();
367
415
  }
416
+ this.limiter = existing.server.limiter;
368
417
  return existing;
369
418
  }
370
419
  if (!this.autoCreate) {
@@ -372,10 +421,11 @@ class QueuedExecutionStrategy {
372
421
  }
373
422
  const storage = new InMemoryQueueStorage(this.queueName);
374
423
  await storage.setupDatabase();
424
+ this.limiter = new ConcurrencyLimiter(this.concurrency);
375
425
  const server = new JobQueueServer(AiJob, {
376
426
  storage,
377
427
  queueName: this.queueName,
378
- limiter: new ConcurrencyLimiter(this.concurrency)
428
+ limiter: this.limiter
379
429
  });
380
430
  const client = new JobQueueClient({
381
431
  storage,
@@ -399,6 +449,7 @@ class QueuedExecutionStrategy {
399
449
  if (!raced.server.isRunning()) {
400
450
  await raced.server.start();
401
451
  }
452
+ this.limiter = raced.server.limiter;
402
453
  return raced;
403
454
  }
404
455
  }
@@ -760,6 +811,10 @@ class AiProvider {
760
811
  }
761
812
  async onInitialize(_options) {}
762
813
  async dispose() {}
814
+ createSession(_model) {
815
+ return crypto.randomUUID();
816
+ }
817
+ async disposeSession(_sessionId) {}
763
818
  async afterRegister(_options) {}
764
819
  }
765
820
 
@@ -783,74 +838,8 @@ class QueuedAiProvider extends AiProvider {
783
838
  // src/task/index.ts
784
839
  import { TaskRegistry } from "@workglow/task-graph";
785
840
 
786
- // src/task/AgentTask.ts
787
- import { CreateWorkflow as CreateWorkflow2, Task as Task2, Workflow as Workflow2 } from "@workglow/task-graph";
788
- import { getLogger as getLogger4 } from "@workglow/util";
789
-
790
- // src/task/AgentTypes.ts
791
- import { parseDataUri } from "@workglow/util/media";
792
- function imageBlock(mimeType, data) {
793
- return { type: "image", mimeType, data };
794
- }
795
- function audioBlock(mimeType, data) {
796
- return { type: "audio", mimeType, data };
797
- }
798
- function imageBlockFromDataUri(dataUri) {
799
- const { mimeType, base64 } = parseDataUri(dataUri);
800
- return { type: "image", mimeType, data: base64 };
801
- }
802
- function audioBlockFromDataUri(dataUri) {
803
- const { mimeType, base64 } = parseDataUri(dataUri);
804
- return { type: "audio", mimeType, data: base64 };
805
- }
806
- function userMessage(prompt) {
807
- return { role: "user", content: prompt };
808
- }
809
- function assistantMessage(text, toolCalls) {
810
- const content = [];
811
- if (text) {
812
- content.push({ type: "text", text });
813
- }
814
- if (toolCalls) {
815
- for (const tc of toolCalls) {
816
- content.push({
817
- type: "tool_use",
818
- id: tc.id,
819
- name: tc.name,
820
- input: tc.input
821
- });
822
- }
823
- }
824
- return { role: "assistant", content };
825
- }
826
- function toolMessage(results) {
827
- return {
828
- role: "tool",
829
- content: results.map((r) => {
830
- const jsonText = JSON.stringify(r.output);
831
- const content = r.mediaContent && r.mediaContent.length > 0 ? [{ type: "text", text: jsonText }, ...r.mediaContent] : jsonText;
832
- return {
833
- type: "tool_result",
834
- tool_use_id: r.toolCallId,
835
- content,
836
- is_error: r.isError || undefined
837
- };
838
- })
839
- };
840
- }
841
- function toolSourceDefinitions(sources) {
842
- return sources.map((s) => s.definition);
843
- }
844
- function findToolSource(sources, name) {
845
- return sources.find((s) => s.definition.name === name);
846
- }
847
-
848
- // src/task/AgentUtils.ts
849
- import { getTaskConstructors as getTaskConstructors2, TaskAbortedError } from "@workglow/task-graph";
850
- import { getLogger as getLogger3 } from "@workglow/util";
851
-
852
- // src/task/ToolCallingTask.ts
853
- import { CreateWorkflow, getTaskConstructors, Workflow } from "@workglow/task-graph";
841
+ // src/task/AiChatTask.ts
842
+ import { TaskConfigSchema as TaskConfigSchema2 } from "@workglow/task-graph";
854
843
 
855
844
  // src/task/base/AiTaskSchemas.ts
856
845
  var TypeLanguage = (annotations = {}) => ({
@@ -1100,6 +1089,10 @@ class AiTask extends Task {
1100
1089
  jobInput.outputSchema = taskOutputSchema;
1101
1090
  }
1102
1091
  }
1092
+ const sessionId = input.sessionId;
1093
+ if (sessionId) {
1094
+ jobInput.sessionId = sessionId;
1095
+ }
1103
1096
  return jobInput;
1104
1097
  }
1105
1098
  async createJob(input, queueName) {
@@ -1226,672 +1219,356 @@ class StreamingAiTask extends AiTask {
1226
1219
  }
1227
1220
  }
1228
1221
 
1229
- // src/task/ToolCallingTask.ts
1230
- function taskTypesToTools(taskNames, registry) {
1231
- const constructors = getTaskConstructors(registry);
1232
- return taskNames.map((name) => {
1233
- const ctor = constructors.get(name);
1234
- if (!ctor) {
1235
- throw new Error(`taskTypesToTools: Unknown task type "${name}" \u2014 not found in task constructors registry (ServiceRegistry: ${registry ? "custom" : "default"})`);
1236
- }
1237
- const configSchema = "configSchema" in ctor && typeof ctor.configSchema === "function" ? ctor.configSchema() : undefined;
1238
- return {
1239
- name: ctor.type,
1240
- description: ctor.description ?? "",
1241
- inputSchema: ctor.inputSchema(),
1242
- outputSchema: ctor.outputSchema(),
1243
- ...configSchema ? { configSchema } : {},
1244
- taskType: name
1245
- };
1246
- });
1247
- }
1248
- var ToolDefinitionSchema = {
1222
+ // src/task/ChatMessage.ts
1223
+ var ContentBlockTextSchema = {
1249
1224
  type: "object",
1250
1225
  properties: {
1251
- name: {
1252
- type: "string",
1253
- title: "Name",
1254
- description: "The tool name"
1255
- },
1256
- description: {
1257
- type: "string",
1258
- title: "Description",
1259
- description: "A description of what the tool does"
1260
- },
1261
- inputSchema: {
1262
- type: "object",
1263
- title: "Input Schema",
1264
- description: "JSON Schema describing the tool's input parameters",
1265
- additionalProperties: true
1266
- },
1267
- outputSchema: {
1268
- type: "object",
1269
- title: "Output Schema",
1270
- description: "JSON Schema describing what the tool returns",
1271
- additionalProperties: true
1272
- },
1273
- configSchema: {
1274
- type: "object",
1275
- title: "Config Schema",
1276
- description: "JSON Schema describing the task's configuration options (not sent to the LLM)",
1277
- additionalProperties: true
1226
+ type: { type: "string", enum: ["text"] },
1227
+ text: { type: "string" }
1228
+ },
1229
+ required: ["type", "text"],
1230
+ additionalProperties: false
1231
+ };
1232
+ var ContentBlockImageSchema = {
1233
+ type: "object",
1234
+ properties: {
1235
+ type: { type: "string", enum: ["image"] },
1236
+ mimeType: { type: "string" },
1237
+ data: { type: "string" }
1238
+ },
1239
+ required: ["type", "mimeType", "data"],
1240
+ additionalProperties: false
1241
+ };
1242
+ var ContentBlockToolUseSchema = {
1243
+ type: "object",
1244
+ properties: {
1245
+ type: { type: "string", enum: ["tool_use"] },
1246
+ id: { type: "string" },
1247
+ name: { type: "string" },
1248
+ input: { type: "object", additionalProperties: true }
1249
+ },
1250
+ required: ["type", "id", "name", "input"],
1251
+ additionalProperties: false
1252
+ };
1253
+ var ContentBlockToolResultSchema = {
1254
+ type: "object",
1255
+ properties: {
1256
+ type: { type: "string", enum: ["tool_result"] },
1257
+ tool_use_id: { type: "string" },
1258
+ content: {
1259
+ type: "array",
1260
+ items: { $ref: "#/definitions/ContentBlock" }
1278
1261
  },
1279
- config: {
1280
- type: "object",
1281
- title: "Config",
1282
- description: "Concrete configuration values for the backing task (not sent to the LLM)",
1283
- additionalProperties: true
1262
+ is_error: { type: "boolean" }
1263
+ },
1264
+ required: ["type", "tool_use_id", "content"],
1265
+ additionalProperties: false
1266
+ };
1267
+ var ContentBlockSchema = {
1268
+ oneOf: [
1269
+ ContentBlockTextSchema,
1270
+ ContentBlockImageSchema,
1271
+ ContentBlockToolUseSchema,
1272
+ ContentBlockToolResultSchema
1273
+ ],
1274
+ definitions: {
1275
+ ContentBlock: {
1276
+ oneOf: [
1277
+ ContentBlockTextSchema,
1278
+ ContentBlockImageSchema,
1279
+ ContentBlockToolUseSchema,
1280
+ ContentBlockToolResultSchema
1281
+ ]
1284
1282
  }
1285
1283
  },
1286
- required: ["name", "description", "inputSchema"],
1287
- additionalProperties: true
1284
+ title: "ContentBlock",
1285
+ description: "A single content block within a chat message"
1288
1286
  };
1289
- var ToolCallSchema = {
1287
+ var ChatMessageSchema = {
1290
1288
  type: "object",
1291
1289
  properties: {
1292
- id: {
1293
- type: "string",
1294
- title: "ID",
1295
- description: "Unique identifier for this tool call"
1296
- },
1297
- name: {
1290
+ role: { type: "string", enum: ["user", "assistant", "tool", "system"] },
1291
+ content: {
1292
+ type: "array",
1293
+ items: ContentBlockSchema
1294
+ }
1295
+ },
1296
+ required: ["role", "content"],
1297
+ additionalProperties: false,
1298
+ title: "ChatMessage",
1299
+ description: "A single chat message with role and structured content blocks"
1300
+ };
1301
+ function isContentBlock(value) {
1302
+ if (!value || typeof value !== "object")
1303
+ return false;
1304
+ const v = value;
1305
+ switch (v.type) {
1306
+ case "text":
1307
+ return typeof v.text === "string";
1308
+ case "image":
1309
+ return typeof v.mimeType === "string" && typeof v.data === "string";
1310
+ case "tool_use":
1311
+ return typeof v.id === "string" && typeof v.name === "string" && v.input !== null && typeof v.input === "object";
1312
+ case "tool_result":
1313
+ return typeof v.tool_use_id === "string" && Array.isArray(v.content) && v.content.every(isContentBlock);
1314
+ default:
1315
+ return false;
1316
+ }
1317
+ }
1318
+ function isChatMessage(value) {
1319
+ if (!value || typeof value !== "object")
1320
+ return false;
1321
+ const v = value;
1322
+ const validRole = v.role === "user" || v.role === "assistant" || v.role === "tool" || v.role === "system";
1323
+ return validRole && Array.isArray(v.content) && v.content.every(isContentBlock);
1324
+ }
1325
+ function textMessage(role, text) {
1326
+ return { role, content: [{ type: "text", text }] };
1327
+ }
1328
+
1329
+ // src/task/AiChatTask.ts
1330
+ import { resolveHumanConnector } from "@workglow/util";
1331
+ var modelSchema = TypeModel("model:AiChatTask");
1332
+ var chatConnectorContentSchema = {
1333
+ type: "object",
1334
+ properties: {
1335
+ content: {
1298
1336
  type: "string",
1299
- title: "Name",
1300
- description: "The name of the tool to invoke"
1301
- },
1302
- input: {
1303
- type: "object",
1304
- title: "Input",
1305
- description: "The input arguments for the tool call",
1306
- additionalProperties: true
1337
+ title: "Message",
1338
+ description: "Your reply (leave blank to end the conversation)"
1307
1339
  }
1308
1340
  },
1309
- required: ["id", "name", "input"],
1310
1341
  additionalProperties: false
1311
1342
  };
1312
- var modelSchema = TypeModel("model:ToolCallingTask");
1313
- var ToolCallingInputSchema = {
1343
+ var AiChatInputSchema = {
1314
1344
  type: "object",
1315
1345
  properties: {
1316
1346
  model: modelSchema,
1317
1347
  prompt: {
1318
1348
  oneOf: [
1319
- { type: "string", title: "Prompt", description: "The prompt to send to the model" },
1349
+ { type: "string", title: "Prompt", description: "The initial user message" },
1320
1350
  {
1321
1351
  type: "array",
1322
1352
  title: "Prompt",
1323
- description: "The prompt as an array of strings or content blocks",
1324
- items: {
1325
- oneOf: [
1326
- { type: "string" },
1327
- {
1328
- type: "object",
1329
- properties: {
1330
- type: { type: "string", enum: ["text", "image", "audio"] }
1331
- },
1332
- required: ["type"],
1333
- additionalProperties: true
1334
- }
1335
- ]
1336
- }
1353
+ description: "The initial user message as structured content blocks",
1354
+ items: ContentBlockSchema
1337
1355
  }
1338
1356
  ],
1339
1357
  title: "Prompt",
1340
- description: "The prompt to send to the model"
1341
- },
1342
- systemPrompt: {
1343
- type: "string",
1344
- title: "System Prompt",
1345
- description: "Optional system instructions for the model"
1358
+ description: "The first user message to start the conversation"
1346
1359
  },
1347
1360
  messages: {
1348
1361
  type: "array",
1349
1362
  title: "Messages",
1350
- description: "Full conversation history for multi-turn interactions. When provided, used instead of prompt to construct the messages array sent to the provider.",
1351
- items: {
1352
- type: "object",
1353
- properties: {
1354
- role: { type: "string", enum: ["user", "assistant", "tool"] },
1355
- content: {}
1356
- },
1357
- required: ["role", "content"],
1358
- additionalProperties: true
1359
- }
1363
+ description: "Conversation history (managed internally by the chat loop; not a user-facing input)",
1364
+ items: ChatMessageSchema,
1365
+ "x-ui-hidden": true
1360
1366
  },
1361
- tools: {
1362
- type: "array",
1363
- format: "tasks",
1364
- title: "Tools",
1365
- description: "Tool definitions available for the model to call",
1366
- items: {
1367
- oneOf: [
1368
- { type: "string", format: "tasks", description: "Task type name" },
1369
- ToolDefinitionSchema
1370
- ]
1371
- }
1372
- },
1373
- toolChoice: {
1367
+ systemPrompt: {
1374
1368
  type: "string",
1375
- title: "Tool Choice",
1376
- description: 'Controls tool selection: "auto" (model decides), "none" (no tools), "required" (must call a tool), or a specific tool name',
1377
- "x-ui-group": "Configuration"
1369
+ title: "System Prompt",
1370
+ description: "Optional system instructions for the model"
1378
1371
  },
1379
1372
  maxTokens: {
1380
1373
  type: "number",
1381
1374
  title: "Max Tokens",
1382
- description: "The maximum number of tokens to generate",
1375
+ description: "Per-turn token limit",
1383
1376
  minimum: 1,
1384
1377
  "x-ui-group": "Configuration"
1385
1378
  },
1386
1379
  temperature: {
1387
1380
  type: "number",
1388
1381
  title: "Temperature",
1389
- description: "The temperature to use for sampling",
1382
+ description: "Sampling temperature",
1390
1383
  minimum: 0,
1391
1384
  maximum: 2,
1392
1385
  "x-ui-group": "Configuration"
1386
+ },
1387
+ maxIterations: {
1388
+ type: "number",
1389
+ title: "Max Iterations",
1390
+ description: "Safety cap on conversation turns",
1391
+ minimum: 1,
1392
+ default: 100,
1393
+ "x-ui-group": "Configuration"
1393
1394
  }
1394
1395
  },
1395
- required: ["model", "prompt", "tools"],
1396
+ required: ["model", "prompt"],
1396
1397
  additionalProperties: false
1397
1398
  };
1398
- var ToolCallingOutputSchema = {
1399
+ var AiChatOutputSchema = {
1399
1400
  type: "object",
1400
1401
  properties: {
1401
1402
  text: {
1402
1403
  type: "string",
1403
1404
  title: "Text",
1404
- description: "Any text content generated by the model",
1405
+ description: "Last assistant response",
1405
1406
  "x-stream": "append"
1406
1407
  },
1407
- toolCalls: {
1408
+ messages: {
1408
1409
  type: "array",
1409
- items: ToolCallSchema,
1410
- title: "Tool Calls",
1411
- description: "Tool calls requested by the model",
1410
+ title: "Messages",
1411
+ description: "Full conversation history",
1412
+ items: ChatMessageSchema,
1412
1413
  "x-stream": "object"
1414
+ },
1415
+ iterations: {
1416
+ type: "number",
1417
+ title: "Iterations",
1418
+ description: "Number of completed turns"
1413
1419
  }
1414
1420
  },
1415
- required: ["text", "toolCalls"],
1421
+ required: ["text", "messages", "iterations"],
1416
1422
  additionalProperties: false
1417
1423
  };
1418
1424
 
1419
- class ToolCallingTask extends StreamingAiTask {
1420
- static type = "ToolCallingTask";
1421
- static category = "AI Text Model";
1422
- static title = "Tool Calling";
1423
- static description = "Sends a prompt with tool definitions to a language model and returns text along with any tool calls the model requests";
1425
+ class AiChatTask extends StreamingAiTask {
1426
+ static type = "AiChatTask";
1427
+ static category = "AI Chat";
1428
+ static title = "AI Chat";
1429
+ static description = "Multi-turn chat with a language model, using a human connector to collect user input between turns.";
1430
+ static cacheable = false;
1431
+ static configSchema() {
1432
+ return {
1433
+ type: "object",
1434
+ properties: {
1435
+ ...TaskConfigSchema2["properties"]
1436
+ },
1437
+ additionalProperties: false
1438
+ };
1439
+ }
1424
1440
  static inputSchema() {
1425
- return ToolCallingInputSchema;
1441
+ return AiChatInputSchema;
1426
1442
  }
1427
1443
  static outputSchema() {
1428
- return ToolCallingOutputSchema;
1444
+ return AiChatOutputSchema;
1429
1445
  }
1430
- }
1431
- var toolCalling = (input, config) => {
1432
- return new ToolCallingTask(config).run(input);
1433
- };
1434
- Workflow.prototype.toolCalling = CreateWorkflow(ToolCallingTask);
1435
-
1436
- // src/task/AgentUtils.ts
1437
- function resolveToolConfig(toolName, config, taskConfigSchema) {
1438
- if (config && !taskConfigSchema) {
1439
- getLogger3().warn(`AgentTask: Tool "${toolName}" provided config but task has no configSchema \u2014 config ignored`);
1440
- return {};
1446
+ _sessionId;
1447
+ async getJobInput(input) {
1448
+ const model = input.model;
1449
+ if (!this._sessionId) {
1450
+ this._sessionId = getAiProviderRegistry().createSession(model.provider, model);
1451
+ }
1452
+ return {
1453
+ taskType: "AiChatTask",
1454
+ aiProvider: model.provider,
1455
+ taskInput: input,
1456
+ sessionId: this._sessionId
1457
+ };
1441
1458
  }
1442
- return config;
1443
- }
1444
- function buildToolSources(tools, registry) {
1445
- if (!tools || tools.length === 0)
1446
- return [];
1447
- const stringNames = tools.filter((t) => typeof t === "string");
1448
- const resolvedDefs = new Map(taskTypesToTools(stringNames, registry).map((d) => [d.taskType, d]));
1449
- const constructors = getTaskConstructors2(registry);
1450
- const sources = [];
1451
- for (const tool of tools) {
1452
- if (typeof tool === "string") {
1453
- const def = resolvedDefs.get(tool);
1454
- if (def) {
1455
- const { taskType, ...definition } = def;
1456
- sources.push({
1457
- type: "registry",
1458
- definition,
1459
- taskType
1460
- });
1461
- }
1462
- } else if (tool.type === "function" || !tool.type && tool.execute) {
1463
- if (!tool.execute) {
1464
- getLogger3().warn(`AgentTask: Tool "${tool.name}" has type "function" but no execute function \u2014 will throw on invocation`);
1465
- }
1466
- const { execute, configSchema: _cs, config: _c, type: _t, ...definition } = tool;
1467
- sources.push({
1468
- type: "function",
1469
- definition,
1470
- run: execute ?? (async () => {
1471
- throw new Error(`No execute function for tool "${tool.name}"`);
1472
- })
1459
+ async* executeStream(input, context) {
1460
+ this._sessionId = undefined;
1461
+ const model = input.model;
1462
+ if (!model || typeof model !== "object") {
1463
+ throw new Error("AiChatTask: model was not resolved to ModelConfig");
1464
+ }
1465
+ const connector = resolveHumanConnector(context);
1466
+ const history = [];
1467
+ if (input.systemPrompt) {
1468
+ history.push({ role: "system", content: [{ type: "text", text: input.systemPrompt }] });
1469
+ }
1470
+ const firstUserBlocks = typeof input.prompt === "string" ? [{ type: "text", text: input.prompt }] : input.prompt;
1471
+ history.push({ role: "user", content: firstUserBlocks });
1472
+ const workingInput = { ...input, messages: history };
1473
+ await this.getJobInput(workingInput);
1474
+ const strategy = getAiProviderRegistry().getStrategy(model);
1475
+ const maxIterations = input.maxIterations ?? 100;
1476
+ if (context.resourceScope && this._sessionId) {
1477
+ const sessionId = this._sessionId;
1478
+ context.resourceScope.register(`ai:session:${sessionId}`, async () => {
1479
+ await getAiProviderRegistry().disposeSession(model.provider, sessionId);
1473
1480
  });
1474
- } else if (tool.type === "task") {
1475
- const ctor = constructors.get(tool.name);
1476
- if (!ctor) {
1477
- getLogger3().warn(`AgentTask: Tool "${tool.name}" has type "task" but is not in TaskRegistry \u2014 will throw on invocation`);
1478
- const { execute: _e, configSchema: _cs, config: _c, type: _t, ...definition } = tool;
1479
- sources.push({
1480
- type: "function",
1481
- definition,
1482
- run: async () => {
1483
- throw new Error(`Task "${tool.name}" not found in TaskRegistry`);
1484
- }
1485
- });
1486
- } else {
1487
- const safeConfig = resolveToolConfig(tool.name, tool.config, ctor.configSchema?.());
1488
- const { execute: _e, configSchema: _cs, config: _c, type: _t, ...definition } = tool;
1489
- sources.push({
1490
- type: "registry",
1491
- definition,
1492
- taskType: tool.name,
1493
- config: safeConfig
1494
- });
1495
- }
1496
- } else {
1497
- const ctor = constructors.get(tool.name);
1498
- if (ctor) {
1499
- const safeConfig = resolveToolConfig(tool.name, tool.config, ctor.configSchema?.());
1500
- const { execute: _e, configSchema: _cs, config: _c, type: _t, ...definition } = tool;
1501
- sources.push({
1502
- type: "registry",
1503
- definition,
1504
- taskType: tool.name,
1505
- config: safeConfig
1506
- });
1507
- } else {
1508
- const { execute: _e, configSchema: _cs, config: _c, type: _t, ...definition } = tool;
1509
- sources.push({
1510
- type: "function",
1511
- definition,
1512
- run: async () => {
1513
- throw new Error(`No executor registered for tool "${tool.name}"`);
1514
- }
1515
- });
1516
- }
1517
1481
  }
1518
- }
1519
- return sources;
1520
- }
1521
- async function executeToolCall(toolCall, sources, context, hooks) {
1522
- const source = findToolSource(sources, toolCall.name);
1523
- if (!source) {
1524
- getLogger3().warn(`AgentTask: Unknown tool "${toolCall.name}" \u2014 not found in tool sources`);
1525
- return {
1526
- toolCallId: toolCall.id,
1527
- toolName: toolCall.name,
1528
- output: { error: `Unknown tool: ${toolCall.name}` },
1529
- isError: true
1482
+ yield {
1483
+ type: "object-delta",
1484
+ port: "messages",
1485
+ objectDelta: [...history]
1530
1486
  };
1531
- }
1532
- let effectiveCall = toolCall;
1533
- if (hooks?.beforeToolCall) {
1534
- const decision = await hooks.beforeToolCall(toolCall, source);
1535
- if (decision.action === "deny") {
1536
- return {
1537
- toolCallId: toolCall.id,
1538
- toolName: toolCall.name,
1539
- output: { error: decision.reason ?? "Tool call denied by hook" },
1540
- isError: true
1541
- };
1542
- }
1543
- if (decision.action === "modify") {
1544
- effectiveCall = { ...toolCall, input: decision.input };
1545
- }
1546
- }
1547
- try {
1548
- let output;
1549
- switch (source.type) {
1550
- case "registry": {
1551
- const ctor = getTaskConstructors2(context.registry).get(source.taskType);
1552
- if (!ctor) {
1553
- throw new Error(`Task type "${source.taskType}" not found in TaskRegistry`);
1487
+ let iterations = 0;
1488
+ let lastAssistantText = "";
1489
+ for (let turn = 0;turn < maxIterations; turn++) {
1490
+ const perTurnInput = { ...input, messages: [...history] };
1491
+ const turnJobInput = await this.getJobInput(perTurnInput);
1492
+ let assistantText = "";
1493
+ for await (const event of strategy.executeStream(turnJobInput, context, this.runConfig.runnerId)) {
1494
+ if (event.type === "text-delta") {
1495
+ assistantText += event.textDelta;
1496
+ yield {
1497
+ ...event,
1498
+ port: event.port ?? "text"
1499
+ };
1500
+ } else if (event.type === "finish") {} else {
1501
+ yield event;
1554
1502
  }
1555
- const taskConfig = source.config ?? {};
1556
- const task = context.own(new ctor({}, taskConfig));
1557
- output = await task.run(effectiveCall.input) ?? {};
1558
- break;
1559
1503
  }
1560
- case "function": {
1561
- output = await source.run(effectiveCall.input);
1504
+ iterations++;
1505
+ lastAssistantText = assistantText;
1506
+ const assistantMsg = {
1507
+ role: "assistant",
1508
+ content: [{ type: "text", text: assistantText }]
1509
+ };
1510
+ history.push(assistantMsg);
1511
+ yield {
1512
+ type: "object-delta",
1513
+ port: "messages",
1514
+ objectDelta: [assistantMsg]
1515
+ };
1516
+ const request = {
1517
+ requestId: crypto.randomUUID(),
1518
+ targetHumanId: "default",
1519
+ kind: "elicit",
1520
+ message: "",
1521
+ contentSchema: chatConnectorContentSchema,
1522
+ contentData: undefined,
1523
+ expectsResponse: true,
1524
+ mode: "multi-turn",
1525
+ metadata: { iteration: turn, taskId: this.id }
1526
+ };
1527
+ const response = await connector.send(request, context.signal);
1528
+ if (response.action === "cancel" || response.action === "decline")
1562
1529
  break;
1530
+ const raw = response.content?.content;
1531
+ let userContent;
1532
+ if (typeof raw === "string") {
1533
+ const text = raw.trim();
1534
+ userContent = text.length > 0 ? [{ type: "text", text: raw }] : [];
1535
+ } else if (Array.isArray(raw)) {
1536
+ userContent = raw;
1537
+ } else {
1538
+ userContent = [];
1563
1539
  }
1540
+ if (userContent.length === 0)
1541
+ break;
1542
+ const userMsg = { role: "user", content: userContent };
1543
+ history.push(userMsg);
1544
+ yield {
1545
+ type: "object-delta",
1546
+ port: "messages",
1547
+ objectDelta: [userMsg]
1548
+ };
1564
1549
  }
1565
- let result = {
1566
- toolCallId: toolCall.id,
1567
- toolName: toolCall.name,
1568
- output,
1569
- isError: false
1570
- };
1571
- if (hooks?.afterToolCall) {
1572
- result = await hooks.afterToolCall(toolCall, result);
1573
- }
1574
- return result;
1575
- } catch (err) {
1576
- const error = err instanceof Error ? err : new Error(String(err));
1577
- if (hooks?.onToolError) {
1578
- const action = await hooks.onToolError(toolCall, error);
1579
- if (action.action === "result") {
1580
- return {
1581
- toolCallId: toolCall.id,
1582
- toolName: toolCall.name,
1583
- output: action.output,
1584
- isError: false
1585
- };
1550
+ yield {
1551
+ type: "finish",
1552
+ data: {
1553
+ text: lastAssistantText,
1554
+ messages: [...history],
1555
+ iterations
1586
1556
  }
1587
- }
1588
- getLogger3().warn(`AgentTask: Tool "${toolCall.name}" failed: ${error.message}`);
1589
- return {
1590
- toolCallId: toolCall.id,
1591
- toolName: toolCall.name,
1592
- output: { error: error.message },
1593
- isError: true
1594
1557
  };
1595
1558
  }
1596
- }
1597
- async function executeToolCalls(toolCalls, sources, context, hooks, maxConcurrency = 5) {
1598
- const calls = toolCalls;
1599
- if (calls.length === 0)
1600
- return [];
1601
- const concurrency = Math.max(1, Math.min(maxConcurrency, calls.length));
1602
- const results = new Array(calls.length);
1603
- let cursor = 0;
1604
- const workers = Array.from({ length: concurrency }, async () => {
1605
- while (true) {
1606
- if (context.signal.aborted) {
1607
- throw context.signal.reason ?? new TaskAbortedError("The operation was aborted");
1608
- }
1609
- const position = cursor;
1610
- cursor += 1;
1611
- if (position >= calls.length)
1612
- return;
1613
- results[position] = await executeToolCall(calls[position], sources, context, hooks);
1614
- }
1615
- });
1616
- await Promise.all(workers);
1617
- return results;
1618
- }
1619
- function hasToolCalls(toolCalls) {
1620
- return toolCalls !== undefined && toolCalls.length > 0;
1621
- }
1622
- function countAssistantToolUses(messages) {
1623
- let n = 0;
1624
- for (const m of messages) {
1625
- if (m.role !== "assistant")
1626
- continue;
1627
- for (const block of m.content) {
1628
- if (block.type === "tool_use")
1629
- n += 1;
1630
- }
1631
- }
1632
- return n;
1633
- }
1634
-
1635
- // src/task/AgentTask.ts
1636
- var MAX_CONTEXT_MESSAGES = 1000;
1637
- var modelSchema2 = TypeModel("model:ToolCallingTask");
1638
- var AgentInputSchema = {
1639
- type: "object",
1640
- properties: {
1641
- model: modelSchema2,
1642
- prompt: {
1643
- oneOf: [
1644
- { type: "string" },
1645
- {
1646
- type: "array",
1647
- items: {
1648
- type: "object",
1649
- properties: {
1650
- type: { type: "string", enum: ["text", "image", "audio"] }
1651
- },
1652
- required: ["type"],
1653
- additionalProperties: true
1654
- }
1655
- }
1656
- ],
1657
- title: "Prompt",
1658
- description: "The user prompt to start the agent loop. Can be a string or an array of content blocks (text, image, audio)."
1659
- },
1660
- systemPrompt: {
1661
- type: "string",
1662
- title: "System Prompt",
1663
- description: "Optional system instructions for the agent"
1664
- },
1665
- tools: {
1666
- type: "array",
1667
- format: "tasks",
1668
- title: "Tools",
1669
- 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.",
1670
- items: {
1671
- oneOf: [
1672
- { type: "string", format: "tasks", description: "Task type name" },
1673
- ToolDefinitionSchema
1674
- ]
1675
- }
1676
- },
1677
- stopTool: {
1678
- type: "string",
1679
- title: "Stop Tool",
1680
- description: "Name of a tool that signals agent completion. When called, the loop ends and the tool input becomes structuredOutput.",
1681
- "x-ui-group": "Configuration"
1682
- },
1683
- maxIterations: {
1684
- type: "number",
1685
- title: "Max Iterations",
1686
- description: "Maximum number of agent loop iterations (default: 10)",
1687
- minimum: 1,
1688
- "x-ui-group": "Configuration"
1689
- },
1690
- maxContextMessages: {
1691
- type: "number",
1692
- title: "Max Context Messages",
1693
- description: "Maximum messages in conversation history. Older messages are trimmed to prevent context overflow.",
1694
- minimum: 3,
1695
- "x-ui-group": "Configuration"
1696
- },
1697
- maxTokens: {
1698
- type: "number",
1699
- title: "Max Tokens",
1700
- description: "Maximum tokens per LLM call",
1701
- minimum: 1,
1702
- "x-ui-group": "Configuration"
1703
- },
1704
- temperature: {
1705
- type: "number",
1706
- title: "Temperature",
1707
- description: "Sampling temperature for LLM calls",
1708
- minimum: 0,
1709
- maximum: 2,
1710
- "x-ui-group": "Configuration"
1711
- }
1712
- },
1713
- required: ["model", "prompt"],
1714
- additionalProperties: false
1715
- };
1716
- var AgentOutputSchema = {
1717
- type: "object",
1718
- properties: {
1719
- text: {
1720
- type: "string",
1721
- title: "Text",
1722
- description: "The final text response from the agent",
1723
- "x-stream": "append"
1724
- },
1725
- messages: {
1726
- type: "array",
1727
- title: "Messages",
1728
- description: "Full conversation history including all tool calls and results",
1729
- items: {
1730
- type: "object",
1731
- additionalProperties: true
1732
- }
1733
- },
1734
- iterations: {
1735
- type: "number",
1736
- title: "Iterations",
1737
- description: "Number of LLM calls made during the agent loop"
1738
- },
1739
- toolCallCount: {
1740
- type: "number",
1741
- title: "Tool Call Count",
1742
- description: "Total number of tool calls the assistant requested (tool_use blocks in assistant messages)"
1743
- },
1744
- structuredOutput: {
1745
- type: "object",
1746
- title: "Structured Output",
1747
- description: "Present when the agent terminated via a stop tool",
1748
- additionalProperties: true
1749
- }
1750
- },
1751
- required: ["text", "messages", "iterations", "toolCallCount"],
1752
- additionalProperties: false
1753
- };
1754
-
1755
- class AgentTask extends Task2 {
1756
- static type = "AgentTask";
1757
- static category = "AI Agent";
1758
- static title = "Agent";
1759
- static description = "Multi-turn agentic loop that calls an LLM with tools, executes tool calls, and iterates until done";
1760
- static cacheable = false;
1761
- static inputSchema() {
1762
- return AgentInputSchema;
1763
- }
1764
- static outputSchema() {
1765
- return AgentOutputSchema;
1766
- }
1767
1559
  async execute(input, context) {
1768
1560
  let result;
1769
- for await (const event of this.agentLoop(input, context)) {
1561
+ for await (const event of this.executeStream(input, context)) {
1770
1562
  if (event.type === "finish") {
1771
1563
  result = event.data;
1772
1564
  }
1773
1565
  }
1774
- if (!result) {
1775
- throw new Error("AgentTask: loop ended without producing output");
1776
- }
1777
1566
  return result;
1778
1567
  }
1779
- async* executeStream(input, context) {
1780
- yield* this.agentLoop(input, context);
1781
- }
1782
- async* agentLoop(input, context) {
1783
- const maxIterations = input.maxIterations ?? 10;
1784
- const hooks = this.config.hooks;
1785
- const maxConcurrency = this.config.maxConcurrency ?? 5;
1786
- const toolSources = this.resolveToolSources(input, context);
1787
- const toolDefs = this.resolveToolDefs(toolSources, input.stopTool);
1788
- const messages = [userMessage(input.prompt)];
1789
- let finalText = "";
1790
- let structuredOutput;
1791
- for (let iteration = 0;iteration < maxIterations; iteration++) {
1792
- if (context.signal.aborted)
1793
- break;
1794
- if (hooks?.onIteration) {
1795
- const action = await hooks.onIteration(iteration, messages, {
1796
- totalToolCalls: countAssistantToolUses(messages)
1797
- });
1798
- if (action.action === "stop")
1799
- break;
1800
- }
1801
- await context.updateProgress(Math.round(iteration / maxIterations * 100), `Agent iteration ${iteration + 1}`);
1802
- const contextMessages = this.trimMessages(messages, input.maxContextMessages ?? MAX_CONTEXT_MESSAGES);
1803
- const llmTask = context.own(new ToolCallingTask);
1804
- let iterationText = "";
1805
- let toolCalls = [];
1806
- for await (const event of llmTask.executeStream({
1807
- model: input.model,
1808
- prompt: input.prompt,
1809
- systemPrompt: input.systemPrompt,
1810
- tools: toolDefs,
1811
- messages: contextMessages,
1812
- maxTokens: input.maxTokens,
1813
- temperature: input.temperature
1814
- }, context)) {
1815
- if (event.type === "text-delta") {
1816
- yield { type: "text-delta", port: "text", textDelta: event.textDelta };
1817
- iterationText += event.textDelta;
1818
- } else if (event.type === "object-delta" && event.port === "toolCalls") {
1819
- const items = event.objectDelta;
1820
- for (const item of items) {
1821
- const idx = toolCalls.findIndex((tc) => tc.id === item.id);
1822
- if (idx >= 0)
1823
- toolCalls[idx] = item;
1824
- else
1825
- toolCalls.push(item);
1826
- }
1827
- } else if (event.type === "finish") {
1828
- const data = event.data;
1829
- iterationText = data?.text ?? iterationText;
1830
- if (data?.toolCalls && data.toolCalls.length > 0) {
1831
- toolCalls = data.toolCalls;
1832
- }
1833
- }
1834
- }
1835
- finalText = iterationText;
1836
- messages.push(assistantMessage(iterationText, toolCalls));
1837
- if (input.stopTool) {
1838
- const stopCall = toolCalls.find((tc) => tc.name === input.stopTool);
1839
- if (stopCall) {
1840
- structuredOutput = stopCall.input;
1841
- break;
1842
- }
1843
- }
1844
- if (!hasToolCalls(toolCalls)) {
1845
- break;
1846
- }
1847
- const results = await executeToolCalls(toolCalls, toolSources, context, hooks, maxConcurrency);
1848
- messages.push(toolMessage(results));
1849
- }
1850
- const output = {
1851
- text: finalText,
1852
- messages,
1853
- iterations: messages.filter((m) => m.role === "assistant").length,
1854
- toolCallCount: countAssistantToolUses(messages),
1855
- ...structuredOutput !== undefined ? { structuredOutput } : {}
1856
- };
1857
- yield { type: "finish", data: output };
1858
- }
1859
- resolveToolSources(input, context) {
1860
- return buildToolSources(input.tools, context.registry);
1861
- }
1862
- resolveToolDefs(toolSources, stopTool) {
1863
- const defs = toolSourceDefinitions(toolSources);
1864
- if (stopTool && !defs.some((d) => d.name === stopTool)) {
1865
- defs.push({
1866
- name: stopTool,
1867
- description: "Call this tool when you have completed the task. Pass your final structured result as the input.",
1868
- inputSchema: { type: "object", additionalProperties: true }
1869
- });
1870
- }
1871
- return defs;
1872
- }
1873
- trimMessages(messages, maxContextMessages) {
1874
- if (!maxContextMessages || messages.length <= maxContextMessages) {
1875
- return messages;
1876
- }
1877
- getLogger4().debug(`AgentTask: Trimming context from ${messages.length} to ${maxContextMessages} messages`);
1878
- const tail = messages.slice(1);
1879
- let startIdx = tail.length - (maxContextMessages - 1);
1880
- if (startIdx < 0)
1881
- startIdx = 0;
1882
- while (startIdx > 0 && startIdx < tail.length && tail[startIdx].role === "tool") {
1883
- startIdx -= 1;
1884
- }
1885
- return [messages[0], ...tail.slice(startIdx)];
1886
- }
1887
1568
  }
1888
- var agent = (input, config) => {
1889
- return new AgentTask(config).run(input);
1890
- };
1891
- Workflow2.prototype.agent = CreateWorkflow2(AgentTask);
1892
1569
 
1893
1570
  // src/task/BackgroundRemovalTask.ts
1894
- import { CreateWorkflow as CreateWorkflow3, Workflow as Workflow3 } from "@workglow/task-graph";
1571
+ import { CreateWorkflow, Workflow } from "@workglow/task-graph";
1895
1572
 
1896
1573
  // src/task/base/AiVisionTask.ts
1897
1574
  import { convertImageDataToUseableForm } from "@workglow/util/media";
@@ -1915,7 +1592,7 @@ class AiVisionTask extends AiTask {
1915
1592
  }
1916
1593
 
1917
1594
  // src/task/BackgroundRemovalTask.ts
1918
- var modelSchema3 = TypeModel("model:BackgroundRemovalTask");
1595
+ var modelSchema2 = TypeModel("model:BackgroundRemovalTask");
1919
1596
  var processedImageSchema = {
1920
1597
  type: "string",
1921
1598
  contentEncoding: "base64",
@@ -1927,7 +1604,7 @@ var BackgroundRemovalInputSchema = {
1927
1604
  type: "object",
1928
1605
  properties: {
1929
1606
  image: TypeImageInput,
1930
- model: modelSchema3
1607
+ model: modelSchema2
1931
1608
  },
1932
1609
  required: ["image", "model"],
1933
1610
  additionalProperties: false
@@ -1956,22 +1633,22 @@ class BackgroundRemovalTask extends AiVisionTask {
1956
1633
  var backgroundRemoval = (input, config) => {
1957
1634
  return new BackgroundRemovalTask(config).run(input);
1958
1635
  };
1959
- Workflow3.prototype.backgroundRemoval = CreateWorkflow3(BackgroundRemovalTask);
1636
+ Workflow.prototype.backgroundRemoval = CreateWorkflow(BackgroundRemovalTask);
1960
1637
 
1961
1638
  // src/task/ChunkRetrievalTask.ts
1962
1639
  import { TypeKnowledgeBase } from "@workglow/knowledge-base";
1963
- import { CreateWorkflow as CreateWorkflow5, Task as Task3, Workflow as Workflow5 } from "@workglow/task-graph";
1640
+ import { CreateWorkflow as CreateWorkflow3, Task as Task2, Workflow as Workflow3 } from "@workglow/task-graph";
1964
1641
  import {
1965
1642
  isTypedArray,
1966
1643
  TypedArraySchema as TypedArraySchema2
1967
1644
  } from "@workglow/util/schema";
1968
1645
 
1969
1646
  // src/task/TextEmbeddingTask.ts
1970
- import { CreateWorkflow as CreateWorkflow4, Workflow as Workflow4 } from "@workglow/task-graph";
1647
+ import { CreateWorkflow as CreateWorkflow2, Workflow as Workflow2 } from "@workglow/task-graph";
1971
1648
  import {
1972
1649
  TypedArraySchema
1973
1650
  } from "@workglow/util/schema";
1974
- var modelSchema4 = TypeModel("model:TextEmbeddingTask");
1651
+ var modelSchema3 = TypeModel("model:TextEmbeddingTask");
1975
1652
  var TextEmbeddingInputSchema = {
1976
1653
  type: "object",
1977
1654
  properties: {
@@ -1980,7 +1657,7 @@ var TextEmbeddingInputSchema = {
1980
1657
  title: "Text",
1981
1658
  description: "The text to embed"
1982
1659
  }),
1983
- model: modelSchema4
1660
+ model: modelSchema3
1984
1661
  },
1985
1662
  required: ["text", "model"],
1986
1663
  additionalProperties: false
@@ -2012,7 +1689,7 @@ class TextEmbeddingTask extends AiTask {
2012
1689
  var textEmbedding = async (input, config) => {
2013
1690
  return new TextEmbeddingTask(config).run(input);
2014
1691
  };
2015
- Workflow4.prototype.textEmbedding = CreateWorkflow4(TextEmbeddingTask);
1692
+ Workflow2.prototype.textEmbedding = CreateWorkflow2(TextEmbeddingTask);
2016
1693
 
2017
1694
  // src/task/ChunkRetrievalTask.ts
2018
1695
  var inputSchema = {
@@ -2137,7 +1814,7 @@ var outputSchema = {
2137
1814
  additionalProperties: false
2138
1815
  };
2139
1816
 
2140
- class ChunkRetrievalTask extends Task3 {
1817
+ class ChunkRetrievalTask extends Task2 {
2141
1818
  static type = "ChunkRetrievalTask";
2142
1819
  static category = "RAG";
2143
1820
  static title = "Chunk Retrieval";
@@ -2204,11 +1881,11 @@ class ChunkRetrievalTask extends Task3 {
2204
1881
  var chunkRetrieval = (input, config) => {
2205
1882
  return new ChunkRetrievalTask(config).run(input);
2206
1883
  };
2207
- Workflow5.prototype.chunkRetrieval = CreateWorkflow5(ChunkRetrievalTask);
1884
+ Workflow3.prototype.chunkRetrieval = CreateWorkflow3(ChunkRetrievalTask);
2208
1885
 
2209
1886
  // src/task/ChunkToVectorTask.ts
2210
1887
  import { ChunkRecordSchema } from "@workglow/knowledge-base";
2211
- import { CreateWorkflow as CreateWorkflow6, Task as Task4, Workflow as Workflow6 } from "@workglow/task-graph";
1888
+ import { CreateWorkflow as CreateWorkflow4, Task as Task3, Workflow as Workflow4 } from "@workglow/task-graph";
2212
1889
  import {
2213
1890
  TypedArraySchema as TypedArraySchema3
2214
1891
  } from "@workglow/util/schema";
@@ -2283,7 +1960,7 @@ var outputSchema2 = {
2283
1960
  additionalProperties: false
2284
1961
  };
2285
1962
 
2286
- class ChunkToVectorTask extends Task4 {
1963
+ class ChunkToVectorTask extends Task3 {
2287
1964
  static type = "ChunkToVectorTask";
2288
1965
  static category = "Document";
2289
1966
  static title = "Chunk to Vector";
@@ -2334,11 +2011,11 @@ class ChunkToVectorTask extends Task4 {
2334
2011
  var chunkToVector = (input, config) => {
2335
2012
  return new ChunkToVectorTask(config).run(input);
2336
2013
  };
2337
- Workflow6.prototype.chunkToVector = CreateWorkflow6(ChunkToVectorTask);
2014
+ Workflow4.prototype.chunkToVector = CreateWorkflow4(ChunkToVectorTask);
2338
2015
 
2339
2016
  // src/task/ChunkVectorHybridSearchTask.ts
2340
2017
  import { TypeKnowledgeBase as TypeKnowledgeBase2 } from "@workglow/knowledge-base";
2341
- import { CreateWorkflow as CreateWorkflow7, Task as Task5, Workflow as Workflow7 } from "@workglow/task-graph";
2018
+ import { CreateWorkflow as CreateWorkflow5, Task as Task4, Workflow as Workflow5 } from "@workglow/task-graph";
2342
2019
  import {
2343
2020
  TypedArraySchema as TypedArraySchema4
2344
2021
  } from "@workglow/util/schema";
@@ -2451,7 +2128,7 @@ var outputSchema3 = {
2451
2128
  additionalProperties: false
2452
2129
  };
2453
2130
 
2454
- class ChunkVectorHybridSearchTask extends Task5 {
2131
+ class ChunkVectorHybridSearchTask extends Task4 {
2455
2132
  static type = "ChunkVectorHybridSearchTask";
2456
2133
  static category = "RAG";
2457
2134
  static title = "Hybrid Search";
@@ -2504,11 +2181,11 @@ class ChunkVectorHybridSearchTask extends Task5 {
2504
2181
  var hybridSearch = async (input, config) => {
2505
2182
  return new ChunkVectorHybridSearchTask(config).run(input);
2506
2183
  };
2507
- Workflow7.prototype.hybridSearch = CreateWorkflow7(ChunkVectorHybridSearchTask);
2184
+ Workflow5.prototype.hybridSearch = CreateWorkflow5(ChunkVectorHybridSearchTask);
2508
2185
 
2509
2186
  // src/task/ChunkVectorSearchTask.ts
2510
2187
  import { TypeKnowledgeBase as TypeKnowledgeBase3 } from "@workglow/knowledge-base";
2511
- import { CreateWorkflow as CreateWorkflow8, Task as Task6, Workflow as Workflow8 } from "@workglow/task-graph";
2188
+ import { CreateWorkflow as CreateWorkflow6, Task as Task5, Workflow as Workflow6 } from "@workglow/task-graph";
2512
2189
  import {
2513
2190
  TypedArraySchema as TypedArraySchema5
2514
2191
  } from "@workglow/util/schema";
@@ -2591,7 +2268,7 @@ var outputSchema4 = {
2591
2268
  additionalProperties: false
2592
2269
  };
2593
2270
 
2594
- class ChunkVectorSearchTask extends Task6 {
2271
+ class ChunkVectorSearchTask extends Task5 {
2595
2272
  static type = "ChunkVectorSearchTask";
2596
2273
  static category = "Vector Store";
2597
2274
  static title = "Vector Store Search";
@@ -2623,11 +2300,11 @@ class ChunkVectorSearchTask extends Task6 {
2623
2300
  var vectorStoreSearch = (input, config) => {
2624
2301
  return new ChunkVectorSearchTask(config).run(input);
2625
2302
  };
2626
- Workflow8.prototype.vectorStoreSearch = CreateWorkflow8(ChunkVectorSearchTask);
2303
+ Workflow6.prototype.vectorStoreSearch = CreateWorkflow6(ChunkVectorSearchTask);
2627
2304
 
2628
2305
  // src/task/ChunkVectorUpsertTask.ts
2629
2306
  import { TypeKnowledgeBase as TypeKnowledgeBase4 } from "@workglow/knowledge-base";
2630
- import { CreateWorkflow as CreateWorkflow9, Task as Task7, Workflow as Workflow9 } from "@workglow/task-graph";
2307
+ import { CreateWorkflow as CreateWorkflow7, Task as Task6, Workflow as Workflow7 } from "@workglow/task-graph";
2631
2308
  import {
2632
2309
  TypedArraySchema as TypedArraySchema6
2633
2310
  } from "@workglow/util/schema";
@@ -2681,7 +2358,7 @@ var outputSchema5 = {
2681
2358
  additionalProperties: false
2682
2359
  };
2683
2360
 
2684
- class ChunkVectorUpsertTask extends Task7 {
2361
+ class ChunkVectorUpsertTask extends Task6 {
2685
2362
  static type = "ChunkVectorUpsertTask";
2686
2363
  static category = "Vector Store";
2687
2364
  static title = "Add to Vector Store";
@@ -2741,15 +2418,15 @@ class ChunkVectorUpsertTask extends Task7 {
2741
2418
  var chunkVectorUpsert = (input, config) => {
2742
2419
  return new ChunkVectorUpsertTask(config).run(input);
2743
2420
  };
2744
- Workflow9.prototype.chunkVectorUpsert = CreateWorkflow9(ChunkVectorUpsertTask);
2421
+ Workflow7.prototype.chunkVectorUpsert = CreateWorkflow7(ChunkVectorUpsertTask);
2745
2422
 
2746
2423
  // src/task/ContextBuilderTask.ts
2747
2424
  import { estimateTokens } from "@workglow/knowledge-base";
2748
- import { CreateWorkflow as CreateWorkflow11, Task as Task8, Workflow as Workflow11 } from "@workglow/task-graph";
2425
+ import { CreateWorkflow as CreateWorkflow9, Task as Task7, Workflow as Workflow9 } from "@workglow/task-graph";
2749
2426
 
2750
2427
  // src/task/CountTokensTask.ts
2751
- import { CreateWorkflow as CreateWorkflow10, Workflow as Workflow10 } from "@workglow/task-graph";
2752
- var modelSchema5 = TypeModel("model");
2428
+ import { CreateWorkflow as CreateWorkflow8, Workflow as Workflow8 } from "@workglow/task-graph";
2429
+ var modelSchema4 = TypeModel("model");
2753
2430
  var CountTokensInputSchema = {
2754
2431
  type: "object",
2755
2432
  properties: {
@@ -2758,7 +2435,7 @@ var CountTokensInputSchema = {
2758
2435
  title: "Text",
2759
2436
  description: "The text to count tokens for"
2760
2437
  },
2761
- model: modelSchema5
2438
+ model: modelSchema4
2762
2439
  },
2763
2440
  required: ["text", "model"],
2764
2441
  additionalProperties: false
@@ -2792,7 +2469,7 @@ class CountTokensTask extends AiTask {
2792
2469
  var countTokens = async (input, config) => {
2793
2470
  return new CountTokensTask(config).run(input);
2794
2471
  };
2795
- Workflow10.prototype.countTokens = CreateWorkflow10(CountTokensTask);
2472
+ Workflow8.prototype.countTokens = CreateWorkflow8(CountTokensTask);
2796
2473
 
2797
2474
  // src/task/ContextBuilderTask.ts
2798
2475
  var ContextFormat = {
@@ -2802,7 +2479,7 @@ var ContextFormat = {
2802
2479
  MARKDOWN: "markdown",
2803
2480
  JSON: "json"
2804
2481
  };
2805
- var modelSchema6 = TypeModel("model", {
2482
+ var modelSchema5 = TypeModel("model", {
2806
2483
  title: "Model",
2807
2484
  description: "Model to use for token counting (optional, falls back to estimation)"
2808
2485
  });
@@ -2866,7 +2543,7 @@ var inputSchema6 = {
2866
2543
 
2867
2544
  `
2868
2545
  },
2869
- model: modelSchema6
2546
+ model: modelSchema5
2870
2547
  },
2871
2548
  required: ["chunks"],
2872
2549
  additionalProperties: false
@@ -2899,7 +2576,7 @@ var outputSchema6 = {
2899
2576
  additionalProperties: false
2900
2577
  };
2901
2578
 
2902
- class ContextBuilderTask extends Task8 {
2579
+ class ContextBuilderTask extends Task7 {
2903
2580
  static type = "ContextBuilderTask";
2904
2581
  static category = "RAG";
2905
2582
  static title = "Context Builder";
@@ -3092,15 +2769,15 @@ class ContextBuilderTask extends Task8 {
3092
2769
  var contextBuilder = (input, config) => {
3093
2770
  return new ContextBuilderTask(config).run(input);
3094
2771
  };
3095
- Workflow11.prototype.contextBuilder = CreateWorkflow11(ContextBuilderTask);
2772
+ Workflow9.prototype.contextBuilder = CreateWorkflow9(ContextBuilderTask);
3096
2773
 
3097
2774
  // src/task/DocumentEnricherTask.ts
3098
2775
  import { getChildren, hasChildren } from "@workglow/knowledge-base";
3099
- import { CreateWorkflow as CreateWorkflow14, Task as Task9, Workflow as Workflow14 } from "@workglow/task-graph";
2776
+ import { CreateWorkflow as CreateWorkflow12, Task as Task8, Workflow as Workflow12 } from "@workglow/task-graph";
3100
2777
 
3101
2778
  // src/task/TextNamedEntityRecognitionTask.ts
3102
- import { CreateWorkflow as CreateWorkflow12, Workflow as Workflow12 } from "@workglow/task-graph";
3103
- var modelSchema7 = TypeModel("model:TextNamedEntityRecognitionTask");
2779
+ import { CreateWorkflow as CreateWorkflow10, Workflow as Workflow10 } from "@workglow/task-graph";
2780
+ var modelSchema6 = TypeModel("model:TextNamedEntityRecognitionTask");
3104
2781
  var TextNamedEntityRecognitionInputSchema = {
3105
2782
  type: "object",
3106
2783
  properties: {
@@ -3119,7 +2796,7 @@ var TextNamedEntityRecognitionInputSchema = {
3119
2796
  "x-ui-group": "Configuration",
3120
2797
  "x-ui-group-open": false
3121
2798
  },
3122
- model: modelSchema7
2799
+ model: modelSchema6
3123
2800
  },
3124
2801
  required: ["text", "model"],
3125
2802
  additionalProperties: false
@@ -3174,11 +2851,11 @@ class TextNamedEntityRecognitionTask extends AiTask {
3174
2851
  var textNamedEntityRecognition = (input, config) => {
3175
2852
  return new TextNamedEntityRecognitionTask(config).run(input);
3176
2853
  };
3177
- Workflow12.prototype.textNamedEntityRecognition = CreateWorkflow12(TextNamedEntityRecognitionTask);
2854
+ Workflow10.prototype.textNamedEntityRecognition = CreateWorkflow10(TextNamedEntityRecognitionTask);
3178
2855
 
3179
2856
  // src/task/TextSummaryTask.ts
3180
- import { CreateWorkflow as CreateWorkflow13, Workflow as Workflow13 } from "@workglow/task-graph";
3181
- var modelSchema8 = TypeModel("model:TextSummaryTask");
2857
+ import { CreateWorkflow as CreateWorkflow11, Workflow as Workflow11 } from "@workglow/task-graph";
2858
+ var modelSchema7 = TypeModel("model:TextSummaryTask");
3182
2859
  var TextSummaryInputSchema = {
3183
2860
  type: "object",
3184
2861
  properties: {
@@ -3187,7 +2864,7 @@ var TextSummaryInputSchema = {
3187
2864
  title: "Text",
3188
2865
  description: "The text to summarize"
3189
2866
  },
3190
- model: modelSchema8
2867
+ model: modelSchema7
3191
2868
  },
3192
2869
  required: ["text", "model"],
3193
2870
  additionalProperties: false
@@ -3221,7 +2898,7 @@ class TextSummaryTask extends StreamingAiTask {
3221
2898
  var textSummary = async (input, config) => {
3222
2899
  return new TextSummaryTask(config).run(input);
3223
2900
  };
3224
- Workflow13.prototype.textSummary = CreateWorkflow13(TextSummaryTask);
2901
+ Workflow11.prototype.textSummary = CreateWorkflow11(TextSummaryTask);
3225
2902
 
3226
2903
  // src/task/DocumentEnricherTask.ts
3227
2904
  var inputSchema7 = {
@@ -3295,7 +2972,7 @@ var outputSchema7 = {
3295
2972
  additionalProperties: false
3296
2973
  };
3297
2974
 
3298
- class DocumentEnricherTask extends Task9 {
2975
+ class DocumentEnricherTask extends Task8 {
3299
2976
  static type = "DocumentEnricherTask";
3300
2977
  static category = "Document";
3301
2978
  static title = "Document Enricher";
@@ -3454,12 +3131,12 @@ class DocumentEnricherTask extends Task9 {
3454
3131
  var documentEnricher = (input, config) => {
3455
3132
  return new DocumentEnricherTask(config).run(input);
3456
3133
  };
3457
- Workflow14.prototype.documentEnricher = CreateWorkflow14(DocumentEnricherTask);
3134
+ Workflow12.prototype.documentEnricher = CreateWorkflow12(DocumentEnricherTask);
3458
3135
 
3459
3136
  // src/task/DocumentUpsertTask.ts
3460
3137
  import { Document, TypeKnowledgeBase as TypeKnowledgeBase5 } from "@workglow/knowledge-base";
3461
3138
  import { DocumentMetadataSchema } from "@workglow/knowledge-base";
3462
- import { CreateWorkflow as CreateWorkflow15, Task as Task10, Workflow as Workflow15 } from "@workglow/task-graph";
3139
+ import { CreateWorkflow as CreateWorkflow13, Task as Task9, Workflow as Workflow13 } from "@workglow/task-graph";
3463
3140
  var inputSchema8 = {
3464
3141
  type: "object",
3465
3142
  properties: {
@@ -3504,7 +3181,7 @@ var outputSchema8 = {
3504
3181
  additionalProperties: false
3505
3182
  };
3506
3183
 
3507
- class DocumentUpsertTask extends Task10 {
3184
+ class DocumentUpsertTask extends Task9 {
3508
3185
  static type = "DocumentUpsertTask";
3509
3186
  static category = "Vector Store";
3510
3187
  static title = "Add Document";
@@ -3537,15 +3214,15 @@ class DocumentUpsertTask extends Task10 {
3537
3214
  var documentUpsert = (input, config) => {
3538
3215
  return new DocumentUpsertTask(config).run(input);
3539
3216
  };
3540
- Workflow15.prototype.documentUpsert = CreateWorkflow15(DocumentUpsertTask);
3217
+ Workflow13.prototype.documentUpsert = CreateWorkflow13(DocumentUpsertTask);
3541
3218
 
3542
3219
  // src/task/DownloadModelTask.ts
3543
- import { CreateWorkflow as CreateWorkflow16, Workflow as Workflow16 } from "@workglow/task-graph";
3544
- var modelSchema9 = TypeModel("model");
3220
+ import { CreateWorkflow as CreateWorkflow14, Workflow as Workflow14 } from "@workglow/task-graph";
3221
+ var modelSchema8 = TypeModel("model");
3545
3222
  var DownloadModelInputSchema = {
3546
3223
  type: "object",
3547
3224
  properties: {
3548
- model: modelSchema9
3225
+ model: modelSchema8
3549
3226
  },
3550
3227
  required: ["model"],
3551
3228
  additionalProperties: false
@@ -3553,7 +3230,7 @@ var DownloadModelInputSchema = {
3553
3230
  var DownloadModelOutputSchema = {
3554
3231
  type: "object",
3555
3232
  properties: {
3556
- model: modelSchema9
3233
+ model: modelSchema8
3557
3234
  },
3558
3235
  required: ["model"],
3559
3236
  additionalProperties: false
@@ -3607,11 +3284,11 @@ class DownloadModelTask extends AiTask {
3607
3284
  var downloadModel = (input, config) => {
3608
3285
  return new DownloadModelTask(config).run(input);
3609
3286
  };
3610
- Workflow16.prototype.downloadModel = CreateWorkflow16(DownloadModelTask);
3287
+ Workflow14.prototype.downloadModel = CreateWorkflow14(DownloadModelTask);
3611
3288
 
3612
3289
  // src/task/FaceDetectorTask.ts
3613
- import { CreateWorkflow as CreateWorkflow17, Workflow as Workflow17 } from "@workglow/task-graph";
3614
- var modelSchema10 = TypeModel("model:FaceDetectorTask");
3290
+ import { CreateWorkflow as CreateWorkflow15, Workflow as Workflow15 } from "@workglow/task-graph";
3291
+ var modelSchema9 = TypeModel("model:FaceDetectorTask");
3615
3292
  var TypeBoundingBox2 = {
3616
3293
  type: "object",
3617
3294
  properties: {
@@ -3684,7 +3361,7 @@ var FaceDetectorInputSchema = {
3684
3361
  type: "object",
3685
3362
  properties: {
3686
3363
  image: TypeImageInput,
3687
- model: modelSchema10,
3364
+ model: modelSchema9,
3688
3365
  minDetectionConfidence: {
3689
3366
  type: "number",
3690
3367
  minimum: 0,
@@ -3738,11 +3415,11 @@ class FaceDetectorTask extends AiVisionTask {
3738
3415
  var faceDetector = (input, config) => {
3739
3416
  return new FaceDetectorTask(config).run(input);
3740
3417
  };
3741
- Workflow17.prototype.faceDetector = CreateWorkflow17(FaceDetectorTask);
3418
+ Workflow15.prototype.faceDetector = CreateWorkflow15(FaceDetectorTask);
3742
3419
 
3743
3420
  // src/task/FaceLandmarkerTask.ts
3744
- import { CreateWorkflow as CreateWorkflow18, Workflow as Workflow18 } from "@workglow/task-graph";
3745
- var modelSchema11 = TypeModel("model:FaceLandmarkerTask");
3421
+ import { CreateWorkflow as CreateWorkflow16, Workflow as Workflow16 } from "@workglow/task-graph";
3422
+ var modelSchema10 = TypeModel("model:FaceLandmarkerTask");
3746
3423
  var TypeLandmark = {
3747
3424
  type: "object",
3748
3425
  properties: {
@@ -3814,7 +3491,7 @@ var FaceLandmarkerInputSchema = {
3814
3491
  type: "object",
3815
3492
  properties: {
3816
3493
  image: TypeImageInput,
3817
- model: modelSchema11,
3494
+ model: modelSchema10,
3818
3495
  numFaces: {
3819
3496
  type: "number",
3820
3497
  minimum: 1,
@@ -3900,11 +3577,11 @@ class FaceLandmarkerTask extends AiVisionTask {
3900
3577
  var faceLandmarker = (input, config) => {
3901
3578
  return new FaceLandmarkerTask(config).run(input);
3902
3579
  };
3903
- Workflow18.prototype.faceLandmarker = CreateWorkflow18(FaceLandmarkerTask);
3580
+ Workflow16.prototype.faceLandmarker = CreateWorkflow16(FaceLandmarkerTask);
3904
3581
 
3905
3582
  // src/task/GestureRecognizerTask.ts
3906
- import { CreateWorkflow as CreateWorkflow19, Workflow as Workflow19 } from "@workglow/task-graph";
3907
- var modelSchema12 = TypeModel("model:GestureRecognizerTask");
3583
+ import { CreateWorkflow as CreateWorkflow17, Workflow as Workflow17 } from "@workglow/task-graph";
3584
+ var modelSchema11 = TypeModel("model:GestureRecognizerTask");
3908
3585
  var TypeLandmark2 = {
3909
3586
  type: "object",
3910
3587
  properties: {
@@ -3996,7 +3673,7 @@ var GestureRecognizerInputSchema = {
3996
3673
  type: "object",
3997
3674
  properties: {
3998
3675
  image: TypeImageInput,
3999
- model: modelSchema12,
3676
+ model: modelSchema11,
4000
3677
  numHands: {
4001
3678
  type: "number",
4002
3679
  minimum: 1,
@@ -4068,11 +3745,11 @@ class GestureRecognizerTask extends AiVisionTask {
4068
3745
  var gestureRecognizer = (input, config) => {
4069
3746
  return new GestureRecognizerTask(config).run(input);
4070
3747
  };
4071
- Workflow19.prototype.gestureRecognizer = CreateWorkflow19(GestureRecognizerTask);
3748
+ Workflow17.prototype.gestureRecognizer = CreateWorkflow17(GestureRecognizerTask);
4072
3749
 
4073
3750
  // src/task/HandLandmarkerTask.ts
4074
- import { CreateWorkflow as CreateWorkflow20, Workflow as Workflow20 } from "@workglow/task-graph";
4075
- var modelSchema13 = TypeModel("model:HandLandmarkerTask");
3751
+ import { CreateWorkflow as CreateWorkflow18, Workflow as Workflow18 } from "@workglow/task-graph";
3752
+ var modelSchema12 = TypeModel("model:HandLandmarkerTask");
4076
3753
  var TypeLandmark3 = {
4077
3754
  type: "object",
4078
3755
  properties: {
@@ -4141,7 +3818,7 @@ var HandLandmarkerInputSchema = {
4141
3818
  type: "object",
4142
3819
  properties: {
4143
3820
  image: TypeImageInput,
4144
- model: modelSchema13,
3821
+ model: modelSchema12,
4145
3822
  numHands: {
4146
3823
  type: "number",
4147
3824
  minimum: 1,
@@ -4213,7 +3890,7 @@ class HandLandmarkerTask extends AiVisionTask {
4213
3890
  var handLandmarker = (input, config) => {
4214
3891
  return new HandLandmarkerTask(config).run(input);
4215
3892
  };
4216
- Workflow20.prototype.handLandmarker = CreateWorkflow20(HandLandmarkerTask);
3893
+ Workflow18.prototype.handLandmarker = CreateWorkflow18(HandLandmarkerTask);
4217
3894
 
4218
3895
  // src/task/HierarchicalChunkerTask.ts
4219
3896
  import {
@@ -4222,9 +3899,9 @@ import {
4222
3899
  getChildren as getChildren2,
4223
3900
  hasChildren as hasChildren2
4224
3901
  } from "@workglow/knowledge-base";
4225
- import { CreateWorkflow as CreateWorkflow21, Task as Task11, Workflow as Workflow21 } from "@workglow/task-graph";
3902
+ import { CreateWorkflow as CreateWorkflow19, Task as Task10, Workflow as Workflow19 } from "@workglow/task-graph";
4226
3903
  import { uuid4 } from "@workglow/util";
4227
- var modelSchema14 = TypeModel("model", {
3904
+ var modelSchema13 = TypeModel("model", {
4228
3905
  title: "Model",
4229
3906
  description: "Model to use for token counting"
4230
3907
  });
@@ -4270,7 +3947,7 @@ var inputSchema9 = {
4270
3947
  description: "Strategy for chunking",
4271
3948
  default: "hierarchical"
4272
3949
  },
4273
- model: modelSchema14
3950
+ model: modelSchema13
4274
3951
  },
4275
3952
  required: ["doc_id", "documentTree"],
4276
3953
  additionalProperties: false
@@ -4305,7 +3982,7 @@ var outputSchema9 = {
4305
3982
  additionalProperties: false
4306
3983
  };
4307
3984
 
4308
- class HierarchicalChunkerTask extends Task11 {
3985
+ class HierarchicalChunkerTask extends Task10 {
4309
3986
  static type = "HierarchicalChunkerTask";
4310
3987
  static category = "Document";
4311
3988
  static title = "Hierarchical Chunker";
@@ -4449,11 +4126,11 @@ class HierarchicalChunkerTask extends Task11 {
4449
4126
  var hierarchicalChunker = (input, config) => {
4450
4127
  return new HierarchicalChunkerTask(config).run(input);
4451
4128
  };
4452
- Workflow21.prototype.hierarchicalChunker = CreateWorkflow21(HierarchicalChunkerTask);
4129
+ Workflow19.prototype.hierarchicalChunker = CreateWorkflow19(HierarchicalChunkerTask);
4453
4130
 
4454
4131
  // src/task/HierarchyJoinTask.ts
4455
4132
  import { ChunkRecordArraySchema, TypeKnowledgeBase as TypeKnowledgeBase6 } from "@workglow/knowledge-base";
4456
- import { CreateWorkflow as CreateWorkflow22, Task as Task12, Workflow as Workflow22 } from "@workglow/task-graph";
4133
+ import { CreateWorkflow as CreateWorkflow20, Task as Task11, Workflow as Workflow20 } from "@workglow/task-graph";
4457
4134
  var inputSchema10 = {
4458
4135
  type: "object",
4459
4136
  properties: {
@@ -4528,7 +4205,7 @@ var outputSchema10 = {
4528
4205
  additionalProperties: false
4529
4206
  };
4530
4207
 
4531
- class HierarchyJoinTask extends Task12 {
4208
+ class HierarchyJoinTask extends Task11 {
4532
4209
  static type = "HierarchyJoinTask";
4533
4210
  static category = "RAG";
4534
4211
  static title = "Hierarchy Join";
@@ -4622,11 +4299,11 @@ class HierarchyJoinTask extends Task12 {
4622
4299
  var hierarchyJoin = (input, config) => {
4623
4300
  return new HierarchyJoinTask(config).run(input);
4624
4301
  };
4625
- Workflow22.prototype.hierarchyJoin = CreateWorkflow22(HierarchyJoinTask);
4302
+ Workflow20.prototype.hierarchyJoin = CreateWorkflow20(HierarchyJoinTask);
4626
4303
 
4627
4304
  // src/task/KbToDocumentsTask.ts
4628
4305
  import { TypeKnowledgeBase as TypeKnowledgeBase7 } from "@workglow/knowledge-base";
4629
- import { CreateWorkflow as CreateWorkflow23, Task as Task13, Workflow as Workflow23 } from "@workglow/task-graph";
4306
+ import { CreateWorkflow as CreateWorkflow21, Task as Task12, Workflow as Workflow21 } from "@workglow/task-graph";
4630
4307
  var inputSchema11 = {
4631
4308
  type: "object",
4632
4309
  properties: {
@@ -4670,7 +4347,7 @@ var outputSchema11 = {
4670
4347
  additionalProperties: false
4671
4348
  };
4672
4349
 
4673
- class KbToDocumentsTask extends Task13 {
4350
+ class KbToDocumentsTask extends Task12 {
4674
4351
  static type = "KbToDocumentsTask";
4675
4352
  static category = "Vector Store";
4676
4353
  static title = "Knowledge Base to Documents";
@@ -4711,16 +4388,16 @@ class KbToDocumentsTask extends Task13 {
4711
4388
  var kbToDocuments = (input, config) => {
4712
4389
  return new KbToDocumentsTask(config).run(input);
4713
4390
  };
4714
- Workflow23.prototype.kbToDocuments = CreateWorkflow23(KbToDocumentsTask);
4391
+ Workflow21.prototype.kbToDocuments = CreateWorkflow21(KbToDocumentsTask);
4715
4392
 
4716
4393
  // src/task/ImageClassificationTask.ts
4717
- import { CreateWorkflow as CreateWorkflow24, Workflow as Workflow24 } from "@workglow/task-graph";
4718
- var modelSchema15 = TypeModel("model:ImageClassificationTask");
4394
+ import { CreateWorkflow as CreateWorkflow22, Workflow as Workflow22 } from "@workglow/task-graph";
4395
+ var modelSchema14 = TypeModel("model:ImageClassificationTask");
4719
4396
  var ImageClassificationInputSchema = {
4720
4397
  type: "object",
4721
4398
  properties: {
4722
4399
  image: TypeImageInput,
4723
- model: modelSchema15,
4400
+ model: modelSchema14,
4724
4401
  categories: {
4725
4402
  type: "array",
4726
4403
  items: {
@@ -4774,19 +4451,19 @@ class ImageClassificationTask extends AiVisionTask {
4774
4451
  var imageClassification = (input, config) => {
4775
4452
  return new ImageClassificationTask(config).run(input);
4776
4453
  };
4777
- Workflow24.prototype.imageClassification = CreateWorkflow24(ImageClassificationTask);
4454
+ Workflow22.prototype.imageClassification = CreateWorkflow22(ImageClassificationTask);
4778
4455
 
4779
4456
  // src/task/ImageEmbeddingTask.ts
4780
- import { CreateWorkflow as CreateWorkflow25, Workflow as Workflow25 } from "@workglow/task-graph";
4457
+ import { CreateWorkflow as CreateWorkflow23, Workflow as Workflow23 } from "@workglow/task-graph";
4781
4458
  import {
4782
4459
  TypedArraySchema as TypedArraySchema7
4783
4460
  } from "@workglow/util/schema";
4784
- var modelSchema16 = TypeModel("model:ImageEmbeddingTask");
4461
+ var modelSchema15 = TypeModel("model:ImageEmbeddingTask");
4785
4462
  var ImageEmbeddingInputSchema = {
4786
4463
  type: "object",
4787
4464
  properties: {
4788
4465
  image: TypeSingleOrArray(TypeImageInput),
4789
- model: modelSchema16
4466
+ model: modelSchema15
4790
4467
  },
4791
4468
  required: ["image", "model"],
4792
4469
  additionalProperties: false
@@ -4818,16 +4495,16 @@ class ImageEmbeddingTask extends AiVisionTask {
4818
4495
  var imageEmbedding = (input, config) => {
4819
4496
  return new ImageEmbeddingTask(config).run(input);
4820
4497
  };
4821
- Workflow25.prototype.imageEmbedding = CreateWorkflow25(ImageEmbeddingTask);
4498
+ Workflow23.prototype.imageEmbedding = CreateWorkflow23(ImageEmbeddingTask);
4822
4499
 
4823
4500
  // src/task/ImageSegmentationTask.ts
4824
- import { CreateWorkflow as CreateWorkflow26, Workflow as Workflow26 } from "@workglow/task-graph";
4825
- var modelSchema17 = TypeModel("model:ImageSegmentationTask");
4501
+ import { CreateWorkflow as CreateWorkflow24, Workflow as Workflow24 } from "@workglow/task-graph";
4502
+ var modelSchema16 = TypeModel("model:ImageSegmentationTask");
4826
4503
  var ImageSegmentationInputSchema = {
4827
4504
  type: "object",
4828
4505
  properties: {
4829
4506
  image: TypeImageInput,
4830
- model: modelSchema17,
4507
+ model: modelSchema16,
4831
4508
  threshold: {
4832
4509
  type: "number",
4833
4510
  title: "Threshold",
@@ -4906,11 +4583,11 @@ class ImageSegmentationTask extends AiVisionTask {
4906
4583
  var imageSegmentation = (input, config) => {
4907
4584
  return new ImageSegmentationTask(config).run(input);
4908
4585
  };
4909
- Workflow26.prototype.imageSegmentation = CreateWorkflow26(ImageSegmentationTask);
4586
+ Workflow24.prototype.imageSegmentation = CreateWorkflow24(ImageSegmentationTask);
4910
4587
 
4911
4588
  // src/task/ImageToTextTask.ts
4912
- import { CreateWorkflow as CreateWorkflow27, Workflow as Workflow27 } from "@workglow/task-graph";
4913
- var modelSchema18 = TypeModel("model:ImageToTextTask");
4589
+ import { CreateWorkflow as CreateWorkflow25, Workflow as Workflow25 } from "@workglow/task-graph";
4590
+ var modelSchema17 = TypeModel("model:ImageToTextTask");
4914
4591
  var generatedTextSchema = {
4915
4592
  type: "string",
4916
4593
  title: "Text",
@@ -4920,7 +4597,7 @@ var ImageToTextInputSchema = {
4920
4597
  type: "object",
4921
4598
  properties: {
4922
4599
  image: TypeImageInput,
4923
- model: modelSchema18,
4600
+ model: modelSchema17,
4924
4601
  maxTokens: {
4925
4602
  type: "number",
4926
4603
  title: "Max Tokens",
@@ -4961,15 +4638,15 @@ class ImageToTextTask extends AiVisionTask {
4961
4638
  var imageToText = (input, config) => {
4962
4639
  return new ImageToTextTask(config).run(input);
4963
4640
  };
4964
- Workflow27.prototype.imageToText = CreateWorkflow27(ImageToTextTask);
4641
+ Workflow25.prototype.imageToText = CreateWorkflow25(ImageToTextTask);
4965
4642
 
4966
4643
  // src/task/ModelInfoTask.ts
4967
- import { CreateWorkflow as CreateWorkflow28, Workflow as Workflow28 } from "@workglow/task-graph";
4968
- var modelSchema19 = TypeModel("model");
4644
+ import { CreateWorkflow as CreateWorkflow26, Workflow as Workflow26 } from "@workglow/task-graph";
4645
+ var modelSchema18 = TypeModel("model");
4969
4646
  var ModelInfoInputSchema = {
4970
4647
  type: "object",
4971
4648
  properties: {
4972
- model: modelSchema19,
4649
+ model: modelSchema18,
4973
4650
  detail: {
4974
4651
  type: "string",
4975
4652
  enum: ["cached_status", "files", "files_with_metadata", "dimensions"],
@@ -4982,7 +4659,7 @@ var ModelInfoInputSchema = {
4982
4659
  var ModelInfoOutputSchema = {
4983
4660
  type: "object",
4984
4661
  properties: {
4985
- model: modelSchema19,
4662
+ model: modelSchema18,
4986
4663
  is_local: { type: "boolean" },
4987
4664
  is_remote: { type: "boolean" },
4988
4665
  supports_browser: { type: "boolean" },
@@ -5040,10 +4717,10 @@ class ModelInfoTask extends AiTask {
5040
4717
  var modelInfo = (input, config) => {
5041
4718
  return new ModelInfoTask(config).run(input);
5042
4719
  };
5043
- Workflow28.prototype.modelInfo = CreateWorkflow28(ModelInfoTask);
4720
+ Workflow26.prototype.modelInfo = CreateWorkflow26(ModelInfoTask);
5044
4721
 
5045
4722
  // src/task/ModelSearchTask.ts
5046
- import { CreateWorkflow as CreateWorkflow29, Task as Task14, Workflow as Workflow29 } from "@workglow/task-graph";
4723
+ import { CreateWorkflow as CreateWorkflow27, Task as Task13, Workflow as Workflow27 } from "@workglow/task-graph";
5047
4724
  var ModelSearchInputSchema = {
5048
4725
  type: "object",
5049
4726
  properties: {
@@ -5108,7 +4785,7 @@ var ModelSearchOutputSchema = {
5108
4785
  additionalProperties: false
5109
4786
  };
5110
4787
 
5111
- class ModelSearchTask extends Task14 {
4788
+ class ModelSearchTask extends Task13 {
5112
4789
  static type = "ModelSearchTask";
5113
4790
  static category = "AI Model";
5114
4791
  static title = "Model Search";
@@ -5134,11 +4811,11 @@ class ModelSearchTask extends Task14 {
5134
4811
  var modelSearch = (input, config) => {
5135
4812
  return new ModelSearchTask(config).run(input);
5136
4813
  };
5137
- Workflow29.prototype.modelSearch = CreateWorkflow29(ModelSearchTask);
4814
+ Workflow27.prototype.modelSearch = CreateWorkflow27(ModelSearchTask);
5138
4815
 
5139
4816
  // src/task/ObjectDetectionTask.ts
5140
- import { CreateWorkflow as CreateWorkflow30, Workflow as Workflow30 } from "@workglow/task-graph";
5141
- var modelSchema20 = TypeModel("model:ObjectDetectionTask");
4817
+ import { CreateWorkflow as CreateWorkflow28, Workflow as Workflow28 } from "@workglow/task-graph";
4818
+ var modelSchema19 = TypeModel("model:ObjectDetectionTask");
5142
4819
  var detectionSchema = {
5143
4820
  type: "object",
5144
4821
  properties: {
@@ -5163,7 +4840,7 @@ var ObjectDetectionInputSchema = {
5163
4840
  type: "object",
5164
4841
  properties: {
5165
4842
  image: TypeImageInput,
5166
- model: modelSchema20,
4843
+ model: modelSchema19,
5167
4844
  labels: {
5168
4845
  type: "array",
5169
4846
  items: {
@@ -5217,11 +4894,11 @@ class ObjectDetectionTask extends AiVisionTask {
5217
4894
  var objectDetection = (input, config) => {
5218
4895
  return new ObjectDetectionTask(config).run(input);
5219
4896
  };
5220
- Workflow30.prototype.objectDetection = CreateWorkflow30(ObjectDetectionTask);
4897
+ Workflow28.prototype.objectDetection = CreateWorkflow28(ObjectDetectionTask);
5221
4898
 
5222
4899
  // src/task/PoseLandmarkerTask.ts
5223
- import { CreateWorkflow as CreateWorkflow31, Workflow as Workflow31 } from "@workglow/task-graph";
5224
- var modelSchema21 = TypeModel("model:PoseLandmarkerTask");
4900
+ import { CreateWorkflow as CreateWorkflow29, Workflow as Workflow29 } from "@workglow/task-graph";
4901
+ var modelSchema20 = TypeModel("model:PoseLandmarkerTask");
5225
4902
  var TypePoseLandmark = {
5226
4903
  type: "object",
5227
4904
  properties: {
@@ -5300,7 +4977,7 @@ var PoseLandmarkerInputSchema = {
5300
4977
  type: "object",
5301
4978
  properties: {
5302
4979
  image: TypeImageInput,
5303
- model: modelSchema21,
4980
+ model: modelSchema20,
5304
4981
  numPoses: {
5305
4982
  type: "number",
5306
4983
  minimum: 1,
@@ -5379,10 +5056,10 @@ class PoseLandmarkerTask extends AiVisionTask {
5379
5056
  var poseLandmarker = (input, config) => {
5380
5057
  return new PoseLandmarkerTask(config).run(input);
5381
5058
  };
5382
- Workflow31.prototype.poseLandmarker = CreateWorkflow31(PoseLandmarkerTask);
5059
+ Workflow29.prototype.poseLandmarker = CreateWorkflow29(PoseLandmarkerTask);
5383
5060
 
5384
5061
  // src/task/QueryExpanderTask.ts
5385
- import { CreateWorkflow as CreateWorkflow32, Task as Task15, Workflow as Workflow32 } from "@workglow/task-graph";
5062
+ import { CreateWorkflow as CreateWorkflow30, Task as Task14, Workflow as Workflow30 } from "@workglow/task-graph";
5386
5063
  var QueryExpansionMethod = {
5387
5064
  MULTI_QUERY: "multi-query",
5388
5065
  HYDE: "hyde",
@@ -5450,7 +5127,7 @@ var outputSchema12 = {
5450
5127
  additionalProperties: false
5451
5128
  };
5452
5129
 
5453
- class QueryExpanderTask extends Task15 {
5130
+ class QueryExpanderTask extends Task14 {
5454
5131
  static type = "QueryExpanderTask";
5455
5132
  static category = "RAG";
5456
5133
  static title = "Query Expander";
@@ -5592,14 +5269,14 @@ class QueryExpanderTask extends Task15 {
5592
5269
  var queryExpander = (input, config) => {
5593
5270
  return new QueryExpanderTask(config).run(input);
5594
5271
  };
5595
- Workflow32.prototype.queryExpander = CreateWorkflow32(QueryExpanderTask);
5272
+ Workflow30.prototype.queryExpander = CreateWorkflow30(QueryExpanderTask);
5596
5273
 
5597
5274
  // src/task/RerankerTask.ts
5598
- import { CreateWorkflow as CreateWorkflow34, Task as Task16, Workflow as Workflow34 } from "@workglow/task-graph";
5275
+ import { CreateWorkflow as CreateWorkflow32, Task as Task15, Workflow as Workflow32 } from "@workglow/task-graph";
5599
5276
 
5600
5277
  // src/task/TextClassificationTask.ts
5601
- import { CreateWorkflow as CreateWorkflow33, Workflow as Workflow33 } from "@workglow/task-graph";
5602
- var modelSchema22 = TypeModel("model:TextClassificationTask");
5278
+ import { CreateWorkflow as CreateWorkflow31, Workflow as Workflow31 } from "@workglow/task-graph";
5279
+ var modelSchema21 = TypeModel("model:TextClassificationTask");
5603
5280
  var TextClassificationInputSchema = {
5604
5281
  type: "object",
5605
5282
  properties: {
@@ -5626,7 +5303,7 @@ var TextClassificationInputSchema = {
5626
5303
  description: "The maximum number of categories to return",
5627
5304
  "x-ui-group": "Configuration"
5628
5305
  },
5629
- model: modelSchema22
5306
+ model: modelSchema21
5630
5307
  },
5631
5308
  required: ["text", "model"],
5632
5309
  additionalProperties: false
@@ -5676,7 +5353,7 @@ class TextClassificationTask extends AiTask {
5676
5353
  var textClassification = (input, config) => {
5677
5354
  return new TextClassificationTask(config).run(input);
5678
5355
  };
5679
- Workflow33.prototype.textClassification = CreateWorkflow33(TextClassificationTask);
5356
+ Workflow31.prototype.textClassification = CreateWorkflow31(TextClassificationTask);
5680
5357
 
5681
5358
  // src/task/RerankerTask.ts
5682
5359
  var inputSchema13 = {
@@ -5771,7 +5448,7 @@ var outputSchema13 = {
5771
5448
  additionalProperties: false
5772
5449
  };
5773
5450
 
5774
- class RerankerTask extends Task16 {
5451
+ class RerankerTask extends Task15 {
5775
5452
  static type = "RerankerTask";
5776
5453
  static category = "RAG";
5777
5454
  static title = "Reranker";
@@ -5899,11 +5576,11 @@ class RerankerTask extends Task16 {
5899
5576
  var reranker = (input, config) => {
5900
5577
  return new RerankerTask(config).run(input);
5901
5578
  };
5902
- Workflow34.prototype.reranker = CreateWorkflow34(RerankerTask);
5579
+ Workflow32.prototype.reranker = CreateWorkflow32(RerankerTask);
5903
5580
 
5904
5581
  // src/task/StructuralParserTask.ts
5905
5582
  import { StructuralParser } from "@workglow/knowledge-base";
5906
- import { CreateWorkflow as CreateWorkflow35, Task as Task17, Workflow as Workflow35 } from "@workglow/task-graph";
5583
+ import { CreateWorkflow as CreateWorkflow33, Task as Task16, Workflow as Workflow33 } from "@workglow/task-graph";
5907
5584
  import { uuid4 as uuid42 } from "@workglow/util";
5908
5585
  var inputSchema14 = {
5909
5586
  type: "object",
@@ -5963,7 +5640,7 @@ var outputSchema14 = {
5963
5640
  additionalProperties: false
5964
5641
  };
5965
5642
 
5966
- class StructuralParserTask extends Task17 {
5643
+ class StructuralParserTask extends Task16 {
5967
5644
  static type = "StructuralParserTask";
5968
5645
  static category = "Document";
5969
5646
  static title = "Structural Parser";
@@ -6006,15 +5683,16 @@ class StructuralParserTask extends Task17 {
6006
5683
  var structuralParser = (input, config) => {
6007
5684
  return new StructuralParserTask(config).run(input);
6008
5685
  };
6009
- Workflow35.prototype.structuralParser = CreateWorkflow35(StructuralParserTask);
5686
+ Workflow33.prototype.structuralParser = CreateWorkflow33(StructuralParserTask);
6010
5687
 
6011
5688
  // src/task/StructuredGenerationTask.ts
6012
- import { CreateWorkflow as CreateWorkflow36, Workflow as Workflow36 } from "@workglow/task-graph";
6013
- var modelSchema23 = TypeModel("model:StructuredGenerationTask");
5689
+ import { CreateWorkflow as CreateWorkflow34, TaskConfigurationError as TaskConfigurationError4, TaskError, Workflow as Workflow34 } from "@workglow/task-graph";
5690
+ import { compileSchema as compileSchema2 } from "@workglow/util/schema";
5691
+ var modelSchema22 = TypeModel("model:StructuredGenerationTask");
6014
5692
  var StructuredGenerationInputSchema = {
6015
5693
  type: "object",
6016
5694
  properties: {
6017
- model: modelSchema23,
5695
+ model: modelSchema22,
6018
5696
  prompt: {
6019
5697
  type: "string",
6020
5698
  title: "Prompt",
@@ -6041,6 +5719,15 @@ var StructuredGenerationInputSchema = {
6041
5719
  minimum: 0,
6042
5720
  maximum: 2,
6043
5721
  "x-ui-group": "Configuration"
5722
+ },
5723
+ maxRetries: {
5724
+ type: "integer",
5725
+ title: "Max Retries",
5726
+ description: "Number of times to re-prompt the model with validation errors when its output doesn't match the schema. 0 disables retries (fail on first mismatch).",
5727
+ minimum: 0,
5728
+ maximum: 10,
5729
+ default: 2,
5730
+ "x-ui-group": "Configuration"
6044
5731
  }
6045
5732
  },
6046
5733
  required: ["model", "prompt", "outputSchema"],
@@ -6062,25 +5749,119 @@ var StructuredGenerationOutputSchema = {
6062
5749
  additionalProperties: false
6063
5750
  };
6064
5751
 
5752
+ class StructuredOutputValidationError extends TaskError {
5753
+ static type = "StructuredOutputValidationError";
5754
+ attempts;
5755
+ constructor(attempts) {
5756
+ const last = attempts[attempts.length - 1];
5757
+ const summary = last?.errors.map((e) => `${e.path || "/"}: ${e.message}`).join("; ") ?? "";
5758
+ super(`StructuredGenerationTask: model output failed validation after ${attempts.length} attempt(s). ` + `Last errors: ${summary}`);
5759
+ this.attempts = attempts;
5760
+ }
5761
+ }
5762
+ function validationErrorsFromSchemaNode(result) {
5763
+ return result.errors.map((e) => ({ path: e.data.pointer || "", message: e.message }));
5764
+ }
5765
+ function buildRetryPrompt(originalPrompt, errors) {
5766
+ const errorList = errors.map((e) => ` - ${e.path || "/"}: ${e.message}`).join(`
5767
+ `);
5768
+ return `${originalPrompt}
5769
+
5770
+ ` + `Your previous response did not conform to the required JSON schema. ` + `Validation errors:
5771
+ ${errorList}
5772
+
5773
+ ` + `Please respond again with a JSON object that satisfies the schema. ` + `Output ONLY the JSON object, no other text.`;
5774
+ }
5775
+
6065
5776
  class StructuredGenerationTask extends StreamingAiTask {
6066
5777
  static type = "StructuredGenerationTask";
6067
5778
  static category = "AI Text Model";
6068
5779
  static title = "Structured Generation";
6069
- static description = "Generates structured JSON output conforming to a provided schema using language models";
5780
+ static description = "Generates structured JSON output conforming to a provided schema using language models, with automatic validation and retry on mismatch";
6070
5781
  static inputSchema() {
6071
5782
  return StructuredGenerationInputSchema;
6072
5783
  }
6073
5784
  static outputSchema() {
6074
5785
  return StructuredGenerationOutputSchema;
6075
5786
  }
5787
+ async* executeStream(input, context) {
5788
+ let validator;
5789
+ try {
5790
+ validator = compileSchema2(input.outputSchema);
5791
+ } catch (err2) {
5792
+ const msg = err2 instanceof Error ? err2.message : String(err2);
5793
+ const configErr = new TaskConfigurationError4(`StructuredGenerationTask: invalid outputSchema \u2014 ${msg}`);
5794
+ configErr.taskType = this.type;
5795
+ configErr.taskId = this.id;
5796
+ throw configErr;
5797
+ }
5798
+ const maxRetries = Math.max(0, input.maxRetries ?? 2);
5799
+ const maxAttempts = maxRetries + 1;
5800
+ const attempts = [];
5801
+ let currentInput = input;
5802
+ for (let attempt = 1;attempt <= maxAttempts; attempt++) {
5803
+ let lastObject;
5804
+ for await (const event of super.executeStream(currentInput, context)) {
5805
+ if (event.type === "object-delta" && event.port === "object") {
5806
+ const delta = event.objectDelta;
5807
+ if (delta && !Array.isArray(delta)) {
5808
+ lastObject = delta;
5809
+ }
5810
+ yield event;
5811
+ } else if (event.type === "finish") {
5812
+ const data = event.data;
5813
+ const finalObject = data?.object ?? lastObject ?? {};
5814
+ const result = validator.validate(finalObject);
5815
+ if (result.valid) {
5816
+ yield {
5817
+ type: "finish",
5818
+ data: { object: finalObject }
5819
+ };
5820
+ return;
5821
+ }
5822
+ const errors = validationErrorsFromSchemaNode(result);
5823
+ attempts.push({ attempt, errors, object: finalObject });
5824
+ lastObject = finalObject;
5825
+ break;
5826
+ } else {
5827
+ yield event;
5828
+ }
5829
+ }
5830
+ if (attempt < maxAttempts) {
5831
+ yield {
5832
+ type: "object-delta",
5833
+ port: "object",
5834
+ objectDelta: {}
5835
+ };
5836
+ const lastErrors = attempts[attempts.length - 1].errors;
5837
+ currentInput = {
5838
+ ...input,
5839
+ prompt: buildRetryPrompt(input.prompt, lastErrors)
5840
+ };
5841
+ }
5842
+ }
5843
+ const err = new StructuredOutputValidationError(attempts);
5844
+ err.taskType = this.type;
5845
+ err.taskId = this.id;
5846
+ throw err;
5847
+ }
5848
+ async execute(input, context) {
5849
+ let result;
5850
+ for await (const event of this.executeStream(input, context)) {
5851
+ if (event.type === "finish") {
5852
+ result = event.data;
5853
+ }
5854
+ }
5855
+ return result;
5856
+ }
6076
5857
  }
6077
5858
  var structuredGeneration = (input, config) => {
6078
5859
  return new StructuredGenerationTask(config).run(input);
6079
5860
  };
6080
- Workflow36.prototype.structuredGeneration = CreateWorkflow36(StructuredGenerationTask);
5861
+ Workflow34.prototype.structuredGeneration = CreateWorkflow34(StructuredGenerationTask);
6081
5862
 
6082
5863
  // src/task/TextChunkerTask.ts
6083
- import { CreateWorkflow as CreateWorkflow37, Task as Task18, Workflow as Workflow37 } from "@workglow/task-graph";
5864
+ import { CreateWorkflow as CreateWorkflow35, Task as Task17, Workflow as Workflow35 } from "@workglow/task-graph";
6084
5865
  var ChunkingStrategy = {
6085
5866
  FIXED: "fixed",
6086
5867
  SENTENCE: "sentence",
@@ -6149,7 +5930,7 @@ var outputSchema15 = {
6149
5930
  additionalProperties: false
6150
5931
  };
6151
5932
 
6152
- class TextChunkerTask extends Task18 {
5933
+ class TextChunkerTask extends Task17 {
6153
5934
  static type = "TextChunkerTask";
6154
5935
  static category = "Document";
6155
5936
  static title = "Text Chunker";
@@ -6329,11 +6110,11 @@ class TextChunkerTask extends Task18 {
6329
6110
  var textChunker = (input, config) => {
6330
6111
  return new TextChunkerTask(config).run(input);
6331
6112
  };
6332
- Workflow37.prototype.textChunker = CreateWorkflow37(TextChunkerTask);
6113
+ Workflow35.prototype.textChunker = CreateWorkflow35(TextChunkerTask);
6333
6114
 
6334
6115
  // src/task/TextFillMaskTask.ts
6335
- import { CreateWorkflow as CreateWorkflow38, Workflow as Workflow38 } from "@workglow/task-graph";
6336
- var modelSchema24 = TypeModel("model:TextFillMaskTask");
6116
+ import { CreateWorkflow as CreateWorkflow36, Workflow as Workflow36 } from "@workglow/task-graph";
6117
+ var modelSchema23 = TypeModel("model:TextFillMaskTask");
6337
6118
  var TextFillMaskInputSchema = {
6338
6119
  type: "object",
6339
6120
  properties: {
@@ -6342,7 +6123,7 @@ var TextFillMaskInputSchema = {
6342
6123
  title: "Text",
6343
6124
  description: "The text with a mask token to fill"
6344
6125
  },
6345
- model: modelSchema24
6126
+ model: modelSchema23
6346
6127
  },
6347
6128
  required: ["text", "model"],
6348
6129
  additionalProperties: false
@@ -6397,21 +6178,21 @@ class TextFillMaskTask extends AiTask {
6397
6178
  var textFillMask = (input, config) => {
6398
6179
  return new TextFillMaskTask(config).run(input);
6399
6180
  };
6400
- Workflow38.prototype.textFillMask = CreateWorkflow38(TextFillMaskTask);
6181
+ Workflow36.prototype.textFillMask = CreateWorkflow36(TextFillMaskTask);
6401
6182
 
6402
6183
  // src/task/TextGenerationTask.ts
6403
- import { CreateWorkflow as CreateWorkflow39, Workflow as Workflow39 } from "@workglow/task-graph";
6184
+ import { CreateWorkflow as CreateWorkflow37, Workflow as Workflow37 } from "@workglow/task-graph";
6404
6185
  var generatedTextSchema2 = {
6405
6186
  type: "string",
6406
6187
  title: "Text",
6407
6188
  description: "The generated text",
6408
6189
  "x-stream": "append"
6409
6190
  };
6410
- var modelSchema25 = TypeModel("model:TextGenerationTask");
6191
+ var modelSchema24 = TypeModel("model:TextGenerationTask");
6411
6192
  var TextGenerationInputSchema = {
6412
6193
  type: "object",
6413
6194
  properties: {
6414
- model: modelSchema25,
6195
+ model: modelSchema24,
6415
6196
  prompt: {
6416
6197
  type: "string",
6417
6198
  title: "Prompt",
@@ -6485,11 +6266,11 @@ class TextGenerationTask extends StreamingAiTask {
6485
6266
  var textGeneration = (input, config) => {
6486
6267
  return new TextGenerationTask(config).run(input);
6487
6268
  };
6488
- Workflow39.prototype.textGeneration = CreateWorkflow39(TextGenerationTask);
6269
+ Workflow37.prototype.textGeneration = CreateWorkflow37(TextGenerationTask);
6489
6270
 
6490
6271
  // src/task/TextLanguageDetectionTask.ts
6491
- import { CreateWorkflow as CreateWorkflow40, Workflow as Workflow40 } from "@workglow/task-graph";
6492
- var modelSchema26 = TypeModel("model:TextLanguageDetectionTask");
6272
+ import { CreateWorkflow as CreateWorkflow38, Workflow as Workflow38 } from "@workglow/task-graph";
6273
+ var modelSchema25 = TypeModel("model:TextLanguageDetectionTask");
6493
6274
  var TextLanguageDetectionInputSchema = {
6494
6275
  type: "object",
6495
6276
  properties: {
@@ -6506,7 +6287,7 @@ var TextLanguageDetectionInputSchema = {
6506
6287
  title: "Max Languages",
6507
6288
  description: "The maximum number of languages to return"
6508
6289
  },
6509
- model: modelSchema26
6290
+ model: modelSchema25
6510
6291
  },
6511
6292
  required: ["text", "model"],
6512
6293
  additionalProperties: false
@@ -6556,10 +6337,10 @@ class TextLanguageDetectionTask extends AiTask {
6556
6337
  var textLanguageDetection = (input, config) => {
6557
6338
  return new TextLanguageDetectionTask(config).run(input);
6558
6339
  };
6559
- Workflow40.prototype.textLanguageDetection = CreateWorkflow40(TextLanguageDetectionTask);
6340
+ Workflow38.prototype.textLanguageDetection = CreateWorkflow38(TextLanguageDetectionTask);
6560
6341
 
6561
6342
  // src/task/TextQuestionAnswerTask.ts
6562
- import { CreateWorkflow as CreateWorkflow41, Workflow as Workflow41 } from "@workglow/task-graph";
6343
+ import { CreateWorkflow as CreateWorkflow39, Workflow as Workflow39 } from "@workglow/task-graph";
6563
6344
  var contextSchema = {
6564
6345
  type: "string",
6565
6346
  title: "Context",
@@ -6576,13 +6357,13 @@ var textSchema = {
6576
6357
  description: "The generated text",
6577
6358
  "x-stream": "append"
6578
6359
  };
6579
- var modelSchema27 = TypeModel("model:TextQuestionAnswerTask");
6360
+ var modelSchema26 = TypeModel("model:TextQuestionAnswerTask");
6580
6361
  var TextQuestionAnswerInputSchema = {
6581
6362
  type: "object",
6582
6363
  properties: {
6583
6364
  context: contextSchema,
6584
6365
  question: questionSchema,
6585
- model: modelSchema27
6366
+ model: modelSchema26
6586
6367
  },
6587
6368
  required: ["context", "question", "model"],
6588
6369
  additionalProperties: false
@@ -6611,11 +6392,11 @@ class TextQuestionAnswerTask extends StreamingAiTask {
6611
6392
  var textQuestionAnswer = (input, config) => {
6612
6393
  return new TextQuestionAnswerTask(config).run(input);
6613
6394
  };
6614
- Workflow41.prototype.textQuestionAnswer = CreateWorkflow41(TextQuestionAnswerTask);
6395
+ Workflow39.prototype.textQuestionAnswer = CreateWorkflow39(TextQuestionAnswerTask);
6615
6396
 
6616
6397
  // src/task/TextRewriterTask.ts
6617
- import { CreateWorkflow as CreateWorkflow42, Workflow as Workflow42 } from "@workglow/task-graph";
6618
- var modelSchema28 = TypeModel("model:TextRewriterTask");
6398
+ import { CreateWorkflow as CreateWorkflow40, Workflow as Workflow40 } from "@workglow/task-graph";
6399
+ var modelSchema27 = TypeModel("model:TextRewriterTask");
6619
6400
  var TextRewriterInputSchema = {
6620
6401
  type: "object",
6621
6402
  properties: {
@@ -6629,7 +6410,7 @@ var TextRewriterInputSchema = {
6629
6410
  title: "Prompt",
6630
6411
  description: "The prompt to direct the rewriting"
6631
6412
  },
6632
- model: modelSchema28
6413
+ model: modelSchema27
6633
6414
  },
6634
6415
  required: ["text", "prompt", "model"],
6635
6416
  additionalProperties: false
@@ -6663,11 +6444,11 @@ class TextRewriterTask extends StreamingAiTask {
6663
6444
  var textRewriter = (input, config) => {
6664
6445
  return new TextRewriterTask(config).run(input);
6665
6446
  };
6666
- Workflow42.prototype.textRewriter = CreateWorkflow42(TextRewriterTask);
6447
+ Workflow40.prototype.textRewriter = CreateWorkflow40(TextRewriterTask);
6667
6448
 
6668
6449
  // src/task/TextTranslationTask.ts
6669
- import { CreateWorkflow as CreateWorkflow43, Workflow as Workflow43 } from "@workglow/task-graph";
6670
- var modelSchema29 = TypeModel("model:TextTranslationTask");
6450
+ import { CreateWorkflow as CreateWorkflow41, Workflow as Workflow41 } from "@workglow/task-graph";
6451
+ var modelSchema28 = TypeModel("model:TextTranslationTask");
6671
6452
  var translationTextSchema = {
6672
6453
  type: "string",
6673
6454
  title: "Text",
@@ -6694,7 +6475,7 @@ var TextTranslationInputSchema = {
6694
6475
  minLength: 2,
6695
6476
  maxLength: 2
6696
6477
  }),
6697
- model: modelSchema29
6478
+ model: modelSchema28
6698
6479
  },
6699
6480
  required: ["text", "source_lang", "target_lang", "model"],
6700
6481
  additionalProperties: false
@@ -6729,10 +6510,245 @@ class TextTranslationTask extends StreamingAiTask {
6729
6510
  var textTranslation = (input, config) => {
6730
6511
  return new TextTranslationTask(config).run(input);
6731
6512
  };
6732
- Workflow43.prototype.textTranslation = CreateWorkflow43(TextTranslationTask);
6513
+ Workflow41.prototype.textTranslation = CreateWorkflow41(TextTranslationTask);
6514
+
6515
+ // src/task/ToolCallingTask.ts
6516
+ import { CreateWorkflow as CreateWorkflow42, getTaskConstructors, Workflow as Workflow42 } from "@workglow/task-graph";
6517
+ import { makeFingerprint } from "@workglow/util";
6518
+ function taskTypesToTools(taskNames, registry) {
6519
+ const constructors = getTaskConstructors(registry);
6520
+ return taskNames.map((name) => {
6521
+ const ctor = constructors.get(name);
6522
+ if (!ctor) {
6523
+ throw new Error(`taskTypesToTools: Unknown task type "${name}" \u2014 not found in task constructors registry (ServiceRegistry: ${registry ? "custom" : "default"})`);
6524
+ }
6525
+ const configSchema = "configSchema" in ctor && typeof ctor.configSchema === "function" ? ctor.configSchema() : undefined;
6526
+ return {
6527
+ name: ctor.type,
6528
+ description: ctor.description ?? "",
6529
+ inputSchema: ctor.inputSchema(),
6530
+ outputSchema: ctor.outputSchema(),
6531
+ ...configSchema ? { configSchema } : {},
6532
+ taskType: name
6533
+ };
6534
+ });
6535
+ }
6536
+ var ToolDefinitionSchema = {
6537
+ type: "object",
6538
+ properties: {
6539
+ name: {
6540
+ type: "string",
6541
+ title: "Name",
6542
+ description: "The tool name"
6543
+ },
6544
+ description: {
6545
+ type: "string",
6546
+ title: "Description",
6547
+ description: "A description of what the tool does"
6548
+ },
6549
+ inputSchema: {
6550
+ type: "object",
6551
+ title: "Input Schema",
6552
+ description: "JSON Schema describing the tool's input parameters",
6553
+ additionalProperties: true
6554
+ },
6555
+ outputSchema: {
6556
+ type: "object",
6557
+ title: "Output Schema",
6558
+ description: "JSON Schema describing what the tool returns",
6559
+ additionalProperties: true
6560
+ },
6561
+ configSchema: {
6562
+ type: "object",
6563
+ title: "Config Schema",
6564
+ description: "JSON Schema describing the task's configuration options (not sent to the LLM)",
6565
+ additionalProperties: true
6566
+ },
6567
+ config: {
6568
+ type: "object",
6569
+ title: "Config",
6570
+ description: "Concrete configuration values for the backing task (not sent to the LLM)",
6571
+ additionalProperties: true
6572
+ }
6573
+ },
6574
+ required: ["name", "description", "inputSchema"],
6575
+ additionalProperties: true
6576
+ };
6577
+ var ToolCallSchema = {
6578
+ type: "object",
6579
+ properties: {
6580
+ id: {
6581
+ type: "string",
6582
+ title: "ID",
6583
+ description: "Unique identifier for this tool call"
6584
+ },
6585
+ name: {
6586
+ type: "string",
6587
+ title: "Name",
6588
+ description: "The name of the tool to invoke"
6589
+ },
6590
+ input: {
6591
+ type: "object",
6592
+ title: "Input",
6593
+ description: "The input arguments for the tool call",
6594
+ additionalProperties: true
6595
+ }
6596
+ },
6597
+ required: ["id", "name", "input"],
6598
+ additionalProperties: false
6599
+ };
6600
+ var modelSchema29 = TypeModel("model:ToolCallingTask");
6601
+ var ToolCallingInputSchema = {
6602
+ type: "object",
6603
+ properties: {
6604
+ model: modelSchema29,
6605
+ prompt: {
6606
+ oneOf: [
6607
+ { type: "string", title: "Prompt", description: "The prompt to send to the model" },
6608
+ {
6609
+ type: "array",
6610
+ title: "Prompt",
6611
+ description: "The prompt as an array of strings or content blocks",
6612
+ items: {
6613
+ oneOf: [
6614
+ { type: "string" },
6615
+ {
6616
+ type: "object",
6617
+ properties: {
6618
+ type: { type: "string", enum: ["text", "image", "audio"] }
6619
+ },
6620
+ required: ["type"],
6621
+ additionalProperties: true
6622
+ }
6623
+ ]
6624
+ }
6625
+ }
6626
+ ],
6627
+ title: "Prompt",
6628
+ description: "The prompt to send to the model"
6629
+ },
6630
+ systemPrompt: {
6631
+ type: "string",
6632
+ title: "System Prompt",
6633
+ description: "Optional system instructions for the model"
6634
+ },
6635
+ messages: {
6636
+ type: "array",
6637
+ title: "Messages",
6638
+ description: "Full conversation history for multi-turn interactions. When provided, used instead of prompt to construct the messages array sent to the provider.",
6639
+ items: ChatMessageSchema
6640
+ },
6641
+ tools: {
6642
+ type: "array",
6643
+ format: "tasks",
6644
+ title: "Tools",
6645
+ description: "Tool definitions available for the model to call",
6646
+ items: {
6647
+ oneOf: [
6648
+ { type: "string", format: "tasks", description: "Task type name" },
6649
+ ToolDefinitionSchema
6650
+ ]
6651
+ }
6652
+ },
6653
+ toolChoice: {
6654
+ type: "string",
6655
+ title: "Tool Choice",
6656
+ description: 'Controls tool selection: "auto" (model decides), "none" (no tools), "required" (must call a tool), or a specific tool name',
6657
+ "x-ui-group": "Configuration"
6658
+ },
6659
+ maxTokens: {
6660
+ type: "number",
6661
+ title: "Max Tokens",
6662
+ description: "The maximum number of tokens to generate",
6663
+ minimum: 1,
6664
+ "x-ui-group": "Configuration"
6665
+ },
6666
+ temperature: {
6667
+ type: "number",
6668
+ title: "Temperature",
6669
+ description: "The temperature to use for sampling",
6670
+ minimum: 0,
6671
+ maximum: 2,
6672
+ "x-ui-group": "Configuration"
6673
+ }
6674
+ },
6675
+ required: ["model", "prompt", "tools"],
6676
+ additionalProperties: false
6677
+ };
6678
+ var ToolCallingOutputSchema = {
6679
+ type: "object",
6680
+ properties: {
6681
+ text: {
6682
+ type: "string",
6683
+ title: "Text",
6684
+ description: "Any text content generated by the model",
6685
+ "x-stream": "append"
6686
+ },
6687
+ toolCalls: {
6688
+ type: "array",
6689
+ items: ToolCallSchema,
6690
+ title: "Tool Calls",
6691
+ description: "Tool calls requested by the model",
6692
+ "x-stream": "object"
6693
+ }
6694
+ },
6695
+ required: ["text", "toolCalls"],
6696
+ additionalProperties: false
6697
+ };
6698
+
6699
+ class ToolCallingTask extends StreamingAiTask {
6700
+ static type = "ToolCallingTask";
6701
+ static category = "AI Text Model";
6702
+ static title = "Tool Calling";
6703
+ static description = "Sends a prompt with tool definitions to a language model and returns text along with any tool calls the model requests";
6704
+ static inputSchema() {
6705
+ return ToolCallingInputSchema;
6706
+ }
6707
+ static outputSchema() {
6708
+ return ToolCallingOutputSchema;
6709
+ }
6710
+ _computedSessionId;
6711
+ async getJobInput(input) {
6712
+ const jobInput = await super.getJobInput(input);
6713
+ if (!jobInput.sessionId && input.tools && input.tools.length > 0) {
6714
+ jobInput.sessionId = await makeFingerprint({
6715
+ tools: input.tools,
6716
+ systemPrompt: input.systemPrompt,
6717
+ runnerId: this.runConfig.runnerId
6718
+ });
6719
+ this._computedSessionId = jobInput.sessionId;
6720
+ }
6721
+ return jobInput;
6722
+ }
6723
+ registerSessionDispose(input, context) {
6724
+ const sessionId = this._computedSessionId;
6725
+ if (!sessionId || !context.resourceScope)
6726
+ return;
6727
+ const model = input.model;
6728
+ if (!model || typeof model !== "object")
6729
+ return;
6730
+ const providerName = model.provider;
6731
+ context.resourceScope.register(`ai:session:${sessionId}`, async () => {
6732
+ await getAiProviderRegistry().disposeSession(providerName, sessionId);
6733
+ });
6734
+ }
6735
+ async execute(input, executeContext) {
6736
+ const result = await super.execute(input, executeContext);
6737
+ this.registerSessionDispose(input, executeContext);
6738
+ return result;
6739
+ }
6740
+ async* executeStream(input, context) {
6741
+ yield* super.executeStream(input, context);
6742
+ this.registerSessionDispose(input, context);
6743
+ }
6744
+ }
6745
+ var toolCalling = (input, config) => {
6746
+ return new ToolCallingTask(config).run(input);
6747
+ };
6748
+ Workflow42.prototype.toolCalling = CreateWorkflow42(ToolCallingTask);
6733
6749
 
6734
6750
  // src/task/TopicSegmenterTask.ts
6735
- import { CreateWorkflow as CreateWorkflow44, Task as Task19, Workflow as Workflow44 } from "@workglow/task-graph";
6751
+ import { CreateWorkflow as CreateWorkflow43, Task as Task18, Workflow as Workflow43 } from "@workglow/task-graph";
6736
6752
  var SegmentationMethod = {
6737
6753
  HEURISTIC: "heuristic",
6738
6754
  EMBEDDING_SIMILARITY: "embedding-similarity",
@@ -6807,7 +6823,7 @@ var outputSchema16 = {
6807
6823
  additionalProperties: false
6808
6824
  };
6809
6825
 
6810
- class TopicSegmenterTask extends Task19 {
6826
+ class TopicSegmenterTask extends Task18 {
6811
6827
  static type = "TopicSegmenterTask";
6812
6828
  static category = "Document";
6813
6829
  static title = "Topic Segmenter";
@@ -7012,10 +7028,10 @@ class TopicSegmenterTask extends Task19 {
7012
7028
  var topicSegmenter = (input, config) => {
7013
7029
  return new TopicSegmenterTask(config).run(input);
7014
7030
  };
7015
- Workflow44.prototype.topicSegmenter = CreateWorkflow44(TopicSegmenterTask);
7031
+ Workflow43.prototype.topicSegmenter = CreateWorkflow43(TopicSegmenterTask);
7016
7032
 
7017
7033
  // src/task/UnloadModelTask.ts
7018
- import { CreateWorkflow as CreateWorkflow45, Workflow as Workflow45 } from "@workglow/task-graph";
7034
+ import { CreateWorkflow as CreateWorkflow44, Workflow as Workflow44 } from "@workglow/task-graph";
7019
7035
  var modelSchema30 = TypeModel("model");
7020
7036
  var UnloadModelInputSchema = {
7021
7037
  type: "object",
@@ -7050,10 +7066,10 @@ class UnloadModelTask extends AiTask {
7050
7066
  var unloadModel = (input, config) => {
7051
7067
  return new UnloadModelTask(config).run(input);
7052
7068
  };
7053
- Workflow45.prototype.unloadModel = CreateWorkflow45(UnloadModelTask);
7069
+ Workflow44.prototype.unloadModel = CreateWorkflow44(UnloadModelTask);
7054
7070
 
7055
7071
  // src/task/VectorQuantizeTask.ts
7056
- import { CreateWorkflow as CreateWorkflow46, Task as Task20, Workflow as Workflow46 } from "@workglow/task-graph";
7072
+ import { CreateWorkflow as CreateWorkflow45, Task as Task19, Workflow as Workflow45 } from "@workglow/task-graph";
7057
7073
  import {
7058
7074
  normalizeNumberArray,
7059
7075
  TensorType,
@@ -7133,7 +7149,7 @@ var outputSchema17 = {
7133
7149
  additionalProperties: false
7134
7150
  };
7135
7151
 
7136
- class VectorQuantizeTask extends Task20 {
7152
+ class VectorQuantizeTask extends Task19 {
7137
7153
  static type = "VectorQuantizeTask";
7138
7154
  static category = "Vector";
7139
7155
  static title = "Quantize";
@@ -7233,10 +7249,10 @@ class VectorQuantizeTask extends Task20 {
7233
7249
  var vectorQuantize = (input, config) => {
7234
7250
  return new VectorQuantizeTask(config).run(input);
7235
7251
  };
7236
- Workflow46.prototype.vectorQuantize = CreateWorkflow46(VectorQuantizeTask);
7252
+ Workflow45.prototype.vectorQuantize = CreateWorkflow45(VectorQuantizeTask);
7237
7253
 
7238
7254
  // src/task/VectorSimilarityTask.ts
7239
- import { CreateWorkflow as CreateWorkflow47, GraphAsTask, Workflow as Workflow47 } from "@workglow/task-graph";
7255
+ import { CreateWorkflow as CreateWorkflow46, GraphAsTask, Workflow as Workflow46 } from "@workglow/task-graph";
7240
7256
  import {
7241
7257
  cosineSimilarity,
7242
7258
  hammingSimilarity,
@@ -7342,7 +7358,7 @@ class VectorSimilarityTask extends GraphAsTask {
7342
7358
  var similarity = (input, config) => {
7343
7359
  return new VectorSimilarityTask(config).run(input);
7344
7360
  };
7345
- Workflow47.prototype.similarity = CreateWorkflow47(VectorSimilarityTask);
7361
+ Workflow46.prototype.similarity = CreateWorkflow46(VectorSimilarityTask);
7346
7362
  // src/task/MessageConversion.ts
7347
7363
  function getInputMessages(input) {
7348
7364
  const messages = input.messages;
@@ -7391,66 +7407,46 @@ function toOpenAIMessages(input) {
7391
7407
  }
7392
7408
  for (const msg of inputMessages) {
7393
7409
  if (msg.role === "user") {
7394
- if (typeof msg.content === "string") {
7395
- messages.push({ role: "user", content: msg.content });
7396
- } else if (Array.isArray(msg.content) && msg.content.length > 0 && typeof msg.content[0]?.type === "string") {
7397
- const parts = [];
7398
- for (const block of msg.content) {
7399
- const b = block;
7400
- if (b.type === "text") {
7401
- parts.push({ type: "text", text: b.text });
7402
- } else if (b.type === "image") {
7403
- parts.push({
7404
- type: "image_url",
7405
- image_url: { url: `data:${b.mimeType};base64,${b.data}` }
7406
- });
7407
- } else if (b.type === "audio") {
7408
- const format = b.mimeType.replace(/^audio\//, "");
7409
- parts.push({
7410
- type: "input_audio",
7411
- input_audio: { data: b.data, format }
7412
- });
7413
- }
7414
- }
7415
- messages.push({ role: "user", content: parts });
7416
- } else {
7417
- try {
7418
- messages.push({ role: "user", content: JSON.stringify(msg.content) });
7419
- } catch {
7420
- messages.push({ role: "user", content: String(msg.content) });
7410
+ const parts = [];
7411
+ for (const block of msg.content) {
7412
+ if (block.type === "text") {
7413
+ parts.push({ type: "text", text: block.text });
7414
+ } else if (block.type === "image") {
7415
+ parts.push({
7416
+ type: "image_url",
7417
+ image_url: { url: `data:${block.mimeType};base64,${block.data}` }
7418
+ });
7421
7419
  }
7422
7420
  }
7421
+ messages.push({ role: "user", content: parts });
7423
7422
  } else if (msg.role === "assistant") {
7424
- if (typeof msg.content === "string") {
7425
- messages.push({ role: "assistant", content: msg.content.length > 0 ? msg.content : null });
7426
- } else if (Array.isArray(msg.content)) {
7427
- const textParts = msg.content.filter((b) => b.type === "text").map((b) => b.text).join("");
7428
- const toolCalls = msg.content.filter((b) => b.type === "tool_use").map((b) => ({
7429
- id: b.id,
7430
- type: "function",
7431
- function: {
7432
- name: b.name,
7433
- arguments: JSON.stringify(b.input)
7434
- }
7435
- }));
7436
- const entry = {
7437
- role: "assistant",
7438
- content: textParts.length > 0 ? textParts : null
7439
- };
7440
- if (toolCalls.length > 0) {
7441
- entry.tool_calls = toolCalls;
7423
+ const textParts = msg.content.filter((b) => b.type === "text").map((b) => b.text).join("");
7424
+ const toolCalls = msg.content.filter((b) => b.type === "tool_use").map((b) => ({
7425
+ id: b.id,
7426
+ type: "function",
7427
+ function: {
7428
+ name: b.name,
7429
+ arguments: JSON.stringify(b.input)
7442
7430
  }
7443
- messages.push(entry);
7431
+ }));
7432
+ const entry = {
7433
+ role: "assistant",
7434
+ content: textParts.length > 0 ? textParts : null
7435
+ };
7436
+ if (toolCalls.length > 0) {
7437
+ entry.tool_calls = toolCalls;
7444
7438
  }
7445
- } else if (msg.role === "tool" && Array.isArray(msg.content)) {
7439
+ messages.push(entry);
7440
+ } else if (msg.role === "tool") {
7446
7441
  for (const block of msg.content) {
7447
- const b = block;
7442
+ if (block.type !== "tool_result")
7443
+ continue;
7448
7444
  let content;
7449
- if (typeof b.content === "string") {
7450
- content = b.content;
7451
- } else if (Array.isArray(b.content)) {
7445
+ if (block.content.length === 1 && block.content[0].type === "text") {
7446
+ content = block.content[0].text;
7447
+ } else {
7452
7448
  const parts = [];
7453
- for (const inner of b.content) {
7449
+ for (const inner of block.content) {
7454
7450
  if (inner.type === "text") {
7455
7451
  parts.push({ type: "text", text: inner.text });
7456
7452
  } else if (inner.type === "image") {
@@ -7461,14 +7457,8 @@ function toOpenAIMessages(input) {
7461
7457
  }
7462
7458
  }
7463
7459
  content = parts;
7464
- } else {
7465
- content = "";
7466
7460
  }
7467
- messages.push({
7468
- role: "tool",
7469
- content,
7470
- tool_call_id: b.tool_use_id
7471
- });
7461
+ messages.push({ role: "tool", content, tool_call_id: block.tool_use_id });
7472
7462
  }
7473
7463
  }
7474
7464
  }
@@ -7498,41 +7488,18 @@ function toTextFlatMessages(input) {
7498
7488
  }
7499
7489
  for (const msg of inputMessages) {
7500
7490
  if (msg.role === "user") {
7501
- let content = "";
7502
- if (typeof msg.content === "string") {
7503
- content = msg.content;
7504
- } else if (Array.isArray(msg.content) && msg.content.length > 0 && typeof msg.content[0]?.type === "string") {
7505
- content = msg.content.filter((b) => b.type === "text").map((b) => b.text).join("");
7506
- } else if (msg.content != null) {
7507
- try {
7508
- content = JSON.stringify(msg.content);
7509
- } catch {
7510
- content = String(msg.content);
7511
- }
7512
- }
7491
+ const content = msg.content.filter((b) => b.type === "text").map((b) => b.text).join("");
7513
7492
  messages.push({ role: "user", content });
7514
7493
  } else if (msg.role === "assistant") {
7515
- if (typeof msg.content === "string") {
7516
- if (msg.content) {
7517
- messages.push({ role: "assistant", content: msg.content });
7518
- }
7519
- } else if (Array.isArray(msg.content)) {
7520
- const text = msg.content.filter((b) => b.type === "text").map((b) => b.text).join("");
7521
- if (text) {
7522
- messages.push({ role: "assistant", content: text });
7523
- }
7494
+ const text = msg.content.filter((b) => b.type === "text").map((b) => b.text).join("");
7495
+ if (text) {
7496
+ messages.push({ role: "assistant", content: text });
7524
7497
  }
7525
- } else if (msg.role === "tool" && Array.isArray(msg.content)) {
7498
+ } else if (msg.role === "tool") {
7526
7499
  for (const block of msg.content) {
7527
- const b = block;
7528
- let content;
7529
- if (typeof b.content === "string") {
7530
- content = b.content;
7531
- } else if (Array.isArray(b.content)) {
7532
- content = b.content.filter((inner) => inner.type === "text").map((inner) => inner.text).join("");
7533
- } else {
7534
- content = "";
7535
- }
7500
+ if (block.type !== "tool_result")
7501
+ continue;
7502
+ const content = block.content.filter((inner) => inner.type === "text").map((inner) => inner.text).join("");
7536
7503
  messages.push({ role: "tool", content });
7537
7504
  }
7538
7505
  }
@@ -7543,7 +7510,7 @@ function toTextFlatMessages(input) {
7543
7510
  // src/task/index.ts
7544
7511
  var registerAiTasks = () => {
7545
7512
  const tasks = [
7546
- AgentTask,
7513
+ AiChatTask,
7547
7514
  BackgroundRemovalTask,
7548
7515
  ChunkToVectorTask,
7549
7516
  CountTokensTask,
@@ -7597,11 +7564,8 @@ var registerAiTasks = () => {
7597
7564
  export {
7598
7565
  vectorStoreSearch,
7599
7566
  vectorQuantize,
7600
- userMessage,
7601
7567
  unloadModel,
7602
7568
  topicSegmenter,
7603
- toolSourceDefinitions,
7604
- toolMessage,
7605
7569
  toolCalling,
7606
7570
  toTextFlatMessages,
7607
7571
  toOpenAIMessages,
@@ -7610,6 +7574,7 @@ export {
7610
7574
  textRewriter,
7611
7575
  textQuestionAnswer,
7612
7576
  textNamedEntityRecognition,
7577
+ textMessage,
7613
7578
  textLanguageDetection,
7614
7579
  textGeneration,
7615
7580
  textFillMask,
@@ -7631,43 +7596,33 @@ export {
7631
7596
  modelSearch,
7632
7597
  modelInfo,
7633
7598
  kbToDocuments,
7599
+ isContentBlock,
7600
+ isChatMessage,
7634
7601
  isAllowedToolName,
7635
7602
  imageToText,
7636
7603
  imageSegmentation,
7637
7604
  imageEmbedding,
7638
7605
  imageClassification,
7639
- imageBlockFromDataUri,
7640
- imageBlock,
7641
7606
  hybridSearch,
7642
7607
  hierarchyJoin,
7643
7608
  hierarchicalChunker,
7644
- hasToolCalls,
7645
7609
  handLandmarker,
7646
7610
  getGlobalModelRepository,
7647
7611
  getAiProviderRegistry,
7648
7612
  gestureRecognizer,
7649
- findToolSource,
7650
7613
  filterValidToolCalls,
7651
7614
  faceLandmarker,
7652
7615
  faceDetector,
7653
- executeToolCalls,
7654
- executeToolCall,
7655
7616
  downloadModel,
7656
7617
  documentUpsert,
7657
7618
  documentEnricher,
7658
7619
  countTokens,
7659
- countAssistantToolUses,
7660
7620
  contextBuilder,
7661
7621
  chunkVectorUpsert,
7662
7622
  chunkToVector,
7663
7623
  chunkRetrieval,
7664
- buildToolSources,
7665
7624
  buildToolDescription,
7666
7625
  backgroundRemoval,
7667
- audioBlockFromDataUri,
7668
- audioBlock,
7669
- assistantMessage,
7670
- agent,
7671
7626
  VectorSimilarityTask,
7672
7627
  VectorQuantizeTask,
7673
7628
  UnloadModelTask,
@@ -7716,6 +7671,7 @@ export {
7716
7671
  TextClassificationOutputSchema,
7717
7672
  TextClassificationInputSchema,
7718
7673
  TextChunkerTask,
7674
+ StructuredOutputValidationError,
7719
7675
  StructuredGenerationTask,
7720
7676
  StructuredGenerationOutputSchema,
7721
7677
  StructuredGenerationInputSchema,
@@ -7779,12 +7735,14 @@ export {
7779
7735
  CountTokensInputSchema,
7780
7736
  ContextFormat,
7781
7737
  ContextBuilderTask,
7738
+ ContentBlockSchema,
7782
7739
  ChunkingStrategy,
7783
7740
  ChunkVectorUpsertTask,
7784
7741
  ChunkVectorSearchTask,
7785
7742
  ChunkVectorHybridSearchTask,
7786
7743
  ChunkToVectorTask,
7787
7744
  ChunkRetrievalTask,
7745
+ ChatMessageSchema,
7788
7746
  BackgroundRemovalTask,
7789
7747
  BackgroundRemovalOutputSchema,
7790
7748
  BackgroundRemovalInputSchema,
@@ -7792,9 +7750,9 @@ export {
7792
7750
  AiProviderRegistry,
7793
7751
  AiProvider,
7794
7752
  AiJob,
7795
- AgentTask,
7796
- AgentOutputSchema,
7797
- AgentInputSchema
7753
+ AiChatTask,
7754
+ AiChatOutputSchema,
7755
+ AiChatInputSchema
7798
7756
  };
7799
7757
 
7800
- //# debugId=8A9763DF6FDECCDA64756E2164756E21
7758
+ //# debugId=4A4F2C3AAA2FA8C064756E2164756E21