@harnesys/sdk 0.0.0-stage → 1.0.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.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 +35 -0
- package/dist/index.js +35 -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 +152 -0
- package/dist/testing/fake-services.d.ts +63 -0
- package/dist/testing/fake-services.js +277 -0
- package/dist/testing/fixtures.d.ts +4 -0
- package/dist/testing/fixtures.js +84 -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.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 +341 -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 +261 -0
- package/src/testing/fake-services.ts +345 -0
- package/src/testing/fixtures.ts +88 -0
- package/src/testing/index.ts +12 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
export type FieldType =
|
|
4
|
+
| 'text'
|
|
5
|
+
| 'secret'
|
|
6
|
+
| 'textarea'
|
|
7
|
+
| 'url'
|
|
8
|
+
| 'select'
|
|
9
|
+
| 'number'
|
|
10
|
+
| 'boolean'
|
|
11
|
+
| 'group';
|
|
12
|
+
|
|
13
|
+
export type FieldValue = string | number | boolean | null;
|
|
14
|
+
|
|
15
|
+
export interface FieldOption {
|
|
16
|
+
value: string;
|
|
17
|
+
label: string;
|
|
18
|
+
/** Hint shown for the currently selected option. */
|
|
19
|
+
help?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Conditional visibility: show the field only when `values[key]` matches. */
|
|
23
|
+
export interface FieldVisibleWhen {
|
|
24
|
+
key: string;
|
|
25
|
+
equals?: string;
|
|
26
|
+
oneOf?: string[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Rich editor registered on the client; unknown kinds fall back to the base type. */
|
|
30
|
+
export interface FieldWidget {
|
|
31
|
+
kind: string;
|
|
32
|
+
params?: Record<string, string | number | boolean>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Declarative option source resolved by the host: an add-on-owned GET route
|
|
37
|
+
* or the add-on's connected accounts. No per-provider client code.
|
|
38
|
+
*/
|
|
39
|
+
export type FieldOptionsFrom =
|
|
40
|
+
| {
|
|
41
|
+
/** Route id served under `/orgs/:orgId/addons/:addonId/r/<route>`. */
|
|
42
|
+
kind: 'addonRoute';
|
|
43
|
+
route: string;
|
|
44
|
+
/** Field keys passed to the route as query params. */
|
|
45
|
+
dependsOn?: string[];
|
|
46
|
+
/** Response body key holding the rows. Defaults to `rows`. */
|
|
47
|
+
listKey?: string;
|
|
48
|
+
/** Row field used as the option value. */
|
|
49
|
+
valueKey: string;
|
|
50
|
+
/** Row field used as the option label. Defaults to `valueKey`. */
|
|
51
|
+
labelKey?: string;
|
|
52
|
+
}
|
|
53
|
+
| { kind: 'connections' }
|
|
54
|
+
| { kind: 'agents' };
|
|
55
|
+
|
|
56
|
+
export interface FieldSpec {
|
|
57
|
+
key: string;
|
|
58
|
+
label: string;
|
|
59
|
+
type: FieldType;
|
|
60
|
+
required: boolean;
|
|
61
|
+
placeholder?: string;
|
|
62
|
+
help?: string;
|
|
63
|
+
default?: FieldValue;
|
|
64
|
+
options?: FieldOption[];
|
|
65
|
+
/** Option-valued field accepting several values, stored as one comma-separated string. */
|
|
66
|
+
multi?: boolean;
|
|
67
|
+
/** Options resolved by the host at render time; static `options` stay the fallback. */
|
|
68
|
+
optionsFrom?: FieldOptionsFrom;
|
|
69
|
+
pattern?: { regex: string; hint: string };
|
|
70
|
+
editable?: boolean;
|
|
71
|
+
generated?: boolean;
|
|
72
|
+
/** Children of a `group` field. */
|
|
73
|
+
fields?: FieldSpec[];
|
|
74
|
+
visibleWhen?: FieldVisibleWhen;
|
|
75
|
+
widget?: FieldWidget;
|
|
76
|
+
/** `group` only: render collapsed by default. */
|
|
77
|
+
collapsible?: boolean;
|
|
78
|
+
/** `group` only: an expert section, rendered after the main fields. */
|
|
79
|
+
advanced?: boolean;
|
|
80
|
+
/** `group` only: grid columns for children. */
|
|
81
|
+
columns?: number;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export const FieldTypeSchema = z.enum([
|
|
85
|
+
'text',
|
|
86
|
+
'secret',
|
|
87
|
+
'textarea',
|
|
88
|
+
'url',
|
|
89
|
+
'select',
|
|
90
|
+
'number',
|
|
91
|
+
'boolean',
|
|
92
|
+
'group',
|
|
93
|
+
]);
|
|
94
|
+
|
|
95
|
+
export const FieldValueSchema = z.union([z.string(), z.number(), z.boolean(), z.null()]);
|
|
96
|
+
|
|
97
|
+
export const FieldOptionSchema = z.object({
|
|
98
|
+
value: z.string(),
|
|
99
|
+
label: z.string(),
|
|
100
|
+
help: z.string().optional(),
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
export const FieldVisibleWhenSchema = z.object({
|
|
104
|
+
key: z.string().min(1),
|
|
105
|
+
equals: z.string().optional(),
|
|
106
|
+
oneOf: z.array(z.string()).optional(),
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
export const FieldWidgetSchema = z.object({
|
|
110
|
+
kind: z.string().min(1),
|
|
111
|
+
params: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])).optional(),
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
export const FieldOptionsFromSchema: z.ZodType<FieldOptionsFrom> = z.union([
|
|
115
|
+
z.object({
|
|
116
|
+
kind: z.literal('addonRoute'),
|
|
117
|
+
route: z.string().min(1),
|
|
118
|
+
dependsOn: z.array(z.string().min(1)).optional(),
|
|
119
|
+
listKey: z.string().min(1).optional(),
|
|
120
|
+
valueKey: z.string().min(1),
|
|
121
|
+
labelKey: z.string().min(1).optional(),
|
|
122
|
+
}),
|
|
123
|
+
z.object({ kind: z.literal('connections') }),
|
|
124
|
+
z.object({ kind: z.literal('agents') }),
|
|
125
|
+
]);
|
|
126
|
+
|
|
127
|
+
export const FieldSpecSchema: z.ZodType<FieldSpec> = z.object({
|
|
128
|
+
key: z.string().min(1),
|
|
129
|
+
label: z.string().min(1),
|
|
130
|
+
type: FieldTypeSchema,
|
|
131
|
+
required: z.boolean(),
|
|
132
|
+
placeholder: z.string().optional(),
|
|
133
|
+
help: z.string().optional(),
|
|
134
|
+
default: FieldValueSchema.optional(),
|
|
135
|
+
options: z.array(FieldOptionSchema).optional(),
|
|
136
|
+
multi: z.boolean().optional(),
|
|
137
|
+
optionsFrom: FieldOptionsFromSchema.optional(),
|
|
138
|
+
pattern: z.object({ regex: z.string(), hint: z.string() }).optional(),
|
|
139
|
+
editable: z.boolean().optional(),
|
|
140
|
+
generated: z.boolean().optional(),
|
|
141
|
+
fields: z.lazy(() => z.array(FieldSpecSchema)).optional(),
|
|
142
|
+
visibleWhen: FieldVisibleWhenSchema.optional(),
|
|
143
|
+
widget: FieldWidgetSchema.optional(),
|
|
144
|
+
collapsible: z.boolean().optional(),
|
|
145
|
+
advanced: z.boolean().optional(),
|
|
146
|
+
columns: z.number().int().min(1).max(4).optional(),
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
export function fieldVisible(field: FieldSpec, values: Record<string, unknown>): boolean {
|
|
150
|
+
const condition = field.visibleWhen;
|
|
151
|
+
if (!condition) {
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
const actual = values[condition.key];
|
|
155
|
+
if (actual === undefined || actual === null) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
if (condition.equals !== undefined) {
|
|
159
|
+
return String(actual) === condition.equals;
|
|
160
|
+
}
|
|
161
|
+
if (condition.oneOf) {
|
|
162
|
+
return condition.oneOf.includes(String(actual));
|
|
163
|
+
}
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export function defaultConfigValues(fields: FieldSpec[]): Record<string, FieldValue> {
|
|
168
|
+
const values: Record<string, FieldValue> = {};
|
|
169
|
+
for (const field of fields) {
|
|
170
|
+
if (field.default !== undefined) {
|
|
171
|
+
values[field.key] = field.default;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return values;
|
|
175
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
export const HOOK_SCHEMA_VERSION = 1;
|
|
4
|
+
|
|
5
|
+
export interface HookDescriptor {
|
|
6
|
+
id: string;
|
|
7
|
+
on: { event: string } | { providerEvent: { connection: string; types?: string[] } };
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const HookOnSchema = z.union([
|
|
11
|
+
z.object({ event: z.string().min(1) }),
|
|
12
|
+
z.object({
|
|
13
|
+
providerEvent: z.object({
|
|
14
|
+
connection: z.string().min(1),
|
|
15
|
+
types: z.array(z.string().min(1)).optional(),
|
|
16
|
+
}),
|
|
17
|
+
}),
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
export const HookDescriptorSchema = z.object({
|
|
21
|
+
id: z.string().min(1),
|
|
22
|
+
on: HookOnSchema,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export const hookFamily = {
|
|
26
|
+
family: 'hook',
|
|
27
|
+
versions: [HOOK_SCHEMA_VERSION],
|
|
28
|
+
schema: (v: number): z.ZodType => {
|
|
29
|
+
if (v !== HOOK_SCHEMA_VERSION) {
|
|
30
|
+
throw new Error(`hook descriptor schema version ${v} is not supported`);
|
|
31
|
+
}
|
|
32
|
+
return HookDescriptorSchema;
|
|
33
|
+
},
|
|
34
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { L10n } from '../manifest/l10n.ts';
|
|
3
|
+
import { L10nSchema } from '../manifest/l10n.ts';
|
|
4
|
+
|
|
5
|
+
export const JOB_SCHEMA_VERSION = 1;
|
|
6
|
+
|
|
7
|
+
export interface JobDescriptor {
|
|
8
|
+
id: string;
|
|
9
|
+
title: L10n;
|
|
10
|
+
schedule: { cron: string } | { everySec: number };
|
|
11
|
+
timezone?: 'org' | 'utc';
|
|
12
|
+
timeoutSec?: number;
|
|
13
|
+
catchUp: 'none' | 'once';
|
|
14
|
+
defaultEnabled?: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const JobScheduleSchema = z.union([
|
|
18
|
+
z.object({ cron: z.string().min(1) }),
|
|
19
|
+
z.object({ everySec: z.number().int().positive() }),
|
|
20
|
+
]);
|
|
21
|
+
|
|
22
|
+
export const JobDescriptorSchema = z.object({
|
|
23
|
+
id: z.string().min(1),
|
|
24
|
+
title: L10nSchema,
|
|
25
|
+
schedule: JobScheduleSchema,
|
|
26
|
+
timezone: z.enum(['org', 'utc']).optional(),
|
|
27
|
+
timeoutSec: z.number().int().positive().optional(),
|
|
28
|
+
catchUp: z.enum(['none', 'once']),
|
|
29
|
+
defaultEnabled: z.boolean().optional(),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export const jobFamily = {
|
|
33
|
+
family: 'job',
|
|
34
|
+
versions: [JOB_SCHEMA_VERSION],
|
|
35
|
+
schema: (v: number): z.ZodType => {
|
|
36
|
+
if (v !== JOB_SCHEMA_VERSION) {
|
|
37
|
+
throw new Error(`job descriptor schema version ${v} is not supported`);
|
|
38
|
+
}
|
|
39
|
+
return JobDescriptorSchema;
|
|
40
|
+
},
|
|
41
|
+
};
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { L10n } from '../manifest/l10n.ts';
|
|
3
|
+
import { L10nSchema } from '../manifest/l10n.ts';
|
|
4
|
+
import type { FieldSpec } from './field-spec.ts';
|
|
5
|
+
import { FieldSpecSchema } from './field-spec.ts';
|
|
6
|
+
import {
|
|
7
|
+
type JsonSchemaSubset,
|
|
8
|
+
JsonSchemaSubsetSchema,
|
|
9
|
+
validateInputSchema,
|
|
10
|
+
} from './json-schema.ts';
|
|
11
|
+
|
|
12
|
+
export const TOOL_PACK_SCHEMA_VERSION = 1;
|
|
13
|
+
|
|
14
|
+
export type ToolEffect = 'read' | 'write' | 'destructive';
|
|
15
|
+
|
|
16
|
+
export interface ToolDescriptor {
|
|
17
|
+
name: string;
|
|
18
|
+
description: L10n;
|
|
19
|
+
inputSchema: JsonSchemaSubset;
|
|
20
|
+
outputSchema?: JsonSchemaSubset;
|
|
21
|
+
effect: ToolEffect;
|
|
22
|
+
idempotent?: boolean;
|
|
23
|
+
timeoutSec?: number;
|
|
24
|
+
maxResultKb?: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface ToolPackDescriptor {
|
|
28
|
+
name: string;
|
|
29
|
+
title: L10n;
|
|
30
|
+
description: L10n;
|
|
31
|
+
icon?: string;
|
|
32
|
+
connection?: string;
|
|
33
|
+
specFields?: FieldSpec[];
|
|
34
|
+
skills?: string[];
|
|
35
|
+
tools: ToolDescriptor[];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const inputSchemaIssues = (descriptor: ToolPackDescriptor, ctx: z.RefinementCtx): void => {
|
|
39
|
+
descriptor.tools.forEach((tool, index) => {
|
|
40
|
+
for (const violation of validateInputSchema(tool.inputSchema)) {
|
|
41
|
+
ctx.addIssue({
|
|
42
|
+
code: 'custom',
|
|
43
|
+
path: ['tools', index, 'inputSchema', violation.path],
|
|
44
|
+
message: `${violation.code}: ${violation.message}`,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
if (tool.outputSchema !== undefined) {
|
|
48
|
+
for (const violation of validateInputSchema(tool.outputSchema)) {
|
|
49
|
+
ctx.addIssue({
|
|
50
|
+
code: 'custom',
|
|
51
|
+
path: ['tools', index, 'outputSchema', violation.path],
|
|
52
|
+
message: `${violation.code}: ${violation.message}`,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const ToolDescriptorSchema = z.object({
|
|
60
|
+
name: z.string().min(1),
|
|
61
|
+
description: L10nSchema,
|
|
62
|
+
inputSchema: JsonSchemaSubsetSchema,
|
|
63
|
+
outputSchema: JsonSchemaSubsetSchema.optional(),
|
|
64
|
+
effect: z.enum(['read', 'write', 'destructive']),
|
|
65
|
+
idempotent: z.boolean().optional(),
|
|
66
|
+
timeoutSec: z.number().int().positive().optional(),
|
|
67
|
+
maxResultKb: z.number().int().positive().optional(),
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
export const ToolPackDescriptorSchema = z
|
|
71
|
+
.object({
|
|
72
|
+
name: z.string().min(1),
|
|
73
|
+
title: L10nSchema,
|
|
74
|
+
description: L10nSchema,
|
|
75
|
+
icon: z.string().optional(),
|
|
76
|
+
connection: z.string().min(1).optional(),
|
|
77
|
+
specFields: z.array(FieldSpecSchema).optional(),
|
|
78
|
+
skills: z.array(z.string().min(1)).optional(),
|
|
79
|
+
tools: z.array(ToolDescriptorSchema).min(1),
|
|
80
|
+
})
|
|
81
|
+
.superRefine(inputSchemaIssues);
|
|
82
|
+
|
|
83
|
+
export const toolPackFamily = {
|
|
84
|
+
family: 'tool-pack',
|
|
85
|
+
versions: [TOOL_PACK_SCHEMA_VERSION],
|
|
86
|
+
schema: (v: number): z.ZodType => {
|
|
87
|
+
if (v !== TOOL_PACK_SCHEMA_VERSION) {
|
|
88
|
+
throw new Error(`tool-pack descriptor schema version ${v} is not supported`);
|
|
89
|
+
}
|
|
90
|
+
return ToolPackDescriptorSchema;
|
|
91
|
+
},
|
|
92
|
+
};
|