@xyne/workflow-sdk 3.2.37 → 3.2.38
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/agents/agent-step.d.ts +2 -2
- package/dist/agents/host-agent-step.d.ts +1 -1
- package/dist/builder/index.d.ts +2 -2
- package/dist/builder/index.d.ts.map +1 -1
- package/dist/builder/index.js +1 -1
- package/dist/builder/index.js.map +1 -1
- package/dist/client/types.d.ts +7 -5
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client/workflow-client.d.ts.map +1 -1
- package/dist/client/workflow-client.js +7 -0
- package/dist/client/workflow-client.js.map +1 -1
- package/dist/common/citation-ref.d.ts +4 -4
- package/dist/common/credentials.d.ts +107 -0
- package/dist/common/credentials.d.ts.map +1 -1
- package/dist/common/credentials.js +67 -0
- package/dist/common/credentials.js.map +1 -1
- package/dist/common/index.d.ts +2 -2
- package/dist/common/index.d.ts.map +1 -1
- package/dist/common/index.js +2 -2
- package/dist/common/index.js.map +1 -1
- package/dist/connectors/builtin/builtin-connector.d.ts +32 -0
- package/dist/connectors/builtin/builtin-connector.d.ts.map +1 -0
- package/dist/connectors/builtin/builtin-connector.js +62 -0
- package/dist/connectors/builtin/builtin-connector.js.map +1 -0
- package/dist/connectors/builtin/credentials.d.ts +18 -0
- package/dist/connectors/builtin/credentials.d.ts.map +1 -0
- package/dist/connectors/builtin/credentials.js +50 -0
- package/dist/connectors/builtin/credentials.js.map +1 -0
- package/dist/connectors/builtin/steps/code.step.d.ts +99 -0
- package/dist/connectors/builtin/steps/code.step.d.ts.map +1 -0
- package/dist/connectors/builtin/steps/code.step.js +152 -0
- package/dist/connectors/builtin/steps/code.step.js.map +1 -0
- package/dist/connectors/builtin/steps/conditional.step.d.ts +182 -0
- package/dist/connectors/builtin/steps/conditional.step.d.ts.map +1 -0
- package/dist/connectors/builtin/steps/conditional.step.js +82 -0
- package/dist/connectors/builtin/steps/conditional.step.js.map +1 -0
- package/dist/connectors/builtin/steps/dedup.step.d.ts +65 -0
- package/dist/connectors/builtin/steps/dedup.step.d.ts.map +1 -0
- package/dist/connectors/builtin/steps/dedup.step.js +61 -0
- package/dist/connectors/builtin/steps/dedup.step.js.map +1 -0
- package/dist/connectors/builtin/steps/http-request.step.d.ts +1027 -0
- package/dist/connectors/builtin/steps/http-request.step.d.ts.map +1 -0
- package/dist/connectors/builtin/steps/http-request.step.js +497 -0
- package/dist/connectors/builtin/steps/http-request.step.js.map +1 -0
- package/dist/connectors/builtin/steps/loop.step.d.ts +100 -0
- package/dist/connectors/builtin/steps/loop.step.d.ts.map +1 -0
- package/dist/connectors/builtin/steps/loop.step.js +73 -0
- package/dist/connectors/builtin/steps/loop.step.js.map +1 -0
- package/dist/connectors/builtin/steps/map.step.d.ts +148 -0
- package/dist/connectors/builtin/steps/map.step.d.ts.map +1 -0
- package/dist/connectors/builtin/steps/map.step.js +111 -0
- package/dist/connectors/builtin/steps/map.step.js.map +1 -0
- package/dist/connectors/builtin/steps/parallel.step.d.ts +246 -0
- package/dist/connectors/builtin/steps/parallel.step.d.ts.map +1 -0
- package/dist/connectors/builtin/steps/parallel.step.js +175 -0
- package/dist/connectors/builtin/steps/parallel.step.js.map +1 -0
- package/dist/connectors/builtin/steps/ssrf-guard.d.ts +9 -0
- package/dist/connectors/builtin/steps/ssrf-guard.d.ts.map +1 -0
- package/dist/connectors/builtin/steps/ssrf-guard.js +115 -0
- package/dist/connectors/builtin/steps/ssrf-guard.js.map +1 -0
- package/dist/connectors/builtin/steps/switch.step.d.ts +235 -0
- package/dist/connectors/builtin/steps/switch.step.d.ts.map +1 -0
- package/dist/connectors/builtin/steps/switch.step.js +101 -0
- package/dist/connectors/builtin/steps/switch.step.js.map +1 -0
- package/dist/connectors/builtin/steps/wait.step.d.ts +1072 -0
- package/dist/connectors/builtin/steps/wait.step.d.ts.map +1 -0
- package/dist/connectors/builtin/steps/wait.step.js +254 -0
- package/dist/connectors/builtin/steps/wait.step.js.map +1 -0
- package/dist/connectors/builtin/triggers/default-cron-trigger.d.ts +44 -0
- package/dist/connectors/builtin/triggers/default-cron-trigger.d.ts.map +1 -0
- package/dist/connectors/builtin/triggers/default-cron-trigger.js +31 -0
- package/dist/connectors/builtin/triggers/default-cron-trigger.js.map +1 -0
- package/dist/connectors/builtin/triggers/default-event-trigger.d.ts +32 -0
- package/dist/connectors/builtin/triggers/default-event-trigger.d.ts.map +1 -0
- package/dist/connectors/builtin/triggers/default-event-trigger.js +21 -0
- package/dist/connectors/builtin/triggers/default-event-trigger.js.map +1 -0
- package/dist/connectors/builtin/triggers/default-manual-trigger.d.ts +45 -0
- package/dist/connectors/builtin/triggers/default-manual-trigger.d.ts.map +1 -0
- package/dist/connectors/builtin/triggers/default-manual-trigger.js +51 -0
- package/dist/connectors/builtin/triggers/default-manual-trigger.js.map +1 -0
- package/dist/connectors/builtin/triggers/default-webhook-v2-trigger.d.ts +31 -0
- package/dist/connectors/builtin/triggers/default-webhook-v2-trigger.d.ts.map +1 -0
- package/dist/connectors/builtin/triggers/default-webhook-v2-trigger.js +40 -0
- package/dist/connectors/builtin/triggers/default-webhook-v2-trigger.js.map +1 -0
- package/dist/connectors/core/base-connector.d.ts +45 -0
- package/dist/connectors/core/base-connector.d.ts.map +1 -0
- package/dist/connectors/core/base-connector.js +3 -0
- package/dist/connectors/core/base-connector.js.map +1 -0
- package/dist/connectors/core/connector-registry.d.ts +130 -0
- package/dist/connectors/core/connector-registry.d.ts.map +1 -0
- package/dist/connectors/core/connector-registry.js +357 -0
- package/dist/connectors/core/connector-registry.js.map +1 -0
- package/dist/connectors/core/credentials.d.ts +104 -0
- package/dist/connectors/core/credentials.d.ts.map +1 -0
- package/dist/connectors/core/credentials.js +67 -0
- package/dist/connectors/core/credentials.js.map +1 -0
- package/dist/connectors/core/index.d.ts +7 -0
- package/dist/connectors/core/index.d.ts.map +1 -0
- package/dist/connectors/core/index.js +5 -0
- package/dist/connectors/core/index.js.map +1 -0
- package/dist/engine/available-context.d.ts +3 -4
- package/dist/engine/available-context.d.ts.map +1 -1
- package/dist/engine/available-context.js +17 -13
- package/dist/engine/available-context.js.map +1 -1
- package/dist/engine/config-validator.d.ts +13 -5
- package/dist/engine/config-validator.d.ts.map +1 -1
- package/dist/engine/config-validator.js +89 -11
- package/dist/engine/config-validator.js.map +1 -1
- package/dist/engine/credential-resolver.d.ts +42 -0
- package/dist/engine/credential-resolver.d.ts.map +1 -0
- package/dist/engine/credential-resolver.js +63 -0
- package/dist/engine/credential-resolver.js.map +1 -0
- package/dist/engine/workflow-executor.d.ts +4 -5
- package/dist/engine/workflow-executor.d.ts.map +1 -1
- package/dist/engine/workflow-executor.js +16 -38
- package/dist/engine/workflow-executor.js.map +1 -1
- package/dist/index.d.ts +43 -28
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +30 -15
- package/dist/index.js.map +1 -1
- package/dist/ingest/body.d.ts +18 -0
- package/dist/ingest/body.d.ts.map +1 -0
- package/dist/ingest/body.js +47 -0
- package/dist/ingest/body.js.map +1 -0
- package/dist/ingest/filter.d.ts +11 -0
- package/dist/ingest/filter.d.ts.map +1 -0
- package/dist/ingest/filter.js +23 -0
- package/dist/ingest/filter.js.map +1 -0
- package/dist/ingest/headers.d.ts +3 -0
- package/dist/ingest/headers.d.ts.map +1 -0
- package/dist/ingest/headers.js +11 -0
- package/dist/ingest/headers.js.map +1 -0
- package/dist/ingest/types.d.ts +50 -0
- package/dist/ingest/types.d.ts.map +1 -0
- package/dist/ingest/types.js +9 -0
- package/dist/ingest/types.js.map +1 -0
- package/dist/persistence/in-memory-adapter.d.ts +4 -8
- package/dist/persistence/in-memory-adapter.d.ts.map +1 -1
- package/dist/persistence/in-memory-adapter.js +8 -25
- package/dist/persistence/in-memory-adapter.js.map +1 -1
- package/dist/persistence/types.d.ts +5 -19
- package/dist/persistence/types.d.ts.map +1 -1
- package/dist/router/types.d.ts +31 -3
- package/dist/router/types.d.ts.map +1 -1
- package/dist/router/workflow-router.d.ts +4 -3
- package/dist/router/workflow-router.d.ts.map +1 -1
- package/dist/router/workflow-router.js +66 -40
- package/dist/router/workflow-router.js.map +1 -1
- package/dist/runtime/types.d.ts +6 -4
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/runtime/workflow-runtime.d.ts +43 -37
- package/dist/runtime/workflow-runtime.d.ts.map +1 -1
- package/dist/runtime/workflow-runtime.js +158 -133
- package/dist/runtime/workflow-runtime.js.map +1 -1
- package/dist/steps/base-step.d.ts +23 -0
- package/dist/steps/base-step.d.ts.map +1 -1
- package/dist/steps/base-step.js +22 -0
- package/dist/steps/base-step.js.map +1 -1
- package/dist/steps/step-descriptor.d.ts +52 -0
- package/dist/steps/step-descriptor.d.ts.map +1 -0
- package/dist/steps/step-descriptor.js +32 -0
- package/dist/steps/step-descriptor.js.map +1 -0
- package/dist/testing/authz-conformance.d.ts.map +1 -1
- package/dist/testing/authz-conformance.js +6 -7
- package/dist/testing/authz-conformance.js.map +1 -1
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +1 -0
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/mock-step-context.d.ts +1 -0
- package/dist/testing/mock-step-context.d.ts.map +1 -1
- package/dist/testing/mock-step-context.js +1 -0
- package/dist/testing/mock-step-context.js.map +1 -1
- package/dist/testing/test-connector.d.ts +40 -0
- package/dist/testing/test-connector.d.ts.map +1 -0
- package/dist/testing/test-connector.js +39 -0
- package/dist/testing/test-connector.js.map +1 -0
- package/dist/triggers/api-trigger.d.ts +15 -0
- package/dist/triggers/api-trigger.d.ts.map +1 -0
- package/dist/triggers/api-trigger.js +14 -0
- package/dist/triggers/api-trigger.js.map +1 -0
- package/dist/triggers/base-trigger.d.ts +29 -0
- package/dist/triggers/base-trigger.d.ts.map +1 -1
- package/dist/triggers/base-trigger.js +16 -0
- package/dist/triggers/base-trigger.js.map +1 -1
- package/dist/triggers/trigger-descriptor.d.ts +42 -0
- package/dist/triggers/trigger-descriptor.d.ts.map +1 -0
- package/dist/triggers/trigger-descriptor.js +29 -0
- package/dist/triggers/trigger-descriptor.js.map +1 -0
- package/dist/triggers/webhook-trigger.d.ts +31 -38
- package/dist/triggers/webhook-trigger.d.ts.map +1 -1
- package/dist/triggers/webhook-trigger.js +19 -6
- package/dist/triggers/webhook-trigger.js.map +1 -1
- package/dist/types/known-types.d.ts +0 -1
- package/dist/types/known-types.d.ts.map +1 -1
- package/dist/types/known-types.js +0 -1
- package/dist/types/known-types.js.map +1 -1
- package/dist/types/validation.d.ts +3 -1
- package/dist/types/validation.d.ts.map +1 -1
- package/dist/types/validation.js +2 -0
- package/dist/types/validation.js.map +1 -1
- package/dist/types/workflow-config.d.ts +23 -0
- package/dist/types/workflow-config.d.ts.map +1 -1
- package/dist/types/workflow-config.js +8 -0
- package/dist/types/workflow-config.js.map +1 -1
- package/dist/util/credential-slot-schema.d.ts +20 -0
- package/dist/util/credential-slot-schema.d.ts.map +1 -0
- package/dist/util/credential-slot-schema.js +30 -0
- package/dist/util/credential-slot-schema.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LOOP step — iterate over an array and walk a body branch per item.
|
|
3
|
+
*
|
|
4
|
+
* BaseControlFlowStep with a single `body` branch. For each item in the
|
|
5
|
+
* source array, sets `ctx.workflow.steps[loopStepId].currentItem` and walks
|
|
6
|
+
* the body branch.
|
|
7
|
+
*
|
|
8
|
+
* Output: `{ results: unknown[], count: number }`
|
|
9
|
+
*/
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
import { BaseControlFlowStep, cloneScope } from '../../../steps/base-step.js';
|
|
12
|
+
import { BuiltinStepType } from '../../../types/known-types.js';
|
|
13
|
+
import { resolvePath } from '../../../engine/variable-resolver.js';
|
|
14
|
+
// ─── Config ───
|
|
15
|
+
export const LoopStepConfigSchema = z.object({
|
|
16
|
+
source: z.string().min(1).describe('Path to the array to iterate over (e.g. steps.fetch.output.items). Supports {{variable}} refs'),
|
|
17
|
+
body: z.array(z.object({ id: z.string(), type: z.string() }).passthrough()).describe('Steps to execute for each item in the array'),
|
|
18
|
+
maxIterations: z.number().int().positive().default(1000).describe('Maximum number of iterations as a safety limit'),
|
|
19
|
+
});
|
|
20
|
+
const LoopStepOutputSchema = z.object({
|
|
21
|
+
results: z.array(z.unknown()),
|
|
22
|
+
count: z.number(),
|
|
23
|
+
});
|
|
24
|
+
// ─── Step ───
|
|
25
|
+
export class LoopStep extends BaseControlFlowStep {
|
|
26
|
+
type = BuiltinStepType.LOOP;
|
|
27
|
+
name = 'Loop';
|
|
28
|
+
description = 'Iterate over an array and execute steps for each item';
|
|
29
|
+
configSchema = LoopStepConfigSchema;
|
|
30
|
+
outputSchema = LoopStepOutputSchema;
|
|
31
|
+
category = 'control';
|
|
32
|
+
branchModel = 'iterate';
|
|
33
|
+
icon = 'repeat';
|
|
34
|
+
declaredOutputs = [
|
|
35
|
+
{ key: 'body', label: 'For each item' },
|
|
36
|
+
];
|
|
37
|
+
getBranches(config) {
|
|
38
|
+
return {
|
|
39
|
+
body: (config['body'] ?? []),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
async execute(config, ctx) {
|
|
43
|
+
// Resolve the source array from context
|
|
44
|
+
const sourceValue = resolvePath(ctx.workflow, config.source);
|
|
45
|
+
if (!Array.isArray(sourceValue)) {
|
|
46
|
+
throw new Error(`LOOP source "${config.source}" did not resolve to an array (got ${typeof sourceValue})`);
|
|
47
|
+
}
|
|
48
|
+
const items = sourceValue;
|
|
49
|
+
const limit = Math.min(items.length, config.maxIterations);
|
|
50
|
+
const results = [];
|
|
51
|
+
for (let i = 0; i < limit; i++) {
|
|
52
|
+
const item = items[i];
|
|
53
|
+
// Each iteration runs in its own scope, keyed by node-path frame
|
|
54
|
+
// `loop_y:body#<i>`. The iteration index isolates body-step records and
|
|
55
|
+
// is the identity that lets a WAIT in iteration N resume the right
|
|
56
|
+
// iteration. `__loop` exposes the current item to body steps within the
|
|
57
|
+
// iteration scope (nested loops nest their own `__loop` in child scopes).
|
|
58
|
+
const iterScope = cloneScope(ctx.workflow);
|
|
59
|
+
iterScope.steps['__loop'] = {
|
|
60
|
+
type: 'LOOP',
|
|
61
|
+
output: {
|
|
62
|
+
currentItem: item,
|
|
63
|
+
currentIndex: i,
|
|
64
|
+
totalItems: items.length,
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
await ctx.walkBranch(config.body, iterScope, 'body', i);
|
|
68
|
+
results.push(item);
|
|
69
|
+
}
|
|
70
|
+
return { results, count: results.length };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=loop.step.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loop.step.js","sourceRoot":"","sources":["../../../../src/connectors/builtin/steps/loop.step.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAE9E,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,OAAO,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AAEnE,iBAAiB;AAEjB,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3C,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,+FAA+F,CAAC;IACnI,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,QAAQ,CAAC,6CAA6C,CAAC;IACnI,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC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C,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC;QAC3D,MAAM,OAAO,GAAc,EAAE,CAAC;QAE9B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;YAC/B,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YAEtB,iEAAiE;YACjE,wEAAwE;YACxE,mEAAmE;YACnE,wEAAwE;YACxE,0EAA0E;YAC1E,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YAC1C,SAAS,CAAC,KAAiC,CAAC,QAAQ,CAAC,GAAG;gBACvD,IAAI,EAAE,MAAM;gBACZ,MAAM,EAAE;oBACN,WAAW,EAAE,IAAI;oBACjB,YAAY,EAAE,CAAC;oBACf,UAAU,EAAE,KAAK,CAAC,MAAM;iBACzB;aACF,CAAC;YAEF,MAAM,GAAG,CAAC,UAAU,CAClB,MAAM,CAAC,IAAuC,EAC9C,SAAS,EACT,MAAM,EACN,CAAC,CACF,CAAC;YAEF,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrB,CAAC;QAED,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;IAC5C,CAAC;CACF"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MAP step — iterate an array and run one `body` per item CONCURRENTLY.
|
|
3
|
+
*
|
|
4
|
+
* Like LOOP (resolves a source array, single `body`) but every item runs in
|
|
5
|
+
* parallel rather than sequentially — for cases where N dynamically-discovered
|
|
6
|
+
* items each need the same processing (e.g. validate the PAN of each of N
|
|
7
|
+
* owners). Each iteration runs in its own scope keyed by the node-path frame
|
|
8
|
+
* `map_x:item#<i>`, so a WAIT inside an iteration parks that iteration's own
|
|
9
|
+
* gate; multiple iterations can pause at once and resume independently — the
|
|
10
|
+
* same durable model PARALLEL uses (the executor's node-path records ARE the
|
|
11
|
+
* state; no saved state lives here).
|
|
12
|
+
*
|
|
13
|
+
* Output: `{ count, items: [{ index, item, steps }] }` — per-iteration step
|
|
14
|
+
* outputs, index-aligned with the source array (mirrors PARALLEL's
|
|
15
|
+
* `branches.<key>.steps`). Reference downstream as
|
|
16
|
+
* `…output.items.<i>.steps.<stepId>.output.<field>`.
|
|
17
|
+
*/
|
|
18
|
+
import { z } from 'zod';
|
|
19
|
+
import { BaseControlFlowStep } from '../../../steps/base-step.js';
|
|
20
|
+
import type { BranchStepOutputs, ControlFlowExecutionContext } from '../../../steps/base-step.js';
|
|
21
|
+
import { BuiltinStepType } from '../../../types/known-types.js';
|
|
22
|
+
import type { WorkflowStepConfig } from '../../../types/workflow-config.js';
|
|
23
|
+
export declare const MapStepConfigSchema: z.ZodObject<{
|
|
24
|
+
source: z.ZodString;
|
|
25
|
+
body: z.ZodArray<z.ZodObject<{
|
|
26
|
+
id: z.ZodString;
|
|
27
|
+
type: z.ZodString;
|
|
28
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
29
|
+
id: z.ZodString;
|
|
30
|
+
type: z.ZodString;
|
|
31
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
32
|
+
id: z.ZodString;
|
|
33
|
+
type: z.ZodString;
|
|
34
|
+
}, z.ZodTypeAny, "passthrough">>, "many">;
|
|
35
|
+
}, "strip", z.ZodTypeAny, {
|
|
36
|
+
body: z.objectOutputType<{
|
|
37
|
+
id: z.ZodString;
|
|
38
|
+
type: z.ZodString;
|
|
39
|
+
}, z.ZodTypeAny, "passthrough">[];
|
|
40
|
+
source: string;
|
|
41
|
+
}, {
|
|
42
|
+
body: z.objectInputType<{
|
|
43
|
+
id: z.ZodString;
|
|
44
|
+
type: z.ZodString;
|
|
45
|
+
}, z.ZodTypeAny, "passthrough">[];
|
|
46
|
+
source: string;
|
|
47
|
+
}>;
|
|
48
|
+
export type MapStepConfig = z.infer<typeof MapStepConfigSchema>;
|
|
49
|
+
/** One iteration's result — its top-level step outputs (or an error). */
|
|
50
|
+
export interface MapItemResult {
|
|
51
|
+
index: number;
|
|
52
|
+
item: unknown;
|
|
53
|
+
steps?: BranchStepOutputs;
|
|
54
|
+
error?: string;
|
|
55
|
+
}
|
|
56
|
+
export interface MapStepOutput extends Record<string, unknown> {
|
|
57
|
+
count: number;
|
|
58
|
+
items: MapItemResult[];
|
|
59
|
+
}
|
|
60
|
+
export declare class MapStep extends BaseControlFlowStep<typeof MapStepConfigSchema, MapStepOutput> {
|
|
61
|
+
readonly type = BuiltinStepType.MAP;
|
|
62
|
+
readonly name = "Map";
|
|
63
|
+
readonly description = "Map over an array, running steps for each item concurrently";
|
|
64
|
+
readonly configSchema: z.ZodObject<{
|
|
65
|
+
source: z.ZodString;
|
|
66
|
+
body: z.ZodArray<z.ZodObject<{
|
|
67
|
+
id: z.ZodString;
|
|
68
|
+
type: z.ZodString;
|
|
69
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
70
|
+
id: z.ZodString;
|
|
71
|
+
type: z.ZodString;
|
|
72
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
73
|
+
id: z.ZodString;
|
|
74
|
+
type: z.ZodString;
|
|
75
|
+
}, z.ZodTypeAny, "passthrough">>, "many">;
|
|
76
|
+
}, "strip", z.ZodTypeAny, {
|
|
77
|
+
body: z.objectOutputType<{
|
|
78
|
+
id: z.ZodString;
|
|
79
|
+
type: z.ZodString;
|
|
80
|
+
}, z.ZodTypeAny, "passthrough">[];
|
|
81
|
+
source: string;
|
|
82
|
+
}, {
|
|
83
|
+
body: z.objectInputType<{
|
|
84
|
+
id: z.ZodString;
|
|
85
|
+
type: z.ZodString;
|
|
86
|
+
}, z.ZodTypeAny, "passthrough">[];
|
|
87
|
+
source: string;
|
|
88
|
+
}>;
|
|
89
|
+
readonly outputSchema: z.ZodObject<{
|
|
90
|
+
count: z.ZodNumber;
|
|
91
|
+
items: z.ZodArray<z.ZodObject<{
|
|
92
|
+
index: z.ZodNumber;
|
|
93
|
+
item: z.ZodUnknown;
|
|
94
|
+
steps: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
95
|
+
output: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
96
|
+
}, "strip", z.ZodTypeAny, {
|
|
97
|
+
output: Record<string, unknown>;
|
|
98
|
+
}, {
|
|
99
|
+
output: Record<string, unknown>;
|
|
100
|
+
}>>>;
|
|
101
|
+
error: z.ZodOptional<z.ZodString>;
|
|
102
|
+
}, "strip", z.ZodTypeAny, {
|
|
103
|
+
index: number;
|
|
104
|
+
steps?: Record<string, {
|
|
105
|
+
output: Record<string, unknown>;
|
|
106
|
+
}> | undefined;
|
|
107
|
+
error?: string | undefined;
|
|
108
|
+
item?: unknown;
|
|
109
|
+
}, {
|
|
110
|
+
index: number;
|
|
111
|
+
steps?: Record<string, {
|
|
112
|
+
output: Record<string, unknown>;
|
|
113
|
+
}> | undefined;
|
|
114
|
+
error?: string | undefined;
|
|
115
|
+
item?: unknown;
|
|
116
|
+
}>, "many">;
|
|
117
|
+
}, "strip", z.ZodTypeAny, {
|
|
118
|
+
items: {
|
|
119
|
+
index: number;
|
|
120
|
+
steps?: Record<string, {
|
|
121
|
+
output: Record<string, unknown>;
|
|
122
|
+
}> | undefined;
|
|
123
|
+
error?: string | undefined;
|
|
124
|
+
item?: unknown;
|
|
125
|
+
}[];
|
|
126
|
+
count: number;
|
|
127
|
+
}, {
|
|
128
|
+
items: {
|
|
129
|
+
index: number;
|
|
130
|
+
steps?: Record<string, {
|
|
131
|
+
output: Record<string, unknown>;
|
|
132
|
+
}> | undefined;
|
|
133
|
+
error?: string | undefined;
|
|
134
|
+
item?: unknown;
|
|
135
|
+
}[];
|
|
136
|
+
count: number;
|
|
137
|
+
}>;
|
|
138
|
+
readonly category: "control";
|
|
139
|
+
readonly branchModel: "map";
|
|
140
|
+
readonly icon = "layers";
|
|
141
|
+
readonly declaredOutputs: readonly [{
|
|
142
|
+
readonly key: "body";
|
|
143
|
+
readonly label: "For each item";
|
|
144
|
+
}];
|
|
145
|
+
getBranches(config: Record<string, unknown>): Record<string, WorkflowStepConfig[]>;
|
|
146
|
+
execute(config: MapStepConfig, ctx: ControlFlowExecutionContext): Promise<MapStepOutput>;
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=map.step.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map.step.d.ts","sourceRoot":"","sources":["../../../../src/connectors/builtin/steps/map.step.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAkC,MAAM,6BAA6B,CAAC;AAClG,OAAO,KAAK,EAAE,iBAAiB,EAAE,2BAA2B,EAAE,MAAM,6BAA6B,CAAC;AAClG,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAM5E,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;EAG9B,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAIhE,yEAAyE;AACzE,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,CAAC,EAAE,iBAAiB,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,aAAc,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC5D,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,aAAa,EAAE,CAAC;CACxB;AAgBD,qBAAa,OAAQ,SAAQ,mBAAmB,CAC9C,OAAO,mBAAmB,EAC1B,aAAa,CACd;IACC,SAAkB,IAAI,uBAAuB;IAC7C,SAAkB,IAAI,SAAS;IAC/B,SAAkB,WAAW,iEAAiE;IAC9F,SAAkB,YAAY;;;;;;;;;;;;;;;;;;;;;;;;OAAuB;IACrD,SAAkB,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAAuB;IACrD,SAAkB,QAAQ,EAAG,SAAS,CAAU;IAChD,SAAkB,WAAW,EAAG,KAAK,CAAU;IAC/C,SAAkB,IAAI,YAAY;IAClC,SAAkB,eAAe;;;OAEtB;IAEF,WAAW,CAClB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,MAAM,CAAC,MAAM,EAAE,kBAAkB,EAAE,CAAC;IAMxB,OAAO,CACpB,MAAM,EAAE,aAAa,EACrB,GAAG,EAAE,2BAA2B,GAC/B,OAAO,CAAC,aAAa,CAAC;CAoE1B"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MAP step — iterate an array and run one `body` per item CONCURRENTLY.
|
|
3
|
+
*
|
|
4
|
+
* Like LOOP (resolves a source array, single `body`) but every item runs in
|
|
5
|
+
* parallel rather than sequentially — for cases where N dynamically-discovered
|
|
6
|
+
* items each need the same processing (e.g. validate the PAN of each of N
|
|
7
|
+
* owners). Each iteration runs in its own scope keyed by the node-path frame
|
|
8
|
+
* `map_x:item#<i>`, so a WAIT inside an iteration parks that iteration's own
|
|
9
|
+
* gate; multiple iterations can pause at once and resume independently — the
|
|
10
|
+
* same durable model PARALLEL uses (the executor's node-path records ARE the
|
|
11
|
+
* state; no saved state lives here).
|
|
12
|
+
*
|
|
13
|
+
* Output: `{ count, items: [{ index, item, steps }] }` — per-iteration step
|
|
14
|
+
* outputs, index-aligned with the source array (mirrors PARALLEL's
|
|
15
|
+
* `branches.<key>.steps`). Reference downstream as
|
|
16
|
+
* `…output.items.<i>.steps.<stepId>.output.<field>`.
|
|
17
|
+
*/
|
|
18
|
+
import { z } from 'zod';
|
|
19
|
+
import { BaseControlFlowStep, cloneScope, collectBranchSteps } from '../../../steps/base-step.js';
|
|
20
|
+
import { BuiltinStepType } from '../../../types/known-types.js';
|
|
21
|
+
import { resolvePath } from '../../../engine/variable-resolver.js';
|
|
22
|
+
import { PauseStep } from '../../../engine/pause-step.js';
|
|
23
|
+
// ─── Config ───
|
|
24
|
+
export const MapStepConfigSchema = z.object({
|
|
25
|
+
source: z.string().min(1).describe('Path to the array to map over (e.g. steps.extract.output.owners). Supports {{variable}} refs'),
|
|
26
|
+
body: z.array(z.object({ id: z.string(), type: z.string() }).passthrough()).describe('Steps to execute for each item — all items run concurrently'),
|
|
27
|
+
});
|
|
28
|
+
const MapStepOutputSchema = z.object({
|
|
29
|
+
count: z.number(),
|
|
30
|
+
items: z.array(z.object({
|
|
31
|
+
index: z.number(),
|
|
32
|
+
item: z.unknown(),
|
|
33
|
+
steps: z.record(z.object({ output: z.record(z.unknown()) })).optional(),
|
|
34
|
+
error: z.string().optional(),
|
|
35
|
+
})),
|
|
36
|
+
});
|
|
37
|
+
// ─── Step ───
|
|
38
|
+
export class MapStep extends BaseControlFlowStep {
|
|
39
|
+
type = BuiltinStepType.MAP;
|
|
40
|
+
name = 'Map';
|
|
41
|
+
description = 'Map over an array, running steps for each item concurrently';
|
|
42
|
+
configSchema = MapStepConfigSchema;
|
|
43
|
+
outputSchema = MapStepOutputSchema;
|
|
44
|
+
category = 'control';
|
|
45
|
+
branchModel = 'map';
|
|
46
|
+
icon = 'layers';
|
|
47
|
+
declaredOutputs = [
|
|
48
|
+
{ key: 'body', label: 'For each item' },
|
|
49
|
+
];
|
|
50
|
+
getBranches(config) {
|
|
51
|
+
return {
|
|
52
|
+
body: (config['body'] ?? []),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
async execute(config, ctx) {
|
|
56
|
+
const sourceValue = resolvePath(ctx.workflow, config.source);
|
|
57
|
+
if (!Array.isArray(sourceValue)) {
|
|
58
|
+
throw new Error(`MAP source "${config.source}" did not resolve to an array (got ${typeof sourceValue})`);
|
|
59
|
+
}
|
|
60
|
+
const items = sourceValue;
|
|
61
|
+
const body = config.body;
|
|
62
|
+
// Run every iteration concurrently, each in its own scope keyed by node-path
|
|
63
|
+
// `map_x:item#<i>`. A paused iteration throws PauseStep; on resume the MAP
|
|
64
|
+
// re-enters and re-walks all iterations — completed ones memo-skip from
|
|
65
|
+
// their records, the parked one(s) resume. No saved state lives here.
|
|
66
|
+
const settled = await Promise.allSettled(items.map(async (item, i) => {
|
|
67
|
+
const iterScope = cloneScope(ctx.workflow);
|
|
68
|
+
iterScope.steps['__map'] = {
|
|
69
|
+
type: 'MAP',
|
|
70
|
+
output: { currentItem: item, currentIndex: i, totalItems: items.length },
|
|
71
|
+
};
|
|
72
|
+
await ctx.walkBranch(body, iterScope, 'item', i);
|
|
73
|
+
return { index: i, item, steps: collectBranchSteps(body, iterScope) };
|
|
74
|
+
}));
|
|
75
|
+
const results = [];
|
|
76
|
+
let pausedCount = 0;
|
|
77
|
+
let firstExternalRef;
|
|
78
|
+
for (let i = 0; i < settled.length; i++) {
|
|
79
|
+
const entry = settled[i];
|
|
80
|
+
if (entry.status === 'fulfilled') {
|
|
81
|
+
results.push(entry.value);
|
|
82
|
+
}
|
|
83
|
+
else if (PauseStep.is(entry.reason)) {
|
|
84
|
+
pausedCount++;
|
|
85
|
+
const pe = entry.reason;
|
|
86
|
+
if (firstExternalRef === undefined && pe.externalRef !== undefined) {
|
|
87
|
+
firstExternalRef = pe.externalRef;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
results.push({
|
|
92
|
+
index: i,
|
|
93
|
+
item: items[i],
|
|
94
|
+
error: entry.reason instanceof Error
|
|
95
|
+
? entry.reason.message
|
|
96
|
+
: String(entry.reason),
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// Any paused iteration parks the whole MAP; the executor records it as
|
|
101
|
+
// EXTERNAL_WAIT and re-enters on resume. Completed/failed iterations are
|
|
102
|
+
// durable in their per-item records — this throw discards the partial list.
|
|
103
|
+
if (pausedCount > 0) {
|
|
104
|
+
const reason = pausedCount === 1 ? 'item awaiting resume' : `${String(pausedCount)} items awaiting resume`;
|
|
105
|
+
throw new PauseStep(reason, firstExternalRef !== undefined ? { externalRef: firstExternalRef } : undefined);
|
|
106
|
+
}
|
|
107
|
+
results.sort((a, b) => a.index - b.index);
|
|
108
|
+
return { count: items.length, items: results };
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=map.step.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map.step.js","sourceRoot":"","sources":["../../../../src/connectors/builtin/steps/map.step.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAElG,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,OAAO,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAE1D,iBAAiB;AAEjB,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,8FAA8F,CAAC;IAClI,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,QAAQ,CAAC,6DAA6D,CAAC;CACpJ,CAAC,CAAC;AAmBH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O,EAAE,CAAC;IACjD,CAAC;CACF"}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PARALLEL step — fan-out N named branches concurrently and collect results.
|
|
3
|
+
*
|
|
4
|
+
* BaseControlFlowStep with N dynamic branches. Runs all in parallel via
|
|
5
|
+
* Promise.allSettled or Promise.race depending on `merge` mode.
|
|
6
|
+
*
|
|
7
|
+
* Each branch gets an isolated copy of the workflow context so concurrent
|
|
8
|
+
* writes to `context.steps` don't conflict. After completion, the last
|
|
9
|
+
* step's output from each branch is collected into the parallel step's output.
|
|
10
|
+
*
|
|
11
|
+
* ## Pause handling (allSettled)
|
|
12
|
+
*
|
|
13
|
+
* Each branch runs in its own scope and persists its steps under node-path keys
|
|
14
|
+
* (`parallel_x:<branch>#0/<stepId>`). When a branch parks, its `walkBranch`
|
|
15
|
+
* throws `PauseStep`; PARALLEL collects which branches paused and, if any did,
|
|
16
|
+
* throws a single `PauseStep` so the whole step parks. There is no internal
|
|
17
|
+
* saved state — the per-branch step records ARE the durable state. On resume
|
|
18
|
+
* the executor re-enters PARALLEL, re-runs every branch via `walkBranch`:
|
|
19
|
+
* completed branch steps memo-skip from their records, the parked one(s) resume
|
|
20
|
+
* from theirs. Multiple branches can be paused simultaneously; each `resume()`
|
|
21
|
+
* targets one branch's gate by node-path. When the last paused branch
|
|
22
|
+
* completes, PARALLEL merges everything and returns.
|
|
23
|
+
*
|
|
24
|
+
* ## Output
|
|
25
|
+
*
|
|
26
|
+
* Discriminated union on `mode` so consumers (including the UI)
|
|
27
|
+
* can switch on `mode` and get full type safety for each case:
|
|
28
|
+
*
|
|
29
|
+
* allSettled: { mode: 'allSettled', branches: { [name]: { status, value?, reason? } } }
|
|
30
|
+
* race: { mode: 'race', winner: string, result: { output } }
|
|
31
|
+
*/
|
|
32
|
+
import { z } from 'zod';
|
|
33
|
+
import { BaseControlFlowStep } from '../../../steps/base-step.js';
|
|
34
|
+
import type { ControlFlowExecutionContext, BranchStepOutputs } from '../../../steps/base-step.js';
|
|
35
|
+
import { BuiltinStepType } from '../../../types/known-types.js';
|
|
36
|
+
import type { WorkflowStepConfig } from '../../../types/workflow-config.js';
|
|
37
|
+
export declare const ParallelStepConfigSchema: z.ZodObject<{
|
|
38
|
+
branches: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodObject<{
|
|
39
|
+
id: z.ZodString;
|
|
40
|
+
type: z.ZodString;
|
|
41
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
42
|
+
id: z.ZodString;
|
|
43
|
+
type: z.ZodString;
|
|
44
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
45
|
+
id: z.ZodString;
|
|
46
|
+
type: z.ZodString;
|
|
47
|
+
}, z.ZodTypeAny, "passthrough">>, "many">>;
|
|
48
|
+
merge: z.ZodDefault<z.ZodEnum<["allSettled", "race"]>>;
|
|
49
|
+
}, "strip", z.ZodTypeAny, {
|
|
50
|
+
branches: Record<string, z.objectOutputType<{
|
|
51
|
+
id: z.ZodString;
|
|
52
|
+
type: z.ZodString;
|
|
53
|
+
}, z.ZodTypeAny, "passthrough">[]>;
|
|
54
|
+
merge: "allSettled" | "race";
|
|
55
|
+
}, {
|
|
56
|
+
branches: Record<string, z.objectInputType<{
|
|
57
|
+
id: z.ZodString;
|
|
58
|
+
type: z.ZodString;
|
|
59
|
+
}, z.ZodTypeAny, "passthrough">[]>;
|
|
60
|
+
merge?: "allSettled" | "race" | undefined;
|
|
61
|
+
}>;
|
|
62
|
+
export type ParallelStepConfig = z.infer<typeof ParallelStepConfigSchema>;
|
|
63
|
+
/**
|
|
64
|
+
* Per-branch result — the branch's TOP-LEVEL steps map (keyed by step id, each
|
|
65
|
+
* `{ output }`, mirroring the main context's `steps.<id>.output`), or a failure.
|
|
66
|
+
* Referenced as `…output.branches.<key>.steps.<id>.output.<field>`.
|
|
67
|
+
*/
|
|
68
|
+
export type ParallelSettledBranchResult = {
|
|
69
|
+
status: 'fulfilled';
|
|
70
|
+
steps: BranchStepOutputs;
|
|
71
|
+
} | {
|
|
72
|
+
status: 'rejected';
|
|
73
|
+
reason: string;
|
|
74
|
+
};
|
|
75
|
+
export interface ParallelAllSettledOutput extends Record<string, unknown> {
|
|
76
|
+
mode: 'allSettled';
|
|
77
|
+
branches: Record<string, ParallelSettledBranchResult>;
|
|
78
|
+
}
|
|
79
|
+
export interface ParallelRaceOutput extends Record<string, unknown> {
|
|
80
|
+
mode: 'race';
|
|
81
|
+
/** Which branch won. */
|
|
82
|
+
branch: string;
|
|
83
|
+
/** Only the winner is populated; uniform `branches` shape with all control flow. */
|
|
84
|
+
branches: Record<string, ParallelSettledBranchResult>;
|
|
85
|
+
}
|
|
86
|
+
export type ParallelStepOutput = ParallelAllSettledOutput | ParallelRaceOutput;
|
|
87
|
+
export declare class ParallelStep extends BaseControlFlowStep<typeof ParallelStepConfigSchema, ParallelStepOutput> {
|
|
88
|
+
readonly type = BuiltinStepType.PARALLEL;
|
|
89
|
+
readonly name = "Parallel";
|
|
90
|
+
readonly description = "Run multiple branches concurrently and collect results";
|
|
91
|
+
readonly configSchema: z.ZodObject<{
|
|
92
|
+
branches: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodObject<{
|
|
93
|
+
id: z.ZodString;
|
|
94
|
+
type: z.ZodString;
|
|
95
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
96
|
+
id: z.ZodString;
|
|
97
|
+
type: z.ZodString;
|
|
98
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
99
|
+
id: z.ZodString;
|
|
100
|
+
type: z.ZodString;
|
|
101
|
+
}, z.ZodTypeAny, "passthrough">>, "many">>;
|
|
102
|
+
merge: z.ZodDefault<z.ZodEnum<["allSettled", "race"]>>;
|
|
103
|
+
}, "strip", z.ZodTypeAny, {
|
|
104
|
+
branches: Record<string, z.objectOutputType<{
|
|
105
|
+
id: z.ZodString;
|
|
106
|
+
type: z.ZodString;
|
|
107
|
+
}, z.ZodTypeAny, "passthrough">[]>;
|
|
108
|
+
merge: "allSettled" | "race";
|
|
109
|
+
}, {
|
|
110
|
+
branches: Record<string, z.objectInputType<{
|
|
111
|
+
id: z.ZodString;
|
|
112
|
+
type: z.ZodString;
|
|
113
|
+
}, z.ZodTypeAny, "passthrough">[]>;
|
|
114
|
+
merge?: "allSettled" | "race" | undefined;
|
|
115
|
+
}>;
|
|
116
|
+
readonly outputSchema: z.ZodDiscriminatedUnion<"mode", [z.ZodObject<{
|
|
117
|
+
mode: z.ZodLiteral<"allSettled">;
|
|
118
|
+
branches: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<"status", [z.ZodObject<{
|
|
119
|
+
status: z.ZodLiteral<"fulfilled">;
|
|
120
|
+
steps: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
121
|
+
output: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
122
|
+
}, "strip", z.ZodTypeAny, {
|
|
123
|
+
output: Record<string, unknown>;
|
|
124
|
+
}, {
|
|
125
|
+
output: Record<string, unknown>;
|
|
126
|
+
}>>;
|
|
127
|
+
}, "strip", z.ZodTypeAny, {
|
|
128
|
+
status: "fulfilled";
|
|
129
|
+
steps: Record<string, {
|
|
130
|
+
output: Record<string, unknown>;
|
|
131
|
+
}>;
|
|
132
|
+
}, {
|
|
133
|
+
status: "fulfilled";
|
|
134
|
+
steps: Record<string, {
|
|
135
|
+
output: Record<string, unknown>;
|
|
136
|
+
}>;
|
|
137
|
+
}>, z.ZodObject<{
|
|
138
|
+
status: z.ZodLiteral<"rejected">;
|
|
139
|
+
reason: z.ZodString;
|
|
140
|
+
}, "strip", z.ZodTypeAny, {
|
|
141
|
+
status: "rejected";
|
|
142
|
+
reason: string;
|
|
143
|
+
}, {
|
|
144
|
+
status: "rejected";
|
|
145
|
+
reason: string;
|
|
146
|
+
}>]>>;
|
|
147
|
+
}, "strip", z.ZodTypeAny, {
|
|
148
|
+
branches: Record<string, {
|
|
149
|
+
status: "fulfilled";
|
|
150
|
+
steps: Record<string, {
|
|
151
|
+
output: Record<string, unknown>;
|
|
152
|
+
}>;
|
|
153
|
+
} | {
|
|
154
|
+
status: "rejected";
|
|
155
|
+
reason: string;
|
|
156
|
+
}>;
|
|
157
|
+
mode: "allSettled";
|
|
158
|
+
}, {
|
|
159
|
+
branches: Record<string, {
|
|
160
|
+
status: "fulfilled";
|
|
161
|
+
steps: Record<string, {
|
|
162
|
+
output: Record<string, unknown>;
|
|
163
|
+
}>;
|
|
164
|
+
} | {
|
|
165
|
+
status: "rejected";
|
|
166
|
+
reason: string;
|
|
167
|
+
}>;
|
|
168
|
+
mode: "allSettled";
|
|
169
|
+
}>, z.ZodObject<{
|
|
170
|
+
mode: z.ZodLiteral<"race">;
|
|
171
|
+
branch: z.ZodString;
|
|
172
|
+
branches: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<"status", [z.ZodObject<{
|
|
173
|
+
status: z.ZodLiteral<"fulfilled">;
|
|
174
|
+
steps: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
175
|
+
output: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
176
|
+
}, "strip", z.ZodTypeAny, {
|
|
177
|
+
output: Record<string, unknown>;
|
|
178
|
+
}, {
|
|
179
|
+
output: Record<string, unknown>;
|
|
180
|
+
}>>;
|
|
181
|
+
}, "strip", z.ZodTypeAny, {
|
|
182
|
+
status: "fulfilled";
|
|
183
|
+
steps: Record<string, {
|
|
184
|
+
output: Record<string, unknown>;
|
|
185
|
+
}>;
|
|
186
|
+
}, {
|
|
187
|
+
status: "fulfilled";
|
|
188
|
+
steps: Record<string, {
|
|
189
|
+
output: Record<string, unknown>;
|
|
190
|
+
}>;
|
|
191
|
+
}>, z.ZodObject<{
|
|
192
|
+
status: z.ZodLiteral<"rejected">;
|
|
193
|
+
reason: z.ZodString;
|
|
194
|
+
}, "strip", z.ZodTypeAny, {
|
|
195
|
+
status: "rejected";
|
|
196
|
+
reason: string;
|
|
197
|
+
}, {
|
|
198
|
+
status: "rejected";
|
|
199
|
+
reason: string;
|
|
200
|
+
}>]>>;
|
|
201
|
+
}, "strip", z.ZodTypeAny, {
|
|
202
|
+
branch: string;
|
|
203
|
+
branches: Record<string, {
|
|
204
|
+
status: "fulfilled";
|
|
205
|
+
steps: Record<string, {
|
|
206
|
+
output: Record<string, unknown>;
|
|
207
|
+
}>;
|
|
208
|
+
} | {
|
|
209
|
+
status: "rejected";
|
|
210
|
+
reason: string;
|
|
211
|
+
}>;
|
|
212
|
+
mode: "race";
|
|
213
|
+
}, {
|
|
214
|
+
branch: string;
|
|
215
|
+
branches: Record<string, {
|
|
216
|
+
status: "fulfilled";
|
|
217
|
+
steps: Record<string, {
|
|
218
|
+
output: Record<string, unknown>;
|
|
219
|
+
}>;
|
|
220
|
+
} | {
|
|
221
|
+
status: "rejected";
|
|
222
|
+
reason: string;
|
|
223
|
+
}>;
|
|
224
|
+
mode: "race";
|
|
225
|
+
}>]>;
|
|
226
|
+
readonly category: "control";
|
|
227
|
+
readonly icon = "columns";
|
|
228
|
+
/**
|
|
229
|
+
* Declared outputs are dynamic — one per branch key.
|
|
230
|
+
* Since branch keys are user-defined, we return empty here and let
|
|
231
|
+
* `getBranches()` handle discovery for validation.
|
|
232
|
+
*/
|
|
233
|
+
readonly declaredOutputs: readonly [];
|
|
234
|
+
getBranches(config: Record<string, unknown>): Record<string, WorkflowStepConfig[]>;
|
|
235
|
+
/**
|
|
236
|
+
* Collapse the static `mode` discriminated union to the *configured* mode, so
|
|
237
|
+
* the variable picker sees a concrete object (not an `anyOf`) it can drill.
|
|
238
|
+
* Only the mode-dependent meta is declared here; the harness
|
|
239
|
+
* (`resolveOutputJsonSchemaOf`) splices the typed `branches` from `getBranches`.
|
|
240
|
+
*/
|
|
241
|
+
resolveOutputJsonSchema(config: Record<string, unknown>): Record<string, unknown>;
|
|
242
|
+
execute(config: ParallelStepConfig, ctx: ControlFlowExecutionContext): Promise<ParallelStepOutput>;
|
|
243
|
+
private executeAllSettled;
|
|
244
|
+
private executeRace;
|
|
245
|
+
}
|
|
246
|
+
//# sourceMappingURL=parallel.step.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parallel.step.d.ts","sourceRoot":"","sources":["../../../../src/connectors/builtin/steps/parallel.step.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAkC,MAAM,6BAA6B,CAAC;AAClG,OAAO,KAAK,EAAE,2BAA2B,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAClG,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAK5E,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;EAMnC,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAI1E;;;;GAIG;AACH,MAAM,MAAM,2BAA2B,GACnC;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,KAAK,EAAE,iBAAiB,CAAA;CAAE,GACjD;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3C,MAAM,WAAW,wBAAyB,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACvE,IAAI,EAAE,YAAY,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,2BAA2B,CAAC,CAAC;CACvD;AAED,MAAM,WAAW,kBAAmB,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACjE,IAAI,EAAE,MAAM,CAAC;IACb,wBAAwB;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,oFAAoF;IACpF,QAAQ,EAAE,MAA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