Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build-base-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
branches:
- main
- deep-agent
- feat/rhitaif-221

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this branch included in the yml?

workflow_dispatch: # Allow manual trigger for testing

permissions:
Expand Down
6 changes: 6 additions & 0 deletions src/frontend/hooks/useStreamingAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,9 @@ export function useStreamingAPI(threadId: string) {
onMetadata(data) {
setTraceId(data.trace_id);
},
onCodeOutput(content) {
console.log('[code_execution_output]', content);
},
};

manager.stream(streamRequest, callbacks).then(() => {
Expand Down Expand Up @@ -704,6 +707,9 @@ export function useStreamingAPI(threadId: string) {
onMetadata(data) {
setTraceId(data.trace_id);
},
onCodeOutput(content) {
console.log('[code_execution_output]', content);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose behind logging in console?

},
};

await manager.stream(resumeRequest, callbacks);
Expand Down
10 changes: 8 additions & 2 deletions src/frontend/lib/streaming/SSEProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import type { HITLInterruptValue } from '@/types/deep-agent';
export type SSEChunk =
| { type: 'token'; content: string; chunk_id: number }
| { type: 'message'; content: Message; chunk_id: number }
| { type: 'interrupt'; content: { value: HITLInterruptValue; resumable: boolean }; chunk_id: number };
| { type: 'interrupt'; content: { value: HITLInterruptValue; resumable: boolean }; chunk_id: number }
| { type: 'code_output'; content: string; chunk_id: number };

export type McpStatusData = {
tool: string;
Expand Down Expand Up @@ -32,7 +33,7 @@ function isRecord(value: unknown): value is Record<string, unknown> {
function parseSSEChunkPayload(parsed: unknown): SSEChunk | null {
if (!isRecord(parsed)) return null;
const type = parsed.type;
if (type !== 'token' && type !== 'message' && type !== 'interrupt') return null;
if (type !== 'token' && type !== 'message' && type !== 'interrupt' && type !== 'code_output') return null;
const chunkIdRaw = parsed.chunk_id;
if (typeof chunkIdRaw !== 'number' || !Number.isFinite(chunkIdRaw)) {
return null;
Expand All @@ -44,6 +45,11 @@ function parseSSEChunkPayload(parsed: unknown): SSEChunk | null {
return { type: 'token', content: contentUnknown, chunk_id: chunkIdRaw };
}

if (type === 'code_output') {
if (typeof contentUnknown !== 'string') return null;
return { type: 'code_output', content: contentUnknown, chunk_id: chunkIdRaw };
}

if (type === 'interrupt') {
if (!isRecord(contentUnknown)) return null;
let rawValue: unknown = contentUnknown.value;
Expand Down
3 changes: 3 additions & 0 deletions src/frontend/lib/streaming/StreamingManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export type StreamCallback = {
onDone: () => void;
onMcpStatus?: (event: McpStreamStatusEvent) => void;
onMetadata?: (data: StreamMetadataPayload) => void;
onCodeOutput?: (content: string) => void;
};

export class StreamingManager {
Expand Down Expand Up @@ -93,6 +94,8 @@ export class StreamingManager {
callbacks.onToken(event.data.content);
} else if (event.data.type === 'interrupt') {
callbacks.onInterrupt(event.data.content);
} else if (event.data.type === 'code_output') {
callbacks.onCodeOutput?.(event.data.content);
} else {
callbacks.onMessage(event.data.content);
}
Expand Down
21 changes: 20 additions & 1 deletion src/server/router/proxy.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ async function proxyRoutes(fastify: FastifyInstance) {

const runBody: Record<string, unknown> = {
assistant_id: 'agent',
stream_mode: ['messages', 'updates'],
stream_mode: ['messages', 'updates', 'custom'],
};
if (isResume) {
runBody.command = { resume: message };
Expand Down Expand Up @@ -529,6 +529,25 @@ async function proxyRoutes(fastify: FastifyInstance) {
continue;
}

// Code execution output streaming (stream_mode="custom")
// Skip ALL custom events to avoid corrupting partial text state
if (sseType === 'custom') {
if (
typeof parsed === 'object' &&
parsed !== null &&
(parsed as Record<string, unknown>).type === 'code_output'
) {
const codeChunk = {
type: 'code_output',
content: (parsed as Record<string, unknown>).content ?? '',
chunk_id: chunkId,
};
reply.raw.write(`event: chunk\ndata: ${JSON.stringify(codeChunk)}\n\n`);
chunkId++;
}
continue;
}

const [uiChunks, nextPartial] = translateMessageEvent(
sseType,
parsed,
Expand Down