Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions apps/api/src/lib/storage/serialization.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {
AnalyticsSummary,
ExecutionFallbackReason,
LatencyBucket,
PaymentAttempt,
QueryMode,
UsageEvent
Expand All @@ -14,6 +15,18 @@ function emptySpendByCategory(): Record<QueryMode, number> {
return { search: 0, news: 0, scrape: 0 };
}

function emptyLatencyBuckets(): Record<LatencyBucket, number> {
return { "<1s": 0, "1-3s": 0, "3-10s": 0, ">10s": 0, unknown: 0 };
}

function classifyLatency(latencyMs: number): LatencyBucket {
if (latencyMs <= 0) return "unknown";
if (latencyMs < 1000) return "<1s";
if (latencyMs < 3000) return "1-3s";
if (latencyMs < 10000) return "3-10s";
return ">10s";
}

function emptyExecutionSummary(): NonNullable<AnalyticsSummary["executionSummary"]> {
return {
totalExecutions: 0,
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ProviderDefinition, QueryMode, QueryResult } from "@query402/shared";
import type { LatencyBucket, ProviderDefinition, QueryMode, QueryResult } from "@query402/shared";

export interface PaymentProofLinks {
transaction: string;
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export type ExecutionFallbackReason =
export type CircuitBreakerState = "closed" | "half-open" | "open";
export type PaymentSource = "sponsored" | "wallet" | "demo";

export type LatencyBucket = "<1s" | "1-3s" | "3-10s" | ">10s" | "unknown";

export interface ProviderExecutionMetadata {
providerId: string;
source: SourceType;
Expand Down
Loading