Skip to content
Draft
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
43 changes: 15 additions & 28 deletions src/Chat/Messages/Stream/Adapters/AGUIAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,17 @@ protected function handleText(TextChunk $chunk): iterable
$this->messageStarted = true;

yield $this->sse([
'type' => 'TextMessageStart',
'type' => 'TEXT_MESSAGE_START',
'messageId' => $this->currentMessageId,
'role' => 'assistant',
'timestamp' => $this->timestamp(),
]);
}

// Stream content delta
yield $this->sse([
'type' => 'TextMessageContent',
'type' => 'TEXT_MESSAGE_CONTENT',
'messageId' => $this->currentMessageId,
'delta' => $chunk->content,
'timestamp' => $this->timestamp(),
]);
}

Expand All @@ -100,24 +98,21 @@ protected function handleReasoning(ReasoningChunk $chunk): iterable
$this->reasoningMessageId = $chunk->messageId;

yield $this->sse([
'type' => 'ReasoningStart',
'type' => 'REASONING_START',
'messageId' => $chunk->messageId,
'timestamp' => $this->timestamp(),
]);

yield $this->sse([
'type' => 'ReasoningMessageStart',
'type' => 'REASONING_MESSAGE_START',
'messageId' => $chunk->messageId,
'role' => 'assistant',
'timestamp' => $this->timestamp(),
]);
}

yield $this->sse([
'type' => 'ReasoningMessageContent',
'type' => 'REASONING_MESSAGE_CONTENT',
'messageId' => $chunk->messageId,
'delta' => $chunk->content,
'timestamp' => $this->timestamp(),
]);
}

Expand All @@ -140,30 +135,27 @@ protected function handleToolCall(ToolCallChunk $chunk): iterable
$this->toolCallStarted[$toolCallId] = true;

yield $this->sse([
'type' => 'ToolCallStart',
'type' => 'TOOL_CALL_START',
'toolCallId' => $toolCallId,
'toolCallName' => $toolName,
'parentMessageId' => $this->currentMessageId,
'timestamp' => $this->timestamp(),
]);
}

// Stream tool arguments as JSON
$args = $chunk->tool->getInputs();
if ($args !== []) {
yield $this->sse([
'type' => 'ToolCallArgs',
'type' => 'TOOL_CALL_ARGS',
'toolCallId' => $toolCallId,
'delta' => json_encode($args),
'timestamp' => $this->timestamp(),
]);
}

// Mark tool call arguments as complete
yield $this->sse([
'type' => 'ToolCallEnd',
'type' => 'TOOL_CALL_END',
'toolCallId' => $toolCallId,
'timestamp' => $this->timestamp(),
]);
}

Expand All @@ -174,11 +166,10 @@ protected function handleToolResult(ToolResultChunk $chunk): iterable

// Emit tool result
yield $this->sse([
'type' => 'ToolCallResult',
'type' => 'TOOL_CALL_RESULT',
'toolCallId' => $toolCallId,
'content' => $chunk->tool->getResult(),
'role' => 'tool',
'timestamp' => $this->timestamp(),
]);
}

Expand All @@ -187,10 +178,9 @@ public function start(): iterable
$this->runId = $this->generateId('run');

yield $this->sse([
'type' => 'RunStarted',
'type' => 'RUN_STARTED',
'runId' => $this->runId,
'threadId' => $this->threadId,
'timestamp' => $this->timestamp(),
]);
}

Expand All @@ -206,15 +196,13 @@ protected function endReasoning(): iterable
}

yield $this->sse([
'type' => 'ReasoningMessageEnd',
'type' => 'REASONING_MESSAGE_END',
'messageId' => $this->reasoningMessageId,
'timestamp' => $this->timestamp(),
]);

yield $this->sse([
'type' => 'ReasoningEnd',
'type' => 'REASONING_END',
'messageId' => $this->reasoningMessageId,
'timestamp' => $this->timestamp(),
]);

$this->reasoningStarted = false;
Expand All @@ -233,9 +221,8 @@ protected function endText(): iterable
}

yield $this->sse([
'type' => 'TextMessageEnd',
'type' => 'TEXT_MESSAGE_END',
'messageId' => $this->currentMessageId,
'timestamp' => $this->timestamp(),
]);

$this->messageStarted = false;
Expand All @@ -254,9 +241,9 @@ public function end(): iterable
// Emit RunFinished event
if ($this->runId !== null) {
yield $this->sse([
'type' => 'RunFinished',
'type' => 'RUN_FINISHED',
'runId' => $this->runId,
'timestamp' => $this->timestamp(),
'threadId' => $this->threadId,
]);
}
}
Expand Down
Loading