UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 2.51 kB
import{c as stripInlineDirectiveTagsForDisplay}from"./directive-tags-batch-BDwCnZoj.mjs";import{a as findCodeOwnership,n as canReuseMarkdownOwnershipForAppend}from"./code-regions-iiBEGTOw.mjs"; //!src/utils/directive-tags-stream.ts function hasDirectiveCodePrefixOpportunity(e,t){if(!t)return false;const n=e.length-t.length;const r=Math.max(0,n-4);let i=-1;for(const t of e.slice(r).matchAll(/(?:\r\n|\n|\r)[^\S\r\n]*\S/g))if(r+t.index+t[0].length>n)i=r+t.index;if(i===-1)return false;const a=e.lastIndexOf(`[[`);return a!==-1&&i>a}function findDirectiveCodePrefix(e,t){if(!hasDirectiveCodePrefixOpportunity(e,t))return;const{regions:n,retainStart:r,completedParagraphs:i}=findCodeOwnership(e);let a=0;let o=0;let s=0;for(let t=e.indexOf(`[[`);t!==-1;t=e.indexOf(`[[`,t+1)){let e=n[a];while(e&&e.end<=t)e=n[++a];let c=i[o];while(c&&c.end<=t)c=i[++o];if(!e||e.start>t||e.end<t+2)return;if(e.block){if(e.end>r)return;s=e.end;continue}if(!c||c.hasReferenceCandidate||c.start>e.start||c.end<e.end)return;s=c.end}return s?{end:s,checkedRawLength:e.length}:void 0}const APPEND_SAFE_DELTA=/^[^[`~]*$/u;const AUDIO_DIRECTIVE=/\[\[\s*audio_as_voice\s*\]\]/iu;function hasUnsettledDirectiveMarker(e){const t=e.lastIndexOf(`[[`);return t!==-1&&e.lastIndexOf(`]]`)<t}const inlineDirectiveDisplayTextFilter={transform:e=>stripInlineDirectiveTagsForDisplay(e).text,create:()=>{let e;let t=false;let n=``;let r=``;let i=``;let a=true;let o=true;let s=false;let c=false;let l;const projector=u=>{const d=u.delta;if(d===null){r=u.text;i=stripInlineDirectiveTagsForDisplay(r).text;e=i===r?findDirectiveCodePrefix(r,r):void 0;t=r.includes(`[[`);o=!hasUnsettledDirectiveMarker(r);s=hasUnsettledDirectiveMarker(i);c=AUDIO_DIRECTIVE.test(r);a=i===r;l=void 0;n=r.slice(-1);return{text:i,delta:null}}if(d===``)return{text:i,delta:``};if((e!==void 0||o&&!s)&&r.length+d.length===u.text.length&&APPEND_SAFE_DELTA.test(d)&&!c&&(!t||canReuseMarkdownOwnershipForAppend(r,d,l??=findCodeOwnership(r)))){r=u.text;n=d.slice(-1);if(a){i=r;return u}i+=d;return{text:i,delta:d}}const f=i;if((n+d).includes(`[[`)){t=true;e=void 0}n=d.slice(-1);r=u.text;if(t&&!e){i=stripInlineDirectiveTagsForDisplay(r).text;e=i===r?findDirectiveCodePrefix(r,d):void 0}else i=r;o=!hasUnsettledDirectiveMarker(r);s=hasUnsettledDirectiveMarker(i);c=AUDIO_DIRECTIVE.test(r);a=i===r;l=void 0;if(a)return u;return{text:i,delta:i===f?``:i.startsWith(f)?i.slice(f.length):null}};return projector}};export{inlineDirectiveDisplayTextFilter as n,findDirectiveCodePrefix as t};