@ssamurias/dsh-fish 1.0.3 → 1.0.4
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/AGENTS.md +3 -3
- package/CHANGELOG.md +25 -0
- package/README.md +55 -7
- package/RELEASE-NOTES-1.0.4.md +80 -0
- package/docs/composite-pressure-v0.1.md +23 -0
- package/docs/composite-pressure-v0.2.md +18 -0
- package/docs/pressure-backtest-v0.1.md +19 -0
- package/docs/session-capacity-advice-v0.1.md +17 -0
- package/docs/session-pressure-design-v1.1.md +1173 -0
- package/docs/session-pressure-ui-v0.3.md +28 -0
- package/docs/tool-retention-diagnostics-v2.md +13 -0
- package/lib/autobackup.js +2 -1
- package/lib/backup.js +58 -6
- package/lib/browse.js +55 -11
- package/lib/capture.js +41 -9
- package/lib/client.js +2099 -27
- package/lib/cloudbackup.js +24 -1
- package/lib/clouddrive.js +4 -1
- package/lib/compact.js +28 -11
- package/lib/cue.js +114 -0
- package/lib/derive.js +48 -5
- package/lib/dreamtable.js +5 -4
- package/lib/drive.js +66 -11
- package/lib/generator.js +1 -1
- package/lib/handoff.js +34 -16
- package/lib/home.js +3 -1
- package/lib/identity.js +15 -0
- package/lib/index.js +1 -1
- package/lib/interest.js +38 -0
- package/lib/look.js +7 -0
- package/lib/note.js +163 -39
- package/lib/observe.js +144 -3
- package/lib/persona.js +28 -13
- package/lib/proactive.js +6 -1
- package/lib/restrict.js +7 -2
- package/lib/sametopic.js +94 -0
- package/lib/scheduler.js +292 -16
- package/lib/session-pressure-analysis.js +296 -0
- package/lib/session-pressure-data.js +239 -0
- package/lib/session-pressure-formulas.js +280 -0
- package/lib/session-pressure-load.js +110 -0
- package/lib/session-pressure.js +706 -0
- package/lib/settings.js +4 -1
- package/lib/sleepfact.js +110 -0
- package/lib/sub.js +9 -7
- package/lib/turns.js +8 -1
- package/lib/whatseen.js +24 -2
- package/lib/wiki.js +1677 -0
- package/lib/wikiserve.js +148 -0
- package/media/feedback-qr.jpg +0 -0
- package/media/principle-drive.svg +2 -2
- package/media/principle-memory.svg +1 -1
- package/package.json +1 -1
- package/scripts/sync-pressure-formulas.mjs +17 -0
package/lib/client.js
CHANGED
|
@@ -21,6 +21,285 @@ window.__ModuleLoader__.load({
|
|
|
21
21
|
const exports = module.exports
|
|
22
22
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
23
23
|
|
|
24
|
+
// BEGIN shared pressure formulas
|
|
25
|
+
const pressureVersions = { capacity: 'capacity_v0.1', request: 'request_v0.1', structure: 'structure_v0.1', composite: 'composite_v0.1' }
|
|
26
|
+
const compositeDefaults = { A: { wc: .5, wr: .3, wq: .2 }, B: { wc: .5, wr: .3, wq: .2 }, C: { wr: .6, wq: .4, mu: .35 } }
|
|
27
|
+
|
|
28
|
+
function scoreCapacity(c, g, gamma, horizon, lambda) {
|
|
29
|
+
const bounded = value => Math.min(1, Math.max(0, value))
|
|
30
|
+
const capacity = Number.isFinite(c) ? bounded(c / 100) : null
|
|
31
|
+
const cScore = capacity == null ? null : 100 * capacity ** gamma
|
|
32
|
+
const remainingUse = capacity == null || capacity >= 1 || !Number.isFinite(g)
|
|
33
|
+
? null : bounded(horizon * Math.max(g, 0) / (100 * (1 - capacity)))
|
|
34
|
+
const score = capacity === 1 ? 100 : remainingUse == null ? null
|
|
35
|
+
: 100 * (1 - (1 - capacity ** gamma) * (1 - lambda * remainingUse))
|
|
36
|
+
const forecast = capacity != null && Number.isFinite(g) ? bounded(capacity + horizon * g / 100) : null
|
|
37
|
+
return { capacity, cScore, remainingUse, score, forecast }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function sessionCapacityAdvice(occupancy, growth) {
|
|
41
|
+
if (!Number.isFinite(occupancy) || occupancy < 0) return { level: 'unknown', five: null, ten: null }
|
|
42
|
+
const { gamma, lambda } = pressureDefaults.capacity
|
|
43
|
+
const forecast = horizon => {
|
|
44
|
+
const value = scoreCapacity(occupancy, growth, gamma, horizon, lambda).forecast
|
|
45
|
+
return Number.isFinite(value) ? 100 * value : null
|
|
46
|
+
}
|
|
47
|
+
const five = forecast(5)
|
|
48
|
+
const ten = forecast(10)
|
|
49
|
+
const reaches = (value, threshold) => Number.isFinite(value) && value >= threshold - 1e-10
|
|
50
|
+
const level = reaches(occupancy, 95) ? 'switch'
|
|
51
|
+
: reaches(occupancy, 85) || reaches(five, 95) ? 'prepare'
|
|
52
|
+
: reaches(occupancy, 70) || reaches(ten, 85) ? 'watch' : 'continue'
|
|
53
|
+
return { level, five, ten }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function scoreRequestBurden(data, rho, beta, tau, recentWeight) {
|
|
57
|
+
function bounds(sample) {
|
|
58
|
+
if (!(sample?.rounds > 0) || ![sample.knownMiss, sample.cached, sample.unknownInput, sample.output].every(Number.isFinite)) return null
|
|
59
|
+
const known = sample.knownMiss + rho * sample.cached + beta * sample.output
|
|
60
|
+
return [(known + rho * sample.unknownInput) / sample.rounds, (known + sample.unknownInput) / sample.rounds]
|
|
61
|
+
}
|
|
62
|
+
const all = bounds(data?.all)
|
|
63
|
+
const recent = bounds(data?.recent)
|
|
64
|
+
const ratios = data?.window > 0 && all && recent
|
|
65
|
+
? all.map((value, i) => recentWeight === 0 ? value / data.window : recentWeight === 1 ? recent[i] / data.window
|
|
66
|
+
: ((1 - recentWeight) * value + recentWeight * recent[i]) / data.window) : null
|
|
67
|
+
return { all, recent, ratios, scores: ratios?.map(value => -100 * Math.expm1(-value / tau)) }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function scoreStructure(current, repeated, retry, toolWeight, epsilon, eta) {
|
|
71
|
+
const valid = value => Number.isFinite(value) && value >= 0 && value <= 100
|
|
72
|
+
const tool = valid(current) && valid(repeated) ? toolWeight * (current / 100) + (1 - toolWeight) * (repeated / 100) : null
|
|
73
|
+
const failure = Number.isFinite(retry) ? -Math.expm1(-retry / (100 * epsilon)) : null
|
|
74
|
+
const score = tool != null && (failure != null || eta === 0)
|
|
75
|
+
? 100 * (1 - (1 - tool) * (1 - eta * (failure ?? 0))) : null
|
|
76
|
+
return { tool, failure, score }
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function capacityInputs(dictionary) {
|
|
80
|
+
const occupancy = dictionary.find(metric => metric.id === 'C')?.rows.find(row => row.label === '窗口占用率')?.value
|
|
81
|
+
const growth = dictionary.find(metric => metric.id === 'G')?.rows ?? []
|
|
82
|
+
const windows = [[5, .5], [10, .3], [20, .2]].map(([rounds, weight]) => {
|
|
83
|
+
const row = growth.find(item => item.label === '平均净增长' && item.scope === '最近 ' + rounds + ' 轮')
|
|
84
|
+
return { rounds, weight, value: row?.value, pairs: row?.raw_value?.comparablePairs ?? 0,
|
|
85
|
+
requestPairs: row?.raw_value?.requestPairs ?? 0, compacted: row?.raw_value?.compacted }
|
|
86
|
+
})
|
|
87
|
+
const available = windows.filter(window => Number.isFinite(window.value) && window.pairs > 0)
|
|
88
|
+
return { occupancy: Number.isFinite(occupancy) ? 100 * occupancy : null, windows,
|
|
89
|
+
growth: available.length ? 100 * available.reduce((sum, window) => sum + window.value * window.weight, 0)
|
|
90
|
+
/ available.reduce((sum, window) => sum + window.weight, 0) : null }
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function scoreComposite(scores, parameters, invalidStructure = false) {
|
|
94
|
+
if (invalidStructure) return {
|
|
95
|
+
A: { score: null, contributions: null }, B: { score: null, factors: [null, null, null], product: null, disabled: false },
|
|
96
|
+
C: { score: null, base: null, mix: null, correction: null },
|
|
97
|
+
}
|
|
98
|
+
const normalized = scores.map(value => Number.isFinite(value) && value >= 0 && value <= 100 ? value / 100 : null)
|
|
99
|
+
const [c, r, q] = normalized
|
|
100
|
+
const { A, B, C } = parameters
|
|
101
|
+
const weightsA = [A.wc, A.wr, A.wq]
|
|
102
|
+
const weightsB = [B.wc, B.wr, B.wq]
|
|
103
|
+
const sumA = A.wc + A.wr + A.wq
|
|
104
|
+
const valid = weights => normalized.every((value, i) => weights[i] === 0 || value != null)
|
|
105
|
+
const contributions = sumA > 0 && valid(weightsA)
|
|
106
|
+
? weightsA.map((weight, i) => weight === 0 ? 0 : weight / sumA * normalized[i]) : null
|
|
107
|
+
const factors = weightsB.map((weight, i) => weight === 0 ? 1 : normalized[i] == null ? null : (1 - normalized[i]) ** weight)
|
|
108
|
+
const product = factors.every(Number.isFinite) ? factors.reduce((a, b) => a * b, 1) : null
|
|
109
|
+
const sumC = C.wr + C.wq
|
|
110
|
+
const mix = sumC === 0 ? 0 : valid([0, C.wr, C.wq]) ? ((r ?? 0) * C.wr + (q ?? 0) * C.wq) / sumC : null
|
|
111
|
+
const correction = c == null ? null : c === 1 || C.mu === 0 ? 0 : mix == null ? null : C.mu * (1 - c) * mix
|
|
112
|
+
const points = value => Math.min(100, Math.max(0, 100 * value))
|
|
113
|
+
return {
|
|
114
|
+
A: { score: contributions ? points(contributions.reduce((a, b) => a + b, 0)) : null, contributions },
|
|
115
|
+
B: { score: factors.includes(0) ? 100 : product == null ? null : points(1 - product), factors, product,
|
|
116
|
+
disabled: weightsB.every(weight => weight === 0) },
|
|
117
|
+
C: { score: correction == null ? null : points(c + correction), base: c, mix, correction },
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function pressureStatistics(current, values) {
|
|
122
|
+
const scores = values.filter(Number.isFinite).sort((a, b) => a - b)
|
|
123
|
+
const count = scores.length
|
|
124
|
+
const middle = Math.floor(count / 2)
|
|
125
|
+
const median = count === 0 ? null : count % 2 ? scores[middle] : (scores[middle - 1] + scores[middle]) / 2
|
|
126
|
+
const comparable = median != null && Number.isFinite(current)
|
|
127
|
+
const percentile = comparable ? 100 * scores.reduce((rank, score) => rank + (score < current ? 1 : score === current ? .5 : 0), 0) / count : null
|
|
128
|
+
return { count, median, percentile, difference: comparable ? current - median : null }
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function scoreDiagnostic(inputs, parameters) {
|
|
132
|
+
const { capacity, request, structure } = parameters
|
|
133
|
+
const [current, repeated, retry] = inputs.structure.map(value => Number.isFinite(value) ? 100 * value : null)
|
|
134
|
+
return [
|
|
135
|
+
scoreCapacity(inputs.capacity.occupancy, inputs.capacity.growth, capacity.gamma, capacity.horizon, capacity.lambda).score,
|
|
136
|
+
scoreRequestBurden(inputs.request, request.rho, request.beta, request.tau, request.recentWeight).scores?.[1] ?? null,
|
|
137
|
+
inputs.invalidStructure ? null : scoreStructure(current, repeated, retry, structure.toolWeight, structure.epsilon, structure.eta).score,
|
|
138
|
+
]
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const pressureDefaults = {
|
|
142
|
+
capacity: { gamma: 2, horizon: 10, lambda: .35 },
|
|
143
|
+
request: { rho: 1, beta: 1, tau: 1, recentWeight: .6 },
|
|
144
|
+
structure: { toolWeight: .7, epsilon: .05, eta: .3 },
|
|
145
|
+
composite: compositeDefaults,
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function sameRoundDiagnostic(current, historical, strict = false) {
|
|
149
|
+
return current?.rounds > 0 && current.id !== historical.id && current.rounds === historical.rounds
|
|
150
|
+
&& (!strict || (current.route != null && current.route === historical.route))
|
|
151
|
+
&& current.diagnosticsVersion === historical.diagnosticsVersion
|
|
152
|
+
&& JSON.stringify(current.versions) === JSON.stringify(historical.versions)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function trendSegments(points) {
|
|
156
|
+
const segments = []
|
|
157
|
+
let previous = null
|
|
158
|
+
for (const point of points) {
|
|
159
|
+
if (!Number.isFinite(point.score)) {
|
|
160
|
+
previous = null
|
|
161
|
+
continue
|
|
162
|
+
}
|
|
163
|
+
if (previous !== point.round - 1) segments.push([])
|
|
164
|
+
segments.at(-1).push(point)
|
|
165
|
+
previous = point.round
|
|
166
|
+
}
|
|
167
|
+
return segments
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const backtestMethods = ['linear5', 'linear10', 'weighted']
|
|
171
|
+
const backtestHorizons = [5, 10, 20]
|
|
172
|
+
|
|
173
|
+
function forecastChildren(prefix, origin, horizon, method) {
|
|
174
|
+
const windows = method === 'linear5' ? [[5, 1]] : method === 'linear10' ? [[10, 1]]
|
|
175
|
+
: [[5, .5], [10, .3], [20, .2]]
|
|
176
|
+
const last = prefix.get(origin)
|
|
177
|
+
if (!last?.children?.every(Number.isFinite)) return null
|
|
178
|
+
const slopes = [0, 0, 0]
|
|
179
|
+
for (const [width, weight] of windows) {
|
|
180
|
+
const middle = (width - 1) / 2
|
|
181
|
+
const denominator = width * (width ** 2 - 1) / 12
|
|
182
|
+
for (let i = 0; i < width; i++) {
|
|
183
|
+
const point = prefix.get(origin - width + 1 + i)
|
|
184
|
+
if (!point?.children?.every(Number.isFinite)) return null
|
|
185
|
+
for (let dimension = 0; dimension < 3; dimension++) {
|
|
186
|
+
slopes[dimension] += weight * (i - middle) * point.children[dimension] / denominator
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return last.children.map((score, dimension) => Math.max(0, Math.min(100, score + horizon * slopes[dimension])))
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function forecastPressure(prefix, origin, horizon, method, parameters) {
|
|
194
|
+
const children = forecastChildren(prefix, origin, horizon, method)
|
|
195
|
+
return children ? scoreComposite(children, parameters) : null
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function pressureContributions(start, end, plan, parameters) {
|
|
199
|
+
if (!start?.every(Number.isFinite) || !end?.every(Number.isFinite)) return null
|
|
200
|
+
const score = values => scoreComposite(values, parameters)[plan]?.score
|
|
201
|
+
if (!Number.isFinite(score(start)) || !Number.isFinite(score(end))) return null
|
|
202
|
+
if (plan === 'A') {
|
|
203
|
+
const { wc, wr, wq } = parameters.A
|
|
204
|
+
const weights = [wc, wr, wq]
|
|
205
|
+
const total = wc + wr + wq
|
|
206
|
+
return weights.map((weight, i) => (end[i] - start[i]) * weight / total)
|
|
207
|
+
}
|
|
208
|
+
const contributions = [0, 0, 0]
|
|
209
|
+
for (const order of [[0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0, 1], [2, 1, 0]]) {
|
|
210
|
+
const values = [...start]
|
|
211
|
+
let before = score(values)
|
|
212
|
+
for (const index of order) {
|
|
213
|
+
values[index] = end[index]
|
|
214
|
+
const after = score(values)
|
|
215
|
+
contributions[index] += (after - before) / 6
|
|
216
|
+
before = after
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return contributions
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function pressureBacktestRecords(sessions, parameters) {
|
|
223
|
+
const records = []
|
|
224
|
+
for (const [sessionId, points] of sessions) {
|
|
225
|
+
const observed = new Map(points.map(point => [point.round, point]))
|
|
226
|
+
const prefix = new Map()
|
|
227
|
+
const lastRound = points.at(-1)?.round ?? 0
|
|
228
|
+
const compactions = points.filter(point => point.markers?.some(marker =>
|
|
229
|
+
['压缩成功', '裁剪'].includes(marker.type))).map(point => point.round)
|
|
230
|
+
let index = 0
|
|
231
|
+
for (let origin = 20; origin + 5 <= lastRound; origin += 5) {
|
|
232
|
+
while (index < points.length && points[index].round <= origin) {
|
|
233
|
+
prefix.set(points[index].round, points[index])
|
|
234
|
+
index++
|
|
235
|
+
}
|
|
236
|
+
for (const horizon of backtestHorizons) {
|
|
237
|
+
const target = origin + horizon
|
|
238
|
+
const actual = observed.get(target)?.scores
|
|
239
|
+
if (!actual) continue
|
|
240
|
+
const before = compactions.some(round => round > origin && round <= target)
|
|
241
|
+
const after = compactions.some(round => round > origin - 5 && round <= origin)
|
|
242
|
+
const groups = ['overall', ...(before ? ['before'] : []), ...(after ? ['after'] : []),
|
|
243
|
+
...(!before && !after ? ['neither'] : [])]
|
|
244
|
+
for (const method of backtestMethods) {
|
|
245
|
+
const predictedChildren = forecastChildren(prefix, origin, horizon, method)
|
|
246
|
+
if (!predictedChildren) continue
|
|
247
|
+
const predicted = scoreComposite(predictedChildren, parameters)
|
|
248
|
+
for (const plan of ['A', 'B', 'C']) {
|
|
249
|
+
const estimate = predicted[plan]?.score
|
|
250
|
+
const observedScore = actual[plan]?.score
|
|
251
|
+
if (Number.isFinite(estimate) && Number.isFinite(observedScore)) {
|
|
252
|
+
records.push({ sessionId, origin, target, horizon, method, plan, estimate, actual: observedScore, predictedChildren, groups })
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return records
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function commonPressureBacktestRecords(records, methods) {
|
|
263
|
+
const key = row => JSON.stringify([row.sessionId, row.origin, row.horizon, row.plan])
|
|
264
|
+
const availability = new Map()
|
|
265
|
+
for (const row of records) {
|
|
266
|
+
if (!methods.includes(row.method)) continue
|
|
267
|
+
const id = key(row)
|
|
268
|
+
if (!availability.has(id)) availability.set(id, new Set())
|
|
269
|
+
availability.get(id).add(row.method)
|
|
270
|
+
}
|
|
271
|
+
return records.filter(row => methods.includes(row.method) && availability.get(key(row))?.size === methods.length)
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function summarizePressureBacktest(records) {
|
|
275
|
+
const groups = ['overall', 'before', 'after', 'neither']
|
|
276
|
+
const rows = backtestMethods.flatMap(method => backtestHorizons.flatMap(horizon => ['A', 'B', 'C'].map(plan => ({
|
|
277
|
+
method, horizon, plan, groups: Object.fromEntries(groups.map(group => [group,
|
|
278
|
+
{ count: 0, absolute: 0, signed: 0, sessions: new Set() }])),
|
|
279
|
+
}))))
|
|
280
|
+
const byKey = new Map(rows.map(row => [[row.method, row.horizon, row.plan].join(':'), row]))
|
|
281
|
+
for (const record of records) {
|
|
282
|
+
const row = byKey.get([record.method, record.horizon, record.plan].join(':'))
|
|
283
|
+
const error = record.estimate - record.actual
|
|
284
|
+
for (const stratum of record.groups) {
|
|
285
|
+
const group = row.groups[stratum]
|
|
286
|
+
group.count++
|
|
287
|
+
group.absolute += Math.abs(error)
|
|
288
|
+
group.signed += error
|
|
289
|
+
group.sessions.add(record.sessionId)
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return rows.map(row => ({ ...row, groups: Object.fromEntries(Object.entries(row.groups).map(([key, group]) => [
|
|
293
|
+
key, { count: group.count, sessions: group.sessions.size, mae: group.count ? group.absolute / group.count : null,
|
|
294
|
+
bias: group.count ? group.signed / group.count : null },
|
|
295
|
+
])) }))
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function runPressureBacktest(sessions, parameters) {
|
|
299
|
+
return summarizePressureBacktest(pressureBacktestRecords(sessions, parameters))
|
|
300
|
+
}
|
|
301
|
+
// END shared pressure formulas
|
|
302
|
+
|
|
24
303
|
const React = require('react')
|
|
25
304
|
const { createElement: h, useCallback, useEffect, useRef, useState } = React
|
|
26
305
|
|
|
@@ -32,6 +311,13 @@ window.__ModuleLoader__.load({
|
|
|
32
311
|
return String(text ?? '').split('她').join(SELF_SHE)
|
|
33
312
|
}
|
|
34
313
|
|
|
314
|
+
// 说明页那批文案(lib/wiki.js)用的是 `{S}` 占位而不是「她」:
|
|
315
|
+
// 那边同时被服务端整页渲染(另一个进程,读不到这里这个变量),
|
|
316
|
+
// 所以两边约定同一个占位符,各自替换。理由和 S() 一样——改称呼不该让说明书跟不上。
|
|
317
|
+
function W(text) {
|
|
318
|
+
return String(text ?? '').split('{S}').join(SELF_SHE)
|
|
319
|
+
}
|
|
320
|
+
|
|
35
321
|
// 插件 API 前缀不能写死 '/dsh-fish':DSH 被反向代理挂在子路径下时
|
|
36
322
|
// (如 /app/deepseek-harness/fngateway/),站点绝对路径会绕过前缀打 404(issue #132)。
|
|
37
323
|
// 页面带 <base href="./"> 时 baseURI 就是子路径目录;根路径部署下仍是 '/dsh-fish'。
|
|
@@ -164,6 +450,14 @@ window.__ModuleLoader__.load({
|
|
|
164
450
|
'.dfish button{background:transparent;border:.5px solid var(--dsw-alias-border-l2);border-radius:7px;color:var(--dsw-alias-label-primary);font-size:12.5px;height:28px;padding:0 12px;cursor:pointer}',
|
|
165
451
|
'.dfish button:hover:not(:disabled){border-color:var(--dsw-alias-state-business-primary);color:var(--dsw-alias-state-business-primary)}',
|
|
166
452
|
'.dfish button:disabled{opacity:.5;cursor:default}',
|
|
453
|
+
// 说明入口(2026-11-16,用户 m04417):默认的蓝链跟这一页的按钮、胶囊完全不是一个语言——
|
|
454
|
+
// 一串带下划线的蓝字插在卡片里,像从别处粘过来的。改成和按钮同高同圆角的「引导钮」:
|
|
455
|
+
// 描边用 border-l3(比普通按钮的 l2 略重一点,认出它是主操作),字色跟正文一样,
|
|
456
|
+
// 只有悬停时才泛出 business-primary —— 读起来是按钮,不是链接。
|
|
457
|
+
'.dfish .go{display:inline-flex;align-items:center;gap:5px;height:28px;padding:0 12px;border:.5px solid var(--dsw-alias-border-l3);border-radius:7px;color:var(--dsw-alias-label-primary);background:rgba(128,128,128,.06);font-size:12.5px;text-decoration:none;white-space:nowrap}',
|
|
458
|
+
'.dfish .go:hover{border-color:var(--dsw-alias-state-business-primary);color:var(--dsw-alias-state-business-primary);text-decoration:none}',
|
|
459
|
+
'.dfish .go .arrow{font-size:11px;color:var(--dsw-alias-label-tertiary);line-height:1}',
|
|
460
|
+
'.dfish .go:hover .arrow{color:var(--dsw-alias-state-business-primary)}',
|
|
167
461
|
'.dfish textarea{width:100%;box-sizing:border-box;min-height:66px;resize:vertical;background:transparent;border:.5px solid var(--dsw-alias-border-l2);border-radius:8px;color:var(--dsw-alias-label-primary);font:inherit;font-size:13px;line-height:20px;padding:8px 10px;outline:none}',
|
|
168
462
|
// 卡片内的两格切换(扫码 / 粘贴 cookie,2026-11-02)。
|
|
169
463
|
// 刻意不复用页面顶部那套 .tabs/.tab:那是导航栏的类名,卡片里再套一层
|
|
@@ -190,6 +484,27 @@ window.__ModuleLoader__.load({
|
|
|
190
484
|
'.dfish .page{display:grid;grid-template-columns:repeat(auto-fit,minmax(340px,1fr));gap:14px;align-items:start}',
|
|
191
485
|
'.dfish .page>.card{min-width:0}',
|
|
192
486
|
'.dfish .card.full{grid-column:1 / -1}',
|
|
487
|
+
'.dfish .pressure-summary{display:grid;gap:9px;grid-template-columns:repeat(auto-fit,minmax(min(100%,190px),1fr))}',
|
|
488
|
+
'.dfish .pressure-metric{min-width:0;border:1px solid var(--dsw-alias-border-l2);border-radius:8px;padding:8px 10px}',
|
|
489
|
+
'.dfish .pressure-value{font-variant-numeric:tabular-nums;font-size:15px;font-weight:600}',
|
|
490
|
+
'.dfish .load-tabs{margin:8px 0 12px}',
|
|
491
|
+
'.dfish .load-panel{display:grid;gap:8px;min-width:0}',
|
|
492
|
+
'.dfish .load-heading{display:flex;align-items:baseline;justify-content:space-between;gap:6px;flex-wrap:wrap}',
|
|
493
|
+
|
|
494
|
+
'.dfish .load-median-line{stroke:var(--dsw-alias-label-secondary);stroke-dasharray:4 3}',
|
|
495
|
+
'.dfish .load-band{fill:currentColor;opacity:.16}',
|
|
496
|
+
'.dfish .load-legend{display:flex;flex-wrap:wrap;gap:4px 12px}',
|
|
497
|
+
'.dfish .load-reference{text-align:right}',
|
|
498
|
+
'.dfish .load-delta{font-variant-numeric:tabular-nums}',
|
|
499
|
+
'.dfish .load-factor{display:flex;align-items:baseline;gap:6px 10px;flex-wrap:wrap;padding:6px 0;border-bottom:1px solid var(--dsw-alias-border-l2);font-size:12px}',
|
|
500
|
+
'.dfish .load-factor label{display:flex;align-items:center;gap:5px;min-width:125px}',
|
|
501
|
+
|
|
502
|
+
'.dfish .pressure-section{border-top:1px solid var(--dsw-alias-border-l2);margin-top:9px;padding-top:7px;min-width:0;font-size:12px}',
|
|
503
|
+
'.dfish .pressure-section summary{cursor:pointer;font-size:12px;font-weight:500}',
|
|
504
|
+
'.dfish .pressure-table{width:100%;table-layout:fixed;border-collapse:collapse;font-size:12px;font-variant-numeric:tabular-nums}',
|
|
505
|
+
'.dfish .pressure-table th,.dfish .pressure-table td{padding:6px 4px;text-align:left;overflow-wrap:anywhere;border-bottom:1px solid var(--dsw-alias-border-l2)}',
|
|
506
|
+
'.dfish .pressure-table th{color:var(--dsw-alias-label-secondary);font-weight:500}',
|
|
507
|
+
'.dfish .pressure-table :is(th,td):last-child{text-align:right}',
|
|
193
508
|
'.dfish .grid2{display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:12px 18px}',
|
|
194
509
|
'.dfish .fld{display:flex;flex-direction:column;gap:5px;min-width:0}',
|
|
195
510
|
'.dfish .fl{display:flex;flex-direction:column;gap:2px}',
|
|
@@ -259,7 +574,11 @@ window.__ModuleLoader__.load({
|
|
|
259
574
|
|
|
260
575
|
function useStyleOnce() {
|
|
261
576
|
useEffect(() => {
|
|
262
|
-
|
|
577
|
+
const current = document.querySelector(`style[data-tag="${CSS_TAG}"]`)
|
|
578
|
+
if (current) {
|
|
579
|
+
if (current.textContent !== CSS) current.textContent = CSS
|
|
580
|
+
return
|
|
581
|
+
}
|
|
263
582
|
const el = document.createElement('style')
|
|
264
583
|
el.setAttribute('data-tag', CSS_TAG)
|
|
265
584
|
el.textContent = CSS
|
|
@@ -384,6 +703,79 @@ window.__ModuleLoader__.load({
|
|
|
384
703
|
return listed ? `${listed};另有 ${n} 个连名字都写不进包里${why}` : `包里连它们的名字都写不下${why}`
|
|
385
704
|
}
|
|
386
705
|
|
|
706
|
+
// ---------------------------------------------------------------- 说明入口(原理页最上面那一条)
|
|
707
|
+
//
|
|
708
|
+
// 2026-11-16 用户 m03816:不要独立的「说明」页签,也不要设置页里那个搜索框——
|
|
709
|
+
// 「而是一个点击跳转的超链接……点了之后,浏览器自动打开本地 html 页面」。
|
|
710
|
+
// 所以 App 里只留一行:一句它在讲什么,加一个蓝链;整套说明在浏览器里看。
|
|
711
|
+
//
|
|
712
|
+
// 为什么这里敢用 <a target="_blank">(前两次都撞墙,两次都不是「再调调」能解决的):
|
|
713
|
+
// · 链到插件自己的路由 → 桌面版 setWindowOpenHandler 对 http(s) 是 openExternal + deny,
|
|
714
|
+
// 链接被甩给系统浏览器;而那道信任栅栏要的 cookie 是「按本次启动密钥签的」,
|
|
715
|
+
// 只有 App 自己的 webContents 带着,浏览器里必然 401。
|
|
716
|
+
// · 链到 file:// → 同一个 handler 里 file: 既不 openExternal 也不放行,点了没反应。
|
|
717
|
+
// · 回环小站(lib/wikiserve.js)不一样:目标不是宿主的任何一条路由,是我们自己起的服务,
|
|
718
|
+
// 只监听 127.0.0.1、只认 GET。浏览器打开它,就跟打开任何一个本地小站一样;
|
|
719
|
+
// Electron 看到 http(s) 就 openExternal,正好把这一下变成「系统浏览器打开」。
|
|
720
|
+
//
|
|
721
|
+
// 组件放在模块作用域:写在 FishSection 里,每次渲染都是新的函数身份,React 会当成
|
|
722
|
+
// 另一个组件卸载重挂,每次都要重新取一遍 /wiki.data。
|
|
723
|
+
function WikiLink() {
|
|
724
|
+
const [info, setInfo] = useState(null)
|
|
725
|
+
const [err, setErr] = useState('')
|
|
726
|
+
const [saving, setSaving] = useState(false)
|
|
727
|
+
const [saved, setSaved] = useState('')
|
|
728
|
+
|
|
729
|
+
useEffect(() => {
|
|
730
|
+
let alive = true
|
|
731
|
+
jget('/wiki.data')
|
|
732
|
+
.then((r) => { if (alive) setInfo(r) })
|
|
733
|
+
.catch((e) => { if (alive) setErr(String(e?.message ?? e)) })
|
|
734
|
+
return () => { alive = false }
|
|
735
|
+
}, [])
|
|
736
|
+
|
|
737
|
+
// 存一份能双击打开的 HTML:浏览器里当然也能「另存为」,但名字和位置得自己找;
|
|
738
|
+
// 这一条是给「想发给别人 / 想留在本地」的人留的(用户 m02916 的 C 案还留着)。
|
|
739
|
+
const saveHtml = async () => {
|
|
740
|
+
setSaving(true)
|
|
741
|
+
setSaved('')
|
|
742
|
+
try {
|
|
743
|
+
const r = await fetch(API + '/wiki', { headers: { accept: 'text/html' } })
|
|
744
|
+
if (!r.ok) throw new Error('HTTP ' + r.status)
|
|
745
|
+
const html = await r.text()
|
|
746
|
+
const blob = new Blob([html], { type: 'text/html;charset=utf-8' })
|
|
747
|
+
const url = URL.createObjectURL(blob)
|
|
748
|
+
const a = document.createElement('a')
|
|
749
|
+
a.href = url
|
|
750
|
+
a.download = '大肥鱼说明.html'
|
|
751
|
+
a.click()
|
|
752
|
+
setTimeout(() => URL.revokeObjectURL(url), 4000)
|
|
753
|
+
setSaved('存好了,双击那个文件也能看。')
|
|
754
|
+
} catch (e) {
|
|
755
|
+
setSaved('没存成:' + (e?.message ?? e) + '。过一会儿再点一次。')
|
|
756
|
+
} finally {
|
|
757
|
+
setSaving(false)
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
const url = typeof info?.url === 'string' ? info.url : ''
|
|
762
|
+
const count = Array.isArray(info?.entries) ? info.entries.length : 0
|
|
763
|
+
|
|
764
|
+
return h('div', { className: 'card', style: { margin: '0 0 12px' } },
|
|
765
|
+
h('div', { style: { fontSize: '13px', fontWeight: 500, lineHeight: '20px' } },
|
|
766
|
+
count ? S('wiki:界面上那些词和数,' + count + ' 条都在这一页') : S('wiki:界面上那些词和数,一条一条讲清')),
|
|
767
|
+
h('div', { className: 'dim', style: { marginTop: '4px', lineHeight: '1.8' } },
|
|
768
|
+
S('阶段怎么算、门要什么证据、疤是什么、劲儿从哪来、五个设置页各管什么、四十七张事件卡都在什么时候出。')),
|
|
769
|
+
h('div', { style: { marginTop: '10px', display: 'flex', alignItems: 'center', gap: '10px', flexWrap: 'wrap' } },
|
|
770
|
+
url
|
|
771
|
+
? h('a', { className: 'go', href: url, target: '_blank', rel: 'noreferrer' },
|
|
772
|
+
S('在浏览器里打开'), h('span', { className: 'arrow' }, '↗'))
|
|
773
|
+
: h('span', { className: 'dim' }, err ? '没拿到地址:' + err : '正在准备地址……一秒'),
|
|
774
|
+
h('button', { onClick: saveHtml, disabled: saving, style: { fontSize: '12.5px' } },
|
|
775
|
+
saving ? '正在存……' : '存一份 HTML')),
|
|
776
|
+
saved ? h('div', { className: 'ok', style: { marginTop: '6px' } }, saved) : null)
|
|
777
|
+
}
|
|
778
|
+
|
|
387
779
|
// ---------------------------------------------------------------- 组件
|
|
388
780
|
function FishSection() {
|
|
389
781
|
useStyleOnce()
|
|
@@ -411,8 +803,8 @@ window.__ModuleLoader__.load({
|
|
|
411
803
|
const [rules, setRules] = useState(null)
|
|
412
804
|
const [st, setSt] = useState(null)
|
|
413
805
|
const [rotateAfter, setRotateAfter] = useState(120)
|
|
414
|
-
// 换新会话时带几轮原话过去(0 = 不带)。默认
|
|
415
|
-
const [carryTurns, setCarryTurns] = useState(
|
|
806
|
+
// 换新会话时带几轮原话过去(0 = 不带)。默认 3(2026-11-17 用户 m04639)。
|
|
807
|
+
const [carryTurns, setCarryTurns] = useState(3)
|
|
416
808
|
const [docBudget, setDocBudget] = useState(2800)
|
|
417
809
|
// 0.9.7 T1:身份段里摆不摆「你最近说过的几句话」(默认开)
|
|
418
810
|
const [echoOn, setEchoOn] = useState(true)
|
|
@@ -463,6 +855,61 @@ window.__ModuleLoader__.load({
|
|
|
463
855
|
const [note, setNote] = useState('')
|
|
464
856
|
// 设置界面重做(2026-10-23):当前页 + 新增的几个环境项
|
|
465
857
|
const [tab, setTab] = useState('now')
|
|
858
|
+
const [pressure, setPressure] = useState(null)
|
|
859
|
+
const [structureExperiment, setStructureExperiment] = useState({})
|
|
860
|
+
const [requestExperiment, setRequestExperiment] = useState({})
|
|
861
|
+
const [capacityExperiment, setCapacityExperiment] = useState({})
|
|
862
|
+
const [pressureTab, setPressureTab] = useState('current')
|
|
863
|
+
const [pressureOpen, setPressureOpen] = useState(false)
|
|
864
|
+
const [pressureRefresh, setPressureRefresh] = useState(0)
|
|
865
|
+
const [showPressureIds, setShowPressureIds] = useState(false)
|
|
866
|
+
const [showUncheckedPressure, setShowUncheckedPressure] = useState(false)
|
|
867
|
+
const [pressureSaving, setPressureSaving] = useState(false)
|
|
868
|
+
const [pressureSelectionError, setPressureSelectionError] = useState(false)
|
|
869
|
+
const [compositeExperiment, setCompositeExperiment] = useState({})
|
|
870
|
+
const [trendConfig, setTrendConfig] = useState({})
|
|
871
|
+
const [trendData, setTrendData] = useState({})
|
|
872
|
+
const [trendLoading, setTrendLoading] = useState(false)
|
|
873
|
+
const [trendFocus, setTrendFocus] = useState(null)
|
|
874
|
+
async function selectPressureSession(id, selected) {
|
|
875
|
+
setPressureSaving(true)
|
|
876
|
+
setPressureSelectionError(false)
|
|
877
|
+
try {
|
|
878
|
+
await jpost('/session-pressure', { id, selected })
|
|
879
|
+
setPressureRefresh(value => value + 1)
|
|
880
|
+
} catch {
|
|
881
|
+
setPressureSelectionError(true)
|
|
882
|
+
} finally { setPressureSaving(false) }
|
|
883
|
+
}
|
|
884
|
+
useEffect(() => {
|
|
885
|
+
if (tab !== 'memory' || !pressureOpen) return
|
|
886
|
+
let active = true
|
|
887
|
+
let inFlight = false
|
|
888
|
+
const compositeQuery = '&composite=1'
|
|
889
|
+
async function refresh() {
|
|
890
|
+
if (!active || inFlight || document.visibilityState === 'hidden') return
|
|
891
|
+
inFlight = true
|
|
892
|
+
try {
|
|
893
|
+
let result = await jget(compositeQuery ? '/session-pressure?composite=1' : '/session-pressure')
|
|
894
|
+
if (active) setPressure(result)
|
|
895
|
+
while (active && document.visibilityState !== 'hidden' && result?.usage?.pendingCount > 0) {
|
|
896
|
+
result = await jget('/session-pressure?wait=1' + compositeQuery)
|
|
897
|
+
if (active) setPressure(result)
|
|
898
|
+
}
|
|
899
|
+
} catch {
|
|
900
|
+
if (active) setPressure({ failed: true })
|
|
901
|
+
} finally { inFlight = false }
|
|
902
|
+
}
|
|
903
|
+
document.addEventListener('visibilitychange', refresh)
|
|
904
|
+
void refresh()
|
|
905
|
+
const poll = compositeQuery ? setInterval(refresh, 5000) : null
|
|
906
|
+
return () => {
|
|
907
|
+
active = false
|
|
908
|
+
if (poll != null) clearInterval(poll)
|
|
909
|
+
document.removeEventListener('visibilitychange', refresh)
|
|
910
|
+
}
|
|
911
|
+
}, [tab, pressureOpen, pressureRefresh])
|
|
912
|
+
|
|
466
913
|
// 恢复撞上碎字文件时,后端回的「要你拿主意」那张清单(issue #65):{ obj, files, count }。
|
|
467
914
|
// 放在 tab 后面(上面的规矩):测试按下标找 tab,别把它挤走。
|
|
468
915
|
const [restoreBad, setRestoreBad] = useState(null)
|
|
@@ -513,6 +960,7 @@ window.__ModuleLoader__.load({
|
|
|
513
960
|
const [proactiveCompact, setProactiveCompact] = useState(true)
|
|
514
961
|
const [proactiveSeen, setProactiveSeen] = useState(false)
|
|
515
962
|
const [doingOn, setDoingOn] = useState(false)
|
|
963
|
+
const [interestGateOn, setInterestGateOn] = useState(false)
|
|
516
964
|
const [doingPerDay, setDoingPerDay] = useState(1)
|
|
517
965
|
const [doingClasses, setDoingClasses] = useState('')
|
|
518
966
|
const doingClassesTimer = useRef(null)
|
|
@@ -663,6 +1111,15 @@ window.__ModuleLoader__.load({
|
|
|
663
1111
|
const kindChosen = cloudNewKind || (cloudState?.kinds ?? [])[0]?.kind || ''
|
|
664
1112
|
// 「看云上那几份」:点开才去问,不在首屏拉——灾后换机才会用到,平时白花一次网络。
|
|
665
1113
|
const [cloudRemote, setCloudRemote] = useState(null)
|
|
1114
|
+
// 2026-11-16 issue #145:点完就把结果滚到眼前,并且让点的那颗按钮说清自己在忙。
|
|
1115
|
+
// 之前结果渲染在目标列表之后、按钮只加 disabled,点完看起来像没反应。
|
|
1116
|
+
const cloudRemoteRef = useRef(null)
|
|
1117
|
+
const [cloudRemoteLoading, setCloudRemoteLoading] = useState('')
|
|
1118
|
+
useEffect(() => {
|
|
1119
|
+
if (cloudRemote && cloudRemoteRef.current) {
|
|
1120
|
+
cloudRemoteRef.current.scrollIntoView({ block: 'nearest', behavior: 'smooth' })
|
|
1121
|
+
}
|
|
1122
|
+
}, [cloudRemote])
|
|
666
1123
|
// 云端那一段默认折叠(2026-11-14 用户 m03310:「默认折叠,只保留标题,点击打开后再显示详细设置」)。
|
|
667
1124
|
// 理由:云端有七八个字段、一张目标列表、口令区,一进来全摊开,会把上面「手动/自动备份」
|
|
668
1125
|
// 挤到一屏之外——多数人根本不用云端,先看见的应该是那两层。
|
|
@@ -914,6 +1371,7 @@ window.__ModuleLoader__.load({
|
|
|
914
1371
|
setProactiveCompact(pr.foldSilent !== false)
|
|
915
1372
|
setProactiveSeen(pr.idleCountsSeen === true)
|
|
916
1373
|
setDoingOn(pr.allowDoing === true)
|
|
1374
|
+
setInterestGateOn(pr.interestGate === true)
|
|
917
1375
|
setDoingPerDay(Number(pr.consumePerDay ?? 1))
|
|
918
1376
|
setDoingClasses(Object.entries(pr.toolClasses && typeof pr.toolClasses === 'object' ? pr.toolClasses : {})
|
|
919
1377
|
.map(([k, v]) => `${k}=${v}`).join('\n'))
|
|
@@ -1027,7 +1485,7 @@ window.__ModuleLoader__.load({
|
|
|
1027
1485
|
setAtOthers(cfg.at?.others !== false)
|
|
1028
1486
|
setAtOwnerWake(cfg.at?.ownerWake !== false)
|
|
1029
1487
|
setRotateAfter(Number(cfg.chat?.rotateAfter ?? 120))
|
|
1030
|
-
setCarryTurns(Number(cfg.chat?.carry ??
|
|
1488
|
+
setCarryTurns(Number(cfg.chat?.carry ?? 3))
|
|
1031
1489
|
setReplyChars(Number(cfg.chat?.replyChars ?? 0))
|
|
1032
1490
|
setAnchorOn(cfg.chat?.anchor === true)
|
|
1033
1491
|
setUiHintDismissed(cfg.ui?.ownerHintDismissed === true)
|
|
@@ -1609,6 +2067,20 @@ window.__ModuleLoader__.load({
|
|
|
1609
2067
|
} finally { setBusy('') }
|
|
1610
2068
|
}
|
|
1611
2069
|
|
|
2070
|
+
// 2026-11-17(用户 m00796):「现在去看积压的视频」——不是叫醒,是单独开一个
|
|
2071
|
+
// 翻一翻回合,把还没摆过的视频标题摆给她挑。wakesPerDay=0 时 /wake 叫不醒,
|
|
2072
|
+
// 这个按钮不受那条限制。
|
|
2073
|
+
const browseNow = async () => {
|
|
2074
|
+
setBusy('browse-now'); setNote('')
|
|
2075
|
+
try {
|
|
2076
|
+
const r = await jpost('/browse-review')
|
|
2077
|
+
setNote(r.ok ? `摆出了 ${r.count} 条。` : (r.why === '没有要整理的' ? '没有积压的视频,不用整理。' : `没摆:${r.why || ''}`))
|
|
2078
|
+
await load()
|
|
2079
|
+
} catch (e) {
|
|
2080
|
+
setErr(e.message)
|
|
2081
|
+
} finally { setBusy('') }
|
|
2082
|
+
}
|
|
2083
|
+
|
|
1612
2084
|
// ---- P3-1:跟她说一句话 ----
|
|
1613
2085
|
const send = async () => {
|
|
1614
2086
|
const t = sayText.trim()
|
|
@@ -1778,13 +2250,6 @@ window.__ModuleLoader__.load({
|
|
|
1778
2250
|
} finally { setBusy('') }
|
|
1779
2251
|
}
|
|
1780
2252
|
|
|
1781
|
-
if (err && !state) {
|
|
1782
|
-
return h('div', { className: 'dfish' },
|
|
1783
|
-
h('h2', null, '大肥鱼'),
|
|
1784
|
-
h('p', { className: 'sub' }, '读不到状态。'),
|
|
1785
|
-
h('pre', { className: 'err' }, err))
|
|
1786
|
-
}
|
|
1787
|
-
|
|
1788
2253
|
const s = state
|
|
1789
2254
|
const kv = (pairs) => h('div', { className: 'kv' },
|
|
1790
2255
|
pairs.filter(Boolean).flatMap(([k, v]) => [h('b', { key: 'k' + k }, k), h('span', { key: 'v' + k }, v)]))
|
|
@@ -2186,7 +2651,7 @@ window.__ModuleLoader__.load({
|
|
|
2186
2651
|
// 定时工具默认不放(m04504):放行才说「能」,没放行就说怎么开。
|
|
2187
2652
|
scheduleOn
|
|
2188
2653
|
? S('白名单里有 schedule_create:存好就生效,她能自己定提醒。')
|
|
2189
|
-
: S('想让她自己定提醒,把 schedule_create、schedule_list、
|
|
2654
|
+
: S('想让她自己定提醒,把 schedule_create、schedule_list、schedule_view、schedule_edit 加进白名单。默认不放,工具数不变。'),
|
|
2190
2655
|
'别的插件和技能启用,DSH会把它们的工具定义也塞进上下文——大肥鱼会看到一堆能做各种操作的工具,占用上下文的同时有可能真的尝试调用这些工具。',
|
|
2191
2656
|
'为了保证大肥鱼不会被插件能力污染,保持原生状态健康成长,禁用了其他能力(只影响和大肥鱼对话框的能力调用,不影响其他对话框的正常工具调用)。',
|
|
2192
2657
|
].filter(Boolean).map((line, i) =>
|
|
@@ -2402,7 +2867,7 @@ window.__ModuleLoader__.load({
|
|
|
2402
2867
|
onClick: wake,
|
|
2403
2868
|
disabled: busy === 'wake',
|
|
2404
2869
|
style: { flex: '0 0 auto' },
|
|
2405
|
-
title: S('马上叫醒她;不到 45 分钟、她在外面,或醒几次、事件数设成 0
|
|
2870
|
+
title: S('马上叫醒她;不到 45 分钟、她在外面,或醒几次、事件数设成 0 时,叫不醒。每天醒 0 次时这个按钮也叫不醒;直接跟她说话不受影响。'),
|
|
2406
2871
|
}, busy === 'wake' ? '叫醒中…' : '现在叫醒大肥鱼')
|
|
2407
2872
|
// 2026-10-24:这张卡**始终渲染**。之前整块挂在 `st ? … : null` 上,状态还没读到时
|
|
2408
2873
|
// 连「叫醒」按钮一起消失——一旦读取失败就没有入口,等于把人锁在门外。
|
|
@@ -2552,6 +3017,10 @@ window.__ModuleLoader__.load({
|
|
|
2552
3017
|
['memory', '记忆'],
|
|
2553
3018
|
['env', '插件'],
|
|
2554
3019
|
['principle', '原理'],
|
|
3020
|
+
// 2026-11-16(用户 m03816):原来这里还有第 10 个页签「说明」。
|
|
3021
|
+
// 他不要独立一页——「说明」挪到原理页最上面、三张图上方,
|
|
3022
|
+
// 而且不再在 App 里就地渲染那 62 条,只留一个蓝链,点一下由浏览器打开
|
|
3023
|
+
// (见下面 WikiLink 那一段注释:为什么只有回环小站这条路走得通)。
|
|
2555
3024
|
['data', '数据'],
|
|
2556
3025
|
['feedback', '反馈'],
|
|
2557
3026
|
]
|
|
@@ -2567,7 +3036,7 @@ window.__ModuleLoader__.load({
|
|
|
2567
3036
|
bili: S('上网:她翻视频、看画面、发评论,以及 B 站登录。'),
|
|
2568
3037
|
memory: '记忆:会话多久换新、身份段多长、记忆概况与体检。',
|
|
2569
3038
|
env: S('插件:她能用哪些工具,以及版本与更新。'),
|
|
2570
|
-
principle: S('
|
|
3039
|
+
principle: S('原理:她怎么长大、记忆怎么筛、理论出处。最上面有整套说明的入口。'),
|
|
2571
3040
|
data: '数据:位置、备份迁移、报告日志、导入与重置。',
|
|
2572
3041
|
feedback: '反馈:常见问题、找开发者、交流群。',
|
|
2573
3042
|
outing: S('出门:送她去别的工作区或对话干活;在外时家里的定时日程暂停。'),
|
|
@@ -2660,6 +3129,1096 @@ window.__ModuleLoader__.load({
|
|
|
2660
3129
|
// · 叫醒 → 状态卡右上角,因为它是针对「现在这个状态」的动作;
|
|
2661
3130
|
// · 保存 → 删掉,因为每个设置页底部本来就有「保存改动」,
|
|
2662
3131
|
// 顶上再放一个同样的按钮,只会让人猜「这两个是不是不一样」。
|
|
3132
|
+
const formatPressure = value => Number.isFinite(value)
|
|
3133
|
+
? value.toLocaleString(undefined, { maximumFractionDigits: 1 }) : '—'
|
|
3134
|
+
const signedPressure = value => Number.isFinite(value)
|
|
3135
|
+
? (value > 0 ? '+' : '') + formatPressure(value) : '—'
|
|
3136
|
+
const sample = pressure?.live ?? pressure?.current
|
|
3137
|
+
const lastRequest = pressure?.lastRequest
|
|
3138
|
+
const score = sample?.score
|
|
3139
|
+
const rows = pressure?.rows ?? []
|
|
3140
|
+
const growth = pressure?.growth ?? []
|
|
3141
|
+
const tools = pressure?.tools ?? []
|
|
3142
|
+
const recentDeltas = rows.map(row => row.delta).filter(Number.isFinite).slice(-5)
|
|
3143
|
+
const average = recentDeltas.length ? recentDeltas.reduce((sum, n) => sum + n, 0) / recentDeltas.length : null
|
|
3144
|
+
const latestUsage = pressure?.usage?.latest
|
|
3145
|
+
const usageHistory = pressure?.usage?.history ?? []
|
|
3146
|
+
const burden = pressure?.usage?.burden ?? []
|
|
3147
|
+
const reference = pressure?.usage?.reference
|
|
3148
|
+
const pressureMetric = (label, value, note) => h('div', { className: 'pressure-metric' },
|
|
3149
|
+
h('div', { className: 'hint' }, label),
|
|
3150
|
+
h('div', { className: 'pressure-value' }, value),
|
|
3151
|
+
note ? h('div', { className: 'hint' }, note) : null)
|
|
3152
|
+
const pressureTable = (columns, data) => h('div', { style: { overflowX: 'auto' } }, h('table', { className: 'pressure-table' },
|
|
3153
|
+
h('thead', null, h('tr', null, ...columns.map(label => h('th', { key: label, scope: 'col' }, label)))),
|
|
3154
|
+
h('tbody', null, ...data.map(([key, ...cells]) => h('tr', { key },
|
|
3155
|
+
...cells.map((value, i) => h('td', { key: i }, value)))))))
|
|
3156
|
+
const sessionLoad = pressure?.load
|
|
3157
|
+
const loadTabs = [['current', '当前'], ['history', '历史'], ['factors', '指标'], ['calculation', '计算']]
|
|
3158
|
+
const loadTabBar = h('div', { className: 'tabs load-tabs', role: 'group', 'aria-label': '会话压力视图' },
|
|
3159
|
+
...loadTabs.map(([id, label]) => h('button', { key: id, type: 'button',
|
|
3160
|
+
className: 'tab' + (pressureTab === id ? ' on' : ''), 'aria-pressed': pressureTab === id,
|
|
3161
|
+
onClick: () => setPressureTab(id) }, label)))
|
|
3162
|
+
|
|
3163
|
+
const contextDiagnostics = h('div', { className: 'load-panel' },
|
|
3164
|
+
sample || latestUsage || lastRequest || average != null ? h('details', { className: 'pressure-section' },
|
|
3165
|
+
h('summary', null, '查看上下文、Token 与采样覆盖'),
|
|
3166
|
+
h('div', { className: 'pressure-summary' },
|
|
3167
|
+
sample ? pressureMetric('上下文占用',
|
|
3168
|
+
Number.isFinite(score) ? formatPressure(score) + '%' : formatPressure(sample.tokens) + ' Token',
|
|
3169
|
+
Number.isFinite(sample.contextWindow)
|
|
3170
|
+
? formatPressure(sample.tokens) + ' / ' + formatPressure(sample.contextWindow) + ' Token(估算)'
|
|
3171
|
+
: '模型窗口未知') : null,
|
|
3172
|
+
sample ? pressureMetric('本会话压缩', data?.compactionCount ? `${data.compactionCount} 次` : '0 次', '宿主只在事件流里给压缩记录;如果还装了别的压缩插件,它们的数据不对外暴露') : null,
|
|
3173
|
+
sessionLoad?.usage.total != null ? pressureMetric('会话实报 Token',
|
|
3174
|
+
formatPressure(sessionLoad.usage.total) + ' Token',
|
|
3175
|
+
'完整用量覆盖 ' + sessionLoad.usage.complete + ' / ' + sessionLoad.usage.turns + ' 轮') : null,
|
|
3176
|
+
latestUsage?.total.value != null ? pressureMetric('上轮 Token 消耗',
|
|
3177
|
+
formatPressure(latestUsage.total.value) + ' Token',
|
|
3178
|
+
'第 ' + latestUsage.turn + ' 轮 · ' + (latestUsage.completeUsage ? '模型实报总量' : '部分用量'))
|
|
3179
|
+
: lastRequest ? pressureMetric('最近一次请求', formatPressure(lastRequest.total) + ' Token', '模型实报') : null),
|
|
3180
|
+
average != null ? h('p', { className: 'hint' }, '最近 ' + recentDeltas.length + ' 个可比较轮次平均增长 '
|
|
3181
|
+
+ signedPressure(average) + ' Token') : null,
|
|
3182
|
+
latestUsage?.amplification != null ? h('p', { className: 'hint' }, '消耗放大 ' + formatPressure(latestUsage.amplification)
|
|
3183
|
+
+ '×,即本轮总用量相当于首次请求输入的多少倍。') : null,
|
|
3184
|
+
latestUsage?.usageBreakdownMismatch ? h('p', { className: 'hint' },
|
|
3185
|
+
'模型返回的总量与输入、输出细分口径不一致,保留实报总量。') : null,
|
|
3186
|
+
latestUsage?.cache ? h('p', { className: 'hint' }, '缓存读取占比 '
|
|
3187
|
+
+ formatPressure(latestUsage.cache.ratio * 100) + '%(' + latestUsage.cache.reported + ' 次可核对请求)') : null,
|
|
3188
|
+
latestUsage && !latestUsage.usageBreakdownMismatch && latestUsage.input.value != null && latestUsage.output.value != null
|
|
3189
|
+
? h('p', { className: 'hint' }, '输入 ' + formatPressure(latestUsage.input.value) + ' · 输出 '
|
|
3190
|
+
+ formatPressure(latestUsage.output.value) + ' Token') : null,
|
|
3191
|
+
latestUsage?.cacheWrite.value != null ? h('p', { className: 'hint' }, '缓存写入 ' + formatPressure(latestUsage.cacheWrite.value) + ' Token') : null,
|
|
3192
|
+
latestUsage?.reasoning.value != null ? h('p', { className: 'hint' }, '推理 ' + formatPressure(latestUsage.reasoning.value) + ' Token') : null,
|
|
3193
|
+
latestUsage ? h('p', { className: 'hint' }, '模型请求步骤 ' + latestUsage.steps + ',已记录回复 ' + latestUsage.requests + ' 次') : null,
|
|
3194
|
+
latestUsage && (latestUsage.attempts || latestUsage.toolErrors || latestUsage.failed)
|
|
3195
|
+
? h('p', { className: 'hint' }, '无回复尝试 ' + latestUsage.attempts + ' 次,重试后有回复 '
|
|
3196
|
+
+ latestUsage.retries + ' 次,工具报错 ' + latestUsage.toolErrors + ' 次' + (latestUsage.failed ? ',本轮失败' : '')) : null,
|
|
3197
|
+
reference?.p90 != null ? h('p', { className: 'hint' }, '历史对照 · 大肥鱼已记录的 '
|
|
3198
|
+
+ reference.count + ' 轮里,约九成的单轮消耗不超过 ' + formatPressure(reference.p90) + ' Token。') : null) : null,
|
|
3199
|
+
growth.length ? h('section', { className: 'pressure-section' },
|
|
3200
|
+
h('h4', null, '压力增长最大的轮次'),
|
|
3201
|
+
pressureTable(['轮次', '轮末占用最大的工具结果', '净增长 Token'], growth.slice(0, 10).map(row => {
|
|
3202
|
+
const largest = (row.tools ?? []).reduce((best, item) => !best || item.tokens > best.tokens ? item : best, null)
|
|
3203
|
+
return [row.seq, '#' + row.turn, largest?.name ?? '—', signedPressure(row.delta)]
|
|
3204
|
+
}))) : null,
|
|
3205
|
+
null)
|
|
3206
|
+
const pressureHistory = h('details', { className: 'pressure-section' },
|
|
3207
|
+
h('summary', null, '历史 Session 范围'), h('section', { className: 'pressure-section' },
|
|
3208
|
+
h('h4', null, '工作区会话'),
|
|
3209
|
+
pressure?.usage?.discoveryPartial ? h('p', { className: 'hint' }, '会话发现不完整。') : null,
|
|
3210
|
+
pressureSelectionError ? h('p', { role: 'alert' }, '保存或刷新失败,请重试。') : null,
|
|
3211
|
+
h('div', { style: { display: 'flex', flexWrap: 'wrap', gap: '8px', marginBottom: '8px' } },
|
|
3212
|
+
h('button', { type: 'button', 'aria-pressed': showUncheckedPressure,
|
|
3213
|
+
onClick: () => setShowUncheckedPressure(!showUncheckedPressure) },
|
|
3214
|
+
(showUncheckedPressure ? '隐藏' : '显示') + '未勾选会话(' + usageHistory.filter(row => !row.current && !row.selected).length + ')'),
|
|
3215
|
+
h('button', { type: 'button', 'aria-pressed': showPressureIds,
|
|
3216
|
+
onClick: () => setShowPressureIds(!showPressureIds) }, showPressureIds ? '隐藏 ID' : '显示 ID')),
|
|
3217
|
+
h('div', { role: 'region', 'aria-label': '工作区会话列表', tabIndex: 0,
|
|
3218
|
+
style: { maxHeight: '16rem', overflowY: 'auto', overscrollBehaviorY: 'contain' } },
|
|
3219
|
+
pressureTable(['采纳', '会话', '归属', '分析'], usageHistory
|
|
3220
|
+
.filter(row => row.current || row.selected || showUncheckedPressure)
|
|
3221
|
+
.map(row => [row.id,
|
|
3222
|
+
row.current ? '当前会话' : h('input', { type: 'checkbox', checked: row.selected,
|
|
3223
|
+
disabled: pressureSaving, 'aria-label': '采纳会话 ' + (row.title || '未命名会话'),
|
|
3224
|
+
onChange: event => void selectPressureSession(row.id, event.target.checked) }),
|
|
3225
|
+
h('div', { style: { overflowWrap: 'anywhere' } }, row.title || '未命名会话',
|
|
3226
|
+
showPressureIds ? h('div', { className: 'hint' }, h('code', null, row.id)) : null),
|
|
3227
|
+
(row.fish ? 'Fish 房间' : '归属待确认') + (row.archived ? ' · 已归档' : ''),
|
|
3228
|
+
row.status === 'analyzed' ? row.usageTurns + ' / ' + row.turns
|
|
3229
|
+
: ({ unchecked: '未勾选', unavailable: '读取失败', 'too-large': '日志超出分析上限', excluded: '不支持的会话' }[row.status] ?? row.status)])))))
|
|
3230
|
+
|
|
3231
|
+
function dictionaryValue(value, unit) {
|
|
3232
|
+
if (!Number.isFinite(value)) return '—'
|
|
3233
|
+
const percent = unit === '%' || unit === '百分点'
|
|
3234
|
+
return formatPressure(percent ? 100 * value : value) + (unit === '%' ? '%' : ' ' + unit)
|
|
3235
|
+
}
|
|
3236
|
+
const dictionary = pressure?.usage?.dictionary ?? [
|
|
3237
|
+
['C', '上下文容量'], ['G', '增长负担'], ['U', 'Token 总消耗'],
|
|
3238
|
+
['A', '请求放大'], ['T', '工具结果残留'], ['K', '缓存复用负担'], ['E', '失败与恢复'],
|
|
3239
|
+
].map(([id, title]) => ({ id, title, rows: [] }))
|
|
3240
|
+
const pressureFactors = h('div', { className: 'load-panel' },
|
|
3241
|
+
...dictionary.map(metric => h('details', { key: metric.id, className: 'pressure-section' },
|
|
3242
|
+
h('summary', null, metric.id + ' · ' + metric.title,
|
|
3243
|
+
metric.rows.length ? ' · ' + dictionaryValue((metric.rows.find(row => row.value != null) ?? metric.rows[0]).value,
|
|
3244
|
+
(metric.rows.find(row => row.value != null) ?? metric.rows[0]).unit) : ''),
|
|
3245
|
+
metric.rows.length ? metric.rows.map((row, index) => h('details', { key: index, className: 'pressure-section' },
|
|
3246
|
+
h('summary', null, row.label + ' · ' + row.scope + ' · ' + dictionaryValue(row.value, row.unit)),
|
|
3247
|
+
pressureTable(['字段', '说明'], [
|
|
3248
|
+
['source', '获取位置', row.source], ['raw_value', '原始数据', row.raw_value == null ? '—' : JSON.stringify(row.raw_value)],
|
|
3249
|
+
['unit', '单位', row.unit], ['scope', '范围', row.scope], ['formula', '单项处理', row.formula],
|
|
3250
|
+
['availability', '可用性', row.availability], ['confidence', '可信度', row.confidence],
|
|
3251
|
+
]))) : h('p', { className: 'hint' }, '等待采集'),
|
|
3252
|
+
metric.id === 'A' ? h('details', { className: 'pressure-section' },
|
|
3253
|
+
h('summary', null, '历史逐轮请求放大'),
|
|
3254
|
+
(pressure?.usage?.amplificationHistory ?? []).map(session => h('details', { key: session.id },
|
|
3255
|
+
h('summary', null, session.title || '未命名会话', ' · ' + session.rows.length + ' 轮'),
|
|
3256
|
+
pressureTable(['轮次', '成功请求', '失败尝试', '首个输入', '追加输入', '放大率'],
|
|
3257
|
+
session.rows.map(row => [row.turn, row.turn, dictionaryValue(row.requests, '次'),
|
|
3258
|
+
dictionaryValue(row.attempts, '次'), dictionaryValue(row.first, 'Token'),
|
|
3259
|
+
dictionaryValue(row.extra, 'Token'),
|
|
3260
|
+
dictionaryValue(Number.isFinite(row.extra) && row.first > 0 ? row.extra / row.first : null, '%')]))))) : null)))
|
|
3261
|
+
|
|
3262
|
+
const { occupancy, growth: observedGrowth, windows: growthWindows } = capacityInputs(dictionary)
|
|
3263
|
+
const { gamma, horizon, lambda } = { ...pressureDefaults.capacity, ...capacityExperiment }
|
|
3264
|
+
const cInput = capacityExperiment.occupancy ?? occupancy
|
|
3265
|
+
const g = capacityExperiment.growth ?? observedGrowth
|
|
3266
|
+
const { capacity: c, cScore, remainingUse, score: capacityScore, forecast } = scoreCapacity(cInput, g, gamma, horizon, lambda)
|
|
3267
|
+
const scenario = capacityExperiment.occupancy != null || capacityExperiment.growth != null
|
|
3268
|
+
const forecastIncludesCompaction = growthWindows.some(window => window.compacted)
|
|
3269
|
+
function experimentNumber(state, setState, key, label, value, min, max, step, unit) {
|
|
3270
|
+
return h('label', null, label + ' ',
|
|
3271
|
+
h('input', { type: 'number', min, max, step, value: state[key] ?? (value == null ? '' : Number(value.toFixed(2))),
|
|
3272
|
+
onChange: event => {
|
|
3273
|
+
const input = event.currentTarget
|
|
3274
|
+
const number = input.valueAsNumber
|
|
3275
|
+
if (input.value && (!Number.isFinite(number) || number < min || number > max)) return
|
|
3276
|
+
const value = input.value ? number : undefined
|
|
3277
|
+
setState(previous => {
|
|
3278
|
+
const next = { ...previous }
|
|
3279
|
+
if (value == null) delete next[key]
|
|
3280
|
+
else next[key] = value
|
|
3281
|
+
return next
|
|
3282
|
+
})
|
|
3283
|
+
} }), ' ' + unit)
|
|
3284
|
+
}
|
|
3285
|
+
const capacityCalculation = h('section', { className: 'card load-panel', style: { minWidth: 0 } },
|
|
3286
|
+
h('h4', null, 'C + G · 容量压力(试算)'),
|
|
3287
|
+
h('p', { className: 'hint' }, scenario ? '使用情景输入。' : '使用当前会话采样。'),
|
|
3288
|
+
h('div', { style: { display: 'flex', flexWrap: 'wrap', gap: '12px' } },
|
|
3289
|
+
experimentNumber(capacityExperiment, setCapacityExperiment, 'occupancy', '当前占用', cInput, 0, Math.max(100, cInput ?? 0), 'any', '%'),
|
|
3290
|
+
experimentNumber(capacityExperiment, setCapacityExperiment, 'growth', '每轮净增长', g, -100, 100, 'any', '百分点/轮'),
|
|
3291
|
+
experimentNumber(capacityExperiment, setCapacityExperiment, 'gamma', '曲线指数 γ', gamma, .1, 10, .1, ''),
|
|
3292
|
+
experimentNumber(capacityExperiment, setCapacityExperiment, 'horizon', '预测轮数 H', horizon, 1, 100, 1, '轮'),
|
|
3293
|
+
experimentNumber(capacityExperiment, setCapacityExperiment, 'lambda', '修正强度 λ', lambda, 0, 1, .01, ''),
|
|
3294
|
+
h('button', { type: 'button', onClick: () => setCapacityExperiment({}) }, '重置')),
|
|
3295
|
+
h('div', { className: 'pressure-summary' },
|
|
3296
|
+
pressureMetric('纯容量压力 C', cScore == null ? '—' : formatPressure(cScore) + ' / 100', '100 × c^γ'),
|
|
3297
|
+
pressureMetric('容量压力 C + G', capacityScore == null ? '—' : formatPressure(capacityScore) + ' / 100',
|
|
3298
|
+
c != null && c < 1 && !Number.isFinite(g) ? '缺少可比增长数据' : '实验参数,尚未校准'),
|
|
3299
|
+
pressureMetric('预计消耗剩余空间', dictionaryValue(remainingUse, '%'),
|
|
3300
|
+
c === 1 ? '当前已无剩余窗口' : '未来 ' + horizon + ' 轮,按当前增长速度'),
|
|
3301
|
+
pressureMetric('预计窗口占用', dictionaryValue(forecast, '%'), '未来 ' + horizon + ' 轮的情景值' + (forecastIncludesCompaction ? ' · 包含压缩事件' : ''))),
|
|
3302
|
+
h('details', { className: 'pressure-section' },
|
|
3303
|
+
h('summary', null, '公式与取样 · ' + pressureVersions.capacity),
|
|
3304
|
+
h('p', null, 'c = 当前请求输入 ÷ 有效窗口。原始占用可超过 100%,评分输入封顶为 100%。'),
|
|
3305
|
+
h('p', null, 'g = Σ(可用窗口增长 × 权重)÷ Σ 可用权重。窗口内仅使用已有的可比轮差值。'),
|
|
3306
|
+
pressureTable(['窗口', '平均净增长', '可比差值数', '初始权重'], growthWindows.map(window =>
|
|
3307
|
+
[window.rounds, window.rounds + ' 轮', dictionaryValue(window.value, '百分点'), window.pairs,
|
|
3308
|
+
dictionaryValue(window.weight, '%')])),
|
|
3309
|
+
h('p', null, 'G_H = clamp(H × max(g, 0) ÷ [100 × (1 − c)], 0, 1)。P_C = 100 × [1 − (1 − c^γ) × (1 − λ × G_H)]。c = 1 时直接取 100 分。'),
|
|
3310
|
+
h('p', null, 'H 是情景观察长度,尚未验证适用于换房决策。G_H 达到 1 后不再增加,增长修正系数最多为 λ(默认 0.35)。即使预计触顶,容量压力也未必很高,这一特性待历史数据验证。'),
|
|
3311
|
+
h('p', null, '未来占用 = clamp(c + H × g ÷ 100, 0, 1)。这是固定增长速度下的情景推演。')),
|
|
3312
|
+
forecastIncludesCompaction
|
|
3313
|
+
? h('p', { className: 'hint' }, '近期取样窗口包含压缩事件(成功压缩或裁剪),净增长仍沿用原有口径。未来趋势可能变化。') : null)
|
|
3314
|
+
|
|
3315
|
+
const requestData = pressure?.usage?.requestBurden
|
|
3316
|
+
const { rho, beta, tau, recentWeight } = { ...pressureDefaults.request, ...requestExperiment }
|
|
3317
|
+
const requestWindow = requestData?.window
|
|
3318
|
+
const { all: allRequestBounds, recent: recentRequestBounds, ratios: requestRatios, scores: requestScores }
|
|
3319
|
+
= scoreRequestBurden(requestData, rho, beta, tau, recentWeight)
|
|
3320
|
+
const neutralScore = scoreRequestBurden(requestData, 1, beta, tau, recentWeight).scores?.[1] ?? null
|
|
3321
|
+
const cacheIntervalWidth = requestScores ? requestScores[1] - requestScores[0] : null
|
|
3322
|
+
const requestRange = requestScores
|
|
3323
|
+
? formatPressure(requestScores[0]) + '–' + formatPressure(requestScores[1]) + ' / 100' : '—'
|
|
3324
|
+
const requestCalculation = h('section', { className: 'card load-panel', style: { minWidth: 0 } },
|
|
3325
|
+
h('h4', null, 'U + A + K · 当前会话请求负担'),
|
|
3326
|
+
h('p', { className: 'hint' }, '基于当前会话用量 · 实验评分'),
|
|
3327
|
+
h('div', { style: { display: 'flex', flexWrap: 'wrap', gap: '12px' } },
|
|
3328
|
+
experimentNumber(requestExperiment, setRequestExperiment, 'rho', '缓存折算 ρ', rho, 0, 1, .01, ''),
|
|
3329
|
+
experimentNumber(requestExperiment, setRequestExperiment, 'beta', '输出折算 β', beta, 0, Number.MAX_VALUE, 'any', ''),
|
|
3330
|
+
experimentNumber(requestExperiment, setRequestExperiment, 'tau', '评分尺度 τ', tau, .001, Number.MAX_VALUE, 'any', ''),
|
|
3331
|
+
experimentNumber(requestExperiment, setRequestExperiment, 'recentWeight', '近期权重', recentWeight, 0, 1, .01, ''),
|
|
3332
|
+
h('button', { type: 'button', onClick: () => setRequestExperiment({}) }, '重置')),
|
|
3333
|
+
rho === 1 ? h('p', { className: 'hint' }, '缓存修正未启用(ρ = 1),当前评分不区分缓存命中与未命中。') : null,
|
|
3334
|
+
pressureTable(['计算模式', '压力分'], [
|
|
3335
|
+
['neutral', '不区分缓存(ρ = 1)', formatPressure(neutralScore)],
|
|
3336
|
+
['current', '当前缓存折算(保守估计)', formatPressure(requestScores?.[1])],
|
|
3337
|
+
['lower', '缓存缺报下界', formatPressure(requestScores?.[0])],
|
|
3338
|
+
['upper', '缓存缺报上界', formatPressure(requestScores?.[1])],
|
|
3339
|
+
]),
|
|
3340
|
+
h('div', { className: 'pressure-summary' },
|
|
3341
|
+
pressureMetric('请求负担', requestScores ? formatPressure(requestScores[1]) + ' / 100' : '—',
|
|
3342
|
+
requestScores ? '缓存未知输入按全额折算(保守上界)' : '有效窗口或成功请求用量不足'),
|
|
3343
|
+
pressureMetric('缓存缺报下的区间', requestRange, rho < 1 && cacheIntervalWidth != null
|
|
3344
|
+
? '区间宽度 ' + formatPressure(cacheIntervalWidth) + ' 分' : '随缓存折算系数变化'),
|
|
3345
|
+
pressureMetric('加权窗口数', dictionaryValue(requestRatios?.[1], '个窗口'), '长期与近期的平均负担折算'),
|
|
3346
|
+
pressureMetric('参照窗口', dictionaryValue(requestWindow, 'Token'), '最近有用量的请求所用窗口')),
|
|
3347
|
+
h('details', { className: 'pressure-section' },
|
|
3348
|
+
h('summary', null, '公式与取样 · ' + pressureVersions.request),
|
|
3349
|
+
pressureTable(['范围', '已完成轮', '缓存报告', '未知缓存输入', '平均负担上界'], [
|
|
3350
|
+
['lifetime', '全会话', requestData?.all, allRequestBounds],
|
|
3351
|
+
['recent', '最近 10 轮', requestData?.recent, recentRequestBounds],
|
|
3352
|
+
].map(([key, label, sample, bounds]) => [key, label, sample?.rounds ?? '—',
|
|
3353
|
+
sample?.requests > 0 ? sample.cacheReports + ' / ' + sample.requests + ' 次('
|
|
3354
|
+
+ dictionaryValue(sample.cacheReports / sample.requests, '%') + ')' : '—',
|
|
3355
|
+
dictionaryValue(sample?.unknownInput, 'Token'), dictionaryValue(bounds?.[1], 'Token/轮')])),
|
|
3356
|
+
h('p', null, 'L = 已知未命中输入 + ρ × 已知命中输入 + β × 输出 + 未知缓存输入的折算。上下界分别给未知部分乘 ρ 和 1。'),
|
|
3357
|
+
h('p', null, 'R =(长期权重 × 全会话平均负担 + 近期权重 × 最近 10 轮平均负担)÷ 参照窗口。P_R = 100 × (1 − exp(−R / τ))。'),
|
|
3358
|
+
h('p', null, '仅计已完成用户轮里的成功请求。A 的追加输入计入总用量。C 与请求负担都包含首次输入的影响,综合评分时需考虑重叠。')))
|
|
3359
|
+
const structureData = pressure?.usage?.structurePressure
|
|
3360
|
+
const invalidStructure = structureData?.measurementStatus === 'invalid'
|
|
3361
|
+
const { toolWeight, epsilon, eta } = { ...pressureDefaults.structure, ...structureExperiment }
|
|
3362
|
+
const structurePercent = (key, ratio) => structureExperiment[key]
|
|
3363
|
+
?? (Number.isFinite(ratio) ? 100 * ratio : null)
|
|
3364
|
+
const currentToolPercent = structurePercent('current', structureData?.currentShare)
|
|
3365
|
+
const repeatedToolPercent = structurePercent('repeated', structureData?.repeatedShare)
|
|
3366
|
+
const retryPercent = structurePercent('retry', structureData?.retryShare)
|
|
3367
|
+
const { tool: toolStructure, failure: failureStructure, score: structureScore }
|
|
3368
|
+
= scoreStructure(invalidStructure ? null : currentToolPercent, invalidStructure ? null : repeatedToolPercent,
|
|
3369
|
+
retryPercent, toolWeight, epsilon, eta)
|
|
3370
|
+
const structureScenario = ['current', 'repeated', 'retry'].some(key => structureExperiment[key] != null)
|
|
3371
|
+
const scoreText = value => Number.isFinite(value) ? formatPressure(value) + ' / 100' : '—'
|
|
3372
|
+
const structureCalculation = h('section', { className: 'card load-panel', style: { minWidth: 0 } },
|
|
3373
|
+
h('h4', null, 'T + E · 当前会话结构与稳定性'),
|
|
3374
|
+
h('p', { className: 'hint' }, structureScenario ? '使用情景输入 · 实验评分' : '基于当前会话用量 · 实验评分'),
|
|
3375
|
+
invalidStructure ? h('p', { role: 'alert' }, '工具残留数据异常,T + E 和 A/B/C 分数无效。') : null,
|
|
3376
|
+
structureData?.measurementReason === 'empty-request-surface'
|
|
3377
|
+
? h('p', { className: 'hint' }, '该请求有实报用量,但缺少可见消息,当前工具残留未知。')
|
|
3378
|
+
: structureData?.measurementReason === 'incomplete-request-surface'
|
|
3379
|
+
? h('p', { className: 'hint' }, '该请求的可见消息重建不完整,当前工具残留未知。') : null,
|
|
3380
|
+
h('div', { style: { display: 'flex', flexWrap: 'wrap', gap: '12px' } },
|
|
3381
|
+
experimentNumber(structureExperiment, setStructureExperiment, 'current', '当前残留占比', currentToolPercent, 0, 100, 'any', '%'),
|
|
3382
|
+
experimentNumber(structureExperiment, setStructureExperiment, 'repeated', '历史重复携带占比', repeatedToolPercent, 0, 100, 'any', '%'),
|
|
3383
|
+
experimentNumber(structureExperiment, setStructureExperiment, 'toolWeight', '当前结构权重', toolWeight, 0, 1, .01, ''),
|
|
3384
|
+
experimentNumber(structureExperiment, setStructureExperiment, 'retry', '重试消耗比例', retryPercent, 0, 100, 'any', '%'),
|
|
3385
|
+
experimentNumber(structureExperiment, setStructureExperiment, 'epsilon', '异常敏感度 ε', epsilon, .001, 1, .001, ''),
|
|
3386
|
+
experimentNumber(structureExperiment, setStructureExperiment, 'eta', '异常修正强度 η', eta, 0, 1, .01, ''),
|
|
3387
|
+
h('button', { type: 'button', onClick: () => setStructureExperiment({}) }, '重置')),
|
|
3388
|
+
h('div', { className: 'pressure-summary' },
|
|
3389
|
+
pressureMetric('结构负担 T', scoreText(toolStructure == null ? null : 100 * toolStructure), '当前残留和历史重复携带'),
|
|
3390
|
+
pressureMetric('失败负担 E', scoreText(failureStructure == null ? null : 100 * failureStructure), '已归因失败尝试用量'),
|
|
3391
|
+
pressureMetric('复合压力', scoreText(structureScore), structureScore == null ? '缺少计算所需的会话读数' : '实验参数,尚未校准')),
|
|
3392
|
+
h('details', { className: 'pressure-section' },
|
|
3393
|
+
h('summary', null, '公式与取样 · ' + pressureVersions.structure),
|
|
3394
|
+
h('p', null, 'T_s = w_t × 当前残留占比 + (1 − w_t) × 历史重复携带占比。比例超出 0–100% 时评分无效。'),
|
|
3395
|
+
h('p', null, 'E_s = 1 − exp(−重试消耗比例 / ε)。P_Q = 100 × [1 − (1 − T_s) × (1 − η × E_s)]。'),
|
|
3396
|
+
pressureTable(['来源', '分子', '分母'], [
|
|
3397
|
+
['current-tool', '当前残留(同请求估算)', dictionaryValue(structureData?.retainedTokens, 'Token'), dictionaryValue(structureData?.currentInput, 'Token')],
|
|
3398
|
+
['history-tool', '跨轮重复携带(请求估算)', dictionaryValue(structureData?.pairedCarry, 'Token·次'), dictionaryValue(structureData?.pairedInput, 'Token·次')],
|
|
3399
|
+
['retry-tokens', '已归因重试', dictionaryValue(structureData?.retryTokens, 'Token'), dictionaryValue(structureData?.regularTokens, 'Token')],
|
|
3400
|
+
]),
|
|
3401
|
+
h('p', null, '模型实报请求输入 ' + dictionaryValue(structureData?.reportedInput, 'Token')
|
|
3402
|
+
+ ',单独显示。工具残留使用同口径估算分母。'),
|
|
3403
|
+
structureData?.measurementStatus === 'estimated' ? h('p', null, structureData.matchedDispatch
|
|
3404
|
+
? '采样边界为该请求的首个响应事件。'
|
|
3405
|
+
: '该请求缺少流式首事件,按日志中回复写入前的可见上下文重建。') : null,
|
|
3406
|
+
h('p', null, '历史重复携带只使用有输入用量且能重建工具上下文的成功请求。匹配 '
|
|
3407
|
+
+ (structureData?.pairedRequests ?? '—') + ' / ' + (structureData?.requestCount ?? '—') + ' 次。'),
|
|
3408
|
+
h('p', null, '工具结果大小为估算。残留比例和失败次数用于描述负担,内容质量和换房收益尚无校准。')),
|
|
3409
|
+
h('details', { className: 'pressure-section' },
|
|
3410
|
+
h('summary', null, '残留年龄与显式失败率'),
|
|
3411
|
+
pressureTable(['诊断指标', '当前读数'], [
|
|
3412
|
+
['age-mean', 'Token 加权平均年龄', dictionaryValue(structureData?.ages?.mean, '轮')],
|
|
3413
|
+
['age-median', 'Token 加权年龄中位数', dictionaryValue(structureData?.ages?.median, '轮')],
|
|
3414
|
+
...(structureData?.ages?.older ?? []).map(item =>
|
|
3415
|
+
['age-' + item.rounds, '超过 ' + item.rounds + ' 轮的残留 Token 占比', dictionaryValue(item.share, '%')]),
|
|
3416
|
+
['model-failure', '模型失败率', dictionaryValue(structureData?.modelFailureRate, '%')],
|
|
3417
|
+
['tool-failure', '工具失败率', dictionaryValue(structureData?.toolFailureRate, '%')],
|
|
3418
|
+
])))
|
|
3419
|
+
const scoreOf = value => Number.isFinite(value) ? (Math.round((value + Math.abs(value) * Number.EPSILON) * 10) / 10).toFixed(1) : '—'
|
|
3420
|
+
const pointText = value => Number.isFinite(value) ? scoreOf(100 * value) : '—'
|
|
3421
|
+
const signedScore = value => Number.isFinite(value) ? (value < 0 ? '−' : '+') + scoreOf(Math.abs(value)) : '—'
|
|
3422
|
+
const compositeParameters = Object.fromEntries(Object.entries(compositeDefaults).map(([id, defaults]) => [
|
|
3423
|
+
id, { ...defaults, ...compositeExperiment[id] },
|
|
3424
|
+
]))
|
|
3425
|
+
const subScores = [capacityScore, requestScores?.[1], structureScore]
|
|
3426
|
+
const compositeScores = scoreComposite(subScores, compositeParameters, invalidStructure)
|
|
3427
|
+
const plans = [
|
|
3428
|
+
['A', '分层加权', 'P_A = 100 × (w_c c + w_r r + w_q q) / (w_c + w_r + w_q)',
|
|
3429
|
+
{ wc: '容量权重 w_c', wr: '请求权重 w_r', wq: '结构权重 w_q' },
|
|
3430
|
+
['容量、请求、结构贡献(分):' + (compositeScores.A.contributions?.map(pointText).join(' / ') ?? '—')]],
|
|
3431
|
+
['B', '非线性合成', 'P_B = 100 × [1 − (1−c)^w_c × (1−r)^w_r × (1−q)^w_q]',
|
|
3432
|
+
{ wc: '容量风险强度 w_c', wr: '请求风险强度 w_r', wq: '结构风险强度 w_q' },
|
|
3433
|
+
['容量、请求、结构剩余因子:' + compositeScores.B.factors.map(value => value?.toFixed(4) ?? '—').join(' × '),
|
|
3434
|
+
'乘积:' + (compositeScores.B.product?.toFixed(4) ?? '—')]],
|
|
3435
|
+
['C', '容量主导修正', 'M = (w_r r + w_q q) / (w_r + w_q);P_C* = 100 × [c + μ(1−c)M]',
|
|
3436
|
+
{ wr: '请求权重 w_r', wq: '结构权重 w_q', mu: '修正强度 μ' },
|
|
3437
|
+
['联合修正 M:' + (compositeScores.C.mix?.toFixed(4) ?? '—'),
|
|
3438
|
+
'基础容量压力:' + pointText(compositeScores.C.base),
|
|
3439
|
+
'请求与结构修正:' + signedScore(compositeScores.C.correction == null ? null : 100 * compositeScores.C.correction)]],
|
|
3440
|
+
]
|
|
3441
|
+
const comparison = pressure?.usage?.comparison
|
|
3442
|
+
const latestRound = comparison?.rounds ?? 0
|
|
3443
|
+
const viewingRound = Math.min(latestRound, trendConfig.round ?? latestRound)
|
|
3444
|
+
const earlierRound = viewingRound > 0 && viewingRound < latestRound
|
|
3445
|
+
const trendChoices = (pressure?.usage?.history ?? []).filter(row => row.current || row.selected)
|
|
3446
|
+
const currentTrendId = trendChoices.find(row => row.current)?.id
|
|
3447
|
+
const isScenario = scenario || structureScenario
|
|
3448
|
+
const childParameters = { capacity: { gamma, horizon, lambda }, request: { rho, beta, tau, recentWeight },
|
|
3449
|
+
structure: { toolWeight, epsilon, eta } }
|
|
3450
|
+
const historyPage = trendConfig.historyPage ?? 'compare'
|
|
3451
|
+
const historyActive = pressureTab === 'history'
|
|
3452
|
+
const wantBacktest = historyActive && historyPage === 'backtest'
|
|
3453
|
+
const wantAttribution = historyActive && historyPage === 'attribution'
|
|
3454
|
+
const trendMulti = trendConfig.multi ?? historyActive
|
|
3455
|
+
const currentDiagnostic = earlierRound ? trendData[currentTrendId]?.points[viewingRound - 1]?.snapshot : comparison?.current
|
|
3456
|
+
const scoreSnapshot = snapshot => scoreComposite(scoreDiagnostic(snapshot.inputs, childParameters), compositeParameters,
|
|
3457
|
+
snapshot.inputs.invalidStructure)
|
|
3458
|
+
const currentHistoryScores = currentDiagnostic ? scoreSnapshot(currentDiagnostic) : {}
|
|
3459
|
+
const eligible = Object.values(currentHistoryScores).some(value => Number.isFinite(value.score))
|
|
3460
|
+
const reasonText = {
|
|
3461
|
+
short: '该 Session 尚未达到所选轮次', missing: '该轮诊断数据缺失',
|
|
3462
|
+
pending: '该轮分析尚未完成', unavailable: '该轮必要数据无法重建',
|
|
3463
|
+
filtered: '用户主动筛选排除(模型或窗口不同)', version: '数据版本不支持重新计算',
|
|
3464
|
+
}
|
|
3465
|
+
const historical = (comparison?.history ?? []).map(row => {
|
|
3466
|
+
const series = trendData[row.id]
|
|
3467
|
+
const snapshot = earlierRound ? series?.points[viewingRound - 1]?.snapshot : row.snapshot
|
|
3468
|
+
const reason = earlierRound ? !series ? 'pending' : series.status !== 'analyzed' ? 'unavailable'
|
|
3469
|
+
: series.points.length < viewingRound ? 'short' : 'missing' : row.reason ?? 'missing'
|
|
3470
|
+
if (!snapshot) return { ...row, reason: reasonText[reason] }
|
|
3471
|
+
if (!currentDiagnostic) return { ...row, reason: reasonText.missing }
|
|
3472
|
+
if (!sameRoundDiagnostic(currentDiagnostic, snapshot)) return { ...row, reason: reasonText.version }
|
|
3473
|
+
if (trendConfig.strict && !sameRoundDiagnostic(currentDiagnostic, snapshot, true)) return { ...row, reason: reasonText.filtered }
|
|
3474
|
+
const scores = scoreSnapshot(snapshot)
|
|
3475
|
+
if (!Object.values(scores).some(value => Number.isFinite(value.score))) return { ...row, reason: reasonText.missing }
|
|
3476
|
+
return { ...row, scores, mismatch: !currentDiagnostic.route || currentDiagnostic.route !== snapshot.route
|
|
3477
|
+
|| snapshot.configurationChanged || currentDiagnostic.configurationChanged }
|
|
3478
|
+
})
|
|
3479
|
+
const comparable = eligible ? historical.filter(row => row.scores && plans.some(([id]) =>
|
|
3480
|
+
Number.isFinite(currentHistoryScores[id]?.score) && Number.isFinite(row.scores[id].score))) : []
|
|
3481
|
+
const schemeStats = Object.fromEntries(plans.map(([id]) => [
|
|
3482
|
+
id, pressureStatistics(currentHistoryScores[id]?.score, Number.isFinite(currentHistoryScores[id]?.score)
|
|
3483
|
+
? comparable.map(row => row.scores[id].score) : []),
|
|
3484
|
+
]))
|
|
3485
|
+
const sampleHint = count => count === 0 ? '暂无可比样本' : count < 5 ? '样本极少,仅供参考' : count < 20 ? '样本有限' : '同轮可比样本'
|
|
3486
|
+
const homeSchemeStats = Object.fromEntries(plans.map(([id]) => {
|
|
3487
|
+
const latest = comparison?.current
|
|
3488
|
+
const score = latest ? scoreSnapshot(latest)[id]?.score : null
|
|
3489
|
+
const values = (comparison?.history ?? []).filter(row => row.snapshot && sameRoundDiagnostic(latest, row.snapshot, trendConfig.strict))
|
|
3490
|
+
return [id, pressureStatistics(score, Number.isFinite(score) ? values.map(row => scoreSnapshot(row.snapshot)[id]?.score) : [])]
|
|
3491
|
+
}))
|
|
3492
|
+
const trendIds = trendMulti
|
|
3493
|
+
? (trendConfig.ids ?? (currentTrendId ? [currentTrendId] : [])).filter(id => trendChoices.some(row => row.id === id))
|
|
3494
|
+
: currentTrendId ? [currentTrendId] : []
|
|
3495
|
+
const attributionId = trendChoices.some(row => row.id === trendConfig.attributionId)
|
|
3496
|
+
? trendConfig.attributionId : currentTrendId ?? trendChoices[0]?.id
|
|
3497
|
+
const loadedIds = wantAttribution ? [attributionId].filter(Boolean)
|
|
3498
|
+
: wantBacktest || (historyActive && historyPage === 'same' && earlierRound)
|
|
3499
|
+
|| (historyActive && historyPage === 'compare' && trendConfig.median && !trendMulti)
|
|
3500
|
+
? trendChoices.map(row => row.id)
|
|
3501
|
+
: historyActive && historyPage === 'compare' ? trendIds
|
|
3502
|
+
: pressureTab === 'current' && currentTrendId ? [currentTrendId] : []
|
|
3503
|
+
const trendRequestKey = JSON.stringify(loadedIds)
|
|
3504
|
+
useEffect(() => {
|
|
3505
|
+
if (tab !== 'memory' || !pressureOpen || !loadedIds.length) return
|
|
3506
|
+
let active = true
|
|
3507
|
+
setTrendLoading(true)
|
|
3508
|
+
async function loadTrends() {
|
|
3509
|
+
const data = Object.create(null)
|
|
3510
|
+
for (const id of JSON.parse(trendRequestKey)) {
|
|
3511
|
+
if (!active) return
|
|
3512
|
+
try { data[id] = await jget('/session-pressure?trend=' + encodeURIComponent(id) + (wantAttribution ? '&diagnostics=1' : '')) }
|
|
3513
|
+
catch { data[id] = { status: 'unavailable', points: [] } }
|
|
3514
|
+
}
|
|
3515
|
+
if (active) {
|
|
3516
|
+
setTrendData(previous => ({ ...previous, ...data }))
|
|
3517
|
+
setTrendLoading(false)
|
|
3518
|
+
}
|
|
3519
|
+
}
|
|
3520
|
+
void loadTrends()
|
|
3521
|
+
return () => { active = false }
|
|
3522
|
+
}, [wantAttribution, tab, pressureOpen, trendRequestKey, comparison?.rounds, pressureRefresh])
|
|
3523
|
+
|
|
3524
|
+
const schemeColors = { A: '#3589e6', B: '#c96a11', C: '#24885d' }
|
|
3525
|
+
const sessionColors = ['#3589e6', '#c96a11', '#24885d', '#9a55cb', '#c94e76']
|
|
3526
|
+
const changeTrend = patch => setTrendConfig(previous => ({ ...previous, ...patch }))
|
|
3527
|
+
const displayedPlans = !trendMulti && !trendConfig.plan ? ['A', 'B', 'C'] : [trendConfig.plan ?? 'A']
|
|
3528
|
+
const trendScoreKey = JSON.stringify([childParameters, compositeParameters])
|
|
3529
|
+
const scoredTrends = React.useMemo(() => Object.fromEntries(Object.entries(trendData).map(([id, data]) => [
|
|
3530
|
+
id, (data.points ?? []).map(point => {
|
|
3531
|
+
const snapshot = point.snapshot
|
|
3532
|
+
const children = snapshot ? scoreDiagnostic(snapshot.inputs, childParameters) : null
|
|
3533
|
+
return { ...point, children, eligible: children?.every(Number.isFinite) ?? false,
|
|
3534
|
+
scores: children ? scoreComposite(children, compositeParameters, snapshot.inputs.invalidStructure) : null }
|
|
3535
|
+
}),
|
|
3536
|
+
])), [trendData, trendScoreKey])
|
|
3537
|
+
const backtestIds = JSON.stringify(trendChoices.filter(row => !row.current).map(row => row.id))
|
|
3538
|
+
const records = React.useMemo(() => wantBacktest || (wantAttribution && trendConfig.attributionForecast)
|
|
3539
|
+
? pressureBacktestRecords(JSON.parse(backtestIds).map(id => [id, scoredTrends[id] ?? []]), compositeParameters)
|
|
3540
|
+
: [], [wantBacktest, wantAttribution, trendConfig.attributionForecast, backtestIds, scoredTrends, trendScoreKey])
|
|
3541
|
+
const methodLabels = { linear5: '最近 5 轮线性', linear10: '最近 10 轮线性', weighted: '5 / 10 / 20 轮加权' }
|
|
3542
|
+
const groupLabels = { overall: '全部', before: '压缩或裁剪前', after: '压缩或裁剪后', neither: '两者皆无' }
|
|
3543
|
+
const backtestGroup = trendConfig.backtestGroup ?? 'overall'
|
|
3544
|
+
const backtestPlan = trendConfig.backtestPlan ?? 'A'
|
|
3545
|
+
const methods = trendConfig.backtestMethods ?? backtestMethods
|
|
3546
|
+
const methodsKey = methods.join(',')
|
|
3547
|
+
const backtestSelection = React.useMemo(() => {
|
|
3548
|
+
const selected = records.filter(row => row.plan === backtestPlan && methods.includes(row.method)
|
|
3549
|
+
&& row.groups.includes(backtestGroup))
|
|
3550
|
+
return trendConfig.backtestCommon ? commonPressureBacktestRecords(selected, methods) : selected
|
|
3551
|
+
}, [records, methodsKey, backtestPlan, backtestGroup, trendConfig.backtestCommon])
|
|
3552
|
+
const backtest = React.useMemo(() => summarizePressureBacktest(backtestSelection).filter(row =>
|
|
3553
|
+
row.plan === backtestPlan && methods.includes(row.method)), [backtestSelection, methodsKey, backtestPlan])
|
|
3554
|
+
const barColors = { 5: '#3589e6', 10: '#c96a11', 20: '#24885d' }
|
|
3555
|
+
function backtestBars(metric, label) {
|
|
3556
|
+
const signed = metric === 'bias'
|
|
3557
|
+
const height = 190
|
|
3558
|
+
const values = backtest.map(row => row.groups[backtestGroup][metric]).filter(Number.isFinite)
|
|
3559
|
+
const limit = Math.max(1, Math.ceil(Math.max(0, ...values.map(Math.abs)) * 10) / 10)
|
|
3560
|
+
const y = value => 20 + height * (limit - value) / (signed ? 2 * limit : limit)
|
|
3561
|
+
const zero = y(0)
|
|
3562
|
+
const ticks = signed ? [-limit, -limit / 2, 0, limit / 2, limit] : [0, limit / 2, limit]
|
|
3563
|
+
return h('section', { className: 'pressure-section' },
|
|
3564
|
+
h('h4', null, label + '(压力分)'),
|
|
3565
|
+
h('svg', { viewBox: '0 0 680 250', role: 'group', 'aria-label': label, style: { width: '100%' } },
|
|
3566
|
+
...ticks.map(tick => h('g', { key: tick },
|
|
3567
|
+
h('line', { x1: 58, x2: 660, y1: y(tick), y2: y(tick), stroke: 'currentColor',
|
|
3568
|
+
opacity: tick === 0 ? .85 : .2, strokeWidth: tick === 0 ? 2 : 1 }),
|
|
3569
|
+
h('text', { x: 51, y: y(tick) + 4, textAnchor: 'end', fill: 'currentColor', fontSize: 12 },
|
|
3570
|
+
tick === 0 ? '0' : (signed ? signedScore(tick) : scoreOf(tick))))),
|
|
3571
|
+
...methods.map((method, index) => h('text', { key: method, x: 58 + (index + .5) * 602 / methods.length,
|
|
3572
|
+
y: 235, fill: 'currentColor', textAnchor: 'middle', fontSize: 13 }, methodLabels[method])),
|
|
3573
|
+
...backtest.map(row => {
|
|
3574
|
+
const result = row.groups[backtestGroup]
|
|
3575
|
+
const value = result[metric]
|
|
3576
|
+
const x = 58 + (methods.indexOf(row.method) + .5) * 602 / methods.length
|
|
3577
|
+
+ (backtestHorizons.indexOf(row.horizon) - 1) * 47
|
|
3578
|
+
const title = methodLabels[row.method] + ' · 提前 ' + row.horizon + ' 轮 · ' + label + ' '
|
|
3579
|
+
+ (signed ? signedScore(value) : scoreOf(value)) + ' · ' + result.count + ' 次预测 · ' + result.sessions + ' 个 Session'
|
|
3580
|
+
if (!Number.isFinite(value)) return h('text', { key: row.method + row.horizon, x, y: zero - 5,
|
|
3581
|
+
textAnchor: 'middle', fill: 'currentColor', fontSize: 12 }, '—')
|
|
3582
|
+
const barHeight = value === 0 ? 2 : Math.max(1, Math.abs(zero - y(value)))
|
|
3583
|
+
return h('g', { key: row.method + row.horizon, tabIndex: 0, 'aria-label': title },
|
|
3584
|
+
h('title', null, title),
|
|
3585
|
+
h('rect', { x: x - 15, y: value < 0 ? zero : zero - barHeight,
|
|
3586
|
+
width: 30, height: barHeight, fill: barColors[row.horizon] }),
|
|
3587
|
+
h('text', { x, y: value < 0 ? Math.min(220, y(value) + 12) : y(value) - 5, textAnchor: 'middle',
|
|
3588
|
+
fill: 'currentColor', fontSize: 11 }, result.count + ' 次'))
|
|
3589
|
+
})),
|
|
3590
|
+
h('p', null, ...backtestHorizons.map(horizon => h('span', { key: horizon, style: { marginInlineEnd: 14 } },
|
|
3591
|
+
h('span', { style: { color: barColors[horizon] }, 'aria-hidden': true }, '■ '), '提前 ' + horizon + ' 轮'))))
|
|
3592
|
+
}
|
|
3593
|
+
const detailSessions = [...new Set(backtestSelection.map(row => row.sessionId))]
|
|
3594
|
+
const detailSession = detailSessions.includes(trendConfig.backtestSession) ? trendConfig.backtestSession : detailSessions[0]
|
|
3595
|
+
const detailMethods = methods.filter(method => backtestSelection.some(row => row.sessionId === detailSession && row.method === method))
|
|
3596
|
+
const detailMethod = detailMethods.includes(trendConfig.backtestMethod) ? trendConfig.backtestMethod : detailMethods[0]
|
|
3597
|
+
const detailCandidates = backtestSelection.filter(row => row.sessionId === detailSession && row.method === detailMethod)
|
|
3598
|
+
const detailOrigins = [...new Set(detailCandidates.map(row => row.origin))]
|
|
3599
|
+
const detailOrigin = detailOrigins.includes(trendConfig.backtestOrigin) ? trendConfig.backtestOrigin : detailOrigins[0]
|
|
3600
|
+
const detailRecords = detailCandidates.filter(row => row.origin === detailOrigin)
|
|
3601
|
+
const detailLast = Math.max(1, ...detailRecords.map(row => row.target))
|
|
3602
|
+
const detailPoints = (scoredTrends[detailSession] ?? []).filter(point => point.round <= detailLast)
|
|
3603
|
+
.map(point => ({ ...point, score: point.scores?.[backtestPlan]?.score }))
|
|
3604
|
+
const detailTargets = new Map(detailRecords.map(row => [row.target, row]))
|
|
3605
|
+
const originScore = detailPoints.find(point => point.round === detailOrigin)?.score
|
|
3606
|
+
const detailX = round => 48 + 611 * (round - 1) / Math.max(1, detailLast - 1)
|
|
3607
|
+
const detailY = value => 217 - 1.93 * value
|
|
3608
|
+
const sessionName = id => trendChoices.find(row => row.id === id)?.title || '未命名 Session ' + (detailSessions.indexOf(id) + 1)
|
|
3609
|
+
const detailChart = detailRecords.length ? h('section', { className: 'pressure-section' },
|
|
3610
|
+
h('h4', null, '真实压力与预测压力'),
|
|
3611
|
+
h('div', { style: { display: 'flex', flexWrap: 'wrap', gap: 12 } },
|
|
3612
|
+
h('label', null, '历史 Session ', h('select', { value: detailSession,
|
|
3613
|
+
onChange: event => changeTrend({ backtestSession: event.currentTarget.value }) },
|
|
3614
|
+
...detailSessions.map(id => h('option', { key: id, value: id }, sessionName(id))))),
|
|
3615
|
+
h('label', null, '预测方法 ', h('select', { value: detailMethod,
|
|
3616
|
+
onChange: event => changeTrend({ backtestMethod: event.currentTarget.value }) },
|
|
3617
|
+
...detailMethods.map(method => h('option', { key: method, value: method }, methodLabels[method])))),
|
|
3618
|
+
h('label', null, '预测起点 ', h('select', { value: detailOrigin,
|
|
3619
|
+
onChange: event => changeTrend({ backtestOrigin: Number(event.currentTarget.value) }) },
|
|
3620
|
+
...detailOrigins.map(round => h('option', { key: round, value: round }, '第 ' + round + ' 轮'))))),
|
|
3621
|
+
h('svg', { viewBox: '0 0 680 255', role: 'group', 'aria-label': '真实压力与预测压力', style: { width: '100%' } },
|
|
3622
|
+
...[0, 25, 50, 75, 100].map(value => h('g', { key: value },
|
|
3623
|
+
h('line', { x1: 48, x2: 660, y1: detailY(value), y2: detailY(value), stroke: 'currentColor', opacity: .2 }),
|
|
3624
|
+
h('text', { x: 40, y: detailY(value) + 4, textAnchor: 'end', fill: 'currentColor', fontSize: 12 }, value))),
|
|
3625
|
+
...trendSegments(detailPoints).map((segment, i) => h('polyline', { key: 'actual:' + i, stroke: '#3589e6',
|
|
3626
|
+
strokeWidth: 2, fill: 'none', points: segment.map(point => detailX(point.round) + ',' + detailY(point.score)).join(' ') })),
|
|
3627
|
+
...detailPoints.filter(point => point.markers.length).map(point => h('g', { key: 'event:' + point.round, tabIndex: 0 },
|
|
3628
|
+
h('title', null, '第 ' + point.round + ' 轮 · ' + point.markers.map(marker => marker.type).join(' / ')),
|
|
3629
|
+
h('line', { x1: detailX(point.round), x2: detailX(point.round), y1: 20, y2: 217, stroke: 'currentColor', opacity: .3, strokeDasharray: '2 4' }),
|
|
3630
|
+
h('circle', { cx: detailX(point.round), cy: 20, r: 4, fill: 'currentColor' }))),
|
|
3631
|
+
h('line', { x1: detailX(detailOrigin), x2: detailX(detailOrigin), y1: 24, y2: 217, stroke: 'currentColor', opacity: .7 }),
|
|
3632
|
+
...detailRecords.map(row => h('line', { key: 'future:' + row.target, x1: detailX(detailOrigin), y1: detailY(originScore),
|
|
3633
|
+
x2: detailX(row.target), y2: detailY(row.estimate), stroke: '#c96a11', strokeWidth: 2, strokeDasharray: '6 5' })),
|
|
3634
|
+
...detailPoints.filter(point => Number.isFinite(point.score)).map(point => {
|
|
3635
|
+
const row = detailTargets.get(point.round)
|
|
3636
|
+
const text = '第 ' + point.round + ' 轮 · 实际 ' + scoreOf(point.score)
|
|
3637
|
+
+ (row ? ' · 预测 ' + scoreOf(row.estimate) + ' · 误差 ' + signedScore(row.estimate - row.actual) : '')
|
|
3638
|
+
return h('g', { key: 'point:' + point.round, tabIndex: row || point.round === detailOrigin ? 0 : undefined, 'aria-label': text },
|
|
3639
|
+
h('title', null, text),
|
|
3640
|
+
h('circle', { cx: detailX(point.round), cy: detailY(point.score), r: 3, fill: '#3589e6' }),
|
|
3641
|
+
row ? h('circle', { cx: detailX(point.round), cy: detailY(row.estimate), r: 5, fill: '#c96a11' }) : null)
|
|
3642
|
+
}),
|
|
3643
|
+
...[...new Set([1, detailOrigin, ...detailRecords.map(row => row.target)])].map(round =>
|
|
3644
|
+
h('text', { key: round, x: detailX(round), y: 239, fill: 'currentColor', fontSize: 12, textAnchor: 'middle' }, round))),
|
|
3645
|
+
h('p', null, '蓝实线为真实压力,橙虚线通向各有效预测目标。竖线标出预测起点及已记录事件。'),
|
|
3646
|
+
pressureTable(['目标轮', '实际', '预测', '误差', '归因'], detailRecords.map(row =>
|
|
3647
|
+
[row.target, row.target, scoreOf(row.actual), scoreOf(row.estimate), signedScore(row.estimate - row.actual),
|
|
3648
|
+
h('button', { type: 'button', onClick: () => changeTrend({ historyPage: 'attribution', attributionId: row.sessionId,
|
|
3649
|
+
attributionStart: row.origin, attributionEnd: row.target, attributionPlan: row.plan,
|
|
3650
|
+
attributionForecast: { method: row.method } }) }, '分析本次预测误差')])))
|
|
3651
|
+
: h('p', null, '当前筛选下暂无有效的逐次预测。')
|
|
3652
|
+
const pressureBacktest = h('section', { className: 'pressure-section' },
|
|
3653
|
+
h('h4', null, '历史预测回测 v0.1'),
|
|
3654
|
+
!wantBacktest ? null : h('div', null,
|
|
3655
|
+
h('div', { style: { display: 'flex', flexWrap: 'wrap', gap: 12 } },
|
|
3656
|
+
h('label', null, '综合公式 ', h('select', { value: backtestPlan,
|
|
3657
|
+
onChange: event => changeTrend({ backtestPlan: event.currentTarget.value }) },
|
|
3658
|
+
...plans.map(([key, name]) => h('option', { key, value: key }, key + ' · ' + name)))),
|
|
3659
|
+
h('label', null, '事件分组 ', h('select', { value: backtestGroup,
|
|
3660
|
+
onChange: event => changeTrend({ backtestGroup: event.currentTarget.value }) },
|
|
3661
|
+
...Object.entries(groupLabels).map(([key, label]) => h('option', { key, value: key }, label)))),
|
|
3662
|
+
h('label', null, h('input', { type: 'checkbox', checked: !!trendConfig.backtestCommon,
|
|
3663
|
+
onChange: event => changeTrend({ backtestCommon: event.currentTarget.checked }) }), ' 共同样本比较')),
|
|
3664
|
+
h('fieldset', null, h('legend', null, '参与比较的预测方法'),
|
|
3665
|
+
...backtestMethods.map(method => h('label', { key: method, style: { marginInlineEnd: 12 } },
|
|
3666
|
+
h('input', { type: 'checkbox', checked: methods.includes(method), disabled: methods.length === 1 && methods.includes(method),
|
|
3667
|
+
onChange: event => {
|
|
3668
|
+
const checked = event.currentTarget.checked
|
|
3669
|
+
changeTrend({ backtestMethods: backtestMethods.filter(id => id === method ? checked : methods.includes(id)) })
|
|
3670
|
+
} }), ' ' + methodLabels[method]))),
|
|
3671
|
+
h('p', { className: 'hint' }, trendConfig.backtestCommon
|
|
3672
|
+
? '各方法在同一提前轮数使用相同的 Session、起点与目标轮。'
|
|
3673
|
+
: '各方法使用各自的有效预测。柱旁标注预测次数,样本集合可能不同。'),
|
|
3674
|
+
trendLoading ? h('p', { role: 'status' }, '正在重建历史数据…') : null,
|
|
3675
|
+
backtestBars('mae', 'MAE 对比'),
|
|
3676
|
+
backtestBars('bias', '预测偏差'),
|
|
3677
|
+
detailChart,
|
|
3678
|
+
h('details', { className: 'pressure-section' }, h('summary', null, '回测统计明细'),
|
|
3679
|
+
h('div', { style: { overflowX: 'auto' } }, pressureTable(['预测方法', '提前轮数', '方案', '有效预测', '会话数', 'MAE', '偏差'],
|
|
3680
|
+
backtest.map(row => {
|
|
3681
|
+
const result = row.groups[backtestGroup]
|
|
3682
|
+
return [row.method + ':' + row.horizon + ':' + row.plan, methodLabels[row.method], row.horizon,
|
|
3683
|
+
row.plan, result.count, result.sessions, scoreOf(result.mae), signedScore(result.bias)]
|
|
3684
|
+
}))))))
|
|
3685
|
+
const trendSeriesKey = JSON.stringify([trendIds, displayedPlans, trendChoices.map(row => [row.id, row.title])])
|
|
3686
|
+
const { series, currentTrend, maxRound, firstRound } = React.useMemo(() => {
|
|
3687
|
+
const series = trendIds.flatMap((id, index) => displayedPlans.map(plan => ({
|
|
3688
|
+
id: id + ':' + plan, label: trendMulti ? (trendChoices.find(row => row.id === id)?.title || (id === currentTrendId ? '当前 Session' : '未命名 Session ' + (index + 1))) : plan,
|
|
3689
|
+
sessionLabel: trendMulti ? null : (trendChoices.find(row => row.id === id)?.title || '当前 Session'),
|
|
3690
|
+
color: trendMulti ? sessionColors[index] : schemeColors[plan],
|
|
3691
|
+
points: (scoredTrends[id] ?? []).map(point => ({ ...point, score: point.scores?.[plan].score })),
|
|
3692
|
+
})))
|
|
3693
|
+
const currentTrend = scoredTrends[currentTrendId] ?? []
|
|
3694
|
+
const historicalTrends = trendConfig.median && !trendMulti
|
|
3695
|
+
? trendChoices.filter(row => row.id !== currentTrendId).map(row => scoredTrends[row.id] ?? []) : []
|
|
3696
|
+
const maxRound = Math.max(1, ...series.map(line => line.points.findLast(point => Number.isFinite(point.score))?.round ?? 0))
|
|
3697
|
+
const firstRound = trendConfig.range ? Math.max(1, maxRound - trendConfig.range + 1) : 1
|
|
3698
|
+
if (historicalTrends.length) for (const plan of displayedPlans) {
|
|
3699
|
+
series.push({ id: 'median:' + plan, label: plan + ' 历史中位数', color: schemeColors[plan], dashed: true,
|
|
3700
|
+
points: currentTrend.filter(point => point.round >= firstRound && point.round <= maxRound).map(point => {
|
|
3701
|
+
const history = historicalTrends.map(other => other[point.round - 1]).filter(other =>
|
|
3702
|
+
Number.isFinite(point.scores?.[plan].score) && Number.isFinite(other?.scores?.[plan].score)
|
|
3703
|
+
&& sameRoundDiagnostic(point.snapshot, other.snapshot, trendConfig.strict))
|
|
3704
|
+
const stats = pressureStatistics(point.scores?.[plan].score, history.map(other => other.scores[plan].score))
|
|
3705
|
+
return { round: point.round, score: stats.median, count: stats.count }
|
|
3706
|
+
}) })
|
|
3707
|
+
}
|
|
3708
|
+
return { series, currentTrend, maxRound, firstRound }
|
|
3709
|
+
}, [scoredTrends, trendSeriesKey, trendMulti, trendConfig.median, trendConfig.strict, trendConfig.range, currentTrendId])
|
|
3710
|
+
const trendX = round => maxRound === firstRound ? 386 : 46 + 680 * (round - firstRound) / (maxRound - firstRound)
|
|
3711
|
+
const trendY = score => 236 - score * 2.1
|
|
3712
|
+
const shownSeries = series.map(line => ({ ...line, points: line.points.filter(point => point.round >= firstRound && point.round <= maxRound) }))
|
|
3713
|
+
const shownMarkers = (trendMulti ? trendIds.flatMap(id => (scoredTrends[id] ?? [])
|
|
3714
|
+
.map(point => ({ ...point, markerId: id, markerLabel: trendChoices.find(row => row.id === id)?.title || 'Session' })))
|
|
3715
|
+
: currentTrend).filter(point => point.round >= firstRound && point.round <= maxRound)
|
|
3716
|
+
const focusRound = Math.min(maxRound, Math.max(firstRound, trendFocus ?? (viewingRound || maxRound)))
|
|
3717
|
+
const routeDetails = point => {
|
|
3718
|
+
const route = point.snapshot?.route ? JSON.parse(point.snapshot.route) : null
|
|
3719
|
+
return (route ? ' · ' + route[1] + ' / ' + route[2].toLocaleString() + ' Token' : '')
|
|
3720
|
+
+ (point.switched || point.snapshot?.configurationChanged ? ' · 曾切换配置' : '')
|
|
3721
|
+
}
|
|
3722
|
+
const chooseRound = round => {
|
|
3723
|
+
setTrendFocus(round > latestRound ? round : null)
|
|
3724
|
+
changeTrend({ round: Math.min(latestRound, round) })
|
|
3725
|
+
}
|
|
3726
|
+
const pointerRound = event => {
|
|
3727
|
+
const bounds = event.currentTarget.getBoundingClientRect()
|
|
3728
|
+
return bounds.width > 0 ? firstRound + Math.round((maxRound - firstRound)
|
|
3729
|
+
* Math.min(1, Math.max(0, (event.clientX - bounds.left) / bounds.width))) : focusRound
|
|
3730
|
+
}
|
|
3731
|
+
const focusDetails = shownSeries.flatMap(line => {
|
|
3732
|
+
const point = line.points.find(item => item.round === focusRound)
|
|
3733
|
+
return point ? [[line.sessionLabel, line.label].filter(Boolean).join(' · ') + ' ' + scoreOf(point.score) + routeDetails(point)
|
|
3734
|
+
+ (point.count == null ? '' : '(' + point.count + ' 个样本)')] : []
|
|
3735
|
+
})
|
|
3736
|
+
const markerText = marker => marker.type + (marker.time == null ? '' : ' · ' + new Date(marker.time).toLocaleString())
|
|
3737
|
+
+ (Number.isFinite(marker.tokenChange) ? ' · ' + signedScore(marker.tokenChange) + ' Token' : '')
|
|
3738
|
+
const plotTicks = [...new Set(Array.from({ length: 6 }, (_, i) => Math.round(firstRound + (maxRound - firstRound) * i / 5)))]
|
|
3739
|
+
const trendChart = h('section', { className: 'pressure-section' },
|
|
3740
|
+
h('h4', null, '压力走势与多 Session 对比'),
|
|
3741
|
+
h('div', { style: { display: 'flex', flexWrap: 'wrap', gap: '12px' } },
|
|
3742
|
+
h('label', null, '模式 ', h('select', { value: trendMulti ? 'multi' : 'single',
|
|
3743
|
+
onChange: event => changeTrend({ multi: event.currentTarget.value === 'multi', plan: null }) },
|
|
3744
|
+
h('option', { value: 'single' }, '当前 Session'), h('option', { value: 'multi' }, '多 Session'))),
|
|
3745
|
+
h('label', null, '公式 ', h('select', { value: trendConfig.plan ?? (trendMulti ? 'A' : ''),
|
|
3746
|
+
onChange: event => changeTrend({ plan: event.currentTarget.value || null }) },
|
|
3747
|
+
trendMulti ? null : h('option', { value: '' }, 'A + B + C'),
|
|
3748
|
+
...plans.map(([id, name]) => h('option', { key: id, value: id }, id + ' · ' + name)))),
|
|
3749
|
+
h('label', null, '轮次范围 ', h('select', { value: trendConfig.range ?? 0,
|
|
3750
|
+
onChange: event => changeTrend({ range: Number(event.currentTarget.value) }) },
|
|
3751
|
+
...[0, 10, 20, 50].map(value => h('option', { key: value, value }, value ? '最近 ' + value + ' 轮' : '全部轮次')))),
|
|
3752
|
+
trendMulti ? null : h('label', null,
|
|
3753
|
+
h('input', { type: 'checkbox', checked: !!trendConfig.median,
|
|
3754
|
+
onChange: event => changeTrend({ median: event.currentTarget.checked }) }), ' 历史同轮次中位数')),
|
|
3755
|
+
trendMulti ? h('div', null, h('p', null, '最多选择 5 个 Session。历史候选来自历史页勾选的会话。'),
|
|
3756
|
+
...trendChoices.map((row, index) => h('label', { key: row.id, style: { display: 'block' } },
|
|
3757
|
+
h('input', { type: 'checkbox', checked: trendIds.includes(row.id), disabled: trendIds.length >= 5 && !trendIds.includes(row.id),
|
|
3758
|
+
onChange: event => changeTrend({ ids: event.currentTarget.checked ? [...trendIds, row.id] : trendIds.filter(id => id !== row.id) }) }),
|
|
3759
|
+
' ' + (row.current ? '当前 Session' : row.title || '未命名 Session ' + (index + 1))))) : null,
|
|
3760
|
+
!historyActive || historyPage !== 'compare' ? null : h('div', null,
|
|
3761
|
+
trendLoading ? h('p', { role: 'status' }, '正在重建逐轮诊断…') : null,
|
|
3762
|
+
isScenario ? h('p', { className: 'hint' }, '走势使用轮末实际采样,情景覆盖仅作用于实时试算卡片。') : null,
|
|
3763
|
+
!trendLoading && (loadedIds.some(id => trendData[id]?.status !== 'analyzed'))
|
|
3764
|
+
? h('p', { className: 'hint' }, '部分会话的日志不可用或超出本地分析范围。') : null,
|
|
3765
|
+
!shownSeries.some(line => line.points.some(point => Number.isFinite(point.score))) ? h('p', null, '该范围暂无可绘制的完整轮末读数。') : null,
|
|
3766
|
+
shownSeries.length ? h('svg', { viewBox: '0 0 750 282', role: 'group', 'aria-label': '用户已完成轮次与压力分',
|
|
3767
|
+
style: { width: '100%', height: 'auto', minHeight: '160px' } },
|
|
3768
|
+
...[0, 25, 50, 75, 100].map(score => h('g', { key: score },
|
|
3769
|
+
h('line', { x1: 46, x2: 726, y1: trendY(score), y2: trendY(score), stroke: 'currentColor', opacity: .14 }),
|
|
3770
|
+
h('text', { x: 38, y: trendY(score) + 4, textAnchor: 'end', fill: 'currentColor', fontSize: 12 }, score))),
|
|
3771
|
+
...plotTicks.map(round => h('text', { key: round, x: trendX(round), y: 253, textAnchor: 'middle', fill: 'currentColor', fontSize: 12 }, round)),
|
|
3772
|
+
h('text', { x: 386, y: 273, textAnchor: 'middle', fill: 'currentColor', fontSize: 12 }, '已完成用户轮次'),
|
|
3773
|
+
...shownMarkers.flatMap(point => point.markers.length ? [h('g', { key: 'event:' + (point.markerId ?? '') + ':' + point.round, tabIndex: 0 },
|
|
3774
|
+
h('title', null, '第 ' + point.round + ' 轮 · ' + (point.markerLabel ? point.markerLabel + ' · ' : '') + point.markers.map(markerText).join(' / ')),
|
|
3775
|
+
h('line', { x1: trendX(point.round), x2: trendX(point.round), y1: 25, y2: 236,
|
|
3776
|
+
stroke: 'currentColor', opacity: .35, strokeDasharray: '3 3' }),
|
|
3777
|
+
h('circle', { cx: trendX(point.round), cy: 25, r: 4, fill: 'currentColor' }))] : []),
|
|
3778
|
+
...shownSeries.map(line => h('g', { key: line.id },
|
|
3779
|
+
...trendSegments(line.points).map((segment, i) => h('polyline', { key: i, fill: 'none', stroke: line.color, strokeWidth: 2,
|
|
3780
|
+
strokeDasharray: line.dashed ? '6 4' : undefined,
|
|
3781
|
+
points: segment.map(point => trendX(point.round) + ',' + trendY(point.score)).join(' ') })),
|
|
3782
|
+
...line.points.filter(point => Number.isFinite(point.score) && (line.points.length <= 100 || point.round === focusRound
|
|
3783
|
+
|| !Number.isFinite(line.points[point.round - firstRound - 1]?.score)
|
|
3784
|
+
|| !Number.isFinite(line.points[point.round - firstRound + 1]?.score))).map(point => {
|
|
3785
|
+
const label = [line.sessionLabel, line.label].filter(Boolean).join(' · ')
|
|
3786
|
+
+ ' · 第 ' + point.round + ' 轮 · ' + scoreOf(point.score) + ' 分' + routeDetails(point)
|
|
3787
|
+
+ (point.count == null ? '' : ' · ' + point.count + ' 个样本')
|
|
3788
|
+
return h('circle', { key: point.round, cx: trendX(point.round), cy: trendY(point.score), r: 3.5,
|
|
3789
|
+
fill: line.color, tabIndex: point.round === line.points.at(-1)?.round ? 0 : undefined,
|
|
3790
|
+
'aria-label': label }, h('title', null, label))
|
|
3791
|
+
}))),
|
|
3792
|
+
h('line', { x1: trendX(focusRound), x2: trendX(focusRound), y1: 25, y2: 236,
|
|
3793
|
+
stroke: 'currentColor', opacity: .3, pointerEvents: 'none' }),
|
|
3794
|
+
h('rect', { x: 46, y: 32, width: 680, height: 204, fill: 'transparent',
|
|
3795
|
+
onPointerMove: event => setTrendFocus(pointerRound(event)),
|
|
3796
|
+
onPointerLeave: () => setTrendFocus(null),
|
|
3797
|
+
onClick: event => chooseRound(pointerRound(event)) })) : null,
|
|
3798
|
+
shownSeries.length ? h('div', null,
|
|
3799
|
+
h('label', null, '查看第 ' + focusRound + ' 轮 ', h('input', { type: 'range', min: firstRound, max: maxRound,
|
|
3800
|
+
value: focusRound, onChange: event => chooseRound(event.currentTarget.valueAsNumber) })),
|
|
3801
|
+
h('button', { type: 'button', onClick: () => { setTrendFocus(null); changeTrend({ round: null }) } }, '最新轮次'),
|
|
3802
|
+
h('p', null, focusDetails.length ? focusDetails.join(' · ') : '该轮暂无压力读数'),
|
|
3803
|
+
...((shownMarkers.find(point => point.round === focusRound)?.markers ?? [])
|
|
3804
|
+
.map((marker, index) => h('p', { key: index }, markerText(marker))))) : null,
|
|
3805
|
+
h('div', { style: { display: 'flex', flexWrap: 'wrap', gap: '12px' } }, ...shownSeries.map(line =>
|
|
3806
|
+
h('span', { key: line.id }, h('span', { style: { color: line.color }, 'aria-hidden': true }, line.dashed ? '┄ ' : '━ '), line.label))),
|
|
3807
|
+
h('p', { className: 'hint' }, '断点表示该轮缺少必要诊断。纵向虚线标记模型、窗口或真实压缩与裁剪事件。')))
|
|
3808
|
+
const overallScores = Object.values(compositeScores).map(item => item.score).filter(Number.isFinite)
|
|
3809
|
+
const compositeCalculation = h('section', { className: 'card load-panel', style: { minWidth: 0 } },
|
|
3810
|
+
h('h4', null, '综合压力公式'),
|
|
3811
|
+
h('p', { className: 'hint' }, '容量 / 请求 / 结构:' + subScores.map(scoreOf).join(' / ') + ' 分 · ' + pressureVersions.composite
|
|
3812
|
+
+ (isScenario ? ' · 使用子模块情景输入' : '')),
|
|
3813
|
+
overallScores.length > 1 ? h('p', null, '最大分差:' + scoreOf(Math.max(...overallScores) - Math.min(...overallScores)) + ' 分') : null,
|
|
3814
|
+
...plans.map(([id, name, formula, labels, details]) => {
|
|
3815
|
+
const params = compositeParameters[id]
|
|
3816
|
+
const setParams = update => setCompositeExperiment(previous => ({ ...previous, [id]: update(previous[id] ?? {}) }))
|
|
3817
|
+
return h('section', { key: id, className: 'card load-panel', style: { minWidth: 0 } },
|
|
3818
|
+
h('h4', null, id + ' · ' + name + ' · ' + scoreOf(compositeScores[id].score) + ' / 100'),
|
|
3819
|
+
h('div', { style: { display: 'flex', flexWrap: 'wrap', gap: '12px' } },
|
|
3820
|
+
...Object.entries(labels).map(([key, label]) => h('label', { key },
|
|
3821
|
+
label + ' ' + params[key].toFixed(2) + ' ',
|
|
3822
|
+
h('input', { type: 'range', min: 0, max: 1, step: .01, value: params[key],
|
|
3823
|
+
onChange: event => {
|
|
3824
|
+
const value = event.currentTarget.valueAsNumber
|
|
3825
|
+
setParams(previous => ({ ...previous, [key]: value }))
|
|
3826
|
+
} }))),
|
|
3827
|
+
h('button', { type: 'button', onClick: () => setParams(() => ({})) }, '重置默认参数')),
|
|
3828
|
+
id === 'B' && compositeScores.B.disabled ? h('p', null, '全部风险贡献已关闭') : null,
|
|
3829
|
+
h('details', { className: 'pressure-section' },
|
|
3830
|
+
h('summary', null, '公式与计算明细'),
|
|
3831
|
+
h('p', null, formula),
|
|
3832
|
+
h('p', null, 'c、r、q = 三个子压力分别除以 100。'),
|
|
3833
|
+
id === 'A' ? h('p', null, '权重总和为 0 时显示 —。') : null,
|
|
3834
|
+
id === 'B' ? h('p', null, '风险强度分别生效;强度为 0 时对应因子为 1。') : null,
|
|
3835
|
+
id === 'C' ? h('p', null, '请求与结构权重总和为 0 时 M = 0。μ 为试算参数。') : null,
|
|
3836
|
+
...details.map(line => h('p', { key: line }, line))))
|
|
3837
|
+
}))
|
|
3838
|
+
const sameRoundPanel = h('section', { className: 'pressure-section' },
|
|
3839
|
+
h('h4', null, '历史同轮次对比'),
|
|
3840
|
+
h('p', null, '当前已完成 ' + (latestRound || '—') + ' 轮 · 查看第 ' + (viewingRound || '—')
|
|
3841
|
+
+ ' 轮 · 可比较历史会话 ' + comparable.length + ' 个'),
|
|
3842
|
+
latestRound ? h('label', null, '当前查看轮次 ', h('input', { type: 'range', min: 1, max: latestRound,
|
|
3843
|
+
value: viewingRound, onChange: event => chooseRound(event.currentTarget.valueAsNumber) })) : null,
|
|
3844
|
+
h('label', null, h('input', { type: 'checkbox', checked: !!trendConfig.strict,
|
|
3845
|
+
onChange: event => changeTrend({ strict: event.currentTarget.checked }) }), ' 仅同配置'),
|
|
3846
|
+
h('p', { className: 'hint' }, eligible ? sampleHint(comparable.length) : '当前选定轮的诊断正在重建或数据缺失。'),
|
|
3847
|
+
comparable.some(row => row.mismatch) ? h('p', { className: 'hint' },
|
|
3848
|
+
'包含不同模型或上下文窗口的 Session。分数经过各自窗口归一化,但跨模型可比性尚未校准。') : null,
|
|
3849
|
+
currentDiagnostic?.route ? h('p', null, '比较配置:' + JSON.parse(currentDiagnostic.route).map(value => String(value)).join(' / ')) : null,
|
|
3850
|
+
comparison?.saveFailed ? h('p', { role: 'status' }, '轮末诊断快照保存失败。') : null,
|
|
3851
|
+
h('div', { style: { overflowX: 'auto' } }, pressureTable(['方案', '轮末分数', '样本数', '同轮中位数', '百分位', '与中位数差值'],
|
|
3852
|
+
plans.map(([id, name]) => {
|
|
3853
|
+
const score = currentHistoryScores[id]?.score
|
|
3854
|
+
const stats = schemeStats[id]
|
|
3855
|
+
return [id, id + ' · ' + name, scoreOf(score), stats.count, scoreOf(stats.median),
|
|
3856
|
+
stats.percentile == null ? '—' : scoreOf(stats.percentile) + '%', signedScore(stats.difference)]
|
|
3857
|
+
}))),
|
|
3858
|
+
h('p', { className: 'hint' }, '百分位 =(严格较低的样本数 + 一半的同分样本数)÷ 有效样本数。'),
|
|
3859
|
+
historical.some(row => row.reason) ? h('details', { className: 'pressure-section' },
|
|
3860
|
+
h('summary', null, '不可比较的历史会话'),
|
|
3861
|
+
pressureTable(['会话', '原因'], historical.filter(row => row.reason).map(row => [row.id, row.title || '未命名会话', row.reason]))) : null)
|
|
3862
|
+
|
|
3863
|
+
const pressureGrid = { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(min(100%, 165px), 1fr))', gap: 12 }
|
|
3864
|
+
const scoreNames = ['容量', '请求', '结构']
|
|
3865
|
+
const childColors = ['#5c9ded', '#cc8b46', '#58ab86']
|
|
3866
|
+
const currentSeries = scoredTrends[currentTrendId] ?? []
|
|
3867
|
+
const latestPoint = currentSeries.at(-1)
|
|
3868
|
+
const priorPoint = currentSeries.find(point => point.round === latestPoint?.round - 5)
|
|
3869
|
+
const rowFor = (id, label, scope) => dictionary.find(metric => metric.id === id)?.rows.find(row =>
|
|
3870
|
+
row.label === label && (!scope || row.scope === scope))
|
|
3871
|
+
const measureText = row => dictionaryValue(row?.value, row?.unit)
|
|
3872
|
+
const summaryMeasures = [
|
|
3873
|
+
['上下文占用率', rowFor('C', '窗口占用率')], ['剩余窗口', rowFor('C', '剩余容量')],
|
|
3874
|
+
['最近 10 轮平均净增长', rowFor('G', '平均净增长', '最近 10 轮')],
|
|
3875
|
+
['平均每轮消耗', rowFor('U', '平均每轮消耗')], ['工具结果残留', rowFor('T', '残留占比')],
|
|
3876
|
+
['缓存未命中', rowFor('K', '未命中比例')], ['缓存报告覆盖', rowFor('K', '缓存统计覆盖率')],
|
|
3877
|
+
]
|
|
3878
|
+
function pressureLines(points, lines, endpoints = []) {
|
|
3879
|
+
const first = points[0]?.round ?? 1
|
|
3880
|
+
const last = points.at(-1)?.round ?? first
|
|
3881
|
+
const x = round => 43 + 617 * (round - first) / Math.max(1, last - first)
|
|
3882
|
+
const y = score => 189 - score * 1.65
|
|
3883
|
+
if (!points.some(point => lines.some(line => Number.isFinite(line.read(point))))) {
|
|
3884
|
+
return h('p', { className: 'hint' }, '暂无可绘制的轮末分数。')
|
|
3885
|
+
}
|
|
3886
|
+
return h('svg', { viewBox: '0 0 680 220', role: 'group', 'aria-label': '轮末压力走势(0–100)', style: { width: '100%' } },
|
|
3887
|
+
...[0, 25, 50, 75, 100].map(value => h('g', { key: value },
|
|
3888
|
+
h('line', { x1: 43, x2: 660, y1: y(value), y2: y(value), stroke: 'currentColor', opacity: .16 }),
|
|
3889
|
+
h('text', { x: 35, y: y(value) + 4, fill: 'currentColor', fontSize: 12, textAnchor: 'end' }, value))),
|
|
3890
|
+
...[...new Set([first, Math.floor((first + last) / 2), last])].map(round => h('text', {
|
|
3891
|
+
key: round, x: x(round), y: 209, fill: 'currentColor', fontSize: 12, textAnchor: 'middle',
|
|
3892
|
+
}, round)),
|
|
3893
|
+
...endpoints.map((round, index) => h('line', { key: index, x1: x(round), x2: x(round), y1: 20, y2: 190,
|
|
3894
|
+
stroke: 'currentColor', strokeDasharray: '4 3', opacity: .6 })),
|
|
3895
|
+
...lines.flatMap(line => trendSegments(points.map(point => ({ round: point.round, score: line.read(point) })))
|
|
3896
|
+
.map((segment, i) => h('polyline', { key: line.label + ':' + i, stroke: line.color, strokeWidth: 2,
|
|
3897
|
+
fill: 'none', points: segment.map(point => x(point.round) + ',' + y(point.score)).join(' ') }))),
|
|
3898
|
+
...points.flatMap(point => {
|
|
3899
|
+
const values = lines.map(line => [line, line.read(point)]).filter(([, score]) => Number.isFinite(score))
|
|
3900
|
+
const label = ['第 ' + point.round + ' 轮', ...values.map(([line, score]) => line.label + ' ' + scoreOf(score) + ' 分'),
|
|
3901
|
+
routeDetails(point), ...point.markers.map(marker => marker.type)].filter(Boolean).join(' · ')
|
|
3902
|
+
return values.length || point.markers.length ? [h('g', { key: point.round, tabIndex: 0, 'aria-label': label },
|
|
3903
|
+
h('title', null, label),
|
|
3904
|
+
...values.map(([line, score]) => h('circle', { key: line.label, cx: x(point.round), cy: y(score), r: 3, fill: line.color })),
|
|
3905
|
+
point.markers.length ? h('path', { d: 'M ' + x(point.round) + ' 13 l 4 4 -4 4 -4 -4 z', fill: 'currentColor' }) : null)] : []
|
|
3906
|
+
}))
|
|
3907
|
+
}
|
|
3908
|
+
function lineToggles(key, options) {
|
|
3909
|
+
const hidden = trendConfig[key] ?? []
|
|
3910
|
+
return h('div', { style: { display: 'flex', flexWrap: 'wrap', gap: 12 } }, ...options.map(item => h('label', { key: item.id },
|
|
3911
|
+
h('input', { type: 'checkbox', checked: !hidden.includes(item.id), onChange: event => changeTrend({
|
|
3912
|
+
[key]: event.currentTarget.checked ? hidden.filter(id => id !== item.id) : [...hidden, item.id],
|
|
3913
|
+
}) }), h('span', { style: { color: item.color } }, ' ' + item.label))))
|
|
3914
|
+
}
|
|
3915
|
+
const currentLines = plans.map(([id]) => ({ id, label: id, color: schemeColors[id], read: point => point.scores?.[id]?.score }))
|
|
3916
|
+
const currentRange = trendConfig.currentRange ?? 20
|
|
3917
|
+
const homePoints = currentRange ? currentSeries.slice(-currentRange) : currentSeries
|
|
3918
|
+
const recentChanges = currentSeries.slice(-10).flatMap((point, index, recent) => plans.flatMap(([id]) => {
|
|
3919
|
+
const previous = recent[index - 1]
|
|
3920
|
+
const before = previous?.scores?.[id]?.score
|
|
3921
|
+
const after = point.scores?.[id]?.score
|
|
3922
|
+
return previous?.round === point.round - 1 && Number.isFinite(before) && Number.isFinite(after) && before !== after
|
|
3923
|
+
? [{ round: point.round, id, difference: after - before }] : []
|
|
3924
|
+
})).sort((a, b) => Math.abs(b.difference) - Math.abs(a.difference)).slice(0, 3)
|
|
3925
|
+
const currentCards = h('div', { style: pressureGrid }, ...plans.map(([id, name], index) => {
|
|
3926
|
+
const stats = homeSchemeStats[id]
|
|
3927
|
+
const last = latestPoint?.scores?.[id]?.score
|
|
3928
|
+
const previous = priorPoint?.scores?.[id]?.score
|
|
3929
|
+
return h('section', { key: id, className: 'card', style: { minWidth: 0, borderBlockStart: '3px solid ' + schemeColors[id] } },
|
|
3930
|
+
h('h4', null, id + ' · ' + name),
|
|
3931
|
+
pressureMetric('当前实时压力', scoreOf(compositeScores[id].score) + ' / 100',
|
|
3932
|
+
['综合均衡视角', '多维风险视角', '容量优先视角'][index]),
|
|
3933
|
+
h('div', { className: 'hint' }, '最近完成轮变化(5 轮) ' + (Number.isFinite(last) && Number.isFinite(previous) ? signedScore(last - previous) : '—')),
|
|
3934
|
+
h('div', { className: 'hint' }, '轮末历史同轮次 · 百分位 ' + (Number.isFinite(stats.percentile) ? scoreOf(stats.percentile) + '%' : '—')
|
|
3935
|
+
+ ' · 中位数差 ' + signedScore(stats.difference)),
|
|
3936
|
+
h('div', { className: 'hint' }, stats.count ? stats.count + ' 个历史样本' : '暂无可比样本'))
|
|
3937
|
+
}))
|
|
3938
|
+
const advice = sessionCapacityAdvice(occupancy, observedGrowth)
|
|
3939
|
+
const capacityStatus = {
|
|
3940
|
+
continue: ['✓', '继续使用', '#58ab86', '当前窗口仍有余量,可以继续使用这个会话。'],
|
|
3941
|
+
watch: ['◉', '继续使用,留意变化', '#5c9ded', '可以继续使用,接下来留意上下文占用的变化。'],
|
|
3942
|
+
prepare: ['△', '建议准备新会话', '#cc8b46', '建议在下一段任务前准备新会话,给后续对话留出空间。'],
|
|
3943
|
+
switch: ['!', '强烈建议切换', '#db726b', '当前上下文已接近或达到有效窗口上限,建议在下一段任务前改用新会话。'],
|
|
3944
|
+
unknown: ['?', '数据不足,暂不能判断', '#8e99a7', '缺少有效窗口或当前请求输入,暂时无法判断容量余量。'],
|
|
3945
|
+
}[advice.level]
|
|
3946
|
+
const unstableTrend = growthWindows.some(window => window.rounds <= 10 && window.compacted)
|
|
3947
|
+
|| currentSeries.slice(-10).some(point => point.markers.some(marker =>
|
|
3948
|
+
['压缩成功', '裁剪', '模型切换', '窗口切换'].includes(marker.type)))
|
|
3949
|
+
const occupancyText = value => Number.isFinite(value) ? scoreOf(value) + '%' : '—'
|
|
3950
|
+
const tShare = structureData?.currentShare
|
|
3951
|
+
const evidence = [
|
|
3952
|
+
[Number.isFinite(occupancy) ? '当前窗口已使用 ' + occupancyText(occupancy) : '当前占用未知',
|
|
3953
|
+
'最新模型请求实报输入 ' + measureText(rowFor('C', '请求输入'))
|
|
3954
|
+
+ ',有效窗口 ' + measureText(rowFor('C', '有效窗口'))
|
|
3955
|
+
+ ',剩余 ' + measureText(rowFor('C', '剩余容量')) + '。占用率按本次请求的输入除以有效窗口计算。'],
|
|
3956
|
+
[advice.five == null ? '近期趋势未知' : observedGrowth < 0 ? '最近可比轮次的占用呈净下降'
|
|
3957
|
+
: advice.five >= 95 - 1e-10 ? '按近期趋势,5 轮后可能接近窗口上限'
|
|
3958
|
+
: advice.ten >= 85 - 1e-10 ? '按近期趋势,10 轮后可能达到较高占用'
|
|
3959
|
+
: '按近期趋势,10 轮内预计低于 85%',
|
|
3960
|
+
advice.five == null ? '缺少当前占用或可比的轮末增长采样。' : '当前加权净增长 '
|
|
3961
|
+
+ signedScore(observedGrowth) + ' 个百分点/轮,复用 C + G 的近期窗口加权和容量推演。'
|
|
3962
|
+
+ '预计占用以 0–100% 显示。'],
|
|
3963
|
+
...(Number.isFinite(tShare) && tShare >= .5 ? [[
|
|
3964
|
+
'工具结果约占宿主可见请求的一半或更多',
|
|
3965
|
+
'同请求估算占比 ' + dictionaryValue(tShare, '%') + '。这描述工具内容占用,仅用于解释压力来源。',
|
|
3966
|
+
]] : []),
|
|
3967
|
+
]
|
|
3968
|
+
const adviceCard = h('section', { className: 'card', style: { borderInlineStart: '4px solid ' + capacityStatus[2] } },
|
|
3969
|
+
h('h4', { className: 'load-heading' }, h('span', null,
|
|
3970
|
+
h('span', { 'aria-hidden': true, style: { color: capacityStatus[2], marginInlineEnd: 8 } }, capacityStatus[0]), capacityStatus[1]),
|
|
3971
|
+
h('span', { className: 'hint' }, '实验规则 · 阈值尚未校准')),
|
|
3972
|
+
h('p', null, capacityStatus[3]),
|
|
3973
|
+
h('ul', null, ...evidence.map(([label]) => h('li', { key: label }, label))))
|
|
3974
|
+
const adviceDetails = h('section', { className: 'card' }, h('h4', null, '为什么这样判断'),
|
|
3975
|
+
h('div', { style: pressureGrid },
|
|
3976
|
+
...[['当前占用', occupancy], ['预计 5 轮后', advice.five], ['预计 10 轮后', advice.ten]].map(([label, value]) =>
|
|
3977
|
+
h('div', { key: label }, pressureMetric(label, occupancyText(value))))),
|
|
3978
|
+
advice.five == null ? h('p', { className: 'hint' }, '趋势未知,现有建议仅依据可用的当前占用。')
|
|
3979
|
+
: h('p', { className: 'hint' }, '按当前增长趋势估算,不保证实际结果。'),
|
|
3980
|
+
unstableTrend ? h('p', { className: 'hint' }, '近期记录了压缩、裁剪或配置切换,趋势可能不稳定。') : null,
|
|
3981
|
+
h('details', { className: 'pressure-section' }, h('summary', null, '查看具体依据'),
|
|
3982
|
+
...evidence.map(([label, detail]) => h('details', { key: label }, h('summary', null, label), h('p', null, detail))),
|
|
3983
|
+
h('p', { className: 'hint' }, '建议采用真实采样和固定的 5、10 轮窗口。公式试算、A/B/C 分数与累计用量用于分析,不参与建议分级。'),
|
|
3984
|
+
h('button', { type: 'button', onClick: () => setPressureTab('factors') }, '查看诊断指标')))
|
|
3985
|
+
const pressureCurrent = h('div', { className: 'load-panel' }, adviceCard, currentCards,
|
|
3986
|
+
isScenario ? h('p', { className: 'hint' }, 'A/B/C 使用当前情景参数试算。') : null,
|
|
3987
|
+
invalidStructure ? h('p', { role: 'alert' }, '工具残留数据异常,当前 T + E 和 A/B/C 分数无效。') : null,
|
|
3988
|
+
adviceDetails,
|
|
3989
|
+
h('section', { className: 'card' },
|
|
3990
|
+
h('h4', null, '压力走势'),
|
|
3991
|
+
h('label', null, '轮次范围 ', h('select', { value: currentRange,
|
|
3992
|
+
onChange: event => changeTrend({ currentRange: Number(event.currentTarget.value) }) },
|
|
3993
|
+
...[10, 20, 50, 0].map(value => h('option', { key: value, value }, value ? '最近 ' + value + ' 轮' : '全部轮次')))),
|
|
3994
|
+
lineToggles('homeHidden', currentLines),
|
|
3995
|
+
pressureLines(homePoints, currentLines.filter(line => !(trendConfig.homeHidden ?? []).includes(line.id))),
|
|
3996
|
+
h('button', { type: 'button', onClick: () => { changeTrend({ historyPage: 'compare' }); setPressureTab('history') } }, '查看完整压力走势'),
|
|
3997
|
+
h('button', { type: 'button', onClick: () => { changeTrend({ historyPage: 'same', round: null }); setPressureTab('history') } }, '查看历史同轮次比较')),
|
|
3998
|
+
h('section', { className: 'card' },
|
|
3999
|
+
h('h4', null, '压力构成'),
|
|
4000
|
+
h('div', { style: pressureGrid }, ...['C + G · 容量压力', 'U + A + K · 请求负担', 'T + E · 结构与稳定性'].map((name, index) => {
|
|
4001
|
+
const last = latestPoint?.children?.[index]
|
|
4002
|
+
const previous = priorPoint?.children?.[index]
|
|
4003
|
+
return h('div', { key: name }, pressureMetric(name, scoreOf(subScores[index]) + ' / 100',
|
|
4004
|
+
'近 5 轮 ' + (Number.isFinite(last) && Number.isFinite(previous) ? signedScore(last - previous) : '—')),
|
|
4005
|
+
Number.isFinite(subScores[index]) ? h('progress', { max: 100, value: subScores[index], 'aria-label': name }) : null)
|
|
4006
|
+
})),
|
|
4007
|
+
h('button', { type: 'button', onClick: () => setPressureTab('calculation') }, '查看详细计算方式')),
|
|
4008
|
+
h('section', { className: 'card' }, h('h4', null, '关键诊断'),
|
|
4009
|
+
h('div', { style: pressureGrid }, ...summaryMeasures.map(([name, row]) => h('div', { key: name },
|
|
4010
|
+
pressureMetric(name, measureText(row), row?.confidence))),
|
|
4011
|
+
pressureMetric('最近失败与重试', latestUsage ? latestUsage.attempts + ' 次尝试失败 · ' + latestUsage.retries + ' 次已匹配重试' : '—'))),
|
|
4012
|
+
h('details', { className: 'pressure-section' }, h('summary', null, '近期变化与事件'),
|
|
4013
|
+
recentChanges.length ? h('ul', null, ...recentChanges.map(row => h('li', { key: row.round + ':' + row.id },
|
|
4014
|
+
'第 ' + row.round + ' 轮 · 方案 ' + row.id + ' ' + signedScore(row.difference) + ' 分'))) : null,
|
|
4015
|
+
eventTable(currentSeries.slice(-10))))
|
|
4016
|
+
const toolOrder = trendConfig.toolOrder ?? 'tokens'
|
|
4017
|
+
const currentTools = (pressure?.usage?.toolResults ?? []).slice().sort((a, b) => toolOrder === 'turn'
|
|
4018
|
+
? b.turn - a.turn : toolOrder === 'age' ? a.turn - b.turn : b.tokens - a.tokens)
|
|
4019
|
+
const rawRecords = new Map((pressure?.usage?.roundDiagnostics ?? []).map(row => [row.turn, row]))
|
|
4020
|
+
const roundNumbers = [...new Set([...rows.map(row => row.turn), ...rawRecords.keys()])].sort((a, b) =>
|
|
4021
|
+
trendConfig.roundAscending ? a - b : b - a)
|
|
4022
|
+
const sampleByRound = new Map(rows.map(row => [row.turn, row]))
|
|
4023
|
+
const diagnosticsView = h('div', { className: 'load-panel' },
|
|
4024
|
+
h('div', { style: pressureGrid }, ...dictionary.map(metric => {
|
|
4025
|
+
const row = metric.rows.find(value => Number.isFinite(value.value))
|
|
4026
|
+
return h('div', { key: metric.id, className: 'card' }, pressureMetric(metric.id + ' · ' + metric.title,
|
|
4027
|
+
measureText(row), row ? row.scope + ' · ' + row.confidence : '缺少数据'))
|
|
4028
|
+
})),
|
|
4029
|
+
pressureFactors, contextDiagnostics,
|
|
4030
|
+
h('details', { className: 'pressure-section' }, h('summary', null, '工具结果分析'),
|
|
4031
|
+
h('label', null, '查看 ', h('select', { value: trendConfig.toolView ?? 'retained',
|
|
4032
|
+
onChange: event => changeTrend({ toolView: event.currentTarget.value }) },
|
|
4033
|
+
h('option', { value: 'retained' }, '当前残留'), h('option', { value: 'carry' }, '历史累计携带'))),
|
|
4034
|
+
trendConfig.toolView === 'carry'
|
|
4035
|
+
? pressureTable(['工具', '采样调用数', '轮末采样 Token', '跨轮可见次数', '累计重复携带 Token(估算)'],
|
|
4036
|
+
[...new Set([...tools.map(row => row.name), ...burden.map(row => row.name)])].map(name => {
|
|
4037
|
+
const sample = tools.find(row => row.name === name)
|
|
4038
|
+
const carry = burden.find(row => row.name === name)
|
|
4039
|
+
return [name, name, formatPressure(sample?.calls), formatPressure(sample?.tokens),
|
|
4040
|
+
formatPressure(carry?.exposures), formatPressure(carry?.tokensAcrossRequests)]
|
|
4041
|
+
}))
|
|
4042
|
+
: h('div', null,
|
|
4043
|
+
h('label', null, '排序 ', h('select', { value: toolOrder, onChange: event => changeTrend({ toolOrder: event.currentTarget.value }) },
|
|
4044
|
+
h('option', { value: 'tokens' }, 'Token'), h('option', { value: 'turn' }, '产生轮次'), h('option', { value: 'age' }, '年龄'))),
|
|
4045
|
+
pressureTable(['工具', '估算 Token', '产生轮次', '年龄(轮)', '后续携带次数', '仍可见'], currentTools.map(row =>
|
|
4046
|
+
[row.seq, row.name, formatPressure(row.tokens), row.turn,
|
|
4047
|
+
formatPressure(Number.isFinite(latestUsage?.turn) ? latestUsage.turn - row.turn : null),
|
|
4048
|
+
formatPressure(row.carried), row.retained == null ? '—' : row.retained ? '是' : '否'])))),
|
|
4049
|
+
h('details', { className: 'pressure-section' }, h('summary', null, '逐轮诊断记录'),
|
|
4050
|
+
h('button', { type: 'button', onClick: () => changeTrend({ roundAscending: !trendConfig.roundAscending }) },
|
|
4051
|
+
trendConfig.roundAscending ? '最新轮在前' : '最早轮在前'),
|
|
4052
|
+
h('label', null, '跳到轮次 ', h('input', { type: 'number', min: 1, value: trendConfig.diagnosticRound ?? '',
|
|
4053
|
+
onChange: event => changeTrend({ diagnosticRound: event.currentTarget.valueAsNumber || null }) })),
|
|
4054
|
+
...roundNumbers.filter(round => !trendConfig.diagnosticRound || round === trendConfig.diagnosticRound).slice(0, 25).map(round => {
|
|
4055
|
+
const record = rawRecords.get(round)
|
|
4056
|
+
const meter = sampleByRound.get(round)
|
|
4057
|
+
return h('details', { key: round, className: 'pressure-section' }, h('summary', null, '第 ' + round + ' 轮'),
|
|
4058
|
+
pressureTable(['诊断', '读数'], [
|
|
4059
|
+
['input', '请求输入', dictionaryValue(record?.input, 'Token')], ['output', '请求输出', dictionaryValue(record?.output, 'Token')],
|
|
4060
|
+
['delta', '轮末净增长', dictionaryValue(meter?.delta, 'Token')], ['occupancy', '轮末窗口占用率', dictionaryValue(meter?.contextWindow > 0 ? meter.tokens / meter.contextWindow : null, '%')],
|
|
4061
|
+
['requests', '请求次数', formatPressure(record?.requests)], ['tools', '工具残留', dictionaryValue(record?.retained, 'Token')],
|
|
4062
|
+
['cache', '缓存未命中', dictionaryValue(record?.cache ? 1 - record.cache.ratio : null, '%')],
|
|
4063
|
+
['events', '记录事件', meter?.compacted ? '压缩或裁剪' : '—'],
|
|
4064
|
+
]))
|
|
4065
|
+
})))
|
|
4066
|
+
const pressureCalculation = h('div', { className: 'load-panel' },
|
|
4067
|
+
h('h4', null, '七项诊断 → 三个子压力 → A/B/C'),
|
|
4068
|
+
h('button', { type: 'button', onClick: () => {
|
|
4069
|
+
setCapacityExperiment({}); setRequestExperiment({}); setStructureExperiment({}); setCompositeExperiment({})
|
|
4070
|
+
} }, '恢复全部实验默认值'),
|
|
4071
|
+
[capacityExperiment, requestExperiment, structureExperiment, ...Object.values(compositeExperiment)]
|
|
4072
|
+
.some(values => Object.keys(values).length) ? h('p', { className: 'hint' }, '实验参数已修改') : null,
|
|
4073
|
+
...[
|
|
4074
|
+
['capacity', 'C + G · 容量压力', subScores[0], 'γ ' + gamma + ' · H ' + horizon + ' · λ ' + lambda, capacityCalculation],
|
|
4075
|
+
['request', 'U + A + K · 请求负担', subScores[1], 'ρ ' + rho + ' · β ' + beta + ' · τ ' + tau, requestCalculation],
|
|
4076
|
+
['structure', 'T + E · 结构与稳定性', subScores[2], 'wₜ ' + toolWeight + ' · ε ' + epsilon + ' · η ' + eta, structureCalculation],
|
|
4077
|
+
].map(([id, label, value, params, content]) => h('details', { key: id, className: 'pressure-section',
|
|
4078
|
+
open: !!trendConfig['formula:' + id], onToggle: event => {
|
|
4079
|
+
const open = event.currentTarget.open
|
|
4080
|
+
if (!!trendConfig['formula:' + id] !== open) changeTrend({ ['formula:' + id]: open })
|
|
4081
|
+
} }, h('summary', null, label + ' · ' + scoreOf(value) + ' / 100 · ' + params
|
|
4082
|
+
+ (Number.isFinite(value) ? '' : ' · 缺少采样')), content)),
|
|
4083
|
+
compositeCalculation)
|
|
4084
|
+
const headerModel = pressure?.lastRequest?.model ?? (comparison?.current?.route ? JSON.parse(comparison.current.route)[1] : null)
|
|
4085
|
+
const pressureHeader = h('div', { className: 'load-heading', style: { flexWrap: 'wrap' } },
|
|
4086
|
+
h('strong', null, trendChoices.find(row => row.current)?.title || '当前 Session'),
|
|
4087
|
+
h('span', { className: 'hint' }, [latestRound ? latestRound + ' 轮' : '— 轮', headerModel || '模型未知',
|
|
4088
|
+
pressure?.updatedAt ? new Date(pressure.updatedAt).toLocaleTimeString() : '—',
|
|
4089
|
+
pressure?.failed ? '读取失败' : pressure?.availability === 'analyzed' ? '已读取诊断' : '等待诊断'].join(' · ')))
|
|
4090
|
+
function eventTable(points) {
|
|
4091
|
+
const events = points.flatMap(point => point.markers.map((marker, index) => [point.round + ':' + index,
|
|
4092
|
+
point.round, marker.time == null ? '—' : new Date(marker.time).toLocaleString(), marker.type,
|
|
4093
|
+
Number.isFinite(marker.tokenChange) ? signedScore(marker.tokenChange) + ' Token' : '—',
|
|
4094
|
+
h('details', null, h('summary', null, '记录详情'),
|
|
4095
|
+
marker.seq != null ? '日志序号 ' + marker.seq + '。' : '',
|
|
4096
|
+
marker.from && marker.to ? marker.from.join(' / ') + ' → ' + marker.to.join(' / ') + '。' : '',
|
|
4097
|
+
marker.count ? '匹配重试 ' + marker.count + ' 次。' : '',
|
|
4098
|
+
Number.isFinite(marker.tokens) ? '归因耗用 ' + formatPressure(marker.tokens) + ' Token。' : '',
|
|
4099
|
+
Number.isFinite(marker.tokenChange) ? '有成对采样。' : '该事件无成对 Token 变化读数。')]))
|
|
4100
|
+
return events.length ? pressureTable(['轮次', '时间', '事件', 'Token 变化', '来源详情'], events)
|
|
4101
|
+
: h('p', { className: 'hint' }, '该区间暂无已记录的结构性事件。')
|
|
4102
|
+
}
|
|
4103
|
+
const attributionPoints = scoredTrends[attributionId] ?? []
|
|
4104
|
+
const endpoints = attributionPoints.filter(point => point.children?.length === 3 && point.children.every(Number.isFinite))
|
|
4105
|
+
const endpoint = (round, fallback) => endpoints.find(point => point.round === round) ?? fallback
|
|
4106
|
+
const startPoint = endpoint(trendConfig.attributionStart, endpoints[Math.max(0, endpoints.length - 6)])
|
|
4107
|
+
const endPoint = endpoint(trendConfig.attributionEnd, endpoints.at(-1))
|
|
4108
|
+
const attributionPlan = trendConfig.attributionPlan ?? 'A'
|
|
4109
|
+
const lowRound = Math.min(startPoint?.round ?? 0, endPoint?.round ?? 0)
|
|
4110
|
+
const highRound = Math.max(startPoint?.round ?? 0, endPoint?.round ?? 0)
|
|
4111
|
+
const interval = attributionPoints.filter(point => point.round >= lowRound && point.round <= highRound)
|
|
4112
|
+
const contribution = pressureContributions(startPoint?.children, endPoint?.children, attributionPlan, compositeParameters)
|
|
4113
|
+
const forecastLink = trendConfig.attributionForecast
|
|
4114
|
+
const errorRecord = forecastLink ? records.find(row => row.sessionId === attributionId && row.origin === startPoint?.round
|
|
4115
|
+
&& row.target === endPoint?.round && row.plan === attributionPlan && row.method === forecastLink.method) : null
|
|
4116
|
+
const errorParts = errorRecord && pressureContributions(endPoint?.children, errorRecord.predictedChildren, attributionPlan, compositeParameters)
|
|
4117
|
+
const childLines = scoreNames.map((label, index) => ({ id: index, label, color: childColors[index], read: point => point.children?.[index] }))
|
|
4118
|
+
const delta = (start, end) => Number.isFinite(start) && Number.isFinite(end) ? signedScore(end - start) : '—'
|
|
4119
|
+
function contributionBars(values, name) {
|
|
4120
|
+
if (!values) return h('p', { className: 'hint' }, '该公式或端点缺少可分解的分数。')
|
|
4121
|
+
const scale = 208 / Math.max(1, ...values.map(Math.abs))
|
|
4122
|
+
return h('svg', { viewBox: '0 0 650 132', role: 'group', 'aria-label': name, style: { width: '100%' } },
|
|
4123
|
+
h('line', { x1: 320, x2: 320, y1: 6, y2: 116, stroke: 'currentColor', opacity: .6 }),
|
|
4124
|
+
...values.map((value, index) => {
|
|
4125
|
+
const y = 15 + 35 * index
|
|
4126
|
+
const label = scoreNames[index] + '贡献 ' + signedScore(value) + ' 分'
|
|
4127
|
+
return h('g', { key: index, tabIndex: 0, 'aria-label': label },
|
|
4128
|
+
h('title', null, label), h('text', { x: 10, y: y + 13, fill: 'currentColor', fontSize: 14 }, scoreNames[index]),
|
|
4129
|
+
h('rect', { x: 320 + Math.min(0, value * scale), y, width: Math.abs(value * scale), height: 17, fill: childColors[index] }),
|
|
4130
|
+
h('text', { x: 555, y: y + 13, fill: 'currentColor', fontSize: 14 }, signedScore(value)))
|
|
4131
|
+
}))
|
|
4132
|
+
}
|
|
4133
|
+
const attributionPanel = !wantAttribution ? null : h('section', { className: 'load-panel' },
|
|
4134
|
+
h('h4', null, '压力变化归因 · v0.1'),
|
|
4135
|
+
h('div', { style: { display: 'flex', gap: 12, flexWrap: 'wrap' } },
|
|
4136
|
+
h('label', null, 'Session ', h('select', { value: attributionId ?? '',
|
|
4137
|
+
onChange: event => changeTrend({ attributionId: event.currentTarget.value, attributionStart: null,
|
|
4138
|
+
attributionEnd: null, attributionForecast: null }) },
|
|
4139
|
+
...trendChoices.map(row => h('option', { key: row.id, value: row.id }, row.title || '未命名 Session')))),
|
|
4140
|
+
...[['attributionStart', '起始轮次', startPoint], ['attributionEnd', '结束轮次', endPoint]].map(([key, label, value]) =>
|
|
4141
|
+
h('label', { key }, label, ' ', h('select', { value: value?.round ?? '',
|
|
4142
|
+
onChange: event => changeTrend({ [key]: Number(event.currentTarget.value), attributionForecast: null }) },
|
|
4143
|
+
...endpoints.map(point => h('option', { key: point.round, value: point.round }, point.round))))),
|
|
4144
|
+
h('label', null, '综合公式 ', h('select', { value: attributionPlan,
|
|
4145
|
+
onChange: event => changeTrend({ attributionPlan: event.currentTarget.value }) },
|
|
4146
|
+
...plans.map(([id, name]) => h('option', { key: id, value: id }, id + ' · ' + name)))),
|
|
4147
|
+
startPoint && endPoint ? h('button', { type: 'button', onClick: () => changeTrend({
|
|
4148
|
+
attributionStart: endPoint.round, attributionEnd: startPoint.round, attributionForecast: null,
|
|
4149
|
+
}) }, '交换起止轮') : null),
|
|
4150
|
+
trendLoading ? h('p', { role: 'status' }, '正在读取逐轮诊断…') : null,
|
|
4151
|
+
forecastLink ? h('section', { className: 'card' }, h('h4', null, '预测误差归因'),
|
|
4152
|
+
errorRecord ? h('div', null,
|
|
4153
|
+
h('p', null, '第 ' + errorRecord.origin + ' → ' + errorRecord.target + ' 轮 · ' + methodLabels[errorRecord.method]
|
|
4154
|
+
+ ' · 实际 ' + scoreOf(errorRecord.actual) + ' · 预测 ' + scoreOf(errorRecord.estimate)
|
|
4155
|
+
+ ' · 误差 ' + signedScore(errorRecord.estimate - errorRecord.actual)),
|
|
4156
|
+
pressureTable(['子压力', '实际', '预测'], scoreNames.map((name, index) =>
|
|
4157
|
+
[index, name, scoreOf(endPoint.children[index]), scoreOf(errorRecord.predictedChildren[index])])),
|
|
4158
|
+
contributionBars(errorParts, '预测误差贡献'))
|
|
4159
|
+
: h('p', { className: 'hint' }, '当前端点或公式的该次预测无法可靠重建。')) : null,
|
|
4160
|
+
!startPoint || !endPoint ? h('p', { className: 'hint' }, '该会话暂无有效的归因端点。') : h('div', { className: 'load-panel' },
|
|
4161
|
+
interval.length < highRound - lowRound + 1 || interval.some(point => !point.children?.every(Number.isFinite))
|
|
4162
|
+
? h('p', { className: 'hint' }, '区间诊断不完整。贡献依据有效端点,图中保留断点。') : null,
|
|
4163
|
+
h('section', { className: 'card' }, h('h4', null, '端点分数'),
|
|
4164
|
+
pressureTable(['压力项', '起点', '终点', '变化'], [
|
|
4165
|
+
...scoreNames.map((name, i) => [name, name + '子压力', scoreOf(startPoint.children[i]), scoreOf(endPoint.children[i]),
|
|
4166
|
+
delta(startPoint.children[i], endPoint.children[i])]),
|
|
4167
|
+
...plans.map(([id, name]) => [id, id + ' · ' + name, scoreOf(startPoint.scores?.[id]?.score),
|
|
4168
|
+
scoreOf(endPoint.scores?.[id]?.score), delta(startPoint.scores?.[id]?.score, endPoint.scores?.[id]?.score)]),
|
|
4169
|
+
])),
|
|
4170
|
+
h('section', { className: 'card' }, h('h4', null, '三个子压力的变化'),
|
|
4171
|
+
lineToggles('attributionHidden', childLines),
|
|
4172
|
+
pressureLines(interval, childLines.filter(line => !(trendConfig.attributionHidden ?? []).includes(line.id)),
|
|
4173
|
+
[...new Set([startPoint.round, endPoint.round])])),
|
|
4174
|
+
h('section', { className: 'card' }, h('h4', null, '综合压力贡献'),
|
|
4175
|
+
contributionBars(contribution, '综合压力变化贡献'),
|
|
4176
|
+
h('p', { className: 'hint' }, '贡献表示评分公式中的数学影响,不代表现实因果关系。')),
|
|
4177
|
+
h('details', { className: 'pressure-section' }, h('summary', null, '七项诊断变化明细'),
|
|
4178
|
+
...dictionary.map(metric => {
|
|
4179
|
+
const keys = row => JSON.stringify([row.label, row.scope, row.unit])
|
|
4180
|
+
const start = new Map((startPoint.diagnostics?.find(item => item.id === metric.id)?.rows ?? []).map(row => [keys(row), row]))
|
|
4181
|
+
const end = new Map((endPoint.diagnostics?.find(item => item.id === metric.id)?.rows ?? []).map(row => [keys(row), row]))
|
|
4182
|
+
return h('details', { key: metric.id, className: 'pressure-section' }, h('summary', null, metric.id + ' · ' + metric.title),
|
|
4183
|
+
pressureTable(['读数', '起点', '终点', '差值', '来源', '范围'], [...new Set([...start.keys(), ...end.keys()])].map(key => {
|
|
4184
|
+
const a = start.get(key)
|
|
4185
|
+
const b = end.get(key)
|
|
4186
|
+
const row = a ?? b
|
|
4187
|
+
const d = a && b ? b.value - a.value : null
|
|
4188
|
+
const unit = row.unit === '%' || row.unit === '百分点' ? '百分点' : row.unit
|
|
4189
|
+
return [key, row.label, measureText(a), measureText(b), dictionaryValue(d, unit), row.source, row.scope]
|
|
4190
|
+
})))
|
|
4191
|
+
})),
|
|
4192
|
+
h('details', { className: 'pressure-section' }, h('summary', null, '结构性事件时间线'), eventTable(interval))))
|
|
4193
|
+
const selectedSessionsSummary = h('details', { className: 'pressure-section' }, h('summary', null, 'Session 概览'),
|
|
4194
|
+
pressureTable(['Session', '实际轮数', '最后有效轮', '最后模型 / 窗口', '配置切换', '成功压缩', '有效轮'], trendIds.map(id => {
|
|
4195
|
+
const points = scoredTrends[id] ?? []
|
|
4196
|
+
const valid = points.filter(point => Number.isFinite(point.scores?.[displayedPlans[0]]?.score))
|
|
4197
|
+
return [id, trendChoices.find(row => row.id === id)?.title || '未命名 Session',
|
|
4198
|
+
points.length || '—', valid.at(-1)?.round ?? '—', routeDetails(points.at(-1) ?? {}) || '—',
|
|
4199
|
+
points.length ? points.some(point => point.switched) ? '有' : '无' : '—',
|
|
4200
|
+
points.length ? points.reduce((count, point) => count + point.markers.filter(marker => marker.type === '压缩成功').length, 0) : '—',
|
|
4201
|
+
points.length ? valid.length + ' / ' + points.length : '—']
|
|
4202
|
+
})))
|
|
4203
|
+
const historyView = h('div', { className: 'load-panel' }, pressureHistory,
|
|
4204
|
+
h('div', { className: 'tabs load-tabs', role: 'group', 'aria-label': '历史分析视图' },
|
|
4205
|
+
...[['compare', 'Session 对比'], ['same', '同轮次比较'], ['backtest', '预测回测'], ['attribution', '变化归因']].map(([id, label]) =>
|
|
4206
|
+
h('button', { key: id, type: 'button', className: 'tab' + (id === historyPage ? ' on' : ''),
|
|
4207
|
+
'aria-pressed': id === historyPage, onClick: () => changeTrend({ historyPage: id }) }, label))),
|
|
4208
|
+
historyPage === 'compare' ? h('div', null, trendChart, selectedSessionsSummary)
|
|
4209
|
+
: historyPage === 'same' ? sameRoundPanel : historyPage === 'backtest' ? pressureBacktest : attributionPanel)
|
|
4210
|
+
|
|
4211
|
+
const pressureCard = h('details', { className: 'card full',
|
|
4212
|
+
onToggle: event => setPressureOpen(event.currentTarget.open) },
|
|
4213
|
+
h('summary', null, h('strong', null, '会话压力')),
|
|
4214
|
+
pressureOpen ? h('div', null,
|
|
4215
|
+
pressure?.usage?.partial || pressure?.usage?.pendingCount > 0
|
|
4216
|
+
? h('p', { className: 'hint', role: 'status' }, '部分结果 · 历史已分析 '
|
|
4217
|
+
+ pressure.usage.analyzedCount + ' / ' + pressure.usage.selectedCount
|
|
4218
|
+
+ ' · 待处理 ' + pressure.usage.pendingCount) : null,
|
|
4219
|
+
pressureHeader, loadTabBar,
|
|
4220
|
+
pressureTab === 'current' ? pressureCurrent : pressureTab === 'history' ? historyView : pressureTab === 'factors' ? diagnosticsView : pressureCalculation) : null)
|
|
4221
|
+
|
|
2663
4222
|
const tabBar = h('div', { className: 'tabs' },
|
|
2664
4223
|
...TABS.map(([id, name]) => h('button', {
|
|
2665
4224
|
key: id,
|
|
@@ -2764,6 +4323,20 @@ window.__ModuleLoader__.load({
|
|
|
2764
4323
|
// 图/声音/影像只是标签,不评价(1.0.5)。
|
|
2765
4324
|
const KIND_LABEL = { text: '文字', image: '图', audio: '声音', video: '影像', file: '文件' }
|
|
2766
4325
|
|
|
4326
|
+
// 东西落在哪儿(2026-11-17,用户):路径写在明面上,旁边一颗「打开文件夹」。
|
|
4327
|
+
// 浏览器开不了本地文件夹,所以真正的打开动作交给服务端(/works-open)。
|
|
4328
|
+
// 不再单独放一颗「复制路径」:路径本来就选得中,两个按钮做同一件兜底,只会让人先犹豫点哪个。
|
|
4329
|
+
const workDirPath = typeof works?.dir === 'string' ? works.dir : ''
|
|
4330
|
+
const openWorkDir = async () => {
|
|
4331
|
+
try {
|
|
4332
|
+
const r = await jpost('/works-open', {})
|
|
4333
|
+
if (!r || r.ok === false) { setWorkMsg(r?.error || '打不开文件夹。路径就在上面,选中复制就行。'); return }
|
|
4334
|
+
setWorkMsg('')
|
|
4335
|
+
} catch (e) {
|
|
4336
|
+
setWorkMsg(e.message || '打不开文件夹。路径就在上面,选中复制就行。')
|
|
4337
|
+
}
|
|
4338
|
+
}
|
|
4339
|
+
|
|
2767
4340
|
const worksCard = group(S('她的东西'),
|
|
2768
4341
|
S('她自己愿意留下的,不是每天都有。只留在家里这一份,不往外面发;你点开只是读,她不知道,也不会因此多写一件。'),
|
|
2769
4342
|
works
|
|
@@ -2785,6 +4358,13 @@ window.__ModuleLoader__.load({
|
|
|
2785
4358
|
`${w.kind && w.kind !== 'text' ? `${KIND_LABEL[w.kind] || ''} · ` : ''}${w.stateText} · 第 ${Number(w.version) || 1} 版 · ${w.day}`))))
|
|
2786
4359
|
: h('p', { className: 'hint' }, S('还没有。她什么时候觉得有个东西值得留下,就会自己放到这儿。')))
|
|
2787
4360
|
: h('p', { className: 'hint' }, '正在读……'),
|
|
4361
|
+
workDirPath
|
|
4362
|
+
? h('div', { className: 'row', style: { gap: '8px', alignItems: 'baseline', marginTop: '10px', flexWrap: 'wrap' } },
|
|
4363
|
+
h('span', {
|
|
4364
|
+
style: { fontSize: '12px', opacity: 0.7, wordBreak: 'break-all', fontFamily: 'ui-monospace, Consolas, monospace' },
|
|
4365
|
+
}, workDirPath),
|
|
4366
|
+
h('button', { className: 'ghost', style: { padding: '0 8px' }, onClick: openWorkDir }, '打开文件夹'))
|
|
4367
|
+
: null,
|
|
2788
4368
|
workMsg ? h('p', { className: 'hint', style: { margin: '6px 0 0' } }, workMsg) : null)
|
|
2789
4369
|
|
|
2790
4370
|
// 点开的那一件。版本并排给,不排序、不标「最新更好」——哪一版好是她自己的判断。
|
|
@@ -2897,6 +4477,7 @@ window.__ModuleLoader__.load({
|
|
|
2897
4477
|
// 规则不是设置项——能在这里改规则,就等于能在这里改她。
|
|
2898
4478
|
rules ? group('规则约束',
|
|
2899
4479
|
'四层:物理层(代码保证,不进提示词)、契约层(不许把关系变成分数)、起点层(一开始是谁)、成长层(可以自己申请)。'
|
|
4480
|
+
+ '「还不会」不是禁令——为什么这样写、要到什么条件,说明里有一条专门讲。'
|
|
2900
4481
|
+ (rules.offersOn === false ? '成长层的申请通道现在关着(已有的不会撤销)。' : ''),
|
|
2901
4482
|
rules.pending ? h('div', {
|
|
2902
4483
|
style: {
|
|
@@ -2968,9 +4549,9 @@ window.__ModuleLoader__.load({
|
|
|
2968
4549
|
'醒来通常带一张事件卡。定时醒来取「每天定时醒几次」和「每天几张事件卡」里小的;主动搭话另算,不占这个数。这是上限,不是保证:没有可出的事、或落点太靠后,可能少醒一次。',
|
|
2969
4550
|
h('div', { className: 'grid2' },
|
|
2970
4551
|
Num({ label: '每天定时醒几次', value: wakes, onChange: setWakes, min: 0, max: 12, unit: '次',
|
|
2971
|
-
hint: '
|
|
4552
|
+
hint: S('只限定时醒来(含空醒)。你手动叫醒会记一次、挤掉后面的定时醒来,但手动本身随时能按(每天醒 0 次时除外)。0 为关掉定时醒来,右上角「现在叫醒大肥鱼」也叫不醒;直接跟她说话不受影响。范围 0–12:每醒一次都是一次模型调用,开得越密越慢、越费钱;醒来时段只有 3 小时,12 次已经接近每 15 分钟一次。') }),
|
|
2972
4553
|
Num({ label: '每天几张事件卡', value: eventsPerDay, onChange: setEventsPerDay, min: 0, max: 12, unit: '张',
|
|
2973
|
-
hint: '只限定时醒来;和「每天定时醒几次」取小的(两个都调大才有效)。0
|
|
4554
|
+
hint: S('只限定时醒来;和「每天定时醒几次」取小的(两个都调大才有效)。0 为关掉定时醒来,手动按钮也叫不醒;直接跟她说话不受影响。范围 0–12。') }),
|
|
2974
4555
|
Num({ label: '对话停下来多久才叫醒', value: quietMin, onChange: setQuietMin, min: 0, max: 60, unit: '分钟',
|
|
2975
4556
|
hint: '你刚说完话的这几分钟里,定时醒来和主动搭话都先不插进来,等安静下来再叫;一直在聊就一直等,等到这次醒来时段快结束就算了。0 = 不拦(以前的样)。' }),
|
|
2976
4557
|
Sel({ label: '每天问题卡数', value: questionsPerDay, onChange: setQuestionsPerDay, options: [0, 1, 2, 3, 4, 5, 6],
|
|
@@ -3047,6 +4628,9 @@ window.__ModuleLoader__.load({
|
|
|
3047
4628
|
options: [0, 1, 2, 3],
|
|
3048
4629
|
fmt: (v) => (Number(v) === 0 ? '0 次 · 不做' : `${v} 次`),
|
|
3049
4630
|
hint: '看视频、看小说、玩游戏这类算消耗;同一件还要隔三天,连着三次同类歇一周。' })),
|
|
4631
|
+
Toggle({ label: '让兴趣也能起一轮', on: interestGateOn,
|
|
4632
|
+
onChange: (v) => { setInterestGateOn(v); patchProactive({ interestGate: v }) },
|
|
4633
|
+
hint: '同一件事三天里反复出现、七天没因它起过、劲儿到 0.9 才起;一天最多一次。默认关。' }),
|
|
3050
4634
|
adv('高级',
|
|
3051
4635
|
Text({ label: '外部工具算哪类', value: doingClasses, wide: true,
|
|
3052
4636
|
placeholder: '每行一个:工具名=consume(也可以是 produce/effect/self)',
|
|
@@ -3386,7 +4970,16 @@ window.__ModuleLoader__.load({
|
|
|
3386
4970
|
TimeRange({ label: '上网时间段(未成年人模式)', from: browseFrom, to: browseTo, onFrom: setBrowseFrom, onTo: setBrowseTo,
|
|
3387
4971
|
hint: S('默认跟着「几点醒」走。她睡着的时候不会出门翻视频,醒来那一刻才现去翻(她自己临时去看不受这条限制)。') })),
|
|
3388
4972
|
Toggle({ label: S('按时间自动替她逛一圈'), on: browseOn, onChange: setBrowseOn,
|
|
3389
|
-
hint: S('到点自己出去走一趟:只看、只记,不叫醒她,也不会把视频标题塞进每一轮。她下次醒来只会看到一行「今天又翻到了哪几条」。') })
|
|
4973
|
+
hint: S('到点自己出去走一趟:只看、只记,不叫醒她,也不会把视频标题塞进每一轮。她下次醒来只会看到一行「今天又翻到了哪几条」。') }),
|
|
4974
|
+
h('div', { className: 'row', style: { marginTop: '8px' } },
|
|
4975
|
+
h('button', {
|
|
4976
|
+
className: 'ghost',
|
|
4977
|
+
onClick: browseNow,
|
|
4978
|
+
disabled: busy === 'browse-now' || !biliOn,
|
|
4979
|
+
title: S('整理已经刷到、还没给她看的视频;没有积压时只提示,不会叫醒她。'),
|
|
4980
|
+
}, busy === 'browse-now' ? '正在翻…' : '现在去看积压的视频')),
|
|
4981
|
+
h('p', { className: 'hint', style: { marginTop: '6px' } },
|
|
4982
|
+
S('有积压时会在她那边开一轮,让她自己挑;没有积压时只提示,不会叫醒她。'))),
|
|
3390
4983
|
group('翻视频',
|
|
3391
4984
|
// 「每天最多刷几次」只有自动逛读;她自己翻(bili_look)不受它限制,其余几项两边都用。
|
|
3392
4985
|
S('她翻首页、搜索、相关推荐或点开一条时用这几项;「每天最多刷几次」除外,它只管自动逛。'),
|
|
@@ -3672,11 +5265,26 @@ window.__ModuleLoader__.load({
|
|
|
3672
5265
|
h('div', { className: 'grid2' },
|
|
3673
5266
|
Num({ label: '聊满多少轮换新会话', value: rotateAfter, onChange: setRotateAfter, min: 0, max: 500, unit: '轮',
|
|
3674
5267
|
hint: S('聊满这个轮数之后,还要等一次停顿才换:最后一句话过去 20 分钟没人接,下一轮开头换新会话;如果一直连着聊,最多再延 10 轮强制换。所以换房总落在对话的缝隙里,不会从话中间切开。默认 120。0 = 永不换——那条会话会一直聊到宿主上下文撑不住为止,之后这一轮会直接失败(不会自动换)。换的时候带过去的是最近几轮原话(「上次我们说到这」)和还挂着的事,带几轮由下面那一项决定;身份段本来每轮都有,不用另带。') }),
|
|
3675
|
-
|
|
3676
|
-
|
|
5268
|
+
// 2026-11-17 用户 m04639:A+C。carry 真的决定摆几轮,设置用档位而不是裸数字;
|
|
5269
|
+
// 当前值不在档位里(老用户可能是 4)就把它动态加进去,否则 select 会误显示第一项。
|
|
5270
|
+
Sel({ label: '换新会话时带几轮原话',
|
|
5271
|
+
value: carryTurns,
|
|
5272
|
+
onChange: (v) => setCarryTurns(Number(v)),
|
|
5273
|
+
options: [...new Set([0, 3, 6, 12, Number(carryTurns)])].filter((v) => Number.isFinite(v)).sort((a, b) => a - b),
|
|
5274
|
+
fmt: (v) => {
|
|
5275
|
+
const n = Number(v)
|
|
5276
|
+
if (n === 0) return '不带原话 · 只带还挂着的事'
|
|
5277
|
+
if (n === 3) return '少 · 3 轮'
|
|
5278
|
+
if (n === 6) return '中 · 6 轮'
|
|
5279
|
+
if (n === 12) return '多 · 12 轮'
|
|
5280
|
+
return `${n} 轮`
|
|
5281
|
+
},
|
|
5282
|
+
hint: S('只影响换窗口后的第一轮:最后 1 轮不裁剪,再往前每轮 40 字;页面上限随轮数放大(400–1200 字)。带得越多,第一轮越贵,也越容易接着旧话题说。0 = 不带原话,只带还挂着的事;更早的事用 her_recall 翻。') }),
|
|
3677
5283
|
Num({ label: '身份段字数', value: docBudget, onChange: setDocBudget, min: 1800, max: 8000, step: 100, unit: '字',
|
|
3678
5284
|
hint: S('她每轮读到的身份段最多多少字;超了先省次要段。范围 1800–8000:1800 以下装不下现在已经有的段,8000 以上每轮都在为这段文字付钱。') }))),
|
|
3679
5285
|
|
|
5286
|
+
// 会话压力不再放在设置页(2026-11-17,用户 m02888):挪到对话页的「压力」页签 + 头部小胶囊。
|
|
5287
|
+
|
|
3680
5288
|
// ---- 记忆(原「背了多少东西」) ----
|
|
3681
5289
|
// 全是客观计数:多少字、占预算几成、多少条被挤掉。
|
|
3682
5290
|
// 刻意不出现任何"打分"型指标(那属于 N2 禁止的量化评价)。
|
|
@@ -3741,7 +5349,7 @@ window.__ModuleLoader__.load({
|
|
|
3741
5349
|
`这几段这一轮放不下:${mem.selfDoc.dropped.join('、')}。调大「身份段字数」可以放回来。`)
|
|
3742
5350
|
: null,
|
|
3743
5351
|
h('p', { className: 'dim', style: { marginTop: '8px' } },
|
|
3744
|
-
'记忆深刻的认知详细记录;普通认知只有一句话,超出上下文的不重要记忆被折叠,被模糊(不是完全消失,只是可能记不太清)。被反复提起、或被反复检验过的会固定下来(记得很牢):身份段里最多列
|
|
5352
|
+
'记忆深刻的认知详细记录;普通认知只有一句话,超出上下文的不重要记忆被折叠,被模糊(不是完全消失,只是可能记不太清)。被反复提起、或被反复检验过的会固定下来(记得很牢):身份段里最多列 3 条,字数紧时这一段也可能放不下;90 天没再被提起或检验,就会掉回普通的。固定不代表那句是对的。'),
|
|
3745
5353
|
h('p', { className: 'dim', style: { marginTop: '6px' } },
|
|
3746
5354
|
'为什么这样做?1.节省token成本2.全量记忆等于提示词污染/强调,会让人格的改变无从发生3.在遗忘发生时,什么能够留下来才是更显珍贵的。'))),
|
|
3747
5355
|
|
|
@@ -3977,6 +5585,9 @@ window.__ModuleLoader__.load({
|
|
|
3977
5585
|
'——来自开发者'))
|
|
3978
5586
|
|
|
3979
5587
|
const principlePage = h('div', { className: 'page' },
|
|
5588
|
+
// 说明入口(2026-11-16 用户 m03816):不要独立页签,放在原理页最上面、三张图上方。
|
|
5589
|
+
// 一条链接,点了由系统浏览器打开那份 HTML——路怎么走通的见 WikiLink 上面那段注释。
|
|
5590
|
+
h(WikiLink),
|
|
3980
5591
|
groupFull(S('三张图看懂她怎么长大'),
|
|
3981
5592
|
S('第一张讲「经历怎么变成认知」,第二张讲「记忆怎么被筛、哪些永远不折叠」,第三张讲「她为什么自己开口、自己动手」。图小的时候点一下放大,按住可以拖动,滚轮缩放,Esc 关掉。'),
|
|
3982
5593
|
zoomable(`${API}/media/principle-loop.svg?v=20261114`, '认知构建循环:五步循环、四阶段与三道瓶颈',
|
|
@@ -4035,8 +5646,8 @@ window.__ModuleLoader__.load({
|
|
|
4035
5646
|
'回忆、验证、复习节奏', 'after'),
|
|
4036
5647
|
theoryCard('兴趣与腻',
|
|
4037
5648
|
'Hidi & Renninger 兴趣发展(2006)+ Zajonc 单纯曝光(1968)',
|
|
4038
|
-
S('兴趣不是标签:只从她最近反复回到的话里现算,24 小时内重复打对折、14
|
|
4039
|
-
'
|
|
5649
|
+
S('兴趣不是标签:只从她最近反复回到的话里现算,24 小时内重复打对折、14 天半衰。平时它只决定先摆哪一条,不替她决定做什么;同一件事连着来,她也会腻。开了兴趣门之后,一件反复出现、七天没因它起过的事,可以在劲儿到 0.9 时为它单独起一轮,一天最多一次——仍然不替她决定这一轮说什么、做什么。'),
|
|
5650
|
+
'选卡顺序、动手候选排序、兴趣门', 'after'),
|
|
4040
5651
|
theoryCard('刹车:额度是环境不是人格',
|
|
4041
5652
|
'Thaler & Shefrin 计划者-行动者(1981)',
|
|
4042
5653
|
S('她可以自己决定做哪件,但一天做几件由环境定:消耗类一天一次、同一件三天冷却、连着三次同类停一周。额度用完只能来问你。这些写成世界的边界,不写进她的人格——不出现「你是个节制的人」,也不出现「今天做了几件」。'),
|
|
@@ -4311,9 +5922,10 @@ window.__ModuleLoader__.load({
|
|
|
4311
5922
|
border: '0.5px solid var(--dsw-alias-border-l2)',
|
|
4312
5923
|
},
|
|
4313
5924
|
}),
|
|
4314
|
-
// 2026-11-
|
|
5925
|
+
// 2026-11-17:换到 3 群。这个群没开「搜群号进群」,只支持扫码,
|
|
5926
|
+
// 所以下面不写群号——写了反而让人去搜一个搜不到的东西。
|
|
4315
5927
|
h('div', { className: 'hint', style: { margin: '10px 0 0' } },
|
|
4316
|
-
'
|
|
5928
|
+
'只能扫码进群。扫不出来就截图放大一点再扫。'))))
|
|
4317
5929
|
|
|
4318
5930
|
// 顺序是用户定的:①手上能用什么 ②为什么默认只放这几个 ③关于(版本 / 检查更新 / GitHub)。
|
|
4319
5931
|
// 「关于」放最后——它是这个页的收尾,不是打开就要看的东西。
|
|
@@ -5248,6 +6860,7 @@ window.__ModuleLoader__.load({
|
|
|
5248
6860
|
// 云上现在有哪些份。灾后换台机器、本机是空的时候,只剩这条路能数得清。
|
|
5249
6861
|
async function viewCloudRemote(t) {
|
|
5250
6862
|
setCloudBusy(true)
|
|
6863
|
+
setCloudRemoteLoading(t.id)
|
|
5251
6864
|
setCloudMsg('正在问那边有哪些份……')
|
|
5252
6865
|
try {
|
|
5253
6866
|
const r = await jget(`/cloud/remote?id=${encodeURIComponent(t.id)}`)
|
|
@@ -5257,6 +6870,7 @@ window.__ModuleLoader__.load({
|
|
|
5257
6870
|
setCloudMsg(`数不回来:${e.message}`)
|
|
5258
6871
|
} finally {
|
|
5259
6872
|
setCloudBusy(false)
|
|
6873
|
+
setCloudRemoteLoading('')
|
|
5260
6874
|
}
|
|
5261
6875
|
}
|
|
5262
6876
|
// 从云上取回来恢复:先取、再解(加密的话),最后走和「从备份恢复」同一条路。
|
|
@@ -5725,7 +7339,8 @@ window.__ModuleLoader__.load({
|
|
|
5725
7339
|
cloudAction('看看现在还连得上吗',
|
|
5726
7340
|
'只测连通,不传任何东西,也不动云上已有的那几份。',
|
|
5727
7341
|
() => testCloudTarget(t)),
|
|
5728
|
-
t.kind === 'smtp' ? null : cloudAction(
|
|
7342
|
+
t.kind === 'smtp' ? null : cloudAction(
|
|
7343
|
+
cloudRemoteLoading === t.id ? '正在问那边有哪些份……' : '看看云上已经存了哪几份',
|
|
5729
7344
|
'列出来之后能取回本机,也能就地恢复。',
|
|
5730
7345
|
() => viewCloudRemote(t)),
|
|
5731
7346
|
cloudAction(cloudDelConfirm === t.id ? '真的删掉' : '删掉这一处',
|
|
@@ -5746,9 +7361,12 @@ window.__ModuleLoader__.load({
|
|
|
5746
7361
|
h('button', { disabled: cloudBusy || !kindChosen, onClick: () => { setCloudDraft(targetDraftOf(kindChosen)); setCloudMsg('') } }, '点击配置')),
|
|
5747
7362
|
cloudDraftBody,
|
|
5748
7363
|
cloudRemote
|
|
5749
|
-
? h('div', { style: { marginTop: '12px', padding: '10px 0', borderTop: '.5px solid var(--dsw-alias-border-l2)' } },
|
|
7364
|
+
? h('div', { ref: cloudRemoteRef, style: { marginTop: '12px', padding: '10px 0', borderTop: '.5px solid var(--dsw-alias-border-l2)' } },
|
|
5750
7365
|
h('p', { className: 'grouphd' }, `「${cloudRemote.target?.name || cloudRemote.target?.kind}」那边现在有:`),
|
|
5751
7366
|
h('p', { className: 'hint' }, '云上放着的是加密过的(文件名后面多个 .enc),不是普通的 json。想拿回去:点「取到本机」会解开并放进备份文件夹,之后用上面「从备份恢复」导入;点「直接恢复」是就地换上这份档,不经过文件。'),
|
|
7367
|
+
cloudRemote.items?.length
|
|
7368
|
+
? h('p', { className: 'hint' }, `${cloudRemote.items.length} 份,合计 ${(cloudRemote.items.reduce((s, it) => s + (Number(it.bytes) || 0), 0) / 1048576).toFixed(1)}MB。只算这个目录里的文件;git 历史另算,删旧份也不会让它变小。`)
|
|
7369
|
+
: null,
|
|
5752
7370
|
cloudRemote.items?.length
|
|
5753
7371
|
? h('div', null, ...cloudRemote.items.map((it) => h('div', { key: it.name, className: 'row', style: { gap: '8px', marginTop: '4px' } },
|
|
5754
7372
|
h('span', { className: 'dim', style: { flex: '1', minWidth: '180px' } }, `${it.name}${it.bytes ? ` ${Math.max(1, Math.round(it.bytes / 1024))}KB` : ''}`),
|
|
@@ -5821,7 +7439,7 @@ window.__ModuleLoader__.load({
|
|
|
5821
7439
|
// 文件落在哪儿、叫什么名字都有可能,导入按钮得自己认。
|
|
5822
7440
|
h('p', { className: 'hint' }, '从网盘下载下来的 `.enc` 加密包也能直接选:这颗按钮不挑扩展名,认的是文件内容。'),
|
|
5823
7441
|
h('div', null,
|
|
5824
|
-
h('p', { className: 'hint' }, '
|
|
7442
|
+
h('p', { className: 'hint' }, '备份含会话压力的轮末采样和压缩配对读数。一般运行日志和旧备份会排除。'),
|
|
5825
7443
|
// 手动这一颗始终是全量(2026-11-16,用户 m00712):自动/云端的凭据开关不管它。
|
|
5826
7444
|
// 备份能发出去、能放网盘,所以这件事要写在按钮旁边,不能只在迁移卡里提一句。
|
|
5827
7445
|
h('p', { className: 'hint' }, '也含主人身份和 B 站登录凭据(登录过的话)。拿到这份文件就能用你的 B 站登录,别随手发给别人。自动备份与云端那份默认不带凭据,不受这里影响。'),
|
|
@@ -6065,6 +7683,12 @@ window.__ModuleLoader__.load({
|
|
|
6065
7683
|
|
|
6066
7684
|
const showTab = (id) => tab === id
|
|
6067
7685
|
|
|
7686
|
+
if (err && !state) {
|
|
7687
|
+
return h('div', { className: 'dfish' },
|
|
7688
|
+
h('h2', null, '大肥鱼'),
|
|
7689
|
+
h('p', { className: 'sub' }, '读不到状态。'),
|
|
7690
|
+
h('pre', { className: 'err' }, err))
|
|
7691
|
+
}
|
|
6068
7692
|
|
|
6069
7693
|
return h('div', { className: 'dfish', ref: (el) => { topEl = el } },
|
|
6070
7694
|
h('h2', null, '大肥鱼'),
|
|
@@ -6146,6 +7770,7 @@ window.__ModuleLoader__.load({
|
|
|
6146
7770
|
showTab('memory') ? memoryPage : null,
|
|
6147
7771
|
showTab('env') ? envPage : null,
|
|
6148
7772
|
showTab('principle') ? principlePage : null,
|
|
7773
|
+
// 2026-11-16(用户 m03816):原来自成一页的说明,现在挂在原理页最上面(WikiLink)。
|
|
6149
7774
|
showTab('data') ? dataPage : null,
|
|
6150
7775
|
showTab('feedback') ? feedbackPage : null,
|
|
6151
7776
|
showTab('outing') ? outingPage : null,
|
|
@@ -6157,6 +7782,438 @@ window.__ModuleLoader__.load({
|
|
|
6157
7782
|
}
|
|
6158
7783
|
|
|
6159
7784
|
|
|
7785
|
+
// ---------------------------------------------------------------- 会话压力(对话页)
|
|
7786
|
+
// 2026-11-17(用户 m02719):压力入口从设置页搬到对话页——会话头部一个小胶囊,
|
|
7787
|
+
// 点开是迷你面板;另有「压力」页签放稍微完整一点的表。按工作区过滤由服务端做,
|
|
7788
|
+
// 不是她这间房的会话返回 not-fish,这里什么都不渲染。
|
|
7789
|
+
function pressureK(value) {
|
|
7790
|
+
const n = Number(value)
|
|
7791
|
+
if (!Number.isFinite(n)) return '—'
|
|
7792
|
+
if (n >= 1e6) return `${(n / 1e6).toFixed(1)}M`
|
|
7793
|
+
if (n >= 1e3) return `${Math.round(n / 1e3)}k`
|
|
7794
|
+
return String(Math.round(n))
|
|
7795
|
+
}
|
|
7796
|
+
|
|
7797
|
+
function pressureTone(score) {
|
|
7798
|
+
const n = Number(score)
|
|
7799
|
+
if (!Number.isFinite(n)) return 'var(--dsh-text-dim, #8a8a8a)'
|
|
7800
|
+
if (n >= 85) return 'var(--dsh-danger, #d9534f)'
|
|
7801
|
+
if (n >= 70) return 'var(--dsh-warning, #c9973f)'
|
|
7802
|
+
return 'var(--dsh-success, #3f9e63)'
|
|
7803
|
+
}
|
|
7804
|
+
|
|
7805
|
+
// 逐轮曲线的分要在浏览器里现算:服务端 live 只给当前这一轮的总分。
|
|
7806
|
+
// 公式与 lib/session-pressure.js 的 pressureScore 保持一致(2026-11-18 真机点开胶囊消失)。
|
|
7807
|
+
function pressureScore(tokens, threshold) {
|
|
7808
|
+
if (!Number.isFinite(tokens) || tokens < 0 || !Number.isFinite(threshold) || threshold <= 0) return null
|
|
7809
|
+
return Math.min(100, 100 * tokens / threshold)
|
|
7810
|
+
}
|
|
7811
|
+
|
|
7812
|
+
// 不再定时轮询(2026-11-18 用户 m03880):挂载取一次、打开弹层取一次(带 composite)、
|
|
7813
|
+
// 页面重新可见时取一次;房外会话在服务端就是 not-fish,前端也不会去问别的房间。
|
|
7814
|
+
function usePressure(sessionId, active) {
|
|
7815
|
+
const [data, setData] = useState(null)
|
|
7816
|
+
const [failed, setFailed] = useState(false)
|
|
7817
|
+
const [tick, setTick] = useState(0)
|
|
7818
|
+
useEffect(() => {
|
|
7819
|
+
if (!sessionId) return undefined
|
|
7820
|
+
let alive = true
|
|
7821
|
+
let timer = null
|
|
7822
|
+
let attempts = 0
|
|
7823
|
+
const run = async () => {
|
|
7824
|
+
try {
|
|
7825
|
+
const q = `session=${encodeURIComponent(sessionId)}${active ? '&composite=1' : ''}`
|
|
7826
|
+
const next = await jget(`/session-pressure?${q}`)
|
|
7827
|
+
if (!alive) return
|
|
7828
|
+
setData(next)
|
|
7829
|
+
setFailed(false)
|
|
7830
|
+
// 服务端第一次常常还在算(availability=pending)。只在这段时间里短轮询,
|
|
7831
|
+
// 算完就停;不做常驻定时器(2026-11-18 用户反馈胶囊要等点击才出现)。
|
|
7832
|
+
if (next?.availability === 'pending' && attempts < 8) {
|
|
7833
|
+
attempts += 1
|
|
7834
|
+
timer = setTimeout(() => { void run() }, 1500)
|
|
7835
|
+
}
|
|
7836
|
+
} catch {
|
|
7837
|
+
if (alive) setFailed(true)
|
|
7838
|
+
}
|
|
7839
|
+
}
|
|
7840
|
+
void run()
|
|
7841
|
+
const onVisible = () => { if (typeof document !== 'undefined' && document.visibilityState === 'visible') void run() }
|
|
7842
|
+
if (typeof document !== 'undefined') document.addEventListener?.('visibilitychange', onVisible)
|
|
7843
|
+
return () => {
|
|
7844
|
+
alive = false
|
|
7845
|
+
if (timer) clearTimeout(timer)
|
|
7846
|
+
if (typeof document !== 'undefined') document.removeEventListener?.('visibilitychange', onVisible)
|
|
7847
|
+
}
|
|
7848
|
+
}, [sessionId, active, tick])
|
|
7849
|
+
return [data, failed, () => setTick(n => n + 1)]
|
|
7850
|
+
}
|
|
7851
|
+
|
|
7852
|
+
function pressureMiniRows(data) {
|
|
7853
|
+
const rows = data?.usage?.roundDiagnostics ?? []
|
|
7854
|
+
return rows.slice(-6).map(row => h('div', {
|
|
7855
|
+
key: String(row.turn),
|
|
7856
|
+
style: { display: 'flex', justifyContent: 'space-between', gap: '8px', fontSize: '12px', opacity: 0.85 },
|
|
7857
|
+
},
|
|
7858
|
+
h('span', null, `第 ${row.turn} 轮`),
|
|
7859
|
+
h('span', null, `输入 ${pressureK(row.input)} · 输出 ${pressureK(row.output)}`)))
|
|
7860
|
+
}
|
|
7861
|
+
|
|
7862
|
+
// 宿主的主题变量不保证凑齐(深色下 --dsh-surface 有、--dsh-text 未必有),
|
|
7863
|
+
// 这里看页面正文文字颜色的明暗判断深浅,再把一整套面板颜色从根上传下去。
|
|
7864
|
+
function pressurePalette(el) {
|
|
7865
|
+
let dark = false
|
|
7866
|
+
try {
|
|
7867
|
+
const probe = (typeof document !== 'undefined' && document.body) || el
|
|
7868
|
+
const m = /rgba?\((\d+),\s*(\d+),\s*(\d+)/.exec(String(getComputedStyle(probe).color || ''))
|
|
7869
|
+
if (m) dark = (0.2126 * Number(m[1]) + 0.7152 * Number(m[2]) + 0.0722 * Number(m[3])) / 255 > 0.5
|
|
7870
|
+
} catch { /* 取不到样式就按浅色面板兜底 */ }
|
|
7871
|
+
return dark
|
|
7872
|
+
? { surface: '#1f2023', text: '#ececef', dim: '#a1a1aa', border: 'rgba(255,255,255,.14)', chip: 'rgba(255,255,255,.07)' }
|
|
7873
|
+
: { surface: '#ffffff', text: '#1d1d1f', dim: '#6b7280', border: 'rgba(0,0,0,.12)', chip: 'rgba(0,0,0,.045)' }
|
|
7874
|
+
}
|
|
7875
|
+
|
|
7876
|
+
function PressureChip(props) {
|
|
7877
|
+
const sessionId = props?.sessionId ?? props?.session?.id ?? props?.session?.header?.id
|
|
7878
|
+
const [open, setOpen] = useState(false)
|
|
7879
|
+
const [data, failed, reload] = usePressure(sessionId, open)
|
|
7880
|
+
const [anchor, setAnchor] = useState(null)
|
|
7881
|
+
const [palette, setPalette] = useState(pressurePalette(null))
|
|
7882
|
+
const [tab, setTab] = useState('current')
|
|
7883
|
+
const [hidden, setHidden] = useState([])
|
|
7884
|
+
const boxRef = useRef(null)
|
|
7885
|
+
const dlgRef = useRef(null)
|
|
7886
|
+
// 用原生 dialog 的 top layer:标题栏的祖先可能 overflow:hidden 或有 transform,
|
|
7887
|
+
// 弹层挂在里面会被裁掉(2026-11-17 真机只看到一个阴影框)。
|
|
7888
|
+
useEffect(() => {
|
|
7889
|
+
const dlg = dlgRef.current
|
|
7890
|
+
if (!dlg) return
|
|
7891
|
+
if (open && !dlg.open) { try { dlg.showModal() } catch { /* 老内核没有 showModal 就退回普通定位 */ } }
|
|
7892
|
+
if (!open && dlg.open) dlg.close()
|
|
7893
|
+
}, [open])
|
|
7894
|
+
// 自己的遮罩自己定:宿主可能给所有 dialog 配了深色 backdrop,会盖住弹层。
|
|
7895
|
+
useEffect(() => {
|
|
7896
|
+
if (!open) return
|
|
7897
|
+
const id = 'dsh-fish-pressure-dialog-css'
|
|
7898
|
+
if (!document.getElementById(id)) {
|
|
7899
|
+
const st = document.createElement('style')
|
|
7900
|
+
st.id = id
|
|
7901
|
+
st.textContent = '.pressure-dialog::backdrop{background:transparent}'
|
|
7902
|
+
document.head.appendChild(st)
|
|
7903
|
+
}
|
|
7904
|
+
}, [open])
|
|
7905
|
+
if (!sessionId) return null
|
|
7906
|
+
const availability = data?.availability
|
|
7907
|
+
// 房外/无会话才隐藏(用户 m02888)。还在算(pending)也要先把胶囊摆出来,
|
|
7908
|
+
// 否则切进对话时看起来「默认不显示」,得等一次点击触发重渲染才冒出来(2026-11-18 用户反馈)。
|
|
7909
|
+
if (availability === 'not-fish' || availability === 'no-session') return null
|
|
7910
|
+
const score = Number(data?.live?.score)
|
|
7911
|
+
const label = Number.isFinite(score) ? String(Math.round(score)) + '%' : (failed ? '压力 —' : '压力 …')
|
|
7912
|
+
const toggle = (ev) => {
|
|
7913
|
+
if (open) { setOpen(false); return }
|
|
7914
|
+
const rect = ev.currentTarget.getBoundingClientRect()
|
|
7915
|
+
setPalette(pressurePalette(ev.currentTarget))
|
|
7916
|
+
setAnchor({
|
|
7917
|
+
top: Math.round(rect.bottom + 6),
|
|
7918
|
+
right: Math.max(8, Math.round(window.innerWidth - rect.right)),
|
|
7919
|
+
})
|
|
7920
|
+
setOpen(true)
|
|
7921
|
+
}
|
|
7922
|
+
return h('div', { ref: boxRef, style: { position: 'relative', display: 'inline-flex' } },
|
|
7923
|
+
h('button', {
|
|
7924
|
+
type: 'button',
|
|
7925
|
+
title: S('这间对话的上下文占用;点一下看细一点'),
|
|
7926
|
+
onClick: toggle,
|
|
7927
|
+
style: {
|
|
7928
|
+
display: 'inline-flex', alignItems: 'center', gap: '5px',
|
|
7929
|
+
padding: '2px 9px', borderRadius: '999px', fontSize: '12px', lineHeight: '18px',
|
|
7930
|
+
border: '1px solid var(--dsh-border, #3a3a3a)', background: 'transparent',
|
|
7931
|
+
color: pressureTone(score), cursor: 'pointer',
|
|
7932
|
+
},
|
|
7933
|
+
},
|
|
7934
|
+
h('span', { style: { width: '6px', height: '6px', borderRadius: '999px', background: pressureTone(score) } }),
|
|
7935
|
+
label),
|
|
7936
|
+
open && anchor ? h('dialog', {
|
|
7937
|
+
ref: dlgRef,
|
|
7938
|
+
className: 'pressure-dialog',
|
|
7939
|
+
onClose: () => setOpen(false),
|
|
7940
|
+
onPointerDown: (ev) => { if (ev.target === ev.currentTarget) setOpen(false) },
|
|
7941
|
+
style: {
|
|
7942
|
+
position: 'fixed', top: anchor.top + 'px', right: anchor.right + 'px', left: 'auto', bottom: 'auto',
|
|
7943
|
+
margin: 0, padding: 0, border: 'none', background: 'transparent', color: 'inherit',
|
|
7944
|
+
maxWidth: 'none', maxHeight: 'none', width: '520px', overflow: 'visible',
|
|
7945
|
+
},
|
|
7946
|
+
}, h('div', {
|
|
7947
|
+
style: {
|
|
7948
|
+
width: '520px', maxWidth: 'calc(100vw - 32px)', maxHeight: '80vh', overflowY: 'auto',
|
|
7949
|
+
padding: '14px 16px', borderRadius: '10px', textAlign: 'left',
|
|
7950
|
+
background: palette.surface, color: palette.text,
|
|
7951
|
+
border: '1px solid ' + palette.border,
|
|
7952
|
+
boxShadow: '0 12px 32px rgba(0,0,0,.35)',
|
|
7953
|
+
// 面板内部的 .hint / 边框等继续读宿主变量,这里把它们固定成当前主题的一套值。
|
|
7954
|
+
'--dsh-surface': palette.surface,
|
|
7955
|
+
'--dsh-text': palette.text,
|
|
7956
|
+
'--dsh-text-dim': palette.dim,
|
|
7957
|
+
'--dsh-border': palette.border,
|
|
7958
|
+
'--pf-surface': palette.surface, '--pf-text': palette.text, '--pf-dim': palette.dim,
|
|
7959
|
+
'--pf-line': palette.border, '--pf-chip': palette.chip,
|
|
7960
|
+
},
|
|
7961
|
+
}, pressureReport({ data: data, failed: failed, reload: reload, tab: tab, setTab: setTab, hidden: hidden, setHidden: setHidden }))) : null)
|
|
7962
|
+
}
|
|
7963
|
+
|
|
7964
|
+
function pressureAdvice(data) {
|
|
7965
|
+
const score = Number(data?.live?.score)
|
|
7966
|
+
if (!Number.isFinite(score)) return null
|
|
7967
|
+
if (score >= 95) return S('这一段快到顶了:聊完这轮就换个房间吧。')
|
|
7968
|
+
if (score >= 85) return S('还能再聊几轮,但可以开始想换房间了。')
|
|
7969
|
+
if (score >= 70) return S('还够用,不过已经过半,别把一整个长任务都堆在这一间。')
|
|
7970
|
+
return S('还很空,这间房可以继续用。')
|
|
7971
|
+
}
|
|
7972
|
+
|
|
7973
|
+
// 第一屏的结论:只看综合分落点,说人话(用户 m03303 要「直观告诉要不要换对话」)。
|
|
7974
|
+
function pressureVerdict(score) {
|
|
7975
|
+
const n = Number(score)
|
|
7976
|
+
if (!Number.isFinite(n)) return { title: S('数据还不够'), tone: '#8a8a8a', hint: S('再聊几轮才有对照。') }
|
|
7977
|
+
if (n >= 95) return { title: S('该换房间了'), tone: '#d9534f', hint: S('这一段基本装满,换一间接着聊。') }
|
|
7978
|
+
if (n >= 85) return { title: S('准备换房'), tone: '#e08a1e', hint: S('还能再聊几轮,可以先想好下一句在哪儿说。') }
|
|
7979
|
+
if (n >= 70) return { title: S('还够用,但过半了'), tone: '#b58a00', hint: S('别把一整个长任务都堆在这一间。') }
|
|
7980
|
+
return { title: S('还很空'), tone: '#3a9d5d', hint: S('这间房可以继续用。') }
|
|
7981
|
+
}
|
|
7982
|
+
|
|
7983
|
+
function pressureBar(pct, tone) {
|
|
7984
|
+
const width = Math.max(0, Math.min(100, Number(pct) || 0))
|
|
7985
|
+
return h('div', { style: { height: '6px', borderRadius: '999px', background: 'rgba(128,128,128,.22)', overflow: 'hidden' } },
|
|
7986
|
+
h('div', { style: { width: width + '%', height: '100%', background: tone, borderRadius: '999px' } }))
|
|
7987
|
+
}
|
|
7988
|
+
|
|
7989
|
+
// 分页式完整报表(用户 m03375):当前 / 历史 / 指标 / 计算 四个页签。
|
|
7990
|
+
function pressureReport(props) {
|
|
7991
|
+
const { data, failed, reload, tab, setTab, hidden, setHidden } = props
|
|
7992
|
+
// 一套自己的排版尺度:正文 12.5、次要说明 11.5、标题 13、数字 15;不再混用 11/12/15 的随机组合。
|
|
7993
|
+
const section = (title, extra) => h('div', {
|
|
7994
|
+
style: {
|
|
7995
|
+
display: 'flex', alignItems: 'center', gap: '8px',
|
|
7996
|
+
padding: '7px 10px', borderRadius: '7px',
|
|
7997
|
+
background: 'var(--pf-chip)', marginBottom: '6px',
|
|
7998
|
+
},
|
|
7999
|
+
},
|
|
8000
|
+
h('span', { style: { fontSize: '12px', fontWeight: 500, letterSpacing: '.01em' } }, title),
|
|
8001
|
+
extra != null ? h('span', { style: { marginLeft: 'auto', fontSize: '11px', color: 'var(--pf-dim)' } }, extra) : null)
|
|
8002
|
+
const table = (headers, list) => h('div', { style: { overflowX: 'auto' } },
|
|
8003
|
+
h('table', { style: { width: '100%', borderCollapse: 'collapse' } },
|
|
8004
|
+
h('thead', null, h('tr', null, ...headers.map(name => h('th', {
|
|
8005
|
+
key: name,
|
|
8006
|
+
style: {
|
|
8007
|
+
textAlign: 'left', padding: '6px 8px', fontSize: '11.5px', fontWeight: 500,
|
|
8008
|
+
color: 'var(--pf-dim)', background: 'var(--pf-chip)',
|
|
8009
|
+
whiteSpace: 'nowrap', borderBottom: '1px solid var(--pf-line)',
|
|
8010
|
+
},
|
|
8011
|
+
}, name)))),
|
|
8012
|
+
h('tbody', null, ...list.map((row, i) => h('tr', { key: String(i) },
|
|
8013
|
+
...row.map((cell, j) => h('td', {
|
|
8014
|
+
key: String(j),
|
|
8015
|
+
style: {
|
|
8016
|
+
padding: '6px 8px', fontSize: '12.5px', borderBottom: '1px solid var(--pf-line)',
|
|
8017
|
+
whiteSpace: 'nowrap', fontVariantNumeric: 'tabular-nums',
|
|
8018
|
+
},
|
|
8019
|
+
}, cell)))))))
|
|
8020
|
+
const stat = (label, value) => h('div', {
|
|
8021
|
+
key: label,
|
|
8022
|
+
style: { padding: '8px 10px', borderRadius: '8px', background: 'var(--pf-chip)' },
|
|
8023
|
+
},
|
|
8024
|
+
h('div', { style: { fontSize: '11px', color: 'var(--pf-dim)' } }, label),
|
|
8025
|
+
h('div', { style: { fontSize: '15px', fontWeight: 600, marginTop: '2px', fontVariantNumeric: 'tabular-nums' } }, value))
|
|
8026
|
+
if (failed || data?.availability === 'unavailable') {
|
|
8027
|
+
return h('div', null,
|
|
8028
|
+
h('p', { className: 'hint' }, S('这次没读到压力数据。不是坏了,再试一次。')),
|
|
8029
|
+
h('button', { onClick: () => reload() }, S('重新读')))
|
|
8030
|
+
}
|
|
8031
|
+
if (!data) return h('div', { className: 'hint' }, S('正在算这一轮的压力……'))
|
|
8032
|
+
const score = Number(data?.live?.score)
|
|
8033
|
+
const tone = pressureTone(score)
|
|
8034
|
+
const verdict = pressureVerdict(score)
|
|
8035
|
+
const windowSize = Number(data?.live?.contextWindow)
|
|
8036
|
+
const tokens = Number(data?.live?.tokens)
|
|
8037
|
+
const ratio = windowSize > 0 && Number.isFinite(tokens) ? Math.max(0, Math.min(100, tokens / windowSize * 100)) : null
|
|
8038
|
+
const usage = data?.usage ?? {}
|
|
8039
|
+
const usageRows = usage.roundDiagnostics ?? []
|
|
8040
|
+
const last = usageRows.at(-1)
|
|
8041
|
+
const history = usage.history ?? []
|
|
8042
|
+
const tools = (data?.tools ?? []).slice(0, 8)
|
|
8043
|
+
const growth = (data?.growth ?? []).slice(0, 8)
|
|
8044
|
+
const allFactors = data?.load?.factors ?? []
|
|
8045
|
+
const ref = usage.reference ?? {}
|
|
8046
|
+
const requestsTotal = usageRows.reduce((sum, row) => sum + (Number(row.requests) || 0), 0)
|
|
8047
|
+
const toolErrorsTotal = usageRows.reduce((sum, row) => sum + (Number(row.toolErrors) || 0), 0)
|
|
8048
|
+
const completedRounds = usageRows.filter(row => Number(row.requests) > 0).length
|
|
8049
|
+
// 走势用每轮开头那一次请求的输入量 ÷ 当轮窗口:这才是「聊到这一轮时上下文占了多少」。
|
|
8050
|
+
const series = usageRows.map(row => {
|
|
8051
|
+
// 老会话不一定记着当轮窗口/首请求输入(2026-11-18 用户反馈图一直空):
|
|
8052
|
+
// 窗口退回当前 live 的 contextWindow,首请求退回该轮总输入,保证曲线能画出来。
|
|
8053
|
+
const liveWindow = Number(data?.live?.contextWindow)
|
|
8054
|
+
const win = Number(row.window) || (liveWindow > 0 ? liveWindow : NaN)
|
|
8055
|
+
const firstRaw = Number(row.first)
|
|
8056
|
+
const first = Number.isFinite(firstRaw) ? firstRaw : Number(row.input)
|
|
8057
|
+
if (!Number.isFinite(win) || win <= 0 || !Number.isFinite(first)) return null
|
|
8058
|
+
return { turn: row.turn, pct: Math.max(0, Math.min(100, first / win * 100)) }
|
|
8059
|
+
}).filter(Boolean)
|
|
8060
|
+
const chartH = 88
|
|
8061
|
+
const chartW = 260
|
|
8062
|
+
const plot = series.length > 1
|
|
8063
|
+
? h('svg', {
|
|
8064
|
+
viewBox: `0 0 ${chartW} ${chartH}`, preserveAspectRatio: 'none',
|
|
8065
|
+
style: { width: '100%', height: chartH + 'px', display: 'block', color: tone },
|
|
8066
|
+
},
|
|
8067
|
+
[70, 85, 100].map(level => h('line', {
|
|
8068
|
+
key: String(level), x1: 0, x2: chartW,
|
|
8069
|
+
y1: 78 - level / 100 * 68, y2: 78 - level / 100 * 68,
|
|
8070
|
+
stroke: 'currentColor', opacity: 0.16, strokeDasharray: '3 3',
|
|
8071
|
+
})),
|
|
8072
|
+
h('path', {
|
|
8073
|
+
fill: 'currentColor', opacity: 0.1,
|
|
8074
|
+
d: `M0,78 L${series.map((row, i) => `${(i / (series.length - 1)) * chartW},${78 - row.pct / 100 * 68}`).join(' L')} L${chartW},78 Z`,
|
|
8075
|
+
}),
|
|
8076
|
+
h('polyline', {
|
|
8077
|
+
fill: 'none', stroke: 'currentColor', strokeWidth: 1.6, strokeLinejoin: 'round', strokeLinecap: 'round',
|
|
8078
|
+
points: series.map((row, i) => `${(i / (series.length - 1)) * chartW},${78 - row.pct / 100 * 68}`).join(' '),
|
|
8079
|
+
}),
|
|
8080
|
+
h('circle', {
|
|
8081
|
+
cx: chartW, cy: 78 - series.at(-1).pct / 100 * 68, r: 2.4, fill: 'currentColor',
|
|
8082
|
+
}))
|
|
8083
|
+
: h('div', { style: { fontSize: '12px', color: 'var(--pf-dim)' } },
|
|
8084
|
+
series.length ? S('只有一轮,够画一个点,还不够成走势。') : S('还没有留下每轮的上下文记录。'))
|
|
8085
|
+
const headline = h('div', { style: { display: 'grid', gap: '10px' } },
|
|
8086
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: '10px' } },
|
|
8087
|
+
h('div', { style: { display: 'flex', alignItems: 'baseline', gap: '6px' } },
|
|
8088
|
+
h('span', { style: { fontSize: '30px', lineHeight: '32px', fontWeight: 600, color: tone } },
|
|
8089
|
+
Number.isFinite(score) ? String(Math.round(score)) : '—'),
|
|
8090
|
+
h('span', { style: { fontSize: '12px', color: 'var(--pf-dim)' } }, S('分 · 越高越重'))),
|
|
8091
|
+
h('span', {
|
|
8092
|
+
style: {
|
|
8093
|
+
marginLeft: 'auto', padding: '3px 10px', borderRadius: '999px',
|
|
8094
|
+
fontSize: '11.5px', color: verdict.tone, background: 'var(--pf-chip)',
|
|
8095
|
+
border: '1px solid ' + verdict.tone, whiteSpace: 'nowrap',
|
|
8096
|
+
},
|
|
8097
|
+
}, verdict.title),
|
|
8098
|
+
h('button', {
|
|
8099
|
+
onClick: () => reload(),
|
|
8100
|
+
style: {
|
|
8101
|
+
fontSize: '11.5px', background: 'transparent', border: '1px solid var(--pf-line)',
|
|
8102
|
+
color: 'var(--pf-dim)', borderRadius: '6px', padding: '3px 8px', cursor: 'pointer',
|
|
8103
|
+
},
|
|
8104
|
+
}, S('刷新'))),
|
|
8105
|
+
h('div', { style: { fontSize: '13px', fontWeight: 400, lineHeight: '19px' } }, verdict.hint),
|
|
8106
|
+
h('div', { style: { display: 'grid', gap: '5px' } },
|
|
8107
|
+
h('div', { style: { height: '6px', borderRadius: '999px', background: 'var(--pf-chip)', overflow: 'hidden' } },
|
|
8108
|
+
h('div', { style: { width: Math.round(ratio ?? 0) + '%', height: '100%', background: tone, borderRadius: '999px' } })),
|
|
8109
|
+
h('div', { style: { display: 'flex', justifyContent: 'space-between', fontSize: '11px', color: 'var(--pf-dim)' } },
|
|
8110
|
+
h('span', null, ratio === null ? S('上下文占用未知') : `上下文已用 ${Math.round(ratio)}%`),
|
|
8111
|
+
h('span', null, `${pressureK(tokens)} / ${pressureK(windowSize)} Token`))),
|
|
8112
|
+
h('div', { style: { display: 'grid', gridTemplateColumns: 'repeat(4, minmax(0, 1fr))', gap: '6px' } },
|
|
8113
|
+
stat(S('轮数'), String(completedRounds || usageRows.length)),
|
|
8114
|
+
stat(S('样本'), ref.count ? String(ref.count) : S('不足')),
|
|
8115
|
+
stat(S('请求'), String(requestsTotal)),
|
|
8116
|
+
stat(S('报错'), String(toolErrorsTotal))))
|
|
8117
|
+
// 第一屏给「历史同轮中位数」(2026-11-18 用户 m03803):直接回答「这一轮比过去同轮重还是轻」。
|
|
8118
|
+
const medianLine = (() => {
|
|
8119
|
+
const mp = data?.medianPoint
|
|
8120
|
+
if (!mp) return h('div', { style: { fontSize: '12px', color: 'var(--pf-dim)' } },
|
|
8121
|
+
S('历史同轮中位数还没有样本:这版开始每轮记录,攒几轮就能对照。'))
|
|
8122
|
+
const nowPct = ratio === null ? null : Math.round(ratio)
|
|
8123
|
+
const diff = nowPct === null ? null : nowPct - Math.round(mp.pct)
|
|
8124
|
+
const kind = mp.n >= 10 ? S('中位数') : S('参考')
|
|
8125
|
+
const tail = nowPct === null ? ''
|
|
8126
|
+
: diff === 0 ? S(',和它差不多')
|
|
8127
|
+
: diff > 0 ? `,比它高 ${diff} 个百分点`
|
|
8128
|
+
: `,比它低 ${-diff} 个百分点`
|
|
8129
|
+
return h('div', { style: { fontSize: '12px', color: 'var(--pf-text)', lineHeight: '19px' } },
|
|
8130
|
+
`第 ${mp.turn} 轮历史${kind} ${mp.pct}%(样本 ${mp.n} 次)· 你现在 ${nowPct === null ? '—' : nowPct + '%'}${tail}`)
|
|
8131
|
+
})()
|
|
8132
|
+
// 被中断的轮不记用量,但明说一句,别让人以为漏数了(2026-11-18 用户 m03880)。
|
|
8133
|
+
const interrupted = Number(data?.interruptedRounds) || 0
|
|
8134
|
+
const interruptedLine = interrupted
|
|
8135
|
+
? h('div', { style: { fontSize: '12px', color: 'var(--pf-dim)' } },
|
|
8136
|
+
`其中 ${interrupted} 轮被中断,没有记录。`)
|
|
8137
|
+
: null
|
|
8138
|
+
const currentView = h('div', { style: { display: 'grid', gap: '14px' } },
|
|
8139
|
+
medianLine,
|
|
8140
|
+
interruptedLine,
|
|
8141
|
+
h('div', null,
|
|
8142
|
+
section(S('上下文占用走势'), S('虚线 70 / 85 / 100')),
|
|
8143
|
+
plot,
|
|
8144
|
+
h('div', { style: { display: 'flex', justifyContent: 'space-between', fontSize: '11px', color: 'var(--pf-dim)', marginTop: '2px' } },
|
|
8145
|
+
h('span', null, series.length ? `第 ${series[0].turn} 轮` : ''),
|
|
8146
|
+
h('span', null, series.length ? `第 ${series.at(-1).turn} 轮` : ''))),
|
|
8147
|
+
growth.length ? h('div', null,
|
|
8148
|
+
section(S('增长最大的轮次')),
|
|
8149
|
+
table([S('轮次'), S('净增长'), S('轮末 Token'), S('请求')],
|
|
8150
|
+
growth.map(row => [`第 ${row.turn} 轮`, row.delta != null ? '+' + pressureK(row.delta) : '—', pressureK(row.tokens), String(row.requests ?? '—')]))) : null,
|
|
8151
|
+
tools.length ? h('div', null,
|
|
8152
|
+
section(S('工具结果长期残留')),
|
|
8153
|
+
table([S('工具'), S('累计 Token'), S('调用')],
|
|
8154
|
+
tools.map(row => [row.name, pressureK(row.tokens), String(row.calls ?? '—')]))) : null,
|
|
8155
|
+
usageRows.length ? h('div', null,
|
|
8156
|
+
section(S('逐轮明细'), S('最近 12 轮')),
|
|
8157
|
+
table([S('轮次'), S('输入'), S('输出'), S('请求'), S('重试')],
|
|
8158
|
+
usageRows.slice(-12).reverse().map(row => [`第 ${row.turn} 轮`, pressureK(row.input), pressureK(row.output), String(row.requests ?? '—'), String(row.attempts ?? '—')]))) : null)
|
|
8159
|
+
const historyView = h('div', { style: { display: 'grid', gap: '12px' } },
|
|
8160
|
+
h('div', { style: { display: 'grid', gridTemplateColumns: 'repeat(3, minmax(0, 1fr))', gap: '6px' } },
|
|
8161
|
+
stat(S('参考样本'), ref.count ? String(ref.count) : S('不足')),
|
|
8162
|
+
stat('P90', ref.p90 != null ? pressureK(ref.p90) : '—'),
|
|
8163
|
+
stat(S('历史会话'), String(history.length))),
|
|
8164
|
+
ref.count && ref.count >= 10 ? null
|
|
8165
|
+
: h('div', { className: 'hint' }, S('历史样本要凑够 10 个完整用量的轮次才给对照;现在还不够,所以只报这间房自己的数。')),
|
|
8166
|
+
history.length ? table([S('会话'), S('状态'), S('轮数')],
|
|
8167
|
+
history.slice(0, 10).map(row => [row.title || S('未命名会话'), row.status ?? '—', String(row.count ?? row.turns ?? '—')]))
|
|
8168
|
+
: h('div', { className: 'hint' }, S('还没有可以对照的历史会话。')),
|
|
8169
|
+
h('div', { className: 'hint' }, S('只统计这间房的会话;别的房间与子代理不参与。')))
|
|
8170
|
+
const factorsView = h('div', { style: { display: 'grid', gap: '10px' } },
|
|
8171
|
+
h('div', { className: 'hint' }, S('勾选只影响这张表显示哪几项;分数仍按七项固定权重算。')),
|
|
8172
|
+
...allFactors.map(factor => {
|
|
8173
|
+
const on = !hidden.includes(factor.id)
|
|
8174
|
+
const cur = Number(factor.current)
|
|
8175
|
+
const base = Number(factor.baseline)
|
|
8176
|
+
const span = Math.max(1, Number.isFinite(cur) ? cur : 0, Number.isFinite(base) ? base : 0)
|
|
8177
|
+
return h('div', { key: factor.id, style: { display: 'grid', gap: '5px', opacity: factor.available ? 1 : 0.55 } },
|
|
8178
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: '8px', fontSize: '12.5px' } },
|
|
8179
|
+
h('input', {
|
|
8180
|
+
type: 'checkbox', checked: on,
|
|
8181
|
+
onChange: () => setHidden(prev => on ? [...prev, factor.id] : prev.filter(id => id !== factor.id)),
|
|
8182
|
+
}),
|
|
8183
|
+
h('span', { style: { fontWeight: 500 } }, `${factor.label ?? factor.id} · ${factor.weight}%`),
|
|
8184
|
+
h('span', { style: { marginLeft: 'auto', fontSize: '11.5px', color: 'var(--pf-dim)' } },
|
|
8185
|
+
`${Number.isFinite(cur) ? Math.round(cur) : '—'} / ${Number.isFinite(base) ? Math.round(base) : '—'}${factor.provisional ? S(' · 样本少') : ''}`)),
|
|
8186
|
+
on ? h('div', { style: { position: 'relative', height: '5px', borderRadius: '999px', background: 'var(--pf-chip)' } },
|
|
8187
|
+
h('div', { style: { width: Math.min(100, (Number.isFinite(cur) ? cur : 0) / span * 100) + '%', height: '100%', borderRadius: '999px', background: tone, opacity: 0.85 } }),
|
|
8188
|
+
Number.isFinite(base) ? h('div', {
|
|
8189
|
+
style: {
|
|
8190
|
+
position: 'absolute', top: '-2px', bottom: '-2px',
|
|
8191
|
+
left: Math.min(100, base / span * 100) + '%', width: '1px',
|
|
8192
|
+
background: 'currentColor', opacity: 0.5,
|
|
8193
|
+
},
|
|
8194
|
+
}) : null) : null)
|
|
8195
|
+
}))
|
|
8196
|
+
const calcView = h('div', { style: { display: 'grid', gap: '9px', fontSize: '12.5px', lineHeight: '1.7', color: 'var(--pf-dim)' } },
|
|
8197
|
+
h('p', null, S('七个维度各自累计,按权重加总,再拿「同轮数的历史中位数」当 100 做换算。100 表示和历史典型情况差不多,越高说明这间房越重。')),
|
|
8198
|
+
h('p', null, S('历史样本不到 10 个时,对照只当参考;样本不到 3 个时干脆不报。')),
|
|
8199
|
+
h('p', null, S('走势和轮数来自每轮模型实报的 Token;压缩次数只统计宿主事件流里能看到的,如果还装了别的压缩插件,它们的数据不对外暴露。')),
|
|
8200
|
+
h('p', null, S('只读统计:不改对话,也不写事件流。')))
|
|
8201
|
+
const tabs = [['current', S('当前')], ['history', S('历史')], ['factors', S('指标')], ['calc', S('计算')]]
|
|
8202
|
+
return h('div', { style: { display: 'grid', gap: '14px' } },
|
|
8203
|
+
headline,
|
|
8204
|
+
h('div', { style: { display: 'flex', gap: '18px', borderBottom: '1px solid var(--pf-line)' } },
|
|
8205
|
+
...tabs.map(([id, label]) => h('button', {
|
|
8206
|
+
key: id, type: 'button', onClick: () => setTab(id),
|
|
8207
|
+
style: {
|
|
8208
|
+
padding: '6px 0 7px', fontSize: '12.5px', background: 'transparent', cursor: 'pointer',
|
|
8209
|
+
color: 'inherit', border: 'none',
|
|
8210
|
+
borderBottom: tab === id ? '2px solid ' + tone : '2px solid transparent',
|
|
8211
|
+
color: tab === id ? tone : 'var(--pf-dim)',
|
|
8212
|
+
fontWeight: tab === id ? 500 : 400,
|
|
8213
|
+
},
|
|
8214
|
+
}, label))),
|
|
8215
|
+
tab === 'current' ? currentView : tab === 'history' ? historyView : tab === 'factors' ? factorsView : calcView)
|
|
8216
|
+
}
|
|
6160
8217
|
// ---------------------------------------------------------------- 挂载
|
|
6161
8218
|
const inject = ['slots']
|
|
6162
8219
|
const NAMES = { nav: '大肥鱼' }
|
|
@@ -6173,6 +8230,21 @@ window.__ModuleLoader__.load({
|
|
|
6173
8230
|
),
|
|
6174
8231
|
'dsh-fish: settings section',
|
|
6175
8232
|
)
|
|
8233
|
+
// 对话页的常驻入口(2026-11-17,用户 m02719):会话头部小胶囊 + 压力页签。
|
|
8234
|
+
// 两边共用同一份 /session-pressure?session=… 数据;非她这间房的会话服务端返回 not-fish,组件直接不渲染。
|
|
8235
|
+
ctx.effect(
|
|
8236
|
+
() =>
|
|
8237
|
+
ctx.slots.inject('conversation.session.header.actions', () =>
|
|
8238
|
+
ctx.slots.register(
|
|
8239
|
+
{ name: 'conversation.session.header.actions', id: 'pressure-chip', order: 20 },
|
|
8240
|
+
PressureChip,
|
|
8241
|
+
),
|
|
8242
|
+
'dsh-fish: pressure chip',
|
|
8243
|
+
),
|
|
8244
|
+
'dsh-fish: pressure chip',
|
|
8245
|
+
)
|
|
8246
|
+
// 没有页签:页签会被宿主给每个会话都列出来,没法按会话隐藏(用户 m02888)。
|
|
8247
|
+
// 压力入口只留小胶囊,点开的弹层里是完整内容;非她这间房时胶囊本身不渲染。
|
|
6176
8248
|
}
|
|
6177
8249
|
|
|
6178
8250
|
exports.apply = apply
|