From b0b4a02a2192f89dc8a7cdb2607e364d92082df0 Mon Sep 17 00:00:00 2001 From: illusia <64828020+EchoSixHIYA@users.noreply.github.com> Date: Sat, 10 Oct 2026 08:10:02 +0800 Subject: [PATCH] feat(skin): preserve screen share user gesture --- docs/OPEN_SKIN_SYSTEM_ROADMAP.zh-CN.md | 2 +- docs/OPEN_SKIN_SYSTEM_SPEC.zh-CN.md | 4 +- docs/SKIN_DEVELOPMENT.md | 2 +- src/shared/skin-extension-ui.ts | 67 ++++++++++++++++--- src/shared/skin-plugin.test.ts | 12 ++++ src/shared/skin-plugin.ts | 6 ++ web/src/components/SkinPluginOutlet.ts | 17 ++++- web/src/components/SkinRuntimePluginHost.ts | 5 +- web/src/services/skin-extension-ui.test.ts | 27 ++++++++ .../services/skin-extension-wasm-ui-loop.ts | 4 +- .../skin-runtime-plugin-session.test.ts | 50 ++++++++++++++ .../services/skin-runtime-plugin-session.ts | 3 +- web/src/styles/skin-plugin.css | 19 ++++++ web/src/views/WebClient.vue | 10 +++ 14 files changed, 209 insertions(+), 19 deletions(-) diff --git a/docs/OPEN_SKIN_SYSTEM_ROADMAP.zh-CN.md b/docs/OPEN_SKIN_SYSTEM_ROADMAP.zh-CN.md index 5761604..77347b0 100644 --- a/docs/OPEN_SKIN_SYSTEM_ROADMAP.zh-CN.md +++ b/docs/OPEN_SKIN_SYSTEM_ROADMAP.zh-CN.md @@ -44,7 +44,7 @@ schema v2 支持公开组件布局、桌面/平板/手机配置、本地覆盖 - Wasm 有界输入协议新增 `env.ui_input_read`:每次运行最多读取一次、最多 64 KiB 的 JSON,包含插件本地标量状态、单个安全事件和按权限投影的公开数据快照(快照最多 48 KiB)。频道、成员、聊天、收藏/历史、音频、悄悄话、屏幕共享数据只输出清单声明权限对应的字段;地址、凭据、SDK 对象与未知字段不会进入 guest。UI 事件只在浏览器 `isTrusted` 事件触发时由宿主组件发出;DOM/Event 对象不跨边界,只传事件名、组件/处理器 ID,以及受限的键盘或输入值字段。生成的密码、文件和隐藏输入会拒绝;输入值与状态还会二次限长验证。协议不含“trusted”自报字段,作者代码不能把字段伪装成宿主授权。 - 新增开发原型 `skin-extension-wasm-ui-loop`,把初始渲染、可信 UI 回调、授权数据变化建模为逐次 Wasm Worker 调用:每次回调按先后顺序执行、最多排队 8 项;调用前重新检查回调 ID 与上次生成的 UI 一致,输入状态键只能来自该组件声明;输出再次经过 schema 4/5/6 校验。关闭时终止当前 Worker、清空等待队列。宿主动作只能跟随可信 UI 回调,不会从初始渲染或数据刷新触发。 - `SkinRuntimePlugin` 已接入权限化数据投影和首版宿主动作桥:插件需通过摘要绑定授权后才能运行;每次调用只收到清单允许的、经字段白名单筛选的数据副本。数据变化会在 100 ms 合并窗口后触发下一次独立调用。动作请求只接受 schema v6 单个宿主动作效果,且必须来自可信 UI 事件触发的同一轮 Wasm 调用;宿主再按插件声明权限和现有会话状态校验。Wasm 仍为开发原型,生产开关关闭;插件商城、widget 布局和安全审查未完成。 -- 该动作桥是有界原型,不代表浏览器瞬时用户激活可跨越异步 Wasm 执行:屏幕共享等要求瞬时手势的 API 仍需真实浏览器验证。后续需完成插件布局与安装管理、端到端验证,并评估不同浏览器的资源和事件边界。 +- 该动作桥是有界原型,不代表浏览器瞬时用户激活可跨越异步 Wasm 执行。已为动态 UI 增加经 `voice.screenShare.control` 权限门控的 `voice.screen-share-start` 宿主按钮,并在可信点击处理器内直接调用屏幕采集入口。仍需在支持的浏览器中端到端验证按钮、授权和系统选择器行为;后续还需完成插件布局与安装管理,并评估不同浏览器的资源和事件边界。 - 这是一次性输出的受限原型,不构成完整插件运行时。生产开关关闭;后续须更换为有版本、权限、事件、生命周期和资源治理的插件协议,并做端到端与独立安全审查。 ### R3.3:完整自定义插件运行时(未完成,优先阶段) diff --git a/docs/OPEN_SKIN_SYSTEM_SPEC.zh-CN.md b/docs/OPEN_SKIN_SYSTEM_SPEC.zh-CN.md index 8dc389e..26a6034 100644 --- a/docs/OPEN_SKIN_SYSTEM_SPEC.zh-CN.md +++ b/docs/OPEN_SKIN_SYSTEM_SPEC.zh-CN.md @@ -16,13 +16,13 @@ v3 自定义组件不是脚本插件。components.json schema v1 是既有格式;schema v2 增加 `mode: "surface"` 与宿主控件节点;schema v3 扩大自定义节点、嵌套、重复列表和声明式交互的边界,并增加映射到现有语音功能的动作。宿主仍解析固定元素/属性白名单、固定数据集合、简单绑定与有限动作,再由 Vue 创建节点。每个自定义组件根和每个有 DOM 的节点都会作为独立本地布局项,可移动、调整尺寸、改变外观或隐藏。节点指定 `part` 后使用该标识;未指定时使用树路径,树结构调整后旧的本地覆盖可能要重新设置。可操作节点保留至少 44 px 的触控目标。作者不必使用固定宿主控件目录,但 v3 仍不足以表达任意自定义 UI 逻辑和完整插件生命周期。管理员面板和演示页不能被 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.screen-share-start`、`voice.whisper-controls`、`voice.performance-panel`、`voice.connection-controls` 和 `voice.disconnect-control`。每个控件在同一页面最多出现一次;未知 ID 或重复的有状态控件会拒绝导入。`voice.screen-share-start` 仅限语音页,并要求插件声明 `voice.screenShare.control`;宿主按钮在可信点击处理器内直接开始屏幕采集,以保留浏览器要求的瞬时用户激活。作者可以不用这些控件,自行绘制界面并将点击、双击等事件绑定到公开数据与受权限保护的动作。 v1-v3 包不能提交 HTML 字符串、事件处理代码、JavaScript、WebAssembly、远程脚本、任意 URL、表单导航、浏览器存储访问或网络调用。v4 可携带本地 JS/Wasm/CSS;JS 仍只校验和缓存,Wasm 在开发构建中经本地摘要授权后运行一次性有界任务,并经宿主解析、渲染动态 UI。运行时支持 `ui.surface.replace`、限定的公开只读数据权限和首版宿主动作效果;投影前由宿主按插件清单过滤字段,总快照最多 48 KiB,`ui_input_read` 输入最多 64 KiB。动作效果限于可信 UI 事件触发的同一轮调用、单个动作,并复用现有动作权限与参数校验。生产构建关闭 Wasm 执行。未知字段、元素、动作、数据路径、控件和权限一律拒绝。 ### 2.1 插件协议(v4 包格式已实现,受限开发运行时已接入) -已实现的 v4 包描述为 `plugins.json` schema v1:每包 1–64 个插件,每个插件指定唯一小写 ID、语义版本、API 版本 1、`home`/`voice` 页面、`widget`/`surface` 模式、`plugins//` 下入口 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 装载;生产构建仍关闭执行。 +已实现的 v4 包描述为 `plugins.json` schema v1:每包 1–64 个插件,每个插件指定唯一小写 ID、语义版本、API 版本 1、`home`/`voice` 页面、`widget`/`surface` 模式、`plugins//` 下入口 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 装载;生产构建仍关闭执行。动态 UI 可使用经过 manifest 权限校验的 `voice.screen-share-start` 宿主按钮;异步 Wasm 动作桥本身不承载屏幕采集所需的瞬时用户激活。 当前 descriptor 没有定义 widget 的宿主挂载位置或默认显隐。每个运行时插件有独立布局根;用户可用通用布局编辑器本地覆盖插件整体、插件组件根和其节点的位置、尺寸、显隐、安全外观及 Flex/Grid 同级顺序。顺序只改视觉排列,不改变 DOM 与键盘焦点顺序。这些用户数据与作者文件分开存储。完整运行时仍需定义默认挂载和布局值是否由皮肤包分发,并确保沙箱内代码不能改动其他插件的宿主容器或恢复控件。 diff --git a/docs/SKIN_DEVELOPMENT.md b/docs/SKIN_DEVELOPMENT.md index 10ac4e3..9164727 100644 --- a/docs/SKIN_DEVELOPMENT.md +++ b/docs/SKIN_DEVELOPMENT.md @@ -146,7 +146,7 @@ components.json 顶层接受 schemaVersion 1、2 或 3 和 components 数组。s } ``` -当前可选宿主控件 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 已有操作,屏幕采集仍由浏览器或操作系统询问用户。 +当前可选宿主控件 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.screen-share-start`、`voice.whisper-controls`、`voice.performance-panel`、`voice.connection-controls`、`voice.disconnect-control`。未知控件和同页重复控件会被拒绝;每个控件的状态和业务动作仍由 WebSpeak 内部处理。`voice.screen-share-start` 仅能放在语音页,并要求 `voice.screenShare.control`;宿主按钮在可信点击处理器内直接启动屏幕采集,避免异步 Wasm 回调丢失浏览器瞬时用户激活。自定义 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,是格式验证脚手架。KAAK 的语音视觉参考来自用户授权进入的前两个语音房间;只记录布局,不保留服务器/房间标识、成员名或聊天内容。当前数据权限和宿主动作以[开放皮肤规格](./OPEN_SKIN_SYSTEM_SPEC.zh-CN.md)中的清单为准。组件按本地用户授权后才渲染;权限对每个皮肤版本、页面和组件分别保存,可在宿主权限入口撤销。页面替换时,宿主会额外显示“返回标准界面”和“恢复内置皮肤”入口;拒绝授权或离开 surface 后,普通页面可立即恢复。 diff --git a/src/shared/skin-extension-ui.ts b/src/shared/skin-extension-ui.ts index 0ed0870..4a54f4b 100644 --- a/src/shared/skin-extension-ui.ts +++ b/src/shared/skin-extension-ui.ts @@ -1,5 +1,7 @@ import { SKIN_PLUGIN_PERMISSIONS, + SKIN_PLUGIN_HOST_WIDGETS, + SKIN_PLUGIN_HOST_WIDGET_PERMISSIONS, parseSkinPluginRuntimeAction, SKIN_PLUGIN_NODE_LIMIT, SKIN_PLUGIN_TREE_DEPTH_LIMIT, @@ -9,6 +11,7 @@ import { type SkinPluginComponent, type SkinPluginDocument, type SkinPluginNode, + type SkinPluginHostWidget, type SkinPluginPermission, } from "./skin-plugin.js"; import { parseSkinExtensionUiInput, SKIN_EXTENSION_UI_EVENT_NAMES } from "./skin-extension-ui-input.js"; @@ -17,6 +20,7 @@ export const SKIN_EXTENSION_UI_OUTPUT_LIMIT_BYTES = 16 * 1024; const LOCAL_UI_ACTIONS = new Set(["ui.setState", "ui.toggleState"]); const GENERATED_COMPONENT_LIMIT = 64; +const GENERATED_RUNTIME_HOST_WIDGETS = new Set(["voice.screen-share-start"]); const GENERATED_CHILD_LIMIT = 256; const GENERATED_ATTRIBUTE_LIMIT = 64; const GENERATED_BLOCKED_ELEMENTS = new Set([ @@ -82,17 +86,51 @@ function onlyKeys(value: Record, allowed: readonly string[], co if (Object.keys(value).some((key) => !allowed.includes(key))) fail("SKIN_EXTENSION_UI_OUTPUT_SCHEMA", `${context} has an unsupported field.`); } -function generatedNode(input: unknown, depth: number, count: { value: number }, allowEvents: boolean): SkinPluginNode { +function generatedNode( + input: unknown, + depth: number, + count: { value: number }, + allowEvents: boolean, + page: "home" | "voice", + permissions: readonly SkinPluginPermission[], +): SkinPluginNode { count.value += 1; if (count.value > SKIN_PLUGIN_NODE_LIMIT || depth > SKIN_PLUGIN_TREE_DEPTH_LIMIT || !isRecord(input)) { fail("SKIN_EXTENSION_UI_COMPLEXITY_LIMIT", "The generated UI tree exceeds its node or depth limit."); } - onlyKeys(input, ["tag", "text", "part", "className", "attributes", "asset", "children", ...(allowEvents ? ["events"] : [])], "A generated UI node"); + onlyKeys(input, ["widget", "tag", "text", "part", "className", "attributes", "asset", "children", ...(allowEvents ? ["events"] : [])], "A generated UI node"); + const hasWidget = input.widget !== undefined; const hasTag = input.tag !== undefined; const hasText = input.text !== undefined; - if (Number(hasTag) + Number(hasText) !== 1) fail("SKIN_EXTENSION_UI_OUTPUT_SCHEMA", "A generated node must contain either a tag or text."); + if (Number(hasWidget) + Number(hasTag) + Number(hasText) !== 1) fail("SKIN_EXTENSION_UI_OUTPUT_SCHEMA", "A generated node must contain exactly one widget, tag, or text."); const node: SkinPluginNode = {}; + if (hasWidget) { + if (typeof input.widget !== "string" || !SKIN_PLUGIN_HOST_WIDGETS.includes(input.widget as SkinPluginHostWidget) + || !GENERATED_RUNTIME_HOST_WIDGETS.has(input.widget as SkinPluginHostWidget)) { + fail("SKIN_EXTENSION_UI_WIDGET_UNSUPPORTED", "The generated UI requested a host widget that is not available to runtime plugins."); + } + if (page !== "voice") fail("SKIN_EXTENSION_UI_WIDGET_UNSUPPORTED", "The screen-share host widget is available only on the voice page."); + const widget = input.widget as SkinPluginHostWidget; + const requiredPermission = SKIN_PLUGIN_HOST_WIDGET_PERMISSIONS[widget]; + if (requiredPermission && !permissions.includes(requiredPermission)) { + fail("SKIN_EXTENSION_UI_PERMISSION_MISSING", `The ${widget} widget requires ${requiredPermission}.`); + } + onlyKeys(input, ["widget", "part", "className"], "A generated host widget node"); + node.widget = widget; + if (input.part !== undefined) { + const part = boundedText(input.part, 64, "SKIN_EXTENSION_UI_OUTPUT_SCHEMA", "node.part"); + if (!/^[a-z][a-z0-9-]*$/.test(part)) fail("SKIN_EXTENSION_UI_OUTPUT_SCHEMA", "A generated part uses an invalid name."); + node.part = part; + } + if (input.className !== undefined) { + if (typeof input.className !== "string" || input.className.length > 512 || /[<>\u0000-\u001f]/.test(input.className)) { + fail("SKIN_EXTENSION_UI_OUTPUT_SCHEMA", "Generated class names must be bounded plain text."); + } + node.className = input.className; + } + return node; + } if (hasText) { if (typeof input.text !== "string" || input.text.length > 8_192) fail("SKIN_EXTENSION_UI_OUTPUT_SCHEMA", "Generated text exceeds its limit."); node.text = input.text; @@ -175,12 +213,17 @@ function generatedNode(input: unknown, depth: number, count: { value: number }, if (node.tag && GENERATED_VOID_ELEMENTS.has(node.tag) && input.children.length > 0) { fail("SKIN_EXTENSION_UI_OUTPUT_SCHEMA", "Void generated elements cannot contain children."); } - node.children = input.children.map((child) => generatedNode(child, depth + 1, count, allowEvents)); + node.children = input.children.map((child) => generatedNode(child, depth + 1, count, allowEvents, page, permissions)); } return node; } -function parseGeneratedDocument(input: Record, allowEvents: boolean, allowRequest = false): SkinPluginDocument { +function parseGeneratedDocument( + input: Record, + allowEvents: boolean, + allowRequest = false, + permissions: readonly SkinPluginPermission[] = [], +): SkinPluginDocument { onlyKeys(input, ["schemaVersion", "components", ...(allowRequest ? ["request"] : [])], "Generated UI document"); if (!Array.isArray(input.components) || input.components.length < 1 || input.components.length > GENERATED_COMPONENT_LIMIT) { fail("SKIN_EXTENSION_UI_OUTPUT_SCHEMA", "The generated document has an unsupported component count."); @@ -195,7 +238,7 @@ function parseGeneratedDocument(input: Record, allowEvents: boo const name = boundedText(raw.name, 80, "SKIN_EXTENSION_UI_OUTPUT_SCHEMA", "component.name"); const accessibleName = boundedText(raw.accessibleName, 120, "SKIN_EXTENSION_UI_OUTPUT_SCHEMA", "component.accessibleName"); if (raw.page !== "home" && raw.page !== "voice") fail("SKIN_EXTENSION_UI_OUTPUT_SCHEMA", "Generated components may target only the public home or voice page."); - const root = generatedNode(raw.root, 1, { value: 0 }, allowEvents); + const root = generatedNode(raw.root, 1, { value: 0 }, allowEvents, raw.page, permissions); if (!root.tag) fail("SKIN_EXTENSION_UI_OUTPUT_SCHEMA", "A generated component root must be an element."); const state = allowEvents ? parseSkinExtensionUiInput({ schemaVersion: 1, state: raw.state ?? {}, event: null }).state @@ -235,12 +278,16 @@ export function parseSkinExtensionUiActionRequest( } /** Parses bounded Wasm output. Schema 5 adds trusted callbacks; schema 6 adds one permission-checked host action effect. */ -export function parseSkinExtensionUiOutput(source: string): SkinPluginDocument { +export function parseSkinExtensionUiOutput( + source: string, + options: { permissions?: readonly SkinPluginPermission[] } = {}, +): SkinPluginDocument { const input = parseOutputInput(source); - if (input.schemaVersion === 4) return parseGeneratedDocument(input, false); - if (input.schemaVersion === 5) return parseGeneratedDocument(input, true); + const permissions = options.permissions ?? []; + if (input.schemaVersion === 4) return parseGeneratedDocument(input, false, false, permissions); + if (input.schemaVersion === 5) return parseGeneratedDocument(input, true, false, permissions); if (input.schemaVersion === 6) { - const document = parseGeneratedDocument(input, true, true); + const document = parseGeneratedDocument(input, true, true, permissions); if (input.request !== undefined) { try { parseSkinPluginRuntimeAction(input.request, Object.keys(SKIN_PLUGIN_PERMISSIONS) as SkinPluginPermission[]); } catch { fail("SKIN_EXTENSION_UI_ACTION_INVALID", "The generated host action request is malformed."); } diff --git a/src/shared/skin-plugin.test.ts b/src/shared/skin-plugin.test.ts index ca4908b..141339f 100644 --- a/src/shared/skin-plugin.test.ts +++ b/src/shared/skin-plugin.test.ts @@ -132,6 +132,18 @@ test("host widget references stay allowlisted and cannot be used on the demo pag errorCode(() => parseSkinPluginDocument(demoWidget), "SKIN_PLUGIN_WIDGET_INVALID"); }); +test("starting screen share from a skin host widget requires its own permission", () => { + const document = validDocument(); + document.schemaVersion = 2; + document.components[0].root = { tag: "main", children: [{ widget: "voice.screen-share-start" }] }; + errorCode(() => parseSkinPluginDocument(document), "SKIN_PLUGIN_PERMISSION_MISSING"); + + document.components[0].permissions = ["voice.screenShare.control"]; + document.components[0].actions = {}; + const parsed = parseSkinPluginDocument(document); + assert.equal(parsed.components[0].root.children?.[0].widget, "voice.screen-share-start"); +}); + test("KAAK v3 example splits validated channel and member data by component", async () => { const source = await readFile(new URL("../../docs/examples/kaak-voice/components.json", import.meta.url), "utf8"); const parsed = parseSkinPluginJson(source); diff --git a/src/shared/skin-plugin.ts b/src/shared/skin-plugin.ts index d0128d1..1b6d76f 100644 --- a/src/shared/skin-plugin.ts +++ b/src/shared/skin-plugin.ts @@ -47,12 +47,16 @@ export const SKIN_PLUGIN_HOST_WIDGETS = Object.freeze([ "voice.chat-panel", "voice.audio-controls", "voice.screen-share-player", + "voice.screen-share-start", "voice.whisper-controls", "voice.performance-panel", "voice.connection-controls", "voice.disconnect-control", ] as const); export type SkinPluginHostWidget = typeof SKIN_PLUGIN_HOST_WIDGETS[number]; +export const SKIN_PLUGIN_HOST_WIDGET_PERMISSIONS: Partial> = Object.freeze({ + "voice.screen-share-start": "voice.screenShare.control", +}); export type SkinPluginEvent = | "click" | "dblclick" | "change" | "input" | "submit" | "keydown" | "keyup" | "contextmenu" | "focus" | "blur" | "pointerdown" | "pointerup" @@ -361,6 +365,8 @@ export function parseSkinPluginDocument(input: unknown): SkinPluginDocument { if (rawNode.widget !== undefined) { if (typeof rawNode.widget !== "string" || !HOST_WIDGETS.has(rawNode.widget)) fail("SKIN_PLUGIN_WIDGET_INVALID", "The component requests an unsupported host widget."); if (page === "demo") fail("SKIN_PLUGIN_WIDGET_INVALID", "Host widgets are available only on the home and voice client pages."); + const requiredPermission = SKIN_PLUGIN_HOST_WIDGET_PERMISSIONS[rawNode.widget as SkinPluginHostWidget]; + if (requiredPermission && !permissions.includes(requiredPermission)) fail("SKIN_PLUGIN_PERMISSION_MISSING", `The ${rawNode.widget} widget requires ${requiredPermission}.`); const widgetOnlyKeys = new Set(["widget", "part", "className", "when"]); onlyKeys(rawNode, widgetOnlyKeys, "Host widget node"); node.widget = rawNode.widget as SkinPluginHostWidget; diff --git a/web/src/components/SkinPluginOutlet.ts b/web/src/components/SkinPluginOutlet.ts index 98410ae..8bfce48 100644 --- a/web/src/components/SkinPluginOutlet.ts +++ b/web/src/components/SkinPluginOutlet.ts @@ -11,6 +11,7 @@ import { type SkinPluginDocument, type SkinPluginHostWidget, type SkinPluginNode, + type SkinPluginPermission, } from "../../../src/shared/skin-plugin.js"; import { parseSkinExtensionUiOutput } from "../../../src/shared/skin-extension-ui.js"; import { parseSkinExtensionUiInput } from "../../../src/shared/skin-extension-ui-input.js"; @@ -35,6 +36,7 @@ export default defineComponent({ document: { type: Object as PropType, required: true }, extensionOutput: { type: String as PropType, default: null }, extensionMode: { type: String as PropType, default: undefined }, + extensionPermissions: { type: Array as PropType, default: () => [] }, componentNamespace: { type: String, default: "" }, manageSurfaceRecovery: { type: Boolean, default: true }, page: { type: String as PropType<"home" | "voice" | "demo">, required: true }, @@ -57,11 +59,21 @@ export default defineComponent({ const objectUrls = new Map(); const validatedDocument = computed(() => { let document: SkinPluginDocument; - try { document = parseSkinPluginDocument(props.document); } + const emptyRuntimeBase = Boolean(props.extensionOutput) + && props.document.schemaVersion === 3 + && Array.isArray(props.document.components) + && props.document.components.length === 0; + try { + // Runtime plugins use an empty v3 base document so their validated generated output + // can flow through the same approval, layout, and rendering path as packaged components. + document = emptyRuntimeBase + ? { schemaVersion: 3, components: [] } + : parseSkinPluginDocument(props.document); + } catch { return { schemaVersion: 2 as const, components: [] }; } if (!props.extensionOutput || document.schemaVersion !== 3) return document; try { - const parsedExtensionDocument = parseSkinExtensionUiOutput(props.extensionOutput); + const parsedExtensionDocument = parseSkinExtensionUiOutput(props.extensionOutput, { permissions: props.extensionPermissions }); const extensionDocument = props.extensionMode ? { ...parsedExtensionDocument, components: parsedExtensionDocument.components.map((component) => ({ ...component, mode: props.extensionMode })) } : parsedExtensionDocument; @@ -192,6 +204,7 @@ export default defineComponent({ function layoutPart(component: SkinPluginComponent, node: SkinPluginNode, nodePath: string): string { const interactive = ["a", "button", "input", "select", "summary", "textarea"].includes(node.tag ?? "") + || node.widget === "voice.screen-share-start" || node.attributes?.role === "button" || ["click", "dblclick", "contextmenu", "keydown", "keyup", "pointerdown", "pointerup", "drop"] .some((eventName) => Boolean(node.events?.[eventName as keyof typeof node.events])); diff --git a/web/src/components/SkinRuntimePluginHost.ts b/web/src/components/SkinRuntimePluginHost.ts index c2dd8b7..2f6b12e 100644 --- a/web/src/components/SkinRuntimePluginHost.ts +++ b/web/src/components/SkinRuntimePluginHost.ts @@ -3,7 +3,7 @@ import type { SkinExtensionSessionStatus } from "../../../src/shared/skin-extens 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 { SKIN_PLUGIN_ACTION_PERMISSIONS, skinPluginActionPermission, type SkinPluginAction, type SkinPluginDocument } from "../../../src/shared/skin-plugin.js"; +import { SKIN_PLUGIN_ACTION_PERMISSIONS, skinPluginActionPermission, type SkinPluginAction, type SkinPluginDocument, type SkinPluginHostWidget } from "../../../src/shared/skin-plugin.js"; import { SKIN_RUNTIME_PLUGIN_DATA_PERMISSIONS } from "../../../src/shared/skin-runtime-plugin-context.js"; import SkinPluginOutlet from "./SkinPluginOutlet.js"; import { approveSkinRuntimePlugin, getSkinRuntimePluginApproval, revokeSkinRuntimePluginApprovals } from "../services/skin-runtime-plugin-approval.js"; @@ -91,6 +91,7 @@ export default defineComponent({ page: { type: String as PropType, required: true }, context: { type: Object as PropType>, default: () => ({}) }, actions: { type: Object as PropType>>, default: () => ({}) }, + widgets: { type: Object as PropType VNodeChild>>>, default: () => ({}) }, readSessionStatus: { type: Function as PropType<(signal: AbortSignal) => SkinExtensionSessionStatus | Promise>, required: true }, }, emits: { @@ -351,6 +352,8 @@ export default defineComponent({ data: {}, assets: pluginAssets, actions: {}, + extensionPermissions: plugin.permissions, + widgets: props.widgets, onExtensionEvent: (event: unknown) => dispatch(plugin.id, event), onSurfaceChange: (active: boolean) => surfaceChanged(plugin.id, active), onRestoreSkin: () => emit("restore-skin"), diff --git a/web/src/services/skin-extension-ui.test.ts b/web/src/services/skin-extension-ui.test.ts index 9d3ca61..4b73567 100644 --- a/web/src/services/skin-extension-ui.test.ts +++ b/web/src/services/skin-extension-ui.test.ts @@ -81,6 +81,33 @@ test("generated UI supports broad safe markup, ARIA/data attributes, and inert c assert.equal(document.components[0].root.children?.[1].tag, "button"); }); +test("generated screen-share host widget requires permission and renders as an interactive host control", async () => { + const source = generatedOutput("share-control", { + tag: "section", + children: [{ widget: "voice.screen-share-start", part: "start-share" }], + }); + expectOutputError(source, "SKIN_EXTENSION_UI_PERMISSION_MISSING"); + + const permissions = ["voice.screenShare.control"] as const; + const document = parseSkinExtensionUiOutput(source, { permissions }); + assert.equal(document.components[0].root.children?.[0].widget, "voice.screen-share-start"); + const html = await renderToString(createSSRApp(SkinPluginOutlet, { + skinId: "community.test", + skinVersion: "1.0.0", + document: { schemaVersion: 3, components: [] }, + extensionOutput: source, + extensionPermissions: permissions, + page: "voice", + data: {}, + assets: {}, + actions: {}, + widgets: { "voice.screen-share-start": () => "Start screen share" }, + })); + assert.match(html, /data-ws-plugin-widget="voice\.screen-share-start"/); + assert.match(html, /data-ws-part="skin\.voice\.share-control\.control-part-start-share"/); + assert.match(html, /Start screen share/); +}); + test("generated UI schema 5 carries bounded state and named callbacks for a trusted host event loop", () => { const source = JSON.stringify({ schemaVersion: 5, diff --git a/web/src/services/skin-extension-wasm-ui-loop.ts b/web/src/services/skin-extension-wasm-ui-loop.ts index a440fea..b9503a7 100644 --- a/web/src/services/skin-extension-wasm-ui-loop.ts +++ b/web/src/services/skin-extension-wasm-ui-loop.ts @@ -16,6 +16,8 @@ export interface SkinExtensionWasmUiLoopRunHandle { export interface SkinExtensionWasmUiLoopOptions { /** Creates one bounded, disposable Wasm job for the supplied UI input. */ createRun(input: SkinExtensionUiInput): SkinExtensionWasmUiLoopRunHandle; + /** Supplies manifest permissions when generated output may embed a privileged host widget. */ + parseOutput?(output: string): SkinPluginDocument; onOutput?(output: string, document: SkinPluginDocument, input: SkinExtensionUiInput): void | Promise; onError?(error: Error): void; } @@ -74,7 +76,7 @@ export function createSkinExtensionWasmUiLoopPrototype(options: SkinExtensionWas if (closed || activeRun !== run) return false; lastState = { ...input.state }; if (result.uiOutput !== null) { - const nextDocument = parseSkinExtensionUiOutput(result.uiOutput); + const nextDocument = options.parseOutput?.(result.uiOutput) ?? parseSkinExtensionUiOutput(result.uiOutput); output = result.uiOutput; document = nextDocument; await options.onOutput?.(output, nextDocument, input); diff --git a/web/src/services/skin-runtime-plugin-session.test.ts b/web/src/services/skin-runtime-plugin-session.test.ts index d415f16..951122c 100644 --- a/web/src/services/skin-runtime-plugin-session.test.ts +++ b/web/src/services/skin-runtime-plugin-session.test.ts @@ -35,6 +35,22 @@ const joinPlugin = parseSkinRuntimePluginDocument({ }], }).plugins[0]; +const screenSharePlugin = parseSkinRuntimePluginDocument({ + schemaVersion: 1, + plugins: [{ + id: "voice-screen-share", + name: "Voice screen share", + version: "1.0.0", + apiVersion: 1, + runtime: "wasm", + page: "voice", + mode: "surface", + entry: "plugins/voice-screen-share/index.wasm", + assets: [], + permissions: ["ui.surface.replace", "voice.screenShare.control"], + }], +}).plugins[0]; + function output(page = "voice", count = 1): string { return JSON.stringify({ schemaVersion: 5, @@ -64,6 +80,19 @@ function joinOutput(request = false, eventName: "dblclick" | "input" = "dblclick }); } +function screenShareOutput(): string { + return JSON.stringify({ + schemaVersion: 4, + components: [{ + id: "voice-ui", + name: "Voice UI", + page: "voice", + accessibleName: "Voice workspace", + root: { tag: "main", children: [{ widget: "voice.screen-share-start" }] }, + }], + }); +} + function sessionWithOutput(value: string, onError: (error: Error) => void = () => undefined) { return createSkinRuntimePluginSession({ plugin, @@ -81,6 +110,27 @@ test("runtime plugin session accepts one generated root for its declared surface assert.equal(session.closed, true); }); +test("runtime plugin session validates generated host widgets against manifest permissions", async () => { + const allowed = createSkinRuntimePluginSession({ + plugin: screenSharePlugin, + createRun: () => ({ result: Promise.resolve({ uiOutput: screenShareOutput() }), close: () => undefined }), + }); + assert.equal(await allowed.start(), true); + assert.equal(allowed.output, screenShareOutput()); + allowed.close(); + + const errors: Error[] = []; + const denied = createSkinRuntimePluginSession({ + plugin, + createRun: () => ({ result: Promise.resolve({ uiOutput: screenShareOutput() }), close: () => undefined }), + onError: (error) => errors.push(error), + }); + assert.equal(await denied.start(), false); + assert.equal((errors[0] as { code?: string } | undefined)?.code, "SKIN_EXTENSION_UI_PERMISSION_MISSING"); + assert.equal(denied.output, null); + denied.close(); +}); + test("runtime plugin session rejects output targeting a different page", async () => { const errors: Error[] = []; const session = sessionWithOutput(output("home"), (error) => errors.push(error)); diff --git a/web/src/services/skin-runtime-plugin-session.ts b/web/src/services/skin-runtime-plugin-session.ts index 3b3aba8..a2a432c 100644 --- a/web/src/services/skin-runtime-plugin-session.ts +++ b/web/src/services/skin-runtime-plugin-session.ts @@ -1,5 +1,5 @@ import type { SkinRuntimePlugin } from "../../../src/shared/skin-runtime-plugins.js"; -import { parseSkinExtensionUiActionRequest } from "../../../src/shared/skin-extension-ui.js"; +import { parseSkinExtensionUiActionRequest, parseSkinExtensionUiOutput } from "../../../src/shared/skin-extension-ui.js"; import type { SkinExtensionUiInput, SkinExtensionUiEventInput } from "../../../src/shared/skin-extension-ui-input.js"; import type { SkinPluginActionDefinition, SkinPluginDocument } from "../../../src/shared/skin-plugin.js"; import { @@ -38,6 +38,7 @@ export function createSkinRuntimePluginSession(options: SkinRuntimePluginSession let output: string | null = null; const loop = createSkinExtensionWasmUiLoopPrototype({ createRun: options.createRun, + parseOutput: (source) => parseSkinExtensionUiOutput(source, { permissions: options.plugin.permissions }), onOutput: async (nextOutput, document, input) => { 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."); diff --git a/web/src/styles/skin-plugin.css b/web/src/styles/skin-plugin.css index e2a65d4..6caafa4 100644 --- a/web/src/styles/skin-plugin.css +++ b/web/src/styles/skin-plugin.css @@ -46,6 +46,25 @@ min-height: 0; } +.ws-plugin-host-widget[data-ws-plugin-widget="voice.screen-share-start"] { min-height: 44px; } +.skin-runtime-screen-share-start { + display: inline-flex; + min-width: 44px; + min-height: 44px; + align-items: center; + justify-content: center; + gap: 8px; + padding: 0 12px; + border: 1px solid currentColor; + border-radius: 10px; + color: inherit; + background: transparent; + font: inherit; + cursor: pointer; +} +.skin-runtime-screen-share-start:disabled { cursor: not-allowed; opacity: .55; } +.skin-runtime-screen-share-start:focus-visible { outline: 3px solid #fbbf24; outline-offset: 3px; } + .ws-plugin-surface-recovery, .ws-plugin-surface-reset { position: fixed; diff --git a/web/src/views/WebClient.vue b/web/src/views/WebClient.vue index 128926b..e931251 100644 --- a/web/src/views/WebClient.vue +++ b/web/src/views/WebClient.vue @@ -35,6 +35,7 @@ :page="showVoiceShell ? 'voice' : 'home'" :context="skinPluginContext" :actions="skinPluginActions" + :widgets="skinPluginWidgets" :read-session-status="readSkinRuntimeSessionStatus" @surface-change="skinRuntimePluginSurfaceActive = $event" @restore-skin="switchToBuiltIn" @@ -1618,6 +1619,15 @@ const skinPluginActions = { }; const skinPluginWidgets = { + "voice.screen-share-start": () => h("button", { + type: "button", + class: "skin-runtime-screen-share-start", + disabled: !voiceState.connected || screenShareActive.value || screenShareStarting.value, + "aria-label": t("startScreenShare"), + onClick: () => { + if (voiceState.connected && !screenShareActive.value && !screenShareStarting.value) void startScreenShare(); + }, + }, [h(Icon, { name: "share", size: 16 }), h("span", null, t("startScreenShare"))]), "home.connection-form": () => h(JoinForm, { autofocusNickname: !isMobileViewport.value, serverHost: serverHost.value,