@codemation/core 0.13.2 → 0.15.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/CHANGELOG.md +167 -0
- package/dist/{CostCatalogContract-Dxq1BTyi.d.cts → CostCatalogContract-Dwo-ZamG.d.cts} +2 -2
- package/dist/EngineRuntimeRegistration.types-BiNasx3G.d.cts +54 -0
- package/dist/EngineRuntimeRegistration.types-Dq4ucrdo.d.ts +21 -0
- package/dist/{InMemoryRunDataFactory-Csy2evr_.d.cts → InMemoryRunDataFactory-D2U9azmZ.d.cts} +4 -20
- package/dist/{InMemoryRunEventBusRegistry-Sa86VxuV.cjs → InMemoryRunEventBusRegistry-DO0WM9Lw.cjs} +1 -1
- package/dist/{InMemoryRunEventBusRegistry-Sa86VxuV.cjs.map → InMemoryRunEventBusRegistry-DO0WM9Lw.cjs.map} +1 -1
- package/dist/{InMemoryRunEventBusRegistry-Bwunvt1T.js → InMemoryRunEventBusRegistry-Layt2xgm.js} +1 -1
- package/dist/{InMemoryRunEventBusRegistry-Bwunvt1T.js.map → InMemoryRunEventBusRegistry-Layt2xgm.js.map} +1 -1
- package/dist/{ItemsInputNormalizer-Bi8m-Ijs.d.cts → ItemsInputNormalizer-A5txcOWX.d.cts} +3 -98
- package/dist/{ItemsInputNormalizer-BbQTSEkZ.cjs → ItemsInputNormalizer-C1fv3sMW.cjs} +2 -2
- package/dist/ItemsInputNormalizer-C1fv3sMW.cjs.map +1 -0
- package/dist/{ItemsInputNormalizer-BYljnXU0.d.ts → ItemsInputNormalizer-D2vrMrX1.d.ts} +2 -62
- package/dist/{ItemsInputNormalizer-CSZGMgl3.js → ItemsInputNormalizer-fUYo4GLV.js} +2 -2
- package/dist/ItemsInputNormalizer-fUYo4GLV.js.map +1 -0
- package/dist/{RunIntentService-BitgkKaT.d.cts → RunIntentService-DKxuHTUz.d.cts} +2 -15
- package/dist/{RunIntentService-DYpqfu6D.d.ts → RunIntentService-DrpKli2k.d.ts} +2 -22
- package/dist/{agentMcpTypes-DGIwk6Ue.d.cts → agentMcpTypes-BHX4RQCC.d.cts} +25 -518
- package/dist/bootstrap/index.cjs +9 -5
- package/dist/bootstrap/index.d.cts +32 -106
- package/dist/bootstrap/index.d.ts +18 -17
- package/dist/bootstrap/index.js +6 -5
- package/dist/{bootstrap-DIv-vloi.cjs → bootstrap-CTB53rEF.cjs} +9 -60
- package/dist/bootstrap-CTB53rEF.cjs.map +1 -0
- package/dist/{bootstrap-Bkd-Nfbn.js → bootstrap-DmqKheCI.js} +6 -57
- package/dist/bootstrap-DmqKheCI.js.map +1 -0
- package/dist/browser.cjs +12 -11
- package/dist/browser.d.cts +4 -4
- package/dist/browser.d.ts +3 -3
- package/dist/browser.js +3 -2
- package/dist/contracts-7L1wJHdk.cjs +569 -0
- package/dist/contracts-7L1wJHdk.cjs.map +1 -0
- package/dist/contracts-CjJ5CZ7N.js +447 -0
- package/dist/contracts-CjJ5CZ7N.js.map +1 -0
- package/dist/contracts.cjs +9 -2
- package/dist/contracts.d.cts +5 -5
- package/dist/contracts.d.ts +2 -2
- package/dist/contracts.js +3 -2
- package/dist/{executionPersistenceContracts-CN9d7AnL.d.cts → deploymentManifestTypes-B8CDmZZK.d.cts} +65 -81
- package/dist/di-C6Ubf9o5.cjs +179 -0
- package/dist/di-C6Ubf9o5.cjs.map +1 -0
- package/dist/di-Cjiil7U-.js +114 -0
- package/dist/di-Cjiil7U-.js.map +1 -0
- package/dist/{index-rllWL4r-.d.ts → index-CRv3_pY3.d.ts} +112 -808
- package/dist/{index-BSQ2LoIh.d.ts → index-mnLS0iQl.d.ts} +39 -372
- package/dist/index.cjs +53 -111
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +50 -438
- package/dist/index.d.ts +5 -5
- package/dist/index.js +28 -94
- package/dist/index.js.map +1 -1
- package/dist/{params-DRUr0F5v.d.cts → params-CrK4iuG1.d.cts} +3 -13
- package/dist/{runtime-CWPdvJpC.js → runtime-CBFDpmiz.js} +112 -648
- package/dist/runtime-CBFDpmiz.js.map +1 -0
- package/dist/{runtime-_VdHwGkJ.cjs → runtime-Due-FOZ2.cjs} +137 -717
- package/dist/runtime-Due-FOZ2.cjs.map +1 -0
- package/dist/testing.cjs +8 -40
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +3 -32
- package/dist/testing.d.ts +3 -32
- package/dist/testing.js +6 -38
- package/dist/testing.js.map +1 -1
- package/dist/{di-LP2qSHkY.cjs → workflowTypes-BW6Hhee7.cjs} +4 -230
- package/dist/workflowTypes-BW6Hhee7.cjs.map +1 -0
- package/dist/{di-tom0pM2h.js → workflowTypes-DZtBTmKf.js} +3 -163
- package/dist/workflowTypes-DZtBTmKf.js.map +1 -0
- package/package.json +1 -1
- package/src/ai/AgentConnectionNodeCollector.ts +0 -4
- package/src/ai/AgentMessageConfigNormalizerFactory.ts +0 -4
- package/src/ai/AiHost.ts +0 -38
- package/src/ai/CallableToolConfig.ts +0 -9
- package/src/ai/CallableToolKindToken.ts +0 -4
- package/src/authoring/callableTool.types.ts +0 -3
- package/src/authoring/defineCollection.types.ts +0 -11
- package/src/authoring/defineHumanApprovalNode.types.ts +0 -116
- package/src/authoring/defineNode.types.ts +18 -32
- package/src/authoring/definePollingTrigger.types.ts +36 -155
- package/src/authoring/definePollingTriggerInternals.ts +0 -4
- package/src/authoring/index.ts +1 -0
- package/src/authoring/nodeBaseOptions.types.ts +4 -0
- package/src/binaries/boundedReadBinary.types.ts +0 -16
- package/src/bootstrap/index.ts +8 -2
- package/src/bootstrap/runtime/EngineRuntimeRegistrar.ts +0 -5
- package/src/bootstrap/runtime/EngineRuntimeRegistration.types.ts +0 -23
- package/src/browser.ts +0 -3
- package/src/contracts/AgentBindError.ts +0 -5
- package/src/contracts/Clock.ts +0 -1
- package/src/contracts/CodemationTelemetryAttributeNames.ts +0 -10
- package/src/contracts/NoOpAgentMcpIntegration.ts +0 -6
- package/src/contracts/NoOpTelemetrySpanScope.ts +0 -7
- package/src/contracts/RetryPolicy.ts +0 -2
- package/src/contracts/agentMcpTypes.ts +0 -34
- package/src/contracts/assertionTypes.ts +0 -33
- package/src/contracts/baseTypes.ts +0 -6
- package/src/contracts/collectionTypes.ts +0 -25
- package/src/contracts/credentialTypes.ts +13 -60
- package/src/contracts/deploymentManifestTypes.ts +158 -0
- package/src/contracts/dispatchTypes.ts +29 -0
- package/src/contracts/executionPersistenceContracts.ts +0 -33
- package/src/contracts/hitlSeamTypes.ts +0 -14
- package/src/contracts/humanTaskStoreTypes.ts +0 -2
- package/src/contracts/inboxChannelTypes.ts +0 -9
- package/src/contracts/index.ts +3 -0
- package/src/contracts/itemExpr.ts +7 -21
- package/src/contracts/itemMeta.ts +0 -3
- package/src/contracts/mcpTypes.ts +0 -16
- package/src/contracts/retryPolicySpec.types.ts +0 -10
- package/src/contracts/runFinishedAtFactory.ts +0 -1
- package/src/contracts/runTypes.ts +0 -74
- package/src/contracts/runtimeTypes.ts +4 -131
- package/src/contracts/telemetryTypes.ts +0 -7
- package/src/contracts/testTriggerTypes.ts +0 -43
- package/src/contracts/triggerInvokerTypes.ts +6 -0
- package/src/contracts/webhookTypes.ts +0 -8
- package/src/contracts/workflowActivationPolicy.ts +0 -5
- package/src/contracts/workflowTypes.ts +5 -80
- package/src/contracts/workspaceFileTypes.ts +10 -42
- package/src/contracts.ts +18 -10
- package/src/credentials/CredentialMaterialProvider.types.ts +0 -28
- package/src/credentials/ManagedCredentialMaterialWriteError.ts +0 -6
- package/src/credentials/ManagedMaterialFetchError.ts +0 -6
- package/src/credentials/OAuthFlowExecutor.types.ts +0 -15
- package/src/di/CoreTokens.ts +2 -6
- package/src/events/ConnectionInvocationEventPublisher.ts +0 -7
- package/src/events/NodeEventPublisher.ts +0 -1
- package/src/events/runEvents.ts +0 -8
- package/src/execution/ActivationEnqueueService.ts +0 -10
- package/src/execution/ChildExecutionScopeFactory.ts +0 -13
- package/src/execution/FanInMergeByOriginMerger.ts +0 -11
- package/src/execution/InProcessRetryRunner.ts +0 -1
- package/src/execution/ItemExprResolver.ts +0 -3
- package/src/execution/NodeActivationRequestComposer.ts +0 -3
- package/src/execution/NodeActivationRequestInputPreparer.ts +0 -5
- package/src/execution/NodeExecutionSnapshotFactory.ts +0 -1
- package/src/execution/NodeExecutor.ts +1 -17
- package/src/execution/NodeOutputNormalizer.ts +8 -1
- package/src/execution/NodeSuspensionHandler.ts +1 -39
- package/src/execution/PersistedRunStateTerminalBuilder.ts +0 -5
- package/src/execution/RunSuspendedError.ts +0 -10
- package/src/execution/RunnableOutputBehaviorResolver.ts +12 -0
- package/src/execution/WorkflowRunExecutionContextFactory.ts +0 -3
- package/src/index.ts +10 -2
- package/src/orchestration/AbortControllerFactory.ts +0 -4
- package/src/orchestration/Engine.ts +0 -9
- package/src/orchestration/NodeExecutionRequestHandlerService.ts +3 -4
- package/src/orchestration/RunContinuationService.ts +7 -39
- package/src/orchestration/RunStartService.ts +0 -7
- package/src/orchestration/TestSuiteOrchestrator.ts +0 -18
- package/src/orchestration/TestSuiteRunIdFactory.ts +0 -4
- package/src/orchestration/TriggerRuntimeService.ts +3 -2
- package/src/planning/CurrentStateFrontierPlanner.ts +0 -1
- package/src/planning/RunQueuePlanner.ts +0 -6
- package/src/policies/executionLimits/EngineExecutionLimitsPolicy.ts +0 -8
- package/src/policies/executionLimits/EngineExecutionLimitsPolicyFactory.ts +0 -3
- package/src/runStorage/RunSummaryMapper.ts +0 -1
- package/src/runtime/EngineFactory.ts +6 -11
- package/src/runtime/RunIntentService.ts +0 -4
- package/src/runtime/WorkflowRepositoryWebhookTriggerMatcher.ts +0 -4
- package/src/runtime-types/InjectableRuntimeDecoratorComposerRegistry.ts +0 -4
- package/src/runtime-types/PersistedRuntimeTypeMetadataStoreRegistry.ts +0 -4
- package/src/runtime-types/PersistedRuntimeTypeNameResolver.ts +0 -1
- package/src/runtime-types/persistedRuntimeTypeModelRegistry.ts +0 -4
- package/src/runtime-types/runtimeTypeDecorators.types.ts +0 -12
- package/src/scheduler/ConfigDrivenOffloadPolicy.ts +0 -1
- package/src/scheduler/DefaultDrivingScheduler.ts +0 -6
- package/src/scheduler/InlineDrivingScheduler.ts +0 -13
- package/src/serialization/ItemsInputNormalizer.ts +0 -5
- package/src/testing/CapturingScheduler.ts +0 -3
- package/src/testing/EngineTestKitRunIdFactory.ts +0 -3
- package/src/testing/ItemHarnessNode.ts +0 -3
- package/src/testing/ItemHarnessNodeConfig.ts +0 -4
- package/src/testing/PrefixedSequentialIdGenerator.ts +0 -3
- package/src/testing/RegistrarEngineTestKit.types.ts +0 -2
- package/src/testing/RejectingCredentialSessionService.ts +0 -4
- package/src/testing/SubWorkflowRunnerTestNode.ts +0 -3
- package/src/testing/WorkflowTestHarnessManualTrigger.ts +0 -3
- package/src/testing/WorkflowTestKitBuilder.ts +0 -4
- package/src/testing/WorkflowTestKitRunNodeWorkflowFactory.ts +0 -3
- package/src/testing.ts +0 -3
- package/src/triggers/polling/PollingTriggerDedupWindow.ts +0 -4
- package/src/triggers/polling/PollingTriggerLogger.ts +0 -5
- package/src/triggers/polling/PollingTriggerRuntime.ts +0 -5
- package/src/types/index.ts +0 -6
- package/src/validation/WorkflowEdgePortValidator.ts +0 -5
- package/src/workflow/definition/ConnectionInvocationIdFactory.ts +0 -7
- package/src/workflow/definition/ConnectionNodeIdFactory.ts +0 -6
- package/src/workflow/definition/NodeIterationIdFactory.ts +0 -13
- package/src/workflow/definition/WorkflowExecutableNodeClassifier.ts +0 -6
- package/src/workflow/dsl/ChainCursorResolver.ts +8 -15
- package/src/workflow/dsl/NodeIdSlugifier.ts +0 -9
- package/src/workflow/dsl/WhenBuilder.ts +49 -2
- package/src/workflow/dsl/WorkflowDefinitionError.ts +0 -9
- package/src/workflow/dsl/workflowBuilderTypes.ts +5 -0
- package/src/workflowSnapshots/MissingRuntimeParityGuard.ts +24 -0
- package/src/workflowSnapshots/PersistedWorkflowTokenRegistry.ts +0 -6
- package/src/workflowSnapshots/WorkflowParityMismatchError.ts +18 -0
- package/src/workflowSnapshots/WorkflowSnapshotCodec.ts +1 -5
- package/src/workflowSnapshots/index.ts +3 -0
- package/dist/EngineRuntimeRegistration.types-CqcTWexS.d.cts +0 -81
- package/dist/EngineRuntimeRegistration.types-Cr75cSfL.d.ts +0 -44
- package/dist/ItemsInputNormalizer-BbQTSEkZ.cjs.map +0 -1
- package/dist/ItemsInputNormalizer-CSZGMgl3.js.map +0 -1
- package/dist/bootstrap-Bkd-Nfbn.js.map +0 -1
- package/dist/bootstrap-DIv-vloi.cjs.map +0 -1
- package/dist/contracts-CK0x6w_G.cjs +0 -74
- package/dist/contracts-CK0x6w_G.cjs.map +0 -1
- package/dist/contracts-DXdfTdpW.js +0 -50
- package/dist/contracts-DXdfTdpW.js.map +0 -1
- package/dist/di-LP2qSHkY.cjs.map +0 -1
- package/dist/di-tom0pM2h.js.map +0 -1
- package/dist/runtime-CWPdvJpC.js.map +0 -1
- package/dist/runtime-_VdHwGkJ.cjs.map +0 -1
|
@@ -15,69 +15,27 @@ import { SuspensionRequest } from "../contracts/runtimeTypes";
|
|
|
15
15
|
import { defineNode } from "./defineNode.types";
|
|
16
16
|
import type { DefinedNode } from "./defineNode.types";
|
|
17
17
|
|
|
18
|
-
// ---------------------------------------------------------------------------
|
|
19
|
-
// Public types
|
|
20
|
-
// ---------------------------------------------------------------------------
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Decision shape merged into `item.json` after a HITL approval task resolves.
|
|
24
|
-
*
|
|
25
|
-
* - `"approved"` / `"rejected"` — from a human decision (uses `approvedPredicate`).
|
|
26
|
-
* - `"timed-out"` — timeout fired with `onTimeout: "halt"`.
|
|
27
|
-
* - `"auto-accepted"` — timeout fired with `onTimeout: "auto-accept"`.
|
|
28
|
-
*/
|
|
29
18
|
export interface HumanApprovalDecisionResult {
|
|
30
19
|
readonly status: "approved" | "rejected" | "timed-out" | "auto-accepted";
|
|
31
|
-
/** Identity of the person who decided; absent for automated outcomes. */
|
|
32
20
|
readonly actor?: HumanTaskActor;
|
|
33
|
-
/** ISO 8601 timestamp of the decision. */
|
|
34
21
|
readonly decidedAt?: Date;
|
|
35
|
-
/** Optional free-text note from the reviewer. */
|
|
36
22
|
readonly note?: string;
|
|
37
|
-
/**
|
|
38
|
-
* Full raw decision payload (only present for `"approved"` / `"rejected"`).
|
|
39
|
-
* Shape is determined by the channel's `decisionSchema`.
|
|
40
|
-
*/
|
|
41
23
|
readonly payload?: Record<string, unknown>;
|
|
42
24
|
}
|
|
43
25
|
|
|
44
|
-
/**
|
|
45
|
-
* Output item shape emitted by a `defineHumanApprovalNode`-based node.
|
|
46
|
-
* Original `item.json` fields are preserved and `decision` is merged in.
|
|
47
|
-
* If the input `item.json` already contained a `decision` key it is **overwritten**.
|
|
48
|
-
*/
|
|
49
26
|
export type HumanApprovalOutputJson<TInputJson extends Record<string, unknown>> = TInputJson & {
|
|
50
27
|
readonly decision: HumanApprovalDecisionResult;
|
|
51
28
|
};
|
|
52
29
|
|
|
53
|
-
/**
|
|
54
|
-
* Extends {@link DefinedNode} with the `humanApprovalToolBehavior` metadata marker.
|
|
55
|
-
* Story 10 reads this field when attaching the node as an agent tool.
|
|
56
|
-
*/
|
|
57
30
|
export interface DefinedHumanApprovalNode<
|
|
58
31
|
TKey extends string,
|
|
59
32
|
TConfig extends CredentialJsonRecord,
|
|
60
33
|
TInputJson extends Record<string, unknown>,
|
|
61
34
|
TBindings extends DefinedNodeCredentialBindings | undefined = undefined,
|
|
62
35
|
> extends DefinedNode<TKey, TConfig, TInputJson, HumanApprovalOutputJson<TInputJson>, TBindings> {
|
|
63
|
-
/**
|
|
64
|
-
* Behavior hint consumed by the agent runtime (story 10) when this node is attached as a tool.
|
|
65
|
-
* `"return"` (default) — return the rejection to the agent as a tool result.
|
|
66
|
-
* `"halt"` — halt the agent run on rejection.
|
|
67
|
-
*
|
|
68
|
-
* Standalone DSL usage ignores this field.
|
|
69
|
-
*/
|
|
70
36
|
readonly humanApprovalToolBehavior: { onRejected: "return" | "halt" };
|
|
71
37
|
}
|
|
72
38
|
|
|
73
|
-
// ---------------------------------------------------------------------------
|
|
74
|
-
// isHumanApprovalNode predicate
|
|
75
|
-
// ---------------------------------------------------------------------------
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Returns `true` when `node` was created by {@link defineHumanApprovalNode}.
|
|
79
|
-
* Uses the `humanApprovalToolBehavior` typed field as the discriminant.
|
|
80
|
-
*/
|
|
81
39
|
export function isHumanApprovalNode(
|
|
82
40
|
node: unknown,
|
|
83
41
|
): node is DefinedHumanApprovalNode<string, Record<string, unknown>, Record<string, unknown>, undefined> {
|
|
@@ -89,57 +47,6 @@ export function isHumanApprovalNode(
|
|
|
89
47
|
);
|
|
90
48
|
}
|
|
91
49
|
|
|
92
|
-
// ---------------------------------------------------------------------------
|
|
93
|
-
// defineHumanApprovalNode
|
|
94
|
-
// ---------------------------------------------------------------------------
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Authoring helper that compiles a HITL approval channel down to a regular
|
|
98
|
-
* {@link defineNode}-backed node with `SuspensionRequest` semantics.
|
|
99
|
-
*
|
|
100
|
-
* **Fast-forward decision semantics:**
|
|
101
|
-
* - On the first `execute` call (no `ctx.resumeContext`): throws a `SuspensionRequest`
|
|
102
|
-
* that calls the author's `deliver`. The engine persists the suspension and continues.
|
|
103
|
-
* - On resume (`ctx.resumeContext` set): calls `onDecision`/`onTimeout` as appropriate,
|
|
104
|
-
* merges a `decision` key into `item.json`, and returns an item with the original
|
|
105
|
-
* `binary` map passed by reference (no copy).
|
|
106
|
-
*
|
|
107
|
-
* **Output shape per item:**
|
|
108
|
-
* ```ts
|
|
109
|
-
* // Input: { json: { invoiceId: 42 }, binary?: {...} }
|
|
110
|
-
* // Output: { json: { invoiceId: 42, decision: { status: "approved", actor, decidedAt } }, binary: <unchanged> }
|
|
111
|
-
* ```
|
|
112
|
-
* If `item.json` already has a `decision` key it is **overwritten**. Namespace as
|
|
113
|
-
* needed if your schema reserves that key for another purpose.
|
|
114
|
-
*
|
|
115
|
-
* **Predicate persistence:**
|
|
116
|
-
* The `approvedPredicate` function is NOT serialized to the suspension record (except
|
|
117
|
-
* as an audit-only string via `toString()`). On resume, the workflow definition is
|
|
118
|
-
* reloaded from code at process start and the predicate closure is rebuilt naturally.
|
|
119
|
-
* If a deploy ships a changed predicate between suspend and resume, the *new* predicate
|
|
120
|
-
* runs — document this in your runbook when the predicate carries business logic that
|
|
121
|
-
* may change across deploys.
|
|
122
|
-
*
|
|
123
|
-
* @example
|
|
124
|
-
* ```ts
|
|
125
|
-
* export const slackApprovalNode = defineHumanApprovalNode({
|
|
126
|
-
* key: "my-plugin.slackApproval",
|
|
127
|
-
* title: "Slack Approval",
|
|
128
|
-
* channel: "slack",
|
|
129
|
-
* configSchema: z.object({ channel: z.string(), message: z.string() }),
|
|
130
|
-
* decisionSchema: z.object({ approved: z.boolean(), note: z.string().optional() }),
|
|
131
|
-
*
|
|
132
|
-
* async deliver({ task, config, item }, ctx) {
|
|
133
|
-
* const ts = await postSlackMessage(config.channel, `Approve? <${task.resumeUrl}>`);
|
|
134
|
-
* return { channel: config.channel, ts };
|
|
135
|
-
* },
|
|
136
|
-
*
|
|
137
|
-
* async onDecision({ decision, actor, delivery }, ctx) {
|
|
138
|
-
* await updateSlackMessage(delivery.channel, delivery.ts, decision.approved ? "✅" : "❌");
|
|
139
|
-
* },
|
|
140
|
-
* });
|
|
141
|
-
* ```
|
|
142
|
-
*/
|
|
143
50
|
export function defineHumanApprovalNode<
|
|
144
51
|
TKey extends string,
|
|
145
52
|
TConfig extends CredentialJsonRecord,
|
|
@@ -159,16 +66,8 @@ export function defineHumanApprovalNode<
|
|
|
159
66
|
decisionSchema: ZodType<TDecision>;
|
|
160
67
|
credentials?: TBindings;
|
|
161
68
|
|
|
162
|
-
/**
|
|
163
|
-
* Custom predicate that decides whether a decision counts as "approved".
|
|
164
|
-
* When omitted, the helper checks if `decisionSchema` is a Zod object with an
|
|
165
|
-
* `approved: boolean` field; if so it uses `decision.approved === true`.
|
|
166
|
-
* If neither holds, `defineHumanApprovalNode` throws at **definition time** (not runtime).
|
|
167
|
-
*/
|
|
168
69
|
approvedPredicate?: (decision: TDecision) => boolean;
|
|
169
|
-
/** Default suspension timeout. Defaults to `"24h"`. */
|
|
170
70
|
defaultTimeout?: Duration;
|
|
171
|
-
/** What to do when the task times out. Defaults to `"halt"`. */
|
|
172
71
|
defaultOnTimeout?: "halt" | "auto-accept";
|
|
173
72
|
|
|
174
73
|
inspectorSummary?: (config: TConfig) => ReadonlyArray<NodeInspectorSummaryRow> | undefined;
|
|
@@ -204,16 +103,11 @@ export function defineHumanApprovalNode<
|
|
|
204
103
|
ctx: ExecutionContext,
|
|
205
104
|
) => Promise<void>;
|
|
206
105
|
}): DefinedHumanApprovalNode<TKey, TConfig, TInputJson, TBindings> {
|
|
207
|
-
// Resolve the approved predicate at definition time so we throw early when
|
|
208
|
-
// the schema is ambiguous.
|
|
209
106
|
const resolvedPredicate = resolveApprovedPredicate(opts.decisionSchema, opts.approvedPredicate);
|
|
210
107
|
|
|
211
108
|
const timeout = opts.defaultTimeout ?? "24h";
|
|
212
109
|
const onTimeout = opts.defaultOnTimeout ?? "halt";
|
|
213
110
|
|
|
214
|
-
// TOutputJson is `unknown` here because `execute` returns an Item-shaped object
|
|
215
|
-
// that the engine's NodeOutputNormalizer converts to the proper output. The public
|
|
216
|
-
// interface's DefinedHumanApprovalNode carries the correct output type for DSL use.
|
|
217
111
|
const inner = defineNode<TKey, TConfig, TInputJson, unknown, TBindings>({
|
|
218
112
|
key: opts.key,
|
|
219
113
|
title: opts.title,
|
|
@@ -226,7 +120,6 @@ export function defineHumanApprovalNode<
|
|
|
226
120
|
|
|
227
121
|
async execute(args, { config, execution: ctx }) {
|
|
228
122
|
if (!ctx.resumeContext) {
|
|
229
|
-
// First pass — suspend.
|
|
230
123
|
const subject = buildSubject(opts.title, args.item, ctx);
|
|
231
124
|
throw new SuspensionRequest({
|
|
232
125
|
decisionSchema: opts.decisionSchema,
|
|
@@ -236,7 +129,6 @@ export function defineHumanApprovalNode<
|
|
|
236
129
|
metadata: {
|
|
237
130
|
channel: opts.channel,
|
|
238
131
|
nodeKey: opts.key,
|
|
239
|
-
// Stored for audit only; never re-evaluated. See JSDoc on defineHumanApprovalNode.
|
|
240
132
|
approvedPredicateSource: opts.approvedPredicate?.toString() ?? null,
|
|
241
133
|
},
|
|
242
134
|
deliver: (handle: HumanTaskHandle) =>
|
|
@@ -252,7 +144,6 @@ export function defineHumanApprovalNode<
|
|
|
252
144
|
});
|
|
253
145
|
}
|
|
254
146
|
|
|
255
|
-
// Resume pass.
|
|
256
147
|
return await handleResume(
|
|
257
148
|
args.item,
|
|
258
149
|
ctx.resumeContext,
|
|
@@ -270,10 +161,6 @@ export function defineHumanApprovalNode<
|
|
|
270
161
|
}) as unknown as DefinedHumanApprovalNode<TKey, TConfig, TInputJson, TBindings>;
|
|
271
162
|
}
|
|
272
163
|
|
|
273
|
-
// ---------------------------------------------------------------------------
|
|
274
|
-
// Internal helpers (module-private)
|
|
275
|
-
// ---------------------------------------------------------------------------
|
|
276
|
-
|
|
277
164
|
function resolveApprovedPredicate<TDecision extends Record<string, unknown>>(
|
|
278
165
|
schema: ZodType<TDecision>,
|
|
279
166
|
predicate: ((d: TDecision) => boolean) | undefined,
|
|
@@ -281,7 +168,6 @@ function resolveApprovedPredicate<TDecision extends Record<string, unknown>>(
|
|
|
281
168
|
if (predicate) {
|
|
282
169
|
return predicate;
|
|
283
170
|
}
|
|
284
|
-
// Zod 4: ZodObject exposes `.shape` directly as an object (not a function).
|
|
285
171
|
const shape = (schema as unknown as ZodObject<Record<string, ZodType>>).shape;
|
|
286
172
|
if (shape && typeof shape === "object" && "approved" in shape) {
|
|
287
173
|
return (d) => (d as { approved?: unknown }).approved === true;
|
|
@@ -310,7 +196,6 @@ function mergeDecision(
|
|
|
310
196
|
): { json: Record<string, unknown>; binary: Item["binary"]; meta: Item["meta"] } {
|
|
311
197
|
return {
|
|
312
198
|
json: { ...(item.json as Record<string, unknown>), decision },
|
|
313
|
-
// binary is passed by reference — no copy. See defineHumanApprovalNode JSDoc.
|
|
314
199
|
binary: item.binary,
|
|
315
200
|
meta: item.meta,
|
|
316
201
|
};
|
|
@@ -355,7 +240,6 @@ async function handleResume<TDecision extends Record<string, unknown>, TDelivery
|
|
|
355
240
|
return mergeDecision(item, { status, decidedAt: dec.at });
|
|
356
241
|
}
|
|
357
242
|
|
|
358
|
-
// dec.kind === "decided"
|
|
359
243
|
const parsed = decisionSchema.parse(dec.value);
|
|
360
244
|
await onDecision?.(
|
|
361
245
|
{
|
|
@@ -12,6 +12,7 @@ import { node as persistedNode } from "../runtime-types/runtimeTypeDecorators.ty
|
|
|
12
12
|
import type { ZodType } from "zod";
|
|
13
13
|
import { z } from "zod";
|
|
14
14
|
import { DefinedNodeRegistry } from "./DefinedNodeRegistry";
|
|
15
|
+
import type { NodeBaseOptions } from "./nodeBaseOptions.types";
|
|
15
16
|
|
|
16
17
|
type MaybePromise<TValue> = TValue | Promise<TValue>;
|
|
17
18
|
|
|
@@ -56,10 +57,6 @@ export interface DefinedNodeRunContext<
|
|
|
56
57
|
readonly execution: NodeExecutionContext<RunnableNodeConfig<TConfig, unknown>>;
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
/**
|
|
60
|
-
* Arguments for {@link defineNode} `execute` (engine `ctx` matches {@link RunnableNode.execute};
|
|
61
|
-
* the second callback parameter adds {@link DefinedNodeRunContext} for credential accessors).
|
|
62
|
-
*/
|
|
63
60
|
export type DefineNodeExecuteArgs<TConfig extends CredentialJsonRecord, TInputJson> = Readonly<{
|
|
64
61
|
input: TInputJson;
|
|
65
62
|
item: Item;
|
|
@@ -87,14 +84,11 @@ export interface DefinedNode<
|
|
|
87
84
|
create<TConfigItemJson = TInputJson>(
|
|
88
85
|
config: DefinedNodeConfigInput<TConfig, TConfigItemJson>,
|
|
89
86
|
name?: string,
|
|
90
|
-
|
|
87
|
+
idOrOptions?: string | NodeBaseOptions,
|
|
91
88
|
): RunnableNodeConfig<TInputJson, TOutputJson>;
|
|
92
89
|
register(context: { registerNode<TValue>(token: TypeToken<TValue>, implementation?: TypeToken<TValue>): void }): void;
|
|
93
90
|
}
|
|
94
91
|
|
|
95
|
-
/**
|
|
96
|
-
* Plugin / DSL-friendly node: per-item `execute` with optional {@link RunnableNodeConfig.inputSchema}.
|
|
97
|
-
*/
|
|
98
92
|
export interface DefineNodeOptions<
|
|
99
93
|
TKey extends string,
|
|
100
94
|
TConfig extends CredentialJsonRecord,
|
|
@@ -105,27 +99,12 @@ export interface DefineNodeOptions<
|
|
|
105
99
|
readonly key: TKey;
|
|
106
100
|
readonly title: string;
|
|
107
101
|
readonly description?: string;
|
|
108
|
-
/**
|
|
109
|
-
* Canvas icon for this node (same contract as `NodeConfigBase.icon` on runnable configs).
|
|
110
|
-
* The Next host resolves Lucide (`lucide:…`), built-in SVGs (`builtin:…`), Simple Icons (`si:…`), and image URLs (`https:`, `data:`, `/…`).
|
|
111
|
-
*/
|
|
112
102
|
readonly icon?: string;
|
|
113
|
-
/** Default values / form hints for **static** node configuration (credentials, retry, IDs), not per-item payload. */
|
|
114
103
|
readonly input?: Readonly<Record<keyof TConfig & string, unknown>>;
|
|
115
104
|
readonly configSchema?: z.ZodType<TConfig>;
|
|
116
105
|
readonly credentials?: TBindings;
|
|
117
|
-
/**
|
|
118
|
-
* Validates **`input`** (engine also accepts `inputSchema` on the node class).
|
|
119
|
-
*/
|
|
120
106
|
readonly inputSchema?: ZodType<TInputJson>;
|
|
121
|
-
/** Preserve inbound `item.binary` when `execute` returns plain JSON or item-shaped results without `binary`. */
|
|
122
107
|
readonly keepBinaries?: boolean;
|
|
123
|
-
/**
|
|
124
|
-
* Static configuration summary surfaced in the workflow inspector — see
|
|
125
|
-
* {@link import("../contracts/workflowTypes").NodeConfigBase.inspectorSummary}.
|
|
126
|
-
*
|
|
127
|
-
* Receives the static config; returns 2–6 short label/value pairs (or `undefined` to skip).
|
|
128
|
-
*/
|
|
129
108
|
readonly inspectorSummary?: (
|
|
130
109
|
args: Readonly<{ config: TConfig }>,
|
|
131
110
|
) => ReadonlyArray<NodeInspectorSummaryRow> | undefined;
|
|
@@ -135,9 +114,6 @@ export interface DefineNodeOptions<
|
|
|
135
114
|
): MaybePromise<TOutputJson>;
|
|
136
115
|
}
|
|
137
116
|
|
|
138
|
-
/**
|
|
139
|
-
* Batch-oriented defined node: `run` receives all item JSON once (last item in activation); emits one output per input row.
|
|
140
|
-
*/
|
|
141
117
|
export interface DefineBatchNodeOptions<
|
|
142
118
|
TKey extends string,
|
|
143
119
|
TConfig extends CredentialJsonRecord,
|
|
@@ -271,12 +247,17 @@ export function defineNode<
|
|
|
271
247
|
readonly icon = options.icon;
|
|
272
248
|
readonly inputSchema = options.inputSchema;
|
|
273
249
|
readonly keepBinaries = options.keepBinaries ?? false;
|
|
250
|
+
readonly id?: string;
|
|
251
|
+
readonly description?: string;
|
|
274
252
|
|
|
275
253
|
constructor(
|
|
276
254
|
public readonly name: string,
|
|
277
255
|
config: DefinedNodeConfigInput<TConfig, unknown>,
|
|
278
|
-
|
|
256
|
+
idOrOptions?: string | NodeBaseOptions,
|
|
279
257
|
) {
|
|
258
|
+
const resolved = typeof idOrOptions === "string" ? { id: idOrOptions } : idOrOptions;
|
|
259
|
+
this.id = resolved?.id;
|
|
260
|
+
this.description = resolved?.description;
|
|
280
261
|
this.config = config as unknown as TConfig;
|
|
281
262
|
}
|
|
282
263
|
|
|
@@ -299,9 +280,9 @@ export function defineNode<
|
|
|
299
280
|
create<TConfigItemJson = TInputJson>(
|
|
300
281
|
config: DefinedNodeConfigInput<TConfig, TConfigItemJson>,
|
|
301
282
|
name = options.title,
|
|
302
|
-
|
|
283
|
+
idOrOptions?: string | NodeBaseOptions,
|
|
303
284
|
) {
|
|
304
|
-
return new DefinedRunnableNodeConfig(name, config as DefinedNodeConfigInput<TConfig, unknown>,
|
|
285
|
+
return new DefinedRunnableNodeConfig(name, config as DefinedNodeConfigInput<TConfig, unknown>, idOrOptions);
|
|
305
286
|
},
|
|
306
287
|
register(context) {
|
|
307
288
|
context.registerNode(DefinedNodeRuntime);
|
|
@@ -358,12 +339,17 @@ export function defineBatchNode<
|
|
|
358
339
|
readonly kind = "node" as const;
|
|
359
340
|
readonly type: TypeToken<unknown> = DefinedNodeRuntime;
|
|
360
341
|
readonly icon = options.icon;
|
|
342
|
+
readonly id?: string;
|
|
343
|
+
readonly description?: string;
|
|
361
344
|
|
|
362
345
|
constructor(
|
|
363
346
|
public readonly name: string,
|
|
364
347
|
config: DefinedNodeConfigInput<TConfig, unknown>,
|
|
365
|
-
|
|
348
|
+
idOrOptions?: string | NodeBaseOptions,
|
|
366
349
|
) {
|
|
350
|
+
const resolved = typeof idOrOptions === "string" ? { id: idOrOptions } : idOrOptions;
|
|
351
|
+
this.id = resolved?.id;
|
|
352
|
+
this.description = resolved?.description;
|
|
367
353
|
this.config = config as unknown as TConfig;
|
|
368
354
|
}
|
|
369
355
|
|
|
@@ -386,9 +372,9 @@ export function defineBatchNode<
|
|
|
386
372
|
create<TConfigItemJson = TInputJson>(
|
|
387
373
|
config: DefinedNodeConfigInput<TConfig, TConfigItemJson>,
|
|
388
374
|
name = options.title,
|
|
389
|
-
|
|
375
|
+
idOrOptions?: string | NodeBaseOptions,
|
|
390
376
|
) {
|
|
391
|
-
return new DefinedRunnableNodeConfig(name, config as DefinedNodeConfigInput<TConfig, unknown>,
|
|
377
|
+
return new DefinedRunnableNodeConfig(name, config as DefinedNodeConfigInput<TConfig, unknown>, idOrOptions);
|
|
392
378
|
},
|
|
393
379
|
register(context) {
|
|
394
380
|
context.registerNode(DefinedNodeRuntime);
|