Merge branch 'feature/mcp-ui' into bot_manager
This commit is contained in:
commit
495b8031bb
@ -93,7 +93,6 @@ async def enhanced_generate_stream_response(
|
||||
chunk_id = 0
|
||||
message_tag = ""
|
||||
current_tool_name = ""
|
||||
current_is_ui_tool = False
|
||||
last_answer_first_char_duration_ms = None
|
||||
waiting_for_answer_first_char = False
|
||||
agent, checkpointer, sandbox = await init_agent(config)
|
||||
@ -115,12 +114,7 @@ async def enhanced_generate_stream_response(
|
||||
chunk_args = tool_call_chunk.get("args") if isinstance(tool_call_chunk, dict) else getattr(tool_call_chunk, "args", None)
|
||||
if chunk_name:
|
||||
current_tool_name = chunk_name
|
||||
current_is_ui_tool = False
|
||||
# Always output ui:// protocol tool calls even when tool_response is disabled
|
||||
# Detect ui:// in chunk args; once detected, all subsequent chunks for this tool are UI
|
||||
if isinstance(chunk_args, str) and '"ui://' in chunk_args:
|
||||
current_is_ui_tool = True
|
||||
if config.tool_response or current_is_ui_tool:
|
||||
if config.tool_response:
|
||||
if chunk_name:
|
||||
new_content = f"[{message_tag}] {chunk_name}\n"
|
||||
if chunk_args:
|
||||
|
||||
@ -29,17 +29,17 @@ def _serialize_ui_resource(ui_resource) -> str:
|
||||
def _handle_render_ui(uri: str, data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""Unified handler for all render_ui URIs.
|
||||
|
||||
Content is NOT self-contained — the actual html_content/url/questions
|
||||
stays in the TOOL_CALL args to save tokens. resource.text is a placeholder.
|
||||
The frontend extracts content from TOOL_CALL args based on URI.
|
||||
Content is self-contained in the TOOL_RESPONSE resource —
|
||||
the frontend only needs TOOL_RESPONSE to render, no TOOL_CALL reference needed.
|
||||
"""
|
||||
width = data.get("width", "100%")
|
||||
height = data.get("height", "auto")
|
||||
|
||||
if uri == "ui://mcp-ui/ask-user":
|
||||
questions = data.get("questions", [])
|
||||
resource = create_ui_resource({
|
||||
"uri": uri,
|
||||
"content": {"type": "rawHtml", "htmlString": "Questions sent to user."},
|
||||
"content": {"type": "rawHtml", "htmlString": json.dumps({"questions": questions}, ensure_ascii=False)},
|
||||
"encoding": "text",
|
||||
"uiMetadata": {
|
||||
"interactive": True,
|
||||
@ -58,9 +58,10 @@ def _handle_render_ui(uri: str, data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
})
|
||||
else:
|
||||
# ui://mcp-ui/html (default)
|
||||
html_content = data.get("html_content", "")
|
||||
resource = create_ui_resource({
|
||||
"uri": uri,
|
||||
"content": {"type": "rawHtml", "htmlString": "UI rendered."},
|
||||
"content": {"type": "rawHtml", "htmlString": html_content},
|
||||
"encoding": "text",
|
||||
"uiMetadata": {
|
||||
UIMetadataKey.PREFERRED_FRAME_SIZE: [width, height],
|
||||
|
||||
Loading…
Reference in New Issue
Block a user