GenkitRouter class final
Serves a set of Genkit actions over HTTP.
Register actions with addAction (and agents with addAgent from
package:genkit/experimental_io.dart), then plug the router into a server:
final genkit = GenkitRouter()
..addAction(helloFlow)
..addAction(secureFlow, contextProvider: bearerAuth);
// Standalone server:
await genkit.serve();
// Or inside your own dart:io server:
await for (final request in server) {
if (await genkit.handleHttpRequest(request, basePath: '/api')) continue;
// ... your own routes
}
Other frameworks go through handle (package:genkit_shelf does this for
shelf).
Every route is a POST that speaks the Genkit client protocol (see
actionHandler), so defineRemoteAction, defineRemoteModel and
remoteAgent from package:genkit/client.dart can call it.
- Available extensions
Constructors
- GenkitRouter({bool sendLegacyErrorFrame = false})
- Creates an empty router.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sendLegacyErrorFrame → bool
-
Whether failed streams end with the legacy
error:frame that Dart clients frompackage:genkit0.17 and earlier understand.final
Methods
-
addAction(
Action action, {String? path, ContextProvider? contextProvider}) → void -
Serves
actionat POSTpath, which defaults to'/${action.name}'. -
addAgent(
Agent agent, {String? path, ContextProvider? contextProvider, bool hideGetSnapshot = false, bool hideAbort = false}) → void -
Available on GenkitRouter, provided by the GenkitRouterAgents extension
Servesagentusing the layoutremoteAgent(url: '<base><path>')expects. Companion routes are mounted only when the agent supports them: -
handle(
GenkitHttpRequest request) → Future< GenkitHttpResponse?> -
Handles a framework-neutral
request, matching GenkitHttpRequest.path (decoded) exactly against the registered routes. -
handleHttpRequest(
HttpRequest request, {String basePath = '', CorsOptions? cors}) → Future< bool> -
Handles a
dart:iorequestif it targets one of the registered routes, and returns whether it did. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
serve(
{InternetAddress? host, int? port, CorsOptions? cors}) → Future< HttpServer> - Starts a standalone HTTP server for the registered routes.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited