AiBot güncellemeleri

This commit is contained in:
Sedat Öztürk 2026-03-21 21:10:40 +03:00
parent 196b0dc24b
commit 95b8b8e798
5 changed files with 42 additions and 33 deletions

View file

@ -4,3 +4,21 @@ export interface AiDto extends FullAuditedEntityDto<string> {
name: string name: string
apiUrl?: 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
}

View file

@ -4,12 +4,16 @@ import { Injections } from './store'
import { GridOptionsEditDto } from '../proxy/form/models' import { GridOptionsEditDto } from '../proxy/form/models'
import setNull from '../utils/setNull' import setNull from '../utils/setNull'
import { ListState } from '@/proxy/admin/list-form/models' import { ListState } from '@/proxy/admin/list-form/models'
import { Message } from '@/proxy/ai/models'
export interface AdminStoreModel { export interface AdminStoreModel {
lists: { lists: {
values: GridOptionsEditDto | undefined values: GridOptionsEditDto | undefined
states: ListState[] states: ListState[]
} }
messages: {
aiPosts: Message[]
}
} }
export interface AdminStoreActions { export interface AdminStoreActions {
@ -23,6 +27,10 @@ export interface AdminStoreActions {
> >
setStates: Action<AdminStoreModel['lists'], ListState> setStates: Action<AdminStoreModel['lists'], ListState>
} }
messages: {
addAiPost: Action<AdminStoreModel['messages'], Message>
setAiPosts: Action<AdminStoreModel['messages'], Message[]>
}
} }
export type AdminModel = AdminStoreModel & AdminStoreActions export type AdminModel = AdminStoreModel & AdminStoreActions
@ -32,6 +40,9 @@ const initialState: AdminStoreModel = {
values: undefined, values: undefined,
states: [], states: [],
}, },
messages: {
aiPosts: [],
},
} }
export const adminModel: AdminModel = { export const adminModel: AdminModel = {
@ -62,4 +73,14 @@ export const adminModel: AdminModel = {
actions.setListFormValues(result.data) actions.setListFormValues(result.data)
}), }),
}, },
messages: {
...initialState.messages,
addAiPost: action((state, payload) => {
state.aiPosts = [...state.aiPosts, payload]
}),
setAiPosts: action((state, payload) => {
state.aiPosts = payload
}),
},
} }

View file

@ -1,24 +1,6 @@
import type { Action } from 'easy-peasy' import type { Action } from 'easy-peasy'
import { 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 { export interface StoreError {
id: string id: string
title: string title: string
@ -34,9 +16,7 @@ export interface BaseStoreModel {
} }
messages: { messages: {
errors: StoreError[] errors: StoreError[]
// success: string[]
warning: string[] warning: string[]
aiPosts: Message[]
} }
} }
@ -50,8 +30,6 @@ export interface BaseStoreActions {
removeError: Action<BaseStoreModel['messages'], string> removeError: Action<BaseStoreModel['messages'], string>
// setSuccess: Action<BaseStoreModel, string> // setSuccess: Action<BaseStoreModel, string>
setWarning: Action<BaseStoreModel['messages'], string> setWarning: Action<BaseStoreModel['messages'], string>
addAiPost: Action<BaseStoreModel['messages'], Message>
setAiPosts: Action<BaseStoreModel['messages'], Message[]>
} }
} }
@ -63,7 +41,6 @@ const initialState: BaseStoreModel = {
errors: [], errors: [],
// success: [], // success: [],
warning: [], warning: [],
aiPosts: [],
}, },
} }
@ -92,12 +69,5 @@ export const baseModel: BaseModel = {
state.warning = [] state.warning = []
} }
}), }),
addAiPost: action((state, payload) => {
state.aiPosts = [...state.aiPosts, payload]
}),
setAiPosts: action((state, payload) => {
state.aiPosts = payload
}),
}, },
} }

View file

@ -35,7 +35,7 @@ const isContentObject = (content: MessageContent): content is BaseContent =>
// Main Component // Main Component
const Assistant = () => { const Assistant = () => {
// Hooks // Hooks
const { addAiPost } = useStoreActions((actions) => actions.base.messages) const { addAiPost } = useStoreActions((actions) => actions.admin.messages)
const [messages, setMessages] = useState<Message[]>([]) const [messages, setMessages] = useState<Message[]>([])
const [input, setInput] = useState('') const [input, setInput] = useState('')
const [loading, setLoading] = useState(false) const [loading, setLoading] = useState(false)
@ -48,7 +48,7 @@ const Assistant = () => {
const { translate } = useLocalization() const { translate } = useLocalization()
const aiPosts = useStoreState((state) => state.base.messages.aiPosts) const aiPosts = useStoreState((state) => state.admin.messages.aiPosts)
useEffect(() => { useEffect(() => {
if (messages.length === 0 && aiPosts.length > 0) { if (messages.length === 0 && aiPosts.length > 0) {

View file

@ -2,7 +2,7 @@ import { useStoreActions } from '@/store'
import { useEffect } from 'react' import { useEffect } from 'react'
const LoadAiPostsFromLocalStorage = () => { const LoadAiPostsFromLocalStorage = () => {
const setAiPosts = useStoreActions((actions) => actions.base.messages.setAiPosts) const setAiPosts = useStoreActions((actions) => actions.admin.messages.setAiPosts)
useEffect(() => { useEffect(() => {
const saved = localStorage.getItem('AiPosts') const saved = localStorage.getItem('AiPosts')