dsh-connect-workbuddy-gateway 1.5.3 → 1.5.4

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.
Files changed (2) hide show
  1. package/client.js +59 -7
  2. package/package.json +1 -1
package/client.js CHANGED
@@ -124,6 +124,9 @@ window.__ModuleLoader__.load({
124
124
  pairingShareName: '本机名称',
125
125
  pairingShareNameHint: '对方在列表里会看到这个名字,留空则只显示 IP。',
126
126
  pairingSaveName: '保存名称',
127
+ pairingRefresh: '刷新',
128
+ pairingRefreshing: '刷新中…',
129
+ pairingAutoHint: '页面每 10 秒自动检查一次',
127
130
  /* 已分享的凭据 */
128
131
  shares: '已分享出去的凭据',
129
132
  sharesEmpty: '还没有分享给任何设备',
@@ -295,6 +298,9 @@ window.__ModuleLoader__.load({
295
298
  pairingShareName: 'Machine name',
296
299
  pairingShareNameHint: 'Other devices see this in their list; leave empty to show only the IP.',
297
300
  pairingSaveName: 'Save name',
301
+ pairingRefresh: 'Refresh',
302
+ pairingRefreshing: 'Refreshing...',
303
+ pairingAutoHint: 'Checked automatically every 10 s',
298
304
  /* Issued credentials */
299
305
  shares: 'Shared credentials',
300
306
  sharesEmpty: 'Nothing has been shared yet',
@@ -1246,10 +1252,27 @@ window.__ModuleLoader__.load({
1246
1252
  * 这一屏是「谁可以拿走我的模型额度」的唯一决策点,所以它把三件事摆明:
1247
1253
  * 谁在申请、要分享哪些模型、会新建一把专用 key。
1248
1254
  */
1249
- function PairingCard({ state, t, onApprove, onDeny, onSaveShareName, onRevoke }) {
1255
+ function PairingCard({ state, t, onApprove, onDeny, onSaveShareName, onRevoke, onRefresh }) {
1250
1256
  const pairing = state?.pairing ?? {}
1251
1257
  const pending = Array.isArray(pairing.pending) ? pairing.pending : []
1252
1258
  const shares = Array.isArray(state?.shares) ? state.shares : []
1259
+ const [refreshing, setRefreshing] = useState(false)
1260
+
1261
+ /*
1262
+ * 手动刷新待批准列表。
1263
+ *
1264
+ * 之前只能靠「切到别的界面再切回来」—— 因为整页只在挂载时读一次(后来
1265
+ * 加了定时刷新,但最长要等 30 秒)。对方点了申请,这边却看不到,很容易
1266
+ * 以为申请没发出去。
1267
+ */
1268
+ const refresh = async () => {
1269
+ setRefreshing(true)
1270
+ try {
1271
+ await onRefresh()
1272
+ } finally {
1273
+ setRefreshing(false)
1274
+ }
1275
+ }
1253
1276
  const keys = Array.isArray(state?.keys) ? state.keys : []
1254
1277
 
1255
1278
  /* 正在批准哪一个(展开模型勾选)。 */
@@ -1327,6 +1350,14 @@ window.__ModuleLoader__.load({
1327
1350
  : h('span', { className: 'wbg-badge' }, t.pairingOff),
1328
1351
  h('span', { className: 'wbg-spacer' }),
1329
1352
  h('span', { className: 'wbg-caption' }, `${t.pairingDiscovery} udp:${pairing.discoveryPort ?? 8791}`),
1353
+ /* 待批准列表的手动刷新:对方刚发申请时不必等自动轮询。 */
1354
+ h('button', {
1355
+ type: 'button',
1356
+ className: 'wbg-btn wbg-btn-sm',
1357
+ onClick: refresh,
1358
+ disabled: refreshing,
1359
+ style: { marginLeft: 8 },
1360
+ }, refreshing ? t.pairingRefreshing : t.pairingRefresh),
1330
1361
  ),
1331
1362
  h('p', { className: 'wbg-hint' }, t.pairingHint),
1332
1363
 
@@ -1611,7 +1642,19 @@ window.__ModuleLoader__.load({
1611
1642
  setNote(undefined)
1612
1643
  try {
1613
1644
  await onRequest(baseUrl, name)
1645
+ /*
1646
+ * **清掉扫描结果,并且把 `scanned` 一起复位。**
1647
+ *
1648
+ * 只清 `found` 不够:`scanned` 还是 true 时,「没找到」那段提示的条件
1649
+ * (`scanned && found.length === 0 && pending === undefined`)会短暂成立
1650
+ * —— 申请成功后、`pending` 从服务器刷新回来之前,界面会闪一下
1651
+ * 「没找到网关」。用户刚成功申请,看到这句话只会以为失败了。
1652
+ *
1653
+ * 复位 `scanned` 后,那段提示只有「真的扫过一次且确实为空」才出现。
1654
+ */
1614
1655
  setFound([])
1656
+ setScanned(false)
1657
+ setDiag(undefined)
1615
1658
  setNote(`${t.peersWaitingHint}`)
1616
1659
  } catch (caught) {
1617
1660
  setError(String(caught.message ?? caught))
@@ -1814,16 +1857,24 @@ window.__ModuleLoader__.load({
1814
1857
  * 该回到可勾选列表。只在挂载时读一次的话,用户开着设置页也要手动刷新才看
1815
1858
  * 得到它回来 —— 而「恢复后自动同步」正是用户的明确要求。
1816
1859
  *
1817
- * 30 秒是刻意选的:比上游自己的轮询(默认 5 分钟)密,用户几乎立刻能看到
1818
- * 变化;又不会密到让一个只在看设置页的人持续产生请求(这个接口只读本地
1819
- * 文件,不打上游)。
1860
+ * 两个间隔:
1861
+ *
1862
+ * - 10 秒 —— 有待批准的配对请求时。对方点了「申请接入」就在等,30 秒
1863
+ * 才出现会让人以为申请没发出去。
1864
+ * - 30 秒 —— 平时。这个接口只读本地文件,不打上游,但没必要更密。
1865
+ *
1866
+ * 另有手动「刷新」按钮兜底,不必干等。
1820
1867
  */
1821
- const REFRESH_MS = 30000
1868
+ const IDLE_REFRESH_MS = 30000
1869
+ const PENDING_REFRESH_MS = 10000
1870
+ const hasPending = (state?.pairing?.pending?.length ?? 0) > 0
1871
+
1822
1872
  useEffect(() => {
1823
1873
  void reload()
1824
- const timer = setInterval(() => { void reload() }, REFRESH_MS)
1874
+ const every = hasPending ? PENDING_REFRESH_MS : IDLE_REFRESH_MS
1875
+ const timer = setInterval(() => { void reload() }, every)
1825
1876
  return () => clearInterval(timer)
1826
- }, [reload])
1877
+ }, [reload, hasPending])
1827
1878
 
1828
1879
  const addKey = useCallback(async () => {
1829
1880
  setBusy(true)
@@ -2128,6 +2179,7 @@ window.__ModuleLoader__.load({
2128
2179
  onDeny: denyPairing,
2129
2180
  onSaveShareName: saveShareName,
2130
2181
  onRevoke: revokeShare,
2182
+ onRefresh: reload,
2131
2183
  }),
2132
2184
  h(OriginCard, { state, t, onSave: saveOriginPolicy }),
2133
2185
  ),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-connect-workbuddy-gateway",
3
- "version": "1.5.3",
3
+ "version": "1.5.4",
4
4
  "description": "把 dsh-connect-workbuddy 的 WorkBuddy 模型开放成 HTTP API:OpenAI Chat / Responses、Anthropic Messages、Gemini 四协议共用一个固定 base URL,模型按 API key 逐个勾选。也可切换成接收方,接入局域网内另一台设备分享的模型。",
5
5
  "keywords": [
6
6
  "dsh-plugin",