@clawchatsai/connector 0.0.24 → 0.0.26
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/dist/index.js +34 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -65,8 +65,8 @@ async function ensureNativeModules(ctx) {
|
|
|
65
65
|
// Check if native modules are usable; if not, rebuild them automatically.
|
|
66
66
|
const pluginDir = path.resolve(__dirname, '..');
|
|
67
67
|
const modules = [
|
|
68
|
-
{ name: 'better-sqlite3', binding: 'build/Release/better_sqlite3.node' },
|
|
69
|
-
{ name: 'node-datachannel', binding: 'build/Release/node_datachannel.node' },
|
|
68
|
+
{ name: 'better-sqlite3', binding: 'build/Release/better_sqlite3.node', strategy: 'rebuild' },
|
|
69
|
+
{ name: 'node-datachannel', binding: 'build/Release/node_datachannel.node', strategy: 'install-script' },
|
|
70
70
|
];
|
|
71
71
|
const missing = modules.filter(m => !fs.existsSync(path.join(pluginDir, 'node_modules', m.name, m.binding)));
|
|
72
72
|
if (missing.length === 0)
|
|
@@ -75,11 +75,37 @@ async function ensureNativeModules(ctx) {
|
|
|
75
75
|
const { execFileSync } = await import('node:child_process');
|
|
76
76
|
for (const mod of missing) {
|
|
77
77
|
try {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
78
|
+
if (mod.strategy === 'install-script') {
|
|
79
|
+
// Packages using prebuild-install need their install script re-run (npm rebuild
|
|
80
|
+
// only triggers node-gyp, not prebuild-install). Run the install script directly
|
|
81
|
+
// from the package's directory.
|
|
82
|
+
const modDir = path.join(pluginDir, 'node_modules', mod.name);
|
|
83
|
+
const modPkg = JSON.parse(fs.readFileSync(path.join(modDir, 'package.json'), 'utf-8'));
|
|
84
|
+
const installCmd = modPkg.scripts?.install;
|
|
85
|
+
if (installCmd) {
|
|
86
|
+
execFileSync('sh', ['-c', installCmd], {
|
|
87
|
+
cwd: modDir,
|
|
88
|
+
stdio: 'pipe',
|
|
89
|
+
timeout: 120_000,
|
|
90
|
+
env: { ...process.env, npm_config_node_gyp: '' },
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
// Fallback to rebuild if no install script found
|
|
95
|
+
execFileSync('npm', ['rebuild', mod.name], {
|
|
96
|
+
cwd: pluginDir,
|
|
97
|
+
stdio: 'pipe',
|
|
98
|
+
timeout: 120_000,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
execFileSync('npm', ['rebuild', mod.name], {
|
|
104
|
+
cwd: pluginDir,
|
|
105
|
+
stdio: 'pipe',
|
|
106
|
+
timeout: 120_000,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
83
109
|
ctx.logger.info(`${mod.name} ready.`);
|
|
84
110
|
}
|
|
85
111
|
catch (e) {
|
|
@@ -482,7 +508,7 @@ async function handleRpcMessage(dc, msg, ctx) {
|
|
|
482
508
|
}
|
|
483
509
|
function sendChunked(dc, id, status, body) {
|
|
484
510
|
const data = typeof body === 'string' ? body : JSON.stringify(body);
|
|
485
|
-
const chunkSize =
|
|
511
|
+
const chunkSize = 128 * 1024; // 128KB — safe margin for JSON envelope + escaping overhead
|
|
486
512
|
const totalChunks = Math.ceil(data.length / chunkSize);
|
|
487
513
|
for (let i = 0; i < totalChunks; i++) {
|
|
488
514
|
dc.send(JSON.stringify({
|