@@ -227,7 +227,9 @@ Parameters mirror `generate(...)`:
227227
228228Each ` PatchEvent ` carries:
229229
230- - ` event.op ` — the raw RFC 6902 operation (` {"op": "add", "path": ..., "value": ...} ` )
230+ - ` event.op ` — the raw RFC 6902 operation (` {"op": "add", "path": ..., "value": ...} ` ).
231+ The dottxt API only ever emits ` add ` ops; ` dottxt.apply_add(doc, path, value) `
232+ folds one into a object in place, returning the (possibly new) root.
231233- ` event.snapshot ` — an independent deep copy of the JSON object built up to
232234 and including this op
233235- ` event.is_leaf ` / ` event.field ` / ` event.value ` convenience demux for
@@ -274,6 +276,26 @@ milliseconds in while `reply` continues to stream. If you need the full
274276object so far (e.g. to log progress or hand a partial object to another
275277service), use ` event.snapshot ` .
276278
279+ To drive your own state from the raw ops instead of the snapshot (e.g. to
280+ mirror the object into a store of your own) fold each ` event.op ` in with
281+ ` apply_add ` :
282+
283+ ``` python
284+ from dottxt import AsyncDotTxt, apply_add
285+
286+ async def main ():
287+ client = AsyncDotTxt()
288+ doc = {} # the stream's first op is the root seed
289+ stream = client.stream(
290+ model = " openai/gpt-oss-20b" ,
291+ response_format = SupportTicket,
292+ input = " I was charged twice this month, please refund the duplicate." ,
293+ )
294+ async for event in stream:
295+ doc = apply_add(doc, event.op[" path" ], event.op[" value" ])
296+ print (doc)
297+ ```
298+
277299Errors:
278300
279301- ` dottxt.PatchStreamError ` : raised when the gateway returns a non-200
0 commit comments