UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 3.06 kB
import{l as normalizeOptionalString}from"./string-coerce-CpTFcSwY.mjs"; //!src/auto-reply/command-turn-context.ts function resolveCommandBody(e){if(typeof e.commandText===`string`)return e.commandText;return normalizeOptionalString(e.CommandBody)??normalizeOptionalString(e.BodyForCommands)??normalizeOptionalString(e.RawBody)??normalizeOptionalString(e.Body)}function parseCommandName(e){if(!e?.startsWith(`/`))return;const t=e.slice(1).split(/\s+/,1)[0]?.split(`@`,1)[0];return normalizeOptionalString(t)}function commandTurnKindToSource(e){return e===`native`?`native`:e===`text-slash`?`text`:`message`}function normalizeCommandTurnKind(e){return e===`native`||e===`text-slash`||e===`normal`?e:void 0}function normalizeCommandTurnSource(e){return e===`native`||e===`text`||e===`message`?e:void 0}function createCommandTurnContext(e,t){return{...e===`native`?{kind:`native`,source:`native`,authorized:t.authorized}:e===`text`?{kind:`text-slash`,source:`text`,authorized:t.authorized}:{kind:`normal`,source:`message`,authorized:false},commandName:t.commandName,body:t.body}}function normalizeExplicitCommandTurn(e,t){if(!e||typeof e!==`object`)return;const n=e;const r=normalizeCommandTurnKind(n.kind);const i=normalizeCommandTurnSource(n.source)??(r?commandTurnKindToSource(r):void 0);if(r&&i&&commandTurnKindToSource(r)!==i)return;if(!i)return;const a=normalizeOptionalString(n.body)??resolveCommandBody(t);return createCommandTurnContext(i,{authorized:typeof n.authorized===`boolean`?n.authorized:t.CommandAuthorized===true,commandName:normalizeOptionalString(n.commandName)??parseCommandName(a),body:a})}function resolveCommandTurnContext(e){const t=normalizeExplicitCommandTurn(e.CommandTurn,e);if(t)return t;const n=normalizeCommandTurnSource(e.CommandSource)??`message`;const r=resolveCommandBody(e);return createCommandTurnContext(n,{authorized:e.CommandAuthorized===true,commandName:parseCommandName(r),body:r})}function isNativeCommandTurn(e){return e?.kind===`native`}function isTextSlashCommandTurn(e){return e?.kind===`text-slash`}function isAuthorizedTextSlashCommandTurn(e){return e?.kind===`text-slash`&&e.authorized}function isExplicitCommandTurn(e){return e?.kind===`native`||e?.kind===`text-slash`&&e.authorized}function isExplicitFollowupCommandTurn(e){const t=resolveCommandTurnContext(e);return t.kind!==`normal`&&t.authorized&&t.commandName?.toLowerCase()===`followup`}function resolveCommandTurnTargetSessionKey(e){const t=resolveCommandTurnContext(e);const n=isAuthorizedTextSlashCommandTurn(t)&&(t.commandName?.toLowerCase()===`steer`||t.commandName?.toLowerCase()===`tell`||t.commandName?.toLowerCase()===`followup`);if(!isNativeCommandTurn(t)&&!n)return;return normalizeOptionalString(e.CommandTargetSessionKey)}export{isExplicitFollowupCommandTurn as a,resolveCommandBody as c,isExplicitCommandTurn as i,resolveCommandTurnContext as l,createCommandTurnContext as n,isNativeCommandTurn as o,isAuthorizedTextSlashCommandTurn as r,isTextSlashCommandTurn as s,commandTurnKindToSource as t,resolveCommandTurnTargetSessionKey as u};