-
Notifications
You must be signed in to change notification settings - Fork 15
agent: @U0AJM7X8FBR currently, after a couple minutes of the chat app being ope #1579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: test
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,6 +17,7 @@ import { DEFAULT_MODEL } from "@/lib/consts"; | |||||||||||||||||||||||||||||||||||||
| import { usePaymentProvider } from "@/providers/PaymentProvider"; | ||||||||||||||||||||||||||||||||||||||
| import useArtistFilesForMentions from "@/hooks/useArtistFilesForMentions"; | ||||||||||||||||||||||||||||||||||||||
| import type { KnowledgeBaseEntry } from "@/lib/supabase/getArtistKnowledge"; | ||||||||||||||||||||||||||||||||||||||
| import { usePrivy } from "@privy-io/react-auth"; | ||||||||||||||||||||||||||||||||||||||
| import { useChatTransport } from "./useChatTransport"; | ||||||||||||||||||||||||||||||||||||||
| import { useAccessToken } from "./useAccessToken"; | ||||||||||||||||||||||||||||||||||||||
| import { TextAttachment } from "@/types/textAttachment"; | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -60,6 +61,7 @@ export function useVercelChat({ | |||||||||||||||||||||||||||||||||||||
| availableModels[0]?.id ?? "", | ||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||
| const { refetchCredits } = usePaymentProvider(); | ||||||||||||||||||||||||||||||||||||||
| const { getAccessToken } = usePrivy(); | ||||||||||||||||||||||||||||||||||||||
| const { transport, headers } = useChatTransport(); | ||||||||||||||||||||||||||||||||||||||
| const accessToken = useAccessToken(); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
@@ -195,7 +197,7 @@ export function useVercelChat({ | |||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => { | ||||||||||||||||||||||||||||||||||||||
| const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => { | ||||||||||||||||||||||||||||||||||||||
| e.preventDefault(); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // Combine all attachments | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -234,7 +236,16 @@ export function useVercelChat({ | |||||||||||||||||||||||||||||||||||||
| files: nonAudioAttachments.length > 0 ? nonAudioAttachments : undefined, | ||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| sendMessage(payload, chatRequestOptions); | ||||||||||||||||||||||||||||||||||||||
| // Get a fresh token at send time so expired tokens are never used | ||||||||||||||||||||||||||||||||||||||
| const freshToken = await getAccessToken(); | ||||||||||||||||||||||||||||||||||||||
| const requestOptions = freshToken | ||||||||||||||||||||||||||||||||||||||
| ? { | ||||||||||||||||||||||||||||||||||||||
| ...chatRequestOptions, | ||||||||||||||||||||||||||||||||||||||
| headers: { Authorization: `Bearer ${freshToken}` }, | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| : chatRequestOptions; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| sendMessage(payload, requestOptions); | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+239
to
+248
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Headers are replaced instead of merged, potentially losing other headers. When 🔧 Proposed fix to merge headers // Get a fresh token at send time so expired tokens are never used
const freshToken = await getAccessToken();
const requestOptions = freshToken
? {
...chatRequestOptions,
- headers: { Authorization: `Bearer ${freshToken}` },
+ headers: { ...chatRequestOptions.headers, Authorization: `Bearer ${freshToken}` },
}
: chatRequestOptions;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
| setInput(""); | ||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
@@ -298,7 +309,7 @@ export function useVercelChat({ | |||||||||||||||||||||||||||||||||||||
| const messageContent = input; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // Submit the message | ||||||||||||||||||||||||||||||||||||||
| handleSubmit(event); | ||||||||||||||||||||||||||||||||||||||
| await handleSubmit(event); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if (!roomId) { | ||||||||||||||||||||||||||||||||||||||
| // Optimistically append a temporary conversation so it appears in Recent Chats | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -311,9 +322,16 @@ export function useVercelChat({ | |||||||||||||||||||||||||||||||||||||
| const handleSendQueryMessages = useCallback( | ||||||||||||||||||||||||||||||||||||||
| async (initialMessage: UIMessage) => { | ||||||||||||||||||||||||||||||||||||||
| silentlyUpdateUrl(); | ||||||||||||||||||||||||||||||||||||||
| sendMessage(initialMessage, chatRequestOptions); | ||||||||||||||||||||||||||||||||||||||
| const freshToken = await getAccessToken(); | ||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The initial-message path now waits for Useful? React with 👍 / 👎. |
||||||||||||||||||||||||||||||||||||||
| const requestOptions = freshToken | ||||||||||||||||||||||||||||||||||||||
| ? { | ||||||||||||||||||||||||||||||||||||||
| ...chatRequestOptions, | ||||||||||||||||||||||||||||||||||||||
| headers: { Authorization: `Bearer ${freshToken}` }, | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| : chatRequestOptions; | ||||||||||||||||||||||||||||||||||||||
| sendMessage(initialMessage, requestOptions); | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+325
to
+332
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same headers merge issue applies here. Consistent with the earlier comment on 🔧 Proposed fix const freshToken = await getAccessToken();
const requestOptions = freshToken
? {
...chatRequestOptions,
- headers: { Authorization: `Bearer ${freshToken}` },
+ headers: { ...chatRequestOptions.headers, Authorization: `Bearer ${freshToken}` },
}
: chatRequestOptions;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
| [silentlyUpdateUrl, sendMessage, chatRequestOptions], | ||||||||||||||||||||||||||||||||||||||
| [silentlyUpdateUrl, sendMessage, chatRequestOptions, getAccessToken], | ||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awaiting
getAccessToken()beforesendMessage()leaves the form in a sendable state while token refresh is in progress; when refresh takes noticeable time (the exact expiry case this patch targets), users can press Enter/click submit again and enqueue duplicate copies of the same prompt, causing duplicate model runs and credit usage. This path previously submitted immediately, so the new await introduces a regression unless resubmission is blocked before the token call.Useful? React with 👍 / 👎.