···395395 let request_id = Printf.sprintf "set_perm_mode_%f" (Unix.gettimeofday ()) in
396396 let request = Sdk_control.Request.set_permission_mode ~mode () in
397397 let _response = send_control_request t ~request_id request in
398398- Log.info (fun m -> m "Permission mode set to: %a" Permissions.Mode.pp mode)
398398+ Log.info (fun m -> m "Permission mode set to: %s" (Permissions.Mode.to_string mode))
399399400400let set_model t model =
401401 let model_str = Model.to_string model in
402402 let request_id = Printf.sprintf "set_model_%f" (Unix.gettimeofday ()) in
403403 let request = Sdk_control.Request.set_model ~model:model_str () in
404404 let _response = send_control_request t ~request_id request in
405405- Log.info (fun m -> m "Model set to: %a" Model.pp model)
405405+ Log.info (fun m -> m "Model set to: %s" model_str)
406406407407let set_model_string t model_str =
408408 set_model t (Model.of_string model_str)
···416416 | Ok si -> si
417417 | Error msg -> raise (Invalid_argument ("Failed to decode server info: " ^ msg))
418418 in
419419- Log.info (fun m -> m "Retrieved server info: %a" Sdk_control.Server_info.pp server_info);
419419+ Log.info (fun m -> m "Retrieved server info: %a" (Jsont.pp_value Sdk_control.Server_info.jsont ()) server_info);
420420 server_info
421421 | None ->
422422 raise (Failure "No response data from get_server_info request")
+2-47
lib/content_block.ml
···1919 |> Jsont.Object.mem "text" Jsont.string ~enc:text
2020 |> Jsont.Object.keep_unknown Jsont.json_mems ~enc:unknown
2121 |> Jsont.Object.finish
2222-2323- let pp fmt t =
2424- if String.length t.text > 60 then
2525- let truncated = String.sub t.text 0 57 in
2626- Fmt.pf fmt "Text[%s...]" truncated
2727- else
2828- Fmt.pf fmt "Text[%S]" t.text
2922end
30233124module Tool_use = struct
···8881 |> Jsont.Object.mem "input" Input.jsont ~enc:input
8982 |> Jsont.Object.keep_unknown Jsont.json_mems ~enc:unknown
9083 |> Jsont.Object.finish
9191-9292- let pp fmt t =
9393- let keys = Input.keys t.input in
9494- let key_info = match keys with
9595- | [] -> ""
9696- | [k] -> Printf.sprintf "(%s)" k
9797- | ks -> Printf.sprintf "(%d params)" (List.length ks)
9898- in
9999- Fmt.pf fmt "Tool[%s%s]" t.name key_info
10084end
1018510286module Tool_result = struct
···124108 |> Jsont.Object.opt_mem "is_error" Jsont.bool ~enc:is_error
125109 |> Jsont.Object.keep_unknown Jsont.json_mems ~enc:unknown
126110 |> Jsont.Object.finish
127127-128128- let pp fmt t =
129129- match t.is_error, t.content with
130130- | Some true, Some c ->
131131- if String.length c > 40 then
132132- let truncated = String.sub c 0 37 in
133133- Fmt.pf fmt "ToolResult[error: %s...]" truncated
134134- else
135135- Fmt.pf fmt "ToolResult[error: %s]" c
136136- | _, Some c ->
137137- if String.length c > 40 then
138138- let truncated = String.sub c 0 37 in
139139- Fmt.pf fmt "ToolResult[%s...]" truncated
140140- else
141141- Fmt.pf fmt "ToolResult[%s]" c
142142- | _, None -> Fmt.pf fmt "ToolResult[empty]"
143111end
144112145113module Thinking = struct
···162130 |> Jsont.Object.mem "signature" Jsont.string ~enc:signature
163131 |> Jsont.Object.keep_unknown Jsont.json_mems ~enc:unknown
164132 |> Jsont.Object.finish
165165-166166- let pp fmt t =
167167- if String.length t.thinking > 50 then
168168- let truncated = String.sub t.thinking 0 47 in
169169- Fmt.pf fmt "Thinking[%s...]" truncated
170170- else
171171- Fmt.pf fmt "Thinking[%s]" t.thinking
172133end
173134174135type t =
···211172 ~tag_to_string:Fun.id ~tag_compare:String.compare
212173 |> Jsont.Object.finish
213174214214-let pp fmt = function
215215- | Text t -> Text.pp fmt t
216216- | Tool_use t -> Tool_use.pp fmt t
217217- | Tool_result t -> Tool_result.pp fmt t
218218- | Thinking t -> Thinking.pp fmt t
219219-220175let log_received t =
221221- Log.debug (fun m -> m "Received content block: %a" pp t)
176176+ Log.debug (fun m -> m "Received content block: %a" (Jsont.pp_value jsont ()) t)
222177223178let log_sending t =
224224- Log.debug (fun m -> m "Sending content block: %a" pp t)
179179+ Log.debug (fun m -> m "Sending content block: %a" (Jsont.pp_value jsont ()) t)
+10-20
lib/content_block.mli
···25252626 val jsont : t Jsont.t
2727 (** [jsont] is the Jsont codec for text blocks.
2828- Use [Jsont.Json.encode jsont] and [Jsont.Json.decode jsont] for serialization. *)
2929-3030- val pp : Format.formatter -> t -> unit
3131- (** [pp fmt t] pretty-prints the text block. *)
2828+ Use [Jsont.Json.encode jsont] and [Jsont.Json.decode jsont] for serialization.
2929+ Use [Jsont.pp_value jsont ()] for pretty-printing. *)
3230end
33313432(** {1 Tool Use Blocks} *)
···91899290 val jsont : t Jsont.t
9391 (** [jsont] is the Jsont codec for tool use blocks.
9494- Use [Jsont.Json.encode jsont] and [Jsont.Json.decode jsont] for serialization. *)
9595-9696- val pp : Format.formatter -> t -> unit
9797- (** [pp fmt t] pretty-prints the tool use block. *)
9292+ Use [Jsont.Json.encode jsont] and [Jsont.Json.decode jsont] for serialization.
9393+ Use [Jsont.pp_value jsont ()] for pretty-printing. *)
9894end
999510096(** {1 Tool Result Blocks} *)
···125121126122 val jsont : t Jsont.t
127123 (** [jsont] is the Jsont codec for tool result blocks.
128128- Use [Jsont.Json.encode jsont] and [Jsont.Json.decode jsont] for serialization. *)
129129-130130- val pp : Format.formatter -> t -> unit
131131- (** [pp fmt t] pretty-prints the tool result block. *)
124124+ Use [Jsont.Json.encode jsont] and [Jsont.Json.decode jsont] for serialization.
125125+ Use [Jsont.pp_value jsont ()] for pretty-printing. *)
132126end
133127134128(** {1 Thinking Blocks} *)
···155149156150 val jsont : t Jsont.t
157151 (** [jsont] is the Jsont codec for thinking blocks.
158158- Use [Jsont.Json.encode jsont] and [Jsont.Json.decode jsont] for serialization. *)
159159-160160- val pp : Format.formatter -> t -> unit
161161- (** [pp fmt t] pretty-prints the thinking block. *)
152152+ Use [Jsont.Json.encode jsont] and [Jsont.Json.decode jsont] for serialization.
153153+ Use [Jsont.pp_value jsont ()] for pretty-printing. *)
162154end
163155164156(** {1 Content Block Union Type} *)
···184176185177val jsont : t Jsont.t
186178(** [jsont] is the Jsont codec for content blocks.
187187- Use [Jsont.Json.encode jsont] and [Jsont.Json.decode jsont] for serialization. *)
188188-189189-val pp : Format.formatter -> t -> unit
190190-(** [pp fmt t] pretty-prints any content block. *)
179179+ Use [Jsont.Json.encode jsont] and [Jsont.Json.decode jsont] for serialization.
180180+ Use [Jsont.pp_value jsont ()] for pretty-printing. *)
191181192182(** {1 Logging} *)
193183
+2-14
lib/control.ml
···11let src = Logs.Src.create "claude.control" ~doc:"Claude control messages"
22module Log = (val Logs.src_log src : Logs.LOG)
3344-(* Helper for pretty-printing JSON *)
55-let pp_json fmt json =
66- let s = match Jsont_bytesrw.encode_string' Jsont.json json with
77- | Ok s -> s
88- | Error err -> Jsont.Error.to_string err
99- in
1010- Fmt.string fmt s
1111-124type t = {
135 request_id : string;
146 subtype : string;
···4840 | Error e -> raise (Invalid_argument ("Control.of_json: " ^ e)))
4941 | Error e -> raise (Invalid_argument ("Control.of_json: " ^ e))
50425151-let pp fmt t =
5252- Fmt.pf fmt "@[<2>Control@ { request_id = %S;@ subtype = %S;@ data = %a }@]"
5353- t.request_id t.subtype pp_json t.data
5454-5543let log_received t =
5656- Log.debug (fun m -> m "Received control message: %a" pp t)
4444+ Log.debug (fun m -> m "Received control message: %a" (Jsont.pp_value jsont ()) t)
57455846let log_sending t =
5959- Log.debug (fun m -> m "Sending control message: %a" pp t)4747+ Log.debug (fun m -> m "Sending control message: %a" (Jsont.pp_value jsont ()) t)
-3
lib/control.mli
···3535(** [of_json json] parses a control message from JSON.
3636 @raise Invalid_argument if the JSON is not a valid control message. *)
37373838-val pp : Format.formatter -> t -> unit
3939-(** [pp fmt t] pretty-prints the control message. *)
4040-4138(** {1 Logging} *)
42394340val log_received : t -> unit
···5454 | Control_request of Control_request.t
55555656val jsont : t Jsont.t
5757-(** Codec for incoming messages. Uses the "type" field to discriminate. *)
5858-5959-val pp : Format.formatter -> t -> unit
6060-(** [pp fmt t] pretty-prints the incoming message. *)
5757+(** Codec for incoming messages. Uses the "type" field to discriminate.
5858+ Use [Jsont.pp_value jsont ()] for pretty-printing. *)
+2-109
lib/message.ml
···125125 match Jsont.Json.decode incoming_jsont json with
126126 | Ok v -> v
127127 | Error msg -> raise (Invalid_argument ("User.of_json: " ^ msg))
128128-129129- let pp fmt t =
130130- match t.content with
131131- | String s ->
132132- if String.length s > 60 then
133133- let truncated = String.sub s 0 57 in
134134- Fmt.pf fmt "@[<2>User:@ %s...@]" truncated
135135- else
136136- Fmt.pf fmt "@[<2>User:@ %S@]" s
137137- | Blocks blocks ->
138138- let text_count = List.length (List.filter (function
139139- | Content_block.Text _ -> true | _ -> false) blocks) in
140140- let tool_result_count = List.length (List.filter (function
141141- | Content_block.Tool_result _ -> true | _ -> false) blocks) in
142142- match text_count, tool_result_count with
143143- | 1, 0 ->
144144- let text = List.find_map (function
145145- | Content_block.Text t -> Some (Content_block.Text.text t)
146146- | _ -> None) blocks in
147147- Fmt.pf fmt "@[<2>User:@ %a@]" Fmt.(option string) text
148148- | 0, 1 ->
149149- Fmt.pf fmt "@[<2>User:@ [tool result]@]"
150150- | 0, n when n > 1 ->
151151- Fmt.pf fmt "@[<2>User:@ [%d tool results]@]" n
152152- | _ ->
153153- Fmt.pf fmt "@[<2>User:@ [%d blocks]@]" (List.length blocks)
154128end
155129156130module Assistant = struct
···294268 match Jsont.Json.decode incoming_jsont json with
295269 | Ok v -> v
296270 | Error msg -> raise (Invalid_argument ("Assistant.of_json: " ^ msg))
297297-298298- let pp fmt t =
299299- let text_count = List.length (get_text_blocks t) in
300300- let tool_count = List.length (get_tool_uses t) in
301301- let thinking_count = List.length (get_thinking t) in
302302- match text_count, tool_count, thinking_count with
303303- | 1, 0, 0 ->
304304- (* Simple text response *)
305305- Fmt.pf fmt "@[<2>Assistant@ [%s]:@ %S@]"
306306- t.model (combined_text t)
307307- | _, 0, 0 when text_count > 0 ->
308308- (* Multiple text blocks *)
309309- Fmt.pf fmt "@[<2>Assistant@ [%s]:@ %d text blocks@]"
310310- t.model text_count
311311- | 0, _, 0 when tool_count > 0 ->
312312- (* Only tool uses *)
313313- let tools = get_tool_uses t in
314314- let tool_names = List.map Content_block.Tool_use.name tools in
315315- Fmt.pf fmt "@[<2>Assistant@ [%s]:@ tools(%a)@]"
316316- t.model Fmt.(list ~sep:comma string) tool_names
317317- | _ ->
318318- (* Mixed content *)
319319- let parts = [] in
320320- let parts = if text_count > 0 then
321321- Printf.sprintf "%d text" text_count :: parts else parts in
322322- let parts = if tool_count > 0 then
323323- Printf.sprintf "%d tools" tool_count :: parts else parts in
324324- let parts = if thinking_count > 0 then
325325- Printf.sprintf "%d thinking" thinking_count :: parts else parts in
326326- Fmt.pf fmt "@[<2>Assistant@ [%s]:@ %s@]"
327327- t.model (String.concat ", " (List.rev parts))
328271end
329272330273module System = struct
···427370 match Jsont.Json.decode jsont json with
428371 | Ok v -> v
429372 | Error msg -> raise (Invalid_argument ("System.of_json: " ^ msg))
430430-431431- let pp fmt = function
432432- | Init i ->
433433- Fmt.pf fmt "@[<2>System.init@ { session_id = %a;@ model = %a;@ cwd = %a }@]"
434434- Fmt.(option string) i.session_id
435435- Fmt.(option string) i.model
436436- Fmt.(option string) i.cwd
437437- | Error e ->
438438- Fmt.pf fmt "@[<2>System.error@ { error = %s }@]" e.error
439439- | Other o ->
440440- Fmt.pf fmt "@[<2>System.%s@ { ... }@]" o.subtype
441373end
442374443375module Result = struct
···493425 let output_cost = float_of_int output *. output_price /. 1_000_000. in
494426 Some (input_cost +. output_cost)
495427 | _ -> None
496496-497497- let pp fmt t =
498498- Fmt.pf fmt "@[<2>Usage@ { input = %a;@ output = %a;@ total = %a;@ \
499499- cache_creation = %a;@ cache_read = %a }@]"
500500- Fmt.(option int) t.input_tokens
501501- Fmt.(option int) t.output_tokens
502502- Fmt.(option int) t.total_tokens
503503- Fmt.(option int) t.cache_creation_input_tokens
504504- Fmt.(option int) t.cache_read_input_tokens
505505-506428 end
507429508430 type t = {
···620542 match Jsont.Json.decode jsont json with
621543 | Ok v -> v
622544 | Error msg -> raise (Invalid_argument ("Result.of_json: " ^ msg))
623623-624624- let pp fmt t =
625625- if t.is_error then
626626- Fmt.pf fmt "@[<2>Result.error@ { session = %S;@ result = %a }@]"
627627- t.session_id
628628- Fmt.(option string) t.result
629629- else
630630- let tokens_info = match t.usage with
631631- | Some u ->
632632- let input = Usage.input_tokens u in
633633- let output = Usage.output_tokens u in
634634- let cached = Usage.cache_read_input_tokens u in
635635- (match input, output, cached with
636636- | Some i, Some o, Some c when c > 0 ->
637637- Printf.sprintf " (tokens: %d+%d, cached: %d)" i o c
638638- | Some i, Some o, _ ->
639639- Printf.sprintf " (tokens: %d+%d)" i o
640640- | _ -> "")
641641- | None -> ""
642642- in
643643- Fmt.pf fmt "@[<2>Result.%s@ { duration = %dms;@ cost = $%.4f%s }@]"
644644- t.subtype
645645- t.duration_ms
646646- (Option.value t.total_cost_usd ~default:0.0)
647647- tokens_info
648545end
649546650547type t =
···708605 | Ok v -> v
709606 | Error msg -> raise (Invalid_argument ("Message.of_json: " ^ msg))
710607711711-let pp fmt = function
712712- | User t -> User.pp fmt t
713713- | Assistant t -> Assistant.pp fmt t
714714- | System t -> System.pp fmt t
715715- | Result t -> Result.pp fmt t
716716-717608let is_user = function User _ -> true | _ -> false
718609let is_assistant = function Assistant _ -> true | _ -> false
719610let is_system = function System _ -> true | _ -> false
···739630 | System s -> System.session_id s
740631 | Result r -> Some (Result.session_id r)
741632 | _ -> None
633633+634634+let pp = Jsont.pp_value jsont ()
742635743636let log_received t =
744637 Log.info (fun m -> m "← %a" pp t)
-15
lib/message.mli
···5959 val of_json : Jsont.json -> t
6060 (** [of_json json] parses a user message from JSON.
6161 @raise Invalid_argument if the JSON is not a valid user message. *)
6262-6363- val pp : Format.formatter -> t -> unit
6464- (** [pp fmt t] pretty-prints the user message. *)
6562end
66636764(** {1 Assistant Messages} *)
···130127 val of_json : Jsont.json -> t
131128 (** [of_json json] parses an assistant message from JSON.
132129 @raise Invalid_argument if the JSON is not a valid assistant message. *)
133133-134134- val pp : Format.formatter -> t -> unit
135135- (** [pp fmt t] pretty-prints the assistant message. *)
136130end
137131138132(** {1 System Messages} *)
···213207 val of_json : Jsont.json -> t
214208 (** [of_json json] parses from JSON.
215209 @raise Invalid_argument if invalid. *)
216216-217217- val pp : Format.formatter -> t -> unit
218218- (** [pp fmt t] pretty-prints the message. *)
219210end
220211221212(** {1 Result Messages} *)
···266257 val total_cost_estimate : t -> input_price:float -> output_price:float -> float option
267258 (** [total_cost_estimate t ~input_price ~output_price] estimates the cost based on token
268259 prices per million tokens. Returns None if token counts are not available. *)
269269-270270- val pp : Format.formatter -> t -> unit
271271- (** [pp fmt t] pretty-prints the usage statistics. *)
272260 end
273261274262 type t
···341329 val of_json : Jsont.json -> t
342330 (** [of_json json] parses a result message from JSON.
343331 @raise Invalid_argument if the JSON is not a valid result message. *)
344344-345345- val pp : Format.formatter -> t -> unit
346346- (** [pp fmt t] pretty-prints the result message. *)
347332end
348333349334(** {1 Message Union Type} *)
-3
lib/model.ml
···2222 | "claude-opus-4" -> `Opus_4
2323 | "claude-haiku-4" -> `Haiku_4
2424 | s -> `Custom s
2525-2626-let pp fmt t =
2727- Fmt.string fmt (to_string t)
-3
lib/model.mli
···3131 Examples:
3232 - "claude-sonnet-4-5" becomes [`Sonnet_4_5]
3333 - "future-model" becomes [`Custom "future-model"] *)
3434-3535-val pp : Format.formatter -> t -> unit
3636-(** [pp fmt t] pretty-prints a model identifier. *)
···354354(** {1 Serialization} *)
355355356356val jsont : t Jsont.t
357357-(** [jsont] is the Jsont codec for Options.t *)
358358-359359-val pp : Format.formatter -> t -> unit
360360-(** [pp fmt t] pretty-prints the options. *)
357357+(** [jsont] is the Jsont codec for Options.t
358358+ Use [Jsont.pp_value jsont ()] for pretty-printing. *)
361359362360(** {1 Logging} *)
363361
···2626 (** [of_string s] parses a mode from its string representation.
2727 @raise Invalid_argument if the string is not a valid mode. *)
28282929- val pp : Format.formatter -> t -> unit
3030- (** [pp fmt t] pretty-prints the mode. *)
3131-3229 val jsont : t Jsont.t
3333- (** [jsont] is the Jsont codec for permission modes. *)
3030+ (** [jsont] is the Jsont codec for permission modes.
3131+ Use [Jsont.pp_value jsont ()] for pretty-printing. *)
3432end
35333634(** {1 Permission Behaviors} *)
···5048 val of_string : string -> t
5149 (** [of_string s] parses a behavior from its string representation.
5250 @raise Invalid_argument if the string is not a valid behavior. *)
5353-5454- val pp : Format.formatter -> t -> unit
5555- (** [pp fmt t] pretty-prints the behavior. *)
56515752 val jsont : t Jsont.t
5858- (** [jsont] is the Jsont codec for permission behaviors. *)
5353+ (** [jsont] is the Jsont codec for permission behaviors.
5454+ Use [Jsont.pp_value jsont ()] for pretty-printing. *)
5955end
60566157(** {1 Permission Rules} *)
···8581 val unknown : t -> Unknown.t
8682 (** [unknown t] returns the unknown fields. *)
87838888- val pp : Format.formatter -> t -> unit
8989- (** [pp fmt t] pretty-prints the rule. *)
9090-9184 val jsont : t Jsont.t
9292- (** [jsont] is the Jsont codec for permission rules. *)
8585+ (** [jsont] is the Jsont codec for permission rules.
8686+ Use [Jsont.pp_value jsont ()] for pretty-printing. *)
9387end
94889589(** {1 Permission Updates} *)
···156150 val unknown : t -> Unknown.t
157151 (** [unknown t] returns the unknown fields. *)
158152159159- val pp : Format.formatter -> t -> unit
160160- (** [pp fmt t] pretty-prints the update. *)
161161-162153 val jsont : t Jsont.t
163163- (** [jsont] is the Jsont codec for permission updates. *)
154154+ (** [jsont] is the Jsont codec for permission updates.
155155+ Use [Jsont.pp_value jsont ()] for pretty-printing. *)
164156end
165157166158(** {1 Permission Context} *)
···184176185177 val unknown : t -> Unknown.t
186178 (** [unknown t] returns the unknown fields. *)
187187-188188- val pp : Format.formatter -> t -> unit
189189- (** [pp fmt t] pretty-prints the context. *)
190179191180 val jsont : t Jsont.t
192192- (** [jsont] is the Jsont codec for permission context. *)
181181+ (** [jsont] is the Jsont codec for permission context.
182182+ Use [Jsont.pp_value jsont ()] for pretty-printing. *)
193183end
194184195185(** {1 Permission Results} *)
···222212 @param interrupt Whether to interrupt further execution
223213 @param unknown Optional unknown fields to preserve *)
224214225225- val pp : Format.formatter -> t -> unit
226226- (** [pp fmt t] pretty-prints the result. *)
227227-228215 val jsont : t Jsont.t
229229- (** [jsont] is the Jsont codec for permission results. *)
216216+ (** [jsont] is the Jsont codec for permission results.
217217+ Use [Jsont.pp_value jsont ()] for pretty-printing. *)
230218end
231219232220(** {1 Permission Callbacks} *)
···167167 (** [get_server_info ?unknown ()] creates a server info request. *)
168168169169 val jsont : t Jsont.t
170170- (** [jsont] is the jsont codec for requests. *)
171171-172172- val pp : Format.formatter -> t -> unit
173173- (** [pp fmt t] pretty-prints the request. *)
170170+ (** [jsont] is the jsont codec for requests.
171171+ Use [Jsont.pp_value jsont ()] for pretty-printing. *)
174172end
175173176174(** {1 Response Types} *)
···206204 (** [error ~request_id ~error ?unknown] creates an error response. *)
207205208206 val jsont : t Jsont.t
209209- (** [jsont] is the jsont codec for responses. *)
210210-211211- val pp : Format.formatter -> t -> unit
212212- (** [pp fmt t] pretty-prints the response. *)
207207+ (** [jsont] is the jsont codec for responses.
208208+ Use [Jsont.pp_value jsont ()] for pretty-printing. *)
213209end
214210215211(** {1 Control Messages} *)
···244240(** [create_response ~response ?unknown ()] creates a control response message. *)
245241246242val jsont : t Jsont.t
247247-(** [jsont] is the jsont codec for control messages. *)
248248-249249-val pp : Format.formatter -> t -> unit
250250-(** [pp fmt t] pretty-prints the control message. *)
243243+(** [jsont] is the jsont codec for control messages.
244244+ Use [Jsont.pp_value jsont ()] for pretty-printing. *)
251245252246(** {1 Logging} *)
253247···331325 (** [unknown t] returns the unknown fields. *)
332326333327 val jsont : t Jsont.t
334334- (** [jsont] is the jsont codec for server info. *)
335335-336336- val pp : Format.formatter -> t -> unit
337337- (** [pp fmt t] pretty-prints the server info. *)
328328+ (** [jsont] is the jsont codec for server info.
329329+ Use [Jsont.pp_value jsont ()] for pretty-printing. *)
338330end
-14
lib/structured_output.ml
···3333 match Jsont.Json.decode jsont json with
3434 | Ok t -> t
3535 | Error msg -> raise (Invalid_argument ("Structured_output.of_json: " ^ msg))
3636-3737-let pp fmt t =
3838- let schema_str =
3939- match Jsont_bytesrw.encode_string' ~format:Jsont.Minify Jsont.json t.json_schema with
4040- | Ok s -> s
4141- | Error err -> Jsont.Error.to_string err
4242- in
4343- let truncated =
4444- if String.length schema_str > 100 then
4545- String.sub schema_str 0 97 ^ "..."
4646- else
4747- schema_str
4848- in
4949- Fmt.pf fmt "@[<2>StructuredOutput { schema = %s }@]" truncated
-3
lib/structured_output.mli
···166166(** [of_json json] parses an output format from JSON.
167167 Internal use only.
168168 @raise Invalid_argument if the JSON is not a valid output format. *)
169169-170170-val pp : Format.formatter -> t -> unit
171171-(** [pp fmt t] pretty-prints the output format. *)