mirror of https://github.com/kortix-ai/suna.git
error msg toast on stream
This commit is contained in:
parent
75823fca3e
commit
4c8bd7b47a
|
@ -802,6 +802,7 @@ Ask user a question and wait for response. Use for: 1) Requesting clarification
|
|||
<!-- This tool indicates successful completion of all tasks -->
|
||||
<!-- The system will stop execution after this tool is used -->
|
||||
</complete>
|
||||
|
||||
\n<web-browser-takeover> Example:
|
||||
<!-- Use web-browser-takeover when automated tools cannot handle the page interaction -->
|
||||
<!-- Examples of when takeover is needed: -->
|
||||
|
|
|
@ -187,6 +187,8 @@ async def run_agent(
|
|||
elif "gpt-4" in model_name.lower():
|
||||
max_tokens = 4096
|
||||
|
||||
model_name = "open123router/nvidia/llama-3.1-nemotron-ultra-253b-v1:free"
|
||||
|
||||
response = await thread_manager.run_thread(
|
||||
thread_id=thread_id,
|
||||
system_prompt=system_message,
|
||||
|
|
|
@ -16,6 +16,8 @@ Make sure your environment variables are properly set:
|
|||
- DAYTONA_SERVER_URL
|
||||
"""
|
||||
|
||||
# TODO: SAVE THE LATEST SANDBOX STATE SOMEWHERE OR LIKE MASS CHECK THE STATE BEFORE STARTING TO ARCHIVE - AS ITS GOING TO GO OVER A BUNCH THAT ARE ALREADY ARCHIVED – MAYBE BEST TO GET ALL FROM DAYTONA AND THEN RUN THE ARCHIVE ONLY ON THE ONES THAT MEET THE CRITERIA (STOPPED STATE)
|
||||
|
||||
import asyncio
|
||||
import sys
|
||||
import os
|
||||
|
@ -81,7 +83,7 @@ async def get_old_projects(days_threshold: int = 1) -> List[Dict[str, Any]]:
|
|||
'created_at',
|
||||
'account_id',
|
||||
'sandbox'
|
||||
).range(start_range, end_range).execute()
|
||||
).order('created_at', desc=True).range(start_range, end_range).execute()
|
||||
|
||||
# Debug info - print raw response
|
||||
print(f"Response data length: {len(result.data)}")
|
||||
|
|
|
@ -487,12 +487,7 @@ export default function ThreadPage({
|
|||
|
||||
const handleStreamError = useCallback((errorMessage: string) => {
|
||||
console.error(`[PAGE] Stream hook error: ${errorMessage}`);
|
||||
if (
|
||||
!errorMessage.toLowerCase().includes('not found') &&
|
||||
!errorMessage.toLowerCase().includes('agent run is not running')
|
||||
) {
|
||||
toast.error(`Stream Error: ${errorMessage}`);
|
||||
}
|
||||
toast.error(errorMessage, { duration: 15000 });
|
||||
}, []);
|
||||
|
||||
const handleStreamClose = useCallback(() => {
|
||||
|
|
|
@ -428,10 +428,7 @@ export default function ThreadPage({
|
|||
|
||||
const handleStreamError = useCallback((errorMessage: string) => {
|
||||
console.error(`[PAGE] Stream hook error: ${errorMessage}`);
|
||||
if (!errorMessage.toLowerCase().includes('not found') &&
|
||||
!errorMessage.toLowerCase().includes('agent run is not running')) {
|
||||
toast.error(`Stream Error: ${errorMessage}`);
|
||||
}
|
||||
toast.error(errorMessage, { duration: 15000 });
|
||||
}, []);
|
||||
|
||||
const handleStreamClose = useCallback(() => {
|
||||
|
@ -930,7 +927,7 @@ export default function ThreadPage({
|
|||
try {
|
||||
const metadata = JSON.parse(toolMsg.metadata);
|
||||
return metadata.assistant_message_id === assistantMsg.message_id;
|
||||
} catch (e) {
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -252,6 +252,21 @@ export function useAgentStream(
|
|||
return;
|
||||
}
|
||||
|
||||
// --- Check for error messages first ---
|
||||
try {
|
||||
const jsonData = JSON.parse(processedData);
|
||||
if (jsonData.status === 'error') {
|
||||
console.error('[useAgentStream] Received error status message:', jsonData);
|
||||
const errorMessage = jsonData.message || 'Unknown error occurred';
|
||||
setError(errorMessage);
|
||||
toast.error(errorMessage, { duration: 15000 });
|
||||
callbacks.onError?.(errorMessage);
|
||||
return;
|
||||
}
|
||||
} catch (jsonError) {
|
||||
// Not JSON or could not parse as JSON, continue processing
|
||||
}
|
||||
|
||||
// --- Process JSON messages ---
|
||||
const message: UnifiedMessage = safeJsonParse(processedData, null);
|
||||
if (!message) {
|
||||
|
@ -379,6 +394,9 @@ export function useAgentStream(
|
|||
|
||||
console.error('[useAgentStream] Streaming error:', errorMessage, err);
|
||||
setError(errorMessage);
|
||||
|
||||
// Show error toast with longer duration
|
||||
toast.error(errorMessage, { duration: 15000 });
|
||||
|
||||
const runId = currentRunIdRef.current;
|
||||
if (!runId) {
|
||||
|
@ -389,53 +407,6 @@ export function useAgentStream(
|
|||
return;
|
||||
}
|
||||
|
||||
// Check agent status immediately after an error
|
||||
getAgentStatus(runId)
|
||||
.then((agentStatus) => {
|
||||
if (!isMountedRef.current) return; // Check mount status again after async call
|
||||
|
||||
if (agentStatus.status === 'running') {
|
||||
console.warn(
|
||||
`[useAgentStream] Stream error for ${runId}, but agent is still running. Finalizing with error.`,
|
||||
);
|
||||
finalizeStream('error', runId); // Stream failed, even if agent might still be running backend-side
|
||||
toast.warning('Stream interrupted. Agent might still be running.');
|
||||
} else {
|
||||
// Map backend terminal status to hook terminal status
|
||||
const finalStatus = mapAgentStatus(agentStatus.status);
|
||||
console.log(
|
||||
`[useAgentStream] Stream error for ${runId}, agent status is ${agentStatus.status}. Finalizing stream as ${finalStatus}.`,
|
||||
);
|
||||
finalizeStream(finalStatus, runId);
|
||||
}
|
||||
})
|
||||
.catch((statusError) => {
|
||||
if (!isMountedRef.current) return;
|
||||
|
||||
const statusErrorMessage =
|
||||
statusError instanceof Error
|
||||
? statusError.message
|
||||
: String(statusError);
|
||||
console.error(
|
||||
`[useAgentStream] Error checking agent status for ${runId} after stream error: ${statusErrorMessage}`,
|
||||
);
|
||||
|
||||
const isNotFoundError =
|
||||
statusErrorMessage.includes('not found') ||
|
||||
statusErrorMessage.includes('404') ||
|
||||
statusErrorMessage.includes('does not exist');
|
||||
|
||||
if (isNotFoundError) {
|
||||
console.log(
|
||||
`[useAgentStream] Agent run ${runId} not found after stream error. Finalizing.`,
|
||||
);
|
||||
// Revert to agent_not_running for this specific case
|
||||
finalizeStream('agent_not_running', runId);
|
||||
} else {
|
||||
// For other status check errors, finalize with the original stream error
|
||||
finalizeStream('error', runId);
|
||||
}
|
||||
});
|
||||
},
|
||||
[finalizeStream],
|
||||
);
|
||||
|
|
|
@ -859,6 +859,22 @@ export const streamAgent = (
|
|||
return;
|
||||
}
|
||||
|
||||
// Check for error status messages
|
||||
try {
|
||||
const jsonData = JSON.parse(rawData);
|
||||
if (jsonData.status === 'error') {
|
||||
console.error(`[STREAM] Error status received for ${agentRunId}:`, jsonData);
|
||||
|
||||
// Pass the error message to the callback
|
||||
callbacks.onError(jsonData.message || 'Unknown error occurred');
|
||||
|
||||
// Don't close the stream for error status messages as they may continue
|
||||
return;
|
||||
}
|
||||
} catch (jsonError) {
|
||||
// Not JSON or invalid JSON, continue with normal processing
|
||||
}
|
||||
|
||||
// Check for "Agent run not found" error
|
||||
if (
|
||||
rawData.includes('Agent run') &&
|
||||
|
|
Loading…
Reference in New Issue