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

more

Changed files
+28 -9
stack
zulip
lib
zulip
lib
zulip_bot
+8 -1
stack/zulip/lib/zulip/lib/client.ml
···
(* Prepare request body if provided *)
let body_opt = match body with
-
| Some json_str -> Some (Requests.Body.of_string Requests.Mime.json json_str)
| None -> None
in
···
(* Prepare request body if provided *)
let body_opt = match body with
+
| Some body_str ->
+
(* Check if this looks like form data (key=value) or JSON *)
+
if String.contains body_str '=' && not (String.contains body_str '{') then
+
(* Form-encoded data *)
+
Some (Requests.Body.of_string Requests.Mime.form body_str)
+
else
+
(* JSON data *)
+
Some (Requests.Body.of_string Requests.Mime.json body_str)
| None -> None
in
+20 -8
stack/zulip/lib/zulip_bot/lib/bot_storage.ml
···
dirty_keys = [];
}
-
(* Helper to encode storage data as JSON *)
let encode_storage_update keys_values =
let storage_obj =
List.map (fun (k, v) -> (k, `String v)) keys_values
in
-
let json_obj = `O [("storage", `O storage_obj)] in
-
(* Convert to JSON string *)
let encoder = Jsonm.encoder (`Buffer (Buffer.create 256)) in
let rec encode_json encoder json =
match json with
···
in
encode_json encoder json_obj;
ignore (Jsonm.encode encoder `End);
-
match Jsonm.encoder_dst encoder with
-
| `Buffer buf -> Buffer.contents buf
-
| _ -> ""
let get t ~key =
Log.debug (fun m -> m "Getting value for key: %s" key);
···
None
let put t ~key ~value =
-
Log.debug (fun m -> m "Storing key: %s" key);
(* Update cache *)
Hashtbl.replace t.cache key value;
···
if not (List.mem key t.dirty_keys) then
t.dirty_keys <- key :: t.dirty_keys;
-
(* Send update to Zulip API *)
let body = encode_storage_update [(key, value)] in
match Zulip.Client.request t.client
~method_:`PUT
~path:"/api/v1/bot_storage"
···
if updates = [] then
Ok ()
else
let body = encode_storage_update updates in
match Zulip.Client.request t.client
~method_:`PUT
~path:"/api/v1/bot_storage"
···
dirty_keys = [];
}
+
(* Helper to encode storage data as form-encoded body for the API *)
let encode_storage_update keys_values =
+
(* Build the storage object - just the key-value pairs, not wrapped in "storage" *)
let storage_obj =
List.map (fun (k, v) -> (k, `String v)) keys_values
in
+
let json_obj = `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
···
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
let get t ~key =
Log.debug (fun m -> m "Getting value for key: %s" key);
···
None
let put t ~key ~value =
+
Log.debug (fun m -> m "Storing key: %s with value: %s" key value);
(* Update cache *)
Hashtbl.replace t.cache key value;
···
if not (List.mem key t.dirty_keys) then
t.dirty_keys <- key :: t.dirty_keys;
+
(* Use the helper to properly encode as form data *)
let body = encode_storage_update [(key, value)] in
+
+
Log.debug (fun m -> m "Sending storage update with body: %s" body);
+
match Zulip.Client.request t.client
~method_:`PUT
~path:"/api/v1/bot_storage"
···
if updates = [] then
Ok ()
else
+
(* Use the helper to properly encode all updates as form data *)
let body = encode_storage_update updates in
+
match Zulip.Client.request t.client
~method_:`PUT
~path:"/api/v1/bot_storage"