🛰️航天仿真算法库 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
58 ChatSession* session() const { return session_; }
59
61 void setSession(ChatSession* session);
62
64 void sendMessage(const QString& message);
65
67 void clearMessages();
68
70 bool isBusy() const { return busy_; }
71
72Q_SIGNALS:
75
78
79private Q_SLOTS:
80 void onSendMessage(const QString& message);
81 void onStopRequested();
82
83 // 事件处理器槽
84 void onHtmlChunk(const QString& html);
85 void flushHtml();
86 void onContentComplete(const QString& text);
87 void onReasoningChunk(const QString& reasoning);
88 void onReasoningComplete(const QString& reasoning);
89 void onToolCallRequest(const QString& toolCallId,
90 const QString& functionName,
91 const QString& arguments);
92 void onToolCallResult(const QString& toolCallId,
93 const QString& functionName,
94 const QString& result);
95 void onCompleted();
96 void onError(const QString& error);
97 void onWorkerFinished(int errorCode);
98
99private:
100 void setupUi();
101 void setBusy(bool busy);
102
103 ChatSession* session_ = nullptr;
104 UiChatEventHandler* handler_ = nullptr;
105 UiChatMessageList* messageList_ = nullptr;
106 UiChatInput* chatInput_ = nullptr;
107 QLabel* statusLabel_ = nullptr;
108
109 // 流式状态
110 UiChatMessageItem* streamingItem_ = nullptr; // 正在流式填充的助手消息
111 UiToolCallTimeline* toolTimeline_ = nullptr; // 当前回合的工具调用时间线
112 QTimer* throttleTimer_ = nullptr; // 40ms 节流定时器
113 QString pendingHtml_; // 累积的 HTML(定时器触发后一次性渲染)
114 std::string accumulatedText_; // 累积的流式文本
115 bool busy_{false};
116};
117
120AST_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:70
void chatStarted()
对话开始(用户发送消息后)
ChatSession * session() const
获取关联的聊天会话
定义 UiChatPanel.hpp:58
工具调用时间线部件
定义 UiToolCallTimeline.hpp:38