Update terminal panel

This commit is contained in:
MacRimi
2026-03-15 16:27:37 +01:00
parent 65add36b2f
commit 0d6d570ae8
4 changed files with 56 additions and 48 deletions

View File

@@ -26,7 +26,7 @@ import {
DropdownMenuLabel,
} from "@/components/ui/dropdown-menu"
import "@xterm/xterm/css/xterm.css"
import { getWebSocketUrl } from "@/lib/api-config"
import { API_PORT } from "@/lib/api-config"
interface WebInteraction {
type: "yesno" | "menu" | "msgbox" | "input" | "inputbox"
@@ -96,7 +96,7 @@ export function ScriptTerminalModal({
wsRef.current.close()
}
const wsUrl = getScriptWebSocketUrlLocal(sessionIdRef.current)
const wsUrl = getScriptWebSocketUrl(sessionIdRef.current)
const ws = new WebSocket(wsUrl)
wsRef.current = ws
@@ -259,7 +259,7 @@ export function ScriptTerminalModal({
}
}, 100)
const wsUrl = getScriptWebSocketUrlLocal(sessionIdRef.current)
const wsUrl = getScriptWebSocketUrl(sessionIdRef.current)
const ws = new WebSocket(wsUrl)
wsRef.current = ws
@@ -493,9 +493,20 @@ export function ScriptTerminalModal({
}
}, [isOpen, isComplete, attemptReconnect])
// Use centralized getWebSocketUrl from api-config
const getScriptWebSocketUrlLocal = (sid: string): string => {
return getWebSocketUrl(`/ws/script/${sid}`)
const getScriptWebSocketUrl = (sid: string): string => {
if (typeof window === "undefined") {
return `ws://localhost:${API_PORT}/ws/script/${sid}`
}
const { protocol, hostname, port } = window.location
const isStandardPort = port === "" || port === "80" || port === "443"
const wsProtocol = protocol === "https:" ? "wss:" : "ws:"
if (isStandardPort) {
return `${wsProtocol}//${hostname}/ws/script/${sid}`
} else {
return `${wsProtocol}//${hostname}:${API_PORT}/ws/script/${sid}`
}
}
const handleInteractionResponse = (value: string) => {