@workglow/ai 0.0.115 → 0.0.117

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