@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.
Files changed (147) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +80 -2
  3. package/dist/addon-context-factory.d.ts +6 -0
  4. package/dist/addon-context-factory.js +160 -0
  5. package/dist/addon-context.d.ts +346 -0
  6. package/dist/addon-context.js +0 -0
  7. package/dist/define-addon.d.ts +57 -0
  8. package/dist/define-addon.js +53 -0
  9. package/dist/families/config.d.ts +14 -0
  10. package/dist/families/config.js +16 -0
  11. package/dist/families/content.d.ts +28 -0
  12. package/dist/families/content.js +19 -0
  13. package/dist/families/field-spec.d.ts +100 -0
  14. package/dist/families/field-spec.js +85 -0
  15. package/dist/families/hook.d.ts +37 -0
  16. package/dist/families/hook.js +25 -0
  17. package/dist/families/job.d.ts +45 -0
  18. package/dist/families/job.js +26 -0
  19. package/dist/families/json-schema-value.d.ts +12 -0
  20. package/dist/families/json-schema-value.js +243 -0
  21. package/dist/families/json-schema.d.ts +36 -0
  22. package/dist/families/json-schema.js +101 -0
  23. package/dist/families/lsp.d.ts +18 -0
  24. package/dist/families/lsp.js +18 -0
  25. package/dist/families/mcp.d.ts +18 -0
  26. package/dist/families/mcp.js +18 -0
  27. package/dist/families/registry.d.ts +9 -0
  28. package/dist/families/registry.js +34 -0
  29. package/dist/families/route.d.ts +38 -0
  30. package/dist/families/route.js +37 -0
  31. package/dist/families/source-kind.d.ts +24 -0
  32. package/dist/families/source-kind.js +21 -0
  33. package/dist/families/tool-pack.d.ts +68 -0
  34. package/dist/families/tool-pack.js +57 -0
  35. package/dist/families/transport.d.ts +52 -0
  36. package/dist/families/transport.js +29 -0
  37. package/dist/families/trigger.d.ts +97 -0
  38. package/dist/families/trigger.js +46 -0
  39. package/dist/families/view.d.ts +255 -0
  40. package/dist/families/view.js +87 -0
  41. package/dist/families/viewer.d.ts +31 -0
  42. package/dist/families/viewer.js +26 -0
  43. package/dist/families/worker.d.ts +23 -0
  44. package/dist/families/worker.js +19 -0
  45. package/dist/host-client.d.ts +11 -0
  46. package/dist/host-client.js +30 -0
  47. package/dist/index.d.ts +36 -0
  48. package/dist/index.js +36 -0
  49. package/dist/manifest/branding.d.ts +14 -0
  50. package/dist/manifest/branding.js +18 -0
  51. package/dist/manifest/connections.d.ts +21 -0
  52. package/dist/manifest/connections.js +10 -0
  53. package/dist/manifest/json-schema.d.ts +2 -0
  54. package/dist/manifest/json-schema.js +13 -0
  55. package/dist/manifest/l10n.d.ts +9 -0
  56. package/dist/manifest/l10n.js +28 -0
  57. package/dist/manifest/manifest.d.ts +112 -0
  58. package/dist/manifest/manifest.js +45 -0
  59. package/dist/manifest/validate.d.ts +14 -0
  60. package/dist/manifest/validate.js +144 -0
  61. package/dist/permissions/permissions.d.ts +31 -0
  62. package/dist/permissions/permissions.js +53 -0
  63. package/dist/process-entry.d.ts +26 -0
  64. package/dist/process-entry.js +146 -0
  65. package/dist/protocol/envelope.d.ts +115 -0
  66. package/dist/protocol/envelope.js +72 -0
  67. package/dist/protocol/error.d.ts +67 -0
  68. package/dist/protocol/error.js +61 -0
  69. package/dist/protocol/handshake.d.ts +55 -0
  70. package/dist/protocol/handshake.js +26 -0
  71. package/dist/protocol/map.d.ts +1090 -0
  72. package/dist/protocol/map.js +127 -0
  73. package/dist/protocol/meta.d.ts +31 -0
  74. package/dist/protocol/meta.js +14 -0
  75. package/dist/protocol/method-spec.d.ts +13 -0
  76. package/dist/protocol/method-spec.js +9 -0
  77. package/dist/protocol/org-service-methods.d.ts +135 -0
  78. package/dist/protocol/org-service-methods.js +106 -0
  79. package/dist/protocol/shared.d.ts +389 -0
  80. package/dist/protocol/shared.js +231 -0
  81. package/dist/protocol/source-methods.d.ts +218 -0
  82. package/dist/protocol/source-methods.js +18 -0
  83. package/dist/protocol/thread-service-methods.d.ts +50 -0
  84. package/dist/protocol/thread-service-methods.js +32 -0
  85. package/dist/runtime.d.ts +25 -0
  86. package/dist/runtime.js +229 -0
  87. package/dist/testing/fake-db.d.ts +15 -0
  88. package/dist/testing/fake-db.js +120 -0
  89. package/dist/testing/fake-files.d.ts +9 -0
  90. package/dist/testing/fake-files.js +87 -0
  91. package/dist/testing/fake-host.d.ts +115 -0
  92. package/dist/testing/fake-host.js +217 -0
  93. package/dist/testing/fake-services.d.ts +63 -0
  94. package/dist/testing/fake-services.js +277 -0
  95. package/dist/testing/fixtures.d.ts +5 -0
  96. package/dist/testing/fixtures.js +101 -0
  97. package/dist/testing/index.d.ts +4 -0
  98. package/dist/testing/index.js +2 -0
  99. package/package.json +66 -4
  100. package/src/addon-context-factory.ts +236 -0
  101. package/src/addon-context.ts +313 -0
  102. package/src/define-addon.ts +178 -0
  103. package/src/families/config.ts +24 -0
  104. package/src/families/content.ts +35 -0
  105. package/src/families/field-spec.ts +175 -0
  106. package/src/families/hook.ts +34 -0
  107. package/src/families/job.ts +41 -0
  108. package/src/families/json-schema-value.ts +322 -0
  109. package/src/families/json-schema.ts +167 -0
  110. package/src/families/lsp.ts +28 -0
  111. package/src/families/mcp.ts +28 -0
  112. package/src/families/registry.ts +44 -0
  113. package/src/families/route.ts +52 -0
  114. package/src/families/source-kind.ts +34 -0
  115. package/src/families/tool-pack.ts +92 -0
  116. package/src/families/transport.ts +52 -0
  117. package/src/families/trigger.ts +92 -0
  118. package/src/families/view.ts +144 -0
  119. package/src/families/viewer.ts +43 -0
  120. package/src/families/worker.ts +30 -0
  121. package/src/host-client.ts +52 -0
  122. package/src/index.ts +345 -0
  123. package/src/manifest/branding.ts +24 -0
  124. package/src/manifest/connections.ts +21 -0
  125. package/src/manifest/json-schema.ts +24 -0
  126. package/src/manifest/l10n.ts +39 -0
  127. package/src/manifest/manifest.ts +94 -0
  128. package/src/manifest/validate.ts +200 -0
  129. package/src/permissions/permissions.ts +79 -0
  130. package/src/process-entry.ts +205 -0
  131. package/src/protocol/envelope.ts +126 -0
  132. package/src/protocol/error.ts +81 -0
  133. package/src/protocol/handshake.ts +43 -0
  134. package/src/protocol/map.ts +339 -0
  135. package/src/protocol/meta.ts +26 -0
  136. package/src/protocol/method-spec.ts +40 -0
  137. package/src/protocol/org-service-methods.ts +148 -0
  138. package/src/protocol/shared.ts +345 -0
  139. package/src/protocol/source-methods.ts +61 -0
  140. package/src/protocol/thread-service-methods.ts +50 -0
  141. package/src/runtime.ts +332 -0
  142. package/src/testing/fake-db.ts +140 -0
  143. package/src/testing/fake-files.ts +114 -0
  144. package/src/testing/fake-host.ts +350 -0
  145. package/src/testing/fake-services.ts +345 -0
  146. package/src/testing/fixtures.ts +106 -0
  147. package/src/testing/index.ts +12 -0
@@ -0,0 +1,236 @@
1
+ import type {
2
+ AddonConfig,
3
+ AddonContext,
4
+ AddonDb,
5
+ AddonEvents,
6
+ AddonFiles,
7
+ AddonHttp,
8
+ AddonLog,
9
+ AddonLogLevel,
10
+ AddonSecrets,
11
+ DbStatement,
12
+ DbWriteResult,
13
+ SqlParam,
14
+ } from './addon-context.ts';
15
+ import type { HostServiceClient } from './protocol/map.ts';
16
+ import type { CallMeta } from './protocol/meta.ts';
17
+
18
+ export type {
19
+ AddonAccounts,
20
+ AddonApprovals,
21
+ AddonBindings,
22
+ AddonBridge,
23
+ AddonConfig,
24
+ AddonContext,
25
+ AddonDb,
26
+ AddonEvents,
27
+ AddonFileChunk,
28
+ AddonFileStat,
29
+ AddonFiles,
30
+ AddonFileWriteResult,
31
+ AddonHttp,
32
+ AddonInboundAttachment,
33
+ AddonLog,
34
+ AddonLogLevel,
35
+ AddonOrg,
36
+ AddonProgress,
37
+ AddonRuns,
38
+ AddonSecrets,
39
+ AddonSkills,
40
+ AddonThreads,
41
+ AddonTriggerField,
42
+ AddonTriggers,
43
+ AddonTriggerTarget,
44
+ AddonUsage,
45
+ AddonWorkers,
46
+ DbRow,
47
+ DbStatement,
48
+ DbWriteResult,
49
+ SqlParam,
50
+ } from './addon-context.ts';
51
+
52
+ function createDb(client: HostServiceClient, _meta: CallMeta, signal: AbortSignal): AddonDb {
53
+ const track = async <T>(promise: Promise<T>): Promise<T> => {
54
+ if (signal.aborted) {
55
+ throw new Error('cancelled');
56
+ }
57
+ return promise;
58
+ };
59
+ return {
60
+ exec: async (sql: string) => {
61
+ await track(client['db.exec']({ sql }, { signal }));
62
+ },
63
+ all: async (sql: string, params?: SqlParam[]) => {
64
+ const result = await track(client['db.all']({ sql, params }, { signal }));
65
+ return result.rows;
66
+ },
67
+ get: async (sql: string, params?: SqlParam[]) => {
68
+ const result = await track(client['db.get']({ sql, params }, { signal }));
69
+ return result.row;
70
+ },
71
+ run: async (sql: string, params?: SqlParam[]): Promise<DbWriteResult> => {
72
+ const result = await track(client['db.run']({ sql, params }, { signal }));
73
+ return { changes: result.changes, lastInsertRowid: result.lastInsertRowid };
74
+ },
75
+ batch: async (statements: DbStatement[]): Promise<DbWriteResult[]> => {
76
+ const result = await track(client['db.batch']({ statements }, { signal }));
77
+ return result.results.map((entry) => ({
78
+ changes: entry.changes,
79
+ lastInsertRowid: entry.lastInsertRowid,
80
+ }));
81
+ },
82
+ };
83
+ }
84
+
85
+ function createLog(
86
+ client: HostServiceClient,
87
+ level: AddonLogLevel,
88
+ ): (message: string, fields?: Record<string, unknown>) => Promise<void> {
89
+ return async (message, fields) => {
90
+ await client['log.write']({ level, message, fields });
91
+ };
92
+ }
93
+
94
+ export type ProgressNotify = (method: string, params: unknown) => void;
95
+
96
+ export function createAddonContext(
97
+ client: HostServiceClient,
98
+ meta: CallMeta,
99
+ signal: AbortSignal,
100
+ notify?: ProgressNotify,
101
+ ): AddonContext {
102
+ const config: AddonConfig = {
103
+ get: async (keys?: string[]) => {
104
+ const result = await client['config.get']({ keys }, { signal });
105
+ return result.values;
106
+ },
107
+ };
108
+ const secrets: AddonSecrets = {
109
+ get: async (key: string) => {
110
+ const result = await client['secrets.get']({ key }, { signal });
111
+ return result.value;
112
+ },
113
+ set: async (key: string, value: string) => {
114
+ await client['secrets.set']({ key, value }, { signal });
115
+ },
116
+ delete: async (key: string) => {
117
+ await client['secrets.delete']({ key }, { signal });
118
+ },
119
+ };
120
+ const log: AddonLog = {
121
+ debug: createLog(client, 'debug'),
122
+ info: createLog(client, 'info'),
123
+ warn: createLog(client, 'warn'),
124
+ error: createLog(client, 'error'),
125
+ };
126
+ const events: AddonEvents = {
127
+ emit: async (name: string, payload: unknown) => {
128
+ await client['events.emit']({ name, payload }, { signal });
129
+ },
130
+ };
131
+ const http: AddonHttp = {
132
+ fetch: async (params) =>
133
+ client['http.fetch']({ ...params, method: params.method ?? 'GET' }, { signal }),
134
+ };
135
+ const files: AddonFiles = {
136
+ stat: async (path: string) => client['files.stat']({ path }, { signal }),
137
+ read: async (params) => client['files.read'](params, { signal }),
138
+ write: async (params) => client['files.write'](params, { signal }),
139
+ };
140
+ const bindings = {
141
+ channels: async (provider?: string) => {
142
+ const result = await client['bindings.channels']({ provider }, { signal });
143
+ return result.channels;
144
+ },
145
+ bind: async (params: { provider: string; channel: string; threadId: string }) =>
146
+ client['bindings.bind'](params, { signal }),
147
+ unbind: async (params: { provider: string; channel: string }) =>
148
+ client['bindings.unbind'](params, { signal }),
149
+ };
150
+ const accounts = {
151
+ list: async (connection: string) => {
152
+ const result = await client['accounts.list']({ connection }, { signal });
153
+ return result.accounts;
154
+ },
155
+ report: async (connection: string, code: string, accountId?: string) => {
156
+ await client['accounts.report']({ connection, code, accountId }, { signal });
157
+ },
158
+ access: async (connection: string, accountId?: string) => {
159
+ const result = await client['accounts.access']({ connection, accountId }, { signal });
160
+ return { credentials: result.credentials, expiresAt: result.expiresAt, app: result.app };
161
+ },
162
+ };
163
+ return {
164
+ meta,
165
+ signal,
166
+ config,
167
+ secrets,
168
+ db: createDb(client, meta, signal),
169
+ log,
170
+ events,
171
+ http,
172
+ files,
173
+ accounts,
174
+ bindings,
175
+ runs: {
176
+ dispatch: async (params) => client['runs.dispatch'](params, { signal }),
177
+ cancel: async (params) => client['runs.cancel'](params, { signal }),
178
+ list: async (params) => (await client['runs.list'](params, { signal })).runs,
179
+ },
180
+ threads: {
181
+ create: async (params: {
182
+ title?: string;
183
+ agentId: string;
184
+ kind?: 'chat' | 'group';
185
+ responderMode?: 'auto' | 'mention';
186
+ }) => client['threads.create'](params, { signal }),
187
+ get: async (params: { threadId: string }) =>
188
+ (await client['threads.get'](params, { signal })).thread ?? null,
189
+ patch: async (params: { threadId: string; responderMode?: 'auto' | 'mention' }) => {
190
+ await client['threads.patch'](params, { signal });
191
+ },
192
+ compact: async (params: { threadId: string }) =>
193
+ client['threads.compact'](params, { signal }),
194
+ },
195
+ agents: {
196
+ list: async () => (await client['agents.list']({}, { signal })).agents,
197
+ },
198
+ usage: {
199
+ summary: async (params: { threadId?: string; since?: string }) =>
200
+ client['usage.summary'](params, { signal }),
201
+ },
202
+ skills: {
203
+ list: async (params: { threadId?: string }) =>
204
+ (await client['skills.list'](params, { signal })).skills,
205
+ },
206
+ triggers: {
207
+ fire: async (params) => client['triggers.fire'](params, { signal }),
208
+ create: async (params) => client['triggers.create'](params, { signal }),
209
+ update: async (params) => client['triggers.update'](params, { signal }),
210
+ },
211
+ bridge: {
212
+ inbound: async (message) => (await client['bridge.inbound']({ message }, { signal })).outcome,
213
+ },
214
+ progress: {
215
+ progress: (token: string, value: unknown) => {
216
+ notify?.('$/progress', { token, value });
217
+ },
218
+ },
219
+ workers: {
220
+ report: async (workerId: string, state: 'running' | 'stopped' | 'failed', code?: string) => {
221
+ await client['workers.report']({ workerId, state, code }, { signal });
222
+ },
223
+ lease: async (workerId: string, ttlMs?: number) =>
224
+ client['workers.lease']({ workerId, ttlMs }, { signal }),
225
+ release: async (workerId: string) => {
226
+ await client['workers.release']({ workerId }, { signal });
227
+ },
228
+ },
229
+ org: {
230
+ settings: async () => client['org.settings.get']({}, { signal }),
231
+ },
232
+ approvals: {
233
+ request: async (params) => client['approvals.request'](params, { signal }),
234
+ },
235
+ };
236
+ }
@@ -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
+ }