@haex-space/vault-sdk 4.1.0 → 4.3.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 (55) hide show
  1. package/README.md +69 -0
  2. package/dist/cli/index.js +2 -1
  3. package/dist/cli/index.js.map +1 -1
  4. package/dist/cli/index.mjs +2 -1
  5. package/dist/cli/index.mjs.map +1 -1
  6. package/dist/{client-Cx4ZyQFL.d.mts → client-CDox5_KH.d.mts} +263 -27
  7. package/dist/{client-CD5QZi7F.d.ts → client-pppDo5Q3.d.ts} +263 -27
  8. package/dist/haex_bundle_bg.wasm +0 -0
  9. package/dist/index.d.mts +45 -6
  10. package/dist/index.d.ts +45 -6
  11. package/dist/index.js +363 -14
  12. package/dist/index.js.map +1 -1
  13. package/dist/index.mjs +360 -15
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/node.d.mts +1 -1
  16. package/dist/node.d.ts +1 -1
  17. package/dist/node.js +2 -1
  18. package/dist/node.js.map +1 -1
  19. package/dist/node.mjs +2 -1
  20. package/dist/node.mjs.map +1 -1
  21. package/dist/nuxt.js +10 -2
  22. package/dist/nuxt.js.map +1 -1
  23. package/dist/nuxt.mjs +10 -2
  24. package/dist/nuxt.mjs.map +1 -1
  25. package/dist/react.d.mts +2 -2
  26. package/dist/react.d.ts +2 -2
  27. package/dist/react.js +339 -14
  28. package/dist/react.js.map +1 -1
  29. package/dist/react.mjs +339 -14
  30. package/dist/react.mjs.map +1 -1
  31. package/dist/runtime/nuxt.plugin.client.d.mts +2 -2
  32. package/dist/runtime/nuxt.plugin.client.d.ts +2 -2
  33. package/dist/runtime/nuxt.plugin.client.js +329 -14
  34. package/dist/runtime/nuxt.plugin.client.js.map +1 -1
  35. package/dist/runtime/nuxt.plugin.client.mjs +329 -14
  36. package/dist/runtime/nuxt.plugin.client.mjs.map +1 -1
  37. package/dist/svelte.d.mts +2 -2
  38. package/dist/svelte.d.ts +2 -2
  39. package/dist/svelte.js +339 -14
  40. package/dist/svelte.js.map +1 -1
  41. package/dist/svelte.mjs +339 -14
  42. package/dist/svelte.mjs.map +1 -1
  43. package/dist/{types-BwFKGH70.d.mts → types-DoNvKiW_.d.mts} +75 -1
  44. package/dist/{types-BwFKGH70.d.ts → types-DoNvKiW_.d.ts} +75 -1
  45. package/dist/vite.js +8 -1
  46. package/dist/vite.js.map +1 -1
  47. package/dist/vite.mjs +8 -1
  48. package/dist/vite.mjs.map +1 -1
  49. package/dist/vue.d.mts +2 -2
  50. package/dist/vue.d.ts +2 -2
  51. package/dist/vue.js +339 -14
  52. package/dist/vue.js.map +1 -1
  53. package/dist/vue.mjs +339 -14
  54. package/dist/vue.mjs.map +1 -1
  55. package/package.json +1 -1
package/dist/vue.mjs CHANGED
@@ -308,7 +308,14 @@ var HAEXSPACE_MESSAGE_TYPES = {
308
308
  *
309
309
  * Payload: `{ type: PORT_READY }` — no data.
310
310
  */
311
- PORT_READY: "haexspace:port:ready"
311
+ PORT_READY: "haexspace:port:ready",
312
+ /**
313
+ * One MCP message of the tool connection (holzi spec 018), in both directions over the
314
+ * MessagePort: the host calls the extension's tools, `sdk.tools` answers.
315
+ *
316
+ * Payload: `{ type: MCP, message }`, where `message` is a JSON-RPC 2.0 object.
317
+ */
318
+ MCP: "haexspace:mcp"
312
319
  };
313
320
 
314
321
  // src/polyfills/debug.ts
@@ -646,6 +653,21 @@ var REMOTE_STORAGE_COMMANDS = {
646
653
  list: "extension_remote_storage_list"
647
654
  };
648
655
 
656
+ // src/commands/encryptedFolders.ts
657
+ init_esm_shims();
658
+ var ENCRYPTED_FOLDER_COMMANDS = {
659
+ /** Let the user pick an encrypted folder of a storage and grant access to it */
660
+ choose: "extension_encrypted_folder_choose",
661
+ /** List the entries of a folder inside an encrypted folder */
662
+ list: "extension_encrypted_folder_list",
663
+ /** Download and decrypt a file */
664
+ download: "extension_encrypted_folder_download",
665
+ /** Encrypt and upload a file */
666
+ upload: "extension_encrypted_folder_upload",
667
+ /** Delete a file or folder */
668
+ delete: "extension_encrypted_folder_delete"
669
+ };
670
+
649
671
  // src/commands/localsend.ts
650
672
  init_esm_shims();
651
673
  var LOCALSEND_COMMANDS = {
@@ -1371,26 +1393,32 @@ var BackendManagement = class {
1371
1393
  );
1372
1394
  }
1373
1395
  /**
1374
- * Add a new storage backend
1375
- * @param request - Backend configuration
1396
+ * Propose a new storage. The host asks the user; credentials are entered
1397
+ * only there. Resolves with the new storage, which the extension may then
1398
+ * read and write.
1399
+ * @param request - The proposal, without credentials
1376
1400
  * @returns Created backend info
1377
1401
  */
1378
1402
  async add(request) {
1379
1403
  return this.client.request(
1380
1404
  REMOTE_STORAGE_COMMANDS.addBackend,
1381
- { request }
1405
+ { request },
1406
+ // No deadline: the host waits for the user's answer in its dialog.
1407
+ { timeout: null }
1382
1408
  );
1383
1409
  }
1384
1410
  /**
1385
- * Update a storage backend
1386
- * Only provided fields are updated. Credentials are preserved if not provided.
1411
+ * Change a storage after the user confirms it in the host.
1412
+ * Only provided fields are updated; new credentials are entered in the host.
1387
1413
  * @param request - Update request with backendId and fields to update
1388
1414
  * @returns Updated backend info
1389
1415
  */
1390
1416
  async update(request) {
1391
1417
  return this.client.request(
1392
1418
  REMOTE_STORAGE_COMMANDS.updateBackend,
1393
- { request }
1419
+ { request },
1420
+ // No deadline: the host waits for the user's answer in its dialog.
1421
+ { timeout: null }
1394
1422
  );
1395
1423
  }
1396
1424
  /**
@@ -1398,17 +1426,100 @@ var BackendManagement = class {
1398
1426
  * @param backendId - Backend ID to remove
1399
1427
  */
1400
1428
  async remove(backendId) {
1401
- await this.client.request(REMOTE_STORAGE_COMMANDS.removeBackend, {
1402
- backendId
1403
- });
1429
+ await this.client.request(
1430
+ REMOTE_STORAGE_COMMANDS.removeBackend,
1431
+ { backendId },
1432
+ { timeout: null }
1433
+ );
1404
1434
  }
1405
1435
  /**
1406
1436
  * Test connection to a storage backend
1407
1437
  * @param backendId - Backend ID to test
1408
1438
  */
1409
1439
  async test(backendId) {
1410
- await this.client.request(REMOTE_STORAGE_COMMANDS.testBackend, {
1411
- backendId
1440
+ await this.client.request(
1441
+ REMOTE_STORAGE_COMMANDS.testBackend,
1442
+ { backendId },
1443
+ { timeout: null }
1444
+ );
1445
+ }
1446
+ };
1447
+
1448
+ // src/api/encryptedFolders.ts
1449
+ init_esm_shims();
1450
+ init_vaultKey();
1451
+ var EncryptedFoldersAPI = class {
1452
+ constructor(client) {
1453
+ this.client = client;
1454
+ }
1455
+ /**
1456
+ * Let the user choose one of the storage's encrypted folders and grant
1457
+ * access to it. The host shows its own window and waits for the answer.
1458
+ * Needs the `remoteStorage` permission for the storage (else 1002 without
1459
+ * asking); 1002 as well when the user refuses.
1460
+ * @param storageId - Storage the folder lies in
1461
+ * @param access - Access the extension asks for
1462
+ * @returns The chosen folder, or `null` when the user closed the chooser without choosing
1463
+ */
1464
+ async choose(storageId, access) {
1465
+ const choice = await this.client.request(
1466
+ ENCRYPTED_FOLDER_COMMANDS.choose,
1467
+ { request: { storageId, access } },
1468
+ // No deadline: the host waits for the user's answer in its window.
1469
+ { timeout: null }
1470
+ );
1471
+ return choice ?? null;
1472
+ }
1473
+ /**
1474
+ * List a folder inside an encrypted folder (permission `read`).
1475
+ * @param storageId - Storage the folder lies in
1476
+ * @param folderId - Folder from {@link EncryptedFoldersAPI.choose}
1477
+ * @param path - Path relative to the encrypted folder; `''` (default) for its root
1478
+ * @returns The entries with their decrypted names
1479
+ */
1480
+ async list(storageId, folderId, path2 = "") {
1481
+ const result = await this.client.request(
1482
+ ENCRYPTED_FOLDER_COMMANDS.list,
1483
+ { request: { storageId, folderId, path: path2 } }
1484
+ );
1485
+ return result.entries;
1486
+ }
1487
+ /**
1488
+ * Download and decrypt a file (permission `read`).
1489
+ * @param storageId - Storage the folder lies in
1490
+ * @param folderId - Folder from {@link EncryptedFoldersAPI.choose}
1491
+ * @param path - Path of the file, relative to the encrypted folder
1492
+ * @returns The decrypted content
1493
+ */
1494
+ async download(storageId, folderId, path2) {
1495
+ const base64 = await this.client.request(
1496
+ ENCRYPTED_FOLDER_COMMANDS.download,
1497
+ { request: { storageId, folderId, path: path2 } }
1498
+ );
1499
+ return base64ToArrayBuffer(base64);
1500
+ }
1501
+ /**
1502
+ * Encrypt and upload a file (permission `readWrite`). Missing parent
1503
+ * folders are created.
1504
+ * @param storageId - Storage the folder lies in
1505
+ * @param folderId - Folder from {@link EncryptedFoldersAPI.choose}
1506
+ * @param path - Path of the file, relative to the encrypted folder
1507
+ * @param data - Content of the file
1508
+ */
1509
+ async upload(storageId, folderId, path2, data) {
1510
+ await this.client.request(ENCRYPTED_FOLDER_COMMANDS.upload, {
1511
+ request: { storageId, folderId, path: path2, data: arrayBufferToBase64(data) }
1512
+ });
1513
+ }
1514
+ /**
1515
+ * Delete a file or folder (permission `readWrite`).
1516
+ * @param storageId - Storage the folder lies in
1517
+ * @param folderId - Folder from {@link EncryptedFoldersAPI.choose}
1518
+ * @param path - Path relative to the encrypted folder
1519
+ */
1520
+ async delete(storageId, folderId, path2) {
1521
+ await this.client.request(ENCRYPTED_FOLDER_COMMANDS.delete, {
1522
+ request: { storageId, folderId, path: path2 }
1412
1523
  });
1413
1524
  }
1414
1525
  };
@@ -2019,6 +2130,202 @@ var DialogAPI = class {
2019
2130
  }
2020
2131
  };
2021
2132
 
2133
+ // src/api/tools/index.ts
2134
+ init_esm_shims();
2135
+
2136
+ // src/api/tools/server.ts
2137
+ init_esm_shims();
2138
+
2139
+ // src/api/tools/schema.ts
2140
+ init_esm_shims();
2141
+ function fail(field, message) {
2142
+ return { ok: false, field, message };
2143
+ }
2144
+ function typeMatches(type, value) {
2145
+ switch (type) {
2146
+ case "object":
2147
+ return typeof value === "object" && value !== null && !Array.isArray(value);
2148
+ case "array":
2149
+ return Array.isArray(value);
2150
+ case "integer":
2151
+ return Number.isInteger(value);
2152
+ case "number":
2153
+ return typeof value === "number" && Number.isFinite(value);
2154
+ case "string":
2155
+ return typeof value === "string";
2156
+ case "boolean":
2157
+ return typeof value === "boolean";
2158
+ default:
2159
+ return false;
2160
+ }
2161
+ }
2162
+ function validateAt(schema, value, field) {
2163
+ if (!typeMatches(schema.type, value)) return fail(field, `expected ${String(schema.type)}`);
2164
+ if (schema.enum && !schema.enum.includes(value)) {
2165
+ return fail(field, `expected one of ${schema.enum.join(", ")}`);
2166
+ }
2167
+ if (schema.type === "array" && schema.items) {
2168
+ const items = value;
2169
+ for (let i = 0; i < items.length; i++) {
2170
+ const result = validateAt(schema.items, items[i], `${field}[${i}]`);
2171
+ if (!result.ok) return result;
2172
+ }
2173
+ }
2174
+ if (schema.type === "object") {
2175
+ const record = value;
2176
+ const properties = schema.properties ?? {};
2177
+ const prefix = field === "" ? "" : `${field}.`;
2178
+ if (schema.properties) {
2179
+ for (const key of Object.keys(record)) {
2180
+ if (!Object.hasOwn(properties, key)) return fail(`${prefix}${key}`, "unknown property");
2181
+ }
2182
+ }
2183
+ for (const key of schema.required ?? []) {
2184
+ if (record[key] === void 0) return fail(`${prefix}${key}`, "required");
2185
+ }
2186
+ for (const [key, child] of Object.entries(properties)) {
2187
+ if (record[key] === void 0) continue;
2188
+ const result = validateAt(child, record[key], `${prefix}${key}`);
2189
+ if (!result.ok) return result;
2190
+ }
2191
+ }
2192
+ return { ok: true };
2193
+ }
2194
+ function validateInput(schema, value) {
2195
+ return validateAt(schema, value, "");
2196
+ }
2197
+
2198
+ // src/api/tools/server.ts
2199
+ var PROTOCOL_VERSION = "2025-11-25";
2200
+ var METHOD_NOT_FOUND = -32601;
2201
+ var INVALID_PARAMS = -32602;
2202
+ function textResult(text, isError) {
2203
+ return { content: [{ type: "text", text }], isError };
2204
+ }
2205
+ function asText(value) {
2206
+ if (typeof value === "string") return value;
2207
+ if (value === void 0) return "";
2208
+ return JSON.stringify(value);
2209
+ }
2210
+ function isId(value) {
2211
+ return typeof value === "string" || typeof value === "number";
2212
+ }
2213
+ var ToolsServer = class {
2214
+ constructor(options) {
2215
+ this.options = options;
2216
+ this.running = /* @__PURE__ */ new Map();
2217
+ }
2218
+ /**
2219
+ * Handles one JSON-RPC message from the host. A tool call runs on its own and answers when it is
2220
+ * done, so a long call never holds up `ping` or the cancellation of that very call.
2221
+ */
2222
+ async receive(message) {
2223
+ if (typeof message !== "object" || message === null) return;
2224
+ const { id, method, params } = message;
2225
+ if (typeof method !== "string") return;
2226
+ const args = typeof params === "object" && params !== null ? params : {};
2227
+ if (!isId(id)) {
2228
+ if (method === "notifications/cancelled" && isId(args.requestId)) {
2229
+ this.running.get(args.requestId)?.abort();
2230
+ }
2231
+ return;
2232
+ }
2233
+ switch (method) {
2234
+ case "initialize":
2235
+ return this.reply(id, {
2236
+ protocolVersion: PROTOCOL_VERSION,
2237
+ capabilities: { tools: {} },
2238
+ serverInfo: {
2239
+ name: this.options.manifest?.name ?? "",
2240
+ version: this.options.manifest?.version ?? ""
2241
+ }
2242
+ });
2243
+ case "ping":
2244
+ return this.reply(id, {});
2245
+ case "tools/list": {
2246
+ const tools = this.tools().map(({ name, title, description, inputSchema }) => ({
2247
+ name,
2248
+ title: title.en,
2249
+ description,
2250
+ inputSchema
2251
+ }));
2252
+ return this.reply(id, { tools });
2253
+ }
2254
+ case "tools/call":
2255
+ void this.call(id, args);
2256
+ return;
2257
+ default:
2258
+ return this.error(id, METHOD_NOT_FOUND, method);
2259
+ }
2260
+ }
2261
+ /** The declared tools that have a handler. */
2262
+ tools() {
2263
+ return (this.options.manifest?.tools ?? []).filter((tool) => this.options.handlers.has(tool.name));
2264
+ }
2265
+ async call(id, params) {
2266
+ const tool = this.tools().find((candidate) => candidate.name === params.name);
2267
+ const handler = tool && this.options.handlers.get(tool.name);
2268
+ if (!tool || !handler) return this.error(id, INVALID_PARAMS, `unknown tool ${String(params.name)}`);
2269
+ const input = params.arguments ?? {};
2270
+ const checked = validateInput(tool.inputSchema, input);
2271
+ if (!checked.ok) {
2272
+ return this.reply(id, textResult(`invalid input: ${checked.field}: ${checked.message}`, true));
2273
+ }
2274
+ const controller = new AbortController();
2275
+ this.running.set(id, controller);
2276
+ let result;
2277
+ try {
2278
+ const output = await handler(input, { signal: controller.signal });
2279
+ result = textResult(asText(output), false);
2280
+ } catch (error) {
2281
+ result = textResult(error instanceof Error ? error.message : String(error), true);
2282
+ } finally {
2283
+ this.running.delete(id);
2284
+ }
2285
+ if (!controller.signal.aborted) this.reply(id, result);
2286
+ }
2287
+ reply(id, result) {
2288
+ this.options.send({ jsonrpc: "2.0", id, result });
2289
+ }
2290
+ error(id, code, message) {
2291
+ this.options.send({ jsonrpc: "2.0", id, error: { code, message } });
2292
+ }
2293
+ };
2294
+
2295
+ // src/api/tools/index.ts
2296
+ var ToolsAPI = class {
2297
+ constructor(options) {
2298
+ this.options = options;
2299
+ this.handlers = /* @__PURE__ */ new Map();
2300
+ const manifest = options.manifest;
2301
+ this.server = new ToolsServer({
2302
+ get manifest() {
2303
+ return manifest();
2304
+ },
2305
+ handlers: this.handlers,
2306
+ send: options.send
2307
+ });
2308
+ }
2309
+ /**
2310
+ * Runs `handler` when the host calls the tool `name`. The tool must be declared in the manifest.
2311
+ * Returns a function that unregisters the handler; the host then no longer sees the tool.
2312
+ */
2313
+ register(name, handler) {
2314
+ const declared = this.options.manifest()?.tools?.some((tool) => tool.name === name) ?? false;
2315
+ if (!declared) {
2316
+ throw new Error(`The tool ${name} is not declared in the manifest's tools`);
2317
+ }
2318
+ this.handlers.set(name, handler);
2319
+ return () => {
2320
+ if (this.handlers.get(name) === handler) this.handlers.delete(name);
2321
+ };
2322
+ }
2323
+ /** Handles one MCP message from the host. Called by the SDK for `haexspace:mcp` port messages. */
2324
+ receive(message) {
2325
+ return this.server.receive(message);
2326
+ }
2327
+ };
2328
+
2022
2329
  // src/client/tableName.ts
2023
2330
  init_esm_shims();
2024
2331
  function validatePublicKey(publicKey) {
@@ -2400,7 +2707,11 @@ function createMessageHandler(config, pendingRequests, extensionInfo2, onEvent)
2400
2707
  }
2401
2708
  };
2402
2709
  }
2403
- function processEvent(event, log, eventListeners, onContextChanged, onExternalRequest, onActionRequest) {
2710
+ function processEvent(event, log, eventListeners, onContextChanged, onExternalRequest, onActionRequest, onMcpMessage) {
2711
+ if (event.type === HAEXSPACE_MESSAGE_TYPES.MCP) {
2712
+ onMcpMessage?.(event.message);
2713
+ return;
2714
+ }
2404
2715
  if (event.type === HAEXTENSION_EVENTS.CONTEXT_CHANGED) {
2405
2716
  const contextEvent = event;
2406
2717
  onContextChanged(contextEvent.data.context);
@@ -2672,6 +2983,7 @@ var HaexVaultSdk = class {
2672
2983
  this.web = new WebAPI(this);
2673
2984
  this.permissions = new PermissionsAPI(this);
2674
2985
  this.remoteStorage = new RemoteStorageAPI(this);
2986
+ this.encryptedFolders = new EncryptedFoldersAPI(this);
2675
2987
  this.localsend = new LocalSendAPI(this);
2676
2988
  this.spaces = new SpacesAPI(this);
2677
2989
  this.shell = new ShellAPI(this);
@@ -2680,6 +2992,10 @@ var HaexVaultSdk = class {
2680
2992
  this.notifications = new NotificationsAPI(this);
2681
2993
  this.tab = new TabAPI(this);
2682
2994
  this.dialog = new DialogAPI(this);
2995
+ this.tools = new ToolsAPI({
2996
+ manifest: () => this.config.manifest,
2997
+ send: (message) => this.sendMcpMessage(message)
2998
+ });
2683
2999
  installConsoleForwarding(this.config.debug);
2684
3000
  this.on(HAEXTENSION_EVENTS.PERMISSION_RESOLVED, (event) => {
2685
3001
  const data = event.data;
@@ -2987,9 +3303,18 @@ var HaexVaultSdk = class {
2987
3303
  this.notifySubscribersInternal();
2988
3304
  },
2989
3305
  (extEvent) => this.handleExternalRequestInternal(extEvent.data),
2990
- (actionEvent) => this.handleActionRequestInternal(actionEvent.data)
3306
+ (actionEvent) => this.handleActionRequestInternal(actionEvent.data),
3307
+ (message) => void this.tools.receive(message)
2991
3308
  );
2992
3309
  }
3310
+ /** Sends one MCP message of the tool connection to the host on the port. */
3311
+ sendMcpMessage(message) {
3312
+ if (!this.hostPort) {
3313
+ this.log("Dropped an MCP message: no host port yet");
3314
+ return;
3315
+ }
3316
+ this.hostPort.postMessage({ type: HAEXSPACE_MESSAGE_TYPES.MCP, message });
3317
+ }
2993
3318
  async handleExternalRequestInternal(request) {
2994
3319
  await handleExternalRequest(request, this.externalRequestHandlers, this.respondToExternalRequest.bind(this), this.log.bind(this));
2995
3320
  }