Spaces:
Sleeping
Sleeping
Commit ·
726398b
1
Parent(s): 220ebd3
🔧 Fix TypeScript build error in API headers
Browse files✅ Issue Fixed:
- Resolved TS2322 type error in api.ts headers
- Changed from Record<string, string> to proper header merging
- Separated baseHeaders for API key injection
- Maintained compatibility with existing header options
🛠️ Technical Changes:
- Use baseHeaders for type-safe API key addition
- Merge baseHeaders with options?.headers safely
- Prevent TypeScript index signature conflicts
- Ensure build compatibility across environments
- frontend/src/lib/api.ts +13 -9
frontend/src/lib/api.ts
CHANGED
|
@@ -25,19 +25,23 @@ async function fetchApi<T>(
|
|
| 25 |
retryCount = 0
|
| 26 |
): Promise<T> {
|
| 27 |
// Get API key from localStorage if available
|
| 28 |
-
const apiKey = localStorage.getItem(
|
| 29 |
-
const authMode = localStorage.getItem(
|
| 30 |
-
|
| 31 |
-
const
|
| 32 |
"Content-Type": "application/json",
|
| 33 |
-
...options?.headers,
|
| 34 |
};
|
| 35 |
-
|
| 36 |
// Add API key header if user is in API key mode
|
| 37 |
-
if (apiKey && authMode ===
|
| 38 |
-
|
| 39 |
}
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
const response = await fetch(`${API_BASE}${endpoint}`, {
|
| 42 |
headers,
|
| 43 |
...options,
|
|
|
|
| 25 |
retryCount = 0
|
| 26 |
): Promise<T> {
|
| 27 |
// Get API key from localStorage if available
|
| 28 |
+
const apiKey = localStorage.getItem("openai_api_key");
|
| 29 |
+
const authMode = localStorage.getItem("auth_mode");
|
| 30 |
+
|
| 31 |
+
const baseHeaders: Record<string, string> = {
|
| 32 |
"Content-Type": "application/json",
|
|
|
|
| 33 |
};
|
| 34 |
+
|
| 35 |
// Add API key header if user is in API key mode
|
| 36 |
+
if (apiKey && authMode === "api_key") {
|
| 37 |
+
baseHeaders["X-OpenAI-API-Key"] = apiKey;
|
| 38 |
}
|
| 39 |
+
|
| 40 |
+
const headers = {
|
| 41 |
+
...baseHeaders,
|
| 42 |
+
...options?.headers,
|
| 43 |
+
};
|
| 44 |
+
|
| 45 |
const response = await fetch(`${API_BASE}${endpoint}`, {
|
| 46 |
headers,
|
| 47 |
...options,
|