(pattern: string)
| 145 | * every deeper segment; a mid-pattern `*` covers exactly that segment. |
| 146 | */ |
| 147 | export const dynamicToolScopeForPattern = (pattern: string): DynamicToolScope | null => { |
| 148 | if (pattern === "*") return { integration: null, owner: null, connection: null }; |
| 149 | const segments = pattern.split("."); |
| 150 | const subtree = segments.at(-1) === "*"; |
| 151 | if (!subtree && segments.length < 4) return null; |
| 152 | const at = (index: number): string | null => { |
| 153 | const segment = segments[index]; |
| 154 | if (segment === undefined) return null; |
| 155 | // Only the trailing `*` reaches past its own position; a mid `*` is one |
| 156 | // segment, which is also "any value" for that position. |
| 157 | return segment === "*" ? null : segment; |
| 158 | }; |
| 159 | const owner = at(1); |
| 160 | // A dynamic tool id's owner segment is always `org` or `user`; any other |
| 161 | // literal there names a static namespace (`executor.coreTools.*`). |
| 162 | if (owner !== null && owner !== "org" && owner !== "user") return null; |
| 163 | return { integration: at(0), owner, connection: at(2) }; |
| 164 | }; |
| 165 | |
| 166 | // --------------------------------------------------------------------------- |
| 167 | // Resolution — each owner contributes its first matching rule by local |
no test coverage detected