@yeaft/webchat-agent 0.1.669 → 0.1.670
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/index.js +2 -15
- package/package.json +3 -6
- package/terminal.js +14 -5
- package/scripts/check-pty.js +0 -87
package/index.js
CHANGED
|
@@ -126,7 +126,8 @@ async function detectCapabilities() {
|
|
|
126
126
|
return capabilities;
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
//
|
|
129
|
+
// 确保依赖已安装。node-pty 已被 @homebridge/node-pty-prebuilt-multiarch
|
|
130
|
+
// 取代(regular dep + 全平台预编译),不再需要 optionalDependency 的特判。
|
|
130
131
|
async function ensureDependencies() {
|
|
131
132
|
const agentDir = new URL('.', import.meta.url).pathname.replace(/^\/([A-Z]:)/, '$1');
|
|
132
133
|
const nodeModulesPath = join(agentDir, 'node_modules');
|
|
@@ -140,20 +141,6 @@ async function ensureDependencies() {
|
|
|
140
141
|
} catch (e) {
|
|
141
142
|
console.warn('[Startup] npm install failed:', e.message);
|
|
142
143
|
}
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// 检查 node-pty 是否可用(optionalDependency,可能需要编译)
|
|
147
|
-
try {
|
|
148
|
-
await import('node-pty');
|
|
149
|
-
} catch (e) {
|
|
150
|
-
console.log('[Startup] node-pty not available, attempting install...');
|
|
151
|
-
try {
|
|
152
|
-
await execAsync('npm install node-pty', { cwd: agentDir, timeout: 120000 });
|
|
153
|
-
console.log('[Startup] node-pty installed successfully');
|
|
154
|
-
} catch (installErr) {
|
|
155
|
-
console.warn('[Startup] node-pty install failed (terminal will be unavailable):', installErr.message);
|
|
156
|
-
}
|
|
157
144
|
}
|
|
158
145
|
}
|
|
159
146
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yeaft/webchat-agent",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.670",
|
|
4
4
|
"description": "Remote agent for Yeaft WebChat — connects worker machines to the central server",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -10,8 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
12
|
"start": "node index.js",
|
|
13
|
-
"dev": "nodemon index.js"
|
|
14
|
-
"postinstall": "node scripts/check-pty.js"
|
|
13
|
+
"dev": "nodemon index.js"
|
|
15
14
|
},
|
|
16
15
|
"engines": {
|
|
17
16
|
"node": ">=22.5.0"
|
|
@@ -55,13 +54,11 @@
|
|
|
55
54
|
"ext": "js"
|
|
56
55
|
},
|
|
57
56
|
"dependencies": {
|
|
57
|
+
"@homebridge/node-pty-prebuilt-multiarch": "^0.13.1",
|
|
58
58
|
"dotenv": "^16.3.1",
|
|
59
59
|
"tweetnacl": "^1.0.3",
|
|
60
60
|
"tweetnacl-util": "^0.15.1",
|
|
61
61
|
"uuid": "^11.1.0",
|
|
62
62
|
"ws": "^8.16.0"
|
|
63
|
-
},
|
|
64
|
-
"optionalDependencies": {
|
|
65
|
-
"node-pty": "^1.0.0"
|
|
66
63
|
}
|
|
67
64
|
}
|
package/terminal.js
CHANGED
|
@@ -4,15 +4,20 @@ import { join, dirname } from 'path';
|
|
|
4
4
|
import { createRequire } from 'module';
|
|
5
5
|
import ctx from './context.js';
|
|
6
6
|
|
|
7
|
+
// Package name of the PTY backend. We use the Homebridge prebuilt fork
|
|
8
|
+
// because upstream node-pty ships no Linux prebuilds and falls back to
|
|
9
|
+
// node-gyp + C++20, which silently fails on older toolchains. The fork
|
|
10
|
+
// ships prebuilds for darwin/linux/win32 across x64/arm64 (incl. musl).
|
|
11
|
+
const PTY_PKG = '@homebridge/node-pty-prebuilt-multiarch';
|
|
12
|
+
|
|
7
13
|
// Ensure spawn-helper has executable permission on Unix systems.
|
|
8
14
|
// npm may strip execute bits from prebuilt binaries, causing
|
|
9
15
|
// "posix_spawnp failed" on macOS/Linux.
|
|
10
|
-
// TODO: Remove this workaround once node-pty ships with correct permissions.
|
|
11
16
|
function ensureSpawnHelperPermissions() {
|
|
12
17
|
if (platform() === 'win32') return;
|
|
13
18
|
try {
|
|
14
19
|
const cjsRequire = createRequire(import.meta.url);
|
|
15
|
-
const ptyPkgPath = dirname(cjsRequire.resolve(
|
|
20
|
+
const ptyPkgPath = dirname(cjsRequire.resolve(`${PTY_PKG}/package.json`));
|
|
16
21
|
const targets = [
|
|
17
22
|
join(ptyPkgPath, 'prebuilds', `${platform()}-${arch()}`, 'spawn-helper'),
|
|
18
23
|
join(ptyPkgPath, 'build', 'Release', 'spawn-helper'),
|
|
@@ -30,11 +35,15 @@ function ensureSpawnHelperPermissions() {
|
|
|
30
35
|
}
|
|
31
36
|
}
|
|
32
37
|
|
|
33
|
-
//
|
|
38
|
+
// Load PTY backend. With the prebuilt fork this is essentially never
|
|
39
|
+
// expected to fail at runtime — it's a regular `dependencies` entry and
|
|
40
|
+
// every supported (platform, abi) combination ships a prebuilt binary.
|
|
41
|
+
// We still catch and degrade so a single missing binary doesn't crash
|
|
42
|
+
// the whole agent on an exotic host.
|
|
34
43
|
export async function loadNodePty() {
|
|
35
44
|
if (ctx.nodePty !== null) return ctx.nodePty;
|
|
36
45
|
try {
|
|
37
|
-
let pty = await import(
|
|
46
|
+
let pty = await import(PTY_PKG);
|
|
38
47
|
if (pty.default) pty = pty.default;
|
|
39
48
|
ensureSpawnHelperPermissions();
|
|
40
49
|
ctx.nodePty = pty;
|
|
@@ -69,7 +78,7 @@ export async function handleTerminalCreate(msg) {
|
|
|
69
78
|
type: 'terminal_error',
|
|
70
79
|
conversationId,
|
|
71
80
|
terminalId,
|
|
72
|
-
message: '
|
|
81
|
+
message: 'Terminal backend is not installed. Run: npm install'
|
|
73
82
|
});
|
|
74
83
|
return;
|
|
75
84
|
}
|
package/scripts/check-pty.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* agent/scripts/check-pty.js — postinstall sanity check for node-pty.
|
|
4
|
-
*
|
|
5
|
-
* Why this exists:
|
|
6
|
-
* `node-pty` is an optionalDependency. npm install swallows install
|
|
7
|
-
* failures silently — when the native module fails to build (e.g.
|
|
8
|
-
* Linux x64, where node-pty's tarball ships no prebuilds and the
|
|
9
|
-
* host g++ is too old to compile C++20), the agent loses its
|
|
10
|
-
* `terminal` capability with zero user-facing signal. The web UI's
|
|
11
|
-
* Terminal tab silently disappears.
|
|
12
|
-
*
|
|
13
|
-
* This postinstall script makes that failure visible: if we're on a
|
|
14
|
-
* platform where node-pty was supposed to install but didn't, print
|
|
15
|
-
* a clear warning with the recovery command. We never fail the
|
|
16
|
-
* install — pty is genuinely optional, and required-feature mode
|
|
17
|
-
* would block users who don't need a Terminal tab.
|
|
18
|
-
*
|
|
19
|
-
* Exit code is always 0 — we only print, never abort.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
import { existsSync } from 'fs';
|
|
23
|
-
import { createRequire } from 'module';
|
|
24
|
-
import { platform } from 'os';
|
|
25
|
-
|
|
26
|
-
const require = createRequire(import.meta.url);
|
|
27
|
-
|
|
28
|
-
function tryResolveNodePty() {
|
|
29
|
-
try {
|
|
30
|
-
return require.resolve('node-pty');
|
|
31
|
-
} catch {
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function tryLoadBinary() {
|
|
37
|
-
// node-pty's lib/index.js does `require('../build/Release/pty.node')`
|
|
38
|
-
// — if the binary is missing or ABI-incompatible, that throws. We
|
|
39
|
-
// mimic the load eagerly so the warning fires at install time, not
|
|
40
|
-
// at agent startup.
|
|
41
|
-
try {
|
|
42
|
-
require('node-pty');
|
|
43
|
-
return { ok: true };
|
|
44
|
-
} catch (e) {
|
|
45
|
-
return { ok: false, error: e.message };
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const resolved = tryResolveNodePty();
|
|
50
|
-
if (!resolved) {
|
|
51
|
-
// node-pty was never installed at all — npm skipped it for the
|
|
52
|
-
// current platform/engine combination.
|
|
53
|
-
const plat = platform();
|
|
54
|
-
if (plat === 'linux' || plat === 'darwin' || plat === 'win32') {
|
|
55
|
-
console.warn('');
|
|
56
|
-
console.warn(' ⚠ node-pty was not installed on this host.');
|
|
57
|
-
console.warn(' The agent will run, but the web UI Terminal tab');
|
|
58
|
-
console.warn(' will be hidden (terminal capability missing).');
|
|
59
|
-
if (plat === 'linux') {
|
|
60
|
-
console.warn('');
|
|
61
|
-
console.warn(' Linux fix: install a C++20-capable compiler');
|
|
62
|
-
console.warn(' (g++-10 or newer) and rebuild:');
|
|
63
|
-
console.warn('');
|
|
64
|
-
console.warn(' sudo apt-get install -y g++-10');
|
|
65
|
-
console.warn(' CXX=g++-10 npm install node-pty --include=optional');
|
|
66
|
-
} else {
|
|
67
|
-
console.warn('');
|
|
68
|
-
console.warn(' Reinstall to retry: npm install node-pty');
|
|
69
|
-
}
|
|
70
|
-
console.warn('');
|
|
71
|
-
}
|
|
72
|
-
process.exit(0);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const loaded = tryLoadBinary();
|
|
76
|
-
if (!loaded.ok) {
|
|
77
|
-
console.warn('');
|
|
78
|
-
console.warn(' ⚠ node-pty resolved but failed to load native binary.');
|
|
79
|
-
console.warn(` Error: ${loaded.error}`);
|
|
80
|
-
console.warn(' The agent will run without Terminal tab support.');
|
|
81
|
-
console.warn(' Recover: npm rebuild node-pty');
|
|
82
|
-
console.warn('');
|
|
83
|
-
process.exit(0);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Silent on success — clean install output.
|
|
87
|
-
process.exit(0);
|