File tree Expand file tree Collapse file tree 1 file changed +21
-6
lines changed Expand file tree Collapse file tree 1 file changed +21
-6
lines changed Original file line number Diff line number Diff line change @@ -130,12 +130,27 @@ const AiChatProvider: React.FC<AiChatContextProps> = ({
130130 if ( ! data ?. thread_id || ! data ?. checkpoint_pk ) {
131131 return
132132 }
133- const { origin } = new URL ( requestOpts . apiUrl )
134- const url =
135- requestOpts . feedbackApiUrl
136- ?. replace ( ":threadId" , data . thread_id )
137- . replace ( ":checkpointPk" , data . checkpoint_pk ) ||
138- `${ origin } /ai/api/v0/chat_sessions/${ data . thread_id } /messages/${ data . checkpoint_pk } /rate/`
133+
134+ let url
135+ if ( requestOpts . feedbackApiUrl ) {
136+ url = requestOpts . feedbackApiUrl
137+ . replace ( ":threadId" , data . thread_id )
138+ . replace ( ":checkpointPk" , data . checkpoint_pk )
139+ } else {
140+ const path = `/ai/api/v0/chat_sessions/${ data . thread_id } /messages/${ data . checkpoint_pk } /rate/`
141+ try {
142+ const { origin } = new URL ( requestOpts . apiUrl )
143+ url = `${ origin } ${ path } `
144+ } catch ( error ) {
145+ console . warn (
146+ "Expected an absolute apiUrl to construct the feedbackApiUrl where not provided" ,
147+ requestOpts . apiUrl ,
148+ error ,
149+ )
150+ url = path
151+ }
152+ }
153+
139154 fetch ( url , {
140155 method : "POST" ,
141156 headers : {
You can’t perform that action at this time.
0 commit comments