@toolproof-core/lib 1.0.26 → 1.0.28
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/artifacts/artifacts.d.ts +30 -30
- package/dist/integrations/firebase/createRunnableStrategy.js +4 -4
- package/dist/integrations/firebase/createRunnableStrategy.js.map +1 -1
- package/dist/integrations/firebase/createStep.js +17 -17
- package/dist/integrations/firebase/createStep.js.map +1 -1
- package/dist/integrations/firebase/firebaseAdminHelpers.d.ts +5 -5
- package/dist/integrations/firebase/firebaseAdminHelpers.d.ts.map +1 -1
- package/dist/integrations/firebase/firebaseAdminHelpers.js +11 -11
- package/dist/integrations/firebase/firebaseAdminHelpers.js.map +1 -1
- package/dist/types/types.d.ts +6 -6
- package/dist/types/types.d.ts.map +1 -1
- package/dist/utils/bindInputRoleToResource.js +2 -2
- package/dist/utils/bindInputRoleToResource.js.map +1 -1
- package/dist/utils/creation/resourceCreation.d.ts +5 -5
- package/dist/utils/creation/resourceCreation.d.ts.map +1 -1
- package/dist/utils/creation/resourceCreation.js +14 -14
- package/dist/utils/creation/resourceCreation.js.map +1 -1
- package/dist/utils/creation/runnableStrategyCreation.d.ts +2 -2
- package/dist/utils/creation/runnableStrategyCreation.d.ts.map +1 -1
- package/dist/utils/creation/runnableStrategyCreation.js +7 -7
- package/dist/utils/creation/runnableStrategyCreation.js.map +1 -1
- package/dist/utils/creation/stepCreation.d.ts +17 -17
- package/dist/utils/creation/stepCreation.d.ts.map +1 -1
- package/dist/utils/creation/stepCreation.js +20 -20
- package/dist/utils/creation/stepCreation.js.map +1 -1
- package/dist/utils/extractData.d.ts +9 -9
- package/dist/utils/extractData.d.ts.map +1 -1
- package/dist/utils/extractData.js +22 -22
- package/dist/utils/extractData.js.map +1 -1
- package/dist/utils/parallelizeSteps.js +7 -7
- package/dist/utils/parallelizeSteps.js.map +1 -1
- package/package.json +2 -2
- package/src/integrations/firebase/createRunnableStrategy.ts +4 -4
- package/src/integrations/firebase/createStep.ts +17 -17
- package/src/integrations/firebase/firebaseAdminHelpers.ts +18 -18
- package/src/types/types.ts +6 -6
- package/src/utils/bindInputRoleToResource.ts +2 -2
- package/src/utils/creation/resourceCreation.ts +19 -19
- package/src/utils/creation/runnableStrategyCreation.ts +10 -10
- package/src/utils/creation/stepCreation.ts +39 -39
- package/src/utils/extractData.ts +42 -42
- package/src/utils/parallelizeSteps.ts +14 -14
- package/toolproof-core-lib-1.0.27.tgz +0 -0
- package/tsconfig.tsbuildinfo +1 -1
package/src/types/types.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
StepKindJson,
|
|
3
3
|
ResourceJson,
|
|
4
|
-
|
|
4
|
+
ResourceTypeIdJson,
|
|
5
5
|
} from '@toolproof-core/schema';
|
|
6
6
|
import { CONSTANTS } from '../artifacts/artifacts.js';
|
|
7
7
|
import { MAPPINGS } from '../artifacts/artifacts.js';
|
|
@@ -12,16 +12,16 @@ export type Collection = keyof typeof CONSTANTS.Persistence.Collections;
|
|
|
12
12
|
|
|
13
13
|
export type SchemaLike = Record<string, unknown>;
|
|
14
14
|
|
|
15
|
-
export type ResourcesByType = Record<
|
|
15
|
+
export type ResourcesByType = Record<ResourceTypeIdJson, ResourceJson[]>;
|
|
16
16
|
|
|
17
|
-
export type
|
|
17
|
+
export type IdName = keyof typeof MAPPINGS.IdNameToIdPrefix;
|
|
18
18
|
|
|
19
|
-
export type
|
|
19
|
+
export type IdStringByIdName<K extends IdName> = `${(typeof MAPPINGS.IdNameToIdPrefix)[K]}${string}`;
|
|
20
20
|
|
|
21
|
-
export type
|
|
21
|
+
export type StepIdStringByStepKind<K extends StepKindJson> = `${(typeof MAPPINGS.StepKindToStepIdPrefix)[K]}${string}`;
|
|
22
22
|
|
|
23
23
|
export interface NucleusBaseSmall<T extends string = string> {
|
|
24
|
-
|
|
24
|
+
id: T;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export interface NucleusBaseLarge<T extends string = string> extends NucleusBaseSmall<T> {
|
|
@@ -56,7 +56,7 @@ export function bindInputRefInStrategyState(
|
|
|
56
56
|
if (result.status === CONSTANTS.Enums.ResourceShellKind.externalInputPotential) {
|
|
57
57
|
const externalInput = result.entry;
|
|
58
58
|
const reusedExternalInput: ExternalInputPotentialShellJson = {
|
|
59
|
-
|
|
59
|
+
id: externalInput.id,
|
|
60
60
|
resourceTypeHandle: externalInput.resourceTypeHandle,
|
|
61
61
|
resourceShellKind: CONSTANTS.Enums.ResourceShellKind.externalInputPotential,
|
|
62
62
|
};
|
|
@@ -72,7 +72,7 @@ export function bindInputRefInStrategyState(
|
|
|
72
72
|
|
|
73
73
|
if (result.status === CONSTANTS.Enums.ResourceShellKind.outputPotential) {
|
|
74
74
|
const potentialInput: InternalInputPotentialShellJson = {
|
|
75
|
-
|
|
75
|
+
id: sourceEntry.id,
|
|
76
76
|
resourceTypeHandle: sourceEntry.resourceTypeHandle,
|
|
77
77
|
creationContext: {
|
|
78
78
|
toolStepHandle: source.toolStepHandle,
|
|
@@ -3,14 +3,14 @@ import type {
|
|
|
3
3
|
ExternalInputPotentialShellJson,
|
|
4
4
|
InternalInputPotentialShellJson,
|
|
5
5
|
OutputPotentialShellJson,
|
|
6
|
-
|
|
6
|
+
ResourceIdJson,
|
|
7
7
|
ResourceJson,
|
|
8
|
-
|
|
8
|
+
ResourceTypeIdJson,
|
|
9
9
|
} from '@toolproof-core/schema';
|
|
10
10
|
import { CONSTANTS } from '../../artifacts/artifacts.js';
|
|
11
11
|
|
|
12
|
-
export function generatePath(resourceTypeHandle:
|
|
13
|
-
return `${resourceTypeHandle}/${
|
|
12
|
+
export function generatePath(resourceTypeHandle: ResourceTypeIdJson, id: ResourceIdJson): string {
|
|
13
|
+
return `${resourceTypeHandle}/${id}.json`;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export function createMaterializedFromOutputPotential(
|
|
@@ -18,11 +18,11 @@ export function createMaterializedFromOutputPotential(
|
|
|
18
18
|
nucleus: unknown,
|
|
19
19
|
timestamp?: string,
|
|
20
20
|
): ResourceJson {
|
|
21
|
-
const {
|
|
22
|
-
const path = generatePath(resourceTypeHandle,
|
|
21
|
+
const { id, resourceTypeHandle, creationContext } = outputPotential;
|
|
22
|
+
const path = generatePath(resourceTypeHandle, id);
|
|
23
23
|
|
|
24
24
|
return {
|
|
25
|
-
|
|
25
|
+
id,
|
|
26
26
|
resourceTypeHandle,
|
|
27
27
|
creationContext,
|
|
28
28
|
resourceShellKind: CONSTANTS.Enums.ResourceShellKind.materialized,
|
|
@@ -38,11 +38,11 @@ export function createMaterializedFromInputPotential(
|
|
|
38
38
|
nucleus: unknown,
|
|
39
39
|
timestamp?: string,
|
|
40
40
|
): ResourceJson {
|
|
41
|
-
const {
|
|
42
|
-
const path = generatePath(resourceTypeHandle,
|
|
41
|
+
const { id, resourceTypeHandle, creationContext } = inputPotential;
|
|
42
|
+
const path = generatePath(resourceTypeHandle, id);
|
|
43
43
|
|
|
44
44
|
return {
|
|
45
|
-
|
|
45
|
+
id,
|
|
46
46
|
resourceTypeHandle,
|
|
47
47
|
creationContext,
|
|
48
48
|
resourceShellKind: CONSTANTS.Enums.ResourceShellKind.materialized,
|
|
@@ -66,23 +66,23 @@ export function createMaterializedFromPotential(
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
export function createExternalInputPotential(
|
|
69
|
-
|
|
70
|
-
resourceTypeHandle:
|
|
69
|
+
id: ResourceIdJson,
|
|
70
|
+
resourceTypeHandle: ResourceTypeIdJson,
|
|
71
71
|
): ExternalInputPotentialShellJson {
|
|
72
72
|
return {
|
|
73
|
-
|
|
73
|
+
id,
|
|
74
74
|
resourceTypeHandle,
|
|
75
75
|
resourceShellKind: CONSTANTS.Enums.ResourceShellKind.externalInputPotential,
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
export function createInputPotential(
|
|
80
|
-
|
|
81
|
-
resourceTypeHandle:
|
|
80
|
+
id: ResourceIdJson,
|
|
81
|
+
resourceTypeHandle: ResourceTypeIdJson,
|
|
82
82
|
creationContext: CreationContextJson,
|
|
83
83
|
): InternalInputPotentialShellJson {
|
|
84
84
|
return {
|
|
85
|
-
|
|
85
|
+
id,
|
|
86
86
|
resourceTypeHandle,
|
|
87
87
|
creationContext,
|
|
88
88
|
resourceShellKind: CONSTANTS.Enums.ResourceShellKind.internalInputPotential,
|
|
@@ -90,12 +90,12 @@ export function createInputPotential(
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
export function createOutputPotential(
|
|
93
|
-
|
|
94
|
-
resourceTypeHandle:
|
|
93
|
+
id: ResourceIdJson,
|
|
94
|
+
resourceTypeHandle: ResourceTypeIdJson,
|
|
95
95
|
creationContext: CreationContextJson,
|
|
96
96
|
): OutputPotentialShellJson {
|
|
97
97
|
return {
|
|
98
|
-
|
|
98
|
+
id,
|
|
99
99
|
resourceTypeHandle,
|
|
100
100
|
creationContext,
|
|
101
101
|
resourceShellKind: CONSTANTS.Enums.ResourceShellKind.outputPotential,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
RawStrategyJson,
|
|
3
|
-
|
|
3
|
+
RunnableStrategyIdJson,
|
|
4
4
|
RunnableStrategyJson,
|
|
5
5
|
StepJson,
|
|
6
6
|
StepArrayByStrategyThreadJson,
|
|
7
|
-
|
|
7
|
+
StrategyThreadIdJson,
|
|
8
8
|
} from '@toolproof-core/schema';
|
|
9
9
|
import { getIndependentThreads } from '../parallelizeSteps.js';
|
|
10
10
|
|
|
@@ -14,28 +14,28 @@ export function getRunnableStrategyThreadGroups(rawStrategy: RawStrategyJson): S
|
|
|
14
14
|
|
|
15
15
|
export function buildRunnableStrategy(
|
|
16
16
|
rawStrategy: RawStrategyJson,
|
|
17
|
-
|
|
17
|
+
runnableStrategyId: RunnableStrategyIdJson,
|
|
18
18
|
threadStepGroups: StepJson[][],
|
|
19
|
-
threadIdentities:
|
|
19
|
+
threadIdentities: StrategyThreadIdJson[],
|
|
20
20
|
): RunnableStrategyJson {
|
|
21
21
|
if (threadStepGroups.length !== threadIdentities.length) {
|
|
22
|
-
throw new Error('buildRunnableStrategy requires one thread
|
|
22
|
+
throw new Error('buildRunnableStrategy requires one thread id per thread group');
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
const stepsByStrategyThread: StepArrayByStrategyThreadJson = {};
|
|
26
26
|
|
|
27
27
|
for (const [index, group] of threadStepGroups.entries()) {
|
|
28
|
-
const
|
|
28
|
+
const threadId = threadIdentities[index];
|
|
29
29
|
|
|
30
|
-
if (!
|
|
31
|
-
throw new Error(`Missing thread
|
|
30
|
+
if (!threadId) {
|
|
31
|
+
throw new Error(`Missing thread id for thread group index ${index}`);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
stepsByStrategyThread[
|
|
34
|
+
stepsByStrategyThread[threadId] = group;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
return {
|
|
38
|
-
|
|
38
|
+
id: runnableStrategyId,
|
|
39
39
|
stepsByStrategyThread,
|
|
40
40
|
strategyState: rawStrategy.strategyState,
|
|
41
41
|
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
2
|
+
BranchStepIdJson,
|
|
3
3
|
BranchStepJson,
|
|
4
4
|
CaseJson,
|
|
5
|
-
|
|
5
|
+
ForStepIdJson,
|
|
6
6
|
ForStepJson,
|
|
7
7
|
ToolJson,
|
|
8
|
-
|
|
8
|
+
ToolStepIdJson,
|
|
9
9
|
ToolStepJson,
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
ResourceRoleIdJson,
|
|
11
|
+
WhileStepIdJson,
|
|
12
12
|
WhileStepJson,
|
|
13
13
|
} from '@toolproof-core/schema';
|
|
14
14
|
import { CONSTANTS } from '../../artifacts/artifacts.js';
|
|
@@ -16,20 +16,20 @@ import { CONSTANTS } from '../../artifacts/artifacts.js';
|
|
|
16
16
|
export type LoopStepBuildIdentities =
|
|
17
17
|
| {
|
|
18
18
|
stepKind: typeof CONSTANTS.Enums.StepKind.for;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
stepId: ForStepIdJson;
|
|
20
|
+
whatId: ToolStepIdJson;
|
|
21
|
+
whenId: ToolStepIdJson;
|
|
22
22
|
}
|
|
23
23
|
| {
|
|
24
24
|
stepKind: typeof CONSTANTS.Enums.StepKind.while;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
stepId: WhileStepIdJson;
|
|
26
|
+
whatId: ToolStepIdJson;
|
|
27
|
+
whenId: ToolStepIdJson;
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
export type BranchCaseBuildIdentities = {
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
whatId: ToolStepIdJson;
|
|
32
|
+
whenId: ToolStepIdJson;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
function assertNonEmpty<T>(arr: T[], msg: string): asserts arr is [T, ...T[]] {
|
|
@@ -40,19 +40,19 @@ function assertNonEmpty<T>(arr: T[], msg: string): asserts arr is [T, ...T[]] {
|
|
|
40
40
|
|
|
41
41
|
function getRoleBindingSpec(tool: ToolJson): ToolStepJson['roleBindingSpec'] {
|
|
42
42
|
return {
|
|
43
|
-
inputBindings: Object.keys(tool.roleSpec.
|
|
44
|
-
outputBindings: Object.keys(tool.roleSpec.
|
|
43
|
+
inputBindings: Object.keys(tool.roleSpec.inputRoleValueById) as ResourceRoleIdJson[],
|
|
44
|
+
outputBindings: Object.keys(tool.roleSpec.outputRoleValueById) as ResourceRoleIdJson[],
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
export function buildToolStepFromTool(
|
|
49
49
|
tool: ToolJson,
|
|
50
|
-
|
|
50
|
+
id: ToolStepIdJson,
|
|
51
51
|
): ToolStepJson {
|
|
52
52
|
return {
|
|
53
|
-
|
|
53
|
+
id,
|
|
54
54
|
stepKind: CONSTANTS.Enums.StepKind.tool,
|
|
55
|
-
toolHandle: tool.
|
|
55
|
+
toolHandle: tool.id,
|
|
56
56
|
roleBindingSpec: getRoleBindingSpec(tool),
|
|
57
57
|
};
|
|
58
58
|
}
|
|
@@ -62,19 +62,19 @@ export function buildLoopStepFromToolPair(
|
|
|
62
62
|
whenTool: ToolJson,
|
|
63
63
|
identities: LoopStepBuildIdentities,
|
|
64
64
|
): ForStepJson | WhileStepJson {
|
|
65
|
-
const what = buildToolStepFromTool(whatTool, identities.
|
|
66
|
-
const when = buildToolStepFromTool(whenTool, identities.
|
|
65
|
+
const what = buildToolStepFromTool(whatTool, identities.whatId);
|
|
66
|
+
const when = buildToolStepFromTool(whenTool, identities.whenId);
|
|
67
67
|
|
|
68
68
|
if (identities.stepKind === CONSTANTS.Enums.StepKind.for) {
|
|
69
69
|
return {
|
|
70
|
-
|
|
70
|
+
id: identities.stepId,
|
|
71
71
|
stepKind: CONSTANTS.Enums.StepKind.for,
|
|
72
72
|
case: { what, when },
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
return {
|
|
77
|
-
|
|
77
|
+
id: identities.stepId,
|
|
78
78
|
stepKind: CONSTANTS.Enums.StepKind.while,
|
|
79
79
|
case: { what, when },
|
|
80
80
|
};
|
|
@@ -82,11 +82,11 @@ export function buildLoopStepFromToolPair(
|
|
|
82
82
|
|
|
83
83
|
export function buildBranchStepFromToolPairs(
|
|
84
84
|
cases: Array<{ whatTool: ToolJson; whenTool: ToolJson }>,
|
|
85
|
-
|
|
85
|
+
branchId: BranchStepIdJson,
|
|
86
86
|
caseIdentities: BranchCaseBuildIdentities[],
|
|
87
87
|
): BranchStepJson {
|
|
88
88
|
if (cases.length !== caseIdentities.length) {
|
|
89
|
-
throw new Error('buildBranchStepFromToolPairs requires one
|
|
89
|
+
throw new Error('buildBranchStepFromToolPairs requires one id pair per case');
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
const resolved = cases.map(({ whatTool, whenTool }, index) => {
|
|
@@ -96,15 +96,15 @@ export function buildBranchStepFromToolPairs(
|
|
|
96
96
|
throw new Error(`Missing case identities for case index ${index}`);
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
const what = buildToolStepFromTool(whatTool, identities.
|
|
100
|
-
const when = buildToolStepFromTool(whenTool, identities.
|
|
99
|
+
const what = buildToolStepFromTool(whatTool, identities.whatId);
|
|
100
|
+
const when = buildToolStepFromTool(whenTool, identities.whenId);
|
|
101
101
|
return { what, when } satisfies CaseJson;
|
|
102
102
|
});
|
|
103
103
|
|
|
104
104
|
assertNonEmpty(resolved, 'buildBranchStepFromToolPairs requires at least one case');
|
|
105
105
|
|
|
106
106
|
return {
|
|
107
|
-
|
|
107
|
+
id: branchId,
|
|
108
108
|
stepKind: CONSTANTS.Enums.StepKind.branch,
|
|
109
109
|
cases: resolved,
|
|
110
110
|
};
|
|
@@ -113,22 +113,22 @@ export function buildBranchStepFromToolPairs(
|
|
|
113
113
|
export function cloneForStepWithIdentities(
|
|
114
114
|
forStep: ForStepJson,
|
|
115
115
|
identities: {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
116
|
+
stepId: ForStepIdJson;
|
|
117
|
+
whatId: ToolStepIdJson;
|
|
118
|
+
whenId: ToolStepIdJson;
|
|
119
119
|
},
|
|
120
120
|
): ForStepJson {
|
|
121
121
|
return {
|
|
122
|
-
|
|
122
|
+
id: identities.stepId,
|
|
123
123
|
stepKind: CONSTANTS.Enums.StepKind.for,
|
|
124
124
|
case: {
|
|
125
125
|
what: {
|
|
126
126
|
...forStep.case.what,
|
|
127
|
-
|
|
127
|
+
id: identities.whatId,
|
|
128
128
|
},
|
|
129
129
|
when: {
|
|
130
130
|
...forStep.case.when,
|
|
131
|
-
|
|
131
|
+
id: identities.whenId,
|
|
132
132
|
},
|
|
133
133
|
},
|
|
134
134
|
};
|
|
@@ -137,22 +137,22 @@ export function cloneForStepWithIdentities(
|
|
|
137
137
|
export function cloneWhileStepWithIdentities(
|
|
138
138
|
whileStep: WhileStepJson,
|
|
139
139
|
identities: {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
140
|
+
stepId: WhileStepIdJson;
|
|
141
|
+
whatId: ToolStepIdJson;
|
|
142
|
+
whenId: ToolStepIdJson;
|
|
143
143
|
},
|
|
144
144
|
): WhileStepJson {
|
|
145
145
|
return {
|
|
146
|
-
|
|
146
|
+
id: identities.stepId,
|
|
147
147
|
stepKind: CONSTANTS.Enums.StepKind.while,
|
|
148
148
|
case: {
|
|
149
149
|
what: {
|
|
150
150
|
...whileStep.case.what,
|
|
151
|
-
|
|
151
|
+
id: identities.whatId,
|
|
152
152
|
},
|
|
153
153
|
when: {
|
|
154
154
|
...whileStep.case.when,
|
|
155
|
-
|
|
155
|
+
id: identities.whenId,
|
|
156
156
|
},
|
|
157
157
|
},
|
|
158
158
|
};
|
package/src/utils/extractData.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
RawStrategyJson,
|
|
3
|
-
|
|
3
|
+
ToolIdJson,
|
|
4
4
|
ToolJson,
|
|
5
|
-
|
|
5
|
+
ToolStepIdJson,
|
|
6
6
|
ToolStepJson,
|
|
7
7
|
StepJson,
|
|
8
|
-
|
|
8
|
+
ResourceRoleIdJson,
|
|
9
9
|
ResourceRoleJson,
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
ResourceIdJson,
|
|
11
|
+
ResourceTypeIdJson,
|
|
12
12
|
ResourceJson,
|
|
13
13
|
} from '@toolproof-core/schema';
|
|
14
14
|
import { CONSTANTS } from '../artifacts/artifacts.js';
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
export function extractToolHandlesFromRawStrategy(rawStrategy: RawStrategyJson):
|
|
17
|
+
export function extractToolHandlesFromRawStrategy(rawStrategy: RawStrategyJson): ToolIdJson[] {
|
|
18
18
|
const toolSteps = extractToolStepsFromRawStrategy(rawStrategy);
|
|
19
|
-
const ids = new Set<
|
|
19
|
+
const ids = new Set<ToolIdJson>();
|
|
20
20
|
for (const jStep of toolSteps) {
|
|
21
21
|
ids.add(jStep.toolHandle);
|
|
22
22
|
}
|
|
@@ -25,13 +25,13 @@ export function extractToolHandlesFromRawStrategy(rawStrategy: RawStrategyJson):
|
|
|
25
25
|
|
|
26
26
|
export function extractToolStepsFromRawStrategy(rawStrategy: RawStrategyJson): ToolStepJson[] {
|
|
27
27
|
const toolSteps: ToolStepJson[] = [];
|
|
28
|
-
const seen = new Set<
|
|
28
|
+
const seen = new Set<ToolStepIdJson>();
|
|
29
29
|
|
|
30
30
|
const addToolStep = (toolStep: ToolStepJson) => {
|
|
31
|
-
if (seen.has(toolStep.
|
|
32
|
-
throw new Error(`Duplicate tool step
|
|
31
|
+
if (seen.has(toolStep.id)) {
|
|
32
|
+
throw new Error(`Duplicate tool step id encountered: ${toolStep.id}`);
|
|
33
33
|
}
|
|
34
|
-
seen.add(toolStep.
|
|
34
|
+
seen.add(toolStep.id);
|
|
35
35
|
toolSteps.push(toolStep);
|
|
36
36
|
};
|
|
37
37
|
|
|
@@ -69,23 +69,23 @@ export function extractToolStepsFromRawStrategy(rawStrategy: RawStrategyJson): T
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
|
|
72
|
-
export function extractRoleMapFromRawStrategy(rawStrategy: RawStrategyJson, toolMap: Map<
|
|
73
|
-
const roleMap = new Map<
|
|
72
|
+
export function extractRoleMapFromRawStrategy(rawStrategy: RawStrategyJson, toolMap: Map<ToolIdJson, ToolJson>): Map<ResourceRoleIdJson, ResourceRoleJson> {
|
|
73
|
+
const roleMap = new Map<ResourceRoleIdJson, ResourceRoleJson>();
|
|
74
74
|
const toolHandles = extractToolHandlesFromRawStrategy(rawStrategy);
|
|
75
75
|
|
|
76
76
|
for (const toolHandle of toolHandles) {
|
|
77
77
|
const tool = toolMap.get(toolHandle);
|
|
78
78
|
if (!tool) continue;
|
|
79
79
|
|
|
80
|
-
for (const [rid, role] of Object.entries(tool.roleSpec.
|
|
81
|
-
roleMap.set(rid as
|
|
82
|
-
|
|
80
|
+
for (const [rid, role] of Object.entries(tool.roleSpec.inputRoleValueById)) {
|
|
81
|
+
roleMap.set(rid as ResourceRoleIdJson, {
|
|
82
|
+
id: rid as ResourceRoleIdJson,
|
|
83
83
|
...role,
|
|
84
84
|
});
|
|
85
85
|
}
|
|
86
|
-
for (const [rid, role] of Object.entries(tool.roleSpec.
|
|
87
|
-
roleMap.set(rid as
|
|
88
|
-
|
|
86
|
+
for (const [rid, role] of Object.entries(tool.roleSpec.outputRoleValueById)) {
|
|
87
|
+
roleMap.set(rid as ResourceRoleIdJson, {
|
|
88
|
+
id: rid as ResourceRoleIdJson,
|
|
89
89
|
...role,
|
|
90
90
|
});
|
|
91
91
|
}
|
|
@@ -94,11 +94,11 @@ export function extractRoleMapFromRawStrategy(rawStrategy: RawStrategyJson, tool
|
|
|
94
94
|
return roleMap;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
export function extractSingleNonErrorOutputTypeHandle(tool: ToolJson):
|
|
97
|
+
export function extractSingleNonErrorOutputTypeHandle(tool: ToolJson): ResourceTypeIdJson | null {
|
|
98
98
|
const errorRoleId = CONSTANTS.Cosmos.ROLE_ErrorOutput;
|
|
99
|
-
const outputEntries = Object.entries(tool.roleSpec.
|
|
99
|
+
const outputEntries = Object.entries(tool.roleSpec.outputRoleValueById).filter(([roleId]) => roleId !== errorRoleId);
|
|
100
100
|
if (!outputEntries || !outputEntries[0] || outputEntries.length !== 1) {
|
|
101
|
-
throw new Error(`Tool ${tool.
|
|
101
|
+
throw new Error(`Tool ${tool.id} must have exactly one non-error output role to be branchable/loopable`);
|
|
102
102
|
} // ATTENTION_PUREIFY
|
|
103
103
|
const outputRole = outputEntries[0][1];
|
|
104
104
|
return outputRole.resourceTypeHandle;
|
|
@@ -107,27 +107,27 @@ export function extractSingleNonErrorOutputTypeHandle(tool: ToolJson): ResourceT
|
|
|
107
107
|
|
|
108
108
|
|
|
109
109
|
export function extractResourceMapForType<TResource extends ResourceJson = ResourceJson>(
|
|
110
|
-
resourcesByType: Partial<Record<
|
|
111
|
-
resourceTypeHandle:
|
|
112
|
-
): Map<
|
|
110
|
+
resourcesByType: Partial<Record<ResourceTypeIdJson, TResource[]>>,
|
|
111
|
+
resourceTypeHandle: ResourceTypeIdJson
|
|
112
|
+
): Map<ResourceIdJson, TResource> {
|
|
113
113
|
const resources = resourcesByType[resourceTypeHandle] ?? [];
|
|
114
|
-
const map = new Map<
|
|
114
|
+
const map = new Map<ResourceIdJson, TResource>();
|
|
115
115
|
|
|
116
116
|
for (const resource of resources) {
|
|
117
|
-
map.set(resource.
|
|
117
|
+
map.set(resource.id, resource);
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
return map;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
// Only use this for resource types whose nuclei are entity-like objects with their own intrinsic
|
|
124
|
-
export function
|
|
123
|
+
// Only use this for resource types whose nuclei are entity-like objects with their own intrinsic id.
|
|
124
|
+
export function extractIdKeyedNucleusMapForType<
|
|
125
125
|
TKey extends string = string,
|
|
126
|
-
TNucleus extends {
|
|
126
|
+
TNucleus extends { id: string | number | boolean } = { id: string | number | boolean },
|
|
127
127
|
TResource extends ResourceJson = ResourceJson
|
|
128
128
|
>(
|
|
129
|
-
resourcesByType: Partial<Record<
|
|
130
|
-
resourceTypeHandle:
|
|
129
|
+
resourcesByType: Partial<Record<ResourceTypeIdJson, TResource[]>>,
|
|
130
|
+
resourceTypeHandle: ResourceTypeIdJson,
|
|
131
131
|
): Map<TKey, TNucleus> {
|
|
132
132
|
const resourceMap = extractResourceMapForType<TResource>(resourcesByType, resourceTypeHandle);
|
|
133
133
|
const out = new Map<TKey, TNucleus>();
|
|
@@ -136,33 +136,33 @@ export function extractIdentityKeyedNucleusMapForType<
|
|
|
136
136
|
const data = (resource as any).nucleus as unknown;
|
|
137
137
|
if (data === null || data === undefined) {
|
|
138
138
|
throw new Error(
|
|
139
|
-
`Expected resource '${resource.
|
|
139
|
+
`Expected resource '${resource.id}' of type '${resourceTypeHandle}' to have a nucleus`
|
|
140
140
|
);
|
|
141
141
|
}
|
|
142
142
|
if (typeof data !== 'object') {
|
|
143
143
|
throw new Error(
|
|
144
|
-
`Expected resource '${resource.
|
|
144
|
+
`Expected resource '${resource.id}' of type '${resourceTypeHandle}' to have an object nucleus with id`
|
|
145
145
|
);
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
const
|
|
149
|
-
if (
|
|
148
|
+
const maybeId = (data as any).id as unknown;
|
|
149
|
+
if (maybeId === null || maybeId === undefined) {
|
|
150
150
|
throw new Error(
|
|
151
|
-
`Expected resource '${resource.
|
|
151
|
+
`Expected resource '${resource.id}' of type '${resourceTypeHandle}' to have nucleus.id`
|
|
152
152
|
);
|
|
153
153
|
}
|
|
154
154
|
if (
|
|
155
|
-
typeof
|
|
156
|
-
typeof
|
|
157
|
-
typeof
|
|
155
|
+
typeof maybeId !== 'string' &&
|
|
156
|
+
typeof maybeId !== 'number' &&
|
|
157
|
+
typeof maybeId !== 'boolean'
|
|
158
158
|
) {
|
|
159
159
|
throw new Error(
|
|
160
|
-
`Expected resource '${resource.
|
|
160
|
+
`Expected resource '${resource.id}' of type '${resourceTypeHandle}' to have nucleus.id as string, number, or boolean`
|
|
161
161
|
);
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
const value = data as TNucleus;
|
|
165
|
-
const key = String(
|
|
165
|
+
const key = String(maybeId) as TKey;
|
|
166
166
|
|
|
167
167
|
out.set(key, value);
|
|
168
168
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
BranchStepJson,
|
|
3
3
|
ForStepJson,
|
|
4
|
-
|
|
4
|
+
ToolStepIdJson,
|
|
5
5
|
ToolStepJson,
|
|
6
|
-
|
|
6
|
+
ResourceRoleIdJson,
|
|
7
7
|
StepJson,
|
|
8
8
|
StrategyStateJson,
|
|
9
9
|
WhileStepJson,
|
|
@@ -19,25 +19,25 @@ export function getIndependentThreads(steps: StepJson[], strategyState: Strategy
|
|
|
19
19
|
return `steps[${ownerIndex}] stepKind=${(step as any)?.stepKind ?? 'unknown'}`;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
// Map each toolStep.
|
|
23
|
-
const toolStepIdToOwner = new Map<
|
|
24
|
-
const ownerToToolStepIds = new Map<OwnerIndex,
|
|
25
|
-
const toolStepById = new Map<
|
|
22
|
+
// Map each toolStep.id (including macro-nested tool steps) to owning top-level step index.
|
|
23
|
+
const toolStepIdToOwner = new Map<ToolStepIdJson, OwnerIndex>();
|
|
24
|
+
const ownerToToolStepIds = new Map<OwnerIndex, ToolStepIdJson[]>();
|
|
25
|
+
const toolStepById = new Map<ToolStepIdJson, ToolStepJson>();
|
|
26
26
|
|
|
27
27
|
const addToolStep = (toolStep: ToolStepJson | undefined, ownerIndex: OwnerIndex) => {
|
|
28
|
-
if (!toolStep?.
|
|
28
|
+
if (!toolStep?.id) return;
|
|
29
29
|
|
|
30
|
-
const existingOwner = toolStepIdToOwner.get(toolStep.
|
|
30
|
+
const existingOwner = toolStepIdToOwner.get(toolStep.id);
|
|
31
31
|
if (existingOwner !== undefined) {
|
|
32
32
|
throw new Error(
|
|
33
|
-
`Duplicate toolStep.
|
|
33
|
+
`Duplicate toolStep.id '${toolStep.id}' found in ${getOwnerLabel(ownerIndex)} and ${getOwnerLabel(existingOwner)}`
|
|
34
34
|
);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
toolStepIdToOwner.set(toolStep.
|
|
38
|
-
toolStepById.set(toolStep.
|
|
37
|
+
toolStepIdToOwner.set(toolStep.id, ownerIndex);
|
|
38
|
+
toolStepById.set(toolStep.id, toolStep);
|
|
39
39
|
const bucket = ownerToToolStepIds.get(ownerIndex) ?? [];
|
|
40
|
-
bucket.push(toolStep.
|
|
40
|
+
bucket.push(toolStep.id);
|
|
41
41
|
ownerToToolStepIds.set(ownerIndex, bucket);
|
|
42
42
|
};
|
|
43
43
|
|
|
@@ -94,10 +94,10 @@ export function getIndependentThreads(steps: StepJson[], strategyState: Strategy
|
|
|
94
94
|
const bucket = strategyState?.[toolStepId] ?? ({} as any);
|
|
95
95
|
|
|
96
96
|
for (const inputRoleHandle of inputBindings) {
|
|
97
|
-
const entry = bucket?.[inputRoleHandle as
|
|
97
|
+
const entry = bucket?.[inputRoleHandle as ResourceRoleIdJson] as any;
|
|
98
98
|
if (!entry || entry.resourceShellKind !== 'internalInputPotential') continue;
|
|
99
99
|
|
|
100
|
-
const creatorToolStepHandle = entry?.creationContext?.toolStepHandle as
|
|
100
|
+
const creatorToolStepHandle = entry?.creationContext?.toolStepHandle as ToolStepIdJson | undefined;
|
|
101
101
|
if (!creatorToolStepHandle) {
|
|
102
102
|
throw new Error(
|
|
103
103
|
`Unresolvable internalInputPotential in toolStep '${toolStepId}' (${getOwnerLabel(ownerIndex)}): missing creationContext.toolStepHandle for role '${inputRoleHandle}'`
|
|
Binary file
|