dsh-plugin-weapp-gateway 0.8.50 → 0.8.53

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/PROTOCOL.md CHANGED
@@ -622,6 +622,13 @@ let image = [
622
622
 
623
623
  ```json
624
624
  { "kind": "session-queue", "sessionId": "session-abc", "items": [] }
625
+
626
+ 客户端也可以主动拉取当前会话队列(小程序在打开会话、发送排队消息、回到前台时使用;控制流推送丢失时靠它兜底):
627
+
628
+ → { "type": "session-queue", "sessionId": "session-abc", "requestId": "rq-1" }
629
+ ← { "kind": "session-queue", "sessionId": "session-abc", "items": [...], "requestId": "rq-1" }
630
+
631
+ 网关直接读取 Host 的 projections.values.inbox 生成 items;旧版 Host 没有该投影时返回空数组。
625
632
  ```
626
633
 
627
634
  - `session-queues.queues` 是全量快照,客户端必须整体替换所有 Session 的本地队列;快照里消失的 Session 也要清除。
package/README.md CHANGED
@@ -6,6 +6,18 @@
6
6
 
7
7
  `dsh-plugin-weapp-gateway` · DeepSeek Harness 移动客户端连接插件
8
8
 
9
+ ### v0.8.52 · 兼容 App 下拉与方案摘要之间留出间距
10
+
11
+ - 「兼容 App(备用)」的连接方式下拉与下方「配对入口」摘要卡片之间增加间距(16px),下拉不再紧贴提示卡片。
12
+ - 摘要卡片的内边距、下方「配对入口地址」输入框与其余配对布局保持不变。
13
+ - 全量测试通过。
14
+ ### v0.8.51 · 配对面板细节打磨
15
+
16
+ - 小程序模块去掉「鲸尾公网 · 小程序 / 中继优先,局域网兜底」说明行(上方描述文案已含同样信息)。
17
+ - 「鲸尾公网服务 · 已注册」下的提示大卡片移除,精简为一行连接器状态(运行中 / 异常 / 恢复中,带颜色标识)。
18
+ - 「兼容 App(备用)」层新增上游样式的**连接方案摘要**:按所选入口显示「配对入口」与提示——局域网 / Cloudflare / Tailscale / 手动地址各自判定(公网必须 wss、内网可 ws,含回环地址与子网路由提示),与上游 `pairingConnectionPlan` 同一判定思路。
19
+ - 「兼容 App」右侧箭头改为与下拉一致的 SVG chevron(展开时旋转 180°,带过渡动画),替换原来的文字箭头。
20
+ - 全量测试通过。
9
21
  ### v0.8.50 · 小程序固定中继优先、局域网兜底;自动选择移到 App 层
10
22
 
11
23
  - 小程序模块不再提供「自动选择」,固定为**鲸尾公网 · 小程序**:二维码改为小程序专用 v2 载荷(`routes` 同时包含中继与局域网端点,不生成 `miniProgramRoute`),因此小程序**先连中继、连不上再回落局域网**(旧的 v3 中继专用码不会回落局域网)。
package/lib/client.js CHANGED
@@ -379,6 +379,65 @@ window.__ModuleLoader__.load({
379
379
  return /^fd7a:115c:a1e0:/i.test(host)
380
380
  }
381
381
 
382
+ // 与上游一致的连接方案摘要:按所选入口给出「配对入口 + 提示」。
383
+ function appConnectionPlan(route, status, rawUrl) {
384
+ const lanUrl = lanPairingUrl(status)
385
+ if (route === 'auto') {
386
+ return {
387
+ valid: !!lanUrl,
388
+ entry: '自动选择(公网优先,局域网兜底)',
389
+ note: lanUrl ? '手机会按实际连通情况在公网与局域网之间自动切换。' : '局域网入口不可用;自动选择需要一个手机可访问的局域网或公网入口。',
390
+ }
391
+ }
392
+ if (route === 'lan') {
393
+ return {
394
+ valid: !!lanUrl,
395
+ entry: '局域网直连',
396
+ note: lanUrl ? '同一局域网可直接访问;离开该网络就无法直连。' : '局域网入口不可用,请先开启基本设置中的局域网入口。',
397
+ }
398
+ }
399
+ if (route === 'cloudflare') {
400
+ const ready = !!(status?.cloudflare?.enabled && status.cloudflare.publicReady === true && status.cloudflare.publicUrl)
401
+ return {
402
+ valid: ready,
403
+ entry: 'Cloudflare Tunnel',
404
+ note: ready ? '公网入口已验证可达;手机在任何网络都可尝试。' : '公网入口尚未验证通过,请先完成下方配置和检测。',
405
+ }
406
+ }
407
+ if (route === 'tailscale') {
408
+ const valid = !!(status?.lan?.listening && isTailscaleInput(rawUrl))
409
+ return {
410
+ valid,
411
+ entry: 'Tailscale 私有网络',
412
+ note: valid ? '手机与主机需登录同一 tailnet,并允许访问网关端口。' : '请填写运行网关这台主机的 Tailscale IP(不是手机 IP),例如 100.x.x.x。',
413
+ }
414
+ }
415
+ // custom:按地址特征给提示(与上游 pairingConnectionPlan 同一判定思路)。
416
+ const raw = String(rawUrl || '').trim()
417
+ let endpoint
418
+ try { endpoint = new URL(raw) } catch {
419
+ return { valid: false, entry: '等待填写有效的配对地址', note: '请输入手机能够访问的 ws:// 或 wss:// 地址。' }
420
+ }
421
+ const scheme = endpoint.protocol === 'http:' ? 'ws:' : endpoint.protocol === 'https:' ? 'wss:' : endpoint.protocol
422
+ const host = endpoint.hostname.replace(/^\[|\]$/g, '').toLowerCase()
423
+ const parts = host.split('.').map(Number)
424
+ const ipv4 = parts.length === 4 && parts.every((n) => Number.isInteger(n) && n >= 0 && n <= 255)
425
+ const loopback = host === 'localhost' || host === '::1' || (ipv4 && parts[0] === 127)
426
+ const privateHost = loopback || host.endsWith('.local') ||
427
+ (ipv4 && (parts[0] === 10 || (parts[0] === 172 && parts[1] >= 16 && parts[1] <= 31) ||
428
+ (parts[0] === 192 && parts[1] === 168) || (parts[0] === 169 && parts[1] === 254))) ||
429
+ (host.includes(':') && /^(fc|fd|fe80:)/.test(host))
430
+ if (!['ws:', 'wss:'].includes(scheme) || endpoint.username || endpoint.password || endpoint.search || endpoint.hash ||
431
+ raw.length > 2048 || ['0.0.0.0', '::'].includes(host) || (scheme === 'ws:' && !privateHost)) {
432
+ return { valid: false, entry: '配对地址需要修改', note: '公网地址必须使用 wss://;地址不能包含账号、查询参数或片段。' }
433
+ }
434
+ const entry = loopback ? '本机回环地址' : privateHost ? '局域网或子网路由' : '加密 WebSocket 入口'
435
+ let note = '配对地址已填写,手机是否可达仍需实际连接确认。'
436
+ if (loopback) note = '回环地址仅适用于本机模拟器;真机请填写电脑的局域网、Tailscale 或公网地址。'
437
+ else if (privateHost) note = '同一局域网可直接访问;异地访问此地址需要手机已有可用的子网路由。'
438
+ return { valid: true, entry, note }
439
+ }
440
+
382
441
  // 手动输入的裸 IP 补成 ws://<ip>:<lanPort><wsPath>;已是 URL 的原样返回。
383
442
  function tailscaleEndpointOf(value, status) {
384
443
  const raw = String(value || '').trim()
@@ -1124,6 +1183,7 @@ window.__ModuleLoader__.load({
1124
1183
  (appRoute === 'auto' && !lanPairingUrl(status)) ||
1125
1184
  (appRoute === 'lan' && !lanPairingUrl(status)) ||
1126
1185
  (appRoute === 'tailscale' && !(status?.lan?.listening && isTailscaleInput(appUrl)))
1186
+ const appPlan = appConnectionPlan(appRoute, status, appUrl)
1127
1187
 
1128
1188
  const advice = connectionAdvice(status, publicSetup)
1129
1189
  const helpLine = (name, description) => React.createElement('div', { style: { marginTop: 7 } },
@@ -1351,23 +1411,18 @@ window.__ModuleLoader__.load({
1351
1411
  React.createElement('div', { style: { color: colors.muted, marginTop: 6 } }, '面板无法判断手机当前网络;请按手机所在位置选择,提示不会替你修改选择。')))
1352
1412
  : null),
1353
1413
  React.createElement('p', { style: styles.muted }, '小程序默认通过鲸尾公网中继连接,不需要公网域名;手机与网关在同一局域网时自动兜底直连。'),
1354
- React.createElement('div', { style: { display: 'flex', alignItems: 'center', flexWrap: 'wrap', gap: '8px 14px', maxWidth: '100%', marginBottom: 2 } },
1355
- React.createElement('strong', { style: { fontWeight: 600 } }, '鲸尾公网 · 小程序'),
1356
- React.createElement('span', { style: styles.muted }, '中继优先,局域网兜底'),
1357
- status?.relay ? null : React.createElement('span', { style: { ...styles.muted, color: colors.danger, fontWeight: 500 } }, '尚未注册中继')),
1414
+
1358
1415
  // 中继信息块属于小程序模块(自动选择 / 鲸尾公网中继)。
1359
1416
  (relayInfo || relayConnector?.running || relayConnector?.delegatedTo || relayConnector?.lastError)
1360
1417
  ? (relayInfo
1361
1418
  ? React.createElement('div', { style: { ...styles.muted, margin: '2px 0 0', fontWeight: 500 } },
1362
1419
  '鲸尾公网服务 · 已注册', ' · ',
1363
1420
  React.createElement('span', { style: { opacity: .8 } }, `设备 ID ${relayInfo.nodeId.slice(0, 8)}… · ${relayInfo.gatewayName}`),
1364
- 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 } },
1365
- React.createElement('div', null, '公网 WSS 就绪时,DSH App 和小程序都会获得公网与局域网候选地址;没有公网入口时,App 使用局域网,小程序优先使用已注册的鲸尾公网中继,否则使用局域网。也可单独选择「鲸尾公网 · 小程序」强制生成专用中继二维码。'),
1366
- React.createElement('div', { style: { marginTop: 5 } }, relayConnector?.running || relayConnector?.delegatedTo
1367
- ? '中继连接保持运行;切换配对方式不会断开已配对设备。'
1368
- : relayConnector?.lastError ? '中继连接器暂不可用,请检查网络或重新开启公网连接。'
1369
- : '中继身份已保存,连接器正在恢复…'),
1370
- React.createElement('div', { style: { marginTop: 5 } }, '设备配对与公网有效期独立;公网到期不影响局域网。已注册不代表手机端完整链路已通过验证。')))
1421
+ React.createElement('div', { style: { marginTop: 4, color: relayConnector?.lastError ? colors.danger : relayConnector?.running || relayConnector?.delegatedTo ? colors.success : 'var(--dsw-alias-link, #4176e6)' } },
1422
+ relayConnector?.running || relayConnector?.delegatedTo
1423
+ ? '中继连接保持运行'
1424
+ : relayConnector?.lastError ? `中继连接器异常:${relayConnector.lastError}`
1425
+ : '中继连接器正在恢复…'))
1371
1426
  : relayConnector && relayConnector.running
1372
1427
  ? React.createElement('div', { style: { ...styles.muted, margin: '2px 0 0', fontWeight: 500,
1373
1428
  color: 'var(--dsw-alias-link, #4176e6)' } }, '内置连接器已自动启动,正在连接中继并上报身份…')
@@ -1398,11 +1453,14 @@ window.__ModuleLoader__.load({
1398
1453
  React.createElement('strong', null, '兼容 App(备用)'),
1399
1454
  React.createElement('span', { style: { ...styles.muted, marginLeft: 8, fontWeight: 400 } },
1400
1455
  appLayerOpen ? '收起 App 兼容方式' : '需要连接 DSH App 时展开')),
1401
- React.createElement('span', { 'aria-hidden': true, style: styles.muted }, appLayerOpen ? '▾' : '▸')),
1456
+ React.createElement('svg', { width: 16, height: 16, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor',
1457
+ strokeWidth: 1.8, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true,
1458
+ style: { flexShrink: 0, color: colors.muted, transform: appLayerOpen ? 'rotate(180deg)' : 'none', transition: 'transform .18s ease' } },
1459
+ React.createElement('path', { d: 'M6 9l6 6 6-6' }))),
1402
1460
  appLayerOpen
1403
1461
  ? React.createElement(React.Fragment, null,
1404
1462
  React.createElement('p', { style: styles.muted }, '仅用于 DSH App(上游移动网关的直连方式),与上方鲸尾公网互不影响。'),
1405
- React.createElement('div', { style: { display: 'flex', alignItems: 'center', flexWrap: 'wrap', gap: '8px 14px', maxWidth: '100%' } },
1463
+ React.createElement('div', { style: { display: 'flex', alignItems: 'center', flexWrap: 'wrap', gap: '8px 14px', maxWidth: '100%', marginBottom: 16 } },
1406
1464
  React.createElement(GatewaySelect, { style: styles.input, value: appRoute, onChange: (event) => chooseAppRoute(event.target.value), disabled: !status, 'aria-label': 'App 连接方式' },
1407
1465
  React.createElement('option', { value: 'auto' }, '自动选择'),
1408
1466
  React.createElement('option', { value: 'lan', disabled: !lanPairingUrl(status) }, lanPairingUrl(status)
@@ -1413,6 +1471,10 @@ window.__ModuleLoader__.load({
1413
1471
  React.createElement('option', { value: 'tailscale', disabled: !(status && status.lan && status.lan.listening) },
1414
1472
  (status && status.lan && status.lan.listening) ? 'Tailscale 私有网络' : 'Tailscale 私有网络 · 请先开启局域网入口'),
1415
1473
  React.createElement('option', { value: 'custom' }, '公网或其他手动地址'))),
1474
+ // 与上游一致的连接方案摘要:配对入口 + 提示。
1475
+ 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 } },
1476
+ React.createElement('div', null, React.createElement('strong', null, '配对入口'), ':', appPlan.entry),
1477
+ React.createElement('div', { style: { color: appPlan.valid ? colors.muted : colors.danger } }, appPlan.note)),
1416
1478
  React.createElement('label', { style: styles.label, htmlFor: 'mgw-pair-address' }, appRoute === 'tailscale'
1417
1479
  ? '主机 Tailscale 地址(运行网关的电脑,不是手机)'
1418
1480
  : '配对入口地址(手机需能访问)'),
package/lib/index.mjs CHANGED
@@ -63,6 +63,7 @@ import { stringifyWireFrame } from './wire-json.mjs'
63
63
  // { "type": "permission", "sessionId", "name" } -> switch preset via /permission command
64
64
  // { "type": "context-usage", "sessionId" } -> tokenUsage + contextPressure projections
65
65
  // { "type": "session-stats", "sessionId" } -> sessionStats + tokenUsage projections
66
+ // { "type": "session-queue", "sessionId" } -> queued/steering inbox items (push-loss fallback)
66
67
  // (the input-box stats strip source)
67
68
  // { "type": "tasks", "sessionId" } -> current todo-list projection
68
69
  // { "type": "goal", "sessionId" } -> current goal projection
@@ -1319,6 +1320,32 @@ function requireSessionId(msg) {
1319
1320
  return { value: sessionId }
1320
1321
  }
1321
1322
 
1323
+ // DSH rc.1 carries pending messages in the durable inbox projection.
1324
+ // session/control no longer emits a separate queues baseline or queue frames.
1325
+ function inboxQueueItems(value, endpoint) {
1326
+ if (value == null) return []
1327
+ if (typeof value !== 'object' || Array.isArray(value)
1328
+ || !Array.isArray(value['next-turn']) || !Array.isArray(value['next-step'])) {
1329
+ throw new Error(endpoint + ' returned an invalid inbox projection')
1330
+ }
1331
+ const convert = (messages, target) => messages.map((message) => {
1332
+ if (!message || typeof message !== 'object' || Array.isArray(message)
1333
+ || typeof message.id !== 'string' || !message.id
1334
+ || !Array.isArray(message.content)
1335
+ || !message.source || typeof message.source.kind !== 'string'
1336
+ || (message.source.rpcId !== undefined && typeof message.source.rpcId !== 'string')) {
1337
+ throw new Error(endpoint + ' returned an invalid inbox message')
1338
+ }
1339
+ return {
1340
+ id: message.id,
1341
+ placement: target === 'next-turn' ? 'queued' : message.source.kind === 'user' ? 'steering' : 'context',
1342
+ ...(message.source.rpcId === undefined ? {} : { rpcId: message.source.rpcId }),
1343
+ message: { id: message.id, content: message.content },
1344
+ }
1345
+ })
1346
+ return [...convert(value['next-turn'], 'next-turn'), ...convert(value['next-step'], 'next-step')]
1347
+ }
1348
+
1322
1349
  // Goal mutations use DSH's compare-and-set reference. Returning a stale
1323
1350
  // revision is intentionally rejected by DSH instead of overwriting a newer
1324
1351
  // WebUI/mobile update.
@@ -1796,6 +1823,30 @@ async function handleQuery(api, host, agentDefaultModel, msg, pluginContext) {
1796
1823
  if (ACCOUNT_REQUEST_TYPES.has(msg.type)) return handleAccount(api, msg)
1797
1824
  if (PLUGIN_REQUEST_TYPES.has(msg.type)) return handlePluginQuery(api, msg, pluginContext)
1798
1825
  if (MODEL_CONFIG_REQUEST_TYPES.has(msg.type)) return handleModelConfigQuery(api, msg, { log })
1826
+ if (msg.type === 'session-queue') {
1827
+ // The mini program asks for the queue when it opens a session / sends a queued
1828
+ // message: answer from the durable inbox projection so a dropped control-stream
1829
+ // push can never leave the queue panel permanently empty.
1830
+ const session = requireSessionId(msg)
1831
+ const requestId = typeof msg.requestId === 'string' ? { requestId: msg.requestId } : {}
1832
+ if (session.error) return { ...session.error, ...requestId }
1833
+ if (typeof api.sessions.projections !== 'function') {
1834
+ return { kind: 'session-queue', sessionId: session.value, items: [], ...requestId }
1835
+ }
1836
+ try {
1837
+ const snapshot = await api.sessions.projections({ sessionId: session.value })
1838
+ if (snapshot === null) throw Object.assign(new Error('session not found'), { code: 'session/not-found' })
1839
+ if (!['sequenced', 'migration-required'].includes(snapshot && snapshot.kind) || !snapshot.values) {
1840
+ throw new Error('invalid session projections')
1841
+ }
1842
+ const items = inboxQueueItems(snapshot.values.inbox, 'session-queue request')
1843
+ return { kind: 'session-queue', sessionId: session.value, items, ...requestId }
1844
+ } catch (error) {
1845
+ return { kind: 'error', code: (error && error.code) || 'internal',
1846
+ message: error && error.message ? error.message : String(error),
1847
+ requestType: 'session-queue', sessionId: session.value, ...requestId }
1848
+ }
1849
+ }
1799
1850
  if (msg.type === 'agent-team' || msg.type === 'subagents') {
1800
1851
  const target = sessionTargetFromMessage(msg)
1801
1852
  const requestIdentity = typeof msg.requestId === 'string' ? { requestId: msg.requestId } : {}
@@ -4006,7 +4057,7 @@ const plugin = {
4006
4057
  msg.type === 'clawbot-control' ||
4007
4058
  msg.type === 'defaults' || msg.type === 'set-default' ||
4008
4059
  msg.type === 'session-stats' || msg.type === 'default-model' ||
4009
- msg.type === 'save-default-model' || msg.type === 'fork' || msg.type === 'session-cancel' || msg.type === 'queue-update' ||
4060
+ msg.type === 'save-default-model' || msg.type === 'fork' || msg.type === 'session-cancel' || msg.type === 'queue-update' || msg.type === 'session-queue' ||
4010
4061
  msg.type === 'session-archive' || msg.type === 'session-rename' || msg.type === 'providers' ||
4011
4062
  msg.type === 'tasks' || msg.type === 'goal' || msg.type === 'goal-edit' ||
4012
4063
  msg.type === 'goal-pause' || msg.type === 'goal-resume' || msg.type === 'goal-clear' ||
@@ -4383,31 +4434,7 @@ const plugin = {
4383
4434
  log(`session archive state forwarded: count=${next.length}`)
4384
4435
  }
4385
4436
 
4386
- // DSH rc.1 carries pending messages in the durable inbox projection.
4387
- // session/control no longer emits a separate queues baseline or queue frames.
4388
- const queueItemsFromInbox = (value, endpoint) => {
4389
- if (value == null) return []
4390
- if (typeof value !== 'object' || Array.isArray(value)
4391
- || !Array.isArray(value['next-turn']) || !Array.isArray(value['next-step'])) {
4392
- throw new Error(`${endpoint} returned an invalid inbox projection`)
4393
- }
4394
- const convert = (messages, target) => messages.map((message) => {
4395
- if (!message || typeof message !== 'object' || Array.isArray(message)
4396
- || typeof message.id !== 'string' || !message.id
4397
- || !Array.isArray(message.content)
4398
- || !message.source || typeof message.source.kind !== 'string'
4399
- || (message.source.rpcId !== undefined && typeof message.source.rpcId !== 'string')) {
4400
- throw new Error(`${endpoint} returned an invalid inbox message`)
4401
- }
4402
- return {
4403
- id: message.id,
4404
- placement: target === 'next-turn' ? 'queued' : message.source.kind === 'user' ? 'steering' : 'context',
4405
- ...(message.source.rpcId === undefined ? {} : { rpcId: message.source.rpcId }),
4406
- message: { id: message.id, content: message.content },
4407
- }
4408
- })
4409
- return [...convert(value['next-turn'], 'next-turn'), ...convert(value['next-step'], 'next-step')]
4410
- }
4437
+ const queueItemsFromInbox = inboxQueueItems
4411
4438
 
4412
4439
  const installSessionQueueBaseline = (projections) => {
4413
4440
  if (!projections || typeof projections !== 'object' || Array.isArray(projections)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-weapp-gateway",
3
- "version": "0.8.50",
3
+ "version": "0.8.53",
4
4
  "description": "鲸尾网关助手:DeepSeek Harness 移动客户端连接与会话同步,支持安全配对、远程访问、上下文、编队、额度和语音输入",
5
5
  "main": "lib/index.mjs",
6
6
  "files": [