defineBidiFlow<Input, Output, Chunk, Init> method

Flow<Input, Output, Chunk, Init> defineBidiFlow<Input, Output, Chunk, Init>({
  1. required String name,
  2. required BidiActionFn<Input, Output, Chunk, Init> fn,
  3. SchemanticType<Input>? inputSchema,
  4. SchemanticType<Output>? outputSchema,
  5. SchemanticType<Chunk>? streamSchema,
  6. SchemanticType<Init>? initSchema,
})

Defines a bi-directional Genkit flow.

Implementation

Flow<Input, Output, Chunk, Init> defineBidiFlow<Input, Output, Chunk, Init>({
  required String name,
  required BidiActionFn<Input, Output, Chunk, Init> fn,
  SchemanticType<Input>? inputSchema,
  SchemanticType<Output>? outputSchema,
  SchemanticType<Chunk>? streamSchema,
  SchemanticType<Init>? initSchema,
}) {
  final flow = Flow(
    name: name,
    fn: (input, context) {
      if (context.inputStream == null) {
        throw GenkitException(
          'Bidi flow $name called without an input stream',
          status: StatusCodes.INVALID_ARGUMENT,
        );
      }
      return fn(context.inputStream!, context);
    },
    inputSchema: inputSchema,
    outputSchema: outputSchema,
    streamSchema: streamSchema,
    initSchema: initSchema,
  );
  registry.register(flow);
  return flow;
}