(url: RequestInfo, options: RequestInit)
| 407 | } |
| 408 | |
| 409 | function getHeadersForCacheKey(url: RequestInfo, options: RequestInit) { |
| 410 | const headers = new Headers(getFetchWithProxyHeaders(url, options)); |
| 411 | |
| 412 | // Mirror monkeyPatchFetch so the cache key reflects the Authorization header that |
| 413 | // will actually be sent: fold in the cloud bearer token for cloud-bound requests, |
| 414 | // without overriding a caller-supplied Authorization. |
| 415 | const cloudAuth = getCloudBearerToken(url); |
| 416 | if (cloudAuth && !headers.has('Authorization')) { |
| 417 | headers.set('Authorization', cloudAuth); |
| 418 | } |
| 419 | |
| 420 | const cloudTaskTeamId = getCloudTaskTeamId(url); |
| 421 | if (cloudTaskTeamId && !headers.has(PROMPTFOO_TEAM_ID_HEADER)) { |
| 422 | headers.set(PROMPTFOO_TEAM_ID_HEADER, cloudTaskTeamId); |
| 423 | } |
| 424 | |
| 425 | return Array.from(headers.entries()) |
| 426 | .sort(([nameA, valueA], [nameB, valueB]) => { |
| 427 | const nameComparison = nameA.localeCompare(nameB); |
| 428 | return nameComparison === 0 ? valueA.localeCompare(valueB) : nameComparison; |
| 429 | }) |
| 430 | .map(([name, value]) => [name, getStringForFetchCacheKey(value, name)]); |
| 431 | } |
| 432 | |
| 433 | function hashFetchCacheKey(identity: unknown) { |
| 434 | return sha256(JSON.stringify(identity)); |
no test coverage detected
searching dependent graphs…