(pattern: string, toolId: string)
| 83 | // --------------------------------------------------------------------------- |
| 84 | |
| 85 | export const matchPattern = (pattern: string, toolId: string): boolean => { |
| 86 | if (pattern === "*") return true; |
| 87 | const patternSegments = pattern.split("."); |
| 88 | const toolSegments = toolId.split("."); |
| 89 | for (let i = 0; i < patternSegments.length; i++) { |
| 90 | const seg = patternSegments[i]!; |
| 91 | if (seg === "*") { |
| 92 | // Trailing `*` is a subtree: the literal prefix already matched, so the |
| 93 | // address matches at this position and anything deeper (or nothing). |
| 94 | if (i === patternSegments.length - 1) return toolSegments.length >= i; |
| 95 | // A non-trailing `*` consumes EXACTLY ONE segment; one must exist here. |
| 96 | if (i >= toolSegments.length) return false; |
| 97 | continue; |
| 98 | } |
| 99 | if (i >= toolSegments.length || toolSegments[i] !== seg) return false; |
| 100 | } |
| 101 | // Pattern exhausted with no trailing `*`: an exact match requires equal length. |
| 102 | return patternSegments.length === toolSegments.length; |
| 103 | }; |
| 104 | |
| 105 | export const isValidPattern = (pattern: string): boolean => { |
| 106 | if (pattern.length === 0) return false; |
no outgoing calls
no test coverage detected