@@ -5,31 +5,44 @@ import { initContext } from "@/lib/chatHistory";
55import { LangId , PageSlug } from "@/lib/docs" ;
66import { chat , section } from "@/schema/chat" ;
77import { and , eq } from "drizzle-orm" ;
8+ import { setExtra , withServerActionInstrumentation } from "@sentry/nextjs" ;
9+ import { headers } from "next/headers" ;
810
911export async function getRedirectFromChat ( chatId : string ) : Promise < string > {
10- chatId = z . uuid ( ) . parse ( chatId ) ;
11-
12- const { drizzle, userId } = await initContext ( ) ;
13- if ( ! userId ) {
14- throw new Error ( "Not authenticated" ) ;
15- }
16-
17- const chatData = ( await drizzle . query . chat . findFirst ( {
18- where : and ( eq ( chat . chatId , chatId ) , eq ( chat . userId , userId ) ) ,
19- with : {
20- section : true ,
12+ return withServerActionInstrumentation (
13+ "getRedirectFromChat" , // Action name for Sentry
14+ {
15+ headers : await headers ( ) , // Connect client and server traces
16+ recordResponse : true , // Include response data
2117 } ,
22- } ) ) as
23- | ( typeof chat . $inferSelect & {
24- section : typeof section . $inferSelect ;
25- } )
26- | undefined ;
27- if ( ! chatData ?. section ) {
28- throw new Error ( "Chat or section not found" ) ;
29- }
30- const [ lang , page ] = ( chatData . section . pagePath . split ( "/" ) ?? [ ] ) as [
31- LangId ,
32- PageSlug ,
33- ] ;
34- return `/${ lang } /${ page } #${ chatData . sectionId } ` ;
18+ async ( ) => {
19+ setExtra ( "args" , { chatId } ) ;
20+
21+ chatId = z . uuid ( ) . parse ( chatId ) ;
22+
23+ const { drizzle, userId } = await initContext ( ) ;
24+ if ( ! userId ) {
25+ throw new Error ( "Not authenticated" ) ;
26+ }
27+
28+ const chatData = ( await drizzle . query . chat . findFirst ( {
29+ where : and ( eq ( chat . chatId , chatId ) , eq ( chat . userId , userId ) ) ,
30+ with : {
31+ section : true ,
32+ } ,
33+ } ) ) as
34+ | ( typeof chat . $inferSelect & {
35+ section : typeof section . $inferSelect ;
36+ } )
37+ | undefined ;
38+ if ( ! chatData ?. section ) {
39+ throw new Error ( "Chat or section not found" ) ;
40+ }
41+ const [ lang , page ] = ( chatData . section . pagePath . split ( "/" ) ?? [ ] ) as [
42+ LangId ,
43+ PageSlug ,
44+ ] ;
45+ return `/${ lang } /${ page } #${ chatData . sectionId } ` ;
46+ }
47+ ) ;
3548}
0 commit comments