feat: 增强命令调用逻辑,支持通过 plugin.invoke_command 返回原始结构,并优化消息统计功能
This commit is contained in:
@@ -209,11 +209,22 @@ class PluginSupervisor:
|
||||
return result if isinstance(result, dict) else {}
|
||||
raise RuntimeError(payload.get("result", "workflow step invoke failed"))
|
||||
|
||||
async def _command_invoke(plugin_id: str, component_name: str, args: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""命令走 plugin.invoke_command,保留原始返回值结构。"""
|
||||
resp = await self.invoke_plugin(
|
||||
method="plugin.invoke_command",
|
||||
plugin_id=plugin_id,
|
||||
component_name=component_name,
|
||||
args=args,
|
||||
)
|
||||
return resp.payload
|
||||
|
||||
return await self._workflow_executor.execute(
|
||||
invoke_fn=_invoke,
|
||||
message=message,
|
||||
stream_id=stream_id,
|
||||
context=context,
|
||||
command_invoke_fn=_command_invoke,
|
||||
)
|
||||
|
||||
async def start(self) -> None:
|
||||
|
||||
@@ -118,9 +118,15 @@ class WorkflowExecutor:
|
||||
message: Optional[Dict[str, Any]] = None,
|
||||
stream_id: Optional[str] = None,
|
||||
context: Optional[WorkflowContext] = None,
|
||||
command_invoke_fn: Optional[InvokeFn] = None,
|
||||
) -> Tuple[WorkflowResult, Optional[Dict[str, Any]], WorkflowContext]:
|
||||
"""执行 workflow pipeline。
|
||||
|
||||
Args:
|
||||
invoke_fn: 用于 workflow_step 的回调
|
||||
command_invoke_fn: 用于 command 的回调(走 plugin.invoke_command),
|
||||
未传则复用 invoke_fn
|
||||
|
||||
Returns:
|
||||
(result, final_message, context)
|
||||
"""
|
||||
@@ -136,7 +142,7 @@ class WorkflowExecutor:
|
||||
# PLAN 阶段: 先做 Command 路由
|
||||
if stage == "plan" and current_message:
|
||||
cmd_result = await self._route_command(
|
||||
invoke_fn, current_message, ctx
|
||||
command_invoke_fn or invoke_fn, current_message, ctx
|
||||
)
|
||||
if cmd_result is not None:
|
||||
# 命令匹配成功,跳过 PLAN 阶段的 hook,直接存结果进 stage_outputs
|
||||
@@ -377,10 +383,12 @@ class WorkflowExecutor:
|
||||
if not plain_text:
|
||||
return None
|
||||
|
||||
matched = self._registry.find_command_by_text(plain_text)
|
||||
if matched is None:
|
||||
match_result = self._registry.find_command_by_text(plain_text)
|
||||
if match_result is None:
|
||||
return None
|
||||
|
||||
matched, matched_groups = match_result
|
||||
|
||||
ctx.matched_command = matched.full_name
|
||||
logger.info(f"[{ctx.trace_id}] 命令匹配: {matched.full_name}")
|
||||
|
||||
@@ -389,6 +397,7 @@ class WorkflowExecutor:
|
||||
"text": plain_text,
|
||||
"message": message,
|
||||
"trace_id": ctx.trace_id,
|
||||
"matched_groups": matched_groups,
|
||||
})
|
||||
except Exception as e:
|
||||
logger.error(f"[{ctx.trace_id}] 命令 {matched.full_name} 执行失败: {e}", exc_info=True)
|
||||
|
||||
Reference in New Issue
Block a user