dsh-tokenbank 0.1.71 → 0.1.73

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/client.js CHANGED
@@ -30,11 +30,12 @@ window.__ModuleLoader__.load({
30
30
  addFreeModels: '获取免费模型',
31
31
  getModels: '获取模型',
32
32
  freeModelsTip: '免费使用主流收费模型,点击后自动获取,模型列表 TokenBank 中的模型任意使用。',
33
- modelLinked: '已接入 {n} 个模型',
33
+ modelLinked: '已接入 {n} 个模型,点输入框上方的模型选择器即可切换使用',
34
34
  reload: '刷新',
35
35
  recharge: '充值',
36
36
  rechargeTip: '全网最低价:¥10 ≈ 3846万 TOKEN,比官方与中转站省 10%~25%;支付宝直付秒到账,余额永不过期。',
37
37
  depositManage: '托管',
38
+ depositGuide: '已打开模型设置,点卡片上的「一键托管」即可把 API Key 托管到 TokenBank',
38
39
  depositManageTip: '把你的 API Key 托管到 TokenBank,临时额度自动转移为永久额度保留使用。适用于周重置快到了还没用完等情况。',
39
40
  checkin: '签到',
40
41
  checkinDone: '已签到',
@@ -133,10 +134,11 @@ window.__ModuleLoader__.load({
133
134
  getModels: 'Get models',
134
135
  freeModelsTip: 'Use paid-tier models for free — one click links them, and every TokenBank model in the list is available.',
135
136
  rechargeTip: 'Best price anywhere: $1 for ¥6.50 — 10%~25% cheaper than official APIs and relays. Pay with Alipay, credited instantly, credit never expires.',
136
- modelLinked: '{n} models linked',
137
+ modelLinked: '{n} models linked — open the model picker above the input to switch to them',
137
138
  reload: 'Reload',
138
139
  recharge: 'Recharge',
139
140
  depositManage: 'Manage keys',
141
+ depositGuide: 'Model settings opened — click "Manage keys" on a provider card to deposit your key',
140
142
  depositManageTip: 'Deposit your API key into TokenBank — remaining temporary quota transfers to permanent credit. Useful when the weekly reset is near.',
141
143
  checkin: 'Check in',
142
144
  checkinDone: 'Checked in',
@@ -345,13 +347,24 @@ window.__ModuleLoader__.load({
345
347
  function BalancePill() {
346
348
  var snap = useTbStore()
347
349
  var st = React.useState(null)
350
+ // 登录跃迁(false→true)自动同步一次免费模型;初始挂载已登录不触发
351
+ var prevLogin = React.useRef(null)
348
352
  React.useEffect(function () {
349
353
  var stopped = false
350
354
  api('status').then(function (data) {
351
- if (!stopped) { st[1](data); tbStore.set({ loggedIn: Boolean(data.loggedIn), portalUrl: data.portalUrl }) }
355
+ if (stopped) return
356
+ st[1](data); tbStore.set({ loggedIn: Boolean(data.loggedIn), portalUrl: data.portalUrl })
357
+ var now = Boolean(data.loggedIn)
358
+ if (prevLogin.current === false && now) autoSyncModels()
359
+ prevLogin.current = now
352
360
  }).catch(function () {})
353
361
  return function () { stopped = true }
354
362
  }, [])
363
+ React.useEffect(function () {
364
+ var now = Boolean(snap.loggedIn)
365
+ if (prevLogin.current === false && now) { prevLogin.current = now; autoSyncModels() }
366
+ else if (prevLogin.current !== null) prevLogin.current = now
367
+ }, [snap.loggedIn])
355
368
  React.useEffect(function () {
356
369
  var stopped = false
357
370
  if (!snap.loggedIn) return
@@ -420,13 +433,24 @@ window.__ModuleLoader__.load({
420
433
  })
421
434
  }
422
435
  var st = React.useState(null)
436
+ // 登录跃迁(false→true)自动同步一次免费模型;初始挂载已登录不触发
437
+ var prevLogin = React.useRef(null)
423
438
  React.useEffect(function () {
424
439
  var stopped = false
425
440
  api('status').then(function (data) {
426
- if (!stopped) { st[1](data); tbStore.set({ loggedIn: Boolean(data.loggedIn), portalUrl: data.portalUrl }) }
441
+ if (stopped) return
442
+ st[1](data); tbStore.set({ loggedIn: Boolean(data.loggedIn), portalUrl: data.portalUrl })
443
+ var now = Boolean(data.loggedIn)
444
+ if (prevLogin.current === false && now) autoSyncModels()
445
+ prevLogin.current = now
427
446
  }).catch(function () {})
428
447
  return function () { stopped = true }
429
448
  }, [])
449
+ React.useEffect(function () {
450
+ var now = Boolean(snap.loggedIn)
451
+ if (prevLogin.current === false && now) { prevLogin.current = now; autoSyncModels() }
452
+ else if (prevLogin.current !== null) prevLogin.current = now
453
+ }, [snap.loggedIn])
430
454
  // 登录态变化(弹窗登录/退出)时刷新余额展示
431
455
  React.useEffect(function () {
432
456
  var stopped = false
@@ -437,6 +461,8 @@ window.__ModuleLoader__.load({
437
461
  return function () { stopped = true }
438
462
  }, [snap.loggedIn, snap.authOpen])
439
463
  var data = st[0]
464
+ // 登录态入口整个不渲染(余额在底部状态栏 pill),否则会残留一个空胶囊
465
+ if (snap.loggedIn) return null
440
466
  return h('button', {
441
467
  type: 'button',
442
468
  id: 'tb-entry-btn',
@@ -464,33 +490,38 @@ window.__ModuleLoader__.load({
464
490
  /** shell.overlay 轻提示:portal 到 document.body,压过设置页抽屉层级。 */
465
491
  function NotifyOverlay() {
466
492
  var snap = useTbStore()
493
+ // 宿主风格:顶部居中深色胶囊,非阻塞,6s 自动消失,点击关闭
494
+ React.useEffect(function () {
495
+ if (!snap.notify) return
496
+ var timer = window.setTimeout(function () { tbStore.set({ notify: null }) }, 6000)
497
+ return function () { window.clearTimeout(timer) }
498
+ }, [snap.notify && snap.notify.title, snap.notify && snap.notify.seq])
467
499
  if (!snap.notify || !ReactDOM || typeof ReactDOM.createPortal !== 'function') return null
468
500
  var n = snap.notify
469
501
  var ok = n.kind === 'success'
470
502
  var close = function () { tbStore.set({ notify: null }) }
471
503
  return ReactDOM.createPortal(
472
504
  h('div', {
505
+ onClick: close,
473
506
  style: {
474
- position: 'fixed', inset: 0, zIndex: 3000,
475
- display: 'flex', alignItems: 'center', justifyContent: 'center',
476
- background: 'rgba(0,0,0,0.35)',
507
+ position: 'fixed', top: 52, left: '50%', transform: 'translateX(-50%)', zIndex: 3000,
508
+ display: 'inline-flex', alignItems: 'center', gap: 8, cursor: 'pointer',
509
+ maxWidth: '86vw', padding: '9px 16px', borderRadius: 10,
510
+ background: 'rgba(30, 30, 32, 0.96)', color: '#f5f5f5',
511
+ border: 'none',
512
+ boxShadow: '0 8px 24px rgba(0,0,0,0.35)',
513
+ fontSize: 13, lineHeight: 1.5, pointerEvents: 'auto',
477
514
  },
478
- onClick: close,
479
515
  },
480
- h('div', {
481
- style: {
482
- background: 'var(--dsw-alias-bg-base)', color: 'var(--dsw-alias-label-primary)',
483
- borderRadius: 12, padding: 16, width: 320, maxWidth: '86vw',
484
- boxShadow: '0 12px 40px rgba(0,0,0,0.25)',
485
- },
486
- onClick: function (e) { e.stopPropagation() },
487
- },
488
- h('div', { style: { fontSize: 14, fontWeight: 700, marginBottom: n.detail ? 6 : 0 } },
489
- (ok ? '✅ ' : '⚠️ ') + n.title),
490
- n.detail ? h('div', { style: { fontSize: 12, color: 'var(--dsw-alias-label-secondary)', whiteSpace: 'pre-wrap', wordBreak: 'break-all' } }, n.detail) : null,
491
- h('div', { style: { display: 'flex', justifyContent: 'flex-end', marginTop: 12 } },
492
- h('button', { type: 'button', style: buttonStyle, onClick: close }, pageT('notifyOk'))),
516
+ h('span', { style: { flexShrink: 0, display: 'inline-flex' } },
517
+ ok
518
+ ? h('svg', { viewBox: '0 0 24 24', width: 15, height: 15, fill: 'none', stroke: '#34c759', 'stroke-width': 2, 'stroke-linecap': 'round', 'stroke-linejoin': 'round' },
519
+ h('circle', { cx: 12, cy: 12, r: 10 }), h('polyline', { points: '8 12.5 11 15.5 16 9.5' }))
520
+ : h('svg', { viewBox: '0 0 24 24', width: 15, height: 15, fill: 'none', stroke: '#ffd60a', 'stroke-width': 2, 'stroke-linecap': 'round', 'stroke-linejoin': 'round' },
521
+ h('circle', { cx: 12, cy: 12, r: 10 }), h('line', { x1: 12, y1: 7.5, x2: 12, y2: 13 }), h('circle', { cx: 12, cy: 16.5, r: 0.5, fill: '#ffd60a' })),
493
522
  ),
523
+ h('span', { style: { fontWeight: 600 } }, n.title),
524
+ n.detail ? h('span', { style: { opacity: 0.75, fontSize: 12, whiteSpace: 'pre-wrap', wordBreak: 'break-all' } }, n.detail) : null,
494
525
  ),
495
526
  document.body,
496
527
  )
@@ -875,6 +906,24 @@ window.__ModuleLoader__.load({
875
906
  var timer = setInterval(pull, 60000)
876
907
  return function () { stopped = true; clearInterval(timer) }
877
908
  }, [snap.authOpen])
909
+ // 登录态下每 30 分钟拉一次网关模型目录并刷新进模型列表(仅保留有可用凭证的模型);
910
+ // 退出登录(snap.loggedIn 变 false)即清定时器,不再同步。
911
+ React.useEffect(function () {
912
+ if (!snap.loggedIn) return
913
+ var syncModels = async function () {
914
+ try {
915
+ var d = await api('status')
916
+ if (!d || !d.loggedIn || !runtimeCtx) return
917
+ var models = await api('gateway-models', { accessKey: d.accessKey })
918
+ var list = (models && models.models) || []
919
+ if (!list.length) return
920
+ await addProviderToModels(runtimeCtx, d.baseURL || d.portalUrl || 'https://bank.skillpie.cn', { accessKey: d.accessKey, list: list, protocol: models.protocol })
921
+ } catch (e) { /* 静默:后台同步失败不打扰用户 */ }
922
+ }
923
+ syncModels()
924
+ var t = window.setInterval(syncModels, 30 * 60 * 1000)
925
+ return function () { window.clearInterval(t) }
926
+ }, [snap.loggedIn])
878
927
  if (!snap.authOpen || !runtimeCtx) return null
879
928
  var close = function () { tbStore.set({ authOpen: false, startRecharge: false }) }
880
929
  var data = st[0]
@@ -932,6 +981,7 @@ window.__ModuleLoader__.load({
932
981
  st[1](null)
933
982
  try { window.localStorage.removeItem('tb-free-models-used') } catch (e) {}
934
983
  tbStore.set({ loggedIn: false })
984
+ if (runtimeCtx) removeProviderFromModels(runtimeCtx)
935
985
  },
936
986
  },
937
987
  h('svg', { viewBox: '0 0 24 24', width: 15, height: 15, fill: 'none', stroke: 'currentColor', 'stroke-width': 2, 'stroke-linecap': 'round', 'stroke-linejoin': 'round' },
@@ -972,7 +1022,12 @@ window.__ModuleLoader__.load({
972
1022
  type: 'button', 'aria-label': pageT('depositManageTip'),
973
1023
  style: Object.assign({}, buttonStyle, { height: 26, padding: '0 12px', fontSize: 12, borderColor: 'var(--dsw-alias-border-l2, #c9ccd1)' }),
974
1024
  onMouseEnter: function () { showTipOnce('deposit') },
975
- onClick: function () { depTip[1](null); tbStore.set({ authOpen: false }); openSettingsPage() },
1025
+ onClick: function () {
1026
+ depTip[1](null)
1027
+ tbStore.set({ authOpen: false })
1028
+ tbStore.set({ notify: { kind: 'success', title: pageT('depositGuide'), detail: '' } })
1029
+ openSettingsPage()
1030
+ },
976
1031
  }, pageT('depositManage')) : null,
977
1032
  h('button', {
978
1033
  type: 'button', disabled: checkin[0].busy,
@@ -997,8 +1052,7 @@ window.__ModuleLoader__.load({
997
1052
  balanceGain[1]({ amount: gain || '0.10', ts: Date.now() })
998
1053
  window.setTimeout(function () { balanceGain[1](null) }, 8000)
999
1054
  var streakText = ci.streak > 1 ? '(' + pageT('checkinStreak').replace('{n}', String(ci.streak)) + ')' : ''
1000
- checkinFlash[1]({ text: pageT('checkinOk') + streakText })
1001
- window.setTimeout(function () { checkinFlash[1](null) }, 3000)
1055
+ tbStore.set({ notify: { kind: 'success', title: pageT('checkinOk') + streakText, detail: '' } })
1002
1056
  }
1003
1057
  } catch (e9) {
1004
1058
  checkin[1](Object.assign({}, checkin[0], { busy: false }))
@@ -1047,7 +1101,7 @@ window.__ModuleLoader__.load({
1047
1101
  }, 80)
1048
1102
  },
1049
1103
  }, pageT('goSwitch')) : null,
1050
- ) : !rechargeOpen[0] ? (checkinFlash[0] ? h('button', {
1104
+ ) : (checkinFlash[0] ? h('button', {
1051
1105
  type: 'button', tabIndex: -1,
1052
1106
  style: Object.assign({}, primaryButtonStyle, { justifyContent: 'center', cursor: checkinFlash[0].models ? 'pointer' : 'default', opacity: 0.9 }),
1053
1107
  onClick: checkinFlash[0].models ? function () {
@@ -1061,30 +1115,7 @@ window.__ModuleLoader__.load({
1061
1115
  }
1062
1116
  }, 80)
1063
1117
  } : undefined,
1064
- }, checkinFlash[0].text) : h('button', {
1065
- type: 'button', style: Object.assign({}, primaryButtonStyle, { justifyContent: 'center' }),
1066
- onMouseEnter: function () { showTipOnce('models') },
1067
- onClick: async function () {
1068
- try {
1069
- var models = await api('gateway-models', { accessKey: data.accessKey })
1070
- var list = Array.isArray(models) ? models : (models.models || models.list || [])
1071
- await addProviderToModels(runtimeCtx, data.baseURL || portal, { accessKey: data.accessKey, list: list, protocol: models.protocol })
1072
- checkinFlash[1]({ text: pageT('modelLinked').replace('{n}', String(list.length)), models: true })
1073
- window.setTimeout(function () { checkinFlash[1](null) }, 3000)
1074
- // 模型接入成功即关弹窗,自动弹出宿主模型选择器(与签到闪现按钮同款时序)
1075
- tbStore.set({ authOpen: false })
1076
- window.setTimeout(function () {
1077
- var triggers = document.querySelectorAll('button[aria-haspopup="menu"]')
1078
- for (var q = 0; q < triggers.length; q++) {
1079
- var lb = triggers[q].getAttribute('aria-label') || ''
1080
- if (/选择模型|Select model/.test(lb)) { triggers[q].click(); return }
1081
- }
1082
- }, 80)
1083
- } catch (err) {
1084
- tbStore.set({ notify: { kind: 'error', title: String(err.message || err), detail: '' } })
1085
- }
1086
- },
1087
- }, pageT('addFreeModels'))) : null,
1118
+ }, checkinFlash[0].text) : null),
1088
1119
  )
1089
1120
  : h(AuthCard, {
1090
1121
  mode: snap.authMode,
@@ -1424,6 +1455,38 @@ window.__ModuleLoader__.load({
1424
1455
  return { ok: true }
1425
1456
  }
1426
1457
 
1458
+ /** 登录后自动同步一次免费模型(写 provider,失败静默,不打扰用户)。 */
1459
+ async function autoSyncModels() {
1460
+ try {
1461
+ if (!runtimeCtx || !runtimeCtx.remote || !runtimeCtx.remote.settings) return
1462
+ var fresh = await api('status')
1463
+ if (!fresh || !fresh.accessKey) return
1464
+ var models = await api('gateway-models', { accessKey: fresh.accessKey })
1465
+ var list = Array.isArray(models) ? models : (models.models || models.list || [])
1466
+ await addProviderToModels(runtimeCtx, fresh.baseURL || fresh.portalUrl, { accessKey: fresh.accessKey, list: list, protocol: models.protocol, key: fresh.accessKey })
1467
+ tbStore.set({ notify: { kind: 'success', title: pageT('modelLinked').replace('{n}', String(list.length)), detail: '' } })
1468
+ } catch (e) {
1469
+ console.warn('[dsh-tokenbank] auto sync models failed:', String(e && e.message || e))
1470
+ }
1471
+ }
1472
+
1473
+ /** 退出登录:从模型列表移除 TokenBank provider(尽力而为,失败不阻塞登出)。 */
1474
+ async function removeProviderFromModels(ctx) {
1475
+ try {
1476
+ const describe = await ctx.remote.settings.describe()
1477
+ const view = describe?.namespaces?.[MODEL_NS] ?? null
1478
+ const revision = view && typeof view.revision === 'number' ? view.revision : undefined
1479
+ const response = await ctx.remote.settings.mutate(MODEL_NS,
1480
+ [{ op: 'unset', path: ['providers', MODEL_ROUTE] }], revision)
1481
+ if (response && response.ok === false) {
1482
+ // 目标不存在(settings/target-missing 之类)视为已删除
1483
+ console.warn('[dsh-tokenbank] remove provider:', response.error?.code || response.error?.message)
1484
+ }
1485
+ } catch (e) {
1486
+ console.warn('[dsh-tokenbank] remove provider failed:', String(e && e.message || e))
1487
+ }
1488
+ }
1489
+
1427
1490
  /* ── auth forms ─────────────────────────────────────────────────────── */
1428
1491
 
1429
1492
  function AuthCard(props) {
package/locale/en.json CHANGED
@@ -11,6 +11,7 @@
11
11
  "learnMore": "About TokenBank →",
12
12
  "freeModelsEntry": "TokenBank free models",
13
13
  "addFreeModels": "Get free models",
14
+ "modelLinked": "{n} models linked — open the model picker above the input to switch to them",
14
15
  "composerEntry": "TokenBank account",
15
16
  "officialSite": "TokenBank website",
16
17
  "reload": "Reload",
@@ -20,6 +21,7 @@
20
21
  "rechargeDone": "Recharge successful",
21
22
  "rechargePending": "No payment detected yet; if you already paid, retry or refresh later",
22
23
  "depositManage": "Manage keys",
24
+ "depositGuide": "Model settings opened — click \"Manage keys\" on a provider card to deposit your key",
23
25
  "rechargeWaiting": "Waiting for payment…",
24
26
  "rechargeOpenPay": "Open payment page",
25
27
  "rechargeCancel": "Cancel",
package/locale/zh.json CHANGED
@@ -11,6 +11,7 @@
11
11
  "learnMore": "了解 TokenBank →",
12
12
  "freeModelsEntry": "TokenBank 免费模型",
13
13
  "addFreeModels": "获取免费模型",
14
+ "modelLinked": "已接入 {n} 个模型,点输入框上方的模型选择器即可切换使用",
14
15
  "composerEntry": "TokenBank 账户",
15
16
  "officialSite": "TokenBank 官网",
16
17
  "reload": "刷新",
@@ -20,6 +21,7 @@
20
21
  "rechargeDone": "充值成功,余额已到账",
21
22
  "rechargePending": "尚未检测到支付结果,如已完成支付请稍后重试或刷新",
22
23
  "depositManage": "托管",
24
+ "depositGuide": "已打开模型设置,点卡片上的「一键托管」即可把 API Key 托管到 TokenBank",
23
25
  "rechargeWaiting": "等待支付中…",
24
26
  "rechargeOpenPay": "打开支付页",
25
27
  "rechargeCancel": "取消",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-tokenbank",
3
- "version": "0.1.71",
3
+ "version": "0.1.73",
4
4
  "description": "DSH 免费模型:一键注册 TokenBank 领免费 APIKey 送 $5 体验金,免费 GLM 模型直接进模型列表;自带余额查询、API Key 密钥托管(临时额度转永久)、每日签到、充值入口(支付宝),获取免费模型无需自建中转。致敬 dsh-our-free-model。官网 https://bank.skillpie.cn",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -48,4 +48,4 @@
48
48
  "publishConfig": {
49
49
  "access": "public"
50
50
  }
51
- }
51
+ }