Closed gregfenton closed 1 month ago
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
@kevinthecheung is this just a docs gap or does it look like a Genkit bug? @mbleigh maybe related to https://github.com/firebase/firebase-functions/issues/1567?
Hi @gregfenton.
It looks like the flow you defined isn't bound to the secret:
export const menuSuggestionFlow = onFlow(
{
name: "menuSuggestionFlow",
inputSchema: z.string(),
outputSchema: z.string(),
httpsOptions: {cors: true},
authPolicy: firebaseAuth((user) => {}),
secrets: [genAiApiKey], # LOOK HERE
},
See the documentation for more info.
It's a common footgun, and I wish there was a more intuitive way to bind secrets to functions. If you have any idea, please let us know.
(FWIW, this issue is unrelated to https://github.com/firebase/firebase-functions/issues/1567)
@taeold I added that line to the onFlow() parameters, but that leads to the error:
Object literal may only specify known properties, and 'secrets' does not exist in type 'FunctionFlowConfig<ZodString, ZodString, ZodTypeAny>'.ts(2353)
Seems that TS is telling the truth.
FYI: I use Cloud Functions and Secrets Manager daily.
It is onFlow()
that is new to me 😁
Is there reference documentation for onFlow()
similar to onCall()
? I can't seem to find it.
@gregfenton Based on https://github.com/firebase/genkit/blob/main/js/plugins/firebase/src/functions.ts#L51, it looks like the correct syntax might be:
export const menuSuggestionFlow = onFlow(
{
name: "menuSuggestionFlow",
inputSchema: z.string(),
outputSchema: z.string(),
httpsOptions: {cors: true, secrets: [genAiApiKey] }, # LOOK HERE
authPolicy: firebaseAuth((user) => {}),
},
Do you mind giving this a try?
Refernce docs would be nice, and I expect them to be incoming!
@taeold That totally fixed it! 🥳
Wasn't obvious to me that HttpOptions
are actually "HTTP Cloud Function options".
Wait....OMG....was this there the whole time? Please tell me this was the Firebase Genkit team just being super responsive and not that I totally can't read/messed up???!!! 🫣
You all rock!
Related issues
Possibly #1567
[REQUIRED] Version info
node:
18.20.2
firebase-functions:
5.0.1
firebase-tools:
13.13.2
firebase-admin:
─ firebase-admin@12.2.0 ─ firebase-functions@5.0.1 ─ firebase-functions-test@3.3.0
─ @genkit-ai/firebase@0.5.6 ─ @genkit-ai/flow@0.5.6
[REQUIRED] Test case
Cloud Functions code:
[REQUIRED] Steps to reproduce
Follow steps from Deploy a flow as a Cloud Function but replace code in
functions/src/index.ts
with:[REQUIRED] Expected behavior
Running web client app returns a generated list of restaurant menu items.
[REQUIRED] Actual behavior
Error is logged to browser's JS Console:
In Logs Explorer I get the error:
Were you able to successfully deploy your functions?
Yes, they deployed fine. And the function
testApiKey
when called from the same HTML client runs fine and displays the proper API key value from the Secrets Manager.