Skip to content

Commit 976103d

Browse files
authored
Merge pull request #1117 from yeyan1996/fix/streaming
fix: correct JSON formatting in streamAgent for message type checks
2 parents 9138038 + 45947eb commit 976103d

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

frontend/src/lib/api.ts

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ export const streamAgent = (
10011001
eventSource.onmessage = (event) => {
10021002
try {
10031003
const rawData = event.data;
1004-
if (rawData.includes('"type":"ping"')) return;
1004+
if (rawData.includes('"type": "ping"')) return;
10051005

10061006
// Log raw data for debugging (truncated for readability)
10071007
console.log(
@@ -1055,18 +1055,15 @@ export const streamAgent = (
10551055

10561056
// Check for completion messages
10571057
if (
1058-
rawData.includes('"type":"status"') &&
1059-
rawData.includes('"status":"completed"')
1058+
rawData.includes('"type": "status"') &&
1059+
rawData.includes('"status": "completed"')
10601060
) {
10611061
console.log(
10621062
`[STREAM] Detected completion status message for ${agentRunId}`,
10631063
);
10641064

10651065
// Check for specific completion messages that indicate we should stop checking
1066-
if (
1067-
rawData.includes('Run data not available for streaming') ||
1068-
rawData.includes('Stream ended with status: completed')
1069-
) {
1066+
if (rawData.includes('Agent run completed successfully')) {
10701067
console.log(
10711068
`[STREAM] Detected final completion message for ${agentRunId}, adding to non-running set`,
10721069
);
@@ -1087,24 +1084,15 @@ export const streamAgent = (
10871084

10881085
// Check for thread run end message
10891086
if (
1090-
rawData.includes('"type":"status"') &&
1091-
rawData.includes('"status_type":"thread_run_end"')
1087+
rawData.includes('"type": "status"') &&
1088+
rawData.includes('thread_run_end')
10921089
) {
10931090
console.log(
10941091
`[STREAM] Detected thread run end message for ${agentRunId}`,
10951092
);
10961093

1097-
// Add to non-running set
1098-
nonRunningAgentRuns.add(agentRunId);
1099-
11001094
// Notify about the message
11011095
callbacks.onMessage(rawData);
1102-
1103-
// Clean up
1104-
eventSource.close();
1105-
activeStreams.delete(agentRunId);
1106-
callbacks.onClose();
1107-
11081096
return;
11091097
}
11101098

0 commit comments

Comments
 (0)