-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUserInput.tsx
More file actions
58 lines (47 loc) · 1.22 KB
/
UserInput.tsx
File metadata and controls
58 lines (47 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { BlinkCaret } from "components/BlinkCaret"
import { useCycleMessages } from "hooks/useCycleMessages"
import { Box } from "ink"
import TextInput from "ink-text-input"
import { AgentStore } from "store"
const commands = {
CLEAR: "clear",
EXIT: "exit",
}
export const UserInput: React.FC = () => {
const store = AgentStore.useStoreState((state) => state)
const actions = AgentStore.useStoreActions((actions) => actions)
const { reset } = useCycleMessages()
const handleSubmit = (value: string) => {
if (value.toLowerCase() === commands.EXIT) {
process.exit(0)
}
if (value.toLowerCase() === commands.CLEAR) {
actions.reset()
return
}
if (!value.trim()) {
return
}
actions.addChatHistoryEntry({
type: "message",
role: "user",
content: value,
})
actions.sendMessage(value)
// Slight delay just in case user has aborted request via second message
setTimeout(() => {
actions.setIsProcessing(true)
}, 100)
reset()
}
return (
<Box>
<BlinkCaret enabled={!store.isProcessing} />
<TextInput
value={store.input}
onChange={actions.setInput}
onSubmit={handleSubmit}
/>
</Box>
)
}