Skip to content
Merged
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
36 changes: 33 additions & 3 deletions apps/mobile/src/features/threads/ChildThreadApprovals.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { useAtomValue } from "@effect/atom-react";
import { AuthOrchestrationOperateScope, type ScopedThreadRef } from "@t3tools/contracts";
import type { ChildThreadApproval } from "@t3tools/client-runtime/state/thread-requests";
import type {
ChildThreadApproval,
ChildThreadSecretRequest,
} from "@t3tools/client-runtime/state/thread-requests";
import {
isAtomCommandInterrupted,
squashAtomCommandFailure,
Expand All @@ -10,9 +13,15 @@ import { useEnvironmentScope } from "../../state/session";
import { ScrollView, View } from "react-native";
import Animated, { useAnimatedStyle, type DerivedValue } from "react-native-reanimated";
import { AppText } from "../../components/ui/AppText";
import { childThreadApprovalsAtom, threadEnvironment } from "../../state/threads";
import { useUniwindTheme } from "../../lib/useUniwindTheme";
import {
childThreadApprovalsAtom,
childThreadSecretRequestsAtom,
threadEnvironment,
} from "../../state/threads";
import { useAtomCommand } from "../../state/use-atom-command";
import { PendingApprovalCard } from "./PendingApprovalCard";
import { SecretRequestCard } from "./SecretRequestCard";

function ChildApproval({ entry }: { entry: ChildThreadApproval }) {
const canRespond = useEnvironmentScope(entry.thread.environmentId, AuthOrchestrationOperateScope);
Expand Down Expand Up @@ -59,6 +68,20 @@ function ChildApproval({ entry }: { entry: ChildThreadApproval }) {
);
}

function ChildSecret({ entry }: { entry: ChildThreadSecretRequest }) {
const iconColor = useUniwindTheme()["--color-icon-subtle"];
return (
<View className="mx-3.5 my-2 gap-2">
<AppText className="font-t3-bold text-sm text-foreground">Secret from {entry.title}</AppText>
<SecretRequestCard
environmentId={entry.thread.environmentId}
projectedItem={{ item: entry.item, visibility: "local" }}
iconColor={iconColor}
/>
</View>
);
}

export function ChildThreadApprovals({
threadRef,
maxHeight,
Expand All @@ -67,11 +90,18 @@ export function ChildThreadApprovals({
maxHeight: DerivedValue<number>;
}) {
const approvals = useAtomValue(childThreadApprovalsAtom(threadRef));
const secrets = useAtomValue(childThreadSecretRequestsAtom(threadRef));
const heightStyle = useAnimatedStyle(() => ({ maxHeight: Math.min(320, maxHeight.value / 2) }));
if (approvals.length === 0) return null;
if (approvals.length === 0 && secrets.length === 0) return null;
return (
<Animated.View style={heightStyle} className="overflow-hidden">
<ScrollView keyboardShouldPersistTaps="handled" nestedScrollEnabled style={{ flexShrink: 1 }}>
{secrets.map((entry) => (
<ChildSecret
key={JSON.stringify([entry.thread.environmentId, entry.item.id])}
entry={entry}
/>
))}
{approvals.map((entry) => (
<ChildApproval
key={JSON.stringify([
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/src/features/threads/SecretRequestCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const PRIVATE_SYMBOL: AppSymbolName = { ios: "checkmark.shield", android: "lock"

export function SecretRequestCard(props: {
readonly environmentId: EnvironmentId;
readonly projectedItem: OrchestrationV2ProjectedTurnItem;
readonly projectedItem: Pick<OrchestrationV2ProjectedTurnItem, "item" | "visibility">;
readonly iconColor: ColorValue;
}) {
const { item, visibility } = props.projectedItem;
Expand Down
9 changes: 8 additions & 1 deletion apps/mobile/src/state/threads.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { createChildThreadApprovalsAtom } from "@t3tools/client-runtime/state/thread-requests";
import {
createChildThreadApprovalsAtom,
createChildThreadSecretRequestsAtom,
} from "@t3tools/client-runtime/state/thread-requests";
import { useAtomValue } from "@effect/atom-react";
import {
createEnvironmentThreadDetailAtoms,
Expand Down Expand Up @@ -50,6 +53,10 @@ export const childThreadApprovalsAtom = createChildThreadApprovalsAtom({
childThreadInputsAtom: environmentThreadShells.childThreadInputsAtom,
pendingRequestsAtom: environmentThreadDetails.pendingRequestsAtom,
});
export const childThreadSecretRequestsAtom = createChildThreadSecretRequestsAtom({
childThreadInputsAtom: environmentThreadShells.childThreadInputsAtom,
visibleTurnItemsAtom: environmentThreadDetails.visibleTurnItemsAtom,
});

// Long enough for the opened screen to subscribe; its subscription keeps the thread after this.
const OPENING_THREAD_HOLD_MS = 3_000;
Expand Down
1 change: 1 addition & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ export default defineConfig({
"apps/mobile/src/features/review/ReviewSheet.tsx",
"apps/mobile/src/features/review/useNativeReviewDiffBridge.ts",
"apps/mobile/src/features/settings/SettingsEnvironmentsRouteScreen.tsx",
"apps/mobile/src/features/threads/ChildThreadApprovals.tsx",
"apps/mobile/src/features/threads/ThreadComposer.tsx",
"apps/mobile/src/features/threads/ThreadFeed.tsx",
"apps/mobile/src/features/threads/ThreadQueueControl.tsx",
Expand Down
Loading