UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 2.18 kB
import{a as resolveCliParentCommandPath,n as isConfigSetJsonParseOnly}from"./config-output-mode-zXCwdxLP.mjs";import{n as loggingState}from"./state-kXlBD9Q4.mjs";import{n as withNoteOutput}from"./note-output-qKC3uvZV.mjs"; //!src/cli/json-output-mode.ts let resolvedJsonOutputMode=null;let stderrRoutingScopes=0;let stderrRoutingAfterScopes=false;function setConsoleRouting(e){if(stderrRoutingScopes>0)stderrRoutingAfterScopes=e;loggingState.forceConsoleToStderr=e||stderrRoutingScopes>0}const noteOutputForConsoleRouting=()=>loggingState.forceConsoleToStderr?process.stderr:process.stdout;function hasJsonOutputFlag(e){for(const t of e){if(t===`--`)return false;if(t===`--json`||t.startsWith(`--json=`))return true}return false}function isJsonOutputModeActive(e){return resolvedJsonOutputMode??(hasJsonOutputFlag(e)&&!(resolveCliParentCommandPath(e,`config`)?.[1]===`set`&&isConfigSetJsonParseOnly(e)))}async function withConsoleLogsRoutedToStderrForJson(e,t,n={}){const r=hasJsonOutputFlag(e)||n.machineOutput;if(!r&&!n.restoreChanges)return withNoteOutput(noteOutputForConsoleRouting,t);const i=stderrRoutingScopes>0?stderrRoutingAfterScopes:loggingState.forceConsoleToStderr;const a=loggingState.earlyConsoleRoutingRestore;const o=resolvedJsonOutputMode;resolvedJsonOutputMode=null;if(r){loggingState.earlyConsoleRoutingRestore=i;setConsoleRouting(true)}try{return await withNoteOutput(noteOutputForConsoleRouting,t)}finally{if(!n.retainRoutingUntilProcessExit){setConsoleRouting(i);loggingState.earlyConsoleRoutingRestore=a;resolvedJsonOutputMode=o}}}function applyResolvedCommandOutputMode(e,t=e){resolvedJsonOutputMode=e;const n=loggingState.earlyConsoleRoutingRestore;if(!t&&n!==null)setConsoleRouting(n)}async function withConsoleLogsRoutedToStderr(e){if(stderrRoutingScopes++===0)stderrRoutingAfterScopes=loggingState.forceConsoleToStderr;loggingState.forceConsoleToStderr=true;try{return await e()}finally{if(--stderrRoutingScopes===0)loggingState.forceConsoleToStderr=stderrRoutingAfterScopes}}export{withConsoleLogsRoutedToStderrForJson as a,withConsoleLogsRoutedToStderr as i,hasJsonOutputFlag as n,isJsonOutputModeActive as r,applyResolvedCommandOutputMode as t};