* 工具统计示例
()
| 302 | * 工具统计示例 |
| 303 | */ |
| 304 | async function statsExample() { |
| 305 | console.log('=== 工具统计示例 ===\n'); |
| 306 | |
| 307 | const toolManager = await createToolManager(); |
| 308 | |
| 309 | // 执行一些工具调用以产生统计数据 |
| 310 | await toolManager.callTool({ |
| 311 | toolName: 'uuid', |
| 312 | parameters: { count: 1 }, |
| 313 | }); |
| 314 | |
| 315 | await toolManager.callTool({ |
| 316 | toolName: 'timestamp', |
| 317 | parameters: { operation: 'now' }, |
| 318 | }); |
| 319 | |
| 320 | // 获取统计信息 |
| 321 | const stats = toolManager.getStats(); |
| 322 | console.log('工具统计信息:'); |
| 323 | console.log(JSON.stringify(stats, null, 2)); |
| 324 | console.log(''); |
| 325 | |
| 326 | // 获取执行历史 |
| 327 | const history = toolManager.getExecutionHistory(5); |
| 328 | console.log('最近执行历史:'); |
| 329 | history.forEach((record, index) => { |
| 330 | console.log( |
| 331 | `${index + 1}. ${record.toolName} - ${record.result.success ? '成功' : '失败'} (${record.result.duration}ms)` |
| 332 | ); |
| 333 | }); |
| 334 | console.log(''); |
| 335 | } |
| 336 | |
| 337 | /** |
| 338 | * 主函数 |
no test coverage detected