@binblink/wasmnest-plugin-sdk-desktop 0.0.1 → 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 +24 -4
- package/README_en.md +1 -1
- package/bin/cli.js +5 -5
- package/bin/manifest-gen.js +4 -0
- package/bin/manifest-validate.js +68 -6
- package/bin/permission-vocabulary.json +2 -2
- package/dev-shell/README.md +6 -5
- package/dev-shell/src/loader.ts +0 -5
- package/dev-shell/src/mock/commands.ts +1 -1
- package/dev-shell/src/mock/domain-context.ts +1 -1
- package/dev-shell/src/shell/types.ts +21 -32
- package/dev-shell/src/styles/shell.css +208 -2
- package/dev-shell/src/styles/style.css +72 -26
- package/dist/index.d.ts +44 -3
- package/dist/index.js +69 -1
- package/dist/types.d.ts +52 -5
- 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 +12 -1
- package/src/index.ts +8 -0
- package/src/types.ts +681 -630
- package/src/ui/AppUpdateSection.d.ts +44 -0
- package/src/ui/AppUpdateSection.vue +253 -0
- package/src/ui/NumberField.d.ts +49 -0
- package/src/ui/NumberField.vue +390 -0
- package/src/ui/Select.vue +4 -4
- package/src/update.ts +123 -0
- package/template/README.md +39 -39
- package/tools/componentize/Cargo.lock +30 -1
- package/tools/componentize/Cargo.toml +3 -0
- package/tools/componentize/src/main.rs +197 -94
- package/dev-shell/src/mock/agent-hub-commands.ts +0 -1065
- package/dev-shell/src/mock/agent-hub.ts +0 -42
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
|
2
|
+
|
|
3
|
+
// Package hosttask represents the imported interface "wasmnest:task/host-task@0.0.1".
|
|
4
|
+
//
|
|
5
|
+
// 桌面端能力域分片(WIT 按包拆分,ADR 0061):一个能力域 = 一个独立包,
|
|
6
|
+
// 版本独立演进——本包 WIT 变更只 bump 本包,不波及未 import 它的应用。
|
|
7
|
+
// 端 `plugin` world 经 `include wasmnest:task/cap-task@0.0.1;` 并入本接口。
|
|
8
|
+
// 宿主并发任务域(v20,**desktop 独有,双端偏离**——同 host-pty / host-auth 先例,
|
|
9
|
+
// ADR 0022「双端偏离」节:桌面独有接口不要求移动端跟演;当前 desktop ABI v31、
|
|
10
|
+
// mobile 11;移动端要接同类能力时再补该端 interface 并对齐计数)。
|
|
11
|
+
//
|
|
12
|
+
// 问题域:WASM 插件(wasm32-wasip3 组件)无法创建 OS 线程;其全部宿主调用在
|
|
13
|
+
// 当前 ABI 下同步阻塞——插件要并发做 50 个 `fs.stat` / 并行跑 3 条 `git diff`,
|
|
14
|
+
// 只能串行排队,每个调用都占用 Store 执行线程。本接口让插件把「单元操作计划」
|
|
15
|
+
// 提交给宿主:由宿主专用 OS 线程池真并行执行既有宿主原语(零业务语义,
|
|
16
|
+
// ADR 0022 裁剪线——宿主不做任何编排解释;fail-collect 不 fail-fast,单元独立
|
|
17
|
+
// 成败,结果按 units 原顺序返回,`id` 由插件指定用于关联,编排判断归插件)。
|
|
18
|
+
//
|
|
19
|
+
// 两档 API 共享同一单元模型与执行器:
|
|
20
|
+
// - `execute-batch`(同步档):扇出 → join → 一次性返回全部单元结果。阻塞 Store
|
|
21
|
+
// 至全部单元终态(或超时)——同 `run-sync` 的阻塞语义,仅限快操作(数十
|
|
22
|
+
// 百毫秒级);长任务一律 `submit`。
|
|
23
|
+
// - `submit`(异步档):登记后立即返回句柄 `task-<uuid>`,宿主线线程池执行,
|
|
24
|
+
// 进度/终态经可选导出 `events-task#on-task-event` 回调;`cancel` 协作式取消。
|
|
25
|
+
//
|
|
26
|
+
// 属主隔离:句柄 `task-<uuid>` 仅创建者插件可调(沿 pty- / wsc- 先例);
|
|
27
|
+
// 插件停用时宿主回收其全部任务(cancel 全部在册任务、清注册表、清回调队列)。
|
|
28
|
+
// 事件丢失自愈:`status` / `list-jobs` 是权威快照(回调是尽力投递)。
|
|
29
|
+
package hosttask
|
|
30
|
+
|
|
31
|
+
import (
|
|
32
|
+
"go.bytecodealliance.org/cm"
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
// ExecuteBatch represents the imported function "execute-batch".
|
|
36
|
+
//
|
|
37
|
+
// 同步批:并发执行 plan 全部单元并 join。
|
|
38
|
+
// plan-json(camelCase):
|
|
39
|
+
// `{ units: [{ id, kind, params }], maxConcurrency?, jobTimeoutMs?, progress? }`
|
|
40
|
+
// - `units[].params` = 对应宿主原语既有请求 JSON **原样内嵌**(如
|
|
41
|
+
// `process.run-sync` 的 params 就是 run-sync 的 request-json),宿主零新 DTO
|
|
42
|
+
// 映射,语义单点在既有实现;
|
|
43
|
+
// - `maxConcurrency` ≤ 全局池线程数,缺省 = 池满即排队;
|
|
44
|
+
// - `jobTimeoutMs` 缺省取常量;超时 → cancelled + 已完成单元结果保留。
|
|
45
|
+
// 返回 `{ jobId, results: [{ id, ok, value?|error?, durationMs }], cancelled }`
|
|
46
|
+
// (camelCase;`value` = 单元原语的原返回 JSON 字符串)。
|
|
47
|
+
// 阻塞 Store 至全部单元终态(或超时)——同 `run-sync` 的阻塞语义,仅限快操作。
|
|
48
|
+
//
|
|
49
|
+
// execute-batch: func(plan-json: string) -> result<string, string>
|
|
50
|
+
//
|
|
51
|
+
//go:nosplit
|
|
52
|
+
func ExecuteBatch(planJSON string) (result cm.Result[string, string, string]) {
|
|
53
|
+
planJson0, planJson1 := cm.LowerString(planJSON)
|
|
54
|
+
wasmimport_ExecuteBatch((*uint8)(planJson0), (uint32)(planJson1), &result)
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Submit represents the imported function "submit".
|
|
59
|
+
//
|
|
60
|
+
// 异步任务:登记后立即返回句柄 `task-<uuid>`;进度/终态经 events-task 回调。
|
|
61
|
+
// plan 同 `execute-batch`,返回 `task-<uuid>` 字符串。
|
|
62
|
+
//
|
|
63
|
+
// submit: func(plan-json: string) -> result<string, string>
|
|
64
|
+
//
|
|
65
|
+
//go:nosplit
|
|
66
|
+
func Submit(planJSON string) (result cm.Result[string, string, string]) {
|
|
67
|
+
planJson0, planJson1 := cm.LowerString(planJSON)
|
|
68
|
+
wasmimport_Submit((*uint8)(planJson0), (uint32)(planJson1), &result)
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Status represents the imported function "status".
|
|
73
|
+
//
|
|
74
|
+
// 任务状态自愈快照(事件丢失后查询):state / 计数器 / 终态 results(有界保留)。
|
|
75
|
+
// `Ok(None)` = job-id 不存在或非属主(不存在与无权限对调用方不可区分,防枚举)。
|
|
76
|
+
//
|
|
77
|
+
// status: func(job-id: string) -> result<option<string>, string>
|
|
78
|
+
//
|
|
79
|
+
//go:nosplit
|
|
80
|
+
func Status(jobID string) (result cm.Result[OptionStringShape, cm.Option[string], string]) {
|
|
81
|
+
jobId0, jobId1 := cm.LowerString(jobID)
|
|
82
|
+
wasmimport_Status((*uint8)(jobId0), (uint32)(jobId1), &result)
|
|
83
|
+
return
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Cancel represents the imported function "cancel".
|
|
87
|
+
//
|
|
88
|
+
// 取消(协作式:正在执行的单元跑完或超时,未开始单元 skipped);幂等,
|
|
89
|
+
// 返回是否命中(`Ok(false)` = 任务不存在 / 非属主 / 已终态)。
|
|
90
|
+
//
|
|
91
|
+
// cancel: func(job-id: string) -> result<bool, string>
|
|
92
|
+
//
|
|
93
|
+
//go:nosplit
|
|
94
|
+
func Cancel(jobID string) (result cm.Result[string, bool, string]) {
|
|
95
|
+
jobId0, jobId1 := cm.LowerString(jobID)
|
|
96
|
+
wasmimport_Cancel((*uint8)(jobId0), (uint32)(jobId1), &result)
|
|
97
|
+
return
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// ListJobs represents the imported function "list-jobs".
|
|
101
|
+
//
|
|
102
|
+
// 本插件在册任务清单(自愈快照):`[ { jobId, state, doneUnits?, failedUnits?, createdAt } ]`
|
|
103
|
+
//
|
|
104
|
+
// list-jobs: func() -> result<string, string>
|
|
105
|
+
//
|
|
106
|
+
//go:nosplit
|
|
107
|
+
func ListJobs() (result cm.Result[string, string, string]) {
|
|
108
|
+
wasmimport_ListJobs(&result)
|
|
109
|
+
return
|
|
110
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
|
2
|
+
|
|
3
|
+
package hosttimer
|
|
4
|
+
|
|
5
|
+
import (
|
|
6
|
+
"go.bytecodealliance.org/cm"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
// This file contains wasmimport and wasmexport declarations for "wasmnest:timer@0.0.1".
|
|
10
|
+
|
|
11
|
+
//go:wasmimport wasmnest:timer/host-timer@0.0.1 register
|
|
12
|
+
//go:noescape
|
|
13
|
+
func wasmimport_Register(intervalSecs0 uint64, command0 *uint8, command1 uint32, result *cm.Result[string, struct{}, string])
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
|
2
|
+
|
|
3
|
+
// Package hosttimer represents the imported interface "wasmnest:timer/host-timer@0.0.1".
|
|
4
|
+
//
|
|
5
|
+
// 桌面端能力域分片(WIT 按包拆分,ADR 0061):一个能力域 = 一个独立包,
|
|
6
|
+
// 版本独立演进——本包 WIT 变更只 bump 本包,不波及未 import 它的应用。
|
|
7
|
+
// 端 `plugin` world 经 `include wasmnest:timer/cap-timer@0.0.1;` 并入本接口。
|
|
8
|
+
// 宿主周期定时器(原 timer.rs:timer_register,ABI v6)
|
|
9
|
+
package hosttimer
|
|
10
|
+
|
|
11
|
+
import (
|
|
12
|
+
"go.bytecodealliance.org/cm"
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
// Register represents the imported function "register".
|
|
16
|
+
//
|
|
17
|
+
// register: func(interval-secs: u64, command: string) -> result<_, string>
|
|
18
|
+
//
|
|
19
|
+
//go:nosplit
|
|
20
|
+
func Register(intervalSecs uint64, command string) (result cm.Result[string, struct{}, string]) {
|
|
21
|
+
intervalSecs0 := (uint64)(intervalSecs)
|
|
22
|
+
command0, command1 := cm.LowerString(command)
|
|
23
|
+
wasmimport_Register((uint64)(intervalSecs0), (*uint8)(command0), (uint32)(command1), &result)
|
|
24
|
+
return
|
|
25
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
|
2
|
+
|
|
3
|
+
package hostwebsocket
|
|
4
|
+
|
|
5
|
+
import (
|
|
6
|
+
"go.bytecodealliance.org/cm"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
// This file contains wasmimport and wasmexport declarations for "wasmnest:ws@0.0.1".
|
|
10
|
+
|
|
11
|
+
//go:wasmimport wasmnest:ws/host-websocket@0.0.1 connect
|
|
12
|
+
//go:noescape
|
|
13
|
+
func wasmimport_Connect(configJson0 *uint8, configJson1 uint32, result *cm.Result[string, string, string])
|
|
14
|
+
|
|
15
|
+
//go:wasmimport wasmnest:ws/host-websocket@0.0.1 send-text
|
|
16
|
+
//go:noescape
|
|
17
|
+
func wasmimport_SendText(handle0 *uint8, handle1 uint32, text0 *uint8, text1 uint32, result *cm.Result[string, struct{}, string])
|
|
18
|
+
|
|
19
|
+
//go:wasmimport wasmnest:ws/host-websocket@0.0.1 send-binary
|
|
20
|
+
//go:noescape
|
|
21
|
+
func wasmimport_SendBinary(handle0 *uint8, handle1 uint32, payload0 *uint8, payload1 uint32, result *cm.Result[string, struct{}, string])
|
|
22
|
+
|
|
23
|
+
//go:wasmimport wasmnest:ws/host-websocket@0.0.1 close
|
|
24
|
+
//go:noescape
|
|
25
|
+
func wasmimport_Close(handle0 *uint8, handle1 uint32, closeJson0 *uint8, closeJson1 uint32, result *cm.Result[string, bool, string])
|
|
26
|
+
|
|
27
|
+
//go:wasmimport wasmnest:ws/host-websocket@0.0.1 is-connected
|
|
28
|
+
//go:noescape
|
|
29
|
+
func wasmimport_IsConnected(handle0 *uint8, handle1 uint32, result *cm.Result[string, bool, string])
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
|
2
|
+
|
|
3
|
+
// Package hostwebsocket represents the imported interface "wasmnest:ws/host-websocket@0.0.1".
|
|
4
|
+
//
|
|
5
|
+
// ======================================================================
|
|
6
|
+
// WebSocket 客户端能力域自持契约分片(ADR 0052 D2/D4)
|
|
7
|
+
//
|
|
8
|
+
// 本文件是 `wasmnest-ws-client-engine` 持有的**共享契约真源**(world `cap-ws`
|
|
9
|
+
// 只 import 客户端域 `host-websocket`):双端 `compose.json` 的 caps.ws 直接指向
|
|
10
|
+
// 本文件(pty 先例)——契约与移动侧实现(同一 crate 的引擎)同属一处。
|
|
11
|
+
//
|
|
12
|
+
// 桌面侧客户端实现暂留 `wasmnest-server-websocket`(common-host 绑定,契约源
|
|
13
|
+
// 同为本文件;ADR 0041 D1 的已知双轨,收敛另行立项);服务端域
|
|
14
|
+
// (原 `host-websocket-server`,10 函数)是桌面扩展,声明真源在桌面
|
|
15
|
+
// `plugin-sdk-desktop/rust/wit-src/cap-ws.wit`(world `cap-ws-server`),不在本文件。
|
|
16
|
+
//
|
|
17
|
+
// 端生成物由 `scripts/compose-wit.mjs` 拼装(本文件与 core.wit 及其余 cap 分片
|
|
18
|
+
// 同 package 同版本)。分片只换绑定源、不换装配语义:`impl Host` / `HostModule` /
|
|
19
|
+
// `MODULE_*` / `DESC` 与 WIT 契约的函数集逐字一致。
|
|
20
|
+
// ======================================================================
|
|
21
|
+
// WebSocket 基础能力(v14 起;双端交集切片 = 客户端域 5 函数)
|
|
22
|
+
//
|
|
23
|
+
// 桌面独有服务端域(入站端点 10 函数,v14/v28 追加)拆入
|
|
24
|
+
// [`host-websocket-server`](cap-ws 分片,移动端不跑 WS 服务器、不跟演);
|
|
25
|
+
// 本接口只剩双端交集(出站连接域)。
|
|
26
|
+
//
|
|
27
|
+
// 事件投递(双端偏离见各端 cap 注释):状态事件经 host-bus 属主私有 topic
|
|
28
|
+
// 推送(`<owner>::ws:open|error|close`),消息帧经可选导出 events-ws 回调。
|
|
29
|
+
package hostwebsocket
|
|
30
|
+
|
|
31
|
+
import (
|
|
32
|
+
"go.bytecodealliance.org/cm"
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
// Connect represents the imported function "connect".
|
|
36
|
+
//
|
|
37
|
+
// 建立出站 WS 连接:**同步阻塞至握手完成**(上限 connect-timeout-secs,
|
|
38
|
+
// 与 host-http 非流式模式同款 block_on 语义)。
|
|
39
|
+
// config-json(camelCase)纯引擎参数:
|
|
40
|
+
// `{ url, headers?, protocols?, connect-timeout-secs?, max-message-bytes? }`
|
|
41
|
+
// url **仅接受 `ws://`**(`wss://` 本期不支持,返回明确错误)。
|
|
42
|
+
// 成功 → 返回连接句柄 `wsc-<uuid>` 并发布 `<owner>::ws:open`;
|
|
43
|
+
// 失败 → 错误上抛且**不发布任何事件**(无句柄可寻址)。
|
|
44
|
+
//
|
|
45
|
+
// connect: func(config-json: string) -> result<string, string>
|
|
46
|
+
//
|
|
47
|
+
//go:nosplit
|
|
48
|
+
func Connect(configJSON string) (result cm.Result[string, string, string]) {
|
|
49
|
+
configJson0, configJson1 := cm.LowerString(configJSON)
|
|
50
|
+
wasmimport_Connect((*uint8)(configJson0), (uint32)(configJson1), &result)
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// SendText represents the imported function "send-text".
|
|
55
|
+
//
|
|
56
|
+
// 发送文本帧(UTF-8);连接不存在/已关闭/发送队列满 → 错误
|
|
57
|
+
//
|
|
58
|
+
// send-text: func(handle: string, text: string) -> result<_, string>
|
|
59
|
+
//
|
|
60
|
+
//go:nosplit
|
|
61
|
+
func SendText(handle string, text string) (result cm.Result[string, struct{}, string]) {
|
|
62
|
+
handle0, handle1 := cm.LowerString(handle)
|
|
63
|
+
text0, text1 := cm.LowerString(text)
|
|
64
|
+
wasmimport_SendText((*uint8)(handle0), (uint32)(handle1), (*uint8)(text0), (uint32)(text1), &result)
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// SendBinary represents the imported function "send-binary".
|
|
69
|
+
//
|
|
70
|
+
// 发送二进制帧;错误语义同 send-text
|
|
71
|
+
//
|
|
72
|
+
// send-binary: func(handle: string, payload: list<u8>) -> result<_, string>
|
|
73
|
+
//
|
|
74
|
+
//go:nosplit
|
|
75
|
+
func SendBinary(handle string, payload cm.List[uint8]) (result cm.Result[string, struct{}, string]) {
|
|
76
|
+
handle0, handle1 := cm.LowerString(handle)
|
|
77
|
+
payload0, payload1 := cm.LowerList(payload)
|
|
78
|
+
wasmimport_SendBinary((*uint8)(handle0), (uint32)(handle1), (*uint8)(payload0), (uint32)(payload1), &result)
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Close represents the imported function "close".
|
|
83
|
+
//
|
|
84
|
+
// 主动关闭连接(close-json:`{ code?, reason? }`,缺省 1000);返回是否命中。
|
|
85
|
+
// 该连接的 `ws:close.<owner>` 随即上报(wasClean=true 当且仅当 code ∈ {1000,1001})
|
|
86
|
+
//
|
|
87
|
+
// close: func(handle: string, close-json: string) -> result<bool, string>
|
|
88
|
+
//
|
|
89
|
+
//go:nosplit
|
|
90
|
+
func Close(handle string, closeJSON string) (result cm.Result[string, bool, string]) {
|
|
91
|
+
handle0, handle1 := cm.LowerString(handle)
|
|
92
|
+
closeJson0, closeJson1 := cm.LowerString(closeJSON)
|
|
93
|
+
wasmimport_Close((*uint8)(handle0), (uint32)(handle1), (*uint8)(closeJson0), (uint32)(closeJson1), &result)
|
|
94
|
+
return
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// IsConnected represents the imported function "is-connected".
|
|
98
|
+
//
|
|
99
|
+
// 查询连接是否处于 open 态(握手完成且未关闭);仅属主可查。
|
|
100
|
+
// 供插件在丢失状态事件后自愈
|
|
101
|
+
//
|
|
102
|
+
// is-connected: func(handle: string) -> result<bool, string>
|
|
103
|
+
//
|
|
104
|
+
//go:nosplit
|
|
105
|
+
func IsConnected(handle string) (result cm.Result[string, bool, string]) {
|
|
106
|
+
handle0, handle1 := cm.LowerString(handle)
|
|
107
|
+
wasmimport_IsConnected((*uint8)(handle0), (uint32)(handle1), &result)
|
|
108
|
+
return
|
|
109
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
|
2
|
+
|
|
3
|
+
package hostwebsocketserver
|
|
4
|
+
|
|
5
|
+
import (
|
|
6
|
+
"go.bytecodealliance.org/cm"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
// This file contains wasmimport and wasmexport declarations for "wasmnest:ws-server@0.0.1".
|
|
10
|
+
|
|
11
|
+
//go:wasmimport wasmnest:ws-server/host-websocket-server@0.0.1 register-endpoint
|
|
12
|
+
//go:noescape
|
|
13
|
+
func wasmimport_RegisterEndpoint(configJson0 *uint8, configJson1 uint32, result *cm.Result[string, string, string])
|
|
14
|
+
|
|
15
|
+
//go:wasmimport wasmnest:ws-server/host-websocket-server@0.0.1 send-text-to-client
|
|
16
|
+
//go:noescape
|
|
17
|
+
func wasmimport_SendTextToClient(endpointId0 *uint8, endpointId1 uint32, clientId0 *uint8, clientId1 uint32, text0 *uint8, text1 uint32, result *cm.Result[string, struct{}, string])
|
|
18
|
+
|
|
19
|
+
//go:wasmimport wasmnest:ws-server/host-websocket-server@0.0.1 send-binary-to-client
|
|
20
|
+
//go:noescape
|
|
21
|
+
func wasmimport_SendBinaryToClient(endpointId0 *uint8, endpointId1 uint32, clientId0 *uint8, clientId1 uint32, payload0 *uint8, payload1 uint32, result *cm.Result[string, struct{}, string])
|
|
22
|
+
|
|
23
|
+
//go:wasmimport wasmnest:ws-server/host-websocket-server@0.0.1 broadcast-text
|
|
24
|
+
//go:noescape
|
|
25
|
+
func wasmimport_BroadcastText(endpointId0 *uint8, endpointId1 uint32, text0 *uint8, text1 uint32, result *cm.Result[string, uint32, string])
|
|
26
|
+
|
|
27
|
+
//go:wasmimport wasmnest:ws-server/host-websocket-server@0.0.1 broadcast-binary
|
|
28
|
+
//go:noescape
|
|
29
|
+
func wasmimport_BroadcastBinary(endpointId0 *uint8, endpointId1 uint32, payload0 *uint8, payload1 uint32, result *cm.Result[string, uint32, string])
|
|
30
|
+
|
|
31
|
+
//go:wasmimport wasmnest:ws-server/host-websocket-server@0.0.1 close-client
|
|
32
|
+
//go:noescape
|
|
33
|
+
func wasmimport_CloseClient(endpointId0 *uint8, endpointId1 uint32, clientId0 *uint8, clientId1 uint32, closeJson0 *uint8, closeJson1 uint32, result *cm.Result[string, bool, string])
|
|
34
|
+
|
|
35
|
+
//go:wasmimport wasmnest:ws-server/host-websocket-server@0.0.1 unregister-endpoint
|
|
36
|
+
//go:noescape
|
|
37
|
+
func wasmimport_UnregisterEndpoint(endpointId0 *uint8, endpointId1 uint32, result *cm.Result[string, bool, string])
|
|
38
|
+
|
|
39
|
+
//go:wasmimport wasmnest:ws-server/host-websocket-server@0.0.1 list-clients
|
|
40
|
+
//go:noescape
|
|
41
|
+
func wasmimport_ListClients(endpointId0 *uint8, endpointId1 uint32, result *cm.Result[string, string, string])
|
|
42
|
+
|
|
43
|
+
//go:wasmimport wasmnest:ws-server/host-websocket-server@0.0.1 list-endpoints
|
|
44
|
+
//go:noescape
|
|
45
|
+
func wasmimport_ListEndpoints(result *cm.Result[string, string, string])
|
|
46
|
+
|
|
47
|
+
//go:wasmimport wasmnest:ws-server/host-websocket-server@0.0.1 connection-context
|
|
48
|
+
//go:noescape
|
|
49
|
+
func wasmimport_ConnectionContext(endpointId0 *uint8, endpointId1 uint32, clientId0 *uint8, clientId1 uint32, result *cm.Result[string, string, string])
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
|
2
|
+
|
|
3
|
+
// Package hostwebsocketserver represents the imported interface "wasmnest:ws-server/host-websocket-server@0.0.1".
|
|
4
|
+
//
|
|
5
|
+
// ======================================================================
|
|
6
|
+
// WebSocket 服务端域(桌面扩展分片,自 `host-websocket` 拆出)
|
|
7
|
+
//
|
|
8
|
+
// 双端功能区分的归属(ADR 0052 D3/D4):客户端域(出站连接 5 函数)是双端
|
|
9
|
+
// 功能级交集,契约与移动侧实现归能力域 crate `wasmnest-ws-client-engine`(真源
|
|
10
|
+
// `packages/wasmnest-ws-client-engine/wit/ws.wit`,world `cap-ws`;桌面侧实现
|
|
11
|
+
// 暂留 `wasmnest-server-websocket` 的双轨收敛另行立项);本 interface 只剩桌面
|
|
12
|
+
// 独有服务端域(入站端点 10 函数,v14 起 + v28 `connection-context`)。
|
|
13
|
+
// 移动端不跑 WS 服务器(ADR 0018 移动端是消费端),服务端域与「插件入站
|
|
14
|
+
// 端点」语义在本端**不存在**,不跟演(ADR 0019 双端偏离)。
|
|
15
|
+
//
|
|
16
|
+
// 属主隔离:**全部函数仅属主可调**(他人句柄/端点 → Err,
|
|
17
|
+
// `not owner of ws handle`);插件停用时宿主自动回收其全部句柄与端点。
|
|
18
|
+
// 权限:服务端域需 `ws:server`。
|
|
19
|
+
//
|
|
20
|
+
// 事件投递:状态事件经 host-bus 订阅,走**属主私有命名空间**
|
|
21
|
+
// (`<owner>::…`,跨属主订阅在宿主侧显式拒绝,他人既订不到也伪投递不进;
|
|
22
|
+
// 构造一律用 SDK `ws_event_topic`,勿手拼),标识在 payload:
|
|
23
|
+
// 服务端域 `<owner>::ws:client-connect` / `<owner>::ws:client-disconnect`
|
|
24
|
+
// 插件**须在 activate 期(或首次 register-endpoint 之前)完成订阅**:
|
|
25
|
+
// 宿主不缓冲、不重放,晚订阅期间的事件永久丢失;丢失自愈靠
|
|
26
|
+
// `list-clients` / `list-endpoints` 查询原语。
|
|
27
|
+
// 消息帧(text + binary)经可选导出 `events-ws` 回调投递。
|
|
28
|
+
//
|
|
29
|
+
// 桌面端 cap 真源:`compose.json` caps.ws-server 指向本文件,
|
|
30
|
+
// 由 `scripts/compose-wit.mjs` 复制为生成物 `rust/wit/cap-ws-server.wit`。
|
|
31
|
+
package hostwebsocketserver
|
|
32
|
+
|
|
33
|
+
import (
|
|
34
|
+
"go.bytecodealliance.org/cm"
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
// RegisterEndpoint represents the imported function "register-endpoint".
|
|
38
|
+
//
|
|
39
|
+
// ==================== 服务端域(入站端点) ====================
|
|
40
|
+
// 在宿主 WS 服务器挂载插件端点(实际路径 `/ws/plugin/<plugin-id>/<path>`,
|
|
41
|
+
// 命名空间段由宿主注入,插件只提供后缀)。
|
|
42
|
+
// config-json(camelCase)纯引擎参数:
|
|
43
|
+
// `{ path, auth?, max-message-bytes?, max-clients? }`
|
|
44
|
+
// auth = "none"(默认:跳过首消息认证状态机,插件自管认证)
|
|
45
|
+
// | "jwt"(宿主校验首消息 `{"type":"auth","token":"<jwt>"}`)。
|
|
46
|
+
//
|
|
47
|
+
// 链路加密策略**按应用**决定(应用设置页 → `link_crypto::set_app_policy`),
|
|
48
|
+
// 覆盖该应用全部 HTTP / WS 端点;本注册配置不携带 `encryption` 字段
|
|
49
|
+
// (未知字段 → `Err`,严格解析)。
|
|
50
|
+
// path 非法(空、含 `/`、含 `.`、超长)或与本插件已注册端点冲突 → 错误
|
|
51
|
+
// (跨插件不冲突:路径含 plugin-id 段)。返回端点句柄 `wse-<uuid>`。
|
|
52
|
+
// 端点存在期间的每一帧都经宿主流过滤器链
|
|
53
|
+
//
|
|
54
|
+
// register-endpoint: func(config-json: string) -> result<string, string>
|
|
55
|
+
//
|
|
56
|
+
//go:nosplit
|
|
57
|
+
func RegisterEndpoint(configJSON string) (result cm.Result[string, string, string]) {
|
|
58
|
+
configJson0, configJson1 := cm.LowerString(configJSON)
|
|
59
|
+
wasmimport_RegisterEndpoint((*uint8)(configJson0), (uint32)(configJson1), &result)
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// SendTextToClient represents the imported function "send-text-to-client".
|
|
64
|
+
//
|
|
65
|
+
// 向端点的指定客户端发文本帧;客户端不存在/队列满 → 错误
|
|
66
|
+
//
|
|
67
|
+
// send-text-to-client: func(endpoint-id: string, client-id: string, text: string)
|
|
68
|
+
// -> result<_, string>
|
|
69
|
+
//
|
|
70
|
+
//go:nosplit
|
|
71
|
+
func SendTextToClient(endpointID string, clientID string, text string) (result cm.Result[string, struct{}, string]) {
|
|
72
|
+
endpointId0, endpointId1 := cm.LowerString(endpointID)
|
|
73
|
+
clientId0, clientId1 := cm.LowerString(clientID)
|
|
74
|
+
text0, text1 := cm.LowerString(text)
|
|
75
|
+
wasmimport_SendTextToClient((*uint8)(endpointId0), (uint32)(endpointId1), (*uint8)(clientId0), (uint32)(clientId1), (*uint8)(text0), (uint32)(text1), &result)
|
|
76
|
+
return
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// SendBinaryToClient represents the imported function "send-binary-to-client".
|
|
80
|
+
//
|
|
81
|
+
// 向端点的指定客户端发二进制帧
|
|
82
|
+
//
|
|
83
|
+
// send-binary-to-client: func(endpoint-id: string, client-id: string, payload: list<u8>)
|
|
84
|
+
// -> result<_, string>
|
|
85
|
+
//
|
|
86
|
+
//go:nosplit
|
|
87
|
+
func SendBinaryToClient(endpointID string, clientID string, payload cm.List[uint8]) (result cm.Result[string, struct{}, string]) {
|
|
88
|
+
endpointId0, endpointId1 := cm.LowerString(endpointID)
|
|
89
|
+
clientId0, clientId1 := cm.LowerString(clientID)
|
|
90
|
+
payload0, payload1 := cm.LowerList(payload)
|
|
91
|
+
wasmimport_SendBinaryToClient((*uint8)(endpointId0), (uint32)(endpointId1), (*uint8)(clientId0), (uint32)(clientId1), (*uint8)(payload0), (uint32)(payload1), &result)
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// BroadcastText represents the imported function "broadcast-text".
|
|
96
|
+
//
|
|
97
|
+
// 向端点全部客户端广播文本帧 → 成功入队客户端数(部分失败不回滚)
|
|
98
|
+
//
|
|
99
|
+
// broadcast-text: func(endpoint-id: string, text: string) -> result<u32, string>
|
|
100
|
+
//
|
|
101
|
+
//go:nosplit
|
|
102
|
+
func BroadcastText(endpointID string, text string) (result cm.Result[string, uint32, string]) {
|
|
103
|
+
endpointId0, endpointId1 := cm.LowerString(endpointID)
|
|
104
|
+
text0, text1 := cm.LowerString(text)
|
|
105
|
+
wasmimport_BroadcastText((*uint8)(endpointId0), (uint32)(endpointId1), (*uint8)(text0), (uint32)(text1), &result)
|
|
106
|
+
return
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// BroadcastBinary represents the imported function "broadcast-binary".
|
|
110
|
+
//
|
|
111
|
+
// 向端点全部客户端广播二进制帧 → 成功入队客户端数
|
|
112
|
+
//
|
|
113
|
+
// broadcast-binary: func(endpoint-id: string, payload: list<u8>) -> result<u32, string>
|
|
114
|
+
//
|
|
115
|
+
//go:nosplit
|
|
116
|
+
func BroadcastBinary(endpointID string, payload cm.List[uint8]) (result cm.Result[string, uint32, string]) {
|
|
117
|
+
endpointId0, endpointId1 := cm.LowerString(endpointID)
|
|
118
|
+
payload0, payload1 := cm.LowerList(payload)
|
|
119
|
+
wasmimport_BroadcastBinary((*uint8)(endpointId0), (uint32)(endpointId1), (*uint8)(payload0), (uint32)(payload1), &result)
|
|
120
|
+
return
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// CloseClient represents the imported function "close-client".
|
|
124
|
+
//
|
|
125
|
+
// 主动踢出端点的单个客户端(close-json:`{ code?, reason? }`,缺省 4004);
|
|
126
|
+
// 返回是否命中;随后该客户端经 `ws:client-disconnect.<owner>` 上报
|
|
127
|
+
//
|
|
128
|
+
// close-client: func(endpoint-id: string, client-id: string, close-json: string)
|
|
129
|
+
// -> result<bool, string>
|
|
130
|
+
//
|
|
131
|
+
//go:nosplit
|
|
132
|
+
func CloseClient(endpointID string, clientID string, closeJSON string) (result cm.Result[string, bool, string]) {
|
|
133
|
+
endpointId0, endpointId1 := cm.LowerString(endpointID)
|
|
134
|
+
clientId0, clientId1 := cm.LowerString(clientID)
|
|
135
|
+
closeJson0, closeJson1 := cm.LowerString(closeJSON)
|
|
136
|
+
wasmimport_CloseClient((*uint8)(endpointId0), (uint32)(endpointId1), (*uint8)(clientId0), (uint32)(clientId1), (*uint8)(closeJson0), (uint32)(closeJson1), &result)
|
|
137
|
+
return
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// UnregisterEndpoint represents the imported function "unregister-endpoint".
|
|
141
|
+
//
|
|
142
|
+
// 关闭端点并回收句柄(含下线全部客户端,close code 4005);返回是否存在该端点
|
|
143
|
+
//
|
|
144
|
+
// unregister-endpoint: func(endpoint-id: string) -> result<bool, string>
|
|
145
|
+
//
|
|
146
|
+
//go:nosplit
|
|
147
|
+
func UnregisterEndpoint(endpointID string) (result cm.Result[string, bool, string]) {
|
|
148
|
+
endpointId0, endpointId1 := cm.LowerString(endpointID)
|
|
149
|
+
wasmimport_UnregisterEndpoint((*uint8)(endpointId0), (uint32)(endpointId1), &result)
|
|
150
|
+
return
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// ListClients represents the imported function "list-clients".
|
|
154
|
+
//
|
|
155
|
+
// 端点在线的客户端清单 → JSON 数组
|
|
156
|
+
// `[{ clientId, addr, authenticated, connectedAt }]`(camelCase);
|
|
157
|
+
// 供插件在丢失 client-connect 事件后自愈;仅属主可查
|
|
158
|
+
//
|
|
159
|
+
// list-clients: func(endpoint-id: string) -> result<string, string>
|
|
160
|
+
//
|
|
161
|
+
//go:nosplit
|
|
162
|
+
func ListClients(endpointID string) (result cm.Result[string, string, string]) {
|
|
163
|
+
endpointId0, endpointId1 := cm.LowerString(endpointID)
|
|
164
|
+
wasmimport_ListClients((*uint8)(endpointId0), (uint32)(endpointId1), &result)
|
|
165
|
+
return
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// ListEndpoints represents the imported function "list-endpoints".
|
|
169
|
+
//
|
|
170
|
+
// 本插件已注册端点清单 → JSON 数组 `[{ endpointId, path, clientCount }]`;
|
|
171
|
+
// 仅属主可查
|
|
172
|
+
//
|
|
173
|
+
// list-endpoints: func() -> result<string, string>
|
|
174
|
+
//
|
|
175
|
+
//go:nosplit
|
|
176
|
+
func ListEndpoints() (result cm.Result[string, string, string]) {
|
|
177
|
+
wasmimport_ListEndpoints(&result)
|
|
178
|
+
return
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// ConnectionContext represents the imported function "connection-context".
|
|
182
|
+
//
|
|
183
|
+
// ==================== v28:连接上下文(安全/连接事实,零业务派生) ====================
|
|
184
|
+
// 查询端点指定客户端的**已脱敏**连接/认证上下文。
|
|
185
|
+
//
|
|
186
|
+
// 返回值只含连接/认证**事实**,不包含会话、设备在线判定、配对记录或任何业务
|
|
187
|
+
// 派生字段:
|
|
188
|
+
//
|
|
189
|
+
// {
|
|
190
|
+
// "clientId": "c-123",
|
|
191
|
+
// "endpointId": "wse-456",
|
|
192
|
+
// "owner": "com.example.plugin",
|
|
193
|
+
// "addr": "192.168.1.10:54321",
|
|
194
|
+
// "authenticated": true,
|
|
195
|
+
// "connectedAt": 1730000000000,
|
|
196
|
+
// "authContext": {
|
|
197
|
+
// "subject": "device-or-client-subject",
|
|
198
|
+
// "deviceName": "optional-name",
|
|
199
|
+
// "fingerprint": "optional-fingerprint"
|
|
200
|
+
// }
|
|
201
|
+
// }
|
|
202
|
+
//
|
|
203
|
+
// 约束:
|
|
204
|
+
// - 仅**端点属主**可调(权限 `ws:server` + 属主仲裁,跨插件查询显式拒绝);
|
|
205
|
+
// - 客户端不存在/不在该端点名下 → `Err`(`client not found in endpoint`);
|
|
206
|
+
// - **永不返回 JWT、token、公钥、私钥或配对记录**(凭据红线,AGENTS §8);
|
|
207
|
+
// - `auth: "none"` 时 `authenticated=false`,`authContext` 省略(不伪造身份);
|
|
208
|
+
// - 该原语是安全上下文查询,**不是**设备列表/在线判定/会话查询接口——
|
|
209
|
+
// 设备派生视图由插件自 `list-clients` 与本原语组合建立。
|
|
210
|
+
//
|
|
211
|
+
// connection-context: func(endpoint-id: string, client-id: string) -> result<string,
|
|
212
|
+
// string>
|
|
213
|
+
//
|
|
214
|
+
//go:nosplit
|
|
215
|
+
func ConnectionContext(endpointID string, clientID string) (result cm.Result[string, string, string]) {
|
|
216
|
+
endpointId0, endpointId1 := cm.LowerString(endpointID)
|
|
217
|
+
clientId0, clientId1 := cm.LowerString(clientID)
|
|
218
|
+
wasmimport_ConnectionContext((*uint8)(endpointId0), (uint32)(endpointId1), (*uint8)(clientId0), (uint32)(clientId1), &result)
|
|
219
|
+
return
|
|
220
|
+
}
|
package/go/go.mod
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// WasmNest 插件 SDK——Go 壳(issue #21「应用后端 Go 语言支持」Phase 1)
|
|
2
|
+
//
|
|
3
|
+
// 模块随平台仓源码取用(首期不发布,spec #21 Out of Scope):应用 Go 工程经
|
|
4
|
+
// replace 指令把本模块指到本目录,等价于 Rust 侧经 crates.io 版本 + [patch]
|
|
5
|
+
// 指回工作树 SDK 的消费形态。
|
|
6
|
+
//
|
|
7
|
+
// 绑定生成物 gen/ 与 SDK 壳 sdk/ 之外,本模块不含手工维护的契约内容——
|
|
8
|
+
// 契约真源在能力仓 WIT(经 compose-wit.mjs 拼装到 ../rust/wit/),重生成见
|
|
9
|
+
// tools/gen-bindings.mjs。
|
|
10
|
+
module github.com/7zai/wasmnest-plugin-sdk-go
|
|
11
|
+
|
|
12
|
+
go 1.27.3
|
|
13
|
+
|
|
14
|
+
require go.bytecodealliance.org/cm v0.3.0
|
package/go/go.sum
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// 命令分发表——最简形态的 [Plugin.InvokeCommand] 实现(可移植,原生可测)。
|
|
2
|
+
//
|
|
3
|
+
// 未知命令显性报错是纪律不是建议(spec #21 User Story 5:不静默返回空),
|
|
4
|
+
// [CommandTable.Invoke] 把这条纪律做成默认行为;应用自定义分发时须自行保持。
|
|
5
|
+
package sdk
|
|
6
|
+
|
|
7
|
+
import (
|
|
8
|
+
"encoding/json"
|
|
9
|
+
"fmt"
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
// CommandFunc 是单条命令的处理函数:原始 JSON 载荷进、任意 JSON 可序列化
|
|
13
|
+
// 值出(nil 序列化为 null,与 Rust `Value::Null` 同形)。
|
|
14
|
+
type CommandFunc func(args json.RawMessage) (any, error)
|
|
15
|
+
|
|
16
|
+
// CommandTable 是命令名到处理函数的分发表。
|
|
17
|
+
type CommandTable map[string]CommandFunc
|
|
18
|
+
|
|
19
|
+
// Invoke 分发一条命令;未知命令返回点名错误(不静默返回空)。
|
|
20
|
+
func (t CommandTable) Invoke(name string, args json.RawMessage) (any, error) {
|
|
21
|
+
fn, ok := t[name]
|
|
22
|
+
if !ok {
|
|
23
|
+
return nil, fmt.Errorf("unknown command: %s", name)
|
|
24
|
+
}
|
|
25
|
+
return fn(args)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// commandResultJSON 把命令结果序列化为宿主回传形状:成功 → 值的 JSON;
|
|
29
|
+
// 失败 → `{"error":"…"}`(错误串经 json.Marshal 转义,与 Rust 侧
|
|
30
|
+
// `serde_json::json!({ "error": e.to_string() })` 同口径,避免引号 /
|
|
31
|
+
// 反斜杠产出非法 JSON 屏蔽真实错误原因)。
|
|
32
|
+
func commandResultJSON(v any, err error) string {
|
|
33
|
+
if err != nil {
|
|
34
|
+
return mustJSON(map[string]string{"error": err.Error()})
|
|
35
|
+
}
|
|
36
|
+
return mustJSON(v)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
func mustJSON(v any) string {
|
|
40
|
+
b, err := json.Marshal(v)
|
|
41
|
+
if err != nil {
|
|
42
|
+
// 序列化失败只可能是值携带 chan / func 等不可编码类型(应用侧缺陷),
|
|
43
|
+
// 点名值类型而非吞错——宿主侧拿到非法 JSON 的诊断更难。
|
|
44
|
+
// 错误串本身经 map 编码转义(字符串值恒可编码,递归必终止),
|
|
45
|
+
// 不手工拼接——拼接会把错误串里的引号 / 反斜杠变成非法 JSON。
|
|
46
|
+
return mustJSON(map[string]string{"error": "command result not JSON-serializable: " + err.Error()})
|
|
47
|
+
}
|
|
48
|
+
return string(b)
|
|
49
|
+
}
|