@fish-under-sea/magpie-dragonapi 0.1.5 → 0.2.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/README.md +45 -8
- package/index.mjs +9 -8
- package/lib/pricing.mjs +132 -6
- package/lib/service.mjs +95 -18
- package/lib/site.mjs +104 -4
- package/lib/store.mjs +18 -6
- package/package.json +1 -1
- package/serve.mjs +5 -2
- package/ui/app.js +882 -165
- package/ui/index.html +42 -20
- package/ui/style.css +676 -99
- package/ui/vendor-icons/ByteDance.svg +1 -0
- package/ui/vendor-icons/Claude.Color.svg +1 -0
- package/ui/vendor-icons/DeepSeek.Color.svg +1 -0
- package/ui/vendor-icons/Flux.svg +1 -0
- package/ui/vendor-icons/Gemini.Color.svg +1 -0
- package/ui/vendor-icons/Hunyuan.Color.svg +1 -0
- package/ui/vendor-icons/Ideogram.svg +1 -0
- package/ui/vendor-icons/Jimeng.Color.svg +1 -0
- package/ui/vendor-icons/Midjourney.svg +1 -0
- package/ui/vendor-icons/Minimax.Color.svg +1 -0
- package/ui/vendor-icons/Moonshot.svg +1 -0
- package/ui/vendor-icons/OpenAI.svg +1 -0
- package/ui/vendor-icons/Qwen.Color.svg +1 -0
- package/ui/vendor-icons/XAI.svg +1 -0
- package/ui/vendor-icons/XiaomiMiMo.svg +1 -0
- package/ui/vendor-icons/Zhipu.Color.svg +1 -0
package/ui/app.js
CHANGED
|
@@ -206,8 +206,14 @@ async function request(path, { method = 'GET', body } = {}) {
|
|
|
206
206
|
cache: 'no-store', // 服务端已经自己缓存目录,浏览器别再叠一层
|
|
207
207
|
headers: body ? { 'content-type': 'application/json' } : undefined,
|
|
208
208
|
body: body ? JSON.stringify(body) : undefined,
|
|
209
|
+
// 必须自己设上限:保存 PAT 要串行探三个站点端点,站点半死不活时
|
|
210
|
+
// 没有信号就会一直转圈,用户看到的是「点了没反应」。
|
|
211
|
+
signal: AbortSignal.timeout(45000),
|
|
209
212
|
});
|
|
210
213
|
} catch (err) {
|
|
214
|
+
if (err && (err.name === 'TimeoutError' || err.name === 'AbortError')) {
|
|
215
|
+
throw new ApiError('本地服务 45 秒没有返回:站点可能卡住了,稍后再试;如果一直这样,检查一下网络或代理。', 0, null);
|
|
216
|
+
}
|
|
211
217
|
// 网络层失败(服务没起来 / 端口变了)统一成一句人话
|
|
212
218
|
throw new ApiError('连不上本地服务,插件可能已经退出,或端口被改了。', 0, null);
|
|
213
219
|
}
|
|
@@ -322,8 +328,33 @@ function fmtInt(n) {
|
|
|
322
328
|
return Number.isFinite(n) ? n.toLocaleString('zh-CN') : '—';
|
|
323
329
|
}
|
|
324
330
|
|
|
331
|
+
/**
|
|
332
|
+
* fmtRatio 统一两位小数:0.1 → 0.10×、1.2 → 1.20×。
|
|
333
|
+
*
|
|
334
|
+
* 定长不只是好看——分组列表里一排胶囊的倍率标签宽度一致,右边的组名才能对齐成一条线。
|
|
335
|
+
*/
|
|
325
336
|
function fmtRatio(r) {
|
|
326
|
-
|
|
337
|
+
const n = Number(r);
|
|
338
|
+
return Number.isFinite(n) ? `${n.toFixed(2)}×` : '—';
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* ratioLevel 给倍率配一个色档,照 neartoken 那种「小标签」的配色:
|
|
343
|
+
* 便宜偏绿、中间偏蓝、偏贵偏红。同一个倍率在任何地方都是同一个颜色。
|
|
344
|
+
*/
|
|
345
|
+
function ratioLevel(r) {
|
|
346
|
+
const n = Number(r);
|
|
347
|
+
if (!Number.isFinite(n) || n <= 0) return 'plain';
|
|
348
|
+
if (n < 0.3) return 'green';
|
|
349
|
+
if (n < 1) return 'blue';
|
|
350
|
+
if (n < 2) return 'gold';
|
|
351
|
+
return 'red';
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/** ratioTag 就是 neartoken 的「低价」小胶囊:白字、圆角 4px、一圈淡描边。 */
|
|
355
|
+
function ratioTag(r, extraClass = '') {
|
|
356
|
+
const text = Number(r) > 0 ? fmtRatio(r) : 'auto';
|
|
357
|
+
return h('span', { class: `gb-tag ${ratioLevel(r)} ${extraClass}`.trim(), text });
|
|
327
358
|
}
|
|
328
359
|
|
|
329
360
|
/** 把服务端给的原始 quota 折成站点币种;金额本身仍优先用服务端格式化好的字符串。 */
|
|
@@ -363,7 +394,7 @@ const cache = {
|
|
|
363
394
|
|
|
364
395
|
const loading = { state: false, catalog: false, keys: false, bind: false, health: false, usage: false, logs: false };
|
|
365
396
|
|
|
366
|
-
const filters = { group: '', kind: '', q: '', range: 'day', account: '' };
|
|
397
|
+
const filters = { category: '', group: '', vendor: '', kind: '', q: '', unit: 'M', sort: 'latest', view: 'grid', range: 'day', account: '' };
|
|
367
398
|
|
|
368
399
|
let activeTab = 'catalog';
|
|
369
400
|
|
|
@@ -538,6 +569,215 @@ function catalogCounts(data) {
|
|
|
538
569
|
};
|
|
539
570
|
}
|
|
540
571
|
|
|
572
|
+
// ── 厂商图标 ──────────────────────────────────────────────
|
|
573
|
+
//
|
|
574
|
+
// 图标来自同一作者的 magpie-neartoken 仓库(ui/vendor-icons/,MIT),
|
|
575
|
+
// 按厂商名做**包含式**匹配:站点的厂商名是中文与英文混着的(「阿里云」
|
|
576
|
+
// 「字节跳动」「Black Forest Labs」),精确匹配只能命中一小半。
|
|
577
|
+
//
|
|
578
|
+
// 匹配不到就退回首字母方块——宁可少一张图,也不要一个破图占位。
|
|
579
|
+
const VENDOR_ICONS = [
|
|
580
|
+
[/openai/i, 'OpenAI.svg'],
|
|
581
|
+
[/anthropic|claude|kiro/i, 'Claude.Color.svg'],
|
|
582
|
+
[/google|gemini|巴德/i, 'Gemini.Color.svg'],
|
|
583
|
+
[/deepseek|深度求索/i, 'DeepSeek.Color.svg'],
|
|
584
|
+
[/阿里|qwen|通义|千问/i, 'Qwen.Color.svg'],
|
|
585
|
+
[/moonshot|kimi|月之暗面/i, 'Moonshot.svg'],
|
|
586
|
+
[/xai|grok/i, 'XAI.svg'],
|
|
587
|
+
[/智谱|zhipu|glm/i, 'Zhipu.Color.svg'],
|
|
588
|
+
[/minimax|海螺/i, 'Minimax.Color.svg'],
|
|
589
|
+
[/字节|bytedance|豆包|doubao/i, 'ByteDance.svg'],
|
|
590
|
+
[/即梦|jimeng/i, 'Jimeng.Color.svg'],
|
|
591
|
+
[/ideogram/i, 'Ideogram.svg'],
|
|
592
|
+
[/midjourney/i, 'Midjourney.svg'],
|
|
593
|
+
[/black forest|flux/i, 'Flux.svg'],
|
|
594
|
+
[/腾讯|hunyuan|混元/i, 'Hunyuan.Color.svg'],
|
|
595
|
+
[/小米|mimo/i, 'XiaomiMiMo.svg'],
|
|
596
|
+
];
|
|
597
|
+
|
|
598
|
+
function vendorIconFile(name) {
|
|
599
|
+
const s = String(name || '');
|
|
600
|
+
if (!s) return '';
|
|
601
|
+
for (const [re, file] of VENDOR_ICONS) if (re.test(s)) return file;
|
|
602
|
+
return '';
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* vendorBadge 造一个 16px 的厂商标记:有图标用 <img>,没有就用首字母。
|
|
607
|
+
*
|
|
608
|
+
* 图标加载失败时把 img 换成字母块——静态托管里少一个 svg 时,页面上
|
|
609
|
+
* 不该出现一个碎图图标。
|
|
610
|
+
*/
|
|
611
|
+
function vendorBadge(name, { size = 16, cls = '' } = {}) {
|
|
612
|
+
const file = vendorIconFile(name);
|
|
613
|
+
const label = String(name || '').trim();
|
|
614
|
+
if (!file) {
|
|
615
|
+
return h('span', { class: `vendor-letter ${cls}`.trim(), 'aria-hidden': 'true', text: label.slice(0, 1).toUpperCase() || '?' });
|
|
616
|
+
}
|
|
617
|
+
const img = h('img', {
|
|
618
|
+
class: `vendor-icon ${cls}`.trim(),
|
|
619
|
+
src: 'vendor-icons/' + file,
|
|
620
|
+
alt: '',
|
|
621
|
+
width: size,
|
|
622
|
+
height: size,
|
|
623
|
+
loading: 'lazy',
|
|
624
|
+
});
|
|
625
|
+
img.addEventListener('error', () => {
|
|
626
|
+
img.replaceWith(h('span', { class: `vendor-letter ${cls}`.trim(), 'aria-hidden': 'true', text: label.slice(0, 1).toUpperCase() || '?' }));
|
|
627
|
+
}, { once: true });
|
|
628
|
+
return img;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
|
|
632
|
+
// ── 分组归类 ──────────────────────────────────────────────
|
|
633
|
+
//
|
|
634
|
+
// 站点的分组名是渠道商随便起的(gpt-promax、claude-kiro正价、国模-原厂…),
|
|
635
|
+
// 直接平铺 14 个 chip 很难找。这里按「厂商家族」归成 7 类,侧栏按
|
|
636
|
+
// claude → gpt → gemini → grok → 国模 → image → video 的顺序展示,
|
|
637
|
+
// 每类下面才是它的分组(前面带倍率)。
|
|
638
|
+
//
|
|
639
|
+
// 「国模」是一个聚合类:DeepSeek / Qwen / Moonshot / 智谱 / 字节… 都算,
|
|
640
|
+
// 所以这一类的下面是**多厂商并列**的厂商 chip,再下面是分组。
|
|
641
|
+
const CATEGORY_ORDER = ['claude', 'gpt', 'gemini', 'grok', 'guomo', 'image', 'video', 'other'];
|
|
642
|
+
const CATEGORY_META = {
|
|
643
|
+
claude: { title: 'Claude', icon: 'Claude.Color.svg' },
|
|
644
|
+
gpt: { title: 'GPT', icon: 'OpenAI.svg' },
|
|
645
|
+
gemini: { title: 'Gemini', icon: 'Gemini.Color.svg' },
|
|
646
|
+
grok: { title: 'Grok', icon: 'XAI.svg' },
|
|
647
|
+
guomo: { title: '国模', icon: '' },
|
|
648
|
+
image: { title: 'Image', icon: '' },
|
|
649
|
+
video: { title: 'Video', icon: '' },
|
|
650
|
+
other: { title: '其它', icon: '' },
|
|
651
|
+
};
|
|
652
|
+
// 匹配顺序与展示顺序不同:image / video 要先于「国模」判,否则名字里带
|
|
653
|
+
// 「可灵 / 即梦」这类词的分组会被国模抢走。
|
|
654
|
+
const CATEGORY_TESTS = [
|
|
655
|
+
['image', /image|img|生图|绘图|draw|flux|midjourney|dall|stable|sdxl/i],
|
|
656
|
+
['video', /video|视频|veo|sora|runway|pika|hailuo|可灵|kling|万相|seedance|muse/i],
|
|
657
|
+
['claude', /claude|anthropic|kiro/i],
|
|
658
|
+
['gpt', /gpt|openai|codex|davinci|o[134]\b/i],
|
|
659
|
+
['gemini', /gemini|google|bard/i],
|
|
660
|
+
['grok', /grok|xai/i],
|
|
661
|
+
['guomo', /国模|deepseek|qwen|通义|千问|glm|智谱|moonshot|kimi|月之暗面|豆包|doubao|hunyuan|混元|文心|ernie|百度|baidu|讯飞|spark|minimax|海螺|阶跃|ling|jimeng|即梦|小米|mimo|零一|yi-/i],
|
|
662
|
+
];
|
|
663
|
+
/** 分组显示名:站点的「视频」按你说的改名成 video。 */
|
|
664
|
+
const GROUP_ALIAS = { 视频: 'video' };
|
|
665
|
+
|
|
666
|
+
/** categoryOf 判一个分组属于哪一类;名字判不出来就看它的模型类型。 */
|
|
667
|
+
function categoryOf(groupId, groupModels = []) {
|
|
668
|
+
const id = String(groupId || '');
|
|
669
|
+
for (const [cat, re] of CATEGORY_TESTS) if (re.test(id)) return cat;
|
|
670
|
+
const kinds = groupModels.map((m) => m.kind || 'chat');
|
|
671
|
+
if (kinds.length) {
|
|
672
|
+
if (kinds.every((k) => k === 'image')) return 'image';
|
|
673
|
+
if (kinds.every((k) => k === 'video')) return 'video';
|
|
674
|
+
}
|
|
675
|
+
return 'other';
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
function categoryTitle(catId) {
|
|
679
|
+
return (CATEGORY_META[catId] && CATEGORY_META[catId].title) || catId;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
function iconImg(file, size = 14) {
|
|
683
|
+
const img = h('img', { class: 'cat-icon', src: 'vendor-icons/' + file, alt: '', width: size, height: size, loading: 'lazy' });
|
|
684
|
+
img.addEventListener('error', () => { img.style.display = 'none' }, { once: true });
|
|
685
|
+
return img;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
/** fmtTok 把一个「每百万 token」的数值按当前单位(M/K)印出来。 */
|
|
689
|
+
function fmtTok(num, unit) {
|
|
690
|
+
if (!Number.isFinite(num)) return '—';
|
|
691
|
+
const v = unit === 'K' ? num / 1000 : num;
|
|
692
|
+
// 位数跟站点原来的写法一致:/M 时 ≥0.01 两位、更小四位;/K 再补两位。
|
|
693
|
+
const digits = unit === 'K' ? (v >= 0.01 ? 4 : 6) : (v >= 0.01 ? 2 : 4);
|
|
694
|
+
const cur = cache.state && cache.state.currency;
|
|
695
|
+
return `${(cur && cur.symbol) || '$'}${v.toFixed(digits)}/${unit}`;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
/** 卡片的三个价格格:有数值就按单位换算,没有就退回服务端给的字符串。 */
|
|
699
|
+
function priceCellsOf(pricing, unit) {
|
|
700
|
+
const cell = (label, num, text) => h('div', null,
|
|
701
|
+
h('span', { text: label }),
|
|
702
|
+
h('b', { text: Number.isFinite(num) ? fmtTok(num, unit) : (text || '—') }));
|
|
703
|
+
return [
|
|
704
|
+
cell('输入', pricing.inputNum, pricing.input),
|
|
705
|
+
cell('输出', pricing.outputNum, pricing.output),
|
|
706
|
+
cell('缓存读取', pricing.cacheNum, pricing.cache),
|
|
707
|
+
];
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
/** versionRank 取模型名里的版本号(gpt-6.1-sol → [6,1],deepseek-v4 → [4])。 */
|
|
711
|
+
function versionRank(name) {
|
|
712
|
+
const m = String(name || '').match(/\d+(?:[.-]\d+)*/);
|
|
713
|
+
return m ? m[0].split(/[.-]/).map(Number) : null;
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
/** byLatestVersion 新版本在前;没有版本号的排到最后,同版本按名称。 */
|
|
717
|
+
function byLatestVersion(a, b) {
|
|
718
|
+
const x = versionRank(a.name);
|
|
719
|
+
const y = versionRank(b.name);
|
|
720
|
+
if (x && y) {
|
|
721
|
+
const n = Math.max(x.length, y.length);
|
|
722
|
+
for (let i = 0; i < n; i++) {
|
|
723
|
+
const d = (y[i] || 0) - (x[i] || 0);
|
|
724
|
+
if (d) return d;
|
|
725
|
+
}
|
|
726
|
+
} else if (x) return -1;
|
|
727
|
+
else if (y) return 1;
|
|
728
|
+
return String(a.name).localeCompare(String(b.name), 'zh');
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
/** billingLabel 计费方式的一句话标签(卡片与列表行共用同一套判据)。 */
|
|
732
|
+
function billingLabel(pricing, isAuto, priceKind) {
|
|
733
|
+
const kind = priceKind || (pricing && pricing.kind) || 'unknown';
|
|
734
|
+
if (isAuto) return { cls: 'auto', label: '以实际命中通道为准' };
|
|
735
|
+
if (kind === 'unknown') return { cls: 'unknown', label: '价格未知' };
|
|
736
|
+
if (kind === 'percall') return { cls: 'call', label: /\/秒/.test(pricing.input || '') ? '按秒计费' : '按次计费' };
|
|
737
|
+
if (kind === 'tiered') return { cls: 'dyn', label: '分档计费' };
|
|
738
|
+
return { cls: 'flat', label: '按量计费' };
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
/** fmtTokValue 只给数值(不带单位),列表里单位单独占一行。 */
|
|
742
|
+
function fmtTokValue(num, unit) {
|
|
743
|
+
if (!Number.isFinite(num)) return '—';
|
|
744
|
+
const v = unit === 'K' ? num / 1000 : num;
|
|
745
|
+
const digits = unit === 'K' ? (v >= 0.01 ? 4 : 6) : (v >= 0.01 ? 2 : 4);
|
|
746
|
+
const cur = cache.state && cache.state.currency;
|
|
747
|
+
return `${(cur && cur.symbol) || '$'}${v.toFixed(digits)}`;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
/** 端点 id → 看得懂的名字(站点给的是 openai / openai-response / anthropic 这类内部名)。 */
|
|
751
|
+
const ENDPOINT_LABEL = {
|
|
752
|
+
openai: 'Chat',
|
|
753
|
+
'openai-response': 'Response',
|
|
754
|
+
anthropic: 'Anthropic',
|
|
755
|
+
gemini: 'Gemini',
|
|
756
|
+
'image-generation': '图片',
|
|
757
|
+
'视频任务': '视频',
|
|
758
|
+
'jina-rerank': 'Rerank',
|
|
759
|
+
rerank: 'Rerank',
|
|
760
|
+
embedding: '嵌入',
|
|
761
|
+
audio: '语音',
|
|
762
|
+
tts: '语音合成',
|
|
763
|
+
asr: '语音识别',
|
|
764
|
+
transcription: '转写',
|
|
765
|
+
speech: '语音',
|
|
766
|
+
};
|
|
767
|
+
|
|
768
|
+
function endLabel(e) {
|
|
769
|
+
return ENDPOINT_LABEL[e] || String(e || '');
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
function endpointEls(list, max) {
|
|
773
|
+
const all = Array.isArray(list) ? list : [];
|
|
774
|
+
const shown = typeof max === 'number' ? all.slice(0, max) : all;
|
|
775
|
+
return [
|
|
776
|
+
shown.map((e) => h('span', { class: 'mc-end', text: endLabel(e), title: String(e) })),
|
|
777
|
+
typeof max === 'number' && all.length > max ? h('span', { class: 'mc-end more', text: `+${all.length - max}` }) : null,
|
|
778
|
+
];
|
|
779
|
+
}
|
|
780
|
+
|
|
541
781
|
function renderCatalog() {
|
|
542
782
|
const data = cache.catalog;
|
|
543
783
|
const body = $('#catalog-body');
|
|
@@ -548,122 +788,270 @@ function renderCatalog() {
|
|
|
548
788
|
const groups = data.groups || [];
|
|
549
789
|
const groupMap = new Map(groups.map((g) => [g.id, g]));
|
|
550
790
|
|
|
551
|
-
|
|
552
|
-
|
|
791
|
+
// 每个分组下有哪些模型 / 属于哪一类,一次算好,供侧栏与过滤共用。
|
|
792
|
+
const modelsByGroup = new Map();
|
|
793
|
+
for (const m of models) {
|
|
794
|
+
const arr = modelsByGroup.get(m.group) || [];
|
|
795
|
+
arr.push(m);
|
|
796
|
+
modelsByGroup.set(m.group, arr);
|
|
797
|
+
}
|
|
798
|
+
const groupCat = new Map(groups.map((g) => [g.id, categoryOf(g.id, modelsByGroup.get(g.id) || [])]));
|
|
799
|
+
|
|
800
|
+
renderGroupedChips(groups, models, modelsByGroup, groupCat);
|
|
801
|
+
renderGroupBanner(groups, models, groupCat);
|
|
553
802
|
|
|
554
803
|
const counts = catalogCounts(data);
|
|
555
804
|
const query = filters.q.trim().toLowerCase();
|
|
556
|
-
const
|
|
805
|
+
const matched = models.filter((m) => {
|
|
806
|
+
if (filters.category && groupCat.get(m.group) !== filters.category) return false;
|
|
557
807
|
if (filters.group && m.group !== filters.group) return false;
|
|
558
|
-
if (filters.
|
|
808
|
+
if (filters.vendor && (m.vendor || '') !== filters.vendor) return false;
|
|
559
809
|
if (!query) return true;
|
|
560
810
|
const hay = [m.name, m.id, m.group, m.vendor, m.description, m.tags, ...(m.endpoints || [])]
|
|
561
811
|
.filter(Boolean).join(' ').toLowerCase();
|
|
562
812
|
return hay.includes(query);
|
|
563
813
|
});
|
|
564
814
|
|
|
815
|
+
// 一行 = 一个「分组 × 模型」。跨分组聚合成一张卡留到下一个 PR。
|
|
816
|
+
const rows = matched;
|
|
817
|
+
|
|
565
818
|
if (meta) {
|
|
566
|
-
|
|
819
|
+
// replaceChildren 吃 null 会把它印成字符串「null」——先过滤掉空项再加。
|
|
820
|
+
meta.replaceChildren(...[
|
|
567
821
|
h('b', { text: fmtInt(rows.length) }),
|
|
568
822
|
h('span', { text: ` 个模型 · 全站 ${fmtInt(counts.models)} 个 / ${fmtInt(counts.rows)} 行 / ${fmtInt(counts.groups)} 个分组` }),
|
|
823
|
+
filters.category ? h('span', { text: ` · 分类 ${categoryTitle(filters.category)}` }) : null,
|
|
824
|
+
filters.vendor ? h('span', { text: ` · 厂商 ${filters.vendor}` }) : null,
|
|
569
825
|
h('span', { class: 'spacer' }),
|
|
570
826
|
h('span', {
|
|
571
827
|
class: 'muted',
|
|
572
828
|
text: `来源 ${SOURCE_LABEL[data.source] || data.source || '未知'} · 更新于 ${fmtAt(data.at)}`,
|
|
573
829
|
}),
|
|
574
|
-
);
|
|
830
|
+
].filter(Boolean));
|
|
575
831
|
}
|
|
576
832
|
|
|
577
833
|
if (!rows.length) {
|
|
578
|
-
body.
|
|
834
|
+
body.className = 'model-grid' + (filters.view === 'list' ? ' as-list' : '');
|
|
835
|
+
body.replaceChildren(h('div', { class: 'empty', text: '没有符合条件的模型。放宽分类、分组或搜索词再试。' }));
|
|
579
836
|
return;
|
|
580
837
|
}
|
|
581
838
|
|
|
582
|
-
|
|
839
|
+
// 排序:默认保留站点顺序(宿主列表与页面一致),另外给价格与名称两种。
|
|
840
|
+
// 排序:默认「最新版本」——按模型名里的版本号从新到旧。
|
|
841
|
+
const priceKey = (m) => (Number.isFinite(m.pricing?.inputNum) ? m.pricing.inputNum : Infinity);
|
|
842
|
+
if (filters.sort === 'price-asc') {
|
|
843
|
+
rows.sort((a, b) => priceKey(a) - priceKey(b) || String(a.name).localeCompare(String(b.name)));
|
|
844
|
+
} else if (filters.sort === 'price-desc') {
|
|
845
|
+
rows.sort((a, b) => priceKey(b) - priceKey(a) || String(a.name).localeCompare(String(b.name)));
|
|
846
|
+
} else if (filters.sort === 'name') {
|
|
847
|
+
rows.sort((a, b) => String(a.name).localeCompare(String(b.name), 'zh'));
|
|
848
|
+
} else {
|
|
849
|
+
rows.sort(byLatestVersion);
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
body.className = 'model-grid' + (filters.view === 'list' ? ' as-list' : '');
|
|
853
|
+
if (filters.view === 'list') {
|
|
854
|
+
body.replaceChildren(listHead(), ...rows.map((m) => modelRow(m, groupMap)));
|
|
855
|
+
} else {
|
|
856
|
+
body.replaceChildren(...rows.map((m) => modelCard(m, groupMap)));
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
/** 列表模式的表头:照 neartoken 的七列(模型 / 类型 / 价格 / 缓存 / 供应商 / 端点 / 分组)。 */
|
|
861
|
+
function listHead() {
|
|
862
|
+
return h('div', { class: 'ml-head' },
|
|
863
|
+
['模型', '类型', '价格', '缓存', '供应商', '端点', '分组'].map((t) => h('span', { text: t })));
|
|
583
864
|
}
|
|
584
865
|
|
|
585
|
-
/**
|
|
586
|
-
function
|
|
587
|
-
const
|
|
866
|
+
/** modelRow 列表模式的一行;点整行打开详情。 */
|
|
867
|
+
function modelRow(m, groupMap) {
|
|
868
|
+
const info = groupMap.get(m.group);
|
|
869
|
+
const pricing = m.pricing || {};
|
|
870
|
+
const kind = m.kind || 'chat';
|
|
871
|
+
const priceKind = pricing.kind || 'unknown';
|
|
872
|
+
const isAuto = m.group === 'auto' || (info && info.auto === true);
|
|
873
|
+
const billing = billingLabel(pricing, isAuto, priceKind);
|
|
874
|
+
const ends = Array.isArray(m.endpoints) ? m.endpoints : [];
|
|
875
|
+
const unit = filters.unit;
|
|
876
|
+
const open = () => openModelDrawer(m);
|
|
877
|
+
|
|
878
|
+
const priceCell = priceKind === 'percall' || priceKind === 'unknown' || isAuto
|
|
879
|
+
? h('span', { class: 'ml-cell ml-price' },
|
|
880
|
+
h('span', { class: 'ml-p-line' }, h('span', { class: 'ml-p-v', text: pricing.input || '—' })))
|
|
881
|
+
: h('span', { class: 'ml-cell ml-price' },
|
|
882
|
+
h('span', { class: 'ml-p-line' },
|
|
883
|
+
h('span', { class: 'ml-p-k', text: '输入' }), h('span', { class: 'ml-p-v', text: fmtTokValue(pricing.inputNum, unit) }),
|
|
884
|
+
h('span', { class: 'ml-p-k', text: '输出' }), h('span', { class: 'ml-p-v', text: fmtTokValue(pricing.outputNum, unit) })),
|
|
885
|
+
h('span', { class: 'ml-p-unit', text: `${(cache.state && cache.state.currency && cache.state.currency.symbol) || '$'} / 1${unit}` }));
|
|
886
|
+
|
|
887
|
+
return h('div', {
|
|
888
|
+
class: 'ml-row',
|
|
889
|
+
role: 'button',
|
|
890
|
+
tabindex: '0',
|
|
891
|
+
title: `打开 ${m.name} 的详情`,
|
|
892
|
+
onclick: open,
|
|
893
|
+
onkeydown: (ev) => {
|
|
894
|
+
if (ev.key === 'Enter' || ev.key === ' ') { ev.preventDefault(); open(); }
|
|
895
|
+
},
|
|
896
|
+
},
|
|
897
|
+
h('span', { class: 'ml-cell ml-model' },
|
|
898
|
+
vendorBadge(m.vendor, { size: 13 }),
|
|
899
|
+
h('span', { class: 'ml-name', text: m.name }),
|
|
900
|
+
kind !== 'chat' ? h('span', { class: 'ml-kind', text: KIND_LABEL[kind] || kind }) : null),
|
|
901
|
+
|
|
902
|
+
h('span', { class: `ml-cell ml-type ${billing.cls}`, text: billing.label }),
|
|
903
|
+
|
|
904
|
+
priceCell,
|
|
905
|
+
|
|
906
|
+
h('span', { class: 'ml-cell ml-cache' },
|
|
907
|
+
h('span', {
|
|
908
|
+
class: 'ml-c-v',
|
|
909
|
+
text: Number.isFinite(pricing.cacheNum) ? fmtTokValue(pricing.cacheNum, unit) : (pricing.cache || '—'),
|
|
910
|
+
}),
|
|
911
|
+
Number.isFinite(pricing.cacheNum) ? h('span', { class: 'ml-c-unit', text: `/ 1${unit}` }) : null),
|
|
912
|
+
|
|
913
|
+
h('span', { class: 'ml-cell ml-vendor' },
|
|
914
|
+
vendorBadge(m.vendor, { size: 13 }),
|
|
915
|
+
h('span', { text: m.vendor || '—' })),
|
|
916
|
+
|
|
917
|
+
h('span', { class: 'ml-cell ml-ends' },
|
|
918
|
+
ends.length ? endpointEls(ends, 3) : h('span', { class: 'ml-dash' })),
|
|
919
|
+
|
|
920
|
+
h('span', { class: 'ml-cell ml-groups' }, groupChipsEl(m)));
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
/** 顶部横幅:选中分组时给分组信息,只选了分类时给分类信息,都没选就收起。 */
|
|
924
|
+
function renderGroupBanner(groups, models, groupCat) {
|
|
925
|
+
const host = $('#group-banner');
|
|
588
926
|
if (!host) return;
|
|
589
927
|
|
|
590
|
-
const
|
|
591
|
-
|
|
592
|
-
const
|
|
593
|
-
|
|
928
|
+
const info = filters.group ? groups.find((g) => g.id === filters.group) : null;
|
|
929
|
+
if (info) {
|
|
930
|
+
const n = models.filter((m) => m.group === info.id).length;
|
|
931
|
+
const ratio = Number(info.ratio) > 0 ? fmtRatio(info.ratio) : (info.auto ? '按命中通道计费' : '');
|
|
932
|
+
host.hidden = false;
|
|
933
|
+
host.replaceChildren(...[
|
|
934
|
+
h('div', { class: 'gb-head' },
|
|
935
|
+
h('span', { class: 'gb-name', text: GROUP_ALIAS[info.id] || info.id }),
|
|
936
|
+
ratio ? h('span', { class: 'gb-ratio', text: ratio }) : null,
|
|
937
|
+
h('span', { class: 'gb-count', text: `${n} 个模型` }),
|
|
938
|
+
h('button', {
|
|
939
|
+
class: 'link gb-actions', type: 'button',
|
|
940
|
+
onclick: () => { filters.group = ''; renderCatalog(); },
|
|
941
|
+
}, '取消筛选')),
|
|
942
|
+
info.note ? h('p', { class: 'gb-note', text: info.note }) : null,
|
|
943
|
+
].filter(Boolean));
|
|
944
|
+
return;
|
|
594
945
|
}
|
|
595
946
|
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
}, '全部')];
|
|
608
|
-
|
|
609
|
-
for (const k of kinds) {
|
|
610
|
-
chips.push(h('button', {
|
|
611
|
-
class: 'market-chip', type: 'button',
|
|
612
|
-
'aria-pressed': String(filters.kind === k),
|
|
613
|
-
onclick: () => {
|
|
614
|
-
filters.kind = filters.kind === k ? '' : k;
|
|
615
|
-
renderCatalog();
|
|
616
|
-
},
|
|
617
|
-
}, KIND_LABEL[k] || k, h('span', { class: 'chip-count', text: String(counts.get(k) || 0) })));
|
|
947
|
+
if (filters.category) {
|
|
948
|
+
const n = models.filter((m) => groupCat.get(m.group) === filters.category).length;
|
|
949
|
+
host.hidden = false;
|
|
950
|
+
host.replaceChildren(h('div', { class: 'gb-head' },
|
|
951
|
+
h('span', { class: 'gb-name', text: categoryTitle(filters.category) }),
|
|
952
|
+
h('span', { class: 'gb-count', text: `${n} 个模型` }),
|
|
953
|
+
h('button', {
|
|
954
|
+
class: 'link gb-actions', type: 'button',
|
|
955
|
+
onclick: () => { filters.category = ''; filters.vendor = ''; renderCatalog(); },
|
|
956
|
+
}, '取消筛选')));
|
|
957
|
+
return;
|
|
618
958
|
}
|
|
619
959
|
|
|
620
|
-
host.
|
|
960
|
+
host.hidden = true;
|
|
961
|
+
host.replaceChildren();
|
|
621
962
|
}
|
|
622
963
|
|
|
623
|
-
|
|
964
|
+
/**
|
|
965
|
+
* 侧栏分组:按分类(claude → gpt → gemini → grok → 国模 → image → video)分组展示。
|
|
966
|
+
*
|
|
967
|
+
* 每个分类一行标题(图标 + 名字 + 模型数,点一下按这一整类筛选),下面列它的
|
|
968
|
+
* 分组;分组的 chip 前面就是倍率,后面是组名与模型数。
|
|
969
|
+
*/
|
|
970
|
+
function renderGroupedChips(groups, models, modelsByGroup, groupCat) {
|
|
624
971
|
const host = $('#group-chips');
|
|
972
|
+
const total = $('#group-total');
|
|
625
973
|
if (!host) return;
|
|
974
|
+
if (total) total.textContent = String(groups.length);
|
|
626
975
|
|
|
627
|
-
const
|
|
628
|
-
|
|
976
|
+
const countOf = (g) => (modelsByGroup.get(g.id) || []).length || g.models || 0;
|
|
977
|
+
const buckets = new Map();
|
|
978
|
+
for (const g of groups) {
|
|
979
|
+
const cat = groupCat.get(g.id);
|
|
980
|
+
const arr = buckets.get(cat) || [];
|
|
981
|
+
arr.push(g);
|
|
982
|
+
buckets.set(cat, arr);
|
|
983
|
+
}
|
|
629
984
|
|
|
630
|
-
const
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
];
|
|
985
|
+
const clearGroupFilters = () => {
|
|
986
|
+
filters.category = '';
|
|
987
|
+
filters.group = '';
|
|
988
|
+
filters.vendor = '';
|
|
989
|
+
renderCatalog();
|
|
990
|
+
};
|
|
637
991
|
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
992
|
+
const nodes = [h('button', {
|
|
993
|
+
class: 'market-chip', type: 'button',
|
|
994
|
+
'aria-pressed': String(!filters.category && !filters.group && !filters.vendor),
|
|
995
|
+
onclick: clearGroupFilters,
|
|
996
|
+
}, h('span', { class: 'chip-name', text: '全部' }), h('span', { class: 'chip-count', text: String(models.length) }))];
|
|
997
|
+
|
|
998
|
+
for (const catId of CATEGORY_ORDER) {
|
|
999
|
+
const list = buckets.get(catId);
|
|
1000
|
+
if (!list || !list.length) continue;
|
|
1001
|
+
const meta = CATEGORY_META[catId];
|
|
1002
|
+
const catCount = list.reduce((n, g) => n + countOf(g), 0);
|
|
1003
|
+
|
|
1004
|
+
nodes.push(h('button', {
|
|
1005
|
+
class: 'cat-head', type: 'button',
|
|
1006
|
+
'aria-pressed': String(filters.category === catId),
|
|
647
1007
|
onclick: () => {
|
|
648
|
-
filters.
|
|
1008
|
+
filters.category = filters.category === catId ? '' : catId;
|
|
1009
|
+
filters.group = '';
|
|
1010
|
+
filters.vendor = '';
|
|
649
1011
|
renderCatalog();
|
|
650
1012
|
},
|
|
651
1013
|
},
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
h('span', { class: '
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
1014
|
+
meta.icon ? iconImg(meta.icon) : null,
|
|
1015
|
+
h('span', { class: 'cat-title', text: meta.title }),
|
|
1016
|
+
h('span', { class: 'cat-count', text: String(catCount) })));
|
|
1017
|
+
|
|
1018
|
+
const chips = libraryGroupChips(list, modelsByGroup, countOf);
|
|
1019
|
+
nodes.push(h('div', { class: 'cat-chips' }, chips));
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
host.replaceChildren(...nodes);
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
/** libraryGroupChips 造一组分组 chip:倍率在前,组名在后。便宜的排前面。 */
|
|
1026
|
+
function libraryGroupChips(list, modelsByGroup, countOf) {
|
|
1027
|
+
return list
|
|
1028
|
+
.slice()
|
|
1029
|
+
.sort((a, b) => (Number(a.ratio) || 0) - (Number(b.ratio) || 0) || a.id.localeCompare(b.id, 'zh'))
|
|
1030
|
+
.map((g) => {
|
|
1031
|
+
return h('button', {
|
|
1032
|
+
class: 'market-chip group-chip', type: 'button',
|
|
1033
|
+
'aria-pressed': String(filters.group === g.id),
|
|
1034
|
+
title: [g.note || '', g.auto ? '该分组费率取决于实际命中的通道' : '', `模型 ${countOf(g)} 个`].filter(Boolean).join(' · '),
|
|
1035
|
+
onclick: () => {
|
|
1036
|
+
filters.group = filters.group === g.id ? '' : g.id;
|
|
1037
|
+
filters.category = '';
|
|
1038
|
+
filters.vendor = '';
|
|
1039
|
+
renderCatalog();
|
|
1040
|
+
},
|
|
1041
|
+
},
|
|
1042
|
+
Number(g.ratio) > 0 ? ratioTag(g.ratio) : null,
|
|
1043
|
+
h('span', { class: 'chip-name', text: GROUP_ALIAS[g.id] || g.id }),
|
|
1044
|
+
h('span', { class: 'chip-count', text: String(countOf(g)) }));
|
|
1045
|
+
});
|
|
658
1046
|
}
|
|
659
1047
|
|
|
660
1048
|
/**
|
|
661
1049
|
* 一张模型卡。
|
|
662
1050
|
*
|
|
663
|
-
* 结构照 NearToken
|
|
664
|
-
* → 端点 → 详情。等高靠三件事:外层 `.model-grid` 的
|
|
665
|
-
*
|
|
666
|
-
*
|
|
1051
|
+
* 结构照 NearToken 的模型广场:厂商图标 + 名称/厂商 → 描述 → 计费方式
|
|
1052
|
+
* → 价格 → 分组 → 端点 → 详情。等高靠三件事:外层 `.model-grid` 的
|
|
1053
|
+
* `align-items: stretch`、卡片自身 `display:flex; flex-direction:column`、
|
|
1054
|
+
* 以及尾部 `margin-top:auto` 把页脚按到底。任何一项缺失,同一行卡片就会参差。
|
|
667
1055
|
*
|
|
668
1056
|
* 刻意没照搬的两处:
|
|
669
1057
|
* 1. NearToken 的卡片有「已启用/未启用」开关。我们按既定要求做成纯展示,
|
|
@@ -671,22 +1059,38 @@ function renderGroupChips(groups, models) {
|
|
|
671
1059
|
* 2. 它有实时健康度(延迟、吞吐、成功率条)。我们没有这些数据,
|
|
672
1060
|
* 编一个出来比留白更糟,所以那个位置换成上下文长度与计费档位。
|
|
673
1061
|
*/
|
|
1062
|
+
/**
|
|
1063
|
+
* groupChipsEl 卡片/列表行里的分组:一个模型可能同时在好几个分组里卖。
|
|
1064
|
+
*
|
|
1065
|
+
* 「全部」视图下这里列的是它所在的全部(最多两个 + +N,title 里给全量);
|
|
1066
|
+
* 选了具体分组时 groups 只有一个,看起来和以前一样。
|
|
1067
|
+
*/
|
|
1068
|
+
function groupChipsEl(m) {
|
|
1069
|
+
const list = Array.isArray(m.groups) && m.groups.length
|
|
1070
|
+
? m.groups
|
|
1071
|
+
: [{ group: m.group, groupRatio: m.groupRatio, groupAuto: m.groupAuto }];
|
|
1072
|
+
const shown = list.slice(0, 2);
|
|
1073
|
+
const more = list.length - shown.length;
|
|
1074
|
+
const title = list
|
|
1075
|
+
.map((g) => `${GROUP_ALIAS[g.group] || g.group}${Number(g.groupRatio) > 0 ? ' ' + fmtRatio(g.groupRatio) : ''}`)
|
|
1076
|
+
.join('\n');
|
|
1077
|
+
return h('span', { class: 'mc-groups', title },
|
|
1078
|
+
shown.map((g) => h('span', { class: 'mc-gb' },
|
|
1079
|
+
Number(g.groupRatio) > 0 ? ratioTag(g.groupRatio) : null,
|
|
1080
|
+
h('span', { class: 'mc-group', text: GROUP_ALIAS[g.group] || g.group || '—' }))),
|
|
1081
|
+
more > 0 ? h('span', { class: 'mc-more', text: `+${more}` }) : null);
|
|
1082
|
+
}
|
|
1083
|
+
|
|
674
1084
|
function modelCard(m, groupMap) {
|
|
675
1085
|
const info = groupMap.get(m.group);
|
|
676
1086
|
const isAuto = m.group === 'auto' || (info && info.auto === true);
|
|
677
1087
|
const pricing = m.pricing || {};
|
|
678
1088
|
const priceKind = pricing.kind || 'unknown';
|
|
679
|
-
const ratio = m.groupRatio != null ? m.groupRatio : (info ? info.ratio : null);
|
|
680
1089
|
const kind = m.kind || 'chat';
|
|
681
1090
|
const endpoints = Array.isArray(m.endpoints) ? m.endpoints : [];
|
|
682
1091
|
|
|
683
1092
|
// 计费方式的说法要跟价格表一致:按次/按秒只给一列,别硬凑出「输出价 —」。
|
|
684
|
-
|
|
685
|
-
if (isAuto) billing = { cls: 'auto', label: '以实际命中通道为准' };
|
|
686
|
-
else if (priceKind === 'unknown') billing = { cls: 'unknown', label: '价格未知' };
|
|
687
|
-
else if (priceKind === 'percall') {
|
|
688
|
-
billing = { cls: 'call', label: /\/秒/.test(pricing.input || '') ? '按秒计费' : '按次计费' };
|
|
689
|
-
} else if (priceKind === 'tiered') billing = { cls: 'dyn', label: '分档计费' };
|
|
1093
|
+
const billing = billingLabel(pricing, isAuto, priceKind);
|
|
690
1094
|
|
|
691
1095
|
let priceCells;
|
|
692
1096
|
if (isAuto) {
|
|
@@ -696,34 +1100,34 @@ function modelCard(m, groupMap) {
|
|
|
696
1100
|
} else if (priceKind === 'percall') {
|
|
697
1101
|
priceCells = [h('div', { class: 'wide' }, h('span', { text: '单价' }), h('b', { text: pricing.input || '—' }))];
|
|
698
1102
|
} else {
|
|
699
|
-
priceCells =
|
|
700
|
-
h('div', null, h('span', { text: '输入' }), h('b', { text: pricing.input || '—' })),
|
|
701
|
-
h('div', null, h('span', { text: '输出' }), h('b', { text: pricing.output || '—' })),
|
|
702
|
-
h('div', null, h('span', { text: '缓存读取' }), h('b', { text: pricing.cache || '—' })),
|
|
703
|
-
];
|
|
1103
|
+
priceCells = priceCellsOf(pricing, filters.unit);
|
|
704
1104
|
}
|
|
705
1105
|
|
|
706
|
-
const desc = m.description ||
|
|
1106
|
+
const desc = m.description || autoDescription(m);
|
|
707
1107
|
const titleBits = [
|
|
708
|
-
desc,
|
|
1108
|
+
m.description ? desc : desc + '(站点没有给说明,这段是按目录信息拼的)',
|
|
709
1109
|
m.tags ? `标签:${m.tags}` : '',
|
|
710
1110
|
pricing.note || '',
|
|
711
1111
|
m.context ? `上下文 ${fmtInt(m.context)}` : '',
|
|
712
1112
|
`模型 id:${m.id || ''}`,
|
|
713
1113
|
].filter(Boolean).join('\n');
|
|
714
1114
|
|
|
1115
|
+
const open = () => openModelDrawer(m);
|
|
1116
|
+
|
|
715
1117
|
return h('article', { class: `mc mc-${kind}`, title: titleBits },
|
|
716
1118
|
h('div', { class: 'mc-head' },
|
|
1119
|
+
h('span', { class: 'mc-vicon' }, vendorBadge(m.vendor, { size: 18 })),
|
|
717
1120
|
h('div', { class: 'grow' },
|
|
718
1121
|
h('button', {
|
|
719
1122
|
class: 'mc-name', type: 'button',
|
|
720
1123
|
title: '查看这个模型的计费表达式与分档',
|
|
721
|
-
onclick:
|
|
1124
|
+
onclick: open,
|
|
722
1125
|
}, m.name || m.id || '未命名'),
|
|
723
1126
|
m.vendor ? h('div', { class: 'mc-vendor', text: m.vendor }) : null),
|
|
724
|
-
|
|
1127
|
+
// 绝大多数是对话模型,每张卡都挂一个「对话」只会变成噪音;只在生图/视频这类上标。
|
|
1128
|
+
kind !== 'chat' ? h('span', { class: 'mc-kind', text: KIND_LABEL[kind] || kind }) : null),
|
|
725
1129
|
|
|
726
|
-
h('p', { class:
|
|
1130
|
+
h('p', { class: 'mc-desc', text: desc }),
|
|
727
1131
|
|
|
728
1132
|
h('div', { class: `mc-billing ${billing.cls}`, text: billing.label }),
|
|
729
1133
|
|
|
@@ -731,17 +1135,37 @@ function modelCard(m, groupMap) {
|
|
|
731
1135
|
|
|
732
1136
|
h('div', { class: 'mc-line' },
|
|
733
1137
|
h('span', { class: 'k', text: '分组' }),
|
|
734
|
-
|
|
735
|
-
ratio != null && Number(ratio) > 0 ? h('span', { class: 'mc-ratio', text: `×${fmtRatio(ratio)}` }) : null),
|
|
1138
|
+
groupChipsEl(m)),
|
|
736
1139
|
|
|
737
|
-
h('div', { class: 'mc-line' },
|
|
1140
|
+
h('div', { class: 'mc-line mc-line-ends' },
|
|
738
1141
|
h('span', { class: 'k', text: '端点' }),
|
|
739
1142
|
endpoints.length
|
|
740
|
-
? h('span', { class: 'mc-ends' }, endpoints
|
|
1143
|
+
? h('span', { class: 'mc-ends' }, ...endpointEls(endpoints, 4))
|
|
741
1144
|
: h('span', { class: 'muted', text: '—' })),
|
|
742
1145
|
|
|
743
1146
|
h('div', { class: 'mc-foot' },
|
|
744
|
-
h('button', { class: 'link', type: 'button', onclick:
|
|
1147
|
+
h('button', { class: 'link mc-detail', type: 'button', onclick: open }, '详情', h('span', { class: 'mc-detail-arrow', text: '›' }))));
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
/**
|
|
1151
|
+
* autoDescription 给「站点没写说明」的模型补一句由目录信息拼出来的说明。
|
|
1152
|
+
*
|
|
1153
|
+
* 只陈述目录里确实存在的字段(厂商 / 类型 / 端点 / 计价),不编用途与能力;
|
|
1154
|
+
* 卡片的 tooltip 里会注明这句是按目录拼的,不冒充站点原文。
|
|
1155
|
+
*/
|
|
1156
|
+
function autoDescription(m) {
|
|
1157
|
+
const vendor = m.vendor || '站点';
|
|
1158
|
+
const kind = KIND_LABEL[m.kind] || '模型';
|
|
1159
|
+
const ends = (Array.isArray(m.endpoints) ? m.endpoints : []).slice(0, 2);
|
|
1160
|
+
const p = m.pricing || {};
|
|
1161
|
+
const billing = p.kind === 'tiered' ? '分档计费'
|
|
1162
|
+
: p.kind === 'percall' ? '按次/按秒计费'
|
|
1163
|
+
: p.kind === 'ratio' ? '按倍率计费'
|
|
1164
|
+
: '';
|
|
1165
|
+
const price = p.input && p.input !== '价格未知'
|
|
1166
|
+
? (p.kind === 'percall' ? `,单价 ${p.input}` : `,输入 ${p.input}`)
|
|
1167
|
+
: '';
|
|
1168
|
+
return `${vendor} 的${kind}模型${ends.length ? `,支持 ${ends.join(' / ')} 端点` : ''}${billing ? `;${billing}` : ''}${price}。`;
|
|
745
1169
|
}
|
|
746
1170
|
|
|
747
1171
|
function bindCatalogControls() {
|
|
@@ -753,15 +1177,80 @@ function bindCatalogControls() {
|
|
|
753
1177
|
if (cache.catalog) renderCatalog();
|
|
754
1178
|
});
|
|
755
1179
|
|
|
756
|
-
//
|
|
1180
|
+
// 重置只清筛选条件;单位、排序、视图属于「怎么看」,保留。
|
|
757
1181
|
reset.addEventListener('click', () => {
|
|
1182
|
+
filters.category = '';
|
|
758
1183
|
filters.group = '';
|
|
759
|
-
filters.
|
|
1184
|
+
filters.vendor = '';
|
|
760
1185
|
filters.q = '';
|
|
761
1186
|
search.value = '';
|
|
762
1187
|
if (cache.catalog) renderCatalog();
|
|
763
1188
|
search.focus();
|
|
764
1189
|
});
|
|
1190
|
+
|
|
1191
|
+
// 价格单位:/1M ↔ /1K
|
|
1192
|
+
for (const btn of $$('#unit-seg button')) {
|
|
1193
|
+
btn.addEventListener('click', () => {
|
|
1194
|
+
filters.unit = btn.dataset.unit === 'K' ? 'K' : 'M';
|
|
1195
|
+
for (const other of $$('#unit-seg button')) other.setAttribute('aria-pressed', String(other === btn));
|
|
1196
|
+
if (cache.catalog) renderCatalog();
|
|
1197
|
+
});
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
// 排序菜单:自绘弹层——原生 <select> 的弹层由系统画,深色页面里会弹出一块白底
|
|
1201
|
+
const trigger = $('#sort-trigger');
|
|
1202
|
+
const pop = $('#sort-pop');
|
|
1203
|
+
const label = $('#sort-label');
|
|
1204
|
+
if (trigger && pop) {
|
|
1205
|
+
const items = $$('#sort-pop [data-sort]');
|
|
1206
|
+
const setOpen = (open) => {
|
|
1207
|
+
pop.hidden = !open;
|
|
1208
|
+
trigger.setAttribute('aria-expanded', String(open));
|
|
1209
|
+
if (open) {
|
|
1210
|
+
const current = items.find((it) => it.getAttribute('aria-selected') === 'true') || items[0];
|
|
1211
|
+
current.focus();
|
|
1212
|
+
}
|
|
1213
|
+
};
|
|
1214
|
+
const choose = (btn) => {
|
|
1215
|
+
if (!btn) return;
|
|
1216
|
+
filters.sort = btn.dataset.sort;
|
|
1217
|
+
for (const it of items) it.setAttribute('aria-selected', String(it === btn));
|
|
1218
|
+
if (label) label.textContent = btn.textContent;
|
|
1219
|
+
setOpen(false);
|
|
1220
|
+
trigger.focus();
|
|
1221
|
+
if (cache.catalog) renderCatalog();
|
|
1222
|
+
};
|
|
1223
|
+
|
|
1224
|
+
trigger.addEventListener('click', () => setOpen(pop.hidden));
|
|
1225
|
+
for (const it of items) it.addEventListener('click', () => choose(it));
|
|
1226
|
+
document.addEventListener('click', (ev) => {
|
|
1227
|
+
if (!pop.hidden && !(ev.target instanceof Element && ev.target.closest('#sort-menu'))) setOpen(false);
|
|
1228
|
+
});
|
|
1229
|
+
document.addEventListener('keydown', (ev) => {
|
|
1230
|
+
if (pop.hidden) return;
|
|
1231
|
+
if (ev.key === 'Escape') { ev.preventDefault(); setOpen(false); trigger.focus(); return; }
|
|
1232
|
+
if (ev.key === 'ArrowDown' || ev.key === 'ArrowUp') {
|
|
1233
|
+
ev.preventDefault();
|
|
1234
|
+
const i = items.indexOf(document.activeElement);
|
|
1235
|
+
const next = ev.key === 'ArrowDown' ? (i + 1) % items.length : (i - 1 + items.length) % items.length;
|
|
1236
|
+
items[next].focus();
|
|
1237
|
+
return;
|
|
1238
|
+
}
|
|
1239
|
+
if ((ev.key === 'Enter' || ev.key === ' ') && items.includes(document.activeElement)) {
|
|
1240
|
+
ev.preventDefault();
|
|
1241
|
+
choose(document.activeElement);
|
|
1242
|
+
}
|
|
1243
|
+
});
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
// 视图:双列卡片 / 单列列表
|
|
1247
|
+
for (const btn of $$('#view-seg button')) {
|
|
1248
|
+
btn.addEventListener('click', () => {
|
|
1249
|
+
filters.view = btn.dataset.view === 'list' ? 'list' : 'grid';
|
|
1250
|
+
for (const other of $$('#view-seg button')) other.setAttribute('aria-pressed', String(other === btn));
|
|
1251
|
+
if (cache.catalog) renderCatalog();
|
|
1252
|
+
});
|
|
1253
|
+
}
|
|
765
1254
|
}
|
|
766
1255
|
|
|
767
1256
|
// ── 2. 余额与用量 ─────────────────────────────────────────
|
|
@@ -802,22 +1291,43 @@ function renderAccounts() {
|
|
|
802
1291
|
const noKeyHint = a.balance === '—'
|
|
803
1292
|
? '插件还没拿到这把钥匙的明文:在 magpie 里发一次请求、或点右上角「刷新」即可'
|
|
804
1293
|
: '';
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
1294
|
+
const split = splitMoney(a.balance || '—');
|
|
1295
|
+
return h('div', { class: 'acct-overview' },
|
|
1296
|
+
h('div', { class: 'acct-main' },
|
|
1297
|
+
h('div', { class: 'grow' },
|
|
1298
|
+
h('div', { class: 'money' },
|
|
1299
|
+
split.unit ? h('span', { class: 'unit', text: split.unit }) : null,
|
|
1300
|
+
split.value),
|
|
1301
|
+
h('p', {
|
|
1302
|
+
class: 'money-note',
|
|
1303
|
+
text: [
|
|
1304
|
+
a.used && a.used !== '—' ? `已用 ${a.used}` : '',
|
|
1305
|
+
a.group ? `分组 ${a.group}` : '',
|
|
1306
|
+
showMask ? `钥匙 ${mask}` : '',
|
|
1307
|
+
Number.isFinite(a.models) && a.models ? `${fmtInt(a.models)} 个模型` : '',
|
|
1308
|
+
Number.isFinite(a.boundAt) && a.boundAt ? `绑定于 ${fmtAt(a.boundAt)}` : '',
|
|
1309
|
+
].filter(Boolean).join(' · ') || (a.label || '还没有读到账户'),
|
|
1310
|
+
})),
|
|
1311
|
+
noKeyHint ? h('span', { class: 'acct-hint', text: noKeyHint }) : null,
|
|
816
1312
|
),
|
|
817
1313
|
);
|
|
818
1314
|
}));
|
|
819
1315
|
}
|
|
820
1316
|
|
|
1317
|
+
/** splitMoney 把「$12.34」拆成符号与大数字,照 neartoken 账户卡的做法。 */
|
|
1318
|
+
function splitMoney(text) {
|
|
1319
|
+
const m = String(text || '').match(/^([^\d-]*)(.*)$/);
|
|
1320
|
+
return { unit: (m && m[1]) || '', value: (m && m[2]) || '—' };
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
/** totalBalanceText 把各账号余额相加(quota),按站点币种印出来。 */
|
|
1324
|
+
function totalBalanceText() {
|
|
1325
|
+
const accts = (cache.state && cache.state.accounts) || [];
|
|
1326
|
+
if (!accts.length) return '—';
|
|
1327
|
+
const raw = accts.reduce((sum, a) => sum + (Number.isFinite(a.balanceRaw) ? a.balanceRaw : 0), 0);
|
|
1328
|
+
return moneyRaw(raw);
|
|
1329
|
+
}
|
|
1330
|
+
|
|
821
1331
|
function fig(k, v, cls = '', title = '') {
|
|
822
1332
|
return h('div', { class: 'fig' },
|
|
823
1333
|
h('span', { class: 'fig-k', text: k }),
|
|
@@ -869,20 +1379,46 @@ function renderUsage() {
|
|
|
869
1379
|
]);
|
|
870
1380
|
|
|
871
1381
|
box.replaceChildren(
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
h('div', { class: 'fig-v', text: fmtInt(data.tokens) })),
|
|
879
|
-
),
|
|
1382
|
+
// 三个数字一行,照 neartoken 的「数据概览」
|
|
1383
|
+
h('div', { class: 'stats' },
|
|
1384
|
+
statBlock('消耗', data.spent || '—'),
|
|
1385
|
+
statBlock('当前余额', totalBalanceText()),
|
|
1386
|
+
statBlock('Token', fmtInt(data.tokens))),
|
|
1387
|
+
usageChart(data),
|
|
880
1388
|
h('p', { class: 'range-note', text: `区间 ${fmtAt(data.start)} → ${fmtAt(data.end)}` }),
|
|
881
1389
|
tableEl([{ label: '模型' }, { label: '调用', cls: 'num' }, { label: 'tokens', cls: 'num' }, { label: '费用', cls: 'num' }],
|
|
882
1390
|
rows, { empty: '这个区间还没有按模型的用量。' }),
|
|
883
1391
|
);
|
|
884
1392
|
}
|
|
885
1393
|
|
|
1394
|
+
function statBlock(k, v, title = '') {
|
|
1395
|
+
return h('div', { class: 'stat' },
|
|
1396
|
+
h('div', { class: 'k', text: k }),
|
|
1397
|
+
h('div', { class: 'v', title: title || null, text: v }));
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
/** usageChart 用柱状条画出区间的消耗分布;没有数据就直说,不画空图。 */
|
|
1401
|
+
function usageChart(data) {
|
|
1402
|
+
const buckets = Array.isArray(data.buckets) ? data.buckets : [];
|
|
1403
|
+
const max = buckets.reduce((m, b) => Math.max(m, Number(b.costRaw) || 0), 0);
|
|
1404
|
+
if (!buckets.length || max <= 0) {
|
|
1405
|
+
return h('div', { class: 'chart-empty', text: '这个区间还没有消耗,所以没有曲线可画。' });
|
|
1406
|
+
}
|
|
1407
|
+
const bars = buckets.map((b) => {
|
|
1408
|
+
const hgt = Math.max(2, Math.round(((Number(b.costRaw) || 0) / max) * 100));
|
|
1409
|
+
return h('i', {
|
|
1410
|
+
class: 'bar',
|
|
1411
|
+
style: `height:${hgt}%`,
|
|
1412
|
+
title: `${fmtAt(b.at)} · ${b.cost || '—'}`,
|
|
1413
|
+
});
|
|
1414
|
+
});
|
|
1415
|
+
return h('div', {
|
|
1416
|
+
class: 'chart-bars',
|
|
1417
|
+
role: 'img',
|
|
1418
|
+
'aria-label': `消耗趋势:${buckets.length} 个时间段,峰值 ${moneyRaw(max)}`,
|
|
1419
|
+
}, bars);
|
|
1420
|
+
}
|
|
1421
|
+
|
|
886
1422
|
async function loadFlow(force = false) {
|
|
887
1423
|
const account = filters.account;
|
|
888
1424
|
if (!account) { renderFlow(); return null; } // 全部账号直接用 usage.rows
|
|
@@ -1378,26 +1914,29 @@ function renderPat() {
|
|
|
1378
1914
|
if (!st) { regionLoading(box, '正在读取 PAT 状态'); if (badge) badge.textContent = ''; return; }
|
|
1379
1915
|
|
|
1380
1916
|
const pat = st.pat || {};
|
|
1381
|
-
if (badge) badge.textContent = pat.set ? '已设置' : '未设置';
|
|
1917
|
+
if (badge) badge.textContent = pat.set ? (pat.verified ? '已设置 · 已验证' : '已设置 · 未验证') : '未设置';
|
|
1382
1918
|
|
|
1383
1919
|
if (!pat.set) {
|
|
1384
1920
|
box.replaceChildren(
|
|
1385
1921
|
h('p', { class: 'muted', text: '还没有设置 PAT。设置后才能读账户、建钥匙、看钱包。' }),
|
|
1386
|
-
h('p', { class: 'hint', text: '
|
|
1922
|
+
h('p', { class: 'hint', text: '在控制台「安全 → 访问令牌」创建后,把整串令牌原样粘过来即可。' }),
|
|
1387
1923
|
);
|
|
1388
1924
|
return;
|
|
1389
1925
|
}
|
|
1390
1926
|
|
|
1391
1927
|
const scopes = Array.isArray(pat.scopes) ? pat.scopes : [];
|
|
1392
|
-
box.replaceChildren(
|
|
1928
|
+
box.replaceChildren(...[
|
|
1929
|
+
pat.verified === false
|
|
1930
|
+
? h('p', { class: 'hint', text: '这份令牌保存时没能连上站点验证,可能是站点一时不可达;点右上角「刷新」或在密钥页试一次就能确认它是否可用。' })
|
|
1931
|
+
: null,
|
|
1393
1932
|
h('div', { class: 'kv' }, h('span', { class: 'k', text: 'hint' }), h('span', { class: 'v', text: pat.hint || '—' })),
|
|
1394
1933
|
h('div', { class: 'kv' },
|
|
1395
1934
|
h('span', { class: 'k', text: 'scopes' }),
|
|
1396
1935
|
scopes.length
|
|
1397
1936
|
? h('span', { class: 'scope-list' }, scopes.map((s) => h('span', { class: 'tag', text: s })))
|
|
1398
|
-
: h('span', { class: 'v muted', text: '
|
|
1937
|
+
: h('span', { class: 'v muted', text: '还没有验到可用的 scope' }),
|
|
1399
1938
|
),
|
|
1400
|
-
);
|
|
1939
|
+
].filter(Boolean));
|
|
1401
1940
|
}
|
|
1402
1941
|
|
|
1403
1942
|
async function loadPing(force = false) {
|
|
@@ -1472,21 +2011,37 @@ async function onSavePat(ev) {
|
|
|
1472
2011
|
const pat = input.value.trim();
|
|
1473
2012
|
|
|
1474
2013
|
if (!pat) { banner('warn', '先粘贴一个 PAT 再保存。', { key: 'pat-form' }); input.focus(); return; }
|
|
1475
|
-
|
|
1476
|
-
|
|
2014
|
+
// 只挡「明显拿错了凭据」:sk- 是模型钥匙,不是访问令牌。
|
|
2015
|
+
// 前缀不做硬校验——站点的令牌前缀由站点自己决定(文档里写过 nap-,代码里写过
|
|
2016
|
+
// nap_,两种都可能是真的),前端按自己的猜测拦下来只会变成「点了没反应」。
|
|
2017
|
+
// 真正的判定交给后端:它会拿令牌去问站点。
|
|
2018
|
+
if (/^sk[-_]/.test(pat)) {
|
|
2019
|
+
banner('warn', '这看起来是一把 sk- 模型钥匙,不是访问令牌。访问令牌在控制台「安全 → 访问令牌」创建。', { key: 'pat-form' });
|
|
2020
|
+
return;
|
|
2021
|
+
}
|
|
2022
|
+
if (pat.length < 8) {
|
|
2023
|
+
banner('warn', '这个值太短了,不像一份访问令牌,确认一下有没有粘全。', { key: 'pat-form' });
|
|
1477
2024
|
return;
|
|
1478
2025
|
}
|
|
1479
2026
|
|
|
1480
2027
|
btn.disabled = true;
|
|
1481
2028
|
btn.textContent = '保存中…';
|
|
2029
|
+
// 立刻给反馈:保存要串行探三个站点端点,没有这句用户会以为没点上。
|
|
2030
|
+
banner('info', '已提交,正在向站点验证这份令牌…', { key: 'pat-form' });
|
|
1482
2031
|
try {
|
|
1483
2032
|
const data = await api.savePat(pat);
|
|
1484
2033
|
if (cache.state) cache.state.pat = data.pat || { set: true };
|
|
1485
2034
|
input.value = '';
|
|
1486
2035
|
clearBanner('pat-form');
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
2036
|
+
// warning 是「存下了,但你该知道」:缺 scope 或没能验证。不能当成成功一笔带过,
|
|
2037
|
+
// 也不该当失败——令牌本身已经收下了。
|
|
2038
|
+
if (data.warning) {
|
|
2039
|
+
banner('warn', data.warning, { key: 'pat-ok' });
|
|
2040
|
+
} else {
|
|
2041
|
+
banner('ok', data.user && data.user.name
|
|
2042
|
+
? `PAT 已保存,已连接到账户 ${data.user.name}。`
|
|
2043
|
+
: 'PAT 已保存。', { key: 'pat-ok', timeout: 7000 });
|
|
2044
|
+
}
|
|
1490
2045
|
renderPat();
|
|
1491
2046
|
// PAT 换了,钥匙/余额/用量都可能变,别拿旧缓存骗人
|
|
1492
2047
|
cache.keys = null;
|
|
@@ -1495,7 +2050,9 @@ async function onSavePat(ev) {
|
|
|
1495
2050
|
if (activeTab === 'keys') loadKeys(true);
|
|
1496
2051
|
return data;
|
|
1497
2052
|
} catch (err) {
|
|
1498
|
-
|
|
2053
|
+
// 服务端在 400 里带的 hint 是可操作的下一步(去勾哪个 scope),必须带出来。
|
|
2054
|
+
const extra = err && err.payload && err.payload.hint ? ` ${err.payload.hint}` : '';
|
|
2055
|
+
banner('error', `保存 PAT 失败:${describeError(err)}${extra}`, { key: 'pat-form' });
|
|
1499
2056
|
return null;
|
|
1500
2057
|
} finally {
|
|
1501
2058
|
btn.disabled = false;
|
|
@@ -1615,8 +2172,20 @@ function openModelDrawer(model) {
|
|
|
1615
2172
|
if (!drawer) return;
|
|
1616
2173
|
drawerLastFocus = document.activeElement;
|
|
1617
2174
|
|
|
2175
|
+
const kind = model.kind || 'chat';
|
|
1618
2176
|
$('#drawer-title').textContent = model.name || model.id || '模型详情';
|
|
1619
|
-
$('#drawer-sub').
|
|
2177
|
+
$('#drawer-sub').replaceChildren(...[
|
|
2178
|
+
h('span', { class: 'tag-chip', text: model.group || '未分组' }),
|
|
2179
|
+
model.groupRatio != null && Number(model.groupRatio) > 0
|
|
2180
|
+
? h('span', { class: 'tag-chip' }, '倍率 ', h('span', { class: 'ratio', text: fmtRatio(model.groupRatio) }))
|
|
2181
|
+
: null,
|
|
2182
|
+
model.vendor ? h('span', { class: 'tag-chip' }, vendorBadge(model.vendor, { size: 12 }), ' ', model.vendor) : null,
|
|
2183
|
+
h('span', { class: 'tag-chip', text: KIND_LABEL[kind] || kind }),
|
|
2184
|
+
].filter(Boolean));
|
|
2185
|
+
|
|
2186
|
+
const icon = $('#drawer-icon');
|
|
2187
|
+
if (icon) icon.replaceChildren(vendorBadge(model.vendor, { size: 30 }));
|
|
2188
|
+
|
|
1620
2189
|
const body = $('#drawer-body');
|
|
1621
2190
|
regionLoading(body, '正在读取计费详情');
|
|
1622
2191
|
drawer.hidden = false;
|
|
@@ -1640,75 +2209,223 @@ async function loadModelDetail(model, body) {
|
|
|
1640
2209
|
}
|
|
1641
2210
|
}
|
|
1642
2211
|
|
|
2212
|
+
/** 计费因子 → 人话。站点 DSL 里的变量名不该原样丢给用户。 */
|
|
2213
|
+
const COEFF_LABEL = {
|
|
2214
|
+
input: '输入',
|
|
2215
|
+
output: '输出',
|
|
2216
|
+
cacheRead: '缓存读取',
|
|
2217
|
+
cacheWrite: '缓存写入',
|
|
2218
|
+
cacheWrite1h: '缓存写入(1 小时)',
|
|
2219
|
+
};
|
|
2220
|
+
const PARAM_LABEL = { service_tier: '服务档' };
|
|
2221
|
+
|
|
2222
|
+
/**
|
|
2223
|
+
* modelDetailNodes 把详情抽屉的内容造出来。
|
|
2224
|
+
*
|
|
2225
|
+
* 这条路径以前的形态是「把站点原文倒出来」:`mode: tiered_expr`、一整行
|
|
2226
|
+
* `tier("standard", p * 0.2 + …)`、分档表两列全是「—」、示例是 `[]`。
|
|
2227
|
+
* 用户看到的是一屏机器串,读不出任何结论。
|
|
2228
|
+
*
|
|
2229
|
+
* 现在的顺序按「先结论、后证据」:
|
|
2230
|
+
* 价签 → 概览 → 计费怎么算(中文)→ 每档实际单价 → 按用量单价 → 原始表达式(折叠)
|
|
2231
|
+
*/
|
|
1643
2232
|
function modelDetailNodes(model, data) {
|
|
1644
2233
|
const nodes = [];
|
|
1645
2234
|
const pricing = model.pricing || {};
|
|
1646
2235
|
const billing = data.billing || null;
|
|
2236
|
+
const priceKind = pricing.kind || 'unknown';
|
|
2237
|
+
const isAuto = model.group === 'auto' || model.groupAuto === true;
|
|
1647
2238
|
|
|
2239
|
+
// ── 1. 价签:详情页最该先被看到的东西 ──────────────────
|
|
2240
|
+
nodes.push(priceTiles(pricing, billing, { isAuto, priceKind }));
|
|
2241
|
+
|
|
2242
|
+
// ── 2. 概览 ────────────────────────────────────────────
|
|
1648
2243
|
nodes.push(h('dl', { class: 'kv-grid' },
|
|
1649
|
-
h('dt', { text: '模型名' }), h('dd', { text: model.name || '—' }),
|
|
1650
|
-
h('dt', { text: '分组' }), h('dd', { text: model.group || '—' }),
|
|
1651
2244
|
h('dt', { text: '厂商' }), h('dd', { text: model.vendor || '—' }),
|
|
1652
2245
|
h('dt', { text: '类型' }), h('dd', { text: KIND_LABEL[model.kind] || model.kind || '—' }),
|
|
1653
|
-
h('dt', { text: '上下文' }), h('dd', { text:
|
|
1654
|
-
h('dt', { text: '端点' }), h('dd', { text: (model.endpoints || []).join(' · ') || '—' }),
|
|
1655
|
-
h('dt', { text: '
|
|
1656
|
-
h('dt', { text: '
|
|
1657
|
-
|
|
1658
|
-
? '价格未知'
|
|
1659
|
-
: [pricing.input, pricing.output, pricing.cache].filter(Boolean).join(' · ') || '—',
|
|
1660
|
-
}),
|
|
2246
|
+
h('dt', { text: '上下文' }), h('dd', { class: 'mono', text: model.context ? fmtInt(model.context) : '—' }),
|
|
2247
|
+
h('dt', { text: '端点' }), h('dd', { class: 'mono', text: (model.endpoints || []).join(' · ') || '—' }),
|
|
2248
|
+
h('dt', { text: '分组' }), h('dd', { text: model.group || '—' }),
|
|
2249
|
+
h('dt', { text: '分组倍率' }), h('dd', { class: 'mono', text: model.groupRatio != null && Number(model.groupRatio) > 0 ? fmtRatio(model.groupRatio) : '—' }),
|
|
2250
|
+
h('dt', { text: '模型 id' }), h('dd', { class: 'mono' }, model.id || '—'),
|
|
1661
2251
|
));
|
|
1662
2252
|
|
|
1663
|
-
if (pricing.note) nodes.push(h('p', { class: 'hint', text: `站点说明:${pricing.note}` }));
|
|
1664
2253
|
if (model.description) nodes.push(h('p', { class: 'hint', text: model.description }));
|
|
1665
2254
|
|
|
2255
|
+
// ── 3. 计费怎么算 ──────────────────────────────────────
|
|
2256
|
+
const facts = billingFacts(billing, { isAuto, priceKind, note: pricing.note });
|
|
2257
|
+
nodes.push(h('section', { class: 'dtl-section' },
|
|
2258
|
+
h('h3', { class: 'dtl-h3', text: '计费方式' }),
|
|
2259
|
+
facts.length
|
|
2260
|
+
? h('ul', { class: 'dtl-facts' }, facts.map((f) => h('li', null, f)))
|
|
2261
|
+
: h('p', { class: 'hint', text: '站点没有给出这个模型的计费规则。' }),
|
|
2262
|
+
));
|
|
2263
|
+
|
|
1666
2264
|
if (!billing) {
|
|
1667
|
-
nodes.push(h('p', { class: '
|
|
2265
|
+
nodes.push(h('p', { class: 'hint', text: '这一条没有更细的计费信息(站点目录里没有它的 billing 配置)。' }));
|
|
1668
2266
|
return nodes;
|
|
1669
2267
|
}
|
|
1670
2268
|
|
|
1671
|
-
|
|
1672
|
-
|
|
2269
|
+
// ── 4. 每档实际单价 ────────────────────────────────────
|
|
2270
|
+
const tiers = Array.isArray(billing.tiers) ? billing.tiers : [];
|
|
2271
|
+
const priced = tiers.filter((t) => t.prices && Object.keys(t.prices).length);
|
|
2272
|
+
if (priced.length) {
|
|
2273
|
+
const hasWrite = priced.some((t) => t.prices.cacheWrite || t.prices.cacheWrite1h);
|
|
2274
|
+
const headers = ['档位', { label: '输入', cls: 'num' }, { label: '输出', cls: 'num' }, { label: '缓存读取', cls: 'num' }];
|
|
2275
|
+
if (hasWrite) headers.push({ label: '缓存写入', cls: 'num' });
|
|
2276
|
+
const rows = priced.map((t) => {
|
|
2277
|
+
const cells = [
|
|
2278
|
+
{ text: t.name || '—', cls: 'mono' },
|
|
2279
|
+
{ text: t.prices.input || '—', cls: 'num' },
|
|
2280
|
+
{ text: t.prices.output || '—', cls: 'num' },
|
|
2281
|
+
{ text: t.prices.cacheRead || '—', cls: 'num' },
|
|
2282
|
+
];
|
|
2283
|
+
if (hasWrite) cells.push({ text: t.prices.cacheWrite || t.prices.cacheWrite1h || '—', cls: 'num' });
|
|
2284
|
+
return cells;
|
|
2285
|
+
});
|
|
2286
|
+
nodes.push(h('section', { class: 'dtl-section' },
|
|
2287
|
+
h('h3', { class: 'dtl-h3', text: '每一档的实际单价(已乘分组倍率)' }),
|
|
2288
|
+
tableEl(headers, rows, { empty: '站点没有给出分档价格。' }),
|
|
2289
|
+
));
|
|
2290
|
+
}
|
|
1673
2291
|
|
|
1674
|
-
|
|
1675
|
-
|
|
2292
|
+
// ── 5. 按用量计费(视频 / 按秒) ───────────────────────
|
|
2293
|
+
const usageRows = Array.isArray(billing.usageRows) ? billing.usageRows : [];
|
|
2294
|
+
if (usageRows.length) {
|
|
2295
|
+
nodes.push(h('section', { class: 'dtl-section' },
|
|
2296
|
+
h('h3', { class: 'dtl-h3', text: '按用量计费' }),
|
|
2297
|
+
tableEl(['字段', '单位', { label: '单价', cls: 'num' }],
|
|
2298
|
+
usageRows.map((u) => [
|
|
2299
|
+
{ text: u.label || u.field || '—', cls: '' },
|
|
2300
|
+
{ text: u.unit || '—', cls: 'mono' },
|
|
2301
|
+
{ text: u.price || '—', cls: 'num' },
|
|
2302
|
+
]),
|
|
2303
|
+
{ empty: '站点没有给出用量单价。' }),
|
|
2304
|
+
));
|
|
1676
2305
|
}
|
|
1677
2306
|
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
nodes.push(
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
{
|
|
1685
|
-
{
|
|
1686
|
-
|
|
2307
|
+
// ── 5. 条件乘数(service_tier 这类整单加成) ─────────────
|
|
2308
|
+
const multipliers = billing && Array.isArray(billing.multipliers) ? billing.multipliers : [];
|
|
2309
|
+
if (multipliers.length) {
|
|
2310
|
+
nodes.push(h('section', { class: 'dtl-section' },
|
|
2311
|
+
h('h3', { class: 'dtl-h3', text: '条件乘数' }),
|
|
2312
|
+
h('div', { class: 'mult-list' }, multipliers.map((m) => h('div', { class: 'mult-row' },
|
|
2313
|
+
h('span', { class: 'mult-when', text: `请求体参数 ${m.param} = ${m.value}` }),
|
|
2314
|
+
h('span', { class: 'mult-pill', text: `${m.factor}×` })))),
|
|
2315
|
+
));
|
|
1687
2316
|
}
|
|
1688
2317
|
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
nodes.push(
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
2318
|
+
// ── 6. 按分组定价:同一个模型在不同分组里的价格 ──────────
|
|
2319
|
+
const siblings = Array.isArray(data.siblings) ? data.siblings : [];
|
|
2320
|
+
if (siblings.length > 1) {
|
|
2321
|
+
nodes.push(h('section', { class: 'dtl-section' },
|
|
2322
|
+
h('h3', { class: 'dtl-h3', text: '按分组定价' }),
|
|
2323
|
+
tableEl(['分组', '倍率', { label: '输入', cls: 'num' }, { label: '输出', cls: 'num' }, { label: '缓存读取', cls: 'num' }],
|
|
2324
|
+
siblings.map((s) => [
|
|
2325
|
+
{ node: h('span', { class: 'sib-group' + (s.current ? ' is-current' : '') },
|
|
2326
|
+
h('span', { text: GROUP_ALIAS[s.group] || s.group }),
|
|
2327
|
+
s.current ? h('span', { class: 'sib-now', text: '当前' }) : null) },
|
|
2328
|
+
{ text: Number(s.groupRatio) > 0 ? fmtRatio(s.groupRatio) : (s.auto ? '按通道' : '—'), cls: 'num' },
|
|
2329
|
+
{ text: s.input || '—', cls: 'num' },
|
|
2330
|
+
{ text: s.output || '—', cls: 'num' },
|
|
2331
|
+
{ text: s.cache || '—', cls: 'num' },
|
|
2332
|
+
]),
|
|
2333
|
+
{ empty: '站点没有给出这个模型的分组价格。' }),
|
|
2334
|
+
));
|
|
1698
2335
|
}
|
|
1699
2336
|
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
nodes.push(h('
|
|
2337
|
+
// ── 7. 原始表达式(证据,默认折叠) ────────────────────
|
|
2338
|
+
if (billing.expr) {
|
|
2339
|
+
nodes.push(h('details', { class: 'raw' },
|
|
2340
|
+
h('summary', { text: '原始计费表达式(站点原文,一般不用看)' }),
|
|
2341
|
+
h('pre', { class: 'expr', text: String(billing.expr) }),
|
|
2342
|
+
billing.schema ? h('pre', { class: 'expr', text: `用量 schema\n${safeJson(billing.schema)}` }) : null,
|
|
2343
|
+
));
|
|
1703
2344
|
}
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
2345
|
+
|
|
2346
|
+
// 示例:站点给了才有,空数组不再渲染成一个「[]」吓人。
|
|
2347
|
+
const examples = Array.isArray(billing.examples) ? billing.examples : [];
|
|
2348
|
+
if (examples.length) {
|
|
2349
|
+
nodes.push(h('details', { class: 'raw' },
|
|
2350
|
+
h('summary', { text: `站点给的计费示例(${examples.length} 条)` }),
|
|
2351
|
+
h('pre', { class: 'expr', text: safeJson(examples) }),
|
|
2352
|
+
));
|
|
1707
2353
|
}
|
|
1708
2354
|
|
|
1709
2355
|
return nodes;
|
|
1710
2356
|
}
|
|
1711
2357
|
|
|
2358
|
+
/** priceTiles 造详情页顶部的价签:能算准就给三格,算不准就直说。 */
|
|
2359
|
+
function priceTiles(pricing, billing, { isAuto, priceKind }) {
|
|
2360
|
+
const one = (label, value, { unknown = false } = {}) => h('div', { class: `dtl-price${unknown ? ' is-unknown' : ''}` },
|
|
2361
|
+
h('span', { text: label }),
|
|
2362
|
+
h('b', { text: value || '—' }));
|
|
2363
|
+
|
|
2364
|
+
if (isAuto) {
|
|
2365
|
+
return h('div', { class: 'dtl-prices one' }, one('单价', pricing.input || '以实际命中通道为准', { unknown: true }));
|
|
2366
|
+
}
|
|
2367
|
+
if (priceKind === 'unknown') {
|
|
2368
|
+
return h('div', { class: 'dtl-prices one' }, one('单价', '价格未知', { unknown: true }));
|
|
2369
|
+
}
|
|
2370
|
+
if (priceKind === 'percall' || priceKind === 'call') {
|
|
2371
|
+
return h('div', { class: 'dtl-prices one' }, one('单价', pricing.input || '—'));
|
|
2372
|
+
}
|
|
2373
|
+
|
|
2374
|
+
// 分档模型:首屏给第一档,具体每一档在下面表格里。
|
|
2375
|
+
const first = billing && Array.isArray(billing.tiers) ? billing.tiers.find((t) => t.prices && t.prices.input) : null;
|
|
2376
|
+
const input = (first && first.prices.input) || pricing.input;
|
|
2377
|
+
const output = (first && first.prices.output) || pricing.output;
|
|
2378
|
+
const cache = (first && first.prices.cacheRead) || pricing.cache;
|
|
2379
|
+
return h('div', { class: 'dtl-prices' },
|
|
2380
|
+
one('输入', input),
|
|
2381
|
+
one('输出', output),
|
|
2382
|
+
one('缓存读取', cache));
|
|
2383
|
+
}
|
|
2384
|
+
|
|
2385
|
+
/**
|
|
2386
|
+
* billingFacts 生成「计费怎么算」的中文句子。
|
|
2387
|
+
*
|
|
2388
|
+
* 只描述站点真的给出来的东西:倍率、档位、服务档加成、用量变量。
|
|
2389
|
+
* 算不出来就说算不出来,不替站点编规则。
|
|
2390
|
+
*/
|
|
2391
|
+
function billingFacts(billing, { isAuto, priceKind, note } = {}) {
|
|
2392
|
+
const facts = [];
|
|
2393
|
+
|
|
2394
|
+
if (isAuto) {
|
|
2395
|
+
facts.push('这个分组没有固定倍率:实际单价取决于这次请求命中的通道,站点也算不出一个确定值。');
|
|
2396
|
+
}
|
|
2397
|
+
|
|
2398
|
+
if (priceKind === 'ratio') {
|
|
2399
|
+
facts.push('按倍率计费:模型倍率 × 分组倍率 × 2 美元 / 百万 token。');
|
|
2400
|
+
}
|
|
2401
|
+
|
|
2402
|
+
if (billing && Array.isArray(billing.tiers) && billing.tiers.length) {
|
|
2403
|
+
const names = billing.tiers.map((t) => t.name).filter(Boolean);
|
|
2404
|
+
const hasTokenPrices = billing.tiers.some((t) => t.prices && Object.keys(t.prices).length);
|
|
2405
|
+
facts.push(hasTokenPrices
|
|
2406
|
+
? `共 ${billing.tiers.length} 档:${names.join(' / ')}。下表每一档的单价已经乘上分组倍率 ${fmtRatio(billing.groupRatio)}。`
|
|
2407
|
+
: `共 ${billing.tiers.length} 档:${names.join(' / ')}。这些档按用量计费,单价见下表。`);
|
|
2408
|
+
}
|
|
2409
|
+
|
|
2410
|
+
const usageRows = billing && Array.isArray(billing.usageRows) ? billing.usageRows : [];
|
|
2411
|
+
if (usageRows.length) {
|
|
2412
|
+
const parts = usageRows.slice(0, 3).map((u) => `${u.label || u.field} ${u.price}`);
|
|
2413
|
+
facts.push(`按用量计费:${parts.join('、')}${usageRows.length > 3 ? ' 等' : ''}。实际扣费以控制台为准。`);
|
|
2414
|
+
}
|
|
2415
|
+
|
|
2416
|
+
if (priceKind === 'percall' && !usageRows.length) {
|
|
2417
|
+
facts.push('按次计费:与 token 数无关,每调用一次扣一次。');
|
|
2418
|
+
}
|
|
2419
|
+
|
|
2420
|
+
if (priceKind === 'unknown' && !isAuto) {
|
|
2421
|
+
facts.push('站点没有给出能解析成单价的规则,所以这里不给数字——编一个出来比留白更糟。');
|
|
2422
|
+
}
|
|
2423
|
+
|
|
2424
|
+
if (note) facts.push(`站点说明:${note}`);
|
|
2425
|
+
|
|
2426
|
+
return facts;
|
|
2427
|
+
}
|
|
2428
|
+
|
|
1712
2429
|
function safeJson(value) {
|
|
1713
2430
|
try { return JSON.stringify(value, null, 2); } catch { return String(value); }
|
|
1714
2431
|
}
|