feat(webui): guide sandbox launcher recovery from chat
This commit is contained in:
1 parent
16250540d3
commit
f5e5bd6ea0
47 files changed
+613
-32
No files matched your search
@@ -198,15 +198,17 @@ class ToolResult(str):
|
||||
"""String-compatible tool output with structured status."""
|
||||
|
||||
is_error: bool
|
||||
error_code: str | None
|
||||
|
||||
def __new__(cls, content: str, *, is_error: bool = False) -> ToolResult:
|
||||
def __new__(cls, content: str, *, is_error: bool = False, error_code: str | None = None) -> ToolResult:
|
||||
obj = str.__new__(cls, content)
|
||||
obj.is_error = is_error
|
||||
obj.error_code = error_code
|
||||
return obj
|
||||
|
||||
@classmethod
|
||||
def error(cls, content: str) -> ToolResult:
|
||||
return cls(content, is_error=True)
|
||||
def error(cls, content: str, *, error_code: str | None = None) -> ToolResult:
|
||||
return cls(content, is_error=True, error_code=error_code)
|
||||
|
||||
|
||||
class Tool(ABC):
|
||||
|
||||
@@ -10,6 +10,7 @@ from typing import Any, cast
|
||||
from loguru import logger
|
||||
|
||||
from nanobot.agent.hook import AgentHook, AgentHookContext
|
||||
from nanobot.agent.tools.base import ToolResult
|
||||
from nanobot.agent.tools.context import tool_log_content_allowed
|
||||
from nanobot.agent.tools.file_state import file_read_context
|
||||
from nanobot.agent.tools.registry import ToolRegistry, is_tool_error_result, with_tool_error_hint
|
||||
@@ -222,6 +223,8 @@ async def _execute_tool_call_inner(
|
||||
"status": "error",
|
||||
"detail": result.replace("\n", " ").strip()[:120],
|
||||
}
|
||||
if isinstance(result, ToolResult) and result.error_code:
|
||||
event["error_code"] = result.error_code
|
||||
handled = _classify_violation(
|
||||
raw_text=result,
|
||||
soft_payload=payload,
|
||||
|
||||
@@ -204,7 +204,10 @@ class ToolRegistry:
|
||||
assert tool is not None # guarded by prepare_call()
|
||||
result = await tool.execute(**params)
|
||||
if is_tool_error_result(result):
|
||||
return ToolResult.error(with_tool_error_hint(str(result)))
|
||||
return ToolResult.error(
|
||||
with_tool_error_hint(str(result)),
|
||||
error_code=result.error_code if isinstance(result, ToolResult) else None,
|
||||
)
|
||||
return result
|
||||
except Exception as e:
|
||||
return ToolResult.error(with_tool_error_hint(f"Error executing {name}: {str(e)}"))
|
||||
|
||||
@@ -364,7 +364,13 @@ class ExecTool(Tool):
|
||||
result += "\nInitial wait ended; session remains active."
|
||||
return ToolResult.error(result) if poll.failed else result
|
||||
except Exception as exc:
|
||||
return ToolResult.error(f"Error executing command: {exc}")
|
||||
# Only an OS rejection of the actual launcher is attributable here.
|
||||
# A command's nonzero exit or stderr is not proof of a sandbox fault.
|
||||
code = "sandbox_start_failed" if (
|
||||
isinstance(exc, OSError) and self.sandbox and not _IS_WINDOWS
|
||||
and isinstance(prepared.command, list) and exc.filename == prepared.command[0]
|
||||
) else None
|
||||
return ToolResult.error(f"Error executing command: {exc}", error_code=code)
|
||||
|
||||
def _resolve_timeout(self, timeout: object) -> int | None:
|
||||
if timeout is not None:
|
||||
@@ -483,8 +489,12 @@ class ExecTool(Tool):
|
||||
)
|
||||
except SandboxLauncherError as exc:
|
||||
if exc.reason == "launcher_missing":
|
||||
return ToolResult.error(f"Error: sandbox launcher not found: {command[0]}")
|
||||
return ToolResult.error(f"Error: sandbox launcher rejected: {exc.reason}")
|
||||
return ToolResult.error(
|
||||
f"Error: sandbox launcher not found: {command[0]}", error_code="sandbox_launcher_missing",
|
||||
)
|
||||
return ToolResult.error(
|
||||
f"Error: sandbox launcher rejected: {exc.reason}", error_code=f"sandbox_{exc.reason}",
|
||||
)
|
||||
cwd = str(Path(workspace).resolve())
|
||||
|
||||
return _PreparedCommand(
|
||||
|
||||
@@ -133,6 +133,8 @@ def build_tool_event_finish_payloads(context: AgentHookContext) -> list[dict[str
|
||||
"embeds": embeds,
|
||||
}
|
||||
if phase == "error":
|
||||
if event.get("error_code"):
|
||||
payload["error_code"] = event["error_code"]
|
||||
if isinstance(result, str) and result.strip():
|
||||
payload["error"] = result.strip()
|
||||
else:
|
||||
|
||||
Reference in new issue
Block a user