forked from stackblitz-labs/bolt.diy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: configure dynamic providers via .env (stackblitz-labs#1108)
* Use backend API route to fetch dynamic models # Conflicts: # app/components/chat/BaseChat.tsx * Override ApiKeys if provided in frontend * Remove obsolete artifact * Transport api keys from client to server in header * Cache static provider information * Restore reading provider settings from cookie * Reload only a single provider on api key change * Transport apiKeys and providerSettings via cookies. While doing this, introduce a simple helper function for cookies
- Loading branch information
Showing
8 changed files
with
164 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
export function parseCookies(cookieHeader: string | null) { | ||
const cookies: Record<string, string> = {}; | ||
|
||
if (!cookieHeader) { | ||
return cookies; | ||
} | ||
|
||
// Split the cookie string by semicolons and spaces | ||
const items = cookieHeader.split(';').map((cookie) => cookie.trim()); | ||
|
||
items.forEach((item) => { | ||
const [name, ...rest] = item.split('='); | ||
|
||
if (name && rest.length > 0) { | ||
// Decode the name and value, and join value parts in case it contains '=' | ||
const decodedName = decodeURIComponent(name.trim()); | ||
const decodedValue = decodeURIComponent(rest.join('=').trim()); | ||
cookies[decodedName] = decodedValue; | ||
} | ||
}); | ||
|
||
return cookies; | ||
} | ||
|
||
export function getApiKeysFromCookie(cookieHeader: string | null): Record<string, string> { | ||
const cookies = parseCookies(cookieHeader); | ||
return cookies.apiKeys ? JSON.parse(cookies.apiKeys) : {}; | ||
} | ||
|
||
export function getProviderSettingsFromCookie(cookieHeader: string | null): Record<string, any> { | ||
const cookies = parseCookies(cookieHeader); | ||
return cookies.providers ? JSON.parse(cookies.providers) : {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import { loader } from './api.models'; | ||
export { loader }; |
Oops, something went wrong.