diff --git a/apps/mobile/src/features/chats/state/kinClient.ts b/apps/mobile/src/features/chats/state/kinClient.ts index b724ef3d6578..99b0aca37c70 100644 --- a/apps/mobile/src/features/chats/state/kinClient.ts +++ b/apps/mobile/src/features/chats/state/kinClient.ts @@ -118,6 +118,7 @@ export const refreshKinAccessMe = kin.refreshAccessMe; export const refreshKinAgents = kin.refreshKinAgents; export const refreshKinBriefs = kin.refreshKinBriefs; export const refreshKinHost = kin.refreshKinHost; +export const refreshKinCacheDays = kin.refreshKinCacheDays; const approvalRead = createKinRpcCommand(connectionAtomRuntime, { label: "kin:approval:read", diff --git a/apps/mobile/src/features/usage/UsageKinCacheLine.tsx b/apps/mobile/src/features/usage/UsageKinCacheLine.tsx new file mode 100644 index 000000000000..07ebea23a331 --- /dev/null +++ b/apps/mobile/src/features/usage/UsageKinCacheLine.tsx @@ -0,0 +1,87 @@ +import { useAtomValue } from "@effect/atom-react"; +import { + KIN_CACHE_DAILY_COPY, + kinCacheDayLine, + kinCacheLabel, +} from "@t3tools/client-runtime/kin/kinCacheDaily"; +import type { EnvironmentId } from "@t3tools/contracts"; +import * as Option from "effect/Option"; +import { AsyncResult } from "effect/reactivity"; +import { View } from "react-native"; + +import { AppText as Text } from "../../components/ui/AppText"; +import { Button } from "../../components/ui/Button"; +import { kinClient, refreshKinCacheDays } from "../chats/state/kinClient"; + +const LINE = "text-sm leading-5 text-foreground-muted"; + +/** Kin's cache line for each selected host whose owner reads it here; nothing for anyone else. */ +export function UsageKinCacheLines(props: { + readonly environments: readonly { + readonly environmentId: EnvironmentId; + readonly label: string; + }[]; +}) { + return props.environments.map((environment) => ( + 1 ? environment.label : null} + /> + )); +} + +function KinCacheGate(props: { + readonly environmentId: EnvironmentId; + readonly label: string | null; +}) { + const allowed = useAtomValue(kinClient.cacheDaily.permissionAtom(props.environmentId)); + return allowed ? : null; +} + +function DayLine(props: { readonly label: string; readonly body: string }) { + return ( + + {props.label}: {props.body} + + ); +} + +function KinCacheLines(props: { + readonly environmentId: EnvironmentId; + readonly label: string | null; +}) { + const result = useAtomValue( + kinClient.cacheDays({ environmentId: props.environmentId, input: {} }), + ); + const days = Option.getOrNull(AsyncResult.value(result)); + const failed = days === null && AsyncResult.isFailure(result); + return ( + + {props.label === null ? null : ( + {props.label} + )} + {days !== null ? ( + [kinCacheDayLine("today", days.day), kinCacheDayLine("yesterday", days.before)].map( + (line) => , + ) + ) : failed ? ( + + {KIN_CACHE_DAILY_COPY.failed} +