PluginProbe
Extendify / 3.0.4
Extendify v3.0.4
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / HelpCenter / state / ai-chat.js

ai-chat.js in Extendify 3.0.4, at src/HelpCenter/state/ai-chat.js

42 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { create } from 'zustand';
2 import { createJSONStorage, devtools, persist } from 'zustand/middleware';
3
4 const initialState = {
5 experienceLevel: 'beginner',
6 currentQuestion: undefined,
7 };
8
9 const state = (set, get) => ({
10 history: [],
11 ...initialState,
12 setCurrentQuestion: (currentQuestion) => set({ currentQuestion }),
13 setExperienceLevel: (experienceLevel) => set({ experienceLevel }),
14 addHistory: (question) =>
15 set((state) => ({
16 // Save the latest 10
17 history: [
18 question,
19 ...state.history
20 .filter(({ answerId }) => answerId !== question.answerId)
21 .slice(0, 9),
22 ],
23 })),
24 hasHistory: () => get().history.length > 0,
25 clearHistory: () => set({ history: [] }),
26 deleteFromHistory: (question) =>
27 set((state) => ({
28 history: state.history.filter(
29 ({ answerId: id }) => id !== question.answerId,
30 ),
31 })),
32 historyCount: () => get().history.length,
33 reset: () => set({ ...initialState }),
34 });
35
36 export const useAIChatStore = create(
37 persist(devtools(state, { name: 'Extendify Chat History' }), {
38 name: `extendify-chat-history-${window.extSharedData.siteId}`,
39 storage: createJSONStorage(() => localStorage),
40 }),
41 );
42