extension-to-functions-codebase

作成者: firebase

インストール済みのFirebase Extension(または拡張機能のソース)を、スタンドアロンのCloud Functions for Firebaseコードベース、または公開可能なnpmパッケージに変換するためのスキル、…

npx skills add https://github.com/firebase/agent-skills --skill extension-to-functions-codebase

Extension to Functions Codebase & npm Package Migration

Overview

Migrates a Firebase Extension into either:

  1. A local Cloud Functions codebase (functions/src/ for app integration).
  2. A publishable npm package (reusable open-source package exporting V2 functions).

Leverages native Cloud Functions features (declarative IAM, Parameterized Config, SDK Lifecycle Hooks) and modernizes 1st Gen triggers to 2nd Gen using the Destructuring Compatibility Shim.


Target Migration Workflows

  • Target A: Local Functions Codebase (End-User App Integration)

    • Output: Code under functions/src/. Config in .env.
    • Deployment: firebase deploy --only functions.
  • Target B: Publishable npm Package / Shareable Package

    • Output: Reusable npm package exporting V2 functions.
    • Configuration: package.json specifying exports map, engines: { "node": ">=22" }, and peerDependencies: { "firebase-functions": ">=6.0.0" }.
    • Usage: Consumers install package and re-export functions in index.ts (export * from "<package-name>").

Core Rules & Constraints

1. Declarative IAM & APIs (Zero-Local-Overhead)

Use native SDK declarations instead of manual gcloud scripts or console instructions:

  • Use requiresRole("roles/...") for required GCP IAM permissions.
  • Use requiresAPI("service.googleapis.com", "Description") for Google APIs.

2. Global Parameter Access Restriction

  • Never call .value() at top-level module load scope.
  • Initialize global SDK instances inside onInit() or lazy getters:
    import { defineString } from "firebase-functions/params";
    import { onInit } from "firebase-functions/v2";
    
    const dataset = defineString("DATASET_ID");
    let client: BigQuery;
    
    onInit(() => {
      client = new BigQuery({ datasetId: dataset.value() });
    });
    

3. V2 Concurrency & Cost Parity

V2 enables concurrency (up to 80 requests). To preserve V1 single-concurrency pricing, set cpu: "gcf_gen1".


Step-by-Step Migration Execution

Step 1: Inventory Extension Resources

  1. extension.yaml:
    • paramsdefineString, defineInt, defineBoolean, defineSecret.
    • apisrequiresAPI(...).
    • rolesrequiresRole(...).
    • lifecycleEventsafterFirstDeploy & afterRedeploy.
    • resources → Upgrade 1st Gen triggers to 2nd Gen (onDocumentWritten, onTaskDispatched, onRequest).
  2. Files & Scripts: Preserve devDependencies, test framework (jest), and test scripts.

Step 2: Configure package.json

  • Set name: "<package-name>", engines: { "node": ">=22" }.
  • Set peerDependencies:
    "peerDependencies": {
      "firebase-admin": "^11.0.0 || ^12.0.0",
      "firebase-functions": ">=6.0.0"
    }
    
  • Configure exports map targeting ESM/CommonJS and TypeScript declarations (lib/index.js, lib/index.d.ts).

Step 3: Upgrade Triggers from V1 to V2

  • Firestore: Use onDocumentWritten from firebase-functions/v2/firestore.
  • Tasks: Use onTaskDispatched from firebase-functions/v2/tasks. Remove EXT_INSTANCE_ID when enqueueing tasks.
  • HTTP: Use onRequest from firebase-functions/v2/https.
  • Apply Destructuring Compatibility Shim ({ change, context }, { snapshot, context }) where legacy 1st Gen handlers expect (change, context).

Step 4: Convert Lifecycle Events

Map extension lifecycle events to SDK lifecycle hooks in src/index.ts:

  • onInstallafterFirstDeploy({ task: { function: "initTask" } })
  • onUpdate / onConfigureafterRedeploy({ task: { function: "setupTask" } })

Step 5: Package README & Export Instructions

Generate README.md containing:

  1. Installation instructions (npm install).
  2. Re-export snippet (export * from "<package-name>").
  3. Parameterized Configuration .env reference table.
  4. What Changed (Extension vs Package) comparison table.

Reminder: NEVER execute npm publish.

firebaseのその他のスキル

developing-genkit-dart
firebase
Dart向け統合AI SDK。コード生成、構造化出力、ツール、フロー、エージェントを実現。単一インターフェースで生成、ツール定義、フローオーケストレーション、埋め込み、ストリーミングのコアAPIを提供。LLMプロバイダー(Google Gemini、Anthropic Claude、OpenAI GPT)、Firebase AI、Model Context Protocol、Chromeブラウザ統合、Shelf経由のHTTPサーバーホスティング向け8以上のプラグインを含む。フロー実行、トレース、モデル実験などのためのローカル開発UIを備えた組み込みCLI。
official
developing-genkit-js
firebase
Genkitのフロー、ツール、マルチモデルサポートを使用して、AIを活用したNode.js/TypeScriptアプリケーションを構築します。Genkitはプロバイダーに依存せず、プラグインを介してGoogle AI、OpenAI、Anthropic、Ollama、その他のLLMプロバイダーをサポートします。Zodを使用して型安全なスキーマでフローを定義し、生成リクエストを実行し、TypeScriptでマルチステップのAIワークフローを構成します。Genkit CLI v1.29.0以上が必要です。最近の主要なAPI変更により、現在のパターンについては、以前の知識ではなく、genkit docs:readおよびcommon-errors.mdを参照する必要があります...
official
firebase-ai-logic
firebase
クライアントサイドのGemini統合で、マルチモーダル推論、ストリーミング、デバイス上のハイブリッド実行を備えたウェブアプリ向け。テキストのみおよびマルチモーダル入力(画像、音声、動画、PDF)をサポート。20MBを超えるファイルはCloud Storage経由でルーティング。自動履歴付きチャットセッション、リアルタイム表示のためのストリーミング応答、構造化JSON出力の強制を含む。ChromeのGemini Nanoを介したデバイス上のハイブリッド推論を提供し、クラウド実行への自動フォールバックを備える。本番環境ではApp Checkが必要。
official
firebase-ai-logic-basics
firebase
Firebase AI Logic(Gemini API)をウェブアプリケーションに統合するための公式スキル。セットアップ、マルチモーダル推論、構造化出力、セキュリティをカバーします。
official
firebase-app-hosting-basics
firebase
Firebase App Hostingを使用して、Next.js、Angular、その他サポートされているフレームワークを用いたフルスタックWebアプリをデプロイおよび管理します。FirebaseプロジェクトがBlaze料金プランである必要があり、サーバーサイドレンダリング(SSR)およびインクリメンタル静的再生成(ISR)ワークフローをサポートします。バックエンド設定用のオプションのapphosting.yamlを伴うfirebase.json設定を介してデプロイするか、GitHub統合を通じて自動化された「git push to deploy」を有効にします。機密キーへの安全なアクセスのためのCLIコマンドによるシークレット管理を含みます。
official
firebase-auth-basics
firebase
Firebase Authenticationを複数のIDプロバイダーと安全なデータアクセスルールで設定します。メール/パスワード、電話番号、匿名、フェデレーションプロバイダー(Google、Facebook、Twitter、GitHub、Microsoft、Apple)、カスタム認証統合をサポートします。各認証ユーザーには一意のIDとJWTベースのトークン(短期間のIDトークンと長期間のリフレッシュトークン)が付与され、Firebaseサービスにアクセスできます。Googleサインイン、匿名、メール/パスワードのプロバイダーはCLI経由で有効化し、Firebase Consoleを使用します...
official
firebase-basics
firebase
Firebaseプロジェクトのセットアップと、AIエージェント統合のためのCLIワークフロー。事前にfirebase-local-env-setupスキルとFirebase CLIのインストールを完了している必要があります。コアワークフローは、firebase loginによる認証、一意のIDを使用したプロジェクト作成、および対話型のfirebase initコマンドによるサービスの初期化をカバーします。セットアップ中にFirestore、Functions、Hostingを含む機能選択をサポートし、自動的に設定ファイルを生成します。--helpフラグを使用した自己文書化CLI...
official
firebase-crashlytics
firebase
Firebase Crashlyticsの包括的なガイド。プロビジョニングとSDKの使用方法を含みます。ユーザーがCrashlyticsのセットアップや追加の設定について支援を必要とする場合にこのスキルを使用してください。
official