Skip to content

Commit 7602294

Browse files
fix: redirect artist handoff from live completion event
1 parent 4c5c3fe commit 7602294

5 files changed

Lines changed: 18 additions & 159 deletions

File tree

components/VercelChat/tools/CreateArtistToolResult.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { useEffect } from "react";
22
import { CreateArtistResult } from "@/types/createArtistResult";
3-
import useCreateArtistTool from "@/hooks/useCreateArtistTool";
43
import GenericSuccess from "./GenericSuccess";
54
import { useArtistProvider } from "@/providers/ArtistProvider";
65

@@ -19,7 +18,6 @@ export function CreateArtistToolResult({
1918
result,
2019
}: CreateArtistToolResultProps) {
2120
const { getArtists } = useArtistProvider();
22-
const { isProcessing, error: processingError } = useCreateArtistTool(result);
2321

2422
useEffect(() => {
2523
getArtists(result.artistAccountId);
@@ -46,13 +44,7 @@ export function CreateArtistToolResult({
4644
<GenericSuccess
4745
image={result.artist.image}
4846
name={result.artist.name}
49-
message={
50-
isProcessing
51-
? "Setting up artist conversation..."
52-
: processingError
53-
? `Created successfully but: ${processingError}`
54-
: "Artist created successfully"
55-
}
47+
message="Artist created successfully"
5648
/>
5749
);
5850
}

hooks/useCreateArtistTool.ts

Lines changed: 0 additions & 91 deletions
This file was deleted.

hooks/useVercelChat.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { usePrivy } from "@privy-io/react-auth";
2121
import { TextAttachment } from "@/types/textAttachment";
2222
import { formatTextAttachments } from "@/lib/chat/formatTextAttachments";
2323
import { useDeleteTrailingMessages } from "./useDeleteTrailingMessages";
24+
import { z } from "zod";
2425

2526
// 30 days in seconds for Supabase signed URL expiry
2627
const SIGNED_URL_EXPIRES_SECONDS = 60 * 60 * 24 * 30;
@@ -61,6 +62,7 @@ export function useVercelChat({
6162
const { refetchCredits } = usePaymentProvider();
6263
const { transport, getHeaders } = useChatTransport();
6364
const { authenticated } = usePrivy();
65+
const redirectPathRef = useRef<string | null>(null);
6466

6567
// Load artist files for mentions (from Supabase)
6668
const { files: allArtistFiles = [] } = useArtistFilesForMentions();
@@ -180,13 +182,28 @@ export function useVercelChat({
180182
transport,
181183
experimental_throttle: 100,
182184
generateId: generateUUID,
185+
dataPartSchemas: {
186+
redirect: z.object({ path: z.string() }),
187+
},
183188
onError: (e) => {
189+
redirectPathRef.current = null;
184190
console.error("An error occurred, please try again!", e);
185191
toast.error("An error occurred, please try again!");
186192
},
193+
onData: (part) => {
194+
if (part.type === "data-redirect" && part.data.path.startsWith("/")) {
195+
redirectPathRef.current = part.data.path;
196+
}
197+
},
187198
onFinish: async () => {
188199
// Update credits after AI response completes
189200
await refetchCredits();
201+
202+
if (redirectPathRef.current) {
203+
const redirectPath = redirectPathRef.current;
204+
redirectPathRef.current = null;
205+
window.history.replaceState({}, "", redirectPath);
206+
}
190207
},
191208
});
192209

lib/messages/copyMessages.ts

Lines changed: 0 additions & 58 deletions
This file was deleted.

types/createArtistResult.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@ export interface CreateArtistResult {
77
artistAccountId?: string;
88
message: string;
99
error?: string;
10-
newRoomId?: string | null;
1110
}

0 commit comments

Comments
 (0)