paseo-dsh 0.2.14 → 0.2.16

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,5 +1,5 @@
1
1
  import type { PluginClientContext, PluginTimelineItemProps } from "@getpaseo/plugin/client";
2
- import { useState } from "react";
2
+ import { Fragment, useState } from "react";
3
3
  import { Pressable, Text, View } from "react-native";
4
4
  import { z } from "zod";
5
5
 
@@ -32,14 +32,19 @@ function formatNumber(value: number): string {
32
32
  return String(Math.round(value)).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
33
33
  }
34
34
 
35
- function contextLine(data: StreamStats): string | undefined {
35
+ function contextRatio(data: StreamStats): number | undefined {
36
36
  if (data.contextUsed === undefined || data.contextMax === undefined || data.contextMax <= 0) {
37
37
  return undefined;
38
38
  }
39
- const ratio = Math.max(0, Math.min(1, data.contextUsed / data.contextMax));
39
+ return Math.max(0, Math.min(1, data.contextUsed / data.contextMax));
40
+ }
41
+
42
+ function contextLine(data: StreamStats): string | undefined {
43
+ const ratio = contextRatio(data);
44
+ if (ratio === undefined) return undefined;
40
45
  const filled = Math.round(ratio * 10);
41
46
  const bar = `${"█".repeat(filled)}${"░".repeat(10 - filled)}`;
42
- return `上下文 ${formatNumber(data.contextUsed)} / ${formatNumber(data.contextMax)} ${bar} ${Math.round(ratio * 100)}%`;
47
+ return `上下文 ${formatNumber(data.contextUsed ?? 0)} / ${formatNumber(data.contextMax ?? 0)} ${bar} ${Math.round(ratio * 100)}%`;
43
48
  }
44
49
 
45
50
  function tokensLine(data: StreamStats): string | undefined {
@@ -62,30 +67,36 @@ function toolsLine(data: StreamStats): string | undefined {
62
67
  return `工具 ${data.toolCalls} 次${duration}`;
63
68
  }
64
69
 
65
- /** One muted line under an answer; tap to expand the full picture. */
70
+ /** One compact line under an answer; tap to expand the full picture. */
66
71
  function StreamStatsRow({ item, theme, layout }: PluginTimelineItemProps<StreamStats>) {
67
72
  const [open, setOpen] = useState(false);
68
73
  const data = item.data;
69
- const summary: string[] = [];
74
+ const fontSize = layout.compact ? 10 : 11;
75
+ const muted = theme.colors.foregroundMuted;
76
+ const base = { color: muted, fontSize, fontVariant: ["tabular-nums"] as const };
77
+
78
+ const ratio = contextRatio(data);
79
+ const segments: Array<{ text: string; color: string }> = [];
70
80
  if (data.turns !== undefined && data.steps !== undefined) {
71
- summary.push(`${data.turns} 轮 ${data.steps} 步`);
81
+ segments.push({ text: `${data.turns} 轮 ${data.steps} 步`, color: muted });
82
+ }
83
+ if (data.firstTokenMs !== undefined) {
84
+ segments.push({ text: `首字 ${formatLatency(data.firstTokenMs)}`, color: muted });
72
85
  }
73
- if (data.firstTokenMs !== undefined) summary.push(`首字 ${formatLatency(data.firstTokenMs)}`);
74
- if (data.tokensPerSecond !== undefined) summary.push(`${Math.round(data.tokensPerSecond)} tok/s`);
75
- if (data.contextUsed !== undefined && data.contextMax !== undefined && data.contextMax > 0) {
76
- summary.push(`上下文 ${Math.round(Math.min(1, data.contextUsed / data.contextMax) * 100)}%`);
86
+ if (data.tokensPerSecond !== undefined) {
87
+ segments.push({ text: `${Math.round(data.tokensPerSecond)} tok/s`, color: muted });
77
88
  }
78
- if (data.cacheHit !== undefined) summary.push(`缓存命中 ${Math.round(data.cacheHit * 100)}%`);
79
- if (summary.length === 0 && data.firstTokenMs !== undefined) {
80
- summary.push(`首字 ${formatLatency(data.firstTokenMs)}`);
89
+ if (ratio !== undefined) {
90
+ segments.push({ text: `上下文 ${Math.round(ratio * 100)}%`, color: muted });
81
91
  }
82
- if (summary.length === 0) return null;
92
+ if (data.cacheHit !== undefined) {
93
+ segments.push({ text: `缓存命中 ${Math.round(data.cacheHit * 100)}%`, color: muted });
94
+ }
95
+ if (segments.length === 0) return null;
83
96
 
84
97
  const details = [contextLine(data), tokensLine(data), routeLine(data), toolsLine(data)].filter(
85
98
  (line): line is string => line !== undefined,
86
99
  );
87
- const fontSize = layout.compact ? 10 : 11;
88
- const muted = { color: theme.colors.foregroundMuted, fontSize };
89
100
 
90
101
  return (
91
102
  <Pressable
@@ -94,14 +105,19 @@ function StreamStatsRow({ item, theme, layout }: PluginTimelineItemProps<StreamS
94
105
  onPress={() => setOpen((value) => !value)}
95
106
  style={{ alignSelf: "flex-start", marginTop: 0, marginBottom: 0, paddingLeft: 2 }}
96
107
  >
97
- <View style={{ flexDirection: "row", alignItems: "center", gap: 6 }}>
98
- <Text style={muted}>{summary.join(" · ")}</Text>
99
- <Text style={muted}>{open ? "▴" : "▾"}</Text>
108
+ <View style={{ flexDirection: "row", alignItems: "center", flexWrap: "wrap" }}>
109
+ {segments.map((segment, index) => (
110
+ <Fragment key={segment.text}>
111
+ {index > 0 ? <Text style={base}> · </Text> : null}
112
+ <Text style={{ ...base, color: segment.color }}>{segment.text}</Text>
113
+ </Fragment>
114
+ ))}
115
+ <Text style={base}>{open ? " ▴" : " ▾"}</Text>
100
116
  </View>
101
117
  {open ? (
102
118
  <View style={{ marginTop: 2, gap: 1 }}>
103
119
  {details.map((line) => (
104
- <Text key={line} style={muted}>
120
+ <Text key={line} style={base}>
105
121
  {line}
106
122
  </Text>
107
123
  ))}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paseo-dsh",
3
- "version": "0.2.14",
3
+ "version": "0.2.16",
4
4
  "description": "DeepSeek Harness (dsh) as a native Paseo provider: question cards, plan mode, thinking levels, steering, images and a real slash menu. 把 DeepSeek Harness 接成 Paseo 原生 provider。",
5
5
  "keywords": [
6
6
  "paseo",
package/server/session.ts CHANGED
@@ -114,6 +114,18 @@ export class DshSession {
114
114
  /** Tool call start times and the current turn's tool total. */
115
115
  #toolStarts = new Map<string, number>();
116
116
  #turnTool = { count: 0, ms: 0 };
117
+ /**
118
+ * Whether the running turn was stopped by the user. A cancelled turn may not
119
+ * get the completed-turn footer that the stats row is pulled into, so it
120
+ * keeps the default spacing instead of risking an overlap.
121
+ */
122
+ #turnInterrupted = false;
123
+ /**
124
+ * Whether the stats row is the newest timeline item. If tools arrive after
125
+ * it, the completed-turn footer belongs to the end of the turn rather than
126
+ * directly above this row, so the row must keep the default spacing.
127
+ */
128
+ #statsIsTail = false;
117
129
  /** Most recent stats row, so context and tool totals can update it in place. */
118
130
  #lastStats: { id: string; data: Record<string, unknown> } | undefined;
119
131
  /** Per-step timing for the streamed-stats row. */
@@ -609,6 +621,7 @@ export class DshSession {
609
621
  * conversation stays continuable — killing the process stranded it instead.
610
622
  */
611
623
  async interrupt(): Promise<void> {
624
+ this.#turnInterrupted = true;
612
625
  this.#flushLive();
613
626
  this.#clearLive();
614
627
  await this.#require().cancel();
@@ -636,6 +649,7 @@ export class DshSession {
636
649
  if (this.#turnId === null) {
637
650
  this.#toolStarts.clear();
638
651
  this.#turnTool = { count: 0, ms: 0 };
652
+ this.#turnInterrupted = false;
639
653
  // A later usage refresh must not rewrite the previous turn's row.
640
654
  this.#lastStats = undefined;
641
655
  }
@@ -653,6 +667,14 @@ export class DshSession {
653
667
  const turnId = this.#turnId;
654
668
  this.#turnId = null;
655
669
  this.#options.emit({ type: "session.turn", sessionId: this.id, turnId, state: "completed" });
670
+ // Paseo renders the completed-turn footer (copy / model / time) beneath
671
+ // the answer only after this event, and reserves its own padding under
672
+ // that footer. Flag the last stats row in the same tick so the client can
673
+ // close the gap without first flashing the row in the wrong position.
674
+ if (this.#lastStats !== undefined && !this.#turnInterrupted && this.#statsIsTail) {
675
+ this.#lastStats.data = { ...this.#lastStats.data, final: true };
676
+ this.#emitStatsRow();
677
+ }
656
678
  // The turn's request reported fresh provider usage; refresh occupancy now
657
679
  // so the readout is current even when no further turn arrives.
658
680
  void this.refreshUsage();
@@ -840,6 +862,7 @@ export class DshSession {
840
862
  }
841
863
 
842
864
  #emitItem(item: ProviderTimelineItem): void {
865
+ this.#statsIsTail = item.type === "plugin" && item.kind === "dsh-stream-stats";
843
866
  this.#options.emit({ type: "timeline.item", sessionId: this.id, item });
844
867
  }
845
868