openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
52 lines (46 loc) • 30.9 kB
JavaScript
import{r as copyCodeModeControlToolIdentity}from"./code-mode-control-tools-CNDO-Zgv.mjs";import{l as copyInternalToolExecutionPreparer}from"./internal-hooks-Bn77tst6.mjs";import{v as copyAgentToolReplaySafety}from"./agent-tool-metadata-D7ctyGhj.mjs";import{t as decodeHtmlEntities}from"./html-entities-Bw-Sof4g.mjs";import{createRequire}from"node:module";import*as fs$1 from"node:fs";import{lstatSync,realpathSync}from"node:fs";import{fileURLToPath}from"node:url";import{join,relative,sep}from"node:path";import{readRegularFileSync}from"@openclaw/fs-safe/advanced";import{hasNodeErrorCode}from"@openclaw/fs-safe/path";import chalk from"chalk";import{Type}from"typebox";import{Errors}from"typebox/schema";import ignore from"ignore";
//!src/agents/utils/syntax-highlight.ts
let highlightJsRuntime;function isHighlightJs(e){return typeof e===`object`&&e!==null&&`getLanguage`in e&&typeof e.getLanguage===`function`&&`highlight`in e&&typeof e.highlight===`function`}function loadHighlightJsRuntime(){if(highlightJsRuntime)return highlightJsRuntime;const e=createRequire(import.meta.url)(fileURLToPath(new URL(`highlight-runtime-c27_1xR4.mjs`,import.meta.url).href)).default;if(!isHighlightJs(e))throw new TypeError(`highlight.js did not expose the expected Node API`);return highlightJsRuntime=e}const SPAN_CLOSE=`</span>`;const HIGHLIGHT_CLASS_PREFIX=`hljs-`;function getScopeFromSpanTag(e){const t=/\sclass\s*=\s*(?:"([^"]*)"|'([^']*)')/.exec(e);const n=t?.[1]??t?.[2];if(!n)return;for(const e of n.split(/\s+/))if(e.startsWith(HIGHLIGHT_CLASS_PREFIX))return e.slice(5)}function getScopeFormatter(e,t){const n=t[e];if(n)return n;for(const n of[`.`,`-`]){const r=e.indexOf(n);if(r!==-1){const n=t[e.slice(0,r)];if(n)return n}}}function getActiveFormatter(e,t){for(let n=e.length-1;n>=0;n--){const r=e[n];if(!r)continue;const i=getScopeFormatter(r,t);if(i)return i}return t.default}function renderHighlightedHtml(e,t){let n=``;let r=``;const i=[];const flushText=()=>{if(!r)return;const e=decodeHtmlEntities(r);const a=getActiveFormatter(i,t);n+=a?a(e):e;r=``};let a=0;while(a<e.length){const t=e[a+5];if(e.startsWith(`<span`,a)&&(t===`>`||t===` `||t===` `||t===`
`||t===`\r`)){const t=e.indexOf(`>`,a+5);if(t!==-1){flushText();const n=getScopeFromSpanTag(e.slice(a,t+1));i.push(n);a=t+1;continue}}if(e.startsWith(SPAN_CLOSE,a)){flushText();i.pop();a+=7;continue}r+=e[a];a++}flushText();return n}function highlight(e,t,n){const{value:r}=loadHighlightJsRuntime().highlight(e,{language:t,ignoreIllegals:true});return renderHighlightedHtml(r,n)}function supportsLanguage(e){return loadHighlightJsRuntime().getLanguage(e)!==void 0}
//!src/agents/modes/interactive/tui-runtime.ts
const require=createRequire(import.meta.url);function loadTuiRuntime(){return require("@earendil-works/pi-tui")}
//!src/agents/modes/interactive/theme/theme-schema.ts
const ColorValueSchema=Type.Union([Type.String(),Type.Integer({minimum:0,maximum:255})]);const ThemeJsonSchema=Type.Object({$schema:Type.Optional(Type.String()),name:Type.String(),vars:Type.Optional(Type.Record(Type.String(),ColorValueSchema)),colors:Type.Object({accent:ColorValueSchema,border:ColorValueSchema,borderAccent:ColorValueSchema,borderMuted:ColorValueSchema,success:ColorValueSchema,error:ColorValueSchema,warning:ColorValueSchema,muted:ColorValueSchema,dim:ColorValueSchema,text:ColorValueSchema,thinkingText:ColorValueSchema,selectedBg:ColorValueSchema,userMessageBg:ColorValueSchema,userMessageText:ColorValueSchema,customMessageBg:ColorValueSchema,customMessageText:ColorValueSchema,customMessageLabel:ColorValueSchema,toolPendingBg:ColorValueSchema,toolSuccessBg:ColorValueSchema,toolErrorBg:ColorValueSchema,toolTitle:ColorValueSchema,toolOutput:ColorValueSchema,mdHeading:ColorValueSchema,mdLink:ColorValueSchema,mdLinkUrl:ColorValueSchema,mdCode:ColorValueSchema,mdCodeBlock:ColorValueSchema,mdCodeBlockBorder:ColorValueSchema,mdQuote:ColorValueSchema,mdQuoteBorder:ColorValueSchema,mdHr:ColorValueSchema,mdListBullet:ColorValueSchema,toolDiffAdded:ColorValueSchema,toolDiffRemoved:ColorValueSchema,toolDiffContext:ColorValueSchema,syntaxComment:ColorValueSchema,syntaxKeyword:ColorValueSchema,syntaxFunction:ColorValueSchema,syntaxVariable:ColorValueSchema,syntaxString:ColorValueSchema,syntaxNumber:ColorValueSchema,syntaxType:ColorValueSchema,syntaxOperator:ColorValueSchema,syntaxPunctuation:ColorValueSchema,thinkingOff:ColorValueSchema,thinkingMinimal:ColorValueSchema,thinkingLow:ColorValueSchema,thinkingMedium:ColorValueSchema,thinkingHigh:ColorValueSchema,thinkingXhigh:ColorValueSchema,bashMode:ColorValueSchema}),export:Type.Optional(Type.Object({pageBg:Type.Optional(ColorValueSchema),cardBg:Type.Optional(ColorValueSchema),infoBg:Type.Optional(ColorValueSchema)}))});
//!src/agents/modes/interactive/theme/theme-validator.generated.js
/*!
TypeBox
The MIT License (MIT)
Copyright (c) 2017-2026 Haydn Paterson
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
var isThemeJson=(()=>{let e=[/^.*$/u],check_0=t=>typeof t==`object`&&t!==null&&!Array.isArray(t)&&`name`in t&&`colors`in t&&(t.$schema===void 0||!(`$schema`in t)||typeof t.$schema==`string`)&&typeof t.name==`string`&&(t.vars===void 0||!(`vars`in t)||typeof t.vars==`object`&&t.vars!==null&&!Array.isArray(t.vars)&&Object.entries(t.vars).every(([t,n],r)=>!e[0].test(t)||typeof n==`string`||Number.isInteger(n)&&(!(Number.isFinite(n)||typeof n==`bigint`)||n>=0&&n<=255)))&&typeof t.colors==`object`&&t.colors!==null&&!Array.isArray(t.colors)&&`accent`in t.colors&&`border`in t.colors&&`borderAccent`in t.colors&&`borderMuted`in t.colors&&`success`in t.colors&&`error`in t.colors&&`warning`in t.colors&&`muted`in t.colors&&`dim`in t.colors&&`text`in t.colors&&`thinkingText`in t.colors&&`selectedBg`in t.colors&&`userMessageBg`in t.colors&&`userMessageText`in t.colors&&`customMessageBg`in t.colors&&`customMessageText`in t.colors&&`customMessageLabel`in t.colors&&`toolPendingBg`in t.colors&&`toolSuccessBg`in t.colors&&`toolErrorBg`in t.colors&&`toolTitle`in t.colors&&`toolOutput`in t.colors&&`mdHeading`in t.colors&&`mdLink`in t.colors&&`mdLinkUrl`in t.colors&&`mdCode`in t.colors&&`mdCodeBlock`in t.colors&&`mdCodeBlockBorder`in t.colors&&`mdQuote`in t.colors&&`mdQuoteBorder`in t.colors&&`mdHr`in t.colors&&`mdListBullet`in t.colors&&`toolDiffAdded`in t.colors&&`toolDiffRemoved`in t.colors&&`toolDiffContext`in t.colors&&`syntaxComment`in t.colors&&`syntaxKeyword`in t.colors&&`syntaxFunction`in t.colors&&`syntaxVariable`in t.colors&&`syntaxString`in t.colors&&`syntaxNumber`in t.colors&&`syntaxType`in t.colors&&`syntaxOperator`in t.colors&&`syntaxPunctuation`in t.colors&&`thinkingOff`in t.colors&&`thinkingMinimal`in t.colors&&`thinkingLow`in t.colors&&`thinkingMedium`in t.colors&&`thinkingHigh`in t.colors&&`thinkingXhigh`in t.colors&&`bashMode`in t.colors&&(typeof t.colors.accent==`string`||Number.isInteger(t.colors.accent)&&(!(Number.isFinite(t.colors.accent)||typeof t.colors.accent==`bigint`)||t.colors.accent>=0&&t.colors.accent<=255))&&(typeof t.colors.border==`string`||Number.isInteger(t.colors.border)&&(!(Number.isFinite(t.colors.border)||typeof t.colors.border==`bigint`)||t.colors.border>=0&&t.colors.border<=255))&&(typeof t.colors.borderAccent==`string`||Number.isInteger(t.colors.borderAccent)&&(!(Number.isFinite(t.colors.borderAccent)||typeof t.colors.borderAccent==`bigint`)||t.colors.borderAccent>=0&&t.colors.borderAccent<=255))&&(typeof t.colors.borderMuted==`string`||Number.isInteger(t.colors.borderMuted)&&(!(Number.isFinite(t.colors.borderMuted)||typeof t.colors.borderMuted==`bigint`)||t.colors.borderMuted>=0&&t.colors.borderMuted<=255))&&(typeof t.colors.success==`string`||Number.isInteger(t.colors.success)&&(!(Number.isFinite(t.colors.success)||typeof t.colors.success==`bigint`)||t.colors.success>=0&&t.colors.success<=255))&&(typeof t.colors.error==`string`||Number.isInteger(t.colors.error)&&(!(Number.isFinite(t.colors.error)||typeof t.colors.error==`bigint`)||t.colors.error>=0&&t.colors.error<=255))&&(typeof t.colors.warning==`string`||Number.isInteger(t.colors.warning)&&(!(Number.isFinite(t.colors.warning)||typeof t.colors.warning==`bigint`)||t.colors.warning>=0&&t.colors.warning<=255))&&(typeof t.colors.muted==`string`||Number.isInteger(t.colors.muted)&&(!(Number.isFinite(t.colors.muted)||typeof t.colors.muted==`bigint`)||t.colors.muted>=0&&t.colors.muted<=255))&&(typeof t.colors.dim==`string`||Number.isInteger(t.colors.dim)&&(!(Number.isFinite(t.colors.dim)||typeof t.colors.dim==`bigint`)||t.colors.dim>=0&&t.colors.dim<=255))&&(typeof t.colors.text==`string`||Number.isInteger(t.colors.text)&&(!(Number.isFinite(t.colors.text)||typeof t.colors.text==`bigint`)||t.colors.text>=0&&t.colors.text<=255))&&(typeof t.colors.thinkingText==`string`||Number.isInteger(t.colors.thinkingText)&&(!(Number.isFinite(t.colors.thinkingText)||typeof t.colors.thinkingText==`bigint`)||t.colors.thinkingText>=0&&t.colors.thinkingText<=255))&&(typeof t.colors.selectedBg==`string`||Number.isInteger(t.colors.selectedBg)&&(!(Number.isFinite(t.colors.selectedBg)||typeof t.colors.selectedBg==`bigint`)||t.colors.selectedBg>=0&&t.colors.selectedBg<=255))&&(typeof t.colors.userMessageBg==`string`||Number.isInteger(t.colors.userMessageBg)&&(!(Number.isFinite(t.colors.userMessageBg)||typeof t.colors.userMessageBg==`bigint`)||t.colors.userMessageBg>=0&&t.colors.userMessageBg<=255))&&(typeof t.colors.userMessageText==`string`||Number.isInteger(t.colors.userMessageText)&&(!(Number.isFinite(t.colors.userMessageText)||typeof t.colors.userMessageText==`bigint`)||t.colors.userMessageText>=0&&t.colors.userMessageText<=255))&&(typeof t.colors.customMessageBg==`string`||Number.isInteger(t.colors.customMessageBg)&&(!(Number.isFinite(t.colors.customMessageBg)||typeof t.colors.customMessageBg==`bigint`)||t.colors.customMessageBg>=0&&t.colors.customMessageBg<=255))&&(typeof t.colors.customMessageText==`string`||Number.isInteger(t.colors.customMessageText)&&(!(Number.isFinite(t.colors.customMessageText)||typeof t.colors.customMessageText==`bigint`)||t.colors.customMessageText>=0&&t.colors.customMessageText<=255))&&(typeof t.colors.customMessageLabel==`string`||Number.isInteger(t.colors.customMessageLabel)&&(!(Number.isFinite(t.colors.customMessageLabel)||typeof t.colors.customMessageLabel==`bigint`)||t.colors.customMessageLabel>=0&&t.colors.customMessageLabel<=255))&&(typeof t.colors.toolPendingBg==`string`||Number.isInteger(t.colors.toolPendingBg)&&(!(Number.isFinite(t.colors.toolPendingBg)||typeof t.colors.toolPendingBg==`bigint`)||t.colors.toolPendingBg>=0&&t.colors.toolPendingBg<=255))&&(typeof t.colors.toolSuccessBg==`string`||Number.isInteger(t.colors.toolSuccessBg)&&(!(Number.isFinite(t.colors.toolSuccessBg)||typeof t.colors.toolSuccessBg==`bigint`)||t.colors.toolSuccessBg>=0&&t.colors.toolSuccessBg<=255))&&(typeof t.colors.toolErrorBg==`string`||Number.isInteger(t.colors.toolErrorBg)&&(!(Number.isFinite(t.colors.toolErrorBg)||typeof t.colors.toolErrorBg==`bigint`)||t.colors.toolErrorBg>=0&&t.colors.toolErrorBg<=255))&&(typeof t.colors.toolTitle==`string`||Number.isInteger(t.colors.toolTitle)&&(!(Number.isFinite(t.colors.toolTitle)||typeof t.colors.toolTitle==`bigint`)||t.colors.toolTitle>=0&&t.colors.toolTitle<=255))&&(typeof t.colors.toolOutput==`string`||Number.isInteger(t.colors.toolOutput)&&(!(Number.isFinite(t.colors.toolOutput)||typeof t.colors.toolOutput==`bigint`)||t.colors.toolOutput>=0&&t.colors.toolOutput<=255))&&(typeof t.colors.mdHeading==`string`||Number.isInteger(t.colors.mdHeading)&&(!(Number.isFinite(t.colors.mdHeading)||typeof t.colors.mdHeading==`bigint`)||t.colors.mdHeading>=0&&t.colors.mdHeading<=255))&&(typeof t.colors.mdLink==`string`||Number.isInteger(t.colors.mdLink)&&(!(Number.isFinite(t.colors.mdLink)||typeof t.colors.mdLink==`bigint`)||t.colors.mdLink>=0&&t.colors.mdLink<=255))&&(typeof t.colors.mdLinkUrl==`string`||Number.isInteger(t.colors.mdLinkUrl)&&(!(Number.isFinite(t.colors.mdLinkUrl)||typeof t.colors.mdLinkUrl==`bigint`)||t.colors.mdLinkUrl>=0&&t.colors.mdLinkUrl<=255))&&(typeof t.colors.mdCode==`string`||Number.isInteger(t.colors.mdCode)&&(!(Number.isFinite(t.colors.mdCode)||typeof t.colors.mdCode==`bigint`)||t.colors.mdCode>=0&&t.colors.mdCode<=255))&&(typeof t.colors.mdCodeBlock==`string`||Number.isInteger(t.colors.mdCodeBlock)&&(!(Number.isFinite(t.colors.mdCodeBlock)||typeof t.colors.mdCodeBlock==`bigint`)||t.colors.mdCodeBlock>=0&&t.colors.mdCodeBlock<=255))&&(typeof t.colors.mdCodeBlockBorder==`string`||Number.isInteger(t.colors.mdCodeBlockBorder)&&(!(Number.isFinite(t.colors.mdCodeBlockBorder)||typeof t.colors.mdCodeBlockBorder==`bigint`)||t.colors.mdCodeBlockBorder>=0&&t.colors.mdCodeBlockBorder<=255))&&(typeof t.colors.mdQuote==`string`||Number.isInteger(t.colors.mdQuote)&&(!(Number.isFinite(t.colors.mdQuote)||typeof t.colors.mdQuote==`bigint`)||t.colors.mdQuote>=0&&t.colors.mdQuote<=255))&&(typeof t.colors.mdQuoteBorder==`string`||Number.isInteger(t.colors.mdQuoteBorder)&&(!(Number.isFinite(t.colors.mdQuoteBorder)||typeof t.colors.mdQuoteBorder==`bigint`)||t.colors.mdQuoteBorder>=0&&t.colors.mdQuoteBorder<=255))&&(typeof t.colors.mdHr==`string`||Number.isInteger(t.colors.mdHr)&&(!(Number.isFinite(t.colors.mdHr)||typeof t.colors.mdHr==`bigint`)||t.colors.mdHr>=0&&t.colors.mdHr<=255))&&(typeof t.colors.mdListBullet==`string`||Number.isInteger(t.colors.mdListBullet)&&(!(Number.isFinite(t.colors.mdListBullet)||typeof t.colors.mdListBullet==`bigint`)||t.colors.mdListBullet>=0&&t.colors.mdListBullet<=255))&&(typeof t.colors.toolDiffAdded==`string`||Number.isInteger(t.colors.toolDiffAdded)&&(!(Number.isFinite(t.colors.toolDiffAdded)||typeof t.colors.toolDiffAdded==`bigint`)||t.colors.toolDiffAdded>=0&&t.colors.toolDiffAdded<=255))&&(typeof t.colors.toolDiffRemoved==`string`||Number.isInteger(t.colors.toolDiffRemoved)&&(!(Number.isFinite(t.colors.toolDiffRemoved)||typeof t.colors.toolDiffRemoved==`bigint`)||t.colors.toolDiffRemoved>=0&&t.colors.toolDiffRemoved<=255))&&(typeof t.colors.toolDiffContext==`string`||Number.isInteger(t.colors.toolDiffContext)&&(!(Number.isFinite(t.colors.toolDiffContext)||typeof t.colors.toolDiffContext==`bigint`)||t.colors.toolDiffContext>=0&&t.colors.toolDiffContext<=255))&&(typeof t.colors.syntaxComment==`string`||Number.isInteger(t.colors.syntaxComment)&&(!(Number.isFinite(t.colors.syntaxComment)||typeof t.colors.syntaxComment==`bigint`)||t.colors.syntaxComment>=0&&t.colors.syntaxComment<=255))&&(typeof t.colors.syntaxKeyword==`string`||Number.isInteger(t.colors.syntaxKeyword)&&(!(Number.isFinite(t.colors.syntaxKeyword)||typeof t.colors.syntaxKeyword==`bigint`)||t.colors.syntaxKeyword>=0&&t.colors.syntaxKeyword<=255))&&(typeof t.colors.syntaxFunction==`string`||Number.isInteger(t.colors.syntaxFunction)&&(!(Number.isFinite(t.colors.syntaxFunction)||typeof t.colors.syntaxFunction==`bigint`)||t.colors.syntaxFunction>=0&&t.colors.syntaxFunction<=255))&&(typeof t.colors.syntaxVariable==`string`||Number.isInteger(t.colors.syntaxVariable)&&(!(Number.isFinite(t.colors.syntaxVariable)||typeof t.colors.syntaxVariable==`bigint`)||t.colors.syntaxVariable>=0&&t.colors.syntaxVariable<=255))&&(typeof t.colors.syntaxString==`string`||Number.isInteger(t.colors.syntaxString)&&(!(Number.isFinite(t.colors.syntaxString)||typeof t.colors.syntaxString==`bigint`)||t.colors.syntaxString>=0&&t.colors.syntaxString<=255))&&(typeof t.colors.syntaxNumber==`string`||Number.isInteger(t.colors.syntaxNumber)&&(!(Number.isFinite(t.colors.syntaxNumber)||typeof t.colors.syntaxNumber==`bigint`)||t.colors.syntaxNumber>=0&&t.colors.syntaxNumber<=255))&&(typeof t.colors.syntaxType==`string`||Number.isInteger(t.colors.syntaxType)&&(!(Number.isFinite(t.colors.syntaxType)||typeof t.colors.syntaxType==`bigint`)||t.colors.syntaxType>=0&&t.colors.syntaxType<=255))&&(typeof t.colors.syntaxOperator==`string`||Number.isInteger(t.colors.syntaxOperator)&&(!(Number.isFinite(t.colors.syntaxOperator)||typeof t.colors.syntaxOperator==`bigint`)||t.colors.syntaxOperator>=0&&t.colors.syntaxOperator<=255))&&(typeof t.colors.syntaxPunctuation==`string`||Number.isInteger(t.colors.syntaxPunctuation)&&(!(Number.isFinite(t.colors.syntaxPunctuation)||typeof t.colors.syntaxPunctuation==`bigint`)||t.colors.syntaxPunctuation>=0&&t.colors.syntaxPunctuation<=255))&&(typeof t.colors.thinkingOff==`string`||Number.isInteger(t.colors.thinkingOff)&&(!(Number.isFinite(t.colors.thinkingOff)||typeof t.colors.thinkingOff==`bigint`)||t.colors.thinkingOff>=0&&t.colors.thinkingOff<=255))&&(typeof t.colors.thinkingMinimal==`string`||Number.isInteger(t.colors.thinkingMinimal)&&(!(Number.isFinite(t.colors.thinkingMinimal)||typeof t.colors.thinkingMinimal==`bigint`)||t.colors.thinkingMinimal>=0&&t.colors.thinkingMinimal<=255))&&(typeof t.colors.thinkingLow==`string`||Number.isInteger(t.colors.thinkingLow)&&(!(Number.isFinite(t.colors.thinkingLow)||typeof t.colors.thinkingLow==`bigint`)||t.colors.thinkingLow>=0&&t.colors.thinkingLow<=255))&&(typeof t.colors.thinkingMedium==`string`||Number.isInteger(t.colors.thinkingMedium)&&(!(Number.isFinite(t.colors.thinkingMedium)||typeof t.colors.thinkingMedium==`bigint`)||t.colors.thinkingMedium>=0&&t.colors.thinkingMedium<=255))&&(typeof t.colors.thinkingHigh==`string`||Number.isInteger(t.colors.thinkingHigh)&&(!(Number.isFinite(t.colors.thinkingHigh)||typeof t.colors.thinkingHigh==`bigint`)||t.colors.thinkingHigh>=0&&t.colors.thinkingHigh<=255))&&(typeof t.colors.thinkingXhigh==`string`||Number.isInteger(t.colors.thinkingXhigh)&&(!(Number.isFinite(t.colors.thinkingXhigh)||typeof t.colors.thinkingXhigh==`bigint`)||t.colors.thinkingXhigh>=0&&t.colors.thinkingXhigh<=255))&&(typeof t.colors.bashMode==`string`||Number.isInteger(t.colors.bashMode)&&(!(Number.isFinite(t.colors.bashMode)||typeof t.colors.bashMode==`bigint`)||t.colors.bashMode>=0&&t.colors.bashMode<=255))&&(t.export===void 0||!(`export`in t)||typeof t.export==`object`&&t.export!==null&&!Array.isArray(t.export)&&(t.export.pageBg===void 0||!(`pageBg`in t.export)||typeof t.export.pageBg==`string`||Number.isInteger(t.export.pageBg)&&(!(Number.isFinite(t.export.pageBg)||typeof t.export.pageBg==`bigint`)||t.export.pageBg>=0&&t.export.pageBg<=255))&&(t.export.cardBg===void 0||!(`cardBg`in t.export)||typeof t.export.cardBg==`string`||Number.isInteger(t.export.cardBg)&&(!(Number.isFinite(t.export.cardBg)||typeof t.export.cardBg==`bigint`)||t.export.cardBg>=0&&t.export.cardBg<=255))&&(t.export.infoBg===void 0||!(`infoBg`in t.export)||typeof t.export.infoBg==`string`||Number.isInteger(t.export.infoBg)&&(!(Number.isFinite(t.export.infoBg)||typeof t.export.infoBg==`bigint`)||t.export.infoBg>=0&&t.export.infoBg<=255)));return e=>check_0(e)})();
//!src/agents/modes/interactive/theme/theme.ts
const BACKGROUND_COLOR_KEYS=[`selectedBg`,`userMessageBg`,`customMessageBg`,`toolPendingBg`,`toolSuccessBg`,`toolErrorBg`];const THINKING_BORDER_COLORS=/* @__PURE__ */ new Map([[`minimal`,`thinkingMinimal`],[`low`,`thinkingLow`],[`medium`,`thinkingMedium`],[`high`,`thinkingHigh`],[`xhigh`,`thinkingXhigh`]]);function hexToRgb(e){const t=e.replace(`#`,``);if(t.length!==6)throw new Error(`Invalid hex color: ${e}`);const n=Number.parseInt(t.slice(0,2),16);const r=Number.parseInt(t.slice(2,4),16);const i=Number.parseInt(t.slice(4,6),16);if(Number.isNaN(n)||Number.isNaN(r)||Number.isNaN(i))throw new Error(`Invalid hex color: ${e}`);return{r:n,g:r,b:i}}const CUBE_VALUES=[0,95,135,175,215,255];const GRAY_VALUES=Array.from({length:24},(e,t)=>8+t*10);function findClosestPaletteIndex(e,t){let n=Infinity;let r=0;for(const[i,a]of t.entries()){const t=Math.abs(e-a);if(t<n){n=t;r=i}}return r}function colorDistance(e,t,n,r,i,a){const o=e-r;const s=t-i;const c=n-a;return o*o*.299+s*s*.587+c*c*.114}function rgbTo256(e,t,n){const r=findClosestPaletteIndex(e,CUBE_VALUES);const i=findClosestPaletteIndex(t,CUBE_VALUES);const a=findClosestPaletteIndex(n,CUBE_VALUES);const o=CUBE_VALUES[r];const s=CUBE_VALUES[i];const c=CUBE_VALUES[a];if(o===void 0||s===void 0||c===void 0)throw new Error(`Invalid 256-color cube index`);const l=16+36*r+6*i+a;const u=colorDistance(e,t,n,o,s,c);const d=findClosestPaletteIndex(Math.round(.299*e+.587*t+.114*n),GRAY_VALUES);const f=GRAY_VALUES[d];if(f===void 0)throw new Error(`Invalid 256-color grayscale index`);const p=232+d;const m=colorDistance(e,t,n,f,f,f);if(Math.max(e,t,n)-Math.min(e,t,n)<10&&m<u)return p;return l}function colorAnsi(e,t,n){const r=n===`fg`?38:48;if(e===``)return n===`fg`?`\x1B[39m`:`\x1B[49m`;if(typeof e===`number`)return`\x1b[${r};5;${e}m`;if(e.startsWith(`#`)){const{r:n,g:i,b:a}=hexToRgb(e);return t===`truecolor`?`\x1b[${r};2;${n};${i};${a}m`:`\x1b[${r};5;${rgbTo256(n,i,a)}m`}throw new Error(`Invalid color value: ${e}`)}function resolveVarRefs(e,t,n=/* @__PURE__ */ new Set){if(typeof e===`number`||e===``||e.startsWith(`#`))return e;if(n.has(e))throw new Error(`Circular variable reference detected: ${e}`);n.add(e);const r=t[e];if(r===void 0)throw new Error(`Variable reference not found: ${e}`);return resolveVarRefs(r,t,n)}function resolveThemeColors(e,t={}){const n={};for(const[r,i]of Object.entries(e))n[r]=resolveVarRefs(i,t);return n}function getThemeAnsi(e,t,n){const r=e.get(t);if(!r)throw new Error(`Unknown theme ${n}: ${t}`);return r}var Theme=class{constructor(e,t,n,r={}){this.name=r.name;this.sourcePath=r.sourcePath;this.sourceInfo=r.sourceInfo;this.mode=n;this.fgColors=/* @__PURE__ */ new Map;for(const[t,r]of Object.entries(e))this.fgColors.set(t,colorAnsi(r,n,`fg`));this.bgColors=/* @__PURE__ */ new Map;for(const[e,r]of Object.entries(t))this.bgColors.set(e,colorAnsi(r,n,`bg`))}fg(e,t){return`${getThemeAnsi(this.fgColors,e,`color`)}${t}\x1b[39m`}bg(e,t){return`${getThemeAnsi(this.bgColors,e,`background color`)}${t}\x1b[49m`}bold(e){return chalk.bold(e)}italic(e){return chalk.italic(e)}underline(e){return chalk.underline(e)}inverse(e){return chalk.inverse(e)}strikethrough(e){return chalk.strikethrough(e)}getFgAnsi(e){return getThemeAnsi(this.fgColors,e,`color`)}getBgAnsi(e){return getThemeAnsi(this.bgColors,e,`background color`)}getColorMode(){return this.mode}getThinkingBorderColor(e){const t=THINKING_BORDER_COLORS.get(e)??`thinkingOff`;return e=>this.fg(t,e)}getBashModeBorderColor(){return e=>this.fg(`bashMode`,e)}};function parseThemeJson(e,t){if(!isThemeJson(t)){const n=Errors(ThemeJsonSchema,t)[1];const r=/* @__PURE__ */ new Set;const i=[];for(const e of n){if(e.keyword===`required`&&e.instancePath===`/colors`){for(const t of e.params.requiredProperties)r.add(t);continue}const t=e.instancePath||`/`;i.push(` - ${t}: ${e.message}`)}let a=`Invalid theme "${e}":\n`;if(r.size>0){a+=`
Missing required color tokens:
`;a+=Array.from(r).toSorted().map(e=>` - ${e}`).join(`
`);a+=`
Please add these colors to your theme's "colors" object.`;a+=`
See the built-in themes (dark.json, light.json) for reference values.`}if(i.length>0)a+=`\n\nOther errors:\n${i.join(`
`)}`;throw new Error(a)}return t}function parseThemeJsonContent(e,t){let n;try{n=JSON.parse(t)}catch(t){const n=t instanceof Error?t.message:String(t);throw new Error(`Failed to parse theme ${e}: ${n}`,{cause:t})}return parseThemeJson(e,n)}function createTheme(e,t,n){const r=t??(loadTuiRuntime().getCapabilities().trueColor?`truecolor`:`256color`);const i=resolveThemeColors(e.colors,e.vars);const a={};const o={};const s=new Set(BACKGROUND_COLOR_KEYS);for(const[e,t]of Object.entries(i))if(s.has(e))o[e]=t;else a[e]=t;return new Theme(a,o,r,{name:e.name,sourcePath:n})}function loadThemeFromPath(e,t){return createTheme(parseThemeJsonContent(e,fs$1.readFileSync(e,`utf-8`)),t,e)}const THEME_KEY=Symbol.for(`openclaw:agent-theme`);const interactiveAgentTheme=new Proxy({},{get(e,t){const n=globalThis[THEME_KEY];if(!n)throw new Error(`Theme not initialized. Call setTheme() first.`);return n[t]}});const cliHighlightTheme={keyword:e=>interactiveAgentTheme.fg(`syntaxKeyword`,e),built_in:e=>interactiveAgentTheme.fg(`syntaxType`,e),literal:e=>interactiveAgentTheme.fg(`syntaxNumber`,e),number:e=>interactiveAgentTheme.fg(`syntaxNumber`,e),string:e=>interactiveAgentTheme.fg(`syntaxString`,e),comment:e=>interactiveAgentTheme.fg(`syntaxComment`,e),function:e=>interactiveAgentTheme.fg(`syntaxFunction`,e),title:e=>interactiveAgentTheme.fg(`syntaxFunction`,e),class:e=>interactiveAgentTheme.fg(`syntaxType`,e),type:e=>interactiveAgentTheme.fg(`syntaxType`,e),attr:e=>interactiveAgentTheme.fg(`syntaxVariable`,e),variable:e=>interactiveAgentTheme.fg(`syntaxVariable`,e),params:e=>interactiveAgentTheme.fg(`syntaxVariable`,e),operator:e=>interactiveAgentTheme.fg(`syntaxOperator`,e),punctuation:e=>interactiveAgentTheme.fg(`syntaxPunctuation`,e)};function highlightCode(e,t){const n=t&&supportsLanguage(t)?t:void 0;if(!n)return e.split(`
`).map(e=>interactiveAgentTheme.fg(`mdCodeBlock`,e));try{return highlight(e,n,cliHighlightTheme).split(`
`)}catch{return e.split(`
`)}}const EXTENSION_LANGUAGES=Object.fromEntries(Object.entries({typescript:[`ts`,`tsx`],javascript:[`js`,`jsx`,`mjs`,`cjs`],python:[`py`],ruby:[`rb`],rust:[`rs`],go:[`go`],java:[`java`],kotlin:[`kt`],swift:[`swift`],c:[`c`,`h`],cpp:[`cpp`,`cc`,`cxx`,`hpp`],csharp:[`cs`],php:[`php`],bash:[`sh`,`bash`,`zsh`],fish:[`fish`],powershell:[`ps1`],sql:[`sql`],html:[`html`,`htm`],css:[`css`],scss:[`scss`],sass:[`sass`],less:[`less`],json:[`json`],yaml:[`yaml`,`yml`],toml:[`toml`],xml:[`xml`],markdown:[`md`,`markdown`],dockerfile:[`dockerfile`],makefile:[`makefile`],cmake:[`cmake`],lua:[`lua`],perl:[`perl`],r:[`r`],scala:[`scala`],clojure:[`clj`],elixir:[`ex`,`exs`],erlang:[`erl`],haskell:[`hs`],ocaml:[`ml`],vim:[`vim`],graphql:[`graphql`],protobuf:[`proto`],hcl:[`tf`,`hcl`]}).flatMap(([e,t])=>t.map(t=>[t,e])));function getLanguageFromPath(e){const t=e.split(`.`).pop()?.toLowerCase();return t?EXTENSION_LANGUAGES[t]:void 0}
//!src/agents/sessions/tools/tool-definition-wrapper.ts
function toolDefinitionMetadata(e){return{name:e.name,label:e.label,...e.hideFromChannelProgress===true?{hideFromChannelProgress:true}:{},...e.resultContentSource?{resultContentSource:e.resultContentSource}:{},description:e.description,parameters:e.parameters,...e.outputSchema?{outputSchema:e.outputSchema}:{},prepareArguments:e.prepareArguments,executionMode:e.executionMode,interruptible:e.interruptible,repeatable:e.repeatable,...e.async===false?{async:false}:{}}}function wrapToolDefinition(e,t){const n={...toolDefinitionMetadata(e),execute:(n,r,i,a)=>e.execute(n,r,i,a,t?.())};copyCodeModeControlToolIdentity(e,n);copyAgentToolReplaySafety(e,n);return copyInternalToolExecutionPreparer(e,n)}function createToolDefinitionFromAgentTool(e){const t={...toolDefinitionMetadata(e),execute:async(t,n,r,i)=>e.execute(t,n,r,i)};copyCodeModeControlToolIdentity(e,t);copyAgentToolReplaySafety(e,t);return copyInternalToolExecutionPreparer(e,t)}
//!src/shared/ignore-rules.ts
const IGNORE_FILE_NAMES=[`.gitignore`,`.ignore`,`.fdignore`];const IGNORE_FILE_MAX_BYTES=4194304;const IGNORE_MATCHER_MAX_PATTERNS=2e4;const IGNORE_PATTERN_MAX_CHARS=16384;const IGNORE_MATCHER_MAX_PATTERN_CHARS=IGNORE_FILE_MAX_BYTES;const OVERSIZED_IGNORE_FILE=Symbol(`oversizedIgnoreFile`);const COMPLEX_IGNORE_FILE=Symbol(`complexIgnoreFile`);const ignoreMatcherStates=/* @__PURE__ */ new WeakMap;function normalizeLiteralSubtreePath(e){const t=normalizeNativePathSeparators(e);return t.endsWith(`/`)?t.slice(0,-1):t}function getIgnoreMatcherState(e){if(e){const t=ignoreMatcherStates.get(e);if(!t)throw new Error(`addIgnoreRules requires a matcher returned by addIgnoreRules`);return t}const t=ignore();const n={matcher:t,excludedSubtrees:/* @__PURE__ */ new Set,patternCount:0,patternChars:0};ignoreMatcherStates.set(t,n);const r=t.ignores.bind(t);t.ignores=e=>{const t=r(e);const i=normalizeLiteralSubtreePath(e).toLowerCase();for(const e of n.excludedSubtrees)if(!e||i===e||i.startsWith(`${e}/`))return true;return t};return n}function addFailClosedSubtree(e,t){const n=normalizeLiteralSubtreePath(t).toLowerCase();e.excludedSubtrees.add(n)}function parseIgnorePatterns(e,t,n){const r=[];let i=0;let a=e.startsWith(``)?1:0;while(a<=e.length){const o=e.indexOf(`
`,a);const s=o===-1?e.length:o;const c=s>a&&e[s-1]===`\r`?s-1:s;const l=prefixIgnorePattern(e.slice(a,c),t);if(l){if(l.length>IGNORE_PATTERN_MAX_CHARS||r.length>=n.patterns)return COMPLEX_IGNORE_FILE;i+=l.length;if(i>n.chars)return COMPLEX_IGNORE_FILE;r.push(l)}if(o===-1)break;a=o+1}return{patterns:r,chars:i}}const normalizeNativePathSeparators=e=>e.split(sep).join(`/`);function addIgnoreRules(e,t,n){const r=getIgnoreMatcherState(n);const i=r.matcher;const a=relative(t,e);const o=a?`${normalizeNativePathSeparators(a)}/`:``;for(const t of IGNORE_FILE_NAMES){const n=join(e,t);if(!lstatSync(n,{throwIfNoEntry:false}))continue;const a=readIgnoreFileContent(n);if(a===OVERSIZED_IGNORE_FILE){addFailClosedSubtree(r,o);break}const s=parseIgnorePatterns(a,o,{patterns:IGNORE_MATCHER_MAX_PATTERNS-r.patternCount,chars:IGNORE_MATCHER_MAX_PATTERN_CHARS-r.patternChars});if(s===COMPLEX_IGNORE_FILE){addFailClosedSubtree(r,o);break}if(s.patterns.length>0){i.add(s.patterns);r.patternCount+=s.patterns.length;r.patternChars+=s.chars}}return i}function readIgnoreFileContent(e){const t=realpathSync(e);try{const{buffer:e}=readRegularFileSync({filePath:t,maxBytes:IGNORE_FILE_MAX_BYTES});return e.toString(`utf-8`)}catch(e){if(hasNodeErrorCode(e,`too-large`))return OVERSIZED_IGNORE_FILE;throw e}}function prefixIgnorePattern(e,t){if(!e.trim()||e.startsWith(`#`))return``;const n=e.startsWith(`!`);const r=n?e.slice(1):e;const i=r.startsWith(`/`);const a=i?r.slice(1):r;const o=a.replace(/ +$/,``);const s=t&&!i&&!o.slice(0,-1).includes(`/`)?`**/`:``;const c=t.replace(/[\\*?[\]#!]/g,`\\$&`);return(n?`!`:``)+(t?`${c}${s}${a}`:r)}export{getLanguageFromPath as a,loadThemeFromPath as c,wrapToolDefinition as i,loadTuiRuntime as l,normalizeNativePathSeparators as n,highlightCode as o,createToolDefinitionFromAgentTool as r,interactiveAgentTheme as s,addIgnoreRules as t};