openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
83 lines (82 loc) • 3.59 kB
JavaScript
import { r as truncateUtf16Safe } from "./utf16-slice-CuDyEXgS.mjs";
import { Et as _enum, Fn as object, Jn as string } from "./schemas-Cy6abvsu.mjs";
import { n as joinClawHubPluginCatalog } from "./catalog-discovery-q1OWXMsX.mjs";
import { v as resolveClawHubBaseUrl, y as resolveClawHubImageUrl } from "./clawhub-client-BLg-dsn2.mjs";
import { t as fetchClawHubPluginCatalog } from "./clawhub-plugin-catalog-BC-4D5Jm.mjs";
import { d as searchClawHubSkills } from "./clawhub-skills-C1KFinHC.mjs";
import "./clawhub-recommendations-Diy5uXfN.mjs";
import { n as registerClawHubCatalogIconUrls, r as resolveClawHubCatalogIconUrl } from "./catalog-icon-registry-Bql9JZh5.mjs";
import { n as listManagedPlugins } from "./management-service-jpAFCXsG.mjs";
import { i as prepareWorkspaceSkillStatus } from "./status-C6DUmZEt.mjs";
//#region src/infra/outbound/clawhub-recommendations.ts
const requestSchema = object({
query: string().trim().min(1).max(160),
kind: _enum(["plugin", "skill"]).optional()
}).strict();
async function resolveClawHubRecommendations(e) {
const t = requestSchema.parse(e.request);
const n = {
cards: [],
text: "ClawHub recommendations are unavailable right now, so I could not verify a matching capability or its installation status. Please try again."
};
let r = [];
if (t.kind !== "skill") {
const i = await Promise.all([fetchClawHubPluginCatalog({
query: t.query,
intent: "official",
limit: 3
}), listManagedPlugins({ config: e.config })]).catch(() => void 0);
if (!i) return n;
const [a, o] = i;
registerClawHubCatalogIconUrls(a.items.map((e) => e.iconUrl));
r = joinClawHubPluginCatalog({
remote: a.items,
local: o
}).filter((e) => e.catalog.official).slice(0, 3).map((e) => ({
type: "clawhub",
kind: "plugin",
id: e.id,
name: truncateUtf16Safe(e.catalog.name, 120),
description: e.catalog.summary ? truncateUtf16Safe(e.catalog.summary, 240) : void 0,
iconUrl: e.catalog.imageUrl ? resolveClawHubCatalogIconUrl(e.catalog.imageUrl) : void 0,
installed: e.local.installed,
official: true,
pluginId: e.local.pluginId
}));
}
if (t.kind !== "plugin" && r.length === 0) {
const i = await searchClawHubSkills({
query: t.query,
limit: 20
}).catch(() => void 0);
if (!i) return n;
const a = i.filter((e) => e.official === true && !e.installOnly).slice(0, 3);
if (a.length > 0 && !e.workspaceDir) throw new Error("ClawHub skill recommendations require the current agent workspace.");
const o = e.workspaceDir && a.length > 0 ? (await prepareWorkspaceSkillStatus(e.workspaceDir, {
config: e.config,
agentId: e.agentId
})).report.skills : [];
r = a.map((e) => ({
type: "clawhub",
kind: "skill",
registry: resolveClawHubBaseUrl(),
id: e.installRef,
skillRef: e.installRef,
name: truncateUtf16Safe(e.displayName, 120),
description: e.summary ? truncateUtf16Safe(e.summary, 240) : void 0,
iconUrl: resolveClawHubImageUrl(e.icon),
installed: o.some((t) => {
const n = t.clawhub;
return n?.valid === true && !n.requestedReference && n.registry === resolveClawHubBaseUrl() && `@${n.ownerHandle}/${n.slug}` === e.installRef;
}),
official: true
}));
registerClawHubCatalogIconUrls(r.map((e) => e.iconUrl));
}
return {
cards: r,
text: r.length > 0 ? r.map((e) => `${e.name}: ${e.installed ? "Installed" : "Available to install"}.`).join("\n") : `No official ClawHub ${t.kind ?? "plugin or skill"} match was returned for “${t.query}”. Try a more specific capability name.`
};
}
//#endregion
export { resolveClawHubRecommendations };