@genkit-ai/firebase

中文文档
1.44.0发布于 2026/11/04Apache-2.0TypeScriptESM + CJS近 30 天下载 92.1万

Genkit AI framework plugin for Firebase including Firestore trace/state store and deployment helpers for Cloud Functions for Firebase.

原始使用文档
文档目录8 节
  1. Installing the plugin
  2. Telemetry / Monitoring
  3. Durable Streaming (Beta)
  4. Usage
  5. Limitations
  6. Session Store (Beta)
  7. Usage
  8. Options

Firebase plugin for Genkit

The Firebase plugin integrates Genkit with Firebase and Google Cloud. It provides:

  • Telemetry / Monitoring - export traces, metrics, and logs to Google Cloud / Firebase for Genkit monitoring.
  • Durable Streaming (Beta) - persist flow stream state in Firestore or the Realtime Database so streams can be resumed.
  • Session Store (Beta) - persist agent session snapshots in Firestore, sharded and scalable to arbitrarily long sessions.

Building with a coding agent? Install the Genkit JS skill first.

npx skills add genkit-ai/skills --skill developing-genkit-js

It teaches your agent the current Genkit JS APIs and common gotchas. Source, manual install and skills for other languages: genkit-ai/skills.

See also the official docs for deploying Genkit with Firebase.

Installing the plugin

npm i --save @genkit-ai/firebase

Telemetry / Monitoring

Call enableFirebaseTelemetry() to export Genkit traces, metrics, and logs to Google Cloud / Firebase:

import { genkit } from 'genkit';
import { enableFirebaseTelemetry } from '@genkit-ai/firebase';

enableFirebaseTelemetry();

const ai = genkit({
  plugins: [
    // ...
  ],
});

See the monitoring documentation for details.

Durable Streaming (Beta)

This plugin provides two StreamManager implementations for durable streaming:

  • FirestoreStreamManager: Persists stream state in Google Firestore.
  • RtdbStreamManager: Persists stream state in the Firebase Realtime Database.

You can use these with expressHandler or appRoute to make your flow streams durable.

Usage

To use a stream manager, import it from @genkit-ai/firebase/beta and provide it to your flow handler:

import { expressHandler } from '@genkit-ai/express';
import { FirestoreStreamManager } from '@genkit-ai/firebase/beta';
import express from 'express';
import { initializeApp } from 'firebase-admin/app';
import { getFirestore } from 'firebase-admin/firestore';

// ... define your flow: myFlow

const fApp = initializeApp();
const firestore = new FirestoreStreamManager({
  firebaseApp: fApp,
  db: getFirestore(fApp),
  collection: 'streams',
});

const app = express();
app.use(express.json());

app.post('/myDurableFlow', expressHandler(myFlow, { streamManager: firestore }));

app.listen(8080);

Similarly, for the Realtime Database:

import { RtdbStreamManager } from '@genkit-ai/firebase/beta';

const rtdb = new RtdbStreamManager({
  firebaseApp: fApp,
  refPrefix: 'streams',
});

app.post('/myDurableRtdbFlow', expressHandler(myFlow, { streamManager: rtdb }));

Limitations

  • Firestore: The entire stream history (chunks and final result) is stored in a single document. Firestore has a strict 1MB limitation on document size. If your stream output exceeds this limit, the flow will fail.
  • Realtime Database: While RTDB does not have the same 1MB limit, storing very large streams may impact performance or hit other quotas.

Session Store (Beta)

FirestoreSessionStore is a Firestore-backed SessionStore for persisting agent session snapshots. It is a thin Firebase wrapper around the core implementation in @genkit-ai/google-cloud, adding a firebaseApp option for deriving the Firestore instance from a Firebase app. Unlike a naive single-document store, it persists each turn as an incremental JSON Patch diff anchored to periodic, sharded full-state checkpoints, so:

  • No single document approaches Firestore's 1 MiB limit (state is sharded across documents).
  • The number of documents read/written per turn is bounded by checkpointInterval rather than total session length, so it scales to arbitrarily long sessions (e.g. long-lived chatbots, coding agents).
  • Reconstruction uses only document-ID lookups inside a read-only transaction, so it needs no secondary indexes and is strongly consistent.

Usage

Import it from @genkit-ai/firebase/beta and pass it as the store when defining an agent:

import { genkit } from 'genkit/beta';
import { FirestoreSessionStore } from '@genkit-ai/firebase/beta';
import { initializeApp } from 'firebase-admin/app';

const fApp = initializeApp();

const ai = genkit({
  plugins: [
    // ...
  ],
});

const myAgent = ai.defineAgent({
  name: 'myAgent',
  model: 'googleai/gemini-flash-latest',
  system: 'You are a helpful assistant.',
  store: new FirestoreSessionStore({ firebaseApp: fApp }),
});

Options

FirestoreSessionStore accepts the following options:

  • firebaseApp: A Firebase app to derive the Firestore instance from.
  • db: An explicit Firestore instance. Takes precedence over firebaseApp.
  • collection: The collection where snapshot documents are stored. Defaults to "genkit-sessions". Two companion collections are derived from it: "<collection>-pointers" (one pointer document per session) and "<collection>-shards" (the sharded checkpoint state).
  • checkpointInterval: Number of turns between full-state checkpoints. Defaults to 25. Lower it (e.g. 10) for small-state, read-heavy sessions; raise it (e.g. 50-100) for large per-turn state retained for a long time.
  • shardSize: Maximum size in bytes of a single shard / diff document. Defaults to 512 KiB. Any diff exceeding this is promoted to a sharded checkpoint so no document approaches the 1 MiB limit.

The sources for this package are in the main Genkit repo. Please file issues and pull requests against that repo.

Usage information and reference details can be found in Genkit documentation.

License: Apache 2.0

版本与发布记录

@genkit-ai/firebase 共发布 168 个版本,首次发布于 2024/04/05;过去 12 个月发布了 40 个版本。

版本发布日期距今
1.44.0latest2026/11/0412 天前
1.43.02026/10/2225 天前
1.43.0-rc.3next2026/10/2225 天前
1.43.0-rc.22026/10/2126 天前
1.43.0-rc.12026/10/091 个月前
1.43.0-rc.02026/10/091 个月前

关于 @genkit-ai/firebase 的常见问题

@genkit-ai/firebase 是什么?

Genkit AI framework plugin for Firebase including Firestore trace/state store and deployment helpers for Cloud Functions for Firebase.

如何安装 @genkit-ai/firebase?

在项目目录运行 npm install @genkit-ai/firebase,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:genkit(^1.44.0)、firebase-admin(>=12.2)、@google-cloud/firestore(^7.11.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@genkit-ai/firebase 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@genkit-ai/firebase 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@genkit-ai/firebase 可以商用吗?

@genkit-ai/firebase 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@genkit-ai/firebase 的下载量有多少?

根据 npm 官方下载统计,@genkit-ai/firebase 在 2026/10/16 – 2026/11/14 这 30 天内被下载 921,461 次,日均约 30,715 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@genkit-ai/firebase 还在维护吗?

最新版本 1.44.0 发布于 2026/11/04(12 天前);至今共发布 168 个版本,其中过去 12 个月发布了 40 个;首次发布于 2024/04/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。