remove more bugs
This commit is contained in:
17
codex.el
17
codex.el
@@ -171,21 +171,24 @@
|
|||||||
(defun codex--parse-msg-from-response (response-string)
|
(defun codex--parse-msg-from-response (response-string)
|
||||||
(let* ((output (string-trim response-string))
|
(let* ((output (string-trim response-string))
|
||||||
(lines (string-lines output))
|
(lines (string-lines output))
|
||||||
(jsons (mapcar #'json-parse-string lines))
|
(jsons (delq nil
|
||||||
|
(mapcar (lambda (line)
|
||||||
|
(condition-case nil
|
||||||
|
(json-parse-string line)
|
||||||
|
(json-parse-error nil)))
|
||||||
|
lines)))
|
||||||
(msg (cl-find-if (lambda (hm) (let ((type (gethash "type" hm))
|
(msg (cl-find-if (lambda (hm) (let ((type (gethash "type" hm))
|
||||||
(item (gethash "item" hm)))
|
(item (gethash "item" hm)))
|
||||||
(and type
|
(and type
|
||||||
item
|
item
|
||||||
(string-equal type "item.completed")
|
(string-equal type "item.completed")
|
||||||
(string-equal (gethash "type" item) "agent_message"))))
|
(string-equal (gethash "type" item) "agent_message"))))
|
||||||
jsons)))
|
jsons))
|
||||||
(unless msg
|
(item (and msg (gethash "item" msg)))
|
||||||
(error "No proper agent_message" received))
|
(text (and item (gethash "text" item))))
|
||||||
(let* ((item (gethash "item" msg))
|
|
||||||
(text (gethash "text" item)))
|
|
||||||
;; We should make sure we get one and only one message here, otherwise bail out
|
;; We should make sure we get one and only one message here, otherwise bail out
|
||||||
(setf codex--session-id (codex--parse-session-id jsons))
|
(setf codex--session-id (codex--parse-session-id jsons))
|
||||||
text)))
|
(or text output)))
|
||||||
|
|
||||||
(defun codex--ensure-session-in-sessions-file (prompt)
|
(defun codex--ensure-session-in-sessions-file (prompt)
|
||||||
(let ((sessions (codex--read-sessions-file)))
|
(let ((sessions (codex--read-sessions-file)))
|
||||||
|
|||||||
Reference in New Issue
Block a user