Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions firebase_functions_genkit/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/

# Avoid committing pubspec.lock for library packages; see
# https://dart.dev/guides/libraries/private-files#pubspeclock.
pubspec.lock
3 changes: 3 additions & 0 deletions firebase_functions_genkit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.1.0

- Initial version.
3 changes: 3 additions & 0 deletions firebase_functions_genkit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Extension on firebase functions to use genkit.

Not included in firebase functions itself for more flexibility and reduced deps.
10 changes: 10 additions & 0 deletions firebase_functions_genkit/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
include: package:dart_flutter_team_lints/analysis_options.yaml

linter:
rules:
- prefer_final_locals
- unnecessary_parenthesis
- prefer_expression_function_bodies
- document_ignores
- parameter_assignments
- prefer_final_in_for_each
1 change: 1 addition & 0 deletions firebase_functions_genkit/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sample of creating a genkit flow and setting it up for an http trigger.
51 changes: 51 additions & 0 deletions firebase_functions_genkit/example/bin/example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import 'package:firebase_functions/firebase_functions.dart';
import 'package:firebase_functions_genkit/firebase_functions_genkit.dart';
import 'package:genkit/genkit.dart';
import 'package:genkit_google_genai/genkit_google_genai.dart';

const name = 'jokeTeller';

void main(List<String> args) {
final gemini = googleAI();
final ai = Genkit(plugins: [gemini]);
final flow = ai.defineFlow(
name: name,
inputSchema: .string(),
outputSchema: .string(),
streamSchema: .string(),
Comment thread
mosuem marked this conversation as resolved.
fn: (jokeType, context) async {
final prompt = 'Tell me a $jokeType joke.';

/// gemini.model does not have a generic type
// ignore: inference_failure_on_function_invocation
final stream = ai.generateStream(
model: gemini.model('gemini-2.5-flash'),
prompt: prompt,
);
await stream.forEach((chunk) => context.sendChunk(chunk.text));
return stream.result.text;
Comment thread
mosuem marked this conversation as resolved.
},
);

fireUp(args, (firebase) {
firebase.https.onCallGenkit(
name: name,
flow: flow,
contextProvider: (request) => {'auth': request.auth?.token?['email']},
);
});
}
12 changes: 12 additions & 0 deletions firebase_functions_genkit/example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: example

resolution: workspace

environment:
sdk: ^3.10.0

dependencies:
firebase_functions: any
firebase_functions_genkit: any
genkit: any
genkit_google_genai: any
15 changes: 15 additions & 0 deletions firebase_functions_genkit/lib/firebase_functions_genkit.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

export 'src/firebase_functions_genkit_base.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import 'package:firebase_functions/firebase_functions.dart';
import 'package:genkit/genkit.dart';

/// It's experimental as we can't semver package:meta
// ignore: experimental_member_use
import 'package:meta/meta.dart' show mustBeConst;

/// Extension on [HttpsNamespace] to provide a seamless integration with Genkit.
extension GenkitExt on HttpsNamespace {
/// Registers a Genkit [flow] as a Firebase callable function.
///
/// Automatically handles streaming and non-streaming responses based on
/// [CallableRequest.acceptsStreaming].
///
/// Use [contextProvider] to map properties from the Firebase
/// [CallableRequest] (such as authentication tokens) into the Genkit context.
void onCallGenkit<Output extends Object, Init>({
// Must repeat the name
/// It's experimental as we can't semver package:meta
// ignore: experimental_member_use
@mustBeConst required String name,
required Flow<Object?, Output, Output, Init> flow,
Comment thread
mosuem marked this conversation as resolved.

/// It's experimental as we can't semver package:meta
// ignore: experimental_member_use
@mustBeConst CallableOptions? options = const CallableOptions(),
Map<String, dynamic> Function(CallableRequest<Object?>)? contextProvider,
}) {
/// This is why we restate the name in the params above
// ignore: non_const_argument_for_const_parameter
onCall<Output>(name: name, options: options, (request, response) async {
if (request.acceptsStreaming) {
final actionStream = flow.stream(
request.data,
context: contextProvider?.call(request),
);
await actionStream.forEach((chunk) => response.sendChunk(chunk));
return CallableResult(actionStream.result);
} else {
final run = await flow.run(
request.data,
context: contextProvider?.call(request),
);
return CallableResult(run.result);
}
});
Comment thread
mosuem marked this conversation as resolved.
}
}
20 changes: 20 additions & 0 deletions firebase_functions_genkit/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: firebase_functions_genkit
description: A starting point for Dart libraries or applications.
version: 0.1.0
repository: https://github.com/firebase/firebase-functions-dart

publish_to: none

workspace:
- example

environment:
sdk: ^3.10.0

dependencies:
firebase_functions: ^0.5.0
genkit: ^0.12.1
meta: ^1.18.1

dev_dependencies:
dart_flutter_team_lints: ^3.5.2