Skip to content

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

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

import type { AuditLogsQueryParams } from './useAuditLogsQuery'

export const queryKeys = {
  checkpoints: {
    all: ['checkpoints'] as const,
    list: (organizationId: string) => [...queryKeys.checkpoints.all, organizationId, 'list'] as const,
  },
  apps: {
    all: ['apps'] as const,
    organization: (organizationId: string) => [...queryKeys.apps.all, organizationId] as const,
    list: (organizationId: string) => [...queryKeys.apps.organization(organizationId), 'list'] as const,
    detail: (organizationId: string, appId: string, env?: string) =>
      env
        ? ([...queryKeys.apps.organization(organizationId), 'detail', appId, env] as const)
        : ([...queryKeys.apps.organization(organizationId), 'detail', appId] as const),
    environments: (organizationId: string, appId: string) =>
      [...queryKeys.apps.detail(organizationId, appId), '@environments'] as const,
  },
  domains: {
    all: ['domains'] as const,
    list: (organizationId: string) => [...queryKeys.domains.all, organizationId, 'list'] as const,
  },
  config: {
    all: ['config'] as const,
  },
  apiKeys: {
    all: ['api-keys'] as const,
    list: (organizationId: string) => [...queryKeys.apiKeys.all, organizationId, 'list'] as const,
  },
  webhooks: {
    all: ['webhooks'] as const,
    appPortalAccess: (organizationId: string) =>
      [...queryKeys.webhooks.all, organizationId, 'app-portal-access'] as const,
    initializationStatus: (organizationId: string) =>
      [...queryKeys.webhooks.all, organizationId, 'initialization-status'] as const,
  },
  organization: {
    all: ['organization'] as const,

    list: () => [...queryKeys.organization.all, 'list'] as const,
    detail: (organizationId: string) => [...queryKeys.organization.all, organizationId, 'detail'] as const,

    usage: {
      overview: (organizationId: string) =>
        [...queryKeys.organization.all, organizationId, 'usage', 'overview'] as const,
      series: (organizationId: string, params: object) =>
        [...queryKeys.organization.all, organizationId, 'usage', 'series', params] as const,
      concurrency: (organizationId: string, params: object) =>
        [...queryKeys.organization.all, organizationId, 'usage', 'concurrency', params] as const,
    },

    plan: (organizationId: string) => [...queryKeys.organization.all, organizationId, 'plan'] as const,
    trialEligibility: (organizationId: string, subject?: string) =>
      [...queryKeys.organization.plan(organizationId), 'trial-eligibility', subject] as const,
    wallet: (organizationId: string) => [...queryKeys.organization.all, organizationId, 'wallet'] as const,
  },
  user: {
    all: ['users'] as const,
    accountProviders: () => [...queryKeys.user.all, 'account-providers'] as const,
  },
  billing: {
    all: ['billing'] as const,
    plans: () => [...queryKeys.billing.all, 'plans'] as const,
    usagePrices: () => [...queryKeys.billing.all, 'usage-prices'] as const,
    emails: (organizationId: string) => [...queryKeys.billing.all, organizationId, 'emails'] as const,
    portalUrl: (organizationId: string) => [...queryKeys.billing.all, organizationId, 'portal-url'] as const,
    checkoutUrl: (organizationId: string) => [...queryKeys.billing.all, organizationId, 'checkout-url'] as const,
    paymentMethods: (organizationId: string) => [...queryKeys.billing.all, organizationId, 'payment-methods'] as const,
    /**
     * Query key factory for invoice listings.
     * Called with the organization alone this is the prefix every invoice
     * listing shares, which is what the money mutations invalidate.
     */
    invoices: (organizationId: string, type?: string, page?: number, perPage?: number) =>
      [
        ...queryKeys.billing.all,
        organizationId,
        'invoices',
        ...(type !== undefined ? [type] : []),
        ...(page !== undefined && perPage !== undefined ? [{ page, perPage }] : []),
      ] as const,
    transactions: (organizationId: string, page?: number, perPage?: number) =>
      [
        ...queryKeys.billing.all,
        organizationId,
        'transactions',
        ...(page !== undefined && perPage !== undefined ? [{ page, perPage }] : []),
      ] as const,
  },
  images: {
    all: ['images'] as const,
    list: (organizationId: string) => [...queryKeys.images.all, organizationId, 'list'] as const,
    // One image can be cached under several keys: the route takes its id or any
    // reference that names it.
    details: (organizationId: string) => [...queryKeys.images.all, organizationId, 'detail'] as const,
    detail: (organizationId: string, idOrRef: string) =>
      [...queryKeys.images.details(organizationId), idOrRef] as const,
    // Kept apart from the list rather than derived from it: the count is of
    // the organization's own images, and the list also carries the curated set,
    // which belongs to no organization and counts against no limit.
    usage: (organizationId: string) => [...queryKeys.images.all, organizationId, 'usage'] as const,
  },
  registries: {
    all: ['registries'] as const,
    list: (organizationId: string) => [...queryKeys.registries.all, organizationId, 'list'] as const,
  },
  volumes: {
    all: ['volumes'] as const,
    list: (organizationId: string) => [...queryKeys.volumes.all, organizationId, 'list'] as const,
  },
  audit: {
    all: ['audit'] as const,
    logs: (organizationId: string, params: AuditLogsQueryParams) =>
      [
        ...queryKeys.audit.all,
        organizationId,
        'logs',
        {
          page: params.page,
          pageSize: params.pageSize,
          ...(params.from && { from: params.from.toISOString() }),
          ...(params.to && { to: params.to.toISOString() }),
          ...(params.cursor && { cursor: params.cursor }),
        },
      ] as const,
  },
  boxes: {
    all: ['boxes'] as const,
    detail: (organizationId: string, boxId: string) =>
      [...queryKeys.boxes.all, organizationId, boxId, 'detail'] as const,
    runningCount: (organizationId: string) => [...queryKeys.boxes.all, organizationId, 'running-count'] as const,
  },
  telemetry: {
    all: ['telemetry'] as const,
    logs: (boxId: string, params: object) => [...queryKeys.telemetry.all, boxId, 'logs', params] as const,
    traces: (boxId: string, params: object) => [...queryKeys.telemetry.all, boxId, 'traces', params] as const,
    metrics: (boxId: string, params: object) => [...queryKeys.telemetry.all, boxId, 'metrics', params] as const,
    traceSpans: (boxId: string, traceId: string) => [...queryKeys.telemetry.all, boxId, 'traces', traceId] as const,
  },
  analytics: {
    all: ['analytics'] as const,
    aggregatedUsage: (organizationId: string, params: object) =>
      [...queryKeys.analytics.all, organizationId, 'aggregated-usage', params] as const,
    boxesUsage: (organizationId: string, params: object) =>
      [...queryKeys.analytics.all, organizationId, 'boxes-usage', params] as const,
    boxUsagePeriods: (organizationId: string, boxId: string, params: object) =>
      [...queryKeys.analytics.all, organizationId, boxId, 'usage-periods', params] as const,
  },
} as const