Skip to content

The micro-VM for AI agents — light enough to embed on your laptop, elastic enough to power an agentic cloud.

1.2 KB
Raw Blame
/*
 * Copyright 2025 Daytona Platforms Inc.
 * Modified by BoxLite AI, 2025-2026
 * SPDX-License-Identifier: AGPL-3.0
 */

import { Column, Entity, Index, PrimaryGeneratedColumn } from 'typeorm'

@Entity('box_usage_periods')
@Index('idx_box_usage_periods_box_end', ['boxId', 'endAt'])
// A box bills against exactly one open period at a time. The per-box Redis lock
// is advisory and expires, so the invariant is enforced in the database: two
// interleaved handlers closing and reopening the same period would otherwise
// leave two open rows and double-count the overlap.
@Index('box_usage_periods_one_open_period_per_box_idx', ['boxId'], {
  unique: true,
  where: '"endAt" IS NULL',
})
export class BoxUsagePeriod {
  @PrimaryGeneratedColumn('uuid')
  id: string

  @Column({ name: 'boxId' })
  boxId: string

  @Column()
  // Redundant property to optimize billing queries
  organizationId: string

  @Column({ type: 'timestamp with time zone' })
  startAt: Date

  @Column({ type: 'timestamp with time zone', nullable: true })
  endAt: Date | null

  @Column({ type: 'float' })
  cpu: number

  @Column({ type: 'float' })
  gpu: number

  @Column({ type: 'float' })
  mem: number

  @Column({ type: 'float' })
  disk: number

  @Column()
  region: string
}