import type { SessionSummary } from "@linkshell/wire"; import { memo } from "react"; import { View } from "react-native"; import { PressableFeedback } from "./pressable-feedback"; import { Text } from "@/components/fixed-text"; import { useActions, useClient } from "@/lib/client"; import { sessionTitle, needsUserInput } from "@/lib/describe"; import { useLocale } from "@/lib/locale"; import { baseName, relativeTime } from "@/lib/format"; import { agentLook } from "@/theme/agents"; import { colors } from "@/theme/colors"; import { mono, radius, type } from "@/theme/type"; import { Icon } from "./icon"; import { Button } from "./button"; import { PermissionActions } from "./permission-actions"; import { openSession, SessionAvatar } from "./session-row"; /** A session waiting on the user, with its approval right on the card. */ export const NeedCard = memo(function NeedCard({ session, now, onPress }: { session: SessionSummary; now: number; onPress?: () => void }) { const { respond } = useActions(); const { pick } = useLocale(); const online = useClient((state) => state.status === "online"); const permission = session.permission; const question = session.asyncQuestions?.[0]; const asks = permission ? !!permission.questions?.length : needsUserInput(session); // An authorization link is only opened from the session, where its address is shown first: // accepting here would tell the agent "opened" without any page having been opened. const inSession = asks || !!permission?.url; const extra = Math.max(0, session.pendingPermissions + (session.asyncQuestions?.length ?? 0) - 1); const prompt = permission?.questions?.[0]?.text ?? question?.title ?? permission?.title ?? pick({ zh: "等你确认", en: "Waiting for your approval", ja: "承認待ち" }); return ( openSession(session.id))} accessibilityRole="button" accessibilityLabel={pick({ zh: `打开 ${sessionTitle(session)}`, en: `Open ${sessionTitle(session)}`, ja: `${sessionTitle(session)} を開く` })} style={{ flexDirection: "row", gap: 12, alignItems: "center" }} > {sessionTitle(session)} {relativeTime(session.updatedAt, now)} {baseName(session.cwd)} · {agentLook(session.agent).short} {prompt} {extra ? ( {pick({ zh: `还有 ${extra} 项`, en: `${extra} more`, ja: `他 ${extra} 件` })} ) : null} {permission?.detail && permission.detail !== prompt ? ( {permission.detail} ) : null} {inSession ? ( // Questions are answered in the session, where there is room for them. {asks ? pick({ zh: "等你回答", en: "Waiting for your answer", ja: "回答待ち" }) : pick({ zh: "等你确认", en: "Waiting for your approval", ja: "承認待ち" })}