openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
34 lines (33 loc) • 2.49 kB
JavaScript
import { i as extractErrorCode, n as collectErrorGraphCandidates } from "./error-coercion-CvJK4lmH.mjs";
import "./errors-O33D01XW.mjs";
//#region src/plugins/plugin-trust.ts
/** The same recorded explanation is rendered by CLI inspection and the runtime refusal. */
function formatPluginTrustDiagnostic(trust) {
return [
`reason=${trust.reason}`,
`registryPath=${JSON.stringify(trust.registryPath)}`,
`origin=${JSON.stringify(trust.origin)}`,
`installSource=${JSON.stringify(trust.installSource ?? null)}`,
`installSpec=${JSON.stringify(trust.installSpec ?? null)}`
].join("; ");
}
const PLUGIN_TRUST_REFUSED_CODE = "PLUGIN_TRUST_REFUSED";
var PluginTrustRefusalError = class extends Error {
constructor(params) {
const trust = params.trust ?? {
reason: "record-missing",
registryPath: null,
origin: params.origin ?? "unknown"
};
const remedy = trust.reason === "provenance-missing" ? "Run openclaw doctor --fix to repair proven legacy official provenance; if it cannot be verified, reinstall from the official npm package or ClawHub listing." : trust.reason === "record-missing" ? "Compare this registryPath with openclaw plugins inspect <plugin-id> --json. If the CLI and Gateway state paths differ, align the service environment; otherwise reinstall from the official npm package or ClawHub listing." : trust.reason === "origin-path" ? "Install the official npm package or ClawHub listing and remove the local override from plugins.load.paths; --link and --force do not grant hook agent-turn authority." : "Reinstall from the official npm package or ClawHub listing; local paths, archives, ambiguous ownership, and inconsistent install records do not grant hook agent-turn authority.";
super(`dispatchHookAgentTurn is only available for trusted plugins in this release. Plugin ${JSON.stringify(params.pluginId)} loaded from ${JSON.stringify(params.source)} with origin ${JSON.stringify(params.origin ?? "unknown")}; ${formatPluginTrustDiagnostic(trust)}. ${remedy}`);
this.code = PLUGIN_TRUST_REFUSED_CODE;
this.name = "PluginTrustRefusalError";
}
};
/** Plugins can wrap hook-turn refusals before channel startup sees them. */
function isPluginTrustRefusalError(error) {
return collectErrorGraphCandidates(error, (current) => [current.cause]).some((candidate) => extractErrorCode(candidate) === PLUGIN_TRUST_REFUSED_CODE);
}
//#endregion
export { formatPluginTrustDiagnostic as n, isPluginTrustRefusalError as r, PluginTrustRefusalError as t };