"use strict";(()=>{var e={};e.id=6366,e.ids=[6366],e.modules={85890:e=>{e.exports=require("better-sqlite3")},20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},78893:e=>{e.exports=require("buffer")},61282:e=>{e.exports=require("child_process")},84770:e=>{e.exports=require("crypto")},17702:e=>{e.exports=require("events")},92048:e=>{e.exports=require("fs")},20629:e=>{e.exports=require("fs/promises")},32615:e=>{e.exports=require("http")},35240:e=>{e.exports=require("https")},98216:e=>{e.exports=require("net")},19801:e=>{e.exports=require("os")},55315:e=>{e.exports=require("path")},76162:e=>{e.exports=require("stream")},82452:e=>{e.exports=require("tls")},17360:e=>{e.exports=require("url")},21764:e=>{e.exports=require("util")},71568:e=>{e.exports=require("zlib")},45762:(e,r,t)=>{t.r(r),t.d(r,{originalPathname:()=>N,patchFetch:()=>j,requestAsyncStorage:()=>h,routeModule:()=>w,serverHooks:()=>k,staticGenerationAsyncStorage:()=>v});var o={};t.r(o),t.d(o,{POST:()=>g});var s=t(49303),n=t(88716),p=t(60670),i=t(87070),a=t(97425),u=t(75748),l=t(55837),d=t(83513),c=t(89194),m=t(63661),x=t(19377),f=t(49528),q=t(38693);async function g(e,{params:r}){try{if(!(0,q.m$)(r.id))return i.NextResponse.json({error:"Invalid worktree ID format"},{status:400});let{answer:t,cliTool:o,promptType:s,defaultOptionNumber:n}=await e.json();if(!t)return i.NextResponse.json({error:"answer is required"},{status:400});if(o&&!(0,d._7)(o))return i.NextResponse.json({error:`Invalid cliTool: '${o}'`},{status:400});let p=(0,a.getDbInstance)(),g=(0,u.gU)(p,r.id);if(!g)return i.NextResponse.json({error:`Worktree '${r.id}' not found`},{status:404});let w=o&&(0,d._7)(o)?o:g.cliToolId||"claude",h=l.g.getInstance().getTool(w);if(!await h.isRunning(r.id))return i.NextResponse.json({error:`${h.name} session is not running`},{status:400});let v=h.getSessionName(r.id),k=null;try{let e=await (0,c.NA)(r.id,w,5e3),o=(0,x.vp)(e),s=(0,x.Sg)(w);if(!(k=(0,m.F)((0,x.BN)(o),s)).isPrompt)return i.NextResponse.json({success:!1,reason:"prompt_no_longer_active",answer:t})}catch{console.warn("[prompt-response] Failed to verify prompt state, proceeding with send")}try{await (0,f.z)({sessionName:v,answer:t,cliToolId:w,promptData:k?.promptData,fallbackPromptType:s,fallbackDefaultOptionNumber:n})}catch(r){let e=r instanceof Error?r.message:"Unknown error";return i.NextResponse.json({error:`Failed to send answer to tmux: ${e}`},{status:500})}return i.NextResponse.json({success:!0,answer:t})}catch(r){console.error("Failed to respond to prompt:",r);let e=r instanceof Error?r.message:"Internal server error";return i.NextResponse.json({error:e},{status:500})}}let w=new s.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/worktrees/[id]/prompt-response/route",pathname:"/api/worktrees/[id]/prompt-response",filename:"route",bundlePath:"app/api/worktrees/[id]/prompt-response/route"},resolvedPagePath:"/home/runner/work/CommandMate/CommandMate/src/app/api/worktrees/[id]/prompt-response/route.ts",nextConfigOutput:"",userland:o}),{requestAsyncStorage:h,staticGenerationAsyncStorage:v,serverHooks:k}=w,N="/api/worktrees/[id]/prompt-response/route";function j(){return(0,p.patchFetch)({serverHooks:k,staticGenerationAsyncStorage:v})}}};var r=require("../../../../../webpack-runtime.js");r.C(e);var t=e=>r(r.s=e),o=r.X(0,[8948,5972,3853,4893,2509,7425,7566,4952,8693],()=>t(45762));module.exports=o})();