@bgicli/bgicli 2.2.5 → 2.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bgi.js +61 -31
- package/package.json +1 -1
package/dist/bgi.js
CHANGED
|
@@ -13731,11 +13731,11 @@ var TOOL_DEFINITIONS = [
|
|
|
13731
13731
|
}
|
|
13732
13732
|
}
|
|
13733
13733
|
];
|
|
13734
|
-
function executeTool(name, args) {
|
|
13734
|
+
async function executeTool(name, args) {
|
|
13735
13735
|
try {
|
|
13736
13736
|
switch (name) {
|
|
13737
13737
|
case "bash":
|
|
13738
|
-
return toolBash(
|
|
13738
|
+
return await toolBash(
|
|
13739
13739
|
args["command"],
|
|
13740
13740
|
args["workdir"],
|
|
13741
13741
|
args["timeout_ms"] ?? 3e4
|
|
@@ -13751,7 +13751,7 @@ function executeTool(name, args) {
|
|
|
13751
13751
|
case "list_dir":
|
|
13752
13752
|
return toolListDir(args["path"]);
|
|
13753
13753
|
case "search_files":
|
|
13754
|
-
return toolSearchFiles(
|
|
13754
|
+
return await toolSearchFiles(
|
|
13755
13755
|
args["pattern"],
|
|
13756
13756
|
args["path"] ?? process.cwd()
|
|
13757
13757
|
);
|
|
@@ -13775,23 +13775,45 @@ function decodeBuffer(buf) {
|
|
|
13775
13775
|
}
|
|
13776
13776
|
}
|
|
13777
13777
|
}
|
|
13778
|
-
function toolBash(command, workdir, timeoutMs = 3e4) {
|
|
13779
|
-
|
|
13780
|
-
const
|
|
13778
|
+
async function toolBash(command, workdir, timeoutMs = 3e4) {
|
|
13779
|
+
return new Promise((resolve3) => {
|
|
13780
|
+
const isWin = process.platform === "win32";
|
|
13781
|
+
const child = (0, import_child_process.spawn)(isWin ? "cmd" : "/bin/sh", isWin ? ["/c", command] : ["-c", command], {
|
|
13781
13782
|
cwd: workdir ?? process.cwd(),
|
|
13782
|
-
|
|
13783
|
-
|
|
13784
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
13785
|
-
maxBuffer: 10 * 1024 * 1024,
|
|
13786
|
-
env: { ...process.env, PYTHONIOENCODING: "utf-8" }
|
|
13783
|
+
env: { ...process.env, PYTHONIOENCODING: "utf-8" },
|
|
13784
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
13787
13785
|
});
|
|
13788
|
-
|
|
13789
|
-
|
|
13790
|
-
const
|
|
13791
|
-
|
|
13792
|
-
|
|
13793
|
-
|
|
13794
|
-
|
|
13786
|
+
const outChunks = [];
|
|
13787
|
+
const errChunks = [];
|
|
13788
|
+
const MAX = 10 * 1024 * 1024;
|
|
13789
|
+
let total = 0;
|
|
13790
|
+
child.stdout?.on("data", (c2) => {
|
|
13791
|
+
if ((total += c2.length) <= MAX) outChunks.push(c2);
|
|
13792
|
+
});
|
|
13793
|
+
child.stderr?.on("data", (c2) => {
|
|
13794
|
+
if ((total += c2.length) <= MAX) errChunks.push(c2);
|
|
13795
|
+
});
|
|
13796
|
+
let timedOut = false;
|
|
13797
|
+
const timer = setTimeout(() => {
|
|
13798
|
+
timedOut = true;
|
|
13799
|
+
child.kill();
|
|
13800
|
+
}, timeoutMs);
|
|
13801
|
+
child.on("close", (code) => {
|
|
13802
|
+
clearTimeout(timer);
|
|
13803
|
+
const out = (decodeBuffer(Buffer.concat(outChunks)) + "\n" + decodeBuffer(Buffer.concat(errChunks))).trim();
|
|
13804
|
+
if (timedOut) {
|
|
13805
|
+
resolve3({ output: out, error: `Command timed out after ${timeoutMs / 1e3}s` });
|
|
13806
|
+
} else if (code !== 0) {
|
|
13807
|
+
resolve3({ output: out, error: `Command failed (exit ${code})` });
|
|
13808
|
+
} else {
|
|
13809
|
+
resolve3({ output: out });
|
|
13810
|
+
}
|
|
13811
|
+
});
|
|
13812
|
+
child.on("error", (err) => {
|
|
13813
|
+
clearTimeout(timer);
|
|
13814
|
+
resolve3({ output: "", error: err.message });
|
|
13815
|
+
});
|
|
13816
|
+
});
|
|
13795
13817
|
}
|
|
13796
13818
|
function toolReadFile(path, maxLines, offset) {
|
|
13797
13819
|
const resolved = (0, import_path3.resolve)(path.replace(/^~/, (0, import_os2.homedir)()));
|
|
@@ -13820,16 +13842,10 @@ function toolListDir(path) {
|
|
|
13820
13842
|
});
|
|
13821
13843
|
return { output: entries.join("\n") };
|
|
13822
13844
|
}
|
|
13823
|
-
function toolSearchFiles(pattern, rootPath) {
|
|
13845
|
+
async function toolSearchFiles(pattern, rootPath) {
|
|
13824
13846
|
const resolved = (0, import_path3.resolve)(rootPath.replace(/^~/, (0, import_os2.homedir)()));
|
|
13825
13847
|
const isWin = process.platform === "win32";
|
|
13826
|
-
|
|
13827
|
-
if (isWin) {
|
|
13828
|
-
command = `dir /s /b "${resolved}\\${pattern}" 2>nul`;
|
|
13829
|
-
} else {
|
|
13830
|
-
const name = pattern.includes("/") ? pattern : `"${pattern}"`;
|
|
13831
|
-
command = `find "${resolved}" -name ${name} 2>/dev/null | head -50`;
|
|
13832
|
-
}
|
|
13848
|
+
const command = isWin ? `dir /s /b "${resolved}\\${pattern}" 2>nul` : `find "${resolved}" -name ${pattern.includes("/") ? pattern : `"${pattern}"`} 2>/dev/null | head -50`;
|
|
13833
13849
|
return toolBash(command, resolved, 1e4);
|
|
13834
13850
|
}
|
|
13835
13851
|
|
|
@@ -13869,12 +13885,26 @@ async function streamLoop(client, messages, model) {
|
|
|
13869
13885
|
function: { name: tc.name, arguments: tc.args }
|
|
13870
13886
|
}))
|
|
13871
13887
|
});
|
|
13888
|
+
const SPIN_FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
13872
13889
|
for (const tc of toolCalls) {
|
|
13873
13890
|
const args = parseArgs(tc.args);
|
|
13874
|
-
|
|
13875
|
-
|
|
13876
|
-
|
|
13877
|
-
|
|
13891
|
+
const label = source_default.dim(`[\u5DE5\u5177: ${tc.name}(${summarizeArgs(args)})]`);
|
|
13892
|
+
const t0 = Date.now();
|
|
13893
|
+
let frame = 0;
|
|
13894
|
+
process.stdout.write(`
|
|
13895
|
+
${label} `);
|
|
13896
|
+
const spin = setInterval(() => {
|
|
13897
|
+
const secs = ((Date.now() - t0) / 1e3).toFixed(1);
|
|
13898
|
+
process.stdout.write(
|
|
13899
|
+
`\r${label} ${source_default.cyan(SPIN_FRAMES[frame++ % SPIN_FRAMES.length])} ${source_default.dim(secs + "s")}`
|
|
13900
|
+
);
|
|
13901
|
+
}, 80);
|
|
13902
|
+
const result = await executeTool(tc.name, args);
|
|
13903
|
+
clearInterval(spin);
|
|
13904
|
+
const elapsed = ((Date.now() - t0) / 1e3).toFixed(1);
|
|
13905
|
+
const doneIcon = result.error ? source_default.yellow("\u2717") : source_default.green("\u2713");
|
|
13906
|
+
process.stdout.write(`\r\x1B[2K${label} ${doneIcon} ${source_default.dim(elapsed + "s")}
|
|
13907
|
+
`);
|
|
13878
13908
|
if (result.error) {
|
|
13879
13909
|
process.stdout.write(source_default.yellow(` \u26A0 ${result.error}
|
|
13880
13910
|
`));
|
|
@@ -14726,7 +14756,7 @@ function routeSkill(message) {
|
|
|
14726
14756
|
}
|
|
14727
14757
|
|
|
14728
14758
|
// src/index.ts
|
|
14729
|
-
var VERSION2 = "2.2.
|
|
14759
|
+
var VERSION2 = "2.2.7";
|
|
14730
14760
|
function installBundledData() {
|
|
14731
14761
|
const bundledData = (0, import_path4.join)(__dirname, "..", "data");
|
|
14732
14762
|
if (!(0, import_fs4.existsSync)(bundledData)) return;
|