From b6b1f83b02da9c482084fc2bf152fd374ffdaf1e Mon Sep 17 00:00:00 2001 From: Saumya Date: Fri, 29 Aug 2025 15:10:08 +0530 Subject: [PATCH] fix tasks api --- backend/triggers/api.py | 15 +----------- .../react-query/triggers/use-all-triggers.ts | 24 +++++-------------- 2 files changed, 7 insertions(+), 32 deletions(-) diff --git a/backend/triggers/api.py b/backend/triggers/api.py index 47291a48..4fd8f604 100644 --- a/backend/triggers/api.py +++ b/backend/triggers/api.py @@ -273,14 +273,11 @@ async def get_agent_triggers( async def get_all_user_triggers( user_id: str = Depends(get_current_user_id_from_jwt) ): - if not await is_enabled("agent_triggers"): - raise HTTPException(status_code=403, detail="Agent triggers are not enabled") - try: client = await db.client agents_result = await client.table('agents').select( - 'agent_id, name, description, current_version_id, config, icon_name, icon_color, icon_background, profile_image_url' + 'agent_id, name, description, current_version_id, icon_name, icon_color, icon_background, profile_image_url' ).eq('account_id', user_id).execute() if not agents_result.data: @@ -288,19 +285,9 @@ async def get_all_user_triggers( agent_info = {} for agent in agents_result.data: - agent_config = agent.get('config', {}) agent_name = agent.get('name', 'Untitled Agent') agent_description = agent.get('description', '') - if isinstance(agent_config, dict): - if 'metadata' in agent_config and isinstance(agent_config['metadata'], dict): - agent_name = agent_config['metadata'].get('name', agent_name) - agent_description = agent_config['metadata'].get('description', agent_description) - elif 'name' in agent_config: - agent_name = agent_config.get('name', agent_name) - elif 'description' in agent_config: - agent_description = agent_config.get('description', agent_description) - agent_info[agent['agent_id']] = { 'agent_name': agent_name, 'agent_description': agent_description, diff --git a/frontend/src/hooks/react-query/triggers/use-all-triggers.ts b/frontend/src/hooks/react-query/triggers/use-all-triggers.ts index 4483d739..9f3aea28 100644 --- a/frontend/src/hooks/react-query/triggers/use-all-triggers.ts +++ b/frontend/src/hooks/react-query/triggers/use-all-triggers.ts @@ -1,5 +1,6 @@ import { useQuery } from '@tanstack/react-query'; import { createClient } from '@/lib/supabase/client'; +import { backendApi } from '@/lib/api-client'; const API_URL = process.env.NEXT_PUBLIC_BACKEND_URL; @@ -24,25 +25,12 @@ export interface TriggerWithAgent { } const fetchAllTriggers = async (): Promise => { - const supabase = createClient(); - const { data: { session } } = await supabase.auth.getSession(); - if (!session) { - throw new Error('You must be logged in to fetch triggers'); + const response = await backendApi.get(`/triggers/all`); + if (!response.success) { + const error = response.error?.message || 'Failed to fetch triggers'; + throw new Error(error || 'Failed to fetch triggers'); } - - const response = await fetch(`${API_URL}/triggers/all`, { - headers: { - 'Content-Type': 'application/json', - 'Authorization': `Bearer ${session.access_token}` - }, - }); - - if (!response.ok) { - const error = await response.json().catch(() => ({ detail: 'Failed to fetch triggers' })); - throw new Error(error.detail || 'Failed to fetch triggers'); - } - - return response.json(); + return response.data; }; export const useAllTriggers = () => {