@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 03:37 UTC

main
ts 66 lines 1.87 KB
Raw
1 import type { UsageSource } from "@t3tools/contracts";
2 import { mFallback, msg } from "gt-i18n";
3 import type { MFunctionType } from "gt-i18n/types";
4
5 import {
6 formatRelativeHourShort as formatRelativeHourShortWith,
7 usageSourceMessages as usageSourceMessagesWith,
8 } from "./usageFormat.ts";
9 import type { UsageContractMismatch } from "./usageMerge.ts";
10
11 /** @public */
12 export function usageSourceMessages(
13 sources: readonly UsageSource[],
14 resolve: MFunctionType = mFallback,
15 ): readonly string[] {
16 return usageSourceMessagesWith(sources, (count) =>
17 resolve(
18 msg(
19 "{count, plural, one {{count} malformed or inconsistent usage record(s) were skipped; usage may be incomplete.} other {{count} malformed or inconsistent usage record(s) were skipped; usage may be incomplete.}}",
20 { count },
21 ),
22 ),
23 );
24 }
25
26 /** @public */
27 export function formatUsageContractMismatch(
28 environmentLabel: string,
29 mismatch: Pick<UsageContractMismatch, "direction">,
30 resolve: MFunctionType = mFallback,
31 ): string {
32 return mismatch.direction === "serverBehind"
33 ? resolve(
34 msg("{environment} runs an older server version and is excluded from totals.", {
35 environment: environmentLabel,
36 }),
37 )
38 : resolve(
39 msg(
40 "This client is older than the server on {environment}; its usage is excluded from totals.",
41 { environment: environmentLabel },
42 ),
43 );
44 }
45
46 /** @public */
47 export function formatRelativeHourShort(
48 hourStart: string,
49 relativeTo: string,
50 timeZone?: string,
51 hour12 = true,
52 resolve: MFunctionType = mFallback,
53 locale?: string,
54 ): string {
55 return formatRelativeHourShortWith(
56 hourStart,
57 relativeTo,
58 timeZone,
59 hour12,
60 (hour, daysAgo) =>
61 daysAgo === 0
62 ? resolve(msg("{hour} today", { hour }))
63 : resolve(msg("{hour} yesterday", { hour })),
64 locale,
65 );
66 }