1import React from "react";
2import { apiFetch } from "../../lib/api";
3import MeshCentralEmbed, { VIEWMODE } from "../../components/MeshCentralEmbed";
5export default function TabScriptRunner({ agentId, agentUuid, agent }) {
6 const [useMeshCentral, setUseMeshCentral] = React.useState(true);
7 const [meshInfo, setMeshInfo] = React.useState(null);
8 const [meshLoading, setMeshLoading] = React.useState(false);
10 // Check if MeshCentral is available
11 React.useEffect(() => {
12 if (!agentId && !agentUuid) return;
15 apiFetch(`/agent/${agentUuid || agentId}/meshcentral-url`)
16 .then((res) => res.ok ? res.json() : null)
18 if (data?.meshcentralNodeId) {
20 setUseMeshCentral(true);
22 setUseMeshCentral(false);
25 .catch(() => setUseMeshCentral(false))
26 .finally(() => setMeshLoading(false));
27 }, [agentId, agentUuid]);
31 <div className="tab-container">
32 <h2>Script Runner</h2>
33 <div className="card">Loading...</div>
39 <div className="tab-container">
40 <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '16px' }}>
41 <h2 style={{ margin: 0 }}>Script Runner</h2>
42 {meshInfo?.available && (
45 onClick={() => setUseMeshCentral(!useMeshCentral)}
46 style={{ display: 'flex', alignItems: 'center', gap: '4px' }}
48 <span className="material-symbols-outlined" style={{ fontSize: '18px' }}>
49 {useMeshCentral ? 'code' : 'desktop_windows'}
51 {useMeshCentral ? 'Switch to Legacy' : 'Switch to MeshCentral'}
56 {/* MeshCentral Console View */}
57 {useMeshCentral && meshInfo?.available && (
58 <div className="card" style={{ padding: '16px' }}>
60 agentUuid={agent?.uuid || agentUuid}
61 viewMode={VIEWMODE.CONSOLE}
62 title="Console / Script Runner (MeshCentral)"
67 {/* Legacy Placeholder */}
68 {(!useMeshCentral || !meshInfo?.available) && (
69 <div className="card" style={{ padding: '40px 20px', textAlign: 'center', color: '#888' }}>
70 <span className="material-symbols-outlined" style={{ fontSize: '48px', opacity: 0.3 }}>
73 <p style={{ marginTop: '16px', fontSize: '16px' }}>
74 Legacy script runner not yet implemented
76 <p style={{ fontSize: '14px', opacity: 0.7 }}>
77 {meshInfo?.available ? 'Switch to MeshCentral for console and script execution' : 'MeshCentral connection required for script execution'}