"use strict";(()=>{var e={};e.id=9607,e.ids=[9607],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")},1577:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>m,patchFetch:()=>g,requestAsyncStorage:()=>d,routeModule:()=>p,serverHooks:()=>f,staticGenerationAsyncStorage:()=>h});var a={};r.r(a),r.d(a,{POST:()=>l});var s=r(9303),n=r(8716),o=r(670),i=r(7070),u=r(5655),c=r(1211);async function l(e){let t;let r=(0,u.e)(),{data:{user:a}}=await r.auth.getUser();if(!a)return i.NextResponse.json({error:"Unauthorized"},{status:401});let{key:s}=await e.json();if(!s)return i.NextResponse.json({error:"Key diperlukan"},{status:400});let{data:n,error:o}=await r.from("env_vars").select("id, encrypted_value").eq("user_id",a.id).eq("key",s).eq("is_active",!0).single();if(o||!n)return i.NextResponse.json({success:!1,error:"Key tidak ditemukan atau tidak aktif"});try{t=(0,c.pe)(n.encrypted_value)}catch{return i.NextResponse.json({success:!1,error:"Gagal dekripsi — ENCRYPTION_SECRET mungkin berubah"})}try{let e={success:!1};if("OPENAI_API_KEY"===s){let r=await fetch("https://api.openai.com/v1/models",{headers:{Authorization:`Bearer ${t}`}});if(!r.ok)throw Error(`HTTP ${r.status}`);let a=await r.json();e={success:!0,info:`${a.data.length} model tersedia`}}else if("ANTHROPIC_API_KEY"===s){let r=await fetch("https://api.anthropic.com/v1/messages",{method:"POST",headers:{"x-api-key":t,"anthropic-version":"2023-06-01","Content-Type":"application/json"},body:JSON.stringify({model:"claude-3-haiku-20240307",max_tokens:1,messages:[{role:"user",content:"hi"}]})});if(200!==r.status&&400!==r.status)throw Error(`HTTP ${r.status}`);e={success:!0,info:"Anthropic API key valid"}}else if("GOOGLE_AI_API_KEY"===s){let r=await fetch(`https://generativelanguage.googleapis.com/v1beta/models?key=${t}`);if(!r.ok)throw Error(`HTTP ${r.status}`);let a=await r.json();e={success:!0,info:`${a.models?.length??0} model tersedia`}}else if("AGENTROUTER_API_KEY"===s){let r=await fetch("https://agentrouter.org/v1/models",{headers:{Authorization:`Bearer ${t}`,"HTTP-Referer":"https://promptmotion.ai","X-Title":"PromptMotion AI"}});if(!r.ok)throw Error(`HTTP ${r.status} — key mungkin invalid atau expired`);let a=await r.json(),s=Array.isArray(a.data)?a.data.length:"?";e={success:!0,info:`AgentRouter key valid — ${s} model tersedia`}}else e={success:!0,info:"Value berhasil didekripsi"};return await r.from("env_vars").update({last_used_at:new Date().toISOString()}).eq("id",n.id),i.NextResponse.json(e)}catch(e){return i.NextResponse.json({success:!1,error:e.message})}}let p=new s.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/env-vars/test/route",pathname:"/api/env-vars/test",filename:"route",bundlePath:"app/api/env-vars/test/route"},resolvedPagePath:"/home/user/.workspace/projects/promptmotion-ai/src/app/api/env-vars/test/route.ts",nextConfigOutput:"",userland:a}),{requestAsyncStorage:d,staticGenerationAsyncStorage:h,serverHooks:f}=p,m="/api/env-vars/test/route";function g(){return(0,o.patchFetch)({serverHooks:f,staticGenerationAsyncStorage:h})}},1211:(e,t,r)=>{r.d(t,{HI:()=>o,in:()=>u,pe:()=>i});var a=r(4770);let s="aes-256-gcm";function n(){let e=process.env.ENCRYPTION_SECRET;if(!e)throw Error("ENCRYPTION_SECRET tidak ditemukan di environment variables. Tambahkan ke .env.local: ENCRYPTION_SECRET=<random-64-char-string>");return(0,a.createHash)("sha256").update(e).digest()}function o(e){let t=n(),r=(0,a.randomBytes)(12),o=(0,a.createCipheriv)(s,t,r),i=Buffer.concat([o.update(e,"utf8"),o.final()]),u=o.getAuthTag();return Buffer.concat([r,u,i]).toString("base64")}function i(e){let t=n(),r=Buffer.from(e,"base64");if(r.length<28)throw Error("Ciphertext terlalu pendek atau corrupt");let o=r.subarray(0,12),i=r.subarray(12,28),u=r.subarray(28),c=(0,a.createDecipheriv)(s,t,o);return c.setAuthTag(i),Buffer.concat([c.update(u),c.final()]).toString("utf8")}function u(e){if(!e||e.length<6)return"••••••";let t=Math.min(4,Math.floor(.1*e.length));return"•".repeat(e.length-t)+e.slice(-t)}},5655:(e,t,r)=>{r.d(t,{e:()=>n});var a=r(5238),s=r(1615);function n(){let e=(0,s.cookies)();return(0,a.l)("https://dummy.supabase.co","eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.dummy",{cookies:{getAll:()=>e.getAll(),setAll(t){try{t.forEach(({name:t,value:r,options:a})=>e.set(t,r,a))}catch{}}}})}}};var t=require("../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),a=t.X(0,[9276,6164,5972],()=>r(1577));module.exports=a})();