mirror of
https://github.com/stackblitz-labs/bolt.diy
synced 2025-06-26 18:26:38 +00:00
- Move stores/utils/types to their relative directories (i.e chat stores in chat directory) - Move utility files to shared/utils - Move component files to shared/components - Move type definitions to shared/types - Move stores to shared/stores - Update import paths across the project
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import type { LoaderFunction } from '@remix-run/cloudflare';
|
|
import { LLMManager } from '~/shared/lib/providers/manager';
|
|
import { getApiKeysFromCookie } from '~/shared/lib/api/cookies';
|
|
|
|
export const loader: LoaderFunction = async ({ context, request }) => {
|
|
// Get API keys from cookie
|
|
const cookieHeader = request.headers.get('Cookie');
|
|
const apiKeysFromCookie = getApiKeysFromCookie(cookieHeader);
|
|
|
|
// Initialize the LLM manager to access environment variables
|
|
const llmManager = LLMManager.getInstance(context?.cloudflare?.env as any);
|
|
|
|
// Get all provider instances to find their API token keys
|
|
const providers = llmManager.getAllProviders();
|
|
|
|
// Create a comprehensive API keys object
|
|
const apiKeys: Record<string, string> = { ...apiKeysFromCookie };
|
|
|
|
// For each provider, check all possible sources for API keys
|
|
for (const provider of providers) {
|
|
if (!provider.config.apiTokenKey) {
|
|
continue;
|
|
}
|
|
|
|
const envVarName = provider.config.apiTokenKey;
|
|
|
|
// Skip if we already have this provider's key from cookies
|
|
if (apiKeys[provider.name]) {
|
|
continue;
|
|
}
|
|
|
|
// Check environment variables in order of precedence
|
|
const envValue =
|
|
(context?.cloudflare?.env as Record<string, any>)?.[envVarName] ||
|
|
process.env[envVarName] ||
|
|
llmManager.env[envVarName];
|
|
|
|
if (envValue) {
|
|
apiKeys[provider.name] = envValue;
|
|
}
|
|
}
|
|
|
|
return Response.json(apiKeys);
|
|
};
|