Serialize a params model to a wire dict, merging `meta` into `_meta`. Shared by `ClientPeer` and `Connection` so every typed convenience method gets the same `_meta` handling. `meta` keys take precedence over any `_meta` already present on the model. `meta` is serialized through `R
(model: BaseModel | None, meta: Meta | None = None)
| 42 | |
| 43 | |
| 44 | def dump_params(model: BaseModel | None, meta: Meta | None = None) -> dict[str, Any] | None: |
| 45 | """Serialize a params model to a wire dict, merging `meta` into `_meta`. |
| 46 | |
| 47 | Shared by `ClientPeer` and `Connection` so every typed convenience method |
| 48 | gets the same `_meta` handling. `meta` keys take precedence over any |
| 49 | `_meta` already present on the model. |
| 50 | |
| 51 | `meta` is serialized through `RequestParams` so Python field names emit |
| 52 | their wire aliases: an inbound `ctx.meta` carries `progress_token` (the |
| 53 | key `_extract_meta` validation produces), and forwarding it outbound via |
| 54 | `meta=ctx.meta` must put `progressToken` back on the wire. Keys not |
| 55 | declared on `RequestParamsMeta` pass through unchanged. |
| 56 | """ |
| 57 | out = model.model_dump(by_alias=True, mode="json", exclude_none=True) if model is not None else None |
| 58 | if meta: |
| 59 | wire_meta = RequestParams(_meta=cast(RequestParamsMeta, meta)).model_dump(by_alias=True, mode="json")["_meta"] |
| 60 | out = dict(out or {}) |
| 61 | out["_meta"] = {**out.get("_meta", {}), **wire_meta} |
| 62 | return out |
| 63 | |
| 64 | |
| 65 | class ClientPeer: |