@bgicli/bgicli 2.3.9 → 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 +29 -11
  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) {
@@ -14334,6 +14347,13 @@ ${label} `);
14334
14347
  };
14335
14348
  let lastChunkTime = t0;
14336
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 });
14337
14357
  const onStream = isBash ? (chunk) => {
14338
14358
  lastChunkTime = Date.now();
14339
14359
  if (!outputStarted) {
@@ -14382,11 +14402,9 @@ ${label} `);
14382
14402
  }
14383
14403
  }
14384
14404
  } : void 0;
14385
- const result = await executeTool(tc.name, args, onStream);
14386
- if (heartbeat) {
14387
- clearInterval(heartbeat);
14388
- heartbeat = null;
14389
- }
14405
+ const result = await executeTool(tc.name, args, onStream, signal);
14406
+ signal?.removeEventListener("abort", clearHeartbeat);
14407
+ clearHeartbeat();
14390
14408
  if (partialLine) {
14391
14409
  if (streamedLines < MAX_STREAM_LINES) {
14392
14410
  process.stdout.write("\r" + source_default.dim(" \u2502 ") + partialLine + "\x1B[K\n");
@@ -15981,7 +15999,7 @@ function clearCheckpoints(sessionId) {
15981
15999
 
15982
16000
  // src/index.ts
15983
16001
  var import_fs7 = require("fs");
15984
- var VERSION2 = "2.3.9";
16002
+ var VERSION2 = "2.4.0";
15985
16003
  var SKILLHUB_HUBS = {
15986
16004
  bgi: { label: "BGI\u5185\u7F51", apiBase: "https://clawhub.ai", backend: "clawhub" },
15987
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.9",
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"