(text: string, tools: ToolWithAnnotations[])
| 65 | } |
| 66 | |
| 67 | function addCrossLinks(text: string, tools: ToolWithAnnotations[]): string { |
| 68 | let result = text; |
| 69 | |
| 70 | // Create a set of all tool names for efficient lookup |
| 71 | const toolNames = new Set(tools.map(tool => tool.name)); |
| 72 | |
| 73 | // Sort tool names by length (descending) to match longer names first |
| 74 | const sortedToolNames = Array.from(toolNames).sort( |
| 75 | (a, b) => b.length - a.length, |
| 76 | ); |
| 77 | |
| 78 | for (const toolName of sortedToolNames) { |
| 79 | // Create regex to match tool name (case insensitive, word boundaries) |
| 80 | const regex = new RegExp(`\\b${toolName}\\b`, 'gi'); |
| 81 | |
| 82 | result = result.replace(regex, match => { |
| 83 | // Only create link if the match isn't already inside a link |
| 84 | if (result.indexOf(`[${match}]`) !== -1) { |
| 85 | return match; // Already linked |
| 86 | } |
| 87 | const anchorLink = toolName.toLowerCase(); |
| 88 | return `[\`${match}\`](#${anchorLink})`; |
| 89 | }); |
| 90 | } |
| 91 | |
| 92 | return result; |
| 93 | } |
| 94 | |
| 95 | function sortTools(a: ToolWithAnnotations, b: ToolWithAnnotations): number { |
| 96 | const aHasConditions = Boolean(a.annotations?.conditions?.length > 0); |
no test coverage detected