"use strict";(()=>{var e={};e.id=4230,e.ids=[4230],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")},1464:(e,r,t)=>{t.r(r),t.d(r,{originalPathname:()=>j,patchFetch:()=>R,requestAsyncStorage:()=>w,routeModule:()=>f,serverHooks:()=>h,staticGenerationAsyncStorage:()=>q});var s={};t.r(s),t.d(s,{POST:()=>g});var o=t(49303),n=t(88716),a=t(60670),i=t(87070),p=t(97425),u=t(75748),d=t(10927),l=t(97213),m=t(59991),c=t(63661),x=t(25079);async function g(e,{params:r}){try{let t;let{messageId:s,answer:o}=await e.json();if(!s||!o)return i.NextResponse.json({error:"messageId and answer are required"},{status:400});let n=(0,p.n)(),a=(0,u.S$)(n,s);if(!a)return i.NextResponse.json({error:"Message not found"},{status:404});if("prompt"!==a.messageType)return i.NextResponse.json({error:"Message is not a prompt"},{status:400});if(!a.promptData)return i.NextResponse.json({error:"Prompt data not found"},{status:400});if("answered"===a.promptData.status)return i.NextResponse.json({error:"Prompt already answered"},{status:400});if("multiple_choice"===a.promptData.type){let e=parseInt(o,10);if(isNaN(e))t=o;else{let r=a.promptData.options.map(e=>e.number);if(!r.includes(e))return i.NextResponse.json({error:`Invalid choice: ${o}. Valid options are: ${r.join(", ")}`},{status:400});t=e.toString()}}else try{t=(0,c.J)(o,a.promptData.type)}catch(r){let e=r instanceof Error?r.message:"Unknown error";return i.NextResponse.json({error:`Invalid answer: ${e}`},{status:400})}let g={...a.promptData,status:"answered",answer:o,answeredAt:new Date().toISOString()};(0,u.GA)(n,s,g);let f=(0,u.gU)(n,r.id);if(!f)return i.NextResponse.json({error:`Worktree '${r.id}' not found`},{status:404});let w=a.cliToolId||f.cliToolId||"claude",q=l.g.getInstance().getTool(w),h=q.getSessionName(r.id);try{await (0,d.Is)(h,t,!1),console.log(`✓ Sent answer '${t}' to ${h} (${q.name})`),await new Promise(e=>setTimeout(e,100)),await (0,d.Is)(h,"",!0),console.log(`✓ Sent Enter to ${h}`)}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})}let j={...a,promptData:g};return(0,x.ps)("message_updated",{worktreeId:r.id,message:j}),(0,m.cn)(r.id,w),console.log(`✓ Resumed polling for ${r.id} (${w})`),i.NextResponse.json({success:!0,message:j})}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 f=new o.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/worktrees/[id]/respond/route",pathname:"/api/worktrees/[id]/respond",filename:"route",bundlePath:"app/api/worktrees/[id]/respond/route"},resolvedPagePath:"/home/runner/work/CommandMate/CommandMate/src/app/api/worktrees/[id]/respond/route.ts",nextConfigOutput:"",userland:s}),{requestAsyncStorage:w,staticGenerationAsyncStorage:q,serverHooks:h}=f,j="/api/worktrees/[id]/respond/route";function R(){return(0,a.patchFetch)({serverHooks:h,staticGenerationAsyncStorage:q})}}};var r=require("../../../../../webpack-runtime.js");r.C(e);var t=e=>r(r.s=e),s=r.X(0,[8948,5972,3853,4893,7425,7213,1528,9723],()=>t(1464));module.exports=s})();