recursive-llm-ts 2.0.5 → 2.0.7

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
@@ -79,14 +80,33 @@ class BunpyBridge {
79
80
  const pythonPackagePath = path.join(__dirname, '..', 'recursive-llm');
80
81
  const pythonSrcPath = path.join(pythonPackagePath, 'src');
81
82
  sys.path.insert(0, pythonSrcPath);
82
- // Import the rlm module
83
+ // Try to import rlm, install deps if import fails
83
84
  try {
84
85
  this.rlmModule = this.python.import('rlm');
85
86
  }
86
87
  catch (error) {
87
- throw new Error('Failed to import rlm module. Python dependencies may not be installed.\n' +
88
- `Run: pip install -e ${pythonPackagePath}\n` +
89
- `Original error: ${error.message || error}`);
88
+ // If import fails, try installing dependencies
89
+ if ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('No module named')) {
90
+ console.log('[recursive-llm-ts] Installing Python dependencies (first time only)...');
91
+ try {
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
+ // Try import again
97
+ this.rlmModule = this.python.import('rlm');
98
+ }
99
+ catch (installError) {
100
+ throw new Error('Failed to import rlm module after installing dependencies.\n' +
101
+ `Manual installation: pip install -e ${pythonPackagePath}\n` +
102
+ `Error: ${installError.message || installError}`);
103
+ }
104
+ }
105
+ else {
106
+ throw new Error('Failed to import rlm module.\n' +
107
+ `Run: pip install -e ${pythonPackagePath}\n` +
108
+ `Original error: ${error.message || error}`);
109
+ }
90
110
  }
91
111
  });
92
112
  }
@@ -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
@@ -75,14 +76,39 @@ class PythoniaBridge {
75
76
  'Note: pythonia only works with Node.js runtime, not Bun');
76
77
  }
77
78
  }
78
- // Get path to recursive-llm Python module
79
- const rlmPath = path.join(__dirname, '..', 'recursive-llm', 'src', 'rlm');
79
+ const pythonPackagePath = path.join(__dirname, '..', 'recursive-llm');
80
80
  // Import sys module to add path
81
81
  const sys = yield this.python('sys');
82
82
  const pathList = yield sys.path;
83
- yield pathList.insert(0, path.join(__dirname, '..', 'recursive-llm', 'src'));
84
- // Import the rlm module
85
- this.rlmModule = yield this.python('rlm');
83
+ yield pathList.insert(0, path.join(pythonPackagePath, 'src'));
84
+ // Try to import rlm, install deps if import fails
85
+ try {
86
+ this.rlmModule = yield this.python('rlm');
87
+ }
88
+ catch (error) {
89
+ // If import fails, try installing dependencies
90
+ if ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('No module named')) {
91
+ console.log('[recursive-llm-ts] Installing Python dependencies (first time only)...');
92
+ try {
93
+ const { execSync } = yield Promise.resolve().then(() => __importStar(require('child_process')));
94
+ const pipCmd = `pip install -e "${pythonPackagePath}" || pip3 install -e "${pythonPackagePath}"`;
95
+ execSync(pipCmd, { stdio: 'inherit' });
96
+ console.log('[recursive-llm-ts] ✓ Python dependencies installed');
97
+ // Try import again
98
+ this.rlmModule = yield this.python('rlm');
99
+ }
100
+ catch (installError) {
101
+ throw new Error('Failed to import rlm module after installing dependencies.\n' +
102
+ `Manual installation: pip install -e ${pythonPackagePath}\n` +
103
+ `Error: ${installError.message || installError}`);
104
+ }
105
+ }
106
+ else {
107
+ throw new Error('Failed to import rlm module.\n' +
108
+ `Run: pip install -e ${pythonPackagePath}\n` +
109
+ `Original error: ${error.message || error}`);
110
+ }
111
+ }
86
112
  });
87
113
  }
88
114
  completion(model_1, query_1, context_1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "recursive-llm-ts",
3
- "version": "2.0.5",
3
+ "version": "2.0.7",
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",