@robinpath/cli 1.95.0 → 1.97.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.
- package/dist/cli.mjs +41 -14
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -18598,7 +18598,7 @@ function getNativeModules() {
|
|
|
18598
18598
|
import { join as join3, basename as basename2 } from "node:path";
|
|
18599
18599
|
import { homedir as homedir2, platform as platform2 } from "node:os";
|
|
18600
18600
|
import { existsSync as existsSync2 } from "node:fs";
|
|
18601
|
-
var CLI_VERSION = true ? "1.
|
|
18601
|
+
var CLI_VERSION = true ? "1.97.0" : "1.97.0";
|
|
18602
18602
|
var FLAG_QUIET = false;
|
|
18603
18603
|
var FLAG_VERBOSE = false;
|
|
18604
18604
|
var FLAG_AUTO_ACCEPT = false;
|
|
@@ -21884,6 +21884,14 @@ async function fetchBrainContext(prompt) {
|
|
|
21884
21884
|
}
|
|
21885
21885
|
async function fetchBrainStream(prompt, { onToken, conversationHistory, provider, model, apiKey, cliContext } = {}) {
|
|
21886
21886
|
try {
|
|
21887
|
+
let resetReadTimer2 = function() {
|
|
21888
|
+
if (readTimer) clearTimeout(readTimer);
|
|
21889
|
+
readTimer = setTimeout(() => {
|
|
21890
|
+
logVerbose("Stream read timeout \u2014 aborting");
|
|
21891
|
+
controller.abort();
|
|
21892
|
+
}, 1e4);
|
|
21893
|
+
};
|
|
21894
|
+
var resetReadTimer = resetReadTimer2;
|
|
21887
21895
|
const body = {
|
|
21888
21896
|
prompt,
|
|
21889
21897
|
topK: 10,
|
|
@@ -21896,11 +21904,13 @@ async function fetchBrainStream(prompt, { onToken, conversationHistory, provider
|
|
|
21896
21904
|
if (conversationHistory && conversationHistory.length > 0) {
|
|
21897
21905
|
body.conversationHistory = conversationHistory;
|
|
21898
21906
|
}
|
|
21907
|
+
const controller = new AbortController();
|
|
21908
|
+
const timeout = setTimeout(() => controller.abort(), 3e4);
|
|
21899
21909
|
const response = await fetch(`${AI_BRAIN_URL}/docs/generate`, {
|
|
21900
21910
|
method: "POST",
|
|
21901
21911
|
headers: { "Content-Type": "application/json" },
|
|
21902
21912
|
body: JSON.stringify(body),
|
|
21903
|
-
signal:
|
|
21913
|
+
signal: controller.signal
|
|
21904
21914
|
});
|
|
21905
21915
|
if (!response.ok) {
|
|
21906
21916
|
logVerbose("Brain stream returned", response.status);
|
|
@@ -21913,20 +21923,20 @@ async function fetchBrainStream(prompt, { onToken, conversationHistory, provider
|
|
|
21913
21923
|
const reader = response.body.getReader();
|
|
21914
21924
|
const decoder = new TextDecoder();
|
|
21915
21925
|
let buffer = "";
|
|
21916
|
-
|
|
21926
|
+
let readTimer = null;
|
|
21927
|
+
resetReadTimer2();
|
|
21917
21928
|
while (true) {
|
|
21918
|
-
|
|
21919
|
-
|
|
21920
|
-
|
|
21921
|
-
|
|
21922
|
-
|
|
21923
|
-
|
|
21924
|
-
|
|
21925
|
-
reader.cancel();
|
|
21926
|
-
} catch {
|
|
21927
|
-
}
|
|
21929
|
+
let done;
|
|
21930
|
+
let value;
|
|
21931
|
+
try {
|
|
21932
|
+
const result = await reader.read();
|
|
21933
|
+
done = result.done;
|
|
21934
|
+
value = result.value;
|
|
21935
|
+
} catch {
|
|
21928
21936
|
break;
|
|
21929
21937
|
}
|
|
21938
|
+
if (done) break;
|
|
21939
|
+
resetReadTimer2();
|
|
21930
21940
|
buffer += decoder.decode(value, { stream: true });
|
|
21931
21941
|
const events = buffer.split("\n\n");
|
|
21932
21942
|
buffer = events.pop() || "";
|
|
@@ -21956,8 +21966,16 @@ async function fetchBrainStream(prompt, { onToken, conversationHistory, provider
|
|
|
21956
21966
|
}
|
|
21957
21967
|
} else if (eventType === "done") {
|
|
21958
21968
|
doneData = parsed;
|
|
21969
|
+
if (readTimer) clearTimeout(readTimer);
|
|
21970
|
+
clearTimeout(timeout);
|
|
21959
21971
|
} else if (eventType === "error") {
|
|
21972
|
+
if (readTimer) clearTimeout(readTimer);
|
|
21973
|
+
clearTimeout(timeout);
|
|
21960
21974
|
logVerbose("Brain stream error:", parsed.message);
|
|
21975
|
+
try {
|
|
21976
|
+
reader.cancel();
|
|
21977
|
+
} catch {
|
|
21978
|
+
}
|
|
21961
21979
|
return {
|
|
21962
21980
|
code: fullText,
|
|
21963
21981
|
sources: metadata?.sources || [],
|
|
@@ -21971,6 +21989,12 @@ async function fetchBrainStream(prompt, { onToken, conversationHistory, provider
|
|
|
21971
21989
|
}
|
|
21972
21990
|
}
|
|
21973
21991
|
}
|
|
21992
|
+
if (readTimer) clearTimeout(readTimer);
|
|
21993
|
+
clearTimeout(timeout);
|
|
21994
|
+
try {
|
|
21995
|
+
reader.cancel();
|
|
21996
|
+
} catch {
|
|
21997
|
+
}
|
|
21974
21998
|
return {
|
|
21975
21999
|
code: fullText,
|
|
21976
22000
|
sources: metadata?.sources || [],
|
|
@@ -24764,7 +24788,7 @@ Type / to see available commands.`;
|
|
|
24764
24788
|
const activeModel = readAiConfig().model || this.model;
|
|
24765
24789
|
const activeKey = readAiConfig().apiKey || this.apiKey;
|
|
24766
24790
|
const activeProvider = this.resolveProvider(activeKey);
|
|
24767
|
-
for (let loop = 0; loop <
|
|
24791
|
+
for (let loop = 0; loop < 5; loop++) {
|
|
24768
24792
|
let fullText = "";
|
|
24769
24793
|
const result = await fetchBrainStream(
|
|
24770
24794
|
loop === 0 ? expanded : this.conversationMessages[this.conversationMessages.length - 1].content,
|
|
@@ -24816,6 +24840,8 @@ Type / to see available commands.`;
|
|
|
24816
24840
|
finalResponse = cleaned || fullText;
|
|
24817
24841
|
break;
|
|
24818
24842
|
}
|
|
24843
|
+
ui?.setStreaming("");
|
|
24844
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
24819
24845
|
if (cleaned) ui?.addMessage(cleaned);
|
|
24820
24846
|
const cmdResults = [];
|
|
24821
24847
|
for (const cmd of commands) {
|
|
@@ -24856,6 +24882,7 @@ ${lines.slice(-5).join("\n")}`,
|
|
|
24856
24882
|
${summary}` });
|
|
24857
24883
|
ui?.setStreaming("");
|
|
24858
24884
|
finalResponse = "";
|
|
24885
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
24859
24886
|
}
|
|
24860
24887
|
} catch (err) {
|
|
24861
24888
|
finalResponse = `\u26A0 Error: ${err.message}`;
|