From 95b8b8e798a0b6368bf2d04e5d38ae6213d0c45f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sedat=20=C3=96zt=C3=BCrk?= Date: Sat, 21 Mar 2026 21:10:40 +0300 Subject: [PATCH] =?UTF-8?q?AiBot=20g=C3=BCncellemeleri?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/src/proxy/ai/models.ts | 18 +++++++++++ ui/src/store/admin.model.ts | 21 +++++++++++++ ui/src/store/base.model.ts | 30 ------------------- ui/src/views/ai/Assistant.tsx | 4 +-- .../views/ai/LoadAiPostsFromLocalStorage.tsx | 2 +- 5 files changed, 42 insertions(+), 33 deletions(-) diff --git a/ui/src/proxy/ai/models.ts b/ui/src/proxy/ai/models.ts index 840a6dd..c121a03 100644 --- a/ui/src/proxy/ai/models.ts +++ b/ui/src/proxy/ai/models.ts @@ -4,3 +4,21 @@ export interface AiDto extends FullAuditedEntityDto { name: string apiUrl?: string } + +export type ChatType = 'chat' | 'query' | 'analyze' + +export interface BaseContent { + type: ChatType + question: string + sql: string | null + answer: string | any[] + chart?: string + error?: string +} + +export type MessageContent = string | BaseContent + +export interface Message { + role: 'user' | 'assistant' + content: MessageContent +} \ No newline at end of file diff --git a/ui/src/store/admin.model.ts b/ui/src/store/admin.model.ts index 7beb8fe..550c7c9 100644 --- a/ui/src/store/admin.model.ts +++ b/ui/src/store/admin.model.ts @@ -4,12 +4,16 @@ import { Injections } from './store' import { GridOptionsEditDto } from '../proxy/form/models' import setNull from '../utils/setNull' import { ListState } from '@/proxy/admin/list-form/models' +import { Message } from '@/proxy/ai/models' export interface AdminStoreModel { lists: { values: GridOptionsEditDto | undefined states: ListState[] } + messages: { + aiPosts: Message[] + } } export interface AdminStoreActions { @@ -23,6 +27,10 @@ export interface AdminStoreActions { > setStates: Action } + messages: { + addAiPost: Action + setAiPosts: Action + } } export type AdminModel = AdminStoreModel & AdminStoreActions @@ -32,6 +40,9 @@ const initialState: AdminStoreModel = { values: undefined, states: [], }, + messages: { + aiPosts: [], + }, } export const adminModel: AdminModel = { @@ -62,4 +73,14 @@ export const adminModel: AdminModel = { actions.setListFormValues(result.data) }), }, + messages: { + ...initialState.messages, + addAiPost: action((state, payload) => { + state.aiPosts = [...state.aiPosts, payload] + }), + + setAiPosts: action((state, payload) => { + state.aiPosts = payload + }), + }, } diff --git a/ui/src/store/base.model.ts b/ui/src/store/base.model.ts index 663cc85..2d9b54a 100644 --- a/ui/src/store/base.model.ts +++ b/ui/src/store/base.model.ts @@ -1,24 +1,6 @@ import type { Action } from 'easy-peasy' import { action } from 'easy-peasy' -type ChatType = 'chat' | 'query' | 'analyze' - -interface BaseContent { - type: ChatType - question: string - sql: string | null - answer: string | any[] - chart?: string - error?: string -} - -type MessageContent = string | BaseContent - -export interface Message { - role: 'user' | 'assistant' - content: MessageContent -} - export interface StoreError { id: string title: string @@ -34,9 +16,7 @@ export interface BaseStoreModel { } messages: { errors: StoreError[] - // success: string[] warning: string[] - aiPosts: Message[] } } @@ -50,8 +30,6 @@ export interface BaseStoreActions { removeError: Action // setSuccess: Action setWarning: Action - addAiPost: Action - setAiPosts: Action } } @@ -63,7 +41,6 @@ const initialState: BaseStoreModel = { errors: [], // success: [], warning: [], - aiPosts: [], }, } @@ -92,12 +69,5 @@ export const baseModel: BaseModel = { state.warning = [] } }), - addAiPost: action((state, payload) => { - state.aiPosts = [...state.aiPosts, payload] - }), - - setAiPosts: action((state, payload) => { - state.aiPosts = payload - }), }, } diff --git a/ui/src/views/ai/Assistant.tsx b/ui/src/views/ai/Assistant.tsx index c606d84..5f54399 100644 --- a/ui/src/views/ai/Assistant.tsx +++ b/ui/src/views/ai/Assistant.tsx @@ -35,7 +35,7 @@ const isContentObject = (content: MessageContent): content is BaseContent => // Main Component const Assistant = () => { // Hooks - const { addAiPost } = useStoreActions((actions) => actions.base.messages) + const { addAiPost } = useStoreActions((actions) => actions.admin.messages) const [messages, setMessages] = useState([]) const [input, setInput] = useState('') const [loading, setLoading] = useState(false) @@ -48,7 +48,7 @@ const Assistant = () => { const { translate } = useLocalization() - const aiPosts = useStoreState((state) => state.base.messages.aiPosts) + const aiPosts = useStoreState((state) => state.admin.messages.aiPosts) useEffect(() => { if (messages.length === 0 && aiPosts.length > 0) { diff --git a/ui/src/views/ai/LoadAiPostsFromLocalStorage.tsx b/ui/src/views/ai/LoadAiPostsFromLocalStorage.tsx index 62119e9..4edc902 100644 --- a/ui/src/views/ai/LoadAiPostsFromLocalStorage.tsx +++ b/ui/src/views/ai/LoadAiPostsFromLocalStorage.tsx @@ -2,7 +2,7 @@ import { useStoreActions } from '@/store' import { useEffect } from 'react' const LoadAiPostsFromLocalStorage = () => { - const setAiPosts = useStoreActions((actions) => actions.base.messages.setAiPosts) + const setAiPosts = useStoreActions((actions) => actions.admin.messages.setAiPosts) useEffect(() => { const saved = localStorage.getItem('AiPosts')