openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
78 lines (77 loc) • 3.77 kB
JavaScript
import { t as formatErrorMessage } from "./errors-Db3Ymjlb.js";
import { t as ManagedPluginLifecycleError } from "./management-lifecycle-error-BlJhejU6.js";
import { t as ErrorCodes } from "./gateway-error-details-w0nAGBBp.js";
import { Fn as validatePluginsInspectParams, Ln as validatePluginsListParams, Rn as validatePluginsRefreshParams, zn as validatePluginsSearchParams } from "./src-BiL5aQto.js";
import { d as errorShape } from "./error-codes-Bo8q2D1o.js";
import { t as assertValidParams } from "./validation-pzrlzFvo.js";
import { t as searchInstallablePluginPackages } from "./catalog-search-Cf5UyWXa.js";
import { i as refreshManagedPluginMetadata, n as listManagedPlugins, t as inspectManagedPlugin } from "./management-service-C_33JbZN.js";
//#region src/gateway/server-methods/plugins.ts
const pluginsHandlers = {
"plugins.refresh": async ({ params, respond, context }) => {
if (!assertValidParams(params, validatePluginsRefreshParams, "plugins.refresh", respond)) return;
try {
refreshManagedPluginMetadata({ config: context.getRuntimeConfig() });
} catch (error) {
respond(false, void 0, errorShape(ErrorCodes.UNAVAILABLE, `Plugin inventory refresh failed: ${formatErrorMessage(error)}. Restart the Gateway to load updated plugins.`, { details: { restartRequired: true } }));
return;
} finally {
context.notifyPluginMetadataChanged();
}
respond(true, {
ok: true,
restartRequired: true
}, void 0);
},
"plugins.list": async ({ params, respond, context }) => {
if (!assertValidParams(params, validatePluginsListParams, "plugins.list", respond)) return;
try {
respond(true, await listManagedPlugins({ config: context.getRuntimeConfig() }), void 0);
} catch (error) {
respond(false, void 0, errorShape(ErrorCodes.UNAVAILABLE, formatErrorMessage(error)));
}
},
"plugins.inspect": async ({ params, respond, context }) => {
if (!assertValidParams(params, validatePluginsInspectParams, "plugins.inspect", respond)) return;
try {
respond(true, await inspectManagedPlugin({
config: context.getRuntimeConfig(),
pluginId: params.pluginId
}), void 0);
} catch (error) {
const lifecycleError = error instanceof ManagedPluginLifecycleError ? error : void 0;
respond(false, void 0, errorShape(lifecycleError?.kind === "invalid-request" ? ErrorCodes.INVALID_REQUEST : ErrorCodes.UNAVAILABLE, formatErrorMessage(error)));
}
},
"plugins.search": async ({ params, respond }) => {
if (!assertValidParams(params, validatePluginsSearchParams, "plugins.search", respond)) return;
try {
respond(true, { results: (await searchInstallablePluginPackages({
query: params.query,
limit: params.limit
})).flatMap((entry) => {
if (entry.package.family !== "code-plugin" && entry.package.family !== "bundle-plugin") return [];
const downloads = entry.package.stats?.downloads;
return [{
score: entry.score,
package: {
name: entry.package.name,
displayName: entry.package.displayName,
family: entry.package.family,
channel: entry.package.channel,
isOfficial: entry.package.isOfficial,
...entry.package.summary ? { summary: entry.package.summary } : {},
...entry.package.latestVersion ? { latestVersion: entry.package.latestVersion } : {},
...entry.package.runtimeId ? { runtimeId: entry.package.runtimeId } : {},
...typeof downloads === "number" && Number.isFinite(downloads) && downloads >= 0 ? { downloads } : {},
...entry.package.verificationTier ? { verificationTier: entry.package.verificationTier } : {}
}
}];
}) }, void 0);
} catch (error) {
respond(false, void 0, errorShape(ErrorCodes.UNAVAILABLE, formatErrorMessage(error)));
}
}
};
//#endregion
export { pluginsHandlers };