openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.16 kB
JavaScript
import{l as isRecord}from"./record-coerce-BTbqdJ3-.mjs";
//!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`||typeof e.official!==`boolean`)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;let r;if(e.kind===`plugin`){if(!boundedText(e.id,512)||!/^ch_[A-Za-z0-9_-]+$/.test(e.id)||!optionalText(e.pluginId,256))return;r={official:e.official,kind:`plugin`,...`pluginId`in e?{pluginId:e.pluginId}:{}}}else{if(e.kind!==`skill`||!e.official||!boundedText(e.id,256)||!skillReference.test(e.id)||e.skillRef!==e.id)return;const t=readUrl(e.registry);if(t===void 0)return;r={official:true,kind:`skill`,registry:t,skillRef:e.id}}return{type:`clawhub`,id:e.id,name:e.name,...`description`in e?{description:e.description}:{},...`iconUrl`in e?{iconUrl:t}:{},installed:e.installed,...r}}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}export{readClawHubRecommendations as n,CLAWHUB_RECOMMENDATIONS_CHANNEL_DATA_KEY as t};