* Build a cache key that is unique per provider+server+key combination. * * - URL-scoped providers include the normalized baseUrl so that two different servers * of the same provider type never share a cache entry. * - Key-scoped providers additionally fold in a short, irreversible discriminat
(options: GetModelsOptions)
| 128 | * Requesty). See deriveApiKeyDiscriminator for why the value cannot be reversed to the key. |
| 129 | */ |
| 130 | function getCacheKey(options: GetModelsOptions): string { |
| 131 | const { provider } = options |
| 132 | const isUrlScoped = URL_SCOPED_PROVIDERS.has(provider as RouterName) |
| 133 | const isKeyScoped = KEY_SCOPED_PROVIDERS.has(provider as RouterName) |
| 134 | |
| 135 | // Build URL and key components independently so that key-scoped providers |
| 136 | // without a custom baseUrl still get a per-key cache entry (otherwise two |
| 137 | // different keys on the default server would collapse to the same entry). |
| 138 | // Strip trailing slashes so "http://host:4000/" and "http://host:4000" map to the same key. |
| 139 | const urlPart = isUrlScoped && options.baseUrl ? options.baseUrl.replace(/\/+$/, "") : undefined |
| 140 | const keyPart = isKeyScoped && options.apiKey ? deriveApiKeyDiscriminator(options.apiKey) : undefined |
| 141 | |
| 142 | if (urlPart && keyPart) return `${provider}:${urlPart}:${keyPart}` |
| 143 | if (urlPart) return `${provider}:${urlPart}` |
| 144 | if (keyPart) return `${provider}:${keyPart}` |
| 145 | return provider |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Convert a cache key to a filesystem-safe filename component. |
no test coverage detected