<svg width="100%" viewBox="0 0 760 560" role="img" xmlns="http://www.w3.org/2000/svg">
  <title>Chat turn — two connections: persistent SSE out, fire-and-forget POST in</title>
  <desc>Browser opens a long-lived SSE stream for output, posts each turn separately; sudo_chat plugin pushes deltas back through sudo-api, which fans them out to every open tab.</desc>
  <style>
    text{font-family:"Anthropic Sans",-apple-system,system-ui,"Segoe UI",sans-serif}
    .t{font-size:14px;font-weight:500;text-anchor:middle;dominant-baseline:central}
    .s{font-size:12px;text-anchor:middle;dominant-baseline:central}
    .stp{font-size:12px;fill:#c2c0b6}
    .lbl{font-size:11px;fill:#9c9a92;text-anchor:middle}
    rect{stroke-width:.5}
    .neutral{fill:#444441;stroke:#b4b2a9} .nt{fill:#d3d1c7} .ns{fill:#b4b2a9}
    .blue{fill:#1f3b7a;stroke:#8aaef0}    .bt{fill:#cfdcf4} .bs{fill:#8aaef0}
    .orange{fill:#712b13;stroke:#f0997b}  .ot{fill:#f5c4b3} .os{fill:#f0997b}
    .arrow{fill:none;stroke:#9c9a92;stroke-width:1.5}
    .arrow-ok{fill:none;stroke:#1d9e75;stroke-width:1.5}
  </style>
  <defs>
    <marker id="a" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">
      <path d="M2 1L8 5L2 9" fill="none" stroke="context-stroke" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
    </marker>
  </defs>

  <text class="stp" x="40"  y="64">1</text>
  <text class="stp" x="40"  y="184">2</text>
  <text class="stp" x="40"  y="304">3</text>
  <text class="stp" x="40"  y="424">4</text>
  <text class="stp" x="40"  y="524">5</text>

  <rect class="neutral" x="100" y="40" width="280" height="60" rx="8"/>
  <text class="t nt" x="240" y="64">Browser opens SSE</text>
  <text class="s ns" x="240" y="84">GET /v1/me/chat/stream?token=JWT</text>

  <rect class="blue" x="420" y="40" width="240" height="60" rx="8"/>
  <text class="t bt" x="540" y="64">sudo-api</text>
  <text class="s bs" x="540" y="84">SSE stays open for the session</text>
  <path class="arrow" d="M 380 70 L 418 70" marker-end="url(#a)"/>

  <rect class="neutral" x="100" y="160" width="280" height="60" rx="8"/>
  <text class="t nt" x="240" y="184">Browser posts a turn</text>
  <text class="s ns" x="240" y="204">POST /v1/me/chat/turn  (fire-and-forget)</text>

  <rect class="orange" x="420" y="280" width="240" height="60" rx="8"/>
  <text class="t ot" x="540" y="304">hermes  ·  sudo_chat plugin</text>
  <text class="s os" x="540" y="324">:8652/inbound · agent runs</text>

  <rect class="blue" x="100" y="280" width="280" height="60" rx="8"/>
  <text class="t bt" x="240" y="304">sudo-api forwards</text>
  <text class="s bs" x="240" y="324">POST :8652/inbound  · internal bearer</text>

  <rect class="blue" x="100" y="400" width="280" height="60" rx="8"/>
  <text class="t bt" x="240" y="424">sudo-api fans out deltas</text>
  <text class="s bs" x="240" y="444">/v1/internal/chat/push → all open tabs</text>

  <rect class="orange" x="420" y="400" width="240" height="60" rx="8"/>
  <text class="t ot" x="540" y="424">plugin pushes tokens back</text>
  <text class="s os" x="540" y="444">POST /v1/internal/chat/push</text>

  <rect class="neutral" x="100" y="500" width="560" height="44" rx="8"/>
  <text class="t nt" x="380" y="522">Browser receives SSE deltas (multi-tab — every open /chat sees them)</text>

  <path class="arrow"    d="M 380 190 L 540 190 L 540 278" marker-end="url(#a)"/>
  <path class="arrow"    d="M 540 340 L 540 398" marker-end="url(#a)"/>
  <path class="arrow-ok" d="M 420 430 L 382 430" marker-end="url(#a)"/>
  <path class="arrow-ok" d="M 240 460 L 240 498" marker-end="url(#a)"/>
</svg>
