Skip to content

Commit

Permalink
🐛 Always send finished message
Browse files Browse the repository at this point in the history
  • Loading branch information
asim-shrestha committed Jun 22, 2023
1 parent 793aef5 commit 5dd0a2e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
5 changes: 4 additions & 1 deletion next/src/components/console/ChatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
getTaskStatus,
isAction,
TASK_STATUS_COMPLETED,
TASK_STATUS_FINAL,
TASK_STATUS_STARTED,
} from "../../types/task";

Expand Down Expand Up @@ -60,7 +61,9 @@ const getMessagePrefix = (message: Message) => {
} else if (getTaskStatus(message) === TASK_STATUS_STARTED) {
return "Task Added:";
} else if (getTaskStatus(message) === TASK_STATUS_COMPLETED) {
return `Completing: ${message.value}`;
return `Executing: ${message.value}`;
} else if (getTaskStatus(message) === TASK_STATUS_FINAL) {
return `Finished: ${message.value}`;
}
return "";
};
Expand Down
7 changes: 6 additions & 1 deletion next/src/components/utils/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
isTask,
TASK_STATUS_COMPLETED,
TASK_STATUS_EXECUTING,
TASK_STATUS_FINAL,
TASK_STATUS_STARTED,
} from "../../types/task";
import type { Message } from "../../types/message";
Expand All @@ -32,6 +33,7 @@ export const getMessageContainerStyle = (message: Message) => {
case TASK_STATUS_EXECUTING:
return "border-white/20 hover:border-white/40";
case TASK_STATUS_COMPLETED:
case TASK_STATUS_FINAL:
return "border-green-500 hover:border-green-400";
default:
return "";
Expand Down Expand Up @@ -60,7 +62,10 @@ export const getTaskStatusIcon = (
) : (
<FaCircleNotch className={`${taskStatusIconClass} animate-spin`} />
);
} else if (getTaskStatus(message) === TASK_STATUS_COMPLETED) {
} else if (
getTaskStatus(message) === TASK_STATUS_COMPLETED ||
getTaskStatus(message) === TASK_STATUS_FINAL
) {
return (
<FaCheckCircle className={`${taskStatusIconClass} text-green-500 hover:text-green-400`} />
);
Expand Down
5 changes: 1 addition & 4 deletions next/src/services/agent/autonomous-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class AutonomousAgent {
);

this.model.updateTaskStatus(currentTask, "completed");
this.messageService.sendMessage({ ...currentTask, status: "final" });

// Wait before adding tasks TODO: think about removing this
await new Promise((r) => setTimeout(r, TIMEOUT_LONG));
Expand All @@ -148,12 +149,8 @@ class AutonomousAgent {
executionMessage.info || ""
);
await this.createTasks(newTasks);
if (newTasks.length == 0) {
this.messageService.sendMessage({ ...currentTask, status: "completed" });
}
} catch (e) {
console.error(e);
this.messageService.sendMessage({ ...currentTask, status: "completed" });
}

await this.loop();
Expand Down
13 changes: 7 additions & 6 deletions next/src/types/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ const messageSchemaBase = z.object({
info: z.string().optional().nullable(),
});

export const [TASK_STATUS_STARTED, TASK_STATUS_EXECUTING, TASK_STATUS_COMPLETED] = [
"started" as const,
"executing" as const,
"completed" as const,
"final" as const,
];
export const [
TASK_STATUS_STARTED,
TASK_STATUS_EXECUTING,
TASK_STATUS_COMPLETED,
TASK_STATUS_FINAL,
] = ["started" as const, "executing" as const, "completed" as const, "final" as const];

export const TaskStatusSchema = z.union([
z.literal(TASK_STATUS_STARTED),
z.literal(TASK_STATUS_EXECUTING),
z.literal(TASK_STATUS_COMPLETED),
z.literal(TASK_STATUS_FINAL),
z.literal(""),
]);

Expand Down

1 comment on commit 5dd0a2e

@vercel
Copy link

@vercel vercel bot commented on 5dd0a2e Jun 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./docs

docs-reworkd.vercel.app
docs-git-main-reworkd.vercel.app
docs.reworkd.ai

Please sign in to comment.