1- import { gemini , gemini as geminiToolModule } from "../../../../src/init/features/aitools/gemini" ;
1+ import {
2+ gemini ,
3+ gemini as geminiToolModule ,
4+ } from "../../../../src/init/features/aitools/gemini" ;
25import * as vscode from "vscode" ;
36import { firebaseConfig } from "../config" ;
47import { ExtensionBrokerImpl } from "../../extension-broker" ;
58import { AnalyticsLogger , DATA_CONNECT_EVENT_NAME } from "../../analytics" ;
69
10+ const GEMINI_EXTENSION_ID = "google.geminicodeassist" ;
711
12+ async function ensureGeminiExtension ( ) : Promise < boolean > {
13+ let geminiExtension = vscode . extensions . getExtension ( GEMINI_EXTENSION_ID ) ;
814
9- export function registerFirebaseMCP ( broker : ExtensionBrokerImpl , analyticsLogger : AnalyticsLogger ) : vscode . Disposable {
15+ if ( geminiExtension ) {
16+ if ( ! geminiExtension . isActive ) {
17+ await geminiExtension . activate ( ) ;
18+ }
19+ return true ;
20+ }
21+
22+ const selection = await vscode . window . showInformationMessage (
23+ "The Firebase Assistant requires the Gemini Code Assist extension. Do you want to install it?" ,
24+ "Yes" ,
25+ "No" ,
26+ ) ;
27+
28+ if ( selection !== "Yes" ) {
29+ vscode . window . showWarningMessage (
30+ "Cannot open Firebase Assistant without the Gemini Code Assist extension." ,
31+ ) ;
32+ return false ;
33+ }
34+
35+ const disposable = vscode . extensions . onDidChange ( async ( ) => {
36+ geminiExtension = vscode . extensions . getExtension ( GEMINI_EXTENSION_ID ) ;
37+ if ( geminiExtension ) {
38+ await openGeminiChat ( ) ;
39+ disposable . dispose ( ) ;
40+ }
41+ } ) ;
42+ vscode . commands . executeCommand (
43+ "workbench.extensions.installExtension" ,
44+ GEMINI_EXTENSION_ID ,
45+ ) ;
46+
47+ return false ;
48+ }
49+
50+ // Writes MCP config, then opens up Gemini with a new chat
51+ async function openGeminiChat ( ) {
52+ writeToGeminiConfig ( ) ;
53+ await vscode . commands . executeCommand ( "cloudcode.gemini.chatView.focus" ) ;
54+ await vscode . commands . executeCommand ( "geminicodeassist.agent.chat.new" ) ;
55+ }
56+
57+ export function registerFirebaseMCP (
58+ broker : ExtensionBrokerImpl ,
59+ analyticsLogger : AnalyticsLogger ,
60+ ) : vscode . Disposable {
1061 const geminiActivateSub = broker . on ( "firebase.activate.gemini" , async ( ) => {
1162 analyticsLogger . logger . logUsage (
1263 DATA_CONNECT_EVENT_NAME . TRY_FIREBASE_AGENT_CLICKED ,
1364 ) ;
14- writeToGeminiConfig ( ) ;
15- await vscode . commands . executeCommand ( "cloudcode.gemini.chatView.focus" ) ;
16- await vscode . commands . executeCommand ( "geminicodeassist.agent.chat.new" ) ; // opens a new chat when an old one exists;
65+
66+ const geminiReady = await ensureGeminiExtension ( ) ;
67+
68+ if ( ! geminiReady ) {
69+ return ;
70+ }
71+ await openGeminiChat ( ) ;
1772 } ) ;
1873
1974 const mcpDocsSub = broker . on ( "docs.mcp.clicked" , ( ) => {
@@ -32,13 +87,14 @@ export function registerFirebaseMCP(broker: ExtensionBrokerImpl, analyticsLogger
3287
3388// Writes the Firebase MCP server to the gemini code assist config file
3489export function writeToGeminiConfig ( ) {
35-
3690 const config = firebaseConfig . value ?. tryReadValue ;
3791 if ( ! config ) {
3892 vscode . window . showErrorMessage ( "Could not read firebase.json" ) ;
3993 // TODO: Consider writing to HOME_DIR in case of this failure
4094 return ;
4195 }
4296
43- geminiToolModule . configure ( config , config . projectDir , [ /** TODO: Create "dataconnect" .md file */ ] ) ;
97+ geminiToolModule . configure ( config , config . projectDir , [
98+ /** TODO: Create "dataconnect" .md file */
99+ ] ) ;
44100}
0 commit comments