🛰️航天仿真算法库 SpaceAST 0.0.1
载入中...
搜索中...
未找到
UiChatPanel.hpp
浏览该文件的文档.
1
13
14#pragma once
15
16#include "AstGlobal.h"
17#include <QWidget>
18#include <memory>
19
20class QLabel;
21class QTimer;
22
23AST_NAMESPACE_BEGIN
24
25class ChatSession;
26class UiChatMessageList;
27class UiChatMessageItem;
28class UiChatInput;
29class UiChatEventHandler;
30class UiChatWorker;
31class UiToolCallTimeline;
32
45class AST_UIAI_API UiChatPanel : public QWidget
46{
47 Q_OBJECT
48
49public:
53 explicit UiChatPanel(ChatSession* session, QWidget* parent = nullptr);
54
55 ~UiChatPanel() override;
56 UiChatPanel(const UiChatPanel&) = delete;
57 UiChatPanel& operator=(const UiChatPanel&) = delete;
58
60 ChatSession* session() const { return session_; }
61
63 void setSession(ChatSession* session);
64
66 void sendMessage(const QString& message);
67
69 void clearMessages();
70
72 bool isBusy() const { return busy_; }
73
74Q_SIGNALS:
77
80
81private Q_SLOTS:
82 void onSendMessage(const QString& message);
83 void onStopRequested();
84
85 // 事件处理器槽
86 void onHtmlChunk(const QString& html);
87 void flushHtml();
88 void onContentComplete(const QString& text);
89 void onReasoningChunk(const QString& reasoning);
90 void onReasoningComplete(const QString& reasoning);
91 void onToolCallRequest(const QString& toolCallId,
92 const QString& functionName,
93 const QString& arguments);
94 void onToolCallResult(const QString& toolCallId,
95 const QString& functionName,
96 const QString& result);
97 void onCompleted();
98 void onError(const QString& error);
99 void onWorkerFinished(int errorCode);
100
101private:
102 void setupUi();
103 void setBusy(bool busy);
104
105 ChatSession* session_ = nullptr;
106 UiChatEventHandler* handler_ = nullptr;
107 UiChatMessageList* messageList_ = nullptr;
108 UiChatInput* chatInput_ = nullptr;
109 QLabel* statusLabel_ = nullptr;
110
111 // 流式状态
112 UiChatMessageItem* streamingItem_ = nullptr; // 正在流式填充的助手消息
113 UiToolCallTimeline* toolTimeline_ = nullptr; // 当前回合的工具调用时间线
114 QTimer* throttleTimer_ = nullptr; // 40ms 节流定时器
115 QString pendingHtml_{}; // 累积的 HTML(定时器触发后一次性渲染)
116 std::string accumulatedText_{}; // 累积的流式文本
117 bool busy_{false};
118};
119
122AST_NAMESPACE_END
聊天会话
定义 ChatSession.hpp:44
流式聊天事件的 Qt 信号桥接器
定义 UiChatEventHandler.hpp:44
聊天输入区域部件
定义 UiChatInput.hpp:30
单条聊天消息气泡部件
定义 UiChatMessageItem.hpp:34
聊天消息列表(可滚动区域)
定义 UiChatMessageList.hpp:33
聊天面板
定义 UiChatPanel.hpp:46
void chatFinished()
对话完成
bool isBusy() const
是否正在等待回复
定义 UiChatPanel.hpp:72
void chatStarted()
对话开始(用户发送消息后)
ChatSession * session() const
获取关联的聊天会话
定义 UiChatPanel.hpp:60
工具调用时间线部件
定义 UiToolCallTimeline.hpp:38