// froog API client (TypeScript). Generated from https://froog.tech/openapi.json by deploy/build-sdks.py; don't edit.
// API version 0.18.0. Docs: https://docs.froog.tech/
//
//   import { Froog } from "froogdev";   // npm install froogdev, or this file: "./froog"
//   const froog = new Froog({ apiKey: process.env.FROOG_API_KEY });
//   await using sb = await froog.sandboxes.create({ size: "small" });   // deleted at the end of the scope
//   console.log((await sb.exec("uname -a")).stdout);
//
//   // or one method per operation:
//   await froog.createSandboxes({ name: "box" });
//   await froog.waitUntil("box", "running");
//   const r = await froog.exec("box", { command: "uname -a" });

/** `POST /org-invites/accept`. */
export interface AcceptOrgInvite {
  /** The token from the invite link. */
  token: string;
}

export interface Account {
  allow_xlarge: boolean;
  /** Closed (`POST /account/close`): unix seconds. Reopen before `erase_at`. */
  closed_at?: number | null;
  data_retention?: DataRetention;
  /** The closing's deletion operation (`dop_…`, `GET /deletion-operations/{id}`). */
  deletion_operation?: string | null;
  email: string;
  /** When a closed account's data is erased for good (closed_at + 30 days). */
  erase_at?: number | null;
  id: string;
  max_sandboxes: number;
  /** The organization this request acted in (`X-Froog-Org`, or the active one); absent in your personal workspace. `id` and `email` stay yours. */
  org?: OrgSummary | null;
}

/** `POST /v1/account/close` and `POST /v1/account/reopen`. */
export interface AccountClosing {
  account: Account;
  operation: DeletionOperation;
}

/** Add an account to a profile (`POST /v1/ai/profiles/{profile}/credentials`). A provider that already has one gets another, used when the first hits a rate or usage limit. */
export interface AddAiCredential {
  /** Custom APIs: an https:// URL with a public DNS name. Bedrock: the AWS region (default us-east-1) goes in `region`. */
  base_url?: string | null;
  /** Custom APIs: the variable name (A-Z, 0-9, _; not a provider's). */
  name?: string | null;
  /** anthropic, openai, gemini, deepseek, mistral, openrouter, xai, bedrock or custom. */
  provider: string;
  /** Bedrock: the AWS region, e.g. us-west-2. */
  region?: string | null;
  /** Custom APIs: the header the proxy puts the secret in, and only there (default `Authorization` with `Bearer `). The placeholder anywhere else in the request is removed. */
  secret_header?: string | null;
  /** Custom APIs: what comes before the secret in the header, e.g. `Bearer ` or `Token ` (default `Bearer ` when neither `secret_header` nor `secret_query` is given, else none). */
  secret_prefix?: string | null;
  /** Custom APIs: put the secret in this query parameter instead of a header (e.g. `api_key`). */
  secret_query?: string | null;
  /** The key: one token of up to 8192 printable characters. Bedrock: a Bedrock API key, or `ACCESS_KEY_ID:SECRET_ACCESS_KEY[:SESSION_TOKEN]`. */
  value: string;
}

export interface AddSshKey {
  name: string;
  public_key: string;
}

/** One event of the agent's work.

`type`: `status` (data: status, error), `text` (content, partial), `tool_call` (name, input, id), `tool_result` (output, is_error, id), `steer` (message, native, mode), `log` (a line the harness printed that isn't an event), `error` (message). */
export interface AgentEvent {
  /** Unix milliseconds. */
  at: number;
  conversation_id: string;
  data: unknown;
  /** Increasing; pass the last one back as `cursor`. */
  id: number;
  prompt_id: string;
  type: string;
}

/** One account of a provider in a profile. Never the secret. */
export interface AiCredential {
  /** The account the proxy uses first for this provider (the first one not resting). */
  active: boolean;
  /** Custom APIs: where the proxy sends the requests. */
  base_url?: string | null;
  created_at: number;
  /** `cred_…` */
  id: string;
  /** The last characters of the key, e.g. `…7f3a`. */
  label: string;
  limited_reason?: string | null;
  /** Hit a rate or usage limit: the proxy skips it until then (unix seconds). */
  limited_until?: number | null;
  /** Custom APIs: the variable name the sandbox gets (e.g. `STRIPE_KEY`). */
  name?: string | null;
  /** anthropic, openai, gemini, deepseek, mistral, openrouter, xai, bedrock or custom. */
  provider: string;
  /** Custom APIs: the header the proxy puts the secret in (e.g. `Authorization`), after `secret_prefix`. Absent when it goes in the query string (`secret_query`). */
  secret_header?: string | null;
  /** Custom APIs: what comes before the secret in `secret_header` (e.g. `Bearer `). */
  secret_prefix?: string | null;
  /** Custom APIs: the query parameter the proxy puts the secret in, instead of a header. */
  secret_query?: string | null;
}

/** A credential profile: a named set of AI credentials. */
export interface AiProfile {
  created_at: number;
  /** In switching order per provider. */
  credentials: Array<AiCredential>;
  /** Sandboxes get the default profile unless their environment or the sandbox names another. */
  default: boolean;
  /** Environments whose sandboxes get this profile. */
  environments: Array<string>;
  /** `aip_…` */
  id: string;
  name: string;
}

/** The account's AI proxy settings (`GET /v1/ai/proxy`). */
export interface AiProxy {
  /** Every proxied sandbox of the account is refused (403 `ai_blocked`). */
  blocked: boolean;
  /** On: sandboxes started from now on get placeholder keys and base URLs pointing at the proxy; the real keys stay on froog. Default off. */
  enabled: boolean;
  /** The base URL sandboxes send their AI requests to. */
  url: string;
  /** With the proxy on, keep subscription sign-ins (Claude, ChatGPT) out of sandboxes too. They are never proxied. Default false: they pass as without the proxy. */
  withhold_subscriptions: boolean;
}

/** Usage of one sandbox in the account view. */
export interface AiSandboxUsage {
  blocked: boolean;
  /** Its name (or its id once deleted). */
  sandbox: string;
  sandbox_id: string;
  totals: AiTotals;
}

/** Tokens and requests over a period. */
export interface AiTotals {
  cache_read_tokens: number;
  cache_write_tokens: number;
  /** Estimated provider cost in USD, from list prices built into froog. Not a froog charge. */
  cost_usd: number;
  /** Answers with status 400 or above (including the proxy's own refusals upstream). */
  errors: number;
  /** Input tokens not read from a cache. */
  input_tokens: number;
  output_tokens: number;
  requests: number;
}

/** The account's AI usage (`GET /v1/ai/usage`). */
export interface AiUsage {
  days: number;
  /** Most expensive first. */
  sandboxes: Array<AiSandboxUsage>;
  totals: AiTotals;
}

/** One row: a UTC day, provider and model. */
export interface AiUsageRow {
  cache_read_tokens: number;
  cache_write_tokens: number;
  /** Estimated provider cost in USD, from list prices built into froog. Not a froog charge. */
  cost_usd: number;
  /** YYYY-MM-DD (UTC). */
  day: string;
  /** Answers with status 400 or above (including the proxy's own refusals upstream). */
  errors: number;
  /** Input tokens not read from a cache. */
  input_tokens: number;
  model: string;
  output_tokens: number;
  provider: string;
  requests: number;
}

/** `GET /v1/account/alerts`: which emails the account gets, and whether an errored sandbox is rebuilt from its last snapshot by itself. */
export interface AlertSettings {
  /** Rebuild a sandbox whose VM was lost (state `error`) from its last snapshot, and email (default on). */
  auto_rebuild: boolean;
  emails: Array<EmailAlert>;
}

/** An API key as listed (the key itself is shown only once, at creation). */
export interface ApiKeyInfo {
  /** What the key may do (`scopes::ACTIONS`); `["*"]` = everything. */
  actions?: Array<string>;
  created_at: number;
  /** An organization key: the email of the member who made it (it acts as that member). */
  created_by?: string | null;
  /** Limited to sandboxes of these environments (names); None = any environment. */
  environments?: Array<string> | null;
  /** None = never expires. */
  expires_at?: number | null;
  id: string;
  label: string;
  /** Limited to sandboxes that have all of these labels; None = any labels. */
  labels?: Record<string, string> | null;
  last_used_at?: number | null;
  /** The preset its actions match, if any (read-only, full-sandbox, ci, admin). */
  preset?: string | null;
  /** Requests made with it in the last 30 days. */
  requests_30d?: number;
  /** The sandboxes it may touch (names), besides those it created; None = all. */
  sandboxes?: Array<string> | null;
  /** Sandboxes this key created that still exist. */
  sandboxes_created?: number;
}

/** One entry of the account's audit log (`GET /audit`): who changed what, from where. Kept 90 days. */
export interface AuditEvent {
  /** What happened, e.g. sandbox.create, api_key.revoke, webhook.update, billing.plan. */
  action: string;
  /** Who did it: an API key id (`key_…`), `session` (the dashboard), or `public-url` (an auto-start by a visitor of a public URL). */
  actor: string;
  /** The API key's name, or the account email for a dashboard session. */
  actor_label?: string | null;
  /** Unix seconds. */
  at: number;
  /** Short extra facts, e.g. the sandboxes a create or fork made. */
  detail?: string | null;
  /** `aud_…` */
  id: string;
  /** The client's IP address. */
  ip?: string | null;
  /** The request's `X-Request-Id`. */
  request_id?: string | null;
  /** What it happened to: a sandbox, key, webhook or variable name or id (never a secret). */
  target?: string | null;
}

export interface AuditList {
  /** Newest first. */
  events: Array<AuditEvent>;
  /** Pass as `cursor` for the next (older) page; None at the end. */
  next_cursor?: string | null;
}

/** `PUT /v1/billing/wallet/auto-topup`: charge this much whenever the wallet drops below half of it (at least $3). 0 turns it off. */
export interface AutoTopup {
  amount_usd: number;
}

/** `GET /v1/availability`: what's free to add to a setup, the past `range` (measured every 10 minutes) and the next (projected). */
export interface Availability {
  now: number;
  points: Array<AvailabilityPoint>;
  /** The range covered on each side of now, in seconds. */
  range_secs: number;
  skus: Array<AvailabilitySku>;
}

/** How many of each kind fit at one time: `counts` lines up with `skus`. */
export interface AvailabilityPoint {
  at: number;
  counts: Array<number>;
  /** After now: worked out from setups' pending changes, not measured. */
  projected?: boolean;
}

/** One kind of sandbox you can add to a setup (`GET /v1/availability`), and how many more fit. */
export interface AvailabilitySku {
  cpu: Cpu;
  disk_gb: number;
  /** The free lite: one per account with a card, interruptible, not counted here. */
  free?: boolean;
  in_1d?: number | null;
  in_1w?: number | null;
  memory_gb: number;
  /** A month in a setup, running 24/7 (0 for the free lite). */
  monthly_usd: number;
  /** How many more could be added to setups now, in a day and in a week (pending removals from setups free room on their date); for the free lite, how many more could start. None: not known (no hosts, or a host didn't answer). */
  now?: number | null;
  size: Size;
  vcpus: number;
}

/** `POST /v1/inboxes/{inbox}/messages/batch-get`: up to 100 messages, with their bodies. */
export interface BatchGetMessages {
  message_ids: Array<string>;
}

/** The result of a batch update: how many messages changed, and ids that weren't found. */
export interface BatchResult {
  not_found?: Array<string>;
  updated: number;
}

/** `POST /v1/inboxes/{inbox}/messages/batch-update`: up to 100 messages. */
export interface BatchUpdateMessages {
  add_labels?: Array<string>;
  message_ids: Array<string>;
  remove_labels?: Array<string>;
}

/** Payment status of an account (`GET /v1/billing`). */
export interface Billing {
  /** Auto top-up charges when the wallet drops below this (half the amount, at least $3). */
  auto_topup_below_usd?: number;
  /** Auto top-up amount in dollars; 0 = off. Turned on by the first payment, off by a declined charge. */
  auto_topup_usd?: number;
  /** Reserved capacity: slots beyond the free ones, for a monthly commitment. */
  capacity?: Capacity;
  /** A card is on file (`POST /billing/card` adds one). */
  card_on_file: boolean;
  /** The account's monthly commitment, when it has one (capacity kept for it). */
  commitment?: Commitment | null;
  /** Payments are set up on this froog server. */
  enabled: boolean;
  /** The account isn't billed (e.g. the operator's own account). */
  exempt: boolean;
  /** Paying from the wallet for starts past the start limits. */
  extra_starts?: ExtraStarts;
  /** The free lite: while froog offers it, an account with a card runs one `lite` sandbox (1 vCPU, 2 GB) free, stopped (its disk saved) when paying customers need the room. */
  free_lite?: FreeLite;
  /** Sandboxes this account may run at once now. */
  max_running?: number;
  max_topup_usd?: number;
  /** Most the card can be charged for the wallet in 24 hours (payments and auto top-ups). */
  max_wallet_per_day_usd?: number;
  /** Smallest and largest wallet payment, dollars. */
  min_topup_usd?: number;
  /** Everything used this calendar month (UTC), at list prices. */
  month_usd?: number;
  /** The plan now; None = no plan (`PUT /billing/plan` chooses one). */
  plan?: PlanState | null;
  /** Starting sandboxes needs a plan (exempt accounts don't). */
  plan_required?: boolean;
  /** Plans on offer, cheapest first. */
  plans?: Array<Plan>;
  /** Per-second rates, quoted per hour and per 730-hour month. */
  rates?: Array<Rate>;
  /** How `max_running` grows with the money added, lowest first. */
  running_tiers?: Array<RunningTier>;
  /** The most this account may spend in a calendar month; reaching it stops its sandboxes (disks saved). None = no cap. */
  spend_cap_usd?: number | null;
  /** The free credit a new account gets when it adds a card. */
  starting_credit?: StartingCredit;
  /** Why they were stopped: `wallet_empty` or `spend_cap`. */
  stopped_for?: string | null;
  /** Sandboxes were stopped (disks saved) because the wallet ran out or the month's spending reached the cap; see `stopped_for`. Add money or raise the cap to start them again. */
  suspended: boolean;
  /** All money ever added (card payments; not credit or bonuses): sets `max_running`. */
  topped_up_usd?: number;
  /** The free trial a first plan starts with. */
  trial?: Trial;
  /** The bonus added to wallet payments and auto top-ups by amount; None = no bonus. */
  wallet_bonus?: WalletBonus | null;
  /** The prepaid balance usage is taken from, every minute. Negative = owed. */
  wallet_usd?: number;
}

/** A Stripe-hosted page to open in a browser. */
export interface BillingUrl {
  url: string;
}

/** `POST /sandboxes/{name}/browser`: open the browser view (only Chrome). */
export interface BrowserRequest {
  /** Chrome's user data directory on the sandbox: an absolute path outside the system directories, created if missing. Default: `~/.config/froog-browser`. */
  profile?: string | null;
}

/** The account's setup (`PUT /v1/billing/capacity`): the sandboxes it pays for by the month. The card is charged at the start of each calendar month; adding slots charges the prorated rest of the month at once; removing slots applies from the next month. */
export interface Capacity {
  /** Invite-only: the most the setup may hold (what was approved). To run more, ask with `POST /v1/billing/capacity/request`. Absent: no limit, or not approved yet. */
  allowed?: Array<CapacitySlot> | null;
  /** What these cost a full month. */
  monthly_usd: number;
  /** What's owed now (the wallet below zero), when `unpaid`. */
  owed_usd?: number;
  /** Slots removed, from the next month: then these. */
  pending?: PendingCapacity | null;
  /** In force now. */
  slots: Array<CapacitySlot>;
  /** Charged for this calendar month so far (prorated from when slots were added). */
  this_month_usd: number;
  /** This month's charge failed: the setup's sandboxes can't start (running ones stop) until it's paid. Pay it on a Stripe page with `POST /v1/billing/capacity/pay` (needed when the bank asks to confirm each payment), or add or choose another card (tried at once). */
  unpaid?: boolean;
  /** Paid sandboxes are invite-only and this account isn't in yet, or it asked for more than it was approved for: its request (`POST /v1/billing/capacity/request`). Absent otherwise. */
  waitlist?: CapacityWaitlist | null;
}

/** One line of an account's setup: `count` sandboxes of `size` with `cpu` vCPUs and a `disk` that's kept (resumable) or erased on stop (ephemeral), each running 24/7 at no extra charge for the month. */
export interface CapacitySlot {
  count: number;
  cpu?: Cpu;
  disk?: Disk;
  size: Size;
}

/** Where an account stands on the waitlist for paid sandboxes. */
export interface CapacityWaitlist {
  note?: string;
  /** When it asked (absent: it hasn't yet). */
  requested_at?: number | null;
  /** The setup it asked for, and what it's for. */
  slots?: Array<CapacitySlot>;
  /** pending, or declined. */
  status?: string | null;
}

/** A saved card (`GET /v1/billing/cards`). */
export interface Card {
  /** visa, mastercard, amex, ... */
  brand: string;
  /** The card wallet payments and auto top-up charge. */
  default: boolean;
  exp_month: number;
  exp_year: number;
  id: string;
  last4: string;
}

/** `GET /cli-login/{code}`: what's being approved. */
export interface CliLoginInfo {
  code: string;
  device: string;
  expires_at: number;
}

/** `POST /cli-login/poll` */
export interface CliLoginPoll {
  poll_token: string;
}

/** `POST /cli-login` (no auth): start an `froog login` in the browser. */
export interface CliLoginRequest {
  /** Shown on the approval page, e.g. the computer's hostname. */
  device?: string;
}

export interface CliLoginResult {
  email?: string | null;
  key?: string | null;
  /** "pending" or "approved" */
  status: string;
}

export interface CliLoginStarted {
  /** Show this; the dashboard asks the person to check it matches. */
  code: string;
  expires_in: number;
  /** Secret: poll with it. Never show it. */
  poll_token: string;
  /** Open this in the browser. */
  url: string;
}

export interface CommandList {
  commands: Array<CommandRecord>;
  /** Pass as `cursor` for the next (older) page; None at the end. */
  next_cursor?: string | null;
}

/** A chunk of a command's stored output from `offset`. Read again from `next_offset` until `done` (the command ended and everything was read). */
export interface CommandLogs {
  /** UTF-8 text, or base64 with `encoding=base64`. */
  data: string;
  done: boolean;
  next_offset: number;
  offset: number;
  /** Bytes stored so far for this stream. */
  size: number;
  status: string;
}

/** One command in a sandbox's history (`GET /sandboxes/{name}/command-history`). Kept 90 days, readable while the sandbox is stopped. `mode`: sync | stream | detached. `status`: running | paused (frozen with a sandbox stopped with its memory kept; a start resumes it) | exited | timed_out | failed | killed | lost. */
export interface CommandRecord {
  /** The command text (first 64 KiB). */
  command: string;
  ended_at?: number | null;
  exit_code?: number | null;
  id: string;
  /** The background job behind a stream/detached command (`froog logs`, `froog kill`). */
  job_id?: string | null;
  mode: string;
  /** The kernel killed it for using too much memory (exit code 137). */
  oom_killed?: boolean;
  /** Output past the per-command or per-account cap was dropped. */
  output_truncated: boolean;
  started_at: number;
  status: string;
  stderr_size: number;
  stdout_size: number;
}

/** A monthly commitment: the least the account pays a calendar month, for capacity kept for it. The month's usage counts toward it; what's short is charged to the wallet when the month ends. */
export interface Commitment {
  /** What this month's usage is still short of it (charged at the month's end if it stays short). */
  shortfall_usd: number;
  /** This month's (prorated in the month it started). */
  this_month_usd: number;
  /** A full month. */
  usd: number;
}

/** `POST /v1/inboxes/forwarding/verifications/confirm`. */
export interface ConfirmForwardingVerification {
  /** The code from the email (`XXXXX-XXXXX`; case, spaces and the dash don't matter). */
  code: string;
  destination: string;
}

/** One way to sign in to the account (`GET /v1/account/connections`). */
export interface Connection {
  created_at: number;
  /** The address this connection signs in with (GitHub: the account's verified primary address). */
  email?: string | null;
  /** `con_…` */
  id: string;
  /** The GitHub login, for a GitHub connection. */
  login?: string | null;
  /** Its address gets the account's emails (the account's email). */
  primary: boolean;
  /** google | github | email | agentid */
  provider: string;
}

/** A conversation: a thread of prompts with the agent's memory (the harness's own session). */
export interface Conversation {
  /** The harness of its last prompt. */
  agent: string;
  created_at: number;
  /** The one a prompt without `conversation_id` or `new` continues (the most recent). */
  current: boolean;
  id: string;
  /** The start of its last prompt. */
  last_prompt: string;
  model?: string | null;
  prompts: number;
  /** Prompts waiting for their turn. */
  queued: number;
  /** A turn is running in it now. */
  running: boolean;
  sandbox: string;
  updated_at: number;
}

/** A conversation with its prompts, oldest first. */
export interface ConversationDetail {
  /** The harness of its last prompt. */
  agent: string;
  created_at: number;
  /** The one a prompt without `conversation_id` or `new` continues (the most recent). */
  current: boolean;
  id: string;
  /** The start of its last prompt. */
  last_prompt: string;
  model?: string | null;
  prompts: number;
  /** Prompts waiting for their turn. */
  queued: number;
  /** A turn is running in it now. */
  running: boolean;
  sandbox: string;
  turns: Array<Prompt>;
  updated_at: number;
}

export interface ConversationList {
  conversations: Array<Conversation>;
}

/** How a sandbox's vCPUs are scheduled. `shared`: time on the host's cores, shared with other sandboxes (most sandboxes idle most of the time). `dedicated`: each vCPU is a physical core of its own that no other sandbox runs on, at 2.5 times the shared price. */
export type Cpu = "shared" | "dedicated";

export interface CreateAiProfile {
  /** Start with a copy of this profile's credentials. */
  copy_from?: string | null;
  /** 1-40 of a-z, 0-9 and -. */
  name: string;
}

export interface CreateInbox {
  /** Your own id for it (1-128 characters). Making an inbox with a `client_id` you used before returns that inbox (200, not 201): safe to retry. */
  client_id?: string | null;
  deactivate_at?: number | null;
  /** One of your verified domains (or a subdomain of one with subdomains on). Default: froogmail.com. */
  domain?: string | null;
  /** Delete messages this many hours after they arrive (1 to the server's retention). */
  expiry_hours?: number | null;
  metadata?: Record<string, string> | null;
  /** Display name. */
  name?: string | null;
  /** Attach it to this sandbox: it's `FROOG_EMAIL` there (from the sandbox's next start), and the key inside the sandbox can read it. The address starts with the sandbox's name unless `username` says otherwise. */
  sandbox?: string | null;
  signature?: InboxSignature | null;
  /** `deactivated` to create it deactivated. */
  status?: string | null;
  /** The start of the address (letters, digits, dots, dashes; 1 to 32). On froogmail.com froog adds a random suffix: `signup` becomes `signup-k3f9qz@froogmail.com`. On your own domain the address is exactly `username@domain`. Default: `agent`. */
  username?: string | null;
}

/** `POST /orgs`. */
export interface CreateOrg {
  name: string;
}

/** `POST /v1/revere/contacts`. `kind` defaults from the URL's host (hooks.slack.com, discord.com, chat.googleapis.com, ntfy.sh). */
export interface CreateRevereContact {
  kind?: string | null;
  /** Monitors (ids or names); none or empty: every monitor. */
  monitors?: Array<string> | null;
  name?: string | null;
  url: string;
}

/** `POST /v1/revere/monitors`. `kind` defaults from the target: a URL is `http`, `host:port` is `tcp`, a bare host is `icmp`, no target is `heartbeat`. */
export interface CreateRevereMonitor {
  /** `http`: a request body, up to 10 KB. */
  body?: string | null;
  cert_warn_days?: number | null;
  confirmations?: number | null;
  email?: boolean | null;
  expect_status?: string | null;
  grace_secs?: number | null;
  /** `http`: up to 10 request headers. */
  headers?: Array<RevereHeader> | null;
  /** Default 300 (the free interval); 30 at the fastest. */
  interval_secs?: number | null;
  keyword?: string | null;
  keyword_absent?: boolean | null;
  kind?: string | null;
  method?: string | null;
  name?: string | null;
  target?: string | null;
  timeout_secs?: number | null;
}

export interface CreateSandbox {
  /** true: adaptive CPU. It occupies a setup slot of its size (the floor) and its CPU grows live while it's busy, up to `max_vcpus`, then shrinks back when idle. vCPU time above the floor is billed per second from the wallet; with an empty wallet or at the spending cap it stays at the floor. Shared vCPUs only (not with `cpu: dedicated`), small and larger. */
  adaptive?: boolean | null;
  /** true: while stopped, a request to one of its public URLs, or an exec, file, job or wait call, starts it. Default false. */
  auto_start?: boolean | null;
  /** Create `count` sandboxes named `name-1..name-N`. */
  count?: number | null;
  /** `shared` (default) or `dedicated`: every vCPU a physical core of its own, at 2.5 times the price. Kept for the sandbox's life (a start keeps it). Not with `lite` or CI. */
  cpu?: Cpu | null;
  /** Delete it after it has stayed stopped this many seconds (0 or absent = never; at most 365 days). A start before then cancels the countdown. */
  delete_after_secs?: number | null;
  /** The desktop's frame rate: 60 (default, included) or 120 (smoother, for 4+ vCPUs; billed per minute from the wallet while a viewer is connected). */
  desktop_fps?: number | null;
  /** Its own environment variables (on top of the account's; they win, and apply even with `environment: false`). With `from`, the default is the saved snapshot's source's. */
  env?: Record<string, string> | null;
  /** false: start with none of the account's environment (no env vars, repos, files or setup script), e.g. for code or people you don't trust with your credentials. Default true, except from a share code (`from: "fsh_…"`) or the saved copy one gave: false there (another account prepared that disk); `true` opts in. */
  environment?: boolean | null;
  /** The environment it uses (`GET /environments`), at its latest version. Default: the account's default environment. Kept with `environment: false` (it then gets none of it). */
  environment_name?: string | null;
  /** Delete it this many seconds after it's created, running or not (60 s to 365 days; absent = never). Shows as `expires_at`. */
  expires_in_secs?: number | null;
  /** Files written into the home directory before the sandbox counts as running (first boot only; mode 600; at most 20, 1 MiB together). */
  files?: Array<NewFile> | null;
  /** Start from this saved snapshot (its name): its disk, OS and, unless `size` is given, size. Or a share code (`fsh_…`) another account gave you: a copy of its saved snapshot becomes a saved snapshot of yours, and the owner's logins, keys and secret files are removed from the disk before the sandbox counts as running. */
  from?: string | null;
  /** Key-value tags (at most 32; keys 1-63 of `a-z A-Z 0-9 . _ - /`, values up to 255 characters). */
  labels?: Record<string, string> | null;
  /** Stop it this many seconds after each start, busy or not, even while an agent prompt runs (0 or absent = no limit; at most 30 days). The auto-stop timer (`ttl_secs`) still applies. */
  max_lifetime_secs?: number | null;
  /** Adaptive: the most vCPUs it may grow to (more than its size's, at most 16; default 16). Implies `adaptive: true`. */
  max_vcpus?: number | null;
  /** false: keep no command history or process samples. Default: the account's setting. */
  monitoring?: boolean | null;
  name?: string | null;
  /** Operating system; default Ubuntu 24.04. */
  os?: Os | null;
  /** A git repo cloned into this sandbox only, by the setup job at boot (also with `environment: false`). */
  repo?: SandboxRepo | null;
  /** A script run once, in the background, after the first boot (as job "setup"). */
  setup?: string | null;
  size?: Size | null;
  /** false: never snapshot it; a stop erases it. Default: the account's setting. */
  snapshots?: boolean | null;
  /** Auto-stop this many seconds after each start, busy or not (at most 30 days; 0 = no auto-stop). Absent or null: 1 hour. */
  ttl_secs?: number | null;
  /** In an organization: `shared` (every member can use it) or `private` (only you). Default: the organization's default visibility. A personal sandbox is always private. */
  visibility?: string | null;
}

/** `POST /v1/seaeye/monitors`. */
export interface CreateSeaeyeMonitor {
  branch?: string | null;
  /** 1-20, default 1. */
  consecutive?: number | null;
  /** 0-1440, default 60. */
  cooldown_mins?: number | null;
  /** Required for duration: 60 to 21600. */
  duration_secs?: number | null;
  /** Default true. */
  email?: boolean | null;
  job?: string | null;
  /** failure (default) | duration */
  kind?: string | null;
  log_pattern?: string | null;
  name: string;
  repo?: string | null;
  workflow?: string | null;
}

export interface CreateSnapshot {
  label?: string | null;
}

/** `POST /v1/revere/pages/{page}/incidents`. Subscribers are emailed (unless `notify` is false). */
export interface CreateStatusIncident {
  /** The first update's text. */
  body?: string;
  ends_at?: number | null;
  impact?: string | null;
  /** `incident` (default) or `maintenance`. */
  kind?: string | null;
  monitors?: Array<string> | null;
  notify?: boolean | null;
  starts_at?: number | null;
  status?: string | null;
  title: string;
}

/** `POST /v1/revere/pages/{page}/incidents/{id}/updates`: a new status and what's happening. */
export interface CreateStatusIncidentUpdate {
  body?: string;
  impact?: string | null;
  notify?: boolean | null;
  status: string;
}

export interface CreateStatusPage {
  auto_incidents?: boolean | null;
  custom_domain?: string | null;
  description?: string | null;
  homepage_url?: string | null;
  /** Monitors (ids or names) to show, in order. Default: none. */
  monitors?: Array<StatusPageMonitor> | null;
  slug: string;
  subscribers_enabled?: boolean | null;
  title?: string | null;
}

export interface CreatedApiKey {
  actions?: Array<string>;
  environments?: Array<string> | null;
  expires_at?: number | null;
  id: string;
  /** Shown once; store it now. */
  key: string;
  label: string;
  labels?: Record<string, string> | null;
  sandboxes?: Array<string> | null;
}

/** `POST /saved-snapshots/{name}/shares`: the code, once. */
export interface CreatedSnapshotShare {
  /** `fsh_…`: another account runs `froog new --from fsh_…`. Shown once; froog keeps only a hash. */
  code: string;
  created_at: number;
  id: string;
  name: string;
}

/** `POST /v1/dashboard-link`: open the dashboard signed in. The code in the URL works once and expires at `expires_at`; it can't call the API. */
export interface DashboardLink {
  expires_at: number;
  url: string;
}

/** `GET/PATCH /account/data-retention`. Changing it needs a dashboard session, not an API key. */
export interface DataRetention {
  /** Turning zero data retention on just now started erasing: this deletion operation (`GET /deletion-operations/{id}`) follows it. Only in the answer to that change. */
  deletion_operation?: string | null;
  /** New sandboxes keep no command history or process samples. */
  monitoring_off: boolean;
  /** New sandboxes are never snapshotted (a stop erases them). */
  snapshots_off: boolean;
  /** Erase each sandbox's data (disk, snapshots, history) when it stops; no saved snapshots. */
  zero_data_retention: boolean;
}

/** `DELETE /sandboxes/{name}/snapshots`: the automatic snapshots that were deleted. */
export interface DeletedSnapshots {
  /** Their ids. */
  deleted: Array<string>;
  /** The snapshot a stopped (or errored) sandbox will start from, which is kept. */
  kept?: string | null;
}

/** A deletion that runs in the background: closing an account (erased after the 30-day reopen window) or turning on zero data retention. `GET /v1/deletion-operations/{id}`. */
export interface DeletionOperation {
  created_at: number;
  /** Why the last attempt couldn't finish (status blocked). */
  error?: string | null;
  /** When the erasure is due (an account close: the end of the reopen window). */
  expected_by?: number | null;
  /** `dop_…` */
  id: string;
  /** account_close | zero_data_retention */
  kind: string;
  /** waiting_for_reopen_window | removing | retrying | completed | reopened */
  stage: string;
  /** pending | processing | blocked | completed | canceled. `blocked` is not final: it is retried. */
  status: string;
  updated_at: number;
}

/** `POST /sandboxes/{name}/desktop`: a link to the VM's desktop in the browser. */
export interface DesktopLink {
  expires_at: number;
  /** The frame rate this view streams at (60 or 120). */
  fps?: number;
  /** Why it streams at less than the sandbox's `desktop_fps`, if it does (too few vCPUs, or the wallet can't pay for 120 fps). */
  fps_note?: string | null;
  /** Secret: carries a token (in the fragment, after `#`). Open it within 10 minutes; an open session keeps working. Add `overlay=0` to the query (before the `#`) to hide the viewer's controls and stats, e.g. in an iframe. */
  url: string;
}

/** What happens to a sandbox's disk when it stops. `resumable` (the default): it's kept, with snapshots, forks and restores. `ephemeral`: never snapshotted, and a stop erases it (a sandbox created with `"snapshots": false`). Setups price the two apart; an ephemeral sandbox may also take a free resumable slot, never the other way round. */
export type Disk = "resumable" | "ephemeral";

export interface DnsRecord {
  /** The full name (`example.com`, `froog._domainkey.example.com`). */
  name: string;
  priority?: number | null;
  /** `inbound`, `spf`, `dkim` or `dmarc`. */
  purpose: string;
  /** Required for the domain to verify (DMARC is recommended, not required). */
  required: boolean;
  /** `verified`, `missing` or `invalid` (there, with another value). */
  status: string;
  /** `MX`, `TXT` or `CNAME`. */
  type: string;
  value: string;
}

/** A message being written (`/v1/inboxes/{inbox}/drafts`). With `send_at` it's scheduled and goes out by itself. */
export interface Draft {
  attachments?: Array<InboxAttachment>;
  bcc?: Array<string>;
  cc?: Array<string>;
  client_id?: string | null;
  created_at: number;
  error?: string | null;
  html?: string | null;
  id: string;
  inbox_id: string;
  /** `new`, `reply`, `reply_all` or `forward` (fixed when it's made). */
  kind: string;
  labels?: Array<string>;
  preview?: string;
  reply_to?: Array<string>;
  send_at?: number | null;
  /** `scheduled`, `sending` or `failed` (with `error`); none for a plain draft. */
  send_status?: string | null;
  /** The message it answers or forwards. */
  source_message_id?: string | null;
  subject?: string;
  text?: string | null;
  thread_id?: string | null;
  to?: Array<string>;
  updated_at: number;
}

export interface DraftList {
  drafts: Array<Draft>;
  next_page_token?: string | null;
}

export interface EmailAlert {
  description: string;
  enabled: boolean;
  /** disk | stop_refused | unresponsive | rebuilt | plan_nudge | billing */
  kind: string;
}

/** `POST /v1/account/connections/email`: send a 6-digit code to an address to connect it. */
export interface EmailCodeRequest {
  email: string;
}

/** `POST /v1/account/connections/email/verify`: the code from the email. */
export interface EmailCodeVerify {
  code: string;
  email: string;
}

/** A secret file written into every sandbox at each start (content never returned). */
export interface EnvFile {
  /** Relative to the home directory, e.g. `.npmrc` or `app/.env`. */
  path: string;
  size: number;
  updated_at: number;
}

/** An account environment variable as listed (the value is never returned, only a preview). */
export interface EnvVar {
  name: string;
  /** e.g. "sk-a…9xQ"; the whole value if it's short and not secret-looking. */
  preview: string;
  updated_at: number;
}

/** The account's environment: what every new sandbox starts with, besides env vars. */
export interface Environment {
  /** New sandboxes use it when they name no environment. */
  default?: boolean;
  files: Array<EnvFile>;
  /** Its name (`default` for the account's first one). */
  name?: string;
  /** A setup script per repo (by its directory under ~), run in that directory after cloning, at every start, before the environment's own setup script. */
  repo_setup?: Record<string, string>;
  /** Git URLs cloned into `~/<repo>` when the directory doesn't exist yet (`https://github.com/org/repo`, optionally `#branch`). */
  repos: Array<string>;
  /** Shell script run in the background at every start, after cloning (as job "setup"). */
  setup?: string | null;
  updated_at: number;
  /** Its latest version: every change makes a new one. Sandboxes stay on the version they started with until `POST /environments/{env}/upgrade`. */
  version?: number;
}

/** One environment in `GET /environments`. */
export interface EnvironmentSummary {
  created_at: number;
  /** New sandboxes use it when they name none. */
  default: boolean;
  files: number;
  name: string;
  repos: number;
  /** Sandboxes (not deleted) per version they are on, newest version first. */
  sandboxes: Array<EnvironmentVersionUse>;
  /** It has a setup script. */
  setup: boolean;
  updated_at: number;
  /** Its latest version (every change makes a new one). */
  version: number;
}

/** The answer to `POST /environments/{env}/upgrade`. */
export interface EnvironmentUpgrade {
  /** Running sandboxes that got the new version now (secret files written, files the new version dropped removed, the setup job started again). */
  applied: Array<string>;
  /** Sandboxes that get it at their next start (stopped, or not reachable right now). */
  at_next_start: Array<string>;
  environment: string;
  /** The version they are on now. */
  version: number;
}

/** One version of an environment (`GET /environments/{env}/versions`). */
export interface EnvironmentVersion {
  /** What the change was, e.g. "repos", "setup script", "file .npmrc set". */
  change: string;
  created_at: number;
  /** Sandboxes (not deleted) on this version. */
  sandboxes: number;
  version: number;
}

export interface EnvironmentVersionUse {
  sandboxes: number;
  version: number;
}

export interface ErrorBody {
  error: ErrorDetail;
}

export interface ErrorDetail {
  code: string;
  message: string;
  /** This request's id (also in the `X-Request-Id` header); quote it when reporting a problem. */
  request_id?: string | null;
}

export interface EventList {
  events: Array<AgentEvent>;
  /** The id of the last event: pass it as `cursor` to get only newer ones. */
  next_cursor: number;
}

/** One line of a streamed exec (`stream: true`): `started` first, then `stdout`/`stderr` chunks as they arrive, then exactly one `exit` or `error`. */
export type ExecEvent = {
  command_id?: string | null;
  type: "started";
} | {
  data: string;
  type: "stdout";
} | {
  data: string;
  type: "stderr";
} | {
  exit_code: number;
  oom_killed?: boolean;
  timed_out: boolean;
  type: "exit";
} | {
  code: string;
  message: string;
  type: "error";
};

export interface ExecRequest {
  command: string;
  /** Run in this directory (relative to the home directory, or absolute). */
  cwd?: string | null;
  /** Extra environment variables for this command only. */
  env?: Record<string, string> | null;
  /** Text fed to the command's standard input, which then ends (at most 1 MiB). Without it (and `stdin_b64`), stdin is empty. */
  stdin?: string | null;
  /** Like `stdin`, base64-encoded (for binary input; at most 1 MiB decoded). */
  stdin_b64?: string | null;
  /** true: answer with `application/x-ndjson`, one `ExecEvent` per line as output arrives (also chosen by `Accept: application/x-ndjson`). */
  stream?: boolean | null;
  timeout_secs?: number | null;
}

export interface ExecResult {
  /** The command's record in the history (`GET /sandboxes/{name}/command-history/{id}`). */
  command_id?: string | null;
  /** 124 when it timed out. */
  exit_code: number;
  /** The kernel killed it for using too much memory (exit code 137 and an out-of-memory kill in the kernel log while it ran). */
  oom_killed?: boolean;
  stderr: string;
  stdout: string;
  /** It ran past `timeout_secs` and was killed; stdout and stderr hold what it printed until then. */
  timed_out?: boolean;
}

/** Starts past the start limits (per minute, hour, day), paid from the wallet. Off by default. */
export interface ExtraStarts {
  /** They can run now: on, with money added before and money in the wallet. */
  available: boolean;
  /** The price of a start by how far past the included number it is. A start pays the highest price of the minute, hour and day windows. */
  brackets: Array<StartBracket>;
  /** Turned on for this account (`PUT /billing/extra-starts`). */
  enabled: boolean;
  /** Past this multiple of the per-minute limit, a start fails even when paid. */
  max_minute_multiple: number;
}

/** `POST /feedback`: a message to the froog team (replies go to the account email). */
export interface Feedback {
  message: string;
}

/** One entry of a directory listing. `kind`: file | dir | link | other. */
export interface FileEntry {
  kind: string;
  modified: number;
  name: string;
  size: number;
}

/** One line of `GET /sandboxes/{name}/files/watch` (NDJSON). `type`: `ready` (watching; `method` inotify or poll), `change` (`event` create | modify | delete, `path`, `dir`), `error` (`message`), and last `end` (`reason` timeout | exited | error). */
export interface FileEvent {
  dir?: boolean | null;
  event?: string | null;
  message?: string | null;
  method?: string | null;
  /** As inotify or find print it: absolute if the watched path was, else relative to ~. */
  path?: string | null;
  reason?: string | null;
  type: string;
}

/** `GET /sandboxes/{name}/files/find?path=&pattern=&regex=`: lines that contain a text. */
export interface FileFind {
  errors?: Array<string>;
  /** At most 1,000. */
  matches: Array<FileMatch>;
  truncated: boolean;
}

/** `GET /sandboxes/{name}/files?path=`: a file's details, or a directory and its entries. */
export interface FileInfo {
  entries?: Array<FileEntry> | null;
  kind: string;
  modified: number;
  path: string;
  size: number;
}

export interface FileMatch {
  /** The line, cut at 500 characters. */
  content: string;
  file: string;
  line: number;
}

/** `POST /sandboxes/{name}/files/permissions`: chmod. The owner (the sandbox user) stays. */
export interface FilePermissions {
  /** Octal, e.g. 755 or 0600. */
  mode: string;
  path: string;
  /** Also everything inside a directory. */
  recursive?: boolean;
}

/** `POST /sandboxes/{name}/files/replace`: replace every occurrence of `pattern` (plain text, byte for byte) with `new_value` in each file (up to 100 files, 5 MiB each). */
export interface FileReplace {
  new_value: string;
  paths: Array<string>;
  pattern: string;
}

export interface FileReplaced {
  error?: string | null;
  file: string;
  replacements?: number | null;
  success: boolean;
}

/** `GET /sandboxes/{name}/files/search?path=&pattern=`: paths whose name matches a glob. */
export interface FileSearch {
  /** Parts of the tree that couldn't be searched (the results are then incomplete). */
  errors?: Array<string>;
  /** Absolute paths, at most 10,000. */
  files: Array<string>;
  truncated: boolean;
}

/** A URL that GETs (download) or PUTs (upload, raw bytes) one file with no Authorization header. */
export interface FileUrl {
  expires_at: number;
  method: string;
  url: string;
}

export interface ForkSandbox {
  /** Adaptive CPU for the copies (`CreateSandbox.adaptive`). Default: the source's. */
  adaptive?: boolean | null;
  count?: number | null;
  /** Environment variables set on top of the source's own (these win). */
  env?: Record<string, string> | null;
  /** false: the copies run without the environment; when the source had it, the owner's logins, keys and secret files are removed from their disks before they count as running. Default: the source's. */
  environment?: boolean | null;
  /** Move the copies to this environment's latest version. Default: exactly the source's environment and version. */
  environment_name?: string | null;
  /** Labels set on top of the source's own (these win). */
  labels?: Record<string, string> | null;
  /** Adaptive: the most vCPUs the copies may grow to. Default: the source's (or 16). */
  max_vcpus?: number | null;
  /** Override the source's monitoring setting. */
  monitoring?: boolean | null;
  name: string;
  /** Size of the new sandboxes; defaults to the source's. */
  size?: Size | null;
  /** Snapshot id or label. Defaults to a fresh snapshot (running) or the latest one (stopped). */
  snapshot?: string | null;
  /** false: never snapshot the copies; a stop erases them. Default: the account's setting. */
  snapshots?: boolean | null;
  /** Auto-stop timer of the copies in seconds (0 = no auto-stop). Default: the source's. */
  ttl_secs?: number | null;
}

/** `POST …/messages/{id}/forward`: the message goes along as an attachment-free copy below your text (its attachments included), subject `Fwd: …`. */
export interface ForwardMessage {
  attachments?: Array<SendAttachment>;
  bcc?: Array<string>;
  cc?: Array<string>;
  html?: string | null;
  labels?: Array<string>;
  send_at?: number | null;
  subject?: string | null;
  text?: string | null;
  to: Array<string>;
}

export interface ForwardingVerification {
  destination: string;
  expires_at?: number | null;
  verified_at?: number | null;
}

/** The free lite (see `Billing::free_lite`). */
export interface FreeLite {
  /** This account may run it now (it has a card). */
  available: boolean;
  /** froog offers it now. */
  offered: boolean;
}

/** `POST /v1/github/connect`: where to install the app (or pick another account). */
export interface GithubConnect {
  url: string;
}

/** A GitHub App installation linked to the account. */
export interface GithubInstallation {
  /** The GitHub user or organization it is installed on. */
  account: string;
  /** User | Organization */
  account_type: string;
  created_at: number;
  /** GitHub's installation id. */
  id: number;
  /** all | selected (the repositories GitHub lets the app see) */
  repository_selection: string;
}

/** A repository the app can see (`GET /v1/github/repos`). */
export interface GithubRepo {
  /** https://github.com/owner/name.git */
  clone_url: string;
  default_branch?: string | null;
  /** owner/name */
  full_name: string;
  id: number;
  installation_id: number;
  private: boolean;
}

/** `GET /v1/github`. */
export interface GithubStatus {
  /** This server has a GitHub App set up (otherwise every other GitHub call is 404 github_not_configured). */
  configured: boolean;
  installations: Array<GithubInstallation>;
  /** The `runs-on` label of CI jobs that run on froog. */
  seaeye_label: string;
  /** `owner/name` of the repositories the token in each sandbox may use; empty = every repository the app can see. */
  token_repos: Array<string>;
}

/** A short-lived GitHub installation token (one hour). */
export interface GithubToken {
  expires_at: number;
  /** The GitHub account it works for. */
  owner: string;
  /** The repositories it is limited to; empty = every repository of the installation. */
  repositories: Array<string>;
  token: string;
}

/** `POST /v1/sandboxes/{name}/github-token`. */
export interface GithubTokenRequest {
  /** The GitHub user or organization (default: the first linked installation). */
  owner?: string | null;
}

/** An email address for an agent (`/v1/inboxes`). */
export interface Inbox {
  /** The full address, e.g. `signup-k3f9qz@froogmail.com`. */
  address: string;
  /** Your own id for it, unique in the account. Creating again with the same `client_id` returns this inbox instead of making another. */
  client_id?: string | null;
  created_at: number;
  /** When it deactivates by itself (unix seconds), if scheduled. */
  deactivate_at?: number | null;
  /** Messages are deleted this many hours after they arrive (default: the server's retention, 30 days). */
  expiry_hours?: number | null;
  id: string;
  last_message_at?: number | null;
  /** Messages kept. */
  messages?: number;
  /** Your key/value pairs (up to 64 keys). */
  metadata?: Record<string, string>;
  /** Display name: the name in From when the inbox sends, and your label for it. */
  name?: string;
  /** The sandbox it belongs to, if any. */
  sandbox?: string | null;
  /** Added to every message the inbox sends. */
  signature?: InboxSignature | null;
  /** `active` or `deactivated`. A deactivated inbox refuses mail and can't send; it is still a paid seat. */
  status?: string;
  /** Messages labeled `unread`. */
  unread?: number;
  updated_at?: number;
}

export interface InboxAttachment {
  content_id?: string | null;
  content_type: string;
  filename?: string;
  /** `att_<n>`, stable for the message. */
  id: string;
  /** Shown in the body (an image the HTML refers to) rather than attached. */
  inline?: boolean;
  size: number;
}

/** What the account pays for inboxes (`GET /v1/inboxes/billing`). */
export interface InboxBilling {
  /** Whether inboxes can be made and receive mail now. */
  active: boolean;
  cancel_at_period_end?: boolean;
  period_end?: number | null;
  /** One inbox a month, in US cents. */
  price_cents: number;
  /** Whether this account pays for inboxes (false: billing-exempt, or a server without payments). */
  required: boolean;
  /** Inboxes paid for this period. */
  seats: number;
  /** The Stripe subscription's status (active, past_due, ...); none without one. */
  status?: string | null;
  /** Inboxes the account has. */
  used: number;
}

/** `POST /v1/inboxes/billing/checkout`: how many inboxes to buy (default: yours plus one). */
export interface InboxCheckout {
  quantity?: number | null;
}

export interface InboxList {
  inboxes: Array<Inbox>;
  /** Pass as `page_token` for the next page; none at the end. */
  next_page_token?: string | null;
  /** Whether this server sends mail. False: inboxes receive only, and send, reply, forward, draft-send and forwarding setup answer `503 mail_send_off`. */
  sending?: boolean;
}

/** A message in an inbox, received or sent. Lists leave out `text`, `html`, `extracted_*` and `headers`; get one message for them. */
export interface InboxMessage {
  attachments?: Array<InboxAttachment>;
  /** SPF, DKIM and DMARC results (received mail). */
  auth?: MailAuth | null;
  /** Sent messages only. */
  bcc?: Array<string>;
  cc?: Array<string>;
  /** One-time codes found in the subject and body, most likely first. */
  codes?: Array<string>;
  /** Delivery state of a sent message: `queued`, `sent` (handed on), `delivered`, `bounced`, `failed`. */
  delivery?: string | null;
  /** The SMTP envelope sender (bounce address); may differ from `from`. */
  envelope_from?: string;
  extracted_html?: string | null;
  /** The new text of a reply, without the quoted message below it. */
  extracted_text?: string | null;
  /** The From header's address. */
  from: string;
  from_name?: string;
  /** Header names in lowercase; repeated headers joined with newlines. */
  headers?: Record<string, string> | null;
  html?: string | null;
  id: string;
  in_reply_to?: string | null;
  inbox_id: string;
  /** System labels (`received`, `sent`, `unread`, `spam`, `unauthenticated`, `trash`, `bounced`, ...) and your own. */
  labels?: Array<string>;
  /** Verification, confirmation and sign-in links found in the body, most likely first. */
  links?: Array<string>;
  /** The Message-ID header (without angle brackets). */
  message_id?: string | null;
  /** The first 200 characters of the text. */
  preview?: string;
  /** When it arrived, or was sent (unix seconds). */
  received_at: number;
  references?: Array<string>;
  reply_to?: Array<string>;
  size: number;
  /** Search results: the text around the match. */
  snippet?: string | null;
  subject: string;
  text?: string | null;
  thread_id?: string;
  /** The To header's addresses (for received mail with none, the address it was delivered to). */
  to?: Array<string>;
  updated_at?: number;
}

export interface InboxMessageList {
  /** Newest first unless `ascending`. */
  messages: Array<InboxMessage>;
  /** Pass as `page_token` for the next page; none at the end. */
  next_page_token?: string | null;
}

export interface InboxSignature {
  /** For the HTML part, up to 4,000 characters. Default: the text, escaped. */
  html?: string | null;
  /** For the plain-text part, up to 1,000 characters. */
  text: string;
}

/** Messages grouped into a conversation (by In-Reply-To and References). */
export interface InboxThread {
  attachment_count?: number;
  created_at: number;
  id: string;
  inbox_id: string;
  /** Every label on any of its messages. */
  labels?: Array<string>;
  last_message_id?: string;
  message_count: number;
  /** Getting one thread: its messages, oldest first, with their bodies. */
  messages?: Array<InboxMessage> | null;
  /** The latest message's preview. */
  preview?: string;
  /** The latest received message. */
  received_at?: number | null;
  /** To and Cc addresses, each once. */
  recipients?: Array<string>;
  /** From addresses, oldest first, each once. */
  senders?: Array<string>;
  /** The latest sent message. */
  sent_at?: number | null;
  size: number;
  /** The first message's subject. */
  subject: string;
  /** The latest message, either way. */
  updated_at: number;
}

export interface InboxThreadList {
  next_page_token?: string | null;
  threads: Array<InboxThread>;
}

/** `GET /v1/inboxes/{inbox}/wait`: the first matching message, or none when the wait timed out. */
export interface InboxWait {
  message?: InboxMessage | null;
}

export interface InterruptRequest {
  /** Only this conversation (default: every conversation on the sandbox). */
  conversation_id?: string | null;
}

export interface InterruptResult {
  /** The prompts stopped (running) or cancelled (queued). */
  interrupted: Array<string>;
}

/** An opened port's public IPv4 address: the host's address and a port of its own, forwarded to the sandbox's port. */
export interface Ipv4Port {
  /** Connect here over IPv4: "203.0.113.7:40001". */
  address: string;
  /** The sandbox's port, "8080/tcp". */
  port: string;
  /** The port on the host's IPv4 address that forwards to it. */
  public_port: number;
}

/** A background command. `state`: running | paused (frozen with a sandbox stopped with its memory kept; a start resumes it) | exited | killed | lost (the sandbox stopped under it). */
export interface Job {
  /** First 200 characters. */
  command: string;
  /** The job's record in the command history (None for jobs froog started itself, like setup). */
  command_id?: string | null;
  exit_code?: number | null;
  id: string;
  started_at: number;
  state: string;
}

/** A job's state and a chunk of its output (stdout and stderr together), read from `offset`. Pass `next_offset` as the next `offset` to follow it. */
export interface JobOutput {
  exit_code?: number | null;
  id: string;
  next_offset: number;
  output: string;
  output_size: number;
  started_at: number;
  state: string;
}

/** Write to a running job's standard input (one started with `stdin_open`), and/or close it. */
export interface JobStdin {
  /** Close the input after writing: the command reads end of file. */
  close?: boolean | null;
  /** Text to write (at most 1 MiB). */
  data?: string | null;
  /** Like `data`, base64-encoded (at most 1 MiB decoded). */
  data_b64?: string | null;
}

export interface JsonRpcError {
  /** -32700 parse error, -32600 invalid request, -32601 unknown method, -32602 bad params. */
  code: number;
  message: string;
}

/** A JSON-RPC 2.0 message to `POST /mcp` (a batch is an array of them). Without `id` it's a notification, answered with 202 and no body. */
export interface JsonRpcRequest {
  id?: unknown;
  /** Always "2.0". */
  jsonrpc: string;
  /** initialize, ping, tools/list, tools/call, notifications/initialized, … */
  method: string;
  params?: unknown;
}

/** The answer to a JSON-RPC request: `result` or `error`. A failed tool call is a `result` with `isError: true` and the API error (`code`, `message`, `request_id`) as its text. */
export interface JsonRpcResponse {
  error?: JsonRpcError | null;
  id: unknown;
  jsonrpc: string;
  result?: unknown;
}

/** What an account may do now: `GET /v1/limits`. */
export interface Limits {
  /** Sandboxes running at once (grows with the money added: `Billing.running_tiers`). */
  max_sandboxes: number;
  /** Running or starting now. */
  running: number;
  /** Saved snapshots included vs kept now. */
  saved_snapshot_allowance?: SavedSnapshotAllowance;
  /** Sizes the account can start. */
  sizes: Array<Size>;
  starts: StartLimits;
}

/** Each is `pass`, `fail`, `softfail`, `neutral`, `none`, `temperror` or `permerror`. */
export interface MailAuth {
  dkim: string;
  dmarc: string;
  /** The From domain's DMARC policy: `none`, `quarantine`, `reject`, or empty without one. */
  dmarc_policy?: string;
  spf: string;
}

/** Your own domain for inboxes (`/v1/inboxes/domains`). */
export interface MailDomain {
  checked_at?: number | null;
  created_at: number;
  domain: string;
  id: string;
  /** Receive mail (its MX points at froog). Off: send only. */
  inbound: boolean;
  reason?: string | null;
  /** The DNS records to add, each with whether we found it. */
  records: Array<DnsRecord>;
  /** `pending` (records not all there yet), `verified`, or `failed` (a record that was there is gone or wrong; inboxes keep working until it's fixed or a week passes). */
  status: string;
  /** Inboxes may use any subdomain too (`a@team.example.com`). */
  subdomains: boolean;
  verified_at?: number | null;
}

/** `GET /v1/inboxes/domains/{domain}/setup-link`. */
export interface MailDomainSetupLink {
  /** A public page with the domain's DNS records, for whoever runs its DNS. */
  url: string;
}

/** Something that happened in an inbox. The same body goes to webhooks that list the event, to WebSocket subscribers, and into the events feed (`GET /v1/inboxes/events`, kept 30 days).

Types: `message.received` (and `message.received.spam`, `.blocked`, `.unauthenticated` for mail with those labels), `message.sent`, `message.delivered`, `message.bounced`, `message.complained`, `message.rejected`, `label.added`, `label.removed` (feed and WebSocket only), `domain.verified`. */
export interface MailEvent {
  body_omitted?: boolean;
  created_at: number;
  /** `domain.verified`. */
  domain?: MailDomain | null;
  /** `evt_…`: the same on every delivery of this event (deduplicate on it). */
  id: string;
  inbox_id?: string | null;
  /** `label.added` / `label.removed`: the label. */
  label?: string | null;
  /** The message, without `text`/`html` when they're over 64 KiB (`body_omitted`). */
  message?: InboxMessage | null;
  message_id?: string | null;
  /** Bounces, rejections and failures: the remote server's answer. */
  reason?: string | null;
  /** Delivery events: the recipients they're about. */
  recipients?: Array<string>;
  thread?: InboxThread | null;
  type: string;
}

export interface MailEventList {
  /** Pass as `after` to get what comes next (also when there's nothing yet). */
  cursor: string;
  /** Oldest first. */
  events: Array<MailEvent>;
}

/** Received mail copied on to other addresses (`/v1/inboxes/forwarding` for the whole account, `/v1/inboxes/{inbox}/forwarding` for one inbox, which replaces the account's). Only verified addresses receive anything; spam, blocked, unauthenticated and sent mail isn't forwarded. */
export interface MailForwarding {
  /** None: this level sets nothing (an inbox then uses the account's). */
  destinations?: Array<string> | null;
  /** Destinations that receive nothing yet: verify them first. */
  unverified?: Array<string>;
}

/** An entry on an allow or block list (`/v1/inboxes/lists/{direction}/{type}` for the whole account, `/v1/inboxes/{inbox}/lists/{direction}/{type}` for one inbox). */
export interface MailListEntry {
  created_at: number;
  /** `receive`, `send` or `reply`. */
  direction: string;
  /** An address, or a domain (which covers its subdomains too). */
  entry: string;
  /** `address` or `domain`. */
  entry_type: string;
  /** The inbox it's for; none for the whole account. */
  inbox_id?: string | null;
  /** `allow` or `block`. */
  list_type: string;
  reason?: string | null;
}

/** Counts of events between `from` and `to` (`GET /v1/inboxes/metrics`), overall and per day. */
export interface MailMetrics {
  /** Bounced and complained as a share of sent (0-1); none without sends. */
  bounce_rate?: number | null;
  bytes_stored: number;
  complaint_rate?: number | null;
  days: Array<MailMetricsDay>;
  from: number;
  /** Messages and bytes stored now. */
  messages_stored: number;
  to: number;
  /** Event type to count. */
  totals: Record<string, number>;
}

export interface MailMetricsDay {
  counts: Record<string, number>;
  /** `YYYY-MM-DD` (UTC). */
  day: string;
}

/** An address the account doesn't send to any more (`/v1/inboxes/suppressions`). */
export interface MailSuppression {
  address: string;
  created_at: number;
  /** `bounced` or `complained`. */
  reason: string;
}

export interface MakeDir {
  /** Octal permissions of the new directory, e.g. 700 (default: the umask's, usually 755). */
  mode?: string | null;
  path: string;
}

/** `GET /sandboxes/{name}/metrics/history`: CPU, memory and disk sampled every 30 seconds while the sandbox runs (monitoring on), kept 7 days, averaged per `step_secs`, oldest first. Times when it was stopped have no points. */
export interface MetricsHistory {
  points: Array<MetricsPoint>;
  /** The window, unix seconds. */
  since: number;
  /** Each point averages this many seconds (a multiple of 30; at most 1000 points). */
  step_secs: number;
  until: number;
}

export interface MetricsPoint {
  /** The bucket's start, unix seconds. */
  at: number;
  cpu_max_percent?: number | null;
  /** Share of all CPUs busy (0-100), the average and the highest sample in the bucket. */
  cpu_percent?: number | null;
  /** Of the root filesystem. */
  disk_used_percent?: number | null;
  memory_total_mb?: number | null;
  memory_used_mb?: number | null;
  /** Samples in the bucket. */
  samples: number;
}

export interface MoveFile {
  from: string;
  to: string;
}

export interface NewApiKey {
  actions?: Array<string> | null;
  /** Limit the key to sandboxes of these environments (names). Sandboxes it creates use the first one unless they name another of them. */
  environments?: Array<string> | null;
  label?: string | null;
  /** Limit the key to sandboxes that have all of these labels. Sandboxes it creates or forks get them, and it can't change or remove them. */
  labels?: Record<string, string> | null;
  /** A key that works until revoked. */
  never_expires?: boolean;
  /** read-only | full-sandbox | ci | admin (`scopes::PRESETS`). Use this or `actions`. */
  preset?: string | null;
  /** Limit the key to these sandboxes (names), plus any it creates. */
  sandboxes?: Array<string> | null;
  /** Days until it expires (1-365). Default 90. */
  ttl_days?: number | null;
}

export interface NewDraft {
  attachments?: Array<SendAttachment>;
  bcc?: Array<string>;
  cc?: Array<string>;
  /** Your own id: making a draft with a `client_id` you used before returns that draft. */
  client_id?: string | null;
  /** A forward draft of this message. */
  forward_of?: string | null;
  html?: string | null;
  /** A reply draft to this message (recipients, subject and threading filled in). */
  in_reply_to?: string | null;
  labels?: Array<string>;
  /** With `in_reply_to`: reply to everyone. */
  reply_all?: boolean;
  reply_to?: Array<string>;
  send_at?: number | null;
  subject?: string | null;
  text?: string | null;
  to?: Array<string>;
}

/** `POST /environments` */
export interface NewEnvironment {
  /** Start with a copy of this environment's latest version (repos, scripts, secret files). Default: empty. */
  copy_from?: string | null;
  /** Make it the default right away. */
  default?: boolean | null;
  name: string;
}

/** A file to write into a new sandbox (`CreateSandbox.files`). */
export interface NewFile {
  content: string;
  /** utf8 (default) or base64 (for binary files). */
  encoding?: string | null;
  /** Relative to the home directory, e.g. `app/.env`. */
  path: string;
}

/** `POST /sandboxes/{name}/files/download-url` or `/upload-url`. */
export interface NewFileUrl {
  /** Seconds the URL works (60-86400, default 900). */
  expires_in?: number | null;
  path: string;
}

/** Start a background command: `POST /sandboxes/{name}/jobs`. */
export interface NewJob {
  command: string;
  /** Run in this directory (relative to the home directory, or absolute). */
  cwd?: string | null;
  /** Extra environment variables for this command only. */
  env?: Record<string, string> | null;
  /** "detached" (default) or "stream" (`froog exec --timeout 0` follows it); shown in the history. */
  mode?: string | null;
  /** Text for the job's standard input, given at start (at most 1 MiB). Kept with the job on the sandbox's disk (`~/.froog/jobs/<id>/stdin`). */
  stdin?: string | null;
  /** Like `stdin`, base64-encoded (at most 1 MiB decoded). */
  stdin_b64?: string | null;
  /** Keep standard input open: write to it later with `POST /jobs/{id}/stdin` (after `stdin`, if given), and close it there for end of file. */
  stdin_open?: boolean | null;
}

export interface NewMailDomain {
  domain: string;
  /** Default true. */
  inbound?: boolean | null;
  subdomains?: boolean | null;
}

export interface NewMailListEntry {
  entry: string;
  reason?: string | null;
}

/** `POST /orgs/{org}/invites`. */
export interface NewOrgInvite {
  email: string;
  /** member (default) or admin. Only the owner invites admins. */
  role?: string | null;
}

/** `POST /sandboxes/{name}/urls`: host a port, or change how an already hosted port is reached. */
export interface NewPublicUrl {
  port: number;
  /** true: no token. Default false (private), like boat. Hosting a public port again without it gives it a new token; with it, removes the token. */
  public?: boolean;
  /** Rename the URL to `https://<subdomain>.<domain>` (3-40 lowercase letters, digits, hyphens). */
  subdomain?: string | null;
  /** A label for people (at most 100 characters); "" removes it. Hosting again without it keeps the old one. */
  title?: string | null;
}

/** `POST /sandboxes/{name}/urls/{port}/tokens`: another token for a private URL, e.g. one per viewer, that expires and can be revoked on its own. */
export interface NewUrlToken {
  /** Who or what it's for (at most 100 characters). */
  label?: string | null;
  /** Seconds until it stops working: 60 to 30 days, default 1 day. */
  ttl_secs?: number | null;
}

export interface NewWebhook {
  events?: Array<string>;
  /** Mail events only for these inboxes (ids or addresses). */
  inboxes?: Array<string> | null;
  name?: string | null;
  url: string;
}

/** `POST /sandboxes/{name}/ports`: open one inbound port (on the sandbox's IPv6 address, and on a public port of its host's IPv4 address). */
export interface OpenPort {
  port: number;
  /** tcp (default) or udp. */
  protocol?: string;
}

/** One organization. */
export interface Org {
  /** The active workspace of your account. */
  active?: boolean;
  created_at: number;
  /** New sandboxes start shared (every member can use them) or private (only their creator). */
  default_visibility: string;
  id: string;
  members: number;
  name: string;
  /** Your role in it. */
  role: string;
  /** Seats the owner bought (`PUT /orgs/{org}/seats`). */
  seats: number;
  /** Seats paid: the larger of `seats` and the members. The plan price is charged per seat. */
  seats_billed: number;
}

/** A pending invite. */
export interface OrgInvite {
  created_at: number;
  email: string;
  expires_at: number;
  /** `inv_…` */
  id: string;
  invited_by: string;
  role: string;
  /** The secret of the link (`froog org accept TOKEN`). Only in that answer. */
  token?: string | null;
  /** The link to accept it. Only in the answer to `POST /orgs/{org}/invites` (it is also emailed). */
  url?: string | null;
}

/** `GET /org-invites/{token}`: what an invite link is for, before accepting it. */
export interface OrgInvitePreview {
  email: string;
  expires_at: number;
  invited_by: string;
  org: string;
  role: string;
}

/** `GET /orgs`. */
export interface OrgList {
  orgs: Array<OrgSummary>;
}

/** One member. */
export interface OrgMember {
  email: string;
  /** The member's account id. */
  id: string;
  joined_at: number;
  /** Cap: organization sandboxes this member runs at once. None = no cap. */
  max_running_sandboxes?: number | null;
  /** Cap: this member's organization-billed machine time per billing period, in US dollars at list prices. None = no cap. */
  max_usage_usd?: number | null;
  /** owner | admin | member */
  role: string;
  /** This member's organization sandboxes running now. */
  running_sandboxes?: number;
  /** What this member's organization sandboxes ran this billing period, in US dollars. */
  usage_usd?: number;
}

/** `GET /orgs/{org}/members`. */
export interface OrgMembers {
  /** Pending invites (owners and admins only; empty for members). */
  invites?: Array<OrgInvite>;
  members: Array<OrgMember>;
}

/** One workspace in `GET /orgs`: your personal account first, then each organization. */
export interface OrgSummary {
  /** The active workspace: requests that name none use it (CLI, account API keys). */
  active: boolean;
  /** `personal`, or the organization id (`org_…`). */
  id: string;
  /** personal | org */
  kind: string;
  /** Members (1 for personal). */
  members?: number;
  name: string;
  /** Your role: owner | admin | member (`owner` for personal). */
  role: string;
}

/** The operating system a sandbox runs. All come with the same tools. `omarchy` is Arch Linux with Omarchy's Hyprland desktop (a sandbox with a screen). `android` is Ubuntu 24.04 running Android 14 (Redroid, in a container) with adb connected on localhost:5600. Accepts the id or the distro's name ("debian"). */
export type Os = "ubuntu-24.04" | "ubuntu-26.04" | "debian-13" | "omarchy" | "android";

/** An OS sandboxes can start with: `GET /v1/images`. */
export interface OsImage {
  default: boolean;
  id: Os;
  name: string;
}

export interface PendingCapacity {
  from: number;
  slots: Array<CapacitySlot>;
}

/** A monthly plan (`GET /v1/billing`'s `plans`). Its price comes back as usage: it includes `included_hours` of a shared `default` sandbox (`included_usd` of usage at list prices), used first each month; the rest of the month's usage comes from the wallet. Unused time doesn't roll over. */
export interface Plan {
  /** Hours of a shared `default` sandbox included each month. */
  included_hours: number;
  /** The same, in dollars of usage at list prices (any size and CPU, and saved snapshots). */
  included_usd: number;
  /** Sandboxes running at once. */
  max_running: number;
  /** Saved snapshots kept free; each one more is billed per day. */
  saved_snapshots: number;
  /** Sizes it can start. */
  sizes: Array<Size>;
  starts_per_day: number;
  starts_per_hour: number;
  /** Starts included per minute, hour and day (more are paid from the wallet: `extra_starts`). */
  starts_per_minute: number;
  /** Its price and its id: `PUT /v1/billing/plan {"usd": 15}`. */
  usd: number;
}

/** The account's plan now. */
export interface PlanState {
  cancel_at_period_end: boolean;
  /** Usage included this period, and how much of it is used. */
  included_usd: number;
  /** This period, unix seconds. */
  period_start: number;
  /** When the period ends: the plan renews then (the card is charged and the included usage starts again), or ends if `cancel_at_period_end`. */
  renews_at: number;
  /** In its free trial: `trial_hours` of usage, at most `trial_max_running` at once, until `renews_at`, when the first month is charged (unless canceled). */
  trial: boolean;
  /** The plan (its price). */
  usd: number;
  used_usd: number;
}

/** One line of `GET /sandboxes/{name}/ports/watch` (NDJSON). `type`: `ready`, then `open` / `close` (`port`, `protocol` tcp) as TCP ports start or stop listening (the ones already listening come first as `open`), and last `end` (`reason`, `message`). */
export interface PortEvent {
  message?: string | null;
  port?: number | null;
  protocol?: string | null;
  reason?: string | null;
  type: string;
}

/** The answer to `POST /sandboxes/{name}/wait`. */
export interface PortWait {
  port: number;
  /** true: something listens on the port (on any address); false: the timeout passed first. */
  ready: boolean;
  /** How long it waited, in milliseconds. */
  waited_ms: number;
}

/** Inbound ports open on a sandbox (`GET /sandboxes/{name}/ports`): on its public IPv6 address as they are, and the explicitly opened ones also on a public port of its host's IPv4 address (`ipv4`). They stay open across stops and starts. */
export interface Ports {
  /** The ones open because a public URL serves that TCP port: they close with the URL (or when it's made private) unless they were also opened on their own. */
  from_urls?: Array<string>;
  /** Where the explicitly opened ports are reached over IPv4: sandboxes share their host's IPv4 address, so each gets a public port of its own there. Empty while stopped (a start gives them again, the same ones when it lands on the same host) and for public URLs' ports. */
  ipv4?: Array<Ipv4Port>;
  /** Why some opened ports have no IPv4 address (stopped, a limit reached, the host's range full). */
  ipv4_note?: string | null;
  /** Everything open besides SSH, as "8080/tcp" or "27015/udp", sorted. */
  ports: Array<string>;
}

/** A process in a sandbox (`GET /sandboxes/{name}/processes`), busiest first. */
export interface ProcessInfo {
  command: string;
  /** The history record of the command this process belongs to, if any. */
  command_id?: string | null;
  cpu_percent: number;
  memory_mb: number;
  pid: number;
  user: string;
}

/** `live`: false when the sandbox isn't running and this is the last sample kept (`sampled_at`). */
export interface ProcessList {
  live: boolean;
  processes: Array<ProcessInfo>;
  sampled_at?: number | null;
  total: number;
}

export interface ProcessRecord {
  /** Its command line (up to 1024 characters). */
  command: string;
  /** The first sample it was missing from: it ended between `last_seen_at` and this. None while it runs. */
  ended_at?: number | null;
  /** The last sample it was in. */
  last_seen_at: number;
  pid: number;
  ppid: number;
  /** Unix seconds (from its elapsed time when first seen). */
  started_at: number;
  user: string;
}

/** `GET /sandboxes/{name}/processes/records`: processes seen in the 30-second samples (monitoring on), kept 72 hours after they end, newest start first. A process that starts and ends between two samples isn't recorded. */
export interface ProcessRecords {
  records: Array<ProcessRecord>;
}

/** `GET /sandboxes/{name}/processes/samples`: the 12 busiest processes, sampled every 30 seconds while the sandbox runs and kept 7 days, newest first. */
export interface ProcessSamples {
  samples: Array<ProcessList>;
}

/** One prompt (a turn of a conversation). */
export interface Prompt {
  agent: string;
  /** Paths of its attachments in the sandbox. */
  attachments?: Array<string>;
  conversation_id: string;
  created_at: number;
  /** done, failed or interrupted. */
  done: boolean;
  effort?: string | null;
  /** Why it failed (failed prompts). */
  error?: string | null;
  /** e.g. provider_not_configured, timed_out, sandbox_stopped. */
  error_code?: string | null;
  exit_code?: number | null;
  fast?: boolean | null;
  finished_at?: number | null;
  id: string;
  model?: string | null;
  /** The prompt text (empty for a sandbox with monitoring off, once it started). */
  prompt: string;
  /** The agent's final answer (done prompts). */
  result?: string | null;
  sandbox: string;
  started_at?: number | null;
  /** queued | running | done | failed | interrupted */
  status: string;
}

/** A file sent with a prompt (`attachments`): saved in the sandbox under `~/attachments/<prompt id>/<name>`, and its path given to the agent. */
export interface PromptAttachment {
  /** The file's bytes, base64. */
  content_b64: string;
  /** File name (no directories), e.g. "error.png". */
  name: string;
}

export interface PromptList {
  prompts: Array<Prompt>;
}

export interface PromptRequest {
  /** The harness: claude (default), codex, gemini, opencode, pi, amp, cursor, prime, kimi or mistral. */
  agent?: string | null;
  /** Images, PDFs or other files for the agent: up to 12, 25 MB each, 64 MB in total. */
  attachments?: Array<PromptAttachment> | null;
  /** Continue this conversation (default: the sandbox's most recent one). */
  conversation_id?: string | null;
  /** Reasoning effort / thinking level, for harnesses that take one (claude, codex, pi, prime, kimi). */
  effort?: string | null;
  /** Fast mode (same model, faster output at the provider's fast rate): claude (Opus) and codex. false forces standard speed. */
  fast?: boolean | null;
  /** Passed to the harness's model flag, e.g. "opus", "gpt-6.1-sol", "anthropic/claude-sonnet-4-5" (`GET /provider-models`). */
  model?: string | null;
  /** Start a new conversation. */
  new?: boolean | null;
  prompt: string;
  timeout_secs?: number | null;
}

/** What `POST /sandboxes/{name}/prompt` (wait for the answer) returns. */
export interface PromptResult {
  conversation_id: string;
  /** 0 when the agent finished; 124 when it timed out. */
  exit_code: number;
  prompt_id: string;
  /** done | failed | interrupted | running (still running when the wait timed out) */
  status: string;
  /** Why it failed, if it did. */
  stderr: string;
  /** The agent's final answer. */
  stdout: string;
  timed_out: boolean;
}

/** One model of a harness in the catalog. */
export interface ProviderModel {
  /** Accepted `effort` levels (empty: none). */
  efforts: Array<string>;
  /** Takes `fast: true`. */
  fast_mode: boolean;
  id: string;
  title: string;
}

/** A harness and the models it accepts. */
export interface ProviderModels {
  /** The `agent` value. */
  agent: string;
  aliases: Array<string>;
  /** Takes model ids beyond `models` (e.g. `openrouter/…`, full model ids). */
  any_model: boolean;
  /** Effort levels of the harness. */
  efforts: Array<string>;
  /** Has a fast mode. */
  fast_mode: boolean;
  /** Env vars it runs on (any one). */
  keys: Array<string>;
  /** Model ids the harness listed in the sandbox (`?sandbox=`; harnesses that can list them). */
  live_models?: Array<string>;
  models: Array<ProviderModel>;
  /** Takes a message in the middle of a running turn (`steer`). */
  steer: boolean;
  /** Takes `model` at all. */
  takes_model: boolean;
  title: string;
}

/** A public HTTPS URL for a port inside a sandbox. */
export interface PublicUrl {
  created_at: number;
  port: number;
  /** false: only people with the token (in the URL, or the `__Host-froog_url` cookie) get through. */
  public?: boolean;
  /** A label for people, e.g. "API docs". */
  title?: string | null;
  /** For a private URL, includes `?_token=…`: treat it like a password. */
  url: string;
}

/** What a sandbox of a size costs a month in the account's setup, running 24/7. */
export interface Rate {
  /** Dedicated vCPUs (a physical core each), a month; 0 where the size isn't offered dedicated. */
  dedicated_usd?: number;
  /** Ephemeral with dedicated vCPUs, a month; 0 where the size isn't offered dedicated. */
  ephemeral_dedicated_usd?: number;
  /** Ephemeral (the disk erased on stop, no snapshots), shared vCPUs, a month. */
  ephemeral_shared_usd?: number;
  /** Free (the lite tier: one per account with a card, stopped when paying customers need room). */
  free?: boolean;
  /** Shared vCPUs, a month. */
  shared_usd: number;
  size: Size;
}

/** `POST …/messages/{id}/reply` and `…/reply-all`: the answer goes to the message's Reply-To (or From); reply-all adds its other recipients as cc. Subject `Re: …` and threading headers are set for you. */
export interface ReplyMessage {
  attachments?: Array<SendAttachment>;
  bcc?: Array<string>;
  cc?: Array<string>;
  headers?: Record<string, string>;
  html?: string | null;
  labels?: Array<string>;
  reply_to?: Array<string>;
  send_at?: number | null;
  text?: string | null;
  /** Instead of the usual recipients. */
  to?: Array<string>;
}

/** `POST /v1/billing/capacity/request`: join the waitlist for paid sandboxes with the setup you'd run and what it's for. */
export interface RequestCapacity {
  note?: string;
  slots: Array<CapacitySlot>;
}

export interface Restore {
  snapshot: string;
}

/** What the account pays for monitors (`GET /v1/revere/billing`). */
export interface RevereBilling {
  /** Whether the account has a live monitor subscription. */
  active: boolean;
  cancel_at_period_end?: boolean;
  /** The fastest interval a free monitor may have. */
  free_interval_secs: number;
  /** Free monitors per account. */
  free_monitors: number;
  period_end?: number | null;
  /** One paid monitor a month, in US cents. */
  price_cents: number;
  /** Whether this account pays for monitors (false: billing-exempt, or a server without payments). */
  required: boolean;
  /** Paid monitors paid for this period. */
  seats: number;
  status?: string | null;
  /** Paid monitors the account has now. */
  used: number;
}

/** Checks in one stretch of time. */
export interface RevereBucket {
  /** Where the bucket starts (unix seconds). */
  at: number;
  /** Response time of the checks that passed, in milliseconds. */
  avg_ms?: number | null;
  checks: number;
  max_ms?: number | null;
  /** Only in buckets shorter than a day. */
  min_ms?: number | null;
  /** Checks that passed. */
  ok: number;
}

/** One check of a monitor. */
export interface RevereCheck {
  at: number;
  /** `http`: the status code. */
  code?: number | null;
  error?: string | null;
  ms?: number | null;
  ok: boolean;
}

export interface RevereCheckList {
  /** Newest first. */
  checks: Array<RevereCheck>;
}

export interface RevereCheckout {
  quantity?: number | null;
}

/** Somewhere besides the account's email that hears when monitors go down and come back up: a Slack, Discord or Google Chat channel (its incoming-webhook URL), or an ntfy topic. */
export interface RevereContact {
  /** Hears about every monitor, new ones too (else only `monitors`). */
  all_monitors: boolean;
  created_at: number;
  id: string;
  /** `slack`, `discord`, `google_chat` or `ntfy`. */
  kind: string;
  last_error?: string | null;
  /** When the last message went (unix seconds), and why it failed if it did. */
  last_sent_at?: number | null;
  /** The monitors it hears about (ids), unless `all_monitors`. */
  monitors?: Array<string>;
  name: string;
  /** Paused: nothing is sent. */
  paused?: boolean;
  /** The incoming-webhook URL (Slack, Discord, Google Chat) or the topic URL (ntfy). */
  url: string;
}

export interface RevereContactList {
  contacts: Array<RevereContact>;
}

/** An HTTP request header a monitor sends. */
export interface RevereHeader {
  name: string;
  value: string;
}

/** `GET /v1/revere/monitors/{monitor}/history`: uptime and response times over a range, in buckets (24h: 48 of 30 minutes; 7d: 84 of 2 hours; 30d and 90d: one a day, UTC). */
export interface RevereHistory {
  avg_ms?: number | null;
  bucket_secs: number;
  /** Oldest first; every bucket of the range, empty ones too. */
  buckets: Array<RevereBucket>;
  /** Seconds down in the range (from outages). */
  down_secs: number;
  max_ms?: number | null;
  min_ms?: number | null;
  /** Outages in the range. */
  outages: number;
  /** `24h`, `7d`, `30d` or `90d`. */
  range: string;
  /** Percent of checks that passed over the range (none without checks). */
  uptime?: number | null;
}

/** Something froog checks: a URL (`http`), a port (`tcp`), a host answering ping (`icmp`), or a job that has to check in on time (`heartbeat`). */
export interface RevereMonitor {
  /** `http`: the request body (POST, PUT, PATCH). */
  body?: string | null;
  /** `http` over https: when the certificate expires (unix seconds), once seen. */
  cert_expires_at?: number | null;
  /** `http` over https: warn this many days before the certificate expires (0: never). */
  cert_warn_days?: number;
  /** Failed checks in a row before the monitor is down. */
  confirmations: number;
  created_at: number;
  /** Email the account when it goes down and comes back. */
  email: boolean;
  /** `http`: status codes that count as up, e.g. `200-299,301` (default `200-399`). */
  expect_status?: string | null;
  /** Counted against the free monitors (false: a paid one, because it checks faster than the free interval or the account is past its free monitors). */
  free: boolean;
  /** `heartbeat`: seconds of grace after `interval_secs` before it's down. */
  grace_secs?: number;
  /** `http`: request headers sent with every check (e.g. an `Authorization` for a health endpoint). */
  headers?: Array<RevereHeader>;
  /** `heartbeat`: the URL your job calls (GET or POST) to check in; `<url>/fail` reports a failure. */
  heartbeat_url?: string | null;
  /** The last 24 hours in 48 half-hour buckets, oldest first (`GET /v1/revere/monitors?history=true`). */
  history?: Array<RevereBucket> | null;
  id: string;
  /** Seconds between checks (heartbeat: the longest gap between check-ins). */
  interval_secs: number;
  /** `http`: text the body must contain (or, with `keyword_absent`, must not). */
  keyword?: string | null;
  keyword_absent?: boolean;
  /** `http`, `tcp`, `icmp` or `heartbeat`. */
  kind: string;
  last_checked_at?: number | null;
  /** Why the last check failed. */
  last_error?: string | null;
  /** The last check's response time in milliseconds. */
  last_ms?: number | null;
  /** Under maintenance now: a status page's maintenance window that names it is under way. Its alerts are held until the window ends. */
  maintenance?: boolean;
  /** `http`: the method (GET, HEAD or POST). */
  method?: string | null;
  /** Unique in the account. */
  name: string;
  /** `up`, `down`, `pending` (not checked yet) or `paused`. */
  status: string;
  /** When `status` last changed (unix seconds). */
  status_since: number;
  /** `http`: the URL. `tcp`: `host:port`. `icmp`: the host. `heartbeat`: empty. */
  target?: string;
  /** Seconds a check may take. */
  timeout_secs: number;
  /** Uptime over the last 24 hours, 7 days, 30 days and 90 days (percent; none without checks). */
  uptime?: RevereUptime | null;
}

export interface RevereMonitorList {
  monitors: Array<RevereMonitor>;
}

/** A time a monitor was down. */
export interface RevereOutage {
  /** None while it's still down. */
  ended_at?: number | null;
  id: string;
  /** It started during a maintenance window: no alerts were sent. */
  maintenance?: boolean;
  monitor: string;
  /** The first failed check's error. */
  reason: string;
  started_at: number;
}

export interface RevereOutageList {
  /** Newest first. */
  outages: Array<RevereOutage>;
}

export interface RevereUptime {
  day?: number | null;
  month?: number | null;
  quarter?: number | null;
  week?: number | null;
}

/** Sandboxes at once from this much money added. */
export interface RunningTier {
  max_running: number;
  topped_up_usd: number;
}

export interface Sandbox {
  /** In an organization: what you may do with it. `owner` (you created it), `use` (a shared sandbox) or `view` (a teammate's private sandbox: see it and its usage). */
  access?: string | null;
  /** Adaptive CPU: it runs on its size's vCPUs (the floor, which its setup slot pays for) and grows live up to `max_vcpus` while it's busy, shrinking back when idle. Time above the floor is billed per vCPU-second from the wallet (usage backend `burst`). Memory stays the size's. */
  adaptive?: boolean;
  /** While stopped, a request to one of its public URLs, or an exec, file, job or wait call, starts it (billed and limited like any start). */
  auto_start?: boolean;
  /** While running with an auto-stop timer: when it stops (unix seconds). A running agent prompt moves it one `ttl_secs` later; `PATCH ttl_secs` sets it to now + ttl_secs. */
  auto_stop_at?: number | null;
  backend: string;
  /** `shared` or `dedicated` vCPUs (fixed when it's created). */
  cpu?: Cpu;
  /** Unix seconds. */
  created_at: number;
  /** In an organization: the email of the member who created it (absent for personal sandboxes and for those the organization made itself, such as CI jobs). */
  created_by?: string | null;
  /** Deleted after staying stopped this many seconds. 0 = never. */
  delete_after_secs?: number;
  /** While stopped with `delete_after_secs`: when it will be deleted (unix seconds). */
  delete_at?: number | null;
  /** The desktop's frame rate: 60 (included) or 120 (`desktop_fps`, metered while a viewer is connected, from the wallet). 120 needs 4 or more vCPUs; on fewer the desktop runs at 60. */
  desktop_fps?: number;
  /** Set once the disk of a stopped sandbox was deleted; start and fork then fail. */
  disk_expired?: boolean;
  /** For a stopped sandbox: when its disk will be deleted (save a snapshot to keep it longer). */
  disk_expires_at?: number | null;
  /** Disk use of a running sandbox in percent (checked every 30 seconds). */
  disk_used_percent?: number | null;
  /** Names of its own environment variables (values are never returned). */
  env?: Array<string>;
  /** false: it runs without its environment (`--no-environment`). */
  environment?: boolean;
  /** The environment it belongs to (`default` unless it was created with another), also when it runs without it (`environment: false`). */
  environment_name?: string | null;
  /** The version of that environment it is on: the latest when it was created; it moves only with `POST /environments/{env}/upgrade` (or a start with `environment_name`). */
  environment_version?: number | null;
  error?: string | null;
  /** A deadline: deleted at this time (unix seconds) whatever its state, like a TTL from creation (`expires_in_secs`). Saved snapshots stay. */
  expires_at?: number | null;
  /** Where its disk came from, when it was forked or started from a saved snapshot (absent for new sandboxes, ones from a share code, and those made before this was recorded). */
  forked_from?: SandboxOrigin | null;
  ipv4?: string | null;
  /** Its own public IPv6 address (inbound: SSH and its open ports, `/sandboxes/{name}/ports`). None while stopped; it can change at a start (not at a warm resume). */
  ipv6?: string | null;
  /** Your own key-value tags (`label=key=value` filters lists). */
  labels?: Record<string, string>;
  last_active_at: number;
  /** When its operating system last booted: a start from its disk, a restart after a crash or a host restart, or a reboot inside it (a warm resume isn't a reboot). Unix seconds. */
  last_reboot?: number | null;
  /** Stopped this many seconds after each start, busy or not. 0 = no limit. */
  max_lifetime_secs?: number;
  /** Adaptive sandboxes: the most vCPUs it may grow to (the guest sees this many CPUs from boot). */
  max_vcpus?: number | null;
  /** false: no command history or process samples. */
  monitoring?: boolean;
  name: string;
  os?: Os;
  /** What its running time cost in the current billing period, at list prices (in lists and info; saved snapshots are billed per account, not here). */
  period_cost_usd?: number | null;
  /** While creating or starting: what takes the time, e.g. copying its disk from another host. */
  progress?: string | null;
  /** The repo cloned into this sandbox at create (`CreateSandbox.repo`). */
  repo?: SandboxRepo | null;
  /** Why setup failed: its error lines (a failed clone, a script's exit code). */
  setup_error?: string | null;
  /** The setup job (repos, the environment's setup script, `new --setup`) of the last boot: none | running | done | failed. */
  setup_status?: string;
  size: Size;
  /** false: never snapshotted; a stop erases it (no start, fork or restore). */
  snapshots?: boolean;
  /** SSH port at `ipv4` (VMs on a shared host each have their own). */
  ssh_port?: number;
  started_at?: number | null;
  state: State;
  /** While running with `max_lifetime_secs`: when it will be stopped (unix seconds). */
  stop_at?: number | null;
  /** Why the stop was refused: the last snapshot error. */
  stop_error?: string | null;
  /** Only in the answer to `POST /sandboxes/{name}/stop`: the stop's id, for `GET /stops/{id}`. */
  stop_id?: string | null;
  /** Set while a stop is refused because its snapshot failed: since when. The sandbox keeps running, unbilled, and froog retries the stop until a snapshot works (a forced stop after 3 days); a start cancels the stop. */
  stop_refused_at?: number | null;
  /** The auto-stop timer: it stops this many seconds after each start (or resume), busy or not, unless an agent prompt is running. 0 = no auto-stop. */
  ttl_secs: number;
  /** Set while a running sandbox doesn't answer (commands and SSH hang): since when. Billing pauses meanwhile; after 3 days it's stopped onto its last snapshot. */
  unresponsive_since?: number | null;
  /** Adaptive sandboxes, while running: the vCPUs it has now (read each minute). */
  vcpus_now?: number | null;
  /** In an organization: `shared` (every member can use it) or `private` (only its creator). */
  visibility?: string | null;
  /** Stopped, with its memory kept until then: a start before it resumes every running program in about a second (after it, the start boots from the disk snapshot). */
  warm_until?: number | null;
}

/** One sandbox's AI settings and usage (`GET /v1/sandboxes/{name}/ai`). */
export interface SandboxAi {
  /** Its AI requests are refused. */
  blocked: boolean;
  days: number;
  /** The profile it uses (its own, its environment's, or the default). */
  profile?: string | null;
  /** Set on the sandbox itself (else it follows its environment). */
  profile_set: boolean;
  /** It holds placeholders now (the proxy was on at its last start). */
  proxied: boolean;
  sandbox: string;
  totals: AiTotals;
  usage: Array<AiUsageRow>;
}

/** `GET /sandboxes/{name}/metrics`: one sample read from the running sandbox now. */
export interface SandboxMetrics {
  cpu_count: number;
  /** Share of all CPUs busy over half a second (0-100). */
  cpu_percent: number;
  disk_total_bytes: number;
  /** Of the root filesystem. */
  disk_used_bytes: number;
  /** Share of the last minute some task waited for disk I/O (0-1). */
  io_pressure: number;
  memory_total_bytes: number;
  memory_used_bytes: number;
  /** Received and sent since boot, all interfaces but loopback. */
  network_rx_bytes: number;
  network_tx_bytes: number;
  /** Unix seconds. */
  sampled_at: number;
}

/** `Sandbox.forked_from`: the sandbox and snapshot a fork (or a start from a saved snapshot) copied its disk from. */
export interface SandboxOrigin {
  /** Unix seconds: when the copy was made. */
  at: number;
  /** The snapshot's name, when it has one. */
  label?: string | null;
  /** The source sandbox's name (it may have been deleted or renamed since). */
  sandbox: string;
  /** The snapshot's id (`snap_…`); absent for a fork of the source's state at that moment. */
  snapshot?: string | null;
}

/** A repo cloned into one sandbox (`CreateSandbox.repo`), like the account's repos: at boot, when the directory has no checkout yet. Credentials come from the sandbox's environment (`GH_TOKEN`, `~/.git-credentials`), never the URL. */
export interface SandboxRepo {
  /** Branch or tag to check out (default: the repo's default branch). */
  branch?: string | null;
  /** Directory relative to the home directory (default: the repo's name). */
  dir?: string | null;
  /** `https://`, `ssh://` or `git@` URL. */
  url: string;
}

/** `GET /sandboxes/{name}/usage`: one sandbox's running time and cost in a window. */
export interface SandboxUsage {
  /** At list prices (saved snapshots are billed per account, not here). */
  cost_usd: number;
  /** The window, unix seconds (`to` is at most now). */
  from: number;
  /** One line per size it ran at. */
  lines: Array<UsageLine>;
  name: string;
  /** Running time in the window, billed per second. */
  seconds: number;
  to: number;
}

/** A saved snapshot of the account (`GET /saved-snapshots`): a template for `new --from NAME`. It outlives its source sandbox. */
export interface SavedSnapshot {
  created_at: number;
  id: string;
  name: string;
  /** A copy is kept off the host, on separate storage (encrypted). */
  offsite?: boolean;
  os: Os;
  /** It came from another account's share code (`new --from fsh_…`); `source` is the code's id. */
  shared?: boolean;
  size: Size;
  size_gb?: number | null;
  /** The sandbox it was saved from. */
  source: string;
  /** The source sandbox was deleted (the saved snapshot stays). */
  source_deleted: boolean;
  /** creating | available */
  status: string;
}

/** Saved snapshots included and how many the account keeps (`GET /limits`). */
export interface SavedSnapshotAllowance {
  /** Above the included ones, billed per day. */
  extra: number;
  included: number;
  price_per_extra_day_usd: number;
  /** Saved snapshots (names) the account keeps now. */
  used: number;
}

/** `GET /v1/seaeye/analytics?days=&repo=`: what the account's jobs add up to. */
export interface SeaeyeAnalytics {
  days: number;
  /** Tests that both failed and passed on the same commit. */
  flaky_tests: Array<SeaeyeFlakyTest>;
  /** One row per repository, workflow and job name; most job time first. */
  jobs: Array<SeaeyeJobStats>;
  /** Most job time first. */
  repos: Array<SeaeyeRepoStats>;
  since: number;
}

export interface SeaeyeCache {
  /** The name in `/cache=<name>`. */
  name: string;
  /** When the last default-branch job saved it. */
  saved_at: number;
  /** What it adds to the base image, in GB. */
  size_gb?: number | null;
  /** Its saved snapshot (`cache-<name>`): `DELETE /v1/saved-snapshots/{snapshot}` starts it over. */
  snapshot: string;
}

export interface SeaeyeFacet {
  name: string;
  runs: number;
}

export interface SeaeyeFlakyTest {
  /** Commits it both failed and passed on. */
  commits: number;
  failed: number;
  last_failed_at: number;
  message?: string | null;
  name: string;
  passed: number;
  repo: string;
  suite?: string | null;
}

/** One GitHub Actions job (`GET /v1/seaeye`, `GET /v1/seaeye/jobs/{id}`). */
export interface SeaeyeJob {
  /** With `/cache=`: whether its VM started from the saved cache (false: a cold start). */
  cache_hit?: boolean | null;
  /** GitHub's conclusion once completed: success | failure | cancelled | … */
  conclusion?: string | null;
  /** What its job time costs at the CI price (so far, while it runs). */
  cost_usd?: number | null;
  finished_at?: number | null;
  /** GitHub's job id. */
  github_job_id: number;
  /** The branch the run is for (GitHub's `head_branch`). */
  head_branch?: string | null;
  /** The commit the run is for. */
  head_sha?: string | null;
  html_url?: string | null;
  /** `seaeye_…` */
  id: string;
  job_name: string;
  /** The job's `runs-on` labels. */
  labels: Array<string>;
  queued_at: number;
  /** Why it waits, or why it didn't run. */
  reason?: string | null;
  /** owner/name */
  repo: string;
  /** CPU and memory the job used, once it completed (from the VM's 30-second samples). */
  resources?: SeaeyeResources | null;
  run_id: number;
  /** Seconds the job ran (its billed job time). */
  run_secs?: number | null;
  /** The sandbox that runs it (`seaeye-<repo>-<job id>`). */
  sandbox?: string | null;
  size: Size;
  started_at?: number | null;
  /** queued (waiting for a sandbox) | starting | running | completed | refused | failed */
  state: string;
  /** Test results from the JUnit XML files the job wrote, once it completed. */
  tests?: SeaeyeTestSummary | null;
  /** Seconds from queued to the sandbox running. */
  wait_secs?: number | null;
  workflow?: string | null;
}

/** `GET /v1/seaeye/jobs/{id}/metrics`: the job's CPU and memory over time, and its steps. */
export interface SeaeyeJobMetrics {
  /** Averaged into at most 120 buckets, oldest first. */
  points: Array<MetricsPoint>;
  resources?: SeaeyeResources | null;
  /** The job's steps, from GitHub, with their times. */
  steps: Array<SeaeyeStep>;
}

export interface SeaeyeJobStats {
  /** A better size for it, when the runs say so. */
  advice?: SeaeyeSizeAdvice | null;
  /** With `/cache=`: the share of runs that started from the cache (0-1). */
  cache_hit_rate?: number | null;
  cancelled: number;
  cost_usd: number;
  /** Average of the runs' CPU averages. */
  cpu_avg_percent?: number | null;
  failed: number;
  failure_rate: number;
  job_name: string;
  /** Highest memory any run used, as a share of its VM's. */
  memory_peak_percent?: number | null;
  minutes: number;
  /** Runs in which the kernel killed a process for want of memory. */
  oom_runs: number;
  p50_secs?: number | null;
  p90_secs?: number | null;
  repo: string;
  runs: number;
  /** The size of its latest run. */
  size: Size;
  /** Its slowest steps (by p50 over the runs), at most 5. */
  slow_steps?: Array<SeaeyeStepStats>;
  succeeded: number;
  /** Queued to running. */
  wait_p50_secs?: number | null;
  wait_p90_secs?: number | null;
  workflow?: string | null;
}

/** `GET /v1/seaeye/jobs/{id}/tests`. */
export interface SeaeyeJobTests {
  /** None: the job wrote no JUnit XML froog found. */
  summary?: SeaeyeTestSummary | null;
  /** Failed first, then skipped, then passed; at most 1,000. */
  tests: Array<SeaeyeTestCase>;
}

export interface SeaeyeLogMatch {
  /** The line's time, from GitHub's timestamp. */
  at?: string | null;
  branch?: string | null;
  conclusion?: string | null;
  job_id: string;
  job_name: string;
  /** 1-based line number in the job's log. */
  line: number;
  queued_at: number;
  repo: string;
  /** The step the line is in (from the log's `##[group]` markers). */
  step?: string | null;
  /** The line without its timestamp (first 500 characters). */
  text: string;
  workflow?: string | null;
}

/** `GET /v1/seaeye/logs/search?q=&days=&limit=&order=`: lines of the account's kept CI job logs. */
export interface SeaeyeLogSearch {
  /** Jobs whose logs were searched. */
  jobs_searched: number;
  /** Newest job first (`order=oldest`: oldest first, for where a failure first appeared). */
  matches: Array<SeaeyeLogMatch>;
  query: string;
  /** More lines matched than `limit`. */
  truncated: boolean;
}

/** A CI monitor (`GET/POST /v1/seaeye/monitors`): an alert when matching jobs fail or run long. */
export interface SeaeyeMonitor {
  /** Only runs for this branch. */
  branch?: string | null;
  /** failure: alert after this many failures in a row (a success starts over). */
  consecutive: number;
  /** No second alert from this monitor for this long. */
  cooldown_mins: number;
  created_at: number;
  /** duration: alert when a job has run this long. */
  duration_secs?: number | null;
  /** Email the account (webhooks listing `seaeye.monitor.triggered` get it either way). */
  email: boolean;
  /** `cim_…` */
  id: string;
  /** Only jobs whose name contains this. */
  job?: string | null;
  /** failure (a job failed or timed out) | duration (a job ran longer than `duration_secs`) */
  kind: string;
  last_triggered_at?: number | null;
  /** failure: only failures whose log contains this (any case), e.g. `OutOfMemory` or `SIGKILL`. */
  log_pattern?: string | null;
  name: string;
  /** Its last alerts, newest first (at most 10). */
  recent?: Array<SeaeyeMonitorEvent>;
  /** Only this repository (owner/name). */
  repo?: string | null;
  /** Failures in a row so far. */
  streak: number;
  /** Only workflows whose name contains this. */
  workflow?: string | null;
}

export interface SeaeyeMonitorEvent {
  at: number;
  job_id: string;
  reason: string;
}

/** `GET /v1/seaeye`. */
export interface SeaeyeOverview {
  /** The account's caches (`/cache=<name>`: saved snapshots named `cache-<name>`). */
  caches?: Array<SeaeyeCache>;
  /** This server takes CI jobs (a GitHub App with a webhook secret is set up). */
  configured: boolean;
  /** The account has a linked installation. */
  connected: boolean;
  /** Newest first. */
  jobs: Array<SeaeyeJob>;
  /** `runs-on` label: `<label>-small`, `<label>`, `<label>-large`, `<label>-xlarge` (or `<label>-2vcpu` ... `-16vcpu`), plus `/from=<saved snapshot>`, `/cache=<name>` and `/debug`. */
  label: string;
  /** CI job time in the current billing period. */
  period?: SeaeyePeriod;
  /** The CI price: dollars per vCPU per minute of job time. */
  price_per_vcpu_minute?: number;
  /** Jobs from public repositories run (off by default). */
  public_repos: boolean;
  /** When public repositories are on: the GitHub users whose runs may use froog (empty = anyone). */
  public_users: Array<string>;
  /** Last 7 days. */
  stats: SeaeyeStats;
}

export interface SeaeyePeriod {
  cost_usd: number;
  /** Start of the billing period. */
  from: number;
  minutes: number;
}

export interface SeaeyeRepoStats {
  cost_usd: number;
  failed: number;
  /** failed / finished runs (0-1). */
  failure_rate: number;
  minutes: number;
  repo: string;
  runs: number;
}

/** What one job used of its VM. */
export interface SeaeyeResources {
  /** Average share of all vCPUs busy while the job ran. */
  cpu_avg_percent?: number | null;
  /** Busiest 30 seconds. */
  cpu_peak_percent?: number | null;
  memory_peak_mb?: number | null;
  memory_total_mb?: number | null;
  /** Processes the kernel killed for want of memory during the job. */
  oom_kills?: number;
}

/** One GitHub Actions workflow run: the jobs of one run that ran on froog (`GET /v1/seaeye/runs`, `GET /v1/seaeye/runs/{run_id}`). */
export interface SeaeyeRun {
  /** The GitHub user who started it. */
  actor?: string | null;
  /** What its jobs' time costs. */
  cost_usd?: number;
  /** First job started to last job finished (so far, while it runs). */
  duration_secs?: number | null;
  /** What started it: push, pull_request, schedule, workflow_dispatch, ... */
  event?: string | null;
  head_branch?: string | null;
  head_sha?: string | null;
  /** The run on GitHub. */
  html_url?: string | null;
  /** Its jobs on froog, oldest first. */
  jobs: Array<SeaeyeJob>;
  /** The workflow file, e.g. `.github/workflows/ci.yml`. */
  path?: string | null;
  /** When its first job was queued. */
  queued_at: number;
  /** owner/name */
  repo: string;
  /** GitHub's run id. */
  run_id: number;
  /** The run's number in its workflow (`#250`). */
  run_number?: number | null;
  /** GitHub's title for the run: the head commit's message, or the pull request's title. */
  title?: string | null;
  workflow?: string | null;
}

/** `GET /v1/seaeye/runs`: one page of runs, newest first, and what the filters can pick from. */
export interface SeaeyeRunList {
  branches: Array<string>;
  repos: Array<string>;
  runs: Array<SeaeyeRun>;
  /** Runs that match the filters, on every page. */
  total: number;
  /** The account's workflows (every run, not only the filtered ones), with their run counts. */
  workflows: Array<SeaeyeFacet>;
}

/** `PUT /v1/seaeye/settings`. */
export interface SeaeyeSettings {
  public_repos: boolean;
  /** GitHub logins; empty = anyone (only with public_repos). */
  public_users?: Array<string>;
}

export interface SeaeyeSizeAdvice {
  /** cost | speed | memory */
  kind: string;
  /** The `runs-on` label for it. */
  label: string;
  size: Size;
  why: string;
}

export interface SeaeyeStats {
  failed: number;
  jobs: number;
  refused: number;
  run_secs: number;
  succeeded: number;
}

export interface SeaeyeStep {
  completed_at?: number | null;
  conclusion?: string | null;
  name: string;
  number: number;
  secs?: number | null;
  started_at?: number | null;
}

export interface SeaeyeStepStats {
  name: string;
  p50_secs: number;
  p90_secs: number;
  runs: number;
}

export interface SeaeyeTestCase {
  /** The failure's message (first 500 characters). */
  message?: string | null;
  name: string;
  secs?: number | null;
  /** passed | failed | skipped */
  status: string;
  /** The JUnit `classname` (or the suite's name). */
  suite?: string | null;
}

export interface SeaeyeTestSummary {
  failed: number;
  passed: number;
  skipped: number;
  total: number;
}

/** An attachment to send: the bytes base64-encoded. 10 MB in all per message. */
export interface SendAttachment {
  /** Base64. */
  content: string;
  /** Shown in the HTML body as `cid:<content_id>` rather than attached. */
  content_id?: string | null;
  /** Default: from the filename's extension. */
  content_type?: string | null;
  filename: string;
}

/** `POST /v1/inboxes/{inbox}/messages/send`. Up to 50 recipients in to, cc and bcc together. */
export interface SendMessage {
  attachments?: Array<SendAttachment>;
  bcc?: Array<string>;
  cc?: Array<string>;
  /** Extra headers (`X-…` and `List-Unsubscribe…` only). */
  headers?: Record<string, string>;
  html?: string | null;
  /** Your labels for the sent message. */
  labels?: Array<string>;
  reply_to?: Array<string>;
  /** Send later (unix seconds): it's kept as a scheduled draft until then. */
  send_at?: number | null;
  subject?: string;
  /** At least one of `text` and `html`. */
  text?: string | null;
  to?: Array<string>;
}

/** What a send returns: the message as stored in the inbox (label `sent`, `delivery: queued`), or the scheduled draft when `send_at` is in the future. */
export interface SendResult {
  draft?: Draft | null;
  message?: InboxMessage | null;
}

/** `PATCH /orgs/active`. */
export interface SetActiveOrg {
  /** An organization id or name, or `personal`. */
  org: string;
}

/** Which environment's sandboxes get which profile (`PUT /v1/ai/environments/{env}`). */
export interface SetAiEnvironmentProfile {
  /** A profile name or id; null: the account's default profile. */
  profile?: string | null;
}

/** `PUT /v1/billing/capacity`: the whole setup (sizes left out are 0). */
export interface SetCapacity {
  slots: Array<CapacitySlot>;
}

/** `PUT /environment/files` */
export interface SetEnvFile {
  content: string;
  path: string;
}

export interface SetEnvVar {
  value: string;
}

/** `PUT /v1/billing/extra-starts`. */
export interface SetExtraStarts {
  enabled: boolean;
}

/** `PUT …/forwarding`: the whole list (up to 5). */
export interface SetForwarding {
  destinations: Array<string>;
}

/** `PUT /v1/billing/plan`: choose a plan, or change to another (applies now: the card is charged the new plan's price and a new month starts; the old period's unused time is dropped). */
export interface SetPlan {
  /** Skip (or end) the free trial: charge the first month now. */
  skip_trial?: boolean;
  /** The plan's price, e.g. 15 (`Billing.plans`). */
  usd: number;
}

/** `PUT /sandboxes/{name}/ports`: the ports to open, replacing the ones opened before ("8080/tcp", "27015/udp"; a bare number is TCP). Public URLs' ports stay open regardless. */
export interface SetPorts {
  ports: Array<string>;
}

/** `PUT /v1/account/primary`: the connection whose address gets the account's emails. */
export interface SetPrimary {
  /** A connection id (`con_…`). */
  connection: string;
}

/** `PUT /orgs/{org}/seats`. */
export interface SetSeats {
  seats: number;
}

/** `PUT /telemetry`: the collector's base URL (froog adds /v1/metrics and /v1/logs) and the headers your vendor needs, e.g. `{"dd-api-key": "…"}`. */
export interface SetTelemetry {
  endpoint: string;
  headers?: Record<string, string>;
}

/** `PUT /v1/github/token-repos`: limit the token in each sandbox to these repositories. */
export interface SetTokenRepos {
  /** `owner/name`; empty = every repository the app can see. */
  repos: Array<string>;
}

/** Machine sizes. Mapped to provider server types by the server's config. */
export type Size = "small" | "default" | "large" | "xlarge" | "lite" | "standard";

export interface Snapshot {
  created_at: number;
  id: string;
  label?: string | null;
  /** A copy is kept off the host, on separate storage (encrypted), so the snapshot survives the loss of the machine. Usually true within minutes of the snapshot being taken. */
  offsite?: boolean;
  /** The sandbox it belongs to (in account-wide lists and single lookups). */
  sandbox?: string | null;
  /** Saved snapshots are kept until deleted and billed per day; automatic ones are free. */
  saved: boolean;
  size_gb?: number | null;
  status: string;
}

/** A share code of a saved snapshot, as listed (`GET /saved-snapshots/{name}/shares`). The code itself is shown only once, when it's made. */
export interface SnapshotShare {
  created_at: number;
  /** `shr_…` */
  id: string;
  last_used_at?: number | null;
  /** The saved snapshot's name. */
  name: string;
  /** Set once revoked: the code creates nothing any more. */
  revoked_at?: number | null;
  /** Sandboxes created from it so far. */
  uses: number;
}

/** `PUT /v1/billing/spend-cap`: the most to spend in a calendar month. None removes the cap. */
export interface SpendCap {
  usd?: number | null;
}

export interface SshInfo {
  host: string;
  /** OpenSSH public host key line, to pin in known_hosts. */
  host_key: string;
  port: number;
  user: string;
}

export interface SshKey {
  created_at: number;
  id: string;
  name: string;
  public_key: string;
}

/** Starts up to `up_to` times the included number cost `price_usd` each. */
export interface StartBracket {
  price_usd: number;
  up_to: number;
}

/** `POST /v1/inboxes/forwarding/verifications`: email a code to the address. */
export interface StartForwardingVerification {
  destination: string;
}

/** Sandbox starts (create, start, fork, restore) allowed per window; 0 = no limit. */
export interface StartLimits {
  per_day: number;
  per_hour: number;
  per_minute: number;
  used_day: number;
  used_hour: number;
  used_minute: number;
}

/** Optional body of `POST /sandboxes/{name}/start`. */
export interface StartSandbox {
  /** Turn adaptive CPU on or off (`CreateSandbox.adaptive`; kept for later starts). Default: as before. With `size`, the floor moves to the new size's vCPUs. */
  adaptive?: boolean | null;
  /** Environment variables set on top of the sandbox's own (these win; kept). */
  env?: Record<string, string> | null;
  /** false: boot without the account's environment (env vars, repos, secret files, setup script, in-sandbox CLI key); true: with it. Default: as before. Kept for later starts. */
  environment?: boolean | null;
  /** Move it to this environment's latest version (it also gets the environment again). */
  environment_name?: string | null;
  /** Adaptive: a new ceiling (implies `adaptive: true`). Default: as before. */
  max_vcpus?: number | null;
  /** Start at a different size. */
  size?: Size | null;
  /** A new auto-stop timer in seconds (0 = no auto-stop). Default: keep it. */
  ttl_secs?: number | null;
}

export interface StartSubscriptionLogin {
  /** A running sandbox to run the sign-in in (it runs `claude setup-token` or `codex login --device-auth` there; nothing is left behind). */
  sandbox: string;
}

/** The one-time credit for adding a card: once per account and once per card, and only before the first payment. */
export interface StartingCredit {
  /** Adding a card now would give it. */
  available: boolean;
  /** This account got it. */
  granted: boolean;
  usd: number;
}

export type State = "creating" | "running" | "stopping" | "stopped" | "starting" | "restoring" | "deleting" | "deleted" | "error";

/** A custom domain for a status page, and the DNS records it needs. */
export interface StatusDomain {
  checked_at?: number | null;
  domain: string;
  /** Records to publish: the CNAME (serves the page) and the TXT (proves it's yours). */
  records: Array<DnsRecord>;
  /** `pending` until the TXT record is found, then `verified`. */
  status: string;
  verified_at?: number | null;
}

/** An incident or a maintenance window on a status page. */
export interface StatusIncident {
  /** Opened by a monitor going down (`auto_incidents`). */
  automatic?: boolean;
  created_at: number;
  ends_at?: number | null;
  id: string;
  /** `minor`, `major` or `critical` (maintenance: `maintenance`). */
  impact: string;
  /** `incident` or `maintenance`. */
  kind: string;
  /** Monitors it affects (ids). */
  monitors?: Array<string>;
  page: string;
  resolved_at?: number | null;
  /** Maintenance: when it starts and ends. */
  starts_at?: number | null;
  /** Incident: `investigating`, `identified`, `monitoring`, `resolved`. Maintenance: `scheduled`, `in_progress`, `completed`. */
  status: string;
  title: string;
  /** Oldest first. */
  updates: Array<StatusIncidentUpdate>;
}

export interface StatusIncidentList {
  /** Newest first. */
  incidents: Array<StatusIncident>;
}

export interface StatusIncidentUpdate {
  at: number;
  body: string;
  id: string;
  status: string;
}

/** A public status page (`https://status.froogusercontent.com/<slug>`, or your own domain). */
export interface StatusPage {
  /** A monitor going down opens an incident on the page; it resolves when the monitor is up. */
  auto_incidents: boolean;
  created_at: number;
  custom_domain?: StatusDomain | null;
  description?: string;
  /** The "back to the site" link on the page. */
  homepage_url?: string | null;
  id: string;
  /** The monitors it shows, in order. */
  monitors: Array<StatusPageMonitor>;
  /** Its address: lowercase letters, digits and dashes. */
  slug: string;
  /** Visitors may subscribe to incident updates by email. */
  subscribers_enabled: boolean;
  title: string;
  /** The page's public URL (the custom domain once it's verified). */
  url: string;
}

export interface StatusPageList {
  pages: Array<StatusPage>;
}

export interface StatusPageMonitor {
  /** The name shown on the page (default: the monitor's name). */
  label?: string | null;
  /** The monitor's id. */
  monitor: string;
}

/** Someone subscribed to a status page's updates by email. */
export interface StatusSubscriber {
  /** False until they open the link in the confirmation email. */
  confirmed: boolean;
  created_at: number;
  email: string;
  id: string;
}

export interface StatusSubscriberList {
  subscribers: Array<StatusSubscriber>;
}

export interface SteerRequest {
  /** The conversation to steer (default: the sandbox's current one). */
  conversation_id?: string | null;
  message: string;
}

export interface SteerResult {
  conversation_id: string;
  /** `native`: added to the running turn. `queued`: the harness can't take a message mid-turn, so it runs as the next turn of the same conversation (`queued_prompt_id`). */
  mode: string;
  /** The harness took the message into the running turn. */
  native: boolean;
  /** The running prompt the message went to. */
  prompt_id: string;
  queued_prompt_id?: string | null;
}

/** A stop (`GET /stops/{id}`): `POST /sandboxes/{name}/stop` returns its id, and an idle or billing stop gets one too. Stopping again while one is pending returns the same id. */
export interface Stop {
  ended_at?: number | null;
  error?: string | null;
  /** `stop_…` */
  id: string;
  /** Unix seconds. */
  requested_at: number;
  /** The sandbox's name. */
  sandbox: string;
  /** pending (snapshotting and shutting down) | failing (its snapshot failed, see `error`: the sandbox keeps running, unbilled, and froog retries this stop) | completed (stopped, or erased when it had snapshots off) | superseded (a start cancelled a failing stop) | failed (see `error`; the sandbox is in the error state, a start retries from its last snapshot). */
  status: string;
}

/** Optional body of `POST /sandboxes/{name}/stop`. */
export interface StopSandbox {
  /** Stop even when the stop snapshot fails: the sandbox then keeps its last good snapshot and loses what was written after it. Skips `~/.froog/pre-stop` and everything that needs the sandbox to answer, so it also stops one that's hung. */
  force?: boolean;
}

/** A subscription sign-in (Claude Pro/Max for Claude Code, ChatGPT for Codex). */
export interface Subscription {
  /** The harness it signs in. */
  agent: string;
  connected: boolean;
  connected_at?: number | null;
  /** A sign-in in progress. */
  login?: SubscriptionLogin | null;
  /** claude | chatgpt */
  provider: string;
  title: string;
}

export interface SubscriptionCode {
  code: string;
}

/** A sign-in in progress: open `url`, then (Claude) paste the code shown back with `POST …/login/code`, or (ChatGPT) enter `user_code` on that page. */
export interface SubscriptionLogin {
  error?: string | null;
  /** Paste the code the vendor's page shows into `POST …/login/code`. */
  needs_code: boolean;
  provider: string;
  /** The sandbox the vendor's own CLI runs the sign-in in. */
  sandbox: string;
  started_at: number;
  /** starting | waiting_for_user | connected | failed */
  status: string;
  url?: string | null;
  user_code?: string | null;
}

/** `GET /telemetry`: the account's OpenTelemetry endpoint (header values are never returned). */
export interface Telemetry {
  endpoint: string;
  /** Header names only. */
  headers: Array<string>;
  last_error?: string | null;
  last_export_at?: number | null;
}

export interface TelemetrySaved {
  telemetry: Telemetry;
  test: TelemetryTest;
}

/** The collector's answer to the test export sent on save. */
export interface TelemetryTest {
  message?: string | null;
  ok: boolean;
  status?: number | null;
}

/** `POST /orgs/{org}/transfer`. */
export interface TransferOrg {
  /** The new owner: a member's id or email. */
  member: string;
}

/** The free trial of the first plan: card required, once per account and per card. */
export interface Trial {
  /** Choosing a plan now would start with the trial. */
  available: boolean;
  days: number;
  /** Hours of a shared `default` sandbox (its usage in dollars: `usd`). */
  hours: number;
  max_running: number;
  sizes: Array<Size>;
  usd: number;
}

export interface UpdateAiProfile {
  /** true: make it the account's default profile. */
  default?: boolean | null;
  /** Rename. */
  name?: string | null;
}

/** Change the proxy settings (`PUT /v1/ai/proxy`); fields left out stay. */
export interface UpdateAiProxy {
  blocked?: boolean | null;
  enabled?: boolean | null;
  withhold_subscriptions?: boolean | null;
}

/** `PATCH /v1/account/alerts`: `{"emails": {"plan_nudge": false}, "auto_rebuild": true}`; kinds left out stay as they are. */
export interface UpdateAlertSettings {
  auto_rebuild?: boolean | null;
  emails?: Record<string, boolean>;
}

export interface UpdateDataRetention {
  /** Turning zero data retention on erases the data of every stopped sandbox: send "delete stopped sandbox data" to confirm. */
  confirmation?: string | null;
  monitoring_off?: boolean | null;
  snapshots_off?: boolean | null;
  zero_data_retention?: boolean | null;
}

/** `PATCH …/drafts/{id}`. Fields left out stay; `send_at: null` unschedules. */
export interface UpdateDraft {
  add_attachments?: Array<SendAttachment>;
  add_labels?: Array<string>;
  bcc?: Array<string> | null;
  cc?: Array<string> | null;
  html?: string | null;
  /** Attachment ids (`att_<n>`). */
  remove_attachments?: Array<string>;
  remove_labels?: Array<string>;
  reply_to?: Array<string> | null;
  send_at?: number | null;
  subject?: string | null;
  text?: string | null;
  to?: Array<string> | null;
}

/** `PATCH /environment`: fields left out stay as they are; `setup: ""` removes the script. */
export interface UpdateEnvironment {
  /** true: make it the default (the one new sandboxes use when they name none). */
  default?: boolean | null;
  /** Rename it (sandboxes stay on their versions). */
  name?: string | null;
  /** Setup scripts per repo directory; `""` removes one. Scripts not named stay. */
  repo_setup?: Record<string, string> | null;
  repos?: Array<string> | null;
  setup?: string | null;
}

/** `PATCH /v1/inboxes/{inbox}`. Fields left out stay as they are; `null` removes. */
export interface UpdateInbox {
  /** Schedule a deactivation (unix seconds); `null` cancels one. */
  deactivate_at?: number | null;
  /** `null` goes back to the server's retention. */
  expiry_hours?: number | null;
  /** Merged into the inbox's metadata: keys given are set, a key set to `null` is removed. */
  metadata?: Record<string, string | null> | null;
  name?: string | null;
  /** A sandbox's name to attach it to; `""` detaches it. */
  sandbox?: string | null;
  /** `null` removes the signature. */
  signature?: InboxSignature | null | null;
  /** `active` or `deactivated`. */
  status?: string | null;
}

/** `PATCH` a message or thread: labels to add and remove (`unread` marks it unread; removing it marks it read). Your own labels: 1-64 characters, lowercased; system labels other than `unread`, `spam`, `trash` and `starred` can't be changed. */
export interface UpdateLabels {
  add_labels?: Array<string>;
  remove_labels?: Array<string>;
}

export interface UpdateMailDomain {
  inbound?: boolean | null;
  subdomains?: boolean | null;
}

/** `PATCH /orgs/{org}`: the owner renames it; owners and admins set the default visibility. */
export interface UpdateOrg {
  /** shared | private */
  default_visibility?: string | null;
  name?: string | null;
}

/** `PATCH /orgs/{org}/members/{member}`: a role (owner only), or the member's caps (owners and admins; only the owner changes the owner's). `0` removes a cap. */
export interface UpdateOrgMember {
  max_running_sandboxes?: number | null;
  max_usage_usd?: number | null;
  /** admin | member */
  role?: string | null;
}

/** `PATCH /v1/revere/contacts/{contact}`: only the fields given change. */
export interface UpdateRevereContact {
  /** Monitors (ids or names); `[]`: every monitor. */
  monitors?: Array<string> | null;
  name?: string | null;
  paused?: boolean | null;
  url?: string | null;
}

/** `PATCH /v1/revere/monitors/{monitor}`: only the fields given change. `paused` pauses or resumes. */
export interface UpdateRevereMonitor {
  body?: string | null;
  cert_warn_days?: number | null;
  confirmations?: number | null;
  email?: boolean | null;
  expect_status?: string | null;
  grace_secs?: number | null;
  /** Replaces the headers (`[]` removes them). */
  headers?: Array<RevereHeader> | null;
  interval_secs?: number | null;
  keyword?: string | null;
  keyword_absent?: boolean | null;
  method?: string | null;
  name?: string | null;
  paused?: boolean | null;
  target?: string | null;
  timeout_secs?: number | null;
}

/** `PATCH /sandboxes/{name}`: rename, change the auto-stop timer, or change labels. */
export interface UpdateSandbox {
  /** true: while stopped, a request to one of its public URLs, or an exec, file, job or wait call, starts it; false: off. */
  auto_start?: boolean | null;
  /** Delete it after staying stopped this many seconds (0 = never). */
  delete_after_secs?: number | null;
  /** The desktop's frame rate: 60 or 120 (4+ vCPUs; billed per minute from the wallet while a viewer is connected). An open desktop picks it up when it's opened again. */
  desktop_fps?: number | null;
  /** Delete it this many seconds from now, running or not (60 s to 365 days); 0 removes the deadline. */
  expires_in_secs?: number | null;
  /** Labels to set; a null value removes that label. Labels not named stay. */
  labels?: Record<string, string | null> | null;
  /** Stop it this many seconds after each start (0 = no limit). Set while it runs, it counts from that start. */
  max_lifetime_secs?: number | null;
  name?: string | null;
  /** A new auto-stop timer in seconds (0 = no auto-stop). While running, the sandbox then stops this long from now (`froog extend --hours`); later starts use it too. */
  ttl_secs?: number | null;
}

/** Change a sandbox's AI settings (`PUT /v1/sandboxes/{name}/ai`). */
export interface UpdateSandboxAi {
  /** Refuse (true) or accept again (false) its AI requests, at once. Blocking needs `sandbox.update`; unblocking needs `environment.write` or `account.admin` on a key not limited to some sandboxes (never the in-sandbox key), and an owner or admin in an organization. */
  blocked?: boolean | null;
  /** A profile name or id; "" (empty) goes back to its environment's. Proxied requests use it at once; the variables the sandbox gets change at its next start. Changing it needs what unblocking needs. */
  profile?: string | null;
}

/** `PATCH /v1/revere/pages/{page}/incidents/{id}`: fix the title, impact, monitors or window (no email). */
export interface UpdateStatusIncident {
  ends_at?: number | null;
  impact?: string | null;
  monitors?: Array<string> | null;
  starts_at?: number | null;
  title?: string | null;
}

/** `PATCH /v1/revere/pages/{page}`. `custom_domain: null` (or "") removes the domain. */
export interface UpdateStatusPage {
  auto_incidents?: boolean | null;
  custom_domain?: string | null;
  description?: string | null;
  homepage_url?: string | null;
  monitors?: Array<StatusPageMonitor> | null;
  slug?: string | null;
  subscribers_enabled?: boolean | null;
  title?: string | null;
}

/** `PATCH /webhooks/{id}`: change what's given. The signing secret stays (rotate changes it). */
export interface UpdateWebhook {
  enabled?: boolean | null;
  /** Empty = every event. */
  events?: Array<string> | null;
  /** Mail events only for these inboxes (ids or addresses); `[]` = all of them again. */
  inboxes?: Array<string> | null;
  /** An empty name removes it. */
  name?: string | null;
  url?: string | null;
}

/** Optional body of `POST /environments/{env}/upgrade`. */
export interface UpgradeEnvironment {
  /** Only these sandboxes (names). Default: every sandbox of the environment on an older version. */
  sandboxes?: Array<string> | null;
}

/** A viewer token of a private URL (`GET /sandboxes/{name}/urls/{port}/tokens`). */
export interface UrlToken {
  created_at: number;
  expires_at: number;
  /** `utk_…`, for revoking it. */
  id: string;
  label?: string | null;
  /** Only when created: the secret (`pvt_…`). Send it as `?_token=` (the proxy turns it into a cookie) or in the `X-Froog-Url-Token` header. */
  token?: string | null;
  /** Only when created: the URL with `?_token=` for this token. */
  url?: string | null;
}

export interface Usage {
  /** The calendar month (UTC), unix seconds. `to` is now for the month still running. */
  from?: number;
  lines: Array<UsageLine>;
  /** "YYYY-MM" of the period's start. */
  month: string;
  saved_snapshot_days: number;
  /** The setup's charge for the month (`Capacity`: the sandboxes paid for by the month, from when each was added), charged to the wallet and then the card. */
  setup_usd?: number;
  snapshot_cost_usd: number;
  to?: number;
  /** Everything in the period: usage at list prices and the setup's charge. */
  total_usd: number;
}

export interface UsageLine {
  /** `froog`: a sandbox's running time. `seaeye`: Seaeye CI job time (`runs-on: seaeye`), priced per vCPU minute. `desktop_120fps`: minutes a viewer watched a 120 fps desktop (`desktop_fps`). `burst`: adaptive sandboxes' vCPUs above their size's, priced per vCPU-hour. */
  backend: string;
  cost_usd: number;
  /** `shared` or `dedicated` vCPUs (dedicated costs 2.5 times as much). */
  cpu?: Cpu;
  /** Running time (or CI job time) in the period, billed per second. For `burst`: vCPU-seconds above the floor. */
  seconds: number;
  size: Size;
}

/** `POST /sandboxes/{name}/wait`: wait until something listens on a TCP port inside the sandbox. */
export interface WaitForPort {
  port: number;
  /** Give up after this many seconds (1-600, default 60). Time spent starting counts. */
  timeout_secs?: number | null;
}

export interface Waitlist {
  email: string;
  /** What you're building. */
  note?: string | null;
  /** The products wanted: `quicksand`, `seaeye`, `tokenmail` (at least one). */
  products?: Array<string>;
  /** The sandboxes planned (with `quicksand`). */
  quicksand?: WaitlistQuicksand | null;
  /** The CI planned (with `seaeye`). */
  seaeye?: WaitlistSeaeye | null;
  /** The inboxes planned (with `tokenmail`). */
  tokenmail?: WaitlistTokenmail | null;
}

/** Sandboxes an access request plans: `free` (the lite), `shared` or `dedicated`, a size and how many at once. */
export interface WaitlistQuicksand {
  count?: number;
  size?: Size | null;
  tier: string;
}

/** CI an access request plans: roughly how many jobs a day, and how many at once. */
export interface WaitlistSeaeye {
  concurrency?: number;
  jobs_per_day?: number;
}

/** Inboxes an access request plans. */
export interface WaitlistTokenmail {
  inboxes?: number;
}

/** The wallet bonus: none below `from_usd`; from `from_percent` there, growing evenly on a log scale to `to_percent` at `to_usd`, and `to_percent` above that. */
export interface WalletBonus {
  /** What some amounts get. */
  examples: Array<WalletQuote>;
  from_percent: number;
  from_usd: number;
  to_percent: number;
  to_usd: number;
}

/** One entry of the wallet's history (`GET /v1/billing/history`), newest first: card payments, the setup's monthly charge, usage, credits and bonuses. */
export interface WalletEntry {
  /** When it was recorded (unix seconds). */
  at: number;
  /** topup (a card payment), bonus, credit, capacity (the setup's charge for a month), usage, commitment, start, trial. */
  kind: string;
  note: string;
  /** Into the wallet (positive) or out of it (negative). */
  usd: number;
}

/** `POST /v1/billing/wallet/pay`: charge the saved card and add the money to the wallet. */
export interface WalletPay {
  /** Whole dollars, from `Billing.min_topup_usd` to `Billing.max_wallet_per_day_usd` (also the most charged in any 24 hours). */
  amount_usd: number;
  /** Also make this the auto top-up amount (default: when auto top-up is off). Send false to leave auto top-up as it is. */
  auto_topup?: boolean | null;
  /** The saved card to charge (`Card.id`); it becomes the default, which auto top-up charges. Default: the default card. */
  card_id?: string | null;
}

/** `GET /v1/billing/wallet/quote?amount_usd=N`: what a payment of N dollars puts in the wallet. */
export interface WalletQuote {
  amount_usd: number;
  bonus_percent: number;
  bonus_usd: number;
  credited_usd: number;
}

/** A webhook endpoint (the signing secret is shown only when created or rotated). */
export interface Webhook {
  created_at: number;
  /** false: paused, nothing is sent (test pings still are). */
  enabled?: boolean;
  /** Empty = every sandbox event. Mail (`message.*`, `domain.verified`) and CI events are sent only to webhooks that list them. */
  events: Array<string>;
  id: string;
  /** Mail events only for these inboxes (ids); none = all of them. */
  inboxes?: Array<string> | null;
  /** Your own name for it (up to 100 characters). */
  name?: string | null;
  updated_at?: number | null;
  url: string;
}

/** One delivery attempt of a webhook (`GET /webhooks/{id}/deliveries`, kept 30 days). */
export interface WebhookDelivery {
  /** 1-8 (`froog-attempt`). */
  attempt: number;
  /** Unix seconds. */
  created_at: number;
  duration_ms: number;
  /** What went wrong (a connection error, a non-2xx answer). */
  error?: string | null;
  /** sandbox.running, …, or ping. */
  event: string;
  /** The event id (`evt_…`, also the `froog-delivery` header): the same on every attempt. */
  event_id: string;
  /** When the next attempt is due, if one is. */
  next_attempt_at?: number | null;
  /** The endpoint's HTTP status; none when it couldn't be reached. */
  response_code?: number | null;
  /** The sandbox it was about (none for a ping). */
  sandbox?: string | null;
  /** delivered | failed (another attempt follows unless this was the last). */
  status: string;
}

export interface WebhookSecret {
  events: Array<string>;
  id: string;
  name?: string | null;
  /** Verify `froog-signature` with this; shown once. */
  secret: string;
  url: string;
}

export class FroogError extends Error {
  status: number;
  code: string;
  /** The request's id (X-Request-Id); quote it when reporting a problem. */
  requestId?: string;
  constructor(status: number, code: string, message: string, requestId?: string) {
    super(message);
    this.name = "FroogError";
    this.status = status;
    this.code = code;
    this.requestId = requestId;
  }
}

export interface FroogOptions {
  /** An API key (froog_…). Default: process.env.FROOG_API_KEY where there is one. */
  apiKey?: string;
  /** Default https://api.froog.tech */
  baseUrl?: string;
  /** The organization requests act in (id or name, or "personal"), sent as X-Froog-Org. Default: process.env.FROOG_ORG; none: the active one. */
  org?: string;
  fetch?: typeof fetch;
}

type Query = Record<string, string | number | boolean | string[] | undefined>;

export class Froog {
  private apiKey?: string;
  private baseUrl: string;
  private org?: string;
  private fetchFn: typeof fetch;
  /** Sandboxes as objects: `await froog.sandboxes.create({...})`, `await froog.sandboxes.get(name)`. */
  readonly sandboxes: Sandboxes = new Sandboxes(this);

  constructor(opts: FroogOptions = {}) {
    const env = (globalThis as any).process?.env ?? {};
    this.apiKey = opts.apiKey ?? env.FROOG_API_KEY;
    this.baseUrl = (opts.baseUrl ?? env.FROOG_API_URL ?? "https://api.froog.tech").replace(/\/$/, "");
    this.org = opts.org ?? env.FROOG_ORG;
    this.fetchFn = opts.fetch ?? fetch.bind(globalThis);
  }

  private async call(method: string, path: string, opts: { query?: Query; json?: unknown; raw?: BodyInit; rawResponse?: boolean; auth?: boolean; idempotencyKey?: string } = {}): Promise<any> {
    const url = new URL(this.baseUrl + path);
    for (const [k, v] of Object.entries(opts.query ?? {})) {
      if (Array.isArray(v)) for (const x of v) url.searchParams.append(k, x);
      else if (v !== undefined) url.searchParams.set(k, String(v));
    }
    const headers: Record<string, string> = { "user-agent": "froog-ts" };
    if (opts.auth !== false && this.apiKey) headers.authorization = `Bearer ${this.apiKey}`;
    if (opts.idempotencyKey) headers["idempotency-key"] = opts.idempotencyKey;
    if (this.org) headers["x-froog-org"] = this.org;
    let body: BodyInit | undefined;
    if (opts.json !== undefined) { headers["content-type"] = "application/json"; body = JSON.stringify(opts.json); }
    if (opts.raw !== undefined) { headers["content-type"] = "application/octet-stream"; body = opts.raw; }
    const res = await this.fetchFn(url, { method, headers, body });
    if (!res.ok) await this.fail(res);
    if (opts.rawResponse) return new Uint8Array(await res.arrayBuffer());
    const text = await res.text();
    return text ? JSON.parse(text) : undefined;
  }

  private async fail(res: Response): Promise<never> {
    let code = "http_" + res.status, message = res.statusText;
    const requestId = res.headers.get("x-request-id") ?? undefined;
    try { const e = await res.json(); code = e.error?.code ?? code; message = e.error?.message ?? message; } catch {}
    throw new FroogError(res.status, code, message, requestId);
  }

  /** A GET answered with NDJSON: each line as it arrives, until the stream ends. */
  private async *stream(path: string, query: Query = {}): AsyncGenerator<any> {
    const url = new URL(this.baseUrl + path);
    for (const [k, v] of Object.entries(query)) {
      if (Array.isArray(v)) for (const x of v) url.searchParams.append(k, x);
      else if (v !== undefined) url.searchParams.set(k, String(v));
    }
    const headers: Record<string, string> = { "user-agent": "froog-ts", accept: "application/x-ndjson" };
    if (this.apiKey) headers.authorization = `Bearer ${this.apiKey}`;
    if (this.org) headers["x-froog-org"] = this.org;
    const res = await this.fetchFn(url, { headers });
    if (!res.ok) await this.fail(res);
    const reader = res.body!.getReader();
    const decoder = new TextDecoder();
    let buf = "";
    for (;;) {
      const { done, value } = await reader.read();
      if (done) break;
      buf += decoder.decode(value, { stream: true });
      let i: number;
      while ((i = buf.indexOf("\n")) >= 0) {
        const line = buf.slice(0, i).trim();
        buf = buf.slice(i + 1);
        if (line) yield JSON.parse(line);
      }
    }
    if (buf.trim()) yield JSON.parse(buf);
  }

  /** Run a command and get its output as it arrives: `started`, then `stdout`/`stderr` chunks, then `exit` (or `error`).
   *  `for await (const e of froog.execStream("box", { command: "make" })) if (e.type === "stdout") process.stdout.write(e.data);` */
  async *execStream(name: string, body: ExecRequest): AsyncGenerator<ExecEvent> {
    const headers: Record<string, string> = { "user-agent": "froog-ts", "content-type": "application/json", accept: "application/x-ndjson" };
    if (this.apiKey) headers.authorization = `Bearer ${this.apiKey}`;
    if (this.org) headers["x-froog-org"] = this.org;
    const res = await this.fetchFn(new URL(`${this.baseUrl}/v1/sandboxes/${encodeURIComponent(name)}/exec`), { method: "POST", headers, body: JSON.stringify({ ...body, stream: true }) });
    if (!res.ok) await this.fail(res);
    const reader = res.body!.getReader();
    const decoder = new TextDecoder();
    let buf = "";
    for (;;) {
      const { done, value } = await reader.read();
      if (done) break;
      buf += decoder.decode(value, { stream: true });
      let i: number;
      while ((i = buf.indexOf("\n")) >= 0) {
        const line = buf.slice(0, i).trim();
        buf = buf.slice(i + 1);
        if (line) yield JSON.parse(line) as ExecEvent;
      }
    }
    if (buf.trim()) yield JSON.parse(buf) as ExecEvent;
  }

  /** Poll until the sandbox reaches `state` (e.g. "running" after create or start). */
  async waitUntil(name: string, state: State, timeoutMs = 600_000): Promise<Sandbox> {
    const until = Date.now() + timeoutMs;
    for (;;) {
      const sb = await this.getSandbox(name);
      if (sb.state === state) return sb;
      if (sb.state === "error") throw new FroogError(409, "sandbox_error", `${name}: ${sb.error ?? "error"}`);
      if (Date.now() > until) throw new FroogError(408, "timeout", `${name} didn't become ${state}`);
      await new Promise((r) => setTimeout(r, 2000));
    }
  }

  /** MCP server (Streamable HTTP, stateless): JSON-RPC 2.0 initialize, tools/list and tools/call, with tools to list, create, run commands in, fork, snapshot, stop and delete sandboxes, run background commands and read their output, read and write files and host ports. A scoped key may call only the tools its actions allow. An exec call with _meta.progressToken from a client that accepts text/event-stream is answered as server-sent events (output as notifications/progress, then the result). With FROOG_SERVER_MCP_OAUTH on, a 401 points at OAuth metadata (MCP authorization) and the access tokens are scoped API keys. `POST /mcp` */
  mcp(body: JsonRpcRequest): Promise<JsonRpcResponse> {
    return this.call("POST", `/mcp`, { json: body });
  }

  /** The signed-in account. `GET /v1/account` */
  getAccount(): Promise<Account> {
    return this.call("GET", `/v1/account`);
  }

  /** Alerts settings: which emails the account gets, and automatic rebuilds. `GET /v1/account/alerts` */
  getAlertSettings(): Promise<AlertSettings> {
    return this.call("GET", `/v1/account/alerts`);
  }

  /** Turn kinds of email, or automatic rebuilds, on or off. `PATCH /v1/account/alerts` */
  updateAlertSettings(body: UpdateAlertSettings): Promise<AlertSettings> {
    return this.call("PATCH", `/v1/account/alerts`, { json: body });
  }

  /** Close the account: stop every sandbox, revoke every key; reopen within 30 days. Needs the header X-Froog-Confirm-Close set to the account's email, and a full-access key or a dashboard session. `POST /v1/account/close` */
  closeAccount(): Promise<AccountClosing> {
    return this.call("POST", `/v1/account/close`);
  }

  /** Ways to sign in to the account (Google, GitHub, email, AgentID); the primary one's address gets the account's emails. `GET /v1/account/connections` */
  listConnections(): Promise<Array<Connection>> {
    return this.call("GET", `/v1/account/connections`);
  }

  /** Send a 6-digit code to an address to add it as a sign-in connection. `POST /v1/account/connections/email` */
  sendConnectionEmailCode(body: EmailCodeRequest): Promise<void> {
    return this.call("POST", `/v1/account/connections/email`, { json: body });
  }

  /** Add the address with the code from the email. `POST /v1/account/connections/email/verify` */
  verifyConnectionEmailCode(body: EmailCodeVerify): Promise<Connection> {
    return this.call("POST", `/v1/account/connections/email/verify`, { json: body });
  }

  /** Remove a sign-in connection (not the last one: 409 last_connection). `DELETE /v1/account/connections/{id}` */
  removeConnection(id: string): Promise<void> {
    return this.call("DELETE", `/v1/account/connections/${encodeURIComponent(id)}`);
  }

  /** Data controls: zero data retention, snapshots off, monitoring off. `GET /v1/account/data-retention` */
  getDataRetention(): Promise<DataRetention> {
    return this.call("GET", `/v1/account/data-retention`);
  }

  /** Change data controls (dashboard session only). `PATCH /v1/account/data-retention` */
  updateDataRetention(body: UpdateDataRetention): Promise<DataRetention> {
    return this.call("PATCH", `/v1/account/data-retention`, { json: body });
  }

  /** Make a connection primary: its address gets the account's emails. `PUT /v1/account/primary` */
  setPrimaryConnection(body: SetPrimary): Promise<Connection> {
    return this.call("PUT", `/v1/account/primary`, { json: body });
  }

  /** Reopen a closed account within its 30-day window. `POST /v1/account/reopen` */
  reopenAccount(): Promise<AccountClosing> {
    return this.call("POST", `/v1/account/reopen`);
  }

  /** The credential profile an environment's sandboxes get. `PUT /v1/ai/environments/{env}` */
  setAiEnvironmentProfile(env: string, body: SetAiEnvironmentProfile): Promise<AiProfile> {
    return this.call("PUT", `/v1/ai/environments/${encodeURIComponent(env)}`, { json: body });
  }

  /** Credential profiles and their accounts (never the keys). `GET /v1/ai/profiles` */
  listAiProfiles(): Promise<Array<AiProfile>> {
    return this.call("GET", `/v1/ai/profiles`);
  }

  /** Create a credential profile, empty or as a copy. `POST /v1/ai/profiles` */
  createAiProfile(body: CreateAiProfile): Promise<AiProfile> {
    return this.call("POST", `/v1/ai/profiles`, { json: body });
  }

  /** Delete a profile (not the default, not one an environment uses). `DELETE /v1/ai/profiles/{profile}` */
  deleteAiProfile(profile: string): Promise<void> {
    return this.call("DELETE", `/v1/ai/profiles/${encodeURIComponent(profile)}`);
  }

  /** One credential profile (name or id). `GET /v1/ai/profiles/{profile}` */
  getAiProfile(profile: string): Promise<AiProfile> {
    return this.call("GET", `/v1/ai/profiles/${encodeURIComponent(profile)}`);
  }

  /** Rename a profile, or make it the default. `PATCH /v1/ai/profiles/{profile}` */
  updateAiProfile(profile: string, body: UpdateAiProfile): Promise<AiProfile> {
    return this.call("PATCH", `/v1/ai/profiles/${encodeURIComponent(profile)}`, { json: body });
  }

  /** Add a provider key or custom API to a profile (another account when the provider has one). `POST /v1/ai/profiles/{profile}/credentials` */
  addAiCredential(profile: string, body: AddAiCredential): Promise<AiCredential> {
    return this.call("POST", `/v1/ai/profiles/${encodeURIComponent(profile)}/credentials`, { json: body });
  }

  /** Remove a key from a profile. `DELETE /v1/ai/profiles/{profile}/credentials/{id}` */
  removeAiCredential(profile: string, id: string): Promise<void> {
    return this.call("DELETE", `/v1/ai/profiles/${encodeURIComponent(profile)}/credentials/${encodeURIComponent(id)}`);
  }

  /** Use this account first for its provider. `PUT /v1/ai/profiles/{profile}/credentials/{id}/active` */
  switchAiCredential(profile: string, id: string): Promise<AiProfile> {
    return this.call("PUT", `/v1/ai/profiles/${encodeURIComponent(profile)}/credentials/${encodeURIComponent(id)}/active`);
  }

  /** The AI proxy: on or off, blocked, subscriptions withheld, its URL. `GET /v1/ai/proxy` */
  getAiProxy(): Promise<AiProxy> {
    return this.call("GET", `/v1/ai/proxy`);
  }

  /** Turn the AI proxy on or off (sandboxes switch at their next start), block every proxied sandbox. `PUT /v1/ai/proxy` */
  updateAiProxy(body: UpdateAiProxy): Promise<AiProxy> {
    return this.call("PUT", `/v1/ai/proxy`, { json: body });
  }

  /** Proxied AI usage per sandbox: requests, tokens, estimated cost. `GET /v1/ai/usage` */
  getAiUsage(query?: { days?: string | number | boolean }): Promise<AiUsage> {
    return this.call("GET", `/v1/ai/usage`, { query: query });
  }

  /** API keys (secrets are never returned). `GET /v1/api-keys` */
  listApiKeys(): Promise<Array<ApiKeyInfo>> {
    return this.call("GET", `/v1/api-keys`);
  }

  /** Create an API key: a preset or actions, sandboxes or labels, expiry. `POST /v1/api-keys` */
  createApiKey(body: NewApiKey): Promise<CreatedApiKey> {
    return this.call("POST", `/v1/api-keys`, { json: body });
  }

  /** Revoke an API key. `DELETE /v1/api-keys/{id}` */
  revokeApiKey(id: string): Promise<void> {
    return this.call("DELETE", `/v1/api-keys/${encodeURIComponent(id)}`);
  }

  /** A new secret for a key (same id, scope and expiry). `POST /v1/api-keys/{id}/rotate` */
  rotateApiKey(id: string): Promise<CreatedApiKey> {
    return this.call("POST", `/v1/api-keys/${encodeURIComponent(id)}/rotate`);
  }

  /** The account's audit log, newest first (90 days): who created, deleted or changed what, from which IP. `GET /v1/audit` */
  listAuditEvents(query?: { action?: string | number | boolean; sandbox?: string | number | boolean; since?: string | number | boolean; until?: string | number | boolean; sort?: string | number | boolean; limit?: string | number | boolean; cursor?: string | number | boolean }): Promise<AuditList> {
    return this.call("GET", `/v1/audit`, { query: query });
  }

  /** Every matching audit entry of the last 90 days as one CSV or NDJSON file. `GET /v1/audit/export` */
  exportAudit(query?: { format?: string | number | boolean; action?: string | number | boolean; sandbox?: string | number | boolean; since?: string | number | boolean; until?: string | number | boolean; sort?: string | number | boolean }): Promise<Uint8Array> {
    return this.call("GET", `/v1/audit/export`, { query: query, rawResponse: true });
  }

  /** What's free to add to a setup: for each size, shared and dedicated, how many more sandboxes fit now, in a day and in a week, measured every 10 minutes behind now and projected from setups' pending changes ahead of it. `GET /v1/availability` */
  getAvailability(query?: { range?: string | number | boolean }): Promise<Availability> {
    return this.call("GET", `/v1/availability`, { query: query });
  }

  /** The plan and the plans on offer, rates (shared and dedicated), the wallet, this month's usage, the spending cap, running limits and auto top-up. `GET /v1/billing` */
  getBilling(): Promise<Billing> {
    return this.call("GET", `/v1/billing`);
  }

  /** Set the account's setup: the sandboxes it pays for by the month (size, shared or dedicated vCPUs, count), each running 24/7 at no extra charge. Adding charges the rest of this month at once (wallet credit first, then the card); removing applies from the next calendar month. `PUT /v1/billing/capacity` */
  setCapacity(body: SetCapacity): Promise<Billing> {
    return this.call("PUT", `/v1/billing/capacity`, { json: body });
  }

  /** A Stripe page to pay the setup's unpaid charge now, on-session (for a card whose bank asks to confirm each payment, or another card); once paid it goes to the wallet and the setup's sandboxes can start. `POST /v1/billing/capacity/pay` */
  payCapacity(): Promise<BillingUrl> {
    return this.call("POST", `/v1/billing/capacity/pay`);
  }

  /** Join the waitlist for paid sandboxes (invite-only for now): the setup you'd run and what it's for. Operators are told at once and approve by hand; you're emailed when you're in. `POST /v1/billing/capacity/request` */
  requestCapacity(body: RequestCapacity): Promise<Billing> {
    return this.call("POST", `/v1/billing/capacity/request`, { json: body });
  }

  /** A Stripe Checkout page that saves a card. `POST /v1/billing/card` */
  addCard(): Promise<BillingUrl> {
    return this.call("POST", `/v1/billing/card`);
  }

  /** The saved cards, the default (charged by wallet payments and auto top-up) first. `GET /v1/billing/cards` */
  listCards(): Promise<Array<Card>> {
    return this.call("GET", `/v1/billing/cards`);
  }

  /** Remove a saved card (removing the last one turns auto top-up off; refused while it's the only card and the setup is billed to it). `DELETE /v1/billing/cards/{id}` */
  removeCard(id: string): Promise<void> {
    return this.call("DELETE", `/v1/billing/cards/${encodeURIComponent(id)}`);
  }

  /** Make a saved card the default: the one the setup's monthly charge, wallet payments and auto top-up charge. An unpaid setup charge is tried on it at once. `PUT /v1/billing/cards/{id}/default` */
  setDefaultCard(id: string): Promise<Array<Card>> {
    return this.call("PUT", `/v1/billing/cards/${encodeURIComponent(id)}/default`);
  }

  /** Turn extra starts on or off: starts past the start limits paid from the wallet. `PUT /v1/billing/extra-starts` */
  setExtraStarts(body: SetExtraStarts): Promise<Billing> {
    return this.call("PUT", `/v1/billing/extra-starts`, { json: body });
  }

  /** The wallet's history, newest first: card payments, the setup's monthly charges, usage, credits and bonuses. `GET /v1/billing/history` */
  getBillingHistory(query?: { limit?: string | number | boolean }): Promise<Array<WalletEntry>> {
    return this.call("GET", `/v1/billing/history`, { query: query });
  }

  /** Cancel the plan (or trial): it ends at the end of the period, nothing more is charged. `DELETE /v1/billing/plan` */
  cancelPlan(): Promise<Billing> {
    return this.call("DELETE", `/v1/billing/plan`);
  }

  /** Choose a plan or change to another: a first plan starts with the free trial (skip_trial charges the first month now); a change applies now (the new price is charged and a new month starts). `PUT /v1/billing/plan` */
  setPlan(body: SetPlan): Promise<Billing> {
    return this.call("PUT", `/v1/billing/plan`, { json: body });
  }

  /** A Stripe page to manage saved cards (froog's charges are listed by GET /v1/billing/history; Stripe emails a receipt for each card payment). `POST /v1/billing/portal` */
  billingPortal(): Promise<BillingUrl> {
    return this.call("POST", `/v1/billing/portal`);
  }

  /** Set the monthly spending cap (null removes it); reaching it stops running sandboxes, disks saved. `PUT /v1/billing/spend-cap` */
  setSpendCap(body: SpendCap): Promise<Billing> {
    return this.call("PUT", `/v1/billing/spend-cap`, { json: body });
  }

  /** Set auto top-up (0 = off). `PUT /v1/billing/wallet/auto-topup` */
  setAutoTopup(body: AutoTopup): Promise<Billing> {
    return this.call("PUT", `/v1/billing/wallet/auto-topup`, { json: body });
  }

  /** Charge a saved card (card_id, or the default) and add the money to the wallet (also turns on auto top-up at this amount when it's off, unless auto_topup is false). Unknown fields are refused. `POST /v1/billing/wallet/pay` */
  walletPay(body: WalletPay): Promise<Billing> {
    return this.call("POST", `/v1/billing/wallet/pay`, { json: body });
  }

  /** What a wallet payment adds, with its bonus. `GET /v1/billing/wallet/quote` */
  walletQuote(query: { amount_usd: string | number | boolean }): Promise<WalletQuote> {
    return this.call("GET", `/v1/billing/wallet/quote`, { query: query });
  }

  /** Start a browser login for the CLI. `POST /v1/cli-login` */
  startCliLogin(body: CliLoginRequest): Promise<CliLoginStarted> {
    return this.call("POST", `/v1/cli-login`, { json: body, auth: false });
  }

  /** Poll a CLI login (202 until approved). `POST /v1/cli-login/poll` */
  pollCliLogin(body: CliLoginPoll): Promise<CliLoginResult> {
    return this.call("POST", `/v1/cli-login/poll`, { json: body, auth: false });
  }

  /** Deny a CLI login. `DELETE /v1/cli-login/{code}` */
  denyCliLogin(code: string): Promise<void> {
    return this.call("DELETE", `/v1/cli-login/${encodeURIComponent(code)}`);
  }

  /** Describe a pending CLI login. `GET /v1/cli-login/{code}` */
  getCliLogin(code: string): Promise<CliLoginInfo> {
    return this.call("GET", `/v1/cli-login/${encodeURIComponent(code)}`);
  }

  /** Approve a CLI login (creates a key). `POST /v1/cli-login/{code}/approve` */
  approveCliLogin(code: string): Promise<void> {
    return this.call("POST", `/v1/cli-login/${encodeURIComponent(code)}/approve`);
  }

  /** A link that opens the dashboard signed in: single use, 15 minutes (full-access keys and sessions only). `POST /v1/dashboard-link` */
  createDashboardLink(): Promise<DashboardLink> {
    return this.call("POST", `/v1/dashboard-link`);
  }

  /** A deletion operation (dop_…): an account close or a zero data retention erasure. `GET /v1/deletion-operations/{id}` */
  getDeletionOperation(id: string): Promise<DeletionOperation> {
    return this.call("GET", `/v1/deletion-operations/${encodeURIComponent(id)}`);
  }

  /** Account environment variables (names and previews). `GET /v1/env` */
  listEnv(): Promise<Array<EnvVar>> {
    return this.call("GET", `/v1/env`);
  }

  /** Remove an account environment variable. `DELETE /v1/env/{name}` */
  removeEnv(name: string): Promise<void> {
    return this.call("DELETE", `/v1/env/${encodeURIComponent(name)}`);
  }

  /** Set an account environment variable. `PUT /v1/env/{name}` */
  setEnv(name: string, body: SetEnvVar): Promise<void> {
    return this.call("PUT", `/v1/env/${encodeURIComponent(name)}`, { json: body });
  }

  /** Repos, secret files and setup script every new sandbox gets. `GET /v1/environment` */
  getEnvironment(): Promise<Environment> {
    return this.call("GET", `/v1/environment`);
  }

  /** Change repos or the setup script. `PATCH /v1/environment` */
  updateEnvironment(body: UpdateEnvironment): Promise<Environment> {
    return this.call("PATCH", `/v1/environment`, { json: body });
  }

  /** Remove a secret file. `DELETE /v1/environment/files` */
  removeEnvironmentFile(query: { path: string | number | boolean }): Promise<void> {
    return this.call("DELETE", `/v1/environment/files`, { query: query });
  }

  /** Write a secret file. `PUT /v1/environment/files` */
  setEnvironmentFile(body: SetEnvFile): Promise<void> {
    return this.call("PUT", `/v1/environment/files`, { json: body });
  }

  /** Named environments: default marker, latest version, sandboxes per version. `GET /v1/environments` */
  listEnvironments(): Promise<Array<EnvironmentSummary>> {
    return this.call("GET", `/v1/environments`);
  }

  /** Create an environment (empty, or a copy of another's latest version). `POST /v1/environments` */
  createEnvironment(body: NewEnvironment): Promise<Environment> {
    return this.call("POST", `/v1/environments`, { json: body });
  }

  /** Delete an environment (its sandboxes keep their version; not the default). `DELETE /v1/environments/{env}` */
  deleteEnvironment(env: string): Promise<void> {
    return this.call("DELETE", `/v1/environments/${encodeURIComponent(env)}`);
  }

  /** One environment: repos, setup scripts, secret files (names and sizes), latest version. `GET /v1/environments/{env}` */
  getNamedEnvironment(env: string): Promise<Environment> {
    return this.call("GET", `/v1/environments/${encodeURIComponent(env)}`);
  }

  /** Change repos or setup scripts (a new version), rename, or make it the default. `PATCH /v1/environments/{env}` */
  updateNamedEnvironment(env: string, body: UpdateEnvironment): Promise<Environment> {
    return this.call("PATCH", `/v1/environments/${encodeURIComponent(env)}`, { json: body });
  }

  /** Remove a secret file (a new version). `DELETE /v1/environments/{env}/files` */
  removeNamedEnvironmentFile(env: string, query: { path: string | number | boolean }): Promise<void> {
    return this.call("DELETE", `/v1/environments/${encodeURIComponent(env)}/files`, { query: query });
  }

  /** Write a secret file (a new version). `PUT /v1/environments/{env}/files` */
  setNamedEnvironmentFile(env: string, body: SetEnvFile): Promise<void> {
    return this.call("PUT", `/v1/environments/${encodeURIComponent(env)}/files`, { json: body });
  }

  /** Move its sandboxes to the latest version (running ones now, stopped ones at their next start). `POST /v1/environments/{env}/upgrade` */
  upgradeEnvironment(env: string, body: UpgradeEnvironment): Promise<EnvironmentUpgrade> {
    return this.call("POST", `/v1/environments/${encodeURIComponent(env)}/upgrade`, { json: body });
  }

  /** An environment's versions, newest first, with sandboxes on each. `GET /v1/environments/{env}/versions` */
  listEnvironmentVersions(env: string): Promise<Array<EnvironmentVersion>> {
    return this.call("GET", `/v1/environments/${encodeURIComponent(env)}/versions`);
  }

  /** Send feedback to the froog team. `POST /v1/feedback` */
  sendFeedback(body: Feedback): Promise<void> {
    return this.call("POST", `/v1/feedback`, { json: body });
  }

  /** Download through a signed link. `GET /v1/file-urls/{token}` */
  downloadSigned(token: string): Promise<Uint8Array> {
    return this.call("GET", `/v1/file-urls/${encodeURIComponent(token)}`, { rawResponse: true, auth: false });
  }

  /** Upload through a signed link (raw bytes). `PUT /v1/file-urls/{token}` */
  uploadSigned(token: string, data: BodyInit): Promise<void> {
    return this.call("PUT", `/v1/file-urls/${encodeURIComponent(token)}`, { raw: data, auth: false });
  }

  /** The GitHub connection: linked installations and the repositories the sandbox token is limited to. `GET /v1/github` */
  getGithub(): Promise<GithubStatus> {
    return this.call("GET", `/v1/github`);
  }

  /** A link that installs the froog GitHub App on a GitHub account or organization. `POST /v1/github/connect` */
  connectGithub(): Promise<GithubConnect> {
    return this.call("POST", `/v1/github/connect`);
  }

  /** Unlink a GitHub installation from the account. `DELETE /v1/github/installations/{id}` */
  disconnectGithubInstallation(id: string): Promise<void> {
    return this.call("DELETE", `/v1/github/installations/${encodeURIComponent(id)}`);
  }

  /** Repositories the linked installations can see. `GET /v1/github/repos` */
  listGithubRepos(): Promise<Array<GithubRepo>> {
    return this.call("GET", `/v1/github/repos`);
  }

  /** Limit the GitHub token in each sandbox to these repositories (empty: all the app can see). `PUT /v1/github/token-repos` */
  setGithubTokenRepos(body: SetTokenRepos): Promise<GithubStatus> {
    return this.call("PUT", `/v1/github/token-repos`, { json: body });
  }

  /** Operating systems a sandbox can run. `GET /v1/images` */
  listImages(): Promise<Array<OsImage>> {
    return this.call("GET", `/v1/images`);
  }

  /** Your agent inboxes. `GET /v1/inboxes` */
  listInboxes(query?: { limit?: string | number | boolean; page_token?: string | number | boolean }): Promise<InboxList> {
    return this.call("GET", `/v1/inboxes`, { query: query });
  }

  /** Make an inbox ($2 a month), on froogmail.com or a verified domain of yours. Uses a paid seat, or adds one; 402 inbox_payment_required without an inbox subscription. A client_id used before returns that inbox (200). `POST /v1/inboxes` */
  createInbox(body: CreateInbox): Promise<Inbox> {
    return this.call("POST", `/v1/inboxes`, { json: body });
  }

  /** What you pay for inboxes: seats paid for, inboxes used, the subscription's status. `GET /v1/inboxes/billing` */
  getInboxBilling(): Promise<InboxBilling> {
    return this.call("GET", `/v1/inboxes/billing`);
  }

  /** A Stripe Checkout page that buys inboxes (default: yours plus one). `POST /v1/inboxes/billing/checkout` */
  buyInboxes(body: InboxCheckout): Promise<BillingUrl> {
    return this.call("POST", `/v1/inboxes/billing/checkout`, { json: body });
  }

  /** Your custom mail domains. `GET /v1/inboxes/domains` */
  listMailDomains(): Promise<Array<MailDomain>> {
    return this.call("GET", `/v1/inboxes/domains`);
  }

  /** Add a domain: the DNS records to publish come back. `POST /v1/inboxes/domains` */
  createMailDomain(body: NewMailDomain): Promise<MailDomain> {
    return this.call("POST", `/v1/inboxes/domains`, { json: body });
  }

  /** The public setup page (HTML). `GET /v1/inboxes/domains/setup/{id}/{token}` */
  mailDomainSetupPage(id: string, token: string): Promise<Uint8Array> {
    return this.call("GET", `/v1/inboxes/domains/setup/${encodeURIComponent(id)}/${encodeURIComponent(token)}`, { rawResponse: true, auth: false });
  }

  /** Remove a domain (its inboxes first). `DELETE /v1/inboxes/domains/{domain}` */
  deleteMailDomain(domain: string): Promise<void> {
    return this.call("DELETE", `/v1/inboxes/domains/${encodeURIComponent(domain)}`);
  }

  /** One domain with its records and what was found. `GET /v1/inboxes/domains/{domain}` */
  getMailDomain(domain: string): Promise<MailDomain> {
    return this.call("GET", `/v1/inboxes/domains/${encodeURIComponent(domain)}`);
  }

  /** Turn receiving or subdomains on or off. `PATCH /v1/inboxes/domains/{domain}` */
  updateMailDomain(domain: string, body: UpdateMailDomain): Promise<MailDomain> {
    return this.call("PATCH", `/v1/inboxes/domains/${encodeURIComponent(domain)}`, { json: body });
  }

  /** A public link to the records, for whoever runs the domain's DNS. `GET /v1/inboxes/domains/{domain}/setup-link` */
  getMailDomainSetupLink(domain: string): Promise<MailDomainSetupLink> {
    return this.call("GET", `/v1/inboxes/domains/${encodeURIComponent(domain)}/setup-link`);
  }

  /** Look up the domain's DNS records now. `POST /v1/inboxes/domains/{domain}/verify` */
  verifyMailDomain(domain: string): Promise<MailDomain> {
    return this.call("POST", `/v1/inboxes/domains/${encodeURIComponent(domain)}/verify`);
  }

  /** The records as a BIND zone file. `GET /v1/inboxes/domains/{domain}/zone-file` */
  getMailDomainZoneFile(domain: string): Promise<Uint8Array> {
    return this.call("GET", `/v1/inboxes/domains/${encodeURIComponent(domain)}/zone-file`, { rawResponse: true });
  }

  /** Drafts of every inbox you can see. `GET /v1/inboxes/drafts` */
  listAllInboxDrafts(query?: { limit?: string | number | boolean; page_token?: string | number | boolean; scheduled?: string | number | boolean }): Promise<DraftList> {
    return this.call("GET", `/v1/inboxes/drafts`, { query: query });
  }

  /** Mail events, oldest first (kept 30 days); wait long-polls for the next one. `GET /v1/inboxes/events` */
  listMailEvents(query?: { after?: string | number | boolean; types?: string | number | boolean; inboxes?: string | number | boolean; limit?: string | number | boolean; wait?: string | number | boolean }): Promise<MailEventList> {
    return this.call("GET", `/v1/inboxes/events`, { query: query });
  }

  /** A WebSocket of events as they happen (each a MailEvent as JSON text); send {"type":"subscribe","inboxes":[…],"types":[…]} to change what you get. `GET /v1/inboxes/events/ws` */
  mailEventsSocket(query?: { after?: string | number | boolean; types?: string | number | boolean; inboxes?: string | number | boolean; limit?: string | number | boolean; wait?: string | number | boolean }): Promise<Uint8Array> {
    return this.call("GET", `/v1/inboxes/events/ws`, { query: query, rawResponse: true });
  }

  /** Stop forwarding (account-wide). `DELETE /v1/inboxes/forwarding` */
  deleteMailForwarding(): Promise<void> {
    return this.call("DELETE", `/v1/inboxes/forwarding`);
  }

  /** Where received mail is forwarded, for every inbox without its own list. `GET /v1/inboxes/forwarding` */
  getMailForwarding(): Promise<MailForwarding> {
    return this.call("GET", `/v1/inboxes/forwarding`);
  }

  /** Set the account's forwarding addresses (up to 5; each must be verified). `PUT /v1/inboxes/forwarding` */
  setMailForwarding(body: SetForwarding): Promise<MailForwarding> {
    return this.call("PUT", `/v1/inboxes/forwarding`, { json: body });
  }

  /** Email a forwarding address a code to confirm it. `POST /v1/inboxes/forwarding/verifications` */
  startForwardingVerification(body: StartForwardingVerification): Promise<ForwardingVerification> {
    return this.call("POST", `/v1/inboxes/forwarding/verifications`, { json: body });
  }

  /** Confirm a forwarding address with the code it got. `POST /v1/inboxes/forwarding/verifications/confirm` */
  confirmForwardingVerification(body: ConfirmForwardingVerification): Promise<ForwardingVerification> {
    return this.call("POST", `/v1/inboxes/forwarding/verifications/confirm`, { json: body });
  }

  /** An account-wide allow or block list (direction receive, send or reply). `GET /v1/inboxes/lists/{direction}/{list_type}` */
  listMailListEntries(direction: string, list_type: string): Promise<Array<MailListEntry>> {
    return this.call("GET", `/v1/inboxes/lists/${encodeURIComponent(direction)}/${encodeURIComponent(list_type)}`);
  }

  /** Add an address or domain to an account-wide list. `POST /v1/inboxes/lists/{direction}/{list_type}` */
  addMailListEntry(direction: string, list_type: string, body: NewMailListEntry): Promise<MailListEntry> {
    return this.call("POST", `/v1/inboxes/lists/${encodeURIComponent(direction)}/${encodeURIComponent(list_type)}`, { json: body });
  }

  /** Remove an entry from an account-wide list. `DELETE /v1/inboxes/lists/{direction}/{list_type}/{entry}` */
  removeMailListEntry(direction: string, list_type: string, entry: string): Promise<void> {
    return this.call("DELETE", `/v1/inboxes/lists/${encodeURIComponent(direction)}/${encodeURIComponent(list_type)}/${encodeURIComponent(entry)}`);
  }

  /** One entry of an account-wide list. `GET /v1/inboxes/lists/{direction}/{list_type}/{entry}` */
  getMailListEntry(direction: string, list_type: string, entry: string): Promise<MailListEntry> {
    return this.call("GET", `/v1/inboxes/lists/${encodeURIComponent(direction)}/${encodeURIComponent(list_type)}/${encodeURIComponent(entry)}`);
  }

  /** Messages of every inbox you can see. `GET /v1/inboxes/messages` */
  listAllInboxMessages(query?: { limit?: string | number | boolean; page_token?: string | number | boolean; labels?: string | number | boolean; before?: string | number | boolean; after?: string | number | boolean; ascending?: string | number | boolean; include_spam?: string | number | boolean; include_blocked?: string | number | boolean; include_unauthenticated?: string | number | boolean; include_trash?: string | number | boolean; sender?: string | number | boolean; to?: string | number | boolean; subject?: string | number | boolean; direction?: string | number | boolean }): Promise<InboxMessageList> {
    return this.call("GET", `/v1/inboxes/messages`, { query: query });
  }

  /** Full-text search across every inbox you can see. `GET /v1/inboxes/messages/search` */
  searchAllInboxMessages(query?: { q?: string | number | boolean; limit?: string | number | boolean; page_token?: string | number | boolean; before?: string | number | boolean; after?: string | number | boolean; labels?: string | number | boolean }): Promise<InboxMessageList> {
    return this.call("GET", `/v1/inboxes/messages/search`, { query: query });
  }

  /** Counts of events per type and per day; bounce and complaint rates; storage. `GET /v1/inboxes/metrics` */
  getMailMetrics(query?: { since?: string | number | boolean; until?: string | number | boolean }): Promise<MailMetrics> {
    return this.call("GET", `/v1/inboxes/metrics`, { query: query });
  }

  /** Find inboxes by address or name. `GET /v1/inboxes/search` */
  searchInboxes(query?: { q?: string | number | boolean; limit?: string | number | boolean }): Promise<InboxList> {
    return this.call("GET", `/v1/inboxes/search`, { query: query });
  }

  /** Addresses not sent to any more (hard bounces, complaints). `GET /v1/inboxes/suppressions` */
  listMailSuppressions(): Promise<Array<MailSuppression>> {
    return this.call("GET", `/v1/inboxes/suppressions`);
  }

  /** Send to an address again. `DELETE /v1/inboxes/suppressions/{address}` */
  removeMailSuppression(address: string): Promise<void> {
    return this.call("DELETE", `/v1/inboxes/suppressions/${encodeURIComponent(address)}`);
  }

  /** Conversations of every inbox you can see. `GET /v1/inboxes/threads` */
  listAllInboxThreads(query?: { limit?: string | number | boolean; page_token?: string | number | boolean; labels?: string | number | boolean; before?: string | number | boolean; after?: string | number | boolean; ascending?: string | number | boolean; include_spam?: string | number | boolean; include_blocked?: string | number | boolean; include_unauthenticated?: string | number | boolean; include_trash?: string | number | boolean; sender?: string | number | boolean; to?: string | number | boolean; subject?: string | number | boolean; q?: string | number | boolean }): Promise<InboxThreadList> {
    return this.call("GET", `/v1/inboxes/threads`, { query: query });
  }

  /** A conversation in any inbox you can see. `GET /v1/inboxes/threads/{thread}` */
  getAnyInboxThread(thread: string): Promise<InboxThread> {
    return this.call("GET", `/v1/inboxes/threads/${encodeURIComponent(thread)}`);
  }

  /** Delete an inbox and its messages, threads and drafts (the address is never given out again; its seat stays paid until the period ends). `DELETE /v1/inboxes/{inbox}` */
  deleteInbox(inbox: string): Promise<void> {
    return this.call("DELETE", `/v1/inboxes/${encodeURIComponent(inbox)}`);
  }

  /** One inbox (by id, address, or the part before @). `GET /v1/inboxes/{inbox}` */
  getInbox(inbox: string): Promise<Inbox> {
    return this.call("GET", `/v1/inboxes/${encodeURIComponent(inbox)}`);
  }

  /** Change an inbox: name, metadata (merged; null removes a key), status, scheduled deactivation, signature, expiry, sandbox ("" detaches it). `PATCH /v1/inboxes/{inbox}` */
  updateInbox(inbox: string, body: UpdateInbox): Promise<Inbox> {
    return this.call("PATCH", `/v1/inboxes/${encodeURIComponent(inbox)}`, { json: body });
  }

  /** Drafts, most recently changed first. `GET /v1/inboxes/{inbox}/drafts` */
  listInboxDrafts(inbox: string, query?: { limit?: string | number | boolean; page_token?: string | number | boolean; scheduled?: string | number | boolean }): Promise<DraftList> {
    return this.call("GET", `/v1/inboxes/${encodeURIComponent(inbox)}/drafts`, { query: query });
  }

  /** Make a draft: new, a reply (in_reply_to, reply_all) or a forward (forward_of); with send_at it's scheduled. `POST /v1/inboxes/{inbox}/drafts` */
  createInboxDraft(inbox: string, body: NewDraft): Promise<Draft> {
    return this.call("POST", `/v1/inboxes/${encodeURIComponent(inbox)}/drafts`, { json: body });
  }

  /** Delete a draft (cancels a scheduled send). `DELETE /v1/inboxes/{inbox}/drafts/{id}` */
  deleteInboxDraft(inbox: string, id: string): Promise<void> {
    return this.call("DELETE", `/v1/inboxes/${encodeURIComponent(inbox)}/drafts/${encodeURIComponent(id)}`);
  }

  /** One draft. `GET /v1/inboxes/{inbox}/drafts/{id}` */
  getInboxDraft(inbox: string, id: string): Promise<Draft> {
    return this.call("GET", `/v1/inboxes/${encodeURIComponent(inbox)}/drafts/${encodeURIComponent(id)}`);
  }

  /** Change a draft, its attachments, labels or schedule. `PATCH /v1/inboxes/{inbox}/drafts/{id}` */
  updateInboxDraft(inbox: string, id: string, body: UpdateDraft): Promise<Draft> {
    return this.call("PATCH", `/v1/inboxes/${encodeURIComponent(inbox)}/drafts/${encodeURIComponent(id)}`, { json: body });
  }

  /** A draft attachment's bytes. `GET /v1/inboxes/{inbox}/drafts/{id}/attachments/{att}` */
  getInboxDraftAttachment(inbox: string, id: string, att: string): Promise<Uint8Array> {
    return this.call("GET", `/v1/inboxes/${encodeURIComponent(inbox)}/drafts/${encodeURIComponent(id)}/attachments/${encodeURIComponent(att)}`, { rawResponse: true });
  }

  /** Send a draft now. `POST /v1/inboxes/{inbox}/drafts/{id}/send` */
  sendInboxDraft(inbox: string, id: string): Promise<SendResult> {
    return this.call("POST", `/v1/inboxes/${encodeURIComponent(inbox)}/drafts/${encodeURIComponent(id)}/send`);
  }

  /** One inbox's events. `GET /v1/inboxes/{inbox}/events` */
  listInboxEvents(inbox: string, query?: { after?: string | number | boolean; types?: string | number | boolean; inboxes?: string | number | boolean; limit?: string | number | boolean; wait?: string | number | boolean }): Promise<MailEventList> {
    return this.call("GET", `/v1/inboxes/${encodeURIComponent(inbox)}/events`, { query: query });
  }

  /** Remove an inbox's own forwarding (it uses the account's again). `DELETE /v1/inboxes/{inbox}/forwarding` */
  deleteInboxForwarding(inbox: string): Promise<void> {
    return this.call("DELETE", `/v1/inboxes/${encodeURIComponent(inbox)}/forwarding`);
  }

  /** Where one inbox's mail is forwarded. `GET /v1/inboxes/{inbox}/forwarding` */
  getInboxForwarding(inbox: string): Promise<MailForwarding> {
    return this.call("GET", `/v1/inboxes/${encodeURIComponent(inbox)}/forwarding`);
  }

  /** Set one inbox's forwarding addresses (replaces the account's for it). `PUT /v1/inboxes/{inbox}/forwarding` */
  setInboxForwarding(inbox: string, body: SetForwarding): Promise<MailForwarding> {
    return this.call("PUT", `/v1/inboxes/${encodeURIComponent(inbox)}/forwarding`, { json: body });
  }

  /** An inbox's allow or block list (it comes before the account's). `GET /v1/inboxes/{inbox}/lists/{direction}/{list_type}` */
  listInboxListEntries(inbox: string, direction: string, list_type: string): Promise<Array<MailListEntry>> {
    return this.call("GET", `/v1/inboxes/${encodeURIComponent(inbox)}/lists/${encodeURIComponent(direction)}/${encodeURIComponent(list_type)}`);
  }

  /** Add an address or domain to an inbox's list. `POST /v1/inboxes/{inbox}/lists/{direction}/{list_type}` */
  addInboxListEntry(inbox: string, direction: string, list_type: string, body: NewMailListEntry): Promise<MailListEntry> {
    return this.call("POST", `/v1/inboxes/${encodeURIComponent(inbox)}/lists/${encodeURIComponent(direction)}/${encodeURIComponent(list_type)}`, { json: body });
  }

  /** Remove an entry from an inbox's list. `DELETE /v1/inboxes/{inbox}/lists/{direction}/{list_type}/{entry}` */
  removeInboxListEntry(inbox: string, direction: string, list_type: string, entry: string): Promise<void> {
    return this.call("DELETE", `/v1/inboxes/${encodeURIComponent(inbox)}/lists/${encodeURIComponent(direction)}/${encodeURIComponent(list_type)}/${encodeURIComponent(entry)}`);
  }

  /** One entry of an inbox's list. `GET /v1/inboxes/{inbox}/lists/{direction}/{list_type}/{entry}` */
  getInboxListEntry(inbox: string, direction: string, list_type: string, entry: string): Promise<MailListEntry> {
    return this.call("GET", `/v1/inboxes/${encodeURIComponent(inbox)}/lists/${encodeURIComponent(direction)}/${encodeURIComponent(list_type)}/${encodeURIComponent(entry)}`);
  }

  /** Messages, newest first, without their bodies; spam, blocked, unauthenticated and trash left out unless asked for. `GET /v1/inboxes/{inbox}/messages` */
  listInboxMessages(inbox: string, query?: { limit?: string | number | boolean; page_token?: string | number | boolean; labels?: string | number | boolean; before?: string | number | boolean; after?: string | number | boolean; ascending?: string | number | boolean; include_spam?: string | number | boolean; include_blocked?: string | number | boolean; include_unauthenticated?: string | number | boolean; include_trash?: string | number | boolean; sender?: string | number | boolean; to?: string | number | boolean; subject?: string | number | boolean; direction?: string | number | boolean }): Promise<InboxMessageList> {
    return this.call("GET", `/v1/inboxes/${encodeURIComponent(inbox)}/messages`, { query: query });
  }

  /** Up to 100 messages with their bodies. `POST /v1/inboxes/{inbox}/messages/batch-get` */
  batchGetInboxMessages(inbox: string, body: BatchGetMessages): Promise<InboxMessageList> {
    return this.call("POST", `/v1/inboxes/${encodeURIComponent(inbox)}/messages/batch-get`, { json: body });
  }

  /** Add and remove labels on up to 100 messages. `POST /v1/inboxes/{inbox}/messages/batch-update` */
  batchUpdateInboxMessages(inbox: string, body: BatchUpdateMessages): Promise<BatchResult> {
    return this.call("POST", `/v1/inboxes/${encodeURIComponent(inbox)}/messages/batch-update`, { json: body });
  }

  /** Full-text search (subject, sender, recipients, body), best match first, with a snippet. `GET /v1/inboxes/{inbox}/messages/search` */
  searchInboxMessages(inbox: string, query?: { q?: string | number | boolean; limit?: string | number | boolean; page_token?: string | number | boolean; before?: string | number | boolean; after?: string | number | boolean; labels?: string | number | boolean }): Promise<InboxMessageList> {
    return this.call("GET", `/v1/inboxes/${encodeURIComponent(inbox)}/messages/search`, { query: query });
  }

  /** Send a message (or schedule it with send_at). Idempotency-Key makes it safe to retry. 503 mail_send_off when the server doesn't send mail. `POST /v1/inboxes/{inbox}/messages/send` */
  sendInboxMessage(inbox: string, body: SendMessage): Promise<SendResult> {
    return this.call("POST", `/v1/inboxes/${encodeURIComponent(inbox)}/messages/send`, { json: body });
  }

  /** Delete a message. `DELETE /v1/inboxes/{inbox}/messages/{id}` */
  deleteInboxMessage(inbox: string, id: string): Promise<void> {
    return this.call("DELETE", `/v1/inboxes/${encodeURIComponent(inbox)}/messages/${encodeURIComponent(id)}`);
  }

  /** One message with its text, HTML, reply text, headers, codes, links and attachments. `GET /v1/inboxes/{inbox}/messages/{id}` */
  getInboxMessage(inbox: string, id: string): Promise<InboxMessage> {
    return this.call("GET", `/v1/inboxes/${encodeURIComponent(inbox)}/messages/${encodeURIComponent(id)}`);
  }

  /** Add and remove labels (remove unread to mark it read). `PATCH /v1/inboxes/{inbox}/messages/{id}` */
  updateInboxMessage(inbox: string, id: string, body: UpdateLabels): Promise<InboxMessage> {
    return this.call("PATCH", `/v1/inboxes/${encodeURIComponent(inbox)}/messages/${encodeURIComponent(id)}`, { json: body });
  }

  /** An attachment's bytes. `GET /v1/inboxes/{inbox}/messages/{id}/attachments/{att}` */
  getInboxAttachment(inbox: string, id: string, att: string): Promise<Uint8Array> {
    return this.call("GET", `/v1/inboxes/${encodeURIComponent(inbox)}/messages/${encodeURIComponent(id)}/attachments/${encodeURIComponent(att)}`, { rawResponse: true });
  }

  /** Forward a message with its attachments. `POST /v1/inboxes/{inbox}/messages/{id}/forward` */
  forwardInboxMessage(inbox: string, id: string, body: ForwardMessage): Promise<SendResult> {
    return this.call("POST", `/v1/inboxes/${encodeURIComponent(inbox)}/messages/${encodeURIComponent(id)}/forward`, { json: body });
  }

  /** The message as received or sent (message/rfc822). `GET /v1/inboxes/{inbox}/messages/{id}/raw` */
  getInboxMessageRaw(inbox: string, id: string): Promise<Uint8Array> {
    return this.call("GET", `/v1/inboxes/${encodeURIComponent(inbox)}/messages/${encodeURIComponent(id)}/raw`, { rawResponse: true });
  }

  /** Reply to the sender (Reply-To, else From), in the same thread. `POST /v1/inboxes/{inbox}/messages/{id}/reply` */
  replyToInboxMessage(inbox: string, id: string, body: ReplyMessage): Promise<SendResult> {
    return this.call("POST", `/v1/inboxes/${encodeURIComponent(inbox)}/messages/${encodeURIComponent(id)}/reply`, { json: body });
  }

  /** Reply to the sender and everyone else on the message. `POST /v1/inboxes/{inbox}/messages/{id}/reply-all` */
  replyAllToInboxMessage(inbox: string, id: string, body: ReplyMessage): Promise<SendResult> {
    return this.call("POST", `/v1/inboxes/${encodeURIComponent(inbox)}/messages/${encodeURIComponent(id)}/reply-all`, { json: body });
  }

  /** One inbox's metrics. `GET /v1/inboxes/{inbox}/metrics` */
  getInboxMetrics(inbox: string, query?: { since?: string | number | boolean; until?: string | number | boolean }): Promise<MailMetrics> {
    return this.call("GET", `/v1/inboxes/${encodeURIComponent(inbox)}/metrics`, { query: query });
  }

  /** Conversations, latest first. `GET /v1/inboxes/{inbox}/threads` */
  listInboxThreads(inbox: string, query?: { limit?: string | number | boolean; page_token?: string | number | boolean; labels?: string | number | boolean; before?: string | number | boolean; after?: string | number | boolean; ascending?: string | number | boolean; include_spam?: string | number | boolean; include_blocked?: string | number | boolean; include_unauthenticated?: string | number | boolean; include_trash?: string | number | boolean; sender?: string | number | boolean; to?: string | number | boolean; subject?: string | number | boolean; q?: string | number | boolean }): Promise<InboxThreadList> {
    return this.call("GET", `/v1/inboxes/${encodeURIComponent(inbox)}/threads`, { query: query });
  }

  /** Delete a conversation and its messages. `DELETE /v1/inboxes/{inbox}/threads/{thread}` */
  deleteInboxThread(inbox: string, thread: string): Promise<void> {
    return this.call("DELETE", `/v1/inboxes/${encodeURIComponent(inbox)}/threads/${encodeURIComponent(thread)}`);
  }

  /** A conversation with its messages, oldest first. `GET /v1/inboxes/{inbox}/threads/{thread}` */
  getInboxThread(inbox: string, thread: string): Promise<InboxThread> {
    return this.call("GET", `/v1/inboxes/${encodeURIComponent(inbox)}/threads/${encodeURIComponent(thread)}`);
  }

  /** Add and remove labels on every message of a conversation. `PATCH /v1/inboxes/{inbox}/threads/{thread}` */
  updateInboxThread(inbox: string, thread: string, body: UpdateLabels): Promise<InboxThread> {
    return this.call("PATCH", `/v1/inboxes/${encodeURIComponent(inbox)}/threads/${encodeURIComponent(thread)}`, { json: body });
  }

  /** Wait for the next received message (its one-time codes and verification links already pulled out); spam, blocked and unauthenticated mail doesn't count; message is null on timeout. `GET /v1/inboxes/{inbox}/wait` */
  waitForInboxMessage(inbox: string, query?: { since?: string | number | boolean; after?: string | number | boolean; sender?: string | number | boolean; subject?: string | number | boolean; timeout?: string | number | boolean }): Promise<InboxWait> {
    return this.call("GET", `/v1/inboxes/${encodeURIComponent(inbox)}/wait`, { query: query });
  }

  /** Put a welcome email in the inbox (from froog, delivered directly; at most 5 an hour). `POST /v1/inboxes/{inbox}/welcome` */
  sendInboxWelcome(inbox: string): Promise<InboxMessage> {
    return this.call("POST", `/v1/inboxes/${encodeURIComponent(inbox)}/welcome`);
  }

  /** What the account can run now: sandboxes at once, sizes, trial, start limits. `GET /v1/limits` */
  getLimits(): Promise<Limits> {
    return this.call("GET", `/v1/limits`);
  }

  /** Accept an invitation with its token (a dashboard session or a full-access key). `POST /v1/org-invites/accept` */
  acceptOrgInvite(body: AcceptOrgInvite): Promise<Org> {
    return this.call("POST", `/v1/org-invites/accept`, { json: body });
  }

  /** What an invitation is for (organization, role, who sent it), before accepting it. `GET /v1/org-invites/{token}` */
  previewOrgInvite(token: string): Promise<OrgInvitePreview> {
    return this.call("GET", `/v1/org-invites/${encodeURIComponent(token)}`);
  }

  /** Your organizations (and your own account), with the active one. `GET /v1/orgs` */
  listOrgs(): Promise<OrgList> {
    return this.call("GET", `/v1/orgs`);
  }

  /** Make an organization: a shared account with members, roles and one bill; you're its owner. `POST /v1/orgs` */
  createOrg(body: CreateOrg): Promise<Org> {
    return this.call("POST", `/v1/orgs`, { json: body });
  }

  /** Choose the organization the dashboard and keys without X-Froog-Org act in (null: your own account). `PATCH /v1/orgs/active` */
  setActiveOrg(body: SetActiveOrg): Promise<OrgList> {
    return this.call("PATCH", `/v1/orgs/active`, { json: body });
  }

  /** Delete an organization (owner; it must have no sandboxes left). `DELETE /v1/orgs/{org}` */
  deleteOrg(org: string): Promise<void> {
    return this.call("DELETE", `/v1/orgs/${encodeURIComponent(org)}`);
  }

  /** One organization. `GET /v1/orgs/{org}` */
  getOrg(org: string): Promise<Org> {
    return this.call("GET", `/v1/orgs/${encodeURIComponent(org)}`);
  }

  /** Rename an organization or change its settings (owner or admin). `PATCH /v1/orgs/{org}` */
  updateOrg(org: string, body: UpdateOrg): Promise<Org> {
    return this.call("PATCH", `/v1/orgs/${encodeURIComponent(org)}`, { json: body });
  }

  /** Invite someone by email (a seat is taken when they accept). `POST /v1/orgs/{org}/invites` */
  inviteOrgMember(org: string, body: NewOrgInvite): Promise<OrgInvite> {
    return this.call("POST", `/v1/orgs/${encodeURIComponent(org)}/invites`, { json: body });
  }

  /** Revoke an invitation. `DELETE /v1/orgs/{org}/invites/{id}` */
  revokeOrgInvite(org: string, id: string): Promise<void> {
    return this.call("DELETE", `/v1/orgs/${encodeURIComponent(org)}/invites/${encodeURIComponent(id)}`);
  }

  /** Leave an organization. `POST /v1/orgs/{org}/leave` */
  leaveOrg(org: string): Promise<void> {
    return this.call("POST", `/v1/orgs/${encodeURIComponent(org)}/leave`);
  }

  /** An organization's members and open invitations. `GET /v1/orgs/{org}/members` */
  listOrgMembers(org: string): Promise<OrgMembers> {
    return this.call("GET", `/v1/orgs/${encodeURIComponent(org)}/members`);
  }

  /** Remove a member from an organization. `DELETE /v1/orgs/{org}/members/{member}` */
  removeOrgMember(org: string, member: string): Promise<void> {
    return this.call("DELETE", `/v1/orgs/${encodeURIComponent(org)}/members/${encodeURIComponent(member)}`);
  }

  /** Change a member's role or limits (running sandboxes, monthly usage). `PATCH /v1/orgs/{org}/members/{member}` */
  updateOrgMember(org: string, member: string, body: UpdateOrgMember): Promise<OrgMember> {
    return this.call("PATCH", `/v1/orgs/${encodeURIComponent(org)}/members/${encodeURIComponent(member)}`, { json: body });
  }

  /** Set how many seats the organization pays for. `PUT /v1/orgs/{org}/seats` */
  setOrgSeats(org: string, body: SetSeats): Promise<Org> {
    return this.call("PUT", `/v1/orgs/${encodeURIComponent(org)}/seats`, { json: body });
  }

  /** Make another member the owner (owner only). `POST /v1/orgs/{org}/transfer` */
  transferOrg(org: string, body: TransferOrg): Promise<Org> {
    return this.call("POST", `/v1/orgs/${encodeURIComponent(org)}/transfer`, { json: body });
  }

  /** The harnesses, their models, effort levels and fast mode. `GET /v1/provider-models` */
  providerModels(): Promise<Array<ProviderModels>> {
    return this.call("GET", `/v1/provider-models`, { auth: false });
  }

  /** What you pay for monitors: free monitors, paid ones used, seats paid for. `GET /v1/revere/billing` */
  getRevereBilling(): Promise<RevereBilling> {
    return this.call("GET", `/v1/revere/billing`);
  }

  /** A Stripe Checkout page that buys paid monitors. `POST /v1/revere/billing/checkout` */
  createRevereCheckout(body: RevereCheckout): Promise<BillingUrl> {
    return this.call("POST", `/v1/revere/billing/checkout`, { json: body });
  }

  /** Your alert contacts: Slack, Discord, Google Chat or ntfy channels that hear when monitors go down and up. `GET /v1/revere/contacts` */
  listRevereContacts(): Promise<RevereContactList> {
    return this.call("GET", `/v1/revere/contacts`);
  }

  /** Add an alert contact (an incoming-webhook or ntfy topic URL), for every monitor or some. `POST /v1/revere/contacts` */
  createRevereContact(body: CreateRevereContact): Promise<RevereContact> {
    return this.call("POST", `/v1/revere/contacts`, { json: body });
  }

  /** Delete an alert contact. `DELETE /v1/revere/contacts/{contact}` */
  deleteRevereContact(contact: string): Promise<void> {
    return this.call("DELETE", `/v1/revere/contacts/${encodeURIComponent(contact)}`);
  }

  /** One alert contact (by id or name). `GET /v1/revere/contacts/{contact}` */
  getRevereContact(contact: string): Promise<RevereContact> {
    return this.call("GET", `/v1/revere/contacts/${encodeURIComponent(contact)}`);
  }

  /** Change an alert contact: name, URL, monitors, paused. `PATCH /v1/revere/contacts/{contact}` */
  updateRevereContact(contact: string, body: UpdateRevereContact): Promise<RevereContact> {
    return this.call("PATCH", `/v1/revere/contacts/${encodeURIComponent(contact)}`, { json: body });
  }

  /** Send a test message now (502 contact_failed if it didn't go through). `POST /v1/revere/contacts/{contact}/test` */
  testRevereContact(contact: string): Promise<RevereContact> {
    return this.call("POST", `/v1/revere/contacts/${encodeURIComponent(contact)}/test`);
  }

  /** A heartbeat check-in (no key: the URL is the secret). POST works too. `GET /v1/revere/heartbeat/{token}` */
  revereHeartbeat(token: string): Promise<void> {
    return this.call("GET", `/v1/revere/heartbeat/${encodeURIComponent(token)}`);
  }

  /** A heartbeat check-in. `POST /v1/revere/heartbeat/{token}` */
  postRevereHeartbeat(token: string): Promise<void> {
    return this.call("POST", `/v1/revere/heartbeat/${encodeURIComponent(token)}`);
  }

  /** Report that the job failed: the heartbeat is down. `GET /v1/revere/heartbeat/{token}/fail` */
  failRevereHeartbeat(token: string, query?: { msg?: string | number | boolean }): Promise<void> {
    return this.call("GET", `/v1/revere/heartbeat/${encodeURIComponent(token)}/fail`, { query: query });
  }

  /** Report that the job failed. `POST /v1/revere/heartbeat/{token}/fail` */
  postFailRevereHeartbeat(token: string, query?: { msg?: string | number | boolean }): Promise<void> {
    return this.call("POST", `/v1/revere/heartbeat/${encodeURIComponent(token)}/fail`, { query: query });
  }

  /** Your uptime monitors, with their status and uptime. `GET /v1/revere/monitors` */
  listRevereMonitors(query?: { history?: string | number | boolean }): Promise<RevereMonitorList> {
    return this.call("GET", `/v1/revere/monitors`, { query: query });
  }

  /** Add a monitor: a URL (http), host:port (tcp), a host (icmp) or no target (heartbeat). 5 monitors checked every 5 minutes are free; others are $1 a month (402 revere_payment_required without a monitor subscription). `POST /v1/revere/monitors` */
  createRevereMonitor(body: CreateRevereMonitor): Promise<RevereMonitor> {
    return this.call("POST", `/v1/revere/monitors`, { json: body });
  }

  /** Delete a monitor and its history. `DELETE /v1/revere/monitors/{monitor}` */
  deleteRevereMonitor(monitor: string): Promise<void> {
    return this.call("DELETE", `/v1/revere/monitors/${encodeURIComponent(monitor)}`);
  }

  /** One monitor (by id or name). `GET /v1/revere/monitors/{monitor}` */
  getRevereMonitor(monitor: string): Promise<RevereMonitor> {
    return this.call("GET", `/v1/revere/monitors/${encodeURIComponent(monitor)}`);
  }

  /** Change a monitor; paused pauses or resumes it. `PATCH /v1/revere/monitors/{monitor}` */
  updateRevereMonitor(monitor: string, body: UpdateRevereMonitor): Promise<RevereMonitor> {
    return this.call("PATCH", `/v1/revere/monitors/${encodeURIComponent(monitor)}`, { json: body });
  }

  /** Check now (once every 10 s at most) and record it. `POST /v1/revere/monitors/{monitor}/check` */
  checkRevereMonitor(monitor: string): Promise<RevereCheck> {
    return this.call("POST", `/v1/revere/monitors/${encodeURIComponent(monitor)}/check`);
  }

  /** A monitor's checks, newest first (kept 7 days). `GET /v1/revere/monitors/{monitor}/checks` */
  listRevereChecks(monitor: string, query?: { since?: string | number | boolean; limit?: string | number | boolean }): Promise<RevereCheckList> {
    return this.call("GET", `/v1/revere/monitors/${encodeURIComponent(monitor)}/checks`, { query: query });
  }

  /** Uptime and response times (avg, min, max) over a range, in buckets. `GET /v1/revere/monitors/{monitor}/history` */
  getRevereHistory(monitor: string, query?: { range?: string | number | boolean }): Promise<RevereHistory> {
    return this.call("GET", `/v1/revere/monitors/${encodeURIComponent(monitor)}/history`, { query: query });
  }

  /** Times a monitor was down, newest first. `GET /v1/revere/monitors/{monitor}/outages` */
  listRevereOutages(monitor: string, query?: { limit?: string | number | boolean }): Promise<RevereOutageList> {
    return this.call("GET", `/v1/revere/monitors/${encodeURIComponent(monitor)}/outages`, { query: query });
  }

  /** Your status pages. `GET /v1/revere/pages` */
  listStatusPages(): Promise<StatusPageList> {
    return this.call("GET", `/v1/revere/pages`);
  }

  /** Make a status page (https://status.froogusercontent.com/<slug>, or your own domain). `POST /v1/revere/pages` */
  createStatusPage(body: CreateStatusPage): Promise<StatusPage> {
    return this.call("POST", `/v1/revere/pages`, { json: body });
  }

  /** Delete a status page, its incidents and subscribers. `DELETE /v1/revere/pages/{page}` */
  deleteStatusPage(page: string): Promise<void> {
    return this.call("DELETE", `/v1/revere/pages/${encodeURIComponent(page)}`);
  }

  /** One status page (by id or slug). `GET /v1/revere/pages/{page}` */
  getStatusPage(page: string): Promise<StatusPage> {
    return this.call("GET", `/v1/revere/pages/${encodeURIComponent(page)}`);
  }

  /** Change a status page: title, monitors, custom domain (null removes it), .... `PATCH /v1/revere/pages/{page}` */
  updateStatusPage(page: string, body: UpdateStatusPage): Promise<StatusPage> {
    return this.call("PATCH", `/v1/revere/pages/${encodeURIComponent(page)}`, { json: body });
  }

  /** Look up the custom domain's CNAME and TXT records now. `POST /v1/revere/pages/{page}/domain/verify` */
  verifyStatusPageDomain(page: string): Promise<StatusPage> {
    return this.call("POST", `/v1/revere/pages/${encodeURIComponent(page)}/domain/verify`);
  }

  /** A page's incidents and maintenance, newest first. `GET /v1/revere/pages/{page}/incidents` */
  listStatusIncidents(page: string, query?: { limit?: string | number | boolean }): Promise<StatusIncidentList> {
    return this.call("GET", `/v1/revere/pages/${encodeURIComponent(page)}/incidents`, { query: query });
  }

  /** Post an incident or schedule maintenance (subscribers are emailed unless notify is false). `POST /v1/revere/pages/{page}/incidents` */
  createStatusIncident(page: string, body: CreateStatusIncident): Promise<StatusIncident> {
    return this.call("POST", `/v1/revere/pages/${encodeURIComponent(page)}/incidents`, { json: body });
  }

  /** Delete an incident. `DELETE /v1/revere/pages/{page}/incidents/{id}` */
  deleteStatusIncident(page: string, id: string): Promise<void> {
    return this.call("DELETE", `/v1/revere/pages/${encodeURIComponent(page)}/incidents/${encodeURIComponent(id)}`);
  }

  /** One incident with its updates. `GET /v1/revere/pages/{page}/incidents/{id}` */
  getStatusIncident(page: string, id: string): Promise<StatusIncident> {
    return this.call("GET", `/v1/revere/pages/${encodeURIComponent(page)}/incidents/${encodeURIComponent(id)}`);
  }

  /** Fix an incident's title, impact, monitors or window (no email). `PATCH /v1/revere/pages/{page}/incidents/{id}` */
  updateStatusIncident(page: string, id: string, body: UpdateStatusIncident): Promise<StatusIncident> {
    return this.call("PATCH", `/v1/revere/pages/${encodeURIComponent(page)}/incidents/${encodeURIComponent(id)}`, { json: body });
  }

  /** Post an update: a new status and what's happening. `POST /v1/revere/pages/{page}/incidents/{id}/updates` */
  addStatusIncidentUpdate(page: string, id: string, body: CreateStatusIncidentUpdate): Promise<StatusIncident> {
    return this.call("POST", `/v1/revere/pages/${encodeURIComponent(page)}/incidents/${encodeURIComponent(id)}/updates`, { json: body });
  }

  /** A page's email subscribers. `GET /v1/revere/pages/{page}/subscribers` */
  listStatusSubscribers(page: string): Promise<StatusSubscriberList> {
    return this.call("GET", `/v1/revere/pages/${encodeURIComponent(page)}/subscribers`);
  }

  /** Remove a subscriber (by id or email). `DELETE /v1/revere/pages/{page}/subscribers/{id}` */
  removeStatusSubscriber(page: string, id: string): Promise<void> {
    return this.call("DELETE", `/v1/revere/pages/${encodeURIComponent(page)}/subscribers/${encodeURIComponent(id)}`);
  }

  /** Sandboxes, oldest first, filtered and paged. `GET /v1/sandboxes` */
  listSandboxes(query?: { label?: string | string[]; name?: string | number | boolean; name_prefix?: string | number | boolean; state?: string | number | boolean; sort?: string | number | boolean; limit?: string | number | boolean; cursor?: string | number | boolean }): Promise<Array<Sandbox>> {
    return this.call("GET", `/v1/sandboxes`, { query: query });
  }

  /** Create sandboxes (202; poll until running). `POST /v1/sandboxes` */
  createSandboxes(body: CreateSandbox, idempotencyKey?: string): Promise<Array<Sandbox>> {
    return this.call("POST", `/v1/sandboxes`, { json: body, idempotencyKey: idempotencyKey });
  }

  /** Delete a sandbox (saved snapshots stay). `DELETE /v1/sandboxes/{name}` */
  deleteSandbox(name: string): Promise<void> {
    return this.call("DELETE", `/v1/sandboxes/${encodeURIComponent(name)}`);
  }

  /** One sandbox. `GET /v1/sandboxes/{name}` */
  getSandbox(name: string): Promise<Sandbox> {
    return this.call("GET", `/v1/sandboxes/${encodeURIComponent(name)}`);
  }

  /** Rename; change the auto-stop timer (counting from now while running), lifetime, auto-delete, auto-start or labels. `PATCH /v1/sandboxes/{name}` */
  updateSandbox(name: string, body: UpdateSandbox): Promise<Sandbox> {
    return this.call("PATCH", `/v1/sandboxes/${encodeURIComponent(name)}`, { json: body });
  }

  /** A sandbox's AI profile, proxy state, block, and usage per day and model. `GET /v1/sandboxes/{name}/ai` */
  getSandboxAi(name: string, query?: { days?: string | number | boolean }): Promise<SandboxAi> {
    return this.call("GET", `/v1/sandboxes/${encodeURIComponent(name)}/ai`, { query: query });
  }

  /** Block or unblock a sandbox's AI requests, or give it another profile. `PUT /v1/sandboxes/{name}/ai` */
  updateSandboxAi(name: string, body: UpdateSandboxAi): Promise<SandboxAi> {
    return this.call("PUT", `/v1/sandboxes/${encodeURIComponent(name)}/ai`, { json: body });
  }

  /** A link to the browser view: only Chrome, 1920x1080. `POST /v1/sandboxes/{name}/browser` */
  getBrowserLink(name: string, body: BrowserRequest, query?: { theme?: string | number | boolean }): Promise<DesktopLink> {
    return this.call("POST", `/v1/sandboxes/${encodeURIComponent(name)}/browser`, { json: body, query: query });
  }

  /** Commands run in the sandbox, newest first (90 days, also while stopped). `GET /v1/sandboxes/{name}/command-history` */
  listCommands(name: string, query?: { mode?: string | number | boolean; sort?: string | number | boolean; limit?: string | number | boolean; cursor?: string | number | boolean }): Promise<CommandList> {
    return this.call("GET", `/v1/sandboxes/${encodeURIComponent(name)}/command-history`, { query: query });
  }

  /** One command's record. `GET /v1/sandboxes/{name}/command-history/{id}` */
  getCommand(name: string, id: string): Promise<CommandRecord> {
    return this.call("GET", `/v1/sandboxes/${encodeURIComponent(name)}/command-history/${encodeURIComponent(id)}`);
  }

  /** A command's stored output from an offset (at most 1 MiB). `GET /v1/sandboxes/{name}/command-history/{id}/logs` */
  readCommandLogs(name: string, id: string, query?: { stream?: string | number | boolean; offset?: string | number | boolean; encoding?: string | number | boolean }): Promise<CommandLogs> {
    return this.call("GET", `/v1/sandboxes/${encodeURIComponent(name)}/command-history/${encodeURIComponent(id)}/logs`, { query: query });
  }

  /** Conversations, most recent first. `GET /v1/sandboxes/{name}/conversations` */
  listConversations(name: string): Promise<ConversationList> {
    return this.call("GET", `/v1/sandboxes/${encodeURIComponent(name)}/conversations`);
  }

  /** Delete a conversation and its history. `DELETE /v1/sandboxes/{name}/conversations/{id}` */
  deleteConversation(name: string, id: string): Promise<void> {
    return this.call("DELETE", `/v1/sandboxes/${encodeURIComponent(name)}/conversations/${encodeURIComponent(id)}`);
  }

  /** A conversation and its turns (id or current). `GET /v1/sandboxes/{name}/conversations/{id}` */
  getConversation(name: string, id: string): Promise<ConversationDetail> {
    return this.call("GET", `/v1/sandboxes/${encodeURIComponent(name)}/conversations/${encodeURIComponent(id)}`);
  }

  /** A link to the desktop (1920x1080) in froog's viewer. `POST /v1/sandboxes/{name}/desktop` */
  getDesktopLink(name: string, query?: { theme?: string | number | boolean }): Promise<DesktopLink> {
    return this.call("POST", `/v1/sandboxes/${encodeURIComponent(name)}/desktop`, { query: query });
  }

  /** Every conversation's events: a JSON page, or a stream (Accept: text/event-stream or application/x-ndjson). `GET /v1/sandboxes/{name}/events` */
  listEvents(name: string, query?: { conversation?: string | number | boolean; cursor?: string | number | boolean; limit?: string | number | boolean }): Promise<EventList> {
    return this.call("GET", `/v1/sandboxes/${encodeURIComponent(name)}/events`, { query: query });
  }

  /** Run a command and wait for it; with stream: true, NDJSON events as output arrives. `POST /v1/sandboxes/{name}/exec` */
  exec(name: string, body: ExecRequest): Promise<ExecResult> {
    return this.call("POST", `/v1/sandboxes/${encodeURIComponent(name)}/exec`, { json: body });
  }

  /** Delete a file or directory. `DELETE /v1/sandboxes/{name}/files` */
  deleteFile(name: string, query: { path: string | number | boolean; recursive?: string | number | boolean }): Promise<void> {
    return this.call("DELETE", `/v1/sandboxes/${encodeURIComponent(name)}/files`, { query: query });
  }

  /** A file's details or a directory listing. `GET /v1/sandboxes/{name}/files` */
  fileInfo(name: string, query: { path: string | number | boolean }): Promise<FileInfo> {
    return this.call("GET", `/v1/sandboxes/${encodeURIComponent(name)}/files`, { query: query });
  }

  /** Unpack a .tar.gz into a directory (raw bytes, up to 100 MiB). `PUT /v1/sandboxes/{name}/files/archive` */
  uploadArchive(name: string, data: BodyInit, query: { path: string | number | boolean }): Promise<void> {
    return this.call("PUT", `/v1/sandboxes/${encodeURIComponent(name)}/files/archive`, { raw: data, query: query });
  }

  /** Download a file (raw bytes, up to 100 MiB). `GET /v1/sandboxes/{name}/files/content` */
  readFile(name: string, query: { path: string | number | boolean }): Promise<Uint8Array> {
    return this.call("GET", `/v1/sandboxes/${encodeURIComponent(name)}/files/content`, { query: query, rawResponse: true });
  }

  /** Upload a file (raw bytes, up to 100 MiB, atomic). `PUT /v1/sandboxes/{name}/files/content` */
  writeFile(name: string, data: BodyInit, query: { path: string | number | boolean; mode?: string | number | boolean }): Promise<void> {
    return this.call("PUT", `/v1/sandboxes/${encodeURIComponent(name)}/files/content`, { raw: data, query: query });
  }

  /** A link that downloads a file without an API key. `POST /v1/sandboxes/{name}/files/download-url` */
  createDownloadUrl(name: string, body: NewFileUrl): Promise<FileUrl> {
    return this.call("POST", `/v1/sandboxes/${encodeURIComponent(name)}/files/download-url`, { json: body });
  }

  /** Lines that contain a text. `GET /v1/sandboxes/{name}/files/find` */
  findInFiles(name: string, query: { pattern: string | number | boolean; path: string | number | boolean; regex?: string | number | boolean }): Promise<FileFind> {
    return this.call("GET", `/v1/sandboxes/${encodeURIComponent(name)}/files/find`, { query: query });
  }

  /** Create a directory (and parents). `POST /v1/sandboxes/{name}/files/mkdir` */
  makeDirectory(name: string, body: MakeDir): Promise<void> {
    return this.call("POST", `/v1/sandboxes/${encodeURIComponent(name)}/files/mkdir`, { json: body });
  }

  /** Move or rename. `POST /v1/sandboxes/{name}/files/move` */
  moveFile(name: string, body: MoveFile): Promise<void> {
    return this.call("POST", `/v1/sandboxes/${encodeURIComponent(name)}/files/move`, { json: body });
  }

  /** Change a file's or directory's permissions (chmod). `POST /v1/sandboxes/{name}/files/permissions` */
  setFilePermissions(name: string, body: FilePermissions): Promise<void> {
    return this.call("POST", `/v1/sandboxes/${encodeURIComponent(name)}/files/permissions`, { json: body });
  }

  /** Replace a text in files, byte for byte. `POST /v1/sandboxes/{name}/files/replace` */
  replaceInFiles(name: string, body: FileReplace): Promise<Array<FileReplaced>> {
    return this.call("POST", `/v1/sandboxes/${encodeURIComponent(name)}/files/replace`, { json: body });
  }

  /** Files whose name matches a glob. `GET /v1/sandboxes/{name}/files/search` */
  searchFiles(name: string, query: { pattern: string | number | boolean; path: string | number | boolean }): Promise<FileSearch> {
    return this.call("GET", `/v1/sandboxes/${encodeURIComponent(name)}/files/search`, { query: query });
  }

  /** A link that takes a PUT of a file without an API key. `POST /v1/sandboxes/{name}/files/upload-url` */
  createUploadUrl(name: string, body: NewFileUrl): Promise<FileUrl> {
    return this.call("POST", `/v1/sandboxes/${encodeURIComponent(name)}/files/upload-url`, { json: body });
  }

  /** Stream file changes under a path (NDJSON: ready, then create / modify / delete, then end). `GET /v1/sandboxes/{name}/files/watch` (NDJSON: `for await (const e of ...)`) */
  watchFiles(name: string, query: { path: string | number | boolean; recursive?: string | number | boolean; timeout_secs?: string | number | boolean }): AsyncGenerator<FileEvent> {
    return this.stream(`/v1/sandboxes/${encodeURIComponent(name)}/files/watch`, query);
  }

  /** New sandboxes from a snapshot of this one. `POST /v1/sandboxes/{name}/fork` */
  forkSandbox(name: string, body: ForkSandbox, idempotencyKey?: string): Promise<Array<Sandbox>> {
    return this.call("POST", `/v1/sandboxes/${encodeURIComponent(name)}/fork`, { json: body, idempotencyKey: idempotencyKey });
  }

  /** A one-hour GitHub token for the sandbox (what its git credential helper uses; needs the environment). `POST /v1/sandboxes/{name}/github-token` */
  getSandboxGithubToken(name: string, body: GithubTokenRequest): Promise<GithubToken> {
    return this.call("POST", `/v1/sandboxes/${encodeURIComponent(name)}/github-token`, { json: body });
  }

  /** Stop running turns and cancel queued prompts (one conversation, or all). `POST /v1/sandboxes/{name}/interrupt` */
  interrupt(name: string, body: InterruptRequest): Promise<InterruptResult> {
    return this.call("POST", `/v1/sandboxes/${encodeURIComponent(name)}/interrupt`, { json: body });
  }

  /** Background commands. `GET /v1/sandboxes/{name}/jobs` */
  listJobs(name: string): Promise<Array<Job>> {
    return this.call("GET", `/v1/sandboxes/${encodeURIComponent(name)}/jobs`);
  }

  /** Start a background command. `POST /v1/sandboxes/{name}/jobs` */
  startJob(name: string, body: NewJob): Promise<Job> {
    return this.call("POST", `/v1/sandboxes/${encodeURIComponent(name)}/jobs`, { json: body });
  }

  /** A background command's state and output from an offset. `GET /v1/sandboxes/{name}/jobs/{id}` */
  readJob(name: string, id: string, query?: { offset?: string | number | boolean; limit?: string | number | boolean }): Promise<JobOutput> {
    return this.call("GET", `/v1/sandboxes/${encodeURIComponent(name)}/jobs/${encodeURIComponent(id)}`, { query: query });
  }

  /** Write to a background command's open standard input (started with stdin_open), or close it. `POST /v1/sandboxes/{name}/jobs/{id}/stdin` */
  writeJobStdin(name: string, id: string, body: JobStdin): Promise<void> {
    return this.call("POST", `/v1/sandboxes/${encodeURIComponent(name)}/jobs/${encodeURIComponent(id)}/stdin`, { json: body });
  }

  /** Stop a background command. `POST /v1/sandboxes/{name}/jobs/{id}/stop` */
  stopJob(name: string, id: string): Promise<void> {
    return this.call("POST", `/v1/sandboxes/${encodeURIComponent(name)}/jobs/${encodeURIComponent(id)}/stop`);
  }

  /** CPU, memory, disk and network of a running sandbox, read now. `GET /v1/sandboxes/{name}/metrics` */
  getSandboxMetrics(name: string): Promise<SandboxMetrics> {
    return this.call("GET", `/v1/sandboxes/${encodeURIComponent(name)}/metrics`);
  }

  /** CPU, memory and disk every 30 seconds, kept 7 days, averaged per step. `GET /v1/sandboxes/{name}/metrics/history` */
  getSandboxMetricsHistory(name: string, query?: { since?: string | number | boolean; until?: string | number | boolean; step?: string | number | boolean }): Promise<MetricsHistory> {
    return this.call("GET", `/v1/sandboxes/${encodeURIComponent(name)}/metrics/history`, { query: query });
  }

  /** Inbound ports open on the sandbox (besides SSH), including its public URLs' ports, and the host IPv4 address and port each opened one is reached at. `GET /v1/sandboxes/{name}/ports` */
  listPorts(name: string): Promise<Ports> {
    return this.call("GET", `/v1/sandboxes/${encodeURIComponent(name)}/ports`);
  }

  /** Open an inbound TCP or UDP port: on the sandbox's IPv6 address, and on a public port of its host's IPv4 address. `POST /v1/sandboxes/{name}/ports` */
  openPort(name: string, body: OpenPort): Promise<Ports> {
    return this.call("POST", `/v1/sandboxes/${encodeURIComponent(name)}/ports`, { json: body });
  }

  /** Set the opened ports, replacing the ones opened before (kept across stops and starts). `PUT /v1/sandboxes/{name}/ports` */
  setPorts(name: string, body: SetPorts): Promise<Ports> {
    return this.call("PUT", `/v1/sandboxes/${encodeURIComponent(name)}/ports`, { json: body });
  }

  /** Stream TCP ports starting or stopping to listen (NDJSON: ready, open / close, end). `GET /v1/sandboxes/{name}/ports/watch` (NDJSON: `for await (const e of ...)`) */
  watchPorts(name: string, query?: { timeout_secs?: string | number | boolean }): AsyncGenerator<PortEvent> {
    return this.stream(`/v1/sandboxes/${encodeURIComponent(name)}/ports/watch`, query);
  }

  /** Close an opened port (IPv6 and IPv4). `DELETE /v1/sandboxes/{name}/ports/{port}/{protocol}` */
  closePort(name: string, port: string, protocol: string): Promise<Ports> {
    return this.call("DELETE", `/v1/sandboxes/${encodeURIComponent(name)}/ports/${encodeURIComponent(port)}/${encodeURIComponent(protocol)}`);
  }

  /** Processes, busiest first (a stopped sandbox: the sample taken at stop). `GET /v1/sandboxes/{name}/processes` */
  listProcesses(name: string): Promise<ProcessList> {
    return this.call("GET", `/v1/sandboxes/${encodeURIComponent(name)}/processes`);
  }

  /** Processes seen in the 30-second samples, with start and end times, kept 72 hours. `GET /v1/sandboxes/{name}/processes/records` */
  listProcessRecords(name: string, query?: { since?: string | number | boolean; until?: string | number | boolean; running?: string | number | boolean; limit?: string | number | boolean }): Promise<ProcessRecords> {
    return this.call("GET", `/v1/sandboxes/${encodeURIComponent(name)}/processes/records`, { query: query });
  }

  /** The 12 busiest processes every 30 seconds, kept 7 days, newest first. `GET /v1/sandboxes/{name}/processes/samples` */
  listProcessSamples(name: string, query?: { since?: string | number | boolean; until?: string | number | boolean; limit?: string | number | boolean }): Promise<ProcessSamples> {
    return this.call("GET", `/v1/sandboxes/${encodeURIComponent(name)}/processes/samples`, { query: query });
  }

  /** Prompt a coding agent and wait for its answer (continues the current conversation). `POST /v1/sandboxes/{name}/prompt` */
  prompt(name: string, body: PromptRequest): Promise<PromptResult> {
    return this.call("POST", `/v1/sandboxes/${encodeURIComponent(name)}/prompt`, { json: body });
  }

  /** Prompts, newest first. `GET /v1/sandboxes/{name}/prompts` */
  listPrompts(name: string, query?: { conversation?: string | number | boolean; limit?: string | number | boolean }): Promise<PromptList> {
    return this.call("GET", `/v1/sandboxes/${encodeURIComponent(name)}/prompts`, { query: query });
  }

  /** Queue a prompt for a coding agent (returns at once; follow its events). `POST /v1/sandboxes/{name}/prompts` */
  queuePrompt(name: string, body: PromptRequest): Promise<Prompt> {
    return this.call("POST", `/v1/sandboxes/${encodeURIComponent(name)}/prompts`, { json: body });
  }

  /** One prompt: status (queued, running, done, failed, interrupted), result, error. `GET /v1/sandboxes/{name}/prompts/{id}` */
  getPrompt(name: string, id: string): Promise<Prompt> {
    return this.call("GET", `/v1/sandboxes/${encodeURIComponent(name)}/prompts/${encodeURIComponent(id)}`);
  }

  /** A prompt's events: a JSON page, or a stream until it ends (Accept: text/event-stream or application/x-ndjson). `GET /v1/sandboxes/{name}/prompts/{id}/events` */
  promptEvents(name: string, id: string, query?: { cursor?: string | number | boolean; limit?: string | number | boolean }): Promise<EventList> {
    return this.call("GET", `/v1/sandboxes/${encodeURIComponent(name)}/prompts/${encodeURIComponent(id)}/events`, { query: query });
  }

  /** The model catalog plus the models the harnesses list in this sandbox. `GET /v1/sandboxes/{name}/provider-models` */
  sandboxProviderModels(name: string): Promise<Array<ProviderModels>> {
    return this.call("GET", `/v1/sandboxes/${encodeURIComponent(name)}/provider-models`);
  }

  /** Roll the sandbox back to a snapshot. `POST /v1/sandboxes/{name}/restore` */
  restoreSandbox(name: string, body: Restore): Promise<Sandbox> {
    return this.call("POST", `/v1/sandboxes/${encodeURIComponent(name)}/restore`, { json: body });
  }

  /** In an organization: let every member see and use the sandbox. `POST /v1/sandboxes/{name}/share` */
  shareSandbox(name: string): Promise<Sandbox> {
    return this.call("POST", `/v1/sandboxes/${encodeURIComponent(name)}/share`);
  }

  /** Delete every automatic snapshot (saved ones and the one a stopped sandbox starts from stay). `DELETE /v1/sandboxes/{name}/snapshots` */
  deleteAutoSnapshots(name: string): Promise<DeletedSnapshots> {
    return this.call("DELETE", `/v1/sandboxes/${encodeURIComponent(name)}/snapshots`);
  }

  /** A sandbox's snapshots, oldest first, paged. `GET /v1/sandboxes/{name}/snapshots` */
  listSnapshots(name: string, query?: { sort?: string | number | boolean; limit?: string | number | boolean; cursor?: string | number | boolean }): Promise<Array<Snapshot>> {
    return this.call("GET", `/v1/sandboxes/${encodeURIComponent(name)}/snapshots`, { query: query });
  }

  /** Save a snapshot (with a label: an account template). `POST /v1/sandboxes/{name}/snapshots` */
  saveSnapshot(name: string, body: CreateSnapshot): Promise<Snapshot> {
    return this.call("POST", `/v1/sandboxes/${encodeURIComponent(name)}/snapshots`, { json: body });
  }

  /** Delete a snapshot. `DELETE /v1/sandboxes/{name}/snapshots/{snap}` */
  deleteSnapshot(name: string, snap: string): Promise<void> {
    return this.call("DELETE", `/v1/sandboxes/${encodeURIComponent(name)}/snapshots/${encodeURIComponent(snap)}`);
  }

  /** One snapshot by id or label; latest is the newest available one. `GET /v1/sandboxes/{name}/snapshots/{snap}` */
  getSnapshot(name: string, snap: string): Promise<Snapshot> {
    return this.call("GET", `/v1/sandboxes/${encodeURIComponent(name)}/snapshots/${encodeURIComponent(snap)}`);
  }

  /** A file's details, or a folder's entries, inside a snapshot (the sandbox may be stopped). `GET /v1/sandboxes/{name}/snapshots/{snap}/files` */
  snapshotFileInfo(name: string, snap: string, query: { path: string | number | boolean }): Promise<FileInfo> {
    return this.call("GET", `/v1/sandboxes/${encodeURIComponent(name)}/snapshots/${encodeURIComponent(snap)}/files`, { query: query });
  }

  /** Download a file (raw bytes) or a folder (tar) out of a snapshot. `GET /v1/sandboxes/{name}/snapshots/{snap}/files/download` */
  downloadFromSnapshot(name: string, snap: string, query: { path: string | number | boolean }): Promise<Uint8Array> {
    return this.call("GET", `/v1/sandboxes/${encodeURIComponent(name)}/snapshots/${encodeURIComponent(snap)}/files/download`, { query: query, rawResponse: true });
  }

  /** Where and how to SSH in (host, port, pinned host key). `GET /v1/sandboxes/{name}/ssh` */
  getSshInfo(name: string): Promise<SshInfo> {
    return this.call("GET", `/v1/sandboxes/${encodeURIComponent(name)}/ssh`);
  }

  /** Start a stopped sandbox (its auto-stop timer starts again), optionally with a new size, auto-stop timer, environment or env vars. `POST /v1/sandboxes/{name}/start` */
  startSandbox(name: string, body?: StartSandbox): Promise<Sandbox> {
    return this.call("POST", `/v1/sandboxes/${encodeURIComponent(name)}/start`, { json: body });
  }

  /** Send a message to a running turn (Claude Code takes it mid-turn; others get it as the next turn). `POST /v1/sandboxes/{name}/steer` */
  steer(name: string, body: SteerRequest): Promise<SteerResult> {
    return this.call("POST", `/v1/sandboxes/${encodeURIComponent(name)}/steer`, { json: body });
  }

  /** Stop: run ~/.froog/pre-stop, snapshot the disk, stop billing (refused and retried if the snapshot fails; force keeps the last good snapshot; the answer's stop_id tracks it). `POST /v1/sandboxes/{name}/stop` */
  stopSandbox(name: string, body?: StopSandbox): Promise<Sandbox> {
    return this.call("POST", `/v1/sandboxes/${encodeURIComponent(name)}/stop`, { json: body });
  }

  /** Record activity (last_active_at); the auto-stop deadline doesn't move (PATCH ttl_secs does). `POST /v1/sandboxes/{name}/touch` */
  touchSandbox(name: string): Promise<void> {
    return this.call("POST", `/v1/sandboxes/${encodeURIComponent(name)}/touch`);
  }

  /** In an organization: make the sandbox private to the member who made it. `POST /v1/sandboxes/{name}/unshare` */
  unshareSandbox(name: string): Promise<Sandbox> {
    return this.call("POST", `/v1/sandboxes/${encodeURIComponent(name)}/unshare`);
  }

  /** Public URLs of the sandbox's ports. `GET /v1/sandboxes/{name}/urls` */
  listUrls(name: string): Promise<Array<PublicUrl>> {
    return this.call("GET", `/v1/sandboxes/${encodeURIComponent(name)}/urls`);
  }

  /** Host a port (private with a token unless public), or rename or title it. `POST /v1/sandboxes/{name}/urls` */
  hostPort(name: string, body: NewPublicUrl): Promise<PublicUrl> {
    return this.call("POST", `/v1/sandboxes/${encodeURIComponent(name)}/urls`, { json: body });
  }

  /** Remove a public URL. `DELETE /v1/sandboxes/{name}/urls/{port}` */
  removeUrl(name: string, port: string): Promise<void> {
    return this.call("DELETE", `/v1/sandboxes/${encodeURIComponent(name)}/urls/${encodeURIComponent(port)}`);
  }

  /** Live viewer tokens of a private URL (secrets are never returned). `GET /v1/sandboxes/{name}/urls/{port}/tokens` */
  listUrlTokens(name: string, port: string): Promise<Array<UrlToken>> {
    return this.call("GET", `/v1/sandboxes/${encodeURIComponent(name)}/urls/${encodeURIComponent(port)}/tokens`);
  }

  /** Another token for a private URL that expires and can be revoked on its own (the secret is returned once). `POST /v1/sandboxes/{name}/urls/{port}/tokens` */
  createUrlToken(name: string, port: string, body: NewUrlToken): Promise<UrlToken> {
    return this.call("POST", `/v1/sandboxes/${encodeURIComponent(name)}/urls/${encodeURIComponent(port)}/tokens`, { json: body });
  }

  /** Revoke a viewer token. `DELETE /v1/sandboxes/{name}/urls/{port}/tokens/{id}` */
  revokeUrlToken(name: string, port: string, id: string): Promise<void> {
    return this.call("DELETE", `/v1/sandboxes/${encodeURIComponent(name)}/urls/${encodeURIComponent(port)}/tokens/${encodeURIComponent(id)}`);
  }

  /** One sandbox's running time and cost in a window, at list prices. `GET /v1/sandboxes/{name}/usage` */
  getSandboxUsage(name: string, query?: { since?: string | number | boolean; until?: string | number | boolean }): Promise<SandboxUsage> {
    return this.call("GET", `/v1/sandboxes/${encodeURIComponent(name)}/usage`, { query: query });
  }

  /** Wait until something listens on a TCP port inside the sandbox (ready: false after the timeout). `POST /v1/sandboxes/{name}/wait` */
  waitForPort(name: string, body: WaitForPort): Promise<PortWait> {
    return this.call("POST", `/v1/sandboxes/${encodeURIComponent(name)}/wait`, { json: body });
  }

  /** Saved snapshots of the account (templates for from). `GET /v1/saved-snapshots` */
  listSavedSnapshots(): Promise<Array<SavedSnapshot>> {
    return this.call("GET", `/v1/saved-snapshots`);
  }

  /** Remove a saved snapshot. `DELETE /v1/saved-snapshots/{name}` */
  deleteSavedSnapshot(name: string): Promise<void> {
    return this.call("DELETE", `/v1/saved-snapshots/${encodeURIComponent(name)}`);
  }

  /** One saved snapshot and its status. `GET /v1/saved-snapshots/{name}` */
  getSavedSnapshot(name: string): Promise<SavedSnapshot> {
    return this.call("GET", `/v1/saved-snapshots/${encodeURIComponent(name)}`);
  }

  /** A file's details, or a folder's entries, inside a saved snapshot. `GET /v1/saved-snapshots/{name}/files` */
  savedSnapshotFileInfo(name: string, query: { path: string | number | boolean }): Promise<FileInfo> {
    return this.call("GET", `/v1/saved-snapshots/${encodeURIComponent(name)}/files`, { query: query });
  }

  /** Download a file (raw bytes) or a folder (tar) out of a saved snapshot. `GET /v1/saved-snapshots/{name}/files/download` */
  downloadFromSavedSnapshot(name: string, query: { path: string | number | boolean }): Promise<Uint8Array> {
    return this.call("GET", `/v1/saved-snapshots/${encodeURIComponent(name)}/files/download`, { query: query, rawResponse: true });
  }

  /** A saved snapshot's share codes (not the codes themselves). `GET /v1/saved-snapshots/{name}/shares` */
  listSnapshotShares(name: string): Promise<Array<SnapshotShare>> {
    return this.call("GET", `/v1/saved-snapshots/${encodeURIComponent(name)}/shares`);
  }

  /** Make a share code another account can create sandboxes from (shown once). `POST /v1/saved-snapshots/{name}/shares` */
  shareSavedSnapshot(name: string): Promise<CreatedSnapshotShare> {
    return this.call("POST", `/v1/saved-snapshots/${encodeURIComponent(name)}/shares`);
  }

  /** Revoke a share code. `DELETE /v1/saved-snapshots/{name}/shares/{id}` */
  revokeSnapshotShare(name: string, id: string): Promise<void> {
    return this.call("DELETE", `/v1/saved-snapshots/${encodeURIComponent(name)}/shares/${encodeURIComponent(id)}`);
  }

  /** Seaeye (CI on froog): setup, 7-day stats and the last GitHub Actions jobs (runs-on: seaeye). `GET /v1/seaeye` */
  getSeaeyeOverview(query?: { repo?: string | number | boolean; state?: string | number | boolean; limit?: string | number | boolean }): Promise<SeaeyeOverview> {
    return this.call("GET", `/v1/seaeye`, { query: query });
  }

  /** CI analytics: per repository and job, runs, failure rate, p50/p90 duration and wait, cost, CPU and memory, a size advice, and flaky tests. `GET /v1/seaeye/analytics` */
  getSeaeyeAnalytics(query?: { days?: string | number | boolean; repo?: string | number | boolean }): Promise<SeaeyeAnalytics> {
    return this.call("GET", `/v1/seaeye/analytics`, { query: query });
  }

  /** One CI job: state, reason, wait, run time and sandbox. `GET /v1/seaeye/jobs/{id}` */
  getSeaeyeJob(id: string): Promise<SeaeyeJob> {
    return this.call("GET", `/v1/seaeye/jobs/${encodeURIComponent(id)}`);
  }

  /** One CI job's log from GitHub (text, the last 1 MiB). `GET /v1/seaeye/jobs/{id}/logs` */
  getSeaeyeJobLog(id: string): Promise<Uint8Array> {
    return this.call("GET", `/v1/seaeye/jobs/${encodeURIComponent(id)}/logs`, { rawResponse: true });
  }

  /** One CI job's CPU and memory over time, and its steps with their times. `GET /v1/seaeye/jobs/{id}/metrics` */
  getSeaeyeJobMetrics(id: string): Promise<SeaeyeJobMetrics> {
    return this.call("GET", `/v1/seaeye/jobs/${encodeURIComponent(id)}/metrics`);
  }

  /** One CI job's test results, from the JUnit XML files it wrote (failed first). `GET /v1/seaeye/jobs/{id}/tests` */
  getSeaeyeJobTests(id: string): Promise<SeaeyeJobTests> {
    return this.call("GET", `/v1/seaeye/jobs/${encodeURIComponent(id)}/tests`);
  }

  /** Search the kept logs of finished CI jobs, line by line. `GET /v1/seaeye/logs/search` */
  searchSeaeyeLogs(query?: { q?: string | number | boolean; days?: string | number | boolean; limit?: string | number | boolean; order?: string | number | boolean }): Promise<SeaeyeLogSearch> {
    return this.call("GET", `/v1/seaeye/logs/search`, { query: query });
  }

  /** CI monitors: alerts when matching jobs fail or run long, with their last alerts. `GET /v1/seaeye/monitors` */
  listSeaeyeMonitors(): Promise<Array<SeaeyeMonitor>> {
    return this.call("GET", `/v1/seaeye/monitors`);
  }

  /** Add a CI monitor (email and the seaeye.monitor.triggered webhook event). `POST /v1/seaeye/monitors` */
  createSeaeyeMonitor(body: CreateSeaeyeMonitor): Promise<SeaeyeMonitor> {
    return this.call("POST", `/v1/seaeye/monitors`, { json: body });
  }

  /** Remove a CI monitor. `DELETE /v1/seaeye/monitors/{id}` */
  deleteSeaeyeMonitor(id: string): Promise<void> {
    return this.call("DELETE", `/v1/seaeye/monitors/${encodeURIComponent(id)}`);
  }

  /** CI workflow runs, newest first, a page at a time: each run's GitHub title, event, number, actor and its jobs on froog, plus the total and the workflows, repositories and branches to filter by. `GET /v1/seaeye/runs` */
  listSeaeyeRuns(query?: { repo?: string | number | boolean; state?: string | number | boolean; workflow?: string | number | boolean; branch?: string | number | boolean; q?: string | number | boolean; limit?: string | number | boolean; offset?: string | number | boolean }): Promise<SeaeyeRunList> {
    return this.call("GET", `/v1/seaeye/runs`, { query: query });
  }

  /** One CI workflow run (GitHub's run id) and its jobs on froog. `GET /v1/seaeye/runs/{run_id}` */
  getSeaeyeRun(run_id: string): Promise<SeaeyeRun> {
    return this.call("GET", `/v1/seaeye/runs/${encodeURIComponent(run_id)}`);
  }

  /** Let jobs from public repositories run, optionally only for listed GitHub users. `PUT /v1/seaeye/settings` */
  setSeaeyeSettings(body: SeaeyeSettings): Promise<SeaeyeSettings> {
    return this.call("PUT", `/v1/seaeye/settings`, { json: body });
  }

  /** Every snapshot of the account, newest first, with its sandbox, paged. `GET /v1/snapshots` */
  listAccountSnapshots(query?: { sort?: string | number | boolean; limit?: string | number | boolean; cursor?: string | number | boolean }): Promise<Array<Snapshot>> {
    return this.call("GET", `/v1/snapshots`, { query: query });
  }

  /** SSH public keys that can log in to your sandboxes. `GET /v1/ssh-keys` */
  listSshKeys(): Promise<Array<SshKey>> {
    return this.call("GET", `/v1/ssh-keys`);
  }

  /** Add an SSH public key. `POST /v1/ssh-keys` */
  addSshKey(body: AddSshKey): Promise<SshKey> {
    return this.call("POST", `/v1/ssh-keys`, { json: body });
  }

  /** Remove an SSH key. `DELETE /v1/ssh-keys/{id}` */
  removeSshKey(id: string): Promise<void> {
    return this.call("DELETE", `/v1/ssh-keys/${encodeURIComponent(id)}`);
  }

  /** Platform status and 90-day uptime. `GET /v1/status` */
  getStatus(): Promise<void> {
    return this.call("GET", `/v1/status`, { auth: false });
  }

  /** A stop's progress: pending, failing (retried), completed, superseded or failed. `GET /v1/stops/{id}` */
  getStop(id: string): Promise<Stop> {
    return this.call("GET", `/v1/stops/${encodeURIComponent(id)}`);
  }

  /** Subscription sign-ins (Claude, ChatGPT): connected or not. `GET /v1/subscriptions` */
  listSubscriptions(): Promise<Array<Subscription>> {
    return this.call("GET", `/v1/subscriptions`);
  }

  /** Sign out of a subscription (every sandbox loses it at its next start). `DELETE /v1/subscriptions/{provider}` */
  signOutSubscription(provider: string): Promise<void> {
    return this.call("DELETE", `/v1/subscriptions/${encodeURIComponent(provider)}`);
  }

  /** Cancel the sign-in in progress. `DELETE /v1/subscriptions/{provider}/login` */
  cancelSubscriptionLogin(provider: string): Promise<void> {
    return this.call("DELETE", `/v1/subscriptions/${encodeURIComponent(provider)}/login`);
  }

  /** The sign-in in progress (stores the credential once it's done). `GET /v1/subscriptions/{provider}/login` */
  getSubscriptionLogin(provider: string): Promise<SubscriptionLogin> {
    return this.call("GET", `/v1/subscriptions/${encodeURIComponent(provider)}/login`);
  }

  /** Start a subscription sign-in in one of your running sandboxes. `POST /v1/subscriptions/{provider}/login` */
  startSubscriptionLogin(provider: string, body: StartSubscriptionLogin): Promise<SubscriptionLogin> {
    return this.call("POST", `/v1/subscriptions/${encodeURIComponent(provider)}/login`, { json: body });
  }

  /** Claude: paste the code the sign-in page showed. `POST /v1/subscriptions/{provider}/login/code` */
  sendSubscriptionCode(provider: string, body: SubscriptionCode): Promise<SubscriptionLogin> {
    return this.call("POST", `/v1/subscriptions/${encodeURIComponent(provider)}/login/code`, { json: body });
  }

  /** Stop the OpenTelemetry export. `DELETE /v1/telemetry` */
  removeTelemetry(): Promise<void> {
    return this.call("DELETE", `/v1/telemetry`);
  }

  /** The OpenTelemetry endpoint (null when none). `GET /v1/telemetry` */
  getTelemetry(): Promise<Telemetry | null> {
    return this.call("GET", `/v1/telemetry`);
  }

  /** Set the OpenTelemetry endpoint; sends a test export. `PUT /v1/telemetry` */
  setTelemetry(body: SetTelemetry): Promise<TelemetrySaved> {
    return this.call("PUT", `/v1/telemetry`, { json: body });
  }

  /** Usage this calendar month: per-second running time and saved snapshots. `GET /v1/usage` */
  getUsage(query?: { month?: string | number | boolean }): Promise<Usage> {
    return this.call("GET", `/v1/usage`, { query: query });
  }

  /** Join the waitlist. `POST /v1/waitlist` */
  joinWaitlist(body: Waitlist): Promise<void> {
    return this.call("POST", `/v1/waitlist`, { json: body, auth: false });
  }

  /** Webhooks. `GET /v1/webhooks` */
  listWebhooks(): Promise<Array<Webhook>> {
    return this.call("GET", `/v1/webhooks`);
  }

  /** Add a webhook (the signing secret is returned once). `POST /v1/webhooks` */
  addWebhook(body: NewWebhook): Promise<WebhookSecret> {
    return this.call("POST", `/v1/webhooks`, { json: body });
  }

  /** Remove a webhook. `DELETE /v1/webhooks/{id}` */
  removeWebhook(id: string): Promise<void> {
    return this.call("DELETE", `/v1/webhooks/${encodeURIComponent(id)}`);
  }

  /** One webhook. `GET /v1/webhooks/{id}` */
  getWebhook(id: string): Promise<Webhook> {
    return this.call("GET", `/v1/webhooks/${encodeURIComponent(id)}`);
  }

  /** Change a webhook's URL, events, name, or pause it (the secret stays). `PATCH /v1/webhooks/{id}` */
  updateWebhook(id: string, body: UpdateWebhook): Promise<Webhook> {
    return this.call("PATCH", `/v1/webhooks/${encodeURIComponent(id)}`, { json: body });
  }

  /** Delivery attempts of the last 30 days, newest first. `GET /v1/webhooks/{id}/deliveries` */
  listWebhookDeliveries(id: string, query?: { limit?: string | number | boolean }): Promise<Array<WebhookDelivery>> {
    return this.call("GET", `/v1/webhooks/${encodeURIComponent(id)}/deliveries`, { query: query });
  }

  /** A new signing secret. `POST /v1/webhooks/{id}/rotate` */
  rotateWebhook(id: string): Promise<WebhookSecret> {
    return this.call("POST", `/v1/webhooks/${encodeURIComponent(id)}/rotate`);
  }

  /** Send a test event now. `POST /v1/webhooks/{id}/test` */
  testWebhook(id: string): Promise<void> {
    return this.call("POST", `/v1/webhooks/${encodeURIComponent(id)}/test`);
  }

}

// ---------------------------------------------------------------- objects
// Hand-written in deploy/sdk/objects.ts.in, appended by deploy/build-sdks.py.

/** Options of `sb.exec` and `sb.execStream`. */
export interface ExecOptions {
  cwd?: string;
  env?: Record<string, string>;
  /** Text, or bytes (sent base64-encoded), fed to the command's standard input. */
  stdin?: string | Uint8Array;
  /** Seconds. */
  timeout?: number;
}

/** Thrown by `exec(..., { check: true })` and `process.wait({ check: true })` when the command exits non-zero. */
export class CommandError extends FroogError {
  command: string;
  exitCode: number | null;
  stdout: string;
  stderr: string;
  constructor(command: string, exitCode: number | null, stdout = "", stderr = "") {
    super(0, "command_failed", `${JSON.stringify(command)} exited with ${exitCode}: ${(stderr || stdout).trim().slice(-500)}`);
    this.name = "CommandError";
    this.command = command;
    this.exitCode = exitCode;
    this.stdout = stdout;
    this.stderr = stderr;
  }
}

function toBase64(b: Uint8Array): string {
  const B = (globalThis as any).Buffer;
  if (B) return B.from(b).toString("base64");
  let s = "";
  for (let i = 0; i < b.length; i++) s += String.fromCharCode(b[i]);
  return btoa(s);
}

function execBody(command: string, o: ExecOptions = {}): ExecRequest {
  const body: ExecRequest = { command };
  if (o.cwd !== undefined) body.cwd = o.cwd;
  if (o.env) body.env = o.env;
  if (o.stdin instanceof Uint8Array) body.stdin_b64 = toBase64(o.stdin);
  else if (o.stdin !== undefined) body.stdin = o.stdin;
  if (o.timeout !== undefined) body.timeout_secs = Math.floor(o.timeout);
  return body;
}

const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
const DONE = ["exited", "killed", "lost"];
declare global {
  // Declared here too, so this file type-checks without lib "esnext.disposable"; `await using` needs a runtime that has it.
  interface SymbolConstructor {
    readonly asyncDispose: unique symbol;
  }
}

/** How long to wait (`wait: false` to return at once) and whether leaving `await using` / `use` deletes it. */
export interface WaitOptions {
  wait?: boolean;
  /** Milliseconds. Default 600000. */
  timeoutMs?: number;
}

/** `froog.sandboxes`: create, get and list sandboxes as `SandboxHandle` objects. */
export class Sandboxes {
  constructor(private froog: Froog) {}

  /** Create one sandbox and wait until it runs. `keep: false` (the default) deletes it when an `await using` block or `use` ends. */
  create(body: CreateSandbox = {}, opts: WaitOptions & { keep?: boolean; idempotencyKey?: string } = {}): Promise<SandboxHandle> {
    return SandboxHandle.create(this.froog, body, opts);
  }

  /** Fetch a sandbox by name. Its handle is kept (not deleted) at the end of a block unless you set `keep = false`. */
  get(name: string): Promise<SandboxHandle> {
    return SandboxHandle.get(this.froog, name);
  }

  async list(query?: Parameters<Froog["listSandboxes"]>[0]): Promise<SandboxHandle[]> {
    return (await this.froog.listSandboxes(query)).map((i) => new SandboxHandle(this.froog, i.name, i));
  }

  /** Create a sandbox, run `fn` with it, then delete it (unless `keep`), also when `fn` throws. For runtimes without `await using`. */
  async use<T>(body: CreateSandbox, fn: (sb: SandboxHandle) => Promise<T>, opts: WaitOptions & { keep?: boolean; idempotencyKey?: string } = {}): Promise<T> {
    const sb = await this.create(body, opts);
    try {
      return await fn(sb);
    } finally {
      await sb.close();
    }
  }
}

/** A sandbox you act on by method. `await using sb = await froog.sandboxes.create({ size: "small" });` deletes it at the end of the scope. */
export class SandboxHandle {
  readonly files: SandboxFiles;
  /** false: `close()` (and the end of an `await using` scope) deletes the sandbox. */
  keep: boolean;

  constructor(readonly froog: Froog, readonly name: string, public info?: Sandbox, keep = true) {
    this.keep = keep;
    this.files = new SandboxFiles(this);
  }

  static async create(froog: Froog, body: CreateSandbox = {}, opts: WaitOptions & { keep?: boolean; idempotencyKey?: string } = {}): Promise<SandboxHandle> {
    if (body.count != null && body.count !== 1) throw new Error("sandboxes.create makes one sandbox; use froog.createSandboxes for count");
    const [info] = await froog.createSandboxes(body, opts.idempotencyKey);
    const sb = new SandboxHandle(froog, info.name, info, opts.keep ?? false);
    if (opts.wait !== false) {
      try {
        await sb.waitUntil("running", opts.timeoutMs);
      } catch (e) {
        await sb.close().catch(() => {});
        throw e;
      }
    }
    return sb;
  }

  static async get(froog: Froog, name: string): Promise<SandboxHandle> {
    return new SandboxHandle(froog, name, await froog.getSandbox(name));
  }

  /** Delete it unless `keep`. */
  async close(): Promise<void> {
    if (this.keep) return;
    try {
      await this.delete();
    } catch (e) {
      if (!(e instanceof FroogError && e.status === 404)) throw e;
    }
  }

  [Symbol.asyncDispose](): Promise<void> {
    return this.close();
  }

  async refresh(): Promise<Sandbox> {
    return (this.info = await this.froog.getSandbox(this.name));
  }

  async state(): Promise<State> {
    return (await this.refresh()).state;
  }

  async waitUntil(state: State, timeoutMs?: number): Promise<Sandbox> {
    return (this.info = await this.froog.waitUntil(this.name, state, timeoutMs));
  }

  /** Run a command and wait for it. `check: true` throws `CommandError` when it exits non-zero. */
  async exec(command: string, opts: ExecOptions & { check?: boolean } = {}): Promise<ExecResult> {
    const r = await this.froog.exec(this.name, execBody(command, opts));
    if (opts.check && r.exit_code !== 0) throw new CommandError(command, r.exit_code, r.stdout, r.stderr);
    return r;
  }

  /** Run a command and get events as output arrives (`started`, `stdout`/`stderr`, then `exit` or `error`). */
  execStream(command: string, opts: ExecOptions = {}): AsyncGenerator<ExecEvent> {
    return this.froog.execStream(this.name, execBody(command, opts));
  }

  /** Start a background command (a job): `await p.wait()`, `await p.logs()`, `await p.kill()`. With `stdinOpen`, its
   * standard input stays open (after `stdin`, if given): `await p.write(...)`, then `await p.closeStdin()`. */
  async spawn(command: string, opts: Omit<ExecOptions, "timeout"> & { stdinOpen?: boolean } = {}): Promise<ProcessHandle> {
    const b = execBody(command, opts);
    const job: NewJob = { command, cwd: b.cwd, env: b.env, stdin: b.stdin, stdin_b64: b.stdin_b64 };
    if (opts.stdinOpen) job.stdin_open = true;
    return new ProcessHandle(this, await this.froog.startJob(this.name, job));
  }

  /** Reconnect to a background command by id (`job_…`). */
  process(id: string): ProcessHandle {
    return new ProcessHandle(this, { id });
  }

  async processes(): Promise<ProcessHandle[]> {
    return (await this.froog.listJobs(this.name)).map((j) => new ProcessHandle(this, j));
  }

  /** Wait until something in the sandbox listens on TCP `port` (`POST /wait`, 1-600 s). Throws a 408 `timeout` FroogError if nothing does. */
  async waitForPort(port: number, timeoutSecs = 60): Promise<void> {
    const p = Math.floor(port);
    const r = await this.froog.waitForPort(this.name, { port: p, timeout_secs: Math.max(1, Math.min(600, Math.floor(timeoutSecs))) });
    if (!r.ready) throw new FroogError(408, "timeout", `nothing listens on port ${p} in ${this.name} after ${timeoutSecs} s`);
  }

  async start(body: StartSandbox = {}, opts: WaitOptions = {}): Promise<this> {
    this.info = await this.froog.startSandbox(this.name, body);
    if (opts.wait !== false) await this.waitUntil("running", opts.timeoutMs);
    return this;
  }

  /** Stop it (disk snapshotted, billing stops) and, unless `wait: false`, wait until the stop finishes.
   * A stop whose snapshot fails is refused (it keeps running); `force: true` keeps the last good snapshot. */
  async stop(opts: WaitOptions & { force?: boolean } = {}): Promise<this> {
    this.info = await this.froog.stopSandbox(this.name, opts.force ? { force: true } : undefined);
    if (opts.wait === false) return this;
    const until = Date.now() + (opts.timeoutMs ?? 600_000);
    const stopId = this.info.stop_id;
    if (!stopId) {
      await this.waitUntil("stopped", opts.timeoutMs);
      return this;
    }
    for (;;) {
      const s = await this.froog.getStop(stopId);
      if (s.status === "completed") break;
      if (s.status === "failed") throw new FroogError(409, "stop_failed", `${this.name}: ${s.error ?? "failed"}`);
      if (s.status === "failing") throw new FroogError(409, "stop_refused", `${this.name} keeps running (stop refused, retried by froog): ${s.error ?? ""}`);
      if (Date.now() > until) throw new FroogError(408, "timeout", `${this.name} didn't stop`);
      await sleep(2000);
    }
    await this.refresh().catch(() => {});
    return this;
  }

  async delete(): Promise<void> {
    await this.froog.deleteSandbox(this.name);
  }

  /** A new sandbox from a snapshot of this one; waits until it runs. */
  async fork(name: string, body: Omit<ForkSandbox, "name" | "count"> = {}, opts: WaitOptions & { keep?: boolean; idempotencyKey?: string } = {}): Promise<SandboxHandle> {
    const [info] = await this.froog.forkSandbox(this.name, { ...body, name }, opts.idempotencyKey);
    const sb = new SandboxHandle(this.froog, info.name, info, opts.keep ?? false);
    if (opts.wait !== false) {
      try {
        await sb.waitUntil("running", opts.timeoutMs);
      } catch (e) {
        await sb.close().catch(() => {});
        throw e;
      }
    }
    return sb;
  }

  snapshot(label?: string): Promise<Snapshot> {
    return this.froog.saveSnapshot(this.name, label ? { label } : {});
  }

  /** Give a port an HTTPS URL and return it (private ones carry `?_token=`). */
  async host(port: number, opts: Omit<NewPublicUrl, "port"> = {}): Promise<string> {
    return (await this.froog.hostPort(this.name, { ...opts, port })).url;
  }

  /** Open an inbound port (kept across stops and starts): on the sandbox's IPv6 address, and on a public port of its host's IPv4 address (see ipv4Ports); returns the open ports. */
  async openPort(port: number, protocol: "tcp" | "udp" = "tcp"): Promise<string[]> {
    return (await this.froog.openPort(this.name, { port, protocol })).ports;
  }

  /** Close a port opened with openPort; returns the open ports. */
  async closePort(port: number, protocol: "tcp" | "udp" = "tcp"): Promise<string[]> {
    return (await this.froog.closePort(this.name, String(port), protocol)).ports;
  }

  /** Inbound ports open besides SSH, e.g. ["8080/tcp", "27015/udp"]. */
  async ports(): Promise<string[]> {
    return (await this.froog.listPorts(this.name)).ports;
  }

  /** Where the opened ports are reached over IPv4 ({ port: "27015/udp", public_port: 40000, address: "203.0.113.7:40000" }). Empty while stopped. */
  async ipv4Ports(): Promise<Ipv4Port[]> {
    return (await this.froog.listPorts(this.name)).ipv4 ?? [];
  }

  metrics(): Promise<SandboxMetrics> {
    return this.froog.getSandboxMetrics(this.name);
  }

  /** Give a coding agent in the sandbox a task and wait for its answer (`stdout`). It continues the sandbox's
   * current conversation unless `new: true` or `conversation_id`. */
  prompt(prompt: string, opts: Omit<PromptRequest, "prompt"> = {}): Promise<PromptResult> {
    return this.froog.prompt(this.name, { ...opts, prompt });
  }

  /** Queue a prompt and return it at once; follow it with `watchPrompt`. */
  queuePrompt(prompt: string, opts: Omit<PromptRequest, "prompt"> = {}): Promise<Prompt> {
    return this.froog.queuePrompt(this.name, { ...opts, prompt });
  }

  /** A prompt's events (status, text, tool_call, tool_result, steer, ...) until it ends. */
  async *watchPrompt(promptId: string, intervalMs = 1000): AsyncGenerator<AgentEvent> {
    let cursor = 0;
    for (;;) {
      const page = await this.froog.promptEvents(this.name, promptId, { cursor });
      for (const e of page.events) {
        yield e;
        const s = (e.data as { status?: string } | null)?.status;
        if (e.type === "status" && (s === "done" || s === "failed" || s === "interrupted")) return;
      }
      cursor = page.next_cursor;
      if (page.events.length === 0) await new Promise((r) => setTimeout(r, intervalMs));
    }
  }

  async conversations(): Promise<Conversation[]> {
    return (await this.froog.listConversations(this.name)).conversations;
  }

  /** Send a message to the running turn (Claude Code takes it mid-turn; other agents get it as the next turn). */
  steer(message: string, conversationId?: string): Promise<SteerResult> {
    return this.froog.steer(this.name, { message, conversation_id: conversationId });
  }

  /** Stop running turns and cancel queued prompts: all, or one conversation's. */
  async interrupt(conversationId?: string): Promise<string[]> {
    return (await this.froog.interrupt(this.name, { conversation_id: conversationId })).interrupted;
  }
}

/** `sb.files`: paths are relative to /home/user, or absolute. */
export class SandboxFiles {
  constructor(private sb: SandboxHandle) {}

  read(path: string): Promise<Uint8Array> {
    return this.sb.froog.readFile(this.sb.name, { path });
  }

  async readText(path: string): Promise<string> {
    return new TextDecoder().decode(await this.read(path));
  }

  /** Write text or bytes (atomic). `mode` like "755". */
  write(path: string, data: string | Uint8Array, mode?: string): Promise<void> {
    const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
    return this.sb.froog.writeFile(this.sb.name, bytes as BodyInit, mode === undefined ? { path } : { path, mode });
  }

  info(path: string): Promise<FileInfo> {
    return this.sb.froog.fileInfo(this.sb.name, { path });
  }

  async list(path = "."): Promise<FileEntry[]> {
    return (await this.info(path)).entries ?? [];
  }

  async exists(path: string): Promise<boolean> {
    try {
      await this.info(path);
      return true;
    } catch (e) {
      if (e instanceof FroogError && e.status === 404) return false;
      throw e;
    }
  }

  remove(path: string, opts: { recursive?: boolean } = {}): Promise<void> {
    return this.sb.froog.deleteFile(this.sb.name, opts.recursive ? { path, recursive: true } : { path });
  }

  mkdir(path: string, mode?: string): Promise<void> {
    return this.sb.froog.makeDirectory(this.sb.name, mode === undefined ? { path } : { path, mode });
  }

  move(from: string, to: string): Promise<void> {
    return this.sb.froog.moveFile(this.sb.name, { from, to });
  }

  /** Changes under `path` as they happen (`event`: create | modify | delete), until `timeoutSecs` (default and at
   *  most 3600) or you stop iterating: `for await (const e of sb.files.watch("src")) console.log(e.event, e.path)`. */
  async *watch(path = ".", opts: { recursive?: boolean; timeoutSecs?: number } = {}): AsyncGenerator<FileEvent> {
    const q: { path: string; recursive?: boolean; timeout_secs?: number } = { path };
    if (opts.recursive === false) q.recursive = false;
    if (opts.timeoutSecs !== undefined) q.timeout_secs = Math.floor(opts.timeoutSecs);
    for await (const e of this.sb.froog.watchFiles(this.sb.name, q)) {
      if (e.type === "change") yield e;
      else if (e.type === "error" || (e.type === "end" && e.reason === "error")) throw new FroogError(409, "watch_failed", e.message ?? "the watch failed");
    }
  }
}

/** A background command (a job). Output is stdout and stderr together. */
export class ProcessHandle {
  readonly id: string;
  /** Where `follow()` reads next. */
  offset = 0;
  constructor(readonly sandbox: SandboxHandle, public info: Partial<Job> & { id: string }) {
    this.id = info.id;
  }

  private async read(offset: number, limit?: number): Promise<JobOutput> {
    const q: { offset: number; limit?: number } = { offset };
    if (limit !== undefined) q.limit = limit;
    const out = await this.sandbox.froog.readJob(this.sandbox.name, this.id, q);
    this.info = { ...this.info, state: out.state, exit_code: out.exit_code, started_at: out.started_at };
    return out;
  }

  async refresh(): Promise<Partial<Job> & { id: string }> {
    await this.read(0, 0);
    return this.info;
  }

  get exitCode(): number | null | undefined {
    return this.info.exit_code;
  }

  /** All its output so far. */
  async logs(): Promise<string> {
    let s = "", offset = 0;
    for (;;) {
      const out = await this.read(offset);
      s += out.output;
      if (out.next_offset <= offset || out.next_offset >= out.output_size) return s;
      offset = out.next_offset;
    }
  }

  /** Yield output as it arrives until the command ends. */
  async *follow(pollMs = 1000): AsyncGenerator<string> {
    for (;;) {
      const out = await this.read(this.offset);
      if (out.output) yield out.output;
      const moved = out.next_offset > this.offset;
      this.offset = out.next_offset;
      if (DONE.includes(out.state) && this.offset >= out.output_size) return;
      if (!moved) await sleep(pollMs);
    }
  }

  /** Wait until it ends; resolves to the exit code (null when killed or lost). */
  async wait(opts: { timeoutMs?: number; pollMs?: number; check?: boolean } = {}): Promise<number | null> {
    const until = opts.timeoutMs === undefined ? Infinity : Date.now() + opts.timeoutMs;
    while (!DONE.includes((await this.refresh()).state ?? "")) {
      if (Date.now() > until) throw new FroogError(408, "timeout", `${this.id} still running`);
      await sleep(opts.pollMs ?? 1000);
    }
    const code = this.info.exit_code ?? null;
    if (opts.check && code !== 0) throw new CommandError(this.info.command ?? this.id, code, await this.logs());
    return code;
  }

  /** Stop it (TERM to its process group, KILL after 3 s). */
  kill(): Promise<void> {
    return this.sandbox.froog.stopJob(this.sandbox.name, this.id);
  }

  /** Write text or bytes to its standard input (spawned with `stdinOpen: true`); `close: true` then closes it. */
  write(data: string | Uint8Array, opts: { close?: boolean } = {}): Promise<void> {
    const body: JobStdin = typeof data === "string" ? { data } : { data_b64: toBase64(data) };
    if (opts.close) body.close = true;
    return this.sandbox.froog.writeJobStdin(this.sandbox.name, this.id, body);
  }

  /** Close its standard input: the command reads end of file. */
  closeStdin(): Promise<void> {
    return this.sandbox.froog.writeJobStdin(this.sandbox.name, this.id, { close: true });
  }
}
