@bike4mind/cli 0.2.10-fix-cli-duplicate-chat-history.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.
- package/dist/index.js +175 -50
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -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
|
|
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
|
-
)) : /* @__PURE__ */ React11.createElement(React11.Fragment, null, /* @__PURE__ */ React11.createElement(Static, { items: messages }, (message
|
|
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(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
|
-
|
|
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
|
-
|
|
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
|
|
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:
|
|
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:
|
|
2444
|
+
this.config = { ...DEFAULT_CONFIG, userId: uuidv42() };
|
|
2430
2445
|
await this.save();
|
|
2431
2446
|
return this.config;
|
|
2432
2447
|
}
|
|
@@ -4336,7 +4351,7 @@ var listFabFilesSchema = z86.object({
|
|
|
4336
4351
|
|
|
4337
4352
|
// ../../b4m-core/packages/services/dist/src/fabFileService/update.js
|
|
4338
4353
|
import mime from "mime-types";
|
|
4339
|
-
import { v4 as
|
|
4354
|
+
import { v4 as uuidv43 } from "uuid";
|
|
4340
4355
|
import { z as z87 } from "zod";
|
|
4341
4356
|
var updateFabFileSchema = z87.object({
|
|
4342
4357
|
id: z87.string(),
|
|
@@ -4457,7 +4472,7 @@ var editFabFileSchema = z98.object({
|
|
|
4457
4472
|
|
|
4458
4473
|
// ../../b4m-core/packages/services/dist/src/fabFileService/applyEdit.js
|
|
4459
4474
|
import mime2 from "mime-types";
|
|
4460
|
-
import { v4 as
|
|
4475
|
+
import { v4 as uuidv44 } from "uuid";
|
|
4461
4476
|
import { z as z99 } from "zod";
|
|
4462
4477
|
var applyEditSchema = z99.object({
|
|
4463
4478
|
id: z99.string(),
|
|
@@ -5285,7 +5300,7 @@ import { toFile } from "openai/uploads";
|
|
|
5285
5300
|
import { Readable } from "stream";
|
|
5286
5301
|
import { TranscribeClient, StartTranscriptionJobCommand, GetTranscriptionJobCommand, LanguageCode, MediaFormat } from "@aws-sdk/client-transcribe";
|
|
5287
5302
|
import { S3Client, PutObjectCommand, GetObjectCommand, DeleteObjectCommand } from "@aws-sdk/client-s3";
|
|
5288
|
-
import { v4 as
|
|
5303
|
+
import { v4 as uuidv45 } from "uuid";
|
|
5289
5304
|
|
|
5290
5305
|
// ../../b4m-core/packages/services/dist/src/emailIngestionService/processIngestedEmail.js
|
|
5291
5306
|
import { randomUUID as randomUUID5 } from "crypto";
|
|
@@ -5446,7 +5461,7 @@ var weatherTool = {
|
|
|
5446
5461
|
// ../../b4m-core/packages/services/dist/src/llm/tools/implementation/imageGeneration/index.js
|
|
5447
5462
|
import axios6 from "axios";
|
|
5448
5463
|
import { fileTypeFromBuffer as fileTypeFromBuffer2 } from "file-type";
|
|
5449
|
-
import { v4 as
|
|
5464
|
+
import { v4 as uuidv46 } from "uuid";
|
|
5450
5465
|
async function downloadImage(url) {
|
|
5451
5466
|
if (url.startsWith("data:image/")) {
|
|
5452
5467
|
const base64Data = url.split(",")[1];
|
|
@@ -5460,7 +5475,7 @@ async function processAndStoreImages(images, context) {
|
|
|
5460
5475
|
return Promise.all(images.map(async (image) => {
|
|
5461
5476
|
const buffer = await downloadImage(image);
|
|
5462
5477
|
const fileType = await fileTypeFromBuffer2(buffer);
|
|
5463
|
-
const filename = `${
|
|
5478
|
+
const filename = `${uuidv46()}.${fileType?.ext}`;
|
|
5464
5479
|
const path16 = await context.imageGenerateStorage.upload(buffer, filename, {});
|
|
5465
5480
|
return path16;
|
|
5466
5481
|
}));
|
|
@@ -6629,7 +6644,7 @@ Return only the edited content without any markdown code blocks or explanations.
|
|
|
6629
6644
|
// ../../b4m-core/packages/services/dist/src/llm/tools/implementation/imageEdit/index.js
|
|
6630
6645
|
import axios7 from "axios";
|
|
6631
6646
|
import { fileTypeFromBuffer as fileTypeFromBuffer3 } from "file-type";
|
|
6632
|
-
import { v4 as
|
|
6647
|
+
import { v4 as uuidv47 } from "uuid";
|
|
6633
6648
|
async function downloadImage2(url) {
|
|
6634
6649
|
if (url.startsWith("data:image/")) {
|
|
6635
6650
|
const base64Data = url.split(",")[1];
|
|
@@ -6673,7 +6688,7 @@ async function getImageFromFileId(fileId, context) {
|
|
|
6673
6688
|
async function processAndStoreImage(imageUrl, context) {
|
|
6674
6689
|
const buffer = await downloadImage2(imageUrl);
|
|
6675
6690
|
const fileType = await fileTypeFromBuffer3(buffer);
|
|
6676
|
-
const filename = `${
|
|
6691
|
+
const filename = `${uuidv47()}.${fileType?.ext}`;
|
|
6677
6692
|
const path16 = await context.imageGenerateStorage.upload(buffer, filename, {});
|
|
6678
6693
|
return path16;
|
|
6679
6694
|
}
|
|
@@ -9650,7 +9665,7 @@ var QuestStartBodySchema = z139.object({
|
|
|
9650
9665
|
// ../../b4m-core/packages/services/dist/src/llm/ImageGeneration.js
|
|
9651
9666
|
import axios8 from "axios";
|
|
9652
9667
|
import { fileTypeFromBuffer as fileTypeFromBuffer4 } from "file-type";
|
|
9653
|
-
import { v4 as
|
|
9668
|
+
import { v4 as uuidv48 } from "uuid";
|
|
9654
9669
|
import { z as z140 } from "zod";
|
|
9655
9670
|
import { fromZodError as fromZodError2 } from "zod-validation-error";
|
|
9656
9671
|
var ImageGenerationBodySchema = OpenAIImageGenerationInput.extend({
|
|
@@ -9671,7 +9686,7 @@ var ImageGenerationBodySchema = OpenAIImageGenerationInput.extend({
|
|
|
9671
9686
|
// ../../b4m-core/packages/services/dist/src/llm/ImageEdit.js
|
|
9672
9687
|
import axios9 from "axios";
|
|
9673
9688
|
import { fileTypeFromBuffer as fileTypeFromBuffer5 } from "file-type";
|
|
9674
|
-
import { v4 as
|
|
9689
|
+
import { v4 as uuidv49 } from "uuid";
|
|
9675
9690
|
import { z as z141 } from "zod";
|
|
9676
9691
|
import { fromZodError as fromZodError3 } from "zod-validation-error";
|
|
9677
9692
|
var ImageEditBodySchema = OpenAIImageGenerationInput.extend({
|
|
@@ -11217,7 +11232,7 @@ var ServerLlmBackend = class {
|
|
|
11217
11232
|
reject(error);
|
|
11218
11233
|
});
|
|
11219
11234
|
} catch (error) {
|
|
11220
|
-
logger.
|
|
11235
|
+
logger.debug(`LLM completion failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
11221
11236
|
if (isAxiosError(error)) {
|
|
11222
11237
|
logger.debug(
|
|
11223
11238
|
`[ServerLlmBackend] Axios error details: ${JSON.stringify({
|
|
@@ -11280,6 +11295,12 @@ var ServerLlmBackend = class {
|
|
|
11280
11295
|
reject(new Error("Cannot connect to Bike4Mind server. Please check your internet connection."));
|
|
11281
11296
|
} else if (error.message.includes("Rate limit exceeded")) {
|
|
11282
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
|
+
);
|
|
11283
11304
|
} else {
|
|
11284
11305
|
reject(new Error(`Failed to complete LLM request: ${error.message}`));
|
|
11285
11306
|
}
|
|
@@ -11512,7 +11533,7 @@ import { isAxiosError as isAxiosError2 } from "axios";
|
|
|
11512
11533
|
// package.json
|
|
11513
11534
|
var package_default = {
|
|
11514
11535
|
name: "@bike4mind/cli",
|
|
11515
|
-
version: "0.2.10-fix-cli-
|
|
11536
|
+
version: "0.2.10-fix-cli-socket-hangup-error-handling.17310+c525c3233",
|
|
11516
11537
|
type: "module",
|
|
11517
11538
|
description: "Interactive CLI tool for Bike4Mind with ReAct agents",
|
|
11518
11539
|
license: "UNLICENSED",
|
|
@@ -11616,10 +11637,10 @@ var package_default = {
|
|
|
11616
11637
|
},
|
|
11617
11638
|
devDependencies: {
|
|
11618
11639
|
"@bike4mind/agents": "0.1.0",
|
|
11619
|
-
"@bike4mind/common": "2.39.1-fix-cli-
|
|
11620
|
-
"@bike4mind/mcp": "1.20.4-fix-cli-
|
|
11621
|
-
"@bike4mind/services": "2.34.2-fix-cli-
|
|
11622
|
-
"@bike4mind/utils": "2.1.4-fix-cli-
|
|
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",
|
|
11623
11644
|
"@types/better-sqlite3": "^7.6.13",
|
|
11624
11645
|
"@types/diff": "^5.0.9",
|
|
11625
11646
|
"@types/jsonwebtoken": "^9.0.4",
|
|
@@ -11632,7 +11653,7 @@ var package_default = {
|
|
|
11632
11653
|
typescript: "^5.9.3",
|
|
11633
11654
|
vitest: "^3.2.4"
|
|
11634
11655
|
},
|
|
11635
|
-
gitHead: "
|
|
11656
|
+
gitHead: "c525c323364efcd1b2107413ac1aa8619f462124"
|
|
11636
11657
|
};
|
|
11637
11658
|
|
|
11638
11659
|
// src/config/constants.ts
|
|
@@ -11643,8 +11664,24 @@ var USAGE_CACHE_TTL = 5 * 60 * 1e3;
|
|
|
11643
11664
|
// src/agents/SubagentOrchestrator.ts
|
|
11644
11665
|
var SubagentOrchestrator = class {
|
|
11645
11666
|
constructor(deps) {
|
|
11667
|
+
this.beforeRunCallback = null;
|
|
11668
|
+
this.afterRunCallback = null;
|
|
11646
11669
|
this.deps = deps;
|
|
11647
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
|
+
}
|
|
11648
11685
|
/**
|
|
11649
11686
|
* Delegate a task to a specialized subagent
|
|
11650
11687
|
*
|
|
@@ -11694,11 +11731,29 @@ var SubagentOrchestrator = class {
|
|
|
11694
11731
|
systemPrompt: config.systemPrompt || this.getDefaultSystemPrompt(type)
|
|
11695
11732
|
});
|
|
11696
11733
|
updatedContext.currentAgent = subagent;
|
|
11734
|
+
if (this.beforeRunCallback) {
|
|
11735
|
+
this.beforeRunCallback(subagent, type);
|
|
11736
|
+
}
|
|
11697
11737
|
const startTime = Date.now();
|
|
11698
|
-
|
|
11699
|
-
|
|
11700
|
-
|
|
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
|
+
}
|
|
11701
11753
|
const duration = Date.now() - startTime;
|
|
11754
|
+
if (this.afterRunCallback) {
|
|
11755
|
+
this.afterRunCallback(subagent, type);
|
|
11756
|
+
}
|
|
11702
11757
|
this.deps.logger.debug(
|
|
11703
11758
|
`Subagent completed in ${duration}ms, ${result.completionInfo.iterations} iterations, ${result.completionInfo.totalTokens} tokens`
|
|
11704
11759
|
);
|
|
@@ -11908,13 +11963,18 @@ function createSubagentDelegateTool(orchestrator, parentSessionId) {
|
|
|
11908
11963
|
}
|
|
11909
11964
|
const thoroughness = params.thoroughness || "medium";
|
|
11910
11965
|
const type = params.type;
|
|
11911
|
-
|
|
11912
|
-
|
|
11913
|
-
|
|
11914
|
-
|
|
11915
|
-
|
|
11916
|
-
|
|
11917
|
-
|
|
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
|
+
}
|
|
11918
11978
|
},
|
|
11919
11979
|
toolSchema: {
|
|
11920
11980
|
name: "subagent_delegate",
|
|
@@ -12095,7 +12155,7 @@ function CliApp() {
|
|
|
12095
12155
|
if (!isAuthenticated) {
|
|
12096
12156
|
console.log("\u2139\uFE0F AI features disabled. Available commands: /login, /help, /config\n");
|
|
12097
12157
|
const minimalSession = {
|
|
12098
|
-
id:
|
|
12158
|
+
id: uuidv410(),
|
|
12099
12159
|
name: `Session ${(/* @__PURE__ */ new Date()).toLocaleString()}`,
|
|
12100
12160
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
12101
12161
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -12139,7 +12199,7 @@ function CliApp() {
|
|
|
12139
12199
|
}
|
|
12140
12200
|
llm.currentModel = modelInfo.id;
|
|
12141
12201
|
const newSession = {
|
|
12142
|
-
id:
|
|
12202
|
+
id: uuidv410(),
|
|
12143
12203
|
name: `Session ${(/* @__PURE__ */ new Date()).toLocaleString()}`,
|
|
12144
12204
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
12145
12205
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -12312,6 +12372,27 @@ Remember: Use context from previous messages to understand follow-up questions.$
|
|
|
12312
12372
|
});
|
|
12313
12373
|
agentContext.currentAgent = agent;
|
|
12314
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
|
+
});
|
|
12315
12396
|
setState((prev) => ({
|
|
12316
12397
|
...prev,
|
|
12317
12398
|
session: newSession,
|
|
@@ -12385,11 +12466,13 @@ Remember: Use context from previous messages to understand follow-up questions.$
|
|
|
12385
12466
|
messageContent = multimodalMessage.content;
|
|
12386
12467
|
}
|
|
12387
12468
|
const userMessage = {
|
|
12469
|
+
id: uuidv410(),
|
|
12388
12470
|
role: "user",
|
|
12389
12471
|
content: userMessageContent,
|
|
12390
12472
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
12391
12473
|
};
|
|
12392
12474
|
const pendingAssistantMessage = {
|
|
12475
|
+
id: uuidv410(),
|
|
12393
12476
|
role: "assistant",
|
|
12394
12477
|
content: "...",
|
|
12395
12478
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -12420,7 +12503,10 @@ Remember: Use context from previous messages to understand follow-up questions.$
|
|
|
12420
12503
|
const currentSession = useCliStore.getState().session;
|
|
12421
12504
|
if (!currentSession) return;
|
|
12422
12505
|
const updatedMessages = [...currentSession.messages];
|
|
12506
|
+
const lastMessage = updatedMessages[updatedMessages.length - 1];
|
|
12423
12507
|
updatedMessages[updatedMessages.length - 1] = {
|
|
12508
|
+
id: lastMessage.id,
|
|
12509
|
+
// Preserve the original message ID
|
|
12424
12510
|
role: "assistant",
|
|
12425
12511
|
content: result.finalAnswer,
|
|
12426
12512
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -12511,6 +12597,15 @@ Remember: Use context from previous messages to understand follow-up questions.$
|
|
|
12511
12597
|
}
|
|
12512
12598
|
useCliStore.getState().setIsThinking(true);
|
|
12513
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
|
+
};
|
|
12514
12609
|
const stepHandler = (step) => {
|
|
12515
12610
|
currentSteps.push(step);
|
|
12516
12611
|
const { pendingMessages, updatePendingMessage } = useCliStore.getState();
|
|
@@ -12535,18 +12630,11 @@ Remember: Use context from previous messages to understand follow-up questions.$
|
|
|
12535
12630
|
userMessageContent = message;
|
|
12536
12631
|
}
|
|
12537
12632
|
const userMessage = {
|
|
12633
|
+
id: uuidv410(),
|
|
12538
12634
|
role: "user",
|
|
12539
12635
|
content: userMessageContent,
|
|
12540
12636
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
12541
12637
|
};
|
|
12542
|
-
const pendingAssistantMessage = {
|
|
12543
|
-
role: "assistant",
|
|
12544
|
-
content: "...",
|
|
12545
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
12546
|
-
metadata: {
|
|
12547
|
-
steps: []
|
|
12548
|
-
}
|
|
12549
|
-
};
|
|
12550
12638
|
const sessionWithUserMessage = {
|
|
12551
12639
|
...state.session,
|
|
12552
12640
|
messages: [...state.session.messages, userMessage],
|
|
@@ -12569,6 +12657,8 @@ Remember: Use context from previous messages to understand follow-up questions.$
|
|
|
12569
12657
|
}
|
|
12570
12658
|
const successfulToolCalls = result.steps.filter((s) => s.type === "observation").length;
|
|
12571
12659
|
const finalAssistantMessage = {
|
|
12660
|
+
id: pendingAssistantMessage.id,
|
|
12661
|
+
// Preserve the original message ID
|
|
12572
12662
|
role: "assistant",
|
|
12573
12663
|
content: result.finalAnswer,
|
|
12574
12664
|
timestamp: pendingAssistantMessage.timestamp,
|
|
@@ -12598,15 +12688,48 @@ Remember: Use context from previous messages to understand follow-up questions.$
|
|
|
12598
12688
|
setStoreSession(updatedSession);
|
|
12599
12689
|
await state.sessionStore.save(updatedSession);
|
|
12600
12690
|
} catch (error) {
|
|
12601
|
-
|
|
12691
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
12692
|
+
let displayMessage;
|
|
12602
12693
|
if (error instanceof Error) {
|
|
12603
12694
|
if (error.message.includes("Authentication failed") || error.message.includes("Authentication expired")) {
|
|
12604
|
-
|
|
12605
|
-
|
|
12606
|
-
|
|
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}`;
|
|
12607
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
|
|
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);
|
|
12608
12732
|
}
|
|
12609
|
-
console.error("Error processing message:", error);
|
|
12610
12733
|
} finally {
|
|
12611
12734
|
state.agent.off("action", stepHandler);
|
|
12612
12735
|
}
|
|
@@ -12630,11 +12753,13 @@ Remember: Use context from previous messages to understand follow-up questions.$
|
|
|
12630
12753
|
isError = true;
|
|
12631
12754
|
}
|
|
12632
12755
|
const userMessage = {
|
|
12756
|
+
id: uuidv410(),
|
|
12633
12757
|
role: "user",
|
|
12634
12758
|
content: `$ ${command}`,
|
|
12635
12759
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
12636
12760
|
};
|
|
12637
12761
|
const assistantMessage = {
|
|
12762
|
+
id: uuidv410(),
|
|
12638
12763
|
role: "assistant",
|
|
12639
12764
|
content: isError ? `\u274C Error:
|
|
12640
12765
|
${output}` : output.trim() || "(no output)",
|
|
@@ -13045,7 +13170,7 @@ Custom Commands:
|
|
|
13045
13170
|
console.clear();
|
|
13046
13171
|
const model = state.session?.model || state.config?.defaultModel || "claude-sonnet";
|
|
13047
13172
|
const newSession = {
|
|
13048
|
-
id:
|
|
13173
|
+
id: uuidv410(),
|
|
13049
13174
|
name: `Session ${(/* @__PURE__ */ new Date()).toLocaleString()}`,
|
|
13050
13175
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
13051
13176
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bike4mind/cli",
|
|
3
|
-
"version": "0.2.10-fix-cli-
|
|
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-cli-
|
|
108
|
-
"@bike4mind/mcp": "1.20.4-fix-cli-
|
|
109
|
-
"@bike4mind/services": "2.34.2-fix-cli-
|
|
110
|
-
"@bike4mind/utils": "2.1.4-fix-cli-
|
|
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": "
|
|
123
|
+
"gitHead": "c525c323364efcd1b2107413ac1aa8619f462124"
|
|
124
124
|
}
|