@deepseek-ai/libreoffice-kit 0.1.5 → 0.2.0-alpha6

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 (77) hide show
  1. package/NOTICE +4 -0
  2. package/README.md +44 -8
  3. package/README.zh.md +45 -9
  4. package/frame-forwarding/CMakeLists.txt +40 -0
  5. package/frame-forwarding/LICENSE +21 -0
  6. package/frame-forwarding/README.md +83 -0
  7. package/frame-forwarding/README.zh.md +83 -0
  8. package/frame-forwarding/include/dsh_frame_forwarding.h +101 -0
  9. package/frame-forwarding/include/dsh_frame_forwarding_engine.h +66 -0
  10. package/frame-forwarding/include/dsh_frame_forwarding_node.h +27 -0
  11. package/frame-forwarding/include/dsh_webgpu.h +52 -0
  12. package/frame-forwarding/index.d.ts +145 -0
  13. package/frame-forwarding/index.mjs +71 -0
  14. package/frame-forwarding/lib/browser/display.d.ts +46 -0
  15. package/frame-forwarding/lib/browser/display.js +128 -0
  16. package/frame-forwarding/lib/browser/index.d.ts +4 -0
  17. package/frame-forwarding/lib/browser/index.js +3 -0
  18. package/frame-forwarding/lib/browser/painters.d.ts +9 -0
  19. package/frame-forwarding/lib/browser/painters.js +180 -0
  20. package/frame-forwarding/lib/browser/types.d.ts +51 -0
  21. package/frame-forwarding/lib/browser/types.js +1 -0
  22. package/frame-forwarding/lib/electron/adapter.d.ts +9 -0
  23. package/frame-forwarding/lib/electron/adapter.js +118 -0
  24. package/frame-forwarding/lib/electron/index.d.ts +3 -0
  25. package/frame-forwarding/lib/electron/index.js +3 -0
  26. package/frame-forwarding/lib/electron/preload.d.ts +13 -0
  27. package/frame-forwarding/lib/electron/preload.js +47 -0
  28. package/frame-forwarding/lib/electron/transfer.d.ts +15 -0
  29. package/frame-forwarding/lib/electron/transfer.js +36 -0
  30. package/frame-forwarding/prebuilds/darwin-arm64/frame-forwarding.node +0 -0
  31. package/frame-forwarding/prebuilds/darwin-arm64/libdsh_frame_forwarding_sdk.a +0 -0
  32. package/frame-forwarding/prebuilds/darwin-arm64/manifest.json +34 -0
  33. package/frame-forwarding/prebuilds/darwin-x64/frame-forwarding.node +0 -0
  34. package/frame-forwarding/prebuilds/darwin-x64/libdsh_frame_forwarding_sdk.a +0 -0
  35. package/frame-forwarding/prebuilds/darwin-x64/manifest.json +34 -0
  36. package/frame-forwarding/prebuilds/win32-arm64/dsh_frame_forwarding_sdk.lib +0 -0
  37. package/frame-forwarding/prebuilds/win32-arm64/frame-forwarding.node +0 -0
  38. package/frame-forwarding/prebuilds/win32-arm64/manifest.json +34 -0
  39. package/frame-forwarding/prebuilds/win32-x64/dsh_frame_forwarding_sdk.lib +0 -0
  40. package/frame-forwarding/prebuilds/win32-x64/frame-forwarding.node +0 -0
  41. package/frame-forwarding/prebuilds/win32-x64/manifest.json +34 -0
  42. package/frame-forwarding/receipt.json +23 -0
  43. package/frame-forwarding/scripts/build-webgpu.mjs +197 -0
  44. package/frame-forwarding/scripts/build.mjs +43 -0
  45. package/frame-forwarding/scripts/metadata.mjs +47 -0
  46. package/frame-forwarding/scripts/source-identity.mjs +15 -0
  47. package/frame-forwarding/scripts/verify-prebuilds.mjs +14 -0
  48. package/frame-forwarding/sdk.json +45 -0
  49. package/frame-forwarding/src/node-producer.cc +595 -0
  50. package/frame-forwarding/src/producer-internal.h +8 -0
  51. package/frame-forwarding/src/producer.cc +306 -0
  52. package/frame-forwarding/src/receiver.cc +1050 -0
  53. package/frame-forwarding/src/relay-transport.inc +293 -0
  54. package/frame-forwarding/src/transport.cc +405 -0
  55. package/frame-forwarding/src/transport.h +80 -0
  56. package/frame-forwarding/src/webgpu.cc +214 -0
  57. package/frame-forwarding/src/win-delay-load.LICENSE +24 -0
  58. package/frame-forwarding/src/win-delay-load.cc +43 -0
  59. package/frame-forwarding/verify.d.mts +4 -0
  60. package/frame-forwarding/verify.mjs +101 -0
  61. package/frame-forwarding/webgpu-dependencies.json +51 -0
  62. package/lib/cli.js +109 -46
  63. package/lib/editor.js +2061 -0
  64. package/lib/index.js +109 -46
  65. package/lib/types/editor-protocol.d.ts +29 -0
  66. package/lib/types/editor-transport.d.ts +36 -0
  67. package/lib/types/editor-types.d.ts +119 -0
  68. package/lib/types/editor.d.ts +105 -0
  69. package/lib/types/engine.d.ts +4 -2
  70. package/lib/types/fonts.d.ts +4 -8
  71. package/lib/types/native-image-renderer.d.ts +0 -1
  72. package/lib/types/native-process.d.ts +1 -0
  73. package/lib/types/native.d.ts +30 -2
  74. package/lib/types/runtime.d.ts +2 -0
  75. package/lib/types/worker.d.ts +2 -2
  76. package/lib/worker.js +38 -31
  77. package/package.json +94 -9
package/lib/cli.js CHANGED
@@ -337,12 +337,17 @@ let pipeAttributes;
337
337
  function windowsPipes() {
338
338
  const koffi = createRequire(import.meta.url)("koffi");
339
339
  const kernel = koffi.load("kernel32.dll"), advapi = koffi.load("advapi32.dll"), node = koffi.load(null);
340
- const attributes = pipeAttributes ??= koffi.struct("KIT_SECURITY_ATTRIBUTES", {
340
+ const attributes = pipeAttributes ??= koffi.struct({
341
341
  nLength: "uint32",
342
342
  lpSecurityDescriptor: "void *",
343
343
  bInheritHandle: "int"
344
344
  });
345
- const createPipe = kernel.func("int __stdcall CreatePipe(_Out_ void **read, _Out_ void **write, KIT_SECURITY_ATTRIBUTES *attributes, uint32 size)");
345
+ const createPipe = kernel.func("__stdcall", "CreatePipe", "int", [
346
+ koffi.out(koffi.pointer("void *")),
347
+ koffi.out(koffi.pointer("void *")),
348
+ koffi.pointer(attributes),
349
+ "uint32"
350
+ ]);
346
351
  const closeHandle = kernel.func("int __stdcall CloseHandle(void *handle)");
347
352
  const localFree = kernel.func("void * __stdcall LocalFree(void *memory)");
348
353
  const peek = kernel.func("int __stdcall PeekNamedPipe(void *pipe, void *buffer, uint32 size, void *read, _Out_ uint32 *available, void *remaining)");
@@ -471,6 +476,9 @@ function spawnNative(executable, args, env) {
471
476
  stdin = stdin;
472
477
  stdout = output.readable;
473
478
  stderr = error.readable;
479
+ get pid() {
480
+ return child.pid;
481
+ }
474
482
  get exitCode() {
475
483
  return child.exitCode;
476
484
  }
@@ -704,7 +712,9 @@ const NATIVE_ENVIRONMENT_KEYS = [
704
712
  "PATHEXT",
705
713
  "LANG",
706
714
  "LC_ALL",
707
- "TZ"
715
+ "TZ",
716
+ "OFFICE_GRAPHITE_DIAGNOSTICS",
717
+ "OFFICE_LOAD_DIAGNOSTICS"
708
718
  ];
709
719
  function fontSearchName(value) {
710
720
  const name = value.replaceAll(/[\uff00-\uff5e]/g, (character) => String.fromCharCode(character.charCodeAt(0) - 65248)).replaceAll(/[A-Z]/g, (character) => character.toLowerCase()).replaceAll(/[^a-z0-9;()\u0080-\uffff]/g, "");
@@ -756,34 +766,84 @@ function nativeEnvironment(profile, programDirectory, source = process.env, plat
756
766
  });
757
767
  }
758
768
  /**
759
- * Keep Windows engine resources reachable through a short profile-owned path until the helper exits.
769
+ * Prepare short Windows engine paths owned by the caller's private profile.
760
770
  * @param engine - Verified engine installation; its resources remain in place.
761
771
  * @param profile - Private operation directory that owns the temporary executable and junction.
762
- * @param run - Operation that settles only after its helper closes.
763
- * @returns The operation result after removing the resource junction.
772
+ * @returns Engine paths and a release function to call once, after the helper closes and before removing the profile.
764
773
  */
765
- async function withNativeEngine(engine, profile, run) {
766
- if (process.platform !== "win32" || engine.executable.length < 260 && engine.programDirectory.length < 260) return run(engine);
774
+ async function prepareNativeEngine(engine, profile) {
775
+ if (process.platform !== "win32" || engine.executable.length < 260 && engine.programDirectory.length < 260) return {
776
+ engine,
777
+ release: async () => {}
778
+ };
767
779
  const root = join(profile, "engine");
768
780
  await symlink(engine.root, root, "junction");
769
781
  try {
770
782
  const executable = join(profile, "libreoffice-kit.exe");
771
783
  await copyFile(engine.executable, executable, constants.COPYFILE_EXCL);
772
- return await run({
773
- ...engine,
774
- root,
775
- executable,
776
- programDirectory: join(root, relative(engine.root, engine.programDirectory))
777
- });
778
- } finally {
784
+ return {
785
+ engine: {
786
+ ...engine,
787
+ root,
788
+ executable,
789
+ programDirectory: join(root, relative(engine.root, engine.programDirectory))
790
+ },
791
+ release: () => unlink(root)
792
+ };
793
+ } catch (error) {
779
794
  await unlink(root);
795
+ throw error;
780
796
  }
781
797
  }
782
798
  /**
799
+ * Keep Windows engine resources reachable through a short profile-owned path until the helper exits.
800
+ * @param engine - Verified engine installation; its resources remain in place.
801
+ * @param profile - Private operation directory that owns the temporary executable and junction.
802
+ * @param run - Operation that settles only after its helper closes.
803
+ * @returns The operation result after removing the resource junction.
804
+ */
805
+ async function withNativeEngine(engine, profile, run) {
806
+ const prepared = await prepareNativeEngine(engine, profile);
807
+ try {
808
+ return await run(prepared.engine);
809
+ } finally {
810
+ await prepared.release();
811
+ }
812
+ }
813
+ /**
814
+ * Prepare the document transport accepted by the pinned helper.
815
+ * @param engine - Resolved helper and input protocol.
816
+ * @param input - Owned document bytes and validated format.
817
+ * @param profile - Private directory retained until the helper exits and removed by the operation owner.
818
+ * @param signal - Cancellation of input preparation.
819
+ * @returns Helper arguments and an optional binary stdin prefix.
820
+ */
821
+ async function prepareNativeInput(engine, input, profile, signal) {
822
+ signal.throwIfAborted();
823
+ if (engine.legacyInputPath) {
824
+ const path = join(profile, `source.${input.format}`);
825
+ await writeFile(path, input.bytes, {
826
+ flag: "wx",
827
+ mode: 384,
828
+ signal
829
+ });
830
+ return { args: ["--input-path", path] };
831
+ }
832
+ return {
833
+ args: [
834
+ "--input-bytes",
835
+ String(input.bytes.byteLength),
836
+ "--input-format",
837
+ input.format
838
+ ],
839
+ bytes: input.bytes
840
+ };
841
+ }
842
+ /**
783
843
  * Run one native conversion and await bounded result transport.
784
844
  * @param engine - Resolved native engine installation.
785
845
  * @param options - Validated conversion limits.
786
- * @param input - Private source path inside the conversion scratch directory.
846
+ * @param input - Owned source bytes and format; older pinned helpers receive a private input file.
787
847
  * @param output - Private PDF path inside the conversion scratch directory.
788
848
  * @param profile - Conversion-owned profile directory.
789
849
  * @param fonts - Installed font files the helper may load.
@@ -802,11 +862,12 @@ async function runNative(engine, options, input, output, profile, fonts, substit
802
862
  return withNativeEngine(engine, profile, async (engine) => {
803
863
  signal.throwIfAborted();
804
864
  const env = nativeEnvironment(profile, engine.programDirectory);
865
+ const transport = await prepareNativeInput(engine, input, profile, signal);
866
+ signal.throwIfAborted();
805
867
  const child = spawnNative(engine.executable, [
806
868
  "--program-directory",
807
869
  engine.programDirectory,
808
- "--input-path",
809
- input,
870
+ ...transport.args,
810
871
  "--output-path",
811
872
  output,
812
873
  "--profile-directory",
@@ -822,7 +883,6 @@ async function runNative(engine, options, input, output, profile, fonts, substit
822
883
  ...operation.sheet === void 0 ? [] : ["--sheet", operation.sheet],
823
884
  ...fonts.flatMap((path) => ["--font-file", path])
824
885
  ], env);
825
- child.stdin.end();
826
886
  let stdout = "";
827
887
  let stderr = "";
828
888
  let failure;
@@ -843,6 +903,11 @@ async function runNative(engine, options, input, output, profile, fonts, substit
843
903
  child.stderr.on("data", (chunk) => {
844
904
  stderr = (stderr + chunk).slice(-65536);
845
905
  });
906
+ child.stdin.on("error", (error) => {
907
+ failure ??= error;
908
+ child.kill("SIGKILL");
909
+ });
910
+ child.stdin.end(transport.bytes);
846
911
  try {
847
912
  const code = await new Promise((resolve, reject) => {
848
913
  child.once("error", (error) => {
@@ -998,19 +1063,22 @@ function plan(ready, request) {
998
1063
  }
999
1064
  /** Run one native image batch and write final PNGs only after each bounded paint succeeds. */
1000
1065
  async function renderImagesWithNative(request) {
1001
- const { engine, options, inputPath, source, scratch, profile, fonts, substitutions, missingFonts, operation, signal } = request;
1066
+ const { engine, options, source, scratch, profile, fonts, substitutions, missingFonts, operation, signal } = request;
1002
1067
  signal.throwIfAborted();
1003
1068
  await mkdir(profile, { mode: 448 });
1004
1069
  await prepareNativeFontProfile(profile, substitutions);
1005
1070
  return withNativeEngine(engine, profile, async (engine) => {
1071
+ const transport = await prepareNativeInput(engine, {
1072
+ bytes: source,
1073
+ format: operation.extension
1074
+ }, profile, signal);
1006
1075
  signal.throwIfAborted();
1007
1076
  const child = spawnNative(engine.executable, [
1008
1077
  "--operation",
1009
1078
  "render-images",
1010
1079
  "--program-directory",
1011
1080
  engine.programDirectory,
1012
- "--input-path",
1013
- inputPath,
1081
+ ...transport.args,
1014
1082
  "--scratch-directory",
1015
1083
  scratch,
1016
1084
  "--profile-directory",
@@ -1050,6 +1118,11 @@ async function renderImagesWithNative(request) {
1050
1118
  child.kill("SIGKILL");
1051
1119
  };
1052
1120
  signal.addEventListener("abort", abort, { once: true });
1121
+ child.stdin.on("error", (error) => {
1122
+ stopped ??= error;
1123
+ child.kill("SIGKILL");
1124
+ });
1125
+ if (transport.bytes) child.stdin.write(transport.bytes);
1053
1126
  const next = async () => {
1054
1127
  signal.throwIfAborted();
1055
1128
  if (lines.length > 0) return lines.shift();
@@ -1464,16 +1537,16 @@ function resolveOptions(input = {}) {
1464
1537
  /** Resolve installed, version-matched engine packages without downloads or compilation. */
1465
1538
  const require = createRequire(import.meta.url);
1466
1539
  /** Node API release version returned by runtime discovery. */
1467
- const ENGINE_VERSION = "0.1.5";
1540
+ const ENGINE_VERSION = "0.2.0-alpha6";
1468
1541
  /** Exact compatible engine versions; unchanged platforms retain their published packages. */
1469
1542
  const ENGINE_VERSIONS = Object.freeze({
1470
- "darwin-arm64": "0.1.5",
1471
- "darwin-x64": "0.1.5",
1543
+ "darwin-arm64": "0.2.0-alpha6",
1544
+ "darwin-x64": "0.2.0-alpha6",
1472
1545
  "linux-arm64-glibc": "0.1.1",
1473
1546
  "linux-x64-glibc": "0.1.1",
1474
1547
  "win32-arm64": "0.1.5",
1475
- "win32-x64": "0.1.5",
1476
- wasm: "0.1.5"
1548
+ "win32-x64": "0.2.0-alpha6",
1549
+ wasm: "0.2.0-alpha5"
1477
1550
  });
1478
1551
  /** npm scope and name prefix shared by the engine packages this adapter installs. */
1479
1552
  const ENGINE_PREFIX = "@deepseek-ai/libreoffice-kit";
@@ -1512,7 +1585,7 @@ function glibcVersion(value) {
1512
1585
  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;
1513
1586
  }
1514
1587
  /**
1515
- * macOS and Windows require their native engine. Linux uses WASM when no compatible development native engine is installed.
1588
+ * Prefer the installed compatible native engine; hosts without one use the shared WASM package.
1516
1589
  * @param resolvePackage - Package manifest resolver; injectable for selection tests.
1517
1590
  * @param packageExists - Installed-package probe; injectable for selection tests.
1518
1591
  * @param host - Process identification and diagnostic report.
@@ -1530,7 +1603,6 @@ async function resolveEngine(resolvePackage = (name) => require.resolve(`${name}
1530
1603
  const failure = error;
1531
1604
  if (!(failure?.code === "MODULE_NOT_FOUND" && typeof failure.message === "string" && failure.message.includes(`${name}/package.json`))) throw error;
1532
1605
  if (packageExists(name)) throw new Error(`Installed LibreOfficeKit package is incomplete: ${name}`, { cause: error });
1533
- if (platform !== "linux") throw new Error(`Required LibreOfficeKit native package is missing: ${name}`, { cause: error });
1534
1606
  }
1535
1607
  if (packageFile !== void 0) {
1536
1608
  const engine = await readEngine(packageFile, "native", target);
@@ -1539,7 +1611,6 @@ async function resolveEngine(resolvePackage = (name) => require.resolve(`${name}
1539
1611
  if (!(minimum && host && minimum.some((part, index) => part > (host[index] ?? 0) && minimum.slice(0, index).every((prior, priorIndex) => prior === host[priorIndex])))) return engine;
1540
1612
  }
1541
1613
  }
1542
- if (platform !== "linux") throw new Error(`Unsupported LibreOfficeKit host: ${platform}-${arch}`);
1543
1614
  return readEngine(resolvePackage(`${ENGINE_PREFIX}-wasm`), "wasm", "wasm");
1544
1615
  }
1545
1616
  async function engineAsset(root, value, name, kind) {
@@ -1564,6 +1635,7 @@ async function readEngine(packageFile, backend, target) {
1564
1635
  root,
1565
1636
  programDirectory: await engineAsset(root, engine.programDirectory, "programDirectory", "directory"),
1566
1637
  executable,
1638
+ ...["0.1.1", "0.1.5"].includes(String(pkg.version)) ? { legacyInputPath: true } : {},
1567
1639
  ...glibcFloor
1568
1640
  };
1569
1641
  }
@@ -1680,6 +1752,7 @@ async function discoverRuntime() {
1680
1752
  return {
1681
1753
  version: ENGINE_VERSION,
1682
1754
  backend: engine.backend,
1755
+ nativePreview: engine.backend === "native" && !engine.legacyInputPath,
1683
1756
  cliPath: fileURLToPath(new URL("./cli.js", import.meta.url)),
1684
1757
  nodeApiPath: fileURLToPath(new URL("./index.js", import.meta.url))
1685
1758
  };
@@ -1968,16 +2041,9 @@ function createConverterWith(resolvedOptions, engine, shared, onDispose) {
1968
2041
  output = await open(request.outputPath, "wx", 384);
1969
2042
  const sourceBytes = await readBounded(request.inputPath, resolvedOptions.maxInputBytes, stopped, "input");
1970
2043
  scratch = await mkdtemp(join(tmpdir(), "libreoffice-kit-"));
1971
- const inputPath = join(scratch, `document.${extension}`);
1972
- const input = await open(inputPath, "wx", 384);
1973
- try {
1974
- await input.writeFile(sourceBytes);
1975
- } finally {
1976
- await input.close();
1977
- }
1978
2044
  const fonts = await snapshot(stopped);
1979
2045
  const result = await runWorker({
1980
- inputPath,
2046
+ bytes: sourceBytes,
1981
2047
  extension,
1982
2048
  operation: request,
1983
2049
  options: resolvedOptions,
@@ -1994,7 +2060,10 @@ function createConverterWith(resolvedOptions, engine, shared, onDispose) {
1994
2060
  const profile = join(scratch, "profile");
1995
2061
  await mkdir(profile, { mode: 448 });
1996
2062
  const path = join(scratch, `output.${format}`);
1997
- await runNative(native, resolvedOptions, inputPath, path, profile, result.fonts, result.substitutions, stopped, request);
2063
+ await runNative(native, resolvedOptions, {
2064
+ bytes: sourceBytes,
2065
+ format: extension
2066
+ }, path, profile, result.fonts, result.substitutions, stopped, request);
1998
2067
  bytes = await readBounded(path, resolvedOptions.maxOutputBytes, stopped, "output");
1999
2068
  }
2000
2069
  validateOutput(bytes, format);
@@ -2045,14 +2114,9 @@ function createConverterWith(resolvedOptions, engine, shared, onDispose) {
2045
2114
  owned = true;
2046
2115
  const source = await readBounded(request.inputPath, resolvedOptions.maxInputBytes, stopped, "input");
2047
2116
  scratch = await mkdtemp(join(tmpdir(), "libreoffice-kit-images-"));
2048
- const inputPath = join(scratch, `document.${request.extension}`);
2049
- await writeFile(inputPath, source, {
2050
- flag: "wx",
2051
- mode: 384
2052
- });
2053
2117
  const fonts = await snapshot(stopped);
2054
2118
  const result = await runWorker({
2055
- inputPath,
2119
+ bytes: source,
2056
2120
  extension: request.extension,
2057
2121
  operation: request,
2058
2122
  options: resolvedOptions,
@@ -2068,7 +2132,6 @@ function createConverterWith(resolvedOptions, engine, shared, onDispose) {
2068
2132
  images = await renderImagesWithNative({
2069
2133
  engine,
2070
2134
  options: resolvedOptions,
2071
- inputPath,
2072
2135
  source,
2073
2136
  scratch,
2074
2137
  profile,