My agentic slop goes here. Not intended for anyone else!

more

Changed files
+13 -76
stack
zulip
lib
zulip
zulip_bot
+2 -1
stack/zulip/dune-project
···
dune
eio
requests
-
jsonm
uri
base64
(alcotest :with-test)
···
dune
zulip
eio
(alcotest :with-test)))
(package
···
dune
eio
requests
+
ezjsonm
uri
base64
(alcotest :with-test)
···
dune
zulip
eio
+
ezjsonm
(alcotest :with-test)))
(package
+7 -46
stack/zulip/lib/zulip/lib/client.ml
···
Buffer.contents buf
in
-
(* Parse JSON response *)
-
let decoder = Jsonm.decoder (`String body_str) in
-
let rec parse_json decoder =
-
match Jsonm.decode decoder with
-
| `Lexeme l ->
-
(match l with
-
| `Oe -> `O []
-
| `Os -> parse_object decoder []
-
| `As -> parse_array decoder []
-
| `Ae -> `A []
-
| `Float f -> `Float f
-
| `String s -> `String s
-
| `Bool b -> `Bool b
-
| `Null -> `Null
-
| `Name _ -> parse_json decoder)
-
| `Error e -> failwith ("JSON parse error: " ^ (Format.asprintf "%a" Jsonm.pp_error e))
-
| `Await | `End -> `Null
-
and parse_object decoder acc =
-
match Jsonm.decode decoder with
-
| `Lexeme (`Name key) ->
-
let value = parse_json decoder in
-
parse_object decoder ((key, value) :: acc)
-
| `Lexeme `Oe -> `O (List.rev acc)
-
| _ -> `O (List.rev acc)
-
and parse_array decoder acc =
-
match Jsonm.decode decoder with
-
| `Lexeme `Ae -> `A (List.rev acc)
-
| `Lexeme l ->
-
(match l with
-
| `Name _ -> parse_array decoder acc
-
| _ ->
-
let reparse l =
-
match l with
-
| `Float f -> `Float f
-
| `String s -> `String s
-
| `Bool b -> `Bool b
-
| `Null -> `Null
-
| `Os -> parse_object decoder []
-
| `As -> parse_array decoder []
-
| _ -> `Null
-
in
-
let value = reparse l in
-
parse_array decoder (value :: acc))
-
| _ -> `A (List.rev acc)
in
-
-
let json = parse_json decoder in
(* Check for Zulip error response *)
match json with
···
Buffer.contents buf
in
+
(* Parse JSON response using Ezjsonm *)
+
let json =
+
try
+
Ezjsonm.from_string body_str
+
with Ezjsonm.Parse_error (_, msg) ->
+
Log.err (fun m -> m "JSON parse error: %s" msg);
+
failwith ("JSON parse error: " ^ msg)
in
(* Check for Zulip error response *)
match json with
+1 -1
stack/zulip/lib/zulip/lib/dune
···
(library
(public_name zulip)
(name zulip)
-
(libraries eio requests jsonm uri base64 logs))
···
(library
(public_name zulip)
(name zulip)
+
(libraries eio requests ezjsonm uri base64 logs))
+2 -27
stack/zulip/lib/zulip_bot/lib/bot_storage.ml
···
in
let json_obj = `O [("storage", `O storage_obj)] in
-
(* Convert to JSON string using Jsonm *)
-
let encoder = Jsonm.encoder (`Buffer (Buffer.create 256)) in
-
let rec encode_json encoder json =
-
match json with
-
| `O fields ->
-
ignore (Jsonm.encode encoder (`Lexeme `Os));
-
List.iter (fun (name, value) ->
-
ignore (Jsonm.encode encoder (`Lexeme (`Name name)));
-
encode_json encoder value
-
) fields;
-
ignore (Jsonm.encode encoder (`Lexeme `Oe))
-
| `A items ->
-
ignore (Jsonm.encode encoder (`Lexeme `As));
-
List.iter (encode_json encoder) items;
-
ignore (Jsonm.encode encoder (`Lexeme `Ae))
-
| `String s -> ignore (Jsonm.encode encoder (`Lexeme (`String s)))
-
| `Float f -> ignore (Jsonm.encode encoder (`Lexeme (`Float f)))
-
| `Bool b -> ignore (Jsonm.encode encoder (`Lexeme (`Bool b)))
-
| `Null -> ignore (Jsonm.encode encoder (`Lexeme `Null))
-
in
-
encode_json encoder json_obj;
-
ignore (Jsonm.encode encoder `End);
-
-
let json_str = match Jsonm.encoder_dst encoder with
-
| `Buffer buf -> Buffer.contents buf
-
| _ -> "{}"
-
in
(* Return as form-encoded body: storage=<url-encoded-json> *)
"storage=" ^ Uri.pct_encode json_str
···
in
let json_obj = `O [("storage", `O storage_obj)] in
+
(* Convert to JSON string using Ezjsonm *)
+
let json_str = Ezjsonm.to_string json_obj in
(* Return as form-encoded body: storage=<url-encoded-json> *)
"storage=" ^ Uri.pct_encode json_str
+1 -1
stack/zulip/lib/zulip_bot/lib/dune
···
(public_name zulip_bot)
(name zulip_bot)
(wrapped true)
-
(libraries zulip unix eio logs mirage-crypto-rng fmt)
(flags (:standard -warn-error -3)))
···
(public_name zulip_bot)
(name zulip_bot)
(wrapped true)
+
(libraries zulip unix eio ezjsonm logs mirage-crypto-rng fmt)
(flags (:standard -warn-error -3)))