Update AppImage

This commit is contained in:
MacRimi
2025-12-06 12:46:41 +01:00
parent c627c65a7d
commit a6c121dc33
2 changed files with 34 additions and 43 deletions

View File

@@ -43,7 +43,6 @@ export function ScriptTerminalModal({
const [currentInteraction, setCurrentInteraction] = useState<WebInteraction | null>(null)
const [interactionInput, setInteractionInput] = useState("")
const terminalRef = useRef<any>(null)
const wsRef = useRef<WebSocket | null>(null)
useEffect(() => {
if (open) {
@@ -53,43 +52,11 @@ export function ScriptTerminalModal({
params,
sessionId,
})
setCurrentInteraction(null)
setInteractionInput("")
}
}, [open, scriptPath, scriptName, params, sessionId])
useEffect(() => {
if (!open) return
const handleWebSocketMessage = (event: MessageEvent) => {
try {
const data = JSON.parse(event.data)
console.log("[v0] Received WebSocket message:", data)
if (data.type === "web_interaction") {
console.log("[v0] Detected web interaction:", data.interaction)
setCurrentInteraction(data.interaction)
}
} catch (e) {
// Not JSON, ignore (it's terminal output)
}
}
const checkWs = setInterval(() => {
if (terminalRef.current?.ws) {
wsRef.current = terminalRef.current.ws
wsRef.current.addEventListener("message", handleWebSocketMessage)
clearInterval(checkWs)
console.log("[v0] Attached WebSocket message listener")
}
}, 100)
return () => {
clearInterval(checkWs)
if (wsRef.current) {
wsRef.current.removeEventListener("message", handleWebSocketMessage)
}
}
}, [open])
const getScriptWebSocketUrl = (): string => {
if (typeof window === "undefined") {
return `ws://localhost:${API_PORT}/ws/script/${sessionId}`
@@ -101,14 +68,14 @@ export function ScriptTerminalModal({
}
const wsUrl = getScriptWebSocketUrl()
console.log("[v0] ScriptTerminalModal WebSocket URL:", wsUrl)
console.log("[v0] ScriptTerminalModal initMessage:", {
script_path: scriptPath,
params: params,
})
const handleWebInteraction = (interaction: WebInteraction) => {
console.log("[v0] Received web interaction:", interaction)
setCurrentInteraction(interaction)
}
const handleInteractionResponse = (value: string) => {
if (!wsRef.current || !currentInteraction) return
if (!terminalRef.current || !currentInteraction) return
const response = JSON.stringify({
type: "interaction_response",
@@ -117,7 +84,13 @@ export function ScriptTerminalModal({
})
console.log("[v0] Sending interaction response:", response)
wsRef.current.send(response)
// Access the terminal instance to send the response
const terminal = terminalRef.current
if (terminal?.terminals?.[0]?.ws) {
terminal.terminals[0].ws.send(response)
}
setCurrentInteraction(null)
setInteractionInput("")
}
@@ -158,6 +131,7 @@ export function ScriptTerminalModal({
script_path: scriptPath,
params: params,
}}
onWebInteraction={handleWebInteraction}
/>
</div>

View File

@@ -27,6 +27,7 @@ type TerminalPanelProps = {
websocketUrl?: string
onClose?: () => void
initMessage?: Record<string, any>
onWebInteraction?: (interaction: any) => void
}
interface TerminalInstance {
@@ -133,7 +134,12 @@ const proxmoxCommands = [
{ cmd: "clear", desc: "Clear terminal screen" },
]
export const TerminalPanel: React.FC<TerminalPanelProps> = ({ websocketUrl, onClose, initMessage }) => {
export const TerminalPanel: React.FC<TerminalPanelProps> = ({
websocketUrl,
onClose,
initMessage,
onWebInteraction,
}) => {
const [terminals, setTerminals] = useState<TerminalInstance[]>([])
const [activeTerminalId, setActiveTerminalId] = useState<string>("")
const [layout, setLayout] = useState<"single" | "grid">("grid")
@@ -440,6 +446,17 @@ export const TerminalPanel: React.FC<TerminalPanelProps> = ({ websocketUrl, onCl
}
ws.onmessage = (event) => {
try {
const data = JSON.parse(event.data)
if (data.type === "web_interaction" && onWebInteraction) {
console.log("[v0] TerminalPanel: Intercepted web_interaction:", data.interaction)
onWebInteraction(data.interaction)
return // Don't write to terminal
}
} catch (e) {
// Not JSON, it's regular terminal output
}
term.write(event.data)
}