From d63af91c894ebec05c357a7332558d8eab43e0c1 Mon Sep 17 00:00:00 2001 From: Surajsm60720 <1ds22is166@dsce.edu.in> Date: Mon, 9 Nov 2026 15:15:06 +0530 Subject: [PATCH 1/2] feat(mobile): Kin trial review, promotion cards and owner Levels screen Render the server's shadow_review and promotion cards natively. Verdicts go to kin.levels.review; Raise, Another week and the shadow-memory choice go to the levels RPCs. The lead's owner opens Levels from their direct chat to see levels, chat caps, the trial and open raises, and to lower or raise. Co-Authored-By: Claude Opus 5.5 --- .../src/features/chats/KinChatScreen.tsx | 34 +- .../src/features/chats/KinLevelsScreen.tsx | 272 +++++++++++ apps/mobile/src/features/chats/routes.tsx | 6 + .../src/features/chats/state/kinClient.ts | 37 ++ .../chats/state/kinScreenState.test.ts | 28 ++ .../features/chats/state/kinScreenState.ts | 21 + .../chats/widgets/KinPromotionCard.tsx | 126 +++++ .../chats/widgets/KinShadowReviewCard.tsx | 167 +++++++ .../features/chats/widgets/KinWidgetView.tsx | 6 + .../chats/widgets/kinCardPresentation.test.ts | 226 ++++++++- .../chats/widgets/kinCardPresentation.ts | 10 +- .../chats/widgets/kinLevelsPresentation.ts | 443 ++++++++++++++++++ 12 files changed, 1369 insertions(+), 7 deletions(-) create mode 100644 apps/mobile/src/features/chats/KinLevelsScreen.tsx create mode 100644 apps/mobile/src/features/chats/widgets/KinPromotionCard.tsx create mode 100644 apps/mobile/src/features/chats/widgets/KinShadowReviewCard.tsx create mode 100644 apps/mobile/src/features/chats/widgets/kinLevelsPresentation.ts diff --git a/apps/mobile/src/features/chats/KinChatScreen.tsx b/apps/mobile/src/features/chats/KinChatScreen.tsx index cb0ad49c09369..17abb60a7fd27 100644 --- a/apps/mobile/src/features/chats/KinChatScreen.tsx +++ b/apps/mobile/src/features/chats/KinChatScreen.tsx @@ -94,7 +94,7 @@ import { type KinChatState, type KinInboxState, } from "./state/kinInboxModel"; -import { kinChatTitle, kinDirectAgentName } from "./state/kinScreenState"; +import { kinChatTitle, kinDirectAgentName, kinLevelsAgentId } from "./state/kinScreenState"; import { useKinHostAt } from "./state/useKinHost"; import { KinChatPushWatch } from "./notifications/KinChatPushWatch"; @@ -172,6 +172,9 @@ function KinLiveChat(props: { inbox?._tag === "Success" ? inbox.value.value.chats.find((chat) => chat.chatId === chatId) : undefined; + const canReadLevels = useAtomValue(kinClient.levelsRead.permissionAtom(props.environmentId)); + const levelsAgentId = + summary === undefined || !canReadLevels ? null : kinLevelsAgentId(summary, viewer.personId); const retry = () => { if (environmentId === null) return; @@ -190,6 +193,11 @@ function KinLiveChat(props: { chatId={chatId ?? (props.chatId as KinChatId)} title={summary === undefined ? "Chat" : kinChatTitle(summary, viewer.agentNames)} agentName={summary === undefined ? null : kinDirectAgentName(summary, viewer.agentNames)} + levels={ + levelsAgentId === null + ? null + : { environmentId: props.environmentId, orgId: props.orgId, agentId: levelsAgentId } + } unread={summary?.unread ?? null} markRead={ environmentId === null || chatId === null @@ -263,6 +271,12 @@ function KinChatPage(props: { readonly title: string; /** The agent a direct chat is with, for the empty chat's copy; null when unknown. */ readonly agentName: string | null; + /** The lead's Levels screen, for its owner in their direct chat; null elsewhere. */ + readonly levels?: { + readonly environmentId: string; + readonly orgId: string; + readonly agentId: string; + } | null; /** The inbox's unread count for this chat; null until the inbox loads. */ readonly unread: number | null; /** Null where nothing can be marked, such as the dev fixture. */ @@ -277,9 +291,25 @@ function KinChatPage(props: { const topInset = useContentTopInset(); const { state } = props; const subtitle = state._tag === "ready" ? kinChatStatusLine(state.chat.value.widgets) : null; + const { levels } = props; return ( - navigation.goBack()} /> + navigation.goBack()} + actions={ + levels == null + ? undefined + : [ + { + accessibilityLabel: "Levels", + icon: "slider.horizontal.3", + onPress: () => navigation.navigate("KinLevels", levels), + }, + ] + } + /> {state._tag === "ready" ? ( ) { + const navigation = useNavigation(); + const environmentId = Option.getOrNull(decodeEnvironmentId(route.params.environmentId)); + const orgId = Option.getOrNull(decodeOrgId(route.params.orgId)); + const agentId = Option.getOrNull(decodeAgentId(route.params.agentId)); + return ( + + navigation.goBack()} /> + + + {environmentId === null || orgId === null || agentId === null ? ( + + ) : ( + + )} + + + + ); +} + +function KinLevelsBody(props: { + readonly environmentId: EnvironmentId; + readonly input: KinLevelsGetInput; +}) { + const { environmentId, input } = props; + const atom = kinClient.levels({ environmentId, input }); + const result = useAtomValue(atom); + const host = useKinHostAt(environmentId); + const { agentNames } = kinDirectory(host._tag === "unpaired" ? { _tag: "none" } : host); + const inbox = useAtomValue(kinClient.inbox({ environmentId, input: {} })); + const canChange = useAtomValue(kinClient.lower.permissionAtom(environmentId)); + const lower = useAtomCommand(kinClient.lower, { reportFailure: false }); + const raise = useAtomCommand(kinClient.raise, { reportFailure: false }); + const [pending, setPending] = useState(null); + const [notice, setNotice] = useState<{ readonly text: string; readonly error: boolean } | null>( + null, + ); + + if (AsyncResult.isInitial(result)) { + return ( + + + + ); + } + if (AsyncResult.isFailure(result)) { + const cause = Cause.squash(result.cause); + if (isKinChatError(cause) && (cause.reason === "not_allowed" || cause.reason === "not_found")) { + return ( + + ); + } + return ( + + + +