feat(frontend): restore session progress sidebar
This commit is contained in:
@ -36,6 +36,7 @@ interface ChatStore {
|
||||
isAuthLoading: boolean;
|
||||
sessionId: string;
|
||||
messages: ChatMessage[];
|
||||
inputDrafts: Record<string, string>;
|
||||
isLoading: boolean;
|
||||
streamingContent: string;
|
||||
wsStatus: WsStatus;
|
||||
@ -56,6 +57,9 @@ interface ChatStore {
|
||||
setSessionId: (id: string) => void;
|
||||
setMessages: (msgs: ChatMessage[]) => void;
|
||||
addMessage: (msg: ChatMessage) => void;
|
||||
setInputDraft: (sessionId: string, value: string) => void;
|
||||
getInputDraft: (sessionId: string) => string;
|
||||
clearInputDraft: (sessionId: string) => void;
|
||||
updateMessageFeedback: (
|
||||
runId: string,
|
||||
feedbackState: ChatMessage['feedback_state'],
|
||||
@ -126,11 +130,12 @@ function createEventId(event: ProcessWsEvent): string {
|
||||
return `${event.type}:${event.run_id}:${event.created_at}:${suffix}`;
|
||||
}
|
||||
|
||||
export const useChatStore = create<ChatStore>((set) => ({
|
||||
export const useChatStore = create<ChatStore>((set, get) => ({
|
||||
user: null,
|
||||
isAuthLoading: true,
|
||||
sessionId: getInitialSessionId(),
|
||||
messages: [],
|
||||
inputDrafts: {},
|
||||
isLoading: false,
|
||||
streamingContent: '',
|
||||
wsStatus: 'disconnected',
|
||||
@ -155,6 +160,23 @@ export const useChatStore = create<ChatStore>((set) => ({
|
||||
},
|
||||
setMessages: (msgs) => set({ messages: msgs }),
|
||||
addMessage: (msg) => set((s) => ({ messages: [...s.messages, msg] })),
|
||||
setInputDraft: (sessionId, value) =>
|
||||
set((state) => ({
|
||||
inputDrafts: {
|
||||
...state.inputDrafts,
|
||||
[sessionId]: value,
|
||||
},
|
||||
})),
|
||||
getInputDraft: (sessionId) => get().inputDrafts[sessionId] ?? '',
|
||||
clearInputDraft: (sessionId) =>
|
||||
set((state) => {
|
||||
if (!(sessionId in state.inputDrafts)) {
|
||||
return {};
|
||||
}
|
||||
const nextDrafts = { ...state.inputDrafts };
|
||||
delete nextDrafts[sessionId];
|
||||
return { inputDrafts: nextDrafts };
|
||||
}),
|
||||
updateMessageFeedback: (runId, feedbackState, error) =>
|
||||
set((s) => ({
|
||||
messages: s.messages.map((message) =>
|
||||
|
||||
Reference in New Issue
Block a user