ai-refactor(flow): 调整抽象流程节点实现和依赖路径
- 修改 AbstractProcessNode 中 ProcessContext 的命名空间引用为 app\flow\context\ProcessContext - 引入 app\flow\vo\CanHandleResult 用于节点处理结果表示 - 更新前置策略执行后对成功状态的判断,改为调用 isSuccess() 方法 - 增加日志记录细节,便于调试策略执行中断时的错误信息 - 优化代码注释,提升代码可读性和维护性
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace app\flow\vo;
|
||||
|
||||
use app\flow\enum\VoiceMessage;
|
||||
|
||||
/**
|
||||
* 节点能否处理的判断结果
|
||||
* 封装 canHandle 方法的返回值(不可变)
|
||||
*/
|
||||
readonly class CanHandleResult
|
||||
{
|
||||
public function __construct(
|
||||
/** 是否能处理 */
|
||||
public bool $canHandle,
|
||||
/** 如果不能处理,期望的下一步提示 */
|
||||
public VoiceMessage $expectedNextStep = VoiceMessage::NONE,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 创建可以处理的结果
|
||||
*/
|
||||
public static function yes(): self
|
||||
{
|
||||
return new self(canHandle: true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建不能处理的结果
|
||||
*/
|
||||
public static function no(?VoiceMessage $expectedNextStep = null): self
|
||||
{
|
||||
return new self(
|
||||
canHandle: false,
|
||||
expectedNextStep: $expectedNextStep ?? VoiceMessage::NONE
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否能处理
|
||||
*/
|
||||
public function isCanHandle(): bool
|
||||
{
|
||||
return $this->canHandle;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否有期望下一步提示
|
||||
*/
|
||||
public function hasExpectedNextStep(): bool
|
||||
{
|
||||
return $this->expectedNextStep !== VoiceMessage::NONE;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user