@toolproof-core/lib 1.0.34 → 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.
Files changed (114) hide show
  1. package/dist/integrations/firebase/firebaseAdminHelpers.d.ts +3 -10
  2. package/dist/integrations/firebase/firebaseAdminHelpers.js +43 -148
  3. package/dist/integrations/firebase/firebaseAdminInit.d.ts +0 -1
  4. package/dist/integrations/firebase/firebaseAdminInit.js +0 -1
  5. package/dist/lookups/lookups.d.ts +214 -0
  6. package/dist/lookups/lookups.js +33 -0
  7. package/dist/types/types.d.ts +15 -15
  8. package/dist/types/types.js +2 -3
  9. package/dist/utils/cosmosDataExtraction.d.ts +5 -0
  10. package/dist/utils/cosmosDataExtraction.js +15 -0
  11. package/dist/utils/identifierGeneration.d.ts +2 -0
  12. package/dist/utils/identifierGeneration.js +5 -0
  13. package/dist/utils/mutableStrategyOverlay.d.ts +55 -0
  14. package/dist/utils/mutableStrategyOverlay.js +115 -0
  15. package/dist/utils/resourceCreation.d.ts +11 -0
  16. package/dist/utils/resourceCreation.js +32 -0
  17. package/dist/utils/stepCreation.d.ts +9 -0
  18. package/dist/utils/stepCreation.js +79 -0
  19. package/dist/utils/stepParallelization.d.ts +2 -0
  20. package/dist/utils/{parallelizeSteps.js → stepParallelization.js} +40 -55
  21. package/dist/utils/strategyAssembly.d.ts +3 -0
  22. package/dist/utils/strategyAssembly.js +6 -0
  23. package/dist/utils/strategyCanonicalization.d.ts +4 -0
  24. package/dist/utils/strategyCanonicalization.js +215 -0
  25. package/dist/utils/strategyExtraction.d.ts +17 -0
  26. package/dist/utils/strategyExtraction.js +88 -0
  27. package/dist/utils/strategyStateResolution.d.ts +17 -0
  28. package/dist/utils/strategyStateResolution.js +27 -0
  29. package/dist/utils/strategyThreading.d.ts +2 -0
  30. package/dist/utils/strategyThreading.js +10 -0
  31. package/dist/utils/toolStepPaths.d.ts +2 -0
  32. package/dist/utils/toolStepPaths.js +21 -0
  33. package/package.json +43 -23
  34. package/src/integrations/firebase/firebaseAdminHelpers.ts +57 -180
  35. package/src/lookups/lookups.ts +35 -0
  36. package/src/types/types.ts +16 -13
  37. package/src/utils/cosmosDataExtraction.ts +25 -0
  38. package/src/utils/identifierGeneration.ts +12 -0
  39. package/src/utils/mutableStrategyOverlay.ts +286 -0
  40. package/src/utils/resourceCreation.ts +87 -0
  41. package/src/utils/stepCreation.ts +114 -0
  42. package/src/utils/stepParallelization.ts +181 -0
  43. package/src/utils/strategyAssembly.ts +14 -0
  44. package/src/utils/strategyCanonicalization.ts +294 -0
  45. package/src/utils/strategyExtraction.ts +150 -0
  46. package/src/utils/strategyStateResolution.ts +57 -0
  47. package/src/utils/strategyThreading.ts +27 -0
  48. package/src/utils/toolStepPaths.ts +34 -0
  49. package/tsconfig.tsbuildinfo +1 -1
  50. package/dist/artifacts/artifacts.d.ts +0 -175
  51. package/dist/artifacts/artifacts.d.ts.map +0 -1
  52. package/dist/artifacts/artifacts.js +0 -48
  53. package/dist/artifacts/artifacts.js.map +0 -1
  54. package/dist/integrations/firebase/createStep.d.ts +0 -11
  55. package/dist/integrations/firebase/createStep.d.ts.map +0 -1
  56. package/dist/integrations/firebase/createStep.js +0 -43
  57. package/dist/integrations/firebase/createStep.js.map +0 -1
  58. package/dist/integrations/firebase/createThreadedStrategy.d.ts +0 -3
  59. package/dist/integrations/firebase/createThreadedStrategy.d.ts.map +0 -1
  60. package/dist/integrations/firebase/createThreadedStrategy.js +0 -9
  61. package/dist/integrations/firebase/createThreadedStrategy.js.map +0 -1
  62. package/dist/integrations/firebase/firebaseAdminHelpers.d.ts.map +0 -1
  63. package/dist/integrations/firebase/firebaseAdminHelpers.js.map +0 -1
  64. package/dist/integrations/firebase/firebaseAdminInit.d.ts.map +0 -1
  65. package/dist/integrations/firebase/firebaseAdminInit.js.map +0 -1
  66. package/dist/types/types.d.ts.map +0 -1
  67. package/dist/types/types.js.map +0 -1
  68. package/dist/utils/bindInputRoleToResource.d.ts +0 -6
  69. package/dist/utils/bindInputRoleToResource.d.ts.map +0 -1
  70. package/dist/utils/bindInputRoleToResource.js +0 -25
  71. package/dist/utils/bindInputRoleToResource.js.map +0 -1
  72. package/dist/utils/creation/resourceCreation.d.ts +0 -21
  73. package/dist/utils/creation/resourceCreation.d.ts.map +0 -1
  74. package/dist/utils/creation/resourceCreation.js +0 -66
  75. package/dist/utils/creation/resourceCreation.js.map +0 -1
  76. package/dist/utils/creation/stepCreation.d.ts +0 -51
  77. package/dist/utils/creation/stepCreation.d.ts.map +0 -1
  78. package/dist/utils/creation/stepCreation.js +0 -90
  79. package/dist/utils/creation/stepCreation.js.map +0 -1
  80. package/dist/utils/creation/threadedStrategyCreation.d.ts +0 -19
  81. package/dist/utils/creation/threadedStrategyCreation.d.ts.map +0 -1
  82. package/dist/utils/creation/threadedStrategyCreation.js +0 -17
  83. package/dist/utils/creation/threadedStrategyCreation.js.map +0 -1
  84. package/dist/utils/extractData.d.ts +0 -13
  85. package/dist/utils/extractData.d.ts.map +0 -1
  86. package/dist/utils/extractData.js +0 -74
  87. package/dist/utils/extractData.js.map +0 -1
  88. package/dist/utils/parallelizeSteps.d.ts +0 -4
  89. package/dist/utils/parallelizeSteps.d.ts.map +0 -1
  90. package/dist/utils/parallelizeSteps.js.map +0 -1
  91. package/dist/utils/resolveResourceChain.d.ts +0 -19
  92. package/dist/utils/resolveResourceChain.d.ts.map +0 -1
  93. package/dist/utils/resolveResourceChain.js +0 -31
  94. package/dist/utils/resolveResourceChain.js.map +0 -1
  95. package/dist/utils/roleSpec.d.ts +0 -17
  96. package/dist/utils/roleSpec.d.ts.map +0 -1
  97. package/dist/utils/roleSpec.js +0 -58
  98. package/dist/utils/roleSpec.js.map +0 -1
  99. package/dist/utils/strategyState.d.ts +0 -8
  100. package/dist/utils/strategyState.d.ts.map +0 -1
  101. package/dist/utils/strategyState.js +0 -29
  102. package/dist/utils/strategyState.js.map +0 -1
  103. package/src/artifacts/artifacts.ts +0 -49
  104. package/src/integrations/firebase/createStep.ts +0 -71
  105. package/src/integrations/firebase/createThreadedStrategy.ts +0 -19
  106. package/src/utils/bindInputRoleToResource.ts +0 -54
  107. package/src/utils/creation/resourceCreation.ts +0 -121
  108. package/src/utils/creation/stepCreation.ts +0 -165
  109. package/src/utils/creation/threadedStrategyCreation.ts +0 -42
  110. package/src/utils/extractData.ts +0 -129
  111. package/src/utils/parallelizeSteps.ts +0 -187
  112. package/src/utils/resolveResourceChain.ts +0 -52
  113. package/src/utils/roleSpec.ts +0 -84
  114. package/src/utils/strategyState.ts +0 -57
@@ -1,52 +0,0 @@
1
- import type {
2
- CreationContext,
3
- ExternalInput,
4
- ReferenceInput,
5
- StrategyStateInputEntry,
6
- ValueInput,
7
- } from '@toolproof-core/schema';
8
- import { getStrategyStateEntry, type StrategyState } from './strategyState.js';
9
-
10
- export type ResolveResult =
11
- | { status: 'valueInput'; entry: ValueInput; path: CreationContext[] }
12
- | { status: 'externalInput'; entry: ExternalInput; path: CreationContext[] }
13
- | { status: 'unresolved'; reason: 'not-found' | 'cycle' | 'depth-exceeded'; path: CreationContext[] };
14
-
15
- export function resolveResourceChain(
16
- strategyState: StrategyState,
17
- start: CreationContext,
18
- opts?: { maxDepth?: number }
19
- ): ResolveResult {
20
- const maxDepth = opts?.maxDepth ?? 50;
21
- const visited = new Set<string>();
22
- const path: CreationContext[] = [];
23
- let current: CreationContext = start;
24
-
25
- for (let depth = 0; depth <= maxDepth; depth++) {
26
- path.push(current);
27
- const visitKey = `${current.toolStepPath}::${current.roleName}`;
28
- if (visited.has(visitKey)) {
29
- return { status: 'unresolved', reason: 'cycle', path };
30
- }
31
- visited.add(visitKey);
32
-
33
- const entry = getStrategyStateEntry(strategyState, current) as StrategyStateInputEntry | undefined;
34
- if (!entry) return { status: 'unresolved', reason: 'not-found', path };
35
-
36
- if (entry.strategyStateInputKind === 'valueInput') {
37
- return { status: 'valueInput', entry: entry, path };
38
- }
39
- if (entry.strategyStateInputKind === 'externalInput') {
40
- return { status: 'externalInput', entry: entry, path };
41
- }
42
-
43
- current = {
44
- toolStepPath: (entry as ReferenceInput).toolStepPath,
45
- roleName: (entry as ReferenceInput).roleName,
46
- };
47
- continue;
48
-
49
- }
50
-
51
- return { status: 'unresolved', reason: 'depth-exceeded', path };
52
- }
@@ -1,84 +0,0 @@
1
- import type {
2
- RoleName,
3
- RoleValue,
4
- Step,
5
- StepArrayArray,
6
- Tool,
7
- ToolStep,
8
- } from '@toolproof-core/schema';
9
-
10
- export type StrategyStepGraph =
11
- | { steps: Step[] }
12
- | { stepsByThreadIndex: StepArrayArray };
13
-
14
- export interface ToolRoleDescriptor extends RoleValue {
15
- id: RoleName;
16
- name: string;
17
- }
18
-
19
- export function getInputRoleEntries(tool: Tool): Array<[RoleName, RoleValue]> {
20
- return Object.entries(tool.roleSpec.inputRoleValueByName) as Array<[RoleName, RoleValue]>;
21
- }
22
-
23
- export function getOutputRoleEntries(tool: Tool): Array<[RoleName, RoleValue]> {
24
- return Object.entries(tool.roleSpec.outputRoleValueByName) as Array<[RoleName, RoleValue]>;
25
- }
26
-
27
- export function getInputRoleNames(tool: Tool): RoleName[] {
28
- return getInputRoleEntries(tool).map(([roleName]) => roleName);
29
- }
30
-
31
- export function getOutputRoleNames(tool: Tool): RoleName[] {
32
- return getOutputRoleEntries(tool).map(([roleName]) => roleName);
33
- }
34
-
35
- export function toToolRoleDescriptor([roleName, roleValue]: [RoleName, RoleValue]): ToolRoleDescriptor {
36
- return {
37
- id: roleName,
38
- name: roleName,
39
- ...roleValue,
40
- };
41
- }
42
-
43
- export function extractToolStepsFromStrategy(strategy: StrategyStepGraph): ToolStep[] {
44
- const toolSteps: ToolStep[] = [];
45
-
46
- const visitStep = (step: Step) => {
47
- switch (step.stepKind) {
48
- case 'tool': {
49
- toolSteps.push(step);
50
- return;
51
- }
52
- case 'branch': {
53
- for (const conditional of step.cases) {
54
- toolSteps.push(conditional.when, conditional.what);
55
- }
56
- return;
57
- }
58
- case 'while':
59
- case 'for': {
60
- toolSteps.push(step.case.when, step.case.what);
61
- return;
62
- }
63
- default: {
64
- const _exhaustive: never = step;
65
- return _exhaustive;
66
- }
67
- }
68
- };
69
-
70
- if ('steps' in strategy) {
71
- for (const step of strategy.steps) {
72
- visitStep(step);
73
- }
74
- return toolSteps;
75
- }
76
-
77
- for (const threadSteps of strategy.stepsByThreadIndex) {
78
- for (const step of threadSteps) {
79
- visitStep(step);
80
- }
81
- }
82
-
83
- return toolSteps;
84
- }
@@ -1,57 +0,0 @@
1
- import type {
2
- CreationContext,
3
- Strategy,
4
- StrategyStateInputEntry,
5
- StrategyStateInputEntryByRoleName,
6
- } from '@toolproof-core/schema';
7
-
8
- export type StrategyState = Strategy['strategyState'];
9
- export type StrategyStateLike = Record<string, Record<string, unknown>>;
10
-
11
- export function getStrategyStateBucket(
12
- strategyState: StrategyStateLike,
13
- toolStepPath: CreationContext['toolStepPath'],
14
- ): StrategyStateInputEntryByRoleName | undefined {
15
- return strategyState[toolStepPath] as StrategyStateInputEntryByRoleName | undefined;
16
- }
17
-
18
- export function getStrategyStateEntry(
19
- strategyState: StrategyStateLike,
20
- context: CreationContext,
21
- ): StrategyStateInputEntry | undefined {
22
- return getStrategyStateBucket(strategyState, context.toolStepPath)?.[context.roleName];
23
- }
24
-
25
- export function setStrategyStateEntry<TStrategyState extends StrategyStateLike>(
26
- strategyState: TStrategyState,
27
- context: CreationContext,
28
- entry: StrategyStateInputEntry,
29
- ): TStrategyState {
30
- const bucket = getStrategyStateBucket(strategyState, context.toolStepPath) ?? {};
31
-
32
- return {
33
- ...strategyState,
34
- [context.toolStepPath]: {
35
- ...bucket,
36
- [context.roleName]: entry,
37
- },
38
- } as TStrategyState;
39
- }
40
-
41
- export function clearStrategyStateEntry<TStrategyState extends StrategyStateLike>(
42
- strategyState: TStrategyState,
43
- context: CreationContext,
44
- ): TStrategyState {
45
- const bucket = getStrategyStateBucket(strategyState, context.toolStepPath);
46
- if (!bucket || !(context.roleName in bucket)) {
47
- return strategyState;
48
- }
49
-
50
- const nextBucket = { ...bucket };
51
- delete nextBucket[context.roleName];
52
-
53
- return {
54
- ...strategyState,
55
- [context.toolStepPath]: nextBucket,
56
- } as TStrategyState;
57
- }