Open History to see the last commit
1/**
2 * Extract `headers` and `signal` from a `Request | RequestInit` for the
3 * OpenRouter SDK's per-call request-options. `Request` exposes `headers` as a
4 * `Headers` instance (HeadersInit-compatible) while `RequestInit` exposes
5 * `HeadersInit` directly — this helper accepts either shape so callers don't
6 * need to cast.
7 *
8 * Always returns an object (possibly empty) rather than `undefined` so test
9 * assertions that match the second argument shape via `expect.anything()` /
10 * `expect.objectContaining()` keep working when no request override was set.
11 */
12export function extractRequestOptions(
13 request: Request | RequestInit | undefined,
14): { headers?: HeadersInit; signal?: AbortSignal | null } {
15 if (!request) return {}
16 return {
17 ...(request.headers !== undefined && { headers: request.headers }),
18 ...(request.signal !== undefined && { signal: request.signal }),
19 }
20}