feat(skins): add persistent voice workspace API and align KAAK

This commit is contained in:
illusia committed 2026-10-24 13:30:50 +08:00
1 parent 0af3236c30
commit 452e6f09ca
24 files changed
+451 -21

No files matched your search

+7 -2
View File
@@ -1,3 +1,4 @@
import { parseSkinWorkspacePolicy, type SkinWorkspacePolicy } from "../shared/skin-workspace.js";
import type { SkinCatalogEntry as SharedSkinCatalogEntry } from "../shared/skin-catalog.js";
import { compileSkinCss, SkinCssValidationError, type SkinCssSchemaVersion } from "../shared/skin-css.js";
import { parseSkinLayoutJson } from "../shared/skin-layout.js";
@@ -58,6 +59,7 @@ type ParsedSkinManifest = Omit<SkinCatalogEntry, "installedAt" | "previewUrl" |
content?: string;
components?: string;
plugins?: string;
workspace?: SkinWorkspacePolicy;
preview?: string;
};
@@ -472,7 +474,7 @@ function parseManifest(bytes: Buffer): ParsedSkinManifest {
if (schemaVersion !== 1 && schemaVersion !== 2 && schemaVersion !== 3 && schemaVersion !== 4) throw new SkinRegistryError("The skin schema version or ID is unsupported.", "SKIN_SCHEMA_VERSION");
if (schemaVersion >= 2) {
const fields = new Set(["schemaVersion", "packageType", "id", "name", "version", "author", "license", "description", "entry", "layout", "permissions", "content", "minAppVersion", "preview"]);
if (schemaVersion >= 3) { fields.delete("permissions"); fields.add("components"); }
if (schemaVersion >= 3) { fields.delete("permissions"); fields.add("components"); fields.add("workspace"); }
if (schemaVersion === 4) fields.add("plugins");
const unknown = Object.keys(value).find((key) => !fields.has(key));
if (unknown) throw new SkinRegistryError(`Version 2 skin manifest contains an unsupported field: ${unknown}.`, "SKIN_MANIFEST_INVALID");
@@ -482,6 +484,9 @@ function parseManifest(bytes: Buffer): ParsedSkinManifest {
if (typeof item !== "string" || !item.trim() || item.length > max) throw new SkinRegistryError(`manifest.json has an invalid ${key} field.`, "SKIN_MANIFEST_INVALID");
return item.trim();
};
let workspace: SkinWorkspacePolicy | undefined;
try { workspace = parseSkinWorkspacePolicy(value.workspace, schemaVersion); }
catch (error) { throw new SkinRegistryError(error instanceof Error ? error.message : "Invalid workspace policy.", "SKIN_MANIFEST_INVALID"); }
const id = read("id", 80);
if (!isSafeSkinId(id)) throw new SkinRegistryError("The skin schema version or ID is unsupported.", "SKIN_SCHEMA_VERSION");
if (schemaVersion === 2 && (value.packageType !== "layout-skin" || !Array.isArray(value.permissions) || value.permissions.length !== 0)) {
@@ -507,7 +512,7 @@ function parseManifest(bytes: Buffer): ParsedSkinManifest {
const declaredFiles = ["manifest.json", entry, ...(layout ? [layout] : []), ...(content ? [content] : []), ...(components ? [components] : []), ...(plugins ? [plugins] : []), ...(preview ? [preview] : [])].map((item) => item.toLowerCase());
if (new Set(declaredFiles).size !== declaredFiles.length) throw new SkinRegistryError("Manifest files must use separate package paths.", "SKIN_MANIFEST_INVALID");
const description = readOptional("description", 400);
return { schemaVersion, ...(schemaVersion === 2 ? { packageType: "layout-skin" as const } : schemaVersion >= 3 ? { packageType: "open-skin" as const } : {}), id, name: read("name", 80), version, author: read("author", 80), license: read("license", 80), minAppVersion, entry, ...(layout ? { layout } : {}), ...(content ? { content } : {}), ...(components ? { components } : {}), ...(plugins ? { plugins } : {}), ...(preview ? { preview } : {}), ...(description ? { description } : {}) };
return { schemaVersion, ...(workspace ? { workspace } : {}), ...(schemaVersion === 2 ? { packageType: "layout-skin" as const } : schemaVersion >= 3 ? { packageType: "open-skin" as const } : {}), id, name: read("name", 80), version, author: read("author", 80), license: read("license", 80), minAppVersion, entry, ...(layout ? { layout } : {}), ...(content ? { content } : {}), ...(components ? { components } : {}), ...(plugins ? { plugins } : {}), ...(preview ? { preview } : {}), ...(description ? { description } : {}) };
}
function singleRootPrefix(paths: string[]): string {
+5
View File
@@ -239,6 +239,10 @@ const PUBLIC_PART_IDS = new Set<string>([
"voice.chat.tab",
"voice.chat.tabs",
"voice.connection-status",
"voice.connection-status.message",
"voice.connection-status.nickname",
"voice.connection-status.nickname.input",
"voice.connection-status.reconnect",
"voice.content",
"voice.context-menu",
"voice.context-menu-backdrop",
@@ -370,6 +374,7 @@ const ACTION_PART_IDS = new Set([
"voice.channel-tree.expander", "voice.channel-tree.row", "demo.skin-switcher", "demo.language-switcher",
]);
const INTERACTIVE_PART_IDS = new Set([
"voice.connection-status.nickname.input", "voice.connection-status.reconnect",
"demo.action.poke", "demo.action.reconnect", "demo.action.speaking", "demo.channel.select",
"demo.chat.input", "demo.chat.send", "demo.chat.tab", "demo.home-link", "demo.poke.dismiss",
"demo.reconnect.restore", "home.connect", "home.favorite-toggle", "home.identity-export.button",
+8 -3
View File
@@ -32,6 +32,7 @@ export const SKIN_PLUGIN_PERMISSIONS = Object.freeze({
"audio.settings.open": Object.freeze({ policyVersion: 1, description: "Open WebSpeak's trusted audio device and processing settings." }),
"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.connect": Object.freeze({ policyVersion: 1, description: "Connect to the host-selected TeamSpeak target after an explicit user action; the skin cannot provide addresses or credentials." }),
"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." }),
@@ -63,6 +64,7 @@ export const SKIN_PLUGIN_HOST_WIDGETS = Object.freeze([
"voice.screen-share-start",
"voice.whisper-controls",
"voice.performance-panel",
"voice.connection-status",
"voice.connection-controls",
"voice.disconnect-control",
] as const);
@@ -90,6 +92,7 @@ export const SKIN_PLUGIN_HOST_WIDGET_PERMISSIONS: Partial<Record<SkinPluginHostW
"voice.server-banner": widgetPermissions("session.status.read"),
"voice.audio-controls": widgetPermissions("audio.status.read", "audio.microphone.control", "audio.output.control"),
"voice.chat-panel": widgetPermissions("chat.channel.read", "chat.channel.send"),
"voice.connection-status": widgetPermissions("session.status.read", "voice.connect"),
"voice.connection-controls": widgetPermissions("voice.disconnect"),
"voice.disconnect-control": widgetPermissions("voice.disconnect"),
"voice.member-cards": widgetPermissions("session.members.read", "session.memberAvatars.read", "voice.screenShare.read", "voice.screenShare.control"),
@@ -123,7 +126,7 @@ export type SkinPluginAction =
| "voice.joinChannel" | "favorites.switch" | "quickServers.switch" | "chat.sendMessage" | "chat.togglePanel"
| "voice.toggleMicrophone" | "voice.toggleOutputMute" | "voice.setOutputVolume" | "audio.openSettings"
| "audio.toggleNoiseSuppression" | "audio.toggleAccompaniment"
| "voice.disconnect" | "voice.setAway" | "voice.setWhisperActive"
| "voice.connect" | "voice.disconnect" | "voice.setAway" | "voice.setWhisperActive"
| "voice.startScreenShare" | "voice.stopScreenShare" | "voice.joinScreenShare" | "voice.leaveScreenShare";
export interface SkinPluginActionDefinition {
@@ -204,11 +207,11 @@ const V3_EVENTS = new Set<string>([
const PASSIVE_EVENTS = new Set<string>(["focus", "blur", "pointerenter", "pointerleave", "dragstart", "dragover"]);
const ACTIONS = new Set<string>([
"ui.setState", "ui.toggleState", "session.copyInviteLink", "voice.joinChannel", "favorites.switch", "quickServers.switch", "chat.sendMessage", "chat.togglePanel",
"voice.toggleMicrophone", "voice.toggleOutputMute", "voice.setOutputVolume", "audio.openSettings", "audio.toggleNoiseSuppression", "audio.toggleAccompaniment", "voice.disconnect", "voice.setAway", "voice.setWhisperActive",
"voice.toggleMicrophone", "voice.toggleOutputMute", "voice.setOutputVolume", "audio.openSettings", "audio.toggleNoiseSuppression", "audio.toggleAccompaniment", "voice.connect", "voice.disconnect", "voice.setAway", "voice.setWhisperActive",
"voice.startScreenShare", "voice.stopScreenShare", "voice.joinScreenShare", "voice.leaveScreenShare",
]);
const V3_ACTIONS = new Set<string>([
"ui.toggleState", "session.copyInviteLink", "chat.togglePanel", "voice.toggleMicrophone", "voice.toggleOutputMute", "voice.setOutputVolume", "audio.openSettings", "audio.toggleNoiseSuppression", "audio.toggleAccompaniment", "voice.disconnect", "voice.setAway",
"ui.toggleState", "session.copyInviteLink", "chat.togglePanel", "voice.toggleMicrophone", "voice.toggleOutputMute", "voice.setOutputVolume", "audio.openSettings", "audio.toggleNoiseSuppression", "audio.toggleAccompaniment", "voice.connect", "voice.disconnect", "voice.setAway",
"voice.setWhisperActive", "voice.startScreenShare", "voice.stopScreenShare", "voice.joinScreenShare", "voice.leaveScreenShare",
]);
const PERMISSIONS = new Set<string>(Object.keys(SKIN_PLUGIN_PERMISSIONS));
@@ -228,6 +231,7 @@ const ACTION_ARGS: Record<SkinPluginAction, ReadonlySet<string>> = {
"audio.openSettings": new Set([]),
"audio.toggleNoiseSuppression": new Set([]),
"audio.toggleAccompaniment": new Set([]),
"voice.connect": new Set([]),
"voice.disconnect": new Set([]),
"voice.setAway": new Set(["away", "message"]),
"voice.setWhisperActive": new Set(["active"]),
@@ -251,6 +255,7 @@ const ACTION_PERMISSION: Record<SkinPluginAction, SkinPluginPermission | null> =
"audio.openSettings": "audio.settings.open",
"audio.toggleNoiseSuppression": "audio.microphone.control",
"audio.toggleAccompaniment": "audio.output.control",
"voice.connect": "voice.connect",
"voice.disconnect": "voice.disconnect",
"voice.setAway": "voice.presence.write",
"voice.setWhisperActive": "voice.whisper.control",
+15
View File
@@ -0,0 +1,15 @@
/** Public workspace API v1. No skin IDs or connection credentials belong here. */
export interface SkinWorkspacePolicy {
apiVersion: 1;
mode: "persistent";
}
export function parseSkinWorkspacePolicy(value: unknown, schemaVersion: number): SkinWorkspacePolicy | undefined {
if (value === undefined) return undefined;
if (schemaVersion < 3 || !value || typeof value !== "object" || Array.isArray(value)) throw new Error("Workspace policy requires an open-skin package.");
const policy = value as Record<string, unknown>;
if (Object.keys(policy).some(key => key !== "apiVersion" && key !== "mode") || policy.apiVersion !== 1 || policy.mode !== "persistent") {
throw new Error("Unsupported workspace policy or API version.");
}
return { apiVersion: 1, mode: "persistent" };
}