@@ -134,7 +134,7 @@ function initCollaborativeWorkspace(io) {
134134 } ) ;
135135
136136 // Ephemeral session chat messages (includes media)
137- socket . on ( 'send-message' , ( { text, media } ) => {
137+ socket . on ( 'send-message' , ( { text, media, userApiKey , userGroqKey } ) => {
138138 const { roomId } = socket ;
139139 if ( ! roomId ) return ;
140140
@@ -159,7 +159,7 @@ function initCollaborativeWorkspace(io) {
159159
160160 // Trigger ForgeAI if message targets the agent
161161 if ( text && text . trim ( ) . toLowerCase ( ) . startsWith ( '@forgeai' ) ) {
162- handleForgeAIMessage ( roomId , io , text ) ;
162+ handleForgeAIMessage ( roomId , io , text , userApiKey , userGroqKey ) ;
163163 }
164164 } ) ;
165165
@@ -396,7 +396,7 @@ function parseJsonResponse(text) {
396396}
397397
398398// Background handler for ForgeAI interaction
399- async function handleForgeAIMessage ( roomId , io , text ) {
399+ async function handleForgeAIMessage ( roomId , io , text , userApiKey , userGroqKey ) {
400400 const workspace = workspaces . get ( roomId ) ;
401401 if ( ! workspace ) return ;
402402
@@ -415,8 +415,8 @@ async function handleForgeAIMessage(roomId, io, text) {
415415 io . to ( roomId ) . emit ( 'new-message' , tempMessageObj ) ;
416416
417417 try {
418- const geminiApiKey = process . env . GEMINI_API_KEY ;
419- const groqApiKey = process . env . GROQ_API_KEY ;
418+ const geminiApiKey = process . env . GEMINI_API_KEY || userApiKey ;
419+ const groqApiKey = process . env . GROQ_API_KEY || userGroqKey ;
420420
421421 if ( ! geminiApiKey && ! groqApiKey ) {
422422 throw new Error ( "No Gemini or Groq API key configured on the server." ) ;
0 commit comments