@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,10 +1,3 @@
1
- import type { ResourceTypeId, StepKind } from '@toolproof-core/schema';
2
- import type { IdName, IdStringByIdName, ResourcesByType } from '../../types/types.js';
3
- type StepIdStringByStepKind<K extends StepKind> = string & {
4
- readonly __stepKind?: K;
5
- };
6
- export declare function getNewId<K extends IdName>(idName: K): IdStringByIdName<K>;
7
- export declare function getNewStepId<K extends StepKind>(stepKind: K): StepIdStringByStepKind<K>;
8
- export declare function listResources(resourceTypeIds: ResourceTypeId[]): Promise<ResourcesByType>;
9
- export {};
10
- //# sourceMappingURL=firebaseAdminHelpers.d.ts.map
1
+ import type { ResourceTypeHandle } from '@toolproof-core/genesis';
2
+ import type { ResourcesByType } from '../../types/types.js';
3
+ export declare function listResources(resourceTypeHandles: ResourceTypeHandle[]): Promise<ResourcesByType>;
@@ -1,157 +1,52 @@
1
- import { CONSTANTS, MAPPINGS } from '../../artifacts/artifacts.js';
1
+ import { CONSTANTS } from '../../lookups/lookups.js';
2
2
  import { dbAdmin, storageAdmin } from './firebaseAdminInit.js';
3
- function capitalizeFirst(value) {
4
- if (!value) {
5
- return value;
6
- }
7
- return value.charAt(0).toUpperCase() + value.slice(1);
8
- }
9
- export function getNewId(idName) {
10
- const prefix = MAPPINGS.IdNameToIdPrefix[idName];
11
- const docRef = dbAdmin
12
- .collection(CONSTANTS.Persistence.Collections.resources)
13
- .doc(idName)
14
- .collection(CONSTANTS.Persistence.Collections.members)
15
- .doc();
16
- return (prefix + docRef.id);
17
- }
18
- export function getNewStepId(stepKind) {
19
- const idName = `${capitalizeFirst(stepKind)}StepId`;
20
- if (!(idName in MAPPINGS.IdNameToIdPrefix)) {
21
- throw new Error(`No IdNameToIdPrefix entry for derived step id name: ${idName}`);
22
- }
23
- return getNewId(idName);
24
- }
25
- export async function listResources(resourceTypeIds) {
26
- const bucketResources = storageAdmin.bucket(CONSTANTS.Persistence.Buckets.tp_resources);
27
- const bucketStrategies = storageAdmin.bucket(CONSTANTS.Persistence.Buckets.tp_strategies);
28
- async function fetchFilesUnder(resourceTypeId) {
29
- const bucket = resourceTypeId === CONSTANTS.Cosmos.TYPE_ThreadedStrategy
30
- ? bucketStrategies
31
- : bucketResources;
32
- const prefix = `${resourceTypeId}/`;
33
- const [found] = await bucket.getFiles({ prefix });
34
- const files = found.filter((file) => {
35
- const name = file.name || '';
36
- return !!name && !name.endsWith('/');
3
+ export async function listResources(resourceTypeHandles) {
4
+ const resourcesBucket = storageAdmin.bucket(CONSTANTS.Persistence.Buckets.tp_resources);
5
+ const strategiesBucket = storageAdmin.bucket(CONSTANTS.Persistence.Buckets.tp_strategies);
6
+ async function fetchTimestampedMetadataUnder(resourceTypeHandle) {
7
+ const snapshot = await dbAdmin
8
+ .collection(CONSTANTS.Persistence.Collections.resources)
9
+ .doc(resourceTypeHandle)
10
+ .collection(CONSTANTS.Persistence.Collections.members)
11
+ .get();
12
+ return snapshot.docs.map((doc) => {
13
+ const data = doc.data();
14
+ if (typeof data.id !== 'string' ||
15
+ typeof data.resourceTypeHandle !== 'string' ||
16
+ !data.provenance ||
17
+ typeof data.provenance !== 'object' ||
18
+ typeof data.provenance.provenanceKind !== 'string') {
19
+ throw new Error(`Invalid TimestampedResource document for ${resourceTypeHandle}/${doc.id}`);
20
+ }
21
+ return {
22
+ id: data.id,
23
+ resourceTypeHandle: data.resourceTypeHandle,
24
+ provenance: data.provenance,
25
+ };
37
26
  });
38
- if (!files.length) {
39
- return [];
27
+ }
28
+ async function fetchProjection(resourceTypeHandle, resourceId) {
29
+ const bucket = resourceTypeHandle === CONSTANTS.Handles.ResourceTypes.TYPE_Strategy
30
+ ? strategiesBucket
31
+ : resourcesBucket;
32
+ const file = bucket.file(`${resourceTypeHandle}/${resourceId}`);
33
+ const [exists] = await file.exists();
34
+ if (!exists) {
35
+ throw new Error(`Missing projection blob for ${resourceTypeHandle}/${resourceId}`);
40
36
  }
41
- const items = await Promise.all(files.map(async (file) => {
42
- try {
43
- const [buf] = await file.download();
44
- const meta = file.metadata || (await file.getMetadata())[0];
45
- const data = JSON.parse(buf.toString('utf8'));
46
- return { data, meta, name: file.name };
47
- }
48
- catch {
49
- return null;
50
- }
51
- }));
52
- return items.filter(Boolean);
37
+ const [buf] = await file.download();
38
+ return JSON.parse(buf.toString('utf8'));
53
39
  }
54
- const entries = await Promise.all(resourceTypeIds.map(async (resourceTypeId) => {
55
- const rows = await fetchFilesUnder(resourceTypeId);
56
- const items = rows.map(({ data, meta, name }) => {
57
- const flat = meta?.metadata ?? {};
58
- const root = {};
59
- for (const [key, valueRaw] of Object.entries(flat)) {
60
- if (typeof valueRaw !== 'string') {
61
- continue;
62
- }
63
- const valueString = valueRaw.trim();
64
- let value = valueString;
65
- if ((valueString.startsWith('{') && valueString.endsWith('}')) || (valueString.startsWith('[') && valueString.endsWith(']'))) {
66
- try {
67
- value = JSON.parse(valueString);
68
- }
69
- catch {
70
- value = valueString;
71
- }
72
- }
73
- const segments = key.split('.');
74
- let cursor = root;
75
- for (const [index, segment] of segments.entries()) {
76
- const arrIdxMatch = segment.match(/^(.*)\[(\d+)\]$/);
77
- if (arrIdxMatch) {
78
- const base = arrIdxMatch[1];
79
- const idxStr = arrIdxMatch[2];
80
- if (base === undefined || idxStr === undefined) {
81
- continue;
82
- }
83
- const idx = parseInt(idxStr, 10);
84
- if (!cursor[base] || !Array.isArray(cursor[base])) {
85
- cursor[base] = [];
86
- }
87
- while (cursor[base].length <= idx) {
88
- cursor[base].push(undefined);
89
- }
90
- if (index === segments.length - 1) {
91
- cursor[base][idx] = value;
92
- }
93
- else {
94
- if (!cursor[base][idx]) {
95
- cursor[base][idx] = {};
96
- }
97
- cursor = cursor[base][idx];
98
- }
99
- }
100
- else {
101
- if (index === segments.length - 1) {
102
- cursor[segment] = value;
103
- }
104
- else {
105
- if (!cursor[segment] || typeof cursor[segment] !== 'object') {
106
- cursor[segment] = {};
107
- }
108
- cursor = cursor[segment];
109
- }
110
- }
111
- }
112
- }
113
- const id = root.id;
114
- const provenance = root.provenance;
115
- const versionRaw = root.version;
116
- const version = typeof versionRaw === 'number'
117
- ? versionRaw
118
- : parseInt(String(versionRaw ?? ''), 10);
119
- const resourcePath = root.path;
120
- const timestamp = root.timestamp;
121
- const missing = [
122
- ['id', id],
123
- ['version', Number.isFinite(version) ? String(version) : ''],
124
- ['timestamp', timestamp],
125
- ['path', resourcePath],
126
- ].filter(([_, value]) => typeof value !== 'string' || value.length === 0);
127
- if (missing.length) {
128
- const keys = missing.map(([key]) => key).join(', ');
129
- throw new Error(`Missing required metadata keys [${keys}] for resource file: ${name}`);
130
- }
131
- if (!provenance || typeof provenance !== 'object' || typeof provenance.resourceProvenanceKind !== 'string') {
132
- throw new Error(`Missing required metadata key [provenance] for resource file: ${name}`);
133
- }
134
- if (provenance.resourceProvenanceKind === 'strategy') {
135
- const creationContext = provenance.creationContext;
136
- if (!creationContext ||
137
- typeof creationContext !== 'object' ||
138
- typeof creationContext.roleName !== 'string' ||
139
- typeof creationContext.toolStepPath !== 'string') {
140
- throw new Error(`Missing required strategy provenance creationContext for resource file: ${name}`);
141
- }
142
- }
40
+ const entries = await Promise.all(resourceTypeHandles.map(async (resourceTypeHandle) => {
41
+ const pointers = await fetchTimestampedMetadataUnder(resourceTypeHandle);
42
+ const items = await Promise.all(pointers.map(async (resourcePointer) => {
43
+ const projection = await fetchProjection(resourceTypeHandle, resourcePointer.id);
143
44
  return {
144
- id,
145
- resourceTypeId,
146
- provenance,
147
- version,
148
- timestamp: timestamp,
149
- path: resourcePath,
150
- nucleus: data,
45
+ ...resourcePointer,
46
+ projection,
151
47
  };
152
- });
153
- return [resourceTypeId, items];
48
+ }));
49
+ return [resourceTypeHandle, items];
154
50
  }));
155
51
  return Object.fromEntries(entries);
156
52
  }
157
- //# sourceMappingURL=firebaseAdminHelpers.js.map
@@ -1,4 +1,3 @@
1
1
  declare const dbAdmin: FirebaseFirestore.Firestore;
2
2
  declare const storageAdmin: import("firebase-admin/storage").Storage;
3
3
  export { dbAdmin, storageAdmin };
4
- //# sourceMappingURL=firebaseAdminInit.d.ts.map
@@ -30,4 +30,3 @@ const app = getApps().length ? getApp() : initializeApp({
30
30
  const dbAdmin = getFirestore(app);
31
31
  const storageAdmin = getStorage(app);
32
32
  export { dbAdmin, storageAdmin };
33
- //# sourceMappingURL=firebaseAdminInit.js.map
@@ -0,0 +1,214 @@
1
+ export declare const CONSTANTS: {
2
+ readonly Persistence: {
3
+ readonly Buckets: {
4
+ readonly tp_resources: "tp-resources";
5
+ readonly tp_strategies: "tp-strategies";
6
+ };
7
+ readonly Collections: {
8
+ readonly resources: "resources";
9
+ readonly members: "members";
10
+ };
11
+ };
12
+ readonly Engine: {
13
+ readonly Graphs: {
14
+ readonly GraphRunStrategy: "GraphRunStrategy";
15
+ readonly GraphBuildStrategy: "GraphBuildStrategy";
16
+ };
17
+ };
18
+ readonly Cosmos: {
19
+ readonly ErrorOutputRoleName: "ErrorOutput";
20
+ };
21
+ readonly Names: {
22
+ readonly AtomicTypeRef: "AtomicTypeRef";
23
+ readonly BaseResource: "BaseResource";
24
+ readonly BaseTracePoint: "BaseTracePoint";
25
+ readonly Boolean: "Boolean";
26
+ readonly BranchStep: "BranchStep";
27
+ readonly Case: "Case";
28
+ readonly ContainerKind: "ContainerKind";
29
+ readonly Description: "Description";
30
+ readonly DescriptionFacet: "DescriptionFacet";
31
+ readonly DocumentationSpec: "DocumentationSpec";
32
+ readonly Embedding: "Embedding";
33
+ readonly Error: "Error";
34
+ readonly ExternalInputPotential: "ExternalInputPotential";
35
+ readonly ForStep: "ForStep";
36
+ readonly GenesisProvenance: "GenesisProvenance";
37
+ readonly Goal: "Goal";
38
+ readonly GoalHandle: "GoalHandle";
39
+ readonly InputPotential: "InputPotential";
40
+ readonly InputResource: "InputResource";
41
+ readonly InternalInputPotential: "InternalInputPotential";
42
+ readonly JsonScalarLink: "JsonScalarLink";
43
+ readonly JsonSchemaObject: "JsonSchemaObject";
44
+ readonly Name: "Name";
45
+ readonly NameFacet: "NameFacet";
46
+ readonly Natural: "Natural";
47
+ readonly Provenance: "Provenance";
48
+ readonly ProvenanceFacet: "ProvenanceFacet";
49
+ readonly ProvenanceKind: "ProvenanceKind";
50
+ readonly Resource: "Resource";
51
+ readonly ResourceId: "ResourceId";
52
+ readonly ResourcePointer: "ResourcePointer";
53
+ readonly ResourceType: "ResourceType";
54
+ readonly ResourceTypeHandle: "ResourceTypeHandle";
55
+ readonly RoleBindingSpec: "RoleBindingSpec";
56
+ readonly RoleBindingSpecFacet: "RoleBindingSpecFacet";
57
+ readonly RoleName: "RoleName";
58
+ readonly RoleNameArray: "RoleNameArray";
59
+ readonly RoleSpec: "RoleSpec";
60
+ readonly RoleSpecFacet: "RoleSpecFacet";
61
+ readonly RoleValue: "RoleValue";
62
+ readonly RoleValueByName: "RoleValueByName";
63
+ readonly RuntimeProvenance: "RuntimeProvenance";
64
+ readonly Step: "Step";
65
+ readonly StepArray: "StepArray";
66
+ readonly StepArrayArray: "StepArrayArray";
67
+ readonly StepKind: "StepKind";
68
+ readonly StepKindFacet: "StepKindFacet";
69
+ readonly StepsByThreadIndexFacet: "StepsByThreadIndexFacet";
70
+ readonly StepsFacet: "StepsFacet";
71
+ readonly Strategy: "Strategy";
72
+ readonly StrategyEndTracePoint: "StrategyEndTracePoint";
73
+ readonly StrategyFacet: "StrategyFacet";
74
+ readonly StrategyHandle: "StrategyHandle";
75
+ readonly StrategyProvenance: "StrategyProvenance";
76
+ readonly StrategyStartTracePoint: "StrategyStartTracePoint";
77
+ readonly StrategyState: "StrategyState";
78
+ readonly StrategyStateFacet: "StrategyStateFacet";
79
+ readonly StrategyStateInputEntry: "StrategyStateInputEntry";
80
+ readonly StrategyStateInputEntryByRoleName: "StrategyStateInputEntryByRoleName";
81
+ readonly StrategyStateInputKind: "StrategyStateInputKind";
82
+ readonly StrategyTrace: "StrategyTrace";
83
+ readonly StrategyTraceHandle: "StrategyTraceHandle";
84
+ readonly Suite: "Suite";
85
+ readonly SuiteIngestorInputSchema: "SuiteIngestorInputSchema";
86
+ readonly SuspendedTracePoint: "SuspendedTracePoint";
87
+ readonly TickTracePoint: "TickTracePoint";
88
+ readonly TimestampedResource: "TimestampedResource";
89
+ readonly Tool: "Tool";
90
+ readonly ToolHandle: "ToolHandle";
91
+ readonly ToolStep: "ToolStep";
92
+ readonly ToolStepPath: "ToolStepPath";
93
+ readonly ToolStepPathSlot: "ToolStepPathSlot";
94
+ readonly ToolStepPathSlotFacet: "ToolStepPathSlotFacet";
95
+ readonly ToolStepPathSpec: "ToolStepPathSpec";
96
+ readonly ToolStepRoleAddress: "ToolStepRoleAddress";
97
+ readonly TracePoint: "TracePoint";
98
+ readonly TracePointCounterSnapshot: "TracePointCounterSnapshot";
99
+ readonly TracePointDelta: "TracePointDelta";
100
+ readonly TracePointKind: "TracePointKind";
101
+ readonly TypeRef: "TypeRef";
102
+ readonly WhileStep: "WhileStep";
103
+ };
104
+ readonly Handles: {
105
+ readonly ResourceTypes: {
106
+ readonly TYPE_Boolean: "TYPE-Boolean";
107
+ readonly TYPE_Error: "TYPE-Error";
108
+ readonly TYPE_Goal: "TYPE-Goal";
109
+ readonly TYPE_Natural: "TYPE-Natural";
110
+ readonly TYPE_Resource: "TYPE-Resource";
111
+ readonly TYPE_ResourceType: "TYPE-ResourceType";
112
+ readonly TYPE_Strategy: "TYPE-Strategy";
113
+ readonly TYPE_StrategyTrace: "TYPE-StrategyTrace";
114
+ readonly TYPE_Suite: "TYPE-Suite";
115
+ readonly TYPE_Tool: "TYPE-Tool";
116
+ };
117
+ readonly Tools: {
118
+ readonly TOOL_Add: "TOOL-Add";
119
+ readonly TOOL_BooleanIdentity: "TOOL-BooleanIdentity";
120
+ readonly TOOL_Divide: "TOOL-Divide";
121
+ readonly TOOL_Double: "TOOL-Double";
122
+ readonly TOOL_Identity: "TOOL-Identity";
123
+ readonly TOOL_LessThan: "TOOL-LessThan";
124
+ readonly TOOL_Multiply: "TOOL-Multiply";
125
+ readonly TOOL_NaturalAdd: "TOOL-NaturalAdd";
126
+ readonly TOOL_NaturalDivide: "TOOL-NaturalDivide";
127
+ readonly TOOL_NaturalDouble: "TOOL-NaturalDouble";
128
+ readonly TOOL_NaturalIdentity: "TOOL-NaturalIdentity";
129
+ readonly TOOL_NaturalLessThan: "TOOL-NaturalLessThan";
130
+ readonly TOOL_NaturalMultiply: "TOOL-NaturalMultiply";
131
+ readonly TOOL_NaturalSubtract: "TOOL-NaturalSubtract";
132
+ readonly TOOL_Subtract: "TOOL-Subtract";
133
+ };
134
+ };
135
+ readonly ToolRoleNames: {
136
+ readonly TOOL_Add: {
137
+ readonly AddendOne: "AddendOne";
138
+ readonly AddendTwo: "AddendTwo";
139
+ readonly Sum: "Sum";
140
+ };
141
+ readonly TOOL_Divide: {
142
+ readonly Dividend: "Dividend";
143
+ readonly Divisor: "Divisor";
144
+ readonly Quotient: "Quotient";
145
+ readonly Remainder: "Remainder";
146
+ };
147
+ readonly TOOL_Double: {
148
+ readonly Doubled: "Doubled";
149
+ readonly N: "N";
150
+ };
151
+ readonly TOOL_Identity: {
152
+ readonly In: "In";
153
+ readonly Out: "Out";
154
+ };
155
+ readonly TOOL_LessThan: {
156
+ readonly LessThanDecision: "LessThanDecision";
157
+ readonly LessThanSource: "LessThanSource";
158
+ readonly LessThanTarget: "LessThanTarget";
159
+ };
160
+ readonly TOOL_Multiply: {
161
+ readonly Multiplicand: "Multiplicand";
162
+ readonly Multiplier: "Multiplier";
163
+ readonly Product: "Product";
164
+ };
165
+ readonly TOOL_Subtract: {
166
+ readonly Difference: "Difference";
167
+ readonly Minuend: "Minuend";
168
+ readonly Subtrahend: "Subtrahend";
169
+ };
170
+ };
171
+ readonly Enums: {
172
+ readonly ContainerKind: {
173
+ readonly scalar: "scalar";
174
+ readonly array: "array";
175
+ readonly map: "map";
176
+ };
177
+ readonly ProvenanceKind: {
178
+ readonly genesis: "genesis";
179
+ readonly runtime: "runtime";
180
+ readonly strategy: "strategy";
181
+ };
182
+ readonly StepKind: {
183
+ readonly tool: "tool";
184
+ readonly branch: "branch";
185
+ readonly while: "while";
186
+ readonly for: "for";
187
+ };
188
+ readonly StrategyStateInputKind: {
189
+ readonly inputResource: "inputResource";
190
+ readonly externalInputPotential: "externalInputPotential";
191
+ readonly internalInputPotential: "internalInputPotential";
192
+ };
193
+ readonly TracePointKind: {
194
+ readonly strategy_start: "strategy_start";
195
+ readonly tick: "tick";
196
+ readonly suspended: "suspended";
197
+ readonly strategy_end: "strategy_end";
198
+ };
199
+ };
200
+ };
201
+ export declare const MAPPINGS: {
202
+ readonly IdentifierNameToPrefix: {
203
+ readonly ToolStepKey: "TOOL_STEP-";
204
+ readonly BranchStepKey: "BRANCH_STEP-";
205
+ readonly WhileStepKey: "WHILE_STEP-";
206
+ readonly ForStepKey: "FOR_STEP-";
207
+ readonly GoalHandle: "GOAL-";
208
+ readonly ResourceId: "RESOURCE-";
209
+ readonly ResourceTypeHandle: "TYPE-";
210
+ readonly StrategyHandle: "STRATEGY-";
211
+ readonly StrategyTraceHandle: "STRATEGY_TRACE-";
212
+ readonly ToolHandle: "TOOL-";
213
+ };
214
+ };
@@ -0,0 +1,33 @@
1
+ import { CONSTANTS as _CONSTANTS, MAPPINGS as _MAPPINGS } from '@toolproof-core/genesis';
2
+ export const CONSTANTS = {
3
+ ..._CONSTANTS,
4
+ Persistence: {
5
+ Buckets: {
6
+ tp_resources: 'tp-resources',
7
+ tp_strategies: 'tp-strategies',
8
+ },
9
+ Collections: {
10
+ resources: 'resources',
11
+ members: 'members',
12
+ },
13
+ },
14
+ Engine: {
15
+ Graphs: {
16
+ GraphRunStrategy: 'GraphRunStrategy',
17
+ GraphBuildStrategy: 'GraphBuildStrategy',
18
+ },
19
+ },
20
+ Cosmos: {
21
+ ErrorOutputRoleName: 'ErrorOutput',
22
+ }
23
+ };
24
+ export const MAPPINGS = {
25
+ ..._MAPPINGS,
26
+ IdentifierNameToPrefix: {
27
+ ..._MAPPINGS.IdentifierNameToPrefix,
28
+ ToolStepKey: 'TOOL_STEP-',
29
+ BranchStepKey: 'BRANCH_STEP-',
30
+ WhileStepKey: 'WHILE_STEP-',
31
+ ForStepKey: 'FOR_STEP-',
32
+ },
33
+ };
@@ -1,20 +1,20 @@
1
- import type { StepKind, Resource, ResourceTypeId } from '@toolproof-core/schema';
2
- import { CONSTANTS } from '../artifacts/artifacts.js';
3
- import { MAPPINGS } from '../artifacts/artifacts.js';
4
- export type Bucket = typeof CONSTANTS.Persistence.Buckets.tp_resources;
1
+ import type { Resource, ResourceTypeHandle } from '@toolproof-core/genesis/types';
2
+ import { CONSTANTS } from '../lookups/lookups.js';
3
+ import { MAPPINGS } from '../lookups/lookups.js';
4
+ export type Bucket = keyof typeof CONSTANTS.Persistence.Buckets;
5
5
  export type Collection = keyof typeof CONSTANTS.Persistence.Collections;
6
6
  export type SchemaLike = Record<string, unknown>;
7
- export type ResourcesByType = Record<ResourceTypeId, Resource[]>;
8
- export type IdName = keyof typeof MAPPINGS.IdNameToIdPrefix;
9
- export type IdStringByIdName<K extends IdName> = `${(typeof MAPPINGS.IdNameToIdPrefix)[K]}${string}`;
10
- export type StepIdStringByStepKind<K extends StepKind> = string & {
11
- readonly __stepKind?: K;
7
+ export type ResourcesByType = Record<ResourceTypeHandle, Resource[]>;
8
+ export type IdentifierName = keyof typeof MAPPINGS.IdentifierNameToPrefix;
9
+ export type IdentifierStringByName<K extends IdentifierName> = `${(typeof MAPPINGS.IdentifierNameToPrefix)[K]}${string}`;
10
+ export type ItemKey = string;
11
+ export type BaseItem = {
12
+ itemKey: ItemKey;
12
13
  };
13
- export interface NucleusBaseSmall<T extends string = string> {
14
- id: T;
15
- }
16
- export interface NucleusBaseLarge<T extends string = string> extends NucleusBaseSmall<T> {
14
+ export type DocumentedBaseItem = BaseItem & {
17
15
  name: string;
18
16
  description: string;
19
- }
20
- //# sourceMappingURL=types.d.ts.map
17
+ };
18
+ export type Item = DocumentedBaseItem & {
19
+ label: string;
20
+ };
@@ -1,3 +1,2 @@
1
- import { CONSTANTS } from '../artifacts/artifacts.js';
2
- import { MAPPINGS } from '../artifacts/artifacts.js';
3
- //# sourceMappingURL=types.js.map
1
+ import { CONSTANTS } from '../lookups/lookups.js';
2
+ import { MAPPINGS } from '../lookups/lookups.js';
@@ -0,0 +1,5 @@
1
+ import type { Resource, TimestampedResource } from '@toolproof-core/genesis';
2
+ export declare function timestampedResourceToResource(timestampedResource: TimestampedResource): Resource;
3
+ export declare function extractProjectionMapByHandle<TKey extends string, TProjection extends {
4
+ handle: TKey;
5
+ }>(resources: Resource[] | undefined): Map<TKey, TProjection>;
@@ -0,0 +1,15 @@
1
+ export function timestampedResourceToResource(timestampedResource) {
2
+ const { timestamp: _timestamp, ...resource } = timestampedResource;
3
+ return resource;
4
+ }
5
+ export function extractProjectionMapByHandle(resources) {
6
+ const map = new Map();
7
+ for (const resource of resources ?? []) {
8
+ const projection = resource.projection;
9
+ if (!projection || typeof projection !== 'object' || !projection.handle) {
10
+ continue;
11
+ }
12
+ map.set(projection.handle, projection);
13
+ }
14
+ return map;
15
+ }
@@ -0,0 +1,2 @@
1
+ import type { IdentifierName, IdentifierStringByName } from '../types/types.js';
2
+ export declare function generateIdentifier<K extends IdentifierName>(identifierName: K): IdentifierStringByName<K>;
@@ -0,0 +1,5 @@
1
+ import { MAPPINGS } from '../lookups/lookups.js';
2
+ export function generateIdentifier(identifierName) {
3
+ const prefix = MAPPINGS.IdentifierNameToPrefix[identifierName];
4
+ return (prefix + crypto.randomUUID());
5
+ }
@@ -0,0 +1,55 @@
1
+ import type { BranchStep, Case, ExternalInputPotential, ForStep, InputResource, InternalInputPotential, Resource, RoleName, Strategy, Tool, ToolHandle, ToolStep, ToolStepRoleAddress, WhileStep } from '@toolproof-core/genesis';
2
+ export type MutableToolStepKey = string;
3
+ export type MutableBranchStepKey = string;
4
+ export type MutableWhileStepKey = string;
5
+ export type MutableForStepKey = string;
6
+ export type MutableLoopStepKey = MutableWhileStepKey | MutableForStepKey;
7
+ export type MutableMacroStepKey = MutableBranchStepKey | MutableLoopStepKey;
8
+ export type MutableInputResource = InputResource;
9
+ export type MutableToolStepRoleAddress<TKey extends string = MutableToolStepKey> = Omit<ToolStepRoleAddress, 'toolStepPath'> & {
10
+ toolStepKey: TKey;
11
+ };
12
+ export type MutableInternalInputPotential<TKey extends string = MutableToolStepKey> = Omit<InternalInputPotential, 'toolStepRoleAddress'> & {
13
+ toolStepRoleAddress: MutableToolStepRoleAddress<TKey>;
14
+ };
15
+ export type MutableExternalInputPotential = ExternalInputPotential;
16
+ export type MutableStrategyStateInputEntry<TKey extends string = MutableToolStepKey> = MutableInputResource | MutableInternalInputPotential<TKey> | MutableExternalInputPotential;
17
+ export type MutableStrategyStateInputEntryByRoleName<TKey extends string = MutableToolStepKey> = Partial<Record<RoleName, MutableStrategyStateInputEntry<TKey>>>;
18
+ export type MutableStrategyState<TKey extends string = MutableToolStepKey> = Partial<Record<TKey, MutableStrategyStateInputEntryByRoleName<TKey>>>;
19
+ export type MutableToolStep<TKey extends string = MutableToolStepKey> = ToolStep & {
20
+ toolStepKey: TKey;
21
+ };
22
+ export type MutableCase<TKey extends string = MutableToolStepKey> = Omit<Case, 'when' | 'what'> & {
23
+ when: MutableToolStep<TKey>;
24
+ what: MutableToolStep<TKey>;
25
+ };
26
+ export type MutableBranchStep<TKey extends string = MutableToolStepKey> = Omit<BranchStep, 'cases'> & {
27
+ macroStepKey: MutableBranchStepKey;
28
+ cases: [MutableCase<TKey>, ...MutableCase<TKey>[]];
29
+ };
30
+ export type MutableWhileStep<TKey extends string = MutableToolStepKey> = Omit<WhileStep, 'case'> & {
31
+ macroStepKey: MutableWhileStepKey;
32
+ case: MutableCase<TKey>;
33
+ };
34
+ export type MutableForStep<TKey extends string = MutableToolStepKey> = Omit<ForStep, 'case'> & {
35
+ macroStepKey: MutableForStepKey;
36
+ case: MutableCase<TKey>;
37
+ };
38
+ export type MutableStep<TKey extends string = MutableToolStepKey> = MutableToolStep<TKey> | MutableBranchStep<TKey> | MutableWhileStep<TKey> | MutableForStep<TKey>;
39
+ export type MutableStrategy<TKey extends string = MutableToolStepKey, TStep extends MutableStep<TKey> = MutableStep<TKey>, TState extends MutableStrategyState<TKey> = MutableStrategyState<TKey>> = Omit<Strategy, 'stepsByThreadIndex' | 'strategyState'> & {
40
+ stepsByThreadIndex: TStep[][];
41
+ strategyState: TState;
42
+ };
43
+ export declare function getAuthoringSteps<TKey extends string = MutableToolStepKey, TStep extends MutableStep<TKey> = MutableStep<TKey>, TState extends MutableStrategyState<TKey> = MutableStrategyState<TKey>>(strategy: MutableStrategy<TKey, TStep, TState>): TStep[];
44
+ export declare function setAuthoringSteps<// ATTENTION
45
+ TKey extends string = MutableToolStepKey, TStep extends MutableStep<TKey> = MutableStep<TKey>, TState extends MutableStrategyState<TKey> = MutableStrategyState<TKey>>(strategy: MutableStrategy<TKey, TStep, TState>, steps: TStep[]): MutableStrategy<TKey, TStep, TState>;
46
+ export declare function getStrategyStateInputEntryByRoleName<TKey extends string, TStrategyState extends MutableStrategyState<TKey>>(strategyState: TStrategyState, toolStepKey: TKey): MutableStrategyStateInputEntryByRoleName<TKey> | undefined;
47
+ export declare function getStrategyStateInputEntry<TKey extends string, TStrategyState extends MutableStrategyState<TKey>>(strategyState: TStrategyState, toolStepRoleAddress: MutableToolStepRoleAddress<TKey>): MutableStrategyStateInputEntry<TKey> | undefined;
48
+ export declare function setStrategyStateInputEntry<TKey extends string, TStrategyState extends MutableStrategyState<TKey>>(strategyState: TStrategyState, toolStepRoleAddress: MutableToolStepRoleAddress<TKey>, entry: MutableStrategyStateInputEntry<TKey>): TStrategyState;
49
+ export declare function clearInputBinding<TKey extends string, TStrategyState extends MutableStrategyState<TKey>>(strategyState: TStrategyState, toolStepRoleAddress: MutableToolStepRoleAddress<TKey>): TStrategyState;
50
+ export declare function bindInputResource<TKey extends string, TStrategyState extends MutableStrategyState<TKey>>(strategyState: TStrategyState, target: MutableToolStepRoleAddress<TKey>, resource: Resource): TStrategyState;
51
+ export declare function bindInternalInputPotential<TKey extends string, TStrategyState extends MutableStrategyState<TKey>>(strategyState: TStrategyState, targetAddress: MutableToolStepRoleAddress<TKey>, sourceAddress: MutableToolStepRoleAddress<TKey>, context: {
52
+ toolStepByKey: ReadonlyMap<TKey, MutableToolStep<TKey>>;
53
+ toolMap: ReadonlyMap<ToolHandle, Tool>;
54
+ }): TStrategyState;
55
+ export declare function bindExternalInputPotential<TKey extends string, TStrategyState extends MutableStrategyState<TKey>>(strategyState: TStrategyState, target: MutableToolStepRoleAddress<TKey>): TStrategyState;