Skip to content

Commit c6ee19a

Browse files
authored
fix: Handle relative URLs for feedback endpoint (#192)
1 parent 540d1af commit c6ee19a

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/components/AiChat/AiChatContext.tsx

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff 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: {

0 commit comments

Comments
 (0)