@toolproof-core/lib 1.0.32 → 1.0.34

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.
Files changed (75) hide show
  1. package/dist/artifacts/artifacts.d.ts +53 -53
  2. package/dist/artifacts/artifacts.d.ts.map +1 -1
  3. package/dist/artifacts/artifacts.js +2 -2
  4. package/dist/artifacts/artifacts.js.map +1 -1
  5. package/dist/integrations/firebase/createThreadedStrategy.d.ts +3 -0
  6. package/dist/integrations/firebase/createThreadedStrategy.d.ts.map +1 -0
  7. package/dist/integrations/firebase/createThreadedStrategy.js +9 -0
  8. package/dist/integrations/firebase/createThreadedStrategy.js.map +1 -0
  9. package/dist/integrations/firebase/firebaseAdminHelpers.d.ts +5 -1
  10. package/dist/integrations/firebase/firebaseAdminHelpers.d.ts.map +1 -1
  11. package/dist/integrations/firebase/firebaseAdminHelpers.js +15 -12
  12. package/dist/integrations/firebase/firebaseAdminHelpers.js.map +1 -1
  13. package/dist/types/types.d.ts +3 -1
  14. package/dist/types/types.d.ts.map +1 -1
  15. package/dist/utils/bindInputRoleToResource.d.ts +5 -4
  16. package/dist/utils/bindInputRoleToResource.d.ts.map +1 -1
  17. package/dist/utils/bindInputRoleToResource.js +15 -65
  18. package/dist/utils/bindInputRoleToResource.js.map +1 -1
  19. package/dist/utils/creation/resourceCreation.d.ts +19 -7
  20. package/dist/utils/creation/resourceCreation.d.ts.map +1 -1
  21. package/dist/utils/creation/resourceCreation.js +16 -12
  22. package/dist/utils/creation/resourceCreation.js.map +1 -1
  23. package/dist/utils/creation/stepCreation.d.ts +22 -5
  24. package/dist/utils/creation/stepCreation.d.ts.map +1 -1
  25. package/dist/utils/creation/stepCreation.js +3 -2
  26. package/dist/utils/creation/stepCreation.js.map +1 -1
  27. package/dist/utils/creation/threadedStrategyCreation.d.ts +19 -0
  28. package/dist/utils/creation/threadedStrategyCreation.d.ts.map +1 -0
  29. package/dist/utils/creation/threadedStrategyCreation.js +17 -0
  30. package/dist/utils/creation/threadedStrategyCreation.js.map +1 -0
  31. package/dist/utils/extractData.d.ts +5 -4
  32. package/dist/utils/extractData.d.ts.map +1 -1
  33. package/dist/utils/extractData.js +12 -54
  34. package/dist/utils/extractData.js.map +1 -1
  35. package/dist/utils/parallelizeSteps.d.ts +2 -1
  36. package/dist/utils/parallelizeSteps.d.ts.map +1 -1
  37. package/dist/utils/parallelizeSteps.js +17 -10
  38. package/dist/utils/parallelizeSteps.js.map +1 -1
  39. package/dist/utils/resolveResourceChain.d.ts +6 -10
  40. package/dist/utils/resolveResourceChain.d.ts.map +1 -1
  41. package/dist/utils/resolveResourceChain.js +12 -20
  42. package/dist/utils/resolveResourceChain.js.map +1 -1
  43. package/dist/utils/roleSpec.d.ts +17 -0
  44. package/dist/utils/roleSpec.d.ts.map +1 -0
  45. package/dist/utils/roleSpec.js +58 -0
  46. package/dist/utils/roleSpec.js.map +1 -0
  47. package/dist/utils/strategyState.d.ts +8 -0
  48. package/dist/utils/strategyState.d.ts.map +1 -0
  49. package/dist/utils/strategyState.js +29 -0
  50. package/dist/utils/strategyState.js.map +1 -0
  51. package/package.json +6 -6
  52. package/src/artifacts/artifacts.ts +2 -2
  53. package/src/integrations/firebase/createThreadedStrategy.ts +19 -0
  54. package/src/integrations/firebase/firebaseAdminHelpers.ts +23 -13
  55. package/src/types/types.ts +1 -1
  56. package/src/utils/bindInputRoleToResource.ts +33 -89
  57. package/src/utils/creation/resourceCreation.ts +40 -22
  58. package/src/utils/creation/stepCreation.ts +23 -17
  59. package/src/utils/creation/threadedStrategyCreation.ts +42 -0
  60. package/src/utils/extractData.ts +25 -67
  61. package/src/utils/parallelizeSteps.ts +24 -15
  62. package/src/utils/resolveResourceChain.ts +18 -32
  63. package/src/utils/roleSpec.ts +84 -0
  64. package/src/utils/strategyState.ts +57 -0
  65. package/tsconfig.tsbuildinfo +1 -1
  66. package/dist/integrations/firebase/createRunnableStrategy.d.ts +0 -3
  67. package/dist/integrations/firebase/createRunnableStrategy.d.ts.map +0 -1
  68. package/dist/integrations/firebase/createRunnableStrategy.js +0 -10
  69. package/dist/integrations/firebase/createRunnableStrategy.js.map +0 -1
  70. package/dist/utils/creation/runnableStrategyCreation.d.ts +0 -4
  71. package/dist/utils/creation/runnableStrategyCreation.d.ts.map +0 -1
  72. package/dist/utils/creation/runnableStrategyCreation.js +0 -23
  73. package/dist/utils/creation/runnableStrategyCreation.js.map +0 -1
  74. package/src/integrations/firebase/createRunnableStrategy.ts +0 -20
  75. package/src/utils/creation/runnableStrategyCreation.ts +0 -42
@@ -1,21 +1,26 @@
1
1
  import type {
2
- RawStrategy,
2
+ RoleName,
3
+ RoleValue,
3
4
  ToolId,
4
5
  Tool,
5
- ToolStepId,
6
6
  ToolStep,
7
- Step,
8
- ResourceRoleId,
9
- ResourceRole,
10
7
  ResourceId,
11
8
  ResourceTypeId,
12
9
  Resource,
13
10
  } from '@toolproof-core/schema';
14
11
  import { CONSTANTS } from '../artifacts/artifacts.js';
15
-
16
-
17
- export function extractToolIdsFromRawStrategy(rawStrategy: RawStrategy): ToolId[] {
18
- const toolSteps = extractToolStepsFromRawStrategy(rawStrategy);
12
+ import {
13
+ extractToolStepsFromStrategy,
14
+ getInputRoleEntries,
15
+ getOutputRoleEntries,
16
+ toToolRoleDescriptor,
17
+ type StrategyStepGraph,
18
+ type ToolRoleDescriptor,
19
+ } from './roleSpec.js';
20
+
21
+
22
+ export function extractToolIdsFromUnthreadedStrategy(unthreadedStrategy: StrategyStepGraph): ToolId[] {
23
+ const toolSteps = extractToolStepsFromUnthreadedStrategy(unthreadedStrategy);
19
24
  const ids = new Set<ToolId>();
20
25
  for (const jStep of toolSteps) {
21
26
  ids.add(jStep.toolId);
@@ -23,71 +28,24 @@ export function extractToolIdsFromRawStrategy(rawStrategy: RawStrategy): ToolId[
23
28
  return Array.from(ids);
24
29
  }
25
30
 
26
- export function extractToolStepsFromRawStrategy(rawStrategy: RawStrategy): ToolStep[] {
27
- const toolSteps: ToolStep[] = [];
28
- const seen = new Set<ToolStepId>();
29
-
30
- const addToolStep = (toolStep: ToolStep) => {
31
- if (seen.has(toolStep.id)) {
32
- throw new Error(`Duplicate tool step id encountered: ${toolStep.id}`);
33
- }
34
- seen.add(toolStep.id);
35
- toolSteps.push(toolStep);
36
- };
37
-
38
- const visitStep = (step: Step) => {
39
- switch (step.stepKind) {
40
- case CONSTANTS.Enums.StepKind.tool: {
41
- addToolStep(step);
42
- return;
43
- }
44
- case CONSTANTS.Enums.StepKind.branch: {
45
- for (const conditional of step.cases) {
46
- addToolStep(conditional.when);
47
- addToolStep(conditional.what);
48
- }
49
- return;
50
- }
51
- case CONSTANTS.Enums.StepKind.while:
52
- case CONSTANTS.Enums.StepKind.for: {
53
- addToolStep(step.case.when);
54
- addToolStep(step.case.what);
55
- return;
56
- }
57
- default: {
58
- const _exhaustive: never = step;
59
- return _exhaustive;
60
- }
61
- }
62
- };
63
-
64
- for (const step of rawStrategy.steps) {
65
- visitStep(step);
66
- }
67
-
68
- return toolSteps;
31
+ export function extractToolStepsFromUnthreadedStrategy(unthreadedStrategy: StrategyStepGraph): ToolStep[] {
32
+ return extractToolStepsFromStrategy(unthreadedStrategy);
69
33
  }
70
34
 
71
35
 
72
- export function extractRoleMapFromRawStrategy(rawStrategy: RawStrategy, toolMap: Map<ToolId, Tool>): Map<ResourceRoleId, ResourceRole> {
73
- const roleMap = new Map<ResourceRoleId, ResourceRole>();
74
- const toolIds = extractToolIdsFromRawStrategy(rawStrategy);
36
+ export function extractRoleMapFromUnthreadedStrategy(unthreadedStrategy: StrategyStepGraph, toolMap: Map<ToolId, Tool>): Map<RoleName, ToolRoleDescriptor> {
37
+ const roleMap = new Map<RoleName, ToolRoleDescriptor>();
38
+ const toolIds = extractToolIdsFromUnthreadedStrategy(unthreadedStrategy);
75
39
 
76
40
  for (const toolId of toolIds) {
77
41
  const tool = toolMap.get(toolId);
78
42
  if (!tool) continue;
79
43
 
80
- for (const [rid, role] of Object.entries(tool.roleSpec.inputRoleValueById)) {
81
- roleMap.set(rid as ResourceRoleId, {
82
- id: rid as ResourceRoleId,
83
- ...role,
84
- });
44
+ for (const entry of getInputRoleEntries(tool)) {
45
+ roleMap.set(entry[0], toToolRoleDescriptor(entry));
85
46
  }
86
- for (const [rid, role] of Object.entries(tool.roleSpec.outputRoleValueById)) {
87
- roleMap.set(rid as ResourceRoleId, {
88
- id: rid as ResourceRoleId,
89
- ...role,
90
- });
47
+ for (const entry of getOutputRoleEntries(tool)) {
48
+ roleMap.set(entry[0], toToolRoleDescriptor(entry));
91
49
  }
92
50
  }
93
51
 
@@ -96,11 +54,11 @@ export function extractRoleMapFromRawStrategy(rawStrategy: RawStrategy, toolMap:
96
54
 
97
55
  export function extractSingleNonErrorOutputTypeId(tool: Tool): ResourceTypeId | null {
98
56
  const errorRoleId = CONSTANTS.Cosmos.ROLE_ErrorOutput;
99
- const outputEntries = Object.entries(tool.roleSpec.outputRoleValueById).filter(([roleId]) => roleId !== errorRoleId);
57
+ const outputEntries = getOutputRoleEntries(tool).filter(([roleName]) => roleName !== errorRoleId);
100
58
  if (!outputEntries || !outputEntries[0] || outputEntries.length !== 1) {
101
59
  throw new Error(`Tool ${tool.id} must have exactly one non-error output role to be branchable/loopable`);
102
60
  } // ATTENTION_PUREIFY
103
- const outputRole = outputEntries[0][1];
61
+ const outputRole = outputEntries[0][1] as RoleValue;
104
62
  return outputRole.resourceTypeId;
105
63
  }
106
64
 
@@ -1,14 +1,20 @@
1
1
  import type {
2
2
  BranchStep,
3
3
  ForStep,
4
- ToolStepId,
5
4
  ToolStep,
6
- ResourceRoleId,
7
5
  Step,
8
- StrategyState,
9
6
  WhileStep,
10
7
  } from '@toolproof-core/schema';
11
8
  import { CONSTANTS } from '../artifacts/artifacts.js';
9
+ import type { StrategyState } from './strategyState.js';
10
+
11
+ type ToolStepId = string;
12
+ type ToolStepWithId = ToolStep & { id: ToolStepId };
13
+
14
+ function getToolStepId(toolStep: ToolStep | undefined): ToolStepId | undefined {
15
+ const maybeId = (toolStep as Partial<ToolStepWithId> | undefined)?.id;
16
+ return typeof maybeId === 'string' ? maybeId : undefined;
17
+ }
12
18
 
13
19
 
14
20
  export function getIndependentThreads(steps: Step[], strategyState: StrategyState): Step[][] {
@@ -22,22 +28,23 @@ export function getIndependentThreads(steps: Step[], strategyState: StrategyStat
22
28
  // Map each toolStep.id (including macro-nested tool steps) to owning top-level step index.
23
29
  const toolStepIdToOwner = new Map<ToolStepId, OwnerIndex>();
24
30
  const ownerToToolStepIds = new Map<OwnerIndex, ToolStepId[]>();
25
- const toolStepById = new Map<ToolStepId, ToolStep>();
31
+ const toolStepById = new Map<ToolStepId, ToolStepWithId>();
26
32
 
27
33
  const addToolStep = (toolStep: ToolStep | undefined, ownerIndex: OwnerIndex) => {
28
- if (!toolStep?.id) return;
34
+ const toolStepId = getToolStepId(toolStep);
35
+ if (!toolStepId || !toolStep) return;
29
36
 
30
- const existingOwner = toolStepIdToOwner.get(toolStep.id);
37
+ const existingOwner = toolStepIdToOwner.get(toolStepId);
31
38
  if (existingOwner !== undefined) {
32
39
  throw new Error(
33
- `Duplicate toolStep.id '${toolStep.id}' found in ${getOwnerLabel(ownerIndex)} and ${getOwnerLabel(existingOwner)}`
40
+ `Duplicate toolStep.id '${toolStepId}' found in ${getOwnerLabel(ownerIndex)} and ${getOwnerLabel(existingOwner)}`
34
41
  );
35
42
  }
36
43
 
37
- toolStepIdToOwner.set(toolStep.id, ownerIndex);
38
- toolStepById.set(toolStep.id, toolStep);
44
+ toolStepIdToOwner.set(toolStepId, ownerIndex);
45
+ toolStepById.set(toolStepId, toolStep as ToolStepWithId);
39
46
  const bucket = ownerToToolStepIds.get(ownerIndex) ?? [];
40
- bucket.push(toolStep.id);
47
+ bucket.push(toolStepId);
41
48
  ownerToToolStepIds.set(ownerIndex, bucket);
42
49
  };
43
50
 
@@ -94,20 +101,22 @@ export function getIndependentThreads(steps: Step[], strategyState: StrategyStat
94
101
  const bucket = strategyState?.[toolStepId] ?? ({} as any);
95
102
 
96
103
  for (const inputRoleId of inputBindings) {
97
- const entry = bucket?.[inputRoleId as ResourceRoleId] as any;
98
- if (!entry || entry.resourceShellKind !== 'internalInputPotential') continue;
104
+ const entry = bucket?.[inputRoleId] as any;
105
+ if (!entry || entry.strategyStateInputKind !== 'referenceInput') continue;
99
106
 
100
- const creatorToolStepId = entry?.creationContext?.toolStepId as ToolStepId | undefined;
107
+ const creatorToolStepId = typeof entry?.toolStepPath === 'string'
108
+ ? entry.toolStepPath as ToolStepId
109
+ : undefined;
101
110
  if (!creatorToolStepId) {
102
111
  throw new Error(
103
- `Unresolvable internalInputPotential in toolStep '${toolStepId}' (${getOwnerLabel(ownerIndex)}): missing creationContext.toolStepId for role '${inputRoleId}'`
112
+ `Unresolvable referenceInput in toolStep '${toolStepId}' (${getOwnerLabel(ownerIndex)}): missing toolStepPath for role '${inputRoleId}'`
104
113
  );
105
114
  }
106
115
 
107
116
  const producerOwner = toolStepIdToOwner.get(creatorToolStepId);
108
117
  if (producerOwner === undefined) {
109
118
  throw new Error(
110
- `Unresolvable internalInputPotential in toolStep '${toolStepId}' (${getOwnerLabel(ownerIndex)}): creator toolStepId '${creatorToolStepId}' not found in strategy steps`
119
+ `Unresolvable referenceInput in toolStep '${toolStepId}' (${getOwnerLabel(ownerIndex)}): creator toolStepPath '${creatorToolStepId}' not found in strategy steps`
111
120
  );
112
121
  }
113
122
 
@@ -1,18 +1,15 @@
1
1
  import type {
2
2
  CreationContext,
3
- ExternalInputPotentialShell,
4
- InternalInputPotentialShell,
5
- OutputPotentialShell,
6
- Resource,
7
- ResourcePotential,
8
- StrategyState,
3
+ ExternalInput,
4
+ ReferenceInput,
5
+ StrategyStateInputEntry,
6
+ ValueInput,
9
7
  } from '@toolproof-core/schema';
10
- import { CONSTANTS } from '../artifacts/artifacts.js';
8
+ import { getStrategyStateEntry, type StrategyState } from './strategyState.js';
11
9
 
12
10
  export type ResolveResult =
13
- | { status: typeof CONSTANTS.Enums.ResourceShellKind.materialized; entry: Resource; path: CreationContext[] }
14
- | { status: typeof CONSTANTS.Enums.ResourceShellKind.externalInputPotential; entry: ExternalInputPotentialShell; path: CreationContext[] }
15
- | { status: typeof CONSTANTS.Enums.ResourceShellKind.outputPotential; entry: OutputPotentialShell; path: CreationContext[] }
11
+ | { status: 'valueInput'; entry: ValueInput; path: CreationContext[] }
12
+ | { status: 'externalInput'; entry: ExternalInput; path: CreationContext[] }
16
13
  | { status: 'unresolved'; reason: 'not-found' | 'cycle' | 'depth-exceeded'; path: CreationContext[] };
17
14
 
18
15
  export function resolveResourceChain(
@@ -27,39 +24,28 @@ export function resolveResourceChain(
27
24
 
28
25
  for (let depth = 0; depth <= maxDepth; depth++) {
29
26
  path.push(current);
30
- const visitKey = `${current.toolStepId}::${current.resourceRoleId}`;
27
+ const visitKey = `${current.toolStepPath}::${current.roleName}`;
31
28
  if (visited.has(visitKey)) {
32
29
  return { status: 'unresolved', reason: 'cycle', path };
33
30
  }
34
31
  visited.add(visitKey);
35
32
 
36
- const bucket = strategyState[current.toolStepId];
37
- if (!bucket) return { status: 'unresolved', reason: 'not-found', path };
38
- const entry = bucket[current.resourceRoleId] as (
39
- | Resource
40
- | ResourcePotential
41
- | undefined
42
- );
33
+ const entry = getStrategyStateEntry(strategyState, current) as StrategyStateInputEntry | undefined;
43
34
  if (!entry) return { status: 'unresolved', reason: 'not-found', path };
44
35
 
45
- if (entry.resourceShellKind === CONSTANTS.Enums.ResourceShellKind.materialized) {
46
- return { status: CONSTANTS.Enums.ResourceShellKind.materialized, entry: entry as Resource, path };
36
+ if (entry.strategyStateInputKind === 'valueInput') {
37
+ return { status: 'valueInput', entry: entry, path };
47
38
  }
48
- if (entry.resourceShellKind === CONSTANTS.Enums.ResourceShellKind.externalInputPotential) {
49
- return { status: CONSTANTS.Enums.ResourceShellKind.externalInputPotential, entry: entry as ExternalInputPotentialShell, path };
50
- }
51
- if (entry.resourceShellKind === CONSTANTS.Enums.ResourceShellKind.outputPotential) {
52
- return { status: CONSTANTS.Enums.ResourceShellKind.outputPotential, entry: entry as OutputPotentialShell, path };
39
+ if (entry.strategyStateInputKind === 'externalInput') {
40
+ return { status: 'externalInput', entry: entry, path };
53
41
  }
54
42
 
55
- // internalInputPotential: follow ref backwards
56
- if (entry.resourceShellKind === CONSTANTS.Enums.ResourceShellKind.internalInputPotential) {
57
- current = (entry as InternalInputPotentialShell).creationContext;
58
- continue;
59
- }
43
+ current = {
44
+ toolStepPath: (entry as ReferenceInput).toolStepPath,
45
+ roleName: (entry as ReferenceInput).roleName,
46
+ };
47
+ continue;
60
48
 
61
- // Unknown case
62
- return { status: 'unresolved', reason: 'not-found', path };
63
49
  }
64
50
 
65
51
  return { status: 'unresolved', reason: 'depth-exceeded', path };
@@ -0,0 +1,84 @@
1
+ import type {
2
+ RoleName,
3
+ RoleValue,
4
+ Step,
5
+ StepArrayArray,
6
+ Tool,
7
+ ToolStep,
8
+ } from '@toolproof-core/schema';
9
+
10
+ export type StrategyStepGraph =
11
+ | { steps: Step[] }
12
+ | { stepsByThreadIndex: StepArrayArray };
13
+
14
+ export interface ToolRoleDescriptor extends RoleValue {
15
+ id: RoleName;
16
+ name: string;
17
+ }
18
+
19
+ export function getInputRoleEntries(tool: Tool): Array<[RoleName, RoleValue]> {
20
+ return Object.entries(tool.roleSpec.inputRoleValueByName) as Array<[RoleName, RoleValue]>;
21
+ }
22
+
23
+ export function getOutputRoleEntries(tool: Tool): Array<[RoleName, RoleValue]> {
24
+ return Object.entries(tool.roleSpec.outputRoleValueByName) as Array<[RoleName, RoleValue]>;
25
+ }
26
+
27
+ export function getInputRoleNames(tool: Tool): RoleName[] {
28
+ return getInputRoleEntries(tool).map(([roleName]) => roleName);
29
+ }
30
+
31
+ export function getOutputRoleNames(tool: Tool): RoleName[] {
32
+ return getOutputRoleEntries(tool).map(([roleName]) => roleName);
33
+ }
34
+
35
+ export function toToolRoleDescriptor([roleName, roleValue]: [RoleName, RoleValue]): ToolRoleDescriptor {
36
+ return {
37
+ id: roleName,
38
+ name: roleName,
39
+ ...roleValue,
40
+ };
41
+ }
42
+
43
+ export function extractToolStepsFromStrategy(strategy: StrategyStepGraph): ToolStep[] {
44
+ const toolSteps: ToolStep[] = [];
45
+
46
+ const visitStep = (step: Step) => {
47
+ switch (step.stepKind) {
48
+ case 'tool': {
49
+ toolSteps.push(step);
50
+ return;
51
+ }
52
+ case 'branch': {
53
+ for (const conditional of step.cases) {
54
+ toolSteps.push(conditional.when, conditional.what);
55
+ }
56
+ return;
57
+ }
58
+ case 'while':
59
+ case 'for': {
60
+ toolSteps.push(step.case.when, step.case.what);
61
+ return;
62
+ }
63
+ default: {
64
+ const _exhaustive: never = step;
65
+ return _exhaustive;
66
+ }
67
+ }
68
+ };
69
+
70
+ if ('steps' in strategy) {
71
+ for (const step of strategy.steps) {
72
+ visitStep(step);
73
+ }
74
+ return toolSteps;
75
+ }
76
+
77
+ for (const threadSteps of strategy.stepsByThreadIndex) {
78
+ for (const step of threadSteps) {
79
+ visitStep(step);
80
+ }
81
+ }
82
+
83
+ return toolSteps;
84
+ }
@@ -0,0 +1,57 @@
1
+ import type {
2
+ CreationContext,
3
+ Strategy,
4
+ StrategyStateInputEntry,
5
+ StrategyStateInputEntryByRoleName,
6
+ } from '@toolproof-core/schema';
7
+
8
+ export type StrategyState = Strategy['strategyState'];
9
+ export type StrategyStateLike = Record<string, Record<string, unknown>>;
10
+
11
+ export function getStrategyStateBucket(
12
+ strategyState: StrategyStateLike,
13
+ toolStepPath: CreationContext['toolStepPath'],
14
+ ): StrategyStateInputEntryByRoleName | undefined {
15
+ return strategyState[toolStepPath] as StrategyStateInputEntryByRoleName | undefined;
16
+ }
17
+
18
+ export function getStrategyStateEntry(
19
+ strategyState: StrategyStateLike,
20
+ context: CreationContext,
21
+ ): StrategyStateInputEntry | undefined {
22
+ return getStrategyStateBucket(strategyState, context.toolStepPath)?.[context.roleName];
23
+ }
24
+
25
+ export function setStrategyStateEntry<TStrategyState extends StrategyStateLike>(
26
+ strategyState: TStrategyState,
27
+ context: CreationContext,
28
+ entry: StrategyStateInputEntry,
29
+ ): TStrategyState {
30
+ const bucket = getStrategyStateBucket(strategyState, context.toolStepPath) ?? {};
31
+
32
+ return {
33
+ ...strategyState,
34
+ [context.toolStepPath]: {
35
+ ...bucket,
36
+ [context.roleName]: entry,
37
+ },
38
+ } as TStrategyState;
39
+ }
40
+
41
+ export function clearStrategyStateEntry<TStrategyState extends StrategyStateLike>(
42
+ strategyState: TStrategyState,
43
+ context: CreationContext,
44
+ ): TStrategyState {
45
+ const bucket = getStrategyStateBucket(strategyState, context.toolStepPath);
46
+ if (!bucket || !(context.roleName in bucket)) {
47
+ return strategyState;
48
+ }
49
+
50
+ const nextBucket = { ...bucket };
51
+ delete nextBucket[context.roleName];
52
+
53
+ return {
54
+ ...strategyState,
55
+ [context.toolStepPath]: nextBucket,
56
+ } as TStrategyState;
57
+ }