openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
82 lines (81 loc) • 2.67 kB
JavaScript
import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs";
//#region src/shared/clawhub-recommendations.ts
const CLAWHUB_RECOMMENDATION_LIMIT = 3;
const CLAWHUB_RECOMMENDATIONS_CHANNEL_DATA_KEY = "openclawClawHubRecommendations";
const sharedKeys = [
"type",
"id",
"name",
"description",
"iconUrl",
"installed",
"official",
"kind"
];
const pluginKeys = /* @__PURE__ */ new Set([...sharedKeys, "pluginId"]);
const skillKeys = /* @__PURE__ */ new Set([
...sharedKeys,
"registry",
"skillRef"
]);
const skillReference = /^@[a-z0-9](?:[a-z0-9._-]{0,38}[a-z0-9])?\/[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i;
function boundedText(e, t, n = 0) {
return typeof e === "string" && e.length >= n && (e.length <= t || Array.from(e).length <= t);
}
function optionalText(e, t) {
return e === void 0 || boundedText(e, t);
}
function readUrl(e) {
if (typeof e !== "string") return;
const t = e.trim().replace(/[\t\n\r]/g, "");
return URL.canParse(t) && boundedText(t, 2048) ? t : void 0;
}
function readClawHubRecommendation(e) {
if (!isRecord(e) || e.type !== "clawhub" || !boundedText(e.name, 120, 1) || !optionalText(e.description, 240) || typeof e.installed !== "boolean" || e.official !== true) return;
const t = e.iconUrl === void 0 ? void 0 : readUrl(e.iconUrl);
if (e.iconUrl !== void 0 && t === void 0) return;
const n = e.kind === "plugin" ? pluginKeys : skillKeys;
for (const t in e) if (!n.has(t)) return;
if (e.kind === "plugin") {
if (!boundedText(e.id, 512) || !/^ch_[A-Za-z0-9_-]+$/.test(e.id) || !optionalText(e.pluginId, 256)) return;
return {
type: "clawhub",
id: e.id,
name: e.name,
..."description" in e ? { description: e.description } : {},
..."iconUrl" in e ? { iconUrl: t } : {},
installed: e.installed,
official: true,
kind: "plugin",
..."pluginId" in e ? { pluginId: e.pluginId } : {}
};
}
if (e.kind !== "skill" || !boundedText(e.id, 256) || !skillReference.test(e.id) || e.skillRef !== e.id) return;
const r = readUrl(e.registry);
if (r === void 0) return;
return {
type: "clawhub",
id: e.id,
name: e.name,
..."description" in e ? { description: e.description } : {},
..."iconUrl" in e ? { iconUrl: t } : {},
installed: e.installed,
official: true,
kind: "skill",
registry: r,
skillRef: e.id
};
}
function readClawHubRecommendations(e) {
const t = e?.[CLAWHUB_RECOMMENDATIONS_CHANNEL_DATA_KEY];
if (!Array.isArray(t) || t.length > 3) return [];
const n = [];
for (const e of t) {
const t = readClawHubRecommendation(e);
if (!t) return [];
n.push(t);
}
return n;
}
//#endregion
export { readClawHubRecommendations as n, CLAWHUB_RECOMMENDATIONS_CHANNEL_DATA_KEY as t };