* 生成工具文档
( tools: ToolDefinition[], categories: Record<string, ToolDefinition[]> )
| 393 | * 生成工具文档 |
| 394 | */ |
| 395 | function generateToolDocs( |
| 396 | tools: ToolDefinition[], |
| 397 | categories: Record<string, ToolDefinition[]> |
| 398 | ): string { |
| 399 | let docs = '# 工具文档\n\n'; |
| 400 | docs += `> 总计 ${tools.length} 个工具\n\n`; |
| 401 | docs += '## 目录\n\n'; |
| 402 | |
| 403 | // 生成目录 |
| 404 | for (const [category, categoryTools] of Object.entries(categories)) { |
| 405 | docs += `- [${category.toUpperCase()}](#${category.toLowerCase()}) (${categoryTools.length})\n`; |
| 406 | } |
| 407 | docs += '\n'; |
| 408 | |
| 409 | // 生成详细文档 |
| 410 | for (const [category, categoryTools] of Object.entries(categories)) { |
| 411 | docs += `## ${category.toUpperCase()}\n\n`; |
| 412 | |
| 413 | for (const tool of categoryTools) { |
| 414 | docs += `### ${tool.name}\n\n`; |
| 415 | docs += `${tool.description}\n\n`; |
| 416 | |
| 417 | if (tool.version || tool.author) { |
| 418 | docs += '**元信息:**\n'; |
| 419 | if (tool.version) docs += `- 版本: ${tool.version}\n`; |
| 420 | if (tool.author) docs += `- 作者: ${tool.author}\n`; |
| 421 | docs += '\n'; |
| 422 | } |
| 423 | |
| 424 | if (tool.tags && tool.tags.length > 0) { |
| 425 | docs += `**标签:** \`${tool.tags.join('`、`')}\`\n\n`; |
| 426 | } |
| 427 | |
| 428 | docs += '**参数:**\n\n'; |
| 429 | docs += '| 参数名 | 类型 | 必需 | 默认值 | 描述 |\n'; |
| 430 | docs += '|--------|------|------|--------|------|\n'; |
| 431 | |
| 432 | for (const [paramName, paramSchema] of Object.entries(tool.parameters)) { |
| 433 | const required = tool.required?.includes(paramName) ? '✅' : '❌'; |
| 434 | const defaultValue = paramSchema.default !== undefined ? `\`${paramSchema.default}\`` : '-'; |
| 435 | const description = paramSchema.description || '-'; |
| 436 | |
| 437 | docs += `| \`${paramName}\` | \`${paramSchema.type}\` | ${required} | ${defaultValue} | ${description} |\n`; |
| 438 | } |
| 439 | |
| 440 | docs += '\n---\n\n'; |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | return docs; |
| 445 | } |
| 446 | |
| 447 | /** |
| 448 | * 生成测试参数 |