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
|
chunk_id = 0
|
||||||
message_tag = ""
|
message_tag = ""
|
||||||
current_tool_name = ""
|
current_tool_name = ""
|
||||||
current_is_ui_tool = False
|
|
||||||
last_answer_first_char_duration_ms = None
|
last_answer_first_char_duration_ms = None
|
||||||
waiting_for_answer_first_char = False
|
waiting_for_answer_first_char = False
|
||||||
agent, checkpointer, sandbox = await init_agent(config)
|
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)
|
chunk_args = tool_call_chunk.get("args") if isinstance(tool_call_chunk, dict) else getattr(tool_call_chunk, "args", None)
|
||||||
if chunk_name:
|
if chunk_name:
|
||||||
current_tool_name = chunk_name
|
current_tool_name = chunk_name
|
||||||
current_is_ui_tool = False
|
if config.tool_response:
|
||||||
# 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 chunk_name:
|
if chunk_name:
|
||||||
new_content = f"[{message_tag}] {chunk_name}\n"
|
new_content = f"[{message_tag}] {chunk_name}\n"
|
||||||
if chunk_args:
|
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]:
|
def _handle_render_ui(uri: str, data: Dict[str, Any]) -> Dict[str, Any]:
|
||||||
"""Unified handler for all render_ui URIs.
|
"""Unified handler for all render_ui URIs.
|
||||||
|
|
||||||
Content is NOT self-contained — the actual html_content/url/questions
|
Content is self-contained in the TOOL_RESPONSE resource —
|
||||||
stays in the TOOL_CALL args to save tokens. resource.text is a placeholder.
|
the frontend only needs TOOL_RESPONSE to render, no TOOL_CALL reference needed.
|
||||||
The frontend extracts content from TOOL_CALL args based on URI.
|
|
||||||
"""
|
"""
|
||||||
width = data.get("width", "100%")
|
width = data.get("width", "100%")
|
||||||
height = data.get("height", "auto")
|
height = data.get("height", "auto")
|
||||||
|
|
||||||
if uri == "ui://mcp-ui/ask-user":
|
if uri == "ui://mcp-ui/ask-user":
|
||||||
|
questions = data.get("questions", [])
|
||||||
resource = create_ui_resource({
|
resource = create_ui_resource({
|
||||||
"uri": uri,
|
"uri": uri,
|
||||||
"content": {"type": "rawHtml", "htmlString": "Questions sent to user."},
|
"content": {"type": "rawHtml", "htmlString": json.dumps({"questions": questions}, ensure_ascii=False)},
|
||||||
"encoding": "text",
|
"encoding": "text",
|
||||||
"uiMetadata": {
|
"uiMetadata": {
|
||||||
"interactive": True,
|
"interactive": True,
|
||||||
@ -58,9 +58,10 @@ def _handle_render_ui(uri: str, data: Dict[str, Any]) -> Dict[str, Any]:
|
|||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
# ui://mcp-ui/html (default)
|
# ui://mcp-ui/html (default)
|
||||||
|
html_content = data.get("html_content", "")
|
||||||
resource = create_ui_resource({
|
resource = create_ui_resource({
|
||||||
"uri": uri,
|
"uri": uri,
|
||||||
"content": {"type": "rawHtml", "htmlString": "UI rendered."},
|
"content": {"type": "rawHtml", "htmlString": html_content},
|
||||||
"encoding": "text",
|
"encoding": "text",
|
||||||
"uiMetadata": {
|
"uiMetadata": {
|
||||||
UIMetadataKey.PREFERRED_FRAME_SIZE: [width, height],
|
UIMetadataKey.PREFERRED_FRAME_SIZE: [width, height],
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user