@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,313 @@
|
|
|
1
|
+
import type { CallMeta } from './protocol/meta.ts';
|
|
2
|
+
import type { AppCredentials, BridgeInboundOutcome } from './protocol/shared.ts';
|
|
3
|
+
|
|
4
|
+
export type DbRow = Record<string, unknown>;
|
|
5
|
+
export type SqlParam = string | number | boolean | null;
|
|
6
|
+
export interface DbStatement {
|
|
7
|
+
sql: string;
|
|
8
|
+
params?: SqlParam[];
|
|
9
|
+
}
|
|
10
|
+
export interface DbWriteResult {
|
|
11
|
+
changes: number;
|
|
12
|
+
lastInsertRowid: string | number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface AddonDb {
|
|
16
|
+
exec(sql: string): Promise<void>;
|
|
17
|
+
all(sql: string, params?: SqlParam[]): Promise<DbRow[]>;
|
|
18
|
+
get(sql: string, params?: SqlParam[]): Promise<DbRow | null>;
|
|
19
|
+
run(sql: string, params?: SqlParam[]): Promise<DbWriteResult>;
|
|
20
|
+
batch(statements: DbStatement[]): Promise<DbWriteResult[]>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface AddonSecrets {
|
|
24
|
+
get(key: string): Promise<string | null>;
|
|
25
|
+
set(key: string, value: string): Promise<void>;
|
|
26
|
+
delete(key: string): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface AddonConfig {
|
|
30
|
+
get(keys?: string[]): Promise<Record<string, unknown>>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type AddonLogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
34
|
+
|
|
35
|
+
export interface AddonLog {
|
|
36
|
+
debug(message: string, fields?: Record<string, unknown>): Promise<void>;
|
|
37
|
+
info(message: string, fields?: Record<string, unknown>): Promise<void>;
|
|
38
|
+
warn(message: string, fields?: Record<string, unknown>): Promise<void>;
|
|
39
|
+
error(message: string, fields?: Record<string, unknown>): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface AddonEvents {
|
|
43
|
+
emit(name: string, payload: unknown): Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface AddonHttp {
|
|
47
|
+
fetch(params: {
|
|
48
|
+
url: string;
|
|
49
|
+
method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD';
|
|
50
|
+
headers?: Record<string, string>;
|
|
51
|
+
body?: string;
|
|
52
|
+
bodyBase64?: string;
|
|
53
|
+
responseEncoding?: 'text' | 'base64';
|
|
54
|
+
auth?: {
|
|
55
|
+
connection: string;
|
|
56
|
+
accountId?: string;
|
|
57
|
+
scheme: 'bearer' | 'basic' | 'header' | 'path';
|
|
58
|
+
credentialKey?: string;
|
|
59
|
+
header?: string;
|
|
60
|
+
placeholder?: string;
|
|
61
|
+
};
|
|
62
|
+
}): Promise<{
|
|
63
|
+
status: number;
|
|
64
|
+
headers: Record<string, string>;
|
|
65
|
+
body: string | null;
|
|
66
|
+
bodyBase64?: string;
|
|
67
|
+
}>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface AddonFileStat {
|
|
71
|
+
path: string;
|
|
72
|
+
name: string;
|
|
73
|
+
size: number;
|
|
74
|
+
mediaType: string;
|
|
75
|
+
modifiedAt: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface AddonFileChunk {
|
|
79
|
+
data: string;
|
|
80
|
+
eof: boolean;
|
|
81
|
+
size: number;
|
|
82
|
+
mediaType: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface AddonFileWriteResult {
|
|
86
|
+
path: string;
|
|
87
|
+
size: number;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface AddonFiles {
|
|
91
|
+
stat(path: string): Promise<AddonFileStat>;
|
|
92
|
+
read(params: { path: string; offset?: number; length?: number }): Promise<AddonFileChunk>;
|
|
93
|
+
write(params: { path: string; data: string; append?: boolean }): Promise<AddonFileWriteResult>;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface AddonBindings {
|
|
97
|
+
channels(
|
|
98
|
+
provider?: string,
|
|
99
|
+
): Promise<Array<{ provider: string; channel: string; threadId: string; createdAt: string }>>;
|
|
100
|
+
bind(params: { provider: string; channel: string; threadId: string }): Promise<{ ok: true }>;
|
|
101
|
+
unbind(params: { provider: string; channel: string }): Promise<{ ok: true }>;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface AddonAccounts {
|
|
105
|
+
list(
|
|
106
|
+
connection: string,
|
|
107
|
+
): Promise<
|
|
108
|
+
Array<{ accountId: string; label: string; externalAccountId: string; status: string }>
|
|
109
|
+
>;
|
|
110
|
+
report(connection: string, code: string, accountId?: string): Promise<void>;
|
|
111
|
+
access(
|
|
112
|
+
connection: string,
|
|
113
|
+
accountId?: string,
|
|
114
|
+
): Promise<{ credentials: unknown; expiresAt?: string; app?: AppCredentials | null }>;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface AddonRuns {
|
|
118
|
+
dispatch(params: {
|
|
119
|
+
threadId?: string;
|
|
120
|
+
agentId?: string;
|
|
121
|
+
input: string;
|
|
122
|
+
}): Promise<{ runId: string }>;
|
|
123
|
+
cancel(params: { threadId: string; runId: string }): Promise<{ ok: true }>;
|
|
124
|
+
list(params: {
|
|
125
|
+
threadId: string;
|
|
126
|
+
status?: string;
|
|
127
|
+
}): Promise<
|
|
128
|
+
Array<{ runId: string; status: string; startedAt: string | null; agentId: string | null }>
|
|
129
|
+
>;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface AddonThreadView {
|
|
133
|
+
threadId: string;
|
|
134
|
+
kind: string;
|
|
135
|
+
title: string;
|
|
136
|
+
responderMode: 'auto' | 'mention';
|
|
137
|
+
autoReplyAgentId: string | null;
|
|
138
|
+
agents: Array<{ id: string; name: string }>;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export interface AddonThreads {
|
|
142
|
+
create(params: {
|
|
143
|
+
title?: string;
|
|
144
|
+
agentId: string;
|
|
145
|
+
kind?: 'chat' | 'group';
|
|
146
|
+
responderMode?: 'auto' | 'mention';
|
|
147
|
+
}): Promise<{ threadId: string }>;
|
|
148
|
+
get(params: { threadId: string }): Promise<AddonThreadView | null>;
|
|
149
|
+
patch(params: { threadId: string; responderMode?: 'auto' | 'mention' }): Promise<void>;
|
|
150
|
+
compact(params: { threadId: string }): Promise<
|
|
151
|
+
| {
|
|
152
|
+
compacted: true;
|
|
153
|
+
id: string;
|
|
154
|
+
coveredFrom: number;
|
|
155
|
+
coveredUntil: number;
|
|
156
|
+
tokensBefore: number;
|
|
157
|
+
tokensAfter: number;
|
|
158
|
+
}
|
|
159
|
+
| { compacted: false; reason?: string }
|
|
160
|
+
>;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export interface AddonAgentView {
|
|
164
|
+
id: string;
|
|
165
|
+
name: string;
|
|
166
|
+
status?: string;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export interface AddonAgents {
|
|
170
|
+
list(): Promise<AddonAgentView[]>;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export interface AddonUsage {
|
|
174
|
+
summary(params: { threadId?: string; since?: string }): Promise<{
|
|
175
|
+
inputTokens: number;
|
|
176
|
+
outputTokens: number;
|
|
177
|
+
costUsd: number;
|
|
178
|
+
byModel: Array<{
|
|
179
|
+
model: string;
|
|
180
|
+
inputTokens: number;
|
|
181
|
+
outputTokens: number;
|
|
182
|
+
costUsd: number;
|
|
183
|
+
}>;
|
|
184
|
+
}>;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export interface AddonSkills {
|
|
188
|
+
list(params: {
|
|
189
|
+
threadId?: string;
|
|
190
|
+
}): Promise<Array<{ id: string; name: string; description: string | null; source: string }>>;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export interface AddonTriggerTarget {
|
|
194
|
+
threadId: string;
|
|
195
|
+
agentId: string;
|
|
196
|
+
modeId?: string;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export interface AddonTriggerField {
|
|
200
|
+
label: string;
|
|
201
|
+
value: string;
|
|
202
|
+
href?: string;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export interface AddonTriggers {
|
|
206
|
+
fire(params: {
|
|
207
|
+
instanceId: string;
|
|
208
|
+
runKey: string;
|
|
209
|
+
text?: string;
|
|
210
|
+
title?: string;
|
|
211
|
+
fields?: AddonTriggerField[];
|
|
212
|
+
payload?: unknown;
|
|
213
|
+
}): Promise<{ outcome: 'fired' | 'suppressed' | 'busy' | 'failed'; runId?: string | null }>;
|
|
214
|
+
create(params: {
|
|
215
|
+
kind: string;
|
|
216
|
+
label: string;
|
|
217
|
+
config: Record<string, unknown>;
|
|
218
|
+
target: AddonTriggerTarget;
|
|
219
|
+
instructions?: string;
|
|
220
|
+
}): Promise<{ instanceId: string }>;
|
|
221
|
+
update(params: {
|
|
222
|
+
instanceId: string;
|
|
223
|
+
label?: string;
|
|
224
|
+
config?: Record<string, unknown>;
|
|
225
|
+
target?: AddonTriggerTarget;
|
|
226
|
+
instructions?: string;
|
|
227
|
+
enabled?: boolean;
|
|
228
|
+
}): Promise<{ instanceId: string }>;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export interface AddonOrg {
|
|
232
|
+
settings(): Promise<{ timezone: string }>;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export interface AddonApprovals {
|
|
236
|
+
request(params: {
|
|
237
|
+
interruptId: string;
|
|
238
|
+
agentId: string;
|
|
239
|
+
threadId?: string;
|
|
240
|
+
kind: 'tool' | 'spend' | 'memory' | 'question' | 'file_access';
|
|
241
|
+
question: string;
|
|
242
|
+
options: Array<'approve' | 'approve_once' | 'deny' | 'block_path' | 'close'>;
|
|
243
|
+
context: {
|
|
244
|
+
source: string;
|
|
245
|
+
ops?: string[];
|
|
246
|
+
tool?: {
|
|
247
|
+
name: string;
|
|
248
|
+
inputPreview?: string;
|
|
249
|
+
command?: string;
|
|
250
|
+
truncated?: boolean;
|
|
251
|
+
};
|
|
252
|
+
note?: string;
|
|
253
|
+
};
|
|
254
|
+
}): Promise<{ id: string }>;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export interface AddonInboundAttachment {
|
|
258
|
+
name: string;
|
|
259
|
+
mediaType?: string;
|
|
260
|
+
path?: string;
|
|
261
|
+
dataBase64?: string;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export interface AddonProgress {
|
|
265
|
+
progress(token: string, value: unknown): void;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export interface AddonBridge {
|
|
269
|
+
inbound(message: {
|
|
270
|
+
channel: string;
|
|
271
|
+
from?: string;
|
|
272
|
+
text: string;
|
|
273
|
+
payload?: unknown;
|
|
274
|
+
attachments?: AddonInboundAttachment[];
|
|
275
|
+
}): Promise<BridgeInboundOutcome>;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export interface AddonWorkerLease {
|
|
279
|
+
held: boolean;
|
|
280
|
+
epoch: number;
|
|
281
|
+
expiresAt: string | null;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export interface AddonWorkers {
|
|
285
|
+
report(workerId: string, state: 'running' | 'stopped' | 'failed', code?: string): Promise<void>;
|
|
286
|
+
lease(workerId: string, ttlMs?: number): Promise<AddonWorkerLease>;
|
|
287
|
+
release(workerId: string): Promise<void>;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export interface AddonContext {
|
|
291
|
+
readonly meta: CallMeta;
|
|
292
|
+
readonly signal: AbortSignal;
|
|
293
|
+
readonly config: AddonConfig;
|
|
294
|
+
readonly secrets: AddonSecrets;
|
|
295
|
+
readonly db: AddonDb;
|
|
296
|
+
readonly log: AddonLog;
|
|
297
|
+
readonly events: AddonEvents;
|
|
298
|
+
readonly http: AddonHttp;
|
|
299
|
+
readonly files: AddonFiles;
|
|
300
|
+
readonly accounts: AddonAccounts;
|
|
301
|
+
readonly bindings: AddonBindings;
|
|
302
|
+
readonly runs: AddonRuns;
|
|
303
|
+
readonly threads: AddonThreads;
|
|
304
|
+
readonly agents: AddonAgents;
|
|
305
|
+
readonly usage: AddonUsage;
|
|
306
|
+
readonly skills: AddonSkills;
|
|
307
|
+
readonly triggers: AddonTriggers;
|
|
308
|
+
readonly bridge: AddonBridge;
|
|
309
|
+
readonly workers: AddonWorkers;
|
|
310
|
+
readonly org: AddonOrg;
|
|
311
|
+
readonly approvals: AddonApprovals;
|
|
312
|
+
readonly progress: AddonProgress;
|
|
313
|
+
}
|
|
@@ -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
|
+
};
|