wuhp commited on
Commit
8b0af6d
·
verified ·
1 Parent(s): b0c12de

Update services/geminiService.ts

Browse files
Files changed (1) hide show
  1. services/geminiService.ts +16 -5
services/geminiService.ts CHANGED
@@ -1,14 +1,25 @@
1
-
2
-
3
-
4
  import { GoogleGenAI } from "@google/genai";
5
  import { Node, Edge } from 'reactflow';
6
  import { NodeData, LayerType } from '../types';
7
  import { LAYER_DEFINITIONS } from '../constants';
8
 
9
  // Key Management
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  let userApiKey = typeof window !== 'undefined' ? localStorage.getItem('gemini_api_key') || '' : '';
11
- const defaultEnvKey = process.env.API_KEY || '';
12
 
13
  export const setUserApiKey = (key: string) => {
14
  userApiKey = key;
@@ -629,4 +640,4 @@ export const fixArchitectureErrors = async (
629
  } catch (e) {
630
  throw new Error("Patcher agent failed to generate valid JSON.");
631
  }
632
- };
 
 
 
 
1
  import { GoogleGenAI } from "@google/genai";
2
  import { Node, Edge } from 'reactflow';
3
  import { NodeData, LayerType } from '../types';
4
  import { LAYER_DEFINITIONS } from '../constants';
5
 
6
  // Key Management
7
+ const getEnvKey = () => {
8
+ // 1. Try Vite standard env var (Matches Dockerfile VITE_ prefix)
9
+ // @ts-ignore - import.meta is standard in Vite but TS might complain without config
10
+ if (typeof import.meta !== 'undefined' && import.meta.env && import.meta.env.VITE_GEMINI_API_KEY) {
11
+ // @ts-ignore
12
+ return import.meta.env.VITE_GEMINI_API_KEY;
13
+ }
14
+ // 2. Fallback to process.env (Safety check to prevent "process is not defined" crash)
15
+ if (typeof process !== 'undefined' && process.env && process.env.API_KEY) {
16
+ return process.env.API_KEY;
17
+ }
18
+ return '';
19
+ };
20
+
21
  let userApiKey = typeof window !== 'undefined' ? localStorage.getItem('gemini_api_key') || '' : '';
22
+ const defaultEnvKey = getEnvKey();
23
 
24
  export const setUserApiKey = (key: string) => {
25
  userApiKey = key;
 
640
  } catch (e) {
641
  throw new Error("Patcher agent failed to generate valid JSON.");
642
  }
643
+ };