"use strict";(()=>{var e={};e.id=2238,e.ids=[2238],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")},38877:(e,r,s)=>{s.r(r),s.d(r,{originalPathname:()=>v,patchFetch:()=>j,requestAsyncStorage:()=>g,routeModule:()=>q,serverHooks:()=>h,staticGenerationAsyncStorage:()=>m});var t={};s.r(t),s.d(t,{POST:()=>k});var o=s(49303),i=s(88716),n=s(60670),l=s(87070),u=s(94925),a=s(30721),p=s(55837),d=s(85930),c=s(11425),x=s(83513);let f=(0,s(43895).h)("api/kill-session");async function k(e,{params:r}){try{let s=(0,u.getDbInstance)();if(!(0,a.gU)(s,r.id))return l.NextResponse.json({error:`Worktree '${r.id}' not found`},{status:404});let t=e.nextUrl.searchParams.get("cliTool");if(t&&!x.tK.includes(t))return l.NextResponse.json({error:`Invalid cliTool: '${t}'. Valid values: ${x.tK.join(", ")}`},{status:400});let o=p.g.getInstance(),i=t?[t]:[...x.tK],n=[],k=!1;for(let e of i){let t=o.getTool(e);if(await t.isRunning(r.id)){k=!0;let i=t.getSessionName(r.id);await (0,d.AJ)(i)&&(n.push(i),f.info("killed-session:")),o.stopPollers(r.id,e),(0,a.j8)(s,r.id,e)}}if(!k){let e=t?` for ${t}`:"";return l.NextResponse.json({error:`No active sessions found${e} for this worktree`},{status:404})}return t?(0,a.GZ)(s,r.id,t):(0,a.HE)(s,r.id),(0,a.Aq)(s,r.id),(0,c.fM)(r.id,{type:"session_status_changed",worktreeId:r.id,isRunning:!1,messagesCleared:!0,cliTool:t||null}),l.NextResponse.json({success:!0,message:t?`Session killed successfully: ${n.join(", ")}`:`All sessions killed successfully: ${n.join(", ")}`,killedSessions:n,cliTool:t||null},{status:200})}catch(e){return f.error("error-killing-sessions:",{error:e instanceof Error?e.message:String(e)}),l.NextResponse.json({error:"Failed to kill sessions"},{status:500})}}let q=new o.AppRouteRouteModule({definition:{kind:i.x.APP_ROUTE,page:"/api/worktrees/[id]/kill-session/route",pathname:"/api/worktrees/[id]/kill-session",filename:"route",bundlePath:"app/api/worktrees/[id]/kill-session/route"},resolvedPagePath:"/home/runner/work/CommandMate/CommandMate/src/app/api/worktrees/[id]/kill-session/route.ts",nextConfigOutput:"",userland:t}),{requestAsyncStorage:g,staticGenerationAsyncStorage:m,serverHooks:h}=q,v="/api/worktrees/[id]/kill-session/route";function j(){return(0,n.patchFetch)({serverHooks:h,staticGenerationAsyncStorage:m})}}};var r=require("../../../../../webpack-runtime.js");r.C(e);var s=e=>r(r.s=e),t=r.X(0,[8948,5972,3853,4893,3895,4925,721,9228],()=>s(38877));module.exports=t})();