Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions plugins/platforms/feishu/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,10 @@ def _build_event_handler(self) -> Any:
"vc.bot.meeting_invited_v1",
self._on_meeting_invited_event,
)
.register_p2_customized_event(
"user_status_change",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update TestAdapterBehavior.test_build_event_handler_registers_reaction_and_card_processors: its exact expected call list at tests/gateway/test_feishu.py:434-450 currently omits this registration, so this hunk will fail that test.

lambda data: None, # ponytail: no-op, suppress "processor not found" ERROR spam (56/day)
)
.build()
)

Expand Down Expand Up @@ -4384,13 +4388,12 @@ def _allow_group_message(
# --- Mention detection ----------------------------------------------------

def _mentions_self(self, message: Any) -> bool:
# @_all is Feishu's @everyone placeholder.
raw_content = getattr(message, "content", "") or ""
if "@_all" in raw_content:
return True
# @_all (Feishu @所有人) does NOT count as mentioning the bot.
# Only check mentions array for bot's open_id.
mentions = getattr(message, "mentions", None) or []
if mentions and self._message_mentions_bot(mentions):
return True
raw_content = getattr(message, "content", "") or ""
normalized = normalize_feishu_message(
message_type=getattr(message, "message_type", "") or "",
raw_content=raw_content,
Expand Down
55 changes: 55 additions & 0 deletions tools/mcp_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -5133,6 +5133,60 @@ def _strip_nullable_union(node):

return strip_nullable_unions(node, keep_nullable_hint=True)

def _coerce_enum_types(node):
"""Coerce enum values to match their declared type.

Moonshot / Kimi strictly validates that ``enum`` array elements
match the property's ``type``. MCP servers commonly produce
``enum: ["10", "20"]`` on an ``integer`` property, which OpenAI
and Anthropic tolerate but Kimi rejects with
``<At path '...enum': not a valid integer>``.

This repair is a JSON Schema sanity fix: if ``type`` says
``integer``, enum values should be ints, not strings; if ``type``
says ``number``, they should be floats/ints, not strings.
"""
if isinstance(node, list):
return [_coerce_enum_types(item) for item in node]
if not isinstance(node, dict):
return node

repaired = {k: _coerce_enum_types(v) for k, v in node.items()}

enum_vals = repaired.get("enum")
type_str = repaired.get("type")
if isinstance(enum_vals, list) and isinstance(type_str, str):
if type_str == "integer":
fixed = []
for v in enum_vals:
if isinstance(v, int):
fixed.append(v)
elif isinstance(v, str):
try:
fixed.append(int(v))
except (ValueError, TypeError):
fixed.append(v)
else:
fixed.append(v)
if fixed != enum_vals:
repaired["enum"] = fixed
elif type_str == "number":
fixed = []
for v in enum_vals:
if isinstance(v, (int, float)):
fixed.append(v)
elif isinstance(v, str):
try:
fixed.append(float(v))
except (ValueError, TypeError):
fixed.append(v)
else:
fixed.append(v)
if fixed != enum_vals:
repaired["enum"] = fixed

return repaired

def _repair_object_shape(node):
"""Recursively repair object-shaped nodes: fill type, prune required."""
if isinstance(node, list):
Expand Down Expand Up @@ -5173,6 +5227,7 @@ def _repair_object_shape(node):

normalized = _rewrite_local_refs(schema)
normalized = _strip_nullable_union(normalized)
normalized = _coerce_enum_types(normalized)
normalized = _repair_object_shape(normalized)

# Ensure top-level is a well-formed object schema
Expand Down