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
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event system for recursive-llm-ts.
|
|
3
|
+
*
|
|
4
|
+
* Provides typed event emission for monitoring LLM operations,
|
|
5
|
+
* validation retries, recursion progress, and more.
|
|
6
|
+
*/
|
|
7
|
+
// ─── Event Emitter ───────────────────────────────────────────────────────────
|
|
8
|
+
/**
|
|
9
|
+
* Typed event emitter for RLM operations.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const rlm = new RLM('gpt-4o-mini');
|
|
14
|
+
* rlm.on('llm_call', (event) => console.log('LLM call:', event.model));
|
|
15
|
+
* rlm.on('error', (event) => reportToSentry(event.error));
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export class RLMEventEmitter {
|
|
19
|
+
constructor() {
|
|
20
|
+
this.listeners = new Map();
|
|
21
|
+
}
|
|
22
|
+
/** Register an event listener */
|
|
23
|
+
on(event, listener) {
|
|
24
|
+
if (!this.listeners.has(event)) {
|
|
25
|
+
this.listeners.set(event, new Set());
|
|
26
|
+
}
|
|
27
|
+
this.listeners.get(event).add(listener);
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
/** Register a one-time event listener */
|
|
31
|
+
once(event, listener) {
|
|
32
|
+
const wrapper = (e) => {
|
|
33
|
+
this.off(event, wrapper);
|
|
34
|
+
listener(e);
|
|
35
|
+
};
|
|
36
|
+
return this.on(event, wrapper);
|
|
37
|
+
}
|
|
38
|
+
/** Remove an event listener */
|
|
39
|
+
off(event, listener) {
|
|
40
|
+
var _a;
|
|
41
|
+
(_a = this.listeners.get(event)) === null || _a === void 0 ? void 0 : _a.delete(listener);
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
/** Remove all listeners for an event (or all events) */
|
|
45
|
+
removeAllListeners(event) {
|
|
46
|
+
if (event) {
|
|
47
|
+
this.listeners.delete(event);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
this.listeners.clear();
|
|
51
|
+
}
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
/** Emit an event to all registered listeners */
|
|
55
|
+
emit(event, data) {
|
|
56
|
+
const eventListeners = this.listeners.get(event);
|
|
57
|
+
if (eventListeners) {
|
|
58
|
+
for (const listener of eventListeners) {
|
|
59
|
+
try {
|
|
60
|
+
listener(data);
|
|
61
|
+
}
|
|
62
|
+
catch (_a) {
|
|
63
|
+
// Don't let listener errors break the emitter
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** Get the number of listeners for an event */
|
|
69
|
+
listenerCount(event) {
|
|
70
|
+
var _a, _b;
|
|
71
|
+
return (_b = (_a = this.listeners.get(event)) === null || _a === void 0 ? void 0 : _a.size) !== null && _b !== void 0 ? _b : 0;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { FileStorageConfig } from './bridge-interface';
|
|
2
|
+
/**
|
|
3
|
+
* Custom error class for S3 storage operations.
|
|
4
|
+
* Provides actionable error messages for common failure modes.
|
|
5
|
+
*/
|
|
6
|
+
export declare class S3StorageError extends Error {
|
|
7
|
+
readonly code: string;
|
|
8
|
+
readonly bucket: string;
|
|
9
|
+
readonly key?: string;
|
|
10
|
+
readonly originalError?: Error;
|
|
11
|
+
constructor(opts: {
|
|
12
|
+
message: string;
|
|
13
|
+
code: string;
|
|
14
|
+
bucket: string;
|
|
15
|
+
key?: string;
|
|
16
|
+
originalError?: Error;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export { FileStorageConfig } from './bridge-interface';
|
|
20
|
+
export interface FileEntry {
|
|
21
|
+
/** Relative path from the root of the storage source */
|
|
22
|
+
relativePath: string;
|
|
23
|
+
/** File content as a string */
|
|
24
|
+
content: string;
|
|
25
|
+
/** Size in bytes */
|
|
26
|
+
size: number;
|
|
27
|
+
}
|
|
28
|
+
export interface FileStorageResult {
|
|
29
|
+
/** The built context string containing all file contents */
|
|
30
|
+
context: string;
|
|
31
|
+
/** List of files that were included */
|
|
32
|
+
files: Array<{
|
|
33
|
+
relativePath: string;
|
|
34
|
+
size: number;
|
|
35
|
+
}>;
|
|
36
|
+
/** Total size of all file contents */
|
|
37
|
+
totalSize: number;
|
|
38
|
+
/** Files that were skipped and why */
|
|
39
|
+
skipped: Array<{
|
|
40
|
+
relativePath: string;
|
|
41
|
+
reason: string;
|
|
42
|
+
}>;
|
|
43
|
+
}
|
|
44
|
+
export interface FileStorageProvider {
|
|
45
|
+
listFiles(): Promise<string[]>;
|
|
46
|
+
readFile(relativePath: string): Promise<string>;
|
|
47
|
+
getFileSize(relativePath: string): Promise<number>;
|
|
48
|
+
}
|
|
49
|
+
export declare class LocalFileStorage implements FileStorageProvider {
|
|
50
|
+
private rootPath;
|
|
51
|
+
constructor(rootPath: string);
|
|
52
|
+
listFiles(): Promise<string[]>;
|
|
53
|
+
private walkDir;
|
|
54
|
+
readFile(relativePath: string): Promise<string>;
|
|
55
|
+
getFileSize(relativePath: string): Promise<number>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* S3FileStorage uses the AWS SDK v3 via dynamic import.
|
|
59
|
+
* If @aws-sdk/client-s3 is not installed, it throws a clear error.
|
|
60
|
+
*
|
|
61
|
+
* Supports:
|
|
62
|
+
* - AWS S3
|
|
63
|
+
* - MinIO (set endpoint to MinIO URL)
|
|
64
|
+
* - LocalStack (set endpoint to LocalStack URL, typically http://localhost:4566)
|
|
65
|
+
* - DigitalOcean Spaces, Backblaze B2, and other S3-compatible services
|
|
66
|
+
*
|
|
67
|
+
* Credential resolution order:
|
|
68
|
+
* 1. Explicit credentials in FileStorageConfig.credentials
|
|
69
|
+
* 2. Environment variables: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN
|
|
70
|
+
* 3. AWS SDK default credential chain (IAM role, ~/.aws/credentials, ECS task role, etc.)
|
|
71
|
+
*/
|
|
72
|
+
export declare class S3FileStorage implements FileStorageProvider {
|
|
73
|
+
private bucket;
|
|
74
|
+
private prefix;
|
|
75
|
+
private region;
|
|
76
|
+
private credentials?;
|
|
77
|
+
private endpoint?;
|
|
78
|
+
private forcePathStyle;
|
|
79
|
+
private s3Client;
|
|
80
|
+
constructor(config: FileStorageConfig);
|
|
81
|
+
/**
|
|
82
|
+
* Returns the credential source being used for debugging/logging.
|
|
83
|
+
*/
|
|
84
|
+
getCredentialSource(): string;
|
|
85
|
+
private getClient;
|
|
86
|
+
private buildKey;
|
|
87
|
+
listFiles(): Promise<string[]>;
|
|
88
|
+
readFile(relativePath: string): Promise<string>;
|
|
89
|
+
getFileSize(relativePath: string): Promise<number>;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* FileContextBuilder reads files from a storage provider, applies filters,
|
|
93
|
+
* and builds a structured context string for LLM consumption.
|
|
94
|
+
*/
|
|
95
|
+
export declare class FileContextBuilder {
|
|
96
|
+
private provider;
|
|
97
|
+
private config;
|
|
98
|
+
constructor(config: FileStorageConfig);
|
|
99
|
+
private createProvider;
|
|
100
|
+
/**
|
|
101
|
+
* Build a structured context string from all matching files.
|
|
102
|
+
* Files are formatted with clear delimiters so the LLM can reference them.
|
|
103
|
+
*/
|
|
104
|
+
buildContext(): Promise<FileStorageResult>;
|
|
105
|
+
/**
|
|
106
|
+
* Build a file tree overview for the LLM to understand the folder structure.
|
|
107
|
+
*/
|
|
108
|
+
private buildFileTree;
|
|
109
|
+
/**
|
|
110
|
+
* Format a single file's content with clear delimiters.
|
|
111
|
+
*/
|
|
112
|
+
private formatFileBlock;
|
|
113
|
+
/**
|
|
114
|
+
* Get just the list of files without reading content.
|
|
115
|
+
* Useful for previewing what would be included.
|
|
116
|
+
*/
|
|
117
|
+
listMatchingFiles(): Promise<string[]>;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Convenience function to build context from a file storage config.
|
|
121
|
+
*/
|
|
122
|
+
export declare function buildFileContext(config: FileStorageConfig): Promise<FileStorageResult>;
|