@codemation/core 0.0.5 → 0.0.7
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/InMemoryLiveWorkflowRepository-DxoualoC.d.ts +1344 -0
- package/dist/InMemoryLiveWorkflowRepository-orY1VsWG.d.cts +1172 -0
- package/dist/RunIntentService-ByuUYsAL.d.cts +279 -0
- package/dist/RunIntentService-CYnn140t.js +3136 -0
- package/dist/RunIntentService-CYnn140t.js.map +1 -0
- package/dist/RunIntentService-DlQH5eZ2.cjs +3467 -0
- package/dist/RunIntentService-DlQH5eZ2.cjs.map +1 -0
- package/dist/WorkflowSnapshotCodec-DSEzKyt3.d.cts +22 -0
- package/dist/bootstrap/index.cjs +133 -4
- package/dist/bootstrap/index.cjs.map +1 -1
- package/dist/bootstrap/index.d.cts +4 -3
- package/dist/bootstrap/index.d.ts +3 -2
- package/dist/bootstrap/index.js +133 -4
- package/dist/bootstrap/index.js.map +1 -1
- package/dist/index-CTjfVHJh.d.ts +694 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/testing.d.cts +2 -2
- package/dist/testing.d.ts +1 -1
- package/package.json +1 -1
- package/src/bootstrap/runtime/EngineRuntimeRegistrar.ts +10 -2
- package/src/contracts/runtimeTypes.ts +5 -0
- package/src/execution/NodeActivationRequestComposer.ts +15 -4
- package/src/orchestration/Engine.ts +12 -1
- package/src/orchestration/NodeExecutionRequestHandlerService.ts +179 -0
- package/src/runtime/EngineFactory.ts +13 -0
package/dist/bootstrap/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as InProcessRetryRunnerFactory, C as PersistedWorkflowTokenRegistry, D as NodeExecutorFactory, E as MissingRuntimeExecutionMarker, F as ActivationEnqueueService, I as DefaultExecutionBinaryService, K as NodeEventPublisher, L as UnavailableBinaryStorage, M as DefaultExecutionContextFactory, N as DefaultAsyncSleeper, O as NodeExecutor, P as CredentialResolverFactory, Q as instanceCachingFactory, S as WorkflowSnapshotResolver, T as MissingRuntimeTriggerToken, _ as RunStateSemantics, a as ENGINE_EXECUTION_LIMITS_DEFAULTS, b as NodeInstanceFactoryFactory, c as InlineDrivingScheduler, d as ConfigDrivenOffloadPolicy, f as RunStartService, g as WorkflowRunExecutionContextFactory, h as WorkflowTopology, i as InMemoryBinaryStorage, it as WorkflowExecutableNodeClassifierFactory, j as InProcessRetryRunner, k as NodeActivationRequestComposer, l as HintOnlyOffloadPolicy, m as RunContinuationService, n as RunFinishedAtFactory, o as EngineExecutionLimitsPolicy, p as RunPolicySnapshotFactory, r as InMemoryRunDataFactory, rt as CoreTokens, s as LocalOnlyScheduler, t as RunIntentService, u as DefaultDrivingScheduler, v as PersistedRunStateTerminalBuilder, w as MissingRuntimeFallbacks, x as NodeInstanceFactory, y as NodeRunStateWriterFactory } from "../RunIntentService-
|
|
1
|
+
import { A as InProcessRetryRunnerFactory, C as PersistedWorkflowTokenRegistry, D as NodeExecutorFactory, E as MissingRuntimeExecutionMarker, F as ActivationEnqueueService, I as DefaultExecutionBinaryService, K as NodeEventPublisher, L as UnavailableBinaryStorage, M as DefaultExecutionContextFactory, N as DefaultAsyncSleeper, O as NodeExecutor, P as CredentialResolverFactory, Q as instanceCachingFactory, S as WorkflowSnapshotResolver, T as MissingRuntimeTriggerToken, _ as RunStateSemantics, a as ENGINE_EXECUTION_LIMITS_DEFAULTS, b as NodeInstanceFactoryFactory, c as InlineDrivingScheduler, d as ConfigDrivenOffloadPolicy, f as RunStartService, g as WorkflowRunExecutionContextFactory, h as WorkflowTopology, i as InMemoryBinaryStorage, it as WorkflowExecutableNodeClassifierFactory, j as InProcessRetryRunner, k as NodeActivationRequestComposer, l as HintOnlyOffloadPolicy, m as RunContinuationService, n as RunFinishedAtFactory, o as EngineExecutionLimitsPolicy, p as RunPolicySnapshotFactory, r as InMemoryRunDataFactory, rt as CoreTokens, s as LocalOnlyScheduler, t as RunIntentService, u as DefaultDrivingScheduler, v as PersistedRunStateTerminalBuilder, w as MissingRuntimeFallbacks, x as NodeInstanceFactory, y as NodeRunStateWriterFactory } from "../RunIntentService-CYnn140t.js";
|
|
2
2
|
import { n as WorkflowSnapshotCodec, t as InMemoryLiveWorkflowRepository } from "../InMemoryLiveWorkflowRepository-BoLNnVLg.js";
|
|
3
3
|
|
|
4
4
|
//#region src/policies/executionLimits/EngineExecutionLimitsPolicyFactory.ts
|
|
@@ -147,6 +147,125 @@ var InMemoryWorkflowExecutionRepository = class {
|
|
|
147
147
|
}
|
|
148
148
|
};
|
|
149
149
|
|
|
150
|
+
//#endregion
|
|
151
|
+
//#region src/orchestration/NodeExecutionRequestHandlerService.ts
|
|
152
|
+
var NodeExecutionRequestHandlerService = class {
|
|
153
|
+
constructor(workflowExecutionRepository, workflowSnapshotResolver, runDataFactory, runExecutionContextFactory, nodeStatePublisherFactory, nodeActivationRequestComposer, nodeExecutor, continuation, executionLimitsPolicy) {
|
|
154
|
+
this.workflowExecutionRepository = workflowExecutionRepository;
|
|
155
|
+
this.workflowSnapshotResolver = workflowSnapshotResolver;
|
|
156
|
+
this.runDataFactory = runDataFactory;
|
|
157
|
+
this.runExecutionContextFactory = runExecutionContextFactory;
|
|
158
|
+
this.nodeStatePublisherFactory = nodeStatePublisherFactory;
|
|
159
|
+
this.nodeActivationRequestComposer = nodeActivationRequestComposer;
|
|
160
|
+
this.nodeExecutor = nodeExecutor;
|
|
161
|
+
this.continuation = continuation;
|
|
162
|
+
this.executionLimitsPolicy = executionLimitsPolicy;
|
|
163
|
+
}
|
|
164
|
+
async handleNodeExecutionRequest(request) {
|
|
165
|
+
const state = await this.workflowExecutionRepository.load(request.runId);
|
|
166
|
+
if (!state) throw new Error(`Unknown runId: ${request.runId}`);
|
|
167
|
+
if (state.workflowId !== request.workflowId) throw new Error(`workflowId mismatch for run ${request.runId}: ${state.workflowId} vs ${request.workflowId}`);
|
|
168
|
+
if (state.status !== "pending" || !state.pending) return;
|
|
169
|
+
if (state.pending.activationId !== request.activationId || state.pending.nodeId !== request.nodeId) return;
|
|
170
|
+
const workflow = this.resolvePersistedWorkflow(state);
|
|
171
|
+
if (!workflow) throw new Error(`Unknown workflowId: ${state.workflowId}`);
|
|
172
|
+
const definition = workflow.nodes.find((node) => node.id === request.nodeId);
|
|
173
|
+
if (!definition) throw new Error(`Unknown nodeId: ${request.nodeId}`);
|
|
174
|
+
if (definition.kind !== "node") throw new Error(`Node ${request.nodeId} is not runnable`);
|
|
175
|
+
const resolvedParent = request.parent ?? state.parent;
|
|
176
|
+
const data = this.runDataFactory.create(state.outputsByNode);
|
|
177
|
+
const limits = this.resolveEngineLimitsFromState(state);
|
|
178
|
+
const base = this.runExecutionContextFactory.create({
|
|
179
|
+
runId: state.runId,
|
|
180
|
+
workflowId: state.workflowId,
|
|
181
|
+
nodeId: request.nodeId,
|
|
182
|
+
parent: resolvedParent,
|
|
183
|
+
subworkflowDepth: state.executionOptions?.subworkflowDepth ?? 0,
|
|
184
|
+
engineMaxNodeActivations: limits.engineMaxNodeActivations,
|
|
185
|
+
engineMaxSubworkflowDepth: limits.engineMaxSubworkflowDepth,
|
|
186
|
+
data,
|
|
187
|
+
nodeState: this.nodeStatePublisherFactory.create(state.runId, state.workflowId, resolvedParent)
|
|
188
|
+
});
|
|
189
|
+
const activationRequest = this.nodeActivationRequestComposer.createSingleFromDefinitionWithActivation({
|
|
190
|
+
activationId: request.activationId,
|
|
191
|
+
runId: request.runId,
|
|
192
|
+
workflowId: request.workflowId,
|
|
193
|
+
parent: resolvedParent,
|
|
194
|
+
executionOptions: request.executionOptions ?? state.executionOptions,
|
|
195
|
+
base,
|
|
196
|
+
data,
|
|
197
|
+
definition: {
|
|
198
|
+
id: definition.id,
|
|
199
|
+
config: definition.config
|
|
200
|
+
},
|
|
201
|
+
batchId: state.pending.batchId ?? "batch_1",
|
|
202
|
+
input: request.input
|
|
203
|
+
});
|
|
204
|
+
await this.continuation.markNodeRunning({
|
|
205
|
+
runId: activationRequest.runId,
|
|
206
|
+
activationId: activationRequest.activationId,
|
|
207
|
+
nodeId: activationRequest.nodeId,
|
|
208
|
+
inputsByPort: { in: activationRequest.input }
|
|
209
|
+
});
|
|
210
|
+
let outputs;
|
|
211
|
+
try {
|
|
212
|
+
outputs = await this.nodeExecutor.execute(activationRequest);
|
|
213
|
+
} catch (error) {
|
|
214
|
+
await this.resumeAfterExecutionError(activationRequest, this.asError(error));
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
await this.resumeAfterExecutionResult(activationRequest, outputs ?? {});
|
|
218
|
+
}
|
|
219
|
+
resolvePersistedWorkflow(state) {
|
|
220
|
+
return this.workflowSnapshotResolver.resolve({
|
|
221
|
+
workflowId: state.workflowId,
|
|
222
|
+
workflowSnapshot: state.workflowSnapshot
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
resolveEngineLimitsFromState(state) {
|
|
226
|
+
const fallback = this.executionLimitsPolicy.createRootExecutionOptions();
|
|
227
|
+
return {
|
|
228
|
+
engineMaxNodeActivations: state.executionOptions?.maxNodeActivations ?? fallback.maxNodeActivations,
|
|
229
|
+
engineMaxSubworkflowDepth: state.executionOptions?.maxSubworkflowDepth ?? fallback.maxSubworkflowDepth
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
async resumeAfterExecutionResult(request, outputs) {
|
|
233
|
+
try {
|
|
234
|
+
await this.continuation.resumeFromNodeResult({
|
|
235
|
+
runId: request.runId,
|
|
236
|
+
activationId: request.activationId,
|
|
237
|
+
nodeId: request.nodeId,
|
|
238
|
+
outputs
|
|
239
|
+
});
|
|
240
|
+
} catch (error) {
|
|
241
|
+
this.rethrowUnlessIgnorableContinuationError(error);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
async resumeAfterExecutionError(request, error) {
|
|
245
|
+
try {
|
|
246
|
+
await this.continuation.resumeFromNodeError({
|
|
247
|
+
runId: request.runId,
|
|
248
|
+
activationId: request.activationId,
|
|
249
|
+
nodeId: request.nodeId,
|
|
250
|
+
error
|
|
251
|
+
});
|
|
252
|
+
} catch (continuationError) {
|
|
253
|
+
this.rethrowUnlessIgnorableContinuationError(continuationError);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
asError(error) {
|
|
257
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
258
|
+
}
|
|
259
|
+
rethrowUnlessIgnorableContinuationError(error) {
|
|
260
|
+
if (this.isIgnorableContinuationError(error)) return;
|
|
261
|
+
throw this.asError(error);
|
|
262
|
+
}
|
|
263
|
+
isIgnorableContinuationError(error) {
|
|
264
|
+
const message = this.asError(error).message;
|
|
265
|
+
return message.includes(" is not pending") || message.includes("activationId mismatch") || message.includes("nodeId mismatch");
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
|
|
150
269
|
//#endregion
|
|
151
270
|
//#region src/planning/RunQueuePlanner.ts
|
|
152
271
|
var RunQueuePlanner = class {
|
|
@@ -703,6 +822,9 @@ var Engine = class {
|
|
|
703
822
|
async waitForWebhookResponse(runId) {
|
|
704
823
|
return await this.deps.runContinuationService.waitForWebhookResponse(runId);
|
|
705
824
|
}
|
|
825
|
+
async handleNodeExecutionRequest(request) {
|
|
826
|
+
await this.deps.nodeExecutionRequestHandler.handleNodeExecutionRequest(request);
|
|
827
|
+
}
|
|
706
828
|
};
|
|
707
829
|
|
|
708
830
|
//#endregion
|
|
@@ -733,6 +855,7 @@ var EngineFactory = class {
|
|
|
733
855
|
const policyErrorServices = new WorkflowPolicyErrorServices(deps.nodeResolver);
|
|
734
856
|
const runStartService = new RunStartService(deps.runIdFactory, deps.workflowExecutionRepository, deps.runDataFactory, workflowSnapshotCodec, planningFactory, nodeStatePublisherFactory, runExecutionContextFactory, nodeActivationRequestComposer, activationEnqueueService, semantics, waiters, deps.workflowPolicyRuntimeDefaults, executionLimitsPolicy);
|
|
735
857
|
const runContinuationService = new RunContinuationService(deps.activationIdFactory, deps.workflowExecutionRepository, deps.runDataFactory, runExecutionContextFactory, workflowSnapshotResolver, planningFactory, nodeStatePublisherFactory, credentialResolverFactory, nodeActivationRequestComposer, persistedRunStateTerminalBuilder, activationEnqueueService, nodeEventPublisher, semantics, waiters, policyErrorServices, terminalPersistence, executionLimitsPolicy);
|
|
858
|
+
const nodeExecutionRequestHandler = new NodeExecutionRequestHandlerService(deps.workflowExecutionRepository, workflowSnapshotResolver, deps.runDataFactory, runExecutionContextFactory, nodeStatePublisherFactory, nodeActivationRequestComposer, deps.nodeExecutor, runContinuationService, executionLimitsPolicy);
|
|
736
859
|
const triggerRuntime = new TriggerRuntimeService(deps.workflowRepository, deps.workflowActivationPolicy, deps.runIdFactory, deps.runDataFactory, deps.executionContextFactory, credentialResolverFactory, nodeStatePublisherFactory, deps.nodeResolver, deps.triggerSetupStateRepository, { emit: async (workflow, triggerNodeId, items) => {
|
|
737
860
|
await runStartService.runWorkflow(workflow, triggerNodeId, items, void 0);
|
|
738
861
|
} }, executionLimitsPolicy, deps.triggerRuntimeDiagnostics);
|
|
@@ -743,7 +866,8 @@ var EngineFactory = class {
|
|
|
743
866
|
workflowSnapshotResolver,
|
|
744
867
|
triggerRuntime,
|
|
745
868
|
runStartService,
|
|
746
|
-
runContinuationService
|
|
869
|
+
runContinuationService,
|
|
870
|
+
nodeExecutionRequestHandler
|
|
747
871
|
});
|
|
748
872
|
deps.activationScheduler.setContinuation?.(engine);
|
|
749
873
|
return engine;
|
|
@@ -901,6 +1025,7 @@ var EngineRuntimeRegistrar = class {
|
|
|
901
1025
|
this.registerSupportFactories(container);
|
|
902
1026
|
this.registerExecutionLimitsPolicy(container, options);
|
|
903
1027
|
this.ensureWorkflowNodeInstanceFactory(container);
|
|
1028
|
+
this.ensureNodeExecutor(container);
|
|
904
1029
|
this.registerDefaultActivationScheduler(container);
|
|
905
1030
|
this.registerEngine(container, options);
|
|
906
1031
|
this.registerIntentServices(container);
|
|
@@ -929,12 +1054,15 @@ var EngineRuntimeRegistrar = class {
|
|
|
929
1054
|
return dependencyContainer.resolve(NodeInstanceFactoryFactory).create(dependencyContainer.resolve(CoreTokens.NodeResolver));
|
|
930
1055
|
}) });
|
|
931
1056
|
}
|
|
932
|
-
|
|
933
|
-
if (container.isRegistered(
|
|
1057
|
+
ensureNodeExecutor(container) {
|
|
1058
|
+
if (container.isRegistered(NodeExecutor, true)) return;
|
|
934
1059
|
container.register(NodeExecutor, { useFactory: instanceCachingFactory((dependencyContainer) => {
|
|
935
1060
|
const retryRunner = dependencyContainer.resolve(InProcessRetryRunnerFactory).create(dependencyContainer.resolve(DefaultAsyncSleeper));
|
|
936
1061
|
return dependencyContainer.resolve(NodeExecutorFactory).create(dependencyContainer.resolve(CoreTokens.WorkflowNodeInstanceFactory), retryRunner);
|
|
937
1062
|
}) });
|
|
1063
|
+
}
|
|
1064
|
+
registerDefaultActivationScheduler(container) {
|
|
1065
|
+
if (container.isRegistered(CoreTokens.NodeActivationScheduler, true)) return;
|
|
938
1066
|
container.register(InlineDrivingScheduler, { useFactory: instanceCachingFactory((dependencyContainer) => {
|
|
939
1067
|
return dependencyContainer.resolve(InlineDrivingSchedulerFactory).create(dependencyContainer.resolve(NodeExecutor));
|
|
940
1068
|
}) });
|
|
@@ -967,6 +1095,7 @@ var EngineRuntimeRegistrar = class {
|
|
|
967
1095
|
activationScheduler: dependencyContainer.resolve(CoreTokens.NodeActivationScheduler),
|
|
968
1096
|
runDataFactory: dependencyContainer.resolve(CoreTokens.RunDataFactory),
|
|
969
1097
|
executionContextFactory: dependencyContainer.resolve(CoreTokens.ExecutionContextFactory),
|
|
1098
|
+
nodeExecutor: dependencyContainer.resolve(NodeExecutor),
|
|
970
1099
|
eventBus: dependencyContainer.resolve(CoreTokens.RunEventBus),
|
|
971
1100
|
tokenRegistry: tokenRegistryLike,
|
|
972
1101
|
workflowNodeInstanceFactory,
|