feat: 增加 screen_id 参数以支持针对特定屏幕的工具执行,优化大屏控制逻辑
This commit is contained in:
+11
-7
@@ -60,15 +60,15 @@ def _query_companies(args):
|
||||
}, ensure_ascii=False)
|
||||
|
||||
|
||||
def _control_display(args):
|
||||
"""大屏显示控制:切页 / 弹通知 / 媒体播放暂停(经 MQTT 广播到大屏)"""
|
||||
def _control_display(args, screen_id=""):
|
||||
"""大屏显示控制:切页 / 弹通知 / 媒体播放暂停(经 MQTT 按发起屏幕下发)"""
|
||||
from .mqtt import hub
|
||||
action = (args.get("action") or "").strip()
|
||||
target = (args.get("target") or "").strip()
|
||||
if action not in ("switch_page", "alert", "media_play", "media_pause"):
|
||||
return json.dumps({"error": f"不支持的 action: {action}"}, ensure_ascii=False)
|
||||
params = {"target": target} if target else {}
|
||||
ok = hub.publish_command(action, params).get("published", False)
|
||||
ok = hub.publish_command(action, params, screen_id=screen_id).get("published", False)
|
||||
return json.dumps({"ok": ok, "action": action, "target": target}, ensure_ascii=False)
|
||||
|
||||
|
||||
@@ -125,15 +125,19 @@ def tool_schemas():
|
||||
]
|
||||
|
||||
|
||||
def exec_tool(name: str, args: dict):
|
||||
"""执行工具 → 返回给 LLM 的字符串结果(JSON)"""
|
||||
def exec_tool(name: str, args: dict, screen_id: str = ""):
|
||||
"""执行工具 → 返回给 LLM 的字符串结果(JSON)。
|
||||
控制类工具(control_display)按发起屏幕 screen_id 只下发到该屏。"""
|
||||
t = TOOLS.get(name)
|
||||
if not t:
|
||||
log.warning("tools: 未知工具 %s", name)
|
||||
return json.dumps({"error": f"未知工具: {name}"}, ensure_ascii=False)
|
||||
try:
|
||||
result = t["fn"](args or {})
|
||||
log.info("tools: 执行工具 %s args=%s", name, json.dumps(args, ensure_ascii=False))
|
||||
if name == "control_display":
|
||||
result = _control_display(args or {}, screen_id)
|
||||
else:
|
||||
result = t["fn"](args or {})
|
||||
log.info("tools: 执行工具 %s args=%s screen=%s", name, json.dumps(args, ensure_ascii=False), screen_id or "all")
|
||||
log.info("tools: 结果 -> %s", _trunc(result, 1000))
|
||||
return result
|
||||
except Exception as e: # noqa: BLE001
|
||||
|
||||
Reference in New Issue
Block a user