dsh-plugin-weapp-gateway 0.8.38 → 0.8.47
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 +40 -10
- package/README.md +61 -12
- package/docs/multi-gateway-app-integration.md +2 -2
- package/lib/client.js +323 -32
- package/lib/index.mjs +227 -46
- package/lib/network-diagnostics.mjs +126 -0
- package/lib/session-event-details.mjs +59 -0
- package/lib/tailscale-addresses.mjs +37 -0
- package/lib/ui-state.mjs +36 -0
- package/package.json +2 -2
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// 移动端事件详情:在裁剪 token 级回放与工具正文后保留诊断事实。
|
|
2
|
+
// 取自上游 mobile-gateway(v0.11.2)的 session-event-details,字段全部为增量:
|
|
3
|
+
// - assistant/message、assistant/attempt: finish(结束原因与失败摘要)
|
|
4
|
+
// - tool/result: output/outputTruncated(16KB 摘要,保留首尾)
|
|
5
|
+
// - llm/retry: failure 摘要
|
|
6
|
+
// - turn/end: reasonDetails(本仓库仍保留原有的 reason 对象形态,mini-program 兼容)
|
|
7
|
+
|
|
8
|
+
const TOOL_OUTPUT_LIMIT = 16_000
|
|
9
|
+
|
|
10
|
+
export function failureDetails(value) {
|
|
11
|
+
if (!value || typeof value !== 'object') return undefined
|
|
12
|
+
const result = {}
|
|
13
|
+
for (const key of ['message', 'code', 'name', 'reason', 'requestId']) {
|
|
14
|
+
if (typeof value[key] === 'string') result[key] = value[key]
|
|
15
|
+
}
|
|
16
|
+
for (const key of ['status', 'providerRetryAfterMs']) {
|
|
17
|
+
if (Number.isFinite(value[key])) result[key] = value[key]
|
|
18
|
+
}
|
|
19
|
+
return Object.keys(result).length ? result : undefined
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function assistantFinish(data) {
|
|
23
|
+
for (let i = (data.stream?.length || 0) - 1; i >= 0; i--) {
|
|
24
|
+
const record = data.stream[i]
|
|
25
|
+
if (record?.type !== 'chunk' || record.chunk?.type !== 'finish') continue
|
|
26
|
+
const reason = record.chunk.reason
|
|
27
|
+
if (typeof reason?.kind !== 'string') return undefined
|
|
28
|
+
const failure = failureDetails(reason.failure ?? reason.error)
|
|
29
|
+
return { kind: reason.kind, ...(failure ? { failure } : {}) }
|
|
30
|
+
}
|
|
31
|
+
return data.finish
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function toolResultDetails(data) {
|
|
35
|
+
const texts = []
|
|
36
|
+
const visit = (block) => {
|
|
37
|
+
if (block?.type === 'text' && typeof block.text === 'string') texts.push(block.text)
|
|
38
|
+
else if (block?.type === 'tool-result' && Array.isArray(block.content)) block.content.forEach(visit)
|
|
39
|
+
}
|
|
40
|
+
for (const block of data.message?.content || []) visit(block)
|
|
41
|
+
const full = texts.join('')
|
|
42
|
+
const outputTruncated = full.length > TOOL_OUTPUT_LIMIT
|
|
43
|
+
// Retain the terminal status and sandbox hints at the end as well as the start.
|
|
44
|
+
const output = outputTruncated
|
|
45
|
+
? `${full.slice(0, TOOL_OUTPUT_LIMIT / 2)}\n[…]\n${full.slice(-TOOL_OUTPUT_LIMIT / 2)}`
|
|
46
|
+
: full
|
|
47
|
+
return { output, outputTruncated }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function turnReasonDetails(reason) {
|
|
51
|
+
if (!reason || typeof reason.kind !== 'string') return undefined
|
|
52
|
+
const error = failureDetails(reason.error ?? reason.failure)
|
|
53
|
+
return { kind: reason.kind, ...(error ? { error } : {}),
|
|
54
|
+
...(typeof reason.reason?.kind === 'string' ? { reason: {
|
|
55
|
+
kind: reason.reason.kind,
|
|
56
|
+
...(typeof reason.reason.reason === 'string' ? { reason: reason.reason.reason } : {}),
|
|
57
|
+
} } : {}),
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Tailscale 地址识别:100.64.0.0/10(CGNAT,Tailscale 使用其中 100.64–100.127)
|
|
2
|
+
// 与 fd7a:115c:a1e0::/48(Tailscale IPv6)。
|
|
3
|
+
//
|
|
4
|
+
// 只检查本网关进程所在网络命名空间的接口,绝不推断手机 IP;检测到接口地址
|
|
5
|
+
// 也不等于已登录 tailnet 或手机可达。取自上游 mobile-gateway(v0.11.2)。
|
|
6
|
+
import os from 'node:os'
|
|
7
|
+
import { isIP } from 'node:net'
|
|
8
|
+
|
|
9
|
+
export function isTailscaleIp(value) {
|
|
10
|
+
if (typeof value !== 'string') return false
|
|
11
|
+
const address = value.replace(/^\[|\]$/g, '').toLowerCase()
|
|
12
|
+
if (isIP(address) === 4) {
|
|
13
|
+
const parts = address.split('.').map(Number)
|
|
14
|
+
return parts[0] === 100 && parts[1] >= 64 && parts[1] <= 127
|
|
15
|
+
}
|
|
16
|
+
return isIP(address) === 6 && address.startsWith('fd7a:115c:a1e0:')
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 只读取本机接口;返回 Tailscale 地址列表与可用(已监听且绑定地址匹配)的 WS URL。
|
|
20
|
+
export function tailscaleInterfaceStatus({ listening, host, port, wsPath }, interfaces = os.networkInterfaces()) {
|
|
21
|
+
const addresses = []
|
|
22
|
+
for (const [name, records] of Object.entries(interfaces)) {
|
|
23
|
+
const entries = (records || []).filter((record) => record && !record.internal)
|
|
24
|
+
const knownInterface = /^(tailscale|utun|tun\d)/i.test(name)
|
|
25
|
+
|| entries.some((record) => isIP(record.address) === 6 && isTailscaleIp(record.address))
|
|
26
|
+
if (!knownInterface) continue
|
|
27
|
+
for (const record of entries) {
|
|
28
|
+
if (isTailscaleIp(record.address) && !addresses.includes(record.address)) addresses.push(record.address)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
addresses.sort((a, b) => isIP(a) - isIP(b))
|
|
32
|
+
const boundHost = (host || '').replace(/^\[|\]$/g, '')
|
|
33
|
+
const urls = listening ? addresses.filter((address) =>
|
|
34
|
+
boundHost === '::' || boundHost === address || (boundHost === '0.0.0.0' && isIP(address) === 4))
|
|
35
|
+
.map((address) => `ws://${isIP(address) === 6 ? `[${address}]` : address}:${port}${wsPath}`) : []
|
|
36
|
+
return { addresses, urls }
|
|
37
|
+
}
|
package/lib/ui-state.mjs
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// 面板 UI 偏好:与网关身份/模式分开存储。该文件损坏时回退默认值,
|
|
2
|
+
// 不让插件启动失败(身份文件损坏才会 fail closed)。
|
|
3
|
+
import fs from 'node:fs'
|
|
4
|
+
import path from 'node:path'
|
|
5
|
+
import crypto from 'node:crypto'
|
|
6
|
+
|
|
7
|
+
const DEFAULTS = { version: 1, sidebarEntry: true }
|
|
8
|
+
|
|
9
|
+
export function createUiState(file) {
|
|
10
|
+
let state = { ...DEFAULTS }
|
|
11
|
+
try {
|
|
12
|
+
const parsed = JSON.parse(fs.readFileSync(file, 'utf8'))
|
|
13
|
+
if (parsed && parsed.version === 1 && typeof parsed.sidebarEntry === 'boolean') {
|
|
14
|
+
state = { version: 1, sidebarEntry: parsed.sidebarEntry }
|
|
15
|
+
}
|
|
16
|
+
} catch { /* 首次运行或文件损坏:使用默认值 */ }
|
|
17
|
+
const write = (value) => {
|
|
18
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 })
|
|
19
|
+
const tmp = `${file}.${process.pid}.${crypto.randomUUID()}.tmp`
|
|
20
|
+
try {
|
|
21
|
+
fs.writeFileSync(tmp, `${JSON.stringify(value)}\n`, { mode: 0o600, flag: 'wx' })
|
|
22
|
+
fs.renameSync(tmp, file)
|
|
23
|
+
} finally {
|
|
24
|
+
fs.rmSync(tmp, { force: true })
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
get sidebarEntry() { return state.sidebarEntry },
|
|
29
|
+
setSidebarEntry(value) {
|
|
30
|
+
if (typeof value !== 'boolean') throw new TypeError('sidebarEntry must be a boolean')
|
|
31
|
+
const next = { version: 1, sidebarEntry: value }
|
|
32
|
+
write(next)
|
|
33
|
+
state = next
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-weapp-gateway",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.47",
|
|
4
4
|
"description": "鲸尾网关助手:DeepSeek Harness 移动客户端连接与会话同步,支持安全配对、远程访问、上下文、编队、额度和语音输入",
|
|
5
5
|
"main": "lib/index.mjs",
|
|
6
6
|
"files": [
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"bin": "bin/setup-ip.mjs",
|
|
31
31
|
"scripts": {
|
|
32
|
-
"test": "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/speech-official.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/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/cloudflare-linux.test.mjs && node test/multi-gateway.test.mjs"
|
|
32
|
+
"test": "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/speech-official.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/cloudflare-linux.test.mjs && node test/multi-gateway.test.mjs"
|
|
33
33
|
},
|
|
34
34
|
"exports": {
|
|
35
35
|
".": "./lib/index.mjs",
|