import { get } from 'svelte/store'; import { activeHost } from '$lib/stores/hosts'; import type { ProcessDetail } from '$lib/types/metrics'; function getApiBase(): string { const host = get(activeHost); const baseUrl = host.isLocal ? '' : host.url; return `${baseUrl}/api/v1`; } export async function getProcessDetail(pid: number): Promise { const response = await fetch(`${getApiBase()}/processes/${pid}`); if (!response.ok) { throw new Error(`Failed to fetch process ${pid}: ${response.statusText}`); } return response.json(); } export interface SignalResult { success: boolean; message: string; } export async function sendSignal(pid: number, signal: number): Promise { const response = await fetch(`${getApiBase()}/processes/${pid}/signal`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ signal }) }); return response.json(); } // Common signal constants export const SIGNALS = { SIGTERM: 15, // Graceful termination SIGKILL: 9, // Force kill SIGSTOP: 19, // Pause process SIGCONT: 18 // Resume process } as const;