init: initial commit

This commit is contained in:
Blizzard
2026-04-01 14:09:33 +08:00
commit aef2e152dc
66 changed files with 6540 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
package handler
import (
"context"
"AI-Expert-Sidebar/internal/service"
)
// SettingsHandler exposes AI settings CRUD via Wails bindings.
type SettingsHandler struct{ ctx context.Context }
func NewSettingsHandler() *SettingsHandler { return &SettingsHandler{} }
func (s *SettingsHandler) SetContext(ctx context.Context) { s.ctx = ctx }
// GetSettings returns the current local AI settings.
func (s *SettingsHandler) GetSettings() *service.SettingsDTO {
return service.GetSettings()
}
// SaveSettings persists AI config to local settings.db.
// Returns empty string on success, error message on failure.
func (s *SettingsHandler) SaveSettings(dto service.SettingsDTO) string {
if err := service.SaveSettings(dto); err != nil {
return err.Error()
}
return ""
}
// GetProviders returns built-in AI provider presets for the frontend dropdown.
func (s *SettingsHandler) GetProviders() []ProviderPreset {
return []ProviderPreset{
{ID: "deepseek", Label: "DeepSeek", BaseURL: "https://api.deepseek.com/chat/completions", DefaultModel: "deepseek-chat"},
{ID: "openai", Label: "OpenAI", BaseURL: "https://api.openai.com/v1/chat/completions", DefaultModel: "gpt-4o"},
{ID: "grok", Label: "Grok (xAI)", BaseURL: "https://api.x.ai/v1/chat/completions", DefaultModel: "grok-3"},
{ID: "custom", Label: "自定义", BaseURL: "", DefaultModel: ""},
}
}
// ProviderPreset describes a known AI provider with preset URL and model.
type ProviderPreset struct {
ID string `json:"id"`
Label string `json:"label"`
BaseURL string `json:"base_url"`
DefaultModel string `json:"default_model"`
}