recursive-llm-ts 1.0.4 → 1.0.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "recursive-llm-ts",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
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,7 +8,9 @@
8
8
  "dist",
9
9
  "recursive-llm/src",
10
10
  "recursive-llm/pyproject.toml",
11
- "scripts/install-python-deps.js"
11
+ "scripts/install-python-deps.js",
12
+ "scripts/apply-patches.js",
13
+ "patches/core.py.patch"
12
14
  ],
13
15
  "scripts": {
14
16
  "build": "tsc",
@@ -0,0 +1,43 @@
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
+
@@ -54,14 +54,31 @@ class RLM:
54
54
  _current_depth: Internal current depth tracker
55
55
  **llm_kwargs: Additional LiteLLM parameters
56
56
  """
57
- self.model = model
58
- self.recursive_model = recursive_model or model
59
- self.api_base = api_base
60
- self.api_key = api_key
61
- self.max_depth = max_depth
62
- self.max_iterations = max_iterations
57
+ # Patch for recursive-llm-ts bug where config is passed as 2nd positional arg
58
+ if isinstance(recursive_model, dict):
59
+ config = recursive_model
60
+ # Reset recursive_model default
61
+ self.recursive_model = config.get('recursive_model', model)
62
+ self.api_base = config.get('api_base', api_base)
63
+ self.api_key = config.get('api_key', api_key)
64
+ self.max_depth = int(config.get('max_depth', max_depth))
65
+ self.max_iterations = int(config.get('max_iterations', max_iterations))
66
+
67
+ # Extract other llm kwargs
68
+ excluded = {'recursive_model', 'api_base', 'api_key', 'max_depth', 'max_iterations'}
69
+ self.llm_kwargs = {k: v for k, v in config.items() if k not in excluded}
70
+ # Merge with any actual kwargs passed
71
+ self.llm_kwargs.update(llm_kwargs)
72
+ else:
73
+ self.recursive_model = recursive_model or model
74
+ self.api_base = api_base
75
+ self.api_key = api_key
76
+ self.max_depth = max_depth
77
+ self.max_iterations = max_iterations
78
+ self.llm_kwargs = llm_kwargs
79
+
63
80
  self._current_depth = _current_depth
64
- self.llm_kwargs = llm_kwargs
81
+ self.model = model
65
82
 
66
83
  self.repl = REPLExecutor()
67
84
 
@@ -0,0 +1,88 @@
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
+ }
@@ -12,6 +12,14 @@ 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
+
15
23
  console.log('Installing Python dependencies for recursive-llm...');
16
24
 
17
25
  try {