feat(feishu): improve tool call card formatting for multiple tools
- Format multiple tool calls each on their own line - Change title from 'Tool Call' to 'Tool Calls' (plural) - Add explicit 'text' language for code block - Improves readability and supports displaying longer content - Update tests to match new formatting
This commit is contained in:
@@ -827,12 +827,18 @@ class FeishuChannel(BaseChannel):
|
|||||||
if msg.content and msg.content.strip():
|
if msg.content and msg.content.strip():
|
||||||
# Create a simple card with a code block
|
# Create a simple card with a code block
|
||||||
code_text = msg.content.strip()
|
code_text = msg.content.strip()
|
||||||
|
# Format tool calls: put each tool on its own line for better readability
|
||||||
|
# _tool_hint uses ", " to join multiple tool calls
|
||||||
|
if ", " in code_text:
|
||||||
|
formatted_code = code_text.replace(", ", ",\n")
|
||||||
|
else:
|
||||||
|
formatted_code = code_text
|
||||||
card = {
|
card = {
|
||||||
"config": {"wide_screen_mode": True},
|
"config": {"wide_screen_mode": True},
|
||||||
"elements": [
|
"elements": [
|
||||||
{
|
{
|
||||||
"tag": "markdown",
|
"tag": "markdown",
|
||||||
"content": f"**Tool Call**\n\n```\n{code_text}\n```"
|
"content": f"**Tool Calls**\n\n```text\n{formatted_code}\n```"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ def test_tool_hint_sends_code_message(mock_feishu_channel):
|
|||||||
assert card["config"]["wide_screen_mode"] is True
|
assert card["config"]["wide_screen_mode"] is True
|
||||||
assert len(card["elements"]) == 1
|
assert len(card["elements"]) == 1
|
||||||
assert card["elements"][0]["tag"] == "markdown"
|
assert card["elements"][0]["tag"] == "markdown"
|
||||||
# Check that code block is properly formatted
|
# Check that code block is properly formatted with language hint
|
||||||
expected_md = "**Tool Call**\n\n```\nweb_search(\"test query\")\n```"
|
expected_md = "**Tool Calls**\n\n```text\nweb_search(\"test query\")\n```"
|
||||||
assert card["elements"][0]["content"] == expected_md
|
assert card["elements"][0]["content"] == expected_md
|
||||||
|
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ def test_tool_hint_without_metadata_sends_as_normal(mock_feishu_channel):
|
|||||||
|
|
||||||
|
|
||||||
def test_tool_hint_multiple_tools_in_one_message(mock_feishu_channel):
|
def test_tool_hint_multiple_tools_in_one_message(mock_feishu_channel):
|
||||||
"""Multiple tool calls should be in a single code block."""
|
"""Multiple tool calls should be displayed each on its own line in a code block."""
|
||||||
msg = OutboundMessage(
|
msg = OutboundMessage(
|
||||||
channel="feishu",
|
channel="feishu",
|
||||||
chat_id="oc_123456",
|
chat_id="oc_123456",
|
||||||
@@ -111,4 +111,6 @@ def test_tool_hint_multiple_tools_in_one_message(mock_feishu_channel):
|
|||||||
msg_type = call_args[2]
|
msg_type = call_args[2]
|
||||||
content = json.loads(call_args[3])
|
content = json.loads(call_args[3])
|
||||||
assert msg_type == "interactive"
|
assert msg_type == "interactive"
|
||||||
assert "web_search(\"query\"), read_file(\"/path/to/file\")" in content["elements"][0]["content"]
|
# Each tool call should be on its own line
|
||||||
|
expected_md = "**Tool Calls**\n\n```text\nweb_search(\"query\"),\nread_file(\"/path/to/file\")\n```"
|
||||||
|
assert content["elements"][0]["content"] == expected_md
|
||||||
|
|||||||
Reference in New Issue
Block a user