fix(cmd): update cmd flow error message and integrate service context

This commit is contained in:
jinli.yl 2026-01-31 16:39:29 +08:00
parent ec4fd33fbe
commit ce653e1f11
2 changed files with 9 additions and 4 deletions

View file

@ -11,7 +11,7 @@ class CmdFlow(BaseFlow):
"""Initialize the command flow with a string-based operation definition."""
super().__init__(**kwargs)
self.flow = flow
assert flow, "add `flow=<op_flow>` in cmd!"
assert flow, "add `cmd.flow=<op_flow>` in cmd!"
def _build_flow(self) -> BaseOp:
"""Parse the stored flow expression into a functional operation object."""

View file

@ -14,19 +14,24 @@ class CmdService(BaseService):
"""Initialize the command service instance."""
super().__init__(**kwargs)
self._cmd_flow: CmdFlow | None = None
run_coro_safely(self.service_context.start())
def integrate_flow(self, flow: BaseFlow) -> str | None:
"""Integrate the workflow configuration into the command service."""
self._cmd_flow = CmdFlow(flow=self.service_config.cmd.flow)
self._cmd_flow = CmdFlow(flow=self.service_config.cmd.flow, service_context=self.service_context)
def run(self):
"""Execute the command flow in either asynchronous or synchronous mode."""
super().run()
kwargs = self.service_config.cmd.model_extra
if self._cmd_flow.async_mode:
response = run_coro_safely(self._cmd_flow.call(**kwargs))
async def async_run():
await self.service_context.start()
return await self._cmd_flow.call(**kwargs)
response = run_coro_safely(async_run())
else:
run_coro_safely(self.service_context.start())
response = self._cmd_flow.call_sync(**kwargs)
if response.answer: