Commit 6580cdc
authored
refactor: use AI budget period from deployment config (#27117)
## Description
Read the AI budget period from the deployment config on both the RPC server and the `/users/{user}/ai/spend` endpoint, instead of hardcoding `month`. Drops the `period_start` RPC parameter that was incorrectly introduced in #26915: the period should have been derived from the deployment config from the start.
## Changes
- Add `codersdk.NewAIBudgetPeriodFromString`, mirroring `NewAIBudgetPolicyFromString`.
- `aibridgedserver.Server` takes a `quartz.Clock`, reads `BudgetPeriod` from the deployment config at construction, and computes the period window inside `IsBudgetExceeded`.
- Remove `period_start` from `IsBudgetExceededRequest` and stop sending it from the daemon.
- The `userAISpendStatus` endpoint reads the period from `AIBridgeConfig.BudgetPeriod` instead of hardcoding month.
> [!NOTE]
> Initially generated by Claude Opus 4.7, modified and reviewed by @ssncferreira1 parent 199b593 commit 6580cdcCopy full SHA for 6580cdc
10 files changed
+236-248Lines changed: 236 additions & 248 deletions
File tree
Expand file treeCollapse file tree
Open diff view settings
Filter options
- cli
- coderd
- aibridgedserver
- aibridged
- proto
- codersdk
- enterprise/coderd
Expand file treeCollapse file tree
Open diff view settings
Collapse file
cli/aibridged_internal_test.go
Copy file name to clipboardExpand all lines: cli/aibridged_internal_test.go+2-1Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
24 | 24 | |
25 | 25 | |
26 | 26 | |
| 27 | + |
27 | 28 | |
28 | 29 | |
29 | 30 | |
| ||
53 | 54 | |
54 | 55 | |
55 | 56 | |
56 | | - |
| 57 | + |
57 | 58 | |
58 | 59 | |
59 | 60 | |
|
Collapse file
+1-1Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
66 | 66 | |
67 | 67 | |
68 | 68 | |
69 | | - |
| 69 | + |
70 | 70 | |
71 | 71 | |
72 | 72 | |
|
Collapse file
+1-12Lines changed: 1 addition & 12 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
7 | 7 | |
8 | 8 | |
9 | 9 | |
10 | | - |
11 | 10 | |
12 | 11 | |
13 | 12 | |
14 | 13 | |
15 | 14 | |
16 | | - |
17 | 15 | |
18 | | - |
19 | | - |
20 | 16 | |
21 | 17 | |
22 | 18 | |
| ||
149 | 145 | |
150 | 146 | |
151 | 147 | |
152 | | - |
153 | | - |
154 | | - |
155 | | - |
156 | | - |
157 | | - |
158 | 148 | |
159 | | - |
160 | | - |
| 149 | + |
161 | 150 | |
162 | 151 | |
163 | 152 | |
|
Collapse file
coderd/aibridged/proto/aibridged.pb.go
Copy file name to clipboardExpand all lines: coderd/aibridged/proto/aibridged.pb.go+156-170Lines changed: 156 additions & 170 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file
coderd/aibridged/proto/aibridged.proto
Copy file name to clipboardExpand all lines: coderd/aibridged/proto/aibridged.proto+1-3Lines changed: 1 addition & 3 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
35 | 35 | |
36 | 36 | |
37 | 37 | |
38 | | - |
| 38 | + |
39 | 39 | |
40 | 40 | |
41 | 41 | |
| ||
189 | 189 | |
190 | 190 | |
191 | 191 | |
192 | | - |
193 | | - |
194 | 192 | |
195 | 193 | |
196 | 194 | |
|
Collapse file
coderd/aibridgedserver/aibridgedserver.go
Copy file name to clipboardExpand all lines: coderd/aibridgedserver/aibridgedserver.go+15-8Lines changed: 15 additions & 8 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
33 | 33 | |
34 | 34 | |
35 | 35 | |
| 36 | + |
36 | 37 | |
37 | 38 | |
38 | 39 | |
| ||
113 | 114 | |
114 | 115 | |
115 | 116 | |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | + |
116 | 121 | |
117 | 122 | |
118 | 123 | |
119 | 124 | |
120 | | - |
| 125 | + |
121 | 126 | |
122 | 127 | |
123 | 128 | |
| ||
138 | 143 | |
139 | 144 | |
140 | 145 | |
| 146 | + |
| 147 | + |
141 | 148 | |
142 | 149 | |
143 | 150 | |
| ||
747 | 754 | |
748 | 755 | |
749 | 756 | |
750 | | - |
| 757 | + |
| 758 | + |
751 | 759 | |
752 | 760 | |
753 | 761 | |
| ||
756 | 764 | |
757 | 765 | |
758 | 766 | |
759 | | - |
760 | | - |
761 | | - |
762 | | - |
| 767 | + |
| 768 | + |
| 769 | + |
| 770 | + |
763 | 771 | |
764 | | - |
765 | 772 | |
766 | | - |
| 773 | + |
767 | 774 | |
768 | 775 | |
769 | 776 | |
|
0 commit comments