mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02:50 +08:00
feat(skin): add bounded plugin runtime and Harbor voice sample
This commit is contained in:
1 parent
8f097ec597
commit
96c29394f3
30 files changed
+1540
-185
No files matched your search
@@ -13,6 +13,7 @@ export const SKIN_PLUGIN_RENDER_NODE_LIMIT = 8192;
|
||||
|
||||
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." }),
|
||||
"ui.input.read": Object.freeze({ policyVersion: 1, description: "Read values entered or autofilled in this plugin's own input fields. Never enter passwords or other secrets." }),
|
||||
"session.status.read": Object.freeze({ policyVersion: 1, description: "Read the current connection and channel summary." }),
|
||||
"session.channels.read": Object.freeze({ policyVersion: 1, description: "Read the public TeamSpeak channel tree; the demo page uses synthetic sample data." }),
|
||||
"session.members.read": Object.freeze({ policyVersion: 1, description: "Read visible member names and speaking states; the demo page uses synthetic sample data." }),
|
||||
|
||||
@@ -47,6 +47,7 @@ test("plugin digest is deterministic and binds all declared source, style, asset
|
||||
assert.notEqual(first, await computeSkinRuntimePluginDigest(definition, files(undefined, undefined, "icon-v2")));
|
||||
assert.notEqual(first, await computeSkinRuntimePluginDigest(plugin({ permissions: [] }), packageFiles));
|
||||
assert.notEqual(first, await computeSkinRuntimePluginDigest(plugin({ mode: "surface", permissions: ["ui.surface.replace"] }), packageFiles));
|
||||
assert.notEqual(first, await computeSkinRuntimePluginDigest(plugin({ mount: "voice.chat.before" }), packageFiles));
|
||||
});
|
||||
|
||||
test("plugin approval is pinned to skin and plugin versions, content digest, and permission policy", async () => {
|
||||
|
||||
@@ -82,6 +82,7 @@ export async function computeSkinRuntimePluginDigest(
|
||||
runtime: plugin.runtime,
|
||||
page: plugin.page,
|
||||
mode: plugin.mode,
|
||||
...(plugin.mount ? { mount: plugin.mount } : {}),
|
||||
entry: plugin.entry,
|
||||
...(plugin.style ? { style: plugin.style } : {}),
|
||||
assets: [...plugin.assets].sort(),
|
||||
|
||||
@@ -70,6 +70,26 @@ test("surface replacement is an explicit page-scoped plugin capability", () => {
|
||||
);
|
||||
});
|
||||
|
||||
test("runtime plugins can request explicit access to values from their own UI inputs", () => {
|
||||
const inputReader = parseSkinRuntimePluginDocument(document([{ ...plugin, permissions: ["ui.input.read"] }]) as never);
|
||||
assert.deepEqual(inputReader.plugins[0].permissions, ["ui.input.read"]);
|
||||
});
|
||||
|
||||
test("runtime widget mount slots are page-scoped and included in the parsed descriptor", () => {
|
||||
const voiceWidget = parseSkinRuntimePluginDocument(document([{ ...plugin, mount: "voice.chat.before" }]) as never);
|
||||
assert.equal(voiceWidget.plugins[0].mount, "voice.chat.before");
|
||||
for (const value of [
|
||||
{ ...plugin, mount: "voice.chat.before", page: "home" },
|
||||
{ ...plugin, mount: "admin.header" },
|
||||
{ ...plugin, mode: "surface", mount: "voice.workspace.overlay", permissions: ["ui.surface.replace"] },
|
||||
]) {
|
||||
assert.throws(
|
||||
() => parseSkinRuntimePluginDocument(document([value]) as never),
|
||||
(error: unknown) => error instanceof SkinRuntimePluginValidationError && error.code === "SKIN_RUNTIME_PLUGIN_MOUNT_INVALID",
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test("v4 plugin descriptors reject unknown fields, path escape, wrong ownership, and executable assets", () => {
|
||||
const cases: Array<[unknown, string]> = [
|
||||
[{ ...plugin, arbitraryCodeHook: "run" }, "SKIN_RUNTIME_PLUGIN_FIELD_INVALID"],
|
||||
|
||||
@@ -10,6 +10,14 @@ export const SKIN_RUNTIME_PLUGIN_STYLE_LIMIT_BYTES = 512 * 1024;
|
||||
export type SkinRuntimePluginPage = "home" | "voice";
|
||||
export type SkinRuntimePluginMode = "widget" | "surface";
|
||||
export type SkinRuntimePluginRuntime = "javascript" | "wasm";
|
||||
export const SKIN_RUNTIME_PLUGIN_MOUNT_SLOTS = Object.freeze([
|
||||
"home.header.after", "home.content.before", "home.content.after", "home.footer.before",
|
||||
"voice.server-rail.before", "voice.server-rail.after", "voice.header.before", "voice.header.after",
|
||||
"voice.activity.before", "voice.activity.after", "voice.chat.before", "voice.chat.after",
|
||||
"voice.channel-panel.before", "voice.channel-panel.after", "voice.audio-dock.before", "voice.audio-dock.after",
|
||||
"voice.mobile-nav.before", "voice.mobile-nav.after", "voice.workspace.overlay",
|
||||
] as const);
|
||||
export type SkinRuntimePluginMountSlot = typeof SKIN_RUNTIME_PLUGIN_MOUNT_SLOTS[number];
|
||||
|
||||
export interface SkinRuntimePlugin {
|
||||
id: string;
|
||||
@@ -19,6 +27,7 @@ export interface SkinRuntimePlugin {
|
||||
runtime: SkinRuntimePluginRuntime;
|
||||
page: SkinRuntimePluginPage;
|
||||
mode: SkinRuntimePluginMode;
|
||||
mount?: SkinRuntimePluginMountSlot;
|
||||
entry: string;
|
||||
style?: string;
|
||||
assets: readonly string[];
|
||||
@@ -40,6 +49,27 @@ export class SkinRuntimePluginValidationError extends Error {
|
||||
const PLUGIN_ID = /^[a-z][a-z0-9-]{0,63}$/;
|
||||
const SEMVER = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
|
||||
const PERMISSIONS = new Set<string>(Object.keys(SKIN_PLUGIN_PERMISSIONS));
|
||||
const MOUNT_SLOT_PAGES: Readonly<Record<SkinRuntimePluginMountSlot, SkinRuntimePluginPage>> = Object.freeze({
|
||||
"home.header.after": "home",
|
||||
"home.content.before": "home",
|
||||
"home.content.after": "home",
|
||||
"home.footer.before": "home",
|
||||
"voice.server-rail.before": "voice",
|
||||
"voice.server-rail.after": "voice",
|
||||
"voice.header.before": "voice",
|
||||
"voice.header.after": "voice",
|
||||
"voice.activity.before": "voice",
|
||||
"voice.activity.after": "voice",
|
||||
"voice.chat.before": "voice",
|
||||
"voice.chat.after": "voice",
|
||||
"voice.channel-panel.before": "voice",
|
||||
"voice.channel-panel.after": "voice",
|
||||
"voice.audio-dock.before": "voice",
|
||||
"voice.audio-dock.after": "voice",
|
||||
"voice.mobile-nav.before": "voice",
|
||||
"voice.mobile-nav.after": "voice",
|
||||
"voice.workspace.overlay": "voice",
|
||||
});
|
||||
const ASSET_PATH = /^plugins\/([a-z][a-z0-9-]{0,63})\/assets\/[A-Za-z0-9][A-Za-z0-9._-]{0,127}\.(?:png|jpe?g|webp|avif|gif|woff2)$/i;
|
||||
|
||||
function invalid(code: string, message: string): never {
|
||||
@@ -88,7 +118,7 @@ export function parseSkinRuntimePluginDocument(input: unknown): SkinRuntimePlugi
|
||||
const plugins: SkinRuntimePlugin[] = [];
|
||||
for (const raw of input.plugins) {
|
||||
if (!isRecord(raw)) invalid("SKIN_RUNTIME_PLUGIN_MANIFEST_INVALID", "A plugin definition must be an object.");
|
||||
onlyKeys(raw, ["id", "name", "version", "apiVersion", "runtime", "page", "mode", "entry", "style", "assets", "permissions"], "Plugin definition");
|
||||
onlyKeys(raw, ["id", "name", "version", "apiVersion", "runtime", "page", "mode", "mount", "entry", "style", "assets", "permissions"], "Plugin definition");
|
||||
|
||||
const id = text(raw.id, "plugin.id", 64);
|
||||
if (!PLUGIN_ID.test(id) || ids.has(id)) invalid("SKIN_RUNTIME_PLUGIN_ID_INVALID", "Plugin IDs must be unique lowercase slugs.");
|
||||
@@ -99,6 +129,16 @@ export function parseSkinRuntimePluginDocument(input: unknown): SkinRuntimePlugi
|
||||
if (raw.apiVersion !== 1) invalid("SKIN_RUNTIME_PLUGIN_API_UNSUPPORTED", "The plugin API version is not supported.");
|
||||
if (raw.page !== "home" && raw.page !== "voice") invalid("SKIN_RUNTIME_PLUGIN_MANIFEST_INVALID", "Plugins may target only the public home or voice page.");
|
||||
if (raw.mode !== "widget" && raw.mode !== "surface") invalid("SKIN_RUNTIME_PLUGIN_MANIFEST_INVALID", "Plugin mode must be widget or surface.");
|
||||
let mount: SkinRuntimePluginMountSlot | undefined;
|
||||
if (raw.mount !== undefined) {
|
||||
if (typeof raw.mount !== "string" || !(SKIN_RUNTIME_PLUGIN_MOUNT_SLOTS as readonly string[]).includes(raw.mount)) {
|
||||
invalid("SKIN_RUNTIME_PLUGIN_MOUNT_INVALID", "Plugin mount must use a registered public UI slot.");
|
||||
}
|
||||
mount = raw.mount as SkinRuntimePluginMountSlot;
|
||||
if (MOUNT_SLOT_PAGES[mount] !== raw.page || raw.mode === "surface") {
|
||||
invalid("SKIN_RUNTIME_PLUGIN_MOUNT_INVALID", "Mount slots must match the plugin page and are available to widget plugins only.");
|
||||
}
|
||||
}
|
||||
|
||||
const runtime = raw.runtime === undefined
|
||||
? (typeof raw.entry === "string" && raw.entry.toLowerCase().endsWith(".wasm") ? "wasm" : "javascript")
|
||||
@@ -153,6 +193,7 @@ export function parseSkinRuntimePluginDocument(input: unknown): SkinRuntimePlugi
|
||||
runtime,
|
||||
page: raw.page,
|
||||
mode: raw.mode,
|
||||
...(mount ? { mount } : {}),
|
||||
entry,
|
||||
...(style ? { style } : {}),
|
||||
assets,
|
||||
|
||||
Reference in new issue
Block a user