dootask/app/Tasks/AiDialogCommandTask.php
kuaifan 5ee5f253ec feat(ai): 添加 /analyze 和 /summarize 对话命令
- 新增 AiDialogCommand 模块处理 AI 命令业务逻辑
- 新增 AiDialogCommandTask 异步任务
- /analyze: 任务对话分析任务状态,项目对话分析项目健康度
- /summarize: 总结对话中的讨论内容
- 前端 ChatInput 添加斜杠命令菜单项
- 支持并发控制,同一对话同时只能执行一个 AI 命令
- 执行状态通过 notice 消息实时反馈

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 02:07:39 +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 $notifyMsgId;
public function __construct(int $dialogId, string $command, int $userId, int $notifyMsgId = 0)
{
parent::__construct();
$this->dialogId = $dialogId;
$this->command = $command;
$this->userId = $userId;
$this->notifyMsgId = $notifyMsgId;
}
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->notifyMsgId),
'summarize' => AiDialogCommand::summarize($dialog, $this->userId, $this->notifyMsgId),
default => null,
};
} catch (\Throwable $e) {
// 异常时释放锁,避免死锁
Cache::forget("ai_dialog_command:{$this->dialogId}");
throw $e;
}
}
public function end()
{
}
}