33 lines
984 B
TypeScript
33 lines
984 B
TypeScript
import type { PluginManifest } from "@toolctrl/plugin-runtime/manifest";
|
|
|
|
export const PLUGIN_HOOK_CONSENT_PREFIX = "hook:";
|
|
|
|
export type PluginConsentRequirement = {
|
|
name: string;
|
|
scope: PluginManifest["capabilities"][number]["scope"] | null;
|
|
kind: "capability" | "hook";
|
|
};
|
|
|
|
export function getPluginHookConsentName(hookName: string): string {
|
|
return `${PLUGIN_HOOK_CONSENT_PREFIX}${hookName}`;
|
|
}
|
|
|
|
export function isPluginHookConsentName(name: string): boolean {
|
|
return name.startsWith(PLUGIN_HOOK_CONSENT_PREFIX);
|
|
}
|
|
|
|
export function getPluginConsentRequirements(manifest: PluginManifest): PluginConsentRequirement[] {
|
|
return [
|
|
...(manifest.capabilities ?? []).map((capability) => ({
|
|
name: capability.name as string,
|
|
scope: capability.scope ?? null,
|
|
kind: "capability" as const,
|
|
})),
|
|
...(manifest.hooks ?? []).map((hook) => ({
|
|
name: getPluginHookConsentName(hook.name),
|
|
scope: null,
|
|
kind: "hook" as const,
|
|
})),
|
|
];
|
|
}
|