npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@crewdle/ai-firebase-functions

v1.0.2

Published

Firebase Cloud Functions for AI workflows for Crewdle applications

Downloads

105

Readme

@crewdle/ai-firebase-functions

Firebase Cloud Functions for AI workflows. This package provides reusable Firebase Functions that can be deployed in any Firebase project to enable AI-powered workflow execution.

Features

  • 🤖 AI Workflow Execution: Execute AI workflows with message history and file attachments
  • 🔄 Real-time Streaming: Stream AI workflow responses in real-time
  • 🚀 Production Ready: Comprehensive error handling and validation
  • 📦 TypeScript Support: Full type safety with exported interfaces
  • Scalable: Optimized for Firebase Cloud Functions v2

Installation

npm install @crewdle/ai-firebase-functions firebase-admin firebase-functions

Quick Start

1. Import Functions

// In your Firebase Functions index.ts
import {
  runWorkflow,
  streamWorkflow
} from '@crewdle/ai-firebase-functions';

// Export functions for deployment
export {
  runWorkflow,
  streamWorkflow
};

2. Set Required Environment Variables

For workflow functions, you need to set the Crewdle API key:

firebase functions:secrets:set CREWDLE_API_KEY

3. Deploy Functions

firebase deploy --only functions

Available Functions

runWorkflow

Executes AI workflows with message history and optional file attachments.

Request:

interface WorkflowRequest {
  workflowId: string;
  messages: WorkflowMessage[];
  files?: WorkflowFile[];
}

interface WorkflowMessage {
  role: 'user' | 'assistant';
  content: string;
}

interface WorkflowFile {
  name: string;
  type: string;
  content: string; // base64 encoded
}

Usage:

const functions = getFunctions();
const runWorkflow = httpsCallable(functions, 'runWorkflow');

const result = await runWorkflow({
  workflowId: 'your-workflow-id',
  messages: [
    { role: 'user', content: 'Hello, analyze this data' }
  ],
  files: [
    {
      name: 'data.txt',
      type: 'text/plain',
      content: 'base64EncodedContent'
    }
  ]
});

streamWorkflow

Streams AI workflow responses in real-time for better user experience.

Usage:

const streamWorkflow = httpsCallable(functions, 'streamWorkflow');

const result = await streamWorkflow({
  workflowId: 'your-workflow-id',
  messages: [
    { role: 'user', content: 'Write a long story about AI' }
  ]
});

Error Handling

All functions include comprehensive error handling:

try {
  const result = await runWorkflow({
    workflowId: 'invalid-id',
    messages: []
  });
} catch (error) {
  console.error('Function error:', error.message);
  // Handle specific error cases
}

Environment Configuration

Required Secrets

  1. CREWDLE_API_KEY: Required for workflow functions
    firebase functions:secrets:set CREWDLE_API_KEY

Firebase Project Setup

Ensure your Firebase project has the following services enabled:

  • Cloud Functions

Advanced Usage

Custom Deployment Regions

Functions are configured for northamerica-northeast1 region by default. You can modify the region in the function definitions:

export const runWorkflow = onCall({
  region: "your-preferred-region",
  // ... other options
}, handler);

Timeout Configuration

Functions are configured with 300-second timeout for AI operations. Adjust as needed:

export const runWorkflow = onCall({
  timeoutSeconds: 600, // 10 minutes
  // ... other options
}, handler);

Development

Local Development

  1. Install dependencies:

    npm install
  2. Build the package:

    npm run build
  3. Run local emulators:

    npm run serve

Testing

Use Firebase emulators for testing:

firebase emulators:start --only functions

Connect your client app to emulators:

import { connectFunctionsEmulator } from 'firebase/functions';

if (process.env.NODE_ENV === 'development') {
  connectFunctionsEmulator(functions, 'localhost', 5001);
}

Security Considerations

  1. API Keys: Always use Firebase secrets for sensitive API keys
  2. Input Validation: All functions include input validation
  3. Error Handling: Errors are sanitized to avoid information leakage
  4. CORS: Functions are configured for secure cross-origin requests

TypeScript Support

Full TypeScript definitions are included:

import {
  WorkflowMessage,
  WorkflowFile,
  WorkflowRequest,
  WorkflowResponse
} from '@crewdle/ai-firebase-functions';

Migration Guide

From Existing Functions

If you're migrating from existing Firebase Functions:

  1. Install the package
  2. Replace individual function implementations with imports
  3. Update your exports in index.ts
  4. Redeploy functions

Breaking Changes

  • Functions use Firebase Functions v2 by default
  • Requires Node.js 18+ runtime
  • Uses Firebase secrets instead of environment variables

License

MIT © Crewdle

Support

For issues and feature requests, please visit our GitHub repository.