module.exports=[93695,(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"))},70406,(e,t,r)=>{t.exports=e.x("next/dist/compiled/@opentelemetry/api",()=>require("next/dist/compiled/@opentelemetry/api"))},18622,(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"))},56704,(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"))},32319,(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"))},24725,(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"))},24280,e=>{"use strict";async function t(e,r={}){let a=r.apiKey||process.env.PIXAZO_SUBSCRIPTION_KEY;if(!a)throw Error("Pixazo API key is not configured. Please add your key in API Settings.");if(!e||0===e.trim().length)throw Error("Prompt is required for Pixazo generation");let{width:n=758,height:i=1344,num_steps:o=4,seed:s=Math.floor(1e5*Math.random())}=r;console.log("[Pixazo AI] Generating image...",{width:n,height:i});let l=await fetch("https://gateway.pixazo.ai/flux-1-schnell/v1/getData",{method:"POST",headers:{"Content-Type":"application/json","Cache-Control":"no-cache","Ocp-Apim-Subscription-Key":a},body:JSON.stringify({prompt:e,num_steps:o,seed:s,height:i,width:n})});if(!l.ok){let e=await l.text().catch(()=>"Unknown error");throw console.error(`[Pixazo AI] Request failed with status ${l.status}:`,e),Error(`Pixazo API failed with status ${l.status}`)}let d=await l.json();if(!d||!d.output)throw console.error("[Pixazo AI] Invalid response format:",d),Error("Pixazo API returned an invalid response");return{imageUrl:d.output}}e.s(["generatePixazoImage",()=>t])},52783,e=>{"use strict";var t=e.i(47909),r=e.i(74017),a=e.i(96250),n=e.i(59756),i=e.i(61916),o=e.i(14444),s=e.i(37092),l=e.i(69741),d=e.i(16795),u=e.i(87718),p=e.i(95169),c=e.i(47587),m=e.i(66012),h=e.i(70101),g=e.i(26937),f=e.i(10372),x=e.i(93695);e.i(52474);var w=e.i(5232),R=e.i(89171),v=e.i(89660),y=e.i(6294);async function E(e,t,r="normal",a){let n=`You are an expert at creating detailed but CONCISE image generation prompts for AI art models.
Your task is to transform character descriptions into effective prompts.

Guidelines:
- Focus on key visual details: appearance, clothing, style.
- KEEP IT SHORT. Maximum 2-3 sentences.
- Include art style keywords.
- Output ONLY the prompt text.
- NO filler words like "captured in a moment of..." or "perhaps walking...".

Example input: "A brave knight with golden armor"
Example output: "Heroic knight in gleaming golden armor, sword raised, dramatic lighting, medieval fantasy style, 8k quality"`,i=`Character Description: ${e}
Appearance Details: ${t}

Generate a concise image prompt (max 400 chars):`;try{let o=(await (0,y.generateWithFallbackChain)("nsfw"===r?["liquid/lfm-2.5-1.2b-instruct:free","nousresearch/hermes-3-llama-3.1-405b:free","z-ai/glm-4.5-air:free","openrouter/elephant-alpha","liquid/lfm-2.5-1.2b-thinking:free","openrouter/free"]:["liquid/lfm-2.5-1.2b-instruct:free","z-ai/glm-4.5-air:free","nousresearch/hermes-3-llama-3.1-405b:free","liquid/lfm-2.5-1.2b-thinking:free","openrouter/elephant-alpha","openrouter/free"],{prompt:i,systemPrompt:n,temperature:.7,maxTokens:150,apiKey:a})).text.trim();return(o=o.replace(/<\/?s>/g,"").replace(/\[\/?INST\]/g,"").replace(/^(System|User|Assistant|Here is .*?|Sure, .*?):\s*/i,"").replace(/^["']|["']$/g,"").replace(/(\r\n|\n|\r)/gm," ").trim())&&!(o.length<5)||(o=`${e}, ${t}`),{prompt:o}}catch(r){return console.error("[generateImagePrompt] Error:",r),{prompt:`${e}, ${t}`,error:`Failed to enhance prompt. Using basic prompt. Error: ${r.message}`}}}var P=e.i(24280);async function C(e){try{let t,r,a=await (0,v.createClient)(),{data:{user:n},error:i}=await a.auth.getUser();if(i||!n)return R.NextResponse.json({error:"Unauthorized"},{status:401});let{characterDescription:o,appearance:s,mode:l="normal",width:d=512,height:u=512,seed:p,model:c,pixazoKey:m,cost:h=5,isEdit:g=!1}=await e.json();if(!o||!s)return R.NextResponse.json({error:"characterDescription and appearance are required"},{status:400});let{data:f}=await v.supabaseAdmin.from("profiles").select("credits, total_credits_spent").eq("id",n.id).single(),x=f?.credits||0,w=f?.total_credits_spent||0;if(x<h)return R.NextResponse.json({error:"Insufficient credits",current:x,required:h},{status:400});let{data:y}=await a.from("user_api_keys").select("key_value").eq("user_id",n.id).eq("provider","openRouter").maybeSingle();if(!y?.key_value)return R.NextResponse.json({error:"OpenRouter API key not found. Please add your key in API Settings to generate prompts."},{status:402});let{prompt:C,error:A}=await E(o,s,l,y.key_value);A&&console.warn("Prompt generation warning:",A);try{t=(await (0,P.generatePixazoImage)(C,{width:Number(d),height:Number(u),seed:p||Math.floor(1e6*Math.random()),num_steps:4,apiKey:m})).imageUrl}catch(e){console.error("Pixazo generation failed:",e),r=e.message||"Pixazo generation failed"}if(r)return console.warn("Image generation warning:",r),R.NextResponse.json({error:r},{status:500});let b=x;if(h>0){b=x-h;let{error:e}=await v.supabaseAdmin.from("profiles").update({credits:b,total_credits_spent:w+h}).eq("id",n.id);e||await v.supabaseAdmin.from("credit_transactions").insert({user_id:n.id,amount:-h,balance_after:b,transaction_type:"spend",description:g?"Character Image Edit":"Character Image Creation"})}return R.NextResponse.json({success:!0,imageUrl:t,prompt:C,newBalance:b,warnings:[A].filter(Boolean)})}catch(e){return console.error("Character image generation error:",e),R.NextResponse.json({error:"Failed to generate character image",details:e.message},{status:500})}}e.s(["POST",()=>C],37204);var A=e.i(37204);let b=new t.AppRouteRouteModule({definition:{kind:r.RouteKind.APP_ROUTE,page:"/api/generate-character-image/route",pathname:"/api/generate-character-image",filename:"route",bundlePath:""},distDir:".next",relativeProjectDir:"",resolvedPagePath:"[project]/app/api/generate-character-image/route.ts",nextConfigOutput:"standalone",userland:A}),{workAsyncStorage:k,workUnitAsyncStorage:I,serverHooks:_}=b;function N(){return(0,a.patchFetch)({workAsyncStorage:k,workUnitAsyncStorage:I})}async function S(e,t,a){b.isDev&&(0,n.addRequestMeta)(e,"devRequestTimingInternalsEnd",process.hrtime.bigint());let R="/api/generate-character-image/route";R=R.replace(/\/index$/,"")||"/";let v=await b.prepare(e,t,{srcPage:R,multiZoneDraftMode:!1});if(!v)return t.statusCode=400,t.end("Bad Request"),null==a.waitUntil||a.waitUntil.call(a,Promise.resolve()),null;let{buildId:y,params:E,nextConfig:P,parsedUrl:C,isDraftMode:A,prerenderManifest:k,routerServerContext:I,isOnDemandRevalidate:_,revalidateOnlyGenerated:N,resolvedPathname:S,clientReferenceManifest:q,serverActionsManifest:O}=v,T=(0,l.normalizeAppPath)(R),j=!!(k.dynamicRoutes[T]||k.routes[S]),U=async()=>((null==I?void 0:I.render404)?await I.render404(e,t,C,!1):t.end("This page could not be found"),null);if(j&&!A){let e=!!k.routes[S],t=k.dynamicRoutes[T];if(t&&!1===t.fallback&&!e){if(P.experimental.adapterPath)return await U();throw new x.NoFallbackError}}let M=null;!j||b.isDev||A||(M="/index"===(M=S)?"/":M);let H=!0===b.isDev||!j,$=j&&!H;O&&q&&(0,o.setReferenceManifestsSingleton)({page:R,clientReferenceManifest:q,serverActionsManifest:O,serverModuleMap:(0,s.createServerModuleMap)({serverActionsManifest:O})});let D=e.method||"GET",z=(0,i.getTracer)(),K=z.getActiveScopeSpan(),F={params:E,prerenderManifest:k,renderOpts:{experimental:{authInterrupts:!!P.experimental.authInterrupts},cacheComponents:!!P.cacheComponents,supportsDynamicResponse:H,incrementalCache:(0,n.getRequestMeta)(e,"incrementalCache"),cacheLifeProfiles:P.cacheLife,waitUntil:a.waitUntil,onClose:e=>{t.on("close",e)},onAfterTaskError:void 0,onInstrumentationRequestError:(t,r,a)=>b.onRequestError(e,t,a,I)},sharedContext:{buildId:y}},B=new d.NodeNextRequest(e),G=new d.NodeNextResponse(t),L=u.NextRequestAdapter.fromNodeNextRequest(B,(0,u.signalFromNodeResponse)(t));try{let o=async e=>b.handle(L,F).finally(()=>{if(!e)return;e.setAttributes({"http.status_code":t.statusCode,"next.rsc":!1});let r=z.getRootSpanAttributes();if(!r)return;if(r.get("next.span_type")!==p.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=`${D} ${a}`;e.setAttributes({"next.route":a,"http.route":a,"next.span_name":t}),e.updateName(t)}else e.updateName(`${D} ${R}`)}),s=!!(0,n.getRequestMeta)(e,"minimalMode"),l=async n=>{var i,l;let d=async({previousCacheEntry:r})=>{try{if(!s&&_&&N&&!r)return t.statusCode=404,t.setHeader("x-nextjs-cache","REVALIDATED"),t.end("This page could not be found"),null;let i=await o(n);e.fetchMetrics=F.renderOpts.fetchMetrics;let l=F.renderOpts.pendingWaitUntil;l&&a.waitUntil&&(a.waitUntil(l),l=void 0);let d=F.renderOpts.collectedTags;if(!j)return await (0,m.sendResponse)(B,G,i,F.renderOpts.pendingWaitUntil),null;{let e=await i.blob(),t=(0,h.toNodeOutgoingHttpHeaders)(i.headers);d&&(t[f.NEXT_CACHE_TAGS_HEADER]=d),!t["content-type"]&&e.type&&(t["content-type"]=e.type);let r=void 0!==F.renderOpts.collectedRevalidate&&!(F.renderOpts.collectedRevalidate>=f.INFINITE_CACHE)&&F.renderOpts.collectedRevalidate,a=void 0===F.renderOpts.collectedExpire||F.renderOpts.collectedExpire>=f.INFINITE_CACHE?void 0:F.renderOpts.collectedExpire;return{value:{kind:w.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 b.onRequestError(e,t,{routerKind:"App Router",routePath:R,routeType:"route",revalidateReason:(0,c.getRevalidateReason)({isStaticGeneration:$,isOnDemandRevalidate:_})},I),t}},u=await b.handleResponse({req:e,nextConfig:P,cacheKey:M,routeKind:r.RouteKind.APP_ROUTE,isFallback:!1,prerenderManifest:k,isRoutePPREnabled:!1,isOnDemandRevalidate:_,revalidateOnlyGenerated:N,responseGenerator:d,waitUntil:a.waitUntil,isMinimalMode:s});if(!j)return null;if((null==u||null==(i=u.value)?void 0:i.kind)!==w.CachedRouteKind.APP_ROUTE)throw Object.defineProperty(Error(`Invariant: app-route received invalid cache entry ${null==u||null==(l=u.value)?void 0:l.kind}`),"__NEXT_ERROR_CODE",{value:"E701",enumerable:!1,configurable:!0});s||t.setHeader("x-nextjs-cache",_?"REVALIDATED":u.isMiss?"MISS":u.isStale?"STALE":"HIT"),A&&t.setHeader("Cache-Control","private, no-cache, no-store, max-age=0, must-revalidate");let p=(0,h.fromNodeOutgoingHttpHeaders)(u.value.headers);return s&&j||p.delete(f.NEXT_CACHE_TAGS_HEADER),!u.cacheControl||t.getHeader("Cache-Control")||p.get("Cache-Control")||p.set("Cache-Control",(0,g.getCacheControlHeader)(u.cacheControl)),await (0,m.sendResponse)(B,G,new Response(u.value.body,{headers:p,status:u.value.status||200})),null};K?await l(K):await z.withPropagatedContext(e.headers,()=>z.trace(p.BaseServerSpan.handleRequest,{spanName:`${D} ${R}`,kind:i.SpanKind.SERVER,attributes:{"http.method":D,"http.target":e.url}},l))}catch(t){if(t instanceof x.NoFallbackError||await b.onRequestError(e,t,{routerKind:"App Router",routePath:T,routeType:"route",revalidateReason:(0,c.getRevalidateReason)({isStaticGeneration:$,isOnDemandRevalidate:_})}),j)throw t;return await (0,m.sendResponse)(B,G,new Response(null,{status:500})),null}}e.s(["handler",()=>S,"patchFetch",()=>N,"routeModule",()=>b,"serverHooks",()=>_,"workAsyncStorage",()=>k,"workUnitAsyncStorage",()=>I],52783)}];

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