@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,178 @@
|
|
|
1
|
+
import type { AddonContext } from './addon-context.ts';
|
|
2
|
+
import type {
|
|
3
|
+
AddonHandlerOf,
|
|
4
|
+
HostToAddonMethods,
|
|
5
|
+
NotificationMethods,
|
|
6
|
+
ParamsOf,
|
|
7
|
+
ResultOf,
|
|
8
|
+
} from './protocol/map.ts';
|
|
9
|
+
|
|
10
|
+
type HostMethodParams<M extends keyof HostToAddonMethods> = ParamsOf<HostToAddonMethods[M]>;
|
|
11
|
+
type HostMethodResult<M extends keyof HostToAddonMethods> = ResultOf<HostToAddonMethods[M]>;
|
|
12
|
+
type NotificationParams<K extends keyof NotificationMethods> = ParamsOf<NotificationMethods[K]>;
|
|
13
|
+
|
|
14
|
+
export type ToolHandler = (
|
|
15
|
+
input: Record<string, unknown>,
|
|
16
|
+
ctx: AddonContext,
|
|
17
|
+
) => unknown | Promise<unknown>;
|
|
18
|
+
|
|
19
|
+
export type RouteHandler = (
|
|
20
|
+
params: Omit<HostMethodParams<'route.handle'>, '_meta'>,
|
|
21
|
+
ctx: AddonContext,
|
|
22
|
+
) => HostMethodResult<'route.handle'> | Promise<HostMethodResult<'route.handle'>>;
|
|
23
|
+
|
|
24
|
+
export interface TriggerPair {
|
|
25
|
+
start(params: HostMethodParams<'trigger.start'>, ctx: AddonContext): Promise<void> | void;
|
|
26
|
+
stop(params: HostMethodParams<'trigger.stop'>, ctx: AddonContext): Promise<void> | void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type JobHandler = (
|
|
30
|
+
params: Omit<HostMethodParams<'job.run'>, '_meta'>,
|
|
31
|
+
ctx: AddonContext,
|
|
32
|
+
) => Promise<void> | void;
|
|
33
|
+
|
|
34
|
+
export interface WorkerPair {
|
|
35
|
+
start(params: HostMethodParams<'worker.start'>, ctx: AddonContext): Promise<void> | void;
|
|
36
|
+
stop(params: HostMethodParams<'worker.stop'>, ctx: AddonContext): Promise<void> | void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type HookHandler = (
|
|
40
|
+
params: Omit<HostMethodParams<'hook.deliver'>, '_meta'>,
|
|
41
|
+
ctx: AddonContext,
|
|
42
|
+
) => Promise<void> | void;
|
|
43
|
+
|
|
44
|
+
export interface TransportHandlers {
|
|
45
|
+
send?(
|
|
46
|
+
params: HostMethodParams<'transport.send'>,
|
|
47
|
+
ctx: AddonContext,
|
|
48
|
+
): Promise<HostMethodResult<'transport.send'>> | HostMethodResult<'transport.send'>;
|
|
49
|
+
edit?(params: HostMethodParams<'transport.edit'>, ctx: AddonContext): Promise<void> | void;
|
|
50
|
+
typing?(params: HostMethodParams<'transport.typing'>, ctx: AddonContext): Promise<void> | void;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface SourceBackendHandlers {
|
|
54
|
+
list(
|
|
55
|
+
params: Omit<HostMethodParams<'source.list'>, '_meta'>,
|
|
56
|
+
ctx: AddonContext,
|
|
57
|
+
): HostMethodResult<'source.list'> | Promise<HostMethodResult<'source.list'>>;
|
|
58
|
+
stat(
|
|
59
|
+
params: Omit<HostMethodParams<'source.stat'>, '_meta'>,
|
|
60
|
+
ctx: AddonContext,
|
|
61
|
+
): HostMethodResult<'source.stat'> | Promise<HostMethodResult<'source.stat'>>;
|
|
62
|
+
download(
|
|
63
|
+
params: Omit<HostMethodParams<'source.download'>, '_meta'>,
|
|
64
|
+
ctx: AddonContext,
|
|
65
|
+
): HostMethodResult<'source.download'> | Promise<HostMethodResult<'source.download'>>;
|
|
66
|
+
upload?(
|
|
67
|
+
params: Omit<HostMethodParams<'source.upload'>, '_meta'>,
|
|
68
|
+
ctx: AddonContext,
|
|
69
|
+
): HostMethodResult<'source.upload'> | Promise<HostMethodResult<'source.upload'>>;
|
|
70
|
+
mkdir?(
|
|
71
|
+
params: Omit<HostMethodParams<'source.mkdir'>, '_meta'>,
|
|
72
|
+
ctx: AddonContext,
|
|
73
|
+
): HostMethodResult<'source.mkdir'> | Promise<HostMethodResult<'source.mkdir'>>;
|
|
74
|
+
remove?(
|
|
75
|
+
params: Omit<HostMethodParams<'source.remove'>, '_meta'>,
|
|
76
|
+
ctx: AddonContext,
|
|
77
|
+
): Promise<void> | void;
|
|
78
|
+
export?(
|
|
79
|
+
params: Omit<HostMethodParams<'source.export'>, '_meta'>,
|
|
80
|
+
ctx: AddonContext,
|
|
81
|
+
): HostMethodResult<'source.export'> | Promise<HostMethodResult<'source.export'>>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface LifecycleHandlers {
|
|
85
|
+
upgrade?(params: HostMethodParams<'lifecycle.upgrade'>, ctx: AddonContext): Promise<void> | void;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface NotificationHandlers {
|
|
89
|
+
'config.changed'?(
|
|
90
|
+
params: NotificationParams<'config.changed'>,
|
|
91
|
+
ctx: AddonContext,
|
|
92
|
+
): Promise<void> | void;
|
|
93
|
+
'permissions.changed'?(
|
|
94
|
+
params: NotificationParams<'permissions.changed'>,
|
|
95
|
+
ctx: AddonContext,
|
|
96
|
+
): Promise<void> | void;
|
|
97
|
+
'accounts.changed'?(
|
|
98
|
+
params: NotificationParams<'accounts.changed'>,
|
|
99
|
+
ctx: AddonContext,
|
|
100
|
+
): Promise<void> | void;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface AddonDefinition {
|
|
104
|
+
tools?: Record<string, ToolHandler>;
|
|
105
|
+
routes?: Record<string, RouteHandler>;
|
|
106
|
+
triggers?: Record<string, TriggerPair>;
|
|
107
|
+
jobs?: Record<string, JobHandler>;
|
|
108
|
+
workers?: Record<string, WorkerPair>;
|
|
109
|
+
hooks?: Record<string, HookHandler>;
|
|
110
|
+
transport?: TransportHandlers;
|
|
111
|
+
sources?: Record<string, SourceBackendHandlers>;
|
|
112
|
+
lifecycle?: LifecycleHandlers;
|
|
113
|
+
notifications?: NotificationHandlers;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface ResolvedAddonDefinition extends AddonDefinition {
|
|
117
|
+
readonly handlers: string[];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function deriveHandlers(definition: AddonDefinition): string[] {
|
|
121
|
+
const handlers = ['ping', 'shutdown'];
|
|
122
|
+
const hasKeys = (value: Record<string, unknown> | undefined): boolean =>
|
|
123
|
+
value !== undefined && Object.keys(value).length > 0;
|
|
124
|
+
if (hasKeys(definition.tools)) {
|
|
125
|
+
handlers.push('tools.call');
|
|
126
|
+
}
|
|
127
|
+
if (hasKeys(definition.routes)) {
|
|
128
|
+
handlers.push('route.handle');
|
|
129
|
+
}
|
|
130
|
+
if (hasKeys(definition.triggers)) {
|
|
131
|
+
handlers.push('trigger.start', 'trigger.stop');
|
|
132
|
+
}
|
|
133
|
+
if (hasKeys(definition.jobs)) {
|
|
134
|
+
handlers.push('job.run');
|
|
135
|
+
}
|
|
136
|
+
if (hasKeys(definition.workers)) {
|
|
137
|
+
handlers.push('worker.start', 'worker.stop');
|
|
138
|
+
}
|
|
139
|
+
if (definition.transport?.send !== undefined) {
|
|
140
|
+
handlers.push('transport.send');
|
|
141
|
+
}
|
|
142
|
+
if (definition.transport?.edit !== undefined) {
|
|
143
|
+
handlers.push('transport.edit');
|
|
144
|
+
}
|
|
145
|
+
if (definition.transport?.typing !== undefined) {
|
|
146
|
+
handlers.push('transport.typing');
|
|
147
|
+
}
|
|
148
|
+
if (hasKeys(definition.hooks)) {
|
|
149
|
+
handlers.push('hook.deliver');
|
|
150
|
+
}
|
|
151
|
+
handlers.push(...sourceHandlerNames(definition.sources));
|
|
152
|
+
if (definition.lifecycle?.upgrade !== undefined) {
|
|
153
|
+
handlers.push('lifecycle.upgrade');
|
|
154
|
+
}
|
|
155
|
+
return handlers;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function sourceHandlerNames(sources: Record<string, SourceBackendHandlers> | undefined): string[] {
|
|
159
|
+
if (sources === undefined || Object.keys(sources).length === 0) {
|
|
160
|
+
return [];
|
|
161
|
+
}
|
|
162
|
+
const names = ['source.list', 'source.stat', 'source.download'];
|
|
163
|
+
const implementations = Object.values(sources);
|
|
164
|
+
const anyOp = (op: keyof SourceBackendHandlers): boolean =>
|
|
165
|
+
implementations.some((backend) => backend[op] !== undefined);
|
|
166
|
+
for (const op of ['upload', 'mkdir', 'remove', 'export'] as const) {
|
|
167
|
+
if (anyOp(op)) {
|
|
168
|
+
names.push(`source.${op}`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return names;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function defineAddon(definition: AddonDefinition): ResolvedAddonDefinition {
|
|
175
|
+
return { ...definition, handlers: deriveHandlers(definition) };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export type { AddonHandlerOf };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { FieldSpec } from './field-spec.ts';
|
|
3
|
+
import { FieldSpecSchema } from './field-spec.ts';
|
|
4
|
+
|
|
5
|
+
export const CONFIG_SCHEMA_VERSION = 1;
|
|
6
|
+
|
|
7
|
+
export interface ConfigDescriptor {
|
|
8
|
+
fields: FieldSpec[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const ConfigDescriptorSchema = z.object({
|
|
12
|
+
fields: z.array(FieldSpecSchema),
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export const configFamily = {
|
|
16
|
+
family: 'config',
|
|
17
|
+
versions: [CONFIG_SCHEMA_VERSION],
|
|
18
|
+
schema: (v: number): z.ZodType => {
|
|
19
|
+
if (v !== CONFIG_SCHEMA_VERSION) {
|
|
20
|
+
throw new Error(`config descriptor schema version ${v} is not supported`);
|
|
21
|
+
}
|
|
22
|
+
return ConfigDescriptorSchema;
|
|
23
|
+
},
|
|
24
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { L10n } from '../manifest/l10n.ts';
|
|
3
|
+
import { L10nSchema } from '../manifest/l10n.ts';
|
|
4
|
+
|
|
5
|
+
export const CONTENT_SCHEMA_VERSION = 1;
|
|
6
|
+
|
|
7
|
+
export interface ContentDescriptor {
|
|
8
|
+
id: string;
|
|
9
|
+
title: L10n;
|
|
10
|
+
kind: 'skill' | 'prompt';
|
|
11
|
+
/**
|
|
12
|
+
* Path from the package root. For `kind: 'skill'` it is the skill directory
|
|
13
|
+
* (containing `SKILL.md` and its `references/`); a path to a single markdown
|
|
14
|
+
* file is still accepted for backward compatibility.
|
|
15
|
+
*/
|
|
16
|
+
path: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const ContentDescriptorSchema = z.object({
|
|
20
|
+
id: z.string().min(1),
|
|
21
|
+
title: L10nSchema,
|
|
22
|
+
kind: z.enum(['skill', 'prompt']),
|
|
23
|
+
path: z.string().min(1),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export const contentFamily = {
|
|
27
|
+
family: 'content',
|
|
28
|
+
versions: [CONTENT_SCHEMA_VERSION],
|
|
29
|
+
schema: (v: number): z.ZodType => {
|
|
30
|
+
if (v !== CONTENT_SCHEMA_VERSION) {
|
|
31
|
+
throw new Error(`content descriptor schema version ${v} is not supported`);
|
|
32
|
+
}
|
|
33
|
+
return ContentDescriptorSchema;
|
|
34
|
+
},
|
|
35
|
+
};
|
|
@@ -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
|
+
};
|