From b71762bafd1727bc1c4e3c8986adcb74df969200 Mon Sep 17 00:00:00 2001 From: marko-kraemer Date: Mon, 21 Apr 2025 13:00:31 +0100 Subject: [PATCH] fix daytona sandbox url --- backend/agent/api.py | 21 +++++++++++++++++-- backend/sandbox/sandbox.py | 11 +++++++--- .../tool-views/FileOperationToolView.tsx | 4 ++-- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/backend/agent/api.py b/backend/agent/api.py index 93da2d3f..c42ff458 100644 --- a/backend/agent/api.py +++ b/backend/agent/api.py @@ -299,12 +299,29 @@ async def start_agent( sandbox = create_sandbox(sandbox_pass) logger.info(f"Created new sandbox with preview: {sandbox.get_preview_link(6080)}/vnc_lite.html?password={sandbox_pass}") sandbox_id = sandbox.id + + # Get preview links + vnc_link = sandbox.get_preview_link(6080) + website_link = sandbox.get_preview_link(8080) + + # Extract the actual URLs and token from the preview link objects + vnc_url = vnc_link.url if hasattr(vnc_link, 'url') else str(vnc_link).split("url='")[1].split("'")[0] + website_url = website_link.url if hasattr(website_link, 'url') else str(website_link).split("url='")[1].split("'")[0] + + # Extract token if available + token = None + if hasattr(vnc_link, 'token'): + token = vnc_link.token + elif "token='" in str(vnc_link): + token = str(vnc_link).split("token='")[1].split("'")[0] + await client.table('projects').update({ 'sandbox': { 'id': sandbox_id, 'pass': sandbox_pass, - 'vnc_preview': str(sandbox.get_preview_link(6080)), - 'sandbox_url': str(sandbox.get_preview_link(8080)) + 'vnc_preview': vnc_url, + 'sandbox_url': website_url, + 'token': token } }).eq('project_id', project_id).execute() diff --git a/backend/sandbox/sandbox.py b/backend/sandbox/sandbox.py index ba524b16..6bc08fbe 100644 --- a/backend/sandbox/sandbox.py +++ b/backend/sandbox/sandbox.py @@ -152,10 +152,15 @@ class SandboxToolsBase(Tool): logger.error(f"Error retrieving sandbox: {str(e)}", exc_info=True) raise e - # Get and log preview links - vnc_url = self.sandbox.get_preview_link(6080) - website_url = self.sandbox.get_preview_link(8080) + # Get preview links + vnc_link = self.sandbox.get_preview_link(6080) + website_link = self.sandbox.get_preview_link(8080) + # Extract the actual URLs from the preview link objects + vnc_url = vnc_link.url if hasattr(vnc_link, 'url') else str(vnc_link) + website_url = website_link.url if hasattr(website_link, 'url') else str(website_link) + + # Log the actual URLs logger.info(f"Sandbox VNC URL: {vnc_url}") logger.info(f"Sandbox Website URL: {website_url}") diff --git a/frontend/src/components/thread/tool-views/FileOperationToolView.tsx b/frontend/src/components/thread/tool-views/FileOperationToolView.tsx index ae5a9094..340891ba 100644 --- a/frontend/src/components/thread/tool-views/FileOperationToolView.tsx +++ b/frontend/src/components/thread/tool-views/FileOperationToolView.tsx @@ -139,12 +139,12 @@ export function FileOperationToolView({ const isCsv = fileName.endsWith('.csv'); const language = getLanguageFromFileName(fileName); const hasHighlighting = language !== 'text'; - // Construct HTML file preview URL if we have a sandbox and the file is HTML const htmlPreviewUrl = (isHtml && project?.sandbox?.sandbox_url && processedFilePath) ? `${project.sandbox.sandbox_url}/${processedFilePath}` : undefined; - + + console.log('HTML Preview URL:', htmlPreviewUrl); // Add state for view mode toggle (code or preview) const [viewMode, setViewMode] = useState<'code' | 'preview'>(isHtml || isMarkdown || isCsv ? 'preview' : 'code');