recursive-llm-ts 2.0.11 → 2.0.12
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/dist/bunpy-bridge.js +25 -4
- package/dist/rlm-bridge.js +25 -4
- package/package.json +1 -1
- package/scripts/install-python-deps.js +35 -6
package/dist/bunpy-bridge.js
CHANGED
|
@@ -55,6 +55,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
55
55
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
56
56
|
exports.BunpyBridge = void 0;
|
|
57
57
|
const path = __importStar(require("path"));
|
|
58
|
+
const fs = __importStar(require("fs"));
|
|
58
59
|
class BunpyBridge {
|
|
59
60
|
constructor() {
|
|
60
61
|
this.rlmModule = null;
|
|
@@ -98,7 +99,27 @@ class BunpyBridge {
|
|
|
98
99
|
const pythonCmd = pythonExecutable.includes(' ') ? `"${pythonExecutable}"` : pythonExecutable;
|
|
99
100
|
const pythonPackagePath = path.join(__dirname, '..', 'recursive-llm');
|
|
100
101
|
const pythonSrcPath = path.join(pythonPackagePath, 'src');
|
|
102
|
+
const pythonDepsPath = path.join(pythonPackagePath, '.pydeps');
|
|
101
103
|
const pipCmd = `${pythonCmd} -m pip install -e "${pythonPackagePath}"`;
|
|
104
|
+
const pyprojectPath = path.join(pythonPackagePath, 'pyproject.toml');
|
|
105
|
+
const dependencySpecifiers = (() => {
|
|
106
|
+
try {
|
|
107
|
+
const pyproject = fs.readFileSync(pyprojectPath, 'utf8');
|
|
108
|
+
const depsBlock = pyproject.match(/dependencies\s*=\s*\[[\s\S]*?\]/);
|
|
109
|
+
if (!depsBlock)
|
|
110
|
+
return [];
|
|
111
|
+
return Array.from(depsBlock[0].matchAll(/"([^"]+)"/g), (match) => match[1]);
|
|
112
|
+
}
|
|
113
|
+
catch (_a) {
|
|
114
|
+
return [];
|
|
115
|
+
}
|
|
116
|
+
})();
|
|
117
|
+
const depsInstallCmd = dependencySpecifiers.length > 0
|
|
118
|
+
? `${pythonCmd} -m pip install --upgrade --target "${pythonDepsPath}" ${dependencySpecifiers.map((dep) => `"${dep}"`).join(' ')}`
|
|
119
|
+
: '';
|
|
120
|
+
const installCmd = depsInstallCmd || pipCmd;
|
|
121
|
+
fs.mkdirSync(pythonDepsPath, { recursive: true });
|
|
122
|
+
sys.path.insert(0, pythonDepsPath);
|
|
102
123
|
sys.path.insert(0, pythonSrcPath);
|
|
103
124
|
// Try to import rlm, install deps if import fails
|
|
104
125
|
try {
|
|
@@ -107,23 +128,23 @@ class BunpyBridge {
|
|
|
107
128
|
catch (error) {
|
|
108
129
|
// If import fails, try installing dependencies
|
|
109
130
|
if ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('No module named')) {
|
|
110
|
-
console.log('[recursive-llm-ts] Installing Python dependencies (first time only)...');
|
|
131
|
+
console.log('[recursive-llm-ts] Installing Python dependencies locally (first time only)...');
|
|
111
132
|
try {
|
|
112
133
|
const { execSync } = yield Promise.resolve().then(() => __importStar(require('child_process')));
|
|
113
|
-
execSync(
|
|
134
|
+
execSync(installCmd, { stdio: 'inherit' });
|
|
114
135
|
console.log('[recursive-llm-ts] ✓ Python dependencies installed');
|
|
115
136
|
// Try import again
|
|
116
137
|
this.rlmModule = this.python.import('rlm');
|
|
117
138
|
}
|
|
118
139
|
catch (installError) {
|
|
119
140
|
throw new Error('Failed to import rlm module after installing dependencies.\n' +
|
|
120
|
-
`Manual installation: ${
|
|
141
|
+
`Manual installation: ${installCmd}\n` +
|
|
121
142
|
`Error: ${installError.message || installError}`);
|
|
122
143
|
}
|
|
123
144
|
}
|
|
124
145
|
else {
|
|
125
146
|
throw new Error('Failed to import rlm module.\n' +
|
|
126
|
-
`Run: ${
|
|
147
|
+
`Run: ${installCmd}\n` +
|
|
127
148
|
`Original error: ${error.message || error}`);
|
|
128
149
|
}
|
|
129
150
|
}
|
package/dist/rlm-bridge.js
CHANGED
|
@@ -55,6 +55,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
55
55
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
56
56
|
exports.PythoniaBridge = void 0;
|
|
57
57
|
const path = __importStar(require("path"));
|
|
58
|
+
const fs = __importStar(require("fs"));
|
|
58
59
|
class PythoniaBridge {
|
|
59
60
|
constructor() {
|
|
60
61
|
this.rlmModule = null;
|
|
@@ -82,7 +83,27 @@ class PythoniaBridge {
|
|
|
82
83
|
const pythonExecutable = String((yield sys.executable) || 'python');
|
|
83
84
|
const pythonCmd = pythonExecutable.includes(' ') ? `"${pythonExecutable}"` : pythonExecutable;
|
|
84
85
|
const pipCmd = `${pythonCmd} -m pip install -e "${pythonPackagePath}"`;
|
|
86
|
+
const pythonDepsPath = path.join(pythonPackagePath, '.pydeps');
|
|
87
|
+
const pyprojectPath = path.join(pythonPackagePath, 'pyproject.toml');
|
|
88
|
+
const dependencySpecifiers = (() => {
|
|
89
|
+
try {
|
|
90
|
+
const pyproject = fs.readFileSync(pyprojectPath, 'utf8');
|
|
91
|
+
const depsBlock = pyproject.match(/dependencies\s*=\s*\[[\s\S]*?\]/);
|
|
92
|
+
if (!depsBlock)
|
|
93
|
+
return [];
|
|
94
|
+
return Array.from(depsBlock[0].matchAll(/"([^"]+)"/g), (match) => match[1]);
|
|
95
|
+
}
|
|
96
|
+
catch (_a) {
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
})();
|
|
100
|
+
const depsInstallCmd = dependencySpecifiers.length > 0
|
|
101
|
+
? `${pythonCmd} -m pip install --upgrade --target "${pythonDepsPath}" ${dependencySpecifiers.map((dep) => `"${dep}"`).join(' ')}`
|
|
102
|
+
: '';
|
|
103
|
+
const installCmd = depsInstallCmd || pipCmd;
|
|
85
104
|
const pathList = yield sys.path;
|
|
105
|
+
fs.mkdirSync(pythonDepsPath, { recursive: true });
|
|
106
|
+
yield pathList.insert(0, pythonDepsPath);
|
|
86
107
|
yield pathList.insert(0, path.join(pythonPackagePath, 'src'));
|
|
87
108
|
// Try to import rlm, install deps if import fails
|
|
88
109
|
try {
|
|
@@ -91,23 +112,23 @@ class PythoniaBridge {
|
|
|
91
112
|
catch (error) {
|
|
92
113
|
// If import fails, try installing dependencies
|
|
93
114
|
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)...');
|
|
115
|
+
console.log('[recursive-llm-ts] Installing Python dependencies locally (first time only)...');
|
|
95
116
|
try {
|
|
96
117
|
const { execSync } = yield Promise.resolve().then(() => __importStar(require('child_process')));
|
|
97
|
-
execSync(
|
|
118
|
+
execSync(installCmd, { stdio: 'inherit' });
|
|
98
119
|
console.log('[recursive-llm-ts] ✓ Python dependencies installed');
|
|
99
120
|
// Try import again
|
|
100
121
|
this.rlmModule = yield this.python('rlm');
|
|
101
122
|
}
|
|
102
123
|
catch (installError) {
|
|
103
124
|
throw new Error('Failed to import rlm module after installing dependencies.\n' +
|
|
104
|
-
`Manual installation: ${
|
|
125
|
+
`Manual installation: ${installCmd}\n` +
|
|
105
126
|
`Error: ${installError.message || installError}`);
|
|
106
127
|
}
|
|
107
128
|
}
|
|
108
129
|
else {
|
|
109
130
|
throw new Error('Failed to import rlm module.\n' +
|
|
110
|
-
`Run: ${
|
|
131
|
+
`Run: ${installCmd}\n` +
|
|
111
132
|
`Original error: ${error.message || error}`);
|
|
112
133
|
}
|
|
113
134
|
}
|
package/package.json
CHANGED
|
@@ -5,6 +5,7 @@ const fs = require('fs');
|
|
|
5
5
|
|
|
6
6
|
const pythonPackagePath = path.join(__dirname, '..', 'recursive-llm');
|
|
7
7
|
const pyprojectPath = path.join(pythonPackagePath, 'pyproject.toml');
|
|
8
|
+
const pythonDepsPath = path.join(pythonPackagePath, '.pydeps');
|
|
8
9
|
|
|
9
10
|
// Check if pyproject.toml exists
|
|
10
11
|
if (!fs.existsSync(pyprojectPath)) {
|
|
@@ -13,9 +14,26 @@ if (!fs.existsSync(pyprojectPath)) {
|
|
|
13
14
|
process.exit(0); // Don't fail the install
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
console.log('[recursive-llm-ts] Installing Python dependencies...');
|
|
17
|
+
console.log('[recursive-llm-ts] Installing Python dependencies locally...');
|
|
18
|
+
|
|
19
|
+
const dependencySpecifiers = (() => {
|
|
20
|
+
try {
|
|
21
|
+
const pyproject = fs.readFileSync(pyprojectPath, 'utf8');
|
|
22
|
+
const depsBlock = pyproject.match(/dependencies\s*=\s*\[[\s\S]*?\]/);
|
|
23
|
+
if (!depsBlock) return [];
|
|
24
|
+
return Array.from(depsBlock[0].matchAll(/"([^"]+)"/g), (match) => match[1]);
|
|
25
|
+
} catch {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
})();
|
|
29
|
+
|
|
30
|
+
const installArgs = dependencySpecifiers.length > 0
|
|
31
|
+
? ['-m', 'pip', 'install', '--upgrade', '--target', pythonDepsPath, ...dependencySpecifiers]
|
|
32
|
+
: ['-m', 'pip', 'install', '-e', pythonPackagePath];
|
|
33
|
+
const dependencyArgs = dependencySpecifiers.map((dep) => `"${dep}"`).join(' ');
|
|
17
34
|
|
|
18
35
|
try {
|
|
36
|
+
|
|
19
37
|
const pythonCandidates = [];
|
|
20
38
|
if (process.env.PYTHON) {
|
|
21
39
|
pythonCandidates.push({ command: process.env.PYTHON, args: [] });
|
|
@@ -41,9 +59,10 @@ try {
|
|
|
41
59
|
}
|
|
42
60
|
|
|
43
61
|
if (pythonCmd) {
|
|
62
|
+
fs.mkdirSync(pythonDepsPath, { recursive: true });
|
|
44
63
|
execFileSync(
|
|
45
64
|
pythonCmd.command,
|
|
46
|
-
[...pythonCmd.args,
|
|
65
|
+
[...pythonCmd.args, ...installArgs],
|
|
47
66
|
{ stdio: 'inherit', cwd: pythonPackagePath }
|
|
48
67
|
);
|
|
49
68
|
} else {
|
|
@@ -53,9 +72,12 @@ try {
|
|
|
53
72
|
} catch {
|
|
54
73
|
execSync('pip3 --version', { stdio: 'pipe' });
|
|
55
74
|
}
|
|
56
|
-
const pipCommand =
|
|
57
|
-
? `pip install
|
|
58
|
-
:
|
|
75
|
+
const pipCommand = dependencySpecifiers.length > 0
|
|
76
|
+
? `pip install --upgrade --target "${pythonDepsPath}" ${dependencySpecifiers.map((dep) => `"${dep}"`).join(' ')}`
|
|
77
|
+
: process.platform === 'win32'
|
|
78
|
+
? `pip install -e "${pythonPackagePath}"`
|
|
79
|
+
: `pip install -e "${pythonPackagePath}" || pip3 install -e "${pythonPackagePath}"`;
|
|
80
|
+
fs.mkdirSync(pythonDepsPath, { recursive: true });
|
|
59
81
|
execSync(pipCommand, {
|
|
60
82
|
stdio: 'inherit',
|
|
61
83
|
cwd: pythonPackagePath
|
|
@@ -65,7 +87,14 @@ try {
|
|
|
65
87
|
} catch (error) {
|
|
66
88
|
console.warn('[recursive-llm-ts] Warning: Failed to auto-install Python dependencies');
|
|
67
89
|
console.warn('[recursive-llm-ts] This is not critical - you can install them manually:');
|
|
68
|
-
|
|
90
|
+
if (dependencySpecifiers.length > 0) {
|
|
91
|
+
console.warn(
|
|
92
|
+
`[recursive-llm-ts] cd node_modules/recursive-llm-ts/recursive-llm && ` +
|
|
93
|
+
`python -m pip install --upgrade --target .pydeps ${dependencyArgs}`
|
|
94
|
+
);
|
|
95
|
+
} else {
|
|
96
|
+
console.warn(`[recursive-llm-ts] cd node_modules/recursive-llm-ts/recursive-llm && python -m pip install -e .`);
|
|
97
|
+
}
|
|
69
98
|
console.warn('[recursive-llm-ts] Or ensure Python 3.9+ and pip are in your PATH');
|
|
70
99
|
// Don't fail the npm install - exit with 0
|
|
71
100
|
process.exit(0);
|