UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

7 lines • 4.5 kB
import{l as isRecord}from"./record-coerce-BTbqdJ3-.mjs";import{i as truncateWithMarker,r as truncateUtf16Safe}from"./utf16-slice-DA3Mllbx.mjs";import{c as redactSensitiveText}from"./redact-BT59pdZ_.mjs";import{i as isSilentReplyText}from"./tokens-DD0Y_anD.mjs";import{n as readTaggedReplyControl,r as stripMixedSilentReplyTokens}from"./tagged-reply-control-DSg5HbyD.mjs";import{s as scanReasoningTags}from"./reasoning-tag-syntax-B9oYHgIu.mjs";import{s as stripHeartbeatToken}from"./heartbeat-D5m0I0bZ.mjs";import{t as stripReasoningTagsFromMarkdown}from"./reasoning-tags-batch-CzMwDE06.mjs";import{g as stripInternalRuntimeContext}from"./internal-runtime-context-DervRrPi.mjs";import{i as stripInboundMetadata}from"./strip-inbound-meta-ftpq205E.mjs"; //!src/auto-reply/reply/display-text-sanitize.ts function stripInternalMetadataForDisplay(e){return stripInboundMetadata(stripInternalRuntimeContext(e))} //!src/agents/agent-run-terminal-receipt.ts const AGENT_RUN_ROUTE_CHANGE_MAX_CHARS=320;function normalizeAgentRunTerminalReceipt(e){const t=e;return t&&typeof t.runId===`string`&&typeof t.sessionId===`string`&&typeof t.turnId===`string`&&t.requested&&t.effective&&Array.isArray(t.successfulToolNames)?t:void 0}function formatAgentRunModelRef(e){const t=redactSensitiveText(`${e.provider}/${e.model}`,{mode:`tools`}).replace(/\s+/gu,` `).trim();return t?truncateUtf16Safe(t,128):void 0}function normalizeAgentRunRouteChange(e){const t=typeof e===`string`?redactSensitiveText(e,{mode:`tools`}).replace(/\s+/gu,` `).trim():``;return t?truncateUtf16Safe(t,AGENT_RUN_ROUTE_CHANGE_MAX_CHARS):void 0}function formatAgentRunRouteChange(e,t){if(e?.runId!==t||!e.rerouted||e.terminalDisposition!==`visible`)return;const n=formatAgentRunModelRef(e.requested);const r=formatAgentRunModelRef({...e.effective,model:e.effective.responseModel||e.effective.model});return n&&r?`Model route changed: ${n} → ${r}.`:void 0} //!src/agents/agent-run-terminal-reply.ts const AGENT_RUN_TERMINAL_REPLY_MAX_CHARS=4096;function isMessageToolNotCalledTerminalReply(e){return e?.disposition===`empty`&&e.code===`message-tool-not-called`}function sanitizeAgentRunTerminalReply(e){const t=stripInternalMetadataForDisplay(e).trim();const n=truncateWithMarker(t,AGENT_RUN_TERMINAL_REPLY_MAX_CHARS,{marker:`…`,reserve:1,trimEnd:true});if(!n)return{disposition:`empty`};return{disposition:`visible`,text:Buffer.from(n,`utf16le`).toString(`utf16le`)}}function filterAgentRunTerminalPayloadsForPresentation(e){if(!e.payloads)return e.payloads;return e.payloads.filter(e=>{const t=e.text;if(!t)return true;const n=stripHeartbeatToken(t,{mode:`message`});const r=e.mediaUrls?.some(e=>e.trim())===true||Boolean(e.mediaUrl?.trim());return!(n.shouldSkip&&!r)})}function prepareAgentRunReplyText(e){if(isSilentReplyText(e))return;return stripMixedSilentReplyTokens(e)??e.replace(/[\r\n]\s*NO_REPLY\s*$/iu,``)}function isSilentAfterClosedReasoning(e){const t=scanReasoningTags(e).tags.findLast(e=>e.isClose);return t!==void 0&&isSilentReplyText(e.slice(t.index+t.text.length))&&isSilentReplyText(stripReasoningTagsFromMarkdown(e,{mode:`strict`,scope:`all`}))}function prepareAgentRunTerminalReply(e){const t=e.rawText??``;const n=readTaggedReplyControl(t);const r=n?n.text:isSilentAfterClosedReasoning(t)?void 0:prepareAgentRunReplyText(t);return{text:r??``,terminalReply:r===void 0?{disposition:`silent`}:sanitizeAgentRunTerminalReply(r)}}function normalizeAgentRunTerminalReplySnapshot(e){if(!isRecord(e))return;const t=e.disposition;if(t===`silent`)return{disposition:t};if(t===`empty`){if(e.code===`message-tool-not-called`)return{disposition:t,code:`message-tool-not-called`};return{disposition:t}}if(t!==`visible`)return;const n=e.text;if(typeof n!==`string`)return;const r=sanitizeAgentRunTerminalReply(n);if(r.disposition===`visible`){const t=normalizeAgentRunRouteChange(e.modelRouteChange);if(t)r.modelRouteChange=t}return r}function mergeAgentRunTerminalReplySnapshot(e,t){if(!t||isMessageToolNotCalledTerminalReply(e))return e;if(!e||isMessageToolNotCalledTerminalReply(t)||e.disposition===`empty`)return t;return t.disposition===`empty`?e:t}export{prepareAgentRunTerminalReply as a,normalizeAgentRunRouteChange as c,prepareAgentRunReplyText as i,normalizeAgentRunTerminalReceipt as l,mergeAgentRunTerminalReplySnapshot as n,sanitizeAgentRunTerminalReply as o,normalizeAgentRunTerminalReplySnapshot as r,formatAgentRunRouteChange as s,filterAgentRunTerminalPayloadsForPresentation as t,stripInternalMetadataForDisplay as u};