@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,10 +0,0 @@
|
|
|
1
|
-
import type { BranchStep, ForStep, Tool, ToolStep, WhileStep } from '@toolproof-core/genesis';
|
|
2
|
-
import { CONSTANTS } from '../../lookups/lookups.js';
|
|
3
|
-
export declare function createToolStepFromTool(tool: Tool): ToolStep;
|
|
4
|
-
export declare function createLoopStepFromToolPair(whatTool: Tool, whenTool: Tool, stepKind: typeof CONSTANTS.Enums.StepKind.for | typeof CONSTANTS.Enums.StepKind.while): ForStep | WhileStep;
|
|
5
|
-
export declare function createBranchStepFromToolPairs(cases: Array<{
|
|
6
|
-
whatTool: Tool;
|
|
7
|
-
whenTool: Tool;
|
|
8
|
-
}>): BranchStep;
|
|
9
|
-
export declare function cloneForStep(forStep: ForStep): ForStep;
|
|
10
|
-
export declare function cloneWhileStep(whileStep: WhileStep): WhileStep;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { CONSTANTS } from '../../lookups/lookups.js';
|
|
2
|
-
import { buildBranchStepFromToolPairs, buildToolStepFromTool, buildLoopStepFromToolPair, cloneForStep as cloneForStepPure, cloneWhileStep as cloneWhileStepPure, } from '../../utils/creation/stepCreation.js';
|
|
3
|
-
export function createToolStepFromTool(tool) {
|
|
4
|
-
return buildToolStepFromTool(tool);
|
|
5
|
-
}
|
|
6
|
-
export function createLoopStepFromToolPair(whatTool, whenTool, stepKind) {
|
|
7
|
-
return buildLoopStepFromToolPair(whatTool, whenTool, stepKind);
|
|
8
|
-
}
|
|
9
|
-
export function createBranchStepFromToolPairs(cases) {
|
|
10
|
-
return buildBranchStepFromToolPairs(cases);
|
|
11
|
-
}
|
|
12
|
-
export function cloneForStep(forStep) {
|
|
13
|
-
return cloneForStepPure(forStep);
|
|
14
|
-
}
|
|
15
|
-
export function cloneWhileStep(whileStep) {
|
|
16
|
-
return cloneWhileStepPure(whileStep);
|
|
17
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { CONSTANTS } from '../../lookups/lookups.js';
|
|
2
|
-
import { buildThreadedStrategy, getThreadedStrategyStepGroups, } from '../../utils/creation/threadedStrategyCreation.js';
|
|
3
|
-
import { getNewId } from './firebaseAdminHelpers.js';
|
|
4
|
-
export function createThreadedStrategy(strategy) {
|
|
5
|
-
const threadStepGroups = getThreadedStrategyStepGroups(strategy);
|
|
6
|
-
const strategyHandle = getNewId(CONSTANTS.Names.StrategyHandle);
|
|
7
|
-
return buildThreadedStrategy(threadStepGroups, strategyHandle, strategy);
|
|
8
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { ToolStepRoleAddress, ExternalInputPotential, InternalInputPotential, ResourceId, Resource, ResourcePointer, ResourceTypeHandle, StrategyProvenance, Provenance, StrategyTraceHandle } from '@toolproof-core/genesis';
|
|
2
|
-
type RuntimeProvenance = Extract<Provenance, {
|
|
3
|
-
provenanceKind: 'runtime';
|
|
4
|
-
}>;
|
|
5
|
-
export interface OutputPotential {
|
|
6
|
-
id: ResourceId;
|
|
7
|
-
resourceTypeHandle: ResourceTypeHandle;
|
|
8
|
-
toolStepRoleAddress?: ToolStepRoleAddress;
|
|
9
|
-
strategyTraceHandle?: StrategyTraceHandle;
|
|
10
|
-
provenanceKind?: Provenance['provenanceKind'];
|
|
11
|
-
}
|
|
12
|
-
export declare function createExternalInputPotential(): ExternalInputPotential;
|
|
13
|
-
export declare function createInternalInputPotential(toolStepRoleAddress: ToolStepRoleAddress): InternalInputPotential;
|
|
14
|
-
export declare function createStrategyProvenance(strategyTraceHandle: StrategyTraceHandle, toolStepRoleAddress: ToolStepRoleAddress): StrategyProvenance;
|
|
15
|
-
export declare function createRuntimeProvenance(): RuntimeProvenance;
|
|
16
|
-
export declare function createResourcePointer(id: ResourceId, resourceTypeHandle: ResourceTypeHandle, provenance: Provenance): ResourcePointer;
|
|
17
|
-
export declare function createResource(resourcePointer: ResourcePointer, projection: unknown): Resource;
|
|
18
|
-
export declare function createMaterializedFromOutputPotential(outputPotential: OutputPotential, projection: unknown): Resource;
|
|
19
|
-
export declare function createMaterializedFromPotential(outputPotential: OutputPotential, projection: unknown): Resource;
|
|
20
|
-
export declare function createOutputPotential(id: ResourceId, resourceTypeHandle: ResourceTypeHandle, toolStepRoleAddress?: ToolStepRoleAddress, strategyTraceHandle?: StrategyTraceHandle, provenanceKind?: Provenance['provenanceKind']): OutputPotential;
|
|
21
|
-
export {};
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
export function createExternalInputPotential() {
|
|
2
|
-
return {
|
|
3
|
-
strategyStateInputKind: 'externalInputPotential',
|
|
4
|
-
};
|
|
5
|
-
}
|
|
6
|
-
export function createInternalInputPotential(toolStepRoleAddress) {
|
|
7
|
-
return {
|
|
8
|
-
strategyStateInputKind: 'internalInputPotential',
|
|
9
|
-
toolStepRoleAddress,
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
export function createStrategyProvenance(strategyTraceHandle, toolStepRoleAddress) {
|
|
13
|
-
return {
|
|
14
|
-
provenanceKind: 'strategy',
|
|
15
|
-
strategyTraceHandle,
|
|
16
|
-
toolStepRoleAddress,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
export function createRuntimeProvenance() {
|
|
20
|
-
return {
|
|
21
|
-
provenanceKind: 'runtime',
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
export function createResourcePointer(id, resourceTypeHandle, provenance) {
|
|
25
|
-
return {
|
|
26
|
-
id,
|
|
27
|
-
resourceTypeHandle,
|
|
28
|
-
provenance,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
export function createResource(resourcePointer, projection) {
|
|
32
|
-
return {
|
|
33
|
-
...resourcePointer,
|
|
34
|
-
projection,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
export function createMaterializedFromOutputPotential(outputPotential, projection) {
|
|
38
|
-
const provenance = outputPotential.provenanceKind === 'runtime'
|
|
39
|
-
? createRuntimeProvenance()
|
|
40
|
-
: createStrategyProvenance(requireStrategyTraceHandle(outputPotential.strategyTraceHandle), requireToolStepRoleAddress(outputPotential.toolStepRoleAddress));
|
|
41
|
-
const resourcePointer = createResourcePointer(outputPotential.id, outputPotential.resourceTypeHandle, provenance);
|
|
42
|
-
return createResource(resourcePointer, projection);
|
|
43
|
-
}
|
|
44
|
-
export function createMaterializedFromPotential(outputPotential, projection) {
|
|
45
|
-
return createMaterializedFromOutputPotential(outputPotential, projection);
|
|
46
|
-
}
|
|
47
|
-
export function createOutputPotential(id, resourceTypeHandle, toolStepRoleAddress, strategyTraceHandle, provenanceKind) {
|
|
48
|
-
return {
|
|
49
|
-
id,
|
|
50
|
-
resourceTypeHandle,
|
|
51
|
-
...(toolStepRoleAddress ? { toolStepRoleAddress } : {}),
|
|
52
|
-
...(strategyTraceHandle ? { strategyTraceHandle } : {}),
|
|
53
|
-
...(provenanceKind ? { provenanceKind } : {}),
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
function requireStrategyTraceHandle(strategyTraceHandle) {
|
|
57
|
-
if (!strategyTraceHandle) {
|
|
58
|
-
throw new Error('strategyTraceHandle is required to materialize a strategy output potential');
|
|
59
|
-
}
|
|
60
|
-
return strategyTraceHandle;
|
|
61
|
-
}
|
|
62
|
-
function requireToolStepRoleAddress(toolStepRoleAddress) {
|
|
63
|
-
if (!toolStepRoleAddress) {
|
|
64
|
-
throw new Error('toolStepRoleAddress is required to materialize a strategy output potential');
|
|
65
|
-
}
|
|
66
|
-
return toolStepRoleAddress;
|
|
67
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { BranchStep, ForStep, Tool, ToolStep, WhileStep } from '@toolproof-core/genesis';
|
|
2
|
-
import { CONSTANTS } from '../../lookups/lookups.js';
|
|
3
|
-
export declare function buildToolStepFromTool(tool: Tool): ToolStep;
|
|
4
|
-
export declare function buildLoopStepFromToolPair(whatTool: Tool, whenTool: Tool, stepKind: typeof CONSTANTS.Enums.StepKind.for | typeof CONSTANTS.Enums.StepKind.while): ForStep | WhileStep;
|
|
5
|
-
export declare function buildBranchStepFromToolPairs(cases: Array<{
|
|
6
|
-
whatTool: Tool;
|
|
7
|
-
whenTool: Tool;
|
|
8
|
-
}>): BranchStep;
|
|
9
|
-
export declare function cloneForStep(forStep: ForStep): ForStep;
|
|
10
|
-
export declare function cloneWhileStep(whileStep: WhileStep): WhileStep;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { CONSTANTS } from '../../lookups/lookups.js';
|
|
2
|
-
import { getInputRoleNames, getOutputRoleNames } from '../roleSpec.js';
|
|
3
|
-
function assertNonEmpty(arr, msg) {
|
|
4
|
-
if (arr.length === 0) {
|
|
5
|
-
throw new Error(msg);
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
function getRoleBindingSpec(tool) {
|
|
9
|
-
return {
|
|
10
|
-
inputBindings: getInputRoleNames(tool),
|
|
11
|
-
outputBindings: getOutputRoleNames(tool),
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
export function buildToolStepFromTool(tool) {
|
|
15
|
-
return {
|
|
16
|
-
stepKind: CONSTANTS.Enums.StepKind.tool,
|
|
17
|
-
toolHandle: tool.handle,
|
|
18
|
-
roleBindingSpec: getRoleBindingSpec(tool),
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
export function buildLoopStepFromToolPair(whatTool, whenTool, stepKind) {
|
|
22
|
-
const what = buildToolStepFromTool(whatTool);
|
|
23
|
-
const when = buildToolStepFromTool(whenTool);
|
|
24
|
-
if (stepKind === CONSTANTS.Enums.StepKind.for) {
|
|
25
|
-
return {
|
|
26
|
-
stepKind: CONSTANTS.Enums.StepKind.for,
|
|
27
|
-
case: { what, when },
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
return {
|
|
31
|
-
stepKind: CONSTANTS.Enums.StepKind.while,
|
|
32
|
-
case: { what, when },
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
export function buildBranchStepFromToolPairs(cases) {
|
|
36
|
-
const resolved = cases.map(({ whatTool, whenTool }, index) => {
|
|
37
|
-
const what = buildToolStepFromTool(whatTool);
|
|
38
|
-
const when = buildToolStepFromTool(whenTool);
|
|
39
|
-
return { what, when };
|
|
40
|
-
});
|
|
41
|
-
assertNonEmpty(resolved, 'buildBranchStepFromToolPairs requires at least one case');
|
|
42
|
-
return {
|
|
43
|
-
stepKind: CONSTANTS.Enums.StepKind.branch,
|
|
44
|
-
cases: resolved,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
export function cloneForStep(forStep) {
|
|
48
|
-
return {
|
|
49
|
-
stepKind: CONSTANTS.Enums.StepKind.for,
|
|
50
|
-
case: {
|
|
51
|
-
what: { ...forStep.case.what },
|
|
52
|
-
when: { ...forStep.case.when },
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
export function cloneWhileStep(whileStep) {
|
|
57
|
-
return {
|
|
58
|
-
stepKind: CONSTANTS.Enums.StepKind.while,
|
|
59
|
-
case: {
|
|
60
|
-
what: { ...whileStep.case.what },
|
|
61
|
-
when: { ...whileStep.case.when },
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Step, StrategyHandle } from '@toolproof-core/genesis';
|
|
2
|
-
import { CONSTANTS } from '../../lookups/lookups.js';
|
|
3
|
-
export type ThreadableStrategy<TStrategyState = unknown> = {
|
|
4
|
-
handle: StrategyHandle;
|
|
5
|
-
strategyState: TStrategyState;
|
|
6
|
-
} & ({
|
|
7
|
-
steps: Step[];
|
|
8
|
-
} | {
|
|
9
|
-
stepsByThreadIndex: Step[][];
|
|
10
|
-
});
|
|
11
|
-
export type ThreadedStrategyLike<TStrategyState = unknown> = {
|
|
12
|
-
handle: StrategyHandle;
|
|
13
|
-
strategyKind: typeof CONSTANTS.Enums.StrategyKind.threaded;
|
|
14
|
-
stepsByThreadIndex: Step[][];
|
|
15
|
-
strategyState: TStrategyState;
|
|
16
|
-
};
|
|
17
|
-
export declare function getThreadedStrategyStepGroups<TStrategyState>(strategy: ThreadableStrategy<TStrategyState>): Step[][];
|
|
18
|
-
export declare function buildThreadedStrategy<TStrategyState>(threadStepGroups: Step[][], threadedStrategyHandle: StrategyHandle, strategy: ThreadableStrategy<TStrategyState>): ThreadedStrategyLike<TStrategyState>;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { getIndependentThreads } from '../parallelizeSteps.js';
|
|
2
|
-
import { CONSTANTS } from '../../lookups/lookups.js';
|
|
3
|
-
export function getThreadedStrategyStepGroups(strategy) {
|
|
4
|
-
if ('steps' in strategy) {
|
|
5
|
-
return getIndependentThreads(strategy.steps, strategy.strategyState);
|
|
6
|
-
}
|
|
7
|
-
return strategy.stepsByThreadIndex;
|
|
8
|
-
}
|
|
9
|
-
export function buildThreadedStrategy(threadStepGroups, threadedStrategyHandle, strategy) {
|
|
10
|
-
return {
|
|
11
|
-
handle: threadedStrategyHandle,
|
|
12
|
-
strategyKind: CONSTANTS.Enums.StrategyKind.threaded,
|
|
13
|
-
stepsByThreadIndex: threadStepGroups,
|
|
14
|
-
strategyState: strategy.strategyState,
|
|
15
|
-
};
|
|
16
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { RoleName, ToolHandle, Tool, ToolStep, ResourceId, ResourceTypeHandle, Resource } from '@toolproof-core/genesis';
|
|
2
|
-
import { type StrategyStepGraph, type ToolRoleDescriptor } from './roleSpec.js';
|
|
3
|
-
export declare function extractToolHandlesFromUnthreadedStrategy(unthreadedStrategy: StrategyStepGraph): ToolHandle[];
|
|
4
|
-
export declare function extractToolStepsFromUnthreadedStrategy(unthreadedStrategy: StrategyStepGraph): ToolStep[];
|
|
5
|
-
export declare function extractRoleMapFromUnthreadedStrategy(unthreadedStrategy: StrategyStepGraph, toolMap: Map<ToolHandle, Tool>): Map<RoleName, ToolRoleDescriptor>;
|
|
6
|
-
export declare function extractSingleNonErrorOutputTypeId(tool: Tool): ResourceTypeHandle | null;
|
|
7
|
-
export declare function extractResourceMapForType<TResource extends Resource = Resource>(resourcesByType: Partial<Record<ResourceTypeHandle, TResource[]>>, resourceTypeHandle: ResourceTypeHandle): Map<ResourceId, TResource>;
|
|
8
|
-
export declare function extractIdKeyedValueMapForType<TKey extends string = string, TValue extends {
|
|
9
|
-
id: string | number | boolean;
|
|
10
|
-
} = {
|
|
11
|
-
id: string | number | boolean;
|
|
12
|
-
}, TResource extends Resource = Resource>(resourcesByType: Partial<Record<ResourceTypeHandle, TResource[]>>, resourceTypeHandle: ResourceTypeHandle): Map<TKey, TValue>;
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { extractToolStepsFromStrategy, getInputRoleEntries, getOutputRoleEntries, toToolRoleDescriptor, } from './roleSpec.js';
|
|
2
|
-
const ERROR_OUTPUT_ROLE_NAME = 'ErrorOutput';
|
|
3
|
-
function extractResourceTypeHandleFromRoleValue(toolRoleValue) {
|
|
4
|
-
const typeRef = toolRoleValue.typeRef;
|
|
5
|
-
if ('resourceTypeHandle' in typeRef) {
|
|
6
|
-
return typeRef.resourceTypeHandle;
|
|
7
|
-
}
|
|
8
|
-
return null;
|
|
9
|
-
}
|
|
10
|
-
export function extractToolHandlesFromUnthreadedStrategy(unthreadedStrategy) {
|
|
11
|
-
const toolSteps = extractToolStepsFromUnthreadedStrategy(unthreadedStrategy);
|
|
12
|
-
const ids = new Set();
|
|
13
|
-
for (const jStep of toolSteps) {
|
|
14
|
-
ids.add(jStep.toolHandle);
|
|
15
|
-
}
|
|
16
|
-
return Array.from(ids);
|
|
17
|
-
}
|
|
18
|
-
export function extractToolStepsFromUnthreadedStrategy(unthreadedStrategy) {
|
|
19
|
-
return extractToolStepsFromStrategy(unthreadedStrategy);
|
|
20
|
-
}
|
|
21
|
-
export function extractRoleMapFromUnthreadedStrategy(unthreadedStrategy, toolMap) {
|
|
22
|
-
const roleMap = new Map();
|
|
23
|
-
const toolHandles = extractToolHandlesFromUnthreadedStrategy(unthreadedStrategy);
|
|
24
|
-
for (const toolHandle of toolHandles) {
|
|
25
|
-
const tool = toolMap.get(toolHandle);
|
|
26
|
-
if (!tool)
|
|
27
|
-
continue;
|
|
28
|
-
for (const entry of getInputRoleEntries(tool)) {
|
|
29
|
-
roleMap.set(entry[0], toToolRoleDescriptor(entry));
|
|
30
|
-
}
|
|
31
|
-
for (const entry of getOutputRoleEntries(tool)) {
|
|
32
|
-
roleMap.set(entry[0], toToolRoleDescriptor(entry));
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return roleMap;
|
|
36
|
-
}
|
|
37
|
-
export function extractSingleNonErrorOutputTypeId(tool) {
|
|
38
|
-
const outputEntries = getOutputRoleEntries(tool).filter(([roleName]) => roleName !== ERROR_OUTPUT_ROLE_NAME);
|
|
39
|
-
if (!outputEntries || !outputEntries[0] || outputEntries.length !== 1) {
|
|
40
|
-
throw new Error(`Tool ${tool.handle} must have exactly one non-error output role to be branchable/loopable`);
|
|
41
|
-
} // ATTENTION_PUREIFY
|
|
42
|
-
return extractResourceTypeHandleFromRoleValue(toToolRoleDescriptor(outputEntries[0]));
|
|
43
|
-
}
|
|
44
|
-
export function extractResourceMapForType(resourcesByType, resourceTypeHandle) {
|
|
45
|
-
const resources = resourcesByType[resourceTypeHandle] ?? [];
|
|
46
|
-
const map = new Map();
|
|
47
|
-
for (const resource of resources) {
|
|
48
|
-
map.set(resource.id, resource);
|
|
49
|
-
}
|
|
50
|
-
return map;
|
|
51
|
-
}
|
|
52
|
-
// Only use this for resource types whose nuclei are entity-like objects with their own intrinsic id.
|
|
53
|
-
export function extractIdKeyedValueMapForType(resourcesByType, resourceTypeHandle) {
|
|
54
|
-
const resourceMap = extractResourceMapForType(resourcesByType, resourceTypeHandle);
|
|
55
|
-
const out = new Map();
|
|
56
|
-
for (const resource of resourceMap.values()) {
|
|
57
|
-
const data = resource.projection;
|
|
58
|
-
if (data === null || data === undefined) {
|
|
59
|
-
throw new Error(`Expected resource '${resource.id}' of type '${resourceTypeHandle}' to have a projection`);
|
|
60
|
-
}
|
|
61
|
-
if (typeof data !== 'object') {
|
|
62
|
-
throw new Error(`Expected resource '${resource.id}' of type '${resourceTypeHandle}' to have an object projection with id`);
|
|
63
|
-
}
|
|
64
|
-
const maybeId = data.id;
|
|
65
|
-
if (maybeId === null || maybeId === undefined) {
|
|
66
|
-
throw new Error(`Expected resource '${resource.id}' of type '${resourceTypeHandle}' to have projection.id`);
|
|
67
|
-
}
|
|
68
|
-
if (typeof maybeId !== 'string' &&
|
|
69
|
-
typeof maybeId !== 'number' &&
|
|
70
|
-
typeof maybeId !== 'boolean') {
|
|
71
|
-
throw new Error(`Expected resource '${resource.id}' of type '${resourceTypeHandle}' to have projection.id as string, number, or boolean`);
|
|
72
|
-
}
|
|
73
|
-
const value = data;
|
|
74
|
-
const key = String(maybeId);
|
|
75
|
-
out.set(key, value);
|
|
76
|
-
}
|
|
77
|
-
return out;
|
|
78
|
-
}
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { CONSTANTS } from '../lookups/lookups.js';
|
|
2
|
-
function toUnthreadedToolStepPath(opts) {
|
|
3
|
-
const base = `/steps/${opts.stepIndex}`;
|
|
4
|
-
switch (opts.toolStepSlot) {
|
|
5
|
-
case 'self':
|
|
6
|
-
return `${base}/self`;
|
|
7
|
-
case 'case.when':
|
|
8
|
-
return `${base}/case/when`;
|
|
9
|
-
case 'case.what':
|
|
10
|
-
return `${base}/case/what`;
|
|
11
|
-
case 'cases.when':
|
|
12
|
-
if (typeof opts.caseIndex !== 'number') {
|
|
13
|
-
throw new Error('Expected caseIndex for cases.when path');
|
|
14
|
-
}
|
|
15
|
-
return `${base}/cases/${opts.caseIndex}/when`;
|
|
16
|
-
case 'cases.what':
|
|
17
|
-
if (typeof opts.caseIndex !== 'number') {
|
|
18
|
-
throw new Error('Expected caseIndex for cases.what path');
|
|
19
|
-
}
|
|
20
|
-
return `${base}/cases/${opts.caseIndex}/what`;
|
|
21
|
-
default: {
|
|
22
|
-
const _exhaustive = opts.toolStepSlot;
|
|
23
|
-
return _exhaustive;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
export function getIndependentThreads(steps, strategyState) {
|
|
28
|
-
const getOwnerLabel = (ownerIndex) => {
|
|
29
|
-
const step = steps[ownerIndex];
|
|
30
|
-
return `steps[${ownerIndex}] stepKind=${step?.stepKind ?? 'unknown'}`;
|
|
31
|
-
};
|
|
32
|
-
// Map each canonical toolStepPath (including macro-nested tool steps) to its owning top-level step index.
|
|
33
|
-
const toolStepPathToOwner = new Map();
|
|
34
|
-
const toolStepByPath = new Map();
|
|
35
|
-
const addToolStep = (toolStep, ownerIndex, toolStepPath) => {
|
|
36
|
-
if (!toolStep)
|
|
37
|
-
return;
|
|
38
|
-
const existingOwner = toolStepPathToOwner.get(toolStepPath);
|
|
39
|
-
if (existingOwner !== undefined) {
|
|
40
|
-
throw new Error(`Duplicate toolStepPath '${toolStepPath}' found in ${getOwnerLabel(ownerIndex)} and ${getOwnerLabel(existingOwner)}`);
|
|
41
|
-
}
|
|
42
|
-
toolStepPathToOwner.set(toolStepPath, ownerIndex);
|
|
43
|
-
toolStepByPath.set(toolStepPath, toolStep);
|
|
44
|
-
};
|
|
45
|
-
steps.forEach((step, ownerIndex) => {
|
|
46
|
-
if (step.stepKind === CONSTANTS.Enums.StepKind.tool) {
|
|
47
|
-
addToolStep(step, ownerIndex, toUnthreadedToolStepPath({ stepIndex: ownerIndex, toolStepSlot: 'self' }));
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
if (step.stepKind === CONSTANTS.Enums.StepKind.for) {
|
|
51
|
-
const loop = step;
|
|
52
|
-
addToolStep(loop.case?.what, ownerIndex, toUnthreadedToolStepPath({ stepIndex: ownerIndex, toolStepSlot: 'case.what' }));
|
|
53
|
-
addToolStep(loop.case?.when, ownerIndex, toUnthreadedToolStepPath({ stepIndex: ownerIndex, toolStepSlot: 'case.when' }));
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
if (step.stepKind === CONSTANTS.Enums.StepKind.while) {
|
|
57
|
-
const loop = step;
|
|
58
|
-
addToolStep(loop.case?.what, ownerIndex, toUnthreadedToolStepPath({ stepIndex: ownerIndex, toolStepSlot: 'case.what' }));
|
|
59
|
-
addToolStep(loop.case?.when, ownerIndex, toUnthreadedToolStepPath({ stepIndex: ownerIndex, toolStepSlot: 'case.when' }));
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
if (step.stepKind === CONSTANTS.Enums.StepKind.branch) {
|
|
63
|
-
const branch = step;
|
|
64
|
-
for (const [caseIndex, caseItem] of (branch.cases ?? []).entries()) {
|
|
65
|
-
addToolStep(caseItem?.what, ownerIndex, toUnthreadedToolStepPath({ stepIndex: ownerIndex, toolStepSlot: 'cases.what', caseIndex }));
|
|
66
|
-
addToolStep(caseItem?.when, ownerIndex, toUnthreadedToolStepPath({ stepIndex: ownerIndex, toolStepSlot: 'cases.when', caseIndex }));
|
|
67
|
-
}
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
// Undirected adjacency used for connected components (thread groups).
|
|
72
|
-
const ownerAdj = new Map();
|
|
73
|
-
// Directed dependencies used for strict ordering validation: owner -> producers it depends on.
|
|
74
|
-
const ownerDeps = new Map();
|
|
75
|
-
const ensureOwner = (ownerIndex) => {
|
|
76
|
-
if (!ownerAdj.has(ownerIndex))
|
|
77
|
-
ownerAdj.set(ownerIndex, new Set());
|
|
78
|
-
if (!ownerDeps.has(ownerIndex))
|
|
79
|
-
ownerDeps.set(ownerIndex, new Set());
|
|
80
|
-
};
|
|
81
|
-
for (let i = 0; i < steps.length; i++) {
|
|
82
|
-
ensureOwner(i);
|
|
83
|
-
}
|
|
84
|
-
// Discover dependencies from strategyState.
|
|
85
|
-
for (const [toolStepPath, ownerIndex] of toolStepPathToOwner) {
|
|
86
|
-
ensureOwner(ownerIndex);
|
|
87
|
-
const toolStep = toolStepByPath.get(toolStepPath);
|
|
88
|
-
const inputBindings = toolStep?.roleBindingSpec?.inputBindings ?? [];
|
|
89
|
-
const bucket = strategyState?.[toolStepPath] ?? {};
|
|
90
|
-
for (const inputRoleId of inputBindings) {
|
|
91
|
-
const entry = bucket?.[inputRoleId];
|
|
92
|
-
if (!entry || entry.strategyStateInputKind !== 'internalInputPotential')
|
|
93
|
-
continue;
|
|
94
|
-
const creatorToolStepPath = typeof entry?.toolStepRoleAddress?.toolStepPath === 'string'
|
|
95
|
-
? entry.toolStepRoleAddress.toolStepPath
|
|
96
|
-
: undefined;
|
|
97
|
-
if (!creatorToolStepPath) {
|
|
98
|
-
throw new Error(`Unresolvable internalInputPotential in toolStep '${toolStepPath}' (${getOwnerLabel(ownerIndex)}): missing toolStepRoleAddress.toolStepPath for role '${inputRoleId}'`);
|
|
99
|
-
}
|
|
100
|
-
const producerOwner = toolStepPathToOwner.get(creatorToolStepPath);
|
|
101
|
-
if (producerOwner === undefined) {
|
|
102
|
-
throw new Error(`Unresolvable internalInputPotential in toolStep '${toolStepPath}' (${getOwnerLabel(ownerIndex)}): source toolStepPath '${creatorToolStepPath}' not found in strategy steps`);
|
|
103
|
-
}
|
|
104
|
-
ensureOwner(producerOwner);
|
|
105
|
-
ownerAdj.get(ownerIndex).add(producerOwner);
|
|
106
|
-
ownerAdj.get(producerOwner).add(ownerIndex);
|
|
107
|
-
ownerDeps.get(ownerIndex).add(producerOwner);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
// Connected components over owners.
|
|
111
|
-
const visited = new Set();
|
|
112
|
-
const components = [];
|
|
113
|
-
for (let ownerIndex = 0; ownerIndex < steps.length; ownerIndex++) {
|
|
114
|
-
if (visited.has(ownerIndex))
|
|
115
|
-
continue;
|
|
116
|
-
const component = [];
|
|
117
|
-
const queue = [ownerIndex];
|
|
118
|
-
visited.add(ownerIndex);
|
|
119
|
-
while (queue.length > 0) {
|
|
120
|
-
const node = queue.shift();
|
|
121
|
-
component.push(node);
|
|
122
|
-
for (const neighbor of ownerAdj.get(node) ?? []) {
|
|
123
|
-
if (!visited.has(neighbor)) {
|
|
124
|
-
visited.add(neighbor);
|
|
125
|
-
queue.push(neighbor);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
components.push(component);
|
|
130
|
-
}
|
|
131
|
-
// Strict validation: within a thread, the linear order must not contain forward refs.
|
|
132
|
-
for (const comp of components) {
|
|
133
|
-
const compSet = new Set(comp);
|
|
134
|
-
const ownersInOrder = steps.map((_, i) => i).filter((i) => compSet.has(i));
|
|
135
|
-
const position = new Map();
|
|
136
|
-
ownersInOrder.forEach((owner, idx) => position.set(owner, idx));
|
|
137
|
-
for (const consumerOwner of ownersInOrder) {
|
|
138
|
-
const deps = ownerDeps.get(consumerOwner);
|
|
139
|
-
if (!deps || deps.size === 0)
|
|
140
|
-
continue;
|
|
141
|
-
const consumerPos = position.get(consumerOwner);
|
|
142
|
-
for (const producerOwner of deps) {
|
|
143
|
-
const producerPos = position.get(producerOwner);
|
|
144
|
-
if (producerPos === undefined) {
|
|
145
|
-
throw new Error(`Internal error: dependency producer ${getOwnerLabel(producerOwner)} missing from computed thread for ${getOwnerLabel(consumerOwner)}`);
|
|
146
|
-
}
|
|
147
|
-
if (producerPos >= consumerPos) {
|
|
148
|
-
throw new Error(`Invalid step order in thread: ${getOwnerLabel(consumerOwner)} depends on ${getOwnerLabel(producerOwner)}, but producer is not scheduled before consumer`);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
return components
|
|
154
|
-
.map((compOwners) => {
|
|
155
|
-
const ownerSet = new Set(compOwners);
|
|
156
|
-
return steps.filter((_, i) => ownerSet.has(i));
|
|
157
|
-
})
|
|
158
|
-
.filter((group) => group.length > 0);
|
|
159
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { ToolStepRoleAddress, ExternalInputPotential, InputResource, ThreadedStrategyState, ThreadedToolStepRoleAddress, UnthreadedStrategyState, UnthreadedToolStepRoleAddress } from '@toolproof-core/genesis';
|
|
2
|
-
import { type StrategyState } from './strategyState.js';
|
|
3
|
-
type ToolStepRoleAddressForStrategyState<TStrategyState extends StrategyState> = TStrategyState extends UnthreadedStrategyState ? UnthreadedToolStepRoleAddress : TStrategyState extends ThreadedStrategyState ? ThreadedToolStepRoleAddress : ToolStepRoleAddress;
|
|
4
|
-
export type ResolveResult = {
|
|
5
|
-
status: 'inputResource';
|
|
6
|
-
entry: InputResource;
|
|
7
|
-
path: ToolStepRoleAddress[];
|
|
8
|
-
} | {
|
|
9
|
-
status: 'externalInputPotential';
|
|
10
|
-
entry: ExternalInputPotential;
|
|
11
|
-
path: ToolStepRoleAddress[];
|
|
12
|
-
} | {
|
|
13
|
-
status: 'unresolved';
|
|
14
|
-
reason: 'not-found' | 'cycle' | 'depth-exceeded';
|
|
15
|
-
path: ToolStepRoleAddress[];
|
|
16
|
-
};
|
|
17
|
-
export declare function resolveStrategyStateChain<TStrategyState extends StrategyState>(strategyState: TStrategyState, start: ToolStepRoleAddressForStrategyState<TStrategyState>, opts?: {
|
|
18
|
-
maxDepth?: number;
|
|
19
|
-
}): ResolveResult;
|
|
20
|
-
export {};
|
package/dist/utils/roleSpec.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { RoleName, RoleValue, Step, StepArrayArray, Tool, ToolStep } from '@toolproof-core/genesis';
|
|
2
|
-
export type StrategyStepGraph = {
|
|
3
|
-
steps: Step[];
|
|
4
|
-
} | {
|
|
5
|
-
stepsByThreadIndex: StepArrayArray;
|
|
6
|
-
};
|
|
7
|
-
export interface ToolRoleDescriptor extends RoleValue {
|
|
8
|
-
id: RoleName;
|
|
9
|
-
name: string;
|
|
10
|
-
}
|
|
11
|
-
export declare function getInputRoleEntries(tool: Tool): Array<[RoleName, RoleValue]>;
|
|
12
|
-
export declare function getOutputRoleEntries(tool: Tool): Array<[RoleName, RoleValue]>;
|
|
13
|
-
export declare function getInputRoleNames(tool: Tool): RoleName[];
|
|
14
|
-
export declare function getOutputRoleNames(tool: Tool): RoleName[];
|
|
15
|
-
export declare function toToolRoleDescriptor([roleName, roleValue]: [RoleName, RoleValue]): ToolRoleDescriptor;
|
|
16
|
-
export declare function extractToolStepsFromStrategy(strategy: StrategyStepGraph): ToolStep[];
|
package/dist/utils/roleSpec.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
export function getInputRoleEntries(tool) {
|
|
2
|
-
return Object.entries(tool.roleSpec.inputRoleValueByName);
|
|
3
|
-
}
|
|
4
|
-
export function getOutputRoleEntries(tool) {
|
|
5
|
-
return Object.entries(tool.roleSpec.outputRoleValueByName);
|
|
6
|
-
}
|
|
7
|
-
export function getInputRoleNames(tool) {
|
|
8
|
-
return getInputRoleEntries(tool).map(([roleName]) => roleName);
|
|
9
|
-
}
|
|
10
|
-
export function getOutputRoleNames(tool) {
|
|
11
|
-
return getOutputRoleEntries(tool).map(([roleName]) => roleName);
|
|
12
|
-
}
|
|
13
|
-
export function toToolRoleDescriptor([roleName, roleValue]) {
|
|
14
|
-
return {
|
|
15
|
-
id: roleName,
|
|
16
|
-
name: roleName,
|
|
17
|
-
...roleValue,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
export function extractToolStepsFromStrategy(strategy) {
|
|
21
|
-
const toolSteps = [];
|
|
22
|
-
const visitStep = (step) => {
|
|
23
|
-
switch (step.stepKind) {
|
|
24
|
-
case 'tool': {
|
|
25
|
-
toolSteps.push(step);
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
case 'branch': {
|
|
29
|
-
for (const conditional of step.cases) {
|
|
30
|
-
toolSteps.push(conditional.when, conditional.what);
|
|
31
|
-
}
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
case 'while':
|
|
35
|
-
case 'for': {
|
|
36
|
-
toolSteps.push(step.case.when, step.case.what);
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
default: {
|
|
40
|
-
const _exhaustive = step;
|
|
41
|
-
return _exhaustive;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
if ('steps' in strategy) {
|
|
46
|
-
for (const step of strategy.steps) {
|
|
47
|
-
visitStep(step);
|
|
48
|
-
}
|
|
49
|
-
return toolSteps;
|
|
50
|
-
}
|
|
51
|
-
for (const threadSteps of strategy.stepsByThreadIndex) {
|
|
52
|
-
for (const step of threadSteps) {
|
|
53
|
-
visitStep(step);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return toolSteps;
|
|
57
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ToolStepRoleAddress, ToolStepPath, Resource, Strategy, StrategyStateInputEntry, StrategyStateInputEntryByRoleName, ThreadedStrategyState, ThreadedToolStepPath, ThreadedToolStepRoleAddress, UnthreadedStrategyState, UnthreadedToolStepPath, UnthreadedToolStepRoleAddress } from '@toolproof-core/genesis';
|
|
2
|
-
export type StrategyState = Strategy['strategyState'];
|
|
3
|
-
type ToolStepPathForStrategyState<TStrategyState extends StrategyState> = TStrategyState extends UnthreadedStrategyState ? UnthreadedToolStepPath : TStrategyState extends ThreadedStrategyState ? ThreadedToolStepPath : ToolStepPath;
|
|
4
|
-
type ToolStepRoleAddressForStrategyState<TStrategyState extends StrategyState> = TStrategyState extends UnthreadedStrategyState ? UnthreadedToolStepRoleAddress : TStrategyState extends ThreadedStrategyState ? ThreadedToolStepRoleAddress : ToolStepRoleAddress;
|
|
5
|
-
export declare function getStrategyStateBucket<TStrategyState extends StrategyState>(strategyState: TStrategyState, toolStepPath: ToolStepPathForStrategyState<TStrategyState>): StrategyStateInputEntryByRoleName | undefined;
|
|
6
|
-
export declare function getStrategyStateEntry<TStrategyState extends StrategyState>(strategyState: TStrategyState, toolStepRoleAddress: ToolStepRoleAddressForStrategyState<TStrategyState>): StrategyStateInputEntry | undefined;
|
|
7
|
-
export declare function setStrategyStateEntry<TStrategyState extends StrategyState>(strategyState: TStrategyState, toolStepRoleAddress: ToolStepRoleAddressForStrategyState<TStrategyState>, entry: StrategyStateInputEntry): TStrategyState;
|
|
8
|
-
export declare function clearStrategyStateEntry<TStrategyState extends StrategyState>(strategyState: TStrategyState, toolStepRoleAddress: ToolStepRoleAddressForStrategyState<TStrategyState>): TStrategyState;
|
|
9
|
-
export declare function bindInputResource<TStrategyState extends StrategyState>(strategyState: TStrategyState, target: ToolStepRoleAddressForStrategyState<TStrategyState>, resource: Resource): TStrategyState;
|
|
10
|
-
export declare function bindInternalInputPotential<TStrategyState extends StrategyState>(strategyState: TStrategyState, target: ToolStepRoleAddressForStrategyState<TStrategyState>, source: ToolStepRoleAddressForStrategyState<TStrategyState>): TStrategyState;
|
|
11
|
-
export declare function bindExternalInputPotential<TStrategyState extends StrategyState>(strategyState: TStrategyState, target: ToolStepRoleAddressForStrategyState<TStrategyState>): TStrategyState;
|
|
12
|
-
export {};
|