openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 4.28 kB
JavaScript
import{m as e}from"./fs-safe-copy.worker-number-coercion-1FVMw2ic.mjs";import{n as t}from"./fs-safe-copy.worker-process-env-DgVwfN3Y.mjs";import{t as n}from"./fs-safe-copy.worker-windows-appcontainer-spawn-DPZpihSk.mjs";import{t as r}from"./fs-safe-copy.worker-windows-install-roots-BA2Oy9MH.mjs";import{spawnSync as i}from"node:child_process";const a={65001:`utf-8`,54936:`gb18030`,874:`windows-874`,936:`gbk`,950:`big5`,932:`shift_jis`,949:`euc-kr`,1250:`windows-1250`,1251:`windows-1251`,1252:`windows-1252`,1253:`windows-1253`,1254:`windows-1254`,1255:`windows-1255`,1256:`windows-1256`,1257:`windows-1257`,1258:`windows-1258`};new Map(Object.entries({65001:`utf-8`,874:`windows-874`,932:`shift_jis`,936:`gbk`,949:`euc-kr`,950:`big5`,1258:`windows-1258`,437:`cp437`,720:`cp720`,737:`cp737`,775:`cp775`,850:`cp850`,852:`cp852`,855:`cp855`,857:`cp857`,858:`cp858`,860:`cp860`,861:`cp861`,862:`cp862`,863:`cp863`,865:`cp865`,866:`cp866`,869:`cp869`}).map(([e,t])=>[t,Number.parseInt(e,10)]));let o;function parseWindowsCodePage(e){let t=Number(e.match(/\b(\d{3,5})\b/)?.[1]);return t>0?t:null}function resolveWindowsConsoleEncoding(){return process.platform===`win32`?(o===void 0&&(o=probeWindowsEncoding(r,[`/d`,`/s`,`/c`,`chcp`])),o):null}function probeWindowsEncoding(e,r){n();try{let n=i(e(),r,{env:t(),windowsHide:!0,encoding:`utf8`,killSignal:`SIGKILL`,stdio:[`ignore`,`pipe`,`pipe`],timeout:5e3}),o=parseWindowsCodePage(`${n.stdout??``}\n${n.stderr??``}`);return o===null?null:a[o]??null}catch{return null}}function decodeWindowsOutputBuffer(e){return decodeWindowsBufferWithFallback({...e,resolveFallbackEncoding:()=>e.windowsEncoding??resolveWindowsConsoleEncoding()})}function decodeUtf16BomBuffer(e){let[t,n]=e;return t===255&&n===254||t===254&&n===255?new TextDecoder(t===255?`utf-16le`:`utf-16be`).decode(e):void 0}function decodeWindowsBufferWithFallback(t){if((t.platform??process.platform)!==`win32`)return t.buffer.toString(`utf8`);let n=decodeUtf16BomBuffer(t.buffer);if(n!==void 0)return n;let r=decodeStrictUtf8(t.buffer);if(r!==null)return r;let i=t.resolveFallbackEncoding();if(!i||e(i)===`utf-8`)return t.buffer.toString(`utf8`);try{return new TextDecoder(i).decode(t.buffer)}catch{return t.buffer.toString(`utf8`)}}function createWindowsOutputDecoder(t){let n=t?.platform??process.platform,r=n===`win32`?t?.windowsEncoding??resolveWindowsConsoleEncoding():null,i=e(r),a=n===`win32`&&r&&i!==`utf-8`?new TextDecoder(r):null,o=t?.preserveUtf8Bom===!0,s=new TextDecoder(`utf-8`,a?{fatal:!0,...o?{ignoreBOM:!0}:{}}:o?{ignoreBOM:!0}:void 0),c=Buffer.alloc(0),l=n===`win32`?void 0:null,u=null,decodeCurrent=e=>{let t=e===void 0?void 0:{stream:!0};if(!a||s===a)return s.decode(e,t);try{let n=s.decode(e,t),r=e&&e.length<4&&c.length>0?Buffer.concat([c,e]):e;return c=r?Buffer.from(getTrailingIncompleteUtf8Bytes(r)):Buffer.alloc(0),n}catch{let n=e===void 0?c:c.length>0?Buffer.concat([c,e]):e;return s=a,c=Buffer.alloc(0),e!==void 0||n.length>0?a.decode(n,t):``}};return{decode(e){let t=Buffer.isBuffer(e)?e:Buffer.from(e);if(u)return u.decode(t,{stream:!0});if(l===null||t.length===0)return l===null?decodeCurrent(t):``;let n=l===void 0?t:Buffer.concat([Buffer.from([l]),t]),[r,i]=n;return i===void 0&&(r===255||r===254)?(l=r,``):(l=null,r===255&&i===254||r===254&&i===255?(u=new TextDecoder(r===255?`utf-16le`:`utf-16be`),u.decode(n,{stream:!0})):decodeCurrent(n))},flush(){if(u)return u.decode();let e=typeof l==`number`?Buffer.from([l]):null;return l=null,(e?decodeCurrent(e):``)+decodeCurrent()}}}function getTrailingIncompleteUtf8Bytes(e){let t=e.length-1,n=0;for(;t>=0&&n<3;){let r=e.readUInt8(t);if(r<128||r>191)break;n+=1,--t}if(t<0)return e;let r=getUtf8SequenceLength(e.readUInt8(t));return r<=1?Buffer.alloc(0):n+1<r?e.subarray(t):Buffer.alloc(0)}function getUtf8SequenceLength(e){return e>=194&&e<=223?2:e>=224&&e<=239?3:e>=240&&e<=244?4:1}function decodeStrictUtf8(e){try{return new TextDecoder(`utf-8`,{fatal:!0}).decode(e)}catch{return null}}function setProcessTimeout(e,t){let n,r=setTimeout(()=>{n=setTimeout(e,0)},t);return{clear(){clearTimeout(r),clearTimeout(n)},refresh(){clearTimeout(n),n=void 0,r.refresh()}}}export{resolveWindowsConsoleEncoding as i,createWindowsOutputDecoder as n,decodeWindowsOutputBuffer as r,setProcessTimeout as t};