g1t/crates/contracts/src/billing.rs

2,295 lines83,623 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,
Agents as a team: lifecycle, merge queue, billing and a new shell193}
194
Integrations: your own model provider, alerts that open issues, tickets agents read195fn g1t() -> String {
196 "g1t".to_owned()
197}
198
Agents as a team: lifecycle, merge queue, billing and a new shell199/// `account` (`Outcome<Account>`) and `ledger` (`Outcome<Vec<LedgerEntry>>`,
200/// newest first). Members of the workspace only.
201#[derive(Debug, Serialize, Deserialize)]
202pub struct AccountArgs {
203 pub workspace: String,
204 pub viewer: Viewer,
205}
206
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look207/// `checkout`: prepays usage: money paid in advance, drawn down by usage
208/// after the plan's included usage, which raises what can be used before
209/// work stops by the same amount at once. $25 at the least. By card, with
210/// 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 shell211/// only. Returns `Outcome<Checkout>`.
212#[derive(Debug, Serialize, Deserialize)]
213#[serde(rename_all = "camelCase")]
214pub struct CheckoutArgs {
215 pub actor: User,
216 pub workspace: String,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look217 /// How much to prepay, in cents.
Agents as a team: lifecycle, merge queue, billing and a new shell218 pub amount_cents: u32,
219 /// Where the payment page sends the person afterwards. The payment's
220 /// id is appended as `session`.
221 pub return_url: String,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look222 /// `card` (the default) or `bank_transfer` (from $1,000): Stripe gives
223 /// the account details, and the money counts once it arrives.
224 #[serde(default)]
225 pub method: Option<String>,
Agents as a team: lifecycle, merge queue, billing and a new shell226}
227
228#[derive(Debug, Serialize, Deserialize)]
229pub struct Checkout {
230 /// The payment page to send the person to.
231 pub url: String,
232}
233
234/// `confirm`: credits a payment once the provider says it was made. Safe
235/// to call any number of times. Returns `Outcome<Account>`.
236#[derive(Debug, Serialize, Deserialize)]
237pub struct ConfirmArgs {
238 pub workspace: String,
239 pub viewer: Viewer,
240 /// The payment's id, as returned to `return_url`.
241 pub session: String,
242}
243
244/// `can_start`: whether a workspace may start an agent now, asked before
245/// anything is opened for it. Returns `Outcome<bool>`: a failure, with the
246/// reason to show, when it has no credit.
247#[derive(Debug, Serialize, Deserialize)]
248pub struct CanStartArgs {
249 pub workspace: String,
250}
251
252/// `start_run`: asks whether a workspace may start an agent, and opens the
253/// run it will be charged for. Called by the runner service. Returns
254/// `Outcome<Option<RunTicket>>`: no ticket when billing is off, a failure
255/// when the workspace has no credit.
256#[derive(Debug, Serialize, Deserialize)]
257pub struct StartRunArgs {
258 pub workspace: String,
259 pub repo: RepoPath,
260 pub number: u32,
261 /// `implement`, `review` or `update`.
262 pub task: String,
263 /// The model, by its public name.
264 pub model: String,
Integrations: your own model provider, alerts that open issues, tickets agents read265 /// `workspace` when the run uses the workspace's own model provider.
Models per workspace: several providers, routed by kind of work266 /// The runner, which is TypeScript, sends it as `billedTo`.
267 #[serde(default = "g1t", alias = "billedTo")]
Integrations: your own model provider, alerts that open issues, tickets agents read268 pub billed_to: String,
Prices keep themselves current with what g1t pays269 /// The model session's id, when its requests go through g1t's AI
270 /// Gateway: settling charges the run what the gateway priced them at.
271 #[serde(default)]
272 pub session: Option<String>,
Agents as a team: lifecycle, merge queue, billing and a new shell273}
274
275#[derive(Clone, Debug, Serialize, Deserialize)]
276#[serde(rename_all = "camelCase")]
277pub struct RunTicket {
278 pub run_id: String,
279 /// Lets the sandbox, and nothing else, report what this run cost.
280 pub token: String,
281}
282
283/// `finish_run`: what a run cost, as its sandbox reports it. Charged once.
284/// Returns `Outcome<bool>`.
285#[derive(Debug, Serialize, Deserialize)]
286#[serde(rename_all = "camelCase")]
287pub struct FinishRunArgs {
288 pub run_id: String,
289 pub token: String,
290 /// What the model provider charged, in US dollars.
291 pub cost_usd: f64,
292 #[serde(default)]
293 pub turns: u32,
294}
Usage, like a hosting provider's: what agents cost, per day, task, repository and pull request295
296
297/// `usage`: what a workspace's agents cost over a period, broken down.
298/// Members only. Returns `Outcome<Usage>`.
299#[derive(Debug, Serialize, Deserialize)]
300pub struct UsageArgs {
301 pub workspace: String,
302 pub viewer: Viewer,
303 /// RFC 3339: the start of the period. The period runs to now.
304 pub since: String,
305}
306
307/// One slice of usage: what it was for, what it cost, how many runs.
308#[derive(Clone, Debug, Serialize, Deserialize)]
309#[serde(rename_all = "camelCase")]
310pub struct UsageSlice {
311 pub key: String,
312 pub micros: i64,
313 pub runs: u32,
314}
315
316/// What a workspace's agents cost over a period.
317#[derive(Clone, Debug, Serialize, Deserialize)]
318#[serde(rename_all = "camelCase")]
319pub struct Usage {
320 pub since: String,
321 /// Charged, including g1t's margin.
322 pub spent_micros: i64,
Integrations: your own model provider, alerts that open issues, tickets agents read323 /// What g1t's model provider charged, before the margin.
Usage, like a hosting provider's: what agents cost, per day, task, repository and pull request324 pub cost_micros: i64,
Integrations: your own model provider, alerts that open issues, tickets agents read325 /// What runs on the workspace's own provider cost there, as the harness
326 /// estimated it. Not charged by g1t.
327 pub provider_micros: i64,
Usage while free is shown at cost; agents get rustfmt and clippy328 /// What the runs used, at cost: g1t's models and the workspace's own
329 /// provider together, whatever was charged for them.
330 pub used_micros: i64,
331 /// g1t charges nothing for now. The slices then measure usage at cost,
332 /// since every charge is zero.
333 pub free: bool,
Usage, like a hosting provider's: what agents cost, per day, task, repository and pull request334 pub runs: u32,
335 /// Spend per day (`YYYY-MM-DD`) and task, as `day/task` keys.
336 pub by_day: Vec<UsageSlice>,
337 /// Per task: implement, review, revise, update, plan.
338 pub by_task: Vec<UsageSlice>,
339 /// Per repository, `namespace/name`.
340 pub by_repo: Vec<UsageSlice>,
341 /// The pull requests that cost most, as `namespace/name#number`.
342 pub by_pull: Vec<UsageSlice>,
343 /// Per model, by its public name.
344 pub by_model: Vec<UsageSlice>,
345 /// Credit bought in the period.
346 pub added_micros: i64,
347}
Models per workspace: several providers, routed by kind of work348
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look349/// What a workspace pays a monthly price for. There is one plan, `plan`
350/// ("g1t"): a flat price per workspace, never per person, with included
351/// usage each month, more private storage, and deployments. Never free:
352/// `FREE_WHILE_BUILDING` does not cover it.
353///
354/// `deployments` is not sold on its own any more: it comes with the plan.
355/// A service that asks `has_feature` for it is told whether the workspace
356/// has the plan, and a Deployments subscription bought before the change
357/// keeps working until its period ends.
Paid features: a workspace turns on Deployments with a monthly plan358#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
359#[serde(rename_all = "snake_case")]
360pub enum Feature {
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look361 /// The g1t plan. Older readers called it `team`.
362 #[serde(alias = "team")]
363 Plan,
364 /// Previews per pull request and production on g1t.page: part of the
365 /// plan.
Paid features: a workspace turns on Deployments with a monthly plan366 Deployments,
367}
368
369impl Feature {
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look370 /// What is sold: the plan alone.
371 pub const ALL: [Feature; 1] = [Feature::Plan];
Paid features: a workspace turns on Deployments with a monthly plan372
373 pub fn as_str(self) -> &'static str {
374 match self {
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look375 Feature::Plan => "plan",
Paid features: a workspace turns on Deployments with a monthly plan376 Feature::Deployments => "deployments",
377 }
378 }
379
380 pub fn parse(name: &str) -> Option<Feature> {
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look381 match name {
382 "plan" | "team" => Some(Feature::Plan),
383 "deployments" => Some(Feature::Deployments),
384 _ => None,
385 }
Paid features: a workspace turns on Deployments with a monthly plan386 }
387
388 pub fn title(self) -> &'static str {
389 match self {
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look390 Feature::Plan => "g1t",
Paid features: a workspace turns on Deployments with a monthly plan391 Feature::Deployments => "Deployments",
392 }
393 }
394}
395
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas396/// What deployments cost g1t, in millionths of a dollar: fallbacks for
397/// when billing's price book cannot be read. Nothing here is an allowance:
398/// on the plan every unit is metered from the first, at cost plus the
399/// margin, and drawn from the plan's included usage before anything is
400/// charged. Projects, previews and the apps behind them are not metered at
401/// all: Cloudflare's Workers for Platforms includes far more scripts than
402/// g1t runs, so an app costs g1t only the requests and CPU it answers with.
403pub mod deployment_costs {
404 /// Workers for Platforms: $0.30 per million requests.
Paid features: a workspace turns on Deployments with a monthly plan405 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 quotas406 /// $0.02 per million CPU milliseconds.
Paid features: a workspace turns on Deployments with a monthly plan407 pub const MICROS_PER_MILLION_CPU_MS: i64 = 20_000;
Deployments: a preview for every pull request, production on g1t.page408 /// 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 look409 /// Containers, standard-1: half a vCPU, 4 GiB, 8 GB disk), rounded up,
410 /// as the price keeper measured it on 2026-10-05 (14.5). Only a
411 /// fallback: billing charges builds at the price book's `build_second`,
412 /// which the keeper keeps current.
413 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 quotas414 /// What one custom hostname costs g1t a month (Cloudflare for SaaS):
415 /// $0.10.
Agents and memory, checks and conflicts, profiles, slug renames, custom domains416 pub const MICROS_PER_DOMAIN_MONTH: i64 = 100_000;
Paid features: a workspace turns on Deployments with a monthly plan417}
418
Every sandbox is metered by the second419/// `record_sandbox`: how long one sandbox ran for a workspace, reported by
Prices are what g1t pays plus 20%, from the first second420/// the runner when it stops. Every sandbox g1t starts for a workspace
421/// (agents, reviews, checks, the merge queue, workflow jobs) is metered by
422/// the second, from the first: recorded once per `reference`, with what it
423/// cost g1t, and charged at the price book's `sandbox_second` price unless
424/// `FREE_WHILE_BUILDING`. Deploy builds are charged by the Deployments plan
425/// instead.
Every sandbox is metered by the second426/// Returns `Outcome<bool>`: false if that reference was recorded before.
427#[derive(Debug, Serialize, Deserialize)]
428#[serde(rename_all = "camelCase")]
429pub struct RecordSandboxArgs {
430 pub workspace: String,
431 pub seconds: u32,
432 /// What ran, e.g. `Checks on acme/api#12`.
433 pub description: String,
434 /// `namespace/name`.
435 pub repo: Option<String>,
436 /// Unique to the run.
437 pub reference: String,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look438 /// What ran: `agent`, `check`, `workflow` or `queue`. Decides whether
439 /// g1t's open-source pool may pay for it (checks, workflows and the
440 /// merge queue on public repositories). Absent: not the pool.
441 #[serde(default)]
442 pub kind: Option<ComputeKind>,
443 /// The vCPU-seconds the sandbox used, when it can tell. With it, the
444 /// run is priced on its own CPU (`sandbox_base_second` per second plus
445 /// `sandbox_cpu_second` per vCPU-second); without it, at the average
446 /// (`sandbox_second`).
447 #[serde(default, alias = "cpu_seconds")]
448 pub cpu_seconds: Option<f64>,
449 /// The reservation the work started under, settled with this cost.
450 #[serde(default, alias = "reservation_id")]
451 pub reservation_id: Option<String>,
Fast pages, required checks on the branch, self-hosted runners, honest incidents452 /// It ran on one of the workspace's self-hosted runners: recorded as
453 /// self-hosted time, for the minutes, at $0.
454 #[serde(default, alias = "self_hosted")]
455 pub self_hosted: bool,
456 /// The machine it ran on, by label (`g1t-4core`); absent, the standard
457 /// one. A larger machine's memory and disk cost more each second.
458 #[serde(default)]
459 pub instance: Option<String>,
Every sandbox is metered by the second460}
461
Usage limits: unpaid usage can only go so far462/// How much a workspace has earned g1t's trust with money, which sets how
463/// far its unpaid usage can go before its work stops.
464#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
465#[serde(rename_all = "snake_case")]
466pub enum Trust {
467 /// No live payment yet: only a little past the free allowances.
468 New,
469 /// Has paid g1t real money: the ceiling grows with what it has paid.
470 Paid,
Two limits, real invoices, trust that grows by itself, sales signals471 /// Has paid steadily for months, with nothing disputed or declined:
472 /// the ceiling follows its monthly spend, up to $10,000, by itself.
473 Established,
Usage limits: unpaid usage can only go so far474 /// A ceiling g1t set by hand, after talking to the workspace.
475 Reviewed,
476 /// g1t's own workspaces: no ceiling.
477 Internal,
478}
479
480#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
481#[serde(rename_all = "snake_case")]
482pub enum LimitState {
483 Ok,
484 /// Past 80% of the ceiling.
485 Warning,
486 /// At or past it: no new sandboxes, builds or app requests.
487 Stopped,
488}
489
490/// How far a workspace's unpaid usage has gone this month, and where its
491/// work stops: like Fly's or Cloudflare's limits for new accounts, so no
492/// one runs up costs g1t cannot collect. Usage counts at what it cost g1t
493/// or what it is charged, whichever is more, so it counts while g1t is
494/// free too.
495#[derive(Clone, Debug, Serialize, Deserialize)]
496#[serde(rename_all = "camelCase")]
497pub struct Limit {
498 pub workspace: String,
Billing accounts, terms and enterprises; g1t is no longer free499 /// The account that pays, whose usage and payments the limit counts:
500 /// the workspace's own, or its enterprise's.
501 #[serde(default)]
502 pub account: String,
503 #[serde(default)]
504 pub account_name: String,
Usage limits: unpaid usage can only go so far505 pub trust: Trust,
506 /// Usage this month (UTC) less what was paid this month.
507 pub exposure_micros: i64,
508 /// Where work stops: the lower of g1t's ceiling and the owner's own
509 /// spend limit. None for g1t's own workspaces.
510 pub ceiling_micros: Option<i64>,
511 /// The ceiling g1t sets from `trust`.
512 pub trust_ceiling_micros: Option<i64>,
513 /// The owner's own monthly limit, if they set one.
514 pub spend_limit_micros: Option<i64>,
515 pub state: LimitState,
516 /// What to tell people when work is stopped or close to it.
517 pub message: Option<String>,
Two limits, real invoices, trust that grows by itself, sales signals518 /// Charged this month, which the spend limit is measured against.
519 #[serde(default)]
520 pub spent_micros: i64,
521 /// True while the owners have not chosen a spend limit of their own, so
522 /// the automatic one applies: $200, or twice last month's spend.
523 #[serde(default)]
524 pub default_spend_limit: bool,
525 /// The most the owners may set their own limit to: g1t's ceiling. To
526 /// go past it, they contact g1t.
527 #[serde(default)]
528 pub available_micros: Option<i64>,
529 /// How the ceiling grows from here, in a sentence.
530 #[serde(default)]
531 pub growth: Option<String>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look532 /// Money paid in advance and not used yet. It raises what can be used
533 /// before work stops by the same amount, at once.
534 #[serde(default)]
535 pub prepaid_micros: i64,
536 /// The highest ceiling the workspace has ever had. Owners may set their
537 /// spend limit anywhere up to it (plus what is prepaid) without asking.
538 #[serde(default)]
539 pub max_ceiling_micros: Option<i64>,
540 /// The most the owners may raise the limit to themselves, once, with
541 /// `raise_once`: twice the highest ceiling. None once it is used.
542 #[serde(default)]
543 pub raise_once_micros: Option<i64>,
544 /// When the one-time raise was used, RFC 3339.
545 #[serde(default)]
546 pub raised_at: Option<String>,
547 /// True in a paid workspace's first billing cycle, when the ceiling is
548 /// the starting one (`LIMIT_PAID_START_MICROS`).
549 #[serde(default)]
550 pub first_month: bool,
Usage limits: unpaid usage can only go so far551}
552
553/// `limit`: a workspace's limit, for its members. Returns `Outcome<Limit>`.
554#[derive(Debug, Serialize, Deserialize)]
555pub struct LimitArgs {
556 pub workspace: String,
557 pub viewer: Viewer,
558}
559
560/// `check_limit`: the same, for the services that enforce it. Returns
561/// `Outcome<Limit>`.
562#[derive(Debug, Serialize, Deserialize)]
563pub struct CheckLimitArgs {
564 pub workspace: String,
565}
566
Prices keep themselves current with what g1t pays567/// `note_pending`: usage this month that will be charged later, such as
568/// app traffic past a plan, so the workspace's limit counts it now. Each
569/// report replaces the last for that workspace, source and month. Called
570/// by the service that meters it. Returns `bool`.
571#[derive(Debug, Serialize, Deserialize)]
572#[serde(rename_all = "camelCase")]
573pub struct NotePendingArgs {
574 pub workspace: String,
Fast pages, required checks on the branch, self-hosted runners, honest incidents575 /// `deployments`, `security` (scans), `context` (search embeddings),
576 /// `storage` or `cache` (actions/cache, plan only). Billing charges
577 /// `security`, `context`, `storage` and `cache` itself once the month
578 /// is over; `deployments` charges its own.
Prices keep themselves current with what g1t pays579 pub source: String,
580 /// What it cost g1t so far this month, before the margin.
581 pub cost_micros: i64,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas582 /// How much of it, for the Billing page: `1.2 million requests and
583 /// 3.4 million CPU ms`, `2 custom domains`.
584 #[serde(default)]
585 pub detail: Option<String>,
Prices keep themselves current with what g1t pays586}
587
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas588/// `usage_meters`: this month's usage for a workspace, one line per kind
589/// of meter, at what it is charged (cost plus the margin, on the account's
590/// terms) before the plan's included usage, the trial or g1t's pools paid
591/// for any of it. Members only. Returns `Outcome<Vec<MeterUsage>>`.
592#[derive(Debug, Serialize, Deserialize)]
593pub struct UsageMetersArgs {
594 pub workspace: String,
595 pub viewer: Viewer,
596}
597
598/// One kind of meter's usage this month.
599#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
600#[serde(rename_all = "camelCase")]
601pub struct MeterUsage {
602 /// `agents` (agent runs, models and sandboxes for checks, workflows
603 /// and the merge queue), `builds`, `requests` (app requests and CPU),
604 /// `domains`, `git_storage` (git operations and private storage) or
605 /// `search_scans` (search embeddings and security scans).
606 pub key: String,
607 pub label: String,
608 /// At price, before what paid for it.
609 pub micros: i64,
610 /// How much, when it is known: `12 runs`, `41 build minutes`.
611 #[serde(default)]
612 pub quantity: Option<String>,
613}
614
Usage limits: unpaid usage can only go so far615/// `set_spend_limit`: the owner's own monthly ceiling, under g1t's; None
616/// removes it. Owners only. Returns `Outcome<Limit>`.
617#[derive(Debug, Serialize, Deserialize)]
618#[serde(rename_all = "camelCase")]
619pub struct SetSpendLimitArgs {
620 pub actor: User,
621 pub workspace: String,
Two limits, real invoices, trust that grows by itself, sales signals622 /// A monthly limit, at most what is available; None goes back to the
623 /// default.
Usage limits: unpaid usage can only go so far624 pub spend_limit_micros: Option<i64>,
Two limits, real invoices, trust that grows by itself, sales signals625 /// Use everything available, with no limit of their own.
626 #[serde(default)]
627 pub use_full_limit: bool,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look628 /// Use the one-time raise: up to twice the highest ceiling the
629 /// workspace has had, without asking. Once per workspace.
630 #[serde(default, alias = "raiseOnce")]
631 pub raise_once: bool,
Usage limits: unpaid usage can only go so far632}
633
Prices keep themselves current with what g1t pays634/// One metered unit: what it costs g1t, and what it is sold at. The price
635/// is always `cost × (100 + markup) / 100`, so it follows the cost.
636#[derive(Clone, Debug, Serialize, Deserialize)]
637#[serde(rename_all = "camelCase")]
638pub struct Price {
639 /// `sandbox_second`, `build_second`, `app_requests`, `app_cpu`, `app_month`.
640 pub meter: String,
641 pub title: String,
642 pub unit: String,
643 /// Millionths of a dollar per unit; may have a fraction.
644 pub cost_micros: f64,
645 pub markup_percent: u32,
646 pub price_micros: f64,
647 /// `list`: Cloudflare's published price. `cloudflare`: what Cloudflare
648 /// actually billed g1t, measured.
649 pub source: String,
650 /// When it was last checked against Cloudflare's bill.
651 pub checked_at: Option<String>,
652 pub updated_at: String,
653}
654
655impl Price {
656 pub fn price_for(cost_micros: f64, markup_percent: u32) -> f64 {
657 cost_micros * f64::from(100 + markup_percent) / 100.0
658 }
659}
660
661/// A cost that moved.
662#[derive(Clone, Debug, Serialize, Deserialize)]
663#[serde(rename_all = "camelCase")]
664pub struct PriceChange {
665 pub meter: String,
666 pub old_cost_micros: f64,
667 pub new_cost_micros: f64,
668 pub markup_percent: u32,
Prices are what g1t pays plus 20%, from the first second669 /// The markup before, when the change was to the markup rather than
670 /// to the cost. Absent when the markup stayed `markup_percent`.
671 #[serde(default, skip_serializing_if = "Option::is_none")]
672 pub old_markup_percent: Option<u32>,
Prices keep themselves current with what g1t pays673 pub reason: String,
674 pub created_at: String,
675}
676
677/// `prices`: every metered price and the recent changes. Public. Returns
678/// `PriceBook`.
679#[derive(Clone, Debug, Serialize, Deserialize)]
680#[serde(rename_all = "camelCase")]
681pub struct PriceBook {
682 pub prices: Vec<Price>,
683 pub changes: Vec<PriceChange>,
684 /// The margin on model usage, which is charged at what AI Gateway
685 /// priced each request at.
686 pub model_margin_percent: u32,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put687 /// Every plan, as it is sold now.
688 #[serde(default)]
689 pub plans: Vec<Plan>,
690 /// What is free, and what pays for it.
691 #[serde(default)]
692 pub free: Option<FreeTier>,
Prices keep themselves current with what g1t pays693}
694
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put695/// What g1t gives without a plan, each with what pays for it: a capped
696/// budget, never an open-ended allowance.
697#[derive(Clone, Debug, Default, Serialize, Deserialize)]
698#[serde(rename_all = "camelCase")]
699pub struct FreeTier {
700 /// Each new workspace's trial credit, once.
701 pub trial_workspace_micros: i64,
702 /// Trial grants each month, in all; new trials wait when it is spent.
703 pub trial_monthly_pool_micros: i64,
704 /// g1t's open-source pool each month, and any one repository's share.
705 pub oss_pool_micros: i64,
706 pub oss_repo_micros: i64,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas707 /// Private repository storage that is free for every workspace. Past
708 /// it, the plan pays at cost plus the margin; a free workspace's pushes
709 /// to private repositories stop instead.
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put710 pub free_private_storage_bytes: i64,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look711 /// Days of audit log, the same on every plan.
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put712 pub audit_retention_days: u32,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look713 /// The smallest amount a card is charged when a month closes; less
714 /// 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 put715 pub min_charge_micros: i64,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas716 /// Git operations (clones, fetches and pushes through g1t) that are
717 /// free for every workspace each month. Past it, the plan pays at cost
718 /// plus the margin and is never slowed; a free workspace is slowed
719 /// down, never charged.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look720 #[serde(default)]
721 pub git_operations_included: u64,
722 /// A new paid workspace's ceiling in its first month.
723 #[serde(default)]
724 pub paid_start_ceiling_micros: i64,
725 /// The most a one-click goodwill credit can cost g1t.
726 #[serde(default)]
727 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 put728}
729
Billing accounts, terms and enterprises; g1t is no longer free730/// Who pays: a billing account. Every workspace has one; by default its
731/// own. An enterprise account pays for several workspaces at once, as
732/// GitHub Enterprise does: one bill, one limit, one set of terms.
733#[derive(Clone, Debug, Serialize, Deserialize)]
734#[serde(rename_all = "camelCase")]
735pub struct BillingAccount {
736 /// `ws_<slug>` for a workspace's own account; `ent_…` for an enterprise.
737 pub id: String,
738 pub kind: AccountKind,
739 pub name: String,
740 pub terms: Terms,
741 /// The workspaces it pays for.
742 pub workspaces: Vec<String>,
Stripe webhooks, enterprise invoices, and sudo for both743 /// Where an enterprise's invoices go.
744 #[serde(default)]
745 pub billing_email: Option<String>,
746 /// An enterprise's invoices, newest first. Empty for a workspace's own.
747 #[serde(default)]
748 pub invoices: Vec<EnterpriseInvoice>,
Billing accounts, terms and enterprises; g1t is no longer free749 pub created_at: String,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put750 /// What g1t staff set for the account beyond its terms.
751 #[serde(default)]
752 pub allowances: Allowances,
753}
754
755/// Set per account by g1t staff in sudo, on top of its terms.
756#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
757#[serde(rename_all = "camelCase")]
758pub struct Allowances {
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look759 /// The g1t plan without paying for its monthly price, such as for a
760 /// partner. Usage is charged as usual. Comped accounts have it anyway.
761 #[serde(default, alias = "team")]
762 pub plan: bool,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put763 /// Each of the account's public repositories' monthly cap on g1t's
764 /// open-source pool, in place of `OSS_REPO_MICROS`. None: the default.
765 #[serde(default)]
766 pub oss_repo_micros: Option<i64>,
767 /// The trial credit each of its workspaces gets, in place of
768 /// `TRIAL_WORKSPACE_MICROS`, outside the monthly pool. None: the default.
769 #[serde(default)]
770 pub trial_micros: Option<i64>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look771 /// Agents at once, in place of the plan's (2 in the first month or on
772 /// the trial, then 10). None: the default.
773 #[serde(default)]
774 pub max_concurrent_agents: Option<u32>,
775 /// One run's spend cap, in place of `RUN_CAP_MICROS` and the owners'
776 /// own. None: theirs, or the default.
777 #[serde(default)]
778 pub run_cap_micros: Option<i64>,
779 /// What the agents on one issue may spend in all, in place of
780 /// `ISSUE_CAP_MICROS` and the owners' own. None: theirs, or the default.
781 #[serde(default)]
782 pub issue_cap_micros: Option<i64>,
783 /// A hold g1t staff put on new compute, with why. None: no hold.
784 #[serde(default)]
785 pub hold: Option<String>,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put786}
787
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look788/// `admin_set_allowances`: the plan on or off without charge, overrides of
789/// the plan's caps, a hold, and the account's share of g1t's pools.
790/// 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 put791#[derive(Debug, Serialize, Deserialize)]
792pub struct AdminSetAllowancesArgs {
793 pub id: String,
794 pub allowances: Allowances,
795 pub note: String,
796 pub by: String,
797}
798
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look799// --- Entitlements, and compute started under a reservation -----------------
800//
801// Every service that starts compute (sandboxes for agents, checks,
802// workflows and the merge queue; builds; models; semantic search) asks
803// billing first:
804//
805// 1. `entitlements { workspace }` says what the workspace may do at all:
806// its plan, whether it may start compute, its caps, and whether compute
807// is paused.
808// 2. `reserve { workspace, repo, public, kind, estimate_micros }` holds the
809// work's estimated cost against what may pay for it, so that starts at
810// the same moment cannot overshoot the ceiling together. It answers who
811// pays first, or refuses with a stable code and a message for the owner.
812// 3. `settle { reservation_id, actual_micros }` releases the hold once the
813// work is done. The charge itself goes on the ledger the usual way
814// (`finish_run`, `record_sandbox`, `charge_feature`, `note_pending`).
815//
816// A reservation never settled expires after `RESERVATION_HOURS`.
817
818/// A reservation that is never settled stops holding after this long.
819pub const RESERVATION_HOURS: u64 = 3;
820/// What a ceiling reads as when there is none (g1t's own workspaces): a
821/// billion dollars, which JavaScript holds exactly.
822pub const UNLIMITED_MICROS: i64 = 1_000_000_000_000_000;
823
824/// What a workspace pays g1t on, as far as compute is concerned.
825#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
826#[serde(rename_all = "snake_case")]
827pub enum PlanKind {
828 /// No plan: the forge is free; compute only from a trial or g1t's
829 /// open-source pool, after a card check.
830 Free,
831 /// The g1t plan, paid for (or given by g1t staff without its price).
832 Paid,
833 /// g1t's own workspaces and Flagon's (comped terms): the plan without
834 /// being charged. Usage is still recorded at what it cost.
835 Internal,
836 /// Paid for by an enterprise account, invoiced.
837 Enterprise,
838}
839
840impl PlanKind {
841 pub fn as_str(self) -> &'static str {
842 match self {
843 PlanKind::Free => "free",
844 PlanKind::Paid => "paid",
845 PlanKind::Internal => "internal",
846 PlanKind::Enterprise => "enterprise",
847 }
848 }
849
850 /// Whether usage past what is included may be charged (on demand).
851 pub fn on_demand(self) -> bool {
852 !matches!(self, PlanKind::Free)
853 }
854}
855
856/// What compute is for.
857#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
858#[serde(rename_all = "snake_case")]
859pub enum ComputeKind {
860 /// An agent's run: its sandbox and its model.
861 Agent,
862 /// Checks on a pull request.
863 Check,
864 /// A workflow job.
865 Workflow,
866 /// The merge queue's checks.
867 Queue,
868 /// A deployment's build.
869 Deploy,
870 /// Semantic search: embeddings in the context hub.
871 Embedding,
872}
873
874impl ComputeKind {
875 pub fn as_str(self) -> &'static str {
876 match self {
877 ComputeKind::Agent => "agent",
878 ComputeKind::Check => "check",
879 ComputeKind::Workflow => "workflow",
880 ComputeKind::Queue => "queue",
881 ComputeKind::Deploy => "deploy",
882 ComputeKind::Embedding => "embedding",
883 }
884 }
885
886 /// Whether g1t's open-source pool may pay for it on a public
887 /// repository: checks, workflows and the merge queue only.
888 pub fn open_source_pool(self) -> bool {
889 matches!(self, ComputeKind::Check | ComputeKind::Workflow | ComputeKind::Queue)
890 }
891}
892
893/// Who pays first for reserved work. What the first source cannot cover
894/// falls to the next, in this order.
895#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
896#[serde(rename_all = "snake_case")]
897pub enum PaidBy {
898 /// The plan's included usage this month.
899 Credit,
900 /// The workspace's one-time trial credit.
901 Trial,
902 /// g1t's open-source pool.
903 Oss,
904 /// Charged to the workspace, at cost plus the margin.
905 OnDemand,
906}
907
908/// `entitlements`: what a workspace may do now, for the services that
909/// start compute and the pages that show it. Takes `EntitlementsArgs`;
910/// 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 put911#[derive(Debug, Serialize, Deserialize)]
912pub struct EntitlementsArgs {
913 pub workspace: String,
914}
915
916#[derive(Clone, Debug, Serialize, Deserialize)]
917#[serde(rename_all = "camelCase")]
918pub struct Entitlements {
919 pub workspace: String,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look920 pub plan: PlanKind,
921 /// May start sandboxes, models, deployments and semantic search at all:
922 /// paid, internal and enterprise workspaces, or a free one with trial
923 /// credit left. A free workspace may still use the open-source pool
924 /// for checks, workflows and the merge queue on public repositories
925 /// after a card check; `reserve` decides that per start.
926 pub compute: bool,
927 /// The one-time trial credit left; 0 if none was granted or it is used.
928 pub trial_micros_left: i64,
929 /// A card check has been done. The trial and the open-source pool need
930 /// it.
931 pub trial_verified: bool,
932 /// A paid workspace still in its first billing cycle.
933 pub first_month: bool,
934 /// Agents at once: 2 in the first month or on the trial, 10 after;
935 /// staff can override it.
936 pub max_concurrent_agents: u32,
937 /// The longest one run may take: 60 minutes in the first month or on
938 /// the trial; otherwise the guardrails' own caps (`MAX_MINUTES`).
939 pub max_run_minutes: u32,
940 /// One run's spend cap (`RUN_CAP_MICROS`, $2 by default); staff can
941 /// override it.
942 pub run_cap_micros: i64,
943 /// What agents may spend on one issue in all (`ISSUE_CAP_MICROS`, $10
944 /// by default); the owners can set it (`set_caps`), and staff override.
945 pub issue_cap_micros: i64,
946 /// Where on-demand work stops: g1t's ceiling on usage not yet paid
947 /// for. `UNLIMITED_MICROS` for g1t's own workspaces; 0 for a free one,
948 /// which has no on-demand usage.
949 pub ceiling_micros: i64,
950 /// Usage not yet paid for this month, with prepayment taken off.
951 pub exposure_micros: i64,
952 /// Why new compute is paused, for the owner: the limit is reached, a
953 /// spend spike is waiting for an owner to confirm it, or g1t staff put
954 /// a hold on it. None when it is not.
955 pub paused: Option<String>,
956 // What the workspace's plan gives it, for its pages.
957 /// What open reservations hold now.
958 #[serde(default)]
959 pub held_micros: i64,
960 /// Paid in advance and not used yet.
961 #[serde(default)]
962 pub prepaid_micros: i64,
963 /// The plan's included usage each month, and what of it is used.
964 #[serde(default)]
965 pub included_micros: i64,
966 #[serde(default)]
967 pub included_used_micros: i64,
968 /// How far back the audit log can be read and exported: the same on
969 /// every plan.
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put970 pub audit_retention_days: u32,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas971 /// Private repository storage that is free for every workspace: past
972 /// 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 put973 pub free_private_storage_bytes: i64,
974 /// The last daily measure of the workspace's private repositories.
975 pub private_storage_bytes: i64,
976 /// What g1t's open-source pool paid for the workspace this month.
977 pub oss_paid_micros: i64,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas978 /// Deploy build time this month, every second of it metered.
979 #[serde(default)]
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put980 pub build_seconds_used: u32,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas981 /// Git operations this month, and how many are free for every
982 /// 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 look983 #[serde(default)]
984 pub git_operations: u64,
985 #[serde(default)]
986 pub git_operations_included: u64,
987 /// 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 put988 pub min_charge_micros: i64,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look989 /// A spend spike waiting for an owner, or decided.
990 #[serde(default)]
991 pub spike: Option<Spike>,
992 /// Where usage stands against what is included and the limits, from 50%.
993 #[serde(default)]
994 pub alerts: Vec<UsageAlert>,
995}
996
997/// One level reached: 50, 75, 90 or 100 percent of something.
998#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
999#[serde(rename_all = "camelCase")]
1000pub struct UsageAlert {
1001 /// `included` (the plan's included usage), `spend_limit` (the owners'
1002 /// own limit) or `ceiling` (g1t's, on usage not yet paid for).
1003 pub meter: String,
1004 pub level: u32,
1005 pub used_micros: i64,
1006 pub limit_micros: i64,
1007 pub message: String,
Billing accounts, terms and enterprises; g1t is no longer free1008}
1009
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1010/// An hour's spend well above the workspace's usual pace: new compute
1011/// waits until an owner says to keep going.
1012#[derive(Clone, Debug, Serialize, Deserialize)]
1013#[serde(rename_all = "camelCase")]
1014pub struct Spike {
1015 pub id: String,
1016 /// `open` (waiting for an owner), `continued` (an owner said keep
1017 /// going) or `stopped` (an owner said stop).
1018 pub status: String,
1019 /// The hour's spend when it was found, and the usual hour's.
1020 pub hour_micros: i64,
1021 pub average_micros: i64,
1022 pub detected_at: String,
1023 #[serde(default)]
1024 pub decided_by: Option<String>,
1025 #[serde(default)]
1026 pub decided_at: Option<String>,
1027 /// While continued: until when, unless spend doubles again first.
1028 #[serde(default)]
1029 pub until: Option<String>,
1030}
1031
1032/// `reserve`: holds an estimate of a start's cost before the work starts.
1033/// Returns `Outcome<Reservation>`, or a failure whose code says why not:
1034///
1035/// - `paused`: a spend spike waiting for an owner, or a hold.
1036/// - `limit`: the spend limit or g1t's ceiling would be passed.
1037/// - `not_paid`: no plan, and nothing else pays for this kind of work (or
1038/// no card check yet).
1039/// - `trial_used`: the one-time trial is spent.
1040/// - `oss_pool_empty`: the open-source pool, or the repository's share of
1041/// it, is spent this month.
1042///
1043/// The message says exactly what to do, with the page to do it on (such as
1044/// `/acme/-/billing`).
1045#[derive(Debug, Serialize, Deserialize)]
1046#[serde(rename_all = "camelCase")]
1047pub struct ReserveArgs {
1048 pub workspace: String,
1049 pub repo: RepoPath,
1050 /// Whether the repository is public: the open-source pool pays only for
1051 /// public repositories' checks, workflows and merge queue.
1052 pub public: bool,
1053 pub kind: ComputeKind,
1054 /// The most the work is expected to cost g1t, before the margin, in
1055 /// millionths of a dollar (billing adds the margin, as it does to every
1056 /// charge). For an agent, its model's average plus its sandbox for its
1057 /// whole time cap.
1058 #[serde(alias = "estimate_micros")]
1059 pub estimate_micros: i64,
1060}
1061
1062#[derive(Clone, Debug, Serialize, Deserialize)]
1063#[serde(rename_all = "camelCase")]
1064pub struct Reservation {
1065 pub id: String,
1066 pub paid_by: PaidBy,
1067 /// What is held, at cost; less than the estimate when a free
1068 /// workspace's last bit of trial credit is all there is.
1069 #[serde(default)]
1070 pub held_micros: i64,
1071 /// RFC 3339: when the hold lapses if never settled.
1072 #[serde(default)]
1073 pub expires_at: String,
1074}
1075
1076/// `settle`: releases a reservation's hold with what the work cost. The
1077/// charge goes on the ledger the usual way. Safe to repeat. Returns
1078/// `Outcome<bool>`: false if it was settled or had lapsed before.
1079#[derive(Debug, Serialize, Deserialize)]
1080#[serde(rename_all = "camelCase")]
1081pub struct SettleArgs {
1082 #[serde(alias = "reservation_id")]
1083 pub reservation_id: String,
1084 /// What the work cost g1t, before the margin.
1085 #[serde(alias = "actual_micros")]
1086 pub actual_micros: i64,
1087}
1088
1089// --- Card checks, the plan, prepayment -------------------------------------
1090
1091/// `card_check`: starts Stripe's page to save and verify a card: a setup
1092/// with 3-D Secure where the card supports it, which the card's bank sees
1093/// as a $0 or $1 authorization that is never charged. The trial and the
1094/// open-source pool need it, and it is the card the plan uses. Owners only.
1095/// Returns `Outcome<Checkout>`; the page's id comes back to `return_url` as
1096/// `session`, for `confirm_card_check`.
1097#[derive(Debug, Serialize, Deserialize)]
1098#[serde(rename_all = "camelCase")]
1099pub struct CardCheckArgs {
1100 pub actor: User,
1101 pub workspace: String,
1102 #[serde(alias = "return_url")]
1103 pub return_url: String,
1104}
1105
1106/// `confirm_card_check`: records the check once Stripe says the card was
1107/// verified, and grants the trial if the month's pool has room and the card
1108/// has not had one before. Safe to repeat. Returns `Outcome<Entitlements>`.
1109#[derive(Debug, Serialize, Deserialize)]
1110pub struct ConfirmCardCheckArgs {
1111 pub workspace: String,
1112 pub viewer: Viewer,
1113 pub session: String,
1114}
1115
1116// --- Limits: raising them, and spikes ---------------------------------------
1117
1118/// A request to g1t: a higher limit, or help with usage that went past
1119/// what was meant.
1120#[derive(Clone, Debug, Serialize, Deserialize)]
1121#[serde(rename_all = "camelCase")]
1122pub struct LimitRequest {
1123 pub id: String,
1124 pub workspace: String,
1125 /// `limit` (raise my limit) or `overage` (spent more than meant to).
1126 pub kind: String,
1127 /// The limit asked for; for an overage, what they think went wrong.
1128 pub amount_micros: i64,
1129 pub reason: String,
1130 pub expected_monthly_micros: i64,
1131 /// `open`, `approved` or `declined`.
1132 pub status: String,
1133 /// What was approved, which may differ from what was asked.
1134 #[serde(default)]
1135 pub decided_micros: Option<i64>,
1136 #[serde(default)]
1137 pub decided_by: Option<String>,
1138 /// The answer, as the owner sees it.
1139 #[serde(default)]
1140 pub answer: Option<String>,
1141 pub created_by: String,
1142 pub created_at: String,
1143 #[serde(default)]
1144 pub decided_at: Option<String>,
1145}
1146
1147/// `request_limit`: an owner asks g1t for more, or for help with usage past
1148/// what they meant. Answered within one business day, in the app and by
1149/// email. Owners only. Returns `Outcome<LimitRequest>`.
1150#[derive(Debug, Serialize, Deserialize)]
1151#[serde(rename_all = "camelCase")]
1152pub struct RequestLimitArgs {
1153 pub actor: User,
1154 pub workspace: String,
1155 /// `limit` or `overage`.
1156 pub kind: String,
1157 #[serde(alias = "amount_micros")]
1158 pub amount_micros: i64,
1159 pub reason: String,
1160 #[serde(default, alias = "expected_monthly_micros")]
1161 pub expected_monthly_micros: i64,
1162}
1163
1164/// `limit_requests`: a workspace's requests, newest first. Members only.
1165/// Returns `Outcome<Vec<LimitRequest>>`.
1166#[derive(Debug, Serialize, Deserialize)]
1167pub struct LimitRequestsArgs {
1168 pub workspace: String,
1169 pub viewer: Viewer,
1170}
1171
1172/// `confirm_spike`: an owner's answer to a spend spike. Keep going lifts the
1173/// pause for 24 hours, or until the hour's spend doubles again; stop keeps
1174/// new compute paused until an owner says to keep going. Owners only.
1175/// Returns `Outcome<Entitlements>`.
1176#[derive(Debug, Serialize, Deserialize)]
1177#[serde(rename_all = "camelCase")]
1178pub struct ConfirmSpikeArgs {
1179 pub actor: User,
1180 pub workspace: String,
1181 #[serde(alias = "keep_going")]
1182 pub keep_going: bool,
1183}
1184
1185/// `set_caps`: the owners' own caps on agents: one run's spend ($0.10 to
1186/// $100) and what the agents on one issue may spend in all ($1 to $1,000).
1187/// None goes back to the default ($2 and $10). A cap g1t staff set for the
1188/// account wins over both. Owners only. Returns `Outcome<Entitlements>`.
1189#[derive(Debug, Serialize, Deserialize)]
1190#[serde(rename_all = "camelCase")]
1191pub struct SetCapsArgs {
1192 pub actor: User,
1193 pub workspace: String,
1194 #[serde(default, alias = "run_cap_micros")]
1195 pub run_cap_micros: Option<i64>,
1196 #[serde(default, alias = "issue_cap_micros")]
1197 pub issue_cap_micros: Option<i64>,
1198}
1199
1200/// What staff see beside a request: the workspace's history with g1t.
1201#[derive(Clone, Debug, Default, Serialize, Deserialize)]
1202#[serde(rename_all = "camelCase")]
1203pub struct WorkspaceHistory {
1204 pub plan: Option<PlanKind>,
1205 /// The last six months, oldest first.
1206 pub months: Vec<MonthFigures>,
1207 /// Live payments that have cleared, and how many.
1208 pub paid_cleared_micros: i64,
1209 pub payments: u32,
1210 pub disputes: u32,
1211 pub declines: u32,
1212 /// The first time the workspace appears in billing, RFC 3339.
1213 pub first_seen: Option<String>,
1214 pub ceiling_micros: Option<i64>,
1215 pub max_ceiling_micros: Option<i64>,
1216 pub spend_limit_micros: Option<i64>,
1217 /// Recent velocity: the last hour, the usual hour over the last week,
1218 /// and the last 24 hours, at price.
1219 pub last_hour_micros: i64,
1220 pub average_hour_micros: i64,
1221 pub last_day_micros: i64,
1222}
1223
1224#[derive(Clone, Debug, Serialize, Deserialize)]
1225#[serde(rename_all = "camelCase")]
1226pub struct LimitRequestReview {
1227 pub request: LimitRequest,
1228 pub history: WorkspaceHistory,
1229}
1230
1231/// `admin_limit_requests`: requests for staff, oldest open first. Returns
1232/// `Vec<LimitRequestReview>`.
1233#[derive(Debug, Default, Serialize, Deserialize)]
1234pub struct AdminLimitRequestsArgs {
1235 /// `open` (the default), `approved`, `declined` or `all`.
1236 #[serde(default)]
1237 pub status: Option<String>,
1238}
1239
1240/// `admin_decide_limit_request`: approve (at the amount asked, or
1241/// `amount_micros`) or decline. The owner is told in the app and by email.
1242/// Recorded with who and why. Returns `Outcome<LimitRequest>`.
1243#[derive(Debug, Serialize, Deserialize)]
1244pub struct AdminDecideLimitRequestArgs {
1245 pub id: String,
1246 /// `approve` or `decline`.
1247 pub decision: String,
1248 #[serde(default)]
1249 pub amount_micros: Option<i64>,
1250 /// What the owner is told, beside the decision.
1251 #[serde(default)]
1252 pub note: String,
1253 pub by: String,
1254}
1255
1256/// `admin_record_payment`: money that reached g1t outside the card pages,
1257/// such as a bank transfer, entered as a payment (it raises the limit like
1258/// one). Recorded with who and the transfer's reference. Returns
1259/// `Outcome<LedgerEntry>`.
1260#[derive(Debug, Serialize, Deserialize)]
1261pub struct AdminRecordPaymentArgs {
1262 pub workspace: String,
1263 pub amount_micros: i64,
1264 /// The bank's reference for the transfer, or Stripe's payment id.
1265 pub reference: String,
1266 pub note: String,
1267 pub by: String,
1268}
1269
1270// --- Overages and goodwill (sudo) --------------------------------------------
1271
1272/// What a one-time goodwill credit would come to: g1t's margin on the
1273/// overage, always, plus as much of its underlying cost as the cap allows.
1274#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
1275#[serde(rename_all = "camelCase")]
1276pub struct Goodwill {
1277 /// This month's charges above the workspace's typical month.
1278 pub overage_micros: i64,
1279 /// The part of the overage that is g1t's margin.
1280 pub margin_micros: i64,
1281 /// The part that is what g1t paid its providers.
1282 pub cost_micros: i64,
1283 /// The one-click credit: the margin plus the cost up to the cap.
1284 pub credit_micros: i64,
1285 /// Of the credit, the real cost g1t absorbs.
1286 pub absorbed_micros: i64,
1287}
1288
1289/// A workspace whose month went well past its usual, or hit a spike.
1290#[derive(Clone, Debug, Serialize, Deserialize)]
1291#[serde(rename_all = "camelCase")]
1292pub struct Overage {
1293 pub workspace: String,
1294 pub plan: PlanKind,
1295 /// The median of its last three months' charges.
1296 pub typical_month_micros: i64,
1297 pub this_month_micros: i64,
1298 /// What this month cost g1t, and what g1t keeps of it.
1299 pub cost_micros: i64,
1300 pub margin_micros: i64,
1301 /// A spike this month, if there was one.
1302 pub spike: Option<Spike>,
1303 /// The runs that cost the most this month.
1304 pub top_entries: Vec<LedgerEntry>,
1305 pub goodwill: Goodwill,
1306 /// False when a goodwill credit was given in the last 12 months.
1307 pub goodwill_available: bool,
1308 pub last_goodwill_at: Option<String>,
1309 /// An open overage request from the owner, if there is one.
1310 pub request: Option<LimitRequest>,
1311}
1312
1313/// `admin_overages`: the Overages queue. Returns `Vec<Overage>`.
1314#[derive(Debug, Default, Serialize, Deserialize)]
1315pub struct AdminOveragesArgs {}
1316
1317/// `admin_goodwill`: credits a workspace for accidental usage. With no
1318/// amount, the one-click credit (`Goodwill::credit_micros`), once per
1319/// workspace in 12 months. A larger amount, or a second within 12 months,
1320/// needs a typed reason. It shows on the statement as "Credit from g1t:
1321/// accidental usage on <date>". Returns `Outcome<LedgerEntry>`.
1322#[derive(Debug, Serialize, Deserialize)]
1323pub struct AdminGoodwillArgs {
1324 pub workspace: String,
1325 #[serde(default)]
1326 pub amount_micros: Option<i64>,
1327 /// Why, typed by staff; needed past the one-click credit.
1328 #[serde(default)]
1329 pub reason: String,
1330 /// The day the accidental usage happened, `YYYY-MM-DD`; today if absent.
1331 #[serde(default)]
1332 pub day: Option<String>,
1333 pub by: String,
1334}
1335
1336/// One workspace's recent pace, for sudo's velocity view.
1337#[derive(Clone, Debug, Serialize, Deserialize)]
1338#[serde(rename_all = "camelCase")]
1339pub struct Velocity {
1340 pub workspace: String,
1341 pub plan: PlanKind,
1342 pub last_hour_micros: i64,
1343 pub average_hour_micros: i64,
1344 pub last_day_micros: i64,
1345 pub this_month_micros: i64,
1346 /// The last hour over the usual hour; 0 with no history.
1347 pub ratio: f64,
1348 pub spike: Option<Spike>,
1349 pub first_seen: Option<String>,
1350}
1351
1352/// `admin_velocity`: workspaces spending in the last day, fastest first.
1353/// Returns `Vec<Velocity>`.
1354#[derive(Debug, Default, Serialize, Deserialize)]
1355pub struct AdminVelocityArgs {}
1356
Billing accounts, terms and enterprises; g1t is no longer free1357#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
1358#[serde(rename_all = "snake_case")]
1359pub enum AccountKind {
1360 Workspace,
1361 Enterprise,
1362}
1363
1364/// How an account is charged. Standard unless g1t set otherwise in sudo.
1365#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1366#[serde(rename_all = "camelCase")]
1367pub struct Terms {
1368 pub kind: TermsKind,
1369 /// Off every usage charge, in percent. Custom terms only.
1370 #[serde(default)]
1371 pub discount_percent: u32,
1372 /// A ceiling on unpaid usage that replaces the one trust would give.
1373 #[serde(default)]
1374 pub ceiling_micros: Option<i64>,
1375 /// Why, for whoever looks next.
1376 #[serde(default)]
1377 pub note: String,
1378 /// When the terms end and the account goes back to standard.
1379 #[serde(default)]
1380 pub until: Option<String>,
1381 #[serde(default)]
1382 pub set_by: Option<String>,
1383 #[serde(default)]
1384 pub set_at: Option<String>,
1385}
1386
1387impl Terms {
1388 pub fn standard() -> Self {
1389 Terms {
1390 kind: TermsKind::Standard,
1391 discount_percent: 0,
1392 ceiling_micros: None,
1393 note: String::new(),
1394 until: None,
1395 set_by: None,
1396 set_at: None,
1397 }
1398 }
1399
1400 /// What a charge becomes under these terms.
1401 pub fn apply(&self, charge_micros: i64) -> i64 {
1402 match self.kind {
1403 TermsKind::Comped => 0,
1404 TermsKind::Custom => charge_micros * i64::from(100 - self.discount_percent.min(100)) / 100,
1405 TermsKind::Standard => charge_micros,
1406 }
1407 }
1408}
1409
1410#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
1411#[serde(rename_all = "snake_case")]
1412pub enum TermsKind {
1413 /// Prices as published, limits by trust.
1414 Standard,
1415 /// Nothing charged; usage still recorded with its cost. Paid features
1416 /// are on without a plan. For g1t's own workspaces, partners, and the
1417 /// like.
1418 Comped,
1419 /// A discount, a ceiling, or both.
1420 Custom,
1421}
1422
Stripe webhooks, enterprise invoices, and sudo for both1423/// `stripe_webhook`: an event from Stripe, as the API received it: the raw
1424/// body and its `Stripe-Signature` header. Billing checks the signature
1425/// against the secret of the endpoint it registered, and handles each
1426/// event once. Returns `Outcome<bool>`: false for one already handled.
1427#[derive(Debug, Serialize, Deserialize)]
1428pub struct StripeWebhookArgs {
1429 pub payload: String,
1430 pub signature: String,
1431}
1432
1433/// `admin_stripe`: where billing stands with Stripe. Staff only. Returns
1434/// `StripeStatus`. With `setup: true`, registers (or replaces) the webhook
1435/// endpoint for the current mode first.
1436#[derive(Debug, Default, Serialize, Deserialize)]
1437pub struct AdminStripeArgs {
1438 #[serde(default)]
1439 pub setup: bool,
1440 #[serde(default)]
1441 pub by: Option<String>,
1442}
1443
1444#[derive(Clone, Debug, Serialize, Deserialize)]
1445#[serde(rename_all = "camelCase")]
1446pub struct StripeStatus {
1447 /// `test` or `live`, from the key; `off` without one.
1448 pub mode: String,
1449 pub webhook: Option<StripeWebhook>,
1450 /// The latest events handled, newest first.
1451 pub recent_events: Vec<StripeEventSummary>,
1452 /// What went wrong setting up, if it did.
1453 pub error: Option<String>,
1454}
1455
1456#[derive(Clone, Debug, Serialize, Deserialize)]
1457#[serde(rename_all = "camelCase")]
1458pub struct StripeWebhook {
1459 pub url: String,
1460 pub endpoint_id: String,
1461 pub events: Vec<String>,
1462 pub created_by: String,
1463 pub created_at: String,
1464}
1465
1466#[derive(Clone, Debug, Serialize, Deserialize)]
1467#[serde(rename_all = "camelCase")]
1468pub struct StripeEventSummary {
1469 pub id: String,
1470 pub kind: String,
1471 pub outcome: String,
1472 pub received_at: String,
1473}
1474
1475/// `admin_enterprise_billing`: where an enterprise's invoices go. Creates
1476/// or updates its Stripe customer. Returns `Outcome<BillingAccount>`.
1477#[derive(Debug, Serialize, Deserialize)]
1478pub struct AdminEnterpriseBillingArgs {
1479 pub id: String,
1480 pub email: String,
1481 pub by: String,
1482}
1483
1484/// `admin_invoice_enterprise`: sends an enterprise its invoice now, for
1485/// what its workspaces owe, rather than waiting for the month to close.
1486/// Returns `Outcome<EnterpriseInvoice>`.
1487#[derive(Debug, Serialize, Deserialize)]
1488pub struct AdminInvoiceEnterpriseArgs {
1489 pub id: String,
1490 pub by: String,
1491}
1492
1493/// An enterprise's invoice: one line per workspace, paid on Stripe.
1494#[derive(Clone, Debug, Serialize, Deserialize)]
1495#[serde(rename_all = "camelCase")]
1496pub struct EnterpriseInvoice {
1497 pub invoice_id: String,
1498 /// Stripe's page for it, where it is paid.
1499 pub hosted_url: Option<String>,
1500 pub amount_micros: i64,
1501 /// `open`, `paid`, `overdue` or `void`.
1502 pub status: String,
1503 pub period: String,
1504 pub lines: Vec<InvoiceLine>,
1505 pub created_at: String,
1506}
1507
1508#[derive(Clone, Debug, Serialize, Deserialize)]
1509#[serde(rename_all = "camelCase")]
1510pub struct InvoiceLine {
1511 pub workspace: String,
1512 pub amount_micros: i64,
1513}
1514
Two limits, real invoices, trust that grows by itself, sales signals1515/// A workspace's invoice from g1t: one per month, and one each time it is
1516/// charged near its limit. Itemised, charged to the card on file, and kept
1517/// in Stripe's billing page with its PDF.
1518#[derive(Clone, Debug, Serialize, Deserialize)]
1519#[serde(rename_all = "camelCase")]
1520pub struct WorkspaceInvoice {
1521 pub invoice_id: String,
1522 pub workspace: String,
1523 /// `month` (2026-10) or `threshold`.
1524 pub reason: String,
1525 pub period: String,
1526 pub amount_micros: i64,
1527 /// `paid`, `open`, `failed` or `void`.
1528 pub status: String,
1529 pub hosted_url: Option<String>,
1530 pub pdf_url: Option<String>,
1531 pub lines: Vec<InvoiceItem>,
1532 pub created_at: String,
1533}
1534
1535#[derive(Clone, Debug, Serialize, Deserialize)]
1536#[serde(rename_all = "camelCase")]
1537pub struct InvoiceItem {
1538 pub description: String,
1539 pub amount_micros: i64,
1540}
1541
1542/// `invoices`: a workspace's invoices from g1t, newest first. Members
1543/// only. Returns `Outcome<Vec<WorkspaceInvoice>>`.
1544#[derive(Debug, Serialize, Deserialize)]
1545pub struct InvoicesArgs {
1546 pub workspace: String,
1547 pub viewer: Viewer,
1548}
1549
1550/// `admin_workspace_invoices`: the same, for staff. Returns
1551/// `Vec<WorkspaceInvoice>`.
1552#[derive(Debug, Serialize, Deserialize)]
1553pub struct AdminWorkspaceInvoicesArgs {
1554 pub workspace: String,
1555}
1556
The statement is a month at a time, a line per kind of charge1557/// `statement`: a month of a workspace's ledger, grouped by day (or by
1558/// project) with a line per kind of charge. Members only. Returns
1559/// `Outcome<Statement>`.
1560#[derive(Debug, Serialize, Deserialize)]
1561pub struct StatementArgs {
1562 pub workspace: String,
1563 pub viewer: Viewer,
1564 /// YYYY-MM; this month when absent.
1565 #[serde(default)]
1566 pub month: Option<String>,
1567 /// `day` (the default) or `project`.
1568 #[serde(default)]
1569 pub group: Option<String>,
1570}
1571
1572#[derive(Clone, Debug, Serialize, Deserialize)]
1573#[serde(rename_all = "camelCase")]
1574pub struct Statement {
1575 pub month: String,
1576 /// Months with any entries, newest first.
1577 pub months: Vec<String>,
1578 pub groups: Vec<StatementGroup>,
1579 pub totals: StatementTotals,
1580}
1581
1582#[derive(Clone, Debug, Serialize, Deserialize)]
1583#[serde(rename_all = "camelCase")]
1584pub struct StatementGroup {
1585 /// The day (YYYY-MM-DD) or the project (`owner/name`, or empty).
1586 pub key: String,
1587 pub label: String,
1588 pub lines: Vec<StatementLine>,
1589 /// What the group's charges come to.
1590 pub charged_micros: i64,
1591}
1592
1593#[derive(Clone, Debug, Serialize, Deserialize)]
1594#[serde(rename_all = "camelCase")]
1595pub struct StatementLine {
1596 /// Agent runs, Sandbox time, Deployments, Payments, Credits from g1t,
Prices are what g1t pays plus 20%, from the first second1597 /// Refunds, and, for older entries, Runs on your own model provider.
The statement is a month at a time, a line per kind of charge1598 pub kind: String,
1599 pub count: u32,
1600 /// Charges positive; money in (payments, credits) negative.
1601 pub charged_micros: i64,
1602 pub cost_micros: i64,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put1603 /// 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 look1604 /// by the plan's included usage, the trial credit, g1t's open-source
1605 /// 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 put1606 #[serde(default)]
1607 pub covered_micros: i64,
The statement is a month at a time, a line per kind of charge1608}
1609
1610#[derive(Clone, Debug, Serialize, Deserialize)]
1611#[serde(rename_all = "camelCase")]
1612pub struct StatementTotals {
1613 pub charged_micros: i64,
1614 pub paid_micros: i64,
1615 pub cost_micros: i64,
1616 pub entries: u32,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put1617 /// What paid for usage before it was charged, one line per source,
1618 /// such as "Paid by g1t's open-source pool".
1619 #[serde(default)]
1620 pub covered: Vec<Covered>,
1621 /// Owed when the month closed but under the minimum charge, so it
1622 /// carries over to the next invoice. Zero when nothing carried.
1623 #[serde(default)]
1624 pub carried_micros: i64,
1625}
1626
1627/// One source that paid for usage before it was charged.
1628#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1629#[serde(rename_all = "camelCase")]
1630pub struct Covered {
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1631 /// `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 put1632 pub source: String,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1633 /// "Paid by your plan's included usage", "Paid by your trial credit",
1634 /// "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 put1635 pub label: String,
1636 pub micros: i64,
The statement is a month at a time, a line per kind of charge1637}
1638
1639/// `statement_entries`: one statement line's entries, newest first, 50 at
1640/// a time (`before` = the last id seen). Returns `Outcome<Vec<LedgerEntry>>`.
1641#[derive(Debug, Serialize, Deserialize)]
1642pub struct StatementEntriesArgs {
1643 pub workspace: String,
1644 pub viewer: Viewer,
1645 pub month: String,
1646 pub kind: String,
1647 #[serde(default)]
1648 pub day: Option<String>,
1649 #[serde(default)]
1650 pub project: Option<String>,
1651 #[serde(default)]
1652 pub before: Option<String>,
1653}
1654
Two limits, real invoices, trust that grows by itself, sales signals1655// --- Sales (sudo.g1t.sh) ------------------------------------------------------
1656//
1657// What staff need to know to reach out: who is growing, who is close to
1658// their limit, who was declined, who has become a steady customer. And what
1659// was done about it: a stage, an owner on g1t's side, a next step, notes.
1660
1661/// Why a workspace is worth a look.
1662#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
1663#[serde(rename_all = "snake_case")]
1664pub enum SignalKind {
1665 /// At its limit, or its own spend limit: work is stopped.
1666 AtLimit,
1667 /// Past 80% of what is available to it: about to need more.
1668 NearCeiling,
1669 /// Its card was declined or a payment disputed.
1670 Declined,
1671 /// This month is well ahead of last month.
1672 Growing,
1673 /// Became Established: the ceiling now follows its spend.
1674 Established,
1675 /// Paid g1t for the first time.
1676 FirstPayment,
1677 /// Spending enough that custom terms or an enterprise may suit it.
1678 HighSpend,
1679}
1680
1681#[derive(Clone, Debug, Serialize, Deserialize)]
1682#[serde(rename_all = "camelCase")]
1683pub struct Signal {
1684 pub workspace: String,
1685 pub kind: SignalKind,
1686 /// One sentence, with the figures.
1687 pub detail: String,
1688 /// The figure that matters, such as this month's spend.
1689 pub value_micros: i64,
1690 /// Its sales stage, if staff gave it one.
1691 pub stage: Option<String>,
1692 pub owner: Option<String>,
Billing lists every invoice and every staff change; signals carry follow-ups1693 #[serde(default)]
1694 pub next_step: Option<String>,
1695 /// When the next step is due, `YYYY-MM-DD`.
1696 #[serde(default)]
1697 pub next_at: Option<String>,
1698}
1699
1700/// `admin_invoices`: every invoice g1t has sent, workspaces' and
1701/// enterprises', newest first. Returns `Vec<InvoiceSummary>`.
1702#[derive(Debug, Default, Serialize, Deserialize)]
1703pub struct AdminInvoicesArgs {
1704 /// `paid`, `open`, `failed`, `overdue` or `void`.
1705 #[serde(default)]
1706 pub status: Option<String>,
1707 /// YYYY-MM, by when it was sent.
1708 #[serde(default)]
1709 pub month: Option<String>,
1710}
1711
1712#[derive(Clone, Debug, Serialize, Deserialize)]
1713#[serde(rename_all = "camelCase")]
1714pub struct InvoiceSummary {
1715 pub invoice_id: String,
1716 /// `workspace` or `enterprise`.
1717 pub kind: String,
1718 /// The workspace's slug, or the enterprise's account id.
1719 pub account: String,
1720 /// What to call it: the workspace, or the enterprise's name.
1721 pub name: String,
1722 pub reason: String,
1723 pub period: String,
1724 pub amount_micros: i64,
1725 pub status: String,
1726 pub hosted_url: Option<String>,
1727 pub created_at: String,
1728 pub paid_at: Option<String>,
1729}
1730
1731/// `admin_audit`: every change made in sudo, and by Stripe, newest first.
1732/// Returns `Vec<AdminAction>`.
1733#[derive(Debug, Default, Serialize, Deserialize)]
1734pub struct AdminAuditArgs {
1735 #[serde(default)]
1736 pub by: Option<String>,
1737 #[serde(default)]
1738 pub action: Option<String>,
1739 /// Only those before this time, for paging.
1740 #[serde(default)]
1741 pub before: Option<String>,
Two limits, real invoices, trust that grows by itself, sales signals1742}
1743
1744/// `admin_signals`: every workspace worth reaching out to, most urgent
1745/// first. Returns `Vec<Signal>`.
1746#[derive(Debug, Default, Serialize, Deserialize)]
1747pub struct AdminSignalsArgs {}
1748
1749/// What staff are doing about a workspace.
1750#[derive(Clone, Debug, Serialize, Deserialize)]
1751#[serde(rename_all = "camelCase")]
1752pub struct SalesRecord {
1753 pub workspace: String,
1754 /// `none`, `lead`, `contacted`, `negotiating`, `won`, `lost` or `churn_risk`.
1755 pub stage: String,
1756 /// The staff member looking after it.
1757 pub owner: Option<String>,
1758 pub next_step: Option<String>,
1759 /// RFC 3339 date.
1760 pub next_at: Option<String>,
1761 pub notes: Vec<SalesNote>,
1762 pub updated_at: Option<String>,
1763}
1764
1765#[derive(Clone, Debug, Serialize, Deserialize)]
1766#[serde(rename_all = "camelCase")]
1767pub struct SalesNote {
1768 pub id: String,
1769 pub text: String,
1770 pub by: String,
1771 pub created_at: String,
1772}
1773
1774/// `admin_sales`: a workspace's sales record. Returns `SalesRecord`.
1775#[derive(Debug, Serialize, Deserialize)]
1776pub struct AdminSalesArgs {
1777 pub workspace: String,
1778}
1779
1780/// `admin_set_sales`: its stage, owner and next step. Returns `Outcome<SalesRecord>`.
1781#[derive(Debug, Serialize, Deserialize)]
1782pub struct AdminSetSalesArgs {
1783 pub workspace: String,
1784 pub stage: String,
1785 #[serde(default)]
1786 pub owner: Option<String>,
1787 #[serde(default)]
1788 pub next_step: Option<String>,
1789 #[serde(default)]
1790 pub next_at: Option<String>,
1791 pub by: String,
1792}
1793
1794/// `admin_add_note`. Returns `Outcome<SalesRecord>`.
1795#[derive(Debug, Serialize, Deserialize)]
1796pub struct AdminAddNoteArgs {
1797 pub workspace: String,
1798 pub text: String,
1799 pub by: String,
1800}
1801
1802/// `admin_overview`: the business at a glance. Returns `Overview`.
1803#[derive(Debug, Default, Serialize, Deserialize)]
1804pub struct AdminOverviewArgs {}
1805
1806#[derive(Clone, Debug, Serialize, Deserialize)]
1807#[serde(rename_all = "camelCase")]
1808pub struct Overview {
1809 /// YYYY-MM.
1810 pub month: String,
1811 /// The last six months, oldest first, all workspaces together.
1812 pub months: Vec<MonthFigures>,
1813 /// This month by kind of usage: models, sandbox, deployments, plans.
1814 pub by_kind: Vec<KindFigures>,
1815 pub paying_workspaces: u32,
1816 pub stopped: u32,
1817 pub near_ceiling: u32,
1818 pub declined: u32,
1819 /// Sent and not yet paid, workspaces and enterprises.
1820 pub open_invoices_micros: i64,
1821 /// Follow-ups due today or earlier.
1822 pub follow_ups_due: u32,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put1823 /// The capped budgets g1t pays from, this month.
1824 #[serde(default)]
1825 pub pools: Option<Pools>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1826 /// This month's revenue: usage charged plus the plan's price paid.
1827 #[serde(default)]
1828 pub revenue_micros: i64,
1829 /// Workspaces on the paid plan now, and what their price comes to a
1830 /// month.
1831 #[serde(default)]
1832 pub active_plans: u32,
1833 #[serde(default)]
1834 pub plan_mrr_micros: i64,
1835 /// What g1t gave this month, by source, apart from its margin.
1836 #[serde(default)]
1837 pub given: Vec<GivenFigures>,
1838 /// g1t's own and Flagon's workspaces this month: what their use cost,
1839 /// and why they are not charged.
1840 #[serde(default)]
1841 pub internal: Vec<InternalUse>,
1842 /// Open limit requests, and workspaces in the Overages queue.
1843 #[serde(default)]
1844 pub open_requests: u32,
1845 #[serde(default)]
1846 pub overages: u32,
1847 /// Spend spikes waiting for an owner.
1848 #[serde(default)]
1849 pub open_spikes: u32,
Two limits, real invoices, trust that grows by itself, sales signals1850}
1851
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1852/// What g1t gave this month from one source.
1853#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
1854#[serde(rename_all = "camelCase")]
1855pub struct GivenFigures {
1856 /// `internal`, `trial`, `oss_pool`, `goodwill` or `covered`.
1857 pub source: String,
1858 pub label: String,
1859 /// At price, and what it cost g1t.
1860 pub micros: i64,
1861 pub cost_micros: i64,
1862}
1863
1864/// One internal workspace's use this month.
1865#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
1866#[serde(rename_all = "camelCase")]
1867pub struct InternalUse {
1868 pub workspace: String,
1869 /// Why it is not charged: its terms' note.
1870 pub reason: String,
1871 pub cost_micros: i64,
1872 pub entries: u32,
1873}
1874
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put1875/// g1t's capped budgets for free usage, this calendar month (UTC).
1876#[derive(Clone, Debug, Default, Serialize, Deserialize)]
1877#[serde(rename_all = "camelCase")]
1878pub struct Pools {
1879 /// YYYY-MM.
1880 pub month: String,
1881 /// Trial grants made this month, against the month's pool.
1882 pub trial_granted_micros: i64,
1883 pub trial_pool_micros: i64,
1884 pub trial_grants: u32,
1885 /// What the open-source pool paid this month, against its cap.
1886 pub oss_used_micros: i64,
1887 pub oss_pool_micros: i64,
1888 /// Each public repository's monthly cap on the pool.
1889 pub oss_repo_micros: i64,
1890}
1891
Two limits, real invoices, trust that grows by itself, sales signals1892#[derive(Clone, Debug, Serialize, Deserialize)]
1893#[serde(rename_all = "camelCase")]
1894pub struct KindFigures {
1895 pub kind: String,
1896 pub charged_micros: i64,
1897 pub cost_micros: i64,
1898}
1899
Billing accounts, terms and enterprises; g1t is no longer free1900// --- Staff (sudo.g1t.sh) ------------------------------------------------------
1901//
1902// Called only by the sudo app, which only g1t staff can reach (behind
1903// Cloudflare Access). Each change names who made it, and is kept in the
1904// audit log.
1905
1906/// `admin_accounts`: every billing account, with where each stands this
1907/// month. Returns `Vec<AccountSummary>`.
1908#[derive(Debug, Default, Serialize, Deserialize)]
1909pub struct AdminAccountsArgs {
1910 #[serde(default)]
1911 pub query: Option<String>,
Stripe webhooks, enterprise invoices, and sudo for both1912 /// Exactly these workspaces' accounts, such as one page of sudo's
1913 /// list; every account with activity when absent.
1914 #[serde(default)]
1915 pub workspaces: Option<Vec<String>>,
Billing accounts, terms and enterprises; g1t is no longer free1916}
1917
1918#[derive(Clone, Debug, Serialize, Deserialize)]
1919#[serde(rename_all = "camelCase")]
1920pub struct AccountSummary {
1921 pub account: BillingAccount,
1922 pub limit: Limit,
1923 /// Charged this month, after terms.
1924 pub charged_micros: i64,
1925 /// What this month's usage cost g1t.
1926 pub cost_micros: i64,
1927 /// Paid, ever.
1928 pub paid_micros: i64,
Billing on Stripe's pages, month-end charges, warnings; sudo by workspace1929 /// The same figures for each of the account's workspaces that has
1930 /// any, so staff can see what one member of an enterprise used.
1931 #[serde(default)]
1932 pub by_workspace: Vec<WorkspaceFigures>,
Two limits, real invoices, trust that grows by itself, sales signals1933 /// The last six months, oldest first, for trends.
1934 #[serde(default)]
1935 pub months: Vec<MonthFigures>,
1936}
1937
1938/// One month of an account's billing.
1939#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
1940#[serde(rename_all = "camelCase")]
1941pub struct MonthFigures {
1942 /// YYYY-MM.
1943 pub month: String,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1944 /// Usage charged, after what paid for it first.
Two limits, real invoices, trust that grows by itself, sales signals1945 pub charged_micros: i64,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1946 /// What usage cost g1t: only what g1t paid for, never a workspace's own
1947 /// model provider.
Two limits, real invoices, trust that grows by itself, sales signals1948 pub cost_micros: i64,
1949 pub paid_micros: i64,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1950 /// The plan's monthly price, paid.
1951 #[serde(default)]
1952 pub plans_micros: i64,
1953 /// What g1t gave, at price: internal (comped) use, trials, the
1954 /// open-source pool, goodwill credits and what g1t covered. Not margin.
1955 #[serde(default)]
1956 pub given_micros: i64,
Billing on Stripe's pages, month-end charges, warnings; sudo by workspace1957}
1958
1959/// One workspace's share of an [`AccountSummary`].
1960#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
1961#[serde(rename_all = "camelCase")]
1962pub struct WorkspaceFigures {
1963 pub workspace: String,
1964 pub charged_micros: i64,
1965 pub cost_micros: i64,
1966 pub paid_micros: i64,
Billing accounts, terms and enterprises; g1t is no longer free1967}
1968
1969/// `admin_account`: one account in full. Returns `Outcome<AccountDetail>`.
1970#[derive(Debug, Serialize, Deserialize)]
1971pub struct AdminAccountArgs {
1972 /// An account id, or a workspace slug.
1973 pub id: String,
1974}
1975
1976#[derive(Clone, Debug, Serialize, Deserialize)]
1977#[serde(rename_all = "camelCase")]
1978pub struct AccountDetail {
1979 pub summary: AccountSummary,
1980 /// Each workspace's limit, for an enterprise.
1981 pub workspaces: Vec<Limit>,
1982 pub ledger: Vec<LedgerEntry>,
1983 pub audit: Vec<AdminAction>,
1984}
1985
1986/// `admin_set_terms`. Returns `Outcome<BillingAccount>`.
1987#[derive(Debug, Serialize, Deserialize)]
1988pub struct AdminSetTermsArgs {
1989 pub id: String,
1990 pub terms: Terms,
1991 pub by: String,
1992}
1993
1994/// `admin_create_enterprise`. Returns `Outcome<BillingAccount>`.
1995#[derive(Debug, Serialize, Deserialize)]
1996pub struct AdminCreateEnterpriseArgs {
1997 pub name: String,
1998 pub workspaces: Vec<String>,
1999 pub by: String,
2000}
2001
2002/// `admin_attach`: moves a workspace onto an enterprise account, or back
2003/// onto its own with `account: None`. Returns `Outcome<BillingAccount>`.
2004#[derive(Debug, Serialize, Deserialize)]
2005pub struct AdminAttachArgs {
2006 pub workspace: String,
2007 pub account: Option<String>,
2008 pub by: String,
2009}
2010
2011/// `admin_credit`: money g1t gives a workspace, such as a refund or a
2012/// goodwill credit. Returns `Outcome<LedgerEntry>`.
2013#[derive(Debug, Serialize, Deserialize)]
2014pub struct AdminCreditArgs {
2015 pub workspace: String,
2016 pub amount_micros: i64,
2017 pub note: String,
2018 pub by: String,
2019}
2020
2021/// One change made in sudo.
2022#[derive(Clone, Debug, Serialize, Deserialize)]
2023#[serde(rename_all = "camelCase")]
2024pub struct AdminAction {
2025 pub id: String,
2026 pub account: String,
2027 pub action: String,
2028 pub detail: String,
2029 pub by: String,
2030 pub created_at: String,
2031}
2032
Paid features: a workspace turns on Deployments with a monthly plan2033/// What a feature's plan costs and includes.
2034#[derive(Clone, Debug, Serialize, Deserialize)]
2035#[serde(rename_all = "camelCase")]
2036pub struct Plan {
2037 pub feature: Feature,
2038 pub title: String,
2039 /// Charged every month while the plan is on, in cents.
2040 pub monthly_cents: u32,
2041 /// What the monthly price includes, one line each, for people to read.
2042 pub includes: Vec<String>,
2043 /// How usage past the allowance is charged, for people to read.
2044 pub overage: String,
2045}
2046
2047#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
2048#[serde(rename_all = "snake_case")]
2049pub enum SubscriptionStatus {
2050 /// Paid up; the feature works.
2051 Active,
2052 /// Paid up to the end of the period, and ends then.
2053 Canceling,
2054 /// The last payment failed; the feature is off until it is paid.
2055 PastDue,
2056 /// Ended.
2057 Canceled,
2058}
2059
2060impl SubscriptionStatus {
2061 /// Whether the feature works in this state.
2062 pub fn on(self) -> bool {
2063 matches!(self, SubscriptionStatus::Active | SubscriptionStatus::Canceling)
2064 }
2065}
2066
2067/// A workspace's plan for one feature.
2068#[derive(Clone, Debug, Serialize, Deserialize)]
2069#[serde(rename_all = "camelCase")]
2070pub struct Subscription {
2071 pub feature: Feature,
2072 pub status: SubscriptionStatus,
2073 /// RFC 3339: when the period paid for ends, and the plan renews or
2074 /// ends.
2075 pub period_end: Option<String>,
2076 /// Username of whoever turned it on.
2077 pub started_by: String,
2078 /// RFC 3339.
2079 pub started_at: String,
2080}
2081
2082/// A feature as a workspace sees it: what it costs, and its plan if it has
2083/// one.
2084#[derive(Clone, Debug, Serialize, Deserialize)]
2085#[serde(rename_all = "camelCase")]
2086pub struct FeatureState {
2087 pub plan: Plan,
2088 pub subscription: Option<Subscription>,
2089 /// Whether the feature works for the workspace now.
2090 pub on: bool,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put2091 /// On without a plan: comped terms, or given by g1t. Nothing to pay
2092 /// and nothing to turn off.
2093 #[serde(default)]
2094 pub included: bool,
Paid features: a workspace turns on Deployments with a monthly plan2095}
2096
2097/// `features`: every paid feature and the workspace's plan for each.
2098/// Members only. Returns `Outcome<Vec<FeatureState>>`.
2099#[derive(Debug, Serialize, Deserialize)]
2100pub struct FeaturesArgs {
2101 pub workspace: String,
2102 pub viewer: Viewer,
2103}
2104
2105/// `subscribe`: starts the card page for a feature's monthly plan. Owners
2106/// only. Returns `Outcome<Checkout>`; the page's id comes back to
2107/// `return_url` as `session`, for `confirm_subscription`.
2108#[derive(Debug, Serialize, Deserialize)]
2109#[serde(rename_all = "camelCase")]
2110pub struct SubscribeArgs {
2111 pub actor: User,
2112 pub workspace: String,
2113 pub feature: Feature,
2114 pub return_url: String,
2115}
2116
2117/// `confirm_subscription`: turns the feature on once the processor says
2118/// the plan was paid for. Safe to call any number of times. Returns
2119/// `Outcome<FeatureState>`.
2120#[derive(Debug, Serialize, Deserialize)]
2121pub struct ConfirmSubscriptionArgs {
2122 pub workspace: String,
2123 pub viewer: Viewer,
2124 pub session: String,
2125}
2126
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look2127/// `close_workspace`: settles a workspace that is about to be deleted.
2128/// Owners only. Refused while it has an invoice that failed, while it
2129/// holds prepaid credit, or while it owes money it cannot be charged for
2130/// now; otherwise what it owes is invoiced to its card at once (no
2131/// minimum), its plan is cancelled at Stripe straight away, and its
2132/// account is marked closed, so the month-end close, autopay and limit
2133/// warnings pass it by. Its ledger, invoices and statements stay. With
2134/// `dry_run`, only says whether it could, changing nothing. Returns
2135/// `Outcome<bool>`.
2136#[derive(Debug, Serialize, Deserialize)]
2137#[serde(rename_all = "camelCase")]
2138pub struct CloseWorkspaceArgs {
2139 pub actor: User,
2140 pub workspace: String,
2141 #[serde(default)]
2142 pub dry_run: bool,
2143}
2144
Paid features: a workspace turns on Deployments with a monthly plan2145/// `cancel_subscription` (`resume` false) ends a plan at the end of the
2146/// period paid for; with `resume` true, takes that back. Owners only.
2147/// Returns `Outcome<FeatureState>`.
2148#[derive(Debug, Serialize, Deserialize)]
2149pub struct CancelSubscriptionArgs {
2150 pub actor: User,
2151 pub workspace: String,
2152 pub feature: Feature,
2153 #[serde(default)]
2154 pub resume: bool,
2155}
2156
2157/// `has_feature`: whether a feature works for a workspace now, asked by the
2158/// service that provides it before doing paid work. Returns
2159/// `Outcome<bool>`: a failure, with the reason to show, when it does not.
2160/// True everywhere when no card processor is configured.
2161#[derive(Debug, Serialize, Deserialize)]
2162pub struct HasFeatureArgs {
2163 pub workspace: String,
2164 pub feature: Feature,
2165}
2166
2167/// `charge_feature`: usage of a feature past its plan's allowance, charged
2168/// from the workspace's credit at cost plus the margin, whatever
2169/// `FREE_WHILE_BUILDING` says. Called by the service that provides it.
2170/// Charged once per `reference`. Returns `Outcome<bool>`: false if that
2171/// reference was charged before.
2172#[derive(Debug, Serialize, Deserialize)]
2173#[serde(rename_all = "camelCase")]
2174pub struct ChargeFeatureArgs {
2175 pub workspace: String,
2176 pub feature: Feature,
2177 /// What it cost g1t, in millionths of a dollar, before the margin.
2178 pub cost_micros: i64,
2179 pub description: String,
2180 /// `namespace/name`, when the usage was one repository's.
2181 pub repo: Option<String>,
2182 /// Unique to this charge, e.g. `deployments/acme/2026-10`.
2183 pub reference: String,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put2184 /// For a build: how long it ran. The plan's included build time this
2185 /// month pays for what it can, and only the rest of `cost_micros` is
2186 /// charged.
2187 #[serde(default)]
2188 pub build_seconds: Option<u32>,
Paid features: a workspace turns on Deployments with a monthly plan2189}
2190
Models per workspace: several providers, routed by kind of work2191#[cfg(test)]
2192mod tests {
2193 use super::*;
2194
2195 #[test]
Prices are what g1t pays plus 20%, from the first second2196 fn an_account_carries_no_run_fee() {
2197 let account = Account {
2198 workspace: "acme".into(),
2199 balance_micros: 0,
2200 status: Status { enabled: true, live: false, free: false },
2201 margin_percent: 20,
2202 card: None,
2203 };
2204 let json = serde_json::to_value(account).unwrap();
2205 let mut keys: Vec<&str> = json.as_object().unwrap().keys().map(String::as_str).collect();
2206 keys.sort_unstable();
2207 assert_eq!(keys, ["balanceMicros", "card", "marginPercent", "status", "workspace"]);
2208 }
2209
2210 #[test]
2211 fn a_price_change_says_when_the_markup_moved() {
2212 let change = PriceChange {
2213 meter: "sandbox_second".into(),
2214 old_cost_micros: 21.0,
2215 new_cost_micros: 21.0,
2216 markup_percent: 20,
2217 old_markup_percent: Some(138),
2218 reason: "Sandbox time is now charged at cost plus 20% from the first second".into(),
2219 created_at: "2026-10-05T00:00:00Z".into(),
2220 };
2221 assert_eq!(serde_json::to_value(&change).unwrap()["oldMarkupPercent"], 138);
2222 let cost_only = PriceChange { old_markup_percent: None, ..change };
2223 assert!(serde_json::to_value(&cost_only).unwrap().get("oldMarkupPercent").is_none());
2224 }
2225
2226 #[test]
Paid features: a workspace turns on Deployments with a monthly plan2227 fn features_are_named_as_the_site_sends_them() {
2228 assert_eq!(
2229 serde_json::to_value(Feature::Deployments).unwrap(),
2230 serde_json::json!("deployments")
2231 );
2232 assert_eq!(Feature::parse("deployments"), Some(Feature::Deployments));
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look2233 assert_eq!(serde_json::to_value(Feature::Plan).unwrap(), serde_json::json!("plan"));
2234 assert_eq!(Feature::parse("plan"), Some(Feature::Plan));
2235 // Older readers named the plan Team.
2236 assert_eq!(Feature::parse("team"), Some(Feature::Plan));
2237 assert_eq!(serde_json::from_value::<Feature>(serde_json::json!("team")).unwrap(), Feature::Plan);
2238 assert_eq!(Feature::ALL, [Feature::Plan]);
Paid features: a workspace turns on Deployments with a monthly plan2239 assert!(SubscriptionStatus::Canceling.on());
2240 assert!(!SubscriptionStatus::PastDue.on());
2241 }
2242
2243 #[test]
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look2244 fn a_reservation_is_asked_for_and_answered_in_camel_case() {
2245 let asked: ReserveArgs = serde_json::from_value(serde_json::json!({
2246 "workspace": "acme",
2247 "repo": { "namespace": "acme", "name": "web" },
2248 "public": true,
2249 "kind": "check",
2250 "estimateMicros": 2_000_000,
2251 }))
2252 .unwrap();
2253 assert_eq!(asked.kind, ComputeKind::Check);
2254 assert!(asked.kind.open_source_pool());
2255 assert!(!ComputeKind::Agent.open_source_pool());
2256 // Rust callers that write snake_case are read too.
2257 let snake: ReserveArgs = serde_json::from_value(serde_json::json!({
2258 "workspace": "acme",
2259 "repo": { "namespace": "acme", "name": "web" },
2260 "public": false,
2261 "kind": "agent",
2262 "estimate_micros": 1,
2263 }))
2264 .unwrap();
2265 assert_eq!(snake.estimate_micros, 1);
2266 let answer = Reservation { id: "rsv_1".into(), paid_by: PaidBy::OnDemand, held_micros: 5, expires_at: String::new() };
2267 assert_eq!(serde_json::to_value(&answer).unwrap()["paidBy"], "on_demand");
2268 assert_eq!(serde_json::to_value(PlanKind::Internal).unwrap(), "internal");
2269 assert!(!PlanKind::Free.on_demand() && PlanKind::Enterprise.on_demand());
2270 }
2271
2272 #[test]
2273 fn a_refusal_carries_its_own_code() {
2274 let refused: crate::Outcome<Reservation> =
2275 crate::Outcome::fail(crate::FailureCode::OssPoolEmpty, "The open-source pool is spent.");
2276 let json = serde_json::to_value(&refused).unwrap();
2277 assert_eq!(json["error"]["code"], "oss_pool_empty");
2278 assert_eq!(crate::FailureCode::NotPaid.http_status(), 402);
2279 assert_eq!(crate::FailureCode::Paused.http_status(), 409);
2280 }
2281
2282 #[test]
Models per workspace: several providers, routed by kind of work2283 fn who_pays_is_read_as_the_runner_sends_it() {
2284 let run: StartRunArgs = serde_json::from_value(serde_json::json!({
2285 "workspace": "acme",
2286 "repo": { "namespace": "acme", "name": "web" },
2287 "number": 7,
2288 "task": "implement",
2289 "model": "Claude Sonnet 5.5",
2290 "billedTo": "workspace",
2291 }))
2292 .unwrap();
2293 assert_eq!(run.billed_to, "workspace");
2294 }
2295}