@bike4mind/cli 0.2.29-feat-cli-websocket-streaming.18841 → 0.2.29-feat-cli-websocket-streaming.18842

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/index.js +49 -76
  2. package/package.json +6 -6
package/dist/index.js CHANGED
@@ -13416,8 +13416,8 @@ var WebSocketLlmBackend = class {
13416
13416
  }
13417
13417
  /**
13418
13418
  * Make LLM completion request via WebSocket.
13419
- * Mirrors ServerLlmBackend accumulation logic collects all chunks,
13420
- * calls callback once at completion with full accumulated content.
13419
+ * Collects all streamed chunks, then calls callback once at completion
13420
+ * with the full accumulated content.
13421
13421
  */
13422
13422
  async complete(model, messages, options, callback) {
13423
13423
  logger.debug(`[WebSocketLlmBackend] Starting complete() with model: ${model}`);
@@ -13444,32 +13444,33 @@ var WebSocketLlmBackend = class {
13444
13444
  let toolsUsed = [];
13445
13445
  let thinkingBlocks = [];
13446
13446
  let settled = false;
13447
- const cleanup = () => {
13448
- this.wsManager.offRequest(requestId);
13449
- };
13450
- const settleResolve = () => {
13451
- if (settled) return;
13452
- settled = true;
13453
- cleanup();
13454
- resolve3();
13455
- };
13456
- const settleReject = (err) => {
13447
+ const settle = (action) => {
13457
13448
  if (settled) return;
13458
13449
  settled = true;
13459
- cleanup();
13460
- reject(err);
13450
+ this.wsManager.offRequest(requestId);
13451
+ action();
13461
13452
  };
13453
+ const settleResolve = () => settle(() => resolve3());
13454
+ const settleReject = (err) => settle(() => reject(err));
13462
13455
  if (options.abortSignal) {
13463
- const abortHandler = () => {
13464
- logger.debug("[WebSocketLlmBackend] Abort signal received");
13465
- settleResolve();
13466
- };
13467
13456
  if (options.abortSignal.aborted) {
13468
13457
  settleResolve();
13469
13458
  return;
13470
13459
  }
13471
- options.abortSignal.addEventListener("abort", abortHandler, { once: true });
13460
+ options.abortSignal.addEventListener(
13461
+ "abort",
13462
+ () => {
13463
+ logger.debug("[WebSocketLlmBackend] Abort signal received");
13464
+ settleResolve();
13465
+ },
13466
+ { once: true }
13467
+ );
13472
13468
  }
13469
+ const updateUsage = (usage) => {
13470
+ if (usage) {
13471
+ lastUsageInfo = { inputTokens: usage.inputTokens, outputTokens: usage.outputTokens };
13472
+ }
13473
+ };
13473
13474
  this.wsManager.onRequest(requestId, (message) => {
13474
13475
  if (options.abortSignal?.aborted) return;
13475
13476
  const action = message.action;
@@ -13477,48 +13478,29 @@ var WebSocketLlmBackend = class {
13477
13478
  eventCount++;
13478
13479
  const chunk = message.chunk;
13479
13480
  streamLogger.onEvent(eventCount, JSON.stringify(chunk));
13481
+ const textChunk = chunk.text || "";
13482
+ if (textChunk) accumulatedText += textChunk;
13483
+ updateUsage(chunk.usage);
13480
13484
  if (chunk.type === "content") {
13481
- const textChunk = chunk.text || "";
13482
- accumulatedText += textChunk;
13483
13485
  streamLogger.onContent(eventCount, textChunk, accumulatedText);
13484
- if (chunk.usage) {
13485
- lastUsageInfo = {
13486
- inputTokens: chunk.usage.inputTokens,
13487
- outputTokens: chunk.usage.outputTokens
13488
- };
13489
- }
13490
13486
  } else if (chunk.type === "tool_use") {
13491
13487
  streamLogger.onCriticalEvent(eventCount, "TOOL_USE", `tools: ${chunk.tools?.length}`);
13492
- const textChunk = chunk.text || "";
13493
- if (textChunk) accumulatedText += textChunk;
13494
- if (chunk.tools && chunk.tools.length > 0) {
13495
- toolsUsed = chunk.tools;
13496
- }
13497
- if (chunk.thinking && chunk.thinking.length > 0) {
13498
- thinkingBlocks = chunk.thinking;
13499
- }
13500
- if (chunk.usage) {
13501
- lastUsageInfo = {
13502
- inputTokens: chunk.usage.inputTokens,
13503
- outputTokens: chunk.usage.outputTokens
13504
- };
13505
- }
13488
+ if (chunk.tools && chunk.tools.length > 0) toolsUsed = chunk.tools;
13489
+ if (chunk.thinking && chunk.thinking.length > 0) thinkingBlocks = chunk.thinking;
13506
13490
  }
13507
13491
  } else if (action === "cli_completion_done") {
13508
13492
  streamLogger.streamComplete(accumulatedText);
13509
13493
  const cleanedText = stripThinkingBlocks2(accumulatedText);
13510
- if (toolsUsed.length > 0) {
13511
- const info = {
13512
- toolsUsed,
13513
- thinking: thinkingBlocks.length > 0 ? thinkingBlocks : void 0,
13514
- ...lastUsageInfo
13515
- };
13516
- callback([cleanedText], info).then(() => settleResolve()).catch((err) => settleReject(err));
13517
- } else if (cleanedText) {
13518
- callback([cleanedText], lastUsageInfo).then(() => settleResolve()).catch((err) => settleReject(err));
13519
- } else {
13494
+ if (!cleanedText && toolsUsed.length === 0) {
13520
13495
  settleResolve();
13496
+ return;
13521
13497
  }
13498
+ const info = {
13499
+ ...lastUsageInfo,
13500
+ ...toolsUsed.length > 0 && { toolsUsed },
13501
+ ...thinkingBlocks.length > 0 && { thinking: thinkingBlocks }
13502
+ };
13503
+ callback([cleanedText], info).then(() => settleResolve()).catch((err) => settleReject(err));
13522
13504
  } else if (action === "cli_completion_error") {
13523
13505
  const errorMsg = message.error || "Server error";
13524
13506
  streamLogger.onCriticalEvent(eventCount, "ERROR", errorMsg);
@@ -13546,7 +13528,7 @@ var WebSocketLlmBackend = class {
13546
13528
  }
13547
13529
  /**
13548
13530
  * Get available models from server (REST call, not streaming).
13549
- * Delegates to ApiClient same as ServerLlmBackend.
13531
+ * Delegates to ApiClient -- same as ServerLlmBackend.
13550
13532
  */
13551
13533
  async getModelInfo() {
13552
13534
  try {
@@ -13783,34 +13765,25 @@ var WebSocketToolExecutor = class {
13783
13765
  const requestId = uuidv412();
13784
13766
  return new Promise((resolve3, reject) => {
13785
13767
  let settled = false;
13786
- const cleanup = () => {
13787
- this.wsManager.offRequest(requestId);
13788
- };
13789
- const settleResolve = (result) => {
13768
+ const settle = (action) => {
13790
13769
  if (settled) return;
13791
13770
  settled = true;
13792
- cleanup();
13793
- resolve3(result);
13794
- };
13795
- const settleReject = (err) => {
13796
- if (settled) return;
13797
- settled = true;
13798
- cleanup();
13799
- reject(err);
13771
+ this.wsManager.offRequest(requestId);
13772
+ action();
13800
13773
  };
13774
+ const settleResolve = (result) => settle(() => resolve3(result));
13775
+ const settleReject = (err) => settle(() => reject(err));
13801
13776
  if (abortSignal) {
13802
- const abortHandler = () => {
13803
- settleReject(new Error("Tool execution aborted"));
13804
- };
13805
13777
  if (abortSignal.aborted) {
13806
13778
  settleReject(new Error("Tool execution aborted"));
13807
13779
  return;
13808
13780
  }
13809
- abortSignal.addEventListener("abort", abortHandler, { once: true });
13781
+ abortSignal.addEventListener("abort", () => settleReject(new Error("Tool execution aborted")), {
13782
+ once: true
13783
+ });
13810
13784
  }
13811
13785
  this.wsManager.onRequest(requestId, (message) => {
13812
- const action = message.action;
13813
- if (action === "cli_tool_response") {
13786
+ if (message.action === "cli_tool_response") {
13814
13787
  settleResolve({
13815
13788
  success: message.success,
13816
13789
  content: message.content,
@@ -13970,7 +13943,7 @@ import { isAxiosError as isAxiosError2 } from "axios";
13970
13943
  // package.json
13971
13944
  var package_default = {
13972
13945
  name: "@bike4mind/cli",
13973
- version: "0.2.29-feat-cli-websocket-streaming.18841+5c940d031",
13946
+ version: "0.2.29-feat-cli-websocket-streaming.18842+8ba59c222",
13974
13947
  type: "module",
13975
13948
  description: "Interactive CLI tool for Bike4Mind with ReAct agents",
13976
13949
  license: "UNLICENSED",
@@ -14080,10 +14053,10 @@ var package_default = {
14080
14053
  },
14081
14054
  devDependencies: {
14082
14055
  "@bike4mind/agents": "0.1.0",
14083
- "@bike4mind/common": "2.50.1-feat-cli-websocket-streaming.18841+5c940d031",
14084
- "@bike4mind/mcp": "1.29.1-feat-cli-websocket-streaming.18841+5c940d031",
14085
- "@bike4mind/services": "2.48.1-feat-cli-websocket-streaming.18841+5c940d031",
14086
- "@bike4mind/utils": "2.5.1-feat-cli-websocket-streaming.18841+5c940d031",
14056
+ "@bike4mind/common": "2.50.1-feat-cli-websocket-streaming.18842+8ba59c222",
14057
+ "@bike4mind/mcp": "1.29.1-feat-cli-websocket-streaming.18842+8ba59c222",
14058
+ "@bike4mind/services": "2.48.1-feat-cli-websocket-streaming.18842+8ba59c222",
14059
+ "@bike4mind/utils": "2.5.1-feat-cli-websocket-streaming.18842+8ba59c222",
14087
14060
  "@types/better-sqlite3": "^7.6.13",
14088
14061
  "@types/diff": "^5.0.9",
14089
14062
  "@types/jsonwebtoken": "^9.0.4",
@@ -14100,7 +14073,7 @@ var package_default = {
14100
14073
  optionalDependencies: {
14101
14074
  "@vscode/ripgrep": "^1.17.0"
14102
14075
  },
14103
- gitHead: "5c940d031610617c76d3c12cc611b71db8bb4caf"
14076
+ gitHead: "8ba59c22293ec8857baaba3c7c6d96db1fbb4b15"
14104
14077
  };
14105
14078
 
14106
14079
  // src/config/constants.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bike4mind/cli",
3
- "version": "0.2.29-feat-cli-websocket-streaming.18841+5c940d031",
3
+ "version": "0.2.29-feat-cli-websocket-streaming.18842+8ba59c222",
4
4
  "type": "module",
5
5
  "description": "Interactive CLI tool for Bike4Mind with ReAct agents",
6
6
  "license": "UNLICENSED",
@@ -110,10 +110,10 @@
110
110
  },
111
111
  "devDependencies": {
112
112
  "@bike4mind/agents": "0.1.0",
113
- "@bike4mind/common": "2.50.1-feat-cli-websocket-streaming.18841+5c940d031",
114
- "@bike4mind/mcp": "1.29.1-feat-cli-websocket-streaming.18841+5c940d031",
115
- "@bike4mind/services": "2.48.1-feat-cli-websocket-streaming.18841+5c940d031",
116
- "@bike4mind/utils": "2.5.1-feat-cli-websocket-streaming.18841+5c940d031",
113
+ "@bike4mind/common": "2.50.1-feat-cli-websocket-streaming.18842+8ba59c222",
114
+ "@bike4mind/mcp": "1.29.1-feat-cli-websocket-streaming.18842+8ba59c222",
115
+ "@bike4mind/services": "2.48.1-feat-cli-websocket-streaming.18842+8ba59c222",
116
+ "@bike4mind/utils": "2.5.1-feat-cli-websocket-streaming.18842+8ba59c222",
117
117
  "@types/better-sqlite3": "^7.6.13",
118
118
  "@types/diff": "^5.0.9",
119
119
  "@types/jsonwebtoken": "^9.0.4",
@@ -130,5 +130,5 @@
130
130
  "optionalDependencies": {
131
131
  "@vscode/ripgrep": "^1.17.0"
132
132
  },
133
- "gitHead": "5c940d031610617c76d3c12cc611b71db8bb4caf"
133
+ "gitHead": "8ba59c22293ec8857baaba3c7c6d96db1fbb4b15"
134
134
  }