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.
- package/README.md +2 -12
- package/dist/cjs/bridge-factory.d.ts +7 -0
- package/dist/cjs/bridge-factory.js +96 -0
- package/dist/{bridge-interface.d.ts → cjs/bridge-interface.d.ts} +1 -2
- package/dist/{config.js → cjs/config.js} +0 -6
- package/dist/{coordinator.js → cjs/coordinator.js} +1 -1
- package/dist/{go-bridge.d.ts → cjs/go-bridge.d.ts} +2 -2
- package/dist/{go-bridge.js → cjs/go-bridge.js} +36 -4
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/pkg-dir.d.ts +7 -0
- package/dist/cjs/pkg-dir.js +79 -0
- package/dist/{rlm.d.ts → cjs/rlm.d.ts} +1 -1
- package/dist/{rlm.js → cjs/rlm.js} +3 -3
- package/dist/esm/bridge-factory.d.ts +7 -0
- package/dist/esm/bridge-factory.js +60 -0
- package/dist/esm/bridge-interface.d.ts +269 -0
- package/dist/esm/bridge-interface.js +1 -0
- package/dist/esm/cache.d.ts +78 -0
- package/dist/esm/cache.js +207 -0
- package/dist/esm/config.d.ts +37 -0
- package/dist/esm/config.js +152 -0
- package/dist/esm/coordinator.d.ts +17 -0
- package/dist/esm/coordinator.js +41 -0
- package/dist/esm/errors.d.ts +113 -0
- package/dist/esm/errors.js +205 -0
- package/dist/esm/events.d.ts +126 -0
- package/dist/esm/events.js +73 -0
- package/dist/esm/file-storage.d.ts +122 -0
- package/dist/esm/file-storage.js +656 -0
- package/dist/esm/go-bridge.d.ts +5 -0
- package/dist/esm/go-bridge.js +133 -0
- package/dist/esm/index.d.ts +12 -0
- package/dist/esm/index.js +17 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/pkg-dir.d.ts +7 -0
- package/dist/esm/pkg-dir.js +43 -0
- package/dist/esm/retry.d.ts +56 -0
- package/dist/esm/retry.js +181 -0
- package/dist/esm/rlm.d.ts +435 -0
- package/dist/esm/rlm.js +1122 -0
- package/dist/esm/streaming.d.ts +96 -0
- package/dist/esm/streaming.js +205 -0
- package/dist/esm/structured-types.d.ts +28 -0
- package/dist/esm/structured-types.js +1 -0
- package/package.json +32 -5
- package/scripts/build-go-binary.js +44 -5
- package/dist/bridge-factory.d.ts +0 -6
- package/dist/bridge-factory.js +0 -134
- package/dist/bunpy-bridge.d.ts +0 -7
- package/dist/bunpy-bridge.js +0 -37
- package/dist/rlm-bridge.d.ts +0 -8
- package/dist/rlm-bridge.js +0 -179
- /package/dist/{bridge-interface.js → cjs/bridge-interface.js} +0 -0
- /package/dist/{cache.d.ts → cjs/cache.d.ts} +0 -0
- /package/dist/{cache.js → cjs/cache.js} +0 -0
- /package/dist/{config.d.ts → cjs/config.d.ts} +0 -0
- /package/dist/{coordinator.d.ts → cjs/coordinator.d.ts} +0 -0
- /package/dist/{errors.d.ts → cjs/errors.d.ts} +0 -0
- /package/dist/{errors.js → cjs/errors.js} +0 -0
- /package/dist/{events.d.ts → cjs/events.d.ts} +0 -0
- /package/dist/{events.js → cjs/events.js} +0 -0
- /package/dist/{file-storage.d.ts → cjs/file-storage.d.ts} +0 -0
- /package/dist/{file-storage.js → cjs/file-storage.js} +0 -0
- /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/dist/{index.js → cjs/index.js} +0 -0
- /package/dist/{retry.d.ts → cjs/retry.d.ts} +0 -0
- /package/dist/{retry.js → cjs/retry.js} +0 -0
- /package/dist/{streaming.d.ts → cjs/streaming.d.ts} +0 -0
- /package/dist/{streaming.js → cjs/streaming.js} +0 -0
- /package/dist/{structured-types.d.ts → cjs/structured-types.d.ts} +0 -0
- /package/dist/{structured-types.js → cjs/structured-types.js} +0 -0
package/README.md
CHANGED
|
@@ -44,11 +44,8 @@ npm install recursive-llm-ts
|
|
|
44
44
|
|
|
45
45
|
### Prerequisites
|
|
46
46
|
|
|
47
|
-
- **Node.js 16+**
|
|
47
|
+
- **Node.js 16+**
|
|
48
48
|
- **Go 1.25+** (for building from source during install)
|
|
49
|
-
|
|
50
|
-
> **Note**: The package includes pre-built binaries for common platforms. Go is only needed if building from source.
|
|
51
|
-
|
|
52
49
|
### Go Binary (Automatic)
|
|
53
50
|
|
|
54
51
|
The `postinstall` script automatically builds the Go binary during installation. If Go is not available, the script will warn but not fail.
|
|
@@ -72,13 +69,11 @@ export RLM_GO_BINARY=/custom/path/to/rlm-go
|
|
|
72
69
|
|
|
73
70
|
## Usage
|
|
74
71
|
|
|
75
|
-
###
|
|
76
|
-
|
|
72
|
+
### Quick Start
|
|
77
73
|
```typescript
|
|
78
74
|
import { RLM } from 'recursive-llm-ts';
|
|
79
75
|
|
|
80
76
|
// Initialize RLM with a model
|
|
81
|
-
// Automatically detects Node.js or Bun and uses appropriate bridge
|
|
82
77
|
const rlm = new RLM('gpt-4o-mini', {
|
|
83
78
|
max_iterations: 15,
|
|
84
79
|
api_key: process.env.OPENAI_API_KEY
|
|
@@ -420,9 +415,6 @@ const rlmGo = new RLM('gpt-4o-mini', {
|
|
|
420
415
|
api_key: process.env.OPENAI_API_KEY
|
|
421
416
|
}, 'go');
|
|
422
417
|
|
|
423
|
-
// Legacy: Use Python bridges (bunpy for Bun, pythonia for Node)
|
|
424
|
-
// Note: Requires separate Python dependencies
|
|
425
|
-
const rlmPython = new RLM('gpt-4o-mini', {}, 'bunpy');
|
|
426
418
|
```
|
|
427
419
|
|
|
428
420
|
|
|
@@ -781,7 +773,6 @@ interface RLMConfig {
|
|
|
781
773
|
// Execution limits
|
|
782
774
|
max_depth?: number; // Maximum recursion depth (default: 5)
|
|
783
775
|
max_iterations?: number; // Maximum REPL iterations per call (default: 30)
|
|
784
|
-
pythonia_timeout?: number; // Python bridge timeout in ms (default: 100000ms = 100s)
|
|
785
776
|
go_binary_path?: string; // Override path for Go binary (optional)
|
|
786
777
|
|
|
787
778
|
// Meta-agent configuration
|
|
@@ -1005,7 +996,6 @@ For large documents or queue-based processing that may take longer than the defa
|
|
|
1005
996
|
```typescript
|
|
1006
997
|
const rlm = new RLM('gpt-4o-mini', {
|
|
1007
998
|
max_iterations: 50, // Allow more iterations for complex processing
|
|
1008
|
-
pythonia_timeout: 600000, // 10 minutes timeout for Python bridge
|
|
1009
999
|
timeout: 300 // 5 minutes timeout for LLM API calls
|
|
1010
1000
|
});
|
|
1011
1001
|
|
|
@@ -0,0 +1,96 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.createBridge = createBridge;
|
|
46
|
+
const fs = __importStar(require("fs"));
|
|
47
|
+
const path = __importStar(require("path"));
|
|
48
|
+
const pkg_dir_1 = require("./pkg-dir");
|
|
49
|
+
const DEFAULT_GO_BINARY = process.platform === 'win32' ? 'rlm-go.exe' : 'rlm-go';
|
|
50
|
+
function resolveDefaultGoBinary() {
|
|
51
|
+
return path.join(pkg_dir_1.PKG_ROOT_DIR, 'bin', DEFAULT_GO_BINARY);
|
|
52
|
+
}
|
|
53
|
+
/** Platform-specific npm package names for pre-built binaries */
|
|
54
|
+
const PLATFORM_PACKAGES = {
|
|
55
|
+
'darwin-arm64': '@recursive-llm/darwin-arm64',
|
|
56
|
+
'darwin-x64': '@recursive-llm/darwin-x64',
|
|
57
|
+
'linux-x64': '@recursive-llm/linux-x64',
|
|
58
|
+
'linux-arm64': '@recursive-llm/linux-arm64',
|
|
59
|
+
'win32-x64': '@recursive-llm/win32-x64',
|
|
60
|
+
};
|
|
61
|
+
function isPlatformBinaryAvailable() {
|
|
62
|
+
const key = `${process.platform}-${process.arch}`;
|
|
63
|
+
const pkgName = PLATFORM_PACKAGES[key];
|
|
64
|
+
if (!pkgName)
|
|
65
|
+
return false;
|
|
66
|
+
try {
|
|
67
|
+
const pkgDir = path.dirname(require.resolve(`${pkgName}/package.json`));
|
|
68
|
+
return fs.existsSync(path.join(pkgDir, 'bin', DEFAULT_GO_BINARY));
|
|
69
|
+
}
|
|
70
|
+
catch (_a) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function isGoBinaryAvailable() {
|
|
75
|
+
const envPath = process.env.RLM_GO_BINARY;
|
|
76
|
+
if (envPath && fs.existsSync(envPath)) {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
if (isPlatformBinaryAvailable())
|
|
80
|
+
return true;
|
|
81
|
+
return fs.existsSync(resolveDefaultGoBinary());
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Create the Go bridge for RLM communication.
|
|
85
|
+
* Throws if the Go binary is not available.
|
|
86
|
+
*/
|
|
87
|
+
function createBridge() {
|
|
88
|
+
return __awaiter(this, arguments, void 0, function* (bridgeType = 'go') {
|
|
89
|
+
if (!isGoBinaryAvailable()) {
|
|
90
|
+
throw new Error('Go RLM binary not found. Build it with: node scripts/build-go-binary.js\n' +
|
|
91
|
+
'Ensure Go 1.25+ is installed: https://go.dev/dl/');
|
|
92
|
+
}
|
|
93
|
+
const { GoBridge } = yield Promise.resolve().then(() => __importStar(require('./go-bridge')));
|
|
94
|
+
return new GoBridge();
|
|
95
|
+
});
|
|
96
|
+
}
|
|
@@ -205,7 +205,6 @@ export interface RLMConfig {
|
|
|
205
205
|
api_key?: string;
|
|
206
206
|
max_depth?: number;
|
|
207
207
|
max_iterations?: number;
|
|
208
|
-
pythonia_timeout?: number;
|
|
209
208
|
go_binary_path?: string;
|
|
210
209
|
meta_agent?: MetaAgentConfig;
|
|
211
210
|
observability?: ObservabilityConfig;
|
|
@@ -264,7 +263,7 @@ export interface FileStorageConfig {
|
|
|
264
263
|
/** File extensions to include (e.g. ['.ts', '.md', '.txt']) */
|
|
265
264
|
extensions?: string[];
|
|
266
265
|
}
|
|
267
|
-
export interface
|
|
266
|
+
export interface Bridge {
|
|
268
267
|
completion(model: string, query: string, context: string, rlmConfig: RLMConfig): Promise<RLMResult>;
|
|
269
268
|
cleanup(): Promise<void>;
|
|
270
269
|
}
|
|
@@ -15,7 +15,6 @@ const KNOWN_CONFIG_KEYS = new Set([
|
|
|
15
15
|
'api_key',
|
|
16
16
|
'max_depth',
|
|
17
17
|
'max_iterations',
|
|
18
|
-
'pythonia_timeout',
|
|
19
18
|
'go_binary_path',
|
|
20
19
|
'meta_agent',
|
|
21
20
|
'observability',
|
|
@@ -58,11 +57,6 @@ function validateConfig(config) {
|
|
|
58
57
|
issues.push({ level: 'error', field: 'max_iterations', message: 'max_iterations must be a positive integer' });
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
|
-
if (config.pythonia_timeout !== undefined) {
|
|
62
|
-
if (typeof config.pythonia_timeout !== 'number' || config.pythonia_timeout < 0) {
|
|
63
|
-
issues.push({ level: 'error', field: 'pythonia_timeout', message: 'pythonia_timeout must be a non-negative number (milliseconds)' });
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
60
|
// Validate API base URL
|
|
67
61
|
if (config.api_base !== undefined && typeof config.api_base === 'string') {
|
|
68
62
|
try {
|
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.RLMAgentCoordinator = void 0;
|
|
13
13
|
const rlm_1 = require("./rlm");
|
|
14
14
|
class RLMAgentCoordinator {
|
|
15
|
-
constructor(model, rlmConfig = {}, bridgeType = '
|
|
15
|
+
constructor(model, rlmConfig = {}, bridgeType = 'go', coordinatorConfig = {}) {
|
|
16
16
|
var _a, _b, _c;
|
|
17
17
|
this.rlm = new rlm_1.RLM(model, rlmConfig, bridgeType);
|
|
18
18
|
this.config = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare class GoBridge implements
|
|
1
|
+
import { Bridge, RLMConfig, RLMResult } from './bridge-interface';
|
|
2
|
+
export declare class GoBridge implements Bridge {
|
|
3
3
|
completion(model: string, query: string, context: string, rlmConfig?: RLMConfig): Promise<RLMResult>;
|
|
4
4
|
cleanup(): Promise<void>;
|
|
5
5
|
}
|
|
@@ -57,16 +57,48 @@ exports.GoBridge = void 0;
|
|
|
57
57
|
const fs = __importStar(require("fs"));
|
|
58
58
|
const path = __importStar(require("path"));
|
|
59
59
|
const child_process_1 = require("child_process");
|
|
60
|
+
const pkg_dir_1 = require("./pkg-dir");
|
|
60
61
|
const DEFAULT_BINARY_NAME = process.platform === 'win32' ? 'rlm-go.exe' : 'rlm-go';
|
|
62
|
+
/** Platform-specific npm package names for pre-built binaries */
|
|
63
|
+
const PLATFORM_PACKAGES = {
|
|
64
|
+
'darwin-arm64': '@recursive-llm/darwin-arm64',
|
|
65
|
+
'darwin-x64': '@recursive-llm/darwin-x64',
|
|
66
|
+
'linux-x64': '@recursive-llm/linux-x64',
|
|
67
|
+
'linux-arm64': '@recursive-llm/linux-arm64',
|
|
68
|
+
'win32-x64': '@recursive-llm/win32-x64',
|
|
69
|
+
};
|
|
70
|
+
function resolvePlatformBinary() {
|
|
71
|
+
const platform = process.platform;
|
|
72
|
+
const arch = process.arch;
|
|
73
|
+
const key = `${platform}-${arch}`;
|
|
74
|
+
const pkgName = PLATFORM_PACKAGES[key];
|
|
75
|
+
if (!pkgName)
|
|
76
|
+
return null;
|
|
77
|
+
try {
|
|
78
|
+
// require.resolve works in both CJS and ESM (via createRequire)
|
|
79
|
+
const pkgDir = path.dirname(require.resolve(`${pkgName}/package.json`));
|
|
80
|
+
const binPath = path.join(pkgDir, 'bin', DEFAULT_BINARY_NAME);
|
|
81
|
+
if (fs.existsSync(binPath))
|
|
82
|
+
return binPath;
|
|
83
|
+
}
|
|
84
|
+
catch (_a) {
|
|
85
|
+
// Package not installed — fall through
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
61
89
|
function resolveBinaryPath(rlmConfig) {
|
|
62
90
|
const configuredPath = rlmConfig.go_binary_path || process.env.RLM_GO_BINARY;
|
|
63
91
|
if (configuredPath) {
|
|
64
92
|
return configuredPath;
|
|
65
93
|
}
|
|
66
|
-
// Try
|
|
94
|
+
// 1. Try platform-specific npm package (pre-built binary)
|
|
95
|
+
const platformBin = resolvePlatformBinary();
|
|
96
|
+
if (platformBin)
|
|
97
|
+
return platformBin;
|
|
98
|
+
// 2. Try local locations
|
|
67
99
|
const possiblePaths = [
|
|
68
|
-
path.join(
|
|
69
|
-
path.join(
|
|
100
|
+
path.join(pkg_dir_1.PKG_ROOT_DIR, 'bin', DEFAULT_BINARY_NAME), // NPM package (primary)
|
|
101
|
+
path.join(pkg_dir_1.PKG_ROOT_DIR, 'go', DEFAULT_BINARY_NAME), // Development fallback
|
|
70
102
|
];
|
|
71
103
|
for (const p of possiblePaths) {
|
|
72
104
|
if (fs.existsSync(p)) {
|
|
@@ -82,7 +114,7 @@ function assertBinaryExists(binaryPath) {
|
|
|
82
114
|
}
|
|
83
115
|
}
|
|
84
116
|
function sanitizeConfig(config) {
|
|
85
|
-
const {
|
|
117
|
+
const { go_binary_path, structured } = config, sanitized = __rest(config, ["go_binary_path", "structured"]);
|
|
86
118
|
return { config: sanitized, structured };
|
|
87
119
|
}
|
|
88
120
|
class GoBridge {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Directory containing the compiled JS file (dist/cjs or dist/esm or dist) */
|
|
2
|
+
export declare const PKG_DIST_DIR: string;
|
|
3
|
+
/**
|
|
4
|
+
* Package root directory.
|
|
5
|
+
* Handles both flat (dist/) and nested (dist/cjs/, dist/esm/) layouts.
|
|
6
|
+
*/
|
|
7
|
+
export declare const PKG_ROOT_DIR: string;
|
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.PKG_ROOT_DIR = exports.PKG_DIST_DIR = void 0;
|
|
37
|
+
/**
|
|
38
|
+
* Portable package directory resolution.
|
|
39
|
+
*
|
|
40
|
+
* Works in both CommonJS and ESM contexts by detecting the available
|
|
41
|
+
* globals and falling back gracefully. The resolved path always points
|
|
42
|
+
* to the package root (parent of the dist/cjs or dist/esm directory).
|
|
43
|
+
*/
|
|
44
|
+
const path = __importStar(require("path"));
|
|
45
|
+
const url_1 = require("url");
|
|
46
|
+
function resolveCurrentDir() {
|
|
47
|
+
// CJS — __dirname is defined natively by Node
|
|
48
|
+
if (typeof __dirname !== 'undefined') {
|
|
49
|
+
return __dirname;
|
|
50
|
+
}
|
|
51
|
+
// ESM — derive from import.meta.url via indirect eval to avoid CJS parse errors.
|
|
52
|
+
// This branch only runs in ESM where import.meta is valid syntax.
|
|
53
|
+
try {
|
|
54
|
+
const meta = new Function('return import.meta')();
|
|
55
|
+
if (meta && typeof meta.url === 'string') {
|
|
56
|
+
return path.dirname((0, url_1.fileURLToPath)(meta.url));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch (_a) {
|
|
60
|
+
// Not in ESM or import.meta not supported
|
|
61
|
+
}
|
|
62
|
+
// Last resort: use process.cwd()
|
|
63
|
+
return process.cwd();
|
|
64
|
+
}
|
|
65
|
+
/** Directory containing the compiled JS file (dist/cjs or dist/esm or dist) */
|
|
66
|
+
exports.PKG_DIST_DIR = resolveCurrentDir();
|
|
67
|
+
/**
|
|
68
|
+
* Package root directory.
|
|
69
|
+
* Handles both flat (dist/) and nested (dist/cjs/, dist/esm/) layouts.
|
|
70
|
+
*/
|
|
71
|
+
exports.PKG_ROOT_DIR = (() => {
|
|
72
|
+
const parent = path.dirname(exports.PKG_DIST_DIR);
|
|
73
|
+
const parentBase = path.basename(parent);
|
|
74
|
+
// If parent is 'dist', we're in dist/cjs or dist/esm — go up one more
|
|
75
|
+
if (parentBase === 'dist') {
|
|
76
|
+
return path.dirname(parent);
|
|
77
|
+
}
|
|
78
|
+
return parent;
|
|
79
|
+
})();
|
|
@@ -111,7 +111,7 @@ export declare class RLM {
|
|
|
111
111
|
*
|
|
112
112
|
* @param model - The LLM model identifier (e.g., 'gpt-4o-mini', 'claude-sonnet-4-20250514')
|
|
113
113
|
* @param rlmConfig - Configuration options for the RLM engine
|
|
114
|
-
* @param bridgeType - Bridge selection: '
|
|
114
|
+
* @param bridgeType - Bridge selection: 'go' (default)
|
|
115
115
|
*
|
|
116
116
|
* @example
|
|
117
117
|
* ```typescript
|
|
@@ -119,7 +119,7 @@ exports.RLMResultFormatter = RLMResultFormatter;
|
|
|
119
119
|
class RLMBuilder {
|
|
120
120
|
constructor(model) {
|
|
121
121
|
this.config = {};
|
|
122
|
-
this.bridgeType = '
|
|
122
|
+
this.bridgeType = 'go';
|
|
123
123
|
this.model = model;
|
|
124
124
|
}
|
|
125
125
|
/** Set the API key */
|
|
@@ -208,7 +208,7 @@ class RLM {
|
|
|
208
208
|
*
|
|
209
209
|
* @param model - The LLM model identifier (e.g., 'gpt-4o-mini', 'claude-sonnet-4-20250514')
|
|
210
210
|
* @param rlmConfig - Configuration options for the RLM engine
|
|
211
|
-
* @param bridgeType - Bridge selection: '
|
|
211
|
+
* @param bridgeType - Bridge selection: 'go' (default)
|
|
212
212
|
*
|
|
213
213
|
* @example
|
|
214
214
|
* ```typescript
|
|
@@ -220,7 +220,7 @@ class RLM {
|
|
|
220
220
|
* });
|
|
221
221
|
* ```
|
|
222
222
|
*/
|
|
223
|
-
constructor(model, rlmConfig = {}, bridgeType = '
|
|
223
|
+
constructor(model, rlmConfig = {}, bridgeType = 'go') {
|
|
224
224
|
this.bridge = null;
|
|
225
225
|
this.lastTraceEvents = [];
|
|
226
226
|
this.model = model;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import * as fs from 'fs';
|
|
11
|
+
import * as path from 'path';
|
|
12
|
+
import { PKG_ROOT_DIR } from './pkg-dir.js';
|
|
13
|
+
const DEFAULT_GO_BINARY = process.platform === 'win32' ? 'rlm-go.exe' : 'rlm-go';
|
|
14
|
+
function resolveDefaultGoBinary() {
|
|
15
|
+
return path.join(PKG_ROOT_DIR, 'bin', DEFAULT_GO_BINARY);
|
|
16
|
+
}
|
|
17
|
+
/** Platform-specific npm package names for pre-built binaries */
|
|
18
|
+
const PLATFORM_PACKAGES = {
|
|
19
|
+
'darwin-arm64': '@recursive-llm/darwin-arm64',
|
|
20
|
+
'darwin-x64': '@recursive-llm/darwin-x64',
|
|
21
|
+
'linux-x64': '@recursive-llm/linux-x64',
|
|
22
|
+
'linux-arm64': '@recursive-llm/linux-arm64',
|
|
23
|
+
'win32-x64': '@recursive-llm/win32-x64',
|
|
24
|
+
};
|
|
25
|
+
function isPlatformBinaryAvailable() {
|
|
26
|
+
const key = `${process.platform}-${process.arch}`;
|
|
27
|
+
const pkgName = PLATFORM_PACKAGES[key];
|
|
28
|
+
if (!pkgName)
|
|
29
|
+
return false;
|
|
30
|
+
try {
|
|
31
|
+
const pkgDir = path.dirname(require.resolve(`${pkgName}/package.json`));
|
|
32
|
+
return fs.existsSync(path.join(pkgDir, 'bin', DEFAULT_GO_BINARY));
|
|
33
|
+
}
|
|
34
|
+
catch (_a) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function isGoBinaryAvailable() {
|
|
39
|
+
const envPath = process.env.RLM_GO_BINARY;
|
|
40
|
+
if (envPath && fs.existsSync(envPath)) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
if (isPlatformBinaryAvailable())
|
|
44
|
+
return true;
|
|
45
|
+
return fs.existsSync(resolveDefaultGoBinary());
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Create the Go bridge for RLM communication.
|
|
49
|
+
* Throws if the Go binary is not available.
|
|
50
|
+
*/
|
|
51
|
+
export function createBridge() {
|
|
52
|
+
return __awaiter(this, arguments, void 0, function* (bridgeType = 'go') {
|
|
53
|
+
if (!isGoBinaryAvailable()) {
|
|
54
|
+
throw new Error('Go RLM binary not found. Build it with: node scripts/build-go-binary.js\n' +
|
|
55
|
+
'Ensure Go 1.25+ is installed: https://go.dev/dl/');
|
|
56
|
+
}
|
|
57
|
+
const { GoBridge } = yield import('./go-bridge.js');
|
|
58
|
+
return new GoBridge();
|
|
59
|
+
});
|
|
60
|
+
}
|