-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtool_event_payload.cpp
More file actions
104 lines (98 loc) · 3.53 KB
/
Copy pathtool_event_payload.cpp
File metadata and controls
104 lines (98 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "tool_event_payload.hpp"
#include "../session/output_attachments.hpp"
#include "../session/tool_metadata_codec.hpp"
namespace acecode::web {
nlohmann::json tool_summary_to_json(const ToolSummary& s) {
nlohmann::json out;
out["icon"] = s.icon;
out["verb"] = s.verb;
out["object"] = s.object;
nlohmann::json metrics = nlohmann::json::array();
for (const auto& [k, v] : s.metrics) {
metrics.push_back({{"label", k}, {"value", v}});
}
out["metrics"] = std::move(metrics);
return out;
}
nlohmann::json build_tool_start_payload(
const std::string& tool_name,
const nlohmann::json& args_payload,
const std::string& command_preview,
const std::string& display_override,
bool is_task_complete,
const std::string& tool_call_id,
int tool_index) {
nlohmann::json p;
p["tool"] = tool_name;
p["args"] = args_payload;
p["command_preview"] = command_preview;
p["display_override"] = display_override;
p["is_task_complete"] = is_task_complete;
if (!tool_call_id.empty()) p["tool_call_id"] = tool_call_id;
if (tool_index >= 0) p["tool_index"] = tool_index;
return p;
}
nlohmann::json build_tool_update_payload(
const std::string& tool_name,
const std::vector<std::string>& tail_lines,
const std::string& current_partial,
int total_lines,
std::size_t total_bytes,
double elapsed_seconds,
const std::string& tool_call_id,
int tool_index) {
nlohmann::json p;
p["tool"] = tool_name;
p["tail_lines"] = tail_lines;
p["current_partial"] = current_partial;
p["total_lines"] = total_lines;
p["total_bytes"] = total_bytes;
p["elapsed_seconds"] = elapsed_seconds;
if (!tool_call_id.empty()) p["tool_call_id"] = tool_call_id;
if (tool_index >= 0) p["tool_index"] = tool_index;
return p;
}
nlohmann::json build_tool_end_payload(
const std::string& tool_name,
const ToolResult& result,
double elapsed_seconds,
const std::string& output_snippet,
const std::string& tool_call_id,
int tool_index,
const std::string& message_id) {
nlohmann::json p;
p["tool"] = tool_name;
p["success"] = result.success;
p["elapsed_seconds"] = elapsed_seconds;
if (!tool_call_id.empty()) p["tool_call_id"] = tool_call_id;
if (tool_index >= 0) p["tool_index"] = tool_index;
if (!message_id.empty()) p["message_id"] = message_id;
if (result.summary.has_value()) {
p["summary"] = tool_summary_to_json(*result.summary);
}
if (result.metadata.is_object() && !result.metadata.empty()) {
p["metadata"] = result.metadata;
}
const std::string& output_payload = result.success
? result.output
: output_snippet;
if (!output_payload.empty()) {
p["output"] = output_payload;
}
// hunks 字段总是存在(空数组而不是省略),便于前端写"if (p.hunks.length)"
// 而不必先 contains 判断。前端 file_edit / file_write 走 diff2html 渲染。
if (result.hunks.has_value()) {
p["hunks"] = encode_tool_hunks(*result.hunks);
} else {
p["hunks"] = nlohmann::json::array();
}
p["attachments"] = result.has_attachments()
? output_attachments_from_content_parts(
output_attachments_to_content_parts(result.attachments))
: nlohmann::json::array();
if (!result.attachment_warnings.empty()) {
p["attachment_warnings"] = result.attachment_warnings;
}
return p;
}
} // namespace acecode::web