mirror of https://github.com/kortix-ai/suna.git
error msg toast on stream
This commit is contained in:
parent
c01508d56f
commit
734f3dbe55
|
@ -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 -->
|
<!-- This tool indicates successful completion of all tasks -->
|
||||||
<!-- The system will stop execution after this tool is used -->
|
<!-- The system will stop execution after this tool is used -->
|
||||||
</complete>
|
</complete>
|
||||||
|
|
||||||
\n<web-browser-takeover> Example:
|
\n<web-browser-takeover> Example:
|
||||||
<!-- Use web-browser-takeover when automated tools cannot handle the page interaction -->
|
<!-- Use web-browser-takeover when automated tools cannot handle the page interaction -->
|
||||||
<!-- Examples of when takeover is needed: -->
|
<!-- Examples of when takeover is needed: -->
|
||||||
|
|
|
@ -187,6 +187,8 @@ async def run_agent(
|
||||||
elif "gpt-4" in model_name.lower():
|
elif "gpt-4" in model_name.lower():
|
||||||
max_tokens = 4096
|
max_tokens = 4096
|
||||||
|
|
||||||
|
model_name = "open123router/nvidia/llama-3.1-nemotron-ultra-253b-v1:free"
|
||||||
|
|
||||||
response = await thread_manager.run_thread(
|
response = await thread_manager.run_thread(
|
||||||
thread_id=thread_id,
|
thread_id=thread_id,
|
||||||
system_prompt=system_message,
|
system_prompt=system_message,
|
||||||
|
|
|
@ -16,6 +16,8 @@ Make sure your environment variables are properly set:
|
||||||
- DAYTONA_SERVER_URL
|
- 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 asyncio
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
@ -81,7 +83,7 @@ async def get_old_projects(days_threshold: int = 1) -> List[Dict[str, Any]]:
|
||||||
'created_at',
|
'created_at',
|
||||||
'account_id',
|
'account_id',
|
||||||
'sandbox'
|
'sandbox'
|
||||||
).range(start_range, end_range).execute()
|
).order('created_at', desc=True).range(start_range, end_range).execute()
|
||||||
|
|
||||||
# Debug info - print raw response
|
# Debug info - print raw response
|
||||||
print(f"Response data length: {len(result.data)}")
|
print(f"Response data length: {len(result.data)}")
|
||||||
|
|
|
@ -550,12 +550,7 @@ export default function ThreadPage({
|
||||||
|
|
||||||
const handleStreamError = useCallback((errorMessage: string) => {
|
const handleStreamError = useCallback((errorMessage: string) => {
|
||||||
console.error(`[PAGE] Stream hook error: ${errorMessage}`);
|
console.error(`[PAGE] Stream hook error: ${errorMessage}`);
|
||||||
if (
|
toast.error(errorMessage, { duration: 15000 });
|
||||||
!errorMessage.toLowerCase().includes('not found') &&
|
|
||||||
!errorMessage.toLowerCase().includes('agent run is not running')
|
|
||||||
) {
|
|
||||||
toast.error(`Stream Error: ${errorMessage}`);
|
|
||||||
}
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleStreamClose = useCallback(() => {
|
const handleStreamClose = useCallback(() => {
|
||||||
|
|
|
@ -442,10 +442,7 @@ export default function ThreadPage({
|
||||||
|
|
||||||
const handleStreamError = useCallback((errorMessage: string) => {
|
const handleStreamError = useCallback((errorMessage: string) => {
|
||||||
console.error(`[PAGE] Stream hook error: ${errorMessage}`);
|
console.error(`[PAGE] Stream hook error: ${errorMessage}`);
|
||||||
if (!errorMessage.toLowerCase().includes('not found') &&
|
toast.error(errorMessage, { duration: 15000 });
|
||||||
!errorMessage.toLowerCase().includes('agent run is not running')) {
|
|
||||||
toast.error(`Stream Error: ${errorMessage}`);
|
|
||||||
}
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleStreamClose = useCallback(() => {
|
const handleStreamClose = useCallback(() => {
|
||||||
|
@ -944,7 +941,7 @@ export default function ThreadPage({
|
||||||
try {
|
try {
|
||||||
const metadata = safeJsonParse<{ assistant_message_id?: string }>(toolMsg.metadata, {});
|
const metadata = safeJsonParse<{ assistant_message_id?: string }>(toolMsg.metadata, {});
|
||||||
return metadata.assistant_message_id === assistantMsg.message_id;
|
return metadata.assistant_message_id === assistantMsg.message_id;
|
||||||
} catch (e) {
|
} catch {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -252,6 +252,21 @@ export function useAgentStream(
|
||||||
return;
|
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 ---
|
// --- Process JSON messages ---
|
||||||
const message: UnifiedMessage = safeJsonParse(processedData, null);
|
const message: UnifiedMessage = safeJsonParse(processedData, null);
|
||||||
if (!message) {
|
if (!message) {
|
||||||
|
@ -379,6 +394,9 @@ export function useAgentStream(
|
||||||
|
|
||||||
console.error('[useAgentStream] Streaming error:', errorMessage, err);
|
console.error('[useAgentStream] Streaming error:', errorMessage, err);
|
||||||
setError(errorMessage);
|
setError(errorMessage);
|
||||||
|
|
||||||
|
// Show error toast with longer duration
|
||||||
|
toast.error(errorMessage, { duration: 15000 });
|
||||||
|
|
||||||
const runId = currentRunIdRef.current;
|
const runId = currentRunIdRef.current;
|
||||||
if (!runId) {
|
if (!runId) {
|
||||||
|
@ -389,53 +407,6 @@ export function useAgentStream(
|
||||||
return;
|
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],
|
[finalizeStream],
|
||||||
);
|
);
|
||||||
|
|
|
@ -859,6 +859,22 @@ export const streamAgent = (
|
||||||
return;
|
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
|
// Check for "Agent run not found" error
|
||||||
if (
|
if (
|
||||||
rawData.includes('Agent run') &&
|
rawData.includes('Agent run') &&
|
||||||
|
|
Loading…
Reference in New Issue