@fish-under-sea/magpie-dragonapi 0.2.1 → 0.3.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.
- package/README.md +14 -7
- package/index.mjs +7 -7
- package/lib/service.mjs +38 -1
- package/lib/site.mjs +437 -401
- package/package.json +9 -9
- package/page/icon.png +0 -0
- package/page/index.html +2 -2
- package/page/star.png +0 -0
- package/ui/app.js +3224 -2568
- package/ui/demo.js +216 -0
- package/ui/icon.png +0 -0
- package/ui/index.html +335 -295
- package/ui/model-agg.js +458 -0
- package/ui/style.css +2758 -1875
- package/page/icon.svg +0 -12
package/ui/demo.js
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
// 演示数据层:网址带 ?demo(且不是 ?demo=0)时接管页面的全部 GET 请求。
|
|
2
|
+
// 数据只存在当前页面内存,刷新即还原;绝不向真实服务发送写请求(POST/DELETE 一律走原实现)。
|
|
3
|
+
// 用途:无 PAT / 无账号时也能核对使用日志页的完整排版与交互。
|
|
4
|
+
|
|
5
|
+
const DAY = 86400000;
|
|
6
|
+
|
|
7
|
+
/** makeRows 造一批形如 /api/usage 服务端输出的日志行。 */
|
|
8
|
+
function makeRows(now, cur) {
|
|
9
|
+
const specs = [
|
|
10
|
+
// [model, group, ratio, input, output, cache, bytes, isStream, tps, ttft, dur, quota, kind]
|
|
11
|
+
['gpt-6.1-sol', 'gpt-promax', 0.16, 84920, 351, 84608, 315 * 1024, true, 50, 3.9, 11.0, 1635, '消耗'],
|
|
12
|
+
['gpt-6.1-sol', 'gpt-promax', 0.16, 84556, 161, 84352, 313 * 1024, true, 443, 6.6, 7.0, 1365, '消耗'],
|
|
13
|
+
['claude-opus-5-5', 'claude-max企业', 1.20, 42100, 580, 40000, 205 * 1024, true, 96, 2.1, 9.5, 9800, '消耗'],
|
|
14
|
+
['claude-sonnet-5-5', 'claude-kiro正价', 0.35, 51200, 240, 50112, 180 * 1024, true, 210, 1.8, 5.2, 1840, '消耗'],
|
|
15
|
+
['gemini-3-pro-preview', 'gemini', 0.30, 20480, 320, 18000, 96 * 1024, true, 158, 2.6, 6.1, 1200, '消耗'],
|
|
16
|
+
['deepseek-v3.2', '国模', 0.15, 30240, 180, 28800, 88 * 1024, true, 320, 1.2, 3.8, 180, '消耗'],
|
|
17
|
+
['kimi-k2.5', '国模', 0.15, 88320, 260, 87500, 260 * 1024, false, null, null, 4.0, 320, '消耗'],
|
|
18
|
+
['gpt-image-2.6', '绘图', 1.00, null, null, null, 12 * 1024, false, null, null, 8.2, 400, '消耗'],
|
|
19
|
+
['seedance-2.5', '视频', 1.00, null, null, null, 9 * 1024, false, null, null, 22.0, 1250, '消耗'],
|
|
20
|
+
['claude-opus-5-5', 'claude-kiro', 0.10, 15800, 120, 15000, 60 * 1024, true, 88, 2.4, 7.0, 1900, '消耗'],
|
|
21
|
+
];
|
|
22
|
+
const tokenNames = ['Magpie-gpt-plus', 'Magpie-claude', '脚本备用'];
|
|
23
|
+
const efforts = ['high', 'medium', ''];
|
|
24
|
+
return specs.flatMap(([model, group, ratio, input, output, cache, bytes, isStream, tps, ttft, dur, quota, kind], i) => {
|
|
25
|
+
// 每条规格复制成两行,时间往前推,制造出翻页与排序都可见的量
|
|
26
|
+
return [0, 1].map((k) => {
|
|
27
|
+
const idx = i * 2 + k;
|
|
28
|
+
const at = Math.floor(now / 1000) - (idx * 17 + k * 3) * 60;
|
|
29
|
+
const d = new Date(at * 1000);
|
|
30
|
+
const p = (x) => String(x).padStart(2, '0');
|
|
31
|
+
const detail = model.startsWith('seedance')
|
|
32
|
+
? '0.272k · ¥1.60 / 720p每秒'
|
|
33
|
+
: model.startsWith('gpt-image')
|
|
34
|
+
? '0.272k · ¥0.20 / 张'
|
|
35
|
+
: `0.272k · ¥2 / ¥10/M`;
|
|
36
|
+
return {
|
|
37
|
+
at: at * 1000,
|
|
38
|
+
atText: `${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`,
|
|
39
|
+
account: 'demo',
|
|
40
|
+
kind,
|
|
41
|
+
model,
|
|
42
|
+
group,
|
|
43
|
+
tokenName: tokenNames[idx % tokenNames.length],
|
|
44
|
+
upModel: k === 0 && model.startsWith('gpt') ? 'gpt-6.1-sol-high' : '',
|
|
45
|
+
respModel: '',
|
|
46
|
+
effort: efforts[idx % efforts.length],
|
|
47
|
+
input,
|
|
48
|
+
output,
|
|
49
|
+
cache,
|
|
50
|
+
bytes,
|
|
51
|
+
cost: `$${(quota / 500000).toFixed(5)}`,
|
|
52
|
+
costRaw: quota,
|
|
53
|
+
tps,
|
|
54
|
+
ttft,
|
|
55
|
+
dur,
|
|
56
|
+
detail,
|
|
57
|
+
isStream,
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** summarize 形状与 lib/usage.mjs 的 summarize 一致(byModel / buckets / rows)。 */
|
|
64
|
+
function summarizeRows(rows, cur, start, end) {
|
|
65
|
+
const span = Math.max(1, end - start);
|
|
66
|
+
const bucketMs = span <= 26 * 3600e3 ? 3600e3 : span <= 8 * 24 * 3600e3 ? 6 * 3600e3 : 24 * 3600e3;
|
|
67
|
+
const byModel = new Map();
|
|
68
|
+
const byBucket = new Map();
|
|
69
|
+
let spent = 0;
|
|
70
|
+
let tokens = 0;
|
|
71
|
+
for (const r of rows) {
|
|
72
|
+
if (!r.at || r.at < start || r.at > end) continue;
|
|
73
|
+
const cost = Number(r.costRaw) || 0;
|
|
74
|
+
const tok = (Number(r.input) || 0) + (Number(r.output) || 0);
|
|
75
|
+
spent += cost;
|
|
76
|
+
tokens += tok;
|
|
77
|
+
const key = r.model || '(未知)';
|
|
78
|
+
const had = byModel.get(key) || { model: key, tokens: 0, costRaw: 0, calls: 0 };
|
|
79
|
+
had.tokens += tok;
|
|
80
|
+
had.costRaw += cost;
|
|
81
|
+
had.calls += 1;
|
|
82
|
+
byModel.set(key, had);
|
|
83
|
+
const b = Math.floor((r.at - start) / bucketMs) * bucketMs + start;
|
|
84
|
+
const hb = byBucket.get(b) || { at: b, costRaw: 0, tokens: 0 };
|
|
85
|
+
hb.costRaw += cost;
|
|
86
|
+
hb.tokens += tok;
|
|
87
|
+
byBucket.set(b, hb);
|
|
88
|
+
}
|
|
89
|
+
const fmt = (raw) => `$${(raw / 500000).toFixed(4)}`;
|
|
90
|
+
return {
|
|
91
|
+
available: true,
|
|
92
|
+
spent: fmt(spent),
|
|
93
|
+
spentRaw: spent,
|
|
94
|
+
tokens,
|
|
95
|
+
start,
|
|
96
|
+
end,
|
|
97
|
+
byModel: [...byModel.values()].sort((a, b) => b.costRaw - a.costRaw).map((m) => ({ ...m, cost: fmt(m.costRaw) })),
|
|
98
|
+
buckets: [...byBucket.values()].sort((a, b) => a.at - b.at).map((b) => ({ ...b, cost: fmt(b.costRaw) })),
|
|
99
|
+
rows,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* createDemoApi 返回 (path, opts) => data。
|
|
105
|
+
* 只拦 GET 的读接口;写接口(建钥匙/删钥匙/转入余额)不拦——演示模式不该有副作用。
|
|
106
|
+
*/
|
|
107
|
+
export function createDemoApi() {
|
|
108
|
+
const now = Date.now();
|
|
109
|
+
const rows = makeRows(now);
|
|
110
|
+
|
|
111
|
+
const rangeOf = (range) => {
|
|
112
|
+
const end = now;
|
|
113
|
+
const start = range === 'week' ? now - 6 * DAY : range === 'month' ? now - 29 * DAY : now - (new Date(now).getHours() * 3600e3 + new Date(now).getMinutes() * 60e3);
|
|
114
|
+
return [start, end];
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
return async function demoRequest(path) {
|
|
118
|
+
await new Promise((r) => setTimeout(r, 120)); // 一点延迟,让「正在读取」状态可见
|
|
119
|
+
|
|
120
|
+
if (path === '/api/ping') return { ok: true, version: 'demo', port: 0 };
|
|
121
|
+
if (path === '/api/state') {
|
|
122
|
+
return {
|
|
123
|
+
ok: true,
|
|
124
|
+
site: 'https://newapi.dragon3api.com',
|
|
125
|
+
siteName: 'DragonAPI',
|
|
126
|
+
pat: { set: true, hint: 'nap_d****demo', scopes: ['profile:read', 'api_key:read', 'api_key:write'], verified: true },
|
|
127
|
+
currency: { symbol: '$', per: 500000, rate: 1, display: true },
|
|
128
|
+
accounts: {
|
|
129
|
+
'sk-demo': {
|
|
130
|
+
key: 'sk-demo', label: 'gpt-promax · sk-d****demo', group: 'gpt-promax',
|
|
131
|
+
masked: 'sk-d****demo', models: 124, boundAt: now - 3 * DAY,
|
|
132
|
+
balance: '$1.92', balanceRaw: 960000, used: '$68.19', usedRaw: 34095000,
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
groups: [['gpt-promax', 0.16], ['claude-kiro', 0.10], ['国模', 0.15], ['绘图', 1], ['视频', 1]],
|
|
136
|
+
counts: { models: 125, rows: 189, groups: 14 },
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
if (path.startsWith('/api/usage')) {
|
|
140
|
+
const range = new URL(path, 'http://x').searchParams.get('range') || 'day';
|
|
141
|
+
const [start, end] = rangeOf(range);
|
|
142
|
+
return summarizeRows(rows, null, start, end);
|
|
143
|
+
}
|
|
144
|
+
if (path === '/api/aff') {
|
|
145
|
+
return {
|
|
146
|
+
ok: true,
|
|
147
|
+
aff: { count: 2, quota: 12500, pending: 12500 },
|
|
148
|
+
code: '0mY4',
|
|
149
|
+
link: 'https://newapi.dragon3api.com/sign-up?aff=0mY4',
|
|
150
|
+
note: '',
|
|
151
|
+
at: now,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
if (path === '/api/keys') {
|
|
155
|
+
return {
|
|
156
|
+
ok: true,
|
|
157
|
+
keys: [
|
|
158
|
+
{ id: 101, name: 'Magpie-gpt-plus', group: 'gpt-promax', key: 'sk-demo-a**********101', status: 1, remainQuota: '∞', bound: true },
|
|
159
|
+
{ id: 102, name: 'Magpie-claude', group: 'claude-kiro', key: 'sk-demo-b**********102', status: 1, remainQuota: '$3.20', bound: false },
|
|
160
|
+
{ id: 103, name: '脚本备用', group: '国模', key: 'sk-demo-c**********103', status: 2, remainQuota: '$0.00', bound: false },
|
|
161
|
+
],
|
|
162
|
+
groups: ['gpt-promax', 'gpt-plus', 'claude-kiro', 'claude-kiro正价', 'claude-max企业', 'gemini', '国模', '绘图', '视频', '视频'],
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
if (path === '/api/bind-info') {
|
|
166
|
+
return {
|
|
167
|
+
ok: true,
|
|
168
|
+
how: [
|
|
169
|
+
'在 magpie 的供应商列表里打开 DragonAPI,点「添加账号」。',
|
|
170
|
+
'选「用访问令牌自动建钥匙」:插件会按你选的分组建一把新钥匙并自动绑定。',
|
|
171
|
+
'或者选「DragonAPI API Key」,把上面复制到的 sk- 钥匙粘进去。',
|
|
172
|
+
],
|
|
173
|
+
auto: { label: '用访问令牌自动建钥匙', method: 'pat' },
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
if (path.startsWith('/api/catalog')) {
|
|
177
|
+
// 目录演示数据:与 /api/catalog 服务端输出同形状(models[],每行一个分组价)。
|
|
178
|
+
// 挑 8 个模型 × 各自分组,覆盖对话/生图/视频三种计费。
|
|
179
|
+
const G = {
|
|
180
|
+
'claude-kiro': 0.10, 'claude-kiro正价': 0.35, 'claude-cursor': 0.40, 'claude-max企业': 1.20,
|
|
181
|
+
'gpt-plus': 0.10, 'gpt-pro': 0.16, 'gpt-promax': 0.16, 'gemini': 0.30, '国模': 0.15, 'image': 1, '视频': 1,
|
|
182
|
+
}
|
|
183
|
+
const spec = (name, vendor, kind, groups, inPrice, outPrice, cachePrice, desc, extra = {}) => ({
|
|
184
|
+
name, vendor,
|
|
185
|
+
kind,
|
|
186
|
+
groups: groups.map((g) => ({ id: g, ratio: G[g], note: '', auto: false })),
|
|
187
|
+
pricing: { kind: 'token', input: `$${inPrice}/M`, output: `$${outPrice}/M`, cache: `$${cachePrice}/M` },
|
|
188
|
+
desc, ...extra,
|
|
189
|
+
})
|
|
190
|
+
return {
|
|
191
|
+
ok: true,
|
|
192
|
+
models: [
|
|
193
|
+
spec('claude-fable-5-2', 'Anthropic', 'chat', ['claude-cursor', 'claude-max企业'], '3.20', '16.00', '0.08', 'Anthropic 的对话模型,支持 Anthropic 兼容 / OpenAI 兼容端点;按倍率计费。'),
|
|
194
|
+
spec('claude-opus-5-5', 'Anthropic', 'chat', ['claude-kiro', 'claude-kiro正价', 'claude-cursor', 'claude-max企业'], '0.40', '2.00', '0.02', 'Anthropic 的对话模型,分档计费。'),
|
|
195
|
+
spec('claude-sonnet-5-5', 'Anthropic', 'chat', ['claude-kiro', 'claude-kiro正价', 'claude-max企业'], '0.20', '1.00', '0.01', 'Anthropic 的对话模型,按倍率计费。'),
|
|
196
|
+
spec('gpt-6.1-sol', 'OpenAI', 'chat', ['gpt-plus', 'gpt-pro', 'gpt-promax'], '1.75', '14.00', '0.18', '通用推理与工具调用,支持多轮工作流。'),
|
|
197
|
+
spec('gemini-3-pro-preview', 'Google', 'chat', ['gemini'], '2.00', '12.00', '0.20', '多模态理解与复杂推理。'),
|
|
198
|
+
spec('deepseek-v3.2', 'DeepSeek', 'chat', ['国模'], '0.28', '0.42', '0.03', '通用对话、代码与中文写作。'),
|
|
199
|
+
spec('gpt-image-2.6', 'OpenAI', 'image', ['image'], '0.04', '0', '0', '根据提示生成或编辑图像。', { pricing: { kind: 'perimage', input: '$0.20/张', output: '$0.20/张' } }),
|
|
200
|
+
spec('seedance-2.5', '字节跳动', 'video', ['视频'], '0.30', '0', '0', '官方key 720p 4.30折。480p ¥0.30 / 720p ¥0.65 / 1080p ¥1.60 每秒。', { pricing: { kind: 'percall', input: '$0.30-1.60/秒', output: '$0.30-1.60/秒' } }),
|
|
201
|
+
],
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (path === '/api/health') {
|
|
205
|
+
return {
|
|
206
|
+
ok: true,
|
|
207
|
+
version: 'demo',
|
|
208
|
+
port: 3672,
|
|
209
|
+
site: 'https://newapi.dragon3api.com',
|
|
210
|
+
catalogVersion: 'demo-1',
|
|
211
|
+
history: [{ at: now, ok: true, source: 'live', ms: 180 }],
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
throw new Error(`演示模式没有准备这个接口:${path}`);
|
|
215
|
+
};
|
|
216
|
+
}
|
package/ui/icon.png
ADDED
|
Binary file
|