blun-king-cli 4.0.1 → 4.1.1
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/bin/blun.js +53 -13
- package/package.json +1 -1
package/bin/blun.js
CHANGED
|
@@ -114,6 +114,7 @@ function apiCall(method, endpoint, body) {
|
|
|
114
114
|
|
|
115
115
|
// ── Chat History ──
|
|
116
116
|
var chatHistory = [];
|
|
117
|
+
var lastCreatedFiles = []; // Track files from last response for follow-up context
|
|
117
118
|
|
|
118
119
|
// ── Print Helpers ──
|
|
119
120
|
function printHeader() {
|
|
@@ -637,15 +638,21 @@ async function sendChat(message) {
|
|
|
637
638
|
var headerPrinted = false;
|
|
638
639
|
|
|
639
640
|
try {
|
|
641
|
+
// Include last created files as context for follow-ups
|
|
642
|
+
var contextMsg = message;
|
|
643
|
+
if (lastCreatedFiles.length > 0) {
|
|
644
|
+
contextMsg = message + "\n\n[Kontext: Zuletzt erstellte Dateien im Ordner " + config.workdir + ": " +
|
|
645
|
+
lastCreatedFiles.map(function(f) { return f.name; }).join(", ") + "]";
|
|
646
|
+
}
|
|
640
647
|
var stream = await apiStreamCall("/chat/stream", {
|
|
641
|
-
message:
|
|
648
|
+
message: contextMsg,
|
|
642
649
|
workdir: config.workdir,
|
|
643
650
|
history: chatHistory.slice(-10)
|
|
644
651
|
});
|
|
645
652
|
|
|
646
|
-
// Collect tokens silently — only update thinking animation
|
|
647
653
|
var buffer = "";
|
|
648
654
|
var streamMeta = {};
|
|
655
|
+
var headerShown = false;
|
|
649
656
|
|
|
650
657
|
await new Promise(function(resolve, reject) {
|
|
651
658
|
stream.on("data", function(chunk) {
|
|
@@ -662,16 +669,44 @@ async function sendChat(message) {
|
|
|
662
669
|
var dataStr = lines[i].trim().slice(6);
|
|
663
670
|
try {
|
|
664
671
|
var eventData = JSON.parse(dataStr);
|
|
665
|
-
|
|
666
|
-
if (eventType === "meta")
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
672
|
+
|
|
673
|
+
if (eventType === "meta") {
|
|
674
|
+
streamMeta = eventData;
|
|
675
|
+
// Stop thinking, show header
|
|
676
|
+
clearInterval(thinkTimer);
|
|
677
|
+
process.stdout.write("\r\x1b[2K");
|
|
678
|
+
console.log("");
|
|
679
|
+
console.log(C.green + C.bold + " " + BOX.bot + " BLUN King" + C.reset +
|
|
680
|
+
C.gray + " " + BOX.dot + " " + (eventData.task_type || "") + "/" + (eventData.role || "") + C.reset);
|
|
681
|
+
console.log(C.green + " " + BOX.h.repeat(40) + C.reset);
|
|
682
|
+
process.stdout.write(" ");
|
|
683
|
+
headerShown = true;
|
|
684
|
+
}
|
|
685
|
+
else if (eventType === "token") {
|
|
686
|
+
fullAnswer += eventData.text;
|
|
687
|
+
// Live output — write token directly
|
|
688
|
+
process.stdout.write(eventData.text);
|
|
689
|
+
}
|
|
690
|
+
else if (eventType === "retry") {
|
|
691
|
+
fullAnswer = "";
|
|
692
|
+
process.stdout.write("\n" + C.yellow + " \u21BB retry..." + C.reset + "\n ");
|
|
693
|
+
}
|
|
694
|
+
else if (eventType === "tool") {
|
|
695
|
+
process.stdout.write("\n" + C.cyan + " \u2699 " + eventData.name + C.reset);
|
|
696
|
+
if (eventData.args && eventData.args.name) process.stdout.write(C.dim + " " + eventData.args.name + C.reset);
|
|
697
|
+
process.stdout.write("\n ");
|
|
698
|
+
}
|
|
699
|
+
else if (eventType === "files") {
|
|
700
|
+
receivedFiles = eventData.files || [];
|
|
701
|
+
}
|
|
670
702
|
else if (eventType === "done") {
|
|
671
703
|
meta = (streamMeta.task_type || "") + "/" + (streamMeta.role || "") + " " + BOX.dot +
|
|
672
704
|
" score: " + ((eventData.quality || {}).score || "?") +
|
|
673
705
|
(eventData.status ? " " + BOX.dot + " " + eventData.status : "");
|
|
674
706
|
}
|
|
707
|
+
else if (eventType === "error") {
|
|
708
|
+
process.stdout.write("\n" + C.red + " ERROR: " + eventData.error + C.reset + "\n");
|
|
709
|
+
}
|
|
675
710
|
} catch(e) {}
|
|
676
711
|
}
|
|
677
712
|
}
|
|
@@ -682,11 +717,14 @@ async function sendChat(message) {
|
|
|
682
717
|
stream.on("error", function(e) { reject(e); });
|
|
683
718
|
});
|
|
684
719
|
|
|
685
|
-
//
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
720
|
+
// Finish streaming output
|
|
721
|
+
if (!headerShown) {
|
|
722
|
+
clearInterval(thinkTimer);
|
|
723
|
+
process.stdout.write("\r\x1b[2K");
|
|
724
|
+
}
|
|
725
|
+
console.log("\n");
|
|
726
|
+
if (meta) console.log(C.dim + " " + meta + C.reset);
|
|
727
|
+
console.log("");
|
|
690
728
|
|
|
691
729
|
} catch(streamErr) {
|
|
692
730
|
// Fallback to non-streaming
|
|
@@ -727,7 +765,8 @@ async function sendChat(message) {
|
|
|
727
765
|
|
|
728
766
|
// ── Save received files to local workdir ──
|
|
729
767
|
if (receivedFiles.length > 0) {
|
|
730
|
-
console.log(C.green + "
|
|
768
|
+
console.log(C.green + " \uD83D\uDCC1 Dateien gespeichert:" + C.reset);
|
|
769
|
+
lastCreatedFiles = [];
|
|
731
770
|
for (var fi = 0; fi < receivedFiles.length; fi++) {
|
|
732
771
|
var f = receivedFiles[fi];
|
|
733
772
|
if (f.content && f.name) {
|
|
@@ -736,6 +775,7 @@ async function sendChat(message) {
|
|
|
736
775
|
if (!fs.existsSync(localDir)) fs.mkdirSync(localDir, { recursive: true });
|
|
737
776
|
fs.writeFileSync(localPath, f.content, "utf8");
|
|
738
777
|
console.log(" " + C.brightCyan + localPath + C.reset + C.dim + " (" + f.size + " bytes)" + C.reset);
|
|
778
|
+
lastCreatedFiles.push({ name: f.name, path: localPath, size: f.size });
|
|
739
779
|
}
|
|
740
780
|
}
|
|
741
781
|
console.log("");
|