feat: implement create-chat-conversation function with OpenAI integration and Supabase support
CI / test (pull_request) Failing after 8s
CI / test (pull_request) Failing after 8s
- Added CORS handling for the create-chat-conversation function. - Implemented health check endpoint for the function. - Created endpoints for managing conversations and messages with OpenAI. - Added error handling and response formatting for better API usability. - Introduced utility functions for environment variable management and Supabase client creation. - Enhanced schema handling for structured responses from OpenAI. - Implemented conversation archiving and retrieval logic.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { createClient } from "jsr:@supabase/supabase-js";
|
||||
import { mustGetEnv } from "./env.ts";
|
||||
import { HttpError } from "./errors.ts";
|
||||
|
||||
export function getSupabaseServiceClient() {
|
||||
const url = mustGetEnv("SUPABASE_URL");
|
||||
const key = mustGetEnv("SUPABASE_SERVICE_ROLE_KEY");
|
||||
return createClient(url, key, { auth: { persistSession: false } });
|
||||
}
|
||||
|
||||
export function getSupabaseAnonClient(authHeader?: string) {
|
||||
const url = mustGetEnv("SUPABASE_URL");
|
||||
const key = mustGetEnv("SUPABASE_ANON_KEY");
|
||||
return createClient(url, key, {
|
||||
auth: { persistSession: false },
|
||||
global: authHeader ? { headers: { Authorization: authHeader } } : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
export async function requireUser(authHeader?: string) {
|
||||
if (!authHeader) {
|
||||
throw new HttpError(401, "missing_auth", "Missing Authorization header");
|
||||
}
|
||||
const anon = getSupabaseAnonClient(authHeader);
|
||||
const { data, error } = await anon.auth.getUser();
|
||||
if (error || !data?.user) {
|
||||
throw new HttpError(401, "invalid_auth", "Invalid or expired token", error);
|
||||
}
|
||||
return data.user;
|
||||
}
|
||||
Reference in New Issue
Block a user