({
headers,
baseUrl,
}: {
headers?: globalThis.Headers
baseUrl?: string
})
| 105 | } |
| 106 | |
| 107 | function detectGateway({ |
| 108 | headers, |
| 109 | baseUrl, |
| 110 | }: { |
| 111 | headers?: globalThis.Headers |
| 112 | baseUrl?: string |
| 113 | }): KnownGateway | undefined { |
| 114 | if (headers) { |
| 115 | // Header names are already lowercase from the Headers API |
| 116 | const headerNames: string[] = [] |
| 117 | headers.forEach((_, key) => headerNames.push(key)) |
| 118 | for (const [gw, { prefixes }] of Object.entries(GATEWAY_FINGERPRINTS)) { |
| 119 | if (prefixes.some(p => headerNames.some(h => h.startsWith(p)))) { |
| 120 | return gw as KnownGateway |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | if (baseUrl) { |
| 126 | try { |
| 127 | const host = new URL(baseUrl).hostname.toLowerCase() |
| 128 | for (const [gw, suffixes] of Object.entries(GATEWAY_HOST_SUFFIXES)) { |
| 129 | if (suffixes.some(s => host.endsWith(s))) { |
| 130 | return gw as KnownGateway |
| 131 | } |
| 132 | } |
| 133 | } catch { |
| 134 | // malformed URL — ignore |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | return undefined |
| 139 | } |
| 140 | |
| 141 | function getAnthropicEnvMetadata() { |
| 142 | return { |
no test coverage detected