@sdux-vault/engine 0.0.9 → 0.0.10
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.0.10';
|
|
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,24 @@ 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
|
+
return normalizedIncoming;
|
|
2299
|
+
}
|
|
2300
|
+
//#endregion
|
|
2301
|
+
//#region Private Methods
|
|
2302
|
+
#prepIncomingForOrchestration(ctx, incoming, operation) {
|
|
2298
2303
|
ctx.incoming = this.normalizeIncoming(incoming);
|
|
2299
2304
|
ctx.resolveType = this.#getResolveType(incoming);
|
|
2300
2305
|
ctx.operation = operation;
|
|
2301
2306
|
return ctx;
|
|
2302
2307
|
}
|
|
2303
|
-
//#endregion
|
|
2304
|
-
//#region Private Methods
|
|
2305
2308
|
#addDefaultMergeBehavior(behaviors, config) {
|
|
2306
2309
|
const mergeBehaviors = config.behaviors.filter((behaviorClass) => {
|
|
2307
2310
|
return behaviorClass.type === BehaviorTypes.Merge;
|
|
@@ -2491,14 +2494,15 @@ class Orchestrator {
|
|
|
2491
2494
|
async #orchestrateMerge(ctx, options) {
|
|
2492
2495
|
this.vaultMonitor.startMerge(this.cellKey, VAULT_ORCHESTRATOR, ctx);
|
|
2493
2496
|
await this.#safeAsync(async () => {
|
|
2494
|
-
const
|
|
2497
|
+
const safeCurrent = isolateValue(ctx.lastSnapshot.value);
|
|
2495
2498
|
let finalState;
|
|
2496
2499
|
finalState = await this.#runInterceptorStage(ctx);
|
|
2497
2500
|
if (!isSignalStop(finalState)) {
|
|
2498
2501
|
const partial = await this.#runUpstreamStage(BehaviorTypes.Resolve, ctx, undefined);
|
|
2502
|
+
const safePartial = isolateValue(partial);
|
|
2499
2503
|
this.vaultMonitor.startComputeMerge(this.cellKey, VAULT_ORCHESTRATOR, ctx);
|
|
2500
2504
|
// eslint-disable-next-line
|
|
2501
|
-
const mergeResult = await this.#mergeBehavior.computeMerge(
|
|
2505
|
+
const mergeResult = await this.#mergeBehavior.computeMerge(safeCurrent, safePartial, options);
|
|
2502
2506
|
this.vaultMonitor.endComputeMerge(this.cellKey, VAULT_ORCHESTRATOR, ctx);
|
|
2503
2507
|
if (isVaultClearState(mergeResult)) {
|
|
2504
2508
|
finalState = VAULT_CLEAR_STATE;
|
|
@@ -2569,6 +2573,8 @@ class Orchestrator {
|
|
|
2569
2573
|
if (typeof behavior.computeResolve === 'function') {
|
|
2570
2574
|
this.vaultMonitor.startResolve(this.cellKey, behavior.key, ctx);
|
|
2571
2575
|
next = await behavior.computeResolve(ctx);
|
|
2576
|
+
if (isDefined(next))
|
|
2577
|
+
current = isolateValue(next);
|
|
2572
2578
|
this.vaultMonitor.endResolve(this.cellKey, behavior.key, ctx);
|
|
2573
2579
|
}
|
|
2574
2580
|
break;
|
|
@@ -2577,7 +2583,9 @@ class Orchestrator {
|
|
|
2577
2583
|
case BehaviorTypes.StepwiseReducer:
|
|
2578
2584
|
if (typeof behavior.evaluateStepwise === 'function') {
|
|
2579
2585
|
this.vaultMonitor.startStepwise(this.cellKey, behavior.key, ctx);
|
|
2580
|
-
|
|
2586
|
+
const safeCurrent = isolateValue(ctx.lastSnapshot.value);
|
|
2587
|
+
const safeCandidate = isolateValue(current);
|
|
2588
|
+
next = await behavior.evaluateStepwise(safeCurrent, safeCandidate, ctx.featureCellKey);
|
|
2581
2589
|
this.vaultMonitor.endStepwise(this.cellKey, behavior.key, ctx);
|
|
2582
2590
|
}
|
|
2583
2591
|
break;
|
|
@@ -2585,10 +2593,11 @@ class Orchestrator {
|
|
|
2585
2593
|
if (typeof behavior.applyFilter === 'function') {
|
|
2586
2594
|
for (const filter of this.#filterFunctions) {
|
|
2587
2595
|
this.vaultMonitor.startFilter(this.cellKey, behavior.key, ctx);
|
|
2588
|
-
const
|
|
2596
|
+
const safeCurrent = isolateValue(current);
|
|
2597
|
+
const nextValue = await behavior.applyFilter(safeCurrent, filter);
|
|
2589
2598
|
this.vaultMonitor.endFilter(this.cellKey, behavior.key, ctx);
|
|
2590
2599
|
if (isDefined(nextValue)) {
|
|
2591
|
-
current = nextValue;
|
|
2600
|
+
current = isolateValue(nextValue);
|
|
2592
2601
|
}
|
|
2593
2602
|
}
|
|
2594
2603
|
}
|
|
@@ -2597,7 +2606,8 @@ class Orchestrator {
|
|
|
2597
2606
|
if (typeof behavior.applyBeforeTap === 'function') {
|
|
2598
2607
|
for (const beforeTap of this.#beforeTapCallbacks) {
|
|
2599
2608
|
this.vaultMonitor.startBeforeTap(this.cellKey, behavior.key, ctx);
|
|
2600
|
-
|
|
2609
|
+
const safeCurrent = isolateValue(current);
|
|
2610
|
+
await behavior.applyBeforeTap(safeCurrent, beforeTap);
|
|
2601
2611
|
this.vaultMonitor.endBeforeTap(this.cellKey, behavior.key, ctx);
|
|
2602
2612
|
}
|
|
2603
2613
|
}
|
|
@@ -2609,10 +2619,11 @@ class Orchestrator {
|
|
|
2609
2619
|
}
|
|
2610
2620
|
for (const reducer of this.#reducerFunctions) {
|
|
2611
2621
|
this.vaultMonitor.startReducer(this.cellKey, behavior.key, ctx);
|
|
2612
|
-
const
|
|
2622
|
+
const safeCurrent = isolateValue(current);
|
|
2623
|
+
const nextValue = await behavior.applyReducer(safeCurrent, reducer);
|
|
2613
2624
|
this.vaultMonitor.endReducer(this.cellKey, behavior.key, ctx);
|
|
2614
2625
|
if (isDefined(nextValue)) {
|
|
2615
|
-
current = nextValue;
|
|
2626
|
+
current = isolateValue(nextValue);
|
|
2616
2627
|
}
|
|
2617
2628
|
}
|
|
2618
2629
|
}
|
|
@@ -2621,7 +2632,8 @@ class Orchestrator {
|
|
|
2621
2632
|
if (typeof behavior.applyAfterTap === 'function') {
|
|
2622
2633
|
for (const afterTap of this.#afterTapCallbacks) {
|
|
2623
2634
|
this.vaultMonitor.startAfterTap(this.cellKey, behavior.key, ctx);
|
|
2624
|
-
|
|
2635
|
+
const safeCurrent = isolateValue(current);
|
|
2636
|
+
await behavior.applyAfterTap(safeCurrent, afterTap);
|
|
2625
2637
|
this.vaultMonitor.endAfterTap(this.cellKey, behavior.key, ctx);
|
|
2626
2638
|
}
|
|
2627
2639
|
}
|
|
@@ -2633,7 +2645,7 @@ class Orchestrator {
|
|
|
2633
2645
|
throw err;
|
|
2634
2646
|
}
|
|
2635
2647
|
if (isDefined(next))
|
|
2636
|
-
current = next;
|
|
2648
|
+
current = isolateValue(next);
|
|
2637
2649
|
}
|
|
2638
2650
|
return current;
|
|
2639
2651
|
}
|
|
@@ -2642,6 +2654,7 @@ class Orchestrator {
|
|
|
2642
2654
|
for (const behavior of interceptorBehaviors) {
|
|
2643
2655
|
try {
|
|
2644
2656
|
this.vaultMonitor.startInterceptor(this.cellKey, behavior.key, ctx);
|
|
2657
|
+
ctx.incoming = isolateValue(ctx.incoming);
|
|
2645
2658
|
const nextIncoming = await behavior.applyInterceptor(ctx);
|
|
2646
2659
|
if (isSignalStop(nextIncoming)) {
|
|
2647
2660
|
this.vaultMonitor.endInterceptor(this.cellKey, behavior.key, ctx, { pipelinePaused: true });
|
|
@@ -2665,13 +2678,14 @@ class Orchestrator {
|
|
|
2665
2678
|
for (const behavior of operatorBehaviors) {
|
|
2666
2679
|
try {
|
|
2667
2680
|
this.vaultMonitor.startOperator(this.cellKey, behavior.key, ctx);
|
|
2668
|
-
const
|
|
2681
|
+
const safeCurrent = isolateValue(current);
|
|
2682
|
+
const next = await behavior.applyOperator(safeCurrent);
|
|
2669
2683
|
if (isUndefined(next)) {
|
|
2670
2684
|
// short-circuit pipeline — operator decided to block this write
|
|
2671
2685
|
this.vaultMonitor.endOperator(this.cellKey, behavior.key, ctx, { noop: true });
|
|
2672
2686
|
return undefined;
|
|
2673
2687
|
}
|
|
2674
|
-
current = next;
|
|
2688
|
+
current = isolateValue(next);
|
|
2675
2689
|
this.vaultMonitor.endOperator(this.cellKey, behavior.key, ctx);
|
|
2676
2690
|
}
|
|
2677
2691
|
catch (err) {
|
|
@@ -2690,14 +2704,19 @@ class Orchestrator {
|
|
|
2690
2704
|
case BehaviorTypes.Encrypt:
|
|
2691
2705
|
if (typeof behavior.encryptState === 'function') {
|
|
2692
2706
|
this.vaultMonitor.startEncrypt(this.cellKey, behavior.key, ctx);
|
|
2693
|
-
|
|
2707
|
+
const safeCurrent = isolateValue(current);
|
|
2708
|
+
const nextValue = await behavior.encryptState(ctx, safeCurrent);
|
|
2694
2709
|
this.vaultMonitor.endEncrypt(this.cellKey, behavior.key, ctx);
|
|
2710
|
+
if (isDefined(nextValue)) {
|
|
2711
|
+
current = isolateValue(nextValue);
|
|
2712
|
+
}
|
|
2695
2713
|
}
|
|
2696
2714
|
break;
|
|
2697
2715
|
case BehaviorTypes.Persist:
|
|
2698
2716
|
if (typeof behavior.persistState === 'function') {
|
|
2699
2717
|
this.vaultMonitor.startPersist(this.cellKey, behavior.key, ctx);
|
|
2700
|
-
|
|
2718
|
+
const safeCurrent = isolateValue(current);
|
|
2719
|
+
await behavior.persistState(safeCurrent);
|
|
2701
2720
|
this.vaultMonitor.endPersist(this.cellKey, behavior.key, ctx);
|
|
2702
2721
|
}
|
|
2703
2722
|
break;
|
|
@@ -2881,7 +2900,7 @@ class Orchestrator {
|
|
|
2881
2900
|
}
|
|
2882
2901
|
incoming.value = value;
|
|
2883
2902
|
if (!isNullish(incoming.value)) {
|
|
2884
|
-
await this.orchestrate(this
|
|
2903
|
+
await this.orchestrate(this.#prepIncomingForOrchestration(ctx, incoming, OperationTypes.Replace));
|
|
2885
2904
|
}
|
|
2886
2905
|
else {
|
|
2887
2906
|
this.decisionEngine?.notifySuccess(this.buildControllerCtx(ctx));
|
|
@@ -2920,7 +2939,7 @@ class Orchestrator {
|
|
|
2920
2939
|
const decrypted = await behavior.decryptState?.(ctx, loaded);
|
|
2921
2940
|
if (isDefined(decrypted)) {
|
|
2922
2941
|
this.vaultMonitor.endDecrypt(this.cellKey, behavior.key, ctx);
|
|
2923
|
-
loaded = decrypted;
|
|
2942
|
+
loaded = isolateValue(decrypted);
|
|
2924
2943
|
}
|
|
2925
2944
|
else {
|
|
2926
2945
|
this.vaultMonitor.endDecrypt(this.cellKey, behavior.key, ctx, { noop: true });
|
|
@@ -3088,6 +3107,12 @@ class ControllerInitializationClass {
|
|
|
3088
3107
|
}
|
|
3089
3108
|
}
|
|
3090
3109
|
|
|
3110
|
+
// --- AI Model File Path (DO NOT DELETE) ---
|
|
3111
|
+
// FilePath: lib > src > conductor > conductor.ts
|
|
3112
|
+
// Updated: 2026-04-07 16:29
|
|
3113
|
+
// Generated by pathcomment [tab] (see .vscode/typescript.code-snippets) or
|
|
3114
|
+
// cmd+alt+j (see .vscode/keybindings.json)
|
|
3115
|
+
// --- END AI MODEL FILE PATH ---
|
|
3091
3116
|
class Conductor extends Orchestrator {
|
|
3092
3117
|
#attemptQueue = [];
|
|
3093
3118
|
#controllers = [];
|
|
@@ -3128,7 +3153,7 @@ class Conductor extends Orchestrator {
|
|
|
3128
3153
|
//#region public method
|
|
3129
3154
|
conduct(ctx, incoming, operation, options) {
|
|
3130
3155
|
const behaviorCtx = this.#buildPipelineCtx(ctx, operation, options);
|
|
3131
|
-
const ensuredIncoming = this
|
|
3156
|
+
const ensuredIncoming = this.prepareIncoming(behaviorCtx, incoming, operation);
|
|
3132
3157
|
if (isVaultNoop(ensuredIncoming)) {
|
|
3133
3158
|
return;
|
|
3134
3159
|
}
|
|
@@ -3444,15 +3469,6 @@ class Conductor extends Orchestrator {
|
|
|
3444
3469
|
incoming: undefined
|
|
3445
3470
|
};
|
|
3446
3471
|
}
|
|
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
3472
|
#resetConductor() {
|
|
3457
3473
|
this.#attemptQueue.length = 0;
|
|
3458
3474
|
this.#processing = false;
|