@fish-under-sea/magpie-dragonapi 1.0.5 → 1.0.7

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/lib/catalog.mjs CHANGED
@@ -35,6 +35,10 @@ export function kindOf(row) {
35
35
  if (ends.some((e) => /^(audio|tts|asr|transcription|speech)$/i.test(e))) return 'audio'
36
36
  if (ends.some((e) => /^(embedding|jina-rerank|rerank)$/i.test(e))) return 'embedding'
37
37
  const groups = Array.isArray(row?.enable_groups) ? row.enable_groups.join(' ').toLowerCase() : ''
38
+ const tags = String(row?.tags || '').toLowerCase()
39
+ // 站点把生图模型挂在 image 分组,endpoint 仍写 openai/gemini,单看 endpoint
40
+ // 会被误判成 chat,然后混进 LLM 列表、还带上思考强度。分组/tag 是可靠信号。
41
+ if (/image|图像|生图|绘图|绘画/.test(groups) || /图像|生图|绘图|绘画/.test(tags)) return 'image'
38
42
  if (/embedding|向量|rerank/.test(groups)) return 'embedding'
39
43
  return 'chat'
40
44
  }
@@ -153,7 +157,7 @@ export function buildCatalog(env, { cur, enabledGroups = [], site } = {}) {
153
157
  input: { text: true, image: false, audio: false, video: false, pdf: false },
154
158
  ...(kind === 'chat' ? { reasoning: true } : {}),
155
159
  },
156
- ...(kind === 'chat' ? { variants: { low: {}, medium: {}, high: {} } } : {}),
160
+ ...(kind === 'chat' ? { variants: { minimal: {}, low: {}, medium: {}, high: {}, xhigh: {}, max: {} } } : {}),
157
161
  // 排序用的私有字段,不进宿主(宿主会忽略不认识的键)
158
162
  _rank: [r0, r1, name],
159
163
  }
package/lib/service.mjs CHANGED
@@ -499,10 +499,20 @@ export async function startService({ port = 3517, dir = '.', site, catalog, stat
499
499
 
500
500
  // 推荐奖励转入余额:原样转发站点的结论,不替它编「成功」。
501
501
  if (path === '/api/aff/transfer' && req.method === 'POST') {
502
- const { st } = await stateOf()
502
+ const { st, cur } = await stateOf()
503
503
  if (!st.pat) { json(res, 400, { ok: false, error: '还没有设置访问令牌(PAT)' }); return }
504
+ let body = {}
505
+ try { body = (await readBody(req)) || {} } catch { throw new BadRequest('转入额度必须是 JSON') }
506
+ const per = Number(cur.per) > 0 ? Number(cur.per) : 500000
507
+ const quota = Math.floor(Number(body?.quota))
508
+ if (!Number.isFinite(quota) || quota <= 0) {
509
+ json(res, 400, { ok: false, error: '请填写要转入的额度' }); return
510
+ }
511
+ if (quota < per) {
512
+ json(res, 400, { ok: false, error: `站点最低一次转入 1 元(${cur.symbol || ''}1),请调高金额` }); return
513
+ }
504
514
  try {
505
- const r = await transferAff(site, st.pat)
515
+ const r = await transferAff(site, st.pat, { quota })
506
516
  json(res, 200, { ok: r.ok, message: r.message || (r.ok ? '已转入余额' : '站点没有说明原因') })
507
517
  } catch (e) {
508
518
  json(res, 502, { ok: false, error: `转入失败:${e?.message || e}` })
@@ -511,7 +521,7 @@ export async function startService({ port = 3517, dir = '.', site, catalog, stat
511
521
  }
512
522
  // 推荐计划:合并邀请码与真实 self 指标,部分读取失败原话放 note。
513
523
  if (path === '/api/aff' && req.method === 'GET') {
514
- const { st } = await stateOf()
524
+ const { st, cur } = await stateOf()
515
525
  if (!st.pat) { json(res, 400, { ok: false, error: '还没有设置访问令牌(PAT)' }); return }
516
526
  const result = await readAff(site, st.pat)
517
527
  const { code, note, ...aff } = result
@@ -520,6 +530,9 @@ export async function startService({ port = 3517, dir = '.', site, catalog, stat
520
530
  aff: Object.keys(aff).length ? aff : null,
521
531
  code,
522
532
  link: code ? `${site}/sign-up?aff=${encodeURIComponent(code)}` : '',
533
+ // 页面换算金额与最低 1 元门槛用;quota 是站点内部单位。
534
+ per: Number(cur.per) > 0 ? Number(cur.per) : 500000,
535
+ symbol: cur.symbol || '$',
523
536
  note,
524
537
  at: Date.now(),
525
538
  })
package/lib/site.mjs CHANGED
@@ -454,10 +454,14 @@ export async function readSubscriptions(site, pat, cur, now = Date.now()) {
454
454
  * 我们没有它的返回结构可依,所以原样把站点的 message 带回去——
455
455
  * 成功失败都以站点为准,不在这里替它编一句「已转入」。
456
456
  */
457
- export async function transferAff(site, pat) {
457
+ export async function transferAff(site, pat, { quota } = {}) {
458
+ const q = Number(quota)
458
459
  const env = await siteCall(site, '/api/user/aff_transfer', {
459
460
  method: 'POST',
460
461
  auth: { kind: 'pat', token: pat },
462
+ // 站点要求 JSON body;不带 body 会直接 EOF。quota 单位是站点内部 quota,
463
+ // 页面按 1 元 = 500000 quota 换算。
464
+ body: Number.isFinite(q) && q > 0 ? { quota: Math.floor(q) } : {},
461
465
  })
462
466
  return { ok: env?.success !== false, message: String(env?.message || ''), data: env?.data ?? null }
463
467
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fish-under-sea/magpie-dragonapi",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "DragonAPI for magpie: a provider plugin whose models, groups and prices come from the site's public /api/pricing, with balance and per-call usage from an sk- key, plus a local page that lists the market (read-only), shows usage and can mint new keys for a group.",
5
5
  "type": "module",
6
6
  "main": "index.mjs",
package/ui/app.js CHANGED
@@ -259,7 +259,7 @@ const api = {
259
259
  keys: () => request('/api/keys'),
260
260
  aff: () => request('/api/aff'),
261
261
  subscriptions: () => request('/api/subscriptions'),
262
- transferAff: () => request('/api/aff/transfer', { method: 'POST' }),
262
+ transferAff: (body) => request('/api/aff/transfer', { method: 'POST', body }),
263
263
  createKey: (body) => request('/api/keys', { method: 'POST', body }),
264
264
  updateKey: (id, body) => request(`/api/keys/${encodeURIComponent(id)}`, { method: 'PUT', body }),
265
265
  deleteKey: (id) => request(`/api/keys/${encodeURIComponent(id)}`, { method: 'DELETE' }),
@@ -1470,9 +1470,6 @@ function subscriptionCard(s) {
1470
1470
  // 站点 /api/user/aff 的字段名随部署而变(aff_count/aff_quota 是 New API 常见写法,
1471
1471
  // 「待确认」没有公认键名),所以每列只在真拿到数字时才渲染。
1472
1472
 
1473
- /** 转入余额需二次确认:第一下改成「确认转入」,5 秒内再点才真的发请求。 */
1474
- let affTransferArmedUntil = 0;
1475
-
1476
1473
  function renderAff() {
1477
1474
  const box = $('#aff-body');
1478
1475
  if (!box) return;
@@ -1485,12 +1482,12 @@ function renderAff() {
1485
1482
 
1486
1483
  const link = d.link || '';
1487
1484
  const a = d.aff || {};
1485
+ const per = Number(d.per) > 0 ? Number(d.per) : 500000;
1488
1486
  // 三列:待确认(站点给才显示)/ 总收入 / 邀请。只认真实值,不拿 0 假装同步过。
1489
1487
  const pending = Number.isFinite(a.pending) ? moneyRaw(a.pending) : null;
1490
1488
  const total = Number.isFinite(a.historyQuota) ? moneyRaw(a.historyQuota) : null;
1491
1489
  const invites = Number.isFinite(a.count) ? fmtInt(a.count) : null;
1492
1490
  const canTransfer = Number.isFinite(a.quota) && a.quota > 0;
1493
- const armed = Date.now() < affTransferArmedUntil;
1494
1491
 
1495
1492
  // replaceChildren 收 null 会把它印成字符串「null」——先过滤再加。
1496
1493
  box.replaceChildren(...[
@@ -1512,16 +1509,17 @@ function renderAff() {
1512
1509
  link
1513
1510
  ? h('button', {
1514
1511
  class: 'rf-copy', type: 'button', title: '复制推荐链接', 'aria-label': '复制推荐链接',
1515
- onclick: (ev) => copyText(link, ev.currentTarget, '已复制'),
1512
+ // 按钮只有 30px 宽;「已复制」会竖排溢出,用对勾表示成功。
1513
+ onclick: (ev) => copyText(link, ev.currentTarget, '✓'),
1516
1514
  }, copyIcon())
1517
1515
  : null,
1518
1516
  canTransfer
1519
1517
  ? h('button', {
1520
- class: `btn primary rf-transfer${armed ? ' is-armed' : ''}`,
1518
+ class: 'btn primary rf-transfer',
1521
1519
  type: 'button',
1522
1520
  title: '把累计奖励转到余额(站点上的真实资金操作)',
1523
- onclick: (ev) => transferAffRewards(ev.currentTarget),
1524
- }, armed ? '确认转入' : '转移到余额')
1521
+ onclick: () => openAffTransfer(a, per, d.symbol || '$'),
1522
+ }, '转移到余额')
1525
1523
  : null),
1526
1524
  ].filter(Boolean));
1527
1525
  }
@@ -1533,29 +1531,64 @@ function rfStat(k, v) {
1533
1531
  h('div', { class: 'rf-v', text: v }));
1534
1532
  }
1535
1533
 
1536
- /** transferAffRewards 转账:两段式确认(沙箱里 window.confirm 会被拦成 false)。 */
1537
- async function transferAffRewards(btn) {
1538
- if (Date.now() >= affTransferArmedUntil) {
1539
- affTransferArmedUntil = Date.now() + 5000;
1540
- renderAff();
1541
- banner('info', '再点一次「确认转入」,就会把累计奖励转进余额。', { key: 'aff-transfer', timeout: 5000 });
1542
- return;
1543
- }
1534
+ /** closeAffTransfer 关掉转入浮窗。 */
1535
+ function closeAffTransfer() {
1536
+ const m = document.querySelector('.aff-modal');
1537
+ if (m) m.remove();
1538
+ }
1544
1539
 
1545
- affTransferArmedUntil = 0;
1546
- btn.disabled = true;
1547
- btn.textContent = '转入中…';
1548
- try {
1549
- const r = await api.transferAff();
1550
- banner(r.ok ? 'ok' : 'warn', r.message || (r.ok ? '已转入余额' : '站点没有说明原因'), { key: 'aff-transfer' });
1551
- await Promise.all([loadAff(true), loadState(true)]);
1552
- renderAccounts();
1553
- } catch (err) {
1554
- banner('error', `转入失败:${describeError(err)}`, { key: 'aff-transfer' });
1555
- } finally {
1556
- btn.disabled = false;
1557
- renderAff();
1558
- }
1540
+ /**
1541
+ * openAffTransfer:和上游一样的浮窗输入金额,最低 1 元。
1542
+ * 站点 /api/user/aff_transfer 要 JSON body(quota 内部单位),不带会 EOF。
1543
+ */
1544
+ function openAffTransfer(a, per, symbol) {
1545
+ closeAffTransfer();
1546
+ const available = Number(a?.quota) > 0 ? Number(a.quota) / per : 0;
1547
+ const amount = h('input', {
1548
+ class: 'aff-amount', type: 'number', min: '1', step: '0.01', inputmode: 'decimal',
1549
+ value: available >= 1 ? String(Math.floor(available * 100) / 100) : '1',
1550
+ 'aria-label': '转入金额',
1551
+ });
1552
+ const error = h('p', { class: 'aff-modal-error', role: 'alert' });
1553
+ const confirm = h('button', { class: 'btn primary', type: 'button' }, '确认转入');
1554
+ const overlay = h('div', { class: 'aff-modal', role: 'dialog', 'aria-modal': 'true', 'aria-label': '转入余额' },
1555
+ h('div', { class: 'aff-modal-panel' },
1556
+ h('h3', { text: '转入余额' }),
1557
+ h('p', {
1558
+ class: 'aff-modal-hint',
1559
+ text: `可转奖励 ${symbol}${available.toFixed(2)};单次最低 1 元,按站点规则换算成 quota。`,
1560
+ }),
1561
+ h('label', { class: 'aff-modal-field' }, '转入金额', amount),
1562
+ error,
1563
+ h('div', { class: 'aff-modal-actions' },
1564
+ h('button', { class: 'btn ghost', type: 'button', onclick: closeAffTransfer }, '取消'),
1565
+ confirm)));
1566
+ overlay.addEventListener('click', (ev) => { if (ev.target === overlay) closeAffTransfer(); });
1567
+ const onKey = (ev) => { if (ev.key === 'Escape') { closeAffTransfer(); document.removeEventListener('keydown', onKey); } };
1568
+ document.addEventListener('keydown', onKey);
1569
+ confirm.addEventListener('click', async () => {
1570
+ const yuan = Number(amount.value);
1571
+ if (!Number.isFinite(yuan) || yuan < 1) { error.textContent = '最低转入 1 元。'; return; }
1572
+ if (available > 0 && yuan > available + 1e-6) { error.textContent = `最多可转 ${symbol}${available.toFixed(2)}。`; return; }
1573
+ error.textContent = '';
1574
+ confirm.disabled = true;
1575
+ confirm.textContent = '转入中…';
1576
+ try {
1577
+ const r = await api.transferAff({ quota: Math.round(yuan * per) });
1578
+ closeAffTransfer();
1579
+ document.removeEventListener('keydown', onKey);
1580
+ banner(r.ok ? 'ok' : 'warn', r.message || (r.ok ? '已转入余额' : '站点没有说明原因'), { key: 'aff-transfer' });
1581
+ await Promise.all([loadAff(true), loadState(true)]);
1582
+ renderAccounts();
1583
+ } catch (err) {
1584
+ error.textContent = `转入失败:${describeError(err)}`;
1585
+ confirm.disabled = false;
1586
+ confirm.textContent = '确认转入';
1587
+ }
1588
+ });
1589
+ document.body.append(overlay);
1590
+ amount.focus();
1591
+ amount.select();
1559
1592
  }
1560
1593
 
1561
1594
  /** 分享图标:三个节点由连线相接(与原站同一图形语言),放在圆形底上。 */
@@ -1623,10 +1656,8 @@ function renderAccounts() {
1623
1656
 
1624
1657
  const bound = Array.isArray(st.accounts) ? st.accounts : Object.values(st.accounts || {});
1625
1658
  const user = st.user;
1626
- const accounts = [
1627
- ...(user ? [{ ...user, wallet: true, label: user.displayName || user.username, models: undefined }] : []),
1628
- ...bound,
1629
- ];
1659
+ // 钱包只显示主账户;绑定钥匙的额度不再各占一张卡(它们仍在上方计数与密钥页)。
1660
+ const accounts = user ? [{ ...user, wallet: true, label: user.displayName || user.username, models: undefined }] : [];
1630
1661
  if (sub) sub.textContent = [user ? 'PAT 账户钱包' : '', bound.length ? `${bound.length} 把绑定钥匙` : ''].filter(Boolean).join(' · ');
1631
1662
  // 空态时让说明在卡里居中,而不是顶在上面、下面留一大片空白
1632
1663
  box.classList.toggle('is-empty', accounts.length === 0);
package/ui/style.css CHANGED
@@ -3459,3 +3459,23 @@ input.keys-input:focus-visible, select.keys-select:focus-visible {
3459
3459
  pointer-events: auto; background: var(--card);
3460
3460
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
3461
3461
  }
3462
+
3463
+ /* 推荐计划:转入余额浮窗(沙箱里不能用 window.confirm) */
3464
+ .aff-modal {
3465
+ position: fixed; inset: 0; z-index: 500; display: grid; place-items: center;
3466
+ padding: 18px; background: rgba(0, 0, 0, .55);
3467
+ }
3468
+ .aff-modal-panel {
3469
+ width: min(380px, 100%); border: 1px solid var(--line-strong); border-radius: var(--radius);
3470
+ background: var(--card); padding: 16px; display: flex; flex-direction: column; gap: 10px;
3471
+ box-shadow: 0 18px 48px rgba(0, 0, 0, .5);
3472
+ }
3473
+ .aff-modal-panel h3 { margin: 0; font-size: 14px; }
3474
+ .aff-modal-hint { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
3475
+ .aff-modal-field { display: flex; flex-direction: column; gap: 6px; font-size: 11.5px; color: var(--muted); }
3476
+ .aff-amount {
3477
+ height: 34px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line-strong);
3478
+ background: var(--sunken); color: var(--fg); font: inherit;
3479
+ }
3480
+ .aff-modal-error { margin: 0; min-height: 16px; color: var(--bad); font-size: 11.5px; }
3481
+ .aff-modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 2px; }