UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

111 lines (110 loc) • 3.54 kB
import { o as normalizeLowercaseStringOrEmpty } from "./string-coerce-CCIiB4H7.mjs"; import { c as visibleWidth, t as iterateGraphemes } from "./ansi-CZa2t0Hf.mjs"; import { t as resolveNoteOutput } from "./note-output-8FFGu-hu.mjs"; import { r as stylePromptTitle } from "./prompt-style-CLys-6GQ.mjs"; import { AsyncLocalStorage } from "node:async_hooks"; import { note } from "@clack/prompts"; //#region 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); const d = a.split(/\s+/).filter(Boolean); const f = []; let p = ""; let m = o; let h = c; for (const e of d) { if (p) { const t = `${p} ${e}`; if ((u ? t.length : visibleWidth(t)) <= h) { p = t; continue; } f.push(m + p); p = ""; m = s; h = l; } if ((u ? e.length : visibleWidth(e)) > h && !e.includes("/") && !e.includes("\\") && !(e.includes("_") && FILE_LIKE_RE.test(e))) { let t = 0; for (const n of iterateGraphemes(e)) { const e = visibleWidth(n); if (p && t + e > h) { f.push(m + p); m = s; p = ""; t = 0; } p += n; t += e; } f.push(m + p); p = ""; m = s; h = l; continue; } p = e; } if (p || d.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("\n"); } 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("\n").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); } //#endregion export { withSuppressedNotes as a, resolveNoteOutputColumns as i, noteToStream as n, wrapNoteMessage as o, resolveNoteColumns as r, note$1 as t };