@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.
- package/dist/integrations/firebase/createStep.d.ts +2 -3
- package/dist/integrations/firebase/createStep.js +7 -33
- package/dist/integrations/firebase/createThreadedStrategy.d.ts +2 -0
- package/dist/integrations/firebase/createThreadedStrategy.js +8 -0
- package/dist/integrations/firebase/firebaseAdminHelpers.d.ts +4 -10
- package/dist/integrations/firebase/firebaseAdminHelpers.js +43 -136
- package/dist/integrations/firebase/firebaseAdminInit.d.ts +0 -1
- package/dist/integrations/firebase/firebaseAdminInit.js +0 -1
- package/dist/lookups/lookups.d.ts +221 -0
- package/dist/lookups/lookups.js +23 -0
- package/dist/types/types.d.ts +8 -12
- package/dist/types/types.js +2 -3
- package/dist/utils/creation/resourceCreation.d.ts +18 -18
- package/dist/utils/creation/resourceCreation.js +49 -48
- package/dist/utils/creation/stepCreation.d.ts +7 -48
- package/dist/utils/creation/stepCreation.js +16 -42
- package/dist/utils/creation/threadedStrategyCreation.d.ts +18 -0
- package/dist/utils/creation/threadedStrategyCreation.js +16 -0
- package/dist/utils/extractData.d.ts +9 -10
- package/dist/utils/extractData.js +29 -25
- package/dist/utils/parallelizeSteps.d.ts +1 -2
- package/dist/utils/parallelizeSteps.js +52 -37
- package/dist/utils/resolveStrategyStateChain.d.ts +20 -0
- package/dist/utils/{resolveResourceChain.js → resolveStrategyStateChain.js} +6 -11
- package/dist/utils/roleSpec.d.ts +7 -3
- package/dist/utils/roleSpec.js +0 -1
- package/dist/utils/strategyState.d.ts +11 -6
- package/dist/utils/strategyState.js +41 -12
- package/dist/utils_2/threadedStrategyCreation.d.ts +5 -0
- package/dist/utils_2/threadedStrategyCreation.js +12 -0
- package/package.json +15 -15
- package/src/integrations/firebase/createStep.ts +9 -39
- package/src/integrations/firebase/createThreadedStrategy.ts +19 -0
- package/src/integrations/firebase/firebaseAdminHelpers.ts +61 -163
- package/src/lookups/lookups.ts +25 -0
- package/src/types/types.ts +9 -12
- package/src/utils/creation/resourceCreation.ts +140 -121
- package/src/utils/creation/stepCreation.ts +25 -95
- package/src/utils/creation/threadedStrategyCreation.ts +42 -0
- package/src/utils/extractData.ts +46 -38
- package/src/utils/parallelizeSteps.ts +92 -40
- package/src/utils/resolveStrategyStateChain.ts +58 -0
- package/src/utils/roleSpec.ts +7 -3
- package/src/utils/strategyState.ts +99 -27
- package/src/utils_2/threadedStrategyCreation.ts +19 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/artifacts/artifacts.d.ts +0 -175
- package/dist/artifacts/artifacts.d.ts.map +0 -1
- package/dist/artifacts/artifacts.js +0 -48
- package/dist/artifacts/artifacts.js.map +0 -1
- package/dist/integrations/firebase/createRunnableStrategy.d.ts +0 -3
- package/dist/integrations/firebase/createRunnableStrategy.d.ts.map +0 -1
- package/dist/integrations/firebase/createRunnableStrategy.js +0 -9
- package/dist/integrations/firebase/createRunnableStrategy.js.map +0 -1
- package/dist/integrations/firebase/createStep.d.ts.map +0 -1
- package/dist/integrations/firebase/createStep.js.map +0 -1
- package/dist/integrations/firebase/firebaseAdminHelpers.d.ts.map +0 -1
- package/dist/integrations/firebase/firebaseAdminHelpers.js.map +0 -1
- package/dist/integrations/firebase/firebaseAdminInit.d.ts.map +0 -1
- package/dist/integrations/firebase/firebaseAdminInit.js.map +0 -1
- package/dist/types/types.d.ts.map +0 -1
- package/dist/types/types.js.map +0 -1
- package/dist/utils/bindInputRoleToResource.d.ts +0 -6
- package/dist/utils/bindInputRoleToResource.d.ts.map +0 -1
- package/dist/utils/bindInputRoleToResource.js +0 -25
- package/dist/utils/bindInputRoleToResource.js.map +0 -1
- package/dist/utils/creation/resourceCreation.d.ts.map +0 -1
- package/dist/utils/creation/resourceCreation.js.map +0 -1
- package/dist/utils/creation/runnableStrategyCreation.d.ts +0 -4
- package/dist/utils/creation/runnableStrategyCreation.d.ts.map +0 -1
- package/dist/utils/creation/runnableStrategyCreation.js +0 -17
- package/dist/utils/creation/runnableStrategyCreation.js.map +0 -1
- package/dist/utils/creation/stepCreation.d.ts.map +0 -1
- package/dist/utils/creation/stepCreation.js.map +0 -1
- package/dist/utils/extractData.d.ts.map +0 -1
- package/dist/utils/extractData.js.map +0 -1
- package/dist/utils/parallelizeSteps.d.ts.map +0 -1
- package/dist/utils/parallelizeSteps.js.map +0 -1
- package/dist/utils/resolveResourceChain.d.ts +0 -19
- package/dist/utils/resolveResourceChain.d.ts.map +0 -1
- package/dist/utils/resolveResourceChain.js.map +0 -1
- package/dist/utils/roleSpec.d.ts.map +0 -1
- package/dist/utils/roleSpec.js.map +0 -1
- package/dist/utils/strategyState.d.ts.map +0 -1
- package/dist/utils/strategyState.js.map +0 -1
- package/src/artifacts/artifacts.ts +0 -49
- package/src/integrations/firebase/createRunnableStrategy.ts +0 -18
- package/src/utils/bindInputRoleToResource.ts +0 -53
- package/src/utils/creation/runnableStrategyCreation.ts +0 -28
- package/src/utils/resolveResourceChain.ts +0 -52
|
@@ -1,121 +1,140 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
ResourceId,
|
|
6
|
-
Resource,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
1
|
+
import type {
|
|
2
|
+
ToolStepRoleAddress,
|
|
3
|
+
ExternalInputPotential,
|
|
4
|
+
InternalInputPotential,
|
|
5
|
+
ResourceId,
|
|
6
|
+
Resource,
|
|
7
|
+
ResourcePointer,
|
|
8
|
+
ResourceTypeHandle,
|
|
9
|
+
StrategyProvenance,
|
|
10
|
+
Provenance,
|
|
11
|
+
StrategyTraceHandle,
|
|
12
|
+
} from '@toolproof-core/genesis';
|
|
13
|
+
|
|
14
|
+
type RuntimeProvenance = Extract<Provenance, { provenanceKind: 'runtime' }>;
|
|
15
|
+
|
|
16
|
+
export interface OutputPotential {
|
|
17
|
+
id: ResourceId;
|
|
18
|
+
resourceTypeHandle: ResourceTypeHandle;
|
|
19
|
+
toolStepRoleAddress?: ToolStepRoleAddress;
|
|
20
|
+
strategyTraceHandle?: StrategyTraceHandle;
|
|
21
|
+
provenanceKind?: Provenance['provenanceKind'];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function createExternalInputPotential(): ExternalInputPotential {
|
|
25
|
+
return {
|
|
26
|
+
strategyStateInputKind: 'externalInputPotential',
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function createInternalInputPotential(
|
|
31
|
+
toolStepRoleAddress: ToolStepRoleAddress,
|
|
32
|
+
): InternalInputPotential {
|
|
33
|
+
return {
|
|
34
|
+
strategyStateInputKind: 'internalInputPotential',
|
|
35
|
+
toolStepRoleAddress,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function createStrategyProvenance(
|
|
40
|
+
strategyTraceHandle: StrategyTraceHandle,
|
|
41
|
+
toolStepRoleAddress: ToolStepRoleAddress,
|
|
42
|
+
): StrategyProvenance {
|
|
43
|
+
return {
|
|
44
|
+
provenanceKind: 'strategy',
|
|
45
|
+
strategyTraceHandle,
|
|
46
|
+
toolStepRoleAddress,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function createRuntimeProvenance(): RuntimeProvenance {
|
|
51
|
+
return {
|
|
52
|
+
provenanceKind: 'runtime',
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function createResourcePointer(
|
|
57
|
+
id: ResourceId,
|
|
58
|
+
resourceTypeHandle: ResourceTypeHandle,
|
|
59
|
+
provenance: Provenance,
|
|
60
|
+
): ResourcePointer {
|
|
61
|
+
return {
|
|
62
|
+
id,
|
|
63
|
+
resourceTypeHandle,
|
|
64
|
+
provenance,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function createResource(
|
|
69
|
+
resourcePointer: ResourcePointer,
|
|
70
|
+
projection: unknown,
|
|
71
|
+
): Resource {
|
|
72
|
+
return {
|
|
73
|
+
...resourcePointer,
|
|
74
|
+
projection,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function createMaterializedFromOutputPotential(
|
|
79
|
+
outputPotential: OutputPotential,
|
|
80
|
+
projection: unknown,
|
|
81
|
+
): Resource {
|
|
82
|
+
const provenance = outputPotential.provenanceKind === 'runtime'
|
|
83
|
+
? createRuntimeProvenance()
|
|
84
|
+
: createStrategyProvenance(
|
|
85
|
+
requireStrategyTraceHandle(outputPotential.strategyTraceHandle),
|
|
86
|
+
requireToolStepRoleAddress(outputPotential.toolStepRoleAddress),
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const resourcePointer = createResourcePointer(
|
|
90
|
+
outputPotential.id,
|
|
91
|
+
outputPotential.resourceTypeHandle,
|
|
92
|
+
provenance,
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
return createResource(resourcePointer, projection);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function createMaterializedFromPotential(
|
|
99
|
+
outputPotential: OutputPotential,
|
|
100
|
+
projection: unknown,
|
|
101
|
+
): Resource {
|
|
102
|
+
return createMaterializedFromOutputPotential(outputPotential, projection);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function createOutputPotential(
|
|
106
|
+
id: ResourceId,
|
|
107
|
+
resourceTypeHandle: ResourceTypeHandle,
|
|
108
|
+
toolStepRoleAddress?: ToolStepRoleAddress,
|
|
109
|
+
strategyTraceHandle?: StrategyTraceHandle,
|
|
110
|
+
provenanceKind?: Provenance['provenanceKind'],
|
|
111
|
+
): OutputPotential {
|
|
112
|
+
return {
|
|
113
|
+
id,
|
|
114
|
+
resourceTypeHandle,
|
|
115
|
+
...(toolStepRoleAddress ? { toolStepRoleAddress } : {}),
|
|
116
|
+
...(strategyTraceHandle ? { strategyTraceHandle } : {}),
|
|
117
|
+
...(provenanceKind ? { provenanceKind } : {}),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function requireStrategyTraceHandle(
|
|
122
|
+
strategyTraceHandle: StrategyTraceHandle | undefined,
|
|
123
|
+
): StrategyTraceHandle {
|
|
124
|
+
if (!strategyTraceHandle) {
|
|
125
|
+
throw new Error('strategyTraceHandle is required to materialize a strategy output potential');
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return strategyTraceHandle;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function requireToolStepRoleAddress(
|
|
132
|
+
toolStepRoleAddress: ToolStepRoleAddress | undefined,
|
|
133
|
+
): ToolStepRoleAddress {
|
|
134
|
+
if (!toolStepRoleAddress) {
|
|
135
|
+
throw new Error('toolStepRoleAddress is required to materialize a strategy output potential');
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return toolStepRoleAddress;
|
|
139
|
+
}
|
|
140
|
+
|
|
@@ -5,39 +5,10 @@ import type {
|
|
|
5
5
|
Tool,
|
|
6
6
|
ToolStep,
|
|
7
7
|
WhileStep,
|
|
8
|
-
} from '@toolproof-core/
|
|
9
|
-
import { CONSTANTS } from '../../
|
|
8
|
+
} from '@toolproof-core/genesis';
|
|
9
|
+
import { CONSTANTS } from '../../lookups/lookups.js';
|
|
10
10
|
import { getInputRoleNames, getOutputRoleNames } from '../roleSpec.js';
|
|
11
11
|
|
|
12
|
-
type ToolStepId = string;
|
|
13
|
-
type BranchStepId = string;
|
|
14
|
-
type ForStepId = string;
|
|
15
|
-
type WhileStepId = string;
|
|
16
|
-
|
|
17
|
-
type ToolStepWithId = ToolStep & { id: ToolStepId };
|
|
18
|
-
type BranchStepWithId = BranchStep & { id: BranchStepId };
|
|
19
|
-
type ForStepWithId = ForStep & { id: ForStepId };
|
|
20
|
-
type WhileStepWithId = WhileStep & { id: WhileStepId };
|
|
21
|
-
|
|
22
|
-
export type LoopStepBuildIdentities =
|
|
23
|
-
| {
|
|
24
|
-
stepKind: typeof CONSTANTS.Enums.StepKind.for;
|
|
25
|
-
stepId: ForStepId;
|
|
26
|
-
whatId: ToolStepId;
|
|
27
|
-
whenId: ToolStepId;
|
|
28
|
-
}
|
|
29
|
-
| {
|
|
30
|
-
stepKind: typeof CONSTANTS.Enums.StepKind.while;
|
|
31
|
-
stepId: WhileStepId;
|
|
32
|
-
whatId: ToolStepId;
|
|
33
|
-
whenId: ToolStepId;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export type BranchCaseBuildIdentities = {
|
|
37
|
-
whatId: ToolStepId;
|
|
38
|
-
whenId: ToolStepId;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
12
|
function assertNonEmpty<T>(arr: T[], msg: string): asserts arr is [T, ...T[]] {
|
|
42
13
|
if (arr.length === 0) {
|
|
43
14
|
throw new Error(msg);
|
|
@@ -53,113 +24,72 @@ function getRoleBindingSpec(tool: Tool): ToolStep['roleBindingSpec'] {
|
|
|
53
24
|
|
|
54
25
|
export function buildToolStepFromTool(
|
|
55
26
|
tool: Tool,
|
|
56
|
-
|
|
57
|
-
): ToolStepWithId {
|
|
27
|
+
): ToolStep {
|
|
58
28
|
return {
|
|
59
|
-
id,
|
|
60
29
|
stepKind: CONSTANTS.Enums.StepKind.tool,
|
|
61
|
-
|
|
30
|
+
toolHandle: tool.handle,
|
|
62
31
|
roleBindingSpec: getRoleBindingSpec(tool),
|
|
63
|
-
}
|
|
32
|
+
};
|
|
64
33
|
}
|
|
65
34
|
|
|
66
35
|
export function buildLoopStepFromToolPair(
|
|
67
36
|
whatTool: Tool,
|
|
68
37
|
whenTool: Tool,
|
|
69
|
-
|
|
38
|
+
stepKind: typeof CONSTANTS.Enums.StepKind.for | typeof CONSTANTS.Enums.StepKind.while,
|
|
70
39
|
): ForStep | WhileStep {
|
|
71
|
-
const what = buildToolStepFromTool(whatTool
|
|
72
|
-
const when = buildToolStepFromTool(whenTool
|
|
40
|
+
const what = buildToolStepFromTool(whatTool);
|
|
41
|
+
const when = buildToolStepFromTool(whenTool);
|
|
73
42
|
|
|
74
|
-
if (
|
|
43
|
+
if (stepKind === CONSTANTS.Enums.StepKind.for) {
|
|
75
44
|
return {
|
|
76
|
-
id: identities.stepId,
|
|
77
45
|
stepKind: CONSTANTS.Enums.StepKind.for,
|
|
78
46
|
case: { what, when },
|
|
79
|
-
}
|
|
47
|
+
};
|
|
80
48
|
}
|
|
81
49
|
|
|
82
50
|
return {
|
|
83
|
-
id: identities.stepId,
|
|
84
51
|
stepKind: CONSTANTS.Enums.StepKind.while,
|
|
85
52
|
case: { what, when },
|
|
86
|
-
}
|
|
53
|
+
};
|
|
87
54
|
}
|
|
88
55
|
|
|
89
56
|
export function buildBranchStepFromToolPairs(
|
|
90
57
|
cases: Array<{ whatTool: Tool; whenTool: Tool }>,
|
|
91
|
-
|
|
92
|
-
caseIdentities: BranchCaseBuildIdentities[],
|
|
93
|
-
): BranchStepWithId {
|
|
94
|
-
if (cases.length !== caseIdentities.length) {
|
|
95
|
-
throw new Error('buildBranchStepFromToolPairs requires one id pair per case');
|
|
96
|
-
}
|
|
97
|
-
|
|
58
|
+
): BranchStep {
|
|
98
59
|
const resolved = cases.map(({ whatTool, whenTool }, index) => {
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
if (!identities) {
|
|
102
|
-
throw new Error(`Missing case identities for case index ${index}`);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const what = buildToolStepFromTool(whatTool, identities.whatId);
|
|
106
|
-
const when = buildToolStepFromTool(whenTool, identities.whenId);
|
|
60
|
+
const what = buildToolStepFromTool(whatTool);
|
|
61
|
+
const when = buildToolStepFromTool(whenTool);
|
|
107
62
|
return { what, when } satisfies Case;
|
|
108
63
|
});
|
|
109
64
|
|
|
110
65
|
assertNonEmpty(resolved, 'buildBranchStepFromToolPairs requires at least one case');
|
|
111
66
|
|
|
112
67
|
return {
|
|
113
|
-
id: branchId,
|
|
114
68
|
stepKind: CONSTANTS.Enums.StepKind.branch,
|
|
115
69
|
cases: resolved,
|
|
116
|
-
}
|
|
70
|
+
};
|
|
117
71
|
}
|
|
118
72
|
|
|
119
|
-
export function
|
|
73
|
+
export function cloneForStep(
|
|
120
74
|
forStep: ForStep,
|
|
121
|
-
|
|
122
|
-
stepId: ForStepId;
|
|
123
|
-
whatId: ToolStepId;
|
|
124
|
-
whenId: ToolStepId;
|
|
125
|
-
},
|
|
126
|
-
): ForStepWithId {
|
|
75
|
+
): ForStep {
|
|
127
76
|
return {
|
|
128
|
-
id: identities.stepId,
|
|
129
77
|
stepKind: CONSTANTS.Enums.StepKind.for,
|
|
130
78
|
case: {
|
|
131
|
-
what: {
|
|
132
|
-
|
|
133
|
-
id: identities.whatId,
|
|
134
|
-
},
|
|
135
|
-
when: {
|
|
136
|
-
...forStep.case.when,
|
|
137
|
-
id: identities.whenId,
|
|
138
|
-
},
|
|
79
|
+
what: { ...forStep.case.what },
|
|
80
|
+
when: { ...forStep.case.when },
|
|
139
81
|
},
|
|
140
|
-
}
|
|
82
|
+
};
|
|
141
83
|
}
|
|
142
84
|
|
|
143
|
-
export function
|
|
85
|
+
export function cloneWhileStep(
|
|
144
86
|
whileStep: WhileStep,
|
|
145
|
-
|
|
146
|
-
stepId: WhileStepId;
|
|
147
|
-
whatId: ToolStepId;
|
|
148
|
-
whenId: ToolStepId;
|
|
149
|
-
},
|
|
150
|
-
): WhileStepWithId {
|
|
87
|
+
): WhileStep {
|
|
151
88
|
return {
|
|
152
|
-
id: identities.stepId,
|
|
153
89
|
stepKind: CONSTANTS.Enums.StepKind.while,
|
|
154
90
|
case: {
|
|
155
|
-
what: {
|
|
156
|
-
|
|
157
|
-
id: identities.whatId,
|
|
158
|
-
},
|
|
159
|
-
when: {
|
|
160
|
-
...whileStep.case.when,
|
|
161
|
-
id: identities.whenId,
|
|
162
|
-
},
|
|
91
|
+
what: { ...whileStep.case.what },
|
|
92
|
+
when: { ...whileStep.case.when },
|
|
163
93
|
},
|
|
164
|
-
}
|
|
94
|
+
};
|
|
165
95
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Step,
|
|
3
|
+
StrategyHandle,
|
|
4
|
+
} from '@toolproof-core/genesis';
|
|
5
|
+
import { getIndependentThreads } from '../parallelizeSteps.js';
|
|
6
|
+
import { CONSTANTS } from '../../lookups/lookups.js';
|
|
7
|
+
|
|
8
|
+
export type ThreadableStrategy<TStrategyState = unknown> = {
|
|
9
|
+
handle: StrategyHandle;
|
|
10
|
+
strategyState: TStrategyState;
|
|
11
|
+
} & (
|
|
12
|
+
| { steps: Step[] }
|
|
13
|
+
| { stepsByThreadIndex: Step[][] }
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
export type ThreadedStrategyLike<TStrategyState = unknown> = {
|
|
17
|
+
handle: StrategyHandle;
|
|
18
|
+
strategyKind: typeof CONSTANTS.Enums.StrategyKind.threaded;
|
|
19
|
+
stepsByThreadIndex: Step[][];
|
|
20
|
+
strategyState: TStrategyState;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export function getThreadedStrategyStepGroups<TStrategyState>(strategy: ThreadableStrategy<TStrategyState>): Step[][] {
|
|
24
|
+
if ('steps' in strategy) {
|
|
25
|
+
return getIndependentThreads(strategy.steps, strategy.strategyState as any);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return strategy.stepsByThreadIndex;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function buildThreadedStrategy<TStrategyState>(
|
|
32
|
+
threadStepGroups: Step[][],
|
|
33
|
+
threadedStrategyHandle: StrategyHandle,
|
|
34
|
+
strategy: ThreadableStrategy<TStrategyState>,
|
|
35
|
+
): ThreadedStrategyLike<TStrategyState> {
|
|
36
|
+
return {
|
|
37
|
+
handle: threadedStrategyHandle,
|
|
38
|
+
strategyKind: CONSTANTS.Enums.StrategyKind.threaded,
|
|
39
|
+
stepsByThreadIndex: threadStepGroups,
|
|
40
|
+
strategyState: strategy.strategyState,
|
|
41
|
+
};
|
|
42
|
+
}
|
package/src/utils/extractData.ts
CHANGED
|
@@ -1,44 +1,54 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
RoleName,
|
|
3
|
-
|
|
4
|
-
Strategy,
|
|
5
|
-
ToolId,
|
|
3
|
+
ToolHandle,
|
|
6
4
|
Tool,
|
|
7
5
|
ToolStep,
|
|
8
6
|
ResourceId,
|
|
9
|
-
|
|
7
|
+
ResourceTypeHandle,
|
|
10
8
|
Resource,
|
|
11
|
-
} from '@toolproof-core/
|
|
12
|
-
import { CONSTANTS } from '../artifacts/artifacts.js';
|
|
9
|
+
} from '@toolproof-core/genesis';
|
|
13
10
|
import {
|
|
14
11
|
extractToolStepsFromStrategy,
|
|
15
12
|
getInputRoleEntries,
|
|
16
13
|
getOutputRoleEntries,
|
|
17
14
|
toToolRoleDescriptor,
|
|
15
|
+
type StrategyStepGraph,
|
|
18
16
|
type ToolRoleDescriptor,
|
|
19
17
|
} from './roleSpec.js';
|
|
20
18
|
|
|
19
|
+
const ERROR_OUTPUT_ROLE_NAME = 'ErrorOutput' as RoleName;
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
21
|
+
function extractResourceTypeHandleFromRoleValue(toolRoleValue: ToolRoleDescriptor): ResourceTypeHandle | null {
|
|
22
|
+
const typeRef = toolRoleValue.typeRef;
|
|
23
|
+
|
|
24
|
+
if ('resourceTypeHandle' in typeRef) {
|
|
25
|
+
return typeRef.resourceTypeHandle;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
export function extractToolHandlesFromUnthreadedStrategy(unthreadedStrategy: StrategyStepGraph): ToolHandle[] {
|
|
33
|
+
const toolSteps = extractToolStepsFromUnthreadedStrategy(unthreadedStrategy);
|
|
34
|
+
const ids = new Set<ToolHandle>();
|
|
25
35
|
for (const jStep of toolSteps) {
|
|
26
|
-
ids.add(jStep.
|
|
36
|
+
ids.add(jStep.toolHandle);
|
|
27
37
|
}
|
|
28
38
|
return Array.from(ids);
|
|
29
39
|
}
|
|
30
40
|
|
|
31
|
-
export function
|
|
32
|
-
return extractToolStepsFromStrategy(
|
|
41
|
+
export function extractToolStepsFromUnthreadedStrategy(unthreadedStrategy: StrategyStepGraph): ToolStep[] {
|
|
42
|
+
return extractToolStepsFromStrategy(unthreadedStrategy);
|
|
33
43
|
}
|
|
34
44
|
|
|
35
45
|
|
|
36
|
-
export function
|
|
46
|
+
export function extractRoleMapFromUnthreadedStrategy(unthreadedStrategy: StrategyStepGraph, toolMap: Map<ToolHandle, Tool>): Map<RoleName, ToolRoleDescriptor> {
|
|
37
47
|
const roleMap = new Map<RoleName, ToolRoleDescriptor>();
|
|
38
|
-
const
|
|
48
|
+
const toolHandles = extractToolHandlesFromUnthreadedStrategy(unthreadedStrategy);
|
|
39
49
|
|
|
40
|
-
for (const
|
|
41
|
-
const tool = toolMap.get(
|
|
50
|
+
for (const toolHandle of toolHandles) {
|
|
51
|
+
const tool = toolMap.get(toolHandle);
|
|
42
52
|
if (!tool) continue;
|
|
43
53
|
|
|
44
54
|
for (const entry of getInputRoleEntries(tool)) {
|
|
@@ -52,23 +62,21 @@ export function extractRoleMapFromRawStrategy(rawStrategy: Strategy, toolMap: Ma
|
|
|
52
62
|
return roleMap;
|
|
53
63
|
}
|
|
54
64
|
|
|
55
|
-
export function extractSingleNonErrorOutputTypeId(tool: Tool):
|
|
56
|
-
const
|
|
57
|
-
const outputEntries = getOutputRoleEntries(tool).filter(([roleName]) => roleName !== errorRoleId);
|
|
65
|
+
export function extractSingleNonErrorOutputTypeId(tool: Tool): ResourceTypeHandle | null {
|
|
66
|
+
const outputEntries = getOutputRoleEntries(tool).filter(([roleName]) => roleName !== ERROR_OUTPUT_ROLE_NAME);
|
|
58
67
|
if (!outputEntries || !outputEntries[0] || outputEntries.length !== 1) {
|
|
59
|
-
throw new Error(`Tool ${tool.
|
|
68
|
+
throw new Error(`Tool ${tool.handle} must have exactly one non-error output role to be branchable/loopable`);
|
|
60
69
|
} // ATTENTION_PUREIFY
|
|
61
|
-
|
|
62
|
-
return outputRole.resourceTypeId;
|
|
70
|
+
return extractResourceTypeHandleFromRoleValue(toToolRoleDescriptor(outputEntries[0]));
|
|
63
71
|
}
|
|
64
72
|
|
|
65
73
|
|
|
66
74
|
|
|
67
75
|
export function extractResourceMapForType<TResource extends Resource = Resource>(
|
|
68
|
-
resourcesByType: Partial<Record<
|
|
69
|
-
|
|
76
|
+
resourcesByType: Partial<Record<ResourceTypeHandle, TResource[]>>,
|
|
77
|
+
resourceTypeHandle: ResourceTypeHandle
|
|
70
78
|
): Map<ResourceId, TResource> {
|
|
71
|
-
const resources = resourcesByType[
|
|
79
|
+
const resources = resourcesByType[resourceTypeHandle] ?? [];
|
|
72
80
|
const map = new Map<ResourceId, TResource>();
|
|
73
81
|
|
|
74
82
|
for (const resource of resources) {
|
|
@@ -79,34 +87,34 @@ export function extractResourceMapForType<TResource extends Resource = Resource>
|
|
|
79
87
|
}
|
|
80
88
|
|
|
81
89
|
// Only use this for resource types whose nuclei are entity-like objects with their own intrinsic id.
|
|
82
|
-
export function
|
|
90
|
+
export function extractIdKeyedValueMapForType<
|
|
83
91
|
TKey extends string = string,
|
|
84
|
-
|
|
92
|
+
TValue extends { id: string | number | boolean } = { id: string | number | boolean },
|
|
85
93
|
TResource extends Resource = Resource
|
|
86
94
|
>(
|
|
87
|
-
resourcesByType: Partial<Record<
|
|
88
|
-
|
|
89
|
-
): Map<TKey,
|
|
90
|
-
const resourceMap = extractResourceMapForType<TResource>(resourcesByType,
|
|
91
|
-
const out = new Map<TKey,
|
|
95
|
+
resourcesByType: Partial<Record<ResourceTypeHandle, TResource[]>>,
|
|
96
|
+
resourceTypeHandle: ResourceTypeHandle,
|
|
97
|
+
): Map<TKey, TValue> {
|
|
98
|
+
const resourceMap = extractResourceMapForType<TResource>(resourcesByType, resourceTypeHandle);
|
|
99
|
+
const out = new Map<TKey, TValue>();
|
|
92
100
|
|
|
93
101
|
for (const resource of resourceMap.values()) {
|
|
94
|
-
const data =
|
|
102
|
+
const data = resource.projection as unknown;
|
|
95
103
|
if (data === null || data === undefined) {
|
|
96
104
|
throw new Error(
|
|
97
|
-
`Expected resource '${resource.id}' of type '${
|
|
105
|
+
`Expected resource '${resource.id}' of type '${resourceTypeHandle}' to have a projection`
|
|
98
106
|
);
|
|
99
107
|
}
|
|
100
108
|
if (typeof data !== 'object') {
|
|
101
109
|
throw new Error(
|
|
102
|
-
`Expected resource '${resource.id}' of type '${
|
|
110
|
+
`Expected resource '${resource.id}' of type '${resourceTypeHandle}' to have an object projection with id`
|
|
103
111
|
);
|
|
104
112
|
}
|
|
105
113
|
|
|
106
114
|
const maybeId = (data as any).id as unknown;
|
|
107
115
|
if (maybeId === null || maybeId === undefined) {
|
|
108
116
|
throw new Error(
|
|
109
|
-
`Expected resource '${resource.id}' of type '${
|
|
117
|
+
`Expected resource '${resource.id}' of type '${resourceTypeHandle}' to have projection.id`
|
|
110
118
|
);
|
|
111
119
|
}
|
|
112
120
|
if (
|
|
@@ -115,11 +123,11 @@ export function extractIdKeyedNucleusMapForType<
|
|
|
115
123
|
typeof maybeId !== 'boolean'
|
|
116
124
|
) {
|
|
117
125
|
throw new Error(
|
|
118
|
-
`Expected resource '${resource.id}' of type '${
|
|
126
|
+
`Expected resource '${resource.id}' of type '${resourceTypeHandle}' to have projection.id as string, number, or boolean`
|
|
119
127
|
);
|
|
120
128
|
}
|
|
121
129
|
|
|
122
|
-
const value = data as
|
|
130
|
+
const value = data as TValue;
|
|
123
131
|
const key = String(maybeId) as TKey;
|
|
124
132
|
|
|
125
133
|
out.set(key, value);
|