@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.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_RunIntentService = require('../RunIntentService-
|
|
1
|
+
const require_RunIntentService = require('../RunIntentService-DlQH5eZ2.cjs');
|
|
2
2
|
const require_InMemoryLiveWorkflowRepository = require('../InMemoryLiveWorkflowRepository-BTzHpQ6e.cjs');
|
|
3
3
|
let tsyringe = require("tsyringe");
|
|
4
4
|
tsyringe = require_RunIntentService.__toESM(tsyringe);
|
|
@@ -149,6 +149,125 @@ var InMemoryWorkflowExecutionRepository = class {
|
|
|
149
149
|
}
|
|
150
150
|
};
|
|
151
151
|
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region src/orchestration/NodeExecutionRequestHandlerService.ts
|
|
154
|
+
var NodeExecutionRequestHandlerService = class {
|
|
155
|
+
constructor(workflowExecutionRepository, workflowSnapshotResolver, runDataFactory, runExecutionContextFactory, nodeStatePublisherFactory, nodeActivationRequestComposer, nodeExecutor, continuation, executionLimitsPolicy) {
|
|
156
|
+
this.workflowExecutionRepository = workflowExecutionRepository;
|
|
157
|
+
this.workflowSnapshotResolver = workflowSnapshotResolver;
|
|
158
|
+
this.runDataFactory = runDataFactory;
|
|
159
|
+
this.runExecutionContextFactory = runExecutionContextFactory;
|
|
160
|
+
this.nodeStatePublisherFactory = nodeStatePublisherFactory;
|
|
161
|
+
this.nodeActivationRequestComposer = nodeActivationRequestComposer;
|
|
162
|
+
this.nodeExecutor = nodeExecutor;
|
|
163
|
+
this.continuation = continuation;
|
|
164
|
+
this.executionLimitsPolicy = executionLimitsPolicy;
|
|
165
|
+
}
|
|
166
|
+
async handleNodeExecutionRequest(request) {
|
|
167
|
+
const state = await this.workflowExecutionRepository.load(request.runId);
|
|
168
|
+
if (!state) throw new Error(`Unknown runId: ${request.runId}`);
|
|
169
|
+
if (state.workflowId !== request.workflowId) throw new Error(`workflowId mismatch for run ${request.runId}: ${state.workflowId} vs ${request.workflowId}`);
|
|
170
|
+
if (state.status !== "pending" || !state.pending) return;
|
|
171
|
+
if (state.pending.activationId !== request.activationId || state.pending.nodeId !== request.nodeId) return;
|
|
172
|
+
const workflow = this.resolvePersistedWorkflow(state);
|
|
173
|
+
if (!workflow) throw new Error(`Unknown workflowId: ${state.workflowId}`);
|
|
174
|
+
const definition = workflow.nodes.find((node) => node.id === request.nodeId);
|
|
175
|
+
if (!definition) throw new Error(`Unknown nodeId: ${request.nodeId}`);
|
|
176
|
+
if (definition.kind !== "node") throw new Error(`Node ${request.nodeId} is not runnable`);
|
|
177
|
+
const resolvedParent = request.parent ?? state.parent;
|
|
178
|
+
const data = this.runDataFactory.create(state.outputsByNode);
|
|
179
|
+
const limits = this.resolveEngineLimitsFromState(state);
|
|
180
|
+
const base = this.runExecutionContextFactory.create({
|
|
181
|
+
runId: state.runId,
|
|
182
|
+
workflowId: state.workflowId,
|
|
183
|
+
nodeId: request.nodeId,
|
|
184
|
+
parent: resolvedParent,
|
|
185
|
+
subworkflowDepth: state.executionOptions?.subworkflowDepth ?? 0,
|
|
186
|
+
engineMaxNodeActivations: limits.engineMaxNodeActivations,
|
|
187
|
+
engineMaxSubworkflowDepth: limits.engineMaxSubworkflowDepth,
|
|
188
|
+
data,
|
|
189
|
+
nodeState: this.nodeStatePublisherFactory.create(state.runId, state.workflowId, resolvedParent)
|
|
190
|
+
});
|
|
191
|
+
const activationRequest = this.nodeActivationRequestComposer.createSingleFromDefinitionWithActivation({
|
|
192
|
+
activationId: request.activationId,
|
|
193
|
+
runId: request.runId,
|
|
194
|
+
workflowId: request.workflowId,
|
|
195
|
+
parent: resolvedParent,
|
|
196
|
+
executionOptions: request.executionOptions ?? state.executionOptions,
|
|
197
|
+
base,
|
|
198
|
+
data,
|
|
199
|
+
definition: {
|
|
200
|
+
id: definition.id,
|
|
201
|
+
config: definition.config
|
|
202
|
+
},
|
|
203
|
+
batchId: state.pending.batchId ?? "batch_1",
|
|
204
|
+
input: request.input
|
|
205
|
+
});
|
|
206
|
+
await this.continuation.markNodeRunning({
|
|
207
|
+
runId: activationRequest.runId,
|
|
208
|
+
activationId: activationRequest.activationId,
|
|
209
|
+
nodeId: activationRequest.nodeId,
|
|
210
|
+
inputsByPort: { in: activationRequest.input }
|
|
211
|
+
});
|
|
212
|
+
let outputs;
|
|
213
|
+
try {
|
|
214
|
+
outputs = await this.nodeExecutor.execute(activationRequest);
|
|
215
|
+
} catch (error) {
|
|
216
|
+
await this.resumeAfterExecutionError(activationRequest, this.asError(error));
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
await this.resumeAfterExecutionResult(activationRequest, outputs ?? {});
|
|
220
|
+
}
|
|
221
|
+
resolvePersistedWorkflow(state) {
|
|
222
|
+
return this.workflowSnapshotResolver.resolve({
|
|
223
|
+
workflowId: state.workflowId,
|
|
224
|
+
workflowSnapshot: state.workflowSnapshot
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
resolveEngineLimitsFromState(state) {
|
|
228
|
+
const fallback = this.executionLimitsPolicy.createRootExecutionOptions();
|
|
229
|
+
return {
|
|
230
|
+
engineMaxNodeActivations: state.executionOptions?.maxNodeActivations ?? fallback.maxNodeActivations,
|
|
231
|
+
engineMaxSubworkflowDepth: state.executionOptions?.maxSubworkflowDepth ?? fallback.maxSubworkflowDepth
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
async resumeAfterExecutionResult(request, outputs) {
|
|
235
|
+
try {
|
|
236
|
+
await this.continuation.resumeFromNodeResult({
|
|
237
|
+
runId: request.runId,
|
|
238
|
+
activationId: request.activationId,
|
|
239
|
+
nodeId: request.nodeId,
|
|
240
|
+
outputs
|
|
241
|
+
});
|
|
242
|
+
} catch (error) {
|
|
243
|
+
this.rethrowUnlessIgnorableContinuationError(error);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
async resumeAfterExecutionError(request, error) {
|
|
247
|
+
try {
|
|
248
|
+
await this.continuation.resumeFromNodeError({
|
|
249
|
+
runId: request.runId,
|
|
250
|
+
activationId: request.activationId,
|
|
251
|
+
nodeId: request.nodeId,
|
|
252
|
+
error
|
|
253
|
+
});
|
|
254
|
+
} catch (continuationError) {
|
|
255
|
+
this.rethrowUnlessIgnorableContinuationError(continuationError);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
asError(error) {
|
|
259
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
260
|
+
}
|
|
261
|
+
rethrowUnlessIgnorableContinuationError(error) {
|
|
262
|
+
if (this.isIgnorableContinuationError(error)) return;
|
|
263
|
+
throw this.asError(error);
|
|
264
|
+
}
|
|
265
|
+
isIgnorableContinuationError(error) {
|
|
266
|
+
const message = this.asError(error).message;
|
|
267
|
+
return message.includes(" is not pending") || message.includes("activationId mismatch") || message.includes("nodeId mismatch");
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
|
|
152
271
|
//#endregion
|
|
153
272
|
//#region src/planning/RunQueuePlanner.ts
|
|
154
273
|
var RunQueuePlanner = class {
|
|
@@ -705,6 +824,9 @@ var Engine = class {
|
|
|
705
824
|
async waitForWebhookResponse(runId) {
|
|
706
825
|
return await this.deps.runContinuationService.waitForWebhookResponse(runId);
|
|
707
826
|
}
|
|
827
|
+
async handleNodeExecutionRequest(request) {
|
|
828
|
+
await this.deps.nodeExecutionRequestHandler.handleNodeExecutionRequest(request);
|
|
829
|
+
}
|
|
708
830
|
};
|
|
709
831
|
|
|
710
832
|
//#endregion
|
|
@@ -735,6 +857,7 @@ var EngineFactory = class {
|
|
|
735
857
|
const policyErrorServices = new WorkflowPolicyErrorServices(deps.nodeResolver);
|
|
736
858
|
const runStartService = new require_RunIntentService.RunStartService(deps.runIdFactory, deps.workflowExecutionRepository, deps.runDataFactory, workflowSnapshotCodec, planningFactory, nodeStatePublisherFactory, runExecutionContextFactory, nodeActivationRequestComposer, activationEnqueueService, semantics, waiters, deps.workflowPolicyRuntimeDefaults, executionLimitsPolicy);
|
|
737
859
|
const runContinuationService = new require_RunIntentService.RunContinuationService(deps.activationIdFactory, deps.workflowExecutionRepository, deps.runDataFactory, runExecutionContextFactory, workflowSnapshotResolver, planningFactory, nodeStatePublisherFactory, credentialResolverFactory, nodeActivationRequestComposer, persistedRunStateTerminalBuilder, activationEnqueueService, nodeEventPublisher, semantics, waiters, policyErrorServices, terminalPersistence, executionLimitsPolicy);
|
|
860
|
+
const nodeExecutionRequestHandler = new NodeExecutionRequestHandlerService(deps.workflowExecutionRepository, workflowSnapshotResolver, deps.runDataFactory, runExecutionContextFactory, nodeStatePublisherFactory, nodeActivationRequestComposer, deps.nodeExecutor, runContinuationService, executionLimitsPolicy);
|
|
738
861
|
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) => {
|
|
739
862
|
await runStartService.runWorkflow(workflow, triggerNodeId, items, void 0);
|
|
740
863
|
} }, executionLimitsPolicy, deps.triggerRuntimeDiagnostics);
|
|
@@ -745,7 +868,8 @@ var EngineFactory = class {
|
|
|
745
868
|
workflowSnapshotResolver,
|
|
746
869
|
triggerRuntime,
|
|
747
870
|
runStartService,
|
|
748
|
-
runContinuationService
|
|
871
|
+
runContinuationService,
|
|
872
|
+
nodeExecutionRequestHandler
|
|
749
873
|
});
|
|
750
874
|
deps.activationScheduler.setContinuation?.(engine);
|
|
751
875
|
return engine;
|
|
@@ -903,6 +1027,7 @@ var EngineRuntimeRegistrar = class {
|
|
|
903
1027
|
this.registerSupportFactories(container);
|
|
904
1028
|
this.registerExecutionLimitsPolicy(container, options);
|
|
905
1029
|
this.ensureWorkflowNodeInstanceFactory(container);
|
|
1030
|
+
this.ensureNodeExecutor(container);
|
|
906
1031
|
this.registerDefaultActivationScheduler(container);
|
|
907
1032
|
this.registerEngine(container, options);
|
|
908
1033
|
this.registerIntentServices(container);
|
|
@@ -931,12 +1056,15 @@ var EngineRuntimeRegistrar = class {
|
|
|
931
1056
|
return dependencyContainer.resolve(require_RunIntentService.NodeInstanceFactoryFactory).create(dependencyContainer.resolve(require_RunIntentService.CoreTokens.NodeResolver));
|
|
932
1057
|
}) });
|
|
933
1058
|
}
|
|
934
|
-
|
|
935
|
-
if (container.isRegistered(require_RunIntentService.
|
|
1059
|
+
ensureNodeExecutor(container) {
|
|
1060
|
+
if (container.isRegistered(require_RunIntentService.NodeExecutor, true)) return;
|
|
936
1061
|
container.register(require_RunIntentService.NodeExecutor, { useFactory: (0, tsyringe.instanceCachingFactory)((dependencyContainer) => {
|
|
937
1062
|
const retryRunner = dependencyContainer.resolve(require_RunIntentService.InProcessRetryRunnerFactory).create(dependencyContainer.resolve(require_RunIntentService.DefaultAsyncSleeper));
|
|
938
1063
|
return dependencyContainer.resolve(require_RunIntentService.NodeExecutorFactory).create(dependencyContainer.resolve(require_RunIntentService.CoreTokens.WorkflowNodeInstanceFactory), retryRunner);
|
|
939
1064
|
}) });
|
|
1065
|
+
}
|
|
1066
|
+
registerDefaultActivationScheduler(container) {
|
|
1067
|
+
if (container.isRegistered(require_RunIntentService.CoreTokens.NodeActivationScheduler, true)) return;
|
|
940
1068
|
container.register(require_RunIntentService.InlineDrivingScheduler, { useFactory: (0, tsyringe.instanceCachingFactory)((dependencyContainer) => {
|
|
941
1069
|
return dependencyContainer.resolve(InlineDrivingSchedulerFactory).create(dependencyContainer.resolve(require_RunIntentService.NodeExecutor));
|
|
942
1070
|
}) });
|
|
@@ -969,6 +1097,7 @@ var EngineRuntimeRegistrar = class {
|
|
|
969
1097
|
activationScheduler: dependencyContainer.resolve(require_RunIntentService.CoreTokens.NodeActivationScheduler),
|
|
970
1098
|
runDataFactory: dependencyContainer.resolve(require_RunIntentService.CoreTokens.RunDataFactory),
|
|
971
1099
|
executionContextFactory: dependencyContainer.resolve(require_RunIntentService.CoreTokens.ExecutionContextFactory),
|
|
1100
|
+
nodeExecutor: dependencyContainer.resolve(require_RunIntentService.NodeExecutor),
|
|
972
1101
|
eventBus: dependencyContainer.resolve(require_RunIntentService.CoreTokens.RunEventBus),
|
|
973
1102
|
tokenRegistry: tokenRegistryLike,
|
|
974
1103
|
workflowNodeInstanceFactory,
|