"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:()=>h,patchFetch:()=>v,requestAsyncStorage:()=>q,routeModule:()=>k,serverHooks:()=>m,staticGenerationAsyncStorage:()=>g});var t={};s.r(t),s.d(t,{POST:()=>f});var o=s(49303),i=s(88716),n=s(60670),l=s(87070),u=s(97425),a=s(75748),p=s(55837),d=s(10927),c=s(68507),x=s(83513);async function f(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=[],f=!1;for(let e of i){let t=o.getTool(e);if(await t.isRunning(r.id)){f=!0;let i=t.getSessionName(r.id);await (0,d.AJ)(i)&&(n.push(i),console.log(`[kill-session] Killed ${e} session: ${i}`)),o.stopPollers(r.id,e),(0,a.j8)(s,r.id,e)}}if(!f){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,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 console.error("Error killing sessions:",e),l.NextResponse.json({error:"Failed to kill sessions"},{status:500})}}let k=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:q,staticGenerationAsyncStorage:g,serverHooks:m}=k,h="/api/worktrees/[id]/kill-session/route";function v(){return(0,n.patchFetch)({serverHooks:m,staticGenerationAsyncStorage:g})}}};var r=require("../../../../../webpack-runtime.js");r.C(e);var s=e=>r(r.s=e),t=r.X(0,[8948,5972,3853,4893,7425,7566,4952],()=>s(38877));module.exports=t})();