openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
5 lines • 2.19 kB
JavaScript
import{c as normalizeOptionalLowercaseString,o as normalizeLowercaseStringOrEmpty}from"./string-coerce-CpTFcSwY.mjs";import{i as stripInboundMetadata}from"./strip-inbound-meta-ftpq205E.mjs";import{n as listChatCommands,r as listChatCommandsForConfig}from"./commands-registry-list-BUUc31nC.mjs";import{n as normalizeCommandBody}from"./commands-registry-normalize-yxTxMnHJ.mjs";import{r as matchPluginCommand}from"./commands-CsddUrkL.mjs";import{t as isAbortTrigger}from"./abort-trigger-text-DayuA6in.mjs";
//!src/auto-reply/reply/bash-command-input.ts
function isBangCommandInput(e){const t=e?.trimStart()??``;return t.startsWith(`!`)&&!/^!\[[^\r\n]*\](?:\(|\[)/.test(t)}
//!src/auto-reply/command-detection.ts
function normalizeControlCommandBody(e,t){return normalizeCommandBody(stripInboundMetadata(e?.trim()??``),t)}function hasNormalizedControlCommand(e,t){if(!e)return false;const n=normalizeLowercaseStringOrEmpty(e);return(t?listChatCommandsForConfig(t):listChatCommands()).some(t=>t.textAliases.some(r=>{const i=normalizeOptionalLowercaseString(r);return Boolean(i&&(n===i||t.acceptsArgs&&n.startsWith(i)&&/\s/.test(e.charAt(i.length))))}))}function hasControlCommand(e,t,n){return hasNormalizedControlCommand(normalizeControlCommandBody(e,n),t)}function isControlCommandMessage(e,t,n){const r=normalizeControlCommandBody(e,n);return hasNormalizedControlCommand(r,t)||isAbortTrigger(r)}function isSessionBoundaryCommandText(e,t){const n=normalizeControlCommandBody(e,t);return/^\/(?:new|reset)(?:\s|$)/i.test(n)&&!/^\/reset\s+soft(?:\s|$)/i.test(n)}function hasInlineCommandTokens(e){return/(?:^|\s)[/!][a-z]/i.test(e??``)}function hasCommandSyntax(e,t,n){if(isBangCommandInput(e)||isControlCommandMessage(e,t,n)||hasInlineCommandTokens(e))return true;const r=e?.match(/(?:^|\s)(\/\s+[a-z][\s\S]*)/i)?.[1];return r?matchPluginCommand(r)!==null:false}function shouldComputeCommandAuthorized(e,t,n){const r=e?.match(/(?:^|\s)(![\s\S]*)/)?.[1];return hasCommandSyntax(e,t,n)||isBangCommandInput(r)}export{shouldComputeCommandAuthorized as a,isSessionBoundaryCommandText as i,hasInlineCommandTokens as n,isBangCommandInput as o,isControlCommandMessage as r,hasControlCommand as t};