@shaykec/bridge 0.4.17 → 0.4.18

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shaykec/bridge",
3
- "version": "0.4.17",
3
+ "version": "0.4.18",
4
4
  "type": "module",
5
5
  "description": "Communication hub — HTTP + WebSocket + SSE server with template engine",
6
6
  "main": "src/server.js",
@@ -22,13 +22,20 @@ import {
22
22
 
23
23
  import { execSync } from 'child_process';
24
24
  import { createRequire } from 'module';
25
+ import { dirname, join } from 'path';
26
+ import { fileURLToPath } from 'url';
27
+
28
+ // Resolve the package tree root (parent of node_modules/@shaykec/bridge)
29
+ const __filename = fileURLToPath(import.meta.url);
30
+ const BRIDGE_ROOT = join(dirname(__filename), '..');
31
+ // Walk up: bridge/ -> @shaykec/ -> node_modules/ -> prefix/
32
+ const NPM_PREFIX = join(BRIDGE_ROOT, '..', '..', '..');
25
33
 
26
34
  // Lazy-load the Agent SDK — auto-installs on first use if missing
27
35
  let _sdk = null;
28
36
  let _sdkLoadError = null;
29
37
 
30
38
  function tryRequireSDK() {
31
- // Use createRequire to avoid Node's ESM import cache (which caches failures)
32
39
  const require = createRequire(import.meta.url);
33
40
  return require('@anthropic-ai/claude-agent-sdk');
34
41
  }
@@ -40,13 +47,13 @@ async function getSDK() {
40
47
  _sdk = tryRequireSDK();
41
48
  return _sdk;
42
49
  } catch {
43
- // SDK not installed — try to install it automatically
50
+ // SDK not installed — install it into the same node_modules tree
44
51
  console.log('[chat] Agent SDK not found, installing @anthropic-ai/claude-agent-sdk...');
45
52
  try {
46
- execSync('npm install @anthropic-ai/claude-agent-sdk --registry https://registry.npmjs.org/ --no-save', {
47
- stdio: 'inherit',
48
- timeout: 60000,
49
- });
53
+ execSync(
54
+ `npm install @anthropic-ai/claude-agent-sdk --registry https://registry.npmjs.org/ --prefix "${NPM_PREFIX}" --no-save`,
55
+ { stdio: 'inherit', timeout: 60000 }
56
+ );
50
57
  _sdk = tryRequireSDK();
51
58
  console.log('[chat] Agent SDK installed successfully.');
52
59
  return _sdk;