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
@@ -23,7 +23,7 @@ export const USER_MEMORY_FILE = path.join(DATA_DIRECTORY, "user-memory.md");
23
23
  /**
24
24
  * AI related constants
25
25
  */
26
- export const DEFAULT_TOKEN_LIMIT = 64000; // Default token limit
26
+ export const DEFAULT_TOKEN_LIMIT = 96000; // Default token limit
27
27
  /**
28
28
  * @deprecated These constants are now legacy. Use ModelConfig through Agent constructor instead.
29
29
  * They are maintained for backward compatibility with existing code that might still reference them,
@@ -1 +1 @@
1
- {"version":3,"file":"convertMessagesForAPI.d.ts","sourceRoot":"","sources":["../../src/utils/convertMessagesForAPI.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAIjD,OAAO,EAEL,0BAA0B,EAC3B,MAAM,qBAAqB,CAAC;AAuB7B;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,OAAO,EAAE,GAClB,0BAA0B,EAAE,CAsM9B"}
1
+ {"version":3,"file":"convertMessagesForAPI.d.ts","sourceRoot":"","sources":["../../src/utils/convertMessagesForAPI.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAIjD,OAAO,EAEL,0BAA0B,EAC3B,MAAM,qBAAqB,CAAC;AAwB7B;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,OAAO,EAAE,GAClB,0BAA0B,EAAE,CA+L9B"}
@@ -1,5 +1,6 @@
1
1
  import { convertImageToBase64 } from "./messageOperations.js";
2
2
  import { stripAnsiColors } from "./stringUtils.js";
3
+ import { logger } from "./globalLogger.js";
3
4
  /**
4
5
  * Safely handle tool call parameters, ensuring a legal JSON string is returned
5
6
  * @param args Tool call parameters
@@ -14,8 +15,8 @@ function safeToolArguments(args) {
14
15
  JSON.parse(args);
15
16
  return args;
16
17
  }
17
- catch {
18
- // logger.error(`Invalid tool arguments: ${args}`);
18
+ catch (error) {
19
+ logger.error(`Invalid tool arguments: ${args}`, error);
19
20
  // If not valid JSON, return a fallback empty object
20
21
  return "{}";
21
22
  }
@@ -54,8 +55,8 @@ export function convertMessagesForAPI(messages) {
54
55
  const completedToolIds = new Set(); // Record completed tool IDs
55
56
  if (toolBlocks.length > 0) {
56
57
  toolBlocks.forEach((toolBlock) => {
57
- // Only add completed tool blocks (i.e., not running)
58
- if (toolBlock.id && !toolBlock.isRunning) {
58
+ // Only add completed tool blocks (i.e., stage is 'end')
59
+ if (toolBlock.id && toolBlock.stage === "end") {
59
60
  completedToolIds.add(toolBlock.id);
60
61
  // Check for image data
61
62
  if (toolBlock.images && toolBlock.images.length > 0) {
@@ -127,6 +128,7 @@ export function convertMessagesForAPI(messages) {
127
128
  role: "assistant",
128
129
  content,
129
130
  tool_calls,
131
+ ...(message.metadata ? { ...message.metadata } : {}),
130
132
  };
131
133
  recentMessages.unshift(assistantMessage);
132
134
  }
@@ -139,14 +141,7 @@ export function convertMessagesForAPI(messages) {
139
141
  if (block.type === "text" && block.content) {
140
142
  contentParts.push({
141
143
  type: "text",
142
- text: block.content,
143
- });
144
- }
145
- // Handle custom command blocks - pass full content as text to AI
146
- if (block.type === "custom_command" && block.content) {
147
- contentParts.push({
148
- type: "text",
149
- text: block.content,
144
+ text: block.customCommandContent || block.content,
150
145
  });
151
146
  }
152
147
  // If there is an image, add image content
@@ -162,7 +157,7 @@ export function convertMessagesForAPI(messages) {
162
157
  finalImageUrl = convertImageToBase64(imageUrl);
163
158
  }
164
159
  catch (error) {
165
- console.error("Failed to convert image path to base64:", imageUrl, error);
160
+ logger.error("Failed to convert image path to base64:", imageUrl, error);
166
161
  // Skip this image, do not add to content
167
162
  return;
168
163
  }
@@ -1 +1 @@
1
- {"version":3,"file":"customCommands.d.ts","sourceRoot":"","sources":["../../src/utils/customCommands.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAG5D;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AA6CD;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,kBAAkB,EAAE,CAkB7E"}
1
+ {"version":3,"file":"customCommands.d.ts","sourceRoot":"","sources":["../../src/utils/customCommands.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAU5D;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AA0GD;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,kBAAkB,EAAE,CAkB7E"}
@@ -1,7 +1,9 @@
1
- import { existsSync, readdirSync } from "fs";
1
+ import { existsSync, readdirSync, statSync } from "fs";
2
2
  import { join, extname, basename } from "path";
3
3
  import { homedir } from "os";
4
4
  import { parseMarkdownFile } from "./markdownParser.js";
5
+ import { generateCommandId, getCommandSegments, getNamespace, getDepth, } from "./commandPathResolver.js";
6
+ import { logger } from "./globalLogger.js";
5
7
  /**
6
8
  * Get the project-specific commands directory
7
9
  */
@@ -15,39 +17,82 @@ export function getUserCommandsDir() {
15
17
  return join(homedir(), ".wave", "commands");
16
18
  }
17
19
  /**
18
- * Scan a directory for markdown command files
20
+ * Scan a directory for markdown command files with nested directory support
21
+ * @param dirPath - Root commands directory path
22
+ * @param maxDepth - Maximum nesting depth to scan (default: 1)
19
23
  */
20
- function scanCommandsDirectory(dirPath) {
24
+ function scanCommandsDirectory(dirPath, maxDepth = 1) {
21
25
  if (!existsSync(dirPath)) {
22
26
  return [];
23
27
  }
28
+ return scanCommandsDirectoryRecursive(dirPath, dirPath, 0, maxDepth);
29
+ }
30
+ /**
31
+ * Recursively scan directory for commands with depth control
32
+ * @param currentPath - Current directory being scanned
33
+ * @param rootPath - Root commands directory (for relative path calculation)
34
+ * @param currentDepth - Current nesting depth
35
+ * @param maxDepth - Maximum allowed depth
36
+ */
37
+ function scanCommandsDirectoryRecursive(currentPath, rootPath, currentDepth, maxDepth) {
24
38
  const commands = [];
25
39
  try {
26
- const files = readdirSync(dirPath);
27
- for (const file of files) {
28
- if (extname(file) !== ".md") {
29
- continue;
30
- }
31
- const filePath = join(dirPath, file);
32
- const commandName = basename(file, ".md");
40
+ const entries = readdirSync(currentPath);
41
+ for (const entryName of entries) {
42
+ const fullPath = join(currentPath, entryName);
43
+ let isDirectory = false;
44
+ let isFile = false;
33
45
  try {
34
- const { content, config } = parseMarkdownFile(filePath);
35
- commands.push({
36
- id: commandName,
37
- name: commandName,
38
- description: config?.description, // Use description from frontmatter
39
- filePath,
40
- content,
41
- config,
42
- });
46
+ const stats = statSync(fullPath);
47
+ isDirectory = stats.isDirectory();
48
+ isFile = stats.isFile();
43
49
  }
44
50
  catch (error) {
45
- console.warn(`Failed to load custom command from ${filePath}:`, error);
51
+ // Skip entries that cannot be stat'd
52
+ logger.warn(`Cannot access ${fullPath}:`, error);
53
+ continue;
54
+ }
55
+ if (isDirectory) {
56
+ // Skip subdirectories if we're at max depth
57
+ if (currentDepth >= maxDepth) {
58
+ logger.warn(`Skipping directory ${fullPath}: exceeds maximum nesting depth of ${maxDepth}`);
59
+ continue;
60
+ }
61
+ // Recursively scan subdirectory
62
+ const nestedCommands = scanCommandsDirectoryRecursive(fullPath, rootPath, currentDepth + 1, maxDepth);
63
+ commands.push(...nestedCommands);
64
+ }
65
+ else if (isFile && extname(entryName) === ".md") {
66
+ // Process markdown file
67
+ try {
68
+ const commandId = generateCommandId(fullPath, rootPath);
69
+ const segments = getCommandSegments(fullPath, rootPath);
70
+ const namespace = getNamespace(segments);
71
+ const depth = getDepth(segments);
72
+ const { content, config } = parseMarkdownFile(fullPath);
73
+ commands.push({
74
+ id: commandId,
75
+ name: basename(entryName, ".md"),
76
+ description: config?.description,
77
+ filePath: fullPath,
78
+ content,
79
+ config,
80
+ // Nested command metadata
81
+ namespace,
82
+ isNested: depth > 0,
83
+ depth,
84
+ segments,
85
+ });
86
+ }
87
+ catch (error) {
88
+ logger.warn(`Failed to load custom command from ${fullPath}:`, error);
89
+ }
46
90
  }
91
+ // Skip non-markdown files silently
47
92
  }
48
93
  }
49
94
  catch (error) {
50
- console.warn(`Failed to scan commands directory ${dirPath}:`, error);
95
+ logger.warn(`Failed to scan commands directory ${currentPath}:`, error);
51
96
  }
52
97
  return commands;
53
98
  }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Reads the first line of a file efficiently using Node.js readline.
3
+ *
4
+ * @param {string} filePath - The path to the file.
5
+ * @return {Promise<string>} - The first non-empty line of the file, or an empty string otherwise.
6
+ */
7
+ export declare function readFirstLine(filePath: string): Promise<string>;
8
+ /**
9
+ * Reads a file from the end and returns the first non-empty line.
10
+ *
11
+ * @param {string} filePath - The path to the file.
12
+ * @return {Promise<string>} - The last non-empty line of the file, or an empty string if no non-empty lines found.
13
+ */
14
+ export declare function getLastLine(filePath: string): Promise<string>;
15
+ //# sourceMappingURL=fileUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fileUtils.d.ts","sourceRoot":"","sources":["../../src/utils/fileUtils.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAyBrE;AAED;;;;;GAKG;AACH,wBAAsB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAuBnE"}
@@ -0,0 +1,61 @@
1
+ import fs from "node:fs";
2
+ /**
3
+ * Reads the first line of a file efficiently using Node.js readline.
4
+ *
5
+ * @param {string} filePath - The path to the file.
6
+ * @return {Promise<string>} - The first non-empty line of the file, or an empty string otherwise.
7
+ */
8
+ export async function readFirstLine(filePath) {
9
+ const { createReadStream } = fs;
10
+ const { createInterface } = await import("node:readline");
11
+ const fileStream = createReadStream(filePath);
12
+ const rl = createInterface({
13
+ input: fileStream,
14
+ crlfDelay: Infinity, // Handle \r\n properly
15
+ });
16
+ try {
17
+ for await (const line of rl) {
18
+ const trimmedLine = line.trim();
19
+ if (trimmedLine.length > 0) {
20
+ return trimmedLine;
21
+ }
22
+ }
23
+ return "";
24
+ }
25
+ catch {
26
+ // If reading fails (e.g., file doesn't exist), return empty string
27
+ return "";
28
+ }
29
+ finally {
30
+ rl.close();
31
+ fileStream.destroy();
32
+ }
33
+ }
34
+ /**
35
+ * Reads a file from the end and returns the first non-empty line.
36
+ *
37
+ * @param {string} filePath - The path to the file.
38
+ * @return {Promise<string>} - The last non-empty line of the file, or an empty string if no non-empty lines found.
39
+ */
40
+ export async function getLastLine(filePath) {
41
+ const { exec } = await import("child_process");
42
+ const { promisify } = await import("util");
43
+ const execAsync = promisify(exec);
44
+ try {
45
+ // Use tail with multiple lines to handle cases where the last line might be empty
46
+ const { stdout } = await execAsync(`tail -n 3 "${filePath}"`);
47
+ const lines = stdout.split(/\r?\n/);
48
+ // Find the first non-empty line working backwards
49
+ for (let i = lines.length - 1; i >= 0; i--) {
50
+ const line = lines[i].trim();
51
+ if (line.length > 0) {
52
+ return line;
53
+ }
54
+ }
55
+ return "";
56
+ }
57
+ catch {
58
+ // If tail fails (e.g., file doesn't exist), return empty string
59
+ return "";
60
+ }
61
+ }
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Global Logger Registry for Agent SDK
3
+ *
4
+ * Provides zero-overhead logging access for utility functions and services
5
+ * without requiring parameter passing. Maintains singleton logger instance
6
+ * accessible across all SDK modules.
7
+ *
8
+ * Features:
9
+ * - Zero overhead when no logger configured (single null check)
10
+ * - Thread-safe in Node.js single-threaded environment
11
+ * - Maintains backward compatibility with existing Logger interface
12
+ * - Direct function delegation when configured
13
+ */
14
+ import type { Logger } from "../types/core.js";
15
+ /**
16
+ * Configure the global logger instance used by utility functions and services
17
+ *
18
+ * @param logger - Logger instance implementing the Logger interface, or null to disable logging
19
+ * @returns void
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * import { setGlobalLogger } from './utils/globalLogger.js';
24
+ *
25
+ * // Configure logger
26
+ * setGlobalLogger(myLogger);
27
+ *
28
+ * // Disable logging
29
+ * setGlobalLogger(null);
30
+ * ```
31
+ */
32
+ export declare function setGlobalLogger(logger: Logger | null): void;
33
+ /**
34
+ * Retrieve the current global logger instance
35
+ *
36
+ * @returns Current logger instance or null if unconfigured
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * const currentLogger = getGlobalLogger();
41
+ * if (currentLogger) {
42
+ * currentLogger.info('Direct logger access');
43
+ * }
44
+ * ```
45
+ */
46
+ export declare function getGlobalLogger(): Logger | null;
47
+ /**
48
+ * Reset global logger to unconfigured state
49
+ * Equivalent to setGlobalLogger(null)
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * clearGlobalLogger(); // All subsequent logging calls become no-ops
54
+ * ```
55
+ */
56
+ export declare function clearGlobalLogger(): void;
57
+ /**
58
+ * Check if global logger is currently configured
59
+ *
60
+ * @returns true if logger configured, false otherwise
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * if (isLoggerConfigured()) {
65
+ * // Perform expensive logging operation
66
+ * const debugInfo = generateDebugInfo();
67
+ * logger.debug(debugInfo);
68
+ * }
69
+ * ```
70
+ */
71
+ export declare function isLoggerConfigured(): boolean;
72
+ /**
73
+ * Zero-overhead logging interface
74
+ *
75
+ * Performance characteristics:
76
+ * - Unconfigured: Single null check + early return (near-zero cost)
77
+ * - Configured: Null check + function delegation
78
+ * - No object creation or intermediate allocations
79
+ */
80
+ export declare const logger: {
81
+ /**
82
+ * Log debug-level message through global logger
83
+ * No-op when global logger is null (zero overhead)
84
+ */
85
+ readonly debug: (...args: unknown[]) => void;
86
+ /**
87
+ * Log info-level message through global logger
88
+ * No-op when global logger is null (zero overhead)
89
+ */
90
+ readonly info: (...args: unknown[]) => void;
91
+ /**
92
+ * Log warning-level message through global logger
93
+ * No-op when global logger is null (zero overhead)
94
+ */
95
+ readonly warn: (...args: unknown[]) => void;
96
+ /**
97
+ * Log error-level message through global logger
98
+ * No-op when global logger is null (zero overhead)
99
+ */
100
+ readonly error: (...args: unknown[]) => void;
101
+ };
102
+ //# sourceMappingURL=globalLogger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"globalLogger.d.ts","sourceRoot":"","sources":["../../src/utils/globalLogger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAa/C;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAE3D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,IAAI,MAAM,GAAG,IAAI,CAE/C;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAExC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,IAAI,OAAO,CAE5C;AAMD;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM;IACjB;;;OAGG;8BACc,OAAO,EAAE,KAAG,IAAI;IAKjC;;;OAGG;6BACa,OAAO,EAAE,KAAG,IAAI;IAKhC;;;OAGG;6BACa,OAAO,EAAE,KAAG,IAAI;IAKhC;;;OAGG;8BACc,OAAO,EAAE,KAAG,IAAI;CAIzB,CAAC"}
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Global Logger Registry for Agent SDK
3
+ *
4
+ * Provides zero-overhead logging access for utility functions and services
5
+ * without requiring parameter passing. Maintains singleton logger instance
6
+ * accessible across all SDK modules.
7
+ *
8
+ * Features:
9
+ * - Zero overhead when no logger configured (single null check)
10
+ * - Thread-safe in Node.js single-threaded environment
11
+ * - Maintains backward compatibility with existing Logger interface
12
+ * - Direct function delegation when configured
13
+ */
14
+ /**
15
+ * Module-level storage for the global logger instance
16
+ * null = unconfigured (logging calls are no-ops)
17
+ * Logger = configured (calls are forwarded)
18
+ */
19
+ let globalLogger = null;
20
+ // =============================================================================
21
+ // Registry Management API
22
+ // =============================================================================
23
+ /**
24
+ * Configure the global logger instance used by utility functions and services
25
+ *
26
+ * @param logger - Logger instance implementing the Logger interface, or null to disable logging
27
+ * @returns void
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * import { setGlobalLogger } from './utils/globalLogger.js';
32
+ *
33
+ * // Configure logger
34
+ * setGlobalLogger(myLogger);
35
+ *
36
+ * // Disable logging
37
+ * setGlobalLogger(null);
38
+ * ```
39
+ */
40
+ export function setGlobalLogger(logger) {
41
+ globalLogger = logger;
42
+ }
43
+ /**
44
+ * Retrieve the current global logger instance
45
+ *
46
+ * @returns Current logger instance or null if unconfigured
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * const currentLogger = getGlobalLogger();
51
+ * if (currentLogger) {
52
+ * currentLogger.info('Direct logger access');
53
+ * }
54
+ * ```
55
+ */
56
+ export function getGlobalLogger() {
57
+ return globalLogger;
58
+ }
59
+ /**
60
+ * Reset global logger to unconfigured state
61
+ * Equivalent to setGlobalLogger(null)
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * clearGlobalLogger(); // All subsequent logging calls become no-ops
66
+ * ```
67
+ */
68
+ export function clearGlobalLogger() {
69
+ globalLogger = null;
70
+ }
71
+ /**
72
+ * Check if global logger is currently configured
73
+ *
74
+ * @returns true if logger configured, false otherwise
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * if (isLoggerConfigured()) {
79
+ * // Perform expensive logging operation
80
+ * const debugInfo = generateDebugInfo();
81
+ * logger.debug(debugInfo);
82
+ * }
83
+ * ```
84
+ */
85
+ export function isLoggerConfigured() {
86
+ return globalLogger !== null;
87
+ }
88
+ // =============================================================================
89
+ // Zero-Overhead Logging API
90
+ // =============================================================================
91
+ /**
92
+ * Zero-overhead logging interface
93
+ *
94
+ * Performance characteristics:
95
+ * - Unconfigured: Single null check + early return (near-zero cost)
96
+ * - Configured: Null check + function delegation
97
+ * - No object creation or intermediate allocations
98
+ */
99
+ export const logger = {
100
+ /**
101
+ * Log debug-level message through global logger
102
+ * No-op when global logger is null (zero overhead)
103
+ */
104
+ debug: (...args) => {
105
+ if (globalLogger === null)
106
+ return;
107
+ globalLogger.debug(...args);
108
+ },
109
+ /**
110
+ * Log info-level message through global logger
111
+ * No-op when global logger is null (zero overhead)
112
+ */
113
+ info: (...args) => {
114
+ if (globalLogger === null)
115
+ return;
116
+ globalLogger.info(...args);
117
+ },
118
+ /**
119
+ * Log warning-level message through global logger
120
+ * No-op when global logger is null (zero overhead)
121
+ */
122
+ warn: (...args) => {
123
+ if (globalLogger === null)
124
+ return;
125
+ globalLogger.warn(...args);
126
+ },
127
+ /**
128
+ * Log error-level message through global logger
129
+ * No-op when global logger is null (zero overhead)
130
+ */
131
+ error: (...args) => {
132
+ if (globalLogger === null)
133
+ return;
134
+ globalLogger.error(...args);
135
+ },
136
+ };
@@ -4,12 +4,7 @@
4
4
  * Provides pattern matching functionality for hook tool name matching.
5
5
  * Supports exact matching, wildcard patterns, and pipe-separated alternatives.
6
6
  */
7
- export interface IHookMatcher {
8
- matches(pattern: string, toolName: string): boolean;
9
- isValidPattern(pattern: string): boolean;
10
- getPatternType(pattern: string): "exact" | "glob" | "regex" | "alternatives";
11
- }
12
- export declare class HookMatcher implements IHookMatcher {
7
+ export declare class HookMatcher {
13
8
  /**
14
9
  * Test if pattern matches tool name
15
10
  * Supports multiple matching strategies:
@@ -1 +1 @@
1
- {"version":3,"file":"hookMatcher.d.ts","sourceRoot":"","sources":["../../src/utils/hookMatcher.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,MAAM,WAAW,YAAY;IAE3B,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;IAGpD,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;IAGzC,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,cAAc,CAAC;CAC9E;AAED,qBAAa,WAAY,YAAW,YAAY;IAC9C;;;;;;;OAOG;IACH,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO;IAYnD;;OAEG;IACH,OAAO,CAAC,aAAa;IAmBrB;;OAEG;IACH,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAoBxC;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAmB5B;;OAEG;IACH,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,cAAc;IA6B5E;;;OAGG;IACH,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE;IAI1D;;;OAGG;IACH,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO;CAkCxD"}
1
+ {"version":3,"file":"hookMatcher.d.ts","sourceRoot":"","sources":["../../src/utils/hookMatcher.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,qBAAa,WAAW;IACtB;;;;;;;OAOG;IACH,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO;IAYnD;;OAEG;IACH,OAAO,CAAC,aAAa;IAmBrB;;OAEG;IACH,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAoBxC;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAmB5B;;OAEG;IACH,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,cAAc;IA6B5E;;;OAGG;IACH,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE;IAI1D;;;OAGG;IACH,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO;CAkCxD"}
@@ -1 +1 @@
1
- {"version":3,"file":"mcpUtils.d.ts","sourceRoot":"","sources":["../../src/utils/mcpUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,KAAK,EAAE,UAAU,EAA2B,MAAM,mBAAmB,CAAC;AAC7E,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAElE;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,MAAM,GACjB,0BAA0B,CAa5B;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,CACX,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC1B,OAAO,CAAC;IACX,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACtD,CAAC,GACD,UAAU,CA2BZ;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,eAAe,EAAE,GACzB,eAAe,GAAG,SAAS,CAK7B"}
1
+ {"version":3,"file":"mcpUtils.d.ts","sourceRoot":"","sources":["../../src/utils/mcpUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,KAAK,EAAE,UAAU,EAA2B,MAAM,mBAAmB,CAAC;AAC7E,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAgClE;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,MAAM,GACjB,0BAA0B,CAc5B;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,CACX,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC1B,OAAO,CAAC;IACX,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACtD,CAAC,GACD,UAAU,CA2BZ;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,eAAe,EAAE,GACzB,eAAe,GAAG,SAAS,CAK7B"}
@@ -1,10 +1,32 @@
1
+ /**
2
+ * Recursively clean schema to remove unsupported fields
3
+ */
4
+ function cleanSchema(schema) {
5
+ if (typeof schema !== "object" || schema === null) {
6
+ return schema;
7
+ }
8
+ if (Array.isArray(schema)) {
9
+ return schema.map(cleanSchema);
10
+ }
11
+ const newSchema = {};
12
+ const obj = schema;
13
+ for (const key in obj) {
14
+ // Remove $schema as OpenAI API doesn't accept it
15
+ // Remove exclusiveMinimum/exclusiveMaximum as some models (e.g. Gemini) don't support them
16
+ if (key === "$schema" ||
17
+ key === "exclusiveMinimum" ||
18
+ key === "exclusiveMaximum") {
19
+ continue;
20
+ }
21
+ newSchema[key] = cleanSchema(obj[key]);
22
+ }
23
+ return newSchema;
24
+ }
1
25
  /**
2
26
  * Convert MCP tool to OpenAI function tool format
3
27
  */
4
28
  export function mcpToolToOpenAITool(mcpTool, serverName) {
5
- // Remove $schema field if it exists, as OpenAI API doesn't accept it
6
- const cleanInputSchema = { ...mcpTool.inputSchema };
7
- delete cleanInputSchema.$schema;
29
+ const cleanInputSchema = cleanSchema(mcpTool.inputSchema);
8
30
  return {
9
31
  type: "function",
10
32
  function: {