openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 6.13 kB
JavaScript
import{l as normalizeOptionalString}from"./string-coerce-CpTFcSwY.mjs";import{l as resolveSessionStorePathCore}from"./paths-CcxgiC3g.mjs";import{r as resolveAgentConfig}from"./agent-scope-config-CG9CFpGX.mjs";import{n as resolveDefaultModelForAgent}from"./model-selection-config-CnvHkHXn.mjs";import{o as resolveEffectiveAgentRuntime}from"./thinking-runtime-V6V09nGt.mjs";import{r as resolveStoredModelOverrideAsync}from"./stored-model-overrides-phlTYtpN.mjs";import{a as formatFastModeCurrentStatus}from"./fast-mode-DEUN0Mjk.mjs";import{t as resolveFastModeState}from"./fast-mode-Bole1OXq.mjs";import"./string-coerce-runtime-BYDH9Quw.mjs";import{f as resolveCommandArgMenuAsync,i as formatCommandArgMenuTitle,l as parseCommandArgs,n as canResolveCommandArgMenu,r as findCommandByNativeName,t as buildCommandTextFromArgs}from"./commands-registry-Dh5K81S2.mjs";import{n as getSessionEntryAsync}from"./session-store-runtime-internal-B2Zhl90F.mjs";import"./session-store-runtime-BiMBNaHL.mjs";import{r as resolveThinkingDefaultWithRuntimeCatalog}from"./agent-runtime-SZFAv6hc.mjs";import"./command-auth-native-Bl-iUqlk.mjs";import{t as loadCommandArgMenuModelCatalog}from"./command-surface-ChzzeOxO.mjs";import{X as withTelegramApiErrorLogging}from"./helpers-B2EnHAZw.mjs";import{h as buildInlineKeyboard}from"./text-chunk-limit-YsOTt7TW.mjs";import{t as buildTelegramNativeCommandCallbackData}from"./native-command-callback-data-IMqzGQhB.mjs";import{t as prepareTelegramCommandDispatch}from"./bot-native-command-dispatch-BJbv-khQ.mjs";
//!extensions/telegram/src/bot-native-command-builtins.ts
async function resolveTelegramCommandMenuModelContext(e,t=`menu`){const n=t===`fast`?resolveDefaultModelForAgent(e):void 0;const r=n?{provider:n.provider,model:n.model}:{};if(!e.sessionKey.trim())return r;try{const r=resolveSessionStorePathCore(e.cfg.session?.store,{agentId:e.agentId});const i=n??resolveDefaultModelForAgent(e);const a=await getSessionEntryAsync({storePath:r,sessionKey:e.sessionKey});const o=normalizeOptionalString(a?.thinkingLevel);const s=a?.fastMode;let c;if(a?.modelOverrideSource===`auto`&&normalizeOptionalString(a.modelOverride))c={provider:i.provider,model:i.model};else{const n=await resolveStoredModelOverrideAsync({sessionEntry:a,loadSessionEntry:e=>getSessionEntryAsync({storePath:r,sessionKey:e}),sessionKey:e.sessionKey,defaultProvider:i.provider});if(t===`fast`)return{provider:n?.provider??i.provider,model:n?.model??i.model,sessionEntry:a};if(n?.model)c={provider:n.provider||i.provider,model:n.model};else{const e=normalizeOptionalString(a?.providerOverride)??normalizeOptionalString(a?.modelProvider);const t=normalizeOptionalString(a?.modelOverride)??normalizeOptionalString(a?.model);c={...e?{provider:e}:{},...t?{model:t}:{}}}}if(t===`fast`)return{...c,sessionEntry:a};return{...c,...o?{thinkingLevel:o}:{},...s!==void 0?{fastMode:s}:{},agentRuntime:resolveEffectiveAgentRuntime({cfg:e.cfg,provider:c.provider??i.provider,modelId:c.model??i.model,agentId:e.agentId,sessionKey:e.sessionKey,sessionEntry:a})}}catch{return r}}async function executeTelegramBuiltinCommand(e){const t=findCommandByNativeName(e.commandName,`telegram`,{includeBundledChannelFallback:false});if(!t)return`fall-through`;const n=parseCommandArgs(t,e.rawText);const r=buildCommandTextFromArgs(t,n);if(t.key!==`login`&&!canResolveCommandArgMenu({command:t,args:n}))return`fall-through`;if(t.key===`login`&&e.shouldSkip?.())return`handled`;const i=await prepareTelegramCommandDispatch({...e,requireAuth:true});if(!i)return`handled`;if(t.key===`login`){const{executeTelegramLoginCommand:e}=await import(`./bot-native-command-login-BZmzytzZ.mjs`);return await e({dispatch:i,commandText:r,currentProvider:(await resolveTelegramCommandMenuModelContext({cfg:i.runtimeCfg,agentId:i.route.agentId,sessionKey:i.targetSessionKey})).provider??resolveDefaultModelForAgent({cfg:i.runtimeCfg,agentId:i.route.agentId}).provider})?`handled-clear-buttons`:`handled`}const a=t.argsMenu&&!(n?.raw&&!n.values)&&t.args?.some(e=>typeof e.choices===`function`&&n?.values?.[e.name]==null);const o={cfg:i.runtimeCfg,agentId:i.route.agentId,sessionKey:a?i.targetSessionKey:``};const s=a?await resolveTelegramCommandMenuModelContext(o,t.key===`fast`?`fast`:`menu`):{};const c=t.key===`think`&&a?await loadCommandArgMenuModelCatalog({cfg:i.runtimeCfg,agentId:i.route.agentId}):void 0;const l=await resolveCommandArgMenuAsync({command:t,args:n,cfg:i.runtimeCfg,session:{agentId:i.route.agentId,sessionKey:i.targetSessionKey},...s,catalog:c});if(l){if(e.shouldSkip?.())return`handled`;let n;if(t.key===`think`){const e=c??[];n=normalizeOptionalString(s.thinkingLevel);if(!n)n=normalizeOptionalString(resolveAgentConfig(i.runtimeCfg,i.route.agentId)?.thinkingDefault);if(!n){const t=resolveDefaultModelForAgent({cfg:i.runtimeCfg,agentId:i.route.agentId});n=await resolveThinkingDefaultWithRuntimeCatalog({cfg:i.runtimeCfg,agentId:i.route.agentId,provider:s.provider??t.provider,model:s.model??t.model,agentRuntime:s.agentRuntime,loadModelCatalog:async()=>e})}}let a;if(t.key===`fast`){const e=resolveDefaultModelForAgent({cfg:i.runtimeCfg,agentId:i.route.agentId});a=formatFastModeCurrentStatus(resolveFastModeState({cfg:i.runtimeCfg,provider:s.provider??e.provider,model:s.model??e.model,agentId:i.route.agentId,sessionEntry:s.sessionEntry}))}let o=formatCommandArgMenuTitle({command:t,menu:l});if(t.key===`think`&&n)o=`Current thinking level: ${n}.\n${o}`;else if(t.key===`fast`&&a){const e=l.choices.map(e=>e.label.trim()).filter(Boolean).join(`, `);o=e?`${a}\nOptions: ${e}.`:a}const u=[];for(let e=0;e<l.choices.length;e+=2)u.push(l.choices.slice(e,e+2).map(e=>({text:e.label,callback_data:buildTelegramNativeCommandCallbackData(buildCommandTextFromArgs(t,{values:{[l.arg.name]:e.value}}))})));const d=buildInlineKeyboard(u);await withTelegramApiErrorLogging({operation:`sendMessage`,runtime:i.runtime,fn:()=>i.bot.api.sendMessage(i.chatId,o,{...d?{reply_markup:d}:{},...i.threadParams})});await i.recordDeliveredReply(r,`${o}\n${l.choices.map(e=>e.label).join(`, `)}`,`menu`);return`handled`}return`fall-through`}export{executeTelegramBuiltinCommand};