mirror of https://github.com/kortix-ai/suna.git
fix tasks api
This commit is contained in:
parent
8afbe01e9e
commit
b6b1f83b02
|
@ -273,14 +273,11 @@ async def get_agent_triggers(
|
||||||
async def get_all_user_triggers(
|
async def get_all_user_triggers(
|
||||||
user_id: str = Depends(get_current_user_id_from_jwt)
|
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:
|
try:
|
||||||
client = await db.client
|
client = await db.client
|
||||||
|
|
||||||
agents_result = await client.table('agents').select(
|
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()
|
).eq('account_id', user_id).execute()
|
||||||
|
|
||||||
if not agents_result.data:
|
if not agents_result.data:
|
||||||
|
@ -288,19 +285,9 @@ async def get_all_user_triggers(
|
||||||
|
|
||||||
agent_info = {}
|
agent_info = {}
|
||||||
for agent in agents_result.data:
|
for agent in agents_result.data:
|
||||||
agent_config = agent.get('config', {})
|
|
||||||
agent_name = agent.get('name', 'Untitled Agent')
|
agent_name = agent.get('name', 'Untitled Agent')
|
||||||
agent_description = agent.get('description', '')
|
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_info[agent['agent_id']] = {
|
||||||
'agent_name': agent_name,
|
'agent_name': agent_name,
|
||||||
'agent_description': agent_description,
|
'agent_description': agent_description,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { createClient } from '@/lib/supabase/client';
|
import { createClient } from '@/lib/supabase/client';
|
||||||
|
import { backendApi } from '@/lib/api-client';
|
||||||
|
|
||||||
const API_URL = process.env.NEXT_PUBLIC_BACKEND_URL;
|
const API_URL = process.env.NEXT_PUBLIC_BACKEND_URL;
|
||||||
|
|
||||||
|
@ -24,25 +25,12 @@ export interface TriggerWithAgent {
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchAllTriggers = async (): Promise<TriggerWithAgent[]> => {
|
const fetchAllTriggers = async (): Promise<TriggerWithAgent[]> => {
|
||||||
const supabase = createClient();
|
const response = await backendApi.get<TriggerWithAgent[]>(`/triggers/all`);
|
||||||
const { data: { session } } = await supabase.auth.getSession();
|
if (!response.success) {
|
||||||
if (!session) {
|
const error = response.error?.message || 'Failed to fetch triggers';
|
||||||
throw new Error('You must be logged in to fetch triggers');
|
throw new Error(error || 'Failed to fetch triggers');
|
||||||
}
|
}
|
||||||
|
return response.data;
|
||||||
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();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useAllTriggers = () => {
|
export const useAllTriggers = () => {
|
||||||
|
|
Loading…
Reference in New Issue