module.exports=[918622,(e,t,r)=>{t.exports=e.x("next/dist/compiled/next-server/app-page-turbo.runtime.prod.js",()=>require("next/dist/compiled/next-server/app-page-turbo.runtime.prod.js"))},556704,(e,t,r)=>{t.exports=e.x("next/dist/server/app-render/work-async-storage.external.js",()=>require("next/dist/server/app-render/work-async-storage.external.js"))},832319,(e,t,r)=>{t.exports=e.x("next/dist/server/app-render/work-unit-async-storage.external.js",()=>require("next/dist/server/app-render/work-unit-async-storage.external.js"))},324725,(e,t,r)=>{t.exports=e.x("next/dist/server/app-render/after-task-async-storage.external.js",()=>require("next/dist/server/app-render/after-task-async-storage.external.js"))},193695,(e,t,r)=>{t.exports=e.x("next/dist/shared/lib/no-fallback-error.external.js",()=>require("next/dist/shared/lib/no-fallback-error.external.js"))},666680,(e,t,r)=>{t.exports=e.x("node:crypto",()=>require("node:crypto"))},750227,(e,t,r)=>{t.exports=e.x("node:path",()=>require("node:path"))},260338,e=>{"use strict";e.i(156325),e.i(844988);var t=e.i(518899);e.s(["count",0,function(e){return t.sql`count(${e||t.sql.raw("*")})`.mapWith(Number)}])},364507,e=>{"use strict";var t=e.i(469719);let r=t.z.enum(["user","assistant","system","tool"]);t.z.object({id:t.z.string(),user_id:t.z.string(),title:t.z.string(),config:t.z.record(t.z.string(),t.z.unknown()),group_id:t.z.string().optional(),created_at:t.z.string(),updated_at:t.z.string(),is_deleted:t.z.boolean()}),t.z.object({id:t.z.string(),conversation_id:t.z.string(),role:r,content:t.z.unknown(),reasoning_content:t.z.string().optional(),model_id:t.z.string().optional(),generation_id:t.z.string().optional(),parent_id:t.z.string().optional(),is_active:t.z.boolean(),rating:t.z.enum(["up","down"]).optional(),feedback:t.z.string().optional(),error:t.z.string().optional(),created_at:t.z.string()});let a=t.z.object({page:t.z.coerce.number().int().min(1).default(1),page_size:t.z.coerce.number().int().min(1).max(200).default(20),sort:t.z.string().default("-updated_at"),keyword:t.z.string().trim().optional()}),n=t.z.object({title:t.z.string().trim().min(1,"title is required").max(200)});t.z.object({page:t.z.coerce.number().int().min(1).default(1),page_size:t.z.coerce.number().int().min(1).max(500).default(50),sort:t.z.string().default("-created_at")});let i=t.z.object({rating:t.z.enum(["up","down","none"]),feedback:t.z.string().nullable().optional()});e.s(["conversationListQuerySchema",0,a,"conversationTitleSchema",0,n,"messageRatingSchema",0,i])},457144,11500,e=>{"use strict";var t=e.i(875225),r=e.i(349129),a=e.i(260338),n=e.i(518899),i=e.i(846344),s=e.i(401632),o=e.i(803028);function d(e,r){let a=i.db.select().from(s.conversations).where((0,t.eq)(s.conversations.id,r)).get();if(!a)throw(0,o.notFound)("Conversation not found");if(a.userId!==e)throw(0,o.forbidden)();return a}e.s(["listConversations",0,function(e,n){let o=[(0,t.eq)(s.conversations.userId,e),(0,t.eq)(s.conversations.isDeleted,!1)];n.keyword&&o.push((0,t.like)(s.conversations.title,`%${n.keyword}%`));let d=(0,t.and)(...o),l=i.db.select({value:(0,a.count)()}).from(s.conversations).where(d).get()?.value??0;return{items:i.db.select().from(s.conversations).where(d).orderBy((0,r.desc)(s.conversations.updatedAt)).limit(n.page_size).offset((n.page-1)*n.page_size).all().map(e=>({id:e.id,user_id:e.userId,title:e.title,config:e.config??{},group_id:e.groupId??void 0,created_at:e.createdAt,updated_at:e.updatedAt,is_deleted:!!e.isDeleted})),total:l,page:n.page,page_size:n.page_size}},"listMessages",0,function(e,o,l){d(e,o);let u=l.sort.startsWith("-")?(0,r.desc)(s.messages.createdAt):(0,r.asc)(s.messages.createdAt),c=(0,t.and)((0,t.eq)(s.messages.conversationId,o),(0,t.eq)(s.messages.isActive,!0)),p=i.db.select({value:(0,a.count)()}).from(s.messages).where(c).get()?.value??0,g=i.db.select().from(s.messages).where(c).orderBy(u).limit(l.page_size).offset((l.page-1)*l.page_size).all(),v=new Set(g.map(e=>e.id)),m=Array.from(new Set(g.map(e=>e.parentId).filter(e=>!!e&&!v.has(e)))),h=[];if(m.length>0){let e=JSON.stringify(m);for(let t of h=i.db.all(n.sql`
            WITH RECURSIVE ancestors(id, depth) AS (
                SELECT value AS id, 0 AS depth FROM json_each(${e})
                UNION
                SELECT m.parent_id, a.depth + 1
                FROM messages m
                JOIN ancestors a ON m.id = a.id
                WHERE m.parent_id IS NOT NULL
                  AND m.conversation_id = ${o}
                  AND a.depth < 64
            )
            SELECT m.* FROM messages m
            JOIN ancestors a ON m.id = a.id
            WHERE m.conversation_id = ${o}
        `))v.add(t.id)}let f=[...g,...h].filter(e=>"assistant"===e.role).map(e=>e.id),x=[];if(f.length>0)for(let e of i.db.select().from(s.messages).where((0,t.and)((0,t.eq)(s.messages.conversationId,o),(0,t.eq)(s.messages.isActive,!0),(0,t.eq)(s.messages.role,"tool"),(0,t.inArray)(s.messages.parentId,f))).all())v.has(e.id)||(v.add(e.id),x.push(e));return{items:[...g,...h,...x].sort((e,t)=>{let r=e.createdAt<t.createdAt?-1:+(e.createdAt>t.createdAt);return l.sort.startsWith("-")?-r:r}).map(e=>({id:e.id,conversation_id:e.conversationId,role:e.role,content:e.content,reasoning_content:e.reasoningContent??void 0,model_id:e.modelId??void 0,generation_id:e.generationId??void 0,parent_id:e.parentId??void 0,is_active:!!e.isActive,rating:e.rating??void 0,feedback:e.feedback??void 0,error:e.error??void 0,created_at:e.createdAt})),total:p,page:l.page,page_size:l.page_size}},"softDeleteConversation",0,function(e,r){d(e,r),i.db.update(s.conversations).set({isDeleted:!0,updatedAt:new Date().toISOString()}).where((0,t.eq)(s.conversations.id,r)).run()},"updateConversationTitle",0,function(e,r,a){d(e,r),i.db.update(s.conversations).set({title:a.title.slice(0,100),updatedAt:new Date().toISOString()}).where((0,t.eq)(s.conversations.id,r)).run()}],11500),e.s([],457144)},16906,e=>{"use strict";var t=e.i(747909),r=e.i(174017),a=e.i(996250),n=e.i(759756),i=e.i(561916),s=e.i(174677),o=e.i(869741),d=e.i(316795),l=e.i(487718),u=e.i(995169),c=e.i(47587),p=e.i(666012),g=e.i(570101),v=e.i(626937),m=e.i(10372),h=e.i(193695);e.i(52474);var f=e.i(600220),x=e.i(456315),R=e.i(364507);e.i(457144);var w=e.i(11500);let _=(0,x.defineRoute)({query:R.conversationListQuerySchema,handler:({user:e,query:t})=>(0,w.listConversations)(e.id,t)});e.s(["GET",0,_],120570);var b=e.i(120570);let E=new t.AppRouteRouteModule({definition:{kind:r.RouteKind.APP_ROUTE,page:"/api/conversations/route",pathname:"/api/conversations",filename:"route",bundlePath:""},distDir:".next",relativeProjectDir:"",resolvedPagePath:"[project]/app/api/conversations/route.ts",nextConfigOutput:"",userland:b,...{}}),{workAsyncStorage:A,workUnitAsyncStorage:z,serverHooks:y}=E;async function C(e,t,a){a.requestMeta&&(0,n.setRequestMeta)(e,a.requestMeta),E.isDev&&(0,n.addRequestMeta)(e,"devRequestTimingInternalsEnd",process.hrtime.bigint());let x="/api/conversations/route";x=x.replace(/\/index$/,"")||"/";let R=await E.prepare(e,t,{srcPage:x,multiZoneDraftMode:!1});if(!R)return t.statusCode=400,t.end("Bad Request"),null==a.waitUntil||a.waitUntil.call(a,Promise.resolve()),null;let{buildId:w,deploymentId:_,params:b,nextConfig:A,parsedUrl:z,isDraftMode:y,prerenderManifest:C,routerServerContext:S,isOnDemandRevalidate:q,revalidateOnlyGenerated:N,resolvedPathname:I,clientReferenceManifest:O,serverActionsManifest:T}=R,k=(0,o.normalizeAppPath)(x),j=!!(C.dynamicRoutes[k]||C.routes[I]),P=async()=>((null==S?void 0:S.render404)?await S.render404(e,t,z,!1):t.end("This page could not be found"),null);if(j&&!y){let e=!!C.routes[I],t=C.dynamicRoutes[k];if(t&&!1===t.fallback&&!e){if(A.adapterPath)return await P();throw new h.NoFallbackError}}let D=null;!j||E.isDev||y||(D="/index"===(D=I)?"/":D);let H=!0===E.isDev||!j,M=j&&!H;T&&O&&(0,s.setManifestsSingleton)({page:x,clientReferenceManifest:O,serverActionsManifest:T});let U=e.method||"GET",$=(0,i.getTracer)(),F=$.getActiveScopeSpan(),L=!!(null==S?void 0:S.isWrappedByNextServer),W=!!(0,n.getRequestMeta)(e,"minimalMode"),B=(0,n.getRequestMeta)(e,"incrementalCache")||await E.getIncrementalCache(e,A,C,W);null==B||B.resetRequestCache(),globalThis.__incrementalCache=B;let K={params:b,previewProps:C.preview,renderOpts:{experimental:{authInterrupts:!!A.experimental.authInterrupts},cacheComponents:!!A.cacheComponents,supportsDynamicResponse:H,incrementalCache:B,cacheLifeProfiles:A.cacheLife,waitUntil:a.waitUntil,onClose:e=>{t.on("close",e)},onAfterTaskError:void 0,onInstrumentationRequestError:(t,r,a,n)=>E.onRequestError(e,t,a,n,S)},sharedContext:{buildId:w,deploymentId:_}},G=new d.NodeNextRequest(e),V=new d.NodeNextResponse(t),J=l.NextRequestAdapter.fromNodeNextRequest(G,(0,l.signalFromNodeResponse)(t));try{let n,s=async e=>E.handle(J,K).finally(()=>{if(!e)return;e.setAttributes({"http.status_code":t.statusCode,"next.rsc":!1});let r=$.getRootSpanAttributes();if(!r)return;if(r.get("next.span_type")!==u.BaseServerSpan.handleRequest)return void console.warn(`Unexpected root span type '${r.get("next.span_type")}'. Please report this Next.js issue https://github.com/vercel/next.js`);let a=r.get("next.route");if(a){let t=`${U} ${a}`;e.setAttributes({"next.route":a,"http.route":a,"next.span_name":t}),e.updateName(t),n&&n!==e&&(n.setAttribute("http.route",a),n.updateName(t))}else e.updateName(`${U} ${x}`)}),o=async n=>{var i,o;let d=async({previousCacheEntry:r})=>{try{if(!W&&q&&N&&!r)return t.statusCode=404,t.setHeader("x-nextjs-cache","REVALIDATED"),t.end("This page could not be found"),null;let i=await s(n);e.fetchMetrics=K.renderOpts.fetchMetrics;let o=K.renderOpts.pendingWaitUntil;o&&a.waitUntil&&(a.waitUntil(o),o=void 0);let d=K.renderOpts.collectedTags;if(!j)return await (0,p.sendResponse)(G,V,i,K.renderOpts.pendingWaitUntil),null;{let e=await i.blob(),t=(0,g.toNodeOutgoingHttpHeaders)(i.headers);d&&(t[m.NEXT_CACHE_TAGS_HEADER]=d),!t["content-type"]&&e.type&&(t["content-type"]=e.type);let r=void 0!==K.renderOpts.collectedRevalidate&&!(K.renderOpts.collectedRevalidate>=m.INFINITE_CACHE)&&K.renderOpts.collectedRevalidate,a=void 0===K.renderOpts.collectedExpire||K.renderOpts.collectedExpire>=m.INFINITE_CACHE?void 0:K.renderOpts.collectedExpire;return{value:{kind:f.CachedRouteKind.APP_ROUTE,status:i.status,body:Buffer.from(await e.arrayBuffer()),headers:t},cacheControl:{revalidate:r,expire:a}}}}catch(t){throw(null==r?void 0:r.isStale)&&await E.onRequestError(e,t,{routerKind:"App Router",routePath:x,routeType:"route",revalidateReason:(0,c.getRevalidateReason)({isStaticGeneration:M,isOnDemandRevalidate:q})},!1,S),t}},l=await E.handleResponse({req:e,nextConfig:A,cacheKey:D,routeKind:r.RouteKind.APP_ROUTE,isFallback:!1,prerenderManifest:C,isRoutePPREnabled:!1,isOnDemandRevalidate:q,revalidateOnlyGenerated:N,responseGenerator:d,waitUntil:a.waitUntil,isMinimalMode:W});if(!j)return null;if((null==l||null==(i=l.value)?void 0:i.kind)!==f.CachedRouteKind.APP_ROUTE)throw Object.defineProperty(Error(`Invariant: app-route received invalid cache entry ${null==l||null==(o=l.value)?void 0:o.kind}`),"__NEXT_ERROR_CODE",{value:"E701",enumerable:!1,configurable:!0});W||t.setHeader("x-nextjs-cache",q?"REVALIDATED":l.isMiss?"MISS":l.isStale?"STALE":"HIT"),y&&t.setHeader("Cache-Control","private, no-cache, no-store, max-age=0, must-revalidate");let u=(0,g.fromNodeOutgoingHttpHeaders)(l.value.headers);return W&&j||u.delete(m.NEXT_CACHE_TAGS_HEADER),!l.cacheControl||t.getHeader("Cache-Control")||u.get("Cache-Control")||u.set("Cache-Control",(0,v.getCacheControlHeader)(l.cacheControl)),await (0,p.sendResponse)(G,V,new Response(l.value.body,{headers:u,status:l.value.status||200})),null};L&&F?await o(F):(n=$.getActiveScopeSpan(),await $.withPropagatedContext(e.headers,()=>$.trace(u.BaseServerSpan.handleRequest,{spanName:`${U} ${x}`,kind:i.SpanKind.SERVER,attributes:{"http.method":U,"http.target":e.url}},o),void 0,!L))}catch(t){if(t instanceof h.NoFallbackError||await E.onRequestError(e,t,{routerKind:"App Router",routePath:k,routeType:"route",revalidateReason:(0,c.getRevalidateReason)({isStaticGeneration:M,isOnDemandRevalidate:q})},!1,S),j)throw t;return await (0,p.sendResponse)(G,V,new Response(null,{status:500})),null}}e.s(["handler",0,C,"patchFetch",0,function(){return(0,a.patchFetch)({workAsyncStorage:A,workUnitAsyncStorage:z})},"routeModule",0,E,"serverHooks",0,y,"workAsyncStorage",0,A,"workUnitAsyncStorage",0,z],16906)}];

//# sourceMappingURL=%5Broot-of-the-server%5D__09aa0ci._.js.map