dsh-neotui 0.0.6 → 0.0.7
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/package.json +1 -1
- package/src/views.js +20 -22
package/package.json
CHANGED
package/src/views.js
CHANGED
|
@@ -111,12 +111,12 @@ function diffText(oldText, newText, width) {
|
|
|
111
111
|
|
|
112
112
|
// ---- Chat node model ----
|
|
113
113
|
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
/** Apply ONE event onto a mutable nodes array (shared by full-window
|
|
115
|
+
* derivation and the incremental mux merge — the two paths must agree). */
|
|
116
|
+
function applyEvent(nodes, event, view, log) {
|
|
116
117
|
const cur = () => nodes[nodes.length - 1];
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
switch (event.type) {
|
|
118
|
+
const d = event.data ?? {};
|
|
119
|
+
switch (event.type) {
|
|
120
120
|
case "user/message": {
|
|
121
121
|
const text = partsToText(d.content ?? d.message?.content);
|
|
122
122
|
const images = partsToImages(d.content ?? d.message?.content);
|
|
@@ -238,7 +238,12 @@ function nodeForEvents(events, log) {
|
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
|
-
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** Re-derive the whole node list from a complete event window (open/poll). */
|
|
244
|
+
function nodeForEvents(events, log) {
|
|
245
|
+
const nodes = [];
|
|
246
|
+
for (const { event, view } of events) applyEvent(nodes, event, view, log);
|
|
242
247
|
return nodes;
|
|
243
248
|
}
|
|
244
249
|
|
|
@@ -557,23 +562,13 @@ export class ChatView extends Widget {
|
|
|
557
562
|
}
|
|
558
563
|
|
|
559
564
|
/** Queue a rebuild; flushed on the next frame render (throttles streaming). */
|
|
560
|
-
/** Merge freshly arrived events (mux frames
|
|
565
|
+
/** Merge freshly arrived events (mux frames) into the tail INCREMENTALLY —
|
|
566
|
+
* each event mutates this.nodes directly via the same applyEvent the
|
|
567
|
+
* full-window re-derivation uses, so a lone reasoning-delta appends to the
|
|
568
|
+
* existing block instead of wiping it (the old "shows then deleted" bug). */
|
|
561
569
|
mergeEvents(entries) {
|
|
562
|
-
const
|
|
563
|
-
|
|
564
|
-
const last = nodes[nodes.length - 1];
|
|
565
|
-
const mine = this.nodes[this.nodes.length - 1];
|
|
566
|
-
// Only merge into the ACTIVE streaming node; a newly started turn is pushed
|
|
567
|
-
// as its own node (merging into a finalized turn would overwrite it).
|
|
568
|
-
if (last.kind === "assistant" && mine && mine.kind === "assistant" && mine.streaming) {
|
|
569
|
-
mine.blocks = last.blocks;
|
|
570
|
-
mine.images = last.images ?? mine.images;
|
|
571
|
-
mine.id = last.id ?? mine.id;
|
|
572
|
-
mine.streaming = last.streaming;
|
|
573
|
-
mine.finalized = false;
|
|
574
|
-
} else {
|
|
575
|
-
this.nodes.push(...nodes);
|
|
576
|
-
this.expanded.add(this.nodes.length - 1);
|
|
570
|
+
for (const { event, view } of entries) {
|
|
571
|
+
applyEvent(this.nodes, event, view, this.app.log);
|
|
577
572
|
}
|
|
578
573
|
this.running = this.nodes.some((n) => n.kind === "assistant" && n.streaming);
|
|
579
574
|
this.queueRebuild();
|
|
@@ -737,6 +732,9 @@ export class ChatView extends Widget {
|
|
|
737
732
|
this.nodes = [{ kind: "system", text: `加载失败: ${e.message}` }];
|
|
738
733
|
}
|
|
739
734
|
this.#rebuild();
|
|
735
|
+
// Jump to the LIVE tail (the newest content) on open — the view would
|
|
736
|
+
// otherwise sit at the top showing the oldest turns.
|
|
737
|
+
this.view.scrollY = this.view.maxScroll();
|
|
740
738
|
}
|
|
741
739
|
|
|
742
740
|
async loadOlder() {
|