mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 03:52:50 +08:00
feat(skin): connect v4 runtime prototype to WebClient
This commit is contained in:
1 parent
7993b38eee
commit
7650bd650b
14 files changed
+683
-49
No files matched your search
@@ -2,7 +2,7 @@
|
||||
|
||||
皮肤只作用于 WebSpeak 的公开连接首页和语音工作区。完成态要求作者能把公开界面几乎完整地做成自己的应用:所有公开组件都能重新排列、换皮、显隐或由作者自定义组件替代;作者可为自定义界面编写布局、样式和本地交互逻辑,不受固定宿主控件目录限制。TeamSpeak 连接、聊天、频道和音频行为仍由宿主能力层执行,管理后台、管理 API、演示设施及 KOOK 运营/广告页面不在范围内。
|
||||
|
||||
现有 v1/v2/v3 是兼容基础,不是“万物皆插件”的完成态。v3 的标签/属性、数据路径和宿主动作均为有限白名单;Wasm UI 输出也仍是未接入生产生命周期的原型。不得用“支持自定义节点”或“支持整页 surface”宣称已经实现完整自定义。
|
||||
现有 v1/v2/v3 是兼容基础,不是“万物皆插件”的完成态。v3 的标签/属性、数据路径和宿主动作均为有限白名单;Wasm UI 输出现已接入开发构建的生命周期,但生产执行仍关闭。不得用“支持自定义节点”或“支持整页 surface”宣称已经实现完整自定义。
|
||||
|
||||
零新增预算是持续约束:不因皮肤系统引入付费托管、CDN、域名或存储。商城与管理员面板重做由后续阶段共同规划;优先复用公开 GitHub 仓库、版本化 Release 附件和现有免费能力,不能把隐私配置发布到公共目录。
|
||||
|
||||
@@ -49,32 +49,38 @@ schema v2 支持公开组件布局、桌面/平板/手机配置、本地覆盖
|
||||
|
||||
### R3.3:完整自定义插件运行时(未完成,优先阶段)
|
||||
|
||||
当前已完成一个仅限开发构建的接入节点:授权、摘要校验、Wasm 生命周期、生成 UI 渲染、插件 CSS 和页面回退已经连到 WebClient。它仍是安全原型,生产构建保持关闭;数据投影和宿主动作能力也远未达到完整目标。
|
||||
|
||||
- v4 包格式的首个节点已落地:客户端和服务端共用 `plugins.json` 描述校验器,校验插件 ID、版本、页面、模式、权限、入口/样式/素材路径与重复 surface;客户端分开缓存插件文件,服务端校验文件存在和大小,并对文本入口/样式验证 UTF-8。
|
||||
- 新增插件本地授权的安全基础:SHA-256 摘要绑定插件描述和所有声明文件,授权记录同时绑定皮肤/插件版本、API 版本、摘要与权限策略版本。任一代码、样式、素材、挂载模式或权限变化都会使旧授权不匹配。摘要不是发布者签名,亦不证明包来源可信。
|
||||
- v4 入口支持 `.js` 与 `.wasm`;客户端对 Wasm 做固定导入/导出 ABI 预检,并按 MIME 类型分别缓存。服务端登记接受有大小上限的 Wasm 二进制,不运行它。
|
||||
- 新增开发态 v4 Wasm 适配器:启动前复核皮肤/插件版本、文件摘要和本地授权;只允许已实现的 `session.status.read` 权限,并为每次调用创建可终止的有界解释器任务。它没有接入 WebClient 的授权 UI、插件生命周期、频道/成员数据投影、动态 UI 渲染或 TeamSpeak 动作桥;普通 JS 仍不执行,生产运行时保持关闭。此节点不能作为完整运行时完成态。
|
||||
- 开发态 v4 Wasm 适配器已接入 WebClient 的本地授权 UI 和页面生命周期。用户授权前不会创建 Worker;授权绑定皮肤版本、插件描述、入口、样式、素材及权限策略摘要。页面切换会关闭插件循环,撤销、运行失败或卸载会终止 Worker、移除插件样式和对象 URL,并恢复宿主页面。
|
||||
- 已将有界 UI 循环接到生成节点树:Wasm 输出通过 schema 校验后由宿主渲染,不执行 HTML;只接收可信浏览器事件,组件状态和输入值继续限长。插件模式从 v4 描述继承,节点与 CSS 按插件 ID 隔离。插件 CSS 仅在明确授权且有有效输出后加载,并仅能引用全局皮肤资源和该插件自己的资源。
|
||||
- 当前开发宿主只支持 Wasm 插件和 `session.status.read`、`ui.surface.replace`。渲染输出不自动接收频道/成员/聊天上下文;没有频道切换、消息发送、音频等宿主动作桥。JavaScript 插件与未知权限会显示为未支持状态,不会执行;生产构建也通过 `import.meta.env.DEV` 保持运行时关闭。
|
||||
- 插件访问弹窗支持逐页批准、暂不启用、查看/撤销本皮肤的全部授权,并为 surface 提供切回标准界面和恢复内置皮肤入口。授权摘要或插件文件校验失败时关闭运行,不执行代码。
|
||||
- 继续新增 opt-in 的插件协议,不给旧 v1/v2/v3 包追溯增加代码执行能力;同一皮肤可将界面分成多个独立、可排序、可显示/隐藏、可单独授权和回退的插件。
|
||||
- 插件可自定义公开界面的 DOM 结构、CSS、组件状态和普通 UI 事件,不局限于当前标签、属性、数据字段和固定动作表。宿主控件目录变成可选的兼容原生组件。
|
||||
- 尚待定义 widget 插件在宿主页面中的挂载、排序、显隐和用户自定义几何布局;当前 v4 描述只有页面与 widget/surface 模式,没有挂载或实例布局字段。应把用户布局保存在本地宿主状态,并让 CSS/插件沙箱边界保持独立。
|
||||
- 插件对 TeamSpeak 的读取和操作经明确列举的权限、脱敏投影和宿主能力桥接;命令总由宿主校验参数、当前会话和权限。双击等事件只改变插件化界面的触发方式,不更改 TeamSpeak 协议,也不影响未启用该插件的其他皮肤。
|
||||
- 沙箱架构还未选定。opaque-origin iframe 可以隔离父页面 DOM 和存储,但不等于网络隔离:浏览器仍允许 frame 自己导航,`sandbox` 主要阻止顶层导航;CSP `navigate-to` 也不能作为跨浏览器阻断保证。若 iframe 同时持有获批的会话数据,插件可尝试把数据编码进自己的导航 URL。详见 R3.3 问题记录。不得因此把任意 JS 放进有浏览 DOM 的 iframe。
|
||||
- 已有安全原型把作者 JavaScript 放在没有 DOM/导航上下文的 data Worker 中,由 opaque-origin iframe 只负责消息桥;Worker CSP 可限制常规网络请求,但没有硬内存上限,仍保持生产关闭。下一版运行时必须同时保留完整自定义 UI 能力和确定的计算/内存边界:优先评估有界解释器 + 宿主创建的通用自定义节点树/CSS;不能以牺牲 DOM/事件自定义为理由退回固定原生控件目录。
|
||||
- 新增 Wasm UI 输出 schema v4/v5 原型:v4 提供常见安全 HTML/SVG、`data-*`/`aria-*` 和惰性自定义元素占位;v5 增加安全事件名到作者处理器 ID 的映射与本地状态。节点/组件/属性/文本仍有硬上限,危险加载、导航、脚本和事件属性会被拒绝。前端只发出剥离 DOM 对象的 `extension-event`,当前还没有接回 Wasm 或宿主能力桥,且未接入生产插件生命周期。
|
||||
- 插件生命周期包括批准前不加载、逐插件/逐权限批准、版本变化重新确认、撤销立即销毁上下文、超时/输出限额/崩溃隔离、旧包兼容和宿主恢复 UI。完整威胁模型、资源耗尽与跨浏览器测试未完成前不启用生产运行开关。
|
||||
- 新增 Wasm UI 输出 schema v4/v5 原型:v4 提供常见安全 HTML/SVG、`data-*`/`aria-*` 和惰性自定义元素占位;v5 增加安全事件名到作者处理器 ID 的映射与本地状态。节点/组件/属性/文本仍有硬上限,危险加载、导航、脚本和事件属性会被拒绝。开发态 WebClient 已把剥离 DOM 对象的 `extension-event` 接回 Wasm 循环并渲染输出;当前没有 TeamSpeak 宿主动作桥。
|
||||
- 插件生命周期的开发态路径已有批准前不加载、版本/内容变化重新确认、页面切换关闭、撤销销毁、超时/输出限额、错误恢复和旧包兼容。生产启用仍需完成更广的数据与动作权限、可信事件票据、资源耗尽和跨浏览器测试、独立安全审查。
|
||||
- 复核零新增预算约束:插件及本地素材随皮肤包分发,不依赖 CDN、外部脚本托管或付费沙箱服务。
|
||||
|
||||
#### R3.3 问题记录
|
||||
|
||||
- 首个 v4 沙箱候选把 opaque-origin iframe 当成了“无网络”边界。复核浏览器规则发现沙箱 frame 仍有自己的文档和 URL 导航能力,`allow-top-navigation` 仅控制顶层页面;当前 MDN browser-compat-data 也没有 `navigate-to` 指令条目。因而 `connect-src 'none'`、禁用表单/弹窗和 CSP 元标签不足以证明获批数据不会通过 frame 导航外传。否决 iframe 直接执行作者 JS 的方案;保留现有只运行于无 DOM Worker 的原型,但 JS 内存无硬上限,继续关闭生产执行。下一步必须通过可计量执行环境承载作者逻辑,并由可信宿主创建/校验通用自定义 UI 树与 CSS,再验证事件到 TeamSpeak 能力的桥接。
|
||||
- Wasm UI 输出原先经过扩展校验后又送入 v3 固定标签/属性解析器,导致打开节点协议时整份扩展 UI 被悄悄丢弃。现改为分别校验基础皮肤和生成输出,只在组件 ID 不冲突且合并数量有界时组合,并额外把自定义标签渲染为惰性 `div`。生产生命周期和能力授权桥接仍缺失,不代表完整运行时已完成。
|
||||
- 一次性 Wasm 运行先前没有宿主发回本地界面状态或交互事件的入口。现增加每次调用只读一次、8 KiB 封顶的 `ui_input_read`、输出 schema v5 命名回调,以及开发态有界 UI 重跑控制器;宿主事件只传安全字段,不信任作者可伪造的“用户手势”标记。当前 v4 Wasm 适配器只把摘要绑定的本地授权接到原型执行器,并只开放 `session.status.read`;循环尚未接入 WebClient 插件授权生命周期、动态 UI 渲染或 TeamSpeak 动作,不能据此打开生产开关。
|
||||
- Wasm UI 输出原先经过扩展校验后又送入 v3 固定标签/属性解析器,导致打开节点协议时整份扩展 UI 被悄悄丢弃。现改为分别校验基础皮肤和生成输出,只在组件 ID 不冲突且合并数量有界时组合,并额外把自定义标签渲染为惰性 `div`;此输出现在由开发态 v4 WebClient 宿主渲染。生产仍关闭,且没有 TeamSpeak 动作桥。
|
||||
- 一次性 Wasm 运行先前没有宿主发回本地界面状态或交互事件的入口。现增加每次调用只读一次、8 KiB 封顶的 `ui_input_read`、输出 schema v5 命名回调,以及开发态有界 UI 重跑控制器;宿主事件只传安全字段,不信任作者可伪造的“用户手势”标记。原先缺少的 WebClient 摘要授权、页面生命周期、生成 UI 渲染和插件 CSS 装载已由本节点接入。余下缺口是更广的数据投影、宿主动作桥及生产级安全审查。
|
||||
- 初次接入时,v4 surface 授权 UI 曾只列出权限却无法控制真实运行;循环关闭也没有联动移除 style 节点和对象 URL。现将授权状态绑定到实际启动路径,并在撤销、换页、失败、卸载时统一清理;v3 与 v4 对同一页声明 surface 时在导入阶段拒绝,避免两个整页 UI 互相覆盖。
|
||||
|
||||
### R3.4:声明式自定义节点布局编辑(已实施)
|
||||
|
||||
- 发现本地布局编辑器只登记了 WebSpeak 静态组件;皮肤 `components.json` 中自定义元素能用 CSS 排版,但不能由用户逐项移动、改尺寸或隐藏。
|
||||
- 为每个自定义组件根和每个实际 DOM 节点生成带 page/component 的动态布局 ID,接入现有每皮肤、每设备的本地覆盖、撤销/重做、导入导出和恢复流程。
|
||||
- 显式 `part` 名称用于保持关键节点覆盖稳定;未命名节点采用组件树路径,树结构调整可能改变对应覆盖。声明式可操作节点仍按至少 44 px 触控目标进行校验。
|
||||
- 本节点扩展的是已授权渲染的声明式皮肤 UI,不执行作者脚本;v4 插件多实例布局、安装授权 UI 和沙箱运行仍属未完成工作。
|
||||
- 本节点扩展的是已授权渲染的声明式皮肤 UI,不执行作者脚本;v4 的受限授权和开发运行原型已接入,但多插件布局、排序/显隐、本地几何设置及生产级沙箱仍属未完成工作。
|
||||
|
||||
### R4:整页皮肤界面和宿主控件组合(进行中)
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
# 更开放的皮肤系统规格
|
||||
|
||||
状态:v1/v2/v3 是兼容实现,不是“万物皆插件”目标的完成态。v4 的插件描述和包文件校验已接入客户端导入及服务端登记;客户端会校验 Wasm 入口的固定 ABI,但 JS/CSS/Wasm 默认只缓存、不执行。另有 Wasm 开发态适配器,会复核摘要绑定的本地授权后运行一次性有界任务,目前只支持 `session.status.read`,尚未接入 WebClient 插件生命周期或 UI/TeamSpeak 能力桥。components.json v3 仍限制元素/属性、数据字段、重复集合和宿主动作,动态 UI 输出也仍未接入生产客户端。完整插件运行时尚未实现,不能把当前系统描述为完全自定义。阶段记录和问题节点见[路线图](./OPEN_SKIN_SYSTEM_ROADMAP.zh-CN.md),当前包格式见[皮肤开发规范](./SKIN_DEVELOPMENT.md)。
|
||||
状态:v1/v2/v3 是兼容实现,不是“万物皆插件”目标的完成态。v4 的 Wasm 原型现已在开发构建接入 WebClient,包含摘要绑定授权、页面生命周期、隔离的动态 UI/CSS 渲染和错误恢复;只支持 `session.status.read`、`ui.surface.replace`,生产构建明确关闭。普通 JavaScript 不执行。频道/成员/聊天数据投影、TeamSpeak 宿主动作桥、widget 布局与插件独立配置仍未实现,故当前仍不能称为完整自定义系统。阶段记录和问题节点见[路线图](./OPEN_SKIN_SYSTEM_ROADMAP.zh-CN.md),当前包格式见[皮肤开发规范](./SKIN_DEVELOPMENT.md)。
|
||||
|
||||
## 1. 目标与范围
|
||||
|
||||
完整目标中,皮肤作者可以用自己的插件组件、DOM、CSS 和本地逻辑排列、替换、隐藏或重做公开客户端界面中的任何视觉元素,也可以重建首页和完整语音工作区。连接、频道、聊天、音频、收藏/历史、共享等基础能力始终由 WebSpeak/TeamSpeak 宿主保留;皮肤能替换其展示和交互入口,但不能删除或篡改底层业务能力。宿主恢复入口、权限管理和安全提示位于皮肤之外,任何插件失效、拒绝授权或撤销后都能回到原生可用界面。
|
||||
|
||||
当前 v1/v2/v3 只能达到该目标的一部分:v3 组件依赖有限标签、属性、数据和动作白名单;v4 包协议与 Wasm 开发执行原型已开始实现,但完整沙箱生命周期、数据投影、宿主渲染和动作桥仍待接入。本规格区分已实现行为与目标行为,不以当前限制重新定义完成态。
|
||||
当前 v1/v2/v3 只能达到该目标的一部分:v3 组件依赖有限标签、属性、数据和动作白名单;v4 开发原型已接入授权生命周期、宿主渲染和受限 UI 事件回路,但权限化数据投影、TeamSpeak 动作桥与插件布局管理仍待实现。本规格区分已实现行为与目标行为,不以当前限制重新定义完成态。
|
||||
|
||||
适用页面为连接首页、语音工作区和公开演示页。管理员面板及其数据、管理 API 明确排除,不读取皮肤包。语音服务的运营、广告、陪玩、活动和商店等页面不属于语音客户端皮肤范围。
|
||||
|
||||
@@ -18,11 +18,11 @@ v3 自定义组件不是脚本插件。components.json schema v1 是既有格式
|
||||
|
||||
宿主控件通过固定 ID 嵌入,始终由 WebSpeak 代码运行。当前可选注册表包括 `home.connection-form`、`app.skin-switcher`、`app.language-switcher`、`voice.channel-panel`、`voice.member-cards`、`voice.chat-panel`、`voice.audio-controls`、`voice.screen-share-player`、`voice.whisper-controls`、`voice.performance-panel`、`voice.connection-controls` 和 `voice.disconnect-control`。每个控件在同一页面最多出现一次;未知 ID 或重复的有状态控件会拒绝导入。作者可以不用这些控件,自行绘制界面并将点击、双击等事件绑定到公开数据与受权限保护的动作。
|
||||
|
||||
v1-v3 包不能提交 HTML 字符串、事件处理代码、JavaScript、WebAssembly、远程脚本、任意 URL、表单导航、浏览器存储访问或网络调用。v4 可携带本地 JS/Wasm/CSS 供后续沙箱运行时使用;JS/CSS 默认只校验和缓存,Wasm 还会做固定 ABI 预检。开发态 Wasm 适配器会在启动前校验摘要绑定的本地授权,仅开放 `session.status.read`,仍未接入 WebClient 授权 UI、插件生命周期、动态 UI 输出或 TeamSpeak 能力桥。未知字段、元素、动作、数据路径、控件和权限一律拒绝。
|
||||
v1-v3 包不能提交 HTML 字符串、事件处理代码、JavaScript、WebAssembly、远程脚本、任意 URL、表单导航、浏览器存储访问或网络调用。v4 可携带本地 JS/Wasm/CSS;JS 仍只校验和缓存,Wasm 在开发构建中经本地摘要授权后运行一次性有界任务,并经宿主解析、渲染动态 UI。运行时只有 `session.status.read` 与 `ui.surface.replace` 两项接入;不提供频道/成员/聊天数据或 TeamSpeak 动作。生产构建关闭 Wasm 执行。未知字段、元素、动作、数据路径、控件和权限一律拒绝。
|
||||
|
||||
### 2.1 完整插件目标协议(v4,运行时尚未实现)
|
||||
### 2.1 插件协议(v4 包格式已实现,受限开发运行时已接入)
|
||||
|
||||
已实现的 v4 包描述为 `plugins.json` schema v1:每包 1–64 个插件,每个插件指定唯一小写 ID、语义版本、API 版本 1、`home`/`voice` 页面、`widget`/`surface` 模式、`plugins/<id>/` 下入口 JS 或 Wasm/可选 CSS、该目录中的图片/woff2 素材和现有权限表中的权限。入口扩展名决定默认运行时,也可显式写 `runtime: "javascript"` 或 `runtime: "wasm"`,且必须匹配扩展名。每页至多一个 surface,且必须申请 `ui.surface.replace`。清单最多 256 KiB、插件入口最多 256 KiB、插件样式最多 512 KiB、每插件最多 32 个素材;引用文件必须存在且路径不重复。客户端与服务端复用同一解析器;客户端还对 Wasm 入口做固定 ABI 预检。另有 SHA-256 摘要与本地授权记录函数:摘要覆盖描述字段和入口、样式、全部素材;本机存储按皮肤、插件 ID 保存授权,并将授权绑定皮肤/插件版本、API 版本、文件摘要及权限策略版本。该摘要仅用于检测本机授权后包内容是否变化,不是发布者签名或来源证明。授权函数尚未接入宿主确认 UI 和执行生命周期;开发态 Wasm 适配器仅在摘要授权匹配后启动一次性有界任务,并只支持 `session.status.read`,尚不能视为生产插件执行。
|
||||
已实现的 v4 包描述为 `plugins.json` schema v1:每包 1–64 个插件,每个插件指定唯一小写 ID、语义版本、API 版本 1、`home`/`voice` 页面、`widget`/`surface` 模式、`plugins/<id>/` 下入口 JS 或 Wasm/可选 CSS、该目录中的图片/woff2 素材和现有权限表中的权限。入口扩展名决定默认运行时,也可显式写 `runtime: "javascript"` 或 `runtime: "wasm"`,且必须匹配扩展名。每页至多一个 v4 surface,且必须申请 `ui.surface.replace`;导入器也拒绝与同页 v3 surface 冲突。清单最多 256 KiB、插件入口最多 256 KiB、插件样式最多 512 KiB、每插件最多 32 个素材;引用文件必须存在且路径不重复。客户端与服务端复用同一解析器;客户端还对 Wasm 入口做固定 ABI 预检。SHA-256 摘要覆盖描述字段和入口、样式、全部素材;本机授权按皮肤、插件 ID 保存并绑定皮肤/插件版本、API 版本、文件摘要及权限策略版本。该摘要仅用于检测本机授权后包内容是否变化,不是发布者签名或来源证明。开发构建的 WebClient 已有逐页授权、Wasm 生命周期、schema 校验后的安全 UI 渲染和插件 CSS 装载;生产构建仍关闭执行。
|
||||
|
||||
当前 descriptor 没有定义 widget 的宿主挂载位置、实例顺序、显隐或几何配置。完整运行时需决定这些默认值随皮肤包分发还是由用户本地覆盖;用户布局应与作者文件分开存储,且沙箱内代码不能改动其他插件的宿主容器或恢复控件。
|
||||
|
||||
@@ -30,7 +30,7 @@ v1-v3 包不能提交 HTML 字符串、事件处理代码、JavaScript、WebAsse
|
||||
|
||||
不能把有 DOM 的 iframe 当作无网络沙箱。opaque origin 可隔离父页面 DOM、Cookie 和本地存储,但嵌入式浏览上下文仍允许自身 URL 导航;sandbox 阻止顶层导航的规则不阻止 frame 自己导航。CSP `navigate-to` 不能作为跨浏览器安全保证,因此仅关闭 `connect-src`、表单、弹窗和外部子 frame 不能阻止通过 URL 导航外带已授权的数据。若未来 iframe 只充当宿主可信的 UI 容器,作者代码必须在没有 DOM/导航能力的另一个受限执行环境中运行;iframe 内不得直接运行作者 JS。
|
||||
|
||||
当前 JavaScript 原型由 opaque-origin iframe 承载一个无 DOM 的 data Worker,CSP 阻断其常规网络接口,Worker 消息不能导航外层页面;但 JavaScript Worker 没有硬内存配额,不能作为面向不可信公开皮肤的生产边界。另有开发态 Wasm 原型:客户端导入器先解析受限模块结构,运行适配器再校验具体皮肤版本、插件、字节摘要和本地授权;每次运行使用可终止的有界解释器任务。当前仅开放 `session.status.read`,还没有 WebClient 生命周期集成、频道/成员数据投影、授权 UI、动态 UI 输出渲染或 TeamSpeak 动作桥,因此运行仍限于开发原型。下一版需把安全执行接入可信插件生命周期,并由宿主校验后创建通用 HTML 节点树和包内 CSS;作者仍需能自定义完整公开界面的结构、样式、局部状态和双击等交互,不能把安全改造变成固定宿主控件目录。
|
||||
当前 JavaScript 原型由 opaque-origin iframe 承载一个无 DOM 的 data Worker,CSP 阻断其常规网络接口,Worker 消息不能导航外层页面;但 JavaScript Worker 没有硬内存配额,不能作为面向不可信公开皮肤的生产边界。Wasm 原型由客户端校验模块结构,再校验具体皮肤版本、插件、字节摘要和本地授权;每次运行使用可终止的有界解释器任务。该原型现已接入开发版 WebClient 生命周期:用户批准后才启动,输出由宿主校验并创建安全节点,批准后才装载作用域限定的插件 CSS;切页、撤权和错误都会关闭任务并恢复基础页面。运行时只接入 `session.status.read` 与 `ui.surface.replace`,普通 UI 输出不自动接收其他宿主数据,也没有 TeamSpeak 动作桥。下一阶段仍需扩展权限化数据/动作协议、插件布局与管理,并完成端到端和独立安全审查;生产构建保持关闭。
|
||||
|
||||
作者逻辑不得直接持有宿主 DOM、网络、持久存储、TeamSpeak SDK 或原始媒体流。宿主只向独立、有界的执行环境提供按权限筛选的结构化数据和本地 UI 事件,并通过私有消息通道收发有界协议。用户在可信宿主节点上触发双击等事件时,宿主生成一次性、短时事件票据;运行时只有在票据未使用、动作权限获批、会话及目标有效、参数通过 schema 校验时才转发 TeamSpeak 动作。不能信任作者逻辑自报“用户已点击”。桥接必须拒绝未知 message、跨插件转发、重放、过期事件票据、过大数据与未批准动作;具体事件/渲染协议仍待实现。
|
||||
|
||||
@@ -77,7 +77,7 @@ v4 插件应独立声明读取投影和宿主动作权限,授权键至少包
|
||||
|
||||
## 4. CSS 与基础组件
|
||||
|
||||
v1-v3 CSS 被重写到当前公开皮肤根节点;未来启用 v4 时,插件 CSS 和宿主渲染的自定义 DOM 必须限制在各自插件容器内,不能让作者脚本直接操作宿主文档。当前 v4 代码尚未渲染。两种路径都不允许影响 `/admin/**`。页面权限提示、皮肤组件权限入口和“返回标准界面”控件由宿主放在皮肤插件/皮肤 CSS 之外,不能被作者样式隐藏。
|
||||
v1-v3 CSS 被重写到当前公开皮肤根节点;v4 插件 CSS 与宿主渲染的自定义 DOM 也限定在各自插件容器内,不运行作者脚本。插件 CSS 只有在用户批准该插件后才会装载。所有路径都不允许影响 `/admin/**`。页面权限提示、皮肤组件权限入口和“返回标准界面”控件由宿主放在皮肤插件/皮肤 CSS 之外,不能被作者样式隐藏。
|
||||
|
||||
v3 CSS 和 surface 可排列、替换或遮挡公开 UI,因此可能改变麦克风、退出、共享等控件的可见位置。宿主提供的“返回标准界面”和“恢复内置皮肤”控件以及组件权限确认和撤销入口在皮肤根节点之外;用户可立即退回 WebSpeak 页面,再用原生皮肤选择器切换皮肤。作者仍应在桌面和移动布局中保留语音操作的可达路径。
|
||||
|
||||
@@ -85,7 +85,7 @@ v3 CSS 和 surface 可排列、替换或遮挡公开 UI,因此可能改变麦
|
||||
|
||||
## 5. 校验与回退
|
||||
|
||||
客户端导入和服务端登记都会校验 manifest、ZIP 路径、组件协议、所引用素材和文件限额;v4 插件描述由共享解析器验证,JS/CSS 目前只作 UTF-8 和尺寸校验并缓存,不执行;Wasm 入口按二进制大小限额处理,客户端另行校验其固定 ABI。开发态 Wasm 适配器仅在摘要绑定的本地授权通过后调用有界解释器原型,尚未集成生产生命周期。现有组件运行时会再次解析持久化的组件文档;无效组件不执行。权限界面和恢复控件由宿主代码渲染。v3/v4 CSS 的作用域能降低跨应用影响,但 CSS 不是针对恶意脚本的沙箱。
|
||||
客户端导入和服务端登记都会校验 manifest、ZIP 路径、组件协议、所引用素材和文件限额;v4 插件描述由共享解析器验证,JS 只作 UTF-8 和尺寸校验并缓存、不执行;Wasm 入口另行校验固定 ABI。开发构建中的 Wasm 生命周期已有摘要授权 UI、可终止运行、动态输出解析和插件样式清理;生产构建保持关闭。现有组件运行时会再次解析持久化的组件文档;无效输出不渲染。权限界面和恢复控件由宿主代码渲染。v3/v4 CSS 的作用域能降低跨应用影响,但 CSS 不是针对恶意脚本的沙箱。
|
||||
|
||||
皮肤载入错误不得清除用户布局或 TeamSpeak 会话。组件树为空、权限被拒绝或皮肤无效时,宿主本身和既有功能仍可由用户恢复。v4 每个插件需有独立错误边界;单个插件崩溃不能拖垮语音会话或其余插件,撤销必须立即销毁该插件运行环境。管理员后台仍沿用自己的样式和服务端管理流程。
|
||||
|
||||
@@ -97,6 +97,6 @@ v3 CSS 和 surface 可排列、替换或遮挡公开 UI,因此可能改变麦
|
||||
|
||||
- 扩展数据字段或宿主动作时,增加精确 schema、权限、明确用户事件约束和宿主侧运行时验证,不暴露内部 SDK 对象。新增宿主控件也必须登记固定 ID、明确页面和确认只在宿主内处理其私有状态;自定义声明式 UI 不应被限制为只能拼装这组控件。
|
||||
- 对恶意输入、路径别名、拒绝授权、撤销、更新和皮肤切换增加测试;高敏能力必须单独设计。
|
||||
- 当前 JavaScript Worker 与 Wasm 扩展运行时都保持生产关闭。JavaScript Worker 缺少硬内存配额;Wasmi 解释器目前只是受限原型:解释器容器上限 64 MiB,扩展线性内存最多 4 MiB,燃料上限 10,000,000,外层 Worker 在 100 ms 后可终止执行。
|
||||
- Wasm 原型的 `env.ui_emit_json` 每次运行最多提交一次、最多 16 KiB 的 UTF-8 字符串。动态 UI 输出 schema v3 可用原声明式节点;v4 允许较完整的安全 HTML/SVG、ARIA/data 属性与包内图片;v5 再增加本地标量状态和节点事件到处理器 ID 的映射。宿主独立校验后创建节点,不把输出当 HTML 执行;自定义标签映射为惰性宿主 `div`,避免触发页面已注册 Web Component。脚本/框架、事件属性、密码/文件/隐藏输入、外部资源和导航目标会被拒绝。另有 `env.ui_input_read`,每次 Wasm 调用最多读取一次、最多 8 KiB 的状态/事件 JSON;宿主不传 DOM/Event 对象或自报的可信标记。开发态 UI 循环原型可把 outlet 发出的安全事件重新作为下一次有界 Wasm 调用的输入,最多串行排队 8 项,并在输出变化后重新验证回调 ID 和所属组件状态。生产 WebClient 尚未把循环接入经摘要授权的插件生命周期,也没有脱敏 TeamSpeak 数据投影或权限化宿主动作桥。Wasm 仍是生产关闭的安全原型。完成用户授权生命周期、可信事件票据/动作校验、权限绑定、资源耗尽测试、端到端验证和独立安全审查之前,不得启用运行开关。
|
||||
- JavaScript Worker 与 Wasm 扩展运行时在生产构建都保持关闭。开发 WebClient 仅用于原型验收;JavaScript Worker 缺少硬内存配额,Wasm 解释器目前也只是受限原型:解释器容器上限 64 MiB,扩展线性内存最多 4 MiB,燃料上限 10,000,000,外层 Worker 在 100 ms 后可终止执行。
|
||||
- Wasm 原型的 `env.ui_emit_json` 每次运行最多提交一次、最多 16 KiB 的 UTF-8 字符串。动态 UI 输出 schema v3 可用原声明式节点;v4 允许较完整的安全 HTML/SVG、ARIA/data 属性与包内图片;v5 再增加本地标量状态和节点事件到处理器 ID 的映射。WebClient 开发构建现已接收经摘要授权的输出,独立校验后由宿主创建节点,不把输出当 HTML 执行;自定义标签映射为惰性宿主 `div`,避免触发页面已注册 Web Component。脚本/框架、事件属性、密码/文件/隐藏输入、外部资源和导航目标会被拒绝。另有 `env.ui_input_read`,每次 Wasm 调用最多读取一次、最多 8 KiB 的状态/事件 JSON;宿主不传 DOM/Event 对象或自报的可信标记。开发态 UI 循环可将 outlet 发出的可信事件作为下一次有界 Wasm 调用输入,最多串行排队 8 项,并重新验证回调 ID 与组件状态归属。当前不提供频道/成员/聊天投影或 TeamSpeak 动作桥;生产构建保持关闭。达到生产启用条件前仍需完成更广权限桥、资源耗尽/跨浏览器端到端测试和独立安全审查。
|
||||
- 商城发布、签名、下架、更新和撤销设计与管理员面板重做一起验收,且保持零新增服务费用为默认约束。
|
||||
@@ -1,10 +1,10 @@
|
||||
# WebSpeak 皮肤开发规范
|
||||
|
||||
本文说明 v1 视觉皮肤、v2 声明式布局皮肤、v3 开放皮肤以及正在接入的 v4 插件包格式。v1/v2 保持固定 CSS 几何边界;v3 可重排公开 UI、用自定义声明式节点构建界面,并用 components.json schema v2/v3 替换首页/语音工作区的整页可见界面。v4 已加入插件清单、文件校验和本地缓存;客户端会预检 Wasm 固定 ABI,并有一个仅供开发验证的 Wasm 授权运行适配器。作者 JS 不执行,Wasm 适配器也没有接入生产 UI 生命周期或完整权限桥。路线和安全边界见[路线图](./OPEN_SKIN_SYSTEM_ROADMAP.zh-CN.md)与[规格](./OPEN_SKIN_SYSTEM_SPEC.zh-CN.md)。
|
||||
本文说明 v1 视觉皮肤、v2 声明式布局皮肤、v3 开放皮肤以及 v4 插件包格式。v1/v2 保持固定 CSS 几何边界;v3 可重排公开 UI、用自定义声明式节点构建界面,并用 components.json schema v2/v3 替换首页/语音工作区的整页可见界面。v4 有插件清单、文件校验和本地缓存;开发构建中的 Wasm 原型已接入 WebClient 授权与 UI 生命周期,生产构建仍关闭。作者 JS 不执行;频道/成员/聊天数据桥和 TeamSpeak 动作桥尚未实现。路线和安全边界见[路线图](./OPEN_SKIN_SYSTEM_ROADMAP.zh-CN.md)与[规格](./OPEN_SKIN_SYSTEM_SPEC.zh-CN.md)。
|
||||
|
||||
KOOK 语音界面参考仅覆盖用户授权的语音频道,语音区结构记录在[参考文档](./KOOK_VOICE_REFERENCE.zh-CN.md);发现、陪玩、活动、广告、商城和管理后台不属于复刻范围。
|
||||
|
||||
当前 v3 仍限制 HTML 标签、属性、可绑定数据集合和宿主动作,不能称为“完全自定义”或“万物皆插件”。v4 完整运行时尚未实现或获安全批准;JS/CSS 只校验、缓存,Wasm 入口增加固定 ABI 预检,开发适配器仅在本地摘要授权匹配时开放一次性有界任务,目前只支持 `session.status.read`。它还没有接入生产 UI 生命周期、频道/成员数据桥或 TeamSpeak 动作桥。完整运行时仍须支持作者自定义 DOM/CSS/本地逻辑,同时保持 TeamSpeak 功能经宿主能力桥接、皮肤后台之外可恢复。不要把 v4 包格式、v3 示例包或 Wasm 输出原型描述成已完成的全量插件系统。
|
||||
当前 v3 仍限制 HTML 标签、属性、可绑定数据集合和宿主动作,不能称为“完全自定义”或“万物皆插件”。开发构建的 v4 Wasm 原型已接入 WebClient 的本地摘要授权、页面生命周期、动态 UI 渲染与插件 CSS;目前只支持 `session.status.read` 和 `ui.surface.replace`,生产构建明确关闭。普通 JavaScript 仍只校验、缓存,不执行。当前没有频道/成员/聊天数据投影或 TeamSpeak 动作桥,也没有 widget 的排序、显隐和本地几何设置。完整目标仍要求作者能自定义 DOM/CSS/本地逻辑,同时保持 TeamSpeak 功能经宿主能力桥接、皮肤后台之外可恢复。不要把 v4 原型或 v3 示例包描述成已完成的全量插件系统。
|
||||
|
||||
`.wskin` 包可为公开页面定制艺术表现。v1 提供 CSS 与美术资源;v2 另外携带受校验的布局 JSON;v3 可自由安排公开组件,并用 components.json 声明由宿主渲染的安全组件。所有版本均由 WebSpeak 保留基础组件的业务逻辑和 TeamSpeak 行为。
|
||||
|
||||
@@ -117,7 +117,7 @@ v1 和 v2 都只支持公开页面。`/admin/**` 不加载布局、用户覆盖
|
||||
|
||||
v3 清单的 packageType 固定为 open-skin,entry 指向 CSS,components 指向 components.json;不含 v2 的 layout 或 permissions 字段。组件文件可以省略。仅 v3 开放公开页面的 CSS 排版能力,v1/v2 仍按旧 CSS 规则校验。客户端导入和服务端登记使用同一共享组件 schema 与权限白名单。
|
||||
|
||||
components.json 顶层接受 schemaVersion 1、2 或 3 和 components 数组。schema v1 维持旧兼容;schema v2 引入 `mode: "widget"`(默认)或 `mode: "surface"`,并提供可选宿主控件节点;schema v3 保持这些能力,扩大声明式 UI 的节点/状态/动作边界,并增加用户操作事件和语音功能动作。v3 仍使用固定元素/属性、公开数据集合和宿主动作白名单,不是任意 HTML 或任意脚本。每个组件需声明 id、name、page、accessibleName、permissions、actions 和 root,可选 state。page 接受 home、voice、demo;surface 仅可用于 home 和 voice,并且必须请求 `ui.surface.replace`。用户批准前不会显示 surface,撤销后宿主立即恢复普通页面。所有皮肤组件根节点及其中的每个可见元素都以动态布局项加入本地布局编辑器,可独立移动、缩放、改尺寸、改外观或隐藏。按钮、输入框及显式用户操作节点保留 44 px 最小触控区域。为让用户覆盖在树结构调整后仍能指向同一元素,请给重要节点设置稳定的 `part` 名称;未设置时按组件树位置生成标识。v4 完整插件协议见[规格](./OPEN_SKIN_SYSTEM_SPEC.zh-CN.md#21-完整插件目标协议v4尚未实现),当前不可作为已支持包格式使用。
|
||||
components.json 顶层接受 schemaVersion 1、2 或 3 和 components 数组。schema v1 维持旧兼容;schema v2 引入 `mode: "widget"`(默认)或 `mode: "surface"`,并提供可选宿主控件节点;schema v3 保持这些能力,扩大声明式 UI 的节点/状态/动作边界,并增加用户操作事件和语音功能动作。v3 仍使用固定元素/属性、公开数据集合和宿主动作白名单,不是任意 HTML 或任意脚本。每个组件需声明 id、name、page、accessibleName、permissions、actions 和 root,可选 state。page 接受 home、voice、demo;surface 仅可用于 home 和 voice,并且必须请求 `ui.surface.replace`。用户批准前不会显示 surface,撤销后宿主立即恢复普通页面。所有皮肤组件根节点及其中的每个可见元素都以动态布局项加入本地布局编辑器,可独立移动、缩放、改尺寸、改外观或隐藏。按钮、输入框及显式用户操作节点保留 44 px 最小触控区域。为让用户覆盖在树结构调整后仍能指向同一元素,请给重要节点设置稳定的 `part` 名称;未设置时按组件树位置生成标识。v4 包和开发态插件原型见[规格](./OPEN_SKIN_SYSTEM_SPEC.zh-CN.md);生产运行时仍关闭。
|
||||
|
||||
普通节点使用白名单 HTML/SVG 元素。节点可包含 text、part、className、受限 attributes、包内图片 asset、bindValue、本地 repeat/when、events 和 children。文本与属性支持简单的双大括号数据路径;不支持表达式、HTML 字符串或脚本。重复列表可使用注册的公开集合;频道重复项仅能再重复其 `channel.members`,并且需要额外批准 `session.members.read`。宿主每个组件的实际渲染节点最多 8192 个,防止嵌套集合放大界面。schema v2 另允许固定宿主控件节点,例如:
|
||||
|
||||
@@ -150,15 +150,15 @@ components.json 顶层接受 schemaVersion 1、2 或 3 和 components 数组。s
|
||||
|
||||
示例包见 [KAAK voice 示例](./examples/KAAK-VOICE.md),其 components.json 展示了公开频道列表和在线成员侧栏;[Open Voice Surface](./examples/OPEN-VOICE-SURFACE.md) 展示了完整首页和语音工作区 surface,是格式验证脚手架。KAAK 的语音视觉参考来自用户授权进入的前两个语音房间;只记录布局,不保留服务器/房间标识、成员名或聊天内容。当前数据权限和宿主动作以[开放皮肤规格](./OPEN_SKIN_SYSTEM_SPEC.zh-CN.md)中的清单为准。组件按本地用户授权后才渲染;权限对每个皮肤版本、页面和组件分别保存,可在宿主权限入口撤销。页面替换时,宿主会额外显示“返回标准界面”和“恢复内置皮肤”入口;拒绝授权或离开 surface 后,普通页面可立即恢复。
|
||||
|
||||
组件树有硬上限:components.json 256 KiB。schema v1/v2 上限为 32 个组件、每组件 256 个模板节点、16 层深度和 100 条重复记录;schema v3 上限为 128 个组件、每组件 2048 个模板节点、32 层深度和 250 条重复记录,并允许 64 个本地标量状态与 64 个动作。Wasmi 原型动态 UI 输出的 schema v4 有 16 KiB 总输出上限、最多 64 个组件、每个节点最多 64 个属性和 256 个子节点,并沿用每组件节点/深度限制;它可使用更广的安全 HTML/SVG 结构、ARIA/data 属性和包内图片。动态输出 schema v5 再增加本地标量状态及事件名到作者处理器 ID 的映射。宿主只通过 `isTrusted` 用户事件发出剥离 DOM/Event 对象后的 `extension-event`,Wasm 侧只能经 `env.ui_input_read` 一次读取最多 8 KiB 的 JSON。输入字段限长;生成界面中的 password/file/hidden 类型输入会拒绝。自定义元素名称映射为惰性 `div`,外部 URL、脚本/框架、事件属性和导航目标会拒绝。开发态 UI 循环原型可把事件作为下一次独立 Wasm 调用的输入,最多串行排队 8 项并验证回调/状态归属;它尚未接入实际 WebClient 授权生命周期,也没有 TeamSpeak 数据投影或宿主动作桥。生产开关仍关闭,不能当作完整插件运行时。
|
||||
组件树有硬上限:components.json 256 KiB。schema v1/v2 上限为 32 个组件、每组件 256 个模板节点、16 层深度和 100 条重复记录;schema v3 上限为 128 个组件、每组件 2048 个模板节点、32 层深度和 250 条重复记录,并允许 64 个本地标量状态与 64 个动作。Wasmi 原型动态 UI 输出的 schema v4 有 16 KiB 总输出上限、最多 64 个组件、每个节点最多 64 个属性和 256 个子节点,并沿用每组件节点/深度限制;它可使用更广的安全 HTML/SVG 结构、ARIA/data 属性和包内图片。动态输出 schema v5 再增加本地标量状态及事件名到作者处理器 ID 的映射。宿主只通过 `isTrusted` 用户事件发出剥离 DOM/Event 对象后的 `extension-event`,Wasm 侧只能经 `env.ui_input_read` 一次读取最多 8 KiB 的 JSON。输入字段限长;生成界面中的 password/file/hidden 类型输入会拒绝。自定义元素名称映射为惰性 `div`,外部 URL、脚本/框架、事件属性和导航目标会拒绝。开发构建中的 UI 循环已经接入 WebClient 授权生命周期,可把可信事件作为下一次独立 Wasm 调用输入,最多串行排队 8 项并验证回调/状态归属;当前仍没有 TeamSpeak 数据投影或宿主动作桥。生产构建关闭运行时,不能当作完整插件系统。
|
||||
|
||||
图片资源只能从包内引用,CSS 不能读取外部 URL、脚本或浏览器存储。宿主动作需显式权限,并只能绑定可信的用户事件;输入或 change 事件不能触发宿主动作。focus/blur、hover 和 drag-start/over 等被动事件只可改动组件本地状态,不能触发语音操作。
|
||||
|
||||
注意:v3 CSS 和 surface 可以隐藏或遮挡普通语音控件。权限和返回标准界面提示由宿主在皮肤根之外绘制;其他界面控件仍受皮肤排版影响。测试时务必确保麦克风、设置、退出语音、屏幕共享操作和移动端导航仍有可达路径。组件演示页 /demo 使用合成数据,加入频道和聊天动作只更新演示状态;它不支持宿主控件或整页替换。
|
||||
|
||||
### schemaVersion 4:插件包描述(运行时尚未启用)
|
||||
### schemaVersion 4:插件包描述与开发态运行时原型
|
||||
|
||||
v4 在 open-skin 包中增加必需的 `plugins` 路径。服务端登记和客户端导入共用 `plugins.json` schema v1 校验器;校验插件 ID、页面、模式、权限、文件归属、路径唯一性和包内文件大小,并将插件文件与普通皮肤素材分别缓存。客户端还会对 Wasm 入口执行固定导入/导出 ABI 预检。SHA-256 授权基础会绑定插件描述、入口、样式和全部素材;本机授权记录还会绑定皮肤/插件版本、API 版本和权限策略版本。摘要只能发现已授权内容被替换,不能证明发布者身份。当前持久化函数尚未连接用户确认界面或运行生命周期。JS、CSS 和 Wasm 文件默认只校验、缓存;另有开发态 Wasm 原型适配器,会在启动前复核摘要绑定的本地授权,但只支持 `session.status.read`,且没有接入 WebClient 生命周期或能力桥。生产运行时仍未启用,因此 v4 目前不能作为可运行插件发布。
|
||||
v4 在 open-skin 包中增加必需的 `plugins` 路径。服务端登记和客户端导入共用 `plugins.json` schema v1 校验器;校验插件 ID、页面、模式、权限、文件归属、路径唯一性和包内文件大小,并将插件文件与普通皮肤素材分别缓存。客户端还会对 Wasm 入口执行固定导入/导出 ABI 预检。SHA-256 授权基础会绑定插件描述、入口、样式和全部素材;本机授权记录还会绑定皮肤/插件版本、API 版本和权限策略版本。摘要只能发现已授权内容被替换,不能证明发布者身份。开发构建的 WebClient 已有本地授权对话框和 Wasm 运行生命周期;目前支持安全 UI 输出、可信 UI 事件回调、插件专属 CSS,以及 `session.status.read` / `ui.surface.replace`。JavaScript 仍只校验、缓存,不执行;生产构建的 Wasm 运行时保持关闭,因此 v4 仍是开发原型而非可发布的生产插件系统。
|
||||
|
||||
```json
|
||||
{
|
||||
@@ -177,9 +177,9 @@ v4 在 open-skin 包中增加必需的 `plugins` 路径。服务端登记和客
|
||||
|
||||
`plugins.json` 顶层 `schemaVersion` 当前为 `1`,并包含 1–64 个插件。每个插件声明 `id`、`name`、`version`、`apiVersion: 1`、`page`(`home` 或 `voice`)、`mode`(`widget` 或 `surface`)、必需的 `entry`、可选的 `runtime`、可选的 `style`、素材路径数组 `assets` 和 `permissions`。入口扩展名 `.js` 默认对应 `javascript`,`.wasm` 默认对应 `wasm`;显式 `runtime` 必须与入口扩展名一致。入口及样式必须位于 `plugins/<id>/`;素材必须位于该插件自己的 `assets/` 子目录,只能是本地图片或 woff2 字体。插件不能共享文件;同一公开页面最多有一个 `surface`,且必须申请 `ui.surface.replace`。其余权限只能从 `src/shared/skin-plugin.ts` 的现有权限表中选择。
|
||||
|
||||
`plugins.json` 不超过 256 KiB;每个入口 JS 或 Wasm 不超过 256 KiB,每个样式 CSS 不超过 512 KiB;每个插件最多声明 32 个素材。客户端导入会拒绝不符合固定内存、导入、导出和 Wasm 模块结构限制的入口。皮肤包整体仍受通用 ZIP 文件数、展开大小、图像和字体限额约束。v1–v3 不接受插件代码。v4 的 JS/CSS/Wasm 默认仍只校验、缓存,不执行。Wasm 开发原型只在用户显式授权、摘要匹配时通过有界解释器启动一次性任务,当前唯一可用的数据权限为 `session.status.read`;尚无频道/成员数据投影、宿主动作桥或页面生命周期集成。不要将有 DOM 的 iframe 当作网络沙箱:sandbox 不阻止 iframe 自己导航,`navigate-to` 也不能作为跨浏览器安全保证;获批数据可能被编码到导航 URL。完整运行时需要同时保留自定义 UI/交互能力,并通过有资源边界的执行环境和可信宿主渲染/权限桥解决,不可退回固定原生控件目录。
|
||||
`plugins.json` 不超过 256 KiB;每个入口 JS 或 Wasm 不超过 256 KiB,每个样式 CSS 不超过 512 KiB;每个插件最多声明 32 个素材。客户端导入会拒绝不符合固定内存、导入、导出和 Wasm 模块结构限制的入口。皮肤包整体仍受通用 ZIP 文件数、展开大小、图像和字体限额约束。v1–v3 不接受插件代码。v4 JavaScript 仍只校验、缓存,不执行。开发构建的 Wasm 原型仅在用户显式授权、摘要匹配时通过有界解释器启动一次性任务;目前接入权限为 `session.status.read` 和 `ui.surface.replace`,但尚无频道/成员/聊天数据投影或宿主动作桥。页面生命周期、输出渲染和插件 CSS 已接入开发 WebClient;生产构建保持关闭。不要将有 DOM 的 iframe 当作网络沙箱:sandbox 不阻止 iframe 自己导航,`navigate-to` 也不能作为跨浏览器安全保证;获批数据可能被编码到导航 URL。完整运行时需要同时保留自定义 UI/交互能力,并通过有资源边界的执行环境和可信宿主渲染/权限桥解决,不可退回固定原生控件目录。
|
||||
|
||||
当前描述还没有 widget 挂载点、排序、显隐或实例布局字段,完整运行时阶段需要明确这些由皮肤作者还是本地用户管理;不能让一个插件越过自身宿主节点去调整其他插件或宿主恢复控件。
|
||||
当前描述还没有 widget 挂载点、排序、显隐或实例布局字段,完整运行时阶段需要明确这些由皮肤作者还是本地用户管理;不能让一个插件越过自身宿主节点去调整其他插件或宿主恢复控件。开发态 v4 host 已按 descriptor 管理当前页 widget/surface、授权、输出、事件循环、样式和清理,但还没有持久化的多插件布局界面。
|
||||
|
||||
## 首页内容和文案
|
||||
|
||||
|
||||
@@ -50,6 +50,10 @@ test("v4 plugin descriptors recognize Wasm entries and reject a runtime/file mis
|
||||
() => parseSkinRuntimePluginDocument(document([{ ...plugin, runtime: "native" }]) as never),
|
||||
(error: unknown) => error instanceof SkinRuntimePluginValidationError && error.code === "SKIN_RUNTIME_PLUGIN_RUNTIME_INVALID",
|
||||
);
|
||||
assert.throws(
|
||||
() => parseSkinRuntimePluginDocument(document([{ ...plugin, permissions: ["ui.surface.replace"] }]) as never),
|
||||
(error: unknown) => error instanceof SkinRuntimePluginValidationError && error.code === "SKIN_RUNTIME_PLUGIN_PERMISSION_INVALID",
|
||||
);
|
||||
});
|
||||
|
||||
test("surface replacement is an explicit page-scoped plugin capability", () => {
|
||||
|
||||
@@ -136,6 +136,9 @@ export function parseSkinRuntimePluginDocument(input: unknown): SkinRuntimePlugi
|
||||
if (raw.mode === "surface" && !permissions.includes("ui.surface.replace")) {
|
||||
invalid("SKIN_RUNTIME_PLUGIN_PERMISSION_MISSING", "A surface plugin requires ui.surface.replace.");
|
||||
}
|
||||
if (raw.mode !== "surface" && permissions.includes("ui.surface.replace")) {
|
||||
invalid("SKIN_RUNTIME_PLUGIN_PERMISSION_INVALID", "Only a surface plugin may request ui.surface.replace.");
|
||||
}
|
||||
|
||||
for (const path of [entry, ...(style ? [style] : []), ...assets]) {
|
||||
const normalized = path.toLowerCase();
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
parseSkinPluginDocument,
|
||||
type SkinPluginActionDefinition,
|
||||
type SkinPluginComponent,
|
||||
type SkinPluginComponentMode,
|
||||
type SkinPluginDocument,
|
||||
type SkinPluginHostWidget,
|
||||
type SkinPluginNode,
|
||||
@@ -32,7 +33,10 @@ export default defineComponent({
|
||||
skinId: { type: String, required: true },
|
||||
skinVersion: { type: String, required: true },
|
||||
document: { type: Object as PropType<SkinPluginDocument>, required: true },
|
||||
extensionOutput: { type: String, default: null },
|
||||
extensionOutput: { type: String as PropType<string | null>, default: null },
|
||||
extensionMode: { type: String as PropType<SkinPluginComponentMode | undefined>, default: undefined },
|
||||
componentNamespace: { type: String, default: "" },
|
||||
manageSurfaceRecovery: { type: Boolean, default: true },
|
||||
page: { type: String as PropType<"home" | "voice" | "demo">, required: true },
|
||||
data: { type: Object as PropType<SafeContext>, required: true },
|
||||
assets: { type: Object as PropType<Record<string, Blob>>, required: true },
|
||||
@@ -57,7 +61,10 @@ export default defineComponent({
|
||||
catch { return { schemaVersion: 2 as const, components: [] }; }
|
||||
if (!props.extensionOutput || document.schemaVersion !== 3) return document;
|
||||
try {
|
||||
const extensionDocument = parseSkinExtensionUiOutput(props.extensionOutput);
|
||||
const parsedExtensionDocument = parseSkinExtensionUiOutput(props.extensionOutput);
|
||||
const extensionDocument = props.extensionMode
|
||||
? { ...parsedExtensionDocument, components: parsedExtensionDocument.components.map((component) => ({ ...component, mode: props.extensionMode })) }
|
||||
: parsedExtensionDocument;
|
||||
const ids = new Set(document.components.map((component) => component.id));
|
||||
if (document.components.length + extensionDocument.components.length > SKIN_PLUGIN_COMPONENT_LIMIT
|
||||
|| extensionDocument.components.some((component) => ids.has(component.id))) return document;
|
||||
@@ -84,7 +91,7 @@ export default defineComponent({
|
||||
const renderedComponents = computed(() => activeComponents.value.filter((component) =>
|
||||
component.mode !== "surface" || component !== surfaceCandidate.value || !surfaceSuppressed.value));
|
||||
|
||||
watch(() => [props.skinId, props.skinVersion, props.document, props.extensionOutput, props.page], () => {
|
||||
watch(() => [props.skinId, props.skinVersion, props.document, props.extensionOutput, props.extensionMode, props.componentNamespace, props.page], () => {
|
||||
denied.value = false;
|
||||
surfaceSuppressed.value = false;
|
||||
refresh.value += 1;
|
||||
@@ -185,7 +192,8 @@ export default defineComponent({
|
||||
|| ["click", "dblclick", "contextmenu", "keydown", "keyup", "pointerdown", "pointerup", "drop"]
|
||||
.some((eventName) => Boolean(node.events?.[eventName as keyof typeof node.events]));
|
||||
const part = node.part ? `part-${node.part}` : nodePath;
|
||||
return `skin.${component.page}.${component.id}.${interactive ? "control-" : ""}${part}`;
|
||||
const componentPath = props.componentNamespace ? `${props.componentNamespace}.${component.id}` : component.id;
|
||||
return `skin.${component.page}.${componentPath}.${interactive ? "control-" : ""}${part}`;
|
||||
}
|
||||
|
||||
function renderNode(component: SkinPluginComponent, node: SkinPluginNode, context: SafeContext, state: Record<string, Scalar>, budget: { remaining: number }, skipRepeat = false, nodePath = "node-root"): VNodeChild {
|
||||
@@ -235,7 +243,8 @@ export default defineComponent({
|
||||
if (node.className || attrs.class) {
|
||||
attrs.class = ["ws-plugin-node", node.className, attrs.class].filter(Boolean).join(" ");
|
||||
} else attrs.class = "ws-plugin-node";
|
||||
attrs["data-ws-plugin-part"] = node.part ? `${component.id}.${node.part}` : component.id;
|
||||
const componentPath = props.componentNamespace ? `${props.componentNamespace}.${component.id}` : component.id;
|
||||
attrs["data-ws-plugin-part"] = node.part ? `${componentPath}.${node.part}` : componentPath;
|
||||
attrs["data-ws-part"] = layoutPart(component, node, nodePath);
|
||||
if (node.bindValue) attrs.value = state[node.bindValue];
|
||||
|
||||
@@ -305,10 +314,11 @@ export default defineComponent({
|
||||
const nodes: VNodeChild[] = renderedComponents.value.map((component) => h("div", {
|
||||
key: `${props.skinId}:${component.id}`,
|
||||
class: ["ws-plugin-component", component.mode === "surface" && "ws-plugin-surface"],
|
||||
"data-ws-plugin-component": component.id,
|
||||
"data-ws-plugin-component": props.componentNamespace ? `${props.componentNamespace}.${component.id}` : component.id,
|
||||
"data-ws-plugin-name": component.name,
|
||||
"data-ws-plugin-part": component.id,
|
||||
"data-ws-part": `skin.${component.page}.${component.id}`,
|
||||
"data-ws-plugin-part": props.componentNamespace ? `${props.componentNamespace}.${component.id}` : component.id,
|
||||
"data-ws-part": `skin.${component.page}.${props.componentNamespace ? `${props.componentNamespace}.` : ""}${component.id}`,
|
||||
...(props.componentNamespace ? { "data-ws-runtime-plugin": props.componentNamespace } : {}),
|
||||
...(component.mode === "surface" ? { "data-ws-plugin-surface": component.page } : {}),
|
||||
"aria-label": component.accessibleName,
|
||||
}, [renderNode(component, component.root, props.data, localState(component), { remaining: SKIN_PLUGIN_RENDER_NODE_LIMIT })]));
|
||||
@@ -320,13 +330,13 @@ export default defineComponent({
|
||||
"aria-label": "管理皮肤组件权限 / Manage skin component access",
|
||||
onClick: openAccessManager,
|
||||
}, "权限 / Access")]) : null;
|
||||
const surfaceRecovery = activeSurface.value ? h(Teleport, { to: "body" }, [h("button", {
|
||||
const surfaceRecovery = activeSurface.value && props.manageSurfaceRecovery ? h(Teleport, { to: "body" }, [h("button", {
|
||||
type: "button",
|
||||
class: "ws-plugin-surface-recovery",
|
||||
"aria-label": "返回 WebSpeak 标准界面 / Return to the built-in interface",
|
||||
onClick: () => { surfaceSuppressed.value = true; },
|
||||
}, "标准界面 / Built-in UI")]) : null;
|
||||
const skinRecovery = activeSurface.value ? h(Teleport, { to: "body" }, [h("button", {
|
||||
const skinRecovery = activeSurface.value && props.manageSurfaceRecovery ? h(Teleport, { to: "body" }, [h("button", {
|
||||
type: "button",
|
||||
class: "ws-plugin-surface-reset",
|
||||
"aria-label": "恢复内置皮肤 / Restore the built-in skin",
|
||||
|
||||
@@ -0,0 +1,384 @@
|
||||
import { computed, defineComponent, h, onUnmounted, ref, Teleport, watch, type PropType, type VNodeChild } from "vue";
|
||||
import type { SkinExtensionSessionStatus } from "../../../src/shared/skin-extension.js";
|
||||
import { computeSkinRuntimePluginDigest, createSkinRuntimePluginApproval, isSkinRuntimePluginApproved, type SkinRuntimePluginApproval } from "../../../src/shared/skin-runtime-plugin-approval.js";
|
||||
import type { SkinRuntimePlugin, SkinRuntimePluginDocument, SkinRuntimePluginPage } from "../../../src/shared/skin-runtime-plugins.js";
|
||||
import { parseSkinExtensionUiInput, type SkinExtensionUiInput } from "../../../src/shared/skin-extension-ui-input.js";
|
||||
import type { SkinPluginDocument } from "../../../src/shared/skin-plugin.js";
|
||||
import SkinPluginOutlet from "./SkinPluginOutlet.js";
|
||||
import { approveSkinRuntimePlugin, getSkinRuntimePluginApproval, revokeSkinRuntimePluginApprovals } from "../services/skin-runtime-plugin-approval.js";
|
||||
import { createSkinRuntimePluginSession } from "../services/skin-runtime-plugin-session.js";
|
||||
import { createSkinRuntimePluginWasmSandboxPrototype } from "../services/skin-runtime-plugin-wasm.js";
|
||||
import type { SkinExtensionWasmSandboxHandle } from "../services/skin-extension-wasm-sandbox.js";
|
||||
import { resolveSkinCssAssets } from "../services/skin-pack.js";
|
||||
|
||||
const EMPTY_DOCUMENT: SkinPluginDocument = { schemaVersion: 3, components: [] };
|
||||
const SUPPORTED_PERMISSIONS = new Set(["session.status.read", "ui.surface.replace"]);
|
||||
|
||||
type Session = ReturnType<typeof createSkinRuntimePluginSession>;
|
||||
type RunHandle = { result: Promise<{ uiOutput: string | null }>; close(reason?: string): void };
|
||||
|
||||
function isSupported(plugin: SkinRuntimePlugin): boolean {
|
||||
return import.meta.env.DEV && plugin.runtime === "wasm"
|
||||
&& plugin.permissions.every((permission) => SUPPORTED_PERMISSIONS.has(permission));
|
||||
}
|
||||
|
||||
function pluginReason(plugin: SkinRuntimePlugin): string {
|
||||
if (!import.meta.env.DEV) return "The Wasm runtime prototype is disabled in production builds. / Wasm 运行时原型在生产构建中保持关闭。";
|
||||
if (plugin.runtime !== "wasm") return "JavaScript plugins are not enabled. / JavaScript 插件尚未启用。";
|
||||
const permission = plugin.permissions.find((candidate) => !SUPPORTED_PERMISSIONS.has(candidate));
|
||||
return permission
|
||||
? `This prototype does not implement ${permission}. / 当前原型尚未实现 ${permission}。`
|
||||
: "";
|
||||
}
|
||||
|
||||
function createRun(
|
||||
skinId: string,
|
||||
skinVersion: string,
|
||||
plugin: SkinRuntimePlugin,
|
||||
approval: SkinRuntimePluginApproval,
|
||||
files: Readonly<Record<string, Blob>>,
|
||||
readSessionStatus: (signal: AbortSignal) => SkinExtensionSessionStatus | Promise<SkinExtensionSessionStatus>,
|
||||
input: SkinExtensionUiInput,
|
||||
): RunHandle {
|
||||
let sandbox: SkinExtensionWasmSandboxHandle | null = null;
|
||||
let cancelled = false;
|
||||
const result = (async () => {
|
||||
const nextSandbox = await createSkinRuntimePluginWasmSandboxPrototype({
|
||||
skinId,
|
||||
skinVersion,
|
||||
plugin,
|
||||
approval,
|
||||
files,
|
||||
uiInput: input,
|
||||
readSessionStatus,
|
||||
prototypeOnly: true,
|
||||
});
|
||||
if (cancelled) {
|
||||
nextSandbox.close("page-or-skin-changed");
|
||||
throw new Error("Plugin run was closed before startup.");
|
||||
}
|
||||
sandbox = nextSandbox;
|
||||
await nextSandbox.ready;
|
||||
const outcome = await nextSandbox.result;
|
||||
return { uiOutput: outcome.uiOutput };
|
||||
})();
|
||||
return {
|
||||
result,
|
||||
close(reason) {
|
||||
cancelled = true;
|
||||
sandbox?.close(reason);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: "SkinRuntimePluginHost",
|
||||
props: {
|
||||
skinId: { type: String, required: true },
|
||||
skinVersion: { type: String, required: true },
|
||||
plugins: { type: Object as PropType<SkinRuntimePluginDocument | undefined>, default: undefined },
|
||||
files: { type: Object as PropType<Record<string, Blob>>, default: () => ({}) },
|
||||
styles: { type: Object as PropType<Record<string, string>>, default: () => ({}) },
|
||||
assets: { type: Object as PropType<Record<string, Blob>>, default: () => ({}) },
|
||||
page: { type: String as PropType<SkinRuntimePluginPage>, required: true },
|
||||
readSessionStatus: { type: Function as PropType<(signal: AbortSignal) => SkinExtensionSessionStatus | Promise<SkinExtensionSessionStatus>>, required: true },
|
||||
},
|
||||
emits: {
|
||||
"surface-change": (_active: boolean) => typeof _active === "boolean",
|
||||
"restore-skin": () => true,
|
||||
},
|
||||
setup(props, { emit }) {
|
||||
const digests = ref<Record<string, string>>({});
|
||||
const digestErrors = ref<Record<string, string>>({});
|
||||
const revision = ref(0);
|
||||
const managerOpen = ref(false);
|
||||
const denied = ref(new Set<string>());
|
||||
const inMemoryApprovals = new Map<string, SkinRuntimePluginApproval>();
|
||||
const sessions = new Map<string, Session>();
|
||||
const stylesByPlugin = new Map<string, { element: HTMLStyleElement; objectUrls: string[] }>();
|
||||
const outputs = ref<Record<string, string | null>>({});
|
||||
const surfaces = ref(new Set<string>());
|
||||
const suppressedSurfaces = ref(new Set<string>());
|
||||
let digestRun = 0;
|
||||
let disposed = false;
|
||||
|
||||
const pagePlugins = computed(() => props.plugins?.plugins.filter((plugin) => plugin.page === props.page) ?? []);
|
||||
const approved = (plugin: SkinRuntimePlugin): SkinRuntimePluginApproval | null => {
|
||||
const digest = digests.value[plugin.id];
|
||||
if (!digest) return null;
|
||||
const memoryGrant = inMemoryApprovals.get(plugin.id);
|
||||
if (memoryGrant && isSkinRuntimePluginApproved(memoryGrant, props.skinId, props.skinVersion, plugin, digest)) return memoryGrant;
|
||||
return getSkinRuntimePluginApproval(props.skinId, props.skinVersion, plugin, digest);
|
||||
};
|
||||
const pending = computed(() => {
|
||||
revision.value;
|
||||
return pagePlugins.value.filter((plugin) => isSupported(plugin) && !approved(plugin) && !denied.value.has(plugin.id));
|
||||
});
|
||||
const activeSurface = computed(() => pagePlugins.value.some((plugin) => plugin.mode === "surface"
|
||||
&& surfaces.value.has(plugin.id) && !suppressedSurfaces.value.has(plugin.id)));
|
||||
|
||||
function publishSurfaceState(): void {
|
||||
emit("surface-change", activeSurface.value);
|
||||
}
|
||||
|
||||
function removeStyle(pluginId: string): void {
|
||||
const style = stylesByPlugin.get(pluginId);
|
||||
if (!style) return;
|
||||
style.element.remove();
|
||||
style.objectUrls.forEach((url) => URL.revokeObjectURL(url));
|
||||
stylesByPlugin.delete(pluginId);
|
||||
}
|
||||
|
||||
function stopPlugin(pluginId: string, reason: string): void {
|
||||
sessions.get(pluginId)?.close(reason);
|
||||
sessions.delete(pluginId);
|
||||
outputs.value = { ...outputs.value, [pluginId]: null };
|
||||
surfaces.value.delete(pluginId);
|
||||
suppressedSurfaces.value.delete(pluginId);
|
||||
removeStyle(pluginId);
|
||||
publishSurfaceState();
|
||||
}
|
||||
|
||||
function stopAll(reason: string): void {
|
||||
for (const pluginId of [...sessions.keys()]) stopPlugin(pluginId, reason);
|
||||
for (const pluginId of [...stylesByPlugin.keys()]) removeStyle(pluginId);
|
||||
outputs.value = {};
|
||||
surfaces.value = new Set();
|
||||
suppressedSurfaces.value = new Set();
|
||||
publishSurfaceState();
|
||||
}
|
||||
|
||||
function pluginStyleAssets(plugin: SkinRuntimePlugin): Record<string, Blob> {
|
||||
const ownPrefix = `plugins/${plugin.id}/assets/`;
|
||||
return Object.fromEntries(Object.entries(props.assets).filter(([path]) => path.startsWith("assets/") || path.startsWith(ownPrefix)));
|
||||
}
|
||||
|
||||
function installStyle(plugin: SkinRuntimePlugin): void {
|
||||
removeStyle(plugin.id);
|
||||
const css = props.styles[plugin.id];
|
||||
if (!css) return;
|
||||
const resolved = resolveSkinCssAssets(css, pluginStyleAssets(plugin));
|
||||
const element = document.createElement("style");
|
||||
element.dataset.wsRuntimePluginStyle = plugin.id;
|
||||
element.textContent = resolved.css;
|
||||
document.head.append(element);
|
||||
stylesByPlugin.set(plugin.id, { element, objectUrls: resolved.objectUrls });
|
||||
}
|
||||
|
||||
function outputAssets(plugin: SkinRuntimePlugin): Record<string, Blob> {
|
||||
const result: Record<string, Blob> = Object.create(null) as Record<string, Blob>;
|
||||
const prefix = `plugins/${plugin.id}/assets/`;
|
||||
for (const path of plugin.assets) {
|
||||
const relative = path.slice(prefix.length);
|
||||
const blob = props.assets[path];
|
||||
if (blob) result[`assets/${relative}`] = blob;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function onRuntimeError(pluginId: string): void {
|
||||
if (disposed) return;
|
||||
stopPlugin(pluginId, "runtime-error");
|
||||
digestErrors.value = { ...digestErrors.value, [pluginId]: "The plugin stopped safely. / 插件已安全停止。" };
|
||||
}
|
||||
|
||||
function startPlugin(plugin: SkinRuntimePlugin, grant: SkinRuntimePluginApproval): void {
|
||||
if (sessions.has(plugin.id) || !isSupported(plugin)) return;
|
||||
const session = createSkinRuntimePluginSession({
|
||||
plugin,
|
||||
createRun: (input) => createRun(props.skinId, props.skinVersion, plugin, grant, props.files, props.readSessionStatus, input),
|
||||
onOutput: () => {
|
||||
installStyle(plugin);
|
||||
outputs.value = { ...outputs.value, [plugin.id]: session.output };
|
||||
digestErrors.value = { ...digestErrors.value, [plugin.id]: "" };
|
||||
},
|
||||
onError: () => onRuntimeError(plugin.id),
|
||||
});
|
||||
sessions.set(plugin.id, session);
|
||||
void session.start().then((started) => {
|
||||
if (!started && sessions.get(plugin.id) === session) onRuntimeError(plugin.id);
|
||||
}).catch(() => onRuntimeError(plugin.id));
|
||||
}
|
||||
|
||||
function reconcile(): void {
|
||||
if (disposed) return;
|
||||
const currentIds = new Set(pagePlugins.value.map((plugin) => plugin.id));
|
||||
for (const pluginId of [...sessions.keys()]) if (!currentIds.has(pluginId)) stopPlugin(pluginId, "page-changed");
|
||||
for (const plugin of pagePlugins.value) {
|
||||
const grant = approved(plugin);
|
||||
if (grant && isSupported(plugin)) startPlugin(plugin, grant);
|
||||
}
|
||||
}
|
||||
|
||||
function approvePending(): void {
|
||||
for (const plugin of pending.value) {
|
||||
const digest = digests.value[plugin.id];
|
||||
if (!digest) continue;
|
||||
approveSkinRuntimePlugin(props.skinId, props.skinVersion, plugin, digest);
|
||||
const stored = getSkinRuntimePluginApproval(props.skinId, props.skinVersion, plugin, digest);
|
||||
inMemoryApprovals.set(plugin.id, stored ?? createSkinRuntimePluginApproval(props.skinId, props.skinVersion, plugin, digest));
|
||||
}
|
||||
denied.value = new Set([...denied.value].filter((id) => !pending.value.some((plugin) => plugin.id === id)));
|
||||
managerOpen.value = false;
|
||||
revision.value += 1;
|
||||
reconcile();
|
||||
}
|
||||
|
||||
function keepDisabled(): void {
|
||||
denied.value = new Set([...denied.value, ...pending.value.map((plugin) => plugin.id)]);
|
||||
managerOpen.value = false;
|
||||
}
|
||||
|
||||
function revokeAll(): void {
|
||||
revokeSkinRuntimePluginApprovals(props.skinId);
|
||||
for (const plugin of props.plugins?.plugins ?? []) inMemoryApprovals.delete(plugin.id);
|
||||
denied.value = new Set((props.plugins?.plugins ?? []).filter(isSupported).map((plugin) => plugin.id));
|
||||
stopAll("approval-revoked");
|
||||
managerOpen.value = false;
|
||||
revision.value += 1;
|
||||
}
|
||||
|
||||
function openManager(): void {
|
||||
managerOpen.value = true;
|
||||
}
|
||||
|
||||
function dispatch(pluginId: string, value: unknown): void {
|
||||
if (!value || typeof value !== "object") return;
|
||||
const input = (value as Record<string, unknown>).input;
|
||||
const session = sessions.get(pluginId);
|
||||
if (session && input) void session.dispatch(input);
|
||||
}
|
||||
|
||||
function surfaceChanged(pluginId: string, active: boolean): void {
|
||||
if (active) surfaces.value.add(pluginId);
|
||||
else surfaces.value.delete(pluginId);
|
||||
publishSurfaceState();
|
||||
}
|
||||
|
||||
function toggleSurface(pluginId: string): void {
|
||||
const next = new Set(suppressedSurfaces.value);
|
||||
if (next.has(pluginId)) next.delete(pluginId);
|
||||
else next.add(pluginId);
|
||||
suppressedSurfaces.value = next;
|
||||
publishSurfaceState();
|
||||
}
|
||||
|
||||
watch(() => [props.skinId, props.skinVersion, props.plugins, props.files], async () => {
|
||||
const currentRun = ++digestRun;
|
||||
stopAll("skin-changed");
|
||||
inMemoryApprovals.clear();
|
||||
denied.value = new Set();
|
||||
managerOpen.value = false;
|
||||
digests.value = {};
|
||||
digestErrors.value = {};
|
||||
const plugins = props.plugins?.plugins ?? [];
|
||||
const nextDigests: Record<string, string> = Object.create(null) as Record<string, string>;
|
||||
const nextErrors: Record<string, string> = Object.create(null) as Record<string, string>;
|
||||
await Promise.all(plugins.map(async (plugin) => {
|
||||
try { nextDigests[plugin.id] = await computeSkinRuntimePluginDigest(plugin, props.files); }
|
||||
catch { nextErrors[plugin.id] = "The package files could not be verified. / 无法校验插件文件。"; }
|
||||
}));
|
||||
if (disposed || currentRun !== digestRun) return;
|
||||
digests.value = nextDigests;
|
||||
digestErrors.value = nextErrors;
|
||||
revision.value += 1;
|
||||
reconcile();
|
||||
}, { immediate: true });
|
||||
|
||||
watch(() => [props.page, digests.value, revision.value], reconcile, { deep: true });
|
||||
watch(activeSurface, publishSurfaceState, { flush: "sync" });
|
||||
onUnmounted(() => {
|
||||
disposed = true;
|
||||
digestRun += 1;
|
||||
stopAll("host-unmounted");
|
||||
});
|
||||
|
||||
return () => {
|
||||
const currentPlugins = pagePlugins.value;
|
||||
const nodes: VNodeChild[] = [];
|
||||
for (const plugin of currentPlugins) {
|
||||
const generatedOutput = suppressedSurfaces.value.has(plugin.id) ? null : outputs.value[plugin.id] ?? null;
|
||||
const pluginAssets = outputAssets(plugin);
|
||||
nodes.push(h(SkinPluginOutlet, {
|
||||
key: `${props.skinId}:${plugin.id}:${props.page}`,
|
||||
skinId: props.skinId,
|
||||
skinVersion: props.skinVersion,
|
||||
document: EMPTY_DOCUMENT,
|
||||
extensionOutput: generatedOutput,
|
||||
extensionMode: plugin.mode,
|
||||
componentNamespace: plugin.id,
|
||||
manageSurfaceRecovery: false,
|
||||
page: props.page,
|
||||
data: {},
|
||||
assets: pluginAssets,
|
||||
actions: {},
|
||||
onExtensionEvent: (event: unknown) => dispatch(plugin.id, event),
|
||||
onSurfaceChange: (active: boolean) => surfaceChanged(plugin.id, active),
|
||||
onRestoreSkin: () => emit("restore-skin"),
|
||||
}));
|
||||
}
|
||||
|
||||
const controls: VNodeChild[] = [];
|
||||
if (currentPlugins.length) {
|
||||
controls.push(h(Teleport, { to: "body" }, [h("button", {
|
||||
type: "button",
|
||||
class: "ws-plugin-access-toggle",
|
||||
"aria-label": "管理运行时插件权限 / Manage runtime plugin access",
|
||||
onClick: openManager,
|
||||
}, "插件权限 / Plugin access")]));
|
||||
}
|
||||
for (const plugin of currentPlugins) {
|
||||
if (plugin.mode !== "surface" || !outputs.value[plugin.id]) continue;
|
||||
const suppressed = suppressedSurfaces.value.has(plugin.id);
|
||||
controls.push(h(Teleport, { to: "body" }, [h("button", {
|
||||
type: "button",
|
||||
class: "ws-plugin-surface-recovery",
|
||||
"aria-label": suppressed ? "恢复自定义界面 / Restore custom interface" : "返回 WebSpeak 标准界面 / Return to built-in interface",
|
||||
onClick: () => toggleSurface(plugin.id),
|
||||
}, suppressed ? "恢复自定义界面 / Restore custom UI" : "标准界面 / Built-in UI")]));
|
||||
controls.push(h(Teleport, { to: "body" }, [h("button", {
|
||||
type: "button",
|
||||
class: "ws-plugin-surface-reset",
|
||||
"aria-label": "恢复内置皮肤 / Restore the built-in skin",
|
||||
onClick: () => emit("restore-skin"),
|
||||
}, "恢复内置皮肤 / Reset skin")]));
|
||||
}
|
||||
|
||||
const showConsent = pending.value.length > 0 || managerOpen.value;
|
||||
if (!showConsent) return h("div", { class: "ws-runtime-plugin-host" }, [...nodes, ...controls]);
|
||||
|
||||
const showApproval = pending.value.length > 0;
|
||||
const listed = showApproval ? pending.value : currentPlugins;
|
||||
const consent = h(Teleport, { to: "body" }, [h("div", { class: "ws-plugin-consent-backdrop", "data-ws-runtime-plugin-consent": "true" }, [
|
||||
h("section", { class: "ws-plugin-consent", role: "dialog", "aria-modal": "true", "aria-labelledby": "ws-runtime-plugin-consent-title" }, [
|
||||
h("h2", { id: "ws-runtime-plugin-consent-title" }, showApproval ? "运行时插件授权 / Runtime plugin approval" : "运行时插件权限 / Runtime plugin access"),
|
||||
h("p", null, "插件只在隔离的 Wasm Worker 中运行。每次执行均有时限和内存上限;插件不能访问网络、存储、连接地址、密码或身份材料。/ Plugins run in a bounded Wasm worker and cannot access network, storage, connection targets, passwords, or identity material."),
|
||||
...listed.map((plugin) => {
|
||||
const grant = approved(plugin);
|
||||
const error = digestErrors.value[plugin.id];
|
||||
const unsupported = pluginReason(plugin);
|
||||
const status = error || unsupported || (grant ? "已授权 / Approved" : "等待授权 / Approval required");
|
||||
return h("div", { class: "ws-plugin-consent-item", key: plugin.id }, [
|
||||
h("strong", null, `${plugin.name} · ${plugin.mode === "surface" ? "整页界面 / surface" : "组件 / widget"}`),
|
||||
h("ul", null, [
|
||||
...plugin.permissions.map((permission) => h("li", { key: permission }, permission)),
|
||||
h("li", { key: "status" }, status),
|
||||
]),
|
||||
]);
|
||||
}),
|
||||
h("p", { class: "ws-plugin-consent-note" }, "当前开发原型仅支持 Wasm、session.status.read 和 ui.surface.replace;授权绑定到此皮肤版本、插件清单和所有插件文件的 SHA-256。/ This development prototype supports Wasm, session.status.read, and ui.surface.replace only. Approval is bound to this skin version, descriptor, and every plugin file by SHA-256."),
|
||||
h("div", { class: "ws-plugin-consent-actions" }, showApproval
|
||||
? [
|
||||
h("button", { type: "button", class: "secondary", onClick: keepDisabled }, "暂不启用 / Keep disabled"),
|
||||
h("button", { type: "button", class: "primary", disabled: listed.some((plugin) => !digests.value[plugin.id] || Boolean(digestErrors.value[plugin.id])) || listed.some((plugin) => !isSupported(plugin)), onClick: approvePending }, "批准所列插件 / Approve listed plugins"),
|
||||
]
|
||||
: [
|
||||
h("button", { type: "button", class: "secondary", onClick: revokeAll }, "撤销全部授权 / Revoke all access"),
|
||||
h("button", { type: "button", class: "primary", onClick: () => { managerOpen.value = false; } }, "关闭 / Close"),
|
||||
]),
|
||||
]),
|
||||
])]);
|
||||
return h("div", { class: "ws-runtime-plugin-host" }, [...nodes, ...controls, consent]);
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -385,7 +385,9 @@ test("schema version 4 validates and caches isolated plugin package files withou
|
||||
assert.equal(await skin.runtimePluginFiles?.[entry].text(), "export const render = () => document.createElement('button');");
|
||||
assert.equal(await skin.runtimePluginFiles?.[style].text(), ".toolbar { color: teal; }");
|
||||
assert.equal(skin.runtimePluginFiles?.[icon].type, "image/png");
|
||||
assert.equal(skin.assets[icon], undefined, "plugin assets stay in the isolated plugin file set");
|
||||
assert.equal(skin.assets[icon]?.type, "image/png", "declared plugin media is available only by its package path for scoped CSS and host remapping");
|
||||
assert.match(skin.runtimePluginStyles?.["voice-toolbar"] ?? "", /data-ws-runtime-plugin="voice-toolbar".*?\.toolbar/s);
|
||||
assert.match(skin.runtimePluginStyles?.["voice-toolbar"] ?? "", /color: teal/);
|
||||
assert.match(skin.css, /position: fixed/);
|
||||
|
||||
await assert.rejects(
|
||||
@@ -402,6 +404,49 @@ test("schema version 4 validates and caches isolated plugin package files withou
|
||||
);
|
||||
});
|
||||
|
||||
test("a v4 surface cannot compete with a v3 surface on the same public page", async () => {
|
||||
const components = {
|
||||
schemaVersion: 2,
|
||||
components: [{
|
||||
id: "voice-v3-surface",
|
||||
name: "Voice v3 surface",
|
||||
page: "voice",
|
||||
mode: "surface",
|
||||
accessibleName: "Voice workspace",
|
||||
permissions: ["ui.surface.replace"],
|
||||
actions: {},
|
||||
root: { tag: "main", children: [{ tag: "p", children: [{ text: "replacement UI" }] }] },
|
||||
}],
|
||||
};
|
||||
const plugins = {
|
||||
schemaVersion: 1,
|
||||
plugins: [{
|
||||
id: "voice-v4-surface",
|
||||
name: "Voice v4 surface",
|
||||
version: "1.0.0",
|
||||
apiVersion: 1,
|
||||
runtime: "wasm",
|
||||
page: "voice",
|
||||
mode: "surface",
|
||||
entry: "plugins/voice-v4-surface/index.wasm",
|
||||
assets: [],
|
||||
permissions: ["ui.surface.replace"],
|
||||
}],
|
||||
};
|
||||
const files = {
|
||||
"manifest.json": strToU8(JSON.stringify({ ...manifest, schemaVersion: 4, packageType: "open-skin", components: "components.json", plugins: "plugins.json" })),
|
||||
"skin.css": strToU8('[data-ws-part="app"] { color: teal; }'),
|
||||
"components.json": strToU8(JSON.stringify(components)),
|
||||
"plugins.json": strToU8(JSON.stringify(plugins)),
|
||||
"plugins/voice-v4-surface/index.wasm": createSkinExtensionWasmPrefixByteImmediateProbe(),
|
||||
};
|
||||
const archive = zipSync(files);
|
||||
await assert.rejects(
|
||||
importSkinPack(new File([archive.slice().buffer as ArrayBuffer], "competing-surfaces.wskin")),
|
||||
(error: unknown) => error instanceof SkinPackError && error.code === "SKIN_PLUGIN_SURFACE_DUPLICATE",
|
||||
);
|
||||
});
|
||||
|
||||
test("the distributable KAAK v3 package validates end to end", async () => {
|
||||
const archive = await readFile(new URL("../../../docs/examples/kaak-voice.wskin", import.meta.url));
|
||||
const file = new File([archive], "kaak-voice.wskin", { type: "application/octet-stream" });
|
||||
|
||||
@@ -109,6 +109,7 @@ export interface InstalledSkin extends SkinManifest {
|
||||
pluginData?: SkinPluginDocument;
|
||||
runtimePlugins?: SkinRuntimePluginDocument;
|
||||
runtimePluginFiles?: Record<string, Blob>;
|
||||
runtimePluginStyles?: Record<string, string>;
|
||||
previewBlob?: Blob;
|
||||
warnings: string[];
|
||||
installedAt: number;
|
||||
@@ -177,6 +178,7 @@ export async function importSkinPack(file: File): Promise<InstalledSkin> {
|
||||
}
|
||||
|
||||
const runtimePluginFiles: Record<string, Blob> = Object.create(null) as Record<string, Blob>;
|
||||
const assets: Record<string, Blob> = Object.create(null) as Record<string, Blob>;
|
||||
const runtimePluginPaths = runtimePlugins ? listSkinRuntimePluginFilePaths(runtimePlugins) : [];
|
||||
const runtimePluginPathSet = new Set(runtimePluginPaths.map((path) => path.toLowerCase()));
|
||||
const manifestPathSet = ["manifest.json", manifest.entry, manifest.layout, manifest.content, manifest.components, manifest.plugins, manifest.preview]
|
||||
@@ -213,10 +215,10 @@ export async function importSkinPack(file: File): Promise<InstalledSkin> {
|
||||
if (mimeType.startsWith("font/") && bytes.byteLength > MAX_FONT_BYTES) throw new SkinPackError("Plugin fonts must be smaller than 4 MiB.", "SKIN_FONT_SIZE");
|
||||
if (mimeType.startsWith("image/") && bytes.byteLength > MAX_IMAGE_BYTES) throw new SkinPackError("Plugin images must be smaller than 16 MiB.", "SKIN_IMAGE_SIZE");
|
||||
runtimePluginFiles[pluginPath] = new Blob([bytes], { type: mimeType });
|
||||
assets[pluginPath] = runtimePluginFiles[pluginPath];
|
||||
}
|
||||
}
|
||||
|
||||
const assets: Record<string, Blob> = Object.create(null) as Record<string, Blob>;
|
||||
for (const [path, bytes] of files) {
|
||||
if (["manifest.json", manifest.entry, manifest.layout, manifest.content, manifest.components, manifest.plugins].includes(path)
|
||||
|| runtimePluginPathSet.has(path.toLowerCase())) continue;
|
||||
@@ -227,6 +229,20 @@ export async function importSkinPack(file: File): Promise<InstalledSkin> {
|
||||
assets[path] = new Blob([bytes], { type: mimeType });
|
||||
}
|
||||
|
||||
const runtimePluginStyles: Record<string, string> = Object.create(null) as Record<string, string>;
|
||||
const runtimePluginWarnings: string[] = [];
|
||||
for (const plugin of runtimePlugins?.plugins ?? []) {
|
||||
if (!plugin.style) continue;
|
||||
const style = runtimePluginFiles[plugin.style];
|
||||
if (!style) throw new SkinPackError(`A declared plugin style is missing: ${plugin.style}`, "SKIN_RUNTIME_PLUGIN_FILE_MISSING");
|
||||
const pluginAssetPrefix = `plugins/${plugin.id}/assets/`;
|
||||
const pluginAssets = Object.fromEntries(Object.entries(assets).filter(([path]) =>
|
||||
path.startsWith("assets/") || path.startsWith(pluginAssetPrefix)));
|
||||
const compiledStyle = compileSkinCss(await style.text(), manifest.id, pluginAssets, manifest.schemaVersion, plugin.id);
|
||||
runtimePluginStyles[plugin.id] = compiledStyle.css;
|
||||
runtimePluginWarnings.push(...compiledStyle.warnings);
|
||||
}
|
||||
|
||||
let contentData: SkinContent | undefined;
|
||||
if (manifest.content) {
|
||||
const contentBytes = files.get(manifest.content);
|
||||
@@ -264,7 +280,24 @@ export async function importSkinPack(file: File): Promise<InstalledSkin> {
|
||||
}
|
||||
|
||||
const compiled = compileSkinCss(decoder.decode(cssBytes), manifest.id, assets, manifest.schemaVersion);
|
||||
return { ...manifest, css: compiled.css, assets, contentData, layoutData, pluginData, runtimePlugins, runtimePluginFiles, previewBlob, warnings: compiled.warnings, installedAt: Date.now() };
|
||||
const hasConflictingSurface = (pluginData?.components ?? []).some((component) => component.mode === "surface"
|
||||
&& runtimePlugins?.plugins.some((plugin) => plugin.mode === "surface" && plugin.page === component.page));
|
||||
if (hasConflictingSurface) throw new SkinPackError("A page cannot declare both a v3 and v4 surface.", "SKIN_PLUGIN_SURFACE_DUPLICATE");
|
||||
|
||||
return {
|
||||
...manifest,
|
||||
css: compiled.css,
|
||||
assets,
|
||||
contentData,
|
||||
layoutData,
|
||||
pluginData,
|
||||
runtimePlugins,
|
||||
runtimePluginFiles,
|
||||
runtimePluginStyles,
|
||||
previewBlob,
|
||||
warnings: [...compiled.warnings, ...runtimePluginWarnings],
|
||||
installedAt: Date.now(),
|
||||
};
|
||||
}
|
||||
|
||||
export function resolveSkinCssAssets(css: string, assets: Record<string, Blob>): { css: string; objectUrls: string[] } {
|
||||
@@ -527,15 +560,18 @@ function parseContent(bytes: Uint8Array): SkinContent {
|
||||
return { defaultLocale: root.defaultLocale, locales };
|
||||
}
|
||||
|
||||
function compileSkinCss(source: string, id: string, assets: Record<string, Blob>, schemaVersion: SkinManifest["schemaVersion"]): { css: string; warnings: string[] } {
|
||||
function compileSkinCss(source: string, id: string, assets: Record<string, Blob>, schemaVersion: SkinManifest["schemaVersion"], pluginId?: string): { css: string; warnings: string[] } {
|
||||
const size = new TextEncoder().encode(source).byteLength;
|
||||
if (!size || size > MAX_CSS_BYTES) throw new SkinPackError("The CSS entry must be between 1 byte and 512 KiB.", "SKIN_CSS_SIZE");
|
||||
let root: postcss.Root;
|
||||
try { root = postcss.parse(source, { from: undefined }); }
|
||||
catch (error) { throw new SkinPackError(`The CSS file could not be parsed: ${(error as Error).message}`, "SKIN_CSS_INVALID"); }
|
||||
|
||||
const scope = `.ws-skin-root[data-ws-skin="${id}"]`;
|
||||
const namespace = `ws-${id.replace(/[^a-z0-9_-]/gi, "-")}`;
|
||||
const skinScope = `.ws-skin-root[data-ws-skin="${id}"]`;
|
||||
const scope = pluginId
|
||||
? `${skinScope} .ws-plugin-component[data-ws-runtime-plugin="${pluginId}"]`
|
||||
: skinScope;
|
||||
const namespace = `ws-${id.replace(/[^a-z0-9_-]/gi, "-")}${pluginId ? `-${pluginId}` : ""}`;
|
||||
const scopeNodes = selectorParser().astSync(scope).first!.nodes.map((node) => node.clone());
|
||||
const warnings = new Set<string>();
|
||||
const keyframeNames = new Map<string, string>();
|
||||
@@ -575,7 +611,7 @@ function compileSkinCss(source: string, id: string, assets: Record<string, Blob>
|
||||
root.walkRules((rule: Rule) => {
|
||||
if (hasKeyframesAncestor(rule)) return;
|
||||
if (rule.parent?.type === "rule") throw rule.error("Nested style rules are not supported; use flat selectors.");
|
||||
if (!selectorUsesPublicHook(rule.selector, schemaVersion >= 3)) throw rule.error("Skin selectors must use :root, [data-ws-page], [data-ws-part], or [data-ws-plugin-part] so they stay attached to WebSpeak's stable visual interface.");
|
||||
if (!pluginId && !selectorUsesPublicHook(rule.selector, schemaVersion >= 3)) throw rule.error("Skin selectors must use :root, [data-ws-page], [data-ws-part], or [data-ws-plugin-part] so they stay attached to WebSpeak's stable visual interface.");
|
||||
if (targetsOnlyOptionalVisualParts(rule.selector)) hideableRules.add(rule);
|
||||
try {
|
||||
rule.selector = selectorParser((selectors) => {
|
||||
@@ -629,8 +665,11 @@ function compileSkinCss(source: string, id: string, assets: Record<string, Blob>
|
||||
const canHideTarget = owningRule
|
||||
? hideableRules.has(owningRule) || Boolean(keyframesRule && optionalOnlyKeyframes.has(keyframesRule.params.trim()))
|
||||
: false;
|
||||
if (property.startsWith("--") && !/^--skin-[a-z0-9_-]+$/i.test(property)) {
|
||||
throw declaration.error("Custom skin variables must use the --skin- prefix so they cannot replace WebSpeak's structural tokens.");
|
||||
if (property.startsWith("--") && !/^--skin-[a-z0-9_-]+$/i.test(property)
|
||||
&& !(pluginId && property.startsWith(`--plugin-${pluginId}-`))) {
|
||||
throw declaration.error(pluginId
|
||||
? `Custom plugin variables must use --plugin-${pluginId}- or --skin- prefixes.`
|
||||
: "Custom skin variables must use the --skin- prefix so they cannot replace WebSpeak's structural tokens.");
|
||||
}
|
||||
if (schemaVersion < 3 && isLayoutAffectingProperty(property)) {
|
||||
throw declaration.error("Skin CSS may change component artwork and appearance, but must not change layout, positioning, sizing, text flow, or interaction geometry.");
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { parseSkinRuntimePluginDocument } from "../../../src/shared/skin-runtime-plugins.js";
|
||||
import { createSkinRuntimePluginSession, SkinRuntimePluginSessionError } from "./skin-runtime-plugin-session.js";
|
||||
|
||||
const plugin = parseSkinRuntimePluginDocument({
|
||||
schemaVersion: 1,
|
||||
plugins: [{
|
||||
id: "voice-surface",
|
||||
name: "Voice surface",
|
||||
version: "1.0.0",
|
||||
apiVersion: 1,
|
||||
runtime: "wasm",
|
||||
page: "voice",
|
||||
mode: "surface",
|
||||
entry: "plugins/voice-surface/index.wasm",
|
||||
assets: [],
|
||||
permissions: ["ui.surface.replace"],
|
||||
}],
|
||||
}).plugins[0];
|
||||
|
||||
function output(page = "voice", count = 1): string {
|
||||
return JSON.stringify({
|
||||
schemaVersion: 5,
|
||||
components: Array.from({ length: count }, (_, index) => ({
|
||||
id: `surface-${index}`,
|
||||
name: "Voice surface",
|
||||
page,
|
||||
accessibleName: "Voice workspace",
|
||||
state: {},
|
||||
root: { tag: "main", children: [{ text: "custom voice UI" }] },
|
||||
})),
|
||||
});
|
||||
}
|
||||
|
||||
function sessionWithOutput(value: string, onError: (error: Error) => void = () => undefined) {
|
||||
return createSkinRuntimePluginSession({
|
||||
plugin,
|
||||
createRun: () => ({ result: Promise.resolve({ uiOutput: value }), close: () => undefined }),
|
||||
onError,
|
||||
});
|
||||
}
|
||||
|
||||
test("runtime plugin session accepts one generated root for its declared surface", async () => {
|
||||
const session = sessionWithOutput(output());
|
||||
assert.equal(await session.start(), true);
|
||||
assert.equal(session.output, output());
|
||||
assert.equal(session.closed, false);
|
||||
session.close();
|
||||
assert.equal(session.closed, true);
|
||||
});
|
||||
|
||||
test("runtime plugin session rejects output targeting a different page", async () => {
|
||||
const errors: Error[] = [];
|
||||
const session = sessionWithOutput(output("home"), (error) => errors.push(error));
|
||||
assert.equal(await session.start(), false);
|
||||
assert.equal(errors[0] instanceof SkinRuntimePluginSessionError, true);
|
||||
assert.equal((errors[0] as SkinRuntimePluginSessionError).code, "SKIN_RUNTIME_PLUGIN_PAGE_MISMATCH");
|
||||
assert.equal(session.output, null);
|
||||
});
|
||||
|
||||
test("runtime surface plugins cannot emit competing roots", async () => {
|
||||
const errors: Error[] = [];
|
||||
const session = sessionWithOutput(output("voice", 2), (error) => errors.push(error));
|
||||
assert.equal(await session.start(), false);
|
||||
assert.ok(errors[0] instanceof SkinRuntimePluginSessionError);
|
||||
assert.equal((errors[0] as SkinRuntimePluginSessionError).code, "SKIN_RUNTIME_PLUGIN_SURFACE_OUTPUT_INVALID");
|
||||
assert.equal(session.output, null);
|
||||
});
|
||||
@@ -0,0 +1,49 @@
|
||||
import type { SkinRuntimePlugin } from "../../../src/shared/skin-runtime-plugins.js";
|
||||
import type { SkinExtensionUiInput } from "../../../src/shared/skin-extension-ui-input.js";
|
||||
import type { SkinPluginDocument } from "../../../src/shared/skin-plugin.js";
|
||||
import {
|
||||
createSkinExtensionWasmUiLoopPrototype,
|
||||
type SkinExtensionWasmUiLoopRunHandle,
|
||||
} from "./skin-extension-wasm-ui-loop.js";
|
||||
|
||||
export class SkinRuntimePluginSessionError extends Error {
|
||||
constructor(readonly code: string, message: string) {
|
||||
super(message);
|
||||
this.name = "SkinRuntimePluginSessionError";
|
||||
}
|
||||
}
|
||||
|
||||
export interface SkinRuntimePluginSessionOptions {
|
||||
plugin: SkinRuntimePlugin;
|
||||
createRun(input: SkinExtensionUiInput): SkinExtensionWasmUiLoopRunHandle;
|
||||
onOutput?(output: string, document: SkinPluginDocument): void | Promise<void>;
|
||||
onError?(error: Error): void;
|
||||
}
|
||||
|
||||
/** Binds one authorized v4 descriptor to its page and surface contract. */
|
||||
export function createSkinRuntimePluginSession(options: SkinRuntimePluginSessionOptions) {
|
||||
let output: string | null = null;
|
||||
const loop = createSkinExtensionWasmUiLoopPrototype({
|
||||
createRun: options.createRun,
|
||||
onOutput: async (nextOutput, document) => {
|
||||
if (document.components.some((component) => component.page !== options.plugin.page)) {
|
||||
throw new SkinRuntimePluginSessionError("SKIN_RUNTIME_PLUGIN_PAGE_MISMATCH", "Generated UI must stay on the page declared by its plugin.");
|
||||
}
|
||||
if (options.plugin.mode === "surface" && document.components.length !== 1) {
|
||||
throw new SkinRuntimePluginSessionError("SKIN_RUNTIME_PLUGIN_SURFACE_OUTPUT_INVALID", "A surface plugin must generate exactly one root component.");
|
||||
}
|
||||
output = nextOutput;
|
||||
await options.onOutput?.(nextOutput, document);
|
||||
},
|
||||
onError: options.onError,
|
||||
});
|
||||
|
||||
return {
|
||||
get output() { return output; },
|
||||
get closed() { return loop.closed; },
|
||||
get running() { return loop.running; },
|
||||
start: () => loop.start(),
|
||||
dispatch: (input: unknown) => loop.dispatch(input),
|
||||
close: (reason?: string) => loop.close(reason),
|
||||
};
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import "./skin-runtime-plugin-session.test.js";
|
||||
import {
|
||||
computeSkinRuntimePluginDigest,
|
||||
createSkinRuntimePluginApproval,
|
||||
|
||||
@@ -33,7 +33,7 @@ export interface SkinRuntimePluginWasmOptions {
|
||||
prototypeOnly: true;
|
||||
}
|
||||
|
||||
const WASM_PROTOTYPE_PERMISSIONS = new Set(["session.status.read"]);
|
||||
const WASM_PROTOTYPE_PERMISSIONS = new Set(["session.status.read", "ui.surface.replace"]);
|
||||
|
||||
/** Starts a Wasm entry only after rechecking the exact package digest and local approval. */
|
||||
export async function createSkinRuntimePluginWasmSandboxPrototype(
|
||||
@@ -66,7 +66,7 @@ export async function createSkinRuntimePluginWasmSandboxPrototype(
|
||||
name: plugin.name,
|
||||
version: plugin.version,
|
||||
apiVersion: plugin.apiVersion,
|
||||
permissions: [...plugin.permissions],
|
||||
permissions: plugin.permissions.filter((permission) => permission === "session.status.read"),
|
||||
});
|
||||
|
||||
// This legacy approval object is created only after the v4 digest-bound host approval above.
|
||||
|
||||
@@ -24,9 +24,22 @@
|
||||
@surface-change="skinPluginSurfaceActive = $event"
|
||||
@restore-skin="switchToBuiltIn"
|
||||
/>
|
||||
<SkinRuntimePluginHost
|
||||
v-if="activeSkin?.runtimePlugins"
|
||||
:skin-id="activeSkin.id"
|
||||
:skin-version="activeSkin.version"
|
||||
:plugins="activeSkin.runtimePlugins"
|
||||
:files="activeSkin.runtimePluginFiles ?? {}"
|
||||
:styles="activeSkin.runtimePluginStyles ?? {}"
|
||||
:assets="activeSkin.assets"
|
||||
:page="showVoiceShell ? 'voice' : 'home'"
|
||||
:read-session-status="readSkinRuntimeSessionStatus"
|
||||
@surface-change="skinRuntimePluginSurfaceActive = $event"
|
||||
@restore-skin="switchToBuiltIn"
|
||||
/>
|
||||
<!-- Connection / welcome screen -->
|
||||
<section
|
||||
v-if="!showVoiceShell && !skinPluginSurfaceActive"
|
||||
v-if="!showVoiceShell && !skinPluginSurfaceActive && !skinRuntimePluginSurfaceActive"
|
||||
class="join-page"
|
||||
data-ws-part="home"
|
||||
>
|
||||
@@ -301,7 +314,7 @@
|
||||
|
||||
<!-- Connected application shell -->
|
||||
<div
|
||||
v-else-if="showVoiceShell && !skinPluginSurfaceActive"
|
||||
v-else-if="showVoiceShell && !skinPluginSurfaceActive && !skinRuntimePluginSurfaceActive"
|
||||
:class="['app-shell', `mobile-view-${mobileSection}`]"
|
||||
:data-performance-open="performancePanelOpen ? 'true' : 'false'"
|
||||
:data-favorite-rail="accessMode === 'open' ? 'true' : 'false'"
|
||||
@@ -930,6 +943,7 @@ import { observeMobileViewport } from "../services/mobile-viewport.js";
|
||||
import { computed, h, onMounted, onUnmounted, reactive, ref, shallowRef, watch } from "vue";
|
||||
import Icon from "../components/Icon.vue";
|
||||
import SkinPluginOutlet from "../components/SkinPluginOutlet.js";
|
||||
import SkinRuntimePluginHost from "../components/SkinRuntimePluginHost.js";
|
||||
import SkinLoadRecoveryNotice from "../components/SkinLoadRecoveryNotice.vue";
|
||||
import VoiceMemberCards from "../components/web-client/VoiceMemberCards.vue";
|
||||
import VoicePerformancePanel from "../components/web-client/VoicePerformancePanel.vue";
|
||||
@@ -1097,7 +1111,11 @@ let toastTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
const language = ref<Language>(getInitialLanguage());
|
||||
const activeSkin = shallowRef<InstalledSkin | null>(null);
|
||||
const skinPluginSurfaceActive = ref(false);
|
||||
watch(activeSkin, () => { skinPluginSurfaceActive.value = false; }, { flush: "sync" });
|
||||
const skinRuntimePluginSurfaceActive = ref(false);
|
||||
watch(activeSkin, () => {
|
||||
skinPluginSurfaceActive.value = false;
|
||||
skinRuntimePluginSurfaceActive.value = false;
|
||||
}, { flush: "sync" });
|
||||
const skinMessageOverrides = computed(() => resolveSkinMessages(activeSkin.value, language.value));
|
||||
const { t: translate, localizedMessage, localizedAudioNotice, visibleErrorCode } = useWebClientI18n(language);
|
||||
function t(key: string, variables: Record<string, string | number> = {}) {
|
||||
@@ -1542,6 +1560,12 @@ const skinPluginContext = computed(() => ({
|
||||
},
|
||||
}));
|
||||
|
||||
const readSkinRuntimeSessionStatus = (_signal: AbortSignal) => ({
|
||||
connected: voiceState.connected,
|
||||
channelName: voiceState.connected ? currentChannelName.value : null,
|
||||
memberCount: skinPluginMembers.value.length,
|
||||
});
|
||||
|
||||
const skinPluginActions = {
|
||||
"voice.joinChannel": (args: Record<string, string | number | boolean>) => {
|
||||
if (!voiceState.connected || typeof args.channelId !== "string") return;
|
||||
|
||||
Reference in new issue
Block a user