@deepseek-ai/libreoffice-kit 0.2.3-rc.3 → 0.2.3-rc.4

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/README.md CHANGED
@@ -106,6 +106,18 @@ The Node API reports its release version through `ENGINE_VERSION`; `ENGINE_VERSI
106
106
 
107
107
  Defaults and all options are documented in the shipped TypeScript declarations in `lib/types/index.d.ts`. Font directories use conventional system/user paths for the selected OS. Indexing skips missing or protected sources and propagates other filesystem errors. `fontkit` indexes original font files and selects installed faces and glyph coverage; it does not rewrite fonts. Each operation discovers font candidates again and revalidates cached file identities. It uses one ordered metadata snapshot; matching entries are invalidated when that snapshot changes. A detected font change during conversion rejects the operation and removes its output. Glyph matching queries only requested Unicode scalars and shares decoding across faces in one physical font collection. It retains scalar answers within the operation and releases each parsed file before examining another; it does not enumerate every glyph or cache font bytes across documents. `missingFonts` contains absent families declared in readable document XML, excluding unrelated engine defaults. Missing glyphs without a named missing family are not a complete document accessibility report.
108
108
 
109
+ ### Engine package resolver
110
+
111
+ By default the adapter locates engine packages with Node module resolution from its own installation. Applications whose engine files live elsewhere on disk pass `resolveEnginePackage` in the options of `createConverter()`, `createConverterFactory()`, `openDocument({ options })`, and `discoverRuntime()`. `discoverRuntime()` accepts and validates the same options object as `createConverter()`, so one object can serve every entry point and all of them select the same engine. The option type is `EnginePackageResolver = (name: string) => string`:
112
+
113
+ - `name` is the platform package (`@deepseek-ai/libreoffice-kit-<target>`) when the host has a native target, then `@deepseek-ai/libreoffice-kit-wasm` if WASM is selected.
114
+ - Return the absolute path of that package's `package.json` synchronously. A relative path, a missing path, a path that is not a file, or a non-string result is an error; it never falls back to WASM.
115
+ - To report that the native package is absent, throw an error whose `code` is `MODULE_NOT_FOUND`, as `require.resolve` does. WASM is then selected through the same resolver. Any other thrown value is an error.
116
+ - The resolver alone decides whether its packages exist: the adapter does not probe its own installation for a package the resolver reports missing. Throw a different error to report a present but incomplete package.
117
+ - Converters, factories, and `discoverRuntime()` reject these errors as `ConversionError` with code `unavailable` and the original error as `cause`. `openDocument()` rejects with the original error, as it does for its other engine errors.
118
+
119
+ The adapter still selects the platform target, applies glibc floors, and validates the version pin and engine assets of the resolved package. The resolver runs on the caller's thread and is not passed to conversion workers. An Electron example is in the [packaging guide](https://github.com/deepseek-ai/dsh-libreoffice-kit/blob/master/docs/packaging.md#engine-package-resolver-for-electron-applications).
120
+
109
121
  ### Font metadata cache
110
122
 
111
123
  Both `createConverter()` and `createConverterFactory()` accept:
package/README.zh.md CHANGED
@@ -106,6 +106,18 @@ Node API 通过 `ENGINE_VERSION` 报告其发布版本;`ENGINE_VERSIONS` 独
106
106
 
107
107
  默认值和所有选项记录在随包发布的 `lib/types/index.d.ts` 类型声明中。字体目录使用所选操作系统的常规系统/用户路径。索引会跳过缺失或受保护的来源,并传播其他文件系统错误。`fontkit` 索引原始字体文件并选择已安装的字面和字形覆盖;它不重写字体。每次操作都会重新发现字体候选并验证缓存中的文件身份。一次操作使用一份有序元数据快照;快照变化后字体匹配条目失效。检测到转换期间字体变化时,操作会失败并删除其输出。字形匹配仅查询请求中的 Unicode 码点,同一物理字体集合中的各字面共享一次解码。码点查询结果只在本次操作内保留,开始检查下一文件前释放当前解析对象;不会遍历所有字形,也不会跨文档缓存字体字节。精确的 family 匹配优先于 `fontFallbacks`。`missingFonts` 包含可读文档 XML 中声明但缺失的 family,不包含无关的引擎默认值。未命名缺失 family 的缺字并不构成完整的文档可访问性报告。
108
108
 
109
+ ### 引擎包解析器
110
+
111
+ 默认情况下,适配器从自身安装位置按 Node 模块解析查找引擎包。引擎文件位于其他磁盘位置的应用,可在 `createConverter()`、`createConverterFactory()`、`openDocument({ options })` 和 `discoverRuntime()` 的选项中传入 `resolveEnginePackage`。`discoverRuntime()` 接受并按相同规则校验与 `createConverter()` 相同的选项对象,因此各入口可共用同一个对象并选择同一引擎。选项类型为 `EnginePackageResolver = (name: string) => string`:
112
+
113
+ - 宿主有原生目标时,`name` 先是平台包(`@deepseek-ai/libreoffice-kit-<target>`);选择 WASM 时为 `@deepseek-ai/libreoffice-kit-wasm`。
114
+ - 同步返回该包 `package.json` 的绝对路径。返回相对路径、不存在的路径、非文件路径或非字符串结果均视为错误,不会回退到 WASM。
115
+ - 要表示原生包不存在,抛出 `code` 为 `MODULE_NOT_FOUND` 的错误(与 `require.resolve` 一致);随后通过同一解析器选择 WASM。抛出其他值均视为错误。
116
+ - 包是否存在只由解析器决定:解析器报告缺失的包,适配器不会再检查自身安装位置。要报告包存在但不完整,请抛出其他错误。
117
+ - 转换器、factory 和 `discoverRuntime()` 以 code 为 `unavailable` 的 `ConversionError` 拒绝上述错误,原始错误保留在 `cause` 中。`openDocument()` 与其处理其他引擎错误的方式一致,直接以原始错误拒绝。
118
+
119
+ 适配器仍负责选择平台目标、应用 glibc 下限,并校验所解析包的版本固定与引擎资源。解析器在调用方线程运行,不会传入转换 Worker。Electron 示例见[打包指南](https://github.com/deepseek-ai/dsh-libreoffice-kit/blob/master/docs/packaging.md#engine-package-resolver-for-electron-applications)。
120
+
109
121
  ### 字体元数据缓存
110
122
 
111
123
  `createConverter()` 和 `createConverterFactory()` 均接受:
@@ -13,16 +13,16 @@
13
13
  "src/win-delay-load.LICENSE": "662a1b0115251cfb29c6aed0f221f8847bc49c6365d1c53a62c9f4bccc2489c3",
14
14
  "src/graphite-interop.cc": "4f2de8e9ad4bd1aef9220c95d3660937980893f12af006116bed720e7dfaf013",
15
15
  "CMakeLists.txt": "90e821d3718037a60d989b80bc156cb4cc267d66487139e81cf568cb8a54d344",
16
- "sdk.json": "b9131060566f8d61b9148ef41d9ea68c8573477f0471d7579ff06520124cec14",
16
+ "sdk.json": "05d5fdf0845272540838c9ce3c453f60391f9c344c8048691ffdba5dc0a37e17",
17
17
  "scripts/build.mjs": "0824c5975106ce2101026d3c7f451643fe28e358b8bff644739fe7614e82c6fa",
18
18
  "scripts/metadata.mjs": "a4848f50df31eb905dba1feb5d7df9fed60af4213c14f6ace7f40c5d066ab20c",
19
19
  "scripts/source-identity.mjs": "e8360e59c4c83eeb4110d3a1c278d330f4a2d20b87edefb1f1e527dc17301602",
20
20
  "scripts/build-webgpu.mjs": "919d40e78b7f5d3e2a7de6d5d2e46ca4a26bcce18f98abc1220c59f8cb79ebdd",
21
21
  "webgpu-dependencies.json": "99fd5b4763f3621ffe72290ca5ddaa9c26f8d2404b54c9158f20f6fd29a403c2"
22
22
  },
23
- "sourceCommit": "5fef7979af12af8b95ade5360e41afb4c6256049",
23
+ "sourceCommit": "ba41be02572d5d0f550f122bd3aaaf7f81af1518",
24
24
  "sourceDirty": false,
25
- "version": "0.2.3-rc.3",
25
+ "version": "0.2.3-rc.4",
26
26
  "protocolVersion": 1,
27
27
  "capabilities": [
28
28
  "transferable-tx",
@@ -31,6 +31,6 @@
31
31
  "platform": "darwin-arm64",
32
32
  "files": {
33
33
  "frame-forwarding.node": "4682ac70dc8c02e17e659a1cd28e4dda7db44b7ff6a939bf46f5436e4fb91a5b",
34
- "libdsh_frame_forwarding_sdk.a": "648f776b02da2207b142f0f5284954387f260f55fd819398c750df037e171dff"
34
+ "libdsh_frame_forwarding_sdk.a": "6dcd2f07a9a019bd493a5a124686bc284bfdcbbcc75a2fc9eed5f12099ae9f2c"
35
35
  }
36
36
  }
@@ -13,16 +13,16 @@
13
13
  "src/win-delay-load.LICENSE": "662a1b0115251cfb29c6aed0f221f8847bc49c6365d1c53a62c9f4bccc2489c3",
14
14
  "src/graphite-interop.cc": "4f2de8e9ad4bd1aef9220c95d3660937980893f12af006116bed720e7dfaf013",
15
15
  "CMakeLists.txt": "90e821d3718037a60d989b80bc156cb4cc267d66487139e81cf568cb8a54d344",
16
- "sdk.json": "b9131060566f8d61b9148ef41d9ea68c8573477f0471d7579ff06520124cec14",
16
+ "sdk.json": "05d5fdf0845272540838c9ce3c453f60391f9c344c8048691ffdba5dc0a37e17",
17
17
  "scripts/build.mjs": "0824c5975106ce2101026d3c7f451643fe28e358b8bff644739fe7614e82c6fa",
18
18
  "scripts/metadata.mjs": "a4848f50df31eb905dba1feb5d7df9fed60af4213c14f6ace7f40c5d066ab20c",
19
19
  "scripts/source-identity.mjs": "e8360e59c4c83eeb4110d3a1c278d330f4a2d20b87edefb1f1e527dc17301602",
20
20
  "scripts/build-webgpu.mjs": "919d40e78b7f5d3e2a7de6d5d2e46ca4a26bcce18f98abc1220c59f8cb79ebdd",
21
21
  "webgpu-dependencies.json": "99fd5b4763f3621ffe72290ca5ddaa9c26f8d2404b54c9158f20f6fd29a403c2"
22
22
  },
23
- "sourceCommit": "5fef7979af12af8b95ade5360e41afb4c6256049",
23
+ "sourceCommit": "ba41be02572d5d0f550f122bd3aaaf7f81af1518",
24
24
  "sourceDirty": false,
25
- "version": "0.2.3-rc.3",
25
+ "version": "0.2.3-rc.4",
26
26
  "protocolVersion": 1,
27
27
  "capabilities": [
28
28
  "transferable-tx",
@@ -31,6 +31,6 @@
31
31
  "platform": "darwin-x64",
32
32
  "files": {
33
33
  "frame-forwarding.node": "ca36836fabbf9217102eab0226e3590984f34491b044a7ef7587e06cca877ed4",
34
- "libdsh_frame_forwarding_sdk.a": "6960028758e3ff792159d2ee29154fac636e714ae4ee601bc43e4cdef3bab305"
34
+ "libdsh_frame_forwarding_sdk.a": "46c47bed559cfa36c734693dc58a8a8342bded73901592fc01be3ba2c4eefc3c"
35
35
  }
36
36
  }
@@ -13,16 +13,16 @@
13
13
  "src/win-delay-load.LICENSE": "662a1b0115251cfb29c6aed0f221f8847bc49c6365d1c53a62c9f4bccc2489c3",
14
14
  "src/graphite-interop.cc": "4f2de8e9ad4bd1aef9220c95d3660937980893f12af006116bed720e7dfaf013",
15
15
  "CMakeLists.txt": "90e821d3718037a60d989b80bc156cb4cc267d66487139e81cf568cb8a54d344",
16
- "sdk.json": "b9131060566f8d61b9148ef41d9ea68c8573477f0471d7579ff06520124cec14",
16
+ "sdk.json": "05d5fdf0845272540838c9ce3c453f60391f9c344c8048691ffdba5dc0a37e17",
17
17
  "scripts/build.mjs": "0824c5975106ce2101026d3c7f451643fe28e358b8bff644739fe7614e82c6fa",
18
18
  "scripts/metadata.mjs": "a4848f50df31eb905dba1feb5d7df9fed60af4213c14f6ace7f40c5d066ab20c",
19
19
  "scripts/source-identity.mjs": "e8360e59c4c83eeb4110d3a1c278d330f4a2d20b87edefb1f1e527dc17301602",
20
20
  "scripts/build-webgpu.mjs": "919d40e78b7f5d3e2a7de6d5d2e46ca4a26bcce18f98abc1220c59f8cb79ebdd",
21
21
  "webgpu-dependencies.json": "99fd5b4763f3621ffe72290ca5ddaa9c26f8d2404b54c9158f20f6fd29a403c2"
22
22
  },
23
- "sourceCommit": "5fef7979af12af8b95ade5360e41afb4c6256049",
23
+ "sourceCommit": "ba41be02572d5d0f550f122bd3aaaf7f81af1518",
24
24
  "sourceDirty": false,
25
- "version": "0.2.3-rc.3",
25
+ "version": "0.2.3-rc.4",
26
26
  "protocolVersion": 1,
27
27
  "capabilities": [
28
28
  "transferable-tx",
@@ -30,7 +30,7 @@
30
30
  ],
31
31
  "platform": "win32-arm64",
32
32
  "files": {
33
- "frame-forwarding.node": "d5e3ea5e08a85559b10bd67c54633e3dad9e2fe2212a405c8e06a7469f122478",
34
- "dsh_frame_forwarding_sdk.lib": "3fde9f1fcec256e96ffaeac64b0e6894f9cbaea9835824a5023ca8566fa424f1"
33
+ "frame-forwarding.node": "c3dec1215309909564755b4f97d5560a5417ae4299ea4d6af60859be88197487",
34
+ "dsh_frame_forwarding_sdk.lib": "1442d0b93d13aaa9a4cd1aef8875a042eb5d4f13d471822381fd8001d72cbc3a"
35
35
  }
36
36
  }
@@ -13,16 +13,16 @@
13
13
  "src/win-delay-load.LICENSE": "662a1b0115251cfb29c6aed0f221f8847bc49c6365d1c53a62c9f4bccc2489c3",
14
14
  "src/graphite-interop.cc": "4f2de8e9ad4bd1aef9220c95d3660937980893f12af006116bed720e7dfaf013",
15
15
  "CMakeLists.txt": "90e821d3718037a60d989b80bc156cb4cc267d66487139e81cf568cb8a54d344",
16
- "sdk.json": "b9131060566f8d61b9148ef41d9ea68c8573477f0471d7579ff06520124cec14",
16
+ "sdk.json": "05d5fdf0845272540838c9ce3c453f60391f9c344c8048691ffdba5dc0a37e17",
17
17
  "scripts/build.mjs": "0824c5975106ce2101026d3c7f451643fe28e358b8bff644739fe7614e82c6fa",
18
18
  "scripts/metadata.mjs": "a4848f50df31eb905dba1feb5d7df9fed60af4213c14f6ace7f40c5d066ab20c",
19
19
  "scripts/source-identity.mjs": "e8360e59c4c83eeb4110d3a1c278d330f4a2d20b87edefb1f1e527dc17301602",
20
20
  "scripts/build-webgpu.mjs": "919d40e78b7f5d3e2a7de6d5d2e46ca4a26bcce18f98abc1220c59f8cb79ebdd",
21
21
  "webgpu-dependencies.json": "99fd5b4763f3621ffe72290ca5ddaa9c26f8d2404b54c9158f20f6fd29a403c2"
22
22
  },
23
- "sourceCommit": "5fef7979af12af8b95ade5360e41afb4c6256049",
23
+ "sourceCommit": "ba41be02572d5d0f550f122bd3aaaf7f81af1518",
24
24
  "sourceDirty": false,
25
- "version": "0.2.3-rc.3",
25
+ "version": "0.2.3-rc.4",
26
26
  "protocolVersion": 1,
27
27
  "capabilities": [
28
28
  "transferable-tx",
@@ -30,7 +30,7 @@
30
30
  ],
31
31
  "platform": "win32-x64",
32
32
  "files": {
33
- "frame-forwarding.node": "d9a232670e54f678220caf855f0ddc339d1c6b9aede2d3042270b7581992c0be",
34
- "dsh_frame_forwarding_sdk.lib": "af9f399f856f208364bc2b3cf6ef3935168b62662d6030dbc3ab41daee66f271"
33
+ "frame-forwarding.node": "e11cb4c485de307d9f0ba63e310ae1bb10decf1001ac84b524238c24f6bf6e15",
34
+ "dsh_frame_forwarding_sdk.lib": "cee40c709874a84b6b895d863c732593c8cd48cd27b246f0365632e45a924775"
35
35
  }
36
36
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "package": "@deepseek-ai/libreoffice-kit",
3
- "version": "0.2.3-rc.3",
3
+ "version": "0.2.3-rc.4",
4
4
  "protocolVersion": 1,
5
5
  "capabilities": [
6
6
  "transferable-tx",
@@ -9,7 +9,7 @@
9
9
  "files": {
10
10
  "LICENSE": "ebb4f09972aee8608be255debaf78451a68e95c290f55c240dec2ecfa16ea6be",
11
11
  "CMakeLists.txt": "90e821d3718037a60d989b80bc156cb4cc267d66487139e81cf568cb8a54d344",
12
- "sdk.json": "b9131060566f8d61b9148ef41d9ea68c8573477f0471d7579ff06520124cec14",
12
+ "sdk.json": "05d5fdf0845272540838c9ce3c453f60391f9c344c8048691ffdba5dc0a37e17",
13
13
  "scripts/metadata.mjs": "a4848f50df31eb905dba1feb5d7df9fed60af4213c14f6ace7f40c5d066ab20c",
14
14
  "webgpu-dependencies.json": "99fd5b4763f3621ffe72290ca5ddaa9c26f8d2404b54c9158f20f6fd29a403c2",
15
15
  "scripts/build-webgpu.mjs": "919d40e78b7f5d3e2a7de6d5d2e46ca4a26bcce18f98abc1220c59f8cb79ebdd",
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.2.3-rc.3",
2
+ "version": "0.2.3-rc.4",
3
3
  "protocolVersion": 1,
4
4
  "capabilities": [
5
5
  "transferable-tx",
package/lib/cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { createRequire } from "node:module";
3
3
  import { parseArgs } from "node:util";
4
4
  import { dirname, extname, isAbsolute, join, posix, relative, resolve, sep, win32 } from "node:path";
5
- import { closeSync, constants, createWriteStream, lstatSync, readSync, readdirSync } from "node:fs";
5
+ import { closeSync, constants, createWriteStream, lstatSync, readSync, readdirSync, statSync } from "node:fs";
6
6
  import { copyFile, lstat, mkdir, mkdtemp, open, readFile, rm, stat, symlink, unlink, writeFile } from "node:fs/promises";
7
7
  import { homedir, tmpdir } from "node:os";
8
8
  import { Worker } from "node:worker_threads";
@@ -51,6 +51,14 @@ function failureCode(error) {
51
51
  const code = error?.code;
52
52
  return typeof code === "string" && CODES.has(code) ? code : "failed";
53
53
  }
54
+ /**
55
+ * Describe any thrown value, including caller callbacks that throw non-Error values.
56
+ * @param error - The thrown value.
57
+ * @returns The Error message, or the value's string form.
58
+ */
59
+ function failureMessage(error) {
60
+ return error instanceof Error ? error.message : String(error);
61
+ }
54
62
  //#endregion
55
63
  //#region lib/types/sheet-geometry.js
56
64
  const MAX_COLUMN = 16383;
@@ -1494,10 +1502,20 @@ function fontGroups(value) {
1494
1502
  return value.map((group) => [...group]);
1495
1503
  }
1496
1504
  /**
1505
+ * Validate an optional caller-supplied engine package resolver.
1506
+ * @param value - The `resolveEnginePackage` option value.
1507
+ * @returns the resolver, or undefined when absent.
1508
+ * @throws TypeError when the value is defined and not a function.
1509
+ */
1510
+ function enginePackageResolver(value) {
1511
+ if (value !== void 0 && typeof value !== "function") throw new TypeError("resolveEnginePackage must be a function.");
1512
+ return value;
1513
+ }
1514
+ /**
1497
1515
  * Resolve defaults once; reject misspelled options and malformed font settings.
1498
1516
  * @param input - Caller options; absent fields keep their documented default.
1499
1517
  * @returns The validated limits and font settings, with caller arrays copied.
1500
- * @throws TypeError for a non-object argument or an unknown option name.
1518
+ * @throws TypeError for a non-object argument, an unknown option name, or a non-function `resolveEnginePackage`.
1501
1519
  * @throws RangeError for a limit outside the positive safe-integer timer range.
1502
1520
  */
1503
1521
  function resolveOptions(input = {}) {
@@ -1510,7 +1528,8 @@ function resolveOptions(input = {}) {
1510
1528
  initialFontFamilies: [],
1511
1529
  ...input
1512
1530
  };
1513
- for (const key of Object.keys(input)) if (!(key in DEFAULT_LIMITS) && !FONT_COLLECTION_NAMES.includes(key) && key !== "fontFallbacks" && key !== "fontMetadataCacheDirectory") throw new TypeError(`Unknown converter option: ${key}`);
1531
+ for (const key of Object.keys(input)) if (!(key in DEFAULT_LIMITS) && !FONT_COLLECTION_NAMES.includes(key) && key !== "fontFallbacks" && key !== "fontMetadataCacheDirectory" && key !== "resolveEnginePackage") throw new TypeError(`Unknown converter option: ${key}`);
1532
+ enginePackageResolver(input.resolveEnginePackage);
1514
1533
  const cacheDirectory = input.fontMetadataCacheDirectory === void 0 ? defaultFontMetadataCacheDirectory() : input.fontMetadataCacheDirectory;
1515
1534
  if (cacheDirectory !== false && (typeof cacheDirectory !== "string" || !isAbsolute(cacheDirectory) || cacheDirectory.includes("\0"))) throw new TypeError("fontMetadataCacheDirectory must be an absolute path or false.");
1516
1535
  return {
@@ -1537,16 +1556,16 @@ function resolveOptions(input = {}) {
1537
1556
  /** Resolve installed, version-matched engine packages without downloads or compilation. */
1538
1557
  const require = createRequire(import.meta.url);
1539
1558
  /** Node API release version returned by runtime discovery. */
1540
- const ENGINE_VERSION = "0.2.3-rc.3";
1559
+ const ENGINE_VERSION = "0.2.3-rc.4";
1541
1560
  /** Exact compatible engine versions; unchanged platforms retain their published packages. */
1542
1561
  const ENGINE_VERSIONS = Object.freeze({
1543
- "darwin-arm64": "0.2.3-rc.3",
1544
- "darwin-x64": "0.2.3-rc.3",
1562
+ "darwin-arm64": "0.2.3-rc.4",
1563
+ "darwin-x64": "0.2.3-rc.4",
1545
1564
  "linux-arm64-glibc": "0.1.1",
1546
1565
  "linux-x64-glibc": "0.1.1",
1547
- "win32-arm64": "0.2.3-rc.3",
1548
- "win32-x64": "0.2.3-rc.3",
1549
- wasm: "0.2.3-rc.3"
1566
+ "win32-arm64": "0.2.3-rc.4",
1567
+ "win32-x64": "0.2.3-rc.4",
1568
+ wasm: "0.2.3-rc.4"
1550
1569
  });
1551
1570
  /** npm scope and name prefix shared by the engine packages this adapter installs. */
1552
1571
  const ENGINE_PREFIX = "@deepseek-ai/libreoffice-kit";
@@ -1584,24 +1603,49 @@ function asset(root, value) {
1584
1603
  function glibcVersion(value) {
1585
1604
  return typeof value === "string" && /^(0|[1-9]\d*)\.(0|[1-9]\d*)(?:\.(0|[1-9]\d*))?$/.test(value) && value.split(".").every((part) => Number.isSafeInteger(Number(part))) ? value.split(".").map(Number) : void 0;
1586
1605
  }
1606
+ /** Resolve engine packages from this module's installation with Node module resolution. */
1607
+ function installedEnginePackage(name) {
1608
+ return require.resolve(`${name}/package.json`);
1609
+ }
1610
+ /**
1611
+ * Check one resolved engine `package.json` path before reading it.
1612
+ * @param packageFile - Value the resolver returned.
1613
+ * @param name - Engine package name.
1614
+ * @returns the path unchanged.
1615
+ * @throws Error when the value is not an absolute path to an existing file.
1616
+ */
1617
+ function resolvedManifest(packageFile, name) {
1618
+ if (typeof packageFile !== "string") throw new Error(`Engine package resolver must synchronously return a string path for ${name}; it returned ${packageFile === null ? "null" : typeof packageFile}`);
1619
+ if (!isAbsolute(packageFile)) throw new Error(`Engine package resolver returned a non-absolute path for ${name}: ${String(packageFile)}`);
1620
+ let file;
1621
+ try {
1622
+ file = statSync(packageFile).isFile();
1623
+ } catch (error) {
1624
+ throw new Error(`Engine package resolver returned a missing path for ${name}: ${packageFile}`, { cause: error });
1625
+ }
1626
+ if (!file) throw new Error(`Engine package resolver returned a path that is not a file for ${name}: ${packageFile}`);
1627
+ return packageFile;
1628
+ }
1587
1629
  /**
1588
1630
  * Prefer the installed compatible native engine; hosts without one use the shared WASM package.
1589
- * @param resolvePackage - Package manifest resolver; injectable for selection tests.
1590
- * @param packageExists - Installed-package probe; injectable for selection tests.
1631
+ * @param resolvePackage - Engine package manifest resolver; defaults to Node resolution from this module.
1632
+ * @param packageExists - Whether a native package that resolved as `MODULE_NOT_FOUND` is nevertheless installed (and
1633
+ * therefore incomplete). Only the default resolver probes this module's installation; a caller resolver is the sole
1634
+ * authority on whether its packages exist.
1591
1635
  * @param host - Process identification and diagnostic report.
1592
1636
  * @returns the installed native engine, or the installed WASM engine.
1593
1637
  */
1594
- async function resolveEngine(resolvePackage = (name) => require.resolve(`${name}/package.json`), packageExists = installedPackageExists, { platform = process.platform, arch = process.arch, report = hostReport } = {}) {
1638
+ async function resolveEngine(resolvePackage = installedEnginePackage, packageExists = resolvePackage === installedEnginePackage ? installedPackageExists : () => false, { platform = process.platform, arch = process.arch, report = hostReport } = {}) {
1595
1639
  const details = platform === "linux" ? report() : {};
1596
1640
  const target = platformTarget(platform, arch, () => details);
1597
1641
  if (target !== void 0) {
1598
1642
  const name = `${ENGINE_PREFIX}-${target}`;
1599
1643
  let packageFile;
1600
1644
  try {
1601
- packageFile = resolvePackage(name);
1645
+ packageFile = resolvedManifest(resolvePackage(name), name);
1602
1646
  } catch (error) {
1603
1647
  const failure = error;
1604
- if (!(failure?.code === "MODULE_NOT_FOUND" && typeof failure.message === "string" && failure.message.includes(`${name}/package.json`))) throw error;
1648
+ if (!(failure?.code === "MODULE_NOT_FOUND" && (resolvePackage !== installedEnginePackage || typeof failure.message === "string" && failure.message.includes(`${name}/package.json`)))) throw error;
1605
1649
  if (packageExists(name)) throw new Error(`Installed LibreOfficeKit package is incomplete: ${name}`, { cause: error });
1606
1650
  }
1607
1651
  if (packageFile !== void 0) {
@@ -1611,7 +1655,8 @@ async function resolveEngine(resolvePackage = (name) => require.resolve(`${name}
1611
1655
  if (!(minimum && host && minimum.some((part, index) => part > (host[index] ?? 0) && minimum.slice(0, index).every((prior, priorIndex) => prior === host[priorIndex])))) return engine;
1612
1656
  }
1613
1657
  }
1614
- return readEngine(resolvePackage(`${ENGINE_PREFIX}-wasm`), "wasm", "wasm");
1658
+ const wasm = `${ENGINE_PREFIX}-wasm`;
1659
+ return readEngine(resolvedManifest(resolvePackage(wasm), wasm), "wasm", "wasm");
1615
1660
  }
1616
1661
  async function engineAsset(root, value, name, kind) {
1617
1662
  const path = asset(root, value);
@@ -1812,12 +1857,16 @@ function pdfPageCount(bytes) {
1812
1857
  /** Offline discovery of the installed engine and public entry points. */
1813
1858
  /**
1814
1859
  * Inspect installed engine metadata without starting, downloading, or building an engine.
1860
+ * @param options - The options of a later createConverter call, validated the same way; only `resolveEnginePackage`
1861
+ * affects discovery, so both select the same engine.
1815
1862
  * @returns Public entry paths, Node API version, and selected backend.
1863
+ * @throws TypeError or RangeError for options createConverter would reject.
1816
1864
  * @throws ConversionError when the installed engine is unavailable or invalid.
1817
1865
  */
1818
- async function discoverRuntime() {
1866
+ async function discoverRuntime(options) {
1867
+ resolveOptions(options);
1819
1868
  try {
1820
- const engine = await resolveEngine();
1869
+ const engine = await resolveEngine(options?.resolveEnginePackage);
1821
1870
  return {
1822
1871
  version: ENGINE_VERSION,
1823
1872
  backend: engine.backend,
@@ -1826,7 +1875,7 @@ async function discoverRuntime() {
1826
1875
  nodeApiPath: fileURLToPath(new URL("./index.js", import.meta.url))
1827
1876
  };
1828
1877
  } catch (cause) {
1829
- throw new ConversionError("unavailable", cause.message, { cause });
1878
+ throw new ConversionError("unavailable", failureMessage(cause), { cause });
1830
1879
  }
1831
1880
  }
1832
1881
  //#endregion
@@ -2029,9 +2078,9 @@ async function resolveConverter(options) {
2029
2078
  const resolvedOptions = resolveOptions(options);
2030
2079
  let engine;
2031
2080
  try {
2032
- engine = await resolveEngine();
2081
+ engine = await resolveEngine(options?.resolveEnginePackage);
2033
2082
  } catch (cause) {
2034
- throw new ConversionError("unavailable", cause.message, { cause });
2083
+ throw new ConversionError("unavailable", failureMessage(cause), { cause });
2035
2084
  }
2036
2085
  return {
2037
2086
  options: resolvedOptions,
package/lib/editor.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createRequire } from "node:module";
2
2
  import { copyFile, mkdir, mkdtemp, readFile, rm, stat, symlink, unlink, writeFile } from "node:fs/promises";
3
- import { closeSync, constants, createWriteStream, fstatSync, lstatSync, openSync, readSync, readdirSync, writeFileSync } from "node:fs";
3
+ import { closeSync, constants, createWriteStream, fstatSync, lstatSync, openSync, readSync, readdirSync, statSync, writeFileSync } from "node:fs";
4
4
  import { homedir, tmpdir } from "node:os";
5
5
  import { basename, dirname, extname, isAbsolute, join, posix, relative, resolve, sep, win32 } from "node:path";
6
6
  import { pathToFileURL } from "node:url";
@@ -431,10 +431,20 @@ function fontGroups(value) {
431
431
  return value.map((group) => [...group]);
432
432
  }
433
433
  /**
434
+ * Validate an optional caller-supplied engine package resolver.
435
+ * @param value - The `resolveEnginePackage` option value.
436
+ * @returns the resolver, or undefined when absent.
437
+ * @throws TypeError when the value is defined and not a function.
438
+ */
439
+ function enginePackageResolver(value) {
440
+ if (value !== void 0 && typeof value !== "function") throw new TypeError("resolveEnginePackage must be a function.");
441
+ return value;
442
+ }
443
+ /**
434
444
  * Resolve defaults once; reject misspelled options and malformed font settings.
435
445
  * @param input - Caller options; absent fields keep their documented default.
436
446
  * @returns The validated limits and font settings, with caller arrays copied.
437
- * @throws TypeError for a non-object argument or an unknown option name.
447
+ * @throws TypeError for a non-object argument, an unknown option name, or a non-function `resolveEnginePackage`.
438
448
  * @throws RangeError for a limit outside the positive safe-integer timer range.
439
449
  */
440
450
  function resolveOptions(input = {}) {
@@ -447,7 +457,8 @@ function resolveOptions(input = {}) {
447
457
  initialFontFamilies: [],
448
458
  ...input
449
459
  };
450
- for (const key of Object.keys(input)) if (!(key in DEFAULT_LIMITS) && !FONT_COLLECTION_NAMES.includes(key) && key !== "fontFallbacks" && key !== "fontMetadataCacheDirectory") throw new TypeError(`Unknown converter option: ${key}`);
460
+ for (const key of Object.keys(input)) if (!(key in DEFAULT_LIMITS) && !FONT_COLLECTION_NAMES.includes(key) && key !== "fontFallbacks" && key !== "fontMetadataCacheDirectory" && key !== "resolveEnginePackage") throw new TypeError(`Unknown converter option: ${key}`);
461
+ enginePackageResolver(input.resolveEnginePackage);
451
462
  const cacheDirectory = input.fontMetadataCacheDirectory === void 0 ? defaultFontMetadataCacheDirectory() : input.fontMetadataCacheDirectory;
452
463
  if (cacheDirectory !== false && (typeof cacheDirectory !== "string" || !isAbsolute(cacheDirectory) || cacheDirectory.includes("\0"))) throw new TypeError("fontMetadataCacheDirectory must be an absolute path or false.");
453
464
  return {
@@ -475,13 +486,13 @@ function resolveOptions(input = {}) {
475
486
  const require = createRequire(import.meta.url);
476
487
  /** Exact compatible engine versions; unchanged platforms retain their published packages. */
477
488
  const ENGINE_VERSIONS = Object.freeze({
478
- "darwin-arm64": "0.2.3-rc.3",
479
- "darwin-x64": "0.2.3-rc.3",
489
+ "darwin-arm64": "0.2.3-rc.4",
490
+ "darwin-x64": "0.2.3-rc.4",
480
491
  "linux-arm64-glibc": "0.1.1",
481
492
  "linux-x64-glibc": "0.1.1",
482
- "win32-arm64": "0.2.3-rc.3",
483
- "win32-x64": "0.2.3-rc.3",
484
- wasm: "0.2.3-rc.3"
493
+ "win32-arm64": "0.2.3-rc.4",
494
+ "win32-x64": "0.2.3-rc.4",
495
+ wasm: "0.2.3-rc.4"
485
496
  });
486
497
  /** npm scope and name prefix shared by the engine packages this adapter installs. */
487
498
  const ENGINE_PREFIX = "@deepseek-ai/libreoffice-kit";
@@ -519,24 +530,49 @@ function asset(root, value) {
519
530
  function glibcVersion(value) {
520
531
  return typeof value === "string" && /^(0|[1-9]\d*)\.(0|[1-9]\d*)(?:\.(0|[1-9]\d*))?$/.test(value) && value.split(".").every((part) => Number.isSafeInteger(Number(part))) ? value.split(".").map(Number) : void 0;
521
532
  }
533
+ /** Resolve engine packages from this module's installation with Node module resolution. */
534
+ function installedEnginePackage(name) {
535
+ return require.resolve(`${name}/package.json`);
536
+ }
537
+ /**
538
+ * Check one resolved engine `package.json` path before reading it.
539
+ * @param packageFile - Value the resolver returned.
540
+ * @param name - Engine package name.
541
+ * @returns the path unchanged.
542
+ * @throws Error when the value is not an absolute path to an existing file.
543
+ */
544
+ function resolvedManifest(packageFile, name) {
545
+ if (typeof packageFile !== "string") throw new Error(`Engine package resolver must synchronously return a string path for ${name}; it returned ${packageFile === null ? "null" : typeof packageFile}`);
546
+ if (!isAbsolute(packageFile)) throw new Error(`Engine package resolver returned a non-absolute path for ${name}: ${String(packageFile)}`);
547
+ let file;
548
+ try {
549
+ file = statSync(packageFile).isFile();
550
+ } catch (error) {
551
+ throw new Error(`Engine package resolver returned a missing path for ${name}: ${packageFile}`, { cause: error });
552
+ }
553
+ if (!file) throw new Error(`Engine package resolver returned a path that is not a file for ${name}: ${packageFile}`);
554
+ return packageFile;
555
+ }
522
556
  /**
523
557
  * Prefer the installed compatible native engine; hosts without one use the shared WASM package.
524
- * @param resolvePackage - Package manifest resolver; injectable for selection tests.
525
- * @param packageExists - Installed-package probe; injectable for selection tests.
558
+ * @param resolvePackage - Engine package manifest resolver; defaults to Node resolution from this module.
559
+ * @param packageExists - Whether a native package that resolved as `MODULE_NOT_FOUND` is nevertheless installed (and
560
+ * therefore incomplete). Only the default resolver probes this module's installation; a caller resolver is the sole
561
+ * authority on whether its packages exist.
526
562
  * @param host - Process identification and diagnostic report.
527
563
  * @returns the installed native engine, or the installed WASM engine.
528
564
  */
529
- async function resolveEngine(resolvePackage = (name) => require.resolve(`${name}/package.json`), packageExists = installedPackageExists, { platform = process.platform, arch = process.arch, report = hostReport } = {}) {
565
+ async function resolveEngine(resolvePackage = installedEnginePackage, packageExists = resolvePackage === installedEnginePackage ? installedPackageExists : () => false, { platform = process.platform, arch = process.arch, report = hostReport } = {}) {
530
566
  const details = platform === "linux" ? report() : {};
531
567
  const target = platformTarget(platform, arch, () => details);
532
568
  if (target !== void 0) {
533
569
  const name = `${ENGINE_PREFIX}-${target}`;
534
570
  let packageFile;
535
571
  try {
536
- packageFile = resolvePackage(name);
572
+ packageFile = resolvedManifest(resolvePackage(name), name);
537
573
  } catch (error) {
538
574
  const failure = error;
539
- if (!(failure?.code === "MODULE_NOT_FOUND" && typeof failure.message === "string" && failure.message.includes(`${name}/package.json`))) throw error;
575
+ if (!(failure?.code === "MODULE_NOT_FOUND" && (resolvePackage !== installedEnginePackage || typeof failure.message === "string" && failure.message.includes(`${name}/package.json`)))) throw error;
540
576
  if (packageExists(name)) throw new Error(`Installed LibreOfficeKit package is incomplete: ${name}`, { cause: error });
541
577
  }
542
578
  if (packageFile !== void 0) {
@@ -546,7 +582,8 @@ async function resolveEngine(resolvePackage = (name) => require.resolve(`${name}
546
582
  if (!(minimum && host && minimum.some((part, index) => part > (host[index] ?? 0) && minimum.slice(0, index).every((prior, priorIndex) => prior === host[priorIndex])))) return engine;
547
583
  }
548
584
  }
549
- return readEngine(resolvePackage(`${ENGINE_PREFIX}-wasm`), "wasm", "wasm");
585
+ const wasm = `${ENGINE_PREFIX}-wasm`;
586
+ return readEngine(resolvedManifest(resolvePackage(wasm), wasm), "wasm", "wasm");
550
587
  }
551
588
  async function engineAsset(root, value, name, kind) {
552
589
  const path = asset(root, value);
@@ -1787,7 +1824,7 @@ async function openDocument(request) {
1787
1824
  const lifetime = new AbortController();
1788
1825
  const signal = request.signal ? AbortSignal.any([request.signal, lifetime.signal]) : lifetime.signal;
1789
1826
  signal.throwIfAborted();
1790
- const engine = await resolveEngine();
1827
+ const engine = await resolveEngine(request.options?.resolveEnginePackage);
1791
1828
  if (engine.backend !== "native" || engine.legacyInputPath) throw new Error("Native editing requires a preview-capable native engine package.");
1792
1829
  const scratch = await mkdtemp(join(tmpdir(), "libreoffice-editor-"));
1793
1830
  let transport;
package/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createRequire } from "node:module";
2
- import { closeSync, constants, createWriteStream, lstatSync, readSync, readdirSync } from "node:fs";
2
+ import { closeSync, constants, createWriteStream, lstatSync, readSync, readdirSync, statSync } from "node:fs";
3
3
  import { copyFile, lstat, mkdir, mkdtemp, open, readFile, rm, stat, symlink, unlink, writeFile } from "node:fs/promises";
4
4
  import { homedir, tmpdir } from "node:os";
5
5
  import { dirname, extname, isAbsolute, join, posix, relative, resolve, sep, win32 } from "node:path";
@@ -49,6 +49,14 @@ function failureCode(error) {
49
49
  const code = error?.code;
50
50
  return typeof code === "string" && CODES.has(code) ? code : "failed";
51
51
  }
52
+ /**
53
+ * Describe any thrown value, including caller callbacks that throw non-Error values.
54
+ * @param error - The thrown value.
55
+ * @returns The Error message, or the value's string form.
56
+ */
57
+ function failureMessage(error) {
58
+ return error instanceof Error ? error.message : String(error);
59
+ }
52
60
  //#endregion
53
61
  //#region lib/types/sheet-geometry.js
54
62
  const MAX_COLUMN = 16383;
@@ -1492,10 +1500,20 @@ function fontGroups(value) {
1492
1500
  return value.map((group) => [...group]);
1493
1501
  }
1494
1502
  /**
1503
+ * Validate an optional caller-supplied engine package resolver.
1504
+ * @param value - The `resolveEnginePackage` option value.
1505
+ * @returns the resolver, or undefined when absent.
1506
+ * @throws TypeError when the value is defined and not a function.
1507
+ */
1508
+ function enginePackageResolver(value) {
1509
+ if (value !== void 0 && typeof value !== "function") throw new TypeError("resolveEnginePackage must be a function.");
1510
+ return value;
1511
+ }
1512
+ /**
1495
1513
  * Resolve defaults once; reject misspelled options and malformed font settings.
1496
1514
  * @param input - Caller options; absent fields keep their documented default.
1497
1515
  * @returns The validated limits and font settings, with caller arrays copied.
1498
- * @throws TypeError for a non-object argument or an unknown option name.
1516
+ * @throws TypeError for a non-object argument, an unknown option name, or a non-function `resolveEnginePackage`.
1499
1517
  * @throws RangeError for a limit outside the positive safe-integer timer range.
1500
1518
  */
1501
1519
  function resolveOptions(input = {}) {
@@ -1508,7 +1526,8 @@ function resolveOptions(input = {}) {
1508
1526
  initialFontFamilies: [],
1509
1527
  ...input
1510
1528
  };
1511
- for (const key of Object.keys(input)) if (!(key in DEFAULT_LIMITS) && !FONT_COLLECTION_NAMES.includes(key) && key !== "fontFallbacks" && key !== "fontMetadataCacheDirectory") throw new TypeError(`Unknown converter option: ${key}`);
1529
+ for (const key of Object.keys(input)) if (!(key in DEFAULT_LIMITS) && !FONT_COLLECTION_NAMES.includes(key) && key !== "fontFallbacks" && key !== "fontMetadataCacheDirectory" && key !== "resolveEnginePackage") throw new TypeError(`Unknown converter option: ${key}`);
1530
+ enginePackageResolver(input.resolveEnginePackage);
1512
1531
  const cacheDirectory = input.fontMetadataCacheDirectory === void 0 ? defaultFontMetadataCacheDirectory() : input.fontMetadataCacheDirectory;
1513
1532
  if (cacheDirectory !== false && (typeof cacheDirectory !== "string" || !isAbsolute(cacheDirectory) || cacheDirectory.includes("\0"))) throw new TypeError("fontMetadataCacheDirectory must be an absolute path or false.");
1514
1533
  return {
@@ -1535,16 +1554,16 @@ function resolveOptions(input = {}) {
1535
1554
  /** Resolve installed, version-matched engine packages without downloads or compilation. */
1536
1555
  const require = createRequire(import.meta.url);
1537
1556
  /** Node API release version returned by runtime discovery. */
1538
- const ENGINE_VERSION = "0.2.3-rc.3";
1557
+ const ENGINE_VERSION = "0.2.3-rc.4";
1539
1558
  /** Exact compatible engine versions; unchanged platforms retain their published packages. */
1540
1559
  const ENGINE_VERSIONS = Object.freeze({
1541
- "darwin-arm64": "0.2.3-rc.3",
1542
- "darwin-x64": "0.2.3-rc.3",
1560
+ "darwin-arm64": "0.2.3-rc.4",
1561
+ "darwin-x64": "0.2.3-rc.4",
1543
1562
  "linux-arm64-glibc": "0.1.1",
1544
1563
  "linux-x64-glibc": "0.1.1",
1545
- "win32-arm64": "0.2.3-rc.3",
1546
- "win32-x64": "0.2.3-rc.3",
1547
- wasm: "0.2.3-rc.3"
1564
+ "win32-arm64": "0.2.3-rc.4",
1565
+ "win32-x64": "0.2.3-rc.4",
1566
+ wasm: "0.2.3-rc.4"
1548
1567
  });
1549
1568
  /** npm scope and name prefix shared by the engine packages this adapter installs. */
1550
1569
  const ENGINE_PREFIX = "@deepseek-ai/libreoffice-kit";
@@ -1582,24 +1601,49 @@ function asset(root, value) {
1582
1601
  function glibcVersion(value) {
1583
1602
  return typeof value === "string" && /^(0|[1-9]\d*)\.(0|[1-9]\d*)(?:\.(0|[1-9]\d*))?$/.test(value) && value.split(".").every((part) => Number.isSafeInteger(Number(part))) ? value.split(".").map(Number) : void 0;
1584
1603
  }
1604
+ /** Resolve engine packages from this module's installation with Node module resolution. */
1605
+ function installedEnginePackage(name) {
1606
+ return require.resolve(`${name}/package.json`);
1607
+ }
1608
+ /**
1609
+ * Check one resolved engine `package.json` path before reading it.
1610
+ * @param packageFile - Value the resolver returned.
1611
+ * @param name - Engine package name.
1612
+ * @returns the path unchanged.
1613
+ * @throws Error when the value is not an absolute path to an existing file.
1614
+ */
1615
+ function resolvedManifest(packageFile, name) {
1616
+ if (typeof packageFile !== "string") throw new Error(`Engine package resolver must synchronously return a string path for ${name}; it returned ${packageFile === null ? "null" : typeof packageFile}`);
1617
+ if (!isAbsolute(packageFile)) throw new Error(`Engine package resolver returned a non-absolute path for ${name}: ${String(packageFile)}`);
1618
+ let file;
1619
+ try {
1620
+ file = statSync(packageFile).isFile();
1621
+ } catch (error) {
1622
+ throw new Error(`Engine package resolver returned a missing path for ${name}: ${packageFile}`, { cause: error });
1623
+ }
1624
+ if (!file) throw new Error(`Engine package resolver returned a path that is not a file for ${name}: ${packageFile}`);
1625
+ return packageFile;
1626
+ }
1585
1627
  /**
1586
1628
  * Prefer the installed compatible native engine; hosts without one use the shared WASM package.
1587
- * @param resolvePackage - Package manifest resolver; injectable for selection tests.
1588
- * @param packageExists - Installed-package probe; injectable for selection tests.
1629
+ * @param resolvePackage - Engine package manifest resolver; defaults to Node resolution from this module.
1630
+ * @param packageExists - Whether a native package that resolved as `MODULE_NOT_FOUND` is nevertheless installed (and
1631
+ * therefore incomplete). Only the default resolver probes this module's installation; a caller resolver is the sole
1632
+ * authority on whether its packages exist.
1589
1633
  * @param host - Process identification and diagnostic report.
1590
1634
  * @returns the installed native engine, or the installed WASM engine.
1591
1635
  */
1592
- async function resolveEngine(resolvePackage = (name) => require.resolve(`${name}/package.json`), packageExists = installedPackageExists, { platform = process.platform, arch = process.arch, report = hostReport } = {}) {
1636
+ async function resolveEngine(resolvePackage = installedEnginePackage, packageExists = resolvePackage === installedEnginePackage ? installedPackageExists : () => false, { platform = process.platform, arch = process.arch, report = hostReport } = {}) {
1593
1637
  const details = platform === "linux" ? report() : {};
1594
1638
  const target = platformTarget(platform, arch, () => details);
1595
1639
  if (target !== void 0) {
1596
1640
  const name = `${ENGINE_PREFIX}-${target}`;
1597
1641
  let packageFile;
1598
1642
  try {
1599
- packageFile = resolvePackage(name);
1643
+ packageFile = resolvedManifest(resolvePackage(name), name);
1600
1644
  } catch (error) {
1601
1645
  const failure = error;
1602
- if (!(failure?.code === "MODULE_NOT_FOUND" && typeof failure.message === "string" && failure.message.includes(`${name}/package.json`))) throw error;
1646
+ if (!(failure?.code === "MODULE_NOT_FOUND" && (resolvePackage !== installedEnginePackage || typeof failure.message === "string" && failure.message.includes(`${name}/package.json`)))) throw error;
1603
1647
  if (packageExists(name)) throw new Error(`Installed LibreOfficeKit package is incomplete: ${name}`, { cause: error });
1604
1648
  }
1605
1649
  if (packageFile !== void 0) {
@@ -1609,7 +1653,8 @@ async function resolveEngine(resolvePackage = (name) => require.resolve(`${name}
1609
1653
  if (!(minimum && host && minimum.some((part, index) => part > (host[index] ?? 0) && minimum.slice(0, index).every((prior, priorIndex) => prior === host[priorIndex])))) return engine;
1610
1654
  }
1611
1655
  }
1612
- return readEngine(resolvePackage(`${ENGINE_PREFIX}-wasm`), "wasm", "wasm");
1656
+ const wasm = `${ENGINE_PREFIX}-wasm`;
1657
+ return readEngine(resolvedManifest(resolvePackage(wasm), wasm), "wasm", "wasm");
1613
1658
  }
1614
1659
  async function engineAsset(root, value, name, kind) {
1615
1660
  const path = asset(root, value);
@@ -1810,12 +1855,16 @@ function pdfPageCount(bytes) {
1810
1855
  /** Offline discovery of the installed engine and public entry points. */
1811
1856
  /**
1812
1857
  * Inspect installed engine metadata without starting, downloading, or building an engine.
1858
+ * @param options - The options of a later createConverter call, validated the same way; only `resolveEnginePackage`
1859
+ * affects discovery, so both select the same engine.
1813
1860
  * @returns Public entry paths, Node API version, and selected backend.
1861
+ * @throws TypeError or RangeError for options createConverter would reject.
1814
1862
  * @throws ConversionError when the installed engine is unavailable or invalid.
1815
1863
  */
1816
- async function discoverRuntime() {
1864
+ async function discoverRuntime(options) {
1865
+ resolveOptions(options);
1817
1866
  try {
1818
- const engine = await resolveEngine();
1867
+ const engine = await resolveEngine(options?.resolveEnginePackage);
1819
1868
  return {
1820
1869
  version: ENGINE_VERSION,
1821
1870
  backend: engine.backend,
@@ -1824,7 +1873,7 @@ async function discoverRuntime() {
1824
1873
  nodeApiPath: fileURLToPath(new URL("./index.js", import.meta.url))
1825
1874
  };
1826
1875
  } catch (cause) {
1827
- throw new ConversionError("unavailable", cause.message, { cause });
1876
+ throw new ConversionError("unavailable", failureMessage(cause), { cause });
1828
1877
  }
1829
1878
  }
1830
1879
  //#endregion
@@ -2027,9 +2076,9 @@ async function resolveConverter(options) {
2027
2076
  const resolvedOptions = resolveOptions(options);
2028
2077
  let engine;
2029
2078
  try {
2030
- engine = await resolveEngine();
2079
+ engine = await resolveEngine(options?.resolveEnginePackage);
2031
2080
  } catch (cause) {
2032
- throw new ConversionError("unavailable", cause.message, { cause });
2081
+ throw new ConversionError("unavailable", failureMessage(cause), { cause });
2033
2082
  }
2034
2083
  return {
2035
2084
  options: resolvedOptions,
@@ -1,5 +1,5 @@
1
1
  /** Node API release version returned by runtime discovery. */
2
- export declare const ENGINE_VERSION = "0.2.3-rc.3";
2
+ export declare const ENGINE_VERSION = "0.2.3-rc.4";
3
3
  /** Exact compatible engine versions; unchanged platforms retain their published packages. */
4
4
  export declare const ENGINE_VERSIONS: Readonly<Record<string, string>>;
5
5
  /** Host diagnostic fields used to identify the runtime glibc version. */
@@ -56,13 +56,24 @@ export declare function installedPackageExists(name: string): boolean;
56
56
  * @returns the declared platform target, or undefined for an unsupported host.
57
57
  */
58
58
  export declare function platformTarget(platform?: string, arch?: string, report?: () => EngineHostReport): string | undefined;
59
+ /**
60
+ * Map an engine package name to the absolute path of that package's installed `package.json`.
61
+ * The resolver receives the platform package name (`@deepseek-ai/libreoffice-kit-<target>`) when the host has a
62
+ * native target, and `@deepseek-ai/libreoffice-kit-wasm` when WASM is selected. To report an absent native package,
63
+ * throw an error whose `code` is `MODULE_NOT_FOUND` (as `require.resolve` does); that selects WASM. Any other
64
+ * failure, or a result that is not an absolute path to an existing file, rejects. The resolver must be synchronous. The adapter does not probe its own
65
+ * installation for packages a caller resolver reports missing.
66
+ */
67
+ export type EnginePackageResolver = (name: string) => string;
59
68
  /**
60
69
  * Prefer the installed compatible native engine; hosts without one use the shared WASM package.
61
- * @param resolvePackage - Package manifest resolver; injectable for selection tests.
62
- * @param packageExists - Installed-package probe; injectable for selection tests.
70
+ * @param resolvePackage - Engine package manifest resolver; defaults to Node resolution from this module.
71
+ * @param packageExists - Whether a native package that resolved as `MODULE_NOT_FOUND` is nevertheless installed (and
72
+ * therefore incomplete). Only the default resolver probes this module's installation; a caller resolver is the sole
73
+ * authority on whether its packages exist.
63
74
  * @param host - Process identification and diagnostic report.
64
75
  * @returns the installed native engine, or the installed WASM engine.
65
76
  */
66
- export declare function resolveEngine(resolvePackage?: (name: string) => string, packageExists?: (name: string) => boolean, { platform, arch, report }?: EngineResolutionHost): Promise<Engine>;
77
+ export declare function resolveEngine(resolvePackage?: EnginePackageResolver, packageExists?: (name: string) => boolean, { platform, arch, report }?: EngineResolutionHost): Promise<Engine>;
67
78
  export {};
68
79
  //# sourceMappingURL=engine.d.ts.map
@@ -18,4 +18,10 @@ export declare class ConversionError extends Error {
18
18
  * @returns The published category, or `failed` when no published category is present.
19
19
  */
20
20
  export declare function failureCode(error: unknown): ConversionErrorCode;
21
+ /**
22
+ * Describe any thrown value, including caller callbacks that throw non-Error values.
23
+ * @param error - The thrown value.
24
+ * @returns The Error message, or the value's string form.
25
+ */
26
+ export declare function failureMessage(error: unknown): string;
21
27
  //# sourceMappingURL=errors.d.ts.map
@@ -1,16 +1,23 @@
1
1
  import type { RenderImagesRequest, RenderImagesResult } from './image-operations.ts';
2
2
  export { IMAGE_FORMATS } from './image-operations.ts';
3
3
  export type { RenderImagesRequest, RenderImagesResult, RenderedImage } from './image-operations.ts';
4
+ import type { EnginePackageResolver } from './engine.ts';
4
5
  import type { ConversionRequest } from './operations.ts';
5
6
  export { CONVERSION_FORMATS } from './operations.ts';
6
7
  export type { ConversionRequest } from './operations.ts';
7
8
  export { discoverRuntime } from './runtime.ts';
8
9
  export type { RuntimeInfo } from './runtime.ts';
10
+ export type { EnginePackageResolver } from './engine.ts';
9
11
  export { ConversionError } from './errors.ts';
10
12
  export type { ConversionErrorCode } from './errors.ts';
11
13
  export { ENGINE_VERSION, ENGINE_VERSIONS } from './engine.ts';
12
14
  /** Host limits used by both native and Node WASM conversions. All byte limits are positive safe integers. */
13
15
  export interface ConverterOptions {
16
+ /**
17
+ * Engine package manifest resolver. Defaults to Node resolution from this package. Its result decides whether the
18
+ * native engine is installed and which installation is read; it also locates the WASM fallback package.
19
+ */
20
+ resolveEnginePackage?: EnginePackageResolver;
14
21
  /** User-local font metadata cache directory. Defaults to the platform cache directory; false disables disk reuse. */
15
22
  fontMetadataCacheDirectory?: string | false;
16
23
  /** Maximum persisted and reusable per-file metadata bytes. Default: 32 MiB. */
@@ -1,5 +1,6 @@
1
1
  /** Validated deployment limits shared by native and Node WASM conversions. */
2
2
  import type { ConverterOptions } from './index.ts';
3
+ import type { EnginePackageResolver } from './engine.ts';
3
4
  /** Ordered family groups used when the caller supplies none. */
4
5
  export declare const FONT_FALLBACKS: readonly (readonly string[])[];
5
6
  /** Resolved limits and font settings used by every conversion of one converter. */
@@ -21,11 +22,18 @@ export interface ResolvedOptions {
21
22
  readonly fontFallbacks: string[][];
22
23
  readonly initialFontFamilies: string[];
23
24
  }
25
+ /**
26
+ * Validate an optional caller-supplied engine package resolver.
27
+ * @param value - The `resolveEnginePackage` option value.
28
+ * @returns the resolver, or undefined when absent.
29
+ * @throws TypeError when the value is defined and not a function.
30
+ */
31
+ export declare function enginePackageResolver(value: unknown): EnginePackageResolver | undefined;
24
32
  /**
25
33
  * Resolve defaults once; reject misspelled options and malformed font settings.
26
34
  * @param input - Caller options; absent fields keep their documented default.
27
35
  * @returns The validated limits and font settings, with caller arrays copied.
28
- * @throws TypeError for a non-object argument or an unknown option name.
36
+ * @throws TypeError for a non-object argument, an unknown option name, or a non-function `resolveEnginePackage`.
29
37
  * @throws RangeError for a limit outside the positive safe-integer timer range.
30
38
  */
31
39
  export declare function resolveOptions(input?: ConverterOptions): ResolvedOptions;
@@ -1,3 +1,4 @@
1
+ import type { ConverterOptions } from './index.ts';
1
2
  /** Paths use the same installed Node API and precompiled engine as createConverter. */
2
3
  export interface RuntimeInfo {
3
4
  readonly version: string;
@@ -9,8 +10,11 @@ export interface RuntimeInfo {
9
10
  }
10
11
  /**
11
12
  * Inspect installed engine metadata without starting, downloading, or building an engine.
13
+ * @param options - The options of a later createConverter call, validated the same way; only `resolveEnginePackage`
14
+ * affects discovery, so both select the same engine.
12
15
  * @returns Public entry paths, Node API version, and selected backend.
16
+ * @throws TypeError or RangeError for options createConverter would reject.
13
17
  * @throws ConversionError when the installed engine is unavailable or invalid.
14
18
  */
15
- export declare function discoverRuntime(): Promise<RuntimeInfo>;
19
+ export declare function discoverRuntime(options?: ConverterOptions): Promise<RuntimeInfo>;
16
20
  //# sourceMappingURL=runtime.d.ts.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@deepseek-ai/libreoffice-kit",
3
3
  "description": "Convert, recalculate, and render Office documents with prebuilt LibreOffice",
4
- "version": "0.2.3-rc.3",
4
+ "version": "0.2.3-rc.4",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -124,11 +124,11 @@
124
124
  },
125
125
  "optionalDependencies": {
126
126
  "koffi": "3.1.1",
127
- "@deepseek-ai/libreoffice-kit-darwin-arm64": "0.2.3-rc.3",
128
- "@deepseek-ai/libreoffice-kit-darwin-x64": "0.2.3-rc.3",
129
- "@deepseek-ai/libreoffice-kit-wasm": "0.2.3-rc.3",
130
- "@deepseek-ai/libreoffice-kit-win32-arm64": "0.2.3-rc.3",
131
- "@deepseek-ai/libreoffice-kit-win32-x64": "0.2.3-rc.3"
127
+ "@deepseek-ai/libreoffice-kit-darwin-arm64": "0.2.3-rc.4",
128
+ "@deepseek-ai/libreoffice-kit-darwin-x64": "0.2.3-rc.4",
129
+ "@deepseek-ai/libreoffice-kit-win32-arm64": "0.2.3-rc.4",
130
+ "@deepseek-ai/libreoffice-kit-win32-x64": "0.2.3-rc.4",
131
+ "@deepseek-ai/libreoffice-kit-wasm": "0.2.3-rc.4"
132
132
  },
133
133
  "bin": {
134
134
  "dsoffice": "./lib/cli.js"