this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

more

+705 -6
+19 -1
claudeio/lib/message.ml
··· 194 194 195 195 module System = struct 196 196 module Data = struct 197 - type t = value 197 + (* Store both the raw JSON and provide typed accessors *) 198 + type t = value (* The full JSON data *) 198 199 199 200 let empty = `O [] 200 201 ··· 205 206 let get_int t key = JU.get_field_int_opt t key 206 207 207 208 let get_bool t key = JU.get_field_bool_opt t key 209 + 210 + let get_float t key = JU.get_field_float_opt t key 211 + 212 + let get_list t key = 213 + match t with 214 + | `O fields -> 215 + (match List.assoc_opt key fields with 216 + | Some (`A lst) -> Some lst 217 + | _ -> None) 218 + | _ -> None 219 + 220 + let get_field t key = 221 + match t with 222 + | `O fields -> List.assoc_opt key fields 223 + | _ -> None 224 + 225 + let raw_json t = t 208 226 209 227 let to_json t = t 210 228 let of_json json = json
+14 -1
claudeio/lib/message.mli
··· 112 112 (** System message data. *) 113 113 114 114 type t 115 - (** Abstract type for system message data. *) 115 + (** Abstract type for system message data. Contains both the raw JSON 116 + and typed accessors for common fields. *) 116 117 117 118 val empty : t 118 119 (** [empty] creates empty data. *) ··· 128 129 129 130 val get_bool : t -> string -> bool option 130 131 (** [get_bool t key] returns the boolean value for [key], if present. *) 132 + 133 + val get_float : t -> string -> float option 134 + (** [get_float t key] returns the float value for [key], if present. *) 135 + 136 + val get_list : t -> string -> Ezjsonm.value list option 137 + (** [get_list t key] returns the list value for [key], if present. *) 138 + 139 + val get_field : t -> string -> Ezjsonm.value option 140 + (** [get_field t key] returns the raw JSON value for [key], if present. *) 141 + 142 + val raw_json : t -> Ezjsonm.value 143 + (** [raw_json t] returns the full underlying JSON data. *) 131 144 132 145 val to_json : t -> Ezjsonm.value 133 146 (** [to_json t] converts to JSON representation. Internal use only. *)
+53 -2
claudeio/lib/options.ml
··· 14 14 model : string option; 15 15 cwd : Eio.Fs.dir_ty Eio.Path.t option; 16 16 env : (string * string) list; 17 + continue_conversation : bool; 18 + resume : string option; 19 + max_turns : int option; 20 + permission_prompt_tool_name : string option; 21 + settings : string option; 22 + add_dirs : string list; 23 + extra_args : (string * string option) list; 24 + debug_stderr : Eio.Flow.sink_ty Eio.Flow.sink option; 17 25 } 18 26 19 27 let default = { ··· 27 35 model = None; 28 36 cwd = None; 29 37 env = []; 38 + continue_conversation = false; 39 + resume = None; 40 + max_turns = None; 41 + permission_prompt_tool_name = None; 42 + settings = None; 43 + add_dirs = []; 44 + extra_args = []; 45 + debug_stderr = None; 30 46 } 31 47 32 48 let create ··· 40 56 ?model 41 57 ?cwd 42 58 ?(env = []) 59 + ?(continue_conversation = false) 60 + ?resume 61 + ?max_turns 62 + ?permission_prompt_tool_name 63 + ?settings 64 + ?(add_dirs = []) 65 + ?(extra_args = []) 66 + ?debug_stderr 43 67 () = 44 68 { allowed_tools; disallowed_tools; max_thinking_tokens; 45 69 system_prompt; append_system_prompt; permission_mode; 46 - permission_callback; model; cwd; env } 70 + permission_callback; model; cwd; env; 71 + continue_conversation; resume; max_turns; 72 + permission_prompt_tool_name; settings; add_dirs; 73 + extra_args; debug_stderr } 47 74 48 75 let allowed_tools t = t.allowed_tools 49 76 let disallowed_tools t = t.disallowed_tools ··· 55 82 let model t = t.model 56 83 let cwd t = t.cwd 57 84 let env t = t.env 85 + let continue_conversation t = t.continue_conversation 86 + let resume t = t.resume 87 + let max_turns t = t.max_turns 88 + let permission_prompt_tool_name t = t.permission_prompt_tool_name 89 + let settings t = t.settings 90 + let add_dirs t = t.add_dirs 91 + let extra_args t = t.extra_args 92 + let debug_stderr t = t.debug_stderr 58 93 59 94 let with_allowed_tools tools t = { t with allowed_tools = tools } 60 95 let with_disallowed_tools tools t = { t with disallowed_tools = tools } ··· 66 101 let with_model model t = { t with model = Some model } 67 102 let with_cwd cwd t = { t with cwd = Some cwd } 68 103 let with_env env t = { t with env } 104 + let with_continue_conversation continue t = { t with continue_conversation = continue } 105 + let with_resume session_id t = { t with resume = Some session_id } 106 + let with_max_turns turns t = { t with max_turns = Some turns } 107 + let with_permission_prompt_tool_name tool t = { t with permission_prompt_tool_name = Some tool } 108 + let with_settings path t = { t with settings = Some path } 109 + let with_add_dirs dirs t = { t with add_dirs = dirs } 110 + let with_extra_args args t = { t with extra_args = args } 111 + let with_debug_stderr sink t = { t with debug_stderr = Some sink } 69 112 70 113 let to_json t = 71 114 let fields = [] in ··· 148 191 { allowed_tools; disallowed_tools; max_thinking_tokens; 149 192 system_prompt; append_system_prompt; permission_mode; 150 193 permission_callback = Some Permissions.default_allow_callback; 151 - model; cwd = None; env } 194 + model; cwd = None; env; 195 + continue_conversation = false; 196 + resume = None; 197 + max_turns = None; 198 + permission_prompt_tool_name = None; 199 + settings = None; 200 + add_dirs = []; 201 + extra_args = []; 202 + debug_stderr = None } 152 203 | _ -> raise (Invalid_argument "Options.of_json: expected object") 153 204 154 205 let pp fmt t =
+68 -2
claudeio/lib/options.mli
··· 30 30 ?model:string -> 31 31 ?cwd:Eio.Fs.dir_ty Eio.Path.t -> 32 32 ?env:(string * string) list -> 33 + ?continue_conversation:bool -> 34 + ?resume:string -> 35 + ?max_turns:int -> 36 + ?permission_prompt_tool_name:string -> 37 + ?settings:string -> 38 + ?add_dirs:string list -> 39 + ?extra_args:(string * string option) list -> 40 + ?debug_stderr:Eio.Flow.sink_ty Eio.Flow.sink -> 33 41 unit -> t 34 42 (** [create ?allowed_tools ?disallowed_tools ?max_thinking_tokens ?system_prompt 35 - ?append_system_prompt ?permission_mode ?permission_callback ?model ?cwd ?env ()] 43 + ?append_system_prompt ?permission_mode ?permission_callback ?model ?cwd ?env 44 + ?continue_conversation ?resume ?max_turns ?permission_prompt_tool_name ?settings 45 + ?add_dirs ?extra_args ?debug_stderr ()] 36 46 creates a new configuration. 37 47 @param allowed_tools List of explicitly allowed tool names 38 48 @param disallowed_tools List of explicitly disallowed tool names ··· 43 53 @param permission_callback Custom permission callback 44 54 @param model Override the default model 45 55 @param cwd Working directory for file operations 46 - @param env Environment variables to set *) 56 + @param env Environment variables to set 57 + @param continue_conversation Continue an existing conversation 58 + @param resume Resume from a specific session ID 59 + @param max_turns Maximum number of conversation turns 60 + @param permission_prompt_tool_name Tool name for permission prompts 61 + @param settings Path to settings file 62 + @param add_dirs Additional directories to allow access to 63 + @param extra_args Additional CLI flags to pass through 64 + @param debug_stderr Sink for debug output when debug-to-stderr is set *) 47 65 48 66 (** {1 Accessors} *) 49 67 ··· 77 95 val env : t -> (string * string) list 78 96 (** [env t] returns the environment variables. *) 79 97 98 + val continue_conversation : t -> bool 99 + (** [continue_conversation t] returns whether to continue an existing conversation. *) 100 + 101 + val resume : t -> string option 102 + (** [resume t] returns the optional session ID to resume. *) 103 + 104 + val max_turns : t -> int option 105 + (** [max_turns t] returns the optional maximum number of turns. *) 106 + 107 + val permission_prompt_tool_name : t -> string option 108 + (** [permission_prompt_tool_name t] returns the optional tool name for permission prompts. *) 109 + 110 + val settings : t -> string option 111 + (** [settings t] returns the optional path to settings file. *) 112 + 113 + val add_dirs : t -> string list 114 + (** [add_dirs t] returns the list of additional allowed directories. *) 115 + 116 + val extra_args : t -> (string * string option) list 117 + (** [extra_args t] returns the additional CLI flags. *) 118 + 119 + val debug_stderr : t -> Eio.Flow.sink_ty Eio.Flow.sink option 120 + (** [debug_stderr t] returns the optional debug output sink. *) 121 + 80 122 (** {1 Builders} *) 81 123 82 124 val with_allowed_tools : string list -> t -> t ··· 108 150 109 151 val with_env : (string * string) list -> t -> t 110 152 (** [with_env env t] sets the environment variables. *) 153 + 154 + val with_continue_conversation : bool -> t -> t 155 + (** [with_continue_conversation continue t] sets whether to continue conversation. *) 156 + 157 + val with_resume : string -> t -> t 158 + (** [with_resume session_id t] sets the session ID to resume. *) 159 + 160 + val with_max_turns : int -> t -> t 161 + (** [with_max_turns turns t] sets the maximum number of turns. *) 162 + 163 + val with_permission_prompt_tool_name : string -> t -> t 164 + (** [with_permission_prompt_tool_name tool t] sets the permission prompt tool name. *) 165 + 166 + val with_settings : string -> t -> t 167 + (** [with_settings path t] sets the path to settings file. *) 168 + 169 + val with_add_dirs : string list -> t -> t 170 + (** [with_add_dirs dirs t] sets the additional allowed directories. *) 171 + 172 + val with_extra_args : (string * string option) list -> t -> t 173 + (** [with_extra_args args t] sets the additional CLI flags. *) 174 + 175 + val with_debug_stderr : Eio.Flow.sink_ty Eio.Flow.sink -> t -> t 176 + (** [with_debug_stderr sink t] sets the debug output sink. *) 111 177 112 178 (** {1 Serialization} *) 113 179
+363
claudeio/lib/sdk_control.ml
··· 1 + open Ezjsonm 2 + 3 + let src = Logs.Src.create "claude.sdk_control" ~doc:"Claude SDK control protocol" 4 + module Log = (val Logs.src_log src : Logs.LOG) 5 + 6 + module JU = Json_utils 7 + 8 + module Request = struct 9 + type interrupt = { 10 + subtype : [`Interrupt]; 11 + } 12 + 13 + type permission = { 14 + subtype : [`Can_use_tool]; 15 + tool_name : string; 16 + input : value; 17 + permission_suggestions : Permissions.Update.t list option; 18 + blocked_path : string option; 19 + } 20 + 21 + type initialize = { 22 + subtype : [`Initialize]; 23 + hooks : (string * value) list option; 24 + } 25 + 26 + type set_permission_mode = { 27 + subtype : [`Set_permission_mode]; 28 + mode : Permissions.Mode.t; 29 + } 30 + 31 + type hook_callback = { 32 + subtype : [`Hook_callback]; 33 + callback_id : string; 34 + input : value; 35 + tool_use_id : string option; 36 + } 37 + 38 + type mcp_message = { 39 + subtype : [`Mcp_message]; 40 + server_name : string; 41 + message : value; 42 + } 43 + 44 + type t = 45 + | Interrupt of interrupt 46 + | Permission of permission 47 + | Initialize of initialize 48 + | Set_permission_mode of set_permission_mode 49 + | Hook_callback of hook_callback 50 + | Mcp_message of mcp_message 51 + 52 + let interrupt () = Interrupt { subtype = `Interrupt } 53 + 54 + let permission ~tool_name ~input ?permission_suggestions ?blocked_path () = 55 + Permission { 56 + subtype = `Can_use_tool; 57 + tool_name; 58 + input; 59 + permission_suggestions; 60 + blocked_path; 61 + } 62 + 63 + let initialize ?hooks () = 64 + Initialize { subtype = `Initialize; hooks } 65 + 66 + let set_permission_mode ~mode = 67 + Set_permission_mode { subtype = `Set_permission_mode; mode } 68 + 69 + let hook_callback ~callback_id ~input ?tool_use_id () = 70 + Hook_callback { 71 + subtype = `Hook_callback; 72 + callback_id; 73 + input; 74 + tool_use_id; 75 + } 76 + 77 + let mcp_message ~server_name ~message = 78 + Mcp_message { 79 + subtype = `Mcp_message; 80 + server_name; 81 + message; 82 + } 83 + 84 + let to_json = function 85 + | Interrupt _ -> 86 + `O [("subtype", `String "interrupt")] 87 + | Permission p -> 88 + let fields = [ 89 + ("subtype", `String "can_use_tool"); 90 + ("tool_name", `String p.tool_name); 91 + ("input", p.input); 92 + ] in 93 + let fields = match p.permission_suggestions with 94 + | Some suggestions -> 95 + ("permission_suggestions", 96 + `A (List.map Permissions.Update.to_json suggestions)) :: fields 97 + | None -> fields 98 + in 99 + let fields = match p.blocked_path with 100 + | Some path -> ("blocked_path", `String path) :: fields 101 + | None -> fields 102 + in 103 + `O fields 104 + | Initialize i -> 105 + let fields = [("subtype", `String "initialize")] in 106 + let fields = match i.hooks with 107 + | Some hooks -> 108 + ("hooks", `O hooks) :: fields 109 + | None -> fields 110 + in 111 + `O fields 112 + | Set_permission_mode s -> 113 + `O [ 114 + ("subtype", `String "set_permission_mode"); 115 + ("mode", Permissions.Mode.to_json s.mode); 116 + ] 117 + | Hook_callback h -> 118 + let fields = [ 119 + ("subtype", `String "hook_callback"); 120 + ("callback_id", `String h.callback_id); 121 + ("input", h.input); 122 + ] in 123 + let fields = match h.tool_use_id with 124 + | Some id -> ("tool_use_id", `String id) :: fields 125 + | None -> fields 126 + in 127 + `O fields 128 + | Mcp_message m -> 129 + `O [ 130 + ("subtype", `String "mcp_message"); 131 + ("server_name", `String m.server_name); 132 + ("message", m.message); 133 + ] 134 + 135 + let of_json = function 136 + | `O fields -> 137 + let subtype = JU.assoc_string "subtype" fields in 138 + (match subtype with 139 + | "interrupt" -> 140 + Interrupt { subtype = `Interrupt } 141 + | "can_use_tool" -> 142 + let tool_name = JU.assoc_string "tool_name" fields in 143 + let input = List.assoc "input" fields in 144 + let permission_suggestions = 145 + match List.assoc_opt "permission_suggestions" fields with 146 + | Some (`A lst) -> 147 + Some (List.map Permissions.Update.of_json lst) 148 + | _ -> None 149 + in 150 + let blocked_path = JU.assoc_string_opt "blocked_path" fields in 151 + Permission { 152 + subtype = `Can_use_tool; 153 + tool_name; 154 + input; 155 + permission_suggestions; 156 + blocked_path; 157 + } 158 + | "initialize" -> 159 + let hooks = 160 + match List.assoc_opt "hooks" fields with 161 + | Some (`O hooks) -> Some hooks 162 + | _ -> None 163 + in 164 + Initialize { subtype = `Initialize; hooks } 165 + | "set_permission_mode" -> 166 + let mode = List.assoc "mode" fields |> Permissions.Mode.of_json in 167 + Set_permission_mode { subtype = `Set_permission_mode; mode } 168 + | "hook_callback" -> 169 + let callback_id = JU.assoc_string "callback_id" fields in 170 + let input = List.assoc "input" fields in 171 + let tool_use_id = JU.assoc_string_opt "tool_use_id" fields in 172 + Hook_callback { 173 + subtype = `Hook_callback; 174 + callback_id; 175 + input; 176 + tool_use_id; 177 + } 178 + | "mcp_message" -> 179 + let server_name = JU.assoc_string "server_name" fields in 180 + let message = List.assoc "message" fields in 181 + Mcp_message { 182 + subtype = `Mcp_message; 183 + server_name; 184 + message; 185 + } 186 + | _ -> raise (Invalid_argument ("Unknown request subtype: " ^ subtype))) 187 + | _ -> raise (Invalid_argument "Request.of_json: expected object") 188 + 189 + let pp fmt = function 190 + | Interrupt _ -> 191 + Fmt.pf fmt "@[<2>Interrupt@]" 192 + | Permission p -> 193 + Fmt.pf fmt "@[<2>Permission@ { tool = %S;@ blocked_path = %a }@]" 194 + p.tool_name Fmt.(option string) p.blocked_path 195 + | Initialize i -> 196 + Fmt.pf fmt "@[<2>Initialize@ { hooks = %s }@]" 197 + (if Option.is_some i.hooks then "present" else "none") 198 + | Set_permission_mode s -> 199 + Fmt.pf fmt "@[<2>SetPermissionMode@ { mode = %a }@]" 200 + Permissions.Mode.pp s.mode 201 + | Hook_callback h -> 202 + Fmt.pf fmt "@[<2>HookCallback@ { id = %S;@ tool_use_id = %a }@]" 203 + h.callback_id Fmt.(option string) h.tool_use_id 204 + | Mcp_message m -> 205 + Fmt.pf fmt "@[<2>McpMessage@ { server = %S }@]" 206 + m.server_name 207 + end 208 + 209 + module Response = struct 210 + type success = { 211 + subtype : [`Success]; 212 + request_id : string; 213 + response : value option; 214 + } 215 + 216 + type error = { 217 + subtype : [`Error]; 218 + request_id : string; 219 + error : string; 220 + } 221 + 222 + type t = 223 + | Success of success 224 + | Error of error 225 + 226 + let success ~request_id ?response () = 227 + Success { 228 + subtype = `Success; 229 + request_id; 230 + response; 231 + } 232 + 233 + let error ~request_id ~error = 234 + Error { 235 + subtype = `Error; 236 + request_id; 237 + error; 238 + } 239 + 240 + let to_json = function 241 + | Success s -> 242 + let fields = [ 243 + ("subtype", `String "success"); 244 + ("request_id", `String s.request_id); 245 + ] in 246 + let fields = match s.response with 247 + | Some resp -> ("response", resp) :: fields 248 + | None -> fields 249 + in 250 + `O fields 251 + | Error e -> 252 + `O [ 253 + ("subtype", `String "error"); 254 + ("request_id", `String e.request_id); 255 + ("error", `String e.error); 256 + ] 257 + 258 + let of_json = function 259 + | `O fields -> 260 + let subtype = JU.assoc_string "subtype" fields in 261 + let request_id = JU.assoc_string "request_id" fields in 262 + (match subtype with 263 + | "success" -> 264 + let response = List.assoc_opt "response" fields in 265 + Success { 266 + subtype = `Success; 267 + request_id; 268 + response; 269 + } 270 + | "error" -> 271 + let error = JU.assoc_string "error" fields in 272 + Error { 273 + subtype = `Error; 274 + request_id; 275 + error; 276 + } 277 + | _ -> raise (Invalid_argument ("Unknown response subtype: " ^ subtype))) 278 + | _ -> raise (Invalid_argument "Response.of_json: expected object") 279 + 280 + let pp fmt = function 281 + | Success s -> 282 + Fmt.pf fmt "@[<2>Success@ { request_id = %S;@ response = %s }@]" 283 + s.request_id (if Option.is_some s.response then "present" else "none") 284 + | Error e -> 285 + Fmt.pf fmt "@[<2>Error@ { request_id = %S;@ error = %S }@]" 286 + e.request_id e.error 287 + end 288 + 289 + type control_request = { 290 + type_ : [`Control_request]; 291 + request_id : string; 292 + request : Request.t; 293 + } 294 + 295 + type control_response = { 296 + type_ : [`Control_response]; 297 + response : Response.t; 298 + } 299 + 300 + type t = 301 + | Request of control_request 302 + | Response of control_response 303 + 304 + let create_request ~request_id ~request = 305 + Request { 306 + type_ = `Control_request; 307 + request_id; 308 + request; 309 + } 310 + 311 + let create_response ~response = 312 + Response { 313 + type_ = `Control_response; 314 + response; 315 + } 316 + 317 + let to_json = function 318 + | Request r -> 319 + `O [ 320 + ("type", `String "control_request"); 321 + ("request_id", `String r.request_id); 322 + ("request", Request.to_json r.request); 323 + ] 324 + | Response r -> 325 + `O [ 326 + ("type", `String "control_response"); 327 + ("response", Response.to_json r.response); 328 + ] 329 + 330 + let of_json = function 331 + | `O fields -> 332 + let type_ = JU.assoc_string "type" fields in 333 + (match type_ with 334 + | "control_request" -> 335 + let request_id = JU.assoc_string "request_id" fields in 336 + let request = List.assoc "request" fields |> Request.of_json in 337 + Request { 338 + type_ = `Control_request; 339 + request_id; 340 + request; 341 + } 342 + | "control_response" -> 343 + let response = List.assoc "response" fields |> Response.of_json in 344 + Response { 345 + type_ = `Control_response; 346 + response; 347 + } 348 + | _ -> raise (Invalid_argument ("Unknown control type: " ^ type_))) 349 + | _ -> raise (Invalid_argument "of_json: expected object") 350 + 351 + let pp fmt = function 352 + | Request r -> 353 + Fmt.pf fmt "@[<2>ControlRequest@ { id = %S;@ request = %a }@]" 354 + r.request_id Request.pp r.request 355 + | Response r -> 356 + Fmt.pf fmt "@[<2>ControlResponse@ { %a }@]" 357 + Response.pp r.response 358 + 359 + let log_request req = 360 + Log.debug (fun m -> m "SDK control request: %a" Request.pp req) 361 + 362 + let log_response resp = 363 + Log.debug (fun m -> m "SDK control response: %a" Response.pp resp)
+188
claudeio/lib/sdk_control.mli
··· 1 + (** SDK Control Protocol for Claude. 2 + 3 + This module defines the typed SDK control protocol for communication 4 + between the SDK and Claude, including request and response types. *) 5 + 6 + open Ezjsonm 7 + 8 + (** The log source for SDK control operations *) 9 + val src : Logs.Src.t 10 + 11 + (** {1 Request Types} *) 12 + 13 + module Request : sig 14 + (** SDK control request types. *) 15 + 16 + type interrupt = { 17 + subtype : [`Interrupt]; 18 + } 19 + (** Interrupt request to stop execution. *) 20 + 21 + type permission = { 22 + subtype : [`Can_use_tool]; 23 + tool_name : string; 24 + input : value; 25 + permission_suggestions : Permissions.Update.t list option; 26 + blocked_path : string option; 27 + } 28 + (** Permission request for tool usage. *) 29 + 30 + type initialize = { 31 + subtype : [`Initialize]; 32 + hooks : (string * value) list option; (* Hook event to configuration *) 33 + } 34 + (** Initialize request with optional hook configuration. *) 35 + 36 + type set_permission_mode = { 37 + subtype : [`Set_permission_mode]; 38 + mode : Permissions.Mode.t; 39 + } 40 + (** Request to change permission mode. *) 41 + 42 + type hook_callback = { 43 + subtype : [`Hook_callback]; 44 + callback_id : string; 45 + input : value; 46 + tool_use_id : string option; 47 + } 48 + (** Hook callback request. *) 49 + 50 + type mcp_message = { 51 + subtype : [`Mcp_message]; 52 + server_name : string; 53 + message : value; 54 + } 55 + (** MCP server message request. *) 56 + 57 + type t = 58 + | Interrupt of interrupt 59 + | Permission of permission 60 + | Initialize of initialize 61 + | Set_permission_mode of set_permission_mode 62 + | Hook_callback of hook_callback 63 + | Mcp_message of mcp_message 64 + (** The type of SDK control requests. *) 65 + 66 + val interrupt : unit -> t 67 + (** [interrupt ()] creates an interrupt request. *) 68 + 69 + val permission : 70 + tool_name:string -> 71 + input:value -> 72 + ?permission_suggestions:Permissions.Update.t list -> 73 + ?blocked_path:string -> 74 + unit -> t 75 + (** [permission ~tool_name ~input ?permission_suggestions ?blocked_path ()] 76 + creates a permission request. *) 77 + 78 + val initialize : ?hooks:(string * value) list -> unit -> t 79 + (** [initialize ?hooks ()] creates an initialize request. *) 80 + 81 + val set_permission_mode : mode:Permissions.Mode.t -> t 82 + (** [set_permission_mode ~mode] creates a permission mode change request. *) 83 + 84 + val hook_callback : 85 + callback_id:string -> 86 + input:value -> 87 + ?tool_use_id:string -> 88 + unit -> t 89 + (** [hook_callback ~callback_id ~input ?tool_use_id ()] creates a hook callback request. *) 90 + 91 + val mcp_message : server_name:string -> message:value -> t 92 + (** [mcp_message ~server_name ~message] creates an MCP message request. *) 93 + 94 + val to_json : t -> value 95 + (** [to_json t] converts a request to JSON. *) 96 + 97 + val of_json : value -> t 98 + (** [of_json json] parses a request from JSON. 99 + @raise Invalid_argument if the JSON is not a valid request. *) 100 + 101 + val pp : Format.formatter -> t -> unit 102 + (** [pp fmt t] pretty-prints the request. *) 103 + end 104 + 105 + (** {1 Response Types} *) 106 + 107 + module Response : sig 108 + (** SDK control response types. *) 109 + 110 + type success = { 111 + subtype : [`Success]; 112 + request_id : string; 113 + response : value option; 114 + } 115 + (** Successful response. *) 116 + 117 + type error = { 118 + subtype : [`Error]; 119 + request_id : string; 120 + error : string; 121 + } 122 + (** Error response. *) 123 + 124 + type t = 125 + | Success of success 126 + | Error of error 127 + (** The type of SDK control responses. *) 128 + 129 + val success : request_id:string -> ?response:value -> unit -> t 130 + (** [success ~request_id ?response ()] creates a success response. *) 131 + 132 + val error : request_id:string -> error:string -> t 133 + (** [error ~request_id ~error] creates an error response. *) 134 + 135 + val to_json : t -> value 136 + (** [to_json t] converts a response to JSON. *) 137 + 138 + val of_json : value -> t 139 + (** [of_json json] parses a response from JSON. 140 + @raise Invalid_argument if the JSON is not a valid response. *) 141 + 142 + val pp : Format.formatter -> t -> unit 143 + (** [pp fmt t] pretty-prints the response. *) 144 + end 145 + 146 + (** {1 Control Messages} *) 147 + 148 + type control_request = { 149 + type_ : [`Control_request]; 150 + request_id : string; 151 + request : Request.t; 152 + } 153 + (** Control request message. *) 154 + 155 + type control_response = { 156 + type_ : [`Control_response]; 157 + response : Response.t; 158 + } 159 + (** Control response message. *) 160 + 161 + type t = 162 + | Request of control_request 163 + | Response of control_response 164 + (** The type of SDK control messages. *) 165 + 166 + val create_request : request_id:string -> request:Request.t -> t 167 + (** [create_request ~request_id ~request] creates a control request message. *) 168 + 169 + val create_response : response:Response.t -> t 170 + (** [create_response ~response] creates a control response message. *) 171 + 172 + val to_json : t -> value 173 + (** [to_json t] converts a control message to JSON. *) 174 + 175 + val of_json : value -> t 176 + (** [of_json json] parses a control message from JSON. 177 + @raise Invalid_argument if the JSON is not a valid control message. *) 178 + 179 + val pp : Format.formatter -> t -> unit 180 + (** [pp fmt t] pretty-prints the control message. *) 181 + 182 + (** {1 Logging} *) 183 + 184 + val log_request : Request.t -> unit 185 + (** [log_request req] logs an SDK control request. *) 186 + 187 + val log_response : Response.t -> unit 188 + (** [log_response resp] logs an SDK control response. *)