@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,277 @@
|
|
|
1
|
+
import { isBaselinePermissionId } from "../permissions/permissions.js";
|
|
2
|
+
import { AddonError } from "../protocol/error.js";
|
|
3
|
+
import { executeFilesService } from "./fake-files.js";
|
|
4
|
+
export function createFakeServices(context) {
|
|
5
|
+
const grants = context.options.grants ??
|
|
6
|
+
context.manifest.permissions.map((p) => ({ id: p.id, scope: p.scope }));
|
|
7
|
+
function granted(permission) {
|
|
8
|
+
if (isBaselinePermissionId(permission)) {
|
|
9
|
+
return { id: permission };
|
|
10
|
+
}
|
|
11
|
+
if (permission === 'trigger' &&
|
|
12
|
+
context.manifest.contributions.some((c) => c.family === 'trigger')) {
|
|
13
|
+
return { id: permission };
|
|
14
|
+
}
|
|
15
|
+
if (permission === 'worker' &&
|
|
16
|
+
context.manifest.contributions.some((c) => c.family === 'worker')) {
|
|
17
|
+
return { id: permission };
|
|
18
|
+
}
|
|
19
|
+
return grants.find((grant) => grant.id === permission);
|
|
20
|
+
}
|
|
21
|
+
function hasGrant(permission) {
|
|
22
|
+
return granted(permission) !== undefined;
|
|
23
|
+
}
|
|
24
|
+
async function execute(method, params) {
|
|
25
|
+
switch (method) {
|
|
26
|
+
case 'db.exec':
|
|
27
|
+
case 'db.all':
|
|
28
|
+
case 'db.get':
|
|
29
|
+
case 'db.run':
|
|
30
|
+
case 'db.batch':
|
|
31
|
+
return executeDb(method, params);
|
|
32
|
+
case 'accounts.list':
|
|
33
|
+
case 'accounts.report':
|
|
34
|
+
case 'accounts.access':
|
|
35
|
+
return executeAccounts(method, params);
|
|
36
|
+
case 'http.fetch':
|
|
37
|
+
return executeHttp(params);
|
|
38
|
+
case 'files.stat':
|
|
39
|
+
case 'files.read':
|
|
40
|
+
case 'files.write':
|
|
41
|
+
return executeFilesService(method, params, {
|
|
42
|
+
options: context.options,
|
|
43
|
+
writes: context.sinks.fileWrites,
|
|
44
|
+
});
|
|
45
|
+
case 'triggers.fire':
|
|
46
|
+
return fireTrigger(params);
|
|
47
|
+
case 'triggers.create':
|
|
48
|
+
return createTriggerInstance(params);
|
|
49
|
+
case 'triggers.update':
|
|
50
|
+
return updateTriggerInstance(params);
|
|
51
|
+
default:
|
|
52
|
+
return executeRecord(method, params);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function executeDb(method, params) {
|
|
56
|
+
const db = context.db;
|
|
57
|
+
switch (method) {
|
|
58
|
+
case 'db.exec':
|
|
59
|
+
db.exec(params.sql);
|
|
60
|
+
return {};
|
|
61
|
+
case 'db.all':
|
|
62
|
+
return { rows: db.all(params.sql, params.params) };
|
|
63
|
+
case 'db.get':
|
|
64
|
+
return { row: db.get(params.sql, params.params) };
|
|
65
|
+
case 'db.run':
|
|
66
|
+
return db.run(params.sql, params.params);
|
|
67
|
+
default:
|
|
68
|
+
return { results: db.batch(params.statements) };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async function executeAccounts(method, params) {
|
|
72
|
+
const connection = params.connection;
|
|
73
|
+
assertConnection(connection);
|
|
74
|
+
if (method === 'accounts.list') {
|
|
75
|
+
const accounts = boundAccounts(connection);
|
|
76
|
+
return {
|
|
77
|
+
accounts: accounts.map((account) => ({
|
|
78
|
+
accountId: account.accountId,
|
|
79
|
+
label: account.label ?? account.accountId,
|
|
80
|
+
externalAccountId: account.externalAccountId ?? account.accountId,
|
|
81
|
+
status: account.status ?? 'connected',
|
|
82
|
+
})),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
if (method === 'accounts.report') {
|
|
86
|
+
context.sinks.accountReports.push({
|
|
87
|
+
connection,
|
|
88
|
+
accountId: params.accountId,
|
|
89
|
+
code: params.code,
|
|
90
|
+
});
|
|
91
|
+
return {};
|
|
92
|
+
}
|
|
93
|
+
const account = selectAccount(connection, params.accountId);
|
|
94
|
+
return { credentials: account.credentials ?? null, expiresAt: account.expiresAt };
|
|
95
|
+
}
|
|
96
|
+
async function executeHttp(params) {
|
|
97
|
+
const request = params;
|
|
98
|
+
let url;
|
|
99
|
+
try {
|
|
100
|
+
url = new URL(request.url);
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
throw new AddonError('invalid_params', { detail: `url '${request.url}' is not valid` });
|
|
104
|
+
}
|
|
105
|
+
if (url.protocol !== 'https:') {
|
|
106
|
+
throw new AddonError('permission_denied', { detail: 'egress policy allows https only' });
|
|
107
|
+
}
|
|
108
|
+
const grant = granted('http.fetch');
|
|
109
|
+
if (grant?.scope &&
|
|
110
|
+
Array.isArray(grant.scope.hosts) &&
|
|
111
|
+
!grant.scope.hosts.includes(url.host)) {
|
|
112
|
+
throw new AddonError('permission_denied', {
|
|
113
|
+
detail: `host '${url.host}' is outside the granted scope`,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
if (!context.options.http) {
|
|
117
|
+
throw new AddonError('unavailable', { detail: 'fake host has no http handler configured' });
|
|
118
|
+
}
|
|
119
|
+
const response = await context.options.http({
|
|
120
|
+
url: request.url,
|
|
121
|
+
method: request.method,
|
|
122
|
+
headers: request.headers ?? {},
|
|
123
|
+
body: request.body,
|
|
124
|
+
auth: params.auth,
|
|
125
|
+
});
|
|
126
|
+
return {
|
|
127
|
+
status: response.status,
|
|
128
|
+
headers: response.headers ?? {},
|
|
129
|
+
body: response.body ?? null,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function fireTrigger(params) {
|
|
133
|
+
const instanceId = params.instanceId;
|
|
134
|
+
const runKey = params.runKey;
|
|
135
|
+
if (!context.startedTriggers.has(instanceId)) {
|
|
136
|
+
throw new AddonError('not_found', {
|
|
137
|
+
detail: `trigger instance '${instanceId}' was not started`,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
const key = `${instanceId}:${runKey}`;
|
|
141
|
+
if (context.firedKeys.has(key)) {
|
|
142
|
+
return { outcome: 'suppressed' };
|
|
143
|
+
}
|
|
144
|
+
context.firedKeys.add(key);
|
|
145
|
+
return { outcome: 'fired' };
|
|
146
|
+
}
|
|
147
|
+
function createTriggerInstance(params) {
|
|
148
|
+
const kind = params.kind;
|
|
149
|
+
const declared = context.manifest.contributions.some((c) => c.family === 'trigger' && c.descriptor.kind === kind);
|
|
150
|
+
if (!declared) {
|
|
151
|
+
throw new AddonError('invalid_params', {
|
|
152
|
+
detail: `trigger kind is not declared: ${kind}`,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
const instanceId = `trigger-instance-${context.sinks.createdTriggerInstances.length + 1}`;
|
|
156
|
+
context.sinks.createdTriggerInstances.push({ ...params, instanceId });
|
|
157
|
+
context.startedTriggers.add(instanceId);
|
|
158
|
+
return { instanceId };
|
|
159
|
+
}
|
|
160
|
+
function updateTriggerInstance(params) {
|
|
161
|
+
const instanceId = params.instanceId;
|
|
162
|
+
const stored = context.sinks.createdTriggerInstances.find((row) => row.instanceId === instanceId);
|
|
163
|
+
if (!stored) {
|
|
164
|
+
throw new AddonError('not_found', {
|
|
165
|
+
detail: `trigger instance not found: ${instanceId}`,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
for (const key of ['label', 'config', 'target', 'instructions']) {
|
|
169
|
+
if (params[key] !== undefined) {
|
|
170
|
+
stored[key] = params[key];
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return { instanceId };
|
|
174
|
+
}
|
|
175
|
+
function executeRecord(method, params) {
|
|
176
|
+
const sinks = context.sinks;
|
|
177
|
+
switch (method) {
|
|
178
|
+
case 'config.get':
|
|
179
|
+
return configValues(params.keys);
|
|
180
|
+
case 'secrets.get': {
|
|
181
|
+
const value = context.options.secrets?.[params.key];
|
|
182
|
+
return { value: value === undefined ? null : value };
|
|
183
|
+
}
|
|
184
|
+
case 'log.write':
|
|
185
|
+
sinks.logs.push({
|
|
186
|
+
level: params.level,
|
|
187
|
+
message: params.message,
|
|
188
|
+
fields: params.fields,
|
|
189
|
+
});
|
|
190
|
+
return {};
|
|
191
|
+
case 'events.emit': {
|
|
192
|
+
const name = params.name;
|
|
193
|
+
if (!name.startsWith(`${context.manifest.id}.`)) {
|
|
194
|
+
throw new AddonError('invalid_params', {
|
|
195
|
+
detail: `events.emit name '${name}' is outside the addon namespace '${context.manifest.id}.*'`,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
sinks.emitted.push({ name, payload: params.payload });
|
|
199
|
+
return {};
|
|
200
|
+
}
|
|
201
|
+
case 'runs.dispatch':
|
|
202
|
+
sinks.dispatchedRuns.push(params);
|
|
203
|
+
return { runId: `run-${sinks.dispatchedRuns.length}` };
|
|
204
|
+
case 'runs.cancel':
|
|
205
|
+
sinks.cancelledRuns.push(params);
|
|
206
|
+
return { ok: true };
|
|
207
|
+
case 'threads.create': {
|
|
208
|
+
const threadId = `thread-${sinks.createdThreads.length + 1}`;
|
|
209
|
+
sinks.createdThreads.push(threadId);
|
|
210
|
+
return { threadId };
|
|
211
|
+
}
|
|
212
|
+
case 'threads.get':
|
|
213
|
+
return { thread: undefined };
|
|
214
|
+
case 'threads.patch':
|
|
215
|
+
sinks.patchedThreads.push(params);
|
|
216
|
+
return {};
|
|
217
|
+
case 'agents.list':
|
|
218
|
+
return { agents: [] };
|
|
219
|
+
case 'bridge.inbound':
|
|
220
|
+
sinks.inboundMessages.push(params.message);
|
|
221
|
+
return { outcome: 'dispatched' };
|
|
222
|
+
case 'workers.report':
|
|
223
|
+
sinks.workerReports.push(params);
|
|
224
|
+
return {};
|
|
225
|
+
default:
|
|
226
|
+
throw new AddonError('unsupported', {
|
|
227
|
+
detail: `fake host has no service implementation for '${method}'`,
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
function configValues(keys) {
|
|
232
|
+
const values = { ...context.options.config };
|
|
233
|
+
if (!keys) {
|
|
234
|
+
return { values };
|
|
235
|
+
}
|
|
236
|
+
return {
|
|
237
|
+
values: Object.fromEntries(keys.filter((key) => key in values).map((key) => [key, values[key]])),
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
function boundAccounts(connection) {
|
|
241
|
+
return (context.options.accounts ?? []).filter((account) => account.connection === connection);
|
|
242
|
+
}
|
|
243
|
+
function assertConnection(connection) {
|
|
244
|
+
const declared = context.manifest.connections.some((requirement) => requirement.id === connection);
|
|
245
|
+
if (!declared) {
|
|
246
|
+
throw new AddonError('invalid_params', {
|
|
247
|
+
detail: `connection '${connection}' is not declared in the manifest`,
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
function selectAccount(connection, accountId) {
|
|
252
|
+
const accounts = boundAccounts(connection);
|
|
253
|
+
if (accounts.length === 0) {
|
|
254
|
+
throw new AddonError('account_failed', {
|
|
255
|
+
detail: `no account is bound to connection '${connection}'`,
|
|
256
|
+
accountCode: 'not_connected',
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
if (accountId === undefined) {
|
|
260
|
+
if (accounts.length > 1) {
|
|
261
|
+
throw new AddonError('invalid_params', {
|
|
262
|
+
detail: `accountId is required: connection '${connection}' has ${accounts.length} bindings`,
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
return accounts[0];
|
|
266
|
+
}
|
|
267
|
+
const found = accounts.find((account) => account.accountId === accountId);
|
|
268
|
+
if (!found) {
|
|
269
|
+
throw new AddonError('account_failed', {
|
|
270
|
+
detail: `account '${accountId}' is not bound to '${connection}'`,
|
|
271
|
+
accountCode: 'not_bound',
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
return found;
|
|
275
|
+
}
|
|
276
|
+
return { execute, hasGrant };
|
|
277
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ResolvedAddonDefinition } from '../define-addon.ts';
|
|
2
|
+
import type { AddonManifest } from '../manifest/manifest.ts';
|
|
3
|
+
export declare function validManifest(): AddonManifest;
|
|
4
|
+
export declare function toolPackManifest(tools: Array<Record<string, unknown>>): AddonManifest;
|
|
5
|
+
export declare function demoDefinition(): ResolvedAddonDefinition;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { defineAddon } from "../define-addon.js";
|
|
2
|
+
export function validManifest() {
|
|
3
|
+
return {
|
|
4
|
+
id: 'harnesys.demo',
|
|
5
|
+
version: '1.0.0',
|
|
6
|
+
platform: 1,
|
|
7
|
+
title: 'Demo',
|
|
8
|
+
description: 'Demo addon',
|
|
9
|
+
runtime: { entry: './dist/index.js', profile: 'restricted' },
|
|
10
|
+
activation: 'lazy',
|
|
11
|
+
permissions: [
|
|
12
|
+
{ id: 'http.fetch', scope: { hosts: ['api.example.com'] }, reason: 'Calls the example API' },
|
|
13
|
+
],
|
|
14
|
+
connections: [
|
|
15
|
+
{
|
|
16
|
+
id: 'example',
|
|
17
|
+
label: 'Example connection',
|
|
18
|
+
accountKinds: ['example-account'],
|
|
19
|
+
cardinality: 'many',
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
contributions: [
|
|
23
|
+
{
|
|
24
|
+
id: 'pack',
|
|
25
|
+
family: 'tool-pack',
|
|
26
|
+
descriptor: {
|
|
27
|
+
name: 'example',
|
|
28
|
+
title: 'Example tools',
|
|
29
|
+
description: 'Tools for the demo',
|
|
30
|
+
connection: 'example',
|
|
31
|
+
tools: [
|
|
32
|
+
{
|
|
33
|
+
name: 'example.ping',
|
|
34
|
+
description: 'Ping',
|
|
35
|
+
inputSchema: { type: 'object' },
|
|
36
|
+
effect: 'read',
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: 'hook',
|
|
43
|
+
family: 'hook',
|
|
44
|
+
descriptor: { id: 'onThread', on: { event: 'thread.*' } },
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export function toolPackManifest(tools) {
|
|
50
|
+
return {
|
|
51
|
+
...validManifest(),
|
|
52
|
+
contributions: [
|
|
53
|
+
{
|
|
54
|
+
id: 'pack',
|
|
55
|
+
family: 'tool-pack',
|
|
56
|
+
descriptor: {
|
|
57
|
+
name: 'example',
|
|
58
|
+
title: 'Example tools',
|
|
59
|
+
description: 'Tools for the demo',
|
|
60
|
+
tools,
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export function demoDefinition() {
|
|
67
|
+
return defineAddon({
|
|
68
|
+
tools: {
|
|
69
|
+
'example.ping': (input, ctx) => ({ pong: true, echo: input, org: ctx.meta.correlationId }),
|
|
70
|
+
},
|
|
71
|
+
routes: {
|
|
72
|
+
items: async () => ({ status: 200, body: { rows: [] } }),
|
|
73
|
+
},
|
|
74
|
+
triggers: {
|
|
75
|
+
'telegram.feed': {
|
|
76
|
+
start: async () => undefined,
|
|
77
|
+
stop: async () => undefined,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
jobs: {
|
|
81
|
+
sync: async (_params, ctx) => {
|
|
82
|
+
await ctx.log.info('job ran');
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
hooks: {
|
|
86
|
+
onThread: async () => undefined,
|
|
87
|
+
},
|
|
88
|
+
sources: {
|
|
89
|
+
example: {
|
|
90
|
+
list: async () => ({ entries: [{ id: 'file-1', name: 'notes.txt', kind: 'file' }] }),
|
|
91
|
+
stat: async (params) => ({
|
|
92
|
+
entry: { id: params.fileId, name: 'notes.txt', kind: 'file' },
|
|
93
|
+
}),
|
|
94
|
+
download: async () => ({ data: '', eof: true }),
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
transport: {
|
|
98
|
+
typing: async () => undefined,
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type { FakeDb } from './fake-db.ts';
|
|
2
|
+
export { createFakeDb, guardSql, SqlAuthorizerError } from './fake-db.ts';
|
|
3
|
+
export type { FakeAccount, FakeGrant, FakeHost, FakeHostOptions, FakeHttpHandler, FakeHttpRequest, FakeHttpResponse, } from './fake-host.ts';
|
|
4
|
+
export { createFakeHost } from './fake-host.ts';
|
package/package.json
CHANGED
|
@@ -1,6 +1,68 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@harnesys/sdk",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Add-on SDK for Harnesys: manifest, contributions, JSON-RPC protocol, permissions, defineAddon, host client and a testing fake host.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"bun": "./src/index.ts",
|
|
13
|
+
"types": "./src/index.ts",
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./testing": {
|
|
18
|
+
"bun": "./src/testing/index.ts",
|
|
19
|
+
"types": "./src/testing/index.ts",
|
|
20
|
+
"import": "./dist/testing/index.js",
|
|
21
|
+
"default": "./dist/testing/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"src",
|
|
27
|
+
"!src/**/*.spec.ts",
|
|
28
|
+
"!src/**/__fixtures__",
|
|
29
|
+
"README.md",
|
|
30
|
+
"LICENSE"
|
|
31
|
+
],
|
|
32
|
+
"sideEffects": false,
|
|
33
|
+
"engines": {
|
|
34
|
+
"bun": ">=1.2.0"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "git+https://github.com/harnesys/harnesys.git",
|
|
42
|
+
"directory": "packages/sdk"
|
|
43
|
+
},
|
|
44
|
+
"homepage": "https://github.com/harnesys/harnesys/tree/main/packages/sdk#readme",
|
|
45
|
+
"bugs": {
|
|
46
|
+
"url": "https://github.com/harnesys/harnesys/issues"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
50
|
+
"pack": "rm -rf dist && tsc -p tsconfig.build.json && npm pack",
|
|
51
|
+
"typecheck": "tsc --noEmit"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"zod": "^4.4.3"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@types/bun": "^1.4.2",
|
|
58
|
+
"typescript": "^5.9.3"
|
|
59
|
+
},
|
|
60
|
+
"peerDependencies": {
|
|
61
|
+
"typescript": "^5.9.3"
|
|
62
|
+
},
|
|
63
|
+
"peerDependenciesMeta": {
|
|
64
|
+
"typescript": {
|
|
65
|
+
"optional": true
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|