recursive-llm-ts 2.0.6 → 2.0.10

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.
@@ -62,6 +62,7 @@ class BunpyBridge {
62
62
  }
63
63
  ensureRLMModule() {
64
64
  return __awaiter(this, void 0, void 0, function* () {
65
+ var _a;
65
66
  if (this.rlmModule)
66
67
  return;
67
68
  // Lazy load bunpy to avoid errors in Node.js environments
@@ -76,29 +77,38 @@ class BunpyBridge {
76
77
  }
77
78
  // Import sys module to add path
78
79
  const sys = this.python.import('sys');
80
+ const pythonExecutable = String(sys.executable || 'python');
81
+ const pythonCmd = pythonExecutable.includes(' ') ? `"${pythonExecutable}"` : pythonExecutable;
79
82
  const pythonPackagePath = path.join(__dirname, '..', 'recursive-llm');
80
83
  const pythonSrcPath = path.join(pythonPackagePath, 'src');
84
+ const pipCmd = `${pythonCmd} -m pip install -e "${pythonPackagePath}"`;
81
85
  sys.path.insert(0, pythonSrcPath);
82
- // Try to import rlm, install deps if needed
86
+ // Try to import rlm, install deps if import fails
83
87
  try {
84
- // First check if litellm is available
85
- try {
86
- this.python.import('litellm');
87
- }
88
- catch (_a) {
89
- // litellm not found, install dependencies
90
- console.log('[recursive-llm-ts] Installing Python dependencies (first time only)...');
91
- const { execSync } = yield Promise.resolve().then(() => __importStar(require('child_process')));
92
- const pipCmd = `pip install -e "${pythonPackagePath}" || pip3 install -e "${pythonPackagePath}"`;
93
- execSync(pipCmd, { stdio: 'inherit' });
94
- console.log('[recursive-llm-ts] ✓ Python dependencies installed');
95
- }
96
88
  this.rlmModule = this.python.import('rlm');
97
89
  }
98
90
  catch (error) {
99
- throw new Error('Failed to import rlm module. Python dependencies may not be installed.\n' +
100
- `Run: pip install -e ${pythonPackagePath}\n` +
101
- `Original error: ${error.message || error}`);
91
+ // If import fails, try installing dependencies
92
+ if ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('No module named')) {
93
+ console.log('[recursive-llm-ts] Installing Python dependencies (first time only)...');
94
+ try {
95
+ const { execSync } = yield Promise.resolve().then(() => __importStar(require('child_process')));
96
+ execSync(pipCmd, { stdio: 'inherit' });
97
+ console.log('[recursive-llm-ts] ✓ Python dependencies installed');
98
+ // Try import again
99
+ this.rlmModule = this.python.import('rlm');
100
+ }
101
+ catch (installError) {
102
+ throw new Error('Failed to import rlm module after installing dependencies.\n' +
103
+ `Manual installation: ${pipCmd}\n` +
104
+ `Error: ${installError.message || installError}`);
105
+ }
106
+ }
107
+ else {
108
+ throw new Error('Failed to import rlm module.\n' +
109
+ `Run: ${pipCmd}\n` +
110
+ `Original error: ${error.message || error}`);
111
+ }
102
112
  }
103
113
  });
104
114
  }
@@ -62,6 +62,7 @@ class PythoniaBridge {
62
62
  }
63
63
  ensureRLMModule() {
64
64
  return __awaiter(this, void 0, void 0, function* () {
65
+ var _a;
65
66
  if (this.rlmModule)
66
67
  return;
67
68
  // Lazy load pythonia to avoid errors in Bun environments
@@ -78,28 +79,37 @@ class PythoniaBridge {
78
79
  const pythonPackagePath = path.join(__dirname, '..', 'recursive-llm');
79
80
  // Import sys module to add path
80
81
  const sys = yield this.python('sys');
82
+ const pythonExecutable = String((yield sys.executable) || 'python');
83
+ const pythonCmd = pythonExecutable.includes(' ') ? `"${pythonExecutable}"` : pythonExecutable;
84
+ const pipCmd = `${pythonCmd} -m pip install -e "${pythonPackagePath}"`;
81
85
  const pathList = yield sys.path;
82
86
  yield pathList.insert(0, path.join(pythonPackagePath, 'src'));
83
- // Try to import rlm, install deps if needed
87
+ // Try to import rlm, install deps if import fails
84
88
  try {
85
- // First check if litellm is available
86
- try {
87
- yield this.python('litellm');
88
- }
89
- catch (_a) {
90
- // litellm not found, install dependencies
91
- console.log('[recursive-llm-ts] Installing Python dependencies (first time only)...');
92
- const { execSync } = yield Promise.resolve().then(() => __importStar(require('child_process')));
93
- const pipCmd = `pip install -e "${pythonPackagePath}" || pip3 install -e "${pythonPackagePath}"`;
94
- execSync(pipCmd, { stdio: 'inherit' });
95
- console.log('[recursive-llm-ts] ✓ Python dependencies installed');
96
- }
97
89
  this.rlmModule = yield this.python('rlm');
98
90
  }
99
91
  catch (error) {
100
- throw new Error('Failed to import rlm module. Python dependencies may not be installed.\n' +
101
- `Run: pip install -e ${pythonPackagePath}\n` +
102
- `Original error: ${error.message || error}`);
92
+ // If import fails, try installing dependencies
93
+ if ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('No module named')) {
94
+ console.log('[recursive-llm-ts] Installing Python dependencies (first time only)...');
95
+ try {
96
+ const { execSync } = yield Promise.resolve().then(() => __importStar(require('child_process')));
97
+ execSync(pipCmd, { stdio: 'inherit' });
98
+ console.log('[recursive-llm-ts] ✓ Python dependencies installed');
99
+ // Try import again
100
+ this.rlmModule = yield this.python('rlm');
101
+ }
102
+ catch (installError) {
103
+ throw new Error('Failed to import rlm module after installing dependencies.\n' +
104
+ `Manual installation: ${pipCmd}\n` +
105
+ `Error: ${installError.message || installError}`);
106
+ }
107
+ }
108
+ else {
109
+ throw new Error('Failed to import rlm module.\n' +
110
+ `Run: ${pipCmd}\n` +
111
+ `Original error: ${error.message || error}`);
112
+ }
103
113
  }
104
114
  });
105
115
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "recursive-llm-ts",
3
- "version": "2.0.6",
3
+ "version": "2.0.10",
4
4
  "description": "TypeScript bridge for recursive-llm: Recursive Language Models for unbounded context processing",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- const { execSync } = require('child_process');
2
+ const { execSync, execFileSync } = require('child_process');
3
3
  const path = require('path');
4
4
  const fs = require('fs');
5
5
 
@@ -16,28 +16,56 @@ if (!fs.existsSync(pyprojectPath)) {
16
16
  console.log('[recursive-llm-ts] Installing Python dependencies...');
17
17
 
18
18
  try {
19
- // Check if pip is available
20
- try {
21
- execSync('pip --version', { stdio: 'pipe' });
22
- } catch {
23
- // Try pip3
24
- execSync('pip3 --version', { stdio: 'pipe' });
19
+ const pythonCandidates = [];
20
+ if (process.env.PYTHON) {
21
+ pythonCandidates.push({ command: process.env.PYTHON, args: [] });
22
+ }
23
+ if (process.platform === 'win32') {
24
+ pythonCandidates.push({ command: 'py', args: ['-3'] });
25
+ pythonCandidates.push({ command: 'python', args: [] });
26
+ pythonCandidates.push({ command: 'python3', args: [] });
27
+ } else {
28
+ pythonCandidates.push({ command: 'python3', args: [] });
29
+ pythonCandidates.push({ command: 'python', args: [] });
30
+ }
31
+
32
+ let pythonCmd = null;
33
+ for (const candidate of pythonCandidates) {
34
+ try {
35
+ execFileSync(candidate.command, [...candidate.args, '--version'], { stdio: 'pipe' });
36
+ pythonCmd = candidate;
37
+ break;
38
+ } catch {
39
+ // Try next candidate
40
+ }
25
41
  }
26
42
 
27
- // Install the Python package in editable mode
28
- const pipCommand = process.platform === 'win32'
29
- ? `pip install -e "${pythonPackagePath}"`
30
- : `pip install -e "${pythonPackagePath}" || pip3 install -e "${pythonPackagePath}"`;
31
-
32
- execSync(pipCommand, {
33
- stdio: 'inherit',
34
- cwd: pythonPackagePath
35
- });
43
+ if (pythonCmd) {
44
+ execFileSync(
45
+ pythonCmd.command,
46
+ [...pythonCmd.args, '-m', 'pip', 'install', '-e', pythonPackagePath],
47
+ { stdio: 'inherit', cwd: pythonPackagePath }
48
+ );
49
+ } else {
50
+ // Fall back to pip/pip3 if a Python executable wasn't found
51
+ try {
52
+ execSync('pip --version', { stdio: 'pipe' });
53
+ } catch {
54
+ execSync('pip3 --version', { stdio: 'pipe' });
55
+ }
56
+ const pipCommand = process.platform === 'win32'
57
+ ? `pip install -e "${pythonPackagePath}"`
58
+ : `pip install -e "${pythonPackagePath}" || pip3 install -e "${pythonPackagePath}"`;
59
+ execSync(pipCommand, {
60
+ stdio: 'inherit',
61
+ cwd: pythonPackagePath
62
+ });
63
+ }
36
64
  console.log('[recursive-llm-ts] ✓ Python dependencies installed successfully');
37
65
  } catch (error) {
38
66
  console.warn('[recursive-llm-ts] Warning: Failed to auto-install Python dependencies');
39
67
  console.warn('[recursive-llm-ts] This is not critical - you can install them manually:');
40
- console.warn(`[recursive-llm-ts] cd node_modules/recursive-llm-ts/recursive-llm && pip install -e .`);
68
+ console.warn(`[recursive-llm-ts] cd node_modules/recursive-llm-ts/recursive-llm && python -m pip install -e .`);
41
69
  console.warn('[recursive-llm-ts] Or ensure Python 3.9+ and pip are in your PATH');
42
70
  // Don't fail the npm install - exit with 0
43
71
  process.exit(0);