recursive-llm-ts 2.0.10 → 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 +43 -5
- 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;
|
|
@@ -77,11 +78,48 @@ class BunpyBridge {
|
|
|
77
78
|
}
|
|
78
79
|
// Import sys module to add path
|
|
79
80
|
const sys = this.python.import('sys');
|
|
80
|
-
const pythonExecutable =
|
|
81
|
+
const pythonExecutable = (() => {
|
|
82
|
+
try {
|
|
83
|
+
const sysExecutable = sys.executable;
|
|
84
|
+
if (sysExecutable && typeof sysExecutable.valueOf === 'function') {
|
|
85
|
+
const value = sysExecutable.valueOf();
|
|
86
|
+
if (typeof value === 'string' && value.trim()) {
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (typeof sysExecutable === 'string' && sysExecutable.trim()) {
|
|
91
|
+
return sysExecutable;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch (_a) {
|
|
95
|
+
// Fall back if bunpy can't coerce sys.executable
|
|
96
|
+
}
|
|
97
|
+
return 'python';
|
|
98
|
+
})();
|
|
81
99
|
const pythonCmd = pythonExecutable.includes(' ') ? `"${pythonExecutable}"` : pythonExecutable;
|
|
82
100
|
const pythonPackagePath = path.join(__dirname, '..', 'recursive-llm');
|
|
83
101
|
const pythonSrcPath = path.join(pythonPackagePath, 'src');
|
|
102
|
+
const pythonDepsPath = path.join(pythonPackagePath, '.pydeps');
|
|
84
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);
|
|
85
123
|
sys.path.insert(0, pythonSrcPath);
|
|
86
124
|
// Try to import rlm, install deps if import fails
|
|
87
125
|
try {
|
|
@@ -90,23 +128,23 @@ class BunpyBridge {
|
|
|
90
128
|
catch (error) {
|
|
91
129
|
// If import fails, try installing dependencies
|
|
92
130
|
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)...');
|
|
131
|
+
console.log('[recursive-llm-ts] Installing Python dependencies locally (first time only)...');
|
|
94
132
|
try {
|
|
95
133
|
const { execSync } = yield Promise.resolve().then(() => __importStar(require('child_process')));
|
|
96
|
-
execSync(
|
|
134
|
+
execSync(installCmd, { stdio: 'inherit' });
|
|
97
135
|
console.log('[recursive-llm-ts] ✓ Python dependencies installed');
|
|
98
136
|
// Try import again
|
|
99
137
|
this.rlmModule = this.python.import('rlm');
|
|
100
138
|
}
|
|
101
139
|
catch (installError) {
|
|
102
140
|
throw new Error('Failed to import rlm module after installing dependencies.\n' +
|
|
103
|
-
`Manual installation: ${
|
|
141
|
+
`Manual installation: ${installCmd}\n` +
|
|
104
142
|
`Error: ${installError.message || installError}`);
|
|
105
143
|
}
|
|
106
144
|
}
|
|
107
145
|
else {
|
|
108
146
|
throw new Error('Failed to import rlm module.\n' +
|
|
109
|
-
`Run: ${
|
|
147
|
+
`Run: ${installCmd}\n` +
|
|
110
148
|
`Original error: ${error.message || error}`);
|
|
111
149
|
}
|
|
112
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);
|