@toolproof-core/lib 1.0.50 → 1.0.52
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 +2 -4
- package/dist/utils/mutableStrategyOverlay.d.ts +2 -2
- package/dist/utils/strategyCanonicalization.d.ts +2 -2
- package/dist/utils/strategyCanonicalization.js +23 -23
- package/dist/utils/toolStepPaths.d.ts +2 -2
- package/dist/utils/toolStepPaths.js +10 -18
- package/package.json +2 -2
- package/src/utils/mutableStrategyOverlay.ts +2 -2
- package/src/utils/strategyCanonicalization.ts +37 -37
- package/src/utils/toolStepPaths.ts +14 -28
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -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,4 +1,4 @@
|
|
|
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}`;
|
|
@@ -6,7 +6,7 @@ export type MutableForStepKey = `FOR_STEP-${string}`;
|
|
|
6
6
|
export type MutableLoopStepKey = MutableWhileStepKey | MutableForStepKey;
|
|
7
7
|
export type MutableStepKey = MutableToolStepKey | MutableBranchStepKey | MutableLoopStepKey;
|
|
8
8
|
export type MutableMaterializedResource = MaterializedResource;
|
|
9
|
-
export type MutableToolStepRoleAddress = Omit<ToolStepRoleAddress, '
|
|
9
|
+
export type MutableToolStepRoleAddress = Omit<ToolStepRoleAddress, 'stepPath'> & {
|
|
10
10
|
stepKey: MutableToolStepKey;
|
|
11
11
|
};
|
|
12
12
|
export type MutableInternalInputPotential = Omit<InternalInputPotential, 'toolStepRoleAddress'> & {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Strategy,
|
|
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
|
|
5
|
+
export declare function mutableStepKeyToStepPath(mutableStrategy: MutableStrategy, stepKey: MutableToolStepKey): StepPath;
|
|
6
6
|
export declare function projectMutableStrategyStateEntriesByStepKeyToCanonicalDelta(mutableStrategy: MutableStrategy, stepKey: MutableToolStepKey, entries: MutableStrategyStateEntryByRoleName): Strategy['strategyState'];
|
|
@@ -15,7 +15,7 @@ function buildExecutionPathMap(strategy) {
|
|
|
15
15
|
const registerStep = (step, pathPrefix) => {
|
|
16
16
|
switch (step.stepKind) {
|
|
17
17
|
case CONSTANTS.Enums.StepKind.tool:
|
|
18
|
-
executionPathByKey.set(step.stepKey,
|
|
18
|
+
executionPathByKey.set(step.stepKey, pathPrefix);
|
|
19
19
|
return;
|
|
20
20
|
case CONSTANTS.Enums.StepKind.branch:
|
|
21
21
|
step.cases.forEach((stepCase, caseIndex) => {
|
|
@@ -43,14 +43,14 @@ function toCanonicalStrategyStateEntry(entry, executionPathByKey) {
|
|
|
43
43
|
if (entry.strategyStateEntryKind !== 'internalInputPotential') {
|
|
44
44
|
return entry;
|
|
45
45
|
}
|
|
46
|
-
const
|
|
47
|
-
if (!
|
|
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
|
-
|
|
53
|
+
stepPath: sourceStepPath,
|
|
54
54
|
roleName: entry.toolStepRoleAddress.roleName,
|
|
55
55
|
},
|
|
56
56
|
};
|
|
@@ -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.
|
|
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
|
|
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',
|
|
@@ -155,8 +155,8 @@ function toMutableStep(step) {
|
|
|
155
155
|
function buildExecutionKeyMap(strategy) {
|
|
156
156
|
const executionPathByKey = buildExecutionPathMap(strategy);
|
|
157
157
|
const executionKeyByPath = new Map();
|
|
158
|
-
for (const [stepKey,
|
|
159
|
-
executionKeyByPath.set(
|
|
158
|
+
for (const [stepKey, stepPath] of executionPathByKey.entries()) {
|
|
159
|
+
executionKeyByPath.set(stepPath, stepKey);
|
|
160
160
|
}
|
|
161
161
|
return executionKeyByPath;
|
|
162
162
|
}
|
|
@@ -169,14 +169,14 @@ export function strategyToMutableStrategy(strategy) {
|
|
|
169
169
|
};
|
|
170
170
|
const executionKeyByPath = buildExecutionKeyMap(seededMutableStrategy);
|
|
171
171
|
const strategyState = {};
|
|
172
|
-
for (const [
|
|
173
|
-
const stepKey = executionKeyByPath.get(
|
|
172
|
+
for (const [stepPath, inputEntryByRoleName] of Object.entries(strategy.strategyState)) {
|
|
173
|
+
const stepKey = executionKeyByPath.get(stepPath);
|
|
174
174
|
if (!stepKey) {
|
|
175
|
-
throw new Error(`Cannot deproject strategy state: no mutable key found for
|
|
175
|
+
throw new Error(`Cannot deproject strategy state: no mutable key found for stepPath '${stepPath}'.`);
|
|
176
176
|
}
|
|
177
177
|
strategyState[stepKey] = Object.fromEntries(Object.entries(inputEntryByRoleName).map(([roleName, entry]) => {
|
|
178
178
|
if (entry === undefined) {
|
|
179
|
-
throw new Error(`Cannot deproject strategy state: role '${roleName}' on
|
|
179
|
+
throw new Error(`Cannot deproject strategy state: role '${roleName}' on stepPath '${stepPath}' is explicitly undefined.`);
|
|
180
180
|
}
|
|
181
181
|
return [
|
|
182
182
|
roleName,
|
|
@@ -197,11 +197,11 @@ export function mutableStrategyToStrategy(mutableStrategy) {
|
|
|
197
197
|
if (!inputEntryByRoleName) {
|
|
198
198
|
continue;
|
|
199
199
|
}
|
|
200
|
-
const
|
|
201
|
-
if (!
|
|
200
|
+
const stepPath = executionPathByKey.get(stepKey);
|
|
201
|
+
if (!stepPath) {
|
|
202
202
|
throw new Error(`Cannot project strategy state: no execution path found for stepKey '${stepKey}'.`);
|
|
203
203
|
}
|
|
204
|
-
strategyState[
|
|
204
|
+
strategyState[stepPath] = Object.fromEntries(Object.entries(inputEntryByRoleName).map(([roleName, entry]) => {
|
|
205
205
|
if (entry === undefined) {
|
|
206
206
|
throw new Error(`Cannot project strategy state: role '${roleName}' on stepKey '${stepKey}' is explicitly undefined.`);
|
|
207
207
|
}
|
|
@@ -217,18 +217,18 @@ export function mutableStrategyToStrategy(mutableStrategy) {
|
|
|
217
217
|
strategyState,
|
|
218
218
|
};
|
|
219
219
|
}
|
|
220
|
-
export function
|
|
220
|
+
export function mutableStepKeyToStepPath(mutableStrategy, stepKey) {
|
|
221
221
|
const executionPathByKey = buildExecutionPathMap(mutableStrategy);
|
|
222
|
-
const
|
|
223
|
-
if (!
|
|
224
|
-
throw new Error(`Cannot project
|
|
222
|
+
const stepPath = executionPathByKey.get(stepKey);
|
|
223
|
+
if (!stepPath) {
|
|
224
|
+
throw new Error(`Cannot project stepPath: no execution path found for stepKey '${stepKey}'.`);
|
|
225
225
|
}
|
|
226
|
-
return
|
|
226
|
+
return stepPath;
|
|
227
227
|
}
|
|
228
228
|
export function projectMutableStrategyStateEntriesByStepKeyToCanonicalDelta(mutableStrategy, stepKey, entries) {
|
|
229
229
|
const executionPathByKey = buildExecutionPathMap(mutableStrategy);
|
|
230
|
-
const
|
|
231
|
-
if (!
|
|
230
|
+
const stepPath = executionPathByKey.get(stepKey);
|
|
231
|
+
if (!stepPath) {
|
|
232
232
|
throw new Error(`Cannot project strategy state delta: no execution path found for stepKey '${stepKey}'.`);
|
|
233
233
|
}
|
|
234
234
|
const canonicalEntries = Object.fromEntries(Object.entries(entries)
|
|
@@ -243,6 +243,6 @@ export function projectMutableStrategyStateEntriesByStepKeyToCanonicalDelta(muta
|
|
|
243
243
|
];
|
|
244
244
|
}));
|
|
245
245
|
return {
|
|
246
|
-
[
|
|
246
|
+
[stepPath]: canonicalEntries,
|
|
247
247
|
};
|
|
248
248
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function
|
|
1
|
+
import type { StepPath, StepPathSpec } from '@toolproof-core/genesis/types';
|
|
2
|
+
export declare function toStepPath(spec: StepPathSpec): StepPath;
|
|
@@ -1,21 +1,13 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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/${
|
|
10
|
-
}
|
|
11
|
-
|
|
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
|
|
20
|
-
return `/threads/${spec.threadIndex}/steps/${spec.stepIndex}${
|
|
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.
|
|
3
|
+
"version": "1.0.52",
|
|
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.
|
|
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}`;
|
|
@@ -26,7 +26,7 @@ export type MutableStepKey = MutableToolStepKey | MutableBranchStepKey | Mutable
|
|
|
26
26
|
export type MutableMaterializedResource = MaterializedResource;
|
|
27
27
|
|
|
28
28
|
export type MutableToolStepRoleAddress =
|
|
29
|
-
Omit<ToolStepRoleAddress, '
|
|
29
|
+
Omit<ToolStepRoleAddress, 'stepPath'> & {
|
|
30
30
|
stepKey: MutableToolStepKey;
|
|
31
31
|
};
|
|
32
32
|
|
|
@@ -10,9 +10,9 @@ import type {
|
|
|
10
10
|
Strategy,
|
|
11
11
|
StrategyStateEntry,
|
|
12
12
|
ToolStep,
|
|
13
|
-
|
|
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,
|
|
45
|
-
const executionPathByKey = new Map<MutableToolStepKey,
|
|
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,
|
|
50
|
+
executionPathByKey.set(step.stepKey, pathPrefix 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
|
|
55
|
-
executionPathByKey.set(stepCase.what.stepKey, `${pathPrefix}/cases/${caseIndex}/what` as
|
|
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
|
|
61
|
-
executionPathByKey.set(step.case.what.stepKey, `${pathPrefix}/case/what` as
|
|
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,
|
|
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
|
|
86
|
-
if (!
|
|
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
|
-
|
|
93
|
+
stepPath: sourceStepPath,
|
|
94
94
|
roleName: entry.toolStepRoleAddress.roleName,
|
|
95
95
|
},
|
|
96
96
|
} satisfies InternalInputPotential;
|
|
@@ -124,15 +124,15 @@ function toCanonicalStep(step: MutableStep): Step {
|
|
|
124
124
|
|
|
125
125
|
function toMutableStrategyStateEntry(
|
|
126
126
|
entry: StrategyStateEntry,
|
|
127
|
-
executionKeyByPath: ReadonlyMap<
|
|
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.
|
|
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
|
|
135
|
+
throw new Error(`Cannot deproject strategy state: no mutable key found for stepPath '${entry.toolStepRoleAddress.stepPath}'.`);
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
return {
|
|
@@ -210,12 +210,12 @@ function toMutableStep(step: Step): MutableStep {
|
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
function buildExecutionKeyMap(strategy: MutableStrategy): Map<
|
|
213
|
+
function buildExecutionKeyMap(strategy: MutableStrategy): Map<StepPath, MutableToolStepKey> {
|
|
214
214
|
const executionPathByKey = buildExecutionPathMap(strategy);
|
|
215
|
-
const executionKeyByPath = new Map<
|
|
215
|
+
const executionKeyByPath = new Map<StepPath, MutableToolStepKey>();
|
|
216
216
|
|
|
217
|
-
for (const [stepKey,
|
|
218
|
-
executionKeyByPath.set(
|
|
217
|
+
for (const [stepKey, stepPath] of executionPathByKey.entries()) {
|
|
218
|
+
executionKeyByPath.set(stepPath, stepKey);
|
|
219
219
|
}
|
|
220
220
|
|
|
221
221
|
return executionKeyByPath;
|
|
@@ -233,17 +233,17 @@ export function strategyToMutableStrategy(strategy: Strategy): MutableStrategy {
|
|
|
233
233
|
const executionKeyByPath = buildExecutionKeyMap(seededMutableStrategy);
|
|
234
234
|
const strategyState: MutableStrategy['strategyState'] = {};
|
|
235
235
|
|
|
236
|
-
for (const [
|
|
237
|
-
const stepKey = executionKeyByPath.get(
|
|
236
|
+
for (const [stepPath, inputEntryByRoleName] of Object.entries(strategy.strategyState)) {
|
|
237
|
+
const stepKey = executionKeyByPath.get(stepPath as StepPath);
|
|
238
238
|
if (!stepKey) {
|
|
239
|
-
throw new Error(`Cannot deproject strategy state: no mutable key found for
|
|
239
|
+
throw new Error(`Cannot deproject strategy state: no mutable key found for stepPath '${stepPath}'.`);
|
|
240
240
|
}
|
|
241
241
|
|
|
242
242
|
strategyState[stepKey] = Object.fromEntries(
|
|
243
243
|
Object.entries(inputEntryByRoleName).map(([roleName, entry]) => {
|
|
244
244
|
if (entry === undefined) {
|
|
245
245
|
throw new Error(
|
|
246
|
-
`Cannot deproject strategy state: role '${roleName}' on
|
|
246
|
+
`Cannot deproject strategy state: role '${roleName}' on stepPath '${stepPath}' is explicitly undefined.`
|
|
247
247
|
);
|
|
248
248
|
}
|
|
249
249
|
|
|
@@ -271,12 +271,12 @@ export function mutableStrategyToStrategy(mutableStrategy: MutableStrategy): Str
|
|
|
271
271
|
continue;
|
|
272
272
|
}
|
|
273
273
|
|
|
274
|
-
const
|
|
275
|
-
if (!
|
|
274
|
+
const stepPath = executionPathByKey.get(stepKey as MutableToolStepKey);
|
|
275
|
+
if (!stepPath) {
|
|
276
276
|
throw new Error(`Cannot project strategy state: no execution path found for stepKey '${stepKey}'.`);
|
|
277
277
|
}
|
|
278
278
|
|
|
279
|
-
strategyState[
|
|
279
|
+
strategyState[stepPath] = Object.fromEntries(
|
|
280
280
|
Object.entries(inputEntryByRoleName).map(([roleName, entry]) => {
|
|
281
281
|
if (entry === undefined) {
|
|
282
282
|
throw new Error(
|
|
@@ -299,17 +299,17 @@ export function mutableStrategyToStrategy(mutableStrategy: MutableStrategy): Str
|
|
|
299
299
|
};
|
|
300
300
|
}
|
|
301
301
|
|
|
302
|
-
export function
|
|
302
|
+
export function mutableStepKeyToStepPath(
|
|
303
303
|
mutableStrategy: MutableStrategy,
|
|
304
304
|
stepKey: MutableToolStepKey,
|
|
305
|
-
):
|
|
305
|
+
): StepPath {
|
|
306
306
|
const executionPathByKey = buildExecutionPathMap(mutableStrategy);
|
|
307
|
-
const
|
|
308
|
-
if (!
|
|
309
|
-
throw new Error(`Cannot project
|
|
307
|
+
const stepPath = executionPathByKey.get(stepKey);
|
|
308
|
+
if (!stepPath) {
|
|
309
|
+
throw new Error(`Cannot project stepPath: no execution path found for stepKey '${stepKey}'.`);
|
|
310
310
|
}
|
|
311
311
|
|
|
312
|
-
return
|
|
312
|
+
return stepPath;
|
|
313
313
|
}
|
|
314
314
|
|
|
315
315
|
export function projectMutableStrategyStateEntriesByStepKeyToCanonicalDelta(
|
|
@@ -318,12 +318,12 @@ export function projectMutableStrategyStateEntriesByStepKeyToCanonicalDelta(
|
|
|
318
318
|
entries: MutableStrategyStateEntryByRoleName,
|
|
319
319
|
): Strategy['strategyState'] {
|
|
320
320
|
const executionPathByKey = buildExecutionPathMap(mutableStrategy);
|
|
321
|
-
const
|
|
322
|
-
if (!
|
|
321
|
+
const stepPath = executionPathByKey.get(stepKey);
|
|
322
|
+
if (!stepPath) {
|
|
323
323
|
throw new Error(`Cannot project strategy state delta: no execution path found for stepKey '${stepKey}'.`);
|
|
324
324
|
}
|
|
325
325
|
|
|
326
|
-
const canonicalEntries: Strategy['strategyState'][
|
|
326
|
+
const canonicalEntries: Strategy['strategyState'][StepPath] = Object.fromEntries(
|
|
327
327
|
Object.entries(entries)
|
|
328
328
|
.filter(([, entry]) => entry !== undefined)
|
|
329
329
|
.map(([roleName, entry]) => {
|
|
@@ -341,6 +341,6 @@ export function projectMutableStrategyStateEntriesByStepKeyToCanonicalDelta(
|
|
|
341
341
|
);
|
|
342
342
|
|
|
343
343
|
return {
|
|
344
|
-
[
|
|
344
|
+
[stepPath]: canonicalEntries,
|
|
345
345
|
};
|
|
346
346
|
}
|
|
@@ -1,34 +1,20 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from '@toolproof-core/genesis';
|
|
2
|
+
StepPath,
|
|
3
|
+
StepPathSpec,
|
|
4
|
+
} from '@toolproof-core/genesis/types';
|
|
5
5
|
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
function getStepPathSuffix(spec: StepPathSpec): string {
|
|
7
|
+
return spec.segments
|
|
8
|
+
.map((segment) => {
|
|
9
|
+
if (segment.segmentKind === 'case') {
|
|
10
|
+
return `/case/${segment.slot}`;
|
|
11
|
+
}
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return `/cases/${spec.caseIndex}/${spec.toolStepPathSlot === 'cases/when' ? 'when' : 'what'}`;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (spec.toolStepPathSlot === 'case/when') {
|
|
20
|
-
return '/case/when';
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (spec.toolStepPathSlot === 'case/what') {
|
|
24
|
-
return '/case/what';
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
throw new Error(
|
|
28
|
-
`Unsupported tool-step path slot '${String(spec.toolStepPathSlot)}'`,
|
|
29
|
-
);
|
|
13
|
+
return `/cases/${segment.caseIndex}/${segment.slot}`;
|
|
14
|
+
})
|
|
15
|
+
.join('');
|
|
30
16
|
}
|
|
31
17
|
|
|
32
|
-
export function
|
|
33
|
-
return `/threads/${spec.threadIndex}/steps/${spec.stepIndex}${
|
|
18
|
+
export function toStepPath(spec: StepPathSpec): StepPath {
|
|
19
|
+
return `/threads/${spec.threadIndex}/steps/${spec.stepIndex}${getStepPathSuffix(spec)}` as StepPath;
|
|
34
20
|
}
|