OCaml Claude SDK using Eio and Jsont
1(*---------------------------------------------------------------------------
2 Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved.
3 SPDX-License-Identifier: ISC
4 ---------------------------------------------------------------------------*)
5
6(** Opaque tool input with typed accessors.
7
8 Tool inputs are JSON objects representing parameters passed to tools. This
9 module provides type-safe accessors while hiding the JSON structure from
10 most client code. *)
11
12type t
13(** Abstract type for tool inputs. *)
14
15(** {1 Typed Accessors} *)
16
17val get_string : t -> string -> string option
18(** [get_string t key] returns the string value for [key], if present and a
19 string. *)
20
21val get_int : t -> string -> int option
22(** [get_int t key] returns the integer value for [key], if present and an int.
23*)
24
25val get_bool : t -> string -> bool option
26(** [get_bool t key] returns the boolean value for [key], if present and a bool.
27*)
28
29val get_float : t -> string -> float option
30(** [get_float t key] returns the float value for [key], if present and a float.
31*)
32
33val get_string_list : t -> string -> string list option
34(** [get_string_list t key] returns the string list for [key], if present and a
35 list of strings. *)
36
37val keys : t -> string list
38(** [keys t] returns all keys in the input. *)
39
40val is_empty : t -> bool
41(** [is_empty t] returns true if the input has no keys. *)
42
43(** {1 Escape Hatch} *)
44
45val to_json : t -> Jsont.json
46(** [to_json t] returns the underlying JSON for advanced use cases. *)
47
48val of_json : Jsont.json -> t
49(** [of_json json] wraps JSON as a tool input. *)
50
51(** {1 Construction} *)
52
53val empty : t
54(** [empty] is an empty tool input. *)
55
56val add_string : string -> string -> t -> t
57(** [add_string key value t] adds a string field. *)
58
59val add_int : string -> int -> t -> t
60(** [add_int key value t] adds an integer field. *)
61
62val add_bool : string -> bool -> t -> t
63(** [add_bool key value t] adds a boolean field. *)
64
65val add_float : string -> float -> t -> t
66(** [add_float key value t] adds a float field. *)
67
68val of_assoc : (string * Jsont.json) list -> t
69(** [of_assoc assoc] creates tool input from an association list. *)
70
71val of_string_pairs : (string * string) list -> t
72(** [of_string_pairs pairs] creates tool input from string key-value pairs. *)