Skip to content

g1t/crates/contracts/src/billing.rs

3,759 lines136,558 bytesCodeBlame

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Agents as a team: lifecycle, merge queue, billing and a new shell1//! The billing service: what agents cost, charged to the workspace they
2//! worked for.
3//!
4//! A workspace buys credit and each agent run deducts what it cost, plus
5//! g1t's margin. With no credit, no agent starts. Money is held in
6//! millionths of a US dollar, so that a run costing a fraction of a cent is
7//! recorded exactly.
8//!
9//! Each `*Args` struct is the argument of the method of the same name,
10//! served at `POST /rpc/<method>`.
11
12use serde::{Deserialize, Serialize};
13
14use crate::repos::RepoPath;
15use crate::{User, Viewer};
16
17/// Millionths of a US dollar in one dollar.
18pub const MICROS_PER_DOLLAR: i64 = 1_000_000;
19
20/// Whether workspaces are charged for agents at all, and with real money.
21/// `status` takes nothing and returns this.
22#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize)]
23pub struct Status {
24 /// False when no payment provider is configured: nothing is charged,
25 /// and who may run agents is decided some other way.
26 pub enabled: bool,
27 /// False while the payment provider is in its test mode, where cards
28 /// are not real.
29 pub live: bool,
Free while g1t is being built out; agents can check out their own forks30 /// True while g1t is being built out: runs are recorded, with what
31 /// they cost, but nothing is charged and no credit is needed. Not a
32 /// promise that it stays free.
33 #[serde(default)]
34 pub free: bool,
Agents as a team: lifecycle, merge queue, billing and a new shell35}
36
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put37/// `trial`: a workspace's trial credit, so people can try g1t (its agents on
38/// g1t's hosted models among it) without a key or a card of their own. Each
39/// new workspace gets one grant of usage credit (`TRIAL_WORKSPACE_MICROS`),
40/// made when it first uses something, out of a pool for everyone that
41/// resets each calendar month (`TRIAL_MONTHLY_POOL_MICROS`). When this
42/// month's pool is given out, new grants wait for the next month. Returns
43/// `Trial`.
A free allowance on g1t's models, so anyone can try its agents44#[derive(Debug, Serialize, Deserialize)]
45#[serde(rename_all = "camelCase")]
46pub struct TrialArgs {
47 pub workspace: String,
48 /// Workspaces open to hosted models anyway, whose use is not counted
49 /// against the pool.
50 #[serde(default)]
51 pub exempt: Vec<String>,
52}
53
54#[derive(Clone, Debug, Serialize, Deserialize)]
55#[serde(rename_all = "camelCase")]
56pub struct Trial {
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put57 /// Whether its agents may use g1t's hosted models on the trial now: it
58 /// has credit left, or this month's pool can still grant it some.
A free allowance on g1t's models, so anyone can try its agents59 pub open: bool,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put60 /// What the trial has paid for so far, in millionths of a dollar.
A free allowance on g1t's models, so anyone can try its agents61 pub used_micros: i64,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put62 /// Its grant, or what it would be granted.
A free allowance on g1t's models, so anyone can try its agents63 pub limit_micros: i64,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put64 /// No longer used: the trial does not end on a date. Kept for older
65 /// readers; always null.
A free allowance on g1t's models, so anyone can try its agents66 pub ends_at: Option<String>,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put67 /// Why it is closed: `off` (no trials), `used` (this workspace's grant
68 /// is spent) or `pool` (this month's grants are all given out; see
69 /// `waits_until`). `ended` is no longer sent.
A free allowance on g1t's models, so anyone can try its agents70 pub reason: Option<String>,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put71 /// Whether the workspace has its grant already.
72 #[serde(default)]
73 pub granted: bool,
74 /// RFC 3339: when a workspace waiting for a grant can get one, the
75 /// first of next month. Only with reason `pool`.
76 #[serde(default)]
77 pub waits_until: Option<String>,
A free allowance on g1t's models, so anyone can try its agents78}
79
Agents as a team: lifecycle, merge queue, billing and a new shell80/// A workspace's standing.
81#[derive(Clone, Debug, Serialize, Deserialize)]
82#[serde(rename_all = "camelCase")]
83pub struct Account {
84 pub workspace: String,
85 /// Credit left, in millionths of a dollar. Can dip below zero by the
86 /// cost of the runs that were under way when it ran out.
87 pub balance_micros: i64,
88 pub status: Status,
89 /// What is added to a run's cost, in percent.
90 pub margin_percent: u32,
Billing on Stripe's pages, month-end charges, warnings; sudo by workspace91 /// The card g1t charges as the workspace nears its limit and when a
92 /// month closes, if one is on file.
93 #[serde(default)]
94 pub card: Option<Card>,
Agents as a team: lifecycle, merge queue, billing and a new shell95}
96
Billing on Stripe's pages, month-end charges, warnings; sudo by workspace97/// A saved card, as far as it is safe to show.
98#[derive(Clone, Debug, Serialize, Deserialize)]
99#[serde(rename_all = "camelCase")]
100pub struct Card {
101 /// `visa`, `mastercard`, ...
102 pub brand: String,
103 pub last4: String,
104 pub exp_month: u32,
105 pub exp_year: u32,
106}
107
108/// `billing_portal`: Stripe's hosted billing page for the workspace, where
109/// an owner adds or replaces the card, sees invoices and receipts, and sets
110/// the billing email and address. g1t never handles card numbers. Owners
111/// only. Returns `Outcome<Checkout>` (its `url`); Stripe sends them back
112/// to `return_url`.
113#[derive(Debug, Serialize, Deserialize)]
114pub struct BillingPortalArgs {
115 pub actor: User,
116 pub workspace: String,
117 pub return_url: String,
118}
119
120/// `admin_billing_link`: for staff to send a customer: their Stripe billing
121/// page. Returns `Outcome<BillingLink>`.
122#[derive(Debug, Serialize, Deserialize)]
123pub struct AdminBillingLinkArgs {
124 pub workspace: String,
125 pub by: String,
126}
127
128#[derive(Clone, Debug, Serialize, Deserialize)]
129#[serde(rename_all = "camelCase")]
130pub struct BillingLink {
131 /// A one-time session on Stripe's billing page, signed in already.
132 pub portal_url: String,
133 /// The billing page's sign-in page, which does not expire: the
134 /// customer signs in with the email Stripe has for them.
135 pub login_url: Option<String>,
136 pub customer_email: Option<String>,
137 pub expires_note: String,
138}
139
Agents as a team: lifecycle, merge queue, billing and a new shell140#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
141#[serde(rename_all = "snake_case")]
142pub enum EntryKind {
143 /// Credit bought with a card.
144 TopUp,
Paid features: a workspace turns on Deployments with a monthly plan145 /// An agent's run, or a paid feature's usage past its allowance.
Agents as a team: lifecycle, merge queue, billing and a new shell146 Usage,
147}
148
149/// One line of a workspace's statement.
150#[derive(Clone, Debug, Serialize, Deserialize)]
151#[serde(rename_all = "camelCase")]
152pub struct LedgerEntry {
153 pub id: String,
154 pub kind: EntryKind,
155 /// Positive for credit added, negative for usage.
156 pub amount_micros: i64,
157 pub description: String,
158 /// For usage: the repository and pull request the agent worked on.
159 pub repo: Option<String>,
160 pub number: Option<u32>,
161 /// For usage: `implement`, `review` or `update`.
162 pub task: Option<String>,
163 /// For usage: the model, by its public name.
164 pub model: Option<String>,
Integrations: your own model provider, alerts that open issues, tickets agents read165 /// For usage: `g1t` when g1t paid the model provider, `workspace` when
Prices are what g1t pays plus 20%, from the first second166 /// the workspace's own account did. Runs on the workspace's own
167 /// provider pay only their sandbox time now, so only older entries
168 /// are `workspace`.
Integrations: your own model provider, alerts that open issues, tickets agents read169 #[serde(default = "g1t")]
170 pub billed_to: String,
Agents as a team: lifecycle, merge queue, billing and a new shell171 /// For a top-up: the username of whoever paid.
172 pub created_by: Option<String>,
173 /// RFC 3339.
174 pub created_at: String,
Billing on Stripe's pages, month-end charges, warnings; sudo by workspace175 /// The workspace the line belongs to, which tells an enterprise's
176 /// lines apart.
177 #[serde(default, skip_serializing_if = "Option::is_none")]
178 pub workspace: Option<String>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look179 /// For usage: what the g1t plan's monthly included usage paid of it.
180 /// The entry's `amount_micros` is what is left to pay.
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put181 #[serde(default)]
182 pub credit_micros: i64,
183 /// For usage: what the workspace's trial credit paid of it.
184 #[serde(default)]
185 pub trial_micros: i64,
186 /// For usage: what g1t's open-source pool paid of it.
187 #[serde(default)]
188 pub oss_micros: i64,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look189 /// For usage: what g1t covered itself, such as the part of a free
190 /// workspace's last trial run that went past its trial credit.
191 #[serde(default)]
192 pub given_micros: i64,
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging193 /// For usage: what the account's discount took off its price. The
194 /// price is `-amount_micros` plus this and what paid for it.
195 #[serde(default)]
196 pub discount_micros: i64,
197 /// For a credit from g1t, and for what of one expired or was revoked:
198 /// its kind.
199 #[serde(default, skip_serializing_if = "Option::is_none")]
200 pub credit_kind: Option<CreditKind>,
Agents as a team: lifecycle, merge queue, billing and a new shell201}
202
Integrations: your own model provider, alerts that open issues, tickets agents read203fn g1t() -> String {
204 "g1t".to_owned()
205}
206
Agents as a team: lifecycle, merge queue, billing and a new shell207/// `account` (`Outcome<Account>`) and `ledger` (`Outcome<Vec<LedgerEntry>>`,
208/// newest first). Members of the workspace only.
209#[derive(Debug, Serialize, Deserialize)]
210pub struct AccountArgs {
211 pub workspace: String,
212 pub viewer: Viewer,
213}
214
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look215/// `checkout`: prepays usage: money paid in advance, drawn down by usage
216/// after the plan's included usage, which raises what can be used before
217/// work stops by the same amount at once. $25 at the least. By card, with
218/// 3-D Secure; from $1,000 also by bank transfer. Owners of the workspace
Agents as a team: lifecycle, merge queue, billing and a new shell219/// only. Returns `Outcome<Checkout>`.
220#[derive(Debug, Serialize, Deserialize)]
221#[serde(rename_all = "camelCase")]
222pub struct CheckoutArgs {
223 pub actor: User,
224 pub workspace: String,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look225 /// How much to prepay, in cents.
Agents as a team: lifecycle, merge queue, billing and a new shell226 pub amount_cents: u32,
227 /// Where the payment page sends the person afterwards. The payment's
228 /// id is appended as `session`.
229 pub return_url: String,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look230 /// `card` (the default) or `bank_transfer` (from $1,000): Stripe gives
231 /// the account details, and the money counts once it arrives.
232 #[serde(default)]
233 pub method: Option<String>,
Agents as a team: lifecycle, merge queue, billing and a new shell234}
235
236#[derive(Debug, Serialize, Deserialize)]
237pub struct Checkout {
238 /// The payment page to send the person to.
239 pub url: String,
240}
241
242/// `confirm`: credits a payment once the provider says it was made. Safe
243/// to call any number of times. Returns `Outcome<Account>`.
244#[derive(Debug, Serialize, Deserialize)]
245pub struct ConfirmArgs {
246 pub workspace: String,
247 pub viewer: Viewer,
248 /// The payment's id, as returned to `return_url`.
249 pub session: String,
250}
251
252/// `can_start`: whether a workspace may start an agent now, asked before
253/// anything is opened for it. Returns `Outcome<bool>`: a failure, with the
254/// reason to show, when it has no credit.
255#[derive(Debug, Serialize, Deserialize)]
256pub struct CanStartArgs {
257 pub workspace: String,
258}
259
260/// `start_run`: asks whether a workspace may start an agent, and opens the
261/// run it will be charged for. Called by the runner service. Returns
262/// `Outcome<Option<RunTicket>>`: no ticket when billing is off, a failure
263/// when the workspace has no credit.
264#[derive(Debug, Serialize, Deserialize)]
265pub struct StartRunArgs {
266 pub workspace: String,
267 pub repo: RepoPath,
268 pub number: u32,
269 /// `implement`, `review` or `update`.
270 pub task: String,
271 /// The model, by its public name.
272 pub model: String,
Integrations: your own model provider, alerts that open issues, tickets agents read273 /// `workspace` when the run uses the workspace's own model provider.
Models per workspace: several providers, routed by kind of work274 /// The runner, which is TypeScript, sends it as `billedTo`.
275 #[serde(default = "g1t", alias = "billedTo")]
Integrations: your own model provider, alerts that open issues, tickets agents read276 pub billed_to: String,
Merge branch 'model-routing'277 /// The model session's id. Through g1t's AI Gateway, settling charges
278 /// the run what the gateway priced its requests at; on the workspace's
279 /// own provider, it is what the proxy counts the run's tokens under,
280 /// for the agent rate.
Prices keep themselves current with what g1t pays281 #[serde(default)]
282 pub session: Option<String>,
Merge branch 'model-routing'283 /// `small`, `large` or `frontier`: the tier g1t routed the run to.
284 /// None when the workspace's own provider names its model.
Auto model routing: the cheapest tier that can do each piece of work, a retry goes up a tier, and each run records its tier285 #[serde(default)]
286 pub tier: Option<String>,
Agents as a team: lifecycle, merge queue, billing and a new shell287}
288
289#[derive(Clone, Debug, Serialize, Deserialize)]
290#[serde(rename_all = "camelCase")]
291pub struct RunTicket {
292 pub run_id: String,
293 /// Lets the sandbox, and nothing else, report what this run cost.
294 pub token: String,
295}
296
297/// `finish_run`: what a run cost, as its sandbox reports it. Charged once.
298/// Returns `Outcome<bool>`.
299#[derive(Debug, Serialize, Deserialize)]
300#[serde(rename_all = "camelCase")]
301pub struct FinishRunArgs {
302 pub run_id: String,
303 pub token: String,
304 /// What the model provider charged, in US dollars.
305 pub cost_usd: f64,
306 #[serde(default)]
307 pub turns: u32,
Merge branch 'model-routing'308 /// The tokens the run used, as the harness counted them from the
309 /// provider's answers. On the workspace's own provider, the agent rate
310 /// is charged on no fewer than these. Absent from older sandboxes.
311 #[serde(default)]
312 pub tokens: Option<RunTokens>,
313}
314
315/// The tokens one run used, by kind.
316#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
317#[serde(rename_all = "camelCase")]
318pub struct RunTokens {
319 #[serde(default)]
320 pub input: u64,
321 #[serde(default)]
322 pub output: u64,
323 #[serde(default)]
324 pub cache_read: u64,
325 #[serde(default)]
326 pub cache_write: u64,
327}
328
329impl RunTokens {
330 /// Every token, of every kind: what the agent rate is charged on.
331 pub fn total(&self) -> u64 {
332 self.input.saturating_add(self.output).saturating_add(self.cache_read).saturating_add(self.cache_write)
333 }
Agents as a team: lifecycle, merge queue, billing and a new shell334}
Usage, like a hosting provider's: what agents cost, per day, task, repository and pull request335
336
337/// `usage`: what a workspace's agents cost over a period, broken down.
338/// Members only. Returns `Outcome<Usage>`.
339#[derive(Debug, Serialize, Deserialize)]
340pub struct UsageArgs {
341 pub workspace: String,
342 pub viewer: Viewer,
343 /// RFC 3339: the start of the period. The period runs to now.
344 pub since: String,
345}
346
347/// One slice of usage: what it was for, what it cost, how many runs.
348#[derive(Clone, Debug, Serialize, Deserialize)]
349#[serde(rename_all = "camelCase")]
350pub struct UsageSlice {
351 pub key: String,
352 pub micros: i64,
353 pub runs: u32,
354}
355
356/// What a workspace's agents cost over a period.
357#[derive(Clone, Debug, Serialize, Deserialize)]
358#[serde(rename_all = "camelCase")]
359pub struct Usage {
360 pub since: String,
361 /// Charged, including g1t's margin.
362 pub spent_micros: i64,
Billing and Usage reconcile: own-provider runs leave Billing's at-price total, and Usage's not-charged part is at price less charged363 /// What g1t's usage came to at price, less what was charged: the plan's
364 /// included usage, the trial, a pool or a free period paid it. Usage at
365 /// price is `spent_micros` plus this.
Billing's usage total is labeled at price, and Usage says what part of it was paid for366 #[serde(default)]
367 pub covered_micros: i64,
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging368 /// What the account's discount took off the price. Usage at price is
369 /// `spent_micros` plus `covered_micros` plus this.
370 #[serde(default)]
371 pub discount_micros: i64,
372 /// The account's discount now, in percent; absent without one. With
373 /// one, the slices measure usage at price.
374 #[serde(default)]
375 pub discount_percent: Option<u32>,
Usage, Billing settings and prepaid AI credit; fixes from the UX audit376 /// Usage at price: `spent_micros` plus `covered_micros` plus
377 /// `discount_micros`, from the same ledger lines. The one figure every
378 /// page shows as usage (mission control, the agent fleet, Usage and
379 /// Billing), labelled "usage at price".
380 #[serde(default)]
381 pub price_micros: i64,
Integrations: your own model provider, alerts that open issues, tickets agents read382 /// What g1t's model provider charged, before the margin.
Usage, like a hosting provider's: what agents cost, per day, task, repository and pull request383 pub cost_micros: i64,
Integrations: your own model provider, alerts that open issues, tickets agents read384 /// What runs on the workspace's own provider cost there, as the harness
385 /// estimated it. Not charged by g1t.
386 pub provider_micros: i64,
Usage while free is shown at cost; agents get rustfmt and clippy387 /// What the runs used, at cost: g1t's models and the workspace's own
388 /// provider together, whatever was charged for them.
389 pub used_micros: i64,
390 /// g1t charges nothing for now. The slices then measure usage at cost,
391 /// since every charge is zero.
392 pub free: bool,
Usage, like a hosting provider's: what agents cost, per day, task, repository and pull request393 pub runs: u32,
394 /// Spend per day (`YYYY-MM-DD`) and task, as `day/task` keys.
395 pub by_day: Vec<UsageSlice>,
396 /// Per task: implement, review, revise, update, plan.
397 pub by_task: Vec<UsageSlice>,
398 /// Per repository, `namespace/name`.
399 pub by_repo: Vec<UsageSlice>,
400 /// The pull requests that cost most, as `namespace/name#number`.
401 pub by_pull: Vec<UsageSlice>,
402 /// Per model, by its public name.
403 pub by_model: Vec<UsageSlice>,
404 /// Credit bought in the period.
405 pub added_micros: i64,
406}
Models per workspace: several providers, routed by kind of work407
Mission control shows model usage, yours and the workspace's: tokens, cost, active days, cache share, each day, and the mix408/// `record_tokens`: what one model answer used, added to the day's count
409/// for its run. The model proxy sends it after each answer. For usage
410/// views only: runs are still priced from AI Gateway. Returns
411/// `Outcome<bool>`: false when there was nothing to count.
412#[derive(Debug, Serialize, Deserialize)]
413#[serde(rename_all = "camelCase")]
414pub struct RecordTokensArgs {
415 pub workspace: String,
416 /// The model session's id (`ModelSession::id`), one per run.
417 pub session: String,
418 /// The person the run is for, by username. Absent when nobody asked.
419 #[serde(default)]
420 pub person: Option<String>,
421 pub model: String,
Merge branch 'model-routing'422 /// The tier g1t routed the run to: `small`, `large` or `frontier`.
Mission control shows model usage, yours and the workspace's: tokens, cost, active days, cache share, each day, and the mix423 #[serde(default)]
424 pub tier: Option<String>,
425 #[serde(default)]
426 pub input: u64,
427 #[serde(default)]
428 pub output: u64,
429 #[serde(default)]
430 pub cache_read: u64,
431 #[serde(default)]
432 pub cache_write: u64,
433}
434
435/// `token_usage`: the model tokens a workspace's runs used, day by day,
436/// for the whole workspace or for one person. Members only; a member may
437/// ask only for themselves, an owner for anyone. Returns
438/// `Outcome<TokenUsage>`.
439#[derive(Debug, Serialize, Deserialize)]
440pub struct TokenUsageArgs {
441 pub workspace: String,
442 pub viewer: Viewer,
443 /// A username: only the runs for them.
444 #[serde(default)]
445 pub person: Option<String>,
446 /// How many days, to today: 42 when absent, 366 at most.
447 #[serde(default)]
448 pub days: Option<u32>,
449}
450
451/// One day's tokens.
452#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
453pub struct DayTokens {
454 /// `YYYY-MM-DD`, UTC.
455 pub day: String,
456 pub tokens: u64,
457}
458
459/// The model tokens runs used over a window of days.
460#[derive(Clone, Debug, Serialize, Deserialize)]
461#[serde(rename_all = "camelCase")]
462pub struct TokenUsage {
463 /// `YYYY-MM-DD`: the first day counted.
464 pub since: String,
465 pub days: u32,
466 /// Null for the whole workspace.
467 pub person: Option<String>,
468 pub total_tokens: u64,
469 pub input_tokens: u64,
470 pub output_tokens: u64,
471 pub cache_read_tokens: u64,
472 pub cache_write_tokens: u64,
473 /// What those runs were charged, as `usage` measures it.
474 pub cost_micros: i64,
475 /// Days in the window with any tokens.
476 pub active_days: u32,
477 /// Every day in the window, oldest first, zeros included.
478 pub by_day: Vec<DayTokens>,
479}
480
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look481/// What a workspace pays a monthly price for. There is one plan, `plan`
482/// ("g1t"): a flat price per workspace, never per person, with included
483/// usage each month, more private storage, and deployments. Never free:
484/// `FREE_WHILE_BUILDING` does not cover it.
485///
486/// `deployments` is not sold on its own any more: it comes with the plan.
487/// A service that asks `has_feature` for it is told whether the workspace
488/// has the plan, and a Deployments subscription bought before the change
489/// keeps working until its period ends.
Paid features: a workspace turns on Deployments with a monthly plan490#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
491#[serde(rename_all = "snake_case")]
492pub enum Feature {
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look493 /// The g1t plan. Older readers called it `team`.
494 #[serde(alias = "team")]
495 Plan,
496 /// Previews per pull request and production on g1t.page: part of the
497 /// plan.
Paid features: a workspace turns on Deployments with a monthly plan498 Deployments,
Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar499 /// The Security and quality activation: the security suite's paid
500 /// features on private repositories, for a monthly price per workspace
501 /// from the price book (`security_activation`). Sold on its own; it
502 /// does not need the plan, and the plan does not include it.
503 Security,
Paid features: a workspace turns on Deployments with a monthly plan504}
505
506impl Feature {
Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar507 /// What is sold: the plan, and the Security and quality activation.
508 pub const ALL: [Feature; 2] = [Feature::Plan, Feature::Security];
Paid features: a workspace turns on Deployments with a monthly plan509
510 pub fn as_str(self) -> &'static str {
511 match self {
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look512 Feature::Plan => "plan",
Paid features: a workspace turns on Deployments with a monthly plan513 Feature::Deployments => "deployments",
Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar514 Feature::Security => "security",
Paid features: a workspace turns on Deployments with a monthly plan515 }
516 }
517
518 pub fn parse(name: &str) -> Option<Feature> {
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look519 match name {
520 "plan" | "team" => Some(Feature::Plan),
521 "deployments" => Some(Feature::Deployments),
Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar522 "security" => Some(Feature::Security),
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look523 _ => None,
524 }
Paid features: a workspace turns on Deployments with a monthly plan525 }
526
527 pub fn title(self) -> &'static str {
528 match self {
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look529 Feature::Plan => "g1t",
Paid features: a workspace turns on Deployments with a monthly plan530 Feature::Deployments => "Deployments",
Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar531 Feature::Security => "Security and quality",
Paid features: a workspace turns on Deployments with a monthly plan532 }
533 }
534}
535
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas536/// What deployments cost g1t, in millionths of a dollar: fallbacks for
537/// when billing's price book cannot be read. Nothing here is an allowance:
538/// on the plan every unit is metered from the first, at cost plus the
539/// margin, and drawn from the plan's included usage before anything is
540/// charged. Projects, previews and the apps behind them are not metered at
541/// all: Cloudflare's Workers for Platforms includes far more scripts than
542/// g1t runs, so an app costs g1t only the requests and CPU it answers with.
543pub mod deployment_costs {
544 /// Workers for Platforms: $0.30 per million requests.
Paid features: a workspace turns on Deployments with a monthly plan545 pub const MICROS_PER_MILLION_REQUESTS: i64 = 300_000;
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas546 /// $0.02 per million CPU milliseconds.
Paid features: a workspace turns on Deployments with a monthly plan547 pub const MICROS_PER_MILLION_CPU_MS: i64 = 20_000;
Deployments: a preview for every pull request, production on g1t.page548 /// What one second of a build's sandbox costs g1t (Cloudflare
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look549 /// Containers, standard-1: half a vCPU, 4 GiB, 8 GB disk), rounded up,
550 /// as the price keeper measured it on 2026-10-05 (14.5). Only a
551 /// fallback: billing charges builds at the price book's `build_second`,
552 /// which the keeper keeps current.
553 pub const MICROS_PER_BUILD_SECOND: i64 = 15;
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas554 /// What one custom hostname costs g1t a month (Cloudflare for SaaS):
555 /// $0.10.
Agents and memory, checks and conflicts, profiles, slug renames, custom domains556 pub const MICROS_PER_DOMAIN_MONTH: i64 = 100_000;
Paid features: a workspace turns on Deployments with a monthly plan557}
558
Every sandbox is metered by the second559/// `record_sandbox`: how long one sandbox ran for a workspace, reported by
Prices are what g1t pays plus 20%, from the first second560/// the runner when it stops. Every sandbox g1t starts for a workspace
561/// (agents, reviews, checks, the merge queue, workflow jobs) is metered by
562/// the second, from the first: recorded once per `reference`, with what it
563/// cost g1t, and charged at the price book's `sandbox_second` price unless
564/// `FREE_WHILE_BUILDING`. Deploy builds are charged by the Deployments plan
565/// instead.
Every sandbox is metered by the second566/// Returns `Outcome<bool>`: false if that reference was recorded before.
567#[derive(Debug, Serialize, Deserialize)]
568#[serde(rename_all = "camelCase")]
569pub struct RecordSandboxArgs {
570 pub workspace: String,
571 pub seconds: u32,
572 /// What ran, e.g. `Checks on acme/api#12`.
573 pub description: String,
574 /// `namespace/name`.
575 pub repo: Option<String>,
576 /// Unique to the run.
577 pub reference: String,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look578 /// What ran: `agent`, `check`, `workflow` or `queue`. Decides whether
579 /// g1t's open-source pool may pay for it (checks, workflows and the
580 /// merge queue on public repositories). Absent: not the pool.
581 #[serde(default)]
582 pub kind: Option<ComputeKind>,
583 /// The vCPU-seconds the sandbox used, when it can tell. With it, the
584 /// run is priced on its own CPU (`sandbox_base_second` per second plus
585 /// `sandbox_cpu_second` per vCPU-second); without it, at the average
586 /// (`sandbox_second`).
587 #[serde(default, alias = "cpu_seconds")]
588 pub cpu_seconds: Option<f64>,
589 /// The reservation the work started under, settled with this cost.
590 #[serde(default, alias = "reservation_id")]
591 pub reservation_id: Option<String>,
Fast pages, required checks on the branch, self-hosted runners, honest incidents592 /// It ran on one of the workspace's self-hosted runners: recorded as
593 /// self-hosted time, for the minutes, at $0.
594 #[serde(default, alias = "self_hosted")]
595 pub self_hosted: bool,
596 /// The machine it ran on, by label (`g1t-4core`); absent, the standard
597 /// one. A larger machine's memory and disk cost more each second.
598 #[serde(default)]
599 pub instance: Option<String>,
Every sandbox is metered by the second600}
601
Usage limits: unpaid usage can only go so far602/// How much a workspace has earned g1t's trust with money, which sets how
603/// far its unpaid usage can go before its work stops.
604#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
605#[serde(rename_all = "snake_case")]
606pub enum Trust {
607 /// No live payment yet: only a little past the free allowances.
608 New,
609 /// Has paid g1t real money: the ceiling grows with what it has paid.
610 Paid,
Two limits, real invoices, trust that grows by itself, sales signals611 /// Has paid steadily for months, with nothing disputed or declined:
612 /// the ceiling follows its monthly spend, up to $10,000, by itself.
613 Established,
Usage limits: unpaid usage can only go so far614 /// A ceiling g1t set by hand, after talking to the workspace.
615 Reviewed,
616 /// g1t's own workspaces: no ceiling.
617 Internal,
618}
619
620#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
621#[serde(rename_all = "snake_case")]
622pub enum LimitState {
623 Ok,
624 /// Past 80% of the ceiling.
625 Warning,
626 /// At or past it: no new sandboxes, builds or app requests.
627 Stopped,
628}
629
630/// How far a workspace's unpaid usage has gone this month, and where its
631/// work stops: like Fly's or Cloudflare's limits for new accounts, so no
632/// one runs up costs g1t cannot collect. Usage counts at what it cost g1t
633/// or what it is charged, whichever is more, so it counts while g1t is
634/// free too.
635#[derive(Clone, Debug, Serialize, Deserialize)]
636#[serde(rename_all = "camelCase")]
637pub struct Limit {
638 pub workspace: String,
Billing accounts, terms and enterprises; g1t is no longer free639 /// The account that pays, whose usage and payments the limit counts:
640 /// the workspace's own, or its enterprise's.
641 #[serde(default)]
642 pub account: String,
643 #[serde(default)]
644 pub account_name: String,
Usage limits: unpaid usage can only go so far645 pub trust: Trust,
646 /// Usage this month (UTC) less what was paid this month.
647 pub exposure_micros: i64,
648 /// Where work stops: the lower of g1t's ceiling and the owner's own
649 /// spend limit. None for g1t's own workspaces.
650 pub ceiling_micros: Option<i64>,
651 /// The ceiling g1t sets from `trust`.
652 pub trust_ceiling_micros: Option<i64>,
653 /// The owner's own monthly limit, if they set one.
654 pub spend_limit_micros: Option<i64>,
655 pub state: LimitState,
656 /// What to tell people when work is stopped or close to it.
657 pub message: Option<String>,
Two limits, real invoices, trust that grows by itself, sales signals658 /// Charged this month, which the spend limit is measured against.
659 #[serde(default)]
660 pub spent_micros: i64,
661 /// True while the owners have not chosen a spend limit of their own, so
662 /// the automatic one applies: $200, or twice last month's spend.
663 #[serde(default)]
664 pub default_spend_limit: bool,
665 /// The most the owners may set their own limit to: g1t's ceiling. To
666 /// go past it, they contact g1t.
667 #[serde(default)]
668 pub available_micros: Option<i64>,
669 /// How the ceiling grows from here, in a sentence.
670 #[serde(default)]
671 pub growth: Option<String>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look672 /// Money paid in advance and not used yet. It raises what can be used
673 /// before work stops by the same amount, at once.
674 #[serde(default)]
675 pub prepaid_micros: i64,
676 /// The highest ceiling the workspace has ever had. Owners may set their
677 /// spend limit anywhere up to it (plus what is prepaid) without asking.
678 #[serde(default)]
679 pub max_ceiling_micros: Option<i64>,
680 /// The most the owners may raise the limit to themselves, once, with
681 /// `raise_once`: twice the highest ceiling. None once it is used.
682 #[serde(default)]
683 pub raise_once_micros: Option<i64>,
684 /// When the one-time raise was used, RFC 3339.
685 #[serde(default)]
686 pub raised_at: Option<String>,
687 /// True in a paid workspace's first billing cycle, when the ceiling is
688 /// the starting one (`LIMIT_PAID_START_MICROS`).
689 #[serde(default)]
690 pub first_month: bool,
Usage, Billing settings and prepaid AI credit; fixes from the UX audit691 /// The budget's alerts, in percent of the spend limit: some of 50, 75,
692 /// 90 and 100. Each is emailed to the owners once a month.
693 #[serde(default)]
694 pub alert_levels: Vec<u32>,
695 /// Whether usage pauses at the spend limit (the default). Off, the
696 /// limit only alerts; g1t's own ceiling still applies.
697 #[serde(default = "yes")]
698 pub pause_at_limit: bool,
699 /// An HTTPS address told of each budget alert with a JSON POST.
700 #[serde(default)]
701 pub budget_webhook: Option<String>,
Usage limits: unpaid usage can only go so far702}
703
Usage, Billing settings and prepaid AI credit; fixes from the UX audit704fn yes() -> bool {
705 true
706}
707
Usage limits: unpaid usage can only go so far708/// `limit`: a workspace's limit, for its members. Returns `Outcome<Limit>`.
709#[derive(Debug, Serialize, Deserialize)]
710pub struct LimitArgs {
711 pub workspace: String,
712 pub viewer: Viewer,
713}
714
715/// `check_limit`: the same, for the services that enforce it. Returns
716/// `Outcome<Limit>`.
717#[derive(Debug, Serialize, Deserialize)]
718pub struct CheckLimitArgs {
719 pub workspace: String,
720}
721
Prices keep themselves current with what g1t pays722/// `note_pending`: usage this month that will be charged later, such as
723/// app traffic past a plan, so the workspace's limit counts it now. Each
724/// report replaces the last for that workspace, source and month. Called
725/// by the service that meters it. Returns `bool`.
726#[derive(Debug, Serialize, Deserialize)]
727#[serde(rename_all = "camelCase")]
728pub struct NotePendingArgs {
729 pub workspace: String,
Fast pages, required checks on the branch, self-hosted runners, honest incidents730 /// `deployments`, `security` (scans), `context` (search embeddings),
731 /// `storage` or `cache` (actions/cache, plan only). Billing charges
732 /// `security`, `context`, `storage` and `cache` itself once the month
733 /// is over; `deployments` charges its own.
Prices keep themselves current with what g1t pays734 pub source: String,
735 /// What it cost g1t so far this month, before the margin.
736 pub cost_micros: i64,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas737 /// How much of it, for the Billing page: `1.2 million requests and
738 /// 3.4 million CPU ms`, `2 custom domains`.
739 #[serde(default)]
740 pub detail: Option<String>,
Prices keep themselves current with what g1t pays741}
742
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas743/// `usage_meters`: this month's usage for a workspace, one line per kind
744/// of meter, at what it is charged (cost plus the margin, on the account's
745/// terms) before the plan's included usage, the trial or g1t's pools paid
746/// for any of it. Members only. Returns `Outcome<Vec<MeterUsage>>`.
747#[derive(Debug, Serialize, Deserialize)]
748pub struct UsageMetersArgs {
749 pub workspace: String,
750 pub viewer: Viewer,
751}
752
753/// One kind of meter's usage this month.
754#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
755#[serde(rename_all = "camelCase")]
756pub struct MeterUsage {
757 /// `agents` (agent runs, models and sandboxes for checks, workflows
758 /// and the merge queue), `builds`, `requests` (app requests and CPU),
759 /// `domains`, `git_storage` (git operations and private storage) or
760 /// `search_scans` (search embeddings and security scans).
761 pub key: String,
762 pub label: String,
763 /// At price, before what paid for it.
764 pub micros: i64,
765 /// How much, when it is known: `12 runs`, `41 build minutes`.
766 #[serde(default)]
767 pub quantity: Option<String>,
768}
769
Usage limits: unpaid usage can only go so far770/// `set_spend_limit`: the owner's own monthly ceiling, under g1t's; None
771/// removes it. Owners only. Returns `Outcome<Limit>`.
772#[derive(Debug, Serialize, Deserialize)]
773#[serde(rename_all = "camelCase")]
774pub struct SetSpendLimitArgs {
775 pub actor: User,
776 pub workspace: String,
Two limits, real invoices, trust that grows by itself, sales signals777 /// A monthly limit, at most what is available; None goes back to the
778 /// default.
Usage limits: unpaid usage can only go so far779 pub spend_limit_micros: Option<i64>,
Two limits, real invoices, trust that grows by itself, sales signals780 /// Use everything available, with no limit of their own.
781 #[serde(default)]
782 pub use_full_limit: bool,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look783 /// Use the one-time raise: up to twice the highest ceiling the
784 /// workspace has had, without asking. Once per workspace.
785 #[serde(default, alias = "raiseOnce")]
786 pub raise_once: bool,
Usage limits: unpaid usage can only go so far787}
788
Prices keep themselves current with what g1t pays789/// One metered unit: what it costs g1t, and what it is sold at. The price
790/// is always `cost × (100 + markup) / 100`, so it follows the cost.
791#[derive(Clone, Debug, Serialize, Deserialize)]
792#[serde(rename_all = "camelCase")]
793pub struct Price {
794 /// `sandbox_second`, `build_second`, `app_requests`, `app_cpu`, `app_month`.
795 pub meter: String,
796 pub title: String,
797 pub unit: String,
798 /// Millionths of a dollar per unit; may have a fraction.
799 pub cost_micros: f64,
800 pub markup_percent: u32,
801 pub price_micros: f64,
802 /// `list`: Cloudflare's published price. `cloudflare`: what Cloudflare
803 /// actually billed g1t, measured.
804 pub source: String,
805 /// When it was last checked against Cloudflare's bill.
806 pub checked_at: Option<String>,
807 pub updated_at: String,
808}
809
810impl Price {
811 pub fn price_for(cost_micros: f64, markup_percent: u32) -> f64 {
812 cost_micros * f64::from(100 + markup_percent) / 100.0
813 }
814}
815
816/// A cost that moved.
817#[derive(Clone, Debug, Serialize, Deserialize)]
818#[serde(rename_all = "camelCase")]
819pub struct PriceChange {
820 pub meter: String,
821 pub old_cost_micros: f64,
822 pub new_cost_micros: f64,
823 pub markup_percent: u32,
Prices are what g1t pays plus 20%, from the first second824 /// The markup before, when the change was to the markup rather than
825 /// to the cost. Absent when the markup stayed `markup_percent`.
826 #[serde(default, skip_serializing_if = "Option::is_none")]
827 pub old_markup_percent: Option<u32>,
Prices keep themselves current with what g1t pays828 pub reason: String,
829 pub created_at: String,
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily830 /// When a change still to come takes effect: a rise is announced
831 /// before it is charged. Absent for changes already made.
832 #[serde(default, skip_serializing_if = "Option::is_none")]
833 pub effective_at: Option<String>,
Prices keep themselves current with what g1t pays834}
835
836/// `prices`: every metered price and the recent changes. Public. Returns
837/// `PriceBook`.
838#[derive(Clone, Debug, Serialize, Deserialize)]
839#[serde(rename_all = "camelCase")]
840pub struct PriceBook {
841 pub prices: Vec<Price>,
842 pub changes: Vec<PriceChange>,
843 /// The margin on model usage, which is charged at what AI Gateway
844 /// priced each request at.
845 pub model_margin_percent: u32,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put846 /// Every plan, as it is sold now.
847 #[serde(default)]
848 pub plans: Vec<Plan>,
849 /// What is free, and what pays for it.
850 #[serde(default)]
851 pub free: Option<FreeTier>,
Prices keep themselves current with what g1t pays852}
853
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put854/// What g1t gives without a plan, each with what pays for it: a capped
855/// budget, never an open-ended allowance.
856#[derive(Clone, Debug, Default, Serialize, Deserialize)]
857#[serde(rename_all = "camelCase")]
858pub struct FreeTier {
859 /// Each new workspace's trial credit, once.
860 pub trial_workspace_micros: i64,
861 /// Trial grants each month, in all; new trials wait when it is spent.
862 pub trial_monthly_pool_micros: i64,
863 /// g1t's open-source pool each month, and any one repository's share.
864 pub oss_pool_micros: i64,
865 pub oss_repo_micros: i64,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas866 /// Private repository storage that is free for every workspace. Past
867 /// it, the plan pays at cost plus the margin; a free workspace's pushes
868 /// to private repositories stop instead.
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put869 pub free_private_storage_bytes: i64,
Audit logs are kept by plan: a week on free, 90 days on the plan, and what staff set for an account in sudo870 /// Days of audit log a free workspace keeps.
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put871 pub audit_retention_days: u32,
Audit logs are kept by plan: a week on free, 90 days on the plan, and what staff set for an account in sudo872 /// Days of audit log the g1t plan keeps, and g1t's own and enterprise
873 /// workspaces. Longer is by arrangement, set per account in sudo.
874 #[serde(default)]
875 pub plan_audit_retention_days: u32,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look876 /// The smallest amount a card is charged when a month closes; less
877 /// carries over. Charges at a limit always go through.
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put878 pub min_charge_micros: i64,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas879 /// Git operations (clones, fetches and pushes through g1t) that are
880 /// free for every workspace each month. Past it, the plan pays at cost
881 /// plus the margin and is never slowed; a free workspace is slowed
882 /// down, never charged.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look883 #[serde(default)]
884 pub git_operations_included: u64,
885 /// A new paid workspace's ceiling in its first month.
886 #[serde(default)]
887 pub paid_start_ceiling_micros: i64,
888 /// The most a one-click goodwill credit can cost g1t.
889 #[serde(default)]
890 pub overage_forgive_cost_micros: i64,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put891}
892
Billing accounts, terms and enterprises; g1t is no longer free893/// Who pays: a billing account. Every workspace has one; by default its
894/// own. An enterprise account pays for several workspaces at once, as
895/// GitHub Enterprise does: one bill, one limit, one set of terms.
896#[derive(Clone, Debug, Serialize, Deserialize)]
897#[serde(rename_all = "camelCase")]
898pub struct BillingAccount {
899 /// `ws_<slug>` for a workspace's own account; `ent_…` for an enterprise.
900 pub id: String,
901 pub kind: AccountKind,
902 pub name: String,
903 pub terms: Terms,
904 /// The workspaces it pays for.
905 pub workspaces: Vec<String>,
Stripe webhooks, enterprise invoices, and sudo for both906 /// Where an enterprise's invoices go.
907 #[serde(default)]
908 pub billing_email: Option<String>,
909 /// An enterprise's invoices, newest first. Empty for a workspace's own.
910 #[serde(default)]
911 pub invoices: Vec<EnterpriseInvoice>,
Billing accounts, terms and enterprises; g1t is no longer free912 pub created_at: String,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put913 /// What g1t staff set for the account beyond its terms.
914 #[serde(default)]
915 pub allowances: Allowances,
916}
917
918/// Set per account by g1t staff in sudo, on top of its terms.
919#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
920#[serde(rename_all = "camelCase")]
921pub struct Allowances {
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look922 /// The g1t plan without paying for its monthly price, such as for a
923 /// partner. Usage is charged as usual. Comped accounts have it anyway.
924 #[serde(default, alias = "team")]
925 pub plan: bool,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put926 /// Each of the account's public repositories' monthly cap on g1t's
927 /// open-source pool, in place of `OSS_REPO_MICROS`. None: the default.
928 #[serde(default)]
929 pub oss_repo_micros: Option<i64>,
930 /// The trial credit each of its workspaces gets, in place of
931 /// `TRIAL_WORKSPACE_MICROS`, outside the monthly pool. None: the default.
932 #[serde(default)]
933 pub trial_micros: Option<i64>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look934 /// Agents at once, in place of the plan's (2 in the first month or on
935 /// the trial, then 10). None: the default.
936 #[serde(default)]
937 pub max_concurrent_agents: Option<u32>,
938 /// One run's spend cap, in place of `RUN_CAP_MICROS` and the owners'
939 /// own. None: theirs, or the default.
940 #[serde(default)]
941 pub run_cap_micros: Option<i64>,
942 /// What the agents on one issue may spend in all, in place of
943 /// `ISSUE_CAP_MICROS` and the owners' own. None: theirs, or the default.
944 #[serde(default)]
945 pub issue_cap_micros: Option<i64>,
Audit logs are kept by plan: a week on free, 90 days on the plan, and what staff set for an account in sudo946 /// Days of audit log its workspaces keep, in place of the plan's (7
947 /// free, 90 on the plan), longer or shorter. None: the plan's.
948 #[serde(default)]
949 pub audit_retention_days: Option<u32>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look950 /// A hold g1t staff put on new compute, with why. None: no hold.
951 #[serde(default)]
952 pub hold: Option<String>,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put953}
954
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look955/// `admin_set_allowances`: the plan on or off without charge, overrides of
956/// the plan's caps, a hold, and the account's share of g1t's pools.
957/// Recorded with who and why. Returns `Outcome<BillingAccount>`.
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put958#[derive(Debug, Serialize, Deserialize)]
959pub struct AdminSetAllowancesArgs {
960 pub id: String,
961 pub allowances: Allowances,
962 pub note: String,
963 pub by: String,
964}
965
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look966// --- Entitlements, and compute started under a reservation -----------------
967//
968// Every service that starts compute (sandboxes for agents, checks,
969// workflows and the merge queue; builds; models; semantic search) asks
970// billing first:
971//
972// 1. `entitlements { workspace }` says what the workspace may do at all:
973// its plan, whether it may start compute, its caps, and whether compute
974// is paused.
975// 2. `reserve { workspace, repo, public, kind, estimate_micros }` holds the
976// work's estimated cost against what may pay for it, so that starts at
977// the same moment cannot overshoot the ceiling together. It answers who
978// pays first, or refuses with a stable code and a message for the owner.
979// 3. `settle { reservation_id, actual_micros }` releases the hold once the
980// work is done. The charge itself goes on the ledger the usual way
981// (`finish_run`, `record_sandbox`, `charge_feature`, `note_pending`).
982//
983// A reservation never settled expires after `RESERVATION_HOURS`.
984
985/// A reservation that is never settled stops holding after this long.
986pub const RESERVATION_HOURS: u64 = 3;
987/// What a ceiling reads as when there is none (g1t's own workspaces): a
988/// billion dollars, which JavaScript holds exactly.
989pub const UNLIMITED_MICROS: i64 = 1_000_000_000_000_000;
990
991/// What a workspace pays g1t on, as far as compute is concerned.
992#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
993#[serde(rename_all = "snake_case")]
994pub enum PlanKind {
995 /// No plan: the forge is free; compute only from a trial or g1t's
996 /// open-source pool, after a card check.
997 Free,
998 /// The g1t plan, paid for (or given by g1t staff without its price).
999 Paid,
1000 /// g1t's own workspaces and Flagon's (comped terms): the plan without
1001 /// being charged. Usage is still recorded at what it cost.
1002 Internal,
1003 /// Paid for by an enterprise account, invoiced.
1004 Enterprise,
1005}
1006
1007impl PlanKind {
1008 pub fn as_str(self) -> &'static str {
1009 match self {
1010 PlanKind::Free => "free",
1011 PlanKind::Paid => "paid",
1012 PlanKind::Internal => "internal",
1013 PlanKind::Enterprise => "enterprise",
1014 }
1015 }
1016
1017 /// Whether usage past what is included may be charged (on demand).
1018 pub fn on_demand(self) -> bool {
1019 !matches!(self, PlanKind::Free)
1020 }
1021}
1022
1023/// What compute is for.
1024#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
1025#[serde(rename_all = "snake_case")]
1026pub enum ComputeKind {
1027 /// An agent's run: its sandbox and its model.
1028 Agent,
1029 /// Checks on a pull request.
1030 Check,
1031 /// A workflow job.
1032 Workflow,
1033 /// The merge queue's checks.
1034 Queue,
1035 /// A deployment's build.
1036 Deploy,
1037 /// Semantic search: embeddings in the context hub.
1038 Embedding,
1039}
1040
1041impl ComputeKind {
1042 pub fn as_str(self) -> &'static str {
1043 match self {
1044 ComputeKind::Agent => "agent",
1045 ComputeKind::Check => "check",
1046 ComputeKind::Workflow => "workflow",
1047 ComputeKind::Queue => "queue",
1048 ComputeKind::Deploy => "deploy",
1049 ComputeKind::Embedding => "embedding",
1050 }
1051 }
1052
1053 /// Whether g1t's open-source pool may pay for it on a public
1054 /// repository: checks, workflows and the merge queue only.
1055 pub fn open_source_pool(self) -> bool {
1056 matches!(self, ComputeKind::Check | ComputeKind::Workflow | ComputeKind::Queue)
1057 }
1058}
1059
1060/// Who pays first for reserved work. What the first source cannot cover
1061/// falls to the next, in this order.
1062#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
1063#[serde(rename_all = "snake_case")]
1064pub enum PaidBy {
1065 /// The plan's included usage this month.
1066 Credit,
1067 /// The workspace's one-time trial credit.
1068 Trial,
1069 /// g1t's open-source pool.
1070 Oss,
1071 /// Charged to the workspace, at cost plus the margin.
1072 OnDemand,
1073}
1074
1075/// `entitlements`: what a workspace may do now, for the services that
1076/// start compute and the pages that show it. Takes `EntitlementsArgs`;
1077/// returns `Entitlements`. No viewer: callers decide who sees it.
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put1078#[derive(Debug, Serialize, Deserialize)]
1079pub struct EntitlementsArgs {
1080 pub workspace: String,
1081}
1082
Audit logs are kept by plan: a week on free, 90 days on the plan, and what staff set for an account in sudo1083/// `audit_retention`: how many days of audit log each workspace keeps, for
1084/// the events service's daily purge. Takes `AuditRetentionArgs`; returns
1085/// `Vec<AuditRetention>`, one for each workspace asked about.
1086#[derive(Debug, Serialize, Deserialize)]
1087pub struct AuditRetentionArgs {
1088 pub workspaces: Vec<String>,
1089}
1090
1091#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1092pub struct AuditRetention {
1093 pub workspace: String,
1094 pub days: u32,
1095}
1096
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put1097#[derive(Clone, Debug, Serialize, Deserialize)]
1098#[serde(rename_all = "camelCase")]
1099pub struct Entitlements {
1100 pub workspace: String,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1101 pub plan: PlanKind,
1102 /// May start sandboxes, models, deployments and semantic search at all:
1103 /// paid, internal and enterprise workspaces, or a free one with trial
1104 /// credit left. A free workspace may still use the open-source pool
1105 /// for checks, workflows and the merge queue on public repositories
1106 /// after a card check; `reserve` decides that per start.
1107 pub compute: bool,
1108 /// The one-time trial credit left; 0 if none was granted or it is used.
1109 pub trial_micros_left: i64,
1110 /// A card check has been done. The trial and the open-source pool need
1111 /// it.
1112 pub trial_verified: bool,
1113 /// A paid workspace still in its first billing cycle.
1114 pub first_month: bool,
1115 /// Agents at once: 2 in the first month or on the trial, 10 after;
1116 /// staff can override it.
1117 pub max_concurrent_agents: u32,
1118 /// The longest one run may take: 60 minutes in the first month or on
1119 /// the trial; otherwise the guardrails' own caps (`MAX_MINUTES`).
1120 pub max_run_minutes: u32,
1121 /// One run's spend cap (`RUN_CAP_MICROS`, $2 by default); staff can
1122 /// override it.
1123 pub run_cap_micros: i64,
1124 /// What agents may spend on one issue in all (`ISSUE_CAP_MICROS`, $10
1125 /// by default); the owners can set it (`set_caps`), and staff override.
1126 pub issue_cap_micros: i64,
1127 /// Where on-demand work stops: g1t's ceiling on usage not yet paid
1128 /// for. `UNLIMITED_MICROS` for g1t's own workspaces; 0 for a free one,
1129 /// which has no on-demand usage.
1130 pub ceiling_micros: i64,
1131 /// Usage not yet paid for this month, with prepayment taken off.
1132 pub exposure_micros: i64,
1133 /// Why new compute is paused, for the owner: the limit is reached, a
1134 /// spend spike is waiting for an owner to confirm it, or g1t staff put
1135 /// a hold on it. None when it is not.
1136 pub paused: Option<String>,
1137 // What the workspace's plan gives it, for its pages.
1138 /// What open reservations hold now.
1139 #[serde(default)]
1140 pub held_micros: i64,
1141 /// Paid in advance and not used yet.
1142 #[serde(default)]
1143 pub prepaid_micros: i64,
1144 /// The plan's included usage each month, and what of it is used.
1145 #[serde(default)]
1146 pub included_micros: i64,
1147 #[serde(default)]
1148 pub included_used_micros: i64,
Audit logs are kept by plan: a week on free, 90 days on the plan, and what staff set for an account in sudo1149 /// How far back the audit log can be read and exported, and what is
1150 /// kept: the plan's days, or what g1t staff set for the account.
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put1151 pub audit_retention_days: u32,
Audit logs are kept by plan: a week on free, 90 days on the plan, and what staff set for an account in sudo1152 /// Whether `audit_retention_days` is what staff set for the account
1153 /// rather than the plan's.
1154 #[serde(default)]
1155 pub audit_retention_custom: bool,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1156 /// Private repository storage that is free for every workspace: past
1157 /// it, the plan pays for it and a free workspace's pushes stop.
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put1158 pub free_private_storage_bytes: i64,
1159 /// The last daily measure of the workspace's private repositories.
1160 pub private_storage_bytes: i64,
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member1161 /// On a paid plan (not Free): storage past the free amounts below is
1162 /// charged, so nothing is refused for it.
1163 #[serde(default)]
1164 pub has_plan: bool,
1165 /// Package storage free for every workspace, public and private: past
1166 /// it, the plan pays for it and a free workspace's pushes are refused.
1167 #[serde(default)]
1168 pub package_public_free_bytes: i64,
1169 #[serde(default)]
1170 pub package_private_free_bytes: i64,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put1171 /// What g1t's open-source pool paid for the workspace this month.
1172 pub oss_paid_micros: i64,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1173 /// Deploy build time this month, every second of it metered.
1174 #[serde(default)]
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put1175 pub build_seconds_used: u32,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1176 /// Git operations this month, and how many are free for every
1177 /// workspace (past it: metered on the plan, slowed when free).
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1178 #[serde(default)]
1179 pub git_operations: u64,
1180 #[serde(default)]
1181 pub git_operations_included: u64,
1182 /// The smallest amount a card is charged when a month closes.
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put1183 pub min_charge_micros: i64,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1184 /// A spend spike waiting for an owner, or decided.
1185 #[serde(default)]
1186 pub spike: Option<Spike>,
1187 /// Where usage stands against what is included and the limits, from 50%.
1188 #[serde(default)]
1189 pub alerts: Vec<UsageAlert>,
1190}
1191
1192/// One level reached: 50, 75, 90 or 100 percent of something.
1193#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1194#[serde(rename_all = "camelCase")]
1195pub struct UsageAlert {
1196 /// `included` (the plan's included usage), `spend_limit` (the owners'
1197 /// own limit) or `ceiling` (g1t's, on usage not yet paid for).
1198 pub meter: String,
1199 pub level: u32,
1200 pub used_micros: i64,
1201 pub limit_micros: i64,
1202 pub message: String,
Billing accounts, terms and enterprises; g1t is no longer free1203}
1204
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1205/// An hour's spend well above the workspace's usual pace: new compute
1206/// waits until an owner says to keep going.
1207#[derive(Clone, Debug, Serialize, Deserialize)]
1208#[serde(rename_all = "camelCase")]
1209pub struct Spike {
1210 pub id: String,
1211 /// `open` (waiting for an owner), `continued` (an owner said keep
1212 /// going) or `stopped` (an owner said stop).
1213 pub status: String,
1214 /// The hour's spend when it was found, and the usual hour's.
1215 pub hour_micros: i64,
1216 pub average_micros: i64,
1217 pub detected_at: String,
1218 #[serde(default)]
1219 pub decided_by: Option<String>,
1220 #[serde(default)]
1221 pub decided_at: Option<String>,
1222 /// While continued: until when, unless spend doubles again first.
1223 #[serde(default)]
1224 pub until: Option<String>,
1225}
1226
1227/// `reserve`: holds an estimate of a start's cost before the work starts.
1228/// Returns `Outcome<Reservation>`, or a failure whose code says why not:
1229///
1230/// - `paused`: a spend spike waiting for an owner, or a hold.
1231/// - `limit`: the spend limit or g1t's ceiling would be passed.
1232/// - `not_paid`: no plan, and nothing else pays for this kind of work (or
1233/// no card check yet).
1234/// - `trial_used`: the one-time trial is spent.
1235/// - `oss_pool_empty`: the open-source pool, or the repository's share of
1236/// it, is spent this month.
1237///
1238/// The message says exactly what to do, with the page to do it on (such as
1239/// `/acme/-/billing`).
1240#[derive(Debug, Serialize, Deserialize)]
1241#[serde(rename_all = "camelCase")]
1242pub struct ReserveArgs {
1243 pub workspace: String,
1244 pub repo: RepoPath,
1245 /// Whether the repository is public: the open-source pool pays only for
1246 /// public repositories' checks, workflows and merge queue.
1247 pub public: bool,
1248 pub kind: ComputeKind,
1249 /// The most the work is expected to cost g1t, before the margin, in
1250 /// millionths of a dollar (billing adds the margin, as it does to every
1251 /// charge). For an agent, its model's average plus its sandbox for its
1252 /// whole time cap.
1253 #[serde(alias = "estimate_micros")]
1254 pub estimate_micros: i64,
Spend caps: a monthly budget for comped workspaces and a daily breaker on what g1t pays1255 /// An agent run on g1t's hosted models (not the workspace's own
1256 /// provider). Unsaid, an agent run is taken to be one. g1t's daily
1257 /// spend breaker pauses these when g1t is paying for them.
1258 #[serde(default, alias = "hosted_model")]
1259 pub hosted_model: Option<bool>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1260}
1261
1262#[derive(Clone, Debug, Serialize, Deserialize)]
1263#[serde(rename_all = "camelCase")]
1264pub struct Reservation {
1265 pub id: String,
1266 pub paid_by: PaidBy,
1267 /// What is held, at cost; less than the estimate when a free
1268 /// workspace's last bit of trial credit is all there is.
1269 #[serde(default)]
1270 pub held_micros: i64,
1271 /// RFC 3339: when the hold lapses if never settled.
1272 #[serde(default)]
1273 pub expires_at: String,
1274}
1275
1276/// `settle`: releases a reservation's hold with what the work cost. The
1277/// charge goes on the ledger the usual way. Safe to repeat. Returns
1278/// `Outcome<bool>`: false if it was settled or had lapsed before.
1279#[derive(Debug, Serialize, Deserialize)]
1280#[serde(rename_all = "camelCase")]
1281pub struct SettleArgs {
1282 #[serde(alias = "reservation_id")]
1283 pub reservation_id: String,
1284 /// What the work cost g1t, before the margin.
1285 #[serde(alias = "actual_micros")]
1286 pub actual_micros: i64,
1287}
1288
1289// --- Card checks, the plan, prepayment -------------------------------------
1290
1291/// `card_check`: starts Stripe's page to save and verify a card: a setup
1292/// with 3-D Secure where the card supports it, which the card's bank sees
1293/// as a $0 or $1 authorization that is never charged. The trial and the
1294/// open-source pool need it, and it is the card the plan uses. Owners only.
1295/// Returns `Outcome<Checkout>`; the page's id comes back to `return_url` as
1296/// `session`, for `confirm_card_check`.
1297#[derive(Debug, Serialize, Deserialize)]
1298#[serde(rename_all = "camelCase")]
1299pub struct CardCheckArgs {
1300 pub actor: User,
1301 pub workspace: String,
1302 #[serde(alias = "return_url")]
1303 pub return_url: String,
1304}
1305
1306/// `confirm_card_check`: records the check once Stripe says the card was
1307/// verified, and grants the trial if the month's pool has room and the card
1308/// has not had one before. Safe to repeat. Returns `Outcome<Entitlements>`.
1309#[derive(Debug, Serialize, Deserialize)]
1310pub struct ConfirmCardCheckArgs {
1311 pub workspace: String,
1312 pub viewer: Viewer,
1313 pub session: String,
1314}
1315
1316// --- Limits: raising them, and spikes ---------------------------------------
1317
1318/// A request to g1t: a higher limit, or help with usage that went past
1319/// what was meant.
1320#[derive(Clone, Debug, Serialize, Deserialize)]
1321#[serde(rename_all = "camelCase")]
1322pub struct LimitRequest {
1323 pub id: String,
1324 pub workspace: String,
1325 /// `limit` (raise my limit) or `overage` (spent more than meant to).
1326 pub kind: String,
1327 /// The limit asked for; for an overage, what they think went wrong.
1328 pub amount_micros: i64,
1329 pub reason: String,
1330 pub expected_monthly_micros: i64,
1331 /// `open`, `approved` or `declined`.
1332 pub status: String,
1333 /// What was approved, which may differ from what was asked.
1334 #[serde(default)]
1335 pub decided_micros: Option<i64>,
1336 #[serde(default)]
1337 pub decided_by: Option<String>,
1338 /// The answer, as the owner sees it.
1339 #[serde(default)]
1340 pub answer: Option<String>,
1341 pub created_by: String,
1342 pub created_at: String,
1343 #[serde(default)]
1344 pub decided_at: Option<String>,
1345}
1346
1347/// `request_limit`: an owner asks g1t for more, or for help with usage past
1348/// what they meant. Answered within one business day, in the app and by
1349/// email. Owners only. Returns `Outcome<LimitRequest>`.
1350#[derive(Debug, Serialize, Deserialize)]
1351#[serde(rename_all = "camelCase")]
1352pub struct RequestLimitArgs {
1353 pub actor: User,
1354 pub workspace: String,
1355 /// `limit` or `overage`.
1356 pub kind: String,
1357 #[serde(alias = "amount_micros")]
1358 pub amount_micros: i64,
1359 pub reason: String,
1360 #[serde(default, alias = "expected_monthly_micros")]
1361 pub expected_monthly_micros: i64,
1362}
1363
1364/// `limit_requests`: a workspace's requests, newest first. Members only.
1365/// Returns `Outcome<Vec<LimitRequest>>`.
1366#[derive(Debug, Serialize, Deserialize)]
1367pub struct LimitRequestsArgs {
1368 pub workspace: String,
1369 pub viewer: Viewer,
1370}
1371
1372/// `confirm_spike`: an owner's answer to a spend spike. Keep going lifts the
1373/// pause for 24 hours, or until the hour's spend doubles again; stop keeps
1374/// new compute paused until an owner says to keep going. Owners only.
1375/// Returns `Outcome<Entitlements>`.
1376#[derive(Debug, Serialize, Deserialize)]
1377#[serde(rename_all = "camelCase")]
1378pub struct ConfirmSpikeArgs {
1379 pub actor: User,
1380 pub workspace: String,
1381 #[serde(alias = "keep_going")]
1382 pub keep_going: bool,
1383}
1384
1385/// `set_caps`: the owners' own caps on agents: one run's spend ($0.10 to
1386/// $100) and what the agents on one issue may spend in all ($1 to $1,000).
1387/// None goes back to the default ($2 and $10). A cap g1t staff set for the
1388/// account wins over both. Owners only. Returns `Outcome<Entitlements>`.
1389#[derive(Debug, Serialize, Deserialize)]
1390#[serde(rename_all = "camelCase")]
1391pub struct SetCapsArgs {
1392 pub actor: User,
1393 pub workspace: String,
1394 #[serde(default, alias = "run_cap_micros")]
1395 pub run_cap_micros: Option<i64>,
1396 #[serde(default, alias = "issue_cap_micros")]
1397 pub issue_cap_micros: Option<i64>,
1398}
1399
1400/// What staff see beside a request: the workspace's history with g1t.
1401#[derive(Clone, Debug, Default, Serialize, Deserialize)]
1402#[serde(rename_all = "camelCase")]
1403pub struct WorkspaceHistory {
1404 pub plan: Option<PlanKind>,
1405 /// The last six months, oldest first.
1406 pub months: Vec<MonthFigures>,
1407 /// Live payments that have cleared, and how many.
1408 pub paid_cleared_micros: i64,
1409 pub payments: u32,
1410 pub disputes: u32,
1411 pub declines: u32,
1412 /// The first time the workspace appears in billing, RFC 3339.
1413 pub first_seen: Option<String>,
1414 pub ceiling_micros: Option<i64>,
1415 pub max_ceiling_micros: Option<i64>,
1416 pub spend_limit_micros: Option<i64>,
1417 /// Recent velocity: the last hour, the usual hour over the last week,
1418 /// and the last 24 hours, at price.
1419 pub last_hour_micros: i64,
1420 pub average_hour_micros: i64,
1421 pub last_day_micros: i64,
1422}
1423
1424#[derive(Clone, Debug, Serialize, Deserialize)]
1425#[serde(rename_all = "camelCase")]
1426pub struct LimitRequestReview {
1427 pub request: LimitRequest,
1428 pub history: WorkspaceHistory,
1429}
1430
1431/// `admin_limit_requests`: requests for staff, oldest open first. Returns
1432/// `Vec<LimitRequestReview>`.
1433#[derive(Debug, Default, Serialize, Deserialize)]
1434pub struct AdminLimitRequestsArgs {
1435 /// `open` (the default), `approved`, `declined` or `all`.
1436 #[serde(default)]
1437 pub status: Option<String>,
1438}
1439
1440/// `admin_decide_limit_request`: approve (at the amount asked, or
1441/// `amount_micros`) or decline. The owner is told in the app and by email.
1442/// Recorded with who and why. Returns `Outcome<LimitRequest>`.
1443#[derive(Debug, Serialize, Deserialize)]
1444pub struct AdminDecideLimitRequestArgs {
1445 pub id: String,
1446 /// `approve` or `decline`.
1447 pub decision: String,
1448 #[serde(default)]
1449 pub amount_micros: Option<i64>,
1450 /// What the owner is told, beside the decision.
1451 #[serde(default)]
1452 pub note: String,
1453 pub by: String,
1454}
1455
1456/// `admin_record_payment`: money that reached g1t outside the card pages,
1457/// such as a bank transfer, entered as a payment (it raises the limit like
1458/// one). Recorded with who and the transfer's reference. Returns
1459/// `Outcome<LedgerEntry>`.
1460#[derive(Debug, Serialize, Deserialize)]
1461pub struct AdminRecordPaymentArgs {
1462 pub workspace: String,
1463 pub amount_micros: i64,
1464 /// The bank's reference for the transfer, or Stripe's payment id.
1465 pub reference: String,
1466 pub note: String,
1467 pub by: String,
1468}
1469
1470// --- Overages and goodwill (sudo) --------------------------------------------
1471
1472/// What a one-time goodwill credit would come to: g1t's margin on the
1473/// overage, always, plus as much of its underlying cost as the cap allows.
1474#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
1475#[serde(rename_all = "camelCase")]
1476pub struct Goodwill {
1477 /// This month's charges above the workspace's typical month.
1478 pub overage_micros: i64,
1479 /// The part of the overage that is g1t's margin.
1480 pub margin_micros: i64,
1481 /// The part that is what g1t paid its providers.
1482 pub cost_micros: i64,
1483 /// The one-click credit: the margin plus the cost up to the cap.
1484 pub credit_micros: i64,
1485 /// Of the credit, the real cost g1t absorbs.
1486 pub absorbed_micros: i64,
1487}
1488
1489/// A workspace whose month went well past its usual, or hit a spike.
1490#[derive(Clone, Debug, Serialize, Deserialize)]
1491#[serde(rename_all = "camelCase")]
1492pub struct Overage {
1493 pub workspace: String,
1494 pub plan: PlanKind,
1495 /// The median of its last three months' charges.
1496 pub typical_month_micros: i64,
1497 pub this_month_micros: i64,
1498 /// What this month cost g1t, and what g1t keeps of it.
1499 pub cost_micros: i64,
1500 pub margin_micros: i64,
1501 /// A spike this month, if there was one.
1502 pub spike: Option<Spike>,
1503 /// The runs that cost the most this month.
1504 pub top_entries: Vec<LedgerEntry>,
1505 pub goodwill: Goodwill,
1506 /// False when a goodwill credit was given in the last 12 months.
1507 pub goodwill_available: bool,
1508 pub last_goodwill_at: Option<String>,
1509 /// An open overage request from the owner, if there is one.
1510 pub request: Option<LimitRequest>,
1511}
1512
1513/// `admin_overages`: the Overages queue. Returns `Vec<Overage>`.
1514#[derive(Debug, Default, Serialize, Deserialize)]
1515pub struct AdminOveragesArgs {}
1516
1517/// `admin_goodwill`: credits a workspace for accidental usage. With no
1518/// amount, the one-click credit (`Goodwill::credit_micros`), once per
1519/// workspace in 12 months. A larger amount, or a second within 12 months,
1520/// needs a typed reason. It shows on the statement as "Credit from g1t:
1521/// accidental usage on <date>". Returns `Outcome<LedgerEntry>`.
1522#[derive(Debug, Serialize, Deserialize)]
1523pub struct AdminGoodwillArgs {
1524 pub workspace: String,
1525 #[serde(default)]
1526 pub amount_micros: Option<i64>,
1527 /// Why, typed by staff; needed past the one-click credit.
1528 #[serde(default)]
1529 pub reason: String,
1530 /// The day the accidental usage happened, `YYYY-MM-DD`; today if absent.
1531 #[serde(default)]
1532 pub day: Option<String>,
1533 pub by: String,
1534}
1535
1536/// One workspace's recent pace, for sudo's velocity view.
1537#[derive(Clone, Debug, Serialize, Deserialize)]
1538#[serde(rename_all = "camelCase")]
1539pub struct Velocity {
1540 pub workspace: String,
1541 pub plan: PlanKind,
1542 pub last_hour_micros: i64,
1543 pub average_hour_micros: i64,
1544 pub last_day_micros: i64,
1545 pub this_month_micros: i64,
1546 /// The last hour over the usual hour; 0 with no history.
1547 pub ratio: f64,
1548 pub spike: Option<Spike>,
1549 pub first_seen: Option<String>,
1550}
1551
1552/// `admin_velocity`: workspaces spending in the last day, fastest first.
1553/// Returns `Vec<Velocity>`.
1554#[derive(Debug, Default, Serialize, Deserialize)]
1555pub struct AdminVelocityArgs {}
1556
Billing accounts, terms and enterprises; g1t is no longer free1557#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
1558#[serde(rename_all = "snake_case")]
1559pub enum AccountKind {
1560 Workspace,
1561 Enterprise,
1562}
1563
1564/// How an account is charged. Standard unless g1t set otherwise in sudo.
1565#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1566#[serde(rename_all = "camelCase")]
1567pub struct Terms {
1568 pub kind: TermsKind,
1569 /// Off every usage charge, in percent. Custom terms only.
1570 #[serde(default)]
1571 pub discount_percent: u32,
1572 /// A ceiling on unpaid usage that replaces the one trust would give.
1573 #[serde(default)]
1574 pub ceiling_micros: Option<i64>,
1575 /// Why, for whoever looks next.
1576 #[serde(default)]
1577 pub note: String,
1578 /// When the terms end and the account goes back to standard.
1579 #[serde(default)]
1580 pub until: Option<String>,
1581 #[serde(default)]
1582 pub set_by: Option<String>,
1583 #[serde(default)]
1584 pub set_at: Option<String>,
1585}
1586
1587impl Terms {
1588 pub fn standard() -> Self {
1589 Terms {
1590 kind: TermsKind::Standard,
1591 discount_percent: 0,
1592 ceiling_micros: None,
1593 note: String::new(),
1594 until: None,
1595 set_by: None,
1596 set_at: None,
1597 }
1598 }
1599
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging1600 /// The discount in percent, 0 to 100. Terms from before discounts
1601 /// replaced "comped" read as 100%.
1602 pub fn percent_off(&self) -> u32 {
1603 match self.kind {
1604 TermsKind::Comped => 100,
1605 TermsKind::Custom => self.discount_percent.min(100),
1606 TermsKind::Standard => 0,
1607 }
1608 }
1609
1610 /// A 100% discount: nothing is charged, usage is recorded at its price
1611 /// and discounted in full. g1t's own workspaces and partners. Paid
1612 /// features are on without a plan, and g1t's own spend on it is held to
1613 /// a monthly budget (the terms' ceiling, at cost).
1614 pub fn full_discount(&self) -> bool {
1615 self.percent_off() >= 100
1616 }
1617
Billing accounts, terms and enterprises; g1t is no longer free1618 /// What a charge becomes under these terms.
1619 pub fn apply(&self, charge_micros: i64) -> i64 {
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging1620 charge_micros * i64::from(100 - self.percent_off()) / 100
Billing accounts, terms and enterprises; g1t is no longer free1621 }
Merge branch 'worktree-agent-a633ac0f7f66d419d'1622
1623 /// What a charge at cost plus the margin becomes under these terms, and
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging1624 /// what the discount took off it (`ledger.discount_micros`), so the
1625 /// statement shows the usage at its price and the discount beside it,
1626 /// and a discount below cost plus the margin is counted as given, never
1627 /// lost. A 100% discount takes it all.
Merge branch 'worktree-agent-a633ac0f7f66d419d'1628 pub fn discounted(&self, charge_micros: i64) -> (i64, i64) {
1629 let charged = self.apply(charge_micros);
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging1630 (charged, (charge_micros - charged).max(0))
1631 }
1632
1633 /// How the statement and sudo name the terms: `100% discount`, `30% off`.
1634 pub fn discount_label(&self) -> Option<String> {
1635 match self.percent_off() {
1636 0 => None,
1637 100 => Some("100% discount".to_owned()),
1638 percent => Some(format!("{percent}% off")),
Merge branch 'worktree-agent-a633ac0f7f66d419d'1639 }
1640 }
Billing accounts, terms and enterprises; g1t is no longer free1641}
1642
1643#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
1644#[serde(rename_all = "snake_case")]
1645pub enum TermsKind {
1646 /// Prices as published, limits by trust.
1647 Standard,
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging1648 /// Before discounts: what a 100% discount is now. Read as one
1649 /// (`Terms::percent_off`); billing never writes it (migration 0039).
Billing accounts, terms and enterprises; g1t is no longer free1650 Comped,
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging1651 /// A discount (up to 100%), a ceiling, or both.
Billing accounts, terms and enterprises; g1t is no longer free1652 Custom,
1653}
1654
Stripe webhooks, enterprise invoices, and sudo for both1655/// `stripe_webhook`: an event from Stripe, as the API received it: the raw
1656/// body and its `Stripe-Signature` header. Billing checks the signature
1657/// against the secret of the endpoint it registered, and handles each
1658/// event once. Returns `Outcome<bool>`: false for one already handled.
1659#[derive(Debug, Serialize, Deserialize)]
1660pub struct StripeWebhookArgs {
1661 pub payload: String,
1662 pub signature: String,
1663}
1664
1665/// `admin_stripe`: where billing stands with Stripe. Staff only. Returns
Stripe's webhook secret is a Worker secret, STRIPE_WEBHOOK_SECRET, from a destination made in Stripe's dashboard1666/// `StripeStatus`. With `fix: true`, first enables the destination at
1667/// billing's address and gives it the events billing needs.
Stripe webhooks, enterprise invoices, and sudo for both1668#[derive(Debug, Default, Serialize, Deserialize)]
1669pub struct AdminStripeArgs {
1670 #[serde(default)]
Stripe's webhook secret is a Worker secret, STRIPE_WEBHOOK_SECRET, from a destination made in Stripe's dashboard1671 pub fix: bool,
Stripe webhooks, enterprise invoices, and sudo for both1672 #[serde(default)]
1673 pub by: Option<String>,
1674}
1675
1676#[derive(Clone, Debug, Serialize, Deserialize)]
1677#[serde(rename_all = "camelCase")]
1678pub struct StripeStatus {
1679 /// `test` or `live`, from the key; `off` without one.
1680 pub mode: String,
Stripe's webhook secret is a Worker secret, STRIPE_WEBHOOK_SECRET, from a destination made in Stripe's dashboard1681 /// Whether `STRIPE_WEBHOOK_SECRET` is set, so events can be checked.
1682 pub secret_set: bool,
1683 /// The destination at billing's address in Stripe, as Stripe has it.
Stripe webhooks, enterprise invoices, and sudo for both1684 pub webhook: Option<StripeWebhook>,
Stripe's webhook secret is a Worker secret, STRIPE_WEBHOOK_SECRET, from a destination made in Stripe's dashboard1685 /// Events billing handles that the destination does not send.
1686 pub missing_events: Vec<String>,
Stripe webhooks, enterprise invoices, and sudo for both1687 /// The latest events handled, newest first.
1688 pub recent_events: Vec<StripeEventSummary>,
Stripe's webhook secret is a Worker secret, STRIPE_WEBHOOK_SECRET, from a destination made in Stripe's dashboard1689 /// What went wrong reading or fixing the destination, if it did.
Stripe webhooks, enterprise invoices, and sudo for both1690 pub error: Option<String>,
1691}
1692
1693#[derive(Clone, Debug, Serialize, Deserialize)]
1694#[serde(rename_all = "camelCase")]
1695pub struct StripeWebhook {
1696 pub url: String,
1697 pub endpoint_id: String,
Stripe's webhook secret is a Worker secret, STRIPE_WEBHOOK_SECRET, from a destination made in Stripe's dashboard1698 /// `enabled` or `disabled`.
1699 pub status: String,
Stripe webhooks, enterprise invoices, and sudo for both1700 pub events: Vec<String>,
1701 pub created_at: String,
1702}
1703
1704#[derive(Clone, Debug, Serialize, Deserialize)]
1705#[serde(rename_all = "camelCase")]
1706pub struct StripeEventSummary {
1707 pub id: String,
1708 pub kind: String,
1709 pub outcome: String,
1710 pub received_at: String,
1711}
1712
1713/// `admin_enterprise_billing`: where an enterprise's invoices go. Creates
1714/// or updates its Stripe customer. Returns `Outcome<BillingAccount>`.
1715#[derive(Debug, Serialize, Deserialize)]
1716pub struct AdminEnterpriseBillingArgs {
1717 pub id: String,
1718 pub email: String,
1719 pub by: String,
1720}
1721
Merge Stripe Tax, the card fee on card payments, and one free workspace per person1722/// `admin_enterprise_address`: the enterprise's billing address and tax ID,
1723/// saved on its Stripe customer (made by `admin_enterprise_billing`).
1724/// Stripe Tax works its invoices' tax out from the address; an invoice is
1725/// not sent without one. Returns `Outcome<bool>`.
1726#[derive(Debug, Serialize, Deserialize)]
1727#[serde(rename_all = "camelCase")]
1728pub struct AdminEnterpriseAddressArgs {
1729 pub id: String,
1730 pub address: PostalAddress,
1731 #[serde(default, alias = "tax_id_type")]
1732 pub tax_id_type: Option<String>,
1733 #[serde(default, alias = "tax_id")]
1734 pub tax_id: Option<String>,
1735 pub by: String,
1736}
1737
Stripe webhooks, enterprise invoices, and sudo for both1738/// `admin_invoice_enterprise`: sends an enterprise its invoice now, for
1739/// what its workspaces owe, rather than waiting for the month to close.
1740/// Returns `Outcome<EnterpriseInvoice>`.
1741#[derive(Debug, Serialize, Deserialize)]
1742pub struct AdminInvoiceEnterpriseArgs {
1743 pub id: String,
1744 pub by: String,
1745}
1746
1747/// An enterprise's invoice: one line per workspace, paid on Stripe.
1748#[derive(Clone, Debug, Serialize, Deserialize)]
1749#[serde(rename_all = "camelCase")]
1750pub struct EnterpriseInvoice {
1751 pub invoice_id: String,
1752 /// Stripe's page for it, where it is paid.
1753 pub hosted_url: Option<String>,
1754 pub amount_micros: i64,
1755 /// `open`, `paid`, `overdue` or `void`.
1756 pub status: String,
1757 pub period: String,
1758 pub lines: Vec<InvoiceLine>,
1759 pub created_at: String,
1760}
1761
1762#[derive(Clone, Debug, Serialize, Deserialize)]
1763#[serde(rename_all = "camelCase")]
1764pub struct InvoiceLine {
1765 pub workspace: String,
1766 pub amount_micros: i64,
1767}
1768
Two limits, real invoices, trust that grows by itself, sales signals1769/// A workspace's invoice from g1t: one per month, and one each time it is
1770/// charged near its limit. Itemised, charged to the card on file, and kept
1771/// in Stripe's billing page with its PDF.
1772#[derive(Clone, Debug, Serialize, Deserialize)]
1773#[serde(rename_all = "camelCase")]
1774pub struct WorkspaceInvoice {
1775 pub invoice_id: String,
1776 pub workspace: String,
1777 /// `month` (2026-10) or `threshold`.
1778 pub reason: String,
1779 pub period: String,
1780 pub amount_micros: i64,
1781 /// `paid`, `open`, `failed` or `void`.
1782 pub status: String,
1783 pub hosted_url: Option<String>,
1784 pub pdf_url: Option<String>,
1785 pub lines: Vec<InvoiceItem>,
1786 pub created_at: String,
Merge Stripe Tax, the card fee on card payments, and one free workspace per person1787 /// The card processing fee on top of `amount_micros`, when the invoice
1788 /// is charged to a card; never part of the usage it pays for.
1789 #[serde(default)]
1790 pub fee_micros: i64,
1791 /// The tax Stripe added on top, once it is known (after paying).
1792 #[serde(default)]
1793 pub tax_micros: i64,
Two limits, real invoices, trust that grows by itself, sales signals1794}
1795
1796#[derive(Clone, Debug, Serialize, Deserialize)]
1797#[serde(rename_all = "camelCase")]
1798pub struct InvoiceItem {
1799 pub description: String,
1800 pub amount_micros: i64,
1801}
1802
1803/// `invoices`: a workspace's invoices from g1t, newest first. Members
1804/// only. Returns `Outcome<Vec<WorkspaceInvoice>>`.
1805#[derive(Debug, Serialize, Deserialize)]
1806pub struct InvoicesArgs {
1807 pub workspace: String,
1808 pub viewer: Viewer,
1809}
1810
1811/// `admin_workspace_invoices`: the same, for staff. Returns
1812/// `Vec<WorkspaceInvoice>`.
1813#[derive(Debug, Serialize, Deserialize)]
1814pub struct AdminWorkspaceInvoicesArgs {
1815 pub workspace: String,
1816}
1817
The statement is a month at a time, a line per kind of charge1818/// `statement`: a month of a workspace's ledger, grouped by day (or by
1819/// project) with a line per kind of charge. Members only. Returns
1820/// `Outcome<Statement>`.
1821#[derive(Debug, Serialize, Deserialize)]
1822pub struct StatementArgs {
1823 pub workspace: String,
1824 pub viewer: Viewer,
1825 /// YYYY-MM; this month when absent.
1826 #[serde(default)]
1827 pub month: Option<String>,
1828 /// `day` (the default) or `project`.
1829 #[serde(default)]
1830 pub group: Option<String>,
1831}
1832
1833#[derive(Clone, Debug, Serialize, Deserialize)]
1834#[serde(rename_all = "camelCase")]
1835pub struct Statement {
1836 pub month: String,
1837 /// Months with any entries, newest first.
1838 pub months: Vec<String>,
1839 pub groups: Vec<StatementGroup>,
1840 pub totals: StatementTotals,
1841}
1842
1843#[derive(Clone, Debug, Serialize, Deserialize)]
1844#[serde(rename_all = "camelCase")]
1845pub struct StatementGroup {
1846 /// The day (YYYY-MM-DD) or the project (`owner/name`, or empty).
1847 pub key: String,
1848 pub label: String,
1849 pub lines: Vec<StatementLine>,
1850 /// What the group's charges come to.
1851 pub charged_micros: i64,
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging1852 /// Its usage at price, and what the discount took off it.
1853 #[serde(default)]
1854 pub price_micros: i64,
1855 #[serde(default)]
1856 pub discount_micros: i64,
The statement is a month at a time, a line per kind of charge1857}
1858
1859#[derive(Clone, Debug, Serialize, Deserialize)]
1860#[serde(rename_all = "camelCase")]
1861pub struct StatementLine {
1862 /// Agent runs, Sandbox time, Deployments, Payments, Credits from g1t,
Prices are what g1t pays plus 20%, from the first second1863 /// Refunds, and, for older entries, Runs on your own model provider.
The statement is a month at a time, a line per kind of charge1864 pub kind: String,
1865 pub count: u32,
1866 /// Charges positive; money in (payments, credits) negative.
1867 pub charged_micros: i64,
1868 pub cost_micros: i64,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put1869 /// Of the usage on the line, what was paid for before it was charged:
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1870 /// by the plan's included usage, the trial credit, g1t's open-source
1871 /// pool, or g1t itself. Not in `charged_micros`.
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put1872 #[serde(default)]
1873 pub covered_micros: i64,
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging1874 /// Usage at its price: charged, plus what paid for it and what the
1875 /// discount took off. Zero for money in.
1876 #[serde(default)]
1877 pub price_micros: i64,
1878 /// What the account's discount took off the line's price.
1879 #[serde(default)]
1880 pub discount_micros: i64,
Merge Stripe Tax, the card fee on card payments, and one free workspace per person1881 /// On the `Tax` and `Card processing fees` lines: what was paid with
1882 /// payments on top of what reached the balance (negative for what a
1883 /// refund gave back). Never in `charged_micros` or the balance.
1884 #[serde(default)]
1885 pub passed_micros: i64,
The statement is a month at a time, a line per kind of charge1886}
1887
1888#[derive(Clone, Debug, Serialize, Deserialize)]
1889#[serde(rename_all = "camelCase")]
1890pub struct StatementTotals {
1891 pub charged_micros: i64,
1892 pub paid_micros: i64,
1893 pub cost_micros: i64,
1894 pub entries: u32,
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging1895 /// Usage at price, and what the discount took off it: charged is the
1896 /// price less the discount and what paid for it.
1897 #[serde(default)]
1898 pub price_micros: i64,
1899 #[serde(default)]
1900 pub discount_micros: i64,
1901 /// The account's discount now, in percent; absent without one.
1902 #[serde(default)]
1903 pub discount_percent: Option<u32>,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put1904 /// What paid for usage before it was charged, one line per source,
1905 /// such as "Paid by g1t's open-source pool".
1906 #[serde(default)]
1907 pub covered: Vec<Covered>,
1908 /// Owed when the month closed but under the minimum charge, so it
1909 /// carries over to the next invoice. Zero when nothing carried.
1910 #[serde(default)]
1911 pub carried_micros: i64,
Merge Stripe Tax, the card fee on card payments, and one free workspace per person1912 /// Tax and card processing fees paid with the month's payments, on top
1913 /// of `paid_micros`.
1914 #[serde(default)]
1915 pub tax_micros: i64,
1916 #[serde(default)]
1917 pub card_fee_micros: i64,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put1918}
1919
1920/// One source that paid for usage before it was charged.
1921#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1922#[serde(rename_all = "camelCase")]
1923pub struct Covered {
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1924 /// `included`, `trial`, `oss_pool` or `given`.
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put1925 pub source: String,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1926 /// "Paid by your plan's included usage", "Paid by your trial credit",
1927 /// "Paid by g1t's open-source pool", "Covered by g1t".
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put1928 pub label: String,
1929 pub micros: i64,
The statement is a month at a time, a line per kind of charge1930}
1931
1932/// `statement_entries`: one statement line's entries, newest first, 50 at
1933/// a time (`before` = the last id seen). Returns `Outcome<Vec<LedgerEntry>>`.
1934#[derive(Debug, Serialize, Deserialize)]
1935pub struct StatementEntriesArgs {
1936 pub workspace: String,
1937 pub viewer: Viewer,
1938 pub month: String,
1939 pub kind: String,
1940 #[serde(default)]
1941 pub day: Option<String>,
1942 #[serde(default)]
1943 pub project: Option<String>,
1944 #[serde(default)]
1945 pub before: Option<String>,
1946}
1947
Two limits, real invoices, trust that grows by itself, sales signals1948// --- Sales (sudo.g1t.sh) ------------------------------------------------------
1949//
1950// What staff need to know to reach out: who is growing, who is close to
1951// their limit, who was declined, who has become a steady customer. And what
1952// was done about it: a stage, an owner on g1t's side, a next step, notes.
1953
1954/// Why a workspace is worth a look.
1955#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
1956#[serde(rename_all = "snake_case")]
1957pub enum SignalKind {
1958 /// At its limit, or its own spend limit: work is stopped.
1959 AtLimit,
1960 /// Past 80% of what is available to it: about to need more.
1961 NearCeiling,
1962 /// Its card was declined or a payment disputed.
1963 Declined,
1964 /// This month is well ahead of last month.
1965 Growing,
1966 /// Became Established: the ceiling now follows its spend.
1967 Established,
1968 /// Paid g1t for the first time.
1969 FirstPayment,
1970 /// Spending enough that custom terms or an enterprise may suit it.
1971 HighSpend,
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily1972 /// Costs g1t more on Cloudflare than it pays, over 30 days: a pricing
1973 /// gap or abuse to look at (billing's `margin`).
1974 CostOverRevenue,
Two limits, real invoices, trust that grows by itself, sales signals1975}
1976
1977#[derive(Clone, Debug, Serialize, Deserialize)]
1978#[serde(rename_all = "camelCase")]
1979pub struct Signal {
1980 pub workspace: String,
1981 pub kind: SignalKind,
1982 /// One sentence, with the figures.
1983 pub detail: String,
1984 /// The figure that matters, such as this month's spend.
1985 pub value_micros: i64,
1986 /// Its sales stage, if staff gave it one.
1987 pub stage: Option<String>,
1988 pub owner: Option<String>,
Billing lists every invoice and every staff change; signals carry follow-ups1989 #[serde(default)]
1990 pub next_step: Option<String>,
1991 /// When the next step is due, `YYYY-MM-DD`.
1992 #[serde(default)]
1993 pub next_at: Option<String>,
1994}
1995
1996/// `admin_invoices`: every invoice g1t has sent, workspaces' and
1997/// enterprises', newest first. Returns `Vec<InvoiceSummary>`.
1998#[derive(Debug, Default, Serialize, Deserialize)]
1999pub struct AdminInvoicesArgs {
2000 /// `paid`, `open`, `failed`, `overdue` or `void`.
2001 #[serde(default)]
2002 pub status: Option<String>,
2003 /// YYYY-MM, by when it was sent.
2004 #[serde(default)]
2005 pub month: Option<String>,
2006}
2007
2008#[derive(Clone, Debug, Serialize, Deserialize)]
2009#[serde(rename_all = "camelCase")]
2010pub struct InvoiceSummary {
2011 pub invoice_id: String,
2012 /// `workspace` or `enterprise`.
2013 pub kind: String,
2014 /// The workspace's slug, or the enterprise's account id.
2015 pub account: String,
2016 /// What to call it: the workspace, or the enterprise's name.
2017 pub name: String,
2018 pub reason: String,
2019 pub period: String,
2020 pub amount_micros: i64,
2021 pub status: String,
2022 pub hosted_url: Option<String>,
2023 pub created_at: String,
2024 pub paid_at: Option<String>,
2025}
2026
2027/// `admin_audit`: every change made in sudo, and by Stripe, newest first.
2028/// Returns `Vec<AdminAction>`.
2029#[derive(Debug, Default, Serialize, Deserialize)]
2030pub struct AdminAuditArgs {
2031 #[serde(default)]
2032 pub by: Option<String>,
2033 #[serde(default)]
2034 pub action: Option<String>,
2035 /// Only those before this time, for paging.
2036 #[serde(default)]
2037 pub before: Option<String>,
Two limits, real invoices, trust that grows by itself, sales signals2038}
2039
2040/// `admin_signals`: every workspace worth reaching out to, most urgent
2041/// first. Returns `Vec<Signal>`.
2042#[derive(Debug, Default, Serialize, Deserialize)]
2043pub struct AdminSignalsArgs {}
2044
2045/// What staff are doing about a workspace.
2046#[derive(Clone, Debug, Serialize, Deserialize)]
2047#[serde(rename_all = "camelCase")]
2048pub struct SalesRecord {
2049 pub workspace: String,
2050 /// `none`, `lead`, `contacted`, `negotiating`, `won`, `lost` or `churn_risk`.
2051 pub stage: String,
2052 /// The staff member looking after it.
2053 pub owner: Option<String>,
2054 pub next_step: Option<String>,
2055 /// RFC 3339 date.
2056 pub next_at: Option<String>,
2057 pub notes: Vec<SalesNote>,
2058 pub updated_at: Option<String>,
2059}
2060
2061#[derive(Clone, Debug, Serialize, Deserialize)]
2062#[serde(rename_all = "camelCase")]
2063pub struct SalesNote {
2064 pub id: String,
2065 pub text: String,
2066 pub by: String,
2067 pub created_at: String,
2068}
2069
2070/// `admin_sales`: a workspace's sales record. Returns `SalesRecord`.
2071#[derive(Debug, Serialize, Deserialize)]
2072pub struct AdminSalesArgs {
2073 pub workspace: String,
2074}
2075
2076/// `admin_set_sales`: its stage, owner and next step. Returns `Outcome<SalesRecord>`.
2077#[derive(Debug, Serialize, Deserialize)]
2078pub struct AdminSetSalesArgs {
2079 pub workspace: String,
2080 pub stage: String,
2081 #[serde(default)]
2082 pub owner: Option<String>,
2083 #[serde(default)]
2084 pub next_step: Option<String>,
2085 #[serde(default)]
2086 pub next_at: Option<String>,
2087 pub by: String,
2088}
2089
2090/// `admin_add_note`. Returns `Outcome<SalesRecord>`.
2091#[derive(Debug, Serialize, Deserialize)]
2092pub struct AdminAddNoteArgs {
2093 pub workspace: String,
2094 pub text: String,
2095 pub by: String,
2096}
2097
2098/// `admin_overview`: the business at a glance. Returns `Overview`.
2099#[derive(Debug, Default, Serialize, Deserialize)]
2100pub struct AdminOverviewArgs {}
2101
2102#[derive(Clone, Debug, Serialize, Deserialize)]
2103#[serde(rename_all = "camelCase")]
2104pub struct Overview {
2105 /// YYYY-MM.
2106 pub month: String,
2107 /// The last six months, oldest first, all workspaces together.
2108 pub months: Vec<MonthFigures>,
2109 /// This month by kind of usage: models, sandbox, deployments, plans.
2110 pub by_kind: Vec<KindFigures>,
2111 pub paying_workspaces: u32,
2112 pub stopped: u32,
2113 pub near_ceiling: u32,
2114 pub declined: u32,
2115 /// Sent and not yet paid, workspaces and enterprises.
2116 pub open_invoices_micros: i64,
2117 /// Follow-ups due today or earlier.
2118 pub follow_ups_due: u32,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put2119 /// The capped budgets g1t pays from, this month.
2120 #[serde(default)]
2121 pub pools: Option<Pools>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look2122 /// This month's revenue: usage charged plus the plan's price paid.
2123 #[serde(default)]
2124 pub revenue_micros: i64,
2125 /// Workspaces on the paid plan now, and what their price comes to a
2126 /// month.
2127 #[serde(default)]
2128 pub active_plans: u32,
2129 #[serde(default)]
2130 pub plan_mrr_micros: i64,
2131 /// What g1t gave this month, by source, apart from its margin.
2132 #[serde(default)]
2133 pub given: Vec<GivenFigures>,
2134 /// g1t's own and Flagon's workspaces this month: what their use cost,
2135 /// and why they are not charged.
2136 #[serde(default)]
2137 pub internal: Vec<InternalUse>,
2138 /// Open limit requests, and workspaces in the Overages queue.
2139 #[serde(default)]
2140 pub open_requests: u32,
2141 #[serde(default)]
2142 pub overages: u32,
2143 /// Spend spikes waiting for an owner.
2144 #[serde(default)]
2145 pub open_spikes: u32,
Two limits, real invoices, trust that grows by itself, sales signals2146}
2147
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look2148/// What g1t gave this month from one source.
2149#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
2150#[serde(rename_all = "camelCase")]
2151pub struct GivenFigures {
2152 /// `internal`, `trial`, `oss_pool`, `goodwill` or `covered`.
2153 pub source: String,
2154 pub label: String,
2155 /// At price, and what it cost g1t.
2156 pub micros: i64,
2157 pub cost_micros: i64,
2158}
2159
2160/// One internal workspace's use this month.
2161#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
2162#[serde(rename_all = "camelCase")]
2163pub struct InternalUse {
2164 pub workspace: String,
2165 /// Why it is not charged: its terms' note.
2166 pub reason: String,
2167 pub cost_micros: i64,
2168 pub entries: u32,
2169}
2170
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put2171/// g1t's capped budgets for free usage, this calendar month (UTC).
2172#[derive(Clone, Debug, Default, Serialize, Deserialize)]
2173#[serde(rename_all = "camelCase")]
2174pub struct Pools {
2175 /// YYYY-MM.
2176 pub month: String,
2177 /// Trial grants made this month, against the month's pool.
2178 pub trial_granted_micros: i64,
2179 pub trial_pool_micros: i64,
2180 pub trial_grants: u32,
2181 /// What the open-source pool paid this month, against its cap.
2182 pub oss_used_micros: i64,
2183 pub oss_pool_micros: i64,
2184 /// Each public repository's monthly cap on the pool.
2185 pub oss_repo_micros: i64,
2186}
2187
Two limits, real invoices, trust that grows by itself, sales signals2188#[derive(Clone, Debug, Serialize, Deserialize)]
2189#[serde(rename_all = "camelCase")]
2190pub struct KindFigures {
2191 pub kind: String,
2192 pub charged_micros: i64,
2193 pub cost_micros: i64,
2194}
2195
Billing accounts, terms and enterprises; g1t is no longer free2196// --- Staff (sudo.g1t.sh) ------------------------------------------------------
2197//
2198// Called only by the sudo app, which only g1t staff can reach (behind
2199// Cloudflare Access). Each change names who made it, and is kept in the
2200// audit log.
2201
2202/// `admin_accounts`: every billing account, with where each stands this
2203/// month. Returns `Vec<AccountSummary>`.
2204#[derive(Debug, Default, Serialize, Deserialize)]
2205pub struct AdminAccountsArgs {
2206 #[serde(default)]
2207 pub query: Option<String>,
Stripe webhooks, enterprise invoices, and sudo for both2208 /// Exactly these workspaces' accounts, such as one page of sudo's
2209 /// list; every account with activity when absent.
2210 #[serde(default)]
2211 pub workspaces: Option<Vec<String>>,
Billing accounts, terms and enterprises; g1t is no longer free2212}
2213
2214#[derive(Clone, Debug, Serialize, Deserialize)]
2215#[serde(rename_all = "camelCase")]
2216pub struct AccountSummary {
2217 pub account: BillingAccount,
2218 pub limit: Limit,
2219 /// Charged this month, after terms.
2220 pub charged_micros: i64,
2221 /// What this month's usage cost g1t.
2222 pub cost_micros: i64,
2223 /// Paid, ever.
2224 pub paid_micros: i64,
Billing on Stripe's pages, month-end charges, warnings; sudo by workspace2225 /// The same figures for each of the account's workspaces that has
2226 /// any, so staff can see what one member of an enterprise used.
2227 #[serde(default)]
2228 pub by_workspace: Vec<WorkspaceFigures>,
Two limits, real invoices, trust that grows by itself, sales signals2229 /// The last six months, oldest first, for trends.
2230 #[serde(default)]
2231 pub months: Vec<MonthFigures>,
2232}
2233
2234/// One month of an account's billing.
2235#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
2236#[serde(rename_all = "camelCase")]
2237pub struct MonthFigures {
2238 /// YYYY-MM.
2239 pub month: String,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look2240 /// Usage charged, after what paid for it first.
Two limits, real invoices, trust that grows by itself, sales signals2241 pub charged_micros: i64,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look2242 /// What usage cost g1t: only what g1t paid for, never a workspace's own
2243 /// model provider.
Two limits, real invoices, trust that grows by itself, sales signals2244 pub cost_micros: i64,
2245 pub paid_micros: i64,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look2246 /// The plan's monthly price, paid.
2247 #[serde(default)]
2248 pub plans_micros: i64,
2249 /// What g1t gave, at price: internal (comped) use, trials, the
2250 /// open-source pool, goodwill credits and what g1t covered. Not margin.
2251 #[serde(default)]
2252 pub given_micros: i64,
Billing on Stripe's pages, month-end charges, warnings; sudo by workspace2253}
2254
2255/// One workspace's share of an [`AccountSummary`].
2256#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
2257#[serde(rename_all = "camelCase")]
2258pub struct WorkspaceFigures {
2259 pub workspace: String,
2260 pub charged_micros: i64,
2261 pub cost_micros: i64,
2262 pub paid_micros: i64,
Billing accounts, terms and enterprises; g1t is no longer free2263}
2264
2265/// `admin_account`: one account in full. Returns `Outcome<AccountDetail>`.
2266#[derive(Debug, Serialize, Deserialize)]
2267pub struct AdminAccountArgs {
2268 /// An account id, or a workspace slug.
2269 pub id: String,
2270}
2271
2272#[derive(Clone, Debug, Serialize, Deserialize)]
2273#[serde(rename_all = "camelCase")]
2274pub struct AccountDetail {
2275 pub summary: AccountSummary,
2276 /// Each workspace's limit, for an enterprise.
2277 pub workspaces: Vec<Limit>,
2278 pub ledger: Vec<LedgerEntry>,
2279 pub audit: Vec<AdminAction>,
2280}
2281
2282/// `admin_set_terms`. Returns `Outcome<BillingAccount>`.
2283#[derive(Debug, Serialize, Deserialize)]
2284pub struct AdminSetTermsArgs {
2285 pub id: String,
2286 pub terms: Terms,
2287 pub by: String,
2288}
2289
2290/// `admin_create_enterprise`. Returns `Outcome<BillingAccount>`.
2291#[derive(Debug, Serialize, Deserialize)]
2292pub struct AdminCreateEnterpriseArgs {
2293 pub name: String,
2294 pub workspaces: Vec<String>,
2295 pub by: String,
2296}
2297
2298/// `admin_attach`: moves a workspace onto an enterprise account, or back
2299/// onto its own with `account: None`. Returns `Outcome<BillingAccount>`.
2300#[derive(Debug, Serialize, Deserialize)]
2301pub struct AdminAttachArgs {
2302 pub workspace: String,
2303 pub account: Option<String>,
2304 pub by: String,
2305}
2306
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging2307/// Why g1t gave a workspace credit.
2308#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
2309#[serde(rename_all = "snake_case")]
2310pub enum CreditKind {
2311 /// Marketing: a welcome, a referral, an event. Given away when spent.
2312 Promotional,
2313 /// An apology, or accidental usage forgiven. Given away when spent.
2314 #[default]
2315 Goodwill,
2316 /// Money back for something that went wrong. Not given away: it gives
2317 /// back money already paid, so it comes off what was paid on the day
2318 /// it refunds, and what it pays for later is paid for.
2319 Refund,
2320 /// Bought by the workspace (prepaid AI): money paid in up front, owed
2321 /// as usage until spent. What it pays for is paid for, never given.
2322 /// Staff never give it; its ledger line is a payment, not `crd…`.
2323 Purchased,
2324}
2325
2326impl CreditKind {
2327 pub fn as_str(self) -> &'static str {
2328 match self {
2329 CreditKind::Promotional => "promotional",
2330 CreditKind::Goodwill => "goodwill",
2331 CreditKind::Refund => "refund",
2332 CreditKind::Purchased => "purchased",
2333 }
2334 }
2335
2336 pub fn parse(text: &str) -> Option<CreditKind> {
2337 match text {
2338 "promotional" => Some(CreditKind::Promotional),
2339 "goodwill" => Some(CreditKind::Goodwill),
2340 "refund" => Some(CreditKind::Refund),
2341 "purchased" => Some(CreditKind::Purchased),
2342 _ => None,
2343 }
2344 }
2345
2346 /// As people read it: `Promotional`.
2347 pub fn label(self) -> &'static str {
2348 match self {
2349 CreditKind::Promotional => "Promotional",
2350 CreditKind::Goodwill => "Goodwill",
2351 CreditKind::Refund => "Refund",
2352 CreditKind::Purchased => "Purchased",
2353 }
2354 }
2355}
2356
2357/// `admin_credit`: credit g1t gives a workspace: promotional, goodwill or a
2358/// refund, with a note, and optionally an expiry. It is spent before
2359/// anything paid in advance, the soonest-expiring first. The workspace's
2360/// owners are emailed. Returns `Outcome<LedgerEntry>`.
Billing accounts, terms and enterprises; g1t is no longer free2361#[derive(Debug, Serialize, Deserialize)]
2362pub struct AdminCreditArgs {
2363 pub workspace: String,
2364 pub amount_micros: i64,
2365 pub note: String,
2366 pub by: String,
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging2367 #[serde(default)]
2368 pub kind: CreditKind,
2369 /// RFC 3339; unused credit stops counting then. Never for a refund.
2370 #[serde(default)]
2371 pub expires_at: Option<String>,
2372 /// A refund: what it refunds, in a line, and the day of it
2373 /// (`YYYY-MM-DD`; today if absent).
2374 #[serde(default)]
2375 pub refund_for: Option<String>,
2376 #[serde(default)]
2377 pub refund_day: Option<String>,
2378}
2379
2380/// One credit g1t gave, with what of it was used: spent on usage, the
2381/// soonest-expiring grant first, before anything paid in advance.
2382#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
2383#[serde(rename_all = "camelCase")]
2384pub struct CreditGrant {
2385 /// `crd_…`, the grant's ledger reference.
2386 pub id: String,
2387 pub workspace: String,
2388 pub kind: CreditKind,
2389 pub amount_micros: i64,
2390 pub used_micros: i64,
2391 /// What can still be spent: nothing once it expired or was revoked.
2392 pub left_micros: i64,
2393 pub note: String,
2394 #[serde(default)]
2395 pub refund_for: Option<String>,
2396 #[serde(default)]
2397 pub refund_day: Option<String>,
2398 pub expires_at: Option<String>,
2399 pub created_by: String,
2400 pub created_at: String,
2401 /// `open`, `used`, `expired` or `revoked`.
2402 pub state: String,
2403 #[serde(default)]
2404 pub closed_at: Option<String>,
2405 #[serde(default)]
2406 pub closed_note: Option<String>,
2407 #[serde(default)]
2408 pub closed_by: Option<String>,
2409 /// What expiring or revoking took off the balance.
2410 #[serde(default)]
2411 pub closed_micros: i64,
2412 /// What it pays for: `all` usage, or `models` only (agent runs' model
2413 /// cost), which is spent first.
2414 #[serde(default)]
2415 pub scope: String,
2416 /// Where it came from: `staff`, `purchase` or `promo_code`.
2417 #[serde(default)]
2418 pub source: String,
2419}
2420
2421/// `credits` (`Outcome<Credits>`, `AccountArgs`): a workspace's credits from
2422/// g1t, newest first, for its members.
2423#[derive(Clone, Debug, Default, Serialize, Deserialize)]
2424#[serde(rename_all = "camelCase")]
2425pub struct Credits {
2426 pub grants: Vec<CreditGrant>,
2427 /// What is left to spend, in all.
2428 pub left_micros: i64,
2429}
2430
2431/// `admin_credits`: every credit g1t gave, newest first, filtered. Returns
2432/// `AdminCredits`.
2433#[derive(Debug, Default, Serialize, Deserialize)]
2434pub struct AdminCreditsArgs {
2435 #[serde(default)]
2436 pub workspace: Option<String>,
2437 #[serde(default)]
2438 pub kind: Option<CreditKind>,
2439 /// `YYYY-MM`: given that month.
2440 #[serde(default)]
2441 pub month: Option<String>,
2442 /// Given by this member of staff.
2443 #[serde(default)]
2444 pub by: Option<String>,
2445}
2446
2447/// One month's credits of one kind: given, used on usage that month, and
2448/// taken back unused (expired or revoked).
2449#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
2450#[serde(rename_all = "camelCase")]
2451pub struct CreditMonth {
2452 pub month: String,
2453 pub kind: CreditKind,
2454 pub given_micros: i64,
2455 pub grants: u32,
2456 pub used_micros: i64,
2457 pub expired_micros: i64,
2458 pub revoked_micros: i64,
2459}
2460
2461#[derive(Clone, Debug, Default, Serialize, Deserialize)]
2462#[serde(rename_all = "camelCase")]
2463pub struct AdminCredits {
2464 /// At most 200.
2465 pub grants: Vec<CreditGrant>,
2466 /// The last 12 months, newest first, whatever the month filter.
2467 pub months: Vec<CreditMonth>,
2468 /// Who has given credit, for the filter.
2469 pub staff: Vec<String>,
2470}
2471
2472/// `admin_revoke_credit`: what is left of a grant, taken off the balance,
2473/// with why. Returns `Outcome<CreditGrant>`.
2474#[derive(Debug, Serialize, Deserialize)]
2475pub struct AdminRevokeCreditArgs {
2476 pub id: String,
2477 pub note: String,
2478 pub by: String,
Billing accounts, terms and enterprises; g1t is no longer free2479}
2480
sudo: reset a test workspace's billing so it starts again as a new customer; refused on a live Stripe key, for comped workspaces and for an enterprise's2481/// `admin_reset_billing`: a test workspace's billing wiped, so it starts
2482/// again as a new customer. Only while billing runs on Stripe's test key;
2483/// never a comped workspace or one an enterprise pays for. `confirm` is the
2484/// workspace's slug typed out. Returns `Outcome<BillingReset>`.
2485#[derive(Debug, Serialize, Deserialize)]
2486pub struct AdminResetBillingArgs {
2487 pub workspace: String,
2488 pub confirm: String,
2489 pub note: String,
2490 pub by: String,
2491}
2492
2493/// What a reset removed.
2494#[derive(Clone, Debug, Serialize, Deserialize)]
2495#[serde(rename_all = "camelCase")]
2496pub struct BillingReset {
2497 pub workspace: String,
2498 pub rows: u32,
sudo: a billing reset runs the costs analysis again so every figure is fresh; every submit button shows it is working (CSS only); no margin percentage on less than a cent sold2499 /// Whether the costs analysis ran again after it, so the margin
2500 /// figures no longer hold the workspace's past usage.
2501 #[serde(default)]
2502 pub refreshed: bool,
sudo: reset a test workspace's billing so it starts again as a new customer; refused on a live Stripe key, for comped workspaces and for an enterprise's2503}
2504
Billing accounts, terms and enterprises; g1t is no longer free2505/// One change made in sudo.
2506#[derive(Clone, Debug, Serialize, Deserialize)]
2507#[serde(rename_all = "camelCase")]
2508pub struct AdminAction {
2509 pub id: String,
2510 pub account: String,
2511 pub action: String,
2512 pub detail: String,
2513 pub by: String,
2514 pub created_at: String,
2515}
2516
Paid features: a workspace turns on Deployments with a monthly plan2517/// What a feature's plan costs and includes.
2518#[derive(Clone, Debug, Serialize, Deserialize)]
2519#[serde(rename_all = "camelCase")]
2520pub struct Plan {
2521 pub feature: Feature,
2522 pub title: String,
Merge Stripe Tax, the card fee on card payments, and one free workspace per person2523 /// Charged every month while the plan is on, in cents, excluding tax.
Paid features: a workspace turns on Deployments with a monthly plan2524 pub monthly_cents: u32,
Merge Stripe Tax, the card fee on card payments, and one free workspace per person2525 /// The card processing fee on top each month, in cents (0 when the
2526 /// fee is off). Excluding tax, like the price.
2527 #[serde(default)]
2528 pub card_fee_cents: u32,
Paid features: a workspace turns on Deployments with a monthly plan2529 /// What the monthly price includes, one line each, for people to read.
2530 pub includes: Vec<String>,
2531 /// How usage past the allowance is charged, for people to read.
2532 pub overage: String,
2533}
2534
2535#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
2536#[serde(rename_all = "snake_case")]
2537pub enum SubscriptionStatus {
2538 /// Paid up; the feature works.
2539 Active,
2540 /// Paid up to the end of the period, and ends then.
2541 Canceling,
2542 /// The last payment failed; the feature is off until it is paid.
2543 PastDue,
2544 /// Ended.
2545 Canceled,
2546}
2547
2548impl SubscriptionStatus {
2549 /// Whether the feature works in this state.
2550 pub fn on(self) -> bool {
2551 matches!(self, SubscriptionStatus::Active | SubscriptionStatus::Canceling)
2552 }
2553}
2554
2555/// A workspace's plan for one feature.
2556#[derive(Clone, Debug, Serialize, Deserialize)]
2557#[serde(rename_all = "camelCase")]
2558pub struct Subscription {
2559 pub feature: Feature,
2560 pub status: SubscriptionStatus,
2561 /// RFC 3339: when the period paid for ends, and the plan renews or
2562 /// ends.
2563 pub period_end: Option<String>,
2564 /// Username of whoever turned it on.
2565 pub started_by: String,
2566 /// RFC 3339.
2567 pub started_at: String,
2568}
2569
2570/// A feature as a workspace sees it: what it costs, and its plan if it has
2571/// one.
2572#[derive(Clone, Debug, Serialize, Deserialize)]
2573#[serde(rename_all = "camelCase")]
2574pub struct FeatureState {
2575 pub plan: Plan,
2576 pub subscription: Option<Subscription>,
2577 /// Whether the feature works for the workspace now.
2578 pub on: bool,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put2579 /// On without a plan: comped terms, or given by g1t. Nothing to pay
2580 /// and nothing to turn off.
2581 #[serde(default)]
2582 pub included: bool,
Paid features: a workspace turns on Deployments with a monthly plan2583}
2584
2585/// `features`: every paid feature and the workspace's plan for each.
2586/// Members only. Returns `Outcome<Vec<FeatureState>>`.
2587#[derive(Debug, Serialize, Deserialize)]
2588pub struct FeaturesArgs {
2589 pub workspace: String,
2590 pub viewer: Viewer,
2591}
2592
2593/// `subscribe`: starts the card page for a feature's monthly plan. Owners
2594/// only. Returns `Outcome<Checkout>`; the page's id comes back to
2595/// `return_url` as `session`, for `confirm_subscription`.
2596#[derive(Debug, Serialize, Deserialize)]
2597#[serde(rename_all = "camelCase")]
2598pub struct SubscribeArgs {
2599 pub actor: User,
2600 pub workspace: String,
2601 pub feature: Feature,
2602 pub return_url: String,
2603}
2604
2605/// `confirm_subscription`: turns the feature on once the processor says
2606/// the plan was paid for. Safe to call any number of times. Returns
2607/// `Outcome<FeatureState>`.
2608#[derive(Debug, Serialize, Deserialize)]
2609pub struct ConfirmSubscriptionArgs {
2610 pub workspace: String,
2611 pub viewer: Viewer,
2612 pub session: String,
2613}
2614
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member2615/// `admin_log`: a staff change another service made to a workspace, kept
2616/// in sudo's audit log with billing's own (`admin_audit`). For identity's
2617/// restores and purges of deleted workspaces. Returns `bool`.
2618#[derive(Debug, Serialize, Deserialize)]
2619pub struct AdminLogArgs {
2620 pub workspace: String,
2621 pub action: String,
2622 pub detail: String,
2623 /// The staff member's email.
2624 pub by: String,
2625}
2626
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look2627/// `close_workspace`: settles a workspace that is about to be deleted.
2628/// Owners only. Refused while it has an invoice that failed, while it
2629/// holds prepaid credit, or while it owes money it cannot be charged for
2630/// now; otherwise what it owes is invoiced to its card at once (no
2631/// minimum), its plan is cancelled at Stripe straight away, and its
2632/// account is marked closed, so the month-end close, autopay and limit
2633/// warnings pass it by. Its ledger, invoices and statements stay. With
2634/// `dry_run`, only says whether it could, changing nothing. Returns
2635/// `Outcome<bool>`.
2636#[derive(Debug, Serialize, Deserialize)]
2637#[serde(rename_all = "camelCase")]
2638pub struct CloseWorkspaceArgs {
2639 pub actor: User,
2640 pub workspace: String,
2641 #[serde(default)]
2642 pub dry_run: bool,
2643}
2644
Paid features: a workspace turns on Deployments with a monthly plan2645/// `cancel_subscription` (`resume` false) ends a plan at the end of the
2646/// period paid for; with `resume` true, takes that back. Owners only.
2647/// Returns `Outcome<FeatureState>`.
2648#[derive(Debug, Serialize, Deserialize)]
2649pub struct CancelSubscriptionArgs {
2650 pub actor: User,
2651 pub workspace: String,
2652 pub feature: Feature,
2653 #[serde(default)]
2654 pub resume: bool,
2655}
2656
2657/// `has_feature`: whether a feature works for a workspace now, asked by the
2658/// service that provides it before doing paid work. Returns
2659/// `Outcome<bool>`: a failure, with the reason to show, when it does not.
2660/// True everywhere when no card processor is configured.
2661#[derive(Debug, Serialize, Deserialize)]
2662pub struct HasFeatureArgs {
2663 pub workspace: String,
2664 pub feature: Feature,
2665}
2666
Merge Stripe Tax, the card fee on card payments, and one free workspace per person2667/// `free_workspaces`: which of `workspaces` are free, that is on no paid
2668/// plan. Paid is the g1t plan, an enterprise's terms, or a discount of
2669/// 100% (g1t's own workspaces). Identity asks before a workspace is made
2670/// (a person owns at most one free workspace) and before anyone is added
2671/// to one (a free workspace cannot invite). Returns `Vec<String>`, the
2672/// free ones, lower-cased; none where payments are not set up.
2673#[derive(Debug, Serialize, Deserialize)]
2674pub struct FreeWorkspacesArgs {
2675 pub workspaces: Vec<String>,
2676}
2677
Paid features: a workspace turns on Deployments with a monthly plan2678/// `charge_feature`: usage of a feature past its plan's allowance, charged
2679/// from the workspace's credit at cost plus the margin, whatever
2680/// `FREE_WHILE_BUILDING` says. Called by the service that provides it.
2681/// Charged once per `reference`. Returns `Outcome<bool>`: false if that
2682/// reference was charged before.
2683#[derive(Debug, Serialize, Deserialize)]
2684#[serde(rename_all = "camelCase")]
2685pub struct ChargeFeatureArgs {
2686 pub workspace: String,
2687 pub feature: Feature,
2688 /// What it cost g1t, in millionths of a dollar, before the margin.
2689 pub cost_micros: i64,
2690 pub description: String,
2691 /// `namespace/name`, when the usage was one repository's.
2692 pub repo: Option<String>,
2693 /// Unique to this charge, e.g. `deployments/acme/2026-10`.
2694 pub reference: String,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put2695 /// For a build: how long it ran. The plan's included build time this
2696 /// month pays for what it can, and only the rest of `cost_micros` is
2697 /// charged.
2698 #[serde(default)]
2699 pub build_seconds: Option<u32>,
Paid features: a workspace turns on Deployments with a monthly plan2700}
2701
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily2702// ---------------------------------------------------------------------
2703// Costs and margin: what Cloudflare charges g1t against what g1t
2704// charges (billing's costs.rs, margin.rs and pricing.rs). Staff only.
2705// ---------------------------------------------------------------------
2706
2707/// `admin_costs`: the Costs & margin page. Returns `CostsReport`.
2708#[derive(Debug, Default, Serialize, Deserialize)]
2709pub struct AdminCostsArgs {
2710 /// How many days back, 7 to 90; 30 when absent.
2711 #[serde(default)]
2712 pub days: Option<u32>,
2713}
2714
2715/// One of g1t's products on one day.
2716#[derive(Clone, Debug, Default, Serialize, Deserialize)]
2717#[serde(rename_all = "camelCase")]
2718pub struct CostDay {
2719 pub day: String,
2720 pub bucket: String,
2721 /// What Cloudflare charged g1t.
2722 pub cf_cost_micros: i64,
2723 /// What g1t's meters recorded it cost, at the price book's cost.
2724 pub own_cost_micros: i64,
2725 /// What customers were charged for it at price, before included
2726 /// usage, trials and pools paid for some.
2727 pub value_micros: i64,
2728 /// Of that, what workspaces paid.
2729 pub cash_micros: i64,
2730}
2731
2732/// One product over the range.
2733#[derive(Clone, Debug, Default, Serialize, Deserialize)]
2734#[serde(rename_all = "camelCase")]
2735pub struct ProductMargin {
2736 pub bucket: String,
2737 pub title: String,
2738 /// The cost the margin is taken from: Cloudflare's bill, or g1t's own
2739 /// figure for what Cloudflare does not bill (models).
2740 pub cost_micros: i64,
2741 pub cf_cost_micros: i64,
2742 pub own_cost_micros: i64,
2743 pub value_micros: i64,
2744 pub margin_micros: i64,
2745 pub margin_percent: Option<f64>,
2746 /// `cloudflare` or `ledger`.
2747 pub cost_source: String,
2748 /// Running g1t itself, paid for by the plan.
2749 pub overhead: bool,
2750}
2751
Costs: margin is measured on what was sold; comped workspaces, free periods, the trial and the pools are given away, a budget shown beside it2752/// All of g1t over the range: money in against every cost, and against
2753/// the cost of what was sold (every cost less what g1t gave away).
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily2754#[derive(Clone, Debug, Default, Serialize, Deserialize)]
2755#[serde(rename_all = "camelCase")]
2756pub struct OverallMargin {
2757 /// What workspaces paid for usage, and for the plan.
2758 pub usage_micros: i64,
2759 pub plans_micros: i64,
2760 pub cost_micros: i64,
2761 pub margin_micros: i64,
2762 pub margin_percent: Option<f64>,
Costs: margin is measured on what was sold; comped workspaces, free periods, the trial and the pools are given away, a budget shown beside it2763 /// Of `cost_micros`, what went on usage g1t gave away on purpose:
2764 /// comped workspaces, free periods, the trial and the open-source pool.
2765 #[serde(default)]
2766 pub given_micros: i64,
2767 /// Money in against `cost_micros - given_micros`.
2768 #[serde(default)]
2769 pub sold_margin_micros: i64,
2770 #[serde(default)]
2771 pub sold_margin_percent: Option<f64>,
Costs: a statement that keeps usage sold, running g1t, subscriptions and what was given away (comped, free use, trial, pool) apart, and says who was paid; free use carries its own cost; the run button says it is running2772 /// What was sold, apart: usage (`usage_micros` against what that usage
2773 /// cost, less what was given), running g1t (`plans_micros` against the
2774 /// platform's cost, less its given share) and what no mapping names.
2775 #[serde(default)]
2776 pub usage_cost_micros: i64,
2777 #[serde(default)]
2778 pub usage_margin_micros: i64,
2779 #[serde(default)]
2780 pub usage_margin_percent: Option<f64>,
2781 #[serde(default)]
2782 pub running_cost_micros: i64,
2783 #[serde(default)]
2784 pub unmapped_cost_micros: i64,
2785 /// `given_micros` by why: comped workspaces, free use (free periods,
2786 /// free allowances, overruns g1t covered), the trial, the open-source pool.
2787 #[serde(default)]
2788 pub given_comped_micros: i64,
2789 #[serde(default)]
2790 pub given_free_micros: i64,
2791 #[serde(default)]
2792 pub given_trial_micros: i64,
2793 #[serde(default)]
2794 pub given_pool_micros: i64,
Merge branch 'worktree-agent-a633ac0f7f66d419d'2795 /// What discounts on an account's terms took below cost plus the
2796 /// margin: given, so a discounted sale is not margin lost.
2797 #[serde(default)]
2798 pub given_discount_micros: i64,
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging2799 /// Credits from g1t spent on usage, by kind: given, so usage paid for
2800 /// with them is never money in. Refunds are not here: they come off
2801 /// money in on the day they refund.
2802 #[serde(default)]
2803 pub given_credit_promotional_micros: i64,
2804 #[serde(default)]
2805 pub given_credit_goodwill_micros: i64,
2806 /// Credits over the range: given (every kind), spent on usage, and
2807 /// refunds' money given back.
2808 #[serde(default)]
2809 pub credits_given_micros: i64,
2810 #[serde(default)]
2811 pub credits_used_micros: i64,
2812 #[serde(default)]
2813 pub credits_refunded_micros: i64,
Costs: a statement that keeps usage sold, running g1t, subscriptions and what was given away (comped, free use, trial, pool) apart, and says who was paid; free use carries its own cost; the run button says it is running2814 /// `cost_micros` by who g1t pays: Cloudflare's bill (billed amounts,
2815 /// after the included allowances), and model providers (the ledger's
2816 /// cost of the tokens, which Cloudflare's bill does not show).
Costs: the plan's included usage counts as paid for the usage it covered, out of what plans leave for running g1t; the run button shows it is running with CSS alone (sudo ships no JavaScript)2817 /// What the plan's included usage paid for, at price (the ledger's
2818 /// `credit_micros`, comped workspaces left out): money in for usage,
2819 /// paid out of `plans_micros`.
2820 #[serde(default)]
2821 pub included_micros: i64,
Costs: a statement that keeps usage sold, running g1t, subscriptions and what was given away (comped, free use, trial, pool) apart, and says who was paid; free use carries its own cost; the run button says it is running2822 #[serde(default)]
2823 pub cloudflare_cost_micros: i64,
2824 #[serde(default)]
2825 pub models_cost_micros: i64,
Merge Stripe Tax, the card fee on card payments, and one free workspace per person2826 /// Tax collected with payments over the range, net of refunds: owed to
2827 /// the tax authorities, never in cash or revenue.
2828 #[serde(default)]
2829 pub tax_collected_micros: i64,
2830 /// Card processing fees passed on with card payments, net of refunds:
2831 /// they pay Stripe's fee, so they are not revenue either.
2832 #[serde(default)]
2833 pub card_fees_micros: i64,
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily2834}
2835
2836/// A count, cost or leak that does not add up.
2837#[derive(Clone, Debug, Serialize, Deserialize)]
2838#[serde(rename_all = "camelCase")]
2839pub struct CostDrift {
2840 pub bucket: String,
2841 pub title: String,
2842 /// `count` (units g1t counted against Cloudflare's), `cost` (the bill
Merge branch 'worktree-agent-a633ac0f7f66d419d'2843 /// against the price book's cost of the same usage; for models, what AI
2844 /// Gateway priced g1t's provider traffic at against the ledger's model
2845 /// cost), `unpriced` (model usage AI Gateway put no price on, so its
2846 /// cost is not the providers'), or `leak`.
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily2847 pub kind: String,
2848 pub ours: f64,
2849 pub cloudflare: f64,
2850 pub delta_percent: Option<f64>,
2851 pub detail: String,
2852 pub found_at: String,
2853}
2854
2855/// A margin alert, open while its condition lasts.
2856#[derive(Clone, Debug, Serialize, Deserialize)]
2857#[serde(rename_all = "camelCase")]
2858pub struct MarginAlert {
2859 pub id: String,
2860 /// `margin`, `overall`, `leak`, `drift` or `workspace`.
2861 pub kind: String,
2862 /// The product, or the workspace.
2863 pub subject: String,
2864 pub detail: String,
2865 pub since: String,
2866 pub opened_at: String,
2867 pub emailed_at: Option<String>,
2868}
2869
2870/// A change to a price the reconciler measured.
2871#[derive(Clone, Debug, Serialize, Deserialize)]
2872#[serde(rename_all = "camelCase")]
2873pub struct PriceProposal {
2874 pub id: String,
2875 pub meter: String,
2876 pub title: String,
2877 pub unit: String,
2878 pub current_cost_micros: f64,
2879 pub proposed_cost_micros: f64,
2880 pub change_percent: f64,
2881 pub markup_percent: u32,
2882 pub reason: String,
2883 /// `keeper` or `reconciler`.
2884 pub source: String,
2885 /// Far off the current cost: look before approving.
2886 pub suspect: bool,
2887 /// `open`, `applied`, `approved`, `rejected` or `superseded`.
2888 pub status: String,
2889 pub created_at: String,
2890 pub decided_at: Option<String>,
2891 pub decided_by: Option<String>,
2892 pub note: Option<String>,
2893 /// When it takes or took effect, once approved or applied.
2894 pub effective_at: Option<String>,
2895}
2896
2897/// One version of one meter's price. Never changed once written.
2898#[derive(Clone, Debug, Serialize, Deserialize)]
2899#[serde(rename_all = "camelCase")]
2900pub struct PriceVersion {
2901 pub id: String,
2902 pub meter: String,
2903 pub version: u32,
2904 pub cost_micros: f64,
2905 pub markup_percent: u32,
2906 pub price_micros: f64,
2907 pub effective_at: String,
2908 pub reason: String,
2909 pub created_by: String,
2910 /// When the price book took it on; absent while it waits for its date.
2911 pub applied_at: Option<String>,
2912}
2913
2914/// What a workspace cost g1t over the range, Cloudflare's costs shared
2915/// out by g1t's own meters, against what it paid.
2916#[derive(Clone, Debug, Serialize, Deserialize)]
2917#[serde(rename_all = "camelCase")]
2918pub struct WorkspaceCost {
2919 pub workspace: String,
2920 pub cost_micros: i64,
2921 pub revenue_micros: i64,
Costs: margin is measured on what was sold; comped workspaces, free periods, the trial and the pools are given away, a budget shown beside it2922 /// Of `cost_micros`, what g1t gave away.
2923 #[serde(default)]
2924 pub given_micros: i64,
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily2925 /// One of g1t's own (comped) workspaces.
2926 pub internal: bool,
2927}
2928
2929/// One Cloudflare meter over the range, and the product it is a cost of.
2930#[derive(Clone, Debug, Serialize, Deserialize)]
2931#[serde(rename_all = "camelCase")]
2932pub struct CostLineSummary {
2933 pub product: String,
2934 pub meter: String,
2935 pub raw_name: String,
2936 pub unit: String,
2937 pub source: String,
2938 pub quantity: f64,
2939 pub cost_micros: i64,
2940 /// Absent when no mapping claims it.
2941 pub bucket: Option<String>,
2942}
2943
2944/// A row of the mapping from Cloudflare's meters to g1t's products.
2945#[derive(Clone, Debug, Serialize, Deserialize)]
2946#[serde(rename_all = "camelCase")]
2947pub struct CostMapping {
2948 pub product: String,
2949 pub meter: String,
2950 pub bucket: String,
2951 pub price_meter: Option<String>,
2952 pub own_meter: Option<String>,
2953 pub scale_to_own: bool,
2954 pub drift_percent: f64,
2955 pub note: String,
2956 pub updated_at: String,
2957 pub updated_by: String,
2958}
2959
2960/// The guardrails on prices and the alerts.
2961#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
2962#[serde(rename_all = "camelCase")]
2963pub struct CostSettings {
2964 /// Apply small moves without staff.
2965 pub auto_apply: bool,
2966 /// The largest move applied without staff, either way, in percent.
2967 pub auto_apply_percent: f64,
2968 /// Days between telling customers of a rise and charging it.
2969 pub notice_days: u32,
2970 /// Below this margin, in percent, for `alert_days` days in a row, alert.
2971 pub margin_floor_percent: f64,
2972 pub alert_days: u32,
2973 /// Days with less cost than this say nothing about a margin.
2974 pub min_daily_cost_micros: i64,
2975 /// A workspace costing more than its revenue times this, over 30 days,
2976 /// and at least `anomaly_floor_micros`, is flagged.
2977 pub anomaly_factor: f64,
2978 pub anomaly_floor_micros: i64,
Merge Stripe Tax, the card fee on card payments, and one free workspace per person2979 /// Pass Stripe's card fee on as its own line on every card payment (the
2980 /// plan, Security and quality, prepaying, AI credit, auto-reload and
2981 /// invoices charged to a card), never on a bank transfer or an invoice
2982 /// sent to be paid (`card_fee_percent` and `card_fee_fixed` in the
2983 /// price book). On by default.
Usage, Billing settings and prepaid AI credit; fixes from the UX audit2984 #[serde(default = "yes")]
2985 pub card_fee: bool,
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily2986}
2987
2988impl Default for CostSettings {
2989 fn default() -> Self {
2990 CostSettings {
2991 auto_apply: true,
2992 auto_apply_percent: 25.0,
2993 notice_days: 14,
2994 margin_floor_percent: 10.0,
2995 alert_days: 3,
2996 min_daily_cost_micros: 100_000,
2997 anomaly_factor: 1.0,
2998 anomaly_floor_micros: 1_000_000,
Usage, Billing settings and prepaid AI credit; fixes from the UX audit2999 card_fee: true,
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily3000 }
3001 }
3002}
3003
3004/// The Costs & margin page.
3005#[derive(Clone, Debug, Default, Serialize, Deserialize)]
3006#[serde(rename_all = "camelCase")]
3007pub struct CostsReport {
3008 /// A token to read Cloudflare's bill is set.
3009 pub configured: bool,
3010 /// When Cloudflare's bill was last read.
3011 pub fetched_at: Option<String>,
3012 /// The days shown, YYYY-MM-DD.
3013 pub since: String,
3014 pub until: String,
3015 pub days: Vec<CostDay>,
3016 pub products: Vec<ProductMargin>,
3017 pub overall: OverallMargin,
3018 pub drift: Vec<CostDrift>,
3019 pub alerts: Vec<MarginAlert>,
3020 pub proposals: Vec<PriceProposal>,
3021 pub versions: Vec<PriceVersion>,
3022 pub top_workspaces: Vec<WorkspaceCost>,
3023 pub lines: Vec<CostLineSummary>,
3024 pub mappings: Vec<CostMapping>,
3025 pub settings: CostSettings,
Spend caps: a monthly budget for comped workspaces and a daily breaker on what g1t pays3026 /// g1t's own spend against its two caps.
3027 #[serde(default)]
3028 pub caps: SpendCaps,
3029}
3030
3031/// What g1t itself pays for, against its caps (billing's `budget`): the
3032/// daily breaker on all of it, and each comped account's monthly budget.
Costs: Cloudflare's subscriptions read from Cloudflare each day, the estimate only until then; sudo's costs split into Costs & margin and Bill & pricing3033/// One of Cloudflare's subscriptions, at what it comes to a month.
3034#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
3035#[serde(rename_all = "camelCase")]
3036pub struct FixedCost {
3037 pub name: String,
3038 pub monthly_micros: i64,
3039}
3040
Spend caps: a monthly budget for comped workspaces and a daily breaker on what g1t pays3041/// At cost, never at price. What sudo's Costs page and its red bar show.
3042#[derive(Clone, Debug, Default, Serialize, Deserialize)]
3043#[serde(rename_all = "camelCase")]
3044pub struct SpendCaps {
3045 /// Today (UTC), YYYY-MM-DD, and this month, YYYY-MM.
3046 pub day: String,
3047 pub month: String,
3048 /// What g1t paid for itself today across every workspace: comped work,
3049 /// the trial and open-source pools, free workspaces' overruns, and
3050 /// anything charged without real money behind it.
3051 pub today_micros: i64,
3052 /// `PLATFORM_DAILY_SPEND_CAP_MICROS`. Zero: no breaker.
3053 pub daily_cap_micros: i64,
3054 /// The breaker is open: new hosted-model agent runs that g1t would pay
3055 /// for wait until tomorrow (UTC) or until staff lift it.
3056 pub tripped: bool,
3057 pub tripped_at: Option<String>,
3058 /// Staff lifted it for the rest of the day.
3059 pub lifted_by: Option<String>,
3060 pub lifted_at: Option<String>,
3061 pub lift_note: Option<String>,
3062 /// This month so far, by what paid: `comped`, `trial`, `oss`, `given`,
3063 /// `unpaid`.
3064 pub month_buckets: Vec<SpendBucket>,
3065 /// Each comped account's monthly budget.
3066 pub comped: Vec<CompedBudget>,
3067 /// Free workspaces' share of this month's reconciled costs (git,
3068 /// storage, platform), through yesterday.
3069 pub free_tier_micros: i64,
Costs: Cloudflare's subscriptions read from Cloudflare each day, the estimate only until then; sudo's costs split into Costs & margin and Bill & pricing3070 /// Cloudflare's subscriptions a month: as read from Cloudflare each
3071 /// day, else `CLOUDFLARE_FIXED_MONTHLY_MICROS`, an estimate.
Spend caps: a monthly budget for comped workspaces and a daily breaker on what g1t pays3072 pub fixed_monthly_micros: i64,
Costs: Cloudflare's subscriptions read from Cloudflare each day, the estimate only until then; sudo's costs split into Costs & margin and Bill & pricing3073 /// `cloudflare` or `estimate`.
3074 #[serde(default)]
3075 pub fixed_source: String,
3076 #[serde(default)]
3077 pub fixed_read_at: Option<String>,
3078 /// Each subscription, when read from Cloudflare.
3079 #[serde(default)]
3080 pub fixed_items: Vec<FixedCost>,
Spend caps: a monthly budget for comped workspaces and a daily breaker on what g1t pays3081 /// Money in this month, through the last reconciled day.
3082 pub revenue_micros: i64,
3083}
3084
3085#[derive(Clone, Debug, Default, Serialize, Deserialize)]
3086#[serde(rename_all = "camelCase")]
3087pub struct SpendBucket {
3088 pub bucket: String,
3089 pub title: String,
3090 pub micros: i64,
3091}
3092
3093/// A comped account's monthly budget: what its work cost g1t this month.
3094#[derive(Clone, Debug, Default, Serialize, Deserialize)]
3095#[serde(rename_all = "camelCase")]
3096pub struct CompedBudget {
3097 pub account: String,
3098 pub name: String,
3099 pub used_micros: i64,
3100 /// Zero: no budget.
3101 pub ceiling_micros: i64,
3102 /// The ceiling is `COMPED_MONTHLY_CEILING_MICROS`, not the account's own.
3103 pub default_ceiling: bool,
3104 /// 50, 75, 90, 100, or 0.
3105 pub level: u32,
3106}
3107
3108/// `admin_spend_caps`: g1t's own spend against its caps. Returns `SpendCaps`.
3109#[derive(Debug, Default, Serialize, Deserialize)]
3110pub struct AdminSpendCapsArgs {}
3111
3112/// `admin_lift_breaker`: lets hosted-model runs start again for the rest
3113/// of today (UTC), with why. Recorded in the audit log. Returns
3114/// `Outcome<SpendCaps>`.
3115#[derive(Debug, Serialize, Deserialize)]
3116pub struct AdminLiftBreakerArgs {
3117 pub note: String,
3118 pub by: String,
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily3119}
3120
3121/// `admin_cost_alerts`: the open margin alerts, for sudo's banner.
3122/// Returns `Vec<MarginAlert>`.
3123#[derive(Debug, Default, Serialize, Deserialize)]
3124pub struct AdminCostAlertsArgs {}
3125
3126/// `admin_decide_proposal`: approve or reject a price proposal. An
3127/// approved rise takes effect after the notice period. Returns
3128/// `Outcome<PriceProposal>`.
3129#[derive(Debug, Serialize, Deserialize)]
3130pub struct AdminDecideProposalArgs {
3131 pub id: String,
3132 /// `approve` or `reject`.
3133 pub decision: String,
3134 #[serde(default)]
3135 pub note: String,
3136 pub by: String,
3137}
3138
3139/// `admin_set_cost_settings`. Returns `Outcome<CostSettings>`.
3140#[derive(Debug, Serialize, Deserialize)]
3141pub struct AdminSetCostSettingsArgs {
3142 pub settings: CostSettings,
3143 pub by: String,
3144}
3145
3146/// `admin_set_cost_mapping`: adds, changes or (with `remove`) removes a
3147/// mapping row. Returns `Outcome<CostMapping>`.
3148#[derive(Debug, Serialize, Deserialize)]
3149pub struct AdminSetCostMappingArgs {
3150 pub product: String,
3151 pub meter: String,
3152 #[serde(default)]
3153 pub bucket: String,
3154 #[serde(default)]
3155 pub price_meter: Option<String>,
3156 #[serde(default)]
3157 pub own_meter: Option<String>,
3158 #[serde(default)]
3159 pub scale_to_own: bool,
3160 #[serde(default)]
3161 pub drift_percent: Option<f64>,
3162 #[serde(default)]
3163 pub note: String,
3164 #[serde(default)]
3165 pub remove: bool,
3166 pub by: String,
3167}
3168
3169/// `admin_run_costs`: reads Cloudflare's bill and reconciles now, as the
3170/// daily run does. Returns `Outcome<CostsRun>`.
3171#[derive(Debug, Default, Serialize, Deserialize)]
3172pub struct AdminRunCostsArgs {
3173 #[serde(default)]
3174 pub by: String,
3175}
3176
3177#[derive(Clone, Debug, Default, Serialize, Deserialize)]
3178#[serde(rename_all = "camelCase")]
3179pub struct CostsRun {
3180 pub lines: u32,
3181 pub days: u32,
3182 pub proposals: u32,
3183 pub alerts: u32,
3184 /// What could not be read, in words.
3185 pub problems: Vec<String>,
3186}
3187
Usage, Billing settings and prepaid AI credit; fixes from the UX audit3188// --- The Usage page ----------------------------------------------------------
3189
3190/// The product families the Usage page groups meters into, in order, with
3191/// their names.
3192pub const PRODUCTS: [(&str, &str); 8] = [
3193 ("agent", "Agent"),
3194 ("sandboxes", "Sandboxes"),
3195 ("gateway", "AI Gateway"),
3196 ("deployments", "Deployments"),
3197 ("git_storage", "Git & storage"),
3198 ("packages", "Packages"),
3199 ("security", "Security & quality"),
3200 ("search", "Search"),
3201];
3202
3203/// `usage_report`: a workspace's usage over a range of days, at price, by
3204/// product, meter, project and day. The figures are the ledger's: the same
3205/// lines the statement and invoices read, so every page agrees. Members
3206/// only. Returns `Outcome<UsageReport>`.
3207#[derive(Debug, Serialize, Deserialize)]
3208#[serde(rename_all = "camelCase")]
3209pub struct UsageReportArgs {
3210 pub workspace: String,
3211 pub viewer: Viewer,
3212 /// The first day, `YYYY-MM-DD` (UTC).
3213 pub from: String,
3214 /// The last day, `YYYY-MM-DD`, included.
3215 pub until: String,
3216 /// Only these product families (`agent`, `sandboxes`…); all when empty.
3217 #[serde(default)]
3218 pub products: Vec<String>,
3219 /// Only these projects (repositories, `owner/name`); all when empty.
3220 #[serde(default)]
3221 pub projects: Vec<String>,
3222}
3223
3224/// What usage came to over a range, and what paid for it. `price_micros`
3225/// less `discount_micros`, `included_micros` and `credits_micros` is
3226/// `charged_micros`.
3227#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
3228#[serde(rename_all = "camelCase")]
3229pub struct UsageTotals {
3230 /// Usage at price, metered usage not yet charged (`pending_micros`)
3231 /// included.
3232 pub price_micros: i64,
3233 /// What the account's discount took off.
3234 pub discount_micros: i64,
3235 /// What the plan's included usage, the trial and g1t's pools paid.
3236 pub included_micros: i64,
3237 /// What credit paid: AI credit, credit from g1t.
3238 pub credits_micros: i64,
3239 /// What is left for the workspace to pay.
3240 pub charged_micros: i64,
3241 /// Metered this month and charged when it closes (storage, git
3242 /// operations, scans, embeddings, domains), at price.
3243 pub pending_micros: i64,
3244 /// What it cost g1t, before any markup.
3245 pub cost_micros: i64,
3246}
3247
3248/// One day's usage of one product, at price.
3249#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
3250#[serde(rename_all = "camelCase")]
3251pub struct UsageDay {
3252 /// `YYYY-MM-DD`.
3253 pub day: String,
3254 pub product: String,
3255 pub micros: i64,
3256}
3257
3258/// How much of an allowance is used, in the meter's unit.
3259#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
3260#[serde(rename_all = "camelCase")]
3261pub struct Allowance {
3262 pub used: f64,
3263 pub of: f64,
3264 /// `bytes`, `operations`, `dollars`…
3265 pub unit: String,
3266}
3267
3268/// One project's part of a meter.
3269#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
3270#[serde(rename_all = "camelCase")]
3271pub struct ProjectUsage {
3272 /// `owner/name`, or empty for usage that is not one project's.
3273 pub project: String,
3274 pub micros: i64,
3275 pub quantity: f64,
3276}
3277
3278/// One meter over the range.
3279#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
3280#[serde(rename_all = "camelCase")]
3281pub struct MeterLine {
3282 /// `agent_models`, `agent_rate`, `sandbox`, `builds`…
3283 pub key: String,
3284 pub label: String,
3285 pub product: String,
3286 /// What `quantity` counts: `tokens`, `seconds`, `bytes`, `operations`,
3287 /// `entries`.
3288 pub unit: String,
3289 pub quantity: f64,
3290 /// At price.
3291 pub micros: i64,
3292 /// Of `micros`, metered this month and charged when it closes.
3293 #[serde(default)]
3294 pub pending_micros: i64,
3295 /// Every day of the range, oldest first, at price: the sparkline.
3296 pub daily: Vec<i64>,
3297 #[serde(default)]
3298 pub allowance: Option<Allowance>,
3299 pub by_project: Vec<ProjectUsage>,
Merge branch 'model-routing'3300 /// How the quantity is counted, when that needs saying: for the agent
3301 /// rate, its tokens are weighted by kind, and this names the weights.
3302 #[serde(default)]
3303 pub note: Option<String>,
Usage, Billing settings and prepaid AI credit; fixes from the UX audit3304}
3305
3306/// A part of a product, such as the agent's runs, reviews and plans.
3307#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
3308#[serde(rename_all = "camelCase")]
3309pub struct FeatureUsage {
3310 pub key: String,
3311 pub label: String,
3312 pub micros: i64,
3313 pub count: u32,
3314}
3315
Merge branch 'model-routing'3316/// The tokens one model used over the range, as the model proxy counted
3317/// them: on g1t's models and the workspace's own provider alike.
3318#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
3319#[serde(rename_all = "camelCase")]
3320pub struct ModelTokens {
3321 /// The model's id, as it ran.
3322 pub model: String,
3323 pub input: u64,
3324 pub output: u64,
3325 pub cache_read: u64,
3326 pub cache_write: u64,
3327}
3328
Usage, Billing settings and prepaid AI credit; fixes from the UX audit3329/// One product family over the range.
3330#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
3331#[serde(rename_all = "camelCase")]
3332pub struct ProductUsage {
3333 pub key: String,
3334 pub label: String,
3335 pub micros: i64,
3336 pub meters: Vec<MeterLine>,
3337 /// For the agent: by what it was doing (runs, reviews, plans, checks).
3338 #[serde(default)]
3339 pub features: Vec<FeatureUsage>,
3340}
3341
3342#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
3343#[serde(rename_all = "camelCase")]
3344pub struct UsageReport {
3345 pub from: String,
3346 pub until: String,
3347 pub totals: UsageTotals,
3348 /// Each day and product with usage, oldest first.
3349 pub days: Vec<UsageDay>,
3350 /// Every product family, in order, even with nothing used.
3351 pub products: Vec<ProductUsage>,
3352 /// Every project with usage in the range, for the filter.
3353 pub projects: Vec<String>,
Merge branch 'model-routing'3354 /// Agent tokens by model over the range, most first.
3355 #[serde(default)]
3356 pub models: Vec<ModelTokens>,
Usage, Billing settings and prepaid AI credit; fixes from the UX audit3357 /// The plan's included usage this month, when the workspace has it.
3358 #[serde(default)]
3359 pub included: Option<Allowance>,
3360 /// The account's discount, in percent, when it has one.
3361 #[serde(default)]
3362 pub discount_percent: Option<u32>,
3363 /// AI credit left now, and credit from g1t for everything.
3364 pub ai_credit_micros: i64,
3365 pub credit_micros: i64,
3366 /// The trial credit left, for a workspace on its trial.
3367 #[serde(default)]
3368 pub trial_micros: Option<i64>,
3369 pub plan: PlanKind,
3370 /// Nothing is charged while g1t is being built out.
3371 pub free: bool,
3372}
3373
3374// --- AI credit -----------------------------------------------------------------
3375
3376/// Auto-reload: when AI credit falls below `threshold_micros`, the saved
3377/// card is charged to bring it back to `target_micros`, at most
3378/// `monthly_max_micros` in a calendar month. Off by default. A failed
3379/// charge turns it off and tells the owners.
3380#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
3381#[serde(rename_all = "camelCase")]
3382pub struct AiReload {
3383 pub enabled: bool,
3384 pub threshold_micros: i64,
3385 pub target_micros: i64,
3386 pub monthly_max_micros: i64,
3387 /// Reloaded this month so far.
3388 #[serde(default)]
3389 pub reloaded_micros: i64,
3390 /// When it last failed and was turned off, and why.
3391 #[serde(default)]
3392 pub failed_at: Option<String>,
3393 #[serde(default)]
3394 pub error: Option<String>,
3395}
3396
3397/// The card fee passed on when AI credit is bought by card.
3398#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
3399#[serde(rename_all = "camelCase")]
3400pub struct CardFee {
3401 pub on: bool,
3402 /// Per dollar charged, in millionths: 29,000 is 2.9%.
3403 pub percent_micros: f64,
3404 pub fixed_cents: u32,
3405}
3406
3407/// `ai_credit` (`AccountArgs`): a workspace's prepaid AI credit, what it
3408/// pays for and how it is bought. Members only. Returns `Outcome<AiCredit>`.
3409#[derive(Clone, Debug, Serialize, Deserialize)]
3410#[serde(rename_all = "camelCase")]
3411pub struct AiCredit {
3412 /// What is left to spend on Agent and AI Gateway usage.
3413 pub balance_micros: i64,
3414 /// Of it, bought (paid) and given (promotional).
3415 pub purchased_micros: i64,
3416 pub given_micros: i64,
3417 /// Its grants, newest first.
3418 pub grants: Vec<CreditGrant>,
3419 /// A 100% discount: AI usage is free, shown at its price then the
3420 /// discount. Nothing to buy.
3421 pub free_via_discount: bool,
3422 /// Invoiced terms (an enterprise): models are billed after use, so no
3423 /// credit is needed.
3424 pub postpaid: bool,
3425 /// Whether new runs on g1t's models are refused now for want of credit.
3426 pub blocked: bool,
3427 /// Whether the workspace may buy it: on the plan, not free.
3428 pub can_buy: bool,
3429 pub presets_cents: Vec<u32>,
3430 pub min_cents: u32,
3431 pub max_cents: u32,
3432 pub card_fee: CardFee,
3433 pub reload: AiReload,
3434 /// The agent rate per million tokens, now, at price.
3435 pub agent_rate_micros: f64,
3436 /// The markup on models' provider price, in percent.
3437 pub model_markup_percent: u32,
3438 /// The markup on AI Gateway's provider price, in percent.
3439 pub gateway_markup_percent: u32,
3440 /// The AI credit given once on starting the plan.
3441 pub upgrade_credit_micros: i64,
3442 /// How long bought credit lasts, in days.
3443 pub expires_days: u32,
3444}
3445
3446/// `buy_ai_credit`: Stripe's page to buy AI credit, one payment by card,
3447/// with the card fee as its own line. Owners only. Returns
3448/// `Outcome<Checkout>`; the page's id comes back to `return_url` as
3449/// `ai_credit`, for `confirm_ai_credit`.
3450#[derive(Debug, Serialize, Deserialize)]
3451#[serde(rename_all = "camelCase")]
3452pub struct BuyAiCreditArgs {
3453 pub actor: User,
3454 pub workspace: String,
3455 /// The credit, in cents; the card fee is added on top.
3456 #[serde(alias = "amount_cents")]
3457 pub amount_cents: u32,
3458 #[serde(alias = "return_url")]
3459 pub return_url: String,
3460}
3461
3462/// `confirm_ai_credit`: credits a purchase once Stripe says it was paid,
3463/// once. Safe to repeat; the webhook does the same. Returns
3464/// `Outcome<AiCredit>`.
3465#[derive(Debug, Serialize, Deserialize)]
3466pub struct ConfirmAiCreditArgs {
3467 pub workspace: String,
3468 pub viewer: Viewer,
3469 pub session: String,
3470}
3471
3472/// `set_ai_reload`: auto-reload's settings. Owners only. Returns
3473/// `Outcome<AiCredit>`.
3474#[derive(Debug, Serialize, Deserialize)]
3475#[serde(rename_all = "camelCase")]
3476pub struct SetAiReloadArgs {
3477 pub actor: User,
3478 pub workspace: String,
3479 pub enabled: bool,
3480 #[serde(alias = "threshold_micros")]
3481 pub threshold_micros: i64,
3482 #[serde(alias = "target_micros")]
3483 pub target_micros: i64,
3484 #[serde(alias = "monthly_max_micros")]
3485 pub monthly_max_micros: i64,
3486}
3487
3488// --- Budgets ------------------------------------------------------------------
3489
3490/// `set_budget`: the monthly budget on usage after included usage: the
3491/// owners' spend limit, its alerts, whether usage pauses at 100%, and an
3492/// optional webhook. Owners only. Returns `Outcome<Limit>`.
3493#[derive(Debug, Serialize, Deserialize)]
3494#[serde(rename_all = "camelCase")]
3495pub struct SetBudgetArgs {
3496 pub actor: User,
3497 pub workspace: String,
3498 /// The amount; None keeps the automatic one.
3499 #[serde(default, alias = "amount_micros")]
3500 pub amount_micros: Option<i64>,
3501 /// Some of 50, 75, 90 and 100.
3502 #[serde(default)]
3503 pub alerts: Vec<u32>,
3504 #[serde(default = "yes", alias = "pause_at_limit")]
3505 pub pause_at_limit: bool,
3506 /// An HTTPS address, or None for no webhook.
3507 #[serde(default)]
3508 pub webhook: Option<String>,
3509 /// Leave the spend limit as it is and change only the alerts, the
3510 /// pause and the webhook.
3511 #[serde(default, alias = "keep_limit")]
3512 pub keep_limit: bool,
3513}
3514
3515// --- Billing details -----------------------------------------------------------
3516
3517/// A postal address, as Stripe keeps it.
3518#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
3519#[serde(rename_all = "camelCase")]
3520pub struct PostalAddress {
3521 #[serde(default)]
3522 pub line1: String,
3523 #[serde(default)]
3524 pub line2: String,
3525 #[serde(default)]
3526 pub city: String,
3527 #[serde(default)]
3528 pub state: String,
3529 #[serde(default)]
3530 pub postal_code: String,
3531 /// Two letters, `US`.
3532 #[serde(default)]
3533 pub country: String,
3534}
3535
3536/// The default way the workspace pays, as far as it is safe to show.
3537#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
3538#[serde(rename_all = "camelCase")]
3539pub struct PaymentMethod {
3540 /// `card`, or another kind Stripe has.
3541 pub kind: String,
3542 #[serde(default)]
3543 pub brand: Option<String>,
3544 #[serde(default)]
3545 pub last4: Option<String>,
3546 #[serde(default)]
3547 pub exp_month: Option<u32>,
3548 #[serde(default)]
3549 pub exp_year: Option<u32>,
3550}
3551
3552/// One of the customer's invoices at Stripe: the plan, activations, AI
3553/// credit and month-end usage.
3554#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
3555#[serde(rename_all = "camelCase")]
3556pub struct StripeInvoice {
3557 pub id: String,
3558 #[serde(default)]
3559 pub number: Option<String>,
3560 /// `paid`, `open`, `void`, `uncollectible` or `draft`.
3561 pub status: String,
3562 pub total_cents: i64,
3563 pub currency: String,
3564 /// RFC 3339.
3565 pub created_at: String,
3566 #[serde(default)]
3567 pub description: Option<String>,
3568 #[serde(default)]
3569 pub hosted_url: Option<String>,
3570 #[serde(default)]
3571 pub pdf_url: Option<String>,
3572}
3573
3574/// What the next invoice will be, from g1t's own ledger.
3575#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
3576#[serde(rename_all = "camelCase")]
3577pub struct UpcomingInvoice {
3578 /// When the month closes, RFC 3339.
3579 pub closes_at: String,
3580 /// The plan and activations, at their monthly price.
3581 pub subscriptions_micros: i64,
3582 /// Usage still owed, after included usage, credit and any discount.
3583 pub usage_micros: i64,
3584 pub total_micros: i64,
3585}
3586
3587/// `billing_details` (`AccountArgs`): who the invoices are for, the default
3588/// payment method, and the invoices, from the Stripe customer. Members see
3589/// it; owners change it. Returns `Outcome<BillingDetails>`.
3590#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
3591#[serde(rename_all = "camelCase")]
3592pub struct BillingDetails {
3593 /// Whether the workspace has a Stripe customer yet.
3594 pub customer: bool,
3595 pub email: Option<String>,
3596 pub name: Option<String>,
3597 pub address: Option<PostalAddress>,
3598 /// `eu_vat`, `us_ein`…, and its value.
3599 pub tax_id_type: Option<String>,
3600 pub tax_id: Option<String>,
3601 /// Printed on invoices.
3602 pub po_number: Option<String>,
3603 /// The invoices' language, such as `en` or `fr`.
3604 pub language: Option<String>,
3605 pub payment_method: Option<PaymentMethod>,
3606 pub invoices: Vec<StripeInvoice>,
3607 pub upcoming: UpcomingInvoice,
3608 /// Stripe could not be read: what is shown is what g1t keeps.
3609 #[serde(default)]
3610 pub unavailable: Option<String>,
Merge Stripe Tax, the card fee on card payments, and one free workspace per person3611 /// Whether Stripe Tax can place the customer from the address: tax
3612 /// is worked out from it, and without it nothing is charged.
3613 #[serde(default)]
3614 pub tax_location: bool,
3615 /// Set when g1t did not charge for want of an address (RFC 3339).
3616 #[serde(default)]
3617 pub tax_address_needed_at: Option<String>,
3618 /// Stripe's check of the tax ID: `pending`, `verified`, `unverified` or
3619 /// `unavailable`.
3620 #[serde(default)]
3621 pub tax_id_status: Option<String>,
3622 /// `none`, `exempt` or `reverse`, as staff set it at Stripe; g1t never
3623 /// changes it.
3624 #[serde(default)]
3625 pub tax_exempt: Option<String>,
Usage, Billing settings and prepaid AI credit; fixes from the UX audit3626}
3627
3628/// `set_billing_details`: saves the invoice details on the Stripe customer.
3629/// Owners only. Absent fields are left as they are; an empty string clears
3630/// one. Returns `Outcome<BillingDetails>`.
3631#[derive(Debug, Serialize, Deserialize)]
3632#[serde(rename_all = "camelCase")]
3633pub struct SetBillingDetailsArgs {
3634 pub actor: User,
3635 pub workspace: String,
3636 #[serde(default)]
3637 pub email: Option<String>,
3638 #[serde(default)]
3639 pub name: Option<String>,
3640 #[serde(default)]
3641 pub address: Option<PostalAddress>,
3642 #[serde(default, alias = "tax_id_type")]
3643 pub tax_id_type: Option<String>,
3644 #[serde(default, alias = "tax_id")]
3645 pub tax_id: Option<String>,
3646 #[serde(default, alias = "po_number")]
3647 pub po_number: Option<String>,
3648 #[serde(default)]
3649 pub language: Option<String>,
3650}
3651
Models per workspace: several providers, routed by kind of work3652#[cfg(test)]
3653mod tests {
3654 use super::*;
3655
3656 #[test]
Prices are what g1t pays plus 20%, from the first second3657 fn an_account_carries_no_run_fee() {
3658 let account = Account {
3659 workspace: "acme".into(),
3660 balance_micros: 0,
3661 status: Status { enabled: true, live: false, free: false },
3662 margin_percent: 20,
3663 card: None,
3664 };
3665 let json = serde_json::to_value(account).unwrap();
3666 let mut keys: Vec<&str> = json.as_object().unwrap().keys().map(String::as_str).collect();
3667 keys.sort_unstable();
3668 assert_eq!(keys, ["balanceMicros", "card", "marginPercent", "status", "workspace"]);
3669 }
3670
3671 #[test]
3672 fn a_price_change_says_when_the_markup_moved() {
3673 let change = PriceChange {
3674 meter: "sandbox_second".into(),
3675 old_cost_micros: 21.0,
3676 new_cost_micros: 21.0,
3677 markup_percent: 20,
3678 old_markup_percent: Some(138),
3679 reason: "Sandbox time is now charged at cost plus 20% from the first second".into(),
3680 created_at: "2026-10-05T00:00:00Z".into(),
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily3681 effective_at: None,
Prices are what g1t pays plus 20%, from the first second3682 };
3683 assert_eq!(serde_json::to_value(&change).unwrap()["oldMarkupPercent"], 138);
3684 let cost_only = PriceChange { old_markup_percent: None, ..change };
3685 assert!(serde_json::to_value(&cost_only).unwrap().get("oldMarkupPercent").is_none());
3686 }
3687
3688 #[test]
Paid features: a workspace turns on Deployments with a monthly plan3689 fn features_are_named_as_the_site_sends_them() {
3690 assert_eq!(
3691 serde_json::to_value(Feature::Deployments).unwrap(),
3692 serde_json::json!("deployments")
3693 );
3694 assert_eq!(Feature::parse("deployments"), Some(Feature::Deployments));
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look3695 assert_eq!(serde_json::to_value(Feature::Plan).unwrap(), serde_json::json!("plan"));
3696 assert_eq!(Feature::parse("plan"), Some(Feature::Plan));
3697 // Older readers named the plan Team.
3698 assert_eq!(Feature::parse("team"), Some(Feature::Plan));
3699 assert_eq!(serde_json::from_value::<Feature>(serde_json::json!("team")).unwrap(), Feature::Plan);
Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar3700 assert_eq!(Feature::ALL, [Feature::Plan, Feature::Security]);
3701 assert_eq!(Feature::parse("security"), Some(Feature::Security));
3702 assert_eq!(serde_json::to_value(Feature::Security).unwrap(), serde_json::json!("security"));
Paid features: a workspace turns on Deployments with a monthly plan3703 assert!(SubscriptionStatus::Canceling.on());
3704 assert!(!SubscriptionStatus::PastDue.on());
3705 }
3706
3707 #[test]
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look3708 fn a_reservation_is_asked_for_and_answered_in_camel_case() {
3709 let asked: ReserveArgs = serde_json::from_value(serde_json::json!({
3710 "workspace": "acme",
3711 "repo": { "namespace": "acme", "name": "web" },
3712 "public": true,
3713 "kind": "check",
3714 "estimateMicros": 2_000_000,
3715 }))
3716 .unwrap();
3717 assert_eq!(asked.kind, ComputeKind::Check);
3718 assert!(asked.kind.open_source_pool());
3719 assert!(!ComputeKind::Agent.open_source_pool());
3720 // Rust callers that write snake_case are read too.
3721 let snake: ReserveArgs = serde_json::from_value(serde_json::json!({
3722 "workspace": "acme",
3723 "repo": { "namespace": "acme", "name": "web" },
3724 "public": false,
3725 "kind": "agent",
3726 "estimate_micros": 1,
3727 }))
3728 .unwrap();
3729 assert_eq!(snake.estimate_micros, 1);
3730 let answer = Reservation { id: "rsv_1".into(), paid_by: PaidBy::OnDemand, held_micros: 5, expires_at: String::new() };
3731 assert_eq!(serde_json::to_value(&answer).unwrap()["paidBy"], "on_demand");
3732 assert_eq!(serde_json::to_value(PlanKind::Internal).unwrap(), "internal");
3733 assert!(!PlanKind::Free.on_demand() && PlanKind::Enterprise.on_demand());
3734 }
3735
3736 #[test]
3737 fn a_refusal_carries_its_own_code() {
3738 let refused: crate::Outcome<Reservation> =
3739 crate::Outcome::fail(crate::FailureCode::OssPoolEmpty, "The open-source pool is spent.");
3740 let json = serde_json::to_value(&refused).unwrap();
3741 assert_eq!(json["error"]["code"], "oss_pool_empty");
3742 assert_eq!(crate::FailureCode::NotPaid.http_status(), 402);
3743 assert_eq!(crate::FailureCode::Paused.http_status(), 409);
3744 }
3745
3746 #[test]
Models per workspace: several providers, routed by kind of work3747 fn who_pays_is_read_as_the_runner_sends_it() {
3748 let run: StartRunArgs = serde_json::from_value(serde_json::json!({
3749 "workspace": "acme",
3750 "repo": { "namespace": "acme", "name": "web" },
3751 "number": 7,
3752 "task": "implement",
3753 "model": "Claude Sonnet 5.5",
3754 "billedTo": "workspace",
3755 }))
3756 .unwrap();
3757 assert_eq!(run.billed_to, "workspace");
3758 }
3759}

This file's history is long; its oldest lines are credited to the oldest commit read.