From 4282383913fb42f1b5ac1645626359ab847b73f2 Mon Sep 17 00:00:00 2001 From: Konstantin Mandrika Date: Mon, 15 Jul 2024 14:41:06 -0400 Subject: [PATCH 1/2] Handle lack of project id in the firebase plugin in dev. --- js/plugins/firebase/src/index.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/js/plugins/firebase/src/index.ts b/js/plugins/firebase/src/index.ts index bda9a99e5e..f4a55f0fa1 100644 --- a/js/plugins/firebase/src/index.ts +++ b/js/plugins/firebase/src/index.ts @@ -15,6 +15,7 @@ */ import { genkitPlugin, Plugin } from '@genkit-ai/core'; +import { logger } from '@genkit-ai/core/logging'; import { FirestoreStateStore } from '@genkit-ai/flow'; import { GcpLogger, @@ -43,7 +44,7 @@ export const firebase: Plugin<[FirestorePluginParams] | []> = genkitPlugin( async (params?: FirestorePluginParams) => { const authClient = new GoogleAuth(); const gcpOptions = { - projectId: params?.projectId || (await authClient.getProjectId()), + projectId: params?.projectId || (await getProjectId(authClient)), telemetryConfig: params?.telemetryConfig, }; return { @@ -68,3 +69,14 @@ export const firebase: Plugin<[FirestorePluginParams] | []> = genkitPlugin( }; } ); + +async function getProjectId(authClient: GoogleAuth): Promise { + if (process.env.GENKIT_ENV === 'dev') { + return await authClient.getProjectId().catch((err) => { + logger.warn('run gcloud auth application-default login'); + return ''; + }); + } + + return await authClient.getProjectId(); +} From f5c7d1c54467a9f0a136608b5019a45b5adf6295 Mon Sep 17 00:00:00 2001 From: Konstantin Mandrika Date: Mon, 15 Jul 2024 15:18:38 -0400 Subject: [PATCH 2/2] Apply feedback --- js/plugins/firebase/src/index.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/js/plugins/firebase/src/index.ts b/js/plugins/firebase/src/index.ts index f4a55f0fa1..2979415710 100644 --- a/js/plugins/firebase/src/index.ts +++ b/js/plugins/firebase/src/index.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { genkitPlugin, Plugin } from '@genkit-ai/core'; +import { genkitPlugin, isDevEnv, Plugin } from '@genkit-ai/core'; import { logger } from '@genkit-ai/core/logging'; import { FirestoreStateStore } from '@genkit-ai/flow'; import { @@ -71,9 +71,11 @@ export const firebase: Plugin<[FirestorePluginParams] | []> = genkitPlugin( ); async function getProjectId(authClient: GoogleAuth): Promise { - if (process.env.GENKIT_ENV === 'dev') { + if (isDevEnv()) { return await authClient.getProjectId().catch((err) => { - logger.warn('run gcloud auth application-default login'); + logger.warn( + 'WARNING: unable to determine Project ID, run "gcloud auth application-default login --project MY_PROJECT_ID"' + ); return ''; }); }