wave-agent-sdk 0.0.8 → 0.0.10

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 (236) hide show
  1. package/dist/agent.d.ts +92 -23
  2. package/dist/agent.d.ts.map +1 -1
  3. package/dist/agent.js +340 -137
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +2 -0
  7. package/dist/managers/aiManager.d.ts +14 -36
  8. package/dist/managers/aiManager.d.ts.map +1 -1
  9. package/dist/managers/aiManager.js +74 -77
  10. package/dist/managers/backgroundBashManager.d.ts.map +1 -1
  11. package/dist/managers/backgroundBashManager.js +4 -3
  12. package/dist/managers/hookManager.d.ts +3 -8
  13. package/dist/managers/hookManager.d.ts.map +1 -1
  14. package/dist/managers/hookManager.js +39 -29
  15. package/dist/managers/liveConfigManager.d.ts +55 -18
  16. package/dist/managers/liveConfigManager.d.ts.map +1 -1
  17. package/dist/managers/liveConfigManager.js +372 -90
  18. package/dist/managers/lspManager.d.ts +43 -0
  19. package/dist/managers/lspManager.d.ts.map +1 -0
  20. package/dist/managers/lspManager.js +326 -0
  21. package/dist/managers/messageManager.d.ts +8 -16
  22. package/dist/managers/messageManager.d.ts.map +1 -1
  23. package/dist/managers/messageManager.js +52 -74
  24. package/dist/managers/permissionManager.d.ts +66 -0
  25. package/dist/managers/permissionManager.d.ts.map +1 -0
  26. package/dist/managers/permissionManager.js +208 -0
  27. package/dist/managers/skillManager.d.ts +1 -0
  28. package/dist/managers/skillManager.d.ts.map +1 -1
  29. package/dist/managers/skillManager.js +2 -1
  30. package/dist/managers/slashCommandManager.d.ts.map +1 -1
  31. package/dist/managers/slashCommandManager.js +0 -1
  32. package/dist/managers/subagentManager.d.ts +8 -23
  33. package/dist/managers/subagentManager.d.ts.map +1 -1
  34. package/dist/managers/subagentManager.js +97 -117
  35. package/dist/managers/toolManager.d.ts +38 -1
  36. package/dist/managers/toolManager.d.ts.map +1 -1
  37. package/dist/managers/toolManager.js +66 -2
  38. package/dist/services/aiService.d.ts +3 -1
  39. package/dist/services/aiService.d.ts.map +1 -1
  40. package/dist/services/aiService.js +123 -30
  41. package/dist/services/configurationService.d.ts +116 -0
  42. package/dist/services/configurationService.d.ts.map +1 -0
  43. package/dist/services/configurationService.js +585 -0
  44. package/dist/services/fileWatcher.d.ts.map +1 -1
  45. package/dist/services/fileWatcher.js +5 -6
  46. package/dist/services/hook.d.ts +7 -124
  47. package/dist/services/hook.d.ts.map +1 -1
  48. package/dist/services/hook.js +46 -458
  49. package/dist/services/jsonlHandler.d.ts +24 -15
  50. package/dist/services/jsonlHandler.d.ts.map +1 -1
  51. package/dist/services/jsonlHandler.js +67 -88
  52. package/dist/services/memory.d.ts +0 -9
  53. package/dist/services/memory.d.ts.map +1 -1
  54. package/dist/services/memory.js +2 -49
  55. package/dist/services/session.d.ts +82 -33
  56. package/dist/services/session.d.ts.map +1 -1
  57. package/dist/services/session.js +275 -181
  58. package/dist/tools/bashTool.d.ts.map +1 -1
  59. package/dist/tools/bashTool.js +72 -13
  60. package/dist/tools/deleteFileTool.d.ts.map +1 -1
  61. package/dist/tools/deleteFileTool.js +25 -0
  62. package/dist/tools/editTool.d.ts.map +1 -1
  63. package/dist/tools/editTool.js +30 -6
  64. package/dist/tools/lspTool.d.ts +6 -0
  65. package/dist/tools/lspTool.d.ts.map +1 -0
  66. package/dist/tools/lspTool.js +589 -0
  67. package/dist/tools/multiEditTool.d.ts.map +1 -1
  68. package/dist/tools/multiEditTool.js +26 -7
  69. package/dist/tools/readTool.d.ts.map +1 -1
  70. package/dist/tools/readTool.js +111 -2
  71. package/dist/tools/skillTool.js +2 -2
  72. package/dist/tools/todoWriteTool.d.ts.map +1 -1
  73. package/dist/tools/todoWriteTool.js +23 -0
  74. package/dist/tools/types.d.ts +11 -8
  75. package/dist/tools/types.d.ts.map +1 -1
  76. package/dist/tools/writeTool.d.ts.map +1 -1
  77. package/dist/tools/writeTool.js +25 -9
  78. package/dist/types/commands.d.ts +0 -1
  79. package/dist/types/commands.d.ts.map +1 -1
  80. package/dist/types/config.d.ts +4 -0
  81. package/dist/types/config.d.ts.map +1 -1
  82. package/dist/types/configuration.d.ts +69 -0
  83. package/dist/types/configuration.d.ts.map +1 -0
  84. package/dist/types/configuration.js +8 -0
  85. package/dist/types/core.d.ts +10 -0
  86. package/dist/types/core.d.ts.map +1 -1
  87. package/dist/types/environment.d.ts +41 -0
  88. package/dist/types/environment.d.ts.map +1 -1
  89. package/dist/types/fileSearch.d.ts +5 -0
  90. package/dist/types/fileSearch.d.ts.map +1 -0
  91. package/dist/types/fileSearch.js +1 -0
  92. package/dist/types/hooks.d.ts +11 -2
  93. package/dist/types/hooks.d.ts.map +1 -1
  94. package/dist/types/hooks.js +1 -7
  95. package/dist/types/index.d.ts +5 -0
  96. package/dist/types/index.d.ts.map +1 -1
  97. package/dist/types/index.js +5 -0
  98. package/dist/types/lsp.d.ts +90 -0
  99. package/dist/types/lsp.d.ts.map +1 -0
  100. package/dist/types/lsp.js +4 -0
  101. package/dist/types/messaging.d.ts +6 -11
  102. package/dist/types/messaging.d.ts.map +1 -1
  103. package/dist/types/permissions.d.ts +35 -0
  104. package/dist/types/permissions.d.ts.map +1 -0
  105. package/dist/types/permissions.js +12 -0
  106. package/dist/types/session.d.ts +1 -6
  107. package/dist/types/session.d.ts.map +1 -1
  108. package/dist/types/skills.d.ts +1 -0
  109. package/dist/types/skills.d.ts.map +1 -1
  110. package/dist/types/tools.d.ts +35 -0
  111. package/dist/types/tools.d.ts.map +1 -0
  112. package/dist/types/tools.js +4 -0
  113. package/dist/utils/abortUtils.d.ts +34 -0
  114. package/dist/utils/abortUtils.d.ts.map +1 -0
  115. package/dist/utils/abortUtils.js +92 -0
  116. package/dist/utils/bashHistory.d.ts +4 -0
  117. package/dist/utils/bashHistory.d.ts.map +1 -1
  118. package/dist/utils/bashHistory.js +21 -4
  119. package/dist/utils/builtinSubagents.d.ts +7 -0
  120. package/dist/utils/builtinSubagents.d.ts.map +1 -0
  121. package/dist/utils/builtinSubagents.js +65 -0
  122. package/dist/utils/cacheControlUtils.d.ts +8 -33
  123. package/dist/utils/cacheControlUtils.d.ts.map +1 -1
  124. package/dist/utils/cacheControlUtils.js +83 -126
  125. package/dist/utils/constants.d.ts +0 -12
  126. package/dist/utils/constants.d.ts.map +1 -1
  127. package/dist/utils/constants.js +1 -13
  128. package/dist/utils/convertMessagesForAPI.d.ts +2 -1
  129. package/dist/utils/convertMessagesForAPI.d.ts.map +1 -1
  130. package/dist/utils/convertMessagesForAPI.js +33 -14
  131. package/dist/utils/fileSearch.d.ts +14 -0
  132. package/dist/utils/fileSearch.d.ts.map +1 -0
  133. package/dist/utils/fileSearch.js +88 -0
  134. package/dist/utils/fileUtils.d.ts +14 -2
  135. package/dist/utils/fileUtils.d.ts.map +1 -1
  136. package/dist/utils/fileUtils.js +101 -17
  137. package/dist/utils/globalLogger.d.ts +0 -14
  138. package/dist/utils/globalLogger.d.ts.map +1 -1
  139. package/dist/utils/globalLogger.js +0 -16
  140. package/dist/utils/largeOutputHandler.d.ts +15 -0
  141. package/dist/utils/largeOutputHandler.d.ts.map +1 -0
  142. package/dist/utils/largeOutputHandler.js +40 -0
  143. package/dist/utils/markdownParser.d.ts.map +1 -1
  144. package/dist/utils/markdownParser.js +1 -17
  145. package/dist/utils/messageOperations.d.ts +1 -11
  146. package/dist/utils/messageOperations.d.ts.map +1 -1
  147. package/dist/utils/messageOperations.js +7 -24
  148. package/dist/utils/pathEncoder.d.ts +4 -0
  149. package/dist/utils/pathEncoder.d.ts.map +1 -1
  150. package/dist/utils/pathEncoder.js +16 -9
  151. package/dist/utils/subagentParser.d.ts +2 -2
  152. package/dist/utils/subagentParser.d.ts.map +1 -1
  153. package/dist/utils/subagentParser.js +10 -7
  154. package/dist/utils/tokenEstimator.d.ts +39 -0
  155. package/dist/utils/tokenEstimator.d.ts.map +1 -0
  156. package/dist/utils/tokenEstimator.js +55 -0
  157. package/package.json +5 -8
  158. package/src/agent.ts +460 -216
  159. package/src/index.ts +2 -0
  160. package/src/managers/aiManager.ts +107 -111
  161. package/src/managers/backgroundBashManager.ts +4 -3
  162. package/src/managers/hookManager.ts +44 -39
  163. package/src/managers/liveConfigManager.ts +524 -138
  164. package/src/managers/lspManager.ts +434 -0
  165. package/src/managers/messageManager.ts +73 -103
  166. package/src/managers/permissionManager.ts +276 -0
  167. package/src/managers/skillManager.ts +3 -1
  168. package/src/managers/slashCommandManager.ts +1 -2
  169. package/src/managers/subagentManager.ts +116 -159
  170. package/src/managers/toolManager.ts +95 -3
  171. package/src/services/aiService.ts +207 -26
  172. package/src/services/configurationService.ts +762 -0
  173. package/src/services/fileWatcher.ts +5 -6
  174. package/src/services/hook.ts +50 -631
  175. package/src/services/jsonlHandler.ts +84 -100
  176. package/src/services/memory.ts +2 -59
  177. package/src/services/session.ts +338 -213
  178. package/src/tools/bashTool.ts +89 -16
  179. package/src/tools/deleteFileTool.ts +36 -0
  180. package/src/tools/editTool.ts +41 -7
  181. package/src/tools/lspTool.ts +760 -0
  182. package/src/tools/multiEditTool.ts +37 -8
  183. package/src/tools/readTool.ts +125 -2
  184. package/src/tools/skillTool.ts +2 -2
  185. package/src/tools/todoWriteTool.ts +33 -1
  186. package/src/tools/types.ts +15 -9
  187. package/src/tools/writeTool.ts +36 -10
  188. package/src/types/commands.ts +0 -1
  189. package/src/types/config.ts +5 -0
  190. package/src/types/configuration.ts +73 -0
  191. package/src/types/core.ts +11 -0
  192. package/src/types/environment.ts +44 -0
  193. package/src/types/fileSearch.ts +4 -0
  194. package/src/types/hooks.ts +14 -11
  195. package/src/types/index.ts +5 -0
  196. package/src/types/lsp.ts +96 -0
  197. package/src/types/messaging.ts +8 -13
  198. package/src/types/permissions.ts +48 -0
  199. package/src/types/session.ts +3 -8
  200. package/src/types/skills.ts +1 -0
  201. package/src/types/tools.ts +38 -0
  202. package/src/utils/abortUtils.ts +118 -0
  203. package/src/utils/bashHistory.ts +28 -4
  204. package/src/utils/builtinSubagents.ts +71 -0
  205. package/src/utils/cacheControlUtils.ts +106 -171
  206. package/src/utils/constants.ts +1 -16
  207. package/src/utils/convertMessagesForAPI.ts +38 -14
  208. package/src/utils/fileSearch.ts +107 -0
  209. package/src/utils/fileUtils.ts +114 -19
  210. package/src/utils/globalLogger.ts +0 -17
  211. package/src/utils/largeOutputHandler.ts +55 -0
  212. package/src/utils/markdownParser.ts +1 -19
  213. package/src/utils/messageOperations.ts +7 -35
  214. package/src/utils/pathEncoder.ts +24 -9
  215. package/src/utils/subagentParser.ts +11 -8
  216. package/src/utils/tokenEstimator.ts +68 -0
  217. package/dist/constants/events.d.ts +0 -28
  218. package/dist/constants/events.d.ts.map +0 -1
  219. package/dist/constants/events.js +0 -27
  220. package/dist/services/configurationWatcher.d.ts +0 -120
  221. package/dist/services/configurationWatcher.d.ts.map +0 -1
  222. package/dist/services/configurationWatcher.js +0 -439
  223. package/dist/services/memoryStore.d.ts +0 -81
  224. package/dist/services/memoryStore.d.ts.map +0 -1
  225. package/dist/services/memoryStore.js +0 -200
  226. package/dist/types/memoryStore.d.ts +0 -82
  227. package/dist/types/memoryStore.d.ts.map +0 -1
  228. package/dist/types/memoryStore.js +0 -7
  229. package/dist/utils/configResolver.d.ts +0 -65
  230. package/dist/utils/configResolver.d.ts.map +0 -1
  231. package/dist/utils/configResolver.js +0 -210
  232. package/src/constants/events.ts +0 -38
  233. package/src/services/configurationWatcher.ts +0 -622
  234. package/src/services/memoryStore.ts +0 -279
  235. package/src/types/memoryStore.ts +0 -94
  236. package/src/utils/configResolver.ts +0 -302
@@ -1,279 +0,0 @@
1
- /**
2
- * Memory Store Service
3
- *
4
- * Provides in-memory storage for file content with automatic updates.
5
- * Optimizes performance by keeping frequently accessed files in memory.
6
- */
7
-
8
- import { promises as fs } from "fs";
9
- import { EventEmitter } from "events";
10
- import type { Logger } from "../types/index.js";
11
-
12
- export interface MemoryStoreEntry {
13
- content: string;
14
- path: string;
15
- lastModified: number;
16
- isLoaded: boolean;
17
- }
18
-
19
- export interface MemoryStoreStats {
20
- contentSize: number;
21
- lastUpdated: number;
22
- updateCount: number;
23
- isLoaded: boolean;
24
- }
25
-
26
- export interface MemoryUpdateEvent {
27
- path: string;
28
- reason: "file_change" | "initial_load" | "manual_reload";
29
- timestamp: number;
30
- previousSize?: number;
31
- newSize: number;
32
- }
33
-
34
- export class MemoryStoreService extends EventEmitter {
35
- private store: Map<string, MemoryStoreEntry> = new Map();
36
- private updateCounts: Map<string, number> = new Map();
37
- private logger?: Logger;
38
-
39
- constructor(logger?: Logger) {
40
- super();
41
- this.logger = logger;
42
- }
43
-
44
- /**
45
- * Get content from memory store (loads from file if not loaded)
46
- * Maps to FR-006: Keep AGENTS.md content in memory to avoid repeated reads
47
- */
48
- async getContent(path: string): Promise<string> {
49
- const entry = this.store.get(path);
50
-
51
- if (entry && entry.isLoaded) {
52
- this.logger?.debug(`Live Config: Memory hit for ${path}`);
53
- return entry.content;
54
- }
55
-
56
- // Load from file if not in memory
57
- return await this.loadFromFile(path, "initial_load");
58
- }
59
-
60
- /**
61
- * Update memory content from file
62
- * Maps to FR-007: Update memory content when file changes
63
- */
64
- async updateContent(path: string): Promise<void> {
65
- const previousEntry = this.store.get(path);
66
- const previousSize = previousEntry?.content.length || 0;
67
-
68
- await this.loadFromFile(path, "file_change", previousSize);
69
- }
70
-
71
- /**
72
- * Get memory store statistics
73
- * For monitoring and debugging
74
- */
75
- getStats(path?: string): MemoryStoreStats {
76
- if (path) {
77
- const entry = this.store.get(path);
78
- const updateCount = this.updateCounts.get(path) || 0;
79
-
80
- return {
81
- contentSize: entry?.content.length || 0,
82
- lastUpdated: entry?.lastModified || 0,
83
- updateCount,
84
- isLoaded: entry?.isLoaded || false,
85
- };
86
- }
87
-
88
- // Return aggregate stats for all entries
89
- let totalSize = 0;
90
- let latestUpdate = 0;
91
- let totalUpdates = 0;
92
- let anyLoaded = false;
93
-
94
- for (const [entryPath, entry] of this.store) {
95
- totalSize += entry.content.length;
96
- latestUpdate = Math.max(latestUpdate, entry.lastModified);
97
- totalUpdates += this.updateCounts.get(entryPath) || 0;
98
- anyLoaded = anyLoaded || entry.isLoaded;
99
- }
100
-
101
- return {
102
- contentSize: totalSize,
103
- lastUpdated: latestUpdate,
104
- updateCount: totalUpdates,
105
- isLoaded: anyLoaded,
106
- };
107
- }
108
-
109
- /**
110
- * Check if content is loaded in memory
111
- * For status checking
112
- */
113
- isLoaded(path: string): boolean {
114
- const entry = this.store.get(path);
115
- return entry?.isLoaded || false;
116
- }
117
-
118
- /**
119
- * Manually reload content from file
120
- * For force refresh scenarios
121
- */
122
- async reloadContent(path: string): Promise<void> {
123
- const previousEntry = this.store.get(path);
124
- const previousSize = previousEntry?.content.length || 0;
125
-
126
- await this.loadFromFile(path, "manual_reload", previousSize);
127
- }
128
-
129
- /**
130
- * Remove content from memory store
131
- * For cleanup when file is deleted
132
- */
133
- removeContent(path: string): boolean {
134
- const removed = this.store.delete(path);
135
- this.updateCounts.delete(path);
136
-
137
- if (removed) {
138
- this.logger?.info(`Live Config: Removed ${path} from memory store`);
139
- }
140
-
141
- return removed;
142
- }
143
-
144
- /**
145
- * Clear all content from memory store
146
- * For cleanup and testing
147
- */
148
- clear(): void {
149
- const pathCount = this.store.size;
150
- this.store.clear();
151
- this.updateCounts.clear();
152
-
153
- if (pathCount > 0) {
154
- this.logger?.info(
155
- `Live Config: Cleared ${pathCount} entries from memory store`,
156
- );
157
- }
158
- }
159
-
160
- /**
161
- * Get all stored paths
162
- * For monitoring and debugging
163
- */
164
- getStoredPaths(): string[] {
165
- return Array.from(this.store.keys());
166
- }
167
-
168
- /**
169
- * Check if file exists and is accessible
170
- */
171
- async fileExists(path: string): Promise<boolean> {
172
- try {
173
- await fs.access(path);
174
- return true;
175
- } catch {
176
- return false;
177
- }
178
- }
179
-
180
- private async loadFromFile(
181
- path: string,
182
- reason: MemoryUpdateEvent["reason"],
183
- previousSize?: number,
184
- ): Promise<string> {
185
- try {
186
- // Check if file exists
187
- const exists = await this.fileExists(path);
188
- if (!exists) {
189
- // Handle file deletion gracefully
190
- const entry: MemoryStoreEntry = {
191
- content: "",
192
- path,
193
- lastModified: Date.now(),
194
- isLoaded: true,
195
- };
196
-
197
- this.store.set(path, entry);
198
- this.incrementUpdateCount(path);
199
-
200
- this.logger?.info(
201
- `Live Config: File ${path} not found, storing empty content`,
202
- );
203
-
204
- this.emitUpdateEvent(path, reason, previousSize, 0);
205
- return "";
206
- }
207
-
208
- // Read file content
209
- const content = await fs.readFile(path, "utf-8");
210
- const stats = await fs.stat(path);
211
-
212
- const entry: MemoryStoreEntry = {
213
- content,
214
- path,
215
- lastModified: stats.mtime.getTime(),
216
- isLoaded: true,
217
- };
218
-
219
- this.store.set(path, entry);
220
- this.incrementUpdateCount(path);
221
-
222
- this.logger?.info(
223
- `Live Config: Loaded ${content.length} bytes from ${path} into memory`,
224
- );
225
-
226
- this.emitUpdateEvent(path, reason, previousSize, content.length);
227
- return content;
228
- } catch (error) {
229
- const errorMessage = `Live Config: Failed to load ${path} into memory: ${(error as Error).message}`;
230
- this.logger?.error(errorMessage);
231
-
232
- // Return existing content if available, otherwise empty string
233
- const existingEntry = this.store.get(path);
234
- if (existingEntry?.isLoaded) {
235
- this.logger?.warn(
236
- `Live Config: Using cached content for ${path} due to read error`,
237
- );
238
- return existingEntry.content;
239
- }
240
-
241
- // Store empty content as fallback
242
- const entry: MemoryStoreEntry = {
243
- content: "",
244
- path,
245
- lastModified: Date.now(),
246
- isLoaded: true,
247
- };
248
-
249
- this.store.set(path, entry);
250
- this.emitUpdateEvent(path, reason, previousSize, 0);
251
- return "";
252
- }
253
- }
254
-
255
- private incrementUpdateCount(path: string): void {
256
- const current = this.updateCounts.get(path) || 0;
257
- this.updateCounts.set(path, current + 1);
258
- }
259
-
260
- private emitUpdateEvent(
261
- path: string,
262
- reason: MemoryUpdateEvent["reason"],
263
- previousSize: number | undefined,
264
- newSize: number,
265
- ): void {
266
- const event: MemoryUpdateEvent = {
267
- path,
268
- reason,
269
- timestamp: Date.now(),
270
- previousSize,
271
- newSize,
272
- };
273
-
274
- this.emit("memoryUpdate", event);
275
- this.logger?.debug(
276
- `Live Config: Memory update event for ${path}: ${reason}`,
277
- );
278
- }
279
- }
@@ -1,94 +0,0 @@
1
- /**
2
- * Memory Store Type Definitions
3
- *
4
- * Provides TypeScript types for in-memory file storage system,
5
- * enabling optimized access to frequently read files like AGENTS.md.
6
- */
7
-
8
- export interface MemoryStore {
9
- content: string; // Current file content in memory
10
- lastModified: number; // File modification timestamp
11
- path: string; // Absolute file path
12
- isLoaded: boolean; // Whether content has been loaded
13
- }
14
-
15
- export interface MemoryStoreEntry {
16
- content: string;
17
- path: string;
18
- lastModified: number;
19
- isLoaded: boolean;
20
- }
21
-
22
- export interface MemoryStoreStats {
23
- contentSize: number;
24
- lastUpdated: number;
25
- updateCount: number;
26
- isLoaded: boolean;
27
- }
28
-
29
- export interface MemoryUpdateEvent {
30
- path: string;
31
- reason: "file_change" | "initial_load" | "manual_reload";
32
- timestamp: number;
33
- previousSize?: number;
34
- newSize: number;
35
- }
36
-
37
- /**
38
- * Memory Store Service Interface
39
- * Maps to FR-006, FR-007: Memory storage and updates
40
- */
41
- export interface MemoryStoreService {
42
- /**
43
- * Get content from memory store (loads from file if not loaded)
44
- * Maps to FR-006: Keep AGENTS.md content in memory to avoid repeated reads
45
- */
46
- getContent(path: string): Promise<string>;
47
-
48
- /**
49
- * Update memory content from file
50
- * Maps to FR-007: Update memory content when file changes
51
- */
52
- updateContent(path: string): Promise<void>;
53
-
54
- /**
55
- * Get memory store statistics
56
- * For monitoring and debugging
57
- */
58
- getStats(path?: string): MemoryStoreStats;
59
-
60
- /**
61
- * Check if content is loaded in memory
62
- * For status checking
63
- */
64
- isLoaded(path: string): boolean;
65
-
66
- /**
67
- * Manually reload content from file
68
- * For force refresh scenarios
69
- */
70
- reloadContent(path: string): Promise<void>;
71
-
72
- /**
73
- * Remove content from memory store
74
- * For cleanup when file is deleted
75
- */
76
- removeContent(path: string): boolean;
77
-
78
- /**
79
- * Clear all content from memory store
80
- * For cleanup and testing
81
- */
82
- clear(): void;
83
-
84
- /**
85
- * Get all stored paths
86
- * For monitoring and debugging
87
- */
88
- getStoredPaths(): string[];
89
-
90
- /**
91
- * Check if file exists and is accessible
92
- */
93
- fileExists(path: string): Promise<boolean>;
94
- }
@@ -1,302 +0,0 @@
1
- /**
2
- * Configuration resolver utilities for Agent Constructor Configuration
3
- * Resolves configuration from constructor arguments with environment fallbacks
4
- * Supports live configuration updates and cache invalidation
5
- */
6
-
7
- import {
8
- GatewayConfig,
9
- ModelConfig,
10
- ConfigurationError,
11
- CONFIG_ERRORS,
12
- } from "../types/index.js";
13
- import { DEFAULT_TOKEN_LIMIT } from "./constants.js";
14
- import { loadMergedWaveConfig } from "../services/hook.js";
15
- import { getGlobalLogger } from "./globalLogger.js";
16
-
17
- /**
18
- * Live configuration cache and invalidation support
19
- */
20
- interface ConfigurationCache {
21
- workdir?: string;
22
- lastUpdated: number;
23
- environmentVars: Record<string, string>;
24
- isValid: boolean;
25
- }
26
-
27
- let configCache: ConfigurationCache | null = null;
28
-
29
- /**
30
- * Initialize configuration cache with current environment variables from settings.json
31
- */
32
- function initializeConfigurationCache(workdir?: string): void {
33
- try {
34
- const waveConfig = workdir ? loadMergedWaveConfig(workdir) : null;
35
- const envVars = waveConfig?.env || {};
36
-
37
- configCache = {
38
- workdir,
39
- lastUpdated: Date.now(),
40
- environmentVars: envVars,
41
- isValid: true,
42
- };
43
-
44
- const logger = getGlobalLogger();
45
- logger?.debug(
46
- `Live Config: Configuration cache initialized with ${Object.keys(envVars).length} environment variables`,
47
- );
48
- } catch (error) {
49
- const logger = getGlobalLogger();
50
- logger?.error(
51
- `Live Config: Failed to initialize configuration cache: ${(error as Error).message}`,
52
- );
53
- configCache = {
54
- workdir,
55
- lastUpdated: Date.now(),
56
- environmentVars: {},
57
- isValid: false,
58
- };
59
- }
60
- }
61
-
62
- /**
63
- * Get current environment variable value with live configuration support
64
- */
65
- function getCurrentEnvironmentValue(
66
- key: string,
67
- workdir?: string,
68
- ): string | undefined {
69
- // Initialize cache if not present or workdir changed
70
- if (!configCache || configCache.workdir !== workdir) {
71
- initializeConfigurationCache(workdir);
72
- }
73
-
74
- // Use cached environment variables if available and valid
75
- if (configCache && configCache.isValid) {
76
- const cachedValue = configCache.environmentVars[key];
77
- if (cachedValue !== undefined) {
78
- const logger = getGlobalLogger();
79
- logger?.debug(
80
- `Live Config: Using cached environment variable ${key}=${cachedValue}`,
81
- );
82
- return cachedValue;
83
- }
84
- }
85
-
86
- // Fallback to process environment
87
- return process.env[key];
88
- }
89
-
90
- export class ConfigResolver {
91
- /**
92
- * Resolves gateway configuration from constructor args and environment with live config support
93
- * @param apiKey - API key from constructor (optional)
94
- * @param baseURL - Base URL from constructor (optional)
95
- * @param workdir - Working directory for loading live configuration (optional)
96
- * @returns Resolved gateway configuration
97
- * @throws ConfigurationError if required configuration is missing after fallbacks
98
- */
99
- static resolveGatewayConfig(
100
- apiKey?: string,
101
- baseURL?: string,
102
- workdir?: string,
103
- ): GatewayConfig {
104
- // Resolve API key: constructor > live configuration > environment variable
105
- // Note: Explicitly provided empty strings should be treated as invalid, not fall back to env
106
- let resolvedApiKey: string;
107
- if (apiKey !== undefined) {
108
- resolvedApiKey = apiKey;
109
- } else {
110
- resolvedApiKey = getCurrentEnvironmentValue("AIGW_TOKEN", workdir) || "";
111
- }
112
-
113
- if (!resolvedApiKey && apiKey === undefined) {
114
- const envValue = getCurrentEnvironmentValue("AIGW_TOKEN", workdir);
115
- throw new ConfigurationError(CONFIG_ERRORS.MISSING_API_KEY, "apiKey", {
116
- constructor: apiKey,
117
- environment: envValue,
118
- });
119
- }
120
-
121
- if (resolvedApiKey.trim() === "") {
122
- throw new ConfigurationError(
123
- CONFIG_ERRORS.EMPTY_API_KEY,
124
- "apiKey",
125
- resolvedApiKey,
126
- );
127
- }
128
-
129
- // Resolve base URL: constructor > live configuration > environment variable
130
- // Note: Explicitly provided empty strings should be treated as invalid, not fall back to env
131
- let resolvedBaseURL: string;
132
- if (baseURL !== undefined) {
133
- resolvedBaseURL = baseURL;
134
- } else {
135
- resolvedBaseURL = getCurrentEnvironmentValue("AIGW_URL", workdir) || "";
136
- }
137
-
138
- if (!resolvedBaseURL && baseURL === undefined) {
139
- const envValue = getCurrentEnvironmentValue("AIGW_URL", workdir);
140
- throw new ConfigurationError(CONFIG_ERRORS.MISSING_BASE_URL, "baseURL", {
141
- constructor: baseURL,
142
- environment: envValue,
143
- });
144
- }
145
-
146
- if (resolvedBaseURL.trim() === "") {
147
- throw new ConfigurationError(
148
- CONFIG_ERRORS.EMPTY_BASE_URL,
149
- "baseURL",
150
- resolvedBaseURL,
151
- );
152
- }
153
-
154
- return {
155
- apiKey: resolvedApiKey,
156
- baseURL: resolvedBaseURL,
157
- };
158
- }
159
-
160
- /**
161
- * Resolves model configuration with fallbacks and live config support
162
- * @param agentModel - Agent model from constructor (optional)
163
- * @param fastModel - Fast model from constructor (optional)
164
- * @param workdir - Working directory for loading live configuration (optional)
165
- * @returns Resolved model configuration with defaults
166
- */
167
- static resolveModelConfig(
168
- agentModel?: string,
169
- fastModel?: string,
170
- workdir?: string,
171
- ): ModelConfig {
172
- // Default values as per data-model.md
173
- const DEFAULT_AGENT_MODEL = "claude-sonnet-4-20250514";
174
- const DEFAULT_FAST_MODEL = "gemini-2.5-flash";
175
-
176
- // Resolve agent model: constructor > live configuration > environment > default
177
- const resolvedAgentModel =
178
- agentModel ||
179
- getCurrentEnvironmentValue("AIGW_MODEL", workdir) ||
180
- DEFAULT_AGENT_MODEL;
181
-
182
- // Resolve fast model: constructor > live configuration > environment > default
183
- const resolvedFastModel =
184
- fastModel ||
185
- getCurrentEnvironmentValue("AIGW_FAST_MODEL", workdir) ||
186
- DEFAULT_FAST_MODEL;
187
-
188
- const logger = getGlobalLogger();
189
- logger?.debug(
190
- `Live Config: Resolved models - agent: ${resolvedAgentModel}, fast: ${resolvedFastModel}`,
191
- );
192
-
193
- return {
194
- agentModel: resolvedAgentModel,
195
- fastModel: resolvedFastModel,
196
- };
197
- }
198
-
199
- /**
200
- * Resolves token limit with fallbacks and live config support
201
- * @param constructorLimit - Token limit from constructor (optional)
202
- * @param workdir - Working directory for loading live configuration (optional)
203
- * @returns Resolved token limit
204
- */
205
- static resolveTokenLimit(
206
- constructorLimit?: number,
207
- workdir?: string,
208
- ): number {
209
- // If constructor value provided, use it
210
- if (constructorLimit !== undefined) {
211
- return constructorLimit;
212
- }
213
-
214
- // Try live configuration then environment variable
215
- const envTokenLimit = getCurrentEnvironmentValue("TOKEN_LIMIT", workdir);
216
- if (envTokenLimit) {
217
- const parsed = parseInt(envTokenLimit, 10);
218
- if (!isNaN(parsed)) {
219
- const logger = getGlobalLogger();
220
- logger?.debug(
221
- `Live Config: Resolved token limit from configuration: ${parsed}`,
222
- );
223
- return parsed;
224
- }
225
- }
226
-
227
- // Use default
228
- return DEFAULT_TOKEN_LIMIT;
229
- }
230
-
231
- /**
232
- * Invalidate configuration cache to force reload from settings.json
233
- * @param workdir - Working directory to invalidate cache for (optional)
234
- */
235
- static invalidateCache(workdir?: string): void {
236
- if (
237
- configCache &&
238
- (workdir === undefined || configCache.workdir === workdir)
239
- ) {
240
- const logger = getGlobalLogger();
241
- logger?.info(
242
- `Live Config: Configuration cache invalidated for workdir: ${workdir || "global"}`,
243
- );
244
- configCache = null;
245
- }
246
- }
247
-
248
- /**
249
- * Refresh configuration cache by reloading from settings.json
250
- * @param workdir - Working directory to refresh cache for (optional)
251
- */
252
- static refreshCache(workdir?: string): void {
253
- const logger = getGlobalLogger();
254
- logger?.info(
255
- `Live Config: Refreshing configuration cache for workdir: ${workdir || "global"}`,
256
- );
257
- initializeConfigurationCache(workdir);
258
- }
259
-
260
- /**
261
- * Get current cache status for monitoring
262
- * @returns Cache information or null if no cache
263
- */
264
- static getCacheStatus(): {
265
- workdir?: string;
266
- lastUpdated: number;
267
- envVarCount: number;
268
- isValid: boolean;
269
- } | null {
270
- if (!configCache) {
271
- return null;
272
- }
273
-
274
- return {
275
- workdir: configCache.workdir,
276
- lastUpdated: configCache.lastUpdated,
277
- envVarCount: Object.keys(configCache.environmentVars).length,
278
- isValid: configCache.isValid,
279
- };
280
- }
281
- }
282
-
283
- /**
284
- * Static configuration resolver instance
285
- * Implements ConfigurationResolver interface from types.ts with backward compatibility
286
- */
287
- export const configResolver = {
288
- resolveGatewayConfig: (apiKey?: string, baseURL?: string, workdir?: string) =>
289
- ConfigResolver.resolveGatewayConfig(apiKey, baseURL, workdir),
290
- resolveModelConfig: (
291
- agentModel?: string,
292
- fastModel?: string,
293
- workdir?: string,
294
- ) => ConfigResolver.resolveModelConfig(agentModel, fastModel, workdir),
295
- resolveTokenLimit: (constructorLimit?: number, workdir?: string) =>
296
- ConfigResolver.resolveTokenLimit(constructorLimit, workdir),
297
-
298
- // Live configuration management methods
299
- invalidateCache: ConfigResolver.invalidateCache,
300
- refreshCache: ConfigResolver.refreshCache,
301
- getCacheStatus: ConfigResolver.getCacheStatus,
302
- };