@xyne/workflow-sdk 1.0.0
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/README.md +36 -0
- package/dist/agents/agent-step.d.ts +152 -0
- package/dist/agents/agent-step.d.ts.map +1 -0
- package/dist/agents/agent-step.js +403 -0
- package/dist/agents/agent-step.js.map +1 -0
- package/dist/agents/base-runtime.d.ts +38 -0
- package/dist/agents/base-runtime.d.ts.map +1 -0
- package/dist/agents/base-runtime.js +21 -0
- package/dist/agents/base-runtime.js.map +1 -0
- package/dist/agents/index.d.ts +12 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +17 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/interceptor.d.ts +19 -0
- package/dist/agents/interceptor.d.ts.map +1 -0
- package/dist/agents/interceptor.js +21 -0
- package/dist/agents/interceptor.js.map +1 -0
- package/dist/agents/interceptors/approval-gate.d.ts +14 -0
- package/dist/agents/interceptors/approval-gate.d.ts.map +1 -0
- package/dist/agents/interceptors/approval-gate.js +19 -0
- package/dist/agents/interceptors/approval-gate.js.map +1 -0
- package/dist/agents/interceptors/tool-logger.d.ts +15 -0
- package/dist/agents/interceptors/tool-logger.d.ts.map +1 -0
- package/dist/agents/interceptors/tool-logger.js +23 -0
- package/dist/agents/interceptors/tool-logger.js.map +1 -0
- package/dist/agents/pi-mono-runtime.d.ts +88 -0
- package/dist/agents/pi-mono-runtime.d.ts.map +1 -0
- package/dist/agents/pi-mono-runtime.js +129 -0
- package/dist/agents/pi-mono-runtime.js.map +1 -0
- package/dist/agents/tool-registry.d.ts +25 -0
- package/dist/agents/tool-registry.d.ts.map +1 -0
- package/dist/agents/tool-registry.js +47 -0
- package/dist/agents/tool-registry.js.map +1 -0
- package/dist/agents/tool-types.d.ts +25 -0
- package/dist/agents/tool-types.d.ts.map +1 -0
- package/dist/agents/tool-types.js +9 -0
- package/dist/agents/tool-types.js.map +1 -0
- package/dist/agents/types.d.ts +91 -0
- package/dist/agents/types.d.ts.map +1 -0
- package/dist/agents/types.js +12 -0
- package/dist/agents/types.js.map +1 -0
- package/dist/builder/index.d.ts +30 -0
- package/dist/builder/index.d.ts.map +1 -0
- package/dist/builder/index.js +32 -0
- package/dist/builder/index.js.map +1 -0
- package/dist/client/index.d.ts +19 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +18 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/types.d.ts +128 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +10 -0
- package/dist/client/types.js.map +1 -0
- package/dist/client/workflow-client.d.ts +15 -0
- package/dist/client/workflow-client.d.ts.map +1 -0
- package/dist/client/workflow-client.js +293 -0
- package/dist/client/workflow-client.js.map +1 -0
- package/dist/common/attachment.d.ts +31 -0
- package/dist/common/attachment.d.ts.map +1 -0
- package/dist/common/attachment.js +21 -0
- package/dist/common/attachment.js.map +1 -0
- package/dist/common/executable-check.d.ts +42 -0
- package/dist/common/executable-check.d.ts.map +1 -0
- package/dist/common/executable-check.js +115 -0
- package/dist/common/executable-check.js.map +1 -0
- package/dist/common/index.d.ts +21 -0
- package/dist/common/index.d.ts.map +1 -0
- package/dist/common/index.js +19 -0
- package/dist/common/index.js.map +1 -0
- package/dist/common/resume-payload.d.ts +34 -0
- package/dist/common/resume-payload.d.ts.map +1 -0
- package/dist/common/resume-payload.js +12 -0
- package/dist/common/resume-payload.js.map +1 -0
- package/dist/engine/available-context.d.ts +29 -0
- package/dist/engine/available-context.d.ts.map +1 -0
- package/dist/engine/available-context.js +66 -0
- package/dist/engine/available-context.js.map +1 -0
- package/dist/engine/condition-evaluator.d.ts +13 -0
- package/dist/engine/condition-evaluator.d.ts.map +1 -0
- package/dist/engine/condition-evaluator.js +92 -0
- package/dist/engine/condition-evaluator.js.map +1 -0
- package/dist/engine/config-validator.d.ts +25 -0
- package/dist/engine/config-validator.d.ts.map +1 -0
- package/dist/engine/config-validator.js +316 -0
- package/dist/engine/config-validator.js.map +1 -0
- package/dist/engine/pause-step.d.ts +20 -0
- package/dist/engine/pause-step.d.ts.map +1 -0
- package/dist/engine/pause-step.js +24 -0
- package/dist/engine/pause-step.js.map +1 -0
- package/dist/engine/service-registry.d.ts +49 -0
- package/dist/engine/service-registry.d.ts.map +1 -0
- package/dist/engine/service-registry.js +76 -0
- package/dist/engine/service-registry.js.map +1 -0
- package/dist/engine/variable-resolver.d.ts +29 -0
- package/dist/engine/variable-resolver.d.ts.map +1 -0
- package/dist/engine/variable-resolver.js +130 -0
- package/dist/engine/variable-resolver.js.map +1 -0
- package/dist/engine/workflow-executor.d.ts +96 -0
- package/dist/engine/workflow-executor.d.ts.map +1 -0
- package/dist/engine/workflow-executor.js +837 -0
- package/dist/engine/workflow-executor.js.map +1 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/dist/persistence/in-memory-adapter.d.ts +138 -0
- package/dist/persistence/in-memory-adapter.d.ts.map +1 -0
- package/dist/persistence/in-memory-adapter.js +315 -0
- package/dist/persistence/in-memory-adapter.js.map +1 -0
- package/dist/persistence/types.d.ts +214 -0
- package/dist/persistence/types.d.ts.map +1 -0
- package/dist/persistence/types.js +8 -0
- package/dist/persistence/types.js.map +1 -0
- package/dist/router/types.d.ts +57 -0
- package/dist/router/types.d.ts.map +1 -0
- package/dist/router/types.js +8 -0
- package/dist/router/types.js.map +1 -0
- package/dist/router/workflow-router.d.ts +26 -0
- package/dist/router/workflow-router.d.ts.map +1 -0
- package/dist/router/workflow-router.js +611 -0
- package/dist/router/workflow-router.js.map +1 -0
- package/dist/runtime/execution-event-bus.d.ts +38 -0
- package/dist/runtime/execution-event-bus.d.ts.map +1 -0
- package/dist/runtime/execution-event-bus.js +87 -0
- package/dist/runtime/execution-event-bus.js.map +1 -0
- package/dist/runtime/types.d.ts +129 -0
- package/dist/runtime/types.d.ts.map +1 -0
- package/dist/runtime/types.js +5 -0
- package/dist/runtime/types.js.map +1 -0
- package/dist/runtime/workflow-runtime.d.ts +256 -0
- package/dist/runtime/workflow-runtime.d.ts.map +1 -0
- package/dist/runtime/workflow-runtime.js +699 -0
- package/dist/runtime/workflow-runtime.js.map +1 -0
- package/dist/steps/base-step.d.ts +204 -0
- package/dist/steps/base-step.d.ts.map +1 -0
- package/dist/steps/base-step.js +69 -0
- package/dist/steps/base-step.js.map +1 -0
- package/dist/steps/builtin/code.step.d.ts +95 -0
- package/dist/steps/builtin/code.step.d.ts.map +1 -0
- package/dist/steps/builtin/code.step.js +122 -0
- package/dist/steps/builtin/code.step.js.map +1 -0
- package/dist/steps/builtin/conditional.step.d.ts +146 -0
- package/dist/steps/builtin/conditional.step.d.ts.map +1 -0
- package/dist/steps/builtin/conditional.step.js +71 -0
- package/dist/steps/builtin/conditional.step.js.map +1 -0
- package/dist/steps/builtin/dedup.step.d.ts +65 -0
- package/dist/steps/builtin/dedup.step.d.ts.map +1 -0
- package/dist/steps/builtin/dedup.step.js +61 -0
- package/dist/steps/builtin/dedup.step.js.map +1 -0
- package/dist/steps/builtin/http-request.step.d.ts +928 -0
- package/dist/steps/builtin/http-request.step.d.ts.map +1 -0
- package/dist/steps/builtin/http-request.step.js +570 -0
- package/dist/steps/builtin/http-request.step.js.map +1 -0
- package/dist/steps/builtin/loop.step.d.ts +100 -0
- package/dist/steps/builtin/loop.step.d.ts.map +1 -0
- package/dist/steps/builtin/loop.step.js +79 -0
- package/dist/steps/builtin/loop.step.js.map +1 -0
- package/dist/steps/builtin/parallel.step.d.ts +208 -0
- package/dist/steps/builtin/parallel.step.d.ts.map +1 -0
- package/dist/steps/builtin/parallel.step.js +249 -0
- package/dist/steps/builtin/parallel.step.js.map +1 -0
- package/dist/steps/builtin/switch.step.d.ts +200 -0
- package/dist/steps/builtin/switch.step.d.ts.map +1 -0
- package/dist/steps/builtin/switch.step.js +92 -0
- package/dist/steps/builtin/switch.step.js.map +1 -0
- package/dist/steps/builtin/transform.step.d.ts +247 -0
- package/dist/steps/builtin/transform.step.d.ts.map +1 -0
- package/dist/steps/builtin/transform.step.js +135 -0
- package/dist/steps/builtin/transform.step.js.map +1 -0
- package/dist/steps/builtin/wait.step.d.ts +921 -0
- package/dist/steps/builtin/wait.step.d.ts.map +1 -0
- package/dist/steps/builtin/wait.step.js +211 -0
- package/dist/steps/builtin/wait.step.js.map +1 -0
- package/dist/steps/step-registry.d.ts +64 -0
- package/dist/steps/step-registry.d.ts.map +1 -0
- package/dist/steps/step-registry.js +102 -0
- package/dist/steps/step-registry.js.map +1 -0
- package/dist/storage/in-memory-adapter.d.ts +25 -0
- package/dist/storage/in-memory-adapter.d.ts.map +1 -0
- package/dist/storage/in-memory-adapter.js +41 -0
- package/dist/storage/in-memory-adapter.js.map +1 -0
- package/dist/storage/types.d.ts +53 -0
- package/dist/storage/types.d.ts.map +1 -0
- package/dist/storage/types.js +13 -0
- package/dist/storage/types.js.map +1 -0
- package/dist/testing/index.d.ts +10 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +10 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/mock-context.d.ts +13 -0
- package/dist/testing/mock-context.d.ts.map +1 -0
- package/dist/testing/mock-context.js +21 -0
- package/dist/testing/mock-context.js.map +1 -0
- package/dist/testing/mock-step-context.d.ts +47 -0
- package/dist/testing/mock-step-context.d.ts.map +1 -0
- package/dist/testing/mock-step-context.js +59 -0
- package/dist/testing/mock-step-context.js.map +1 -0
- package/dist/triggers/base-trigger.d.ts +58 -0
- package/dist/triggers/base-trigger.d.ts.map +1 -0
- package/dist/triggers/base-trigger.js +37 -0
- package/dist/triggers/base-trigger.js.map +1 -0
- package/dist/triggers/builtin/default-cron-trigger.d.ts +44 -0
- package/dist/triggers/builtin/default-cron-trigger.d.ts.map +1 -0
- package/dist/triggers/builtin/default-cron-trigger.js +31 -0
- package/dist/triggers/builtin/default-cron-trigger.js.map +1 -0
- package/dist/triggers/builtin/default-event-trigger.d.ts +32 -0
- package/dist/triggers/builtin/default-event-trigger.d.ts.map +1 -0
- package/dist/triggers/builtin/default-event-trigger.js +21 -0
- package/dist/triggers/builtin/default-event-trigger.js.map +1 -0
- package/dist/triggers/builtin/default-manual-trigger.d.ts +119 -0
- package/dist/triggers/builtin/default-manual-trigger.d.ts.map +1 -0
- package/dist/triggers/builtin/default-manual-trigger.js +64 -0
- package/dist/triggers/builtin/default-manual-trigger.js.map +1 -0
- package/dist/triggers/builtin/default-webhook-trigger.d.ts +72 -0
- package/dist/triggers/builtin/default-webhook-trigger.d.ts.map +1 -0
- package/dist/triggers/builtin/default-webhook-trigger.js +91 -0
- package/dist/triggers/builtin/default-webhook-trigger.js.map +1 -0
- package/dist/triggers/cron-trigger.d.ts +52 -0
- package/dist/triggers/cron-trigger.d.ts.map +1 -0
- package/dist/triggers/cron-trigger.js +15 -0
- package/dist/triggers/cron-trigger.js.map +1 -0
- package/dist/triggers/event-trigger.d.ts +14 -0
- package/dist/triggers/event-trigger.d.ts.map +1 -0
- package/dist/triggers/event-trigger.js +13 -0
- package/dist/triggers/event-trigger.js.map +1 -0
- package/dist/triggers/manual-trigger.d.ts +11 -0
- package/dist/triggers/manual-trigger.d.ts.map +1 -0
- package/dist/triggers/manual-trigger.js +10 -0
- package/dist/triggers/manual-trigger.js.map +1 -0
- package/dist/triggers/trigger-registry.d.ts +48 -0
- package/dist/triggers/trigger-registry.d.ts.map +1 -0
- package/dist/triggers/trigger-registry.js +81 -0
- package/dist/triggers/trigger-registry.js.map +1 -0
- package/dist/triggers/webhook-trigger.d.ts +54 -0
- package/dist/triggers/webhook-trigger.d.ts.map +1 -0
- package/dist/triggers/webhook-trigger.js +13 -0
- package/dist/triggers/webhook-trigger.js.map +1 -0
- package/dist/types/attachment.d.ts +23 -0
- package/dist/types/attachment.d.ts.map +1 -0
- package/dist/types/attachment.js +2 -0
- package/dist/types/attachment.js.map +1 -0
- package/dist/types/categories.d.ts +14 -0
- package/dist/types/categories.d.ts.map +1 -0
- package/dist/types/categories.js +10 -0
- package/dist/types/categories.js.map +1 -0
- package/dist/types/context.d.ts +61 -0
- package/dist/types/context.d.ts.map +1 -0
- package/dist/types/context.js +2 -0
- package/dist/types/context.js.map +1 -0
- package/dist/types/index.d.ts +18 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +12 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/known-types.d.ts +34 -0
- package/dist/types/known-types.d.ts.map +1 -0
- package/dist/types/known-types.js +49 -0
- package/dist/types/known-types.js.map +1 -0
- package/dist/types/operators.d.ts +20 -0
- package/dist/types/operators.d.ts.map +1 -0
- package/dist/types/operators.js +27 -0
- package/dist/types/operators.js.map +1 -0
- package/dist/types/pause-path.d.ts +23 -0
- package/dist/types/pause-path.d.ts.map +1 -0
- package/dist/types/pause-path.js +2 -0
- package/dist/types/pause-path.js.map +1 -0
- package/dist/types/pause-state.d.ts +100 -0
- package/dist/types/pause-state.d.ts.map +1 -0
- package/dist/types/pause-state.js +15 -0
- package/dist/types/pause-state.js.map +1 -0
- package/dist/types/resume-payload.d.ts +34 -0
- package/dist/types/resume-payload.d.ts.map +1 -0
- package/dist/types/resume-payload.js +12 -0
- package/dist/types/resume-payload.js.map +1 -0
- package/dist/types/status.d.ts +27 -0
- package/dist/types/status.d.ts.map +1 -0
- package/dist/types/status.js +41 -0
- package/dist/types/status.js.map +1 -0
- package/dist/types/step-events.d.ts +22 -0
- package/dist/types/step-events.d.ts.map +1 -0
- package/dist/types/step-events.js +8 -0
- package/dist/types/step-events.js.map +1 -0
- package/dist/types/step-types.d.ts +12 -0
- package/dist/types/step-types.d.ts.map +1 -0
- package/dist/types/step-types.js +2 -0
- package/dist/types/step-types.js.map +1 -0
- package/dist/types/trigger-types.d.ts +12 -0
- package/dist/types/trigger-types.d.ts.map +1 -0
- package/dist/types/trigger-types.js +2 -0
- package/dist/types/trigger-types.js.map +1 -0
- package/dist/types/validation.d.ts +19 -0
- package/dist/types/validation.d.ts.map +1 -0
- package/dist/types/validation.js +11 -0
- package/dist/types/validation.js.map +1 -0
- package/dist/types/workflow-config.d.ts +122 -0
- package/dist/types/workflow-config.d.ts.map +1 -0
- package/dist/types/workflow-config.js +71 -0
- package/dist/types/workflow-config.js.map +1 -0
- package/dist/util/executable-check.d.ts +42 -0
- package/dist/util/executable-check.d.ts.map +1 -0
- package/dist/util/executable-check.js +115 -0
- package/dist/util/executable-check.js.map +1 -0
- package/dist/util/schema-convert.d.ts +14 -0
- package/dist/util/schema-convert.d.ts.map +1 -0
- package/dist/util/schema-convert.js +16 -0
- package/dist/util/schema-convert.js.map +1 -0
- package/dist/util/variable-ref.d.ts +52 -0
- package/dist/util/variable-ref.d.ts.map +1 -0
- package/dist/util/variable-ref.js +89 -0
- package/dist/util/variable-ref.js.map +1 -0
- package/package.json +97 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SWITCH step — first-match-wins over an ordered list of conditional cases,
|
|
3
|
+
* with a guaranteed `default` fallback.
|
|
4
|
+
*
|
|
5
|
+
* Semantics (no fall-through):
|
|
6
|
+
*
|
|
7
|
+
* for (const [i, c] of cases.entries())
|
|
8
|
+
* if (evaluator.evaluate(c.condition, ctx.workflow)) {
|
|
9
|
+
* walkBranch(c.steps, `case_${i}`)
|
|
10
|
+
* return { branch: `case_${i}`, caseIndex: i, label: c.label ?? null }
|
|
11
|
+
* }
|
|
12
|
+
* walkBranch(default, 'default')
|
|
13
|
+
* return { branch: 'default', caseIndex: null, label: null }
|
|
14
|
+
*
|
|
15
|
+
* Branch keys are positional (`case_0`, `case_1`, ..., `default`) so a
|
|
16
|
+
* paused execution's PausePath survives label edits.
|
|
17
|
+
*/
|
|
18
|
+
import { z } from 'zod';
|
|
19
|
+
import { BaseControlFlowStep } from '../base-step.js';
|
|
20
|
+
import type { ControlFlowExecutionContext } from '../base-step.js';
|
|
21
|
+
import { BuiltinStepType } from '../../types/known-types.js';
|
|
22
|
+
import type { WorkflowStepConfig } from '../../types/workflow-config.js';
|
|
23
|
+
export declare const SwitchStepConfigSchema: z.ZodObject<{
|
|
24
|
+
cases: z.ZodArray<z.ZodObject<{
|
|
25
|
+
condition: z.ZodType<import("../../types/workflow-config.js").Condition, z.ZodTypeDef, import("../../types/workflow-config.js").Condition>;
|
|
26
|
+
label: z.ZodOptional<z.ZodString>;
|
|
27
|
+
steps: z.ZodArray<z.ZodObject<{
|
|
28
|
+
id: z.ZodString;
|
|
29
|
+
type: z.ZodString;
|
|
30
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
31
|
+
id: z.ZodString;
|
|
32
|
+
type: z.ZodString;
|
|
33
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
34
|
+
id: z.ZodString;
|
|
35
|
+
type: z.ZodString;
|
|
36
|
+
}, z.ZodTypeAny, "passthrough">>, "many">;
|
|
37
|
+
}, "strip", z.ZodTypeAny, {
|
|
38
|
+
steps: z.objectOutputType<{
|
|
39
|
+
id: z.ZodString;
|
|
40
|
+
type: z.ZodString;
|
|
41
|
+
}, z.ZodTypeAny, "passthrough">[];
|
|
42
|
+
condition: import("../../types/workflow-config.js").Condition;
|
|
43
|
+
label?: string | undefined;
|
|
44
|
+
}, {
|
|
45
|
+
steps: z.objectInputType<{
|
|
46
|
+
id: z.ZodString;
|
|
47
|
+
type: z.ZodString;
|
|
48
|
+
}, z.ZodTypeAny, "passthrough">[];
|
|
49
|
+
condition: import("../../types/workflow-config.js").Condition;
|
|
50
|
+
label?: string | undefined;
|
|
51
|
+
}>, "many">;
|
|
52
|
+
default: z.ZodArray<z.ZodObject<{
|
|
53
|
+
id: z.ZodString;
|
|
54
|
+
type: z.ZodString;
|
|
55
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
56
|
+
id: z.ZodString;
|
|
57
|
+
type: z.ZodString;
|
|
58
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
59
|
+
id: z.ZodString;
|
|
60
|
+
type: z.ZodString;
|
|
61
|
+
}, z.ZodTypeAny, "passthrough">>, "many">;
|
|
62
|
+
}, "strip", z.ZodTypeAny, {
|
|
63
|
+
default: z.objectOutputType<{
|
|
64
|
+
id: z.ZodString;
|
|
65
|
+
type: z.ZodString;
|
|
66
|
+
}, z.ZodTypeAny, "passthrough">[];
|
|
67
|
+
cases: {
|
|
68
|
+
steps: z.objectOutputType<{
|
|
69
|
+
id: z.ZodString;
|
|
70
|
+
type: z.ZodString;
|
|
71
|
+
}, z.ZodTypeAny, "passthrough">[];
|
|
72
|
+
condition: import("../../types/workflow-config.js").Condition;
|
|
73
|
+
label?: string | undefined;
|
|
74
|
+
}[];
|
|
75
|
+
}, {
|
|
76
|
+
default: z.objectInputType<{
|
|
77
|
+
id: z.ZodString;
|
|
78
|
+
type: z.ZodString;
|
|
79
|
+
}, z.ZodTypeAny, "passthrough">[];
|
|
80
|
+
cases: {
|
|
81
|
+
steps: z.objectInputType<{
|
|
82
|
+
id: z.ZodString;
|
|
83
|
+
type: z.ZodString;
|
|
84
|
+
}, z.ZodTypeAny, "passthrough">[];
|
|
85
|
+
condition: import("../../types/workflow-config.js").Condition;
|
|
86
|
+
label?: string | undefined;
|
|
87
|
+
}[];
|
|
88
|
+
}>;
|
|
89
|
+
export type SwitchStepConfig = z.infer<typeof SwitchStepConfigSchema>;
|
|
90
|
+
export interface SwitchStepOutput extends Record<string, unknown> {
|
|
91
|
+
/** Which branch executed. `'default'` when no case matched. `case_<i>` (i = caseIndex) otherwise. */
|
|
92
|
+
branch: string;
|
|
93
|
+
/** Index of the matched case, or `null` when `default` ran. */
|
|
94
|
+
caseIndex: number | null;
|
|
95
|
+
/** Label of the matched case, or `null` when `default` ran (or case had no label). */
|
|
96
|
+
label: string | null;
|
|
97
|
+
}
|
|
98
|
+
export declare class SwitchStep extends BaseControlFlowStep<typeof SwitchStepConfigSchema, SwitchStepOutput> {
|
|
99
|
+
readonly type = BuiltinStepType.SWITCH;
|
|
100
|
+
readonly name = "Switch";
|
|
101
|
+
readonly description = "Route to one of N branches; first matching case wins, otherwise default";
|
|
102
|
+
readonly configSchema: z.ZodObject<{
|
|
103
|
+
cases: z.ZodArray<z.ZodObject<{
|
|
104
|
+
condition: z.ZodType<import("../../types/workflow-config.js").Condition, z.ZodTypeDef, import("../../types/workflow-config.js").Condition>;
|
|
105
|
+
label: z.ZodOptional<z.ZodString>;
|
|
106
|
+
steps: z.ZodArray<z.ZodObject<{
|
|
107
|
+
id: z.ZodString;
|
|
108
|
+
type: z.ZodString;
|
|
109
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
110
|
+
id: z.ZodString;
|
|
111
|
+
type: z.ZodString;
|
|
112
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
113
|
+
id: z.ZodString;
|
|
114
|
+
type: z.ZodString;
|
|
115
|
+
}, z.ZodTypeAny, "passthrough">>, "many">;
|
|
116
|
+
}, "strip", z.ZodTypeAny, {
|
|
117
|
+
steps: z.objectOutputType<{
|
|
118
|
+
id: z.ZodString;
|
|
119
|
+
type: z.ZodString;
|
|
120
|
+
}, z.ZodTypeAny, "passthrough">[];
|
|
121
|
+
condition: import("../../types/workflow-config.js").Condition;
|
|
122
|
+
label?: string | undefined;
|
|
123
|
+
}, {
|
|
124
|
+
steps: z.objectInputType<{
|
|
125
|
+
id: z.ZodString;
|
|
126
|
+
type: z.ZodString;
|
|
127
|
+
}, z.ZodTypeAny, "passthrough">[];
|
|
128
|
+
condition: import("../../types/workflow-config.js").Condition;
|
|
129
|
+
label?: string | undefined;
|
|
130
|
+
}>, "many">;
|
|
131
|
+
default: z.ZodArray<z.ZodObject<{
|
|
132
|
+
id: z.ZodString;
|
|
133
|
+
type: z.ZodString;
|
|
134
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
135
|
+
id: z.ZodString;
|
|
136
|
+
type: z.ZodString;
|
|
137
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
138
|
+
id: z.ZodString;
|
|
139
|
+
type: z.ZodString;
|
|
140
|
+
}, z.ZodTypeAny, "passthrough">>, "many">;
|
|
141
|
+
}, "strip", z.ZodTypeAny, {
|
|
142
|
+
default: z.objectOutputType<{
|
|
143
|
+
id: z.ZodString;
|
|
144
|
+
type: z.ZodString;
|
|
145
|
+
}, z.ZodTypeAny, "passthrough">[];
|
|
146
|
+
cases: {
|
|
147
|
+
steps: z.objectOutputType<{
|
|
148
|
+
id: z.ZodString;
|
|
149
|
+
type: z.ZodString;
|
|
150
|
+
}, z.ZodTypeAny, "passthrough">[];
|
|
151
|
+
condition: import("../../types/workflow-config.js").Condition;
|
|
152
|
+
label?: string | undefined;
|
|
153
|
+
}[];
|
|
154
|
+
}, {
|
|
155
|
+
default: z.objectInputType<{
|
|
156
|
+
id: z.ZodString;
|
|
157
|
+
type: z.ZodString;
|
|
158
|
+
}, z.ZodTypeAny, "passthrough">[];
|
|
159
|
+
cases: {
|
|
160
|
+
steps: z.objectInputType<{
|
|
161
|
+
id: z.ZodString;
|
|
162
|
+
type: z.ZodString;
|
|
163
|
+
}, z.ZodTypeAny, "passthrough">[];
|
|
164
|
+
condition: import("../../types/workflow-config.js").Condition;
|
|
165
|
+
label?: string | undefined;
|
|
166
|
+
}[];
|
|
167
|
+
}>;
|
|
168
|
+
readonly outputSchema: z.ZodObject<{
|
|
169
|
+
branch: z.ZodString;
|
|
170
|
+
caseIndex: z.ZodNullable<z.ZodNumber>;
|
|
171
|
+
label: z.ZodNullable<z.ZodString>;
|
|
172
|
+
}, "strip", z.ZodTypeAny, {
|
|
173
|
+
branch: string;
|
|
174
|
+
label: string | null;
|
|
175
|
+
caseIndex: number | null;
|
|
176
|
+
}, {
|
|
177
|
+
branch: string;
|
|
178
|
+
label: string | null;
|
|
179
|
+
caseIndex: number | null;
|
|
180
|
+
}>;
|
|
181
|
+
readonly category: "control";
|
|
182
|
+
readonly icon = "switch";
|
|
183
|
+
readonly declaredOutputs: readonly [{
|
|
184
|
+
readonly key: "branch";
|
|
185
|
+
readonly label: "Matched branch key";
|
|
186
|
+
}, {
|
|
187
|
+
readonly key: "caseIndex";
|
|
188
|
+
readonly label: "Matched case index";
|
|
189
|
+
}, {
|
|
190
|
+
readonly key: "label";
|
|
191
|
+
readonly label: "Matched case label";
|
|
192
|
+
}];
|
|
193
|
+
/**
|
|
194
|
+
* Expose every branch (each case + default) so the config validator can
|
|
195
|
+
* walk forward references inside each one independently.
|
|
196
|
+
*/
|
|
197
|
+
getBranches(config: Record<string, unknown>): Record<string, WorkflowStepConfig[]>;
|
|
198
|
+
execute(config: SwitchStepConfig, ctx: ControlFlowExecutionContext): Promise<SwitchStepOutput>;
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=switch.step.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switch.step.d.ts","sourceRoot":"","sources":["../../../src/steps/builtin/switch.step.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAgBzE,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAMjC,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAItE,MAAM,WAAW,gBAAiB,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC/D,qGAAqG;IACrG,MAAM,EAAE,MAAM,CAAC;IACf,+DAA+D;IAC/D,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,sFAAsF;IACtF,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAaD,qBAAa,UAAW,SAAQ,mBAAmB,CACjD,OAAO,sBAAsB,EAC7B,gBAAgB,CACjB;IACC,SAAkB,IAAI,0BAA0B;IAChD,SAAkB,IAAI,YAAY;IAClC,SAAkB,WAAW,6EAA6E;IAC1G,SAAkB,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAA0B;IACxD,SAAkB,YAAY;;;;;;;;;;;;OAA0B;IACxD,SAAkB,QAAQ,EAAG,SAAS,CAAU;IAChD,SAAkB,IAAI,YAAY;IAClC,SAAkB,eAAe;;;;;;;;;OAItB;IAEX;;;OAGG;IACM,WAAW,CAClB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,MAAM,CAAC,MAAM,EAAE,kBAAkB,EAAE,CAAC;IAUxB,OAAO,CACpB,MAAM,EAAE,gBAAgB,EACxB,GAAG,EAAE,2BAA2B,GAC/B,OAAO,CAAC,gBAAgB,CAAC;CA+B7B"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SWITCH step — first-match-wins over an ordered list of conditional cases,
|
|
3
|
+
* with a guaranteed `default` fallback.
|
|
4
|
+
*
|
|
5
|
+
* Semantics (no fall-through):
|
|
6
|
+
*
|
|
7
|
+
* for (const [i, c] of cases.entries())
|
|
8
|
+
* if (evaluator.evaluate(c.condition, ctx.workflow)) {
|
|
9
|
+
* walkBranch(c.steps, `case_${i}`)
|
|
10
|
+
* return { branch: `case_${i}`, caseIndex: i, label: c.label ?? null }
|
|
11
|
+
* }
|
|
12
|
+
* walkBranch(default, 'default')
|
|
13
|
+
* return { branch: 'default', caseIndex: null, label: null }
|
|
14
|
+
*
|
|
15
|
+
* Branch keys are positional (`case_0`, `case_1`, ..., `default`) so a
|
|
16
|
+
* paused execution's PausePath survives label edits.
|
|
17
|
+
*/
|
|
18
|
+
import { z } from 'zod';
|
|
19
|
+
import { BaseControlFlowStep } from '../base-step.js';
|
|
20
|
+
import { BuiltinStepType } from '../../types/known-types.js';
|
|
21
|
+
import { ConditionSchema } from '../../types/workflow-config.js';
|
|
22
|
+
import { ConditionEvaluator } from '../../engine/condition-evaluator.js';
|
|
23
|
+
// ─── Config ───
|
|
24
|
+
const SwitchCaseSchema = z.object({
|
|
25
|
+
condition: ConditionSchema
|
|
26
|
+
.describe('Recursive condition tree (leaf or all/any composite). First case whose condition is true wins.'),
|
|
27
|
+
label: z.string().optional()
|
|
28
|
+
.describe('Optional UI label for this case. Not used for routing — branch keys are positional.'),
|
|
29
|
+
steps: z.array(z.object({ id: z.string(), type: z.string() }).passthrough()).describe('Steps to execute when this case wins.'),
|
|
30
|
+
});
|
|
31
|
+
export const SwitchStepConfigSchema = z.object({
|
|
32
|
+
cases: z.array(SwitchCaseSchema)
|
|
33
|
+
.describe('Ordered cases. Evaluated top-to-bottom; first match wins, no fall-through.'),
|
|
34
|
+
default: z.array(z.object({ id: z.string(), type: z.string() }).passthrough()).describe('Fallback branch. Runs when no case matches. Use `[]` to no-op the fallback.'),
|
|
35
|
+
});
|
|
36
|
+
const SwitchStepOutputSchema = z.object({
|
|
37
|
+
branch: z.string(),
|
|
38
|
+
caseIndex: z.number().int().nullable(),
|
|
39
|
+
label: z.string().nullable(),
|
|
40
|
+
});
|
|
41
|
+
// ─── Step ───
|
|
42
|
+
const DEFAULT_BRANCH_KEY = 'default';
|
|
43
|
+
const caseBranchKey = (i) => `case_${i}`;
|
|
44
|
+
export class SwitchStep extends BaseControlFlowStep {
|
|
45
|
+
type = BuiltinStepType.SWITCH;
|
|
46
|
+
name = 'Switch';
|
|
47
|
+
description = 'Route to one of N branches; first matching case wins, otherwise default';
|
|
48
|
+
configSchema = SwitchStepConfigSchema;
|
|
49
|
+
outputSchema = SwitchStepOutputSchema;
|
|
50
|
+
category = 'control';
|
|
51
|
+
icon = 'switch';
|
|
52
|
+
declaredOutputs = [
|
|
53
|
+
{ key: 'branch', label: 'Matched branch key' },
|
|
54
|
+
{ key: 'caseIndex', label: 'Matched case index' },
|
|
55
|
+
{ key: 'label', label: 'Matched case label' },
|
|
56
|
+
];
|
|
57
|
+
/**
|
|
58
|
+
* Expose every branch (each case + default) so the config validator can
|
|
59
|
+
* walk forward references inside each one independently.
|
|
60
|
+
*/
|
|
61
|
+
getBranches(config) {
|
|
62
|
+
const branches = {};
|
|
63
|
+
const cases = (config['cases'] ?? []);
|
|
64
|
+
for (let i = 0; i < cases.length; i++) {
|
|
65
|
+
branches[caseBranchKey(i)] = (cases[i]?.steps ?? []);
|
|
66
|
+
}
|
|
67
|
+
branches[DEFAULT_BRANCH_KEY] = (config['default'] ?? []);
|
|
68
|
+
return branches;
|
|
69
|
+
}
|
|
70
|
+
async execute(config, ctx) {
|
|
71
|
+
const evaluator = new ConditionEvaluator();
|
|
72
|
+
for (let i = 0; i < config.cases.length; i++) {
|
|
73
|
+
const entry = config.cases[i];
|
|
74
|
+
if (evaluator.evaluate(entry.condition, ctx.workflow)) {
|
|
75
|
+
const branchKey = caseBranchKey(i);
|
|
76
|
+
if (entry.steps.length > 0) {
|
|
77
|
+
await ctx.walkBranch(entry.steps, ctx.workflow, branchKey);
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
branch: branchKey,
|
|
81
|
+
caseIndex: i,
|
|
82
|
+
label: entry.label ?? null,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (config.default.length > 0) {
|
|
87
|
+
await ctx.walkBranch(config.default, ctx.workflow, DEFAULT_BRANCH_KEY);
|
|
88
|
+
}
|
|
89
|
+
return { branch: DEFAULT_BRANCH_KEY, caseIndex: null, label: null };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=switch.step.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":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|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TRANSFORM step — pure data manipulation.
|
|
3
|
+
*
|
|
4
|
+
* Applies a sequence of operations to the workflow context:
|
|
5
|
+
* - set: write a value at a dotted path
|
|
6
|
+
* - rename: move a value from one path to another
|
|
7
|
+
* - remove: delete a value at a dotted path
|
|
8
|
+
* - copy: copy a value from one path to another
|
|
9
|
+
*
|
|
10
|
+
* No services, no credentials — pure deterministic logic.
|
|
11
|
+
*/
|
|
12
|
+
import { z } from 'zod';
|
|
13
|
+
import { BaseActionStep } from '../base-step.js';
|
|
14
|
+
import type { StepExecutionContext } from '../base-step.js';
|
|
15
|
+
import { BuiltinStepType } from '../../types/known-types.js';
|
|
16
|
+
import type { StepCategory } from '../../types/categories.js';
|
|
17
|
+
export declare const TransformOpSchema: z.ZodDiscriminatedUnion<"op", [z.ZodObject<{
|
|
18
|
+
op: z.ZodLiteral<"set">;
|
|
19
|
+
path: z.ZodString;
|
|
20
|
+
value: z.ZodUnknown;
|
|
21
|
+
}, "strip", z.ZodTypeAny, {
|
|
22
|
+
op: "set";
|
|
23
|
+
path: string;
|
|
24
|
+
value?: unknown;
|
|
25
|
+
}, {
|
|
26
|
+
op: "set";
|
|
27
|
+
path: string;
|
|
28
|
+
value?: unknown;
|
|
29
|
+
}>, z.ZodObject<{
|
|
30
|
+
op: z.ZodLiteral<"rename">;
|
|
31
|
+
from: z.ZodString;
|
|
32
|
+
to: z.ZodString;
|
|
33
|
+
}, "strip", z.ZodTypeAny, {
|
|
34
|
+
op: "rename";
|
|
35
|
+
from: string;
|
|
36
|
+
to: string;
|
|
37
|
+
}, {
|
|
38
|
+
op: "rename";
|
|
39
|
+
from: string;
|
|
40
|
+
to: string;
|
|
41
|
+
}>, z.ZodObject<{
|
|
42
|
+
op: z.ZodLiteral<"remove">;
|
|
43
|
+
path: z.ZodString;
|
|
44
|
+
}, "strip", z.ZodTypeAny, {
|
|
45
|
+
op: "remove";
|
|
46
|
+
path: string;
|
|
47
|
+
}, {
|
|
48
|
+
op: "remove";
|
|
49
|
+
path: string;
|
|
50
|
+
}>, z.ZodObject<{
|
|
51
|
+
op: z.ZodLiteral<"copy">;
|
|
52
|
+
from: z.ZodString;
|
|
53
|
+
to: z.ZodString;
|
|
54
|
+
}, "strip", z.ZodTypeAny, {
|
|
55
|
+
op: "copy";
|
|
56
|
+
from: string;
|
|
57
|
+
to: string;
|
|
58
|
+
}, {
|
|
59
|
+
op: "copy";
|
|
60
|
+
from: string;
|
|
61
|
+
to: string;
|
|
62
|
+
}>]>;
|
|
63
|
+
export type TransformOp = z.infer<typeof TransformOpSchema>;
|
|
64
|
+
export declare const TransformStepConfigSchema: z.ZodObject<{
|
|
65
|
+
operations: z.ZodArray<z.ZodDiscriminatedUnion<"op", [z.ZodObject<{
|
|
66
|
+
op: z.ZodLiteral<"set">;
|
|
67
|
+
path: z.ZodString;
|
|
68
|
+
value: z.ZodUnknown;
|
|
69
|
+
}, "strip", z.ZodTypeAny, {
|
|
70
|
+
op: "set";
|
|
71
|
+
path: string;
|
|
72
|
+
value?: unknown;
|
|
73
|
+
}, {
|
|
74
|
+
op: "set";
|
|
75
|
+
path: string;
|
|
76
|
+
value?: unknown;
|
|
77
|
+
}>, z.ZodObject<{
|
|
78
|
+
op: z.ZodLiteral<"rename">;
|
|
79
|
+
from: z.ZodString;
|
|
80
|
+
to: z.ZodString;
|
|
81
|
+
}, "strip", z.ZodTypeAny, {
|
|
82
|
+
op: "rename";
|
|
83
|
+
from: string;
|
|
84
|
+
to: string;
|
|
85
|
+
}, {
|
|
86
|
+
op: "rename";
|
|
87
|
+
from: string;
|
|
88
|
+
to: string;
|
|
89
|
+
}>, z.ZodObject<{
|
|
90
|
+
op: z.ZodLiteral<"remove">;
|
|
91
|
+
path: z.ZodString;
|
|
92
|
+
}, "strip", z.ZodTypeAny, {
|
|
93
|
+
op: "remove";
|
|
94
|
+
path: string;
|
|
95
|
+
}, {
|
|
96
|
+
op: "remove";
|
|
97
|
+
path: string;
|
|
98
|
+
}>, z.ZodObject<{
|
|
99
|
+
op: z.ZodLiteral<"copy">;
|
|
100
|
+
from: z.ZodString;
|
|
101
|
+
to: z.ZodString;
|
|
102
|
+
}, "strip", z.ZodTypeAny, {
|
|
103
|
+
op: "copy";
|
|
104
|
+
from: string;
|
|
105
|
+
to: string;
|
|
106
|
+
}, {
|
|
107
|
+
op: "copy";
|
|
108
|
+
from: string;
|
|
109
|
+
to: string;
|
|
110
|
+
}>]>, "many">;
|
|
111
|
+
}, "strip", z.ZodTypeAny, {
|
|
112
|
+
operations: ({
|
|
113
|
+
op: "set";
|
|
114
|
+
path: string;
|
|
115
|
+
value?: unknown;
|
|
116
|
+
} | {
|
|
117
|
+
op: "rename";
|
|
118
|
+
from: string;
|
|
119
|
+
to: string;
|
|
120
|
+
} | {
|
|
121
|
+
op: "remove";
|
|
122
|
+
path: string;
|
|
123
|
+
} | {
|
|
124
|
+
op: "copy";
|
|
125
|
+
from: string;
|
|
126
|
+
to: string;
|
|
127
|
+
})[];
|
|
128
|
+
}, {
|
|
129
|
+
operations: ({
|
|
130
|
+
op: "set";
|
|
131
|
+
path: string;
|
|
132
|
+
value?: unknown;
|
|
133
|
+
} | {
|
|
134
|
+
op: "rename";
|
|
135
|
+
from: string;
|
|
136
|
+
to: string;
|
|
137
|
+
} | {
|
|
138
|
+
op: "remove";
|
|
139
|
+
path: string;
|
|
140
|
+
} | {
|
|
141
|
+
op: "copy";
|
|
142
|
+
from: string;
|
|
143
|
+
to: string;
|
|
144
|
+
})[];
|
|
145
|
+
}>;
|
|
146
|
+
export type TransformStepConfig = z.infer<typeof TransformStepConfigSchema>;
|
|
147
|
+
export interface TransformStepOutput extends Record<string, unknown> {
|
|
148
|
+
applied: number;
|
|
149
|
+
}
|
|
150
|
+
export declare class TransformStep extends BaseActionStep<typeof TransformStepConfigSchema, TransformStepOutput> {
|
|
151
|
+
readonly type = BuiltinStepType.TRANSFORM;
|
|
152
|
+
readonly name = "Transform";
|
|
153
|
+
readonly description = "Apply data transformations to the workflow context";
|
|
154
|
+
readonly configSchema: z.ZodObject<{
|
|
155
|
+
operations: z.ZodArray<z.ZodDiscriminatedUnion<"op", [z.ZodObject<{
|
|
156
|
+
op: z.ZodLiteral<"set">;
|
|
157
|
+
path: z.ZodString;
|
|
158
|
+
value: z.ZodUnknown;
|
|
159
|
+
}, "strip", z.ZodTypeAny, {
|
|
160
|
+
op: "set";
|
|
161
|
+
path: string;
|
|
162
|
+
value?: unknown;
|
|
163
|
+
}, {
|
|
164
|
+
op: "set";
|
|
165
|
+
path: string;
|
|
166
|
+
value?: unknown;
|
|
167
|
+
}>, z.ZodObject<{
|
|
168
|
+
op: z.ZodLiteral<"rename">;
|
|
169
|
+
from: z.ZodString;
|
|
170
|
+
to: z.ZodString;
|
|
171
|
+
}, "strip", z.ZodTypeAny, {
|
|
172
|
+
op: "rename";
|
|
173
|
+
from: string;
|
|
174
|
+
to: string;
|
|
175
|
+
}, {
|
|
176
|
+
op: "rename";
|
|
177
|
+
from: string;
|
|
178
|
+
to: string;
|
|
179
|
+
}>, z.ZodObject<{
|
|
180
|
+
op: z.ZodLiteral<"remove">;
|
|
181
|
+
path: z.ZodString;
|
|
182
|
+
}, "strip", z.ZodTypeAny, {
|
|
183
|
+
op: "remove";
|
|
184
|
+
path: string;
|
|
185
|
+
}, {
|
|
186
|
+
op: "remove";
|
|
187
|
+
path: string;
|
|
188
|
+
}>, z.ZodObject<{
|
|
189
|
+
op: z.ZodLiteral<"copy">;
|
|
190
|
+
from: z.ZodString;
|
|
191
|
+
to: z.ZodString;
|
|
192
|
+
}, "strip", z.ZodTypeAny, {
|
|
193
|
+
op: "copy";
|
|
194
|
+
from: string;
|
|
195
|
+
to: string;
|
|
196
|
+
}, {
|
|
197
|
+
op: "copy";
|
|
198
|
+
from: string;
|
|
199
|
+
to: string;
|
|
200
|
+
}>]>, "many">;
|
|
201
|
+
}, "strip", z.ZodTypeAny, {
|
|
202
|
+
operations: ({
|
|
203
|
+
op: "set";
|
|
204
|
+
path: string;
|
|
205
|
+
value?: unknown;
|
|
206
|
+
} | {
|
|
207
|
+
op: "rename";
|
|
208
|
+
from: string;
|
|
209
|
+
to: string;
|
|
210
|
+
} | {
|
|
211
|
+
op: "remove";
|
|
212
|
+
path: string;
|
|
213
|
+
} | {
|
|
214
|
+
op: "copy";
|
|
215
|
+
from: string;
|
|
216
|
+
to: string;
|
|
217
|
+
})[];
|
|
218
|
+
}, {
|
|
219
|
+
operations: ({
|
|
220
|
+
op: "set";
|
|
221
|
+
path: string;
|
|
222
|
+
value?: unknown;
|
|
223
|
+
} | {
|
|
224
|
+
op: "rename";
|
|
225
|
+
from: string;
|
|
226
|
+
to: string;
|
|
227
|
+
} | {
|
|
228
|
+
op: "remove";
|
|
229
|
+
path: string;
|
|
230
|
+
} | {
|
|
231
|
+
op: "copy";
|
|
232
|
+
from: string;
|
|
233
|
+
to: string;
|
|
234
|
+
})[];
|
|
235
|
+
}>;
|
|
236
|
+
readonly outputSchema: z.ZodObject<{
|
|
237
|
+
applied: z.ZodNumber;
|
|
238
|
+
}, "strip", z.ZodTypeAny, {
|
|
239
|
+
applied: number;
|
|
240
|
+
}, {
|
|
241
|
+
applied: number;
|
|
242
|
+
}>;
|
|
243
|
+
readonly category: StepCategory;
|
|
244
|
+
readonly icon = "filter";
|
|
245
|
+
execute(config: TransformStepConfig, ctx: StepExecutionContext): Promise<TransformStepOutput>;
|
|
246
|
+
}
|
|
247
|
+
//# sourceMappingURL=transform.step.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.step.d.ts","sourceRoot":"","sources":["../../../src/steps/builtin/transform.step.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB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|
|
5
|
+
* - set: write a value at a dotted path
|
|
6
|
+
* - rename: move a value from one path to another
|
|
7
|
+
* - remove: delete a value at a dotted path
|
|
8
|
+
* - copy: copy a value from one path to another
|
|
9
|
+
*
|
|
10
|
+
* No services, no credentials — pure deterministic logic.
|
|
11
|
+
*/
|
|
12
|
+
import { z } from 'zod';
|
|
13
|
+
import { BaseActionStep } from '../base-step.js';
|
|
14
|
+
import { BuiltinStepType } from '../../types/known-types.js';
|
|
15
|
+
import { resolvePath } from '../../engine/variable-resolver.js';
|
|
16
|
+
// ─── Config ───
|
|
17
|
+
const SetOpSchema = z.object({
|
|
18
|
+
op: z.literal('set'),
|
|
19
|
+
path: z.string().min(1).describe('Dotted path where the value will be written'),
|
|
20
|
+
value: z.unknown().describe('Value to set at the path'),
|
|
21
|
+
});
|
|
22
|
+
const RenameOpSchema = z.object({
|
|
23
|
+
op: z.literal('rename'),
|
|
24
|
+
from: z.string().min(1).describe('Source dotted path'),
|
|
25
|
+
to: z.string().min(1).describe('Destination dotted path'),
|
|
26
|
+
});
|
|
27
|
+
const RemoveOpSchema = z.object({
|
|
28
|
+
op: z.literal('remove'),
|
|
29
|
+
path: z.string().min(1).describe('Dotted path to delete'),
|
|
30
|
+
});
|
|
31
|
+
const CopyOpSchema = z.object({
|
|
32
|
+
op: z.literal('copy'),
|
|
33
|
+
from: z.string().min(1).describe('Source dotted path'),
|
|
34
|
+
to: z.string().min(1).describe('Destination dotted path'),
|
|
35
|
+
});
|
|
36
|
+
export const TransformOpSchema = z.discriminatedUnion('op', [
|
|
37
|
+
SetOpSchema,
|
|
38
|
+
RenameOpSchema,
|
|
39
|
+
RemoveOpSchema,
|
|
40
|
+
CopyOpSchema,
|
|
41
|
+
]);
|
|
42
|
+
export const TransformStepConfigSchema = z.object({
|
|
43
|
+
operations: z.array(TransformOpSchema).min(1).describe('Sequence of data transformation operations to apply'),
|
|
44
|
+
});
|
|
45
|
+
const TransformStepOutputSchema = z.object({
|
|
46
|
+
applied: z.number(),
|
|
47
|
+
});
|
|
48
|
+
// ─── Helpers ───
|
|
49
|
+
/**
|
|
50
|
+
* Set a value at a dotted path on a target object.
|
|
51
|
+
* Creates intermediate objects as needed.
|
|
52
|
+
*/
|
|
53
|
+
function setAtPath(target, path, value) {
|
|
54
|
+
const parts = path.split('.');
|
|
55
|
+
let current = target;
|
|
56
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
57
|
+
const key = parts[i];
|
|
58
|
+
if (current[key] === undefined ||
|
|
59
|
+
current[key] === null ||
|
|
60
|
+
typeof current[key] !== 'object') {
|
|
61
|
+
current[key] = {};
|
|
62
|
+
}
|
|
63
|
+
current = current[key];
|
|
64
|
+
}
|
|
65
|
+
current[parts[parts.length - 1]] = value;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Delete a value at a dotted path.
|
|
69
|
+
*/
|
|
70
|
+
function deleteAtPath(target, path) {
|
|
71
|
+
const parts = path.split('.');
|
|
72
|
+
let current = target;
|
|
73
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
74
|
+
const key = parts[i];
|
|
75
|
+
if (current[key] === undefined ||
|
|
76
|
+
current[key] === null ||
|
|
77
|
+
typeof current[key] !== 'object') {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
current = current[key];
|
|
81
|
+
}
|
|
82
|
+
const lastKey = parts[parts.length - 1];
|
|
83
|
+
if (lastKey in current) {
|
|
84
|
+
delete current[lastKey];
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
// ─── Step ───
|
|
90
|
+
export class TransformStep extends BaseActionStep {
|
|
91
|
+
type = BuiltinStepType.TRANSFORM;
|
|
92
|
+
name = 'Transform';
|
|
93
|
+
description = 'Apply data transformations to the workflow context';
|
|
94
|
+
configSchema = TransformStepConfigSchema;
|
|
95
|
+
outputSchema = TransformStepOutputSchema;
|
|
96
|
+
category = 'data';
|
|
97
|
+
icon = 'filter';
|
|
98
|
+
async execute(config, ctx) {
|
|
99
|
+
let applied = 0;
|
|
100
|
+
// Operate on the steps record
|
|
101
|
+
const data = ctx.workflow.steps;
|
|
102
|
+
for (const op of config.operations) {
|
|
103
|
+
switch (op.op) {
|
|
104
|
+
case 'set':
|
|
105
|
+
setAtPath(data, op.path, op.value);
|
|
106
|
+
applied++;
|
|
107
|
+
break;
|
|
108
|
+
case 'rename': {
|
|
109
|
+
const value = resolvePath(ctx.workflow, op.from);
|
|
110
|
+
if (value !== undefined) {
|
|
111
|
+
setAtPath(data, op.to, value);
|
|
112
|
+
deleteAtPath(data, op.from);
|
|
113
|
+
applied++;
|
|
114
|
+
}
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
case 'remove':
|
|
118
|
+
if (deleteAtPath(data, op.path)) {
|
|
119
|
+
applied++;
|
|
120
|
+
}
|
|
121
|
+
break;
|
|
122
|
+
case 'copy': {
|
|
123
|
+
const val = resolvePath(ctx.workflow, op.from);
|
|
124
|
+
if (val !== undefined) {
|
|
125
|
+
setAtPath(data, op.to, val);
|
|
126
|
+
applied++;
|
|
127
|
+
}
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return { applied };
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=transform.step.js.map
|