Skip to content

Commit 965a7f8

Browse files
committed
fix (chat): resolving buffering issues (WIP)
1 parent 95fca0c commit 965a7f8

1 file changed

Lines changed: 27 additions & 13 deletions

File tree

src/client/components/ChatOverlay.js

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,33 @@ const ChatOverlay = ({ onClose }) => {
9999
}))
100100

101101
try {
102-
const response = await fetch("/api/chat/message", {
103-
method: "POST",
104-
headers: { "Content-Type": "application/json" },
105-
body: JSON.stringify({
106-
messages: apiMessages,
107-
enable_internet: isInternetEnabled,
108-
enable_weather: isWeatherEnabled,
109-
enable_news: isNewsEnabled,
110-
enable_maps: isMapsEnabled,
111-
enable_shopping: isShoppingEnabled
112-
}),
113-
signal: abortControllerRef.current.signal
114-
})
102+
// 1. Fetch the access token from our own API to authenticate the direct call
103+
const tokenResponse = await fetch("/api/auth/token")
104+
if (!tokenResponse.ok) {
105+
throw new Error("Could not fetch authentication token.")
106+
}
107+
const { accessToken } = await tokenResponse.json()
108+
109+
// 2. Make the streaming call directly to the backend, bypassing the Netlify function proxy
110+
const response = await fetch(
111+
`${process.env.NEXT_PUBLIC_APP_SERVER_URL}/chat/message`,
112+
{
113+
method: "POST",
114+
headers: {
115+
"Content-Type": "application/json",
116+
Authorization: `Bearer ${accessToken}` // Add the auth header
117+
},
118+
body: JSON.stringify({
119+
messages: apiMessages,
120+
enable_internet: isInternetEnabled,
121+
enable_weather: isWeatherEnabled,
122+
enable_news: isNewsEnabled,
123+
enable_maps: isMapsEnabled,
124+
enable_shopping: isShoppingEnabled
125+
}),
126+
signal: abortControllerRef.current.signal
127+
}
128+
)
115129
if (!response.ok || !response.body) {
116130
const errorData = await response
117131
.json()

0 commit comments

Comments
 (0)