recursive-llm-ts 5.0.2 → 5.2.3

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.
Files changed (71) hide show
  1. package/README.md +2 -12
  2. package/dist/cjs/bridge-factory.d.ts +7 -0
  3. package/dist/cjs/bridge-factory.js +96 -0
  4. package/dist/{bridge-interface.d.ts → cjs/bridge-interface.d.ts} +1 -2
  5. package/dist/{config.js → cjs/config.js} +0 -6
  6. package/dist/{coordinator.js → cjs/coordinator.js} +1 -1
  7. package/dist/{go-bridge.d.ts → cjs/go-bridge.d.ts} +2 -2
  8. package/dist/{go-bridge.js → cjs/go-bridge.js} +36 -4
  9. package/dist/cjs/package.json +3 -0
  10. package/dist/cjs/pkg-dir.d.ts +7 -0
  11. package/dist/cjs/pkg-dir.js +79 -0
  12. package/dist/{rlm.d.ts → cjs/rlm.d.ts} +1 -1
  13. package/dist/{rlm.js → cjs/rlm.js} +3 -3
  14. package/dist/esm/bridge-factory.d.ts +7 -0
  15. package/dist/esm/bridge-factory.js +60 -0
  16. package/dist/esm/bridge-interface.d.ts +269 -0
  17. package/dist/esm/bridge-interface.js +1 -0
  18. package/dist/esm/cache.d.ts +78 -0
  19. package/dist/esm/cache.js +207 -0
  20. package/dist/esm/config.d.ts +37 -0
  21. package/dist/esm/config.js +152 -0
  22. package/dist/esm/coordinator.d.ts +17 -0
  23. package/dist/esm/coordinator.js +41 -0
  24. package/dist/esm/errors.d.ts +113 -0
  25. package/dist/esm/errors.js +205 -0
  26. package/dist/esm/events.d.ts +126 -0
  27. package/dist/esm/events.js +73 -0
  28. package/dist/esm/file-storage.d.ts +122 -0
  29. package/dist/esm/file-storage.js +656 -0
  30. package/dist/esm/go-bridge.d.ts +5 -0
  31. package/dist/esm/go-bridge.js +133 -0
  32. package/dist/esm/index.d.ts +12 -0
  33. package/dist/esm/index.js +17 -0
  34. package/dist/esm/package.json +3 -0
  35. package/dist/esm/pkg-dir.d.ts +7 -0
  36. package/dist/esm/pkg-dir.js +43 -0
  37. package/dist/esm/retry.d.ts +56 -0
  38. package/dist/esm/retry.js +181 -0
  39. package/dist/esm/rlm.d.ts +435 -0
  40. package/dist/esm/rlm.js +1122 -0
  41. package/dist/esm/streaming.d.ts +96 -0
  42. package/dist/esm/streaming.js +205 -0
  43. package/dist/esm/structured-types.d.ts +28 -0
  44. package/dist/esm/structured-types.js +1 -0
  45. package/package.json +32 -5
  46. package/scripts/build-go-binary.js +44 -5
  47. package/dist/bridge-factory.d.ts +0 -6
  48. package/dist/bridge-factory.js +0 -134
  49. package/dist/bunpy-bridge.d.ts +0 -7
  50. package/dist/bunpy-bridge.js +0 -37
  51. package/dist/rlm-bridge.d.ts +0 -8
  52. package/dist/rlm-bridge.js +0 -179
  53. /package/dist/{bridge-interface.js → cjs/bridge-interface.js} +0 -0
  54. /package/dist/{cache.d.ts → cjs/cache.d.ts} +0 -0
  55. /package/dist/{cache.js → cjs/cache.js} +0 -0
  56. /package/dist/{config.d.ts → cjs/config.d.ts} +0 -0
  57. /package/dist/{coordinator.d.ts → cjs/coordinator.d.ts} +0 -0
  58. /package/dist/{errors.d.ts → cjs/errors.d.ts} +0 -0
  59. /package/dist/{errors.js → cjs/errors.js} +0 -0
  60. /package/dist/{events.d.ts → cjs/events.d.ts} +0 -0
  61. /package/dist/{events.js → cjs/events.js} +0 -0
  62. /package/dist/{file-storage.d.ts → cjs/file-storage.d.ts} +0 -0
  63. /package/dist/{file-storage.js → cjs/file-storage.js} +0 -0
  64. /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
  65. /package/dist/{index.js → cjs/index.js} +0 -0
  66. /package/dist/{retry.d.ts → cjs/retry.d.ts} +0 -0
  67. /package/dist/{retry.js → cjs/retry.js} +0 -0
  68. /package/dist/{streaming.d.ts → cjs/streaming.d.ts} +0 -0
  69. /package/dist/{streaming.js → cjs/streaming.js} +0 -0
  70. /package/dist/{structured-types.d.ts → cjs/structured-types.d.ts} +0 -0
  71. /package/dist/{structured-types.js → cjs/structured-types.js} +0 -0
@@ -1,179 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
- return new (P || (P = Promise))(function (resolve, reject) {
38
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
43
- };
44
- var __rest = (this && this.__rest) || function (s, e) {
45
- var t = {};
46
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
47
- t[p] = s[p];
48
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
49
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
50
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
51
- t[p[i]] = s[p[i]];
52
- }
53
- return t;
54
- };
55
- Object.defineProperty(exports, "__esModule", { value: true });
56
- exports.PythoniaBridge = void 0;
57
- const path = __importStar(require("path"));
58
- const fs = __importStar(require("fs"));
59
- class PythoniaBridge {
60
- constructor() {
61
- this.rlmModule = null;
62
- this.python = null;
63
- }
64
- ensureRLMModule() {
65
- return __awaiter(this, void 0, void 0, function* () {
66
- var _a;
67
- if (this.rlmModule)
68
- return;
69
- // Lazy load pythonia to avoid errors in Bun environments
70
- if (!this.python) {
71
- try {
72
- // @ts-ignore - Optional dependency, may not be installed
73
- const pythonia = yield Promise.resolve().then(() => __importStar(require('pythonia')));
74
- this.python = pythonia.python;
75
- }
76
- catch (error) {
77
- throw new Error('pythonia is not available (Python dependencies removed in v3.0). ' +
78
- 'Please use the Go bridge (default) or install pythonia separately: npm install pythonia\n' +
79
- 'Note: pythonia only works with Node.js runtime, not Bun');
80
- }
81
- }
82
- const pythonPackagePath = path.join(__dirname, '..', 'recursive-llm');
83
- // Import sys module to add path
84
- const sys = yield this.python('sys');
85
- const pythonExecutable = String((yield sys.executable) || 'python');
86
- const pythonCmd = pythonExecutable.includes(' ') ? `"${pythonExecutable}"` : pythonExecutable;
87
- const pipCmd = `${pythonCmd} -m pip install -e "${pythonPackagePath}"`;
88
- const pythonDepsPath = path.join(pythonPackagePath, '.pydeps');
89
- const pyprojectPath = path.join(pythonPackagePath, 'pyproject.toml');
90
- const dependencySpecifiers = (() => {
91
- try {
92
- const pyproject = fs.readFileSync(pyprojectPath, 'utf8');
93
- const depsBlock = pyproject.match(/dependencies\s*=\s*\[[\s\S]*?\]/);
94
- if (!depsBlock)
95
- return [];
96
- return Array.from(depsBlock[0].matchAll(/"([^"]+)"/g), (match) => match[1]);
97
- }
98
- catch (_a) {
99
- return [];
100
- }
101
- })();
102
- const depsInstallCmd = dependencySpecifiers.length > 0
103
- ? `${pythonCmd} -m pip install --upgrade --target "${pythonDepsPath}" ${dependencySpecifiers.map((dep) => `"${dep}"`).join(' ')}`
104
- : '';
105
- const installCmd = depsInstallCmd || pipCmd;
106
- const pathList = yield sys.path;
107
- fs.mkdirSync(pythonDepsPath, { recursive: true });
108
- yield pathList.insert(0, pythonDepsPath);
109
- yield pathList.insert(0, path.join(pythonPackagePath, 'src'));
110
- // Try to import rlm, install deps if import fails
111
- try {
112
- this.rlmModule = yield this.python('rlm');
113
- }
114
- catch (error) {
115
- // If import fails, try installing dependencies
116
- if ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('No module named')) {
117
- console.log('[recursive-llm-ts] Installing Python dependencies locally (first time only)...');
118
- try {
119
- const { execSync } = yield Promise.resolve().then(() => __importStar(require('child_process')));
120
- execSync(installCmd, { stdio: 'inherit' });
121
- console.log('[recursive-llm-ts] ✓ Python dependencies installed');
122
- // Try import again
123
- this.rlmModule = yield this.python('rlm');
124
- }
125
- catch (installError) {
126
- throw new Error('Failed to import rlm module after installing dependencies.\n' +
127
- `Manual installation: ${installCmd}\n` +
128
- `Error: ${installError.message || installError}`);
129
- }
130
- }
131
- else {
132
- throw new Error('Failed to import rlm module.\n' +
133
- `Run: ${installCmd}\n` +
134
- `Original error: ${error.message || error}`);
135
- }
136
- }
137
- });
138
- }
139
- completion(model_1, query_1, context_1) {
140
- return __awaiter(this, arguments, void 0, function* (model, query, context, rlmConfig = {}) {
141
- yield this.ensureRLMModule();
142
- try {
143
- // Extract pythonia timeout (default: 100000ms)
144
- const pythoniaTimeout = rlmConfig.pythonia_timeout || 100000;
145
- // Remove pythonia_timeout from config passed to Python
146
- const { pythonia_timeout } = rlmConfig, pythonConfig = __rest(rlmConfig, ["pythonia_timeout"]);
147
- // Create RLM instance with config, passing timeout to pythonia
148
- const RLMClass = yield this.rlmModule.RLM;
149
- const rlmInstance = yield RLMClass(model, Object.assign(Object.assign({}, pythonConfig), { $timeout: pythoniaTimeout }));
150
- // Call completion method with timeout
151
- const result = yield rlmInstance.completion(query, context, { $timeout: pythoniaTimeout });
152
- const stats = yield rlmInstance.stats;
153
- // Convert Python stats dict to JS object
154
- const statsObj = {
155
- llm_calls: yield stats.llm_calls,
156
- iterations: yield stats.iterations,
157
- depth: yield stats.depth
158
- };
159
- return {
160
- result: String(result),
161
- stats: statsObj
162
- };
163
- }
164
- catch (error) {
165
- throw new Error(`RLM completion failed: ${error.message || error}`);
166
- }
167
- });
168
- }
169
- cleanup() {
170
- return __awaiter(this, void 0, void 0, function* () {
171
- if (this.python && this.rlmModule) {
172
- this.python.exit();
173
- this.rlmModule = null;
174
- this.python = null;
175
- }
176
- });
177
- }
178
- }
179
- exports.PythoniaBridge = PythoniaBridge;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes