@toolproof-core/lib 1.0.37 → 1.0.39
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/lookups/lookups.d.ts +6 -6
- package/dist/utils/mutableStrategyOverlay.d.ts +9 -9
- package/dist/utils/mutableStrategyOverlay.js +14 -14
- package/dist/utils/stepParallelization.js +1 -1
- package/dist/utils/strategyCanonicalization.d.ts +4 -2
- package/dist/utils/strategyCanonicalization.js +33 -4
- package/dist/utils/strategyStateResolution.d.ts +3 -3
- package/dist/utils/strategyStateResolution.js +5 -5
- package/package.json +2 -2
- package/src/utils/mutableStrategyOverlay.ts +24 -24
- package/src/utils/stepParallelization.ts +1 -1
- package/src/utils/strategyCanonicalization.ts +60 -13
- package/src/utils/strategyStateResolution.ts +8 -8
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -37,10 +37,10 @@ export declare const CONSTANTS: {
|
|
|
37
37
|
readonly Goal: "Goal";
|
|
38
38
|
readonly GoalHandle: "GoalHandle";
|
|
39
39
|
readonly InputPotential: "InputPotential";
|
|
40
|
-
readonly InputResource: "InputResource";
|
|
41
40
|
readonly InternalInputPotential: "InternalInputPotential";
|
|
42
41
|
readonly JsonScalarLink: "JsonScalarLink";
|
|
43
42
|
readonly JsonSchemaObject: "JsonSchemaObject";
|
|
43
|
+
readonly MaterializedResource: "MaterializedResource";
|
|
44
44
|
readonly Name: "Name";
|
|
45
45
|
readonly NameFacet: "NameFacet";
|
|
46
46
|
readonly Natural: "Natural";
|
|
@@ -75,10 +75,10 @@ export declare const CONSTANTS: {
|
|
|
75
75
|
readonly StrategyProvenance: "StrategyProvenance";
|
|
76
76
|
readonly StrategyStartTracePoint: "StrategyStartTracePoint";
|
|
77
77
|
readonly StrategyState: "StrategyState";
|
|
78
|
+
readonly StrategyStateEntry: "StrategyStateEntry";
|
|
79
|
+
readonly StrategyStateEntryByRoleName: "StrategyStateEntryByRoleName";
|
|
80
|
+
readonly StrategyStateEntryKind: "StrategyStateEntryKind";
|
|
78
81
|
readonly StrategyStateFacet: "StrategyStateFacet";
|
|
79
|
-
readonly StrategyStateInputEntry: "StrategyStateInputEntry";
|
|
80
|
-
readonly StrategyStateInputEntryByRoleName: "StrategyStateInputEntryByRoleName";
|
|
81
|
-
readonly StrategyStateInputKind: "StrategyStateInputKind";
|
|
82
82
|
readonly StrategyTrace: "StrategyTrace";
|
|
83
83
|
readonly StrategyTraceHandle: "StrategyTraceHandle";
|
|
84
84
|
readonly Suite: "Suite";
|
|
@@ -185,8 +185,8 @@ export declare const CONSTANTS: {
|
|
|
185
185
|
readonly while: "while";
|
|
186
186
|
readonly for: "for";
|
|
187
187
|
};
|
|
188
|
-
readonly
|
|
189
|
-
readonly
|
|
188
|
+
readonly StrategyStateEntryKind: {
|
|
189
|
+
readonly materializedResource: "materializedResource";
|
|
190
190
|
readonly externalInputPotential: "externalInputPotential";
|
|
191
191
|
readonly internalInputPotential: "internalInputPotential";
|
|
192
192
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { BranchStep, Case, ExternalInputPotential, ForStep,
|
|
1
|
+
import type { BranchStep, Case, ExternalInputPotential, ForStep, MaterializedResource, InternalInputPotential, Resource, RoleName, Strategy, Tool, ToolHandle, ToolStep, ToolStepRoleAddress, WhileStep } from '@toolproof-core/genesis';
|
|
2
2
|
export type MutableToolStepKey = string;
|
|
3
3
|
export type MutableBranchStepKey = string;
|
|
4
4
|
export type MutableWhileStepKey = string;
|
|
5
5
|
export type MutableForStepKey = string;
|
|
6
6
|
export type MutableLoopStepKey = MutableWhileStepKey | MutableForStepKey;
|
|
7
7
|
export type MutableMacroStepKey = MutableBranchStepKey | MutableLoopStepKey;
|
|
8
|
-
export type
|
|
8
|
+
export type MutableMaterializedResource = MaterializedResource;
|
|
9
9
|
export type MutableToolStepRoleAddress<TKey extends string = MutableToolStepKey> = Omit<ToolStepRoleAddress, 'toolStepPath'> & {
|
|
10
10
|
toolStepKey: TKey;
|
|
11
11
|
};
|
|
@@ -13,9 +13,9 @@ export type MutableInternalInputPotential<TKey extends string = MutableToolStepK
|
|
|
13
13
|
toolStepRoleAddress: MutableToolStepRoleAddress<TKey>;
|
|
14
14
|
};
|
|
15
15
|
export type MutableExternalInputPotential = ExternalInputPotential;
|
|
16
|
-
export type
|
|
17
|
-
export type
|
|
18
|
-
export type MutableStrategyState<TKey extends string = MutableToolStepKey> = Partial<Record<TKey,
|
|
16
|
+
export type MutableStrategyStateEntry<TKey extends string = MutableToolStepKey> = MutableMaterializedResource | MutableInternalInputPotential<TKey> | MutableExternalInputPotential;
|
|
17
|
+
export type MutableStrategyStateEntryByRoleName<TKey extends string = MutableToolStepKey> = Partial<Record<RoleName, MutableStrategyStateEntry<TKey>>>;
|
|
18
|
+
export type MutableStrategyState<TKey extends string = MutableToolStepKey> = Partial<Record<TKey, MutableStrategyStateEntryByRoleName<TKey>>>;
|
|
19
19
|
export type MutableToolStep<TKey extends string = MutableToolStepKey> = ToolStep & {
|
|
20
20
|
toolStepKey: TKey;
|
|
21
21
|
};
|
|
@@ -43,11 +43,11 @@ export type MutableStrategy<TKey extends string = MutableToolStepKey, TStep exte
|
|
|
43
43
|
export declare function getAuthoringSteps<TKey extends string = MutableToolStepKey, TStep extends MutableStep<TKey> = MutableStep<TKey>, TState extends MutableStrategyState<TKey> = MutableStrategyState<TKey>>(strategy: MutableStrategy<TKey, TStep, TState>): TStep[];
|
|
44
44
|
export declare function setAuthoringSteps<// ATTENTION
|
|
45
45
|
TKey extends string = MutableToolStepKey, TStep extends MutableStep<TKey> = MutableStep<TKey>, TState extends MutableStrategyState<TKey> = MutableStrategyState<TKey>>(strategy: MutableStrategy<TKey, TStep, TState>, steps: TStep[]): MutableStrategy<TKey, TStep, TState>;
|
|
46
|
-
export declare function
|
|
47
|
-
export declare function
|
|
48
|
-
export declare function
|
|
46
|
+
export declare function getStrategyStateEntryByRoleName<TKey extends string, TStrategyState extends MutableStrategyState<TKey>>(strategyState: TStrategyState, toolStepKey: TKey): MutableStrategyStateEntryByRoleName<TKey> | undefined;
|
|
47
|
+
export declare function getStrategyStateEntry<TKey extends string, TStrategyState extends MutableStrategyState<TKey>>(strategyState: TStrategyState, toolStepRoleAddress: MutableToolStepRoleAddress<TKey>): MutableStrategyStateEntry<TKey> | undefined;
|
|
48
|
+
export declare function setStrategyStateEntry<TKey extends string, TStrategyState extends MutableStrategyState<TKey>>(strategyState: TStrategyState, toolStepRoleAddress: MutableToolStepRoleAddress<TKey>, entry: MutableStrategyStateEntry<TKey>): TStrategyState;
|
|
49
49
|
export declare function clearInputBinding<TKey extends string, TStrategyState extends MutableStrategyState<TKey>>(strategyState: TStrategyState, toolStepRoleAddress: MutableToolStepRoleAddress<TKey>): TStrategyState;
|
|
50
|
-
export declare function
|
|
50
|
+
export declare function bindMaterializedResource<TKey extends string, TStrategyState extends MutableStrategyState<TKey>>(strategyState: TStrategyState, target: MutableToolStepRoleAddress<TKey>, resource: Resource): TStrategyState;
|
|
51
51
|
export declare function bindInternalInputPotential<TKey extends string, TStrategyState extends MutableStrategyState<TKey>>(strategyState: TStrategyState, targetAddress: MutableToolStepRoleAddress<TKey>, sourceAddress: MutableToolStepRoleAddress<TKey>, context: {
|
|
52
52
|
toolStepByKey: ReadonlyMap<TKey, MutableToolStep<TKey>>;
|
|
53
53
|
toolMap: ReadonlyMap<ToolHandle, Tool>;
|
|
@@ -10,15 +10,15 @@ export function setAuthoringSteps(strategy, steps) {
|
|
|
10
10
|
stepsByThreadIndex: nextStepsByThreadIndex,
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
|
-
export function
|
|
13
|
+
export function getStrategyStateEntryByRoleName(strategyState, toolStepKey) {
|
|
14
14
|
return strategyState[toolStepKey];
|
|
15
15
|
}
|
|
16
|
-
export function
|
|
17
|
-
const inputEntryByRoleName =
|
|
16
|
+
export function getStrategyStateEntry(strategyState, toolStepRoleAddress) {
|
|
17
|
+
const inputEntryByRoleName = getStrategyStateEntryByRoleName(strategyState, toolStepRoleAddress.toolStepKey);
|
|
18
18
|
return inputEntryByRoleName?.[toolStepRoleAddress.roleName];
|
|
19
19
|
}
|
|
20
|
-
export function
|
|
21
|
-
const inputEntryByRoleName =
|
|
20
|
+
export function setStrategyStateEntry(strategyState, toolStepRoleAddress, entry) {
|
|
21
|
+
const inputEntryByRoleName = getStrategyStateEntryByRoleName(strategyState, toolStepRoleAddress.toolStepKey) ?? {};
|
|
22
22
|
return {
|
|
23
23
|
...strategyState,
|
|
24
24
|
[toolStepRoleAddress.toolStepKey]: {
|
|
@@ -28,7 +28,7 @@ export function setStrategyStateInputEntry(strategyState, toolStepRoleAddress, e
|
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
export function clearInputBinding(strategyState, toolStepRoleAddress) {
|
|
31
|
-
const inputEntryByRoleName =
|
|
31
|
+
const inputEntryByRoleName = getStrategyStateEntryByRoleName(strategyState, toolStepRoleAddress.toolStepKey);
|
|
32
32
|
if (!inputEntryByRoleName || !(toolStepRoleAddress.roleName in inputEntryByRoleName)) {
|
|
33
33
|
return strategyState;
|
|
34
34
|
}
|
|
@@ -44,12 +44,12 @@ export function clearInputBinding(strategyState, toolStepRoleAddress) {
|
|
|
44
44
|
[toolStepRoleAddress.toolStepKey]: nextInputEntryByRoleName,
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
|
-
export function
|
|
48
|
-
const
|
|
47
|
+
export function bindMaterializedResource(strategyState, target, resource) {
|
|
48
|
+
const mutableMaterializedResource = {
|
|
49
49
|
...resource,
|
|
50
|
-
|
|
50
|
+
strategyStateEntryKind: 'materializedResource',
|
|
51
51
|
};
|
|
52
|
-
return
|
|
52
|
+
return setStrategyStateEntry(strategyState, target, mutableMaterializedResource);
|
|
53
53
|
}
|
|
54
54
|
function getInputRoleValue(tool, roleName) {
|
|
55
55
|
return tool.roleSpec.inputRoleValueByName[roleName];
|
|
@@ -99,8 +99,8 @@ export function bindInternalInputPotential(strategyState, targetAddress, sourceA
|
|
|
99
99
|
if (!sourceRoleType || !targetRoleType || sourceRoleType !== targetRoleType) {
|
|
100
100
|
throw new Error(`Reference type mismatch between source (${sourceAddress.toolStepKey}, ${sourceAddress.roleName}) and target (${targetAddress.toolStepKey}, ${targetAddress.roleName}).`);
|
|
101
101
|
}
|
|
102
|
-
return
|
|
103
|
-
|
|
102
|
+
return setStrategyStateEntry(strategyState, targetAddress, {
|
|
103
|
+
strategyStateEntryKind: 'internalInputPotential',
|
|
104
104
|
toolStepRoleAddress: {
|
|
105
105
|
toolStepKey: sourceAddress.toolStepKey,
|
|
106
106
|
roleName: sourceAddress.roleName,
|
|
@@ -109,7 +109,7 @@ export function bindInternalInputPotential(strategyState, targetAddress, sourceA
|
|
|
109
109
|
}
|
|
110
110
|
export function bindExternalInputPotential(strategyState, target) {
|
|
111
111
|
const mutableExternalInputPotential = {
|
|
112
|
-
|
|
112
|
+
strategyStateEntryKind: 'externalInputPotential',
|
|
113
113
|
};
|
|
114
|
-
return
|
|
114
|
+
return setStrategyStateEntry(strategyState, target, mutableExternalInputPotential);
|
|
115
115
|
}
|
|
@@ -59,7 +59,7 @@ export function getIndependentThreads(steps, strategyState) {
|
|
|
59
59
|
const bucket = strategyState[toolStepKey];
|
|
60
60
|
for (const inputRoleId of inputBindings) {
|
|
61
61
|
const entry = bucket?.[inputRoleId];
|
|
62
|
-
if (!entry || entry.
|
|
62
|
+
if (!entry || entry.strategyStateEntryKind !== 'internalInputPotential')
|
|
63
63
|
continue;
|
|
64
64
|
const producerToolStepKey = entry.toolStepRoleAddress?.toolStepKey;
|
|
65
65
|
if (typeof producerToolStepKey !== 'string') {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type { Strategy } from '@toolproof-core/genesis';
|
|
2
|
-
import type { MutableStrategy } from './mutableStrategyOverlay.js';
|
|
1
|
+
import type { Strategy, ToolStepPath } from '@toolproof-core/genesis';
|
|
2
|
+
import type { MutableStrategy, MutableStrategyStateEntryByRoleName, MutableToolStepKey } from './mutableStrategyOverlay.js';
|
|
3
3
|
export declare function strategyToMutableStrategy(strategy: Strategy): MutableStrategy;
|
|
4
4
|
export declare function mutableStrategyToStrategy(mutableStrategy: MutableStrategy): Strategy;
|
|
5
|
+
export declare function mutableToolStepKeyToToolStepPath(mutableStrategy: MutableStrategy, toolStepKey: MutableToolStepKey): ToolStepPath;
|
|
6
|
+
export declare function projectMutableRoleEntriesByToolStepKeyToCanonicalDelta(mutableStrategy: MutableStrategy, toolStepKey: MutableToolStepKey, roleEntries: MutableStrategyStateEntryByRoleName): Strategy['strategyState'];
|
|
@@ -40,7 +40,7 @@ function buildExecutionPathMap(strategy) {
|
|
|
40
40
|
return executionPathByKey;
|
|
41
41
|
}
|
|
42
42
|
function toCanonicalStrategyStateEntry(entry, executionPathByKey) {
|
|
43
|
-
if (entry.
|
|
43
|
+
if (entry.strategyStateEntryKind !== 'internalInputPotential') {
|
|
44
44
|
return entry;
|
|
45
45
|
}
|
|
46
46
|
const sourceToolStepPath = executionPathByKey.get(entry.toolStepRoleAddress.toolStepKey);
|
|
@@ -48,7 +48,7 @@ function toCanonicalStrategyStateEntry(entry, executionPathByKey) {
|
|
|
48
48
|
throw new Error(`Cannot project strategy state: no execution path found for toolStepKey '${entry.toolStepRoleAddress.toolStepKey}'.`);
|
|
49
49
|
}
|
|
50
50
|
return {
|
|
51
|
-
|
|
51
|
+
strategyStateEntryKind: 'internalInputPotential',
|
|
52
52
|
toolStepRoleAddress: {
|
|
53
53
|
toolStepPath: sourceToolStepPath,
|
|
54
54
|
roleName: entry.toolStepRoleAddress.roleName,
|
|
@@ -81,7 +81,7 @@ function toCanonicalStep(step) {
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
function toMutableStrategyStateEntry(entry, executionKeyByPath) {
|
|
84
|
-
if (entry.
|
|
84
|
+
if (entry.strategyStateEntryKind !== 'internalInputPotential') {
|
|
85
85
|
return entry;
|
|
86
86
|
}
|
|
87
87
|
const sourceToolStepKey = executionKeyByPath.get(entry.toolStepRoleAddress.toolStepPath);
|
|
@@ -89,7 +89,7 @@ function toMutableStrategyStateEntry(entry, executionKeyByPath) {
|
|
|
89
89
|
throw new Error(`Cannot deproject strategy state: no mutable key found for toolStepPath '${entry.toolStepRoleAddress.toolStepPath}'.`);
|
|
90
90
|
}
|
|
91
91
|
return {
|
|
92
|
-
|
|
92
|
+
strategyStateEntryKind: 'internalInputPotential',
|
|
93
93
|
toolStepRoleAddress: {
|
|
94
94
|
toolStepKey: sourceToolStepKey,
|
|
95
95
|
roleName: entry.toolStepRoleAddress.roleName,
|
|
@@ -213,3 +213,32 @@ export function mutableStrategyToStrategy(mutableStrategy) {
|
|
|
213
213
|
strategyState,
|
|
214
214
|
};
|
|
215
215
|
}
|
|
216
|
+
export function mutableToolStepKeyToToolStepPath(mutableStrategy, toolStepKey) {
|
|
217
|
+
const executionPathByKey = buildExecutionPathMap(mutableStrategy);
|
|
218
|
+
const toolStepPath = executionPathByKey.get(toolStepKey);
|
|
219
|
+
if (!toolStepPath) {
|
|
220
|
+
throw new Error(`Cannot project toolStepPath: no execution path found for toolStepKey '${toolStepKey}'.`);
|
|
221
|
+
}
|
|
222
|
+
return toolStepPath;
|
|
223
|
+
}
|
|
224
|
+
export function projectMutableRoleEntriesByToolStepKeyToCanonicalDelta(mutableStrategy, toolStepKey, roleEntries) {
|
|
225
|
+
const executionPathByKey = buildExecutionPathMap(mutableStrategy);
|
|
226
|
+
const toolStepPath = executionPathByKey.get(toolStepKey);
|
|
227
|
+
if (!toolStepPath) {
|
|
228
|
+
throw new Error(`Cannot project strategy state delta: no execution path found for toolStepKey '${toolStepKey}'.`);
|
|
229
|
+
}
|
|
230
|
+
const canonicalRoleEntries = Object.fromEntries(Object.entries(roleEntries)
|
|
231
|
+
.filter(([, entry]) => entry !== undefined)
|
|
232
|
+
.map(([roleName, entry]) => {
|
|
233
|
+
if (entry === undefined) {
|
|
234
|
+
throw new Error(`Cannot project strategy state delta: role '${roleName}' on toolStepKey '${toolStepKey}' is explicitly undefined.`);
|
|
235
|
+
}
|
|
236
|
+
return [
|
|
237
|
+
roleName,
|
|
238
|
+
toCanonicalStrategyStateEntry(entry, executionPathByKey),
|
|
239
|
+
];
|
|
240
|
+
}));
|
|
241
|
+
return {
|
|
242
|
+
[toolStepPath]: canonicalRoleEntries,
|
|
243
|
+
};
|
|
244
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { MutableMaterializedResource, MutableExternalInputPotential, MutableStrategyState, MutableToolStepKey, MutableToolStepRoleAddress } from './mutableStrategyOverlay.js';
|
|
2
2
|
export type ResolveResult<TKey extends string = MutableToolStepKey> = {
|
|
3
|
-
status: '
|
|
4
|
-
entry:
|
|
3
|
+
status: 'materializedResource';
|
|
4
|
+
entry: MutableMaterializedResource;
|
|
5
5
|
path: MutableToolStepRoleAddress<TKey>[];
|
|
6
6
|
} | {
|
|
7
7
|
status: 'externalInputPotential';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getStrategyStateEntry } from './mutableStrategyOverlay.js';
|
|
2
2
|
export function resolveStrategyStateChain(strategyState, start, opts) {
|
|
3
3
|
const maxDepth = opts?.maxDepth ?? 50;
|
|
4
4
|
const visited = new Set();
|
|
@@ -11,14 +11,14 @@ export function resolveStrategyStateChain(strategyState, start, opts) {
|
|
|
11
11
|
return { status: 'unresolved', reason: 'cycle', path };
|
|
12
12
|
}
|
|
13
13
|
visited.add(visitKey);
|
|
14
|
-
const entry =
|
|
14
|
+
const entry = getStrategyStateEntry(strategyState, current);
|
|
15
15
|
if (!entry) {
|
|
16
16
|
return { status: 'unresolved', reason: 'not-found', path };
|
|
17
17
|
}
|
|
18
|
-
if (entry.
|
|
19
|
-
return { status: '
|
|
18
|
+
if (entry.strategyStateEntryKind === 'materializedResource') {
|
|
19
|
+
return { status: 'materializedResource', entry, path };
|
|
20
20
|
}
|
|
21
|
-
if (entry.
|
|
21
|
+
if (entry.strategyStateEntryKind === 'externalInputPotential') {
|
|
22
22
|
return { status: 'externalInputPotential', entry, path };
|
|
23
23
|
}
|
|
24
24
|
current = entry.toolStepRoleAddress;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toolproof-core/lib",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.39",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [],
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"@types/node": "^22.0.0"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@toolproof-core/genesis": "^1.0.
|
|
75
|
+
"@toolproof-core/genesis": "^1.0.60",
|
|
76
76
|
"firebase-admin": "^13.7.0"
|
|
77
77
|
},
|
|
78
78
|
"scripts": {
|
|
@@ -3,7 +3,7 @@ import type {
|
|
|
3
3
|
Case,
|
|
4
4
|
ExternalInputPotential,
|
|
5
5
|
ForStep,
|
|
6
|
-
|
|
6
|
+
MaterializedResource,
|
|
7
7
|
InternalInputPotential,
|
|
8
8
|
Resource,
|
|
9
9
|
RoleName,
|
|
@@ -23,7 +23,7 @@ export type MutableForStepKey = string;
|
|
|
23
23
|
export type MutableLoopStepKey = MutableWhileStepKey | MutableForStepKey;
|
|
24
24
|
export type MutableMacroStepKey = MutableBranchStepKey | MutableLoopStepKey;
|
|
25
25
|
|
|
26
|
-
export type
|
|
26
|
+
export type MutableMaterializedResource = MaterializedResource;
|
|
27
27
|
|
|
28
28
|
export type MutableToolStepRoleAddress<TKey extends string = MutableToolStepKey> =
|
|
29
29
|
Omit<ToolStepRoleAddress, 'toolStepPath'> & {
|
|
@@ -37,18 +37,18 @@ export type MutableInternalInputPotential<TKey extends string = MutableToolStepK
|
|
|
37
37
|
|
|
38
38
|
export type MutableExternalInputPotential = ExternalInputPotential;
|
|
39
39
|
|
|
40
|
-
export type
|
|
41
|
-
|
|
|
40
|
+
export type MutableStrategyStateEntry<TKey extends string = MutableToolStepKey> =
|
|
41
|
+
| MutableMaterializedResource
|
|
42
42
|
| MutableInternalInputPotential<TKey>
|
|
43
43
|
| MutableExternalInputPotential;
|
|
44
44
|
|
|
45
|
-
export type
|
|
45
|
+
export type MutableStrategyStateEntryByRoleName<
|
|
46
46
|
TKey extends string = MutableToolStepKey,
|
|
47
|
-
> = Partial<Record<RoleName,
|
|
47
|
+
> = Partial<Record<RoleName, MutableStrategyStateEntry<TKey>>>;
|
|
48
48
|
|
|
49
49
|
export type MutableStrategyState<
|
|
50
50
|
TKey extends string = MutableToolStepKey,
|
|
51
|
-
> = Partial<Record<TKey,
|
|
51
|
+
> = Partial<Record<TKey, MutableStrategyStateEntryByRoleName<TKey>>>;
|
|
52
52
|
|
|
53
53
|
export type MutableToolStep<TKey extends string = MutableToolStepKey> = ToolStep & {
|
|
54
54
|
toolStepKey: TKey;
|
|
@@ -116,27 +116,27 @@ export function setAuthoringSteps< // ATTENTION
|
|
|
116
116
|
};
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
export function
|
|
119
|
+
export function getStrategyStateEntryByRoleName<TKey extends string, TStrategyState extends MutableStrategyState<TKey>>(
|
|
120
120
|
strategyState: TStrategyState,
|
|
121
121
|
toolStepKey: TKey,
|
|
122
|
-
):
|
|
122
|
+
): MutableStrategyStateEntryByRoleName<TKey> | undefined {
|
|
123
123
|
return strategyState[toolStepKey];
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
export function
|
|
126
|
+
export function getStrategyStateEntry<TKey extends string, TStrategyState extends MutableStrategyState<TKey>>(
|
|
127
127
|
strategyState: TStrategyState,
|
|
128
128
|
toolStepRoleAddress: MutableToolStepRoleAddress<TKey>,
|
|
129
|
-
):
|
|
130
|
-
const inputEntryByRoleName =
|
|
129
|
+
): MutableStrategyStateEntry<TKey> | undefined {
|
|
130
|
+
const inputEntryByRoleName = getStrategyStateEntryByRoleName(strategyState, toolStepRoleAddress.toolStepKey);
|
|
131
131
|
return inputEntryByRoleName?.[toolStepRoleAddress.roleName];
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
export function
|
|
134
|
+
export function setStrategyStateEntry<TKey extends string, TStrategyState extends MutableStrategyState<TKey>>(
|
|
135
135
|
strategyState: TStrategyState,
|
|
136
136
|
toolStepRoleAddress: MutableToolStepRoleAddress<TKey>,
|
|
137
|
-
entry:
|
|
137
|
+
entry: MutableStrategyStateEntry<TKey>,
|
|
138
138
|
): TStrategyState {
|
|
139
|
-
const inputEntryByRoleName =
|
|
139
|
+
const inputEntryByRoleName = getStrategyStateEntryByRoleName(strategyState, toolStepRoleAddress.toolStepKey) ?? {};
|
|
140
140
|
|
|
141
141
|
return {
|
|
142
142
|
...strategyState,
|
|
@@ -155,7 +155,7 @@ export function clearInputBinding<
|
|
|
155
155
|
toolStepRoleAddress: MutableToolStepRoleAddress<TKey>,
|
|
156
156
|
): TStrategyState {
|
|
157
157
|
const inputEntryByRoleName =
|
|
158
|
-
|
|
158
|
+
getStrategyStateEntryByRoleName(
|
|
159
159
|
strategyState,
|
|
160
160
|
toolStepRoleAddress.toolStepKey,
|
|
161
161
|
);
|
|
@@ -179,17 +179,17 @@ export function clearInputBinding<
|
|
|
179
179
|
};
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
-
export function
|
|
182
|
+
export function bindMaterializedResource<TKey extends string, TStrategyState extends MutableStrategyState<TKey>>(
|
|
183
183
|
strategyState: TStrategyState,
|
|
184
184
|
target: MutableToolStepRoleAddress<TKey>,
|
|
185
185
|
resource: Resource,
|
|
186
186
|
): TStrategyState {
|
|
187
|
-
const
|
|
187
|
+
const mutableMaterializedResource: MutableMaterializedResource = {
|
|
188
188
|
...resource,
|
|
189
|
-
|
|
189
|
+
strategyStateEntryKind: 'materializedResource',
|
|
190
190
|
};
|
|
191
191
|
|
|
192
|
-
return
|
|
192
|
+
return setStrategyStateEntry(strategyState, target, mutableMaterializedResource);
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
function getInputRoleValue(tool: Tool, roleName: RoleName) {
|
|
@@ -265,8 +265,8 @@ export function bindInternalInputPotential<TKey extends string, TStrategyState e
|
|
|
265
265
|
);
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
-
return
|
|
269
|
-
|
|
268
|
+
return setStrategyStateEntry(strategyState, targetAddress, {
|
|
269
|
+
strategyStateEntryKind: 'internalInputPotential',
|
|
270
270
|
toolStepRoleAddress: {
|
|
271
271
|
toolStepKey: sourceAddress.toolStepKey,
|
|
272
272
|
roleName: sourceAddress.roleName,
|
|
@@ -279,8 +279,8 @@ export function bindExternalInputPotential<TKey extends string, TStrategyState e
|
|
|
279
279
|
target: MutableToolStepRoleAddress<TKey>,
|
|
280
280
|
): TStrategyState {
|
|
281
281
|
const mutableExternalInputPotential: MutableExternalInputPotential = {
|
|
282
|
-
|
|
282
|
+
strategyStateEntryKind: 'externalInputPotential',
|
|
283
283
|
};
|
|
284
284
|
|
|
285
|
-
return
|
|
285
|
+
return setStrategyStateEntry(strategyState, target, mutableExternalInputPotential);
|
|
286
286
|
}
|
|
@@ -93,7 +93,7 @@ export function getIndependentThreads<
|
|
|
93
93
|
|
|
94
94
|
for (const inputRoleId of inputBindings) {
|
|
95
95
|
const entry = bucket?.[inputRoleId];
|
|
96
|
-
if (!entry || entry.
|
|
96
|
+
if (!entry || entry.strategyStateEntryKind !== 'internalInputPotential') continue;
|
|
97
97
|
|
|
98
98
|
const producerToolStepKey = entry.toolStepRoleAddress?.toolStepKey;
|
|
99
99
|
if (typeof producerToolStepKey !== 'string') {
|
|
@@ -3,12 +3,12 @@ import type {
|
|
|
3
3
|
Case,
|
|
4
4
|
ExternalInputPotential,
|
|
5
5
|
ForStep,
|
|
6
|
-
|
|
6
|
+
MaterializedResource,
|
|
7
7
|
InternalInputPotential,
|
|
8
8
|
RoleName,
|
|
9
9
|
Step,
|
|
10
10
|
Strategy,
|
|
11
|
-
|
|
11
|
+
StrategyStateEntry,
|
|
12
12
|
ToolStep,
|
|
13
13
|
ToolStepPath,
|
|
14
14
|
WhileStep,
|
|
@@ -21,7 +21,8 @@ import type {
|
|
|
21
21
|
MutableInternalInputPotential,
|
|
22
22
|
MutableStrategy,
|
|
23
23
|
MutableStep,
|
|
24
|
-
|
|
24
|
+
MutableStrategyStateEntryByRoleName,
|
|
25
|
+
MutableStrategyStateEntry,
|
|
25
26
|
MutableToolStepKey,
|
|
26
27
|
MutableWhileStep,
|
|
27
28
|
} from './mutableStrategyOverlay.js';
|
|
@@ -73,11 +74,11 @@ function buildExecutionPathMap(strategy: MutableStrategy): Map<MutableToolStepKe
|
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
function toCanonicalStrategyStateEntry(
|
|
76
|
-
entry:
|
|
77
|
+
entry: MutableStrategyStateEntry,
|
|
77
78
|
executionPathByKey: ReadonlyMap<MutableToolStepKey, ToolStepPath>,
|
|
78
|
-
):
|
|
79
|
-
if (entry.
|
|
80
|
-
return entry as
|
|
79
|
+
): StrategyStateEntry {
|
|
80
|
+
if (entry.strategyStateEntryKind !== 'internalInputPotential') {
|
|
81
|
+
return entry as MaterializedResource | ExternalInputPotential;
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
const sourceToolStepPath = executionPathByKey.get(entry.toolStepRoleAddress.toolStepKey);
|
|
@@ -86,7 +87,7 @@ function toCanonicalStrategyStateEntry(
|
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
return {
|
|
89
|
-
|
|
90
|
+
strategyStateEntryKind: 'internalInputPotential',
|
|
90
91
|
toolStepRoleAddress: {
|
|
91
92
|
toolStepPath: sourceToolStepPath,
|
|
92
93
|
roleName: entry.toolStepRoleAddress.roleName,
|
|
@@ -121,11 +122,11 @@ function toCanonicalStep(step: MutableStep): Step {
|
|
|
121
122
|
}
|
|
122
123
|
|
|
123
124
|
function toMutableStrategyStateEntry(
|
|
124
|
-
entry:
|
|
125
|
+
entry: StrategyStateEntry,
|
|
125
126
|
executionKeyByPath: ReadonlyMap<ToolStepPath, MutableToolStepKey>,
|
|
126
|
-
):
|
|
127
|
-
if (entry.
|
|
128
|
-
return entry as
|
|
127
|
+
): MutableStrategyStateEntry {
|
|
128
|
+
if (entry.strategyStateEntryKind !== 'internalInputPotential') {
|
|
129
|
+
return entry as MaterializedResource | ExternalInputPotential;
|
|
129
130
|
}
|
|
130
131
|
|
|
131
132
|
const sourceToolStepKey = executionKeyByPath.get(entry.toolStepRoleAddress.toolStepPath);
|
|
@@ -134,7 +135,7 @@ function toMutableStrategyStateEntry(
|
|
|
134
135
|
}
|
|
135
136
|
|
|
136
137
|
return {
|
|
137
|
-
|
|
138
|
+
strategyStateEntryKind: 'internalInputPotential',
|
|
138
139
|
toolStepRoleAddress: {
|
|
139
140
|
toolStepKey: sourceToolStepKey,
|
|
140
141
|
roleName: entry.toolStepRoleAddress.roleName,
|
|
@@ -291,4 +292,50 @@ export function mutableStrategyToStrategy(mutableStrategy: MutableStrategy): Str
|
|
|
291
292
|
stepsByThreadIndex: mutableStrategy.stepsByThreadIndex.map((steps) => steps.map(toCanonicalStep)),
|
|
292
293
|
strategyState,
|
|
293
294
|
};
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export function mutableToolStepKeyToToolStepPath(
|
|
298
|
+
mutableStrategy: MutableStrategy,
|
|
299
|
+
toolStepKey: MutableToolStepKey,
|
|
300
|
+
): ToolStepPath {
|
|
301
|
+
const executionPathByKey = buildExecutionPathMap(mutableStrategy);
|
|
302
|
+
const toolStepPath = executionPathByKey.get(toolStepKey);
|
|
303
|
+
if (!toolStepPath) {
|
|
304
|
+
throw new Error(`Cannot project toolStepPath: no execution path found for toolStepKey '${toolStepKey}'.`);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
return toolStepPath;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export function projectMutableRoleEntriesByToolStepKeyToCanonicalDelta(
|
|
311
|
+
mutableStrategy: MutableStrategy,
|
|
312
|
+
toolStepKey: MutableToolStepKey,
|
|
313
|
+
roleEntries: MutableStrategyStateEntryByRoleName,
|
|
314
|
+
): Strategy['strategyState'] {
|
|
315
|
+
const executionPathByKey = buildExecutionPathMap(mutableStrategy);
|
|
316
|
+
const toolStepPath = executionPathByKey.get(toolStepKey);
|
|
317
|
+
if (!toolStepPath) {
|
|
318
|
+
throw new Error(`Cannot project strategy state delta: no execution path found for toolStepKey '${toolStepKey}'.`);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const canonicalRoleEntries: Strategy['strategyState'][ToolStepPath] = Object.fromEntries(
|
|
322
|
+
Object.entries(roleEntries)
|
|
323
|
+
.filter(([, entry]) => entry !== undefined)
|
|
324
|
+
.map(([roleName, entry]) => {
|
|
325
|
+
if (entry === undefined) {
|
|
326
|
+
throw new Error(
|
|
327
|
+
`Cannot project strategy state delta: role '${roleName}' on toolStepKey '${toolStepKey}' is explicitly undefined.`
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
return [
|
|
332
|
+
roleName as RoleName,
|
|
333
|
+
toCanonicalStrategyStateEntry(entry, executionPathByKey),
|
|
334
|
+
] as const;
|
|
335
|
+
})
|
|
336
|
+
);
|
|
337
|
+
|
|
338
|
+
return {
|
|
339
|
+
[toolStepPath]: canonicalRoleEntries,
|
|
340
|
+
};
|
|
294
341
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
2
|
+
MutableMaterializedResource,
|
|
3
3
|
MutableExternalInputPotential,
|
|
4
4
|
MutableInternalInputPotential,
|
|
5
5
|
MutableStrategyState,
|
|
6
|
-
|
|
6
|
+
MutableStrategyStateEntry,
|
|
7
7
|
MutableToolStepKey,
|
|
8
8
|
MutableToolStepRoleAddress,
|
|
9
9
|
} from './mutableStrategyOverlay.js';
|
|
10
|
-
import {
|
|
10
|
+
import { getStrategyStateEntry } from './mutableStrategyOverlay.js';
|
|
11
11
|
|
|
12
12
|
export type ResolveResult<TKey extends string = MutableToolStepKey> =
|
|
13
|
-
| { status: '
|
|
13
|
+
| { status: 'materializedResource'; entry: MutableMaterializedResource; path: MutableToolStepRoleAddress<TKey>[] }
|
|
14
14
|
| { status: 'externalInputPotential'; entry: MutableExternalInputPotential; path: MutableToolStepRoleAddress<TKey>[] }
|
|
15
15
|
| {
|
|
16
16
|
status: 'unresolved';
|
|
@@ -37,16 +37,16 @@ export function resolveStrategyStateChain<TKey extends string, TStrategyState ex
|
|
|
37
37
|
}
|
|
38
38
|
visited.add(visitKey);
|
|
39
39
|
|
|
40
|
-
const entry =
|
|
40
|
+
const entry = getStrategyStateEntry(strategyState, current) as MutableStrategyStateEntry<TKey> | undefined;
|
|
41
41
|
if (!entry) {
|
|
42
42
|
return { status: 'unresolved', reason: 'not-found', path };
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
if (entry.
|
|
46
|
-
return { status: '
|
|
45
|
+
if (entry.strategyStateEntryKind === 'materializedResource') {
|
|
46
|
+
return { status: 'materializedResource', entry, path };
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
if (entry.
|
|
49
|
+
if (entry.strategyStateEntryKind === 'externalInputPotential') {
|
|
50
50
|
return { status: 'externalInputPotential', entry, path };
|
|
51
51
|
}
|
|
52
52
|
|