wave-agent-sdk 0.0.6 → 0.0.8

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 (180) hide show
  1. package/dist/agent.d.ts +32 -20
  2. package/dist/agent.d.ts.map +1 -1
  3. package/dist/agent.js +209 -24
  4. package/dist/constants/events.d.ts +28 -0
  5. package/dist/constants/events.d.ts.map +1 -0
  6. package/dist/constants/events.js +27 -0
  7. package/dist/index.d.ts +2 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +2 -0
  10. package/dist/managers/aiManager.d.ts +34 -1
  11. package/dist/managers/aiManager.d.ts.map +1 -1
  12. package/dist/managers/aiManager.js +248 -132
  13. package/dist/managers/backgroundBashManager.d.ts.map +1 -1
  14. package/dist/managers/backgroundBashManager.js +7 -6
  15. package/dist/managers/hookManager.d.ts +13 -16
  16. package/dist/managers/hookManager.d.ts.map +1 -1
  17. package/dist/managers/hookManager.js +81 -44
  18. package/dist/managers/liveConfigManager.d.ts +58 -0
  19. package/dist/managers/liveConfigManager.d.ts.map +1 -0
  20. package/dist/managers/liveConfigManager.js +160 -0
  21. package/dist/managers/messageManager.d.ts +41 -24
  22. package/dist/managers/messageManager.d.ts.map +1 -1
  23. package/dist/managers/messageManager.js +168 -49
  24. package/dist/managers/slashCommandManager.d.ts.map +1 -1
  25. package/dist/managers/slashCommandManager.js +9 -3
  26. package/dist/managers/subagentManager.d.ts +51 -0
  27. package/dist/managers/subagentManager.d.ts.map +1 -1
  28. package/dist/managers/subagentManager.js +190 -19
  29. package/dist/services/aiService.d.ts +13 -5
  30. package/dist/services/aiService.d.ts.map +1 -1
  31. package/dist/services/aiService.js +350 -74
  32. package/dist/services/configurationWatcher.d.ts +120 -0
  33. package/dist/services/configurationWatcher.d.ts.map +1 -0
  34. package/dist/services/configurationWatcher.js +439 -0
  35. package/dist/services/fileWatcher.d.ts +69 -0
  36. package/dist/services/fileWatcher.d.ts.map +1 -0
  37. package/dist/services/fileWatcher.js +213 -0
  38. package/dist/services/hook.d.ts +91 -9
  39. package/dist/services/hook.d.ts.map +1 -1
  40. package/dist/services/hook.js +393 -43
  41. package/dist/services/jsonlHandler.d.ts +62 -0
  42. package/dist/services/jsonlHandler.d.ts.map +1 -0
  43. package/dist/services/jsonlHandler.js +257 -0
  44. package/dist/services/memory.d.ts +9 -0
  45. package/dist/services/memory.d.ts.map +1 -1
  46. package/dist/services/memory.js +81 -12
  47. package/dist/services/memoryStore.d.ts +81 -0
  48. package/dist/services/memoryStore.d.ts.map +1 -0
  49. package/dist/services/memoryStore.js +200 -0
  50. package/dist/services/session.d.ts +64 -49
  51. package/dist/services/session.d.ts.map +1 -1
  52. package/dist/services/session.js +310 -132
  53. package/dist/tools/bashTool.d.ts.map +1 -1
  54. package/dist/tools/bashTool.js +5 -4
  55. package/dist/tools/deleteFileTool.d.ts.map +1 -1
  56. package/dist/tools/deleteFileTool.js +2 -1
  57. package/dist/tools/editTool.d.ts.map +1 -1
  58. package/dist/tools/editTool.js +3 -2
  59. package/dist/tools/multiEditTool.d.ts.map +1 -1
  60. package/dist/tools/multiEditTool.js +4 -3
  61. package/dist/tools/readTool.d.ts.map +1 -1
  62. package/dist/tools/readTool.js +2 -1
  63. package/dist/tools/todoWriteTool.d.ts.map +1 -1
  64. package/dist/tools/todoWriteTool.js +3 -10
  65. package/dist/tools/writeTool.d.ts.map +1 -1
  66. package/dist/tools/writeTool.js +5 -6
  67. package/dist/types/commands.d.ts +4 -0
  68. package/dist/types/commands.d.ts.map +1 -1
  69. package/dist/types/core.d.ts +35 -0
  70. package/dist/types/core.d.ts.map +1 -1
  71. package/dist/types/environment.d.ts +42 -0
  72. package/dist/types/environment.d.ts.map +1 -0
  73. package/dist/types/environment.js +21 -0
  74. package/dist/types/hooks.d.ts +8 -2
  75. package/dist/types/hooks.d.ts.map +1 -1
  76. package/dist/types/hooks.js +8 -2
  77. package/dist/types/index.d.ts +2 -0
  78. package/dist/types/index.d.ts.map +1 -1
  79. package/dist/types/index.js +2 -0
  80. package/dist/types/memoryStore.d.ts +82 -0
  81. package/dist/types/memoryStore.d.ts.map +1 -0
  82. package/dist/types/memoryStore.js +7 -0
  83. package/dist/types/messaging.d.ts +21 -9
  84. package/dist/types/messaging.d.ts.map +1 -1
  85. package/dist/types/messaging.js +5 -1
  86. package/dist/types/session.d.ts +20 -0
  87. package/dist/types/session.d.ts.map +1 -0
  88. package/dist/types/session.js +7 -0
  89. package/dist/utils/bashHistory.d.ts.map +1 -1
  90. package/dist/utils/bashHistory.js +27 -26
  91. package/dist/utils/cacheControlUtils.d.ts +121 -0
  92. package/dist/utils/cacheControlUtils.d.ts.map +1 -0
  93. package/dist/utils/cacheControlUtils.js +367 -0
  94. package/dist/utils/commandPathResolver.d.ts +52 -0
  95. package/dist/utils/commandPathResolver.d.ts.map +1 -0
  96. package/dist/utils/commandPathResolver.js +145 -0
  97. package/dist/utils/configPaths.d.ts +85 -0
  98. package/dist/utils/configPaths.d.ts.map +1 -0
  99. package/dist/utils/configPaths.js +121 -0
  100. package/dist/utils/configResolver.d.ts +37 -10
  101. package/dist/utils/configResolver.d.ts.map +1 -1
  102. package/dist/utils/configResolver.js +127 -23
  103. package/dist/utils/constants.d.ts +1 -1
  104. package/dist/utils/constants.js +1 -1
  105. package/dist/utils/convertMessagesForAPI.d.ts.map +1 -1
  106. package/dist/utils/convertMessagesForAPI.js +8 -13
  107. package/dist/utils/customCommands.d.ts.map +1 -1
  108. package/dist/utils/customCommands.js +66 -21
  109. package/dist/utils/fileUtils.d.ts +15 -0
  110. package/dist/utils/fileUtils.d.ts.map +1 -0
  111. package/dist/utils/fileUtils.js +61 -0
  112. package/dist/utils/globalLogger.d.ts +102 -0
  113. package/dist/utils/globalLogger.d.ts.map +1 -0
  114. package/dist/utils/globalLogger.js +136 -0
  115. package/dist/utils/hookMatcher.d.ts +1 -6
  116. package/dist/utils/hookMatcher.d.ts.map +1 -1
  117. package/dist/utils/mcpUtils.d.ts.map +1 -1
  118. package/dist/utils/mcpUtils.js +25 -3
  119. package/dist/utils/messageOperations.d.ts +27 -27
  120. package/dist/utils/messageOperations.d.ts.map +1 -1
  121. package/dist/utils/messageOperations.js +46 -36
  122. package/dist/utils/pathEncoder.d.ts +104 -0
  123. package/dist/utils/pathEncoder.d.ts.map +1 -0
  124. package/dist/utils/pathEncoder.js +272 -0
  125. package/dist/utils/subagentParser.d.ts.map +1 -1
  126. package/dist/utils/subagentParser.js +2 -1
  127. package/dist/utils/tokenCalculation.d.ts +26 -0
  128. package/dist/utils/tokenCalculation.d.ts.map +1 -0
  129. package/dist/utils/tokenCalculation.js +36 -0
  130. package/package.json +6 -3
  131. package/src/agent.ts +301 -37
  132. package/src/constants/events.ts +38 -0
  133. package/src/index.ts +2 -0
  134. package/src/managers/aiManager.ts +325 -173
  135. package/src/managers/backgroundBashManager.ts +7 -6
  136. package/src/managers/hookManager.ts +106 -84
  137. package/src/managers/liveConfigManager.ts +248 -0
  138. package/src/managers/messageManager.ts +237 -100
  139. package/src/managers/slashCommandManager.ts +9 -7
  140. package/src/managers/subagentManager.ts +284 -22
  141. package/src/services/aiService.ts +474 -83
  142. package/src/services/configurationWatcher.ts +622 -0
  143. package/src/services/fileWatcher.ts +301 -0
  144. package/src/services/hook.ts +538 -47
  145. package/src/services/jsonlHandler.ts +319 -0
  146. package/src/services/memory.ts +92 -12
  147. package/src/services/memoryStore.ts +279 -0
  148. package/src/services/session.ts +381 -157
  149. package/src/tools/bashTool.ts +5 -4
  150. package/src/tools/deleteFileTool.ts +2 -1
  151. package/src/tools/editTool.ts +3 -2
  152. package/src/tools/multiEditTool.ts +4 -3
  153. package/src/tools/readTool.ts +2 -1
  154. package/src/tools/todoWriteTool.ts +3 -11
  155. package/src/tools/writeTool.ts +7 -6
  156. package/src/types/commands.ts +6 -0
  157. package/src/types/core.ts +44 -0
  158. package/src/types/environment.ts +60 -0
  159. package/src/types/hooks.ts +21 -8
  160. package/src/types/index.ts +2 -0
  161. package/src/types/memoryStore.ts +94 -0
  162. package/src/types/messaging.ts +21 -10
  163. package/src/types/session.ts +25 -0
  164. package/src/utils/bashHistory.ts +27 -27
  165. package/src/utils/cacheControlUtils.ts +540 -0
  166. package/src/utils/commandPathResolver.ts +189 -0
  167. package/src/utils/configPaths.ts +163 -0
  168. package/src/utils/configResolver.ts +182 -22
  169. package/src/utils/constants.ts +1 -1
  170. package/src/utils/convertMessagesForAPI.ts +8 -14
  171. package/src/utils/customCommands.ts +90 -22
  172. package/src/utils/fileUtils.ts +65 -0
  173. package/src/utils/globalLogger.ts +145 -0
  174. package/src/utils/hookMatcher.ts +1 -12
  175. package/src/utils/mcpUtils.ts +34 -3
  176. package/src/utils/messageOperations.ts +77 -60
  177. package/src/utils/pathEncoder.ts +379 -0
  178. package/src/utils/subagentParser.ts +2 -1
  179. package/src/utils/tokenCalculation.ts +43 -0
  180. package/src/types/index.ts.backup +0 -357
@@ -0,0 +1,272 @@
1
+ /**
2
+ * Path encoding utility for converting working directory paths to filesystem-safe names
3
+ * Handles cross-platform directory name encoding for project-based session organization
4
+ */
5
+ import { resolve, join } from "path";
6
+ import { createHash } from "crypto";
7
+ import { realpath, mkdir } from "fs/promises";
8
+ import { homedir, platform } from "os";
9
+ /**
10
+ * PathEncoder class for converting working directory paths to filesystem-safe names
11
+ */
12
+ export class PathEncoder {
13
+ constructor(options = {}) {
14
+ this.options = {
15
+ maxLength: options.maxLength ?? 200,
16
+ pathSeparatorReplacement: options.pathSeparatorReplacement ?? "-",
17
+ spaceReplacement: options.spaceReplacement ?? "_",
18
+ invalidCharReplacement: options.invalidCharReplacement ?? "_",
19
+ preserveCase: options.preserveCase ?? false,
20
+ hashLength: options.hashLength ?? 8,
21
+ };
22
+ this.constraints = this.getFilesystemConstraints();
23
+ }
24
+ /**
25
+ * Encode a working directory path to a filesystem-safe directory name
26
+ */
27
+ async encode(originalPath) {
28
+ // Resolve symbolic links and normalize path
29
+ const resolvedPath = await this.resolvePath(originalPath);
30
+ return this.encodeSync(resolvedPath);
31
+ }
32
+ /**
33
+ * Synchronously encode a path to a filesystem-safe directory name
34
+ * Note: Does not resolve symbolic links - use encode() for full path resolution
35
+ */
36
+ encodeSync(pathToEncode) {
37
+ // Convert to safe directory name
38
+ let encoded = pathToEncode;
39
+ // Remove leading slash to avoid empty directory names
40
+ if (encoded.startsWith("/")) {
41
+ encoded = encoded.substring(1);
42
+ }
43
+ // Replace path separators with hyphens
44
+ encoded = encoded.replace(/[/\\]/g, this.options.pathSeparatorReplacement);
45
+ // Replace spaces with underscores
46
+ encoded = encoded.replace(/\s+/g, this.options.spaceReplacement);
47
+ // Replace invalid characters with underscores
48
+ const escapedChars = this.constraints.invalidCharacters
49
+ .map((c) => `\\${c}`)
50
+ .join("");
51
+ const invalidChars = new RegExp(`[${escapedChars}]`, "g");
52
+ encoded = encoded.replace(invalidChars, this.options.invalidCharReplacement);
53
+ // Convert to lowercase unless preserveCase is true
54
+ if (!this.options.preserveCase) {
55
+ encoded = encoded.toLowerCase();
56
+ }
57
+ // Handle length limit with hash
58
+ if (encoded.length > this.options.maxLength) {
59
+ const hash = this.generateHash(pathToEncode, this.options.hashLength);
60
+ const maxBaseLength = this.options.maxLength - this.options.hashLength - 1; // -1 for separator
61
+ encoded = `${encoded.substring(0, maxBaseLength)}-${hash}`;
62
+ }
63
+ return encoded;
64
+ }
65
+ /**
66
+ * Decode an encoded directory name back to original path (limited functionality)
67
+ * Note: This is best-effort as encoding is lossy
68
+ */
69
+ async decode(encodedName) {
70
+ return this.decodeSync(encodedName);
71
+ }
72
+ /**
73
+ * Synchronously decode an encoded directory name back to original path (limited functionality)
74
+ * Note: This is best-effort as encoding is lossy
75
+ */
76
+ decodeSync(encodedName) {
77
+ // This is a simplified version - full reversal is not always possible
78
+ // due to lossy encoding (case changes, character replacements, hashing)
79
+ // Check if this has a hash suffix
80
+ const hashPattern = new RegExp(`-[a-f0-9]{${this.options.hashLength}}$`);
81
+ if (hashPattern.test(encodedName)) {
82
+ // Cannot reliably decode hashed paths
83
+ return null;
84
+ }
85
+ // Attempt basic reversal
86
+ let decoded = encodedName;
87
+ // Reverse path separator replacement
88
+ decoded = decoded.replace(new RegExp(this.options.pathSeparatorReplacement, "g"), "/");
89
+ // Reverse space replacement
90
+ decoded = decoded.replace(new RegExp(this.options.spaceReplacement, "g"), " ");
91
+ // Add leading slash
92
+ decoded = `/${decoded}`;
93
+ return decoded;
94
+ }
95
+ /**
96
+ * Resolve symbolic links and normalize path before encoding
97
+ */
98
+ async resolvePath(path) {
99
+ try {
100
+ // Expand tilde to home directory
101
+ const expandedPath = this.expandTilde(path);
102
+ // Resolve to absolute path
103
+ const absolutePath = resolve(expandedPath);
104
+ // Resolve symbolic links
105
+ const resolvedPath = await realpath(absolutePath);
106
+ return resolvedPath;
107
+ }
108
+ catch (error) {
109
+ throw new Error(`Failed to resolve path "${path}": ${error}`);
110
+ }
111
+ }
112
+ /**
113
+ * Create project directory entity from original path
114
+ */
115
+ async createProjectDirectory(originalPath, baseSessionDir) {
116
+ // Resolve the original path and check for symbolic links
117
+ const expandedPath = this.expandTilde(originalPath);
118
+ const absolutePath = resolve(expandedPath);
119
+ let resolvedPath;
120
+ let isSymbolicLink = false;
121
+ try {
122
+ resolvedPath = await realpath(absolutePath);
123
+ isSymbolicLink = resolvedPath !== absolutePath;
124
+ }
125
+ catch {
126
+ // If realpath fails, use the absolute path
127
+ resolvedPath = absolutePath;
128
+ }
129
+ // Encode the resolved path
130
+ const encodedName = await this.encode(resolvedPath);
131
+ const encodedPath = join(baseSessionDir, encodedName);
132
+ // Generate hash if encoding resulted in truncation
133
+ let pathHash;
134
+ if (resolvedPath.length > this.options.maxLength) {
135
+ pathHash = this.generateHash(resolvedPath, this.options.hashLength);
136
+ }
137
+ // Ensure the encoded directory exists
138
+ try {
139
+ await mkdir(encodedPath, { recursive: true });
140
+ }
141
+ catch {
142
+ // Ignore errors if directory already exists
143
+ }
144
+ return {
145
+ originalPath: resolvedPath,
146
+ encodedName,
147
+ encodedPath,
148
+ pathHash,
149
+ isSymbolicLink,
150
+ };
151
+ }
152
+ /**
153
+ * Validate that an encoded name is filesystem-safe
154
+ */
155
+ validateEncodedName(encodedName) {
156
+ // Check length
157
+ if (encodedName.length > this.constraints.maxDirectoryNameLength) {
158
+ return false;
159
+ }
160
+ // Check for invalid characters
161
+ for (const char of this.constraints.invalidCharacters) {
162
+ if (encodedName.includes(char)) {
163
+ return false;
164
+ }
165
+ }
166
+ // Check for reserved names
167
+ const lowerName = encodedName.toLowerCase();
168
+ if (this.constraints.reservedNames.some((reserved) => reserved.toLowerCase() === lowerName)) {
169
+ return false;
170
+ }
171
+ // Check for empty or dots-only names
172
+ if (!encodedName.trim() || /^\.+$/.test(encodedName)) {
173
+ return false;
174
+ }
175
+ return true;
176
+ }
177
+ /**
178
+ * Handle encoding collisions by generating unique names
179
+ */
180
+ resolveCollision(baseName, existingNames) {
181
+ if (!existingNames.has(baseName)) {
182
+ return baseName;
183
+ }
184
+ // Try numbered suffixes first
185
+ for (let i = 1; i <= 999; i++) {
186
+ const candidate = `${baseName}-${i}`;
187
+ if (!existingNames.has(candidate)) {
188
+ return candidate;
189
+ }
190
+ }
191
+ // If all numbered suffixes are taken, use hash
192
+ const hash = this.generateHash(baseName + Date.now(), this.options.hashLength);
193
+ return `${baseName}-${hash}`;
194
+ }
195
+ /**
196
+ * Get platform-specific filesystem constraints
197
+ */
198
+ getFilesystemConstraints() {
199
+ const currentPlatform = platform();
200
+ switch (currentPlatform) {
201
+ case "win32":
202
+ return {
203
+ maxDirectoryNameLength: 255,
204
+ maxPathLength: 260,
205
+ invalidCharacters: ["<", ">", ":", '"', "|", "?", "*"],
206
+ reservedNames: [
207
+ "CON",
208
+ "PRN",
209
+ "AUX",
210
+ "NUL",
211
+ "COM1",
212
+ "COM2",
213
+ "COM3",
214
+ "COM4",
215
+ "COM5",
216
+ "COM6",
217
+ "COM7",
218
+ "COM8",
219
+ "COM9",
220
+ "LPT1",
221
+ "LPT2",
222
+ "LPT3",
223
+ "LPT4",
224
+ "LPT5",
225
+ "LPT6",
226
+ "LPT7",
227
+ "LPT8",
228
+ "LPT9",
229
+ ],
230
+ caseSensitive: false,
231
+ };
232
+ case "darwin":
233
+ return {
234
+ maxDirectoryNameLength: 255,
235
+ maxPathLength: 1024,
236
+ invalidCharacters: [":"],
237
+ reservedNames: [],
238
+ caseSensitive: false, // HFS+ is case-insensitive by default
239
+ };
240
+ default: // Linux and other Unix-like systems
241
+ return {
242
+ maxDirectoryNameLength: 255,
243
+ maxPathLength: 4096,
244
+ invalidCharacters: ["\0"],
245
+ reservedNames: [],
246
+ caseSensitive: true,
247
+ };
248
+ }
249
+ }
250
+ /**
251
+ * Generate hash for collision resolution
252
+ */
253
+ generateHash(input, length) {
254
+ return createHash("sha256")
255
+ .update(input)
256
+ .digest("hex")
257
+ .substring(0, length);
258
+ }
259
+ /**
260
+ * Expand tilde (~) to home directory
261
+ */
262
+ expandTilde(path) {
263
+ if (path.startsWith("~/") || path === "~") {
264
+ return path.replace(/^~/, homedir());
265
+ }
266
+ return path;
267
+ }
268
+ }
269
+ /**
270
+ * Default PathEncoder instance
271
+ */
272
+ export const pathEncoder = new PathEncoder();
@@ -1 +1 @@
1
- {"version":3,"file":"subagentParser.d.ts","sourceRoot":"","sources":["../../src/utils/subagentParser.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,SAAS,GAAG,MAAM,CAAC;IAC1B,QAAQ,EAAE,MAAM,CAAC;CAClB;AA+KD;;GAEG;AACH,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,qBAAqB,EAAE,CAAC,CAmBlC;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC,CAGvC"}
1
+ {"version":3,"file":"subagentParser.d.ts","sourceRoot":"","sources":["../../src/utils/subagentParser.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,SAAS,GAAG,MAAM,CAAC;IAC1B,QAAQ,EAAE,MAAM,CAAC;CAClB;AA+KD;;GAEG;AACH,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,qBAAqB,EAAE,CAAC,CAmBlC;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC,CAGvC"}
@@ -1,5 +1,6 @@
1
1
  import { readFileSync, readdirSync, statSync } from "fs";
2
2
  import { join, extname } from "path";
3
+ import { logger } from "./globalLogger.js";
3
4
  /**
4
5
  * Parse YAML frontmatter from markdown file content
5
6
  */
@@ -120,7 +121,7 @@ function scanSubagentDirectory(dirPath, scope) {
120
121
  }
121
122
  catch (parseError) {
122
123
  // Log error but continue with other files
123
- console.warn(`Warning: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
124
+ logger.warn(`Warning: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
124
125
  }
125
126
  }
126
127
  }
@@ -0,0 +1,26 @@
1
+ import type { Usage } from "../types/index.js";
2
+ /**
3
+ * Calculate comprehensive total tokens including cache-related tokens
4
+ *
5
+ * This function computes the true total token cost by including:
6
+ * - Base total_tokens (prompt + completion)
7
+ * - Cache read tokens (cost savings indicator)
8
+ * - Cache creation tokens (cache investment)
9
+ *
10
+ * For accurate cost tracking with Claude models that support cache control.
11
+ *
12
+ * @param usage - Usage statistics from AI operation
13
+ * @returns Comprehensive total including all cache-related tokens
14
+ */
15
+ export declare function calculateComprehensiveTotalTokens(usage: Usage): number;
16
+ /**
17
+ * Extract the latest total tokens from the last message with usage data
18
+ * Uses comprehensive calculation that includes cache tokens for accurate tracking
19
+ *
20
+ * @param messages - Array of messages to search
21
+ * @returns Comprehensive total tokens from the most recent usage data, or 0 if none found
22
+ */
23
+ export declare function extractLatestTotalTokens(messages: Array<{
24
+ usage?: Usage;
25
+ }>): number;
26
+ //# sourceMappingURL=tokenCalculation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokenCalculation.d.ts","sourceRoot":"","sources":["../../src/utils/tokenCalculation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C;;;;;;;;;;;;GAYG;AACH,wBAAgB,iCAAiC,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAMtE;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,KAAK,CAAC;IAAE,KAAK,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC,GACjC,MAAM,CAUR"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Calculate comprehensive total tokens including cache-related tokens
3
+ *
4
+ * This function computes the true total token cost by including:
5
+ * - Base total_tokens (prompt + completion)
6
+ * - Cache read tokens (cost savings indicator)
7
+ * - Cache creation tokens (cache investment)
8
+ *
9
+ * For accurate cost tracking with Claude models that support cache control.
10
+ *
11
+ * @param usage - Usage statistics from AI operation
12
+ * @returns Comprehensive total including all cache-related tokens
13
+ */
14
+ export function calculateComprehensiveTotalTokens(usage) {
15
+ const baseTokens = usage.total_tokens;
16
+ const cacheReadTokens = usage.cache_read_input_tokens || 0;
17
+ const cacheCreateTokens = usage.cache_creation_input_tokens || 0;
18
+ return baseTokens + cacheReadTokens + cacheCreateTokens;
19
+ }
20
+ /**
21
+ * Extract the latest total tokens from the last message with usage data
22
+ * Uses comprehensive calculation that includes cache tokens for accurate tracking
23
+ *
24
+ * @param messages - Array of messages to search
25
+ * @returns Comprehensive total tokens from the most recent usage data, or 0 if none found
26
+ */
27
+ export function extractLatestTotalTokens(messages) {
28
+ // Find the last message with usage data (iterate backwards for efficiency)
29
+ for (let i = messages.length - 1; i >= 0; i--) {
30
+ const message = messages[i];
31
+ if (message.usage) {
32
+ return calculateComprehensiveTotalTokens(message.usage);
33
+ }
34
+ }
35
+ return 0; // No usage data found
36
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wave-agent-sdk",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "SDK for building AI-powered development tools and agents",
5
5
  "keywords": [
6
6
  "ai",
@@ -21,12 +21,15 @@
21
21
  "dependencies": {
22
22
  "@modelcontextprotocol/sdk": "^1.18.2",
23
23
  "@vscode/ripgrep": "^1.15.14",
24
+ "chokidar": "^5.0.0",
24
25
  "diff": "^8.0.2",
25
26
  "glob": "^11.0.3",
26
27
  "minimatch": "^10.0.3",
27
- "openai": "^5.12.2"
28
+ "openai": "^5.12.2",
29
+ "uuid": "^13.0.0"
28
30
  },
29
31
  "devDependencies": {
32
+ "@types/uuid": "^11.0.0",
30
33
  "rimraf": "^6.0.1",
31
34
  "tsc-alias": "^1.8.16",
32
35
  "tsx": "^4.20.4",
@@ -39,7 +42,7 @@
39
42
  "scripts": {
40
43
  "build": "rimraf dist && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
41
44
  "type-check": "tsc --noEmit --incremental",
42
- "dev": "tsc -p tsconfig.build.json --watch & tsc-alias -p tsconfig.build.json --watch",
45
+ "watch": "tsc -p tsconfig.build.json --watch & tsc-alias -p tsconfig.build.json --watch",
43
46
  "test": "vitest run",
44
47
  "lint": "eslint --cache",
45
48
  "format": "prettier --write ."