@@ -18,6 +18,12 @@ public function __construct(
1818 }
1919
2020 /**
21+ * Parse a streamed chat response and yield assistant content fragments as they arrive.
22+ *
23+ * The generator return value contains the reconstructed response payload, including
24+ * usage and rebuilt choices for SSE responses, or the original decoded JSON body
25+ * when the upstream responded with non-streamed JSON.
26+ *
2127 * @param array{body?: mixed, content-type?: mixed} $response
2228 * @return \Generator<string, mixed, mixed, array{usage?: array<string, mixed>, choices?: array<int, array<string, mixed>>}>
2329 * @throws Exception
@@ -85,6 +91,9 @@ public function parseStreamChatResponse(array $response): \Generator {
8591 }
8692
8793 /**
94+ * Parse one SSE event payload, update the accumulated choice state, and return any
95+ * assistant text fragments that should be yielded to the caller.
96+ *
8897 * @param string $event
8998 * @param bool $done
9099 * @param array<string, mixed>|null $usage
@@ -166,6 +175,12 @@ private function parseSseEvent(string $event, bool &$done, ?array &$usage, array
166175 }
167176
168177 /**
178+ * Append a raw chunk to the SSE buffer and parse all complete events currently
179+ * available in that buffer.
180+ *
181+ * When `$flush` is true, the remaining buffer is parsed as a final event even if it
182+ * is not terminated by the usual blank-line SSE delimiter.
183+ *
169184 * @param string $chunk
170185 * @param string $buffer
171186 * @param bool $done
@@ -197,6 +212,9 @@ private function parseSseChunk(string $chunk, string &$buffer, bool &$done, ?arr
197212 }
198213
199214 /**
215+ * Merge fragmented `tool_calls` deltas from multiple SSE events into the accumulated
216+ * message structure for a single choice.
217+ *
200218 * @param array<string, mixed> $message
201219 * @param array<int, array<string, mixed>> $toolCallsDelta
202220 */
0 commit comments