import React from 'react'; import { Icon } from '@/components/icon/Icon'; import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'; import { useSessionAssistState } from '@/hooks/useSessionAssist'; import { useThemeSystem } from '@/contexts/useThemeSystem'; import { patchSessionMetadata } from '@/sync/session-actions'; import { useI18n } from '@/lib/i18n'; interface SessionSuggestionChipProps { sessionId: string | null; directory?: string; /** The composer already has content — the suggestion must stay out of the way. */ hidden: boolean; onApply: (text: string) => void; className?: string; } const isRecord = (value: unknown): value is Record => Boolean(value) && typeof value === 'object' && !Array.isArray(value); // One small-model-suggested follow-up message, styled like the draft starter // chips. Tapping it fills the composer (no auto-send); the X patches the // suggestion out of the session metadata so it stays dismissed everywhere. export const SessionSuggestionChip: React.FC = React.memo(({ sessionId, directory, hidden, onApply, className }) => { const { suggestion } = useSessionAssistState(sessionId ?? '', directory); const { t } = useI18n(); const { currentTheme } = useThemeSystem(); const [dismissing, setDismissing] = React.useState(false); const handleDismiss = React.useCallback(async (event: React.MouseEvent) => { event.stopPropagation(); if (!sessionId || dismissing) return; setDismissing(true); try { await patchSessionMetadata(sessionId, undefined, (metadata) => { const namespace = isRecord(metadata.openchamber) ? metadata.openchamber : {}; const assist = isRecord(namespace.assist) ? namespace.assist : {}; const nextAssist = { ...assist }; delete nextAssist.suggestion; return { ...metadata, openchamber: { ...namespace, assist: nextAssist } }; }); } catch (error) { console.warn('Failed to dismiss suggestion:', error); } finally { setDismissing(false); } }, [sessionId, dismissing]); if (!suggestion || hidden) { return null; } const chipStyle: React.CSSProperties = { backgroundColor: currentTheme?.colors?.surface?.elevated, borderColor: currentTheme?.colors?.interactive?.border, }; return (
{suggestion}
); }); SessionSuggestionChip.displayName = 'SessionSuggestionChip';