Guard SSE JSON parsing against non-object values
ober
6ff536c0dae63ae63a5dd8503653ae92d0d97ba8
--- a/lib/jcode/provider/provider.sls +++ b/lib/jcode/provider/provider.sls @@ -411,7 +411,8 @@ (let ([json (guard (e [list #t #f]) (string->json-object data))]) - (when json + (when (and json + (hash-table? json)) (let ([usage (hash-get json "usage")]) @@ -589,7 +590,7 @@ (let ([json (guard (e [list #t #f]) (string->json-object data-str))]) - (when json + (when (and json (hash-table? json)) (cond [(equal? event-type --- a/src/jcode/provider/provider.ss +++ b/src/jcode/provider/provider.ss @@ -367,7 +367,7 @@ (else (let ((json (guard (e [#t #f]) (string->json-object data)))) - (when json + (when (and json (hash-table? json)) ;; Capture usage from final chunk (let ((usage (hash-get json "usage"))) (when (and usage (hash-table? usage)) @@ -469,7 +469,7 @@ lines) (when (and event-type data-str) (let ((json (guard (e [#t #f]) (string->json-object data-str)))) - (when json + (when (and json (hash-table? json)) (cond ;; Text delta ((equal? event-type "content_block_delta")