mirror of https://github.com/kortix-ai/suna.git
Merge pull request #680 from tnfssc/fix/lp-toast
This commit is contained in:
commit
24df75cae0
|
@ -29,6 +29,13 @@ export class BillingError extends Error {
|
|||
}
|
||||
}
|
||||
|
||||
export class NoAccessTokenAvailableError extends Error {
|
||||
constructor(message?: string, options?: { cause?: Error }) {
|
||||
super(message || 'No access token available', options);
|
||||
}
|
||||
name = 'NoAccessTokenAvailableError';
|
||||
}
|
||||
|
||||
// Type Definitions (moved from potential separate file for clarity)
|
||||
export type Project = {
|
||||
id: string;
|
||||
|
@ -541,7 +548,7 @@ export const startAgent = async (
|
|||
} = await supabase.auth.getSession();
|
||||
|
||||
if (!session?.access_token) {
|
||||
throw new Error('No access token available');
|
||||
throw new NoAccessTokenAvailableError();
|
||||
}
|
||||
|
||||
// Check if backend URL is configured
|
||||
|
@ -633,6 +640,10 @@ export const startAgent = async (
|
|||
throw error;
|
||||
}
|
||||
|
||||
if (error instanceof NoAccessTokenAvailableError) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
console.error('[API] Failed to start agent:', error);
|
||||
|
||||
// Handle different error types with appropriate user messages
|
||||
|
@ -673,7 +684,7 @@ export const stopAgent = async (agentRunId: string): Promise<void> => {
|
|||
} = await supabase.auth.getSession();
|
||||
|
||||
if (!session?.access_token) {
|
||||
const authError = new Error('No access token available');
|
||||
const authError = new NoAccessTokenAvailableError();
|
||||
handleApiError(authError, { operation: 'stop agent', resource: 'AI assistant' });
|
||||
throw authError;
|
||||
}
|
||||
|
@ -714,7 +725,7 @@ export const getAgentStatus = async (agentRunId: string): Promise<AgentRun> => {
|
|||
|
||||
if (!session?.access_token) {
|
||||
console.error('[API] No access token available for getAgentStatus');
|
||||
throw new Error('No access token available');
|
||||
throw new NoAccessTokenAvailableError();
|
||||
}
|
||||
|
||||
const url = `${API_URL}/agent-run/${agentRunId}`;
|
||||
|
@ -771,7 +782,7 @@ export const getAgentRuns = async (threadId: string): Promise<AgentRun[]> => {
|
|||
} = await supabase.auth.getSession();
|
||||
|
||||
if (!session?.access_token) {
|
||||
throw new Error('No access token available');
|
||||
throw new NoAccessTokenAvailableError();
|
||||
}
|
||||
|
||||
const response = await fetch(`${API_URL}/thread/${threadId}/agent-runs`, {
|
||||
|
@ -789,6 +800,10 @@ export const getAgentRuns = async (threadId: string): Promise<AgentRun[]> => {
|
|||
const data = await response.json();
|
||||
return data.agent_runs || [];
|
||||
} catch (error) {
|
||||
if (error instanceof NoAccessTokenAvailableError) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
console.error('Failed to get agent runs:', error);
|
||||
handleApiError(error, { operation: 'load agent runs', resource: 'conversation history' });
|
||||
throw error;
|
||||
|
@ -875,8 +890,9 @@ export const streamAgent = (
|
|||
} = await supabase.auth.getSession();
|
||||
|
||||
if (!session?.access_token) {
|
||||
const authError = new NoAccessTokenAvailableError();
|
||||
console.error('[STREAM] No auth token available');
|
||||
callbacks.onError(new Error('Authentication required'));
|
||||
callbacks.onError(authError);
|
||||
callbacks.onClose();
|
||||
return;
|
||||
}
|
||||
|
@ -1398,7 +1414,7 @@ export const initiateAgent = async (
|
|||
} = await supabase.auth.getSession();
|
||||
|
||||
if (!session?.access_token) {
|
||||
throw new Error('No access token available');
|
||||
throw new NoAccessTokenAvailableError();
|
||||
}
|
||||
|
||||
if (!API_URL) {
|
||||
|
@ -1570,7 +1586,7 @@ export const createCheckoutSession = async (
|
|||
} = await supabase.auth.getSession();
|
||||
|
||||
if (!session?.access_token) {
|
||||
throw new Error('No access token available');
|
||||
throw new NoAccessTokenAvailableError();
|
||||
}
|
||||
|
||||
const response = await fetch(`${API_URL}/billing/create-checkout-session`, {
|
||||
|
@ -1637,7 +1653,7 @@ export const createPortalSession = async (
|
|||
} = await supabase.auth.getSession();
|
||||
|
||||
if (!session?.access_token) {
|
||||
throw new Error('No access token available');
|
||||
throw new NoAccessTokenAvailableError();
|
||||
}
|
||||
|
||||
const response = await fetch(`${API_URL}/billing/create-portal-session`, {
|
||||
|
@ -1679,7 +1695,7 @@ export const getSubscription = async (): Promise<SubscriptionStatus> => {
|
|||
} = await supabase.auth.getSession();
|
||||
|
||||
if (!session?.access_token) {
|
||||
throw new Error('No access token available');
|
||||
throw new NoAccessTokenAvailableError();
|
||||
}
|
||||
|
||||
const response = await fetch(`${API_URL}/billing/subscription`, {
|
||||
|
@ -1703,6 +1719,10 @@ export const getSubscription = async (): Promise<SubscriptionStatus> => {
|
|||
|
||||
return response.json();
|
||||
} catch (error) {
|
||||
if (error instanceof NoAccessTokenAvailableError) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
console.error('Failed to get subscription:', error);
|
||||
handleApiError(error, { operation: 'load subscription', resource: 'billing information' });
|
||||
throw error;
|
||||
|
@ -1717,7 +1737,7 @@ export const getAvailableModels = async (): Promise<AvailableModelsResponse> =>
|
|||
} = await supabase.auth.getSession();
|
||||
|
||||
if (!session?.access_token) {
|
||||
throw new Error('No access token available');
|
||||
throw new NoAccessTokenAvailableError();
|
||||
}
|
||||
|
||||
const response = await fetch(`${API_URL}/billing/available-models`, {
|
||||
|
@ -1741,6 +1761,10 @@ export const getAvailableModels = async (): Promise<AvailableModelsResponse> =>
|
|||
|
||||
return response.json();
|
||||
} catch (error) {
|
||||
if (error instanceof NoAccessTokenAvailableError) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
console.error('Failed to get available models:', error);
|
||||
handleApiError(error, { operation: 'load available models', resource: 'AI models' });
|
||||
throw error;
|
||||
|
@ -1756,7 +1780,7 @@ export const checkBillingStatus = async (): Promise<BillingStatusResponse> => {
|
|||
} = await supabase.auth.getSession();
|
||||
|
||||
if (!session?.access_token) {
|
||||
throw new Error('No access token available');
|
||||
throw new NoAccessTokenAvailableError();
|
||||
}
|
||||
|
||||
const response = await fetch(`${API_URL}/billing/check-status`, {
|
||||
|
@ -1780,6 +1804,10 @@ export const checkBillingStatus = async (): Promise<BillingStatusResponse> => {
|
|||
|
||||
return response.json();
|
||||
} catch (error) {
|
||||
if (error instanceof NoAccessTokenAvailableError) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
console.error('Failed to check billing status:', error);
|
||||
throw error;
|
||||
}
|
||||
|
@ -1799,7 +1827,7 @@ export const transcribeAudio = async (audioFile: File): Promise<TranscriptionRes
|
|||
} = await supabase.auth.getSession();
|
||||
|
||||
if (!session?.access_token) {
|
||||
throw new Error('No access token available');
|
||||
throw new NoAccessTokenAvailableError();
|
||||
}
|
||||
|
||||
const formData = new FormData();
|
||||
|
@ -1828,6 +1856,10 @@ export const transcribeAudio = async (audioFile: File): Promise<TranscriptionRes
|
|||
|
||||
return response.json();
|
||||
} catch (error) {
|
||||
if (error instanceof NoAccessTokenAvailableError) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
console.error('Failed to transcribe audio:', error);
|
||||
handleApiError(error, { operation: 'transcribe audio', resource: 'speech-to-text' });
|
||||
throw error;
|
||||
|
@ -1841,7 +1873,7 @@ export const getAgentBuilderChatHistory = async (agentId: string): Promise<{mess
|
|||
} = await supabase.auth.getSession();
|
||||
|
||||
if (!session?.access_token) {
|
||||
throw new Error('No access token available');
|
||||
throw new NoAccessTokenAvailableError();
|
||||
}
|
||||
|
||||
const response = await fetch(`${API_URL}/agents/${agentId}/builder-chat-history`, {
|
||||
|
|
Loading…
Reference in New Issue