@toolproof-core/lib 1.0.33 → 1.0.36

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 (90) hide show
  1. package/dist/integrations/firebase/createStep.d.ts +2 -3
  2. package/dist/integrations/firebase/createStep.js +7 -33
  3. package/dist/integrations/firebase/createThreadedStrategy.d.ts +2 -0
  4. package/dist/integrations/firebase/createThreadedStrategy.js +8 -0
  5. package/dist/integrations/firebase/firebaseAdminHelpers.d.ts +4 -10
  6. package/dist/integrations/firebase/firebaseAdminHelpers.js +43 -136
  7. package/dist/integrations/firebase/firebaseAdminInit.d.ts +0 -1
  8. package/dist/integrations/firebase/firebaseAdminInit.js +0 -1
  9. package/dist/lookups/lookups.d.ts +221 -0
  10. package/dist/lookups/lookups.js +23 -0
  11. package/dist/types/types.d.ts +8 -12
  12. package/dist/types/types.js +2 -3
  13. package/dist/utils/creation/resourceCreation.d.ts +18 -18
  14. package/dist/utils/creation/resourceCreation.js +49 -48
  15. package/dist/utils/creation/stepCreation.d.ts +7 -48
  16. package/dist/utils/creation/stepCreation.js +16 -42
  17. package/dist/utils/creation/threadedStrategyCreation.d.ts +18 -0
  18. package/dist/utils/creation/threadedStrategyCreation.js +16 -0
  19. package/dist/utils/extractData.d.ts +9 -10
  20. package/dist/utils/extractData.js +29 -25
  21. package/dist/utils/parallelizeSteps.d.ts +1 -2
  22. package/dist/utils/parallelizeSteps.js +52 -37
  23. package/dist/utils/resolveStrategyStateChain.d.ts +20 -0
  24. package/dist/utils/{resolveResourceChain.js → resolveStrategyStateChain.js} +6 -11
  25. package/dist/utils/roleSpec.d.ts +7 -3
  26. package/dist/utils/roleSpec.js +0 -1
  27. package/dist/utils/strategyState.d.ts +11 -6
  28. package/dist/utils/strategyState.js +41 -12
  29. package/dist/utils_2/threadedStrategyCreation.d.ts +5 -0
  30. package/dist/utils_2/threadedStrategyCreation.js +12 -0
  31. package/package.json +15 -15
  32. package/src/integrations/firebase/createStep.ts +9 -39
  33. package/src/integrations/firebase/createThreadedStrategy.ts +19 -0
  34. package/src/integrations/firebase/firebaseAdminHelpers.ts +61 -163
  35. package/src/lookups/lookups.ts +25 -0
  36. package/src/types/types.ts +9 -12
  37. package/src/utils/creation/resourceCreation.ts +140 -121
  38. package/src/utils/creation/stepCreation.ts +25 -95
  39. package/src/utils/creation/threadedStrategyCreation.ts +42 -0
  40. package/src/utils/extractData.ts +46 -38
  41. package/src/utils/parallelizeSteps.ts +92 -40
  42. package/src/utils/resolveStrategyStateChain.ts +58 -0
  43. package/src/utils/roleSpec.ts +7 -3
  44. package/src/utils/strategyState.ts +99 -27
  45. package/src/utils_2/threadedStrategyCreation.ts +19 -0
  46. package/tsconfig.tsbuildinfo +1 -1
  47. package/dist/artifacts/artifacts.d.ts +0 -175
  48. package/dist/artifacts/artifacts.d.ts.map +0 -1
  49. package/dist/artifacts/artifacts.js +0 -48
  50. package/dist/artifacts/artifacts.js.map +0 -1
  51. package/dist/integrations/firebase/createRunnableStrategy.d.ts +0 -3
  52. package/dist/integrations/firebase/createRunnableStrategy.d.ts.map +0 -1
  53. package/dist/integrations/firebase/createRunnableStrategy.js +0 -9
  54. package/dist/integrations/firebase/createRunnableStrategy.js.map +0 -1
  55. package/dist/integrations/firebase/createStep.d.ts.map +0 -1
  56. package/dist/integrations/firebase/createStep.js.map +0 -1
  57. package/dist/integrations/firebase/firebaseAdminHelpers.d.ts.map +0 -1
  58. package/dist/integrations/firebase/firebaseAdminHelpers.js.map +0 -1
  59. package/dist/integrations/firebase/firebaseAdminInit.d.ts.map +0 -1
  60. package/dist/integrations/firebase/firebaseAdminInit.js.map +0 -1
  61. package/dist/types/types.d.ts.map +0 -1
  62. package/dist/types/types.js.map +0 -1
  63. package/dist/utils/bindInputRoleToResource.d.ts +0 -6
  64. package/dist/utils/bindInputRoleToResource.d.ts.map +0 -1
  65. package/dist/utils/bindInputRoleToResource.js +0 -25
  66. package/dist/utils/bindInputRoleToResource.js.map +0 -1
  67. package/dist/utils/creation/resourceCreation.d.ts.map +0 -1
  68. package/dist/utils/creation/resourceCreation.js.map +0 -1
  69. package/dist/utils/creation/runnableStrategyCreation.d.ts +0 -4
  70. package/dist/utils/creation/runnableStrategyCreation.d.ts.map +0 -1
  71. package/dist/utils/creation/runnableStrategyCreation.js +0 -17
  72. package/dist/utils/creation/runnableStrategyCreation.js.map +0 -1
  73. package/dist/utils/creation/stepCreation.d.ts.map +0 -1
  74. package/dist/utils/creation/stepCreation.js.map +0 -1
  75. package/dist/utils/extractData.d.ts.map +0 -1
  76. package/dist/utils/extractData.js.map +0 -1
  77. package/dist/utils/parallelizeSteps.d.ts.map +0 -1
  78. package/dist/utils/parallelizeSteps.js.map +0 -1
  79. package/dist/utils/resolveResourceChain.d.ts +0 -19
  80. package/dist/utils/resolveResourceChain.d.ts.map +0 -1
  81. package/dist/utils/resolveResourceChain.js.map +0 -1
  82. package/dist/utils/roleSpec.d.ts.map +0 -1
  83. package/dist/utils/roleSpec.js.map +0 -1
  84. package/dist/utils/strategyState.d.ts.map +0 -1
  85. package/dist/utils/strategyState.js.map +0 -1
  86. package/src/artifacts/artifacts.ts +0 -49
  87. package/src/integrations/firebase/createRunnableStrategy.ts +0 -18
  88. package/src/utils/bindInputRoleToResource.ts +0 -53
  89. package/src/utils/creation/runnableStrategyCreation.ts +0 -28
  90. package/src/utils/resolveResourceChain.ts +0 -52
@@ -1,19 +1,44 @@
1
1
  import type {
2
2
  BranchStep,
3
3
  ForStep,
4
+ ToolStepPath,
4
5
  ToolStep,
5
6
  Step,
6
7
  WhileStep,
7
- } from '@toolproof-core/schema';
8
- import { CONSTANTS } from '../artifacts/artifacts.js';
8
+ } from '@toolproof-core/genesis';
9
+ import { CONSTANTS } from '../lookups/lookups.js';
9
10
  import type { StrategyState } from './strategyState.js';
10
11
 
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;
12
+ type ToolStepSlot = 'self' | 'case.when' | 'case.what' | 'cases.when' | 'cases.what';
13
+
14
+ function toUnthreadedToolStepPath(opts: {
15
+ stepIndex: number;
16
+ toolStepSlot: ToolStepSlot;
17
+ caseIndex?: number;
18
+ }): ToolStepPath {
19
+ const base = `/steps/${opts.stepIndex}`;
20
+ switch (opts.toolStepSlot) {
21
+ case 'self':
22
+ return `${base}/self` as ToolStepPath;
23
+ case 'case.when':
24
+ return `${base}/case/when` as ToolStepPath;
25
+ case 'case.what':
26
+ return `${base}/case/what` as ToolStepPath;
27
+ case 'cases.when':
28
+ if (typeof opts.caseIndex !== 'number') {
29
+ throw new Error('Expected caseIndex for cases.when path');
30
+ }
31
+ return `${base}/cases/${opts.caseIndex}/when` as ToolStepPath;
32
+ case 'cases.what':
33
+ if (typeof opts.caseIndex !== 'number') {
34
+ throw new Error('Expected caseIndex for cases.what path');
35
+ }
36
+ return `${base}/cases/${opts.caseIndex}/what` as ToolStepPath;
37
+ default: {
38
+ const _exhaustive: never = opts.toolStepSlot;
39
+ return _exhaustive;
40
+ }
41
+ }
17
42
  }
18
43
 
19
44
 
@@ -25,54 +50,81 @@ export function getIndependentThreads(steps: Step[], strategyState: StrategyStat
25
50
  return `steps[${ownerIndex}] stepKind=${(step as any)?.stepKind ?? 'unknown'}`;
26
51
  };
27
52
 
28
- // Map each toolStep.id (including macro-nested tool steps) to owning top-level step index.
29
- const toolStepIdToOwner = new Map<ToolStepId, OwnerIndex>();
30
- const ownerToToolStepIds = new Map<OwnerIndex, ToolStepId[]>();
31
- const toolStepById = new Map<ToolStepId, ToolStepWithId>();
53
+ // Map each canonical toolStepPath (including macro-nested tool steps) to its owning top-level step index.
54
+ const toolStepPathToOwner = new Map<ToolStepPath, OwnerIndex>();
55
+ const toolStepByPath = new Map<ToolStepPath, ToolStep>();
32
56
 
33
- const addToolStep = (toolStep: ToolStep | undefined, ownerIndex: OwnerIndex) => {
34
- const toolStepId = getToolStepId(toolStep);
35
- if (!toolStepId || !toolStep) return;
57
+ const addToolStep = (
58
+ toolStep: ToolStep | undefined,
59
+ ownerIndex: OwnerIndex,
60
+ toolStepPath: ToolStepPath,
61
+ ) => {
62
+ if (!toolStep) return;
36
63
 
37
- const existingOwner = toolStepIdToOwner.get(toolStepId);
64
+ const existingOwner = toolStepPathToOwner.get(toolStepPath);
38
65
  if (existingOwner !== undefined) {
39
66
  throw new Error(
40
- `Duplicate toolStep.id '${toolStepId}' found in ${getOwnerLabel(ownerIndex)} and ${getOwnerLabel(existingOwner)}`
67
+ `Duplicate toolStepPath '${toolStepPath}' found in ${getOwnerLabel(ownerIndex)} and ${getOwnerLabel(existingOwner)}`
41
68
  );
42
69
  }
43
70
 
44
- toolStepIdToOwner.set(toolStepId, ownerIndex);
45
- toolStepById.set(toolStepId, toolStep as ToolStepWithId);
46
- const bucket = ownerToToolStepIds.get(ownerIndex) ?? [];
47
- bucket.push(toolStepId);
48
- ownerToToolStepIds.set(ownerIndex, bucket);
71
+ toolStepPathToOwner.set(toolStepPath, ownerIndex);
72
+ toolStepByPath.set(toolStepPath, toolStep);
49
73
  };
50
74
 
51
75
  steps.forEach((step, ownerIndex) => {
52
76
  if (step.stepKind === CONSTANTS.Enums.StepKind.tool) {
53
- addToolStep(step as ToolStep, ownerIndex);
77
+ addToolStep(
78
+ step as ToolStep,
79
+ ownerIndex,
80
+ toUnthreadedToolStepPath({ stepIndex: ownerIndex, toolStepSlot: 'self' }),
81
+ );
54
82
  return;
55
83
  }
56
84
 
57
85
  if (step.stepKind === CONSTANTS.Enums.StepKind.for) {
58
86
  const loop = step as ForStep;
59
- addToolStep(loop.case?.what, ownerIndex);
60
- addToolStep(loop.case?.when, ownerIndex);
87
+ addToolStep(
88
+ loop.case?.what,
89
+ ownerIndex,
90
+ toUnthreadedToolStepPath({ stepIndex: ownerIndex, toolStepSlot: 'case.what' }),
91
+ );
92
+ addToolStep(
93
+ loop.case?.when,
94
+ ownerIndex,
95
+ toUnthreadedToolStepPath({ stepIndex: ownerIndex, toolStepSlot: 'case.when' }),
96
+ );
61
97
  return;
62
98
  }
63
99
 
64
100
  if (step.stepKind === CONSTANTS.Enums.StepKind.while) {
65
101
  const loop = step as WhileStep;
66
- addToolStep(loop.case?.what, ownerIndex);
67
- addToolStep(loop.case?.when, ownerIndex);
102
+ addToolStep(
103
+ loop.case?.what,
104
+ ownerIndex,
105
+ toUnthreadedToolStepPath({ stepIndex: ownerIndex, toolStepSlot: 'case.what' }),
106
+ );
107
+ addToolStep(
108
+ loop.case?.when,
109
+ ownerIndex,
110
+ toUnthreadedToolStepPath({ stepIndex: ownerIndex, toolStepSlot: 'case.when' }),
111
+ );
68
112
  return;
69
113
  }
70
114
 
71
115
  if (step.stepKind === CONSTANTS.Enums.StepKind.branch) {
72
116
  const branch = step as BranchStep;
73
- for (const caseItem of branch.cases ?? []) {
74
- addToolStep(caseItem?.what, ownerIndex);
75
- addToolStep(caseItem?.when, ownerIndex);
117
+ for (const [caseIndex, caseItem] of (branch.cases ?? []).entries()) {
118
+ addToolStep(
119
+ caseItem?.what,
120
+ ownerIndex,
121
+ toUnthreadedToolStepPath({ stepIndex: ownerIndex, toolStepSlot: 'cases.what', caseIndex }),
122
+ );
123
+ addToolStep(
124
+ caseItem?.when,
125
+ ownerIndex,
126
+ toUnthreadedToolStepPath({ stepIndex: ownerIndex, toolStepSlot: 'cases.when', caseIndex }),
127
+ );
76
128
  }
77
129
  return;
78
130
  }
@@ -93,30 +145,30 @@ export function getIndependentThreads(steps: Step[], strategyState: StrategyStat
93
145
  }
94
146
 
95
147
  // Discover dependencies from strategyState.
96
- for (const [toolStepId, ownerIndex] of toolStepIdToOwner) {
148
+ for (const [toolStepPath, ownerIndex] of toolStepPathToOwner) {
97
149
  ensureOwner(ownerIndex);
98
150
 
99
- const toolStep = toolStepById.get(toolStepId);
151
+ const toolStep = toolStepByPath.get(toolStepPath);
100
152
  const inputBindings = toolStep?.roleBindingSpec?.inputBindings ?? [];
101
- const bucket = strategyState?.[toolStepId] ?? ({} as any);
153
+ const bucket = strategyState?.[toolStepPath] ?? ({} as any);
102
154
 
103
155
  for (const inputRoleId of inputBindings) {
104
156
  const entry = bucket?.[inputRoleId] as any;
105
- if (!entry || entry.strategyStateInputKind !== 'referenceInput') continue;
157
+ if (!entry || entry.strategyStateInputKind !== 'internalInputPotential') continue;
106
158
 
107
- const creatorToolStepId = typeof entry?.toolStepPath === 'string'
108
- ? entry.toolStepPath as ToolStepId
159
+ const creatorToolStepPath = typeof entry?.toolStepRoleAddress?.toolStepPath === 'string'
160
+ ? entry.toolStepRoleAddress.toolStepPath as ToolStepPath
109
161
  : undefined;
110
- if (!creatorToolStepId) {
162
+ if (!creatorToolStepPath) {
111
163
  throw new Error(
112
- `Unresolvable referenceInput in toolStep '${toolStepId}' (${getOwnerLabel(ownerIndex)}): missing toolStepPath for role '${inputRoleId}'`
164
+ `Unresolvable internalInputPotential in toolStep '${toolStepPath}' (${getOwnerLabel(ownerIndex)}): missing toolStepRoleAddress.toolStepPath for role '${inputRoleId}'`
113
165
  );
114
166
  }
115
167
 
116
- const producerOwner = toolStepIdToOwner.get(creatorToolStepId);
168
+ const producerOwner = toolStepPathToOwner.get(creatorToolStepPath);
117
169
  if (producerOwner === undefined) {
118
170
  throw new Error(
119
- `Unresolvable referenceInput in toolStep '${toolStepId}' (${getOwnerLabel(ownerIndex)}): creator toolStepPath '${creatorToolStepId}' not found in strategy steps`
171
+ `Unresolvable internalInputPotential in toolStep '${toolStepPath}' (${getOwnerLabel(ownerIndex)}): source toolStepPath '${creatorToolStepPath}' not found in strategy steps`
120
172
  );
121
173
  }
122
174
 
@@ -0,0 +1,58 @@
1
+ import type {
2
+ ToolStepRoleAddress,
3
+ ExternalInputPotential,
4
+ InputResource,
5
+ InternalInputPotential,
6
+ StrategyStateInputEntry,
7
+ ThreadedStrategyState,
8
+ ThreadedToolStepRoleAddress,
9
+ UnthreadedStrategyState,
10
+ UnthreadedToolStepRoleAddress,
11
+ } from '@toolproof-core/genesis';
12
+ import { getStrategyStateEntry, type StrategyState } from './strategyState.js';
13
+
14
+ type ToolStepRoleAddressForStrategyState<TStrategyState extends StrategyState> =
15
+ TStrategyState extends UnthreadedStrategyState
16
+ ? UnthreadedToolStepRoleAddress
17
+ : TStrategyState extends ThreadedStrategyState
18
+ ? ThreadedToolStepRoleAddress
19
+ : ToolStepRoleAddress;
20
+
21
+ export type ResolveResult =
22
+ | { status: 'inputResource'; entry: InputResource; path: ToolStepRoleAddress[] }
23
+ | { status: 'externalInputPotential'; entry: ExternalInputPotential; path: ToolStepRoleAddress[] }
24
+ | { status: 'unresolved'; reason: 'not-found' | 'cycle' | 'depth-exceeded'; path: ToolStepRoleAddress[] };
25
+
26
+ export function resolveStrategyStateChain<TStrategyState extends StrategyState>(
27
+ strategyState: TStrategyState,
28
+ start: ToolStepRoleAddressForStrategyState<TStrategyState>,
29
+ opts?: { maxDepth?: number }
30
+ ): ResolveResult {
31
+ const maxDepth = opts?.maxDepth ?? 50;
32
+ const visited = new Set<string>();
33
+ const path: ToolStepRoleAddress[] = [];
34
+ let current: ToolStepRoleAddressForStrategyState<TStrategyState> = start;
35
+
36
+ for (let depth = 0; depth <= maxDepth; depth++) {
37
+ path.push(current);
38
+ const visitKey = `${current.toolStepPath}::${current.roleName}`;
39
+ if (visited.has(visitKey)) {
40
+ return { status: 'unresolved', reason: 'cycle', path };
41
+ }
42
+ visited.add(visitKey);
43
+
44
+ const entry = getStrategyStateEntry(strategyState, current) as StrategyStateInputEntry | undefined;
45
+ if (!entry) return { status: 'unresolved', reason: 'not-found', path };
46
+
47
+ if (entry.strategyStateInputKind === 'inputResource') {
48
+ return { status: 'inputResource', entry, path };
49
+ }
50
+ if (entry.strategyStateInputKind === 'externalInputPotential') {
51
+ return { status: 'externalInputPotential', entry, path };
52
+ }
53
+
54
+ current = (entry as InternalInputPotential).toolStepRoleAddress as ToolStepRoleAddressForStrategyState<TStrategyState>;
55
+ }
56
+
57
+ return { status: 'unresolved', reason: 'depth-exceeded', path };
58
+ }
@@ -1,11 +1,15 @@
1
1
  import type {
2
2
  RoleName,
3
3
  RoleValue,
4
- Strategy,
5
4
  Step,
5
+ StepArrayArray,
6
6
  Tool,
7
7
  ToolStep,
8
- } from '@toolproof-core/schema';
8
+ } from '@toolproof-core/genesis';
9
+
10
+ export type StrategyStepGraph =
11
+ | { steps: Step[] }
12
+ | { stepsByThreadIndex: StepArrayArray };
9
13
 
10
14
  export interface ToolRoleDescriptor extends RoleValue {
11
15
  id: RoleName;
@@ -36,7 +40,7 @@ export function toToolRoleDescriptor([roleName, roleValue]: [RoleName, RoleValue
36
40
  };
37
41
  }
38
42
 
39
- export function extractToolStepsFromStrategy(strategy: Strategy): ToolStep[] {
43
+ export function extractToolStepsFromStrategy(strategy: StrategyStepGraph): ToolStep[] {
40
44
  const toolSteps: ToolStep[] = [];
41
45
 
42
46
  const visitStep = (step: Step) => {
@@ -1,56 +1,128 @@
1
1
  import type {
2
- CreationContext,
2
+ ToolStepRoleAddress,
3
+ ToolStepPath,
4
+ Resource,
5
+ InputResource,
6
+ InternalInputPotential,
7
+ ExternalInputPotential,
3
8
  Strategy,
4
9
  StrategyStateInputEntry,
5
10
  StrategyStateInputEntryByRoleName,
6
- } from '@toolproof-core/schema';
11
+ ThreadedStrategyState,
12
+ ThreadedToolStepPath,
13
+ ThreadedToolStepRoleAddress,
14
+ UnthreadedStrategyState,
15
+ UnthreadedToolStepPath,
16
+ UnthreadedToolStepRoleAddress,
17
+ } from '@toolproof-core/genesis';
7
18
 
8
19
  export type StrategyState = Strategy['strategyState'];
9
20
 
10
- export function getStrategyStateBucket(
11
- strategyState: StrategyState,
12
- toolStepPath: CreationContext['toolStepPath'],
21
+ type ToolStepPathForStrategyState<TStrategyState extends StrategyState> =
22
+ TStrategyState extends UnthreadedStrategyState
23
+ ? UnthreadedToolStepPath
24
+ : TStrategyState extends ThreadedStrategyState
25
+ ? ThreadedToolStepPath
26
+ : ToolStepPath;
27
+
28
+ type ToolStepRoleAddressForStrategyState<TStrategyState extends StrategyState> =
29
+ TStrategyState extends UnthreadedStrategyState
30
+ ? UnthreadedToolStepRoleAddress
31
+ : TStrategyState extends ThreadedStrategyState
32
+ ? ThreadedToolStepRoleAddress
33
+ : ToolStepRoleAddress;
34
+
35
+ export function getStrategyStateBucket<TStrategyState extends StrategyState>(
36
+ strategyState: TStrategyState,
37
+ toolStepPath: ToolStepPathForStrategyState<TStrategyState>,
13
38
  ): StrategyStateInputEntryByRoleName | undefined {
14
- return strategyState[toolStepPath];
39
+ return strategyState[toolStepPath] as StrategyStateInputEntryByRoleName | undefined;
15
40
  }
16
41
 
17
- export function getStrategyStateEntry(
18
- strategyState: StrategyState,
19
- context: CreationContext,
42
+ export function getStrategyStateEntry<TStrategyState extends StrategyState>(
43
+ strategyState: TStrategyState,
44
+ toolStepRoleAddress: ToolStepRoleAddressForStrategyState<TStrategyState>,
20
45
  ): StrategyStateInputEntry | undefined {
21
- return getStrategyStateBucket(strategyState, context.toolStepPath)?.[context.roleName];
46
+ const toolStepPath = toolStepRoleAddress.toolStepPath as ToolStepPathForStrategyState<TStrategyState>;
47
+ return getStrategyStateBucket(strategyState, toolStepPath)?.[toolStepRoleAddress.roleName];
22
48
  }
23
49
 
24
- export function setStrategyStateEntry(
25
- strategyState: StrategyState,
26
- context: CreationContext,
50
+ export function setStrategyStateEntry<TStrategyState extends StrategyState>(
51
+ strategyState: TStrategyState,
52
+ toolStepRoleAddress: ToolStepRoleAddressForStrategyState<TStrategyState>,
27
53
  entry: StrategyStateInputEntry,
28
- ): StrategyState {
29
- const bucket = getStrategyStateBucket(strategyState, context.toolStepPath) ?? {};
54
+ ): TStrategyState {
55
+ const toolStepPath = toolStepRoleAddress.toolStepPath as ToolStepPathForStrategyState<TStrategyState>;
56
+ const bucket = getStrategyStateBucket(strategyState, toolStepPath) ?? {};
30
57
 
31
58
  return {
32
59
  ...strategyState,
33
- [context.toolStepPath]: {
60
+ [toolStepPath]: {
34
61
  ...bucket,
35
- [context.roleName]: entry,
62
+ [toolStepRoleAddress.roleName]: entry,
36
63
  },
37
- };
64
+ } as TStrategyState;
38
65
  }
39
66
 
40
- export function clearStrategyStateEntry(
41
- strategyState: StrategyState,
42
- context: CreationContext,
43
- ): StrategyState {
44
- const bucket = getStrategyStateBucket(strategyState, context.toolStepPath);
45
- if (!bucket || !(context.roleName in bucket)) {
67
+ export function clearStrategyStateEntry<TStrategyState extends StrategyState>(
68
+ strategyState: TStrategyState,
69
+ toolStepRoleAddress: ToolStepRoleAddressForStrategyState<TStrategyState>,
70
+ ): TStrategyState {
71
+ const toolStepPath = toolStepRoleAddress.toolStepPath as ToolStepPathForStrategyState<TStrategyState>;
72
+ const bucket = getStrategyStateBucket(strategyState, toolStepPath);
73
+ if (!bucket || !(toolStepRoleAddress.roleName in bucket)) {
46
74
  return strategyState;
47
75
  }
48
76
 
49
77
  const nextBucket = { ...bucket };
50
- delete nextBucket[context.roleName];
78
+ delete nextBucket[toolStepRoleAddress.roleName];
51
79
 
52
80
  return {
53
81
  ...strategyState,
54
- [context.toolStepPath]: nextBucket,
82
+ [toolStepPath]: nextBucket,
83
+ } as TStrategyState;
84
+ }
85
+
86
+ export function bindInputResource<TStrategyState extends StrategyState>(
87
+ strategyState: TStrategyState,
88
+ target: ToolStepRoleAddressForStrategyState<TStrategyState>,
89
+ resource: Resource,
90
+ ): TStrategyState {
91
+ const inputResource: InputResource = {
92
+ ...resource,
93
+ strategyStateInputKind: 'inputResource',
55
94
  };
56
- }
95
+
96
+ return setStrategyStateEntry(strategyState, target, inputResource);
97
+ }
98
+
99
+ export function bindInternalInputPotential<TStrategyState extends StrategyState>(
100
+ strategyState: TStrategyState,
101
+ target: ToolStepRoleAddressForStrategyState<TStrategyState>,
102
+ source: ToolStepRoleAddressForStrategyState<TStrategyState>,
103
+ ): TStrategyState {
104
+ const sourceEntry = getStrategyStateEntry(strategyState, source);
105
+ if (!sourceEntry) {
106
+ throw new Error(`resourceEntry not found for source (${source.toolStepPath}, ${source.roleName})`);
107
+ }
108
+
109
+ const internalInputPotential: InternalInputPotential = {
110
+ strategyStateInputKind: 'internalInputPotential',
111
+ toolStepRoleAddress: {
112
+ toolStepPath: source.toolStepPath,
113
+ roleName: source.roleName,
114
+ },
115
+ };
116
+
117
+ return setStrategyStateEntry(strategyState, target, internalInputPotential);
118
+ }
119
+
120
+ export function bindExternalInputPotential<TStrategyState extends StrategyState>(
121
+ strategyState: TStrategyState,
122
+ target: ToolStepRoleAddressForStrategyState<TStrategyState>,
123
+ ): TStrategyState {
124
+ const externalInputPotential: ExternalInputPotential = {
125
+ strategyStateInputKind: 'externalInputPotential',
126
+ };
127
+ return setStrategyStateEntry(strategyState, target, externalInputPotential);
128
+ }
@@ -0,0 +1,19 @@
1
+ import type { UnthreadedStrategy, ThreadedStrategy, StepArray, StepArrayArray, UnthreadedStrategyState, ThreadedStrategyState } from "@toolproof-core/genesis/types";
2
+
3
+
4
+ export const __UnthreadedStrategyToThreadedStrategy = (unthreadedStrategy: UnthreadedStrategy): ThreadedStrategy => {
5
+ throw new Error('Not implemented yet');
6
+ }
7
+
8
+ export const __UnthreadedStrategyStateToThreadedStrategyState = (unthreadedStrategyState: UnthreadedStrategyState): ThreadedStrategyState => {
9
+ throw new Error('Not implemented yet');
10
+ }
11
+
12
+ export const __StepArrayToStepArrayArray = (stepArray: StepArray): StepArrayArray => {
13
+ throw new Error('Not implemented yet');
14
+ }
15
+
16
+ export const __Foo = (unthreadedStrategy: UnthreadedStrategy, draft: any): UnthreadedStrategy => {
17
+ throw new Error('Not implemented yet');
18
+ }
19
+