Open History to see the last commit
1import { TextInput, View } from "react-native";
2
3import { AppText as Text } from "../../../components/ui/AppText";
4import type { ComposerEditorSelection } from "../../../components/ComposerEditor";
5import {
6 ComposerDictationCancelAction,
7 ComposerDictationError,
8 ComposerDictationPrimaryAction,
9 ComposerDictationStartAction,
10 ComposerDictationStatus,
11 ComposerDictationToolbar,
12} from "../../voice-input/ComposerDictationControl";
13import type { useVoiceInputController } from "../../voice-input/useVoiceInputController";
14import { resolveVoiceComposerPresentation } from "../../voice-input/voiceInputPresentation";
15
16export function ScheduledTaskPromptField(props: {
17 readonly value: string;
18 readonly onChange: (value: string) => void;
19 readonly selection: ComposerEditorSelection;
20 readonly onChangeSelection: (selection: ComposerEditorSelection) => void;
21 readonly disabled: boolean;
22 readonly voiceInput: ReturnType<typeof useVoiceInputController>;
23}) {
24 const voice = props.voiceInput;
25 const presentation = resolveVoiceComposerPresentation(voice.state, voice.elapsedSeconds);
26 const showsDictation = presentation.statusKind === "active";
27 const showsIdleTrigger = voice.isAvailable && !showsDictation;
28
29 return (
30 <View className="gap-2 border-t border-border-subtle px-4 py-3">
31 <Text className="text-sm text-foreground-muted">Prompt</Text>
32 <View className="flex-row items-end">
33 <TextInput
34 accessibilityLabel="Prompt"
35 value={props.value}
36 onChangeText={props.onChange}
37 selection={props.selection}
38 onSelectionChange={({ nativeEvent }) => props.onChangeSelection(nativeEvent.selection)}
39 readOnly={props.disabled || voice.freezesEditor}
40 multiline
41 scrollEnabled
42 textAlignVertical="top"
43 placeholder="What should the agent do each time?"
44 placeholderTextColorClassName="accent-foreground-muted"
45 className="max-h-40 min-h-24 min-w-0 flex-1 font-sans text-base text-foreground"
46 />
47 {showsIdleTrigger ? (
48 <ComposerDictationStartAction
49 state={voice.state}
50 isAvailable={voice.isAvailable}
51 disabled={props.disabled}
52 onStart={voice.start}
53 onCancel={voice.cancel}
54 />
55 ) : null}
56 </View>
57 <ComposerDictationError
58 error={voice.state.phase === "error" ? voice.state.error : null}
59 onDismiss={voice.cancel}
60 />
61 {showsDictation ? (
62 <ComposerDictationToolbar showsDictation>
63 <View className="h-11 flex-row items-center">
64 <ComposerDictationCancelAction presentation={presentation} onCancel={voice.cancel} />
65 <ComposerDictationStatus
66 audioLevels={voice.audioLevels}
67 elapsedSeconds={voice.elapsedSeconds}
68 phase={voice.state.phase}
69 presentation={presentation}
70 />
71 <ComposerDictationPrimaryAction
72 state={voice.state}
73 presentation={presentation}
74 isAvailable={voice.isAvailable}
75 disabled={props.disabled}
76 onStart={voice.start}
77 onConfirm={voice.stop}
78 onCancel={voice.cancel}
79 />
80 </View>
81 </ComposerDictationToolbar>
82 ) : null}
83 </View>
84 );
85}