3 lines
9.5 KiB
JavaScript
3 lines
9.5 KiB
JavaScript
(()=>{var a={};a.id=276,a.ids=[276],a.modules={261:a=>{"use strict";a.exports=require("next/dist/shared/lib/router/utils/app-paths")},456:()=>{},600:(a,b,c)=>{"use strict";c.r(b),c.d(b,{handler:()=>C,patchFetch:()=>B,routeModule:()=>x,serverHooks:()=>A,workAsyncStorage:()=>y,workUnitAsyncStorage:()=>z});var d={};c.r(d),c.d(d,{POST:()=>w});var e=c(5397),f=c(914),g=c(9537),h=c(1297),i=c(2403),j=c(261),k=c(2937),l=c(6039),m=c(3793),n=c(9042),o=c(1428),p=c(4414),q=c(5252),r=c(6709),s=c(6439),t=c(427),u=c(7364);function v(a){try{let{oldCode:b,newCode:c,title:d,language:e}=a;if(!b||!c)return"Error: Missing oldCode or newCode in diff tool call";let f={oldCode:String(b).replace(/\n/g,"\\n"),newCode:String(c).replace(/\n/g,"\\n"),title:d||"Code Changes",language:e||"text"};return`\`\`\`diff-tool
|
|
${JSON.stringify(f,null,2)}
|
|
\`\`\``}catch(a){return console.error("[v0] Error converting diff tool:",a),"Error: Failed to process diff tool call"}}async function w(a){try{let b=await a.json();if("object"!=typeof b||null===b)return u.NextResponse.json({error:"Invalid request body"},{status:400});let{message:c,timestamp:d,sessionId:e,agentId:f,images:g}=b;if(!c||"string"!=typeof c)return u.NextResponse.json({error:"Message is required"},{status:400});if(!f||"string"!=typeof f)return u.NextResponse.json({error:"Agent ID is required"},{status:400});let h=function(a){let b=a.match(/agent-(\d+)/);if(!b)return console.error("[chat] Invalid agentId format:",a),null;let c=b[1],d=`AGENT_${c}_URL`,e=process.env[d];return e||(console.error(`[chat] No webhook URL configured for ${d}`),null)}(f);if(!h)return u.NextResponse.json({error:`Agent ${f} is not properly configured`},{status:400});console.log("[chat] Sending to webhook:",{agentId:f,message:c,timestamp:d,sessionId:e});let i=await fetch(h,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:c,timestamp:d,sessionId:e,agentId:f,images:g&&g.length>0?g:void 0})});console.log("[v0] Webhook response status:",i.status);let j=await i.text();if(console.log("[v0] Webhook response body (first 200 chars):",j.substring(0,200)),!i.ok){let a;try{a=j?JSON.parse(j):{}}catch{a={message:j||"Unknown error"}}return console.error("[v0] Webhook error:",a),u.NextResponse.json({error:a.message||"Failed to communicate with webhook",hint:a.hint,code:a.code},{status:i.status})}if(!j)return console.log("[v0] Empty response from webhook"),u.NextResponse.json({response:"The webhook received your message but didn't return a response. Please ensure your n8n workflow includes a 'Respond to Webhook' node that returns data.",hint:"Add a 'Respond to Webhook' node in your n8n workflow to send responses back to the chat."});try{let a=j.trim().split("\n"),b=[];for(let c of a)if(c.trim())try{let a=JSON.parse(c);if("item"===a.type&&a.content&&b.push(a.content),"tool_call"===a.type&&"show_diff"===a.name){let c=v(a.args);b.push(c)}}catch{console.log("[v0] Failed to parse line:",c)}if(b.length>0){let a=b.join("");return console.log("[v0] Combined message from",b.length,"chunks"),u.NextResponse.json({response:a})}let c=JSON.parse(j);if(console.log("[v0] Parsed webhook data:",c),"tool_call"===c.type&&"show_diff"===c.name){let a=v(c.args);return u.NextResponse.json({response:a})}let d=c.response||c.message||c.output||c.text;return"object"==typeof d&&(d=d.response||d.message||d.output||d.text),d||(d=JSON.stringify(c)),u.NextResponse.json({response:d})}catch{return console.log("[v0] Response is not JSON, returning as text"),u.NextResponse.json({response:j})}}catch(a){return console.error("[v0] API route error:",a),u.NextResponse.json({error:"Internal server error"},{status:500})}}let x=new e.AppRouteRouteModule({definition:{kind:f.RouteKind.APP_ROUTE,page:"/api/chat/route",pathname:"/api/chat",filename:"route",bundlePath:"app/api/chat/route"},distDir:".next",relativeProjectDir:"",resolvedPagePath:"/home/nicholai/Documents/dev/multi-agent_chat_interface/src/app/api/chat/route.ts",nextConfigOutput:"",userland:d}),{workAsyncStorage:y,workUnitAsyncStorage:z,serverHooks:A}=x;function B(){return(0,g.patchFetch)({workAsyncStorage:y,workUnitAsyncStorage:z})}async function C(a,b,c){var d;let e="/api/chat/route";"/index"===e&&(e="/");let g=await x.prepare(a,b,{srcPage:e,multiZoneDraftMode:!1});if(!g)return b.statusCode=400,b.end("Bad Request"),null==c.waitUntil||c.waitUntil.call(c,Promise.resolve()),null;let{buildId:u,params:v,nextConfig:w,isDraftMode:y,prerenderManifest:z,routerServerContext:A,isOnDemandRevalidate:B,revalidateOnlyGenerated:C,resolvedPathname:D}=g,E=(0,j.normalizeAppPath)(e),F=!!(z.dynamicRoutes[E]||z.routes[D]);if(F&&!y){let a=!!z.routes[D],b=z.dynamicRoutes[E];if(b&&!1===b.fallback&&!a)throw new s.NoFallbackError}let G=null;!F||x.isDev||y||(G="/index"===(G=D)?"/":G);let H=!0===x.isDev||!F,I=F&&!H,J=a.method||"GET",K=(0,i.getTracer)(),L=K.getActiveScopeSpan(),M={params:v,prerenderManifest:z,renderOpts:{experimental:{cacheComponents:!!w.experimental.cacheComponents,authInterrupts:!!w.experimental.authInterrupts},supportsDynamicResponse:H,incrementalCache:(0,h.getRequestMeta)(a,"incrementalCache"),cacheLifeProfiles:null==(d=w.experimental)?void 0:d.cacheLife,isRevalidate:I,waitUntil:c.waitUntil,onClose:a=>{b.on("close",a)},onAfterTaskError:void 0,onInstrumentationRequestError:(b,c,d)=>x.onRequestError(a,b,d,A)},sharedContext:{buildId:u}},N=new k.NodeNextRequest(a),O=new k.NodeNextResponse(b),P=l.NextRequestAdapter.fromNodeNextRequest(N,(0,l.signalFromNodeResponse)(b));try{let d=async c=>x.handle(P,M).finally(()=>{if(!c)return;c.setAttributes({"http.status_code":b.statusCode,"next.rsc":!1});let d=K.getRootSpanAttributes();if(!d)return;if(d.get("next.span_type")!==m.BaseServerSpan.handleRequest)return void console.warn(`Unexpected root span type '${d.get("next.span_type")}'. Please report this Next.js issue https://github.com/vercel/next.js`);let e=d.get("next.route");if(e){let a=`${J} ${e}`;c.setAttributes({"next.route":e,"http.route":e,"next.span_name":a}),c.updateName(a)}else c.updateName(`${J} ${a.url}`)}),g=async g=>{var i,j;let k=async({previousCacheEntry:f})=>{try{if(!(0,h.getRequestMeta)(a,"minimalMode")&&B&&C&&!f)return b.statusCode=404,b.setHeader("x-nextjs-cache","REVALIDATED"),b.end("This page could not be found"),null;let e=await d(g);a.fetchMetrics=M.renderOpts.fetchMetrics;let i=M.renderOpts.pendingWaitUntil;i&&c.waitUntil&&(c.waitUntil(i),i=void 0);let j=M.renderOpts.collectedTags;if(!F)return await (0,o.I)(N,O,e,M.renderOpts.pendingWaitUntil),null;{let a=await e.blob(),b=(0,p.toNodeOutgoingHttpHeaders)(e.headers);j&&(b[r.NEXT_CACHE_TAGS_HEADER]=j),!b["content-type"]&&a.type&&(b["content-type"]=a.type);let c=void 0!==M.renderOpts.collectedRevalidate&&!(M.renderOpts.collectedRevalidate>=r.INFINITE_CACHE)&&M.renderOpts.collectedRevalidate,d=void 0===M.renderOpts.collectedExpire||M.renderOpts.collectedExpire>=r.INFINITE_CACHE?void 0:M.renderOpts.collectedExpire;return{value:{kind:t.CachedRouteKind.APP_ROUTE,status:e.status,body:Buffer.from(await a.arrayBuffer()),headers:b},cacheControl:{revalidate:c,expire:d}}}}catch(b){throw(null==f?void 0:f.isStale)&&await x.onRequestError(a,b,{routerKind:"App Router",routePath:e,routeType:"route",revalidateReason:(0,n.c)({isRevalidate:I,isOnDemandRevalidate:B})},A),b}},l=await x.handleResponse({req:a,nextConfig:w,cacheKey:G,routeKind:f.RouteKind.APP_ROUTE,isFallback:!1,prerenderManifest:z,isRoutePPREnabled:!1,isOnDemandRevalidate:B,revalidateOnlyGenerated:C,responseGenerator:k,waitUntil:c.waitUntil});if(!F)return null;if((null==l||null==(i=l.value)?void 0:i.kind)!==t.CachedRouteKind.APP_ROUTE)throw Object.defineProperty(Error(`Invariant: app-route received invalid cache entry ${null==l||null==(j=l.value)?void 0:j.kind}`),"__NEXT_ERROR_CODE",{value:"E701",enumerable:!1,configurable:!0});(0,h.getRequestMeta)(a,"minimalMode")||b.setHeader("x-nextjs-cache",B?"REVALIDATED":l.isMiss?"MISS":l.isStale?"STALE":"HIT"),y&&b.setHeader("Cache-Control","private, no-cache, no-store, max-age=0, must-revalidate");let m=(0,p.fromNodeOutgoingHttpHeaders)(l.value.headers);return(0,h.getRequestMeta)(a,"minimalMode")&&F||m.delete(r.NEXT_CACHE_TAGS_HEADER),!l.cacheControl||b.getHeader("Cache-Control")||m.get("Cache-Control")||m.set("Cache-Control",(0,q.getCacheControlHeader)(l.cacheControl)),await (0,o.I)(N,O,new Response(l.value.body,{headers:m,status:l.value.status||200})),null};L?await g(L):await K.withPropagatedContext(a.headers,()=>K.trace(m.BaseServerSpan.handleRequest,{spanName:`${J} ${a.url}`,kind:i.SpanKind.SERVER,attributes:{"http.method":J,"http.target":a.url}},g))}catch(b){if(b instanceof s.NoFallbackError||await x.onRequestError(a,b,{routerKind:"App Router",routePath:E,routeType:"route",revalidateReason:(0,n.c)({isRevalidate:I,isOnDemandRevalidate:B})}),F)throw b;return await (0,o.I)(N,O,new Response(null,{status:500})),null}}},846:a=>{"use strict";a.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},3033:a=>{"use strict";a.exports=require("next/dist/server/app-render/work-unit-async-storage.external.js")},3295:a=>{"use strict";a.exports=require("next/dist/server/app-render/after-task-async-storage.external.js")},4870:a=>{"use strict";a.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},6439:a=>{"use strict";a.exports=require("next/dist/shared/lib/no-fallback-error.external")},6904:()=>{},9121:a=>{"use strict";a.exports=require("next/dist/server/app-render/action-async-storage.external.js")},9294:a=>{"use strict";a.exports=require("next/dist/server/app-render/work-async-storage.external.js")}};var b=require("../../../webpack-runtime.js");b.C(a);var c=b.X(0,[729,305],()=>b(b.s=600));module.exports=c})(); |