From e08341dab3bb10e26a64eb44cbebd2d507087b03 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Wed, 4 Mar 2026 15:51:03 -0600 Subject: [PATCH] enh: ot ports --- src/lib/apis/terminal/index.ts | 23 +++ .../components/chat/FileNav/PortList.svelte | 141 ++++++++++++++++++ 2 files changed, 164 insertions(+) create mode 100644 src/lib/components/chat/FileNav/PortList.svelte diff --git a/src/lib/apis/terminal/index.ts b/src/lib/apis/terminal/index.ts index aa99810753..b1a0e7acf9 100644 --- a/src/lib/apis/terminal/index.ts +++ b/src/lib/apis/terminal/index.ts @@ -5,6 +5,12 @@ export type FileEntry = { modified?: number; }; +export type ListeningPort = { + port: number; + pid: number | null; + process: string | null; +}; + export type TerminalFeatures = { terminal?: boolean; }; @@ -235,3 +241,20 @@ export const moveEntry = async ( }); return res; }; + +export const getListeningPorts = async ( + baseUrl: string, + apiKey: string +): Promise => { + const url = `${baseUrl.replace(/\/$/, '')}/ports`; + const res = await fetch(url, { + headers: { Authorization: `Bearer ${apiKey}` } + }).catch(() => null); + if (!res || !res.ok) return []; + const json = await res.json().catch(() => null); + return json?.ports ?? []; +}; + +export const getPortProxyUrl = (baseUrl: string, port: number, path: string = ''): string => { + return `${baseUrl.replace(/\/$/, '')}/proxy/${port}/${path}`; +}; diff --git a/src/lib/components/chat/FileNav/PortList.svelte b/src/lib/components/chat/FileNav/PortList.svelte new file mode 100644 index 0000000000..609ce9f0b4 --- /dev/null +++ b/src/lib/components/chat/FileNav/PortList.svelte @@ -0,0 +1,141 @@ + + +
+ + + + + + {#if expanded} +
+ {#if ports.length === 0} +
+ {$i18n.t('No servers detected')} +
+ {:else} + {#each ports as port} + + {/each} + {/if} +
+ {/if} +