openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 3.56 kB
JavaScript
import{c as normalizeOptionalLowercaseString}from"./string-coerce-CpTFcSwY.mjs";import{r as truncateUtf16Safe}from"./utf16-slice-DA3Mllbx.mjs";import{i as getPluginRegistryForContext}from"./gateway-request-scope-7deHmsb_.mjs";import{t as getChannelPlugin}from"./registry-CpNh6QcT.mjs";import"./plugins-DxOycUNJ.mjs";import{t as COMMAND_DESCRIPTION_MAX_LENGTH}from"./commands-Cnlfo3ir.mjs";import{r as listChatCommandsForConfig}from"./commands-registry-list-BUUc31nC.mjs";import{m as supportsNativeProvider}from"./commands-registry-Dh5K81S2.mjs";import{n as getPluginCommandEntrySpecsFromRegistrations,t as getPluginCommandEntrySpecs}from"./command-specs-CT6Mu9CU.mjs";import{i as prepareSkillCommandsForAgents}from"./chat-commands-C2fIuWNC.mjs";
//!src/gateway/server-methods/commands-list-result.ts
async function buildCommandsListResult(e){const t=e.includeArgs!==false;const n=e.scope??`both`;const r=n===`text`?`text`:`native`;const i=normalizeOptionalLowercaseString(e.provider);const a=await prepareSkillCommandsForAgents({cfg:e.cfg,agentIds:[e.agentId],sessionEntry:e.sessionEntry,sessionKey:e.sessionKey,...e.projectSkillRoot});const o=listChatCommandsForConfig(e.cfg,{skillCommands:a});const s=new Map(a.map(e=>[`skill:${e.skillName}`,e]));const c=[];for(const e of o){if(n!==`both`&&e.scope!==`both`&&e.scope!==n)continue;if(r===`native`&&e.scope!==`text`&&i&&!supportsNativeProvider(e,i))continue;const a=s.get(e.key);const o=e.nativeName??e.key;const l=e.scope===`text`?void 0:i&&e.nativeName?getChannelPlugin(i)?.commands?.resolveNativeCommandName?.({commandKey:e.key,defaultName:e.nativeName})??o:o;let u;if(e.scope!==`native`){const t=/* @__PURE__ */ new Set;for(const n of e.textAliases){const e=n.trim();if(!e)continue;const r=truncateUtf16Safe(e,200);t.add(r.startsWith(`/`)?r:`/${r}`);if(t.size>=20)break}u=t.size>0?[...t]:[`/${truncateUtf16Safe(e.key,200)}`]}c.push({name:truncateUtf16Safe(r===`text`?u?.[0]?.slice(1)??e.key:l??e.key,200),...l?{nativeName:truncateUtf16Safe(l,200)}:{},...u?{textAliases:u}:{},description:truncateUtf16Safe(e.description??``,COMMAND_DESCRIPTION_MAX_LENGTH),...e.category?{category:e.category===`docks`?`tools`:e.category}:{},source:a?`skill`:`native`,scope:e.scope,acceptsArgs:Boolean(e.acceptsArgs),...t&&e.acceptsArgs&&e.args?.length?{args:e.args.slice(0,20).map(e=>{const t={name:truncateUtf16Safe(e.name,200),description:truncateUtf16Safe(e.description,500),type:e.type};if(e.required)t.required=true;if(Array.isArray(e.choices))t.choices=e.choices.slice(0,50).map(e=>({value:truncateUtf16Safe(typeof e===`string`?e:e.value,200),label:truncateUtf16Safe(typeof e===`string`?e:e.label,200)}));if(typeof e.choices===`function`)t.dynamic=true;return t})}:{},...a?{skillDisplayName:truncateUtf16Safe(a.displayName??a.skillName,200),skillModelVisible:a.modelVisible!==false,skillReferenceable:!a.promptTemplate}:{}})}const l=getPluginRegistryForContext();const u=l?getPluginCommandEntrySpecsFromRegistrations(l.commands,i,{config:e.cfg}):getPluginCommandEntrySpecs(i,{config:e.cfg});for(const e of u){if(r===`native`&&!e.nativeName)continue;c.push({name:truncateUtf16Safe(r===`text`?e.name:e.nativeName??e.name,200),...e.nativeName?{nativeName:truncateUtf16Safe(e.nativeName,200)}:{},textAliases:[`/${truncateUtf16Safe(e.name,200)}`],description:truncateUtf16Safe(e.description??``,COMMAND_DESCRIPTION_MAX_LENGTH),source:`plugin`,scope:`both`,acceptsArgs:e.acceptsArgs,...e.clientPresentation?{clientPresentation:e.clientPresentation}:{}})}return{commands:c.slice(0,500)}}export{buildCommandsListResult as t};