recursive-llm-ts 2.0.0 → 2.0.2

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 @@ function detectRuntime() {
62
62
  */
63
63
  function createBridge() {
64
64
  return __awaiter(this, arguments, void 0, function* (bridgeType = 'auto') {
65
+ var _a;
65
66
  let selectedBridge;
66
67
  if (bridgeType === 'auto') {
67
68
  const runtime = detectRuntime();
@@ -80,12 +81,24 @@ function createBridge() {
80
81
  selectedBridge = bridgeType;
81
82
  }
82
83
  if (selectedBridge === 'bunpy') {
83
- const { BunpyBridge } = yield Promise.resolve().then(() => __importStar(require('./bunpy-bridge')));
84
- return new BunpyBridge();
84
+ try {
85
+ const { BunpyBridge } = yield Promise.resolve().then(() => __importStar(require('./bunpy-bridge')));
86
+ return new BunpyBridge();
87
+ }
88
+ catch (error) {
89
+ if (bridgeType === 'auto' && ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('bunpy is not installed'))) {
90
+ console.warn('[recursive-llm-ts] bunpy not found, falling back to pythonia');
91
+ selectedBridge = 'pythonia';
92
+ }
93
+ else {
94
+ throw error;
95
+ }
96
+ }
85
97
  }
86
- else {
98
+ if (selectedBridge === 'pythonia') {
87
99
  const { PythoniaBridge } = yield Promise.resolve().then(() => __importStar(require('./rlm-bridge')));
88
100
  return new PythoniaBridge();
89
101
  }
102
+ throw new Error('Failed to initialize bridge');
90
103
  });
91
104
  }
@@ -1,6 +1,7 @@
1
1
  import { PythonBridge, RLMConfig, RLMResult } from './bridge-interface';
2
2
  export declare class PythoniaBridge implements PythonBridge {
3
3
  private rlmModule;
4
+ private python;
4
5
  private ensureRLMModule;
5
6
  completion(model: string, query: string, context: string, rlmConfig?: RLMConfig): Promise<RLMResult>;
6
7
  cleanup(): Promise<void>;
@@ -54,24 +54,35 @@ var __rest = (this && this.__rest) || function (s, e) {
54
54
  };
55
55
  Object.defineProperty(exports, "__esModule", { value: true });
56
56
  exports.PythoniaBridge = void 0;
57
- const pythonia_1 = require("pythonia");
58
57
  const path = __importStar(require("path"));
59
58
  class PythoniaBridge {
60
59
  constructor() {
61
60
  this.rlmModule = null;
61
+ this.python = null;
62
62
  }
63
63
  ensureRLMModule() {
64
64
  return __awaiter(this, void 0, void 0, function* () {
65
65
  if (this.rlmModule)
66
66
  return;
67
+ // Lazy load pythonia to avoid errors in Bun environments
68
+ if (!this.python) {
69
+ try {
70
+ const pythonia = yield Promise.resolve().then(() => __importStar(require('pythonia')));
71
+ this.python = pythonia.python;
72
+ }
73
+ catch (error) {
74
+ throw new Error('pythonia is not installed. Install it with: npm install pythonia\n' +
75
+ 'Note: pythonia only works with Node.js runtime, not Bun');
76
+ }
77
+ }
67
78
  // Get path to recursive-llm Python module
68
79
  const rlmPath = path.join(__dirname, '..', 'recursive-llm', 'src', 'rlm');
69
80
  // Import sys module to add path
70
- const sys = yield (0, pythonia_1.python)('sys');
81
+ const sys = yield this.python('sys');
71
82
  const pathList = yield sys.path;
72
83
  yield pathList.insert(0, path.join(__dirname, '..', 'recursive-llm', 'src'));
73
84
  // Import the rlm module
74
- this.rlmModule = yield (0, pythonia_1.python)('rlm');
85
+ this.rlmModule = yield this.python('rlm');
75
86
  });
76
87
  }
77
88
  completion(model_1, query_1, context_1) {
@@ -107,9 +118,10 @@ class PythoniaBridge {
107
118
  }
108
119
  cleanup() {
109
120
  return __awaiter(this, void 0, void 0, function* () {
110
- if (this.rlmModule) {
111
- pythonia_1.python.exit();
121
+ if (this.python && this.rlmModule) {
122
+ this.python.exit();
112
123
  this.rlmModule = null;
124
+ this.python = null;
113
125
  }
114
126
  });
115
127
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "recursive-llm-ts",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
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",
@@ -8,9 +8,7 @@
8
8
  "dist",
9
9
  "recursive-llm/src",
10
10
  "recursive-llm/pyproject.toml",
11
- "scripts/install-python-deps.js",
12
- "scripts/apply-patches.js",
13
- "patches/core.py.patch"
11
+ "scripts/install-python-deps.js"
14
12
  ],
15
13
  "scripts": {
16
14
  "build": "tsc",
@@ -32,23 +30,16 @@
32
30
  "license": "MIT",
33
31
  "repository": {
34
32
  "type": "git",
35
- "url": "https://github.com/yourusername/recursive-llm-ts.git"
33
+ "url": "https://github.com/jbeck018/recursive-llm-ts.git"
36
34
  },
37
35
  "bugs": {
38
- "url": "https://github.com/yourusername/recursive-llm-ts/issues"
36
+ "url": "https://github.com/jbeck018/recursive-llm-ts/issues"
39
37
  },
40
- "homepage": "https://github.com/yourusername/recursive-llm-ts#readme",
38
+ "homepage": "https://github.com/jbeck018/recursive-llm-ts#readme",
41
39
  "dependencies": {
40
+ "bunpy": "^0.1.0",
42
41
  "pythonia": "^1.2.6"
43
42
  },
44
- "peerDependencies": {
45
- "bunpy": "^0.1.0"
46
- },
47
- "peerDependenciesMeta": {
48
- "bunpy": {
49
- "optional": true
50
- }
51
- },
52
43
  "devDependencies": {
53
44
  "@types/node": "^20.11.19",
54
45
  "dotenv": "^16.4.5",
@@ -12,15 +12,8 @@ if (!fs.existsSync(pyprojectPath)) {
12
12
  process.exit(1);
13
13
  }
14
14
 
15
- // Apply patches first
16
- console.log('Applying patches to Python package...');
17
- try {
18
- execSync('node "' + path.join(__dirname, 'apply-patches.js') + '"', { stdio: 'inherit' });
19
- } catch (error) {
20
- console.error('Warning: Failed to apply patches. Continuing with installation...');
21
- }
22
-
23
15
  console.log('Installing Python dependencies for recursive-llm...');
16
+ console.log('Note: Python source is vendored with patches pre-applied.');
24
17
 
25
18
  try {
26
19
  // Install the Python package in editable mode
@@ -1,43 +0,0 @@
1
- diff --git a/src/rlm/core.py b/src/rlm/core.py
2
- index badb248..bcbb9c0 100644
3
- --- a/src/rlm/core.py
4
- +++ b/src/rlm/core.py
5
- @@ -54,14 +54,31 @@ class RLM:
6
- _current_depth: Internal current depth tracker
7
- **llm_kwargs: Additional LiteLLM parameters
8
- """
9
- - self.model = model
10
- - self.recursive_model = recursive_model or model
11
- - self.api_base = api_base
12
- - self.api_key = api_key
13
- - self.max_depth = max_depth
14
- - self.max_iterations = max_iterations
15
- + # Patch for recursive-llm-ts bug where config is passed as 2nd positional arg
16
- + if isinstance(recursive_model, dict):
17
- + config = recursive_model
18
- + # Reset recursive_model default
19
- + self.recursive_model = config.get('recursive_model', model)
20
- + self.api_base = config.get('api_base', api_base)
21
- + self.api_key = config.get('api_key', api_key)
22
- + self.max_depth = int(config.get('max_depth', max_depth))
23
- + self.max_iterations = int(config.get('max_iterations', max_iterations))
24
- +
25
- + # Extract other llm kwargs
26
- + excluded = {'recursive_model', 'api_base', 'api_key', 'max_depth', 'max_iterations'}
27
- + self.llm_kwargs = {k: v for k, v in config.items() if k not in excluded}
28
- + # Merge with any actual kwargs passed
29
- + self.llm_kwargs.update(llm_kwargs)
30
- + else:
31
- + self.recursive_model = recursive_model or model
32
- + self.api_base = api_base
33
- + self.api_key = api_key
34
- + self.max_depth = max_depth
35
- + self.max_iterations = max_iterations
36
- + self.llm_kwargs = llm_kwargs
37
- +
38
- self._current_depth = _current_depth
39
- - self.llm_kwargs = llm_kwargs
40
- + self.model = model
41
-
42
- self.repl = REPLExecutor()
43
-
@@ -1,88 +0,0 @@
1
- #!/usr/bin/env node
2
- const { execSync } = require('child_process');
3
- const path = require('path');
4
- const fs = require('fs');
5
-
6
- const corePyPath = path.join(__dirname, '..', 'recursive-llm', 'src', 'rlm', 'core.py');
7
- const patchPath = path.join(__dirname, '..', 'patches', 'core.py.patch');
8
-
9
- // Check if core.py exists
10
- if (!fs.existsSync(corePyPath)) {
11
- console.error('Error: core.py not found at', corePyPath);
12
- process.exit(1);
13
- }
14
-
15
- // Check if patch exists
16
- if (!fs.existsSync(patchPath)) {
17
- console.error('Error: patch file not found at', patchPath);
18
- process.exit(1);
19
- }
20
-
21
- console.log('Applying patches to recursive-llm Python package...');
22
-
23
- // Check if patch is already applied by looking for the patch marker
24
- const coreContent = fs.readFileSync(corePyPath, 'utf8');
25
- if (coreContent.includes('# Patch for recursive-llm-ts bug where config is passed as 2nd positional arg')) {
26
- console.log('✓ Patch already applied to core.py');
27
- process.exit(0);
28
- }
29
-
30
- // Apply the patch
31
- const pythonPackagePath = path.join(__dirname, '..', 'recursive-llm');
32
-
33
- try {
34
- // Try to apply patch
35
- execSync(`patch -p1 -i "${patchPath}"`, {
36
- cwd: pythonPackagePath,
37
- stdio: 'inherit'
38
- });
39
- console.log('✓ Successfully applied core.py patch');
40
- } catch (error) {
41
- console.error('Failed to apply patch using patch command.');
42
- console.error('Attempting manual patch application...');
43
-
44
- // Fallback: manually apply the patch by replacing the constructor
45
- try {
46
- const updatedContent = coreContent.replace(
47
- /(\s+)self\.model = model\n(\s+)self\.recursive_model = recursive_model or model\n(\s+)self\.api_base = api_base\n(\s+)self\.api_key = api_key\n(\s+)self\.max_depth = max_depth\n(\s+)self\.max_iterations = max_iterations\n(\s+)self\._current_depth = _current_depth\n(\s+)self\.llm_kwargs = llm_kwargs/,
48
- `$1# Patch for recursive-llm-ts bug where config is passed as 2nd positional arg
49
- $1if isinstance(recursive_model, dict):
50
- $1 config = recursive_model
51
- $1 # Reset recursive_model default
52
- $1 self.recursive_model = config.get('recursive_model', model)
53
- $1 self.api_base = config.get('api_base', api_base)
54
- $1 self.api_key = config.get('api_key', api_key)
55
- $1 self.max_depth = int(config.get('max_depth', max_depth))
56
- $1 self.max_iterations = int(config.get('max_iterations', max_iterations))
57
- $1
58
- $1 # Extract other llm kwargs
59
- $1 excluded = {'recursive_model', 'api_base', 'api_key', 'max_depth', 'max_iterations'}
60
- $1 self.llm_kwargs = {k: v for k, v in config.items() if k not in excluded}
61
- $1 # Merge with any actual kwargs passed
62
- $1 self.llm_kwargs.update(llm_kwargs)
63
- $1else:
64
- $1 self.recursive_model = recursive_model or model
65
- $1 self.api_base = api_base
66
- $1 self.api_key = api_key
67
- $1 self.max_depth = max_depth
68
- $1 self.max_iterations = max_iterations
69
- $1 self.llm_kwargs = llm_kwargs
70
-
71
- $1self._current_depth = _current_depth
72
- $1self.model = model`
73
- );
74
-
75
- if (updatedContent === coreContent) {
76
- console.error('Manual patch failed: pattern not found in core.py');
77
- console.error('The file may have been updated upstream.');
78
- console.error('Please manually apply the patch from patches/core.py.patch');
79
- process.exit(1);
80
- }
81
-
82
- fs.writeFileSync(corePyPath, updatedContent, 'utf8');
83
- console.log('✓ Successfully applied patch manually');
84
- } catch (manualError) {
85
- console.error('Manual patch application failed:', manualError.message);
86
- process.exit(1);
87
- }
88
- }