@toolproof-core/lib 1.0.48 → 1.0.50
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/utils/mutableStrategyOverlay.d.ts +2 -8
- package/dist/utils/mutableStrategyOverlay.js +17 -18
- package/dist/utils/stepCreation.js +4 -10
- package/dist/utils/stepParallelization.js +13 -13
- package/dist/utils/strategyCanonicalization.d.ts +2 -2
- package/dist/utils/strategyCanonicalization.js +28 -33
- package/dist/utils/strategyStateResolution.js +1 -1
- package/package.json +1 -1
- package/src/utils/mutableStrategyOverlay.ts +18 -25
- package/src/utils/stepCreation.ts +4 -10
- package/src/utils/stepParallelization.ts +13 -13
- package/src/utils/strategyCanonicalization.ts +30 -35
- package/src/utils/strategyStateResolution.ts +1 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -21,15 +21,13 @@ export type MutableBranchStepKey = `BRANCH_STEP-${string}`;
|
|
|
21
21
|
export type MutableWhileStepKey = `WHILE_STEP-${string}`;
|
|
22
22
|
export type MutableForStepKey = `FOR_STEP-${string}`;
|
|
23
23
|
export type MutableLoopStepKey = MutableWhileStepKey | MutableForStepKey;
|
|
24
|
-
export type
|
|
25
|
-
export type MutableStepKey = MutableToolStepKey | MutableMacroStepKey;
|
|
24
|
+
export type MutableStepKey = MutableToolStepKey | MutableBranchStepKey | MutableLoopStepKey;
|
|
26
25
|
|
|
27
26
|
export type MutableMaterializedResource = MaterializedResource;
|
|
28
27
|
|
|
29
28
|
export type MutableToolStepRoleAddress =
|
|
30
29
|
Omit<ToolStepRoleAddress, 'toolStepPath'> & {
|
|
31
30
|
stepKey: MutableToolStepKey;
|
|
32
|
-
toolStepKey: MutableToolStepKey;
|
|
33
31
|
};
|
|
34
32
|
|
|
35
33
|
export type MutableInternalInputPotential =
|
|
@@ -50,7 +48,6 @@ export type MutableStrategyState = Partial<Record<MutableToolStepKey, MutableStr
|
|
|
50
48
|
|
|
51
49
|
export type MutableToolStep = ToolStep & {
|
|
52
50
|
stepKey: MutableToolStepKey;
|
|
53
|
-
toolStepKey: MutableToolStepKey;
|
|
54
51
|
};
|
|
55
52
|
|
|
56
53
|
export type MutableCase = Omit<Case, 'when' | 'what'> & {
|
|
@@ -60,19 +57,16 @@ export type MutableCase = Omit<Case, 'when' | 'what'> & {
|
|
|
60
57
|
|
|
61
58
|
export type MutableBranchStep = Omit<BranchStep, 'cases'> & {
|
|
62
59
|
stepKey: MutableBranchStepKey;
|
|
63
|
-
macroStepKey: MutableBranchStepKey;
|
|
64
60
|
cases: [MutableCase, ...MutableCase[]];
|
|
65
61
|
};
|
|
66
62
|
|
|
67
63
|
export type MutableWhileStep = Omit<WhileStep, 'case'> & {
|
|
68
64
|
stepKey: MutableWhileStepKey;
|
|
69
|
-
macroStepKey: MutableWhileStepKey;
|
|
70
65
|
case: MutableCase;
|
|
71
66
|
};
|
|
72
67
|
|
|
73
68
|
export type MutableForStep = Omit<ForStep, 'case'> & {
|
|
74
69
|
stepKey: MutableForStepKey;
|
|
75
|
-
macroStepKey: MutableForStepKey;
|
|
76
70
|
case: MutableCase;
|
|
77
71
|
};
|
|
78
72
|
|
|
@@ -108,16 +102,16 @@ export function setAuthoringSteps(
|
|
|
108
102
|
|
|
109
103
|
export function getStrategyStateEntryByRoleName(
|
|
110
104
|
strategyState: MutableStrategyState,
|
|
111
|
-
|
|
105
|
+
stepKey: MutableToolStepKey,
|
|
112
106
|
): MutableStrategyStateEntryByRoleName | undefined {
|
|
113
|
-
return strategyState[
|
|
107
|
+
return strategyState[stepKey];
|
|
114
108
|
}
|
|
115
109
|
|
|
116
110
|
export function getStrategyStateEntry(
|
|
117
111
|
strategyState: MutableStrategyState,
|
|
118
112
|
toolStepRoleAddress: MutableToolStepRoleAddress,
|
|
119
113
|
): MutableStrategyStateEntry | undefined {
|
|
120
|
-
const inputEntryByRoleName = getStrategyStateEntryByRoleName(strategyState, toolStepRoleAddress.
|
|
114
|
+
const inputEntryByRoleName = getStrategyStateEntryByRoleName(strategyState, toolStepRoleAddress.stepKey);
|
|
121
115
|
return inputEntryByRoleName?.[toolStepRoleAddress.roleName];
|
|
122
116
|
}
|
|
123
117
|
|
|
@@ -126,11 +120,11 @@ export function setStrategyStateEntry(
|
|
|
126
120
|
toolStepRoleAddress: MutableToolStepRoleAddress,
|
|
127
121
|
entry: MutableStrategyStateEntry,
|
|
128
122
|
): MutableStrategyState {
|
|
129
|
-
const inputEntryByRoleName = getStrategyStateEntryByRoleName(strategyState, toolStepRoleAddress.
|
|
123
|
+
const inputEntryByRoleName = getStrategyStateEntryByRoleName(strategyState, toolStepRoleAddress.stepKey) ?? {};
|
|
130
124
|
|
|
131
125
|
return {
|
|
132
126
|
...strategyState,
|
|
133
|
-
[toolStepRoleAddress.
|
|
127
|
+
[toolStepRoleAddress.stepKey]: {
|
|
134
128
|
...inputEntryByRoleName,
|
|
135
129
|
[toolStepRoleAddress.roleName]: entry,
|
|
136
130
|
},
|
|
@@ -144,7 +138,7 @@ export function clearInputBinding(
|
|
|
144
138
|
const inputEntryByRoleName =
|
|
145
139
|
getStrategyStateEntryByRoleName(
|
|
146
140
|
strategyState,
|
|
147
|
-
toolStepRoleAddress.
|
|
141
|
+
toolStepRoleAddress.stepKey,
|
|
148
142
|
);
|
|
149
143
|
|
|
150
144
|
if (!inputEntryByRoleName || !(toolStepRoleAddress.roleName in inputEntryByRoleName)) {
|
|
@@ -156,13 +150,13 @@ export function clearInputBinding(
|
|
|
156
150
|
|
|
157
151
|
if (Object.keys(nextInputEntryByRoleName).length === 0) {
|
|
158
152
|
const nextStrategyState = { ...strategyState };
|
|
159
|
-
delete nextStrategyState[toolStepRoleAddress.
|
|
153
|
+
delete nextStrategyState[toolStepRoleAddress.stepKey];
|
|
160
154
|
return nextStrategyState;
|
|
161
155
|
}
|
|
162
156
|
|
|
163
157
|
return {
|
|
164
158
|
...strategyState,
|
|
165
|
-
[toolStepRoleAddress.
|
|
159
|
+
[toolStepRoleAddress.stepKey]: nextInputEntryByRoleName,
|
|
166
160
|
};
|
|
167
161
|
}
|
|
168
162
|
|
|
@@ -197,14 +191,14 @@ export function bindInternalInputPotential(
|
|
|
197
191
|
}
|
|
198
192
|
): MutableStrategyState {
|
|
199
193
|
|
|
200
|
-
const sourceToolStep = context.toolStepByKey.get(sourceAddress.
|
|
194
|
+
const sourceToolStep = context.toolStepByKey.get(sourceAddress.stepKey);
|
|
201
195
|
if (!sourceToolStep) {
|
|
202
|
-
throw new Error(`Source tool step not found for '${sourceAddress.
|
|
196
|
+
throw new Error(`Source tool step not found for '${sourceAddress.stepKey}'.`);
|
|
203
197
|
}
|
|
204
198
|
|
|
205
|
-
const targetToolStep = context.toolStepByKey.get(targetAddress.
|
|
199
|
+
const targetToolStep = context.toolStepByKey.get(targetAddress.stepKey);
|
|
206
200
|
if (!targetToolStep) {
|
|
207
|
-
throw new Error(`Target tool step not found for '${targetAddress.
|
|
201
|
+
throw new Error(`Target tool step not found for '${targetAddress.stepKey}'.`);
|
|
208
202
|
}
|
|
209
203
|
|
|
210
204
|
const sourceTool = context.toolMap.get(sourceToolStep.toolHandle);
|
|
@@ -219,13 +213,13 @@ export function bindInternalInputPotential(
|
|
|
219
213
|
|
|
220
214
|
const targetInputRoleValue = getInputRoleValue(targetTool, targetAddress.roleName);
|
|
221
215
|
if (!targetInputRoleValue) {
|
|
222
|
-
throw new Error(`Target input role not found for (${targetAddress.
|
|
216
|
+
throw new Error(`Target input role not found for (${targetAddress.stepKey}, ${targetAddress.roleName}).`);
|
|
223
217
|
}
|
|
224
218
|
|
|
225
219
|
const sourceOutputRoleValue = getOutputRoleValue(sourceTool, sourceAddress.roleName);
|
|
226
220
|
const sourceInputRoleValue = getInputRoleValue(sourceTool, sourceAddress.roleName);
|
|
227
221
|
|
|
228
|
-
const sourceInputEntryByRoleName = strategyState[sourceAddress.
|
|
222
|
+
const sourceInputEntryByRoleName = strategyState[sourceAddress.stepKey];
|
|
229
223
|
const sourceInputEntry = sourceInputEntryByRoleName?.[sourceAddress.roleName];
|
|
230
224
|
|
|
231
225
|
const sourceRoleType = sourceOutputRoleValue
|
|
@@ -238,17 +232,17 @@ export function bindInternalInputPotential(
|
|
|
238
232
|
|
|
239
233
|
if (!sourceOutputRoleValue && sourceInputRoleValue) {
|
|
240
234
|
if (!sourceInputEntry) {
|
|
241
|
-
throw new Error(`Source input role is not bound for (${sourceAddress.
|
|
235
|
+
throw new Error(`Source input role is not bound for (${sourceAddress.stepKey}, ${sourceAddress.roleName}).`); // ATTENTION: not an ontological invariant, but it might help catch some mistakes early on.
|
|
242
236
|
}
|
|
243
237
|
}
|
|
244
238
|
|
|
245
239
|
if (!sourceOutputRoleValue && !sourceInputRoleValue) {
|
|
246
|
-
throw new Error(`Source role not found for (${sourceAddress.
|
|
240
|
+
throw new Error(`Source role not found for (${sourceAddress.stepKey}, ${sourceAddress.roleName}).`);
|
|
247
241
|
}
|
|
248
242
|
|
|
249
243
|
if (!sourceRoleType || !targetRoleType || sourceRoleType !== targetRoleType) {
|
|
250
244
|
throw new Error(
|
|
251
|
-
`Reference type mismatch between source (${sourceAddress.
|
|
245
|
+
`Reference type mismatch between source (${sourceAddress.stepKey}, ${sourceAddress.roleName}) and target (${targetAddress.stepKey}, ${targetAddress.roleName}).`
|
|
252
246
|
);
|
|
253
247
|
}
|
|
254
248
|
|
|
@@ -256,7 +250,6 @@ export function bindInternalInputPotential(
|
|
|
256
250
|
strategyStateEntryKind: 'internalInputPotential',
|
|
257
251
|
toolStepRoleAddress: {
|
|
258
252
|
stepKey: sourceAddress.stepKey,
|
|
259
|
-
toolStepKey: sourceAddress.toolStepKey,
|
|
260
253
|
roleName: sourceAddress.roleName,
|
|
261
254
|
},
|
|
262
255
|
});
|
|
@@ -32,7 +32,6 @@ export function createToolStepFromTool(
|
|
|
32
32
|
): MutableToolStep {
|
|
33
33
|
return {
|
|
34
34
|
stepKey: generateIdentifier('ToolStepKey'),
|
|
35
|
-
toolStepKey: generateIdentifier('ToolStepKey'),
|
|
36
35
|
stepKind: CONSTANTS.Enums.StepKind.tool,
|
|
37
36
|
toolHandle: tool.handle,
|
|
38
37
|
roleBindingSpec: getRoleBindingSpec(tool),
|
|
@@ -63,7 +62,6 @@ export function createLoopStepFromCase(
|
|
|
63
62
|
if (stepKind === CONSTANTS.Enums.StepKind.for) {
|
|
64
63
|
return {
|
|
65
64
|
stepKey: generateIdentifier('ForStepKey'),
|
|
66
|
-
macroStepKey: generateIdentifier('ForStepKey'),
|
|
67
65
|
stepKind: CONSTANTS.Enums.StepKind.for,
|
|
68
66
|
case: stepCase,
|
|
69
67
|
};
|
|
@@ -71,7 +69,6 @@ export function createLoopStepFromCase(
|
|
|
71
69
|
|
|
72
70
|
return {
|
|
73
71
|
stepKey: generateIdentifier('WhileStepKey'),
|
|
74
|
-
macroStepKey: generateIdentifier('WhileStepKey'),
|
|
75
72
|
stepKind: CONSTANTS.Enums.StepKind.while,
|
|
76
73
|
case: stepCase,
|
|
77
74
|
};
|
|
@@ -84,7 +81,6 @@ export function createBranchStepFromCases(
|
|
|
84
81
|
|
|
85
82
|
return {
|
|
86
83
|
stepKey: generateIdentifier('BranchStepKey'),
|
|
87
|
-
macroStepKey: generateIdentifier('BranchStepKey'),
|
|
88
84
|
stepKind: CONSTANTS.Enums.StepKind.branch,
|
|
89
85
|
cases,
|
|
90
86
|
};
|
|
@@ -95,16 +91,15 @@ export function cloneForStep(
|
|
|
95
91
|
): MutableForStep {
|
|
96
92
|
return {
|
|
97
93
|
stepKey: generateIdentifier('ForStepKey'),
|
|
98
|
-
macroStepKey: generateIdentifier('ForStepKey'),
|
|
99
94
|
stepKind: CONSTANTS.Enums.StepKind.for,
|
|
100
95
|
case: {
|
|
101
96
|
what: {
|
|
102
97
|
...forStep.case.what,
|
|
103
|
-
|
|
98
|
+
stepKey: generateIdentifier('ToolStepKey'),
|
|
104
99
|
},
|
|
105
100
|
when: {
|
|
106
101
|
...forStep.case.when,
|
|
107
|
-
|
|
102
|
+
stepKey: generateIdentifier('ToolStepKey'),
|
|
108
103
|
},
|
|
109
104
|
},
|
|
110
105
|
};
|
|
@@ -115,16 +110,15 @@ export function cloneWhileStep(
|
|
|
115
110
|
): MutableWhileStep {
|
|
116
111
|
return {
|
|
117
112
|
stepKey: generateIdentifier('WhileStepKey'),
|
|
118
|
-
macroStepKey: generateIdentifier('WhileStepKey'),
|
|
119
113
|
stepKind: CONSTANTS.Enums.StepKind.while,
|
|
120
114
|
case: {
|
|
121
115
|
what: {
|
|
122
116
|
...whileStep.case.what,
|
|
123
|
-
|
|
117
|
+
stepKey: generateIdentifier('ToolStepKey'),
|
|
124
118
|
},
|
|
125
119
|
when: {
|
|
126
120
|
...whileStep.case.when,
|
|
127
|
-
|
|
121
|
+
stepKey: generateIdentifier('ToolStepKey'),
|
|
128
122
|
},
|
|
129
123
|
},
|
|
130
124
|
};
|
|
@@ -17,7 +17,7 @@ export function getIndependentThreads(
|
|
|
17
17
|
return `steps[${ownerIndex}] stepKind=${step?.stepKind ?? 'unknown'}`;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
const
|
|
20
|
+
const stepKeyToOwner = new Map<MutableToolStepKey, OwnerIndex>();
|
|
21
21
|
const toolStepByKey = new Map<MutableToolStepKey, MutableToolStep>();
|
|
22
22
|
|
|
23
23
|
const addToolStep = (
|
|
@@ -26,15 +26,15 @@ export function getIndependentThreads(
|
|
|
26
26
|
) => {
|
|
27
27
|
if (!toolStep) return;
|
|
28
28
|
|
|
29
|
-
const existingOwner =
|
|
29
|
+
const existingOwner = stepKeyToOwner.get(toolStep.stepKey);
|
|
30
30
|
if (existingOwner !== undefined) {
|
|
31
31
|
throw new Error(
|
|
32
|
-
`Duplicate
|
|
32
|
+
`Duplicate stepKey '${toolStep.stepKey}' found in ${getOwnerLabel(ownerIndex)} and ${getOwnerLabel(existingOwner)}`
|
|
33
33
|
);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
toolStepByKey.set(toolStep.
|
|
36
|
+
stepKeyToOwner.set(toolStep.stepKey, ownerIndex);
|
|
37
|
+
toolStepByKey.set(toolStep.stepKey, toolStep);
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
steps.forEach((step, ownerIndex) => {
|
|
@@ -55,28 +55,28 @@ export function getIndependentThreads(
|
|
|
55
55
|
ensureOwner(index);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
for (const [
|
|
58
|
+
for (const [stepKey, ownerIndex] of stepKeyToOwner) {
|
|
59
59
|
ensureOwner(ownerIndex);
|
|
60
60
|
|
|
61
|
-
const toolStep = toolStepByKey.get(
|
|
61
|
+
const toolStep = toolStepByKey.get(stepKey);
|
|
62
62
|
const inputBindings = toolStep?.roleBindingSpec?.inputBindings ?? [];
|
|
63
|
-
const bucket = strategyState[
|
|
63
|
+
const bucket = strategyState[stepKey];
|
|
64
64
|
|
|
65
65
|
for (const inputRoleId of inputBindings) {
|
|
66
66
|
const entry = bucket?.[inputRoleId];
|
|
67
67
|
if (!entry || entry.strategyStateEntryKind !== 'internalInputPotential') continue;
|
|
68
68
|
|
|
69
|
-
const
|
|
70
|
-
if (typeof
|
|
69
|
+
const producerStepKey = entry.toolStepRoleAddress?.stepKey;
|
|
70
|
+
if (typeof producerStepKey !== 'string') {
|
|
71
71
|
throw new Error(
|
|
72
|
-
`Unresolvable internalInputPotential in toolStep '${
|
|
72
|
+
`Unresolvable internalInputPotential in toolStep '${stepKey}' (${getOwnerLabel(ownerIndex)}): missing toolStepRoleAddress.stepKey for role '${inputRoleId}'`
|
|
73
73
|
);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
const producerOwner =
|
|
76
|
+
const producerOwner = stepKeyToOwner.get(producerStepKey);
|
|
77
77
|
if (producerOwner === undefined) {
|
|
78
78
|
throw new Error(
|
|
79
|
-
`Unresolvable internalInputPotential in toolStep '${
|
|
79
|
+
`Unresolvable internalInputPotential in toolStep '${stepKey}' (${getOwnerLabel(ownerIndex)}): source stepKey '${producerStepKey}' not found in strategy steps`
|
|
80
80
|
);
|
|
81
81
|
}
|
|
82
82
|
|
|
@@ -31,8 +31,8 @@ import { generateIdentifier } from './identifierGeneration.js';
|
|
|
31
31
|
|
|
32
32
|
function stripMutableCase(stepCase: MutableCase): Case {
|
|
33
33
|
const { when, what, ...rest } = stepCase;
|
|
34
|
-
const { stepKey: _whenStepKey,
|
|
35
|
-
const { stepKey: _whatStepKey,
|
|
34
|
+
const { stepKey: _whenStepKey, ...canonicalWhen } = when;
|
|
35
|
+
const { stepKey: _whatStepKey, ...canonicalWhat } = what;
|
|
36
36
|
|
|
37
37
|
return {
|
|
38
38
|
...rest,
|
|
@@ -47,18 +47,18 @@ function buildExecutionPathMap(strategy: MutableStrategy): Map<MutableToolStepKe
|
|
|
47
47
|
const registerStep = (step: MutableStep, pathPrefix: string) => {
|
|
48
48
|
switch (step.stepKind) {
|
|
49
49
|
case CONSTANTS.Enums.StepKind.tool:
|
|
50
|
-
executionPathByKey.set(step.
|
|
50
|
+
executionPathByKey.set(step.stepKey, `${pathPrefix}/self` as ToolStepPath);
|
|
51
51
|
return;
|
|
52
52
|
case CONSTANTS.Enums.StepKind.branch:
|
|
53
53
|
step.cases.forEach((stepCase, caseIndex) => {
|
|
54
|
-
executionPathByKey.set(stepCase.when.
|
|
55
|
-
executionPathByKey.set(stepCase.what.
|
|
54
|
+
executionPathByKey.set(stepCase.when.stepKey, `${pathPrefix}/cases/${caseIndex}/when` as ToolStepPath);
|
|
55
|
+
executionPathByKey.set(stepCase.what.stepKey, `${pathPrefix}/cases/${caseIndex}/what` as ToolStepPath);
|
|
56
56
|
});
|
|
57
57
|
return;
|
|
58
58
|
case CONSTANTS.Enums.StepKind.while:
|
|
59
59
|
case CONSTANTS.Enums.StepKind.for:
|
|
60
|
-
executionPathByKey.set(step.case.when.
|
|
61
|
-
executionPathByKey.set(step.case.what.
|
|
60
|
+
executionPathByKey.set(step.case.when.stepKey, `${pathPrefix}/case/when` as ToolStepPath);
|
|
61
|
+
executionPathByKey.set(step.case.what.stepKey, `${pathPrefix}/case/what` as ToolStepPath);
|
|
62
62
|
return;
|
|
63
63
|
default:
|
|
64
64
|
throw new Error('Unsupported step kind while projecting strategy.');
|
|
@@ -82,9 +82,9 @@ function toCanonicalStrategyStateEntry(
|
|
|
82
82
|
return entry as MaterializedResource | ExternalInputPotential;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
const sourceToolStepPath = executionPathByKey.get(entry.toolStepRoleAddress.
|
|
85
|
+
const sourceToolStepPath = executionPathByKey.get(entry.toolStepRoleAddress.stepKey);
|
|
86
86
|
if (!sourceToolStepPath) {
|
|
87
|
-
throw new Error(`Cannot project strategy state: no execution path found for
|
|
87
|
+
throw new Error(`Cannot project strategy state: no execution path found for stepKey '${entry.toolStepRoleAddress.stepKey}'.`);
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
return {
|
|
@@ -99,11 +99,11 @@ function toCanonicalStrategyStateEntry(
|
|
|
99
99
|
function toCanonicalStep(step: MutableStep): Step {
|
|
100
100
|
switch (step.stepKind) {
|
|
101
101
|
case CONSTANTS.Enums.StepKind.tool: {
|
|
102
|
-
const { stepKey: _stepKey,
|
|
102
|
+
const { stepKey: _stepKey, ...canonicalToolStep } = step;
|
|
103
103
|
return canonicalToolStep;
|
|
104
104
|
}
|
|
105
105
|
case CONSTANTS.Enums.StepKind.branch: {
|
|
106
|
-
const { stepKey: _stepKey,
|
|
106
|
+
const { stepKey: _stepKey, cases, ...rest } = step;
|
|
107
107
|
return {
|
|
108
108
|
...rest,
|
|
109
109
|
cases: cases.map(stripMutableCase) as [Case, ...Case[]],
|
|
@@ -111,7 +111,7 @@ function toCanonicalStep(step: MutableStep): Step {
|
|
|
111
111
|
}
|
|
112
112
|
case CONSTANTS.Enums.StepKind.while:
|
|
113
113
|
case CONSTANTS.Enums.StepKind.for: {
|
|
114
|
-
const { stepKey: _stepKey,
|
|
114
|
+
const { stepKey: _stepKey, case: stepCase, ...rest } = step;
|
|
115
115
|
return {
|
|
116
116
|
...rest,
|
|
117
117
|
case: stripMutableCase(stepCase),
|
|
@@ -139,7 +139,6 @@ function toMutableStrategyStateEntry(
|
|
|
139
139
|
strategyStateEntryKind: 'internalInputPotential',
|
|
140
140
|
toolStepRoleAddress: {
|
|
141
141
|
stepKey: sourceToolStepKey,
|
|
142
|
-
toolStepKey: sourceToolStepKey,
|
|
143
142
|
roleName: entry.toolStepRoleAddress.roleName,
|
|
144
143
|
},
|
|
145
144
|
} satisfies MutableInternalInputPotential;
|
|
@@ -150,7 +149,6 @@ function toMutableToolStep(step: ToolStep): MutableToolStep {
|
|
|
150
149
|
return {
|
|
151
150
|
...step,
|
|
152
151
|
stepKey: key,
|
|
153
|
-
toolStepKey: key,
|
|
154
152
|
};
|
|
155
153
|
}
|
|
156
154
|
|
|
@@ -171,7 +169,6 @@ function toMutableBranchStep(step: BranchStep): MutableBranchStep {
|
|
|
171
169
|
return {
|
|
172
170
|
...rest,
|
|
173
171
|
stepKey: key,
|
|
174
|
-
macroStepKey: key,
|
|
175
172
|
cases: cases.map(toMutableCase) as [MutableCase, ...MutableCase[]],
|
|
176
173
|
};
|
|
177
174
|
}
|
|
@@ -183,7 +180,6 @@ function toMutableWhileStep(step: WhileStep): MutableWhileStep {
|
|
|
183
180
|
return {
|
|
184
181
|
...rest,
|
|
185
182
|
stepKey: key,
|
|
186
|
-
macroStepKey: key,
|
|
187
183
|
case: toMutableCase(stepCase),
|
|
188
184
|
};
|
|
189
185
|
}
|
|
@@ -195,7 +191,6 @@ function toMutableForStep(step: ForStep): MutableForStep {
|
|
|
195
191
|
return {
|
|
196
192
|
...rest,
|
|
197
193
|
stepKey: key,
|
|
198
|
-
macroStepKey: key,
|
|
199
194
|
case: toMutableCase(stepCase),
|
|
200
195
|
};
|
|
201
196
|
}
|
|
@@ -219,8 +214,8 @@ function buildExecutionKeyMap(strategy: MutableStrategy): Map<ToolStepPath, Muta
|
|
|
219
214
|
const executionPathByKey = buildExecutionPathMap(strategy);
|
|
220
215
|
const executionKeyByPath = new Map<ToolStepPath, MutableToolStepKey>();
|
|
221
216
|
|
|
222
|
-
for (const [
|
|
223
|
-
executionKeyByPath.set(toolStepPath,
|
|
217
|
+
for (const [stepKey, toolStepPath] of executionPathByKey.entries()) {
|
|
218
|
+
executionKeyByPath.set(toolStepPath, stepKey);
|
|
224
219
|
}
|
|
225
220
|
|
|
226
221
|
return executionKeyByPath;
|
|
@@ -239,12 +234,12 @@ export function strategyToMutableStrategy(strategy: Strategy): MutableStrategy {
|
|
|
239
234
|
const strategyState: MutableStrategy['strategyState'] = {};
|
|
240
235
|
|
|
241
236
|
for (const [toolStepPath, inputEntryByRoleName] of Object.entries(strategy.strategyState)) {
|
|
242
|
-
const
|
|
243
|
-
if (!
|
|
237
|
+
const stepKey = executionKeyByPath.get(toolStepPath as ToolStepPath);
|
|
238
|
+
if (!stepKey) {
|
|
244
239
|
throw new Error(`Cannot deproject strategy state: no mutable key found for toolStepPath '${toolStepPath}'.`);
|
|
245
240
|
}
|
|
246
241
|
|
|
247
|
-
strategyState[
|
|
242
|
+
strategyState[stepKey] = Object.fromEntries(
|
|
248
243
|
Object.entries(inputEntryByRoleName).map(([roleName, entry]) => {
|
|
249
244
|
if (entry === undefined) {
|
|
250
245
|
throw new Error(
|
|
@@ -271,21 +266,21 @@ export function mutableStrategyToStrategy(mutableStrategy: MutableStrategy): Str
|
|
|
271
266
|
const executionPathByKey = buildExecutionPathMap(mutableStrategy);
|
|
272
267
|
const strategyState: Strategy['strategyState'] = {};
|
|
273
268
|
|
|
274
|
-
for (const [
|
|
269
|
+
for (const [stepKey, inputEntryByRoleName] of Object.entries(mutableStrategy.strategyState)) {
|
|
275
270
|
if (!inputEntryByRoleName) {
|
|
276
271
|
continue;
|
|
277
272
|
}
|
|
278
273
|
|
|
279
|
-
const toolStepPath = executionPathByKey.get(
|
|
274
|
+
const toolStepPath = executionPathByKey.get(stepKey as MutableToolStepKey);
|
|
280
275
|
if (!toolStepPath) {
|
|
281
|
-
throw new Error(`Cannot project strategy state: no execution path found for
|
|
276
|
+
throw new Error(`Cannot project strategy state: no execution path found for stepKey '${stepKey}'.`);
|
|
282
277
|
}
|
|
283
278
|
|
|
284
279
|
strategyState[toolStepPath] = Object.fromEntries(
|
|
285
280
|
Object.entries(inputEntryByRoleName).map(([roleName, entry]) => {
|
|
286
281
|
if (entry === undefined) {
|
|
287
282
|
throw new Error(
|
|
288
|
-
`Cannot project strategy state: role '${roleName}' on
|
|
283
|
+
`Cannot project strategy state: role '${roleName}' on stepKey '${stepKey}' is explicitly undefined.`
|
|
289
284
|
);
|
|
290
285
|
}
|
|
291
286
|
|
|
@@ -304,28 +299,28 @@ export function mutableStrategyToStrategy(mutableStrategy: MutableStrategy): Str
|
|
|
304
299
|
};
|
|
305
300
|
}
|
|
306
301
|
|
|
307
|
-
export function
|
|
302
|
+
export function mutableStepKeyToToolStepPath(
|
|
308
303
|
mutableStrategy: MutableStrategy,
|
|
309
|
-
|
|
304
|
+
stepKey: MutableToolStepKey,
|
|
310
305
|
): ToolStepPath {
|
|
311
306
|
const executionPathByKey = buildExecutionPathMap(mutableStrategy);
|
|
312
|
-
const toolStepPath = executionPathByKey.get(
|
|
307
|
+
const toolStepPath = executionPathByKey.get(stepKey);
|
|
313
308
|
if (!toolStepPath) {
|
|
314
|
-
throw new Error(`Cannot project toolStepPath: no execution path found for
|
|
309
|
+
throw new Error(`Cannot project toolStepPath: no execution path found for stepKey '${stepKey}'.`);
|
|
315
310
|
}
|
|
316
311
|
|
|
317
312
|
return toolStepPath;
|
|
318
313
|
}
|
|
319
314
|
|
|
320
|
-
export function
|
|
315
|
+
export function projectMutableStrategyStateEntriesByStepKeyToCanonicalDelta(
|
|
321
316
|
mutableStrategy: MutableStrategy,
|
|
322
|
-
|
|
317
|
+
stepKey: MutableToolStepKey,
|
|
323
318
|
entries: MutableStrategyStateEntryByRoleName,
|
|
324
319
|
): Strategy['strategyState'] {
|
|
325
320
|
const executionPathByKey = buildExecutionPathMap(mutableStrategy);
|
|
326
|
-
const toolStepPath = executionPathByKey.get(
|
|
321
|
+
const toolStepPath = executionPathByKey.get(stepKey);
|
|
327
322
|
if (!toolStepPath) {
|
|
328
|
-
throw new Error(`Cannot project strategy state delta: no execution path found for
|
|
323
|
+
throw new Error(`Cannot project strategy state delta: no execution path found for stepKey '${stepKey}'.`);
|
|
329
324
|
}
|
|
330
325
|
|
|
331
326
|
const canonicalEntries: Strategy['strategyState'][ToolStepPath] = Object.fromEntries(
|
|
@@ -334,7 +329,7 @@ export function projectMutableStrategyStateEntriesByToolStepKeyToCanonicalDelta(
|
|
|
334
329
|
.map(([roleName, entry]) => {
|
|
335
330
|
if (entry === undefined) {
|
|
336
331
|
throw new Error(
|
|
337
|
-
`Cannot project strategy state delta: role '${roleName}' on
|
|
332
|
+
`Cannot project strategy state delta: role '${roleName}' on stepKey '${stepKey}' is explicitly undefined.`
|
|
338
333
|
);
|
|
339
334
|
}
|
|
340
335
|
|
|
@@ -28,7 +28,7 @@ export function resolveStrategyStateChain(
|
|
|
28
28
|
for (let depth = 0; depth <= maxDepth; depth++) {
|
|
29
29
|
path.push(current);
|
|
30
30
|
|
|
31
|
-
const visitKey = `${current.
|
|
31
|
+
const visitKey = `${current.stepKey}::${current.roleName}`;
|
|
32
32
|
if (visited.has(visitKey)) {
|
|
33
33
|
return { status: 'unresolved', reason: 'cycle', path };
|
|
34
34
|
}
|