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 [currentInteraction, setCurrentInteraction] = useState<WebInteraction | null>(null)
const [interactionInput, setInteractionInput] = useState("") const [interactionInput, setInteractionInput] = useState("")
const terminalRef = useRef<any>(null) const terminalRef = useRef<any>(null)
const wsRef = useRef<WebSocket | null>(null)
useEffect(() => { useEffect(() => {
if (open) { if (open) {
@@ -53,43 +52,11 @@ export function ScriptTerminalModal({
params, params,
sessionId, sessionId,
}) })
setCurrentInteraction(null)
setInteractionInput("")
} }
}, [open, scriptPath, scriptName, params, sessionId]) }, [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 => { const getScriptWebSocketUrl = (): string => {
if (typeof window === "undefined") { if (typeof window === "undefined") {
return `ws://localhost:${API_PORT}/ws/script/${sessionId}` return `ws://localhost:${API_PORT}/ws/script/${sessionId}`
@@ -101,14 +68,14 @@ export function ScriptTerminalModal({
} }
const wsUrl = getScriptWebSocketUrl() const wsUrl = getScriptWebSocketUrl()
console.log("[v0] ScriptTerminalModal WebSocket URL:", wsUrl)
console.log("[v0] ScriptTerminalModal initMessage:", { const handleWebInteraction = (interaction: WebInteraction) => {
script_path: scriptPath, console.log("[v0] Received web interaction:", interaction)
params: params, setCurrentInteraction(interaction)
}) }
const handleInteractionResponse = (value: string) => { const handleInteractionResponse = (value: string) => {
if (!wsRef.current || !currentInteraction) return if (!terminalRef.current || !currentInteraction) return
const response = JSON.stringify({ const response = JSON.stringify({
type: "interaction_response", type: "interaction_response",
@@ -117,7 +84,13 @@ export function ScriptTerminalModal({
}) })
console.log("[v0] Sending interaction response:", response) 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) setCurrentInteraction(null)
setInteractionInput("") setInteractionInput("")
} }
@@ -158,6 +131,7 @@ export function ScriptTerminalModal({
script_path: scriptPath, script_path: scriptPath,
params: params, params: params,
}} }}
onWebInteraction={handleWebInteraction}
/> />
</div> </div>

View File

@@ -27,6 +27,7 @@ type TerminalPanelProps = {
websocketUrl?: string websocketUrl?: string
onClose?: () => void onClose?: () => void
initMessage?: Record<string, any> initMessage?: Record<string, any>
onWebInteraction?: (interaction: any) => void
} }
interface TerminalInstance { interface TerminalInstance {
@@ -133,7 +134,12 @@ const proxmoxCommands = [
{ cmd: "clear", desc: "Clear terminal screen" }, { 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 [terminals, setTerminals] = useState<TerminalInstance[]>([])
const [activeTerminalId, setActiveTerminalId] = useState<string>("") const [activeTerminalId, setActiveTerminalId] = useState<string>("")
const [layout, setLayout] = useState<"single" | "grid">("grid") const [layout, setLayout] = useState<"single" | "grid">("grid")
@@ -440,6 +446,17 @@ export const TerminalPanel: React.FC<TerminalPanelProps> = ({ websocketUrl, onCl
} }
ws.onmessage = (event) => { 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) term.write(event.data)
} }