25#include "AstUtil/NetworkStreamReceiver.hpp"
26#include "AstUtil/JsonValue.hpp"
27#include "AstAI/ChatEventHandler.hpp"
44 void onHeaders(
int statusCode,
const std::map<std::string, std::string>& headers)
override;
45 errc_t
onData(
const char* data,
size_t size)
override;
47 void onError(errc_t error)
override;
52 bool hasError()
const {
return !error_.empty(); }
63 struct AccumulatedToolCall
67 std::string functionName;
68 std::string functionArguments;
72 void processEvent(
const std::string& event);
73 void processToolCallDeltas(
const JsonValue& toolCalls);
75 ChatEventHandler& handler_;
76 bool thoughtCompleted_{
false};
82 std::string accumulatedContent_;
83 std::string accumulatedReasoning_;
84 std::string finishReason_;
85 std::map<int, AccumulatedToolCall> toolCallsByIndex_;
流式聊天事件处理器
定义 ChatEventHandler.hpp:42
JSON 值类
定义 JsonValue.hpp:47
流式数据接收器
定义 NetworkStreamReceiver.hpp:41
virtual void onHeaders(int statusCode, const std::map< std::string, std::string > &headers)
收到 HTTP 响应头(在 onData 之前触发一次)
定义 NetworkStreamReceiver.hpp:49
virtual void onComplete()
数据接收完毕(正常完成时触发)
定义 NetworkStreamReceiver.hpp:65
virtual errc_t onData(const char *data, size_t size)=0
收到一块响应体数据(可能被多次调用)
virtual void onError(errc_t error)
发生网络错误
定义 NetworkStreamReceiver.hpp:62
SSE 增量解析器(内部组件)
定义 SSEParser.hpp:38
bool hasError() const
是否发生了错误(HTTP 非 200 或网络错误)
定义 SSEParser.hpp:52
const std::string & errorMessage() const
获取错误描述
定义 SSEParser.hpp:55