# stream.py
from __future__ import annotations
import json
from typing import Callable, Any
from .client import Client
from .decoder import iter_frames

def stream_post(
    cli: Client,
    path: str,
    body: dict,
    on_delta: Callable[[dict, bool], Any] | None = None,
    *,
    params: dict | None = None
):
    resp = cli.post(path, body, stream=True, params=params)
    for typ, raw in iter_frames(resp):
        if typ == "done":
            on_delta and on_delta({}, True)
            break
        try:
            on_delta and on_delta(json.loads(raw), False)
        except Exception:
            continue