@harnesys/sdk 0.0.0-stage → 1.1.0
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/LICENSE +21 -0
- package/README.md +80 -2
- package/dist/addon-context-factory.d.ts +6 -0
- package/dist/addon-context-factory.js +160 -0
- package/dist/addon-context.d.ts +346 -0
- package/dist/addon-context.js +0 -0
- package/dist/define-addon.d.ts +57 -0
- package/dist/define-addon.js +53 -0
- package/dist/families/config.d.ts +14 -0
- package/dist/families/config.js +16 -0
- package/dist/families/content.d.ts +28 -0
- package/dist/families/content.js +19 -0
- package/dist/families/field-spec.d.ts +100 -0
- package/dist/families/field-spec.js +85 -0
- package/dist/families/hook.d.ts +37 -0
- package/dist/families/hook.js +25 -0
- package/dist/families/job.d.ts +45 -0
- package/dist/families/job.js +26 -0
- package/dist/families/json-schema-value.d.ts +12 -0
- package/dist/families/json-schema-value.js +243 -0
- package/dist/families/json-schema.d.ts +36 -0
- package/dist/families/json-schema.js +101 -0
- package/dist/families/lsp.d.ts +18 -0
- package/dist/families/lsp.js +18 -0
- package/dist/families/mcp.d.ts +18 -0
- package/dist/families/mcp.js +18 -0
- package/dist/families/registry.d.ts +9 -0
- package/dist/families/registry.js +34 -0
- package/dist/families/route.d.ts +38 -0
- package/dist/families/route.js +37 -0
- package/dist/families/source-kind.d.ts +24 -0
- package/dist/families/source-kind.js +21 -0
- package/dist/families/tool-pack.d.ts +68 -0
- package/dist/families/tool-pack.js +57 -0
- package/dist/families/transport.d.ts +52 -0
- package/dist/families/transport.js +29 -0
- package/dist/families/trigger.d.ts +97 -0
- package/dist/families/trigger.js +46 -0
- package/dist/families/view.d.ts +255 -0
- package/dist/families/view.js +87 -0
- package/dist/families/viewer.d.ts +31 -0
- package/dist/families/viewer.js +26 -0
- package/dist/families/worker.d.ts +23 -0
- package/dist/families/worker.js +19 -0
- package/dist/host-client.d.ts +11 -0
- package/dist/host-client.js +30 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +36 -0
- package/dist/manifest/branding.d.ts +14 -0
- package/dist/manifest/branding.js +18 -0
- package/dist/manifest/connections.d.ts +21 -0
- package/dist/manifest/connections.js +10 -0
- package/dist/manifest/json-schema.d.ts +2 -0
- package/dist/manifest/json-schema.js +13 -0
- package/dist/manifest/l10n.d.ts +9 -0
- package/dist/manifest/l10n.js +28 -0
- package/dist/manifest/manifest.d.ts +112 -0
- package/dist/manifest/manifest.js +45 -0
- package/dist/manifest/validate.d.ts +14 -0
- package/dist/manifest/validate.js +144 -0
- package/dist/permissions/permissions.d.ts +31 -0
- package/dist/permissions/permissions.js +53 -0
- package/dist/process-entry.d.ts +26 -0
- package/dist/process-entry.js +146 -0
- package/dist/protocol/envelope.d.ts +115 -0
- package/dist/protocol/envelope.js +72 -0
- package/dist/protocol/error.d.ts +67 -0
- package/dist/protocol/error.js +61 -0
- package/dist/protocol/handshake.d.ts +55 -0
- package/dist/protocol/handshake.js +26 -0
- package/dist/protocol/map.d.ts +1090 -0
- package/dist/protocol/map.js +127 -0
- package/dist/protocol/meta.d.ts +31 -0
- package/dist/protocol/meta.js +14 -0
- package/dist/protocol/method-spec.d.ts +13 -0
- package/dist/protocol/method-spec.js +9 -0
- package/dist/protocol/org-service-methods.d.ts +135 -0
- package/dist/protocol/org-service-methods.js +106 -0
- package/dist/protocol/shared.d.ts +389 -0
- package/dist/protocol/shared.js +231 -0
- package/dist/protocol/source-methods.d.ts +218 -0
- package/dist/protocol/source-methods.js +18 -0
- package/dist/protocol/thread-service-methods.d.ts +50 -0
- package/dist/protocol/thread-service-methods.js +32 -0
- package/dist/runtime.d.ts +25 -0
- package/dist/runtime.js +229 -0
- package/dist/testing/fake-db.d.ts +15 -0
- package/dist/testing/fake-db.js +120 -0
- package/dist/testing/fake-files.d.ts +9 -0
- package/dist/testing/fake-files.js +87 -0
- package/dist/testing/fake-host.d.ts +115 -0
- package/dist/testing/fake-host.js +217 -0
- package/dist/testing/fake-services.d.ts +63 -0
- package/dist/testing/fake-services.js +277 -0
- package/dist/testing/fixtures.d.ts +5 -0
- package/dist/testing/fixtures.js +101 -0
- package/dist/testing/index.d.ts +4 -0
- package/dist/testing/index.js +2 -0
- package/package.json +66 -4
- package/src/addon-context-factory.ts +236 -0
- package/src/addon-context.ts +313 -0
- package/src/define-addon.ts +178 -0
- package/src/families/config.ts +24 -0
- package/src/families/content.ts +35 -0
- package/src/families/field-spec.ts +175 -0
- package/src/families/hook.ts +34 -0
- package/src/families/job.ts +41 -0
- package/src/families/json-schema-value.ts +322 -0
- package/src/families/json-schema.ts +167 -0
- package/src/families/lsp.ts +28 -0
- package/src/families/mcp.ts +28 -0
- package/src/families/registry.ts +44 -0
- package/src/families/route.ts +52 -0
- package/src/families/source-kind.ts +34 -0
- package/src/families/tool-pack.ts +92 -0
- package/src/families/transport.ts +52 -0
- package/src/families/trigger.ts +92 -0
- package/src/families/view.ts +144 -0
- package/src/families/viewer.ts +43 -0
- package/src/families/worker.ts +30 -0
- package/src/host-client.ts +52 -0
- package/src/index.ts +345 -0
- package/src/manifest/branding.ts +24 -0
- package/src/manifest/connections.ts +21 -0
- package/src/manifest/json-schema.ts +24 -0
- package/src/manifest/l10n.ts +39 -0
- package/src/manifest/manifest.ts +94 -0
- package/src/manifest/validate.ts +200 -0
- package/src/permissions/permissions.ts +79 -0
- package/src/process-entry.ts +205 -0
- package/src/protocol/envelope.ts +126 -0
- package/src/protocol/error.ts +81 -0
- package/src/protocol/handshake.ts +43 -0
- package/src/protocol/map.ts +339 -0
- package/src/protocol/meta.ts +26 -0
- package/src/protocol/method-spec.ts +40 -0
- package/src/protocol/org-service-methods.ts +148 -0
- package/src/protocol/shared.ts +345 -0
- package/src/protocol/source-methods.ts +61 -0
- package/src/protocol/thread-service-methods.ts +50 -0
- package/src/runtime.ts +332 -0
- package/src/testing/fake-db.ts +140 -0
- package/src/testing/fake-files.ts +114 -0
- package/src/testing/fake-host.ts +350 -0
- package/src/testing/fake-services.ts +345 -0
- package/src/testing/fixtures.ts +106 -0
- package/src/testing/index.ts +12 -0
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import type { JsonSchemaSubset } from './json-schema.ts';
|
|
2
|
+
|
|
3
|
+
export interface SchemaValueIssue {
|
|
4
|
+
path: string;
|
|
5
|
+
message: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface ValidationContext {
|
|
9
|
+
root: Record<string, unknown>;
|
|
10
|
+
issues: SchemaValueIssue[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const MAX_VALIDATION_DEPTH = 16;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Validates a value against the §6.5 JSON Schema subset (`type`, `properties`,
|
|
17
|
+
* `required`, `items`, `enum`, `const`, numeric and string bounds,
|
|
18
|
+
* `additionalProperties`, limited `oneOf`/`anyOf`, local `$defs`/`$ref`).
|
|
19
|
+
* Same contract the host applies to route request bodies; the fake host uses it
|
|
20
|
+
* to validate tool `inputSchema`/`outputSchema`.
|
|
21
|
+
*/
|
|
22
|
+
export function schemaValueIssues(
|
|
23
|
+
value: unknown,
|
|
24
|
+
schema: Record<string, unknown>,
|
|
25
|
+
): SchemaValueIssue[] {
|
|
26
|
+
const ctx: ValidationContext = { root: schema, issues: [] };
|
|
27
|
+
validateNode(value, schema as JsonSchemaSubset, '$', 0, ctx);
|
|
28
|
+
return ctx.issues;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function validateNode(
|
|
32
|
+
value: unknown,
|
|
33
|
+
node: JsonSchemaSubset,
|
|
34
|
+
path: string,
|
|
35
|
+
depth: number,
|
|
36
|
+
ctx: ValidationContext,
|
|
37
|
+
): void {
|
|
38
|
+
if (depth > MAX_VALIDATION_DEPTH) {
|
|
39
|
+
ctx.issues.push({ path, message: 'value nesting exceeds the maximum depth' });
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (node.$ref !== undefined) {
|
|
43
|
+
validateRef(value, node.$ref, path, depth, ctx);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (!matchesUnion(value, node, path, ctx)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (!matchesEnum(value, node, path, ctx)) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (node.const !== undefined && node.const !== value) {
|
|
53
|
+
ctx.issues.push({ path, message: 'value does not equal the const constraint' });
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (typeof value === 'string') {
|
|
57
|
+
validateString(value, node, path, ctx);
|
|
58
|
+
} else if (typeof value === 'number' && Number.isFinite(value)) {
|
|
59
|
+
validateNumber(value, node, path, ctx);
|
|
60
|
+
} else if (Array.isArray(value)) {
|
|
61
|
+
validateArray(value, node, path, depth, ctx);
|
|
62
|
+
} else if (isPlainObject(value)) {
|
|
63
|
+
validateObject(value, node, path, depth, ctx);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function validateRef(
|
|
68
|
+
value: unknown,
|
|
69
|
+
ref: string,
|
|
70
|
+
path: string,
|
|
71
|
+
depth: number,
|
|
72
|
+
ctx: ValidationContext,
|
|
73
|
+
): void {
|
|
74
|
+
const resolved = resolveRef(ctx.root, ref);
|
|
75
|
+
if (resolved === null) {
|
|
76
|
+
ctx.issues.push({ path, message: `unresolvable $ref '${ref}'` });
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
validateNode(value, resolved, path, depth + 1, ctx);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function matchesUnion(
|
|
83
|
+
value: unknown,
|
|
84
|
+
node: JsonSchemaSubset,
|
|
85
|
+
path: string,
|
|
86
|
+
ctx: ValidationContext,
|
|
87
|
+
): boolean {
|
|
88
|
+
if (node.oneOf !== undefined && node.oneOf.length > 0) {
|
|
89
|
+
const matches = node.oneOf.filter((branch) => branchIssues(value, branch, ctx) === 0).length;
|
|
90
|
+
if (matches !== 1) {
|
|
91
|
+
ctx.issues.push({ path, message: `expected exactly one oneOf branch, matched ${matches}` });
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
if (node.anyOf !== undefined && node.anyOf.length > 0) {
|
|
97
|
+
if (!node.anyOf.some((branch) => branchIssues(value, branch, ctx) === 0)) {
|
|
98
|
+
ctx.issues.push({ path, message: 'value matches no anyOf branch' });
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
if (!matchesType(value, node.type)) {
|
|
104
|
+
ctx.issues.push({ path, message: `expected ${node.type ?? 'any'}, got ${kindOf(value)}` });
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function matchesEnum(
|
|
111
|
+
value: unknown,
|
|
112
|
+
node: JsonSchemaSubset,
|
|
113
|
+
path: string,
|
|
114
|
+
ctx: ValidationContext,
|
|
115
|
+
): boolean {
|
|
116
|
+
if (node.enum === undefined || node.enum.some((entry) => entry === value)) {
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
ctx.issues.push({ path, message: 'value is not one of the allowed enum entries' });
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
type SchemaType = 'object' | 'array' | 'string' | 'number' | 'integer' | 'boolean' | 'null';
|
|
124
|
+
|
|
125
|
+
function matchesType(value: unknown, expected: SchemaType | undefined): boolean {
|
|
126
|
+
if (expected === undefined) {
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
switch (expected) {
|
|
130
|
+
case 'string':
|
|
131
|
+
return typeof value === 'string';
|
|
132
|
+
case 'boolean':
|
|
133
|
+
return typeof value === 'boolean';
|
|
134
|
+
case 'null':
|
|
135
|
+
return value === null;
|
|
136
|
+
case 'integer':
|
|
137
|
+
return typeof value === 'number' && Number.isInteger(value);
|
|
138
|
+
case 'number':
|
|
139
|
+
return typeof value === 'number' && Number.isFinite(value);
|
|
140
|
+
case 'array':
|
|
141
|
+
return Array.isArray(value);
|
|
142
|
+
case 'object':
|
|
143
|
+
return isPlainObject(value);
|
|
144
|
+
default:
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function validateString(
|
|
150
|
+
value: string,
|
|
151
|
+
node: JsonSchemaSubset,
|
|
152
|
+
path: string,
|
|
153
|
+
ctx: ValidationContext,
|
|
154
|
+
): void {
|
|
155
|
+
if (node.minLength !== undefined && value.length < node.minLength) {
|
|
156
|
+
ctx.issues.push({ path, message: `length is below minLength ${node.minLength}` });
|
|
157
|
+
}
|
|
158
|
+
if (node.maxLength !== undefined && value.length > node.maxLength) {
|
|
159
|
+
ctx.issues.push({ path, message: `length exceeds maxLength ${node.maxLength}` });
|
|
160
|
+
}
|
|
161
|
+
if (node.pattern === undefined) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
try {
|
|
165
|
+
if (!new RegExp(node.pattern).test(value)) {
|
|
166
|
+
ctx.issues.push({ path, message: `value does not match pattern '${node.pattern}'` });
|
|
167
|
+
}
|
|
168
|
+
} catch {
|
|
169
|
+
ctx.issues.push({ path, message: `schema pattern '${node.pattern}' is not a valid regex` });
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function validateNumber(
|
|
174
|
+
value: number,
|
|
175
|
+
node: JsonSchemaSubset,
|
|
176
|
+
path: string,
|
|
177
|
+
ctx: ValidationContext,
|
|
178
|
+
): void {
|
|
179
|
+
if (node.minimum !== undefined && value < node.minimum) {
|
|
180
|
+
ctx.issues.push({ path, message: `value is below minimum ${node.minimum}` });
|
|
181
|
+
}
|
|
182
|
+
if (node.maximum !== undefined && value > node.maximum) {
|
|
183
|
+
ctx.issues.push({ path, message: `value exceeds maximum ${node.maximum}` });
|
|
184
|
+
}
|
|
185
|
+
if (node.exclusiveMinimum !== undefined && value <= node.exclusiveMinimum) {
|
|
186
|
+
ctx.issues.push({
|
|
187
|
+
path,
|
|
188
|
+
message: `value is not above exclusiveMinimum ${node.exclusiveMinimum}`,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
if (node.exclusiveMaximum !== undefined && value >= node.exclusiveMaximum) {
|
|
192
|
+
ctx.issues.push({
|
|
193
|
+
path,
|
|
194
|
+
message: `value is not below exclusiveMaximum ${node.exclusiveMaximum}`,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function validateArray(
|
|
200
|
+
value: unknown[],
|
|
201
|
+
node: JsonSchemaSubset,
|
|
202
|
+
path: string,
|
|
203
|
+
depth: number,
|
|
204
|
+
ctx: ValidationContext,
|
|
205
|
+
): void {
|
|
206
|
+
if (node.minItems !== undefined && value.length < node.minItems) {
|
|
207
|
+
ctx.issues.push({ path, message: `array has fewer than minItems ${node.minItems}` });
|
|
208
|
+
}
|
|
209
|
+
if (node.maxItems !== undefined && value.length > node.maxItems) {
|
|
210
|
+
ctx.issues.push({ path, message: `array has more than maxItems ${node.maxItems}` });
|
|
211
|
+
}
|
|
212
|
+
if (node.uniqueItems === true && hasDuplicates(value)) {
|
|
213
|
+
ctx.issues.push({ path, message: 'array entries are not unique' });
|
|
214
|
+
}
|
|
215
|
+
if (node.items === undefined) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const items = node.items;
|
|
219
|
+
if (Array.isArray(items)) {
|
|
220
|
+
for (const [index, item] of value.entries()) {
|
|
221
|
+
const itemSchema = items[index];
|
|
222
|
+
if (itemSchema !== undefined) {
|
|
223
|
+
validateNode(item, itemSchema, `${path}[${index}]`, depth + 1, ctx);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
for (const [index, item] of value.entries()) {
|
|
229
|
+
validateNode(item, items, `${path}[${index}]`, depth + 1, ctx);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function validateObject(
|
|
234
|
+
value: Record<string, unknown>,
|
|
235
|
+
node: JsonSchemaSubset,
|
|
236
|
+
path: string,
|
|
237
|
+
depth: number,
|
|
238
|
+
ctx: ValidationContext,
|
|
239
|
+
): void {
|
|
240
|
+
for (const key of node.required ?? []) {
|
|
241
|
+
if (!(key in value)) {
|
|
242
|
+
ctx.issues.push({ path, message: `missing required property '${key}'` });
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const additional = node.additionalProperties;
|
|
246
|
+
if (additional === undefined || additional === true) {
|
|
247
|
+
validateDeclaredProperties(value, node, path, depth, ctx);
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
for (const [key, child] of Object.entries(value)) {
|
|
251
|
+
const childPath = `${path}.${key}`;
|
|
252
|
+
const declared = node.properties?.[key];
|
|
253
|
+
if (declared !== undefined) {
|
|
254
|
+
validateNode(child, declared, childPath, depth + 1, ctx);
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
if (additional === false) {
|
|
258
|
+
ctx.issues.push({ path: childPath, message: 'property is not allowed by the schema' });
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
validateNode(child, additional, childPath, depth + 1, ctx);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function validateDeclaredProperties(
|
|
266
|
+
value: Record<string, unknown>,
|
|
267
|
+
node: JsonSchemaSubset,
|
|
268
|
+
path: string,
|
|
269
|
+
depth: number,
|
|
270
|
+
ctx: ValidationContext,
|
|
271
|
+
): void {
|
|
272
|
+
for (const [key, child] of Object.entries(node.properties ?? {})) {
|
|
273
|
+
if (key in value) {
|
|
274
|
+
validateNode(value[key], child, `${path}.${key}`, depth + 1, ctx);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function branchIssues(value: unknown, branch: JsonSchemaSubset, ctx: ValidationContext): number {
|
|
280
|
+
const issues: SchemaValueIssue[] = [];
|
|
281
|
+
validateNode(value, branch, '$', 0, { root: ctx.root, issues });
|
|
282
|
+
return issues.length;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function resolveRef(root: Record<string, unknown>, ref: string): JsonSchemaSubset | null {
|
|
286
|
+
if (!ref.startsWith('#/')) {
|
|
287
|
+
return null;
|
|
288
|
+
}
|
|
289
|
+
let current: unknown = root;
|
|
290
|
+
for (const segment of ref.slice(2).split('/')) {
|
|
291
|
+
if (!isPlainObject(current)) {
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
current = current[segment];
|
|
295
|
+
}
|
|
296
|
+
return isPlainObject(current) ? (current as JsonSchemaSubset) : null;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function hasDuplicates(value: unknown[]): boolean {
|
|
300
|
+
const seen = new Set<string>();
|
|
301
|
+
for (const entry of value) {
|
|
302
|
+
const key = JSON.stringify(entry);
|
|
303
|
+
if (seen.has(key)) {
|
|
304
|
+
return true;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
311
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function kindOf(value: unknown): string {
|
|
315
|
+
if (value === null) {
|
|
316
|
+
return 'null';
|
|
317
|
+
}
|
|
318
|
+
if (Array.isArray(value)) {
|
|
319
|
+
return 'array';
|
|
320
|
+
}
|
|
321
|
+
return typeof value;
|
|
322
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
export type JsonSchemaItems = JsonSchemaSubset | JsonSchemaSubset[];
|
|
4
|
+
|
|
5
|
+
export interface JsonSchemaSubset {
|
|
6
|
+
type?: 'object' | 'array' | 'string' | 'number' | 'integer' | 'boolean' | 'null';
|
|
7
|
+
properties?: Record<string, JsonSchemaSubset>;
|
|
8
|
+
required?: string[];
|
|
9
|
+
additionalProperties?: boolean | JsonSchemaSubset;
|
|
10
|
+
items?: JsonSchemaItems;
|
|
11
|
+
enum?: unknown[];
|
|
12
|
+
const?: unknown;
|
|
13
|
+
minimum?: number;
|
|
14
|
+
maximum?: number;
|
|
15
|
+
exclusiveMinimum?: number;
|
|
16
|
+
exclusiveMaximum?: number;
|
|
17
|
+
minLength?: number;
|
|
18
|
+
maxLength?: number;
|
|
19
|
+
pattern?: string;
|
|
20
|
+
minItems?: number;
|
|
21
|
+
maxItems?: number;
|
|
22
|
+
uniqueItems?: boolean;
|
|
23
|
+
oneOf?: JsonSchemaSubset[];
|
|
24
|
+
anyOf?: JsonSchemaSubset[];
|
|
25
|
+
description?: string;
|
|
26
|
+
default?: unknown;
|
|
27
|
+
$defs?: Record<string, JsonSchemaSubset>;
|
|
28
|
+
$ref?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const node = z.lazy(
|
|
32
|
+
(): z.ZodType<JsonSchemaSubset> =>
|
|
33
|
+
z.strictObject({
|
|
34
|
+
type: z
|
|
35
|
+
.enum(['object', 'array', 'string', 'number', 'integer', 'boolean', 'null'])
|
|
36
|
+
.optional(),
|
|
37
|
+
properties: z.record(z.string(), node).optional(),
|
|
38
|
+
required: z.array(z.string()).optional(),
|
|
39
|
+
additionalProperties: z.union([z.boolean(), node]).optional(),
|
|
40
|
+
items: z.union([node, z.array(node)]).optional(),
|
|
41
|
+
enum: z.array(z.unknown()).optional(),
|
|
42
|
+
const: z.unknown().optional(),
|
|
43
|
+
minimum: z.number().optional(),
|
|
44
|
+
maximum: z.number().optional(),
|
|
45
|
+
exclusiveMinimum: z.number().optional(),
|
|
46
|
+
exclusiveMaximum: z.number().optional(),
|
|
47
|
+
minLength: z.number().int().nonnegative().optional(),
|
|
48
|
+
maxLength: z.number().int().nonnegative().optional(),
|
|
49
|
+
pattern: z.string().optional(),
|
|
50
|
+
minItems: z.number().int().nonnegative().optional(),
|
|
51
|
+
maxItems: z.number().int().nonnegative().optional(),
|
|
52
|
+
uniqueItems: z.boolean().optional(),
|
|
53
|
+
oneOf: z.array(node).optional(),
|
|
54
|
+
anyOf: z.array(node).optional(),
|
|
55
|
+
description: z.string().optional(),
|
|
56
|
+
default: z.unknown().optional(),
|
|
57
|
+
$defs: z.record(z.string(), node).optional(),
|
|
58
|
+
$ref: z.string().optional(),
|
|
59
|
+
}),
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
export const JsonSchemaSubsetSchema = node;
|
|
63
|
+
|
|
64
|
+
export const INPUT_SCHEMA_MAX_DEPTH = 8;
|
|
65
|
+
export const INPUT_SCHEMA_MAX_BYTES = 64 * 1024;
|
|
66
|
+
|
|
67
|
+
export interface SchemaViolation {
|
|
68
|
+
path: string;
|
|
69
|
+
code: 'schema' | 'depth' | 'size' | 'external_ref';
|
|
70
|
+
message: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function validateInputSchema(raw: unknown): SchemaViolation[] {
|
|
74
|
+
const violations: SchemaViolation[] = [];
|
|
75
|
+
const parsed = JsonSchemaSubsetSchema.safeParse(raw);
|
|
76
|
+
if (!parsed.success) {
|
|
77
|
+
for (const issue of parsed.error.issues) {
|
|
78
|
+
violations.push({
|
|
79
|
+
path: issue.path.map(String).join('.') || '(root)',
|
|
80
|
+
code: 'schema',
|
|
81
|
+
message: issue.message,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return violations;
|
|
85
|
+
}
|
|
86
|
+
const size = new TextEncoder().encode(JSON.stringify(raw)).length;
|
|
87
|
+
if (size > INPUT_SCHEMA_MAX_BYTES) {
|
|
88
|
+
violations.push({
|
|
89
|
+
path: '(root)',
|
|
90
|
+
code: 'size',
|
|
91
|
+
message: `schema exceeds ${INPUT_SCHEMA_MAX_BYTES} bytes (${size})`,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
checkNode(parsed.data, '$', 0, violations);
|
|
95
|
+
return violations;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const LOCAL_REF = /^#(\/(\$defs|properties)\/[A-Za-z0-9_-]+)*$/;
|
|
99
|
+
|
|
100
|
+
function checkNode(
|
|
101
|
+
nodeValue: JsonSchemaSubset,
|
|
102
|
+
path: string,
|
|
103
|
+
depth: number,
|
|
104
|
+
violations: SchemaViolation[],
|
|
105
|
+
): void {
|
|
106
|
+
if (depth > INPUT_SCHEMA_MAX_DEPTH) {
|
|
107
|
+
violations.push({
|
|
108
|
+
path,
|
|
109
|
+
code: 'depth',
|
|
110
|
+
message: `schema depth exceeds ${INPUT_SCHEMA_MAX_DEPTH}`,
|
|
111
|
+
});
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
checkRef(nodeValue, path, violations);
|
|
115
|
+
checkChildren(nodeValue, path, depth, violations);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function checkRef(nodeValue: JsonSchemaSubset, path: string, violations: SchemaViolation[]): void {
|
|
119
|
+
if (nodeValue.$ref !== undefined && !LOCAL_REF.test(nodeValue.$ref)) {
|
|
120
|
+
violations.push({
|
|
121
|
+
path,
|
|
122
|
+
code: 'external_ref',
|
|
123
|
+
message: `external $ref '${nodeValue.$ref}' is not allowed`,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function checkChildren(
|
|
129
|
+
nodeValue: JsonSchemaSubset,
|
|
130
|
+
path: string,
|
|
131
|
+
depth: number,
|
|
132
|
+
violations: SchemaViolation[],
|
|
133
|
+
): void {
|
|
134
|
+
for (const child of Object.values(nodeValue.properties ?? {})) {
|
|
135
|
+
checkNode(child, `${path}.properties`, depth + 1, violations);
|
|
136
|
+
}
|
|
137
|
+
checkItems(nodeValue.items, path, depth, violations);
|
|
138
|
+
const branches = [...(nodeValue.oneOf ?? []), ...(nodeValue.anyOf ?? [])];
|
|
139
|
+
for (const branch of branches) {
|
|
140
|
+
checkNode(branch, `${path}.oneOf`, depth + 1, violations);
|
|
141
|
+
}
|
|
142
|
+
if (typeof nodeValue.additionalProperties === 'object') {
|
|
143
|
+
checkNode(
|
|
144
|
+
nodeValue.additionalProperties,
|
|
145
|
+
`${path}.additionalProperties`,
|
|
146
|
+
depth + 1,
|
|
147
|
+
violations,
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
for (const def of Object.values(nodeValue.$defs ?? {})) {
|
|
151
|
+
checkNode(def, `${path}.$defs`, depth + 1, violations);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function checkItems(
|
|
156
|
+
items: JsonSchemaItems | undefined,
|
|
157
|
+
path: string,
|
|
158
|
+
depth: number,
|
|
159
|
+
violations: SchemaViolation[],
|
|
160
|
+
): void {
|
|
161
|
+
if (!items) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
for (const item of Array.isArray(items) ? items : [items]) {
|
|
165
|
+
checkNode(item, `${path}.items`, depth + 1, violations);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { L10n } from '../manifest/l10n.ts';
|
|
3
|
+
import { L10nSchema } from '../manifest/l10n.ts';
|
|
4
|
+
|
|
5
|
+
export const LSP_SCHEMA_VERSION = 1;
|
|
6
|
+
|
|
7
|
+
export interface LspDescriptor {
|
|
8
|
+
id: string;
|
|
9
|
+
title: L10n;
|
|
10
|
+
connection?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const LspDescriptorSchema = z.object({
|
|
14
|
+
id: z.string().min(1),
|
|
15
|
+
title: L10nSchema,
|
|
16
|
+
connection: z.string().min(1).optional(),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export const lspFamily = {
|
|
20
|
+
family: 'lsp',
|
|
21
|
+
versions: [LSP_SCHEMA_VERSION],
|
|
22
|
+
schema: (v: number): z.ZodType => {
|
|
23
|
+
if (v !== LSP_SCHEMA_VERSION) {
|
|
24
|
+
throw new Error(`lsp descriptor schema version ${v} is not supported`);
|
|
25
|
+
}
|
|
26
|
+
return LspDescriptorSchema;
|
|
27
|
+
},
|
|
28
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { L10n } from '../manifest/l10n.ts';
|
|
3
|
+
import { L10nSchema } from '../manifest/l10n.ts';
|
|
4
|
+
|
|
5
|
+
export const MCP_SCHEMA_VERSION = 1;
|
|
6
|
+
|
|
7
|
+
export interface McpDescriptor {
|
|
8
|
+
id: string;
|
|
9
|
+
title: L10n;
|
|
10
|
+
connection?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const McpDescriptorSchema = z.object({
|
|
14
|
+
id: z.string().min(1),
|
|
15
|
+
title: L10nSchema,
|
|
16
|
+
connection: z.string().min(1).optional(),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export const mcpFamily = {
|
|
20
|
+
family: 'mcp',
|
|
21
|
+
versions: [MCP_SCHEMA_VERSION],
|
|
22
|
+
schema: (v: number): z.ZodType => {
|
|
23
|
+
if (v !== MCP_SCHEMA_VERSION) {
|
|
24
|
+
throw new Error(`mcp descriptor schema version ${v} is not supported`);
|
|
25
|
+
}
|
|
26
|
+
return McpDescriptorSchema;
|
|
27
|
+
},
|
|
28
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import { configFamily } from './config.ts';
|
|
3
|
+
import { contentFamily } from './content.ts';
|
|
4
|
+
import { hookFamily } from './hook.ts';
|
|
5
|
+
import { jobFamily } from './job.ts';
|
|
6
|
+
import { lspFamily } from './lsp.ts';
|
|
7
|
+
import { mcpFamily } from './mcp.ts';
|
|
8
|
+
import { routeFamily } from './route.ts';
|
|
9
|
+
import { sourceKindFamily } from './source-kind.ts';
|
|
10
|
+
import { toolPackFamily } from './tool-pack.ts';
|
|
11
|
+
import { transportFamily } from './transport.ts';
|
|
12
|
+
import { triggerFamily } from './trigger.ts';
|
|
13
|
+
import { viewFamily } from './view.ts';
|
|
14
|
+
import { viewerFamily } from './viewer.ts';
|
|
15
|
+
import { workerFamily } from './worker.ts';
|
|
16
|
+
|
|
17
|
+
export interface FamilyDefinition {
|
|
18
|
+
readonly family: string;
|
|
19
|
+
readonly versions: readonly number[];
|
|
20
|
+
schema(v: number): z.ZodType;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const familyRegistry: Record<string, FamilyDefinition> = {
|
|
24
|
+
'tool-pack': toolPackFamily,
|
|
25
|
+
trigger: triggerFamily,
|
|
26
|
+
job: jobFamily,
|
|
27
|
+
worker: workerFamily,
|
|
28
|
+
route: routeFamily,
|
|
29
|
+
transport: transportFamily,
|
|
30
|
+
hook: hookFamily,
|
|
31
|
+
content: contentFamily,
|
|
32
|
+
config: configFamily,
|
|
33
|
+
view: viewFamily,
|
|
34
|
+
'source-kind': sourceKindFamily,
|
|
35
|
+
mcp: mcpFamily,
|
|
36
|
+
lsp: lspFamily,
|
|
37
|
+
viewer: viewerFamily,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const FAMILY_NAMES = Object.keys(familyRegistry) as Array<keyof typeof familyRegistry>;
|
|
41
|
+
|
|
42
|
+
export function familyDefinition(family: string): FamilyDefinition | undefined {
|
|
43
|
+
return familyRegistry[family];
|
|
44
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { JsonSchemaSubsetSchema, validateInputSchema } from './json-schema.ts';
|
|
3
|
+
|
|
4
|
+
export const ROUTE_SCHEMA_VERSION = 1;
|
|
5
|
+
|
|
6
|
+
export type RouteMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
7
|
+
|
|
8
|
+
export interface RouteDescriptor {
|
|
9
|
+
id: string;
|
|
10
|
+
method: RouteMethod;
|
|
11
|
+
path: string;
|
|
12
|
+
role?: 'member' | 'admin';
|
|
13
|
+
exposure?: 'org' | 'public';
|
|
14
|
+
bodyLimitKb?: number;
|
|
15
|
+
requestSchema?: Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const RouteDescriptorSchema = z
|
|
19
|
+
.object({
|
|
20
|
+
id: z.string().min(1),
|
|
21
|
+
method: z.enum(['GET', 'POST', 'PUT', 'PATCH', 'DELETE']),
|
|
22
|
+
path: z
|
|
23
|
+
.string()
|
|
24
|
+
.regex(/^\/[A-Za-z0-9/_:.-]*$/, 'path must start with / and use :param segments'),
|
|
25
|
+
role: z.enum(['member', 'admin']).optional(),
|
|
26
|
+
exposure: z.enum(['org', 'public']).optional(),
|
|
27
|
+
bodyLimitKb: z.number().int().positive().optional(),
|
|
28
|
+
requestSchema: JsonSchemaSubsetSchema.optional(),
|
|
29
|
+
})
|
|
30
|
+
.superRefine((descriptor, ctx) => {
|
|
31
|
+
if (descriptor.requestSchema === undefined) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
for (const violation of validateInputSchema(descriptor.requestSchema)) {
|
|
35
|
+
ctx.addIssue({
|
|
36
|
+
code: 'custom',
|
|
37
|
+
path: ['requestSchema', violation.path],
|
|
38
|
+
message: `${violation.code}: ${violation.message}`,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export const routeFamily = {
|
|
44
|
+
family: 'route',
|
|
45
|
+
versions: [ROUTE_SCHEMA_VERSION],
|
|
46
|
+
schema: (v: number): z.ZodType => {
|
|
47
|
+
if (v !== ROUTE_SCHEMA_VERSION) {
|
|
48
|
+
throw new Error(`route descriptor schema version ${v} is not supported`);
|
|
49
|
+
}
|
|
50
|
+
return RouteDescriptorSchema;
|
|
51
|
+
},
|
|
52
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { L10n } from '../manifest/l10n.ts';
|
|
3
|
+
import { L10nSchema } from '../manifest/l10n.ts';
|
|
4
|
+
|
|
5
|
+
export const SOURCE_KIND_SCHEMA_VERSION = 1;
|
|
6
|
+
|
|
7
|
+
export interface SourceKindDescriptor {
|
|
8
|
+
id: string;
|
|
9
|
+
title: L10n;
|
|
10
|
+
connection?: string;
|
|
11
|
+
supportsRootMount?: boolean;
|
|
12
|
+
supportsSearch?: boolean;
|
|
13
|
+
rootTitle?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const SourceKindDescriptorSchema = z.object({
|
|
17
|
+
id: z.string().min(1),
|
|
18
|
+
title: L10nSchema,
|
|
19
|
+
connection: z.string().min(1).optional(),
|
|
20
|
+
supportsRootMount: z.boolean().optional(),
|
|
21
|
+
supportsSearch: z.boolean().optional(),
|
|
22
|
+
rootTitle: z.string().min(1).optional(),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export const sourceKindFamily = {
|
|
26
|
+
family: 'source-kind',
|
|
27
|
+
versions: [SOURCE_KIND_SCHEMA_VERSION],
|
|
28
|
+
schema: (v: number): z.ZodType => {
|
|
29
|
+
if (v !== SOURCE_KIND_SCHEMA_VERSION) {
|
|
30
|
+
throw new Error(`source-kind descriptor schema version ${v} is not supported`);
|
|
31
|
+
}
|
|
32
|
+
return SourceKindDescriptorSchema;
|
|
33
|
+
},
|
|
34
|
+
};
|