Firebase Integration
Relevant source files
The following files were used as context for generating this wiki page:
Firebase Integration provides the backend infrastructure for user authentication, persistent data storage, and cross-device synchronization. It coordinates state files, prompt presets, and chat sessions by saving encrypted payloads to secure cloud registers.
The system uses Firebase Authentication for anonymous sign-ins and Cloud Firestore for data persistence. To support desktop and mobile environments like Tauri and Capacitor, the integration implements persistent local caching with multi-tab management.
Sources: src/firebase.ts:1-7, src/utils/ai.ts:204-210
Core Configuration and Initialization
The application initializes Firebase using a local configuration file that defines project identifiers and API keys. The SDK consumes specific keys for projectId, appId, apiKey, and authDomain. Additional optional keys like storageBucket, messagingSenderId, and measurementId are included if present in the configuration.
Sources: firebase-applet-config.json , src/firebase.ts:35-50
Firestore Persistence Layer
The integration configures Firestore with persistentLocalCache to ensure functionality in environments where standard browser persistence may be restricted, such as Tauri file:// protocols or Capacitor WebViews.
The diagram shows the initialization flow and the configuration of the local cache for cross-environment compatibility.
Sources: src/firebase.ts:52-58
Authentication Services
The signIn function performs anonymous authentication to establish a session without requiring user credentials. The signOut function terminates the current Firebase session.
| Function | Action | Return Type |
|---|---|---|
signIn() | Authenticates anonymously via signInAnonymously | Promise<User> |
signOut() | Ends the session via firebaseSignOut | Promise<void> |
Sources: src/firebase.ts:60-72
Data Synchronization and Security
The system synchronizes the entire workspace, including prompt profiles and chat history, across nodes. Security is maintained through client-side encryption before data reaches the cloud.
Sync Workflow
- Passphrase Hashing: Uses 256-bit PBKDF2 encryption for keys.
- Encrypted Payloads: Saves state files to secure Firestore registers.
- Cluster Mapping: Identifies devices using a Cluster Code to sync coordinates.
Sources: src/utils/ai.ts:204-215, src/components/SyncCluster.tsx:50-58
Synchronization Sequence
This sequence demonstrates the path from a manual sync trigger to a successful database push.
Sources: src/components/SyncCluster.tsx:90-112, src/firebase.ts:60-65
Error Handling
The system implements a structured error handler, handleFirestoreError, to translate Firebase SDK errors into actionable information. This is defined by the FirestoreErrorInfo interface.
Error Resolution Mapping
| Error Code | Potential Resolution | Retryable |
|---|---|---|
permission-denied | Verify sign-in and resource access. | No |
unavailable | Check internet connection; Firestore is offline. | Yes |
unauthenticated | Please sign in to continue. | No |
quota-exceeded | Database limit reached; try later. | No |
Sources: src/firebase.ts:8-32
Summary
Firebase Integration acts as the secure bridge between local AI operations and persistent cloud storage. By combining anonymous authentication with encrypted Firestore payloads and local caching, it enables a consistent workspace experience across Windows, macOS, Android, and iOS platforms.
Sources: src/firebase.ts:52-58, src/utils/ai.ts:207-215