@cloudwarriors-ai/rlm 0.1.5

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 (220) hide show
  1. package/README.md +208 -0
  2. package/dist/application/index.d.ts +4 -0
  3. package/dist/application/index.d.ts.map +1 -0
  4. package/dist/application/index.js +4 -0
  5. package/dist/application/index.js.map +1 -0
  6. package/dist/application/query-handler.d.ts +49 -0
  7. package/dist/application/query-handler.d.ts.map +1 -0
  8. package/dist/application/query-handler.js +311 -0
  9. package/dist/application/query-handler.js.map +1 -0
  10. package/dist/application/rlm-service.d.ts +68 -0
  11. package/dist/application/rlm-service.d.ts.map +1 -0
  12. package/dist/application/rlm-service.js +132 -0
  13. package/dist/application/rlm-service.js.map +1 -0
  14. package/dist/application/session-manager.d.ts +70 -0
  15. package/dist/application/session-manager.d.ts.map +1 -0
  16. package/dist/application/session-manager.js +237 -0
  17. package/dist/application/session-manager.js.map +1 -0
  18. package/dist/cli/commands/config.d.ts +34 -0
  19. package/dist/cli/commands/config.d.ts.map +1 -0
  20. package/dist/cli/commands/config.js +157 -0
  21. package/dist/cli/commands/config.js.map +1 -0
  22. package/dist/cli/commands/index.d.ts +4 -0
  23. package/dist/cli/commands/index.d.ts.map +1 -0
  24. package/dist/cli/commands/index.js +4 -0
  25. package/dist/cli/commands/index.js.map +1 -0
  26. package/dist/cli/commands/query.d.ts +26 -0
  27. package/dist/cli/commands/query.d.ts.map +1 -0
  28. package/dist/cli/commands/query.js +90 -0
  29. package/dist/cli/commands/query.js.map +1 -0
  30. package/dist/cli/commands/session.d.ts +40 -0
  31. package/dist/cli/commands/session.d.ts.map +1 -0
  32. package/dist/cli/commands/session.js +55 -0
  33. package/dist/cli/commands/session.js.map +1 -0
  34. package/dist/cli/config-loader.d.ts +63 -0
  35. package/dist/cli/config-loader.d.ts.map +1 -0
  36. package/dist/cli/config-loader.js +94 -0
  37. package/dist/cli/config-loader.js.map +1 -0
  38. package/dist/cli/index.d.ts +3 -0
  39. package/dist/cli/index.d.ts.map +1 -0
  40. package/dist/cli/index.js +120 -0
  41. package/dist/cli/index.js.map +1 -0
  42. package/dist/cli/output/formatter.d.ts +24 -0
  43. package/dist/cli/output/formatter.d.ts.map +1 -0
  44. package/dist/cli/output/formatter.js +196 -0
  45. package/dist/cli/output/formatter.js.map +1 -0
  46. package/dist/cli/output/index.d.ts +3 -0
  47. package/dist/cli/output/index.d.ts.map +1 -0
  48. package/dist/cli/output/index.js +3 -0
  49. package/dist/cli/output/index.js.map +1 -0
  50. package/dist/cli/output/progress.d.ts +60 -0
  51. package/dist/cli/output/progress.d.ts.map +1 -0
  52. package/dist/cli/output/progress.js +142 -0
  53. package/dist/cli/output/progress.js.map +1 -0
  54. package/dist/domain/errors/base-error.d.ts +17 -0
  55. package/dist/domain/errors/base-error.d.ts.map +1 -0
  56. package/dist/domain/errors/base-error.js +29 -0
  57. package/dist/domain/errors/base-error.js.map +1 -0
  58. package/dist/domain/errors/execution-error.d.ts +61 -0
  59. package/dist/domain/errors/execution-error.d.ts.map +1 -0
  60. package/dist/domain/errors/execution-error.js +86 -0
  61. package/dist/domain/errors/execution-error.js.map +1 -0
  62. package/dist/domain/errors/index.d.ts +14 -0
  63. package/dist/domain/errors/index.d.ts.map +1 -0
  64. package/dist/domain/errors/index.js +26 -0
  65. package/dist/domain/errors/index.js.map +1 -0
  66. package/dist/domain/errors/limit-exceeded.d.ts +38 -0
  67. package/dist/domain/errors/limit-exceeded.d.ts.map +1 -0
  68. package/dist/domain/errors/limit-exceeded.js +71 -0
  69. package/dist/domain/errors/limit-exceeded.js.map +1 -0
  70. package/dist/domain/errors/llm-error.d.ts +60 -0
  71. package/dist/domain/errors/llm-error.d.ts.map +1 -0
  72. package/dist/domain/errors/llm-error.js +92 -0
  73. package/dist/domain/errors/llm-error.js.map +1 -0
  74. package/dist/domain/errors/validation-error.d.ts +58 -0
  75. package/dist/domain/errors/validation-error.d.ts.map +1 -0
  76. package/dist/domain/errors/validation-error.js +81 -0
  77. package/dist/domain/errors/validation-error.js.map +1 -0
  78. package/dist/domain/interfaces/code-executor.d.ts +98 -0
  79. package/dist/domain/interfaces/code-executor.d.ts.map +1 -0
  80. package/dist/domain/interfaces/code-executor.js +2 -0
  81. package/dist/domain/interfaces/code-executor.js.map +1 -0
  82. package/dist/domain/interfaces/event-emitter.d.ts +137 -0
  83. package/dist/domain/interfaces/event-emitter.d.ts.map +1 -0
  84. package/dist/domain/interfaces/event-emitter.js +2 -0
  85. package/dist/domain/interfaces/event-emitter.js.map +1 -0
  86. package/dist/domain/interfaces/index.d.ts +5 -0
  87. package/dist/domain/interfaces/index.d.ts.map +1 -0
  88. package/dist/domain/interfaces/index.js +2 -0
  89. package/dist/domain/interfaces/index.js.map +1 -0
  90. package/dist/domain/interfaces/llm-provider.d.ts +64 -0
  91. package/dist/domain/interfaces/llm-provider.d.ts.map +1 -0
  92. package/dist/domain/interfaces/llm-provider.js +2 -0
  93. package/dist/domain/interfaces/llm-provider.js.map +1 -0
  94. package/dist/domain/interfaces/session-store.d.ts +65 -0
  95. package/dist/domain/interfaces/session-store.d.ts.map +1 -0
  96. package/dist/domain/interfaces/session-store.js +2 -0
  97. package/dist/domain/interfaces/session-store.js.map +1 -0
  98. package/dist/domain/services/context-chunker.d.ts +43 -0
  99. package/dist/domain/services/context-chunker.d.ts.map +1 -0
  100. package/dist/domain/services/context-chunker.js +152 -0
  101. package/dist/domain/services/context-chunker.js.map +1 -0
  102. package/dist/domain/services/cost-calculator.d.ts +63 -0
  103. package/dist/domain/services/cost-calculator.d.ts.map +1 -0
  104. package/dist/domain/services/cost-calculator.js +121 -0
  105. package/dist/domain/services/cost-calculator.js.map +1 -0
  106. package/dist/domain/services/index.d.ts +5 -0
  107. package/dist/domain/services/index.d.ts.map +1 -0
  108. package/dist/domain/services/index.js +9 -0
  109. package/dist/domain/services/index.js.map +1 -0
  110. package/dist/domain/services/limit-checker.d.ts +54 -0
  111. package/dist/domain/services/limit-checker.d.ts.map +1 -0
  112. package/dist/domain/services/limit-checker.js +146 -0
  113. package/dist/domain/services/limit-checker.js.map +1 -0
  114. package/dist/domain/services/result-aggregator.d.ts +49 -0
  115. package/dist/domain/services/result-aggregator.d.ts.map +1 -0
  116. package/dist/domain/services/result-aggregator.js +131 -0
  117. package/dist/domain/services/result-aggregator.js.map +1 -0
  118. package/dist/domain/types/config.d.ts +41 -0
  119. package/dist/domain/types/config.d.ts.map +1 -0
  120. package/dist/domain/types/config.js +22 -0
  121. package/dist/domain/types/config.js.map +1 -0
  122. package/dist/domain/types/context.d.ts +64 -0
  123. package/dist/domain/types/context.d.ts.map +1 -0
  124. package/dist/domain/types/context.js +20 -0
  125. package/dist/domain/types/context.js.map +1 -0
  126. package/dist/domain/types/index.d.ts +5 -0
  127. package/dist/domain/types/index.d.ts.map +1 -0
  128. package/dist/domain/types/index.js +9 -0
  129. package/dist/domain/types/index.js.map +1 -0
  130. package/dist/domain/types/result.d.ts +137 -0
  131. package/dist/domain/types/result.d.ts.map +1 -0
  132. package/dist/domain/types/result.js +27 -0
  133. package/dist/domain/types/result.js.map +1 -0
  134. package/dist/domain/types/session.d.ts +74 -0
  135. package/dist/domain/types/session.d.ts.map +1 -0
  136. package/dist/domain/types/session.js +31 -0
  137. package/dist/domain/types/session.js.map +1 -0
  138. package/dist/factory/create-rlm.d.ts +77 -0
  139. package/dist/factory/create-rlm.d.ts.map +1 -0
  140. package/dist/factory/create-rlm.js +82 -0
  141. package/dist/factory/create-rlm.js.map +1 -0
  142. package/dist/factory/default-config.d.ts +27 -0
  143. package/dist/factory/default-config.d.ts.map +1 -0
  144. package/dist/factory/default-config.js +98 -0
  145. package/dist/factory/default-config.js.map +1 -0
  146. package/dist/factory/index.d.ts +3 -0
  147. package/dist/factory/index.d.ts.map +1 -0
  148. package/dist/factory/index.js +3 -0
  149. package/dist/factory/index.js.map +1 -0
  150. package/dist/index.d.ts +37 -0
  151. package/dist/index.d.ts.map +1 -0
  152. package/dist/index.js +40 -0
  153. package/dist/index.js.map +1 -0
  154. package/dist/infrastructure/events/event-types.d.ts +35 -0
  155. package/dist/infrastructure/events/event-types.d.ts.map +1 -0
  156. package/dist/infrastructure/events/event-types.js +44 -0
  157. package/dist/infrastructure/events/event-types.js.map +1 -0
  158. package/dist/infrastructure/events/index.d.ts +3 -0
  159. package/dist/infrastructure/events/index.d.ts.map +1 -0
  160. package/dist/infrastructure/events/index.js +3 -0
  161. package/dist/infrastructure/events/index.js.map +1 -0
  162. package/dist/infrastructure/events/node-emitter.d.ts +72 -0
  163. package/dist/infrastructure/events/node-emitter.d.ts.map +1 -0
  164. package/dist/infrastructure/events/node-emitter.js +125 -0
  165. package/dist/infrastructure/events/node-emitter.js.map +1 -0
  166. package/dist/infrastructure/llm/index.d.ts +3 -0
  167. package/dist/infrastructure/llm/index.d.ts.map +1 -0
  168. package/dist/infrastructure/llm/index.js +3 -0
  169. package/dist/infrastructure/llm/index.js.map +1 -0
  170. package/dist/infrastructure/llm/openrouter-provider.d.ts +35 -0
  171. package/dist/infrastructure/llm/openrouter-provider.d.ts.map +1 -0
  172. package/dist/infrastructure/llm/openrouter-provider.js +158 -0
  173. package/dist/infrastructure/llm/openrouter-provider.js.map +1 -0
  174. package/dist/infrastructure/llm/prompts/code-gen-prompt.d.ts +21 -0
  175. package/dist/infrastructure/llm/prompts/code-gen-prompt.d.ts.map +1 -0
  176. package/dist/infrastructure/llm/prompts/code-gen-prompt.js +78 -0
  177. package/dist/infrastructure/llm/prompts/code-gen-prompt.js.map +1 -0
  178. package/dist/infrastructure/llm/prompts/error-recovery-prompt.d.ts +24 -0
  179. package/dist/infrastructure/llm/prompts/error-recovery-prompt.d.ts.map +1 -0
  180. package/dist/infrastructure/llm/prompts/error-recovery-prompt.js +70 -0
  181. package/dist/infrastructure/llm/prompts/error-recovery-prompt.js.map +1 -0
  182. package/dist/infrastructure/llm/prompts/index.d.ts +4 -0
  183. package/dist/infrastructure/llm/prompts/index.d.ts.map +1 -0
  184. package/dist/infrastructure/llm/prompts/index.js +4 -0
  185. package/dist/infrastructure/llm/prompts/index.js.map +1 -0
  186. package/dist/infrastructure/llm/prompts/system-prompt.d.ts +12 -0
  187. package/dist/infrastructure/llm/prompts/system-prompt.d.ts.map +1 -0
  188. package/dist/infrastructure/llm/prompts/system-prompt.js +96 -0
  189. package/dist/infrastructure/llm/prompts/system-prompt.js.map +1 -0
  190. package/dist/infrastructure/persistence/index.d.ts +3 -0
  191. package/dist/infrastructure/persistence/index.d.ts.map +1 -0
  192. package/dist/infrastructure/persistence/index.js +3 -0
  193. package/dist/infrastructure/persistence/index.js.map +1 -0
  194. package/dist/infrastructure/persistence/memory-store.d.ts +24 -0
  195. package/dist/infrastructure/persistence/memory-store.d.ts.map +1 -0
  196. package/dist/infrastructure/persistence/memory-store.js +71 -0
  197. package/dist/infrastructure/persistence/memory-store.js.map +1 -0
  198. package/dist/infrastructure/persistence/schema.d.ts +120 -0
  199. package/dist/infrastructure/persistence/schema.d.ts.map +1 -0
  200. package/dist/infrastructure/persistence/schema.js +130 -0
  201. package/dist/infrastructure/persistence/schema.js.map +1 -0
  202. package/dist/infrastructure/sandbox/ast-validator.d.ts +23 -0
  203. package/dist/infrastructure/sandbox/ast-validator.d.ts.map +1 -0
  204. package/dist/infrastructure/sandbox/ast-validator.js +249 -0
  205. package/dist/infrastructure/sandbox/ast-validator.js.map +1 -0
  206. package/dist/infrastructure/sandbox/index.d.ts +4 -0
  207. package/dist/infrastructure/sandbox/index.d.ts.map +1 -0
  208. package/dist/infrastructure/sandbox/index.js +4 -0
  209. package/dist/infrastructure/sandbox/index.js.map +1 -0
  210. package/dist/infrastructure/sandbox/prelude/rlm_prelude.py +376 -0
  211. package/dist/infrastructure/sandbox/process-manager.d.ts +98 -0
  212. package/dist/infrastructure/sandbox/process-manager.d.ts.map +1 -0
  213. package/dist/infrastructure/sandbox/process-manager.js +186 -0
  214. package/dist/infrastructure/sandbox/process-manager.js.map +1 -0
  215. package/dist/infrastructure/sandbox/python-executor.d.ts +29 -0
  216. package/dist/infrastructure/sandbox/python-executor.d.ts.map +1 -0
  217. package/dist/infrastructure/sandbox/python-executor.js +182 -0
  218. package/dist/infrastructure/sandbox/python-executor.js.map +1 -0
  219. package/package.json +65 -0
  220. package/src/infrastructure/sandbox/prelude/rlm_prelude.py +376 -0
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Metadata associated with context content
3
+ */
4
+ export interface ContextMetadata {
5
+ /** Source type: file, string, url, etc. */
6
+ readonly source: ContextSource;
7
+ /** Original source path/url if applicable */
8
+ readonly sourcePath?: string;
9
+ /** MIME type if known */
10
+ readonly mimeType?: string;
11
+ /** Size in bytes */
12
+ readonly sizeBytes: number;
13
+ /** Estimated token count */
14
+ readonly estimatedTokens: number;
15
+ /** Timestamp when context was created */
16
+ readonly createdAt: Date;
17
+ }
18
+ export type ContextSource = 'file' | 'string' | 'url' | 'stdin' | 'variable';
19
+ /**
20
+ * A named context variable available in the Python REPL
21
+ */
22
+ export interface ContextVariable {
23
+ /** Variable name (valid Python identifier) */
24
+ readonly name: string;
25
+ /** The actual content */
26
+ readonly content: string;
27
+ /** Metadata about the content */
28
+ readonly metadata: ContextMetadata;
29
+ }
30
+ /**
31
+ * Input for creating context - more flexible than ContextVariable
32
+ */
33
+ export interface ContextInput {
34
+ /** The content to process */
35
+ readonly content: string;
36
+ /** Optional name (defaults to 'context') */
37
+ readonly name?: string;
38
+ /** Optional source info */
39
+ readonly source?: ContextSource;
40
+ /** Optional source path */
41
+ readonly sourcePath?: string;
42
+ }
43
+ /**
44
+ * A chunk of context for processing
45
+ */
46
+ export interface ContextChunk {
47
+ /** Chunk index (0-based) */
48
+ readonly index: number;
49
+ /** Total number of chunks */
50
+ readonly total: number;
51
+ /** The chunk content */
52
+ readonly content: string;
53
+ /** Start offset in original content */
54
+ readonly startOffset: number;
55
+ /** End offset in original content */
56
+ readonly endOffset: number;
57
+ /** Estimated tokens in this chunk */
58
+ readonly estimatedTokens: number;
59
+ }
60
+ /**
61
+ * Create a context variable from input
62
+ */
63
+ export declare function createContextVariable(input: ContextInput, tokenEstimator: (text: string) => number): ContextVariable;
64
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/domain/types/context.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,2CAA2C;IAC3C,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAE/B,6CAA6C;IAC7C,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAE7B,yBAAyB;IACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAE3B,oBAAoB;IACpB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,4BAA4B;IAC5B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IAEjC,yCAAyC;IACzC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;CAC1B;AAED,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,GAAG,OAAO,GAAG,UAAU,CAAC;AAE7E;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,8CAA8C;IAC9C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,yBAAyB;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,iCAAiC;IACjC,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,6BAA6B;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,4CAA4C;IAC5C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAEvB,2BAA2B;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,aAAa,CAAC;IAEhC,2BAA2B;IAC3B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,4BAA4B;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB,6BAA6B;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB,wBAAwB;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,uCAAuC;IACvC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAE7B,qCAAqC;IACrC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,qCAAqC;IACrC,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;CAClC;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,YAAY,EACnB,cAAc,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GACvC,eAAe,CAgBjB"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Create a context variable from input
3
+ */
4
+ export function createContextVariable(input, tokenEstimator) {
5
+ const name = input.name ?? 'context';
6
+ const content = input.content;
7
+ const estimatedTokens = tokenEstimator(content);
8
+ return {
9
+ name,
10
+ content,
11
+ metadata: {
12
+ source: input.source ?? 'string',
13
+ sourcePath: input.sourcePath,
14
+ sizeBytes: Buffer.byteLength(content, 'utf-8'),
15
+ estimatedTokens,
16
+ createdAt: new Date(),
17
+ },
18
+ };
19
+ }
20
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/domain/types/context.ts"],"names":[],"mappings":"AA+EA;;GAEG;AACH,MAAM,UAAU,qBAAqB,CACnC,KAAmB,EACnB,cAAwC;IAExC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,IAAI,SAAS,CAAC;IACrC,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;IAC9B,MAAM,eAAe,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;IAEhD,OAAO;QACL,IAAI;QACJ,OAAO;QACP,QAAQ,EAAE;YACR,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,QAAQ;YAChC,UAAU,EAAE,KAAK,CAAC,UAAU;YAC5B,SAAS,EAAE,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC;YAC9C,eAAe;YACf,SAAS,EAAE,IAAI,IAAI,EAAE;SACtB;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { type RLMConfig, type RLMConfigInput, type SandboxMode, DEFAULT_CONFIG, createConfig, } from './config.js';
2
+ export { type ContextMetadata, type ContextSource, type ContextVariable, type ContextInput, type ContextChunk, createContextVariable, } from './context.js';
3
+ export { type TokenUsage, type ResourceUsage, type ExecutionStep, type ExecutionStepType, type ExecutionStepDetails, type LLMCallDetails, type CodeGenerationDetails, type CodeExecutionDetails, type RecursiveCallDetails, type ResultAggregationDetails, type ExecutionTrace, type RecoveredError, type RecursiveCallResult, type RLMResult, createEmptyUsage, mergeUsage, } from './result.js';
4
+ export { type SessionStatus, type RLMSession, type SessionState, createSessionState, stateToUsage, } from './session.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/domain/types/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,cAAc,EACd,YAAY,GACb,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,qBAAqB,GACtB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,wBAAwB,EAC7B,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,SAAS,EACd,gBAAgB,EAChB,UAAU,GACX,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,kBAAkB,EAClB,YAAY,GACb,MAAM,cAAc,CAAC"}
@@ -0,0 +1,9 @@
1
+ // Configuration types
2
+ export { DEFAULT_CONFIG, createConfig, } from './config.js';
3
+ // Context types
4
+ export { createContextVariable, } from './context.js';
5
+ // Result types
6
+ export { createEmptyUsage, mergeUsage, } from './result.js';
7
+ // Session types
8
+ export { createSessionState, stateToUsage, } from './session.js';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/domain/types/index.ts"],"names":[],"mappings":"AAAA,sBAAsB;AACtB,OAAO,EAIL,cAAc,EACd,YAAY,GACb,MAAM,aAAa,CAAC;AAErB,gBAAgB;AAChB,OAAO,EAML,qBAAqB,GACtB,MAAM,cAAc,CAAC;AAEtB,eAAe;AACf,OAAO,EAeL,gBAAgB,EAChB,UAAU,GACX,MAAM,aAAa,CAAC;AAErB,gBAAgB;AAChB,OAAO,EAIL,kBAAkB,EAClB,YAAY,GACb,MAAM,cAAc,CAAC"}
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Token usage statistics
3
+ */
4
+ export interface TokenUsage {
5
+ /** Input tokens (prompt) */
6
+ readonly promptTokens: number;
7
+ /** Output tokens (completion) */
8
+ readonly completionTokens: number;
9
+ /** Total tokens */
10
+ readonly totalTokens: number;
11
+ }
12
+ /**
13
+ * Resource usage for a session
14
+ */
15
+ export interface ResourceUsage {
16
+ /** Total tokens used across all calls */
17
+ readonly totalTokens: number;
18
+ /** Cost in USD */
19
+ readonly costUsd: number;
20
+ /** Number of LLM calls made */
21
+ readonly llmCalls: number;
22
+ /** Number of recursive calls */
23
+ readonly recursiveCalls: number;
24
+ /** Maximum recursion depth reached */
25
+ readonly maxDepthReached: number;
26
+ /** Total execution time in milliseconds */
27
+ readonly executionTimeMs: number;
28
+ }
29
+ /**
30
+ * A single step in the execution trace
31
+ */
32
+ export interface ExecutionStep {
33
+ /** Step index */
34
+ readonly index: number;
35
+ /** Recursion depth at this step */
36
+ readonly depth: number;
37
+ /** Type of step */
38
+ readonly type: ExecutionStepType;
39
+ /** Timestamp when step started */
40
+ readonly startedAt: Date;
41
+ /** Timestamp when step completed */
42
+ readonly completedAt: Date;
43
+ /** Duration in milliseconds */
44
+ readonly durationMs: number;
45
+ /** Details specific to step type */
46
+ readonly details: ExecutionStepDetails;
47
+ }
48
+ export type ExecutionStepType = 'llm_call' | 'code_generation' | 'code_execution' | 'recursive_call' | 'result_aggregation';
49
+ export type ExecutionStepDetails = LLMCallDetails | CodeGenerationDetails | CodeExecutionDetails | RecursiveCallDetails | ResultAggregationDetails;
50
+ export interface LLMCallDetails {
51
+ readonly type: 'llm_call';
52
+ readonly model: string;
53
+ readonly promptTokens: number;
54
+ readonly completionTokens: number;
55
+ readonly cost: number;
56
+ }
57
+ export interface CodeGenerationDetails {
58
+ readonly type: 'code_generation';
59
+ readonly codeLength: number;
60
+ readonly codePreview: string;
61
+ }
62
+ export interface CodeExecutionDetails {
63
+ readonly type: 'code_execution';
64
+ readonly success: boolean;
65
+ readonly output?: string;
66
+ readonly error?: string;
67
+ }
68
+ export interface RecursiveCallDetails {
69
+ readonly type: 'recursive_call';
70
+ readonly query: string;
71
+ readonly contextSize: number;
72
+ readonly depth: number;
73
+ }
74
+ export interface ResultAggregationDetails {
75
+ readonly type: 'result_aggregation';
76
+ readonly resultCount: number;
77
+ readonly combinedLength: number;
78
+ }
79
+ /**
80
+ * Execution trace for debugging and analysis
81
+ */
82
+ export interface ExecutionTrace {
83
+ /** All execution steps */
84
+ readonly steps: readonly ExecutionStep[];
85
+ /** Any warnings during execution */
86
+ readonly warnings: readonly string[];
87
+ /** Any errors that were recovered from */
88
+ readonly recoveredErrors: readonly RecoveredError[];
89
+ }
90
+ export interface RecoveredError {
91
+ readonly stepIndex: number;
92
+ readonly error: string;
93
+ readonly recovery: string;
94
+ }
95
+ /**
96
+ * Result of a single recursive call
97
+ */
98
+ export interface RecursiveCallResult {
99
+ /** The query that was executed */
100
+ readonly query: string;
101
+ /** The answer/result */
102
+ readonly answer: string;
103
+ /** Depth at which this call was made */
104
+ readonly depth: number;
105
+ /** Token usage for this call */
106
+ readonly usage: TokenUsage;
107
+ /** Child call results */
108
+ readonly children: readonly RecursiveCallResult[];
109
+ }
110
+ /**
111
+ * Final result of an RLM query
112
+ */
113
+ export interface RLMResult {
114
+ /** Session ID */
115
+ readonly sessionId: string;
116
+ /** The final answer */
117
+ readonly answer: string;
118
+ /** Whether the query completed successfully */
119
+ readonly success: boolean;
120
+ /** Error message if not successful */
121
+ readonly error?: string;
122
+ /** Full execution trace */
123
+ readonly trace: ExecutionTrace;
124
+ /** Resource usage statistics */
125
+ readonly usage: ResourceUsage;
126
+ /** Timestamp when completed */
127
+ readonly completedAt: Date;
128
+ }
129
+ /**
130
+ * Create an empty resource usage object
131
+ */
132
+ export declare function createEmptyUsage(): ResourceUsage;
133
+ /**
134
+ * Merge two resource usage objects
135
+ */
136
+ export declare function mergeUsage(a: ResourceUsage, b: ResourceUsage): ResourceUsage;
137
+ //# sourceMappingURL=result.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../../src/domain/types/result.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,4BAA4B;IAC5B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAE9B,iCAAiC;IACjC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAElC,mBAAmB;IACnB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,yCAAyC;IACzC,Q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,mBAAmB;IAClC,kCAAkC;IAClC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB,wBAAwB;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,wCAAwC;IACxC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB,gCAAgC;IAChC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAE3B,yBAAyB;IACzB,QAAQ,CAAC,QAAQ,EAAE,SAAS,mBAAmB,EAAE,CAAC;CACnD;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,iBAAiB;IACjB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,uBAAuB;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,+CAA+C;IAC/C,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAE1B,sCAAsC;IACtC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAExB,2BAA2B;IAC3B,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAE/B,gCAAgC;IAChC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAE9B,+BAA+B;IAC/B,QAAQ,CAAC,WAAW,EAAE,IAAI,CAAC;CAC5B;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,aAAa,CAShD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,EAAE,aAAa,GAAG,aAAa,CAS5E"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Create an empty resource usage object
3
+ */
4
+ export function createEmptyUsage() {
5
+ return {
6
+ totalTokens: 0,
7
+ costUsd: 0,
8
+ llmCalls: 0,
9
+ recursiveCalls: 0,
10
+ maxDepthReached: 0,
11
+ executionTimeMs: 0,
12
+ };
13
+ }
14
+ /**
15
+ * Merge two resource usage objects
16
+ */
17
+ export function mergeUsage(a, b) {
18
+ return {
19
+ totalTokens: a.totalTokens + b.totalTokens,
20
+ costUsd: a.costUsd + b.costUsd,
21
+ llmCalls: a.llmCalls + b.llmCalls,
22
+ recursiveCalls: a.recursiveCalls + b.recursiveCalls,
23
+ maxDepthReached: Math.max(a.maxDepthReached, b.maxDepthReached),
24
+ executionTimeMs: a.executionTimeMs + b.executionTimeMs,
25
+ };
26
+ }
27
+ //# sourceMappingURL=result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.js","sourceRoot":"","sources":["../../../src/domain/types/result.ts"],"names":[],"mappings":"AAiLA;;GAEG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO;QACL,WAAW,EAAE,CAAC;QACd,OAAO,EAAE,CAAC;QACV,QAAQ,EAAE,CAAC;QACX,cAAc,EAAE,CAAC;QACjB,eAAe,EAAE,CAAC;QAClB,eAAe,EAAE,CAAC;KACnB,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,CAAgB,EAAE,CAAgB;IAC3D,OAAO;QACL,WAAW,EAAE,CAAC,CAAC,WAAW,GAAG,CAAC,CAAC,WAAW;QAC1C,OAAO,EAAE,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO;QAC9B,QAAQ,EAAE,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ;QACjC,cAAc,EAAE,CAAC,CAAC,cAAc,GAAG,CAAC,CAAC,cAAc;QACnD,eAAe,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC,CAAC,eAAe,CAAC;QAC/D,eAAe,EAAE,CAAC,CAAC,eAAe,GAAG,CAAC,CAAC,eAAe;KACvD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,74 @@
1
+ import type { RLMConfig } from './config.js';
2
+ import type { ContextVariable } from './context.js';
3
+ import type { ResourceUsage, ExecutionTrace, RLMResult } from './result.js';
4
+ /**
5
+ * Status of an RLM session
6
+ */
7
+ export type SessionStatus = 'pending' | 'running' | 'completed' | 'failed' | 'cancelled' | 'timeout';
8
+ /**
9
+ * An RLM session representing a complete query execution
10
+ */
11
+ export interface RLMSession {
12
+ /** Unique session ID */
13
+ readonly id: string;
14
+ /** The original query */
15
+ readonly query: string;
16
+ /** Initial context variables */
17
+ readonly context: readonly ContextVariable[];
18
+ /** Configuration for this session */
19
+ readonly config: RLMConfig;
20
+ /** Current status */
21
+ readonly status: SessionStatus;
22
+ /** Current recursion depth */
23
+ readonly currentDepth: number;
24
+ /** Running resource usage */
25
+ readonly usage: ResourceUsage;
26
+ /** Execution trace so far */
27
+ readonly trace: ExecutionTrace;
28
+ /** Timestamp when session was created */
29
+ readonly createdAt: Date;
30
+ /** Timestamp when session started executing */
31
+ readonly startedAt?: Date;
32
+ /** Timestamp when session completed */
33
+ readonly completedAt?: Date;
34
+ /** Final result if completed */
35
+ readonly result?: RLMResult;
36
+ /** Error message if failed */
37
+ readonly error?: string;
38
+ /** Cancellation requested */
39
+ readonly cancellationRequested: boolean;
40
+ }
41
+ /**
42
+ * Mutable session state for internal tracking during execution
43
+ */
44
+ export interface SessionState {
45
+ /** Session ID */
46
+ sessionId: string;
47
+ /** Current depth */
48
+ currentDepth: number;
49
+ /** Accumulated tokens */
50
+ totalTokens: number;
51
+ /** Accumulated cost */
52
+ totalCostUsd: number;
53
+ /** Number of LLM calls */
54
+ llmCalls: number;
55
+ /** Number of recursive calls */
56
+ recursiveCalls: number;
57
+ /** Maximum depth reached */
58
+ maxDepthReached: number;
59
+ /** Start time */
60
+ startTime: number;
61
+ /** Whether cancellation has been requested */
62
+ cancellationRequested: boolean;
63
+ /** Python variables currently in scope */
64
+ pythonVariables: Map<string, string>;
65
+ }
66
+ /**
67
+ * Create initial session state
68
+ */
69
+ export declare function createSessionState(sessionId: string): SessionState;
70
+ /**
71
+ * Convert session state to resource usage
72
+ */
73
+ export declare function stateToUsage(state: SessionState): ResourceUsage;
74
+ //# sourceMappingURL=session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.d.ts","sourceRo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,OAAO,CAAC;CACzC;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,iBAAiB;IACjB,SAAS,EAAE,MAAM,CAAC;IAElB,oBAAoB;IACpB,YAAY,EAAE,MAAM,CAAC;IAErB,yBAAyB;IACzB,WAAW,EAAE,MAAM,CAAC;IAEpB,uBAAuB;IACvB,YAAY,EAAE,MAAM,CAAC;IAErB,0BAA0B;IAC1B,QAAQ,EAAE,MAAM,CAAC;IAEjB,gCAAgC;IAChC,cAAc,EAAE,MAAM,CAAC;IAEvB,4BAA4B;IAC5B,eAAe,EAAE,MAAM,CAAC;IAExB,iBAAiB;IACjB,SAAS,EAAE,MAAM,CAAC;IAElB,8CAA8C;IAC9C,qBAAqB,EAAE,OAAO,CAAC;IAE/B,0CAA0C;IAC1C,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,YAAY,CAalE;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,YAAY,GAAG,aAAa,CAS/D"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Create initial session state
3
+ */
4
+ export function createSessionState(sessionId) {
5
+ return {
6
+ sessionId,
7
+ currentDepth: 0,
8
+ totalTokens: 0,
9
+ totalCostUsd: 0,
10
+ llmCalls: 0,
11
+ recursiveCalls: 0,
12
+ maxDepthReached: 0,
13
+ startTime: Date.now(),
14
+ cancellationRequested: false,
15
+ pythonVariables: new Map(),
16
+ };
17
+ }
18
+ /**
19
+ * Convert session state to resource usage
20
+ */
21
+ export function stateToUsage(state) {
22
+ return {
23
+ totalTokens: state.totalTokens,
24
+ costUsd: state.totalCostUsd,
25
+ llmCalls: state.llmCalls,
26
+ recursiveCalls: state.recursiveCalls,
27
+ maxDepthReached: state.maxDepthReached,
28
+ executionTimeMs: Date.now() - state.startTime,
29
+ };
30
+ }
31
+ //# sourceMappingURL=session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/domain/types/session.ts"],"names":[],"mappings":"AAiGA;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,SAAiB;IAClD,OAAO;QACL,SAAS;QACT,YAAY,EAAE,CAAC;QACf,WAAW,EAAE,CAAC;QACd,YAAY,EAAE,CAAC;QACf,QAAQ,EAAE,CAAC;QACX,cAAc,EAAE,CAAC;QACjB,eAAe,EAAE,CAAC;QAClB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;QACrB,qBAAqB,EAAE,KAAK;QAC5B,eAAe,EAAE,IAAI,GAAG,EAAE;KAC3B,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,KAAmB;IAC9C,OAAO;QACL,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,OAAO,EAAE,KAAK,CAAC,YAAY;QAC3B,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,eAAe,EAAE,KAAK,CAAC,eAAe;QACtC,eAAe,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,SAAS;KAC9C,CAAC;AACJ,CAAC"}
@@ -0,0 +1,77 @@
1
+ import type { EventEmitter } from 'node:events';
2
+ import type { RLMConfigInput } from '../domain/types/config.js';
3
+ import type { ISessionStore } from '../domain/interfaces/session-store.js';
4
+ import type { IEventEmitter } from '../domain/interfaces/event-emitter.js';
5
+ import { RLMService } from '../application/rlm-service.js';
6
+ /**
7
+ * Options for creating an RLM instance
8
+ */
9
+ export interface CreateRLMOptions {
10
+ /**
11
+ * OpenRouter API key
12
+ * If not provided, will look for OPENROUTER_API_KEY environment variable
13
+ */
14
+ readonly apiKey?: string;
15
+ /**
16
+ * LLM model to use
17
+ * @default 'anthropic/claude-sonnet-4'
18
+ */
19
+ readonly model?: string;
20
+ /**
21
+ * Configuration overrides
22
+ */
23
+ readonly config?: RLMConfigInput;
24
+ /**
25
+ * Custom session store
26
+ * If not provided, uses in-memory store
27
+ */
28
+ readonly sessionStore?: ISessionStore;
29
+ /**
30
+ * Custom event emitter
31
+ * If not provided, uses a no-op emitter
32
+ */
33
+ readonly eventEmitter?: IEventEmitter;
34
+ /**
35
+ * External Node.js EventEmitter to use for events
36
+ * Alternative to providing a custom IEventEmitter
37
+ */
38
+ readonly eventBus?: EventEmitter;
39
+ /**
40
+ * Whether to include environment variables in config resolution
41
+ * @default true
42
+ */
43
+ readonly includeEnv?: boolean;
44
+ /**
45
+ * Site URL for OpenRouter analytics
46
+ */
47
+ readonly siteUrl?: string;
48
+ /**
49
+ * Site name for OpenRouter analytics
50
+ */
51
+ readonly siteName?: string;
52
+ }
53
+ /**
54
+ * Create an RLM service instance
55
+ *
56
+ * This is the main entry point for using RLM.
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * import { createRLM } from '@cloudwarriors-ai/rlm';
61
+ *
62
+ * const rlm = createRLM({
63
+ * apiKey: process.env.OPENROUTER_API_KEY,
64
+ * model: 'anthropic/claude-sonnet-4',
65
+ * });
66
+ *
67
+ * const result = await rlm.query(
68
+ * fs.readFileSync('./large-file.txt', 'utf-8'),
69
+ * 'Summarize the main points'
70
+ * );
71
+ *
72
+ * console.log(result.answer);
73
+ * console.log(`Cost: $${result.usage.costUsd.toFixed(4)}`);
74
+ * ```
75
+ */
76
+ export declare function createRLM(options?: CreateRLMOptions): RLMService;
77
+ //# sourceMappingURL=create-rlm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-rlm.d.ts","sourceRoot":"","sources":["../../src/factory/create-rlm.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAQ3D;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,cAAc,CAAC;IAEjC;;;OAGG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,aAAa,CAAC;IAEtC;;;OAGG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,aAAa,CAAC;IAEtC;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,YAAY,CAAC;IAEjC;;;OAGG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAE9B;;OAEG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAE1B;;OAEG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,SAAS,CAAC,OAAO,GAAE,gBAAqB,GAAG,UAAU,CA4DpE"}
@@ -0,0 +1,82 @@
1
+ import { RLMService } from '../application/rlm-service.js';
2
+ import { OpenRouterProvider } from '../infrastructure/llm/openrouter-provider.js';
3
+ import { PythonExecutor } from '../infrastructure/sandbox/python-executor.js';
4
+ import { MemorySessionStore } from '../infrastructure/persistence/memory-store.js';
5
+ import { NodeEventEmitter, NoopEventEmitter } from '../infrastructure/events/node-emitter.js';
6
+ import { resolveConfig, validateConfig, ENV_VARS } from './default-config.js';
7
+ import { ConfigurationError } from '../domain/errors/index.js';
8
+ /**
9
+ * Create an RLM service instance
10
+ *
11
+ * This is the main entry point for using RLM.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import { createRLM } from '@cloudwarriors-ai/rlm';
16
+ *
17
+ * const rlm = createRLM({
18
+ * apiKey: process.env.OPENROUTER_API_KEY,
19
+ * model: 'anthropic/claude-sonnet-4',
20
+ * });
21
+ *
22
+ * const result = await rlm.query(
23
+ * fs.readFileSync('./large-file.txt', 'utf-8'),
24
+ * 'Summarize the main points'
25
+ * );
26
+ *
27
+ * console.log(result.answer);
28
+ * console.log(`Cost: $${result.usage.costUsd.toFixed(4)}`);
29
+ * ```
30
+ */
31
+ export function createRLM(options = {}) {
32
+ // Resolve API key
33
+ const apiKey = options.apiKey ?? process.env[ENV_VARS.OPENROUTER_API_KEY];
34
+ if (!apiKey) {
35
+ throw new ConfigurationError('OpenRouter API key is required. Set OPENROUTER_API_KEY environment variable or pass apiKey option.', 'apiKey');
36
+ }
37
+ // Resolve config
38
+ const includeEnv = options.includeEnv ?? true;
39
+ const userConfig = {
40
+ ...options.config,
41
+ model: options.model ?? options.config?.model,
42
+ };
43
+ const config = resolveConfig(userConfig, includeEnv);
44
+ // Validate config
45
+ const configErrors = validateConfig(config);
46
+ if (configErrors.length > 0) {
47
+ throw new ConfigurationError(`Invalid configuration: ${configErrors.join(', ')}`);
48
+ }
49
+ // Create LLM provider
50
+ const llmProvider = new OpenRouterProvider({
51
+ apiKey,
52
+ model: config.model,
53
+ siteUrl: options.siteUrl,
54
+ siteName: options.siteName ?? 'RLM',
55
+ });
56
+ // Create code executor
57
+ const codeExecutor = new PythonExecutor({
58
+ strictMode: config.sandboxMode === 'strict',
59
+ });
60
+ // Resolve session store
61
+ const sessionStore = options.sessionStore ?? new MemorySessionStore();
62
+ // Resolve event emitter
63
+ let eventEmitter;
64
+ if (options.eventEmitter) {
65
+ eventEmitter = options.eventEmitter;
66
+ }
67
+ else if (options.eventBus) {
68
+ eventEmitter = new NodeEventEmitter(options.eventBus);
69
+ }
70
+ else {
71
+ eventEmitter = new NoopEventEmitter();
72
+ }
73
+ // Create and return service
74
+ return new RLMService({
75
+ llmProvider,
76
+ codeExecutor,
77
+ sessionStore,
78
+ eventEmitter,
79
+ config,
80
+ });
81
+ }
82
+ //# sourceMappingURL=create-rlm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-rlm.js","sourceRoot":"","sources":["../../src/factory/create-rlm.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,8CAA8C,CAAC;AAClF,OAAO,EAAE,cAAc,EAAE,MAAM,8CAA8C,CAAC;AAC9E,OAAO,EAAE,kBAAkB,EAAE,MAAM,+CAA+C,CAAC;AACnF,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAC9F,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AA0D/D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,SAAS,CAAC,UAA4B,EAAE;IACtD,kBAAkB;IAClB,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC;IAC1E,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,kBAAkB,CAC1B,oGAAoG,EACpG,QAAQ,CACT,CAAC;IACJ,CAAC;IAED,iBAAiB;IACjB,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,IAAI,CAAC;IAC9C,MAAM,UAAU,GAAmB;QACjC,GAAG,OAAO,CAAC,MAAM;QACjB,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,MAAM,EAAE,KAAK;KAC9C,CAAC;IACF,MAAM,MAAM,GAAG,aAAa,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAErD,kBAAkB;IAClB,MAAM,YAAY,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;IAC5C,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,kBAAkB,CAC1B,0BAA0B,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACpD,CAAC;IACJ,CAAC;IAED,sBAAsB;IACtB,MAAM,WAAW,GAAG,IAAI,kBAAkB,CAAC;QACzC,MAAM;QACN,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,KAAK;KACpC,CAAC,CAAC;IAEH,uBAAuB;IACvB,MAAM,YAAY,GAAG,IAAI,cAAc,CAAC;QACtC,UAAU,EAAE,MAAM,CAAC,WAAW,KAAK,QAAQ;KAC5C,CAAC,CAAC;IAEH,wBAAwB;IACxB,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,IAAI,kBAAkB,EAAE,CAAC;IAEtE,wBAAwB;IACxB,IAAI,YAA2B,CAAC;IAChC,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;QACzB,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IACtC,CAAC;SAAM,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;QAC5B,YAAY,GAAG,IAAI,gBAAgB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACxD,CAAC;SAAM,CAAC;QACN,YAAY,GAAG,IAAI,gBAAgB,EAAE,CAAC;IACxC,CAAC;IAED,4BAA4B;IAC5B,OAAO,IAAI,UAAU,CAAC;QACpB,WAAW;QACX,YAAY;QACZ,YAAY;QACZ,YAAY;QACZ,MAAM;KACP,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { RLMConfig, RLMConfigInput } from '../domain/types/config.js';
2
+ /**
3
+ * Environment variable names for configuration
4
+ */
5
+ export declare const ENV_VARS: {
6
+ readonly OPENROUTER_API_KEY: "OPENROUTER_API_KEY";
7
+ readonly RLM_MODEL: "RLM_MODEL";
8
+ readonly RLM_MAX_DEPTH: "RLM_MAX_DEPTH";
9
+ readonly RLM_MAX_COST_USD: "RLM_MAX_COST_USD";
10
+ readonly RLM_MAX_TOKENS: "RLM_MAX_TOKENS";
11
+ readonly RLM_TIMEOUT_SECONDS: "RLM_TIMEOUT_SECONDS";
12
+ readonly RLM_SANDBOX_MODE: "RLM_SANDBOX_MODE";
13
+ readonly RLM_TEMPERATURE: "RLM_TEMPERATURE";
14
+ };
15
+ /**
16
+ * Load configuration from environment variables
17
+ */
18
+ export declare function loadConfigFromEnv(): RLMConfigInput;
19
+ /**
20
+ * Resolve configuration with defaults and environment
21
+ */
22
+ export declare function resolveConfig(userConfig?: RLMConfigInput, includeEnv?: boolean): RLMConfig;
23
+ /**
24
+ * Validate configuration values
25
+ */
26
+ export declare function validateConfig(config: RLMConfig): string[];
27
+ //# sourceMappingURL=default-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-config.d.ts","sourceRoot":"","sources":["../../src/factory/default-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAG3E;;GAEG;AACH,eAAO,MAAM,QAAQ;;;;;;;;;CASX,CAAC;AAEX;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,CAsDlD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,UAAU,CAAC,EAAE,cAAc,EAC3B,UAAU,UAAO,GAChB,SAAS,CAQX;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,EAAE,CAwB1D"}