avoid garbled Chinese when call runTerminalCommandTool in windows
This commit is contained in:
parent
82e3b02f34
commit
a000397160
2 changed files with 20 additions and 2 deletions
|
|
@ -78,6 +78,7 @@
|
|||
"handlebars": "^4.7.8",
|
||||
"http-proxy-agent": "^7.0.1",
|
||||
"https-proxy-agent": "^7.0.3",
|
||||
"iconv-lite": "^0.6.3",
|
||||
"ignore": "^5.3.1",
|
||||
"is-localhost-ip": "^2.0.0",
|
||||
"jinja-js": "0.1.8",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,22 @@
|
|||
import iconv from "iconv-lite";
|
||||
import childProcess from "node:child_process";
|
||||
import util from "node:util";
|
||||
// Automatically decode the buffer according to the platform to avoid garbled Chinese
|
||||
function getDecodedOutput(data: Buffer): string {
|
||||
if (process.platform === "win32") {
|
||||
try {
|
||||
let out = iconv.decode(data, "utf-8");
|
||||
if (/<2F>/.test(out)) {
|
||||
out = iconv.decode(data, "gbk");
|
||||
}
|
||||
return out;
|
||||
} catch {
|
||||
return iconv.decode(data, "gbk");
|
||||
}
|
||||
} else {
|
||||
return data.toString();
|
||||
}
|
||||
}
|
||||
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { ToolImpl } from ".";
|
||||
|
|
@ -77,7 +94,7 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => {
|
|||
// Skip if this process has been backgrounded
|
||||
if (isProcessBackgrounded(toolCallId)) return;
|
||||
|
||||
const newOutput = data.toString();
|
||||
const newOutput = getDecodedOutput(data);
|
||||
terminalOutput += newOutput;
|
||||
|
||||
// Send partial output to UI
|
||||
|
|
@ -103,7 +120,7 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => {
|
|||
// Skip if this process has been backgrounded
|
||||
if (isProcessBackgrounded(toolCallId)) return;
|
||||
|
||||
const newOutput = data.toString();
|
||||
const newOutput = getDecodedOutput(data);
|
||||
terminalOutput += newOutput;
|
||||
|
||||
// Send partial output to UI, status is not required
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue