SPB Git forge

spb/wp13_uqo

Public
3commits 1branches 1releases
1.2 MBsize
maindefault branch
4 h agolast push
TeX 93.9% Python 6%
2.6 KB · 49 lines latex
Raw Blame History
1% --- Streaming SSE parsing and event dispatch ---2\begin{figure}[htbp]3\centering4\begin{tikzpicture}[vqfont]56% Pipeline backbone7\node[vqpurple, minimum height=1.5cm, text width=2.0cm] (prov) at (0,0)8  {\textbf{Provider}\\\vqsmall \texttt{/v1/messages}\\ streaming HTTP};9\node[vqblue, minimum height=1.5cm, text width=2.35cm] (buf) at (3.5,0)10  {\textbf{Byte buffer}\\\vqsmall append chunk;\\split on \texttt{\textbackslash n};\\\textit{keep partial line}};11\node[vqblue, minimum height=1.5cm, text width=2.2cm] (disp) at (7.05,0)12  {\textbf{Dispatch}\\\vqsmall parse \texttt{data:} line\\$\to$ JSON;\\switch on \texttt{type}};1314% Right-hand output channels15\node[vqgreen,  text width=3.0cm] (txt)  at (11.0, 2.55)16  {\textbf{Answer channel}\\\vqsmall \texttt{text\_delta} $\to$ accumulate $+$ stream};17\node[vqgreen,  text width=3.0cm] (think) at (11.0, 1.05)18  {\textbf{Reasoning channel}\\\vqsmall \texttt{thinking\_delta} $\to$ separate panel};19\node[vqorange, text width=3.0cm] (tool) at (11.0,-0.65)20  {\textbf{Tool assembler}\\\vqsmall \texttt{start} $\cdot$ \texttt{input\_json\_delta}$^\ast$ $\cdot$ \texttt{stop} $\to$ args};21\node[vqred,    text width=3.0cm] (tok)  at (11.0,-2.35)22  {\textbf{Token ledger}\\\vqsmall \texttt{message\_start/delta/stop} $\to$ usage};2324% Backbone arrows25\draw[vqflow] (prov) -- node[vqtag, above]{raw bytes} (buf);26\draw[vqflow] (buf)  -- node[vqtag, above]{\texttt{data:} lines} (disp);2728% Fan-out29\draw[vqarr] (disp.east) to[out=20,in=180]  (txt.west);30\draw[vqarr] (disp.east) to[out=8,in=180]   (think.west);31\draw[vqarr] (disp.east) to[out=-8,in=180]  (tool.west);32\draw[vqarr] (disp.east) to[out=-22,in=180] (tok.west);3334% Downstream consequences35\draw[vqdash] (tool.south) to[out=-90,in=-90] node[vqtag, below, pos=0.5]{executable $\to$ loop} (disp.south);3637\end{tikzpicture}38\caption{\textbf{Streaming transport and event dispatch.} The server reads the provider's39Server-Sent Event stream as raw bytes, buffers them, and splits on newlines while \emph{retaining40the trailing partial line} (frames do not align with packet boundaries). Each \texttt{data:} line41is parsed to JSON and dispatched on its \texttt{type} onto four channels: answer text is42accumulated and forwarded; private reasoning is forwarded to a separate panel; a tool call is43assembled from a \texttt{content\_block\_start}, a sequence of \texttt{input\_json\_delta}44fragments ($\ast$), and a closing \texttt{content\_block\_stop}, becoming executable only once the45block closes; and usage events feed the token ledger. Heavy arrows are the byte backbone; thin46arrows are per-event dispatch.}47\label{fig:streaming}48\end{figure}49