@toolproof-core/lib 1.0.48 → 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.
@@ -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, toolStepKey: _whenToolStepKey, ...canonicalWhen } = when;
35
- const { stepKey: _whatStepKey, toolStepKey: _whatToolStepKey, ...canonicalWhat } = what;
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.toolStepKey, `${pathPrefix}/self` as ToolStepPath);
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.toolStepKey, `${pathPrefix}/cases/${caseIndex}/when` as ToolStepPath);
55
- executionPathByKey.set(stepCase.what.toolStepKey, `${pathPrefix}/cases/${caseIndex}/what` as ToolStepPath);
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.toolStepKey, `${pathPrefix}/case/when` as ToolStepPath);
61
- executionPathByKey.set(step.case.what.toolStepKey, `${pathPrefix}/case/what` as ToolStepPath);
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.toolStepKey);
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 toolStepKey '${entry.toolStepRoleAddress.toolStepKey}'.`);
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,7 +99,7 @@ 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, toolStepKey: _toolStepKey, ...canonicalToolStep } = step;
102
+ const { stepKey: _stepKey, ...canonicalToolStep } = step;
103
103
  return canonicalToolStep;
104
104
  }
105
105
  case CONSTANTS.Enums.StepKind.branch: {
@@ -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
 
@@ -219,8 +217,8 @@ function buildExecutionKeyMap(strategy: MutableStrategy): Map<ToolStepPath, Muta
219
217
  const executionPathByKey = buildExecutionPathMap(strategy);
220
218
  const executionKeyByPath = new Map<ToolStepPath, MutableToolStepKey>();
221
219
 
222
- for (const [toolStepKey, toolStepPath] of executionPathByKey.entries()) {
223
- executionKeyByPath.set(toolStepPath, toolStepKey);
220
+ for (const [stepKey, toolStepPath] of executionPathByKey.entries()) {
221
+ executionKeyByPath.set(toolStepPath, stepKey);
224
222
  }
225
223
 
226
224
  return executionKeyByPath;
@@ -271,21 +269,21 @@ export function mutableStrategyToStrategy(mutableStrategy: MutableStrategy): Str
271
269
  const executionPathByKey = buildExecutionPathMap(mutableStrategy);
272
270
  const strategyState: Strategy['strategyState'] = {};
273
271
 
274
- for (const [toolStepKey, inputEntryByRoleName] of Object.entries(mutableStrategy.strategyState)) {
272
+ for (const [stepKey, inputEntryByRoleName] of Object.entries(mutableStrategy.strategyState)) {
275
273
  if (!inputEntryByRoleName) {
276
274
  continue;
277
275
  }
278
276
 
279
- const toolStepPath = executionPathByKey.get(toolStepKey as MutableToolStepKey);
277
+ const toolStepPath = executionPathByKey.get(stepKey as MutableToolStepKey);
280
278
  if (!toolStepPath) {
281
- throw new Error(`Cannot project strategy state: no execution path found for toolStepKey '${toolStepKey}'.`);
279
+ throw new Error(`Cannot project strategy state: no execution path found for stepKey '${stepKey}'.`);
282
280
  }
283
281
 
284
282
  strategyState[toolStepPath] = Object.fromEntries(
285
283
  Object.entries(inputEntryByRoleName).map(([roleName, entry]) => {
286
284
  if (entry === undefined) {
287
285
  throw new Error(
288
- `Cannot project strategy state: role '${roleName}' on toolStepKey '${toolStepKey}' is explicitly undefined.`
286
+ `Cannot project strategy state: role '${roleName}' on stepKey '${stepKey}' is explicitly undefined.`
289
287
  );
290
288
  }
291
289
 
@@ -304,28 +302,28 @@ export function mutableStrategyToStrategy(mutableStrategy: MutableStrategy): Str
304
302
  };
305
303
  }
306
304
 
307
- export function mutableToolStepKeyToToolStepPath(
305
+ export function mutableStepKeyToToolStepPath(
308
306
  mutableStrategy: MutableStrategy,
309
- toolStepKey: MutableToolStepKey,
307
+ stepKey: MutableToolStepKey,
310
308
  ): ToolStepPath {
311
309
  const executionPathByKey = buildExecutionPathMap(mutableStrategy);
312
- const toolStepPath = executionPathByKey.get(toolStepKey);
310
+ const toolStepPath = executionPathByKey.get(stepKey);
313
311
  if (!toolStepPath) {
314
- throw new Error(`Cannot project toolStepPath: no execution path found for toolStepKey '${toolStepKey}'.`);
312
+ throw new Error(`Cannot project toolStepPath: no execution path found for stepKey '${stepKey}'.`);
315
313
  }
316
314
 
317
315
  return toolStepPath;
318
316
  }
319
317
 
320
- export function projectMutableStrategyStateEntriesByToolStepKeyToCanonicalDelta(
318
+ export function projectMutableStrategyStateEntriesByStepKeyToCanonicalDelta(
321
319
  mutableStrategy: MutableStrategy,
322
- toolStepKey: MutableToolStepKey,
320
+ stepKey: MutableToolStepKey,
323
321
  entries: MutableStrategyStateEntryByRoleName,
324
322
  ): Strategy['strategyState'] {
325
323
  const executionPathByKey = buildExecutionPathMap(mutableStrategy);
326
- const toolStepPath = executionPathByKey.get(toolStepKey);
324
+ const toolStepPath = executionPathByKey.get(stepKey);
327
325
  if (!toolStepPath) {
328
- throw new Error(`Cannot project strategy state delta: no execution path found for toolStepKey '${toolStepKey}'.`);
326
+ throw new Error(`Cannot project strategy state delta: no execution path found for stepKey '${stepKey}'.`);
329
327
  }
330
328
 
331
329
  const canonicalEntries: Strategy['strategyState'][ToolStepPath] = Object.fromEntries(
@@ -334,7 +332,7 @@ export function projectMutableStrategyStateEntriesByToolStepKeyToCanonicalDelta(
334
332
  .map(([roleName, entry]) => {
335
333
  if (entry === undefined) {
336
334
  throw new Error(
337
- `Cannot project strategy state delta: role '${roleName}' on toolStepKey '${toolStepKey}' is explicitly undefined.`
335
+ `Cannot project strategy state delta: role '${roleName}' on stepKey '${stepKey}' is explicitly undefined.`
338
336
  );
339
337
  }
340
338
 
@@ -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.toolStepKey}::${current.roleName}`;
31
+ const visitKey = `${current.stepKey}::${current.roleName}`;
32
32
  if (visited.has(visitKey)) {
33
33
  return { status: 'unresolved', reason: 'cycle', path };
34
34
  }