@workglow/tasks 0.0.101 → 0.0.103

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/browser.js +1693 -1362
  2. package/dist/browser.js.map +17 -17
  3. package/dist/bun.js +1747 -1393
  4. package/dist/bun.js.map +18 -18
  5. package/dist/common.d.ts +1 -2
  6. package/dist/common.d.ts.map +1 -1
  7. package/dist/node.js +1747 -1393
  8. package/dist/node.js.map +18 -18
  9. package/dist/task/DebugLogTask.d.ts +1 -0
  10. package/dist/task/DebugLogTask.d.ts.map +1 -1
  11. package/dist/task/DelayTask.d.ts +2 -1
  12. package/dist/task/DelayTask.d.ts.map +1 -1
  13. package/dist/task/FileLoaderTask.d.ts +23 -0
  14. package/dist/task/FileLoaderTask.d.ts.map +1 -1
  15. package/dist/task/FileLoaderTask.server.d.ts +3 -0
  16. package/dist/task/FileLoaderTask.server.d.ts.map +1 -1
  17. package/dist/task/InputTask.d.ts.map +1 -1
  18. package/dist/task/JavaScriptTask.d.ts +66 -1
  19. package/dist/task/JavaScriptTask.d.ts.map +1 -1
  20. package/dist/task/LambdaTask.d.ts +10 -1
  21. package/dist/task/LambdaTask.d.ts.map +1 -1
  22. package/dist/task/OutputTask.d.ts.map +1 -1
  23. package/dist/task/mcp/McpListTask.d.ts +2 -2
  24. package/dist/task/mcp/McpPromptGetTask.d.ts +158 -66
  25. package/dist/task/mcp/McpPromptGetTask.d.ts.map +1 -1
  26. package/dist/task/mcp/McpResourceReadTask.d.ts +155 -47
  27. package/dist/task/mcp/McpResourceReadTask.d.ts.map +1 -1
  28. package/dist/task/mcp/McpToolCallTask.d.ts +156 -323
  29. package/dist/task/mcp/McpToolCallTask.d.ts.map +1 -1
  30. package/package.json +9 -9
  31. package/dist/task/scalar/scalar.test.d.ts +0 -7
  32. package/dist/task/scalar/scalar.test.d.ts.map +0 -1
  33. package/dist/task/vector/vector.test.d.ts +0 -7
  34. package/dist/task/vector/vector.test.d.ts.map +0 -1
package/dist/bun.js CHANGED
@@ -4,1090 +4,436 @@ var __require = import.meta.require;
4
4
  // src/bun.ts
5
5
  import { TaskRegistry as TaskRegistry2 } from "@workglow/task-graph";
6
6
 
7
- // src/task/FileLoaderTask.server.ts
8
- import {
9
- CreateWorkflow as CreateWorkflow3,
10
- TaskAbortedError as TaskAbortedError2,
11
- Workflow as Workflow3
12
- } from "@workglow/task-graph";
13
- import { readFile } from "fs/promises";
7
+ // src/task/adaptive.ts
8
+ import { CreateAdaptiveWorkflow, Workflow as Workflow10 } from "@workglow/task-graph";
14
9
 
15
- // src/task/FileLoaderTask.ts
16
- import {
17
- CreateWorkflow as CreateWorkflow2,
18
- Task,
19
- TaskAbortedError,
20
- Workflow as Workflow2
21
- } from "@workglow/task-graph";
22
- import Papa from "papaparse";
10
+ // src/task/scalar/ScalarAddTask.ts
11
+ import { CreateWorkflow, Task, Workflow } from "@workglow/task-graph";
23
12
 
24
- // src/task/FetchUrlTask.ts
25
- import {
26
- AbortSignalJobError,
27
- Job,
28
- PermanentJobError,
29
- RetryableJobError
30
- } from "@workglow/job-queue";
31
- import {
32
- CreateWorkflow,
33
- JobQueueTask,
34
- TaskConfigurationError,
35
- TaskInvalidInputError,
36
- Workflow
37
- } from "@workglow/task-graph";
13
+ // src/task/scalar/sumPrecise.ts
14
+ function kahanSum(values) {
15
+ let sum = 0;
16
+ let compensation = 0;
17
+ for (const value of values) {
18
+ const y = value - compensation;
19
+ const t = sum + y;
20
+ compensation = t - sum - y;
21
+ sum = t;
22
+ }
23
+ return sum;
24
+ }
25
+ var nativeSumPrecise = typeof Math.sumPrecise === "function" ? Math.sumPrecise : undefined;
26
+ var sumPrecise = nativeSumPrecise ? nativeSumPrecise.bind(Math) : kahanSum;
27
+
28
+ // src/task/scalar/ScalarAddTask.ts
38
29
  var inputSchema = {
39
30
  type: "object",
40
31
  properties: {
41
- url: {
42
- type: "string",
43
- title: "URL",
44
- description: "The URL to fetch from",
45
- format: "uri"
46
- },
47
- method: {
48
- enum: ["GET", "POST", "PUT", "DELETE", "PATCH"],
49
- title: "Method",
50
- description: "The HTTP method to use",
51
- default: "GET"
52
- },
53
- headers: {
54
- type: "object",
55
- additionalProperties: {
56
- type: "string"
57
- },
58
- title: "Headers",
59
- description: "The headers to send with the request"
60
- },
61
- body: {
62
- type: "string",
63
- title: "Body",
64
- description: "The body of the request"
65
- },
66
- response_type: {
67
- anyOf: [{ type: "null" }, { enum: ["json", "text", "blob", "arraybuffer"] }],
68
- title: "Response Type",
69
- description: "The forced type of response to return. If null, the response type is inferred from the Content-Type header.",
70
- default: null
71
- },
72
- timeout: {
32
+ a: {
73
33
  type: "number",
74
- title: "Timeout",
75
- description: "Request timeout in milliseconds"
34
+ title: "A",
35
+ description: "First number"
76
36
  },
77
- queue: {
78
- oneOf: [{ type: "boolean" }, { type: "string" }],
79
- description: "Queue handling: false=run inline, true=use default, string=explicit queue name",
80
- default: true,
81
- "x-ui-hidden": true
37
+ b: {
38
+ type: "number",
39
+ title: "B",
40
+ description: "Second number"
82
41
  }
83
42
  },
84
- required: ["url"],
43
+ required: ["a", "b"],
85
44
  additionalProperties: false
86
45
  };
87
46
  var outputSchema = {
88
47
  type: "object",
89
48
  properties: {
90
- json: {
91
- title: "JSON",
92
- description: "The JSON response"
93
- },
94
- text: {
95
- type: "string",
96
- title: "Text",
97
- description: "The text response"
98
- },
99
- blob: {
100
- title: "Blob",
101
- description: "The blob response"
102
- },
103
- arraybuffer: {
104
- title: "ArrayBuffer",
105
- description: "The arraybuffer response"
106
- },
107
- metadata: {
108
- type: "object",
109
- properties: {
110
- contentType: { type: "string" },
111
- headers: { type: "object", additionalProperties: { type: "string" } }
112
- },
113
- additionalProperties: false,
114
- title: "Response Metadata",
115
- description: "HTTP response metadata including content type and headers"
49
+ result: {
50
+ type: "number",
51
+ title: "Result",
52
+ description: "Sum of a and b"
116
53
  }
117
54
  },
55
+ required: ["result"],
118
56
  additionalProperties: false
119
57
  };
120
- async function fetchWithProgress(url, options = {}, onProgress) {
121
- if (!options.signal) {
122
- throw new TaskConfigurationError("An AbortSignal must be provided.");
123
- }
124
- const response = await globalThis.fetch(url, options);
125
- if (!response.body) {
126
- throw new Error("ReadableStream not supported in this environment.");
127
- }
128
- const contentLength = response.headers.get("Content-Length");
129
- const totalBytes = contentLength ? parseInt(contentLength, 10) : 0;
130
- let receivedBytes = 0;
131
- const reader = response.body.getReader();
132
- const stream = new ReadableStream({
133
- start(controller) {
134
- async function push() {
135
- try {
136
- while (true) {
137
- if (options.signal?.aborted) {
138
- controller.error(new AbortSignalJobError("Fetch aborted"));
139
- reader.cancel();
140
- return;
141
- }
142
- const { done, value } = await reader.read();
143
- if (done) {
144
- controller.close();
145
- break;
146
- }
147
- controller.enqueue(value);
148
- receivedBytes += value.length;
149
- if (onProgress && totalBytes) {
150
- await onProgress(receivedBytes / totalBytes * 100);
151
- }
152
- }
153
- } catch (error) {
154
- controller.error(error);
155
- }
156
- }
157
- push();
158
- },
159
- cancel() {
160
- reader.cancel();
161
- }
162
- });
163
- return new Response(stream, {
164
- headers: response.headers,
165
- status: response.status,
166
- statusText: response.statusText
167
- });
168
- }
169
-
170
- class FetchUrlJob extends Job {
171
- constructor(config = { input: {} }) {
172
- super(config);
173
- }
174
- static type = "FetchUrlJob";
175
- async execute(input, context) {
176
- const response = await fetchWithProgress(input.url, {
177
- method: input.method,
178
- headers: input.headers,
179
- body: input.body,
180
- signal: context.signal
181
- }, async (progress) => await context.updateProgress(progress));
182
- if (response.ok) {
183
- const contentType = response.headers.get("content-type") ?? "";
184
- const headers = {};
185
- response.headers.forEach((value, key) => {
186
- headers[key] = value;
187
- });
188
- const metadata = {
189
- contentType,
190
- headers
191
- };
192
- let responseType = input.response_type;
193
- if (!responseType) {
194
- if (contentType.includes("application/json")) {
195
- responseType = "json";
196
- } else if (contentType.includes("text/")) {
197
- responseType = "text";
198
- } else if (contentType.includes("application/octet-stream")) {
199
- responseType = "arraybuffer";
200
- } else if (contentType.includes("application/pdf") || contentType.includes("image/") || contentType.includes("application/zip")) {
201
- responseType = "blob";
202
- } else {
203
- responseType = "json";
204
- }
205
- input.response_type = responseType;
206
- }
207
- if (responseType === "json") {
208
- return { json: await response.json(), metadata };
209
- } else if (responseType === "text") {
210
- return { text: await response.text(), metadata };
211
- } else if (responseType === "blob") {
212
- return { blob: await response.blob(), metadata };
213
- } else if (responseType === "arraybuffer") {
214
- return { arraybuffer: await response.arrayBuffer(), metadata };
215
- }
216
- throw new TaskInvalidInputError(`Invalid response type: ${responseType}`);
217
- } else {
218
- if (response.status === 429 || response.status === 503 || response.headers.get("Retry-After")) {
219
- let retryDate;
220
- const retryAfterStr = response.headers.get("Retry-After");
221
- if (retryAfterStr) {
222
- const parsedDate = new Date(retryAfterStr);
223
- if (!isNaN(parsedDate.getTime()) && parsedDate > new Date) {
224
- retryDate = parsedDate;
225
- } else {
226
- const retryAfterSeconds = parseInt(retryAfterStr) * 1000;
227
- if (!isNaN(retryAfterSeconds)) {
228
- retryDate = new Date(Date.now() + retryAfterSeconds);
229
- }
230
- }
231
- }
232
- throw new RetryableJobError(`Failed to fetch ${input.url}: ${response.status} ${response.statusText}`, retryDate);
233
- } else {
234
- throw new PermanentJobError(`Failed to fetch ${input.url}: ${response.status} ${response.statusText}`);
235
- }
236
- }
237
- }
238
- }
239
58
 
240
- class FetchUrlTask extends JobQueueTask {
241
- static type = "FetchUrlTask";
242
- static category = "Input";
243
- static title = "Fetch";
244
- static description = "Fetches data from a URL with progress tracking and automatic retry handling";
245
- static hasDynamicSchemas = true;
59
+ class ScalarAddTask extends Task {
60
+ static type = "ScalarAddTask";
61
+ static category = "Math";
62
+ static title = "Add";
63
+ static description = "Returns the sum of two numbers";
246
64
  static inputSchema() {
247
65
  return inputSchema;
248
66
  }
249
67
  static outputSchema() {
250
68
  return outputSchema;
251
69
  }
252
- outputSchema() {
253
- const responseType = this.runInputData?.response_type ?? this.defaults?.response_type ?? null;
254
- if (responseType === null || responseType === undefined) {
255
- return this.constructor.outputSchema();
256
- }
257
- const staticSchema = this.constructor.outputSchema();
258
- if (typeof staticSchema === "boolean") {
259
- return staticSchema;
260
- }
261
- if (!staticSchema.properties) {
262
- return staticSchema;
263
- }
264
- const properties = {};
265
- if (responseType === "json" && staticSchema.properties.json) {
266
- properties.json = staticSchema.properties.json;
267
- } else if (responseType === "text" && staticSchema.properties.text) {
268
- properties.text = staticSchema.properties.text;
269
- } else if (responseType === "blob" && staticSchema.properties.blob) {
270
- properties.blob = staticSchema.properties.blob;
271
- } else if (responseType === "arraybuffer" && staticSchema.properties.arraybuffer) {
272
- properties.arraybuffer = staticSchema.properties.arraybuffer;
273
- }
274
- if (staticSchema.properties.metadata) {
275
- properties.metadata = staticSchema.properties.metadata;
276
- }
277
- if (Object.keys(properties).length === 0) {
278
- return staticSchema;
279
- }
280
- return {
281
- type: "object",
282
- properties,
283
- additionalProperties: false
284
- };
285
- }
286
- constructor(input = {}, config = {}) {
287
- config.queue = input?.queue ?? config.queue;
288
- if (config.queue === undefined) {
289
- config.queue = false;
290
- }
291
- super(input, config);
292
- this.jobClass = FetchUrlJob;
293
- }
294
- setInput(input) {
295
- if (!("response_type" in input)) {
296
- super.setInput(input);
297
- return;
298
- }
299
- const getCurrentResponseType = () => {
300
- return this.runInputData?.response_type ?? this.defaults?.response_type ?? null;
301
- };
302
- const previousResponseType = getCurrentResponseType();
303
- super.setInput(input);
304
- const newResponseType = getCurrentResponseType();
305
- if (previousResponseType !== newResponseType) {
306
- this.emitSchemaChange();
307
- }
308
- }
309
- async getDefaultQueueName(input) {
310
- if (!input.url) {
311
- return `fetch:${this.type}`;
312
- }
313
- try {
314
- const hostname = new URL(input.url).hostname.toLowerCase();
315
- const parts = hostname.split(".").filter(Boolean);
316
- if (parts.length === 0) {
317
- return `fetch:${this.type}`;
318
- }
319
- const domain = parts.length <= 2 ? parts.join(".") : parts.slice(-2).join(".");
320
- return `fetch:${domain}`;
321
- } catch {
322
- return `fetch:${this.type}`;
323
- }
70
+ async execute(input, _context) {
71
+ return { result: sumPrecise([input.a, input.b]) };
324
72
  }
325
73
  }
326
- var fetchUrl = async (input, config = {}) => {
327
- const result = await new FetchUrlTask({}, config).run(input);
328
- return result;
329
- };
330
- Workflow.prototype.fetch = CreateWorkflow(FetchUrlTask);
74
+ Workflow.prototype.scalarAdd = CreateWorkflow(ScalarAddTask);
331
75
 
332
- // src/task/FileLoaderTask.ts
76
+ // src/task/scalar/ScalarDivideTask.ts
77
+ import { CreateWorkflow as CreateWorkflow2, Task as Task2, Workflow as Workflow2 } from "@workglow/task-graph";
333
78
  var inputSchema2 = {
334
79
  type: "object",
335
80
  properties: {
336
- url: {
337
- type: "string",
338
- title: "URL",
339
- description: "URL to load document from (http://, https://)",
340
- format: "uri"
81
+ a: {
82
+ type: "number",
83
+ title: "A",
84
+ description: "Numerator"
341
85
  },
342
- format: {
343
- type: "string",
344
- enum: ["text", "markdown", "json", "csv", "pdf", "image", "html", "auto"],
345
- title: "Format",
346
- description: "File format (auto-detected from URL if 'auto')",
347
- default: "auto"
86
+ b: {
87
+ type: "number",
88
+ title: "B",
89
+ description: "Denominator"
348
90
  }
349
91
  },
350
- required: ["url"],
92
+ required: ["a", "b"],
351
93
  additionalProperties: false
352
94
  };
353
95
  var outputSchema2 = {
354
96
  type: "object",
355
97
  properties: {
356
- text: {
357
- type: "string",
358
- title: "Text",
359
- description: "Text content (for text, markdown, html formats)"
360
- },
361
- json: {
362
- title: "JSON",
363
- description: "Parsed JSON object or array"
364
- },
365
- csv: {
366
- type: "array",
367
- title: "CSV",
368
- description: "Parsed CSV data as array of objects"
369
- },
370
- image: {
371
- type: "string",
372
- title: "Image",
373
- description: "Base64 data URL for image files",
374
- format: "image:data-uri"
375
- },
376
- pdf: {
377
- type: "string",
378
- title: "PDF",
379
- description: "Base64 data URL for PDF files"
380
- },
381
- metadata: {
382
- type: "object",
383
- properties: {
384
- url: { type: "string" },
385
- format: { type: "string" },
386
- size: { type: "number" },
387
- title: { type: "string" },
388
- mimeType: { type: "string" }
389
- },
390
- additionalProperties: false,
391
- title: "Metadata",
392
- description: "File metadata"
98
+ result: {
99
+ type: "number",
100
+ title: "Result",
101
+ description: "Quotient (a / b)"
393
102
  }
394
103
  },
395
- required: ["metadata"],
104
+ required: ["result"],
396
105
  additionalProperties: false
397
106
  };
398
107
 
399
- class FileLoaderTask extends Task {
400
- static type = "FileLoaderTask";
401
- static category = "Document";
402
- static title = "File Loader";
403
- static description = "Load documents from URLs (http://, https://)";
404
- static cacheable = true;
108
+ class ScalarDivideTask extends Task2 {
109
+ static type = "ScalarDivideTask";
110
+ static category = "Math";
111
+ static title = "Divide";
112
+ static description = "Returns the quotient of two numbers (a / b)";
405
113
  static inputSchema() {
406
114
  return inputSchema2;
407
115
  }
408
116
  static outputSchema() {
409
117
  return outputSchema2;
410
118
  }
411
- async execute(input, context) {
412
- const { url, format = "auto" } = input;
413
- if (context.signal.aborted) {
414
- throw new TaskAbortedError("Task aborted");
415
- }
416
- await context.updateProgress(0, "Detecting file format");
417
- const detectedFormat = this.detectFormat(url, format);
418
- const responseType = this.detectResponseType(detectedFormat);
419
- if (context.signal.aborted) {
420
- throw new TaskAbortedError("Task aborted");
421
- }
422
- await context.updateProgress(10, `Fetching ${detectedFormat} file from ${url}`);
423
- const fetchTask = context.own(new FetchUrlTask({
424
- url,
425
- response_type: responseType,
426
- queue: false
427
- }));
428
- const response = await fetchTask.run();
429
- if (context.signal.aborted) {
430
- throw new TaskAbortedError("Task aborted");
119
+ async execute(input, _context) {
120
+ return { result: input.a / input.b };
121
+ }
122
+ }
123
+ Workflow2.prototype.scalarDivide = CreateWorkflow2(ScalarDivideTask);
124
+
125
+ // src/task/scalar/ScalarMultiplyTask.ts
126
+ import { CreateWorkflow as CreateWorkflow3, Task as Task3, Workflow as Workflow3 } from "@workglow/task-graph";
127
+ var inputSchema3 = {
128
+ type: "object",
129
+ properties: {
130
+ a: {
131
+ type: "number",
132
+ title: "A",
133
+ description: "First number"
134
+ },
135
+ b: {
136
+ type: "number",
137
+ title: "B",
138
+ description: "Second number"
431
139
  }
432
- await context.updateProgress(60, "Parsing file content");
433
- const title = url.split("/").pop() || url;
434
- const { text, json, csv, image, pdf, size, mimeType } = await this.parseResponse(response, url, detectedFormat);
435
- if (context.signal.aborted) {
436
- throw new TaskAbortedError("Task aborted");
140
+ },
141
+ required: ["a", "b"],
142
+ additionalProperties: false
143
+ };
144
+ var outputSchema3 = {
145
+ type: "object",
146
+ properties: {
147
+ result: {
148
+ type: "number",
149
+ title: "Result",
150
+ description: "Product of a and b"
437
151
  }
438
- await context.updateProgress(100, "File loaded successfully");
439
- return {
440
- text,
441
- json,
442
- csv,
443
- image,
444
- pdf,
445
- metadata: {
446
- url,
447
- format: detectedFormat,
448
- size,
449
- title,
450
- mimeType
451
- }
452
- };
152
+ },
153
+ required: ["result"],
154
+ additionalProperties: false
155
+ };
156
+
157
+ class ScalarMultiplyTask extends Task3 {
158
+ static type = "ScalarMultiplyTask";
159
+ static category = "Math";
160
+ static title = "Multiply";
161
+ static description = "Returns the product of two numbers";
162
+ static inputSchema() {
163
+ return inputSchema3;
453
164
  }
454
- parseJsonContent(content) {
455
- return JSON.parse(content);
165
+ static outputSchema() {
166
+ return outputSchema3;
456
167
  }
457
- parseCsvContent(content) {
458
- try {
459
- const result = Papa.parse(content, {
460
- header: true,
461
- skipEmptyLines: true,
462
- transformHeader: (header) => header.trim()
463
- });
464
- return result.data;
465
- } catch (error) {
466
- throw new Error(`Failed to parse CSV: ${error}`);
467
- }
168
+ async execute(input, _context) {
169
+ return { result: input.a * input.b };
468
170
  }
469
- async parseResponse(response, url, detectedFormat) {
470
- const responseMimeType = response.metadata?.contentType || "";
471
- if (detectedFormat === "json") {
472
- if (!response.json) {
473
- throw new Error(`Failed to load JSON from ${url}`);
474
- }
475
- const jsonData = response.json;
476
- const content2 = JSON.stringify(jsonData, null, 2);
477
- return {
478
- text: undefined,
479
- json: jsonData,
480
- csv: undefined,
481
- image: undefined,
482
- pdf: undefined,
483
- size: content2.length,
484
- mimeType: responseMimeType || "application/json"
485
- };
486
- }
487
- if (detectedFormat === "csv") {
488
- const content2 = response.text || "";
489
- if (!content2) {
490
- throw new Error(`Failed to load CSV from ${url}`);
491
- }
492
- const csvData = this.parseCsvContent(content2);
493
- return {
494
- text: undefined,
495
- json: undefined,
496
- csv: csvData,
497
- image: undefined,
498
- pdf: undefined,
499
- size: content2.length,
500
- mimeType: responseMimeType || "text/csv"
501
- };
502
- }
503
- if (detectedFormat === "image") {
504
- if (!response.blob) {
505
- throw new Error(`Failed to load image from ${url}`);
506
- }
507
- const blob = response.blob;
508
- const mimeType2 = responseMimeType || (blob.type && blob.type !== "" ? blob.type : this.getImageMimeType(url));
509
- const imageData = await this.blobToBase64DataURL(blob, mimeType2);
510
- return {
511
- text: undefined,
512
- json: undefined,
513
- csv: undefined,
514
- image: imageData,
515
- pdf: undefined,
516
- size: blob.size,
517
- mimeType: mimeType2
518
- };
519
- }
520
- if (detectedFormat === "pdf") {
521
- if (!response.blob) {
522
- throw new Error(`Failed to load PDF from ${url}`);
523
- }
524
- const blob = response.blob;
525
- const mimeType2 = responseMimeType || "application/pdf";
526
- const pdfData = await this.blobToBase64DataURL(blob, mimeType2);
527
- return {
528
- text: undefined,
529
- json: undefined,
530
- csv: undefined,
531
- image: undefined,
532
- pdf: pdfData,
533
- size: blob.size,
534
- mimeType: mimeType2
535
- };
171
+ }
172
+ Workflow3.prototype.scalarMultiply = CreateWorkflow3(ScalarMultiplyTask);
173
+
174
+ // src/task/scalar/ScalarSubtractTask.ts
175
+ import { CreateWorkflow as CreateWorkflow4, Task as Task4, Workflow as Workflow4 } from "@workglow/task-graph";
176
+ var inputSchema4 = {
177
+ type: "object",
178
+ properties: {
179
+ a: {
180
+ type: "number",
181
+ title: "A",
182
+ description: "First number"
183
+ },
184
+ b: {
185
+ type: "number",
186
+ title: "B",
187
+ description: "Second number"
536
188
  }
537
- const content = response.text || "";
538
- if (!content) {
539
- throw new Error(`Failed to load content from ${url}`);
189
+ },
190
+ required: ["a", "b"],
191
+ additionalProperties: false
192
+ };
193
+ var outputSchema4 = {
194
+ type: "object",
195
+ properties: {
196
+ result: {
197
+ type: "number",
198
+ title: "Result",
199
+ description: "Difference (a - b)"
540
200
  }
541
- const mimeType = responseMimeType || (detectedFormat === "markdown" ? "text/markdown" : detectedFormat === "html" ? "text/html" : "text/plain");
542
- return {
543
- text: content,
544
- json: undefined,
545
- csv: undefined,
546
- image: undefined,
547
- pdf: undefined,
548
- size: content.length,
549
- mimeType
550
- };
201
+ },
202
+ required: ["result"],
203
+ additionalProperties: false
204
+ };
205
+
206
+ class ScalarSubtractTask extends Task4 {
207
+ static type = "ScalarSubtractTask";
208
+ static category = "Math";
209
+ static title = "Subtract";
210
+ static description = "Returns the difference of two numbers (a - b)";
211
+ static inputSchema() {
212
+ return inputSchema4;
551
213
  }
552
- detectResponseType(detectedFormat) {
553
- let responseType = "text";
554
- if (detectedFormat === "json") {
555
- responseType = "json";
556
- } else if (detectedFormat === "image" || detectedFormat === "pdf") {
557
- responseType = "blob";
558
- } else if (detectedFormat === "csv" || detectedFormat === "text" || detectedFormat === "markdown" || detectedFormat === "html") {
559
- responseType = "text";
560
- }
561
- return responseType;
214
+ static outputSchema() {
215
+ return outputSchema4;
562
216
  }
563
- detectFormat(url, format) {
564
- if (format === "auto") {
565
- const urlLower = url.toLowerCase();
566
- if (urlLower.endsWith(".md") || urlLower.endsWith(".markdown")) {
567
- return "markdown";
568
- } else if (urlLower.endsWith(".json")) {
569
- return "json";
570
- } else if (urlLower.endsWith(".csv")) {
571
- return "csv";
572
- } else if (urlLower.endsWith(".pdf")) {
573
- return "pdf";
574
- } else if (urlLower.match(/\.(jpg|jpeg|png|gif|bmp|webp|svg|ico)$/)) {
575
- return "image";
576
- } else if (urlLower.endsWith(".html") || urlLower.endsWith(".htm")) {
577
- return "html";
578
- } else {
579
- return "text";
580
- }
217
+ async execute(input, _context) {
218
+ return { result: input.a - input.b };
219
+ }
220
+ }
221
+ Workflow4.prototype.scalarSubtract = CreateWorkflow4(ScalarSubtractTask);
222
+
223
+ // src/task/scalar/ScalarSumTask.ts
224
+ import { CreateWorkflow as CreateWorkflow5, Task as Task5, Workflow as Workflow5 } from "@workglow/task-graph";
225
+ var inputSchema5 = {
226
+ type: "object",
227
+ properties: {
228
+ values: {
229
+ type: "array",
230
+ items: { type: "number" },
231
+ title: "Values",
232
+ description: "Array of numbers to sum"
581
233
  }
582
- return format;
234
+ },
235
+ required: ["values"],
236
+ additionalProperties: false
237
+ };
238
+ var outputSchema5 = {
239
+ type: "object",
240
+ properties: {
241
+ result: {
242
+ type: "number",
243
+ title: "Result",
244
+ description: "Sum of all values"
245
+ }
246
+ },
247
+ required: ["result"],
248
+ additionalProperties: false
249
+ };
250
+
251
+ class ScalarSumTask extends Task5 {
252
+ static type = "ScalarSumTask";
253
+ static category = "Math";
254
+ static title = "Sum";
255
+ static description = "Returns the sum of an array of numbers";
256
+ static inputSchema() {
257
+ return inputSchema5;
583
258
  }
584
- getImageMimeType(url) {
585
- const urlLower = url.toLowerCase();
586
- if (urlLower.endsWith(".png"))
587
- return "image/png";
588
- if (urlLower.endsWith(".jpg") || urlLower.endsWith(".jpeg"))
589
- return "image/jpeg";
590
- if (urlLower.endsWith(".gif"))
591
- return "image/gif";
592
- if (urlLower.endsWith(".webp"))
593
- return "image/webp";
594
- if (urlLower.endsWith(".bmp"))
595
- return "image/bmp";
596
- if (urlLower.endsWith(".svg"))
597
- return "image/svg+xml";
598
- if (urlLower.endsWith(".ico"))
599
- return "image/x-icon";
600
- return "image/jpeg";
259
+ static outputSchema() {
260
+ return outputSchema5;
601
261
  }
602
- async blobToBase64DataURL(blob, mimeType) {
603
- if (typeof Buffer !== "undefined") {
604
- const arrayBuffer = await blob.arrayBuffer();
605
- const buffer = Buffer.from(arrayBuffer);
606
- return `data:${mimeType};base64,${buffer.toString("base64")}`;
607
- }
608
- return new Promise((resolve, reject) => {
609
- const reader = new FileReader;
610
- reader.onloadend = () => {
611
- const result = reader.result;
612
- if (result.startsWith("data:;base64,")) {
613
- resolve(`data:${mimeType};base64,${result.substring(13)}`);
614
- } else {
615
- resolve(result);
616
- }
617
- };
618
- reader.onerror = reject;
619
- reader.readAsDataURL(blob);
620
- });
262
+ async execute(input, _context) {
263
+ return { result: sumPrecise(input.values) };
621
264
  }
622
265
  }
623
- Workflow2.prototype.fileLoader = CreateWorkflow2(FileLoaderTask);
266
+ Workflow5.prototype.scalarSum = CreateWorkflow5(ScalarSumTask);
624
267
 
625
- // src/task/FileLoaderTask.server.ts
626
- class FileLoaderTask2 extends FileLoaderTask {
627
- async execute(input, context) {
628
- let { url, format = "auto" } = input;
629
- if (url.startsWith("http://") || url.startsWith("https://")) {
630
- return super.execute(input, context);
268
+ // src/task/vector/VectorDivideTask.ts
269
+ import { CreateWorkflow as CreateWorkflow6, Task as Task6, Workflow as Workflow6 } from "@workglow/task-graph";
270
+ import {
271
+ createTypedArrayFrom,
272
+ TypedArraySchema
273
+ } from "@workglow/util";
274
+ var inputSchema6 = {
275
+ type: "object",
276
+ properties: {
277
+ vectors: {
278
+ type: "array",
279
+ items: TypedArraySchema({
280
+ title: "Vector",
281
+ description: "Vector (first is numerator, rest are denominators)"
282
+ }),
283
+ title: "Vectors",
284
+ description: "Array of vectors: vectors[0] / vectors[1] / vectors[2] / ..."
631
285
  }
632
- if (context.signal.aborted) {
633
- throw new TaskAbortedError2("Task aborted");
286
+ },
287
+ required: ["vectors"],
288
+ additionalProperties: false
289
+ };
290
+ var outputSchema6 = {
291
+ type: "object",
292
+ properties: {
293
+ result: TypedArraySchema({
294
+ title: "Result",
295
+ description: "Component-wise quotient"
296
+ })
297
+ },
298
+ required: ["result"],
299
+ additionalProperties: false
300
+ };
301
+
302
+ class VectorDivideTask extends Task6 {
303
+ static type = "VectorDivideTask";
304
+ static category = "Vector";
305
+ static title = "Divide";
306
+ static description = "Returns component-wise quotient: vectors[0] / vectors[1] / vectors[2] / ...";
307
+ static inputSchema() {
308
+ return inputSchema6;
309
+ }
310
+ static outputSchema() {
311
+ return outputSchema6;
312
+ }
313
+ async execute(input, _context) {
314
+ const { vectors } = input;
315
+ if (vectors.length < 2) {
316
+ throw new Error("At least two vectors are required");
634
317
  }
635
- await context.updateProgress(0, "Detecting file format");
636
- if (url.startsWith("file://")) {
637
- url = url.slice(7);
638
- }
639
- const detectedFormat = this.detectFormat(url, format);
640
- const title = url.split("/").pop() || url;
641
- if (context.signal.aborted) {
642
- throw new TaskAbortedError2("Task aborted");
643
- }
644
- await context.updateProgress(10, `Reading ${detectedFormat} file from filesystem`);
645
- if (detectedFormat === "json") {
646
- const fileContent2 = await readFile(url, { encoding: "utf-8" });
647
- if (context.signal.aborted) {
648
- throw new TaskAbortedError2("Task aborted");
649
- }
650
- await context.updateProgress(50, "Parsing JSON content");
651
- const jsonData = this.parseJsonContent(fileContent2);
652
- const content = JSON.stringify(jsonData, null, 2);
653
- if (context.signal.aborted) {
654
- throw new TaskAbortedError2("Task aborted");
655
- }
656
- await context.updateProgress(100, "File loaded successfully");
657
- return {
658
- text: undefined,
659
- json: jsonData,
660
- csv: undefined,
661
- image: undefined,
662
- pdf: undefined,
663
- metadata: {
664
- url,
665
- format: detectedFormat,
666
- size: content.length,
667
- title,
668
- mimeType: "application/json"
669
- }
670
- };
671
- }
672
- if (detectedFormat === "csv") {
673
- const fileContent2 = await readFile(url, { encoding: "utf-8" });
674
- if (!fileContent2) {
675
- throw new Error(`Failed to load CSV from ${url}`);
676
- }
677
- if (context.signal.aborted) {
678
- throw new TaskAbortedError2("Task aborted");
679
- }
680
- await context.updateProgress(50, "Parsing CSV content");
681
- const csvData = this.parseCsvContent(fileContent2);
682
- if (context.signal.aborted) {
683
- throw new TaskAbortedError2("Task aborted");
684
- }
685
- await context.updateProgress(100, "File loaded successfully");
686
- return {
687
- text: undefined,
688
- json: undefined,
689
- csv: csvData,
690
- image: undefined,
691
- pdf: undefined,
692
- metadata: {
693
- url,
694
- format: detectedFormat,
695
- size: fileContent2.length,
696
- title,
697
- mimeType: "text/csv"
698
- }
699
- };
700
- }
701
- if (detectedFormat === "image") {
702
- const fileBuffer = await readFile(url);
703
- if (context.signal.aborted) {
704
- throw new TaskAbortedError2("Task aborted");
705
- }
706
- await context.updateProgress(50, "Converting image to base64");
707
- const mimeType2 = this.getImageMimeType(url);
708
- const blob = new Blob([fileBuffer], { type: mimeType2 });
709
- const imageData = await this.blobToBase64DataURL(blob, mimeType2);
710
- if (context.signal.aborted) {
711
- throw new TaskAbortedError2("Task aborted");
712
- }
713
- await context.updateProgress(100, "File loaded successfully");
714
- return {
715
- text: undefined,
716
- json: undefined,
717
- csv: undefined,
718
- image: imageData,
719
- pdf: undefined,
720
- metadata: {
721
- url,
722
- format: detectedFormat,
723
- size: fileBuffer.length,
724
- title,
725
- mimeType: mimeType2
726
- }
727
- };
728
- }
729
- if (detectedFormat === "pdf") {
730
- const fileBuffer = await readFile(url);
731
- if (context.signal.aborted) {
732
- throw new TaskAbortedError2("Task aborted");
733
- }
734
- await context.updateProgress(50, "Converting PDF to base64");
735
- const mimeType2 = "application/pdf";
736
- const blob = new Blob([fileBuffer], { type: mimeType2 });
737
- const pdfData = await this.blobToBase64DataURL(blob, mimeType2);
738
- if (context.signal.aborted) {
739
- throw new TaskAbortedError2("Task aborted");
318
+ const len = vectors[0].length;
319
+ for (let i = 1;i < vectors.length; i++) {
320
+ if (vectors[i].length !== len) {
321
+ throw new Error("All vectors must have the same length");
740
322
  }
741
- await context.updateProgress(100, "File loaded successfully");
742
- return {
743
- text: undefined,
744
- json: undefined,
745
- csv: undefined,
746
- image: undefined,
747
- pdf: pdfData,
748
- metadata: {
749
- url,
750
- format: detectedFormat,
751
- size: fileBuffer.length,
752
- title,
753
- mimeType: mimeType2
754
- }
755
- };
756
- }
757
- const fileContent = await readFile(url, { encoding: "utf-8" });
758
- if (!fileContent) {
759
- throw new Error(`Failed to load content from ${url}`);
760
- }
761
- if (context.signal.aborted) {
762
- throw new TaskAbortedError2("Task aborted");
763
- }
764
- await context.updateProgress(50, `Parsing ${detectedFormat} content`);
765
- const mimeType = detectedFormat === "markdown" ? "text/markdown" : detectedFormat === "html" ? "text/html" : "text/plain";
766
- if (context.signal.aborted) {
767
- throw new TaskAbortedError2("Task aborted");
768
323
  }
769
- await context.updateProgress(100, "File loaded successfully");
770
- return {
771
- text: fileContent,
772
- json: undefined,
773
- csv: undefined,
774
- image: undefined,
775
- pdf: undefined,
776
- metadata: {
777
- url,
778
- format: detectedFormat,
779
- size: fileContent.length,
780
- title,
781
- mimeType
324
+ const values = Array.from({ length: len }, (_, i) => {
325
+ let acc = Number(vectors[0][i]);
326
+ for (let j = 1;j < vectors.length; j++) {
327
+ acc /= Number(vectors[j][i]);
782
328
  }
783
- };
784
- }
785
- }
786
- var fileLoader = (input, config) => {
787
- return new FileLoaderTask2({}, config).run(input);
788
- };
789
- Workflow3.prototype.fileLoader = CreateWorkflow3(FileLoaderTask2);
790
-
791
- // src/task/adaptive.ts
792
- import { CreateAdaptiveWorkflow, Workflow as Workflow13 } from "@workglow/task-graph";
793
-
794
- // src/task/scalar/ScalarAddTask.ts
795
- import { CreateWorkflow as CreateWorkflow4, Task as Task2, Workflow as Workflow4 } from "@workglow/task-graph";
796
-
797
- // src/task/scalar/sumPrecise.ts
798
- function kahanSum(values) {
799
- let sum = 0;
800
- let compensation = 0;
801
- for (const value of values) {
802
- const y = value - compensation;
803
- const t = sum + y;
804
- compensation = t - sum - y;
805
- sum = t;
329
+ return acc;
330
+ });
331
+ return { result: createTypedArrayFrom(vectors, values) };
806
332
  }
807
- return sum;
808
333
  }
809
- var nativeSumPrecise = typeof Math.sumPrecise === "function" ? Math.sumPrecise : undefined;
810
- var sumPrecise = nativeSumPrecise ? nativeSumPrecise.bind(Math) : kahanSum;
334
+ Workflow6.prototype.vectorDivide = CreateWorkflow6(VectorDivideTask);
811
335
 
812
- // src/task/scalar/ScalarAddTask.ts
813
- var inputSchema3 = {
336
+ // src/task/vector/VectorMultiplyTask.ts
337
+ import { CreateWorkflow as CreateWorkflow7, Task as Task7, Workflow as Workflow7 } from "@workglow/task-graph";
338
+ import {
339
+ createTypedArrayFrom as createTypedArrayFrom2,
340
+ TypedArraySchema as TypedArraySchema2
341
+ } from "@workglow/util";
342
+ var inputSchema7 = {
814
343
  type: "object",
815
344
  properties: {
816
- a: {
817
- type: "number",
818
- title: "A",
819
- description: "First number"
820
- },
821
- b: {
822
- type: "number",
823
- title: "B",
824
- description: "Second number"
345
+ vectors: {
346
+ type: "array",
347
+ items: TypedArraySchema2({
348
+ title: "Vector",
349
+ description: "Vector for component-wise product"
350
+ }),
351
+ title: "Vectors",
352
+ description: "Array of vectors to multiply component-wise"
825
353
  }
826
354
  },
827
- required: ["a", "b"],
355
+ required: ["vectors"],
828
356
  additionalProperties: false
829
357
  };
830
- var outputSchema3 = {
358
+ var outputSchema7 = {
831
359
  type: "object",
832
360
  properties: {
833
- result: {
834
- type: "number",
361
+ result: TypedArraySchema2({
835
362
  title: "Result",
836
- description: "Sum of a and b"
837
- }
363
+ description: "Component-wise product (Hadamard product)"
364
+ })
838
365
  },
839
366
  required: ["result"],
840
367
  additionalProperties: false
841
368
  };
842
369
 
843
- class ScalarAddTask extends Task2 {
844
- static type = "ScalarAddTask";
845
- static category = "Math";
846
- static title = "Add";
847
- static description = "Returns the sum of two numbers";
370
+ class VectorMultiplyTask extends Task7 {
371
+ static type = "VectorMultiplyTask";
372
+ static category = "Vector";
373
+ static title = "Multiply";
374
+ static description = "Returns the component-wise product (Hadamard product) of all vectors";
848
375
  static inputSchema() {
849
- return inputSchema3;
376
+ return inputSchema7;
850
377
  }
851
378
  static outputSchema() {
852
- return outputSchema3;
379
+ return outputSchema7;
853
380
  }
854
381
  async execute(input, _context) {
855
- return { result: sumPrecise([input.a, input.b]) };
382
+ const { vectors } = input;
383
+ if (vectors.length === 0) {
384
+ throw new Error("At least one vector is required");
385
+ }
386
+ const len = vectors[0].length;
387
+ for (let i = 1;i < vectors.length; i++) {
388
+ if (vectors[i].length !== len) {
389
+ throw new Error("All vectors must have the same length");
390
+ }
391
+ }
392
+ const values = Array.from({ length: len }, (_, i) => vectors.reduce((acc, v) => acc * Number(v[i]), 1));
393
+ return { result: createTypedArrayFrom2(vectors, values) };
856
394
  }
857
395
  }
858
- Workflow4.prototype.scalarAdd = CreateWorkflow4(ScalarAddTask);
396
+ Workflow7.prototype.vectorMultiply = CreateWorkflow7(VectorMultiplyTask);
859
397
 
860
- // src/task/scalar/ScalarDivideTask.ts
861
- import { CreateWorkflow as CreateWorkflow5, Task as Task3, Workflow as Workflow5 } from "@workglow/task-graph";
862
- var inputSchema4 = {
398
+ // src/task/vector/VectorSubtractTask.ts
399
+ import { CreateWorkflow as CreateWorkflow8, Task as Task8, Workflow as Workflow8 } from "@workglow/task-graph";
400
+ import {
401
+ createTypedArrayFrom as createTypedArrayFrom3,
402
+ TypedArraySchema as TypedArraySchema3
403
+ } from "@workglow/util";
404
+ var inputSchema8 = {
863
405
  type: "object",
864
406
  properties: {
865
- a: {
866
- type: "number",
867
- title: "A",
868
- description: "Numerator"
869
- },
870
- b: {
871
- type: "number",
872
- title: "B",
873
- description: "Denominator"
407
+ vectors: {
408
+ type: "array",
409
+ items: TypedArraySchema3({
410
+ title: "Vector",
411
+ description: "Vector (first is minuend, rest are subtrahends)"
412
+ }),
413
+ title: "Vectors",
414
+ description: "Array of vectors: vectors[0] - vectors[1] - vectors[2] - ..."
874
415
  }
875
416
  },
876
- required: ["a", "b"],
877
- additionalProperties: false
878
- };
879
- var outputSchema4 = {
880
- type: "object",
881
- properties: {
882
- result: {
883
- type: "number",
884
- title: "Result",
885
- description: "Quotient (a / b)"
886
- }
887
- },
888
- required: ["result"],
889
- additionalProperties: false
890
- };
891
-
892
- class ScalarDivideTask extends Task3 {
893
- static type = "ScalarDivideTask";
894
- static category = "Math";
895
- static title = "Divide";
896
- static description = "Returns the quotient of two numbers (a / b)";
897
- static inputSchema() {
898
- return inputSchema4;
899
- }
900
- static outputSchema() {
901
- return outputSchema4;
902
- }
903
- async execute(input, _context) {
904
- return { result: input.a / input.b };
905
- }
906
- }
907
- Workflow5.prototype.scalarDivide = CreateWorkflow5(ScalarDivideTask);
908
-
909
- // src/task/scalar/ScalarMultiplyTask.ts
910
- import { CreateWorkflow as CreateWorkflow6, Task as Task4, Workflow as Workflow6 } from "@workglow/task-graph";
911
- var inputSchema5 = {
912
- type: "object",
913
- properties: {
914
- a: {
915
- type: "number",
916
- title: "A",
917
- description: "First number"
918
- },
919
- b: {
920
- type: "number",
921
- title: "B",
922
- description: "Second number"
923
- }
924
- },
925
- required: ["a", "b"],
926
- additionalProperties: false
927
- };
928
- var outputSchema5 = {
929
- type: "object",
930
- properties: {
931
- result: {
932
- type: "number",
933
- title: "Result",
934
- description: "Product of a and b"
935
- }
936
- },
937
- required: ["result"],
938
- additionalProperties: false
939
- };
940
-
941
- class ScalarMultiplyTask extends Task4 {
942
- static type = "ScalarMultiplyTask";
943
- static category = "Math";
944
- static title = "Multiply";
945
- static description = "Returns the product of two numbers";
946
- static inputSchema() {
947
- return inputSchema5;
948
- }
949
- static outputSchema() {
950
- return outputSchema5;
951
- }
952
- async execute(input, _context) {
953
- return { result: input.a * input.b };
954
- }
955
- }
956
- Workflow6.prototype.scalarMultiply = CreateWorkflow6(ScalarMultiplyTask);
957
-
958
- // src/task/scalar/ScalarSubtractTask.ts
959
- import { CreateWorkflow as CreateWorkflow7, Task as Task5, Workflow as Workflow7 } from "@workglow/task-graph";
960
- var inputSchema6 = {
961
- type: "object",
962
- properties: {
963
- a: {
964
- type: "number",
965
- title: "A",
966
- description: "First number"
967
- },
968
- b: {
969
- type: "number",
970
- title: "B",
971
- description: "Second number"
972
- }
973
- },
974
- required: ["a", "b"],
975
- additionalProperties: false
976
- };
977
- var outputSchema6 = {
978
- type: "object",
979
- properties: {
980
- result: {
981
- type: "number",
982
- title: "Result",
983
- description: "Difference (a - b)"
984
- }
985
- },
986
- required: ["result"],
987
- additionalProperties: false
988
- };
989
-
990
- class ScalarSubtractTask extends Task5 {
991
- static type = "ScalarSubtractTask";
992
- static category = "Math";
993
- static title = "Subtract";
994
- static description = "Returns the difference of two numbers (a - b)";
995
- static inputSchema() {
996
- return inputSchema6;
997
- }
998
- static outputSchema() {
999
- return outputSchema6;
1000
- }
1001
- async execute(input, _context) {
1002
- return { result: input.a - input.b };
1003
- }
1004
- }
1005
- Workflow7.prototype.scalarSubtract = CreateWorkflow7(ScalarSubtractTask);
1006
-
1007
- // src/task/scalar/ScalarSumTask.ts
1008
- import { CreateWorkflow as CreateWorkflow8, Task as Task6, Workflow as Workflow8 } from "@workglow/task-graph";
1009
- var inputSchema7 = {
1010
- type: "object",
1011
- properties: {
1012
- values: {
1013
- type: "array",
1014
- items: { type: "number" },
1015
- title: "Values",
1016
- description: "Array of numbers to sum"
1017
- }
1018
- },
1019
- required: ["values"],
1020
- additionalProperties: false
1021
- };
1022
- var outputSchema7 = {
1023
- type: "object",
1024
- properties: {
1025
- result: {
1026
- type: "number",
1027
- title: "Result",
1028
- description: "Sum of all values"
1029
- }
1030
- },
1031
- required: ["result"],
1032
- additionalProperties: false
1033
- };
1034
-
1035
- class ScalarSumTask extends Task6 {
1036
- static type = "ScalarSumTask";
1037
- static category = "Math";
1038
- static title = "Sum";
1039
- static description = "Returns the sum of an array of numbers";
1040
- static inputSchema() {
1041
- return inputSchema7;
1042
- }
1043
- static outputSchema() {
1044
- return outputSchema7;
1045
- }
1046
- async execute(input, _context) {
1047
- return { result: sumPrecise(input.values) };
1048
- }
1049
- }
1050
- Workflow8.prototype.scalarSum = CreateWorkflow8(ScalarSumTask);
1051
-
1052
- // src/task/vector/VectorDivideTask.ts
1053
- import { CreateWorkflow as CreateWorkflow9, Task as Task7, Workflow as Workflow9 } from "@workglow/task-graph";
1054
- import {
1055
- createTypedArrayFrom,
1056
- TypedArraySchema
1057
- } from "@workglow/util";
1058
- var inputSchema8 = {
1059
- type: "object",
1060
- properties: {
1061
- vectors: {
1062
- type: "array",
1063
- items: TypedArraySchema({
1064
- title: "Vector",
1065
- description: "Vector (first is numerator, rest are denominators)"
1066
- }),
1067
- title: "Vectors",
1068
- description: "Array of vectors: vectors[0] / vectors[1] / vectors[2] / ..."
1069
- }
1070
- },
1071
- required: ["vectors"],
417
+ required: ["vectors"],
1072
418
  additionalProperties: false
1073
419
  };
1074
420
  var outputSchema8 = {
1075
421
  type: "object",
1076
422
  properties: {
1077
- result: TypedArraySchema({
423
+ result: TypedArraySchema3({
1078
424
  title: "Result",
1079
- description: "Component-wise quotient"
425
+ description: "Difference of vectors"
1080
426
  })
1081
427
  },
1082
428
  required: ["result"],
1083
429
  additionalProperties: false
1084
430
  };
1085
431
 
1086
- class VectorDivideTask extends Task7 {
1087
- static type = "VectorDivideTask";
432
+ class VectorSubtractTask extends Task8 {
433
+ static type = "VectorSubtractTask";
1088
434
  static category = "Vector";
1089
- static title = "Divide";
1090
- static description = "Returns component-wise quotient: vectors[0] / vectors[1] / vectors[2] / ...";
435
+ static title = "Subtract";
436
+ static description = "Returns component-wise difference: vectors[0] - vectors[1] - vectors[2] - ...";
1091
437
  static inputSchema() {
1092
438
  return inputSchema8;
1093
439
  }
@@ -1108,32 +454,32 @@ class VectorDivideTask extends Task7 {
1108
454
  const values = Array.from({ length: len }, (_, i) => {
1109
455
  let acc = Number(vectors[0][i]);
1110
456
  for (let j = 1;j < vectors.length; j++) {
1111
- acc /= Number(vectors[j][i]);
457
+ acc -= Number(vectors[j][i]);
1112
458
  }
1113
459
  return acc;
1114
460
  });
1115
- return { result: createTypedArrayFrom(vectors, values) };
461
+ return { result: createTypedArrayFrom3(vectors, values) };
1116
462
  }
1117
463
  }
1118
- Workflow9.prototype.vectorDivide = CreateWorkflow9(VectorDivideTask);
464
+ Workflow8.prototype.vectorSubtract = CreateWorkflow8(VectorSubtractTask);
1119
465
 
1120
- // src/task/vector/VectorMultiplyTask.ts
1121
- import { CreateWorkflow as CreateWorkflow10, Task as Task8, Workflow as Workflow10 } from "@workglow/task-graph";
466
+ // src/task/vector/VectorSumTask.ts
467
+ import { CreateWorkflow as CreateWorkflow9, Task as Task9, Workflow as Workflow9 } from "@workglow/task-graph";
1122
468
  import {
1123
- createTypedArrayFrom as createTypedArrayFrom2,
1124
- TypedArraySchema as TypedArraySchema2
469
+ createTypedArrayFrom as createTypedArrayFrom4,
470
+ TypedArraySchema as TypedArraySchema4
1125
471
  } from "@workglow/util";
1126
472
  var inputSchema9 = {
1127
473
  type: "object",
1128
474
  properties: {
1129
475
  vectors: {
1130
476
  type: "array",
1131
- items: TypedArraySchema2({
477
+ items: TypedArraySchema4({
1132
478
  title: "Vector",
1133
- description: "Vector for component-wise product"
479
+ description: "Vector to sum"
1134
480
  }),
1135
481
  title: "Vectors",
1136
- description: "Array of vectors to multiply component-wise"
482
+ description: "Array of vectors to sum component-wise"
1137
483
  }
1138
484
  },
1139
485
  required: ["vectors"],
@@ -1142,20 +488,20 @@ var inputSchema9 = {
1142
488
  var outputSchema9 = {
1143
489
  type: "object",
1144
490
  properties: {
1145
- result: TypedArraySchema2({
491
+ result: TypedArraySchema4({
1146
492
  title: "Result",
1147
- description: "Component-wise product (Hadamard product)"
493
+ description: "Sum of vectors"
1148
494
  })
1149
495
  },
1150
496
  required: ["result"],
1151
497
  additionalProperties: false
1152
498
  };
1153
499
 
1154
- class VectorMultiplyTask extends Task8 {
1155
- static type = "VectorMultiplyTask";
500
+ class VectorSumTask extends Task9 {
501
+ static type = "VectorSumTask";
1156
502
  static category = "Vector";
1157
- static title = "Multiply";
1158
- static description = "Returns the component-wise product (Hadamard product) of all vectors";
503
+ static title = "Sum";
504
+ static description = "Returns the component-wise sum of an array of vectors";
1159
505
  static inputSchema() {
1160
506
  return inputSchema9;
1161
507
  }
@@ -1173,160 +519,22 @@ class VectorMultiplyTask extends Task8 {
1173
519
  throw new Error("All vectors must have the same length");
1174
520
  }
1175
521
  }
1176
- const values = Array.from({ length: len }, (_, i) => vectors.reduce((acc, v) => acc * Number(v[i]), 1));
1177
- return { result: createTypedArrayFrom2(vectors, values) };
522
+ const values = Array.from({ length: len }, (_, i) => sumPrecise(vectors.map((v) => Number(v[i]))));
523
+ return { result: createTypedArrayFrom4(vectors, values) };
1178
524
  }
1179
525
  }
1180
- Workflow10.prototype.vectorMultiply = CreateWorkflow10(VectorMultiplyTask);
526
+ Workflow9.prototype.vectorSum = CreateWorkflow9(VectorSumTask);
1181
527
 
1182
- // src/task/vector/VectorSubtractTask.ts
1183
- import { CreateWorkflow as CreateWorkflow11, Task as Task9, Workflow as Workflow11 } from "@workglow/task-graph";
528
+ // src/task/adaptive.ts
529
+ Workflow10.prototype.add = CreateAdaptiveWorkflow(ScalarAddTask, VectorSumTask);
530
+ Workflow10.prototype.subtract = CreateAdaptiveWorkflow(ScalarSubtractTask, VectorSubtractTask);
531
+ Workflow10.prototype.multiply = CreateAdaptiveWorkflow(ScalarMultiplyTask, VectorMultiplyTask);
532
+ Workflow10.prototype.divide = CreateAdaptiveWorkflow(ScalarDivideTask, VectorDivideTask);
533
+ Workflow10.prototype.sum = CreateAdaptiveWorkflow(ScalarSumTask, VectorSumTask);
534
+
535
+ // src/task/ArrayTask.ts
1184
536
  import {
1185
- createTypedArrayFrom as createTypedArrayFrom3,
1186
- TypedArraySchema as TypedArraySchema3
1187
- } from "@workglow/util";
1188
- var inputSchema10 = {
1189
- type: "object",
1190
- properties: {
1191
- vectors: {
1192
- type: "array",
1193
- items: TypedArraySchema3({
1194
- title: "Vector",
1195
- description: "Vector (first is minuend, rest are subtrahends)"
1196
- }),
1197
- title: "Vectors",
1198
- description: "Array of vectors: vectors[0] - vectors[1] - vectors[2] - ..."
1199
- }
1200
- },
1201
- required: ["vectors"],
1202
- additionalProperties: false
1203
- };
1204
- var outputSchema10 = {
1205
- type: "object",
1206
- properties: {
1207
- result: TypedArraySchema3({
1208
- title: "Result",
1209
- description: "Difference of vectors"
1210
- })
1211
- },
1212
- required: ["result"],
1213
- additionalProperties: false
1214
- };
1215
-
1216
- class VectorSubtractTask extends Task9 {
1217
- static type = "VectorSubtractTask";
1218
- static category = "Vector";
1219
- static title = "Subtract";
1220
- static description = "Returns component-wise difference: vectors[0] - vectors[1] - vectors[2] - ...";
1221
- static inputSchema() {
1222
- return inputSchema10;
1223
- }
1224
- static outputSchema() {
1225
- return outputSchema10;
1226
- }
1227
- async execute(input, _context) {
1228
- const { vectors } = input;
1229
- if (vectors.length < 2) {
1230
- throw new Error("At least two vectors are required");
1231
- }
1232
- const len = vectors[0].length;
1233
- for (let i = 1;i < vectors.length; i++) {
1234
- if (vectors[i].length !== len) {
1235
- throw new Error("All vectors must have the same length");
1236
- }
1237
- }
1238
- const values = Array.from({ length: len }, (_, i) => {
1239
- let acc = Number(vectors[0][i]);
1240
- for (let j = 1;j < vectors.length; j++) {
1241
- acc -= Number(vectors[j][i]);
1242
- }
1243
- return acc;
1244
- });
1245
- return { result: createTypedArrayFrom3(vectors, values) };
1246
- }
1247
- }
1248
- Workflow11.prototype.vectorSubtract = CreateWorkflow11(VectorSubtractTask);
1249
-
1250
- // src/task/vector/VectorSumTask.ts
1251
- import { CreateWorkflow as CreateWorkflow12, Task as Task10, Workflow as Workflow12 } from "@workglow/task-graph";
1252
- import {
1253
- createTypedArrayFrom as createTypedArrayFrom4,
1254
- TypedArraySchema as TypedArraySchema4
1255
- } from "@workglow/util";
1256
- var inputSchema11 = {
1257
- type: "object",
1258
- properties: {
1259
- vectors: {
1260
- type: "array",
1261
- items: TypedArraySchema4({
1262
- title: "Vector",
1263
- description: "Vector to sum"
1264
- }),
1265
- title: "Vectors",
1266
- description: "Array of vectors to sum component-wise"
1267
- }
1268
- },
1269
- required: ["vectors"],
1270
- additionalProperties: false
1271
- };
1272
- var outputSchema11 = {
1273
- type: "object",
1274
- properties: {
1275
- result: TypedArraySchema4({
1276
- title: "Result",
1277
- description: "Sum of vectors"
1278
- })
1279
- },
1280
- required: ["result"],
1281
- additionalProperties: false
1282
- };
1283
-
1284
- class VectorSumTask extends Task10 {
1285
- static type = "VectorSumTask";
1286
- static category = "Vector";
1287
- static title = "Sum";
1288
- static description = "Returns the component-wise sum of an array of vectors";
1289
- static inputSchema() {
1290
- return inputSchema11;
1291
- }
1292
- static outputSchema() {
1293
- return outputSchema11;
1294
- }
1295
- async execute(input, _context) {
1296
- const { vectors } = input;
1297
- if (vectors.length === 0) {
1298
- throw new Error("At least one vector is required");
1299
- }
1300
- const len = vectors[0].length;
1301
- for (let i = 1;i < vectors.length; i++) {
1302
- if (vectors[i].length !== len) {
1303
- throw new Error("All vectors must have the same length");
1304
- }
1305
- }
1306
- const values = Array.from({ length: len }, (_, i) => sumPrecise(vectors.map((v) => Number(v[i]))));
1307
- return { result: createTypedArrayFrom4(vectors, values) };
1308
- }
1309
- }
1310
- Workflow12.prototype.vectorSum = CreateWorkflow12(VectorSumTask);
1311
-
1312
- // src/task/adaptive.ts
1313
- Workflow13.prototype.add = CreateAdaptiveWorkflow(ScalarAddTask, VectorSumTask);
1314
- Workflow13.prototype.subtract = CreateAdaptiveWorkflow(ScalarSubtractTask, VectorSubtractTask);
1315
- Workflow13.prototype.multiply = CreateAdaptiveWorkflow(ScalarMultiplyTask, VectorMultiplyTask);
1316
- Workflow13.prototype.divide = CreateAdaptiveWorkflow(ScalarDivideTask, VectorDivideTask);
1317
- Workflow13.prototype.sum = CreateAdaptiveWorkflow(ScalarSumTask, VectorSumTask);
1318
-
1319
- // src/common.ts
1320
- import {
1321
- createMcpClient,
1322
- mcpClientFactory as mcpClientFactory5,
1323
- mcpServerConfigSchema as mcpServerConfigSchema5,
1324
- mcpTransportTypes
1325
- } from "@workglow/util";
1326
-
1327
- // src/task/ArrayTask.ts
1328
- import {
1329
- uuid4
537
+ uuid4
1330
538
  } from "@workglow/util";
1331
539
  import {
1332
540
  GraphAsTask,
@@ -1358,12 +566,12 @@ class ArrayTask extends GraphAsTask {
1358
566
  regenerateGraph() {
1359
567
  const arrayInputs = new Map;
1360
568
  let hasArrayInputs = false;
1361
- const inputSchema12 = this.inputSchema();
1362
- if (typeof inputSchema12 !== "boolean") {
1363
- const keys = Object.keys(inputSchema12.properties || {});
569
+ const inputSchema10 = this.inputSchema();
570
+ if (typeof inputSchema10 !== "boolean") {
571
+ const keys = Object.keys(inputSchema10.properties || {});
1364
572
  for (const inputId of keys) {
1365
573
  const inputValue = this.runInputData[inputId];
1366
- const inputDef = inputSchema12.properties?.[inputId];
574
+ const inputDef = inputSchema10.properties?.[inputId];
1367
575
  if (typeof inputDef === "object" && inputDef !== null && "x-replicate" in inputDef && inputDef["x-replicate"] === true && Array.isArray(inputValue) && inputValue.length > 1) {
1368
576
  arrayInputs.set(inputId, inputValue);
1369
577
  hasArrayInputs = true;
@@ -1452,7 +660,7 @@ class ArrayTaskRunner extends GraphAsTaskRunner {
1452
660
  }
1453
661
  }
1454
662
  // src/task/DebugLogTask.ts
1455
- import { CreateWorkflow as CreateWorkflow13, Task as Task11, TaskConfigSchema, Workflow as Workflow14 } from "@workglow/task-graph";
663
+ import { CreateWorkflow as CreateWorkflow10, Task as Task10, TaskConfigSchema, Workflow as Workflow11 } from "@workglow/task-graph";
1456
664
  var log_levels = ["dir", "log", "debug", "info", "warn", "error"];
1457
665
  var DEFAULT_LOG_LEVEL = "log";
1458
666
  var debugLogTaskConfigSchema = {
@@ -1469,32 +677,33 @@ var debugLogTaskConfigSchema = {
1469
677
  },
1470
678
  additionalProperties: false
1471
679
  };
1472
- var inputSchema12 = {
680
+ var inputSchema10 = {
1473
681
  type: "object",
1474
682
  properties: {},
1475
683
  additionalProperties: true
1476
684
  };
1477
- var outputSchema12 = {
685
+ var outputSchema10 = {
1478
686
  type: "object",
1479
687
  properties: {},
1480
688
  additionalProperties: true
1481
689
  };
1482
690
 
1483
- class DebugLogTask extends Task11 {
691
+ class DebugLogTask extends Task10 {
1484
692
  static type = "DebugLogTask";
1485
693
  static category = "Utility";
1486
694
  static title = "Debug Log";
1487
695
  static description = "Logs messages to the console with configurable log levels for debugging task graphs";
1488
696
  static cacheable = false;
1489
697
  static passthroughInputsToOutputs = true;
698
+ static customizable = true;
1490
699
  static configSchema() {
1491
700
  return debugLogTaskConfigSchema;
1492
701
  }
1493
702
  static inputSchema() {
1494
- return inputSchema12;
703
+ return inputSchema10;
1495
704
  }
1496
705
  static outputSchema() {
1497
- return outputSchema12;
706
+ return outputSchema10;
1498
707
  }
1499
708
  async executeReactive(input, output) {
1500
709
  const log_level = this.config.log_level ?? DEFAULT_LOG_LEVEL;
@@ -1512,14 +721,14 @@ var debugLog = (input, config = {}) => {
1512
721
  const task = new DebugLogTask({}, config);
1513
722
  return task.run(input);
1514
723
  };
1515
- Workflow14.prototype.debugLog = CreateWorkflow13(DebugLogTask);
724
+ Workflow11.prototype.debugLog = CreateWorkflow10(DebugLogTask);
1516
725
  // src/task/DelayTask.ts
1517
726
  import {
1518
- CreateWorkflow as CreateWorkflow14,
1519
- Task as Task12,
1520
- TaskAbortedError as TaskAbortedError3,
727
+ CreateWorkflow as CreateWorkflow11,
728
+ Task as Task11,
729
+ TaskAbortedError,
1521
730
  TaskConfigSchema as TaskConfigSchema2,
1522
- Workflow as Workflow15
731
+ Workflow as Workflow12
1523
732
  } from "@workglow/task-graph";
1524
733
  import { sleep } from "@workglow/util";
1525
734
  var delayTaskConfigSchema = {
@@ -1534,32 +743,33 @@ var delayTaskConfigSchema = {
1534
743
  },
1535
744
  additionalProperties: false
1536
745
  };
1537
- var inputSchema13 = {
746
+ var inputSchema11 = {
1538
747
  type: "object",
1539
748
  properties: {},
1540
749
  additionalProperties: true
1541
750
  };
1542
- var outputSchema13 = {
751
+ var outputSchema11 = {
1543
752
  type: "object",
1544
753
  properties: {},
1545
754
  additionalProperties: true
1546
755
  };
1547
756
 
1548
- class DelayTask extends Task12 {
757
+ class DelayTask extends Task11 {
1549
758
  static type = "DelayTask";
1550
759
  static category = "Utility";
1551
760
  static title = "Delay";
1552
761
  static description = "Delays execution for a specified duration with progress tracking";
1553
762
  static cacheable = false;
1554
763
  static passthroughInputsToOutputs = true;
764
+ static customizable = true;
1555
765
  static configSchema() {
1556
766
  return delayTaskConfigSchema;
1557
767
  }
1558
768
  static inputSchema() {
1559
- return inputSchema13;
769
+ return inputSchema11;
1560
770
  }
1561
771
  static outputSchema() {
1562
- return outputSchema13;
772
+ return outputSchema11;
1563
773
  }
1564
774
  async execute(input, executeContext) {
1565
775
  const delay = this.config.delay ?? 1;
@@ -1568,7 +778,7 @@ class DelayTask extends Task12 {
1568
778
  const chunkSize = delay / iterations;
1569
779
  for (let i = 0;i < iterations; i++) {
1570
780
  if (executeContext.signal.aborted) {
1571
- throw new TaskAbortedError3("Task aborted");
781
+ throw new TaskAbortedError("Task aborted");
1572
782
  }
1573
783
  await sleep(chunkSize);
1574
784
  await executeContext.updateProgress(100 * i / iterations, `Delaying for ${delay}ms`);
@@ -1583,49 +793,360 @@ var delay = (input, config = { delay: 1 }) => {
1583
793
  const task = new DelayTask({}, config);
1584
794
  return task.run(input);
1585
795
  };
1586
- Workflow15.prototype.delay = CreateWorkflow14(DelayTask);
1587
- // src/task/InputTask.ts
1588
- import { CreateWorkflow as CreateWorkflow15, Task as Task13, Workflow as Workflow16 } from "@workglow/task-graph";
1589
-
1590
- class InputTask extends Task13 {
1591
- static type = "InputTask";
1592
- static category = "Flow Control";
1593
- static title = "Input";
1594
- static description = "Starts the workflow";
1595
- static hasDynamicSchemas = true;
1596
- static cacheable = false;
1597
- static inputSchema() {
1598
- return {
796
+ Workflow12.prototype.delay = CreateWorkflow11(DelayTask);
797
+ // src/task/FetchUrlTask.ts
798
+ import {
799
+ AbortSignalJobError,
800
+ Job,
801
+ PermanentJobError,
802
+ RetryableJobError
803
+ } from "@workglow/job-queue";
804
+ import {
805
+ CreateWorkflow as CreateWorkflow12,
806
+ JobQueueTask,
807
+ TaskConfigurationError,
808
+ TaskInvalidInputError,
809
+ Workflow as Workflow13
810
+ } from "@workglow/task-graph";
811
+ var inputSchema12 = {
812
+ type: "object",
813
+ properties: {
814
+ url: {
815
+ type: "string",
816
+ title: "URL",
817
+ description: "The URL to fetch from",
818
+ format: "uri"
819
+ },
820
+ method: {
821
+ enum: ["GET", "POST", "PUT", "DELETE", "PATCH"],
822
+ title: "Method",
823
+ description: "The HTTP method to use",
824
+ default: "GET"
825
+ },
826
+ headers: {
1599
827
  type: "object",
1600
- properties: {},
1601
- additionalProperties: true
1602
- };
1603
- }
1604
- static outputSchema() {
1605
- return {
828
+ additionalProperties: {
829
+ type: "string"
830
+ },
831
+ title: "Headers",
832
+ description: "The headers to send with the request"
833
+ },
834
+ body: {
835
+ type: "string",
836
+ title: "Body",
837
+ description: "The body of the request"
838
+ },
839
+ response_type: {
840
+ anyOf: [{ type: "null" }, { enum: ["json", "text", "blob", "arraybuffer"] }],
841
+ title: "Response Type",
842
+ description: "The forced type of response to return. If null, the response type is inferred from the Content-Type header.",
843
+ default: null
844
+ },
845
+ timeout: {
846
+ type: "number",
847
+ title: "Timeout",
848
+ description: "Request timeout in milliseconds"
849
+ },
850
+ queue: {
851
+ oneOf: [{ type: "boolean" }, { type: "string" }],
852
+ description: "Queue handling: false=run inline, true=use default, string=explicit queue name",
853
+ default: true,
854
+ "x-ui-hidden": true
855
+ }
856
+ },
857
+ required: ["url"],
858
+ additionalProperties: false
859
+ };
860
+ var outputSchema12 = {
861
+ type: "object",
862
+ properties: {
863
+ json: {
864
+ title: "JSON",
865
+ description: "The JSON response"
866
+ },
867
+ text: {
868
+ type: "string",
869
+ title: "Text",
870
+ description: "The text response"
871
+ },
872
+ blob: {
873
+ title: "Blob",
874
+ description: "The blob response"
875
+ },
876
+ arraybuffer: {
877
+ title: "ArrayBuffer",
878
+ description: "The arraybuffer response"
879
+ },
880
+ metadata: {
1606
881
  type: "object",
1607
- properties: {},
1608
- additionalProperties: true
1609
- };
1610
- }
1611
- inputSchema() {
1612
- return this.config?.inputSchema ?? this.constructor.inputSchema();
1613
- }
1614
- outputSchema() {
1615
- return this.config?.outputSchema ?? this.constructor.outputSchema();
1616
- }
1617
- async execute(input) {
1618
- return input;
882
+ properties: {
883
+ contentType: { type: "string" },
884
+ headers: { type: "object", additionalProperties: { type: "string" } }
885
+ },
886
+ additionalProperties: false,
887
+ title: "Response Metadata",
888
+ description: "HTTP response metadata including content type and headers"
889
+ }
890
+ },
891
+ additionalProperties: false
892
+ };
893
+ async function fetchWithProgress(url, options = {}, onProgress) {
894
+ if (!options.signal) {
895
+ throw new TaskConfigurationError("An AbortSignal must be provided.");
1619
896
  }
1620
- async executeReactive(input) {
1621
- return input;
897
+ const response = await globalThis.fetch(url, options);
898
+ if (!response.body) {
899
+ throw new Error("ReadableStream not supported in this environment.");
1622
900
  }
1623
- async* executeStream(input, context) {
1624
- if (context.inputStreams) {
1625
- for (const [, stream] of context.inputStreams) {
1626
- const reader = stream.getReader();
1627
- try {
1628
- while (true) {
901
+ const contentLength = response.headers.get("Content-Length");
902
+ const totalBytes = contentLength ? parseInt(contentLength, 10) : 0;
903
+ let receivedBytes = 0;
904
+ const reader = response.body.getReader();
905
+ const stream = new ReadableStream({
906
+ start(controller) {
907
+ async function push() {
908
+ try {
909
+ while (true) {
910
+ if (options.signal?.aborted) {
911
+ controller.error(new AbortSignalJobError("Fetch aborted"));
912
+ reader.cancel();
913
+ return;
914
+ }
915
+ const { done, value } = await reader.read();
916
+ if (done) {
917
+ controller.close();
918
+ break;
919
+ }
920
+ controller.enqueue(value);
921
+ receivedBytes += value.length;
922
+ if (onProgress && totalBytes) {
923
+ await onProgress(receivedBytes / totalBytes * 100);
924
+ }
925
+ }
926
+ } catch (error) {
927
+ controller.error(error);
928
+ }
929
+ }
930
+ push();
931
+ },
932
+ cancel() {
933
+ reader.cancel();
934
+ }
935
+ });
936
+ return new Response(stream, {
937
+ headers: response.headers,
938
+ status: response.status,
939
+ statusText: response.statusText
940
+ });
941
+ }
942
+
943
+ class FetchUrlJob extends Job {
944
+ constructor(config = { input: {} }) {
945
+ super(config);
946
+ }
947
+ static type = "FetchUrlJob";
948
+ async execute(input, context) {
949
+ const response = await fetchWithProgress(input.url, {
950
+ method: input.method,
951
+ headers: input.headers,
952
+ body: input.body,
953
+ signal: context.signal
954
+ }, async (progress) => await context.updateProgress(progress));
955
+ if (response.ok) {
956
+ const contentType = response.headers.get("content-type") ?? "";
957
+ const headers = {};
958
+ response.headers.forEach((value, key) => {
959
+ headers[key] = value;
960
+ });
961
+ const metadata = {
962
+ contentType,
963
+ headers
964
+ };
965
+ let responseType = input.response_type;
966
+ if (!responseType) {
967
+ if (contentType.includes("application/json")) {
968
+ responseType = "json";
969
+ } else if (contentType.includes("text/")) {
970
+ responseType = "text";
971
+ } else if (contentType.includes("application/octet-stream")) {
972
+ responseType = "arraybuffer";
973
+ } else if (contentType.includes("application/pdf") || contentType.includes("image/") || contentType.includes("application/zip")) {
974
+ responseType = "blob";
975
+ } else {
976
+ responseType = "json";
977
+ }
978
+ input.response_type = responseType;
979
+ }
980
+ if (responseType === "json") {
981
+ return { json: await response.json(), metadata };
982
+ } else if (responseType === "text") {
983
+ return { text: await response.text(), metadata };
984
+ } else if (responseType === "blob") {
985
+ return { blob: await response.blob(), metadata };
986
+ } else if (responseType === "arraybuffer") {
987
+ return { arraybuffer: await response.arrayBuffer(), metadata };
988
+ }
989
+ throw new TaskInvalidInputError(`Invalid response type: ${responseType}`);
990
+ } else {
991
+ if (response.status === 429 || response.status === 503 || response.headers.get("Retry-After")) {
992
+ let retryDate;
993
+ const retryAfterStr = response.headers.get("Retry-After");
994
+ if (retryAfterStr) {
995
+ const parsedDate = new Date(retryAfterStr);
996
+ if (!isNaN(parsedDate.getTime()) && parsedDate > new Date) {
997
+ retryDate = parsedDate;
998
+ } else {
999
+ const retryAfterSeconds = parseInt(retryAfterStr) * 1000;
1000
+ if (!isNaN(retryAfterSeconds)) {
1001
+ retryDate = new Date(Date.now() + retryAfterSeconds);
1002
+ }
1003
+ }
1004
+ }
1005
+ throw new RetryableJobError(`Failed to fetch ${input.url}: ${response.status} ${response.statusText}`, retryDate);
1006
+ } else {
1007
+ throw new PermanentJobError(`Failed to fetch ${input.url}: ${response.status} ${response.statusText}`);
1008
+ }
1009
+ }
1010
+ }
1011
+ }
1012
+
1013
+ class FetchUrlTask extends JobQueueTask {
1014
+ static type = "FetchUrlTask";
1015
+ static category = "Input";
1016
+ static title = "Fetch";
1017
+ static description = "Fetches data from a URL with progress tracking and automatic retry handling";
1018
+ static hasDynamicSchemas = true;
1019
+ static inputSchema() {
1020
+ return inputSchema12;
1021
+ }
1022
+ static outputSchema() {
1023
+ return outputSchema12;
1024
+ }
1025
+ outputSchema() {
1026
+ const responseType = this.runInputData?.response_type ?? this.defaults?.response_type ?? null;
1027
+ if (responseType === null || responseType === undefined) {
1028
+ return this.constructor.outputSchema();
1029
+ }
1030
+ const staticSchema = this.constructor.outputSchema();
1031
+ if (typeof staticSchema === "boolean") {
1032
+ return staticSchema;
1033
+ }
1034
+ if (!staticSchema.properties) {
1035
+ return staticSchema;
1036
+ }
1037
+ const properties = {};
1038
+ if (responseType === "json" && staticSchema.properties.json) {
1039
+ properties.json = staticSchema.properties.json;
1040
+ } else if (responseType === "text" && staticSchema.properties.text) {
1041
+ properties.text = staticSchema.properties.text;
1042
+ } else if (responseType === "blob" && staticSchema.properties.blob) {
1043
+ properties.blob = staticSchema.properties.blob;
1044
+ } else if (responseType === "arraybuffer" && staticSchema.properties.arraybuffer) {
1045
+ properties.arraybuffer = staticSchema.properties.arraybuffer;
1046
+ }
1047
+ if (staticSchema.properties.metadata) {
1048
+ properties.metadata = staticSchema.properties.metadata;
1049
+ }
1050
+ if (Object.keys(properties).length === 0) {
1051
+ return staticSchema;
1052
+ }
1053
+ return {
1054
+ type: "object",
1055
+ properties,
1056
+ additionalProperties: false
1057
+ };
1058
+ }
1059
+ constructor(input = {}, config = {}) {
1060
+ config.queue = input?.queue ?? config.queue;
1061
+ if (config.queue === undefined) {
1062
+ config.queue = false;
1063
+ }
1064
+ super(input, config);
1065
+ this.jobClass = FetchUrlJob;
1066
+ }
1067
+ setInput(input) {
1068
+ if (!("response_type" in input)) {
1069
+ super.setInput(input);
1070
+ return;
1071
+ }
1072
+ const getCurrentResponseType = () => {
1073
+ return this.runInputData?.response_type ?? this.defaults?.response_type ?? null;
1074
+ };
1075
+ const previousResponseType = getCurrentResponseType();
1076
+ super.setInput(input);
1077
+ const newResponseType = getCurrentResponseType();
1078
+ if (previousResponseType !== newResponseType) {
1079
+ this.emitSchemaChange();
1080
+ }
1081
+ }
1082
+ async getDefaultQueueName(input) {
1083
+ if (!input.url) {
1084
+ return `fetch:${this.type}`;
1085
+ }
1086
+ try {
1087
+ const hostname = new URL(input.url).hostname.toLowerCase();
1088
+ const parts = hostname.split(".").filter(Boolean);
1089
+ if (parts.length === 0) {
1090
+ return `fetch:${this.type}`;
1091
+ }
1092
+ const domain = parts.length <= 2 ? parts.join(".") : parts.slice(-2).join(".");
1093
+ return `fetch:${domain}`;
1094
+ } catch {
1095
+ return `fetch:${this.type}`;
1096
+ }
1097
+ }
1098
+ }
1099
+ var fetchUrl = async (input, config = {}) => {
1100
+ const result = await new FetchUrlTask({}, config).run(input);
1101
+ return result;
1102
+ };
1103
+ Workflow13.prototype.fetch = CreateWorkflow12(FetchUrlTask);
1104
+ // src/task/InputTask.ts
1105
+ import {
1106
+ CreateWorkflow as CreateWorkflow13,
1107
+ Task as Task12,
1108
+ Workflow as Workflow14
1109
+ } from "@workglow/task-graph";
1110
+
1111
+ class InputTask extends Task12 {
1112
+ static type = "InputTask";
1113
+ static category = "Flow Control";
1114
+ static title = "Input";
1115
+ static description = "Starts the workflow";
1116
+ static hasDynamicSchemas = true;
1117
+ static cacheable = false;
1118
+ static inputSchema() {
1119
+ return {
1120
+ type: "object",
1121
+ properties: {},
1122
+ additionalProperties: true
1123
+ };
1124
+ }
1125
+ static outputSchema() {
1126
+ return {
1127
+ type: "object",
1128
+ properties: {},
1129
+ additionalProperties: true
1130
+ };
1131
+ }
1132
+ inputSchema() {
1133
+ return this.config?.inputSchema ?? this.constructor.inputSchema();
1134
+ }
1135
+ outputSchema() {
1136
+ return this.config?.outputSchema ?? this.constructor.outputSchema();
1137
+ }
1138
+ async execute(input) {
1139
+ return input;
1140
+ }
1141
+ async executeReactive(input) {
1142
+ return input;
1143
+ }
1144
+ async* executeStream(input, context) {
1145
+ if (context.inputStreams) {
1146
+ for (const [, stream] of context.inputStreams) {
1147
+ const reader = stream.getReader();
1148
+ try {
1149
+ while (true) {
1629
1150
  const { done, value } = await reader.read();
1630
1151
  if (done)
1631
1152
  break;
@@ -1641,9 +1162,9 @@ class InputTask extends Task13 {
1641
1162
  yield { type: "finish", data: input };
1642
1163
  }
1643
1164
  }
1644
- Workflow16.prototype.input = CreateWorkflow15(InputTask);
1165
+ Workflow14.prototype.input = CreateWorkflow13(InputTask);
1645
1166
  // src/task/JavaScriptTask.ts
1646
- import { CreateWorkflow as CreateWorkflow16, Task as Task14, Workflow as Workflow17 } from "@workglow/task-graph";
1167
+ import { CreateWorkflow as CreateWorkflow14, Task as Task13, TaskConfigSchema as TaskConfigSchema3, Workflow as Workflow15 } from "@workglow/task-graph";
1647
1168
 
1648
1169
  // src/util/acorn.js
1649
1170
  var options;
@@ -6106,9 +5627,10 @@ Interpreter["VALUE_IN_DESCRIPTOR"] = Interpreter.VALUE_IN_DESCRIPTOR;
6106
5627
  Interpreter["Status"] = Interpreter.Status;
6107
5628
 
6108
5629
  // src/task/JavaScriptTask.ts
6109
- var inputSchema14 = {
5630
+ var configSchema = {
6110
5631
  type: "object",
6111
5632
  properties: {
5633
+ ...TaskConfigSchema3["properties"],
6112
5634
  javascript_code: {
6113
5635
  type: "string",
6114
5636
  title: "Code",
@@ -6117,34 +5639,67 @@ var inputSchema14 = {
6117
5639
  format: "code:javascript"
6118
5640
  }
6119
5641
  },
6120
- required: ["javascript_code"],
6121
- additionalProperties: true
5642
+ additionalProperties: false
6122
5643
  };
6123
- var outputSchema14 = {
5644
+ var inputSchema13 = {
6124
5645
  type: "object",
6125
5646
  properties: {
6126
- output: {
6127
- title: "Output",
6128
- description: "The output of the JavaScript code"
6129
- }
5647
+ javascript_code: {
5648
+ type: "string",
5649
+ title: "Code",
5650
+ minLength: 1,
5651
+ description: "JavaScript code to execute",
5652
+ format: "code:javascript"
5653
+ }
5654
+ },
5655
+ required: ["javascript_code"],
5656
+ additionalProperties: true
5657
+ };
5658
+ var outputSchema13 = {
5659
+ type: "object",
5660
+ properties: {
5661
+ output: {
5662
+ title: "Output",
5663
+ description: "The output of the JavaScript code"
5664
+ }
6130
5665
  },
6131
5666
  required: ["output"],
6132
5667
  additionalProperties: false
6133
5668
  };
6134
5669
 
6135
- class JavaScriptTask extends Task14 {
5670
+ class JavaScriptTask extends Task13 {
6136
5671
  static type = "JavaScriptTask";
6137
5672
  static category = "Utility";
6138
5673
  static title = "JavaScript Interpreter";
6139
5674
  static description = "Executes JavaScript code in a sandboxed interpreter environment";
5675
+ static customizable = true;
5676
+ static configSchema() {
5677
+ return configSchema;
5678
+ }
6140
5679
  static inputSchema() {
6141
- return inputSchema14;
5680
+ return inputSchema13;
6142
5681
  }
6143
5682
  static outputSchema() {
6144
- return outputSchema14;
5683
+ return outputSchema13;
5684
+ }
5685
+ constructor(input2 = {}, config = {}) {
5686
+ super(input2, config);
5687
+ }
5688
+ inputSchema() {
5689
+ if (this.config?.javascript_code) {
5690
+ if (this.config.inputSchema) {
5691
+ return this.config.inputSchema;
5692
+ }
5693
+ return {
5694
+ type: "object",
5695
+ properties: {},
5696
+ additionalProperties: true
5697
+ };
5698
+ }
5699
+ return inputSchema13;
6145
5700
  }
6146
5701
  async executeReactive(input2, output) {
6147
- if (input2.javascript_code) {
5702
+ if (this.config.javascript_code || input2.javascript_code) {
6148
5703
  try {
6149
5704
  const inputVariables = Object.keys(input2).filter((key) => key !== "javascript_code");
6150
5705
  const inputVariablesString = inputVariables.map((key) => `var ${key} = ${JSON.stringify(input2[key])};`).join(`
@@ -6160,18 +5715,18 @@ class JavaScriptTask extends Task14 {
6160
5715
  var javaScript = (input2, config = {}) => {
6161
5716
  return new JavaScriptTask({}, config).run(input2);
6162
5717
  };
6163
- Workflow17.prototype.javaScript = CreateWorkflow16(JavaScriptTask);
5718
+ Workflow15.prototype.javaScript = CreateWorkflow14(JavaScriptTask);
6164
5719
  // src/task/JsonTask.ts
6165
5720
  import {
6166
5721
  createGraphFromDependencyJSON,
6167
5722
  createGraphFromGraphJSON,
6168
- CreateWorkflow as CreateWorkflow17,
5723
+ CreateWorkflow as CreateWorkflow15,
6169
5724
  Dataflow,
6170
5725
  GraphAsTask as GraphAsTask2,
6171
5726
  TaskConfigurationError as TaskConfigurationError2,
6172
- Workflow as Workflow18
5727
+ Workflow as Workflow16
6173
5728
  } from "@workglow/task-graph";
6174
- var inputSchema15 = {
5729
+ var inputSchema14 = {
6175
5730
  type: "object",
6176
5731
  properties: {
6177
5732
  json: {
@@ -6182,7 +5737,7 @@ var inputSchema15 = {
6182
5737
  },
6183
5738
  additionalProperties: false
6184
5739
  };
6185
- var outputSchema15 = {
5740
+ var outputSchema14 = {
6186
5741
  type: "object",
6187
5742
  properties: {
6188
5743
  output: {
@@ -6199,10 +5754,10 @@ class JsonTask extends GraphAsTask2 {
6199
5754
  static title = "JSON Task";
6200
5755
  static description = "A task that creates and manages task graphs from JSON configurations";
6201
5756
  static inputSchema() {
6202
- return inputSchema15;
5757
+ return inputSchema14;
6203
5758
  }
6204
5759
  static outputSchema() {
6205
- return outputSchema15;
5760
+ return outputSchema14;
6206
5761
  }
6207
5762
  regenerateGraph() {
6208
5763
  if (!this.runInputData.json)
@@ -6225,7 +5780,7 @@ class JsonTask extends GraphAsTask2 {
6225
5780
  if (!sourceTask) {
6226
5781
  throw new TaskConfigurationError2(`Dependency id ${dep.id} not found`);
6227
5782
  }
6228
- const df = new Dataflow(sourceTask.config.id, dep.output, item.id, input2);
5783
+ const df = new Dataflow(sourceTask.id, dep.output, item.id, input2);
6229
5784
  this.subGraph.addDataflow(df);
6230
5785
  }
6231
5786
  }
@@ -6236,26 +5791,26 @@ class JsonTask extends GraphAsTask2 {
6236
5791
  var json = (input2, config = {}) => {
6237
5792
  return new JsonTask({}, config).run(input2);
6238
5793
  };
6239
- Workflow18.prototype.json = CreateWorkflow17(JsonTask);
5794
+ Workflow16.prototype.json = CreateWorkflow15(JsonTask);
6240
5795
  // src/task/LambdaTask.ts
6241
5796
  import {
6242
- CreateWorkflow as CreateWorkflow18,
5797
+ CreateWorkflow as CreateWorkflow16,
6243
5798
  DATAFLOW_ALL_PORTS,
6244
- Task as Task15,
6245
- TaskConfigSchema as TaskConfigSchema3,
5799
+ Task as Task14,
5800
+ TaskConfigSchema as TaskConfigSchema4,
6246
5801
  TaskConfigurationError as TaskConfigurationError3,
6247
- Workflow as Workflow19
5802
+ Workflow as Workflow17
6248
5803
  } from "@workglow/task-graph";
6249
5804
  var lambdaTaskConfigSchema = {
6250
5805
  type: "object",
6251
5806
  properties: {
6252
- ...TaskConfigSchema3["properties"],
5807
+ ...TaskConfigSchema4["properties"],
6253
5808
  execute: {},
6254
5809
  executeReactive: {}
6255
5810
  },
6256
5811
  additionalProperties: false
6257
5812
  };
6258
- var inputSchema16 = {
5813
+ var inputSchema15 = {
6259
5814
  type: "object",
6260
5815
  properties: {
6261
5816
  [DATAFLOW_ALL_PORTS]: {
@@ -6265,7 +5820,7 @@ var inputSchema16 = {
6265
5820
  },
6266
5821
  additionalProperties: true
6267
5822
  };
6268
- var outputSchema16 = {
5823
+ var outputSchema15 = {
6269
5824
  type: "object",
6270
5825
  properties: {
6271
5826
  [DATAFLOW_ALL_PORTS]: {
@@ -6276,7 +5831,7 @@ var outputSchema16 = {
6276
5831
  additionalProperties: true
6277
5832
  };
6278
5833
 
6279
- class LambdaTask extends Task15 {
5834
+ class LambdaTask extends Task14 {
6280
5835
  static type = "LambdaTask";
6281
5836
  static title = "Lambda Task";
6282
5837
  static description = "A task that wraps a provided function and its input";
@@ -6286,10 +5841,10 @@ class LambdaTask extends Task15 {
6286
5841
  return lambdaTaskConfigSchema;
6287
5842
  }
6288
5843
  static inputSchema() {
6289
- return inputSchema16;
5844
+ return inputSchema15;
6290
5845
  }
6291
5846
  static outputSchema() {
6292
- return outputSchema16;
5847
+ return outputSchema15;
6293
5848
  }
6294
5849
  constructor(input2 = {}, config = {}) {
6295
5850
  if (!config.execute && !config.executeReactive) {
@@ -6327,15 +5882,15 @@ function lambda(input2, config) {
6327
5882
  const task = new LambdaTask(input2, config);
6328
5883
  return task.run();
6329
5884
  }
6330
- Workflow19.prototype.lambda = CreateWorkflow18(LambdaTask);
5885
+ Workflow17.prototype.lambda = CreateWorkflow16(LambdaTask);
6331
5886
  // src/task/MergeTask.ts
6332
- import { CreateWorkflow as CreateWorkflow19, Task as Task16, Workflow as Workflow20 } from "@workglow/task-graph";
6333
- var inputSchema17 = {
5887
+ import { CreateWorkflow as CreateWorkflow17, Task as Task15, Workflow as Workflow18 } from "@workglow/task-graph";
5888
+ var inputSchema16 = {
6334
5889
  type: "object",
6335
5890
  properties: {},
6336
5891
  additionalProperties: true
6337
5892
  };
6338
- var outputSchema17 = {
5893
+ var outputSchema16 = {
6339
5894
  type: "object",
6340
5895
  properties: {
6341
5896
  output: {
@@ -6347,17 +5902,17 @@ var outputSchema17 = {
6347
5902
  additionalProperties: false
6348
5903
  };
6349
5904
 
6350
- class MergeTask extends Task16 {
5905
+ class MergeTask extends Task15 {
6351
5906
  static type = "MergeTask";
6352
5907
  static category = "Utility";
6353
5908
  static title = "Merge";
6354
5909
  static description = "Merges multiple inputs into a single array output";
6355
5910
  static cacheable = true;
6356
5911
  static inputSchema() {
6357
- return inputSchema17;
5912
+ return inputSchema16;
6358
5913
  }
6359
5914
  static outputSchema() {
6360
- return outputSchema17;
5915
+ return outputSchema16;
6361
5916
  }
6362
5917
  async execute(input2, _context) {
6363
5918
  const keys = Object.keys(input2).sort();
@@ -6371,11 +5926,15 @@ var merge = (input2, config = {}) => {
6371
5926
  const task = new MergeTask({}, config);
6372
5927
  return task.run(input2);
6373
5928
  };
6374
- Workflow20.prototype.merge = CreateWorkflow19(MergeTask);
5929
+ Workflow18.prototype.merge = CreateWorkflow17(MergeTask);
6375
5930
  // src/task/OutputTask.ts
6376
- import { CreateWorkflow as CreateWorkflow20, Task as Task17, Workflow as Workflow21 } from "@workglow/task-graph";
5931
+ import {
5932
+ CreateWorkflow as CreateWorkflow18,
5933
+ Task as Task16,
5934
+ Workflow as Workflow19
5935
+ } from "@workglow/task-graph";
6377
5936
 
6378
- class OutputTask extends Task17 {
5937
+ class OutputTask extends Task16 {
6379
5938
  static type = "OutputTask";
6380
5939
  static category = "Flow Control";
6381
5940
  static title = "Output";
@@ -6429,10 +5988,10 @@ class OutputTask extends Task17 {
6429
5988
  yield { type: "finish", data: input2 };
6430
5989
  }
6431
5990
  }
6432
- Workflow21.prototype.output = CreateWorkflow20(OutputTask);
5991
+ Workflow19.prototype.output = CreateWorkflow18(OutputTask);
6433
5992
  // src/task/SplitTask.ts
6434
- import { CreateWorkflow as CreateWorkflow21, Task as Task18, Workflow as Workflow22 } from "@workglow/task-graph";
6435
- var inputSchema18 = {
5993
+ import { CreateWorkflow as CreateWorkflow19, Task as Task17, Workflow as Workflow20 } from "@workglow/task-graph";
5994
+ var inputSchema17 = {
6436
5995
  type: "object",
6437
5996
  properties: {
6438
5997
  input: {
@@ -6442,13 +6001,13 @@ var inputSchema18 = {
6442
6001
  },
6443
6002
  additionalProperties: false
6444
6003
  };
6445
- var outputSchema18 = {
6004
+ var outputSchema17 = {
6446
6005
  type: "object",
6447
6006
  properties: {},
6448
6007
  additionalProperties: true
6449
6008
  };
6450
6009
 
6451
- class SplitTask extends Task18 {
6010
+ class SplitTask extends Task17 {
6452
6011
  static type = "SplitTask";
6453
6012
  static category = "Utility";
6454
6013
  static title = "Split";
@@ -6456,13 +6015,13 @@ class SplitTask extends Task18 {
6456
6015
  static hasDynamicSchemas = true;
6457
6016
  static cacheable = false;
6458
6017
  static inputSchema() {
6459
- return inputSchema18;
6018
+ return inputSchema17;
6460
6019
  }
6461
6020
  static outputSchema() {
6462
- return outputSchema18;
6021
+ return outputSchema17;
6463
6022
  }
6464
6023
  outputSchema() {
6465
- return outputSchema18;
6024
+ return outputSchema17;
6466
6025
  }
6467
6026
  async executeReactive(input2) {
6468
6027
  const inputValue = input2.input;
@@ -6481,15 +6040,15 @@ var split = (input2, config = {}) => {
6481
6040
  const task = new SplitTask({}, config);
6482
6041
  return task.run(input2);
6483
6042
  };
6484
- Workflow22.prototype.split = CreateWorkflow21(SplitTask);
6043
+ Workflow20.prototype.split = CreateWorkflow19(SplitTask);
6485
6044
  // src/task/mcp/McpListTask.ts
6486
- import { CreateWorkflow as CreateWorkflow22, Task as Task19, Workflow as Workflow23 } from "@workglow/task-graph";
6045
+ import { CreateWorkflow as CreateWorkflow20, Task as Task18, Workflow as Workflow21 } from "@workglow/task-graph";
6487
6046
  import {
6488
6047
  mcpClientFactory,
6489
6048
  mcpServerConfigSchema
6490
6049
  } from "@workglow/util";
6491
6050
  var mcpListTypes = ["tools", "resources", "prompts"];
6492
- var inputSchema19 = {
6051
+ var inputSchema18 = {
6493
6052
  type: "object",
6494
6053
  properties: {
6495
6054
  ...mcpServerConfigSchema,
@@ -6658,7 +6217,7 @@ var outputSchemaAll = {
6658
6217
  additionalProperties: false
6659
6218
  };
6660
6219
 
6661
- class McpListTask extends Task19 {
6220
+ class McpListTask extends Task18 {
6662
6221
  static type = "McpListTask";
6663
6222
  static category = "MCP";
6664
6223
  static title = "MCP List";
@@ -6666,7 +6225,7 @@ class McpListTask extends Task19 {
6666
6225
  static cacheable = false;
6667
6226
  static hasDynamicSchemas = true;
6668
6227
  static inputSchema() {
6669
- return inputSchema19;
6228
+ return inputSchema18;
6670
6229
  }
6671
6230
  static outputSchema() {
6672
6231
  return outputSchemaAll;
@@ -6726,30 +6285,34 @@ class McpListTask extends Task19 {
6726
6285
  var mcpList = async (input2, config = {}) => {
6727
6286
  return new McpListTask({}, config).run(input2);
6728
6287
  };
6729
- Workflow23.prototype.mcpList = CreateWorkflow22(McpListTask);
6288
+ Workflow21.prototype.mcpList = CreateWorkflow20(McpListTask);
6730
6289
  // src/task/mcp/McpPromptGetTask.ts
6731
- import { CreateWorkflow as CreateWorkflow23, Task as Task20, Workflow as Workflow24 } from "@workglow/task-graph";
6290
+ import {
6291
+ CreateWorkflow as CreateWorkflow21,
6292
+ Task as Task19,
6293
+ TaskConfigSchema as TaskConfigSchema5,
6294
+ Workflow as Workflow22
6295
+ } from "@workglow/task-graph";
6732
6296
  import {
6733
6297
  mcpClientFactory as mcpClientFactory2,
6734
6298
  mcpServerConfigSchema as mcpServerConfigSchema2
6735
6299
  } from "@workglow/util";
6736
- var inputSchema20 = {
6300
+ var configSchema2 = {
6737
6301
  type: "object",
6738
6302
  properties: {
6303
+ ...TaskConfigSchema5["properties"],
6739
6304
  ...mcpServerConfigSchema2,
6740
6305
  prompt_name: {
6741
6306
  type: "string",
6742
6307
  title: "Prompt Name",
6743
- description: "The name of the prompt to get"
6744
- },
6745
- prompt_arguments: {
6746
- type: "object",
6747
- additionalProperties: { type: "string" },
6748
- title: "Prompt Arguments",
6749
- description: "Arguments to pass to the prompt"
6308
+ description: "The name of the prompt to get",
6309
+ format: "string:mcp-promptname"
6750
6310
  }
6751
6311
  },
6752
6312
  required: ["transport", "prompt_name"],
6313
+ if: { properties: { transport: { const: "stdio" } }, required: ["transport"] },
6314
+ then: { required: ["command"] },
6315
+ else: { required: ["server_url"] },
6753
6316
  additionalProperties: false
6754
6317
  };
6755
6318
  var annotationsSchema = {
@@ -6853,7 +6416,7 @@ var contentSchema = {
6853
6416
  }
6854
6417
  ]
6855
6418
  };
6856
- var outputSchema19 = {
6419
+ var fallbackOutputSchema = {
6857
6420
  type: "object",
6858
6421
  properties: {
6859
6422
  messages: {
@@ -6879,25 +6442,83 @@ var outputSchema19 = {
6879
6442
  required: ["messages"],
6880
6443
  additionalProperties: false
6881
6444
  };
6445
+ var fallbackInputSchema = {
6446
+ type: "object",
6447
+ properties: {},
6448
+ additionalProperties: false
6449
+ };
6882
6450
 
6883
- class McpPromptGetTask extends Task20 {
6451
+ class McpPromptGetTask extends Task19 {
6884
6452
  static type = "McpPromptGetTask";
6885
6453
  static category = "MCP";
6886
6454
  static title = "MCP Get Prompt";
6887
6455
  static description = "Gets a prompt from an MCP server";
6888
6456
  static cacheable = false;
6457
+ static customizable = true;
6458
+ static hasDynamicSchemas = true;
6889
6459
  static inputSchema() {
6890
- return inputSchema20;
6460
+ return fallbackInputSchema;
6891
6461
  }
6892
6462
  static outputSchema() {
6893
- return outputSchema19;
6463
+ return fallbackOutputSchema;
6464
+ }
6465
+ static configSchema() {
6466
+ return configSchema2;
6467
+ }
6468
+ inputSchema() {
6469
+ return this.config?.inputSchema ?? fallbackInputSchema;
6470
+ }
6471
+ outputSchema() {
6472
+ return this.config?.outputSchema ?? fallbackOutputSchema;
6473
+ }
6474
+ _schemasDiscovering = false;
6475
+ async discoverSchemas(signal) {
6476
+ if (this.config.inputSchema)
6477
+ return;
6478
+ if (this._schemasDiscovering)
6479
+ return;
6480
+ if (!this.config.transport || !this.config.prompt_name)
6481
+ return;
6482
+ this._schemasDiscovering = true;
6483
+ try {
6484
+ const result = await mcpList({
6485
+ transport: this.config.transport,
6486
+ server_url: this.config.server_url,
6487
+ command: this.config.command,
6488
+ args: this.config.args,
6489
+ env: this.config.env,
6490
+ list_type: "prompts"
6491
+ });
6492
+ const prompt = result.prompts?.find((p) => p.name === this.config.prompt_name);
6493
+ if (prompt) {
6494
+ const args = prompt.arguments ?? [];
6495
+ const required = args.filter((a) => a.required).map((a) => a.name);
6496
+ const properties = {};
6497
+ for (const arg of args) {
6498
+ properties[arg.name] = {
6499
+ type: "string",
6500
+ ...arg.description ? { description: arg.description } : {}
6501
+ };
6502
+ }
6503
+ this.config.inputSchema = {
6504
+ type: "object",
6505
+ properties,
6506
+ ...required.length > 0 ? { required } : {},
6507
+ additionalProperties: false
6508
+ };
6509
+ this.emitSchemaChange();
6510
+ }
6511
+ } finally {
6512
+ this._schemasDiscovering = false;
6513
+ }
6894
6514
  }
6895
6515
  async execute(input2, context) {
6896
- const { client } = await mcpClientFactory2.create(input2, context.signal);
6516
+ await this.discoverSchemas(context.signal);
6517
+ const { client } = await mcpClientFactory2.create(this.config, context.signal);
6897
6518
  try {
6898
6519
  const result = await client.getPrompt({
6899
- name: input2.prompt_name,
6900
- arguments: input2.prompt_arguments
6520
+ name: this.config.prompt_name,
6521
+ arguments: input2
6901
6522
  });
6902
6523
  return {
6903
6524
  messages: result.messages,
@@ -6908,28 +6529,37 @@ class McpPromptGetTask extends Task20 {
6908
6529
  }
6909
6530
  }
6910
6531
  }
6911
- var mcpPromptGet = async (input2, config = {}) => {
6912
- const result = await new McpPromptGetTask({}, config).run(input2);
6913
- return result;
6532
+ var mcpPromptGet = async (input2, config) => {
6533
+ return new McpPromptGetTask({}, config).run(input2);
6914
6534
  };
6915
- Workflow24.prototype.mcpPromptGet = CreateWorkflow23(McpPromptGetTask);
6535
+ Workflow22.prototype.mcpPromptGet = CreateWorkflow21(McpPromptGetTask);
6916
6536
  // src/task/mcp/McpResourceReadTask.ts
6917
- import { CreateWorkflow as CreateWorkflow24, Task as Task21, Workflow as Workflow25 } from "@workglow/task-graph";
6537
+ import {
6538
+ CreateWorkflow as CreateWorkflow22,
6539
+ Task as Task20,
6540
+ TaskConfigSchema as TaskConfigSchema6,
6541
+ Workflow as Workflow23
6542
+ } from "@workglow/task-graph";
6918
6543
  import {
6919
6544
  mcpClientFactory as mcpClientFactory3,
6920
6545
  mcpServerConfigSchema as mcpServerConfigSchema3
6921
6546
  } from "@workglow/util";
6922
- var inputSchema21 = {
6547
+ var configSchema3 = {
6923
6548
  type: "object",
6924
6549
  properties: {
6550
+ ...TaskConfigSchema6["properties"],
6925
6551
  ...mcpServerConfigSchema3,
6926
6552
  resource_uri: {
6927
6553
  type: "string",
6928
6554
  title: "Resource URI",
6929
- description: "The URI of the resource to read"
6555
+ description: "The URI of the resource to read",
6556
+ format: "string:uri:mcp-resourceuri"
6930
6557
  }
6931
6558
  },
6932
6559
  required: ["transport", "resource_uri"],
6560
+ if: { properties: { transport: { const: "stdio" } }, required: ["transport"] },
6561
+ then: { required: ["command"] },
6562
+ else: { required: ["server_url"] },
6933
6563
  additionalProperties: false
6934
6564
  };
6935
6565
  var contentItemSchema = {
@@ -6958,7 +6588,12 @@ var contentItemSchema = {
6958
6588
  }
6959
6589
  ]
6960
6590
  };
6961
- var outputSchema20 = {
6591
+ var inputSchema19 = {
6592
+ type: "object",
6593
+ properties: {},
6594
+ additionalProperties: false
6595
+ };
6596
+ var outputSchema18 = {
6962
6597
  type: "object",
6963
6598
  properties: {
6964
6599
  contents: {
@@ -6972,55 +6607,63 @@ var outputSchema20 = {
6972
6607
  additionalProperties: false
6973
6608
  };
6974
6609
 
6975
- class McpResourceReadTask extends Task21 {
6610
+ class McpResourceReadTask extends Task20 {
6976
6611
  static type = "McpResourceReadTask";
6977
6612
  static category = "MCP";
6978
6613
  static title = "MCP Read Resource";
6979
6614
  static description = "Reads a resource from an MCP server";
6980
6615
  static cacheable = false;
6616
+ static customizable = true;
6981
6617
  static inputSchema() {
6982
- return inputSchema21;
6618
+ return inputSchema19;
6983
6619
  }
6984
6620
  static outputSchema() {
6985
- return outputSchema20;
6621
+ return outputSchema18;
6986
6622
  }
6987
- async execute(input2, context) {
6988
- const { client } = await mcpClientFactory3.create(input2, context.signal);
6623
+ static configSchema() {
6624
+ return configSchema3;
6625
+ }
6626
+ async execute(_input, context) {
6627
+ const { client } = await mcpClientFactory3.create(this.config, context.signal);
6989
6628
  try {
6990
- const result = await client.readResource({ uri: input2.resource_uri });
6629
+ const result = await client.readResource({ uri: this.config.resource_uri });
6991
6630
  return { contents: result.contents };
6992
6631
  } finally {
6993
6632
  await client.close();
6994
6633
  }
6995
6634
  }
6996
6635
  }
6997
- var mcpResourceRead = async (input2, config = {}) => {
6998
- return new McpResourceReadTask({}, config).run(input2);
6636
+ var mcpResourceRead = async (config) => {
6637
+ return new McpResourceReadTask({}, config).run({});
6999
6638
  };
7000
- Workflow25.prototype.mcpResourceRead = CreateWorkflow24(McpResourceReadTask);
6639
+ Workflow23.prototype.mcpResourceRead = CreateWorkflow22(McpResourceReadTask);
7001
6640
  // src/task/mcp/McpToolCallTask.ts
7002
- import { CreateWorkflow as CreateWorkflow25, Task as Task22, Workflow as Workflow26 } from "@workglow/task-graph";
6641
+ import {
6642
+ CreateWorkflow as CreateWorkflow23,
6643
+ Task as Task21,
6644
+ TaskConfigSchema as TaskConfigSchema7,
6645
+ Workflow as Workflow24
6646
+ } from "@workglow/task-graph";
7003
6647
  import {
7004
6648
  mcpClientFactory as mcpClientFactory4,
7005
6649
  mcpServerConfigSchema as mcpServerConfigSchema4
7006
6650
  } from "@workglow/util";
7007
- var inputSchema22 = {
6651
+ var configSchema4 = {
7008
6652
  type: "object",
7009
6653
  properties: {
6654
+ ...TaskConfigSchema7["properties"],
7010
6655
  ...mcpServerConfigSchema4,
7011
6656
  tool_name: {
7012
6657
  type: "string",
7013
6658
  title: "Tool Name",
7014
- description: "The name of the tool to call"
7015
- },
7016
- tool_arguments: {
7017
- type: "object",
7018
- additionalProperties: true,
7019
- title: "Tool Arguments",
7020
- description: "Arguments to pass to the tool"
6659
+ description: "The name of the tool to call",
6660
+ format: "string:mcp-toolname"
7021
6661
  }
7022
6662
  },
7023
6663
  required: ["transport", "tool_name"],
6664
+ if: { properties: { transport: { const: "stdio" } }, required: ["transport"] },
6665
+ then: { required: ["command"] },
6666
+ else: { required: ["server_url"] },
7024
6667
  additionalProperties: false
7025
6668
  };
7026
6669
  var annotationsSchema2 = {
@@ -7124,7 +6767,7 @@ var toolContentSchema = {
7124
6767
  }
7125
6768
  ]
7126
6769
  };
7127
- var outputSchema21 = {
6770
+ var fallbackOutputSchema2 = {
7128
6771
  type: "object",
7129
6772
  properties: {
7130
6773
  content: {
@@ -7142,45 +6785,115 @@ var outputSchema21 = {
7142
6785
  required: ["content", "isError"],
7143
6786
  additionalProperties: false
7144
6787
  };
6788
+ var fallbackInputSchema2 = {
6789
+ type: "object",
6790
+ properties: {},
6791
+ additionalProperties: true
6792
+ };
7145
6793
 
7146
- class McpToolCallTask extends Task22 {
6794
+ class McpToolCallTask extends Task21 {
7147
6795
  static type = "McpToolCallTask";
7148
6796
  static category = "MCP";
7149
6797
  static title = "MCP Call Tool";
7150
6798
  static description = "Calls a tool on an MCP server and returns the result";
7151
6799
  static cacheable = false;
6800
+ static customizable = true;
6801
+ static hasDynamicSchemas = true;
7152
6802
  static inputSchema() {
7153
- return inputSchema22;
6803
+ return fallbackInputSchema2;
7154
6804
  }
7155
6805
  static outputSchema() {
7156
- return outputSchema21;
6806
+ return fallbackOutputSchema2;
6807
+ }
6808
+ static configSchema() {
6809
+ return configSchema4;
6810
+ }
6811
+ inputSchema() {
6812
+ return this.config?.inputSchema ?? fallbackInputSchema2;
6813
+ }
6814
+ outputSchema() {
6815
+ return this.config?.outputSchema ?? fallbackOutputSchema2;
6816
+ }
6817
+ _schemasDiscovering = false;
6818
+ async discoverSchemas(signal) {
6819
+ if (this.config.inputSchema && this.config.outputSchema)
6820
+ return;
6821
+ if (this._schemasDiscovering)
6822
+ return;
6823
+ if (!this.config.transport || !this.config.tool_name)
6824
+ return;
6825
+ this._schemasDiscovering = true;
6826
+ try {
6827
+ const result = await mcpList({
6828
+ transport: this.config.transport,
6829
+ server_url: this.config.server_url,
6830
+ command: this.config.command,
6831
+ args: this.config.args,
6832
+ env: this.config.env,
6833
+ list_type: "tools"
6834
+ });
6835
+ const tool = result.tools?.find((t) => t.name === this.config.tool_name);
6836
+ if (tool) {
6837
+ if (!this.config.inputSchema) {
6838
+ this.config.inputSchema = tool.inputSchema;
6839
+ }
6840
+ if (!this.config.outputSchema && tool.outputSchema) {
6841
+ this.config.outputSchema = tool.outputSchema;
6842
+ }
6843
+ this.emitSchemaChange();
6844
+ }
6845
+ } finally {
6846
+ this._schemasDiscovering = false;
6847
+ }
7157
6848
  }
7158
6849
  async execute(input2, context) {
7159
- const { client } = await mcpClientFactory4.create(input2, context.signal);
6850
+ await this.discoverSchemas(context.signal);
6851
+ const { client } = await mcpClientFactory4.create(this.config, context.signal);
7160
6852
  try {
7161
6853
  const result = await client.callTool({
7162
- name: input2.tool_name,
7163
- arguments: input2.tool_arguments
6854
+ name: this.config.tool_name,
6855
+ arguments: input2
7164
6856
  });
7165
6857
  if (!("content" in result) || !Array.isArray(result.content)) {
7166
6858
  throw new Error("Expected tool result with content array");
7167
6859
  }
6860
+ const content = result.content;
6861
+ const isError = result.isError === true;
6862
+ const structuredContent = "structuredContent" in result && result.structuredContent && typeof result.structuredContent === "object" && !Array.isArray(result.structuredContent) ? result.structuredContent : undefined;
6863
+ let parsedFromText;
6864
+ if (!structuredContent && content.length === 1) {
6865
+ const item = content[0];
6866
+ if (item && typeof item === "object" && "type" in item && item.type === "text" && "text" in item) {
6867
+ const text = String(item.text);
6868
+ const trimmed = text.trim();
6869
+ if (trimmed.startsWith("{") && trimmed.endsWith("}") || trimmed.startsWith("[") && trimmed.endsWith("]")) {
6870
+ try {
6871
+ const parsed = JSON.parse(text);
6872
+ if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) {
6873
+ parsedFromText = parsed;
6874
+ }
6875
+ } catch {}
6876
+ }
6877
+ }
6878
+ }
7168
6879
  return {
7169
- content: result.content,
7170
- isError: result.isError === true
6880
+ content,
6881
+ isError,
6882
+ ...parsedFromText,
6883
+ ...structuredContent
7171
6884
  };
7172
6885
  } finally {
7173
6886
  await client.close();
7174
6887
  }
7175
6888
  }
7176
6889
  }
7177
- var mcpToolCall = async (input2, config = {}) => {
6890
+ var mcpToolCall = async (input2, config) => {
7178
6891
  return new McpToolCallTask({}, config).run(input2);
7179
6892
  };
7180
- Workflow26.prototype.mcpToolCall = CreateWorkflow25(McpToolCallTask);
6893
+ Workflow24.prototype.mcpToolCall = CreateWorkflow23(McpToolCallTask);
7181
6894
  // src/task/scalar/ScalarAbsTask.ts
7182
- import { CreateWorkflow as CreateWorkflow26, Task as Task23, Workflow as Workflow27 } from "@workglow/task-graph";
7183
- var inputSchema23 = {
6895
+ import { CreateWorkflow as CreateWorkflow24, Task as Task22, Workflow as Workflow25 } from "@workglow/task-graph";
6896
+ var inputSchema20 = {
7184
6897
  type: "object",
7185
6898
  properties: {
7186
6899
  value: {
@@ -7192,7 +6905,7 @@ var inputSchema23 = {
7192
6905
  required: ["value"],
7193
6906
  additionalProperties: false
7194
6907
  };
7195
- var outputSchema22 = {
6908
+ var outputSchema19 = {
7196
6909
  type: "object",
7197
6910
  properties: {
7198
6911
  result: {
@@ -7205,25 +6918,25 @@ var outputSchema22 = {
7205
6918
  additionalProperties: false
7206
6919
  };
7207
6920
 
7208
- class ScalarAbsTask extends Task23 {
6921
+ class ScalarAbsTask extends Task22 {
7209
6922
  static type = "ScalarAbsTask";
7210
6923
  static category = "Math";
7211
6924
  static title = "Abs";
7212
6925
  static description = "Returns the absolute value of a number";
7213
6926
  static inputSchema() {
7214
- return inputSchema23;
6927
+ return inputSchema20;
7215
6928
  }
7216
6929
  static outputSchema() {
7217
- return outputSchema22;
6930
+ return outputSchema19;
7218
6931
  }
7219
6932
  async execute(input2, _context) {
7220
6933
  return { result: Math.abs(input2.value) };
7221
6934
  }
7222
6935
  }
7223
- Workflow27.prototype.scalarAbs = CreateWorkflow26(ScalarAbsTask);
6936
+ Workflow25.prototype.scalarAbs = CreateWorkflow24(ScalarAbsTask);
7224
6937
  // src/task/scalar/ScalarCeilTask.ts
7225
- import { CreateWorkflow as CreateWorkflow27, Task as Task24, Workflow as Workflow28 } from "@workglow/task-graph";
7226
- var inputSchema24 = {
6938
+ import { CreateWorkflow as CreateWorkflow25, Task as Task23, Workflow as Workflow26 } from "@workglow/task-graph";
6939
+ var inputSchema21 = {
7227
6940
  type: "object",
7228
6941
  properties: {
7229
6942
  value: {
@@ -7235,7 +6948,7 @@ var inputSchema24 = {
7235
6948
  required: ["value"],
7236
6949
  additionalProperties: false
7237
6950
  };
7238
- var outputSchema23 = {
6951
+ var outputSchema20 = {
7239
6952
  type: "object",
7240
6953
  properties: {
7241
6954
  result: {
@@ -7248,25 +6961,25 @@ var outputSchema23 = {
7248
6961
  additionalProperties: false
7249
6962
  };
7250
6963
 
7251
- class ScalarCeilTask extends Task24 {
6964
+ class ScalarCeilTask extends Task23 {
7252
6965
  static type = "ScalarCeilTask";
7253
6966
  static category = "Math";
7254
6967
  static title = "Ceil";
7255
6968
  static description = "Returns the smallest integer greater than or equal to a number";
7256
6969
  static inputSchema() {
7257
- return inputSchema24;
6970
+ return inputSchema21;
7258
6971
  }
7259
6972
  static outputSchema() {
7260
- return outputSchema23;
6973
+ return outputSchema20;
7261
6974
  }
7262
6975
  async execute(input2, _context) {
7263
6976
  return { result: Math.ceil(input2.value) };
7264
6977
  }
7265
6978
  }
7266
- Workflow28.prototype.scalarCeil = CreateWorkflow27(ScalarCeilTask);
6979
+ Workflow26.prototype.scalarCeil = CreateWorkflow25(ScalarCeilTask);
7267
6980
  // src/task/scalar/ScalarFloorTask.ts
7268
- import { CreateWorkflow as CreateWorkflow28, Task as Task25, Workflow as Workflow29 } from "@workglow/task-graph";
7269
- var inputSchema25 = {
6981
+ import { CreateWorkflow as CreateWorkflow26, Task as Task24, Workflow as Workflow27 } from "@workglow/task-graph";
6982
+ var inputSchema22 = {
7270
6983
  type: "object",
7271
6984
  properties: {
7272
6985
  value: {
@@ -7278,7 +6991,7 @@ var inputSchema25 = {
7278
6991
  required: ["value"],
7279
6992
  additionalProperties: false
7280
6993
  };
7281
- var outputSchema24 = {
6994
+ var outputSchema21 = {
7282
6995
  type: "object",
7283
6996
  properties: {
7284
6997
  result: {
@@ -7291,25 +7004,25 @@ var outputSchema24 = {
7291
7004
  additionalProperties: false
7292
7005
  };
7293
7006
 
7294
- class ScalarFloorTask extends Task25 {
7007
+ class ScalarFloorTask extends Task24 {
7295
7008
  static type = "ScalarFloorTask";
7296
7009
  static category = "Math";
7297
7010
  static title = "Floor";
7298
7011
  static description = "Returns the largest integer less than or equal to a number";
7299
7012
  static inputSchema() {
7300
- return inputSchema25;
7013
+ return inputSchema22;
7301
7014
  }
7302
7015
  static outputSchema() {
7303
- return outputSchema24;
7016
+ return outputSchema21;
7304
7017
  }
7305
7018
  async execute(input2, _context) {
7306
7019
  return { result: Math.floor(input2.value) };
7307
7020
  }
7308
7021
  }
7309
- Workflow29.prototype.scalarFloor = CreateWorkflow28(ScalarFloorTask);
7022
+ Workflow27.prototype.scalarFloor = CreateWorkflow26(ScalarFloorTask);
7310
7023
  // src/task/scalar/ScalarMaxTask.ts
7311
- import { CreateWorkflow as CreateWorkflow29, Task as Task26, Workflow as Workflow30 } from "@workglow/task-graph";
7312
- var inputSchema26 = {
7024
+ import { CreateWorkflow as CreateWorkflow27, Task as Task25, Workflow as Workflow28 } from "@workglow/task-graph";
7025
+ var inputSchema23 = {
7313
7026
  type: "object",
7314
7027
  properties: {
7315
7028
  values: {
@@ -7322,7 +7035,7 @@ var inputSchema26 = {
7322
7035
  required: ["values"],
7323
7036
  additionalProperties: false
7324
7037
  };
7325
- var outputSchema25 = {
7038
+ var outputSchema22 = {
7326
7039
  type: "object",
7327
7040
  properties: {
7328
7041
  result: {
@@ -7335,25 +7048,25 @@ var outputSchema25 = {
7335
7048
  additionalProperties: false
7336
7049
  };
7337
7050
 
7338
- class ScalarMaxTask extends Task26 {
7051
+ class ScalarMaxTask extends Task25 {
7339
7052
  static type = "ScalarMaxTask";
7340
7053
  static category = "Math";
7341
7054
  static title = "Max";
7342
7055
  static description = "Returns the largest of the given numbers";
7343
7056
  static inputSchema() {
7344
- return inputSchema26;
7057
+ return inputSchema23;
7345
7058
  }
7346
7059
  static outputSchema() {
7347
- return outputSchema25;
7060
+ return outputSchema22;
7348
7061
  }
7349
7062
  async execute(input2, _context) {
7350
7063
  return { result: Math.max(...input2.values) };
7351
7064
  }
7352
7065
  }
7353
- Workflow30.prototype.scalarMax = CreateWorkflow29(ScalarMaxTask);
7066
+ Workflow28.prototype.scalarMax = CreateWorkflow27(ScalarMaxTask);
7354
7067
  // src/task/scalar/ScalarMinTask.ts
7355
- import { CreateWorkflow as CreateWorkflow30, Task as Task27, Workflow as Workflow31 } from "@workglow/task-graph";
7356
- var inputSchema27 = {
7068
+ import { CreateWorkflow as CreateWorkflow28, Task as Task26, Workflow as Workflow29 } from "@workglow/task-graph";
7069
+ var inputSchema24 = {
7357
7070
  type: "object",
7358
7071
  properties: {
7359
7072
  values: {
@@ -7366,7 +7079,7 @@ var inputSchema27 = {
7366
7079
  required: ["values"],
7367
7080
  additionalProperties: false
7368
7081
  };
7369
- var outputSchema26 = {
7082
+ var outputSchema23 = {
7370
7083
  type: "object",
7371
7084
  properties: {
7372
7085
  result: {
@@ -7379,25 +7092,25 @@ var outputSchema26 = {
7379
7092
  additionalProperties: false
7380
7093
  };
7381
7094
 
7382
- class ScalarMinTask extends Task27 {
7095
+ class ScalarMinTask extends Task26 {
7383
7096
  static type = "ScalarMinTask";
7384
7097
  static category = "Math";
7385
7098
  static title = "Min";
7386
7099
  static description = "Returns the smallest of the given numbers";
7387
7100
  static inputSchema() {
7388
- return inputSchema27;
7101
+ return inputSchema24;
7389
7102
  }
7390
7103
  static outputSchema() {
7391
- return outputSchema26;
7104
+ return outputSchema23;
7392
7105
  }
7393
7106
  async execute(input2, _context) {
7394
7107
  return { result: Math.min(...input2.values) };
7395
7108
  }
7396
7109
  }
7397
- Workflow31.prototype.scalarMin = CreateWorkflow30(ScalarMinTask);
7110
+ Workflow29.prototype.scalarMin = CreateWorkflow28(ScalarMinTask);
7398
7111
  // src/task/scalar/ScalarRoundTask.ts
7399
- import { CreateWorkflow as CreateWorkflow31, Task as Task28, Workflow as Workflow32 } from "@workglow/task-graph";
7400
- var inputSchema28 = {
7112
+ import { CreateWorkflow as CreateWorkflow29, Task as Task27, Workflow as Workflow30 } from "@workglow/task-graph";
7113
+ var inputSchema25 = {
7401
7114
  type: "object",
7402
7115
  properties: {
7403
7116
  value: {
@@ -7409,7 +7122,7 @@ var inputSchema28 = {
7409
7122
  required: ["value"],
7410
7123
  additionalProperties: false
7411
7124
  };
7412
- var outputSchema27 = {
7125
+ var outputSchema24 = {
7413
7126
  type: "object",
7414
7127
  properties: {
7415
7128
  result: {
@@ -7422,25 +7135,25 @@ var outputSchema27 = {
7422
7135
  additionalProperties: false
7423
7136
  };
7424
7137
 
7425
- class ScalarRoundTask extends Task28 {
7138
+ class ScalarRoundTask extends Task27 {
7426
7139
  static type = "ScalarRoundTask";
7427
7140
  static category = "Math";
7428
7141
  static title = "Round";
7429
7142
  static description = "Returns the value of a number rounded to the nearest integer";
7430
7143
  static inputSchema() {
7431
- return inputSchema28;
7144
+ return inputSchema25;
7432
7145
  }
7433
7146
  static outputSchema() {
7434
- return outputSchema27;
7147
+ return outputSchema24;
7435
7148
  }
7436
7149
  async execute(input2, _context) {
7437
7150
  return { result: Math.round(input2.value) };
7438
7151
  }
7439
7152
  }
7440
- Workflow32.prototype.scalarRound = CreateWorkflow31(ScalarRoundTask);
7153
+ Workflow30.prototype.scalarRound = CreateWorkflow29(ScalarRoundTask);
7441
7154
  // src/task/scalar/ScalarTruncTask.ts
7442
- import { CreateWorkflow as CreateWorkflow32, Task as Task29, Workflow as Workflow33 } from "@workglow/task-graph";
7443
- var inputSchema29 = {
7155
+ import { CreateWorkflow as CreateWorkflow30, Task as Task28, Workflow as Workflow31 } from "@workglow/task-graph";
7156
+ var inputSchema26 = {
7444
7157
  type: "object",
7445
7158
  properties: {
7446
7159
  value: {
@@ -7452,7 +7165,7 @@ var inputSchema29 = {
7452
7165
  required: ["value"],
7453
7166
  additionalProperties: false
7454
7167
  };
7455
- var outputSchema28 = {
7168
+ var outputSchema25 = {
7456
7169
  type: "object",
7457
7170
  properties: {
7458
7171
  result: {
@@ -7465,28 +7178,28 @@ var outputSchema28 = {
7465
7178
  additionalProperties: false
7466
7179
  };
7467
7180
 
7468
- class ScalarTruncTask extends Task29 {
7181
+ class ScalarTruncTask extends Task28 {
7469
7182
  static type = "ScalarTruncTask";
7470
7183
  static category = "Math";
7471
7184
  static title = "Truncate";
7472
7185
  static description = "Returns the integer part of a number by removing fractional digits";
7473
7186
  static inputSchema() {
7474
- return inputSchema29;
7187
+ return inputSchema26;
7475
7188
  }
7476
7189
  static outputSchema() {
7477
- return outputSchema28;
7190
+ return outputSchema25;
7478
7191
  }
7479
7192
  async execute(input2, _context) {
7480
7193
  return { result: Math.trunc(input2.value) };
7481
7194
  }
7482
7195
  }
7483
- Workflow33.prototype.scalarTrunc = CreateWorkflow32(ScalarTruncTask);
7196
+ Workflow31.prototype.scalarTrunc = CreateWorkflow30(ScalarTruncTask);
7484
7197
  // src/task/vector/VectorDistanceTask.ts
7485
- import { CreateWorkflow as CreateWorkflow33, Task as Task30, Workflow as Workflow34 } from "@workglow/task-graph";
7198
+ import { CreateWorkflow as CreateWorkflow31, Task as Task29, Workflow as Workflow32 } from "@workglow/task-graph";
7486
7199
  import {
7487
7200
  TypedArraySchema as TypedArraySchema5
7488
7201
  } from "@workglow/util";
7489
- var inputSchema30 = {
7202
+ var inputSchema27 = {
7490
7203
  type: "object",
7491
7204
  properties: {
7492
7205
  vectors: {
@@ -7502,7 +7215,7 @@ var inputSchema30 = {
7502
7215
  required: ["vectors"],
7503
7216
  additionalProperties: false
7504
7217
  };
7505
- var outputSchema29 = {
7218
+ var outputSchema26 = {
7506
7219
  type: "object",
7507
7220
  properties: {
7508
7221
  result: {
@@ -7515,16 +7228,16 @@ var outputSchema29 = {
7515
7228
  additionalProperties: false
7516
7229
  };
7517
7230
 
7518
- class VectorDistanceTask extends Task30 {
7231
+ class VectorDistanceTask extends Task29 {
7519
7232
  static type = "VectorDistanceTask";
7520
7233
  static category = "Vector";
7521
7234
  static title = "Distance";
7522
7235
  static description = "Returns the Euclidean distance between the first two vectors";
7523
7236
  static inputSchema() {
7524
- return inputSchema30;
7237
+ return inputSchema27;
7525
7238
  }
7526
7239
  static outputSchema() {
7527
- return outputSchema29;
7240
+ return outputSchema26;
7528
7241
  }
7529
7242
  async execute(input2, _context) {
7530
7243
  const { vectors } = input2;
@@ -7542,13 +7255,13 @@ class VectorDistanceTask extends Task30 {
7542
7255
  return { result: Math.sqrt(sumPrecise(diffs)) };
7543
7256
  }
7544
7257
  }
7545
- Workflow34.prototype.vectorDistance = CreateWorkflow33(VectorDistanceTask);
7258
+ Workflow32.prototype.vectorDistance = CreateWorkflow31(VectorDistanceTask);
7546
7259
  // src/task/vector/VectorDotProductTask.ts
7547
- import { CreateWorkflow as CreateWorkflow34, Task as Task31, Workflow as Workflow35 } from "@workglow/task-graph";
7260
+ import { CreateWorkflow as CreateWorkflow32, Task as Task30, Workflow as Workflow33 } from "@workglow/task-graph";
7548
7261
  import {
7549
7262
  TypedArraySchema as TypedArraySchema6
7550
7263
  } from "@workglow/util";
7551
- var inputSchema31 = {
7264
+ var inputSchema28 = {
7552
7265
  type: "object",
7553
7266
  properties: {
7554
7267
  vectors: {
@@ -7564,7 +7277,7 @@ var inputSchema31 = {
7564
7277
  required: ["vectors"],
7565
7278
  additionalProperties: false
7566
7279
  };
7567
- var outputSchema30 = {
7280
+ var outputSchema27 = {
7568
7281
  type: "object",
7569
7282
  properties: {
7570
7283
  result: {
@@ -7577,16 +7290,16 @@ var outputSchema30 = {
7577
7290
  additionalProperties: false
7578
7291
  };
7579
7292
 
7580
- class VectorDotProductTask extends Task31 {
7293
+ class VectorDotProductTask extends Task30 {
7581
7294
  static type = "VectorDotProductTask";
7582
7295
  static category = "Vector";
7583
7296
  static title = "Dot Product";
7584
7297
  static description = "Returns the dot (inner) product of the first two vectors";
7585
7298
  static inputSchema() {
7586
- return inputSchema31;
7299
+ return inputSchema28;
7587
7300
  }
7588
7301
  static outputSchema() {
7589
- return outputSchema30;
7302
+ return outputSchema27;
7590
7303
  }
7591
7304
  async execute(input2, _context) {
7592
7305
  const { vectors } = input2;
@@ -7601,14 +7314,14 @@ class VectorDotProductTask extends Task31 {
7601
7314
  return { result: sumPrecise(products) };
7602
7315
  }
7603
7316
  }
7604
- Workflow35.prototype.vectorDotProduct = CreateWorkflow34(VectorDotProductTask);
7317
+ Workflow33.prototype.vectorDotProduct = CreateWorkflow32(VectorDotProductTask);
7605
7318
  // src/task/vector/VectorNormalizeTask.ts
7606
- import { CreateWorkflow as CreateWorkflow35, Task as Task32, Workflow as Workflow36 } from "@workglow/task-graph";
7319
+ import { CreateWorkflow as CreateWorkflow33, Task as Task31, Workflow as Workflow34 } from "@workglow/task-graph";
7607
7320
  import {
7608
7321
  TypedArraySchema as TypedArraySchema7,
7609
7322
  normalize
7610
7323
  } from "@workglow/util";
7611
- var inputSchema32 = {
7324
+ var inputSchema29 = {
7612
7325
  type: "object",
7613
7326
  properties: {
7614
7327
  vector: TypedArraySchema7({
@@ -7619,7 +7332,7 @@ var inputSchema32 = {
7619
7332
  required: ["vector"],
7620
7333
  additionalProperties: false
7621
7334
  };
7622
- var outputSchema31 = {
7335
+ var outputSchema28 = {
7623
7336
  type: "object",
7624
7337
  properties: {
7625
7338
  result: TypedArraySchema7({
@@ -7631,29 +7344,29 @@ var outputSchema31 = {
7631
7344
  additionalProperties: false
7632
7345
  };
7633
7346
 
7634
- class VectorNormalizeTask extends Task32 {
7347
+ class VectorNormalizeTask extends Task31 {
7635
7348
  static type = "VectorNormalizeTask";
7636
7349
  static category = "Vector";
7637
7350
  static title = "Normalize";
7638
7351
  static description = "Returns the L2-normalized (unit length) vector";
7639
7352
  static inputSchema() {
7640
- return inputSchema32;
7353
+ return inputSchema29;
7641
7354
  }
7642
7355
  static outputSchema() {
7643
- return outputSchema31;
7356
+ return outputSchema28;
7644
7357
  }
7645
7358
  async execute(input2, _context) {
7646
7359
  return { result: normalize(input2.vector) };
7647
7360
  }
7648
7361
  }
7649
- Workflow36.prototype.vectorNormalize = CreateWorkflow35(VectorNormalizeTask);
7362
+ Workflow34.prototype.vectorNormalize = CreateWorkflow33(VectorNormalizeTask);
7650
7363
  // src/task/vector/VectorScaleTask.ts
7651
- import { CreateWorkflow as CreateWorkflow36, Task as Task33, Workflow as Workflow37 } from "@workglow/task-graph";
7364
+ import { CreateWorkflow as CreateWorkflow34, Task as Task32, Workflow as Workflow35 } from "@workglow/task-graph";
7652
7365
  import {
7653
7366
  createTypedArrayFrom as createTypedArrayFrom5,
7654
7367
  TypedArraySchema as TypedArraySchema8
7655
7368
  } from "@workglow/util";
7656
- var inputSchema33 = {
7369
+ var inputSchema30 = {
7657
7370
  type: "object",
7658
7371
  properties: {
7659
7372
  vector: TypedArraySchema8({
@@ -7669,7 +7382,7 @@ var inputSchema33 = {
7669
7382
  required: ["vector", "scalar"],
7670
7383
  additionalProperties: false
7671
7384
  };
7672
- var outputSchema32 = {
7385
+ var outputSchema29 = {
7673
7386
  type: "object",
7674
7387
  properties: {
7675
7388
  result: TypedArraySchema8({
@@ -7681,16 +7394,16 @@ var outputSchema32 = {
7681
7394
  additionalProperties: false
7682
7395
  };
7683
7396
 
7684
- class VectorScaleTask extends Task33 {
7397
+ class VectorScaleTask extends Task32 {
7685
7398
  static type = "VectorScaleTask";
7686
7399
  static category = "Vector";
7687
7400
  static title = "Scale";
7688
7401
  static description = "Multiplies each element of a vector by a scalar";
7689
7402
  static inputSchema() {
7690
- return inputSchema33;
7403
+ return inputSchema30;
7691
7404
  }
7692
7405
  static outputSchema() {
7693
- return outputSchema32;
7406
+ return outputSchema29;
7694
7407
  }
7695
7408
  async execute(input2, _context) {
7696
7409
  const { vector, scalar } = input2;
@@ -7698,7 +7411,7 @@ class VectorScaleTask extends Task33 {
7698
7411
  return { result: createTypedArrayFrom5([vector], values) };
7699
7412
  }
7700
7413
  }
7701
- Workflow37.prototype.vectorScale = CreateWorkflow36(VectorScaleTask);
7414
+ Workflow35.prototype.vectorScale = CreateWorkflow34(VectorScaleTask);
7702
7415
 
7703
7416
  // src/common.ts
7704
7417
  import { TaskRegistry } from "@workglow/task-graph";
@@ -7743,20 +7456,662 @@ var registerCommonTasks = () => {
7743
7456
  return tasks;
7744
7457
  };
7745
7458
 
7746
- // src/bun.ts
7747
- [FileLoaderTask2].map(TaskRegistry2.registerTask);
7459
+ // src/task/FileLoaderTask.server.ts
7460
+ import {
7461
+ CreateWorkflow as CreateWorkflow36,
7462
+ TaskAbortedError as TaskAbortedError3,
7463
+ Workflow as Workflow37
7464
+ } from "@workglow/task-graph";
7465
+ import { readFile } from "fs/promises";
7466
+
7467
+ // src/task/FileLoaderTask.ts
7468
+ import {
7469
+ CreateWorkflow as CreateWorkflow35,
7470
+ Task as Task33,
7471
+ TaskAbortedError as TaskAbortedError2,
7472
+ Workflow as Workflow36
7473
+ } from "@workglow/task-graph";
7474
+ import Papa from "papaparse";
7475
+ var inputSchema31 = {
7476
+ type: "object",
7477
+ properties: {
7478
+ url: {
7479
+ type: "string",
7480
+ title: "URL",
7481
+ description: "URL to load document from (http://, https://)",
7482
+ format: "uri"
7483
+ },
7484
+ format: {
7485
+ type: "string",
7486
+ enum: ["text", "markdown", "json", "csv", "pdf", "image", "html", "auto"],
7487
+ title: "Format",
7488
+ description: "File format (auto-detected from URL if 'auto')",
7489
+ default: "auto"
7490
+ }
7491
+ },
7492
+ required: ["url"],
7493
+ additionalProperties: false
7494
+ };
7495
+ var outputSchema30 = {
7496
+ type: "object",
7497
+ properties: {
7498
+ text: {
7499
+ type: "string",
7500
+ title: "Text",
7501
+ description: "Text content (for text, markdown, html formats)"
7502
+ },
7503
+ json: {
7504
+ title: "JSON",
7505
+ description: "Parsed JSON object or array"
7506
+ },
7507
+ csv: {
7508
+ type: "array",
7509
+ title: "CSV",
7510
+ description: "Parsed CSV data as array of objects"
7511
+ },
7512
+ image: {
7513
+ type: "string",
7514
+ title: "Image",
7515
+ description: "Base64 data URL for image files",
7516
+ format: "image:data-uri"
7517
+ },
7518
+ pdf: {
7519
+ type: "string",
7520
+ title: "PDF",
7521
+ description: "Base64 data URL for PDF files"
7522
+ },
7523
+ frontmatter: {
7524
+ type: "object",
7525
+ title: "Frontmatter",
7526
+ description: "Parsed YAML frontmatter from markdown/MDX files"
7527
+ },
7528
+ metadata: {
7529
+ type: "object",
7530
+ properties: {
7531
+ url: { type: "string" },
7532
+ format: { type: "string" },
7533
+ size: { type: "number" },
7534
+ title: { type: "string" },
7535
+ mimeType: { type: "string" }
7536
+ },
7537
+ additionalProperties: false,
7538
+ title: "Metadata",
7539
+ description: "File metadata"
7540
+ }
7541
+ },
7542
+ required: ["metadata"],
7543
+ additionalProperties: false
7544
+ };
7545
+
7546
+ class FileLoaderTask extends Task33 {
7547
+ static type = "FileLoaderTask";
7548
+ static category = "Document";
7549
+ static title = "File Loader";
7550
+ static description = "Load documents from URLs (http://, https://)";
7551
+ static cacheable = true;
7552
+ static inputSchema() {
7553
+ return inputSchema31;
7554
+ }
7555
+ static outputSchema() {
7556
+ return outputSchema30;
7557
+ }
7558
+ async execute(input2, context) {
7559
+ const { url, format = "auto" } = input2;
7560
+ if (context.signal.aborted) {
7561
+ throw new TaskAbortedError2("Task aborted");
7562
+ }
7563
+ await context.updateProgress(0, "Detecting file format");
7564
+ const detectedFormat = this.detectFormat(url, format);
7565
+ const responseType = this.detectResponseType(detectedFormat);
7566
+ if (context.signal.aborted) {
7567
+ throw new TaskAbortedError2("Task aborted");
7568
+ }
7569
+ await context.updateProgress(10, `Fetching ${detectedFormat} file from ${url}`);
7570
+ const fetchTask = context.own(new FetchUrlTask({
7571
+ url,
7572
+ response_type: responseType,
7573
+ queue: false
7574
+ }));
7575
+ const response = await fetchTask.run();
7576
+ if (context.signal.aborted) {
7577
+ throw new TaskAbortedError2("Task aborted");
7578
+ }
7579
+ await context.updateProgress(60, "Parsing file content");
7580
+ const title = url.split("/").pop() || url;
7581
+ const { text, json: json2, csv, image, pdf, frontmatter, size, mimeType } = await this.parseResponse(response, url, detectedFormat);
7582
+ if (context.signal.aborted) {
7583
+ throw new TaskAbortedError2("Task aborted");
7584
+ }
7585
+ await context.updateProgress(100, "File loaded successfully");
7586
+ return {
7587
+ text,
7588
+ json: json2,
7589
+ csv,
7590
+ image,
7591
+ pdf,
7592
+ frontmatter,
7593
+ metadata: {
7594
+ url,
7595
+ format: detectedFormat,
7596
+ size,
7597
+ title,
7598
+ mimeType
7599
+ }
7600
+ };
7601
+ }
7602
+ parseJsonContent(content) {
7603
+ return JSON.parse(content);
7604
+ }
7605
+ parseCsvContent(content) {
7606
+ try {
7607
+ const result = Papa.parse(content, {
7608
+ header: true,
7609
+ skipEmptyLines: true,
7610
+ transformHeader: (header) => header.trim()
7611
+ });
7612
+ return result.data;
7613
+ } catch (error) {
7614
+ throw new Error(`Failed to parse CSV: ${error}`);
7615
+ }
7616
+ }
7617
+ parseFrontmatter(content) {
7618
+ const trimmed = content.replace(/^\uFEFF/, "");
7619
+ if (!trimmed.startsWith(`---
7620
+ `) && !trimmed.startsWith(`---\r
7621
+ `)) {
7622
+ return { frontmatter: undefined, body: content };
7623
+ }
7624
+ const firstDelimEnd = trimmed.indexOf(`
7625
+ `) + 1;
7626
+ const closingIdx = trimmed.indexOf(`
7627
+ ---`, firstDelimEnd);
7628
+ if (closingIdx === -1) {
7629
+ return { frontmatter: undefined, body: content };
7630
+ }
7631
+ const yamlBlock = trimmed.slice(firstDelimEnd, closingIdx);
7632
+ const afterClosing = closingIdx + 4;
7633
+ let bodyStart = afterClosing;
7634
+ if (trimmed[bodyStart] === "\r")
7635
+ bodyStart++;
7636
+ if (trimmed[bodyStart] === `
7637
+ `)
7638
+ bodyStart++;
7639
+ const body = trimmed.slice(bodyStart).replace(/^\r?\n/, "");
7640
+ const frontmatter = this.parseSimpleYaml(yamlBlock);
7641
+ return { frontmatter, body };
7642
+ }
7643
+ parseSimpleYaml(yaml) {
7644
+ const result = {};
7645
+ const lines = yaml.split(/\r?\n/);
7646
+ let i = 0;
7647
+ while (i < lines.length) {
7648
+ i = this.parseYamlLine(lines, i, result, 0);
7649
+ }
7650
+ return result;
7651
+ }
7652
+ parseYamlLine(lines, index, target, indent) {
7653
+ if (index >= lines.length)
7654
+ return index + 1;
7655
+ const line = lines[index];
7656
+ if (line.trim() === "" || line.trim().startsWith("#")) {
7657
+ return index + 1;
7658
+ }
7659
+ const lineIndent = line.length - line.trimStart().length;
7660
+ if (lineIndent < indent)
7661
+ return index;
7662
+ const match = line.match(/^(\s*)([^:#]+?)\s*:\s*(.*)?$/);
7663
+ if (!match)
7664
+ return index + 1;
7665
+ const key = match[2].trim();
7666
+ const rawValue = (match[3] ?? "").trim();
7667
+ if (rawValue === "" || rawValue === "|" || rawValue === ">") {
7668
+ const nextIndex = index + 1;
7669
+ if (nextIndex < lines.length) {
7670
+ const nextLine = lines[nextIndex];
7671
+ const nextTrimmed = nextLine.trimStart();
7672
+ const nextIndent = nextLine.length - nextTrimmed.length;
7673
+ if (nextIndent > lineIndent && nextTrimmed.startsWith("- ")) {
7674
+ const arr = [];
7675
+ let j = nextIndex;
7676
+ while (j < lines.length) {
7677
+ const arrLine = lines[j];
7678
+ const arrTrimmed = arrLine.trimStart();
7679
+ const arrIndent = arrLine.length - arrTrimmed.length;
7680
+ if (arrTrimmed === "" || arrTrimmed.startsWith("#")) {
7681
+ j++;
7682
+ continue;
7683
+ }
7684
+ if (arrIndent < nextIndent)
7685
+ break;
7686
+ if (arrTrimmed.startsWith("- ")) {
7687
+ arr.push(this.parseYamlValue(arrTrimmed.slice(2).trim()));
7688
+ j++;
7689
+ } else {
7690
+ break;
7691
+ }
7692
+ }
7693
+ target[key] = arr;
7694
+ return j;
7695
+ } else if (nextIndent > lineIndent) {
7696
+ const nested = {};
7697
+ let j = nextIndex;
7698
+ while (j < lines.length) {
7699
+ const nestedLine = lines[j];
7700
+ const nestedTrimmed = nestedLine.trimStart();
7701
+ const nestedIndent = nestedLine.length - nestedTrimmed.length;
7702
+ if (nestedTrimmed === "" || nestedTrimmed.startsWith("#")) {
7703
+ j++;
7704
+ continue;
7705
+ }
7706
+ if (nestedIndent < nextIndent)
7707
+ break;
7708
+ j = this.parseYamlLine(lines, j, nested, nextIndent);
7709
+ }
7710
+ target[key] = nested;
7711
+ return j;
7712
+ }
7713
+ }
7714
+ target[key] = rawValue === "" ? null : rawValue;
7715
+ return index + 1;
7716
+ }
7717
+ target[key] = this.parseYamlValue(rawValue);
7718
+ return index + 1;
7719
+ }
7720
+ parseYamlValue(raw) {
7721
+ if (raw.startsWith('"') && raw.endsWith('"') || raw.startsWith("'") && raw.endsWith("'")) {
7722
+ return raw.slice(1, -1);
7723
+ }
7724
+ if (raw === "true" || raw === "True" || raw === "TRUE")
7725
+ return true;
7726
+ if (raw === "false" || raw === "False" || raw === "FALSE")
7727
+ return false;
7728
+ if (raw === "null" || raw === "~")
7729
+ return null;
7730
+ if (/^-?\d+(\.\d+)?$/.test(raw))
7731
+ return Number(raw);
7732
+ if (raw.startsWith("[") && raw.endsWith("]")) {
7733
+ return raw.slice(1, -1).split(",").map((item) => this.parseYamlValue(item.trim()));
7734
+ }
7735
+ return raw;
7736
+ }
7737
+ async parseResponse(response, url, detectedFormat) {
7738
+ const responseMimeType = response.metadata?.contentType || "";
7739
+ if (detectedFormat === "json") {
7740
+ if (!response.json) {
7741
+ throw new Error(`Failed to load JSON from ${url}`);
7742
+ }
7743
+ const jsonData = response.json;
7744
+ const content2 = JSON.stringify(jsonData, null, 2);
7745
+ return {
7746
+ text: undefined,
7747
+ json: jsonData,
7748
+ csv: undefined,
7749
+ image: undefined,
7750
+ pdf: undefined,
7751
+ frontmatter: undefined,
7752
+ size: content2.length,
7753
+ mimeType: responseMimeType || "application/json"
7754
+ };
7755
+ }
7756
+ if (detectedFormat === "csv") {
7757
+ const content2 = response.text || "";
7758
+ if (!content2) {
7759
+ throw new Error(`Failed to load CSV from ${url}`);
7760
+ }
7761
+ const csvData = this.parseCsvContent(content2);
7762
+ return {
7763
+ text: undefined,
7764
+ json: undefined,
7765
+ csv: csvData,
7766
+ image: undefined,
7767
+ pdf: undefined,
7768
+ frontmatter: undefined,
7769
+ size: content2.length,
7770
+ mimeType: responseMimeType || "text/csv"
7771
+ };
7772
+ }
7773
+ if (detectedFormat === "image") {
7774
+ if (!response.blob) {
7775
+ throw new Error(`Failed to load image from ${url}`);
7776
+ }
7777
+ const blob = response.blob;
7778
+ const mimeType2 = responseMimeType || (blob.type && blob.type !== "" ? blob.type : this.getImageMimeType(url));
7779
+ const imageData = await this.blobToBase64DataURL(blob, mimeType2);
7780
+ return {
7781
+ text: undefined,
7782
+ json: undefined,
7783
+ csv: undefined,
7784
+ image: imageData,
7785
+ pdf: undefined,
7786
+ frontmatter: undefined,
7787
+ size: blob.size,
7788
+ mimeType: mimeType2
7789
+ };
7790
+ }
7791
+ if (detectedFormat === "pdf") {
7792
+ if (!response.blob) {
7793
+ throw new Error(`Failed to load PDF from ${url}`);
7794
+ }
7795
+ const blob = response.blob;
7796
+ const mimeType2 = responseMimeType || "application/pdf";
7797
+ const pdfData = await this.blobToBase64DataURL(blob, mimeType2);
7798
+ return {
7799
+ text: undefined,
7800
+ json: undefined,
7801
+ csv: undefined,
7802
+ image: undefined,
7803
+ pdf: pdfData,
7804
+ frontmatter: undefined,
7805
+ size: blob.size,
7806
+ mimeType: mimeType2
7807
+ };
7808
+ }
7809
+ const content = response.text || "";
7810
+ if (!content) {
7811
+ throw new Error(`Failed to load content from ${url}`);
7812
+ }
7813
+ const mimeType = responseMimeType || (detectedFormat === "markdown" ? "text/markdown" : detectedFormat === "html" ? "text/html" : "text/plain");
7814
+ if (detectedFormat === "markdown") {
7815
+ const { frontmatter, body } = this.parseFrontmatter(content);
7816
+ return {
7817
+ text: body,
7818
+ json: undefined,
7819
+ csv: undefined,
7820
+ image: undefined,
7821
+ pdf: undefined,
7822
+ frontmatter,
7823
+ size: content.length,
7824
+ mimeType
7825
+ };
7826
+ }
7827
+ return {
7828
+ text: content,
7829
+ json: undefined,
7830
+ csv: undefined,
7831
+ image: undefined,
7832
+ pdf: undefined,
7833
+ frontmatter: undefined,
7834
+ size: content.length,
7835
+ mimeType
7836
+ };
7837
+ }
7838
+ detectResponseType(detectedFormat) {
7839
+ let responseType = "text";
7840
+ if (detectedFormat === "json") {
7841
+ responseType = "json";
7842
+ } else if (detectedFormat === "image" || detectedFormat === "pdf") {
7843
+ responseType = "blob";
7844
+ } else if (detectedFormat === "csv" || detectedFormat === "text" || detectedFormat === "markdown" || detectedFormat === "html") {
7845
+ responseType = "text";
7846
+ }
7847
+ return responseType;
7848
+ }
7849
+ detectFormat(url, format) {
7850
+ if (format === "auto") {
7851
+ const urlLower = url.toLowerCase();
7852
+ if (urlLower.endsWith(".md") || urlLower.endsWith(".mdx") || urlLower.endsWith(".markdown")) {
7853
+ return "markdown";
7854
+ } else if (urlLower.endsWith(".json")) {
7855
+ return "json";
7856
+ } else if (urlLower.endsWith(".csv")) {
7857
+ return "csv";
7858
+ } else if (urlLower.endsWith(".pdf")) {
7859
+ return "pdf";
7860
+ } else if (urlLower.match(/\.(jpg|jpeg|png|gif|bmp|webp|svg|ico)$/)) {
7861
+ return "image";
7862
+ } else if (urlLower.endsWith(".html") || urlLower.endsWith(".htm")) {
7863
+ return "html";
7864
+ } else {
7865
+ return "text";
7866
+ }
7867
+ }
7868
+ return format;
7869
+ }
7870
+ getImageMimeType(url) {
7871
+ const urlLower = url.toLowerCase();
7872
+ if (urlLower.endsWith(".png"))
7873
+ return "image/png";
7874
+ if (urlLower.endsWith(".jpg") || urlLower.endsWith(".jpeg"))
7875
+ return "image/jpeg";
7876
+ if (urlLower.endsWith(".gif"))
7877
+ return "image/gif";
7878
+ if (urlLower.endsWith(".webp"))
7879
+ return "image/webp";
7880
+ if (urlLower.endsWith(".bmp"))
7881
+ return "image/bmp";
7882
+ if (urlLower.endsWith(".svg"))
7883
+ return "image/svg+xml";
7884
+ if (urlLower.endsWith(".ico"))
7885
+ return "image/x-icon";
7886
+ return "image/jpeg";
7887
+ }
7888
+ async blobToBase64DataURL(blob, mimeType) {
7889
+ if (typeof Buffer !== "undefined") {
7890
+ const arrayBuffer = await blob.arrayBuffer();
7891
+ const buffer = Buffer.from(arrayBuffer);
7892
+ return `data:${mimeType};base64,${buffer.toString("base64")}`;
7893
+ }
7894
+ return new Promise((resolve, reject) => {
7895
+ const reader = new FileReader;
7896
+ reader.onloadend = () => {
7897
+ const result = reader.result;
7898
+ if (result.startsWith("data:;base64,")) {
7899
+ resolve(`data:${mimeType};base64,${result.substring(13)}`);
7900
+ } else {
7901
+ resolve(result);
7902
+ }
7903
+ };
7904
+ reader.onerror = reject;
7905
+ reader.readAsDataURL(blob);
7906
+ });
7907
+ }
7908
+ }
7909
+ Workflow36.prototype.fileLoader = CreateWorkflow35(FileLoaderTask);
7910
+
7911
+ // src/task/FileLoaderTask.server.ts
7912
+ class FileLoaderTask2 extends FileLoaderTask {
7913
+ async execute(input2, context) {
7914
+ let { url, format = "auto" } = input2;
7915
+ if (url.startsWith("http://") || url.startsWith("https://")) {
7916
+ return super.execute(input2, context);
7917
+ }
7918
+ if (context.signal.aborted) {
7919
+ throw new TaskAbortedError3("Task aborted");
7920
+ }
7921
+ await context.updateProgress(0, "Detecting file format");
7922
+ if (url.startsWith("file://")) {
7923
+ url = url.slice(7);
7924
+ }
7925
+ const detectedFormat = this.detectFormat(url, format);
7926
+ const title = url.split("/").pop() || url;
7927
+ if (context.signal.aborted) {
7928
+ throw new TaskAbortedError3("Task aborted");
7929
+ }
7930
+ await context.updateProgress(10, `Reading ${detectedFormat} file from filesystem`);
7931
+ if (detectedFormat === "json") {
7932
+ const fileContent2 = await readFile(url, { encoding: "utf-8" });
7933
+ if (context.signal.aborted) {
7934
+ throw new TaskAbortedError3("Task aborted");
7935
+ }
7936
+ await context.updateProgress(50, "Parsing JSON content");
7937
+ const jsonData = this.parseJsonContent(fileContent2);
7938
+ const content = JSON.stringify(jsonData, null, 2);
7939
+ if (context.signal.aborted) {
7940
+ throw new TaskAbortedError3("Task aborted");
7941
+ }
7942
+ await context.updateProgress(100, "File loaded successfully");
7943
+ return {
7944
+ text: undefined,
7945
+ json: jsonData,
7946
+ csv: undefined,
7947
+ image: undefined,
7948
+ pdf: undefined,
7949
+ frontmatter: undefined,
7950
+ metadata: {
7951
+ url,
7952
+ format: detectedFormat,
7953
+ size: content.length,
7954
+ title,
7955
+ mimeType: "application/json"
7956
+ }
7957
+ };
7958
+ }
7959
+ if (detectedFormat === "csv") {
7960
+ const fileContent2 = await readFile(url, { encoding: "utf-8" });
7961
+ if (!fileContent2) {
7962
+ throw new Error(`Failed to load CSV from ${url}`);
7963
+ }
7964
+ if (context.signal.aborted) {
7965
+ throw new TaskAbortedError3("Task aborted");
7966
+ }
7967
+ await context.updateProgress(50, "Parsing CSV content");
7968
+ const csvData = this.parseCsvContent(fileContent2);
7969
+ if (context.signal.aborted) {
7970
+ throw new TaskAbortedError3("Task aborted");
7971
+ }
7972
+ await context.updateProgress(100, "File loaded successfully");
7973
+ return {
7974
+ text: undefined,
7975
+ json: undefined,
7976
+ csv: csvData,
7977
+ image: undefined,
7978
+ pdf: undefined,
7979
+ frontmatter: undefined,
7980
+ metadata: {
7981
+ url,
7982
+ format: detectedFormat,
7983
+ size: fileContent2.length,
7984
+ title,
7985
+ mimeType: "text/csv"
7986
+ }
7987
+ };
7988
+ }
7989
+ if (detectedFormat === "image") {
7990
+ const fileBuffer = await readFile(url);
7991
+ if (context.signal.aborted) {
7992
+ throw new TaskAbortedError3("Task aborted");
7993
+ }
7994
+ await context.updateProgress(50, "Converting image to base64");
7995
+ const mimeType2 = this.getImageMimeType(url);
7996
+ const blob = new Blob([fileBuffer], { type: mimeType2 });
7997
+ const imageData = await this.blobToBase64DataURL(blob, mimeType2);
7998
+ if (context.signal.aborted) {
7999
+ throw new TaskAbortedError3("Task aborted");
8000
+ }
8001
+ await context.updateProgress(100, "File loaded successfully");
8002
+ return {
8003
+ text: undefined,
8004
+ json: undefined,
8005
+ csv: undefined,
8006
+ image: imageData,
8007
+ pdf: undefined,
8008
+ frontmatter: undefined,
8009
+ metadata: {
8010
+ url,
8011
+ format: detectedFormat,
8012
+ size: fileBuffer.length,
8013
+ title,
8014
+ mimeType: mimeType2
8015
+ }
8016
+ };
8017
+ }
8018
+ if (detectedFormat === "pdf") {
8019
+ const fileBuffer = await readFile(url);
8020
+ if (context.signal.aborted) {
8021
+ throw new TaskAbortedError3("Task aborted");
8022
+ }
8023
+ await context.updateProgress(50, "Converting PDF to base64");
8024
+ const mimeType2 = "application/pdf";
8025
+ const blob = new Blob([fileBuffer], { type: mimeType2 });
8026
+ const pdfData = await this.blobToBase64DataURL(blob, mimeType2);
8027
+ if (context.signal.aborted) {
8028
+ throw new TaskAbortedError3("Task aborted");
8029
+ }
8030
+ await context.updateProgress(100, "File loaded successfully");
8031
+ return {
8032
+ text: undefined,
8033
+ json: undefined,
8034
+ csv: undefined,
8035
+ image: undefined,
8036
+ pdf: pdfData,
8037
+ frontmatter: undefined,
8038
+ metadata: {
8039
+ url,
8040
+ format: detectedFormat,
8041
+ size: fileBuffer.length,
8042
+ title,
8043
+ mimeType: mimeType2
8044
+ }
8045
+ };
8046
+ }
8047
+ const fileContent = await readFile(url, { encoding: "utf-8" });
8048
+ if (!fileContent) {
8049
+ throw new Error(`Failed to load content from ${url}`);
8050
+ }
8051
+ if (context.signal.aborted) {
8052
+ throw new TaskAbortedError3("Task aborted");
8053
+ }
8054
+ await context.updateProgress(50, `Parsing ${detectedFormat} content`);
8055
+ const mimeType = detectedFormat === "markdown" ? "text/markdown" : detectedFormat === "html" ? "text/html" : "text/plain";
8056
+ if (context.signal.aborted) {
8057
+ throw new TaskAbortedError3("Task aborted");
8058
+ }
8059
+ await context.updateProgress(100, "File loaded successfully");
8060
+ if (detectedFormat === "markdown") {
8061
+ const { frontmatter, body } = this.parseFrontmatter(fileContent);
8062
+ return {
8063
+ text: body,
8064
+ json: undefined,
8065
+ csv: undefined,
8066
+ image: undefined,
8067
+ pdf: undefined,
8068
+ frontmatter,
8069
+ metadata: {
8070
+ url,
8071
+ format: detectedFormat,
8072
+ size: fileContent.length,
8073
+ title,
8074
+ mimeType
8075
+ }
8076
+ };
8077
+ }
8078
+ return {
8079
+ text: fileContent,
8080
+ json: undefined,
8081
+ csv: undefined,
8082
+ image: undefined,
8083
+ pdf: undefined,
8084
+ frontmatter: undefined,
8085
+ metadata: {
8086
+ url,
8087
+ format: detectedFormat,
8088
+ size: fileContent.length,
8089
+ title,
8090
+ mimeType
8091
+ }
8092
+ };
8093
+ }
8094
+ }
8095
+ var fileLoader = (input2, config) => {
8096
+ return new FileLoaderTask2({}, config).run(input2);
8097
+ };
8098
+ Workflow37.prototype.fileLoader = CreateWorkflow36(FileLoaderTask2);
8099
+
8100
+ // src/bun.ts
8101
+ var registerCommonTasks2 = () => {
8102
+ const tasks = registerCommonTasks();
8103
+ TaskRegistry2.registerTask(FileLoaderTask2);
8104
+ return [...tasks, FileLoaderTask2];
8105
+ };
7748
8106
  export {
7749
8107
  split,
7750
- registerCommonTasks,
8108
+ registerCommonTasks2 as registerCommonTasks,
7751
8109
  process,
7752
8110
  merge,
7753
- mcpTransportTypes,
7754
8111
  mcpToolCall,
7755
- mcpServerConfigSchema5 as mcpServerConfigSchema,
7756
8112
  mcpResourceRead,
7757
8113
  mcpPromptGet,
7758
8114
  mcpList,
7759
- mcpClientFactory5 as mcpClientFactory,
7760
8115
  lambdaTaskConfigSchema,
7761
8116
  lambda,
7762
8117
  json,
@@ -7765,7 +8120,6 @@ export {
7765
8120
  fetchUrl,
7766
8121
  delay,
7767
8122
  debugLog,
7768
- createMcpClient,
7769
8123
  VectorSumTask,
7770
8124
  VectorSubtractTask,
7771
8125
  VectorScaleTask,
@@ -7806,4 +8160,4 @@ export {
7806
8160
  ArrayTask
7807
8161
  };
7808
8162
 
7809
- //# debugId=7CCC89E5D1B94B2764756E2164756E21
8163
+ //# debugId=974227C62DC42D4364756E2164756E21