UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

5 lines • 3.01 kB
import{o as normalizeLowercaseStringOrEmpty}from"./string-coerce-CpTFcSwY.mjs";import{c as visibleWidth,t as iterateGraphemes}from"./ansi-54CEWBZf.mjs";import{t as resolveNoteOutput}from"./note-output-qKC3uvZV.mjs";import{r as stylePromptTitle}from"./prompt-style-B-J86yY8.mjs";import{AsyncLocalStorage}from"node:async_hooks";import{note}from"@clack/prompts"; //!packages/terminal-core/src/note.ts const MIN_NOTE_COLUMNS=80;const FILE_LIKE_RE=/^[a-zA-Z0-9._-]+$/;const suppressNotesStorage=new AsyncLocalStorage;function isSuppressedByEnv(e){const t=normalizeLowercaseStringOrEmpty(e);return Boolean(t)&&t!==`0`&&t!==`false`&&t!==`off`}function wrapLine(e,t){if(e.trim().length===0)return[e];const n=e.match(/^(\s*)([-*\u2022]\s+)?(.*)$/);const r=n?.[1]??``;const i=n?.[2]??``;const a=n?.[3]??``;const o=`${r}${i}`;const s=`${r}${i?` `.repeat(i.length):``}`;const c=Math.max(10,t-visibleWidth(o));const l=Math.max(10,t-visibleWidth(s));const u=/^[\u0020-\u007E]*$/.test(a);let d=0;const f=[];let p=``;let m=o;let h=c;for(const e of a.matchAll(/\S+/g)){const t=e[0];const n=a.slice(d,e.index);const r=/^ +$/.test(n)?n:` `;d=e.index+t.length;if(p){const e=`${p}${r}${t}`;if((u?e.length:visibleWidth(e))<=h){p=e;continue}f.push(m+p);p=``;m=s;h=l}if((u?t.length:visibleWidth(t))>h&&!t.includes(`/`)&&!t.includes(`\\`)&&!(t.includes(`_`)&&FILE_LIKE_RE.test(t))){let e=0;for(const n of iterateGraphemes(t)){const t=visibleWidth(n);if(p&&e+t>h){f.push(m+p);m=s;p=``;e=0}p+=n;e+=t}f.push(m+p);p=``;m=s;h=l;continue}p=t}if(p||f.length===0)f.push(m+p);return f}function coerceNoteMessage(e){if(typeof e===`string`)return e;if(typeof e===`number`||typeof e===`boolean`||typeof e===`bigint`)return String(e);if(e instanceof Error)return e.message?`${e.name}: ${e.message}`:e.name;return``}function wrapNoteMessage(e,t={}){const n=coerceNoteMessage(e);const r=t.columns??resolveNoteColumns(process.stdout.columns);const i=t.maxWidth??Math.max(40,Math.min(88,r-10));return n.split(/\r\n?|[\n\u2028\u2029]/u).flatMap(e=>wrapLine(e,i)).join(` `)}function resolveNoteColumns(e){if(!Number.isFinite(e)||!e||e<MIN_NOTE_COLUMNS)return MIN_NOTE_COLUMNS;return e}function resolveNoteOutputColumns(e,t){const n=e.split(` `).reduce((e,t)=>Math.max(e,visibleWidth(t)),0);return Math.max(t,n+6)}function createNoteOutput(e,t){if(e.columns===t)return e;const n=Object.create(e);Object.defineProperty(n,"columns",{value:t,configurable:true});n.write=e.write.bind(e);return n}function noteToStream(e,t,n){if(suppressNotesStorage.getStore()===true||isSuppressedByEnv(process.env.OPENCLAW_SUPPRESS_NOTES))return;const r=resolveNoteColumns(n.columns);const i=wrapNoteMessage(e,{columns:r});note(i,stylePromptTitle(t),{output:createNoteOutput(n,resolveNoteOutputColumns(i,r))})}function note$1(e,t){noteToStream(e,t,resolveNoteOutput())}function withSuppressedNotes(e){return suppressNotesStorage.run(true,e)}export{withSuppressedNotes as a,resolveNoteOutputColumns as i,noteToStream as n,wrapNoteMessage as o,resolveNoteColumns as r,note$1 as t};