My agentic slop goes here. Not intended for anyone else!
1(** Content blocks for Claude messages.
2
3 This module defines the various types of content blocks that can appear
4 in Claude messages, including text, tool use, tool results, and thinking blocks. *)
5
6(** The log source for content block operations *)
7val src : Logs.Src.t
8
9(** {1 Text Blocks} *)
10
11module Text : sig
12 (** Plain text content blocks. *)
13
14 type t
15 (** The type of text blocks. *)
16
17 val create : string -> t
18 (** [create text] creates a new text block with the given text content. *)
19
20 val text : t -> string
21 (** [text t] returns the text content of the block. *)
22
23 val to_json : t -> Ezjsonm.value
24 (** [to_json t] converts the text block to its JSON representation. *)
25
26 val of_json : Ezjsonm.value -> t
27 (** [of_json json] parses a text block from JSON.
28 @raise Invalid_argument if the JSON is not a valid text block. *)
29
30 val pp : Format.formatter -> t -> unit
31 (** [pp fmt t] pretty-prints the text block. *)
32end
33
34(** {1 Tool Use Blocks} *)
35
36module Tool_use : sig
37 (** Tool invocation requests from the assistant. *)
38
39 module Input : sig
40 (** Tool input parameters. *)
41
42 type t
43 (** Abstract type for tool inputs. *)
44
45 val of_string_pairs : (string * string) list -> t
46 (** [of_string_pairs pairs] creates tool input from string key-value pairs. *)
47
48 val of_assoc : (string * Ezjsonm.value) list -> t
49 (** [of_assoc assoc] creates tool input from an association list. *)
50
51 val get_string : t -> string -> string option
52 (** [get_string t key] returns the string value for [key], if present. *)
53
54 val get_int : t -> string -> int option
55 (** [get_int t key] returns the integer value for [key], if present. *)
56
57 val get_bool : t -> string -> bool option
58 (** [get_bool t key] returns the boolean value for [key], if present. *)
59
60 val get_float : t -> string -> float option
61 (** [get_float t key] returns the float value for [key], if present. *)
62
63 val keys : t -> string list
64 (** [keys t] returns all keys in the input. *)
65
66 val to_json : t -> Ezjsonm.value
67 (** [to_json t] converts to JSON representation. Internal use only. *)
68
69 val of_json : Ezjsonm.value -> t
70 (** [of_json json] parses from JSON. Internal use only. *)
71 end
72
73 type t
74 (** The type of tool use blocks. *)
75
76 val create : id:string -> name:string -> input:Input.t -> t
77 (** [create ~id ~name ~input] creates a new tool use block.
78 @param id Unique identifier for this tool invocation
79 @param name Name of the tool to invoke
80 @param input Parameters for the tool *)
81
82 val id : t -> string
83 (** [id t] returns the unique identifier of the tool use. *)
84
85 val name : t -> string
86 (** [name t] returns the name of the tool being invoked. *)
87
88 val input : t -> Input.t
89 (** [input t] returns the input parameters for the tool. *)
90
91 val to_json : t -> Ezjsonm.value
92 (** [to_json t] converts the tool use block to its JSON representation. *)
93
94 val of_json : Ezjsonm.value -> t
95 (** [of_json json] parses a tool use block from JSON.
96 @raise Invalid_argument if the JSON is not a valid tool use block. *)
97
98 val pp : Format.formatter -> t -> unit
99 (** [pp fmt t] pretty-prints the tool use block. *)
100end
101
102(** {1 Tool Result Blocks} *)
103
104module Tool_result : sig
105 (** Results from tool invocations. *)
106
107 type t
108 (** The type of tool result blocks. *)
109
110 val create : tool_use_id:string -> ?content:string -> ?is_error:bool -> unit -> t
111 (** [create ~tool_use_id ?content ?is_error ()] creates a new tool result block.
112 @param tool_use_id The ID of the corresponding tool use block
113 @param content Optional result content
114 @param is_error Whether the tool execution resulted in an error *)
115
116 val tool_use_id : t -> string
117 (** [tool_use_id t] returns the ID of the corresponding tool use. *)
118
119 val content : t -> string option
120 (** [content t] returns the optional result content. *)
121
122 val is_error : t -> bool option
123 (** [is_error t] returns whether this result represents an error. *)
124
125 val to_json : t -> Ezjsonm.value
126 (** [to_json t] converts the tool result block to its JSON representation. *)
127
128 val of_json : Ezjsonm.value -> t
129 (** [of_json json] parses a tool result block from JSON.
130 @raise Invalid_argument if the JSON is not a valid tool result block. *)
131
132 val pp : Format.formatter -> t -> unit
133 (** [pp fmt t] pretty-prints the tool result block. *)
134end
135
136(** {1 Thinking Blocks} *)
137
138module Thinking : sig
139 (** Assistant's internal reasoning blocks. *)
140
141 type t
142 (** The type of thinking blocks. *)
143
144 val create : thinking:string -> signature:string -> t
145 (** [create ~thinking ~signature] creates a new thinking block.
146 @param thinking The assistant's internal reasoning
147 @param signature Cryptographic signature for verification *)
148
149 val thinking : t -> string
150 (** [thinking t] returns the thinking content. *)
151
152 val signature : t -> string
153 (** [signature t] returns the cryptographic signature. *)
154
155 val to_json : t -> Ezjsonm.value
156 (** [to_json t] converts the thinking block to its JSON representation. *)
157
158 val of_json : Ezjsonm.value -> t
159 (** [of_json json] parses a thinking block from JSON.
160 @raise Invalid_argument if the JSON is not a valid thinking block. *)
161
162 val pp : Format.formatter -> t -> unit
163 (** [pp fmt t] pretty-prints the thinking block. *)
164end
165
166(** {1 Content Block Union Type} *)
167
168type t =
169 | Text of Text.t
170 | Tool_use of Tool_use.t
171 | Tool_result of Tool_result.t
172 | Thinking of Thinking.t
173(** The type of content blocks, which can be text, tool use, tool result, or thinking. *)
174
175val text : string -> t
176(** [text s] creates a text content block. *)
177
178val tool_use : id:string -> name:string -> input:Tool_use.Input.t -> t
179(** [tool_use ~id ~name ~input] creates a tool use content block. *)
180
181val tool_result : tool_use_id:string -> ?content:string -> ?is_error:bool -> unit -> t
182(** [tool_result ~tool_use_id ?content ?is_error ()] creates a tool result content block. *)
183
184val thinking : thinking:string -> signature:string -> t
185(** [thinking ~thinking ~signature] creates a thinking content block. *)
186
187val to_json : t -> Ezjsonm.value
188(** [to_json t] converts any content block to its JSON representation. *)
189
190val of_json : Ezjsonm.value -> t
191(** [of_json json] parses a content block from JSON.
192 @raise Invalid_argument if the JSON is not a valid content block. *)
193
194val pp : Format.formatter -> t -> unit
195(** [pp fmt t] pretty-prints any content block. *)
196
197(** {1 Logging} *)
198
199val log_received : t -> unit
200(** [log_received t] logs that a content block was received. *)
201
202val log_sending : t -> unit
203(** [log_sending t] logs that a content block is being sent. *)