@workglow/tasks 0.2.8 → 0.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.d.ts CHANGED
@@ -12,5 +12,5 @@ export * from "./util/McpAuthTypes";
12
12
  export * from "./util/McpClientUtil";
13
13
  export * from "./util/McpTaskDeps";
14
14
  import { FileLoaderTask } from "./task/FileLoaderTask";
15
- export declare const registerCommonTasks: () => (typeof import("./common").ScalarAddTask | typeof import("./common").ScalarDivideTask | typeof import("./common").ScalarMultiplyTask | typeof import("./common").ScalarSubtractTask | typeof import("./common").ScalarSumTask | typeof import("./common").VectorDivideTask | typeof import("./common").VectorMultiplyTask | typeof import("./common").VectorSubtractTask | typeof import("./common").VectorSumTask | typeof import("./common").DateFormatTask | typeof import("./common").DebugLogTask | typeof import("./common").DelayTask | typeof import("./common").FetchUrlTask | typeof import("./common").HumanInputTask | typeof import("./common").HumanApprovalTask | typeof import("./common").ImageBlurTask | typeof import("./common").ImageBorderTask | typeof import("./common").ImageBrightnessTask | typeof import("./common").ImageContrastTask | typeof import("./common").ImageCropTask | typeof import("./common").ImageFlipTask | typeof import("./common").ImageGrayscaleTask | typeof import("./common").ImageInvertTask | typeof import("./common").ImagePixelateTask | typeof import("./common").ImagePosterizeTask | typeof import("./common").ImageResizeTask | typeof import("./common").ImageRotateTask | typeof import("./common").ImageSepiaTask | typeof import("./common").ImageTextTask | typeof import("./common").ImageThresholdTask | typeof import("./common").ImageTintTask | typeof import("./common").ImageTransparencyTask | typeof import("./common").ImageWatermarkTask | typeof import("./common").InputTask | typeof import("./common").JavaScriptTask | typeof import("./common").JsonPathTask | typeof import("./common").JsonTask | typeof import("./common").LambdaTask | typeof import("./common").McpListTask | typeof import("./common").McpPromptGetTask | typeof import("./common").McpResourceReadTask | typeof import("./common").McpSearchTask | typeof import("./common").McpToolCallTask | typeof import("./common").MergeTask | typeof import("./common").RegexTask | typeof import("./common").ScalarAbsTask | typeof import("./common").ScalarCeilTask | typeof import("./common").ScalarFloorTask | typeof import("./common").ScalarMaxTask | typeof import("./common").ScalarMinTask | typeof import("./common").ScalarRoundTask | typeof import("./common").ScalarTruncTask | typeof import("./common").SplitTask | typeof import("./common").StringConcatTask | typeof import("./common").StringIncludesTask | typeof import("./common").StringJoinTask | typeof import("./common").StringLengthTask | typeof import("./common").StringLowerCaseTask | typeof import("./common").StringReplaceTask | typeof import("./common").StringSliceTask | typeof import("./common").StringTemplateTask | typeof import("./common").StringTrimTask | typeof import("./common").StringUpperCaseTask | typeof import("./common").TemplateTask | typeof import("./common").VectorDistanceTask | typeof import("./common").VectorDotProductTask | typeof import("./common").VectorNormalizeTask | typeof import("./common").VectorScaleTask | typeof FileLoaderTask)[];
15
+ export declare const registerCommonTasks: () => (typeof import("./common").ScalarAddTask | typeof import("./common").ScalarDivideTask | typeof import("./common").ScalarMultiplyTask | typeof import("./common").ScalarSubtractTask | typeof import("./common").ScalarSumTask | typeof import("./common").VectorDivideTask | typeof import("./common").VectorMultiplyTask | typeof import("./common").VectorSubtractTask | typeof import("./common").VectorSumTask | typeof import("./common").DateFormatTask | typeof import("./common").DebugLogTask | typeof import("./common").DelayTask | typeof import("./common").FetchUrlTask | typeof import("./common").HumanApprovalTask | typeof import("./common").HumanInputTask | typeof import("./common").ImageBlurTask | typeof import("./common").ImageBorderTask | typeof import("./common").ImageBrightnessTask | typeof import("./common").ImageContrastTask | typeof import("./common").ImageCropTask | typeof import("./common").ImageFlipTask | typeof import("./common").ImageGrayscaleTask | typeof import("./common").ImageInvertTask | typeof import("./common").ImagePixelateTask | typeof import("./common").ImagePosterizeTask | typeof import("./common").ImageResizeTask | typeof import("./common").ImageRotateTask | typeof import("./common").ImageSepiaTask | typeof import("./common").ImageTextTask | typeof import("./common").ImageThresholdTask | typeof import("./common").ImageTintTask | typeof import("./common").ImageTransparencyTask | typeof import("./common").ImageWatermarkTask | typeof import("./common").InputTask | typeof import("./common").JavaScriptTask | typeof import("./common").JsonPathTask | typeof import("./common").JsonTask | typeof import("./common").LambdaTask | typeof import("./common").McpListTask | typeof import("./common").McpPromptGetTask | typeof import("./common").McpResourceReadTask | typeof import("./common").McpSearchTask | typeof import("./common").McpToolCallTask | typeof import("./common").MergeTask | typeof import("./common").RegexTask | typeof import("./common").ScalarAbsTask | typeof import("./common").ScalarCeilTask | typeof import("./common").ScalarFloorTask | typeof import("./common").ScalarMaxTask | typeof import("./common").ScalarMinTask | typeof import("./common").ScalarRoundTask | typeof import("./common").ScalarTruncTask | typeof import("./common").SplitTask | typeof import("./common").StringConcatTask | typeof import("./common").StringIncludesTask | typeof import("./common").StringJoinTask | typeof import("./common").StringLengthTask | typeof import("./common").StringLowerCaseTask | typeof import("./common").StringReplaceTask | typeof import("./common").StringSliceTask | typeof import("./common").StringTemplateTask | typeof import("./common").StringTrimTask | typeof import("./common").StringUpperCaseTask | typeof import("./common").TemplateTask | typeof import("./common").VectorDistanceTask | typeof import("./common").VectorDotProductTask | typeof import("./common").VectorNormalizeTask | typeof import("./common").VectorScaleTask | typeof FileLoaderTask)[];
16
16
  //# sourceMappingURL=browser.d.ts.map
package/dist/browser.js CHANGED
@@ -5427,30 +5427,170 @@ var fetchUrl = async (input, config = {}) => {
5427
5427
  };
5428
5428
  Workflow14.prototype.fetch = CreateWorkflow13(FetchUrlTask);
5429
5429
  // src/task/HumanApprovalTask.ts
5430
+ import {
5431
+ CreateWorkflow as CreateWorkflow14,
5432
+ Task as Task40,
5433
+ TaskAbortedError as TaskAbortedError2,
5434
+ TaskConfigSchema as TaskConfigSchema30,
5435
+ Workflow as Workflow15
5436
+ } from "@workglow/task-graph";
5437
+ import { uuid4 as uuid43, resolveHumanConnector } from "@workglow/util";
5438
+ var humanApprovalConfigSchema = {
5439
+ type: "object",
5440
+ properties: {
5441
+ ...TaskConfigSchema30["properties"],
5442
+ targetHumanId: {
5443
+ type: "string",
5444
+ title: "Target Human",
5445
+ description: "Identifier of the human to ask for approval",
5446
+ default: "default"
5447
+ },
5448
+ message: {
5449
+ type: "string",
5450
+ title: "Message",
5451
+ description: "Explanatory message shown to the approver",
5452
+ "x-ui-editor": "textarea"
5453
+ },
5454
+ metadata: {
5455
+ type: "object",
5456
+ additionalProperties: true,
5457
+ "x-ui-hidden": true
5458
+ }
5459
+ },
5460
+ additionalProperties: false
5461
+ };
5462
+ var inputSchema40 = {
5463
+ type: "object",
5464
+ properties: {
5465
+ prompt: {
5466
+ type: "string",
5467
+ title: "Prompt",
5468
+ description: "Dynamic prompt text merged into the approval message"
5469
+ },
5470
+ context: {
5471
+ type: "object",
5472
+ additionalProperties: true,
5473
+ title: "Context",
5474
+ description: "Dynamic context data merged into the request metadata",
5475
+ "x-ui-hidden": true
5476
+ }
5477
+ },
5478
+ additionalProperties: false
5479
+ };
5480
+ var approvalRequestedSchema = {
5481
+ type: "object",
5482
+ properties: {
5483
+ approved: {
5484
+ type: "boolean",
5485
+ title: "Approved",
5486
+ description: "Whether the request is approved"
5487
+ },
5488
+ reason: {
5489
+ type: "string",
5490
+ title: "Reason",
5491
+ description: "Optional explanation for the decision"
5492
+ }
5493
+ },
5494
+ required: ["approved"]
5495
+ };
5496
+ var approvalOutputSchema = {
5497
+ type: "object",
5498
+ properties: {
5499
+ action: {
5500
+ type: "string",
5501
+ title: "Action",
5502
+ description: "The human's action: accept, decline, or cancel",
5503
+ enum: ["accept", "decline", "cancel"]
5504
+ },
5505
+ approved: {
5506
+ type: "boolean",
5507
+ title: "Approved",
5508
+ description: "Whether the human approved the request"
5509
+ },
5510
+ reason: {
5511
+ type: "string",
5512
+ title: "Reason",
5513
+ description: "Optional explanation for the decision"
5514
+ }
5515
+ },
5516
+ required: ["action", "approved"],
5517
+ additionalProperties: false
5518
+ };
5519
+
5520
+ class HumanApprovalTask extends Task40 {
5521
+ static type = "HumanApprovalTask";
5522
+ static category = "Flow Control";
5523
+ static title = "Human Approval";
5524
+ static description = "Pauses execution to request approval from a human (approve/deny) via MCP elicitation";
5525
+ static cacheable = false;
5526
+ static configSchema() {
5527
+ return humanApprovalConfigSchema;
5528
+ }
5529
+ static inputSchema() {
5530
+ return inputSchema40;
5531
+ }
5532
+ static outputSchema() {
5533
+ return approvalOutputSchema;
5534
+ }
5535
+ async execute(input, context) {
5536
+ const connector = resolveHumanConnector(context);
5537
+ const requestId = uuid43();
5538
+ const message = input.prompt ? this.config.message ? `${this.config.message}
5539
+
5540
+ ${input.prompt}` : input.prompt : this.config.message ?? "";
5541
+ const request = {
5542
+ requestId,
5543
+ targetHumanId: this.config.targetHumanId ?? "default",
5544
+ kind: "elicit",
5545
+ message,
5546
+ contentSchema: approvalRequestedSchema,
5547
+ contentData: undefined,
5548
+ expectsResponse: true,
5549
+ mode: "single",
5550
+ metadata: input.context ? { ...this.config.metadata, ...input.context } : this.config.metadata
5551
+ };
5552
+ if (context.signal.aborted) {
5553
+ throw new TaskAbortedError2("Task aborted before requesting human approval");
5554
+ }
5555
+ let response;
5556
+ try {
5557
+ response = await connector.send(request, context.signal);
5558
+ } catch (err) {
5559
+ if (context.signal.aborted) {
5560
+ throw new TaskAbortedError2("Task aborted during human approval");
5561
+ }
5562
+ throw err;
5563
+ }
5564
+ if (response.action === "accept" && response.content) {
5565
+ return {
5566
+ action: response.action,
5567
+ approved: response.content.approved === true,
5568
+ reason: response.content.reason
5569
+ };
5570
+ }
5571
+ return {
5572
+ action: response.action,
5573
+ approved: false,
5574
+ ...response.content?.reason !== undefined ? { reason: response.content.reason } : {}
5575
+ };
5576
+ }
5577
+ }
5578
+ Workflow15.prototype.humanApproval = CreateWorkflow14(HumanApprovalTask);
5579
+ // src/task/HumanInputTask.ts
5430
5580
  import {
5431
5581
  CreateWorkflow as CreateWorkflow15,
5432
5582
  Task as Task41,
5433
5583
  TaskAbortedError as TaskAbortedError3,
5434
5584
  TaskConfigSchema as TaskConfigSchema31,
5585
+ TaskConfigurationError as TaskConfigurationError2,
5435
5586
  Workflow as Workflow16
5436
5587
  } from "@workglow/task-graph";
5437
5588
  import { uuid4 as uuid44 } from "@workglow/util";
5438
-
5439
- // src/task/HumanInputTask.ts
5440
- import {
5441
- CreateWorkflow as CreateWorkflow14,
5442
- Task as Task40,
5443
- TaskAbortedError as TaskAbortedError2,
5444
- TaskConfigSchema as TaskConfigSchema30,
5445
- TaskConfigurationError as TaskConfigurationError2,
5446
- Workflow as Workflow15
5447
- } from "@workglow/task-graph";
5448
- import { createServiceToken as createServiceToken5, uuid4 as uuid43 } from "@workglow/util";
5449
- var HUMAN_CONNECTOR = createServiceToken5("HUMAN_CONNECTOR");
5589
+ import { resolveHumanConnector as resolveHumanConnector2 } from "@workglow/util";
5450
5590
  var humanInputTaskConfigSchema = {
5451
5591
  type: "object",
5452
5592
  properties: {
5453
- ...TaskConfigSchema30["properties"],
5593
+ ...TaskConfigSchema31["properties"],
5454
5594
  targetHumanId: {
5455
5595
  type: "string",
5456
5596
  title: "Target Human",
@@ -5531,7 +5671,7 @@ var defaultOutputSchema = {
5531
5671
  additionalProperties: true
5532
5672
  };
5533
5673
 
5534
- class HumanInputTask extends Task40 {
5674
+ class HumanInputTask extends Task41 {
5535
5675
  static type = "HumanInputTask";
5536
5676
  static category = "Flow Control";
5537
5677
  static title = "Human Input";
@@ -5569,10 +5709,10 @@ class HumanInputTask extends Task40 {
5569
5709
  return this.constructor.outputSchema();
5570
5710
  }
5571
5711
  async execute(input, context) {
5572
- const connector = resolveHumanConnector(context);
5712
+ const connector = resolveHumanConnector2(context);
5573
5713
  const kind = this.config.kind ?? "elicit";
5574
5714
  const mode = this.config.mode ?? "single";
5575
- const requestId = uuid43();
5715
+ const requestId = uuid44();
5576
5716
  const message = input.prompt ? this.config.message ? `${this.config.message}
5577
5717
 
5578
5718
  ${input.prompt}` : input.prompt : this.config.message ?? "";
@@ -5593,14 +5733,14 @@ ${input.prompt}` : input.prompt : this.config.message ?? "";
5593
5733
  metadata: input.context ? { ...this.config.metadata, ...input.context } : this.config.metadata
5594
5734
  };
5595
5735
  if (context.signal.aborted) {
5596
- throw new TaskAbortedError2("Task aborted before sending human interaction");
5736
+ throw new TaskAbortedError3("Task aborted before sending human interaction");
5597
5737
  }
5598
5738
  let response;
5599
5739
  try {
5600
5740
  response = await connector.send(request, context.signal);
5601
5741
  } catch (err) {
5602
5742
  if (context.signal.aborted) {
5603
- throw new TaskAbortedError2("Task aborted during human interaction");
5743
+ throw new TaskAbortedError3("Task aborted during human interaction");
5604
5744
  }
5605
5745
  throw err;
5606
5746
  }
@@ -5610,13 +5750,13 @@ ${input.prompt}` : input.prompt : this.config.message ?? "";
5610
5750
  }
5611
5751
  while (!response.done) {
5612
5752
  if (context.signal.aborted) {
5613
- throw new TaskAbortedError2("Task aborted during multi-turn conversation");
5753
+ throw new TaskAbortedError3("Task aborted during multi-turn conversation");
5614
5754
  }
5615
5755
  try {
5616
5756
  response = await connector.followUp(request, response, context.signal);
5617
5757
  } catch (err) {
5618
5758
  if (context.signal.aborted) {
5619
- throw new TaskAbortedError2("Task aborted during multi-turn conversation");
5759
+ throw new TaskAbortedError3("Task aborted during multi-turn conversation");
5620
5760
  }
5621
5761
  throw err;
5622
5762
  }
@@ -5625,156 +5765,7 @@ ${input.prompt}` : input.prompt : this.config.message ?? "";
5625
5765
  return { ...response.content, action: response.action };
5626
5766
  }
5627
5767
  }
5628
- function resolveHumanConnector(context) {
5629
- if (!context.registry.has(HUMAN_CONNECTOR)) {
5630
- throw new TaskConfigurationError2("No IHumanConnector registered. Register one via " + "registry.registerInstance(HUMAN_CONNECTOR, connector) before running a human-in-the-loop task.");
5631
- }
5632
- return context.registry.get(HUMAN_CONNECTOR);
5633
- }
5634
- Workflow15.prototype.humanInput = CreateWorkflow14(HumanInputTask);
5635
-
5636
- // src/task/HumanApprovalTask.ts
5637
- var humanApprovalConfigSchema = {
5638
- type: "object",
5639
- properties: {
5640
- ...TaskConfigSchema31["properties"],
5641
- targetHumanId: {
5642
- type: "string",
5643
- title: "Target Human",
5644
- description: "Identifier of the human to ask for approval",
5645
- default: "default"
5646
- },
5647
- message: {
5648
- type: "string",
5649
- title: "Message",
5650
- description: "Explanatory message shown to the approver",
5651
- "x-ui-editor": "textarea"
5652
- },
5653
- metadata: {
5654
- type: "object",
5655
- additionalProperties: true,
5656
- "x-ui-hidden": true
5657
- }
5658
- },
5659
- additionalProperties: false
5660
- };
5661
- var inputSchema40 = {
5662
- type: "object",
5663
- properties: {
5664
- prompt: {
5665
- type: "string",
5666
- title: "Prompt",
5667
- description: "Dynamic prompt text merged into the approval message"
5668
- },
5669
- context: {
5670
- type: "object",
5671
- additionalProperties: true,
5672
- title: "Context",
5673
- description: "Dynamic context data merged into the request metadata",
5674
- "x-ui-hidden": true
5675
- }
5676
- },
5677
- additionalProperties: false
5678
- };
5679
- var approvalRequestedSchema = {
5680
- type: "object",
5681
- properties: {
5682
- approved: {
5683
- type: "boolean",
5684
- title: "Approved",
5685
- description: "Whether the request is approved"
5686
- },
5687
- reason: {
5688
- type: "string",
5689
- title: "Reason",
5690
- description: "Optional explanation for the decision"
5691
- }
5692
- },
5693
- required: ["approved"]
5694
- };
5695
- var approvalOutputSchema = {
5696
- type: "object",
5697
- properties: {
5698
- action: {
5699
- type: "string",
5700
- title: "Action",
5701
- description: "The human's action: accept, decline, or cancel",
5702
- enum: ["accept", "decline", "cancel"]
5703
- },
5704
- approved: {
5705
- type: "boolean",
5706
- title: "Approved",
5707
- description: "Whether the human approved the request"
5708
- },
5709
- reason: {
5710
- type: "string",
5711
- title: "Reason",
5712
- description: "Optional explanation for the decision"
5713
- }
5714
- },
5715
- required: ["action", "approved"],
5716
- additionalProperties: false
5717
- };
5718
-
5719
- class HumanApprovalTask extends Task41 {
5720
- static type = "HumanApprovalTask";
5721
- static category = "Flow Control";
5722
- static title = "Human Approval";
5723
- static description = "Pauses execution to request approval from a human (approve/deny) via MCP elicitation";
5724
- static cacheable = false;
5725
- static configSchema() {
5726
- return humanApprovalConfigSchema;
5727
- }
5728
- static inputSchema() {
5729
- return inputSchema40;
5730
- }
5731
- static outputSchema() {
5732
- return approvalOutputSchema;
5733
- }
5734
- async execute(input, context) {
5735
- const connector = resolveHumanConnector(context);
5736
- const requestId = uuid44();
5737
- const message = input.prompt ? this.config.message ? `${this.config.message}
5738
-
5739
- ${input.prompt}` : input.prompt : this.config.message ?? "";
5740
- const request = {
5741
- requestId,
5742
- targetHumanId: this.config.targetHumanId ?? "default",
5743
- kind: "elicit",
5744
- message,
5745
- contentSchema: approvalRequestedSchema,
5746
- contentData: undefined,
5747
- expectsResponse: true,
5748
- mode: "single",
5749
- metadata: input.context ? { ...this.config.metadata, ...input.context } : this.config.metadata
5750
- };
5751
- if (context.signal.aborted) {
5752
- throw new TaskAbortedError3("Task aborted before requesting human approval");
5753
- }
5754
- let response;
5755
- try {
5756
- response = await connector.send(request, context.signal);
5757
- } catch (err) {
5758
- if (context.signal.aborted) {
5759
- throw new TaskAbortedError3("Task aborted during human approval");
5760
- }
5761
- throw err;
5762
- }
5763
- if (response.action === "accept" && response.content) {
5764
- return {
5765
- action: response.action,
5766
- approved: response.content.approved === true,
5767
- reason: response.content.reason
5768
- };
5769
- }
5770
- return {
5771
- action: response.action,
5772
- approved: false,
5773
- ...response.content?.reason !== undefined ? { reason: response.content.reason } : {}
5774
- };
5775
- }
5776
- }
5777
- Workflow16.prototype.humanApproval = CreateWorkflow15(HumanApprovalTask);
5768
+ Workflow16.prototype.humanInput = CreateWorkflow15(HumanInputTask);
5778
5769
  // src/task/image/ImageBlurTask.ts
5779
5770
  import {
5780
5771
  CreateWorkflow as CreateWorkflow16,
@@ -15317,7 +15308,6 @@ export {
15317
15308
  searchMcpRegistry,
15318
15309
  safeFetch,
15319
15310
  resolveImageInput,
15320
- resolveHumanConnector,
15321
15311
  resolveAuthSecrets,
15322
15312
  resetSafeFetch,
15323
15313
  registerSafeFetch,
@@ -15450,7 +15440,6 @@ export {
15450
15440
  ImageBinaryOrDataUriSchema,
15451
15441
  HumanInputTask,
15452
15442
  HumanApprovalTask,
15453
- HUMAN_CONNECTOR,
15454
15443
  FileLoaderTask,
15455
15444
  FetchUrlTask,
15456
15445
  FetchUrlJob,
@@ -15492,4 +15481,4 @@ export {
15492
15481
  ArrayTask
15493
15482
  };
15494
15483
 
15495
- //# debugId=28F36DC8F603338064756E2164756E21
15484
+ //# debugId=03EA11327765032064756E2164756E21