io library
Serve Genkit flows, models and other actions over HTTP (dart:io).
import 'package:genkit/io.dart';
final genkit = GenkitRouter()
..addAction(helloFlow)
..addAction(secureFlow, contextProvider: bearerAuth);
await genkit.serve();
Or plug it into your own dart:io server with
GenkitRouter.handleHttpRequest, or serve a single action with
ioHandler. Other HTTP frameworks integrate through the framework-neutral
GenkitRouter.handle, actionHandler and withCors
(package:genkit_shelf is the shelf adapter).
Agents are served with addAgent from the experimental
package:genkit/experimental_io.dart.
Depends on dart:io, so it does not work on the web.
Classes
- CorsOptions
-
CORS settings for
GenkitRouter.serveandGenkitRouter.handleHttpRequest. - GenkitHttpRequest
- A framework-neutral HTTP request, the input of a GenkitHttpHandler.
- GenkitHttpResponse
- A framework-neutral HTTP response, the output of a GenkitHttpHandler.
- GenkitRouter
- Serves a set of Genkit actions over HTTP.
- RequestData
- What a ContextProvider sees of the incoming request.
Functions
-
actionHandler(
Action action, {ContextProvider? contextProvider, bool sendLegacyErrorFrame = false}) → GenkitHttpHandler -
Serves a single
action(flow, model, tool, ...) as a framework-neutral GenkitHttpHandler. -
ioHandler(
Action action, {ContextProvider? contextProvider, bool sendLegacyErrorFrame = false}) → Future< void> Function(HttpRequest request) -
Serves a single
actionas adart:iorequest handler, thedart:iocounterpart of Go'sgenkit.Handler. -
withCors(
CorsOptions options, GenkitHttpRequest request, GenkitHttpHandler inner) → Future< GenkitHttpResponse> -
Applies
optionsaroundinner; answers preflightOPTIONSitself.
Typedefs
-
ContextProvider
= FutureOr<
Map< Function(RequestData request)String, dynamic> > - Builds the action context for a request, typically from auth headers.
-
GenkitHttpHandler
= Future<
GenkitHttpResponse> Function(GenkitHttpRequest request) -
Handles one GenkitHttpRequest. See
actionHandler.