@workglow/ai 0.0.116 → 0.0.118

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.
package/dist/browser.js CHANGED
@@ -421,8 +421,83 @@ class AiProvider {
421
421
  // src/task/index.ts
422
422
  import { TaskRegistry } from "@workglow/task-graph";
423
423
 
424
- // src/task/BackgroundRemovalTask.ts
425
- import { CreateWorkflow, Workflow } from "@workglow/task-graph";
424
+ // src/task/AgentTask.ts
425
+ import {
426
+ CreateWorkflow as CreateWorkflow2,
427
+ Task,
428
+ Workflow as Workflow2
429
+ } from "@workglow/task-graph";
430
+ import { getLogger as getLogger3 } from "@workglow/util";
431
+
432
+ // src/task/AgentTypes.ts
433
+ import { parseDataUri } from "@workglow/util";
434
+ function imageBlock(mimeType, data) {
435
+ return { type: "image", mimeType, data };
436
+ }
437
+ function audioBlock(mimeType, data) {
438
+ return { type: "audio", mimeType, data };
439
+ }
440
+ function imageBlockFromDataUri(dataUri) {
441
+ const { mimeType, base64 } = parseDataUri(dataUri);
442
+ return { type: "image", mimeType, data: base64 };
443
+ }
444
+ function audioBlockFromDataUri(dataUri) {
445
+ const { mimeType, base64 } = parseDataUri(dataUri);
446
+ return { type: "audio", mimeType, data: base64 };
447
+ }
448
+ function userMessage(prompt) {
449
+ return { role: "user", content: prompt };
450
+ }
451
+ function assistantMessage(text, toolCalls) {
452
+ const content = [];
453
+ if (text) {
454
+ content.push({ type: "text", text });
455
+ }
456
+ if (toolCalls) {
457
+ for (const tc of toolCalls) {
458
+ content.push({
459
+ type: "tool_use",
460
+ id: tc.id,
461
+ name: tc.name,
462
+ input: tc.input
463
+ });
464
+ }
465
+ }
466
+ return { role: "assistant", content };
467
+ }
468
+ function toolMessage(results) {
469
+ return {
470
+ role: "tool",
471
+ content: results.map((r) => {
472
+ const jsonText = JSON.stringify(r.output);
473
+ const content = r.mediaContent && r.mediaContent.length > 0 ? [{ type: "text", text: jsonText }, ...r.mediaContent] : jsonText;
474
+ return {
475
+ type: "tool_result",
476
+ tool_use_id: r.toolCallId,
477
+ content,
478
+ is_error: r.isError || undefined
479
+ };
480
+ })
481
+ };
482
+ }
483
+ function toolSourceDefinitions(sources) {
484
+ return sources.map((s) => s.definition);
485
+ }
486
+ function findToolSource(sources, name) {
487
+ return sources.find((s) => s.definition.name === name);
488
+ }
489
+
490
+ // src/task/AgentUtils.ts
491
+ import { getTaskConstructors as getTaskConstructors2 } from "@workglow/task-graph";
492
+ import { getLogger as getLogger2 } from "@workglow/util";
493
+
494
+ // src/task/ToolCallingTask.ts
495
+ import {
496
+ CreateWorkflow,
497
+ getTaskConstructors,
498
+ Workflow
499
+ } from "@workglow/task-graph";
500
+ import { getLogger } from "@workglow/util";
426
501
 
427
502
  // src/task/base/AiTaskSchemas.ts
428
503
  var TypeLanguage = (annotations = {}) => ({
@@ -581,8 +656,10 @@ var TypeCategory = {
581
656
  description: "Classification category with label and score"
582
657
  };
583
658
 
584
- // src/task/base/AiVisionTask.ts
585
- import { convertImageDataToUseableForm } from "@workglow/util";
659
+ // src/task/base/StreamingAiTask.ts
660
+ import {
661
+ getStreamingPorts
662
+ } from "@workglow/task-graph";
586
663
 
587
664
  // src/task/base/AiTask.ts
588
665
  import {
@@ -711,7 +788,667 @@ class AiTask extends JobQueueTask {
711
788
  }
712
789
  }
713
790
 
791
+ // src/task/base/StreamingAiTask.ts
792
+ class StreamingAiTask extends AiTask {
793
+ static type = "StreamingAiTask";
794
+ async* executeStream(input, context) {
795
+ const jobInput = await this.getJobInput(input);
796
+ const queueName = await this.getDefaultQueueName(input);
797
+ const job = new AiJob({
798
+ queueName: queueName ?? this.type,
799
+ jobRunId: this.runConfig.runnerId,
800
+ input: jobInput
801
+ });
802
+ const ports = getStreamingPorts(this.outputSchema());
803
+ const defaultPort = ports.length > 0 ? ports[0].port : "text";
804
+ for await (const event of job.executeStream(jobInput, {
805
+ signal: context.signal,
806
+ updateProgress: context.updateProgress.bind(this)
807
+ })) {
808
+ if (event.type === "text-delta") {
809
+ yield { ...event, port: event.port ?? defaultPort };
810
+ } else if (event.type === "object-delta") {
811
+ yield { ...event, port: event.port ?? defaultPort };
812
+ } else {
813
+ yield event;
814
+ }
815
+ }
816
+ }
817
+ }
818
+
819
+ // src/task/ToolCallingTask.ts
820
+ function buildToolDescription(tool) {
821
+ let desc = tool.description;
822
+ if (tool.outputSchema && typeof tool.outputSchema === "object") {
823
+ desc += `
824
+
825
+ Returns: ${JSON.stringify(tool.outputSchema)}`;
826
+ }
827
+ return desc;
828
+ }
829
+ function isAllowedToolName(name, allowedTools) {
830
+ return allowedTools.some((t) => t.name === name);
831
+ }
832
+ function filterValidToolCalls(toolCalls, allowedTools) {
833
+ return toolCalls.filter((tc) => {
834
+ if (tc.name && isAllowedToolName(tc.name, allowedTools)) {
835
+ return true;
836
+ }
837
+ getLogger().warn(`Filtered out tool call with unknown name "${tc.name ?? "(missing)"}"`, {
838
+ callId: tc.id,
839
+ toolName: tc.name
840
+ });
841
+ return false;
842
+ });
843
+ }
844
+ function taskTypesToTools(taskNames, registry) {
845
+ const constructors = getTaskConstructors(registry);
846
+ return taskNames.map((name) => {
847
+ const ctor = constructors.get(name);
848
+ if (!ctor) {
849
+ throw new Error(`taskTypesToTools: Unknown task type "${name}" — not found in task constructors registry (ServiceRegistry: ${registry ? "custom" : "default"})`);
850
+ }
851
+ const configSchema = "configSchema" in ctor && typeof ctor.configSchema === "function" ? ctor.configSchema() : undefined;
852
+ return {
853
+ name: ctor.type,
854
+ description: ctor.description ?? "",
855
+ inputSchema: ctor.inputSchema(),
856
+ outputSchema: ctor.outputSchema(),
857
+ ...configSchema ? { configSchema } : {},
858
+ taskType: name
859
+ };
860
+ });
861
+ }
862
+ var ToolDefinitionSchema = {
863
+ type: "object",
864
+ properties: {
865
+ name: {
866
+ type: "string",
867
+ title: "Name",
868
+ description: "The tool name"
869
+ },
870
+ description: {
871
+ type: "string",
872
+ title: "Description",
873
+ description: "A description of what the tool does"
874
+ },
875
+ inputSchema: {
876
+ type: "object",
877
+ title: "Input Schema",
878
+ description: "JSON Schema describing the tool's input parameters",
879
+ additionalProperties: true
880
+ },
881
+ outputSchema: {
882
+ type: "object",
883
+ title: "Output Schema",
884
+ description: "JSON Schema describing what the tool returns",
885
+ additionalProperties: true
886
+ },
887
+ configSchema: {
888
+ type: "object",
889
+ title: "Config Schema",
890
+ description: "JSON Schema describing the task's configuration options (not sent to the LLM)",
891
+ additionalProperties: true
892
+ },
893
+ config: {
894
+ type: "object",
895
+ title: "Config",
896
+ description: "Concrete configuration values for the backing task (not sent to the LLM)",
897
+ additionalProperties: true
898
+ }
899
+ },
900
+ required: ["name", "description", "inputSchema"],
901
+ additionalProperties: true
902
+ };
903
+ var ToolCallSchema = {
904
+ type: "object",
905
+ properties: {
906
+ id: {
907
+ type: "string",
908
+ title: "ID",
909
+ description: "Unique identifier for this tool call"
910
+ },
911
+ name: {
912
+ type: "string",
913
+ title: "Name",
914
+ description: "The name of the tool to invoke"
915
+ },
916
+ input: {
917
+ type: "object",
918
+ title: "Input",
919
+ description: "The input arguments for the tool call",
920
+ additionalProperties: true
921
+ }
922
+ },
923
+ required: ["id", "name", "input"],
924
+ additionalProperties: false
925
+ };
926
+ var modelSchema = TypeModel("model:ToolCallingTask");
927
+ var ToolCallingInputSchema = {
928
+ type: "object",
929
+ properties: {
930
+ model: modelSchema,
931
+ prompt: {
932
+ oneOf: [
933
+ { type: "string", title: "Prompt", description: "The prompt to send to the model" },
934
+ {
935
+ type: "array",
936
+ title: "Prompt",
937
+ description: "The prompt as an array of strings or content blocks",
938
+ items: {
939
+ oneOf: [
940
+ { type: "string" },
941
+ {
942
+ type: "object",
943
+ properties: {
944
+ type: { type: "string", enum: ["text", "image", "audio"] }
945
+ },
946
+ required: ["type"],
947
+ additionalProperties: true
948
+ }
949
+ ]
950
+ }
951
+ }
952
+ ],
953
+ title: "Prompt",
954
+ description: "The prompt to send to the model"
955
+ },
956
+ systemPrompt: {
957
+ type: "string",
958
+ title: "System Prompt",
959
+ description: "Optional system instructions for the model"
960
+ },
961
+ messages: {
962
+ type: "array",
963
+ title: "Messages",
964
+ description: "Full conversation history for multi-turn interactions. When provided, used instead of prompt to construct the messages array sent to the provider.",
965
+ items: {
966
+ type: "object",
967
+ properties: {
968
+ role: { type: "string", enum: ["user", "assistant", "tool"] },
969
+ content: {}
970
+ },
971
+ required: ["role", "content"],
972
+ additionalProperties: true
973
+ }
974
+ },
975
+ tools: {
976
+ type: "array",
977
+ format: "tasks",
978
+ title: "Tools",
979
+ description: "Tool definitions available for the model to call",
980
+ items: {
981
+ oneOf: [
982
+ { type: "string", format: "tasks", description: "Task type name" },
983
+ ToolDefinitionSchema
984
+ ]
985
+ }
986
+ },
987
+ toolChoice: {
988
+ type: "string",
989
+ title: "Tool Choice",
990
+ description: 'Controls tool selection: "auto" (model decides), "none" (no tools), "required" (must call a tool), or a specific tool name',
991
+ "x-ui-group": "Configuration"
992
+ },
993
+ maxTokens: {
994
+ type: "number",
995
+ title: "Max Tokens",
996
+ description: "The maximum number of tokens to generate",
997
+ minimum: 1,
998
+ "x-ui-group": "Configuration"
999
+ },
1000
+ temperature: {
1001
+ type: "number",
1002
+ title: "Temperature",
1003
+ description: "The temperature to use for sampling",
1004
+ minimum: 0,
1005
+ maximum: 2,
1006
+ "x-ui-group": "Configuration"
1007
+ }
1008
+ },
1009
+ required: ["model", "prompt", "tools"],
1010
+ additionalProperties: false
1011
+ };
1012
+ var ToolCallingOutputSchema = {
1013
+ type: "object",
1014
+ properties: {
1015
+ text: TypeSingleOrArray({
1016
+ type: "string",
1017
+ title: "Text",
1018
+ description: "Any text content generated by the model",
1019
+ "x-stream": "append"
1020
+ }),
1021
+ toolCalls: TypeSingleOrArray({
1022
+ ...ToolCallSchema,
1023
+ "x-stream": "object"
1024
+ })
1025
+ },
1026
+ required: ["text", "toolCalls"],
1027
+ additionalProperties: false
1028
+ };
1029
+
1030
+ class ToolCallingTask extends StreamingAiTask {
1031
+ static type = "ToolCallingTask";
1032
+ static category = "AI Text Model";
1033
+ static title = "Tool Calling";
1034
+ static description = "Sends a prompt with tool definitions to a language model and returns text along with any tool calls the model requests";
1035
+ static inputSchema() {
1036
+ return ToolCallingInputSchema;
1037
+ }
1038
+ static outputSchema() {
1039
+ return ToolCallingOutputSchema;
1040
+ }
1041
+ }
1042
+ var toolCalling = (input, config) => {
1043
+ return new ToolCallingTask({}, config).run(input);
1044
+ };
1045
+ Workflow.prototype.toolCalling = CreateWorkflow(ToolCallingTask);
1046
+
1047
+ // src/task/AgentUtils.ts
1048
+ function buildToolSources(tools, registry) {
1049
+ if (!tools || tools.length === 0)
1050
+ return [];
1051
+ const stringNames = tools.filter((t) => typeof t === "string");
1052
+ const resolvedDefs = new Map(taskTypesToTools(stringNames, registry).map((d) => [d.taskType, d]));
1053
+ const constructors = getTaskConstructors2(registry);
1054
+ const sources = [];
1055
+ for (const tool of tools) {
1056
+ if (typeof tool === "string") {
1057
+ const def = resolvedDefs.get(tool);
1058
+ if (def) {
1059
+ const { taskType, ...definition } = def;
1060
+ sources.push({
1061
+ type: "registry",
1062
+ definition,
1063
+ taskType
1064
+ });
1065
+ }
1066
+ } else if (tool.execute) {
1067
+ const { execute, configSchema: _cs, config: _c, ...definition } = tool;
1068
+ sources.push({
1069
+ type: "function",
1070
+ definition,
1071
+ run: execute
1072
+ });
1073
+ } else {
1074
+ const ctor = constructors.get(tool.name);
1075
+ if (ctor) {
1076
+ const { execute: _e, configSchema: _cs, config: _c, ...definition } = tool;
1077
+ sources.push({
1078
+ type: "registry",
1079
+ definition,
1080
+ taskType: tool.name,
1081
+ config: tool.config
1082
+ });
1083
+ } else {
1084
+ const { execute: _e, configSchema: _cs, config: _c, ...definition } = tool;
1085
+ sources.push({
1086
+ type: "function",
1087
+ definition,
1088
+ run: async () => {
1089
+ throw new Error(`No executor registered for tool "${tool.name}"`);
1090
+ }
1091
+ });
1092
+ }
1093
+ }
1094
+ }
1095
+ return sources;
1096
+ }
1097
+ async function executeToolCall(toolCall, sources, context, hooks) {
1098
+ const source = findToolSource(sources, toolCall.name);
1099
+ if (!source) {
1100
+ getLogger2().warn(`AgentTask: Unknown tool "${toolCall.name}" — not found in tool sources`);
1101
+ return {
1102
+ toolCallId: toolCall.id,
1103
+ toolName: toolCall.name,
1104
+ output: { error: `Unknown tool: ${toolCall.name}` },
1105
+ isError: true
1106
+ };
1107
+ }
1108
+ let effectiveCall = toolCall;
1109
+ if (hooks?.beforeToolCall) {
1110
+ const decision = await hooks.beforeToolCall(toolCall, source);
1111
+ if (decision.action === "deny") {
1112
+ return {
1113
+ toolCallId: toolCall.id,
1114
+ toolName: toolCall.name,
1115
+ output: { error: decision.reason ?? "Tool call denied by hook" },
1116
+ isError: true
1117
+ };
1118
+ }
1119
+ if (decision.action === "modify") {
1120
+ effectiveCall = { ...toolCall, input: decision.input };
1121
+ }
1122
+ }
1123
+ try {
1124
+ let output;
1125
+ switch (source.type) {
1126
+ case "registry": {
1127
+ const ctor = getTaskConstructors2(context.registry).get(source.taskType);
1128
+ if (!ctor) {
1129
+ throw new Error(`Task type "${source.taskType}" not found in TaskRegistry`);
1130
+ }
1131
+ const taskConfig = source.config ?? {};
1132
+ const task = context.own(new ctor({}, taskConfig));
1133
+ output = await task.run(effectiveCall.input) ?? {};
1134
+ break;
1135
+ }
1136
+ case "function": {
1137
+ output = await source.run(effectiveCall.input);
1138
+ break;
1139
+ }
1140
+ }
1141
+ let result = {
1142
+ toolCallId: toolCall.id,
1143
+ toolName: toolCall.name,
1144
+ output,
1145
+ isError: false
1146
+ };
1147
+ if (hooks?.afterToolCall) {
1148
+ result = await hooks.afterToolCall(toolCall, result);
1149
+ }
1150
+ return result;
1151
+ } catch (err) {
1152
+ const error = err instanceof Error ? err : new Error(String(err));
1153
+ if (hooks?.onToolError) {
1154
+ const action = await hooks.onToolError(toolCall, error);
1155
+ if (action.action === "result") {
1156
+ return {
1157
+ toolCallId: toolCall.id,
1158
+ toolName: toolCall.name,
1159
+ output: action.output,
1160
+ isError: false
1161
+ };
1162
+ }
1163
+ }
1164
+ getLogger2().warn(`AgentTask: Tool "${toolCall.name}" failed: ${error.message}`);
1165
+ return {
1166
+ toolCallId: toolCall.id,
1167
+ toolName: toolCall.name,
1168
+ output: { error: error.message },
1169
+ isError: true
1170
+ };
1171
+ }
1172
+ }
1173
+ async function executeToolCalls(toolCalls, sources, context, hooks, maxConcurrency = 5) {
1174
+ const calls = toolCalls;
1175
+ if (calls.length === 0)
1176
+ return [];
1177
+ const concurrency = Math.max(1, Math.min(maxConcurrency, calls.length));
1178
+ const results = new Array(calls.length);
1179
+ let cursor = 0;
1180
+ const workers = Array.from({ length: concurrency }, async () => {
1181
+ while (true) {
1182
+ if (context.signal.aborted) {
1183
+ throw context.signal.reason ?? new DOMException("The operation was aborted", "AbortError");
1184
+ }
1185
+ const position = cursor;
1186
+ cursor += 1;
1187
+ if (position >= calls.length)
1188
+ return;
1189
+ results[position] = await executeToolCall(calls[position], sources, context, hooks);
1190
+ }
1191
+ });
1192
+ await Promise.all(workers);
1193
+ return results;
1194
+ }
1195
+ function hasToolCalls(toolCalls) {
1196
+ return toolCalls !== undefined && toolCalls.length > 0;
1197
+ }
1198
+
1199
+ // src/task/AgentTask.ts
1200
+ var modelSchema2 = TypeModel("model:ToolCallingTask");
1201
+ var AgentInputSchema = {
1202
+ type: "object",
1203
+ properties: {
1204
+ model: modelSchema2,
1205
+ prompt: {
1206
+ oneOf: [
1207
+ { type: "string" },
1208
+ {
1209
+ type: "array",
1210
+ items: {
1211
+ type: "object",
1212
+ properties: {
1213
+ type: { type: "string", enum: ["text", "image", "audio"] }
1214
+ },
1215
+ required: ["type"],
1216
+ additionalProperties: true
1217
+ }
1218
+ }
1219
+ ],
1220
+ title: "Prompt",
1221
+ description: "The user prompt to start the agent loop. Can be a string or an array of content blocks (text, image, audio)."
1222
+ },
1223
+ systemPrompt: {
1224
+ type: "string",
1225
+ title: "System Prompt",
1226
+ description: "Optional system instructions for the agent"
1227
+ },
1228
+ tools: {
1229
+ type: "array",
1230
+ format: "tasks",
1231
+ title: "Tools",
1232
+ 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.",
1233
+ items: {
1234
+ oneOf: [
1235
+ { type: "string", format: "tasks", description: "Task type name" },
1236
+ ToolDefinitionSchema
1237
+ ]
1238
+ }
1239
+ },
1240
+ stopTool: {
1241
+ type: "string",
1242
+ title: "Stop Tool",
1243
+ description: "Name of a tool that signals agent completion. When called, the loop ends and the tool input becomes structuredOutput.",
1244
+ "x-ui-group": "Configuration"
1245
+ },
1246
+ maxIterations: {
1247
+ type: "number",
1248
+ title: "Max Iterations",
1249
+ description: "Maximum number of agent loop iterations (default: 10)",
1250
+ minimum: 1,
1251
+ "x-ui-group": "Configuration"
1252
+ },
1253
+ maxContextMessages: {
1254
+ type: "number",
1255
+ title: "Max Context Messages",
1256
+ description: "Maximum messages in conversation history. Older messages are trimmed to prevent context overflow.",
1257
+ minimum: 3,
1258
+ "x-ui-group": "Configuration"
1259
+ },
1260
+ maxTokens: {
1261
+ type: "number",
1262
+ title: "Max Tokens",
1263
+ description: "Maximum tokens per LLM call",
1264
+ minimum: 1,
1265
+ "x-ui-group": "Configuration"
1266
+ },
1267
+ temperature: {
1268
+ type: "number",
1269
+ title: "Temperature",
1270
+ description: "Sampling temperature for LLM calls",
1271
+ minimum: 0,
1272
+ maximum: 2,
1273
+ "x-ui-group": "Configuration"
1274
+ }
1275
+ },
1276
+ required: ["model", "prompt"],
1277
+ additionalProperties: false
1278
+ };
1279
+ var AgentOutputSchema = {
1280
+ type: "object",
1281
+ properties: {
1282
+ text: {
1283
+ type: "string",
1284
+ title: "Text",
1285
+ description: "The final text response from the agent",
1286
+ "x-stream": "append"
1287
+ },
1288
+ messages: {
1289
+ type: "array",
1290
+ title: "Messages",
1291
+ description: "Full conversation history including all tool calls and results",
1292
+ items: {
1293
+ type: "object",
1294
+ additionalProperties: true
1295
+ }
1296
+ },
1297
+ iterations: {
1298
+ type: "number",
1299
+ title: "Iterations",
1300
+ description: "Number of LLM calls made during the agent loop"
1301
+ },
1302
+ toolCallCount: {
1303
+ type: "number",
1304
+ title: "Tool Call Count",
1305
+ description: "Total number of tool calls executed"
1306
+ },
1307
+ structuredOutput: {
1308
+ type: "object",
1309
+ title: "Structured Output",
1310
+ description: "Present when the agent terminated via a stop tool",
1311
+ additionalProperties: true
1312
+ }
1313
+ },
1314
+ required: ["text", "messages", "iterations", "toolCallCount"],
1315
+ additionalProperties: false
1316
+ };
1317
+
1318
+ class AgentTask extends Task {
1319
+ static type = "AgentTask";
1320
+ static category = "AI Agent";
1321
+ static title = "Agent";
1322
+ static description = "Multi-turn agentic loop that calls an LLM with tools, executes tool calls, and iterates until done";
1323
+ static cacheable = false;
1324
+ static inputSchema() {
1325
+ return AgentInputSchema;
1326
+ }
1327
+ static outputSchema() {
1328
+ return AgentOutputSchema;
1329
+ }
1330
+ async execute(input, context) {
1331
+ let result;
1332
+ for await (const event of this.agentLoop(input, context)) {
1333
+ if (event.type === "finish") {
1334
+ result = event.data;
1335
+ }
1336
+ }
1337
+ if (!result) {
1338
+ throw new Error("AgentTask: loop ended without producing output");
1339
+ }
1340
+ return result;
1341
+ }
1342
+ async* executeStream(input, context) {
1343
+ yield* this.agentLoop(input, context);
1344
+ }
1345
+ async* agentLoop(input, context) {
1346
+ const maxIterations = input.maxIterations ?? 10;
1347
+ const hooks = this.config.hooks;
1348
+ const maxConcurrency = this.config.maxConcurrency ?? 5;
1349
+ const toolSources = this.resolveToolSources(input, context);
1350
+ const toolDefs = this.resolveToolDefs(toolSources, input.stopTool);
1351
+ const messages = [userMessage(input.prompt)];
1352
+ let totalToolCalls = 0;
1353
+ let finalText = "";
1354
+ let structuredOutput;
1355
+ for (let iteration = 0;iteration < maxIterations; iteration++) {
1356
+ if (context.signal.aborted)
1357
+ break;
1358
+ if (hooks?.onIteration) {
1359
+ const action = await hooks.onIteration(iteration, messages, { totalToolCalls });
1360
+ if (action.action === "stop")
1361
+ break;
1362
+ }
1363
+ await context.updateProgress(Math.round(iteration / maxIterations * 100), `Agent iteration ${iteration + 1}`);
1364
+ const contextMessages = this.trimMessages(messages, input.maxContextMessages);
1365
+ const llmTask = context.own(new ToolCallingTask({}, {}));
1366
+ let iterationText = "";
1367
+ let toolCalls = [];
1368
+ for await (const event of llmTask.executeStream({
1369
+ model: input.model,
1370
+ prompt: input.prompt,
1371
+ systemPrompt: input.systemPrompt,
1372
+ tools: toolDefs,
1373
+ messages: contextMessages,
1374
+ maxTokens: input.maxTokens,
1375
+ temperature: input.temperature
1376
+ }, context)) {
1377
+ if (event.type === "text-delta") {
1378
+ yield { type: "text-delta", port: "text", textDelta: event.textDelta };
1379
+ iterationText += event.textDelta;
1380
+ } else if (event.type === "finish") {
1381
+ const data = event.data;
1382
+ iterationText = data?.text ?? iterationText;
1383
+ if (data?.toolCalls) {
1384
+ toolCalls = data.toolCalls ?? [];
1385
+ }
1386
+ }
1387
+ }
1388
+ finalText = iterationText;
1389
+ messages.push(assistantMessage(iterationText, toolCalls));
1390
+ if (input.stopTool) {
1391
+ const stopCall = toolCalls.find((tc) => tc.name === input.stopTool);
1392
+ if (stopCall) {
1393
+ structuredOutput = stopCall.input;
1394
+ break;
1395
+ }
1396
+ }
1397
+ if (!hasToolCalls(toolCalls)) {
1398
+ break;
1399
+ }
1400
+ const results = await executeToolCalls(toolCalls, toolSources, context, hooks, maxConcurrency);
1401
+ totalToolCalls += results.length;
1402
+ messages.push(toolMessage(results));
1403
+ }
1404
+ const output = {
1405
+ text: finalText,
1406
+ messages,
1407
+ iterations: messages.filter((m) => m.role === "assistant").length,
1408
+ toolCallCount: totalToolCalls,
1409
+ ...structuredOutput !== undefined ? { structuredOutput } : {}
1410
+ };
1411
+ yield { type: "finish", data: output };
1412
+ }
1413
+ resolveToolSources(input, context) {
1414
+ return buildToolSources(input.tools, context.registry);
1415
+ }
1416
+ resolveToolDefs(toolSources, stopTool) {
1417
+ const defs = toolSourceDefinitions(toolSources);
1418
+ if (stopTool && !defs.some((d) => d.name === stopTool)) {
1419
+ defs.push({
1420
+ name: stopTool,
1421
+ description: "Call this tool when you have completed the task. Pass your final structured result as the input.",
1422
+ inputSchema: { type: "object", additionalProperties: true }
1423
+ });
1424
+ }
1425
+ return defs;
1426
+ }
1427
+ trimMessages(messages, maxContextMessages) {
1428
+ if (!maxContextMessages || messages.length <= maxContextMessages) {
1429
+ return messages;
1430
+ }
1431
+ getLogger3().debug(`AgentTask: Trimming context from ${messages.length} to ${maxContextMessages} messages`);
1432
+ const tail = messages.slice(1);
1433
+ let startIdx = tail.length - (maxContextMessages - 1);
1434
+ if (startIdx < 0)
1435
+ startIdx = 0;
1436
+ if (startIdx > 0 && startIdx < tail.length && tail[startIdx].role === "tool") {
1437
+ startIdx -= 1;
1438
+ }
1439
+ return [messages[0], ...tail.slice(startIdx)];
1440
+ }
1441
+ }
1442
+ var agent = (input, config) => {
1443
+ return new AgentTask({}, config).run(input);
1444
+ };
1445
+ Workflow2.prototype.agent = CreateWorkflow2(AgentTask);
1446
+
1447
+ // src/task/BackgroundRemovalTask.ts
1448
+ import { CreateWorkflow as CreateWorkflow3, Workflow as Workflow3 } from "@workglow/task-graph";
1449
+
714
1450
  // src/task/base/AiVisionTask.ts
1451
+ import { convertImageDataToUseableForm } from "@workglow/util";
715
1452
  class AiVisionTask extends AiTask {
716
1453
  static type = "AiVisionTask";
717
1454
  async getJobInput(input) {
@@ -733,7 +1470,7 @@ class AiVisionTask extends AiTask {
733
1470
  }
734
1471
 
735
1472
  // src/task/BackgroundRemovalTask.ts
736
- var modelSchema = TypeModel("model:BackgroundRemovalTask");
1473
+ var modelSchema3 = TypeModel("model:BackgroundRemovalTask");
737
1474
  var processedImageSchema = {
738
1475
  type: "string",
739
1476
  contentEncoding: "base64",
@@ -745,7 +1482,7 @@ var BackgroundRemovalInputSchema = {
745
1482
  type: "object",
746
1483
  properties: {
747
1484
  image: TypeImageInput,
748
- model: modelSchema
1485
+ model: modelSchema3
749
1486
  },
750
1487
  required: ["image", "model"],
751
1488
  additionalProperties: false
@@ -774,14 +1511,14 @@ class BackgroundRemovalTask extends AiVisionTask {
774
1511
  var backgroundRemoval = (input, config) => {
775
1512
  return new BackgroundRemovalTask({}, config).run(input);
776
1513
  };
777
- Workflow.prototype.backgroundRemoval = CreateWorkflow(BackgroundRemovalTask);
1514
+ Workflow3.prototype.backgroundRemoval = CreateWorkflow3(BackgroundRemovalTask);
778
1515
 
779
1516
  // src/task/ChunkRetrievalTask.ts
780
1517
  import { TypeKnowledgeBase } from "@workglow/knowledge-base";
781
1518
  import {
782
- CreateWorkflow as CreateWorkflow3,
783
- Task,
784
- Workflow as Workflow3
1519
+ CreateWorkflow as CreateWorkflow5,
1520
+ Task as Task2,
1521
+ Workflow as Workflow5
785
1522
  } from "@workglow/task-graph";
786
1523
  import {
787
1524
  isTypedArray,
@@ -789,11 +1526,11 @@ import {
789
1526
  } from "@workglow/util";
790
1527
 
791
1528
  // src/task/TextEmbeddingTask.ts
792
- import { CreateWorkflow as CreateWorkflow2, Workflow as Workflow2 } from "@workglow/task-graph";
1529
+ import { CreateWorkflow as CreateWorkflow4, Workflow as Workflow4 } from "@workglow/task-graph";
793
1530
  import {
794
1531
  TypedArraySchema
795
1532
  } from "@workglow/util";
796
- var modelSchema2 = TypeModel("model:TextEmbeddingTask");
1533
+ var modelSchema4 = TypeModel("model:TextEmbeddingTask");
797
1534
  var TextEmbeddingInputSchema = {
798
1535
  type: "object",
799
1536
  properties: {
@@ -802,7 +1539,7 @@ var TextEmbeddingInputSchema = {
802
1539
  title: "Text",
803
1540
  description: "The text to embed"
804
1541
  }),
805
- model: modelSchema2
1542
+ model: modelSchema4
806
1543
  },
807
1544
  required: ["text", "model"],
808
1545
  additionalProperties: false
@@ -834,7 +1571,7 @@ class TextEmbeddingTask extends AiTask {
834
1571
  var textEmbedding = async (input, config) => {
835
1572
  return new TextEmbeddingTask({}, config).run(input);
836
1573
  };
837
- Workflow2.prototype.textEmbedding = CreateWorkflow2(TextEmbeddingTask);
1574
+ Workflow4.prototype.textEmbedding = CreateWorkflow4(TextEmbeddingTask);
838
1575
 
839
1576
  // src/task/ChunkRetrievalTask.ts
840
1577
  var inputSchema = {
@@ -959,7 +1696,7 @@ var outputSchema = {
959
1696
  additionalProperties: false
960
1697
  };
961
1698
 
962
- class ChunkRetrievalTask extends Task {
1699
+ class ChunkRetrievalTask extends Task2 {
963
1700
  static type = "ChunkRetrievalTask";
964
1701
  static category = "RAG";
965
1702
  static title = "Chunk Retrieval";
@@ -1026,14 +1763,14 @@ class ChunkRetrievalTask extends Task {
1026
1763
  var chunkRetrieval = (input, config) => {
1027
1764
  return new ChunkRetrievalTask({}, config).run(input);
1028
1765
  };
1029
- Workflow3.prototype.chunkRetrieval = CreateWorkflow3(ChunkRetrievalTask);
1766
+ Workflow5.prototype.chunkRetrieval = CreateWorkflow5(ChunkRetrievalTask);
1030
1767
 
1031
1768
  // src/task/ChunkToVectorTask.ts
1032
1769
  import { ChunkRecordSchema } from "@workglow/knowledge-base";
1033
1770
  import {
1034
- CreateWorkflow as CreateWorkflow4,
1035
- Task as Task2,
1036
- Workflow as Workflow4
1771
+ CreateWorkflow as CreateWorkflow6,
1772
+ Task as Task3,
1773
+ Workflow as Workflow6
1037
1774
  } from "@workglow/task-graph";
1038
1775
  import {
1039
1776
  TypedArraySchema as TypedArraySchema3
@@ -1109,7 +1846,7 @@ var outputSchema2 = {
1109
1846
  additionalProperties: false
1110
1847
  };
1111
1848
 
1112
- class ChunkToVectorTask extends Task2 {
1849
+ class ChunkToVectorTask extends Task3 {
1113
1850
  static type = "ChunkToVectorTask";
1114
1851
  static category = "Document";
1115
1852
  static title = "Chunk to Vector";
@@ -1160,14 +1897,14 @@ class ChunkToVectorTask extends Task2 {
1160
1897
  var chunkToVector = (input, config) => {
1161
1898
  return new ChunkToVectorTask({}, config).run(input);
1162
1899
  };
1163
- Workflow4.prototype.chunkToVector = CreateWorkflow4(ChunkToVectorTask);
1900
+ Workflow6.prototype.chunkToVector = CreateWorkflow6(ChunkToVectorTask);
1164
1901
 
1165
1902
  // src/task/ChunkVectorHybridSearchTask.ts
1166
1903
  import { TypeKnowledgeBase as TypeKnowledgeBase2 } from "@workglow/knowledge-base";
1167
1904
  import {
1168
- CreateWorkflow as CreateWorkflow5,
1169
- Task as Task3,
1170
- Workflow as Workflow5
1905
+ CreateWorkflow as CreateWorkflow7,
1906
+ Task as Task4,
1907
+ Workflow as Workflow7
1171
1908
  } from "@workglow/task-graph";
1172
1909
  import {
1173
1910
  TypedArraySchema as TypedArraySchema4
@@ -1281,7 +2018,7 @@ var outputSchema3 = {
1281
2018
  additionalProperties: false
1282
2019
  };
1283
2020
 
1284
- class ChunkVectorHybridSearchTask extends Task3 {
2021
+ class ChunkVectorHybridSearchTask extends Task4 {
1285
2022
  static type = "ChunkVectorHybridSearchTask";
1286
2023
  static category = "RAG";
1287
2024
  static title = "Hybrid Search";
@@ -1334,14 +2071,14 @@ class ChunkVectorHybridSearchTask extends Task3 {
1334
2071
  var hybridSearch = async (input, config) => {
1335
2072
  return new ChunkVectorHybridSearchTask({}, config).run(input);
1336
2073
  };
1337
- Workflow5.prototype.hybridSearch = CreateWorkflow5(ChunkVectorHybridSearchTask);
2074
+ Workflow7.prototype.hybridSearch = CreateWorkflow7(ChunkVectorHybridSearchTask);
1338
2075
 
1339
2076
  // src/task/ChunkVectorSearchTask.ts
1340
2077
  import { TypeKnowledgeBase as TypeKnowledgeBase3 } from "@workglow/knowledge-base";
1341
2078
  import {
1342
- CreateWorkflow as CreateWorkflow6,
1343
- Task as Task4,
1344
- Workflow as Workflow6
2079
+ CreateWorkflow as CreateWorkflow8,
2080
+ Task as Task5,
2081
+ Workflow as Workflow8
1345
2082
  } from "@workglow/task-graph";
1346
2083
  import {
1347
2084
  TypedArraySchema as TypedArraySchema5
@@ -1425,7 +2162,7 @@ var outputSchema4 = {
1425
2162
  additionalProperties: false
1426
2163
  };
1427
2164
 
1428
- class ChunkVectorSearchTask extends Task4 {
2165
+ class ChunkVectorSearchTask extends Task5 {
1429
2166
  static type = "ChunkVectorSearchTask";
1430
2167
  static category = "Vector Store";
1431
2168
  static title = "Vector Store Search";
@@ -1457,14 +2194,14 @@ class ChunkVectorSearchTask extends Task4 {
1457
2194
  var vectorStoreSearch = (input, config) => {
1458
2195
  return new ChunkVectorSearchTask({}, config).run(input);
1459
2196
  };
1460
- Workflow6.prototype.vectorStoreSearch = CreateWorkflow6(ChunkVectorSearchTask);
2197
+ Workflow8.prototype.vectorStoreSearch = CreateWorkflow8(ChunkVectorSearchTask);
1461
2198
 
1462
2199
  // src/task/ChunkVectorUpsertTask.ts
1463
2200
  import { TypeKnowledgeBase as TypeKnowledgeBase4 } from "@workglow/knowledge-base";
1464
2201
  import {
1465
- CreateWorkflow as CreateWorkflow7,
1466
- Task as Task5,
1467
- Workflow as Workflow7
2202
+ CreateWorkflow as CreateWorkflow9,
2203
+ Task as Task6,
2204
+ Workflow as Workflow9
1468
2205
  } from "@workglow/task-graph";
1469
2206
  import {
1470
2207
  TypedArraySchema as TypedArraySchema6
@@ -1519,7 +2256,7 @@ var outputSchema5 = {
1519
2256
  additionalProperties: false
1520
2257
  };
1521
2258
 
1522
- class ChunkVectorUpsertTask extends Task5 {
2259
+ class ChunkVectorUpsertTask extends Task6 {
1523
2260
  static type = "ChunkVectorUpsertTask";
1524
2261
  static category = "Vector Store";
1525
2262
  static title = "Add to Vector Store";
@@ -1579,19 +2316,19 @@ class ChunkVectorUpsertTask extends Task5 {
1579
2316
  var chunkVectorUpsert = (input, config) => {
1580
2317
  return new ChunkVectorUpsertTask({}, config).run(input);
1581
2318
  };
1582
- Workflow7.prototype.chunkVectorUpsert = CreateWorkflow7(ChunkVectorUpsertTask);
2319
+ Workflow9.prototype.chunkVectorUpsert = CreateWorkflow9(ChunkVectorUpsertTask);
1583
2320
 
1584
2321
  // src/task/ContextBuilderTask.ts
1585
2322
  import { estimateTokens } from "@workglow/knowledge-base";
1586
2323
  import {
1587
- CreateWorkflow as CreateWorkflow9,
1588
- Task as Task6,
1589
- Workflow as Workflow9
2324
+ CreateWorkflow as CreateWorkflow11,
2325
+ Task as Task7,
2326
+ Workflow as Workflow11
1590
2327
  } from "@workglow/task-graph";
1591
2328
 
1592
2329
  // src/task/CountTokensTask.ts
1593
- import { CreateWorkflow as CreateWorkflow8, Workflow as Workflow8 } from "@workglow/task-graph";
1594
- var modelSchema3 = TypeModel("model");
2330
+ import { CreateWorkflow as CreateWorkflow10, Workflow as Workflow10 } from "@workglow/task-graph";
2331
+ var modelSchema5 = TypeModel("model");
1595
2332
  var CountTokensInputSchema = {
1596
2333
  type: "object",
1597
2334
  properties: {
@@ -1600,7 +2337,7 @@ var CountTokensInputSchema = {
1600
2337
  title: "Text",
1601
2338
  description: "The text to count tokens for"
1602
2339
  }),
1603
- model: modelSchema3
2340
+ model: modelSchema5
1604
2341
  },
1605
2342
  required: ["text", "model"],
1606
2343
  additionalProperties: false
@@ -1634,7 +2371,7 @@ class CountTokensTask extends AiTask {
1634
2371
  var countTokens = async (input, config) => {
1635
2372
  return new CountTokensTask({}, config).run(input);
1636
2373
  };
1637
- Workflow8.prototype.countTokens = CreateWorkflow8(CountTokensTask);
2374
+ Workflow10.prototype.countTokens = CreateWorkflow10(CountTokensTask);
1638
2375
 
1639
2376
  // src/task/ContextBuilderTask.ts
1640
2377
  var ContextFormat = {
@@ -1644,7 +2381,7 @@ var ContextFormat = {
1644
2381
  MARKDOWN: "markdown",
1645
2382
  JSON: "json"
1646
2383
  };
1647
- var modelSchema4 = TypeModel("model", {
2384
+ var modelSchema6 = TypeModel("model", {
1648
2385
  title: "Model",
1649
2386
  description: "Model to use for token counting (optional, falls back to estimation)"
1650
2387
  });
@@ -1708,7 +2445,7 @@ var inputSchema6 = {
1708
2445
 
1709
2446
  `
1710
2447
  },
1711
- model: modelSchema4
2448
+ model: modelSchema6
1712
2449
  },
1713
2450
  required: ["chunks"],
1714
2451
  additionalProperties: false
@@ -1741,7 +2478,7 @@ var outputSchema6 = {
1741
2478
  additionalProperties: false
1742
2479
  };
1743
2480
 
1744
- class ContextBuilderTask extends Task6 {
2481
+ class ContextBuilderTask extends Task7 {
1745
2482
  static type = "ContextBuilderTask";
1746
2483
  static category = "RAG";
1747
2484
  static title = "Context Builder";
@@ -1934,7 +2671,7 @@ class ContextBuilderTask extends Task6 {
1934
2671
  var contextBuilder = (input, config) => {
1935
2672
  return new ContextBuilderTask({}, config).run(input);
1936
2673
  };
1937
- Workflow9.prototype.contextBuilder = CreateWorkflow9(ContextBuilderTask);
2674
+ Workflow11.prototype.contextBuilder = CreateWorkflow11(ContextBuilderTask);
1938
2675
 
1939
2676
  // src/task/DocumentEnricherTask.ts
1940
2677
  import {
@@ -1942,14 +2679,14 @@ import {
1942
2679
  hasChildren
1943
2680
  } from "@workglow/knowledge-base";
1944
2681
  import {
1945
- CreateWorkflow as CreateWorkflow12,
1946
- Task as Task7,
1947
- Workflow as Workflow12
2682
+ CreateWorkflow as CreateWorkflow14,
2683
+ Task as Task8,
2684
+ Workflow as Workflow14
1948
2685
  } from "@workglow/task-graph";
1949
2686
 
1950
2687
  // src/task/TextNamedEntityRecognitionTask.ts
1951
- import { CreateWorkflow as CreateWorkflow10, Workflow as Workflow10 } from "@workglow/task-graph";
1952
- var modelSchema5 = TypeModel("model:TextNamedEntityRecognitionTask");
2688
+ import { CreateWorkflow as CreateWorkflow12, Workflow as Workflow12 } from "@workglow/task-graph";
2689
+ var modelSchema7 = TypeModel("model:TextNamedEntityRecognitionTask");
1953
2690
  var TextNamedEntityRecognitionInputSchema = {
1954
2691
  type: "object",
1955
2692
  properties: {
@@ -1968,7 +2705,7 @@ var TextNamedEntityRecognitionInputSchema = {
1968
2705
  "x-ui-group": "Configuration",
1969
2706
  "x-ui-group-open": false
1970
2707
  },
1971
- model: modelSchema5
2708
+ model: modelSchema7
1972
2709
  },
1973
2710
  required: ["text", "model"],
1974
2711
  additionalProperties: false
@@ -2023,44 +2760,11 @@ class TextNamedEntityRecognitionTask extends AiTask {
2023
2760
  var textNamedEntityRecognition = (input, config) => {
2024
2761
  return new TextNamedEntityRecognitionTask({}, config).run(input);
2025
2762
  };
2026
- Workflow10.prototype.textNamedEntityRecognition = CreateWorkflow10(TextNamedEntityRecognitionTask);
2027
-
2028
- // src/task/TextSummaryTask.ts
2029
- import { CreateWorkflow as CreateWorkflow11, Workflow as Workflow11 } from "@workglow/task-graph";
2030
-
2031
- // src/task/base/StreamingAiTask.ts
2032
- import {
2033
- getStreamingPorts
2034
- } from "@workglow/task-graph";
2035
- class StreamingAiTask extends AiTask {
2036
- static type = "StreamingAiTask";
2037
- async* executeStream(input, context) {
2038
- const jobInput = await this.getJobInput(input);
2039
- const queueName = await this.getDefaultQueueName(input);
2040
- const job = new AiJob({
2041
- queueName: queueName ?? this.type,
2042
- jobRunId: this.runConfig.runnerId,
2043
- input: jobInput
2044
- });
2045
- const ports = getStreamingPorts(this.outputSchema());
2046
- const defaultPort = ports.length > 0 ? ports[0].port : "text";
2047
- for await (const event of job.executeStream(jobInput, {
2048
- signal: context.signal,
2049
- updateProgress: context.updateProgress.bind(this)
2050
- })) {
2051
- if (event.type === "text-delta") {
2052
- yield { ...event, port: event.port ?? defaultPort };
2053
- } else if (event.type === "object-delta") {
2054
- yield { ...event, port: event.port ?? defaultPort };
2055
- } else {
2056
- yield event;
2057
- }
2058
- }
2059
- }
2060
- }
2763
+ Workflow12.prototype.textNamedEntityRecognition = CreateWorkflow12(TextNamedEntityRecognitionTask);
2061
2764
 
2062
2765
  // src/task/TextSummaryTask.ts
2063
- var modelSchema6 = TypeModel("model:TextSummaryTask");
2766
+ import { CreateWorkflow as CreateWorkflow13, Workflow as Workflow13 } from "@workglow/task-graph";
2767
+ var modelSchema8 = TypeModel("model:TextSummaryTask");
2064
2768
  var TextSummaryInputSchema = {
2065
2769
  type: "object",
2066
2770
  properties: {
@@ -2069,7 +2773,7 @@ var TextSummaryInputSchema = {
2069
2773
  title: "Text",
2070
2774
  description: "The text to summarize"
2071
2775
  }),
2072
- model: modelSchema6
2776
+ model: modelSchema8
2073
2777
  },
2074
2778
  required: ["text", "model"],
2075
2779
  additionalProperties: false
@@ -2103,7 +2807,7 @@ class TextSummaryTask extends StreamingAiTask {
2103
2807
  var textSummary = async (input, config) => {
2104
2808
  return new TextSummaryTask({}, config).run(input);
2105
2809
  };
2106
- Workflow11.prototype.textSummary = CreateWorkflow11(TextSummaryTask);
2810
+ Workflow13.prototype.textSummary = CreateWorkflow13(TextSummaryTask);
2107
2811
 
2108
2812
  // src/task/DocumentEnricherTask.ts
2109
2813
  var inputSchema7 = {
@@ -2175,7 +2879,7 @@ var outputSchema7 = {
2175
2879
  additionalProperties: false
2176
2880
  };
2177
2881
 
2178
- class DocumentEnricherTask extends Task7 {
2882
+ class DocumentEnricherTask extends Task8 {
2179
2883
  static type = "DocumentEnricherTask";
2180
2884
  static category = "Document";
2181
2885
  static title = "Document Enricher";
@@ -2334,15 +3038,15 @@ class DocumentEnricherTask extends Task7 {
2334
3038
  var documentEnricher = (input, config) => {
2335
3039
  return new DocumentEnricherTask({}, config).run(input);
2336
3040
  };
2337
- Workflow12.prototype.documentEnricher = CreateWorkflow12(DocumentEnricherTask);
3041
+ Workflow14.prototype.documentEnricher = CreateWorkflow14(DocumentEnricherTask);
2338
3042
 
2339
3043
  // src/task/DownloadModelTask.ts
2340
- import { CreateWorkflow as CreateWorkflow13, Workflow as Workflow13 } from "@workglow/task-graph";
2341
- var modelSchema7 = TypeModel("model");
3044
+ import { CreateWorkflow as CreateWorkflow15, Workflow as Workflow15 } from "@workglow/task-graph";
3045
+ var modelSchema9 = TypeModel("model");
2342
3046
  var DownloadModelInputSchema = {
2343
3047
  type: "object",
2344
3048
  properties: {
2345
- model: modelSchema7
3049
+ model: modelSchema9
2346
3050
  },
2347
3051
  required: ["model"],
2348
3052
  additionalProperties: false
@@ -2350,7 +3054,7 @@ var DownloadModelInputSchema = {
2350
3054
  var DownloadModelOutputSchema = {
2351
3055
  type: "object",
2352
3056
  properties: {
2353
- model: modelSchema7
3057
+ model: modelSchema9
2354
3058
  },
2355
3059
  required: ["model"],
2356
3060
  additionalProperties: false
@@ -2393,11 +3097,11 @@ class DownloadModelTask extends AiTask {
2393
3097
  var downloadModel = (input, config) => {
2394
3098
  return new DownloadModelTask({}, config).run(input);
2395
3099
  };
2396
- Workflow13.prototype.downloadModel = CreateWorkflow13(DownloadModelTask);
3100
+ Workflow15.prototype.downloadModel = CreateWorkflow15(DownloadModelTask);
2397
3101
 
2398
3102
  // src/task/FaceDetectorTask.ts
2399
- import { CreateWorkflow as CreateWorkflow14, Workflow as Workflow14 } from "@workglow/task-graph";
2400
- var modelSchema8 = TypeModel("model:FaceDetectorTask");
3103
+ import { CreateWorkflow as CreateWorkflow16, Workflow as Workflow16 } from "@workglow/task-graph";
3104
+ var modelSchema10 = TypeModel("model:FaceDetectorTask");
2401
3105
  var TypeBoundingBox2 = {
2402
3106
  type: "object",
2403
3107
  properties: {
@@ -2470,7 +3174,7 @@ var FaceDetectorInputSchema = {
2470
3174
  type: "object",
2471
3175
  properties: {
2472
3176
  image: TypeImageInput,
2473
- model: modelSchema8,
3177
+ model: modelSchema10,
2474
3178
  minDetectionConfidence: {
2475
3179
  type: "number",
2476
3180
  minimum: 0,
@@ -2524,11 +3228,11 @@ class FaceDetectorTask extends AiVisionTask {
2524
3228
  var faceDetector = (input, config) => {
2525
3229
  return new FaceDetectorTask({}, config).run(input);
2526
3230
  };
2527
- Workflow14.prototype.faceDetector = CreateWorkflow14(FaceDetectorTask);
3231
+ Workflow16.prototype.faceDetector = CreateWorkflow16(FaceDetectorTask);
2528
3232
 
2529
3233
  // src/task/FaceLandmarkerTask.ts
2530
- import { CreateWorkflow as CreateWorkflow15, Workflow as Workflow15 } from "@workglow/task-graph";
2531
- var modelSchema9 = TypeModel("model:FaceLandmarkerTask");
3234
+ import { CreateWorkflow as CreateWorkflow17, Workflow as Workflow17 } from "@workglow/task-graph";
3235
+ var modelSchema11 = TypeModel("model:FaceLandmarkerTask");
2532
3236
  var TypeLandmark = {
2533
3237
  type: "object",
2534
3238
  properties: {
@@ -2600,7 +3304,7 @@ var FaceLandmarkerInputSchema = {
2600
3304
  type: "object",
2601
3305
  properties: {
2602
3306
  image: TypeImageInput,
2603
- model: modelSchema9,
3307
+ model: modelSchema11,
2604
3308
  numFaces: {
2605
3309
  type: "number",
2606
3310
  minimum: 1,
@@ -2686,11 +3390,11 @@ class FaceLandmarkerTask extends AiVisionTask {
2686
3390
  var faceLandmarker = (input, config) => {
2687
3391
  return new FaceLandmarkerTask({}, config).run(input);
2688
3392
  };
2689
- Workflow15.prototype.faceLandmarker = CreateWorkflow15(FaceLandmarkerTask);
3393
+ Workflow17.prototype.faceLandmarker = CreateWorkflow17(FaceLandmarkerTask);
2690
3394
 
2691
3395
  // src/task/GestureRecognizerTask.ts
2692
- import { CreateWorkflow as CreateWorkflow16, Workflow as Workflow16 } from "@workglow/task-graph";
2693
- var modelSchema10 = TypeModel("model:GestureRecognizerTask");
3396
+ import { CreateWorkflow as CreateWorkflow18, Workflow as Workflow18 } from "@workglow/task-graph";
3397
+ var modelSchema12 = TypeModel("model:GestureRecognizerTask");
2694
3398
  var TypeLandmark2 = {
2695
3399
  type: "object",
2696
3400
  properties: {
@@ -2782,7 +3486,7 @@ var GestureRecognizerInputSchema = {
2782
3486
  type: "object",
2783
3487
  properties: {
2784
3488
  image: TypeImageInput,
2785
- model: modelSchema10,
3489
+ model: modelSchema12,
2786
3490
  numHands: {
2787
3491
  type: "number",
2788
3492
  minimum: 1,
@@ -2854,11 +3558,11 @@ class GestureRecognizerTask extends AiVisionTask {
2854
3558
  var gestureRecognizer = (input, config) => {
2855
3559
  return new GestureRecognizerTask({}, config).run(input);
2856
3560
  };
2857
- Workflow16.prototype.gestureRecognizer = CreateWorkflow16(GestureRecognizerTask);
3561
+ Workflow18.prototype.gestureRecognizer = CreateWorkflow18(GestureRecognizerTask);
2858
3562
 
2859
3563
  // src/task/HandLandmarkerTask.ts
2860
- import { CreateWorkflow as CreateWorkflow17, Workflow as Workflow17 } from "@workglow/task-graph";
2861
- var modelSchema11 = TypeModel("model:HandLandmarkerTask");
3564
+ import { CreateWorkflow as CreateWorkflow19, Workflow as Workflow19 } from "@workglow/task-graph";
3565
+ var modelSchema13 = TypeModel("model:HandLandmarkerTask");
2862
3566
  var TypeLandmark3 = {
2863
3567
  type: "object",
2864
3568
  properties: {
@@ -2927,7 +3631,7 @@ var HandLandmarkerInputSchema = {
2927
3631
  type: "object",
2928
3632
  properties: {
2929
3633
  image: TypeImageInput,
2930
- model: modelSchema11,
3634
+ model: modelSchema13,
2931
3635
  numHands: {
2932
3636
  type: "number",
2933
3637
  minimum: 1,
@@ -2999,7 +3703,7 @@ class HandLandmarkerTask extends AiVisionTask {
2999
3703
  var handLandmarker = (input, config) => {
3000
3704
  return new HandLandmarkerTask({}, config).run(input);
3001
3705
  };
3002
- Workflow17.prototype.handLandmarker = CreateWorkflow17(HandLandmarkerTask);
3706
+ Workflow19.prototype.handLandmarker = CreateWorkflow19(HandLandmarkerTask);
3003
3707
 
3004
3708
  // src/task/HierarchicalChunkerTask.ts
3005
3709
  import {
@@ -3009,12 +3713,12 @@ import {
3009
3713
  hasChildren as hasChildren2
3010
3714
  } from "@workglow/knowledge-base";
3011
3715
  import {
3012
- CreateWorkflow as CreateWorkflow18,
3013
- Task as Task8,
3014
- Workflow as Workflow18
3716
+ CreateWorkflow as CreateWorkflow20,
3717
+ Task as Task9,
3718
+ Workflow as Workflow20
3015
3719
  } from "@workglow/task-graph";
3016
3720
  import { uuid4 } from "@workglow/util";
3017
- var modelSchema12 = TypeModel("model", {
3721
+ var modelSchema14 = TypeModel("model", {
3018
3722
  title: "Model",
3019
3723
  description: "Model to use for token counting"
3020
3724
  });
@@ -3058,7 +3762,7 @@ var inputSchema8 = {
3058
3762
  description: "Strategy for chunking",
3059
3763
  default: "hierarchical"
3060
3764
  },
3061
- model: modelSchema12
3765
+ model: modelSchema14
3062
3766
  },
3063
3767
  required: ["doc_id", "documentTree"],
3064
3768
  additionalProperties: false
@@ -3093,7 +3797,7 @@ var outputSchema8 = {
3093
3797
  additionalProperties: false
3094
3798
  };
3095
3799
 
3096
- class HierarchicalChunkerTask extends Task8 {
3800
+ class HierarchicalChunkerTask extends Task9 {
3097
3801
  static type = "HierarchicalChunkerTask";
3098
3802
  static category = "Document";
3099
3803
  static title = "Hierarchical Chunker";
@@ -3237,7 +3941,7 @@ class HierarchicalChunkerTask extends Task8 {
3237
3941
  var hierarchicalChunker = (input, config) => {
3238
3942
  return new HierarchicalChunkerTask({}, config).run(input);
3239
3943
  };
3240
- Workflow18.prototype.hierarchicalChunker = CreateWorkflow18(HierarchicalChunkerTask);
3944
+ Workflow20.prototype.hierarchicalChunker = CreateWorkflow20(HierarchicalChunkerTask);
3241
3945
 
3242
3946
  // src/task/HierarchyJoinTask.ts
3243
3947
  import {
@@ -3245,9 +3949,9 @@ import {
3245
3949
  TypeKnowledgeBase as TypeKnowledgeBase5
3246
3950
  } from "@workglow/knowledge-base";
3247
3951
  import {
3248
- CreateWorkflow as CreateWorkflow19,
3249
- Task as Task9,
3250
- Workflow as Workflow19
3952
+ CreateWorkflow as CreateWorkflow21,
3953
+ Task as Task10,
3954
+ Workflow as Workflow21
3251
3955
  } from "@workglow/task-graph";
3252
3956
  var inputSchema9 = {
3253
3957
  type: "object",
@@ -3323,7 +4027,7 @@ var outputSchema9 = {
3323
4027
  additionalProperties: false
3324
4028
  };
3325
4029
 
3326
- class HierarchyJoinTask extends Task9 {
4030
+ class HierarchyJoinTask extends Task10 {
3327
4031
  static type = "HierarchyJoinTask";
3328
4032
  static category = "RAG";
3329
4033
  static title = "Hierarchy Join";
@@ -3417,16 +4121,16 @@ class HierarchyJoinTask extends Task9 {
3417
4121
  var hierarchyJoin = (input, config) => {
3418
4122
  return new HierarchyJoinTask({}, config).run(input);
3419
4123
  };
3420
- Workflow19.prototype.hierarchyJoin = CreateWorkflow19(HierarchyJoinTask);
4124
+ Workflow21.prototype.hierarchyJoin = CreateWorkflow21(HierarchyJoinTask);
3421
4125
 
3422
4126
  // src/task/ImageClassificationTask.ts
3423
- import { CreateWorkflow as CreateWorkflow20, Workflow as Workflow20 } from "@workglow/task-graph";
3424
- var modelSchema13 = TypeModel("model:ImageClassificationTask");
4127
+ import { CreateWorkflow as CreateWorkflow22, Workflow as Workflow22 } from "@workglow/task-graph";
4128
+ var modelSchema15 = TypeModel("model:ImageClassificationTask");
3425
4129
  var ImageClassificationInputSchema = {
3426
4130
  type: "object",
3427
4131
  properties: {
3428
4132
  image: TypeImageInput,
3429
- model: modelSchema13,
4133
+ model: modelSchema15,
3430
4134
  categories: {
3431
4135
  type: "array",
3432
4136
  items: {
@@ -3480,14 +4184,14 @@ class ImageClassificationTask extends AiVisionTask {
3480
4184
  var imageClassification = (input, config) => {
3481
4185
  return new ImageClassificationTask({}, config).run(input);
3482
4186
  };
3483
- Workflow20.prototype.imageClassification = CreateWorkflow20(ImageClassificationTask);
4187
+ Workflow22.prototype.imageClassification = CreateWorkflow22(ImageClassificationTask);
3484
4188
 
3485
4189
  // src/task/ImageEmbeddingTask.ts
3486
- import { CreateWorkflow as CreateWorkflow21, Workflow as Workflow21 } from "@workglow/task-graph";
4190
+ import { CreateWorkflow as CreateWorkflow23, Workflow as Workflow23 } from "@workglow/task-graph";
3487
4191
  import {
3488
4192
  TypedArraySchema as TypedArraySchema7
3489
4193
  } from "@workglow/util";
3490
- var modelSchema14 = TypeModel("model:ImageEmbeddingTask");
4194
+ var modelSchema16 = TypeModel("model:ImageEmbeddingTask");
3491
4195
  var embeddingSchema = TypedArraySchema7({
3492
4196
  title: "Embedding",
3493
4197
  description: "The image embedding vector"
@@ -3496,7 +4200,7 @@ var ImageEmbeddingInputSchema = {
3496
4200
  type: "object",
3497
4201
  properties: {
3498
4202
  image: TypeImageInput,
3499
- model: modelSchema14
4203
+ model: modelSchema16
3500
4204
  },
3501
4205
  required: ["image", "model"],
3502
4206
  additionalProperties: false
@@ -3525,16 +4229,16 @@ class ImageEmbeddingTask extends AiVisionTask {
3525
4229
  var imageEmbedding = (input, config) => {
3526
4230
  return new ImageEmbeddingTask({}, config).run(input);
3527
4231
  };
3528
- Workflow21.prototype.imageEmbedding = CreateWorkflow21(ImageEmbeddingTask);
4232
+ Workflow23.prototype.imageEmbedding = CreateWorkflow23(ImageEmbeddingTask);
3529
4233
 
3530
4234
  // src/task/ImageSegmentationTask.ts
3531
- import { CreateWorkflow as CreateWorkflow22, Workflow as Workflow22 } from "@workglow/task-graph";
3532
- var modelSchema15 = TypeModel("model:ImageSegmentationTask");
4235
+ import { CreateWorkflow as CreateWorkflow24, Workflow as Workflow24 } from "@workglow/task-graph";
4236
+ var modelSchema17 = TypeModel("model:ImageSegmentationTask");
3533
4237
  var ImageSegmentationInputSchema = {
3534
4238
  type: "object",
3535
4239
  properties: {
3536
4240
  image: TypeImageInput,
3537
- model: modelSchema15,
4241
+ model: modelSchema17,
3538
4242
  threshold: {
3539
4243
  type: "number",
3540
4244
  title: "Threshold",
@@ -3613,11 +4317,11 @@ class ImageSegmentationTask extends AiVisionTask {
3613
4317
  var imageSegmentation = (input, config) => {
3614
4318
  return new ImageSegmentationTask({}, config).run(input);
3615
4319
  };
3616
- Workflow22.prototype.imageSegmentation = CreateWorkflow22(ImageSegmentationTask);
4320
+ Workflow24.prototype.imageSegmentation = CreateWorkflow24(ImageSegmentationTask);
3617
4321
 
3618
4322
  // src/task/ImageToTextTask.ts
3619
- import { CreateWorkflow as CreateWorkflow23, Workflow as Workflow23 } from "@workglow/task-graph";
3620
- var modelSchema16 = TypeModel("model:ImageToTextTask");
4323
+ import { CreateWorkflow as CreateWorkflow25, Workflow as Workflow25 } from "@workglow/task-graph";
4324
+ var modelSchema18 = TypeModel("model:ImageToTextTask");
3621
4325
  var generatedTextSchema = {
3622
4326
  type: "string",
3623
4327
  title: "Text",
@@ -3627,7 +4331,7 @@ var ImageToTextInputSchema = {
3627
4331
  type: "object",
3628
4332
  properties: {
3629
4333
  image: TypeImageInput,
3630
- model: modelSchema16,
4334
+ model: modelSchema18,
3631
4335
  maxTokens: {
3632
4336
  type: "number",
3633
4337
  title: "Max Tokens",
@@ -3668,15 +4372,15 @@ class ImageToTextTask extends AiVisionTask {
3668
4372
  var imageToText = (input, config) => {
3669
4373
  return new ImageToTextTask({}, config).run(input);
3670
4374
  };
3671
- Workflow23.prototype.imageToText = CreateWorkflow23(ImageToTextTask);
4375
+ Workflow25.prototype.imageToText = CreateWorkflow25(ImageToTextTask);
3672
4376
 
3673
4377
  // src/task/ModelInfoTask.ts
3674
- import { CreateWorkflow as CreateWorkflow24, Workflow as Workflow24 } from "@workglow/task-graph";
3675
- var modelSchema17 = TypeModel("model");
4378
+ import { CreateWorkflow as CreateWorkflow26, Workflow as Workflow26 } from "@workglow/task-graph";
4379
+ var modelSchema19 = TypeModel("model");
3676
4380
  var ModelInfoInputSchema = {
3677
4381
  type: "object",
3678
4382
  properties: {
3679
- model: modelSchema17,
4383
+ model: modelSchema19,
3680
4384
  detail: {
3681
4385
  type: "string",
3682
4386
  enum: ["cached_status", "files", "files_with_metadata"],
@@ -3689,7 +4393,7 @@ var ModelInfoInputSchema = {
3689
4393
  var ModelInfoOutputSchema = {
3690
4394
  type: "object",
3691
4395
  properties: {
3692
- model: modelSchema17,
4396
+ model: modelSchema19,
3693
4397
  is_local: { type: "boolean" },
3694
4398
  is_remote: { type: "boolean" },
3695
4399
  supports_browser: { type: "boolean" },
@@ -3727,11 +4431,11 @@ class ModelInfoTask extends AiTask {
3727
4431
  var modelInfo = (input, config) => {
3728
4432
  return new ModelInfoTask({}, config).run(input);
3729
4433
  };
3730
- Workflow24.prototype.modelInfo = CreateWorkflow24(ModelInfoTask);
4434
+ Workflow26.prototype.modelInfo = CreateWorkflow26(ModelInfoTask);
3731
4435
 
3732
4436
  // src/task/ObjectDetectionTask.ts
3733
- import { CreateWorkflow as CreateWorkflow25, Workflow as Workflow25 } from "@workglow/task-graph";
3734
- var modelSchema18 = TypeModel("model:ObjectDetectionTask");
4437
+ import { CreateWorkflow as CreateWorkflow27, Workflow as Workflow27 } from "@workglow/task-graph";
4438
+ var modelSchema20 = TypeModel("model:ObjectDetectionTask");
3735
4439
  var detectionSchema = {
3736
4440
  type: "object",
3737
4441
  properties: {
@@ -3756,7 +4460,7 @@ var ObjectDetectionInputSchema = {
3756
4460
  type: "object",
3757
4461
  properties: {
3758
4462
  image: TypeImageInput,
3759
- model: modelSchema18,
4463
+ model: modelSchema20,
3760
4464
  labels: {
3761
4465
  type: "array",
3762
4466
  items: {
@@ -3810,11 +4514,11 @@ class ObjectDetectionTask extends AiVisionTask {
3810
4514
  var objectDetection = (input, config) => {
3811
4515
  return new ObjectDetectionTask({}, config).run(input);
3812
4516
  };
3813
- Workflow25.prototype.objectDetection = CreateWorkflow25(ObjectDetectionTask);
4517
+ Workflow27.prototype.objectDetection = CreateWorkflow27(ObjectDetectionTask);
3814
4518
 
3815
4519
  // src/task/PoseLandmarkerTask.ts
3816
- import { CreateWorkflow as CreateWorkflow26, Workflow as Workflow26 } from "@workglow/task-graph";
3817
- var modelSchema19 = TypeModel("model:PoseLandmarkerTask");
4520
+ import { CreateWorkflow as CreateWorkflow28, Workflow as Workflow28 } from "@workglow/task-graph";
4521
+ var modelSchema21 = TypeModel("model:PoseLandmarkerTask");
3818
4522
  var TypePoseLandmark = {
3819
4523
  type: "object",
3820
4524
  properties: {
@@ -3893,7 +4597,7 @@ var PoseLandmarkerInputSchema = {
3893
4597
  type: "object",
3894
4598
  properties: {
3895
4599
  image: TypeImageInput,
3896
- model: modelSchema19,
4600
+ model: modelSchema21,
3897
4601
  numPoses: {
3898
4602
  type: "number",
3899
4603
  minimum: 1,
@@ -3972,13 +4676,13 @@ class PoseLandmarkerTask extends AiVisionTask {
3972
4676
  var poseLandmarker = (input, config) => {
3973
4677
  return new PoseLandmarkerTask({}, config).run(input);
3974
4678
  };
3975
- Workflow26.prototype.poseLandmarker = CreateWorkflow26(PoseLandmarkerTask);
4679
+ Workflow28.prototype.poseLandmarker = CreateWorkflow28(PoseLandmarkerTask);
3976
4680
 
3977
4681
  // src/task/QueryExpanderTask.ts
3978
4682
  import {
3979
- CreateWorkflow as CreateWorkflow27,
3980
- Task as Task10,
3981
- Workflow as Workflow27
4683
+ CreateWorkflow as CreateWorkflow29,
4684
+ Task as Task11,
4685
+ Workflow as Workflow29
3982
4686
  } from "@workglow/task-graph";
3983
4687
  var QueryExpansionMethod = {
3984
4688
  MULTI_QUERY: "multi-query",
@@ -4047,7 +4751,7 @@ var outputSchema10 = {
4047
4751
  additionalProperties: false
4048
4752
  };
4049
4753
 
4050
- class QueryExpanderTask extends Task10 {
4754
+ class QueryExpanderTask extends Task11 {
4051
4755
  static type = "QueryExpanderTask";
4052
4756
  static category = "RAG";
4053
4757
  static title = "Query Expander";
@@ -4189,18 +4893,18 @@ class QueryExpanderTask extends Task10 {
4189
4893
  var queryExpander = (input, config) => {
4190
4894
  return new QueryExpanderTask({}, config).run(input);
4191
4895
  };
4192
- Workflow27.prototype.queryExpander = CreateWorkflow27(QueryExpanderTask);
4896
+ Workflow29.prototype.queryExpander = CreateWorkflow29(QueryExpanderTask);
4193
4897
 
4194
4898
  // src/task/RerankerTask.ts
4195
4899
  import {
4196
- CreateWorkflow as CreateWorkflow29,
4197
- Task as Task11,
4198
- Workflow as Workflow29
4900
+ CreateWorkflow as CreateWorkflow31,
4901
+ Task as Task12,
4902
+ Workflow as Workflow31
4199
4903
  } from "@workglow/task-graph";
4200
4904
 
4201
4905
  // src/task/TextClassificationTask.ts
4202
- import { CreateWorkflow as CreateWorkflow28, Workflow as Workflow28 } from "@workglow/task-graph";
4203
- var modelSchema20 = TypeModel("model:TextClassificationTask");
4906
+ import { CreateWorkflow as CreateWorkflow30, Workflow as Workflow30 } from "@workglow/task-graph";
4907
+ var modelSchema22 = TypeModel("model:TextClassificationTask");
4204
4908
  var TextClassificationInputSchema = {
4205
4909
  type: "object",
4206
4910
  properties: {
@@ -4227,7 +4931,7 @@ var TextClassificationInputSchema = {
4227
4931
  description: "The maximum number of categories to return",
4228
4932
  "x-ui-group": "Configuration"
4229
4933
  },
4230
- model: modelSchema20
4934
+ model: modelSchema22
4231
4935
  },
4232
4936
  required: ["text", "model"],
4233
4937
  additionalProperties: false
@@ -4277,7 +4981,7 @@ class TextClassificationTask extends AiTask {
4277
4981
  var textClassification = (input, config) => {
4278
4982
  return new TextClassificationTask({}, config).run(input);
4279
4983
  };
4280
- Workflow28.prototype.textClassification = CreateWorkflow28(TextClassificationTask);
4984
+ Workflow30.prototype.textClassification = CreateWorkflow30(TextClassificationTask);
4281
4985
 
4282
4986
  // src/task/RerankerTask.ts
4283
4987
  var inputSchema11 = {
@@ -4372,7 +5076,7 @@ var outputSchema11 = {
4372
5076
  additionalProperties: false
4373
5077
  };
4374
5078
 
4375
- class RerankerTask extends Task11 {
5079
+ class RerankerTask extends Task12 {
4376
5080
  static type = "RerankerTask";
4377
5081
  static category = "RAG";
4378
5082
  static title = "Reranker";
@@ -4501,14 +5205,14 @@ class RerankerTask extends Task11 {
4501
5205
  var reranker = (input, config) => {
4502
5206
  return new RerankerTask({}, config).run(input);
4503
5207
  };
4504
- Workflow29.prototype.reranker = CreateWorkflow29(RerankerTask);
5208
+ Workflow31.prototype.reranker = CreateWorkflow31(RerankerTask);
4505
5209
 
4506
5210
  // src/task/StructuralParserTask.ts
4507
5211
  import { StructuralParser } from "@workglow/knowledge-base";
4508
5212
  import {
4509
- CreateWorkflow as CreateWorkflow30,
4510
- Task as Task12,
4511
- Workflow as Workflow30
5213
+ CreateWorkflow as CreateWorkflow32,
5214
+ Task as Task13,
5215
+ Workflow as Workflow32
4512
5216
  } from "@workglow/task-graph";
4513
5217
  import { uuid4 as uuid42 } from "@workglow/util";
4514
5218
  var inputSchema12 = {
@@ -4567,7 +5271,7 @@ var outputSchema12 = {
4567
5271
  additionalProperties: false
4568
5272
  };
4569
5273
 
4570
- class StructuralParserTask extends Task12 {
5274
+ class StructuralParserTask extends Task13 {
4571
5275
  static type = "StructuralParserTask";
4572
5276
  static category = "Document";
4573
5277
  static title = "Structural Parser";
@@ -4610,15 +5314,15 @@ class StructuralParserTask extends Task12 {
4610
5314
  var structuralParser = (input, config) => {
4611
5315
  return new StructuralParserTask({}, config).run(input);
4612
5316
  };
4613
- Workflow30.prototype.structuralParser = CreateWorkflow30(StructuralParserTask);
5317
+ Workflow32.prototype.structuralParser = CreateWorkflow32(StructuralParserTask);
4614
5318
 
4615
5319
  // src/task/StructuredGenerationTask.ts
4616
- import { CreateWorkflow as CreateWorkflow31, Workflow as Workflow31 } from "@workglow/task-graph";
4617
- var modelSchema21 = TypeModel("model:StructuredGenerationTask");
5320
+ import { CreateWorkflow as CreateWorkflow33, Workflow as Workflow33 } from "@workglow/task-graph";
5321
+ var modelSchema23 = TypeModel("model:StructuredGenerationTask");
4618
5322
  var StructuredGenerationInputSchema = {
4619
5323
  type: "object",
4620
5324
  properties: {
4621
- model: modelSchema21,
5325
+ model: modelSchema23,
4622
5326
  prompt: {
4623
5327
  type: "string",
4624
5328
  title: "Prompt",
@@ -4681,13 +5385,13 @@ class StructuredGenerationTask extends StreamingAiTask {
4681
5385
  var structuredGeneration = (input, config) => {
4682
5386
  return new StructuredGenerationTask({}, config).run(input);
4683
5387
  };
4684
- Workflow31.prototype.structuredGeneration = CreateWorkflow31(StructuredGenerationTask);
5388
+ Workflow33.prototype.structuredGeneration = CreateWorkflow33(StructuredGenerationTask);
4685
5389
 
4686
5390
  // src/task/TextChunkerTask.ts
4687
5391
  import {
4688
- CreateWorkflow as CreateWorkflow32,
4689
- Task as Task13,
4690
- Workflow as Workflow32
5392
+ CreateWorkflow as CreateWorkflow34,
5393
+ Task as Task14,
5394
+ Workflow as Workflow34
4691
5395
  } from "@workglow/task-graph";
4692
5396
  var ChunkingStrategy = {
4693
5397
  FIXED: "fixed",
@@ -4757,7 +5461,7 @@ var outputSchema13 = {
4757
5461
  additionalProperties: false
4758
5462
  };
4759
5463
 
4760
- class TextChunkerTask extends Task13 {
5464
+ class TextChunkerTask extends Task14 {
4761
5465
  static type = "TextChunkerTask";
4762
5466
  static category = "Document";
4763
5467
  static title = "Text Chunker";
@@ -4937,11 +5641,11 @@ class TextChunkerTask extends Task13 {
4937
5641
  var textChunker = (input, config) => {
4938
5642
  return new TextChunkerTask({}, config).run(input);
4939
5643
  };
4940
- Workflow32.prototype.textChunker = CreateWorkflow32(TextChunkerTask);
5644
+ Workflow34.prototype.textChunker = CreateWorkflow34(TextChunkerTask);
4941
5645
 
4942
5646
  // src/task/TextFillMaskTask.ts
4943
- import { CreateWorkflow as CreateWorkflow33, Workflow as Workflow33 } from "@workglow/task-graph";
4944
- var modelSchema22 = TypeModel("model:TextFillMaskTask");
5647
+ import { CreateWorkflow as CreateWorkflow35, Workflow as Workflow35 } from "@workglow/task-graph";
5648
+ var modelSchema24 = TypeModel("model:TextFillMaskTask");
4945
5649
  var TextFillMaskInputSchema = {
4946
5650
  type: "object",
4947
5651
  properties: {
@@ -4950,7 +5654,7 @@ var TextFillMaskInputSchema = {
4950
5654
  title: "Text",
4951
5655
  description: "The text with a mask token to fill"
4952
5656
  }),
4953
- model: modelSchema22
5657
+ model: modelSchema24
4954
5658
  },
4955
5659
  required: ["text", "model"],
4956
5660
  additionalProperties: false
@@ -5005,21 +5709,21 @@ class TextFillMaskTask extends AiTask {
5005
5709
  var textFillMask = (input, config) => {
5006
5710
  return new TextFillMaskTask({}, config).run(input);
5007
5711
  };
5008
- Workflow33.prototype.textFillMask = CreateWorkflow33(TextFillMaskTask);
5712
+ Workflow35.prototype.textFillMask = CreateWorkflow35(TextFillMaskTask);
5009
5713
 
5010
5714
  // src/task/TextGenerationTask.ts
5011
- import { CreateWorkflow as CreateWorkflow34, Workflow as Workflow34 } from "@workglow/task-graph";
5715
+ import { CreateWorkflow as CreateWorkflow36, Workflow as Workflow36 } from "@workglow/task-graph";
5012
5716
  var generatedTextSchema2 = TypeSingleOrArray({
5013
5717
  type: "string",
5014
5718
  title: "Text",
5015
5719
  description: "The generated text",
5016
5720
  "x-stream": "append"
5017
5721
  });
5018
- var modelSchema23 = TypeModel("model:TextGenerationTask");
5722
+ var modelSchema25 = TypeModel("model:TextGenerationTask");
5019
5723
  var TextGenerationInputSchema = {
5020
5724
  type: "object",
5021
5725
  properties: {
5022
- model: modelSchema23,
5726
+ model: modelSchema25,
5023
5727
  prompt: TypeSingleOrArray({
5024
5728
  type: "string",
5025
5729
  title: "Prompt",
@@ -5093,11 +5797,11 @@ class TextGenerationTask extends StreamingAiTask {
5093
5797
  var textGeneration = (input, config) => {
5094
5798
  return new TextGenerationTask({}, config).run(input);
5095
5799
  };
5096
- Workflow34.prototype.textGeneration = CreateWorkflow34(TextGenerationTask);
5800
+ Workflow36.prototype.textGeneration = CreateWorkflow36(TextGenerationTask);
5097
5801
 
5098
5802
  // src/task/TextLanguageDetectionTask.ts
5099
- import { CreateWorkflow as CreateWorkflow35, Workflow as Workflow35 } from "@workglow/task-graph";
5100
- var modelSchema24 = TypeModel("model:TextLanguageDetectionTask");
5803
+ import { CreateWorkflow as CreateWorkflow37, Workflow as Workflow37 } from "@workglow/task-graph";
5804
+ var modelSchema26 = TypeModel("model:TextLanguageDetectionTask");
5101
5805
  var TextLanguageDetectionInputSchema = {
5102
5806
  type: "object",
5103
5807
  properties: {
@@ -5114,7 +5818,7 @@ var TextLanguageDetectionInputSchema = {
5114
5818
  title: "Max Languages",
5115
5819
  description: "The maximum number of languages to return"
5116
5820
  },
5117
- model: modelSchema24
5821
+ model: modelSchema26
5118
5822
  },
5119
5823
  required: ["text", "model"],
5120
5824
  additionalProperties: false
@@ -5164,10 +5868,10 @@ class TextLanguageDetectionTask extends AiTask {
5164
5868
  var textLanguageDetection = (input, config) => {
5165
5869
  return new TextLanguageDetectionTask({}, config).run(input);
5166
5870
  };
5167
- Workflow35.prototype.textLanguageDetection = CreateWorkflow35(TextLanguageDetectionTask);
5871
+ Workflow37.prototype.textLanguageDetection = CreateWorkflow37(TextLanguageDetectionTask);
5168
5872
 
5169
5873
  // src/task/TextQuestionAnswerTask.ts
5170
- import { CreateWorkflow as CreateWorkflow36, Workflow as Workflow36 } from "@workglow/task-graph";
5874
+ import { CreateWorkflow as CreateWorkflow38, Workflow as Workflow38 } from "@workglow/task-graph";
5171
5875
  var contextSchema = TypeSingleOrArray({
5172
5876
  type: "string",
5173
5877
  title: "Context",
@@ -5184,13 +5888,13 @@ var textSchema = TypeSingleOrArray({
5184
5888
  description: "The generated text",
5185
5889
  "x-stream": "append"
5186
5890
  });
5187
- var modelSchema25 = TypeModel("model:TextQuestionAnswerTask");
5891
+ var modelSchema27 = TypeModel("model:TextQuestionAnswerTask");
5188
5892
  var TextQuestionAnswerInputSchema = {
5189
5893
  type: "object",
5190
5894
  properties: {
5191
5895
  context: contextSchema,
5192
5896
  question: questionSchema,
5193
- model: modelSchema25
5897
+ model: modelSchema27
5194
5898
  },
5195
5899
  required: ["context", "question", "model"],
5196
5900
  additionalProperties: false
@@ -5219,11 +5923,11 @@ class TextQuestionAnswerTask extends StreamingAiTask {
5219
5923
  var textQuestionAnswer = (input, config) => {
5220
5924
  return new TextQuestionAnswerTask({}, config).run(input);
5221
5925
  };
5222
- Workflow36.prototype.textQuestionAnswer = CreateWorkflow36(TextQuestionAnswerTask);
5926
+ Workflow38.prototype.textQuestionAnswer = CreateWorkflow38(TextQuestionAnswerTask);
5223
5927
 
5224
5928
  // src/task/TextRewriterTask.ts
5225
- import { CreateWorkflow as CreateWorkflow37, Workflow as Workflow37 } from "@workglow/task-graph";
5226
- var modelSchema26 = TypeModel("model:TextRewriterTask");
5929
+ import { CreateWorkflow as CreateWorkflow39, Workflow as Workflow39 } from "@workglow/task-graph";
5930
+ var modelSchema28 = TypeModel("model:TextRewriterTask");
5227
5931
  var TextRewriterInputSchema = {
5228
5932
  type: "object",
5229
5933
  properties: {
@@ -5237,7 +5941,7 @@ var TextRewriterInputSchema = {
5237
5941
  title: "Prompt",
5238
5942
  description: "The prompt to direct the rewriting"
5239
5943
  },
5240
- model: modelSchema26
5944
+ model: modelSchema28
5241
5945
  },
5242
5946
  required: ["text", "prompt", "model"],
5243
5947
  additionalProperties: false
@@ -5271,11 +5975,11 @@ class TextRewriterTask extends StreamingAiTask {
5271
5975
  var textRewriter = (input, config) => {
5272
5976
  return new TextRewriterTask({}, config).run(input);
5273
5977
  };
5274
- Workflow37.prototype.textRewriter = CreateWorkflow37(TextRewriterTask);
5978
+ Workflow39.prototype.textRewriter = CreateWorkflow39(TextRewriterTask);
5275
5979
 
5276
5980
  // src/task/TextTranslationTask.ts
5277
- import { CreateWorkflow as CreateWorkflow38, Workflow as Workflow38 } from "@workglow/task-graph";
5278
- var modelSchema27 = TypeModel("model:TextTranslationTask");
5981
+ import { CreateWorkflow as CreateWorkflow40, Workflow as Workflow40 } from "@workglow/task-graph";
5982
+ var modelSchema29 = TypeModel("model:TextTranslationTask");
5279
5983
  var translationTextSchema = TypeSingleOrArray({
5280
5984
  type: "string",
5281
5985
  title: "Text",
@@ -5302,7 +6006,7 @@ var TextTranslationInputSchema = {
5302
6006
  minLength: 2,
5303
6007
  maxLength: 2
5304
6008
  }),
5305
- model: modelSchema27
6009
+ model: modelSchema29
5306
6010
  },
5307
6011
  required: ["text", "source_lang", "target_lang", "model"],
5308
6012
  additionalProperties: false
@@ -5337,181 +6041,13 @@ class TextTranslationTask extends StreamingAiTask {
5337
6041
  var textTranslation = (input, config) => {
5338
6042
  return new TextTranslationTask({}, config).run(input);
5339
6043
  };
5340
- Workflow38.prototype.textTranslation = CreateWorkflow38(TextTranslationTask);
5341
-
5342
- // src/task/ToolCallingTask.ts
5343
- import {
5344
- CreateWorkflow as CreateWorkflow39,
5345
- getTaskConstructors,
5346
- Workflow as Workflow39
5347
- } from "@workglow/task-graph";
5348
- import { getLogger } from "@workglow/util";
5349
- function buildToolDescription(tool) {
5350
- let desc = tool.description;
5351
- if (tool.outputSchema && typeof tool.outputSchema === "object") {
5352
- desc += `
5353
-
5354
- Returns: ${JSON.stringify(tool.outputSchema)}`;
5355
- }
5356
- return desc;
5357
- }
5358
- function isAllowedToolName(name, allowedTools) {
5359
- return allowedTools.some((t) => t.name === name);
5360
- }
5361
- function filterValidToolCalls(toolCalls, allowedTools) {
5362
- const filtered = {};
5363
- for (const [key, value] of Object.entries(toolCalls)) {
5364
- const tc = value;
5365
- if (tc.name && isAllowedToolName(tc.name, allowedTools)) {
5366
- filtered[key] = value;
5367
- } else {
5368
- getLogger().warn(`Filtered out tool call with unknown name "${tc.name ?? "(missing)"}"`, {
5369
- callId: key,
5370
- toolName: tc.name
5371
- });
5372
- }
5373
- }
5374
- return filtered;
5375
- }
5376
- function taskTypesToTools(taskNames, registry) {
5377
- const constructors = getTaskConstructors(registry);
5378
- return taskNames.map((name) => {
5379
- const ctor = constructors.get(name);
5380
- if (!ctor) {
5381
- throw new Error(`taskTypesToTools: Unknown task type "${name}" — not found in task constructors registry (ServiceRegistry: ${registry ? "custom" : "default"})`);
5382
- }
5383
- return {
5384
- name: ctor.type,
5385
- description: ctor.description ?? "",
5386
- inputSchema: ctor.inputSchema(),
5387
- outputSchema: ctor.outputSchema()
5388
- };
5389
- });
5390
- }
5391
- var ToolDefinitionSchema = {
5392
- type: "object",
5393
- properties: {
5394
- name: {
5395
- type: "string",
5396
- title: "Name",
5397
- description: "The tool name"
5398
- },
5399
- description: {
5400
- type: "string",
5401
- title: "Description",
5402
- description: "A description of what the tool does"
5403
- },
5404
- inputSchema: {
5405
- type: "object",
5406
- title: "Input Schema",
5407
- description: "JSON Schema describing the tool's input parameters",
5408
- additionalProperties: true
5409
- },
5410
- outputSchema: {
5411
- type: "object",
5412
- title: "Output Schema",
5413
- description: "JSON Schema describing what the tool returns",
5414
- additionalProperties: true
5415
- }
5416
- },
5417
- required: ["name", "description", "inputSchema"],
5418
- additionalProperties: false
5419
- };
5420
- var modelSchema28 = TypeModel("model:ToolCallingTask");
5421
- var ToolCallingInputSchema = {
5422
- type: "object",
5423
- properties: {
5424
- model: modelSchema28,
5425
- prompt: TypeSingleOrArray({
5426
- type: "string",
5427
- title: "Prompt",
5428
- description: "The prompt to send to the model"
5429
- }),
5430
- systemPrompt: {
5431
- type: "string",
5432
- title: "System Prompt",
5433
- description: "Optional system instructions for the model"
5434
- },
5435
- tools: {
5436
- type: "array",
5437
- format: "tasks",
5438
- title: "Tools",
5439
- description: "Tool definitions available for the model to call",
5440
- items: {
5441
- oneOf: [
5442
- { type: "string", format: "tasks", description: "Task type name" },
5443
- ToolDefinitionSchema
5444
- ]
5445
- }
5446
- },
5447
- toolChoice: {
5448
- type: "string",
5449
- title: "Tool Choice",
5450
- description: 'Controls tool selection: "auto" (model decides), "none" (no tools), "required" (must call a tool), or a specific tool name',
5451
- "x-ui-group": "Configuration"
5452
- },
5453
- maxTokens: {
5454
- type: "number",
5455
- title: "Max Tokens",
5456
- description: "The maximum number of tokens to generate",
5457
- minimum: 1,
5458
- "x-ui-group": "Configuration"
5459
- },
5460
- temperature: {
5461
- type: "number",
5462
- title: "Temperature",
5463
- description: "The temperature to use for sampling",
5464
- minimum: 0,
5465
- maximum: 2,
5466
- "x-ui-group": "Configuration"
5467
- }
5468
- },
5469
- required: ["model", "prompt", "tools"],
5470
- additionalProperties: false
5471
- };
5472
- var ToolCallingOutputSchema = {
5473
- type: "object",
5474
- properties: {
5475
- text: TypeSingleOrArray({
5476
- type: "string",
5477
- title: "Text",
5478
- description: "Any text content generated by the model",
5479
- "x-stream": "append"
5480
- }),
5481
- toolCalls: TypeSingleOrArray({
5482
- type: "object",
5483
- title: "Tool Calls",
5484
- description: "Tool invocations requested by the model, keyed by call id",
5485
- additionalProperties: true,
5486
- "x-stream": "object"
5487
- })
5488
- },
5489
- required: ["text", "toolCalls"],
5490
- additionalProperties: false
5491
- };
5492
-
5493
- class ToolCallingTask extends StreamingAiTask {
5494
- static type = "ToolCallingTask";
5495
- static category = "AI Text Model";
5496
- static title = "Tool Calling";
5497
- static description = "Sends a prompt with tool definitions to a language model and returns text along with any tool calls the model requests";
5498
- static inputSchema() {
5499
- return ToolCallingInputSchema;
5500
- }
5501
- static outputSchema() {
5502
- return ToolCallingOutputSchema;
5503
- }
5504
- }
5505
- var toolCalling = (input, config) => {
5506
- return new ToolCallingTask({}, config).run(input);
5507
- };
5508
- Workflow39.prototype.toolCalling = CreateWorkflow39(ToolCallingTask);
6044
+ Workflow40.prototype.textTranslation = CreateWorkflow40(TextTranslationTask);
5509
6045
 
5510
6046
  // src/task/TopicSegmenterTask.ts
5511
6047
  import {
5512
- CreateWorkflow as CreateWorkflow40,
5513
- Task as Task14,
5514
- Workflow as Workflow40
6048
+ CreateWorkflow as CreateWorkflow41,
6049
+ Task as Task15,
6050
+ Workflow as Workflow41
5515
6051
  } from "@workglow/task-graph";
5516
6052
  var SegmentationMethod = {
5517
6053
  HEURISTIC: "heuristic",
@@ -5587,7 +6123,7 @@ var outputSchema14 = {
5587
6123
  additionalProperties: false
5588
6124
  };
5589
6125
 
5590
- class TopicSegmenterTask extends Task14 {
6126
+ class TopicSegmenterTask extends Task15 {
5591
6127
  static type = "TopicSegmenterTask";
5592
6128
  static category = "Document";
5593
6129
  static title = "Topic Segmenter";
@@ -5792,15 +6328,15 @@ class TopicSegmenterTask extends Task14 {
5792
6328
  var topicSegmenter = (input, config) => {
5793
6329
  return new TopicSegmenterTask({}, config).run(input);
5794
6330
  };
5795
- Workflow40.prototype.topicSegmenter = CreateWorkflow40(TopicSegmenterTask);
6331
+ Workflow41.prototype.topicSegmenter = CreateWorkflow41(TopicSegmenterTask);
5796
6332
 
5797
6333
  // src/task/UnloadModelTask.ts
5798
- import { CreateWorkflow as CreateWorkflow41, Workflow as Workflow41 } from "@workglow/task-graph";
5799
- var modelSchema29 = TypeModel("model");
6334
+ import { CreateWorkflow as CreateWorkflow42, Workflow as Workflow42 } from "@workglow/task-graph";
6335
+ var modelSchema30 = TypeModel("model");
5800
6336
  var UnloadModelInputSchema = {
5801
6337
  type: "object",
5802
6338
  properties: {
5803
- model: modelSchema29
6339
+ model: modelSchema30
5804
6340
  },
5805
6341
  required: ["model"],
5806
6342
  additionalProperties: false
@@ -5808,7 +6344,7 @@ var UnloadModelInputSchema = {
5808
6344
  var UnloadModelOutputSchema = {
5809
6345
  type: "object",
5810
6346
  properties: {
5811
- model: modelSchema29
6347
+ model: modelSchema30
5812
6348
  },
5813
6349
  required: ["model"],
5814
6350
  additionalProperties: false
@@ -5830,10 +6366,10 @@ class UnloadModelTask extends AiTask {
5830
6366
  var unloadModel = (input, config) => {
5831
6367
  return new UnloadModelTask({}, config).run(input);
5832
6368
  };
5833
- Workflow41.prototype.unloadModel = CreateWorkflow41(UnloadModelTask);
6369
+ Workflow42.prototype.unloadModel = CreateWorkflow42(UnloadModelTask);
5834
6370
 
5835
6371
  // src/task/VectorQuantizeTask.ts
5836
- import { CreateWorkflow as CreateWorkflow42, Task as Task15, Workflow as Workflow42 } from "@workglow/task-graph";
6372
+ import { CreateWorkflow as CreateWorkflow43, Task as Task16, Workflow as Workflow43 } from "@workglow/task-graph";
5837
6373
  import {
5838
6374
  normalizeNumberArray,
5839
6375
  TensorType,
@@ -5913,7 +6449,7 @@ var outputSchema15 = {
5913
6449
  additionalProperties: false
5914
6450
  };
5915
6451
 
5916
- class VectorQuantizeTask extends Task15 {
6452
+ class VectorQuantizeTask extends Task16 {
5917
6453
  static type = "VectorQuantizeTask";
5918
6454
  static category = "Vector";
5919
6455
  static title = "Quantize";
@@ -6013,10 +6549,10 @@ class VectorQuantizeTask extends Task15 {
6013
6549
  var vectorQuantize = (input, config) => {
6014
6550
  return new VectorQuantizeTask({}, config).run(input);
6015
6551
  };
6016
- Workflow42.prototype.vectorQuantize = CreateWorkflow42(VectorQuantizeTask);
6552
+ Workflow43.prototype.vectorQuantize = CreateWorkflow43(VectorQuantizeTask);
6017
6553
 
6018
6554
  // src/task/VectorSimilarityTask.ts
6019
- import { CreateWorkflow as CreateWorkflow43, GraphAsTask, Workflow as Workflow43 } from "@workglow/task-graph";
6555
+ import { CreateWorkflow as CreateWorkflow44, GraphAsTask, Workflow as Workflow44 } from "@workglow/task-graph";
6020
6556
  import {
6021
6557
  cosineSimilarity,
6022
6558
  hammingSimilarity,
@@ -6090,7 +6626,7 @@ var SimilarityOutputSchema = {
6090
6626
 
6091
6627
  class VectorSimilarityTask extends GraphAsTask {
6092
6628
  static type = "VectorSimilarityTask";
6093
- static category = "Analysis";
6629
+ static category = "Vector";
6094
6630
  static title = "Vector Similarity";
6095
6631
  static description = "Compares vectors using similarity functions and returns top-K ranked results";
6096
6632
  static cacheable = true;
@@ -6122,11 +6658,208 @@ class VectorSimilarityTask extends GraphAsTask {
6122
6658
  var similarity = (input, config) => {
6123
6659
  return new VectorSimilarityTask({}, config).run(input);
6124
6660
  };
6125
- Workflow43.prototype.similarity = CreateWorkflow43(VectorSimilarityTask);
6661
+ Workflow44.prototype.similarity = CreateWorkflow44(VectorSimilarityTask);
6662
+ // src/task/MessageConversion.ts
6663
+ function getInputMessages(input) {
6664
+ const messages = input.messages;
6665
+ if (!messages || messages.length === 0)
6666
+ return;
6667
+ return messages;
6668
+ }
6669
+ function toOpenAIMessages(input) {
6670
+ const messages = [];
6671
+ if (input.systemPrompt) {
6672
+ messages.push({ role: "system", content: input.systemPrompt });
6673
+ }
6674
+ const inputMessages = getInputMessages(input);
6675
+ if (!inputMessages) {
6676
+ if (!Array.isArray(input.prompt)) {
6677
+ messages.push({ role: "user", content: input.prompt });
6678
+ } else if (input.prompt.every((item) => typeof item === "string")) {
6679
+ messages.push({ role: "user", content: input.prompt.join(`
6680
+ `) });
6681
+ } else {
6682
+ const parts = [];
6683
+ for (const item of input.prompt) {
6684
+ if (typeof item === "string") {
6685
+ parts.push({ type: "text", text: item });
6686
+ } else {
6687
+ const b = item;
6688
+ if (b.type === "text") {
6689
+ parts.push({ type: "text", text: b.text });
6690
+ } else if (b.type === "image") {
6691
+ parts.push({
6692
+ type: "image_url",
6693
+ image_url: { url: `data:${b.mimeType};base64,${b.data}` }
6694
+ });
6695
+ } else if (b.type === "audio") {
6696
+ const format = b.mimeType.replace(/^audio\//, "");
6697
+ parts.push({
6698
+ type: "input_audio",
6699
+ input_audio: { data: b.data, format }
6700
+ });
6701
+ }
6702
+ }
6703
+ }
6704
+ messages.push({ role: "user", content: parts });
6705
+ }
6706
+ return messages;
6707
+ }
6708
+ for (const msg of inputMessages) {
6709
+ if (msg.role === "user") {
6710
+ if (typeof msg.content === "string") {
6711
+ messages.push({ role: "user", content: msg.content });
6712
+ } else if (Array.isArray(msg.content) && msg.content.length > 0 && typeof msg.content[0]?.type === "string") {
6713
+ const parts = [];
6714
+ for (const block of msg.content) {
6715
+ const b = block;
6716
+ if (b.type === "text") {
6717
+ parts.push({ type: "text", text: b.text });
6718
+ } else if (b.type === "image") {
6719
+ parts.push({
6720
+ type: "image_url",
6721
+ image_url: { url: `data:${b.mimeType};base64,${b.data}` }
6722
+ });
6723
+ } else if (b.type === "audio") {
6724
+ const format = b.mimeType.replace(/^audio\//, "");
6725
+ parts.push({
6726
+ type: "input_audio",
6727
+ input_audio: { data: b.data, format }
6728
+ });
6729
+ }
6730
+ }
6731
+ messages.push({ role: "user", content: parts });
6732
+ } else {
6733
+ try {
6734
+ messages.push({ role: "user", content: JSON.stringify(msg.content) });
6735
+ } catch {
6736
+ messages.push({ role: "user", content: String(msg.content) });
6737
+ }
6738
+ }
6739
+ } else if (msg.role === "assistant") {
6740
+ if (typeof msg.content === "string") {
6741
+ messages.push({ role: "assistant", content: msg.content.length > 0 ? msg.content : null });
6742
+ } else if (Array.isArray(msg.content)) {
6743
+ const textParts = msg.content.filter((b) => b.type === "text").map((b) => b.text).join("");
6744
+ const toolCalls = msg.content.filter((b) => b.type === "tool_use").map((b) => ({
6745
+ id: b.id,
6746
+ type: "function",
6747
+ function: {
6748
+ name: b.name,
6749
+ arguments: JSON.stringify(b.input)
6750
+ }
6751
+ }));
6752
+ const entry = {
6753
+ role: "assistant",
6754
+ content: textParts.length > 0 ? textParts : null
6755
+ };
6756
+ if (toolCalls.length > 0) {
6757
+ entry.tool_calls = toolCalls;
6758
+ }
6759
+ messages.push(entry);
6760
+ }
6761
+ } else if (msg.role === "tool" && Array.isArray(msg.content)) {
6762
+ for (const block of msg.content) {
6763
+ const b = block;
6764
+ let content;
6765
+ if (typeof b.content === "string") {
6766
+ content = b.content;
6767
+ } else if (Array.isArray(b.content)) {
6768
+ const parts = [];
6769
+ for (const inner of b.content) {
6770
+ if (inner.type === "text") {
6771
+ parts.push({ type: "text", text: inner.text });
6772
+ } else if (inner.type === "image") {
6773
+ parts.push({
6774
+ type: "image_url",
6775
+ image_url: { url: `data:${inner.mimeType};base64,${inner.data}` }
6776
+ });
6777
+ }
6778
+ }
6779
+ content = parts;
6780
+ } else {
6781
+ content = "";
6782
+ }
6783
+ messages.push({
6784
+ role: "tool",
6785
+ content,
6786
+ tool_call_id: b.tool_use_id
6787
+ });
6788
+ }
6789
+ }
6790
+ }
6791
+ return messages;
6792
+ }
6793
+ function toTextFlatMessages(input) {
6794
+ const messages = [];
6795
+ if (input.systemPrompt) {
6796
+ messages.push({ role: "system", content: input.systemPrompt });
6797
+ }
6798
+ const inputMessages = getInputMessages(input);
6799
+ if (!inputMessages) {
6800
+ let promptContent;
6801
+ if (!Array.isArray(input.prompt)) {
6802
+ promptContent = input.prompt;
6803
+ } else {
6804
+ promptContent = input.prompt.map((item) => {
6805
+ if (typeof item === "string")
6806
+ return item;
6807
+ const b = item;
6808
+ return b.type === "text" ? b.text : "";
6809
+ }).filter((s) => s !== "").join(`
6810
+ `);
6811
+ }
6812
+ messages.push({ role: "user", content: promptContent });
6813
+ return messages;
6814
+ }
6815
+ for (const msg of inputMessages) {
6816
+ if (msg.role === "user") {
6817
+ let content = "";
6818
+ if (typeof msg.content === "string") {
6819
+ content = msg.content;
6820
+ } else if (Array.isArray(msg.content) && msg.content.length > 0 && typeof msg.content[0]?.type === "string") {
6821
+ content = msg.content.filter((b) => b.type === "text").map((b) => b.text).join("");
6822
+ } else if (msg.content != null) {
6823
+ try {
6824
+ content = JSON.stringify(msg.content);
6825
+ } catch {
6826
+ content = String(msg.content);
6827
+ }
6828
+ }
6829
+ messages.push({ role: "user", content });
6830
+ } else if (msg.role === "assistant") {
6831
+ if (typeof msg.content === "string") {
6832
+ if (msg.content) {
6833
+ messages.push({ role: "assistant", content: msg.content });
6834
+ }
6835
+ } else if (Array.isArray(msg.content)) {
6836
+ const text = msg.content.filter((b) => b.type === "text").map((b) => b.text).join("");
6837
+ if (text) {
6838
+ messages.push({ role: "assistant", content: text });
6839
+ }
6840
+ }
6841
+ } else if (msg.role === "tool" && Array.isArray(msg.content)) {
6842
+ for (const block of msg.content) {
6843
+ const b = block;
6844
+ let content;
6845
+ if (typeof b.content === "string") {
6846
+ content = b.content;
6847
+ } else if (Array.isArray(b.content)) {
6848
+ content = b.content.filter((inner) => inner.type === "text").map((inner) => inner.text).join("");
6849
+ } else {
6850
+ content = "";
6851
+ }
6852
+ messages.push({ role: "tool", content });
6853
+ }
6854
+ }
6855
+ }
6856
+ return messages;
6857
+ }
6126
6858
 
6127
6859
  // src/task/index.ts
6128
6860
  var registerAiTasks = () => {
6129
6861
  const tasks = [
6862
+ AgentTask,
6130
6863
  BackgroundRemovalTask,
6131
6864
  ChunkToVectorTask,
6132
6865
  CountTokensTask,
@@ -6177,9 +6910,14 @@ var registerAiTasks = () => {
6177
6910
  export {
6178
6911
  vectorStoreSearch,
6179
6912
  vectorQuantize,
6913
+ userMessage,
6180
6914
  unloadModel,
6181
6915
  topicSegmenter,
6916
+ toolSourceDefinitions,
6917
+ toolMessage,
6182
6918
  toolCalling,
6919
+ toTextFlatMessages,
6920
+ toOpenAIMessages,
6183
6921
  textTranslation,
6184
6922
  textSummary,
6185
6923
  textRewriter,
@@ -6208,16 +6946,22 @@ export {
6208
6946
  imageSegmentation,
6209
6947
  imageEmbedding,
6210
6948
  imageClassification,
6949
+ imageBlockFromDataUri,
6950
+ imageBlock,
6211
6951
  hybridSearch,
6212
6952
  hierarchyJoin,
6213
6953
  hierarchicalChunker,
6954
+ hasToolCalls,
6214
6955
  handLandmarker,
6215
6956
  getGlobalModelRepository,
6216
6957
  getAiProviderRegistry,
6217
6958
  gestureRecognizer,
6959
+ findToolSource,
6218
6960
  filterValidToolCalls,
6219
6961
  faceLandmarker,
6220
6962
  faceDetector,
6963
+ executeToolCalls,
6964
+ executeToolCall,
6221
6965
  downloadModel,
6222
6966
  documentEnricher,
6223
6967
  countTokens,
@@ -6225,8 +6969,13 @@ export {
6225
6969
  chunkVectorUpsert,
6226
6970
  chunkToVector,
6227
6971
  chunkRetrieval,
6972
+ buildToolSources,
6228
6973
  buildToolDescription,
6229
6974
  backgroundRemoval,
6975
+ audioBlockFromDataUri,
6976
+ audioBlock,
6977
+ assistantMessage,
6978
+ agent,
6230
6979
  VectorSimilarityTask,
6231
6980
  VectorQuantizeTask,
6232
6981
  UnloadModelTask,
@@ -6343,7 +7092,10 @@ export {
6343
7092
  AiTask,
6344
7093
  AiProviderRegistry,
6345
7094
  AiProvider,
6346
- AiJob
7095
+ AiJob,
7096
+ AgentTask,
7097
+ AgentOutputSchema,
7098
+ AgentInputSchema
6347
7099
  };
6348
7100
 
6349
- //# debugId=FA713AFFB061070264756E2164756E21
7101
+ //# debugId=7632C16D204CE7AB64756E2164756E21