@xmoon76/dsh-pi-tui 0.5.1 → 0.5.3
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/README.en.md +130 -17
- package/README.md +76 -16
- package/cordis.patch.yml +17 -49
- package/dist/builtins.mjs +3 -2
- package/dist/context-summary-CxUpNkA9.mjs +2951 -0
- package/dist/extension/advanced.d.mts +2 -2
- package/dist/extension/unstable.d.mts +1 -1
- package/dist/{extensions-v3Rf-qJA.d.mts → extensions-DzpBiiYb.d.mts} +1 -1
- package/dist/{extensions-1WYBUQ8I.mjs → extensions-a-rxanjw.mjs} +3514 -2892
- package/dist/extensions.d.mts +2 -2
- package/dist/extensions.mjs +1 -1
- package/dist/index.d.mts +13 -11
- package/dist/index.mjs +20158 -7768
- package/dist/performance-host-BJT6scGF.mjs +266 -0
- package/dist/performance-host.d.mts +36 -0
- package/dist/performance-host.mjs +2 -0
- package/dist/performance-view-jvvd8Jn7.mjs +476 -0
- package/dist/{public-types-BEjj7FEb.d.mts → public-types-gZi3iFNh.d.mts} +1 -1
- package/dist/rolldown-runtime-8H4AJuhK.mjs +14 -0
- package/dist/{runtime-CcQyhIvI.mjs → runtime-BtPH-UUb.mjs} +625 -261
- package/dist/session-BZLxhrPQ.mjs +5697 -0
- package/dist/{startup-CmTYVTGC.mjs → startup-D5Xu8diR.mjs} +22 -7
- package/dist/startup.d.mts +1 -2
- package/dist/startup.mjs +1 -1
- package/dist/tasks-D_z5Yjjr.mjs +267 -0
- package/dist/{terminal-progress-source-BfiTKDT-.mjs → terminal-progress-source-BlmksrSD.mjs} +116 -265
- package/generated/dsh-presets/cordis.patch.yml +8 -26
- package/generated/dsh-presets/minimal.patch.yml +17 -0
- package/generated/dsh-presets/ptc.patch.yml +8 -26
- package/generated/dsh-presets/standard.patch.yml +8 -26
- package/package.json +166 -146
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.mjs";
|
|
2
|
+
import { a as firstTokenTimeFromAssistantStream, c as usageFromAssistantSettlement, r as emptyPerformanceView, t as PI_TUI_PERFORMANCE_KEY } from "./performance-view-jvvd8Jn7.mjs";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
//#region src/app/host/performance-projection.ts
|
|
5
|
+
/**
|
|
6
|
+
* The `piTuiPerformance` Host fold: the ONE statistics state machine for the
|
|
7
|
+
* recent (R5) and Session-lifetime ("All") model-request output rate and for
|
|
8
|
+
* the recent time-to-first-token.
|
|
9
|
+
*
|
|
10
|
+
* The unit is a pure synchronous fold over committed Session events (plan §3.3
|
|
11
|
+
* / §3.4). The official session-projection seam owns the subscription, the
|
|
12
|
+
* per-session cell, the checkpoint cache and the change feed; this module owns
|
|
13
|
+
* only the computation and its plain-JSON state:
|
|
14
|
+
*
|
|
15
|
+
* ```text
|
|
16
|
+
* step/start open the logical step (turn, step, startTime)
|
|
17
|
+
* assistant/attempt fill the step's missing first-token evidence only
|
|
18
|
+
* assistant/message close it ONCE: route epoch, All pair, R5 pair, TTFB sample
|
|
19
|
+
* step/end, turn/end close a step that produced no message (no accounting)
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* Every other event returns the SAME state object (zero downstream work), and
|
|
23
|
+
* an internal-only transition that changes nothing observable reuses the
|
|
24
|
+
* previous view object, so the seam publishes no frame for it (plan §3.3).
|
|
25
|
+
*
|
|
26
|
+
* Usage parsing and the observable-first-token predicate are the SHARED
|
|
27
|
+
* transcript facts (`domain/transcript/usage.ts`), never a second parser; the
|
|
28
|
+
* route identity is the message's `(provider, model)` pair, encoded
|
|
29
|
+
* unambiguously.
|
|
30
|
+
*
|
|
31
|
+
* @module @xmoon76/dsh-pi-tui/app/host/performance-projection
|
|
32
|
+
*/
|
|
33
|
+
const counterSchema = z.strictObject({
|
|
34
|
+
outputTokens: z.number().nonnegative(),
|
|
35
|
+
modelMs: z.number().nonnegative(),
|
|
36
|
+
samples: z.number().int().nonnegative()
|
|
37
|
+
});
|
|
38
|
+
const recentCounterSchema = z.strictObject({
|
|
39
|
+
outputTokens: z.number().nonnegative(),
|
|
40
|
+
modelMs: z.number().nonnegative(),
|
|
41
|
+
samples: z.number().int().nonnegative(),
|
|
42
|
+
firstTokenMs: z.number().nonnegative(),
|
|
43
|
+
firstTokenSamples: z.number().int().nonnegative()
|
|
44
|
+
});
|
|
45
|
+
const viewSchema = z.strictObject({
|
|
46
|
+
recent: recentCounterSchema,
|
|
47
|
+
all: counterSchema
|
|
48
|
+
});
|
|
49
|
+
const stateSchema = z.strictObject({
|
|
50
|
+
view: viewSchema,
|
|
51
|
+
openStep: z.strictObject({
|
|
52
|
+
turn: z.number().int().nonnegative(),
|
|
53
|
+
step: z.number().int().nonnegative(),
|
|
54
|
+
startTime: z.number().nonnegative(),
|
|
55
|
+
firstTokenTime: z.number().nonnegative().nullable()
|
|
56
|
+
}).nullable(),
|
|
57
|
+
routeKey: z.string().nullable(),
|
|
58
|
+
recentSamples: z.array(z.strictObject({
|
|
59
|
+
outputTokens: z.number().nonnegative(),
|
|
60
|
+
modelMs: z.number().nonnegative()
|
|
61
|
+
})).max(5),
|
|
62
|
+
firstTokenSamples: z.array(z.number().nonnegative()).max(5)
|
|
63
|
+
});
|
|
64
|
+
/** The empty fold state. */
|
|
65
|
+
function emptyPerformanceState() {
|
|
66
|
+
return {
|
|
67
|
+
view: emptyPerformanceView(),
|
|
68
|
+
openStep: null,
|
|
69
|
+
routeKey: null,
|
|
70
|
+
recentSamples: [],
|
|
71
|
+
firstTokenSamples: []
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** Whether a replacement-surface rewrite (compaction) carries no new evidence. */
|
|
75
|
+
function isReplacementSurface(event) {
|
|
76
|
+
const op = event.surfaceOp;
|
|
77
|
+
return typeof op === "object" && op !== null && op.op === "replace";
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The step's `(provider, model)` route identity. Only a message whose source is
|
|
81
|
+
* a model route yields a key — a missing identity never resets the window
|
|
82
|
+
* (fail-soft), it only keeps that step out of the route-scoped rings.
|
|
83
|
+
*/
|
|
84
|
+
function performanceRouteKeyOf(message) {
|
|
85
|
+
const source = message.source;
|
|
86
|
+
if (source?.kind !== "model") return void 0;
|
|
87
|
+
if (typeof source.provider !== "string" || typeof source.model !== "string") return void 0;
|
|
88
|
+
return JSON.stringify([source.provider, source.model]);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* One eligible TPS pair: a finite positive output count AND a finite positive
|
|
92
|
+
* model wall time. Provider-boundary validation: an invalid, absent,
|
|
93
|
+
* NaN/Infinity or negative value never enters the All counter or an R5 ring.
|
|
94
|
+
*/
|
|
95
|
+
function eligibleSample(outputTokens, modelMs) {
|
|
96
|
+
if (outputTokens === void 0 || !Number.isFinite(outputTokens) || outputTokens <= 0) return void 0;
|
|
97
|
+
if (!Number.isFinite(modelMs) || modelMs <= 0) return void 0;
|
|
98
|
+
return {
|
|
99
|
+
outputTokens,
|
|
100
|
+
modelMs
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/** Append to a bounded ring, dropping the oldest entries past the limit. */
|
|
104
|
+
function appendRing(ring, value) {
|
|
105
|
+
const next = [...ring, value];
|
|
106
|
+
return next.length > 5 ? next.slice(next.length - 5) : next;
|
|
107
|
+
}
|
|
108
|
+
/** Whether two published views are numerically identical. */
|
|
109
|
+
function sameView(left, right) {
|
|
110
|
+
return left.recent.outputTokens === right.recent.outputTokens && left.recent.modelMs === right.recent.modelMs && left.recent.samples === right.recent.samples && left.recent.firstTokenMs === right.recent.firstTokenMs && left.recent.firstTokenSamples === right.recent.firstTokenSamples && left.all.outputTokens === right.all.outputTokens && left.all.modelMs === right.all.modelMs && left.all.samples === right.all.samples;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Close ONE step at its `assistant/message` boundary and produce the next
|
|
114
|
+
* state (plan §3.4 rules 4-7, 9, 10):
|
|
115
|
+
*
|
|
116
|
+
* 1. a validly declared route different from the current one clears both
|
|
117
|
+
* route-scoped rings BEFORE this step's samples join (A→B→A included);
|
|
118
|
+
* 2. an eligible pair (`outputTokens > 0`, `modelMs > 0`) joins the All counter
|
|
119
|
+
* always and the R5 ring only for a route-identified step;
|
|
120
|
+
* 3. a completed step with first-token evidence inside
|
|
121
|
+
* `[step/start, assistant/message]` joins the TTFB ring for a
|
|
122
|
+
* route-identified step, independent of `outputTokens`;
|
|
123
|
+
* 4. the view object is recreated only when one of its numbers changed.
|
|
124
|
+
*/
|
|
125
|
+
function settleCompletedStep(state, open, eventTime, topLevelUsage, stream, message) {
|
|
126
|
+
const modelMs = eventTime - open.startTime;
|
|
127
|
+
const declaredRouteKey = performanceRouteKeyOf(message);
|
|
128
|
+
let routeKey = state.routeKey;
|
|
129
|
+
let recentSamples = state.recentSamples;
|
|
130
|
+
let firstTokenSamples = state.firstTokenSamples;
|
|
131
|
+
if (declaredRouteKey !== void 0) {
|
|
132
|
+
if (routeKey !== null && routeKey !== declaredRouteKey) {
|
|
133
|
+
recentSamples = [];
|
|
134
|
+
firstTokenSamples = [];
|
|
135
|
+
}
|
|
136
|
+
routeKey = declaredRouteKey;
|
|
137
|
+
}
|
|
138
|
+
const sample = eligibleSample(usageFromAssistantSettlement("message", topLevelUsage, stream)?.outputTokens, modelMs);
|
|
139
|
+
if (sample !== void 0 && declaredRouteKey !== void 0) recentSamples = appendRing(recentSamples, sample);
|
|
140
|
+
const firstTokenTime = open.firstTokenTime ?? firstTokenTimeFromAssistantStream(stream) ?? null;
|
|
141
|
+
if (declaredRouteKey !== void 0 && firstTokenTime !== null) {
|
|
142
|
+
const firstTokenMs = firstTokenTime - open.startTime;
|
|
143
|
+
if (Number.isFinite(firstTokenMs) && firstTokenMs >= 0 && firstTokenMs <= modelMs) firstTokenSamples = appendRing(firstTokenSamples, firstTokenMs);
|
|
144
|
+
}
|
|
145
|
+
const previousAll = state.view.all;
|
|
146
|
+
const all = sample === void 0 ? previousAll : {
|
|
147
|
+
outputTokens: previousAll.outputTokens + sample.outputTokens,
|
|
148
|
+
modelMs: previousAll.modelMs + sample.modelMs,
|
|
149
|
+
samples: previousAll.samples + 1
|
|
150
|
+
};
|
|
151
|
+
const nextView = {
|
|
152
|
+
recent: {
|
|
153
|
+
outputTokens: recentSamples.reduce((sum, pair) => sum + pair.outputTokens, 0),
|
|
154
|
+
modelMs: recentSamples.reduce((sum, pair) => sum + pair.modelMs, 0),
|
|
155
|
+
samples: recentSamples.length,
|
|
156
|
+
firstTokenMs: firstTokenSamples.reduce((sum, value) => sum + value, 0),
|
|
157
|
+
firstTokenSamples: firstTokenSamples.length
|
|
158
|
+
},
|
|
159
|
+
all
|
|
160
|
+
};
|
|
161
|
+
return {
|
|
162
|
+
view: sameView(state.view, nextView) ? state.view : nextView,
|
|
163
|
+
openStep: null,
|
|
164
|
+
routeKey,
|
|
165
|
+
recentSamples,
|
|
166
|
+
firstTokenSamples
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* The `piTuiPerformance` projection unit. `stateVersion` gates the persisted
|
|
171
|
+
* cache: a row from another fold version is discarded and refolded, never
|
|
172
|
+
* forward-applied into garbage.
|
|
173
|
+
*/
|
|
174
|
+
const piTuiPerformanceDefinition = {
|
|
175
|
+
key: PI_TUI_PERFORMANCE_KEY,
|
|
176
|
+
stateVersion: 1,
|
|
177
|
+
stateSchema,
|
|
178
|
+
init: () => emptyPerformanceState(),
|
|
179
|
+
apply: (state, event) => {
|
|
180
|
+
if (isReplacementSurface(event)) return state;
|
|
181
|
+
switch (event.type) {
|
|
182
|
+
case "step/start": return {
|
|
183
|
+
...state,
|
|
184
|
+
openStep: {
|
|
185
|
+
turn: event.data.turn,
|
|
186
|
+
step: event.data.step,
|
|
187
|
+
startTime: event.time,
|
|
188
|
+
firstTokenTime: null
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
case "assistant/attempt": {
|
|
192
|
+
const open = state.openStep;
|
|
193
|
+
if (open === null || open.turn !== event.data.turn || open.step !== event.data.step) return state;
|
|
194
|
+
if (open.firstTokenTime !== null) return state;
|
|
195
|
+
const firstTokenTime = firstTokenTimeFromAssistantStream(event.data.stream);
|
|
196
|
+
if (firstTokenTime === void 0 || !Number.isFinite(firstTokenTime)) return state;
|
|
197
|
+
return {
|
|
198
|
+
...state,
|
|
199
|
+
openStep: {
|
|
200
|
+
...open,
|
|
201
|
+
firstTokenTime
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
case "assistant/message": {
|
|
206
|
+
const open = state.openStep;
|
|
207
|
+
if (open === null || open.turn !== event.data.turn || open.step !== event.data.step) return state;
|
|
208
|
+
return settleCompletedStep(state, open, event.time, event.data.usage, event.data.stream, event.data.message);
|
|
209
|
+
}
|
|
210
|
+
case "step/end":
|
|
211
|
+
case "turn/end": return state.openStep === null ? state : {
|
|
212
|
+
...state,
|
|
213
|
+
openStep: null
|
|
214
|
+
};
|
|
215
|
+
default: return state;
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
wire: {
|
|
219
|
+
viewSchema,
|
|
220
|
+
view: (state) => state.view
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
//#endregion
|
|
224
|
+
//#region src/app/host/performance-host.ts
|
|
225
|
+
var performance_host_exports = /* @__PURE__ */ __exportAll({
|
|
226
|
+
PI_TUI_PERFORMANCE_READY_SERVICE: () => PI_TUI_PERFORMANCE_READY_SERVICE,
|
|
227
|
+
apply: () => apply,
|
|
228
|
+
inject: () => inject,
|
|
229
|
+
name: () => name
|
|
230
|
+
});
|
|
231
|
+
/** Stable Cordis plugin name (the Loader row id in `cordis.patch.yml`). */
|
|
232
|
+
const name = "pi-tui-performance-host";
|
|
233
|
+
/** The projection registry is this plugin's whole purpose: without it the fiber stays pending. */
|
|
234
|
+
const inject = ["sessionProjections"];
|
|
235
|
+
/**
|
|
236
|
+
* The readiness gate this row publishes after the unit is registered. It
|
|
237
|
+
* carries NO data — it is not a second performance authority, only the
|
|
238
|
+
* ordering proof that the Host projection exists before the TUI mounts.
|
|
239
|
+
*
|
|
240
|
+
* The key is declared the way this repository declares its OWN Cordis
|
|
241
|
+
* services (`src/startup.ts`'s `TUI_STARTUP_SERVICE`): an exported string
|
|
242
|
+
* constant, consumed by the dependent row's `inject` list in
|
|
243
|
+
* `cordis.patch.yml`. The gate is data-free, so there is no value shape to
|
|
244
|
+
* declare and no `Context` augmentation to add; a consumer that needs to
|
|
245
|
+
* narrow the read does it at its own call site, exactly as the `tuiStartup`
|
|
246
|
+
* consumers do.
|
|
247
|
+
*/
|
|
248
|
+
const PI_TUI_PERFORMANCE_READY_SERVICE = "piTuiPerformanceReady";
|
|
249
|
+
/**
|
|
250
|
+
* Register the `piTuiPerformance` unit and publish the readiness gate.
|
|
251
|
+
*
|
|
252
|
+
* The registry is resolved through the context's reflection layer, the
|
|
253
|
+
* documented Host-plane idiom of this repository (`app/remote/host-runtime.ts`
|
|
254
|
+
* and `app/remote/pi-tui-file-reference-host.ts` do the same): this module IS
|
|
255
|
+
* the Host plane, so its Host-service read is not Client-side coupling and the
|
|
256
|
+
* client-boundary inventory stays unchanged. `inject` above is what guarantees
|
|
257
|
+
* the service is present and active here.
|
|
258
|
+
*
|
|
259
|
+
* @param ctx - the Host context that owns this row's fiber.
|
|
260
|
+
*/
|
|
261
|
+
function apply(ctx) {
|
|
262
|
+
ctx.reflect.get("sessionProjections").register(piTuiPerformanceDefinition);
|
|
263
|
+
ctx.provide(PI_TUI_PERFORMANCE_READY_SERVICE, {});
|
|
264
|
+
}
|
|
265
|
+
//#endregion
|
|
266
|
+
export { performance_host_exports as a, name as i, apply as n, inject as r, PI_TUI_PERFORMANCE_READY_SERVICE as t };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
|
|
3
|
+
//#region src/app/host/performance-host.d.ts
|
|
4
|
+
/** Stable Cordis plugin name (the Loader row id in `cordis.patch.yml`). */
|
|
5
|
+
declare const name = "pi-tui-performance-host";
|
|
6
|
+
/** The projection registry is this plugin's whole purpose: without it the fiber stays pending. */
|
|
7
|
+
declare const inject: string[];
|
|
8
|
+
/**
|
|
9
|
+
* The readiness gate this row publishes after the unit is registered. It
|
|
10
|
+
* carries NO data — it is not a second performance authority, only the
|
|
11
|
+
* ordering proof that the Host projection exists before the TUI mounts.
|
|
12
|
+
*
|
|
13
|
+
* The key is declared the way this repository declares its OWN Cordis
|
|
14
|
+
* services (`src/startup.ts`'s `TUI_STARTUP_SERVICE`): an exported string
|
|
15
|
+
* constant, consumed by the dependent row's `inject` list in
|
|
16
|
+
* `cordis.patch.yml`. The gate is data-free, so there is no value shape to
|
|
17
|
+
* declare and no `Context` augmentation to add; a consumer that needs to
|
|
18
|
+
* narrow the read does it at its own call site, exactly as the `tuiStartup`
|
|
19
|
+
* consumers do.
|
|
20
|
+
*/
|
|
21
|
+
declare const PI_TUI_PERFORMANCE_READY_SERVICE = "piTuiPerformanceReady";
|
|
22
|
+
/**
|
|
23
|
+
* Register the `piTuiPerformance` unit and publish the readiness gate.
|
|
24
|
+
*
|
|
25
|
+
* The registry is resolved through the context's reflection layer, the
|
|
26
|
+
* documented Host-plane idiom of this repository (`app/remote/host-runtime.ts`
|
|
27
|
+
* and `app/remote/pi-tui-file-reference-host.ts` do the same): this module IS
|
|
28
|
+
* the Host plane, so its Host-service read is not Client-side coupling and the
|
|
29
|
+
* client-boundary inventory stays unchanged. `inject` above is what guarantees
|
|
30
|
+
* the service is present and active here.
|
|
31
|
+
*
|
|
32
|
+
* @param ctx - the Host context that owns this row's fiber.
|
|
33
|
+
*/
|
|
34
|
+
declare function apply(ctx: Context): void;
|
|
35
|
+
//#endregion
|
|
36
|
+
export { PI_TUI_PERFORMANCE_READY_SERVICE, apply, inject, name };
|