@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,17 +1,17 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
BranchStep,
|
|
3
|
+
ForStep,
|
|
4
|
+
ToolStepId,
|
|
5
|
+
ToolStep,
|
|
6
|
+
ResourceRoleId,
|
|
7
|
+
Step,
|
|
8
|
+
StrategyState,
|
|
9
|
+
WhileStep,
|
|
10
10
|
} from '@toolproof-core/schema';
|
|
11
11
|
import { CONSTANTS } from '../artifacts/artifacts.js';
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
export function getIndependentThreads(steps:
|
|
14
|
+
export function getIndependentThreads(steps: Step[], strategyState: StrategyState): Step[][] {
|
|
15
15
|
type OwnerIndex = number;
|
|
16
16
|
|
|
17
17
|
const getOwnerLabel = (ownerIndex: OwnerIndex) => {
|
|
@@ -20,11 +20,11 @@ export function getIndependentThreads(steps: StepJson[], strategyState: Strategy
|
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
// Map each toolStep.id (including macro-nested tool steps) to owning top-level step index.
|
|
23
|
-
const toolStepIdToOwner = new Map<
|
|
24
|
-
const ownerToToolStepIds = new Map<OwnerIndex,
|
|
25
|
-
const toolStepById = new Map<
|
|
23
|
+
const toolStepIdToOwner = new Map<ToolStepId, OwnerIndex>();
|
|
24
|
+
const ownerToToolStepIds = new Map<OwnerIndex, ToolStepId[]>();
|
|
25
|
+
const toolStepById = new Map<ToolStepId, ToolStep>();
|
|
26
26
|
|
|
27
|
-
const addToolStep = (toolStep:
|
|
27
|
+
const addToolStep = (toolStep: ToolStep | undefined, ownerIndex: OwnerIndex) => {
|
|
28
28
|
if (!toolStep?.id) return;
|
|
29
29
|
|
|
30
30
|
const existingOwner = toolStepIdToOwner.get(toolStep.id);
|
|
@@ -43,26 +43,26 @@ export function getIndependentThreads(steps: StepJson[], strategyState: Strategy
|
|
|
43
43
|
|
|
44
44
|
steps.forEach((step, ownerIndex) => {
|
|
45
45
|
if (step.stepKind === CONSTANTS.Enums.StepKind.tool) {
|
|
46
|
-
addToolStep(step as
|
|
46
|
+
addToolStep(step as ToolStep, ownerIndex);
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
if (step.stepKind === CONSTANTS.Enums.StepKind.for) {
|
|
51
|
-
const loop = step as
|
|
51
|
+
const loop = step as ForStep;
|
|
52
52
|
addToolStep(loop.case?.what, ownerIndex);
|
|
53
53
|
addToolStep(loop.case?.when, ownerIndex);
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
if (step.stepKind === CONSTANTS.Enums.StepKind.while) {
|
|
58
|
-
const loop = step as
|
|
58
|
+
const loop = step as WhileStep;
|
|
59
59
|
addToolStep(loop.case?.what, ownerIndex);
|
|
60
60
|
addToolStep(loop.case?.when, ownerIndex);
|
|
61
61
|
return;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
if (step.stepKind === CONSTANTS.Enums.StepKind.branch) {
|
|
65
|
-
const branch = step as
|
|
65
|
+
const branch = step as BranchStep;
|
|
66
66
|
for (const caseItem of branch.cases ?? []) {
|
|
67
67
|
addToolStep(caseItem?.what, ownerIndex);
|
|
68
68
|
addToolStep(caseItem?.when, ownerIndex);
|
|
@@ -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 inputRoleId of inputBindings) {
|
|
97
|
-
const entry = bucket?.[inputRoleId as
|
|
97
|
+
const entry = bucket?.[inputRoleId as ResourceRoleId] as any;
|
|
98
98
|
if (!entry || entry.resourceShellKind !== 'internalInputPotential') continue;
|
|
99
99
|
|
|
100
|
-
const creatorToolStepId = entry?.creationContext?.toolStepId as
|
|
100
|
+
const creatorToolStepId = entry?.creationContext?.toolStepId as ToolStepId | undefined;
|
|
101
101
|
if (!creatorToolStepId) {
|
|
102
102
|
throw new Error(
|
|
103
103
|
`Unresolvable internalInputPotential in toolStep '${toolStepId}' (${getOwnerLabel(ownerIndex)}): missing creationContext.toolStepId for role '${inputRoleId}'`
|
|
@@ -1,29 +1,29 @@
|
|
|
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
|
|
|
12
12
|
export type ResolveResult =
|
|
13
|
-
| { status: typeof CONSTANTS.Enums.ResourceShellKind.materialized; entry:
|
|
14
|
-
| { status: typeof CONSTANTS.Enums.ResourceShellKind.externalInputPotential; entry:
|
|
15
|
-
| { status: typeof CONSTANTS.Enums.ResourceShellKind.outputPotential; entry:
|
|
16
|
-
| { status: 'unresolved'; reason: 'not-found' | 'cycle' | 'depth-exceeded'; path:
|
|
13
|
+
| { status: typeof CONSTANTS.Enums.ResourceShellKind.materialized; entry: Resource; path: CreationContext[] }
|
|
14
|
+
| { status: typeof CONSTANTS.Enums.ResourceShellKind.externalInputPotential; entry: ExternalInputPotentialShell; path: CreationContext[] }
|
|
15
|
+
| { status: typeof CONSTANTS.Enums.ResourceShellKind.outputPotential; entry: OutputPotentialShell; path: CreationContext[] }
|
|
16
|
+
| { status: 'unresolved'; reason: 'not-found' | 'cycle' | 'depth-exceeded'; path: CreationContext[] };
|
|
17
17
|
|
|
18
18
|
export function resolveResourceChain(
|
|
19
|
-
strategyState:
|
|
20
|
-
start:
|
|
19
|
+
strategyState: StrategyState,
|
|
20
|
+
start: CreationContext,
|
|
21
21
|
opts?: { maxDepth?: number }
|
|
22
22
|
): ResolveResult {
|
|
23
23
|
const maxDepth = opts?.maxDepth ?? 50;
|
|
24
24
|
const visited = new Set<string>();
|
|
25
|
-
const path:
|
|
26
|
-
let current:
|
|
25
|
+
const path: CreationContext[] = [];
|
|
26
|
+
let current: CreationContext = start;
|
|
27
27
|
|
|
28
28
|
for (let depth = 0; depth <= maxDepth; depth++) {
|
|
29
29
|
path.push(current);
|
|
@@ -36,25 +36,25 @@ export function resolveResourceChain(
|
|
|
36
36
|
const bucket = strategyState[current.toolStepId];
|
|
37
37
|
if (!bucket) return { status: 'unresolved', reason: 'not-found', path };
|
|
38
38
|
const entry = bucket[current.resourceRoleId] as (
|
|
39
|
-
|
|
|
40
|
-
|
|
|
39
|
+
| Resource
|
|
40
|
+
| ResourcePotential
|
|
41
41
|
| undefined
|
|
42
42
|
);
|
|
43
43
|
if (!entry) return { status: 'unresolved', reason: 'not-found', path };
|
|
44
44
|
|
|
45
45
|
if (entry.resourceShellKind === CONSTANTS.Enums.ResourceShellKind.materialized) {
|
|
46
|
-
return { status: CONSTANTS.Enums.ResourceShellKind.materialized, entry: entry as
|
|
46
|
+
return { status: CONSTANTS.Enums.ResourceShellKind.materialized, entry: entry as Resource, path };
|
|
47
47
|
}
|
|
48
48
|
if (entry.resourceShellKind === CONSTANTS.Enums.ResourceShellKind.externalInputPotential) {
|
|
49
|
-
return { status: CONSTANTS.Enums.ResourceShellKind.externalInputPotential, entry: entry as
|
|
49
|
+
return { status: CONSTANTS.Enums.ResourceShellKind.externalInputPotential, entry: entry as ExternalInputPotentialShell, path };
|
|
50
50
|
}
|
|
51
51
|
if (entry.resourceShellKind === CONSTANTS.Enums.ResourceShellKind.outputPotential) {
|
|
52
|
-
return { status: CONSTANTS.Enums.ResourceShellKind.outputPotential, entry: entry as
|
|
52
|
+
return { status: CONSTANTS.Enums.ResourceShellKind.outputPotential, entry: entry as OutputPotentialShell, path };
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
// internalInputPotential: follow ref backwards
|
|
56
56
|
if (entry.resourceShellKind === CONSTANTS.Enums.ResourceShellKind.internalInputPotential) {
|
|
57
|
-
current = (entry as
|
|
57
|
+
current = (entry as InternalInputPotentialShell).creationContext;
|
|
58
58
|
continue;
|
|
59
59
|
}
|
|
60
60
|
|