From 849eb1a6d98fa07d97629f8de58eb8f5648067bc Mon Sep 17 00:00:00 2001 From: illusia <64828020+EchoSixHIYA@users.noreply.github.com> Date: Sat, 10 Oct 2026 01:44:59 +0800 Subject: [PATCH] feat(skin): expand schema v3 voice interactions --- .../skills/webspeak-skin-development/SKILL.md | 10 +- docs/OPEN_SKIN_SYSTEM_ROADMAP.zh-CN.md | 18 ++- docs/OPEN_SKIN_SYSTEM_SPEC.zh-CN.md | 18 ++- docs/SKIN_DEVELOPMENT.md | 10 +- src/shared/skin-plugin.test.ts | 61 ++++++- src/shared/skin-plugin.ts | 152 ++++++++++++++---- web/src/components/SkinPluginOutlet.ts | 18 ++- web/src/views/WebClient.vue | 53 ++++++ 8 files changed, 282 insertions(+), 58 deletions(-) diff --git a/.agents/skills/webspeak-skin-development/SKILL.md b/.agents/skills/webspeak-skin-development/SKILL.md index 36d6925..770e0bb 100644 --- a/.agents/skills/webspeak-skin-development/SKILL.md +++ b/.agents/skills/webspeak-skin-development/SKILL.md @@ -1,11 +1,11 @@ --- name: webspeak-skin-development -description: Create, refine, package, and verify WebSpeak v1 visual, v2 layout, and v3 open skins, including declarative full-page surfaces that compose host-owned voice controls. +description: Create, refine, package, and verify WebSpeak v1 visual, v2 layout, and v3 open skins, including custom declarative public interfaces, full-page surfaces, and permission-gated TeamSpeak interactions. --- # WebSpeak skin development -Use this skill when editing or authoring a WebSpeak `.wskin` package, a built-in skin, or skin-facing UI hooks. v1/v2 packages are visual/layout data; v3 may rearrange public UI, add bounded declarative components, or replace the visible home/voice page with a validated surface. WebSpeak owns host behavior and the administrator console is outside the skin scope. +Use this skill when editing or authoring a WebSpeak `.wskin` package, a built-in skin, or skin-facing UI hooks. v1/v2 packages are visual/layout data; v3 may freely compose bounded declarative UI from its own nodes, rearrange public UI, and replace the visible home/voice page with a validated surface. Optional host widgets are reusable trusted primitives, not the limit of custom UI. WebSpeak owns host behavior and the administrator console is outside the skin scope. ## Before editing @@ -17,8 +17,8 @@ Use this skill when editing or authoring a WebSpeak `.wskin` package, a built-in - Keep WebSpeak's translations and semantic content as the baseline. Add `content.json` only when a text override is an explicit part of the request; never use it to implement visual artwork. - Follow the schema-specific CSS rules: v1/v2 reject layout changes; v3 allows layout, placement, size, typography, and visibility changes within the skin root. Keep CSS package-local, scoped to public hooks, and free of external resources or executable values. -- v3 can replace or obscure normal page controls. A surface must request `ui.surface.replace` and stays disabled until the user approves it. Arrange host widgets for the functions it needs; available IDs are registered in `src/shared/skin-plugin.ts`. Each stateful host widget may appear once per page. Preserve usable microphone, disconnect, device-settings, screen-share and recovery paths at desktop and mobile sizes. Verify both the return-to-built-in-UI and restore-built-in-skin buttons. The host recovery and permission UI render outside the skin root. Keep `/admin/**` unskinned. -- components.json schema v1 is legacy; schema v2 adds `mode: "surface"` and allowlisted host-widget nodes. Component trees are declarative JSON rendered by the host. Never add script, Wasm, HTML strings, direct network/storage, or private host objects. Request only the component-level permissions needed; surfaces require `ui.surface.replace`. Keep server-list labels and opaque identifiers separate from addresses and credentials. Use `servers.quickList` plus `quickServers.switch` when a custom UI should show favorites and recent servers together. Host widgets execute in WebSpeak and do not grant author code access to their private state. +- v3 can replace or obscure normal page controls. A surface must request `ui.surface.replace` and stays disabled until the user approves it. Custom interfaces can use their own declarative nodes and CSS; embed optional host widgets only when a trusted WebSpeak control is useful. Available widget IDs are registered in `src/shared/skin-plugin.ts`; each stateful host widget may appear once per page. Preserve usable microphone, disconnect, device-settings, screen-share and recovery paths at desktop and mobile sizes. Verify both the return-to-built-in-UI and restore-built-in-skin buttons. The host recovery and permission UI render outside the skin root. Keep `/admin/**` unskinned. +- components.json schema v1 is legacy; v2 adds `mode: "surface"` and optional allowlisted host-widget nodes; v3 expands bounded declarative composition, events and permission-gated voice actions. Never add script, Wasm, HTML strings, direct network/storage, or private host objects. Request only the component-level permissions needed; surfaces require `ui.surface.replace`. Bind voice actions only to explicit trusted activations; passive focus/blur/hover/drag-start/over events may update local UI state only, and input/change must not trigger host actions. Keep server-list labels and opaque identifiers separate from addresses and credentials. Use `servers.quickList` plus `quickServers.switch` when a custom UI should show favorites and recent servers together. Host widgets execute in WebSpeak and do not grant author code access to their private state. - Use the host's reserved artwork hooks for layered character art and the headphone scene. Prefer transparent assets and `background-size: contain` where the reference requires the full character or chibi to remain visible; arrange the artwork around the fixed hook rather than changing its geometry. - Build visual depth with separate background, surface, and foreground artwork already exposed by the hooks. Avoid duplicate static decorations when an animated replacement exists. For motion, keep waveforms/sonar smooth and restrained, honor reduced-motion preferences, and retain readable focus, error, mute, and speaking states. - Keep skin-specific CSS variables under `--skin-*`. Use only package-local assets and confirm their redistribution rights. @@ -27,7 +27,7 @@ Use this skill when editing or authoring a WebSpeak `.wskin` package, a built-in 1. Compare the implementation with its accessible visual reference at desktop and narrow widths. Check the homepage, voice workspace, empty chat, member list, screen-share player, selectors, and `/demo`; verify no crop, overflow, text collision, or control overlap. Do not claim visual verification when the reference page could not be read. 2. Check all five interface languages, day/night modes, keyboard focus, and reduced-motion behavior. Confirm the admin console is unchanged. -3. Run the relevant skin-package tests and application build after a related batch of changes. Fix validation failures rather than weakening v1/v2 boundaries, v3 permission checks, surface limits, or the host-widget allowlist. +3. Run the relevant skin-package tests and application build after a related batch of changes. Fix validation failures rather than weakening v1/v2 boundaries, v3 permission and event checks, surface limits, or the host-widget allowlist. 4. Package the contents of the skin directory so `manifest.json` is at the archive root, then import it through `/admin/skins` and retest the installed `.wskin` in a visitor session. The shipped default day, default night, and ILLUSIA skins are protected built-ins. Do not change their IDs or introduce upload/update flows that can disable, replace, or remove them. A permission request is not a grant; verify the deny and revoke paths. Do not claim a skin was visually verified against an external reference unless that page was actually accessible. diff --git a/docs/OPEN_SKIN_SYSTEM_ROADMAP.zh-CN.md b/docs/OPEN_SKIN_SYSTEM_ROADMAP.zh-CN.md index 9dc79eb..4f8bd90 100644 --- a/docs/OPEN_SKIN_SYSTEM_ROADMAP.zh-CN.md +++ b/docs/OPEN_SKIN_SYSTEM_ROADMAP.zh-CN.md @@ -22,14 +22,22 @@ schema v2 支持公开组件布局、桌面/平板/手机配置、本地覆盖 皮肤包 schema v3 的客户端和服务端包校验、CSS 布局能力、声明式组件渲染、按组件权限审批与撤销、公开数据代理及有限宿主动作已接入。旧的 components.json schema v1 使用受限 JSON 节点,不运行作者 JavaScript 或 WebAssembly。宿主对每次动作重新校验。 -当前白名单包括连接摘要、公开频道、可见成员、当前公开频道消息和脱敏收藏名称。宿主动作覆盖公开频道加入、已有收藏切换、当前频道聊天发送和组件本地状态更新。收藏服务器地址、密码、身份密钥、私聊数据、原始音频、屏幕流、管理 API、任意网络和浏览器存储不会交给组件代码。 +自定义 UI 使用作者定义的节点和 CSS,不要求从固定宿主控件目录里选布局。宿主控件只是可以嵌入的可选可信功能块;页面交互按组件权限连接到有限、逐项校验的现有 TeamSpeak 功能。 + +### R3.1:扩展声明式交互(进行中) + +- components.json schema v3 兼容 schema v1/v2,同时扩大节点/深度/列表上限,并增加键盘、指针、上下文菜单和拖放交互事件。 +- 新增自己的麦克风/扬声器、音量、离开状态、悄悄话、断开连接和屏幕共享等宿主动作及逐项权限;皮肤只调用现有 WebSpeak 流程。 +- 新增音频、悄悄话和屏幕共享的公开状态数据,不向组件提供私有 SDK 对象、地址、原始音频或屏幕流。 +- 被动 focus/blur/hover/drag-start/drag-over 只能更新本地 UI 状态;触发宿主动作需要明确用户操作,输入/change 仍不能触发连接、切房或消息发送。 +- 完成统一批次验证后,再以真实授权语音房间完善 KAAK 参考实现;授权房间在当前浏览器仍不可读取时,保持未完成状态,不猜测视觉细节。 ### R4:整页皮肤界面和宿主控件组合(进行中) -- components.json schema v2 增加 `mode: "surface"`,允许替换首页或语音工作区的完整可见页面;旧 schema v1 继续兼容。 +- components.json schema v2 引入、schema v3 继续支持 `mode: "surface"`,允许替换首页或语音工作区的完整可见页面;旧 schema v1/v2 继续兼容。 - surface 用受限节点、受控 CSS、公开数据绑定及白名单动作构建布局,不运行作者代码。 - 整页替换要求用户单独批准 `ui.surface.replace`;页面权限确认、撤销入口和恢复控件由宿主绘制。 -- 固定宿主控件 ID 可供皮肤编排,包括连接表单、皮肤/语言选择器、频道成员面板、语音成员卡、聊天、音频控制、屏幕共享、悄悄话、性能面板和退出控件。控件只在 WebSpeak 内执行,作者代码无法读取其私有状态;每个有状态控件每页仅可挂载一次。 +- 可选宿主控件 ID 包括连接表单、皮肤/语言选择器、频道成员面板、语音成员卡、聊天、音频控制、屏幕共享、悄悄话、性能面板和退出控件。控件只在 WebSpeak 内执行,作者代码无法读取其私有状态;每个有状态控件每页仅可挂载一次。自定义声明式元素不受此注册表限制。 - 为完整定制常用服务器栏提供脱敏的收藏/历史列表与宿主切换动作;地址、密码和身份材料仍留在 WebSpeak 内。 - 页面权限确认、撤销入口和“返回标准界面”控件在皮肤 CSS 作用域之外。页面替换被拒绝或退出时,原生首页/语音工作区重新显示。 - 补充导入、旧包兼容、页面替换、权限拒绝/撤销、宿主控件及皮肤切换回归。 @@ -42,7 +50,7 @@ schema v2 支持公开组件布局、桌面/平板/手机配置、本地覆盖 - surface 的“恢复内置皮肤”按钮误接到仅用于皮肤加载错误的回退函数,正常皮肤下点击无效。已改为明确切换到当前主题对应的内置皮肤,并增加授权/撤销回归。 - 初版自定义服务器栏只有收藏数据,缺少最近连接项。新增 `servers.quickList` 和宿主切换动作,使用不透明令牌,不下放目标地址或凭据。 - 收藏名/最近连接显示名有时会直接等于服务器地址;投影数据前增加地址匹配与泛化标签,避免通过“显示名”字段间接暴露连接目标。 -- KOOK 页面标签能在标签清单中看到,但 IAB `getTab` 超时,Edge 扩展桥接返回 `nodeRepl.fetch request failed`;因此本轮未进入授权频道,未取得真实房间截图。视觉复刻与房间交互验收保持未完成,不以第三方截图替代授权页面证据。 +- KOOK 已授权范围是“比奇堡恶人帮”相关的前两个语音房间;用户明确排除陪玩店、活动通知等运营页面。新建 IAB 标签可以读取频道页的大致布局结构,但现有页面绑定、截图和语音频道点击均超时,无法确认是否真正进入语音房或取得视觉截图。尚未保存频道 ID、成员名单或历史消息;房间视觉复刻与交互验收仍未完成,不以推广内容、历史消息、搜索摘要或不相关页面替代参考。 ## 下一阶段 @@ -64,7 +72,7 @@ schema v2 支持公开组件布局、桌面/平板/手机配置、本地覆盖 ## 迁移和验收 - v1、v2 皮肤包继续按原有规则校验;皮肤包 schema v3 才有开放 CSS 和组件能力。 -- components.json schema v1 继续导入;只有 schema v2 可以声明 surface 和宿主控件。 +- components.json schema v1/v2/v3 继续导入;schema v2 起可声明 surface 和宿主控件,schema v3 扩展自定义交互与权限动作。 - 未知版本、字段、权限、节点、数据路径、动作、控件和素材类型都拒绝导入。 - 每次将相关修改合并成一批统一运行验证,避免每个小节点重复跑全套构建。 - 管理端、运营页面和语音服务内部行为不因开放皮肤系统而扩展。 diff --git a/docs/OPEN_SKIN_SYSTEM_SPEC.zh-CN.md b/docs/OPEN_SKIN_SYSTEM_SPEC.zh-CN.md index 37d5b1e..abc42bc 100644 --- a/docs/OPEN_SKIN_SYSTEM_SPEC.zh-CN.md +++ b/docs/OPEN_SKIN_SYSTEM_SPEC.zh-CN.md @@ -1,6 +1,6 @@ # 更开放的皮肤系统规格 -状态:皮肤包 schema v3 已接入公开客户端、浏览器导入和服务端包校验;components.json schema v2 正在提供整页替换和宿主控件插槽,旧组件 schema v1 继续兼容。页面内容由受限声明式树和皮肤 CSS 定义,交互通过白名单动作及 WebSpeak 原生控件完成;不执行皮肤作者的 JavaScript 或 WebAssembly。阶段记录见[路线图](./OPEN_SKIN_SYSTEM_ROADMAP.zh-CN.md),创作者操作见[皮肤开发规范](./SKIN_DEVELOPMENT.md)。 +状态:皮肤包 schema v3 已接入公开客户端、浏览器导入和服务端包校验;components.json schema v3 支持自定义公开页面结构、整页替换和更丰富的宿主动作,schema v1/v2 继续兼容。界面由受限声明式树和皮肤 CSS 定义,交互映射到经权限控制的 WebSpeak/TeamSpeak 功能;不执行作者 JavaScript 或 WebAssembly。阶段记录见[路线图](./OPEN_SKIN_SYSTEM_ROADMAP.zh-CN.md),创作者操作见[皮肤开发规范](./SKIN_DEVELOPMENT.md)。 ## 1. 目标与范围 @@ -12,13 +12,13 @@ 皮肤格式按版本区分:v1 保持视觉皮肤兼容;v2 提供有界布局 JSON;v3 使用 open-skin 清单、受控 CSS 和可选的 components.json。v1/v2 的 CSS 继续拒绝布局类声明,既有用户包不会因升级而获得新权限。v3 才允许 CSS 控制公开页面中的布局、位置、尺寸、顺序、文字排版和显隐。 -v3 自定义组件不是脚本插件。components.json schema v1 是既有组件格式;schema v2 增加 `mode: "surface"` 与宿主控件节点。surface 可以替换首页或语音工作区的整页可见内容;作者可把安全节点、公开数据列表和宿主控件组合成自己的应用布局。宿主解析元素白名单、受限属性、数据绑定、重复列表、条件和事件声明,再由 Vue 创建节点。管理员面板和演示页不能被 surface 替换。 +v3 自定义组件不是脚本插件。components.json schema v1 是既有格式;schema v2 增加 `mode: "surface"` 与宿主控件节点;schema v3 扩大自定义节点、嵌套、重复列表和声明式交互的边界,并增加映射到现有语音功能的动作。作者可直接用自己的节点和 CSS 构建页面,宿主控件只是可选的可信原生功能块,不是允许自定义界面的固定组件目录。宿主解析元素白名单、受限属性、数据绑定、重复列表、条件和事件声明,再由 Vue 创建节点。管理员面板和演示页不能被 surface 替换。 -宿主控件通过固定 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 或重复的有状态控件会拒绝导入。频道、收藏等自定义列表仍可用现有公开数据绑定和受限动作构建。 +宿主控件通过固定 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 或重复的有状态控件会拒绝导入。作者可以不用这些控件,自行绘制界面并将点击、双击等事件绑定到公开数据与受权限保护的动作。 包不能提交 HTML 字符串、事件处理代码、JavaScript、WebAssembly、远程脚本、任意 URL、表单导航、浏览器存储访问或网络调用。未知字段、元素、动作、数据路径、控件和权限一律拒绝。 -每个组件只能声明 home、voice 或 demo 页面中的一个页面、一个有界的树和精确权限清单。components.json 全文不超过 256 KiB;最多 32 个组件;每组件最多 256 个节点、16 层深度、100 个重复行、32 个本地状态值和 24 个宿主动作。图片仅可通过包内 image 资源引用。 +每个组件只能声明 home、voice 或 demo 页面中的一个页面、一个有界的树和精确权限清单。components.json 全文不超过 256 KiB。schema v1/v2 保留旧上限(32 个组件、每组件 256 个节点、16 层深度、100 个重复行);schema v3 上限为 128 个组件、每组件 2048 个节点、32 层深度、250 个重复行、64 个本地状态值和 64 个动作。图片仅可通过包内 image 资源引用。文档字节上限仍优先生效,因此实际可用数量取决于包内容。 ## 3. 可读数据和权限 @@ -32,6 +32,10 @@ v3 自定义组件不是脚本插件。components.json schema v1 是既有组件 - chat.channel.read:当前公开文字频道中可见的消息。 - favorites.read:收藏项名称、类型、是否当前项和随机不透明本地令牌;不提供地址或凭据。 - servers.quickList.read:统一后的收藏和最近连接名称、当前项、分类与随机不透明本地令牌;不提供地址或凭据。 +- audio.status.read:当前用户自己的麦克风静音和输出静音状态。 +- voice.whisper.status.read:悄悄话开关状态与已配置目标数量。 +- voice.screenShare.status.read:当前用户自己的屏幕共享状态。 +- voice.screenShare.read:当前可见共享的名称、来源、所有者显示名、音频标记和观看人数;不提供流内容。 当前宿主动作如下: @@ -40,10 +44,12 @@ v3 自定义组件不是脚本插件。components.json schema v1 是既有组件 - quickServers.switch 需要 servers.quickList.switch,只能让宿主按不透明令牌选择本机已有收藏或最近连接并走原连接流程。 - chat.sendMessage 需要 chat.channel.send,只能发送到当前公开文字频道;不包括私聊。 - ui.setState 只修改该组件短暂的本地标量状态,不需要会话权限。 +- v3 的 ui.toggleState 可切换该组件声明的布尔状态,不需要会话权限。 +- v3 可在用户明确操作时切换自己的麦克风和扬声器静音、调整本地输出音量、断开当前会话、设置自己的离开状态、启停悄悄话,以及开始/停止或加入/离开可见的屏幕共享;每项都需要对应权限,并继续走 WebSpeak 原有流程。 宿主控件节点只是把 WebSpeak 的原生界面放进皮肤布局,不向皮肤提供控件内部的数据对象。控件仍使用原来的连接、权限和用户事件检查;例如嵌入 `voice.chat-panel` 可以让用户继续使用原生聊天界面,但不会授予组件读取私聊内容的能力。 -动作仅能绑定到真实可信用户事件。输入和 change 事件不能调用宿主动作;键盘动作仅响应 Enter 或 Space。宿主再次检查当前频道、令牌及动作参数。皮肤不能控制麦克风、音频设备、屏幕采集、身份密钥或 TeamSpeak 管理命令。 +事件支持 click、dblclick、keydown/up、contextmenu、focus/blur、pointer 和 drag/drop 等受限事件;键盘动作仅响应 Enter、Space 或 Escape。输入和 change 事件不能调用宿主动作;focus/blur、pointerenter/leave、dragstart/over 这类被动事件只能改变组件本地状态,不能触发语音或其他宿主动作。敏感语音动作要求可信的明确用户操作。宿主再次检查当前频道、令牌、共享 ID 及动作参数;系统屏幕采集授权仍由浏览器/操作系统处理。皮肤不能读取原始音频或屏幕流、控制其他用户、读取身份密钥或调用 TeamSpeak 管理命令。 数据授权不是数据上传授权:组件没有任意联网或持久化 API,权限决定保存在本机。渲染进程不会把服务器地址、密码、身份私钥、访问令牌、Cookie、私聊、原始音频或屏幕流交给皮肤。 @@ -67,7 +73,7 @@ v3 CSS 和 surface 可排列、替换或遮挡公开 UI,因此可能改变麦 ## 7. 后续安全工作 -- 扩展数据字段或宿主动作时,增加精确 schema、权限和宿主侧运行时验证,不暴露内部 SDK 对象。新增宿主控件也必须登记固定 ID、明确页面和确认只在宿主内处理其私有状态。 +- 扩展数据字段或宿主动作时,增加精确 schema、权限、明确用户事件约束和宿主侧运行时验证,不暴露内部 SDK 对象。新增宿主控件也必须登记固定 ID、明确页面和确认只在宿主内处理其私有状态;自定义声明式 UI 不应被限制为只能拼装这组控件。 - 对恶意输入、路径别名、拒绝授权、撤销、更新和皮肤切换增加测试;高敏能力必须单独设计。 - 不把当前声明式包描述为可执行代码沙箱。现有 JavaScript Worker 与 Wasm 原型均未启用;浏览器 Worker 没有硬内存配额,原型也没有完整的页面渲染、控件与动作审查流程。若未来考虑作者代码,应另行开展威胁建模、资源耗尽测试、浏览器隔离评估与独立安全审查。 - 商城发布、签名、下架、更新和撤销设计与管理员面板重做一起验收,且保持零新增服务费用为默认约束。 diff --git a/docs/SKIN_DEVELOPMENT.md b/docs/SKIN_DEVELOPMENT.md index 92e2d30..539818d 100644 --- a/docs/SKIN_DEVELOPMENT.md +++ b/docs/SKIN_DEVELOPMENT.md @@ -1,10 +1,10 @@ # WebSpeak 皮肤开发规范 -本文说明仍受支持的 v1 视觉皮肤、v2 声明式布局皮肤和 v3 开放皮肤。v1/v2 保持固定 CSS 几何边界;v3 可重排公开 UI、添加受限组件,或用 components.json schema v2 替换首页/语音工作区的整页可见界面。界面由宿主安全渲染,仍不执行作者代码。路线和安全边界见[路线图](./OPEN_SKIN_SYSTEM_ROADMAP.zh-CN.md)与[规格](./OPEN_SKIN_SYSTEM_SPEC.zh-CN.md)。 +本文说明仍受支持的 v1 视觉皮肤、v2 声明式布局皮肤和 v3 开放皮肤。v1/v2 保持固定 CSS 几何边界;v3 可重排公开 UI、用自定义声明式节点构建界面,并用 components.json schema v2/v3 替换首页/语音工作区的整页可见界面。自定义界面不依赖固定宿主控件目录;交互通过逐项授权的宿主动作实现。界面由宿主安全渲染,不执行作者代码。路线和安全边界见[路线图](./OPEN_SKIN_SYSTEM_ROADMAP.zh-CN.md)与[规格](./OPEN_SKIN_SYSTEM_SPEC.zh-CN.md)。 `.wskin` 包可为公开页面定制艺术表现。v1 提供 CSS 与美术资源;v2 另外携带受校验的布局 JSON;v3 可自由安排公开组件,并用 components.json 声明由宿主渲染的安全组件。所有版本均由 WebSpeak 保留基础组件的业务逻辑和 TeamSpeak 行为。 -页面结构、必要控件和所有基础翻译均由 WebSpeak 提供。皮肤包不必携带文案;如果只包含样式与美术素材,所有界面文字仍由 WebSpeak 按当前语言显示。`content.json` 仅用于可选覆盖,缺少的语言或字段回退到 WebSpeak 的基础内容。皮肤不注入 HTML 或 JavaScript,也不改变语音、权限、连接、拖动和屏幕共享行为。**管理后台 `/admin/**` 不属于皮肤范围,始终使用 WebSpeak 自己的固定样式。** +页面结构、必要控件和所有基础翻译均由 WebSpeak 提供。皮肤包不必携带文案;如果只包含样式与美术素材,所有界面文字仍由 WebSpeak 按当前语言显示。`content.json` 仅用于可选覆盖,缺少的语言或字段回退到 WebSpeak 的基础内容。皮肤不注入 HTML 或 JavaScript;授权后的交互只调用 WebSpeak 登记并校验过的 TeamSpeak 功能。**管理后台 `/admin/**` 不属于皮肤范围,始终使用 WebSpeak 自己的固定样式。** 可直接查看 [ILLUSIA 风示例源码](examples/illusia-voice/) 与 [示例说明](examples/ILLUSIA-VOICE.md)。它使用本地美术素材和 CSS 完整定制首页、语音房间、成员区、聊天空状态及播放器,同时沿用 WebSpeak 提供的基础翻译;也是管理控制台内置且不可移除的示例皮肤。 @@ -108,7 +108,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 和 components 数组。schema v1 维持原有兼容;schema v2 的组件可声明 `mode: "widget"`(默认)或 `mode: "surface"`。每个组件需声明 id、name、page、accessibleName、permissions、actions 和 root,可选 state。page 接受 home、voice、demo;surface 仅可用于 home 和 voice,并且必须请求 `ui.surface.replace`。用户批准前不会显示 surface,撤销后宿主立即恢复普通页面。 +components.json 顶层接受 schemaVersion 1、2 或 3 和 components 数组。schema v1 维持旧兼容;schema v2 引入 `mode: "widget"`(默认)或 `mode: "surface"`,并提供可选宿主控件节点;schema v3 保持这些能力,扩大声明式 UI 的节点/状态/动作边界,并增加用户操作事件和语音功能动作。每个组件需声明 id、name、page、accessibleName、permissions、actions 和 root,可选 state。page 接受 home、voice、demo;surface 仅可用于 home 和 voice,并且必须请求 `ui.surface.replace`。用户批准前不会显示 surface,撤销后宿主立即恢复普通页面。 普通节点使用白名单 HTML/SVG 元素。节点可包含 text、part、className、受限 attributes、包内图片 asset、bindValue、本地 repeat/when、events 和 children。文本与属性支持简单的双大括号数据路径;不支持表达式、HTML 字符串或脚本。schema v2 另允许固定宿主控件节点,例如: @@ -137,11 +137,11 @@ components.json 顶层接受 schemaVersion 1 或 2 和 components 数组。schem } ``` -当前宿主控件 ID:`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`。未知控件和同页重复控件会被拒绝;每个控件的状态和业务动作仍由 WebSpeak 内部处理。只显示收藏时可用 `favorites.items` 和 `favorites.switch`;若要将收藏与最近连接放在同一自定义栏,可用 `servers.quickList` 数据与 `quickServers.switch` 动作。服务器目标始终使用本机生成的不透明令牌,不把地址、密码或身份材料交给组件。频道行也可把 `voice.joinChannel` 绑定到双击事件,切房继续走 TeamSpeak 原有权限和密码流程。 +当前可选宿主控件 ID:`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`。未知控件和同页重复控件会被拒绝;每个控件的状态和业务动作仍由 WebSpeak 内部处理。自定义 UI 可以完全用普通声明式节点搭建,不需要采用这些控件。只显示收藏时可用 `favorites.items` 和 `favorites.switch`;若要将收藏与最近连接放在同一自定义栏,可用 `servers.quickList` 数据与 `quickServers.switch` 动作。服务器目标始终使用本机生成的不透明令牌,不把地址、密码或身份材料交给组件。频道行也可把 `voice.joinChannel` 绑定到双击事件,切房继续走 TeamSpeak 原有权限和密码流程。v3 还提供经独立权限保护的麦克风/扬声器、输出音量、离开状态、悄悄话、断开连接和屏幕共享动作;它们只调用 WebSpeak 已有操作,屏幕采集仍由浏览器或操作系统询问用户。 示例包见 [KAAK voice 示例](./examples/KAAK-VOICE.md),其 components.json 展示了公开频道列表和双击加入频道;[Open Voice Surface](./examples/OPEN-VOICE-SURFACE.md) 展示了完整首页和语音工作区 surface。后者是格式验证脚手架,不声称已经逐像素复刻 KOOK。当前数据权限和宿主动作以[开放皮肤规格](./OPEN_SKIN_SYSTEM_SPEC.zh-CN.md)中的清单为准。组件按本地用户授权后才渲染;权限对每个皮肤版本、页面和组件分别保存,可在宿主权限入口撤销。页面替换时,宿主会额外显示“返回标准界面”和“恢复内置皮肤”入口;拒绝授权或离开 surface 后,普通页面可立即恢复。 -组件树有硬上限:components.json 256 KiB,最多 32 个组件,每组件最多 256 个模板节点、16 层深度、100 条重复记录、32 个本地标量状态和 24 个动作。图片资源只能从包内引用,CSS 不能读取外部 URL、脚本或浏览器存储。宿主动作需显式权限,并只能绑定可信的用户事件;输入或 change 事件不能连接、切房或发消息。 +组件树有硬上限:components.json 256 KiB。schema v1/v2 上限为 32 个组件、每组件 256 个模板节点、16 层深度和 100 条重复记录;schema v3 上限为 128 个组件、每组件 2048 个模板节点、32 层深度和 250 条重复记录,并允许 64 个本地标量状态与 64 个动作。图片资源只能从包内引用,CSS 不能读取外部 URL、脚本或浏览器存储。宿主动作需显式权限,并只能绑定可信的用户事件;输入或 change 事件不能触发宿主动作。focus/blur、hover 和 drag-start/over 等被动事件只可改动组件本地状态,不能触发语音操作。 注意:v3 CSS 和 surface 可以隐藏或遮挡普通语音控件。权限和返回标准界面提示由宿主在皮肤根之外绘制;其他界面控件仍受皮肤排版影响。测试时务必确保麦克风、设置、退出语音、屏幕共享操作和移动端导航仍有可达路径。组件演示页 /demo 使用合成数据,加入频道和聊天动作只更新演示状态;它不支持宿主控件或整页替换。 diff --git a/src/shared/skin-plugin.test.ts b/src/shared/skin-plugin.test.ts index 07e5c51..684afec 100644 --- a/src/shared/skin-plugin.test.ts +++ b/src/shared/skin-plugin.test.ts @@ -41,7 +41,7 @@ function errorCode(run: () => unknown, expected: string): void { test("skin plugin accepts a bounded channel list with a double-click host action", () => { const parsed = parseSkinPluginDocument(validDocument()); - assert.equal(parsed.schemaVersion, 2, "legacy documents normalize to the current component schema"); + assert.equal(parsed.schemaVersion, 1, "legacy documents retain their original capability boundary"); assert.equal(parsed.components[0].mode, "widget"); assert.equal(parsed.components[0].root.repeat?.path, "session.channels"); assert.equal(parsed.components[0].root.children?.[0].events?.dblclick, "join"); @@ -189,6 +189,65 @@ test("skin plugin never dispatches host actions from typing or selection changes errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_EVENT_INVALID"); }); +test("component schema v3 exposes composable interaction patterns and permission-gated voice actions", () => { + const document = validDocument(); + document.schemaVersion = 3; + document.components[0].permissions = [ + "audio.microphone.control", "audio.output.control", "audio.status.read", "voice.disconnect", "voice.presence.write", + "voice.whisper.control", "voice.whisper.status.read", "voice.screenShare.control", "voice.screenShare.read", "voice.screenShare.status.read", + ]; + document.components[0].state = { menuopen: false, volume: 0.5, awaymessage: "" }; + document.components[0].actions = { + "toggle-menu": { type: "ui.toggleState", args: { key: "menuopen" } }, + microphone: { type: "voice.toggleMicrophone", args: {} }, + speaker: { type: "voice.toggleOutputMute", args: {} }, + volume: { type: "voice.setOutputVolume", args: { volume: "{{state.volume}}" } }, + disconnect: { type: "voice.disconnect", args: {} }, + away: { type: "voice.setAway", args: { away: true, message: "{{state.awaymessage}}" } }, + whisper: { type: "voice.setWhisperActive", args: { active: true } }, + "start-share": { type: "voice.startScreenShare", args: {} }, + "stop-share": { type: "voice.stopScreenShare", args: {} }, + "join-share": { type: "voice.joinScreenShare", args: { streamId: "{{share.streamId}}" } }, + "leave-share": { type: "voice.leaveScreenShare", args: {} }, + }; + document.components[0].root = { + tag: "main", + attributes: { "data-layout": "room", "aria-label": "Custom voice page" }, + children: [ + { tag: "button", events: { contextmenu: "toggle-menu", pointerenter: "toggle-menu" }, children: [{ text: "Menu" }] }, + { tag: "button", events: { click: "microphone" }, children: [{ text: "Microphone" }] }, + { tag: "button", events: { click: "speaker" }, children: [{ text: "Speaker" }] }, + { tag: "button", events: { click: "volume" }, children: [{ text: "Volume" }] }, + { tag: "button", events: { click: "disconnect" }, children: [{ text: "Disconnect" }] }, + { tag: "button", events: { click: "away" }, children: [{ text: "Away" }] }, + { tag: "button", events: { click: "whisper" }, children: [{ text: "Whisper" }] }, + { tag: "button", events: { click: "start-share" }, children: [{ text: "Share" }] }, + { tag: "button", events: { click: "stop-share" }, children: [{ text: "Stop sharing" }] }, + { tag: "div", repeat: { path: "screenShare.streams", as: "share" }, children: [ + { tag: "button", events: { click: "join-share" }, children: [{ text: "{{share.name}}" }] }, + ] }, + { tag: "button", events: { click: "leave-share" }, children: [{ text: "Leave share" }] }, + ], + }; + const parsed = parseSkinPluginDocument(document); + assert.equal(parsed.schemaVersion, 3); + assert.equal(parsed.components[0].root.children?.[0].events?.contextmenu, "toggle-menu"); + assert.equal(parsed.components[0].actions["join-share"].type, "voice.joinScreenShare"); + assert.equal(parsed.components[0].root.children?.[9].repeat?.path, "screenShare.streams"); + + const passiveVoiceControl = structuredClone(document); + passiveVoiceControl.components[0].root.children![0].events = { pointerenter: "microphone" }; + errorCode(() => parseSkinPluginDocument(passiveVoiceControl), "SKIN_PLUGIN_EVENT_INVALID"); + + const missingPermission = structuredClone(document); + missingPermission.components[0].permissions = missingPermission.components[0].permissions.filter((item) => item !== "audio.microphone.control"); + errorCode(() => parseSkinPluginDocument(missingPermission), "SKIN_PLUGIN_PERMISSION_MISSING"); + + const oldSchema = structuredClone(document); + oldSchema.schemaVersion = 2; + errorCode(() => parseSkinPluginDocument(oldSchema), "SKIN_PLUGIN_SCHEMA_UNSUPPORTED"); +}); + test("skin plugin JSON parser enforces a bounded document size and valid JSON", () => { assert.throws(() => parseSkinPluginJson("{")); assert.throws(() => parseSkinPluginJson(" ".repeat(256 * 1024 + 1))); diff --git a/src/shared/skin-plugin.ts b/src/shared/skin-plugin.ts index 74f7eed..3db97f9 100644 --- a/src/shared/skin-plugin.ts +++ b/src/shared/skin-plugin.ts @@ -2,13 +2,13 @@ * Extension authors provide a bounded component tree and action declarations, * never executable HTML, JavaScript, or browser APIs. */ -export const SKIN_PLUGIN_SCHEMA_VERSION = 2 as const; -export const SKIN_PLUGIN_SUPPORTED_SCHEMA_VERSIONS = Object.freeze([1, 2] as const); +export const SKIN_PLUGIN_SCHEMA_VERSION = 3 as const; +export const SKIN_PLUGIN_SUPPORTED_SCHEMA_VERSIONS = Object.freeze([1, 2, 3] as const); export const SKIN_PLUGIN_DOCUMENT_LIMIT_BYTES = 256 * 1024; -export const SKIN_PLUGIN_COMPONENT_LIMIT = 32; -export const SKIN_PLUGIN_NODE_LIMIT = 256; -export const SKIN_PLUGIN_TREE_DEPTH_LIMIT = 16; -export const SKIN_PLUGIN_REPEAT_LIMIT = 100; +export const SKIN_PLUGIN_COMPONENT_LIMIT = 128; +export const SKIN_PLUGIN_NODE_LIMIT = 2048; +export const SKIN_PLUGIN_TREE_DEPTH_LIMIT = 32; +export const SKIN_PLUGIN_REPEAT_LIMIT = 250; export const SKIN_PLUGIN_PERMISSIONS = Object.freeze({ "ui.surface.replace": Object.freeze({ policyVersion: 1, description: "Replace the built-in public page with a custom skin surface; the host recovery controls remain available." }), @@ -22,6 +22,16 @@ export const SKIN_PLUGIN_PERMISSIONS = Object.freeze({ "servers.quickList.read": Object.freeze({ policyVersion: 1, description: "Read favorite and recent server labels and opaque local identifiers, without server addresses or credentials." }), "servers.quickList.switch": Object.freeze({ policyVersion: 1, description: "Switch to a user-selected favorite or recent server through the host connection flow." }), "session.channel.join": Object.freeze({ policyVersion: 1, description: "Request joining a visible TeamSpeak channel through the host; the demo page only changes simulated state." }), + "audio.status.read": Object.freeze({ policyVersion: 1, description: "Read the user's own microphone and speaker mute states." }), + "audio.microphone.control": Object.freeze({ policyVersion: 1, description: "Toggle the user's own microphone through WebSpeak's audio pipeline." }), + "audio.output.control": Object.freeze({ policyVersion: 1, description: "Toggle or adjust the user's local speaker output." }), + "voice.presence.write": Object.freeze({ policyVersion: 1, description: "Set the user's own away status through the connected TeamSpeak session." }), + "voice.whisper.control": Object.freeze({ policyVersion: 1, description: "Enable or disable the user's existing TeamSpeak whisper target selection." }), + "voice.disconnect": Object.freeze({ policyVersion: 1, description: "Disconnect the user's current TeamSpeak voice session." }), + "voice.whisper.status.read": Object.freeze({ policyVersion: 1, description: "Read whether whisper is active and how many existing targets are selected." }), + "voice.screenShare.status.read": Object.freeze({ policyVersion: 1, description: "Read the user's own screen-share state." }), + "voice.screenShare.read": Object.freeze({ policyVersion: 1, description: "Read visible screen-share names, owners, audio flags, and viewer counts." }), + "voice.screenShare.control": Object.freeze({ policyVersion: 1, description: "Start or stop the user's screen share, or join/leave a visible share through the host." }), } as const); export type SkinPluginPermission = keyof typeof SKIN_PLUGIN_PERMISSIONS; @@ -42,8 +52,16 @@ export const SKIN_PLUGIN_HOST_WIDGETS = Object.freeze([ "voice.disconnect-control", ] as const); export type SkinPluginHostWidget = typeof SKIN_PLUGIN_HOST_WIDGETS[number]; -export type SkinPluginEvent = "click" | "dblclick" | "change" | "input" | "submit" | "keydown"; -export type SkinPluginAction = "ui.setState" | "voice.joinChannel" | "favorites.switch" | "quickServers.switch" | "chat.sendMessage"; +export type SkinPluginEvent = + | "click" | "dblclick" | "change" | "input" | "submit" | "keydown" + | "keyup" | "contextmenu" | "focus" | "blur" | "pointerdown" | "pointerup" + | "pointerenter" | "pointerleave" | "dragstart" | "dragover" | "drop"; +export type SkinPluginAction = + | "ui.setState" | "ui.toggleState" + | "voice.joinChannel" | "favorites.switch" | "quickServers.switch" | "chat.sendMessage" + | "voice.toggleMicrophone" | "voice.toggleOutputMute" | "voice.setOutputVolume" + | "voice.disconnect" | "voice.setAway" | "voice.setWhisperActive" + | "voice.startScreenShare" | "voice.stopScreenShare" | "voice.joinScreenShare" | "voice.leaveScreenShare"; export interface SkinPluginActionDefinition { type: SkinPluginAction; @@ -78,7 +96,7 @@ export interface SkinPluginComponent { } export interface SkinPluginDocument { - schemaVersion: 1 | typeof SKIN_PLUGIN_SCHEMA_VERSION; + schemaVersion: 1 | 2 | typeof SKIN_PLUGIN_SCHEMA_VERSION; components: SkinPluginComponent[]; } @@ -95,33 +113,72 @@ export class SkinPluginValidationError extends Error { } const ELEMENTS = new Set([ - "article", "aside", "button", "circle", "code", "dd", "details", "div", "dl", "dt", "em", "figcaption", "figure", "footer", "form", - "g", "h1", "h2", "h3", "h4", "header", "hr", "img", "input", "label", "li", "line", "main", "nav", "ol", "option", - "output", "p", "path", "polyline", "rect", "section", "select", "small", "span", "strong", "summary", "svg", "textarea", "time", "ul", + "article", "aside", "b", "blockquote", "br", "button", "caption", "circle", "cite", "code", "dd", "del", "details", "div", "dl", "dt", + "em", "fieldset", "figcaption", "figure", "footer", "form", "g", "h1", "h2", "h3", "h4", "h5", "h6", "header", "hr", "i", "img", "input", + "kbd", "label", "legend", "li", "line", "main", "mark", "nav", "ol", "option", "output", "p", "path", "polyline", "pre", "progress", "q", + "rect", "s", "section", "select", "small", "span", "strong", "sub", "summary", "sup", "svg", "table", "tbody", "td", "textarea", "th", "thead", + "time", "tr", "u", "ul", "wbr", ]); -const VOID_ELEMENTS = new Set(["circle", "hr", "img", "input", "line", "path", "polyline", "rect"]); +const VOID_ELEMENTS = new Set(["br", "circle", "hr", "img", "input", "line", "path", "polyline", "rect", "wbr"]); const ATTRIBUTES = new Set([ - "alt", "aria-current", "aria-expanded", "aria-hidden", "aria-label", "aria-pressed", "aria-selected", "class", "colspan", "fill", - "height", "max", "min", "name", "placeholder", "role", "rowspan", "stroke", "stroke-linecap", "stroke-linejoin", "stroke-width", - "tabindex", "title", "type", "value", "viewbox", "width", "x", "x1", "x2", "y", "y1", "y2", + "alt", "aria-current", "aria-expanded", "aria-hidden", "aria-label", "aria-pressed", "aria-selected", "autocomplete", "checked", "class", "colspan", "disabled", "draggable", "fill", "height", "inputmode", "max", "maxlength", "min", + "minlength", "multiple", "name", "open", "placeholder", "required", "role", "rows", "rowspan", "stroke", "stroke-linecap", "stroke-linejoin", + "stroke-width", "tabindex", "title", "type", "value", "viewbox", "width", "x", "x1", "x2", "y", "y1", "y2", +]); +const EVENTS = new Set([ + "click", "dblclick", "change", "input", "submit", "keydown", "keyup", "contextmenu", "focus", "blur", "pointerdown", "pointerup", + "pointerenter", "pointerleave", "dragstart", "dragover", "drop", +]); +const V3_EVENTS = new Set([ + "keyup", "contextmenu", "focus", "blur", "pointerdown", "pointerup", "pointerenter", "pointerleave", "dragstart", "dragover", "drop", +]); +const PASSIVE_EVENTS = new Set(["focus", "blur", "pointerenter", "pointerleave", "dragstart", "dragover"]); +const ACTIONS = new Set([ + "ui.setState", "ui.toggleState", "voice.joinChannel", "favorites.switch", "quickServers.switch", "chat.sendMessage", + "voice.toggleMicrophone", "voice.toggleOutputMute", "voice.setOutputVolume", "voice.disconnect", "voice.setAway", "voice.setWhisperActive", + "voice.startScreenShare", "voice.stopScreenShare", "voice.joinScreenShare", "voice.leaveScreenShare", +]); +const V3_ACTIONS = new Set([ + "ui.toggleState", "voice.toggleMicrophone", "voice.toggleOutputMute", "voice.setOutputVolume", "voice.disconnect", "voice.setAway", + "voice.setWhisperActive", "voice.startScreenShare", "voice.stopScreenShare", "voice.joinScreenShare", "voice.leaveScreenShare", ]); -const EVENTS = new Set(["click", "dblclick", "change", "input", "submit", "keydown"]); -const ACTIONS = new Set(["ui.setState", "voice.joinChannel", "favorites.switch", "quickServers.switch", "chat.sendMessage"]); const PERMISSIONS = new Set(Object.keys(SKIN_PLUGIN_PERMISSIONS)); const HOST_WIDGETS = new Set(SKIN_PLUGIN_HOST_WIDGETS); const ACTION_ARGS: Record> = { "ui.setState": new Set(["key", "value"]), + "ui.toggleState": new Set(["key"]), "voice.joinChannel": new Set(["channelId"]), "favorites.switch": new Set(["favoriteId"]), "quickServers.switch": new Set(["quickServerId"]), "chat.sendMessage": new Set(["text"]), + "voice.toggleMicrophone": new Set([]), + "voice.toggleOutputMute": new Set([]), + "voice.setOutputVolume": new Set(["volume"]), + "voice.disconnect": new Set([]), + "voice.setAway": new Set(["away", "message"]), + "voice.setWhisperActive": new Set(["active"]), + "voice.startScreenShare": new Set([]), + "voice.stopScreenShare": new Set([]), + "voice.joinScreenShare": new Set(["streamId"]), + "voice.leaveScreenShare": new Set([]), }; const ACTION_PERMISSION: Record = { "ui.setState": null, + "ui.toggleState": null, "voice.joinChannel": "session.channel.join", "favorites.switch": "favorites.switch", "quickServers.switch": "servers.quickList.switch", "chat.sendMessage": "chat.channel.send", + "voice.toggleMicrophone": "audio.microphone.control", + "voice.toggleOutputMute": "audio.output.control", + "voice.setOutputVolume": "audio.output.control", + "voice.disconnect": "voice.disconnect", + "voice.setAway": "voice.presence.write", + "voice.setWhisperActive": "voice.whisper.control", + "voice.startScreenShare": "voice.screenShare.control", + "voice.stopScreenShare": "voice.screenShare.control", + "voice.joinScreenShare": "voice.screenShare.control", + "voice.leaveScreenShare": "voice.screenShare.control", }; const COLLECTION_PERMISSION: Record = { "session.channels": "session.channels.read", @@ -129,6 +186,7 @@ const COLLECTION_PERMISSION: Record = { "favorites.items": "favorites.read", "servers.quickList": "servers.quickList.read", "chat.messages": "chat.channel.read", + "screenShare.streams": "voice.screenShare.read", }; const COLLECTION_FIELDS: Record> = { "session.channels": new Set(["id", "name", "parentId", "depth", "memberCount", "current"]), @@ -136,8 +194,19 @@ const COLLECTION_FIELDS: Record> = { "favorites.items": new Set(["id", "label", "current", "kind"]), "servers.quickList": new Set(["id", "label", "current", "kind", "favorite"]), "chat.messages": new Set(["id", "author", "text", "time", "kind", "channelId"]), + "screenShare.streams": new Set(["streamId", "source", "ownerClientId", "ownerNickname", "name", "audio", "viewerCount"]), }; const SESSION_STATUS_FIELDS = new Set(["connected", "connecting", "serverLabel", "channelId", "channelName", "userName"]); +const CONTEXT_FIELDS: Record> = { + "audio.status": new Set(["microphoneMuted", "outputMuted"]), + "screenShare.status": new Set(["active", "starting", "viewing"]), + "whisper.status": new Set(["active", "targetCount"]), +}; +const CONTEXT_PERMISSIONS: Record = { + "audio.status": "audio.status.read", + "screenShare.status": "voice.screenShare.status.read", + "whisper.status": "voice.whisper.status.read", +}; function fail(code: string, message: string): never { throw new SkinPluginValidationError(code, message); } function isRecord(value: unknown): value is Record { return Boolean(value) && typeof value === "object" && !Array.isArray(value); } @@ -171,6 +240,11 @@ function bindingPermissions(value: string, aliases: ReadonlyMap, found.add("session.status.read"); continue; } + const contextPath = path.slice(0, 2).join("."); + if (path.length === 3 && CONTEXT_FIELDS[contextPath]?.has(path[2])) { + found.add(CONTEXT_PERMISSIONS[contextPath]); + continue; + } const collectionPath = path.slice(0, 2).join("."); const permission = COLLECTION_PERMISSION[collectionPath]; if (permission && (path.length === 2 || (path.length === 3 && COLLECTION_FIELDS[collectionPath].has(path[2])))) { @@ -188,12 +262,12 @@ function bindingPermissions(value: string, aliases: ReadonlyMap, export function parseSkinPluginDocument(input: unknown): SkinPluginDocument { if (!isRecord(input)) fail("SKIN_PLUGIN_DOCUMENT_INVALID", "components.json must contain an object."); onlyKeys(input, new Set(["schemaVersion", "components"]), "components.json"); - if (!SKIN_PLUGIN_SUPPORTED_SCHEMA_VERSIONS.includes(input.schemaVersion as 1 | 2) || !Array.isArray(input.components) - || !input.components.length || input.components.length > SKIN_PLUGIN_COMPONENT_LIMIT) { + if (!SKIN_PLUGIN_SUPPORTED_SCHEMA_VERSIONS.includes(input.schemaVersion as 1 | 2 | 3) || !Array.isArray(input.components) + || !input.components.length || input.components.length > (input.schemaVersion === 3 ? SKIN_PLUGIN_COMPONENT_LIMIT : 32)) { fail("SKIN_PLUGIN_DOCUMENT_INVALID", "components.json uses an unsupported schema or component count."); } const ids = new Set(); - const inputSchemaVersion = input.schemaVersion as 1 | 2; + const inputSchemaVersion = input.schemaVersion as 1 | 2 | 3; const components = input.components.map((rawComponent, componentIndex): SkinPluginComponent => { if (!isRecord(rawComponent)) fail("SKIN_PLUGIN_COMPONENT_INVALID", `Component ${componentIndex} must be an object.`); onlyKeys(rawComponent, new Set(["id", "name", "page", "mode", "accessibleName", "permissions", "actions", "state", "root"]), "Skin plugin component"); @@ -208,7 +282,7 @@ export function parseSkinPluginDocument(input: unknown): SkinPluginDocument { if (mode === "surface" && page === "demo") fail("SKIN_PLUGIN_COMPONENT_INVALID", "Page surfaces are supported only for the home and voice client pages."); const name = boundedText(rawComponent.name, "component.name", 80); const accessibleName = boundedText(rawComponent.accessibleName, "component.accessibleName", 120); - if (!Array.isArray(rawComponent.permissions) || rawComponent.permissions.length > 11) fail("SKIN_PLUGIN_PERMISSION_INVALID", "Each component may request at most eleven explicit permissions."); + if (!Array.isArray(rawComponent.permissions) || rawComponent.permissions.length > (inputSchemaVersion >= 3 ? 32 : 11)) fail("SKIN_PLUGIN_PERMISSION_INVALID", "A component requests too many explicit permissions."); const permissions: SkinPluginPermission[] = []; for (const permission of rawComponent.permissions) { if (typeof permission !== "string" || !PERMISSIONS.has(permission)) fail("SKIN_PLUGIN_PERMISSION_UNKNOWN", "The component requests an unsupported permission."); @@ -220,7 +294,7 @@ export function parseSkinPluginDocument(input: unknown): SkinPluginDocument { } const state: Record = Object.create(null) as Record; if (rawComponent.state !== undefined) { - if (!isRecord(rawComponent.state) || Object.keys(rawComponent.state).length > 32) fail("SKIN_PLUGIN_STATE_INVALID", "A component may declare up to 32 local state values."); + if (!isRecord(rawComponent.state) || Object.keys(rawComponent.state).length > (inputSchemaVersion >= 3 ? 64 : 32)) fail("SKIN_PLUGIN_STATE_INVALID", "A component declares too many local state values."); for (const [key, value] of Object.entries(rawComponent.state)) { identifier(key, "state.key"); if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") fail("SKIN_PLUGIN_STATE_INVALID", "Component state values must be scalar."); @@ -231,13 +305,14 @@ export function parseSkinPluginDocument(input: unknown): SkinPluginDocument { const stateKeys = new Set(Object.keys(state)); if (!isRecord(rawComponent.actions)) fail("SKIN_PLUGIN_ACTION_INVALID", "A component must declare an action map."); const actionEntries = Object.entries(rawComponent.actions); - if (actionEntries.length > 24) fail("SKIN_PLUGIN_ACTION_INVALID", "A component declares too many actions."); + if (actionEntries.length > (inputSchemaVersion >= 3 ? 64 : 24)) fail("SKIN_PLUGIN_ACTION_INVALID", "A component declares too many actions."); const actions: Record = Object.create(null) as Record; for (const [actionId, rawAction] of actionEntries) { identifier(actionId, "action.id"); if (!isRecord(rawAction)) fail("SKIN_PLUGIN_ACTION_INVALID", "An action must be an object."); onlyKeys(rawAction, new Set(["type", "args"]), "Component action"); if (typeof rawAction.type !== "string" || !ACTIONS.has(rawAction.type)) fail("SKIN_PLUGIN_ACTION_UNKNOWN", "An action type is not supported by the host."); + if (inputSchemaVersion < 3 && V3_ACTIONS.has(rawAction.type)) fail("SKIN_PLUGIN_SCHEMA_UNSUPPORTED", "This action requires components schema version 3."); if (!isRecord(rawAction.args)) fail("SKIN_PLUGIN_ACTION_INVALID", "An action must define an argument object."); const requiredPermission = ACTION_PERMISSION[rawAction.type as SkinPluginAction]; if (requiredPermission && !permissions.includes(requiredPermission)) fail("SKIN_PLUGIN_PERMISSION_MISSING", `The ${rawAction.type} action requires ${requiredPermission}.`); @@ -254,17 +329,24 @@ export function parseSkinPluginDocument(input: unknown): SkinPluginDocument { if (rawAction.type === "ui.setState" && (typeof args.key !== "string" || !/^[a-z][a-z0-9_-]{0,31}$/.test(args.key) || !stateKeys.has(args.key) || !("value" in args))) { fail("SKIN_PLUGIN_ACTION_INVALID", "ui.setState requires a local state key and value."); } + if (rawAction.type === "ui.toggleState" && (typeof args.key !== "string" || !/^[a-z][a-z0-9_-]{0,31}$/.test(args.key) || !stateKeys.has(args.key) || typeof state[args.key] !== "boolean")) { + fail("SKIN_PLUGIN_ACTION_INVALID", "ui.toggleState requires a declared boolean local state key."); + } if (rawAction.type === "voice.joinChannel" && typeof args.channelId !== "string") fail("SKIN_PLUGIN_ACTION_INVALID", "voice.joinChannel requires a channelId binding."); if (rawAction.type === "favorites.switch" && typeof args.favoriteId !== "string") fail("SKIN_PLUGIN_ACTION_INVALID", "favorites.switch requires a favoriteId binding."); if (rawAction.type === "quickServers.switch" && typeof args.quickServerId !== "string") fail("SKIN_PLUGIN_ACTION_INVALID", "quickServers.switch requires a quickServerId binding."); if (rawAction.type === "chat.sendMessage" && typeof args.text !== "string") fail("SKIN_PLUGIN_ACTION_INVALID", "chat.sendMessage requires a text binding."); + if (rawAction.type === "voice.setOutputVolume" && typeof args.volume !== "number" && typeof args.volume !== "string") fail("SKIN_PLUGIN_ACTION_INVALID", "voice.setOutputVolume requires a volume value."); + if (rawAction.type === "voice.setAway" && typeof args.away !== "boolean") fail("SKIN_PLUGIN_ACTION_INVALID", "voice.setAway requires an away boolean."); + if (rawAction.type === "voice.setWhisperActive" && typeof args.active !== "boolean") fail("SKIN_PLUGIN_ACTION_INVALID", "voice.setWhisperActive requires an active boolean."); + if (rawAction.type === "voice.joinScreenShare" && typeof args.streamId !== "string") fail("SKIN_PLUGIN_ACTION_INVALID", "voice.joinScreenShare requires a visible streamId."); actions[actionId] = { type: rawAction.type as SkinPluginAction, args }; } let componentNodes = 0; const walk = (rawNode: unknown, depth: number, aliases: ReadonlyMap = new Map()): SkinPluginNode => { componentNodes += 1; - if (componentNodes > SKIN_PLUGIN_NODE_LIMIT) fail("SKIN_PLUGIN_COMPLEXITY_LIMIT", "A component contains too many template nodes."); - if (depth > SKIN_PLUGIN_TREE_DEPTH_LIMIT || !isRecord(rawNode)) fail("SKIN_PLUGIN_TREE_INVALID", "A component tree is too deep or contains an invalid node."); + if (componentNodes > (inputSchemaVersion >= 3 ? SKIN_PLUGIN_NODE_LIMIT : 256)) fail("SKIN_PLUGIN_COMPLEXITY_LIMIT", "A component contains too many template nodes."); + if (depth > (inputSchemaVersion >= 3 ? SKIN_PLUGIN_TREE_DEPTH_LIMIT : 16) || !isRecord(rawNode)) fail("SKIN_PLUGIN_TREE_INVALID", "A component tree is too deep or contains an invalid node."); onlyKeys(rawNode, new Set(["widget", "tag", "text", "part", "className", "attributes", "asset", "bindValue", "repeat", "when", "events", "children"]), "Component node"); if (inputSchemaVersion === 1 && rawNode.widget !== undefined) fail("SKIN_PLUGIN_SCHEMA_UNSUPPORTED", "Host widgets require components schema version 2."); const nodeKinds = Number(rawNode.widget !== undefined) + Number(rawNode.tag !== undefined) + Number(rawNode.text !== undefined); @@ -293,11 +375,12 @@ export function parseSkinPluginDocument(input: unknown): SkinPluginDocument { node.className = rawNode.className; } if (rawNode.attributes !== undefined) { - if (!isRecord(rawNode.attributes) || Object.keys(rawNode.attributes).length > 24) fail("SKIN_PLUGIN_ATTRIBUTE_INVALID", "Component attributes must be a small object."); + if (!isRecord(rawNode.attributes) || Object.keys(rawNode.attributes).length > (inputSchemaVersion >= 3 ? 48 : 24)) fail("SKIN_PLUGIN_ATTRIBUTE_INVALID", "Component attributes must be a small object."); const attrs: Record = Object.create(null) as Record; for (const [key, value] of Object.entries(rawNode.attributes)) { const lowerKey = key.toLowerCase(); - if (!ATTRIBUTES.has(lowerKey) || lowerKey.startsWith("on") || key !== lowerKey) fail("SKIN_PLUGIN_ATTRIBUTE_INVALID", "The component uses an unsupported or executable attribute."); + const isAriaOrData = inputSchemaVersion >= 3 && /^(?:aria|data)-[a-z][a-z0-9-]{0,47}$/.test(lowerKey); + if ((!ATTRIBUTES.has(lowerKey) && !isAriaOrData) || lowerKey.startsWith("on") || key !== lowerKey) fail("SKIN_PLUGIN_ATTRIBUTE_INVALID", "The component uses an unsupported or executable attribute."); if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") fail("SKIN_PLUGIN_ATTRIBUTE_INVALID", "Component attributes must be scalar values."); if (typeof value === "string" && ["fill", "stroke"].includes(lowerKey) && /\burl\s*\(|javascript\s*:/i.test(value)) fail("SKIN_PLUGIN_ATTRIBUTE_INVALID", "SVG paint attributes cannot load external or executable resources."); if (typeof value === "string") { @@ -326,7 +409,7 @@ export function parseSkinPluginDocument(input: unknown): SkinPluginDocument { if (!isRecord(rawNode.repeat)) fail("SKIN_PLUGIN_REPEAT_INVALID", "A repeat declaration must be an object."); onlyKeys(rawNode.repeat, new Set(["path", "as"]), "Repeat declaration"); const path = boundedText(rawNode.repeat.path, "repeat.path", 120); - if (!(path === "session.channels" || path === "session.members" || path === "favorites.items" || path === "servers.quickList" || path === "chat.messages")) fail("SKIN_PLUGIN_REPEAT_INVALID", "A component may repeat only a registered public collection."); + if (!(path === "session.channels" || path === "session.members" || path === "favorites.items" || path === "servers.quickList" || path === "chat.messages" || path === "screenShare.streams")) fail("SKIN_PLUGIN_REPEAT_INVALID", "A component may repeat only a registered public collection."); const permission = COLLECTION_PERMISSION[path]; if (!permissions.includes(permission)) fail("SKIN_PLUGIN_PERMISSION_MISSING", `Repeating ${path} requires ${permission}.`); const alias = identifier(rawNode.repeat.as, "repeat.as"); @@ -345,12 +428,15 @@ export function parseSkinPluginDocument(input: unknown): SkinPluginDocument { node.when = { path, ...(equals === undefined ? {} : { equals }) }; } if (rawNode.events !== undefined) { - if (!isRecord(rawNode.events) || Object.keys(rawNode.events).length > 6) fail("SKIN_PLUGIN_EVENT_INVALID", "Component events must be a small object."); + if (!isRecord(rawNode.events) || Object.keys(rawNode.events).length > (inputSchemaVersion >= 3 ? 18 : 6)) fail("SKIN_PLUGIN_EVENT_INVALID", "Component events must be a small object."); const events: Partial> = {}; for (const [event, actionIdValue] of Object.entries(rawNode.events)) { - if (!EVENTS.has(event) || typeof actionIdValue !== "string" || !actions[actionIdValue]) fail("SKIN_PLUGIN_EVENT_INVALID", "Each component event must refer to a declared host action."); + if (!EVENTS.has(event) || (inputSchemaVersion < 3 && V3_EVENTS.has(event)) || typeof actionIdValue !== "string" || !actions[actionIdValue]) fail("SKIN_PLUGIN_EVENT_INVALID", "Each component event must refer to a declared host action supported by this schema."); const action = actions[actionIdValue]; if (action.type !== "ui.setState" && (event === "input" || event === "change")) fail("SKIN_PLUGIN_EVENT_INVALID", "Host actions cannot run while a form value is being typed or changed."); + if (action.type !== "ui.setState" && action.type !== "ui.toggleState" && PASSIVE_EVENTS.has(event)) { + fail("SKIN_PLUGIN_EVENT_INVALID", "Voice and host actions require an explicit user activation event."); + } for (const argument of Object.values(action.args)) { if (typeof argument !== "string") continue; for (const permission of bindingPermissions(argument, aliases, stateKeys)) { @@ -362,7 +448,7 @@ export function parseSkinPluginDocument(input: unknown): SkinPluginDocument { node.events = events; } if (rawNode.children !== undefined) { - if (!Array.isArray(rawNode.children) || rawNode.children.length > 100) fail("SKIN_PLUGIN_TREE_INVALID", "A component node contains too many children."); + if (!Array.isArray(rawNode.children) || rawNode.children.length > (inputSchemaVersion >= 3 ? 256 : 100)) fail("SKIN_PLUGIN_TREE_INVALID", "A component node contains too many children."); if (node.tag && VOID_ELEMENTS.has(node.tag) && rawNode.children.length) fail("SKIN_PLUGIN_TREE_INVALID", "A void element cannot contain child nodes."); const childAliases = new Map(aliases); if (node.repeat) childAliases.set(node.repeat.as, node.repeat.path); @@ -395,7 +481,7 @@ export function parseSkinPluginDocument(input: unknown): SkinPluginDocument { visit(component.root); widgetsByPage.set(component.page, pageWidgets); } - return { schemaVersion: SKIN_PLUGIN_SCHEMA_VERSION, components }; + return { schemaVersion: inputSchemaVersion, components }; } export function parseSkinPluginJson(source: string): SkinPluginDocument { diff --git a/web/src/components/SkinPluginOutlet.ts b/web/src/components/SkinPluginOutlet.ts index 10bf63a..3e3ae8d 100644 --- a/web/src/components/SkinPluginOutlet.ts +++ b/web/src/components/SkinPluginOutlet.ts @@ -1,6 +1,7 @@ import { computed, defineComponent, Fragment, h, onUnmounted, reactive, ref, Teleport, watch, type PropType, type VNodeChild } from "vue"; import { SKIN_PLUGIN_PERMISSIONS, + SKIN_PLUGIN_REPEAT_LIMIT, parseSkinPluginDocument, type SkinPluginActionDefinition, type SkinPluginComponent, @@ -16,7 +17,9 @@ type HostAction = (args: Record, component: SkinPluginComponent) type HostWidget = () => VNodeChild; const eventProps: Record = { - click: "onClick", dblclick: "onDblclick", change: "onChange", input: "onInput", submit: "onSubmit", keydown: "onKeydown", + click: "onClick", dblclick: "onDblclick", change: "onChange", input: "onInput", submit: "onSubmit", keydown: "onKeydown", keyup: "onKeyup", + contextmenu: "onContextmenu", focus: "onFocus", blur: "onBlur", pointerdown: "onPointerdown", pointerup: "onPointerup", + pointerenter: "onPointerenter", pointerleave: "onPointerleave", dragstart: "onDragstart", dragover: "onDragover", drop: "onDrop", }; export default defineComponent({ @@ -118,6 +121,12 @@ export default defineComponent({ if (typeof args.key === "string" && component.state && Object.hasOwn(component.state, args.key) && "value" in args) state[args.key] = args.value; return; } + if (definition.type === "ui.toggleState") { + if (typeof args.key === "string" && component.state && Object.hasOwn(component.state, args.key) && typeof state[args.key] === "boolean") { + state[args.key] = !state[args.key]; + } + return; + } const handler = props.actions[definition.type]; if (handler) void Promise.resolve(handler(args, component)).catch(() => undefined); } @@ -149,7 +158,8 @@ export default defineComponent({ if (!skipRepeat && node.repeat) { const values = resolvePath(node.repeat.path, context, state); if (!Array.isArray(values)) return null; - return h(Fragment, null, values.slice(0, 100).map((value) => renderNode(component, node, { ...context, [node.repeat!.as]: value }, state, true))); + const repeatLimit = props.document.schemaVersion >= 3 ? SKIN_PLUGIN_REPEAT_LIMIT : 100; + return h(Fragment, null, values.slice(0, repeatLimit).map((value) => renderNode(component, node, { ...context, [node.repeat!.as]: value }, state, true))); } if (node.when) { const value = resolvePath(node.when.path, context, state); @@ -174,7 +184,9 @@ export default defineComponent({ if (!propName) continue; attrs[propName] = (event: Event) => { if (!event.isTrusted) return; - if (eventName === "keydown" && event instanceof KeyboardEvent && event.key !== "Enter" && event.key !== " ") return; + if ((eventName === "keydown" || eventName === "keyup") && event instanceof KeyboardEvent + && event.key !== "Enter" && event.key !== " " && event.key !== "Escape") return; + if (eventName === "contextmenu" || eventName === "dragover") event.preventDefault(); if (node.bindValue && eventName === "input" && (event.target instanceof HTMLInputElement || event.target instanceof HTMLTextAreaElement)) { state[node.bindValue] = event.target instanceof HTMLInputElement && event.target.type === "checkbox" ? event.target.checked : event.target.value; } else if (node.bindValue && eventName === "change" && (event.target instanceof HTMLInputElement || event.target instanceof HTMLSelectElement || event.target instanceof HTMLTextAreaElement)) { diff --git a/web/src/views/WebClient.vue b/web/src/views/WebClient.vue index 0580f0b..c46417f 100644 --- a/web/src/views/WebClient.vue +++ b/web/src/views/WebClient.vue @@ -1507,6 +1507,34 @@ const skinPluginContext = computed(() => ({ channelId: message.targetId ?? currentChannel.value?.id ?? "", })), }, + audio: { + status: { + microphoneMuted: microphoneMuted.value, + outputMuted: outputMuted.value, + }, + }, + whisper: { + status: { + active: whisperActive.value, + targetCount: whisperTargetIds.size, + }, + }, + screenShare: { + status: { + active: screenShareActive.value, + starting: screenShareStarting.value, + viewing: screenShareViewing.value, + }, + streams: screenShareStreams.map((stream) => ({ + streamId: stream.streamId, + source: stream.source, + ownerClientId: stream.ownerClientId ?? 0, + ownerNickname: stream.ownerNickname, + name: stream.name, + audio: stream.audio, + viewerCount: stream.viewerCount, + })), + }, })); const skinPluginActions = { @@ -1531,6 +1559,31 @@ const skinPluginActions = { if (!text || text.length > 1000 || text.includes("\u0000")) return; void sendTextMessage(text, currentChannel.value.id); }, + "voice.toggleMicrophone": () => { if (voiceState.connected) toggleMicrophone(); }, + "voice.toggleOutputMute": () => { if (voiceState.connected) toggleOutputMute(); }, + "voice.setOutputVolume": (args: Record) => { + if (!voiceState.connected || typeof args.volume !== "number" || !Number.isFinite(args.volume)) return; + setOutputVolume(Math.max(0, Math.min(1, args.volume))); + }, + "voice.disconnect": () => { if (voiceState.connected || voiceState.connecting) doDisconnect(); }, + "voice.setAway": (args: Record) => { + if (!voiceState.connected || typeof args.away !== "boolean") return; + const message = typeof args.message === "string" ? args.message.slice(0, 200) : ""; + setAway(args.away, message); + }, + "voice.setWhisperActive": (args: Record) => { + if (!voiceState.connected || typeof args.active !== "boolean") return; + setWhisperActive(args.active); + }, + "voice.startScreenShare": () => { + if (voiceState.connected && !screenShareActive.value && !screenShareStarting.value) void startScreenShare(); + }, + "voice.stopScreenShare": () => { if (screenShareActive.value) stopScreenShare(); }, + "voice.joinScreenShare": (args: Record) => { + if (!voiceState.connected || typeof args.streamId !== "string") return; + if (screenShareStreams.some((stream) => stream.streamId === args.streamId)) joinScreenShare(args.streamId); + }, + "voice.leaveScreenShare": () => { if (screenShareViewing.value) leaveScreenShare(); }, }; const skinPluginWidgets = {