mirror of
https://github.com/voideditor/void
synced 2026-05-24 09:58:23 +00:00
Refactor openAITolerantFetch to improve type handling and compatibility with Electron's global fetch; enhance type safety with explicit casts for OpenAI client fetch arguments.
This commit is contained in:
parent
56a9e7ce20
commit
81ae128320
1 changed files with 9 additions and 3 deletions
|
|
@ -76,8 +76,14 @@ const openAICompatibleErrorMessageFromParsedBody = (parsed: unknown, rawText: st
|
|||
return `HTTP ${status}`
|
||||
}
|
||||
|
||||
const openAITolerantFetch: typeof fetch = async (input, init) => {
|
||||
const res = await globalThis.fetch(input, init as RequestInit)
|
||||
type OpenAIClientFetchArgs = Parameters<NonNullable<ClientOptions['fetch']>>
|
||||
|
||||
/** OpenAI typings use node-fetch shapes in Node; Electron uses global fetch — bridge with explicit casts. */
|
||||
const openAITolerantFetch = (async (url: OpenAIClientFetchArgs[0], init?: OpenAIClientFetchArgs[1]) => {
|
||||
const res = await globalThis.fetch(
|
||||
url as string | URL | Request,
|
||||
init as Parameters<typeof globalThis.fetch>[1],
|
||||
)
|
||||
if (res.ok)
|
||||
return res
|
||||
const rawText = await res.text().catch(() => '')
|
||||
|
|
@ -93,7 +99,7 @@ const openAITolerantFetch: typeof fetch = async (input, init) => {
|
|||
statusText: res.statusText,
|
||||
headers: res.headers,
|
||||
})
|
||||
}
|
||||
}) as unknown as NonNullable<ClientOptions['fetch']>
|
||||
|
||||
// ------------ OPENAI-COMPATIBLE (HELPERS) ------------
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue