Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
import { iconSize, iconStroke } from '@/theme';
import { useRef, useState } from 'react';
import { Pressable, View } from 'react-native';
import { Copy, Check, Ellipsis } from 'lucide-react-native';
import { useTranslation } from 'react-i18next';
import { Text } from '@/components/AppText';
import { ChatReplyIcon } from '@/components/ChatReplyIcon';
import { NativePullDownMenu, usesNativePullDownMenu, type NativePullDownAction } from '@/platform/chrome/NativePullDownMenu';
import { useTheme, spacing } from '@/theme';
import { fontWeight, lineHeight, typeScale } from '@/theme/tokens';
/** §3 menu-item role: 16/22 medium. */
const menuItemText = { fontSize: typeScale.body, lineHeight: lineHeight.body, fontWeight: fontWeight.medium } as const;
import { CompanionSheet } from './CompanionSheet';
/** Compact companion controls; the existing task handlers still own every operation. */
export function CompanionMessageActions({ user, copied, copying, disabled, onCopy, actions, onAction }: {
user: boolean; copied: boolean; copying: boolean; disabled: boolean;
onCopy?: () => void; actions: NativePullDownAction[]; onAction(id: string): void;
}) {
const { t } = useTranslation(); const { colors } = useTheme();
const [open, setOpen] = useState(false);
const pending = useRef<string | null>(null);
// Desktop exposes this existing composer action as Reply in companion chats.
const reply = actions.find(action => action.id === 'add-to-chat');
const menuActions = actions.filter(action => action.id !== 'add-to-chat');
const hit = { width: 44, height: 44, alignItems: 'center' as const, justifyContent: 'center' as const };
const more = <Pressable style={hit} disabled={disabled} accessibilityRole="button" accessibilityState={{ disabled }} accessibilityLabel={t('message.renderer.moreActions')} testID="companion.messageMore" onPress={() => { if (!usesNativePullDownMenu()) setOpen(true); }}>
<Ellipsis size={iconSize.sm} color={colors.textSecondary} />
</Pressable>;
return <View style={{ flexDirection: 'row', justifyContent: user ? 'flex-end' : 'flex-start' }} testID="companion.messageActions">
{!user && onCopy ? <Pressable style={hit} disabled={disabled || copying} accessibilityRole="button" accessibilityLabel={t(copied ? 'message.renderer.copyStateCopied' : 'message.renderer.copyStateCopy')} onPress={onCopy} testID="message.copyButton">
{copied ? <Check size={iconSize.sm} color={colors.textSecondary} /> : <Copy size={iconSize.sm} color={colors.textSecondary} />}
</Pressable> : null}
{reply ? <Pressable style={hit} disabled={disabled || reply.disabled} accessibilityRole="button"
accessibilityState={{ disabled: disabled || !!reply.disabled }} accessibilityLabel={t('message.renderer.reply')}
onPress={() => onAction(reply.id)} testID="companion.messageReply">
<ChatReplyIcon size={iconSize.sm} color={colors.textSecondary} strokeWidth={iconStroke.regular} />
</Pressable> : null}
{/* The system menu (UIMenu / Android PopupMenu) opens over the trigger regardless of its
own disabled state, so a disabled More button is rendered without one. */}
{disabled ? more : <NativePullDownMenu actions={menuActions} onAction={onAction}>{more}</NativePullDownMenu>}
<CompanionSheet visible={open} title="" onClose={() => { pending.current = null; setOpen(false); }} onClosed={() => { const id = pending.current; pending.current = null; if (id) onAction(id); }}>
{menuActions.map(action => <Pressable key={action.id} disabled={action.disabled} accessibilityRole="button" style={{ minHeight: 44, justifyContent: 'center', paddingHorizontal: spacing.md }} onPress={() => { pending.current = action.id; setOpen(false); }}>
<Text style={{ ...menuItemText, color: action.destructive ? colors.destructive : action.disabled ? colors.textSecondary : colors.textPrimary }}>{action.title}</Text>
</Pressable>)}
</CompanionSheet>
</View>;
}