@toolproof-core/lib 1.0.49 → 1.0.51

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.
@@ -42,6 +42,8 @@ export declare const CONSTANTS: {
42
42
  readonly InternalInputPotential: "InternalInputPotential";
43
43
  readonly JsonScalarLink: "JsonScalarLink";
44
44
  readonly JsonSchemaObject: "JsonSchemaObject";
45
+ readonly MacroStepContext: "MacroStepContext";
46
+ readonly MacroStepSlot: "MacroStepSlot";
45
47
  readonly MaterializedResource: "MaterializedResource";
46
48
  readonly Name: "Name";
47
49
  readonly NameFacet: "NameFacet";
@@ -96,10 +98,6 @@ export declare const CONSTANTS: {
96
98
  readonly Tool: "Tool";
97
99
  readonly ToolHandle: "ToolHandle";
98
100
  readonly ToolStep: "ToolStep";
99
- readonly ToolStepPath: "ToolStepPath";
100
- readonly ToolStepPathSlot: "ToolStepPathSlot";
101
- readonly ToolStepPathSlotFacet: "ToolStepPathSlotFacet";
102
- readonly ToolStepPathSpec: "ToolStepPathSpec";
103
101
  readonly ToolStepRoleAddress: "ToolStepRoleAddress";
104
102
  readonly TracePoint: "TracePoint";
105
103
  readonly TracePointCounterSnapshot: "TracePointCounterSnapshot";
@@ -1,13 +1,12 @@
1
- import type { BranchStep, Case, ExternalInputPotential, ForStep, MaterializedResource, InternalInputPotential, Resource, RoleName, Strategy, Tool, ToolHandle, ToolStep, ToolStepRoleAddress, WhileStep } from '@toolproof-core/genesis';
1
+ import type { BranchStep, Case, ExternalInputPotential, ForStep, MaterializedResource, InternalInputPotential, Resource, RoleName, Strategy, Tool, ToolHandle, ToolStep, ToolStepRoleAddress, WhileStep } from '@toolproof-core/genesis/types';
2
2
  export type MutableToolStepKey = `TOOL_STEP-${string}`;
3
3
  export type MutableBranchStepKey = `BRANCH_STEP-${string}`;
4
4
  export type MutableWhileStepKey = `WHILE_STEP-${string}`;
5
5
  export type MutableForStepKey = `FOR_STEP-${string}`;
6
6
  export type MutableLoopStepKey = MutableWhileStepKey | MutableForStepKey;
7
- export type MutableMacroStepKey = MutableBranchStepKey | MutableLoopStepKey;
8
- export type MutableStepKey = MutableToolStepKey | MutableMacroStepKey;
7
+ export type MutableStepKey = MutableToolStepKey | MutableBranchStepKey | MutableLoopStepKey;
9
8
  export type MutableMaterializedResource = MaterializedResource;
10
- export type MutableToolStepRoleAddress = Omit<ToolStepRoleAddress, 'toolStepPath'> & {
9
+ export type MutableToolStepRoleAddress = Omit<ToolStepRoleAddress, 'stepPath'> & {
11
10
  stepKey: MutableToolStepKey;
12
11
  };
13
12
  export type MutableInternalInputPotential = Omit<InternalInputPotential, 'toolStepRoleAddress'> & {
@@ -26,17 +25,14 @@ export type MutableCase = Omit<Case, 'when' | 'what'> & {
26
25
  };
27
26
  export type MutableBranchStep = Omit<BranchStep, 'cases'> & {
28
27
  stepKey: MutableBranchStepKey;
29
- macroStepKey: MutableBranchStepKey;
30
28
  cases: [MutableCase, ...MutableCase[]];
31
29
  };
32
30
  export type MutableWhileStep = Omit<WhileStep, 'case'> & {
33
31
  stepKey: MutableWhileStepKey;
34
- macroStepKey: MutableWhileStepKey;
35
32
  case: MutableCase;
36
33
  };
37
34
  export type MutableForStep = Omit<ForStep, 'case'> & {
38
35
  stepKey: MutableForStepKey;
39
- macroStepKey: MutableForStepKey;
40
36
  case: MutableCase;
41
37
  };
42
38
  export type MutableStep = MutableToolStep | MutableBranchStep | MutableWhileStep | MutableForStep;
@@ -33,14 +33,12 @@ export function createLoopStepFromCase(stepCase, stepKind) {
33
33
  if (stepKind === CONSTANTS.Enums.StepKind.for) {
34
34
  return {
35
35
  stepKey: generateIdentifier('ForStepKey'),
36
- macroStepKey: generateIdentifier('ForStepKey'),
37
36
  stepKind: CONSTANTS.Enums.StepKind.for,
38
37
  case: stepCase,
39
38
  };
40
39
  }
41
40
  return {
42
41
  stepKey: generateIdentifier('WhileStepKey'),
43
- macroStepKey: generateIdentifier('WhileStepKey'),
44
42
  stepKind: CONSTANTS.Enums.StepKind.while,
45
43
  case: stepCase,
46
44
  };
@@ -49,7 +47,6 @@ export function createBranchStepFromCases(cases) {
49
47
  assertNonEmpty(cases, 'createBranchStepFromCases requires at least one case');
50
48
  return {
51
49
  stepKey: generateIdentifier('BranchStepKey'),
52
- macroStepKey: generateIdentifier('BranchStepKey'),
53
50
  stepKind: CONSTANTS.Enums.StepKind.branch,
54
51
  cases,
55
52
  };
@@ -57,7 +54,6 @@ export function createBranchStepFromCases(cases) {
57
54
  export function cloneForStep(forStep) {
58
55
  return {
59
56
  stepKey: generateIdentifier('ForStepKey'),
60
- macroStepKey: generateIdentifier('ForStepKey'),
61
57
  stepKind: CONSTANTS.Enums.StepKind.for,
62
58
  case: {
63
59
  what: {
@@ -74,7 +70,6 @@ export function cloneForStep(forStep) {
74
70
  export function cloneWhileStep(whileStep) {
75
71
  return {
76
72
  stepKey: generateIdentifier('WhileStepKey'),
77
- macroStepKey: generateIdentifier('WhileStepKey'),
78
73
  stepKind: CONSTANTS.Enums.StepKind.while,
79
74
  case: {
80
75
  what: {
@@ -1,6 +1,6 @@
1
- import type { Strategy, ToolStepPath } from '@toolproof-core/genesis';
1
+ import type { Strategy, StepPath } from '@toolproof-core/genesis/types';
2
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 mutableStepKeyToToolStepPath(mutableStrategy: MutableStrategy, stepKey: MutableToolStepKey): ToolStepPath;
5
+ export declare function mutableStepKeyToStepPath(mutableStrategy: MutableStrategy, stepKey: MutableToolStepKey): StepPath;
6
6
  export declare function projectMutableStrategyStateEntriesByStepKeyToCanonicalDelta(mutableStrategy: MutableStrategy, stepKey: MutableToolStepKey, entries: MutableStrategyStateEntryByRoleName): Strategy['strategyState'];
@@ -43,14 +43,14 @@ function toCanonicalStrategyStateEntry(entry, executionPathByKey) {
43
43
  if (entry.strategyStateEntryKind !== 'internalInputPotential') {
44
44
  return entry;
45
45
  }
46
- const sourceToolStepPath = executionPathByKey.get(entry.toolStepRoleAddress.stepKey);
47
- if (!sourceToolStepPath) {
46
+ const sourceStepPath = executionPathByKey.get(entry.toolStepRoleAddress.stepKey);
47
+ if (!sourceStepPath) {
48
48
  throw new Error(`Cannot project strategy state: no execution path found for stepKey '${entry.toolStepRoleAddress.stepKey}'.`);
49
49
  }
50
50
  return {
51
51
  strategyStateEntryKind: 'internalInputPotential',
52
52
  toolStepRoleAddress: {
53
- toolStepPath: sourceToolStepPath,
53
+ stepPath: sourceStepPath,
54
54
  roleName: entry.toolStepRoleAddress.roleName,
55
55
  },
56
56
  };
@@ -62,7 +62,7 @@ function toCanonicalStep(step) {
62
62
  return canonicalToolStep;
63
63
  }
64
64
  case CONSTANTS.Enums.StepKind.branch: {
65
- const { stepKey: _stepKey, macroStepKey: _macroStepKey, cases, ...rest } = step;
65
+ const { stepKey: _stepKey, cases, ...rest } = step;
66
66
  return {
67
67
  ...rest,
68
68
  cases: cases.map(stripMutableCase),
@@ -70,7 +70,7 @@ function toCanonicalStep(step) {
70
70
  }
71
71
  case CONSTANTS.Enums.StepKind.while:
72
72
  case CONSTANTS.Enums.StepKind.for: {
73
- const { stepKey: _stepKey, macroStepKey: _macroStepKey, case: stepCase, ...rest } = step;
73
+ const { stepKey: _stepKey, case: stepCase, ...rest } = step;
74
74
  return {
75
75
  ...rest,
76
76
  case: stripMutableCase(stepCase),
@@ -84,9 +84,9 @@ function toMutableStrategyStateEntry(entry, executionKeyByPath) {
84
84
  if (entry.strategyStateEntryKind !== 'internalInputPotential') {
85
85
  return entry;
86
86
  }
87
- const sourceToolStepKey = executionKeyByPath.get(entry.toolStepRoleAddress.toolStepPath);
87
+ const sourceToolStepKey = executionKeyByPath.get(entry.toolStepRoleAddress.stepPath);
88
88
  if (!sourceToolStepKey) {
89
- throw new Error(`Cannot deproject strategy state: no mutable key found for toolStepPath '${entry.toolStepRoleAddress.toolStepPath}'.`);
89
+ throw new Error(`Cannot deproject strategy state: no mutable key found for stepPath '${entry.toolStepRoleAddress.stepPath}'.`);
90
90
  }
91
91
  return {
92
92
  strategyStateEntryKind: 'internalInputPotential',
@@ -117,7 +117,6 @@ function toMutableBranchStep(step) {
117
117
  return {
118
118
  ...rest,
119
119
  stepKey: key,
120
- macroStepKey: key,
121
120
  cases: cases.map(toMutableCase),
122
121
  };
123
122
  }
@@ -127,7 +126,6 @@ function toMutableWhileStep(step) {
127
126
  return {
128
127
  ...rest,
129
128
  stepKey: key,
130
- macroStepKey: key,
131
129
  case: toMutableCase(stepCase),
132
130
  };
133
131
  }
@@ -137,7 +135,6 @@ function toMutableForStep(step) {
137
135
  return {
138
136
  ...rest,
139
137
  stepKey: key,
140
- macroStepKey: key,
141
138
  case: toMutableCase(stepCase),
142
139
  };
143
140
  }
@@ -158,8 +155,8 @@ function toMutableStep(step) {
158
155
  function buildExecutionKeyMap(strategy) {
159
156
  const executionPathByKey = buildExecutionPathMap(strategy);
160
157
  const executionKeyByPath = new Map();
161
- for (const [stepKey, toolStepPath] of executionPathByKey.entries()) {
162
- executionKeyByPath.set(toolStepPath, stepKey);
158
+ for (const [stepKey, stepPath] of executionPathByKey.entries()) {
159
+ executionKeyByPath.set(stepPath, stepKey);
163
160
  }
164
161
  return executionKeyByPath;
165
162
  }
@@ -172,14 +169,14 @@ export function strategyToMutableStrategy(strategy) {
172
169
  };
173
170
  const executionKeyByPath = buildExecutionKeyMap(seededMutableStrategy);
174
171
  const strategyState = {};
175
- for (const [toolStepPath, inputEntryByRoleName] of Object.entries(strategy.strategyState)) {
176
- const toolStepKey = executionKeyByPath.get(toolStepPath);
177
- if (!toolStepKey) {
178
- throw new Error(`Cannot deproject strategy state: no mutable key found for toolStepPath '${toolStepPath}'.`);
172
+ for (const [stepPath, inputEntryByRoleName] of Object.entries(strategy.strategyState)) {
173
+ const stepKey = executionKeyByPath.get(stepPath);
174
+ if (!stepKey) {
175
+ throw new Error(`Cannot deproject strategy state: no mutable key found for stepPath '${stepPath}'.`);
179
176
  }
180
- strategyState[toolStepKey] = Object.fromEntries(Object.entries(inputEntryByRoleName).map(([roleName, entry]) => {
177
+ strategyState[stepKey] = Object.fromEntries(Object.entries(inputEntryByRoleName).map(([roleName, entry]) => {
181
178
  if (entry === undefined) {
182
- throw new Error(`Cannot deproject strategy state: role '${roleName}' on toolStepPath '${toolStepPath}' is explicitly undefined.`);
179
+ throw new Error(`Cannot deproject strategy state: role '${roleName}' on stepPath '${stepPath}' is explicitly undefined.`);
183
180
  }
184
181
  return [
185
182
  roleName,
@@ -200,11 +197,11 @@ export function mutableStrategyToStrategy(mutableStrategy) {
200
197
  if (!inputEntryByRoleName) {
201
198
  continue;
202
199
  }
203
- const toolStepPath = executionPathByKey.get(stepKey);
204
- if (!toolStepPath) {
200
+ const stepPath = executionPathByKey.get(stepKey);
201
+ if (!stepPath) {
205
202
  throw new Error(`Cannot project strategy state: no execution path found for stepKey '${stepKey}'.`);
206
203
  }
207
- strategyState[toolStepPath] = Object.fromEntries(Object.entries(inputEntryByRoleName).map(([roleName, entry]) => {
204
+ strategyState[stepPath] = Object.fromEntries(Object.entries(inputEntryByRoleName).map(([roleName, entry]) => {
208
205
  if (entry === undefined) {
209
206
  throw new Error(`Cannot project strategy state: role '${roleName}' on stepKey '${stepKey}' is explicitly undefined.`);
210
207
  }
@@ -220,18 +217,18 @@ export function mutableStrategyToStrategy(mutableStrategy) {
220
217
  strategyState,
221
218
  };
222
219
  }
223
- export function mutableStepKeyToToolStepPath(mutableStrategy, stepKey) {
220
+ export function mutableStepKeyToStepPath(mutableStrategy, stepKey) {
224
221
  const executionPathByKey = buildExecutionPathMap(mutableStrategy);
225
- const toolStepPath = executionPathByKey.get(stepKey);
226
- if (!toolStepPath) {
227
- throw new Error(`Cannot project toolStepPath: no execution path found for stepKey '${stepKey}'.`);
222
+ const stepPath = executionPathByKey.get(stepKey);
223
+ if (!stepPath) {
224
+ throw new Error(`Cannot project stepPath: no execution path found for stepKey '${stepKey}'.`);
228
225
  }
229
- return toolStepPath;
226
+ return stepPath;
230
227
  }
231
228
  export function projectMutableStrategyStateEntriesByStepKeyToCanonicalDelta(mutableStrategy, stepKey, entries) {
232
229
  const executionPathByKey = buildExecutionPathMap(mutableStrategy);
233
- const toolStepPath = executionPathByKey.get(stepKey);
234
- if (!toolStepPath) {
230
+ const stepPath = executionPathByKey.get(stepKey);
231
+ if (!stepPath) {
235
232
  throw new Error(`Cannot project strategy state delta: no execution path found for stepKey '${stepKey}'.`);
236
233
  }
237
234
  const canonicalEntries = Object.fromEntries(Object.entries(entries)
@@ -246,6 +243,6 @@ export function projectMutableStrategyStateEntriesByStepKeyToCanonicalDelta(muta
246
243
  ];
247
244
  }));
248
245
  return {
249
- [toolStepPath]: canonicalEntries,
246
+ [stepPath]: canonicalEntries,
250
247
  };
251
248
  }
@@ -1,2 +1,2 @@
1
- import type { ToolStepPath, ToolStepPathSpec } from '@toolproof-core/genesis';
2
- export declare function toToolStepPath(spec: ToolStepPathSpec): ToolStepPath;
1
+ import type { StepPath, StepPathSpec } from '@toolproof-core/genesis/types';
2
+ export declare function toStepPath(spec: StepPathSpec): StepPath;
@@ -1,21 +1,13 @@
1
- function getToolStepPathSuffix(spec) {
2
- if (spec.toolStepPathSlot === 'self') {
3
- return '/self';
4
- }
5
- if (spec.toolStepPathSlot === 'cases/when' || spec.toolStepPathSlot === 'cases/what') {
6
- if (typeof spec.caseIndex !== 'number') {
7
- throw new Error('Expected caseIndex for branch tool-step path construction');
1
+ function getStepPathSuffix(spec) {
2
+ return spec.segments
3
+ .map((segment) => {
4
+ if (segment.segmentKind === 'case') {
5
+ return `/case/${segment.slot}`;
8
6
  }
9
- return `/cases/${spec.caseIndex}/${spec.toolStepPathSlot === 'cases/when' ? 'when' : 'what'}`;
10
- }
11
- if (spec.toolStepPathSlot === 'case/when') {
12
- return '/case/when';
13
- }
14
- if (spec.toolStepPathSlot === 'case/what') {
15
- return '/case/what';
16
- }
17
- throw new Error(`Unsupported tool-step path slot '${String(spec.toolStepPathSlot)}'`);
7
+ return `/cases/${segment.caseIndex}/${segment.slot}`;
8
+ })
9
+ .join('');
18
10
  }
19
- export function toToolStepPath(spec) {
20
- return `/threads/${spec.threadIndex}/steps/${spec.stepIndex}${getToolStepPathSuffix(spec)}`;
11
+ export function toStepPath(spec) {
12
+ return `/threads/${spec.threadIndex}/steps/${spec.stepIndex}${getStepPathSuffix(spec)}`;
21
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toolproof-core/lib",
3
- "version": "1.0.49",
3
+ "version": "1.0.51",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "keywords": [],
@@ -80,7 +80,7 @@
80
80
  "@types/node": "^22.0.0"
81
81
  },
82
82
  "dependencies": {
83
- "@toolproof-core/genesis": "^1.0.65",
83
+ "@toolproof-core/genesis": "^1.0.66",
84
84
  "firebase-admin": "^13.7.0"
85
85
  },
86
86
  "scripts": {
@@ -13,7 +13,7 @@ import type {
13
13
  ToolStep,
14
14
  ToolStepRoleAddress,
15
15
  WhileStep,
16
- } from '@toolproof-core/genesis';
16
+ } from '@toolproof-core/genesis/types';
17
17
  import { extractResourceTypeHandleFromRoleValue } from './strategyExtraction.js';
18
18
 
19
19
  export type MutableToolStepKey = `TOOL_STEP-${string}`;
@@ -21,13 +21,12 @@ 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 MutableMacroStepKey = MutableBranchStepKey | MutableLoopStepKey;
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
- Omit<ToolStepRoleAddress, 'toolStepPath'> & {
29
+ Omit<ToolStepRoleAddress, 'stepPath'> & {
31
30
  stepKey: MutableToolStepKey;
32
31
  };
33
32
 
@@ -58,19 +57,16 @@ export type MutableCase = Omit<Case, 'when' | 'what'> & {
58
57
 
59
58
  export type MutableBranchStep = Omit<BranchStep, 'cases'> & {
60
59
  stepKey: MutableBranchStepKey;
61
- macroStepKey: MutableBranchStepKey;
62
60
  cases: [MutableCase, ...MutableCase[]];
63
61
  };
64
62
 
65
63
  export type MutableWhileStep = Omit<WhileStep, 'case'> & {
66
64
  stepKey: MutableWhileStepKey;
67
- macroStepKey: MutableWhileStepKey;
68
65
  case: MutableCase;
69
66
  };
70
67
 
71
68
  export type MutableForStep = Omit<ForStep, 'case'> & {
72
69
  stepKey: MutableForStepKey;
73
- macroStepKey: MutableForStepKey;
74
70
  case: MutableCase;
75
71
  };
76
72
 
@@ -62,7 +62,6 @@ export function createLoopStepFromCase(
62
62
  if (stepKind === CONSTANTS.Enums.StepKind.for) {
63
63
  return {
64
64
  stepKey: generateIdentifier('ForStepKey'),
65
- macroStepKey: generateIdentifier('ForStepKey'),
66
65
  stepKind: CONSTANTS.Enums.StepKind.for,
67
66
  case: stepCase,
68
67
  };
@@ -70,7 +69,6 @@ export function createLoopStepFromCase(
70
69
 
71
70
  return {
72
71
  stepKey: generateIdentifier('WhileStepKey'),
73
- macroStepKey: generateIdentifier('WhileStepKey'),
74
72
  stepKind: CONSTANTS.Enums.StepKind.while,
75
73
  case: stepCase,
76
74
  };
@@ -83,7 +81,6 @@ export function createBranchStepFromCases(
83
81
 
84
82
  return {
85
83
  stepKey: generateIdentifier('BranchStepKey'),
86
- macroStepKey: generateIdentifier('BranchStepKey'),
87
84
  stepKind: CONSTANTS.Enums.StepKind.branch,
88
85
  cases,
89
86
  };
@@ -94,7 +91,6 @@ export function cloneForStep(
94
91
  ): MutableForStep {
95
92
  return {
96
93
  stepKey: generateIdentifier('ForStepKey'),
97
- macroStepKey: generateIdentifier('ForStepKey'),
98
94
  stepKind: CONSTANTS.Enums.StepKind.for,
99
95
  case: {
100
96
  what: {
@@ -114,7 +110,6 @@ export function cloneWhileStep(
114
110
  ): MutableWhileStep {
115
111
  return {
116
112
  stepKey: generateIdentifier('WhileStepKey'),
117
- macroStepKey: generateIdentifier('WhileStepKey'),
118
113
  stepKind: CONSTANTS.Enums.StepKind.while,
119
114
  case: {
120
115
  what: {
@@ -10,9 +10,9 @@ import type {
10
10
  Strategy,
11
11
  StrategyStateEntry,
12
12
  ToolStep,
13
- ToolStepPath,
13
+ StepPath,
14
14
  WhileStep,
15
- } from '@toolproof-core/genesis';
15
+ } from '@toolproof-core/genesis/types';
16
16
  import { CONSTANTS } from '../lookups/lookups.js';
17
17
  import type {
18
18
  MutableBranchStep,
@@ -41,24 +41,24 @@ function stripMutableCase(stepCase: MutableCase): Case {
41
41
  };
42
42
  }
43
43
 
44
- function buildExecutionPathMap(strategy: MutableStrategy): Map<MutableToolStepKey, ToolStepPath> {
45
- const executionPathByKey = new Map<MutableToolStepKey, ToolStepPath>();
44
+ function buildExecutionPathMap(strategy: MutableStrategy): Map<MutableToolStepKey, StepPath> {
45
+ const executionPathByKey = new Map<MutableToolStepKey, StepPath>();
46
46
 
47
47
  const registerStep = (step: MutableStep, pathPrefix: string) => {
48
48
  switch (step.stepKind) {
49
49
  case CONSTANTS.Enums.StepKind.tool:
50
- executionPathByKey.set(step.stepKey, `${pathPrefix}/self` as ToolStepPath);
50
+ executionPathByKey.set(step.stepKey, `${pathPrefix}/self` as StepPath);
51
51
  return;
52
52
  case CONSTANTS.Enums.StepKind.branch:
53
53
  step.cases.forEach((stepCase, caseIndex) => {
54
- executionPathByKey.set(stepCase.when.stepKey, `${pathPrefix}/cases/${caseIndex}/when` as ToolStepPath);
55
- executionPathByKey.set(stepCase.what.stepKey, `${pathPrefix}/cases/${caseIndex}/what` as ToolStepPath);
54
+ executionPathByKey.set(stepCase.when.stepKey, `${pathPrefix}/cases/${caseIndex}/when` as StepPath);
55
+ executionPathByKey.set(stepCase.what.stepKey, `${pathPrefix}/cases/${caseIndex}/what` as StepPath);
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.stepKey, `${pathPrefix}/case/when` as ToolStepPath);
61
- executionPathByKey.set(step.case.what.stepKey, `${pathPrefix}/case/what` as ToolStepPath);
60
+ executionPathByKey.set(step.case.when.stepKey, `${pathPrefix}/case/when` as StepPath);
61
+ executionPathByKey.set(step.case.what.stepKey, `${pathPrefix}/case/what` as StepPath);
62
62
  return;
63
63
  default:
64
64
  throw new Error('Unsupported step kind while projecting strategy.');
@@ -76,21 +76,21 @@ function buildExecutionPathMap(strategy: MutableStrategy): Map<MutableToolStepKe
76
76
 
77
77
  function toCanonicalStrategyStateEntry(
78
78
  entry: MutableStrategyStateEntry,
79
- executionPathByKey: ReadonlyMap<MutableToolStepKey, ToolStepPath>,
79
+ executionPathByKey: ReadonlyMap<MutableToolStepKey, StepPath>,
80
80
  ): StrategyStateEntry {
81
81
  if (entry.strategyStateEntryKind !== 'internalInputPotential') {
82
82
  return entry as MaterializedResource | ExternalInputPotential;
83
83
  }
84
84
 
85
- const sourceToolStepPath = executionPathByKey.get(entry.toolStepRoleAddress.stepKey);
86
- if (!sourceToolStepPath) {
85
+ const sourceStepPath = executionPathByKey.get(entry.toolStepRoleAddress.stepKey);
86
+ if (!sourceStepPath) {
87
87
  throw new Error(`Cannot project strategy state: no execution path found for stepKey '${entry.toolStepRoleAddress.stepKey}'.`);
88
88
  }
89
89
 
90
90
  return {
91
91
  strategyStateEntryKind: 'internalInputPotential',
92
92
  toolStepRoleAddress: {
93
- toolStepPath: sourceToolStepPath,
93
+ stepPath: sourceStepPath,
94
94
  roleName: entry.toolStepRoleAddress.roleName,
95
95
  },
96
96
  } satisfies InternalInputPotential;
@@ -103,7 +103,7 @@ function toCanonicalStep(step: MutableStep): Step {
103
103
  return canonicalToolStep;
104
104
  }
105
105
  case CONSTANTS.Enums.StepKind.branch: {
106
- const { stepKey: _stepKey, macroStepKey: _macroStepKey, cases, ...rest } = step;
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, macroStepKey: _macroStepKey, case: stepCase, ...rest } = step;
114
+ const { stepKey: _stepKey, case: stepCase, ...rest } = step;
115
115
  return {
116
116
  ...rest,
117
117
  case: stripMutableCase(stepCase),
@@ -124,15 +124,15 @@ function toCanonicalStep(step: MutableStep): Step {
124
124
 
125
125
  function toMutableStrategyStateEntry(
126
126
  entry: StrategyStateEntry,
127
- executionKeyByPath: ReadonlyMap<ToolStepPath, MutableToolStepKey>,
127
+ executionKeyByPath: ReadonlyMap<StepPath, MutableToolStepKey>,
128
128
  ): MutableStrategyStateEntry {
129
129
  if (entry.strategyStateEntryKind !== 'internalInputPotential') {
130
130
  return entry as MaterializedResource | ExternalInputPotential;
131
131
  }
132
132
 
133
- const sourceToolStepKey = executionKeyByPath.get(entry.toolStepRoleAddress.toolStepPath);
133
+ const sourceToolStepKey = executionKeyByPath.get(entry.toolStepRoleAddress.stepPath);
134
134
  if (!sourceToolStepKey) {
135
- throw new Error(`Cannot deproject strategy state: no mutable key found for toolStepPath '${entry.toolStepRoleAddress.toolStepPath}'.`);
135
+ throw new Error(`Cannot deproject strategy state: no mutable key found for stepPath '${entry.toolStepRoleAddress.stepPath}'.`);
136
136
  }
137
137
 
138
138
  return {
@@ -169,7 +169,6 @@ function toMutableBranchStep(step: BranchStep): MutableBranchStep {
169
169
  return {
170
170
  ...rest,
171
171
  stepKey: key,
172
- macroStepKey: key,
173
172
  cases: cases.map(toMutableCase) as [MutableCase, ...MutableCase[]],
174
173
  };
175
174
  }
@@ -181,7 +180,6 @@ function toMutableWhileStep(step: WhileStep): MutableWhileStep {
181
180
  return {
182
181
  ...rest,
183
182
  stepKey: key,
184
- macroStepKey: key,
185
183
  case: toMutableCase(stepCase),
186
184
  };
187
185
  }
@@ -193,7 +191,6 @@ function toMutableForStep(step: ForStep): MutableForStep {
193
191
  return {
194
192
  ...rest,
195
193
  stepKey: key,
196
- macroStepKey: key,
197
194
  case: toMutableCase(stepCase),
198
195
  };
199
196
  }
@@ -213,12 +210,12 @@ function toMutableStep(step: Step): MutableStep {
213
210
  }
214
211
  }
215
212
 
216
- function buildExecutionKeyMap(strategy: MutableStrategy): Map<ToolStepPath, MutableToolStepKey> {
213
+ function buildExecutionKeyMap(strategy: MutableStrategy): Map<StepPath, MutableToolStepKey> {
217
214
  const executionPathByKey = buildExecutionPathMap(strategy);
218
- const executionKeyByPath = new Map<ToolStepPath, MutableToolStepKey>();
215
+ const executionKeyByPath = new Map<StepPath, MutableToolStepKey>();
219
216
 
220
- for (const [stepKey, toolStepPath] of executionPathByKey.entries()) {
221
- executionKeyByPath.set(toolStepPath, stepKey);
217
+ for (const [stepKey, stepPath] of executionPathByKey.entries()) {
218
+ executionKeyByPath.set(stepPath, stepKey);
222
219
  }
223
220
 
224
221
  return executionKeyByPath;
@@ -236,17 +233,17 @@ export function strategyToMutableStrategy(strategy: Strategy): MutableStrategy {
236
233
  const executionKeyByPath = buildExecutionKeyMap(seededMutableStrategy);
237
234
  const strategyState: MutableStrategy['strategyState'] = {};
238
235
 
239
- for (const [toolStepPath, inputEntryByRoleName] of Object.entries(strategy.strategyState)) {
240
- const toolStepKey = executionKeyByPath.get(toolStepPath as ToolStepPath);
241
- if (!toolStepKey) {
242
- throw new Error(`Cannot deproject strategy state: no mutable key found for toolStepPath '${toolStepPath}'.`);
236
+ for (const [stepPath, inputEntryByRoleName] of Object.entries(strategy.strategyState)) {
237
+ const stepKey = executionKeyByPath.get(stepPath as StepPath);
238
+ if (!stepKey) {
239
+ throw new Error(`Cannot deproject strategy state: no mutable key found for stepPath '${stepPath}'.`);
243
240
  }
244
241
 
245
- strategyState[toolStepKey] = Object.fromEntries(
242
+ strategyState[stepKey] = Object.fromEntries(
246
243
  Object.entries(inputEntryByRoleName).map(([roleName, entry]) => {
247
244
  if (entry === undefined) {
248
245
  throw new Error(
249
- `Cannot deproject strategy state: role '${roleName}' on toolStepPath '${toolStepPath}' is explicitly undefined.`
246
+ `Cannot deproject strategy state: role '${roleName}' on stepPath '${stepPath}' is explicitly undefined.`
250
247
  );
251
248
  }
252
249
 
@@ -274,12 +271,12 @@ export function mutableStrategyToStrategy(mutableStrategy: MutableStrategy): Str
274
271
  continue;
275
272
  }
276
273
 
277
- const toolStepPath = executionPathByKey.get(stepKey as MutableToolStepKey);
278
- if (!toolStepPath) {
274
+ const stepPath = executionPathByKey.get(stepKey as MutableToolStepKey);
275
+ if (!stepPath) {
279
276
  throw new Error(`Cannot project strategy state: no execution path found for stepKey '${stepKey}'.`);
280
277
  }
281
278
 
282
- strategyState[toolStepPath] = Object.fromEntries(
279
+ strategyState[stepPath] = Object.fromEntries(
283
280
  Object.entries(inputEntryByRoleName).map(([roleName, entry]) => {
284
281
  if (entry === undefined) {
285
282
  throw new Error(
@@ -302,17 +299,17 @@ export function mutableStrategyToStrategy(mutableStrategy: MutableStrategy): Str
302
299
  };
303
300
  }
304
301
 
305
- export function mutableStepKeyToToolStepPath(
302
+ export function mutableStepKeyToStepPath(
306
303
  mutableStrategy: MutableStrategy,
307
304
  stepKey: MutableToolStepKey,
308
- ): ToolStepPath {
305
+ ): StepPath {
309
306
  const executionPathByKey = buildExecutionPathMap(mutableStrategy);
310
- const toolStepPath = executionPathByKey.get(stepKey);
311
- if (!toolStepPath) {
312
- throw new Error(`Cannot project toolStepPath: no execution path found for stepKey '${stepKey}'.`);
307
+ const stepPath = executionPathByKey.get(stepKey);
308
+ if (!stepPath) {
309
+ throw new Error(`Cannot project stepPath: no execution path found for stepKey '${stepKey}'.`);
313
310
  }
314
311
 
315
- return toolStepPath;
312
+ return stepPath;
316
313
  }
317
314
 
318
315
  export function projectMutableStrategyStateEntriesByStepKeyToCanonicalDelta(
@@ -321,12 +318,12 @@ export function projectMutableStrategyStateEntriesByStepKeyToCanonicalDelta(
321
318
  entries: MutableStrategyStateEntryByRoleName,
322
319
  ): Strategy['strategyState'] {
323
320
  const executionPathByKey = buildExecutionPathMap(mutableStrategy);
324
- const toolStepPath = executionPathByKey.get(stepKey);
325
- if (!toolStepPath) {
321
+ const stepPath = executionPathByKey.get(stepKey);
322
+ if (!stepPath) {
326
323
  throw new Error(`Cannot project strategy state delta: no execution path found for stepKey '${stepKey}'.`);
327
324
  }
328
325
 
329
- const canonicalEntries: Strategy['strategyState'][ToolStepPath] = Object.fromEntries(
326
+ const canonicalEntries: Strategy['strategyState'][StepPath] = Object.fromEntries(
330
327
  Object.entries(entries)
331
328
  .filter(([, entry]) => entry !== undefined)
332
329
  .map(([roleName, entry]) => {
@@ -344,6 +341,6 @@ export function projectMutableStrategyStateEntriesByStepKeyToCanonicalDelta(
344
341
  );
345
342
 
346
343
  return {
347
- [toolStepPath]: canonicalEntries,
344
+ [stepPath]: canonicalEntries,
348
345
  };
349
346
  }