@bike4mind/cli 0.2.10-fix-extendend-thinking-with-tool-use.17269 → 0.2.10-fix-cli-socket-hangup-error-handling.17310

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.
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  CurationArtifactType
4
- } from "./chunk-3OX632TE.js";
4
+ } from "./chunk-DJPXSSP4.js";
5
5
  import "./chunk-PDX44BCA.js";
6
6
 
7
7
  // ../../b4m-core/packages/services/dist/src/notebookCurationService/artifactExtractor.js
@@ -7,11 +7,11 @@ import {
7
7
  getSettingsMap,
8
8
  getSettingsValue,
9
9
  secureParameters
10
- } from "./chunk-T7NEJI2V.js";
10
+ } from "./chunk-GCVIRGIN.js";
11
11
  import {
12
12
  KnowledgeType,
13
13
  SupportedFabFileMimeTypes
14
- } from "./chunk-3OX632TE.js";
14
+ } from "./chunk-DJPXSSP4.js";
15
15
 
16
16
  // ../../b4m-core/packages/services/dist/src/fabFileService/create.js
17
17
  import { z } from "zod";
@@ -5901,9 +5901,6 @@ function buildSSEEvent(text, info) {
5901
5901
  outputTokens: info.outputTokens
5902
5902
  };
5903
5903
  }
5904
- if (info?.thinking && info.thinking.length > 0) {
5905
- event.thinking = info.thinking;
5906
- }
5907
5904
  return event;
5908
5905
  }
5909
5906
  function formatSSEError(error) {
@@ -16,7 +16,7 @@ import {
16
16
  dayjsConfig_default,
17
17
  extractSnippetMeta,
18
18
  settingsMap
19
- } from "./chunk-3OX632TE.js";
19
+ } from "./chunk-DJPXSSP4.js";
20
20
 
21
21
  // ../../b4m-core/packages/utils/dist/src/storage/S3Storage.js
22
22
  import { S3Client, PutObjectCommand, DeleteObjectCommand, GetObjectCommand, HeadObjectCommand } from "@aws-sdk/client-s3";
@@ -701,12 +701,8 @@ var AnthropicBackend = class {
701
701
  this.logger.debug(`[Tool Execution] Last few messages:`, JSON.stringify(messages.slice(-3), null, 2));
702
702
  await this.complete(model, messages, options, cb, toolsUsed);
703
703
  } else {
704
- const thinkingBlocks = this.isThinkingEnabled ? this.lastAssistantContent.filter((block) => block?.type === "thinking" || block?.type === "redacted_thinking") : void 0;
705
- this.logger.debug(`[Tool Execution] executeTools=false, passing tool calls to callback with ${thinkingBlocks?.length || 0} thinking blocks`);
706
- await cb([null], {
707
- toolsUsed,
708
- thinking: thinkingBlocks?.length ? thinkingBlocks : void 0
709
- });
704
+ this.logger.debug(`[Tool Execution] executeTools=false, passing tool calls to callback`);
705
+ await cb([null], { toolsUsed });
710
706
  }
711
707
  return;
712
708
  }
@@ -778,12 +774,8 @@ var AnthropicBackend = class {
778
774
  await this.complete(model, messages, { ...options, tools: void 0, _internal: void 0 }, cb, toolsUsed);
779
775
  }
780
776
  } else {
781
- const thinkingBlocks = this.isThinkingEnabled ? this.lastAssistantContent.filter((block) => block?.type === "thinking" || block?.type === "redacted_thinking") : void 0;
782
- this.logger.debug(`[Tool Execution] executeTools=false, passing tool calls to callback with ${thinkingBlocks?.length || 0} thinking blocks`);
783
- await cb([null], {
784
- toolsUsed,
785
- thinking: thinkingBlocks?.length ? thinkingBlocks : void 0
786
- });
777
+ this.logger.debug(`[Tool Execution] executeTools=false, passing tool calls to callback`);
778
+ await cb([null], { toolsUsed });
787
779
  }
788
780
  return;
789
781
  }
@@ -6,12 +6,12 @@ import {
6
6
  getSettingsByNames,
7
7
  obfuscateApiKey,
8
8
  secureParameters
9
- } from "./chunk-T7NEJI2V.js";
9
+ } from "./chunk-GCVIRGIN.js";
10
10
  import {
11
11
  ApiKeyType,
12
12
  MementoTier,
13
13
  isSupportedEmbeddingModel
14
- } from "./chunk-3OX632TE.js";
14
+ } from "./chunk-DJPXSSP4.js";
15
15
 
16
16
  // ../../b4m-core/packages/services/dist/src/apiKeyService/get.js
17
17
  import { z } from "zod";
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  BadRequestError,
4
4
  secureParameters
5
- } from "./chunk-T7NEJI2V.js";
5
+ } from "./chunk-GCVIRGIN.js";
6
6
  import {
7
7
  GenericCreditDeductTransaction,
8
8
  ImageEditUsageTransaction,
@@ -10,7 +10,7 @@ import {
10
10
  RealtimeVoiceUsageTransaction,
11
11
  TextGenerationUsageTransaction,
12
12
  TransferCreditTransaction
13
- } from "./chunk-3OX632TE.js";
13
+ } from "./chunk-DJPXSSP4.js";
14
14
 
15
15
  // ../../b4m-core/packages/services/dist/src/creditService/subtractCredits.js
16
16
  import { z } from "zod";
@@ -2,10 +2,10 @@
2
2
  import {
3
3
  createFabFile,
4
4
  createFabFileSchema
5
- } from "./chunk-J5CBHZGK.js";
6
- import "./chunk-T7NEJI2V.js";
5
+ } from "./chunk-AQBZVAYO.js";
6
+ import "./chunk-GCVIRGIN.js";
7
7
  import "./chunk-AMDXHL6S.js";
8
- import "./chunk-3OX632TE.js";
8
+ import "./chunk-DJPXSSP4.js";
9
9
  import "./chunk-PDX44BCA.js";
10
10
  export {
11
11
  createFabFile,
package/dist/index.js CHANGED
@@ -4,9 +4,9 @@ import {
4
4
  getEffectiveApiKey,
5
5
  getOpenWeatherKey,
6
6
  getSerperKey
7
- } from "./chunk-AKSB42HL.js";
8
- import "./chunk-OX65IHIA.js";
9
- import "./chunk-J5CBHZGK.js";
7
+ } from "./chunk-GO75FMLY.js";
8
+ import "./chunk-VZU4Z7WI.js";
9
+ import "./chunk-AQBZVAYO.js";
10
10
  import {
11
11
  BFLImageService,
12
12
  BaseStorage,
@@ -15,7 +15,7 @@ import {
15
15
  OpenAIBackend,
16
16
  OpenAIImageService,
17
17
  XAIImageService
18
- } from "./chunk-T7NEJI2V.js";
18
+ } from "./chunk-GCVIRGIN.js";
19
19
  import {
20
20
  Logger
21
21
  } from "./chunk-AMDXHL6S.js";
@@ -73,7 +73,7 @@ import {
73
73
  XAI_IMAGE_MODELS,
74
74
  b4mLLMTools,
75
75
  getMcpProviderMetadata
76
- } from "./chunk-3OX632TE.js";
76
+ } from "./chunk-DJPXSSP4.js";
77
77
  import {
78
78
  __require
79
79
  } from "./chunk-PDX44BCA.js";
@@ -82,7 +82,7 @@ import {
82
82
  import React17, { useState as useState8, useEffect as useEffect3, useCallback, useRef as useRef2 } from "react";
83
83
  import { render, Box as Box16, Text as Text16, useApp, useInput as useInput6 } from "ink";
84
84
  import { execSync } from "child_process";
85
- import { v4 as uuidv49 } from "uuid";
85
+ import { v4 as uuidv410 } from "uuid";
86
86
 
87
87
  // src/components/App.tsx
88
88
  import React11, { useState as useState4 } from "react";
@@ -1523,7 +1523,7 @@ ${errorBlock}`;
1523
1523
  onSave: onSaveConfig,
1524
1524
  onClose: () => setShowConfigEditor(false)
1525
1525
  }
1526
- )) : permissionPrompt ? /* @__PURE__ */ React11.createElement(Box10, { flexDirection: "column", paddingX: 1 }, /* @__PURE__ */ React11.createElement(
1526
+ )) : /* @__PURE__ */ React11.createElement(React11.Fragment, null, /* @__PURE__ */ React11.createElement(Static, { items: messages }, (message) => /* @__PURE__ */ React11.createElement(Box10, { key: message.id, flexDirection: "column", paddingX: 1 }, /* @__PURE__ */ React11.createElement(MessageItem, { message }))), /* @__PURE__ */ React11.createElement(Box10, { flexDirection: "column" }, pendingMessages.map((message) => /* @__PURE__ */ React11.createElement(Box10, { key: message.id, flexDirection: "column", paddingX: 1 }, /* @__PURE__ */ React11.createElement(MessageItem, { message })))), permissionPrompt && /* @__PURE__ */ React11.createElement(Box10, { flexDirection: "column", paddingX: 1 }, /* @__PURE__ */ React11.createElement(
1527
1527
  PermissionPrompt,
1528
1528
  {
1529
1529
  toolName: permissionPrompt.toolName,
@@ -1532,7 +1532,7 @@ ${errorBlock}`;
1532
1532
  canBeTrusted: permissionPrompt.canBeTrusted,
1533
1533
  onResponse: onPermissionResponse
1534
1534
  }
1535
- )) : /* @__PURE__ */ React11.createElement(React11.Fragment, null, /* @__PURE__ */ React11.createElement(Static, { items: messages }, (message, index) => /* @__PURE__ */ React11.createElement(Box10, { key: `${message.timestamp}-${message.role}-${index}`, flexDirection: "column", paddingX: 1 }, /* @__PURE__ */ React11.createElement(MessageItem, { message }))), /* @__PURE__ */ React11.createElement(Box10, { flexDirection: "column" }, pendingMessages.map((message, index) => /* @__PURE__ */ React11.createElement(Box10, { key: `pending-${message.timestamp}-${index}`, flexDirection: "column", paddingX: 1 }, /* @__PURE__ */ React11.createElement(MessageItem, { message })))), /* @__PURE__ */ React11.createElement(AgentThinking, null), exitRequested && /* @__PURE__ */ React11.createElement(Box10, { paddingX: 1, marginBottom: 1 }, /* @__PURE__ */ React11.createElement(Text10, { color: "yellow", bold: true }, "Press Ctrl+C again to exit")), /* @__PURE__ */ React11.createElement(Box10, { borderStyle: "single", borderColor: isBashMode ? "yellow" : "cyan", paddingX: 1 }, /* @__PURE__ */ React11.createElement(
1535
+ )), !permissionPrompt && /* @__PURE__ */ React11.createElement(AgentThinking, null), exitRequested && /* @__PURE__ */ React11.createElement(Box10, { paddingX: 1, marginBottom: 1 }, /* @__PURE__ */ React11.createElement(Text10, { color: "yellow", bold: true }, "Press Ctrl+C again to exit")), /* @__PURE__ */ React11.createElement(Box10, { borderStyle: "single", borderColor: isBashMode ? "yellow" : "cyan", paddingX: 1 }, /* @__PURE__ */ React11.createElement(
1536
1536
  InputPrompt,
1537
1537
  {
1538
1538
  onSubmit: handleSubmit,
@@ -1932,6 +1932,7 @@ function LoginFlow({ apiUrl = "http://localhost:3000", configStore, onSuccess, o
1932
1932
  import { promises as fs3 } from "fs";
1933
1933
  import path3 from "path";
1934
1934
  import { homedir } from "os";
1935
+ import { v4 as uuidv4 } from "uuid";
1935
1936
  var SessionStore = class {
1936
1937
  constructor(basePath) {
1937
1938
  this.basePath = basePath || path3.join(homedir(), ".bike4mind", "sessions");
@@ -1967,7 +1968,14 @@ var SessionStore = class {
1967
1968
  const filePath = path3.join(this.basePath, `${id}.json`);
1968
1969
  try {
1969
1970
  const data = await fs3.readFile(filePath, "utf-8");
1970
- return JSON.parse(data);
1971
+ const session = JSON.parse(data);
1972
+ session.messages = session.messages.map((msg) => {
1973
+ if (!msg.id) {
1974
+ return { ...msg, id: uuidv4() };
1975
+ }
1976
+ return msg;
1977
+ });
1978
+ return session;
1971
1979
  } catch (error) {
1972
1980
  if (error.code === "ENOENT") {
1973
1981
  return null;
@@ -1996,7 +2004,14 @@ var SessionStore = class {
1996
2004
  jsonFiles.map(async (file) => {
1997
2005
  const filePath = path3.join(this.basePath, file);
1998
2006
  const data = await fs3.readFile(filePath, "utf-8");
1999
- return JSON.parse(data);
2007
+ const session = JSON.parse(data);
2008
+ session.messages = session.messages.map((msg) => {
2009
+ if (!msg.id) {
2010
+ return { ...msg, id: uuidv4() };
2011
+ }
2012
+ return msg;
2013
+ });
2014
+ return session;
2000
2015
  })
2001
2016
  );
2002
2017
  return sessions.sort((a, b) => new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime());
@@ -2050,7 +2065,7 @@ var SessionStore = class {
2050
2065
  import { promises as fs4, existsSync as existsSync3 } from "fs";
2051
2066
  import path4 from "path";
2052
2067
  import { homedir as homedir2 } from "os";
2053
- import { v4 as uuidv4 } from "uuid";
2068
+ import { v4 as uuidv42 } from "uuid";
2054
2069
  import { z } from "zod";
2055
2070
  var AuthTokensSchema = z.object({
2056
2071
  accessToken: z.string(),
@@ -2144,7 +2159,7 @@ var ProjectLocalConfigSchema = z.object({
2144
2159
  });
2145
2160
  var DEFAULT_CONFIG = {
2146
2161
  version: "0.1.0",
2147
- userId: uuidv4(),
2162
+ userId: uuidv42(),
2148
2163
  defaultModel: "claude-sonnet-4-5-20250929",
2149
2164
  toolApiKeys: {
2150
2165
  openweather: void 0,
@@ -2426,7 +2441,7 @@ var ConfigStore = class {
2426
2441
  * Reset configuration to defaults
2427
2442
  */
2428
2443
  async reset() {
2429
- this.config = { ...DEFAULT_CONFIG, userId: uuidv4() };
2444
+ this.config = { ...DEFAULT_CONFIG, userId: uuidv42() };
2430
2445
  await this.save();
2431
2446
  return this.config;
2432
2447
  }
@@ -3129,7 +3144,6 @@ ${options.context}` : this.getSystemPrompt()
3129
3144
  }
3130
3145
  if (completionInfo.toolsUsed && completionInfo.toolsUsed.length > 0) {
3131
3146
  hadToolCalls = true;
3132
- const thinkingBlocks = completionInfo.thinking || [];
3133
3147
  for (const toolUse of completionInfo.toolsUsed) {
3134
3148
  const toolCallId = `${toolUse.name}_${JSON.stringify(toolUse.arguments)}`;
3135
3149
  if (processedToolIds.has(toolCallId)) {
@@ -3162,21 +3176,16 @@ ${options.context}` : this.getSystemPrompt()
3162
3176
  const params = typeof toolUse.arguments === "string" ? JSON.parse(toolUse.arguments) : toolUse.arguments;
3163
3177
  observation = await tool.toolFn(params);
3164
3178
  const toolCallId2 = `${toolUse.name}_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
3165
- const assistantContent = [
3166
- // Include thinking blocks first (required by Anthropic when thinking is enabled)
3167
- ...thinkingBlocks,
3168
- // Then the tool use
3169
- {
3170
- type: "tool_use",
3171
- id: toolCallId2,
3172
- name: toolUse.name,
3173
- input: params
3174
- }
3175
- ];
3176
- this.context.logger.debug("[assistantContent] ", JSON.stringify(assistantContent, null, 2));
3177
3179
  messages.push({
3178
3180
  role: "assistant",
3179
- content: assistantContent
3181
+ content: [
3182
+ {
3183
+ type: "tool_use",
3184
+ id: toolCallId2,
3185
+ name: toolUse.name,
3186
+ input: params
3187
+ }
3188
+ ]
3180
3189
  });
3181
3190
  messages.push({
3182
3191
  role: "user",
@@ -4342,7 +4351,7 @@ var listFabFilesSchema = z86.object({
4342
4351
 
4343
4352
  // ../../b4m-core/packages/services/dist/src/fabFileService/update.js
4344
4353
  import mime from "mime-types";
4345
- import { v4 as uuidv42 } from "uuid";
4354
+ import { v4 as uuidv43 } from "uuid";
4346
4355
  import { z as z87 } from "zod";
4347
4356
  var updateFabFileSchema = z87.object({
4348
4357
  id: z87.string(),
@@ -4463,7 +4472,7 @@ var editFabFileSchema = z98.object({
4463
4472
 
4464
4473
  // ../../b4m-core/packages/services/dist/src/fabFileService/applyEdit.js
4465
4474
  import mime2 from "mime-types";
4466
- import { v4 as uuidv43 } from "uuid";
4475
+ import { v4 as uuidv44 } from "uuid";
4467
4476
  import { z as z99 } from "zod";
4468
4477
  var applyEditSchema = z99.object({
4469
4478
  id: z99.string(),
@@ -5291,7 +5300,7 @@ import { toFile } from "openai/uploads";
5291
5300
  import { Readable } from "stream";
5292
5301
  import { TranscribeClient, StartTranscriptionJobCommand, GetTranscriptionJobCommand, LanguageCode, MediaFormat } from "@aws-sdk/client-transcribe";
5293
5302
  import { S3Client, PutObjectCommand, GetObjectCommand, DeleteObjectCommand } from "@aws-sdk/client-s3";
5294
- import { v4 as uuidv44 } from "uuid";
5303
+ import { v4 as uuidv45 } from "uuid";
5295
5304
 
5296
5305
  // ../../b4m-core/packages/services/dist/src/emailIngestionService/processIngestedEmail.js
5297
5306
  import { randomUUID as randomUUID5 } from "crypto";
@@ -5452,7 +5461,7 @@ var weatherTool = {
5452
5461
  // ../../b4m-core/packages/services/dist/src/llm/tools/implementation/imageGeneration/index.js
5453
5462
  import axios6 from "axios";
5454
5463
  import { fileTypeFromBuffer as fileTypeFromBuffer2 } from "file-type";
5455
- import { v4 as uuidv45 } from "uuid";
5464
+ import { v4 as uuidv46 } from "uuid";
5456
5465
  async function downloadImage(url) {
5457
5466
  if (url.startsWith("data:image/")) {
5458
5467
  const base64Data = url.split(",")[1];
@@ -5466,7 +5475,7 @@ async function processAndStoreImages(images, context) {
5466
5475
  return Promise.all(images.map(async (image) => {
5467
5476
  const buffer = await downloadImage(image);
5468
5477
  const fileType = await fileTypeFromBuffer2(buffer);
5469
- const filename = `${uuidv45()}.${fileType?.ext}`;
5478
+ const filename = `${uuidv46()}.${fileType?.ext}`;
5470
5479
  const path16 = await context.imageGenerateStorage.upload(buffer, filename, {});
5471
5480
  return path16;
5472
5481
  }));
@@ -6635,7 +6644,7 @@ Return only the edited content without any markdown code blocks or explanations.
6635
6644
  // ../../b4m-core/packages/services/dist/src/llm/tools/implementation/imageEdit/index.js
6636
6645
  import axios7 from "axios";
6637
6646
  import { fileTypeFromBuffer as fileTypeFromBuffer3 } from "file-type";
6638
- import { v4 as uuidv46 } from "uuid";
6647
+ import { v4 as uuidv47 } from "uuid";
6639
6648
  async function downloadImage2(url) {
6640
6649
  if (url.startsWith("data:image/")) {
6641
6650
  const base64Data = url.split(",")[1];
@@ -6679,7 +6688,7 @@ async function getImageFromFileId(fileId, context) {
6679
6688
  async function processAndStoreImage(imageUrl, context) {
6680
6689
  const buffer = await downloadImage2(imageUrl);
6681
6690
  const fileType = await fileTypeFromBuffer3(buffer);
6682
- const filename = `${uuidv46()}.${fileType?.ext}`;
6691
+ const filename = `${uuidv47()}.${fileType?.ext}`;
6683
6692
  const path16 = await context.imageGenerateStorage.upload(buffer, filename, {});
6684
6693
  return path16;
6685
6694
  }
@@ -9656,7 +9665,7 @@ var QuestStartBodySchema = z139.object({
9656
9665
  // ../../b4m-core/packages/services/dist/src/llm/ImageGeneration.js
9657
9666
  import axios8 from "axios";
9658
9667
  import { fileTypeFromBuffer as fileTypeFromBuffer4 } from "file-type";
9659
- import { v4 as uuidv47 } from "uuid";
9668
+ import { v4 as uuidv48 } from "uuid";
9660
9669
  import { z as z140 } from "zod";
9661
9670
  import { fromZodError as fromZodError2 } from "zod-validation-error";
9662
9671
  var ImageGenerationBodySchema = OpenAIImageGenerationInput.extend({
@@ -9677,7 +9686,7 @@ var ImageGenerationBodySchema = OpenAIImageGenerationInput.extend({
9677
9686
  // ../../b4m-core/packages/services/dist/src/llm/ImageEdit.js
9678
9687
  import axios9 from "axios";
9679
9688
  import { fileTypeFromBuffer as fileTypeFromBuffer5 } from "file-type";
9680
- import { v4 as uuidv48 } from "uuid";
9689
+ import { v4 as uuidv49 } from "uuid";
9681
9690
  import { z as z141 } from "zod";
9682
9691
  import { fromZodError as fromZodError3 } from "zod-validation-error";
9683
9692
  var ImageEditBodySchema = OpenAIImageGenerationInput.extend({
@@ -11125,7 +11134,6 @@ var ServerLlmBackend = class {
11125
11134
  let accumulatedText = "";
11126
11135
  let lastUsageInfo = {};
11127
11136
  let toolsUsed = [];
11128
- let thinkingBlocks = [];
11129
11137
  let receivedDone = false;
11130
11138
  const parser = createParser({
11131
11139
  onEvent: (event) => {
@@ -11139,12 +11147,9 @@ var ServerLlmBackend = class {
11139
11147
  if (toolsUsed.length > 0) {
11140
11148
  const info = {
11141
11149
  toolsUsed,
11142
- thinking: thinkingBlocks.length > 0 ? thinkingBlocks : void 0,
11143
11150
  ...lastUsageInfo
11144
11151
  };
11145
- logger.debug(
11146
- `[ServerLlmBackend] Calling callback with tools, thinking blocks: ${thinkingBlocks.length}`
11147
- );
11152
+ logger.debug("[ServerLlmBackend] Calling callback with tools, will wait for completion");
11148
11153
  callback([cleanedText], info).catch((err) => {
11149
11154
  logger.error("[ServerLlmBackend] Callback error:", err);
11150
11155
  reject(err);
@@ -11200,10 +11205,6 @@ var ServerLlmBackend = class {
11200
11205
  if (parsed.tools && parsed.tools.length > 0) {
11201
11206
  toolsUsed = parsed.tools;
11202
11207
  }
11203
- if (parsed.thinking && parsed.thinking.length > 0) {
11204
- thinkingBlocks = parsed.thinking;
11205
- logger.debug(`[ServerLlmBackend] Received ${thinkingBlocks.length} thinking blocks`);
11206
- }
11207
11208
  if (parsed.usage) {
11208
11209
  lastUsageInfo = {
11209
11210
  inputTokens: parsed.usage.inputTokens,
@@ -11231,7 +11232,7 @@ var ServerLlmBackend = class {
11231
11232
  reject(error);
11232
11233
  });
11233
11234
  } catch (error) {
11234
- logger.error("LLM completion failed", error);
11235
+ logger.debug(`LLM completion failed: ${error instanceof Error ? error.message : String(error)}`);
11235
11236
  if (isAxiosError(error)) {
11236
11237
  logger.debug(
11237
11238
  `[ServerLlmBackend] Axios error details: ${JSON.stringify({
@@ -11294,6 +11295,12 @@ var ServerLlmBackend = class {
11294
11295
  reject(new Error("Cannot connect to Bike4Mind server. Please check your internet connection."));
11295
11296
  } else if (error.message.includes("Rate limit exceeded")) {
11296
11297
  reject(error);
11298
+ } else if (error.message.includes("socket hang up")) {
11299
+ reject(
11300
+ new Error(
11301
+ "Connection to server was interrupted (socket hang up). This can happen due to server timeouts or network issues. Please try again."
11302
+ )
11303
+ );
11297
11304
  } else {
11298
11305
  reject(new Error(`Failed to complete LLM request: ${error.message}`));
11299
11306
  }
@@ -11526,7 +11533,7 @@ import { isAxiosError as isAxiosError2 } from "axios";
11526
11533
  // package.json
11527
11534
  var package_default = {
11528
11535
  name: "@bike4mind/cli",
11529
- version: "0.2.10-fix-extendend-thinking-with-tool-use.17269+e94200ce4",
11536
+ version: "0.2.10-fix-cli-socket-hangup-error-handling.17310+c525c3233",
11530
11537
  type: "module",
11531
11538
  description: "Interactive CLI tool for Bike4Mind with ReAct agents",
11532
11539
  license: "UNLICENSED",
@@ -11630,10 +11637,10 @@ var package_default = {
11630
11637
  },
11631
11638
  devDependencies: {
11632
11639
  "@bike4mind/agents": "0.1.0",
11633
- "@bike4mind/common": "2.39.1-fix-extendend-thinking-with-tool-use.17269+e94200ce4",
11634
- "@bike4mind/mcp": "1.20.4-fix-extendend-thinking-with-tool-use.17269+e94200ce4",
11635
- "@bike4mind/services": "2.34.2-fix-extendend-thinking-with-tool-use.17269+e94200ce4",
11636
- "@bike4mind/utils": "2.1.4-fix-extendend-thinking-with-tool-use.17269+e94200ce4",
11640
+ "@bike4mind/common": "2.39.1-fix-cli-socket-hangup-error-handling.17310+c525c3233",
11641
+ "@bike4mind/mcp": "1.20.4-fix-cli-socket-hangup-error-handling.17310+c525c3233",
11642
+ "@bike4mind/services": "2.34.2-fix-cli-socket-hangup-error-handling.17310+c525c3233",
11643
+ "@bike4mind/utils": "2.1.4-fix-cli-socket-hangup-error-handling.17310+c525c3233",
11637
11644
  "@types/better-sqlite3": "^7.6.13",
11638
11645
  "@types/diff": "^5.0.9",
11639
11646
  "@types/jsonwebtoken": "^9.0.4",
@@ -11646,7 +11653,7 @@ var package_default = {
11646
11653
  typescript: "^5.9.3",
11647
11654
  vitest: "^3.2.4"
11648
11655
  },
11649
- gitHead: "e94200ce4e993f1a05a29c6df68d05697e922ca1"
11656
+ gitHead: "c525c323364efcd1b2107413ac1aa8619f462124"
11650
11657
  };
11651
11658
 
11652
11659
  // src/config/constants.ts
@@ -11657,8 +11664,24 @@ var USAGE_CACHE_TTL = 5 * 60 * 1e3;
11657
11664
  // src/agents/SubagentOrchestrator.ts
11658
11665
  var SubagentOrchestrator = class {
11659
11666
  constructor(deps) {
11667
+ this.beforeRunCallback = null;
11668
+ this.afterRunCallback = null;
11660
11669
  this.deps = deps;
11661
11670
  }
11671
+ /**
11672
+ * Set a callback to be invoked before each subagent.run()
11673
+ * Use this to subscribe to agent events (e.g., subagent.on('action', handler))
11674
+ */
11675
+ setBeforeRunCallback(callback) {
11676
+ this.beforeRunCallback = callback;
11677
+ }
11678
+ /**
11679
+ * Set a callback to be invoked after each subagent.run()
11680
+ * Use this to unsubscribe from agent events (e.g., subagent.off('action', handler))
11681
+ */
11682
+ setAfterRunCallback(callback) {
11683
+ this.afterRunCallback = callback;
11684
+ }
11662
11685
  /**
11663
11686
  * Delegate a task to a specialized subagent
11664
11687
  *
@@ -11708,11 +11731,29 @@ var SubagentOrchestrator = class {
11708
11731
  systemPrompt: config.systemPrompt || this.getDefaultSystemPrompt(type)
11709
11732
  });
11710
11733
  updatedContext.currentAgent = subagent;
11734
+ if (this.beforeRunCallback) {
11735
+ this.beforeRunCallback(subagent, type);
11736
+ }
11711
11737
  const startTime = Date.now();
11712
- const result = await subagent.run(task, {
11713
- maxIterations
11714
- });
11738
+ let result;
11739
+ try {
11740
+ result = await subagent.run(task, {
11741
+ maxIterations
11742
+ });
11743
+ } catch (error) {
11744
+ const duration2 = Date.now() - startTime;
11745
+ const errorMessage = error instanceof Error ? error.message : String(error);
11746
+ this.deps.logger.error(`Subagent failed after ${duration2}ms: ${errorMessage}`);
11747
+ throw new Error(
11748
+ `Subagent execution failed: ${errorMessage}
11749
+
11750
+ This error occurred while running a ${type} subagent. The main conversation has been preserved, and you can retry or continue with other tasks.`
11751
+ );
11752
+ }
11715
11753
  const duration = Date.now() - startTime;
11754
+ if (this.afterRunCallback) {
11755
+ this.afterRunCallback(subagent, type);
11756
+ }
11716
11757
  this.deps.logger.debug(
11717
11758
  `Subagent completed in ${duration}ms, ${result.completionInfo.iterations} iterations, ${result.completionInfo.totalTokens} tokens`
11718
11759
  );
@@ -11922,13 +11963,18 @@ function createSubagentDelegateTool(orchestrator, parentSessionId) {
11922
11963
  }
11923
11964
  const thoroughness = params.thoroughness || "medium";
11924
11965
  const type = params.type;
11925
- const result = await orchestrator.delegateToSubagent({
11926
- task: params.task,
11927
- type,
11928
- thoroughness,
11929
- parentSessionId
11930
- });
11931
- return result.summary;
11966
+ try {
11967
+ const result = await orchestrator.delegateToSubagent({
11968
+ task: params.task,
11969
+ type,
11970
+ thoroughness,
11971
+ parentSessionId
11972
+ });
11973
+ return result.summary;
11974
+ } catch (error) {
11975
+ const errorMessage = error instanceof Error ? error.message : String(error);
11976
+ throw new Error(`Failed to execute ${type} subagent: ${errorMessage}`);
11977
+ }
11932
11978
  },
11933
11979
  toolSchema: {
11934
11980
  name: "subagent_delegate",
@@ -12109,7 +12155,7 @@ function CliApp() {
12109
12155
  if (!isAuthenticated) {
12110
12156
  console.log("\u2139\uFE0F AI features disabled. Available commands: /login, /help, /config\n");
12111
12157
  const minimalSession = {
12112
- id: uuidv49(),
12158
+ id: uuidv410(),
12113
12159
  name: `Session ${(/* @__PURE__ */ new Date()).toLocaleString()}`,
12114
12160
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
12115
12161
  updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -12153,7 +12199,7 @@ function CliApp() {
12153
12199
  }
12154
12200
  llm.currentModel = modelInfo.id;
12155
12201
  const newSession = {
12156
- id: uuidv49(),
12202
+ id: uuidv410(),
12157
12203
  name: `Session ${(/* @__PURE__ */ new Date()).toLocaleString()}`,
12158
12204
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
12159
12205
  updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -12326,6 +12372,27 @@ Remember: Use context from previous messages to understand follow-up questions.$
12326
12372
  });
12327
12373
  agentContext.currentAgent = agent;
12328
12374
  agent.observationQueue = agentContext.observationQueue;
12375
+ const stepHandler = (step) => {
12376
+ const { pendingMessages, updatePendingMessage } = useCliStore.getState();
12377
+ const lastIdx = pendingMessages.length - 1;
12378
+ if (lastIdx >= 0 && pendingMessages[lastIdx].role === "assistant") {
12379
+ const existingSteps = pendingMessages[lastIdx].metadata?.steps || [];
12380
+ updatePendingMessage(lastIdx, {
12381
+ ...pendingMessages[lastIdx],
12382
+ metadata: {
12383
+ ...pendingMessages[lastIdx].metadata,
12384
+ steps: [...existingSteps, step]
12385
+ }
12386
+ });
12387
+ }
12388
+ };
12389
+ agent.on("action", stepHandler);
12390
+ orchestrator.setBeforeRunCallback((subagent, _subagentType) => {
12391
+ subagent.on("action", stepHandler);
12392
+ });
12393
+ orchestrator.setAfterRunCallback((subagent, _subagentType) => {
12394
+ subagent.off("action", stepHandler);
12395
+ });
12329
12396
  setState((prev) => ({
12330
12397
  ...prev,
12331
12398
  session: newSession,
@@ -12399,11 +12466,13 @@ Remember: Use context from previous messages to understand follow-up questions.$
12399
12466
  messageContent = multimodalMessage.content;
12400
12467
  }
12401
12468
  const userMessage = {
12469
+ id: uuidv410(),
12402
12470
  role: "user",
12403
12471
  content: userMessageContent,
12404
12472
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
12405
12473
  };
12406
12474
  const pendingAssistantMessage = {
12475
+ id: uuidv410(),
12407
12476
  role: "assistant",
12408
12477
  content: "...",
12409
12478
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
@@ -12434,7 +12503,10 @@ Remember: Use context from previous messages to understand follow-up questions.$
12434
12503
  const currentSession = useCliStore.getState().session;
12435
12504
  if (!currentSession) return;
12436
12505
  const updatedMessages = [...currentSession.messages];
12506
+ const lastMessage = updatedMessages[updatedMessages.length - 1];
12437
12507
  updatedMessages[updatedMessages.length - 1] = {
12508
+ id: lastMessage.id,
12509
+ // Preserve the original message ID
12438
12510
  role: "assistant",
12439
12511
  content: result.finalAnswer,
12440
12512
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
@@ -12525,6 +12597,15 @@ Remember: Use context from previous messages to understand follow-up questions.$
12525
12597
  }
12526
12598
  useCliStore.getState().setIsThinking(true);
12527
12599
  const currentSteps = [];
12600
+ const pendingAssistantMessage = {
12601
+ id: uuidv410(),
12602
+ role: "assistant",
12603
+ content: "...",
12604
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
12605
+ metadata: {
12606
+ steps: []
12607
+ }
12608
+ };
12528
12609
  const stepHandler = (step) => {
12529
12610
  currentSteps.push(step);
12530
12611
  const { pendingMessages, updatePendingMessage } = useCliStore.getState();
@@ -12549,18 +12630,11 @@ Remember: Use context from previous messages to understand follow-up questions.$
12549
12630
  userMessageContent = message;
12550
12631
  }
12551
12632
  const userMessage = {
12633
+ id: uuidv410(),
12552
12634
  role: "user",
12553
12635
  content: userMessageContent,
12554
12636
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
12555
12637
  };
12556
- const pendingAssistantMessage = {
12557
- role: "assistant",
12558
- content: "...",
12559
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
12560
- metadata: {
12561
- steps: []
12562
- }
12563
- };
12564
12638
  const sessionWithUserMessage = {
12565
12639
  ...state.session,
12566
12640
  messages: [...state.session.messages, userMessage],
@@ -12583,6 +12657,8 @@ Remember: Use context from previous messages to understand follow-up questions.$
12583
12657
  }
12584
12658
  const successfulToolCalls = result.steps.filter((s) => s.type === "observation").length;
12585
12659
  const finalAssistantMessage = {
12660
+ id: pendingAssistantMessage.id,
12661
+ // Preserve the original message ID
12586
12662
  role: "assistant",
12587
12663
  content: result.finalAnswer,
12588
12664
  timestamp: pendingAssistantMessage.timestamp,
@@ -12612,15 +12688,48 @@ Remember: Use context from previous messages to understand follow-up questions.$
12612
12688
  setStoreSession(updatedSession);
12613
12689
  await state.sessionStore.save(updatedSession);
12614
12690
  } catch (error) {
12615
- useCliStore.getState().clearPendingMessages();
12691
+ const errorMessage = error instanceof Error ? error.message : String(error);
12692
+ let displayMessage;
12616
12693
  if (error instanceof Error) {
12617
12694
  if (error.message.includes("Authentication failed") || error.message.includes("Authentication expired")) {
12618
- console.log("\n\u274C Authentication failed");
12619
- console.log("\u{1F4A1} Run /login to authenticate with your API environment.\n");
12620
- return;
12695
+ displayMessage = "\u274C Authentication failed\n\n\u{1F4A1} Run /login to authenticate with your API environment.";
12696
+ } else if (error.message.includes("socket hang up")) {
12697
+ displayMessage = `\u26A0\uFE0F Connection Error
12698
+
12699
+ ${errorMessage}
12700
+
12701
+ \u{1F4A1} This is usually a temporary issue. Please try your request again.`;
12702
+ } else {
12703
+ displayMessage = `\u274C Error
12704
+
12705
+ ${errorMessage}`;
12706
+ }
12707
+ } else {
12708
+ displayMessage = `\u274C Error
12709
+
12710
+ ${errorMessage}`;
12711
+ }
12712
+ const errorAssistantMessage = {
12713
+ id: pendingAssistantMessage.id,
12714
+ role: "assistant",
12715
+ content: displayMessage,
12716
+ timestamp: pendingAssistantMessage.timestamp,
12717
+ metadata: {
12718
+ steps: currentSteps
12719
+ // Include any steps that were completed before error
12621
12720
  }
12721
+ };
12722
+ useCliStore.getState().completePendingMessage(0, errorAssistantMessage);
12723
+ const currentSession = useCliStore.getState().session;
12724
+ if (currentSession) {
12725
+ const updatedSession = {
12726
+ ...currentSession,
12727
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
12728
+ };
12729
+ setState((prev) => ({ ...prev, session: updatedSession }));
12730
+ setStoreSession(updatedSession);
12731
+ await state.sessionStore.save(updatedSession);
12622
12732
  }
12623
- console.error("Error processing message:", error);
12624
12733
  } finally {
12625
12734
  state.agent.off("action", stepHandler);
12626
12735
  }
@@ -12644,11 +12753,13 @@ Remember: Use context from previous messages to understand follow-up questions.$
12644
12753
  isError = true;
12645
12754
  }
12646
12755
  const userMessage = {
12756
+ id: uuidv410(),
12647
12757
  role: "user",
12648
12758
  content: `$ ${command}`,
12649
12759
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
12650
12760
  };
12651
12761
  const assistantMessage = {
12762
+ id: uuidv410(),
12652
12763
  role: "assistant",
12653
12764
  content: isError ? `\u274C Error:
12654
12765
  ${output}` : output.trim() || "(no output)",
@@ -13059,7 +13170,7 @@ Custom Commands:
13059
13170
  console.clear();
13060
13171
  const model = state.session?.model || state.config?.defaultModel || "claude-sonnet";
13061
13172
  const newSession = {
13062
- id: uuidv49(),
13173
+ id: uuidv410(),
13063
13174
  name: `Session ${(/* @__PURE__ */ new Date()).toLocaleString()}`,
13064
13175
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
13065
13176
  updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  CurationArtifactType
4
- } from "./chunk-3OX632TE.js";
4
+ } from "./chunk-DJPXSSP4.js";
5
5
  import "./chunk-PDX44BCA.js";
6
6
 
7
7
  // ../../b4m-core/packages/services/dist/src/notebookCurationService/llmMarkdownGenerator.js
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  CurationArtifactType
4
- } from "./chunk-3OX632TE.js";
4
+ } from "./chunk-DJPXSSP4.js";
5
5
  import "./chunk-PDX44BCA.js";
6
6
 
7
7
  // ../../b4m-core/packages/services/dist/src/notebookCurationService/markdownGenerator.js
@@ -2,10 +2,10 @@
2
2
  import {
3
3
  findMostSimilarMemento,
4
4
  getRelevantMementos
5
- } from "./chunk-AKSB42HL.js";
6
- import "./chunk-T7NEJI2V.js";
5
+ } from "./chunk-GO75FMLY.js";
6
+ import "./chunk-GCVIRGIN.js";
7
7
  import "./chunk-AMDXHL6S.js";
8
- import "./chunk-3OX632TE.js";
8
+ import "./chunk-DJPXSSP4.js";
9
9
  import "./chunk-PDX44BCA.js";
10
10
  export {
11
11
  findMostSimilarMemento,
@@ -120,7 +120,7 @@ import {
120
120
  validateMermaidSyntax,
121
121
  warmUpSettingsCache,
122
122
  withRetry
123
- } from "./chunk-T7NEJI2V.js";
123
+ } from "./chunk-GCVIRGIN.js";
124
124
  import {
125
125
  Logger,
126
126
  NotificationDeduplicator,
@@ -129,7 +129,7 @@ import {
129
129
  postLowCreditsNotificationToSlack,
130
130
  postMessageToSlack
131
131
  } from "./chunk-AMDXHL6S.js";
132
- import "./chunk-3OX632TE.js";
132
+ import "./chunk-DJPXSSP4.js";
133
133
  import "./chunk-PDX44BCA.js";
134
134
  export {
135
135
  AWSBackend,
@@ -293,7 +293,7 @@ import {
293
293
  validateQuestMasterArtifactV2,
294
294
  validateReactArtifactV2,
295
295
  validateSvgArtifactV2
296
- } from "./chunk-3OX632TE.js";
296
+ } from "./chunk-DJPXSSP4.js";
297
297
  import "./chunk-PDX44BCA.js";
298
298
  export {
299
299
  ALL_IMAGE_MODELS,
@@ -2,10 +2,10 @@
2
2
  import {
3
3
  SubtractCreditsSchema,
4
4
  subtractCredits
5
- } from "./chunk-OX65IHIA.js";
6
- import "./chunk-T7NEJI2V.js";
5
+ } from "./chunk-VZU4Z7WI.js";
6
+ import "./chunk-GCVIRGIN.js";
7
7
  import "./chunk-AMDXHL6S.js";
8
- import "./chunk-3OX632TE.js";
8
+ import "./chunk-DJPXSSP4.js";
9
9
  import "./chunk-PDX44BCA.js";
10
10
  export {
11
11
  SubtractCreditsSchema,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bike4mind/cli",
3
- "version": "0.2.10-fix-extendend-thinking-with-tool-use.17269+e94200ce4",
3
+ "version": "0.2.10-fix-cli-socket-hangup-error-handling.17310+c525c3233",
4
4
  "type": "module",
5
5
  "description": "Interactive CLI tool for Bike4Mind with ReAct agents",
6
6
  "license": "UNLICENSED",
@@ -104,10 +104,10 @@
104
104
  },
105
105
  "devDependencies": {
106
106
  "@bike4mind/agents": "0.1.0",
107
- "@bike4mind/common": "2.39.1-fix-extendend-thinking-with-tool-use.17269+e94200ce4",
108
- "@bike4mind/mcp": "1.20.4-fix-extendend-thinking-with-tool-use.17269+e94200ce4",
109
- "@bike4mind/services": "2.34.2-fix-extendend-thinking-with-tool-use.17269+e94200ce4",
110
- "@bike4mind/utils": "2.1.4-fix-extendend-thinking-with-tool-use.17269+e94200ce4",
107
+ "@bike4mind/common": "2.39.1-fix-cli-socket-hangup-error-handling.17310+c525c3233",
108
+ "@bike4mind/mcp": "1.20.4-fix-cli-socket-hangup-error-handling.17310+c525c3233",
109
+ "@bike4mind/services": "2.34.2-fix-cli-socket-hangup-error-handling.17310+c525c3233",
110
+ "@bike4mind/utils": "2.1.4-fix-cli-socket-hangup-error-handling.17310+c525c3233",
111
111
  "@types/better-sqlite3": "^7.6.13",
112
112
  "@types/diff": "^5.0.9",
113
113
  "@types/jsonwebtoken": "^9.0.4",
@@ -120,5 +120,5 @@
120
120
  "typescript": "^5.9.3",
121
121
  "vitest": "^3.2.4"
122
122
  },
123
- "gitHead": "e94200ce4e993f1a05a29c6df68d05697e922ca1"
123
+ "gitHead": "c525c323364efcd1b2107413ac1aa8619f462124"
124
124
  }