# extendify/1.17.1/src/HelpCenter/state/ai-chat.js

Extendify, version 1.17.1. 42 lines.

- Page: https://pluginprobe.com/plugins/extendify/1.17.1/code/src/HelpCenter/state/ai-chat.js
- Raw: https://pluginprobe.com/plugins/extendify/1.17.1/raw/src/HelpCenter/state/ai-chat.js
- Modified: 2024-07-12T05:26:18+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/extendify/1.17.1/code/src/HelpCenter/state/ai-chat.js#L10-L20`.

```javascript
import { create } from 'zustand';
import { devtools, persist, createJSONStorage } from 'zustand/middleware';

const initialState = {
	experienceLevel: 'beginner',
	currentQuestion: undefined,
};

const state = (set, get) => ({
	history: [],
	...initialState,
	setCurrentQuestion: (currentQuestion) => set({ currentQuestion }),
	setExperienceLevel: (experienceLevel) => set({ experienceLevel }),
	addHistory: (question) =>
		set((state) => ({
			// Save the latest 10
			history: [
				question,
				...state.history
					.filter(({ answerId }) => answerId !== question.answerId)
					.slice(0, 9),
			],
		})),
	hasHistory: () => get().history.length > 0,
	clearHistory: () => set({ history: [] }),
	deleteFromHistory: (question) =>
		set((state) => ({
			history: state.history.filter(
				({ answerId: id }) => id !== question.answerId,
			),
		})),
	historyCount: () => get().history.length,
	reset: () => set({ ...initialState }),
});

export const useAIChatStore = create(
	persist(devtools(state, { name: 'Extendify Chat History' }), {
		name: 'extendify-chat-history',
		storage: createJSONStorage(() => localStorage),
	}),
);

```
