@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/NOTICE CHANGED
@@ -1,3 +1,7 @@
1
+ Browser presentation, Electron texture transfer and adapter detection, and GPU diagnostic examples originate from MIT-licensed DeepSeek Harness commit 21261bee8b9a820c62c9e42cade3ff644b747a29. They retain the frame-forwarding/LICENSE notice.
2
+
3
+ The frame-forwarding subpaths contain MIT-licensed SDK sources from DeepSeek Harness at commit 4438b67c13d529c9882d89893ed5cd610ace11cc, integrated with the LibreOffice Kit WebGPU adapter from commit 2ae2de8c7e88df00e74ee538ebd5662f47c7a1df. The SDK retains its MIT license in frame-forwarding/LICENSE. The Windows Node delay-load implementation retains its separate notice in frame-forwarding/src/win-delay-load.LICENSE. Native-render does not require the LibreOffice engine.
4
+
1
5
  LibreOffice Kit incorporates font handling and conversion integration derived from DeepSeek Harness. These portions retain the following notice. LibreOffice engine sources and their separate third-party notices are distributed in the engine packages.
2
6
 
3
7
  The adapter's src/native-font-names.ts contains font-name data derived from LibreOffice Core's unotools/source/misc/fontdefs.cxx at commit bce0998afefdbc355585ca324285661a2170ba77. That file retains the upstream Mozilla Public License 2.0 notice and the Apache Software Foundation notice for incorporated work licensed under the Apache License 2.0.
package/README.md CHANGED
@@ -4,19 +4,21 @@ English | [中文](README.zh.md)
4
4
 
5
5
  Convert, recalculate, and directly render local Office documents with prebuilt LibreOffice engines. Use the same API in a server, desktop application, or document-processing job, with configurable fonts, cancellation, and resource limits.
6
6
 
7
+ The conversion and native preview entry points can run together in one process, in either initialization order.
8
+
7
9
  Binary `.doc`, `.xls`, and `.ppt` inputs must be OLE compound documents, such as Office 97–2003 files. Renamed RTF/HTML and `.wps` inputs are unsupported. `missingFonts` is empty for binary inputs because their font tables are interpreted by LibreOffice rather than the OOXML inspector.
8
10
 
9
- The Node API version is independent of its platform engine versions. Version 0.1.3 uses macOS, Windows and WASM engines 0.1.3. `ENGINE_VERSION` and `discoverRuntime().version` identify the Node API; `ENGINE_VERSIONS` lists the exact compatible engine versions.
11
+ The Node API version is independent of its platform engine versions. The 0.2.0-alpha6 adapter uses alpha5 macOS and Windows x64 engines, retains the Windows ARM64 0.1.5 engine, and uses a portable alpha5 WASM package containing the 0.1.5 engine files. `ENGINE_VERSION` and `discoverRuntime().version` identify the Node API; `ENGINE_VERSIONS` lists the exact compatible engine versions. `discoverRuntime().nativePreview` distinguishes native preview support from PDF conversion. Missing native packages select WASM; malformed installed packages reject.
10
12
 
11
13
  ## Installation and usage
12
14
 
13
- Install with Node.js 22.19.0 or newer:
15
+ Use Node.js 22.19.0 or newer. This command applies after alpha5 is published; unpublished candidates must be built and qualified from source first:
14
16
 
15
17
  ```sh
16
- npm install @deepseek-ai/libreoffice-kit@0.1.3
18
+ npm install @deepseek-ai/libreoffice-kit@0.2.0-alpha6
17
19
  ```
18
20
 
19
- npm installs the matching native engine on macOS/Windows ARM64 or x64, and the shared WASM engine on Linux. macOS and Windows require their native package; a missing or invalid package rejects `createConverter` with `unavailable`, without switching to WASM. Linux uses WASM unless a compatible development native package was installed explicitly. Conversion failures never switch engines.
21
+ npm installs the shared WASM engine and any matching native engine. The adapter prefers a compatible installed native engine, then selects WASM when no native package supports the host or the optional native package is absent. A corrupt installed package rejects with `unavailable`. Conversion failures never switch engines.
20
22
 
21
23
  ```js
22
24
  import { createConverter } from '@deepseek-ai/libreoffice-kit';
@@ -54,11 +56,11 @@ Right-to-left worksheets produce readable PNG text with column A on the right. A
54
56
 
55
57
  Conversion workers run the package's shipped JavaScript with an empty `execArgv`; consumer launch flags such as `--input-type=module` are not inherited.
56
58
 
57
- Windows native helpers use anonymous stdio pipes and inherit the caller's token and Job restrictions. Pipe polling does not occupy libuv worker threads while a helper waits for commands. Cancellation and rejected worksheet selections wait for process exit and pipe closure, including when the protocol reader has paused stdout; this transport does not grant additional filesystem or network access.
59
+ Windows conversion, image-rendering, and persistent-editing helpers use anonymous stdio pipes and inherit the caller's token and Job restrictions. The pipes preserve binary pixel frames, and polling does not occupy libuv worker threads while a helper waits for commands. Closure waits for process exit and output drainage after cancellation and rejected worksheet selections, including when the protocol reader has paused stdout; this transport does not grant additional filesystem or network access.
58
60
 
59
61
  Native conversion and image-rendering helpers disable printer enumeration and default-printer lookup with `SAL_DISABLE_PRINTERLIST=1` and `SAL_DISABLE_DEFAULTPRINTER=1`. Document previews and exports do not need a physical printer; these child-process settings prevent printer-driver dialogs and network-printer connection waits without changing the system's printer settings.
60
62
 
61
- On Windows, an engine executable or program path of 260 or more characters uses a temporary helper copy and a junction to the installed resources inside the private operation directory. Resources stay in their installation, and the junction remains until the helper closes. A renderer that exits before returning a protocol response rejects with its exit status and captured diagnostics.
63
+ On Windows, an engine executable or program path of 260 or more characters uses a temporary helper copy and a junction to the installed resources inside the private operation directory. Resources stay in their installation. Conversion, image rendering, and editing retain the helper paths until the child closes, including during startup failure; cleanup then unlinks the junction. A renderer that exits before returning a protocol response rejects with its exit status and captured diagnostics.
62
64
 
63
65
  On Linux, the native child searches the selected engine's program directory before system paths for shared libraries. Caller-provided `LD_LIBRARY_PATH` and `LD_PRELOAD` are not inherited.
64
66
 
@@ -66,11 +68,41 @@ The caller authorizes input access and owns private input/output directories; pa
66
68
 
67
69
  `ConversionError.code` distinguishes `invalid-document`, `unsupported-format`, `input-too-large`, `output-too-large`, `invalid-output`, `timeout`, `unavailable`, and `failed`. These codes survive the worker/native transports. Invalid installation assets reject creation as `unavailable`; they never enable fallback. Filesystem errors such as `EEXIST`, invalid configuration errors, and caller cancellation reasons remain unchanged.
68
70
 
71
+ ## Native editor
72
+
73
+ `@deepseek-ai/libreoffice-kit/editor` opens a persistent DOCX, XLSX, or PPTX document with `openDocument()`. The caller owns authorization, input bytes, rendering, and saved snapshots; `close()` joins the native process. Editing requires `writable: true`. The editor does not expose a browser document model or LibreOffice desktop windows.
74
+
75
+ `openDocument({ onProgress })` reports `fonts`, `engine`, and `document` when each loading stage begins. Observer failures become warnings. Rendering can start only after the returned promise resolves; the callback does not make LibreOffice import incremental.
76
+
77
+ Native document loading sends owned bytes over the helper's stdin into a seekable UNO `InputStream` with `private:stream`; it does not create an input document file. Conversion and image rendering read the caller's input path once and pass bytes to both the inspection worker and the native loader. The standard LibreOfficeKit URL-only loader cannot supply this stream: the bundled Core adds a private memory-loading entry. Missing that entry fails instead of writing a fallback file. Profile/font files, save/export outputs, and LibreOffice's internal repair or storage temporaries are separate; this is not a guarantee of zero filesystem activity. WASM uses its in-memory filesystem.
78
+
79
+ `renderBackend` selects the native drawing backend. The default `"auto"` enables LibreOffice's Skia Ganesh GPU path, which uses Vulkan on Windows and Metal on macOS, and keeps CPU drawing when the driver is denylisted, the GPU context cannot start, or shared-image import fails its initialization probe; `getInfo().renderBackend` reports the backend actually in use, so callers can surface that fallback. `"ganesh"` requires the GPU backend and rejects the open when it is unavailable, `"graphite"` initializes a native Dawn device before loading the document and binds each final output device directly to a borrowed SDK texture, and `"raster"` forces CPU rendering. `graphiteCacheBytes` defaults to 128 MiB, divided between the Graphite context and recorder caches; live/inflight allocations and SDK display textures are outside this cache budget. Forced-backend creation failures reject opening; shared rendering failures do not select another backend or close the document. The owner may export the current in-memory document and explicitly open a raster replacement.
80
+
81
+ When migrating from 0.1.3 to the 0.2.0 preview, update the Node adapter and its exact platform engines together; engines from 0.1.3 cannot serve the new editor startup options. Existing conversion calls keep their behavior, while editor calls that need the previous CPU path must set `renderBackend: "raster"`; omission now selects `"auto"`. Opt into `graphite` when opening a desktop document and retain the same shared receiver attachment, input ordering and release responsibilities. Changing backends requires a new process: export the current in-memory snapshot, open its replacement with `renderBackend: "raster"` before closing the old editor, and restore the view in the owner. The snapshot preserves document content, not the old undo/redo stack or running slideshow state. If export or replacement initialization fails, retain the old editor and its unsaved document.
82
+
83
+ Devices without a usable Graphite backend reject initialization; Linux development native engines support raster only. Borrowed WebGPU objects remain in the native document process; no device is passed through Node or a browser. Dawn manages GPU submission and completion, while the native SDK manages shared access across processes, frame credits, and consumer release. Submitting a WebGPU queue alone does not mean a display consumer has finished using an image.
84
+
85
+ Opening requires editor protocol 4 and frame-forwarding protocol 1 from the installed engine. A missing or incompatible protocol rejects initialization without selecting another engine.
86
+
87
+ `getSelection()` returns plain text or HTML for the active selection. Native JSON replies use `maxOutputBytes` with a 1 MiB minimum; a reply exceeding that budget rejects the operation while keeping the document open. Escape cancels selection even with modifiers and does not open native command popups.
88
+
89
+ `setViewport()` sets the actual visible rectangle in twips and the client pixel/twip scale. Writer opens in print layout; zooming and resizing the viewport preserve its page geometry and line breaks. Impress text selection uses the active cell's line-height settings for rendering and hit testing, including merged cells and vertical alignment.
90
+
91
+ `render()` and `renderSurface()` accept an optional zero-based `part` in the paint rectangle for background presentation slides. These requests use a lazily created, read-only view of the existing document, preserve the active part and selection, and restore the active view before accepting further input. Word pages use their document rectangles. Both operations require slideshow playback to be stopped. Opening still completes native import and pagination before rendering can begin.
92
+
93
+ `render()` and `presentationFrame()` return tightly packed straight RGBA in a dedicated buffer that later renders never reuse. The native worker normalizes document tiles in place; opaque slideshow frames already use this format. The adapter validates dimensions and the explicit pixel format without copying or converting the returned pixels.
94
+
95
+ `input()` and `dispatch()` submit ordered input and whitelisted editing commands. `exportSnapshot()` returns original-format bytes with their format and revision; the caller saves them. Opening copies the input bytes, and editing or exporting never overwrites the caller's source. Read-only documents reject mutations and snapshot export. An abort signal ends the document lifetime; call `close()` to await cleanup even after an operation fails.
96
+
97
+ Desktop applications that need shared images can bind a trusted native receiver to `processId`, then use `attachSurfaceTransport()`, `renderSurface()`, or `presentationSurface()`. Replies carry correlation fields while the separate SDK transports the image; the receiver releases each frame after its display consumer finishes. `waitForInput()` orders commands or exports after the requested input sequence. `detachSurfaceTransport()` retains the document. A healthy device can still serve RGBA requests, but detaching does not change the backend and Graphite pixel requests require readback. Raster reads tiles into a CPU buffer and uploads them into the SDK texture. Ganesh reuses LibreOffice's existing GPU context and copies its final image into the SDK texture with Metal blits or Vulkan external-memory copies; Windows allocates that texture on the Vulkan device's matching D3D11 adapter. Ganesh and Graphite shared output skip final-target CPU readback; document features may still need internal bitmap reads or asset uploads.
98
+
99
+ Continuous presentation streams acquire and publish only when the slideshow requests a canvas update. Static or paused slides retain their last image without consuming additional frame credits. A pending change survives unavailable credits; the next successful frame includes the latest state, including an animation's final frame. Starting a stream or changing its viewport forces a frame. Explicit `presentationFrame()` and `presentationSurface()` calls still return a frame on every request; document views paint only on explicit requests.
100
+
69
101
  ## Engines, fonts, and runtime behavior
70
102
 
71
103
  The Node API reports its release version through `ENGINE_VERSION`; `ENGINE_VERSIONS` pins each platform engine independently. npm installs prepared engines; installation and conversion never compile LibreOffice or download additional engine payloads. Each engine includes its matching source recipes, patches, build information, and third-party license notices under `sources/` and `licenses/`.
72
104
 
73
- 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. Original font bytes and decoded glyph coverage remain conversion-local. `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.
105
+ 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.
74
106
 
75
107
  ### Font metadata cache
76
108
 
@@ -112,4 +144,8 @@ This package is licensed under [MPL-2.0](LICENSE). The engine packages include `
112
144
  - Font import and output limits do not bound all native memory or temporary disk use. Native platform engines may resolve fonts differently from WASM.
113
145
  - Installations from npm use platform-specific optional packages. Applications that bundle engines must retain the complete selected package, including its resources and notices.
114
146
  - Windows requires the Microsoft Visual C++ v14 Redistributable matching the Node.js architecture (x64 or ARM64); it is not bundled. Use ARM64 Node.js for the Windows ARM64 engine.
115
- - Version `0.1.0` ships macOS and Windows native engines for ARM64 and x64 and a shared Node WASM engine for Linux. Other native platforms are development recipes.
147
+ - The preview declares macOS and Windows native engines for ARM64 and x64 and a shared Node WASM engine for Linux. Other native platforms are development recipes.
148
+
149
+ ## Native rendering SDK
150
+
151
+ `@deepseek-ai/libreoffice-kit/frame-forwarding` provides the standalone Node producer/receiver and C/C++ SDK for macOS and Windows x64/ARM64. Install with `--omit=optional` when LibreOffice engines are not needed. All four addons and static libraries ship in the main Kit package. `./frame-forwarding/sdk` describes source and library paths, and `./frame-forwarding/verify` checks complete SDK payloads. Installation and normal runtime do not compile or download native code. See the [SDK documentation](../frame-forwarding/README.md) for ownership and explicit diagnostic builds.
package/README.zh.md CHANGED
@@ -4,21 +4,21 @@
4
4
 
5
5
  使用预编译 LibreOffice 引擎,在 Node.js 中转换、重算并直接渲染本地 Office 文档。通过同一套 API,为服务端、桌面应用和文档处理任务提供可配置字体、取消和资源限制。
6
6
 
7
+ 转换与原生预览入口可在同一进程中同时使用,不受初始化顺序影响。
8
+
7
9
  二进制 `.doc`、`.xls`、`.ppt` 输入必须是 OLE 复合文档,例如 Office 97–2003 文件。不支持改后缀的 RTF/HTML 和 `.wps`。二进制输入的 `missingFonts` 为空,因为其字体表由 LibreOffice 读取,而不是由 OOXML 检查器读取。
8
10
 
9
- Node API 与各平台引擎独立指定版本。0.1.3 使用 macOS、Windows 和 WASM 引擎 0.1.3。`ENGINE_VERSION` 和 `discoverRuntime().version` 表示 Node API 版本;`ENGINE_VERSIONS` 列出各平台兼容的精确引擎版本。
11
+ Node API 与各平台引擎独立指定版本。0.2.0-alpha6 转换器使用 alpha5 的 macOS 与 Windows x64 引擎,保留 Windows ARM64 的 0.1.5 引擎,并使用包含 0.1.5 引擎文件的通用 alpha5 WASM 包。`ENGINE_VERSION` 和 `discoverRuntime().version` 表示 Node API 版本;`ENGINE_VERSIONS` 列出各平台兼容的精确引擎版本。`discoverRuntime().nativePreview` 区分原生预览与 PDF 转换能力。缺少原生包时选择 WASM;已安装的包损坏时拒绝。
10
12
 
11
13
  ## 安装与使用
12
14
 
13
- 使用 Node.js 22.19.0 或更新版本安装:
15
+ 使用 Node.js 22.19.0 或更新版本。以下命令适用于已发布的 alpha5 包;未发布的候选包需先从源码构建并验证:
14
16
 
15
17
  ```sh
16
- npm install @deepseek-ai/libreoffice-kit@0.1.3
18
+ npm install @deepseek-ai/libreoffice-kit@0.2.0-alpha6
17
19
  ```
18
20
 
19
- npm 在 macOS/Windows ARM64 或 x64 上安装匹配的原生引擎,Windows 上,引擎可执行文件或程序目录路径达到 260 个字符时,在私有操作目录中使用 helper 临时副本和指向已安装资源的 junction。资源保留在安装目录,junction 在 helper 关闭后清理。渲染器若在返回协议响应前退出,会携带退出状态和捕获的诊断信息拒绝操作。
20
-
21
- 在 Linux 上安装共享 WASM 引擎。macOS 和 Windows 必须具有对应原生包;包缺失或无效时,`createConverter` 以 `unavailable` 拒绝,不会切换到 WASM。Linux 使用 WASM,除非显式安装了兼容的原生开发包。转换失败不会切换引擎。
21
+ npm 安装共享 WASM 引擎和匹配平台的原生引擎。转换器优先使用已安装且兼容的原生引擎;平台没有原生包或可选原生包未安装时选择 WASM。已安装的包损坏时以 `unavailable` 拒绝。转换失败不会切换引擎。
22
22
 
23
23
  ```js
24
24
  import { createConverter } from '@deepseek-ai/libreoffice-kit';
@@ -56,21 +56,53 @@ npm exec -- dsoffice recalculate --input budget.xlsx --output recalculated.xlsx
56
56
 
57
57
  转换 worker 以空的 `execArgv` 运行包内发布的 JavaScript;`--input-type=module` 之类的调用方启动参数不会被继承。
58
58
 
59
- Windows 原生 helper 使用匿名标准输入输出管道,继承调用方的令牌和 Job 限制。helper 等待命令时,管道轮询不会占用 libuv 工作线程。取消及工作表选择失败均会等待进程退出和管道关闭,包括协议读取器已暂停 stdout 的情况;此传输方式不授予额外的文件系统或网络权限。
59
+ Windows 的转换、图像渲染和持久编辑 helper 使用匿名标准输入输出管道,继承调用方的令牌和 Job 限制。管道保持二进制像素帧完整,helper 等待命令时的管道轮询不会占用 libuv 工作线程。取消及工作表选择失败后,关闭会等待进程退出并读完输出,包括协议读取器已暂停 stdout 的情况;此传输方式不授予额外的文件系统或网络权限。
60
60
 
61
61
  原生转换和图片渲染 helper 设置 `SAL_DISABLE_PRINTERLIST=1` 与 `SAL_DISABLE_DEFAULTPRINTER=1`,禁用打印机枚举和默认打印机查询。文档预览和导出不需要实体打印机;这些子进程设置可避免打印机驱动弹窗及网络打印机连接等待,不会修改系统打印机设置。
62
62
 
63
+ Windows 上,引擎可执行文件或程序目录路径达到 260 个字符时,在私有操作目录中使用 helper 临时副本和指向已安装资源的 junction。转换、图像渲染和编辑均保留这些路径直到子进程退出,包括启动失败时;随后清理 junction。渲染器若在返回协议响应前退出,会携带退出状态和捕获的诊断信息拒绝操作。
64
+
63
65
  在 Linux 上,原生子进程会先在所选引擎的 program 目录中查找共享库,然后才查找系统路径。调用方提供的 `LD_LIBRARY_PATH` 和 `LD_PRELOAD` 不会被继承。
64
66
 
65
67
  调用方负责授权输入访问并拥有私有输入/输出目录;路径必须是绝对路径,并在转换期间保持不变。输入文件必须是常规 Office 文件,且在配置的字节限制之内。ZIP 条目数和解压大小限制适用于 OOXML;二进制 DOC/XLS/PPT 使用 OLE 复合容器,内部结构由 LibreOffice 导入器验证。二进制格式仍遵守相同的转换超时和输入/输出限制。输出创建使用独占模式和 `0600` 权限;已存在的输出绝不会被覆盖。失败或取消的渲染会删除新建的输出。`maxOutputBytes` 限制返回的 PDF 及其读取缓冲区;原生临时磁盘文件在导出完成前可能继续增长,随后过大的 PDF 会在 Node 读取之前被拒绝并删除。成功的 PDF 归调用方所有,调用方可以将其字节发送给浏览器 PDF 阅读器。
66
68
 
67
69
  `ConversionError.code` 区分 `invalid-document`、`unsupported-format`、`input-too-large`、`output-too-large`、`invalid-output`、`timeout`、`unavailable` 和 `failed`。这些 code 会原样穿过 worker 和原生传输层。无效的安装资源会让创建以 `unavailable` 拒绝;它们绝不会启用回退。`EEXIST` 等文件系统错误、无效配置错误和调用方取消原因保持原样。
68
70
 
71
+ ## 原生编辑器
72
+
73
+ `@deepseek-ai/libreoffice-kit/editor` 通过 `openDocument()` 打开常驻的 DOCX、XLSX 或 PPTX 文档。调用方负责访问授权、输入字节、绘制和保存快照;`close()` 会等待原生进程退出。编辑需要设置 `writable: true`。编辑器不提供浏览器文档模型或 LibreOffice 桌面窗口。
74
+
75
+ `openDocument({ onProgress })` 在各加载阶段开始时报告 `fonts`、`engine` 和 `document`。观察函数抛错会转为警告。只有返回的 Promise 完成后才能开始绘制;该回调不会让 LibreOffice 导入变为渐进式。
76
+
77
+ 原生文档加载将自有 bytes 通过 helper 的 stdin 传入可寻址的 UNO `InputStream`,以 `private:stream` 打开,不创建输入文档文件。转换和图像渲染读取一次调用方输入路径,将 bytes 传给检查 worker 和原生加载器。标准 LibreOfficeKit 加载接口只接受 URL,无法传入流;内置 Core 增加私有内存加载入口,缺少该入口会明确失败,不回退到写文件。配置与字体文件、保存与导出输出,以及 LibreOffice 内部修复或存储临时文件另行管理;这不代表完全没有文件系统活动。WASM 使用内存文件系统。
78
+
79
+ `renderBackend` 选择原生绘制后端。默认 `"auto"` 启用 LibreOffice 的 Skia Ganesh GPU 路径(Windows 用 Vulkan,macOS 用 Metal);当驱动进入黑名单或 GPU 上下文无法启动时保持 CPU 绘制,`getInfo().renderBackend` 返回实际使用的后端,便于调用方显式告警。`"ganesh"` 强制要求 GPU 后端,不可用时直接拒绝打开;`"graphite"` 在加载文档前初始化原生 Dawn device,并把最终输出设备直接绑定到 SDK 借用的纹理;`"raster"` 强制 CPU 绘制。`graphiteCacheBytes` 默认 128 MiB,分别分配给 Graphite context 和 recorder 缓存;正在使用或执行中的 GPU 分配以及 SDK 显示纹理不计入该缓存预算。强制指定的后端创建失败会拒绝打开文档;共享绘制失败不会切换后端或关闭文档。调用方可以导出当前内存文档,再显式打开 raster 替代进程。
80
+
81
+ 从 0.1.3 迁移到 0.2.0 预览版时,需要同时更新 Node adapter 和其精确匹配的平台引擎;0.1.3 引擎不能处理新增的编辑器启动选项。现有转换调用保持原有行为;需要此前 CPU 路径的编辑器调用必须设置 `renderBackend: "raster"`,因为省略它现在会选择 `"auto"`。打开桌面文档时可显式选择 `graphite`,共享 receiver 连接、输入顺序和释放责任保持一致。切换后端需要新进程:先导出当前内存快照,在旧编辑器关闭前用 `renderBackend: "raster"` 打开替代进程,并由调用方恢复视图。快照保留文档内容,但不保留旧的撤销/重做历史或正在运行的放映。导出或替代进程初始化失败时,应保留旧编辑器及其未保存文档。
82
+
83
+ Graphite 后端不可用的设备会拒绝初始化;Linux 原生开发引擎仅支持 raster。共享绘制借用的 WebGPU 对象留在原生文档进程内,不通过 Node 或浏览器传递 device。GPU 提交和完成由 Dawn 管理,跨进程共享访问、帧配额和消费者释放仍由原生 SDK 管理。单独提交 WebGPU queue 不表示显示消费者已使用完该图像。
84
+
85
+ 打开文档要求已安装的引擎提供编辑器协议 4 和 frame-forwarding 协议 1。缺失或不兼容的协议会使初始化失败,不会选择其他引擎。
86
+
87
+ `getSelection()` 返回当前选区的纯文本或 HTML。原生 JSON 回复以 `maxOutputBytes` 为预算,最低为 1 MiB;超出预算时只拒绝当前操作,文档保持打开。Escape 即使带有修饰键也只取消选择,不打开原生命令弹窗。
88
+
89
+ `setViewport()` 接收以 twip 为单位的实际可见区域和客户端像素/twip 比例。Writer 以打印布局打开;缩放和调整视口大小会保持纸张尺寸与换行。Impress 在文字选择的绘制和点击命中计算中使用当前单元格的行高设置,支持合并单元格与垂直对齐。
90
+
91
+ `render()` 和 `renderSurface()` 的绘制矩形可携带从零开始的 `part`,用于后台渲染幻灯片。此请求按需创建同一文档的只读视图,保留活动页和选区,并在接收后续输入前恢复活动视图。Word 页面使用其文档矩形坐标。两种绘制都要求先停止演示播放;打开文档仍需完成原生导入和分页后才能开始渲染。
92
+
93
+ `render()` 和 `presentationFrame()` 返回紧密排列、非预乘的 RGBA,使用后续渲染不会复用的独立缓冲区。原生 worker 原地转换文档图块;不透明的幻灯片播放帧本身已使用此格式。适配器校验尺寸和显式像素格式,不复制或转换返回的像素。
94
+
95
+ `input()` 和 `dispatch()` 按顺序提交输入与允许的编辑命令;`exportSnapshot()` 返回包含格式和修订号的原格式字节,调用方负责保存。打开时会复制输入字节,编辑和导出不会覆盖调用方源文件。只读文档拒绝修改和快照导出。取消信号结束文档生命周期;即使操作失败,也应调用 `close()` 等待清理。
96
+
97
+ 需要共享图像的桌面应用可通过 `processId` 绑定可信原生接收端,再调用 `attachSurfaceTransport()`、`renderSurface()` 或 `presentationSurface()`。回复只包含关联信息,图像由独立 SDK 传输;接收端在显示消费者完成使用后释放帧。`waitForInput()` 可让命令或导出等待对应输入序号;`detachSurfaceTransport()` 保留文档;设备健康时可继续请求 RGBA 输出,但它不会更换后端,Graphite 的像素请求仍需要回读。Raster 将 tile 回读到 CPU 缓冲区,再上传到 SDK 纹理。Ganesh 复用 LibreOffice 的 GPU 上下文,通过 Metal blit 或 Vulkan 外部内存复制将最终图像送入 SDK 纹理;Windows 在与 Vulkan 设备匹配的 D3D11 适配器上分配纹理。Ganesh 和 Graphite 的共享输出均跳过最终目标的 CPU 回读。文档功能仍可能要求内部位图回读或素材上传。
98
+
99
+ 连续放映流仅在幻灯片请求 canvas 更新时申请并提交帧。静止或暂停时保留最后一张图像,不消耗额外帧额度。等待可用额度期间会保留变化,下一次成功提交包含最新状态及动画末帧。启动流或更改视口会强制输出一帧。显式调用 `presentationFrame()` 和 `presentationSurface()` 仍每次返回一帧;文档视图仅在显式请求时绘制。
100
+
69
101
  ## 引擎、字体与运行行为
70
102
 
71
103
  Node API 通过 `ENGINE_VERSION` 报告其发布版本;`ENGINE_VERSIONS` 独立固定各平台的引擎版本。npm 安装预编译引擎;安装和转换阶段均不会编译 LibreOffice 或额外下载引擎资源。每个引擎包的 `sources/` 和 `licenses/` 保留匹配的源码配方、补丁、构建信息和第三方许可声明。
72
104
 
73
- 默认值和所有选项记录在随包发布的 `lib/types/index.d.ts` 类型声明中。字体目录使用所选操作系统的常规系统/用户路径。索引会跳过缺失或受保护的来源,并传播其他文件系统错误。`fontkit` 索引原始字体文件并选择已安装的字面和字形覆盖;它不重写字体。每次操作都会重新发现字体候选并验证缓存中的文件身份。一次操作使用一份有序元数据快照;快照变化后字体匹配条目失效。检测到转换期间字体变化时,操作会失败并删除其输出。原始字体字节和解码后的字形覆盖都只在本次转换内有效。精确的 family 匹配优先于 `fontFallbacks`。`missingFonts` 包含可读文档 XML 中声明但缺失的 family,不包含无关的引擎默认值。未命名缺失 family 的缺字并不构成完整的文档可访问性报告。
105
+ 默认值和所有选项记录在随包发布的 `lib/types/index.d.ts` 类型声明中。字体目录使用所选操作系统的常规系统/用户路径。索引会跳过缺失或受保护的来源,并传播其他文件系统错误。`fontkit` 索引原始字体文件并选择已安装的字面和字形覆盖;它不重写字体。每次操作都会重新发现字体候选并验证缓存中的文件身份。一次操作使用一份有序元数据快照;快照变化后字体匹配条目失效。检测到转换期间字体变化时,操作会失败并删除其输出。字形匹配仅查询请求中的 Unicode 码点,同一物理字体集合中的各字面共享一次解码。码点查询结果只在本次操作内保留,开始检查下一文件前释放当前解析对象;不会遍历所有字形,也不会跨文档缓存字体字节。精确的 family 匹配优先于 `fontFallbacks`。`missingFonts` 包含可读文档 XML 中声明但缺失的 family,不包含无关的引擎默认值。未命名缺失 family 的缺字并不构成完整的文档可访问性报告。
74
106
 
75
107
  ### 字体元数据缓存
76
108
 
@@ -112,4 +144,8 @@ Node WASM 的图像降采样使用 LibreOffice 的 CPU 图像过滤器。文本
112
144
  - 字体导入和输出限制不能约束全部原生内存或临时磁盘使用。原生平台引擎的字体解析可能与 WASM 不同。
113
145
  - npm 安装使用按平台选择的可选包。自行打包引擎的应用需要保留所选包的完整内容,包括资源和许可声明。
114
146
  - Windows 需要系统安装与 Node.js 架构一致的 Microsoft Visual C++ v14 Redistributable(x64 或 ARM64);包中不捆绑该运行库。Windows ARM64 引擎需要使用 ARM64 Node.js。
115
- - `0.1.0` 提供 macOS 和 Windows 的 ARM64、x64 原生引擎,以及供 Linux 使用的共享 Node WASM 引擎;其他原生平台仅保留开发构建配方。
147
+ - 预览版声明 macOS 和 Windows 的 ARM64、x64 原生引擎,以及供 Linux 使用的共享 Node WASM 引擎;其他原生平台仅保留开发构建配方。
148
+
149
+ ## 原生渲染 SDK
150
+
151
+ `@deepseek-ai/libreoffice-kit/frame-forwarding` 提供独立的 Node 生产者、接收者和 C/C++ SDK,支持 macOS、Windows 的 x64/ARM64。不需要 LibreOffice 引擎时可使用 `--omit=optional` 安装。四套插件及静态库均随 Kit 主包分发。`./frame-forwarding/sdk` 描述源码与库路径,`./frame-forwarding/verify` 校验完整 SDK。正常安装和运行不编译或下载原生二进制。资源所有权与显式诊断构建见 [SDK 文档](../frame-forwarding/README.zh.md)。
@@ -0,0 +1,40 @@
1
+ cmake_minimum_required(VERSION 3.20)
2
+ file(READ "${CMAKE_CURRENT_SOURCE_DIR}/sdk.json" DSH_FRAME_FORWARDING_METADATA)
3
+ string(JSON DSH_FRAME_FORWARDING_VERSION GET "${DSH_FRAME_FORWARDING_METADATA}" version)
4
+ string(REGEX REPLACE "-.*$" "" DSH_FRAME_FORWARDING_CMAKE_VERSION "${DSH_FRAME_FORWARDING_VERSION}")
5
+ project(dsh_frame_forwarding VERSION ${DSH_FRAME_FORWARDING_CMAKE_VERSION} LANGUAGES CXX)
6
+ add_library(dsh_frame_forwarding_sdk STATIC src/producer.cc src/transport.cc)
7
+ target_compile_features(dsh_frame_forwarding_sdk PUBLIC cxx_std_17)
8
+ target_include_directories(dsh_frame_forwarding_sdk PUBLIC include PRIVATE src)
9
+ set_target_properties(dsh_frame_forwarding_sdk PROPERTIES POSITION_INDEPENDENT_CODE ON)
10
+ target_compile_options(dsh_frame_forwarding_sdk PRIVATE $<$<PLATFORM_ID:Windows>:/EHsc>)
11
+ if(APPLE)
12
+ target_link_libraries(dsh_frame_forwarding_sdk PUBLIC "-framework IOSurface" "-framework CoreFoundation" bsm)
13
+ elseif(WIN32)
14
+ target_compile_definitions(dsh_frame_forwarding_sdk PUBLIC _WIN32_WINNT=0x0602)
15
+ target_link_libraries(dsh_frame_forwarding_sdk PUBLIC d3d11 dxgi advapi32)
16
+ else()
17
+ message(FATAL_ERROR "DSH native render requires macOS or Windows")
18
+ endif()
19
+ install(TARGETS dsh_frame_forwarding_sdk ARCHIVE DESTINATION lib)
20
+ install(FILES include/dsh_frame_forwarding.h include/dsh_frame_forwarding_engine.h include/dsh_frame_forwarding_node.h DESTINATION include)
21
+
22
+ option(DSH_FRAME_FORWARDING_WEBGPU "Build the native WebGPU producer adapter" OFF)
23
+ if(DSH_FRAME_FORWARDING_WEBGPU)
24
+ if(NOT DSH_DAWN_SOURCE_DIR)
25
+ message(FATAL_ERROR "Use scripts/build-webgpu.mjs to prepare the pinned Dawn sources")
26
+ endif()
27
+ set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
28
+ set(DAWN_BUILD_MONOLITHIC_LIBRARY STATIC CACHE STRING "" FORCE)
29
+ set(DAWN_ENABLE_INSTALL ON CACHE BOOL "" FORCE)
30
+ add_subdirectory("${DSH_DAWN_SOURCE_DIR}" dawn)
31
+ set_target_properties(webgpu_dawn PROPERTIES OUTPUT_NAME dawn)
32
+ add_library(dsh_webgpu STATIC src/webgpu.cc)
33
+ target_compile_features(dsh_webgpu PUBLIC cxx_std_20)
34
+ target_include_directories(dsh_webgpu PUBLIC include)
35
+ target_link_libraries(dsh_webgpu PUBLIC dsh_frame_forwarding_sdk dawn::webgpu_dawn)
36
+ set_target_properties(dsh_webgpu PROPERTIES POSITION_INDEPENDENT_CODE ON)
37
+ target_compile_options(dsh_webgpu PRIVATE $<$<PLATFORM_ID:Windows>:/EHsc>)
38
+ install(TARGETS dsh_webgpu ARCHIVE DESTINATION lib)
39
+ install(FILES include/dsh_webgpu.h DESTINATION include)
40
+ endif()
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DeepSeek
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,83 @@
1
+ # Frame forwarding SDK
2
+
3
+ English | [中文](README.zh.md)
4
+
5
+ The `@deepseek-ai/libreoffice-kit/frame-forwarding` package connects an authorized native producer to Electron Main without routing pixels through DSH Host. This public Kit subpath contains Node/TypeScript producer and receiver APIs backed by the same Electron-independent C/C++ SDK. Its payload includes explicitly listed C/C++ build sources; source globs and source maps are excluded. macOS uses IOSurface with Mach port transfer; Windows uses D3D11 shared NT handles and an owner-only named pipe. Separate browser and Electron subpaths provide presentation and texture ownership; consumers own authorization and application commands.
6
+
7
+ Installing Kit with `--omit=optional` provides the SDK without Office engines or the Windows Office pipe dependency Koffi. Normal installation retains both optional dependency selections. Neither SDK installation nor SDK communication compiles or downloads binaries.
8
+
9
+ ## Receiver
10
+
11
+ Create one `createBudget(maxBytes)` per window and pass it to every `createReceiver({ maxFrames, maxBytes, budget, displayAdapter, readbackTimeoutMs, framePolicy }, onEvent)`. Start the owned producer through its normal application lifecycle, bind its PID once with `bindProducer(pid)`, and pass the private `endpoint` directly to that producer. The endpoint contains authentication credentials and must never reach the Renderer or logs.
12
+
13
+ Frame events carry `transport: "shared-texture"`, an eight-byte native handle, the producer's `frameId`, and a receiver-owned `deliveryId`. Call `release(deliveryId)` only after Electron reports `allReferencesReleased`; queue submission and frame timeout do not release consumer ownership. Delivery IDs remain distinct when a producer reuses a released frame ID. Duplicate releases return false. `close()` asynchronously drains submitted GPU work and joins the owned workers; delivered resources remain retained until release or receiver destruction. A stalled GPU can keep close pending; cancellation never frees resources still used by that GPU.
14
+
15
+ Windows shared-texture receivers require the compositor’s actual adapter LUID in `displayAdapter`; creating one without it fails. The producer reports its device LUID during authentication, and the receiver verifies it against each texture. For matching adapters, keyed producer textures are imported directly; legacy textures are copied into a receiver-owned shared target. `sourceKeyedMutex` reports the actual source descriptor, independent of the handshake declaration. For different adapters, a native worker reads back the entire source texture and uploads its premultiplied BGRA pixels into a shared texture on the compositor’s adapter. JavaScript receives only its handle. `adapterId` identifies the source; `presentationAdapterId` identifies the exported texture’s adapter and is null for macOS IOSurface.
16
+
17
+ The receiver’s Windows target uses a keyed mutex recognized by Chromium to order GPU access; Electron’s reference-release callback controls lifetime but does not replace this synchronization. Cross-adapter copies preserve row pitch and return source credit as soon as the readback GPU copy completes; the independent target remains held until Electron releases its delivery. Same-adapter copying and macOS IOSurface retain source credit through delivery release. GPU completion uses reusable fence events when supported and bounded query polling otherwise. `readbackTimeoutMs` bounds native frame preparation and delivery; timeout or cancellation stops new work while retaining submitted copies until GPU completion or device removal. Worker termination and receiver garbage collection use the same asynchronous cleanup.
18
+
19
+ [Chromium 152 acquires key 0 with `INFINITE`](https://github.com/chromium/chromium/blob/24072c1aa400ec4a89dc738b6b6acd12a8589b6f/gpu/command_buffer/service/dxgi_shared_handle_manager.cc#L129). Before direct handoff, the receiver worker performs a bounded acquire/release readiness check. This moves a possible CPU wait to that worker without copying pixels; it does not impose a timeout on Chromium. A producer must release before submitting and must not access the surface until credit returns. A producer that violates this after the check can still stall Chromium or trigger its GPU watchdog.
20
+
21
+ Shared-texture `framePolicy` defaults to `ordered`, preserving independent request/reply frames such as Office tiles. Continuous streams may select `latest`: a completed relay readback replaces the frame whose upload has not begun, with at most one pending frame and one upload in progress. Two staging slots allow source copying while a prepared frame waits for a target. Held targets stop further uploads; ordered delivery also stops readback when both staging slots are occupied.
22
+
23
+ The byte budget reserves one surface per macOS allocation or declared Windows same-adapter keyed allocation. A legacy same-adapter allocation reserves a source plus target. The optional hello capability permits the smaller reservation; a declared keyed producer that supplies a non-keyed texture is rejected. An undeclared keyed source can still be imported directly, with the conservative legacy reservation. Relay reserves up to `N = maxFrames` source textures, `N` independent targets, and two staging textures. Target and staging capacity tracks the connection's largest requested frame; source and pool growth receive one atomic budget grant. Relay limits each frame to `maxBytes / (2N + 2)` bytes and advertises `N` times that allowance to the producer. With three frames and 256 MiB, three 4K BGRA sources plus the five receiver textures reserve 253.125 MiB. Idle storage retains its reservation; closing frees independent pool slots while each held target retains its own budget until release. Renderer queues and canvas storage have separate limits; this budget is not a process-memory ceiling.
24
+
25
+ `send(json)` queues a bounded control message without blocking Main on native I/O. Producer messages arrive as `message` events. OS peer identity is checked in addition to the endpoint credential. A receiver accepts one producer connection and cannot be rebound. Errors require the consumer to terminate or replace that connection. Frames discarded before delivery release their native resources; delivered frames still require explicit release after closure.
26
+
27
+ ## Node/TypeScript producer
28
+
29
+ Import `createProducer` from `@deepseek-ai/libreoffice-kit/frame-forwarding` inside the owning Node process. Bind the receiver to that Node process's PID; an in-process plugin uses `process.pid`. Pass the private endpoint, `maxPendingOperations`, `operationTimeoutMs`, and an optional native engine descriptor. Await `ready`, and register explicit `close()` with the owning plugin's disposal. The [TypeScript API](index.d.ts) defines operations and resource ownership.
30
+
31
+ A dedicated native worker serializes connection, uploads, engine callbacks, mutex waits and submission. A separate polling thread wakes it on credit and control events; acquisition does not poll on a timer. Accepted operations may queue before readiness; excess ordinary operations reject, including control messages. Discard has one reserved queue slot per owned lease so a full queue cannot prevent release. Pending acquisitions wait for credits without blocking worker execution. Acquisition timeout rejects that request without closing the producer. Transport or uncertain GPU completion failures close the connection. `closed` resolves after queued operations settle and the worker, client and engine are destroyed. Event-listener exceptions are contained; listeners remain responsible for their own diagnostics. Worker termination uses asynchronous native cleanup. Set `DSH_FRAME_FORWARDING_DIAGNOSTICS=1` to report contained producer callback exceptions to stderr.
32
+
33
+ `acquire(width, height)` returns an explicit surface lease. Await `writeBgra(buffer, stride)` or `render()`, then `submit(frameId, metadata)` or `discard()`; surface `close()` is a discard alias. Busy or consumed surfaces reject reuse. Garbage collection never grants frame credit. Submission consumes the lease, but the underlying texture remains unavailable until the receiver releases its frame.
34
+
35
+ CPU uploads borrow a non-shared Node Buffer until the returned promise settles. During that time callers must not modify it, detach it or transfer its backing ArrayBuffer. Row stride may exceed the packed row width. The binding retains the Buffer and avoids an intermediate binding copy; the C SDK still copies or uploads those bytes. CPU upload is not GPU zero-copy.
36
+
37
+ For continuous GPU rendering, supply an engine exported by another Node addon using [dsh_frame_forwarding_node.h](include/dsh_frame_forwarding_node.h). Its [engine callbacks](include/dsh_frame_forwarding_engine.h) run serially on the producer worker. The descriptor stays alive through engine destruction. `render` borrows the acquired native texture and releases imports before returning. Windows callbacks queue work on the supplied device's immediate context while the SDK owns key 0; they must not acquire that lock themselves. macOS callbacks complete GPU work before returning. Both observe cancellation. Third-party callbacks must return promptly; the SDK cannot preempt arbitrary engine code. Engine creation, update and destruction must not call JavaScript.
38
+
39
+ `start({ width, height, generation, frameIntervalMs })` renders continuously in native code; `update(json, inputSequence)` applies batched engine state, and `stop()` stops new frames. The interval includes rendering time and accepts fractions such as `1000 / 60`; elapsed deadlines are skipped without catch-up bursts. Manual leases must be released before starting. Frame metadata contains request ID, viewport generation, revision and the latest applied input sequence.
40
+
41
+ Engine ABI v2 adds `prepare` before surface acquisition: return 1 for a changed frame, 0 for no change, or -1 for failure. An unchanged frame makes no acquisition or submission and consumes no credit. A declared change remains pending through credit waits; preparation continues at the stream cadence, and newer updates may replace the state rendered when credit arrives. Start and resize force one frame, and updates make the next change check immediately eligible. ABI v1 keeps continuous rendering; manual Node callers skip a frame by not acquiring or submitting it. Manual `surface.render()` does not call `prepare`.
42
+
43
+ The display path can match the C producer's native path without per-frame JavaScript or pixel readback on the same adapter. End-to-end performance still depends on engine work, callbacks, pacing, GPU choice and CPU copying. Displayed-frame intervals, skipped revisions, input-to-observed-frame latency and memory require separate measurement; arrival throughput alone is not displayed FPS. Both languages use the same automatic receiver transport.
44
+
45
+ ## C/C++ producer
46
+
47
+ Include `include/dsh_frame_forwarding.h` and link the matching `libdsh_frame_forwarding_sdk.a` or `dsh_frame_forwarding_sdk.lib`, or build the sources listed in `sdk.json`. The API has no Node or Electron dependency. Poll on one thread; acquisition, writing, submission and discard may run on another. Callers must serialize use of the same graphics context. Interrupt polling, join that thread, and close the client after all its API calls return.
48
+
49
+ On Windows, `dsh_frame_forwarding_connect_with_device` accepts the application’s `ID3D11Device` and retains it until close. Passing null, or using `dsh_frame_forwarding_connect`, creates a default device. `dsh_frame_forwarding_connect_with_options` additionally bounds connection/handshake time and accepts a cancellation callback on the connecting thread. Applications choose their own GPU; DSH selects the transport. Serialize the adopted device’s immediate context with SDK writes. macOS requires a null device.
50
+
51
+ Acquisition initially returns null while the receiver grants allocation credit. Poll and retry when the owning application is ready; do not spin. Allocation requests enter a shared FIFO budget queue. Grants cover idle pool allocations as well as displayed frames. A null acquisition otherwise indicates exhausted credits; terminal allocation errors are reported by polling with `kind = -1` and explanatory text. Stop processing on a negative poll result and preserve its diagnostic before closing. A consumer must bound its overall operation lifetime and disconnect on timeout.
52
+
53
+ Textures use top-left BGRA8 premultiplied pixels in sRGB. Windows surfaces have a keyed mutex using key 0. Acquisition grants a lease without locking: SDK CPU uploads and engine callbacks own the write lock; external GPU writers own it themselves through `dsh_frame_forwarding_surface_keyed_mutex` or their import API. Writers release key 0 after queueing commands and release imported objects/views before submit or discard. CPU uploads copy the input before returning and do not wait for GPU completion; `dsh_frame_forwarding_write_bgra_with_timeout` bounds mutex acquisition. `AcquireSync` can block the CPU. macOS writers must complete GPU work before submit or discard. Reusing a surface requires both a new acquisition and the write lock on Windows. If GPU access release fails, close the connection without reusing the surface.
54
+
55
+ Frame IDs must be integers from 1 through 9007199254740991 and unique among outstanding submissions. `dsh_frame_forwarding_submit` returns 1 when submitted and 0 on failure. A failed submission leaves a valid acquisition with the caller for retry or discard under the same GPU completion requirements.
56
+
57
+ Windows Vulkan and D3D12 consumers borrow the NT handle through `dsh_frame_forwarding_surface_shared_handle` while the surface is acquired. They must use the SDK's GPU adapter and enable keyed-mutex synchronization in their import API, following the ownership rules above. The SDK owns the handle; callers must not close it. The function returns null on macOS. Receiver copies acquire the source mutex with a bounded timeout when the actual texture descriptor declares one; legacy textures retain the completed-write requirement.
58
+
59
+ Application JSON, frame correlation, input semantics, viewport generations and input acknowledgements are defined by the consuming application protocol. Control messages are limited to 16383 UTF-8 bytes. The SDK does not expose arbitrary process launching or native handles to webpages. The SDK has no LibreOffice runtime dependency; applications may install Kit with `--omit=optional` when only native rendering is needed.
60
+
61
+ ## Build and validation
62
+
63
+ Run `node scripts/build.mjs` on the target platform with complete matching Node headers available. The SDK version comes from the public Kit package metadata. Set `DSH_NODE_INCLUDE` explicitly when necessary; Windows additionally requires a developer toolchain environment and `DSH_NODE_LIB`. Builds produce precompiled Node-API and static SDK artifacts with SHA-256 receipts. Installation never invokes a compiler. Public Kit packing requires all four supported targets from one source commit. Partial payloads cannot be packed. The verifier checks addon and static-library architectures, artifact hashes, source hashes, versions and protocol before signing. Desktop runtime packaging retains only the selected target’s frame-forwarding prebuilds, along with the package license.
64
+
65
+ Run `pnpm test` in this directory after building. `DSH_FRAME_FORWARDING_PACKAGE_ROOT` selects an installed SDK payload for transport and lifecycle tests; diagnostics may be retained outside the package with `DSH_FRAME_FORWARDING_DIAGNOSTICS`. Fixture setup gives each complete compile/link group 120 seconds within a 180-second setup hook; protocol and runner deadlines are separate. Compiler receipts preserve the resolved executable, arguments, working directory, elapsed time, direct-child outcome and stdout/stderr. Compiler descendant exit is not observed. Parent fixtures prepare GPU inspectors and pass their paths only to owned runners, retaining the temporary files until those runners exit. The native CI lane runs C transport and Node producer integration tests serially before packing, including asynchronous shutdown and Worker termination. Performance and Electron shared-texture import require separate actual GPU validation; a successful native transport test alone does not establish those results.
66
+
67
+ ## Browser and Electron presentation
68
+
69
+ `@deepseek-ai/libreoffice-kit/frame-forwarding/browser` exports `FrameForwardingFrameDisplay`, `createFrameForwardingFramePainter`, and their types. Importing this entry does not load Electron, Office or native addons and allocates no graphics resources. The generic view identifier preserves application-specific string types. Applications own view creation, authorization, producer control and input arbitration.
70
+
71
+ `FrameForwardingFrameDisplay.present()` takes ownership of a frame lease and releases it after painting or rejection. Hidden documents wait for visibility; a generation change or disposal cancels the wait. The owner separately updates producer visibility. Dispose the display before removing its canvas.
72
+
73
+ `@deepseek-ai/libreoffice-kit/frame-forwarding/electron` exports `detectFrameForwardingAdapter` and `sendFrameForwardingFrame` for Electron Main. Adapter detection waits for complete Chromium GPU information and observes its exported Direct3D11 texture within one supplied deadline. Unsupported backends or software compositing return `null` without creating an offscreen window. Cancellation also covers GPU initialization and window construction. After the application validates the recipient and frame metadata, `sendFrameForwardingFrame` owns the delivery credit through submission failure or Electron's final GPU-reference release. Its completion does not imply GPU release. The required failure callback synchronously stops producer I/O before Main releases its import or returns the delivery credit; the submission promise then rejects.
74
+
75
+ `@deepseek-ai/libreoffice-kit/frame-forwarding/electron/preload` exports `createFrameForwardingTextureReceiver` for a sandboxed preload. Bundle this entry with Electron external, and install its single document-wide receiver before starting production. Register at most one listener per view. Unsubscribe and revocation stop future deliveries; consumers retain delivered leases until explicit release. Missing consumers, frame extraction failures and throwing listeners release the imported texture. IPC authorization and application lifecycle remain with the caller.
76
+
77
+ ## Distribution
78
+
79
+ The public Kit package exports the Node SDK, SDK metadata, verifier, browser and Electron entries independently. Resolve the SDK JSON file and read its `header`, `sources`, and `staticLibraries[target]` paths relative to that directory. Normal installation and runtime use the bundled addon without compiling or downloading native binaries.
80
+
81
+ The browser painters/display, Electron adapter probe and generic texture ownership tests originate from DeepSeek Harness commit `21261bee8b9a820c62c9e42cade3ff644b747a29`, under `packages/client/frame-forwarding` and `apps/desktop`. Their unit tests are maintained with these implementations; DSH retains application integration tests.
82
+
83
+ The MIT SDK originated in DeepSeek Harness commit `4438b67c13d529c9882d89893ed5cd610ace11cc`. Its WebGPU adapter retains the Office fixes from LibreOffice Kit commit `2ae2de8c7e88df00e74ee538ebd5662f47c7a1df`. The Node binding and standalone C SDK share the source tree used by the Kit engine build. Protocol version 1 and engine ABI versions 1 and 2 are unchanged.
@@ -0,0 +1,83 @@
1
+ # 帧转发 SDK
2
+
3
+ [English](README.md) | 中文
4
+
5
+ `@deepseek-ai/libreoffice-kit/frame-forwarding` 将经过授权的原生生产者连接到 Electron Main,像素不经过 DSH Host。这个公开子路径提供 Node/TypeScript 生产者与接收者,以及不依赖 Electron 的 C/C++ SDK。包内明确列出可供编译的源码;macOS 使用 IOSurface 与 Mach 端口传递,Windows 使用 D3D11 共享 NT 句柄和仅拥有者可访问的命名管道。独立 browser 与 Electron 子路径提供呈现和纹理所有权管理;消费方负责鉴权和应用控制协议。
6
+
7
+ 使用 `--omit=optional` 安装 Kit 可仅使用 SDK,不安装 Office 引擎或 Windows Office 管道依赖 Koffi。普通安装保留这些可选依赖的选择规则。SDK 安装和通信均不编译或下载二进制。
8
+
9
+ ## 接收端
10
+
11
+ 每个窗口创建一个 `createBudget(maxBytes)`,传给窗口内所有 `createReceiver({ maxFrames, maxBytes, budget, displayAdapter, readbackTimeoutMs, framePolicy }, onEvent)`。通过应用已有生命周期启动生产者,仅调用一次 `bindProducer(pid)` 绑定其 PID,并直接向生产者提供私有 `endpoint`。端点包含认证凭据,不得进入 Renderer 或日志。
12
+
13
+ 帧事件通过 `transport: "shared-texture"` 携带八字节原生句柄、生产者的 `frameId` 和接收端持有的 `deliveryId`。仅在 Electron 发出 `allReferencesReleased` 后调用 `release(deliveryId)`;提交队列和帧超时不解除消费者的所有权。生产者复用已释放的帧 ID 时,交付 ID 仍然不同。重复释放返回 false。`close()` 异步等待已提交 GPU 工作完成并回收所属线程;已交付资源保留至显式释放或接收端销毁。GPU 停滞可能使关闭持续等待;取消操作不会释放该 GPU 仍在使用的资源。
14
+
15
+ Windows shared-texture 接收端要求 `displayAdapter` 提供合成器实际使用的适配器 LUID;缺失时创建失败。生产者在认证时报告设备 LUID,接收端逐帧验证纹理的实际适配器。同卡时,带 keyed mutex 的生产者纹理直接导入;旧纹理复制到接收端持有的共享目标。`sourceKeyedMutex` 报告实际源纹理描述符,与握手声明无关。跨卡时,原生工作线程读回整张源纹理,将其预乘 BGRA 像素上传到合成器所用适配器上的共享纹理。JavaScript 仅接收句柄。`adapterId` 标识源卡;`presentationAdapterId` 标识导出纹理所属适配器,macOS IOSurface 的该值为 null。
16
+
17
+ 接收端在 Windows 上通过 Chromium 可识别的 keyed mutex 协调目标纹理的 GPU 访问;Electron 的引用释放回调控制生命周期,不能代替这项同步。跨卡复制遵循行跨度,GPU 读回复制完成后立即归还源信用;独立目标仍保持占用,直到 Electron 释放其交付。同卡复制和 macOS IOSurface 的源信用仍随交付释放。GPU 完成通知在设备支持时复用 fence 事件,否则使用有界 query 轮询。`readbackTimeoutMs` 限制原生帧准备与交付的时间;超时或取消会停止新工作,同时保留已提交复制的资源,直到 GPU 完成或设备移除。Worker 终止和接收端垃圾回收使用相同的异步清理。
18
+
19
+ [Chromium 152 使用 `INFINITE` 获取 key 0](https://github.com/chromium/chromium/blob/24072c1aa400ec4a89dc738b6b6acd12a8589b6f/gpu/command_buffer/service/dxgi_shared_handle_manager.cc#L129)。直接交付前,接收端工作线程有界获取并释放锁,检查源纹理是否就绪。这将可能的 CPU 等待移至该线程,不复制像素,也无法限制 Chromium 自身的等待。生产者必须在提交前释放锁,且在信用归还前不得访问表面。在检查后违反规则的生产者仍可能阻塞 Chromium 或触发 GPU 看门狗。
20
+
21
+ shared-texture 的 `framePolicy` 默认为 `ordered`,保留 Office 瓦片等独立请求与响应帧。连续流可以选择 `latest`:完成的中转读回替换尚未开始上传的帧,最多保留一帧等待和一帧上传。两个暂存槽允许源复制与等待目标的准备帧并存。目标被持有时停止后续上传;有序交付在两个暂存槽均占用时也停止读回。
22
+
23
+ 字节预算为每个 macOS 分配或声明 keyed mutex 的 Windows 同卡分配预留一份表面。旧同卡分配预留源和目标各一份。可选 hello 能力声明允许较小的预留;声明 keyed mutex 却提供无锁纹理的生产者会被拒绝。未声明但带锁的源纹理也可直接导入,预算仍按旧路径保守预留。中转最多预留 `N = maxFrames` 张源纹理、`N` 张独立目标及两张暂存纹理。目标和暂存容量按当前连接申请过的最大帧计算;源及池扩容通过一次原子预算授予。中转将每帧限制为 `maxBytes / (2N + 2)` 字节,向生产者声明其 `N` 倍的额度。三帧、256 MiB 配置下,三张 4K BGRA 源与五张接收端纹理合计预留 253.125 MiB。闲置存储保留预算;关闭释放独立池槽,仍被持有的各目标仅保留自己的预算直到释放。渲染进程队列和画布存储有独立限制;该预算不是进程内存上限。
24
+
25
+ `send(json)` 将控制消息加入有界队列,不让 Main 阻塞于原生 I/O。生产者消息以 `message` 事件到达。除端点凭据外还验证操作系统提供的对端身份。接收端只接受一个生产者连接且不能重新绑定。发生错误时消费者应终止或替换该连接。交付前丢弃的帧释放其原生资源;已交付帧在连接关闭后仍需显式释放。
26
+
27
+ ## Node/TypeScript 生产者
28
+
29
+ 在所属 Node 进程中,从 `@deepseek-ai/libreoffice-kit/frame-forwarding` 导入 `createProducer`。将接收端绑定至该 Node 进程的 PID;进程内插件使用 `process.pid`。传入私有端点、`maxPendingOperations`、`operationTimeoutMs` 及可选原生引擎描述符。等待 `ready`,并在所属插件的销毁流程中注册显式 `close()`。[TypeScript API](index.d.ts) 定义操作和资源所有权。
30
+
31
+ 专用原生工作线程串行执行连接、上传、引擎回调、锁等待及提交。独立轮询线程收到信用和控制事件后唤醒它;表面获取不使用定时器轮询。就绪前可以将操作入队;超出额度的普通操作被拒绝,包括控制消息。每个持有的租约均预留一个 discard 队列位置,因此队列满时仍可归还表面。等待额度的获取操作不会阻塞工作线程执行。获取超时仅拒绝该请求,不关闭生产者。传输故障或无法确认 GPU 完成的错误会关闭连接。`closed` 在排队操作全部完成,且工作线程、客户端和引擎销毁后解决。事件监听器异常被隔离;监听器自行负责诊断。Worker 终止通过异步原生清理处理。 设置 `DSH_FRAME_FORWARDING_DIAGNOSTICS=1` 可将已隔离的生产者回调异常报告到 stderr。
32
+
33
+ `acquire(width, height)` 返回显式表面租约。等待 `writeBgra(buffer, stride)` 或 `render()`,再调用 `submit(frameId, metadata)` 或 `discard()`;表面的 `close()` 等同于 discard。忙碌或已消费的表面拒绝复用。垃圾回收不会归还帧额度。提交消耗租约,但底层纹理仍须等待接收端释放该帧后才可复用。
34
+
35
+ CPU 上传借用非共享的 Node Buffer,直到返回的 promise 完成。在此期间,调用者不得修改 Buffer、分离其底层 ArrayBuffer 或转移所有权。行跨度可以大于紧密排列的行宽。绑定层持有 Buffer,省去绑定层的中间复制;C SDK 仍需复制或上传像素。CPU 上传不属于 GPU 零拷贝。
36
+
37
+ 持续 GPU 渲染需要提供由另一 Node addon 通过 [dsh_frame_forwarding_node.h](include/dsh_frame_forwarding_node.h) 导出的引擎。[引擎回调](include/dsh_frame_forwarding_engine.h) 在生产者工作线程上串行运行,描述符保留至引擎销毁。`render` 借用已获取的原生纹理,并在返回前释放导入对象。Windows 回调在所提供设备的即时上下文上排队命令,由 SDK 持有 key 0;回调不得重复获取该锁。macOS 回调在返回前完成 GPU 工作。两者都须遵守取消回调。第三方回调必须及时返回;SDK 无法抢占任意引擎代码。引擎创建、更新和销毁不得调用 JavaScript。
38
+
39
+ `start({ width, height, generation, frameIntervalMs })` 在原生代码中持续渲染;`update(json, inputSequence)` 批量更新引擎状态,`stop()` 停止新帧。帧间隔包含渲染耗时,支持 `1000 / 60` 等小数;已过的截止时刻会被跳过,不会突发补帧。启动前必须释放手动租约。帧元数据包含请求 ID、视口代次、修订号和最新应用的输入序列。
40
+
41
+ 引擎 ABI v2 在获取表面前增加 `prepare`:有变化返回 1,无变化返回 0,失败返回 -1。无变化的帧不获取、不提交,也不消耗信用。已声明的变化在等待信用期间保持待处理;准备工作继续按流的节奏执行,新更新也可以替换信用到达后要绘制的状态。启动和调整尺寸强制生成一帧,更新会让下一次变化检查立即具备执行条件。ABI v1 保持持续渲染;Node 手动调用方通过不获取、不提交来跳过一帧。手动 `surface.render()` 不调用 `prepare`。
42
+
43
+ 同卡时,显示可以沿用 C 生产者的原生路径,不逐帧执行 JavaScript 或像素读回。端到端性能仍取决于引擎工作量、回调、节奏、GPU 选择及 CPU 复制。实际显示帧间隔、跳过的修订、输入到观测帧延迟和内存需分别测量;到达吞吐不等于显示 FPS。两种语言使用相同的接收端自动传输策略。
44
+
45
+ ## C/C++ 生产者
46
+
47
+ 包含 `include/dsh_frame_forwarding.h` 并链接对应的 `libdsh_frame_forwarding_sdk.a` 或 `dsh_frame_forwarding_sdk.lib`,也可以构建 `sdk.json` 列出的源码。API 不依赖 Node 或 Electron。仅一个线程执行轮询;获取、写入、提交和归还表面可以在另一线程执行。调用者必须串行使用同一图形上下文。先中断轮询并等待该线程退出,所有 API 调用返回后再关闭客户端。
48
+
49
+ 在 Windows 上,`dsh_frame_forwarding_connect_with_device` 接受应用的 `ID3D11Device`,并保留引用至关闭。传入空值或使用 `dsh_frame_forwarding_connect` 会创建默认设备。`dsh_frame_forwarding_connect_with_options` 还限制连接及握手时长,并接受在连接线程执行的取消回调。应用自行选择 GPU,DSH 选择传输方式。使用被接管设备的即时上下文时须与 SDK 写入串行执行。macOS 要求传入空设备。
50
+
51
+ 首次获取表面时返回空值,等待接收端授予分配额度。轮询后在所属应用适合的时机重试,不得忙等。分配请求进入共享 FIFO 预算队列。额度同时覆盖闲置池和显示中的帧。其他获取空值表示额度不足;终止性分配错误由轮询返回 `kind = -1` 和说明文本。轮询返回负数时停止处理,并在关闭前保留诊断信息。消费者必须限制操作总时长,超时后断开连接。
52
+
53
+ 纹理采用左上原点、sRGB、BGRA8 预乘像素。Windows 表面带有使用 key 0 的 keyed mutex。获取租约不加锁:SDK CPU 上传和引擎回调持有写锁;外部 GPU 写入方通过 `dsh_frame_forwarding_surface_keyed_mutex` 或导入 API 自行持锁。写入方将命令排队后释放 key 0,并在提交或归还前释放导入对象和视图。CPU 上传在返回前复制输入,不等待 GPU 完成;`dsh_frame_forwarding_write_bgra_with_timeout` 限制锁获取时间。`AcquireSync` 可能阻塞 CPU。macOS 写入方必须在提交或归还前完成 GPU 工作。复用表面需要重新获取租约,Windows 上还必须取得写锁。GPU 访问释放失败时,应关闭连接,不得复用表面。
54
+
55
+ 帧 ID 必须是 1 到 9007199254740991 之间的整数,且在尚未释放的提交中唯一。`dsh_frame_forwarding_submit` 提交成功返回 1,失败返回 0。提交失败后,有效的获取仍归调用方所有,可在满足相同 GPU 完成要求后重试或归还。
56
+
57
+ Windows Vulkan 和 D3D12 消费者在表面获取期间,通过 `dsh_frame_forwarding_surface_shared_handle` 借用 NT 句柄。消费者必须使用 SDK 所在的 GPU 适配器,并在导入 API 中启用 keyed mutex 同步,遵守上述所有权规则。句柄归 SDK 所有,调用方不得关闭。macOS 上该函数返回空值。接收端复制会在实际纹理描述符声明 keyed mutex 时有界获取源锁;旧纹理仍要求写入已经完成。
58
+
59
+ 应用 JSON、帧关联、输入语义、视口代次及输入确认由消费者协议定义。控制消息上限为 16383 个 UTF-8 字节。SDK 不向网页暴露任意进程启动或原生句柄。
60
+
61
+ ## 构建与验证
62
+
63
+ 在目标平台运行 `node scripts/build.mjs`,并提供完整且匹配的 Node 头文件。SDK 版本读取公开 Kit 包元数据。需要时显式设置 `DSH_NODE_INCLUDE`;Windows 还需要开发者工具链环境和 `DSH_NODE_LIB`。构建产出预编译 Node-API 插件、静态 SDK 及 SHA-256 回执。正常安装不调用编译器。公开 Kit 打包必须包含同一源码提交的四个平台,不能打包局部产物。校验同时检查插件和静态库架构、二进制和源码哈希、版本及协议。Desktop 运行时仅保留目标平台插件和必要元数据、许可证。
64
+
65
+ 构建后在本目录运行 `pnpm test`。测试沿用串行范围,覆盖 C 传输、Node 生产者、异步关闭及 Worker 终止。`DSH_FRAME_FORWARDING_PACKAGE_ROOT` 可选择已安装 SDK,`DSH_FRAME_FORWARDING_DIAGNOSTICS` 可将失败诊断保留到包外目录。性能及 Electron 共享纹理导入仍需实际 GPU 验证。
66
+
67
+ ## 浏览器与 Electron 呈现
68
+
69
+ `@deepseek-ai/libreoffice-kit/frame-forwarding/browser` 导出 `FrameForwardingFrameDisplay`、`createFrameForwardingFramePainter` 及其类型。导入此入口不会加载 Electron、Office 或原生 addon,也不会分配图形资源。泛型视图标识保留应用定义的字符串类型。应用负责视图创建、鉴权、生产者控制和输入仲裁。
70
+
71
+ `FrameForwardingFrameDisplay.present()` 接管帧租约,在绘制或拒绝后释放。隐藏文档等待恢复可见;代次变化或销毁会取消等待。所属应用另行更新生产者的可见性。移除画布前先销毁 display。
72
+
73
+ `@deepseek-ai/libreoffice-kit/frame-forwarding/electron` 为 Electron Main 导出 `detectFrameForwardingAdapter` 和 `sendFrameForwardingFrame`。适配器探测在同一指定期限内等待 Chromium 完整 GPU 信息,并观察其导出的 Direct3D11 纹理。不支持的后端或软件合成模式会返回 `null`,不创建离屏窗口。取消操作同时覆盖 GPU 初始化和窗口构造。应用验证接收方和帧元数据后,`sendFrameForwardingFrame` 接管交付信用,直至提交失败或 Electron 释放最后一个 GPU 引用。其完成不代表 GPU 已释放。必需的失败回调在 Main 释放导入引用或归还交付信用前同步停止生产者 I/O;随后提交 Promise 拒绝。
74
+
75
+ `@deepseek-ai/libreoffice-kit/frame-forwarding/electron/preload` 为沙箱 preload 导出 `createFrameForwardingTextureReceiver`。打包此入口时将 Electron 保持为外部依赖,并在启动生产前安装文档唯一的接收器。每个视图最多注册一个监听器。取消订阅和撤销只停止未来交付;消费者显式释放前仍持有已交付租约。无消费者、提取帧失败或监听器抛错均会释放导入纹理。调用方负责 IPC 鉴权和应用生命周期。
76
+
77
+ ## 分发
78
+
79
+ 公开 Kit 包独立提供 Node SDK、SDK 元数据、校验器、browser 和 Electron 入口。以 SDK JSON 所在目录为根解析 `header`、`sources` 和 `staticLibraries[target]`。原生渲染无需 LibreOffice 引擎,只使用此功能时可用 `--omit=optional` 安装 Kit。正常安装和运行使用包内插件,不编译或下载额外原生二进制。
80
+
81
+ 浏览器绘制器、display、Electron 适配器探测及通用纹理所有权测试源自 DeepSeek Harness 提交 `21261bee8b9a820c62c9e42cade3ff644b747a29` 的 `packages/client/frame-forwarding` 与 `apps/desktop`。单元测试随实现维护;DSH 保留产品集成测试。
82
+
83
+ MIT SDK 来自 DeepSeek Harness 提交 `4438b67c13d529c9882d89893ed5cd610ace11cc`,WebGPU 适配器保留 LibreOffice Kit 提交 `2ae2de8c7e88df00e74ee538ebd5662f47c7a1df` 的 Office 修复。Node 绑定、独立 C SDK 与 Kit 引擎使用同一源码目录。协议版本 1 及引擎 ABI 版本 1、2 保持不变。