Files
openclaw/scripts/lib/plugin-inventory-doc.mjs
Peter SteinbergerandGitHub be5e427f56 feat(dashboard): plugin-declared widget data bindings and action verbs (#112083)
* feat(dashboard): add plugin capability declarations

* docs(dashboard): describe plugin capabilities

* fix(plugins): preserve registry map cloning

* fix(dashboard): make plugin grant ids unambiguous

* fix(dashboard): align generated plugin grant ids

* chore(boards): internalize verb ids and refresh protocol snapshots
2026-07-20 22:43:04 -07:00

53 lines
1.8 KiB
JavaScript

function formatIdentifiers(values) {
return values.map((value) => `\`${value}\``).join(", ");
}
function encodeDashboardPluginIdSegment(pluginId) {
return pluginId.replaceAll("%", "%25").replaceAll(".", "%2E");
}
function resolveDashboardCapabilityIds(manifest, field) {
if (typeof manifest.id !== "string" || !Array.isArray(manifest.dashboard?.[field])) {
return [];
}
const pluginIdSegment = encodeDashboardPluginIdSegment(manifest.id);
return manifest.dashboard[field]
.map((entry) =>
typeof entry?.id === "string" && entry.id.length > 0
? `${pluginIdSegment}.${entry.id}`
: null,
)
.filter((value) => value !== null);
}
export function resolvePluginSurface(manifest) {
const parts = [];
if (Array.isArray(manifest.channels) && manifest.channels.length > 0) {
parts.push(`channels: ${formatIdentifiers(manifest.channels)}`);
}
if (Array.isArray(manifest.providers) && manifest.providers.length > 0) {
parts.push(`providers: ${formatIdentifiers(manifest.providers)}`);
}
const contracts = Object.keys(manifest.contracts ?? {}).toSorted((left, right) =>
left.localeCompare(right),
);
if (contracts.length > 0) {
parts.push(`contracts: ${formatIdentifiers(contracts)}`);
}
const dashboardDataBindings = resolveDashboardCapabilityIds(manifest, "dataBindings");
if (dashboardDataBindings.length > 0) {
parts.push(`dashboard data bindings: ${formatIdentifiers(dashboardDataBindings)}`);
}
const dashboardActionVerbs = resolveDashboardCapabilityIds(manifest, "actionVerbs");
if (dashboardActionVerbs.length > 0) {
parts.push(`dashboard action verbs: ${formatIdentifiers(dashboardActionVerbs)}`);
}
if (Array.isArray(manifest.skills) && manifest.skills.length > 0) {
parts.push("skills");
}
if (parts.length === 0) {
return "plugin";
}
return parts.join("; ");
}