fix(scum): gate plugin features by companion support

This commit is contained in:
npc0-hue
2026-07-29 11:28:19 +08:00
parent 63022baa18
commit 47738acfd6
8 changed files with 38 additions and 25 deletions
+4 -2
View File
@@ -4,12 +4,14 @@ import type { PluginBridgeHostContext, PluginPageContract } from "../contracts/p
export interface PluginPageBundleModule {
pluginPageBundle: { key: string; version: string; integritySha256: string };
renderPluginPage: (react: { createElement: typeof import("react").createElement }, input: { page: PluginPageContract; context: PluginBridgeHostContext; workspace?: unknown; availability: { available: boolean; reason?: string } }) => ReturnType<typeof import("react").createElement>;
renderPluginPage: (react: { createElement: typeof import("react").createElement }, input: { page: PluginPageContract; context: PluginBridgeHostContext; workspace?: unknown; availability: PluginPageAvailability }) => ReturnType<typeof import("react").createElement>;
}
export type PluginPageAvailability = { available: boolean; reason?: string; features?: Array<{ key: string; available: boolean; reason?: string }> };
const pageBundles = import.meta.glob<PluginPageBundleModule>("../../plugins/examples/*/page-bundle/index.ts");
export async function loadPluginPageBundle(page: PluginPageContract): Promise<ComponentType<{ context: PluginBridgeHostContext; workspace?: unknown; availability: { available: boolean; reason?: string } }>> {
export async function loadPluginPageBundle(page: PluginPageContract): Promise<ComponentType<{ context: PluginBridgeHostContext; workspace?: unknown; availability: PluginPageAvailability }>> {
if (!page.bundleKey || !page.bundleVersion || !page.bundleIntegritySha256) throw new Error("插件没有声明受验证的页面 bundle。");
const match = Object.entries(pageBundles).find(([path]) => path.endsWith(`/${page.bundleKey}/page-bundle/index.ts`));
if (!match) throw new Error("已声明的插件页面 bundle 未安装。");