@toolproof-core/genesis 1.0.49 → 1.0.51
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/src/implementations/tools.d.ts +100 -0
- package/dist/src/implementations/tools.js +135 -0
- package/dist/src/index.d.ts +5 -4
- package/dist/src/index.js +4 -3
- package/dist/src/utils/resourceTypes.d.ts +2 -1
- package/dist/src/utils/resourceTypes.js +22 -6
- package/dist/src/utils/schemaRefNormalization.js +3 -3
- package/dist/src/utils/standaloneTypes.js +2 -2
- package/dist/src/utils/timestampedResources.d.ts +16 -0
- package/dist/src/utils/timestampedResources.js +17 -0
- package/dist/src/utils/typeGenerationPostProcess.js +2 -2
- package/dist/src/utils/zodCodegen.js +3 -3
- package/generated-src/declarations/booleans.json +4 -0
- package/generated-src/declarations/booleans.ts +2 -0
- package/generated-src/declarations/naturals.json +13 -0
- package/generated-src/declarations/naturals.ts +2 -0
- package/generated-src/{resourceTypes → declarations}/resourceTypes.json +176 -39
- package/generated-src/declarations/resourceTypes.ts +2 -0
- package/generated-src/declarations/tools.json +705 -0
- package/generated-src/declarations/tools.ts +2 -0
- package/generated-src/implementations/tools.ts +214 -0
- package/generated-src/{derived → lookups}/constants.ts +4 -5
- package/generated-src/metadata/Core.json +51 -36
- package/generated-src/metadata/dependencyMap.json +16 -2
- package/generated-src/metadata/terminals.json +3 -4
- package/generated-src/schemas/schemas.json +198 -29
- package/generated-src/schemas/standalone/Resource.json +4 -8
- package/generated-src/schemas/standalone/ResourceType.json +21 -5
- package/generated-src/schemas/standalone/Strategy.json +4 -8
- package/generated-src/schemas/standalone/StrategyTrace.json +4 -8
- package/generated-src/schemas/standalone/Suite.json +646 -0
- package/generated-src/schemas/standalone/Suite.ts +2 -0
- package/generated-src/schemas/standalone/Tool.json +48 -23
- package/generated-src/schemas/zod/Resource.ts +2 -2
- package/generated-src/schemas/zod/ResourceType.ts +1 -1
- package/generated-src/schemas/zod/Strategy.ts +3 -3
- package/generated-src/schemas/zod/StrategyTrace.ts +3 -3
- package/generated-src/schemas/zod/Suite.ts +44 -0
- package/generated-src/schemas/zod/Tool.ts +7 -2
- package/generated-src/schemas/zod/index.ts +1 -0
- package/{src/genesis/resources → generated-src/timestampedResources}/booleans.json +19 -23
- package/generated-src/timestampedResources/booleans.ts +2 -0
- package/{src/genesis/resources → generated-src/timestampedResources}/naturals.json +100 -111
- package/generated-src/timestampedResources/naturals.ts +2 -0
- package/generated-src/{resources → timestampedResources}/resourceTypes.json +202 -66
- package/generated-src/timestampedResources/resourceTypes.ts +2 -0
- package/{src/genesis/resources → generated-src/timestampedResources}/tools.json +824 -839
- package/generated-src/timestampedResources/tools.ts +2 -0
- package/generated-src/types/standalone/BooleanResource.d.ts +2 -2
- package/generated-src/types/standalone/ErrorResource.d.ts +2 -2
- package/generated-src/types/standalone/GoalResource.d.ts +2 -2
- package/generated-src/types/standalone/NaturalResource.d.ts +2 -2
- package/generated-src/types/standalone/ResourceResource.d.ts +2 -2
- package/generated-src/types/standalone/ResourceTypeResource.d.ts +2 -2
- package/generated-src/types/standalone/StrategyResource.d.ts +2 -2
- package/generated-src/types/standalone/StrategyTraceResource.d.ts +2 -2
- package/generated-src/types/standalone/SuiteResource.d.ts +3 -0
- package/generated-src/types/standalone/SuiteResource.js +1 -0
- package/generated-src/types/standalone/ToolResource.d.ts +2 -2
- package/generated-src/types/types.d.ts +57 -14
- package/package.json +7 -4
- package/src/declarations/booleans.json +4 -0
- package/src/declarations/naturals.json +13 -0
- package/src/{genesis → declarations/resourceTypes}/resourceTypeShells.json +15 -9
- package/src/{genesis → declarations/resourceTypes}/schemas.json +198 -29
- package/src/declarations/tools.json +705 -0
- package/src/implementations/tools.ts +214 -0
- package/src/index.ts +25 -4
- package/src/utils/resourceTypes.ts +39 -7
- package/src/utils/schemaRefNormalization.ts +4 -4
- package/src/utils/standaloneTypes.ts +2 -2
- package/src/utils/timestampedResources.ts +42 -0
- package/src/utils/typeGenerationPostProcess.ts +2 -2
- package/src/utils/zodCodegen.ts +3 -3
- package/toolproof.json +19 -0
- package/dist/src/genesis/resources/implementations/foo.d.ts +0 -1
- package/dist/src/genesis/resources/implementations/foo.js +0 -184
- package/dist/src/utils/resources.d.ts +0 -5
- package/dist/src/utils/resources.js +0 -17
- package/generated-src/resourceTypes/resourceTypes.ts +0 -2
- package/generated-src/resources/resourceTypes.ts +0 -2
- package/src/genesis/resources/implementations/foo.ts +0 -183
- package/src/utils/resources.ts +0 -26
- /package/generated-src/{derived → lookups}/mappings.ts +0 -0
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Boolean,
|
|
3
|
+
Natural,
|
|
4
|
+
ResourceType,
|
|
5
|
+
Tool,
|
|
6
|
+
} from '../../generated-src/types/types.js';
|
|
7
|
+
|
|
8
|
+
type GenericAssignmentByRoleName<GenericRoleName extends string> = Record<GenericRoleName, ResourceType>;
|
|
9
|
+
|
|
10
|
+
type InstantiationToolHandleBySpecializationKey = Record<string, Tool>;
|
|
11
|
+
|
|
12
|
+
type TemplateInputs<GenericRoleName extends string> = {
|
|
13
|
+
GenericAssignmentByRoleName: GenericAssignmentByRoleName<GenericRoleName>;
|
|
14
|
+
InstantiationToolHandleBySpecializationKey: InstantiationToolHandleBySpecializationKey;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type TemplateOutputs = {
|
|
18
|
+
InstantiationTool: Tool;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
type OperandTemplateInputs = TemplateInputs<'OperandType'>;
|
|
22
|
+
|
|
23
|
+
const OPERAND_TYPE_ROLE_NAMES = ['OperandType'] as const;
|
|
24
|
+
|
|
25
|
+
function assertExactKeys(actualKeys: string[], expectedKeys: readonly string[], label: string): void {
|
|
26
|
+
const sortedActualKeys = [...actualKeys].sort();
|
|
27
|
+
const sortedExpectedKeys = [...expectedKeys].sort();
|
|
28
|
+
|
|
29
|
+
if (sortedActualKeys.length !== sortedExpectedKeys.length) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
`${label} must contain exactly [${sortedExpectedKeys.join(', ')}], got [${sortedActualKeys.join(', ')}]`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
for (let index = 0; index < sortedExpectedKeys.length; index += 1) {
|
|
36
|
+
if (sortedActualKeys[index] !== sortedExpectedKeys[index]) {
|
|
37
|
+
throw new Error(
|
|
38
|
+
`${label} must contain exactly [${sortedExpectedKeys.join(', ')}], got [${sortedActualKeys.join(', ')}]`
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function asNatural(value: number, label: string): Natural {
|
|
45
|
+
if (!Number.isInteger(value) || value < 0) {
|
|
46
|
+
throw new Error(`${label} must be a non-negative integer, got ${value}`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return value as Natural;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function createSpecializationKey(assignments: Record<string, ResourceType>): string {
|
|
53
|
+
return JSON.stringify(
|
|
54
|
+
Object.entries(assignments)
|
|
55
|
+
.sort(([leftRoleName], [rightRoleName]) => leftRoleName.localeCompare(rightRoleName))
|
|
56
|
+
.map(([roleName, resourceType]) => [roleName, resourceType.handle])
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function resolveTemplateInstantiation<GenericRoleName extends string>(
|
|
61
|
+
inputs: TemplateInputs<GenericRoleName>,
|
|
62
|
+
expectedGenericRoleNames: readonly GenericRoleName[]
|
|
63
|
+
): TemplateOutputs {
|
|
64
|
+
const { GenericAssignmentByRoleName, InstantiationToolHandleBySpecializationKey } = inputs;
|
|
65
|
+
|
|
66
|
+
assertExactKeys(
|
|
67
|
+
Object.keys(GenericAssignmentByRoleName),
|
|
68
|
+
expectedGenericRoleNames,
|
|
69
|
+
'GenericAssignmentByRoleName'
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const specializationKey = createSpecializationKey(GenericAssignmentByRoleName);
|
|
73
|
+
const instantiationTool = InstantiationToolHandleBySpecializationKey[specializationKey];
|
|
74
|
+
|
|
75
|
+
if (!instantiationTool) {
|
|
76
|
+
throw new Error(`No instantiation tool registered for specializationKey ${specializationKey}`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
InstantiationTool: instantiationTool,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function Identity(inputs: OperandTemplateInputs): TemplateOutputs {
|
|
85
|
+
return resolveTemplateInstantiation(inputs, OPERAND_TYPE_ROLE_NAMES);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function Add(inputs: OperandTemplateInputs): TemplateOutputs {
|
|
89
|
+
return resolveTemplateInstantiation(inputs, OPERAND_TYPE_ROLE_NAMES);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function Subtract(inputs: OperandTemplateInputs): TemplateOutputs {
|
|
93
|
+
return resolveTemplateInstantiation(inputs, OPERAND_TYPE_ROLE_NAMES);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function Multiply(inputs: OperandTemplateInputs): TemplateOutputs {
|
|
97
|
+
return resolveTemplateInstantiation(inputs, OPERAND_TYPE_ROLE_NAMES);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function Divide(inputs: OperandTemplateInputs): TemplateOutputs {
|
|
101
|
+
return resolveTemplateInstantiation(inputs, OPERAND_TYPE_ROLE_NAMES);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function Double(inputs: OperandTemplateInputs): TemplateOutputs {
|
|
105
|
+
return resolveTemplateInstantiation(inputs, OPERAND_TYPE_ROLE_NAMES);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function LessThan(inputs: OperandTemplateInputs): TemplateOutputs {
|
|
109
|
+
return resolveTemplateInstantiation(inputs, OPERAND_TYPE_ROLE_NAMES);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function BooleanIdentity(inputs: { In: Boolean }): { Out: Boolean } {
|
|
113
|
+
return {
|
|
114
|
+
Out: inputs.In,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function NaturalIdentity(inputs: { In: Natural }): { Out: Natural } {
|
|
119
|
+
return {
|
|
120
|
+
Out: inputs.In,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function NaturalLessThan(inputs: {
|
|
125
|
+
LessThanSource: Natural;
|
|
126
|
+
LessThanTarget: Natural;
|
|
127
|
+
}): { LessThanDecision: Boolean } {
|
|
128
|
+
return {
|
|
129
|
+
LessThanDecision: inputs.LessThanSource < inputs.LessThanTarget,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function NaturalAdd(inputs: {
|
|
134
|
+
AddendOne: Natural;
|
|
135
|
+
AddendTwo: Natural;
|
|
136
|
+
}): { Sum: Natural } {
|
|
137
|
+
return {
|
|
138
|
+
Sum: asNatural(inputs.AddendOne + inputs.AddendTwo, 'Sum'),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function NaturalSubtract(inputs: {
|
|
143
|
+
Minuend: Natural;
|
|
144
|
+
Subtrahend: Natural;
|
|
145
|
+
}): { Difference: Natural } {
|
|
146
|
+
return {
|
|
147
|
+
Difference: asNatural(inputs.Minuend - inputs.Subtrahend, 'Difference'),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export function NaturalMultiply(inputs: {
|
|
152
|
+
Multiplicand: Natural;
|
|
153
|
+
Multiplier: Natural;
|
|
154
|
+
}): { Product: Natural } {
|
|
155
|
+
return {
|
|
156
|
+
Product: asNatural(inputs.Multiplicand * inputs.Multiplier, 'Product'),
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function NaturalDivide(inputs: {
|
|
161
|
+
Dividend: Natural;
|
|
162
|
+
Divisor: Natural;
|
|
163
|
+
}): { Quotient: Natural; Remainder: Natural } {
|
|
164
|
+
if (inputs.Divisor === 0) {
|
|
165
|
+
throw new Error('Divisor must be non-zero');
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return {
|
|
169
|
+
Quotient: asNatural(Math.floor(inputs.Dividend / inputs.Divisor), 'Quotient'),
|
|
170
|
+
Remainder: asNatural(inputs.Dividend % inputs.Divisor, 'Remainder'),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function NaturalDouble(inputs: { N: Natural }): { Doubled: Natural } {
|
|
175
|
+
return {
|
|
176
|
+
Doubled: asNatural(inputs.N * 2, 'Doubled'),
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export const TOOL_IMPLEMENTATION_BY_NAME = {
|
|
181
|
+
Identity,
|
|
182
|
+
Add,
|
|
183
|
+
Subtract,
|
|
184
|
+
Multiply,
|
|
185
|
+
Divide,
|
|
186
|
+
Double,
|
|
187
|
+
LessThan,
|
|
188
|
+
BooleanIdentity,
|
|
189
|
+
NaturalIdentity,
|
|
190
|
+
NaturalLessThan,
|
|
191
|
+
NaturalAdd,
|
|
192
|
+
NaturalSubtract,
|
|
193
|
+
NaturalMultiply,
|
|
194
|
+
NaturalDivide,
|
|
195
|
+
NaturalDouble,
|
|
196
|
+
} as const;
|
|
197
|
+
|
|
198
|
+
export const TOOL_IMPLEMENTATION_BY_HANDLE = {
|
|
199
|
+
'TOOL-Identity': Identity,
|
|
200
|
+
'TOOL-Add': Add,
|
|
201
|
+
'TOOL-Subtract': Subtract,
|
|
202
|
+
'TOOL-Multiply': Multiply,
|
|
203
|
+
'TOOL-Divide': Divide,
|
|
204
|
+
'TOOL-Double': Double,
|
|
205
|
+
'TOOL-LessThan': LessThan,
|
|
206
|
+
'TOOL-BooleanIdentity': BooleanIdentity,
|
|
207
|
+
'TOOL-NaturalIdentity': NaturalIdentity,
|
|
208
|
+
'TOOL-NaturalLessThan': NaturalLessThan,
|
|
209
|
+
'TOOL-NaturalAdd': NaturalAdd,
|
|
210
|
+
'TOOL-NaturalSubtract': NaturalSubtract,
|
|
211
|
+
'TOOL-NaturalMultiply': NaturalMultiply,
|
|
212
|
+
'TOOL-NaturalDivide': NaturalDivide,
|
|
213
|
+
'TOOL-NaturalDouble': NaturalDouble,
|
|
214
|
+
} as const;
|
package/src/index.ts
CHANGED
|
@@ -14,10 +14,31 @@ export { StrategyTraceSchema as ZodStrategyTraceSchema } from '../generated-src/
|
|
|
14
14
|
export { GoalSchema as ZodGoalSchema } from '../generated-src/schemas/zod/Goal.js';
|
|
15
15
|
export * as ZodSchemas from '../generated-src/schemas/zod/index.js';
|
|
16
16
|
|
|
17
|
-
export { default as
|
|
17
|
+
export { default as ResourceTypeTimestampedResources } from '../generated-src/timestampedResources/resourceTypes.js';
|
|
18
18
|
|
|
19
|
-
export {
|
|
20
|
-
|
|
19
|
+
export {
|
|
20
|
+
Add,
|
|
21
|
+
BooleanIdentity,
|
|
22
|
+
createSpecializationKey,
|
|
23
|
+
Divide,
|
|
24
|
+
Double,
|
|
25
|
+
Identity,
|
|
26
|
+
LessThan,
|
|
27
|
+
Multiply,
|
|
28
|
+
NaturalAdd,
|
|
29
|
+
NaturalDivide,
|
|
30
|
+
NaturalDouble,
|
|
31
|
+
NaturalIdentity,
|
|
32
|
+
NaturalLessThan,
|
|
33
|
+
NaturalMultiply,
|
|
34
|
+
NaturalSubtract,
|
|
35
|
+
Subtract,
|
|
36
|
+
TOOL_IMPLEMENTATION_BY_HANDLE,
|
|
37
|
+
TOOL_IMPLEMENTATION_BY_NAME,
|
|
38
|
+
} from '../generated-src/implementations/tools.js';
|
|
39
|
+
|
|
40
|
+
export { default as CONSTANTS } from '../generated-src/lookups/constants.js';
|
|
41
|
+
export { default as MAPPINGS } from '../generated-src/lookups/mappings.js';
|
|
21
42
|
|
|
22
43
|
export type {
|
|
23
44
|
ResourceTypeResource,
|
|
@@ -36,6 +57,7 @@ export type {
|
|
|
36
57
|
BaseResource,
|
|
37
58
|
BaseStrategy,
|
|
38
59
|
BaseToolStepPathSpec,
|
|
60
|
+
Boolean,
|
|
39
61
|
BranchStep,
|
|
40
62
|
Case,
|
|
41
63
|
ContainerKind,
|
|
@@ -94,7 +116,6 @@ export type {
|
|
|
94
116
|
ThreadedToolStepPathSpec,
|
|
95
117
|
Tool,
|
|
96
118
|
ToolHandle,
|
|
97
|
-
ToolKind,
|
|
98
119
|
ToolStep,
|
|
99
120
|
ToolStepPath,
|
|
100
121
|
ToolStepPathSlot,
|
|
@@ -8,6 +8,7 @@ type ResourceTypeShell = JsonObject & {
|
|
|
8
8
|
handle?: unknown;
|
|
9
9
|
name?: unknown;
|
|
10
10
|
description?: unknown;
|
|
11
|
+
ingestorToolInputSchema?: unknown;
|
|
11
12
|
};
|
|
12
13
|
|
|
13
14
|
type ResourceTypeShellByName = Record<string, ResourceTypeShell>;
|
|
@@ -15,24 +16,55 @@ type ResourceTypeShellByName = Record<string, ResourceTypeShell>;
|
|
|
15
16
|
export function generateResourceTypes(
|
|
16
17
|
schemasDocument: SchemasDocument,
|
|
17
18
|
resourceTypeShells: ResourceTypeShellByName,
|
|
18
|
-
):
|
|
19
|
+
): ResourceTypeShell[] {
|
|
19
20
|
if (!schemasDocument.$defs || typeof schemasDocument.$defs !== 'object') {
|
|
20
21
|
throw new Error('Schema document must have root $defs');
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
const resourceTypes:
|
|
24
|
+
const resourceTypes: ResourceTypeShell[] = [];
|
|
24
25
|
|
|
25
26
|
for (const [resourceTypeName, resourceTypeShell] of Object.entries(resourceTypeShells)) {
|
|
26
|
-
const
|
|
27
|
+
const projectionSchema = schemasDocument.$defs[resourceTypeName];
|
|
28
|
+
const ingestorToolInputSchemaDefName = resourceTypeShell.ingestorToolInputSchema;
|
|
27
29
|
|
|
28
|
-
if (!
|
|
30
|
+
if (!projectionSchema || typeof projectionSchema !== 'object' || Array.isArray(projectionSchema)) {
|
|
29
31
|
throw new Error(`Missing matching schema for resource type record ${resourceTypeName}`);
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
if (
|
|
35
|
+
ingestorToolInputSchemaDefName !== undefined &&
|
|
36
|
+
typeof ingestorToolInputSchemaDefName !== 'string'
|
|
37
|
+
) {
|
|
38
|
+
throw new Error(
|
|
39
|
+
`ingestorToolInputSchema for resource type record ${resourceTypeName} must be a schema definition name when present`,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const ingestorToolInputSchema =
|
|
44
|
+
typeof ingestorToolInputSchemaDefName === 'string'
|
|
45
|
+
? schemasDocument.$defs[ingestorToolInputSchemaDefName]
|
|
46
|
+
: undefined;
|
|
47
|
+
|
|
48
|
+
if (typeof ingestorToolInputSchemaDefName === 'string' && !ingestorToolInputSchema) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
`Missing ingestor input schema ${ingestorToolInputSchemaDefName} for resource type record ${resourceTypeName}`,
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (
|
|
55
|
+
ingestorToolInputSchema !== undefined &&
|
|
56
|
+
(typeof ingestorToolInputSchema !== 'object' || Array.isArray(ingestorToolInputSchema))
|
|
57
|
+
) {
|
|
58
|
+
throw new Error(
|
|
59
|
+
`Ingestor input schema ${ingestorToolInputSchemaDefName} for resource type record ${resourceTypeName} must be an object`,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
resourceTypes.push({
|
|
33
64
|
...resourceTypeShell,
|
|
34
|
-
|
|
35
|
-
|
|
65
|
+
projectionSchema,
|
|
66
|
+
...(ingestorToolInputSchema ? { ingestorToolInputSchema } : {}),
|
|
67
|
+
});
|
|
36
68
|
}
|
|
37
69
|
|
|
38
70
|
return resourceTypes;
|
|
@@ -42,10 +42,10 @@ export function normalizeAnchorsToPointers<T>(input: T): T {
|
|
|
42
42
|
|
|
43
43
|
if (!defValue || typeof defValue !== 'object') continue;
|
|
44
44
|
|
|
45
|
-
const envelope = defValue as {
|
|
46
|
-
const
|
|
47
|
-
if (
|
|
48
|
-
const anchor =
|
|
45
|
+
const envelope = defValue as { projectionSchema?: { $anchor?: unknown }; $anchor?: unknown };
|
|
46
|
+
const projectionSchema = envelope.projectionSchema;
|
|
47
|
+
if (projectionSchema && typeof projectionSchema === 'object') {
|
|
48
|
+
const anchor = projectionSchema.$anchor;
|
|
49
49
|
if (typeof anchor === 'string' && !anchorToDef[anchor]) {
|
|
50
50
|
anchorToDef[anchor] = defName;
|
|
51
51
|
}
|
|
@@ -3,8 +3,8 @@ export function generateStandaloneTypeContent(name: string): string {
|
|
|
3
3
|
const standaloneResourceTypeName = `${name}Resource`;
|
|
4
4
|
|
|
5
5
|
const ts =
|
|
6
|
-
`import type { ResourcePointer, ${name} as
|
|
7
|
-
`export type ${standaloneResourceTypeName} = ResourcePointer & {
|
|
6
|
+
`import type { ResourcePointer, ${name} as ProjectionSchema } from "../types.js";\n` +
|
|
7
|
+
`export type ${standaloneResourceTypeName} = ResourcePointer & { projection: ProjectionSchema };\n`;
|
|
8
8
|
return header + ts;
|
|
9
9
|
}
|
|
10
10
|
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
type JsonObject = Record<string, unknown>;
|
|
2
|
+
|
|
3
|
+
type TimestampedResource = JsonObject & {
|
|
4
|
+
id: string;
|
|
5
|
+
resourceTypeHandle: string;
|
|
6
|
+
provenance: {
|
|
7
|
+
resourceProvenanceKind: 'genesis';
|
|
8
|
+
};
|
|
9
|
+
timestamp: string;
|
|
10
|
+
projection: unknown;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
type GenerateTimestampedResourcesOptions = {
|
|
14
|
+
resourceTypeHandle: string;
|
|
15
|
+
getResourceId: (projection: unknown) => string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const GENESIS_TIMESTAMP = '2025-11-30T00:00:00.000Z';
|
|
19
|
+
|
|
20
|
+
export function generateTimestampedResources(
|
|
21
|
+
declarations: unknown[],
|
|
22
|
+
options: GenerateTimestampedResourcesOptions,
|
|
23
|
+
): TimestampedResource[] {
|
|
24
|
+
return declarations.map((projection) => {
|
|
25
|
+
return createTimestampedResource(projection, options);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function createTimestampedResource(
|
|
30
|
+
projection: unknown,
|
|
31
|
+
options: GenerateTimestampedResourcesOptions,
|
|
32
|
+
): TimestampedResource {
|
|
33
|
+
return {
|
|
34
|
+
id: options.getResourceId(projection),
|
|
35
|
+
resourceTypeHandle: options.resourceTypeHandle,
|
|
36
|
+
provenance: {
|
|
37
|
+
resourceProvenanceKind: 'genesis',
|
|
38
|
+
},
|
|
39
|
+
timestamp: GENESIS_TIMESTAMP,
|
|
40
|
+
projection,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -53,9 +53,9 @@ function escapeRegExpLiteral(value: string): string {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
function deriveStrategyStateInputEntryByRoleNameValueType(parsedSchema: any): string {
|
|
56
|
-
const defs = parsedSchema?.$defs ?? parsedSchema?.
|
|
56
|
+
const defs = parsedSchema?.$defs ?? parsedSchema?.projectionSchema?.$defs;
|
|
57
57
|
const def = defs?.StrategyStateInputEntryByRoleName;
|
|
58
|
-
const schemaNode = def?.
|
|
58
|
+
const schemaNode = def?.projectionSchema ?? def;
|
|
59
59
|
const additionalProperties = schemaNode?.additionalProperties;
|
|
60
60
|
|
|
61
61
|
if (!additionalProperties || typeof additionalProperties !== 'object' || Array.isArray(additionalProperties)) {
|
package/src/utils/zodCodegen.ts
CHANGED
|
@@ -88,8 +88,8 @@ function isRecordLikeObjectSchema(node: any): boolean {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
function emitRecordLikeObjectSchema(node: any, ctx: Ctx, path: string): string {
|
|
91
|
-
const
|
|
92
|
-
const valueExpr = emitSchema(
|
|
91
|
+
const projectionSchemaNode = node.additionalProperties;
|
|
92
|
+
const valueExpr = emitSchema(projectionSchemaNode, ctx, pathJoin(path, 'additionalProperties'));
|
|
93
93
|
|
|
94
94
|
const pn = node.propertyNames;
|
|
95
95
|
let keyPattern: string | undefined;
|
|
@@ -504,7 +504,7 @@ function buildAnchorMap(defs: Record<string, any>): Record<string, string> {
|
|
|
504
504
|
const top = defSchema.$anchor;
|
|
505
505
|
if (typeof top === 'string' && top) map[top] = defName;
|
|
506
506
|
|
|
507
|
-
const nested = (defSchema as any).
|
|
507
|
+
const nested = (defSchema as any).projectionSchema;
|
|
508
508
|
if (isObject(nested) && typeof nested.$anchor === 'string' && nested.$anchor) {
|
|
509
509
|
map[nested.$anchor] = defName;
|
|
510
510
|
}
|
package/toolproof.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": {
|
|
3
|
+
"kind": "json-pointer",
|
|
4
|
+
"filePath": "package.json",
|
|
5
|
+
"pointer": "/name"
|
|
6
|
+
},
|
|
7
|
+
"version": {
|
|
8
|
+
"kind": "json-pointer",
|
|
9
|
+
"filePath": "package.json",
|
|
10
|
+
"pointer": "/version"
|
|
11
|
+
},
|
|
12
|
+
"description": {
|
|
13
|
+
"kind": "json-pointer",
|
|
14
|
+
"filePath": "package.json",
|
|
15
|
+
"pointer": "/description"
|
|
16
|
+
},
|
|
17
|
+
"resourceTypesPath": "generated-src/declarations/resourceTypes.json",
|
|
18
|
+
"toolsPath": "generated-src/declarations/tools.json"
|
|
19
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
export {};
|
|
2
|
-
/* import type { Resource } from '@toolproof-core/genesis';
|
|
3
|
-
import { createMaterializedFromPotential } from '@toolproof-core/lib/create-resource';
|
|
4
|
-
|
|
5
|
-
function extractNaturalValue(resource: Resource): number {
|
|
6
|
-
const value: unknown = resource.value;
|
|
7
|
-
if (typeof value === 'number' && Number.isInteger(value) && value >= 0) {
|
|
8
|
-
return value;
|
|
9
|
-
}
|
|
10
|
-
throw new Error(`Invalid Natural resource: value must be a non-negative integer`);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function createMockOutput(potentialOutput: any, value: number): Resource {
|
|
14
|
-
const mockPath = `mock://natural/${value}`;
|
|
15
|
-
|
|
16
|
-
const materialized = createMaterializedFromPotential(potentialOutput, value);
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
...materialized,
|
|
20
|
-
path: mockPath,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function createMockErrorOutput(
|
|
25
|
-
potentialOutput: any,
|
|
26
|
-
name: string,
|
|
27
|
-
description: string,
|
|
28
|
-
details?: Record<string, unknown>
|
|
29
|
-
): Resource {
|
|
30
|
-
const value: unknown = {
|
|
31
|
-
name,
|
|
32
|
-
description,
|
|
33
|
-
...(details ? { details } : {}),
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const mockPath = `mock://error/${encodeURIComponent(name)}`;
|
|
37
|
-
|
|
38
|
-
const materialized = createMaterializedFromPotential(potentialOutput, value);
|
|
39
|
-
|
|
40
|
-
return {
|
|
41
|
-
...materialized,
|
|
42
|
-
path: mockPath,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function mockAdd(inputs: Record<string, Resource | any>): Record<string, Resource> {
|
|
47
|
-
const addendOne = inputs['AddendOne'] as Resource;
|
|
48
|
-
const addendTwo = inputs['AddendTwo'] as Resource;
|
|
49
|
-
const sumOutput = inputs['Sum'] as any;
|
|
50
|
-
|
|
51
|
-
const value1 = extractNaturalValue(addendOne);
|
|
52
|
-
const value2 = extractNaturalValue(addendTwo);
|
|
53
|
-
const result = value1 + value2;
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
Sum: createMockOutput(sumOutput, result),
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function mockSubtract(inputs: Record<string, Resource | any>): Record<string, Resource> {
|
|
61
|
-
const minuend = inputs['Minuend'] as Resource;
|
|
62
|
-
const subtrahend = inputs['Subtrahend'] as Resource;
|
|
63
|
-
const differenceOutput = inputs['Difference'] as any;
|
|
64
|
-
|
|
65
|
-
const errorOutput = inputs['ErrorOutput'] as any | undefined;
|
|
66
|
-
|
|
67
|
-
const value1 = extractNaturalValue(minuend);
|
|
68
|
-
const value2 = extractNaturalValue(subtrahend);
|
|
69
|
-
|
|
70
|
-
if (value2 > value1) {
|
|
71
|
-
if (!errorOutput) {
|
|
72
|
-
throw new Error(
|
|
73
|
-
`Subtract mock tool cannot emit error: missing 'ErrorOutput' potential output (subtrahend ${value2} > minuend ${value1})`
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return {
|
|
78
|
-
ErrorOutput: createMockErrorOutput(
|
|
79
|
-
errorOutput,
|
|
80
|
-
'SubtractInvalidInput',
|
|
81
|
-
`Subtrahend (${value2}) is larger than minuend (${value1}); subtraction would result in a negative value.`,
|
|
82
|
-
{
|
|
83
|
-
minuend: value1,
|
|
84
|
-
subtrahend: value2,
|
|
85
|
-
}
|
|
86
|
-
),
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const result = value1 - value2;
|
|
91
|
-
|
|
92
|
-
return {
|
|
93
|
-
Difference: createMockOutput(differenceOutput, result),
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export function mockMultiply(inputs: Record<string, Resource | any>): Record<string, Resource> {
|
|
98
|
-
const multiplicand = inputs['Multiplicand'] as Resource;
|
|
99
|
-
const multiplier = inputs['Multiplier'] as Resource;
|
|
100
|
-
const productOutput = inputs['Product'] as any;
|
|
101
|
-
|
|
102
|
-
const value1 = extractNaturalValue(multiplicand);
|
|
103
|
-
const value2 = extractNaturalValue(multiplier);
|
|
104
|
-
const result = value1 * value2;
|
|
105
|
-
|
|
106
|
-
return {
|
|
107
|
-
Product: createMockOutput(productOutput, result),
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export function mockDouble(inputs: Record<string, Resource | any>): Record<string, Resource> {
|
|
112
|
-
const N = inputs['N'] as Resource;
|
|
113
|
-
const DoubledOutput = inputs['Doubled'] as any;
|
|
114
|
-
|
|
115
|
-
const value = extractNaturalValue(N);
|
|
116
|
-
const result = value * 2;
|
|
117
|
-
|
|
118
|
-
return {
|
|
119
|
-
Doubled: createMockOutput(DoubledOutput, result),
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export function mockDivide(inputs: Record<string, Resource | any>): Record<string, Resource> {
|
|
124
|
-
const dividend = inputs['Dividend'] as Resource;
|
|
125
|
-
const divisor = inputs['Divisor'] as Resource;
|
|
126
|
-
const quotientOutput = inputs['Quotient'] as any;
|
|
127
|
-
const remainderOutput = inputs['Remainder'] as any;
|
|
128
|
-
|
|
129
|
-
const errorOutput = inputs['ErrorOutput'] as any | undefined;
|
|
130
|
-
|
|
131
|
-
const value1 = extractNaturalValue(dividend);
|
|
132
|
-
const value2 = extractNaturalValue(divisor);
|
|
133
|
-
|
|
134
|
-
if (value2 === 0) {
|
|
135
|
-
if (!errorOutput) {
|
|
136
|
-
throw new Error(
|
|
137
|
-
`Divide mock tool cannot emit error: missing 'ErrorOutput' potential output (division by zero; dividend ${value1})`
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return {
|
|
142
|
-
ErrorOutput: createMockErrorOutput(
|
|
143
|
-
errorOutput,
|
|
144
|
-
'DivideByZero',
|
|
145
|
-
`Cannot divide by zero (dividend ${value1}, divisor ${value2}).`,
|
|
146
|
-
{
|
|
147
|
-
dividend: value1,
|
|
148
|
-
divisor: value2,
|
|
149
|
-
}
|
|
150
|
-
),
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const quotient = Math.floor(value1 / value2);
|
|
155
|
-
const remainder = value1 % value2;
|
|
156
|
-
|
|
157
|
-
return {
|
|
158
|
-
Quotient: createMockOutput(quotientOutput, quotient),
|
|
159
|
-
Remainder: createMockOutput(remainderOutput, remainder),
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export function executeMockNumericalTool(
|
|
164
|
-
toolName: string,
|
|
165
|
-
payload: Record<string, Resource | any>
|
|
166
|
-
): Record<string, Resource> {
|
|
167
|
-
const normalizedName = toolName.toLowerCase();
|
|
168
|
-
|
|
169
|
-
switch (normalizedName) {
|
|
170
|
-
case 'add':
|
|
171
|
-
return mockAdd(payload);
|
|
172
|
-
case 'subtract':
|
|
173
|
-
return mockSubtract(payload);
|
|
174
|
-
case 'multiply':
|
|
175
|
-
return mockMultiply(payload);
|
|
176
|
-
case 'double':
|
|
177
|
-
return mockDouble(payload);
|
|
178
|
-
case 'divide':
|
|
179
|
-
return mockDivide(payload);
|
|
180
|
-
default:
|
|
181
|
-
throw new Error(`Unknown numerical tool: ${toolName}`);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
*/
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const GENESIS_TIMESTAMP = '2025-11-30T00:00:00.000Z';
|
|
2
|
-
export function generateResources(resourceTypes) {
|
|
3
|
-
const resources = {};
|
|
4
|
-
for (const [name, resourceType] of Object.entries(resourceTypes)) {
|
|
5
|
-
resources[name] = {
|
|
6
|
-
id: `RESOURCE-${name}`,
|
|
7
|
-
resourceTypeHandle: 'TYPE-ResourceType',
|
|
8
|
-
provenance: {
|
|
9
|
-
resourceProvenanceKind: 'genesis',
|
|
10
|
-
},
|
|
11
|
-
version: 1,
|
|
12
|
-
timestamp: GENESIS_TIMESTAMP,
|
|
13
|
-
value: resourceType,
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
return resources;
|
|
17
|
-
}
|