mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2025-12-15 00:26:23 +00:00
Update hybrid-script-monitor.tsx
This commit is contained in:
@@ -66,17 +66,31 @@ export function HybridScriptMonitor({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!sessionId) return
|
if (!sessionId) return
|
||||||
|
|
||||||
|
console.log("[v0] Setting up EventSource for session:", sessionId)
|
||||||
const eventSource = new EventSource(`/api/scripts/logs/${sessionId}`)
|
const eventSource = new EventSource(`/api/scripts/logs/${sessionId}`)
|
||||||
|
|
||||||
eventSource.onmessage = (event) => {
|
eventSource.onmessage = (event) => {
|
||||||
try {
|
try {
|
||||||
const data = JSON.parse(event.data)
|
const data = JSON.parse(event.data)
|
||||||
console.log("[v0] Received log event:", data)
|
console.log("[v0] Received SSE event:", data)
|
||||||
|
|
||||||
// Check if it's an interaction
|
if (data.type === "init") {
|
||||||
if (data.type === "interaction" || (typeof data === "string" && data.includes("WEB_INTERACTION:"))) {
|
// Initial message, add to logs
|
||||||
const line = typeof data === "string" ? data : data.message
|
setLogs((prev) => [
|
||||||
const interactionPart = line.split("WEB_INTERACTION:")[1]
|
...prev,
|
||||||
|
{
|
||||||
|
timestamp: new Date().toLocaleTimeString(),
|
||||||
|
message: `Starting script: ${data.script}`,
|
||||||
|
type: "info",
|
||||||
|
},
|
||||||
|
])
|
||||||
|
} else if (data.type === "raw") {
|
||||||
|
// Raw log line from script
|
||||||
|
const message = data.message
|
||||||
|
|
||||||
|
// Check if it contains a WEB_INTERACTION
|
||||||
|
if (message.includes("WEB_INTERACTION:")) {
|
||||||
|
const interactionPart = message.split("WEB_INTERACTION:")[1]
|
||||||
|
|
||||||
if (interactionPart) {
|
if (interactionPart) {
|
||||||
const parts = interactionPart.split(":")
|
const parts = interactionPart.split(":")
|
||||||
@@ -97,9 +111,7 @@ export function HybridScriptMonitor({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Regular log entry
|
// Regular log line
|
||||||
const message = typeof data === "string" ? data : data.message || JSON.stringify(data)
|
|
||||||
|
|
||||||
setLogs((prev) => [
|
setLogs((prev) => [
|
||||||
...prev,
|
...prev,
|
||||||
{
|
{
|
||||||
@@ -115,13 +127,51 @@ export function HybridScriptMonitor({
|
|||||||
},
|
},
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
} else if (data.type === "error") {
|
||||||
|
// Error from script_runner
|
||||||
|
setLogs((prev) => [
|
||||||
|
...prev,
|
||||||
|
{
|
||||||
|
timestamp: new Date().toLocaleTimeString(),
|
||||||
|
message: `Error: ${data.message}`,
|
||||||
|
type: "error",
|
||||||
|
},
|
||||||
|
])
|
||||||
|
} else {
|
||||||
|
// Unknown type, display as-is
|
||||||
|
setLogs((prev) => [
|
||||||
|
...prev,
|
||||||
|
{
|
||||||
|
timestamp: new Date().toLocaleTimeString(),
|
||||||
|
message: JSON.stringify(data),
|
||||||
|
type: "info",
|
||||||
|
},
|
||||||
|
])
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("[v0] Error parsing log event:", e)
|
console.error("[v0] Error parsing SSE event:", e, "Raw data:", event.data)
|
||||||
|
// If not JSON, display as plain text
|
||||||
|
setLogs((prev) => [
|
||||||
|
...prev,
|
||||||
|
{
|
||||||
|
timestamp: new Date().toLocaleTimeString(),
|
||||||
|
message: event.data,
|
||||||
|
type: "info",
|
||||||
|
},
|
||||||
|
])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
eventSource.onerror = (error) => {
|
eventSource.onerror = (error) => {
|
||||||
console.error("[v0] EventSource error:", error)
|
console.error("[v0] EventSource error:", error)
|
||||||
|
setLogs((prev) => [
|
||||||
|
...prev,
|
||||||
|
{
|
||||||
|
timestamp: new Date().toLocaleTimeString(),
|
||||||
|
message: "Connection to log stream lost",
|
||||||
|
type: "error",
|
||||||
|
},
|
||||||
|
])
|
||||||
eventSource.close()
|
eventSource.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user