dsh-plugin-weapp-gateway 0.8.23 → 0.8.34
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/LICENSE +21 -21
- package/PROTOCOL.md +1545 -1486
- package/README.md +503 -464
- package/THIRD-PARTY-NOTICES/dsh-cost-meter.txt +31 -31
- package/bin/setup-ip.mjs +474 -474
- package/cordis.patch.yml +50 -50
- package/docs/agent-team-app-integration.md +945 -0
- package/docs/blog-mobile-gateway.md +542 -542
- package/docs/dsh-0.1.5-rc.2-compatibility-audit.md +255 -255
- package/docs/dsh-0.1.6-alpha.1-compatibility-audit.md +122 -122
- package/docs/dsh-0.1.7-rc.1-compatibility-audit.md +52 -52
- package/docs/dsh-0.2.0-rc.2-plugin-management-mobile-integration.md +109 -109
- package/docs/dsh-rc2-mobile-integration.md +155 -155
- package/docs/file-upload-app-integration.md +250 -0
- package/docs/multi-gateway-app-integration.md +141 -125
- package/docs/multi-gateway-phase1-acceptance.md +179 -179
- package/docs/multi-gateway-todo.md +137 -137
- package/docs/remote-gateway-refactor-plan.md +52 -52
- package/docs/runtime-architecture.architecture.json +264 -264
- package/docs/runtime-architecture.html +15001 -15001
- package/docs/runtime-architecture.visual-check.html +32 -32
- package/docs/runtime-architecture.visual-check.json +548 -548
- package/docs/session-agent-preset-app-integration.md +93 -93
- package/docs/turn-outline-app-integration.md +196 -0
- package/docs/typert-remote-gateway-feature-checklist.md +294 -294
- package/docs/voice-input-implementation.md +219 -219
- package/docs/workspace-changes-mobile-integration.md +32 -32
- package/helper/dsh_mobile_gateway_helper.py +227 -227
- package/lib/account-bridge.mjs +57 -57
- package/lib/client.js +1409 -1361
- package/lib/cloudflare-tunnel.mjs +314 -314
- package/lib/cloudflared-binary.mjs +135 -135
- package/lib/context-bridge.mjs +3338 -1715
- package/lib/cost-meter-bridge.mjs +794 -794
- package/lib/cost-meter-dashboard-bridge.mjs +1655 -1449
- package/lib/devices.js +273 -245
- package/lib/dsh-host-adapter.mjs +508 -426
- package/lib/file-upload.mjs +205 -0
- package/lib/gateway-probe.mjs +6 -6
- package/lib/gateway-state.mjs +57 -57
- package/lib/gateway-tools.mjs +36 -36
- package/lib/history-cache.mjs +66 -0
- package/lib/index.mjs +4390 -3803
- package/lib/plugin-management.mjs +251 -233
- package/lib/public-endpoint-check.mjs +61 -61
- package/lib/relay-connector.mjs +213 -181
- package/lib/relay-state.mjs +83 -76
- package/lib/session-follower.mjs +140 -136
- package/lib/session-resume-bridge.mjs +86 -0
- package/lib/session-target.mjs +29 -0
- package/lib/speech-input.mjs +192 -192
- package/lib/vendor/cost-meter/aliyun-balance.mjs +123 -123
- package/lib/vendor/cost-meter/coding-plans.mjs +1668 -1668
- package/lib/vendor/cost-meter/credentials-shim.mjs +8 -8
- package/lib/vendor/cost-meter/custom-balance.mjs +281 -281
- package/lib/vendor/cost-meter/factory-quota.mjs +69 -69
- package/lib/vendor/cost-meter/gateway-quota-adapters.mjs +1006 -1006
- package/lib/vendor/cost-meter/gateway-quotas.mjs +664 -664
- package/lib/vendor/cost-meter/home-paths-shim.mjs +13 -13
- package/lib/vendor/cost-meter/net.mjs +183 -183
- package/lib/vendor/cost-meter/opendesign.mjs +204 -204
- package/lib/vendor/cost-meter/tokenrhythm-balance.mjs +95 -95
- package/lib/vendor/cost-meter/workbuddy-accounts.mjs +44 -44
- package/lib/vendor/cost-meter/workbuddy-transport.mjs +38 -38
- package/lib/vendor/cost-meter/workbuddy.mjs +356 -356
- package/lib/web-restart.mjs +47 -47
- package/lib/wire-json.mjs +7 -7
- package/lib/workspace-changes-bridge.mjs +32 -32
- package/package.json +54 -54
- package/relay/agent-connector.js +588 -569
- package/relay/vendor/tweetnacl.js +2391 -2391
|
@@ -1,135 +1,135 @@
|
|
|
1
|
-
import fs from 'node:fs/promises'
|
|
2
|
-
import path from 'node:path'
|
|
3
|
-
import crypto from 'node:crypto'
|
|
4
|
-
import { createReadStream } from 'node:fs'
|
|
5
|
-
import { execFile } from 'node:child_process'
|
|
6
|
-
import { promisify } from 'node:util'
|
|
7
|
-
|
|
8
|
-
const execFileAsync = promisify(execFile)
|
|
9
|
-
const CLOUDFLARED_VERSION = '2026.9.3'
|
|
10
|
-
const MAX_RELEASE_BYTES = 80 * 1024 * 1024
|
|
11
|
-
// GitHub's asset digests for the pinned Cloudflare release. The release API may
|
|
12
|
-
// return 403 even when the public release assets remain available.
|
|
13
|
-
const RELEASE_DIGESTS = Object.freeze({
|
|
14
|
-
'cloudflared-darwin-amd64.tgz': 'd1155d0837487f261183b15c1eab6c4ebcad9dc49b94675f1524c3564cea3977',
|
|
15
|
-
'cloudflared-darwin-arm64.tgz': '587c2cfb1c230fe36c7fa7727da78be459dae028cabe8c001291999350f07095',
|
|
16
|
-
'cloudflared-windows-386.exe': '9b95ddc2eba67b86ed3dc4cc2a15881960563031b52ce564376af41fb91ad402',
|
|
17
|
-
'cloudflared-windows-amd64.exe': 'f096265ec2fcbe9bb6e2d64268db167ced3fcbb83d894bdb9e2fcdb26f2ea7e2',
|
|
18
|
-
})
|
|
19
|
-
const BINARY_DIGESTS = Object.freeze({
|
|
20
|
-
'cloudflared-darwin-amd64.tgz': 'ab588b3b4db9cdb4476c30a3db2a72635b1d8327d44741fee6799a0f37b0ec07',
|
|
21
|
-
'cloudflared-darwin-arm64.tgz': '5472c1a01c84bc31b3021056a73b4e5774ddddefc572124ea8fdf6c340639f32',
|
|
22
|
-
'cloudflared-windows-386.exe': RELEASE_DIGESTS['cloudflared-windows-386.exe'],
|
|
23
|
-
'cloudflared-windows-amd64.exe': RELEASE_DIGESTS['cloudflared-windows-amd64.exe'],
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
export function cloudflaredAsset(platform = process.platform, arch = process.arch) {
|
|
27
|
-
if (platform === 'darwin' && (arch === 'arm64' || arch === 'x64')) {
|
|
28
|
-
return `cloudflared-darwin-${arch === 'x64' ? 'amd64' : 'arm64'}.tgz`
|
|
29
|
-
}
|
|
30
|
-
if (platform === 'win32' && arch === 'x64') return 'cloudflared-windows-amd64.exe'
|
|
31
|
-
if (platform === 'win32' && arch === 'ia32') return 'cloudflared-windows-386.exe'
|
|
32
|
-
throw new Error(`unsupported Cloudflare PC architecture: ${platform}/${arch}`)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Fork extension for Linux servers: Cloudflare ships a GPG-signed distro
|
|
36
|
-
// package (pkg.cloudflare.com/cloudflared) instead of a checksummed bare
|
|
37
|
-
// release asset, so there is nothing for the managed download to fetch. Use
|
|
38
|
-
// whatever the operator installed — an absolute path wins everywhere, and on
|
|
39
|
-
// Linux the bare 'cloudflared' name resolves through PATH.
|
|
40
|
-
async function resolveOnPath(name) {
|
|
41
|
-
try {
|
|
42
|
-
const quoted = `'${String(name).replace(/'/g, `'\\''`)}'`
|
|
43
|
-
const { stdout } = await execFileAsync('sh', ['-c', `command -v ${quoted}`])
|
|
44
|
-
return stdout.trim() || null
|
|
45
|
-
} catch {
|
|
46
|
-
return null
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
async function readBounded(response, limit) {
|
|
51
|
-
if (!response.ok) throw new Error(`Cloudflare binary download returned HTTP ${response.status} from GitHub Releases`)
|
|
52
|
-
const length = Number(response.headers.get('content-length'))
|
|
53
|
-
if (length > limit) throw new Error('Cloudflare binary download exceeds the size limit')
|
|
54
|
-
const chunks = []
|
|
55
|
-
let size = 0
|
|
56
|
-
for await (const chunk of response.body) {
|
|
57
|
-
size += chunk.length
|
|
58
|
-
if (size > limit) throw new Error('Cloudflare binary download exceeds the size limit')
|
|
59
|
-
chunks.push(Buffer.from(chunk))
|
|
60
|
-
}
|
|
61
|
-
return Buffer.concat(chunks, size)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async function regularExecutable(file) {
|
|
65
|
-
try { return (await fs.lstat(file)).isFile() } catch { return false }
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
async function sha256File(file) {
|
|
69
|
-
const hash = crypto.createHash('sha256')
|
|
70
|
-
for await (const chunk of createReadStream(file)) hash.update(chunk)
|
|
71
|
-
return hash.digest('hex')
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// The default executable stays in DSH's private cache. External binaries are
|
|
75
|
-
// used only when an explicit path is configured.
|
|
76
|
-
export async function ensureCloudflared({ cacheDir, executable = 'cloudflared',
|
|
77
|
-
platform = process.platform, arch = process.arch, fetchImpl = fetch,
|
|
78
|
-
releaseDigests = RELEASE_DIGESTS, binaryDigests = BINARY_DIGESTS,
|
|
79
|
-
resolveExecutable = resolveOnPath } = {}) {
|
|
80
|
-
if (executable !== 'cloudflared') return executable
|
|
81
|
-
if (platform === 'linux') {
|
|
82
|
-
const installed = await resolveExecutable(executable)
|
|
83
|
-
if (installed) return installed
|
|
84
|
-
throw new Error('Linux 下未找到 cloudflared:请先安装(pkg.cloudflare.com 的 cloudflared 包),或在插件配置里把 cloudflaredPath 指向可执行文件')
|
|
85
|
-
}
|
|
86
|
-
const assetName = cloudflaredAsset(platform, arch)
|
|
87
|
-
const destination = path.join(cacheDir, `${CLOUDFLARED_VERSION}-${platform}-${arch}${platform === 'win32' ? '.exe' : ''}`)
|
|
88
|
-
await fs.mkdir(cacheDir, { recursive: true, mode: 0o700 })
|
|
89
|
-
await fs.chmod(cacheDir, 0o700)
|
|
90
|
-
const expectedDigest = releaseDigests[assetName]
|
|
91
|
-
const expectedBinaryDigest = binaryDigests[assetName]
|
|
92
|
-
if (!/^[0-9a-f]{64}$/.test(expectedDigest || '') ||
|
|
93
|
-
!/^[0-9a-f]{64}$/.test(expectedBinaryDigest || '')) {
|
|
94
|
-
throw new Error('Cloudflare release has no verifiable binary for this PC')
|
|
95
|
-
}
|
|
96
|
-
if (await regularExecutable(destination)) {
|
|
97
|
-
if (await sha256File(destination) === expectedBinaryDigest) {
|
|
98
|
-
await fs.chmod(destination, 0o700)
|
|
99
|
-
return destination
|
|
100
|
-
}
|
|
101
|
-
await fs.rm(destination)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const expectedUrl = `https://github.com/cloudflare/cloudflared/releases/download/${CLOUDFLARED_VERSION}/${assetName}`
|
|
105
|
-
const response = await fetchImpl(expectedUrl, {
|
|
106
|
-
headers: { 'User-Agent': 'dsh-mobile-gateway' },
|
|
107
|
-
signal: AbortSignal.timeout(120_000),
|
|
108
|
-
})
|
|
109
|
-
const archive = await readBounded(response, MAX_RELEASE_BYTES)
|
|
110
|
-
const actual = crypto.createHash('sha256').update(archive).digest('hex')
|
|
111
|
-
if (actual !== expectedDigest) {
|
|
112
|
-
throw new Error('Cloudflare binary checksum mismatch')
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const stage = await fs.mkdtemp(path.join(cacheDir, '.cloudflared-'))
|
|
116
|
-
try {
|
|
117
|
-
let source
|
|
118
|
-
if (assetName.endsWith('.tgz')) {
|
|
119
|
-
const archiveFile = path.join(stage, assetName)
|
|
120
|
-
await fs.writeFile(archiveFile, archive, { mode: 0o600 })
|
|
121
|
-
await execFileAsync('tar', ['-xzf', archiveFile, '-C', stage], { timeout: 30_000 })
|
|
122
|
-
source = path.join(stage, 'cloudflared')
|
|
123
|
-
if (!await regularExecutable(source)) throw new Error('Cloudflare archive contains no cloudflared executable')
|
|
124
|
-
} else {
|
|
125
|
-
source = path.join(stage, 'cloudflared.exe')
|
|
126
|
-
await fs.writeFile(source, archive, { mode: 0o700 })
|
|
127
|
-
}
|
|
128
|
-
if (await sha256File(source) !== expectedBinaryDigest) throw new Error('Cloudflare executable checksum mismatch')
|
|
129
|
-
await fs.chmod(source, 0o700)
|
|
130
|
-
if (!await regularExecutable(destination)) await fs.rename(source, destination)
|
|
131
|
-
return destination
|
|
132
|
-
} finally {
|
|
133
|
-
await fs.rm(stage, { recursive: true, force: true })
|
|
134
|
-
}
|
|
135
|
-
}
|
|
1
|
+
import fs from 'node:fs/promises'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import crypto from 'node:crypto'
|
|
4
|
+
import { createReadStream } from 'node:fs'
|
|
5
|
+
import { execFile } from 'node:child_process'
|
|
6
|
+
import { promisify } from 'node:util'
|
|
7
|
+
|
|
8
|
+
const execFileAsync = promisify(execFile)
|
|
9
|
+
const CLOUDFLARED_VERSION = '2026.9.3'
|
|
10
|
+
const MAX_RELEASE_BYTES = 80 * 1024 * 1024
|
|
11
|
+
// GitHub's asset digests for the pinned Cloudflare release. The release API may
|
|
12
|
+
// return 403 even when the public release assets remain available.
|
|
13
|
+
const RELEASE_DIGESTS = Object.freeze({
|
|
14
|
+
'cloudflared-darwin-amd64.tgz': 'd1155d0837487f261183b15c1eab6c4ebcad9dc49b94675f1524c3564cea3977',
|
|
15
|
+
'cloudflared-darwin-arm64.tgz': '587c2cfb1c230fe36c7fa7727da78be459dae028cabe8c001291999350f07095',
|
|
16
|
+
'cloudflared-windows-386.exe': '9b95ddc2eba67b86ed3dc4cc2a15881960563031b52ce564376af41fb91ad402',
|
|
17
|
+
'cloudflared-windows-amd64.exe': 'f096265ec2fcbe9bb6e2d64268db167ced3fcbb83d894bdb9e2fcdb26f2ea7e2',
|
|
18
|
+
})
|
|
19
|
+
const BINARY_DIGESTS = Object.freeze({
|
|
20
|
+
'cloudflared-darwin-amd64.tgz': 'ab588b3b4db9cdb4476c30a3db2a72635b1d8327d44741fee6799a0f37b0ec07',
|
|
21
|
+
'cloudflared-darwin-arm64.tgz': '5472c1a01c84bc31b3021056a73b4e5774ddddefc572124ea8fdf6c340639f32',
|
|
22
|
+
'cloudflared-windows-386.exe': RELEASE_DIGESTS['cloudflared-windows-386.exe'],
|
|
23
|
+
'cloudflared-windows-amd64.exe': RELEASE_DIGESTS['cloudflared-windows-amd64.exe'],
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
export function cloudflaredAsset(platform = process.platform, arch = process.arch) {
|
|
27
|
+
if (platform === 'darwin' && (arch === 'arm64' || arch === 'x64')) {
|
|
28
|
+
return `cloudflared-darwin-${arch === 'x64' ? 'amd64' : 'arm64'}.tgz`
|
|
29
|
+
}
|
|
30
|
+
if (platform === 'win32' && arch === 'x64') return 'cloudflared-windows-amd64.exe'
|
|
31
|
+
if (platform === 'win32' && arch === 'ia32') return 'cloudflared-windows-386.exe'
|
|
32
|
+
throw new Error(`unsupported Cloudflare PC architecture: ${platform}/${arch}`)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Fork extension for Linux servers: Cloudflare ships a GPG-signed distro
|
|
36
|
+
// package (pkg.cloudflare.com/cloudflared) instead of a checksummed bare
|
|
37
|
+
// release asset, so there is nothing for the managed download to fetch. Use
|
|
38
|
+
// whatever the operator installed — an absolute path wins everywhere, and on
|
|
39
|
+
// Linux the bare 'cloudflared' name resolves through PATH.
|
|
40
|
+
async function resolveOnPath(name) {
|
|
41
|
+
try {
|
|
42
|
+
const quoted = `'${String(name).replace(/'/g, `'\\''`)}'`
|
|
43
|
+
const { stdout } = await execFileAsync('sh', ['-c', `command -v ${quoted}`])
|
|
44
|
+
return stdout.trim() || null
|
|
45
|
+
} catch {
|
|
46
|
+
return null
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function readBounded(response, limit) {
|
|
51
|
+
if (!response.ok) throw new Error(`Cloudflare binary download returned HTTP ${response.status} from GitHub Releases`)
|
|
52
|
+
const length = Number(response.headers.get('content-length'))
|
|
53
|
+
if (length > limit) throw new Error('Cloudflare binary download exceeds the size limit')
|
|
54
|
+
const chunks = []
|
|
55
|
+
let size = 0
|
|
56
|
+
for await (const chunk of response.body) {
|
|
57
|
+
size += chunk.length
|
|
58
|
+
if (size > limit) throw new Error('Cloudflare binary download exceeds the size limit')
|
|
59
|
+
chunks.push(Buffer.from(chunk))
|
|
60
|
+
}
|
|
61
|
+
return Buffer.concat(chunks, size)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function regularExecutable(file) {
|
|
65
|
+
try { return (await fs.lstat(file)).isFile() } catch { return false }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function sha256File(file) {
|
|
69
|
+
const hash = crypto.createHash('sha256')
|
|
70
|
+
for await (const chunk of createReadStream(file)) hash.update(chunk)
|
|
71
|
+
return hash.digest('hex')
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// The default executable stays in DSH's private cache. External binaries are
|
|
75
|
+
// used only when an explicit path is configured.
|
|
76
|
+
export async function ensureCloudflared({ cacheDir, executable = 'cloudflared',
|
|
77
|
+
platform = process.platform, arch = process.arch, fetchImpl = fetch,
|
|
78
|
+
releaseDigests = RELEASE_DIGESTS, binaryDigests = BINARY_DIGESTS,
|
|
79
|
+
resolveExecutable = resolveOnPath } = {}) {
|
|
80
|
+
if (executable !== 'cloudflared') return executable
|
|
81
|
+
if (platform === 'linux') {
|
|
82
|
+
const installed = await resolveExecutable(executable)
|
|
83
|
+
if (installed) return installed
|
|
84
|
+
throw new Error('Linux 下未找到 cloudflared:请先安装(pkg.cloudflare.com 的 cloudflared 包),或在插件配置里把 cloudflaredPath 指向可执行文件')
|
|
85
|
+
}
|
|
86
|
+
const assetName = cloudflaredAsset(platform, arch)
|
|
87
|
+
const destination = path.join(cacheDir, `${CLOUDFLARED_VERSION}-${platform}-${arch}${platform === 'win32' ? '.exe' : ''}`)
|
|
88
|
+
await fs.mkdir(cacheDir, { recursive: true, mode: 0o700 })
|
|
89
|
+
await fs.chmod(cacheDir, 0o700)
|
|
90
|
+
const expectedDigest = releaseDigests[assetName]
|
|
91
|
+
const expectedBinaryDigest = binaryDigests[assetName]
|
|
92
|
+
if (!/^[0-9a-f]{64}$/.test(expectedDigest || '') ||
|
|
93
|
+
!/^[0-9a-f]{64}$/.test(expectedBinaryDigest || '')) {
|
|
94
|
+
throw new Error('Cloudflare release has no verifiable binary for this PC')
|
|
95
|
+
}
|
|
96
|
+
if (await regularExecutable(destination)) {
|
|
97
|
+
if (await sha256File(destination) === expectedBinaryDigest) {
|
|
98
|
+
await fs.chmod(destination, 0o700)
|
|
99
|
+
return destination
|
|
100
|
+
}
|
|
101
|
+
await fs.rm(destination)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const expectedUrl = `https://github.com/cloudflare/cloudflared/releases/download/${CLOUDFLARED_VERSION}/${assetName}`
|
|
105
|
+
const response = await fetchImpl(expectedUrl, {
|
|
106
|
+
headers: { 'User-Agent': 'dsh-mobile-gateway' },
|
|
107
|
+
signal: AbortSignal.timeout(120_000),
|
|
108
|
+
})
|
|
109
|
+
const archive = await readBounded(response, MAX_RELEASE_BYTES)
|
|
110
|
+
const actual = crypto.createHash('sha256').update(archive).digest('hex')
|
|
111
|
+
if (actual !== expectedDigest) {
|
|
112
|
+
throw new Error('Cloudflare binary checksum mismatch')
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const stage = await fs.mkdtemp(path.join(cacheDir, '.cloudflared-'))
|
|
116
|
+
try {
|
|
117
|
+
let source
|
|
118
|
+
if (assetName.endsWith('.tgz')) {
|
|
119
|
+
const archiveFile = path.join(stage, assetName)
|
|
120
|
+
await fs.writeFile(archiveFile, archive, { mode: 0o600 })
|
|
121
|
+
await execFileAsync('tar', ['-xzf', archiveFile, '-C', stage], { timeout: 30_000 })
|
|
122
|
+
source = path.join(stage, 'cloudflared')
|
|
123
|
+
if (!await regularExecutable(source)) throw new Error('Cloudflare archive contains no cloudflared executable')
|
|
124
|
+
} else {
|
|
125
|
+
source = path.join(stage, 'cloudflared.exe')
|
|
126
|
+
await fs.writeFile(source, archive, { mode: 0o700 })
|
|
127
|
+
}
|
|
128
|
+
if (await sha256File(source) !== expectedBinaryDigest) throw new Error('Cloudflare executable checksum mismatch')
|
|
129
|
+
await fs.chmod(source, 0o700)
|
|
130
|
+
if (!await regularExecutable(destination)) await fs.rename(source, destination)
|
|
131
|
+
return destination
|
|
132
|
+
} finally {
|
|
133
|
+
await fs.rm(stage, { recursive: true, force: true })
|
|
134
|
+
}
|
|
135
|
+
}
|