modelpace 0.0.0-stage → 0.1.0

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.
@@ -0,0 +1,522 @@
1
+ (() => {
2
+ 'use strict';
3
+
4
+ const I18N = {
5
+ en: {
6
+ title: 'modelpace dashboard',
7
+ tabQuota: 'Quota & Even Pace', tabSpeed: 'Speed Leaderboard', tabScores: 'Scores & Dispatch Audit',
8
+ generated: 'Generated', noInstances: 'No usage snapshot available.',
9
+ remaining: 'remaining', resetsIn: 'resets in', evenPace: 'Even Pace', pool: 'Pool', noReset: 'no reset time',
10
+ creditCards: 'reset credit(s)', credit: 'reset credit', expires: 'expires', noCredits: 'no reset credits',
11
+ paceSurplus: 'ahead of pace', paceBalanced: 'on pace', paceConserve: 'behind pace', paceUnknown: 'no pace data',
12
+ speedHint: 'Median tok/s of requests with >=1000 output tokens, from local session logs.',
13
+ rank: '#', model: 'Model', channel: 'Channel', rate: 'tok/s', short: 'Short s', requests: 'Requests',
14
+ dispatchPass: 'Dispatch Pass', noSpeed: 'No local speed samples found.', lowSample: 'Low sample (<20 long requests)',
15
+ showLow: 'Show {n} low-sample rows', hideLow: 'Hide low-sample rows', shareImage: 'Share Image',
16
+ shareTitle: 'Share image', download: 'Download PNG', copy: 'Copy to clipboard', close: 'Close', copied: 'Copied',
17
+ copyFailed: 'Copy not supported here', rows: 'Rows', noRows: 'Nothing to draw',
18
+ scoresHint: 'Beta(1,1) pass rate with 90% interval, median task duration and nominal cost per run.',
19
+ identity: 'Identity', task: 'Task', passRate: 'Pass rate', interval: '90% interval', n: 'n', duration: 'Median min',
20
+ cost: 'Cost / run', noScores: 'No acceptance records.', trial: 'trial', audit: 'Latest dispatch decision',
21
+ action: 'Action', candidate: 'Candidate', quota: 'Quota', quality: 'Quality', eligible: 'Eligible', speed: 'tok/s',
22
+ pace: 'Pace', notes: 'Notes', noDecision: 'No dispatch decision available.', yes: 'yes', no: 'no',
23
+ shareHeaderRate: 'tok/s', shareHeaderPass: 'Tasks passed',
24
+ shareTitleText: 'Output Speed of the Models I Use',
25
+ shareSubtitle: (period, omitted) => `Compiled from my local session logs · ${period} · median of requests with ≥1,000 output tokens${omitted}`,
26
+ shareOmitted: (n, sparse) => ` · ${n} ${sparse ? 'low-sample ' : ''}model${n === 1 ? '' : 's'} not shown`,
27
+ shareThin: 'Hatched: <20 speed samples', shareNoDispatch: 'no delegated tasks',
28
+ shareNoteSpeed: 'Speed = output tokens (incl. thinking) ÷ request wall time (incl. time to first token, network and queueing). Real-world speed on my machine, not vendor-reported decode speed.',
29
+ shareNotePass: 'Tasks passed = delegated tasks that were accepted with no false report, no scope violation, stopped when access was denied and at most one rework round, out of all delegated tasks (all-time).',
30
+ shareNoteChannel: 'The tag under each name is the client the model ran through. Speed is measured separately per client.',
31
+ shareBrand: 'Generated with modelpace', periodJoin: ' to ',
32
+ },
33
+ zh: {
34
+ title: 'modelpace 仪表盘',
35
+ tabQuota: '额度与 Even Pace', tabSpeed: '速度排行', tabScores: '验收评分与派发审计',
36
+ generated: '生成于', noInstances: '没有可用的用量快照。',
37
+ remaining: '剩余', resetsIn: '重置于', evenPace: 'Even Pace', pool: '池', noReset: '无重置时间',
38
+ creditCards: '张重置卡', credit: '重置卡', expires: '到期', noCredits: '无重置卡',
39
+ paceSurplus: '领先节奏', paceBalanced: '节奏正常', paceConserve: '落后节奏', paceUnknown: '无节奏数据',
40
+ speedHint: '本机会话日志中输出 ≥1000 token 请求的 tok/s 中位数。',
41
+ rank: '#', model: '模型', channel: '通道', rate: 'tok/s', short: '短请求秒', requests: '请求数',
42
+ dispatchPass: '派发通过', noSpeed: '没有找到本地速度样本。', lowSample: '样本少(长请求 <20)',
43
+ showLow: '展开 {n} 个样本少的行', hideLow: '收起样本少的行', shareImage: '分享图',
44
+ shareTitle: '分享图', download: '下载 PNG', copy: '复制到剪贴板', close: '关闭', copied: '已复制',
45
+ copyFailed: '当前环境不支持复制', rows: '行', noRows: '没有可画的行',
46
+ scoresHint: 'Beta(1,1) 通过率及 90% 区间、任务耗时中位数与名义单次成本。',
47
+ identity: '执行者', task: '任务', passRate: '通过率', interval: '90% 区间', n: '样本', duration: '耗时中位(分)',
48
+ cost: '单次成本', noScores: '暂无验收记录。', trial: '试用', audit: '最近一次派发决策',
49
+ action: '动作', candidate: '候选', quota: '额度', quality: '质量', eligible: '可用', speed: 'tok/s',
50
+ pace: '节奏', notes: '说明', noDecision: '暂无派发决策。', yes: '是', no: '否',
51
+ shareHeaderRate: '速率 tok/s', shareHeaderPass: '派发通过',
52
+ shareTitleText: '我用过的模型 · 输出速率排行',
53
+ shareSubtitle: (period, omitted) => `从本机会话日志汇总 · ${period} · 单次输出 ≥1000 token 的请求取中位数${omitted}`,
54
+ shareOmitted: (n, sparse) => ` · 未列出 ${n} 个${sparse ? '样本 <20 次的' : ''}模型`,
55
+ shareThin: '斜纹:速率样本 <20 次', shareNoDispatch: '没有派发记录',
56
+ shareNoteSpeed: '速率 = 输出 token(含思考)÷ 单次请求耗时(含首字等待、网络与排队),是这台机器上的实际体验,不是厂商标称的纯生成速度。',
57
+ shareNotePass: '派发通过 = 派发给该模型的任务中,复核通过、未虚报、未越界、遇授权拒绝即停、返工不超过 1 轮的次数 / 派发次数(全部历史)。',
58
+ shareNoteChannel: '名称下方标签为调用通道(客户端),同一模型经不同通道调用时速率分开统计。',
59
+ shareBrand: '由 modelpace 生成', periodJoin: ' 至 ',
60
+ },
61
+ };
62
+
63
+ const VENDORS = {
64
+ anthropic: { name: 'Anthropic', color: '#d95926' },
65
+ google: { name: 'Google', color: '#4a90f0' },
66
+ openai: { name: 'OpenAI', color: '#199e70' },
67
+ deepseek: { name: 'DeepSeek', color: '#c060c0' },
68
+ xai: { name: 'xAI', color: '#d4a017' },
69
+ other: { name: 'Other', color: '#8a93a3' },
70
+ };
71
+ const VENDOR_ORDER = Object.values(VENDORS);
72
+ const CHANNELS = {
73
+ claude: ['Claude Code', VENDORS.anthropic.color], antigravity: ['Antigravity', VENDORS.google.color],
74
+ codex: ['Codex', VENDORS.openai.color], grok: ['Grok CLI', VENDORS.xai.color], opencode: ['OpenCode', VENDORS.other.color],
75
+ };
76
+ const EM_DASH = '—';
77
+ const KEY_LANG = 'modelpace:lang';
78
+ const KEY_TAB = 'modelpace:tab';
79
+ const KEY_ROWS = 'modelpace:share-rows:v1';
80
+
81
+ const store = {
82
+ get: (key) => { try { return localStorage.getItem(key); } catch { return null; } },
83
+ set: (key, value) => { try { localStorage.setItem(key, value); } catch { /* 无存储时只是不记忆 */ } },
84
+ };
85
+
86
+ let data = JSON.parse(document.getElementById('t3d-data').textContent);
87
+ let lang = store.get(KEY_LANG) === 'zh' ? 'zh' : 'en';
88
+ let tab = ['quota', 'speed', 'scores'].includes(store.get(KEY_TAB)) ? store.get(KEY_TAB) : 'quota';
89
+ let showLow = false;
90
+ let modal = null;
91
+
92
+ const t = (key) => I18N[lang][key];
93
+ const root = document.getElementById('t3d-root');
94
+
95
+ function h(tag, attrs, ...children) {
96
+ const el = document.createElement(tag);
97
+ for (const [name, value] of Object.entries(attrs ?? {})) {
98
+ if (value === null || value === undefined || value === false) continue;
99
+ if (name === 'class') el.className = value;
100
+ else if (name === 'style') el.setAttribute('style', value);
101
+ else if (name.startsWith('on')) el.addEventListener(name.slice(2), value);
102
+ else el.setAttribute(name, value === true ? '' : value);
103
+ }
104
+ for (const child of children.flat()) {
105
+ if (child === null || child === undefined || child === false) continue;
106
+ el.append(child instanceof Node ? child : document.createTextNode(String(child)));
107
+ }
108
+ return el;
109
+ }
110
+
111
+ // ---- 格式化 ----
112
+ const pct = (value, digits = 0) => `${Number(value).toFixed(digits)}%`;
113
+ const num = (value, digits = 1) => (value === null || value === undefined ? EM_DASH : Number(value).toFixed(digits));
114
+ function duration(mins) {
115
+ if (mins === null || mins === undefined) return t('noReset');
116
+ if (mins <= 0) return '0m';
117
+ const days = Math.floor(mins / 1440);
118
+ const hours = Math.floor((mins % 1440) / 60);
119
+ const minutes = Math.floor(mins % 60);
120
+ if (days) return `${days}d ${hours}h`;
121
+ return hours ? `${hours}h ${minutes}m` : `${minutes}m`;
122
+ }
123
+ const resetsInMins = (win) => (win.resetsAtMs === null ? null : (win.resetsAtMs - Date.now()) / 60000);
124
+
125
+ // ---- 厂商与模型名 ----
126
+ function vendorOf(model) {
127
+ const id = model.slice(model.lastIndexOf('/') + 1).toLowerCase();
128
+ if (id.startsWith('claude')) return VENDORS.anthropic;
129
+ if (id.startsWith('gemini')) return VENDORS.google;
130
+ if (id.startsWith('gpt') || id.startsWith('codex') || /^o\d/.test(id)) return VENDORS.openai;
131
+ if (id.startsWith('deepseek')) return VENDORS.deepseek;
132
+ if (id.startsWith('grok')) return VENDORS.xai;
133
+ return VENDORS.other;
134
+ }
135
+ const channelOf = (provider) => {
136
+ const [label, color] = CHANNELS[provider] ?? [provider, VENDORS.other.color];
137
+ return { label, color };
138
+ };
139
+ function titleToken(token) {
140
+ const lower = token.toLowerCase();
141
+ if (lower === 'gpt') return 'GPT';
142
+ if (lower === 'oss') return 'OSS';
143
+ if (lower === 'deepseek') return 'DeepSeek';
144
+ if (/^\d+[a-z]$/.test(lower)) return token.toUpperCase();
145
+ return token.charAt(0).toUpperCase() + token.slice(1);
146
+ }
147
+ function displayName(model) {
148
+ const id = model.slice(model.lastIndexOf('/') + 1).replace(/-\d{8}$/, '');
149
+ const words = [];
150
+ let digits = [];
151
+ const flush = () => { if (digits.length) words.push(digits.join('.')); digits = []; };
152
+ for (const token of id.split('-')) {
153
+ if (/^\d+$/.test(token)) { digits.push(token); continue; }
154
+ flush();
155
+ words.push(titleToken(token));
156
+ }
157
+ flush();
158
+ return words[0] === 'GPT' && words[1] && /^(\d|OSS$)/.test(words[1])
159
+ ? [`GPT-${words[1]}`, ...words.slice(2)].join(' ')
160
+ : words.join(' ');
161
+ }
162
+ const rowKey = (row) => JSON.stringify([row.provider, row.model, row.tier ?? null]);
163
+ const rowName = (row) => `${displayName(row.model)}${row.tier ? ` (${row.tier})` : ''}`;
164
+ const passText = (row) => (row.dispatch ? `${row.dispatch.successes}/${row.dispatch.total}` : EM_DASH);
165
+
166
+ // ---- Tab 1:额度与 Even Pace ----
167
+ const PACE_TEXT = { surplus: 'paceSurplus', balanced: 'paceBalanced', conserve: 'paceConserve', unknown: 'paceUnknown' };
168
+ function windowBar(win) {
169
+ const remaining = Math.max(0, Math.min(100, win.effectiveRemainingPercent));
170
+ const mins = resetsInMins(win);
171
+ return h('div', { class: 'win' },
172
+ h('div', { class: 'win-head' },
173
+ h('span', { class: 'win-label' }, win.label, win.pool ? h('span', { class: 'tag' }, `${t('pool')}: ${win.pool}`) : null),
174
+ h('span', { class: 'win-meta' }, `${pct(remaining)} ${t('remaining')} · ${t('resetsIn')} ${duration(mins)}`)),
175
+ h('div', { class: `bar pace-${win.pace}`, role: 'img', 'aria-label': `${win.label} ${pct(remaining)}` },
176
+ h('div', { class: 'bar-fill', style: `width:${remaining}%` }),
177
+ win.remainingTimePercent === null ? null
178
+ : h('div', { class: 'even-pace', style: `left:${Math.max(0, Math.min(100, win.remainingTimePercent))}%`, title: `${t('evenPace')} ${pct(win.remainingTimePercent)}` })),
179
+ h('div', { class: 'win-foot' },
180
+ h('span', { class: `pace-text pace-${win.pace}` }, t(PACE_TEXT[win.pace] ?? 'paceUnknown')),
181
+ win.remainingTimePercent === null ? null : h('span', null, `${t('evenPace')} ${pct(win.remainingTimePercent)}`)));
182
+ }
183
+
184
+ function creditLine(credits) {
185
+ if (!credits || !credits.known) return null;
186
+ if (!credits.availableCount) return h('div', { class: 'credits muted' }, t('noCredits'));
187
+ return h('div', { class: 'credits' },
188
+ `${credits.availableCount} ${t('creditCards')}`,
189
+ credits.nextExpiresAt ? ` · ${t('expires')} ${credits.nextExpiresAt.slice(0, 10)}` : '');
190
+ }
191
+
192
+ function renderQuota() {
193
+ const { instances, pools } = data.quota;
194
+ if (!instances.length) return h('p', { class: 'empty' }, t('noInstances'));
195
+ const cards = instances.map((inst) =>
196
+ h('section', { class: 'card' },
197
+ h('header', null, h('h3', null, inst.displayName), h('span', { class: `status status-${inst.status}` }, inst.status),
198
+ inst.plan ? h('span', { class: 'muted' }, inst.plan) : null),
199
+ inst.windows.length ? inst.windows.map(windowBar) : h('p', { class: 'muted' }, t('paceUnknown')),
200
+ creditLine(inst.resetCredits)));
201
+ const poolCards = pools.map((pool) =>
202
+ h('section', { class: 'card' },
203
+ h('header', null, h('h3', null, `${t('pool')}: ${pool.pool}`)),
204
+ pool.windows.map((entry) => h('div', null, h('div', { class: 'muted small' }, entry.instance), windowBar(entry.window)))));
205
+ return h('div', { class: 'grid' }, cards, poolCards);
206
+ }
207
+
208
+ // ---- Tab 2:速度排行 ----
209
+ function renderSpeed() {
210
+ const rows = data.speed.ranking;
211
+ if (!rows.length) return h('p', { class: 'empty' }, t('noSpeed'));
212
+ const solid = rows.filter((row) => !row.lowSample);
213
+ const split = solid.length === 0 ? { solid: rows, sparse: [] } : { solid, sparse: rows.filter((row) => row.lowSample) };
214
+ const visible = showLow ? [...split.solid, ...split.sparse] : split.solid;
215
+ const max = Math.max(1, ...rows.map((row) => row.longRate ?? row.allRate ?? 0));
216
+ const body = visible.map((row, index) => {
217
+ const rate = row.longRate ?? row.allRate ?? 0;
218
+ const color = vendorOf(row.model).color;
219
+ const channel = channelOf(row.provider);
220
+ return h('tr', null,
221
+ h('td', { class: 'num muted' }, index + 1),
222
+ h('td', null, h('div', null, rowName(row)), h('span', { class: 'chip', style: `color:${channel.color};border-color:${channel.color}` }, channel.label)),
223
+ h('td', { class: 'bar-cell' }, h('div', { class: `speed-bar${row.lowSample ? ' hatched' : ''}`, style: `width:${(rate / max) * 100}%;--c:${color}`, title: row.lowSample ? t('lowSample') : null })),
224
+ h('td', { class: 'num strong' }, num(row.longRate ?? row.allRate)),
225
+ h('td', { class: 'num' }, num(row.shortSeconds, 2)),
226
+ h('td', { class: 'num' }, `${row.longRequests}/${row.requests}`),
227
+ h('td', { class: 'num' }, passText(row)));
228
+ });
229
+ const toggle = split.sparse.length
230
+ ? h('button', { class: 'btn', onclick: () => { showLow = !showLow; render(); } },
231
+ showLow ? t('hideLow') : t('showLow').replace('{n}', split.sparse.length))
232
+ : null;
233
+ return h('div', null,
234
+ h('div', { class: 'toolbar' }, h('p', { class: 'muted' }, t('speedHint')),
235
+ h('button', { class: 'btn primary', onclick: openShare }, t('shareImage'))),
236
+ h('table', null,
237
+ h('thead', null, h('tr', null, [t('rank'), t('model'), '', t('rate'), t('short'), t('requests'), t('dispatchPass')].map((label, i) => h('th', { class: i > 2 ? 'num' : '' }, label)))),
238
+ h('tbody', null, body)),
239
+ toggle,
240
+ data.speed.warnings.length ? h('ul', { class: 'muted small' }, data.speed.warnings.map((w) => h('li', null, w))) : null);
241
+ }
242
+
243
+ // ---- Tab 3:验收评分与派发审计 ----
244
+ function renderScores() {
245
+ const { cells, minSamples } = data.scores;
246
+ const intervalBar = (cell) => (cell.interval90
247
+ ? h('div', { class: 'ci' }, h('div', { class: 'ci-range', style: `left:${cell.interval90[0] * 100}%;width:${(cell.interval90[1] - cell.interval90[0]) * 100}%` }),
248
+ h('div', { class: 'ci-dot', style: `left:${cell.passRate * 100}%` }))
249
+ : h('span', { class: 'muted' }, t('trial')));
250
+ const scoreRows = cells.map((cell) => h('tr', null,
251
+ h('td', null, cell.identity), h('td', null, cell.task),
252
+ h('td', { class: 'num strong' }, cell.passRate === null ? `${t('trial')} (<${minSamples})` : pct(cell.passRate * 100, 1)),
253
+ h('td', { class: 'ci-cell' }, intervalBar(cell)),
254
+ h('td', { class: 'num' }, `${cell.n} (${cell.s}/${cell.f})`),
255
+ h('td', { class: 'num' }, num(cell.durationMedianMin)),
256
+ h('td', { class: 'num' }, cell.costMedian === null ? EM_DASH : `${cell.costCurrency} ${cell.costMedian.toFixed(2)}`)));
257
+ const scoresTable = cells.length
258
+ ? h('table', null, h('thead', null, h('tr', null, [t('identity'), t('task'), t('passRate'), t('interval'), t('n'), t('duration'), t('cost')].map((l, i) => h('th', { class: i > 1 && i !== 3 ? 'num' : '' }, l)))), h('tbody', null, scoreRows))
259
+ : h('p', { class: 'empty' }, t('noScores'));
260
+
261
+ const decision = data.decision;
262
+ const audit = decision
263
+ ? h('div', null,
264
+ h('p', null, h('strong', null, `${t('action')}: ${decision.action}`),
265
+ decision.recommended ? ` → ${decision.recommended.instanceId} / ${decision.recommended.model}` : '',
266
+ h('span', { class: 'muted' }, ` · slot=${decision.slot} task=${decision.task}${decision.tier ? ` tier=${decision.tier}` : ''}`)),
267
+ h('table', null,
268
+ h('thead', null, h('tr', null, [t('candidate'), t('quota'), t('quality'), t('eligible'), t('speed'), t('pace'), t('notes')].map((l, i) => h('th', { class: i > 3 && i < 6 ? 'num' : '' }, l)))),
269
+ h('tbody', null, decision.candidates.map((c) => h('tr', { class: c.eligible ? '' : 'dim' },
270
+ h('td', null, `${c.candidateId} (${c.instanceId}/${c.model})`), h('td', null, c.quotaState), h('td', null, c.qualityTier ?? EM_DASH),
271
+ h('td', null, c.eligible ? t('yes') : t('no')), h('td', { class: 'num' }, num(c.speedLongRate)), h('td', { class: 'num' }, num(c.paceScore, 2)),
272
+ h('td', { class: 'small' }, [...c.rejectionReasons, ...c.warnings].join('; ')))))))
273
+ : h('p', { class: 'empty' }, t('noDecision'));
274
+ return h('div', null, h('p', { class: 'muted' }, t('scoresHint')), scoresTable, h('h3', { class: 'section' }, t('audit')), audit);
275
+ }
276
+
277
+ // ---- 分享图 ----
278
+ const shareDefaults = () => {
279
+ const candidates = data.speed.ranking.filter((row) => row.longRate !== null);
280
+ const solid = candidates.filter((row) => !row.lowSample);
281
+ return new Set((solid.length ? solid : candidates).map(rowKey));
282
+ };
283
+ function readChoices() {
284
+ try { return JSON.parse(store.get(KEY_ROWS) ?? '{}') ?? {}; } catch { return {}; }
285
+ }
286
+ function shareOptions() {
287
+ const candidates = data.speed.ranking.filter((row) => row.longRate !== null);
288
+ const defaults = shareDefaults();
289
+ const choices = readChoices();
290
+ const options = candidates.map((row) => ({ row, key: rowKey(row), checked: choices[rowKey(row)] ?? defaults.has(rowKey(row)) }));
291
+ return options.some((o) => o.checked) ? options : options.map((o) => ({ ...o, checked: defaults.has(o.key) }));
292
+ }
293
+ function buildShare(options) {
294
+ const chosen = options.filter((o) => o.checked).map((o) => o.row);
295
+ const hidden = data.speed.ranking.filter((row) => !chosen.includes(row));
296
+ const rows = chosen.map((row, index) => ({
297
+ rank: index + 1, name: rowName(row), channel: channelOf(row.provider), color: vendorOf(row.model).color,
298
+ rate: row.longRate, thin: row.lowSample, dispatch: row.dispatch ? passText(row) : null,
299
+ }));
300
+ const present = new Set(chosen.map((row) => vendorOf(row.model).name));
301
+ const maxRate = Math.max(0, ...rows.map((row) => row.rate));
302
+ const steps = [10, 20, 50, 100, 200, 500, 1000, 2000];
303
+ const step = steps.find((s) => Math.ceil(maxRate / s) <= 5) ?? 2000;
304
+ const max = Math.max(maxRate * 1.05, step);
305
+ const ticks = [];
306
+ for (let tick = 0; tick <= max; tick += step) ticks.push(tick);
307
+ const showDispatch = rows.some((row) => row.dispatch !== null);
308
+ const period = `${data.speed.sinceDay}${t('periodJoin')}${data.speed.untilDay}`;
309
+ return {
310
+ rows, showDispatch, axis: { max, ticks }, vendors: VENDOR_ORDER.filter((v) => present.has(v.name)),
311
+ title: t('shareTitleText'),
312
+ subtitle: t('shareSubtitle')(period, hidden.length ? t('shareOmitted')(hidden.length, hidden.every((row) => row.lowSample)) : ''),
313
+ thinKey: rows.some((row) => row.thin) ? t('shareThin') : null,
314
+ noDispatchKey: showDispatch && rows.some((row) => row.dispatch === null) ? `${EM_DASH}: ${t('shareNoDispatch')}` : null,
315
+ notes: [t('shareNoteSpeed'), ...(showDispatch ? [t('shareNotePass')] : []), t('shareNoteChannel')],
316
+ brand: t('shareBrand'), headerRate: t('shareHeaderRate'), headerPass: t('shareHeaderPass'),
317
+ };
318
+ }
319
+
320
+ const W = 1200, SCALE = 2, PAD = 60, ROW_H = 58;
321
+ const FONT = '-apple-system, system-ui, "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Segoe UI", "Microsoft YaHei", sans-serif';
322
+ const RANK_R = PAD + 30, NAME_R = RANK_R + 16 + 290, TRACK_L = NAME_R + 16, TRACK_W = 528;
323
+ const RATE_R = TRACK_L + TRACK_W + 16 + 72, PASS_R = RATE_R + 16 + 96, CONTENT_W = W - PAD * 2;
324
+ const WORD = /[(「『《【]*(?:[ -鿿＀-￯]|[^\s -鿿＀-￯]+)[,。、;:)」』》】!?]*\s*/g;
325
+
326
+ function wrap(measure, text, maxWidth) {
327
+ const lines = [];
328
+ let line = '';
329
+ for (const piece of text.match(WORD) ?? []) {
330
+ if (line !== '' && measure((line + piece).trimEnd()) > maxWidth) { lines.push(line.trimEnd()); line = piece.trimStart(); } else line += piece;
331
+ }
332
+ if (line !== '') lines.push(line.trimEnd());
333
+ return lines;
334
+ }
335
+ function alpha(color, a) {
336
+ const v = Number.parseInt(color.slice(1), 16);
337
+ return `rgba(${(v >> 16) & 255}, ${(v >> 8) & 255}, ${v & 255}, ${a})`;
338
+ }
339
+ function hatch(ctx, x, y, w, hgt, color) {
340
+ const length = (w + hgt) * Math.SQRT1_2;
341
+ const cx = x + w / 2, cy = y + hgt / 2, dx = Math.SQRT1_2 * (length / 2);
342
+ const g = ctx.createLinearGradient(cx - dx, cy + dx, cx + dx, cy - dx);
343
+ for (let at = 0; at < length; at += 11) {
344
+ g.addColorStop(at / length, color);
345
+ g.addColorStop(Math.min(1, (at + 6) / length), color);
346
+ if ((at + 6) / length < 1) {
347
+ g.addColorStop(Math.min(1, (at + 6) / length), 'rgba(0,0,0,0)');
348
+ g.addColorStop(Math.min(1, (at + 11) / length), 'rgba(0,0,0,0)');
349
+ }
350
+ }
351
+ ctx.fillStyle = g;
352
+ ctx.fillRect(x, y, w, hgt);
353
+ }
354
+ function drawShare(ctx, s, height) {
355
+ const text = (value, x, cy, { size, weight = 400, color, spacing = 0 }, align = 'left') => {
356
+ ctx.font = `${weight} ${size}px ${FONT}`; ctx.fillStyle = color; ctx.textAlign = align; ctx.textBaseline = 'middle';
357
+ ctx.letterSpacing = `${spacing}px`; ctx.fillText(value, x, cy);
358
+ return ctx.measureText(value).width;
359
+ };
360
+ const measure = (value, size, weight = 400) => { ctx.font = `${weight} ${size}px ${FONT}`; ctx.letterSpacing = '0px'; return ctx.measureText(value).width; };
361
+ ctx.fillStyle = '#0d0f13'; ctx.fillRect(0, 0, W, height);
362
+ ctx.save(); ctx.translate(W * 0.15, -50); ctx.scale(1, 500 / 1200);
363
+ const glow = ctx.createRadialGradient(0, 0, 0, 0, 0, 1200);
364
+ glow.addColorStop(0, '#1a2233'); glow.addColorStop(0.6, 'rgba(26, 34, 51, 0)');
365
+ ctx.fillStyle = glow; ctx.fillRect(-W, -1200, W * 3, 2400 + height * 3); ctx.restore();
366
+
367
+ let y = 52;
368
+ const badgeW = measure('modelpace', 14) + 26;
369
+ ctx.strokeStyle = '#2c3445'; ctx.lineWidth = 1; ctx.beginPath(); ctx.roundRect(PAD + 0.5, y + 0.5, badgeW - 1, 26, 13); ctx.stroke();
370
+ text('modelpace', PAD + 13, y + 13.5, { size: 14, color: '#aab4c6', spacing: 0.6 });
371
+ y += 43;
372
+ text(s.title, PAD, y + 24, { size: 40, weight: 700, color: '#e9ecf1', spacing: 0.3 });
373
+ y += 58;
374
+ for (const line of wrap((v) => measure(v, 18), s.subtitle, CONTENT_W)) { text(line, PAD, y + 11, { size: 18, color: '#9aa3b2' }); y += 22; }
375
+ y += 22;
376
+ let x = PAD;
377
+ for (const vendor of s.vendors) {
378
+ ctx.fillStyle = vendor.color; ctx.beginPath(); ctx.roundRect(x, y + 3.5, 12, 12, 3); ctx.fill();
379
+ x += 19; x += text(vendor.name, x, y + 9.5, { size: 16, color: '#c7cdd8' }) + 22;
380
+ }
381
+ y += 45;
382
+ for (const tick of s.axis.ticks) text(String(tick), TRACK_L + (tick / s.axis.max) * TRACK_W, y + 12, { size: 13, color: '#7d8697' }, 'center');
383
+ text(s.headerRate, RATE_R, y + 13, { size: 13, color: '#7d8697' }, 'right');
384
+ if (s.showDispatch) text(s.headerPass, PASS_R, y + 13, { size: 13, color: '#7d8697' }, 'right');
385
+ y += 26;
386
+ const top0 = y, bottom0 = y + s.rows.length * ROW_H;
387
+ ctx.fillStyle = '#232834';
388
+ for (const tick of s.axis.ticks) if (tick > 0) ctx.fillRect(TRACK_L + (tick / s.axis.max) * TRACK_W - 0.5, top0, 1, bottom0 - top0);
389
+ for (const row of s.rows) {
390
+ const top = y + 6;
391
+ text(String(row.rank), RANK_R, y + 29, { size: 17, color: '#5f6779' }, 'right');
392
+ text(row.name, NAME_R, top + 12, { size: 20, color: '#dfe3ea' }, 'right');
393
+ const chipW = measure(row.channel.label, 12.5, 600) + 14, chipX = NAME_R - chipW;
394
+ ctx.beginPath(); ctx.roundRect(chipX, top + 28, chipW, 18, 5); ctx.fillStyle = alpha(row.channel.color, 0.12); ctx.fill();
395
+ ctx.strokeStyle = alpha(row.channel.color, 0.55); ctx.lineWidth = 1; ctx.beginPath(); ctx.roundRect(chipX + 0.5, top + 28.5, chipW - 1, 17, 4.5); ctx.stroke();
396
+ text(row.channel.label, chipX + 7, top + 37.5, { size: 12.5, weight: 600, color: row.channel.color });
397
+ const barW = (row.rate / s.axis.max) * TRACK_W;
398
+ ctx.save(); ctx.beginPath(); ctx.roundRect(TRACK_L, y + 17, barW, 24, [0, 6, 6, 0]);
399
+ if (row.thin) {
400
+ ctx.clip(); hatch(ctx, TRACK_L, y + 17, barW, 24, row.color); ctx.restore();
401
+ ctx.strokeStyle = row.color; ctx.lineWidth = 1.5; ctx.beginPath(); ctx.roundRect(TRACK_L + 0.75, y + 17.75, barW - 1.5, 22.5, [0, 5.25, 5.25, 0]); ctx.stroke();
402
+ } else { ctx.fillStyle = row.color; ctx.fill(); ctx.restore(); }
403
+ text(row.rate.toFixed(1), RATE_R, y + 29, { size: 21, weight: 700, color: '#e9ecf1' }, 'right');
404
+ if (s.showDispatch) text(row.dispatch ?? EM_DASH, PASS_R, y + 29, { size: 17, color: '#aeb6c4' }, 'right');
405
+ y += ROW_H;
406
+ }
407
+ y += 26; ctx.fillStyle = '#232834'; ctx.fillRect(PAD, y, CONTENT_W, 1); y += 19;
408
+ const lh = 26.25;
409
+ const keys = [s.thinKey, s.noDispatchKey].filter(Boolean);
410
+ if (keys.length) { let kx = PAD; for (const key of keys) kx += text(key, kx, y + lh / 2, { size: 15, color: '#b5bcc8' }) + 22; y += lh + 6; }
411
+ for (const note of s.notes) for (const line of wrap((v) => measure(v, 15), note, CONTENT_W)) { text(line, PAD, y + lh / 2, { size: 15, color: '#8a93a3' }); y += lh; }
412
+ y += 12; text(s.brand, PAD, y + lh / 2, { size: 15, color: '#c5ccd8' }); y += lh;
413
+ return y + 40;
414
+ }
415
+ function renderShareBlob(share) {
416
+ const scratch = document.createElement('canvas').getContext('2d');
417
+ const height = Math.ceil(drawShare(scratch, share, 0));
418
+ const canvas = document.createElement('canvas');
419
+ canvas.width = W * SCALE; canvas.height = height * SCALE;
420
+ const ctx = canvas.getContext('2d');
421
+ ctx.scale(SCALE, SCALE);
422
+ drawShare(ctx, share, height);
423
+ return new Promise((resolve, reject) => canvas.toBlob((b) => (b ? resolve(b) : reject(new Error('encode'))), 'image/png'));
424
+ }
425
+
426
+ function openShare() { modal = { status: '' }; render(); updateShare(); }
427
+ async function updateShare() {
428
+ if (!modal) return;
429
+ const options = shareOptions();
430
+ const share = buildShare(options);
431
+ const holder = document.getElementById('t3d-share-preview');
432
+ if (!holder) return;
433
+ holder.textContent = '';
434
+ if (!share.rows.length) { holder.append(h('p', { class: 'empty' }, t('noRows'))); modal.blob = null; return; }
435
+ modal.blob = await renderShareBlob(share);
436
+ modal.url && URL.revokeObjectURL(modal.url);
437
+ modal.url = URL.createObjectURL(modal.blob);
438
+ holder.append(h('img', { src: modal.url, alt: share.title, class: 'share-img' }));
439
+ }
440
+ function setChoice(key, checked) {
441
+ const choices = readChoices();
442
+ choices[key] = checked;
443
+ store.set(KEY_ROWS, JSON.stringify(choices));
444
+ const list = shareOptions();
445
+ if (!list.some((o) => o.checked)) { choices[key] = true; store.set(KEY_ROWS, JSON.stringify(choices)); }
446
+ render(); updateShare();
447
+ }
448
+ function renderModal() {
449
+ const options = shareOptions();
450
+ const onlyOne = options.filter((o) => o.checked).length === 1;
451
+ const close = () => { if (modal.url) URL.revokeObjectURL(modal.url); modal = null; render(); };
452
+ return h('div', { class: 'modal-back', onclick: (e) => { if (e.target === e.currentTarget) close(); } },
453
+ h('div', { class: 'modal', role: 'dialog', 'aria-modal': 'true', 'aria-label': t('shareTitle') },
454
+ h('div', { class: 'modal-head' }, h('h3', null, t('shareTitle')),
455
+ h('div', { class: 'seg' }, ['en', 'zh'].map((code) => h('button', { class: code === lang ? 'on' : '', onclick: () => setLang(code) }, code.toUpperCase()))),
456
+ h('button', { class: 'btn', onclick: close }, t('close'))),
457
+ h('div', { class: 'modal-body' },
458
+ h('div', { class: 'picker' }, h('div', { class: 'muted small' }, t('rows')),
459
+ options.map((o) => h('label', { class: 'pick' },
460
+ h('input', { type: 'checkbox', checked: o.checked, disabled: onlyOne && o.checked, onchange: (e) => setChoice(o.key, e.target.checked) }),
461
+ h('span', null, `${rowName(o.row)} · ${channelOf(o.row.provider).label} (${o.row.longRequests})`)))),
462
+ h('div', { id: 't3d-share-preview', class: 'preview' })),
463
+ h('div', { class: 'modal-foot' },
464
+ h('span', { class: 'muted small' }, modal.status),
465
+ h('button', { class: 'btn', onclick: copyShare }, t('copy')),
466
+ h('button', { class: 'btn primary', onclick: downloadShare }, t('download')))));
467
+ }
468
+ function downloadShare() {
469
+ if (!modal?.blob) return;
470
+ const a = h('a', { href: modal.url, download: `model-speed-${data.speed.untilDay}-${lang}.png` });
471
+ document.body.append(a); a.click(); a.remove();
472
+ }
473
+ async function copyShare() {
474
+ if (!modal?.blob) return;
475
+ let status = t('copied');
476
+ try { await navigator.clipboard.write([new ClipboardItem({ 'image/png': modal.blob })]); } catch { status = t('copyFailed'); }
477
+ modal.status = status;
478
+ const foot = document.querySelector('.modal-foot .muted');
479
+ if (foot) foot.textContent = status;
480
+ }
481
+
482
+ // ---- 外壳 ----
483
+ function setLang(code) {
484
+ lang = code; store.set(KEY_LANG, lang);
485
+ document.documentElement.lang = lang;
486
+ render(); updateShare();
487
+ }
488
+ function render() {
489
+ document.title = t('title');
490
+ const tabs = [['quota', 'tabQuota'], ['speed', 'tabSpeed'], ['scores', 'tabScores']];
491
+ const views = { quota: renderQuota, speed: renderSpeed, scores: renderScores };
492
+ root.replaceChildren(
493
+ h('header', { class: 'top' },
494
+ h('h1', null, t('title')),
495
+ h('span', { class: 'muted small' }, `${t('generated')} ${data.generatedAt.slice(0, 19).replace('T', ' ')} UTC`),
496
+ h('div', { class: 'seg lang' }, ['en', 'zh'].map((code) => h('button', { class: code === lang ? 'on' : '', onclick: () => setLang(code) }, code.toUpperCase())))),
497
+ h('nav', { class: 'tabs', role: 'tablist' }, tabs.map(([id, key]) => h('button', {
498
+ role: 'tab', 'aria-selected': id === tab ? 'true' : 'false', class: id === tab ? 'on' : '',
499
+ onclick: () => { tab = id; store.set(KEY_TAB, id); render(); },
500
+ }, t(key)))),
501
+ h('main', { role: 'tabpanel' }, views[tab]()),
502
+ ...(modal ? [renderModal()] : []));
503
+ }
504
+
505
+ render();
506
+ if (data.live) {
507
+ // 独立服务走 fetch;在宿主插件视图里没有同源接口,改经桥取数。
508
+ const fetchData = async () => {
509
+ if (globalThis.t3dBridgeCall) return globalThis.t3dBridgeCall('data');
510
+ const response = await fetch('api/data', { cache: 'no-store' });
511
+ if (!response.ok) throw new Error('refresh failed');
512
+ return response.json();
513
+ };
514
+ setInterval(async () => {
515
+ if (modal) return;
516
+ try {
517
+ data = await fetchData();
518
+ render();
519
+ } catch { /* 服务暂不可达时保留当前画面 */ }
520
+ }, 15000);
521
+ }
522
+ })();
@@ -0,0 +1,106 @@
1
+ :root {
2
+ --c-bg: var(--background, #f6f7f9);
3
+ --c-fg: var(--foreground, #171a20);
4
+ --c-card: var(--card, #ffffff);
5
+ --c-border: var(--border, #dde1e8);
6
+ --c-muted: var(--muted-foreground, #667085);
7
+ --c-accent: var(--primary, #2f6df6);
8
+ --c-ok: var(--success, #1a9d6c);
9
+ --c-warn: var(--warning, #d99a1b);
10
+ --c-bad: var(--destructive, #d4493f);
11
+ --c-track: rgba(120, 130, 150, 0.18);
12
+ color-scheme: light dark;
13
+ }
14
+ @media (prefers-color-scheme: dark) {
15
+ :root:not([data-theme='light']) {
16
+ --c-bg: var(--background, #0f1115);
17
+ --c-fg: var(--foreground, #e7eaf0);
18
+ --c-card: var(--card, #171a21);
19
+ --c-border: var(--border, #2a2f3a);
20
+ --c-muted: var(--muted-foreground, #98a2b3);
21
+ --c-accent: var(--primary, #6b9bff);
22
+ --c-track: rgba(150, 160, 180, 0.2);
23
+ }
24
+ }
25
+ :root[data-theme='dark'] {
26
+ --c-bg: var(--background, #0f1115);
27
+ --c-fg: var(--foreground, #e7eaf0);
28
+ --c-card: var(--card, #171a21);
29
+ --c-border: var(--border, #2a2f3a);
30
+ --c-muted: var(--muted-foreground, #98a2b3);
31
+ --c-accent: var(--primary, #6b9bff);
32
+ --c-track: rgba(150, 160, 180, 0.2);
33
+ }
34
+ * { box-sizing: border-box; }
35
+ body {
36
+ margin: 0;
37
+ background: var(--c-bg);
38
+ color: var(--c-fg);
39
+ font: 14px/1.5 -apple-system, system-ui, 'SF Pro Text', 'PingFang SC', 'Segoe UI', 'Microsoft YaHei', sans-serif;
40
+ }
41
+ #t3d-root { max-width: 1100px; margin: 0 auto; padding: 16px; }
42
+ .top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
43
+ .top h1 { font-size: 18px; margin: 0; flex: 1; }
44
+ .muted { color: var(--c-muted); }
45
+ .small { font-size: 12px; }
46
+ .strong { font-weight: 600; }
47
+ .empty { color: var(--c-muted); padding: 24px 0; }
48
+ .tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--c-border); margin: 12px 0 16px; overflow-x: auto; }
49
+ .tabs button { background: none; border: 0; border-bottom: 2px solid transparent; color: var(--c-muted); padding: 8px 12px; cursor: pointer; font: inherit; white-space: nowrap; }
50
+ .tabs button.on { color: var(--c-fg); border-bottom-color: var(--c-accent); }
51
+ .seg { display: inline-flex; border: 1px solid var(--c-border); border-radius: 6px; overflow: hidden; }
52
+ .seg button { background: none; border: 0; padding: 3px 10px; color: var(--c-muted); cursor: pointer; font: inherit; font-size: 12px; }
53
+ .seg button.on { background: var(--c-accent); color: #fff; }
54
+ .btn { background: var(--c-card); border: 1px solid var(--c-border); color: var(--c-fg); border-radius: 6px; padding: 5px 12px; cursor: pointer; font: inherit; }
55
+ .btn.primary { background: var(--c-accent); border-color: var(--c-accent); color: #fff; }
56
+ .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
57
+ .card { background: var(--c-card); border: 1px solid var(--c-border); border-radius: 10px; padding: 12px 14px; }
58
+ .card header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
59
+ .card h3 { margin: 0; font-size: 15px; flex: 1; }
60
+ .status { font-size: 11px; padding: 1px 6px; border-radius: 10px; background: var(--c-track); }
61
+ .status-ready { color: var(--c-ok); }
62
+ .win { margin: 10px 0; }
63
+ .win-head, .win-foot { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; }
64
+ .win-label { font-weight: 600; }
65
+ .win-meta, .win-foot { color: var(--c-muted); }
66
+ .tag { margin-left: 6px; font-size: 11px; font-weight: 400; color: var(--c-muted); border: 1px solid var(--c-border); border-radius: 4px; padding: 0 4px; }
67
+ .bar { position: relative; height: 10px; border-radius: 5px; background: var(--c-track); margin: 4px 0; }
68
+ .bar-fill { height: 100%; border-radius: 5px; background: var(--c-ok); }
69
+ .pace-conserve .bar-fill, .bar.pace-conserve .bar-fill { background: var(--c-bad); }
70
+ .bar.pace-balanced .bar-fill { background: var(--c-warn); }
71
+ .even-pace { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--c-fg); opacity: 0.75; transform: translateX(-1px); }
72
+ .pace-text.pace-surplus { color: var(--c-ok); }
73
+ .pace-text.pace-balanced { color: var(--c-warn); }
74
+ .pace-text.pace-conserve { color: var(--c-bad); }
75
+ .credits { margin-top: 8px; font-size: 12px; }
76
+ .toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
77
+ table { width: 100%; border-collapse: collapse; margin: 8px 0; }
78
+ th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--c-border); vertical-align: middle; }
79
+ th { font-size: 12px; font-weight: 500; color: var(--c-muted); }
80
+ .num { text-align: right; font-variant-numeric: tabular-nums; }
81
+ .dim { opacity: 0.55; }
82
+ .chip { display: inline-block; font-size: 11px; border: 1px solid; border-radius: 4px; padding: 0 5px; margin-top: 2px; }
83
+ .bar-cell { width: 34%; }
84
+ .speed-bar { height: 16px; border-radius: 0 6px 6px 0; background: var(--c); min-width: 2px; }
85
+ .speed-bar.hatched { background: repeating-linear-gradient(45deg, var(--c) 0 6px, transparent 6px 11px); outline: 1.5px solid var(--c); outline-offset: -1.5px; }
86
+ .ci-cell { width: 20%; }
87
+ .ci { position: relative; height: 8px; border-radius: 4px; background: var(--c-track); }
88
+ .ci-range { position: absolute; top: 0; bottom: 0; background: var(--c-accent); opacity: 0.45; border-radius: 4px; }
89
+ .ci-dot { position: absolute; top: -2px; width: 4px; height: 12px; background: var(--c-fg); transform: translateX(-2px); border-radius: 2px; }
90
+ .section { margin: 20px 0 4px; font-size: 15px; }
91
+ .modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
92
+ .modal { background: var(--c-card); border: 1px solid var(--c-border); border-radius: 12px; width: min(1000px, 100%); max-height: 100%; display: flex; flex-direction: column; }
93
+ .modal-head, .modal-foot { display: flex; align-items: center; gap: 10px; padding: 10px 14px; }
94
+ .modal-head h3 { margin: 0; flex: 1; font-size: 15px; }
95
+ .modal-foot { justify-content: flex-end; border-top: 1px solid var(--c-border); }
96
+ .modal-foot .muted { flex: 1; }
97
+ .modal-body { display: flex; gap: 14px; padding: 0 14px 14px; overflow: auto; min-height: 0; }
98
+ .picker { flex: 0 0 240px; display: flex; flex-direction: column; gap: 4px; }
99
+ .pick { display: flex; gap: 6px; align-items: flex-start; font-size: 12px; }
100
+ .preview { flex: 1; min-width: 0; }
101
+ .share-img { width: 100%; height: auto; border-radius: 6px; border: 1px solid var(--c-border); }
102
+ @media (max-width: 720px) {
103
+ .modal-body { flex-direction: column; }
104
+ .picker { flex-basis: auto; }
105
+ .bar-cell { display: none; }
106
+ }