A TypeScript AI Firebase service wrapper that provides workflow execution and file processing capabilities for Crewdle applications. Built on top of @crewdle/firebase-service.
- π€ AI Workflows: Execute AI workflows with message history and file attachments
- π¦ File Processing: Handle file uploads with base64 encoding and caching
- π Streaming Support: Stream AI responses in real-time
- πΎ Image Caching: Automatic caching of fetched images for performance
- π― TypeScript: Full type safety and IntelliSense support
- π§ Flexible: Works with any Firebase project configuration
- π± Angular Integration: Injectable service with module support
npm install @crewdle/ai-firebase-service @crewdle/firebase-serviceNote: Firebase is a peer dependency, so you need to install it separately:
npm install firebase1. Install the package:
npm install @crewdle/ai-firebase-service @crewdle/firebase-service firebase2. Configure in your app module:
import { NgModule } from '@angular/core';
import { AiFirebaseServiceModule } from '@crewdle/ai-firebase-service';
import { environment } from '../environments/environment';
@NgModule({
imports: [
AiFirebaseServiceModule.forRoot({
firebaseConfig: environment.firebaseConfig,
functionsRegion: 'us-central1' // optional
})
]
})
export class AppModule { }Alternative: Using providers directly (for standalone apps):
import { bootstrapApplication } from '@angular/platform-browser';
import { AiFirebaseService, AI_FIREBASE_SERVICE_CONFIG } from '@crewdle/ai-firebase-service';
import { environment } from './environments/environment';
bootstrapApplication(AppComponent, {
providers: [
{
provide: AI_FIREBASE_SERVICE_CONFIG,
useValue: {
firebaseConfig: environment.firebaseConfig,
functionsRegion: 'us-central1'
}
},
AiFirebaseService
]
});3. Inject and use in your components/services:
import { Component, inject } from '@angular/core';
import { AiFirebaseService, WorkflowMessage } from '@crewdle/ai-firebase-service';
@Component({
selector: 'app-example',
template: '...'
})
export class ExampleComponent {
private readonly aiService = inject(AiFirebaseService);
async generateContent() {
const messages: WorkflowMessage[] = [
{ role: 'user', content: 'Hello, can you help me?' }
];
const response = await this.aiService.generateContent('workflow-id', messages);
console.log(response);
}
}import { AiFirebaseService } from '@crewdle/ai-firebase-service';
const aiService = AiFirebaseService.create({
firebaseConfig: {
apiKey: "your-api-key",
authDomain: "your-project.firebaseapp.com",
projectId: "your-project-id",
// ... other config
},
functionsRegion: "us-central1" // optional, defaults to us-central1
});// Generate content using a workflow
const messages: WorkflowMessage[] = [
{ role: 'user', content: 'Analyze this data' }
];
const response = await aiService.generateContent('workflow-id', messages);
console.log('Generated content:', response);
// Generate content with file attachments
const files = [new File(['content'], 'data.txt', { type: 'text/plain' })];
const responseWithFiles = await aiService.generateContent('workflow-id', messages, files);// Stream AI responses in real-time
const messages: WorkflowMessage[] = [
{ role: 'user', content: 'Write a story about AI' }
];
for await (const chunk of aiService.streamContent('workflow-id', messages)) {
console.log('Chunk:', chunk);
// Update UI with streaming content
}// Fetch and cache images from URLs
const imageFile = await aiService.fetchUrl('https://example.com/image.jpg');
console.log('Image file:', imageFile.name, imageFile.size);
// Use fetched image in workflow
const messages: WorkflowMessage[] = [
{ role: 'user', content: 'Describe this image' }
];
const description = await aiService.generateContent('vision-workflow', messages, [imageFile]);// Check cached images count
const cacheCount = aiService.getCachedImageCount();
console.log('Cached images:', cacheCount);
// Clear image cache
aiService.clearImageCache();// Get underlying Firebase service if needed
const firebaseService = aiService.getFirebaseService();
const firestore = firebaseService.getFirestore();// Process multiple files with different types
const files = [
new File(['{"data": "value"}'], 'data.json', { type: 'application/json' }),
new File(['Hello world'], 'text.txt', { type: 'text/plain' })
];
const response = await aiService.generateContent('data-analysis-workflow', [
{ role: 'user', content: 'Analyze these files' }
], files);try {
const response = await aiService.generateContent('workflow-id', messages);
} catch (error) {
console.error('Failed to generate content:', error);
}try {
for await (const chunk of aiService.streamContent('workflow-id', messages)) {
// Process chunk
console.log(chunk);
}
} catch (error) {
console.error('Streaming failed:', error);
}The package includes full TypeScript definitions:
import {
AiFirebaseService,
WorkflowMessage,
WorkflowResponse,
WorkflowFile,
StreamChunk,
FetchUrlResponse,
FirebaseServiceConfig
} from '@crewdle/ai-firebase-service';- Node.js >= 16
- TypeScript >= 4.7
- Angular >= 15 (for Angular usage)
- @crewdle/firebase-service >= 1.0.0
- firebase >= 9.0.0
MIT Β© Crewdle