opencode-tokenwatch 0.3.0 → 0.3.1
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/LICENSE +21 -21
- package/README.en.md +104 -97
- package/README.md +104 -97
- package/dist/commands.js +208 -0
- package/dist/commands.jsx +11 -2
- package/dist/generate-usage-html.js +719 -707
- package/dist/i18n.js +2 -0
- package/dist/perf-tracker.d.ts +1 -0
- package/dist/perf-tracker.js +37 -0
- package/dist/queries.js +101 -101
- package/dist/sidebar.d.ts +2 -2
- package/dist/sidebar.jsx +333 -137
- package/dist/stats-store.d.ts +23 -0
- package/dist/stats-store.js +258 -0
- package/dist/tui.jsx +80 -26
- package/package.json +63 -63
|
@@ -33,42 +33,46 @@ function renderKpiCards(data) {
|
|
|
33
33
|
const s = data.summary;
|
|
34
34
|
const hitRate = cacheHitRate(s.inputTokens, s.cacheRead);
|
|
35
35
|
const hitRatePct = fmtPercent(hitRate);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
let tpsSum = 0, tpsReqs = 0;
|
|
37
|
+
for (const p of data.perfSummary) {
|
|
38
|
+
if (p.avgTPS != null && p.avgTPS > 0) {
|
|
39
|
+
tpsSum += p.avgTPS * p.requestCount;
|
|
40
|
+
tpsReqs += p.requestCount;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const avgTpsRaw = tpsReqs > 0 ? tpsSum / tpsReqs : 0;
|
|
44
|
+
const avgTps = tpsReqs > 0 ? avgTpsRaw.toFixed(1) : '—';
|
|
41
45
|
const isHighCache = hitRate >= 0.5;
|
|
42
46
|
const errors = data.errors;
|
|
43
47
|
const errorRatePct = errors ? (errors.errorRate * 100).toFixed(1) + '%' : '—';
|
|
44
48
|
const errorColor = errors && errors.errorRate >= 0.05 ? 'var(--output)'
|
|
45
49
|
: errors && errors.errorRate > 0 ? 'var(--tps)' : 'var(--cache)';
|
|
46
|
-
return `
|
|
47
|
-
<div class="kpi-row">
|
|
48
|
-
<div class="kpi-card">
|
|
49
|
-
<div class="kpi-label">Total Tokens</div>
|
|
50
|
-
<div class="kpi-value">${fmtTokens(s.totalTokens)}</div>
|
|
51
|
-
</div>
|
|
52
|
-
<div class="kpi-card${isHighCache ? ' kpi-glow' : ''}">
|
|
53
|
-
<div class="kpi-label">Cache Hit Rate</div>
|
|
54
|
-
<div class="kpi-value" style="color:var(--cache)">${hitRatePct}</div>
|
|
55
|
-
</div>
|
|
56
|
-
<div class="kpi-card">
|
|
57
|
-
<div class="kpi-label">Avg TPS</div>
|
|
58
|
-
<div class="kpi-value" style="color:var(--tps)">${avgTps}</div>
|
|
59
|
-
</div>
|
|
60
|
-
<div class="kpi-card">
|
|
61
|
-
<div class="kpi-label">Requests</div>
|
|
62
|
-
<div class="kpi-value">${s.requestCount}</div>
|
|
63
|
-
</div>
|
|
64
|
-
<div class="kpi-card">
|
|
65
|
-
<div class="kpi-label">Total Cost</div>
|
|
66
|
-
<div class="kpi-value" style="color:var(--tps)">${fmtCost(s.totalCost)}</div>
|
|
67
|
-
</div>
|
|
68
|
-
<div class="kpi-card">
|
|
69
|
-
<div class="kpi-label">Error Rate</div>
|
|
70
|
-
<div class="kpi-value" style="color:${errorColor}">${errorRatePct}</div>
|
|
71
|
-
</div>
|
|
50
|
+
return `
|
|
51
|
+
<div class="kpi-row">
|
|
52
|
+
<div class="kpi-card">
|
|
53
|
+
<div class="kpi-label">Total Tokens</div>
|
|
54
|
+
<div class="kpi-value">${fmtTokens(s.totalTokens)}</div>
|
|
55
|
+
</div>
|
|
56
|
+
<div class="kpi-card${isHighCache ? ' kpi-glow' : ''}">
|
|
57
|
+
<div class="kpi-label">Cache Hit Rate</div>
|
|
58
|
+
<div class="kpi-value" style="color:var(--cache)">${hitRatePct}</div>
|
|
59
|
+
</div>
|
|
60
|
+
<div class="kpi-card">
|
|
61
|
+
<div class="kpi-label">Avg TPS</div>
|
|
62
|
+
<div class="kpi-value" style="color:var(--tps)">${avgTps}</div>
|
|
63
|
+
</div>
|
|
64
|
+
<div class="kpi-card">
|
|
65
|
+
<div class="kpi-label">Requests</div>
|
|
66
|
+
<div class="kpi-value">${s.requestCount}</div>
|
|
67
|
+
</div>
|
|
68
|
+
<div class="kpi-card">
|
|
69
|
+
<div class="kpi-label">Total Cost</div>
|
|
70
|
+
<div class="kpi-value" style="color:var(--tps)">${fmtCost(s.totalCost)}</div>
|
|
71
|
+
</div>
|
|
72
|
+
<div class="kpi-card">
|
|
73
|
+
<div class="kpi-label">Error Rate</div>
|
|
74
|
+
<div class="kpi-value" style="color:${errorColor}">${errorRatePct}</div>
|
|
75
|
+
</div>
|
|
72
76
|
</div>`;
|
|
73
77
|
}
|
|
74
78
|
function renderModelChartInit(data) {
|
|
@@ -81,139 +85,139 @@ function renderModelChartInit(data) {
|
|
|
81
85
|
const perf = data.perfSummary.find(p => p.model === `${m.provider}/${m.model}`);
|
|
82
86
|
return perf?.avgTPS ?? null;
|
|
83
87
|
});
|
|
84
|
-
return `var modelNames = ${JSON.stringify(names)};
|
|
85
|
-
var modelInput = ${JSON.stringify(inputData)};
|
|
86
|
-
var modelOutput = ${JSON.stringify(outputData)};
|
|
87
|
-
var modelCache = ${JSON.stringify(cacheData)};
|
|
88
|
-
var modelTps = ${JSON.stringify(tpsData)};
|
|
89
|
-
|
|
90
|
-
function initModelChart() {
|
|
91
|
-
var el = document.getElementById('model-chart');
|
|
92
|
-
if (!el) return;
|
|
93
|
-
var chart = echarts.init(el);
|
|
94
|
-
window.modelChart = chart;
|
|
95
|
-
renderModelChart(chart);
|
|
96
|
-
return chart;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function renderModelChart(chart) {
|
|
100
|
-
var totals = modelInput.map(function(v, i) { return v + modelOutput[i] + modelCache[i]; });
|
|
101
|
-
var option = {
|
|
102
|
-
tooltip: {
|
|
103
|
-
trigger: 'axis',
|
|
104
|
-
axisPointer: { type: 'shadow' },
|
|
105
|
-
formatter: function(params) {
|
|
106
|
-
var html = '<b>' + params[0].axisValue + '</b><br/>';
|
|
107
|
-
var total = 0;
|
|
108
|
-
params.forEach(function(p) {
|
|
109
|
-
if (p.seriesName !== 'TPS') {
|
|
110
|
-
html += p.marker + ' ' + p.seriesName + ': ' + fmt(p.value) + '<br/>';
|
|
111
|
-
total += p.value;
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
html += 'Total: ' + fmt(total) + '<br/>';
|
|
115
|
-
var tpsParam = params.find(function(p) { return p.seriesName === 'TPS'; });
|
|
116
|
-
if (tpsParam && tpsParam.value != null) {
|
|
117
|
-
html += tpsParam.marker + ' TPS: ' + tpsParam.value.toFixed(1) + '<br/>';
|
|
118
|
-
}
|
|
119
|
-
return html;
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
legend: {
|
|
123
|
-
data: ['Input', 'Output', 'Cache', 'TPS'],
|
|
124
|
-
textStyle: { color: '#B0B0C0' },
|
|
125
|
-
top: 5
|
|
126
|
-
},
|
|
127
|
-
grid: { left: 60, right: 60, bottom: 100, top: 50 },
|
|
128
|
-
xAxis: {
|
|
129
|
-
type: 'category',
|
|
130
|
-
data: modelNames,
|
|
131
|
-
axisLabel: { color: '#B0B0C0', rotate: 45, interval: 0, fontSize: 10 },
|
|
132
|
-
axisLine: { lineStyle: { color: '#2A2A35' } }
|
|
133
|
-
},
|
|
134
|
-
yAxis: [
|
|
135
|
-
{
|
|
136
|
-
type: 'value',
|
|
137
|
-
name: 'Tokens',
|
|
138
|
-
nameTextStyle: { color: '#B0B0C0' },
|
|
139
|
-
axisLabel: {
|
|
140
|
-
color: '#B0B0C0',
|
|
141
|
-
formatter: fmt
|
|
142
|
-
},
|
|
143
|
-
splitLine: { lineStyle: { color: '#2A2A35', type: 'dashed' } }
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
type: 'value',
|
|
147
|
-
name: 'TPS',
|
|
148
|
-
nameTextStyle: { color: '#FFB800' },
|
|
149
|
-
axisLabel: { color: '#FFB800', formatter: function(v) { return v.toFixed(1); } },
|
|
150
|
-
splitLine: { show: false }
|
|
151
|
-
}
|
|
152
|
-
],
|
|
153
|
-
series: [
|
|
154
|
-
{
|
|
155
|
-
name: 'Input',
|
|
156
|
-
type: 'bar',
|
|
157
|
-
stack: 'tokens',
|
|
158
|
-
data: modelInput,
|
|
159
|
-
itemStyle: { color: '#00D1FF' },
|
|
160
|
-
barMaxWidth: 40
|
|
161
|
-
},
|
|
162
|
-
{
|
|
163
|
-
name: 'Cache',
|
|
164
|
-
type: 'bar',
|
|
165
|
-
stack: 'tokens',
|
|
166
|
-
data: modelCache,
|
|
167
|
-
itemStyle: { color: '#00F593' },
|
|
168
|
-
barMaxWidth: 40,
|
|
169
|
-
label: {
|
|
170
|
-
show: true,
|
|
171
|
-
position: 'inside',
|
|
172
|
-
formatter: function(p) {
|
|
173
|
-
var cache = modelCache[p.dataIndex];
|
|
174
|
-
var input = modelInput[p.dataIndex];
|
|
175
|
-
if (cache === 0) return '';
|
|
176
|
-
return (cache / (input + cache) * 100).toFixed(0) + '%';
|
|
177
|
-
},
|
|
178
|
-
color: '#fff', fontSize: 10, fontWeight: 'bold'
|
|
179
|
-
}
|
|
180
|
-
},
|
|
181
|
-
{
|
|
182
|
-
name: 'Output',
|
|
183
|
-
type: 'bar',
|
|
184
|
-
stack: 'tokens',
|
|
185
|
-
data: modelOutput,
|
|
186
|
-
itemStyle: { color: '#B545FF' },
|
|
187
|
-
barMaxWidth: 40,
|
|
188
|
-
label: {
|
|
189
|
-
show: true,
|
|
190
|
-
position: 'top',
|
|
191
|
-
formatter: function(p) {
|
|
192
|
-
var total = modelInput[p.dataIndex] + modelOutput[p.dataIndex] + modelCache[p.dataIndex];
|
|
193
|
-
return total > 0 ? fmt(total) : '';
|
|
194
|
-
},
|
|
195
|
-
color: '#fff', fontSize: 10, fontWeight: 'bold'
|
|
196
|
-
}
|
|
197
|
-
},
|
|
198
|
-
{
|
|
199
|
-
name: 'TPS',
|
|
200
|
-
type: 'scatter',
|
|
201
|
-
yAxisIndex: 1,
|
|
202
|
-
data: modelTps,
|
|
203
|
-
symbol: 'diamond',
|
|
204
|
-
symbolSize: function(val) { return val != null && val > 0 ? 13 : 0; },
|
|
205
|
-
itemStyle: { color: '#FFB800' },
|
|
206
|
-
label: {
|
|
207
|
-
show: true,
|
|
208
|
-
position: 'right',
|
|
209
|
-
formatter: function(p) { return p.value != null && p.value > 0 ? p.value.toFixed(1) : ''; },
|
|
210
|
-
color: '#FFB800', fontSize: 10
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
]
|
|
214
|
-
};
|
|
215
|
-
chart.setOption(option);
|
|
216
|
-
chart.resize();
|
|
88
|
+
return `var modelNames = ${JSON.stringify(names)};
|
|
89
|
+
var modelInput = ${JSON.stringify(inputData)};
|
|
90
|
+
var modelOutput = ${JSON.stringify(outputData)};
|
|
91
|
+
var modelCache = ${JSON.stringify(cacheData)};
|
|
92
|
+
var modelTps = ${JSON.stringify(tpsData)};
|
|
93
|
+
|
|
94
|
+
function initModelChart() {
|
|
95
|
+
var el = document.getElementById('model-chart');
|
|
96
|
+
if (!el) return;
|
|
97
|
+
var chart = echarts.init(el);
|
|
98
|
+
window.modelChart = chart;
|
|
99
|
+
renderModelChart(chart);
|
|
100
|
+
return chart;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function renderModelChart(chart) {
|
|
104
|
+
var totals = modelInput.map(function(v, i) { return v + modelOutput[i] + modelCache[i]; });
|
|
105
|
+
var option = {
|
|
106
|
+
tooltip: {
|
|
107
|
+
trigger: 'axis',
|
|
108
|
+
axisPointer: { type: 'shadow' },
|
|
109
|
+
formatter: function(params) {
|
|
110
|
+
var html = '<b>' + params[0].axisValue + '</b><br/>';
|
|
111
|
+
var total = 0;
|
|
112
|
+
params.forEach(function(p) {
|
|
113
|
+
if (p.seriesName !== 'TPS') {
|
|
114
|
+
html += p.marker + ' ' + p.seriesName + ': ' + fmt(p.value) + '<br/>';
|
|
115
|
+
total += p.value;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
html += 'Total: ' + fmt(total) + '<br/>';
|
|
119
|
+
var tpsParam = params.find(function(p) { return p.seriesName === 'TPS'; });
|
|
120
|
+
if (tpsParam && tpsParam.value != null) {
|
|
121
|
+
html += tpsParam.marker + ' TPS: ' + tpsParam.value.toFixed(1) + '<br/>';
|
|
122
|
+
}
|
|
123
|
+
return html;
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
legend: {
|
|
127
|
+
data: ['Input', 'Output', 'Cache', 'TPS'],
|
|
128
|
+
textStyle: { color: '#B0B0C0' },
|
|
129
|
+
top: 5
|
|
130
|
+
},
|
|
131
|
+
grid: { left: 60, right: 60, bottom: 100, top: 50 },
|
|
132
|
+
xAxis: {
|
|
133
|
+
type: 'category',
|
|
134
|
+
data: modelNames,
|
|
135
|
+
axisLabel: { color: '#B0B0C0', rotate: 45, interval: 0, fontSize: 10 },
|
|
136
|
+
axisLine: { lineStyle: { color: '#2A2A35' } }
|
|
137
|
+
},
|
|
138
|
+
yAxis: [
|
|
139
|
+
{
|
|
140
|
+
type: 'value',
|
|
141
|
+
name: 'Tokens',
|
|
142
|
+
nameTextStyle: { color: '#B0B0C0' },
|
|
143
|
+
axisLabel: {
|
|
144
|
+
color: '#B0B0C0',
|
|
145
|
+
formatter: fmt
|
|
146
|
+
},
|
|
147
|
+
splitLine: { lineStyle: { color: '#2A2A35', type: 'dashed' } }
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
type: 'value',
|
|
151
|
+
name: 'TPS',
|
|
152
|
+
nameTextStyle: { color: '#FFB800' },
|
|
153
|
+
axisLabel: { color: '#FFB800', formatter: function(v) { return v.toFixed(1); } },
|
|
154
|
+
splitLine: { show: false }
|
|
155
|
+
}
|
|
156
|
+
],
|
|
157
|
+
series: [
|
|
158
|
+
{
|
|
159
|
+
name: 'Input',
|
|
160
|
+
type: 'bar',
|
|
161
|
+
stack: 'tokens',
|
|
162
|
+
data: modelInput,
|
|
163
|
+
itemStyle: { color: '#00D1FF' },
|
|
164
|
+
barMaxWidth: 40
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
name: 'Cache',
|
|
168
|
+
type: 'bar',
|
|
169
|
+
stack: 'tokens',
|
|
170
|
+
data: modelCache,
|
|
171
|
+
itemStyle: { color: '#00F593' },
|
|
172
|
+
barMaxWidth: 40,
|
|
173
|
+
label: {
|
|
174
|
+
show: true,
|
|
175
|
+
position: 'inside',
|
|
176
|
+
formatter: function(p) {
|
|
177
|
+
var cache = modelCache[p.dataIndex];
|
|
178
|
+
var input = modelInput[p.dataIndex];
|
|
179
|
+
if (cache === 0) return '';
|
|
180
|
+
return (cache / (input + cache) * 100).toFixed(0) + '%';
|
|
181
|
+
},
|
|
182
|
+
color: '#fff', fontSize: 10, fontWeight: 'bold'
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
name: 'Output',
|
|
187
|
+
type: 'bar',
|
|
188
|
+
stack: 'tokens',
|
|
189
|
+
data: modelOutput,
|
|
190
|
+
itemStyle: { color: '#B545FF' },
|
|
191
|
+
barMaxWidth: 40,
|
|
192
|
+
label: {
|
|
193
|
+
show: true,
|
|
194
|
+
position: 'top',
|
|
195
|
+
formatter: function(p) {
|
|
196
|
+
var total = modelInput[p.dataIndex] + modelOutput[p.dataIndex] + modelCache[p.dataIndex];
|
|
197
|
+
return total > 0 ? fmt(total) : '';
|
|
198
|
+
},
|
|
199
|
+
color: '#fff', fontSize: 10, fontWeight: 'bold'
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
name: 'TPS',
|
|
204
|
+
type: 'scatter',
|
|
205
|
+
yAxisIndex: 1,
|
|
206
|
+
data: modelTps,
|
|
207
|
+
symbol: 'diamond',
|
|
208
|
+
symbolSize: function(val) { return val != null && val > 0 ? 13 : 0; },
|
|
209
|
+
itemStyle: { color: '#FFB800' },
|
|
210
|
+
label: {
|
|
211
|
+
show: true,
|
|
212
|
+
position: 'right',
|
|
213
|
+
formatter: function(p) { return p.value != null && p.value > 0 ? p.value.toFixed(1) : ''; },
|
|
214
|
+
color: '#FFB800', fontSize: 10
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
]
|
|
218
|
+
};
|
|
219
|
+
chart.setOption(option);
|
|
220
|
+
chart.resize();
|
|
217
221
|
}`;
|
|
218
222
|
}
|
|
219
223
|
function renderScatterChartInit(data) {
|
|
@@ -238,92 +242,92 @@ function renderScatterChartInit(data) {
|
|
|
238
242
|
});
|
|
239
243
|
const hitRates = sorted.map(p => p.cacheHitRate ?? 0);
|
|
240
244
|
const reqCounts = sorted.map(p => p.requestCount);
|
|
241
|
-
return `
|
|
242
|
-
var effNames = ${JSON.stringify(names)};
|
|
243
|
-
var effTps = ${JSON.stringify(tpsValues)};
|
|
244
|
-
var effTtft = ${JSON.stringify(ttftValues)};
|
|
245
|
-
var effCost = ${JSON.stringify(costValues)};
|
|
246
|
-
var effHit = ${JSON.stringify(hitRates)};
|
|
247
|
-
var effReq = ${JSON.stringify(reqCounts)};
|
|
248
|
-
|
|
249
|
-
function initScatterChart() {
|
|
250
|
-
var el = document.getElementById('scatter-chart');
|
|
251
|
-
if (!el) return;
|
|
252
|
-
var chart = echarts.init(el);
|
|
253
|
-
window.scatterChart = chart;
|
|
254
|
-
|
|
255
|
-
// TPS 越高越绿,越低越紫,无数据为灰
|
|
256
|
-
var maxTps = Math.max.apply(null, effTps.filter(function(v){ return v > 0; })) || 1;
|
|
257
|
-
var barColors = effTps.map(function(v) {
|
|
258
|
-
if (v <= 0) return '#444455';
|
|
259
|
-
var r = v / maxTps;
|
|
260
|
-
if (r >= 0.8) return '#00F593';
|
|
261
|
-
if (r >= 0.5) return '#FFB800';
|
|
262
|
-
return '#B545FF';
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
var option = {
|
|
266
|
-
tooltip: {
|
|
267
|
-
trigger: 'axis',
|
|
268
|
-
axisPointer: { type: 'none' },
|
|
269
|
-
formatter: function(params) {
|
|
270
|
-
var i = params[0].dataIndex;
|
|
271
|
-
var tps = effTps[i] > 0 ? effTps[i].toFixed(1) + ' tok/s' : '\u2014';
|
|
272
|
-
var ttft = effTtft[i] > 0 ? effTtft[i].toFixed(0) + ' ms' : '\u2014';
|
|
273
|
-
var cost = effCost[i] > 0 ? '$' + effCost[i].toFixed(4) + '/1K' : '\u2014';
|
|
274
|
-
var hit = effHit[i] > 0 ? effHit[i].toFixed(1) + '%' : '\u2014';
|
|
275
|
-
return '<b>' + effNames[i] + '</b><br/>' +
|
|
276
|
-
'\u25B6 TPS: ' + tps + '<br/>' +
|
|
277
|
-
'\u23F1 TTFT: ' + ttft + '<br/>' +
|
|
278
|
-
'\uD83D\uDCB0 Cost/1K: ' + cost + '<br/>' +
|
|
279
|
-
'\uD83D\uDCBE Cache Hit: ' + hit + '<br/>' +
|
|
280
|
-
'Requests: ' + effReq[i];
|
|
281
|
-
}
|
|
282
|
-
},
|
|
283
|
-
grid: { left: 20, right:
|
|
284
|
-
xAxis: {
|
|
285
|
-
type: 'value',
|
|
286
|
-
name: 'Avg TPS (tokens / sec)',
|
|
287
|
-
nameTextStyle: { color: '#B0B0C0', fontSize: 11 },
|
|
288
|
-
axisLabel: { color: '#B0B0C0', formatter: function(v) { return v > 0 ? v.toFixed(0) : '0'; } },
|
|
289
|
-
splitLine: { lineStyle: { color: '#2A2A35', type: 'dashed' } }
|
|
290
|
-
},
|
|
291
|
-
yAxis: {
|
|
292
|
-
type: 'category',
|
|
293
|
-
data: effNames,
|
|
294
|
-
inverse: true,
|
|
295
|
-
axisLabel: {
|
|
296
|
-
color: '#E0E0F0',
|
|
297
|
-
fontSize: 11,
|
|
298
|
-
formatter: function(v) { return v.length >
|
|
299
|
-
},
|
|
300
|
-
axisLine: { show: false },
|
|
301
|
-
axisTick: { show: false }
|
|
302
|
-
},
|
|
303
|
-
series: [{
|
|
304
|
-
type: 'bar',
|
|
305
|
-
data: effTps.map(function(v, i) {
|
|
306
|
-
return { value: v > 0 ? v : 0.001, itemStyle: { color: barColors[i], borderRadius: [0, 4, 4, 0] } };
|
|
307
|
-
}),
|
|
308
|
-
barMaxWidth: 22,
|
|
309
|
-
label: {
|
|
310
|
-
show: true,
|
|
311
|
-
position: 'right',
|
|
312
|
-
color: '#E0E0F0',
|
|
313
|
-
fontSize: 10,
|
|
314
|
-
formatter: function(p) {
|
|
315
|
-
var i = p.dataIndex;
|
|
316
|
-
var parts = [effTps[i] > 0 ? effTps[i].toFixed(1) + ' t/s' : '\u2014'];
|
|
317
|
-
if (effTtft[i] > 0) parts.push('TTFT ' + effTtft[i].toFixed(0) + 'ms');
|
|
318
|
-
if (effCost[i] > 0) parts.push('\u0024' + effCost[i].toFixed(4) + '/1K');
|
|
319
|
-
return parts.join(' ');
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
}]
|
|
323
|
-
};
|
|
324
|
-
chart.setOption(option);
|
|
325
|
-
chart.resize();
|
|
326
|
-
}
|
|
245
|
+
return `
|
|
246
|
+
var effNames = ${JSON.stringify(names)};
|
|
247
|
+
var effTps = ${JSON.stringify(tpsValues)};
|
|
248
|
+
var effTtft = ${JSON.stringify(ttftValues)};
|
|
249
|
+
var effCost = ${JSON.stringify(costValues)};
|
|
250
|
+
var effHit = ${JSON.stringify(hitRates)};
|
|
251
|
+
var effReq = ${JSON.stringify(reqCounts)};
|
|
252
|
+
|
|
253
|
+
function initScatterChart() {
|
|
254
|
+
var el = document.getElementById('scatter-chart');
|
|
255
|
+
if (!el) return;
|
|
256
|
+
var chart = echarts.init(el);
|
|
257
|
+
window.scatterChart = chart;
|
|
258
|
+
|
|
259
|
+
// TPS 越高越绿,越低越紫,无数据为灰
|
|
260
|
+
var maxTps = Math.max.apply(null, effTps.filter(function(v){ return v > 0; })) || 1;
|
|
261
|
+
var barColors = effTps.map(function(v) {
|
|
262
|
+
if (v <= 0) return '#444455';
|
|
263
|
+
var r = v / maxTps;
|
|
264
|
+
if (r >= 0.8) return '#00F593';
|
|
265
|
+
if (r >= 0.5) return '#FFB800';
|
|
266
|
+
return '#B545FF';
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
var option = {
|
|
270
|
+
tooltip: {
|
|
271
|
+
trigger: 'axis',
|
|
272
|
+
axisPointer: { type: 'none' },
|
|
273
|
+
formatter: function(params) {
|
|
274
|
+
var i = params[0].dataIndex;
|
|
275
|
+
var tps = effTps[i] > 0 ? effTps[i].toFixed(1) + ' tok/s' : '\u2014';
|
|
276
|
+
var ttft = effTtft[i] > 0 ? effTtft[i].toFixed(0) + ' ms' : '\u2014';
|
|
277
|
+
var cost = effCost[i] > 0 ? '$' + effCost[i].toFixed(4) + '/1K' : '\u2014';
|
|
278
|
+
var hit = effHit[i] > 0 ? effHit[i].toFixed(1) + '%' : '\u2014';
|
|
279
|
+
return '<b>' + effNames[i] + '</b><br/>' +
|
|
280
|
+
'\u25B6 TPS: ' + tps + '<br/>' +
|
|
281
|
+
'\u23F1 TTFT: ' + ttft + '<br/>' +
|
|
282
|
+
'\uD83D\uDCB0 Cost/1K: ' + cost + '<br/>' +
|
|
283
|
+
'\uD83D\uDCBE Cache Hit: ' + hit + '<br/>' +
|
|
284
|
+
'Requests: ' + effReq[i];
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
grid: { left: 20, right: 280, bottom: 30, top: 20, containLabel: true },
|
|
288
|
+
xAxis: {
|
|
289
|
+
type: 'value',
|
|
290
|
+
name: 'Avg TPS (tokens / sec)',
|
|
291
|
+
nameTextStyle: { color: '#B0B0C0', fontSize: 11 },
|
|
292
|
+
axisLabel: { color: '#B0B0C0', formatter: function(v) { return v > 0 ? v.toFixed(0) : '0'; } },
|
|
293
|
+
splitLine: { lineStyle: { color: '#2A2A35', type: 'dashed' } }
|
|
294
|
+
},
|
|
295
|
+
yAxis: {
|
|
296
|
+
type: 'category',
|
|
297
|
+
data: effNames,
|
|
298
|
+
inverse: true,
|
|
299
|
+
axisLabel: {
|
|
300
|
+
color: '#E0E0F0',
|
|
301
|
+
fontSize: 11,
|
|
302
|
+
formatter: function(v) { return v.length > 50 ? v.slice(0, 48) + '\u2026' : v; }
|
|
303
|
+
},
|
|
304
|
+
axisLine: { show: false },
|
|
305
|
+
axisTick: { show: false }
|
|
306
|
+
},
|
|
307
|
+
series: [{
|
|
308
|
+
type: 'bar',
|
|
309
|
+
data: effTps.map(function(v, i) {
|
|
310
|
+
return { value: v > 0 ? v : 0.001, itemStyle: { color: barColors[i], borderRadius: [0, 4, 4, 0] } };
|
|
311
|
+
}),
|
|
312
|
+
barMaxWidth: 22,
|
|
313
|
+
label: {
|
|
314
|
+
show: true,
|
|
315
|
+
position: 'right',
|
|
316
|
+
color: '#E0E0F0',
|
|
317
|
+
fontSize: 10,
|
|
318
|
+
formatter: function(p) {
|
|
319
|
+
var i = p.dataIndex;
|
|
320
|
+
var parts = [effTps[i] > 0 ? effTps[i].toFixed(1) + ' t/s' : '\u2014'];
|
|
321
|
+
if (effTtft[i] > 0) parts.push('TTFT ' + effTtft[i].toFixed(0) + 'ms');
|
|
322
|
+
if (effCost[i] > 0) parts.push('\u0024' + effCost[i].toFixed(4) + '/1K');
|
|
323
|
+
return parts.join(' ');
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}]
|
|
327
|
+
};
|
|
328
|
+
chart.setOption(option);
|
|
329
|
+
chart.resize();
|
|
330
|
+
}
|
|
327
331
|
`;
|
|
328
332
|
}
|
|
329
333
|
function providerBorderColor(provider) {
|
|
@@ -334,22 +338,30 @@ function renderProviderCards(data) {
|
|
|
334
338
|
return data.providers.map(p => {
|
|
335
339
|
const modelCount = data.models.filter(m => m.provider === p.provider).length;
|
|
336
340
|
const perfItems = data.perfSummary.filter(ps => ps.providerID === p.provider);
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
341
|
+
let ttftSum = 0, ttftReqs = 0;
|
|
342
|
+
for (const x of perfItems) {
|
|
343
|
+
if (x.avgTTFT != null && x.avgTTFT > 0) {
|
|
344
|
+
ttftSum += x.avgTTFT * x.requestCount;
|
|
345
|
+
ttftReqs += x.requestCount;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
const avgTtft = ttftReqs > 0 ? ttftSum / ttftReqs : null;
|
|
349
|
+
let tpsSum = 0, tpsReqs = 0;
|
|
350
|
+
for (const x of perfItems) {
|
|
351
|
+
if (x.avgTPS != null && x.avgTPS > 0) {
|
|
352
|
+
tpsSum += x.avgTPS * x.requestCount;
|
|
353
|
+
tpsReqs += x.requestCount;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
const avgTps = tpsReqs > 0 ? tpsSum / tpsReqs : null;
|
|
357
|
+
return `
|
|
358
|
+
<div class="provider-card" style="border-color:${providerBorderColor(p.provider)}">
|
|
359
|
+
<div class="provider-name">${p.provider}</div>
|
|
360
|
+
<div class="provider-stat"><span class="stat-label">Tokens</span><span>${fmtTokens(p.totalTokens)}</span></div>
|
|
361
|
+
<div class="provider-stat"><span class="stat-label">Cost</span><span>${fmtCost(p.totalCost)}</span></div>
|
|
362
|
+
<div class="provider-stat"><span class="stat-label">Avg TTFT</span><span>${avgTtft != null ? avgTtft.toFixed(0) + 'ms' : '—'}</span></div>
|
|
363
|
+
<div class="provider-stat"><span class="stat-label">Avg TPS</span><span>${avgTps != null ? avgTps.toFixed(1) : '—'}</span></div>
|
|
364
|
+
<div class="provider-stat"><span class="stat-label">Models</span><span>${modelCount}</span></div>
|
|
353
365
|
</div>`;
|
|
354
366
|
}).join("\n");
|
|
355
367
|
}
|
|
@@ -362,39 +374,39 @@ function renderDataTable(data) {
|
|
|
362
374
|
const ttft = perf?.avgTTFT != null ? perf.avgTTFT.toFixed(0) + 'ms' : '—';
|
|
363
375
|
const p95ttft = perf?.p95TTFT != null ? perf.p95TTFT.toFixed(0) + 'ms' : '—';
|
|
364
376
|
const tps = perf?.avgTPS != null ? perf.avgTPS.toFixed(1) : '—';
|
|
365
|
-
return `<tr>
|
|
366
|
-
<td>${m.model}</td>
|
|
367
|
-
<td>${m.provider}</td>
|
|
368
|
-
<td>${m.requests}</td>
|
|
369
|
-
<td>${fmtTokens(m.totalTokens)}</td>
|
|
370
|
-
<td>${fmtTokens(m.inputTokens)}</td>
|
|
371
|
-
<td>${fmtTokens(m.outputTokens)}</td>
|
|
372
|
-
<td>${fmtTokens(m.cacheRead)}</td>
|
|
373
|
-
<td style="color:${hitColor};font-weight:600">${hitRatePct}</td>
|
|
374
|
-
<td>${ttft}</td>
|
|
375
|
-
<td style="color:var(--tps);font-size:0.85em">${p95ttft}</td>
|
|
376
|
-
<td>${tps}</td>
|
|
377
|
-
<td>${fmtCost(m.totalCost)}</td>
|
|
377
|
+
return `<tr>
|
|
378
|
+
<td>${m.model}</td>
|
|
379
|
+
<td>${m.provider}</td>
|
|
380
|
+
<td>${m.requests}</td>
|
|
381
|
+
<td>${fmtTokens(m.totalTokens)}</td>
|
|
382
|
+
<td>${fmtTokens(m.inputTokens)}</td>
|
|
383
|
+
<td>${fmtTokens(m.outputTokens)}</td>
|
|
384
|
+
<td>${fmtTokens(m.cacheRead)}</td>
|
|
385
|
+
<td style="color:${hitColor};font-weight:600">${hitRatePct}</td>
|
|
386
|
+
<td>${ttft}</td>
|
|
387
|
+
<td style="color:var(--tps);font-size:0.85em">${p95ttft}</td>
|
|
388
|
+
<td>${tps}</td>
|
|
389
|
+
<td>${fmtCost(m.totalCost)}</td>
|
|
378
390
|
</tr>`;
|
|
379
391
|
}).join("\n");
|
|
380
|
-
return `<table class="data-table">
|
|
381
|
-
<thead>
|
|
382
|
-
<tr>
|
|
383
|
-
<th>Model</th>
|
|
384
|
-
<th>Provider</th>
|
|
385
|
-
<th>Req</th>
|
|
386
|
-
<th>Total</th>
|
|
387
|
-
<th>Input</th>
|
|
388
|
-
<th>Output</th>
|
|
389
|
-
<th>Cache</th>
|
|
390
|
-
<th>Hit Rate</th>
|
|
391
|
-
<th>Avg TTFT</th>
|
|
392
|
-
<th>P95 TTFT</th>
|
|
393
|
-
<th>TPS</th>
|
|
394
|
-
<th>Cost</th>
|
|
395
|
-
</tr>
|
|
396
|
-
</thead>
|
|
397
|
-
<tbody>${rows}</tbody>
|
|
392
|
+
return `<table class="data-table">
|
|
393
|
+
<thead>
|
|
394
|
+
<tr>
|
|
395
|
+
<th>Model</th>
|
|
396
|
+
<th>Provider</th>
|
|
397
|
+
<th>Req</th>
|
|
398
|
+
<th>Total</th>
|
|
399
|
+
<th>Input</th>
|
|
400
|
+
<th>Output</th>
|
|
401
|
+
<th>Cache</th>
|
|
402
|
+
<th>Hit Rate</th>
|
|
403
|
+
<th>Avg TTFT</th>
|
|
404
|
+
<th>P95 TTFT</th>
|
|
405
|
+
<th>TPS</th>
|
|
406
|
+
<th>Cost</th>
|
|
407
|
+
</tr>
|
|
408
|
+
</thead>
|
|
409
|
+
<tbody>${rows}</tbody>
|
|
398
410
|
</table>`;
|
|
399
411
|
}
|
|
400
412
|
/** 渲染 P50/P95/P99 延迟分位数表格 */
|
|
@@ -405,41 +417,41 @@ function renderPerfPercentileTable(data) {
|
|
|
405
417
|
const rows = data.perfSummary.map(p => {
|
|
406
418
|
const hitColor = p.cacheHitRate != null && p.cacheHitRate >= 85 ? 'var(--cache)'
|
|
407
419
|
: p.cacheHitRate != null && p.cacheHitRate >= 70 ? 'var(--tps)' : 'var(--output)';
|
|
408
|
-
return `<tr>
|
|
409
|
-
<td>${p.model}</td>
|
|
410
|
-
<td>${p.requestCount}</td>
|
|
411
|
-
<td>${fmtMs(p.avgTTFT)}</td>
|
|
412
|
-
<td>${fmtMs(p.p50TTFT)}</td>
|
|
413
|
-
<td>${fmtMs(p.p95TTFT)}</td>
|
|
414
|
-
<td>${fmtMs(p.p99TTFT)}</td>
|
|
415
|
-
<td>${fmtMs(p.avgLatency)}</td>
|
|
416
|
-
<td>${fmtMs(p.p50Latency)}</td>
|
|
417
|
-
<td>${fmtMs(p.p95Latency)}</td>
|
|
418
|
-
<td>${fmtMs(p.p99Latency)}</td>
|
|
419
|
-
<td style="color:${hitColor};font-weight:600">${p.cacheHitRate != null ? p.cacheHitRate.toFixed(1) + '%' : '—'}</td>
|
|
420
|
+
return `<tr>
|
|
421
|
+
<td>${p.model}</td>
|
|
422
|
+
<td>${p.requestCount}</td>
|
|
423
|
+
<td>${fmtMs(p.avgTTFT)}</td>
|
|
424
|
+
<td>${fmtMs(p.p50TTFT)}</td>
|
|
425
|
+
<td>${fmtMs(p.p95TTFT)}</td>
|
|
426
|
+
<td>${fmtMs(p.p99TTFT)}</td>
|
|
427
|
+
<td>${fmtMs(p.avgLatency)}</td>
|
|
428
|
+
<td>${fmtMs(p.p50Latency)}</td>
|
|
429
|
+
<td>${fmtMs(p.p95Latency)}</td>
|
|
430
|
+
<td>${fmtMs(p.p99Latency)}</td>
|
|
431
|
+
<td style="color:${hitColor};font-weight:600">${p.cacheHitRate != null ? p.cacheHitRate.toFixed(1) + '%' : '—'}</td>
|
|
420
432
|
</tr>`;
|
|
421
433
|
}).join("\n");
|
|
422
|
-
return `
|
|
423
|
-
<section class="section">
|
|
424
|
-
<h2 class="section-title">Performance Latency Percentiles</h2>
|
|
425
|
-
<table class="data-table">
|
|
426
|
-
<thead>
|
|
427
|
-
<tr>
|
|
428
|
-
<th>Model</th>
|
|
429
|
-
<th>Req</th>
|
|
430
|
-
<th>Avg TTFT</th>
|
|
431
|
-
<th>P50 TTFT</th>
|
|
432
|
-
<th>P95 TTFT</th>
|
|
433
|
-
<th>P99 TTFT</th>
|
|
434
|
-
<th>Avg E2E</th>
|
|
435
|
-
<th>P50 E2E</th>
|
|
436
|
-
<th>P95 E2E</th>
|
|
437
|
-
<th>P99 E2E</th>
|
|
438
|
-
<th>Cache Hit</th>
|
|
439
|
-
</tr>
|
|
440
|
-
</thead>
|
|
441
|
-
<tbody>${rows}</tbody>
|
|
442
|
-
</table>
|
|
434
|
+
return `
|
|
435
|
+
<section class="section">
|
|
436
|
+
<h2 class="section-title">Performance Latency Percentiles</h2>
|
|
437
|
+
<table class="data-table">
|
|
438
|
+
<thead>
|
|
439
|
+
<tr>
|
|
440
|
+
<th>Model</th>
|
|
441
|
+
<th>Req</th>
|
|
442
|
+
<th>Avg TTFT</th>
|
|
443
|
+
<th>P50 TTFT</th>
|
|
444
|
+
<th>P95 TTFT</th>
|
|
445
|
+
<th>P99 TTFT</th>
|
|
446
|
+
<th>Avg E2E</th>
|
|
447
|
+
<th>P50 E2E</th>
|
|
448
|
+
<th>P95 E2E</th>
|
|
449
|
+
<th>P99 E2E</th>
|
|
450
|
+
<th>Cache Hit</th>
|
|
451
|
+
</tr>
|
|
452
|
+
</thead>
|
|
453
|
+
<tbody>${rows}</tbody>
|
|
454
|
+
</table>
|
|
443
455
|
</section>`;
|
|
444
456
|
}
|
|
445
457
|
/** 渲染失败请求统计区域 */
|
|
@@ -454,119 +466,119 @@ function renderErrorStatsSection(data) {
|
|
|
454
466
|
.filter(m => m.failed > 0)
|
|
455
467
|
.map(m => {
|
|
456
468
|
const modelRate = m.total > 0 ? (m.failed / m.total * 100).toFixed(1) + '%' : '—';
|
|
457
|
-
return `<tr>
|
|
458
|
-
<td>${m.provider}</td>
|
|
459
|
-
<td>${m.model}</td>
|
|
460
|
-
<td>${m.total}</td>
|
|
461
|
-
<td style="color:var(--output)">${m.failed}</td>
|
|
462
|
-
<td style="color:var(--tps)">${m.total - m.failed}</td>
|
|
463
|
-
<td style="color:${errors.errorRate >= 0.05 ? 'var(--output)' : 'var(--tps)'}">${modelRate}</td>
|
|
469
|
+
return `<tr>
|
|
470
|
+
<td>${m.provider}</td>
|
|
471
|
+
<td>${m.model}</td>
|
|
472
|
+
<td>${m.total}</td>
|
|
473
|
+
<td style="color:var(--output)">${m.failed}</td>
|
|
474
|
+
<td style="color:var(--tps)">${m.total - m.failed}</td>
|
|
475
|
+
<td style="color:${errors.errorRate >= 0.05 ? 'var(--output)' : 'var(--tps)'}">${modelRate}</td>
|
|
464
476
|
</tr>`;
|
|
465
477
|
}).join('\n');
|
|
466
|
-
return `
|
|
467
|
-
<section class="section">
|
|
468
|
-
<h2 class="section-title">Failed Requests
|
|
469
|
-
<span style="margin-left:12px;font-size:0.85em;color:${rateColor}">
|
|
470
|
-
overall error rate: ${errorRatePct} (${errors.failedCount} failed / ${errors.successCount + errors.failedCount} total)
|
|
471
|
-
</span>
|
|
472
|
-
</h2>
|
|
473
|
-
<table class="data-table">
|
|
474
|
-
<thead>
|
|
475
|
-
<tr>
|
|
476
|
-
<th>Provider</th><th>Model</th><th>Total</th>
|
|
477
|
-
<th>Failed</th><th>Success</th><th>Error Rate</th>
|
|
478
|
-
</tr>
|
|
479
|
-
</thead>
|
|
480
|
-
<tbody>${rows}</tbody>
|
|
481
|
-
</table>
|
|
478
|
+
return `
|
|
479
|
+
<section class="section">
|
|
480
|
+
<h2 class="section-title">Failed Requests
|
|
481
|
+
<span style="margin-left:12px;font-size:0.85em;color:${rateColor}">
|
|
482
|
+
overall error rate: ${errorRatePct} (${errors.failedCount} failed / ${errors.successCount + errors.failedCount} total)
|
|
483
|
+
</span>
|
|
484
|
+
</h2>
|
|
485
|
+
<table class="data-table">
|
|
486
|
+
<thead>
|
|
487
|
+
<tr>
|
|
488
|
+
<th>Provider</th><th>Model</th><th>Total</th>
|
|
489
|
+
<th>Failed</th><th>Success</th><th>Error Rate</th>
|
|
490
|
+
</tr>
|
|
491
|
+
</thead>
|
|
492
|
+
<tbody>${rows}</tbody>
|
|
493
|
+
</table>
|
|
482
494
|
</section>`;
|
|
483
495
|
}
|
|
484
496
|
function renderDailyTrendInit(data) {
|
|
485
497
|
const days = data.daily.slice().reverse().map(d => d.day);
|
|
486
498
|
const tokens = data.daily.slice().reverse().map(d => d.totalTokens);
|
|
487
499
|
const costs = data.daily.slice().reverse().map(d => d.totalCost);
|
|
488
|
-
return `
|
|
489
|
-
var dailyDays = ${JSON.stringify(days)};
|
|
490
|
-
var dailyTokens = ${JSON.stringify(tokens)};
|
|
491
|
-
var dailyCosts = ${JSON.stringify(costs)};
|
|
492
|
-
|
|
493
|
-
function initDailyChart() {
|
|
494
|
-
var el = document.getElementById('daily-chart');
|
|
495
|
-
if (!el) return;
|
|
496
|
-
var chart = echarts.init(el);
|
|
497
|
-
window.dailyChart = chart;
|
|
498
|
-
var option = {
|
|
499
|
-
tooltip: {
|
|
500
|
-
trigger: 'axis',
|
|
501
|
-
formatter: function(params) {
|
|
502
|
-
var html = '<b>' + params[0].axisValue + '</b><br/>';
|
|
503
|
-
params.forEach(function(p) {
|
|
504
|
-
html += p.marker + ' ' + p.seriesName + ': ' + (p.seriesName === 'Cost' ? '$' + p.value.toFixed(4) : fmt(p.value)) + '<br/>';
|
|
505
|
-
});
|
|
506
|
-
return html;
|
|
507
|
-
}
|
|
508
|
-
},
|
|
509
|
-
legend: {
|
|
510
|
-
data: ['Tokens', 'Cost'],
|
|
511
|
-
textStyle: { color: '#B0B0C0' },
|
|
512
|
-
top: 5
|
|
513
|
-
},
|
|
514
|
-
grid: { left: 60, right: 60, bottom: 80, top: 40 },
|
|
515
|
-
xAxis: {
|
|
516
|
-
type: 'category',
|
|
517
|
-
data: dailyDays,
|
|
518
|
-
axisLabel: { color: '#B0B0C0', rotate: 45, interval: 0, fontSize: 10 },
|
|
519
|
-
axisLine: { lineStyle: { color: '#2A2A35' } }
|
|
520
|
-
},
|
|
521
|
-
yAxis: [
|
|
522
|
-
{
|
|
523
|
-
type: 'value',
|
|
524
|
-
name: 'Tokens',
|
|
525
|
-
nameTextStyle: { color: '#B0B0C0' },
|
|
526
|
-
axisLabel: { color: '#B0B0C0', formatter: fmt },
|
|
527
|
-
splitLine: { lineStyle: { color: '#2A2A35', type: 'dashed' } }
|
|
528
|
-
},
|
|
529
|
-
{
|
|
530
|
-
type: 'value',
|
|
531
|
-
name: 'Cost',
|
|
532
|
-
nameTextStyle: { color: '#FFB800' },
|
|
533
|
-
axisLabel: { color: '#FFB800', formatter: function(v) { return '$' + v.toFixed(4); } },
|
|
534
|
-
splitLine: { show: false }
|
|
535
|
-
}
|
|
536
|
-
],
|
|
537
|
-
dataZoom: [{
|
|
538
|
-
type: 'slider',
|
|
539
|
-
bottom: 5,
|
|
540
|
-
height: 20,
|
|
541
|
-
borderColor: '#2A2A35',
|
|
542
|
-
fillerColor: 'rgba(0,213,255,0.1)',
|
|
543
|
-
handleStyle: { color: '#00D1FF' },
|
|
544
|
-
textStyle: { color: '#B0B0C0' }
|
|
545
|
-
}],
|
|
546
|
-
series: [
|
|
547
|
-
{
|
|
548
|
-
name: 'Tokens',
|
|
549
|
-
type: 'line',
|
|
550
|
-
data: dailyTokens,
|
|
551
|
-
smooth: true,
|
|
552
|
-
symbol: 'none',
|
|
553
|
-
lineStyle: { color: '#00D1FF', width: 2 },
|
|
554
|
-
areaStyle: { color: 'rgba(0,209,255,0.15)' }
|
|
555
|
-
},
|
|
556
|
-
{
|
|
557
|
-
name: 'Cost',
|
|
558
|
-
type: 'line',
|
|
559
|
-
yAxisIndex: 1,
|
|
560
|
-
data: dailyCosts,
|
|
561
|
-
smooth: true,
|
|
562
|
-
symbol: 'none',
|
|
563
|
-
lineStyle: { color: '#FFB800', width: 2 },
|
|
564
|
-
areaStyle: { color: 'rgba(255,184,0,0.1)' }
|
|
565
|
-
}
|
|
566
|
-
]
|
|
567
|
-
};
|
|
568
|
-
chart.setOption(option);
|
|
569
|
-
chart.resize();
|
|
500
|
+
return `
|
|
501
|
+
var dailyDays = ${JSON.stringify(days)};
|
|
502
|
+
var dailyTokens = ${JSON.stringify(tokens)};
|
|
503
|
+
var dailyCosts = ${JSON.stringify(costs)};
|
|
504
|
+
|
|
505
|
+
function initDailyChart() {
|
|
506
|
+
var el = document.getElementById('daily-chart');
|
|
507
|
+
if (!el) return;
|
|
508
|
+
var chart = echarts.init(el);
|
|
509
|
+
window.dailyChart = chart;
|
|
510
|
+
var option = {
|
|
511
|
+
tooltip: {
|
|
512
|
+
trigger: 'axis',
|
|
513
|
+
formatter: function(params) {
|
|
514
|
+
var html = '<b>' + params[0].axisValue + '</b><br/>';
|
|
515
|
+
params.forEach(function(p) {
|
|
516
|
+
html += p.marker + ' ' + p.seriesName + ': ' + (p.seriesName === 'Cost' ? '$' + p.value.toFixed(4) : fmt(p.value)) + '<br/>';
|
|
517
|
+
});
|
|
518
|
+
return html;
|
|
519
|
+
}
|
|
520
|
+
},
|
|
521
|
+
legend: {
|
|
522
|
+
data: ['Tokens', 'Cost'],
|
|
523
|
+
textStyle: { color: '#B0B0C0' },
|
|
524
|
+
top: 5
|
|
525
|
+
},
|
|
526
|
+
grid: { left: 60, right: 60, bottom: 80, top: 40 },
|
|
527
|
+
xAxis: {
|
|
528
|
+
type: 'category',
|
|
529
|
+
data: dailyDays,
|
|
530
|
+
axisLabel: { color: '#B0B0C0', rotate: 45, interval: 0, fontSize: 10 },
|
|
531
|
+
axisLine: { lineStyle: { color: '#2A2A35' } }
|
|
532
|
+
},
|
|
533
|
+
yAxis: [
|
|
534
|
+
{
|
|
535
|
+
type: 'value',
|
|
536
|
+
name: 'Tokens',
|
|
537
|
+
nameTextStyle: { color: '#B0B0C0' },
|
|
538
|
+
axisLabel: { color: '#B0B0C0', formatter: fmt },
|
|
539
|
+
splitLine: { lineStyle: { color: '#2A2A35', type: 'dashed' } }
|
|
540
|
+
},
|
|
541
|
+
{
|
|
542
|
+
type: 'value',
|
|
543
|
+
name: 'Cost',
|
|
544
|
+
nameTextStyle: { color: '#FFB800' },
|
|
545
|
+
axisLabel: { color: '#FFB800', formatter: function(v) { return '$' + v.toFixed(4); } },
|
|
546
|
+
splitLine: { show: false }
|
|
547
|
+
}
|
|
548
|
+
],
|
|
549
|
+
dataZoom: [{
|
|
550
|
+
type: 'slider',
|
|
551
|
+
bottom: 5,
|
|
552
|
+
height: 20,
|
|
553
|
+
borderColor: '#2A2A35',
|
|
554
|
+
fillerColor: 'rgba(0,213,255,0.1)',
|
|
555
|
+
handleStyle: { color: '#00D1FF' },
|
|
556
|
+
textStyle: { color: '#B0B0C0' }
|
|
557
|
+
}],
|
|
558
|
+
series: [
|
|
559
|
+
{
|
|
560
|
+
name: 'Tokens',
|
|
561
|
+
type: 'line',
|
|
562
|
+
data: dailyTokens,
|
|
563
|
+
smooth: true,
|
|
564
|
+
symbol: 'none',
|
|
565
|
+
lineStyle: { color: '#00D1FF', width: 2 },
|
|
566
|
+
areaStyle: { color: 'rgba(0,209,255,0.15)' }
|
|
567
|
+
},
|
|
568
|
+
{
|
|
569
|
+
name: 'Cost',
|
|
570
|
+
type: 'line',
|
|
571
|
+
yAxisIndex: 1,
|
|
572
|
+
data: dailyCosts,
|
|
573
|
+
smooth: true,
|
|
574
|
+
symbol: 'none',
|
|
575
|
+
lineStyle: { color: '#FFB800', width: 2 },
|
|
576
|
+
areaStyle: { color: 'rgba(255,184,0,0.1)' }
|
|
577
|
+
}
|
|
578
|
+
]
|
|
579
|
+
};
|
|
580
|
+
chart.setOption(option);
|
|
581
|
+
chart.resize();
|
|
570
582
|
}`;
|
|
571
583
|
}
|
|
572
584
|
function renderHeatmapInit(data) {
|
|
@@ -574,54 +586,54 @@ function renderHeatmapInit(data) {
|
|
|
574
586
|
const heatData = days.map(d => [d.day, Math.log10(d.totalTokens + 1)]);
|
|
575
587
|
const minDate = days.length > 0 ? days[0].day : '';
|
|
576
588
|
const maxDate = days.length > 0 ? days[days.length - 1].day : '';
|
|
577
|
-
return `
|
|
578
|
-
var heatData = ${JSON.stringify(heatData)};
|
|
579
|
-
|
|
580
|
-
function initHeatmapChart() {
|
|
581
|
-
var el = document.getElementById('heatmap-chart');
|
|
582
|
-
if (!el) return;
|
|
583
|
-
var chart = echarts.init(el);
|
|
584
|
-
window.heatmapChart = chart;
|
|
585
|
-
var option = {
|
|
586
|
-
tooltip: {
|
|
587
|
-
formatter: function(params) {
|
|
588
|
-
var val = params.value;
|
|
589
|
-
var rawTokens = Math.pow(10, val[1]) - 1;
|
|
590
|
-
return '<b>' + val[0] + '</b><br/>Tokens: ' + fmt(Math.round(rawTokens));
|
|
591
|
-
}
|
|
592
|
-
},
|
|
593
|
-
visualMap: {
|
|
594
|
-
min: 0,
|
|
595
|
-
max: Math.max.apply(null, heatData.map(function(d) { return d[1]; })) || 5,
|
|
596
|
-
calculable: true,
|
|
597
|
-
orient: 'horizontal',
|
|
598
|
-
left: 'center',
|
|
599
|
-
bottom: 10,
|
|
600
|
-
textStyle: { color: '#B0B0C0' },
|
|
601
|
-
inRange: {
|
|
602
|
-
color: ['#0C0C0E', '#1a3a2a', '#00F593', '#00D1FF', '#B545FF']
|
|
603
|
-
}
|
|
604
|
-
},
|
|
605
|
-
calendar: {
|
|
606
|
-
left: 30,
|
|
607
|
-
right: 30,
|
|
608
|
-
top: 20,
|
|
609
|
-
bottom: 60,
|
|
610
|
-
range: ['${minDate}', '${maxDate}'],
|
|
611
|
-
splitLine: { lineStyle: { color: '#2A2A35' } },
|
|
612
|
-
dayLabel: { color: '#B0B0C0' },
|
|
613
|
-
monthLabel: { color: '#B0B0C0' },
|
|
614
|
-
yearLabel: { color: '#B0B0C0' },
|
|
615
|
-
itemStyle: { color: '#16161A', borderColor: '#0C0C0E', borderWidth: 2 }
|
|
616
|
-
},
|
|
617
|
-
series: [{
|
|
618
|
-
type: 'heatmap',
|
|
619
|
-
coordinateSystem: 'calendar',
|
|
620
|
-
data: heatData
|
|
621
|
-
}]
|
|
622
|
-
};
|
|
623
|
-
chart.setOption(option);
|
|
624
|
-
chart.resize();
|
|
589
|
+
return `
|
|
590
|
+
var heatData = ${JSON.stringify(heatData)};
|
|
591
|
+
|
|
592
|
+
function initHeatmapChart() {
|
|
593
|
+
var el = document.getElementById('heatmap-chart');
|
|
594
|
+
if (!el) return;
|
|
595
|
+
var chart = echarts.init(el);
|
|
596
|
+
window.heatmapChart = chart;
|
|
597
|
+
var option = {
|
|
598
|
+
tooltip: {
|
|
599
|
+
formatter: function(params) {
|
|
600
|
+
var val = params.value;
|
|
601
|
+
var rawTokens = Math.pow(10, val[1]) - 1;
|
|
602
|
+
return '<b>' + val[0] + '</b><br/>Tokens: ' + fmt(Math.round(rawTokens));
|
|
603
|
+
}
|
|
604
|
+
},
|
|
605
|
+
visualMap: {
|
|
606
|
+
min: 0,
|
|
607
|
+
max: Math.max.apply(null, heatData.map(function(d) { return d[1]; })) || 5,
|
|
608
|
+
calculable: true,
|
|
609
|
+
orient: 'horizontal',
|
|
610
|
+
left: 'center',
|
|
611
|
+
bottom: 10,
|
|
612
|
+
textStyle: { color: '#B0B0C0' },
|
|
613
|
+
inRange: {
|
|
614
|
+
color: ['#0C0C0E', '#1a3a2a', '#00F593', '#00D1FF', '#B545FF']
|
|
615
|
+
}
|
|
616
|
+
},
|
|
617
|
+
calendar: {
|
|
618
|
+
left: 30,
|
|
619
|
+
right: 30,
|
|
620
|
+
top: 20,
|
|
621
|
+
bottom: 60,
|
|
622
|
+
range: ['${minDate}', '${maxDate}'],
|
|
623
|
+
splitLine: { lineStyle: { color: '#2A2A35' } },
|
|
624
|
+
dayLabel: { color: '#B0B0C0' },
|
|
625
|
+
monthLabel: { color: '#B0B0C0' },
|
|
626
|
+
yearLabel: { color: '#B0B0C0' },
|
|
627
|
+
itemStyle: { color: '#16161A', borderColor: '#0C0C0E', borderWidth: 2 }
|
|
628
|
+
},
|
|
629
|
+
series: [{
|
|
630
|
+
type: 'heatmap',
|
|
631
|
+
coordinateSystem: 'calendar',
|
|
632
|
+
data: heatData
|
|
633
|
+
}]
|
|
634
|
+
};
|
|
635
|
+
chart.setOption(option);
|
|
636
|
+
chart.resize();
|
|
625
637
|
}`;
|
|
626
638
|
}
|
|
627
639
|
export function generateUsageHtml(data) {
|
|
@@ -638,229 +650,229 @@ export function generateUsageHtml(data) {
|
|
|
638
650
|
const heatmapJs = renderHeatmapInit(data);
|
|
639
651
|
const hasPerf = data.perfSummary.length > 0;
|
|
640
652
|
const jsonData = JSON.stringify(data);
|
|
641
|
-
return `<!DOCTYPE html>
|
|
642
|
-
<html lang="en">
|
|
643
|
-
<head>
|
|
644
|
-
<meta charset="UTF-8">
|
|
645
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
646
|
-
<title>TokenWatch Usage Report</title>
|
|
647
|
-
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
648
|
-
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap" rel="stylesheet">
|
|
649
|
-
<script src="https://cdn.jsdelivr.net/npm/echarts@5.5.0/dist/echarts.min.js"></script>
|
|
650
|
-
<style>
|
|
651
|
-
:root {
|
|
652
|
-
--bg: #0C0C0E;
|
|
653
|
-
--card: #16161A;
|
|
654
|
-
--border: #2A2A35;
|
|
655
|
-
--text: #E0E0F0;
|
|
656
|
-
--text-dim: #B0B0C0;
|
|
657
|
-
--cache: #00F593;
|
|
658
|
-
--input: #00D1FF;
|
|
659
|
-
--output: #B545FF;
|
|
660
|
-
--tps: #FFB800;
|
|
661
|
-
--radius: 8px;
|
|
662
|
-
}
|
|
663
|
-
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
664
|
-
body {
|
|
665
|
-
background: var(--bg);
|
|
666
|
-
color: var(--text);
|
|
667
|
-
font-family: 'Inter', -apple-system, sans-serif;
|
|
668
|
-
font-size: 14px;
|
|
669
|
-
line-height: 1.5;
|
|
670
|
-
min-height: 100vh;
|
|
671
|
-
}
|
|
672
|
-
.container { max-width: 1400px; margin: 0 auto; padding: 24px 20px; }
|
|
673
|
-
.header {
|
|
674
|
-
display: flex; justify-content: space-between; align-items: center;
|
|
675
|
-
padding: 16px 0; border-bottom: 1px solid var(--border); margin-bottom: 24px;
|
|
676
|
-
}
|
|
677
|
-
.header h1 { font-size: 22px; font-weight: 600; color: var(--text); }
|
|
678
|
-
.header h1 span { color: var(--input); }
|
|
679
|
-
.header .meta { font-size: 12px; color: var(--text-dim); font-family: 'JetBrains Mono', monospace; }
|
|
680
|
-
|
|
681
|
-
.kpi-row { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; margin-bottom: 24px; }
|
|
682
|
-
.kpi-card {
|
|
683
|
-
background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
|
|
684
|
-
padding: 16px; text-align: center;
|
|
685
|
-
}
|
|
686
|
-
.kpi-card.kpi-glow { box-shadow: 0 0 20px rgba(0,245,147,0.15); border-color: var(--cache); }
|
|
687
|
-
.kpi-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }
|
|
688
|
-
.kpi-value { font-size: 26px; font-weight: 700; font-family: 'JetBrains Mono', monospace; color: var(--text); }
|
|
689
|
-
|
|
690
|
-
.section { margin-bottom: 28px; }
|
|
691
|
-
.section-title {
|
|
692
|
-
font-size: 16px; font-weight: 600; margin-bottom: 12px;
|
|
693
|
-
padding-bottom: 6px; border-bottom: 1px solid var(--border);
|
|
694
|
-
}
|
|
695
|
-
.chart-box {
|
|
696
|
-
background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
|
|
697
|
-
padding: 12px; height: 400px;
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
.tab-bar { display: flex; gap: 4px; margin-bottom: 12px; }
|
|
701
|
-
.tab-btn {
|
|
702
|
-
background: var(--card); border: 1px solid var(--border); color: var(--text-dim);
|
|
703
|
-
padding: 6px 18px; border-radius: 4px 4px 0 0; cursor: pointer; font-size: 13px; font-family: 'Inter', sans-serif;
|
|
704
|
-
}
|
|
705
|
-
.tab-btn:hover { border-color: var(--input); color: var(--text); }
|
|
706
|
-
.tab-btn.active {
|
|
707
|
-
background: var(--border); color: var(--text); border-bottom-color: var(--border);
|
|
708
|
-
}
|
|
709
|
-
.tab-content { display: none; }
|
|
710
|
-
.tab-content.active { display: block; }
|
|
711
|
-
|
|
712
|
-
.provider-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
|
|
713
|
-
.provider-card {
|
|
714
|
-
background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
|
|
715
|
-
padding: 14px;
|
|
716
|
-
}
|
|
717
|
-
.provider-name { font-size: 14px; font-weight: 600; margin-bottom: 8px; color: var(--input); }
|
|
718
|
-
.provider-stat { display: flex; justify-content: space-between; font-size: 12px; padding: 2px 0; }
|
|
719
|
-
.provider-stat .stat-label { color: var(--text-dim); }
|
|
720
|
-
|
|
721
|
-
.data-table { width: 100%; border-collapse: collapse; font-size: 12px; }
|
|
722
|
-
.data-table th {
|
|
723
|
-
background: var(--card); color: var(--text-dim); padding: 8px 10px;
|
|
724
|
-
text-align: right; border-bottom: 1px solid var(--border); font-weight: 500;
|
|
725
|
-
white-space: nowrap;
|
|
726
|
-
}
|
|
727
|
-
.data-table th:first-child { text-align: left; }
|
|
728
|
-
.data-table td {
|
|
729
|
-
padding: 6px 10px; text-align: right; border-bottom: 1px solid var(--border);
|
|
730
|
-
font-family: 'JetBrains Mono', monospace;
|
|
731
|
-
}
|
|
732
|
-
.data-table td:first-child {
|
|
733
|
-
text-align: left; color: var(--text); font-family: 'Inter', sans-serif;
|
|
734
|
-
}
|
|
735
|
-
.data-table tbody tr:hover { background: rgba(42,42,53,0.4); }
|
|
736
|
-
|
|
737
|
-
.empty-state {
|
|
738
|
-
background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
|
|
739
|
-
padding: 40px; text-align: center; color: var(--text-dim);
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
.footer {
|
|
743
|
-
margin-top: 40px; padding: 16px 0; border-top: 1px solid var(--border);
|
|
744
|
-
text-align: center; font-size: 11px; color: var(--text-dim);
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
@media (max-width: 768px) {
|
|
748
|
-
.kpi-row { grid-template-columns: repeat(2, 1fr); }
|
|
749
|
-
.provider-row { grid-template-columns: 1fr; }
|
|
750
|
-
.container { padding: 12px 10px; }
|
|
751
|
-
.header { flex-direction: column; gap: 6px; align-items: flex-start; }
|
|
752
|
-
.chart-box { height: 300px; }
|
|
753
|
-
.data-table { font-size: 11px; }
|
|
754
|
-
.data-table th, .data-table td { padding: 4px 6px; }
|
|
755
|
-
}
|
|
756
|
-
</style>
|
|
757
|
-
</head>
|
|
758
|
-
<body>
|
|
759
|
-
<div class="container">
|
|
760
|
-
<div class="header">
|
|
761
|
-
<h1><span>TokenWatch</span> Usage Report</h1>
|
|
762
|
-
<div class="meta">${metaStr}</div>
|
|
763
|
-
</div>
|
|
764
|
-
|
|
765
|
-
${kpiStr}
|
|
766
|
-
|
|
767
|
-
<div class="section">
|
|
768
|
-
<div class="section-title">Model Comparison Matrix</div>
|
|
769
|
-
${modelChartVisible ? '<div class="chart-box" id="model-chart"></div>' : '<div class="empty-state">No models with >=1M tokens in this period.</div>'}
|
|
770
|
-
</div>
|
|
771
|
-
|
|
772
|
-
<div class="section">
|
|
773
|
-
<div class="section-title">Provider Summary</div>
|
|
774
|
-
<div class="provider-row">${providerStr}</div>
|
|
775
|
-
</div>
|
|
776
|
-
|
|
777
|
-
<div class="section">
|
|
778
|
-
<div class="section-title">Detailed Data Grid</div>
|
|
779
|
-
${tableStr}
|
|
780
|
-
</div>
|
|
781
|
-
|
|
782
|
-
${perfPercentileStr}
|
|
783
|
-
|
|
784
|
-
${errorStatsStr}
|
|
785
|
-
|
|
786
|
-
<div class="section">
|
|
787
|
-
<div class="section-title">Efficiency vs Cost</div>
|
|
788
|
-
${hasPerf ? '<div class="chart-box" id="scatter-chart"></div>' : '<div class="empty-state">No performance data available for this period.</div>'}
|
|
789
|
-
</div>
|
|
790
|
-
|
|
791
|
-
<div class="section">
|
|
792
|
-
<div class="section-title">Usage Timeline</div>
|
|
793
|
-
<div class="tab-bar">
|
|
794
|
-
<button class="tab-btn active" data-tab="daily" onclick="switchTab('daily')">Daily Trend</button>
|
|
795
|
-
<button class="tab-btn" data-tab="heatmap" onclick="switchTab('heatmap')">Heatmap</button>
|
|
796
|
-
</div>
|
|
797
|
-
<div id="tab-daily" class="tab-content active">
|
|
798
|
-
<div class="chart-box" id="daily-chart"></div>
|
|
799
|
-
</div>
|
|
800
|
-
<div id="tab-heatmap" class="tab-content">
|
|
801
|
-
<div class="chart-box" id="heatmap-chart"></div>
|
|
802
|
-
</div>
|
|
803
|
-
</div>
|
|
804
|
-
|
|
805
|
-
<div class="footer">
|
|
806
|
-
Generated by TokenWatch · Data: SQLite + JSONL · Export: <a href="javascript:void(0)" onclick="downloadJSON()" style="color:var(--input);text-decoration:none">JSON</a> <span style="color:var(--text-dim)">(saves to browser download folder)</span>
|
|
807
|
-
</div>
|
|
808
|
-
</div>
|
|
809
|
-
|
|
810
|
-
<script id="report-data" type="application/json">${jsonData}</script>
|
|
811
|
-
|
|
812
|
-
<script>
|
|
813
|
-
var fmt = function(v) {
|
|
814
|
-
if (v == null) return '\u2014';
|
|
815
|
-
if (v >= 1000000000) return (v/1000000000).toFixed(1)+'B';
|
|
816
|
-
if (v >= 1000000) return (v/1000000).toFixed(1)+'M';
|
|
817
|
-
if (v >= 1000) return (v/1000).toFixed(1)+'K';
|
|
818
|
-
return String(v);
|
|
819
|
-
};
|
|
820
|
-
|
|
821
|
-
window.switchTab = function(name) {
|
|
822
|
-
document.querySelectorAll('.tab-content').forEach(function(el) { el.classList.remove('active'); });
|
|
823
|
-
document.querySelectorAll('.tab-btn').forEach(function(el) { el.classList.remove('active'); });
|
|
824
|
-
document.getElementById('tab-' + name).classList.add('active');
|
|
825
|
-
document.querySelector('[data-tab="' + name + '"]').classList.add('active');
|
|
826
|
-
setTimeout(function() {
|
|
827
|
-
if (name === 'daily' && window.dailyChart) window.dailyChart.resize();
|
|
828
|
-
if (name === 'heatmap' && window.heatmapChart) window.heatmapChart.resize();
|
|
829
|
-
}, 50);
|
|
830
|
-
};
|
|
831
|
-
|
|
832
|
-
${modelChartJs}
|
|
833
|
-
${scatterChartJs}
|
|
834
|
-
${dailyChartJs}
|
|
835
|
-
${heatmapJs}
|
|
836
|
-
|
|
837
|
-
window.downloadJSON = function() {
|
|
838
|
-
var d = document.getElementById('report-data');
|
|
839
|
-
if (!d) return;
|
|
840
|
-
var b = new Blob([d.textContent], { type: 'application/json' });
|
|
841
|
-
var a = document.createElement('a');
|
|
842
|
-
a.href = URL.createObjectURL(b);
|
|
843
|
-
a.download = 'tokenwatch-data.json';
|
|
844
|
-
document.body.appendChild(a);
|
|
845
|
-
a.click();
|
|
846
|
-
document.body.removeChild(a);
|
|
847
|
-
setTimeout(function() { URL.revokeObjectURL(a.href); }, 100);
|
|
848
|
-
};
|
|
849
|
-
|
|
850
|
-
document.addEventListener('DOMContentLoaded', function() {
|
|
851
|
-
${modelChartVisible ? 'initModelChart();' : ''}
|
|
852
|
-
${hasPerf ? 'initScatterChart();' : ''}
|
|
853
|
-
initDailyChart();
|
|
854
|
-
initHeatmapChart();
|
|
855
|
-
});
|
|
856
|
-
|
|
857
|
-
window.addEventListener('resize', function() {
|
|
858
|
-
${modelChartVisible ? 'if (window.modelChart) window.modelChart.resize();' : ''}
|
|
859
|
-
if (window.scatterChart) window.scatterChart.resize();
|
|
860
|
-
if (window.dailyChart) window.dailyChart.resize();
|
|
861
|
-
if (window.heatmapChart) window.heatmapChart.resize();
|
|
862
|
-
});
|
|
863
|
-
</script>
|
|
864
|
-
</body>
|
|
653
|
+
return `<!DOCTYPE html>
|
|
654
|
+
<html lang="en">
|
|
655
|
+
<head>
|
|
656
|
+
<meta charset="UTF-8">
|
|
657
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
658
|
+
<title>TokenWatch Usage Report</title>
|
|
659
|
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
660
|
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap" rel="stylesheet">
|
|
661
|
+
<script src="https://cdn.jsdelivr.net/npm/echarts@5.5.0/dist/echarts.min.js"></script>
|
|
662
|
+
<style>
|
|
663
|
+
:root {
|
|
664
|
+
--bg: #0C0C0E;
|
|
665
|
+
--card: #16161A;
|
|
666
|
+
--border: #2A2A35;
|
|
667
|
+
--text: #E0E0F0;
|
|
668
|
+
--text-dim: #B0B0C0;
|
|
669
|
+
--cache: #00F593;
|
|
670
|
+
--input: #00D1FF;
|
|
671
|
+
--output: #B545FF;
|
|
672
|
+
--tps: #FFB800;
|
|
673
|
+
--radius: 8px;
|
|
674
|
+
}
|
|
675
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
676
|
+
body {
|
|
677
|
+
background: var(--bg);
|
|
678
|
+
color: var(--text);
|
|
679
|
+
font-family: 'Inter', -apple-system, sans-serif;
|
|
680
|
+
font-size: 14px;
|
|
681
|
+
line-height: 1.5;
|
|
682
|
+
min-height: 100vh;
|
|
683
|
+
}
|
|
684
|
+
.container { max-width: 1400px; margin: 0 auto; padding: 24px 20px; }
|
|
685
|
+
.header {
|
|
686
|
+
display: flex; justify-content: space-between; align-items: center;
|
|
687
|
+
padding: 16px 0; border-bottom: 1px solid var(--border); margin-bottom: 24px;
|
|
688
|
+
}
|
|
689
|
+
.header h1 { font-size: 22px; font-weight: 600; color: var(--text); }
|
|
690
|
+
.header h1 span { color: var(--input); }
|
|
691
|
+
.header .meta { font-size: 12px; color: var(--text-dim); font-family: 'JetBrains Mono', monospace; }
|
|
692
|
+
|
|
693
|
+
.kpi-row { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; margin-bottom: 24px; }
|
|
694
|
+
.kpi-card {
|
|
695
|
+
background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
|
|
696
|
+
padding: 16px; text-align: center;
|
|
697
|
+
}
|
|
698
|
+
.kpi-card.kpi-glow { box-shadow: 0 0 20px rgba(0,245,147,0.15); border-color: var(--cache); }
|
|
699
|
+
.kpi-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }
|
|
700
|
+
.kpi-value { font-size: 26px; font-weight: 700; font-family: 'JetBrains Mono', monospace; color: var(--text); }
|
|
701
|
+
|
|
702
|
+
.section { margin-bottom: 28px; }
|
|
703
|
+
.section-title {
|
|
704
|
+
font-size: 16px; font-weight: 600; margin-bottom: 12px;
|
|
705
|
+
padding-bottom: 6px; border-bottom: 1px solid var(--border);
|
|
706
|
+
}
|
|
707
|
+
.chart-box {
|
|
708
|
+
background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
|
|
709
|
+
padding: 12px; height: 400px;
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
.tab-bar { display: flex; gap: 4px; margin-bottom: 12px; }
|
|
713
|
+
.tab-btn {
|
|
714
|
+
background: var(--card); border: 1px solid var(--border); color: var(--text-dim);
|
|
715
|
+
padding: 6px 18px; border-radius: 4px 4px 0 0; cursor: pointer; font-size: 13px; font-family: 'Inter', sans-serif;
|
|
716
|
+
}
|
|
717
|
+
.tab-btn:hover { border-color: var(--input); color: var(--text); }
|
|
718
|
+
.tab-btn.active {
|
|
719
|
+
background: var(--border); color: var(--text); border-bottom-color: var(--border);
|
|
720
|
+
}
|
|
721
|
+
.tab-content { display: none; }
|
|
722
|
+
.tab-content.active { display: block; }
|
|
723
|
+
|
|
724
|
+
.provider-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
|
|
725
|
+
.provider-card {
|
|
726
|
+
background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
|
|
727
|
+
padding: 14px;
|
|
728
|
+
}
|
|
729
|
+
.provider-name { font-size: 14px; font-weight: 600; margin-bottom: 8px; color: var(--input); }
|
|
730
|
+
.provider-stat { display: flex; justify-content: space-between; font-size: 12px; padding: 2px 0; }
|
|
731
|
+
.provider-stat .stat-label { color: var(--text-dim); }
|
|
732
|
+
|
|
733
|
+
.data-table { width: 100%; border-collapse: collapse; font-size: 12px; }
|
|
734
|
+
.data-table th {
|
|
735
|
+
background: var(--card); color: var(--text-dim); padding: 8px 10px;
|
|
736
|
+
text-align: right; border-bottom: 1px solid var(--border); font-weight: 500;
|
|
737
|
+
white-space: nowrap;
|
|
738
|
+
}
|
|
739
|
+
.data-table th:first-child { text-align: left; }
|
|
740
|
+
.data-table td {
|
|
741
|
+
padding: 6px 10px; text-align: right; border-bottom: 1px solid var(--border);
|
|
742
|
+
font-family: 'JetBrains Mono', monospace;
|
|
743
|
+
}
|
|
744
|
+
.data-table td:first-child {
|
|
745
|
+
text-align: left; color: var(--text); font-family: 'Inter', sans-serif;
|
|
746
|
+
}
|
|
747
|
+
.data-table tbody tr:hover { background: rgba(42,42,53,0.4); }
|
|
748
|
+
|
|
749
|
+
.empty-state {
|
|
750
|
+
background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
|
|
751
|
+
padding: 40px; text-align: center; color: var(--text-dim);
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
.footer {
|
|
755
|
+
margin-top: 40px; padding: 16px 0; border-top: 1px solid var(--border);
|
|
756
|
+
text-align: center; font-size: 11px; color: var(--text-dim);
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
@media (max-width: 768px) {
|
|
760
|
+
.kpi-row { grid-template-columns: repeat(2, 1fr); }
|
|
761
|
+
.provider-row { grid-template-columns: 1fr; }
|
|
762
|
+
.container { padding: 12px 10px; }
|
|
763
|
+
.header { flex-direction: column; gap: 6px; align-items: flex-start; }
|
|
764
|
+
.chart-box { height: 300px; }
|
|
765
|
+
.data-table { font-size: 11px; }
|
|
766
|
+
.data-table th, .data-table td { padding: 4px 6px; }
|
|
767
|
+
}
|
|
768
|
+
</style>
|
|
769
|
+
</head>
|
|
770
|
+
<body>
|
|
771
|
+
<div class="container">
|
|
772
|
+
<div class="header">
|
|
773
|
+
<h1><span>TokenWatch</span> Usage Report</h1>
|
|
774
|
+
<div class="meta">${metaStr}</div>
|
|
775
|
+
</div>
|
|
776
|
+
|
|
777
|
+
${kpiStr}
|
|
778
|
+
|
|
779
|
+
<div class="section">
|
|
780
|
+
<div class="section-title">Model Comparison Matrix</div>
|
|
781
|
+
${modelChartVisible ? '<div class="chart-box" id="model-chart"></div>' : '<div class="empty-state">No models with >=1M tokens in this period.</div>'}
|
|
782
|
+
</div>
|
|
783
|
+
|
|
784
|
+
<div class="section">
|
|
785
|
+
<div class="section-title">Provider Summary</div>
|
|
786
|
+
<div class="provider-row">${providerStr}</div>
|
|
787
|
+
</div>
|
|
788
|
+
|
|
789
|
+
<div class="section">
|
|
790
|
+
<div class="section-title">Detailed Data Grid</div>
|
|
791
|
+
${tableStr}
|
|
792
|
+
</div>
|
|
793
|
+
|
|
794
|
+
${perfPercentileStr}
|
|
795
|
+
|
|
796
|
+
${errorStatsStr}
|
|
797
|
+
|
|
798
|
+
<div class="section">
|
|
799
|
+
<div class="section-title">Efficiency vs Cost</div>
|
|
800
|
+
${hasPerf ? '<div class="chart-box" id="scatter-chart"></div>' : '<div class="empty-state">No performance data available for this period.</div>'}
|
|
801
|
+
</div>
|
|
802
|
+
|
|
803
|
+
<div class="section">
|
|
804
|
+
<div class="section-title">Usage Timeline</div>
|
|
805
|
+
<div class="tab-bar">
|
|
806
|
+
<button class="tab-btn active" data-tab="daily" onclick="switchTab('daily')">Daily Trend</button>
|
|
807
|
+
<button class="tab-btn" data-tab="heatmap" onclick="switchTab('heatmap')">Heatmap</button>
|
|
808
|
+
</div>
|
|
809
|
+
<div id="tab-daily" class="tab-content active">
|
|
810
|
+
<div class="chart-box" id="daily-chart"></div>
|
|
811
|
+
</div>
|
|
812
|
+
<div id="tab-heatmap" class="tab-content">
|
|
813
|
+
<div class="chart-box" id="heatmap-chart"></div>
|
|
814
|
+
</div>
|
|
815
|
+
</div>
|
|
816
|
+
|
|
817
|
+
<div class="footer">
|
|
818
|
+
Generated by TokenWatch · Data: SQLite + JSONL · Export: <a href="javascript:void(0)" onclick="downloadJSON()" style="color:var(--input);text-decoration:none">JSON</a> <span style="color:var(--text-dim)">(saves to browser download folder)</span>
|
|
819
|
+
</div>
|
|
820
|
+
</div>
|
|
821
|
+
|
|
822
|
+
<script id="report-data" type="application/json">${jsonData}</script>
|
|
823
|
+
|
|
824
|
+
<script>
|
|
825
|
+
var fmt = function(v) {
|
|
826
|
+
if (v == null) return '\u2014';
|
|
827
|
+
if (v >= 1000000000) return (v/1000000000).toFixed(1)+'B';
|
|
828
|
+
if (v >= 1000000) return (v/1000000).toFixed(1)+'M';
|
|
829
|
+
if (v >= 1000) return (v/1000).toFixed(1)+'K';
|
|
830
|
+
return String(v);
|
|
831
|
+
};
|
|
832
|
+
|
|
833
|
+
window.switchTab = function(name) {
|
|
834
|
+
document.querySelectorAll('.tab-content').forEach(function(el) { el.classList.remove('active'); });
|
|
835
|
+
document.querySelectorAll('.tab-btn').forEach(function(el) { el.classList.remove('active'); });
|
|
836
|
+
document.getElementById('tab-' + name).classList.add('active');
|
|
837
|
+
document.querySelector('[data-tab="' + name + '"]').classList.add('active');
|
|
838
|
+
setTimeout(function() {
|
|
839
|
+
if (name === 'daily' && window.dailyChart) window.dailyChart.resize();
|
|
840
|
+
if (name === 'heatmap' && window.heatmapChart) window.heatmapChart.resize();
|
|
841
|
+
}, 50);
|
|
842
|
+
};
|
|
843
|
+
|
|
844
|
+
${modelChartJs}
|
|
845
|
+
${scatterChartJs}
|
|
846
|
+
${dailyChartJs}
|
|
847
|
+
${heatmapJs}
|
|
848
|
+
|
|
849
|
+
window.downloadJSON = function() {
|
|
850
|
+
var d = document.getElementById('report-data');
|
|
851
|
+
if (!d) return;
|
|
852
|
+
var b = new Blob([d.textContent], { type: 'application/json' });
|
|
853
|
+
var a = document.createElement('a');
|
|
854
|
+
a.href = URL.createObjectURL(b);
|
|
855
|
+
a.download = 'tokenwatch-data.json';
|
|
856
|
+
document.body.appendChild(a);
|
|
857
|
+
a.click();
|
|
858
|
+
document.body.removeChild(a);
|
|
859
|
+
setTimeout(function() { URL.revokeObjectURL(a.href); }, 100);
|
|
860
|
+
};
|
|
861
|
+
|
|
862
|
+
document.addEventListener('DOMContentLoaded', function() {
|
|
863
|
+
${modelChartVisible ? 'initModelChart();' : ''}
|
|
864
|
+
${hasPerf ? 'initScatterChart();' : ''}
|
|
865
|
+
initDailyChart();
|
|
866
|
+
initHeatmapChart();
|
|
867
|
+
});
|
|
868
|
+
|
|
869
|
+
window.addEventListener('resize', function() {
|
|
870
|
+
${modelChartVisible ? 'if (window.modelChart) window.modelChart.resize();' : ''}
|
|
871
|
+
if (window.scatterChart) window.scatterChart.resize();
|
|
872
|
+
if (window.dailyChart) window.dailyChart.resize();
|
|
873
|
+
if (window.heatmapChart) window.heatmapChart.resize();
|
|
874
|
+
});
|
|
875
|
+
</script>
|
|
876
|
+
</body>
|
|
865
877
|
</html>`;
|
|
866
878
|
}
|