mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-17 07:11:41 +00:00
Co-authored-by: chengzhichao-xydt <chengzhichao-xydt@users.noreply.github.com> Co-authored-by: wangmiao0668000666 <wang.miao86@xydigit.com> Co-authored-by: 黄剑雄0668001315 <huang.jianxiong@xydigit.com>
72 lines
2.6 KiB
TypeScript
72 lines
2.6 KiB
TypeScript
// Text formatter for plugin list rows and verbose plugin details.
|
|
import { truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
|
|
import { sanitizeTerminalText } from "../../packages/terminal-core/src/safe-text.js";
|
|
import { theme } from "../../packages/terminal-core/src/theme.js";
|
|
import type { PluginRecord } from "../plugins/registry.js";
|
|
import { shortenHomeInString } from "../utils.js";
|
|
|
|
export function formatPluginLine(plugin: PluginRecord, verbose = false): string {
|
|
const status =
|
|
plugin.status === "error"
|
|
? theme.error("error")
|
|
: plugin.enabled
|
|
? theme.success("enabled")
|
|
: theme.warn("disabled");
|
|
const name = theme.command(plugin.name || plugin.id);
|
|
const idSuffix = plugin.name && plugin.name !== plugin.id ? theme.muted(` (${plugin.id})`) : "";
|
|
const desc = plugin.description
|
|
? theme.muted(
|
|
plugin.description.length > 60
|
|
? `${truncateUtf16Safe(plugin.description, 57)}...`
|
|
: plugin.description,
|
|
)
|
|
: theme.muted("(no description)");
|
|
const format = plugin.format ?? "openclaw";
|
|
|
|
if (!verbose) {
|
|
return `${name}${idSuffix} ${status} ${theme.muted(`[${format}]`)} - ${desc}`;
|
|
}
|
|
|
|
const parts = [
|
|
`${name}${idSuffix} ${status}`,
|
|
` format: ${format}`,
|
|
` source: ${theme.muted(shortenHomeInString(plugin.source))}`,
|
|
` origin: ${plugin.origin}`,
|
|
];
|
|
if (plugin.bundleFormat) {
|
|
parts.push(` bundle format: ${plugin.bundleFormat}`);
|
|
}
|
|
if (plugin.version) {
|
|
parts.push(` version: ${plugin.version}`);
|
|
}
|
|
if (plugin.activated !== undefined) {
|
|
parts.push(` activated: ${plugin.activated ? "yes" : "no"}`);
|
|
}
|
|
if (plugin.imported !== undefined) {
|
|
parts.push(` imported: ${plugin.imported ? "yes" : "no"}`);
|
|
}
|
|
if (plugin.explicitlyEnabled !== undefined) {
|
|
parts.push(` explicitly enabled: ${plugin.explicitlyEnabled ? "yes" : "no"}`);
|
|
}
|
|
if (plugin.activationSource) {
|
|
parts.push(` activation source: ${plugin.activationSource}`);
|
|
}
|
|
if (plugin.activationReason) {
|
|
parts.push(` activation reason: ${sanitizeTerminalText(plugin.activationReason)}`);
|
|
}
|
|
if (plugin.providerIds.length > 0) {
|
|
parts.push(` providers: ${plugin.providerIds.join(", ")}`);
|
|
}
|
|
if (plugin.activated !== undefined || plugin.activationSource || plugin.activationReason) {
|
|
const activationSummary =
|
|
plugin.activated === false
|
|
? "inactive"
|
|
: (plugin.activationSource ?? (plugin.activated ? "active" : "inactive"));
|
|
parts.push(` activation: ${activationSummary}`);
|
|
}
|
|
if (plugin.error) {
|
|
parts.push(theme.error(` error: ${plugin.error}`));
|
|
}
|
|
return parts.join("\n");
|
|
}
|