@toolproof-core/lib 1.0.36 → 1.0.37
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/firebaseAdminHelpers.d.ts +1 -2
- package/dist/integrations/firebase/firebaseAdminHelpers.js +5 -14
- package/dist/lookups/lookups.d.ts +17 -24
- package/dist/lookups/lookups.js +10 -0
- package/dist/types/types.d.ts +10 -6
- package/dist/utils/cosmosDataExtraction.d.ts +5 -0
- package/dist/utils/cosmosDataExtraction.js +15 -0
- package/dist/utils/identifierGeneration.d.ts +2 -0
- package/dist/utils/identifierGeneration.js +5 -0
- package/dist/utils/mutableStrategyOverlay.d.ts +55 -0
- package/dist/utils/mutableStrategyOverlay.js +115 -0
- package/dist/utils/resourceCreation.d.ts +11 -0
- package/dist/utils/resourceCreation.js +32 -0
- package/dist/utils/stepCreation.d.ts +9 -0
- package/dist/utils/stepCreation.js +79 -0
- package/dist/utils/stepParallelization.d.ts +2 -0
- package/dist/utils/stepParallelization.js +129 -0
- package/dist/utils/strategyAssembly.d.ts +3 -0
- package/dist/utils/strategyAssembly.js +6 -0
- package/dist/utils/strategyCanonicalization.d.ts +4 -0
- package/dist/utils/strategyCanonicalization.js +215 -0
- package/dist/utils/strategyExtraction.d.ts +17 -0
- package/dist/utils/strategyExtraction.js +88 -0
- package/dist/utils/strategyStateResolution.d.ts +17 -0
- package/dist/utils/{resolveStrategyStateChain.js → strategyStateResolution.js} +5 -4
- package/dist/utils/strategyThreading.d.ts +2 -0
- package/dist/utils/strategyThreading.js +10 -0
- package/dist/utils/toolStepPaths.d.ts +2 -0
- package/dist/utils/toolStepPaths.js +21 -0
- package/package.json +41 -21
- package/src/integrations/firebase/firebaseAdminHelpers.ts +5 -17
- package/src/lookups/lookups.ts +16 -6
- package/src/types/types.ts +10 -4
- package/src/utils/cosmosDataExtraction.ts +25 -0
- package/src/utils/identifierGeneration.ts +12 -0
- package/src/utils/mutableStrategyOverlay.ts +286 -0
- package/src/utils/resourceCreation.ts +87 -0
- package/src/utils/stepCreation.ts +114 -0
- package/src/utils/stepParallelization.ts +181 -0
- package/src/utils/strategyAssembly.ts +14 -0
- package/src/utils/strategyCanonicalization.ts +294 -0
- package/src/utils/strategyExtraction.ts +150 -0
- package/src/utils/strategyStateResolution.ts +57 -0
- package/src/utils/strategyThreading.ts +27 -0
- package/src/utils/toolStepPaths.ts +34 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/integrations/firebase/createStep.d.ts +0 -10
- package/dist/integrations/firebase/createStep.js +0 -17
- package/dist/integrations/firebase/createThreadedStrategy.d.ts +0 -2
- package/dist/integrations/firebase/createThreadedStrategy.js +0 -8
- package/dist/utils/creation/resourceCreation.d.ts +0 -21
- package/dist/utils/creation/resourceCreation.js +0 -67
- package/dist/utils/creation/stepCreation.d.ts +0 -10
- package/dist/utils/creation/stepCreation.js +0 -64
- package/dist/utils/creation/threadedStrategyCreation.d.ts +0 -18
- package/dist/utils/creation/threadedStrategyCreation.js +0 -16
- package/dist/utils/extractData.d.ts +0 -12
- package/dist/utils/extractData.js +0 -78
- package/dist/utils/parallelizeSteps.d.ts +0 -3
- package/dist/utils/parallelizeSteps.js +0 -159
- package/dist/utils/resolveStrategyStateChain.d.ts +0 -20
- package/dist/utils/roleSpec.d.ts +0 -16
- package/dist/utils/roleSpec.js +0 -57
- package/dist/utils/strategyState.d.ts +0 -12
- package/dist/utils/strategyState.js +0 -58
- package/dist/utils_2/threadedStrategyCreation.d.ts +0 -5
- package/dist/utils_2/threadedStrategyCreation.js +0 -12
- package/src/integrations/firebase/createStep.ts +0 -41
- package/src/integrations/firebase/createThreadedStrategy.ts +0 -19
- package/src/utils/creation/resourceCreation.ts +0 -140
- package/src/utils/creation/stepCreation.ts +0 -95
- package/src/utils/creation/threadedStrategyCreation.ts +0 -42
- package/src/utils/extractData.ts +0 -137
- package/src/utils/parallelizeSteps.ts +0 -239
- package/src/utils/resolveStrategyStateChain.ts +0 -58
- package/src/utils/roleSpec.ts +0 -84
- package/src/utils/strategyState.ts +0 -128
- package/src/utils_2/threadedStrategyCreation.ts +0 -19
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
export function getStrategyStateBucket(strategyState, toolStepPath) {
|
|
2
|
-
return strategyState[toolStepPath];
|
|
3
|
-
}
|
|
4
|
-
export function getStrategyStateEntry(strategyState, toolStepRoleAddress) {
|
|
5
|
-
const toolStepPath = toolStepRoleAddress.toolStepPath;
|
|
6
|
-
return getStrategyStateBucket(strategyState, toolStepPath)?.[toolStepRoleAddress.roleName];
|
|
7
|
-
}
|
|
8
|
-
export function setStrategyStateEntry(strategyState, toolStepRoleAddress, entry) {
|
|
9
|
-
const toolStepPath = toolStepRoleAddress.toolStepPath;
|
|
10
|
-
const bucket = getStrategyStateBucket(strategyState, toolStepPath) ?? {};
|
|
11
|
-
return {
|
|
12
|
-
...strategyState,
|
|
13
|
-
[toolStepPath]: {
|
|
14
|
-
...bucket,
|
|
15
|
-
[toolStepRoleAddress.roleName]: entry,
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
export function clearStrategyStateEntry(strategyState, toolStepRoleAddress) {
|
|
20
|
-
const toolStepPath = toolStepRoleAddress.toolStepPath;
|
|
21
|
-
const bucket = getStrategyStateBucket(strategyState, toolStepPath);
|
|
22
|
-
if (!bucket || !(toolStepRoleAddress.roleName in bucket)) {
|
|
23
|
-
return strategyState;
|
|
24
|
-
}
|
|
25
|
-
const nextBucket = { ...bucket };
|
|
26
|
-
delete nextBucket[toolStepRoleAddress.roleName];
|
|
27
|
-
return {
|
|
28
|
-
...strategyState,
|
|
29
|
-
[toolStepPath]: nextBucket,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
export function bindInputResource(strategyState, target, resource) {
|
|
33
|
-
const inputResource = {
|
|
34
|
-
...resource,
|
|
35
|
-
strategyStateInputKind: 'inputResource',
|
|
36
|
-
};
|
|
37
|
-
return setStrategyStateEntry(strategyState, target, inputResource);
|
|
38
|
-
}
|
|
39
|
-
export function bindInternalInputPotential(strategyState, target, source) {
|
|
40
|
-
const sourceEntry = getStrategyStateEntry(strategyState, source);
|
|
41
|
-
if (!sourceEntry) {
|
|
42
|
-
throw new Error(`resourceEntry not found for source (${source.toolStepPath}, ${source.roleName})`);
|
|
43
|
-
}
|
|
44
|
-
const internalInputPotential = {
|
|
45
|
-
strategyStateInputKind: 'internalInputPotential',
|
|
46
|
-
toolStepRoleAddress: {
|
|
47
|
-
toolStepPath: source.toolStepPath,
|
|
48
|
-
roleName: source.roleName,
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
return setStrategyStateEntry(strategyState, target, internalInputPotential);
|
|
52
|
-
}
|
|
53
|
-
export function bindExternalInputPotential(strategyState, target) {
|
|
54
|
-
const externalInputPotential = {
|
|
55
|
-
strategyStateInputKind: 'externalInputPotential',
|
|
56
|
-
};
|
|
57
|
-
return setStrategyStateEntry(strategyState, target, externalInputPotential);
|
|
58
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { UnthreadedStrategy, ThreadedStrategy, StepArray, StepArrayArray, UnthreadedStrategyState, ThreadedStrategyState } from "@toolproof-core/genesis/types";
|
|
2
|
-
export declare const __UnthreadedStrategyToThreadedStrategy: (unthreadedStrategy: UnthreadedStrategy) => ThreadedStrategy;
|
|
3
|
-
export declare const __UnthreadedStrategyStateToThreadedStrategyState: (unthreadedStrategyState: UnthreadedStrategyState) => ThreadedStrategyState;
|
|
4
|
-
export declare const __StepArrayToStepArrayArray: (stepArray: StepArray) => StepArrayArray;
|
|
5
|
-
export declare const __Foo: (unthreadedStrategy: UnthreadedStrategy, draft: any) => UnthreadedStrategy;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export const __UnthreadedStrategyToThreadedStrategy = (unthreadedStrategy) => {
|
|
2
|
-
throw new Error('Not implemented yet');
|
|
3
|
-
};
|
|
4
|
-
export const __UnthreadedStrategyStateToThreadedStrategyState = (unthreadedStrategyState) => {
|
|
5
|
-
throw new Error('Not implemented yet');
|
|
6
|
-
};
|
|
7
|
-
export const __StepArrayToStepArrayArray = (stepArray) => {
|
|
8
|
-
throw new Error('Not implemented yet');
|
|
9
|
-
};
|
|
10
|
-
export const __Foo = (unthreadedStrategy, draft) => {
|
|
11
|
-
throw new Error('Not implemented yet');
|
|
12
|
-
};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
BranchStep,
|
|
3
|
-
ForStep,
|
|
4
|
-
Tool,
|
|
5
|
-
ToolStep,
|
|
6
|
-
WhileStep,
|
|
7
|
-
} from '@toolproof-core/genesis';
|
|
8
|
-
import { CONSTANTS } from '../../lookups/lookups.js';
|
|
9
|
-
import {
|
|
10
|
-
buildBranchStepFromToolPairs,
|
|
11
|
-
buildToolStepFromTool,
|
|
12
|
-
buildLoopStepFromToolPair,
|
|
13
|
-
cloneForStep as cloneForStepPure,
|
|
14
|
-
cloneWhileStep as cloneWhileStepPure,
|
|
15
|
-
} from '../../utils/creation/stepCreation.js';
|
|
16
|
-
|
|
17
|
-
export function createToolStepFromTool(tool: Tool): ToolStep {
|
|
18
|
-
return buildToolStepFromTool(tool);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function createLoopStepFromToolPair(
|
|
22
|
-
whatTool: Tool,
|
|
23
|
-
whenTool: Tool,
|
|
24
|
-
stepKind: typeof CONSTANTS.Enums.StepKind.for | typeof CONSTANTS.Enums.StepKind.while,
|
|
25
|
-
): ForStep | WhileStep {
|
|
26
|
-
return buildLoopStepFromToolPair(whatTool, whenTool, stepKind);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function createBranchStepFromToolPairs(
|
|
30
|
-
cases: Array<{ whatTool: Tool; whenTool: Tool }>,
|
|
31
|
-
): BranchStep {
|
|
32
|
-
return buildBranchStepFromToolPairs(cases);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function cloneForStep(forStep: ForStep): ForStep {
|
|
36
|
-
return cloneForStepPure(forStep);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function cloneWhileStep(whileStep: WhileStep): WhileStep {
|
|
40
|
-
return cloneWhileStepPure(whileStep);
|
|
41
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { CONSTANTS } from '../../lookups/lookups.js';
|
|
2
|
-
import {
|
|
3
|
-
buildThreadedStrategy,
|
|
4
|
-
getThreadedStrategyStepGroups,
|
|
5
|
-
type ThreadableStrategy,
|
|
6
|
-
type ThreadedStrategyLike,
|
|
7
|
-
} from '../../utils/creation/threadedStrategyCreation.js';
|
|
8
|
-
import { getNewId } from './firebaseAdminHelpers.js';
|
|
9
|
-
|
|
10
|
-
export function createThreadedStrategy<TStrategyState>(strategy: ThreadableStrategy<TStrategyState>): ThreadedStrategyLike<TStrategyState> {
|
|
11
|
-
const threadStepGroups = getThreadedStrategyStepGroups(strategy);
|
|
12
|
-
const strategyHandle = getNewId(CONSTANTS.Names.StrategyHandle);
|
|
13
|
-
|
|
14
|
-
return buildThreadedStrategy(
|
|
15
|
-
threadStepGroups,
|
|
16
|
-
strategyHandle,
|
|
17
|
-
strategy,
|
|
18
|
-
);
|
|
19
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
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
|
-
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
BranchStep,
|
|
3
|
-
Case,
|
|
4
|
-
ForStep,
|
|
5
|
-
Tool,
|
|
6
|
-
ToolStep,
|
|
7
|
-
WhileStep,
|
|
8
|
-
} from '@toolproof-core/genesis';
|
|
9
|
-
import { CONSTANTS } from '../../lookups/lookups.js';
|
|
10
|
-
import { getInputRoleNames, getOutputRoleNames } from '../roleSpec.js';
|
|
11
|
-
|
|
12
|
-
function assertNonEmpty<T>(arr: T[], msg: string): asserts arr is [T, ...T[]] {
|
|
13
|
-
if (arr.length === 0) {
|
|
14
|
-
throw new Error(msg);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function getRoleBindingSpec(tool: Tool): ToolStep['roleBindingSpec'] {
|
|
19
|
-
return {
|
|
20
|
-
inputBindings: getInputRoleNames(tool),
|
|
21
|
-
outputBindings: getOutputRoleNames(tool),
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function buildToolStepFromTool(
|
|
26
|
-
tool: Tool,
|
|
27
|
-
): ToolStep {
|
|
28
|
-
return {
|
|
29
|
-
stepKind: CONSTANTS.Enums.StepKind.tool,
|
|
30
|
-
toolHandle: tool.handle,
|
|
31
|
-
roleBindingSpec: getRoleBindingSpec(tool),
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function buildLoopStepFromToolPair(
|
|
36
|
-
whatTool: Tool,
|
|
37
|
-
whenTool: Tool,
|
|
38
|
-
stepKind: typeof CONSTANTS.Enums.StepKind.for | typeof CONSTANTS.Enums.StepKind.while,
|
|
39
|
-
): ForStep | WhileStep {
|
|
40
|
-
const what = buildToolStepFromTool(whatTool);
|
|
41
|
-
const when = buildToolStepFromTool(whenTool);
|
|
42
|
-
|
|
43
|
-
if (stepKind === CONSTANTS.Enums.StepKind.for) {
|
|
44
|
-
return {
|
|
45
|
-
stepKind: CONSTANTS.Enums.StepKind.for,
|
|
46
|
-
case: { what, when },
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
stepKind: CONSTANTS.Enums.StepKind.while,
|
|
52
|
-
case: { what, when },
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function buildBranchStepFromToolPairs(
|
|
57
|
-
cases: Array<{ whatTool: Tool; whenTool: Tool }>,
|
|
58
|
-
): BranchStep {
|
|
59
|
-
const resolved = cases.map(({ whatTool, whenTool }, index) => {
|
|
60
|
-
const what = buildToolStepFromTool(whatTool);
|
|
61
|
-
const when = buildToolStepFromTool(whenTool);
|
|
62
|
-
return { what, when } satisfies Case;
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
assertNonEmpty(resolved, 'buildBranchStepFromToolPairs requires at least one case');
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
stepKind: CONSTANTS.Enums.StepKind.branch,
|
|
69
|
-
cases: resolved,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function cloneForStep(
|
|
74
|
-
forStep: ForStep,
|
|
75
|
-
): ForStep {
|
|
76
|
-
return {
|
|
77
|
-
stepKind: CONSTANTS.Enums.StepKind.for,
|
|
78
|
-
case: {
|
|
79
|
-
what: { ...forStep.case.what },
|
|
80
|
-
when: { ...forStep.case.when },
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export function cloneWhileStep(
|
|
86
|
-
whileStep: WhileStep,
|
|
87
|
-
): WhileStep {
|
|
88
|
-
return {
|
|
89
|
-
stepKind: CONSTANTS.Enums.StepKind.while,
|
|
90
|
-
case: {
|
|
91
|
-
what: { ...whileStep.case.what },
|
|
92
|
-
when: { ...whileStep.case.when },
|
|
93
|
-
},
|
|
94
|
-
};
|
|
95
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
RoleName,
|
|
3
|
-
ToolHandle,
|
|
4
|
-
Tool,
|
|
5
|
-
ToolStep,
|
|
6
|
-
ResourceId,
|
|
7
|
-
ResourceTypeHandle,
|
|
8
|
-
Resource,
|
|
9
|
-
} from '@toolproof-core/genesis';
|
|
10
|
-
import {
|
|
11
|
-
extractToolStepsFromStrategy,
|
|
12
|
-
getInputRoleEntries,
|
|
13
|
-
getOutputRoleEntries,
|
|
14
|
-
toToolRoleDescriptor,
|
|
15
|
-
type StrategyStepGraph,
|
|
16
|
-
type ToolRoleDescriptor,
|
|
17
|
-
} from './roleSpec.js';
|
|
18
|
-
|
|
19
|
-
const ERROR_OUTPUT_ROLE_NAME = 'ErrorOutput' as RoleName;
|
|
20
|
-
|
|
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>();
|
|
35
|
-
for (const jStep of toolSteps) {
|
|
36
|
-
ids.add(jStep.toolHandle);
|
|
37
|
-
}
|
|
38
|
-
return Array.from(ids);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function extractToolStepsFromUnthreadedStrategy(unthreadedStrategy: StrategyStepGraph): ToolStep[] {
|
|
42
|
-
return extractToolStepsFromStrategy(unthreadedStrategy);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
export function extractRoleMapFromUnthreadedStrategy(unthreadedStrategy: StrategyStepGraph, toolMap: Map<ToolHandle, Tool>): Map<RoleName, ToolRoleDescriptor> {
|
|
47
|
-
const roleMap = new Map<RoleName, ToolRoleDescriptor>();
|
|
48
|
-
const toolHandles = extractToolHandlesFromUnthreadedStrategy(unthreadedStrategy);
|
|
49
|
-
|
|
50
|
-
for (const toolHandle of toolHandles) {
|
|
51
|
-
const tool = toolMap.get(toolHandle);
|
|
52
|
-
if (!tool) continue;
|
|
53
|
-
|
|
54
|
-
for (const entry of getInputRoleEntries(tool)) {
|
|
55
|
-
roleMap.set(entry[0], toToolRoleDescriptor(entry));
|
|
56
|
-
}
|
|
57
|
-
for (const entry of getOutputRoleEntries(tool)) {
|
|
58
|
-
roleMap.set(entry[0], toToolRoleDescriptor(entry));
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return roleMap;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function extractSingleNonErrorOutputTypeId(tool: Tool): ResourceTypeHandle | null {
|
|
66
|
-
const outputEntries = getOutputRoleEntries(tool).filter(([roleName]) => roleName !== ERROR_OUTPUT_ROLE_NAME);
|
|
67
|
-
if (!outputEntries || !outputEntries[0] || outputEntries.length !== 1) {
|
|
68
|
-
throw new Error(`Tool ${tool.handle} must have exactly one non-error output role to be branchable/loopable`);
|
|
69
|
-
} // ATTENTION_PUREIFY
|
|
70
|
-
return extractResourceTypeHandleFromRoleValue(toToolRoleDescriptor(outputEntries[0]));
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
export function extractResourceMapForType<TResource extends Resource = Resource>(
|
|
76
|
-
resourcesByType: Partial<Record<ResourceTypeHandle, TResource[]>>,
|
|
77
|
-
resourceTypeHandle: ResourceTypeHandle
|
|
78
|
-
): Map<ResourceId, TResource> {
|
|
79
|
-
const resources = resourcesByType[resourceTypeHandle] ?? [];
|
|
80
|
-
const map = new Map<ResourceId, TResource>();
|
|
81
|
-
|
|
82
|
-
for (const resource of resources) {
|
|
83
|
-
map.set(resource.id, resource);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return map;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Only use this for resource types whose nuclei are entity-like objects with their own intrinsic id.
|
|
90
|
-
export function extractIdKeyedValueMapForType<
|
|
91
|
-
TKey extends string = string,
|
|
92
|
-
TValue extends { id: string | number | boolean } = { id: string | number | boolean },
|
|
93
|
-
TResource extends Resource = Resource
|
|
94
|
-
>(
|
|
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>();
|
|
100
|
-
|
|
101
|
-
for (const resource of resourceMap.values()) {
|
|
102
|
-
const data = resource.projection as unknown;
|
|
103
|
-
if (data === null || data === undefined) {
|
|
104
|
-
throw new Error(
|
|
105
|
-
`Expected resource '${resource.id}' of type '${resourceTypeHandle}' to have a projection`
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
if (typeof data !== 'object') {
|
|
109
|
-
throw new Error(
|
|
110
|
-
`Expected resource '${resource.id}' of type '${resourceTypeHandle}' to have an object projection with id`
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const maybeId = (data as any).id as unknown;
|
|
115
|
-
if (maybeId === null || maybeId === undefined) {
|
|
116
|
-
throw new Error(
|
|
117
|
-
`Expected resource '${resource.id}' of type '${resourceTypeHandle}' to have projection.id`
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
if (
|
|
121
|
-
typeof maybeId !== 'string' &&
|
|
122
|
-
typeof maybeId !== 'number' &&
|
|
123
|
-
typeof maybeId !== 'boolean'
|
|
124
|
-
) {
|
|
125
|
-
throw new Error(
|
|
126
|
-
`Expected resource '${resource.id}' of type '${resourceTypeHandle}' to have projection.id as string, number, or boolean`
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const value = data as TValue;
|
|
131
|
-
const key = String(maybeId) as TKey;
|
|
132
|
-
|
|
133
|
-
out.set(key, value);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return out;
|
|
137
|
-
}
|