Skip to content

Commit 25c21cb

Browse files
authored
fix: approval dialog clears user input (#57)
1 parent 8b8eefb commit 25c21cb

File tree

2 files changed

+77
-71
lines changed

2 files changed

+77
-71
lines changed

packages/blink/src/tui/components/text-input.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,14 @@ function TextInput({
5555
slashCommands,
5656
onLayoutChange,
5757
borderColor,
58+
visible,
5859
}: {
5960
onSubmit: (value: string) => void;
6061
placeholder?: string;
6162
slashCommands?: Array<SlashCommand>;
6263
onLayoutChange?: () => void;
6364
borderColor?: string;
65+
visible: boolean;
6466
}) {
6567
const config = useMemo(() => createMinimalConfig(), []);
6668
const [userMessages, setUserMessages] = useState<string[]>([]);
@@ -92,6 +94,10 @@ function TextInput({
9294
return convertToCommands(slashCommands ?? []);
9395
}, [slashCommands]);
9496

97+
if (!visible) {
98+
return null;
99+
}
100+
95101
return (
96102
<Box marginBottom={isSlashOpen ? 1 : 0} flexDirection="column">
97103
<InputPrompt

packages/blink/src/tui/dev.tsx

Lines changed: 71 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ const App = ({ directory }: { directory: string }) => {
380380
</Box>
381381

382382
<Box flexDirection="column" marginTop={1}>
383-
{dev.approval ? (
383+
{dev.approval && (
384384
<ApprovalInput
385385
onConfirm={async (approved, autoApprove) => {
386386
if (approved) {
@@ -393,82 +393,82 @@ const App = ({ directory }: { directory: string }) => {
393393
autoApproveEnabled={dev.approval.autoApproveEnabled}
394394
logger={logger}
395395
/>
396-
) : (
397-
<TextInput
398-
borderColor={colors[dev.mode]}
399-
slashCommands={[
400-
{
401-
name: "help",
402-
description: "Show help information",
403-
action: () => {
404-
getHelpText(dev.build.entrypoint).forEach((line) =>
405-
console.log(line)
406-
);
407-
},
396+
)}
397+
<TextInput
398+
visible={!dev.approval}
399+
borderColor={colors[dev.mode]}
400+
slashCommands={[
401+
{
402+
name: "help",
403+
description: "Show help information",
404+
action: () => {
405+
getHelpText(dev.build.entrypoint).forEach((line) =>
406+
console.log(line)
407+
);
408408
},
409-
{
410-
name: "reset",
411-
altNames: ["clear"],
412-
description: "Reset the chat",
413-
action: async () => {
414-
await dev.chat.resetChat();
415-
resetTerminal();
416-
},
409+
},
410+
{
411+
name: "reset",
412+
altNames: ["clear"],
413+
description: "Reset the chat",
414+
action: async () => {
415+
await dev.chat.resetChat();
416+
resetTerminal();
417417
},
418-
{
419-
name: "switch",
420-
description: "Switch to a different chat",
421-
action: (args: string) => {
422-
dev.switchChat(args as ID);
423-
},
424-
completion: async (partialArg: string) => {
425-
return dev.chats.filter((id) => id.startsWith(partialArg));
426-
},
418+
},
419+
{
420+
name: "switch",
421+
description: "Switch to a different chat",
422+
action: (args: string) => {
423+
dev.switchChat(args as ID);
427424
},
428-
{
429-
name: "new",
430-
description: "Create a new chat",
431-
action: (args: string) => {
432-
dev.switchChat(args as ID);
433-
},
425+
completion: async (partialArg: string) => {
426+
return dev.chats.filter((id) => id.startsWith(partialArg));
434427
},
435-
{
436-
name: "edit",
437-
description: "Switch to Edit mode (AI helps build your agent)",
438-
action: () => {
439-
dev.chat.stopStreaming();
440-
dev.setMode("edit");
441-
},
428+
},
429+
{
430+
name: "new",
431+
description: "Create a new chat",
432+
action: (args: string) => {
433+
dev.switchChat(args as ID);
442434
},
443-
{
444-
name: "run",
445-
description: "Switch to Run mode (use your agent)",
446-
action: () => {
447-
dev.chat.stopStreaming();
448-
dev.setMode("run");
449-
},
435+
},
436+
{
437+
name: "edit",
438+
description: "Switch to Edit mode (AI helps build your agent)",
439+
action: () => {
440+
dev.chat.stopStreaming();
441+
dev.setMode("edit");
450442
},
451-
...(optionCommand ? [optionCommand] : []),
452-
]}
453-
onSubmit={(value) => {
454-
dev.chat.sendMessage({
455-
id: crypto.randomUUID(),
456-
role: "user",
457-
parts: [{ type: "text", text: value }],
458-
created_at: new Date().toISOString(),
459-
metadata: undefined,
460-
mode: dev.mode,
461-
});
462-
return true;
463-
}}
464-
onLayoutChange={() => {
465-
// We could reset the terminal here to fix the extra
466-
// space added by the slash command.
467-
//
468-
// It looks a bit janky, though.
469-
}}
470-
/>
471-
)}
443+
},
444+
{
445+
name: "run",
446+
description: "Switch to Run mode (use your agent)",
447+
action: () => {
448+
dev.chat.stopStreaming();
449+
dev.setMode("run");
450+
},
451+
},
452+
...(optionCommand ? [optionCommand] : []),
453+
]}
454+
onSubmit={(value) => {
455+
dev.chat.sendMessage({
456+
id: crypto.randomUUID(),
457+
role: "user",
458+
parts: [{ type: "text", text: value }],
459+
created_at: new Date().toISOString(),
460+
metadata: undefined,
461+
mode: dev.mode,
462+
});
463+
return true;
464+
}}
465+
onLayoutChange={() => {
466+
// We could reset the terminal here to fix the extra
467+
// space added by the slash command.
468+
//
469+
// It looks a bit janky, though.
470+
}}
471+
/>
472472
</Box>
473473

474474
<Box>

0 commit comments

Comments
 (0)