@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.
- package/README.md +307 -2
- package/README_en.md +284 -0
- package/bin/cli.js +602 -0
- package/bin/manifest-gen.js +458 -0
- package/bin/manifest-validate.js +494 -0
- package/bin/permission-vocabulary.json +5 -0
- package/bin/plugin-watch.js +331 -0
- package/bin/wasm-hash.js +124 -0
- package/dev-shell/README.md +122 -0
- package/dev-shell/index.html +12 -0
- package/dev-shell/package.json +28 -0
- package/dev-shell/pnpm-workspace.yaml +9 -0
- package/dev-shell/postcss.config.js +6 -0
- package/dev-shell/src/App.vue +90 -0
- package/dev-shell/src/components/LogPanel.vue +90 -0
- package/dev-shell/src/loader.ts +104 -0
- package/dev-shell/src/locale.ts +29 -0
- package/dev-shell/src/locales.ts +50 -0
- package/dev-shell/src/main.ts +46 -0
- package/dev-shell/src/mock/app-env.ts +102 -0
- package/dev-shell/src/mock/commands.ts +54 -0
- package/dev-shell/src/mock/domain-context.ts +46 -0
- package/dev-shell/src/mock/events.ts +16 -0
- package/dev-shell/src/mock/file-transfer.ts +512 -0
- package/dev-shell/src/mock/tauri-ipc.ts +109 -0
- package/dev-shell/src/registry.ts +90 -0
- package/dev-shell/src/shell/components/AppMountSlot.vue +241 -0
- package/dev-shell/src/shell/components/ShellIcon.vue +141 -0
- package/dev-shell/src/shell/components/ShellStatusBar.vue +87 -0
- package/dev-shell/src/shell/components/ShellToolbar.vue +287 -0
- package/dev-shell/src/shell/mount/appSession.ts +45 -0
- package/dev-shell/src/shell/mount/devAppMount.ts +80 -0
- package/dev-shell/src/shell/types.ts +121 -0
- package/dev-shell/src/styles/dev.css +27 -0
- package/dev-shell/src/styles/shell.css +752 -0
- package/dev-shell/src/styles/style.css +1178 -0
- package/dev-shell/src/theme.ts +140 -0
- package/dev-shell/src/vite-env.d.ts +24 -0
- package/dev-shell/tailwind.config.js +98 -0
- package/dev-shell/vite.config.ts +174 -0
- package/dist/index.d.ts +150 -0
- package/dist/index.js +238 -0
- package/dist/types.d.ts +632 -0
- package/dist/types.js +0 -0
- package/dist/vite-plugin.d.ts +25 -0
- package/dist/vite-plugin.js +80 -0
- package/go/.gitignore +5 -0
- package/go/README.md +80 -0
- package/go/gen/wasmnest/api-call/host-api-call/empty.s +3 -0
- package/go/gen/wasmnest/api-call/host-api-call/host-api-call.wasm.go +13 -0
- package/go/gen/wasmnest/api-call/host-api-call/host-api-call.wit.go +34 -0
- package/go/gen/wasmnest/app/host-app/empty.s +3 -0
- package/go/gen/wasmnest/app/host-app/host-app.wasm.go +29 -0
- package/go/gen/wasmnest/app/host-app/host-app.wit.go +108 -0
- package/go/gen/wasmnest/auth-center/host-auth-center/abi.go +14 -0
- package/go/gen/wasmnest/auth-center/host-auth-center/empty.s +3 -0
- package/go/gen/wasmnest/auth-center/host-auth-center/host-auth-center.wasm.go +49 -0
- package/go/gen/wasmnest/auth-center/host-auth-center/host-auth-center.wit.go +225 -0
- package/go/gen/wasmnest/clipboard/host-clipboard/abi.go +14 -0
- package/go/gen/wasmnest/clipboard/host-clipboard/empty.s +3 -0
- package/go/gen/wasmnest/clipboard/host-clipboard/host-clipboard.wasm.go +17 -0
- package/go/gen/wasmnest/clipboard/host-clipboard/host-clipboard.wit.go +68 -0
- package/go/gen/wasmnest/connection-registry/host-connection-registry/empty.s +3 -0
- package/go/gen/wasmnest/connection-registry/host-connection-registry/host-connection-registry.wasm.go +13 -0
- package/go/gen/wasmnest/connection-registry/host-connection-registry/host-connection-registry.wit.go +50 -0
- package/go/gen/wasmnest/crypto/host-crypto/abi.go +18 -0
- package/go/gen/wasmnest/crypto/host-crypto/empty.s +3 -0
- package/go/gen/wasmnest/crypto/host-crypto/host-crypto.wasm.go +37 -0
- package/go/gen/wasmnest/crypto/host-crypto/host-crypto.wit.go +139 -0
- package/go/gen/wasmnest/fs-desktop/host-fs-desktop/abi.go +14 -0
- package/go/gen/wasmnest/fs-desktop/host-fs-desktop/empty.s +3 -0
- package/go/gen/wasmnest/fs-desktop/host-fs-desktop/host-fs-desktop.wasm.go +21 -0
- package/go/gen/wasmnest/fs-desktop/host-fs-desktop/host-fs-desktop.wit.go +62 -0
- package/go/gen/wasmnest/http/host-http/abi.go +14 -0
- package/go/gen/wasmnest/http/host-http/empty.s +3 -0
- package/go/gen/wasmnest/http/host-http/host-http.wasm.go +13 -0
- package/go/gen/wasmnest/http/host-http/host-http.wit.go +40 -0
- package/go/gen/wasmnest/http-endpoint/host-http-endpoint/empty.s +3 -0
- package/go/gen/wasmnest/http-endpoint/host-http-endpoint/host-http-endpoint.wasm.go +17 -0
- package/go/gen/wasmnest/http-endpoint/host-http-endpoint/host-http-endpoint.wit.go +69 -0
- package/go/gen/wasmnest/mdns/host-mdns/empty.s +3 -0
- package/go/gen/wasmnest/mdns/host-mdns/host-mdns.wasm.go +29 -0
- package/go/gen/wasmnest/mdns/host-mdns/host-mdns.wit.go +101 -0
- package/go/gen/wasmnest/notify/host-notify/empty.s +3 -0
- package/go/gen/wasmnest/notify/host-notify/host-notify.wasm.go +13 -0
- package/go/gen/wasmnest/notify/host-notify/host-notify.wit.go +64 -0
- package/go/gen/wasmnest/peer/host-peer/abi.go +14 -0
- package/go/gen/wasmnest/peer/host-peer/empty.s +3 -0
- package/go/gen/wasmnest/peer/host-peer/host-peer.wasm.go +85 -0
- package/go/gen/wasmnest/peer/host-peer/host-peer.wit.go +357 -0
- package/go/gen/wasmnest/platform-desktop/host-platform-desktop/empty.s +3 -0
- package/go/gen/wasmnest/platform-desktop/host-platform-desktop/host-platform-desktop.wasm.go +21 -0
- package/go/gen/wasmnest/platform-desktop/host-platform-desktop/host-platform-desktop.wit.go +70 -0
- package/go/gen/wasmnest/plugin/abi-form/abi-form.exports.go +11 -0
- package/go/gen/wasmnest/plugin/abi-form/abi-form.wasm.go +13 -0
- package/go/gen/wasmnest/plugin/abi-form/abi-form.wit.go +7 -0
- package/go/gen/wasmnest/plugin/abi-form/empty.s +3 -0
- package/go/gen/wasmnest/plugin/command/command.exports.go +11 -0
- package/go/gen/wasmnest/plugin/command/command.wasm.go +19 -0
- package/go/gen/wasmnest/plugin/command/command.wit.go +6 -0
- package/go/gen/wasmnest/plugin/command/empty.s +3 -0
- package/go/gen/wasmnest/plugin/events/empty.s +3 -0
- package/go/gen/wasmnest/plugin/events/events.exports.go +52 -0
- package/go/gen/wasmnest/plugin/events/events.wasm.go +74 -0
- package/go/gen/wasmnest/plugin/events/events.wit.go +195 -0
- package/go/gen/wasmnest/plugin/host-bus/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-bus/host-bus.wasm.go +29 -0
- package/go/gen/wasmnest/plugin/host-bus/host-bus.wit.go +94 -0
- package/go/gen/wasmnest/plugin/host-config/abi.go +14 -0
- package/go/gen/wasmnest/plugin/host-config/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-config/host-config.wasm.go +13 -0
- package/go/gen/wasmnest/plugin/host-config/host-config.wit.go +21 -0
- package/go/gen/wasmnest/plugin/host-events/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-events/host-events.wasm.go +9 -0
- package/go/gen/wasmnest/plugin/host-events/host-events.wit.go +27 -0
- package/go/gen/wasmnest/plugin/host-fs/abi.go +14 -0
- package/go/gen/wasmnest/plugin/host-fs/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-fs/host-fs.wasm.go +33 -0
- package/go/gen/wasmnest/plugin/host-fs/host-fs.wit.go +86 -0
- package/go/gen/wasmnest/plugin/host-log/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-log/host-log.wasm.go +25 -0
- package/go/gen/wasmnest/plugin/host-log/host-log.wit.go +65 -0
- package/go/gen/wasmnest/plugin/host-metrics/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-metrics/host-metrics.wasm.go +13 -0
- package/go/gen/wasmnest/plugin/host-metrics/host-metrics.wit.go +34 -0
- package/go/gen/wasmnest/plugin/host-platform/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-platform/host-platform.wasm.go +21 -0
- package/go/gen/wasmnest/plugin/host-platform/host-platform.wit.go +85 -0
- package/go/gen/wasmnest/plugin/host-plugin-database/abi.go +14 -0
- package/go/gen/wasmnest/plugin/host-plugin-database/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-plugin-database/host-plugin-database.wasm.go +29 -0
- package/go/gen/wasmnest/plugin/host-plugin-database/host-plugin-database.wit.go +70 -0
- package/go/gen/wasmnest/plugin/host-storage/abi.go +14 -0
- package/go/gen/wasmnest/plugin/host-storage/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-storage/host-storage.wasm.go +21 -0
- package/go/gen/wasmnest/plugin/host-storage/host-storage.wit.go +44 -0
- package/go/gen/wasmnest/plugin/host-worker/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-worker/host-worker.wasm.go +17 -0
- package/go/gen/wasmnest/plugin/host-worker/host-worker.wit.go +50 -0
- package/go/gen/wasmnest/plugin/lifecycle/empty.s +3 -0
- package/go/gen/wasmnest/plugin/lifecycle/lifecycle.exports.go +32 -0
- package/go/gen/wasmnest/plugin/lifecycle/lifecycle.wasm.go +41 -0
- package/go/gen/wasmnest/plugin/lifecycle/lifecycle.wit.go +9 -0
- package/go/gen/wasmnest/plugin/manifest/empty.s +3 -0
- package/go/gen/wasmnest/plugin/manifest/manifest.exports.go +11 -0
- package/go/gen/wasmnest/plugin/manifest/manifest.wasm.go +13 -0
- package/go/gen/wasmnest/plugin/manifest/manifest.wit.go +6 -0
- package/go/gen/wasmnest/plugin/plugin/plugin.wit.go +4 -0
- package/go/gen/wasmnest/process/host-process/empty.s +3 -0
- package/go/gen/wasmnest/process/host-process/host-process.wasm.go +21 -0
- package/go/gen/wasmnest/process/host-process/host-process.wit.go +56 -0
- package/go/gen/wasmnest/pty/host-pty/abi.go +14 -0
- package/go/gen/wasmnest/pty/host-pty/empty.s +3 -0
- package/go/gen/wasmnest/pty/host-pty/host-pty.wasm.go +33 -0
- package/go/gen/wasmnest/pty/host-pty/host-pty.wit.go +164 -0
- package/go/gen/wasmnest/task/host-task/abi.go +14 -0
- package/go/gen/wasmnest/task/host-task/empty.s +3 -0
- package/go/gen/wasmnest/task/host-task/host-task.wasm.go +29 -0
- package/go/gen/wasmnest/task/host-task/host-task.wit.go +110 -0
- package/go/gen/wasmnest/timer/host-timer/empty.s +3 -0
- package/go/gen/wasmnest/timer/host-timer/host-timer.wasm.go +13 -0
- package/go/gen/wasmnest/timer/host-timer/host-timer.wit.go +25 -0
- package/go/gen/wasmnest/ws/host-websocket/empty.s +3 -0
- package/go/gen/wasmnest/ws/host-websocket/host-websocket.wasm.go +29 -0
- package/go/gen/wasmnest/ws/host-websocket/host-websocket.wit.go +109 -0
- package/go/gen/wasmnest/ws-server/host-websocket-server/empty.s +3 -0
- package/go/gen/wasmnest/ws-server/host-websocket-server/host-websocket-server.wasm.go +49 -0
- package/go/gen/wasmnest/ws-server/host-websocket-server/host-websocket-server.wit.go +220 -0
- package/go/go.mod +14 -0
- package/go/go.sum +2 -0
- package/go/sdk/dispatch.go +49 -0
- package/go/sdk/dispatch_test.go +81 -0
- package/go/sdk/entry_native.go +13 -0
- package/go/sdk/entry_wasip2.go +188 -0
- package/go/sdk/host_http_wasip2.go +42 -0
- package/go/sdk/host_wasip2.go +251 -0
- package/go/sdk/plugin.go +103 -0
- package/go/testplugin/index.js +1 -0
- package/go/testplugin/main.go +67 -0
- package/go/testplugin/plugin.json +24 -0
- package/go/tools/assemble-wit.mjs +152 -0
- package/go/tools/gen-bindings.mjs +51 -0
- package/go/wit/core.wit +273 -0
- package/go/wit/deps/api-call/cap-api-call.wit +20 -0
- package/go/wit/deps/app/cap-app.wit +54 -0
- package/go/wit/deps/auth-center/cap-auth-center.wit +124 -0
- package/go/wit/deps/clipboard/clipboard.wit +48 -0
- package/go/wit/deps/clocks/monotonic-clock.wit +45 -0
- package/go/wit/deps/clocks/wall-clock.wit +42 -0
- package/go/wit/deps/clocks/world.wit +6 -0
- package/go/wit/deps/connection-registry/cap-connection-registry.wit +40 -0
- package/go/wit/deps/crypto/cap-crypto.wit +68 -0
- package/go/wit/deps/filesystem/preopens.wit +8 -0
- package/go/wit/deps/filesystem/types.wit +634 -0
- package/go/wit/deps/filesystem/world.wit +6 -0
- package/go/wit/deps/fs-desktop/cap-fs-desktop.wit +29 -0
- package/go/wit/deps/http/http.wit +28 -0
- package/go/wit/deps/http-endpoint/cap-http.wit +44 -0
- package/go/wit/deps/io/error.wit +34 -0
- package/go/wit/deps/io/poll.wit +41 -0
- package/go/wit/deps/io/streams.wit +262 -0
- package/go/wit/deps/io/world.wit +6 -0
- package/go/wit/deps/mdns/mdns.wit +45 -0
- package/go/wit/deps/notify/notify.wit +51 -0
- package/go/wit/deps/peer/peer.wit +126 -0
- package/go/wit/deps/platform-desktop/cap-platform-desktop.wit +38 -0
- package/go/wit/deps/process/cap-process.wit +25 -0
- package/go/wit/deps/pty/pty.wit +80 -0
- package/go/wit/deps/random/insecure-seed.wit +25 -0
- package/go/wit/deps/random/insecure.wit +22 -0
- package/go/wit/deps/random/random.wit +26 -0
- package/go/wit/deps/random/world.wit +7 -0
- package/go/wit/deps/sockets/instance-network.wit +9 -0
- package/go/wit/deps/sockets/ip-name-lookup.wit +51 -0
- package/go/wit/deps/sockets/network.wit +145 -0
- package/go/wit/deps/sockets/tcp-create-socket.wit +27 -0
- package/go/wit/deps/sockets/tcp.wit +353 -0
- package/go/wit/deps/sockets/udp-create-socket.wit +27 -0
- package/go/wit/deps/sockets/udp.wit +266 -0
- package/go/wit/deps/sockets/world.wit +11 -0
- package/go/wit/deps/task/cap-task.wit +56 -0
- package/go/wit/deps/timer/cap-timer.wit +14 -0
- package/go/wit/deps/wasi-cli/command.wit +7 -0
- package/go/wit/deps/wasi-cli/environment.wit +18 -0
- package/go/wit/deps/wasi-cli/exit.wit +4 -0
- package/go/wit/deps/wasi-cli/imports.wit +20 -0
- package/go/wit/deps/wasi-cli/run.wit +4 -0
- package/go/wit/deps/wasi-cli/stdio.wit +17 -0
- package/go/wit/deps/wasi-cli/terminal.wit +49 -0
- package/go/wit/deps/ws/ws.wit +50 -0
- package/go/wit/deps/ws-server/cap-ws.wit +99 -0
- package/go/wit/go-plugin.wit +28 -0
- package/go/wit/plugin-face.wit +355 -0
- package/go/wit/wasmnest.wit +25 -0
- package/package.json +100 -3
- package/src/config.ts +49 -0
- package/src/global-dialog.ts +169 -0
- package/src/index.ts +88 -0
- package/src/runtime.ts +54 -0
- package/src/types.ts +681 -0
- package/src/ui/AppUpdateSection.d.ts +44 -0
- package/src/ui/AppUpdateSection.vue +253 -0
- package/src/ui/MarkdownEditor.vue +520 -0
- package/src/ui/NumberField.d.ts +49 -0
- package/src/ui/NumberField.vue +390 -0
- package/src/ui/PluginGlobalDialog.vue +401 -0
- package/src/ui/Select.d.ts +36 -0
- package/src/ui/Select.vue +220 -0
- package/src/ui/TerminalInputRail.vue +184 -0
- package/src/ui/apply-select-position.ts +65 -0
- package/src/ui/markdown-editor-syntax.ts +234 -0
- package/src/ui/markdown-editor.d.ts +36 -0
- package/src/ui/plugin-global-dialog.d.ts +12 -0
- package/src/ui/select-position.ts +79 -0
- package/src/ui/terminal-input-rail.d.ts +30 -0
- package/src/ui/zoom-compensation.d.ts +9 -0
- package/src/ui/zoom-compensation.ts +52 -0
- package/src/update.ts +123 -0
- package/src/vite-plugin.ts +124 -0
- package/template/README.md +39 -0
- package/template/package.json +23 -0
- package/template/plugin.json +14 -0
- package/template/rust/Cargo.toml +21 -0
- package/template/rust/src/lib.rs +39 -0
- package/template/src/env.d.ts +24 -0
- package/template/src/index.ts +37 -0
- package/template/tsconfig.json +17 -0
- package/template/vite.config.ts +21 -0
- package/tools/componentize/Cargo.lock +299 -0
- package/tools/componentize/Cargo.toml +18 -0
- package/tools/componentize/src/main.rs +197 -0
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
|
|
2
|
+
interface udp {
|
|
3
|
+
use wasi:io/poll@0.2.0.{pollable};
|
|
4
|
+
use network.{network, error-code, ip-socket-address, ip-address-family};
|
|
5
|
+
|
|
6
|
+
/// A received datagram.
|
|
7
|
+
record incoming-datagram {
|
|
8
|
+
/// The payload.
|
|
9
|
+
///
|
|
10
|
+
/// Theoretical max size: ~64 KiB. In practice, typically less than 1500 bytes.
|
|
11
|
+
data: list<u8>,
|
|
12
|
+
|
|
13
|
+
/// The source address.
|
|
14
|
+
///
|
|
15
|
+
/// This field is guaranteed to match the remote address the stream was initialized with, if any.
|
|
16
|
+
///
|
|
17
|
+
/// Equivalent to the `src_addr` out parameter of `recvfrom`.
|
|
18
|
+
remote-address: ip-socket-address,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/// A datagram to be sent out.
|
|
22
|
+
record outgoing-datagram {
|
|
23
|
+
/// The payload.
|
|
24
|
+
data: list<u8>,
|
|
25
|
+
|
|
26
|
+
/// The destination address.
|
|
27
|
+
///
|
|
28
|
+
/// The requirements on this field depend on how the stream was initialized:
|
|
29
|
+
/// - with a remote address: this field must be None or match the stream's remote address exactly.
|
|
30
|
+
/// - without a remote address: this field is required.
|
|
31
|
+
///
|
|
32
|
+
/// If this value is None, the send operation is equivalent to `send` in POSIX. Otherwise it is equivalent to `sendto`.
|
|
33
|
+
remote-address: option<ip-socket-address>,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
/// A UDP socket handle.
|
|
39
|
+
resource udp-socket {
|
|
40
|
+
/// Bind the socket to a specific network on the provided IP address and port.
|
|
41
|
+
///
|
|
42
|
+
/// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the implementation to decide which
|
|
43
|
+
/// network interface(s) to bind to.
|
|
44
|
+
/// If the port is zero, the socket will be bound to a random free port.
|
|
45
|
+
///
|
|
46
|
+
/// # Typical errors
|
|
47
|
+
/// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows)
|
|
48
|
+
/// - `invalid-state`: The socket is already bound. (EINVAL)
|
|
49
|
+
/// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows)
|
|
50
|
+
/// - `address-in-use`: Address is already in use. (EADDRINUSE)
|
|
51
|
+
/// - `address-not-bindable`: `local-address` is not an address that the `network` can bind to. (EADDRNOTAVAIL)
|
|
52
|
+
/// - `not-in-progress`: A `bind` operation is not in progress.
|
|
53
|
+
/// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN)
|
|
54
|
+
///
|
|
55
|
+
/// # Implementors note
|
|
56
|
+
/// Unlike in POSIX, in WASI the bind operation is async. This enables
|
|
57
|
+
/// interactive WASI hosts to inject permission prompts. Runtimes that
|
|
58
|
+
/// don't want to make use of this ability can simply call the native
|
|
59
|
+
/// `bind` as part of either `start-bind` or `finish-bind`.
|
|
60
|
+
///
|
|
61
|
+
/// # References
|
|
62
|
+
/// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html>
|
|
63
|
+
/// - <https://man7.org/linux/man-pages/man2/bind.2.html>
|
|
64
|
+
/// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-bind>
|
|
65
|
+
/// - <https://man.freebsd.org/cgi/man.cgi?query=bind&sektion=2&format=html>
|
|
66
|
+
start-bind: func(network: borrow<network>, local-address: ip-socket-address) -> result<_, error-code>;
|
|
67
|
+
finish-bind: func() -> result<_, error-code>;
|
|
68
|
+
|
|
69
|
+
/// Set up inbound & outbound communication channels, optionally to a specific peer.
|
|
70
|
+
///
|
|
71
|
+
/// This function only changes the local socket configuration and does not generate any network traffic.
|
|
72
|
+
/// On success, the `remote-address` of the socket is updated. The `local-address` may be updated as well,
|
|
73
|
+
/// based on the best network path to `remote-address`.
|
|
74
|
+
///
|
|
75
|
+
/// When a `remote-address` is provided, the returned streams are limited to communicating with that specific peer:
|
|
76
|
+
/// - `send` can only be used to send to this destination.
|
|
77
|
+
/// - `receive` will only return datagrams sent from the provided `remote-address`.
|
|
78
|
+
///
|
|
79
|
+
/// This method may be called multiple times on the same socket to change its association, but
|
|
80
|
+
/// only the most recently returned pair of streams will be operational. Implementations may trap if
|
|
81
|
+
/// the streams returned by a previous invocation haven't been dropped yet before calling `stream` again.
|
|
82
|
+
///
|
|
83
|
+
/// The POSIX equivalent in pseudo-code is:
|
|
84
|
+
/// ```text
|
|
85
|
+
/// if (was previously connected) {
|
|
86
|
+
/// connect(s, AF_UNSPEC)
|
|
87
|
+
/// }
|
|
88
|
+
/// if (remote_address is Some) {
|
|
89
|
+
/// connect(s, remote_address)
|
|
90
|
+
/// }
|
|
91
|
+
/// ```
|
|
92
|
+
///
|
|
93
|
+
/// Unlike in POSIX, the socket must already be explicitly bound.
|
|
94
|
+
///
|
|
95
|
+
/// # Typical errors
|
|
96
|
+
/// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT)
|
|
97
|
+
/// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL)
|
|
98
|
+
/// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL)
|
|
99
|
+
/// - `invalid-state`: The socket is not bound.
|
|
100
|
+
/// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD)
|
|
101
|
+
/// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)
|
|
102
|
+
/// - `connection-refused`: The connection was refused. (ECONNREFUSED)
|
|
103
|
+
///
|
|
104
|
+
/// # References
|
|
105
|
+
/// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html>
|
|
106
|
+
/// - <https://man7.org/linux/man-pages/man2/connect.2.html>
|
|
107
|
+
/// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-connect>
|
|
108
|
+
/// - <https://man.freebsd.org/cgi/man.cgi?connect>
|
|
109
|
+
%stream: func(remote-address: option<ip-socket-address>) -> result<tuple<incoming-datagram-stream, outgoing-datagram-stream>, error-code>;
|
|
110
|
+
|
|
111
|
+
/// Get the current bound address.
|
|
112
|
+
///
|
|
113
|
+
/// POSIX mentions:
|
|
114
|
+
/// > If the socket has not been bound to a local name, the value
|
|
115
|
+
/// > stored in the object pointed to by `address` is unspecified.
|
|
116
|
+
///
|
|
117
|
+
/// WASI is stricter and requires `local-address` to return `invalid-state` when the socket hasn't been bound yet.
|
|
118
|
+
///
|
|
119
|
+
/// # Typical errors
|
|
120
|
+
/// - `invalid-state`: The socket is not bound to any local address.
|
|
121
|
+
///
|
|
122
|
+
/// # References
|
|
123
|
+
/// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockname.html>
|
|
124
|
+
/// - <https://man7.org/linux/man-pages/man2/getsockname.2.html>
|
|
125
|
+
/// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-getsockname>
|
|
126
|
+
/// - <https://man.freebsd.org/cgi/man.cgi?getsockname>
|
|
127
|
+
local-address: func() -> result<ip-socket-address, error-code>;
|
|
128
|
+
|
|
129
|
+
/// Get the address the socket is currently streaming to.
|
|
130
|
+
///
|
|
131
|
+
/// # Typical errors
|
|
132
|
+
/// - `invalid-state`: The socket is not streaming to a specific remote address. (ENOTCONN)
|
|
133
|
+
///
|
|
134
|
+
/// # References
|
|
135
|
+
/// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpeername.html>
|
|
136
|
+
/// - <https://man7.org/linux/man-pages/man2/getpeername.2.html>
|
|
137
|
+
/// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-getpeername>
|
|
138
|
+
/// - <https://man.freebsd.org/cgi/man.cgi?query=getpeername&sektion=2&n=1>
|
|
139
|
+
remote-address: func() -> result<ip-socket-address, error-code>;
|
|
140
|
+
|
|
141
|
+
/// Whether this is a IPv4 or IPv6 socket.
|
|
142
|
+
///
|
|
143
|
+
/// Equivalent to the SO_DOMAIN socket option.
|
|
144
|
+
address-family: func() -> ip-address-family;
|
|
145
|
+
|
|
146
|
+
/// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options.
|
|
147
|
+
///
|
|
148
|
+
/// If the provided value is 0, an `invalid-argument` error is returned.
|
|
149
|
+
///
|
|
150
|
+
/// # Typical errors
|
|
151
|
+
/// - `invalid-argument`: (set) The TTL value must be 1 or higher.
|
|
152
|
+
unicast-hop-limit: func() -> result<u8, error-code>;
|
|
153
|
+
set-unicast-hop-limit: func(value: u8) -> result<_, error-code>;
|
|
154
|
+
|
|
155
|
+
/// The kernel buffer space reserved for sends/receives on this socket.
|
|
156
|
+
///
|
|
157
|
+
/// If the provided value is 0, an `invalid-argument` error is returned.
|
|
158
|
+
/// Any other value will never cause an error, but it might be silently clamped and/or rounded.
|
|
159
|
+
/// I.e. after setting a value, reading the same setting back may return a different value.
|
|
160
|
+
///
|
|
161
|
+
/// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options.
|
|
162
|
+
///
|
|
163
|
+
/// # Typical errors
|
|
164
|
+
/// - `invalid-argument`: (set) The provided value was 0.
|
|
165
|
+
receive-buffer-size: func() -> result<u64, error-code>;
|
|
166
|
+
set-receive-buffer-size: func(value: u64) -> result<_, error-code>;
|
|
167
|
+
send-buffer-size: func() -> result<u64, error-code>;
|
|
168
|
+
set-send-buffer-size: func(value: u64) -> result<_, error-code>;
|
|
169
|
+
|
|
170
|
+
/// Create a `pollable` which will resolve once the socket is ready for I/O.
|
|
171
|
+
///
|
|
172
|
+
/// Note: this function is here for WASI Preview2 only.
|
|
173
|
+
/// It's planned to be removed when `future` is natively supported in Preview3.
|
|
174
|
+
subscribe: func() -> pollable;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
resource incoming-datagram-stream {
|
|
178
|
+
/// Receive messages on the socket.
|
|
179
|
+
///
|
|
180
|
+
/// This function attempts to receive up to `max-results` datagrams on the socket without blocking.
|
|
181
|
+
/// The returned list may contain fewer elements than requested, but never more.
|
|
182
|
+
///
|
|
183
|
+
/// This function returns successfully with an empty list when either:
|
|
184
|
+
/// - `max-results` is 0, or:
|
|
185
|
+
/// - `max-results` is greater than 0, but no results are immediately available.
|
|
186
|
+
/// This function never returns `error(would-block)`.
|
|
187
|
+
///
|
|
188
|
+
/// # Typical errors
|
|
189
|
+
/// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)
|
|
190
|
+
/// - `connection-refused`: The connection was refused. (ECONNREFUSED)
|
|
191
|
+
///
|
|
192
|
+
/// # References
|
|
193
|
+
/// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/recvfrom.html>
|
|
194
|
+
/// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/recvmsg.html>
|
|
195
|
+
/// - <https://man7.org/linux/man-pages/man2/recv.2.html>
|
|
196
|
+
/// - <https://man7.org/linux/man-pages/man2/recvmmsg.2.html>
|
|
197
|
+
/// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-recv>
|
|
198
|
+
/// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-recvfrom>
|
|
199
|
+
/// - <https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/ms741687(v=vs.85)>
|
|
200
|
+
/// - <https://man.freebsd.org/cgi/man.cgi?query=recv&sektion=2>
|
|
201
|
+
receive: func(max-results: u64) -> result<list<incoming-datagram>, error-code>;
|
|
202
|
+
|
|
203
|
+
/// Create a `pollable` which will resolve once the stream is ready to receive again.
|
|
204
|
+
///
|
|
205
|
+
/// Note: this function is here for WASI Preview2 only.
|
|
206
|
+
/// It's planned to be removed when `future` is natively supported in Preview3.
|
|
207
|
+
subscribe: func() -> pollable;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
resource outgoing-datagram-stream {
|
|
211
|
+
/// Check readiness for sending. This function never blocks.
|
|
212
|
+
///
|
|
213
|
+
/// Returns the number of datagrams permitted for the next call to `send`,
|
|
214
|
+
/// or an error. Calling `send` with more datagrams than this function has
|
|
215
|
+
/// permitted will trap.
|
|
216
|
+
///
|
|
217
|
+
/// When this function returns ok(0), the `subscribe` pollable will
|
|
218
|
+
/// become ready when this function will report at least ok(1), or an
|
|
219
|
+
/// error.
|
|
220
|
+
///
|
|
221
|
+
/// Never returns `would-block`.
|
|
222
|
+
check-send: func() -> result<u64, error-code>;
|
|
223
|
+
|
|
224
|
+
/// Send messages on the socket.
|
|
225
|
+
///
|
|
226
|
+
/// This function attempts to send all provided `datagrams` on the socket without blocking and
|
|
227
|
+
/// returns how many messages were actually sent (or queued for sending). This function never
|
|
228
|
+
/// returns `error(would-block)`. If none of the datagrams were able to be sent, `ok(0)` is returned.
|
|
229
|
+
///
|
|
230
|
+
/// This function semantically behaves the same as iterating the `datagrams` list and sequentially
|
|
231
|
+
/// sending each individual datagram until either the end of the list has been reached or the first error occurred.
|
|
232
|
+
/// If at least one datagram has been sent successfully, this function never returns an error.
|
|
233
|
+
///
|
|
234
|
+
/// If the input list is empty, the function returns `ok(0)`.
|
|
235
|
+
///
|
|
236
|
+
/// Each call to `send` must be permitted by a preceding `check-send`. Implementations must trap if
|
|
237
|
+
/// either `check-send` was not called or `datagrams` contains more items than `check-send` permitted.
|
|
238
|
+
///
|
|
239
|
+
/// # Typical errors
|
|
240
|
+
/// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT)
|
|
241
|
+
/// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL)
|
|
242
|
+
/// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL)
|
|
243
|
+
/// - `invalid-argument`: The socket is in "connected" mode and `remote-address` is `some` value that does not match the address passed to `stream`. (EISCONN)
|
|
244
|
+
/// - `invalid-argument`: The socket is not "connected" and no value for `remote-address` was provided. (EDESTADDRREQ)
|
|
245
|
+
/// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)
|
|
246
|
+
/// - `connection-refused`: The connection was refused. (ECONNREFUSED)
|
|
247
|
+
/// - `datagram-too-large`: The datagram is too large. (EMSGSIZE)
|
|
248
|
+
///
|
|
249
|
+
/// # References
|
|
250
|
+
/// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/sendto.html>
|
|
251
|
+
/// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/sendmsg.html>
|
|
252
|
+
/// - <https://man7.org/linux/man-pages/man2/send.2.html>
|
|
253
|
+
/// - <https://man7.org/linux/man-pages/man2/sendmmsg.2.html>
|
|
254
|
+
/// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-send>
|
|
255
|
+
/// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-sendto>
|
|
256
|
+
/// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasendmsg>
|
|
257
|
+
/// - <https://man.freebsd.org/cgi/man.cgi?query=send&sektion=2>
|
|
258
|
+
send: func(datagrams: list<outgoing-datagram>) -> result<u64, error-code>;
|
|
259
|
+
|
|
260
|
+
/// Create a `pollable` which will resolve once the stream is ready to send again.
|
|
261
|
+
///
|
|
262
|
+
/// Note: this function is here for WASI Preview2 only.
|
|
263
|
+
/// It's planned to be removed when `future` is natively supported in Preview3.
|
|
264
|
+
subscribe: func() -> pollable;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
package wasmnest:task@0.0.1;
|
|
2
|
+
|
|
3
|
+
// 桌面端能力域分片(WIT 按包拆分,ADR 0061):一个能力域 = 一个独立包,
|
|
4
|
+
// 版本独立演进——本包 WIT 变更只 bump 本包,不波及未 import 它的应用。
|
|
5
|
+
// 端 `plugin` world 经 `include wasmnest:task/cap-task@0.0.1;` 并入本接口。
|
|
6
|
+
|
|
7
|
+
/// 宿主并发任务域(v20,**desktop 独有,双端偏离**——同 host-pty / host-auth 先例,
|
|
8
|
+
/// ADR 0022「双端偏离」节:桌面独有接口不要求移动端跟演;当前 desktop ABI v31、
|
|
9
|
+
/// mobile 11;移动端要接同类能力时再补该端 interface 并对齐计数)。
|
|
10
|
+
///
|
|
11
|
+
/// 问题域:WASM 插件(wasm32-wasip3 组件)无法创建 OS 线程;其全部宿主调用在
|
|
12
|
+
/// 当前 ABI 下同步阻塞——插件要并发做 50 个 `fs.stat` / 并行跑 3 条 `git diff`,
|
|
13
|
+
/// 只能串行排队,每个调用都占用 Store 执行线程。本接口让插件把「单元操作计划」
|
|
14
|
+
/// 提交给宿主:由宿主专用 OS 线程池真并行执行既有宿主原语(零业务语义,
|
|
15
|
+
/// ADR 0022 裁剪线——宿主不做任何编排解释;fail-collect 不 fail-fast,单元独立
|
|
16
|
+
/// 成败,结果按 units 原顺序返回,`id` 由插件指定用于关联,编排判断归插件)。
|
|
17
|
+
///
|
|
18
|
+
/// 两档 API 共享同一单元模型与执行器:
|
|
19
|
+
/// - `execute-batch`(同步档):扇出 → join → 一次性返回全部单元结果。阻塞 Store
|
|
20
|
+
/// 至全部单元终态(或超时)——同 `run-sync` 的阻塞语义,仅限快操作(数十
|
|
21
|
+
/// 百毫秒级);长任务一律 `submit`。
|
|
22
|
+
/// - `submit`(异步档):登记后立即返回句柄 `task-<uuid>`,宿主线线程池执行,
|
|
23
|
+
/// 进度/终态经可选导出 `events-task#on-task-event` 回调;`cancel` 协作式取消。
|
|
24
|
+
///
|
|
25
|
+
/// 属主隔离:句柄 `task-<uuid>` 仅创建者插件可调(沿 pty- / wsc- 先例);
|
|
26
|
+
/// 插件停用时宿主回收其全部任务(cancel 全部在册任务、清注册表、清回调队列)。
|
|
27
|
+
/// 事件丢失自愈:`status` / `list-jobs` 是权威快照(回调是尽力投递)。
|
|
28
|
+
interface host-task {
|
|
29
|
+
/// 同步批:并发执行 plan 全部单元并 join。
|
|
30
|
+
/// plan-json(camelCase):
|
|
31
|
+
/// `{ units: [{ id, kind, params }], maxConcurrency?, jobTimeoutMs?, progress? }`
|
|
32
|
+
/// - `units[].params` = 对应宿主原语既有请求 JSON **原样内嵌**(如
|
|
33
|
+
/// `process.run-sync` 的 params 就是 run-sync 的 request-json),宿主零新 DTO
|
|
34
|
+
/// 映射,语义单点在既有实现;
|
|
35
|
+
/// - `maxConcurrency` ≤ 全局池线程数,缺省 = 池满即排队;
|
|
36
|
+
/// - `jobTimeoutMs` 缺省取常量;超时 → cancelled + 已完成单元结果保留。
|
|
37
|
+
/// 返回 `{ jobId, results: [{ id, ok, value?|error?, durationMs }], cancelled }`
|
|
38
|
+
/// (camelCase;`value` = 单元原语的原返回 JSON 字符串)。
|
|
39
|
+
/// 阻塞 Store 至全部单元终态(或超时)——同 `run-sync` 的阻塞语义,仅限快操作。
|
|
40
|
+
execute-batch: func(plan-json: string) -> result<string, string>;
|
|
41
|
+
/// 异步任务:登记后立即返回句柄 `task-<uuid>`;进度/终态经 events-task 回调。
|
|
42
|
+
/// plan 同 `execute-batch`,返回 `task-<uuid>` 字符串。
|
|
43
|
+
submit: func(plan-json: string) -> result<string, string>;
|
|
44
|
+
/// 任务状态自愈快照(事件丢失后查询):state / 计数器 / 终态 results(有界保留)。
|
|
45
|
+
/// `Ok(None)` = job-id 不存在或非属主(不存在与无权限对调用方不可区分,防枚举)。
|
|
46
|
+
status: func(job-id: string) -> result<option<string>, string>;
|
|
47
|
+
/// 取消(协作式:正在执行的单元跑完或超时,未开始单元 skipped);幂等,
|
|
48
|
+
/// 返回是否命中(`Ok(false)` = 任务不存在 / 非属主 / 已终态)。
|
|
49
|
+
cancel: func(job-id: string) -> result<bool, string>;
|
|
50
|
+
/// 本插件在册任务清单(自愈快照):`[ { jobId, state, doneUnits?, failedUnits?, createdAt } ]`
|
|
51
|
+
list-jobs: func() -> result<string, string>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
world cap-task {
|
|
55
|
+
import host-task;
|
|
56
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
package wasmnest:timer@0.0.1;
|
|
2
|
+
|
|
3
|
+
// 桌面端能力域分片(WIT 按包拆分,ADR 0061):一个能力域 = 一个独立包,
|
|
4
|
+
// 版本独立演进——本包 WIT 变更只 bump 本包,不波及未 import 它的应用。
|
|
5
|
+
// 端 `plugin` world 经 `include wasmnest:timer/cap-timer@0.0.1;` 并入本接口。
|
|
6
|
+
|
|
7
|
+
/// 宿主周期定时器(原 timer.rs:timer_register,ABI v6)
|
|
8
|
+
interface host-timer {
|
|
9
|
+
register: func(interval-secs: u64, command: string) -> result<_, string>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
world cap-timer {
|
|
13
|
+
import host-timer;
|
|
14
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface environment {
|
|
2
|
+
/// Get the POSIX-style environment variables.
|
|
3
|
+
///
|
|
4
|
+
/// Each environment variable is provided as a pair of string variable names
|
|
5
|
+
/// and string value.
|
|
6
|
+
///
|
|
7
|
+
/// Morally, these are a value import, but until value imports are available
|
|
8
|
+
/// in the component model, this import function should return the same
|
|
9
|
+
/// values each time it is called.
|
|
10
|
+
get-environment: func() -> list<tuple<string, string>>;
|
|
11
|
+
|
|
12
|
+
/// Get the POSIX-style arguments to the program.
|
|
13
|
+
get-arguments: func() -> list<string>;
|
|
14
|
+
|
|
15
|
+
/// Return a path that programs should use as their initial current working
|
|
16
|
+
/// directory, interpreting `.` as shorthand for this.
|
|
17
|
+
initial-cwd: func() -> option<string>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
package wasi:cli@0.2.0;
|
|
2
|
+
|
|
3
|
+
world imports {
|
|
4
|
+
include wasi:clocks/imports@0.2.0;
|
|
5
|
+
include wasi:filesystem/imports@0.2.0;
|
|
6
|
+
include wasi:sockets/imports@0.2.0;
|
|
7
|
+
include wasi:random/imports@0.2.0;
|
|
8
|
+
include wasi:io/imports@0.2.0;
|
|
9
|
+
|
|
10
|
+
import environment;
|
|
11
|
+
import exit;
|
|
12
|
+
import stdin;
|
|
13
|
+
import stdout;
|
|
14
|
+
import stderr;
|
|
15
|
+
import terminal-input;
|
|
16
|
+
import terminal-output;
|
|
17
|
+
import terminal-stdin;
|
|
18
|
+
import terminal-stdout;
|
|
19
|
+
import terminal-stderr;
|
|
20
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
interface stdin {
|
|
2
|
+
use wasi:io/streams@0.2.0.{input-stream};
|
|
3
|
+
|
|
4
|
+
get-stdin: func() -> input-stream;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
interface stdout {
|
|
8
|
+
use wasi:io/streams@0.2.0.{output-stream};
|
|
9
|
+
|
|
10
|
+
get-stdout: func() -> output-stream;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface stderr {
|
|
14
|
+
use wasi:io/streams@0.2.0.{output-stream};
|
|
15
|
+
|
|
16
|
+
get-stderr: func() -> output-stream;
|
|
17
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/// Terminal input.
|
|
2
|
+
///
|
|
3
|
+
/// In the future, this may include functions for disabling echoing,
|
|
4
|
+
/// disabling input buffering so that keyboard events are sent through
|
|
5
|
+
/// immediately, querying supported features, and so on.
|
|
6
|
+
interface terminal-input {
|
|
7
|
+
/// The input side of a terminal.
|
|
8
|
+
resource terminal-input;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/// Terminal output.
|
|
12
|
+
///
|
|
13
|
+
/// In the future, this may include functions for querying the terminal
|
|
14
|
+
/// size, being notified of terminal size changes, querying supported
|
|
15
|
+
/// features, and so on.
|
|
16
|
+
interface terminal-output {
|
|
17
|
+
/// The output side of a terminal.
|
|
18
|
+
resource terminal-output;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/// An interface providing an optional `terminal-input` for stdin as a
|
|
22
|
+
/// link-time authority.
|
|
23
|
+
interface terminal-stdin {
|
|
24
|
+
use terminal-input.{terminal-input};
|
|
25
|
+
|
|
26
|
+
/// If stdin is connected to a terminal, return a `terminal-input` handle
|
|
27
|
+
/// allowing further interaction with it.
|
|
28
|
+
get-terminal-stdin: func() -> option<terminal-input>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/// An interface providing an optional `terminal-output` for stdout as a
|
|
32
|
+
/// link-time authority.
|
|
33
|
+
interface terminal-stdout {
|
|
34
|
+
use terminal-output.{terminal-output};
|
|
35
|
+
|
|
36
|
+
/// If stdout is connected to a terminal, return a `terminal-output` handle
|
|
37
|
+
/// allowing further interaction with it.
|
|
38
|
+
get-terminal-stdout: func() -> option<terminal-output>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/// An interface providing an optional `terminal-output` for stderr as a
|
|
42
|
+
/// link-time authority.
|
|
43
|
+
interface terminal-stderr {
|
|
44
|
+
use terminal-output.{terminal-output};
|
|
45
|
+
|
|
46
|
+
/// If stderr is connected to a terminal, return a `terminal-output` handle
|
|
47
|
+
/// allowing further interaction with it.
|
|
48
|
+
get-terminal-stderr: func() -> option<terminal-output>;
|
|
49
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
package wasmnest:ws@0.0.1;
|
|
2
|
+
// ======================================================================
|
|
3
|
+
// WebSocket 客户端能力域自持契约分片(ADR 0052 D2/D4)
|
|
4
|
+
//
|
|
5
|
+
// 本文件是 `wasmnest-ws-client-engine` 持有的**共享契约真源**(world `cap-ws`
|
|
6
|
+
// 只 import 客户端域 `host-websocket`):双端 `compose.json` 的 caps.ws 直接指向
|
|
7
|
+
// 本文件(pty 先例)——契约与移动侧实现(同一 crate 的引擎)同属一处。
|
|
8
|
+
//
|
|
9
|
+
// 桌面侧客户端实现暂留 `wasmnest-server-websocket`(common-host 绑定,契约源
|
|
10
|
+
// 同为本文件;ADR 0041 D1 的已知双轨,收敛另行立项);服务端域
|
|
11
|
+
// (原 `host-websocket-server`,10 函数)是桌面扩展,声明真源在桌面
|
|
12
|
+
// `plugin-sdk-desktop/rust/wit-src/cap-ws.wit`(world `cap-ws-server`),不在本文件。
|
|
13
|
+
//
|
|
14
|
+
// 端生成物由 `scripts/compose-wit.mjs` 拼装(本文件与 core.wit 及其余 cap 分片
|
|
15
|
+
// 同 package 同版本)。分片只换绑定源、不换装配语义:`impl Host` / `HostModule` /
|
|
16
|
+
// `MODULE_*` / `DESC` 与 WIT 契约的函数集逐字一致。
|
|
17
|
+
// ======================================================================
|
|
18
|
+
|
|
19
|
+
/// WebSocket 基础能力(v14 起;双端交集切片 = 客户端域 5 函数)
|
|
20
|
+
///
|
|
21
|
+
/// 桌面独有服务端域(入站端点 10 函数,v14/v28 追加)拆入
|
|
22
|
+
/// [`host-websocket-server`](cap-ws 分片,移动端不跑 WS 服务器、不跟演);
|
|
23
|
+
/// 本接口只剩双端交集(出站连接域)。
|
|
24
|
+
///
|
|
25
|
+
/// 事件投递(双端偏离见各端 cap 注释):状态事件经 host-bus 属主私有 topic
|
|
26
|
+
/// 推送(`<owner>::ws:open|error|close`),消息帧经可选导出 events-ws 回调。
|
|
27
|
+
interface host-websocket {
|
|
28
|
+
/// 建立出站 WS 连接:**同步阻塞至握手完成**(上限 connect-timeout-secs,
|
|
29
|
+
/// 与 host-http 非流式模式同款 block_on 语义)。
|
|
30
|
+
/// config-json(camelCase)纯引擎参数:
|
|
31
|
+
/// `{ url, headers?, protocols?, connect-timeout-secs?, max-message-bytes? }`
|
|
32
|
+
/// url **仅接受 `ws://`**(`wss://` 本期不支持,返回明确错误)。
|
|
33
|
+
/// 成功 → 返回连接句柄 `wsc-<uuid>` 并发布 `<owner>::ws:open`;
|
|
34
|
+
/// 失败 → 错误上抛且**不发布任何事件**(无句柄可寻址)。
|
|
35
|
+
connect: func(config-json: string) -> result<string, string>;
|
|
36
|
+
/// 发送文本帧(UTF-8);连接不存在/已关闭/发送队列满 → 错误
|
|
37
|
+
send-text: func(handle: string, text: string) -> result<_, string>;
|
|
38
|
+
/// 发送二进制帧;错误语义同 send-text
|
|
39
|
+
send-binary: func(handle: string, payload: list<u8>) -> result<_, string>;
|
|
40
|
+
/// 主动关闭连接(close-json:`{ code?, reason? }`,缺省 1000);返回是否命中。
|
|
41
|
+
/// 该连接的 `ws:close.<owner>` 随即上报(wasClean=true 当且仅当 code ∈ {1000,1001})
|
|
42
|
+
close: func(handle: string, close-json: string) -> result<bool, string>;
|
|
43
|
+
/// 查询连接是否处于 open 态(握手完成且未关闭);仅属主可查。
|
|
44
|
+
/// 供插件在丢失状态事件后自愈
|
|
45
|
+
is-connected: func(handle: string) -> result<bool, string>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
world cap-ws {
|
|
49
|
+
import host-websocket;
|
|
50
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
package wasmnest:ws-server@0.0.1;
|
|
2
|
+
// ======================================================================
|
|
3
|
+
// WebSocket 服务端域(桌面扩展分片,自 `host-websocket` 拆出)
|
|
4
|
+
//
|
|
5
|
+
// 双端功能区分的归属(ADR 0052 D3/D4):客户端域(出站连接 5 函数)是双端
|
|
6
|
+
// 功能级交集,契约与移动侧实现归能力域 crate `wasmnest-ws-client-engine`(真源
|
|
7
|
+
// `packages/wasmnest-ws-client-engine/wit/ws.wit`,world `cap-ws`;桌面侧实现
|
|
8
|
+
// 暂留 `wasmnest-server-websocket` 的双轨收敛另行立项);本 interface 只剩桌面
|
|
9
|
+
// 独有服务端域(入站端点 10 函数,v14 起 + v28 `connection-context`)。
|
|
10
|
+
// 移动端不跑 WS 服务器(ADR 0018 移动端是消费端),服务端域与「插件入站
|
|
11
|
+
// 端点」语义在本端**不存在**,不跟演(ADR 0019 双端偏离)。
|
|
12
|
+
//
|
|
13
|
+
// 属主隔离:**全部函数仅属主可调**(他人句柄/端点 → Err,
|
|
14
|
+
// `not owner of ws handle`);插件停用时宿主自动回收其全部句柄与端点。
|
|
15
|
+
// 权限:服务端域需 `ws:server`。
|
|
16
|
+
//
|
|
17
|
+
// 事件投递:状态事件经 host-bus 订阅,走**属主私有命名空间**
|
|
18
|
+
// (`<owner>::…`,跨属主订阅在宿主侧显式拒绝,他人既订不到也伪投递不进;
|
|
19
|
+
// 构造一律用 SDK `ws_event_topic`,勿手拼),标识在 payload:
|
|
20
|
+
// 服务端域 `<owner>::ws:client-connect` / `<owner>::ws:client-disconnect`
|
|
21
|
+
// 插件**须在 activate 期(或首次 register-endpoint 之前)完成订阅**:
|
|
22
|
+
// 宿主不缓冲、不重放,晚订阅期间的事件永久丢失;丢失自愈靠
|
|
23
|
+
// `list-clients` / `list-endpoints` 查询原语。
|
|
24
|
+
// 消息帧(text + binary)经可选导出 `events-ws` 回调投递。
|
|
25
|
+
//
|
|
26
|
+
// 桌面端 cap 真源:`compose.json` caps.ws-server 指向本文件,
|
|
27
|
+
// 由 `scripts/compose-wit.mjs` 复制为生成物 `rust/wit/cap-ws-server.wit`。
|
|
28
|
+
interface host-websocket-server {
|
|
29
|
+
// ==================== 服务端域(入站端点) ====================
|
|
30
|
+
/// 在宿主 WS 服务器挂载插件端点(实际路径 `/ws/plugin/<plugin-id>/<path>`,
|
|
31
|
+
/// 命名空间段由宿主注入,插件只提供后缀)。
|
|
32
|
+
/// config-json(camelCase)纯引擎参数:
|
|
33
|
+
/// `{ path, auth?, max-message-bytes?, max-clients? }`
|
|
34
|
+
/// auth = "none"(默认:跳过首消息认证状态机,插件自管认证)
|
|
35
|
+
/// | "jwt"(宿主校验首消息 `{"type":"auth","token":"<jwt>"}`)。
|
|
36
|
+
///
|
|
37
|
+
/// 链路加密策略**按应用**决定(应用设置页 → `link_crypto::set_app_policy`),
|
|
38
|
+
/// 覆盖该应用全部 HTTP / WS 端点;本注册配置不携带 `encryption` 字段
|
|
39
|
+
/// (未知字段 → `Err`,严格解析)。
|
|
40
|
+
/// path 非法(空、含 `/`、含 `.`、超长)或与本插件已注册端点冲突 → 错误
|
|
41
|
+
/// (跨插件不冲突:路径含 plugin-id 段)。返回端点句柄 `wse-<uuid>`。
|
|
42
|
+
/// 端点存在期间的每一帧都经宿主流过滤器链
|
|
43
|
+
register-endpoint: func(config-json: string) -> result<string, string>;
|
|
44
|
+
/// 向端点的指定客户端发文本帧;客户端不存在/队列满 → 错误
|
|
45
|
+
send-text-to-client: func(endpoint-id: string, client-id: string, text: string) -> result<_, string>;
|
|
46
|
+
/// 向端点的指定客户端发二进制帧
|
|
47
|
+
send-binary-to-client: func(endpoint-id: string, client-id: string, payload: list<u8>) -> result<_, string>;
|
|
48
|
+
/// 向端点全部客户端广播文本帧 → 成功入队客户端数(部分失败不回滚)
|
|
49
|
+
broadcast-text: func(endpoint-id: string, text: string) -> result<u32, string>;
|
|
50
|
+
/// 向端点全部客户端广播二进制帧 → 成功入队客户端数
|
|
51
|
+
broadcast-binary: func(endpoint-id: string, payload: list<u8>) -> result<u32, string>;
|
|
52
|
+
/// 主动踢出端点的单个客户端(close-json:`{ code?, reason? }`,缺省 4004);
|
|
53
|
+
/// 返回是否命中;随后该客户端经 `ws:client-disconnect.<owner>` 上报
|
|
54
|
+
close-client: func(endpoint-id: string, client-id: string, close-json: string) -> result<bool, string>;
|
|
55
|
+
/// 关闭端点并回收句柄(含下线全部客户端,close code 4005);返回是否存在该端点
|
|
56
|
+
unregister-endpoint: func(endpoint-id: string) -> result<bool, string>;
|
|
57
|
+
/// 端点在线的客户端清单 → JSON 数组
|
|
58
|
+
/// `[{ clientId, addr, authenticated, connectedAt }]`(camelCase);
|
|
59
|
+
/// 供插件在丢失 client-connect 事件后自愈;仅属主可查
|
|
60
|
+
list-clients: func(endpoint-id: string) -> result<string, string>;
|
|
61
|
+
/// 本插件已注册端点清单 → JSON 数组 `[{ endpointId, path, clientCount }]`;
|
|
62
|
+
/// 仅属主可查
|
|
63
|
+
list-endpoints: func() -> result<string, string>;
|
|
64
|
+
|
|
65
|
+
// ==================== v28:连接上下文(安全/连接事实,零业务派生) ====================
|
|
66
|
+
|
|
67
|
+
/// 查询端点指定客户端的**已脱敏**连接/认证上下文。
|
|
68
|
+
///
|
|
69
|
+
/// 返回值只含连接/认证**事实**,不包含会话、设备在线判定、配对记录或任何业务
|
|
70
|
+
/// 派生字段:
|
|
71
|
+
///
|
|
72
|
+
/// ```json
|
|
73
|
+
/// {
|
|
74
|
+
/// "clientId": "c-123",
|
|
75
|
+
/// "endpointId": "wse-456",
|
|
76
|
+
/// "owner": "com.example.plugin",
|
|
77
|
+
/// "addr": "192.168.1.10:54321",
|
|
78
|
+
/// "authenticated": true,
|
|
79
|
+
/// "connectedAt": 1730000000000,
|
|
80
|
+
/// "authContext": {
|
|
81
|
+
/// "subject": "device-or-client-subject",
|
|
82
|
+
/// "deviceName": "optional-name",
|
|
83
|
+
/// "fingerprint": "optional-fingerprint"
|
|
84
|
+
/// }
|
|
85
|
+
/// }
|
|
86
|
+
/// ```
|
|
87
|
+
///
|
|
88
|
+
/// 约束:
|
|
89
|
+
/// - 仅**端点属主**可调(权限 `ws:server` + 属主仲裁,跨插件查询显式拒绝);
|
|
90
|
+
/// - 客户端不存在/不在该端点名下 → `Err`(`client not found in endpoint`);
|
|
91
|
+
/// - **永不返回 JWT、token、公钥、私钥或配对记录**(凭据红线,AGENTS §8);
|
|
92
|
+
/// - `auth: "none"` 时 `authenticated=false`,`authContext` 省略(不伪造身份);
|
|
93
|
+
/// - 该原语是安全上下文查询,**不是**设备列表/在线判定/会话查询接口——
|
|
94
|
+
/// 设备派生视图由插件自 `list-clients` 与本原语组合建立。
|
|
95
|
+
connection-context: func(endpoint-id: string, client-id: string) -> result<string, string>;
|
|
96
|
+
}
|
|
97
|
+
world cap-ws-server {
|
|
98
|
+
import host-websocket-server;
|
|
99
|
+
}
|