@workglow/tasks 0.0.102 → 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.
package/dist/node.js CHANGED
@@ -4,1090 +4,436 @@ var __require = /* @__PURE__ */ createRequire(import.meta.url);
4
4
  // src/node.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 "node: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,152 +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/task/ArrayTask.ts
1320
- import {
1321
- uuid4
537
+ uuid4
1322
538
  } from "@workglow/util";
1323
539
  import {
1324
540
  GraphAsTask,
@@ -1350,12 +566,12 @@ class ArrayTask extends GraphAsTask {
1350
566
  regenerateGraph() {
1351
567
  const arrayInputs = new Map;
1352
568
  let hasArrayInputs = false;
1353
- const inputSchema12 = this.inputSchema();
1354
- if (typeof inputSchema12 !== "boolean") {
1355
- const keys = Object.keys(inputSchema12.properties || {});
569
+ const inputSchema10 = this.inputSchema();
570
+ if (typeof inputSchema10 !== "boolean") {
571
+ const keys = Object.keys(inputSchema10.properties || {});
1356
572
  for (const inputId of keys) {
1357
573
  const inputValue = this.runInputData[inputId];
1358
- const inputDef = inputSchema12.properties?.[inputId];
574
+ const inputDef = inputSchema10.properties?.[inputId];
1359
575
  if (typeof inputDef === "object" && inputDef !== null && "x-replicate" in inputDef && inputDef["x-replicate"] === true && Array.isArray(inputValue) && inputValue.length > 1) {
1360
576
  arrayInputs.set(inputId, inputValue);
1361
577
  hasArrayInputs = true;
@@ -1444,7 +660,7 @@ class ArrayTaskRunner extends GraphAsTaskRunner {
1444
660
  }
1445
661
  }
1446
662
  // src/task/DebugLogTask.ts
1447
- 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";
1448
664
  var log_levels = ["dir", "log", "debug", "info", "warn", "error"];
1449
665
  var DEFAULT_LOG_LEVEL = "log";
1450
666
  var debugLogTaskConfigSchema = {
@@ -1461,18 +677,18 @@ var debugLogTaskConfigSchema = {
1461
677
  },
1462
678
  additionalProperties: false
1463
679
  };
1464
- var inputSchema12 = {
680
+ var inputSchema10 = {
1465
681
  type: "object",
1466
682
  properties: {},
1467
683
  additionalProperties: true
1468
684
  };
1469
- var outputSchema12 = {
685
+ var outputSchema10 = {
1470
686
  type: "object",
1471
687
  properties: {},
1472
688
  additionalProperties: true
1473
689
  };
1474
690
 
1475
- class DebugLogTask extends Task11 {
691
+ class DebugLogTask extends Task10 {
1476
692
  static type = "DebugLogTask";
1477
693
  static category = "Utility";
1478
694
  static title = "Debug Log";
@@ -1484,10 +700,10 @@ class DebugLogTask extends Task11 {
1484
700
  return debugLogTaskConfigSchema;
1485
701
  }
1486
702
  static inputSchema() {
1487
- return inputSchema12;
703
+ return inputSchema10;
1488
704
  }
1489
705
  static outputSchema() {
1490
- return outputSchema12;
706
+ return outputSchema10;
1491
707
  }
1492
708
  async executeReactive(input, output) {
1493
709
  const log_level = this.config.log_level ?? DEFAULT_LOG_LEVEL;
@@ -1505,14 +721,14 @@ var debugLog = (input, config = {}) => {
1505
721
  const task = new DebugLogTask({}, config);
1506
722
  return task.run(input);
1507
723
  };
1508
- Workflow14.prototype.debugLog = CreateWorkflow13(DebugLogTask);
724
+ Workflow11.prototype.debugLog = CreateWorkflow10(DebugLogTask);
1509
725
  // src/task/DelayTask.ts
1510
726
  import {
1511
- CreateWorkflow as CreateWorkflow14,
1512
- Task as Task12,
1513
- TaskAbortedError as TaskAbortedError3,
727
+ CreateWorkflow as CreateWorkflow11,
728
+ Task as Task11,
729
+ TaskAbortedError,
1514
730
  TaskConfigSchema as TaskConfigSchema2,
1515
- Workflow as Workflow15
731
+ Workflow as Workflow12
1516
732
  } from "@workglow/task-graph";
1517
733
  import { sleep } from "@workglow/util";
1518
734
  var delayTaskConfigSchema = {
@@ -1527,18 +743,18 @@ var delayTaskConfigSchema = {
1527
743
  },
1528
744
  additionalProperties: false
1529
745
  };
1530
- var inputSchema13 = {
746
+ var inputSchema11 = {
1531
747
  type: "object",
1532
748
  properties: {},
1533
749
  additionalProperties: true
1534
750
  };
1535
- var outputSchema13 = {
751
+ var outputSchema11 = {
1536
752
  type: "object",
1537
753
  properties: {},
1538
754
  additionalProperties: true
1539
755
  };
1540
756
 
1541
- class DelayTask extends Task12 {
757
+ class DelayTask extends Task11 {
1542
758
  static type = "DelayTask";
1543
759
  static category = "Utility";
1544
760
  static title = "Delay";
@@ -1550,10 +766,10 @@ class DelayTask extends Task12 {
1550
766
  return delayTaskConfigSchema;
1551
767
  }
1552
768
  static inputSchema() {
1553
- return inputSchema13;
769
+ return inputSchema11;
1554
770
  }
1555
771
  static outputSchema() {
1556
- return outputSchema13;
772
+ return outputSchema11;
1557
773
  }
1558
774
  async execute(input, executeContext) {
1559
775
  const delay = this.config.delay ?? 1;
@@ -1562,7 +778,7 @@ class DelayTask extends Task12 {
1562
778
  const chunkSize = delay / iterations;
1563
779
  for (let i = 0;i < iterations; i++) {
1564
780
  if (executeContext.signal.aborted) {
1565
- throw new TaskAbortedError3("Task aborted");
781
+ throw new TaskAbortedError("Task aborted");
1566
782
  }
1567
783
  await sleep(chunkSize);
1568
784
  await executeContext.updateProgress(100 * i / iterations, `Delaying for ${delay}ms`);
@@ -1577,53 +793,364 @@ var delay = (input, config = { delay: 1 }) => {
1577
793
  const task = new DelayTask({}, config);
1578
794
  return task.run(input);
1579
795
  };
1580
- Workflow15.prototype.delay = CreateWorkflow14(DelayTask);
1581
- // src/task/InputTask.ts
1582
- import { CreateWorkflow as CreateWorkflow15, Task as Task13, Workflow as Workflow16 } from "@workglow/task-graph";
1583
-
1584
- class InputTask extends Task13 {
1585
- static type = "InputTask";
1586
- static category = "Flow Control";
1587
- static title = "Input";
1588
- static description = "Starts the workflow";
1589
- static hasDynamicSchemas = true;
1590
- static cacheable = false;
1591
- static inputSchema() {
1592
- 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: {
1593
827
  type: "object",
1594
- properties: {},
1595
- additionalProperties: true
1596
- };
1597
- }
1598
- static outputSchema() {
1599
- 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: {
1600
881
  type: "object",
1601
- properties: {},
1602
- additionalProperties: true
1603
- };
1604
- }
1605
- inputSchema() {
1606
- return this.config?.inputSchema ?? this.constructor.inputSchema();
1607
- }
1608
- outputSchema() {
1609
- return this.config?.outputSchema ?? this.constructor.outputSchema();
1610
- }
1611
- async execute(input) {
1612
- 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.");
1613
896
  }
1614
- async executeReactive(input) {
1615
- return input;
897
+ const response = await globalThis.fetch(url, options);
898
+ if (!response.body) {
899
+ throw new Error("ReadableStream not supported in this environment.");
1616
900
  }
1617
- async* executeStream(input, context) {
1618
- if (context.inputStreams) {
1619
- for (const [, stream] of context.inputStreams) {
1620
- const reader = stream.getReader();
1621
- try {
1622
- while (true) {
1623
- const { done, value } = await reader.read();
1624
- if (done)
1625
- break;
1626
- if (value.type === "finish")
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) {
1150
+ const { done, value } = await reader.read();
1151
+ if (done)
1152
+ break;
1153
+ if (value.type === "finish")
1627
1154
  continue;
1628
1155
  yield value;
1629
1156
  }
@@ -1635,9 +1162,9 @@ class InputTask extends Task13 {
1635
1162
  yield { type: "finish", data: input };
1636
1163
  }
1637
1164
  }
1638
- Workflow16.prototype.input = CreateWorkflow15(InputTask);
1165
+ Workflow14.prototype.input = CreateWorkflow13(InputTask);
1639
1166
  // src/task/JavaScriptTask.ts
1640
- import { CreateWorkflow as CreateWorkflow16, Task as Task14, TaskConfigSchema as TaskConfigSchema3, 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";
1641
1168
 
1642
1169
  // src/util/acorn.js
1643
1170
  var options;
@@ -6114,7 +5641,7 @@ var configSchema = {
6114
5641
  },
6115
5642
  additionalProperties: false
6116
5643
  };
6117
- var inputSchema14 = {
5644
+ var inputSchema13 = {
6118
5645
  type: "object",
6119
5646
  properties: {
6120
5647
  javascript_code: {
@@ -6128,7 +5655,7 @@ var inputSchema14 = {
6128
5655
  required: ["javascript_code"],
6129
5656
  additionalProperties: true
6130
5657
  };
6131
- var outputSchema14 = {
5658
+ var outputSchema13 = {
6132
5659
  type: "object",
6133
5660
  properties: {
6134
5661
  output: {
@@ -6140,7 +5667,7 @@ var outputSchema14 = {
6140
5667
  additionalProperties: false
6141
5668
  };
6142
5669
 
6143
- class JavaScriptTask extends Task14 {
5670
+ class JavaScriptTask extends Task13 {
6144
5671
  static type = "JavaScriptTask";
6145
5672
  static category = "Utility";
6146
5673
  static title = "JavaScript Interpreter";
@@ -6150,10 +5677,10 @@ class JavaScriptTask extends Task14 {
6150
5677
  return configSchema;
6151
5678
  }
6152
5679
  static inputSchema() {
6153
- return inputSchema14;
5680
+ return inputSchema13;
6154
5681
  }
6155
5682
  static outputSchema() {
6156
- return outputSchema14;
5683
+ return outputSchema13;
6157
5684
  }
6158
5685
  constructor(input2 = {}, config = {}) {
6159
5686
  super(input2, config);
@@ -6169,7 +5696,7 @@ class JavaScriptTask extends Task14 {
6169
5696
  additionalProperties: true
6170
5697
  };
6171
5698
  }
6172
- return inputSchema14;
5699
+ return inputSchema13;
6173
5700
  }
6174
5701
  async executeReactive(input2, output) {
6175
5702
  if (this.config.javascript_code || input2.javascript_code) {
@@ -6188,18 +5715,18 @@ class JavaScriptTask extends Task14 {
6188
5715
  var javaScript = (input2, config = {}) => {
6189
5716
  return new JavaScriptTask({}, config).run(input2);
6190
5717
  };
6191
- Workflow17.prototype.javaScript = CreateWorkflow16(JavaScriptTask);
5718
+ Workflow15.prototype.javaScript = CreateWorkflow14(JavaScriptTask);
6192
5719
  // src/task/JsonTask.ts
6193
5720
  import {
6194
5721
  createGraphFromDependencyJSON,
6195
5722
  createGraphFromGraphJSON,
6196
- CreateWorkflow as CreateWorkflow17,
5723
+ CreateWorkflow as CreateWorkflow15,
6197
5724
  Dataflow,
6198
5725
  GraphAsTask as GraphAsTask2,
6199
5726
  TaskConfigurationError as TaskConfigurationError2,
6200
- Workflow as Workflow18
5727
+ Workflow as Workflow16
6201
5728
  } from "@workglow/task-graph";
6202
- var inputSchema15 = {
5729
+ var inputSchema14 = {
6203
5730
  type: "object",
6204
5731
  properties: {
6205
5732
  json: {
@@ -6210,7 +5737,7 @@ var inputSchema15 = {
6210
5737
  },
6211
5738
  additionalProperties: false
6212
5739
  };
6213
- var outputSchema15 = {
5740
+ var outputSchema14 = {
6214
5741
  type: "object",
6215
5742
  properties: {
6216
5743
  output: {
@@ -6227,10 +5754,10 @@ class JsonTask extends GraphAsTask2 {
6227
5754
  static title = "JSON Task";
6228
5755
  static description = "A task that creates and manages task graphs from JSON configurations";
6229
5756
  static inputSchema() {
6230
- return inputSchema15;
5757
+ return inputSchema14;
6231
5758
  }
6232
5759
  static outputSchema() {
6233
- return outputSchema15;
5760
+ return outputSchema14;
6234
5761
  }
6235
5762
  regenerateGraph() {
6236
5763
  if (!this.runInputData.json)
@@ -6253,7 +5780,7 @@ class JsonTask extends GraphAsTask2 {
6253
5780
  if (!sourceTask) {
6254
5781
  throw new TaskConfigurationError2(`Dependency id ${dep.id} not found`);
6255
5782
  }
6256
- const df = new Dataflow(sourceTask.config.id, dep.output, item.id, input2);
5783
+ const df = new Dataflow(sourceTask.id, dep.output, item.id, input2);
6257
5784
  this.subGraph.addDataflow(df);
6258
5785
  }
6259
5786
  }
@@ -6264,15 +5791,15 @@ class JsonTask extends GraphAsTask2 {
6264
5791
  var json = (input2, config = {}) => {
6265
5792
  return new JsonTask({}, config).run(input2);
6266
5793
  };
6267
- Workflow18.prototype.json = CreateWorkflow17(JsonTask);
5794
+ Workflow16.prototype.json = CreateWorkflow15(JsonTask);
6268
5795
  // src/task/LambdaTask.ts
6269
5796
  import {
6270
- CreateWorkflow as CreateWorkflow18,
5797
+ CreateWorkflow as CreateWorkflow16,
6271
5798
  DATAFLOW_ALL_PORTS,
6272
- Task as Task15,
5799
+ Task as Task14,
6273
5800
  TaskConfigSchema as TaskConfigSchema4,
6274
5801
  TaskConfigurationError as TaskConfigurationError3,
6275
- Workflow as Workflow19
5802
+ Workflow as Workflow17
6276
5803
  } from "@workglow/task-graph";
6277
5804
  var lambdaTaskConfigSchema = {
6278
5805
  type: "object",
@@ -6283,7 +5810,7 @@ var lambdaTaskConfigSchema = {
6283
5810
  },
6284
5811
  additionalProperties: false
6285
5812
  };
6286
- var inputSchema16 = {
5813
+ var inputSchema15 = {
6287
5814
  type: "object",
6288
5815
  properties: {
6289
5816
  [DATAFLOW_ALL_PORTS]: {
@@ -6293,7 +5820,7 @@ var inputSchema16 = {
6293
5820
  },
6294
5821
  additionalProperties: true
6295
5822
  };
6296
- var outputSchema16 = {
5823
+ var outputSchema15 = {
6297
5824
  type: "object",
6298
5825
  properties: {
6299
5826
  [DATAFLOW_ALL_PORTS]: {
@@ -6304,7 +5831,7 @@ var outputSchema16 = {
6304
5831
  additionalProperties: true
6305
5832
  };
6306
5833
 
6307
- class LambdaTask extends Task15 {
5834
+ class LambdaTask extends Task14 {
6308
5835
  static type = "LambdaTask";
6309
5836
  static title = "Lambda Task";
6310
5837
  static description = "A task that wraps a provided function and its input";
@@ -6314,10 +5841,10 @@ class LambdaTask extends Task15 {
6314
5841
  return lambdaTaskConfigSchema;
6315
5842
  }
6316
5843
  static inputSchema() {
6317
- return inputSchema16;
5844
+ return inputSchema15;
6318
5845
  }
6319
5846
  static outputSchema() {
6320
- return outputSchema16;
5847
+ return outputSchema15;
6321
5848
  }
6322
5849
  constructor(input2 = {}, config = {}) {
6323
5850
  if (!config.execute && !config.executeReactive) {
@@ -6355,15 +5882,15 @@ function lambda(input2, config) {
6355
5882
  const task = new LambdaTask(input2, config);
6356
5883
  return task.run();
6357
5884
  }
6358
- Workflow19.prototype.lambda = CreateWorkflow18(LambdaTask);
5885
+ Workflow17.prototype.lambda = CreateWorkflow16(LambdaTask);
6359
5886
  // src/task/MergeTask.ts
6360
- import { CreateWorkflow as CreateWorkflow19, Task as Task16, Workflow as Workflow20 } from "@workglow/task-graph";
6361
- var inputSchema17 = {
5887
+ import { CreateWorkflow as CreateWorkflow17, Task as Task15, Workflow as Workflow18 } from "@workglow/task-graph";
5888
+ var inputSchema16 = {
6362
5889
  type: "object",
6363
5890
  properties: {},
6364
5891
  additionalProperties: true
6365
5892
  };
6366
- var outputSchema17 = {
5893
+ var outputSchema16 = {
6367
5894
  type: "object",
6368
5895
  properties: {
6369
5896
  output: {
@@ -6375,17 +5902,17 @@ var outputSchema17 = {
6375
5902
  additionalProperties: false
6376
5903
  };
6377
5904
 
6378
- class MergeTask extends Task16 {
5905
+ class MergeTask extends Task15 {
6379
5906
  static type = "MergeTask";
6380
5907
  static category = "Utility";
6381
5908
  static title = "Merge";
6382
5909
  static description = "Merges multiple inputs into a single array output";
6383
5910
  static cacheable = true;
6384
5911
  static inputSchema() {
6385
- return inputSchema17;
5912
+ return inputSchema16;
6386
5913
  }
6387
5914
  static outputSchema() {
6388
- return outputSchema17;
5915
+ return outputSchema16;
6389
5916
  }
6390
5917
  async execute(input2, _context) {
6391
5918
  const keys = Object.keys(input2).sort();
@@ -6399,11 +5926,15 @@ var merge = (input2, config = {}) => {
6399
5926
  const task = new MergeTask({}, config);
6400
5927
  return task.run(input2);
6401
5928
  };
6402
- Workflow20.prototype.merge = CreateWorkflow19(MergeTask);
5929
+ Workflow18.prototype.merge = CreateWorkflow17(MergeTask);
6403
5930
  // src/task/OutputTask.ts
6404
- 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";
6405
5936
 
6406
- class OutputTask extends Task17 {
5937
+ class OutputTask extends Task16 {
6407
5938
  static type = "OutputTask";
6408
5939
  static category = "Flow Control";
6409
5940
  static title = "Output";
@@ -6457,10 +5988,10 @@ class OutputTask extends Task17 {
6457
5988
  yield { type: "finish", data: input2 };
6458
5989
  }
6459
5990
  }
6460
- Workflow21.prototype.output = CreateWorkflow20(OutputTask);
5991
+ Workflow19.prototype.output = CreateWorkflow18(OutputTask);
6461
5992
  // src/task/SplitTask.ts
6462
- import { CreateWorkflow as CreateWorkflow21, Task as Task18, Workflow as Workflow22 } from "@workglow/task-graph";
6463
- var inputSchema18 = {
5993
+ import { CreateWorkflow as CreateWorkflow19, Task as Task17, Workflow as Workflow20 } from "@workglow/task-graph";
5994
+ var inputSchema17 = {
6464
5995
  type: "object",
6465
5996
  properties: {
6466
5997
  input: {
@@ -6470,13 +6001,13 @@ var inputSchema18 = {
6470
6001
  },
6471
6002
  additionalProperties: false
6472
6003
  };
6473
- var outputSchema18 = {
6004
+ var outputSchema17 = {
6474
6005
  type: "object",
6475
6006
  properties: {},
6476
6007
  additionalProperties: true
6477
6008
  };
6478
6009
 
6479
- class SplitTask extends Task18 {
6010
+ class SplitTask extends Task17 {
6480
6011
  static type = "SplitTask";
6481
6012
  static category = "Utility";
6482
6013
  static title = "Split";
@@ -6484,13 +6015,13 @@ class SplitTask extends Task18 {
6484
6015
  static hasDynamicSchemas = true;
6485
6016
  static cacheable = false;
6486
6017
  static inputSchema() {
6487
- return inputSchema18;
6018
+ return inputSchema17;
6488
6019
  }
6489
6020
  static outputSchema() {
6490
- return outputSchema18;
6021
+ return outputSchema17;
6491
6022
  }
6492
6023
  outputSchema() {
6493
- return outputSchema18;
6024
+ return outputSchema17;
6494
6025
  }
6495
6026
  async executeReactive(input2) {
6496
6027
  const inputValue = input2.input;
@@ -6509,15 +6040,15 @@ var split = (input2, config = {}) => {
6509
6040
  const task = new SplitTask({}, config);
6510
6041
  return task.run(input2);
6511
6042
  };
6512
- Workflow22.prototype.split = CreateWorkflow21(SplitTask);
6043
+ Workflow20.prototype.split = CreateWorkflow19(SplitTask);
6513
6044
  // src/task/mcp/McpListTask.ts
6514
- 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";
6515
6046
  import {
6516
6047
  mcpClientFactory,
6517
6048
  mcpServerConfigSchema
6518
6049
  } from "@workglow/util";
6519
6050
  var mcpListTypes = ["tools", "resources", "prompts"];
6520
- var inputSchema19 = {
6051
+ var inputSchema18 = {
6521
6052
  type: "object",
6522
6053
  properties: {
6523
6054
  ...mcpServerConfigSchema,
@@ -6686,7 +6217,7 @@ var outputSchemaAll = {
6686
6217
  additionalProperties: false
6687
6218
  };
6688
6219
 
6689
- class McpListTask extends Task19 {
6220
+ class McpListTask extends Task18 {
6690
6221
  static type = "McpListTask";
6691
6222
  static category = "MCP";
6692
6223
  static title = "MCP List";
@@ -6694,7 +6225,7 @@ class McpListTask extends Task19 {
6694
6225
  static cacheable = false;
6695
6226
  static hasDynamicSchemas = true;
6696
6227
  static inputSchema() {
6697
- return inputSchema19;
6228
+ return inputSchema18;
6698
6229
  }
6699
6230
  static outputSchema() {
6700
6231
  return outputSchemaAll;
@@ -6754,13 +6285,13 @@ class McpListTask extends Task19 {
6754
6285
  var mcpList = async (input2, config = {}) => {
6755
6286
  return new McpListTask({}, config).run(input2);
6756
6287
  };
6757
- Workflow23.prototype.mcpList = CreateWorkflow22(McpListTask);
6288
+ Workflow21.prototype.mcpList = CreateWorkflow20(McpListTask);
6758
6289
  // src/task/mcp/McpPromptGetTask.ts
6759
6290
  import {
6760
- CreateWorkflow as CreateWorkflow23,
6761
- Task as Task20,
6291
+ CreateWorkflow as CreateWorkflow21,
6292
+ Task as Task19,
6762
6293
  TaskConfigSchema as TaskConfigSchema5,
6763
- Workflow as Workflow24
6294
+ Workflow as Workflow22
6764
6295
  } from "@workglow/task-graph";
6765
6296
  import {
6766
6297
  mcpClientFactory as mcpClientFactory2,
@@ -6917,7 +6448,7 @@ var fallbackInputSchema = {
6917
6448
  additionalProperties: false
6918
6449
  };
6919
6450
 
6920
- class McpPromptGetTask extends Task20 {
6451
+ class McpPromptGetTask extends Task19 {
6921
6452
  static type = "McpPromptGetTask";
6922
6453
  static category = "MCP";
6923
6454
  static title = "MCP Get Prompt";
@@ -7001,13 +6532,13 @@ class McpPromptGetTask extends Task20 {
7001
6532
  var mcpPromptGet = async (input2, config) => {
7002
6533
  return new McpPromptGetTask({}, config).run(input2);
7003
6534
  };
7004
- Workflow24.prototype.mcpPromptGet = CreateWorkflow23(McpPromptGetTask);
6535
+ Workflow22.prototype.mcpPromptGet = CreateWorkflow21(McpPromptGetTask);
7005
6536
  // src/task/mcp/McpResourceReadTask.ts
7006
6537
  import {
7007
- CreateWorkflow as CreateWorkflow24,
7008
- Task as Task21,
6538
+ CreateWorkflow as CreateWorkflow22,
6539
+ Task as Task20,
7009
6540
  TaskConfigSchema as TaskConfigSchema6,
7010
- Workflow as Workflow25
6541
+ Workflow as Workflow23
7011
6542
  } from "@workglow/task-graph";
7012
6543
  import {
7013
6544
  mcpClientFactory as mcpClientFactory3,
@@ -7057,12 +6588,12 @@ var contentItemSchema = {
7057
6588
  }
7058
6589
  ]
7059
6590
  };
7060
- var inputSchema20 = {
6591
+ var inputSchema19 = {
7061
6592
  type: "object",
7062
6593
  properties: {},
7063
6594
  additionalProperties: false
7064
6595
  };
7065
- var outputSchema19 = {
6596
+ var outputSchema18 = {
7066
6597
  type: "object",
7067
6598
  properties: {
7068
6599
  contents: {
@@ -7076,7 +6607,7 @@ var outputSchema19 = {
7076
6607
  additionalProperties: false
7077
6608
  };
7078
6609
 
7079
- class McpResourceReadTask extends Task21 {
6610
+ class McpResourceReadTask extends Task20 {
7080
6611
  static type = "McpResourceReadTask";
7081
6612
  static category = "MCP";
7082
6613
  static title = "MCP Read Resource";
@@ -7084,10 +6615,10 @@ class McpResourceReadTask extends Task21 {
7084
6615
  static cacheable = false;
7085
6616
  static customizable = true;
7086
6617
  static inputSchema() {
7087
- return inputSchema20;
6618
+ return inputSchema19;
7088
6619
  }
7089
6620
  static outputSchema() {
7090
- return outputSchema19;
6621
+ return outputSchema18;
7091
6622
  }
7092
6623
  static configSchema() {
7093
6624
  return configSchema3;
@@ -7105,13 +6636,13 @@ class McpResourceReadTask extends Task21 {
7105
6636
  var mcpResourceRead = async (config) => {
7106
6637
  return new McpResourceReadTask({}, config).run({});
7107
6638
  };
7108
- Workflow25.prototype.mcpResourceRead = CreateWorkflow24(McpResourceReadTask);
6639
+ Workflow23.prototype.mcpResourceRead = CreateWorkflow22(McpResourceReadTask);
7109
6640
  // src/task/mcp/McpToolCallTask.ts
7110
6641
  import {
7111
- CreateWorkflow as CreateWorkflow25,
7112
- Task as Task22,
6642
+ CreateWorkflow as CreateWorkflow23,
6643
+ Task as Task21,
7113
6644
  TaskConfigSchema as TaskConfigSchema7,
7114
- Workflow as Workflow26
6645
+ Workflow as Workflow24
7115
6646
  } from "@workglow/task-graph";
7116
6647
  import {
7117
6648
  mcpClientFactory as mcpClientFactory4,
@@ -7260,7 +6791,7 @@ var fallbackInputSchema2 = {
7260
6791
  additionalProperties: true
7261
6792
  };
7262
6793
 
7263
- class McpToolCallTask extends Task22 {
6794
+ class McpToolCallTask extends Task21 {
7264
6795
  static type = "McpToolCallTask";
7265
6796
  static category = "MCP";
7266
6797
  static title = "MCP Call Tool";
@@ -7359,10 +6890,10 @@ class McpToolCallTask extends Task22 {
7359
6890
  var mcpToolCall = async (input2, config) => {
7360
6891
  return new McpToolCallTask({}, config).run(input2);
7361
6892
  };
7362
- Workflow26.prototype.mcpToolCall = CreateWorkflow25(McpToolCallTask);
6893
+ Workflow24.prototype.mcpToolCall = CreateWorkflow23(McpToolCallTask);
7363
6894
  // src/task/scalar/ScalarAbsTask.ts
7364
- import { CreateWorkflow as CreateWorkflow26, Task as Task23, Workflow as Workflow27 } from "@workglow/task-graph";
7365
- var inputSchema21 = {
6895
+ import { CreateWorkflow as CreateWorkflow24, Task as Task22, Workflow as Workflow25 } from "@workglow/task-graph";
6896
+ var inputSchema20 = {
7366
6897
  type: "object",
7367
6898
  properties: {
7368
6899
  value: {
@@ -7374,7 +6905,7 @@ var inputSchema21 = {
7374
6905
  required: ["value"],
7375
6906
  additionalProperties: false
7376
6907
  };
7377
- var outputSchema20 = {
6908
+ var outputSchema19 = {
7378
6909
  type: "object",
7379
6910
  properties: {
7380
6911
  result: {
@@ -7387,25 +6918,25 @@ var outputSchema20 = {
7387
6918
  additionalProperties: false
7388
6919
  };
7389
6920
 
7390
- class ScalarAbsTask extends Task23 {
6921
+ class ScalarAbsTask extends Task22 {
7391
6922
  static type = "ScalarAbsTask";
7392
6923
  static category = "Math";
7393
6924
  static title = "Abs";
7394
6925
  static description = "Returns the absolute value of a number";
7395
6926
  static inputSchema() {
7396
- return inputSchema21;
6927
+ return inputSchema20;
7397
6928
  }
7398
6929
  static outputSchema() {
7399
- return outputSchema20;
6930
+ return outputSchema19;
7400
6931
  }
7401
6932
  async execute(input2, _context) {
7402
6933
  return { result: Math.abs(input2.value) };
7403
6934
  }
7404
6935
  }
7405
- Workflow27.prototype.scalarAbs = CreateWorkflow26(ScalarAbsTask);
6936
+ Workflow25.prototype.scalarAbs = CreateWorkflow24(ScalarAbsTask);
7406
6937
  // src/task/scalar/ScalarCeilTask.ts
7407
- import { CreateWorkflow as CreateWorkflow27, Task as Task24, Workflow as Workflow28 } from "@workglow/task-graph";
7408
- var inputSchema22 = {
6938
+ import { CreateWorkflow as CreateWorkflow25, Task as Task23, Workflow as Workflow26 } from "@workglow/task-graph";
6939
+ var inputSchema21 = {
7409
6940
  type: "object",
7410
6941
  properties: {
7411
6942
  value: {
@@ -7417,7 +6948,7 @@ var inputSchema22 = {
7417
6948
  required: ["value"],
7418
6949
  additionalProperties: false
7419
6950
  };
7420
- var outputSchema21 = {
6951
+ var outputSchema20 = {
7421
6952
  type: "object",
7422
6953
  properties: {
7423
6954
  result: {
@@ -7430,25 +6961,25 @@ var outputSchema21 = {
7430
6961
  additionalProperties: false
7431
6962
  };
7432
6963
 
7433
- class ScalarCeilTask extends Task24 {
6964
+ class ScalarCeilTask extends Task23 {
7434
6965
  static type = "ScalarCeilTask";
7435
6966
  static category = "Math";
7436
6967
  static title = "Ceil";
7437
6968
  static description = "Returns the smallest integer greater than or equal to a number";
7438
6969
  static inputSchema() {
7439
- return inputSchema22;
6970
+ return inputSchema21;
7440
6971
  }
7441
6972
  static outputSchema() {
7442
- return outputSchema21;
6973
+ return outputSchema20;
7443
6974
  }
7444
6975
  async execute(input2, _context) {
7445
6976
  return { result: Math.ceil(input2.value) };
7446
6977
  }
7447
6978
  }
7448
- Workflow28.prototype.scalarCeil = CreateWorkflow27(ScalarCeilTask);
6979
+ Workflow26.prototype.scalarCeil = CreateWorkflow25(ScalarCeilTask);
7449
6980
  // src/task/scalar/ScalarFloorTask.ts
7450
- import { CreateWorkflow as CreateWorkflow28, Task as Task25, Workflow as Workflow29 } from "@workglow/task-graph";
7451
- var inputSchema23 = {
6981
+ import { CreateWorkflow as CreateWorkflow26, Task as Task24, Workflow as Workflow27 } from "@workglow/task-graph";
6982
+ var inputSchema22 = {
7452
6983
  type: "object",
7453
6984
  properties: {
7454
6985
  value: {
@@ -7460,7 +6991,7 @@ var inputSchema23 = {
7460
6991
  required: ["value"],
7461
6992
  additionalProperties: false
7462
6993
  };
7463
- var outputSchema22 = {
6994
+ var outputSchema21 = {
7464
6995
  type: "object",
7465
6996
  properties: {
7466
6997
  result: {
@@ -7473,25 +7004,25 @@ var outputSchema22 = {
7473
7004
  additionalProperties: false
7474
7005
  };
7475
7006
 
7476
- class ScalarFloorTask extends Task25 {
7007
+ class ScalarFloorTask extends Task24 {
7477
7008
  static type = "ScalarFloorTask";
7478
7009
  static category = "Math";
7479
7010
  static title = "Floor";
7480
7011
  static description = "Returns the largest integer less than or equal to a number";
7481
7012
  static inputSchema() {
7482
- return inputSchema23;
7013
+ return inputSchema22;
7483
7014
  }
7484
7015
  static outputSchema() {
7485
- return outputSchema22;
7016
+ return outputSchema21;
7486
7017
  }
7487
7018
  async execute(input2, _context) {
7488
7019
  return { result: Math.floor(input2.value) };
7489
7020
  }
7490
7021
  }
7491
- Workflow29.prototype.scalarFloor = CreateWorkflow28(ScalarFloorTask);
7022
+ Workflow27.prototype.scalarFloor = CreateWorkflow26(ScalarFloorTask);
7492
7023
  // src/task/scalar/ScalarMaxTask.ts
7493
- import { CreateWorkflow as CreateWorkflow29, Task as Task26, Workflow as Workflow30 } from "@workglow/task-graph";
7494
- var inputSchema24 = {
7024
+ import { CreateWorkflow as CreateWorkflow27, Task as Task25, Workflow as Workflow28 } from "@workglow/task-graph";
7025
+ var inputSchema23 = {
7495
7026
  type: "object",
7496
7027
  properties: {
7497
7028
  values: {
@@ -7504,7 +7035,7 @@ var inputSchema24 = {
7504
7035
  required: ["values"],
7505
7036
  additionalProperties: false
7506
7037
  };
7507
- var outputSchema23 = {
7038
+ var outputSchema22 = {
7508
7039
  type: "object",
7509
7040
  properties: {
7510
7041
  result: {
@@ -7517,25 +7048,25 @@ var outputSchema23 = {
7517
7048
  additionalProperties: false
7518
7049
  };
7519
7050
 
7520
- class ScalarMaxTask extends Task26 {
7051
+ class ScalarMaxTask extends Task25 {
7521
7052
  static type = "ScalarMaxTask";
7522
7053
  static category = "Math";
7523
7054
  static title = "Max";
7524
7055
  static description = "Returns the largest of the given numbers";
7525
7056
  static inputSchema() {
7526
- return inputSchema24;
7057
+ return inputSchema23;
7527
7058
  }
7528
7059
  static outputSchema() {
7529
- return outputSchema23;
7060
+ return outputSchema22;
7530
7061
  }
7531
7062
  async execute(input2, _context) {
7532
7063
  return { result: Math.max(...input2.values) };
7533
7064
  }
7534
7065
  }
7535
- Workflow30.prototype.scalarMax = CreateWorkflow29(ScalarMaxTask);
7066
+ Workflow28.prototype.scalarMax = CreateWorkflow27(ScalarMaxTask);
7536
7067
  // src/task/scalar/ScalarMinTask.ts
7537
- import { CreateWorkflow as CreateWorkflow30, Task as Task27, Workflow as Workflow31 } from "@workglow/task-graph";
7538
- var inputSchema25 = {
7068
+ import { CreateWorkflow as CreateWorkflow28, Task as Task26, Workflow as Workflow29 } from "@workglow/task-graph";
7069
+ var inputSchema24 = {
7539
7070
  type: "object",
7540
7071
  properties: {
7541
7072
  values: {
@@ -7548,7 +7079,7 @@ var inputSchema25 = {
7548
7079
  required: ["values"],
7549
7080
  additionalProperties: false
7550
7081
  };
7551
- var outputSchema24 = {
7082
+ var outputSchema23 = {
7552
7083
  type: "object",
7553
7084
  properties: {
7554
7085
  result: {
@@ -7561,25 +7092,25 @@ var outputSchema24 = {
7561
7092
  additionalProperties: false
7562
7093
  };
7563
7094
 
7564
- class ScalarMinTask extends Task27 {
7095
+ class ScalarMinTask extends Task26 {
7565
7096
  static type = "ScalarMinTask";
7566
7097
  static category = "Math";
7567
7098
  static title = "Min";
7568
7099
  static description = "Returns the smallest of the given numbers";
7569
7100
  static inputSchema() {
7570
- return inputSchema25;
7101
+ return inputSchema24;
7571
7102
  }
7572
7103
  static outputSchema() {
7573
- return outputSchema24;
7104
+ return outputSchema23;
7574
7105
  }
7575
7106
  async execute(input2, _context) {
7576
7107
  return { result: Math.min(...input2.values) };
7577
7108
  }
7578
7109
  }
7579
- Workflow31.prototype.scalarMin = CreateWorkflow30(ScalarMinTask);
7110
+ Workflow29.prototype.scalarMin = CreateWorkflow28(ScalarMinTask);
7580
7111
  // src/task/scalar/ScalarRoundTask.ts
7581
- import { CreateWorkflow as CreateWorkflow31, Task as Task28, Workflow as Workflow32 } from "@workglow/task-graph";
7582
- var inputSchema26 = {
7112
+ import { CreateWorkflow as CreateWorkflow29, Task as Task27, Workflow as Workflow30 } from "@workglow/task-graph";
7113
+ var inputSchema25 = {
7583
7114
  type: "object",
7584
7115
  properties: {
7585
7116
  value: {
@@ -7591,7 +7122,7 @@ var inputSchema26 = {
7591
7122
  required: ["value"],
7592
7123
  additionalProperties: false
7593
7124
  };
7594
- var outputSchema25 = {
7125
+ var outputSchema24 = {
7595
7126
  type: "object",
7596
7127
  properties: {
7597
7128
  result: {
@@ -7604,25 +7135,25 @@ var outputSchema25 = {
7604
7135
  additionalProperties: false
7605
7136
  };
7606
7137
 
7607
- class ScalarRoundTask extends Task28 {
7138
+ class ScalarRoundTask extends Task27 {
7608
7139
  static type = "ScalarRoundTask";
7609
7140
  static category = "Math";
7610
7141
  static title = "Round";
7611
7142
  static description = "Returns the value of a number rounded to the nearest integer";
7612
7143
  static inputSchema() {
7613
- return inputSchema26;
7144
+ return inputSchema25;
7614
7145
  }
7615
7146
  static outputSchema() {
7616
- return outputSchema25;
7147
+ return outputSchema24;
7617
7148
  }
7618
7149
  async execute(input2, _context) {
7619
7150
  return { result: Math.round(input2.value) };
7620
7151
  }
7621
7152
  }
7622
- Workflow32.prototype.scalarRound = CreateWorkflow31(ScalarRoundTask);
7153
+ Workflow30.prototype.scalarRound = CreateWorkflow29(ScalarRoundTask);
7623
7154
  // src/task/scalar/ScalarTruncTask.ts
7624
- import { CreateWorkflow as CreateWorkflow32, Task as Task29, Workflow as Workflow33 } from "@workglow/task-graph";
7625
- var inputSchema27 = {
7155
+ import { CreateWorkflow as CreateWorkflow30, Task as Task28, Workflow as Workflow31 } from "@workglow/task-graph";
7156
+ var inputSchema26 = {
7626
7157
  type: "object",
7627
7158
  properties: {
7628
7159
  value: {
@@ -7634,7 +7165,7 @@ var inputSchema27 = {
7634
7165
  required: ["value"],
7635
7166
  additionalProperties: false
7636
7167
  };
7637
- var outputSchema26 = {
7168
+ var outputSchema25 = {
7638
7169
  type: "object",
7639
7170
  properties: {
7640
7171
  result: {
@@ -7647,28 +7178,28 @@ var outputSchema26 = {
7647
7178
  additionalProperties: false
7648
7179
  };
7649
7180
 
7650
- class ScalarTruncTask extends Task29 {
7181
+ class ScalarTruncTask extends Task28 {
7651
7182
  static type = "ScalarTruncTask";
7652
7183
  static category = "Math";
7653
7184
  static title = "Truncate";
7654
7185
  static description = "Returns the integer part of a number by removing fractional digits";
7655
7186
  static inputSchema() {
7656
- return inputSchema27;
7187
+ return inputSchema26;
7657
7188
  }
7658
7189
  static outputSchema() {
7659
- return outputSchema26;
7190
+ return outputSchema25;
7660
7191
  }
7661
7192
  async execute(input2, _context) {
7662
7193
  return { result: Math.trunc(input2.value) };
7663
7194
  }
7664
7195
  }
7665
- Workflow33.prototype.scalarTrunc = CreateWorkflow32(ScalarTruncTask);
7196
+ Workflow31.prototype.scalarTrunc = CreateWorkflow30(ScalarTruncTask);
7666
7197
  // src/task/vector/VectorDistanceTask.ts
7667
- 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";
7668
7199
  import {
7669
7200
  TypedArraySchema as TypedArraySchema5
7670
7201
  } from "@workglow/util";
7671
- var inputSchema28 = {
7202
+ var inputSchema27 = {
7672
7203
  type: "object",
7673
7204
  properties: {
7674
7205
  vectors: {
@@ -7684,7 +7215,7 @@ var inputSchema28 = {
7684
7215
  required: ["vectors"],
7685
7216
  additionalProperties: false
7686
7217
  };
7687
- var outputSchema27 = {
7218
+ var outputSchema26 = {
7688
7219
  type: "object",
7689
7220
  properties: {
7690
7221
  result: {
@@ -7697,16 +7228,16 @@ var outputSchema27 = {
7697
7228
  additionalProperties: false
7698
7229
  };
7699
7230
 
7700
- class VectorDistanceTask extends Task30 {
7231
+ class VectorDistanceTask extends Task29 {
7701
7232
  static type = "VectorDistanceTask";
7702
7233
  static category = "Vector";
7703
7234
  static title = "Distance";
7704
7235
  static description = "Returns the Euclidean distance between the first two vectors";
7705
7236
  static inputSchema() {
7706
- return inputSchema28;
7237
+ return inputSchema27;
7707
7238
  }
7708
7239
  static outputSchema() {
7709
- return outputSchema27;
7240
+ return outputSchema26;
7710
7241
  }
7711
7242
  async execute(input2, _context) {
7712
7243
  const { vectors } = input2;
@@ -7724,13 +7255,13 @@ class VectorDistanceTask extends Task30 {
7724
7255
  return { result: Math.sqrt(sumPrecise(diffs)) };
7725
7256
  }
7726
7257
  }
7727
- Workflow34.prototype.vectorDistance = CreateWorkflow33(VectorDistanceTask);
7258
+ Workflow32.prototype.vectorDistance = CreateWorkflow31(VectorDistanceTask);
7728
7259
  // src/task/vector/VectorDotProductTask.ts
7729
- 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";
7730
7261
  import {
7731
7262
  TypedArraySchema as TypedArraySchema6
7732
7263
  } from "@workglow/util";
7733
- var inputSchema29 = {
7264
+ var inputSchema28 = {
7734
7265
  type: "object",
7735
7266
  properties: {
7736
7267
  vectors: {
@@ -7746,7 +7277,7 @@ var inputSchema29 = {
7746
7277
  required: ["vectors"],
7747
7278
  additionalProperties: false
7748
7279
  };
7749
- var outputSchema28 = {
7280
+ var outputSchema27 = {
7750
7281
  type: "object",
7751
7282
  properties: {
7752
7283
  result: {
@@ -7759,16 +7290,16 @@ var outputSchema28 = {
7759
7290
  additionalProperties: false
7760
7291
  };
7761
7292
 
7762
- class VectorDotProductTask extends Task31 {
7293
+ class VectorDotProductTask extends Task30 {
7763
7294
  static type = "VectorDotProductTask";
7764
7295
  static category = "Vector";
7765
7296
  static title = "Dot Product";
7766
7297
  static description = "Returns the dot (inner) product of the first two vectors";
7767
7298
  static inputSchema() {
7768
- return inputSchema29;
7299
+ return inputSchema28;
7769
7300
  }
7770
7301
  static outputSchema() {
7771
- return outputSchema28;
7302
+ return outputSchema27;
7772
7303
  }
7773
7304
  async execute(input2, _context) {
7774
7305
  const { vectors } = input2;
@@ -7783,14 +7314,14 @@ class VectorDotProductTask extends Task31 {
7783
7314
  return { result: sumPrecise(products) };
7784
7315
  }
7785
7316
  }
7786
- Workflow35.prototype.vectorDotProduct = CreateWorkflow34(VectorDotProductTask);
7317
+ Workflow33.prototype.vectorDotProduct = CreateWorkflow32(VectorDotProductTask);
7787
7318
  // src/task/vector/VectorNormalizeTask.ts
7788
- 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";
7789
7320
  import {
7790
7321
  TypedArraySchema as TypedArraySchema7,
7791
7322
  normalize
7792
7323
  } from "@workglow/util";
7793
- var inputSchema30 = {
7324
+ var inputSchema29 = {
7794
7325
  type: "object",
7795
7326
  properties: {
7796
7327
  vector: TypedArraySchema7({
@@ -7801,7 +7332,7 @@ var inputSchema30 = {
7801
7332
  required: ["vector"],
7802
7333
  additionalProperties: false
7803
7334
  };
7804
- var outputSchema29 = {
7335
+ var outputSchema28 = {
7805
7336
  type: "object",
7806
7337
  properties: {
7807
7338
  result: TypedArraySchema7({
@@ -7813,29 +7344,29 @@ var outputSchema29 = {
7813
7344
  additionalProperties: false
7814
7345
  };
7815
7346
 
7816
- class VectorNormalizeTask extends Task32 {
7347
+ class VectorNormalizeTask extends Task31 {
7817
7348
  static type = "VectorNormalizeTask";
7818
7349
  static category = "Vector";
7819
7350
  static title = "Normalize";
7820
7351
  static description = "Returns the L2-normalized (unit length) vector";
7821
7352
  static inputSchema() {
7822
- return inputSchema30;
7353
+ return inputSchema29;
7823
7354
  }
7824
7355
  static outputSchema() {
7825
- return outputSchema29;
7356
+ return outputSchema28;
7826
7357
  }
7827
7358
  async execute(input2, _context) {
7828
7359
  return { result: normalize(input2.vector) };
7829
7360
  }
7830
7361
  }
7831
- Workflow36.prototype.vectorNormalize = CreateWorkflow35(VectorNormalizeTask);
7362
+ Workflow34.prototype.vectorNormalize = CreateWorkflow33(VectorNormalizeTask);
7832
7363
  // src/task/vector/VectorScaleTask.ts
7833
- 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";
7834
7365
  import {
7835
7366
  createTypedArrayFrom as createTypedArrayFrom5,
7836
7367
  TypedArraySchema as TypedArraySchema8
7837
7368
  } from "@workglow/util";
7838
- var inputSchema31 = {
7369
+ var inputSchema30 = {
7839
7370
  type: "object",
7840
7371
  properties: {
7841
7372
  vector: TypedArraySchema8({
@@ -7851,7 +7382,7 @@ var inputSchema31 = {
7851
7382
  required: ["vector", "scalar"],
7852
7383
  additionalProperties: false
7853
7384
  };
7854
- var outputSchema30 = {
7385
+ var outputSchema29 = {
7855
7386
  type: "object",
7856
7387
  properties: {
7857
7388
  result: TypedArraySchema8({
@@ -7863,16 +7394,16 @@ var outputSchema30 = {
7863
7394
  additionalProperties: false
7864
7395
  };
7865
7396
 
7866
- class VectorScaleTask extends Task33 {
7397
+ class VectorScaleTask extends Task32 {
7867
7398
  static type = "VectorScaleTask";
7868
7399
  static category = "Vector";
7869
7400
  static title = "Scale";
7870
7401
  static description = "Multiplies each element of a vector by a scalar";
7871
7402
  static inputSchema() {
7872
- return inputSchema31;
7403
+ return inputSchema30;
7873
7404
  }
7874
7405
  static outputSchema() {
7875
- return outputSchema30;
7406
+ return outputSchema29;
7876
7407
  }
7877
7408
  async execute(input2, _context) {
7878
7409
  const { vector, scalar } = input2;
@@ -7880,7 +7411,7 @@ class VectorScaleTask extends Task33 {
7880
7411
  return { result: createTypedArrayFrom5([vector], values) };
7881
7412
  }
7882
7413
  }
7883
- Workflow37.prototype.vectorScale = CreateWorkflow36(VectorScaleTask);
7414
+ Workflow35.prototype.vectorScale = CreateWorkflow34(VectorScaleTask);
7884
7415
 
7885
7416
  // src/common.ts
7886
7417
  import { TaskRegistry } from "@workglow/task-graph";
@@ -7925,11 +7456,656 @@ var registerCommonTasks = () => {
7925
7456
  return tasks;
7926
7457
  };
7927
7458
 
7928
- // src/node.ts
7929
- [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 "node: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/node.ts
8101
+ var registerCommonTasks2 = () => {
8102
+ const tasks = registerCommonTasks();
8103
+ TaskRegistry2.registerTask(FileLoaderTask2);
8104
+ return [...tasks, FileLoaderTask2];
8105
+ };
7930
8106
  export {
7931
8107
  split,
7932
- registerCommonTasks,
8108
+ registerCommonTasks2 as registerCommonTasks,
7933
8109
  process,
7934
8110
  merge,
7935
8111
  mcpToolCall,
@@ -7984,4 +8160,4 @@ export {
7984
8160
  ArrayTask
7985
8161
  };
7986
8162
 
7987
- //# debugId=017044E656C85CB364756E2164756E21
8163
+ //# debugId=A6B33698A9E8527664756E2164756E21