diff --git a/docs/auth.md b/docs/auth.md index eb097bea6e..c15bdca2a4 100644 --- a/docs/auth.md +++ b/docs/auth.md @@ -21,7 +21,7 @@ All flows can define an `authPolicy` in their config. An auth policy is a functi If this field is set, it is executed before the flow is invoked: ```ts -import { defineFlow, runFlow } from '@genkit-ai/flow'; +import { defineFlow } from '@genkit-ai/flow'; export const selfSummaryFlow = defineFlow( { @@ -45,11 +45,10 @@ receive an error: ```ts // Error: Authorization required. -await runFlow(selfSummaryFlow, { uid: 'abc-def' }); +await selfSummaryFlow({ uid: 'abc-def' }); // Error: You may only summarize your own profile data. -await runFlow( - selfSummaryFlow, +await selfSummaryFlow( { uid: 'abc-def' }, { withLocalAuthContext: { uid: 'hij-klm' }, @@ -57,8 +56,7 @@ await runFlow( ); // Success -await runFlow( - selfSummaryFlow, +await selfSummaryFlow( { uid: 'abc-def' }, { withLocalAuthContext: { uid: 'abc-def' }, @@ -223,7 +221,7 @@ Firebase, you'll want to have a way to set up your own authorization checks alongside the native flows. You have two options: 1. Use whatever server framework you like, and pass the auth context through via - `runFlow()` as noted above. + the flow call as noted above. 1. Use the built-in `startFlowsServer()` and provide Express middleware in the flow config: @@ -262,4 +260,4 @@ alongside the native flows. You have two options: instructions. Please note, if you go with (1), you the `middleware` configuration option will -be ignored by `runFlow()`. +be ignored by when the flow is invoked directly. diff --git a/docs/flows.md b/docs/flows.md index 98df428839..649820fdcf 100644 --- a/docs/flows.md +++ b/docs/flows.md @@ -46,10 +46,10 @@ When schema is specified Genkit will validate the schema for inputs and outputs. ## Running flows -Use the `runFlow` function to run the flow: +Run the flow by calling it directly like a normal function: ```js -const response = await runFlow(menuSuggestionFlow, 'French'); +const response = await menuSuggestionFlow('French'); ``` You can use the CLI to run flows as well: @@ -63,35 +63,30 @@ genkit flow:run menuSuggestionFlow '"French"' Here's a simple example of a flow that can stream values from a flow: ```javascript -export const menuSuggestionFlow = defineFlow( +export const menuSuggestionFlow = defineStreamingFlow( { name: 'menuSuggestionFlow', streamSchema: z.string(), }, async (restaurantTheme, streamingCallback) => { - if (streamingCallback) { - makeMenuItemSuggestionsAsync(restaurantTheme).subscribe((suggestion) => { - streamingCallback(suggestion); - }); - } + makeMenuItemSuggestionsAsync(restaurantTheme).subscribe((suggestion) => { + streamingCallback(suggestion); + }); } ); ``` -Note that `streamingCallback` can be undefined. It's only defined if the -invoking client is requesting streamed response. - -To invoke a flow in streaming mode use `streamFlow` function: +To invoke a streaming flow, call it directly like a normal function and stream the results: ```javascript -const response = streamFlow(menuSuggestionFlow, 'French'); +const { stream, output } = menuSuggestionFlow('French'); -for await (const suggestion of response.stream()) { +for await (const suggestion of stream) { console.log('suggestion', suggestion); } -``` -If the flow does not implement streaming `streamFlow` will behave identically to `runFlow`. +console.log('output', await output); +``` You can use the CLI to stream flows as well: diff --git a/docs/nextjs.md b/docs/nextjs.md index 9547e6f4b6..52e80343d4 100644 --- a/docs/nextjs.md +++ b/docs/nextjs.md @@ -111,7 +111,7 @@ Node.js 20 or later. ```ts export async function callMenuSuggestionFlow(theme: string) { - const flowResponse = await runFlow(menuSuggestionFlow, theme); + const flowResponse = await menuSuggestionFlow(theme); console.log(flowResponse); return flowResponse; }