@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,137 @@
1
+ import type { TokenUsage, ResourceUsage } from '../types/result.js';
2
+ import type { SessionStatus } from '../types/session.js';
3
+ /**
4
+ * Base event interface
5
+ */
6
+ export interface RLMEventBase {
7
+ /** Event type */
8
+ readonly type: string;
9
+ /** Session ID */
10
+ readonly sessionId: string;
11
+ /** Timestamp */
12
+ readonly timestamp: Date;
13
+ }
14
+ /**
15
+ * Session started event
16
+ */
17
+ export interface SessionStartedEvent extends RLMEventBase {
18
+ readonly type: 'rlm.session.started';
19
+ readonly query: string;
20
+ readonly contextSize: number;
21
+ }
22
+ /**
23
+ * Session completed event
24
+ */
25
+ export interface SessionCompletedEvent extends RLMEventBase {
26
+ readonly type: 'rlm.session.completed';
27
+ readonly success: boolean;
28
+ readonly usage: ResourceUsage;
29
+ }
30
+ /**
31
+ * Session failed event
32
+ */
33
+ export interface SessionFailedEvent extends RLMEventBase {
34
+ readonly type: 'rlm.session.failed';
35
+ readonly error: string;
36
+ readonly usage: ResourceUsage;
37
+ }
38
+ /**
39
+ * Session cancelled event
40
+ */
41
+ export interface SessionCancelledEvent extends RLMEventBase {
42
+ readonly type: 'rlm.session.cancelled';
43
+ readonly usage: ResourceUsage;
44
+ }
45
+ /**
46
+ * LLM call completed event
47
+ */
48
+ export interface LLMCallCompletedEvent extends RLMEventBase {
49
+ readonly type: 'rlm.llm.completed';
50
+ readonly model: string;
51
+ readonly usage: TokenUsage;
52
+ readonly cost: number;
53
+ readonly depth: number;
54
+ }
55
+ /**
56
+ * Code execution completed event
57
+ */
58
+ export interface CodeExecutionCompletedEvent extends RLMEventBase {
59
+ readonly type: 'rlm.code.completed';
60
+ readonly success: boolean;
61
+ readonly executionTimeMs: number;
62
+ readonly depth: number;
63
+ }
64
+ /**
65
+ * Recursive call started event
66
+ */
67
+ export interface RecursiveCallStartedEvent extends RLMEventBase {
68
+ readonly type: 'rlm.recursive.started';
69
+ readonly query: string;
70
+ readonly depth: number;
71
+ }
72
+ /**
73
+ * Recursive call completed event
74
+ */
75
+ export interface RecursiveCallCompletedEvent extends RLMEventBase {
76
+ readonly type: 'rlm.recursive.completed';
77
+ readonly depth: number;
78
+ readonly resultLength: number;
79
+ }
80
+ /**
81
+ * Progress update event
82
+ */
83
+ export interface ProgressUpdateEvent extends RLMEventBase {
84
+ readonly type: 'rlm.progress.update';
85
+ readonly status: SessionStatus;
86
+ readonly currentDepth: number;
87
+ readonly usage: ResourceUsage;
88
+ readonly message?: string;
89
+ }
90
+ /**
91
+ * Limit warning event
92
+ */
93
+ export interface LimitWarningEvent extends RLMEventBase {
94
+ readonly type: 'rlm.limit.warning';
95
+ readonly limitType: 'depth' | 'tokens' | 'cost' | 'time';
96
+ readonly current: number;
97
+ readonly max: number;
98
+ readonly percentage: number;
99
+ }
100
+ /**
101
+ * Union of all RLM events
102
+ */
103
+ export type RLMEvent = SessionStartedEvent | SessionCompletedEvent | SessionFailedEvent | SessionCancelledEvent | LLMCallCompletedEvent | CodeExecutionCompletedEvent | RecursiveCallStartedEvent | RecursiveCallCompletedEvent | ProgressUpdateEvent | LimitWarningEvent;
104
+ /**
105
+ * Event handler function
106
+ */
107
+ export type EventHandler<T extends RLMEvent = RLMEvent> = (event: T) => void;
108
+ /**
109
+ * Interface for event emission
110
+ */
111
+ export interface IEventEmitter {
112
+ /**
113
+ * Emit an event
114
+ */
115
+ emit(event: RLMEvent): void;
116
+ /**
117
+ * Subscribe to events of a specific type
118
+ */
119
+ on<T extends RLMEvent['type']>(type: T, handler: EventHandler<Extract<RLMEvent, {
120
+ type: T;
121
+ }>>): void;
122
+ /**
123
+ * Subscribe to all events
124
+ */
125
+ onAny(handler: EventHandler): void;
126
+ /**
127
+ * Unsubscribe a handler
128
+ */
129
+ off<T extends RLMEvent['type']>(type: T, handler: EventHandler<Extract<RLMEvent, {
130
+ type: T;
131
+ }>>): void;
132
+ /**
133
+ * Unsubscribe from all events
134
+ */
135
+ offAny(handler: EventHandler): void;
136
+ }
137
+ //# sourceMappingURL=event-emitter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-emitter.d.ts","sourceRoot":"","sources":["../../../src/domain/interfaces/event-emitter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,iBAAiB;IACjB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,iBAAiB;IACjB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,gBAAgB;IAChB,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,mBAAoB,SAAQ,YAAY;IACvD,QAAQ,CAAC,IAAI,EAAE,qBAAqB,CAAC;IACrC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,qBAAsB,SAAQ,YAAY;IACzD,QAAQ,CAAC,IAAI,EAAE,uBAAuB,CAAC;IACvC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,YAAY;IACtD,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAAC;IACpC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;CAC/B;AAED;;GAEG;AACH,MAA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;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC,CAAC,GACpD,IAAI,CAAC;IAER;;OAEG;IACH,MAAM,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAAC;CACrC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=event-emitter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-emitter.js","sourceRoot":"","sources":["../../../src/domain/interfaces/event-emitter.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ export { type MessageRole, type Message, type GenerateOptions, type LLMResponse, type FinishReason, type ILLMProvider, } from './llm-provider.js';
2
+ export { type ExecutionContext, type ValidationResult, type ValidationError, type ValidationErrorCode, type ExecutionResult, type PythonCommand, type LLMQueryCommand, type SetResultCommand, type SetVariableCommand, type ICodeExecutor, } from './code-executor.js';
3
+ export { type SessionFilter, type SessionPatch, type ISessionStore, } from './session-store.js';
4
+ export { type RLMEventBase, type SessionStartedEvent, type SessionCompletedEvent, type SessionFailedEvent, type SessionCancelledEvent, type LLMCallCompletedEvent, type CodeExecutionCompletedEvent, type RecursiveCallStartedEvent, type RecursiveCallCompletedEvent, type ProgressUpdateEvent, type LimitWarningEvent, type RLMEvent, type EventHandler, type IEventEmitter, } from './event-emitter.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/domain/interfaces/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,YAAY,GAClB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,aAAa,GACnB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,aAAa,GACnB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,2BAA2B,EAChC,KAAK,yBAAyB,EAC9B,KAAK,2BAA2B,EAChC,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,aAAa,GACnB,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/domain/interfaces/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,64 @@
1
+ import type { TokenUsage } from '../types/result.js';
2
+ /**
3
+ * Message role for chat-based LLM APIs
4
+ */
5
+ export type MessageRole = 'system' | 'user' | 'assistant';
6
+ /**
7
+ * A message in a conversation
8
+ */
9
+ export interface Message {
10
+ readonly role: MessageRole;
11
+ readonly content: string;
12
+ }
13
+ /**
14
+ * Options for LLM generation
15
+ */
16
+ export interface GenerateOptions {
17
+ /** Temperature (0-1) */
18
+ readonly temperature?: number;
19
+ /** Maximum tokens to generate */
20
+ readonly maxTokens?: number;
21
+ /** Stop sequences */
22
+ readonly stopSequences?: readonly string[];
23
+ /** System prompt override */
24
+ readonly systemPrompt?: string;
25
+ }
26
+ /**
27
+ * Response from LLM generation
28
+ */
29
+ export interface LLMResponse {
30
+ /** The generated content */
31
+ readonly content: string;
32
+ /** Token usage statistics */
33
+ readonly usage: TokenUsage;
34
+ /** Model that was used */
35
+ readonly model: string;
36
+ /** Finish reason */
37
+ readonly finishReason: FinishReason;
38
+ /** Cost in USD for this call */
39
+ readonly cost: number;
40
+ }
41
+ export type FinishReason = 'stop' | 'length' | 'content_filter' | 'error';
42
+ /**
43
+ * Interface for LLM providers (OpenRouter, Anthropic, etc.)
44
+ */
45
+ export interface ILLMProvider {
46
+ /**
47
+ * Generate a completion for the given messages
48
+ */
49
+ generate(messages: readonly Message[], options?: GenerateOptions): Promise<LLMResponse>;
50
+ /**
51
+ * Estimate token count for text
52
+ * This is an approximation, not exact
53
+ */
54
+ estimateTokens(text: string): number;
55
+ /**
56
+ * Get the current model being used
57
+ */
58
+ getModel(): string;
59
+ /**
60
+ * Check if the provider is healthy/available
61
+ */
62
+ healthCheck(): Promise<boolean>;
63
+ }
64
+ //# sourceMappingURL=llm-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llm-provider.d.ts","sourceRoot":"","sources":["../../../src/domain/interfaces/llm-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,wBAAwB;IACxB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAE9B,iCAAiC;IACjC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAE5B,qBAAqB;IACrB,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAE3C,6BAA6B;IAC7B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,4BAA4B;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,6BAA6B;IAC7B,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAE3B,0BAA0B;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB,oBAAoB;IACpB,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IAEpC,gCAAgC;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,QAAQ,GAAG,gBAAgB,GAAG,OAAO,CAAC;AAE1E;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAExF;;;OAGG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAErC;;OAEG;IACH,QAAQ,IAAI,MAAM,CAAC;IAEnB;;OAEG;IACH,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CACjC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=llm-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llm-provider.js","sourceRoot":"","sources":["../../../src/domain/interfaces/llm-provider.ts"],"names":[],"mappings":""}
@@ -0,0 +1,65 @@
1
+ import type { RLMSession, SessionStatus } from '../types/session.js';
2
+ import type { ResourceUsage, ExecutionTrace, RLMResult } from '../types/result.js';
3
+ /**
4
+ * Filter options for listing sessions
5
+ */
6
+ export interface SessionFilter {
7
+ /** Filter by status */
8
+ readonly status?: SessionStatus | readonly SessionStatus[];
9
+ /** Filter by creation date (after) */
10
+ readonly createdAfter?: Date;
11
+ /** Filter by creation date (before) */
12
+ readonly createdBefore?: Date;
13
+ /** Limit number of results */
14
+ readonly limit?: number;
15
+ /** Offset for pagination */
16
+ readonly offset?: number;
17
+ /** Order by field */
18
+ readonly orderBy?: 'createdAt' | 'updatedAt';
19
+ /** Order direction */
20
+ readonly orderDir?: 'asc' | 'desc';
21
+ }
22
+ /**
23
+ * Patch for updating session fields
24
+ */
25
+ export interface SessionPatch {
26
+ readonly status?: SessionStatus;
27
+ readonly currentDepth?: number;
28
+ readonly usage?: ResourceUsage;
29
+ readonly trace?: ExecutionTrace;
30
+ readonly startedAt?: Date;
31
+ readonly completedAt?: Date;
32
+ readonly result?: RLMResult;
33
+ readonly error?: string;
34
+ readonly cancellationRequested?: boolean;
35
+ }
36
+ /**
37
+ * Interface for session persistence
38
+ */
39
+ export interface ISessionStore {
40
+ /**
41
+ * Save a new session
42
+ */
43
+ save(session: RLMSession): Promise<void>;
44
+ /**
45
+ * Load a session by ID
46
+ */
47
+ load(id: string): Promise<RLMSession | null>;
48
+ /**
49
+ * Update a session with a patch
50
+ */
51
+ update(id: string, patch: SessionPatch): Promise<void>;
52
+ /**
53
+ * Delete a session
54
+ */
55
+ delete(id: string): Promise<void>;
56
+ /**
57
+ * List sessions with optional filter
58
+ */
59
+ list(filter?: SessionFilter): Promise<readonly RLMSession[]>;
60
+ /**
61
+ * Count sessions matching filter
62
+ */
63
+ count(filter?: SessionFilter): Promise<number>;
64
+ }
65
+ //# sourceMappingURL=session-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-store.d.ts","sourceRoot":"","sources":["../../../src/domain/interfaces/session-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEnF;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,uBAAuB;IACvB,QAAQ,CAAC,MAAM,CAAC,EAAE,aAAa,GAAG,SAAS,aAAa,EAAE,CAAC;IAE3D,sCAAsC;IACtC,QAAQ,CAAC,YAAY,CAAC,EAAE,IA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,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAElC;;OAEG;IACH,IAAI,CAAC,MAAM,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,SAAS,UAAU,EAAE,CAAC,CAAC;IAE7D;;OAEG;IACH,KAAK,CAAC,MAAM,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAChD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=session-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-store.js","sourceRoot":"","sources":["../../../src/domain/interfaces/session-store.ts"],"names":[],"mappings":""}
@@ -0,0 +1,43 @@
1
+ import type { ContextChunk } from '../types/context.js';
2
+ /**
3
+ * Strategy for chunking content
4
+ */
5
+ export type ChunkStrategy = 'tokens' | 'lines' | 'paragraphs' | 'delimiter';
6
+ /**
7
+ * Options for chunking
8
+ */
9
+ export interface ChunkOptions {
10
+ /** Strategy to use */
11
+ readonly strategy: ChunkStrategy;
12
+ /** Target size (tokens, lines, or chars depending on strategy) */
13
+ readonly targetSize: number;
14
+ /** Overlap between chunks (in same unit as targetSize) */
15
+ readonly overlap?: number;
16
+ /** Custom delimiter for 'delimiter' strategy */
17
+ readonly delimiter?: string;
18
+ }
19
+ /**
20
+ * Token estimator function type
21
+ */
22
+ export type TokenEstimator = (text: string) => number;
23
+ /**
24
+ * Chunk content by estimated token count
25
+ */
26
+ export declare function chunkByTokens(content: string, maxTokensPerChunk: number, estimateTokens: TokenEstimator, overlap?: number): ContextChunk[];
27
+ /**
28
+ * Chunk content by line count
29
+ */
30
+ export declare function chunkByLines(content: string, linesPerChunk: number, estimateTokens: TokenEstimator, overlap?: number): ContextChunk[];
31
+ /**
32
+ * Chunk content by delimiter (e.g., paragraphs, sections)
33
+ */
34
+ export declare function chunkByDelimiter(content: string, delimiter: string, estimateTokens: TokenEstimator): ContextChunk[];
35
+ /**
36
+ * Chunk content by paragraphs (double newlines)
37
+ */
38
+ export declare function chunkByParagraphs(content: string, estimateTokens: TokenEstimator): ContextChunk[];
39
+ /**
40
+ * Smart chunking that tries to find good split points
41
+ */
42
+ export declare function chunkSmart(content: string, maxTokensPerChunk: number, estimateTokens: TokenEstimator): ContextChunk[];
43
+ //# sourceMappingURL=context-chunker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-chunker.d.ts","sourceRoot":"","sources":["../../../src/domain/services/context-chunker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,OAAO,GAAG,YAAY,GAAG,WAAW,CAAC;AAE5E;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,sBAAsB;IACtB,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;IAEjC,kEAAkE;IAClE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B,0DAA0D;IAC1D,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAE1B,gDAAgD;IAChD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;AAEtD;;GAEG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,iBAAiB,EAAE,MAAM,EACzB,cAAc,EAAE,cAAc,EAC9B,OAAO,SAAI,GACV,YAAY,EAAE,CAkEhB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,MAAM,EACf,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,cAAc,EAC9B,OAAO,SAAI,GACV,YAAY,EAAE,CAgChB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,cAAc,GAC7B,YAAY,EAAE,CAqBhB;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,cAAc,GAC7B,YAAY,EAAE,CAEhB;AAED;;GAEG;AACH,wBAAgB,UAAU,CACxB,OAAO,EAAE,MAAM,EACf,iBAAiB,EAAE,MAAM,EACzB,cAAc,EAAE,cAAc,GAC7B,YAAY,EAAE,CAyBhB"}
@@ -0,0 +1,152 @@
1
+ /**
2
+ * Chunk content by estimated token count
3
+ */
4
+ export function chunkByTokens(content, maxTokensPerChunk, estimateTokens, overlap = 0) {
5
+ const chunks = [];
6
+ const lines = content.split('\n');
7
+ let currentChunk = [];
8
+ let currentTokens = 0;
9
+ let startOffset = 0;
10
+ let currentOffset = 0;
11
+ for (const line of lines) {
12
+ const lineTokens = estimateTokens(line);
13
+ if (currentTokens + lineTokens > maxTokensPerChunk && currentChunk.length > 0) {
14
+ // Finish current chunk
15
+ const chunkContent = currentChunk.join('\n');
16
+ chunks.push({
17
+ index: chunks.length,
18
+ total: -1, // Will be updated at the end
19
+ content: chunkContent,
20
+ startOffset,
21
+ endOffset: currentOffset - 1,
22
+ estimatedTokens: currentTokens,
23
+ });
24
+ // Handle overlap by keeping some lines
25
+ if (overlap > 0) {
26
+ const overlapLines = [];
27
+ let overlapTokens = 0;
28
+ for (let i = currentChunk.length - 1; i >= 0 && overlapTokens < overlap; i--) {
29
+ const l = currentChunk[i];
30
+ if (l !== undefined) {
31
+ overlapLines.unshift(l);
32
+ overlapTokens += estimateTokens(l);
33
+ }
34
+ }
35
+ currentChunk = overlapLines;
36
+ currentTokens = overlapTokens;
37
+ startOffset = currentOffset - overlapLines.join('\n').length - 1;
38
+ }
39
+ else {
40
+ currentChunk = [];
41
+ currentTokens = 0;
42
+ startOffset = currentOffset;
43
+ }
44
+ }
45
+ currentChunk.push(line);
46
+ currentTokens += lineTokens;
47
+ currentOffset += line.length + 1; // +1 for newline
48
+ }
49
+ // Don't forget the last chunk
50
+ if (currentChunk.length > 0) {
51
+ const chunkContent = currentChunk.join('\n');
52
+ chunks.push({
53
+ index: chunks.length,
54
+ total: -1,
55
+ content: chunkContent,
56
+ startOffset,
57
+ endOffset: content.length,
58
+ estimatedTokens: currentTokens,
59
+ });
60
+ }
61
+ // Update total count
62
+ const total = chunks.length;
63
+ return chunks.map((chunk) => ({ ...chunk, total }));
64
+ }
65
+ /**
66
+ * Chunk content by line count
67
+ */
68
+ export function chunkByLines(content, linesPerChunk, estimateTokens, overlap = 0) {
69
+ const lines = content.split('\n');
70
+ const chunks = [];
71
+ let startIndex = 0;
72
+ let startOffset = 0;
73
+ while (startIndex < lines.length) {
74
+ const endIndex = Math.min(startIndex + linesPerChunk, lines.length);
75
+ const chunkLines = lines.slice(startIndex, endIndex);
76
+ const chunkContent = chunkLines.join('\n');
77
+ const endOffset = startOffset + chunkContent.length;
78
+ chunks.push({
79
+ index: chunks.length,
80
+ total: -1,
81
+ content: chunkContent,
82
+ startOffset,
83
+ endOffset,
84
+ estimatedTokens: estimateTokens(chunkContent),
85
+ });
86
+ startIndex = endIndex - overlap;
87
+ startOffset = endOffset + 1; // Account for the newline
88
+ if (overlap > 0) {
89
+ // Adjust startOffset for overlap
90
+ const overlapContent = lines.slice(startIndex, endIndex).join('\n');
91
+ startOffset = endOffset - overlapContent.length;
92
+ }
93
+ }
94
+ const total = chunks.length;
95
+ return chunks.map((chunk) => ({ ...chunk, total }));
96
+ }
97
+ /**
98
+ * Chunk content by delimiter (e.g., paragraphs, sections)
99
+ */
100
+ export function chunkByDelimiter(content, delimiter, estimateTokens) {
101
+ const parts = content.split(delimiter);
102
+ const chunks = [];
103
+ let offset = 0;
104
+ for (const part of parts) {
105
+ if (part.trim().length > 0) {
106
+ chunks.push({
107
+ index: chunks.length,
108
+ total: -1,
109
+ content: part,
110
+ startOffset: offset,
111
+ endOffset: offset + part.length,
112
+ estimatedTokens: estimateTokens(part),
113
+ });
114
+ }
115
+ offset += part.length + delimiter.length;
116
+ }
117
+ const total = chunks.length;
118
+ return chunks.map((chunk) => ({ ...chunk, total }));
119
+ }
120
+ /**
121
+ * Chunk content by paragraphs (double newlines)
122
+ */
123
+ export function chunkByParagraphs(content, estimateTokens) {
124
+ return chunkByDelimiter(content, '\n\n', estimateTokens);
125
+ }
126
+ /**
127
+ * Smart chunking that tries to find good split points
128
+ */
129
+ export function chunkSmart(content, maxTokensPerChunk, estimateTokens) {
130
+ const totalTokens = estimateTokens(content);
131
+ // If content fits in one chunk, return as-is
132
+ if (totalTokens <= maxTokensPerChunk) {
133
+ return [
134
+ {
135
+ index: 0,
136
+ total: 1,
137
+ content,
138
+ startOffset: 0,
139
+ endOffset: content.length,
140
+ estimatedTokens: totalTokens,
141
+ },
142
+ ];
143
+ }
144
+ // Try paragraphs first
145
+ const paragraphChunks = chunkByParagraphs(content, estimateTokens);
146
+ if (paragraphChunks.every((c) => c.estimatedTokens <= maxTokensPerChunk)) {
147
+ return paragraphChunks;
148
+ }
149
+ // Fall back to token-based chunking
150
+ return chunkByTokens(content, maxTokensPerChunk, estimateTokens, Math.floor(maxTokensPerChunk * 0.1));
151
+ }
152
+ //# sourceMappingURL=context-chunker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-chunker.js","sourceRoot":"","sources":["../../../src/domain/services/context-chunker.ts"],"names":[],"mappings":"AA6BA;;GAEG;AACH,MAAM,UAAU,aAAa,CAC3B,OAAe,EACf,iBAAyB,EACzB,cAA8B,EAC9B,OAAO,GAAG,CAAC;IAEX,MAAM,MAAM,GAAmB,EAAE,CAAC;IAClC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAElC,IAAI,YAAY,GAAa,EAAE,CAAC;IAChC,IAAI,aAAa,GAAG,CAAC,CAAC;IACtB,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,IAAI,aAAa,GAAG,CAAC,CAAC;IAEtB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,UAAU,G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ACzE,OAAO,eAAe,CAAC;IACzB,CAAC;IAED,oCAAoC;IACpC,OAAO,aAAa,CAAC,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,IAAI,CAAC,KAAK,CAAC,iBAAiB,GAAG,GAAG,CAAC,CAAC,CAAC;AACxG,CAAC"}
@@ -0,0 +1,63 @@
1
+ import type { TokenUsage } from '../types/result.js';
2
+ import type { RLMConfig } from '../types/config.js';
3
+ /**
4
+ * Pricing information for a model
5
+ */
6
+ export interface ModelPricing {
7
+ /** Cost per 1M input tokens in USD */
8
+ readonly inputCostPer1M: number;
9
+ /** Cost per 1M output tokens in USD */
10
+ readonly outputCostPer1M: number;
11
+ }
12
+ /**
13
+ * Known model pricing (as of early 2025)
14
+ * These should be updated periodically
15
+ */
16
+ export declare const MODEL_PRICING: Record<string, ModelPricing>;
17
+ /**
18
+ * Default pricing for unknown models
19
+ */
20
+ export declare const DEFAULT_PRICING: ModelPricing;
21
+ /**
22
+ * Get pricing for a model
23
+ */
24
+ export declare function getModelPricing(model: string): ModelPricing;
25
+ /**
26
+ * Calculate cost for token usage
27
+ */
28
+ export declare function calculateCost(usage: TokenUsage, model: string): number;
29
+ /**
30
+ * Estimate for a session
31
+ */
32
+ export interface CostEstimate {
33
+ /** Minimum estimated cost */
34
+ readonly minCostUsd: number;
35
+ /** Maximum estimated cost */
36
+ readonly maxCostUsd: number;
37
+ /** Average/expected cost */
38
+ readonly expectedCostUsd: number;
39
+ /** Estimated number of LLM calls */
40
+ readonly estimatedCalls: number;
41
+ }
42
+ /**
43
+ * Estimate session cost based on context size
44
+ * This is a rough heuristic based on typical usage patterns
45
+ */
46
+ export declare function estimateSessionCost(config: RLMConfig, contextTokens: number): CostEstimate;
47
+ /**
48
+ * Format cost for display
49
+ */
50
+ export declare function formatCost(costUsd: number): string;
51
+ /**
52
+ * Check if cost is within budget
53
+ */
54
+ export declare function isWithinBudget(currentCost: number, maxCost: number): boolean;
55
+ /**
56
+ * Calculate remaining budget
57
+ */
58
+ export declare function remainingBudget(currentCost: number, maxCost: number): number;
59
+ /**
60
+ * Calculate percentage of budget used
61
+ */
62
+ export declare function budgetUsedPercent(currentCost: number, maxCost: number): number;
63
+ //# sourceMappingURL=cost-calculator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cost-calculator.d.ts","sourceRoot":"","sources":["../../../src/domain/services/cost-calculator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,sCAAsC;IACtC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAEhC,uCAAuC;IACvC,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;CAClC;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CA6BtD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,YAG7B,CAAC;AAEF;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,CAe3D;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAOtE;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,6BAA6B;IAC7B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B,6BAA6B;IAC7B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B,4BAA4B;IAC5B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IAEjC,oCAAoC;IACpC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,SAAS,EACjB,aAAa,EAAE,MAAM,GACpB,YAAY,CA2Bd;AAED;;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