()
| 29 | } |
| 30 | |
| 31 | function writeToolCallMetricsConfig() { |
| 32 | const outputPath = path.resolve('src/telemetry/tool_call_metrics.json'); |
| 33 | |
| 34 | const dir = path.dirname(outputPath); |
| 35 | if (!fs.existsSync(dir)) { |
| 36 | throw new Error(`Error: Directory ${dir} does not exist.`); |
| 37 | } |
| 38 | |
| 39 | const allTools = createTools( |
| 40 | ServerConfig.applyDefaults({}, {suppressUsageStatisticsNotice: true}), |
| 41 | ); |
| 42 | |
| 43 | if (!haveUniqueNames(allTools)) { |
| 44 | throw new Error('Error: Duplicate tool names found.'); |
| 45 | } |
| 46 | |
| 47 | let existingMetrics: ToolMetric[] = []; |
| 48 | if (fs.existsSync(outputPath)) { |
| 49 | try { |
| 50 | existingMetrics = JSON.parse( |
| 51 | fs.readFileSync(outputPath, 'utf8'), |
| 52 | ) as ToolMetric[]; |
| 53 | } catch { |
| 54 | console.warn( |
| 55 | `Warning: Failed to parse existing metrics from ${outputPath}. Starting fresh.`, |
| 56 | ); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | const newMetrics = generateToolMetrics(allTools); |
| 61 | const mergedMetrics = applyToExistingMetrics(existingMetrics, newMetrics); |
| 62 | |
| 63 | fs.writeFileSync(outputPath, JSON.stringify(mergedMetrics, null, 2) + '\n'); |
| 64 | |
| 65 | console.log( |
| 66 | `Successfully wrote ${mergedMetrics.length} total tool metrics (including deprecated ones) to ${outputPath}`, |
| 67 | ); |
| 68 | } |
| 69 | |
| 70 | function writeFlagUsageMetrics() { |
| 71 | const outputPath = path.resolve('src/telemetry/flag_usage_metrics.json'); |
no test coverage detected