paseo-dsh 0.2.12 → 0.2.13
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/client/stream-stats.tsx +20 -1
- package/package.json +1 -1
- package/server/session.ts +43 -1
package/client/stream-stats.tsx
CHANGED
|
@@ -16,6 +16,10 @@ export const streamStatsSchema = z.object({
|
|
|
16
16
|
thinkingOption: z.string().optional(),
|
|
17
17
|
toolCalls: z.number().optional(),
|
|
18
18
|
toolMs: z.number().optional(),
|
|
19
|
+
turns: z.number().optional(),
|
|
20
|
+
steps: z.number().optional(),
|
|
21
|
+
sessionTokens: z.number().optional(),
|
|
22
|
+
cacheHit: z.number().optional(),
|
|
19
23
|
});
|
|
20
24
|
|
|
21
25
|
type StreamStats = z.infer<typeof streamStatsSchema>;
|
|
@@ -28,6 +32,13 @@ function formatNumber(value: number): string {
|
|
|
28
32
|
return String(Math.round(value)).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
29
33
|
}
|
|
30
34
|
|
|
35
|
+
function formatCompact(value: number): string {
|
|
36
|
+
if (value >= 1_000_000) return `${(value / 1_000_000).toFixed(1)}M`;
|
|
37
|
+
if (value >= 10_000) return `${Math.round(value / 1000)}K`;
|
|
38
|
+
if (value >= 1000) return `${(value / 1000).toFixed(1)}K`;
|
|
39
|
+
return String(Math.round(value));
|
|
40
|
+
}
|
|
41
|
+
|
|
31
42
|
function contextLine(data: StreamStats): string | undefined {
|
|
32
43
|
if (data.contextUsed === undefined || data.contextMax === undefined || data.contextMax <= 0) {
|
|
33
44
|
return undefined;
|
|
@@ -63,8 +74,16 @@ function StreamStatsRow({ item, theme, layout }: PluginTimelineItemProps<StreamS
|
|
|
63
74
|
const [open, setOpen] = useState(false);
|
|
64
75
|
const data = item.data;
|
|
65
76
|
const summary: string[] = [];
|
|
77
|
+
if (data.turns !== undefined && data.steps !== undefined) {
|
|
78
|
+
summary.push(`${data.turns} 轮 ${data.steps} 步`);
|
|
79
|
+
}
|
|
66
80
|
if (data.firstTokenMs !== undefined) summary.push(`首字 ${formatLatency(data.firstTokenMs)}`);
|
|
67
|
-
if (data.tokensPerSecond !== undefined) summary.push(`${data.tokensPerSecond
|
|
81
|
+
if (data.tokensPerSecond !== undefined) summary.push(`${Math.round(data.tokensPerSecond)} tok/s`);
|
|
82
|
+
if (data.sessionTokens !== undefined) summary.push(`${formatCompact(data.sessionTokens)} tok`);
|
|
83
|
+
if (data.cacheHit !== undefined) summary.push(`缓存命中 ${Math.round(data.cacheHit * 100)}%`);
|
|
84
|
+
if (summary.length === 0 && data.firstTokenMs !== undefined) {
|
|
85
|
+
summary.push(`首字 ${formatLatency(data.firstTokenMs)}`);
|
|
86
|
+
}
|
|
68
87
|
if (summary.length === 0) return null;
|
|
69
88
|
|
|
70
89
|
const details = [contextLine(data), tokensLine(data), routeLine(data), toolsLine(data)].filter(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "paseo-dsh",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.13",
|
|
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
|
@@ -107,6 +107,10 @@ export class DshSession {
|
|
|
107
107
|
* durable log only carries one complete message per step, so this is what
|
|
108
108
|
* makes the answer appear while the model is still writing it.
|
|
109
109
|
*/
|
|
110
|
+
/** Session totals shown in the collapsed stats line. */
|
|
111
|
+
#totals = { input: 0, cache: 0, cacheWrite: 0, output: 0 };
|
|
112
|
+
#seenTurns = new Set<number>();
|
|
113
|
+
#seenSteps = new Set<string>();
|
|
110
114
|
/** Tool call start times and the current turn's tool total. */
|
|
111
115
|
#toolStarts = new Map<string, number>();
|
|
112
116
|
#turnTool = { count: 0, ms: 0 };
|
|
@@ -383,6 +387,8 @@ export class DshSession {
|
|
|
383
387
|
for (const event of events) {
|
|
384
388
|
const data = isRecord(event.data) ? event.data : {};
|
|
385
389
|
const seq = typeof event.seq === "number" ? event.seq : this.#replaySeq++;
|
|
390
|
+
// Seed the session totals so a resumed agent keeps its 轮/步/token line.
|
|
391
|
+
if (event.type === "assistant/message") this.#accumulateTotals(data);
|
|
386
392
|
if (event.type === "user/message") {
|
|
387
393
|
const source = isRecord(data.source) ? data.source : {};
|
|
388
394
|
if (source.kind !== "user") continue;
|
|
@@ -694,7 +700,10 @@ export class DshSession {
|
|
|
694
700
|
// authoritative final snapshot and simply replaces it.
|
|
695
701
|
if (event.type === "assistant/message") this.#flushLive();
|
|
696
702
|
for (const item of this.#timeline.consume(event)) this.#emitItem(item);
|
|
697
|
-
if (event.type === "assistant/message")
|
|
703
|
+
if (event.type === "assistant/message") {
|
|
704
|
+
this.#accumulateTotals(isRecord(event.data) ? event.data : {});
|
|
705
|
+
this.#emitStreamStats(isRecord(event.data) ? event.data : {});
|
|
706
|
+
}
|
|
698
707
|
if (event.type === "turn/end" && this.#lastStats !== undefined) {
|
|
699
708
|
this.#lastStats.data = {
|
|
700
709
|
...this.#lastStats.data,
|
|
@@ -743,11 +752,44 @@ export class DshSession {
|
|
|
743
752
|
...(this.#thinkingOption === undefined ? {} : { thinkingOption: this.#thinkingOption }),
|
|
744
753
|
toolCalls: this.#turnTool.count,
|
|
745
754
|
...(this.#turnTool.ms > 0 ? { toolMs: this.#turnTool.ms } : {}),
|
|
755
|
+
...this.#sessionFields(),
|
|
746
756
|
};
|
|
747
757
|
this.#lastStats = { id: `stream-stats:${turn}:${step}`, data: statsData };
|
|
748
758
|
this.#emitStatsRow();
|
|
749
759
|
}
|
|
750
760
|
|
|
761
|
+
/** Fold one assistant message's turn, step and usage into the session totals. */
|
|
762
|
+
#accumulateTotals(data: Record<string, unknown>): void {
|
|
763
|
+
const turn = typeof data.turn === "number" ? data.turn : undefined;
|
|
764
|
+
const step = typeof data.step === "number" ? data.step : undefined;
|
|
765
|
+
if (turn !== undefined) this.#seenTurns.add(turn);
|
|
766
|
+
if (turn !== undefined && step !== undefined) this.#seenSteps.add(`${turn}:${step}`);
|
|
767
|
+
const usage = isRecord(data.usage) ? data.usage : undefined;
|
|
768
|
+
if (usage === undefined) return;
|
|
769
|
+
if (typeof usage.inputTokens === "number") this.#totals.input += usage.inputTokens;
|
|
770
|
+
if (typeof usage.cacheReadTokens === "number") this.#totals.cache += usage.cacheReadTokens;
|
|
771
|
+
if (typeof usage.cacheWriteTokens === "number") this.#totals.cacheWrite += usage.cacheWriteTokens;
|
|
772
|
+
if (typeof usage.outputTokens === "number") this.#totals.output += usage.outputTokens;
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
/**
|
|
776
|
+
* Turns, steps, total tokens and cache-hit rate for the collapsed line.
|
|
777
|
+
*
|
|
778
|
+
* Mirrors DSH's own UsagePill: the total is the three prompt-side billing
|
|
779
|
+
* buckets plus output, and the cache rate divides cache reads by that same
|
|
780
|
+
* prompt-side total.
|
|
781
|
+
*/
|
|
782
|
+
#sessionFields(): Record<string, number> {
|
|
783
|
+
const promptTokens = this.#totals.input + this.#totals.cache + this.#totals.cacheWrite;
|
|
784
|
+
const tokens = promptTokens + this.#totals.output;
|
|
785
|
+
return {
|
|
786
|
+
turns: this.#seenTurns.size,
|
|
787
|
+
steps: this.#seenSteps.size,
|
|
788
|
+
...(tokens > 0 ? { sessionTokens: tokens } : {}),
|
|
789
|
+
...(promptTokens > 0 ? { cacheHit: this.#totals.cache / promptTokens } : {}),
|
|
790
|
+
};
|
|
791
|
+
}
|
|
792
|
+
|
|
751
793
|
/** Context occupancy from the last usage snapshot, when known. */
|
|
752
794
|
#contextFields(): Record<string, number> {
|
|
753
795
|
const usage = this.#lastUsage;
|