remove more bugs
This commit is contained in:
19
codex.el
19
codex.el
@@ -171,21 +171,24 @@
|
||||
(defun codex--parse-msg-from-response (response-string)
|
||||
(let* ((output (string-trim response-string))
|
||||
(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))
|
||||
(item (gethash "item" hm)))
|
||||
(and type
|
||||
item
|
||||
(string-equal type "item.completed")
|
||||
(string-equal (gethash "type" item) "agent_message"))))
|
||||
jsons)))
|
||||
(unless msg
|
||||
(error "No proper agent_message" received))
|
||||
(let* ((item (gethash "item" msg))
|
||||
(text (gethash "text" item)))
|
||||
jsons))
|
||||
(item (and msg (gethash "item" msg)))
|
||||
(text (and item (gethash "text" item))))
|
||||
;; We should make sure we get one and only one message here, otherwise bail out
|
||||
(setf codex--session-id (codex--parse-session-id jsons))
|
||||
text)))
|
||||
(setf codex--session-id (codex--parse-session-id jsons))
|
||||
(or text output)))
|
||||
|
||||
(defun codex--ensure-session-in-sessions-file (prompt)
|
||||
(let ((sessions (codex--read-sessions-file)))
|
||||
|
||||
Reference in New Issue
Block a user