()
| 354 | } |
| 355 | |
| 356 | function createWwwAuthenticateCaptureFetch() { |
| 357 | let capturedHeader: string | null = null; |
| 358 | |
| 359 | // @ai-sdk/mcp expects a full fetch implementation (including static helpers like |
| 360 | // preconnect), so wrap the call path while preserving the original function shape. |
| 361 | const fetchWithCapture = Object.assign(async (...args: Parameters<typeof fetch>) => { |
| 362 | const response = await fetch(...args); |
| 363 | if (!capturedHeader && (response.status === 401 || response.status === 403)) { |
| 364 | capturedHeader = extractHeaderValue(response.headers, "www-authenticate"); |
| 365 | } |
| 366 | return response; |
| 367 | }, fetch) as typeof fetch; |
| 368 | |
| 369 | return { |
| 370 | fetch: fetchWithCapture, |
| 371 | getCapturedHeader: () => capturedHeader, |
| 372 | }; |
| 373 | } |
| 374 | |
| 375 | async function extractBearerOauthChallenge(options: { |
| 376 | error: unknown; |
no test coverage detected