fix(tunnels): skip tunnel creation for terminal-only tools
This commit is contained in:
@@ -437,44 +437,52 @@ async def start_instance(
|
||||
}
|
||||
|
||||
instance_port = tool_type.default_port
|
||||
logger.info("Tool type for instance %s: name=%s, default_port=%s",
|
||||
instance.id, tool_type.name, instance_port)
|
||||
logger.info("Tool type for instance %s: name=%s, default_port=%s, interfaces=%s",
|
||||
instance.id, tool_type.name, instance_port, tool_type.interfaces)
|
||||
|
||||
# Create temporary Cloudflare tunnel for public access
|
||||
try:
|
||||
logger.info("Creating temporary tunnel for instance %s (container=%s, port=%d)",
|
||||
instance.id, instance.container_name, instance_port)
|
||||
tunnel_info = start_cloudflared_tunnel(
|
||||
container_name=instance.container_name or instance.name,
|
||||
port=instance_port,
|
||||
)
|
||||
instance.tunnel_id = tunnel_info["pid"]
|
||||
instance.public_url = tunnel_info["url"]
|
||||
instance.url = tunnel_info["url"]
|
||||
await session.commit()
|
||||
logger.info(
|
||||
"Created temporary tunnel for instance %s: pid=%s, url=%s",
|
||||
instance.id,
|
||||
tunnel_info["pid"],
|
||||
tunnel_info["url"],
|
||||
)
|
||||
except Exception as exc:
|
||||
import traceback
|
||||
error_msg = str(exc)
|
||||
error_trace = traceback.format_exc()
|
||||
logger.error(
|
||||
"Failed to create tunnel for instance %s: %s\nTraceback:\n%s",
|
||||
instance.id,
|
||||
error_msg,
|
||||
error_trace,
|
||||
)
|
||||
instance.status = "error"
|
||||
# Only create Cloudflare tunnel for web-enabled tools
|
||||
if "web" in tool_type.interfaces:
|
||||
# Create temporary Cloudflare tunnel for public access
|
||||
try:
|
||||
logger.info("Creating temporary tunnel for instance %s (container=%s, port=%d)",
|
||||
instance.id, instance.container_name, instance_port)
|
||||
tunnel_info = start_cloudflared_tunnel(
|
||||
container_name=instance.container_name or instance.name,
|
||||
port=instance_port,
|
||||
)
|
||||
instance.tunnel_id = tunnel_info["pid"]
|
||||
instance.public_url = tunnel_info["url"]
|
||||
instance.url = tunnel_info["url"]
|
||||
await session.commit()
|
||||
logger.info(
|
||||
"Created temporary tunnel for instance %s: pid=%s, url=%s",
|
||||
instance.id,
|
||||
tunnel_info["pid"],
|
||||
tunnel_info["url"],
|
||||
)
|
||||
except Exception as exc:
|
||||
import traceback
|
||||
error_msg = str(exc)
|
||||
error_trace = traceback.format_exc()
|
||||
logger.error(
|
||||
"Failed to create tunnel for instance %s: %s\nTraceback:\n%s",
|
||||
instance.id,
|
||||
error_msg,
|
||||
error_trace,
|
||||
)
|
||||
instance.status = "error"
|
||||
instance.url = None
|
||||
await session.commit()
|
||||
return {
|
||||
"status": "error",
|
||||
"error": f"Failed to create tunnel: {error_msg}",
|
||||
}
|
||||
else:
|
||||
# Terminal-only tool - no tunnel needed
|
||||
logger.info("Instance %s is terminal-only (no web interface), skipping tunnel creation", instance.id)
|
||||
instance.url = None
|
||||
instance.public_url = None
|
||||
await session.commit()
|
||||
return {
|
||||
"status": "error",
|
||||
"error": f"Failed to create tunnel: {error_msg}",
|
||||
}
|
||||
|
||||
return {"status": instance.status, "url": instance.url}
|
||||
|
||||
@@ -597,33 +605,39 @@ async def restart_instance(
|
||||
|
||||
instance_port = tool_type.default_port
|
||||
|
||||
# Create new temporary tunnel
|
||||
try:
|
||||
tunnel_info = start_cloudflared_tunnel(
|
||||
container_name=instance.container_name or instance.name,
|
||||
port=instance_port,
|
||||
)
|
||||
instance.tunnel_id = tunnel_info["pid"]
|
||||
instance.public_url = tunnel_info["url"]
|
||||
instance.url = tunnel_info["url"]
|
||||
logger.info(
|
||||
"Created new tunnel for instance %s: %s",
|
||||
instance.id,
|
||||
tunnel_info["url"],
|
||||
)
|
||||
except Exception as exc:
|
||||
logger.warning(
|
||||
"Failed to create tunnel for instance %s: %s",
|
||||
instance.id,
|
||||
exc,
|
||||
)
|
||||
instance.status = "error"
|
||||
# Only create tunnel for web-enabled tools
|
||||
if "web" in tool_type.interfaces:
|
||||
# Create new temporary tunnel
|
||||
try:
|
||||
tunnel_info = start_cloudflared_tunnel(
|
||||
container_name=instance.container_name or instance.name,
|
||||
port=instance_port,
|
||||
)
|
||||
instance.tunnel_id = tunnel_info["pid"]
|
||||
instance.public_url = tunnel_info["url"]
|
||||
instance.url = tunnel_info["url"]
|
||||
logger.info(
|
||||
"Created new tunnel for instance %s: %s",
|
||||
instance.id,
|
||||
tunnel_info["url"],
|
||||
)
|
||||
except Exception as exc:
|
||||
logger.warning(
|
||||
"Failed to create tunnel for instance %s: %s",
|
||||
instance.id,
|
||||
exc,
|
||||
)
|
||||
instance.status = "error"
|
||||
instance.url = None
|
||||
await session.commit()
|
||||
return {
|
||||
"status": "error",
|
||||
"error": f"Failed to create tunnel: {exc}",
|
||||
}
|
||||
else:
|
||||
# Terminal-only tool
|
||||
instance.url = None
|
||||
await session.commit()
|
||||
return {
|
||||
"status": "error",
|
||||
"error": f"Failed to create tunnel: {exc}",
|
||||
}
|
||||
instance.public_url = None
|
||||
|
||||
await session.commit()
|
||||
return {"status": instance.status, "url": instance.url}
|
||||
|
||||
Reference in New Issue
Block a user