dsh-plugin-weapp-gateway 0.8.53 → 0.8.55

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 (46) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/PROTOCOL.md +26 -12
  3. package/README.en.md +410 -0
  4. package/README.md +16 -0
  5. package/README.zh-CN.md +425 -0
  6. package/cordis.patch.yml +2 -0
  7. package/docs/agent-team-app-integration.md +76 -55
  8. package/docs/android-connectors-alignment.md +73 -0
  9. package/docs/dsh-0.2.2-rc.1-mobile-integration.md +269 -0
  10. package/docs/dsh-0.2.2-rc.3-compatibility-audit.md +145 -0
  11. package/docs/file-cards-mobile-integration.md +111 -0
  12. package/docs/file-changes-app-integration.md +277 -0
  13. package/docs/generated-images-mobile-integration.md +125 -0
  14. package/docs/iphone-connector-actions.md +69 -0
  15. package/docs/iphone-map-markers.md +41 -0
  16. package/docs/iphone-maps-connectors.md +56 -0
  17. package/docs/iphone-music-cards.md +28 -0
  18. package/docs/map-app-adapters.md +57 -0
  19. package/docs/phone-connectors-implementation.md +105 -0
  20. package/docs/phone-connectors.md +91 -0
  21. package/docs/readme/README.de.md +404 -0
  22. package/docs/readme/README.es.md +404 -0
  23. package/docs/readme/README.fr.md +404 -0
  24. package/docs/readme/README.ja.md +404 -0
  25. package/docs/readme/README.ko.md +404 -0
  26. package/docs/readme/README.pt-BR.md +404 -0
  27. package/lib/client.js +82 -27
  28. package/lib/cloudflare-tunnel.mjs +6 -2
  29. package/lib/cloudflared-binary.mjs +10 -24
  30. package/lib/device-tool-validation.mjs +173 -0
  31. package/lib/device-tools.mjs +119 -0
  32. package/lib/devices.js +29 -7
  33. package/lib/dsh-host-adapter.mjs +169 -36
  34. package/lib/dsh-runtime-version.mjs +22 -0
  35. package/lib/index.mjs +253 -102
  36. package/lib/logging.mjs +16 -0
  37. package/lib/message-text.mjs +51 -0
  38. package/lib/phone-request-sources.mjs +91 -0
  39. package/lib/phone-tools.mjs +248 -0
  40. package/lib/plugin-management.mjs +24 -0
  41. package/lib/schedule-management.mjs +130 -0
  42. package/lib/session-target.mjs +16 -0
  43. package/lib/tool-images.mjs +32 -0
  44. package/lib/web-restart.mjs +11 -8
  45. package/lib/workspace-changes.mjs +162 -0
  46. package/package.json +8 -3
@@ -0,0 +1,32 @@
1
+ // 工具图片只传递持久附件引用,字节继续由 Host 的会话附件接口读取。
2
+ const IMAGE_TYPES = new Set(['image/png', 'image/jpeg', 'image/webp', 'image/gif'])
3
+
4
+ export function toolImages(data, type = 'tool/result') {
5
+ const images = new Map()
6
+ const add = attachment => {
7
+ if (!attachment || typeof attachment.attachmentId !== 'string' || !attachment.attachmentId.trim()
8
+ || !IMAGE_TYPES.has(attachment.mediaType)
9
+ || !['bytes', 'width', 'height'].every(key => Number.isSafeInteger(attachment[key]) && attachment[key] > 0)) return
10
+ const ref = {}
11
+ for (const key of ['attachmentId', 'mediaType', 'bytes', 'width', 'height']) ref[key] = attachment[key]
12
+ if (typeof attachment.name === 'string') ref.name = attachment.name
13
+ images.set(ref.attachmentId, ref)
14
+ }
15
+ const visit = blocks => {
16
+ if (!Array.isArray(blocks)) return
17
+ for (const block of blocks) {
18
+ if (block?.type === 'image') add(block.attachment)
19
+ else if (block?.type === 'tool-result' && block.isError !== true) visit(block.content)
20
+ }
21
+ }
22
+ // 失败结果不当作成功生图;成功批次仍可包含单项失败的文字。
23
+ if (data.isError === true || data.message?.isError === true || data.error) return []
24
+ visit(type === 'tool/result' ? data.message?.content : data.content)
25
+ // dsh-image-gen 的普通调用还会持久化 presentation meta;兼容仅保留 meta 的结果。
26
+ const meta = data.meta
27
+ const candidates = meta?.kind === 'dsh-image-gen-batch' && Array.isArray(meta.images) ? meta.images : [meta]
28
+ for (const candidate of candidates) {
29
+ if (candidate?.kind === 'dsh-image-gen') add(candidate.attachment)
30
+ }
31
+ return [...images.values()]
32
+ }
@@ -1,11 +1,9 @@
1
1
  // Detached handoff process: only launched by the loopback-only management API.
2
2
  import { spawn } from 'node:child_process'
3
- import { openSync, closeSync, appendFileSync } from 'node:fs'
3
+ import { openSync, closeSync } from 'node:fs'
4
+ import { LOG_FILE, log } from './logging.mjs'
4
5
 
5
- const logFile = '/tmp/mobile-gateway.log'
6
- const note = (message) => {
7
- try { appendFileSync(logFile, `[${new Date().toISOString()}] web restart: ${message}\n`) } catch {}
8
- }
6
+ const note = (message) => log(`web restart: ${message}`)
9
7
 
10
8
  try {
11
9
  const spec = JSON.parse(Buffer.from(process.argv[2] || '', 'base64url').toString())
@@ -27,10 +25,15 @@ try {
27
25
  } catch (error) {
28
26
  if (error.code !== 'ESRCH') throw error
29
27
  }
30
- const fd = openSync(logFile, 'a')
28
+ let fd
29
+ try {
30
+ fd = openSync(LOG_FILE, 'a')
31
+ } catch (error) {
32
+ note(`cannot redirect child logs to ${LOG_FILE}: ${error?.message || String(error)}`)
33
+ }
31
34
  try {
32
35
  const child = spawn(spec.execPath, [...spec.execArgv, ...spec.argv], {
33
- cwd: spec.cwd, env: process.env, detached: true, stdio: ['ignore', fd, fd],
36
+ cwd: spec.cwd, env: process.env, detached: true, stdio: ['ignore', fd ?? 'inherit', fd ?? 'inherit'],
34
37
  })
35
38
  await new Promise((resolve, reject) => {
36
39
  child.once('spawn', resolve)
@@ -39,7 +42,7 @@ try {
39
42
  child.unref()
40
43
  note(`started DSH Web pid=${child.pid}`)
41
44
  } finally {
42
- closeSync(fd)
45
+ if (fd !== undefined) closeSync(fd)
43
46
  }
44
47
  } catch (error) {
45
48
  note(error?.message || String(error))
@@ -0,0 +1,162 @@
1
+ import { stringifyWireFrame } from './wire-json.mjs'
2
+
3
+ export const WORKSPACE_CHANGES_REQUEST_TYPES = new Set(['workspace-changes-summary', 'workspace-changes-diff'])
4
+ const SUMMARY_LIMIT = 1024 * 1024
5
+ const DIFF_LIMIT = 4 * 1024 * 1024
6
+ const routes = { summary: '/api/changes.summary', diff: '/api/changes.diff' }
7
+ const record = value => value !== null && typeof value === 'object' && !Array.isArray(value)
8
+ const integer = value => Number.isSafeInteger(value) && value >= 0
9
+ const nonempty = value => typeof value === 'string' && value.trim().length > 0
10
+ const failure = (code, message) => Object.assign(new Error(message), { code })
11
+ const tooLarge = () => failure('workspace-changes-response-too-large', 'Change response exceeds the byte budget')
12
+
13
+ function abortable(task, signal) {
14
+ signal.throwIfAborted()
15
+ return new Promise((resolve, reject) => {
16
+ const abort = () => reject(signal.reason)
17
+ signal.addEventListener('abort', abort, { once: true })
18
+ Promise.resolve(task).then(resolve, reject).finally(() => signal.removeEventListener('abort', abort))
19
+ })
20
+ }
21
+
22
+ async function readJson(response, limit, signal) {
23
+ const reader = response.body?.getReader()
24
+ if (!reader) throw new Error('Missing change response body')
25
+ const chunks = []
26
+ let bytes = 0
27
+ try {
28
+ if (Number(response.headers.get('content-length')) > limit) throw tooLarge()
29
+ while (true) {
30
+ const { done, value } = await abortable(reader.read(), signal)
31
+ if (done) break
32
+ bytes += value.byteLength
33
+ if (bytes > limit) throw tooLarge()
34
+ chunks.push(Buffer.from(value))
35
+ }
36
+ return JSON.parse(Buffer.concat(chunks, bytes).toString('utf8'))
37
+ } finally {
38
+ await reader.cancel().catch(() => {})
39
+ reader.releaseLock()
40
+ }
41
+ }
42
+
43
+ function changedFile(value) {
44
+ if (!record(value) || typeof value.path !== 'string' || typeof value.display !== 'string'
45
+ || !integer(value.added) || !integer(value.deleted)
46
+ || (value.binary !== undefined && value.binary !== true)
47
+ || (value.oversized !== undefined && value.oversized !== true)) throw new Error('Invalid changed file')
48
+ const { path, display, added, deleted, binary, oversized } = value
49
+ return { path, display, added, deleted, ...(binary ? { binary } : {}), ...(oversized ? { oversized } : {}) }
50
+ }
51
+
52
+ function summaryValue(value) {
53
+ if (!record(value) || !integer(value.turn) || value.turn < 1 || !Array.isArray(value.files)
54
+ || !integer(value.total) || value.total < value.files.length || !integer(value.added) || !integer(value.deleted)) {
55
+ throw new Error('Invalid change summary')
56
+ }
57
+ return { turn: value.turn, total: value.total, added: value.added, deleted: value.deleted,
58
+ files: value.files.map(changedFile) }
59
+ }
60
+
61
+ function diffValue(value) {
62
+ if (!record(value) || typeof value.path !== 'string' || typeof value.display !== 'string') throw new Error('Invalid change comparison')
63
+ const { kind, path, display } = value
64
+ if (kind === 'binary' || kind === 'oversized') return { kind, path, display }
65
+ if (kind !== 'text' || typeof value.before !== 'boolean' || typeof value.after !== 'boolean'
66
+ || typeof value.coarse !== 'boolean' || !Array.isArray(value.hunks)) throw new Error('Invalid text comparison')
67
+ const hunks = value.hunks.map(hunk => {
68
+ if (!record(hunk) || !integer(hunk.oldStart) || hunk.oldStart < 1 || !integer(hunk.oldLines)
69
+ || !integer(hunk.newStart) || hunk.newStart < 1 || !integer(hunk.newLines) || !Array.isArray(hunk.lines)) {
70
+ throw new Error('Invalid diff hunk')
71
+ }
72
+ let oldLines = 0, newLines = 0
73
+ for (const line of hunk.lines) {
74
+ if (typeof line !== 'string' || ![' ', '+', '-'].includes(line[0])) throw new Error('Invalid diff line')
75
+ if (line[0] !== '+') oldLines++
76
+ if (line[0] !== '-') newLines++
77
+ }
78
+ if (oldLines !== hunk.oldLines || newLines !== hunk.newLines) throw new Error('Invalid diff line counts')
79
+ return { oldStart: hunk.oldStart, oldLines, newStart: hunk.newStart, newLines, lines: hunk.lines }
80
+ })
81
+ return { kind, path, display, before: value.before, after: value.after, coarse: value.coarse, hunks }
82
+ }
83
+
84
+ function coordinates(payload, diff) {
85
+ if (!nonempty(payload.sessionId) || payload.sessionId.length > 2048 || !integer(payload.seq)
86
+ || (diff && !integer(payload.index)) || payload.childSessionId !== undefined) {
87
+ throw failure('bad-request', 'Changes require sessionId, a non-negative seq, and for diff a non-negative index; subagents are unsupported')
88
+ }
89
+ }
90
+
91
+ // Only fixed official Fetch routes cross the Host boundary. Buffered mode alone
92
+ // cannot detect a registered GET route: Connection also returns it for 404s.
93
+ export function createWorkspaceChangesAdapter(handler, peer) {
94
+ let available = false
95
+ let probing
96
+ const fetchResponse = async (url, signal) => {
97
+ signal.throwIfAborted()
98
+ const task = Promise.resolve().then(() => handler.fetch(new Request(url, { signal }), peer))
99
+ task.then(response => { if (signal.aborted) void response.body?.cancel().catch(() => {}) }, () => {})
100
+ return abortable(task, signal)
101
+ }
102
+ return {
103
+ available: () => available && !peer.signal.aborted,
104
+ refresh() {
105
+ if (!handler?.fetch || peer.signal.aborted) return Promise.resolve(false)
106
+ if (probing) return probing
107
+ const signal = AbortSignal.any([peer.signal, AbortSignal.timeout(2000)])
108
+ probing = Promise.all(Object.values(routes).map(async route => {
109
+ // Both official routes validate coordinates before touching a Session.
110
+ const response = await fetchResponse(new URL(route, 'http://localhost'), signal)
111
+ await response.body?.cancel()
112
+ return response.status === 400
113
+ })).then(results => { available = results.every(Boolean); return available }, () => { available = false; return false })
114
+ .finally(() => { probing = undefined })
115
+ return probing
116
+ },
117
+ async read(method, payload, callerSignal) {
118
+ coordinates(payload, method === 'diff')
119
+ if (!Object.hasOwn(routes, method)) throw failure('bad-request', 'Invalid change query')
120
+ if (!handler?.fetch) throw failure('workspace-changes-unavailable', 'Host change routes are unavailable')
121
+ const signal = AbortSignal.any([peer.signal, AbortSignal.timeout(30_000), ...(callerSignal ? [callerSignal] : [])])
122
+ signal.throwIfAborted()
123
+ if (!available && !await abortable(this.refresh(), signal)) {
124
+ throw failure('workspace-changes-unavailable', 'Host change routes are unavailable')
125
+ }
126
+ const url = new URL(routes[method], 'http://localhost')
127
+ url.searchParams.set('sessionId', payload.sessionId)
128
+ url.searchParams.set('seq', payload.seq)
129
+ if (method === 'diff') url.searchParams.set('index', payload.index)
130
+ const response = await fetchResponse(url, signal)
131
+ if (!response.ok) {
132
+ await response.body?.cancel()
133
+ const code = response.status === 404 ? 'workspace-changes-missing'
134
+ : response.status === 401 || response.status === 403 ? 'authentication-required' : 'workspace-changes-failed'
135
+ throw failure(code, `Host change query returned HTTP ${response.status}`)
136
+ }
137
+ const value = await readJson(response, method === 'diff' ? DIFF_LIMIT : SUMMARY_LIMIT, signal)
138
+ return method === 'diff' ? diffValue(value) : summaryValue(value)
139
+ },
140
+ }
141
+ }
142
+
143
+ export async function handleWorkspaceChangesQuery(api, msg, signal) {
144
+ const identity = Object.fromEntries(['requestId', 'sessionId', 'seq', 'index']
145
+ .filter(key => ['string', 'number'].includes(typeof msg[key])).map(key => [key, msg[key]]))
146
+ try {
147
+ const diff = msg.type === 'workspace-changes-diff'
148
+ if (!WORKSPACE_CHANGES_REQUEST_TYPES.has(msg.type) || !nonempty(msg.requestId) || msg.requestId.length > 128) {
149
+ throw failure('bad-request', 'A non-empty requestId of at most 128 characters is required')
150
+ }
151
+ coordinates(msg, diff)
152
+ if (!api.workspaceChanges) throw failure('workspace-changes-unavailable', 'Host change routes are unavailable')
153
+ const value = await api.workspaceChanges.read(diff ? 'diff' : 'summary', msg, signal)
154
+ const frame = { kind: msg.type, requestId: msg.requestId, sessionId: msg.sessionId, seq: msg.seq,
155
+ ...(diff ? { index: msg.index, diff: value } : { summary: value }) }
156
+ if (Buffer.byteLength(stringifyWireFrame(frame)) > (diff ? DIFF_LIMIT : SUMMARY_LIMIT)) throw tooLarge()
157
+ return frame
158
+ } catch (error) {
159
+ return { kind: 'error', ...identity, requestType: msg.type, code: error.code && typeof error.code === 'string'
160
+ ? error.code : 'workspace-changes-failed', message: error.message || 'Change query failed' }
161
+ }
162
+ }
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "dsh-plugin-weapp-gateway",
3
- "version": "0.8.53",
3
+ "version": "0.8.55",
4
4
  "description": "鲸尾网关助手:DeepSeek Harness 移动客户端连接与会话同步,支持安全配对、远程访问、上下文、编队、额度和语音输入",
5
5
  "main": "lib/index.mjs",
6
6
  "files": [
7
+ "CHANGELOG.md",
7
8
  "bin",
8
9
  "helper",
9
10
  "lib",
@@ -29,13 +30,16 @@
29
30
  },
30
31
  "bin": "bin/setup-ip.mjs",
31
32
  "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 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
+ "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
+ "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"
33
36
  },
34
37
  "exports": {
35
38
  ".": "./lib/index.mjs",
36
39
  "./client": "./lib/client.js",
37
40
  "./locale/*.json": "./locale/*.json",
38
- "./package.json": "./package.json"
41
+ "./package.json": "./package.json",
42
+ "./phone-tools": "./lib/phone-tools.mjs"
39
43
  },
40
44
  "dsh": {
41
45
  "bundle": {
@@ -45,6 +49,7 @@
45
49
  "platform": "web",
46
50
  "inject": [
47
51
  "@deepseek-ai/dsh-client-runtime",
52
+ "@deepseek-ai/dsh-client-locale",
48
53
  "@deepseek-ai/dsh-client-ui-layout",
49
54
  "@deepseek-ai/dsh-client-ui-sidebar"
50
55
  ]