80 lines
3.4 KiB
Go
80 lines
3.4 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
|
|
"AI-Expert-Sidebar/internal/config"
|
|
"AI-Expert-Sidebar/internal/database"
|
|
"AI-Expert-Sidebar/internal/handler"
|
|
"AI-Expert-Sidebar/internal/service"
|
|
)
|
|
|
|
type App struct {
|
|
ctx context.Context
|
|
expert *handler.Expert
|
|
settings *handler.SettingsHandler
|
|
library *handler.LibraryHandler
|
|
knowledge *handler.KnowledgeOps
|
|
}
|
|
|
|
func NewApp() *App {
|
|
return &App{
|
|
expert: handler.NewExpert(),
|
|
settings: handler.NewSettingsHandler(),
|
|
library: handler.NewLibraryHandler(),
|
|
knowledge: handler.NewKnowledgeOps(),
|
|
}
|
|
}
|
|
|
|
func (a *App) startup(ctx context.Context) {
|
|
a.ctx = ctx
|
|
a.expert.SetContext(ctx)
|
|
a.settings.SetContext(ctx)
|
|
a.library.SetContext(ctx)
|
|
a.knowledge.SetContext(ctx)
|
|
|
|
if err := config.Load(); err != nil {
|
|
log.Printf("[App] Config warning: %v", err)
|
|
}
|
|
if err := database.Init(); err != nil {
|
|
log.Printf("[App] DB warning: %v", err)
|
|
}
|
|
if err := service.InitLibraries(); err != nil {
|
|
log.Printf("[App] Library init warning: %v", err)
|
|
}
|
|
}
|
|
|
|
// ── Library ───────────────────────────────────────────────────────────────────
|
|
|
|
func (a *App) ListLibraries() []handler.LibraryInfo { return a.library.ListLibraries() }
|
|
func (a *App) GetActiveLibrary() string { return a.library.GetActiveLibrary() }
|
|
func (a *App) CreateLibrary(name, description string) string {
|
|
return a.library.CreateLibrary(name, description)
|
|
}
|
|
func (a *App) SwitchLibrary(name string) string { return a.library.SwitchLibrary(name) }
|
|
func (a *App) DeleteLibrary(name string) string { return a.library.DeleteLibrary(name) }
|
|
func (a *App) ImportCSV() service.ImportResult { return a.library.ImportCSV() }
|
|
func (a *App) ImportExcel() service.ImportResult { return a.library.ImportExcel() }
|
|
|
|
// ── Knowledge ops ─────────────────────────────────────────────────────────────
|
|
|
|
func (a *App) DeleteItems(ids []uint) string { return a.knowledge.DeleteItems(ids) }
|
|
func (a *App) ClearDatabase() string { return a.knowledge.ClearDatabase() }
|
|
|
|
// ── Settings ──────────────────────────────────────────────────────────────────
|
|
|
|
func (a *App) GetSettings() *service.SettingsDTO { return a.settings.GetSettings() }
|
|
func (a *App) SaveSettings(dto service.SettingsDTO) string { return a.settings.SaveSettings(dto) }
|
|
func (a *App) GetProviders() []handler.ProviderPreset { return a.settings.GetProviders() }
|
|
|
|
// ── Expert ────────────────────────────────────────────────────────────────────
|
|
|
|
func (a *App) SearchExpert(query string) interface{} { return a.expert.SearchExpert(query) }
|
|
func (a *App) AskDeepSeek(query, rawAnswer string) string {
|
|
return a.expert.AskDeepSeek(query, rawAnswer)
|
|
}
|
|
func (a *App) StopGeneration() { a.expert.StopGeneration() }
|
|
func (a *App) ToggleTopmost(enabled bool) { a.expert.ToggleTopmost(enabled) }
|
|
func (a *App) GetDBStatus() bool { return a.expert.GetDBStatus() }
|