mirror of
https://github.com/eigent-ai/eigent.git
synced 2026-05-20 01:09:26 +00:00
enhance: queue per project basis
This commit is contained in:
parent
d494d1bcca
commit
24d3ca3dec
3 changed files with 96 additions and 56 deletions
|
|
@ -20,7 +20,7 @@ export default function ChatBox(): JSX.Element {
|
|||
const [message, setMessage] = useState<string>("");
|
||||
|
||||
//Get Chatstore for the active project's task
|
||||
const { chatStore } = useChatStoreAdapter();
|
||||
const { chatStore, projectStore } = useChatStoreAdapter();
|
||||
if (!chatStore) {
|
||||
return <div>Loading...</div>;
|
||||
}
|
||||
|
|
@ -110,7 +110,7 @@ export default function ChatBox(): JSX.Element {
|
|||
if (isTaskBusy && !task.activeAsk) {
|
||||
// Queue the message instead of sending immediately
|
||||
const currentAttaches = JSON.parse(JSON.stringify(task.attaches)) || [];
|
||||
chatStore.addQueuedMessage(_taskId, tempMessageContent, currentAttaches);
|
||||
projectStore.addQueuedMessage(projectStore.activeProjectId as string, tempMessageContent, currentAttaches);
|
||||
chatStore.setAttaches(_taskId, []); // Clear attaches after queuing
|
||||
setMessage("");
|
||||
if (textareaRef.current) textareaRef.current.style.height = "60px";
|
||||
|
|
@ -400,9 +400,10 @@ export default function ChatBox(): JSX.Element {
|
|||
const getBottomBoxState = () => {
|
||||
if (!chatStore.activeTaskId) return "input";
|
||||
const task = chatStore.tasks[chatStore.activeTaskId];
|
||||
const activeProject = projectStore.getProjectById(projectStore.activeProjectId || '');
|
||||
|
||||
// Check for queued messages
|
||||
if (task.queuedMessages && task.queuedMessages.length > 0) {
|
||||
// Check for queued messages at project level
|
||||
if (activeProject?.queuedMessages && activeProject.queuedMessages.length > 0) {
|
||||
return "queuing";
|
||||
}
|
||||
|
||||
|
|
@ -720,12 +721,12 @@ export default function ChatBox(): JSX.Element {
|
|||
{chatStore.activeTaskId && (
|
||||
<BottomBox
|
||||
state={getBottomBoxState()}
|
||||
queuedMessages={chatStore.tasks[chatStore.activeTaskId]?.queuedMessages?.map(m => ({
|
||||
queuedMessages={projectStore.getProjectById(projectStore.activeProjectId || '')?.queuedMessages?.map(m => ({
|
||||
id: m.id,
|
||||
content: m.content,
|
||||
timestamp: m.timestamp
|
||||
})) || []}
|
||||
onRemoveQueuedMessage={(id) => chatStore.removeQueuedMessage(chatStore.activeTaskId as string, id)}
|
||||
onRemoveQueuedMessage={(id) => projectStore.removeQueuedMessage(projectStore.activeProjectId as string, id)}
|
||||
subTasks={chatStore.tasks[chatStore.activeTaskId]?.taskInfo?.map(t => ({
|
||||
id: t.id || generateUniqueId(),
|
||||
content: t.content,
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ interface Task {
|
|||
snapshotsTemp: any[];
|
||||
isTakeControl: boolean;
|
||||
isTaskEdit: boolean;
|
||||
queuedMessages: Array<{ id: string; content: string; timestamp: number; attaches: File[] }>;
|
||||
}
|
||||
|
||||
export interface ChatStore {
|
||||
|
|
@ -95,9 +94,6 @@ export interface ChatStore {
|
|||
setSnapshotsTemp: (taskId: string, snapshot: any) => void,
|
||||
setIsTaskEdit: (taskId: string, isTaskEdit: boolean) => void,
|
||||
clearTasks: () => void,
|
||||
addQueuedMessage: (taskId: string, content: string, attaches: File[]) => void;
|
||||
removeQueuedMessage: (taskId: string, messageId: string) => void;
|
||||
clearQueuedMessages: (taskId: string) => void;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -146,7 +142,6 @@ const chatStore = (initial?: Partial<ChatStore>) => createStore<ChatStore>()(
|
|||
snapshotsTemp: [],
|
||||
isTakeControl: false,
|
||||
isTaskEdit: false,
|
||||
queuedMessages: []
|
||||
},
|
||||
}
|
||||
}))
|
||||
|
|
@ -1705,50 +1700,6 @@ const chatStore = (initial?: Partial<ChatStore>) => createStore<ChatStore>()(
|
|||
},
|
||||
}))
|
||||
},
|
||||
addQueuedMessage(taskId: string, content: string, attaches: File[]) {
|
||||
set((state) => ({
|
||||
...state,
|
||||
tasks: {
|
||||
...state.tasks,
|
||||
[taskId]: {
|
||||
...state.tasks[taskId],
|
||||
queuedMessages: [
|
||||
...state.tasks[taskId].queuedMessages,
|
||||
{
|
||||
id: generateUniqueId(),
|
||||
content,
|
||||
timestamp: Date.now(),
|
||||
attaches: [...attaches]
|
||||
}
|
||||
]
|
||||
},
|
||||
},
|
||||
}))
|
||||
},
|
||||
removeQueuedMessage(taskId: string, messageId: string) {
|
||||
set((state) => ({
|
||||
...state,
|
||||
tasks: {
|
||||
...state.tasks,
|
||||
[taskId]: {
|
||||
...state.tasks[taskId],
|
||||
queuedMessages: state.tasks[taskId].queuedMessages.filter(m => m.id !== messageId)
|
||||
},
|
||||
},
|
||||
}))
|
||||
},
|
||||
clearQueuedMessages(taskId: string) {
|
||||
set((state) => ({
|
||||
...state,
|
||||
tasks: {
|
||||
...state.tasks,
|
||||
[taskId]: {
|
||||
...state.tasks[taskId],
|
||||
queuedMessages: []
|
||||
},
|
||||
},
|
||||
}))
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ interface Project {
|
|||
updatedAt: number;
|
||||
chatStores: { [chatId: string]: VanillaChatStore }; // Multiple chat stores for this project
|
||||
activeChatId: string | null; // ID of the currently active chat store
|
||||
queuedMessages: Array<{ id: string; content: string; timestamp: number; attaches: File[] }>; // Project-level queued messages
|
||||
metadata?: {
|
||||
tags?: string[];
|
||||
priority?: 'low' | 'medium' | 'high';
|
||||
|
|
@ -34,6 +35,11 @@ interface ProjectStore {
|
|||
updateProject: (projectId: string, updates: Partial<Omit<Project, 'id' | 'createdAt'>>) => void;
|
||||
replayProject: (taskIds: string[], question?: string, projectId?: string) => string;
|
||||
|
||||
// Project-level queued messages management
|
||||
addQueuedMessage: (projectId: string, content: string, attaches: File[]) => void;
|
||||
removeQueuedMessage: (projectId: string, messageId: string) => void;
|
||||
clearQueuedMessages: (projectId: string) => void;
|
||||
|
||||
// Chat store state management
|
||||
createChatStore: (projectId: string, chatName?: string) => string | null;
|
||||
setActiveChatStore: (projectId: string, chatId: string) => void;
|
||||
|
|
@ -76,6 +82,11 @@ const isEmptyProject = (project: Project): boolean => {
|
|||
return false;
|
||||
}
|
||||
|
||||
// Check if project has any queued messages
|
||||
if (project.queuedMessages && project.queuedMessages.length > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if task is in initial/empty state
|
||||
const isEmpty = (
|
||||
Array.isArray(task.messages) && task.messages.length === 0 &&
|
||||
|
|
@ -153,6 +164,7 @@ const projectStore = create<ProjectStore>()((set, get) => ({
|
|||
[initialChatId]: initialChatStore
|
||||
},
|
||||
activeChatId: initialChatId,
|
||||
queuedMessages: [], // Initialize empty queued messages array
|
||||
metadata: {
|
||||
status: 'active'
|
||||
}
|
||||
|
|
@ -498,6 +510,75 @@ const projectStore = create<ProjectStore>()((set, get) => ({
|
|||
return null;
|
||||
},
|
||||
|
||||
// Project-level queued messages management
|
||||
addQueuedMessage: (projectId: string, content: string, attaches: File[]) => {
|
||||
const { projects } = get();
|
||||
|
||||
if (!projects[projectId]) {
|
||||
console.warn(`Project ${projectId} not found`);
|
||||
return;
|
||||
}
|
||||
|
||||
set((state) => ({
|
||||
projects: {
|
||||
...state.projects,
|
||||
[projectId]: {
|
||||
...state.projects[projectId],
|
||||
queuedMessages: [
|
||||
...state.projects[projectId].queuedMessages,
|
||||
{
|
||||
id: generateUniqueId(),
|
||||
content,
|
||||
timestamp: Date.now(),
|
||||
attaches: [...attaches]
|
||||
}
|
||||
],
|
||||
updatedAt: Date.now()
|
||||
}
|
||||
}
|
||||
}));
|
||||
},
|
||||
|
||||
removeQueuedMessage: (projectId: string, messageId: string) => {
|
||||
const { projects } = get();
|
||||
|
||||
if (!projects[projectId]) {
|
||||
console.warn(`Project ${projectId} not found`);
|
||||
return;
|
||||
}
|
||||
|
||||
set((state) => ({
|
||||
projects: {
|
||||
...state.projects,
|
||||
[projectId]: {
|
||||
...state.projects[projectId],
|
||||
queuedMessages: state.projects[projectId].queuedMessages.filter(m => m.id !== messageId),
|
||||
updatedAt: Date.now()
|
||||
}
|
||||
}
|
||||
}));
|
||||
},
|
||||
|
||||
clearQueuedMessages: (projectId: string) => {
|
||||
const { projects } = get();
|
||||
|
||||
if (!projects[projectId]) {
|
||||
console.warn(`Project ${projectId} not found`);
|
||||
return;
|
||||
}
|
||||
|
||||
set((state) => ({
|
||||
projects: {
|
||||
...state.projects,
|
||||
[projectId]: {
|
||||
...state.projects[projectId],
|
||||
queuedMessages: [],
|
||||
updatedAt: Date.now()
|
||||
}
|
||||
}
|
||||
}));
|
||||
},
|
||||
|
||||
getAllChatStores: (projectId: string) => {
|
||||
const { projects } = get();
|
||||
|
||||
|
|
@ -515,7 +596,14 @@ const projectStore = create<ProjectStore>()((set, get) => ({
|
|||
|
||||
getProjectById: (projectId: string) => {
|
||||
const { projects } = get();
|
||||
return projects[projectId] || null;
|
||||
const project = projects[projectId] || null;
|
||||
|
||||
// Ensure backwards compatibility - add queuedMessages if it doesn't exist
|
||||
if (project && !project.queuedMessages) {
|
||||
project.queuedMessages = [];
|
||||
}
|
||||
|
||||
return project;
|
||||
}
|
||||
}));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue