@clawchatsai/connector 0.0.25 → 0.0.27

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 (2) hide show
  1. package/dist/index.js +35 -9
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -13,7 +13,6 @@ import * as fs from 'node:fs';
13
13
  import * as http from 'node:http';
14
14
  import * as path from 'node:path';
15
15
  import { SignalingClient } from './signaling-client.js';
16
- import { WebRTCPeerManager } from './webrtc-peer.js';
17
16
  import { dispatchRpc } from './shim.js';
18
17
  import { checkForUpdates, performUpdate } from './updater.js';
19
18
  import { initAuth, handleAuthMessage, cleanupAuth } from './auth-handler.js';
@@ -65,8 +64,8 @@ async function ensureNativeModules(ctx) {
65
64
  // Check if native modules are usable; if not, rebuild them automatically.
66
65
  const pluginDir = path.resolve(__dirname, '..');
67
66
  const modules = [
68
- { name: 'better-sqlite3', binding: 'build/Release/better_sqlite3.node' },
69
- { name: 'node-datachannel', binding: 'build/Release/node_datachannel.node' },
67
+ { name: 'better-sqlite3', binding: 'build/Release/better_sqlite3.node', strategy: 'rebuild' },
68
+ { name: 'node-datachannel', binding: 'build/Release/node_datachannel.node', strategy: 'install-script' },
70
69
  ];
71
70
  const missing = modules.filter(m => !fs.existsSync(path.join(pluginDir, 'node_modules', m.name, m.binding)));
72
71
  if (missing.length === 0)
@@ -75,11 +74,37 @@ async function ensureNativeModules(ctx) {
75
74
  const { execFileSync } = await import('node:child_process');
76
75
  for (const mod of missing) {
77
76
  try {
78
- execFileSync('npm', ['rebuild', mod.name], {
79
- cwd: pluginDir,
80
- stdio: 'pipe',
81
- timeout: 120_000,
82
- });
77
+ if (mod.strategy === 'install-script') {
78
+ // Packages using prebuild-install need their install script re-run (npm rebuild
79
+ // only triggers node-gyp, not prebuild-install). Run the install script directly
80
+ // from the package's directory.
81
+ const modDir = path.join(pluginDir, 'node_modules', mod.name);
82
+ const modPkg = JSON.parse(fs.readFileSync(path.join(modDir, 'package.json'), 'utf-8'));
83
+ const installCmd = modPkg.scripts?.install;
84
+ if (installCmd) {
85
+ execFileSync('sh', ['-c', installCmd], {
86
+ cwd: modDir,
87
+ stdio: 'pipe',
88
+ timeout: 120_000,
89
+ env: { ...process.env, npm_config_node_gyp: '' },
90
+ });
91
+ }
92
+ else {
93
+ // Fallback to rebuild if no install script found
94
+ execFileSync('npm', ['rebuild', mod.name], {
95
+ cwd: pluginDir,
96
+ stdio: 'pipe',
97
+ timeout: 120_000,
98
+ });
99
+ }
100
+ }
101
+ else {
102
+ execFileSync('npm', ['rebuild', mod.name], {
103
+ cwd: pluginDir,
104
+ stdio: 'pipe',
105
+ timeout: 120_000,
106
+ });
107
+ }
83
108
  ctx.logger.info(`${mod.name} ready.`);
84
109
  }
85
110
  catch (e) {
@@ -178,7 +203,8 @@ async function startClawChats(ctx, api) {
178
203
  ctx.logger.error(`Account suspended: ${reason}`);
179
204
  broadcastToClients({ type: 'account-suspended', reason });
180
205
  });
181
- // 6. Initialize WebRTC peer manager
206
+ // 6. Initialize WebRTC peer manager (lazy import — native module must be built first)
207
+ const { WebRTCPeerManager } = await import('./webrtc-peer.js');
182
208
  webrtcPeer = new WebRTCPeerManager();
183
209
  webrtcPeer.on('datachannel', (dc, connectionId) => {
184
210
  ctx.logger.info(`Browser connected via DataChannel: ${connectionId}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clawchatsai/connector",
3
- "version": "0.0.25",
3
+ "version": "0.0.27",
4
4
  "type": "module",
5
5
  "description": "ClawChats OpenClaw plugin — P2P tunnel + local API bridge",
6
6
  "main": "dist/index.js",