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