Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add recommended tasks when instruction is empty #76

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions src/common/RecommendedTasks.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Button, VStack, Text } from "@chakra-ui/react";
import { useAppState } from "../state/store";

const tasks = [
'Post on twitter.com with content "an automated post from WebWand!" If I\'m not logged in, stop and wait for me to log in.',
"Find a book about AI and add it to cart on Amazon.com",
];

const RecommendedTasks = ({
runTask,
}: {
runTask: (instructions: string) => void;
}) => {
const state = useAppState((state) => ({
instructions: state.ui.instructions,
}));
if (state.instructions) {
return null;
}

const onButtonClick = (idx: number) => {
runTask(tasks[idx]);
};

return (
<VStack spacing={2} align="stretch">
<Text fontSize="large" mt={1}>
Examples:
</Text>
<Button
textAlign="left"
display="block"
variant="outline"
height="4rem"
onClick={() => onButtonClick(0)}
>
<Text fontWeight={600} noOfLines={1}>
Post on twitter.com
</Text>
<Text fontWeight={400} noOfLines={1} color="gray">
with content &quot;an automated post from WebWand!&quot;
</Text>
</Button>
<Button
textAlign="left"
display="block"
variant="outline"
height="4rem"
onClick={() => onButtonClick(1)}
>
<Text fontWeight={600} noOfLines={1}>
Find a book about AI
</Text>
<Text fontWeight={400} noOfLines={1} color="gray">
and add it to cart on Amazon.com
</Text>
</Button>
</VStack>
);
};

export default RecommendedTasks;
28 changes: 17 additions & 11 deletions src/common/TaskUI.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useCallback, useState } from "react";
import {
Button,
Box,
HStack,
Spacer,
Textarea,
Expand All @@ -15,6 +16,7 @@ import RunTaskButton from "./RunTaskButton";
import VoiceButton from "./VoiceButton";
import TaskHistory from "./TaskHistory";
import TaskStatus from "./TaskStatus";
import RecommendedTasks from "./RecommendedTasks";

function ActionExecutor() {
const state = useAppState((state) => ({
Expand All @@ -30,7 +32,7 @@ function ActionExecutor() {
}
`);
return (
<div>
<Box mt={4}>
<Textarea
value={action}
onChange={(e) => setAction(e.target.value)}
Expand All @@ -48,7 +50,7 @@ function ActionExecutor() {
Run
</Button>
</HStack>
</div>
</Box>
);
}

Expand Down Expand Up @@ -78,15 +80,16 @@ const TaskUI = () => {
[toast],
);

const runTask = useCallback(() => {
state.instructions && state.runTask(toastError);
// if (state.instructions) {
// chrome.runtime.sendMessage({
// action: 'runTask',
// task: state.instructions,
// });
// }
}, [state, toastError]);
const runTask = useCallback(
(newInstructions: string = "") => {
if (newInstructions) {
state.setInstructions(newInstructions);
}
const instructions = newInstructions || state.instructions;
instructions && state.runTask(toastError);
},
[state, toastError],
);

const onKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
if (e.key === "Enter" && !e.shiftKey) {
Expand Down Expand Up @@ -127,6 +130,9 @@ const TaskUI = () => {
</AlertDescription>
</Alert>
)}
{!state.voiceMode && !state.instructions && (
<RecommendedTasks runTask={runTask} />
)}
{debugMode && <ActionExecutor />}
<TaskHistory />
</>
Expand Down
2 changes: 2 additions & 0 deletions src/helpers/vision-agent/determineNavigateAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ You can use the following tool:

${navigateSchemaDescription}

You will have access to more tools as you progress through the task.

You will be given a task to perform.
This is an example of expected response from you:

Expand Down
Loading