40 lines
1.5 KiB
TypeScript
40 lines
1.5 KiB
TypeScript
import type { KeybindingCommand, ResolvedKeybindingsConfig } from "@t3tools/contracts";
|
|
import type { UsageChartMetric } from "./UsageProviderChart";
|
|
import { resolveShortcutCommand, type ShortcutEventLike } from "../../keybindings";
|
|
|
|
export type UsageMetric = UsageChartMetric | "limits";
|
|
export const METRIC_OPTIONS = [
|
|
{ value: "cost", label: "Cost", command: "usage.cost" },
|
|
{ value: "tokens", label: "Tokens", command: "usage.tokens" },
|
|
{ value: "limits", label: "Limits", command: "usage.limits" },
|
|
] as const satisfies readonly { value: UsageMetric; label: string; command: KeybindingCommand }[];
|
|
|
|
export const WINDOW_OPTIONS = [
|
|
{ days: 1, label: "Past 24h", command: "usage.period.day" },
|
|
{ days: 7, label: "7 days", command: "usage.period.week" },
|
|
{ days: 30, label: "30 days", command: "usage.period.month" },
|
|
{ days: 90, label: "90 days", command: "usage.period.quarter" },
|
|
] as const;
|
|
|
|
/** Resolves page shortcuts without taking letters from fields or popup controls. */
|
|
export function resolveUsageShortcut(
|
|
event: ShortcutEventLike & { target: EventTarget | null },
|
|
keybindings: ResolvedKeybindingsConfig,
|
|
) {
|
|
const target = event.target;
|
|
if (
|
|
target instanceof HTMLElement &&
|
|
(target.tagName === "INPUT" ||
|
|
target.tagName === "TEXTAREA" ||
|
|
target.tagName === "SELECT" ||
|
|
target.isContentEditable ||
|
|
target.closest('[role="dialog"], [aria-modal="true"], [data-slot$="popup"]'))
|
|
) {
|
|
return null;
|
|
}
|
|
|
|
return resolveShortcutCommand(event, keybindings, {
|
|
context: { usagePageOpen: true },
|
|
});
|
|
}
|