MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / parse_role_command

Function parse_role_command

agents/role-manager/main.py:310–372  ·  view source on GitHub ↗

解析角色命令 支持格式: - "创建角色 roleB,研究方向:GUI Agent" - "切换到 roleB" - "查看角色列表" - "删除角色 roleA" - "绑定飞书群 roleA chat_xxx" Args: text: 用户输入 Returns: 命令字典

(text: str)

Source from the content-addressed store, hash-verified

308 """
309 解析角色命令
310
311 支持格式:
312 - "创建角色 roleB,研究方向:GUI Agent"
313 - "切换到 roleB"
314 - "查看角色列表"
315 - "删除角色 roleA"
316 - "绑定飞书群 roleA chat_xxx"
317
318 Args:
319 text: 用户输入
320
321 Returns:
322 命令字典
323 """
324 text_lower = text.lower().strip()
325
326 # 绑定飞书群
327 if any(kw in text_lower for kw in ["绑定", "bind", "关联"]):
328 match = re.search(r'(?:绑定 |bind| 关联)\s*(?:飞书)?(?:群 |chat)?\s*(\w+)\s*(\w+)', text_lower)
329 if match:
330 return {
331 "action": "bind",
332 "role_name": match.group(1),
333 "feishu_chat_id": match.group(2),
334 }
335
336 # 创建角色
337 if any(kw in text_lower for kw in ["创建角色", "create role", "新建角色"]):
338 # 提取角色名和描述
339 match = re.search(r'(?:创建角色 | 新建角色|create role)\s*(\w+)[, ,]*(.*)', text_lower)
340 if match:
341 return {
342 "action": "create",
343 "role_name": match.group(1),
344 "natural_language": match.group(2).strip() if match.group(2) else "",
345 }
346
347 # 切换角色
348 if any(kw in text_lower for kw in ["切换", "switch", "转到", "转到"]):
349 match = re.search(r'(?:切换到 | 转到|switch to)\s*(\w+)', text_lower)
350 if match:
351 return {
352 "action": "switch",
353 "role_name": match.group(1),
354 }
355
356 # 查看列表
357 if any(kw in text_lower for kw in ["查看角色", "list roles", "角色列表", "我的角色"]):
358 return {"action": "list"}
359
360 # 删除角色
361 if any(kw in text_lower for kw in ["删除角色", "delete role", "移除角色"]):
362 match = re.search(r'(?:删除 | 移除|delete)\s*(?:角色)?\s*(\w+)', text_lower)
363 if match:
364 return {
365 "action": "delete",
366 "role_name": match.group(1),
367 }

Callers 1

process_role_commandFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected