11import { Model } from "./stores/chat" ;
2- import { getExecutionType } from "sql-query-identifier" ;
2+ import { identify } from "sql-query-identifier" ;
33
44export function safeJSONStringify ( value : any , ...args : any ) : string {
55 return JSON . stringify (
@@ -51,15 +51,15 @@ export function isAbortError(error: unknown) {
5151
5252export function parseHeaders ( text : string ) : Record < string , string > {
5353 const headers = { } ;
54- const lines = text . split ( '\n' ) ;
54+ const lines = text . split ( "\n" ) ;
5555
5656 for ( let line of lines ) {
5757 line = line . trim ( ) ;
58- if ( ! line || ! line . includes ( ':' ) ) continue ;
58+ if ( ! line || ! line . includes ( ":" ) ) continue ;
5959
60- const [ key , ...rest ] = line . split ( ':' ) ;
60+ const [ key , ...rest ] = line . split ( ":" ) ;
6161 const trimmedKey = key . trim ( ) ;
62- const value = rest . join ( ':' ) . trim ( ) ;
62+ const value = rest . join ( ":" ) . trim ( ) ;
6363
6464 if ( trimmedKey ) {
6565 headers [ trimmedKey ] = value ;
@@ -75,6 +75,13 @@ export function matchModel(a: Model, b?: Model) {
7575}
7676
7777export function isReadQuery ( query : string ) {
78- const type = getExecutionType ( query ) ;
79- return type === "LISTING" || type === "INFORMATION" ;
78+ try {
79+ // Not sure, but assume that identify() can throw an error
80+ return identify ( query ) . every (
81+ ( { executionType } ) =>
82+ executionType === "LISTING" || executionType === "INFORMATION" ,
83+ ) ;
84+ } catch ( e ) {
85+ return false ;
86+ }
8087}
0 commit comments