@sdux-vault/engine 0.0.9 → 0.1.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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { registerVersion, vaultDebug, ControllerVotes, ControllerMessageTypes, OperationTypes, vaultWarn, VaultController, defineControllerKey, ControllerTypes, DevMode, DecisionOutcomeTypes, vaultError, defineBehaviorKey, DEVTOOLS_LOGGING_KEY_CONSTANT, DEVTOOLS_AGGREGATE_KEY_CONSTANT, createVaultError, EventTypes, EventBoundaryTypes, setVaultLogLevel, isTestEnv, BEHAVIOR_META, validateBehaviorKey, BehaviorTypes, VAULT_STOP, isVaultNoop, VaultPrivateErrorService, isHttpResourceRef, isFunction, isStateInputShape, isVaultClearState, VAULT_CLEAR_STATE, VAULT_NOOP, VAULT_CONTINUE, isVaultContinue,
|
|
1
|
+
import { registerVersion, vaultDebug, ControllerVotes, ControllerMessageTypes, OperationTypes, vaultWarn, VaultController, defineControllerKey, ControllerTypes, DevMode, DecisionOutcomeTypes, vaultError, defineBehaviorKey, DEVTOOLS_LOGGING_KEY_CONSTANT, DEVTOOLS_AGGREGATE_KEY_CONSTANT, createVaultError, EventTypes, EventBoundaryTypes, setVaultLogLevel, isTestEnv, BEHAVIOR_META, validateBehaviorKey, BehaviorTypes, VAULT_STOP, isVaultNoop, VaultPrivateErrorService, isHttpResourceRef, isFunction, isStateInputShape, isolateValue, isVaultClearState, VAULT_CLEAR_STATE, VAULT_NOOP, VAULT_CONTINUE, isVaultContinue, isUndefined, isDefined, isNullish, ResolveTypes, isPromise, VaultUsagePromiseError, CONTROLLER_META, validateControllerKey, VaultLicenseError } from '@sdux-vault/shared';
|
|
2
2
|
import { of, map, catchError, forkJoin, Subject, ReplaySubject, isObservable, firstValueFrom, tap } from 'rxjs';
|
|
3
3
|
import { __decorate } from 'tslib';
|
|
4
4
|
import { filter } from 'rxjs/operators';
|
|
@@ -11,7 +11,7 @@ import { EventBus } from '@sdux-vault/devtools';
|
|
|
11
11
|
// cmd+alt+j (see .vscode/keybindings.json)
|
|
12
12
|
// --- END AI MODEL FILE PATH ---
|
|
13
13
|
const SDUX_PACKAGE = '@sdux-vault/engine';
|
|
14
|
-
const SDUX_VERSION = '0.0
|
|
14
|
+
const SDUX_VERSION = '0.1.0';
|
|
15
15
|
registerVersion(SDUX_PACKAGE, SDUX_VERSION);
|
|
16
16
|
|
|
17
17
|
/**
|
|
@@ -2194,8 +2194,8 @@ const assignTraceId = () => {
|
|
|
2194
2194
|
const isPipelineTerminal = (current) => isVaultNoop(current) || isSignalStop(current);
|
|
2195
2195
|
|
|
2196
2196
|
// --- AI Model File Path (DO NOT DELETE) ---
|
|
2197
|
-
// FilePath:
|
|
2198
|
-
// Updated: 2026-
|
|
2197
|
+
// FilePath: lib > src > orchestrator > orchestrator.ts
|
|
2198
|
+
// Updated: 2026-04-07 16:30
|
|
2199
2199
|
// Generated by pathcomment [tab] (see .vscode/typescript.code-snippets) or
|
|
2200
2200
|
// cmd+alt+j (see .vscode/keybindings.json)
|
|
2201
2201
|
// --- END AI MODEL FILE PATH ---
|
|
@@ -2243,13 +2243,6 @@ class Orchestrator {
|
|
|
2243
2243
|
resetBehaviors(ctx) {
|
|
2244
2244
|
this.#resetBehaviors(ctx);
|
|
2245
2245
|
}
|
|
2246
|
-
preparingIncoming(ctx) {
|
|
2247
|
-
const incoming = this.#coreStateBehavior.preparePipelineIncoming(ctx);
|
|
2248
|
-
if (isVaultNoop(incoming)) {
|
|
2249
|
-
this.#runStateBehaviors(ctx);
|
|
2250
|
-
}
|
|
2251
|
-
return incoming;
|
|
2252
|
-
}
|
|
2253
2246
|
async orchestrate(ctx, options) {
|
|
2254
2247
|
// no controllers → pipeline behaves exactly as before
|
|
2255
2248
|
if (ctx.operation === OperationTypes.Replace) {
|
|
@@ -2276,7 +2269,7 @@ class Orchestrator {
|
|
|
2276
2269
|
return incoming;
|
|
2277
2270
|
}
|
|
2278
2271
|
if (isStateInputShape(incoming)) {
|
|
2279
|
-
return incoming;
|
|
2272
|
+
return isolateValue(incoming);
|
|
2280
2273
|
}
|
|
2281
2274
|
return {
|
|
2282
2275
|
value: incoming
|
|
@@ -2294,14 +2287,31 @@ class Orchestrator {
|
|
|
2294
2287
|
}
|
|
2295
2288
|
}
|
|
2296
2289
|
}
|
|
2297
|
-
|
|
2290
|
+
prepareIncoming(ctx, incoming, operation) {
|
|
2291
|
+
ctx = this.#prepIncomingForOrchestration(ctx, incoming, operation);
|
|
2292
|
+
const normalizedIncoming = this.#coreStateBehavior.preparePipelineIncoming(ctx);
|
|
2293
|
+
if (isVaultNoop(normalizedIncoming)) {
|
|
2294
|
+
this.vaultMonitor.startCoreState(this.cellKey, VAULT_ORCHESTRATOR, ctx);
|
|
2295
|
+
this.#runStateBehaviors(ctx);
|
|
2296
|
+
this.vaultMonitor.endCoreState(this.cellKey, VAULT_ORCHESTRATOR, ctx);
|
|
2297
|
+
}
|
|
2298
|
+
if (isVaultClearState(normalizedIncoming)) {
|
|
2299
|
+
this.vaultMonitor.startCoreState(this.cellKey, VAULT_ORCHESTRATOR, ctx);
|
|
2300
|
+
this.#resetBehaviors(ctx);
|
|
2301
|
+
this.#runStateBehaviors(ctx);
|
|
2302
|
+
this.vaultMonitor.endCoreState(this.cellKey, VAULT_ORCHESTRATOR, ctx);
|
|
2303
|
+
return;
|
|
2304
|
+
}
|
|
2305
|
+
return normalizedIncoming;
|
|
2306
|
+
}
|
|
2307
|
+
//#endregion
|
|
2308
|
+
//#region Private Methods
|
|
2309
|
+
#prepIncomingForOrchestration(ctx, incoming, operation) {
|
|
2298
2310
|
ctx.incoming = this.normalizeIncoming(incoming);
|
|
2299
2311
|
ctx.resolveType = this.#getResolveType(incoming);
|
|
2300
2312
|
ctx.operation = operation;
|
|
2301
2313
|
return ctx;
|
|
2302
2314
|
}
|
|
2303
|
-
//#endregion
|
|
2304
|
-
//#region Private Methods
|
|
2305
2315
|
#addDefaultMergeBehavior(behaviors, config) {
|
|
2306
2316
|
const mergeBehaviors = config.behaviors.filter((behaviorClass) => {
|
|
2307
2317
|
return behaviorClass.type === BehaviorTypes.Merge;
|
|
@@ -2491,14 +2501,15 @@ class Orchestrator {
|
|
|
2491
2501
|
async #orchestrateMerge(ctx, options) {
|
|
2492
2502
|
this.vaultMonitor.startMerge(this.cellKey, VAULT_ORCHESTRATOR, ctx);
|
|
2493
2503
|
await this.#safeAsync(async () => {
|
|
2494
|
-
const
|
|
2504
|
+
const safeCurrent = isolateValue(ctx.lastSnapshot.value);
|
|
2495
2505
|
let finalState;
|
|
2496
2506
|
finalState = await this.#runInterceptorStage(ctx);
|
|
2497
2507
|
if (!isSignalStop(finalState)) {
|
|
2498
2508
|
const partial = await this.#runUpstreamStage(BehaviorTypes.Resolve, ctx, undefined);
|
|
2509
|
+
const safePartial = isolateValue(partial);
|
|
2499
2510
|
this.vaultMonitor.startComputeMerge(this.cellKey, VAULT_ORCHESTRATOR, ctx);
|
|
2500
2511
|
// eslint-disable-next-line
|
|
2501
|
-
const mergeResult = await this.#mergeBehavior.computeMerge(
|
|
2512
|
+
const mergeResult = await this.#mergeBehavior.computeMerge(safeCurrent, safePartial, options);
|
|
2502
2513
|
this.vaultMonitor.endComputeMerge(this.cellKey, VAULT_ORCHESTRATOR, ctx);
|
|
2503
2514
|
if (isVaultClearState(mergeResult)) {
|
|
2504
2515
|
finalState = VAULT_CLEAR_STATE;
|
|
@@ -2569,6 +2580,8 @@ class Orchestrator {
|
|
|
2569
2580
|
if (typeof behavior.computeResolve === 'function') {
|
|
2570
2581
|
this.vaultMonitor.startResolve(this.cellKey, behavior.key, ctx);
|
|
2571
2582
|
next = await behavior.computeResolve(ctx);
|
|
2583
|
+
if (isDefined(next))
|
|
2584
|
+
current = isolateValue(next);
|
|
2572
2585
|
this.vaultMonitor.endResolve(this.cellKey, behavior.key, ctx);
|
|
2573
2586
|
}
|
|
2574
2587
|
break;
|
|
@@ -2577,7 +2590,9 @@ class Orchestrator {
|
|
|
2577
2590
|
case BehaviorTypes.StepwiseReducer:
|
|
2578
2591
|
if (typeof behavior.evaluateStepwise === 'function') {
|
|
2579
2592
|
this.vaultMonitor.startStepwise(this.cellKey, behavior.key, ctx);
|
|
2580
|
-
|
|
2593
|
+
const safeCurrent = isolateValue(ctx.lastSnapshot.value);
|
|
2594
|
+
const safeCandidate = isolateValue(current);
|
|
2595
|
+
next = await behavior.evaluateStepwise(safeCurrent, safeCandidate, ctx.featureCellKey);
|
|
2581
2596
|
this.vaultMonitor.endStepwise(this.cellKey, behavior.key, ctx);
|
|
2582
2597
|
}
|
|
2583
2598
|
break;
|
|
@@ -2585,10 +2600,11 @@ class Orchestrator {
|
|
|
2585
2600
|
if (typeof behavior.applyFilter === 'function') {
|
|
2586
2601
|
for (const filter of this.#filterFunctions) {
|
|
2587
2602
|
this.vaultMonitor.startFilter(this.cellKey, behavior.key, ctx);
|
|
2588
|
-
const
|
|
2603
|
+
const safeCurrent = isolateValue(current);
|
|
2604
|
+
const nextValue = await behavior.applyFilter(safeCurrent, filter);
|
|
2589
2605
|
this.vaultMonitor.endFilter(this.cellKey, behavior.key, ctx);
|
|
2590
2606
|
if (isDefined(nextValue)) {
|
|
2591
|
-
current = nextValue;
|
|
2607
|
+
current = isolateValue(nextValue);
|
|
2592
2608
|
}
|
|
2593
2609
|
}
|
|
2594
2610
|
}
|
|
@@ -2597,7 +2613,8 @@ class Orchestrator {
|
|
|
2597
2613
|
if (typeof behavior.applyBeforeTap === 'function') {
|
|
2598
2614
|
for (const beforeTap of this.#beforeTapCallbacks) {
|
|
2599
2615
|
this.vaultMonitor.startBeforeTap(this.cellKey, behavior.key, ctx);
|
|
2600
|
-
|
|
2616
|
+
const safeCurrent = isolateValue(current);
|
|
2617
|
+
await behavior.applyBeforeTap(safeCurrent, beforeTap);
|
|
2601
2618
|
this.vaultMonitor.endBeforeTap(this.cellKey, behavior.key, ctx);
|
|
2602
2619
|
}
|
|
2603
2620
|
}
|
|
@@ -2609,10 +2626,11 @@ class Orchestrator {
|
|
|
2609
2626
|
}
|
|
2610
2627
|
for (const reducer of this.#reducerFunctions) {
|
|
2611
2628
|
this.vaultMonitor.startReducer(this.cellKey, behavior.key, ctx);
|
|
2612
|
-
const
|
|
2629
|
+
const safeCurrent = isolateValue(current);
|
|
2630
|
+
const nextValue = await behavior.applyReducer(safeCurrent, reducer);
|
|
2613
2631
|
this.vaultMonitor.endReducer(this.cellKey, behavior.key, ctx);
|
|
2614
2632
|
if (isDefined(nextValue)) {
|
|
2615
|
-
current = nextValue;
|
|
2633
|
+
current = isolateValue(nextValue);
|
|
2616
2634
|
}
|
|
2617
2635
|
}
|
|
2618
2636
|
}
|
|
@@ -2621,7 +2639,8 @@ class Orchestrator {
|
|
|
2621
2639
|
if (typeof behavior.applyAfterTap === 'function') {
|
|
2622
2640
|
for (const afterTap of this.#afterTapCallbacks) {
|
|
2623
2641
|
this.vaultMonitor.startAfterTap(this.cellKey, behavior.key, ctx);
|
|
2624
|
-
|
|
2642
|
+
const safeCurrent = isolateValue(current);
|
|
2643
|
+
await behavior.applyAfterTap(safeCurrent, afterTap);
|
|
2625
2644
|
this.vaultMonitor.endAfterTap(this.cellKey, behavior.key, ctx);
|
|
2626
2645
|
}
|
|
2627
2646
|
}
|
|
@@ -2633,7 +2652,7 @@ class Orchestrator {
|
|
|
2633
2652
|
throw err;
|
|
2634
2653
|
}
|
|
2635
2654
|
if (isDefined(next))
|
|
2636
|
-
current = next;
|
|
2655
|
+
current = isolateValue(next);
|
|
2637
2656
|
}
|
|
2638
2657
|
return current;
|
|
2639
2658
|
}
|
|
@@ -2642,6 +2661,7 @@ class Orchestrator {
|
|
|
2642
2661
|
for (const behavior of interceptorBehaviors) {
|
|
2643
2662
|
try {
|
|
2644
2663
|
this.vaultMonitor.startInterceptor(this.cellKey, behavior.key, ctx);
|
|
2664
|
+
ctx.incoming = isolateValue(ctx.incoming);
|
|
2645
2665
|
const nextIncoming = await behavior.applyInterceptor(ctx);
|
|
2646
2666
|
if (isSignalStop(nextIncoming)) {
|
|
2647
2667
|
this.vaultMonitor.endInterceptor(this.cellKey, behavior.key, ctx, { pipelinePaused: true });
|
|
@@ -2665,13 +2685,14 @@ class Orchestrator {
|
|
|
2665
2685
|
for (const behavior of operatorBehaviors) {
|
|
2666
2686
|
try {
|
|
2667
2687
|
this.vaultMonitor.startOperator(this.cellKey, behavior.key, ctx);
|
|
2668
|
-
const
|
|
2688
|
+
const safeCurrent = isolateValue(current);
|
|
2689
|
+
const next = await behavior.applyOperator(safeCurrent);
|
|
2669
2690
|
if (isUndefined(next)) {
|
|
2670
2691
|
// short-circuit pipeline — operator decided to block this write
|
|
2671
2692
|
this.vaultMonitor.endOperator(this.cellKey, behavior.key, ctx, { noop: true });
|
|
2672
2693
|
return undefined;
|
|
2673
2694
|
}
|
|
2674
|
-
current = next;
|
|
2695
|
+
current = isolateValue(next);
|
|
2675
2696
|
this.vaultMonitor.endOperator(this.cellKey, behavior.key, ctx);
|
|
2676
2697
|
}
|
|
2677
2698
|
catch (err) {
|
|
@@ -2690,14 +2711,19 @@ class Orchestrator {
|
|
|
2690
2711
|
case BehaviorTypes.Encrypt:
|
|
2691
2712
|
if (typeof behavior.encryptState === 'function') {
|
|
2692
2713
|
this.vaultMonitor.startEncrypt(this.cellKey, behavior.key, ctx);
|
|
2693
|
-
|
|
2714
|
+
const safeCurrent = isolateValue(current);
|
|
2715
|
+
const nextValue = await behavior.encryptState(ctx, safeCurrent);
|
|
2694
2716
|
this.vaultMonitor.endEncrypt(this.cellKey, behavior.key, ctx);
|
|
2717
|
+
if (isDefined(nextValue)) {
|
|
2718
|
+
current = isolateValue(nextValue);
|
|
2719
|
+
}
|
|
2695
2720
|
}
|
|
2696
2721
|
break;
|
|
2697
2722
|
case BehaviorTypes.Persist:
|
|
2698
2723
|
if (typeof behavior.persistState === 'function') {
|
|
2699
2724
|
this.vaultMonitor.startPersist(this.cellKey, behavior.key, ctx);
|
|
2700
|
-
|
|
2725
|
+
const safeCurrent = isolateValue(current);
|
|
2726
|
+
await behavior.persistState(safeCurrent);
|
|
2701
2727
|
this.vaultMonitor.endPersist(this.cellKey, behavior.key, ctx);
|
|
2702
2728
|
}
|
|
2703
2729
|
break;
|
|
@@ -2881,7 +2907,7 @@ class Orchestrator {
|
|
|
2881
2907
|
}
|
|
2882
2908
|
incoming.value = value;
|
|
2883
2909
|
if (!isNullish(incoming.value)) {
|
|
2884
|
-
await this.orchestrate(this
|
|
2910
|
+
await this.orchestrate(this.#prepIncomingForOrchestration(ctx, incoming, OperationTypes.Replace));
|
|
2885
2911
|
}
|
|
2886
2912
|
else {
|
|
2887
2913
|
this.decisionEngine?.notifySuccess(this.buildControllerCtx(ctx));
|
|
@@ -2920,7 +2946,7 @@ class Orchestrator {
|
|
|
2920
2946
|
const decrypted = await behavior.decryptState?.(ctx, loaded);
|
|
2921
2947
|
if (isDefined(decrypted)) {
|
|
2922
2948
|
this.vaultMonitor.endDecrypt(this.cellKey, behavior.key, ctx);
|
|
2923
|
-
loaded = decrypted;
|
|
2949
|
+
loaded = isolateValue(decrypted);
|
|
2924
2950
|
}
|
|
2925
2951
|
else {
|
|
2926
2952
|
this.vaultMonitor.endDecrypt(this.cellKey, behavior.key, ctx, { noop: true });
|
|
@@ -3088,6 +3114,12 @@ class ControllerInitializationClass {
|
|
|
3088
3114
|
}
|
|
3089
3115
|
}
|
|
3090
3116
|
|
|
3117
|
+
// --- AI Model File Path (DO NOT DELETE) ---
|
|
3118
|
+
// FilePath: lib > src > conductor > conductor.ts
|
|
3119
|
+
// Updated: 2026-04-07 16:29
|
|
3120
|
+
// Generated by pathcomment [tab] (see .vscode/typescript.code-snippets) or
|
|
3121
|
+
// cmd+alt+j (see .vscode/keybindings.json)
|
|
3122
|
+
// --- END AI MODEL FILE PATH ---
|
|
3091
3123
|
class Conductor extends Orchestrator {
|
|
3092
3124
|
#attemptQueue = [];
|
|
3093
3125
|
#controllers = [];
|
|
@@ -3128,11 +3160,11 @@ class Conductor extends Orchestrator {
|
|
|
3128
3160
|
//#region public method
|
|
3129
3161
|
conduct(ctx, incoming, operation, options) {
|
|
3130
3162
|
const behaviorCtx = this.#buildPipelineCtx(ctx, operation, options);
|
|
3131
|
-
const
|
|
3132
|
-
if (isVaultNoop(
|
|
3163
|
+
const preparedIncoming = this.prepareIncoming(behaviorCtx, incoming, operation);
|
|
3164
|
+
if (isVaultNoop(preparedIncoming) || isVaultClearState(preparedIncoming)) {
|
|
3133
3165
|
return;
|
|
3134
3166
|
}
|
|
3135
|
-
behaviorCtx.incoming =
|
|
3167
|
+
behaviorCtx.incoming = preparedIncoming;
|
|
3136
3168
|
const controllerCtx = this.buildControllerCtx(behaviorCtx);
|
|
3137
3169
|
this.#enqueueAttempt({ behaviorCtx, controllerCtx, options });
|
|
3138
3170
|
}
|
|
@@ -3444,15 +3476,6 @@ class Conductor extends Orchestrator {
|
|
|
3444
3476
|
incoming: undefined
|
|
3445
3477
|
};
|
|
3446
3478
|
}
|
|
3447
|
-
#ensureIncoming(ctx) {
|
|
3448
|
-
const incoming = this.preparingIncoming(ctx);
|
|
3449
|
-
if (isVaultNoop(incoming)) {
|
|
3450
|
-
this.vaultMonitor.startCoreState(this.cellKey, VAULT_CONDUCTOR, ctx);
|
|
3451
|
-
this.reset(ctx);
|
|
3452
|
-
this.vaultMonitor.endCoreState(this.cellKey, VAULT_CONDUCTOR, ctx);
|
|
3453
|
-
}
|
|
3454
|
-
return incoming;
|
|
3455
|
-
}
|
|
3456
3479
|
#resetConductor() {
|
|
3457
3480
|
this.#attemptQueue.length = 0;
|
|
3458
3481
|
this.#processing = false;
|