@toolproof-core/lib 1.0.31 → 1.0.32
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/createRunnableStrategy.d.ts +2 -2
- package/dist/integrations/firebase/createRunnableStrategy.d.ts.map +1 -1
- package/dist/integrations/firebase/createRunnableStrategy.js.map +1 -1
- package/dist/integrations/firebase/createStep.d.ts +8 -8
- package/dist/integrations/firebase/createStep.d.ts.map +1 -1
- package/dist/integrations/firebase/createStep.js.map +1 -1
- package/dist/integrations/firebase/firebaseAdminHelpers.d.ts +3 -3
- package/dist/integrations/firebase/firebaseAdminHelpers.d.ts.map +1 -1
- package/dist/integrations/firebase/firebaseAdminHelpers.js.map +1 -1
- package/dist/types/types.d.ts +3 -3
- package/dist/types/types.d.ts.map +1 -1
- package/dist/utils/bindInputRoleToResource.d.ts +4 -4
- package/dist/utils/bindInputRoleToResource.d.ts.map +1 -1
- package/dist/utils/bindInputRoleToResource.js.map +1 -1
- package/dist/utils/creation/resourceCreation.d.ts +8 -8
- package/dist/utils/creation/resourceCreation.d.ts.map +1 -1
- package/dist/utils/creation/resourceCreation.js.map +1 -1
- package/dist/utils/creation/runnableStrategyCreation.d.ts +3 -3
- package/dist/utils/creation/runnableStrategyCreation.d.ts.map +1 -1
- package/dist/utils/creation/runnableStrategyCreation.js.map +1 -1
- package/dist/utils/creation/stepCreation.d.ts +24 -24
- package/dist/utils/creation/stepCreation.d.ts.map +1 -1
- package/dist/utils/creation/stepCreation.js.map +1 -1
- package/dist/utils/extractData.d.ts +7 -7
- package/dist/utils/extractData.d.ts.map +1 -1
- package/dist/utils/extractData.js.map +1 -1
- package/dist/utils/parallelizeSteps.d.ts +2 -2
- package/dist/utils/parallelizeSteps.d.ts.map +1 -1
- package/dist/utils/parallelizeSteps.js.map +1 -1
- package/dist/utils/resolveResourceChain.d.ts +9 -9
- package/dist/utils/resolveResourceChain.d.ts.map +1 -1
- package/dist/utils/resolveResourceChain.js.map +1 -1
- package/package.json +2 -2
- package/src/integrations/firebase/createRunnableStrategy.ts +2 -2
- package/src/integrations/firebase/createStep.ts +13 -13
- package/src/integrations/firebase/firebaseAdminHelpers.ts +8 -8
- package/src/types/types.ts +5 -5
- package/src/utils/bindInputRoleToResource.ts +22 -22
- package/src/utils/creation/resourceCreation.ts +25 -25
- package/src/utils/creation/runnableStrategyCreation.ts +13 -13
- package/src/utils/creation/stepCreation.ts +42 -42
- package/src/utils/extractData.ts +33 -33
- package/src/utils/parallelizeSteps.ts +19 -19
- package/src/utils/resolveResourceChain.ts +21 -21
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
BranchStep,
|
|
3
|
+
ForStep,
|
|
4
|
+
Tool,
|
|
5
|
+
ToolStep,
|
|
6
|
+
WhileStep,
|
|
7
7
|
} from '@toolproof-core/schema';
|
|
8
8
|
import { CONSTANTS } from '../../artifacts/artifacts.js';
|
|
9
9
|
import {
|
|
@@ -15,15 +15,15 @@ import {
|
|
|
15
15
|
} from '../../utils/creation/stepCreation.js';
|
|
16
16
|
import { getNewStepId } from './firebaseAdminHelpers.js';
|
|
17
17
|
|
|
18
|
-
export function createToolStepFromTool(tool:
|
|
18
|
+
export function createToolStepFromTool(tool: Tool): ToolStep {
|
|
19
19
|
return buildToolStepFromTool(tool, getNewStepId(CONSTANTS.Enums.StepKind.tool));
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export function createLoopStepFromToolPair(
|
|
23
|
-
whatTool:
|
|
24
|
-
whenTool:
|
|
23
|
+
whatTool: Tool,
|
|
24
|
+
whenTool: Tool,
|
|
25
25
|
stepKind: typeof CONSTANTS.Enums.StepKind.for | typeof CONSTANTS.Enums.StepKind.while,
|
|
26
|
-
):
|
|
26
|
+
): ForStep | WhileStep {
|
|
27
27
|
if (stepKind === CONSTANTS.Enums.StepKind.for) {
|
|
28
28
|
return buildLoopStepFromToolPair(whatTool, whenTool, {
|
|
29
29
|
stepKind,
|
|
@@ -42,8 +42,8 @@ export function createLoopStepFromToolPair(
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
export function createBranchStepFromToolPairs(
|
|
45
|
-
cases: Array<{ whatTool:
|
|
46
|
-
):
|
|
45
|
+
cases: Array<{ whatTool: Tool; whenTool: Tool }>,
|
|
46
|
+
): BranchStep {
|
|
47
47
|
return buildBranchStepFromToolPairs(
|
|
48
48
|
cases,
|
|
49
49
|
getNewStepId(CONSTANTS.Enums.StepKind.branch),
|
|
@@ -54,7 +54,7 @@ export function createBranchStepFromToolPairs(
|
|
|
54
54
|
);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
export function cloneForStep(forStep:
|
|
57
|
+
export function cloneForStep(forStep: ForStep): ForStep {
|
|
58
58
|
return cloneForStepWithIdentities(forStep, {
|
|
59
59
|
stepId: getNewStepId(CONSTANTS.Enums.StepKind.for),
|
|
60
60
|
whatId: getNewStepId(CONSTANTS.Enums.StepKind.tool),
|
|
@@ -62,7 +62,7 @@ export function cloneForStep(forStep: ForStepJson): ForStepJson {
|
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
export function cloneWhileStep(whileStep:
|
|
65
|
+
export function cloneWhileStep(whileStep: WhileStep): WhileStep {
|
|
66
66
|
return cloneWhileStepWithIdentities(whileStep, {
|
|
67
67
|
stepId: getNewStepId(CONSTANTS.Enums.StepKind.while),
|
|
68
68
|
whatId: getNewStepId(CONSTANTS.Enums.StepKind.tool),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
Resource,
|
|
3
|
+
ResourceTypeId,
|
|
4
|
+
StepKind,
|
|
5
5
|
} from '@toolproof-core/schema';
|
|
6
6
|
import type {
|
|
7
7
|
IdName,
|
|
@@ -31,7 +31,7 @@ export function getNewId<K extends IdName>(idName: K): IdStringByIdName<K> {
|
|
|
31
31
|
return (prefix + docRef.id) as IdStringByIdName<K>;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
export function getNewStepId<K extends
|
|
34
|
+
export function getNewStepId<K extends StepKind>(stepKind: K): StepIdStringByStepKind<K> {
|
|
35
35
|
const idName = `${capitalizeFirst(stepKind)}StepId` as IdName;
|
|
36
36
|
|
|
37
37
|
if (!(idName in MAPPINGS.IdNameToIdPrefix)) {
|
|
@@ -42,13 +42,13 @@ export function getNewStepId<K extends StepKindJson>(stepKind: K): StepIdStringB
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
export async function listResources(
|
|
45
|
-
resourceTypeIds:
|
|
45
|
+
resourceTypeIds: ResourceTypeId[],
|
|
46
46
|
): Promise<ResourcesByType> {
|
|
47
47
|
const bucketResources = storageAdmin.bucket(CONSTANTS.Persistence.Buckets.tp_resources);
|
|
48
48
|
const bucketStrategies = storageAdmin.bucket(CONSTANTS.Persistence.Buckets.tp_strategies);
|
|
49
49
|
|
|
50
50
|
async function fetchFilesUnder(
|
|
51
|
-
resourceTypeId:
|
|
51
|
+
resourceTypeId: ResourceTypeId,
|
|
52
52
|
): Promise<Array<{ data: unknown; meta: any; name: string }>> {
|
|
53
53
|
const bucket = resourceTypeId === CONSTANTS.Cosmos.TYPE_RunnableStrategy
|
|
54
54
|
? bucketStrategies
|
|
@@ -81,7 +81,7 @@ export async function listResources(
|
|
|
81
81
|
const entries = await Promise.all(
|
|
82
82
|
resourceTypeIds.map(async (resourceTypeId) => {
|
|
83
83
|
const rows = await fetchFilesUnder(resourceTypeId);
|
|
84
|
-
const items:
|
|
84
|
+
const items: Resource[] = rows.map(({ data, meta, name }) => {
|
|
85
85
|
const flat = meta?.metadata ?? {};
|
|
86
86
|
const root: any = {};
|
|
87
87
|
|
|
@@ -184,7 +184,7 @@ export async function listResources(
|
|
|
184
184
|
timestamp: timestamp as string,
|
|
185
185
|
path: resourcePath as string,
|
|
186
186
|
nucleus: data as any,
|
|
187
|
-
} as unknown as
|
|
187
|
+
} as unknown as Resource;
|
|
188
188
|
});
|
|
189
189
|
|
|
190
190
|
return [resourceTypeId, items] as const;
|
package/src/types/types.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
StepKind,
|
|
3
|
+
Resource,
|
|
4
|
+
ResourceTypeId,
|
|
5
5
|
} from '@toolproof-core/schema';
|
|
6
6
|
import { CONSTANTS } from '../artifacts/artifacts.js';
|
|
7
7
|
import { MAPPINGS } from '../artifacts/artifacts.js';
|
|
@@ -12,13 +12,13 @@ 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<ResourceTypeId, Resource[]>;
|
|
16
16
|
|
|
17
17
|
export type IdName = keyof typeof MAPPINGS.IdNameToIdPrefix;
|
|
18
18
|
|
|
19
19
|
export type IdStringByIdName<K extends IdName> = `${(typeof MAPPINGS.IdNameToIdPrefix)[K]}${string}`;
|
|
20
20
|
|
|
21
|
-
export type StepIdStringByStepKind<K extends
|
|
21
|
+
export type StepIdStringByStepKind<K extends StepKind> = `${(typeof MAPPINGS.StepKindToStepIdPrefix)[K]}${string}`;
|
|
22
22
|
|
|
23
23
|
export interface NucleusBaseSmall<T extends string = string> {
|
|
24
24
|
id: T;
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
CreationContext,
|
|
3
|
+
ExternalInputPotentialShell,
|
|
4
|
+
InternalInputPotentialShell,
|
|
5
|
+
OutputPotentialShell,
|
|
6
|
+
Resource,
|
|
7
|
+
ResourcePotential,
|
|
8
|
+
StrategyState,
|
|
9
9
|
} from '@toolproof-core/schema';
|
|
10
10
|
import { CONSTANTS } from '../artifacts/artifacts.js';
|
|
11
11
|
import { resolveResourceChain } from './resolveResourceChain.js';
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
export function bindInputResInStrategyState(
|
|
15
|
-
strategyState:
|
|
16
|
-
target:
|
|
17
|
-
resource:
|
|
18
|
-
):
|
|
15
|
+
strategyState: StrategyState,
|
|
16
|
+
target: CreationContext,
|
|
17
|
+
resource: Resource
|
|
18
|
+
): StrategyState {
|
|
19
19
|
const bucket = strategyState[target.toolStepId] ?? {};
|
|
20
20
|
return {
|
|
21
21
|
...strategyState,
|
|
@@ -27,13 +27,13 @@ export function bindInputResInStrategyState(
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export function bindInputRefInStrategyState(
|
|
30
|
-
strategyState:
|
|
31
|
-
target:
|
|
32
|
-
source:
|
|
33
|
-
):
|
|
30
|
+
strategyState: StrategyState,
|
|
31
|
+
target: CreationContext,
|
|
32
|
+
source: CreationContext
|
|
33
|
+
): StrategyState {
|
|
34
34
|
const sourceEntry = strategyState?.[source.toolStepId]?.[source.resourceRoleId] as (
|
|
35
|
-
|
|
|
36
|
-
|
|
|
35
|
+
| Resource
|
|
36
|
+
| ResourcePotential
|
|
37
37
|
| undefined
|
|
38
38
|
);
|
|
39
39
|
if (!sourceEntry) {
|
|
@@ -55,7 +55,7 @@ export function bindInputRefInStrategyState(
|
|
|
55
55
|
|
|
56
56
|
if (result.status === CONSTANTS.Enums.ResourceShellKind.externalInputPotential) {
|
|
57
57
|
const externalInput = result.entry;
|
|
58
|
-
const reusedExternalInput:
|
|
58
|
+
const reusedExternalInput: ExternalInputPotentialShell = {
|
|
59
59
|
id: externalInput.id,
|
|
60
60
|
resourceTypeId: externalInput.resourceTypeId,
|
|
61
61
|
resourceShellKind: CONSTANTS.Enums.ResourceShellKind.externalInputPotential,
|
|
@@ -71,7 +71,7 @@ export function bindInputRefInStrategyState(
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
if (result.status === CONSTANTS.Enums.ResourceShellKind.outputPotential) {
|
|
74
|
-
const potentialInput:
|
|
74
|
+
const potentialInput: InternalInputPotentialShell = {
|
|
75
75
|
id: sourceEntry.id,
|
|
76
76
|
resourceTypeId: sourceEntry.resourceTypeId,
|
|
77
77
|
creationContext: {
|
|
@@ -94,9 +94,9 @@ export function bindInputRefInStrategyState(
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
export function clearInputBindingInStrategyState(
|
|
97
|
-
strategyState:
|
|
98
|
-
target:
|
|
99
|
-
):
|
|
97
|
+
strategyState: StrategyState,
|
|
98
|
+
target: CreationContext
|
|
99
|
+
): StrategyState {
|
|
100
100
|
const bucket = strategyState?.[target.toolStepId];
|
|
101
101
|
if (!bucket?.[target.resourceRoleId]) return strategyState;
|
|
102
102
|
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
CreationContext,
|
|
3
|
+
ExternalInputPotentialShell,
|
|
4
|
+
InternalInputPotentialShell,
|
|
5
|
+
OutputPotentialShell,
|
|
6
|
+
ResourceId,
|
|
7
|
+
Resource,
|
|
8
|
+
ResourceTypeId,
|
|
9
9
|
} from '@toolproof-core/schema';
|
|
10
10
|
import { CONSTANTS } from '../../artifacts/artifacts.js';
|
|
11
11
|
|
|
12
|
-
export function generatePath(resourceTypeId:
|
|
12
|
+
export function generatePath(resourceTypeId: ResourceTypeId, id: ResourceId): string {
|
|
13
13
|
return `${resourceTypeId}/${id}.json`;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export function createMaterializedFromOutputPotential(
|
|
17
|
-
outputPotential:
|
|
17
|
+
outputPotential: OutputPotentialShell,
|
|
18
18
|
nucleus: unknown,
|
|
19
19
|
timestamp?: string,
|
|
20
|
-
):
|
|
20
|
+
): Resource {
|
|
21
21
|
const { id, resourceTypeId, creationContext } = outputPotential;
|
|
22
22
|
const path = generatePath(resourceTypeId, id);
|
|
23
23
|
|
|
@@ -34,10 +34,10 @@ export function createMaterializedFromOutputPotential(
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export function createMaterializedFromInputPotential(
|
|
37
|
-
inputPotential:
|
|
37
|
+
inputPotential: InternalInputPotentialShell,
|
|
38
38
|
nucleus: unknown,
|
|
39
39
|
timestamp?: string,
|
|
40
|
-
):
|
|
40
|
+
): Resource {
|
|
41
41
|
const { id, resourceTypeId, creationContext } = inputPotential;
|
|
42
42
|
const path = generatePath(resourceTypeId, id);
|
|
43
43
|
|
|
@@ -54,10 +54,10 @@ export function createMaterializedFromInputPotential(
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
export function createMaterializedFromPotential(
|
|
57
|
-
potential:
|
|
57
|
+
potential: InternalInputPotentialShell | OutputPotentialShell,
|
|
58
58
|
nucleus: unknown,
|
|
59
59
|
timestamp?: string,
|
|
60
|
-
):
|
|
60
|
+
): Resource {
|
|
61
61
|
if (potential.resourceShellKind === CONSTANTS.Enums.ResourceShellKind.internalInputPotential) {
|
|
62
62
|
return createMaterializedFromInputPotential(potential, nucleus, timestamp);
|
|
63
63
|
}
|
|
@@ -66,9 +66,9 @@ export function createMaterializedFromPotential(
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
export function createExternalInputPotential(
|
|
69
|
-
id:
|
|
70
|
-
resourceTypeId:
|
|
71
|
-
):
|
|
69
|
+
id: ResourceId,
|
|
70
|
+
resourceTypeId: ResourceTypeId,
|
|
71
|
+
): ExternalInputPotentialShell {
|
|
72
72
|
return {
|
|
73
73
|
id,
|
|
74
74
|
resourceTypeId,
|
|
@@ -77,10 +77,10 @@ export function createExternalInputPotential(
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
export function createInputPotential(
|
|
80
|
-
id:
|
|
81
|
-
resourceTypeId:
|
|
82
|
-
creationContext:
|
|
83
|
-
):
|
|
80
|
+
id: ResourceId,
|
|
81
|
+
resourceTypeId: ResourceTypeId,
|
|
82
|
+
creationContext: CreationContext,
|
|
83
|
+
): InternalInputPotentialShell {
|
|
84
84
|
return {
|
|
85
85
|
id,
|
|
86
86
|
resourceTypeId,
|
|
@@ -90,10 +90,10 @@ export function createInputPotential(
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
export function createOutputPotential(
|
|
93
|
-
id:
|
|
94
|
-
resourceTypeId:
|
|
95
|
-
creationContext:
|
|
96
|
-
):
|
|
93
|
+
id: ResourceId,
|
|
94
|
+
resourceTypeId: ResourceTypeId,
|
|
95
|
+
creationContext: CreationContext,
|
|
96
|
+
): OutputPotentialShell {
|
|
97
97
|
return {
|
|
98
98
|
id,
|
|
99
99
|
resourceTypeId,
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
RawStrategy,
|
|
3
|
+
RunnableStrategyId,
|
|
4
|
+
RunnableStrategy,
|
|
5
|
+
Step,
|
|
6
|
+
StepArrayByStrategyThread,
|
|
7
|
+
StrategyThreadId,
|
|
8
8
|
} from '@toolproof-core/schema';
|
|
9
9
|
import { getIndependentThreads } from '../parallelizeSteps.js';
|
|
10
10
|
|
|
11
|
-
export function getRunnableStrategyThreadGroups(rawStrategy:
|
|
11
|
+
export function getRunnableStrategyThreadGroups(rawStrategy: RawStrategy): Step[][] {
|
|
12
12
|
return getIndependentThreads(rawStrategy.steps, rawStrategy.strategyState);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export function buildRunnableStrategy(
|
|
16
|
-
rawStrategy:
|
|
17
|
-
runnableStrategyId:
|
|
18
|
-
threadStepGroups:
|
|
19
|
-
threadIdentities:
|
|
20
|
-
):
|
|
16
|
+
rawStrategy: RawStrategy,
|
|
17
|
+
runnableStrategyId: RunnableStrategyId,
|
|
18
|
+
threadStepGroups: Step[][],
|
|
19
|
+
threadIdentities: StrategyThreadId[],
|
|
20
|
+
): RunnableStrategy {
|
|
21
21
|
if (threadStepGroups.length !== threadIdentities.length) {
|
|
22
22
|
throw new Error('buildRunnableStrategy requires one thread id per thread group');
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
const stepsByStrategyThread:
|
|
25
|
+
const stepsByStrategyThread: StepArrayByStrategyThread = {};
|
|
26
26
|
|
|
27
27
|
for (const [index, group] of threadStepGroups.entries()) {
|
|
28
28
|
const threadId = threadIdentities[index];
|
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
BranchStepId,
|
|
3
|
+
BranchStep,
|
|
4
|
+
Case,
|
|
5
|
+
ForStepId,
|
|
6
|
+
ForStep,
|
|
7
|
+
Tool,
|
|
8
|
+
ToolStepId,
|
|
9
|
+
ToolStep,
|
|
10
|
+
ResourceRoleId,
|
|
11
|
+
WhileStepId,
|
|
12
|
+
WhileStep,
|
|
13
13
|
} from '@toolproof-core/schema';
|
|
14
14
|
import { CONSTANTS } from '../../artifacts/artifacts.js';
|
|
15
15
|
|
|
16
16
|
export type LoopStepBuildIdentities =
|
|
17
17
|
| {
|
|
18
18
|
stepKind: typeof CONSTANTS.Enums.StepKind.for;
|
|
19
|
-
stepId:
|
|
20
|
-
whatId:
|
|
21
|
-
whenId:
|
|
19
|
+
stepId: ForStepId;
|
|
20
|
+
whatId: ToolStepId;
|
|
21
|
+
whenId: ToolStepId;
|
|
22
22
|
}
|
|
23
23
|
| {
|
|
24
24
|
stepKind: typeof CONSTANTS.Enums.StepKind.while;
|
|
25
|
-
stepId:
|
|
26
|
-
whatId:
|
|
27
|
-
whenId:
|
|
25
|
+
stepId: WhileStepId;
|
|
26
|
+
whatId: ToolStepId;
|
|
27
|
+
whenId: ToolStepId;
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
export type BranchCaseBuildIdentities = {
|
|
31
|
-
whatId:
|
|
32
|
-
whenId:
|
|
31
|
+
whatId: ToolStepId;
|
|
32
|
+
whenId: ToolStepId;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
function assertNonEmpty<T>(arr: T[], msg: string): asserts arr is [T, ...T[]] {
|
|
@@ -38,17 +38,17 @@ function assertNonEmpty<T>(arr: T[], msg: string): asserts arr is [T, ...T[]] {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
function getRoleBindingSpec(tool:
|
|
41
|
+
function getRoleBindingSpec(tool: Tool): ToolStep['roleBindingSpec'] {
|
|
42
42
|
return {
|
|
43
|
-
inputBindings: Object.keys(tool.roleSpec.inputRoleValueById) as
|
|
44
|
-
outputBindings: Object.keys(tool.roleSpec.outputRoleValueById) as
|
|
43
|
+
inputBindings: Object.keys(tool.roleSpec.inputRoleValueById) as ResourceRoleId[],
|
|
44
|
+
outputBindings: Object.keys(tool.roleSpec.outputRoleValueById) as ResourceRoleId[],
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
export function buildToolStepFromTool(
|
|
49
|
-
tool:
|
|
50
|
-
id:
|
|
51
|
-
):
|
|
49
|
+
tool: Tool,
|
|
50
|
+
id: ToolStepId,
|
|
51
|
+
): ToolStep {
|
|
52
52
|
return {
|
|
53
53
|
id,
|
|
54
54
|
stepKind: CONSTANTS.Enums.StepKind.tool,
|
|
@@ -58,10 +58,10 @@ export function buildToolStepFromTool(
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
export function buildLoopStepFromToolPair(
|
|
61
|
-
whatTool:
|
|
62
|
-
whenTool:
|
|
61
|
+
whatTool: Tool,
|
|
62
|
+
whenTool: Tool,
|
|
63
63
|
identities: LoopStepBuildIdentities,
|
|
64
|
-
):
|
|
64
|
+
): ForStep | WhileStep {
|
|
65
65
|
const what = buildToolStepFromTool(whatTool, identities.whatId);
|
|
66
66
|
const when = buildToolStepFromTool(whenTool, identities.whenId);
|
|
67
67
|
|
|
@@ -81,10 +81,10 @@ export function buildLoopStepFromToolPair(
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
export function buildBranchStepFromToolPairs(
|
|
84
|
-
cases: Array<{ whatTool:
|
|
85
|
-
branchId:
|
|
84
|
+
cases: Array<{ whatTool: Tool; whenTool: Tool }>,
|
|
85
|
+
branchId: BranchStepId,
|
|
86
86
|
caseIdentities: BranchCaseBuildIdentities[],
|
|
87
|
-
):
|
|
87
|
+
): BranchStep {
|
|
88
88
|
if (cases.length !== caseIdentities.length) {
|
|
89
89
|
throw new Error('buildBranchStepFromToolPairs requires one id pair per case');
|
|
90
90
|
}
|
|
@@ -98,7 +98,7 @@ export function buildBranchStepFromToolPairs(
|
|
|
98
98
|
|
|
99
99
|
const what = buildToolStepFromTool(whatTool, identities.whatId);
|
|
100
100
|
const when = buildToolStepFromTool(whenTool, identities.whenId);
|
|
101
|
-
return { what, when } satisfies
|
|
101
|
+
return { what, when } satisfies Case;
|
|
102
102
|
});
|
|
103
103
|
|
|
104
104
|
assertNonEmpty(resolved, 'buildBranchStepFromToolPairs requires at least one case');
|
|
@@ -111,13 +111,13 @@ export function buildBranchStepFromToolPairs(
|
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
export function cloneForStepWithIdentities(
|
|
114
|
-
forStep:
|
|
114
|
+
forStep: ForStep,
|
|
115
115
|
identities: {
|
|
116
|
-
stepId:
|
|
117
|
-
whatId:
|
|
118
|
-
whenId:
|
|
116
|
+
stepId: ForStepId;
|
|
117
|
+
whatId: ToolStepId;
|
|
118
|
+
whenId: ToolStepId;
|
|
119
119
|
},
|
|
120
|
-
):
|
|
120
|
+
): ForStep {
|
|
121
121
|
return {
|
|
122
122
|
id: identities.stepId,
|
|
123
123
|
stepKind: CONSTANTS.Enums.StepKind.for,
|
|
@@ -135,13 +135,13 @@ export function cloneForStepWithIdentities(
|
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
export function cloneWhileStepWithIdentities(
|
|
138
|
-
whileStep:
|
|
138
|
+
whileStep: WhileStep,
|
|
139
139
|
identities: {
|
|
140
|
-
stepId:
|
|
141
|
-
whatId:
|
|
142
|
-
whenId:
|
|
140
|
+
stepId: WhileStepId;
|
|
141
|
+
whatId: ToolStepId;
|
|
142
|
+
whenId: ToolStepId;
|
|
143
143
|
},
|
|
144
|
-
):
|
|
144
|
+
): WhileStep {
|
|
145
145
|
return {
|
|
146
146
|
id: identities.stepId,
|
|
147
147
|
stepKind: CONSTANTS.Enums.StepKind.while,
|
package/src/utils/extractData.ts
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
RawStrategy,
|
|
3
|
+
ToolId,
|
|
4
|
+
Tool,
|
|
5
|
+
ToolStepId,
|
|
6
|
+
ToolStep,
|
|
7
|
+
Step,
|
|
8
|
+
ResourceRoleId,
|
|
9
|
+
ResourceRole,
|
|
10
|
+
ResourceId,
|
|
11
|
+
ResourceTypeId,
|
|
12
|
+
Resource,
|
|
13
13
|
} from '@toolproof-core/schema';
|
|
14
14
|
import { CONSTANTS } from '../artifacts/artifacts.js';
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
export function extractToolIdsFromRawStrategy(rawStrategy:
|
|
17
|
+
export function extractToolIdsFromRawStrategy(rawStrategy: RawStrategy): ToolId[] {
|
|
18
18
|
const toolSteps = extractToolStepsFromRawStrategy(rawStrategy);
|
|
19
|
-
const ids = new Set<
|
|
19
|
+
const ids = new Set<ToolId>();
|
|
20
20
|
for (const jStep of toolSteps) {
|
|
21
21
|
ids.add(jStep.toolId);
|
|
22
22
|
}
|
|
23
23
|
return Array.from(ids);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export function extractToolStepsFromRawStrategy(rawStrategy:
|
|
27
|
-
const toolSteps:
|
|
28
|
-
const seen = new Set<
|
|
26
|
+
export function extractToolStepsFromRawStrategy(rawStrategy: RawStrategy): ToolStep[] {
|
|
27
|
+
const toolSteps: ToolStep[] = [];
|
|
28
|
+
const seen = new Set<ToolStepId>();
|
|
29
29
|
|
|
30
|
-
const addToolStep = (toolStep:
|
|
30
|
+
const addToolStep = (toolStep: ToolStep) => {
|
|
31
31
|
if (seen.has(toolStep.id)) {
|
|
32
32
|
throw new Error(`Duplicate tool step id encountered: ${toolStep.id}`);
|
|
33
33
|
}
|
|
@@ -35,7 +35,7 @@ export function extractToolStepsFromRawStrategy(rawStrategy: RawStrategyJson): T
|
|
|
35
35
|
toolSteps.push(toolStep);
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
const visitStep = (step:
|
|
38
|
+
const visitStep = (step: Step) => {
|
|
39
39
|
switch (step.stepKind) {
|
|
40
40
|
case CONSTANTS.Enums.StepKind.tool: {
|
|
41
41
|
addToolStep(step);
|
|
@@ -69,8 +69,8 @@ export function extractToolStepsFromRawStrategy(rawStrategy: RawStrategyJson): T
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
|
|
72
|
-
export function extractRoleMapFromRawStrategy(rawStrategy:
|
|
73
|
-
const roleMap = new Map<
|
|
72
|
+
export function extractRoleMapFromRawStrategy(rawStrategy: RawStrategy, toolMap: Map<ToolId, Tool>): Map<ResourceRoleId, ResourceRole> {
|
|
73
|
+
const roleMap = new Map<ResourceRoleId, ResourceRole>();
|
|
74
74
|
const toolIds = extractToolIdsFromRawStrategy(rawStrategy);
|
|
75
75
|
|
|
76
76
|
for (const toolId of toolIds) {
|
|
@@ -78,14 +78,14 @@ export function extractRoleMapFromRawStrategy(rawStrategy: RawStrategyJson, tool
|
|
|
78
78
|
if (!tool) continue;
|
|
79
79
|
|
|
80
80
|
for (const [rid, role] of Object.entries(tool.roleSpec.inputRoleValueById)) {
|
|
81
|
-
roleMap.set(rid as
|
|
82
|
-
id: rid as
|
|
81
|
+
roleMap.set(rid as ResourceRoleId, {
|
|
82
|
+
id: rid as ResourceRoleId,
|
|
83
83
|
...role,
|
|
84
84
|
});
|
|
85
85
|
}
|
|
86
86
|
for (const [rid, role] of Object.entries(tool.roleSpec.outputRoleValueById)) {
|
|
87
|
-
roleMap.set(rid as
|
|
88
|
-
id: rid as
|
|
87
|
+
roleMap.set(rid as ResourceRoleId, {
|
|
88
|
+
id: rid as ResourceRoleId,
|
|
89
89
|
...role,
|
|
90
90
|
});
|
|
91
91
|
}
|
|
@@ -94,7 +94,7 @@ export function extractRoleMapFromRawStrategy(rawStrategy: RawStrategyJson, tool
|
|
|
94
94
|
return roleMap;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
export function extractSingleNonErrorOutputTypeId(tool:
|
|
97
|
+
export function extractSingleNonErrorOutputTypeId(tool: Tool): ResourceTypeId | null {
|
|
98
98
|
const errorRoleId = CONSTANTS.Cosmos.ROLE_ErrorOutput;
|
|
99
99
|
const outputEntries = Object.entries(tool.roleSpec.outputRoleValueById).filter(([roleId]) => roleId !== errorRoleId);
|
|
100
100
|
if (!outputEntries || !outputEntries[0] || outputEntries.length !== 1) {
|
|
@@ -106,12 +106,12 @@ export function extractSingleNonErrorOutputTypeId(tool: ToolJson): ResourceTypeI
|
|
|
106
106
|
|
|
107
107
|
|
|
108
108
|
|
|
109
|
-
export function extractResourceMapForType<TResource extends
|
|
110
|
-
resourcesByType: Partial<Record<
|
|
111
|
-
resourceTypeId:
|
|
112
|
-
): Map<
|
|
109
|
+
export function extractResourceMapForType<TResource extends Resource = Resource>(
|
|
110
|
+
resourcesByType: Partial<Record<ResourceTypeId, TResource[]>>,
|
|
111
|
+
resourceTypeId: ResourceTypeId
|
|
112
|
+
): Map<ResourceId, TResource> {
|
|
113
113
|
const resources = resourcesByType[resourceTypeId] ?? [];
|
|
114
|
-
const map = new Map<
|
|
114
|
+
const map = new Map<ResourceId, TResource>();
|
|
115
115
|
|
|
116
116
|
for (const resource of resources) {
|
|
117
117
|
map.set(resource.id, resource);
|
|
@@ -124,10 +124,10 @@ export function extractResourceMapForType<TResource extends ResourceJson = Resou
|
|
|
124
124
|
export function extractIdKeyedNucleusMapForType<
|
|
125
125
|
TKey extends string = string,
|
|
126
126
|
TNucleus extends { id: string | number | boolean } = { id: string | number | boolean },
|
|
127
|
-
TResource extends
|
|
127
|
+
TResource extends Resource = Resource
|
|
128
128
|
>(
|
|
129
|
-
resourcesByType: Partial<Record<
|
|
130
|
-
resourceTypeId:
|
|
129
|
+
resourcesByType: Partial<Record<ResourceTypeId, TResource[]>>,
|
|
130
|
+
resourceTypeId: ResourceTypeId,
|
|
131
131
|
): Map<TKey, TNucleus> {
|
|
132
132
|
const resourceMap = extractResourceMapForType<TResource>(resourcesByType, resourceTypeId);
|
|
133
133
|
const out = new Map<TKey, TNucleus>();
|