dsh-plugin-weapp-gateway 0.8.47 → 0.8.48

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 (3) hide show
  1. package/README.md +8 -0
  2. package/lib/client.js +157 -173
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -6,6 +6,14 @@
6
6
 
7
7
  `dsh-plugin-weapp-gateway` · DeepSeek Harness 移动客户端连接插件
8
8
 
9
+ ### v0.8.48 · 配对界面拆分为两个模块(App 连接修复)
10
+
11
+ - 「连接与配对」拆成两个独立模块,避免把小程序中继码当 App 码用:
12
+ - **小程序连接(推荐)**:自动选择 / 鲸尾公网 · 小程序,独立的中继状态与「生成小程序二维码」按钮;
13
+ - **App 直连(备用)**:局域网直连 / Cloudflare 外网 / Tailscale 私有网络 / 公网或其他手动地址,统一的配对入口地址与「生成 App 二维码」按钮(上游插件的直连方式)。
14
+ - 两个模块各自生成二维码、各自维护地址与按钮状态,互不影响;中继信息块只出现在小程序模块,App 模块不再出现鲸尾公网内容。
15
+ - 协议层排查:本机复现 App 配对(LAN 入口 `dsh-pair` 握手 → `paired`/`hello` v3 → token 重连)正常;LAN / 自定义地址 / Tailscale / Cloudflare 四种 App 路线均返回 201 的 v2 直连载荷。此前 App 连不上最可能的原因是扫了「鲸尾公网 · 小程序」的中继专用码(v3,App 无法使用)。
16
+ - 渲染测试与帮助文案同步;全量测试通过。
9
17
  ### v0.8.47 · 手动地址方案不再显示鲸尾公网内容
10
18
 
11
19
  - 中继信息块(「鲸尾公网服务 · 已注册」、中继连接器状态、单独中继二维码提示)只在「自动选择」和「鲸尾公网 · 小程序」方案下显示;「公网或其他手动地址」「局域网直连」「Cloudflare 外网」「Tailscale 私有网络」方案不再出现鲸尾公网相关内容。
package/lib/client.js CHANGED
@@ -545,8 +545,10 @@ window.__ModuleLoader__.load({
545
545
  const [showAllDevices, setShowAllDevices] = React.useState(false)
546
546
  const [status, setStatus] = React.useState(null)
547
547
  const [dismissedNotice, setDismissedNotice] = React.useState(() => dismissedRestartInstance)
548
- const [publicUrl, setPublicUrl] = React.useState('')
549
- const [pairingRoute, setPairingRoute] = React.useState('auto')
548
+ // 两个配对模块各自维护方案:小程序(主用)与 App 直连(备用)。
549
+ const [appUrl, setAppUrl] = React.useState('')
550
+ const [miniPlan, setMiniPlan] = React.useState('auto')
551
+ const [appRoute, setAppRoute] = React.useState('lan')
550
552
  const [connectionHelpOpen, setConnectionHelpOpen] = React.useState(false)
551
553
  const [toolsOpen, setToolsOpen] = React.useState(false)
552
554
  const [toolBusy, setToolBusy] = React.useState(false)
@@ -613,10 +615,11 @@ window.__ModuleLoader__.load({
613
615
  const [offlineClearing, setOfflineClearing] = React.useState(false)
614
616
 
615
617
  const revokingIdsRef = React.useRef(new Set())
616
- const manualUrlRef = React.useRef(false)
617
- const automaticUrlRef = React.useRef('')
618
- const pairingRouteRef = React.useRef('auto')
619
- const pairingRouteSelectedRef = React.useRef(false)
618
+ const manualAppUrlRef = React.useRef(false)
619
+ const appUrlRef = React.useRef('')
620
+ const appRouteRef = React.useRef('lan')
621
+ const appRouteChosenRef = React.useRef(false)
622
+ const miniChosenRef = React.useRef(false)
620
623
  const cloudflareModeLoadedRef = React.useRef(false)
621
624
 
622
625
  const refresh = React.useCallback(async () => {
@@ -648,20 +651,15 @@ window.__ModuleLoader__.load({
648
651
  cloudflareModeLoadedRef.current = true
649
652
  setCloudflareMode(statusData.cloudflare.mode || 'quick')
650
653
  }
651
- // Adopt the saved legacy mode only until the operator makes a choice;
652
- // polling must not overwrite an in-progress route change.
653
- if (!pairingRouteSelectedRef.current) {
654
- const savedRoute = statusData.pairingMode === 'relay' ? 'relay' : 'auto'
655
- pairingRouteRef.current = savedRoute
656
- setPairingRoute(savedRoute)
657
- }
658
- // 自定义地址与手动填写的 Tailscale 地址不能被轮询覆盖。
659
- if (pairingRouteRef.current !== 'custom'
660
- && !(pairingRouteRef.current === 'tailscale' && manualUrlRef.current)) {
661
- const preferredUrl = pairingUrlFor(pairingRouteRef.current, statusData)
662
- if (automaticUrlRef.current && preferredUrl !== automaticUrlRef.current) setQr(null)
663
- automaticUrlRef.current = preferredUrl
664
- setPublicUrl(preferredUrl)
654
+ // 小程序方案只在首次加载时按保存的配对模式选择,之后不覆盖运营者选择。
655
+ if (!miniChosenRef.current) setMiniPlan(statusData.pairingMode === 'relay' ? 'relay' : 'auto')
656
+ // App 模块地址跟随环境刷新;自定义地址与手动填写的 Tailscale 地址不被覆盖。
657
+ if (appRouteRef.current !== 'custom'
658
+ && !(appRouteRef.current === 'tailscale' && manualAppUrlRef.current)) {
659
+ const preferredUrl = pairingUrlFor(appRouteRef.current, statusData)
660
+ if (appUrlRef.current && preferredUrl !== appUrlRef.current) setQr(null)
661
+ appUrlRef.current = preferredUrl
662
+ setAppUrl(preferredUrl)
665
663
  }
666
664
  return true
667
665
  } catch (cause) {
@@ -826,45 +824,25 @@ window.__ModuleLoader__.load({
826
824
  return () => previousFocus?.focus()
827
825
  }, [qr])
828
826
 
829
- const changePairingMode = async (mode) => {
830
- setBusy(true)
831
- setError(null)
832
- try {
833
- const data = await request('/mgw/mode', {
834
- method: 'POST',
835
- headers: { 'Content-Type': 'application/json' },
836
- body: JSON.stringify({ mode }),
837
- })
838
- setStatus((current) => ({ ...(current || {}), pairingMode: data.pairingMode, relay: data.relay }))
839
- } catch (cause) {
840
- setError(cause.message)
841
- } finally {
842
- setBusy(false)
843
- }
827
+
828
+ const chooseMiniPlan = (plan) => {
829
+ setQr(null)
830
+ miniChosenRef.current = true
831
+ setMiniPlan(plan)
844
832
  }
845
833
 
846
- const choosePairingRoute = (route) => {
834
+ // App 模块方案:自定义地址与手动 Tailscale 地址不随轮询覆盖。
835
+ const chooseAppRoute = (route) => {
847
836
  setQr(null)
848
- const previousRoute = pairingRouteRef.current
849
- pairingRouteSelectedRef.current = true
850
- pairingRouteRef.current = route
851
- setPairingRoute(route)
852
- manualUrlRef.current = false
853
- if (route === 'custom') {
854
- automaticUrlRef.current = ''
855
- // 「公网或其他手动地址」不从其它方案(尤其鲸尾中继)继承地址:
856
- // 有已配置的公网 WSS 入口时预填它,否则留空等待填写。
857
- setPublicUrl((publicSetup && publicSetup.publicUrl) || '')
858
- } else if (status) {
859
- const nextUrl = pairingUrlFor(route, status)
860
- automaticUrlRef.current = nextUrl
861
- setPublicUrl(nextUrl)
862
- }
863
- const targetMode = route === 'relay' ? 'relay' : 'direct'
864
- if (status && status.pairingMode !== targetMode &&
865
- (route === 'relay' || previousRoute === 'relay')) {
866
- void changePairingMode(targetMode)
867
- }
837
+ appRouteChosenRef.current = true
838
+ appRouteRef.current = route
839
+ setAppRoute(route)
840
+ manualAppUrlRef.current = false
841
+ const nextUrl = route === 'custom'
842
+ ? (publicSetup && publicSetup.publicUrl) || ''
843
+ : (status ? pairingUrlFor(route, status) : '')
844
+ appUrlRef.current = nextUrl
845
+ setAppUrl(nextUrl)
868
846
  }
869
847
 
870
848
  const configurePublicAccess = async () => {
@@ -878,9 +856,10 @@ window.__ModuleLoader__.load({
878
856
  body: JSON.stringify({ publicIp }),
879
857
  })
880
858
  setPublicSetup(data)
881
- if (data.publicUrl && pairingRouteRef.current === 'auto') {
882
- automaticUrlRef.current = data.publicUrl
883
- setPublicUrl(data.publicUrl)
859
+ // 手动地址模块尚未编辑时,把刚配置好的公网入口预填进去。
860
+ if (data.publicUrl && appRouteRef.current === 'custom' && !manualAppUrlRef.current) {
861
+ appUrlRef.current = data.publicUrl
862
+ setAppUrl(data.publicUrl)
884
863
  }
885
864
  } catch (cause) {
886
865
  setError(cause.message)
@@ -939,30 +918,41 @@ window.__ModuleLoader__.load({
939
918
  }
940
919
  }
941
920
 
942
- const createPairing = async (endpoint) => request('/mgw/pair', {
921
+ const requestPairing = async (body) => request('/mgw/pair', {
943
922
  method: 'POST',
944
923
  headers: { 'Content-Type': 'application/json' },
945
- body: JSON.stringify({
946
- publicUrl: pairingRoute === 'tailscale' ? tailscaleEndpointOf(endpoint, status) : endpoint,
947
- route: pairingRoute,
948
- lanUrl: lanPairingUrl(status),
949
- }),
924
+ body: JSON.stringify({ lanUrl: lanPairingUrl(status), ...body }),
950
925
  })
951
926
 
952
- const pair = async () => {
927
+ // 两个模块各自生成二维码:
928
+ // 小程序:自动选择(多路载荷,小程序优先中继)或鲸尾公网中继专用码;
929
+ // App:局域网 / Cloudflare / Tailscale / 手动地址(上游插件的直连方式)。
930
+ const pairFor = async (module) => {
953
931
  setBusy(true)
954
932
  setError(null)
955
933
  setPairingTokenCopied(false)
956
934
  try {
957
- if (pairingRoute === 'relay' && status?.pairingMode !== 'relay') {
958
- const modeData = await request('/mgw/mode', {
959
- method: 'POST',
960
- headers: { 'Content-Type': 'application/json' },
961
- body: JSON.stringify({ mode: 'relay' }),
935
+ let data
936
+ if (module === 'mini') {
937
+ if (miniPlan === 'relay') {
938
+ if (status?.pairingMode !== 'relay') {
939
+ const modeData = await request('/mgw/mode', {
940
+ method: 'POST',
941
+ headers: { 'Content-Type': 'application/json' },
942
+ body: JSON.stringify({ mode: 'relay' }),
943
+ })
944
+ setStatus((current) => ({ ...(current || {}), pairingMode: modeData.pairingMode, relay: modeData.relay }))
945
+ }
946
+ data = await requestPairing({})
947
+ } else {
948
+ data = await requestPairing({ route: 'auto' })
949
+ }
950
+ } else {
951
+ data = await requestPairing({
952
+ publicUrl: appRoute === 'tailscale' ? tailscaleEndpointOf(appUrl, status) : appUrl,
953
+ route: appRoute,
962
954
  })
963
- setStatus((current) => ({ ...(current || {}), pairingMode: modeData.pairingMode, relay: modeData.relay }))
964
955
  }
965
- const data = await createPairing(publicUrl)
966
956
  pairingIdRef.current = data.pairing?.id || null
967
957
  setQr(data)
968
958
  } catch (cause) {
@@ -1144,8 +1134,13 @@ window.__ModuleLoader__.load({
1144
1134
  // routing is carried in an optional field that older apps ignore.
1145
1135
  const relayInfo = status && status.relay ? status.relay : null
1146
1136
  const relayConnector = status && status.relayConnector ? status.relayConnector : null
1147
- const effectiveRoute = pairingRoute
1148
1137
  const cloudflareReady = !!(status?.cloudflare?.enabled && status.cloudflare.publicReady === true && status.cloudflare.publicUrl)
1138
+ // App 模块的生成按钮:入口就绪才可点,避免生成无法连接的二维码。
1139
+ const appPairingDisabled = busy || !(status && status.gatewayEnabled) ||
1140
+ (appRoute === 'custom' && !appUrl.trim()) ||
1141
+ (appRoute === 'cloudflare' && !cloudflareReady) ||
1142
+ (appRoute === 'lan' && !lanPairingUrl(status)) ||
1143
+ (appRoute === 'tailscale' && !(status?.lan?.listening && isTailscaleInput(appUrl)))
1149
1144
 
1150
1145
  const advice = connectionAdvice(status, publicSetup)
1151
1146
  const helpLine = (name, description) => React.createElement('div', { style: { marginTop: 7 } },
@@ -1339,10 +1334,10 @@ window.__ModuleLoader__.load({
1339
1334
  React.createElement('div', { hidden: activeSection !== 'network' },
1340
1335
  React.createElement(ServerNetworkDiagnostics, null)),
1341
1336
  React.createElement('div', { hidden: activeSection !== 'pairing' },
1337
+ // ── 模块一:小程序连接(主用)────────────────────────────────────
1342
1338
  React.createElement('section', { style: styles.card },
1343
- React.createElement('div', { className: 'mgw-setting-row' },
1344
1339
  React.createElement('div', { style: { position: 'relative', display: 'flex', alignItems: 'center', gap: 6, marginBottom: 6 }, onMouseLeave: () => setConnectionHelpOpen(false) },
1345
- React.createElement('h3', { className: 'mgw-section-title', style: { marginBottom: 0 } }, '连接方案'),
1340
+ React.createElement('h3', { className: 'mgw-section-title', style: { marginBottom: 0 } }, '小程序连接(推荐)'),
1346
1341
  React.createElement('button', {
1347
1342
  type: 'button',
1348
1343
  style: styles.helpButton,
@@ -1357,13 +1352,13 @@ window.__ModuleLoader__.load({
1357
1352
  }, '?'),
1358
1353
  connectionHelpOpen ? React.createElement('div', { id: 'mgw-route-help', role: 'tooltip', style: styles.helpBubble },
1359
1354
  React.createElement('strong', null, '怎么选连接方式'),
1360
- helpLine('自动选择', '优先已就绪的公网入口,同时保留局域网与 Tailscale 地址;没有公网入口时小程序自动使用已注册的鲸尾中继。适合大多数情况。'),
1355
+ helpLine('小程序连接(推荐)', '鲸尾小程序在微信里通过鲸尾公网中继连接,不受 wss 域名限制;「自动选择」的二维码同时带上 App 可用的地址。'),
1356
+ helpLine('自动选择', '优先已就绪的公网入口,同时保留局域网与 Tailscale 地址;没有公网入口时小程序自动使用已注册的鲸尾中继。'),
1357
+ helpLine('鲸尾公网 · 小程序', '生成仅供鲸尾小程序使用的中继二维码。'),
1358
+ helpLine('App 直连(备用)', 'DSH App 使用直连入口:局域网直连、Cloudflare 外网、Tailscale 私有网络或公网/手动地址。'),
1361
1359
  helpLine('局域网直连', '手机与 DSH 在同一个可互访的局域网,使用 ws:// 私有地址;离开该网络就无法直连。'),
1362
1360
  helpLine('Cloudflare 外网', 'PC 主动连接 Cloudflare,外网用固定域名的 wss://;需要 Cloudflare 账户和域名。'),
1363
- helpLine('Quick Channel(Quick Tunnel)', '无需账户或域名,Cloudflare 分配临时 wss:// 地址;隧道重建后地址可能变化。'),
1364
1361
  helpLine('Tailscale 私有网络', '可检测本机地址,或填写主机的 100.x 私有地址;手机与电脑需登录同一 tailnet。'),
1365
- helpLine('鲸尾公网 · 小程序', '生成仅供鲸尾小程序使用的中继二维码;要同时配对 DSH App 和小程序,请选「自动选择」。'),
1366
- helpLine('公网服务器连接', 'DSH 运行在有固定公网 IPv4 的 Linux 服务器上,配置公网入口后用 wss:// 公网 IP 连接。'),
1367
1362
  helpLine('公网或其他手动地址', '已配置公网 WSS 反代或只想指定一个固定地址时使用;编辑下方地址即可。'),
1368
1363
  React.createElement('div', { style: { borderTop: `1px solid ${colors.border}`, marginTop: 10, paddingTop: 8 } },
1369
1364
  React.createElement('strong', null, '结合当前环境'),
@@ -1372,96 +1367,90 @@ window.__ModuleLoader__.load({
1372
1367
  React.createElement('div', { style: { marginTop: 6 } }, advice.remote),
1373
1368
  React.createElement('div', { style: { color: colors.muted, marginTop: 6 } }, '面板无法判断手机当前网络;请按手机所在位置选择,提示不会替你修改选择。')))
1374
1369
  : null),
1370
+ React.createElement('p', { style: styles.muted }, '鲸尾小程序通过鲸尾公网中继连接,不需要公网域名;「自动选择」生成的二维码同时兼容 App。'),
1375
1371
  React.createElement('div', { style: { display: 'flex', alignItems: 'center', flexWrap: 'wrap', gap: '8px 14px', maxWidth: '100%' } },
1376
- // 连接方案:与上游一致的整合列表(保留「自动选择」)。Tailscale 私有网络
1377
- // 与「公网或其他手动地址」共用下方统一的配对入口地址输入框。
1378
- React.createElement(GatewaySelect, { style: styles.input, value: effectiveRoute, onChange: (event) => choosePairingRoute(event.target.value), disabled: !status, 'aria-label': '连接方案' },
1372
+ React.createElement(GatewaySelect, { style: styles.input, value: miniPlan, onChange: (event) => chooseMiniPlan(event.target.value), disabled: !status, 'aria-label': '小程序连接方式' },
1379
1373
  React.createElement('option', { value: 'auto' }, '自动选择'),
1380
1374
  React.createElement('option', { value: 'relay', disabled: !status?.relay }, status?.relay
1381
- ? '鲸尾公网 · 小程序' : '鲸尾公网 · 尚未注册'),
1382
- lanPairingUrl(status) || pairingRoute === 'lan'
1383
- ? React.createElement('option', { value: 'lan', disabled: !lanPairingUrl(status) }, lanPairingUrl(status)
1384
- ? '局域网直连'
1385
- : '局域网直连 · 当前不可用')
1386
- : null,
1375
+ ? '鲸尾公网 · 小程序' : '鲸尾公网 · 尚未注册'))),
1376
+ React.createElement('p', { style: { ...styles.muted, margin: '-6px 0 10px' } }, miniPlan === 'relay'
1377
+ ? '此方案生成仅供鲸尾小程序使用的中继二维码;App 请使用下方「App 直连(备用)」。'
1378
+ : '自动选择会优先已就绪的公网入口,同时保留局域网与 Tailscale 地址;小程序没有公网入口时自动使用已注册的鲸尾中继;App 也可使用该二维码。生成新二维码不会断开已连接设备。'),
1379
+ // 中继信息块属于小程序模块(自动选择 / 鲸尾公网中继)。
1380
+ (relayInfo || relayConnector?.running || relayConnector?.delegatedTo || relayConnector?.lastError)
1381
+ ? (relayInfo
1382
+ ? React.createElement('div', { style: { ...styles.muted, margin: '2px 0 0', fontWeight: 500 } },
1383
+ '鲸尾公网服务 · 已注册', ' · ',
1384
+ React.createElement('span', { style: { opacity: .8 } }, `设备 ID ${relayInfo.nodeId.slice(0, 8)}… · ${relayInfo.gatewayName}`),
1385
+ React.createElement('div', { style: { marginTop: 6, padding: '9px 11px', borderRadius: 10, border: '1px solid color-mix(in srgb, var(--dsw-alias-state-warning-primary, #d98324) 26%, transparent)', background: 'color-mix(in srgb, var(--dsw-alias-state-warning-primary, #d98324) 9%, transparent)', fontWeight: 400 } },
1386
+ React.createElement('div', null, '公网 WSS 就绪时,DSH App 和小程序都会获得公网与局域网候选地址;没有公网入口时,App 使用局域网,小程序优先使用已注册的鲸尾公网中继,否则使用局域网。也可单独选择「鲸尾公网 · 小程序」强制生成专用中继二维码。'),
1387
+ React.createElement('div', { style: { marginTop: 5 } }, relayConnector?.running || relayConnector?.delegatedTo
1388
+ ? '中继连接保持运行;切换配对方式不会断开已配对设备。'
1389
+ : relayConnector?.lastError ? '中继连接器暂不可用,请检查网络或重新开启公网连接。'
1390
+ : '中继身份已保存,连接器正在恢复…'),
1391
+ React.createElement('div', { style: { marginTop: 5 } }, '设备配对与公网有效期独立;公网到期不影响局域网。已注册不代表手机端完整链路已通过验证。')))
1392
+ : relayConnector && relayConnector.running
1393
+ ? React.createElement('div', { style: { ...styles.muted, margin: '2px 0 0', fontWeight: 500,
1394
+ color: 'var(--dsw-alias-link, #4176e6)' } }, '内置连接器已自动启动,正在连接中继并上报身份…')
1395
+ : relayConnector && relayConnector.lastError
1396
+ ? React.createElement('div', { style: { ...styles.muted, margin: '2px 0 0', fontWeight: 500, color: colors.danger } },
1397
+ '公网连接器暂时不可用,请检查网络或重新开启公网连接。', ' ',
1398
+ React.createElement('span', { style: { opacity: .8 } }, '如已自行部署连接器,请执行 systemctl restart dsh-connector。'))
1399
+ : React.createElement('div', { style: { ...styles.muted, margin: '2px 0 0' } }, '正在启动内置连接器…(中继模式需要一个本地连接器把小程序流量桥接进来,插件会自动准备)'))
1400
+ : null,
1401
+ React.createElement('div', { style: { display: 'flex', alignItems: 'center', gap: 12, flexWrap: 'wrap', marginTop: 10 } },
1402
+ React.createElement('button', {
1403
+ style: { ...styles.button, ...styles.primary, opacity: busy || !(status && status.gatewayEnabled) || (miniPlan === 'relay' && !status?.relay) ? .65 : 1 },
1404
+ disabled: busy || !(status && status.gatewayEnabled) || (miniPlan === 'relay' && !status?.relay),
1405
+ onClick: () => pairFor('mini'),
1406
+ }, busy ? '正在生成…' : !(status && status.gatewayEnabled) ? '请先开启移动网关'
1407
+ : miniPlan === 'relay' ? '生成小程序中继二维码' : '生成小程序二维码'),
1408
+ React.createElement('span', { style: styles.muted }, '配对码仅可使用一次,5 分钟内有效。'))),
1409
+ // ── 模块二:App 直连(备用)──────────────────────────────────────
1410
+ React.createElement('section', { style: { ...styles.card, marginTop: 16 } },
1411
+ React.createElement('h3', { className: 'mgw-section-title' }, 'App 直连(备用)'),
1412
+ React.createElement('p', { style: styles.muted }, 'DSH App 使用直连入口(上游移动网关的方式);小程序已在上方模块配对时,这里只用于 App。'),
1413
+ React.createElement('div', { style: { display: 'flex', alignItems: 'center', flexWrap: 'wrap', gap: '8px 14px', maxWidth: '100%' } },
1414
+ React.createElement(GatewaySelect, { style: styles.input, value: appRoute, onChange: (event) => chooseAppRoute(event.target.value), disabled: !status, 'aria-label': 'App 连接方式' },
1415
+ React.createElement('option', { value: 'lan', disabled: !lanPairingUrl(status) }, lanPairingUrl(status)
1416
+ ? '局域网直连'
1417
+ : '局域网直连 · 当前不可用'),
1387
1418
  status?.cloudflare?.supported
1388
1419
  ? React.createElement('option', { value: 'cloudflare' }, 'Cloudflare 外网') : null,
1389
1420
  React.createElement('option', { value: 'tailscale', disabled: !(status && status.lan && status.lan.listening) },
1390
1421
  (status && status.lan && status.lan.listening) ? 'Tailscale 私有网络' : 'Tailscale 私有网络 · 请先开启局域网入口'),
1391
- React.createElement('option', { value: 'custom' }, '公网或其他手动地址')),
1392
- status?.cloudflare?.supported && pairingRoute === 'auto'
1393
- ? React.createElement('span', { style: { fontSize: 12, lineHeight: 1.5, fontWeight: 500,
1394
- color: 'var(--dsw-alias-link, #4176e6)' } }, '自动选择会优先尝试已就绪的公网入口,并同时保留局域网与 Tailscale 地址;DSH App 和小程序都可使用这些候选地址。配置 Cloudflare 请切换到“Cloudflare 外网”。')
1395
- : pairingRoute === 'tailscale'
1396
- ? React.createElement('span', { style: { fontSize: 12, lineHeight: 1.5, fontWeight: 500,
1397
- color: 'var(--dsw-alias-link, #4176e6)' } }, (() => {
1398
- const detected = Array.isArray(status?.tailscale?.urls) ? status.tailscale.urls : []
1399
- return detected.length
1400
- ? `已检测到本机 Tailscale 地址:${detected.join('、')}(可直接生成二维码)。手机需登录同一 tailnet;微信小程序线上环境要求 wss 域名,可能只能供 DSH App 使用。`
1401
- : '未检测到本机 Tailscale 地址:请填写运行网关这台主机的 Tailscale IP(不是手机 IP),例如 100.x.x.x 或 ws://100.x.x.x:3081/ws/mobile。手机与电脑需登录同一 tailnet。'
1402
- })())
1403
- : status?.cloudflare?.supported && pairingRoute === 'cloudflare'
1404
- ? React.createElement('span', { style: { fontSize: 12, lineHeight: 1.5, fontWeight: 500,
1405
- color: 'var(--dsw-alias-link, #4176e6)' } }, cloudflareReady
1406
- ? 'Cloudflare 外网已就绪;DSH App 和小程序都可使用公网入口,也会保留局域网候选地址。'
1407
- : 'Cloudflare 尚未就绪,可在本页 Cloudflare 设置中开启并完成连通性检测。')
1408
- : null),
1409
- React.createElement('p', { style: { ...styles.muted, margin: '-6px 0 10px' } }, pairingRoute === 'relay'
1410
- ? '此方案生成仅供鲸尾小程序使用的中继二维码;DSH App 请选「自动选择」或「局域网直连」。'
1411
- : pairingRoute === 'auto'
1412
- ? '公网 WSS 就绪时,DSH App 和小程序都会尝试公网、局域网与 Tailscale 地址;没有公网入口时,App 使用局域网或 Tailscale,小程序优先使用已注册的鲸尾中继,否则也使用局域网。生成新二维码不会断开已连接设备。'
1413
- : pairingRoute === 'tailscale'
1414
- ? '此方案只生成 Tailscale 私有网络二维码;手机与电脑需登录同一 tailnet。微信小程序线上环境要求 wss 域名,可能无法使用,请改用局域网/公网地址或 tailscale serve。'
1415
- : '当前方案仅使用所选入口;编辑「配对入口地址」会切换到「公网或其他手动地址」。'),
1416
- // 中继信息块只属于会用到中继的方案(中继 / 自动选择);
1417
- // 手动地址、局域网、Cloudflare、Tailscale 方案不应出现鲸尾公网内容。
1418
- (pairingRoute === 'relay' || pairingRoute === 'auto') && (relayInfo || relayConnector?.running || relayConnector?.delegatedTo || relayConnector?.lastError)
1419
- ? (relayInfo
1420
- ? React.createElement('div', { style: { ...styles.muted, margin: '2px 0 0', fontWeight: 500 } },
1421
- '鲸尾公网服务 · 已注册', ' · ',
1422
- React.createElement('span', { style: { opacity: .8 } }, `设备 ID ${relayInfo.nodeId.slice(0, 8)}… · ${relayInfo.gatewayName}`),
1423
- React.createElement('div', { style: { marginTop: 6, padding: '9px 11px', borderRadius: 10, border: '1px solid color-mix(in srgb, var(--dsw-alias-state-warning-primary, #d98324) 26%, transparent)', background: 'color-mix(in srgb, var(--dsw-alias-state-warning-primary, #d98324) 9%, transparent)', fontWeight: 400 } },
1424
- React.createElement('div', null, '公网 WSS 就绪时,DSH App 和小程序都会获得公网与局域网候选地址;没有公网入口时,App 使用局域网,小程序优先使用已注册的鲸尾公网中继,否则使用局域网。也可单独选择「鲸尾公网 · 小程序」强制生成专用中继二维码。'),
1425
- React.createElement('div', { style: { marginTop: 5 } }, relayConnector?.running || relayConnector?.delegatedTo
1426
- ? '中继连接保持运行;切换配对方式不会断开已配对设备。'
1427
- : relayConnector?.lastError ? '中继连接器暂不可用,请检查网络或重新开启公网连接。'
1428
- : '中继身份已保存,连接器正在恢复…'),
1429
- React.createElement('div', { style: { marginTop: 5 } }, '设备配对与公网有效期独立;公网到期不影响局域网。已注册不代表手机端完整链路已通过验证。')))
1430
- : relayConnector && relayConnector.running
1431
- ? React.createElement('div', { style: { ...styles.muted, margin: '2px 0 0', fontWeight: 500,
1432
- color: 'var(--dsw-alias-link, #4176e6)' } }, '内置连接器已自动启动,正在连接中继并上报身份…')
1433
- : relayConnector && relayConnector.lastError
1434
- ? React.createElement('div', { style: { ...styles.muted, margin: '2px 0 0', fontWeight: 500, color: colors.danger } },
1435
- '公网连接器暂时不可用,请检查网络或重新开启公网连接。', ' ',
1436
- React.createElement('span', { style: { opacity: .8 } }, '如已自行部署连接器,请执行 systemctl restart dsh-connector。'))
1437
- : React.createElement('div', { style: { ...styles.muted, margin: '2px 0 0' } }, '正在启动内置连接器…(中继模式需要一个本地连接器把小程序流量桥接进来,插件会自动准备)'))
1438
- : null),
1439
- // 与上游一致的统一「配对入口地址」输入框:所有方案共用;编辑即切换到
1440
- // 「公网或其他手动地址」,Tailscale 方案则保留为手动主机地址。
1441
- React.createElement('label', { style: styles.label, htmlFor: 'mgw-pair-address' }, pairingRoute === 'tailscale'
1422
+ React.createElement('option', { value: 'custom' }, '公网或其他手动地址'))),
1423
+ React.createElement('label', { style: styles.label, htmlFor: 'mgw-pair-address' }, appRoute === 'tailscale'
1442
1424
  ? '主机 Tailscale 地址(运行网关的电脑,不是手机)'
1443
1425
  : '配对入口地址(手机需能访问)'),
1444
1426
  React.createElement('input', {
1445
1427
  id: 'mgw-pair-address',
1446
1428
  style: styles.input,
1447
- value: publicUrl,
1429
+ value: appUrl,
1448
1430
  onChange: (event) => {
1449
1431
  const value = event.target.value
1450
- if (pairingRoute === 'tailscale') { manualUrlRef.current = true; setPublicUrl(value); return }
1451
- if (pairingRoute !== 'custom') { choosePairingRoute('custom'); setPublicUrl(value); return }
1452
- setPublicUrl(value)
1432
+ if (appRoute === 'tailscale') { manualAppUrlRef.current = true; setAppUrl(value); return }
1433
+ if (appRoute !== 'custom') { chooseAppRoute('custom'); setAppUrl(value); return }
1434
+ setAppUrl(value)
1453
1435
  },
1454
- placeholder: pairingRoute === 'tailscale'
1436
+ placeholder: appRoute === 'tailscale'
1455
1437
  ? '100.x.x.x 或 ws://100.x.x.x:3081/ws/mobile(IPv6 用 [fd7a:…])'
1456
1438
  : 'ws://192.168.1.10:3081/ws/mobile 或 wss://gateway.example.com/ws/mobile',
1457
- readOnly: pairingRoute === 'relay',
1458
- title: pairingRoute === 'relay' ? '鲸尾中继地址由注册信息决定;需要自定义地址请选「公网或其他手动地址」' : undefined,
1459
1439
  spellCheck: false,
1460
1440
  }),
1461
- pairingRoute === 'tailscale' && publicUrl.trim() && !isTailscaleInput(publicUrl)
1441
+ appRoute === 'tailscale' && appUrl.trim() && !isTailscaleInput(appUrl)
1462
1442
  ? React.createElement('div', { style: { ...styles.error, margin: '-4px 0 8px' } }, '这里要填 100.64.0.0/10(或 fd7a:115c:a1e0::/48)的 Tailscale 私有地址。')
1463
1443
  : null,
1464
- pairingRoute !== 'tailscale' && status && status.lan && status.lan.enabled
1444
+ // Tailscale 手动地址指引:检测到本机地址时提示可直接使用。
1445
+ appRoute === 'tailscale'
1446
+ ? React.createElement('div', { style: { ...styles.muted, margin: '-4px 0 10px', fontWeight: 500 } }, (() => {
1447
+ const detected = Array.isArray(status?.tailscale?.urls) ? status.tailscale.urls : []
1448
+ return detected.length
1449
+ ? `已检测到本机 Tailscale 地址:${detected.join('、')}(可直接生成二维码)。手机需登录同一 tailnet。`
1450
+ : '未检测到本机 Tailscale 地址:请填写运行网关这台主机的 Tailscale IP(不是手机 IP),例如 100.x.x.x。手机与电脑需登录同一 tailnet。'
1451
+ })())
1452
+ : null,
1453
+ appRoute !== 'tailscale' && status && status.lan && status.lan.enabled
1465
1454
  ? React.createElement('div', { style: { ...styles.muted, margin: '-7px 0 10px', fontWeight: 500, color: status.lan.error ? colors.danger : status.lan.listening ? colors.success : 'var(--dsw-alias-link, #4176e6)' } },
1466
1455
  status.lan.error
1467
1456
  ? `局域网监听失败:${status.lan.error}`
@@ -1469,30 +1458,25 @@ window.__ModuleLoader__.load({
1469
1458
  ? `局域网入口已开启${status.lan.urls && status.lan.urls.length ? `:${status.lan.urls.join('、')}` : `,端口 ${status.lan.port}`}`
1470
1459
  : '局域网入口启动中…')
1471
1460
  : null,
1472
- // Tailscale 直连:同一 tailnet 的手机可直接连 ws://100.x 地址,无需 tailscale serve。
1473
- status && status.tailscale && Array.isArray(status.tailscale.urls) && status.tailscale.urls.length
1474
- ? React.createElement('div', { style: { ...styles.muted, margin: '-7px 0 10px', fontWeight: 500, color: colors.success } },
1475
- `Tailscale 直连可用:${status.tailscale.urls.join('、')}`)
1476
- : status && status.tailscale && Array.isArray(status.tailscale.addresses) && status.tailscale.addresses.length
1477
- ? React.createElement('div', { style: { ...styles.muted, margin: '-7px 0 10px', fontWeight: 500, color: 'var(--dsw-alias-link, #4176e6)' } },
1478
- `检测到 Tailscale 地址 ${status.tailscale.addresses.join('、')};开启局域网入口后可直接使用。`)
1479
- : null,
1480
- React.createElement('button', {
1481
- style: { ...styles.button, ...styles.primary, opacity: busy || !(status && status.gatewayEnabled) || (pairingRoute === 'custom' && !publicUrl.trim()) || (pairingRoute === 'cloudflare' && !cloudflareReady) || (pairingRoute === 'tailscale' && !(status?.lan?.listening && isTailscaleInput(publicUrl))) ? .65 : 1 },
1482
- disabled: busy || !(status && status.gatewayEnabled) ||
1483
- (pairingRoute === 'custom' && !publicUrl.trim()) ||
1484
- (pairingRoute === 'cloudflare' && !cloudflareReady) ||
1485
- (pairingRoute === 'tailscale' && !(status?.lan?.listening && isTailscaleInput(publicUrl))) ||
1486
- (pairingRoute === 'relay' && !status?.relay),
1487
- onClick: pair,
1488
- }, busy ? '正在生成…' : !(status && status.gatewayEnabled) ? '请先开启移动网关'
1489
- : pairingRoute === 'cloudflare' && !cloudflareReady
1490
- ? status?.cloudflare?.enabled ? '等待 Cloudflare 外网就绪' : '先开启 Cloudflare Tunnel'
1491
- : (pairingRoute === 'tailscale' && !status?.lan?.listening) ? '请先开启局域网入口'
1492
- : (pairingRoute === 'tailscale' && !isTailscaleInput(publicUrl)) ? '填写主机 Tailscale 地址'
1493
- : (pairingRoute === 'custom' && !publicUrl.trim()) ? '等待连接地址' : '生成配对二维码'),
1494
- React.createElement('p', { style: { ...styles.muted, margin: '10px 0 0' } }, '配对码仅可使用一次,5 分钟内有效。')),
1495
- pairingRoute === 'cloudflare' && status?.cloudflare?.supported
1461
+ appRoute === 'cloudflare' && !cloudflareReady
1462
+ ? React.createElement('div', { style: { ...styles.muted, margin: '-4px 0 10px', fontWeight: 500 } }, status?.cloudflare?.enabled
1463
+ ? 'Cloudflare 外网尚未就绪,请稍候或查看下方 Cloudflare 设置。'
1464
+ : '尚未开启 Cloudflare Tunnel,可在下方设置中一键开启。')
1465
+ : null,
1466
+ React.createElement('div', { style: { display: 'flex', alignItems: 'center', gap: 12, flexWrap: 'wrap' } },
1467
+ React.createElement('button', {
1468
+ style: { ...styles.button, ...styles.primary, opacity: appPairingDisabled ? .65 : 1 },
1469
+ disabled: appPairingDisabled,
1470
+ onClick: () => pairFor('app'),
1471
+ }, busy ? '正在生成…' : !(status && status.gatewayEnabled) ? '请先开启移动网关'
1472
+ : appRoute === 'cloudflare' && !cloudflareReady
1473
+ ? status?.cloudflare?.enabled ? '等待 Cloudflare 外网就绪' : '先开启 Cloudflare Tunnel'
1474
+ : appRoute === 'tailscale' && !status?.lan?.listening ? '请先开启局域网入口'
1475
+ : appRoute === 'tailscale' && !isTailscaleInput(appUrl) ? '填写主机 Tailscale 地址'
1476
+ : appRoute === 'lan' && !lanPairingUrl(status) ? '当前不可用'
1477
+ : appRoute === 'custom' && !appUrl.trim() ? '等待连接地址' : '生成 App 二维码'),
1478
+ React.createElement('span', { style: styles.muted }, '二维码只发给 App;小程序请用上方模块。'))),
1479
+ appRoute === 'cloudflare' && status?.cloudflare?.supported
1496
1480
  ? React.createElement('section', { className: 'mgw-cloudflare-block', style: { ...styles.card, background: colors.card, border: 0, borderRadius: 16, padding: 18, marginTop: 16 } },
1497
1481
  React.createElement('h3', { className: 'mgw-section-title' }, 'Cloudflare Tunnel · 外网接入'),
1498
1482
  React.createElement('p', { style: styles.muted }, status.platform === 'linux'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-weapp-gateway",
3
- "version": "0.8.47",
3
+ "version": "0.8.48",
4
4
  "description": "鲸尾网关助手:DeepSeek Harness 移动客户端连接与会话同步,支持安全配对、远程访问、上下文、编队、额度和语音输入",
5
5
  "main": "lib/index.mjs",
6
6
  "files": [