import { ChevronDown, ChevronRight, Loader2, Play } from "lucide-react"; import { useState } from "react"; import { SandboxAgentError } from "sandbox-agent"; import type { ProcessRunResponse, SandboxAgent } from "sandbox-agent"; const parseArgs = (value: string): string[] => value.split("\n").map((part) => part.trim()).filter(Boolean); const ProcessRunTab = ({ getClient, }: { getClient: () => SandboxAgent; }) => { const [command, setCommand] = useState(""); const [argsText, setArgsText] = useState(""); const [cwd, setCwd] = useState(""); const [timeoutMs, setTimeoutMs] = useState("30000"); const [maxOutputBytes, setMaxOutputBytes] = useState(""); const [showAdvanced, setShowAdvanced] = useState(false); const [running, setRunning] = useState(false); const [error, setError] = useState(null); const [result, setResult] = useState(null); const handleRun = async () => { const trimmedCommand = command.trim(); if (!trimmedCommand) { setError("Command is required."); return; } setRunning(true); setError(null); try { const response = await getClient().runProcess({ command: trimmedCommand, args: parseArgs(argsText), cwd: cwd.trim() || undefined, timeoutMs: timeoutMs.trim() ? Number(timeoutMs) : undefined, maxOutputBytes: maxOutputBytes.trim() ? Number(maxOutputBytes) : undefined, }); setResult(response); } catch (runError) { const detail = runError instanceof SandboxAgentError ? runError.problem?.detail : undefined; setError(detail || (runError instanceof Error ? runError.message : "Unable to run process.")); setResult(null); } finally { setRunning(false); } }; return (
{ setCommand(event.target.value); setError(null); }} placeholder="ls" />
{ setCwd(event.target.value); setError(null); }} placeholder="/workspace" />