@toolproof-core/lib 1.0.32 → 1.0.33
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 +51 -51
- package/dist/artifacts/artifacts.d.ts.map +1 -1
- 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 +2 -3
- package/dist/integrations/firebase/createRunnableStrategy.js.map +1 -1
- package/dist/integrations/firebase/firebaseAdminHelpers.d.ts +5 -1
- 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 -1
- package/dist/types/types.d.ts.map +1 -1
- package/dist/utils/bindInputRoleToResource.d.ts +2 -1
- package/dist/utils/bindInputRoleToResource.d.ts.map +1 -1
- package/dist/utils/bindInputRoleToResource.js +15 -65
- package/dist/utils/bindInputRoleToResource.js.map +1 -1
- package/dist/utils/creation/resourceCreation.d.ts +19 -7
- package/dist/utils/creation/resourceCreation.d.ts.map +1 -1
- package/dist/utils/creation/resourceCreation.js +16 -12
- 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 +8 -14
- package/dist/utils/creation/runnableStrategyCreation.js.map +1 -1
- package/dist/utils/creation/stepCreation.d.ts +22 -5
- package/dist/utils/creation/stepCreation.d.ts.map +1 -1
- package/dist/utils/creation/stepCreation.js +3 -2
- package/dist/utils/creation/stepCreation.js.map +1 -1
- package/dist/utils/extractData.d.ts +5 -4
- package/dist/utils/extractData.d.ts.map +1 -1
- package/dist/utils/extractData.js +7 -49
- package/dist/utils/extractData.js.map +1 -1
- package/dist/utils/parallelizeSteps.d.ts +2 -1
- package/dist/utils/parallelizeSteps.d.ts.map +1 -1
- package/dist/utils/parallelizeSteps.js +17 -10
- package/dist/utils/parallelizeSteps.js.map +1 -1
- package/dist/utils/resolveResourceChain.d.ts +6 -10
- package/dist/utils/resolveResourceChain.d.ts.map +1 -1
- package/dist/utils/resolveResourceChain.js +12 -20
- package/dist/utils/resolveResourceChain.js.map +1 -1
- package/dist/utils/roleSpec.d.ts +12 -0
- package/dist/utils/roleSpec.d.ts.map +1 -0
- package/dist/utils/roleSpec.js +58 -0
- package/dist/utils/roleSpec.js.map +1 -0
- package/dist/utils/strategyState.d.ts +7 -0
- package/dist/utils/strategyState.d.ts.map +1 -0
- package/dist/utils/strategyState.js +29 -0
- package/dist/utils/strategyState.js.map +1 -0
- package/package.json +3 -3
- package/src/integrations/firebase/createRunnableStrategy.ts +5 -7
- package/src/integrations/firebase/firebaseAdminHelpers.ts +2 -1
- package/src/types/types.ts +1 -1
- package/src/utils/bindInputRoleToResource.ts +23 -80
- package/src/utils/creation/resourceCreation.ts +40 -22
- package/src/utils/creation/runnableStrategyCreation.ts +14 -28
- package/src/utils/creation/stepCreation.ts +23 -17
- package/src/utils/extractData.ts +21 -63
- package/src/utils/parallelizeSteps.ts +24 -15
- package/src/utils/resolveResourceChain.ts +18 -32
- package/src/utils/roleSpec.ts +80 -0
- package/src/utils/strategyState.ts +56 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
CreationContext,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
ResourcePotential,
|
|
8
|
-
StrategyState,
|
|
3
|
+
ExternalInput,
|
|
4
|
+
ReferenceInput,
|
|
5
|
+
StrategyStateInputEntry,
|
|
6
|
+
ValueInput,
|
|
9
7
|
} from '@toolproof-core/schema';
|
|
10
|
-
import {
|
|
8
|
+
import { getStrategyStateEntry, type StrategyState } from './strategyState.js';
|
|
11
9
|
|
|
12
10
|
export type ResolveResult =
|
|
13
|
-
| { status:
|
|
14
|
-
| { status:
|
|
15
|
-
| { status: typeof CONSTANTS.Enums.ResourceShellKind.outputPotential; entry: OutputPotentialShell; path: CreationContext[] }
|
|
11
|
+
| { status: 'valueInput'; entry: ValueInput; path: CreationContext[] }
|
|
12
|
+
| { status: 'externalInput'; entry: ExternalInput; path: CreationContext[] }
|
|
16
13
|
| { status: 'unresolved'; reason: 'not-found' | 'cycle' | 'depth-exceeded'; path: CreationContext[] };
|
|
17
14
|
|
|
18
15
|
export function resolveResourceChain(
|
|
@@ -27,39 +24,28 @@ export function resolveResourceChain(
|
|
|
27
24
|
|
|
28
25
|
for (let depth = 0; depth <= maxDepth; depth++) {
|
|
29
26
|
path.push(current);
|
|
30
|
-
const visitKey = `${current.
|
|
27
|
+
const visitKey = `${current.toolStepPath}::${current.roleName}`;
|
|
31
28
|
if (visited.has(visitKey)) {
|
|
32
29
|
return { status: 'unresolved', reason: 'cycle', path };
|
|
33
30
|
}
|
|
34
31
|
visited.add(visitKey);
|
|
35
32
|
|
|
36
|
-
const
|
|
37
|
-
if (!bucket) return { status: 'unresolved', reason: 'not-found', path };
|
|
38
|
-
const entry = bucket[current.resourceRoleId] as (
|
|
39
|
-
| Resource
|
|
40
|
-
| ResourcePotential
|
|
41
|
-
| undefined
|
|
42
|
-
);
|
|
33
|
+
const entry = getStrategyStateEntry(strategyState, current) as StrategyStateInputEntry | undefined;
|
|
43
34
|
if (!entry) return { status: 'unresolved', reason: 'not-found', path };
|
|
44
35
|
|
|
45
|
-
if (entry.
|
|
46
|
-
return { status:
|
|
36
|
+
if (entry.strategyStateInputKind === 'valueInput') {
|
|
37
|
+
return { status: 'valueInput', entry: entry, path };
|
|
47
38
|
}
|
|
48
|
-
if (entry.
|
|
49
|
-
return { status:
|
|
50
|
-
}
|
|
51
|
-
if (entry.resourceShellKind === CONSTANTS.Enums.ResourceShellKind.outputPotential) {
|
|
52
|
-
return { status: CONSTANTS.Enums.ResourceShellKind.outputPotential, entry: entry as OutputPotentialShell, path };
|
|
39
|
+
if (entry.strategyStateInputKind === 'externalInput') {
|
|
40
|
+
return { status: 'externalInput', entry: entry, path };
|
|
53
41
|
}
|
|
54
42
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
43
|
+
current = {
|
|
44
|
+
toolStepPath: (entry as ReferenceInput).toolStepPath,
|
|
45
|
+
roleName: (entry as ReferenceInput).roleName,
|
|
46
|
+
};
|
|
47
|
+
continue;
|
|
60
48
|
|
|
61
|
-
// Unknown case
|
|
62
|
-
return { status: 'unresolved', reason: 'not-found', path };
|
|
63
49
|
}
|
|
64
50
|
|
|
65
51
|
return { status: 'unresolved', reason: 'depth-exceeded', path };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
RoleName,
|
|
3
|
+
RoleValue,
|
|
4
|
+
Strategy,
|
|
5
|
+
Step,
|
|
6
|
+
Tool,
|
|
7
|
+
ToolStep,
|
|
8
|
+
} from '@toolproof-core/schema';
|
|
9
|
+
|
|
10
|
+
export interface ToolRoleDescriptor extends RoleValue {
|
|
11
|
+
id: RoleName;
|
|
12
|
+
name: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function getInputRoleEntries(tool: Tool): Array<[RoleName, RoleValue]> {
|
|
16
|
+
return Object.entries(tool.roleSpec.inputRoleValueByName) as Array<[RoleName, RoleValue]>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getOutputRoleEntries(tool: Tool): Array<[RoleName, RoleValue]> {
|
|
20
|
+
return Object.entries(tool.roleSpec.outputRoleValueByName) as Array<[RoleName, RoleValue]>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getInputRoleNames(tool: Tool): RoleName[] {
|
|
24
|
+
return getInputRoleEntries(tool).map(([roleName]) => roleName);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function getOutputRoleNames(tool: Tool): RoleName[] {
|
|
28
|
+
return getOutputRoleEntries(tool).map(([roleName]) => roleName);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function toToolRoleDescriptor([roleName, roleValue]: [RoleName, RoleValue]): ToolRoleDescriptor {
|
|
32
|
+
return {
|
|
33
|
+
id: roleName,
|
|
34
|
+
name: roleName,
|
|
35
|
+
...roleValue,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function extractToolStepsFromStrategy(strategy: Strategy): ToolStep[] {
|
|
40
|
+
const toolSteps: ToolStep[] = [];
|
|
41
|
+
|
|
42
|
+
const visitStep = (step: Step) => {
|
|
43
|
+
switch (step.stepKind) {
|
|
44
|
+
case 'tool': {
|
|
45
|
+
toolSteps.push(step);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
case 'branch': {
|
|
49
|
+
for (const conditional of step.cases) {
|
|
50
|
+
toolSteps.push(conditional.when, conditional.what);
|
|
51
|
+
}
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
case 'while':
|
|
55
|
+
case 'for': {
|
|
56
|
+
toolSteps.push(step.case.when, step.case.what);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
default: {
|
|
60
|
+
const _exhaustive: never = step;
|
|
61
|
+
return _exhaustive;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
if ('steps' in strategy) {
|
|
67
|
+
for (const step of strategy.steps) {
|
|
68
|
+
visitStep(step);
|
|
69
|
+
}
|
|
70
|
+
return toolSteps;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
for (const threadSteps of strategy.stepsByThreadIndex) {
|
|
74
|
+
for (const step of threadSteps) {
|
|
75
|
+
visitStep(step);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return toolSteps;
|
|
80
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CreationContext,
|
|
3
|
+
Strategy,
|
|
4
|
+
StrategyStateInputEntry,
|
|
5
|
+
StrategyStateInputEntryByRoleName,
|
|
6
|
+
} from '@toolproof-core/schema';
|
|
7
|
+
|
|
8
|
+
export type StrategyState = Strategy['strategyState'];
|
|
9
|
+
|
|
10
|
+
export function getStrategyStateBucket(
|
|
11
|
+
strategyState: StrategyState,
|
|
12
|
+
toolStepPath: CreationContext['toolStepPath'],
|
|
13
|
+
): StrategyStateInputEntryByRoleName | undefined {
|
|
14
|
+
return strategyState[toolStepPath];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function getStrategyStateEntry(
|
|
18
|
+
strategyState: StrategyState,
|
|
19
|
+
context: CreationContext,
|
|
20
|
+
): StrategyStateInputEntry | undefined {
|
|
21
|
+
return getStrategyStateBucket(strategyState, context.toolStepPath)?.[context.roleName];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function setStrategyStateEntry(
|
|
25
|
+
strategyState: StrategyState,
|
|
26
|
+
context: CreationContext,
|
|
27
|
+
entry: StrategyStateInputEntry,
|
|
28
|
+
): StrategyState {
|
|
29
|
+
const bucket = getStrategyStateBucket(strategyState, context.toolStepPath) ?? {};
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
...strategyState,
|
|
33
|
+
[context.toolStepPath]: {
|
|
34
|
+
...bucket,
|
|
35
|
+
[context.roleName]: entry,
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function clearStrategyStateEntry(
|
|
41
|
+
strategyState: StrategyState,
|
|
42
|
+
context: CreationContext,
|
|
43
|
+
): StrategyState {
|
|
44
|
+
const bucket = getStrategyStateBucket(strategyState, context.toolStepPath);
|
|
45
|
+
if (!bucket || !(context.roleName in bucket)) {
|
|
46
|
+
return strategyState;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const nextBucket = { ...bucket };
|
|
50
|
+
delete nextBucket[context.roleName];
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
...strategyState,
|
|
54
|
+
[context.toolStepPath]: nextBucket,
|
|
55
|
+
};
|
|
56
|
+
}
|