@yeaft/webchat-agent 0.1.200 → 0.1.201
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/package.json +1 -1
- package/terminal.js +31 -2
package/package.json
CHANGED
package/terminal.js
CHANGED
|
@@ -1,13 +1,42 @@
|
|
|
1
|
-
import { platform } from 'os';
|
|
2
|
-
import { existsSync } from 'fs';
|
|
1
|
+
import { platform, arch } from 'os';
|
|
2
|
+
import { existsSync, chmodSync, statSync } from 'fs';
|
|
3
|
+
import { join, dirname } from 'path';
|
|
4
|
+
import { createRequire } from 'module';
|
|
3
5
|
import ctx from './context.js';
|
|
4
6
|
|
|
7
|
+
// Fix spawn-helper executable permission on Unix systems.
|
|
8
|
+
// npm may strip execute bits from prebuilt binaries, causing
|
|
9
|
+
// "posix_spawnp failed" on macOS/Linux.
|
|
10
|
+
// TODO: Remove this workaround once node-pty ships with correct permissions.
|
|
11
|
+
function fixSpawnHelperPermissions() {
|
|
12
|
+
if (platform() === 'win32') return;
|
|
13
|
+
try {
|
|
14
|
+
const cjsRequire = createRequire(import.meta.url);
|
|
15
|
+
const ptyPkgPath = dirname(cjsRequire.resolve('node-pty/package.json'));
|
|
16
|
+
const targets = [
|
|
17
|
+
join(ptyPkgPath, 'prebuilds', `${platform()}-${arch()}`, 'spawn-helper'),
|
|
18
|
+
join(ptyPkgPath, 'build', 'Release', 'spawn-helper'),
|
|
19
|
+
];
|
|
20
|
+
for (const helper of targets) {
|
|
21
|
+
if (!existsSync(helper)) continue;
|
|
22
|
+
const mode = statSync(helper).mode;
|
|
23
|
+
if (!(mode & 0o111)) {
|
|
24
|
+
chmodSync(helper, 0o755);
|
|
25
|
+
console.log(`[PTY] Fixed spawn-helper permissions: ${helper}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
} catch (e) {
|
|
29
|
+
console.warn('[PTY] Failed to fix spawn-helper permissions:', e.message);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
5
33
|
// 动态加载 node-pty (optionalDependency)
|
|
6
34
|
export async function loadNodePty() {
|
|
7
35
|
if (ctx.nodePty !== null) return ctx.nodePty;
|
|
8
36
|
try {
|
|
9
37
|
let pty = await import('node-pty');
|
|
10
38
|
if (pty.default) pty = pty.default;
|
|
39
|
+
fixSpawnHelperPermissions();
|
|
11
40
|
ctx.nodePty = pty;
|
|
12
41
|
console.log('[PTY] node-pty loaded successfully');
|
|
13
42
|
return pty;
|