dootask/app/Tasks/AiDialogCommandTask.php
kuaifan 77ebdd2ccb fix(ai): 前端仅在任务/项目对话中显示 /analyze 命令
- /analyze 命令仅在 group_type 为 task 或 project 时显示
- /summarize 命令保持在所有对话类型中可用
- 统一变量名 notifyMsgId -> pendingMsgId

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
2026-01-25 12:32:38 +00:00

55 lines
1.4 KiB
PHP

<?php
namespace App\Tasks;
use App\Models\WebSocketDialog;
use App\Module\AiDialogCommand;
use Illuminate\Support\Facades\Cache;
/**
* AI 对话命令异步任务
* 处理 /analyze 和 /summarize 命令
*/
class AiDialogCommandTask extends AbstractTask
{
protected int $dialogId;
protected string $command;
protected int $userId;
protected int $pendingMsgId;
public function __construct(int $dialogId, string $command, int $userId, int $pendingMsgId = 0)
{
parent::__construct();
$this->dialogId = $dialogId;
$this->command = $command;
$this->userId = $userId;
$this->pendingMsgId = $pendingMsgId;
}
public function start()
{
$dialog = WebSocketDialog::find($this->dialogId);
if (!$dialog) {
// 对话不存在,释放锁
Cache::forget("ai_dialog_command:{$this->dialogId}");
return;
}
try {
match ($this->command) {
'analyze' => AiDialogCommand::analyze($dialog, $this->userId, $this->pendingMsgId),
'summarize' => AiDialogCommand::summarize($dialog, $this->userId, $this->pendingMsgId),
default => null,
};
} catch (\Throwable $e) {
// 异常时释放锁,避免死锁
Cache::forget("ai_dialog_command:{$this->dialogId}");
throw $e;
}
}
public function end()
{
}
}