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)}])},457144,11500,e=>{"use strict";var t=e.i(875225),r=e.i(349129),a=e.i(260338),s=e.i(518899),n=e.i(846344),i=e.i(401632),o=e.i(803028);function d(e,r){let a=n.db.select().from(i.conversations).where((0,t.eq)(i.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,s){let o=[(0,t.eq)(i.conversations.userId,e),(0,t.eq)(i.conversations.isDeleted,!1)];s.keyword&&o.push((0,t.like)(i.conversations.title,`%${s.keyword}%`));let d=(0,t.and)(...o),l=n.db.select({value:(0,a.count)()}).from(i.conversations).where(d).get()?.value??0;return{items:n.db.select().from(i.conversations).where(d).orderBy((0,r.desc)(i.conversations.updatedAt)).limit(s.page_size).offset((s.page-1)*s.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:s.page,page_size:s.page_size}},"listMessages",0,function(e,o,l){d(e,o);let u=l.sort.startsWith("-")?(0,r.desc)(i.messages.createdAt):(0,r.asc)(i.messages.createdAt),c=(0,t.and)((0,t.eq)(i.messages.conversationId,o),(0,t.eq)(i.messages.isActive,!0)),p=n.db.select({value:(0,a.count)()}).from(i.messages).where(c).get()?.value??0,v=n.db.select().from(i.messages).where(c).orderBy(u).limit(l.page_size).offset((l.page-1)*l.page_size).all(),g=new Set(v.map(e=>e.id)),h=Array.from(new Set(v.map(e=>e.parentId).filter(e=>!!e&&!g.has(e)))),m=[];if(h.length>0){let e=JSON.stringify(h);for(let t of m=n.db.all(s.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}
        `))g.add(t.id)}let f=[...v,...m].filter(e=>"assistant"===e.role).map(e=>e.id),R=[];if(f.length>0)for(let e of n.db.select().from(i.messages).where((0,t.and)((0,t.eq)(i.messages.conversationId,o),(0,t.eq)(i.messages.isActive,!0),(0,t.eq)(i.messages.role,"tool"),(0,t.inArray)(i.messages.parentId,f))).all())g.has(e.id)||(g.add(e.id),R.push(e));return{items:[...v,...m,...R].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),n.db.update(i.conversations).set({isDeleted:!0,updatedAt:new Date().toISOString()}).where((0,t.eq)(i.conversations.id,r)).run()},"updateConversationTitle",0,function(e,r,a){d(e,r),n.db.update(i.conversations).set({title:a.title.slice(0,100),updatedAt:new Date().toISOString()}).where((0,t.eq)(i.conversations.id,r)).run()}],11500),e.s([],457144)},442863,e=>{"use strict";var t=e.i(747909),r=e.i(174017),a=e.i(996250),s=e.i(759756),n=e.i(561916),i=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),v=e.i(570101),g=e.i(626937),h=e.i(10372),m=e.i(193695);e.i(52474);var f=e.i(600220),R=e.i(469719),x=e.i(456315);e.i(457144);var w=e.i(11500);let E=R.z.object({page:R.z.coerce.number().int().min(1).default(1),page_size:R.z.coerce.number().int().min(1).max(500).default(50),sort:R.z.string().default("-created_at")}),A=(0,x.defineRoute)({params:R.z.object({id:R.z.string().min(1)}),query:E,handler:({user:e,params:t,query:r})=>(0,w.listMessages)(e.id,t.id,r)});e.s(["GET",0,A],126133);var _=e.i(126133);let b=new t.AppRouteRouteModule({definition:{kind:r.RouteKind.APP_ROUTE,page:"/api/conversations/[id]/messages/route",pathname:"/api/conversations/[id]/messages",filename:"route",bundlePath:""},distDir:".next",relativeProjectDir:"",resolvedPagePath:"[project]/app/api/conversations/[id]/messages/route.ts",nextConfigOutput:"",userland:_,...{}}),{workAsyncStorage:C,workUnitAsyncStorage:y,serverHooks:q}=b;async function N(e,t,a){a.requestMeta&&(0,s.setRequestMeta)(e,a.requestMeta),b.isDev&&(0,s.addRequestMeta)(e,"devRequestTimingInternalsEnd",process.hrtime.bigint());let R="/api/conversations/[id]/messages/route";R=R.replace(/\/index$/,"")||"/";let x=await b.prepare(e,t,{srcPage:R,multiZoneDraftMode:!1});if(!x)return t.statusCode=400,t.end("Bad Request"),null==a.waitUntil||a.waitUntil.call(a,Promise.resolve()),null;let{buildId:w,deploymentId:E,params:A,nextConfig:_,parsedUrl:C,isDraftMode:y,prerenderManifest:q,routerServerContext:N,isOnDemandRevalidate:S,revalidateOnlyGenerated:I,resolvedPathname:O,clientReferenceManifest:T,serverActionsManifest:k}=x,P=(0,o.normalizeAppPath)(R),D=!!(q.dynamicRoutes[P]||q.routes[O]),j=async()=>((null==N?void 0:N.render404)?await N.render404(e,t,C,!1):t.end("This page could not be found"),null);if(D&&!y){let e=!!q.routes[O],t=q.dynamicRoutes[P];if(t&&!1===t.fallback&&!e){if(_.adapterPath)return await j();throw new m.NoFallbackError}}let H=null;!D||b.isDev||y||(H="/index"===(H=O)?"/":H);let M=!0===b.isDev||!D,U=D&&!M;k&&T&&(0,i.setManifestsSingleton)({page:R,clientReferenceManifest:T,serverActionsManifest:k});let z=e.method||"GET",$=(0,n.getTracer)(),F=$.getActiveScopeSpan(),L=!!(null==N?void 0:N.isWrappedByNextServer),W=!!(0,s.getRequestMeta)(e,"minimalMode"),B=(0,s.getRequestMeta)(e,"incrementalCache")||await b.getIncrementalCache(e,_,q,W);null==B||B.resetRequestCache(),globalThis.__incrementalCache=B;let K={params:A,previewProps:q.preview,renderOpts:{experimental:{authInterrupts:!!_.experimental.authInterrupts},cacheComponents:!!_.cacheComponents,supportsDynamicResponse:M,incrementalCache:B,cacheLifeProfiles:_.cacheLife,waitUntil:a.waitUntil,onClose:e=>{t.on("close",e)},onAfterTaskError:void 0,onInstrumentationRequestError:(t,r,a,s)=>b.onRequestError(e,t,a,s,N)},sharedContext:{buildId:w,deploymentId:E}},G=new d.NodeNextRequest(e),V=new d.NodeNextResponse(t),J=l.NextRequestAdapter.fromNodeNextRequest(G,(0,l.signalFromNodeResponse)(t));try{let s,i=async e=>b.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=`${z} ${a}`;e.setAttributes({"next.route":a,"http.route":a,"next.span_name":t}),e.updateName(t),s&&s!==e&&(s.setAttribute("http.route",a),s.updateName(t))}else e.updateName(`${z} ${R}`)}),o=async s=>{var n,o;let d=async({previousCacheEntry:r})=>{try{if(!W&&S&&I&&!r)return t.statusCode=404,t.setHeader("x-nextjs-cache","REVALIDATED"),t.end("This page could not be found"),null;let n=await i(s);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(!D)return await (0,p.sendResponse)(G,V,n,K.renderOpts.pendingWaitUntil),null;{let e=await n.blob(),t=(0,v.toNodeOutgoingHttpHeaders)(n.headers);d&&(t[h.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>=h.INFINITE_CACHE)&&K.renderOpts.collectedRevalidate,a=void 0===K.renderOpts.collectedExpire||K.renderOpts.collectedExpire>=h.INFINITE_CACHE?void 0:K.renderOpts.collectedExpire;return{value:{kind:f.CachedRouteKind.APP_ROUTE,status:n.status,body:Buffer.from(await e.arrayBuffer()),headers:t},cacheControl:{revalidate:r,expire:a}}}}catch(t){throw(null==r?void 0:r.isStale)&&await b.onRequestError(e,t,{routerKind:"App Router",routePath:R,routeType:"route",revalidateReason:(0,c.getRevalidateReason)({isStaticGeneration:U,isOnDemandRevalidate:S})},!1,N),t}},l=await b.handleResponse({req:e,nextConfig:_,cacheKey:H,routeKind:r.RouteKind.APP_ROUTE,isFallback:!1,prerenderManifest:q,isRoutePPREnabled:!1,isOnDemandRevalidate:S,revalidateOnlyGenerated:I,responseGenerator:d,waitUntil:a.waitUntil,isMinimalMode:W});if(!D)return null;if((null==l||null==(n=l.value)?void 0:n.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",S?"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,v.fromNodeOutgoingHttpHeaders)(l.value.headers);return W&&D||u.delete(h.NEXT_CACHE_TAGS_HEADER),!l.cacheControl||t.getHeader("Cache-Control")||u.get("Cache-Control")||u.set("Cache-Control",(0,g.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):(s=$.getActiveScopeSpan(),await $.withPropagatedContext(e.headers,()=>$.trace(u.BaseServerSpan.handleRequest,{spanName:`${z} ${R}`,kind:n.SpanKind.SERVER,attributes:{"http.method":z,"http.target":e.url}},o),void 0,!L))}catch(t){if(t instanceof m.NoFallbackError||await b.onRequestError(e,t,{routerKind:"App Router",routePath:P,routeType:"route",revalidateReason:(0,c.getRevalidateReason)({isStaticGeneration:U,isOnDemandRevalidate:S})},!1,N),D)throw t;return await (0,p.sendResponse)(G,V,new Response(null,{status:500})),null}}e.s(["handler",0,N,"patchFetch",0,function(){return(0,a.patchFetch)({workAsyncStorage:C,workUnitAsyncStorage:y})},"routeModule",0,b,"serverHooks",0,q,"workAsyncStorage",0,C,"workUnitAsyncStorage",0,y],442863)}];

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