@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
@@ -1,7 +1,7 @@
1
1
  import * as nuxt_app from 'nuxt/app';
2
2
  import { ShallowRef } from 'vue';
3
- import { H as HaexVaultSdk } from '../client-Cx4ZyQFL.mjs';
4
- import { A as ApplicationContext } from '../types-BwFKGH70.mjs';
3
+ import { H as HaexVaultSdk } from '../client-CDox5_KH.mjs';
4
+ import { A as ApplicationContext } from '../types-DoNvKiW_.mjs';
5
5
  import 'drizzle-orm/sqlite-proxy';
6
6
 
7
7
  declare const _default: nuxt_app.Plugin<{
@@ -1,7 +1,7 @@
1
1
  import * as nuxt_app from 'nuxt/app';
2
2
  import { ShallowRef } from 'vue';
3
- import { H as HaexVaultSdk } from '../client-CD5QZi7F.js';
4
- import { A as ApplicationContext } from '../types-BwFKGH70.js';
3
+ import { H as HaexVaultSdk } from '../client-pppDo5Q3.js';
4
+ import { A as ApplicationContext } from '../types-DoNvKiW_.js';
5
5
  import 'drizzle-orm/sqlite-proxy';
6
6
 
7
7
  declare const _default: nuxt_app.Plugin<{
@@ -213,6 +213,20 @@ var REMOTE_STORAGE_COMMANDS = {
213
213
  list: "extension_remote_storage_list"
214
214
  };
215
215
 
216
+ // src/commands/encryptedFolders.ts
217
+ var ENCRYPTED_FOLDER_COMMANDS = {
218
+ /** Let the user pick an encrypted folder of a storage and grant access to it */
219
+ choose: "extension_encrypted_folder_choose",
220
+ /** List the entries of a folder inside an encrypted folder */
221
+ list: "extension_encrypted_folder_list",
222
+ /** Download and decrypt a file */
223
+ download: "extension_encrypted_folder_download",
224
+ /** Encrypt and upload a file */
225
+ upload: "extension_encrypted_folder_upload",
226
+ /** Delete a file or folder */
227
+ delete: "extension_encrypted_folder_delete"
228
+ };
229
+
216
230
  // src/commands/localsend.ts
217
231
  var LOCALSEND_COMMANDS = {
218
232
  // Initialization
@@ -952,26 +966,32 @@ var BackendManagement = class {
952
966
  );
953
967
  }
954
968
  /**
955
- * Add a new storage backend
956
- * @param request - Backend configuration
969
+ * Propose a new storage. The host asks the user; credentials are entered
970
+ * only there. Resolves with the new storage, which the extension may then
971
+ * read and write.
972
+ * @param request - The proposal, without credentials
957
973
  * @returns Created backend info
958
974
  */
959
975
  async add(request) {
960
976
  return this.client.request(
961
977
  REMOTE_STORAGE_COMMANDS.addBackend,
962
- { request }
978
+ { request },
979
+ // No deadline: the host waits for the user's answer in its dialog.
980
+ { timeout: null }
963
981
  );
964
982
  }
965
983
  /**
966
- * Update a storage backend
967
- * Only provided fields are updated. Credentials are preserved if not provided.
984
+ * Change a storage after the user confirms it in the host.
985
+ * Only provided fields are updated; new credentials are entered in the host.
968
986
  * @param request - Update request with backendId and fields to update
969
987
  * @returns Updated backend info
970
988
  */
971
989
  async update(request) {
972
990
  return this.client.request(
973
991
  REMOTE_STORAGE_COMMANDS.updateBackend,
974
- { request }
992
+ { request },
993
+ // No deadline: the host waits for the user's answer in its dialog.
994
+ { timeout: null }
975
995
  );
976
996
  }
977
997
  /**
@@ -979,17 +999,98 @@ var BackendManagement = class {
979
999
  * @param backendId - Backend ID to remove
980
1000
  */
981
1001
  async remove(backendId) {
982
- await this.client.request(REMOTE_STORAGE_COMMANDS.removeBackend, {
983
- backendId
984
- });
1002
+ await this.client.request(
1003
+ REMOTE_STORAGE_COMMANDS.removeBackend,
1004
+ { backendId },
1005
+ { timeout: null }
1006
+ );
985
1007
  }
986
1008
  /**
987
1009
  * Test connection to a storage backend
988
1010
  * @param backendId - Backend ID to test
989
1011
  */
990
1012
  async test(backendId) {
991
- await this.client.request(REMOTE_STORAGE_COMMANDS.testBackend, {
992
- backendId
1013
+ await this.client.request(
1014
+ REMOTE_STORAGE_COMMANDS.testBackend,
1015
+ { backendId },
1016
+ { timeout: null }
1017
+ );
1018
+ }
1019
+ };
1020
+
1021
+ // src/api/encryptedFolders.ts
1022
+ var EncryptedFoldersAPI = class {
1023
+ constructor(client) {
1024
+ this.client = client;
1025
+ }
1026
+ /**
1027
+ * Let the user choose one of the storage's encrypted folders and grant
1028
+ * access to it. The host shows its own window and waits for the answer.
1029
+ * Needs the `remoteStorage` permission for the storage (else 1002 without
1030
+ * asking); 1002 as well when the user refuses.
1031
+ * @param storageId - Storage the folder lies in
1032
+ * @param access - Access the extension asks for
1033
+ * @returns The chosen folder, or `null` when the user closed the chooser without choosing
1034
+ */
1035
+ async choose(storageId, access) {
1036
+ const choice = await this.client.request(
1037
+ ENCRYPTED_FOLDER_COMMANDS.choose,
1038
+ { request: { storageId, access } },
1039
+ // No deadline: the host waits for the user's answer in its window.
1040
+ { timeout: null }
1041
+ );
1042
+ return choice ?? null;
1043
+ }
1044
+ /**
1045
+ * List a folder inside an encrypted folder (permission `read`).
1046
+ * @param storageId - Storage the folder lies in
1047
+ * @param folderId - Folder from {@link EncryptedFoldersAPI.choose}
1048
+ * @param path - Path relative to the encrypted folder; `''` (default) for its root
1049
+ * @returns The entries with their decrypted names
1050
+ */
1051
+ async list(storageId, folderId, path = "") {
1052
+ const result = await this.client.request(
1053
+ ENCRYPTED_FOLDER_COMMANDS.list,
1054
+ { request: { storageId, folderId, path } }
1055
+ );
1056
+ return result.entries;
1057
+ }
1058
+ /**
1059
+ * Download and decrypt a file (permission `read`).
1060
+ * @param storageId - Storage the folder lies in
1061
+ * @param folderId - Folder from {@link EncryptedFoldersAPI.choose}
1062
+ * @param path - Path of the file, relative to the encrypted folder
1063
+ * @returns The decrypted content
1064
+ */
1065
+ async download(storageId, folderId, path) {
1066
+ const base64 = await this.client.request(
1067
+ ENCRYPTED_FOLDER_COMMANDS.download,
1068
+ { request: { storageId, folderId, path } }
1069
+ );
1070
+ return base64ToArrayBuffer(base64);
1071
+ }
1072
+ /**
1073
+ * Encrypt and upload a file (permission `readWrite`). Missing parent
1074
+ * folders are created.
1075
+ * @param storageId - Storage the folder lies in
1076
+ * @param folderId - Folder from {@link EncryptedFoldersAPI.choose}
1077
+ * @param path - Path of the file, relative to the encrypted folder
1078
+ * @param data - Content of the file
1079
+ */
1080
+ async upload(storageId, folderId, path, data) {
1081
+ await this.client.request(ENCRYPTED_FOLDER_COMMANDS.upload, {
1082
+ request: { storageId, folderId, path, data: arrayBufferToBase64(data) }
1083
+ });
1084
+ }
1085
+ /**
1086
+ * Delete a file or folder (permission `readWrite`).
1087
+ * @param storageId - Storage the folder lies in
1088
+ * @param folderId - Folder from {@link EncryptedFoldersAPI.choose}
1089
+ * @param path - Path relative to the encrypted folder
1090
+ */
1091
+ async delete(storageId, folderId, path) {
1092
+ await this.client.request(ENCRYPTED_FOLDER_COMMANDS.delete, {
1093
+ request: { storageId, folderId, path }
993
1094
  });
994
1095
  }
995
1096
  };
@@ -1592,6 +1693,195 @@ var DialogAPI = class {
1592
1693
  }
1593
1694
  };
1594
1695
 
1696
+ // src/api/tools/schema.ts
1697
+ function fail(field, message) {
1698
+ return { ok: false, field, message };
1699
+ }
1700
+ function typeMatches(type, value) {
1701
+ switch (type) {
1702
+ case "object":
1703
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1704
+ case "array":
1705
+ return Array.isArray(value);
1706
+ case "integer":
1707
+ return Number.isInteger(value);
1708
+ case "number":
1709
+ return typeof value === "number" && Number.isFinite(value);
1710
+ case "string":
1711
+ return typeof value === "string";
1712
+ case "boolean":
1713
+ return typeof value === "boolean";
1714
+ default:
1715
+ return false;
1716
+ }
1717
+ }
1718
+ function validateAt(schema, value, field) {
1719
+ if (!typeMatches(schema.type, value)) return fail(field, `expected ${String(schema.type)}`);
1720
+ if (schema.enum && !schema.enum.includes(value)) {
1721
+ return fail(field, `expected one of ${schema.enum.join(", ")}`);
1722
+ }
1723
+ if (schema.type === "array" && schema.items) {
1724
+ const items = value;
1725
+ for (let i = 0; i < items.length; i++) {
1726
+ const result = validateAt(schema.items, items[i], `${field}[${i}]`);
1727
+ if (!result.ok) return result;
1728
+ }
1729
+ }
1730
+ if (schema.type === "object") {
1731
+ const record = value;
1732
+ const properties = schema.properties ?? {};
1733
+ const prefix = field === "" ? "" : `${field}.`;
1734
+ if (schema.properties) {
1735
+ for (const key of Object.keys(record)) {
1736
+ if (!Object.hasOwn(properties, key)) return fail(`${prefix}${key}`, "unknown property");
1737
+ }
1738
+ }
1739
+ for (const key of schema.required ?? []) {
1740
+ if (record[key] === void 0) return fail(`${prefix}${key}`, "required");
1741
+ }
1742
+ for (const [key, child] of Object.entries(properties)) {
1743
+ if (record[key] === void 0) continue;
1744
+ const result = validateAt(child, record[key], `${prefix}${key}`);
1745
+ if (!result.ok) return result;
1746
+ }
1747
+ }
1748
+ return { ok: true };
1749
+ }
1750
+ function validateInput(schema, value) {
1751
+ return validateAt(schema, value, "");
1752
+ }
1753
+
1754
+ // src/api/tools/server.ts
1755
+ var PROTOCOL_VERSION = "2025-11-25";
1756
+ var METHOD_NOT_FOUND = -32601;
1757
+ var INVALID_PARAMS = -32602;
1758
+ function textResult(text, isError) {
1759
+ return { content: [{ type: "text", text }], isError };
1760
+ }
1761
+ function asText(value) {
1762
+ if (typeof value === "string") return value;
1763
+ if (value === void 0) return "";
1764
+ return JSON.stringify(value);
1765
+ }
1766
+ function isId(value) {
1767
+ return typeof value === "string" || typeof value === "number";
1768
+ }
1769
+ var ToolsServer = class {
1770
+ constructor(options) {
1771
+ this.options = options;
1772
+ this.running = /* @__PURE__ */ new Map();
1773
+ }
1774
+ /**
1775
+ * Handles one JSON-RPC message from the host. A tool call runs on its own and answers when it is
1776
+ * done, so a long call never holds up `ping` or the cancellation of that very call.
1777
+ */
1778
+ async receive(message) {
1779
+ if (typeof message !== "object" || message === null) return;
1780
+ const { id, method, params } = message;
1781
+ if (typeof method !== "string") return;
1782
+ const args = typeof params === "object" && params !== null ? params : {};
1783
+ if (!isId(id)) {
1784
+ if (method === "notifications/cancelled" && isId(args.requestId)) {
1785
+ this.running.get(args.requestId)?.abort();
1786
+ }
1787
+ return;
1788
+ }
1789
+ switch (method) {
1790
+ case "initialize":
1791
+ return this.reply(id, {
1792
+ protocolVersion: PROTOCOL_VERSION,
1793
+ capabilities: { tools: {} },
1794
+ serverInfo: {
1795
+ name: this.options.manifest?.name ?? "",
1796
+ version: this.options.manifest?.version ?? ""
1797
+ }
1798
+ });
1799
+ case "ping":
1800
+ return this.reply(id, {});
1801
+ case "tools/list": {
1802
+ const tools = this.tools().map(({ name, title, description, inputSchema }) => ({
1803
+ name,
1804
+ title: title.en,
1805
+ description,
1806
+ inputSchema
1807
+ }));
1808
+ return this.reply(id, { tools });
1809
+ }
1810
+ case "tools/call":
1811
+ void this.call(id, args);
1812
+ return;
1813
+ default:
1814
+ return this.error(id, METHOD_NOT_FOUND, method);
1815
+ }
1816
+ }
1817
+ /** The declared tools that have a handler. */
1818
+ tools() {
1819
+ return (this.options.manifest?.tools ?? []).filter((tool) => this.options.handlers.has(tool.name));
1820
+ }
1821
+ async call(id, params) {
1822
+ const tool = this.tools().find((candidate) => candidate.name === params.name);
1823
+ const handler = tool && this.options.handlers.get(tool.name);
1824
+ if (!tool || !handler) return this.error(id, INVALID_PARAMS, `unknown tool ${String(params.name)}`);
1825
+ const input = params.arguments ?? {};
1826
+ const checked = validateInput(tool.inputSchema, input);
1827
+ if (!checked.ok) {
1828
+ return this.reply(id, textResult(`invalid input: ${checked.field}: ${checked.message}`, true));
1829
+ }
1830
+ const controller = new AbortController();
1831
+ this.running.set(id, controller);
1832
+ let result;
1833
+ try {
1834
+ const output = await handler(input, { signal: controller.signal });
1835
+ result = textResult(asText(output), false);
1836
+ } catch (error) {
1837
+ result = textResult(error instanceof Error ? error.message : String(error), true);
1838
+ } finally {
1839
+ this.running.delete(id);
1840
+ }
1841
+ if (!controller.signal.aborted) this.reply(id, result);
1842
+ }
1843
+ reply(id, result) {
1844
+ this.options.send({ jsonrpc: "2.0", id, result });
1845
+ }
1846
+ error(id, code, message) {
1847
+ this.options.send({ jsonrpc: "2.0", id, error: { code, message } });
1848
+ }
1849
+ };
1850
+
1851
+ // src/api/tools/index.ts
1852
+ var ToolsAPI = class {
1853
+ constructor(options) {
1854
+ this.options = options;
1855
+ this.handlers = /* @__PURE__ */ new Map();
1856
+ const manifest = options.manifest;
1857
+ this.server = new ToolsServer({
1858
+ get manifest() {
1859
+ return manifest();
1860
+ },
1861
+ handlers: this.handlers,
1862
+ send: options.send
1863
+ });
1864
+ }
1865
+ /**
1866
+ * Runs `handler` when the host calls the tool `name`. The tool must be declared in the manifest.
1867
+ * Returns a function that unregisters the handler; the host then no longer sees the tool.
1868
+ */
1869
+ register(name, handler) {
1870
+ const declared = this.options.manifest()?.tools?.some((tool) => tool.name === name) ?? false;
1871
+ if (!declared) {
1872
+ throw new Error(`The tool ${name} is not declared in the manifest's tools`);
1873
+ }
1874
+ this.handlers.set(name, handler);
1875
+ return () => {
1876
+ if (this.handlers.get(name) === handler) this.handlers.delete(name);
1877
+ };
1878
+ }
1879
+ /** Handles one MCP message from the host. Called by the SDK for `haexspace:mcp` port messages. */
1880
+ receive(message) {
1881
+ return this.server.receive(message);
1882
+ }
1883
+ };
1884
+
1595
1885
  // src/messages.ts
1596
1886
  var HAEXSPACE_MESSAGE_TYPES = {
1597
1887
  /** Debug message for development/troubleshooting */
@@ -1614,7 +1904,14 @@ var HAEXSPACE_MESSAGE_TYPES = {
1614
1904
  *
1615
1905
  * Payload: `{ type: PORT_READY }` — no data.
1616
1906
  */
1617
- PORT_READY: "haexspace:port:ready"
1907
+ PORT_READY: "haexspace:port:ready",
1908
+ /**
1909
+ * One MCP message of the tool connection (holzi spec 018), in both directions over the
1910
+ * MessagePort: the host calls the extension's tools, `sdk.tools` answers.
1911
+ *
1912
+ * Payload: `{ type: MCP, message }`, where `message` is a JSON-RPC 2.0 object.
1913
+ */
1914
+ MCP: "haexspace:mcp"
1618
1915
  };
1619
1916
 
1620
1917
  // src/polyfills/consoleForwarding.ts
@@ -2060,7 +2357,11 @@ function createMessageHandler(config, pendingRequests, extensionInfo, onEvent) {
2060
2357
  }
2061
2358
  };
2062
2359
  }
2063
- function processEvent(event, log, eventListeners, onContextChanged, onExternalRequest, onActionRequest) {
2360
+ function processEvent(event, log, eventListeners, onContextChanged, onExternalRequest, onActionRequest, onMcpMessage) {
2361
+ if (event.type === HAEXSPACE_MESSAGE_TYPES.MCP) {
2362
+ onMcpMessage?.(event.message);
2363
+ return;
2364
+ }
2064
2365
  if (event.type === HAEXTENSION_EVENTS.CONTEXT_CHANGED) {
2065
2366
  const contextEvent = event;
2066
2367
  onContextChanged(contextEvent.data.context);
@@ -2326,6 +2627,7 @@ var HaexVaultSdk = class {
2326
2627
  this.web = new WebAPI(this);
2327
2628
  this.permissions = new PermissionsAPI(this);
2328
2629
  this.remoteStorage = new RemoteStorageAPI(this);
2630
+ this.encryptedFolders = new EncryptedFoldersAPI(this);
2329
2631
  this.localsend = new LocalSendAPI(this);
2330
2632
  this.spaces = new SpacesAPI(this);
2331
2633
  this.shell = new ShellAPI(this);
@@ -2334,6 +2636,10 @@ var HaexVaultSdk = class {
2334
2636
  this.notifications = new NotificationsAPI(this);
2335
2637
  this.tab = new TabAPI(this);
2336
2638
  this.dialog = new DialogAPI(this);
2639
+ this.tools = new ToolsAPI({
2640
+ manifest: () => this.config.manifest,
2641
+ send: (message) => this.sendMcpMessage(message)
2642
+ });
2337
2643
  installConsoleForwarding(this.config.debug);
2338
2644
  this.on(HAEXTENSION_EVENTS.PERMISSION_RESOLVED, (event) => {
2339
2645
  const data = event.data;
@@ -2641,9 +2947,18 @@ var HaexVaultSdk = class {
2641
2947
  this.notifySubscribersInternal();
2642
2948
  },
2643
2949
  (extEvent) => this.handleExternalRequestInternal(extEvent.data),
2644
- (actionEvent) => this.handleActionRequestInternal(actionEvent.data)
2950
+ (actionEvent) => this.handleActionRequestInternal(actionEvent.data),
2951
+ (message) => void this.tools.receive(message)
2645
2952
  );
2646
2953
  }
2954
+ /** Sends one MCP message of the tool connection to the host on the port. */
2955
+ sendMcpMessage(message) {
2956
+ if (!this.hostPort) {
2957
+ this.log("Dropped an MCP message: no host port yet");
2958
+ return;
2959
+ }
2960
+ this.hostPort.postMessage({ type: HAEXSPACE_MESSAGE_TYPES.MCP, message });
2961
+ }
2647
2962
  async handleExternalRequestInternal(request) {
2648
2963
  await handleExternalRequest(request, this.externalRequestHandlers, this.respondToExternalRequest.bind(this), this.log.bind(this));
2649
2964
  }