yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
tool_call_argument_codec.h
Go to the documentation of this file.
1#ifndef YAZE_CLI_SERVICE_AI_TOOL_CALL_ARGUMENT_CODEC_H_
2#define YAZE_CLI_SERVICE_AI_TOOL_CALL_ARGUMENT_CODEC_H_
3
4#include <cstdint>
5#include <map>
6#include <string>
7
8#include "nlohmann/json.hpp"
9
10namespace yaze::cli::ai {
11
12// Convert provider-native JSON tool arguments into the string map consumed by
13// ToolDispatcher. Preserve integer spelling so CLI integer parsers receive
14// "7", not "7.000000", and preserve booleans for flag arguments.
15inline std::map<std::string, std::string> DecodeToolCallArguments(
16 const nlohmann::json& arguments) {
17 std::map<std::string, std::string> decoded;
18 if (!arguments.is_object()) {
19 return decoded;
20 }
21
22 for (const auto& [key, value] : arguments.items()) {
23 if (value.is_string()) {
24 decoded[key] = value.get<std::string>();
25 } else if (value.is_boolean()) {
26 decoded[key] = value.get<bool>() ? "true" : "false";
27 } else if (value.is_number_unsigned()) {
28 decoded[key] = std::to_string(value.get<uint64_t>());
29 } else if (value.is_number_integer()) {
30 decoded[key] = std::to_string(value.get<int64_t>());
31 } else if (value.is_number_float()) {
32 decoded[key] = value.dump();
33 }
34 }
35 return decoded;
36}
37
38} // namespace yaze::cli::ai
39
40#endif // YAZE_CLI_SERVICE_AI_TOOL_CALL_ARGUMENT_CODEC_H_
std::map< std::string, std::string > DecodeToolCallArguments(const nlohmann::json &arguments)