This guide will help you set up and start working with the Agentic Edge Functions repository. Follow these steps to get your development environment configured and deploy your first edge function.
Before you begin, ensure you have the following installed:
- Node.js (v16 or later)
- Deno (v1.28 or later)
- Supabase CLI
- Git
# Clone the repository
git clone https://github.com/agentics-foundation/edge-agents.git
# Navigate to the project directory
cd edge-agents- Sign up or log in to Supabase
- Create a new project from the Supabase dashboard
- Note your project URL and API keys
If you already have a Supabase project, you can use it with this repository.
Link your local repository to your Supabase project:
# Login to Supabase
supabase login
# Link your project
supabase link --project-ref your-project-refReplace your-project-ref with your Supabase project reference ID, which can be found in your project's dashboard URL or settings.
Create a .env file in the root directory with the following variables:
SUPABASE_URL=https://your-project-ref.supabase.co
SUPABASE_ANON_KEY=your-anon-key
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key
Replace the placeholders with your actual Supabase project details.
Some edge functions may require additional dependencies. Check the specific function's documentation for details.
To run edge functions locally for development and testing:
# Start the Supabase local development server
supabase start
# Serve all functions
supabase functions serve --no-verify-jwt
# Serve a specific function
supabase functions serve function-name --no-verify-jwtThe --no-verify-jwt flag allows you to call the functions without authentication during local development.
You can test HTTP-based edge functions using curl or any API testing tool:
# Test a function locally
curl -X POST http://localhost:54321/functions/v1/function-name \
-H "Content-Type: application/json" \
-d '{"param1": "value1", "param2": "value2"}'
# Test a deployed function
curl -X POST https://your-project-ref.supabase.co/functions/v1/function-name \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-anon-key" \
-d '{"param1": "value1", "param2": "value2"}'For WebSocket-based functions, you can use tools like websocat or write a simple client:
// Simple WebSocket client
const ws = new WebSocket('wss://your-project-ref.supabase.co/functions/v1/function-name');
ws.onopen = () => {
console.log('Connected');
ws.send(JSON.stringify({ message: 'Hello' }));
};
ws.onmessage = (event) => {
console.log('Received:', event.data);
};
ws.onerror = (error) => {
console.error('Error:', error);
};
ws.onclose = () => {
console.log('Disconnected');
};To deploy an edge function to your Supabase project:
# Deploy a specific function
supabase functions deploy function-name
# Deploy all functions
supabase functions deploySet environment variables for your deployed functions:
# Set a single environment variable
supabase secrets set MY_API_KEY=your-api-key
# Set multiple environment variables
supabase secrets set MY_API_KEY=your-api-key OTHER_SECRET=another-secret
# Set environment variables from a .env file
supabase secrets set --env-file .envView logs for your deployed functions:
# View logs for a specific function
supabase functions logs function-name
# View logs for all functions
supabase functions logs# Create a new function directory
mkdir -p supabase/functions/new-function
# Create the main function file
touch supabase/functions/new-function/index.tsEdit the index.ts file with your function code:
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
serve(async (req) => {
const { name } = await req.json();
return new Response(
JSON.stringify({ message: `Hello, ${name}!` }),
{ headers: { "Content-Type": "application/json" } }
);
});# Serve the function locally
supabase functions serve new-function --no-verify-jwt
# Test the function
curl -X POST http://localhost:54321/functions/v1/new-function \
-H "Content-Type: application/json" \
-d '{"name": "World"}'# Deploy the function
supabase functions deploy new-function# Test the deployed function
curl -X POST https://your-project-ref.supabase.co/functions/v1/new-function \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-anon-key" \
-d '{"name": "World"}'Now that you have set up your development environment and deployed your first function, you can:
- Explore the function documentation to learn about the available functions
- Learn about Supabase Edge Functions in more detail
- Understand how to use Real-time Channels with your functions
- Learn about Secrets Management for secure credential handling
- Explore Database Triggers for event-driven architectures
If you encounter issues deploying functions:
-
Check that your Supabase CLI is up to date:
npm install -g supabase@latest
-
Verify that your project is correctly linked:
supabase projects list
-
Check for syntax errors in your function code
If you encounter issues with local development:
-
Ensure Deno is installed correctly:
deno --version
-
Check that the Supabase local development server is running:
supabase status
-
Restart the functions server:
supabase functions serve --no-verify-jwt
If you encounter authentication issues:
- For local development, use the
--no-verify-jwtflag - For deployed functions, ensure you're including the correct authorization header
- Check that your API keys are correct in your environment variables
Created by rUv, Agentics Foundation founder.