"use strict";(()=>{var e={};e.id=4331,e.ids=[4331],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")},399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},4770:e=>{e.exports=require("crypto")},7135:(e,t,a)=>{a.r(t),a.d(t,{originalPathname:()=>S,patchFetch:()=>N,requestAsyncStorage:()=>x,routeModule:()=>y,serverHooks:()=>D,staticGenerationAsyncStorage:()=>v});var n={};a.r(n),a.d(n,{POST:()=>f,maxDuration:()=>k});var o=a(9303),i=a(8716),r=a(670),s=a(7070),u=a(5655),l=a(2822),p=a(6097),c=a(2582),m=a(1789),d=a(7939),g=a(987),h=a(4437);let k=60,b={"1:1":"Square (1:1)","16:9":"Landscape (16:9)","9:16":"Portrait / Reels (9:16)","4:3":"Standard (4:3)","3:4":"Portrait (3:4)"};async function f(e){try{let t,a;if(!(0,g._)(e))return s.NextResponse.json((0,g.E)(),{status:403});let n=(0,u.e)(),{data:{user:o},error:i}=await n.auth.getUser();if(i||!o)return s.NextResponse.json({success:!1,error:"Unauthorized"},{status:401});let r=await (0,p.D)(o.id);if(!r.allowed)return s.NextResponse.json({success:!1,error:"Rate limit exceeded. Coba lagi dalam 1 menit."},{status:429});let k=await (0,c.Sb)(n,o.id);if(!(0,c.q9)(k))return s.NextResponse.json({success:!1,error:"Belum ada AI API key. Tambahkan di Settings → API Keys.",redirectTo:"/settings"},{status:402});let f=await (0,m.T)(n,o.id,1);if("quota_exceeded"===f)return s.NextResponse.json({success:!1,error:"Kuota habis. Upgrade plan untuk lebih banyak generasi."},{status:403});let{scenes:y=[],style:x="cinematic",language:v="id",aspectRatio:D="16:9",quality:S="hd",extraContext:N=""}=await e.json();if(!Array.isArray(y)||0===y.length)return s.NextResponse.json({success:!1,error:"Scenes tidak boleh kosong."},{status:400});if(y.length>20)return s.NextResponse.json({success:!1,error:"Maksimal 20 scene per request."},{status:400});let j=h.bQ[x],A="id"===v?"Bahasa Indonesia":"English",P=b[D]??D,R=y.map(e=>JSON.stringify({sceneNumber:e.sceneNumber,title:e.title,narration:e.narration,visualDescription:e.visualDescription,cameraAngle:e.cameraAngle??null,emotion:e.emotion??null,duration:e.duration})).join("\n"),T=`You are a world-class AI image prompt engineer specializing in GPT Image (DALL-E 3 / gpt-image-2) prompts for cinematic storyboard visualization.

Your task: given a list of storyboard scenes, generate ONE highly detailed image generation prompt per scene that is optimized for GPT Image.

RULES:
1. Each prompt must be self-contained — include subject, composition, lighting, color palette, style, and mood
2. Be specific about visual elements: textures, depth of field, lens type, time of day, atmosphere
3. Do NOT include motion or time-based language ("moving", "transitioning", "pan") — these are STILL images
4. Mirror the storyboard style: ${j?.label??x} — ${j?.description??""}
5. Aspect ratio context: ${P} — frame composition accordingly
6. Quality target: ${"hd"===S?"ultra high detail, photorealistic or high-fidelity illustration":"clean, balanced composition"}
7. Output MUST be valid JSON — no text outside the JSON block
8. "compositionNote" and "colorMood" should be in ${A}; "prompt" and "negativeHint" in English
${N?`9. Storyboard context: ${N}`:""}

OUTPUT FORMAT:
{
  "scenePrompts": [
    {
      "sceneNumber": 1,
      "title": "scene title here",
      "prompt": "Full detailed image prompt in English, optimized for GPT Image...",
      "negativeHint": "Elements to avoid (not an official DALL-E param — note for reference): ...",
      "compositionNote": "Catatan singkat tentang komposisi dan sudut kamera dalam ${A}",
      "colorMood": "Palet warna dan mood dominan dalam ${A}"
    }
  ]
}`,C=`Generate GPT Image prompts for each of the following ${y.length} storyboard scenes.
Style: ${j?.label??x}
Aspect Ratio: ${P}
Quality: ${S}

SCENES:
${R}

Important: Return EXACTLY ${y.length} prompts, one per scene, in the same order.`,w="",E="unknown",$="unknown",I=null;for(let e=0;e<=2;e++)try{let e=await (0,l.SN)([{role:"system",content:T},{role:"user",content:C}],{temperature:.75,maxTokens:8e3},k);w=e.content,E=e.model,$=e.provider,t=e.usage,I=null;break}catch(t){I=t,e<2&&await new Promise(t=>setTimeout(t,1e3*(e+1)))}if(I)return s.NextResponse.json({success:!1,error:I.message},{status:500});try{let e=w.replace(/^```(?:json)?\s*/i,"").replace(/\s*```$/i,"").trim();a=JSON.parse(e)}catch{let e=w.match(/\{[\s\S]*\}/);if(!e)return s.NextResponse.json({success:!1,error:"AI menghasilkan output tidak valid. Coba lagi."},{status:500});try{a=JSON.parse(e[0])}catch{return s.NextResponse.json({success:!1,error:"Gagal memparse output AI. Coba lagi."},{status:500})}}if(!Array.isArray(a.scenePrompts)||0===a.scenePrompts.length)return s.NextResponse.json({success:!1,error:"AI tidak mengembalikan prompt yang valid. Coba lagi."},{status:500});let q=a.scenePrompts.map(e=>({...e,aspectRatio:D,quality:S})),O={scenePrompts:q,storyboardStyle:x,metadata:{generatedAt:new Date().toISOString(),model:`${$}/${E}`,aspectRatio:D,quality:S,totalScenes:q.length}},_=(0,d.n)($,E,t??null);return t&&await n.from("usage_logs").insert({user_id:o.id,action:"gptimage_prompts",platform:"storyboard",metadata:{model:E,provider:$,scene_count:q.length,aspect_ratio:D,quality:S},prompt_tokens:t.promptTokens,completion_tokens:t.completionTokens,total_tokens:t.totalTokens,estimated_cost_usd:_}),s.NextResponse.json({success:!0,data:O},{headers:{"X-RateLimit-Remaining":String(r.remaining)}})}catch(e){return console.error("[gptimage-prompts]",e),s.NextResponse.json({success:!1,error:"Internal server error"},{status:500})}}let y=new o.AppRouteRouteModule({definition:{kind:i.x.APP_ROUTE,page:"/api/storyboard/gptimage-prompts/route",pathname:"/api/storyboard/gptimage-prompts",filename:"route",bundlePath:"app/api/storyboard/gptimage-prompts/route"},resolvedPagePath:"/home/user/.workspace/projects/promptmotion-ai/src/app/api/storyboard/gptimage-prompts/route.ts",nextConfigOutput:"",userland:n}),{requestAsyncStorage:x,staticGenerationAsyncStorage:v,serverHooks:D}=y,S="/api/storyboard/gptimage-prompts/route";function N(){return(0,r.patchFetch)({serverHooks:D,staticGenerationAsyncStorage:v})}},7939:(e,t,a)=>{a.d(t,{n:()=>i});let n={"gpt-4o-mini":{input:15e-5,output:6e-4},"gpt-4o":{input:.005,output:.015},"gpt-4o-2024-11-20":{input:.0025,output:.01},"claude-3-haiku-20240307":{input:25e-5,output:.00125},"claude-3-5-haiku-20241022":{input:8e-4,output:.004},"claude-3-5-sonnet-20240620":{input:.003,output:.015},"claude-3-5-sonnet-20241022":{input:.003,output:.015},"gemini-1.5-flash":{input:75e-6,output:3e-4},"gemini-1.5-pro":{input:.00125,output:.005},"gemini-2.0-flash":{input:1e-4,output:4e-4},"gemini-2.5-flash":{input:15e-5,output:6e-4},"agentrouter/claude-3-haiku-20240307":{input:22e-5,output:.0011},"agentrouter/claude-3-5-haiku-20241022":{input:7e-4,output:.0035},"agentrouter/claude-3-5-sonnet-20240620":{input:.0028,output:.014},"agentrouter/claude-3-5-sonnet-20241022":{input:.0028,output:.014},"agentrouter/gpt-4o-mini":{input:14e-5,output:55e-5},"agentrouter/gpt-4o":{input:.0045,output:.014},"agentrouter/gemini-1.5-flash":{input:7e-5,output:28e-5},"agentrouter/gemini-2.0-flash":{input:95e-6,output:38e-5},"agentrouter/deepseek-chat":{input:27e-5,output:.0011},"agentrouter/deepseek-reasoner":{input:55e-5,output:.00219}},o={input:.001,output:.002};function i(e,t,a){if(!a)return null;let i=n["agentrouter"===e?`agentrouter/${t}`:t]??o;return a.promptTokens/1e3*i.input+a.completionTokens/1e3*i.output}},4437:(e,t,a)=>{a.d(t,{Mx:()=>i,bQ:()=>n,eQ:()=>r,qP:()=>o});let n={cinematic:{label:"Cinematic",icon:"\uD83C\uDFAC",description:"Dramatis, sinematik, nuansa film"},documentary:{label:"Dokumenter",icon:"\uD83D\uDCF9",description:"Faktual, informatif, terstruktur"},social_media:{label:"Social Media",icon:"\uD83D\uDCF1",description:"Singkat, catchy, viral-ready"},ugc:{label:"UGC",icon:"\uD83E\uDD33",description:"Kasual, autentik, user-generated feel"},explainer:{label:"Explainer",icon:"\uD83D\uDCA1",description:"Edukatif, jelas, step-by-step"},emotional:{label:"Emotional",icon:"\uD83D\uDC96",description:"Menyentuh hati, penuh empati"},humorous:{label:"Humoris",icon:"\uD83D\uDE04",description:"Ringan, lucu, menghibur"}},o={short:{label:"Pendek",scenes:"3–5 scene",duration:"15–30 detik",count:[3,5]},medium:{label:"Sedang",scenes:"6–9 scene",duration:"30–60 detik",count:[6,9]},long:{label:"Panjang",scenes:"10–15 scene",duration:"1–3 menit",count:[10,15]},custom:{label:"Custom",scenes:"kamu tentukan",duration:"kamu tentukan"}},i={"2-3s":{label:"2–3 detik",value:"2-3 detik"},"3-5s":{label:"3–5 detik",value:"3-5 detik"},"5-8s":{label:"5–8 detik",value:"5-8 detik"},"8-12s":{label:"8–12 detik",value:"8-12 detik"},custom:{label:"Custom",value:""}},r={"15s":{label:"15 detik",value:"15 detik"},"30s":{label:"30 detik",value:"30 detik"},"60s":{label:"60 detik",value:"60 detik"},"90s":{label:"90 detik",value:"90 detik"},"3min":{label:"3 menit",value:"3 menit"},"5min":{label:"5 menit",value:"5 menit"},custom:{label:"Custom",value:""}}}};var t=require("../../../../webpack-runtime.js");t.C(e);var a=e=>t(t.s=e),n=t.X(0,[9276,6164,5972,3454],()=>a(7135));module.exports=n})();