@bgicli/bgicli 2.3.8 → 2.4.0

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.
Files changed (2) hide show
  1. package/dist/bgi.js +32 -12
  2. package/package.json +1 -1
package/dist/bgi.js CHANGED
@@ -13956,7 +13956,7 @@ var TOOL_DEFINITIONS = [
13956
13956
  }
13957
13957
  }
13958
13958
  ];
13959
- async function executeTool(name, args, onStream) {
13959
+ async function executeTool(name, args, onStream, signal) {
13960
13960
  try {
13961
13961
  switch (name) {
13962
13962
  case "bash": {
@@ -13964,9 +13964,9 @@ async function executeTool(name, args, onStream) {
13964
13964
  const requestedTimeout = args["timeout_ms"] ?? 3e5;
13965
13965
  const isDownload = /\b(wget|curl|aria2c|axel|rsync)\b/.test(cmd);
13966
13966
  if (isDownload) {
13967
- return await toolBash(cmd, args["workdir"], 0, onStream, 6e5);
13967
+ return await toolBash(cmd, args["workdir"], 0, onStream, 6e5, signal);
13968
13968
  }
13969
- return await toolBash(cmd, args["workdir"], requestedTimeout, onStream);
13969
+ return await toolBash(cmd, args["workdir"], requestedTimeout, onStream, void 0, signal);
13970
13970
  }
13971
13971
  case "read_file":
13972
13972
  return toolReadFile(
@@ -14017,7 +14017,7 @@ function injectProgressFlags(cmd) {
14017
14017
  }
14018
14018
  return cmd;
14019
14019
  }
14020
- async function toolBash(command, workdir, timeoutMs = 3e5, onStream, inactivityMs) {
14020
+ async function toolBash(command, workdir, timeoutMs = 3e5, onStream, inactivityMs, signal) {
14021
14021
  const scan = scanCommand(command);
14022
14022
  const criticals = scan.matches.filter((m2) => m2.pattern.level === "CRITICAL");
14023
14023
  if (criticals.length > 0) {
@@ -14067,6 +14067,17 @@ async function toolBash(command, workdir, timeoutMs = 3e5, onStream, inactivityM
14067
14067
  });
14068
14068
  let timedOut = false;
14069
14069
  let timedOutSecs = 0;
14070
+ let aborted = false;
14071
+ if (signal) {
14072
+ if (signal.aborted) {
14073
+ child.kill();
14074
+ return resolve4({ output: "", error: "\u4EFB\u52A1\u5DF2\u4E2D\u65AD" });
14075
+ }
14076
+ signal.addEventListener("abort", () => {
14077
+ aborted = true;
14078
+ child.kill();
14079
+ }, { once: true });
14080
+ }
14070
14081
  const effectiveMs = inactivityMs ?? timeoutMs;
14071
14082
  let timer = setTimeout(() => {
14072
14083
  timedOut = true;
@@ -14088,7 +14099,9 @@ async function toolBash(command, workdir, timeoutMs = 3e5, onStream, inactivityM
14088
14099
  child.on("close", (code) => {
14089
14100
  clearTimeout(timer);
14090
14101
  const out = (decodeBuffer(Buffer.concat(outChunks)) + "\n" + decodeBuffer(Buffer.concat(errChunks))).trim();
14091
- if (timedOut) {
14102
+ if (aborted) {
14103
+ resolve4({ output: out, error: "\u4EFB\u52A1\u5DF2\u4E2D\u65AD" });
14104
+ } else if (timedOut) {
14092
14105
  const msg = inactivityMs ? `\u4E0B\u8F7D\u505C\u6EDE \u2014 \u8D85\u8FC7 ${timedOutSecs}s \u65E0\u4EFB\u4F55\u8F93\u51FA\uFF08\u8FDE\u63A5\u53EF\u80FD\u5DF2\u65AD\u5F00\uFF09` : `Command timed out after ${timedOutSecs}s`;
14093
14106
  resolve4({ output: out, error: msg });
14094
14107
  } else if (code !== 0) {
@@ -14316,6 +14329,7 @@ ${label} `);
14316
14329
  let lastLineWasEmpty = false;
14317
14330
  let spinnerCleared = false;
14318
14331
  let partialLine = "";
14332
+ let outputStarted = false;
14319
14333
  const MAX_STREAM_LINES = 200;
14320
14334
  let frame = 0;
14321
14335
  const spin = setInterval(() => {
@@ -14333,9 +14347,17 @@ ${label} `);
14333
14347
  };
14334
14348
  let lastChunkTime = t0;
14335
14349
  let heartbeat = null;
14350
+ const clearHeartbeat = () => {
14351
+ if (heartbeat) {
14352
+ clearInterval(heartbeat);
14353
+ heartbeat = null;
14354
+ }
14355
+ };
14356
+ signal?.addEventListener("abort", clearHeartbeat, { once: true });
14336
14357
  const onStream = isBash ? (chunk) => {
14337
14358
  lastChunkTime = Date.now();
14338
- if (streamedLines === 0 && partialLine.length === 0) {
14359
+ if (!outputStarted) {
14360
+ outputStarted = true;
14339
14361
  clearSpinner();
14340
14362
  process.stdout.write(`${label}
14341
14363
  `);
@@ -14380,11 +14402,9 @@ ${label} `);
14380
14402
  }
14381
14403
  }
14382
14404
  } : void 0;
14383
- const result = await executeTool(tc.name, args, onStream);
14384
- if (heartbeat) {
14385
- clearInterval(heartbeat);
14386
- heartbeat = null;
14387
- }
14405
+ const result = await executeTool(tc.name, args, onStream, signal);
14406
+ signal?.removeEventListener("abort", clearHeartbeat);
14407
+ clearHeartbeat();
14388
14408
  if (partialLine) {
14389
14409
  if (streamedLines < MAX_STREAM_LINES) {
14390
14410
  process.stdout.write("\r" + source_default.dim(" \u2502 ") + partialLine + "\x1B[K\n");
@@ -15979,7 +15999,7 @@ function clearCheckpoints(sessionId) {
15979
15999
 
15980
16000
  // src/index.ts
15981
16001
  var import_fs7 = require("fs");
15982
- var VERSION2 = "2.3.8";
16002
+ var VERSION2 = "2.4.0";
15983
16003
  var SKILLHUB_HUBS = {
15984
16004
  bgi: { label: "BGI\u5185\u7F51", apiBase: "https://clawhub.ai", backend: "clawhub" },
15985
16005
  clawhub: { label: "clawhub.ai", apiBase: "https://clawhub.ai", backend: "clawhub" },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bgicli/bgicli",
3
- "version": "2.3.8",
3
+ "version": "2.4.0",
4
4
  "description": "BGI CLI — Bioinformatics AI terminal for Chinese researchers (百炼/DeepSeek/Kimi/Qwen)",
5
5
  "bin": {
6
6
  "bgi": "dist/bgi.js"