-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsession_usage_ledger.hpp
More file actions
112 lines (95 loc) · 2.88 KB
/
Copy pathsession_usage_ledger.hpp
File metadata and controls
112 lines (95 loc) · 2.88 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
105
106
107
108
109
110
111
112
#pragma once
#include "../provider/llm_provider.hpp"
#include <cstdint>
#include <set>
#include <string>
#include <vector>
#include <nlohmann/json.hpp>
namespace acecode {
struct UsageLedgerRecord {
int version = 1;
std::int64_t timestamp_ms = 0;
std::string timestamp;
std::string session_id;
std::string cwd;
std::string provider;
std::string model;
std::string model_preset;
std::string surface;
TokenUsage usage;
};
struct UsageLedgerScope {
std::string project_dir;
std::string workspace_hash;
std::string workspace_name;
std::string cwd;
};
struct UsageLedgerQuery {
int days = 30;
std::int64_t now_ms = 0;
int timezone_offset_minutes = 0;
std::string workspace_hash;
};
struct UsageTotals {
std::int64_t prompt_tokens = 0;
std::int64_t completion_tokens = 0;
std::int64_t total_tokens = 0;
std::int64_t cache_read_tokens = 0;
std::int64_t cache_write_tokens = 0;
std::int64_t reasoning_tokens = 0;
};
struct UsageDailyBucket {
std::string date;
std::int64_t day_start_ms = 0;
UsageTotals totals;
int records = 0;
int estimated_records = 0;
std::set<std::string> session_ids;
};
struct UsageModelBucket {
std::string provider;
std::string model;
std::string model_preset;
std::string label;
UsageTotals totals;
int records = 0;
int estimated_records = 0;
std::set<std::string> session_ids;
};
struct UsageWorkspaceBucket {
std::string workspace_hash;
std::string workspace_name;
std::string cwd;
UsageTotals totals;
int records = 0;
int estimated_records = 0;
std::set<std::string> session_ids;
};
struct UsageAggregate {
UsageTotals totals;
int records = 0;
int estimated_records = 0;
std::set<std::string> session_ids;
int days = 30;
int timezone_offset_minutes = 0;
std::int64_t period_start_ms = 0;
std::int64_t period_end_ms = 0;
std::vector<UsageDailyBucket> daily;
std::vector<UsageModelBucket> models;
std::vector<UsageWorkspaceBucket> workspaces;
};
std::string usage_ledger_path(const std::string& project_dir);
std::int64_t usage_now_unix_ms();
std::string usage_iso8601_from_unix_ms(std::int64_t timestamp_ms);
std::string usage_date_key_from_unix_ms(std::int64_t timestamp_ms);
nlohmann::json usage_ledger_record_to_json(const UsageLedgerRecord& record);
bool usage_ledger_record_from_json(const nlohmann::json& j, UsageLedgerRecord& out);
void append_usage_ledger_record(const std::string& project_dir,
const UsageLedgerRecord& record);
std::vector<UsageLedgerRecord> load_usage_ledger_records(
const std::string& project_dir);
UsageAggregate aggregate_usage_ledgers(
const std::vector<UsageLedgerScope>& scopes,
const UsageLedgerQuery& query = {});
nlohmann::json usage_aggregate_to_json(const UsageAggregate& aggregate);
} // namespace acecode