feat(web): chat + llmAdmin api clients with FormData support

This commit is contained in:
2026-05-04 19:48:26 +08:00
parent 8effeee063
commit 00daad07a9
3 changed files with 298 additions and 2 deletions
+9 -2
View File
@@ -21,10 +21,11 @@ export function configure(opts: {
}
export async function request<T>(path: string, opts: RequestOptions = {}): Promise<T> {
const isForm = opts.body instanceof FormData
const headers: Record<string, string> = {
'Content-Type': 'application/json',
'X-Client-Request-ID': crypto.randomUUID(),
}
if (!isForm) headers['Content-Type'] = 'application/json'
const token = authTokenProvider()
if (token) headers['Authorization'] = `Bearer ${token}`
@@ -39,10 +40,16 @@ export async function request<T>(path: string, opts: RequestOptions = {}): Promi
}
try {
const body =
opts.body === undefined
? undefined
: isForm
? (opts.body as FormData)
: JSON.stringify(opts.body)
const resp = await fetch(BASE + path, {
method: opts.method || 'GET',
headers,
body: opts.body !== undefined ? JSON.stringify(opts.body) : undefined,
body,
signal: controller.signal,
})