feat(skin): bridge trusted plugin actions

This commit is contained in:
illusia committed 2026-10-10 15:53:50 +08:00
1 parent 1aa29158ef
commit 35cb6ad6df
13 files changed
+276 -45

No files matched your search

+20 -3
View File
@@ -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 type { SkinPluginDocument } from "../../../src/shared/skin-plugin.js";
import { SKIN_PLUGIN_ACTION_PERMISSIONS, skinPluginActionPermission, type SkinPluginAction, type SkinPluginDocument } 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";
@@ -13,7 +13,12 @@ import type { SkinExtensionWasmSandboxHandle } from "../services/skin-extension-
import { resolveSkinCssAssets } from "../services/skin-pack.js";
const EMPTY_DOCUMENT: SkinPluginDocument = { schemaVersion: 3, components: [] };
const SUPPORTED_PERMISSIONS = new Set([...SKIN_RUNTIME_PLUGIN_DATA_PERMISSIONS, "ui.surface.replace"]);
const SUPPORTED_PERMISSIONS = new Set([
...SKIN_RUNTIME_PLUGIN_DATA_PERMISSIONS,
...SKIN_PLUGIN_ACTION_PERMISSIONS,
"ui.surface.replace",
]);
type HostActionHandler = (args: Record<string, string | number | boolean>) => void | Promise<void>;
type Session = ReturnType<typeof createSkinRuntimePluginSession>;
type RunHandle = { result: Promise<{ uiOutput: string | null }>; close(reason?: string): void };
@@ -85,6 +90,7 @@ export default defineComponent({
assets: { type: Object as PropType<Record<string, Blob>>, default: () => ({}) },
page: { type: String as PropType<SkinRuntimePluginPage>, required: true },
context: { type: Object as PropType<Record<string, unknown>>, default: () => ({}) },
actions: { type: Object as PropType<Partial<Record<SkinPluginAction, HostActionHandler>>>, default: () => ({}) },
readSessionStatus: { type: Function as PropType<(signal: AbortSignal) => SkinExtensionSessionStatus | Promise<SkinExtensionSessionStatus>>, required: true },
},
emits: {
@@ -196,6 +202,17 @@ export default defineComponent({
const session = createSkinRuntimePluginSession({
plugin,
createRun: (input) => createRun(props.skinId, props.skinVersion, plugin, grant, props.files, props.context, props.readSessionStatus, input),
onAction: async (action) => {
const permission = skinPluginActionPermission(action.type);
const currentGrant = approved(plugin);
if (!permission || !plugin.permissions.includes(permission) || !currentGrant
|| sessions.get(plugin.id) !== session || disposed) {
throw new Error("The plugin action is no longer approved.");
}
const handler = props.actions[action.type];
if (!handler) throw new Error("The host does not provide this action.");
await handler(action.args);
},
onOutput: () => {
installStyle(plugin);
outputs.value = { ...outputs.value, [plugin.id]: session.output };
@@ -383,7 +400,7 @@ export default defineComponent({
]),
]);
}),
h("p", { class: "ws-plugin-consent-note" }, "当前开发原型支持 Wasm、安全的公开数据读取与 ui.surface.replace;TeamSpeak 写操作仍未接入此运行时。数据字段只按清单中的读取权限投影,授权绑定到此皮肤版本、插件清单和所有插件文件的 SHA-256。/ This development prototype supports Wasm, safe public data reads, and ui.surface.replace; TeamSpeak write actions are not connected to this runtime. Data is projected by the read permissions in the descriptor, and approval is bound to this skin version, descriptor, and every plugin file by SHA-256."),
h("p", { class: "ws-plugin-consent-note" }, "当前开发原型支持 Wasm、权限化公开数据和 ui.surface.replace;已批准的宿主动作只能由可信的明确用户操作触发,并仍由 WebSpeak 校验会话和参数。数据字段只按清单中的读取权限投影,授权绑定到此皮肤版本、插件清单和所有插件文件的 SHA-256。/ This development prototype supports Wasm, permission-filtered public data, and ui.surface.replace. Approved host actions require a trusted explicit user event and are still validated by WebSpeak against the current session and arguments. Data is projected by the read permissions in the descriptor, and 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"),