@shaykec/bridge 0.4.16 → 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 +1 -1
- package/src/claude-session.js +21 -7
package/package.json
CHANGED
package/src/claude-session.js
CHANGED
|
@@ -21,26 +21,40 @@ import {
|
|
|
21
21
|
} from '@shaykec/shared';
|
|
22
22
|
|
|
23
23
|
import { execSync } from 'child_process';
|
|
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, '..', '..', '..');
|
|
24
33
|
|
|
25
34
|
// Lazy-load the Agent SDK — auto-installs on first use if missing
|
|
26
35
|
let _sdk = null;
|
|
27
36
|
let _sdkLoadError = null;
|
|
28
37
|
|
|
38
|
+
function tryRequireSDK() {
|
|
39
|
+
const require = createRequire(import.meta.url);
|
|
40
|
+
return require('@anthropic-ai/claude-agent-sdk');
|
|
41
|
+
}
|
|
42
|
+
|
|
29
43
|
async function getSDK() {
|
|
30
44
|
if (_sdk) return _sdk;
|
|
31
45
|
if (_sdkLoadError) throw _sdkLoadError;
|
|
32
46
|
try {
|
|
33
|
-
_sdk =
|
|
47
|
+
_sdk = tryRequireSDK();
|
|
34
48
|
return _sdk;
|
|
35
49
|
} catch {
|
|
36
|
-
// SDK not installed —
|
|
50
|
+
// SDK not installed — install it into the same node_modules tree
|
|
37
51
|
console.log('[chat] Agent SDK not found, installing @anthropic-ai/claude-agent-sdk...');
|
|
38
52
|
try {
|
|
39
|
-
execSync(
|
|
40
|
-
|
|
41
|
-
timeout: 60000
|
|
42
|
-
|
|
43
|
-
_sdk =
|
|
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
|
+
);
|
|
57
|
+
_sdk = tryRequireSDK();
|
|
44
58
|
console.log('[chat] Agent SDK installed successfully.');
|
|
45
59
|
return _sdk;
|
|
46
60
|
} catch (installErr) {
|