dsh-plugin-weapp-gateway 0.8.55 → 0.8.57

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 CHANGED
@@ -11,6 +11,11 @@
11
11
  - 「兼容 App(备用)」的连接方式下拉与下方「配对入口」摘要卡片之间增加间距(16px),下拉不再紧贴提示卡片。
12
12
  - 摘要卡片的内边距、下方「配对入口地址」输入框与其余配对布局保持不变。
13
13
  - 全量测试通过。
14
+ ### v0.8.56 · 修复「点击插件弹窗空白」
15
+
16
+ - 修复 v0.8.54 整合时丢失的两个 fork 派生值:`visibleDevices` 与 `showAllDevices` 状态。有已配对设备时,设备列表渲染直接抛 `ReferenceError: visibleDevices is not defined`,整块弹窗白屏(设备为 0 时走另一分支才没暴露)。
17
+ - 已用真实 `/mgw/status` + 23 台已配对设备的真实数据跑通完整面板渲染(97 节点),并核对全部 onClick/onChange 处理器与组件辅助函数均已定义。
18
+ - 全量测试通过。
14
19
  ### v0.8.55 · 修复设置页无法加载(locale 注入缺失)
15
20
 
16
21
  - 修复 v0.8.54 引入的客户端加载失败:上游的语言同步 effect 引用了 `ctx.locale`,但 fork 未在 `inject` 里声明该服务,DSH 直接抛出 `cannot get property "locale" without inject`,整个客户端模块加载失败,设置页空白。
package/lib/client.js CHANGED
@@ -354,7 +354,7 @@ window.__ModuleLoader__.load({
354
354
  if (route === 'lan') return lanUrl
355
355
  if (route === 'relay') return status.relay?.relay || ''
356
356
  if (route === 'cloudflare') return tunnelUrl
357
- if (route === 'tailscale') return status.tailscale?.urls?.[0] || ''
357
+ if (route === 'tailscale') return status.tailscale?.serveUrl || status.tailscale?.urls?.[0] || ''
358
358
  const statusUrl = status.cloudflare?.enabled && status.cloudflare.publicReady !== true &&
359
359
  status.publicUrl === status.cloudflare.publicUrl ? '' : status.publicUrl
360
360
  return tunnelUrl || statusUrl || lanUrl || inferredUrl(status.wsPath)
@@ -374,6 +374,7 @@ window.__ModuleLoader__.load({
374
374
  function isTailscaleInput(value) {
375
375
  const host = tailscaleHostOf(value)
376
376
  if (!host) return false
377
+ if (/\.ts\.net$/i.test(host)) return true
377
378
  const octets = host.split('.').map(Number)
378
379
  if (octets.length === 4 && octets.every((part) => Number.isInteger(part) && part >= 0 && part <= 255)) {
379
380
  return octets[0] === 100 && octets[1] >= 64 && octets[1] <= 127
@@ -407,11 +408,14 @@ window.__ModuleLoader__.load({
407
408
  }
408
409
  }
409
410
  if (route === 'tailscale') {
410
- const valid = !!(status?.lan?.listening && isTailscaleInput(rawUrl))
411
+ const serveUrl = status?.tailscale?.serveUrl || ''
412
+ const valid = !!((serveUrl && String(rawUrl || '').trim() === serveUrl) || (status?.lan?.listening && isTailscaleInput(rawUrl)))
411
413
  return {
412
414
  valid,
413
- entry: 'Tailscale 私有网络',
414
- note: valid ? '手机与主机需登录同一 tailnet,并允许访问网关端口。' : '请填写运行网关这台主机的 Tailscale IP(不是手机 IP),例如 100.x.x.x。',
415
+ entry: 'Tailscale 内嵌隧道',
416
+ note: valid
417
+ ? '手机经 App 内嵌隧道连接网关节点(不占用系统 VPN,局域网不可用时仍可用)。'
418
+ : '可一键使用网关内置隧道地址;也可填写主机 Tailscale 100.x 地址。',
415
419
  }
416
420
  }
417
421
  // custom:按地址特征给提示(与上游 pairingConnectionPlan 同一判定思路)。
@@ -451,6 +455,11 @@ window.__ModuleLoader__.load({
451
455
  return `ws://${host}:${port}${wsPath}`
452
456
  }
453
457
 
458
+ // Tailscale 内嵌隧道:地址自动填入,无需用户手填。
459
+ function tailscaleServeUrl(status) {
460
+ return status?.tailscale?.serveUrl || ''
461
+ }
462
+
454
463
  function connectionAdvice(status, publicSetup) {
455
464
  if (!status) return { detected: '正在读取网关环境…', local: '', remote: '' }
456
465
  const system = status.platform === 'darwin' ? 'macOS 电脑' : status.platform === 'win32' ? 'Windows 电脑' : status.platform === 'linux' ? 'Linux 服务器' : '当前设备'
@@ -607,6 +616,8 @@ window.__ModuleLoader__.load({
607
616
  const [statusLoadError, setStatusLoadError] = React.useState(null)
608
617
  const refreshRequests = React.useRef(new Map())
609
618
  const manualRefreshRef = React.useRef(false)
619
+ // fork:离线设备折叠开关(上游整合时该状态丢失)。
620
+ const [showAllDevices, setShowAllDevices] = React.useState(false)
610
621
  const [permissionSaving, setPermissionSaving] = React.useState(null)
611
622
  const permissionLock = React.useRef(false)
612
623
  const deviceRevision = React.useRef(0)
@@ -687,7 +698,7 @@ window.__ModuleLoader__.load({
687
698
  const [revokingIds, setRevokingIds] = React.useState(() => new Set())
688
699
  const [sidebarBusy, setSidebarBusy] = React.useState(false)
689
700
  const [offlineClearing, setOfflineClearing] = React.useState(false)
690
- const [appLayerOpen, setAppLayerOpen] = React.useState(false)
701
+ const [appLayerOpen, setAppLayerOpen] = React.useState(true)
691
702
 
692
703
  const revokingIdsRef = React.useRef(new Set())
693
704
  const manualAppUrlRef = React.useRef(false)
@@ -1189,8 +1200,8 @@ window.__ModuleLoader__.load({
1189
1200
  }
1190
1201
  await refreshRead('devices')
1191
1202
  return removed
1192
- const revoke = (device) => removeDevices([device])
1193
1203
  }
1204
+ const revoke = (device) => removeDevices([device])
1194
1205
  const selectDevice = (id, selected) => setSelectedDeviceIds(current => {
1195
1206
  const next = new Set(current)
1196
1207
  selected ? next.add(id) : next.delete(id)
@@ -1222,6 +1233,8 @@ window.__ModuleLoader__.load({
1222
1233
  const onlineDevices = (devices || []).filter((device) => device.online)
1223
1234
  const offlineDevices = (devices || []).filter((device) => !device.online)
1224
1235
  const orderedDevices = [...onlineDevices, ...offlineDevices]
1236
+ // fork:默认只列在线设备,展开后列全部(上游整合时该派生值丢失)。
1237
+ const visibleDevices = showAllDevices ? orderedDevices : onlineDevices
1225
1238
  const selectedCount = orderedDevices.filter(device => selectedDeviceIds.has(device.id)).length
1226
1239
  const deletingDevices = revokingIds.size > 0
1227
1240
  const deviceActionsDisabled = deletingDevices || permissionSaving !== null
@@ -1432,71 +1445,7 @@ window.__ModuleLoader__.load({
1432
1445
  React.createElement('div', { hidden: activeSection !== 'network' },
1433
1446
  React.createElement(ServerNetworkDiagnostics, null)),
1434
1447
  React.createElement('div', { hidden: activeSection !== 'pairing' },
1435
- // ── 模块一:小程序连接(主用)────────────────────────────────────
1436
- React.createElement('section', { style: styles.card },
1437
- React.createElement('div', { style: { position: 'relative', display: 'flex', alignItems: 'center', gap: 6, marginBottom: 6 }, onMouseLeave: () => setConnectionHelpOpen(false) },
1438
- React.createElement('h3', { className: 'mgw-section-title', style: { marginBottom: 0 } }, '小程序连接(推荐)'),
1439
- React.createElement('button', {
1440
- type: 'button',
1441
- style: styles.helpButton,
1442
- 'aria-label': '连接方式说明与场景建议',
1443
- 'aria-expanded': connectionHelpOpen,
1444
- 'aria-describedby': connectionHelpOpen ? 'mgw-route-help' : undefined,
1445
- onMouseEnter: () => setConnectionHelpOpen(true),
1446
- onFocus: () => setConnectionHelpOpen(true),
1447
- onBlur: () => setConnectionHelpOpen(false),
1448
- onClick: () => setConnectionHelpOpen(true),
1449
- onKeyDown: (event) => { if (event.key === 'Escape') setConnectionHelpOpen(false) },
1450
- }, '?'),
1451
- connectionHelpOpen ? React.createElement('div', { id: 'mgw-route-help', role: 'tooltip', style: styles.helpBubble },
1452
- React.createElement('strong', null, '怎么选连接方式'),
1453
- helpLine('小程序连接(推荐)', '鲸尾小程序在微信里通过鲸尾公网中继连接,不受 wss 域名限制;手机与网关在同一局域网时自动兜底直连。'),
1454
- helpLine('鲸尾公网 · 小程序', '小程序专用二维码:中继优先、局域网兜底;无需公网域名。'),
1455
- helpLine('兼容 App(备用)', 'DSH App 使用直连入口:自动选择、局域网直连、Cloudflare 外网、Tailscale 私有网络或公网/手动地址。'),
1456
- helpLine('自动选择(App)', '优先已就绪的公网入口,同时保留局域网与 Tailscale 地址;没有公网入口时使用局域网。'),
1457
- helpLine('局域网直连', '手机与 DSH 在同一个可互访的局域网,使用 ws:// 私有地址;离开该网络就无法直连。'),
1458
- helpLine('Cloudflare 外网', 'PC 主动连接 Cloudflare,外网用固定域名的 wss://;需要 Cloudflare 账户和域名。'),
1459
- helpLine('Tailscale 私有网络', '可检测本机地址,或填写主机的 100.x 私有地址;手机与电脑需登录同一 tailnet。'),
1460
- helpLine('公网或其他手动地址', '已配置公网 WSS 反代或只想指定一个固定地址时使用;编辑下方地址即可。'),
1461
- React.createElement('div', { style: { borderTop: `1px solid ${colors.border}`, marginTop: 10, paddingTop: 8 } },
1462
- React.createElement('strong', null, '结合当前环境'),
1463
- React.createElement('div', { style: { color: colors.muted, marginTop: 4 } }, advice.detected),
1464
- React.createElement('div', { style: { marginTop: 6 } }, advice.local),
1465
- React.createElement('div', { style: { marginTop: 6 } }, advice.remote),
1466
- React.createElement('div', { style: { color: colors.muted, marginTop: 6 } }, '面板无法判断手机当前网络;请按手机所在位置选择,提示不会替你修改选择。')))
1467
- : null),
1468
- React.createElement('p', { style: styles.muted }, '小程序默认通过鲸尾公网中继连接,不需要公网域名;手机与网关在同一局域网时自动兜底直连。'),
1469
-
1470
- // 中继信息块属于小程序模块(自动选择 / 鲸尾公网中继)。
1471
- (relayInfo || relayConnector?.running || relayConnector?.delegatedTo || relayConnector?.lastError)
1472
- ? (relayInfo
1473
- ? React.createElement('div', { style: { ...styles.muted, margin: '2px 0 0', fontWeight: 500 } },
1474
- '鲸尾公网服务 · 已注册', ' · ',
1475
- React.createElement('span', { style: { opacity: .8 } }, `设备 ID ${relayInfo.nodeId.slice(0, 8)}… · ${relayInfo.gatewayName}`),
1476
- React.createElement('div', { style: { marginTop: 4, color: relayConnector?.lastError ? colors.danger : relayConnector?.running || relayConnector?.delegatedTo ? colors.success : 'var(--dsw-alias-link, #4176e6)' } },
1477
- relayConnector?.running || relayConnector?.delegatedTo
1478
- ? '中继连接保持运行'
1479
- : relayConnector?.lastError ? `中继连接器异常:${relayConnector.lastError}`
1480
- : '中继连接器正在恢复…'))
1481
- : relayConnector && relayConnector.running
1482
- ? React.createElement('div', { style: { ...styles.muted, margin: '2px 0 0', fontWeight: 500,
1483
- color: 'var(--dsw-alias-link, #4176e6)' } }, '内置连接器已自动启动,正在连接中继并上报身份…')
1484
- : relayConnector && relayConnector.lastError
1485
- ? React.createElement('div', { style: { ...styles.muted, margin: '2px 0 0', fontWeight: 500, color: colors.danger } },
1486
- '公网连接器暂时不可用,请检查网络或重新开启公网连接。', ' ',
1487
- React.createElement('span', { style: { opacity: .8 } }, '如已自行部署连接器,请执行 systemctl restart dsh-connector。'))
1488
- : React.createElement('div', { style: { ...styles.muted, margin: '2px 0 0' } }, '正在启动内置连接器…(中继模式需要一个本地连接器把小程序流量桥接进来,插件会自动准备)'))
1489
- : null,
1490
- React.createElement('div', { style: { display: 'flex', alignItems: 'center', gap: 12, flexWrap: 'wrap', marginTop: 10 } },
1491
- React.createElement('button', {
1492
- style: { ...styles.button, ...styles.primary, opacity: busy || !(status && status.gatewayEnabled) || !status?.relay || !lanPairingUrl(status) ? .65 : 1 },
1493
- disabled: busy || !(status && status.gatewayEnabled) || !status?.relay || !lanPairingUrl(status),
1494
- onClick: () => pairFor('mini'),
1495
- }, busy ? '正在生成…' : !(status && status.gatewayEnabled) ? '请先开启移动网关'
1496
- : !status?.relay ? '请先注册鲸尾公网中继'
1497
- : !lanPairingUrl(status) ? '请先开启局域网入口' : '生成小程序二维码'),
1498
- React.createElement('span', { style: styles.muted }, '配对码仅可使用一次,5 分钟内有效。'))),
1499
- // ── 第二层:兼容 App(折叠备用)────────────────────────────────
1448
+ // ── 模块一:DSH App(推荐)────────────────────────────────
1500
1449
  React.createElement('section', { style: { ...styles.card, marginTop: 16 } },
1501
1450
  React.createElement('button', {
1502
1451
  type: 'button',
@@ -1505,16 +1454,16 @@ window.__ModuleLoader__.load({
1505
1454
  onClick: () => setAppLayerOpen((value) => !value),
1506
1455
  },
1507
1456
  React.createElement('span', null,
1508
- React.createElement('strong', null, '兼容 App(备用)'),
1457
+ React.createElement('strong', null, 'DSH App(推荐)'),
1509
1458
  React.createElement('span', { style: { ...styles.muted, marginLeft: 8, fontWeight: 400 } },
1510
- appLayerOpen ? '收起 App 兼容方式' : '需要连接 DSH App 时展开')),
1459
+ appLayerOpen ? '收起 DSH App 方式' : '推荐:手机安装 DSH App 时使用')),
1511
1460
  React.createElement('svg', { width: 16, height: 16, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor',
1512
1461
  strokeWidth: 1.8, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true,
1513
1462
  style: { flexShrink: 0, color: colors.muted, transform: appLayerOpen ? 'rotate(180deg)' : 'none', transition: 'transform .18s ease' } },
1514
1463
  React.createElement('path', { d: 'M6 9l6 6 6-6' }))),
1515
1464
  appLayerOpen
1516
1465
  ? React.createElement(React.Fragment, null,
1517
- React.createElement('p', { style: styles.muted }, '仅用于 DSH App(上游移动网关的直连方式),与上方鲸尾公网互不影响。'),
1466
+ React.createElement('p', { style: styles.muted }, 'DSH App 直连入口(推荐手机端使用),与下方的鲸尾公网互不影响。'),
1518
1467
  React.createElement('div', { style: { display: 'flex', alignItems: 'center', flexWrap: 'wrap', gap: '8px 14px', maxWidth: '100%', marginBottom: 16 } },
1519
1468
  React.createElement(GatewaySelect, { style: styles.input, value: appRoute, onChange: (event) => chooseAppRoute(event.target.value), disabled: !status, 'aria-label': 'App 连接方式' },
1520
1469
  React.createElement('option', { value: 'auto' }, '自动选择'),
@@ -1523,13 +1472,61 @@ window.__ModuleLoader__.load({
1523
1472
  : '局域网直连 · 当前不可用'),
1524
1473
  status?.cloudflare?.supported
1525
1474
  ? React.createElement('option', { value: 'cloudflare' }, 'Cloudflare 外网') : null,
1526
- React.createElement('option', { value: 'tailscale', disabled: !(status && status.lan && status.lan.listening) },
1527
- (status && status.lan && status.lan.listening) ? 'Tailscale 私有网络' : 'Tailscale 私有网络 · 请先开启局域网入口'),
1475
+ React.createElement('option', { value: 'tailscale', disabled: !(status && ((status.tailscale && status.tailscale.serveUrl) || (status.lan && status.lan.listening))) },
1476
+ (status && ((status.tailscale && status.tailscale.serveUrl) || (status.lan && status.lan.listening)))
1477
+ ? 'Tailscale 内嵌隧道'
1478
+ : 'Tailscale 内嵌隧道 · 未就绪'),
1528
1479
  React.createElement('option', { value: 'custom' }, '公网或其他手动地址'))),
1529
1480
  // 与上游一致的连接方案摘要:配对入口 + 提示。
1530
1481
  React.createElement('div', { 'aria-label': '当前连接方案', style: { margin: '0 0 10px', padding: '9px 11px', borderRadius: 10, border: `1px solid ${colors.border}`, background: colors.card, fontSize: 12, lineHeight: 1.7 } },
1531
1482
  React.createElement('div', null, React.createElement('strong', null, '配对入口'), ':', appPlan.entry),
1532
1483
  React.createElement('div', { style: { color: appPlan.valid ? colors.muted : colors.danger } }, appPlan.note)),
1484
+ appRoute === 'tailscale'
1485
+ ? React.createElement('div', { style: { margin: '0 0 10px', padding: '9px 11px', borderRadius: 10, border: `1px solid ${colors.border}`, background: colors.card, fontSize: 12, lineHeight: 1.7 } },
1486
+ React.createElement('div', { style: { fontWeight: 600 } }, (() => {
1487
+ const ts = status?.tailscale || {}
1488
+ const serve = ts.serve || {}
1489
+ if (ts.serveUrl) return '内嵌隧道已连接'
1490
+ if (serve.loginUrl) return '内嵌隧道需要授权'
1491
+ return '内嵌隧道未启动'
1492
+ })()),
1493
+ React.createElement('div', { style: { color: colors.muted, marginTop: 2, wordBreak: 'break-all' } }, (() => {
1494
+ const ts = status?.tailscale || {}
1495
+ const serve = ts.serve || {}
1496
+ if (ts.serveUrl) return ts.serveUrl
1497
+ if (serve.loginUrl) return '点「去授权」在浏览器完成一次登录,之后地址会自动填入下方。'
1498
+ if (serve.backendState && serve.backendState !== 'disabled') return '状态:' + serve.backendState + (serve.error ? '(' + serve.error + ')' : '')
1499
+ return '网关内置 Tailscale 节点(userspace,不占系统 VPN)。启动后可自动生成固定地址。'
1500
+ })()),
1501
+ React.createElement('div', { style: { display: 'flex', gap: 8, marginTop: 8, flexWrap: 'wrap' } },
1502
+ (status?.tailscale?.serve?.loginUrl || '') !== ''
1503
+ ? React.createElement('button', {
1504
+ type: 'button',
1505
+ style: { ...styles.button, ...styles.primary },
1506
+ onClick: () => window.open('/mgw/tailscale/login', '_blank', 'noopener'),
1507
+ }, '去授权')
1508
+ : null,
1509
+ React.createElement('button', {
1510
+ type: 'button',
1511
+ style: styles.button,
1512
+ onClick: async () => {
1513
+ try {
1514
+ setBusy(true)
1515
+ await request('/mgw/tailscale', {
1516
+ method: 'POST',
1517
+ headers: { 'Content-Type': 'application/json' },
1518
+ body: JSON.stringify({ action: 'start' }),
1519
+ })
1520
+ const next = await request('/mgw/status')
1521
+ setStatus(next)
1522
+ } catch (cause) {
1523
+ setError(cause.message)
1524
+ } finally {
1525
+ setBusy(false)
1526
+ }
1527
+ },
1528
+ }, status?.tailscale?.serveUrl ? '重新连接' : '启动隧道')))
1529
+ : null,
1533
1530
  React.createElement('label', { style: styles.label, htmlFor: 'mgw-pair-address' }, appRoute === 'tailscale'
1534
1531
  ? '主机 Tailscale 地址(运行网关的电脑,不是手机)'
1535
1532
  : '配对入口地址(手机需能访问)'),
@@ -1585,7 +1582,7 @@ window.__ModuleLoader__.load({
1585
1582
  : appRoute === 'tailscale' && !isTailscaleInput(appUrl) ? '填写主机 Tailscale 地址'
1586
1583
  : appRoute === 'lan' && !lanPairingUrl(status) ? '当前不可用'
1587
1584
  : appRoute === 'custom' && !appUrl.trim() ? '等待连接地址' : '生成 App 二维码'),
1588
- React.createElement('span', { style: styles.muted }, '二维码只发给 App;小程序请用上方模块。')))
1585
+ React.createElement('span', { style: styles.muted }, '二维码只发给 App;小程序请用下方模块。')))
1589
1586
  : React.createElement('p', { style: { ...styles.muted, margin: '8px 0 0' } }, '局域网直连 / Cloudflare 外网 / Tailscale 私有网络 / 公网或其他手动地址;与鲸尾公网互不影响。')),
1590
1587
  appLayerOpen && appRoute === 'cloudflare' && status?.cloudflare?.supported
1591
1588
  ? React.createElement('section', { className: 'mgw-cloudflare-block', style: { ...styles.card, background: colors.card, border: 0, borderRadius: 16, padding: 18, marginTop: 16 } },
@@ -1672,6 +1669,70 @@ window.__ModuleLoader__.load({
1672
1669
  React.createElement('p', { style: { ...styles.muted, marginBottom: 8 } }, '尚未安装系统 Helper。请在服务器执行一次初始化:'),
1673
1670
  React.createElement('code', { style: { display: 'block', fontSize: 10, lineHeight: 1.5, overflowWrap: 'anywhere', userSelect: 'all' } }, 'npx --yes dsh-plugin-mobile-gateway@latest init'))) : null,
1674
1671
 
1672
+ // ── 模块二:小程序连接(备用)────────────────────────────────────
1673
+ React.createElement('section', { style: styles.card },
1674
+ React.createElement('div', { style: { position: 'relative', display: 'flex', alignItems: 'center', gap: 6, marginBottom: 6 }, onMouseLeave: () => setConnectionHelpOpen(false) },
1675
+ React.createElement('h3', { className: 'mgw-section-title', style: { marginBottom: 0 } }, '小程序连接(备用)'),
1676
+ React.createElement('button', {
1677
+ type: 'button',
1678
+ style: styles.helpButton,
1679
+ 'aria-label': '连接方式说明与场景建议',
1680
+ 'aria-expanded': connectionHelpOpen,
1681
+ 'aria-describedby': connectionHelpOpen ? 'mgw-route-help' : undefined,
1682
+ onMouseEnter: () => setConnectionHelpOpen(true),
1683
+ onFocus: () => setConnectionHelpOpen(true),
1684
+ onBlur: () => setConnectionHelpOpen(false),
1685
+ onClick: () => setConnectionHelpOpen(true),
1686
+ onKeyDown: (event) => { if (event.key === 'Escape') setConnectionHelpOpen(false) },
1687
+ }, '?'),
1688
+ connectionHelpOpen ? React.createElement('div', { id: 'mgw-route-help', role: 'tooltip', style: styles.helpBubble },
1689
+ React.createElement('strong', null, '怎么选连接方式'),
1690
+ helpLine('小程序连接(备用)', '鲸尾小程序在微信里通过鲸尾公网中继连接,不受 wss 域名限制;手机与网关在同一局域网时自动兜底直连。'),
1691
+ helpLine('鲸尾公网 · 小程序', '小程序专用二维码:中继优先、局域网兜底;无需公网域名。'),
1692
+ helpLine('DSH App(推荐)', 'DSH App 使用直连入口:自动选择、局域网直连、Cloudflare 外网、Tailscale 私有网络或公网/手动地址。'),
1693
+ helpLine('自动选择(App)', '优先已就绪的公网入口,同时保留局域网与 Tailscale 地址;没有公网入口时使用局域网。'),
1694
+ helpLine('局域网直连', '手机与 DSH 在同一个可互访的局域网,使用 ws:// 私有地址;离开该网络就无法直连。'),
1695
+ helpLine('Cloudflare 外网', 'PC 主动连接 Cloudflare,外网用固定域名的 wss://;需要 Cloudflare 账户和域名。'),
1696
+ helpLine('Tailscale 私有网络', '可检测本机地址,或填写主机的 100.x 私有地址;手机与电脑需登录同一 tailnet。'),
1697
+ helpLine('公网或其他手动地址', '已配置公网 WSS 反代或只想指定一个固定地址时使用;编辑下方地址即可。'),
1698
+ React.createElement('div', { style: { borderTop: `1px solid ${colors.border}`, marginTop: 10, paddingTop: 8 } },
1699
+ React.createElement('strong', null, '结合当前环境'),
1700
+ React.createElement('div', { style: { color: colors.muted, marginTop: 4 } }, advice.detected),
1701
+ React.createElement('div', { style: { marginTop: 6 } }, advice.local),
1702
+ React.createElement('div', { style: { marginTop: 6 } }, advice.remote),
1703
+ React.createElement('div', { style: { color: colors.muted, marginTop: 6 } }, '面板无法判断手机当前网络;请按手机所在位置选择,提示不会替你修改选择。')))
1704
+ : null),
1705
+ React.createElement('p', { style: styles.muted }, '小程序默认通过鲸尾公网中继连接,不需要公网域名;手机与网关在同一局域网时自动兜底直连。'),
1706
+
1707
+ // 中继信息块属于小程序模块(自动选择 / 鲸尾公网中继)。
1708
+ (relayInfo || relayConnector?.running || relayConnector?.delegatedTo || relayConnector?.lastError)
1709
+ ? (relayInfo
1710
+ ? React.createElement('div', { style: { ...styles.muted, margin: '2px 0 0', fontWeight: 500 } },
1711
+ '鲸尾公网服务 · 已注册', ' · ',
1712
+ React.createElement('span', { style: { opacity: .8 } }, `设备 ID ${relayInfo.nodeId.slice(0, 8)}… · ${relayInfo.gatewayName}`),
1713
+ React.createElement('div', { style: { marginTop: 4, color: relayConnector?.lastError ? colors.danger : relayConnector?.running || relayConnector?.delegatedTo ? colors.success : 'var(--dsw-alias-link, #4176e6)' } },
1714
+ relayConnector?.running || relayConnector?.delegatedTo
1715
+ ? '中继连接保持运行'
1716
+ : relayConnector?.lastError ? `中继连接器异常:${relayConnector.lastError}`
1717
+ : '中继连接器正在恢复…'))
1718
+ : relayConnector && relayConnector.running
1719
+ ? React.createElement('div', { style: { ...styles.muted, margin: '2px 0 0', fontWeight: 500,
1720
+ color: 'var(--dsw-alias-link, #4176e6)' } }, '内置连接器已自动启动,正在连接中继并上报身份…')
1721
+ : relayConnector && relayConnector.lastError
1722
+ ? React.createElement('div', { style: { ...styles.muted, margin: '2px 0 0', fontWeight: 500, color: colors.danger } },
1723
+ '公网连接器暂时不可用,请检查网络或重新开启公网连接。', ' ',
1724
+ React.createElement('span', { style: { opacity: .8 } }, '如已自行部署连接器,请执行 systemctl restart dsh-connector。'))
1725
+ : React.createElement('div', { style: { ...styles.muted, margin: '2px 0 0' } }, '正在启动内置连接器…(中继模式需要一个本地连接器把小程序流量桥接进来,插件会自动准备)'))
1726
+ : null,
1727
+ React.createElement('div', { style: { display: 'flex', alignItems: 'center', gap: 12, flexWrap: 'wrap', marginTop: 10 } },
1728
+ React.createElement('button', {
1729
+ style: { ...styles.button, ...styles.primary, opacity: busy || !(status && status.gatewayEnabled) || !status?.relay || !lanPairingUrl(status) ? .65 : 1 },
1730
+ disabled: busy || !(status && status.gatewayEnabled) || !status?.relay || !lanPairingUrl(status),
1731
+ onClick: () => pairFor('mini'),
1732
+ }, busy ? '正在生成…' : !(status && status.gatewayEnabled) ? '请先开启移动网关'
1733
+ : !status?.relay ? '请先注册鲸尾公网中继'
1734
+ : !lanPairingUrl(status) ? '请先开启局域网入口' : '生成小程序二维码'),
1735
+ React.createElement('span', { style: styles.muted }, '配对码仅可使用一次,5 分钟内有效。'))),
1675
1736
  ),
1676
1737
  React.createElement('div', { hidden: activeSection !== 'devices' },
1677
1738
  React.createElement('section', { style: styles.card },
package/lib/index.mjs CHANGED
@@ -169,6 +169,7 @@ import { createFileUploadManager, FILE_UPLOAD_REQUEST_TYPES, FILE_UPLOAD_DEFAULT
169
169
  import { assistantFinish, failureDetails, toolResultDetails, turnReasonDetails } from './session-event-details.mjs'
170
170
  import { createNetworkDiagnostics } from './network-diagnostics.mjs'
171
171
  import { isTailscaleIp, tailscaleInterfaceStatus } from './tailscale-addresses.mjs'
172
+ import { createTailscaleServe } from './tailscale-serve.mjs'
172
173
  import { createUiState } from './ui-state.mjs'
173
174
 
174
175
  const { createRegistry } = devicesModule
@@ -320,6 +321,10 @@ const Config = Schema.object({
320
321
  cloudflaredPath: Schema.string().default('cloudflared'),
321
322
  cloudflarePort: Schema.natural().min(1).max(65535).default(3082),
322
323
  cloudflareStateFile: Schema.string().default(''),
324
+ tailscaleEnabled: Schema.boolean().default(false),
325
+ tailscaleAuthKey: Schema.string().default(''),
326
+ tailscaleHostname: Schema.string().default('dsh-gateway'),
327
+ tailscaleServePort: Schema.natural().min(1).max(65535).default(3081),
323
328
  logFile: Schema.string().default(''),
324
329
  })
325
330
 
@@ -752,7 +757,10 @@ async function admitMessage(api, msg, notificationTracker, authenticatedSource =
752
757
  // 对象(gatewayId/deviceId,上游 phone-connectors 契约)。
753
758
  const tracker = notificationTracker && typeof notificationTracker.register === 'function' ? notificationTracker : null
754
759
  const phoneSource = !tracker && notificationTracker && typeof notificationTracker === 'object' ? notificationTracker : (authenticatedSource || null)
755
- const requestId = typeof msg.requestId === 'string' && msg.requestId.trim().length > 0
760
+ // Phone-source admission fills a server-side requestId when the client did not
761
+ // send one, so this must stay reassignable (a const here made every un-requestId'd
762
+ // mobile message throw "Assignment to constant variable." before reaching the host).
763
+ let requestId = typeof msg.requestId === 'string' && msg.requestId.trim().length > 0
756
764
  && msg.requestId.length <= 128 ? msg.requestId.trim() : null
757
765
  const target = parseSessionTarget(msg, { optional: true })
758
766
  if (target.error) return { ...target.error, ...(requestId ? { requestId } : {}),
@@ -2937,6 +2945,10 @@ const plugin = {
2937
2945
  cloudflaredPath: 'cloudflared',
2938
2946
  cloudflarePort: 3082,
2939
2947
  cloudflareStateFile: '',
2948
+ tailscaleEnabled: false,
2949
+ tailscaleAuthKey: '',
2950
+ tailscaleHostname: 'dsh-gateway',
2951
+ tailscaleServePort: 3081,
2940
2952
  logFile: '',
2941
2953
  ...(config || {}),
2942
2954
  }
@@ -3066,6 +3078,7 @@ const plugin = {
3066
3078
  let lanBoundPort = options.lanPort
3067
3079
  let lanDisposeLanRetry = null
3068
3080
  let tunnel = null
3081
+ let tailscaleServe = null
3069
3082
  const configuredPublicUrl = () => {
3070
3083
  if (typeof options.publicUrl === 'string' && options.publicUrl.trim()) return options.publicUrl.trim()
3071
3084
  if (typeof options.publicUrlFile !== 'string' || !options.publicUrlFile.trim()) return ''
@@ -3080,6 +3093,18 @@ const plugin = {
3080
3093
  }
3081
3094
  }
3082
3095
 
3096
+ const tailscaleStatus = () => {
3097
+ const base = tailscaleInterfaceStatus({ listening: lanListening, host: options.lanHost, port: lanBoundPort, wsPath })
3098
+ const serveUrl = tailscaleServe?.snapshot().publicUrl || ''
3099
+ const serveState = tailscaleServe ? tailscaleServe.snapshot() : { enabled: false, backendState: 'disabled', loginUrl: '', error: '' }
3100
+ return {
3101
+ ...base,
3102
+ serveUrl,
3103
+ urls: serveUrl ? [serveUrl, ...(base.urls || [])] : (base.urls || []),
3104
+ serve: serveState,
3105
+ }
3106
+ }
3107
+
3083
3108
  const advertisedEndpoints = (primary, extra = []) => {
3084
3109
  const publicUrl = configuredPublicUrl()
3085
3110
  return normalizeEndpoints([...new Set([
@@ -3088,6 +3113,7 @@ const plugin = {
3088
3113
  ...configuredEndpoints,
3089
3114
  ...(publicUrl ? [publicUrl] : []),
3090
3115
  ...(tunnel?.snapshot().publicUrl ? [tunnel.snapshot().publicUrl] : []),
3116
+ ...(tailscaleServe?.snapshot().publicUrl ? [tailscaleServe.snapshot().publicUrl] : []),
3091
3117
  ...(lanListening ? lanWebSocketUrls(options, wsPath, lanBoundPort) : []),
3092
3118
  // Tailscale 直连地址与局域网同等作为候选:手机在同一 tailnet 时可直连,
3093
3119
  // 不在 tailnet 的客户端会自然失败并回退到其他候选。
@@ -3515,14 +3541,15 @@ const plugin = {
3515
3541
  webPid: process.pid,
3516
3542
  gatewayInstanceId,
3517
3543
  wsPath,
3518
- publicUrl: tunnel?.snapshot().enabled && tunnel.snapshot().mode === 'quick'
3519
- ? tunnel.snapshot().publicUrl
3520
- : tunnel?.snapshot().publicUrl || configuredPublicUrl() || null,
3544
+ publicUrl: tailscaleServe?.snapshot().publicUrl ||
3545
+ (tunnel?.snapshot().enabled && tunnel.snapshot().mode === 'quick'
3546
+ ? tunnel.snapshot().publicUrl
3547
+ : tunnel?.snapshot().publicUrl) || configuredPublicUrl() || null,
3521
3548
  platform: process.platform,
3522
3549
  cloudflare: tunnel?.snapshot() || null,
3523
3550
  // 本机 Tailscale 接口地址(100.64/10 或 fd7a:115c:a1e0::/48)。
3524
3551
  // 只用于面板展示与可选配对地址;检测到接口不等于已登录 tailnet。
3525
- tailscale: tailscaleInterfaceStatus({ listening: lanListening, host: options.lanHost, port: lanBoundPort, wsPath }),
3552
+ tailscale: tailscaleStatus(),
3526
3553
  lan: {
3527
3554
  enabled: options.lanEnabled === true,
3528
3555
  listening: lanListening,
@@ -3578,6 +3605,30 @@ const plugin = {
3578
3605
  restartPending = true
3579
3606
  res.once('finish', () => setTimeout(() => process.kill(process.pid, 'SIGTERM'), 100))
3580
3607
  sendJson(res, 202, { stopping: true })
3608
+ } else if (req.method === 'GET' && p === '/mgw/tailscale') {
3609
+ let snapshot = tailscaleServe ? tailscaleServe.snapshot() : { enabled: false }
3610
+ if (tailscaleServe) {
3611
+ try {
3612
+ snapshot = await tailscaleServe.refresh()
3613
+ } catch (error) {
3614
+ log('tailscale refresh failed: ' + (error && error.message ? error.message : String(error)))
3615
+ }
3616
+ }
3617
+ sendJson(res, 200, snapshot)
3618
+ } else if (req.method === 'GET' && p === '/mgw/tailscale/login') {
3619
+ const url = tailscaleServe ? await tailscaleServe.loginUrl() : ''
3620
+ if (!url) throw badRequest('tailscale login url unavailable')
3621
+ res.writeHead(302, { Location: url })
3622
+ res.end()
3623
+ } else if (req.method === 'POST' && p === '/mgw/tailscale') {
3624
+ if (!tailscaleServe) throw badRequest('tailscale is not available')
3625
+ const body = await readBody(req)
3626
+ await tailscaleServe.stop()
3627
+ if (body && body.action === 'stop') {
3628
+ sendJson(res, 200, tailscaleServe.snapshot())
3629
+ } else {
3630
+ sendJson(res, 200, await tailscaleServe.start())
3631
+ }
3581
3632
  } else if (req.method === 'GET' && p === '/mgw/public-setup') {
3582
3633
  sendJson(res, 200, await systemHelperStatus())
3583
3634
  } else if (req.method === 'POST' && p === '/mgw/public-setup') {
@@ -3683,12 +3734,16 @@ const plugin = {
3683
3734
  ? '' : configuredUrl
3684
3735
  // Tailscale 专用路线:只接受 ws:// + Tailscale IP。未显式给出地址时使用
3685
3736
  // 本机探测到的第一个地址;探测不到时明确报错,而不是退化成其他路线。
3686
- const tailscaleUrls = lanListening
3687
- ? tailscaleInterfaceStatus({ listening: true, host: options.lanHost, port: lanBoundPort, wsPath }).urls
3688
- : []
3737
+ const serveTailscaleUrl = tailscaleServe?.snapshot().publicUrl || ''
3738
+ const tailscaleUrls = [
3739
+ ...(serveTailscaleUrl ? [serveTailscaleUrl] : []),
3740
+ ...(lanListening
3741
+ ? tailscaleInterfaceStatus({ listening: true, host: options.lanHost, port: lanBoundPort, wsPath }).urls
3742
+ : []),
3743
+ ]
3689
3744
  const requestedTailscaleUrl = clientRoute === 'tailscale'
3690
3745
  ? (() => {
3691
- if (!lanListening) {
3746
+ if (!lanListening && !serveTailscaleUrl) {
3692
3747
  const error = new Error('enable the LAN listener before generating a Tailscale pairing code')
3693
3748
  error.status = 409
3694
3749
  throw error
@@ -3708,8 +3763,11 @@ const plugin = {
3708
3763
  throw error
3709
3764
  }
3710
3765
  const parsed = new URL(candidate)
3711
- if (parsed.protocol !== 'ws:' || !isTailscaleIp(parsed.hostname.replace(/^\[|\]$/g, ''))) {
3712
- const error = new Error('Tailscale pairing requires a ws:// Tailscale IP address')
3766
+ const candidateHost = parsed.hostname.replace(/^\[|\]$/g, '')
3767
+ const isServeUrl = candidate === serveTailscaleUrl ||
3768
+ (parsed.protocol === 'wss:' && /\.ts\.net$/i.test(candidateHost))
3769
+ if (!isServeUrl && (parsed.protocol !== 'ws:' || !isTailscaleIp(candidateHost))) {
3770
+ const error = new Error('Tailscale pairing requires a ws:// Tailscale IP address, or the embedded wss://<node>.ts.net address')
3713
3771
  error.status = 409
3714
3772
  throw error
3715
3773
  }
@@ -3724,7 +3782,7 @@ const plugin = {
3724
3782
  ? (autoUrl ? normalizePublicUrl(autoUrl, req, wsPath) : '')
3725
3783
  : clientRoute === 'mini'
3726
3784
  ? ''
3727
- : normalizePublicUrl(body.publicUrl || configuredUrl, req, wsPath)
3785
+ : normalizePublicUrl(body.publicUrl || (tailscaleServe?.snapshot().publicUrl || '') || configuredUrl, req, wsPath)
3728
3786
  if (clientRoute) {
3729
3787
  const discoveredLan = lanListening
3730
3788
  ? lanWebSocketUrls(options, wsPath, lanBoundPort).find(isRoutablePrivateEndpoint)
@@ -3737,7 +3795,13 @@ const plugin = {
3737
3795
  req,
3738
3796
  wsPath,
3739
3797
  )
3740
- if (!isRoutablePrivateEndpoint(appUrl)) {
3798
+ const tailscaleServeAppUrl = clientRoute === 'tailscale' && (() => {
3799
+ try {
3800
+ const parsed = new URL(appUrl)
3801
+ return parsed.protocol === 'wss:' && /\.ts\.net$/i.test(parsed.hostname)
3802
+ } catch { return false }
3803
+ })()
3804
+ if (!tailscaleServeAppUrl && !isRoutablePrivateEndpoint(appUrl)) {
3741
3805
  const error = new Error('enable or configure a reachable LAN WebSocket address before generating a multi-client QR code')
3742
3806
  error.status = 409
3743
3807
  throw error
@@ -3756,7 +3820,9 @@ const plugin = {
3756
3820
  .filter((url) => {
3757
3821
  try {
3758
3822
  const parsed = new URL(url)
3759
- return parsed.protocol === 'ws:' && isTailscaleIp(parsed.hostname.replace(/^\[|\]$/g, ''))
3823
+ const host = parsed.hostname.replace(/^\[|\]$/g, '')
3824
+ return (parsed.protocol === 'ws:' && isTailscaleIp(host)) ||
3825
+ (parsed.protocol === 'wss:' && /\.ts\.net$/i.test(host))
3760
3826
  } catch { return false }
3761
3827
  })
3762
3828
  .slice(0, 16)
@@ -4390,6 +4456,18 @@ const plugin = {
4390
4456
  })
4391
4457
  void tunnel.reconcile()
4392
4458
 
4459
+ tailscaleServe = createTailscaleServe({
4460
+ file: path.join(os.homedir(), '.dsh', 'tailscale', 'tailscale-serve.json'),
4461
+ wsPath,
4462
+ servePort: options.tailscaleServePort,
4463
+ hostname: options.tailscaleHostname,
4464
+ authKey: options.tailscaleAuthKey,
4465
+ log,
4466
+ })
4467
+ if (options.tailscaleEnabled === true) {
4468
+ void tailscaleServe.start().then((snap) => log('tailscale serve: ' + JSON.stringify(snap)))
4469
+ }
4470
+
4393
4471
  const disposeEvents = ctx.on('session/event', (session, event) => {
4394
4472
  api.observeSessionEvent(String(session.id), event)
4395
4473
  completionNotifications.onSessionEvent(String(session.id), event)
@@ -0,0 +1,202 @@
1
+ import fs from 'node:fs/promises'
2
+ import os from 'node:os'
3
+ import path from 'node:path'
4
+ import { spawn, execFile } from 'node:child_process'
5
+ import { promisify } from 'node:util'
6
+
7
+ const execFileAsync = promisify(execFile)
8
+
9
+ /**
10
+ * 网关内嵌 Tailscale(userspace,不占系统 VPN、不需要安装 Tailscale.app):
11
+ * - 启动 tailscaled --tun=userspace-networking
12
+ * - authKey 或登录链接加入 tailnet(一次性)
13
+ * - tailscale serve --bg <端口> 把网关端口暴露成 wss://<node>.<tailnet>.ts.net/ws/mobile
14
+ */
15
+ function resolveBinary(name) {
16
+ const candidates = [
17
+ '/opt/homebrew/bin/' + name,
18
+ '/usr/local/bin/' + name,
19
+ '/Applications/Tailscale.app/Contents/MacOS/' + (name === 'tailscaled' ? 'tailscaled' : 'Tailscale'),
20
+ name,
21
+ ]
22
+ for (const candidate of candidates) {
23
+ try {
24
+ if (candidate === name) return name
25
+ if (require('node:fs').existsSync(candidate)) return candidate
26
+ } catch (error) { /* ignore */ }
27
+ }
28
+ return name
29
+ }
30
+
31
+ export function createTailscaleServe(options = {}) {
32
+ const log = typeof options.log === 'function' ? options.log : () => {}
33
+ const wsPath = options.wsPath || '/ws/mobile'
34
+ const baseDir = options.baseDir || path.join(os.homedir(), '.dsh', 'tailscale')
35
+ const stateFile = path.join(baseDir, 'tailscaled.state')
36
+ const socketPath = options.socketPath || path.join(baseDir, 'tailscaled.sock')
37
+ const cacheFile = options.file || path.join(baseDir, 'tailscale-serve.json')
38
+ const servePort = Number(options.servePort) || 3081
39
+ const hostname = String(options.hostname || 'dsh-gateway').trim() || 'dsh-gateway'
40
+ const authKey = String(options.authKey || '').trim()
41
+ const tailscaledBin = options.tailscaledPath || resolveBinary('tailscaled')
42
+ const tailscaleBin = options.tailscalePath || resolveBinary('tailscale')
43
+
44
+ let child = null
45
+ let starting = false
46
+ let state = { enabled: false, backendState: 'disabled', loginUrl: '', publicUrl: '', error: '' }
47
+
48
+ const snapshot = () => ({ ...state })
49
+
50
+ async function persist() {
51
+ try {
52
+ await fs.mkdir(baseDir, { recursive: true })
53
+ await fs.writeFile(cacheFile, JSON.stringify(snapshot(), null, 2))
54
+ } catch (error) {
55
+ log('tailscale: persist failed ' + (error && error.message ? error.message : String(error)))
56
+ }
57
+ }
58
+
59
+ async function cli(args, timeoutMs = 15000) {
60
+ const result = await execFileAsync(tailscaleBin, ['--socket=' + socketPath, ...args], {
61
+ timeout: timeoutMs,
62
+ maxBuffer: 4 * 1024 * 1024,
63
+ })
64
+ return String(result.stdout || '')
65
+ }
66
+
67
+ async function statusJson() {
68
+ const text = await cli(['status', '--json'])
69
+ return JSON.parse(text)
70
+ }
71
+
72
+ async function waitForBackend(timeoutMs = 30000) {
73
+ const deadline = Date.now() + timeoutMs
74
+ while (Date.now() < deadline) {
75
+ try {
76
+ const status = await statusJson()
77
+ state.backendState = String(status.BackendState || 'unknown')
78
+ if (state.backendState === 'Running') return status
79
+ if (state.backendState === 'NeedsLogin' && !state.loginUrl) {
80
+ const authUrl = status.AuthURL || ''
81
+ if (authUrl) state.loginUrl = authUrl
82
+ }
83
+ } catch (error) {
84
+ // tailscaled 尚未就绪
85
+ }
86
+ await new Promise((resolve) => setTimeout(resolve, 1000))
87
+ }
88
+ return null
89
+ }
90
+
91
+ async function enableServe() {
92
+ try {
93
+ await cli(['serve', '--bg', String(servePort)])
94
+ } catch (error) {
95
+ log('tailscale: serve failed ' + (error && error.message ? error.message : String(error)))
96
+ }
97
+ }
98
+
99
+ async function refresh() {
100
+ const status = await statusJson()
101
+ state.backendState = String(status.BackendState || 'unknown')
102
+ const dnsName = status.Self && status.Self.DNSName ? String(status.Self.DNSName).replace(/\.$/, '') : ''
103
+ if (state.backendState === 'Running' && dnsName) {
104
+ await enableServe()
105
+ state.publicUrl = 'wss://' + dnsName + wsPath
106
+ state.error = ''
107
+ }
108
+ await persist()
109
+ return snapshot()
110
+ }
111
+
112
+ async function start() {
113
+ if (starting) return snapshot()
114
+ starting = true
115
+ state = { ...state, enabled: true, error: '' }
116
+ try {
117
+ await fs.mkdir(baseDir, { recursive: true })
118
+ const args = [
119
+ '--tun=userspace-networking',
120
+ '--state=' + stateFile,
121
+ '--socket=' + socketPath,
122
+ '--port=41642',
123
+ '--socks5-server=127.0.0.1:1055',
124
+ ]
125
+ child = spawn(tailscaledBin, args, { stdio: ['ignore', 'pipe', 'pipe'] })
126
+ child.stdout.on('data', (chunk) => log('tailscaled: ' + String(chunk).trim()))
127
+ child.stderr.on('data', (chunk) => log('tailscaled: ' + String(chunk).trim()))
128
+ child.on('error', (error) => {
129
+ state.error = 'spawn-failed: ' + (error && error.message ? error.message : String(error))
130
+ log('tailscale: spawn failed ' + state.error)
131
+ child = null
132
+ })
133
+ child.on('exit', (code) => {
134
+ log('tailscaled exited code=' + code)
135
+ child = null
136
+ })
137
+ await new Promise((resolve) => setTimeout(resolve, 1500))
138
+ if (authKey) {
139
+ try {
140
+ await cli(['up', '--authkey=' + authKey, '--hostname=' + hostname], 60000)
141
+ } catch (error) {
142
+ log('tailscale: up with authkey failed ' + (error && error.message ? error.message : String(error)))
143
+ }
144
+ } else {
145
+ try {
146
+ await cli(['up', '--hostname=' + hostname], 8000)
147
+ } catch (error) {
148
+ const text = String((error && error.stdout) || '') + String((error && error.stderr) || '') +
149
+ String((error && error.message) || '')
150
+ const match = text.match(/https:\/\/login\.tailscale\.com\/[a-z0-9]+/i)
151
+ if (match) state.loginUrl = match[0]
152
+ }
153
+ if (!state.loginUrl) {
154
+ try {
155
+ const status = await statusJson()
156
+ state.loginUrl = status.AuthURL || ''
157
+ } catch (error) { /* ignore */ }
158
+ }
159
+ }
160
+ const running = await waitForBackend()
161
+ if (!running) {
162
+ state.error = state.loginUrl ? 'needs-login' : 'backend-not-running'
163
+ } else {
164
+ await enableServe()
165
+ const dnsName = running.Self && running.Self.DNSName
166
+ ? String(running.Self.DNSName).replace(/\.$/, '') : ''
167
+ if (dnsName) {
168
+ state.publicUrl = 'wss://' + dnsName + wsPath
169
+ }
170
+ state.error = ''
171
+ }
172
+ await persist()
173
+ } catch (error) {
174
+ state.error = error && error.message ? error.message : String(error)
175
+ log('tailscale: start failed ' + state.error)
176
+ } finally {
177
+ starting = false
178
+ }
179
+ return snapshot()
180
+ }
181
+
182
+ async function stop() {
183
+ state = { ...state, enabled: false, publicUrl: '', loginUrl: '' }
184
+ if (child) {
185
+ try { child.kill('SIGTERM') } catch (error) { /* ignore */ }
186
+ child = null
187
+ }
188
+ await persist()
189
+ return snapshot()
190
+ }
191
+
192
+ async function loginUrl() {
193
+ try {
194
+ const status = await statusJson()
195
+ return status.AuthURL || state.loginUrl
196
+ } catch (error) {
197
+ return state.loginUrl
198
+ }
199
+ }
200
+
201
+ return { start, stop, refresh, snapshot, loginUrl, enableServe }
202
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-weapp-gateway",
3
- "version": "0.8.55",
3
+ "version": "0.8.57",
4
4
  "description": "鲸尾网关助手:DeepSeek Harness 移动客户端连接与会话同步,支持安全配对、远程访问、上下文、编队、额度和语音输入",
5
5
  "main": "lib/index.mjs",
6
6
  "files": [
@@ -32,7 +32,7 @@
32
32
  "scripts": {
33
33
  "test": "node --test test/tool-images.test.mjs test/dsh-runtime-version.test.mjs && node --test test/logging.test.mjs && node test/dsh-022.test.mjs && node test/device-tools.test.mjs && node test/external-files.test.mjs && node test/team-mode.test.mjs && node test/android-connectors.test.mjs && node test/workspace-changes.test.mjs && node test/devices.test.mjs && node test/dsh-runtime-version.test.mjs && node test/wire-json.test.mjs && node --test test/history-cache.test.mjs && node test/session-target.test.mjs && node test/setup-ip.test.mjs && node test/host-adapter.test.mjs && node test/file-upload-adapter.test.mjs && node test/file-upload.test.mjs && node test/agent-team.test.mjs && node test/account-bridge.test.mjs && node test/context-bridge.test.mjs && node test/cost-meter.test.mjs && node --test test/cost-meter-dashboard.test.mjs && node test/clawbot-service.test.mjs && node test/speech-input.test.mjs && node test/plugin-management.test.mjs && node test/model-config.test.mjs && node test/plugin-updates.test.mjs && node test/session-preset.test.mjs && node test/session-follower.test.mjs && node test/completion-notifications.test.mjs && node --test test/workspace-changes.test.mjs && node --test test/question-replay.test.mjs && node --test test/network-diagnostics.test.mjs && node --test test/tailscale-addresses.test.mjs && node --test test/ui-state.test.mjs && node test/gateway.test.mjs && node test/auth.test.mjs && node test/lan.test.mjs && node test/cloudflared-binary.test.mjs && node test/cloudflare-tunnel.test.mjs && node --test test/public-endpoint-check.test.mjs && node test/gateway-tools.test.mjs && node test/relay-connector.test.mjs && node test/restart-reconnect.test.mjs && node test/multi-gateway.test.mjs",
34
34
  "test:official": "node test/dsh-022-official.test.mjs && node test/tool-images-official.test.mjs && node test/workspace-changes-official.test.mjs && node test/host-official.test.mjs && node test/speech-official.test.mjs && node test/agent-team-official.test.mjs && node test/file-upload-official.test.mjs && node test/package-install.test.mjs",
35
- "test:ui": "node --test test/connection-choice-ui.test.cjs test/network-diagnostics-ui.test.cjs"
35
+ "test:ui": "node --test test/connection-choice-ui.test.cjs test/network-diagnostics-ui.test.cjs test/client-device-panel.render.test.cjs"
36
36
  },
37
37
  "exports": {
38
38
  ".": "./lib/index.mjs",