"use strict";(()=>{var e={};e.id=5971,e.ids=[5971],e.modules={2934:e=>{e.exports=require("next/dist/client/components/action-async-storage.external.js")},4580:e=>{e.exports=require("next/dist/client/components/request-async-storage.external.js")},5869:e=>{e.exports=require("next/dist/client/components/static-generation-async-storage.external.js")},517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},7147:e=>{e.exports=require("fs")},1017:e=>{e.exports=require("path")},4320:(e,t,s)=>{s.r(t),s.d(t,{headerHooks:()=>p,originalPathname:()=>f,patchFetch:()=>g,requestAsyncStorage:()=>l,routeModule:()=>u,serverHooks:()=>v,staticGenerationAsyncStorage:()=>_,staticGenerationBailout:()=>m});var o={};s.r(o),s.d(o,{GET:()=>d});var r=s(5419),n=s(9108),i=s(9678),a=s(8070),c=s(2509);async function d(e,{params:t}){try{let s=await (0,c.e)(),{data:{user:o},error:r}=await s.auth.getUser();if(r||!o)return a.Z.json({error:{code:"UNAUTHORIZED",message:"Authentication required"}},{status:401});let n=new URL(e.url).searchParams.get("site_id"),i=t.conversationId;if(!n)return a.Z.json({error:{code:"MISSING_REQUIRED_FIELD",message:"site_id is required"}},{status:400});let d=(0,c.createAdminClient)(),{data:u,error:l}=await d.from("sites").select("tenant_id").eq("id",n).single();if(l||!u)return a.Z.json({error:{code:"SITE_NOT_FOUND",message:"Site not found"}},{status:404});let _=null,v=null,{data:p,error:m}=await d.from("conversations").select(`
        id,
        conversation_id,
        site_id,
        visitor_id,
        last_message_at,
        message_count,
        created_at,
        visitors!inner (
          visitor_id,
          first_seen_at,
          last_seen_at
        )
      `).eq("site_id",n).eq("id",i).single();if(p&&!m)_=p;else{let{data:e,error:t}=await d.from("conversations").select(`
          id,
          conversation_id,
          site_id,
          visitor_id,
          last_message_at,
          message_count,
          created_at,
          visitors!inner (
            visitor_id,
            first_seen_at,
            last_seen_at
          )
        `).eq("site_id",n).eq("conversation_id",i).single();_=e,v=t}if(v||!_)return a.Z.json({error:{code:"CONVERSATION_NOT_FOUND",message:"Conversation not found"}},{status:404});let{data:f,error:g}=await d.from("messages").select("*").eq("conversation_id",_.id).order("created_at",{ascending:!0});if(g)throw g;let h={id:_.id,conversation_id:_.conversation_id,site_id:_.site_id,visitor_id:_.visitor_id,last_message_at:_.last_message_at,message_count:_.message_count||0,created_at:_.created_at,visitor:_.visitors?{visitor_id:_.visitors.visitor_id,first_seen_at:_.visitors.first_seen_at,last_seen_at:_.visitors.last_seen_at}:null,messages:(f||[]).map(e=>({id:e.id,role:e.role,content_text:e.content_text,content_json:e.content_json,token_usage:e.token_usage,created_at:e.created_at,metadata:e.metadata}))};return a.Z.json(h)}catch(e){return console.error("Conversation GET error:",e),a.Z.json({error:{code:"INTERNAL_ERROR",message:e instanceof Error?e.message:"Failed to fetch conversation"}},{status:500})}}let u=new r.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/conversations/[conversationId]/route",pathname:"/api/conversations/[conversationId]",filename:"route",bundlePath:"app/api/conversations/[conversationId]/route"},resolvedPagePath:"C:\\xampp\\htdocs\\AI Woo Chat\\src\\app\\api\\conversations\\[conversationId]\\route.ts",nextConfigOutput:"standalone",userland:o}),{requestAsyncStorage:l,staticGenerationAsyncStorage:_,serverHooks:v,headerHooks:p,staticGenerationBailout:m}=u,f="/api/conversations/[conversationId]/route";function g(){return(0,i.patchFetch)({serverHooks:v,staticGenerationAsyncStorage:_})}},2509:(e,t,s)=>{s.d(t,{createAdminClient:()=>a,e:()=>i});var o=s(6874),r=s(7439),n=s(3950);async function i(){let e=await (0,r.cookies)();return(0,o.lx)("https://drmuwsxyvvfivdfsyydy.supabase.co","eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImRybXV3c3h5dnZmaXZkZnN5eWR5Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3Njg0NjAwMDgsImV4cCI6MjA4NDAzNjAwOH0.kMsFG-VLNqwzIgl3cFW-owiRCWHcB47M6V6Ti4O4alY",{cookies:{get:t=>e.get(t)?.value,set(t,s,o){try{e.set({name:t,value:s,...o})}catch(e){}},remove(t,s){try{e.set({name:t,value:"",...s})}catch(e){}}}})}function a(){return(0,n.eI)("https://drmuwsxyvvfivdfsyydy.supabase.co",process.env.SUPABASE_SERVICE_ROLE_KEY,{auth:{autoRefreshToken:!1,persistSession:!1}})}(0,s(4113).C)()},4113:(e,t,s)=>{s.d(t,{C:()=>i});var o=s(7147),r=s(1017);let n=!1;function i(){if(!n)try{let e=process.cwd(),t=[(0,r.join)(e,".env.production"),(0,r.join)(e,"..",".env.production"),(0,r.join)(e,"..","..",".env.production"),(0,r.join)(e,"app",".env.production")],s=null,i=null;for(let e of t)try{i=(0,o.readFileSync)(e,"utf-8"),s=e,console.log("[EnvLoader] Found .env.production at:",e);break}catch{continue}if(!i||!s)throw Error(`Could not find .env.production. Tried: ${t.join(", ")}`);for(let e of i.split("\n")){let t=e.trim();if(!t||t.startsWith("#"))continue;let s=t.match(/^([^=]+)=(.*)$/);if(s){let e=s[1].trim(),t=s[2].trim();(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'"))&&(t=t.slice(1,-1)),process.env[e]||(process.env[e]=t)}}n=!0,console.log("[EnvLoader] Loaded environment variables from .env.production"),console.log("[EnvLoader] SUPABASE_DB_URL:",process.env.SUPABASE_DB_URL?"SET":"NOT SET")}catch(e){"ENOENT"===e.code?console.warn("[EnvLoader] .env.production file not found at:",envPath):console.warn("[EnvLoader] Could not load .env.production:",e.message)}}}};var t=require("../../../../webpack-runtime.js");t.C(e);var s=e=>t(t.s=e),o=t.X(0,[1638,9989,6206],()=>s(4320));module.exports=o})();