UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

7 lines (6 loc) • 1.65 kB
import{i as truncateWithMarker}from"./utf16-slice-DA3Mllbx.mjs";import{a as mapNestedStrings}from"./plugin-text-transforms-DAtG_ddJ.mjs";import{s as markInboundContextLabel}from"./strip-inbound-meta-ftpq205E.mjs";import{n as resolvePromptHistoryLimit}from"./history-limit-BpNaFIRz.mjs";import{t as normalizeInboundTextNewlines}from"./inbound-text-BoSvn4e1.mjs"; //!src/auto-reply/reply/channel-prompt-context.ts function appendChannelPromptContext(e,t){if(!t?.length)return e;const n=t.map(normalizeInboundTextNewlines).filter(Boolean);if(n.length===0)return e;return[e,[markInboundContextLabel(`Context:`),...n].join(` `)].filter(Boolean).join(` `)}const MAX_CONTEXT_JSON_STRING_CHARS=2e3;function neutralizeMarkdownFences(e){return e.replaceAll("```","`​``")}function sanitizeContextJsonString(e){return neutralizeMarkdownFences(truncateWithMarker(e,MAX_CONTEXT_JSON_STRING_CHARS,{marker:`…[truncated]`,reserve:14,trimEnd:true}))}function formatContextJsonBlock(e,t){return[e,"```json",JSON.stringify(mapNestedStrings(t,sanitizeContextJsonString)),"```"].join(` `)}function selectInboundHistoryContext(e){const t=e.InboundHistory??[];const n=e.SessionTranscriptContext?.historyKind===`recent`;const r=e.SessionTranscriptContext?.historyLimit;const i=n&&typeof r===`number`&&Number.isSafeInteger(r)&&r>=0?resolvePromptHistoryLimit(r,20):20;return{boundedHistory:i>0?t.slice(-i):[],historyLabel:n?`Recent chat history:`:`Chat history since last reply:`,truncated:t.length>i}}export{selectInboundHistoryContext as a,neutralizeMarkdownFences as i,appendChannelPromptContext as n,formatContextJsonBlock as r,MAX_CONTEXT_JSON_STRING_CHARS as t};