@toolproof-core/lib 1.0.47 → 1.0.49
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 +9 -0
- package/dist/utils/mutableStrategyOverlay.d.ts +45 -42
- package/dist/utils/mutableStrategyOverlay.js +18 -18
- package/dist/utils/stepCreation.js +10 -5
- package/dist/utils/stepExpansion.d.ts +2 -2
- package/dist/utils/stepExpansion.js +9 -9
- package/dist/utils/stepParallelization.d.ts +2 -2
- package/dist/utils/stepParallelization.js +13 -13
- package/dist/utils/strategyAssembly.d.ts +1 -1
- package/dist/utils/strategyCanonicalization.d.ts +2 -2
- package/dist/utils/strategyCanonicalization.js +37 -30
- package/dist/utils/strategyStateResolution.d.ts +7 -7
- package/dist/utils/strategyStateResolution.js +1 -1
- package/dist/utils/strategyThreading.d.ts +2 -2
- package/package.json +2 -2
- package/src/utils/mutableStrategyOverlay.ts +92 -107
- package/src/utils/stepCreation.ts +10 -5
- package/src/utils/stepExpansion.ts +15 -22
- package/src/utils/stepParallelization.ts +20 -23
- package/src/utils/strategyAssembly.ts +2 -2
- package/src/utils/strategyCanonicalization.ts +41 -33
- package/src/utils/strategyStateResolution.ts +13 -16
- package/src/utils/strategyThreading.ts +3 -10
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import type { MutableMaterializedResource, MutableExternalInputPotential, MutableStrategyState,
|
|
2
|
-
export type ResolveResult
|
|
1
|
+
import type { MutableMaterializedResource, MutableExternalInputPotential, MutableStrategyState, MutableToolStepRoleAddress } from './mutableStrategyOverlay.js';
|
|
2
|
+
export type ResolveResult = {
|
|
3
3
|
status: 'materializedResource';
|
|
4
4
|
entry: MutableMaterializedResource;
|
|
5
|
-
path: MutableToolStepRoleAddress
|
|
5
|
+
path: MutableToolStepRoleAddress[];
|
|
6
6
|
} | {
|
|
7
7
|
status: 'externalInputPotential';
|
|
8
8
|
entry: MutableExternalInputPotential;
|
|
9
|
-
path: MutableToolStepRoleAddress
|
|
9
|
+
path: MutableToolStepRoleAddress[];
|
|
10
10
|
} | {
|
|
11
11
|
status: 'unresolved';
|
|
12
12
|
reason: 'not-found' | 'cycle' | 'depth-exceeded';
|
|
13
|
-
path: MutableToolStepRoleAddress
|
|
13
|
+
path: MutableToolStepRoleAddress[];
|
|
14
14
|
};
|
|
15
|
-
export declare function resolveStrategyStateChain
|
|
15
|
+
export declare function resolveStrategyStateChain(strategyState: MutableStrategyState, start: MutableToolStepRoleAddress, opts?: {
|
|
16
16
|
maxDepth?: number;
|
|
17
|
-
}): ResolveResult
|
|
17
|
+
}): ResolveResult;
|
|
@@ -6,7 +6,7 @@ export function resolveStrategyStateChain(strategyState, start, opts) {
|
|
|
6
6
|
let current = start;
|
|
7
7
|
for (let depth = 0; depth <= maxDepth; depth++) {
|
|
8
8
|
path.push(current);
|
|
9
|
-
const visitKey = `${current.
|
|
9
|
+
const visitKey = `${current.stepKey}::${current.roleName}`;
|
|
10
10
|
if (visited.has(visitKey)) {
|
|
11
11
|
return { status: 'unresolved', reason: 'cycle', path };
|
|
12
12
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { MutableStrategy
|
|
2
|
-
export declare function toExecutionMutableStrategy
|
|
1
|
+
import type { MutableStrategy } from './mutableStrategyOverlay.js';
|
|
2
|
+
export declare function toExecutionMutableStrategy(mutableStrategy: MutableStrategy): MutableStrategy;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toolproof-core/lib",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.49",
|
|
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.65",
|
|
84
84
|
"firebase-admin": "^13.7.0"
|
|
85
85
|
},
|
|
86
86
|
"scripts": {
|
|
@@ -16,97 +16,85 @@ import type {
|
|
|
16
16
|
} from '@toolproof-core/genesis';
|
|
17
17
|
import { extractResourceTypeHandleFromRoleValue } from './strategyExtraction.js';
|
|
18
18
|
|
|
19
|
-
export type MutableToolStepKey = string
|
|
20
|
-
export type MutableBranchStepKey = string
|
|
21
|
-
export type MutableWhileStepKey = string
|
|
22
|
-
export type MutableForStepKey = string
|
|
19
|
+
export type MutableToolStepKey = `TOOL_STEP-${string}`;
|
|
20
|
+
export type MutableBranchStepKey = `BRANCH_STEP-${string}`;
|
|
21
|
+
export type MutableWhileStepKey = `WHILE_STEP-${string}`;
|
|
22
|
+
export type MutableForStepKey = `FOR_STEP-${string}`;
|
|
23
23
|
export type MutableLoopStepKey = MutableWhileStepKey | MutableForStepKey;
|
|
24
24
|
export type MutableMacroStepKey = MutableBranchStepKey | MutableLoopStepKey;
|
|
25
|
+
export type MutableStepKey = MutableToolStepKey | MutableMacroStepKey;
|
|
25
26
|
|
|
26
27
|
export type MutableMaterializedResource = MaterializedResource;
|
|
27
28
|
|
|
28
|
-
export type MutableToolStepRoleAddress
|
|
29
|
+
export type MutableToolStepRoleAddress =
|
|
29
30
|
Omit<ToolStepRoleAddress, 'toolStepPath'> & {
|
|
30
|
-
|
|
31
|
+
stepKey: MutableToolStepKey;
|
|
31
32
|
};
|
|
32
33
|
|
|
33
|
-
export type MutableInternalInputPotential
|
|
34
|
+
export type MutableInternalInputPotential =
|
|
34
35
|
Omit<InternalInputPotential, 'toolStepRoleAddress'> & {
|
|
35
|
-
toolStepRoleAddress: MutableToolStepRoleAddress
|
|
36
|
+
toolStepRoleAddress: MutableToolStepRoleAddress;
|
|
36
37
|
};
|
|
37
38
|
|
|
38
39
|
export type MutableExternalInputPotential = ExternalInputPotential;
|
|
39
40
|
|
|
40
|
-
export type MutableStrategyStateEntry
|
|
41
|
+
export type MutableStrategyStateEntry =
|
|
41
42
|
| MutableMaterializedResource
|
|
42
|
-
| MutableInternalInputPotential
|
|
43
|
+
| MutableInternalInputPotential
|
|
43
44
|
| MutableExternalInputPotential;
|
|
44
45
|
|
|
45
|
-
export type MutableStrategyStateEntryByRoleName<
|
|
46
|
-
TKey extends string = MutableToolStepKey,
|
|
47
|
-
> = Partial<Record<RoleName, MutableStrategyStateEntry<TKey>>>;
|
|
46
|
+
export type MutableStrategyStateEntryByRoleName = Partial<Record<RoleName, MutableStrategyStateEntry>>;
|
|
48
47
|
|
|
49
|
-
export type MutableStrategyState<
|
|
50
|
-
TKey extends string = MutableToolStepKey,
|
|
51
|
-
> = Partial<Record<TKey, MutableStrategyStateEntryByRoleName<TKey>>>;
|
|
48
|
+
export type MutableStrategyState = Partial<Record<MutableToolStepKey, MutableStrategyStateEntryByRoleName>>;
|
|
52
49
|
|
|
53
|
-
export type MutableToolStep
|
|
54
|
-
|
|
50
|
+
export type MutableToolStep = ToolStep & {
|
|
51
|
+
stepKey: MutableToolStepKey;
|
|
55
52
|
};
|
|
56
53
|
|
|
57
|
-
export type MutableCase
|
|
58
|
-
when: MutableToolStep
|
|
59
|
-
what: MutableToolStep
|
|
54
|
+
export type MutableCase = Omit<Case, 'when' | 'what'> & {
|
|
55
|
+
when: MutableToolStep;
|
|
56
|
+
what: MutableToolStep;
|
|
60
57
|
};
|
|
61
58
|
|
|
62
|
-
export type MutableBranchStep
|
|
59
|
+
export type MutableBranchStep = Omit<BranchStep, 'cases'> & {
|
|
60
|
+
stepKey: MutableBranchStepKey;
|
|
63
61
|
macroStepKey: MutableBranchStepKey;
|
|
64
|
-
cases: [MutableCase
|
|
62
|
+
cases: [MutableCase, ...MutableCase[]];
|
|
65
63
|
};
|
|
66
64
|
|
|
67
|
-
export type MutableWhileStep
|
|
65
|
+
export type MutableWhileStep = Omit<WhileStep, 'case'> & {
|
|
66
|
+
stepKey: MutableWhileStepKey;
|
|
68
67
|
macroStepKey: MutableWhileStepKey;
|
|
69
|
-
case: MutableCase
|
|
68
|
+
case: MutableCase;
|
|
70
69
|
};
|
|
71
70
|
|
|
72
|
-
export type MutableForStep
|
|
71
|
+
export type MutableForStep = Omit<ForStep, 'case'> & {
|
|
72
|
+
stepKey: MutableForStepKey;
|
|
73
73
|
macroStepKey: MutableForStepKey;
|
|
74
|
-
case: MutableCase
|
|
74
|
+
case: MutableCase;
|
|
75
75
|
};
|
|
76
76
|
|
|
77
|
-
export type MutableStep
|
|
78
|
-
| MutableToolStep
|
|
79
|
-
| MutableBranchStep
|
|
80
|
-
| MutableWhileStep
|
|
81
|
-
| MutableForStep
|
|
82
|
-
|
|
83
|
-
export type MutableStrategy<
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
TState extends MutableStrategyState<TKey> = MutableStrategyState<TKey>,
|
|
87
|
-
> = Omit<Strategy, 'stepsByThreadIndex' | 'strategyState'> & {
|
|
88
|
-
stepsByThreadIndex: TStep[][];
|
|
89
|
-
strategyState: TState;
|
|
77
|
+
export type MutableStep =
|
|
78
|
+
| MutableToolStep
|
|
79
|
+
| MutableBranchStep
|
|
80
|
+
| MutableWhileStep
|
|
81
|
+
| MutableForStep;
|
|
82
|
+
|
|
83
|
+
export type MutableStrategy = Omit<Strategy, 'stepsByThreadIndex' | 'strategyState'> & {
|
|
84
|
+
stepsByThreadIndex: MutableStep[][];
|
|
85
|
+
strategyState: MutableStrategyState;
|
|
90
86
|
};
|
|
91
87
|
|
|
92
|
-
export function getAuthoringSteps
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
TState extends MutableStrategyState<TKey> = MutableStrategyState<TKey>,
|
|
96
|
-
>(
|
|
97
|
-
strategy: MutableStrategy<TKey, TStep, TState>,
|
|
98
|
-
): TStep[] {
|
|
88
|
+
export function getAuthoringSteps(
|
|
89
|
+
strategy: MutableStrategy,
|
|
90
|
+
): MutableStep[] {
|
|
99
91
|
return strategy.stepsByThreadIndex[0] ?? [];
|
|
100
92
|
}
|
|
101
93
|
|
|
102
|
-
export function setAuthoringSteps
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
>(
|
|
107
|
-
strategy: MutableStrategy<TKey, TStep, TState>,
|
|
108
|
-
steps: TStep[],
|
|
109
|
-
): MutableStrategy<TKey, TStep, TState> {
|
|
94
|
+
export function setAuthoringSteps(
|
|
95
|
+
strategy: MutableStrategy,
|
|
96
|
+
steps: MutableStep[],
|
|
97
|
+
): MutableStrategy {
|
|
110
98
|
const nextStepsByThreadIndex = [...strategy.stepsByThreadIndex];
|
|
111
99
|
nextStepsByThreadIndex[0] = steps;
|
|
112
100
|
|
|
@@ -116,48 +104,45 @@ export function setAuthoringSteps< // ATTENTION
|
|
|
116
104
|
};
|
|
117
105
|
}
|
|
118
106
|
|
|
119
|
-
export function getStrategyStateEntryByRoleName
|
|
120
|
-
strategyState:
|
|
121
|
-
|
|
122
|
-
): MutableStrategyStateEntryByRoleName
|
|
123
|
-
return strategyState[
|
|
107
|
+
export function getStrategyStateEntryByRoleName(
|
|
108
|
+
strategyState: MutableStrategyState,
|
|
109
|
+
stepKey: MutableToolStepKey,
|
|
110
|
+
): MutableStrategyStateEntryByRoleName | undefined {
|
|
111
|
+
return strategyState[stepKey];
|
|
124
112
|
}
|
|
125
113
|
|
|
126
|
-
export function getStrategyStateEntry
|
|
127
|
-
strategyState:
|
|
128
|
-
toolStepRoleAddress: MutableToolStepRoleAddress
|
|
129
|
-
): MutableStrategyStateEntry
|
|
130
|
-
const inputEntryByRoleName = getStrategyStateEntryByRoleName(strategyState, toolStepRoleAddress.
|
|
114
|
+
export function getStrategyStateEntry(
|
|
115
|
+
strategyState: MutableStrategyState,
|
|
116
|
+
toolStepRoleAddress: MutableToolStepRoleAddress,
|
|
117
|
+
): MutableStrategyStateEntry | undefined {
|
|
118
|
+
const inputEntryByRoleName = getStrategyStateEntryByRoleName(strategyState, toolStepRoleAddress.stepKey);
|
|
131
119
|
return inputEntryByRoleName?.[toolStepRoleAddress.roleName];
|
|
132
120
|
}
|
|
133
121
|
|
|
134
|
-
export function setStrategyStateEntry
|
|
135
|
-
strategyState:
|
|
136
|
-
toolStepRoleAddress: MutableToolStepRoleAddress
|
|
137
|
-
entry: MutableStrategyStateEntry
|
|
138
|
-
):
|
|
139
|
-
const inputEntryByRoleName = getStrategyStateEntryByRoleName(strategyState, toolStepRoleAddress.
|
|
122
|
+
export function setStrategyStateEntry(
|
|
123
|
+
strategyState: MutableStrategyState,
|
|
124
|
+
toolStepRoleAddress: MutableToolStepRoleAddress,
|
|
125
|
+
entry: MutableStrategyStateEntry,
|
|
126
|
+
): MutableStrategyState {
|
|
127
|
+
const inputEntryByRoleName = getStrategyStateEntryByRoleName(strategyState, toolStepRoleAddress.stepKey) ?? {};
|
|
140
128
|
|
|
141
129
|
return {
|
|
142
130
|
...strategyState,
|
|
143
|
-
[toolStepRoleAddress.
|
|
131
|
+
[toolStepRoleAddress.stepKey]: {
|
|
144
132
|
...inputEntryByRoleName,
|
|
145
133
|
[toolStepRoleAddress.roleName]: entry,
|
|
146
134
|
},
|
|
147
135
|
};
|
|
148
136
|
}
|
|
149
137
|
|
|
150
|
-
export function clearInputBinding
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
strategyState: TStrategyState,
|
|
155
|
-
toolStepRoleAddress: MutableToolStepRoleAddress<TKey>,
|
|
156
|
-
): TStrategyState {
|
|
138
|
+
export function clearInputBinding(
|
|
139
|
+
strategyState: MutableStrategyState,
|
|
140
|
+
toolStepRoleAddress: MutableToolStepRoleAddress,
|
|
141
|
+
): MutableStrategyState {
|
|
157
142
|
const inputEntryByRoleName =
|
|
158
143
|
getStrategyStateEntryByRoleName(
|
|
159
144
|
strategyState,
|
|
160
|
-
toolStepRoleAddress.
|
|
145
|
+
toolStepRoleAddress.stepKey,
|
|
161
146
|
);
|
|
162
147
|
|
|
163
148
|
if (!inputEntryByRoleName || !(toolStepRoleAddress.roleName in inputEntryByRoleName)) {
|
|
@@ -169,21 +154,21 @@ export function clearInputBinding<
|
|
|
169
154
|
|
|
170
155
|
if (Object.keys(nextInputEntryByRoleName).length === 0) {
|
|
171
156
|
const nextStrategyState = { ...strategyState };
|
|
172
|
-
delete nextStrategyState[toolStepRoleAddress.
|
|
173
|
-
return nextStrategyState
|
|
157
|
+
delete nextStrategyState[toolStepRoleAddress.stepKey];
|
|
158
|
+
return nextStrategyState;
|
|
174
159
|
}
|
|
175
160
|
|
|
176
161
|
return {
|
|
177
162
|
...strategyState,
|
|
178
|
-
[toolStepRoleAddress.
|
|
163
|
+
[toolStepRoleAddress.stepKey]: nextInputEntryByRoleName,
|
|
179
164
|
};
|
|
180
165
|
}
|
|
181
166
|
|
|
182
|
-
export function bindMaterializedResource
|
|
183
|
-
strategyState:
|
|
184
|
-
target: MutableToolStepRoleAddress
|
|
167
|
+
export function bindMaterializedResource(
|
|
168
|
+
strategyState: MutableStrategyState,
|
|
169
|
+
target: MutableToolStepRoleAddress,
|
|
185
170
|
resource: Resource,
|
|
186
|
-
):
|
|
171
|
+
): MutableStrategyState { // ATTENTION: misleading name since it also materializes the Resource
|
|
187
172
|
const mutableMaterializedResource: MutableMaterializedResource = {
|
|
188
173
|
...resource,
|
|
189
174
|
strategyStateEntryKind: 'materializedResource',
|
|
@@ -200,24 +185,24 @@ function getOutputRoleValue(tool: Tool, roleName: RoleName) {
|
|
|
200
185
|
return tool.roleSpec.outputRoleValueByName[roleName];
|
|
201
186
|
}
|
|
202
187
|
|
|
203
|
-
export function bindInternalInputPotential
|
|
204
|
-
strategyState:
|
|
205
|
-
targetAddress: MutableToolStepRoleAddress
|
|
206
|
-
sourceAddress: MutableToolStepRoleAddress
|
|
188
|
+
export function bindInternalInputPotential(
|
|
189
|
+
strategyState: MutableStrategyState,
|
|
190
|
+
targetAddress: MutableToolStepRoleAddress,
|
|
191
|
+
sourceAddress: MutableToolStepRoleAddress,
|
|
207
192
|
context: {
|
|
208
|
-
toolStepByKey: ReadonlyMap<
|
|
193
|
+
toolStepByKey: ReadonlyMap<MutableToolStepKey, MutableToolStep>;
|
|
209
194
|
toolMap: ReadonlyMap<ToolHandle, Tool>;
|
|
210
195
|
}
|
|
211
|
-
):
|
|
196
|
+
): MutableStrategyState {
|
|
212
197
|
|
|
213
|
-
const sourceToolStep = context.toolStepByKey.get(sourceAddress.
|
|
198
|
+
const sourceToolStep = context.toolStepByKey.get(sourceAddress.stepKey);
|
|
214
199
|
if (!sourceToolStep) {
|
|
215
|
-
throw new Error(`Source tool step not found for '${sourceAddress.
|
|
200
|
+
throw new Error(`Source tool step not found for '${sourceAddress.stepKey}'.`);
|
|
216
201
|
}
|
|
217
202
|
|
|
218
|
-
const targetToolStep = context.toolStepByKey.get(targetAddress.
|
|
203
|
+
const targetToolStep = context.toolStepByKey.get(targetAddress.stepKey);
|
|
219
204
|
if (!targetToolStep) {
|
|
220
|
-
throw new Error(`Target tool step not found for '${targetAddress.
|
|
205
|
+
throw new Error(`Target tool step not found for '${targetAddress.stepKey}'.`);
|
|
221
206
|
}
|
|
222
207
|
|
|
223
208
|
const sourceTool = context.toolMap.get(sourceToolStep.toolHandle);
|
|
@@ -232,13 +217,13 @@ export function bindInternalInputPotential<TKey extends string, TStrategyState e
|
|
|
232
217
|
|
|
233
218
|
const targetInputRoleValue = getInputRoleValue(targetTool, targetAddress.roleName);
|
|
234
219
|
if (!targetInputRoleValue) {
|
|
235
|
-
throw new Error(`Target input role not found for (${targetAddress.
|
|
220
|
+
throw new Error(`Target input role not found for (${targetAddress.stepKey}, ${targetAddress.roleName}).`);
|
|
236
221
|
}
|
|
237
222
|
|
|
238
223
|
const sourceOutputRoleValue = getOutputRoleValue(sourceTool, sourceAddress.roleName);
|
|
239
224
|
const sourceInputRoleValue = getInputRoleValue(sourceTool, sourceAddress.roleName);
|
|
240
225
|
|
|
241
|
-
const sourceInputEntryByRoleName = strategyState[sourceAddress.
|
|
226
|
+
const sourceInputEntryByRoleName = strategyState[sourceAddress.stepKey];
|
|
242
227
|
const sourceInputEntry = sourceInputEntryByRoleName?.[sourceAddress.roleName];
|
|
243
228
|
|
|
244
229
|
const sourceRoleType = sourceOutputRoleValue
|
|
@@ -251,33 +236,33 @@ export function bindInternalInputPotential<TKey extends string, TStrategyState e
|
|
|
251
236
|
|
|
252
237
|
if (!sourceOutputRoleValue && sourceInputRoleValue) {
|
|
253
238
|
if (!sourceInputEntry) {
|
|
254
|
-
throw new Error(`Source input role is not bound for (${sourceAddress.
|
|
239
|
+
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.
|
|
255
240
|
}
|
|
256
241
|
}
|
|
257
242
|
|
|
258
243
|
if (!sourceOutputRoleValue && !sourceInputRoleValue) {
|
|
259
|
-
throw new Error(`Source role not found for (${sourceAddress.
|
|
244
|
+
throw new Error(`Source role not found for (${sourceAddress.stepKey}, ${sourceAddress.roleName}).`);
|
|
260
245
|
}
|
|
261
246
|
|
|
262
247
|
if (!sourceRoleType || !targetRoleType || sourceRoleType !== targetRoleType) {
|
|
263
248
|
throw new Error(
|
|
264
|
-
`Reference type mismatch between source (${sourceAddress.
|
|
249
|
+
`Reference type mismatch between source (${sourceAddress.stepKey}, ${sourceAddress.roleName}) and target (${targetAddress.stepKey}, ${targetAddress.roleName}).`
|
|
265
250
|
);
|
|
266
251
|
}
|
|
267
252
|
|
|
268
253
|
return setStrategyStateEntry(strategyState, targetAddress, {
|
|
269
254
|
strategyStateEntryKind: 'internalInputPotential',
|
|
270
255
|
toolStepRoleAddress: {
|
|
271
|
-
|
|
256
|
+
stepKey: sourceAddress.stepKey,
|
|
272
257
|
roleName: sourceAddress.roleName,
|
|
273
258
|
},
|
|
274
259
|
});
|
|
275
260
|
}
|
|
276
261
|
|
|
277
|
-
export function bindExternalInputPotential
|
|
278
|
-
strategyState:
|
|
279
|
-
target: MutableToolStepRoleAddress
|
|
280
|
-
):
|
|
262
|
+
export function bindExternalInputPotential(
|
|
263
|
+
strategyState: MutableStrategyState,
|
|
264
|
+
target: MutableToolStepRoleAddress,
|
|
265
|
+
): MutableStrategyState {
|
|
281
266
|
const mutableExternalInputPotential: MutableExternalInputPotential = {
|
|
282
267
|
strategyStateEntryKind: 'externalInputPotential',
|
|
283
268
|
};
|
|
@@ -31,7 +31,7 @@ export function createToolStepFromTool(
|
|
|
31
31
|
tool: Tool,
|
|
32
32
|
): MutableToolStep {
|
|
33
33
|
return {
|
|
34
|
-
|
|
34
|
+
stepKey: generateIdentifier('ToolStepKey'),
|
|
35
35
|
stepKind: CONSTANTS.Enums.StepKind.tool,
|
|
36
36
|
toolHandle: tool.handle,
|
|
37
37
|
roleBindingSpec: getRoleBindingSpec(tool),
|
|
@@ -61,6 +61,7 @@ export function createLoopStepFromCase(
|
|
|
61
61
|
): MutableForStep | MutableWhileStep {
|
|
62
62
|
if (stepKind === CONSTANTS.Enums.StepKind.for) {
|
|
63
63
|
return {
|
|
64
|
+
stepKey: generateIdentifier('ForStepKey'),
|
|
64
65
|
macroStepKey: generateIdentifier('ForStepKey'),
|
|
65
66
|
stepKind: CONSTANTS.Enums.StepKind.for,
|
|
66
67
|
case: stepCase,
|
|
@@ -68,6 +69,7 @@ export function createLoopStepFromCase(
|
|
|
68
69
|
}
|
|
69
70
|
|
|
70
71
|
return {
|
|
72
|
+
stepKey: generateIdentifier('WhileStepKey'),
|
|
71
73
|
macroStepKey: generateIdentifier('WhileStepKey'),
|
|
72
74
|
stepKind: CONSTANTS.Enums.StepKind.while,
|
|
73
75
|
case: stepCase,
|
|
@@ -80,6 +82,7 @@ export function createBranchStepFromCases(
|
|
|
80
82
|
assertNonEmpty(cases, 'createBranchStepFromCases requires at least one case');
|
|
81
83
|
|
|
82
84
|
return {
|
|
85
|
+
stepKey: generateIdentifier('BranchStepKey'),
|
|
83
86
|
macroStepKey: generateIdentifier('BranchStepKey'),
|
|
84
87
|
stepKind: CONSTANTS.Enums.StepKind.branch,
|
|
85
88
|
cases,
|
|
@@ -90,16 +93,17 @@ export function cloneForStep(
|
|
|
90
93
|
forStep: MutableForStep,
|
|
91
94
|
): MutableForStep {
|
|
92
95
|
return {
|
|
96
|
+
stepKey: generateIdentifier('ForStepKey'),
|
|
93
97
|
macroStepKey: generateIdentifier('ForStepKey'),
|
|
94
98
|
stepKind: CONSTANTS.Enums.StepKind.for,
|
|
95
99
|
case: {
|
|
96
100
|
what: {
|
|
97
101
|
...forStep.case.what,
|
|
98
|
-
|
|
102
|
+
stepKey: generateIdentifier('ToolStepKey'),
|
|
99
103
|
},
|
|
100
104
|
when: {
|
|
101
105
|
...forStep.case.when,
|
|
102
|
-
|
|
106
|
+
stepKey: generateIdentifier('ToolStepKey'),
|
|
103
107
|
},
|
|
104
108
|
},
|
|
105
109
|
};
|
|
@@ -109,16 +113,17 @@ export function cloneWhileStep(
|
|
|
109
113
|
whileStep: MutableWhileStep,
|
|
110
114
|
): MutableWhileStep {
|
|
111
115
|
return {
|
|
116
|
+
stepKey: generateIdentifier('WhileStepKey'),
|
|
112
117
|
macroStepKey: generateIdentifier('WhileStepKey'),
|
|
113
118
|
stepKind: CONSTANTS.Enums.StepKind.while,
|
|
114
119
|
case: {
|
|
115
120
|
what: {
|
|
116
121
|
...whileStep.case.what,
|
|
117
|
-
|
|
122
|
+
stepKey: generateIdentifier('ToolStepKey'),
|
|
118
123
|
},
|
|
119
124
|
when: {
|
|
120
125
|
...whileStep.case.when,
|
|
121
|
-
|
|
126
|
+
stepKey: generateIdentifier('ToolStepKey'),
|
|
122
127
|
},
|
|
123
128
|
},
|
|
124
129
|
};
|
|
@@ -1,63 +1,56 @@
|
|
|
1
1
|
import { CONSTANTS } from '../lookups/lookups.js';
|
|
2
2
|
import type {
|
|
3
|
-
MutableBranchStep,
|
|
4
|
-
MutableForStep,
|
|
5
3
|
MutableStep,
|
|
6
4
|
MutableToolStep,
|
|
7
|
-
MutableToolStepKey,
|
|
8
|
-
MutableWhileStep,
|
|
9
5
|
} from './mutableStrategyOverlay.js';
|
|
10
6
|
|
|
11
|
-
export type StepExpansionOrder = {
|
|
7
|
+
export type StepExpansionOrder = { // ATTENTION: redundant?
|
|
12
8
|
branchCaseOrder?: 'when-what' | 'what-when';
|
|
13
9
|
loopCaseOrder?: 'what-when' | 'when-what';
|
|
14
10
|
};
|
|
15
11
|
|
|
16
|
-
export function extractToolStepsFromStep
|
|
17
|
-
|
|
18
|
-
TStep extends MutableStep<TKey> = MutableStep<TKey>,
|
|
19
|
-
>(
|
|
20
|
-
step: TStep,
|
|
12
|
+
export function extractToolStepsFromStep(
|
|
13
|
+
step: MutableStep,
|
|
21
14
|
order: StepExpansionOrder = {},
|
|
22
|
-
): MutableToolStep
|
|
15
|
+
): MutableToolStep[] {
|
|
23
16
|
const {
|
|
24
17
|
branchCaseOrder = 'when-what',
|
|
25
18
|
loopCaseOrder = 'what-when',
|
|
26
19
|
} = order;
|
|
27
20
|
|
|
28
21
|
if (step.stepKind === CONSTANTS.Enums.StepKind.tool) {
|
|
29
|
-
return [step
|
|
22
|
+
return [step];
|
|
30
23
|
}
|
|
31
24
|
|
|
32
25
|
if (step.stepKind === CONSTANTS.Enums.StepKind.branch) {
|
|
33
|
-
const
|
|
34
|
-
const cases =
|
|
26
|
+
const branchStep = step;
|
|
27
|
+
const cases = branchStep.cases ?? [];
|
|
35
28
|
return cases.flatMap((stepCase) => {
|
|
36
29
|
if (branchCaseOrder === 'what-when') {
|
|
37
30
|
return [stepCase.what, stepCase.when];
|
|
38
31
|
}
|
|
39
32
|
|
|
40
33
|
return [stepCase.when, stepCase.what];
|
|
41
|
-
})
|
|
34
|
+
});
|
|
42
35
|
}
|
|
43
36
|
|
|
44
37
|
if (step.stepKind === CONSTANTS.Enums.StepKind.while) {
|
|
45
|
-
const
|
|
38
|
+
const whileStep = step;
|
|
46
39
|
if (loopCaseOrder === 'when-what') {
|
|
47
|
-
return [
|
|
40
|
+
return [whileStep.case.when, whileStep.case.what];
|
|
48
41
|
}
|
|
49
42
|
|
|
50
|
-
return [
|
|
43
|
+
return [whileStep.case.what, whileStep.case.when];
|
|
51
44
|
}
|
|
52
45
|
|
|
53
46
|
if (step.stepKind === CONSTANTS.Enums.StepKind.for) {
|
|
54
|
-
const
|
|
47
|
+
const forStep = step;
|
|
55
48
|
if (loopCaseOrder === 'when-what') {
|
|
56
|
-
return [
|
|
49
|
+
return [forStep.case.when, forStep.case.what];
|
|
57
50
|
}
|
|
58
51
|
|
|
59
|
-
return [
|
|
52
|
+
return [forStep.case.what, forStep.case.when];
|
|
60
53
|
}
|
|
61
54
|
|
|
62
|
-
return []
|
|
55
|
+
return [];
|
|
63
56
|
}
|
|
@@ -6,13 +6,10 @@ import type {
|
|
|
6
6
|
} from './mutableStrategyOverlay.js';
|
|
7
7
|
import { extractToolStepsFromStep } from './stepExpansion.js';
|
|
8
8
|
|
|
9
|
-
export function getIndependentThreads
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
steps: TStep[],
|
|
14
|
-
strategyState: MutableStrategyState<TKey>,
|
|
15
|
-
): TStep[][] {
|
|
9
|
+
export function getIndependentThreads(
|
|
10
|
+
steps: MutableStep[],
|
|
11
|
+
strategyState: MutableStrategyState,
|
|
12
|
+
): MutableStep[][] {
|
|
16
13
|
type OwnerIndex = number;
|
|
17
14
|
|
|
18
15
|
const getOwnerLabel = (ownerIndex: OwnerIndex) => {
|
|
@@ -20,28 +17,28 @@ export function getIndependentThreads<
|
|
|
20
17
|
return `steps[${ownerIndex}] stepKind=${step?.stepKind ?? 'unknown'}`;
|
|
21
18
|
};
|
|
22
19
|
|
|
23
|
-
const
|
|
24
|
-
const toolStepByKey = new Map<
|
|
20
|
+
const stepKeyToOwner = new Map<MutableToolStepKey, OwnerIndex>();
|
|
21
|
+
const toolStepByKey = new Map<MutableToolStepKey, MutableToolStep>();
|
|
25
22
|
|
|
26
23
|
const addToolStep = (
|
|
27
|
-
toolStep: MutableToolStep
|
|
24
|
+
toolStep: MutableToolStep | undefined,
|
|
28
25
|
ownerIndex: OwnerIndex,
|
|
29
26
|
) => {
|
|
30
27
|
if (!toolStep) return;
|
|
31
28
|
|
|
32
|
-
const existingOwner =
|
|
29
|
+
const existingOwner = stepKeyToOwner.get(toolStep.stepKey);
|
|
33
30
|
if (existingOwner !== undefined) {
|
|
34
31
|
throw new Error(
|
|
35
|
-
`Duplicate
|
|
32
|
+
`Duplicate stepKey '${toolStep.stepKey}' found in ${getOwnerLabel(ownerIndex)} and ${getOwnerLabel(existingOwner)}`
|
|
36
33
|
);
|
|
37
34
|
}
|
|
38
35
|
|
|
39
|
-
|
|
40
|
-
toolStepByKey.set(toolStep.
|
|
36
|
+
stepKeyToOwner.set(toolStep.stepKey, ownerIndex);
|
|
37
|
+
toolStepByKey.set(toolStep.stepKey, toolStep);
|
|
41
38
|
};
|
|
42
39
|
|
|
43
40
|
steps.forEach((step, ownerIndex) => {
|
|
44
|
-
for (const toolStep of extractToolStepsFromStep
|
|
41
|
+
for (const toolStep of extractToolStepsFromStep(step, { branchCaseOrder: 'what-when' })) {
|
|
45
42
|
addToolStep(toolStep, ownerIndex);
|
|
46
43
|
}
|
|
47
44
|
});
|
|
@@ -58,28 +55,28 @@ export function getIndependentThreads<
|
|
|
58
55
|
ensureOwner(index);
|
|
59
56
|
}
|
|
60
57
|
|
|
61
|
-
for (const [
|
|
58
|
+
for (const [stepKey, ownerIndex] of stepKeyToOwner) {
|
|
62
59
|
ensureOwner(ownerIndex);
|
|
63
60
|
|
|
64
|
-
const toolStep = toolStepByKey.get(
|
|
61
|
+
const toolStep = toolStepByKey.get(stepKey);
|
|
65
62
|
const inputBindings = toolStep?.roleBindingSpec?.inputBindings ?? [];
|
|
66
|
-
const bucket = strategyState[
|
|
63
|
+
const bucket = strategyState[stepKey];
|
|
67
64
|
|
|
68
65
|
for (const inputRoleId of inputBindings) {
|
|
69
66
|
const entry = bucket?.[inputRoleId];
|
|
70
67
|
if (!entry || entry.strategyStateEntryKind !== 'internalInputPotential') continue;
|
|
71
68
|
|
|
72
|
-
const
|
|
73
|
-
if (typeof
|
|
69
|
+
const producerStepKey = entry.toolStepRoleAddress?.stepKey;
|
|
70
|
+
if (typeof producerStepKey !== 'string') {
|
|
74
71
|
throw new Error(
|
|
75
|
-
`Unresolvable internalInputPotential in toolStep '${
|
|
72
|
+
`Unresolvable internalInputPotential in toolStep '${stepKey}' (${getOwnerLabel(ownerIndex)}): missing toolStepRoleAddress.stepKey for role '${inputRoleId}'`
|
|
76
73
|
);
|
|
77
74
|
}
|
|
78
75
|
|
|
79
|
-
const producerOwner =
|
|
76
|
+
const producerOwner = stepKeyToOwner.get(producerStepKey);
|
|
80
77
|
if (producerOwner === undefined) {
|
|
81
78
|
throw new Error(
|
|
82
|
-
`Unresolvable internalInputPotential in toolStep '${
|
|
79
|
+
`Unresolvable internalInputPotential in toolStep '${stepKey}' (${getOwnerLabel(ownerIndex)}): source stepKey '${producerStepKey}' not found in strategy steps`
|
|
83
80
|
);
|
|
84
81
|
}
|
|
85
82
|
|
|
@@ -4,8 +4,8 @@ import { toExecutionMutableStrategy } from './strategyThreading.js';
|
|
|
4
4
|
import { mutableStrategyToStrategy } from './strategyCanonicalization.js';
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
export function composeStrategyForExecution
|
|
8
|
-
mutableStrategy: MutableStrategy
|
|
7
|
+
export function composeStrategyForExecution(
|
|
8
|
+
mutableStrategy: MutableStrategy,
|
|
9
9
|
): Strategy {
|
|
10
10
|
const executionStrategy =
|
|
11
11
|
toExecutionMutableStrategy(mutableStrategy);
|