"use strict";(()=>{var e={};e.id=4720,e.ids=[4720],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")},84770:e=>{e.exports=require("crypto")},92048:e=>{e.exports=require("fs")},19801:e=>{e.exports=require("os")},55315:e=>{e.exports=require("path")},90783:(e,t,a)=>{a.r(t),a.d(t,{originalPathname:()=>m,patchFetch:()=>b,requestAsyncStorage:()=>_,routeModule:()=>u,serverHooks:()=>E,staticGenerationAsyncStorage:()=>w});var r={};a.r(r),a.d(r,{GET:()=>h,dynamic:()=>l});var n=a(49303),o=a(88716),p=a(60670),s=a(87070),i=a(97425),d=a(51172);let l="force-dynamic";async function c(e,t){let a=`http://${e}:${t}/`,r=Date.now();try{let e=new AbortController,t=setTimeout(()=>e.abort(),5e3);await fetch(a,{method:"HEAD",signal:e.signal}),clearTimeout(t);let n=Date.now()-r;return{healthy:!0,responseTime:n}}catch(t){let e=Date.now()-r;if(t instanceof Error){if("AbortError"===t.name)return{healthy:!1,responseTime:e,error:"Connection timeout"};return{healthy:!1,responseTime:e,error:t.message}}return{healthy:!1,responseTime:e,error:"Unknown error"}}}async function h(e,{params:t}){try{let{id:e}=await t,a=(0,i.n)(),r=(0,d.JF)(a,e);if(!r)return s.NextResponse.json({error:`External app not found: ${e}`},{status:404});let n=await c(r.targetHost,r.targetPort),o={id:r.id,healthy:n.healthy,responseTime:n.responseTime,lastChecked:Date.now(),error:n.error};return s.NextResponse.json({health:o},{status:200})}catch(e){return console.error("Error checking external app health:",e),s.NextResponse.json({error:"Failed to check external app health"},{status:500})}}let u=new n.AppRouteRouteModule({definition:{kind:o.x.APP_ROUTE,page:"/api/external-apps/[id]/health/route",pathname:"/api/external-apps/[id]/health",filename:"route",bundlePath:"app/api/external-apps/[id]/health/route"},resolvedPagePath:"/home/runner/work/CommandMate/CommandMate/src/app/api/external-apps/[id]/health/route.ts",nextConfigOutput:"",userland:r}),{requestAsyncStorage:_,staticGenerationAsyncStorage:w,serverHooks:E}=u,m="/api/external-apps/[id]/health/route";function b(){return(0,p.patchFetch)({serverHooks:E,staticGenerationAsyncStorage:w})}},51172:(e,t,a)=>{a.d(t,{F1:()=>i,J6:()=>h,JF:()=>s,j6:()=>p,ke:()=>d,uz:()=>l,vV:()=>c});var r=a(84770);class n extends Error{constructor(e,t,a){super(e),this.code=t,this.cause=a,this.name="ExternalAppDbError"}}function o(e){return{id:e.id,name:e.name,displayName:e.display_name,description:e.description??void 0,pathPrefix:e.path_prefix,targetPort:e.target_port,targetHost:e.target_host,appType:e.app_type,websocketEnabled:1===e.websocket_enabled,websocketPathPattern:e.websocket_path_pattern??void 0,enabled:1===e.enabled,createdAt:e.created_at,updatedAt:e.updated_at}}function p(e,t){let a=(0,r.randomUUID)(),o=Date.now(),p={name:t.name,display_name:t.displayName,description:t.description??null,path_prefix:t.pathPrefix,target_port:t.targetPort,target_host:t.targetHost??"localhost",app_type:t.appType,websocket_enabled:t.websocketEnabled?1:0,websocket_path_pattern:t.websocketPathPattern??null};try{return e.prepare(`
      INSERT INTO external_apps (
        id, name, display_name, description, path_prefix,
        target_port, target_host, app_type,
        websocket_enabled, websocket_path_pattern,
        enabled, created_at, updated_at
      )
      VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, ?, ?)
    `).run(a,p.name,p.display_name,p.description,p.path_prefix,p.target_port,p.target_host,p.app_type,p.websocket_enabled,p.websocket_path_pattern,o,o),{id:a,name:t.name,displayName:t.displayName,description:t.description,pathPrefix:t.pathPrefix,targetPort:t.targetPort,targetHost:t.targetHost??"localhost",appType:t.appType,websocketEnabled:t.websocketEnabled??!1,websocketPathPattern:t.websocketPathPattern,enabled:!0,createdAt:o,updatedAt:o}}catch(e){if(e instanceof Error&&e.message.includes("UNIQUE constraint"))throw new n(`External app with name "${t.name}" or pathPrefix "${t.pathPrefix}" already exists`,"DUPLICATE",e);throw new n(`Failed to create external app: ${e instanceof Error?e.message:"Unknown error"}`,"DB_ERROR",e instanceof Error?e:void 0)}}function s(e,t){try{let a=e.prepare(`
      SELECT id, name, display_name, description, path_prefix,
             target_port, target_host, app_type,
             websocket_enabled, websocket_path_pattern,
             enabled, created_at, updated_at
      FROM external_apps
      WHERE id = ?
    `).get(t);if(!a)return null;return o(a)}catch(e){throw new n(`Failed to get external app by ID: ${e instanceof Error?e.message:"Unknown error"}`,"DB_ERROR",e instanceof Error?e:void 0)}}function i(e,t){try{let a=e.prepare(`
      SELECT id, name, display_name, description, path_prefix,
             target_port, target_host, app_type,
             websocket_enabled, websocket_path_pattern,
             enabled, created_at, updated_at
      FROM external_apps
      WHERE path_prefix = ?
    `).get(t);if(!a)return null;return o(a)}catch(e){throw new n(`Failed to get external app by path prefix: ${e instanceof Error?e.message:"Unknown error"}`,"DB_ERROR",e instanceof Error?e:void 0)}}function d(e){try{return e.prepare(`
      SELECT id, name, display_name, description, path_prefix,
             target_port, target_host, app_type,
             websocket_enabled, websocket_path_pattern,
             enabled, created_at, updated_at
      FROM external_apps
      ORDER BY name ASC
    `).all().map(o)}catch(e){throw new n(`Failed to get all external apps: ${e instanceof Error?e.message:"Unknown error"}`,"DB_ERROR",e instanceof Error?e:void 0)}}function l(e,t,a){if(!s(e,t))throw new n(`External app not found: ${t}`,"NOT_FOUND");try{let r=Date.now(),n=["updated_at = ?"],o=[r];return void 0!==a.displayName&&(n.push("display_name = ?"),o.push(a.displayName)),void 0!==a.description&&(n.push("description = ?"),o.push(a.description)),void 0!==a.targetPort&&(n.push("target_port = ?"),o.push(a.targetPort)),void 0!==a.targetHost&&(n.push("target_host = ?"),o.push(a.targetHost)),void 0!==a.websocketEnabled&&(n.push("websocket_enabled = ?"),o.push(a.websocketEnabled?1:0)),void 0!==a.websocketPathPattern&&(n.push("websocket_path_pattern = ?"),o.push(a.websocketPathPattern)),void 0!==a.enabled&&(n.push("enabled = ?"),o.push(a.enabled?1:0)),o.push(t),e.prepare(`
      UPDATE external_apps
      SET ${n.join(", ")}
      WHERE id = ?
    `).run(...o),s(e,t)}catch(e){if(e instanceof n)throw e;throw new n(`Failed to update external app: ${e instanceof Error?e.message:"Unknown error"}`,"DB_ERROR",e instanceof Error?e:void 0)}}function c(e,t){try{e.prepare(`
      DELETE FROM external_apps
      WHERE id = ?
    `).run(t)}catch(e){throw new n(`Failed to delete external app: ${e instanceof Error?e.message:"Unknown error"}`,"DB_ERROR",e instanceof Error?e:void 0)}}function h(e,t){try{let a=`
      SELECT id, name, display_name, description, path_prefix,
             target_port, target_host, app_type,
             websocket_enabled, websocket_path_pattern,
             enabled, created_at, updated_at, issue_no
      FROM external_apps
      WHERE enabled = 1
    `,r=[];t?.issueNo===null?a+=" AND issue_no IS NULL":t?.issueNo!==void 0&&(a+=" AND issue_no = ?",r.push(t.issueNo)),a+=" ORDER BY name ASC";let n=e.prepare(a);return(r.length>0?n.all(...r):n.all()).map(o)}catch(e){throw new n(`Failed to get enabled external apps: ${e instanceof Error?e.message:"Unknown error"}`,"DB_ERROR",e instanceof Error?e:void 0)}}}};var t=require("../../../../../webpack-runtime.js");t.C(e);var a=e=>t(t.s=e),r=t.X(0,[8948,5972,7425],()=>a(90783));module.exports=r})();