@binblink/wasmnest-plugin-sdk-desktop 0.0.0-stage → 0.0.2

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 (271) hide show
  1. package/README.md +307 -2
  2. package/README_en.md +284 -0
  3. package/bin/cli.js +602 -0
  4. package/bin/manifest-gen.js +458 -0
  5. package/bin/manifest-validate.js +494 -0
  6. package/bin/permission-vocabulary.json +5 -0
  7. package/bin/plugin-watch.js +331 -0
  8. package/bin/wasm-hash.js +124 -0
  9. package/dev-shell/README.md +122 -0
  10. package/dev-shell/index.html +12 -0
  11. package/dev-shell/package.json +28 -0
  12. package/dev-shell/pnpm-workspace.yaml +9 -0
  13. package/dev-shell/postcss.config.js +6 -0
  14. package/dev-shell/src/App.vue +90 -0
  15. package/dev-shell/src/components/LogPanel.vue +90 -0
  16. package/dev-shell/src/loader.ts +104 -0
  17. package/dev-shell/src/locale.ts +29 -0
  18. package/dev-shell/src/locales.ts +50 -0
  19. package/dev-shell/src/main.ts +46 -0
  20. package/dev-shell/src/mock/app-env.ts +102 -0
  21. package/dev-shell/src/mock/commands.ts +54 -0
  22. package/dev-shell/src/mock/domain-context.ts +46 -0
  23. package/dev-shell/src/mock/events.ts +16 -0
  24. package/dev-shell/src/mock/file-transfer.ts +512 -0
  25. package/dev-shell/src/mock/tauri-ipc.ts +109 -0
  26. package/dev-shell/src/registry.ts +90 -0
  27. package/dev-shell/src/shell/components/AppMountSlot.vue +241 -0
  28. package/dev-shell/src/shell/components/ShellIcon.vue +141 -0
  29. package/dev-shell/src/shell/components/ShellStatusBar.vue +87 -0
  30. package/dev-shell/src/shell/components/ShellToolbar.vue +287 -0
  31. package/dev-shell/src/shell/mount/appSession.ts +45 -0
  32. package/dev-shell/src/shell/mount/devAppMount.ts +80 -0
  33. package/dev-shell/src/shell/types.ts +121 -0
  34. package/dev-shell/src/styles/dev.css +27 -0
  35. package/dev-shell/src/styles/shell.css +752 -0
  36. package/dev-shell/src/styles/style.css +1178 -0
  37. package/dev-shell/src/theme.ts +140 -0
  38. package/dev-shell/src/vite-env.d.ts +24 -0
  39. package/dev-shell/tailwind.config.js +98 -0
  40. package/dev-shell/vite.config.ts +174 -0
  41. package/dist/index.d.ts +150 -0
  42. package/dist/index.js +238 -0
  43. package/dist/types.d.ts +632 -0
  44. package/dist/types.js +0 -0
  45. package/dist/vite-plugin.d.ts +25 -0
  46. package/dist/vite-plugin.js +80 -0
  47. package/go/.gitignore +5 -0
  48. package/go/README.md +80 -0
  49. package/go/gen/wasmnest/api-call/host-api-call/empty.s +3 -0
  50. package/go/gen/wasmnest/api-call/host-api-call/host-api-call.wasm.go +13 -0
  51. package/go/gen/wasmnest/api-call/host-api-call/host-api-call.wit.go +34 -0
  52. package/go/gen/wasmnest/app/host-app/empty.s +3 -0
  53. package/go/gen/wasmnest/app/host-app/host-app.wasm.go +29 -0
  54. package/go/gen/wasmnest/app/host-app/host-app.wit.go +108 -0
  55. package/go/gen/wasmnest/auth-center/host-auth-center/abi.go +14 -0
  56. package/go/gen/wasmnest/auth-center/host-auth-center/empty.s +3 -0
  57. package/go/gen/wasmnest/auth-center/host-auth-center/host-auth-center.wasm.go +49 -0
  58. package/go/gen/wasmnest/auth-center/host-auth-center/host-auth-center.wit.go +225 -0
  59. package/go/gen/wasmnest/clipboard/host-clipboard/abi.go +14 -0
  60. package/go/gen/wasmnest/clipboard/host-clipboard/empty.s +3 -0
  61. package/go/gen/wasmnest/clipboard/host-clipboard/host-clipboard.wasm.go +17 -0
  62. package/go/gen/wasmnest/clipboard/host-clipboard/host-clipboard.wit.go +68 -0
  63. package/go/gen/wasmnest/connection-registry/host-connection-registry/empty.s +3 -0
  64. package/go/gen/wasmnest/connection-registry/host-connection-registry/host-connection-registry.wasm.go +13 -0
  65. package/go/gen/wasmnest/connection-registry/host-connection-registry/host-connection-registry.wit.go +50 -0
  66. package/go/gen/wasmnest/crypto/host-crypto/abi.go +18 -0
  67. package/go/gen/wasmnest/crypto/host-crypto/empty.s +3 -0
  68. package/go/gen/wasmnest/crypto/host-crypto/host-crypto.wasm.go +37 -0
  69. package/go/gen/wasmnest/crypto/host-crypto/host-crypto.wit.go +139 -0
  70. package/go/gen/wasmnest/fs-desktop/host-fs-desktop/abi.go +14 -0
  71. package/go/gen/wasmnest/fs-desktop/host-fs-desktop/empty.s +3 -0
  72. package/go/gen/wasmnest/fs-desktop/host-fs-desktop/host-fs-desktop.wasm.go +21 -0
  73. package/go/gen/wasmnest/fs-desktop/host-fs-desktop/host-fs-desktop.wit.go +62 -0
  74. package/go/gen/wasmnest/http/host-http/abi.go +14 -0
  75. package/go/gen/wasmnest/http/host-http/empty.s +3 -0
  76. package/go/gen/wasmnest/http/host-http/host-http.wasm.go +13 -0
  77. package/go/gen/wasmnest/http/host-http/host-http.wit.go +40 -0
  78. package/go/gen/wasmnest/http-endpoint/host-http-endpoint/empty.s +3 -0
  79. package/go/gen/wasmnest/http-endpoint/host-http-endpoint/host-http-endpoint.wasm.go +17 -0
  80. package/go/gen/wasmnest/http-endpoint/host-http-endpoint/host-http-endpoint.wit.go +69 -0
  81. package/go/gen/wasmnest/mdns/host-mdns/empty.s +3 -0
  82. package/go/gen/wasmnest/mdns/host-mdns/host-mdns.wasm.go +29 -0
  83. package/go/gen/wasmnest/mdns/host-mdns/host-mdns.wit.go +101 -0
  84. package/go/gen/wasmnest/notify/host-notify/empty.s +3 -0
  85. package/go/gen/wasmnest/notify/host-notify/host-notify.wasm.go +13 -0
  86. package/go/gen/wasmnest/notify/host-notify/host-notify.wit.go +64 -0
  87. package/go/gen/wasmnest/peer/host-peer/abi.go +14 -0
  88. package/go/gen/wasmnest/peer/host-peer/empty.s +3 -0
  89. package/go/gen/wasmnest/peer/host-peer/host-peer.wasm.go +85 -0
  90. package/go/gen/wasmnest/peer/host-peer/host-peer.wit.go +357 -0
  91. package/go/gen/wasmnest/platform-desktop/host-platform-desktop/empty.s +3 -0
  92. package/go/gen/wasmnest/platform-desktop/host-platform-desktop/host-platform-desktop.wasm.go +21 -0
  93. package/go/gen/wasmnest/platform-desktop/host-platform-desktop/host-platform-desktop.wit.go +70 -0
  94. package/go/gen/wasmnest/plugin/abi-form/abi-form.exports.go +11 -0
  95. package/go/gen/wasmnest/plugin/abi-form/abi-form.wasm.go +13 -0
  96. package/go/gen/wasmnest/plugin/abi-form/abi-form.wit.go +7 -0
  97. package/go/gen/wasmnest/plugin/abi-form/empty.s +3 -0
  98. package/go/gen/wasmnest/plugin/command/command.exports.go +11 -0
  99. package/go/gen/wasmnest/plugin/command/command.wasm.go +19 -0
  100. package/go/gen/wasmnest/plugin/command/command.wit.go +6 -0
  101. package/go/gen/wasmnest/plugin/command/empty.s +3 -0
  102. package/go/gen/wasmnest/plugin/events/empty.s +3 -0
  103. package/go/gen/wasmnest/plugin/events/events.exports.go +52 -0
  104. package/go/gen/wasmnest/plugin/events/events.wasm.go +74 -0
  105. package/go/gen/wasmnest/plugin/events/events.wit.go +195 -0
  106. package/go/gen/wasmnest/plugin/host-bus/empty.s +3 -0
  107. package/go/gen/wasmnest/plugin/host-bus/host-bus.wasm.go +29 -0
  108. package/go/gen/wasmnest/plugin/host-bus/host-bus.wit.go +94 -0
  109. package/go/gen/wasmnest/plugin/host-config/abi.go +14 -0
  110. package/go/gen/wasmnest/plugin/host-config/empty.s +3 -0
  111. package/go/gen/wasmnest/plugin/host-config/host-config.wasm.go +13 -0
  112. package/go/gen/wasmnest/plugin/host-config/host-config.wit.go +21 -0
  113. package/go/gen/wasmnest/plugin/host-events/empty.s +3 -0
  114. package/go/gen/wasmnest/plugin/host-events/host-events.wasm.go +9 -0
  115. package/go/gen/wasmnest/plugin/host-events/host-events.wit.go +27 -0
  116. package/go/gen/wasmnest/plugin/host-fs/abi.go +14 -0
  117. package/go/gen/wasmnest/plugin/host-fs/empty.s +3 -0
  118. package/go/gen/wasmnest/plugin/host-fs/host-fs.wasm.go +33 -0
  119. package/go/gen/wasmnest/plugin/host-fs/host-fs.wit.go +86 -0
  120. package/go/gen/wasmnest/plugin/host-log/empty.s +3 -0
  121. package/go/gen/wasmnest/plugin/host-log/host-log.wasm.go +25 -0
  122. package/go/gen/wasmnest/plugin/host-log/host-log.wit.go +65 -0
  123. package/go/gen/wasmnest/plugin/host-metrics/empty.s +3 -0
  124. package/go/gen/wasmnest/plugin/host-metrics/host-metrics.wasm.go +13 -0
  125. package/go/gen/wasmnest/plugin/host-metrics/host-metrics.wit.go +34 -0
  126. package/go/gen/wasmnest/plugin/host-platform/empty.s +3 -0
  127. package/go/gen/wasmnest/plugin/host-platform/host-platform.wasm.go +21 -0
  128. package/go/gen/wasmnest/plugin/host-platform/host-platform.wit.go +85 -0
  129. package/go/gen/wasmnest/plugin/host-plugin-database/abi.go +14 -0
  130. package/go/gen/wasmnest/plugin/host-plugin-database/empty.s +3 -0
  131. package/go/gen/wasmnest/plugin/host-plugin-database/host-plugin-database.wasm.go +29 -0
  132. package/go/gen/wasmnest/plugin/host-plugin-database/host-plugin-database.wit.go +70 -0
  133. package/go/gen/wasmnest/plugin/host-storage/abi.go +14 -0
  134. package/go/gen/wasmnest/plugin/host-storage/empty.s +3 -0
  135. package/go/gen/wasmnest/plugin/host-storage/host-storage.wasm.go +21 -0
  136. package/go/gen/wasmnest/plugin/host-storage/host-storage.wit.go +44 -0
  137. package/go/gen/wasmnest/plugin/host-worker/empty.s +3 -0
  138. package/go/gen/wasmnest/plugin/host-worker/host-worker.wasm.go +17 -0
  139. package/go/gen/wasmnest/plugin/host-worker/host-worker.wit.go +50 -0
  140. package/go/gen/wasmnest/plugin/lifecycle/empty.s +3 -0
  141. package/go/gen/wasmnest/plugin/lifecycle/lifecycle.exports.go +32 -0
  142. package/go/gen/wasmnest/plugin/lifecycle/lifecycle.wasm.go +41 -0
  143. package/go/gen/wasmnest/plugin/lifecycle/lifecycle.wit.go +9 -0
  144. package/go/gen/wasmnest/plugin/manifest/empty.s +3 -0
  145. package/go/gen/wasmnest/plugin/manifest/manifest.exports.go +11 -0
  146. package/go/gen/wasmnest/plugin/manifest/manifest.wasm.go +13 -0
  147. package/go/gen/wasmnest/plugin/manifest/manifest.wit.go +6 -0
  148. package/go/gen/wasmnest/plugin/plugin/plugin.wit.go +4 -0
  149. package/go/gen/wasmnest/process/host-process/empty.s +3 -0
  150. package/go/gen/wasmnest/process/host-process/host-process.wasm.go +21 -0
  151. package/go/gen/wasmnest/process/host-process/host-process.wit.go +56 -0
  152. package/go/gen/wasmnest/pty/host-pty/abi.go +14 -0
  153. package/go/gen/wasmnest/pty/host-pty/empty.s +3 -0
  154. package/go/gen/wasmnest/pty/host-pty/host-pty.wasm.go +33 -0
  155. package/go/gen/wasmnest/pty/host-pty/host-pty.wit.go +164 -0
  156. package/go/gen/wasmnest/task/host-task/abi.go +14 -0
  157. package/go/gen/wasmnest/task/host-task/empty.s +3 -0
  158. package/go/gen/wasmnest/task/host-task/host-task.wasm.go +29 -0
  159. package/go/gen/wasmnest/task/host-task/host-task.wit.go +110 -0
  160. package/go/gen/wasmnest/timer/host-timer/empty.s +3 -0
  161. package/go/gen/wasmnest/timer/host-timer/host-timer.wasm.go +13 -0
  162. package/go/gen/wasmnest/timer/host-timer/host-timer.wit.go +25 -0
  163. package/go/gen/wasmnest/ws/host-websocket/empty.s +3 -0
  164. package/go/gen/wasmnest/ws/host-websocket/host-websocket.wasm.go +29 -0
  165. package/go/gen/wasmnest/ws/host-websocket/host-websocket.wit.go +109 -0
  166. package/go/gen/wasmnest/ws-server/host-websocket-server/empty.s +3 -0
  167. package/go/gen/wasmnest/ws-server/host-websocket-server/host-websocket-server.wasm.go +49 -0
  168. package/go/gen/wasmnest/ws-server/host-websocket-server/host-websocket-server.wit.go +220 -0
  169. package/go/go.mod +14 -0
  170. package/go/go.sum +2 -0
  171. package/go/sdk/dispatch.go +49 -0
  172. package/go/sdk/dispatch_test.go +81 -0
  173. package/go/sdk/entry_native.go +13 -0
  174. package/go/sdk/entry_wasip2.go +188 -0
  175. package/go/sdk/host_http_wasip2.go +42 -0
  176. package/go/sdk/host_wasip2.go +251 -0
  177. package/go/sdk/plugin.go +103 -0
  178. package/go/testplugin/index.js +1 -0
  179. package/go/testplugin/main.go +67 -0
  180. package/go/testplugin/plugin.json +24 -0
  181. package/go/tools/assemble-wit.mjs +152 -0
  182. package/go/tools/gen-bindings.mjs +51 -0
  183. package/go/wit/core.wit +273 -0
  184. package/go/wit/deps/api-call/cap-api-call.wit +20 -0
  185. package/go/wit/deps/app/cap-app.wit +54 -0
  186. package/go/wit/deps/auth-center/cap-auth-center.wit +124 -0
  187. package/go/wit/deps/clipboard/clipboard.wit +48 -0
  188. package/go/wit/deps/clocks/monotonic-clock.wit +45 -0
  189. package/go/wit/deps/clocks/wall-clock.wit +42 -0
  190. package/go/wit/deps/clocks/world.wit +6 -0
  191. package/go/wit/deps/connection-registry/cap-connection-registry.wit +40 -0
  192. package/go/wit/deps/crypto/cap-crypto.wit +68 -0
  193. package/go/wit/deps/filesystem/preopens.wit +8 -0
  194. package/go/wit/deps/filesystem/types.wit +634 -0
  195. package/go/wit/deps/filesystem/world.wit +6 -0
  196. package/go/wit/deps/fs-desktop/cap-fs-desktop.wit +29 -0
  197. package/go/wit/deps/http/http.wit +28 -0
  198. package/go/wit/deps/http-endpoint/cap-http.wit +44 -0
  199. package/go/wit/deps/io/error.wit +34 -0
  200. package/go/wit/deps/io/poll.wit +41 -0
  201. package/go/wit/deps/io/streams.wit +262 -0
  202. package/go/wit/deps/io/world.wit +6 -0
  203. package/go/wit/deps/mdns/mdns.wit +45 -0
  204. package/go/wit/deps/notify/notify.wit +51 -0
  205. package/go/wit/deps/peer/peer.wit +126 -0
  206. package/go/wit/deps/platform-desktop/cap-platform-desktop.wit +38 -0
  207. package/go/wit/deps/process/cap-process.wit +25 -0
  208. package/go/wit/deps/pty/pty.wit +80 -0
  209. package/go/wit/deps/random/insecure-seed.wit +25 -0
  210. package/go/wit/deps/random/insecure.wit +22 -0
  211. package/go/wit/deps/random/random.wit +26 -0
  212. package/go/wit/deps/random/world.wit +7 -0
  213. package/go/wit/deps/sockets/instance-network.wit +9 -0
  214. package/go/wit/deps/sockets/ip-name-lookup.wit +51 -0
  215. package/go/wit/deps/sockets/network.wit +145 -0
  216. package/go/wit/deps/sockets/tcp-create-socket.wit +27 -0
  217. package/go/wit/deps/sockets/tcp.wit +353 -0
  218. package/go/wit/deps/sockets/udp-create-socket.wit +27 -0
  219. package/go/wit/deps/sockets/udp.wit +266 -0
  220. package/go/wit/deps/sockets/world.wit +11 -0
  221. package/go/wit/deps/task/cap-task.wit +56 -0
  222. package/go/wit/deps/timer/cap-timer.wit +14 -0
  223. package/go/wit/deps/wasi-cli/command.wit +7 -0
  224. package/go/wit/deps/wasi-cli/environment.wit +18 -0
  225. package/go/wit/deps/wasi-cli/exit.wit +4 -0
  226. package/go/wit/deps/wasi-cli/imports.wit +20 -0
  227. package/go/wit/deps/wasi-cli/run.wit +4 -0
  228. package/go/wit/deps/wasi-cli/stdio.wit +17 -0
  229. package/go/wit/deps/wasi-cli/terminal.wit +49 -0
  230. package/go/wit/deps/ws/ws.wit +50 -0
  231. package/go/wit/deps/ws-server/cap-ws.wit +99 -0
  232. package/go/wit/go-plugin.wit +28 -0
  233. package/go/wit/plugin-face.wit +355 -0
  234. package/go/wit/wasmnest.wit +25 -0
  235. package/package.json +100 -3
  236. package/src/config.ts +49 -0
  237. package/src/global-dialog.ts +169 -0
  238. package/src/index.ts +88 -0
  239. package/src/runtime.ts +54 -0
  240. package/src/types.ts +681 -0
  241. package/src/ui/AppUpdateSection.d.ts +44 -0
  242. package/src/ui/AppUpdateSection.vue +253 -0
  243. package/src/ui/MarkdownEditor.vue +520 -0
  244. package/src/ui/NumberField.d.ts +49 -0
  245. package/src/ui/NumberField.vue +390 -0
  246. package/src/ui/PluginGlobalDialog.vue +401 -0
  247. package/src/ui/Select.d.ts +36 -0
  248. package/src/ui/Select.vue +220 -0
  249. package/src/ui/TerminalInputRail.vue +184 -0
  250. package/src/ui/apply-select-position.ts +65 -0
  251. package/src/ui/markdown-editor-syntax.ts +234 -0
  252. package/src/ui/markdown-editor.d.ts +36 -0
  253. package/src/ui/plugin-global-dialog.d.ts +12 -0
  254. package/src/ui/select-position.ts +79 -0
  255. package/src/ui/terminal-input-rail.d.ts +30 -0
  256. package/src/ui/zoom-compensation.d.ts +9 -0
  257. package/src/ui/zoom-compensation.ts +52 -0
  258. package/src/update.ts +123 -0
  259. package/src/vite-plugin.ts +124 -0
  260. package/template/README.md +39 -0
  261. package/template/package.json +23 -0
  262. package/template/plugin.json +14 -0
  263. package/template/rust/Cargo.toml +21 -0
  264. package/template/rust/src/lib.rs +39 -0
  265. package/template/src/env.d.ts +24 -0
  266. package/template/src/index.ts +37 -0
  267. package/template/tsconfig.json +17 -0
  268. package/template/vite.config.ts +21 -0
  269. package/tools/componentize/Cargo.lock +299 -0
  270. package/tools/componentize/Cargo.toml +18 -0
  271. package/tools/componentize/src/main.rs +197 -0
@@ -0,0 +1,28 @@
1
+ package wasmnest:http@0.0.1;
2
+ // ======================================================================
3
+ // HTTP 能力域自持契约分片(ADR 0052 D2/D3)
4
+ //
5
+ // 本文件是 `wasmnest-server-http` 持有的**共享契约真源**(world `cap-http`
6
+ // 只 import 出站域 `host-http`):双端 `compose.json` 的 caps.http 直接指向
7
+ // 本文件(pty 先例)——契约与实现同属一处。
8
+ //
9
+ // 服务端域 `host-http-endpoint`(桌面扩展)**不在本文件**:声明真源在桌面
10
+ // `plugin-sdk-desktop/rust/wit-src/cap-http.wit`(world `cap-http-endpoint`),
11
+ // 实现随端扩展归桌面宿主(ADR 0052 D4)。
12
+ //
13
+ // 端生成物由 `scripts/compose-wit.mjs` 拼装(本文件与 core.wit 及其余 cap 分片
14
+ // 同 package 同版本)。分片只换绑定源、不换装配语义:`impl Host` / `HostModule` /
15
+ // `MODULE_*` / `DESC` 与 WIT 契约的函数集逐字一致。
16
+ // ======================================================================
17
+
18
+ /// HTTP 出站代理(原 http.rs:http_fetch,双端交集 1 函数)
19
+ ///
20
+ /// 桌面独有服务端域(入站路由注册,v29)拆入 [`host-http-endpoint`]
21
+ /// (cap-http 分片,移动端不承载服务端网关、不跟演);本接口只剩双端交集
22
+ /// 出站 `fetch`。
23
+ interface host-http {
24
+ fetch: func(request-json: string) -> result<option<string>, string>;
25
+ }
26
+ world cap-http {
27
+ import host-http;
28
+ }
@@ -0,0 +1,44 @@
1
+ package wasmnest:http-endpoint@0.0.1;
2
+ // ======================================================================
3
+ // HTTP 服务端域(桌面扩展分片,自 `host-http` 拆出)
4
+ //
5
+ // 双端功能区分的归属(ADR 0052 D3/D4):出站 `host-http`(1 函数)是双端功能级
6
+ // 交集,契约与实现都归能力域 crate `wasmnest-server-http`(真源
7
+ // `packages/wasmnest-server-http/wit/http.wit`,world `cap-http`);本 interface
8
+ // 只剩桌面独有服务端域(入站路由注册 2 函数,v29 HTTP 路由代码注册下沉专项)。
9
+ // 移动端是自持业务 App,不承载服务端网关与插件入站路由(ADR 0018),不跟演
10
+ // (ADR 0019 双端偏离)。
11
+ //
12
+ // 属主隔离:**全部函数仅属主可调**;注册表按调用方插件
13
+ // 注入 `plugin_id`(插件不能注册他人名下路由);插件停用时宿主自动清空其全部注册
14
+ // 路由(同 host-websocket `purge_for_plugin` 先例)。
15
+ //
16
+ // 权限:`network:http`(与前端面 `http.registerEndpoint` 同权限位)。
17
+ //
18
+ // 桌面端 cap 真源:`compose.json` caps.http-endpoint 指向本文件,
19
+ // 由 `scripts/compose-wit.mjs` 复制为生成物 `rust/wit/cap-http-endpoint.wit`。
20
+ interface host-http-endpoint {
21
+ /// 在宿主 HTTP 服务器注册插件端点。config-json(camelCase):
22
+ /// `{ path, host?, methods?, auth? }`
23
+ /// - `path`:插件内相对端点段,宿主拼出内部可达路径 `/api/plugin/<plugin-id>/<path>`
24
+ /// (命名空间段由宿主注入,插件只提供后缀);
25
+ /// - `host`:可选对外 URL 别名(如 `/api/configs`;支持 `{id}` 模板段如
26
+ /// `/api/sessions/{id}/stop`——模板捕获值经 `_http_endpoint` 的 `params` 字段
27
+ /// 传给插件,宿主不拿捕获值构造路径);
28
+ /// - `methods`:host 别名的允许方法(缺省 `["GET"]`);
29
+ /// - `auth` = "jwt"(缺省,最严:要求宿主已验签)| "none"(免凭证转发)。
30
+ ///
31
+ /// 链路加密策略**按应用**决定(应用设置页 → `link_crypto::set_app_policy`),
32
+ /// 覆盖该应用全部 HTTP / WS 端点;本注册配置不携带 `encryption` 字段
33
+ /// (未知字段 → `Err`,严格解析,绝不静默忽略)。
34
+ ///
35
+ /// 冲突仲裁(fail-visible):同一 `host+method` 已被其他插件注册 → `Err`(不覆盖
36
+ /// 在位者);本插件内部 path 重复注册 → `Err`。成功 → 返回端点句柄 `http-<uuid>`。
37
+ register-endpoint: func(config-json: string) -> result<string, string>;
38
+ /// 注销本插件注册的端点(未知句柄 → `Ok(false)`,他人句柄 → `Err` 属主仲裁);
39
+ /// 宿主侧插件停用回收同样会清空其全部注册路由(幂等)。
40
+ unregister-endpoint: func(endpoint-id: string) -> result<bool, string>;
41
+ }
42
+ world cap-http-endpoint {
43
+ import host-http-endpoint;
44
+ }
@@ -0,0 +1,34 @@
1
+ package wasi:io@0.2.0;
2
+
3
+
4
+ interface error {
5
+ /// A resource which represents some error information.
6
+ ///
7
+ /// The only method provided by this resource is `to-debug-string`,
8
+ /// which provides some human-readable information about the error.
9
+ ///
10
+ /// In the `wasi:io` package, this resource is returned through the
11
+ /// `wasi:io/streams/stream-error` type.
12
+ ///
13
+ /// To provide more specific error information, other interfaces may
14
+ /// provide functions to further "downcast" this error into more specific
15
+ /// error information. For example, `error`s returned in streams derived
16
+ /// from filesystem types to be described using the filesystem's own
17
+ /// error-code type, using the function
18
+ /// `wasi:filesystem/types/filesystem-error-code`, which takes a parameter
19
+ /// `borrow<error>` and returns
20
+ /// `option<wasi:filesystem/types/error-code>`.
21
+ ///
22
+ /// The set of functions which can "downcast" an `error` into a more
23
+ /// concrete type is open.
24
+ resource error {
25
+ /// Returns a string that is suitable to assist humans in debugging
26
+ /// this error.
27
+ ///
28
+ /// WARNING: The returned string should not be consumed mechanically!
29
+ /// It may change across platforms, hosts, or other implementation
30
+ /// details. Parsing this string is a major platform-compatibility
31
+ /// hazard.
32
+ to-debug-string: func() -> string;
33
+ }
34
+ }
@@ -0,0 +1,41 @@
1
+ package wasi:io@0.2.0;
2
+
3
+ /// A poll API intended to let users wait for I/O events on multiple handles
4
+ /// at once.
5
+ interface poll {
6
+ /// `pollable` represents a single I/O event which may be ready, or not.
7
+ resource pollable {
8
+
9
+ /// Return the readiness of a pollable. This function never blocks.
10
+ ///
11
+ /// Returns `true` when the pollable is ready, and `false` otherwise.
12
+ ready: func() -> bool;
13
+
14
+ /// `block` returns immediately if the pollable is ready, and otherwise
15
+ /// blocks until ready.
16
+ ///
17
+ /// This function is equivalent to calling `poll.poll` on a list
18
+ /// containing only this pollable.
19
+ block: func();
20
+ }
21
+
22
+ /// Poll for completion on a set of pollables.
23
+ ///
24
+ /// This function takes a list of pollables, which identify I/O sources of
25
+ /// interest, and waits until one or more of the events is ready for I/O.
26
+ ///
27
+ /// The result `list<u32>` contains one or more indices of handles in the
28
+ /// argument list that is ready for I/O.
29
+ ///
30
+ /// If the list contains more elements than can be indexed with a `u32`
31
+ /// value, this function traps.
32
+ ///
33
+ /// A timeout can be implemented by adding a pollable from the
34
+ /// wasi-clocks API to the list.
35
+ ///
36
+ /// This function does not return a `result`; polling in itself does not
37
+ /// do any I/O so it doesn't fail. If any of the I/O sources identified by
38
+ /// the pollables has an error, it is indicated by marking the source as
39
+ /// being reaedy for I/O.
40
+ poll: func(in: list<borrow<pollable>>) -> list<u32>;
41
+ }
@@ -0,0 +1,262 @@
1
+ package wasi:io@0.2.0;
2
+
3
+ /// WASI I/O is an I/O abstraction API which is currently focused on providing
4
+ /// stream types.
5
+ ///
6
+ /// In the future, the component model is expected to add built-in stream types;
7
+ /// when it does, they are expected to subsume this API.
8
+ interface streams {
9
+ use error.{error};
10
+ use poll.{pollable};
11
+
12
+ /// An error for input-stream and output-stream operations.
13
+ variant stream-error {
14
+ /// The last operation (a write or flush) failed before completion.
15
+ ///
16
+ /// More information is available in the `error` payload.
17
+ last-operation-failed(error),
18
+ /// The stream is closed: no more input will be accepted by the
19
+ /// stream. A closed output-stream will return this error on all
20
+ /// future operations.
21
+ closed
22
+ }
23
+
24
+ /// An input bytestream.
25
+ ///
26
+ /// `input-stream`s are *non-blocking* to the extent practical on underlying
27
+ /// platforms. I/O operations always return promptly; if fewer bytes are
28
+ /// promptly available than requested, they return the number of bytes promptly
29
+ /// available, which could even be zero. To wait for data to be available,
30
+ /// use the `subscribe` function to obtain a `pollable` which can be polled
31
+ /// for using `wasi:io/poll`.
32
+ resource input-stream {
33
+ /// Perform a non-blocking read from the stream.
34
+ ///
35
+ /// When the source of a `read` is binary data, the bytes from the source
36
+ /// are returned verbatim. When the source of a `read` is known to the
37
+ /// implementation to be text, bytes containing the UTF-8 encoding of the
38
+ /// text are returned.
39
+ ///
40
+ /// This function returns a list of bytes containing the read data,
41
+ /// when successful. The returned list will contain up to `len` bytes;
42
+ /// it may return fewer than requested, but not more. The list is
43
+ /// empty when no bytes are available for reading at this time. The
44
+ /// pollable given by `subscribe` will be ready when more bytes are
45
+ /// available.
46
+ ///
47
+ /// This function fails with a `stream-error` when the operation
48
+ /// encounters an error, giving `last-operation-failed`, or when the
49
+ /// stream is closed, giving `closed`.
50
+ ///
51
+ /// When the caller gives a `len` of 0, it represents a request to
52
+ /// read 0 bytes. If the stream is still open, this call should
53
+ /// succeed and return an empty list, or otherwise fail with `closed`.
54
+ ///
55
+ /// The `len` parameter is a `u64`, which could represent a list of u8 which
56
+ /// is not possible to allocate in wasm32, or not desirable to allocate as
57
+ /// as a return value by the callee. The callee may return a list of bytes
58
+ /// less than `len` in size while more bytes are available for reading.
59
+ read: func(
60
+ /// The maximum number of bytes to read
61
+ len: u64
62
+ ) -> result<list<u8>, stream-error>;
63
+
64
+ /// Read bytes from a stream, after blocking until at least one byte can
65
+ /// be read. Except for blocking, behavior is identical to `read`.
66
+ blocking-read: func(
67
+ /// The maximum number of bytes to read
68
+ len: u64
69
+ ) -> result<list<u8>, stream-error>;
70
+
71
+ /// Skip bytes from a stream. Returns number of bytes skipped.
72
+ ///
73
+ /// Behaves identical to `read`, except instead of returning a list
74
+ /// of bytes, returns the number of bytes consumed from the stream.
75
+ skip: func(
76
+ /// The maximum number of bytes to skip.
77
+ len: u64,
78
+ ) -> result<u64, stream-error>;
79
+
80
+ /// Skip bytes from a stream, after blocking until at least one byte
81
+ /// can be skipped. Except for blocking behavior, identical to `skip`.
82
+ blocking-skip: func(
83
+ /// The maximum number of bytes to skip.
84
+ len: u64,
85
+ ) -> result<u64, stream-error>;
86
+
87
+ /// Create a `pollable` which will resolve once either the specified stream
88
+ /// has bytes available to read or the other end of the stream has been
89
+ /// closed.
90
+ /// The created `pollable` is a child resource of the `input-stream`.
91
+ /// Implementations may trap if the `input-stream` is dropped before
92
+ /// all derived `pollable`s created with this function are dropped.
93
+ subscribe: func() -> pollable;
94
+ }
95
+
96
+
97
+ /// An output bytestream.
98
+ ///
99
+ /// `output-stream`s are *non-blocking* to the extent practical on
100
+ /// underlying platforms. Except where specified otherwise, I/O operations also
101
+ /// always return promptly, after the number of bytes that can be written
102
+ /// promptly, which could even be zero. To wait for the stream to be ready to
103
+ /// accept data, the `subscribe` function to obtain a `pollable` which can be
104
+ /// polled for using `wasi:io/poll`.
105
+ resource output-stream {
106
+ /// Check readiness for writing. This function never blocks.
107
+ ///
108
+ /// Returns the number of bytes permitted for the next call to `write`,
109
+ /// or an error. Calling `write` with more bytes than this function has
110
+ /// permitted will trap.
111
+ ///
112
+ /// When this function returns 0 bytes, the `subscribe` pollable will
113
+ /// become ready when this function will report at least 1 byte, or an
114
+ /// error.
115
+ check-write: func() -> result<u64, stream-error>;
116
+
117
+ /// Perform a write. This function never blocks.
118
+ ///
119
+ /// When the destination of a `write` is binary data, the bytes from
120
+ /// `contents` are written verbatim. When the destination of a `write` is
121
+ /// known to the implementation to be text, the bytes of `contents` are
122
+ /// transcoded from UTF-8 into the encoding of the destination and then
123
+ /// written.
124
+ ///
125
+ /// Precondition: check-write gave permit of Ok(n) and contents has a
126
+ /// length of less than or equal to n. Otherwise, this function will trap.
127
+ ///
128
+ /// returns Err(closed) without writing if the stream has closed since
129
+ /// the last call to check-write provided a permit.
130
+ write: func(
131
+ contents: list<u8>
132
+ ) -> result<_, stream-error>;
133
+
134
+ /// Perform a write of up to 4096 bytes, and then flush the stream. Block
135
+ /// until all of these operations are complete, or an error occurs.
136
+ ///
137
+ /// This is a convenience wrapper around the use of `check-write`,
138
+ /// `subscribe`, `write`, and `flush`, and is implemented with the
139
+ /// following pseudo-code:
140
+ ///
141
+ /// ```text
142
+ /// let pollable = this.subscribe();
143
+ /// while !contents.is_empty() {
144
+ /// // Wait for the stream to become writable
145
+ /// pollable.block();
146
+ /// let Ok(n) = this.check-write(); // eliding error handling
147
+ /// let len = min(n, contents.len());
148
+ /// let (chunk, rest) = contents.split_at(len);
149
+ /// this.write(chunk ); // eliding error handling
150
+ /// contents = rest;
151
+ /// }
152
+ /// this.flush();
153
+ /// // Wait for completion of `flush`
154
+ /// pollable.block();
155
+ /// // Check for any errors that arose during `flush`
156
+ /// let _ = this.check-write(); // eliding error handling
157
+ /// ```
158
+ blocking-write-and-flush: func(
159
+ contents: list<u8>
160
+ ) -> result<_, stream-error>;
161
+
162
+ /// Request to flush buffered output. This function never blocks.
163
+ ///
164
+ /// This tells the output-stream that the caller intends any buffered
165
+ /// output to be flushed. the output which is expected to be flushed
166
+ /// is all that has been passed to `write` prior to this call.
167
+ ///
168
+ /// Upon calling this function, the `output-stream` will not accept any
169
+ /// writes (`check-write` will return `ok(0)`) until the flush has
170
+ /// completed. The `subscribe` pollable will become ready when the
171
+ /// flush has completed and the stream can accept more writes.
172
+ flush: func() -> result<_, stream-error>;
173
+
174
+ /// Request to flush buffered output, and block until flush completes
175
+ /// and stream is ready for writing again.
176
+ blocking-flush: func() -> result<_, stream-error>;
177
+
178
+ /// Create a `pollable` which will resolve once the output-stream
179
+ /// is ready for more writing, or an error has occured. When this
180
+ /// pollable is ready, `check-write` will return `ok(n)` with n>0, or an
181
+ /// error.
182
+ ///
183
+ /// If the stream is closed, this pollable is always ready immediately.
184
+ ///
185
+ /// The created `pollable` is a child resource of the `output-stream`.
186
+ /// Implementations may trap if the `output-stream` is dropped before
187
+ /// all derived `pollable`s created with this function are dropped.
188
+ subscribe: func() -> pollable;
189
+
190
+ /// Write zeroes to a stream.
191
+ ///
192
+ /// This should be used precisely like `write` with the exact same
193
+ /// preconditions (must use check-write first), but instead of
194
+ /// passing a list of bytes, you simply pass the number of zero-bytes
195
+ /// that should be written.
196
+ write-zeroes: func(
197
+ /// The number of zero-bytes to write
198
+ len: u64
199
+ ) -> result<_, stream-error>;
200
+
201
+ /// Perform a write of up to 4096 zeroes, and then flush the stream.
202
+ /// Block until all of these operations are complete, or an error
203
+ /// occurs.
204
+ ///
205
+ /// This is a convenience wrapper around the use of `check-write`,
206
+ /// `subscribe`, `write-zeroes`, and `flush`, and is implemented with
207
+ /// the following pseudo-code:
208
+ ///
209
+ /// ```text
210
+ /// let pollable = this.subscribe();
211
+ /// while num_zeroes != 0 {
212
+ /// // Wait for the stream to become writable
213
+ /// pollable.block();
214
+ /// let Ok(n) = this.check-write(); // eliding error handling
215
+ /// let len = min(n, num_zeroes);
216
+ /// this.write-zeroes(len); // eliding error handling
217
+ /// num_zeroes -= len;
218
+ /// }
219
+ /// this.flush();
220
+ /// // Wait for completion of `flush`
221
+ /// pollable.block();
222
+ /// // Check for any errors that arose during `flush`
223
+ /// let _ = this.check-write(); // eliding error handling
224
+ /// ```
225
+ blocking-write-zeroes-and-flush: func(
226
+ /// The number of zero-bytes to write
227
+ len: u64
228
+ ) -> result<_, stream-error>;
229
+
230
+ /// Read from one stream and write to another.
231
+ ///
232
+ /// The behavior of splice is equivelant to:
233
+ /// 1. calling `check-write` on the `output-stream`
234
+ /// 2. calling `read` on the `input-stream` with the smaller of the
235
+ /// `check-write` permitted length and the `len` provided to `splice`
236
+ /// 3. calling `write` on the `output-stream` with that read data.
237
+ ///
238
+ /// Any error reported by the call to `check-write`, `read`, or
239
+ /// `write` ends the splice and reports that error.
240
+ ///
241
+ /// This function returns the number of bytes transferred; it may be less
242
+ /// than `len`.
243
+ splice: func(
244
+ /// The stream to read from
245
+ src: borrow<input-stream>,
246
+ /// The number of bytes to splice
247
+ len: u64,
248
+ ) -> result<u64, stream-error>;
249
+
250
+ /// Read from one stream and write to another, with blocking.
251
+ ///
252
+ /// This is similar to `splice`, except that it blocks until the
253
+ /// `output-stream` is ready for writing, and the `input-stream`
254
+ /// is ready for reading, before performing the `splice`.
255
+ blocking-splice: func(
256
+ /// The stream to read from
257
+ src: borrow<input-stream>,
258
+ /// The number of bytes to splice
259
+ len: u64,
260
+ ) -> result<u64, stream-error>;
261
+ }
262
+ }
@@ -0,0 +1,6 @@
1
+ package wasi:io@0.2.0;
2
+
3
+ world imports {
4
+ import streams;
5
+ import poll;
6
+ }
@@ -0,0 +1,45 @@
1
+ package wasmnest:mdns@0.0.1;
2
+ // ======================================================================
3
+ // mDNS 能力域自持契约分片(ADR 0052 D2/D3)
4
+ //
5
+ // 本文件是 `wasmnest-discovery-engine` 持有的**共享契约真源**(world `cap-mdns`
6
+ // 只 import 浏览/广播域 `host-mdns`):双端 `compose.json` 的 caps.mdns 直接指向
7
+ // 本文件(pty 先例)——契约与实现同属一处,端组合不再经 core.wit 间接消费。
8
+ //
9
+ // 端生成物由 `scripts/compose-wit.mjs` 拼装(本文件与 core.wit 及其余 cap 分片
10
+ // 同 package 同版本)。分片只换绑定源、不换装配语义:`impl Host` / `HostModule` /
11
+ // `MODULE_*` / `DESC` 与 WIT 契约的函数集逐字一致。
12
+ // ======================================================================
13
+
14
+ /// mDNS 浏览纯能力(ADR 0022 v2):browse-only,发现/离开事件原样透传
15
+ ///
16
+ /// 发现/离开经消息总线**属主私有 topic** 推送(host-bus 订阅):
17
+ /// `<owner>::mdns:found` / `<owner>::mdns:lost`(构造用 SDK `mdns_event_topic`,
18
+ /// 跨属主订阅被宿主拒绝),
19
+ /// payload 原样透传:`{ instanceName, addresses: string[], port, txtRecords:
20
+ /// Record<string,string> }`,宿主不做任何加工。设备列表(去重/TTL 过期/展示名
21
+ /// 解读)是发现事件的派生视图,由消费插件自建缓存。
22
+ ///
23
+ /// 自我广播(register/advertise)不进本接口:「本机是谁」与宿主 TLS 监听器
24
+ /// 同生共死,留在 peer-net 启动流程自动完成;无插件激活时主机照样可被发现。
25
+ interface host-mdns {
26
+ /// 浏览某服务类型,返回 browser 句柄;重复浏览同一类型允许(各自独立生命周期)。
27
+ /// 事件定向投递到 `<plugin-id>::mdns:found` / `<plugin-id>::mdns:lost`(宿主实现)
28
+ browse: func(service-type: string) -> result<string, string>;
29
+ /// 停止浏览并回收句柄(返回是否存在该句柄);仅属主可停(跨插件拒绝);
30
+ /// 插件停用时宿主自动回收其全部句柄
31
+ stop-browse: func(browser-id: string) -> result<bool, string>;
32
+
33
+ /// 广播某服务类型(v2 新增):返回 advertise 句柄。
34
+ /// config-json 为纯引擎参数(服务类型 / 实例名 / 端口 / TXT 键值),
35
+ /// 宿主零业务拼装;实例名省略时宿主按 `{plugin}-{短指纹}` 默认。
36
+ advertise: func(config-json: string) -> result<string, string>;
37
+ /// 停止广播并回收句柄(返回是否存在该句柄);仅属主可停;
38
+ /// 插件停用时宿主自动回收其全部广播句柄。
39
+ stop-advertise: func(advertise-id: string) -> result<bool, string>;
40
+ /// 查询广播状态(返回是否存在该句柄);仅属主可查。
41
+ is-advertising: func(advertise-id: string) -> result<bool, string>;
42
+ }
43
+ world cap-mdns {
44
+ import host-mdns;
45
+ }
@@ -0,0 +1,51 @@
1
+ package wasmnest:notify@0.0.1;
2
+ // ======================================================================
3
+ // 通知域共享契约(唯一真源;ADR 0052 D2/D3 · domain-owned-contracts 票 04)
4
+ //
5
+ // 本文件是 `host-notify` 的单一事实源:
6
+ // - 双端 `compose.json` 的 caps.notify 直接指向本文件(pty 先例推广);
7
+ // - 有实现两端投递机制不同、且都只有几行宿主代码,故本域没有共享引擎,
8
+ // 按 ADR 0052 D2/D4 用**轻量契约房**(`packages/wasmnest-notify-engine`)承载;
9
+ // 实现按端住宿主(桌面 / 移动各自 `src-tauri/src/plugin/notify.rs`)。
10
+ //
11
+ // ## 功能级口径(票 04 统一)
12
+ //
13
+ // - 原桌面 `host-events-desktop.notify(title, body)` 与原移动
14
+ // `host-notify.notify(title, body, options-json)` 合并为本接口的单一签名;
15
+ // 桌面 `host-events-desktop` 整 interface 退役。
16
+ // - 移动附加的权限查询 / 请求、即时震动、提示音 4 函数不是交集(桌面无
17
+ // 对应平台概念),改名 `host-notify-mobile` 留移动端独立包(`cap-notify-mobile.wit`,ADR 0061)。
18
+ //
19
+ // ## options-json 契约
20
+ //
21
+ // `{ "vibrate"?: bool, "sound"?: bool }`(camelCase;字段可省,缺省均为 `true`,
22
+ // 与移动端 v18 起的既有行为一致)。**严格解析**:非法 JSON / 字段类型错误 →
23
+ // `Err`(禁静默降级成默认值)。
24
+ //
25
+ // **平台不支持的选项静默忽略**(桌面无震动 / 提示音通道;移动全部支持):
26
+ // 报错会让「只想发通知」的桌面调用点无谓失败,而选项是装饰性诉求;
27
+ // 调用方按同一份代码跨端调用,不需要按端裁剪 options。
28
+ //
29
+ // ## 权限(各端自持,契约不规定门)
30
+ //
31
+ // - 桌面:**无权限门**(弹提示是插件常规能力,与退役前 `plugin_notify` /
32
+ // `host-events-desktop.notify` 口径逐字一致);
33
+ // - 移动:`notify`(fail-closed,未声明即拒——通知 / 震动 / 声音是用户打扰面)。
34
+ //
35
+ // 门在各端函数实现内(正确性由 Rust 端仲裁),契约面只描述签名。
36
+ // ======================================================================
37
+
38
+ /// 系统通知(功能级交集;实现按端住宿主)
39
+ interface host-notify {
40
+ /// 发送系统通知(文案由插件 i18n 构建、原样透传,宿主不做文案加工)。
41
+ ///
42
+ /// options-json(camelCase,字段可省):`{ vibrate?: bool, sound?: bool }`,
43
+ /// 缺省均 true;非法 JSON / 字段类型错误 → Err(严格解析)。
44
+ /// 平台不支持的选项**静默忽略**(桌面无震动 / 提示音通道)。
45
+ notify: func(title: string, body: string, options-json: string) -> result<_, string>;
46
+ }
47
+
48
+ /// 通知域端组合 world(双端 compose.json 的 `caps.notify` 指向本文件)
49
+ world cap-notify {
50
+ import host-notify;
51
+ }
@@ -0,0 +1,126 @@
1
+ package wasmnest:peer@0.0.1;
2
+ // ======================================================================
3
+ // 对等网络能力域自持契约分片(ADR 0052 D2/D3)
4
+ //
5
+ // 本文件是 `wasmnest-server-peer-net` 持有的**共享契约真源**(world `cap-peer`
6
+ // 只 import `host-peer`):双端 `compose.json` 的 caps.peer 直接指向本文件
7
+ // (pty 先例)——契约与实现同属一处,端组合不再经 core.wit 间接消费。
8
+ //
9
+ // 端生成物由 `scripts/compose-wit.mjs` 拼装(本文件与 core.wit 及其余 cap 分片
10
+ // 同 package 同版本)。分片只换绑定源、不换装配语义:`impl Host` / `HostModule` /
11
+ // `MODULE_*` / `DESC` 与 WIT 契约的函数集逐字一致。
12
+ // ======================================================================
13
+
14
+ /// 对等网络基础能力:宿主只提供能力原语,
15
+ /// file-transfer 插件是首个上层消费者
16
+ ///
17
+ /// 发现/信任/拨号/收发/浏览的引擎全部在宿主 peer-net 层;本接口只是
18
+ /// 命令面的 WASM 投影。DTO 一律 JSON 字符串承载(camelCase,与 Tauri
19
+ /// 命令返回形状一致)。事件经消息总线 `peer:*` topic 推送(host-bus 订阅):
20
+ /// - `peer:devices` 发现缓存全量列表变化
21
+ /// - `peer:connection` 节点连上/断开
22
+ /// - `peer:consent` 首次连接确认请求
23
+ /// - `peer:transfer-event` / `peer:receive-event` 引擎原始事件流(唯一回流——
24
+ /// 旧快照 topic `peer:transfer` / `peer:receive` 已退役,任务状态真源在
25
+ /// 插件事件归约状态机)
26
+ interface host-peer {
27
+ /// per-app 节点启动配置(`start-node` 参数)
28
+ ///
29
+ /// 每个 app 声明自己的身份与网络参数,宿主按 app 维度隔离节点实例。
30
+ /// `listen-port = 0` 表示由 OS 分配(防火墙友好场景应显式指定固定端口)。
31
+ record peer-node-config {
32
+ /// 节点数据目录(存放 identity keypair、known peers 等持久状态)
33
+ data-dir: string,
34
+ /// 人类可读的设备名(广播给对端发现用)
35
+ device-name: string,
36
+ /// TCP 监听端口(0 = OS 自动分配)
37
+ listen-port: u16,
38
+ }
39
+ /// 按 endpoint 拨号连接(ADR 0022 v2 终态,原 dial-peer-endpoint 转正):
40
+ /// endpoint = `{ nodeId, addr, port }`(camelCase JSON,插件从自身设备缓存/
41
+ /// mdns 事件解析后显式传入;宿主不内藏 node-id → 地址解析表)。握手期
42
+ /// 「证书指纹 ↔ nodeId 绑定 + 信任检查」语义不变。成功返回 session 句柄
43
+ /// (`sess-<uuid>`,后续按句柄寻址);denied/unreachable 以错误上抛
44
+ dial-peer: func(endpoint-json: string) -> result<string, string>;
45
+ /// 统一资源关闭(ADR 0022 v2):session 句柄 = 断开连接;传输句柄 = 取消传输
46
+ /// (先发送批取消、后接收批取消——pending 接收批被关闭即拒绝,闸门 fail-safe
47
+ /// 的自然结果)。返回是否命中并关闭了任意资源
48
+ close: func(handle: string) -> result<bool, string>;
49
+ /// 首次连接确认应答(返回是否命中了待确认项)
50
+ respond-consent: func(request-id: string, accepted: bool) -> result<bool, string>;
51
+ /// 可信对端列表 → TrustedPeerDto JSON 数组
52
+ list-trusted: func() -> result<string, string>;
53
+ /// 撤销对指定节点的信任(返回是否删除了条目)
54
+ revoke-trusted: func(node-id: string) -> result<bool, string>;
55
+ /// 向单个对端发送一批文件(目录递归展开、同名去重由宿主完成;
56
+ /// 扇出 = 对多个对端各调一次,各批相互独立)→ 传输句柄(batch-id 字符串)
57
+ ///
58
+ /// 一次调用 = 一个会话立即发起,无宿主并发闸门排队——发送方向并发节流由
59
+ /// 调用方在调用前自控(插件侧并发闸门)。paths 元素双形态:纯 string 或
60
+ /// `{ path, encrypt? }` 对象(任一元素 encrypt=true → 本批强制加密);
61
+ /// 旧产物载荷携带的 `concurrency` 并发脉冲字段已退役,出现即**显性报错**
62
+ /// (fail-visible:旧产物按当前 SDK 重建)。连接已断时以句柄记忆的
63
+ /// endpoint 自动重拨(信任检查照走引擎握手)
64
+ send-files: func(session-handle: string, paths-json: string) -> result<string, string>;
65
+ /// 接收批应答:accept=false 或超时视为拒绝
66
+ respond-transfer: func(batch-id: string, accept: bool) -> result<_, string>;
67
+ /// 设置接收策略(引擎安全闸门配置原语,ADR 0022 v3):mode = "ask" |
68
+ /// "always_accept" | "always_deny";产品真源在插件侧,经本原语推送宿主闸门
69
+ set-receive-policy: func(mode: string, timeout-secs: u64) -> result<_, string>;
70
+ /// 显式暂停进行中的发送批(batch-id 寻址):会话数据面门控(wire Pause 帧
71
+ /// + 供方停推流,连接保持),任务保留(含已传字节)不落历史;本端发起的
72
+ /// 活跃会话查句柄表、serve 供流批查 handler 注册表。无命中返回错误
73
+ pause-transfer: func(batch-id: string) -> result<_, string>;
74
+ /// 恢复暂停的发送批(batch-id 寻址):活跃会话写 Resume 帧续流;会话已
75
+ /// 中断的以句柄表记忆的源清单重新拨号续传(断点真源在接收端落盘侧)。
76
+ /// 无命中返回错误
77
+ resume-transfer: func(batch-id: string) -> result<_, string>;
78
+ /// 批量恢复暂停的发送批:**本接口不提供**——「全部」编排归插件自己
79
+ /// 完成(遍历暂停批逐个调 [`resume-transfer`],并发节流由插件侧闸门
80
+ /// 自控),宿主句柄表不做批量调度。该批量函数已删除:旧产物 import
81
+ /// 它在实例化期因缺失 interface 显性失败(按当前 SDK 重建)
82
+ /// 全量幂等替换本插件声明的共享根清单(ADR 0022 v2):
83
+ /// 条目 `[{ id, name, path }]`(camelCase JSON;移动端 SAF 树以
84
+ /// `safTreeUri` 字段替代 `path`)。注册表 CRUD 真源在插件侧,本函数
85
+ /// 只同步暴露面镜像;任一条目非法整批拒绝
86
+ set-shared-roots: func(dirs-json: string) -> result<_, string>;
87
+ /// 浏览对端共享根清单 → PeerSharedRootDto JSON 数组(仅 session 句柄寻址;
88
+ /// 连接已断时以句柄记忆的 endpoint 自动重拨)
89
+ list-shared-roots: func(session-handle: string) -> result<string, string>;
90
+ /// 目录下钻 → RemoteBrowseDto JSON(仅 session 句柄寻址;重拨语义同上)
91
+ browse-directory: func(session-handle: string, dir-id: string, rel-path: string) -> result<string, string>;
92
+ /// 拉取对端文件(files = RemotePullFileDto JSON 数组)→ 入队文件数
93
+ /// (仅 session 句柄寻址;重拨语义同上)。逐文件会话立即发起、无宿主
94
+ /// 并发信号量——并发节流由调用方分批调用自控;每个拉取会话发起时经
95
+ /// `peer:receive-event` 直推 `pull-started` 引擎事实事件
96
+ /// (batchId/nodeId/files/totalSize/tsMs),任务行由插件事件归约自建
97
+ pull-files: func(session-handle: string, dir-id: string, files-json: string) -> result<u32, string>;
98
+ /// 设置接收落点目录(空串 = 恢复默认 Downloads\WasmNest\;引擎落盘配置原语,
99
+ /// ADR 0022 v3)
100
+ set-download-dir: func(path: string) -> result<_, string>;
101
+ /// 按需启动本机 peer 节点(引擎级生命周期原语):app 声明自己的身份与
102
+ /// 网络参数(`peer-node-config`),宿主按 app 维度隔离节点实例。
103
+ /// 幂等——该 config 对应的节点已在跑时返回 false(未改变状态)。
104
+ ///
105
+ /// 属主语义:把节点从「未跑」带到「跑」的那次调用,其调用方成为节点属主;
106
+ /// 已被别的插件起着的节点**不可被本调用接管**(报错,且文案不回带他方身份)。
107
+ /// 谁起谁停:内核不再按硬编码插件 id 猜测节点归属
108
+ /// (旧 `peer_net::FILE_TRANSFER_PLUGIN_ID` 与激活外壳随之退役)。
109
+ start-node: func(config: peer-node-config) -> result<bool, string>;
110
+ /// 让本机节点下线(幂等;节点未跑为 no-op):停广播 / 关监听 / 排水连接与
111
+ /// 入站记账。仅节点属主可关停——非属主报错,文案不回带属主身份
112
+ stop-node: func() -> result<bool, string>;
113
+ /// 活跃传输批清单(实现 = 会话句柄表投影,接口形状不变):`[{ batchId, direction, status, totalBytes, transferredBytes,
114
+ /// rateBps, updatedAtMs }]`(camelCase JSON 数组)。仅引擎会话事实——不含
115
+ /// peerName / 文件清单 / 原因码等业务字段(展示名与业务视图由插件自持);
116
+ /// 供插件事件归约状态机首屏重建(激活晚于事件时的兜底查询)
117
+ active-transfers: func() -> result<string, string>;
118
+ /// 收集发送源:paths = string[] JSON,目录递归展开 + 批内同名去重
119
+ /// (「名称 (2).ext」编号——批内 remote 路径唯一性属 wire 协议正确性)
120
+ /// → `[{ path, size }]` JSON(path 为相对落位形状,size 为字节)。
121
+ /// 仅读元数据不读内容;路径应来自 host-platform pick-* 用户选择(选择即授权)
122
+ collect-outgoing: func(paths-json: string) -> result<string, string>;
123
+ }
124
+ world cap-peer {
125
+ import host-peer;
126
+ }