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
+3
View File
@@ -0,0 +1,3 @@
build/bin
node_modules
frontend/dist
+10
View File
@@ -0,0 +1,10 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Ignored default folder with query files
/queries/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
+9
View File
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
+10
View File
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GoImports">
<option name="excludedPackages">
<array>
<option value="golang.org/x/net/context" />
</array>
</option>
</component>
</project>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/AI-Expert-Sidebar.iml" filepath="$PROJECT_DIR$/.idea/AI-Expert-Sidebar.iml" />
</modules>
</component>
</project>
+19
View File
@@ -0,0 +1,19 @@
# README
## About
This is the official Wails React-TS template.
You can configure the project by editing `wails.json`. More information about the project settings can be found
here: https://wails.io/docs/reference/project-config
## Live Development
To run in live development mode, run `wails dev` in the project directory. This will run a Vite development
server that will provide very fast hot reload of your frontend changes. If you want to develop in a browser
and have access to your Go methods, there is also a dev server that runs on http://localhost:34115. Connect
to this in your browser, and you can call your Go code from devtools.
## Building
To build a redistributable, production mode package, use `wails build`.
+94
View File
@@ -0,0 +1,94 @@
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
}
func NewApp() *App {
return &App{
expert: handler.NewExpert(),
settings: handler.NewSettingsHandler(),
library: handler.NewLibraryHandler(),
}
}
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
a.expert.SetContext(ctx)
a.settings.SetContext(ctx)
a.library.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 init 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()
}
// ── 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()
}
+35
View File
@@ -0,0 +1,35 @@
# Build Directory
The build directory is used to house all the build files and assets for your application.
The structure is:
* bin - Output directory
* darwin - macOS specific files
* windows - Windows specific files
## Mac
The `darwin` directory holds files specific to Mac builds.
These may be customised and used as part of the build. To return these files to the default state, simply delete them
and
build with `wails build`.
The directory contains the following files:
- `Info.plist` - the main plist file used for Mac builds. It is used when building using `wails build`.
- `Info.dev.plist` - same as the main plist file but used when building using `wails dev`.
## Windows
The `windows` directory contains the manifest and rc files used when building with `wails build`.
These may be customised for your application. To return these files to the default state, simply delete them and
build with `wails build`.
- `icon.ico` - The icon used for the application. This is used when building using `wails build`. If you wish to
use a different icon, simply replace this file with your own. If it is missing, a new `icon.ico` file
will be created using the `appicon.png` file in the build directory.
- `installer/*` - The files used to create the Windows installer. These are used when building using `wails build`.
- `info.json` - Application details used for Windows builds. The data here will be used by the Windows installer,
as well as the application itself (right click the exe -> properties -> details)
- `wails.exe.manifest` - The main application manifest file.
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

+68
View File
@@ -0,0 +1,68 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleName</key>
<string>{{.Info.ProductName}}</string>
<key>CFBundleExecutable</key>
<string>{{.OutputFilename}}</string>
<key>CFBundleIdentifier</key>
<string>com.wails.{{.Name}}</string>
<key>CFBundleVersion</key>
<string>{{.Info.ProductVersion}}</string>
<key>CFBundleGetInfoString</key>
<string>{{.Info.Comments}}</string>
<key>CFBundleShortVersionString</key>
<string>{{.Info.ProductVersion}}</string>
<key>CFBundleIconFile</key>
<string>iconfile</string>
<key>LSMinimumSystemVersion</key>
<string>10.13.0</string>
<key>NSHighResolutionCapable</key>
<string>true</string>
<key>NSHumanReadableCopyright</key>
<string>{{.Info.Copyright}}</string>
{{if .Info.FileAssociations}}
<key>CFBundleDocumentTypes</key>
<array>
{{range .Info.FileAssociations}}
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>{{.Ext}}</string>
</array>
<key>CFBundleTypeName</key>
<string>{{.Name}}</string>
<key>CFBundleTypeRole</key>
<string>{{.Role}}</string>
<key>CFBundleTypeIconFile</key>
<string>{{.IconName}}</string>
</dict>
{{end}}
</array>
{{end}}
{{if .Info.Protocols}}
<key>CFBundleURLTypes</key>
<array>
{{range .Info.Protocols}}
<dict>
<key>CFBundleURLName</key>
<string>com.wails.{{.Scheme}}</string>
<key>CFBundleURLSchemes</key>
<array>
<string>{{.Scheme}}</string>
</array>
<key>CFBundleTypeRole</key>
<string>{{.Role}}</string>
</dict>
{{end}}
</array>
{{end}}
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsLocalNetworking</key>
<true/>
</dict>
</dict>
</plist>
+63
View File
@@ -0,0 +1,63 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleName</key>
<string>{{.Info.ProductName}}</string>
<key>CFBundleExecutable</key>
<string>{{.OutputFilename}}</string>
<key>CFBundleIdentifier</key>
<string>com.wails.{{.Name}}</string>
<key>CFBundleVersion</key>
<string>{{.Info.ProductVersion}}</string>
<key>CFBundleGetInfoString</key>
<string>{{.Info.Comments}}</string>
<key>CFBundleShortVersionString</key>
<string>{{.Info.ProductVersion}}</string>
<key>CFBundleIconFile</key>
<string>iconfile</string>
<key>LSMinimumSystemVersion</key>
<string>10.13.0</string>
<key>NSHighResolutionCapable</key>
<string>true</string>
<key>NSHumanReadableCopyright</key>
<string>{{.Info.Copyright}}</string>
{{if .Info.FileAssociations}}
<key>CFBundleDocumentTypes</key>
<array>
{{range .Info.FileAssociations}}
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>{{.Ext}}</string>
</array>
<key>CFBundleTypeName</key>
<string>{{.Name}}</string>
<key>CFBundleTypeRole</key>
<string>{{.Role}}</string>
<key>CFBundleTypeIconFile</key>
<string>{{.IconName}}</string>
</dict>
{{end}}
</array>
{{end}}
{{if .Info.Protocols}}
<key>CFBundleURLTypes</key>
<array>
{{range .Info.Protocols}}
<dict>
<key>CFBundleURLName</key>
<string>com.wails.{{.Scheme}}</string>
<key>CFBundleURLSchemes</key>
<array>
<string>{{.Scheme}}</string>
</array>
<key>CFBundleTypeRole</key>
<string>{{.Role}}</string>
</dict>
{{end}}
</array>
{{end}}
</dict>
</plist>
Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

+15
View File
@@ -0,0 +1,15 @@
{
"fixed": {
"file_version": "{{.Info.ProductVersion}}"
},
"info": {
"0000": {
"ProductVersion": "{{.Info.ProductVersion}}",
"CompanyName": "{{.Info.CompanyName}}",
"FileDescription": "{{.Info.ProductName}}",
"LegalCopyright": "{{.Info.Copyright}}",
"ProductName": "{{.Info.ProductName}}",
"Comments": "{{.Info.Comments}}"
}
}
}
+114
View File
@@ -0,0 +1,114 @@
Unicode true
####
## Please note: Template replacements don't work in this file. They are provided with default defines like
## mentioned underneath.
## If the keyword is not defined, "wails_tools.nsh" will populate them with the values from ProjectInfo.
## If they are defined here, "wails_tools.nsh" will not touch them. This allows to use this project.nsi manually
## from outside of Wails for debugging and development of the installer.
##
## For development first make a wails nsis build to populate the "wails_tools.nsh":
## > wails build --target windows/amd64 --nsis
## Then you can call makensis on this file with specifying the path to your binary:
## For a AMD64 only installer:
## > makensis -DARG_WAILS_AMD64_BINARY=..\..\bin\app.exe
## For a ARM64 only installer:
## > makensis -DARG_WAILS_ARM64_BINARY=..\..\bin\app.exe
## For a installer with both architectures:
## > makensis -DARG_WAILS_AMD64_BINARY=..\..\bin\app-amd64.exe -DARG_WAILS_ARM64_BINARY=..\..\bin\app-arm64.exe
####
## The following information is taken from the ProjectInfo file, but they can be overwritten here.
####
## !define INFO_PROJECTNAME "MyProject" # Default "{{.Name}}"
## !define INFO_COMPANYNAME "MyCompany" # Default "{{.Info.CompanyName}}"
## !define INFO_PRODUCTNAME "MyProduct" # Default "{{.Info.ProductName}}"
## !define INFO_PRODUCTVERSION "1.0.0" # Default "{{.Info.ProductVersion}}"
## !define INFO_COPYRIGHT "Copyright" # Default "{{.Info.Copyright}}"
###
## !define PRODUCT_EXECUTABLE "Application.exe" # Default "${INFO_PROJECTNAME}.exe"
## !define UNINST_KEY_NAME "UninstKeyInRegistry" # Default "${INFO_COMPANYNAME}${INFO_PRODUCTNAME}"
####
## !define REQUEST_EXECUTION_LEVEL "admin" # Default "admin" see also https://nsis.sourceforge.io/Docs/Chapter4.html
####
## Include the wails tools
####
!include "wails_tools.nsh"
# The version information for this two must consist of 4 parts
VIProductVersion "${INFO_PRODUCTVERSION}.0"
VIFileVersion "${INFO_PRODUCTVERSION}.0"
VIAddVersionKey "CompanyName" "${INFO_COMPANYNAME}"
VIAddVersionKey "FileDescription" "${INFO_PRODUCTNAME} Installer"
VIAddVersionKey "ProductVersion" "${INFO_PRODUCTVERSION}"
VIAddVersionKey "FileVersion" "${INFO_PRODUCTVERSION}"
VIAddVersionKey "LegalCopyright" "${INFO_COPYRIGHT}"
VIAddVersionKey "ProductName" "${INFO_PRODUCTNAME}"
# Enable HiDPI support. https://nsis.sourceforge.io/Reference/ManifestDPIAware
ManifestDPIAware true
!include "MUI.nsh"
!define MUI_ICON "..\icon.ico"
!define MUI_UNICON "..\icon.ico"
# !define MUI_WELCOMEFINISHPAGE_BITMAP "resources\leftimage.bmp" #Include this to add a bitmap on the left side of the Welcome Page. Must be a size of 164x314
!define MUI_FINISHPAGE_NOAUTOCLOSE # Wait on the INSTFILES page so the user can take a look into the details of the installation steps
!define MUI_ABORTWARNING # This will warn the user if they exit from the installer.
!insertmacro MUI_PAGE_WELCOME # Welcome to the installer page.
# !insertmacro MUI_PAGE_LICENSE "resources\eula.txt" # Adds a EULA page to the installer
!insertmacro MUI_PAGE_DIRECTORY # In which folder install page.
!insertmacro MUI_PAGE_INSTFILES # Installing page.
!insertmacro MUI_PAGE_FINISH # Finished installation page.
!insertmacro MUI_UNPAGE_INSTFILES # Uinstalling page
!insertmacro MUI_LANGUAGE "English" # Set the Language of the installer
## The following two statements can be used to sign the installer and the uninstaller. The path to the binaries are provided in %1
#!uninstfinalize 'signtool --file "%1"'
#!finalize 'signtool --file "%1"'
Name "${INFO_PRODUCTNAME}"
OutFile "..\..\bin\${INFO_PROJECTNAME}-${ARCH}-installer.exe" # Name of the installer's file.
InstallDir "$PROGRAMFILES64\${INFO_COMPANYNAME}\${INFO_PRODUCTNAME}" # Default installing folder ($PROGRAMFILES is Program Files folder).
ShowInstDetails show # This will always show the installation details.
Function .onInit
!insertmacro wails.checkArchitecture
FunctionEnd
Section
!insertmacro wails.setShellContext
!insertmacro wails.webview2runtime
SetOutPath $INSTDIR
!insertmacro wails.files
CreateShortcut "$SMPROGRAMS\${INFO_PRODUCTNAME}.lnk" "$INSTDIR\${PRODUCT_EXECUTABLE}"
CreateShortCut "$DESKTOP\${INFO_PRODUCTNAME}.lnk" "$INSTDIR\${PRODUCT_EXECUTABLE}"
!insertmacro wails.associateFiles
!insertmacro wails.associateCustomProtocols
!insertmacro wails.writeUninstaller
SectionEnd
Section "uninstall"
!insertmacro wails.setShellContext
RMDir /r "$AppData\${PRODUCT_EXECUTABLE}" # Remove the WebView2 DataPath
RMDir /r $INSTDIR
Delete "$SMPROGRAMS\${INFO_PRODUCTNAME}.lnk"
Delete "$DESKTOP\${INFO_PRODUCTNAME}.lnk"
!insertmacro wails.unassociateFiles
!insertmacro wails.unassociateCustomProtocols
!insertmacro wails.deleteUninstaller
SectionEnd
+249
View File
@@ -0,0 +1,249 @@
# DO NOT EDIT - Generated automatically by `wails build`
!include "x64.nsh"
!include "WinVer.nsh"
!include "FileFunc.nsh"
!ifndef INFO_PROJECTNAME
!define INFO_PROJECTNAME "{{.Name}}"
!endif
!ifndef INFO_COMPANYNAME
!define INFO_COMPANYNAME "{{.Info.CompanyName}}"
!endif
!ifndef INFO_PRODUCTNAME
!define INFO_PRODUCTNAME "{{.Info.ProductName}}"
!endif
!ifndef INFO_PRODUCTVERSION
!define INFO_PRODUCTVERSION "{{.Info.ProductVersion}}"
!endif
!ifndef INFO_COPYRIGHT
!define INFO_COPYRIGHT "{{.Info.Copyright}}"
!endif
!ifndef PRODUCT_EXECUTABLE
!define PRODUCT_EXECUTABLE "${INFO_PROJECTNAME}.exe"
!endif
!ifndef UNINST_KEY_NAME
!define UNINST_KEY_NAME "${INFO_COMPANYNAME}${INFO_PRODUCTNAME}"
!endif
!define UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${UNINST_KEY_NAME}"
!ifndef REQUEST_EXECUTION_LEVEL
!define REQUEST_EXECUTION_LEVEL "admin"
!endif
RequestExecutionLevel "${REQUEST_EXECUTION_LEVEL}"
!ifdef ARG_WAILS_AMD64_BINARY
!define SUPPORTS_AMD64
!endif
!ifdef ARG_WAILS_ARM64_BINARY
!define SUPPORTS_ARM64
!endif
!ifdef SUPPORTS_AMD64
!ifdef SUPPORTS_ARM64
!define ARCH "amd64_arm64"
!else
!define ARCH "amd64"
!endif
!else
!ifdef SUPPORTS_ARM64
!define ARCH "arm64"
!else
!error "Wails: Undefined ARCH, please provide at least one of ARG_WAILS_AMD64_BINARY or ARG_WAILS_ARM64_BINARY"
!endif
!endif
!macro wails.checkArchitecture
!ifndef WAILS_WIN10_REQUIRED
!define WAILS_WIN10_REQUIRED "This product is only supported on Windows 10 (Server 2016) and later."
!endif
!ifndef WAILS_ARCHITECTURE_NOT_SUPPORTED
!define WAILS_ARCHITECTURE_NOT_SUPPORTED "This product can't be installed on the current Windows architecture. Supports: ${ARCH}"
!endif
${If} ${AtLeastWin10}
!ifdef SUPPORTS_AMD64
${if} ${IsNativeAMD64}
Goto ok
${EndIf}
!endif
!ifdef SUPPORTS_ARM64
${if} ${IsNativeARM64}
Goto ok
${EndIf}
!endif
IfSilent silentArch notSilentArch
silentArch:
SetErrorLevel 65
Abort
notSilentArch:
MessageBox MB_OK "${WAILS_ARCHITECTURE_NOT_SUPPORTED}"
Quit
${else}
IfSilent silentWin notSilentWin
silentWin:
SetErrorLevel 64
Abort
notSilentWin:
MessageBox MB_OK "${WAILS_WIN10_REQUIRED}"
Quit
${EndIf}
ok:
!macroend
!macro wails.files
!ifdef SUPPORTS_AMD64
${if} ${IsNativeAMD64}
File "/oname=${PRODUCT_EXECUTABLE}" "${ARG_WAILS_AMD64_BINARY}"
${EndIf}
!endif
!ifdef SUPPORTS_ARM64
${if} ${IsNativeARM64}
File "/oname=${PRODUCT_EXECUTABLE}" "${ARG_WAILS_ARM64_BINARY}"
${EndIf}
!endif
!macroend
!macro wails.writeUninstaller
WriteUninstaller "$INSTDIR\uninstall.exe"
SetRegView 64
WriteRegStr HKLM "${UNINST_KEY}" "Publisher" "${INFO_COMPANYNAME}"
WriteRegStr HKLM "${UNINST_KEY}" "DisplayName" "${INFO_PRODUCTNAME}"
WriteRegStr HKLM "${UNINST_KEY}" "DisplayVersion" "${INFO_PRODUCTVERSION}"
WriteRegStr HKLM "${UNINST_KEY}" "DisplayIcon" "$INSTDIR\${PRODUCT_EXECUTABLE}"
WriteRegStr HKLM "${UNINST_KEY}" "UninstallString" "$\"$INSTDIR\uninstall.exe$\""
WriteRegStr HKLM "${UNINST_KEY}" "QuietUninstallString" "$\"$INSTDIR\uninstall.exe$\" /S"
${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
IntFmt $0 "0x%08X" $0
WriteRegDWORD HKLM "${UNINST_KEY}" "EstimatedSize" "$0"
!macroend
!macro wails.deleteUninstaller
Delete "$INSTDIR\uninstall.exe"
SetRegView 64
DeleteRegKey HKLM "${UNINST_KEY}"
!macroend
!macro wails.setShellContext
${If} ${REQUEST_EXECUTION_LEVEL} == "admin"
SetShellVarContext all
${else}
SetShellVarContext current
${EndIf}
!macroend
# Install webview2 by launching the bootstrapper
# See https://docs.microsoft.com/en-us/microsoft-edge/webview2/concepts/distribution#online-only-deployment
!macro wails.webview2runtime
!ifndef WAILS_INSTALL_WEBVIEW_DETAILPRINT
!define WAILS_INSTALL_WEBVIEW_DETAILPRINT "Installing: WebView2 Runtime"
!endif
SetRegView 64
# If the admin key exists and is not empty then webview2 is already installed
ReadRegStr $0 HKLM "SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" "pv"
${If} $0 != ""
Goto ok
${EndIf}
${If} ${REQUEST_EXECUTION_LEVEL} == "user"
# If the installer is run in user level, check the user specific key exists and is not empty then webview2 is already installed
ReadRegStr $0 HKCU "Software\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" "pv"
${If} $0 != ""
Goto ok
${EndIf}
${EndIf}
SetDetailsPrint both
DetailPrint "${WAILS_INSTALL_WEBVIEW_DETAILPRINT}"
SetDetailsPrint listonly
InitPluginsDir
CreateDirectory "$pluginsdir\webview2bootstrapper"
SetOutPath "$pluginsdir\webview2bootstrapper"
File "tmp\MicrosoftEdgeWebview2Setup.exe"
ExecWait '"$pluginsdir\webview2bootstrapper\MicrosoftEdgeWebview2Setup.exe" /silent /install'
SetDetailsPrint both
ok:
!macroend
# Copy of APP_ASSOCIATE and APP_UNASSOCIATE macros from here https://gist.github.com/nikku/281d0ef126dbc215dd58bfd5b3a5cd5b
!macro APP_ASSOCIATE EXT FILECLASS DESCRIPTION ICON COMMANDTEXT COMMAND
; Backup the previously associated file class
ReadRegStr $R0 SHELL_CONTEXT "Software\Classes\.${EXT}" ""
WriteRegStr SHELL_CONTEXT "Software\Classes\.${EXT}" "${FILECLASS}_backup" "$R0"
WriteRegStr SHELL_CONTEXT "Software\Classes\.${EXT}" "" "${FILECLASS}"
WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}" "" `${DESCRIPTION}`
WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}\DefaultIcon" "" `${ICON}`
WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}\shell" "" "open"
WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}\shell\open" "" `${COMMANDTEXT}`
WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}\shell\open\command" "" `${COMMAND}`
!macroend
!macro APP_UNASSOCIATE EXT FILECLASS
; Backup the previously associated file class
ReadRegStr $R0 SHELL_CONTEXT "Software\Classes\.${EXT}" `${FILECLASS}_backup`
WriteRegStr SHELL_CONTEXT "Software\Classes\.${EXT}" "" "$R0"
DeleteRegKey SHELL_CONTEXT `Software\Classes\${FILECLASS}`
!macroend
!macro wails.associateFiles
; Create file associations
{{range .Info.FileAssociations}}
!insertmacro APP_ASSOCIATE "{{.Ext}}" "{{.Name}}" "{{.Description}}" "$INSTDIR\{{.IconName}}.ico" "Open with ${INFO_PRODUCTNAME}" "$INSTDIR\${PRODUCT_EXECUTABLE} $\"%1$\""
File "..\{{.IconName}}.ico"
{{end}}
!macroend
!macro wails.unassociateFiles
; Delete app associations
{{range .Info.FileAssociations}}
!insertmacro APP_UNASSOCIATE "{{.Ext}}" "{{.Name}}"
Delete "$INSTDIR\{{.IconName}}.ico"
{{end}}
!macroend
!macro CUSTOM_PROTOCOL_ASSOCIATE PROTOCOL DESCRIPTION ICON COMMAND
DeleteRegKey SHELL_CONTEXT "Software\Classes\${PROTOCOL}"
WriteRegStr SHELL_CONTEXT "Software\Classes\${PROTOCOL}" "" "${DESCRIPTION}"
WriteRegStr SHELL_CONTEXT "Software\Classes\${PROTOCOL}" "URL Protocol" ""
WriteRegStr SHELL_CONTEXT "Software\Classes\${PROTOCOL}\DefaultIcon" "" "${ICON}"
WriteRegStr SHELL_CONTEXT "Software\Classes\${PROTOCOL}\shell" "" ""
WriteRegStr SHELL_CONTEXT "Software\Classes\${PROTOCOL}\shell\open" "" ""
WriteRegStr SHELL_CONTEXT "Software\Classes\${PROTOCOL}\shell\open\command" "" "${COMMAND}"
!macroend
!macro CUSTOM_PROTOCOL_UNASSOCIATE PROTOCOL
DeleteRegKey SHELL_CONTEXT "Software\Classes\${PROTOCOL}"
!macroend
!macro wails.associateCustomProtocols
; Create custom protocols associations
{{range .Info.Protocols}}
!insertmacro CUSTOM_PROTOCOL_ASSOCIATE "{{.Scheme}}" "{{.Description}}" "$INSTDIR\${PRODUCT_EXECUTABLE},0" "$INSTDIR\${PRODUCT_EXECUTABLE} $\"%1$\""
{{end}}
!macroend
!macro wails.unassociateCustomProtocols
; Delete app custom protocol associations
{{range .Info.Protocols}}
!insertmacro CUSTOM_PROTOCOL_UNASSOCIATE "{{.Scheme}}"
{{end}}
!macroend
+15
View File
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<assemblyIdentity type="win32" name="com.wails.{{.Name}}" version="{{.Info.ProductVersion}}.0" processorArchitecture="*"/>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
</dependentAssembly>
</dependency>
<asmv3:application>
<asmv3:windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware> <!-- fallback for Windows 7 and 8 -->
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">permonitorv2,permonitor</dpiAwareness> <!-- falls back to per-monitor if per-monitor v2 is not supported -->
</asmv3:windowsSettings>
</asmv3:application>
</assembly>
+11
View File
@@ -0,0 +1,11 @@
database:
dsn: "root:root@tcp(129.28.103.17:3413)/sundynix_ai_expert_sidebar?charset=utf8mb4&parseTime=True&loc=Local"
deepseek:
api_key: "sk-e43c6678af654f329ab508c4707c9778"
model: "deepseek-chat" # or "deepseek-reasoner" for R1
timeout_seconds: 60
max_tokens: 1024
app:
debug: true
+14
View File
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
<title>AI Expert Sidebar — 智能客服助手</title>
<meta name="description" content="AI Expert Sidebar:轻量级桌面客服辅助工具,知识库搜索 + AI 话术润色"/>
</head>
<body>
<div id="root"></div>
<script src="./src/main.tsx" type="module"></script>
</body>
</html>
+2287
View File
File diff suppressed because it is too large Load Diff
+25
View File
@@ -0,0 +1,25 @@
{
"name": "frontend",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.0.17",
"@types/react-dom": "^18.0.6",
"@vitejs/plugin-react": "^2.0.1",
"autoprefixer": "^10.4.27",
"postcss": "^8.5.8",
"tailwindcss": "^3.4.19",
"typescript": "^4.6.4",
"vite": "^3.0.7"
}
}
+1
View File
@@ -0,0 +1 @@
603a1d85b868dec3cb564be2820cbd39
+6
View File
@@ -0,0 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
+59
View File
@@ -0,0 +1,59 @@
#app {
height: 100vh;
text-align: center;
}
#logo {
display: block;
width: 50%;
height: 50%;
margin: auto;
padding: 10% 0 0;
background-position: center;
background-repeat: no-repeat;
background-size: 100% 100%;
background-origin: content-box;
}
.result {
height: 20px;
line-height: 20px;
margin: 1.5rem auto;
}
.input-box .btn {
width: 60px;
height: 30px;
line-height: 30px;
border-radius: 3px;
border: none;
margin: 0 0 0 20px;
padding: 0 8px;
cursor: pointer;
}
.input-box .btn:hover {
background-image: linear-gradient(to top, #cfd9df 0%, #e2ebf0 100%);
color: #333333;
}
.input-box .input {
border: none;
border-radius: 3px;
outline: none;
height: 30px;
line-height: 30px;
padding: 0 10px;
background-color: rgba(240, 240, 240, 1);
-webkit-font-smoothing: antialiased;
}
.input-box .input:hover {
border: none;
background-color: rgba(255, 255, 255, 1);
}
.input-box .input:focus {
border: none;
background-color: rgba(255, 255, 255, 1);
}
+116
View File
@@ -0,0 +1,116 @@
import { useCallback, useEffect, useRef, useState } from 'react';
import { AskDeepSeek, GetActiveLibrary, GetDBStatus, StopGeneration } from 'wailsjs/go/main/App';
import { EventsOn } from 'wailsjs/runtime/runtime';
import TitleBar from './components/TitleBar';
import LibraryBar from './components/LibraryBar';
import SearchInput from './components/SearchInput';
import ResultCard from './components/ResultCard';
import AIPanel from './components/AIPanel';
import SettingsModal from './components/SettingsModal';
import { useSearch, type SearchResult } from './hooks/useSearch';
export default function App() {
const [dbReady, setDbReady] = useState(false);
const [activeLib, setActiveLib] = useState('');
const [showSettings, setShowSettings] = useState(false);
const [aiText, setAiText] = useState('');
const [aiLoading, setAiLoading] = useState(false);
const [aiError, setAiError] = useState<string | null>(null);
const [aiTarget, setAiTarget] = useState<SearchResult | null>(null);
const [isFallback, setIsFallback] = useState(false);
const aiTextRef = useRef('');
const { query, setQuery, results, loading, error } = useSearch();
useEffect(() => {
const check = async () => {
try { setDbReady(await GetDBStatus()); } catch { setDbReady(false); }
};
const loadLib = async () => { setActiveLib(await GetActiveLibrary()); };
check(); loadLib();
const id = setInterval(check, 5000);
return () => clearInterval(id);
}, []);
useEffect(() => {
const offChunk = EventsOn('ai:chunk', (c: string) => { aiTextRef.current += c; setAiText(aiTextRef.current); });
const offDone = EventsOn('ai:done', () => setAiLoading(false));
const offFallback = EventsOn('ai:fallback', (raw: string) => { setIsFallback(true); aiTextRef.current = raw; setAiText(raw); setAiLoading(false); });
const offErr = EventsOn('ai:error', (m: string) => { setAiError(m); setAiLoading(false); });
return () => { offChunk(); offDone(); offFallback(); offErr(); };
}, []);
const handleAsk = useCallback(async (result: SearchResult) => {
setAiTarget(result); setAiText(''); setAiError(null); setIsFallback(false);
setAiLoading(true); aiTextRef.current = '';
try { await AskDeepSeek(result.question, result.answer); }
catch { setAiError('DeepSeek 连接失败'); setAiLoading(false); }
}, []);
const handleStop = useCallback(async () => { await StopGeneration(); }, []);
const handleCopyAI = useCallback(async (text: string) => {
try { await navigator.clipboard.writeText(text); }
catch {
const el = document.createElement('textarea'); el.value = text;
document.body.appendChild(el); el.select(); document.execCommand('copy');
document.body.removeChild(el);
}
}, []);
const closeAI = useCallback(() => {
handleStop(); setAiTarget(null); setAiText(''); setAiError(null); setIsFallback(false);
}, [handleStop]);
return (
<div className="sidebar-root">
<div className="orb orb-purple" /><div className="orb orb-blue" />
<div className="relative z-10 flex flex-col h-full">
<TitleBar dbReady={dbReady} onSettings={() => setShowSettings(true)} />
<LibraryBar activeName={activeLib} onSwitch={name => { setActiveLib(name); setQuery(''); }} />
<SearchInput value={query} onChange={setQuery} loading={loading} />
{error && (
<div className="mx-4 mb-2 px-3 py-2 rounded-lg bg-red-500/10 border border-red-500/25 text-red-400 text-[11px] flex items-center gap-2">
<span></span><span>{error}</span>
</div>
)}
<div className="flex-1 overflow-y-auto results-scroll px-4 pb-2 flex flex-col gap-2">
{!loading && results.length === 0 && query.trim() && (
<div className="flex flex-col items-center justify-center h-36 gap-3">
<span className="text-3xl">🔍</span>
<p className="text-[12px] text-white/30"></p>
<button id="btn-ask-direct" onClick={() => handleAsk({ id: 0, question: query, answer: '', category: '', score: 0, is_fallback: false })}
className="flex items-center gap-2 px-4 py-2 rounded-xl bg-accent/20 text-accent-light
border border-accent/30 hover:bg-accent/35 transition-all text-[12px] font-medium">
DeepSeek
</button>
</div>
)}
{!query.trim() && !loading && (
<div className="flex flex-col items-center justify-center h-32 text-white/25">
<span className="text-3xl mb-2">💬</span>
<p className="text-[12px]"></p>
</div>
)}
{!loading && results.length > 0 && results[0].is_fallback && (
<div className="px-3 py-2 rounded-lg bg-white/5 border border-white/8 text-white/35 text-[10px] flex items-center gap-2">
<span>💡</span><span></span>
</div>
)}
{results.map(r => <ResultCard key={r.id} result={r} onPolish={handleAsk} />)}
</div>
{aiTarget && (
<AIPanel text={aiText} loading={aiLoading} error={aiError}
isFallback={isFallback} question={aiTarget.question}
onCopy={handleCopyAI} onStop={handleStop} onClose={closeAI} />
)}
</div>
{showSettings && <SettingsModal onClose={() => setShowSettings(false)} />}
</div>
);
}
+93
View File
@@ -0,0 +1,93 @@
Copyright 2016 The Nunito Project Authors (contact@sansoxygen.com),
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
Binary file not shown.

After

Width:  |  Height:  |  Size: 136 KiB

+136
View File
@@ -0,0 +1,136 @@
import { useState } from 'react';
interface AIPanelProps {
text: string;
loading: boolean;
error: string | null;
isFallback: boolean;
question: string;
onCopy: (text: string) => void;
onStop: () => void;
onClose: () => void;
}
export default function AIPanel({
text, loading, error, isFallback, question, onCopy, onStop, onClose,
}: AIPanelProps) {
const [copied, setCopied] = useState(false);
const handleCopy = () => {
onCopy(text);
setCopied(true);
setTimeout(() => setCopied(false), 1000);
};
return (
<div className="flex-shrink-0 px-4 pb-4 animate-fade-in">
{/* Header */}
<div className="flex items-center justify-between mb-2">
<div className="flex items-center gap-1.5">
<span className="text-sm"></span>
<span className="text-[12px] font-semibold text-accent-light">
DeepSeek RAG
</span>
{/* Animated loading dots */}
{loading && (
<div className="flex gap-1 ml-1">
{[0, 1, 2].map(i => (
<span
key={i}
className="w-1 h-1 rounded-full bg-accent-light"
style={{ animation: `pulseDot 1.4s ease-in-out ${i * 0.2}s infinite` }}
/>
))}
</div>
)}
{/* Fallback badge */}
{isFallback && !loading && (
<span className="text-[9px] px-1.5 py-0.5 rounded-full bg-amber-500/20 text-amber-400 border border-amber-500/30 ml-1">
</span>
)}
</div>
<div className="flex items-center gap-1">
{/* Stop button — only visible while streaming */}
{loading && (
<button
id="btn-ai-stop"
onClick={onStop}
title="停止生成"
className="flex items-center gap-1 text-[10px] px-2 py-1 rounded-md
bg-red-500/15 text-red-400 border border-red-500/25
hover:bg-red-500/25 transition-all"
>
<span></span>
</button>
)}
<button
id="btn-ai-close"
onClick={onClose}
className="text-white/30 hover:text-white/70 text-xs transition-colors ml-1"
>
</button>
</div>
</div>
{/* Question context */}
{question && (
<p className="text-[10px] text-white/35 mb-2 line-clamp-1">
{question}
</p>
)}
{/* Fallback notice */}
{isFallback && (
<div className="mb-2 px-2 py-1.5 rounded-lg bg-amber-500/10 border border-amber-500/20
text-amber-400 text-[10px] flex items-center gap-1.5">
<span></span>
<span>DeepSeek </span>
</div>
)}
{/* Error state */}
{error && !isFallback ? (
<div className="ai-panel border-red-500/30 bg-red-500/5">
<p className="text-red-400 text-[12px] font-medium mb-1"> AI </p>
<p className="text-white/50 text-[11px]">{error}</p>
<p className="text-white/30 text-[11px] mt-2">使</p>
</div>
) : (
/* Content panel with typewriter effect */
<div className={`ai-panel ${isFallback ? 'border-amber-500/20 bg-amber-500/5' : ''}`}>
{loading && !text ? (
<p className="text-white/30 text-[12px] animate-pulse">
DeepSeek
</p>
) : (
<p className="text-[13px] leading-relaxed whitespace-pre-wrap">
{text}
{/* Blinking cursor while streaming */}
{loading && (
<span className="inline-block w-0.5 h-3.5 bg-accent ml-0.5 align-middle"
style={{ animation: 'pulseDot 0.8s ease-in-out infinite' }} />
)}
</p>
)}
</div>
)}
{/* Copy button */}
{text && !error && (
<button
id="btn-ai-copy"
onClick={handleCopy}
className="mt-2 w-full text-[11px] py-2 rounded-lg bg-accent/20 text-accent-light
border border-accent/30 hover:bg-accent/35 transition-all font-medium"
>
{copied ? '✓ 已复制' : '📋 复制此话术'}
</button>
)}
</div>
);
}
+124
View File
@@ -0,0 +1,124 @@
import { useEffect, useRef, useState } from 'react';
import { CreateLibrary, DeleteLibrary, ImportCSV, ListLibraries, SwitchLibrary } from 'wailsjs/go/main/App';
import type { handler } from 'wailsjs/go/models';
interface LibraryBarProps {
activeName: string;
onSwitch: (name: string) => void;
}
export default function LibraryBar({ activeName, onSwitch }: LibraryBarProps) {
const [open, setOpen] = useState(false);
const [libs, setLibs] = useState<handler.LibraryInfo[]>([]);
const [creating, setCreating] = useState(false);
const [newName, setNewName] = useState('');
const [importing, setImporting] = useState(false);
const [msg, setMsg] = useState('');
const ref = useRef<HTMLDivElement>(null);
const load = async () => { setLibs(await ListLibraries()); };
useEffect(() => {
if (open) load();
}, [open]);
// Close on outside click
useEffect(() => {
const handler = (e: MouseEvent) => {
if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false);
};
document.addEventListener('mousedown', handler);
return () => document.removeEventListener('mousedown', handler);
}, []);
const handleSwitch = async (name: string) => {
await SwitchLibrary(name);
onSwitch(name);
setOpen(false);
};
const handleCreate = async () => {
if (!newName.trim()) return;
const err = await CreateLibrary(newName.trim(), '');
if (!err) { onSwitch(newName.trim()); setNewName(''); setCreating(false); load(); }
else setMsg(err);
};
const handleImport = async () => {
setImporting(true); setMsg('');
const result = await ImportCSV();
setImporting(false);
if (result.error && result.error !== '已取消') setMsg(result.error);
else if (result.imported > 0) { setMsg(`✓ 导入了 ${result.imported} 条(跳过 ${result.skipped} 条)`); load(); }
setTimeout(() => setMsg(''), 4000);
};
return (
<div ref={ref} className="relative px-4 pb-2">
{/* Button row */}
<div className="flex items-center gap-2">
<button onClick={() => setOpen(o => !o)}
className="flex-1 flex items-center gap-2 px-3 py-1.5 rounded-xl
bg-white/5 hover:bg-white/10 border border-white/8 transition-all text-left">
<span className="text-sm">📚</span>
<span className="text-[12px] text-white/80 truncate flex-1">{activeName || '选择知识库'}</span>
<span className="text-[10px] text-white/30">{open ? '▲' : '▾'}</span>
</button>
<button onClick={handleImport} disabled={importing} title="导入 CSV"
className="px-2.5 py-1.5 rounded-xl bg-accent/15 text-accent-light border border-accent/25
hover:bg-accent/25 transition-all text-[11px] font-medium disabled:opacity-50">
{importing ? '…' : '📥 导入'}
</button>
</div>
{msg && <p className={`text-[10px] mt-1 ${msg.startsWith('✓') ? 'text-green-400' : 'text-red-400'}`}>{msg}</p>}
{/* Dropdown */}
{open && (
<div className="absolute left-4 right-4 top-full mt-1 z-40
bg-[rgba(12,10,24,0.98)] border border-white/10 rounded-xl
shadow-2xl overflow-hidden animate-fade-in">
<div className="max-h-48 overflow-y-auto results-scroll">
{libs.map(lib => (
<div key={lib.id}
className={`flex items-center gap-2 px-3 py-2.5 cursor-pointer transition-colors
${lib.is_active ? 'bg-accent/15 border-l-2 border-accent' : 'hover:bg-white/5'}`}
onClick={() => handleSwitch(lib.name)}>
<span className="text-sm">{lib.is_active ? '✅' : '📁'}</span>
<div className="flex-1 min-w-0">
<p className="text-[12px] text-white/85 truncate">{lib.name}</p>
<p className="text-[10px] text-white/35">{lib.entry_count} </p>
</div>
{!lib.is_active && (
<button onClick={e => { e.stopPropagation(); DeleteLibrary(lib.name); load(); }}
className="text-white/20 hover:text-red-400 text-xs transition-colors"></button>
)}
</div>
))}
</div>
{/* Create new */}
<div className="border-t border-white/8 p-2">
{creating ? (
<div className="flex gap-2">
<input autoFocus className="flex-1 search-input text-[11px]" placeholder="知识库名称"
value={newName} onChange={e => setNewName(e.target.value)}
onKeyDown={e => e.key === 'Enter' && handleCreate()}
style={{ paddingLeft: '10px', paddingRight: '10px' }} />
<button onClick={handleCreate}
className="px-3 py-1.5 rounded-lg bg-accent text-white text-[11px]"></button>
<button onClick={() => setCreating(false)} className="text-white/30 text-xs"></button>
</div>
) : (
<button onClick={() => setCreating(true)}
className="w-full flex items-center gap-2 px-2 py-1.5 rounded-lg
text-[11px] text-white/50 hover:text-white/70 hover:bg-white/5 transition-all">
<span>+</span>
</button>
)}
</div>
</div>
)}
</div>
);
}
+95
View File
@@ -0,0 +1,95 @@
import { useState } from 'react';
import type { SearchResult } from '../hooks/useSearch';
interface ResultCardProps {
result: SearchResult;
onPolish: (result: SearchResult) => void;
}
const CATEGORY_COLORS: Record<string, string> = {
'通用': 'bg-indigo-500/20 text-indigo-300',
'退款': 'bg-red-500/20 text-red-300',
'物流': 'bg-amber-500/20 text-amber-300',
'产品': 'bg-emerald-500/20 text-emerald-300',
'促销': 'bg-pink-500/20 text-pink-300',
};
export default function ResultCard({ result, onPolish }: ResultCardProps) {
const [copied, setCopied] = useState(false);
const handleCopy = async () => {
try {
await navigator.clipboard.writeText(result.answer);
} catch {
// Wails fallback — plain execCommand
const el = document.createElement('textarea');
el.value = result.answer;
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
}
setCopied(true);
setTimeout(() => setCopied(false), 1000);
};
const catColor = CATEGORY_COLORS[result.category] ?? 'bg-white/10 text-white/50';
return (
<div className={`result-card group relative ${result.is_fallback ? 'opacity-70' : ''}`} onClick={handleCopy}>
{/* Category badge + match indicator */}
<div className="flex items-center justify-between mb-2">
<span className={`text-[10px] font-medium px-2 py-0.5 rounded-full ${catColor}`}>
{result.category}
</span>
{result.is_fallback ? (
<span className="text-[10px] text-white/30 flex items-center gap-1">
🔥
</span>
) : result.score === 2 ? (
<span className="text-[10px] text-accent-light flex items-center gap-1">
</span>
) : null}
</div>
{/* Question */}
<p className="text-[12px] text-white/50 mb-1.5 line-clamp-1">
Q: {result.question}
</p>
{/* Answer */}
<p className="text-[13px] text-white/90 leading-relaxed line-clamp-3">
{result.answer}
</p>
{/* Hover action bar */}
<div className="flex items-center gap-2 mt-3 opacity-0 group-hover:opacity-100 transition-opacity">
<button
id={`btn-copy-${result.id}`}
onClick={e => { e.stopPropagation(); handleCopy(); }}
className="flex-1 text-[11px] py-1.5 rounded-lg bg-accent/20 text-accent-light border border-accent/30
hover:bg-accent/35 transition-all font-medium"
>
{copied ? '✓ 已复制' : '📋 复制'}
</button>
<button
id={`btn-polish-${result.id}`}
onClick={e => { e.stopPropagation(); onPolish(result); }}
className="flex-1 text-[11px] py-1.5 rounded-lg bg-white/5 text-white/60 border border-white/10
hover:bg-accent/15 hover:text-accent-light hover:border-accent/30 transition-all font-medium"
>
AI
</button>
</div>
{/* Copy toast */}
{copied && (
<div className="copy-toast absolute top-2 right-2 text-[10px] bg-green-500/20 text-green-400
border border-green-500/30 px-2 py-1 rounded-md pointer-events-none">
</div>
)}
</div>
);
}
+53
View File
@@ -0,0 +1,53 @@
import { useRef } from 'react';
interface SearchInputProps {
value: string;
onChange: (v: string) => void;
loading: boolean;
}
export default function SearchInput({ value, onChange, loading }: SearchInputProps) {
const inputRef = useRef<HTMLInputElement>(null);
return (
<div className="px-4 pt-4 pb-2 flex-shrink-0">
<div className="relative">
{/* Icon / spinner */}
<div className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 flex items-center justify-center">
{loading ? (
<svg className="animate-spin w-4 h-4 text-accent" viewBox="0 0 24 24" fill="none">
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"/>
<path className="opacity-75" fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"/>
</svg>
) : (
<svg className="w-4 h-4 text-white/30" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
<circle cx="11" cy="11" r="8"/><path d="m21 21-4.35-4.35"/>
</svg>
)}
</div>
<input
ref={inputRef}
id="search-input"
className="search-input"
type="text"
placeholder="输入关键词搜索知识库…"
value={value}
onChange={e => onChange(e.target.value)}
style={{ userSelect: 'text' }}
/>
{/* Clear button */}
{value && (
<button
onClick={() => { onChange(''); inputRef.current?.focus(); }}
className="absolute right-3 top-1/2 -translate-y-1/2 text-white/30 hover:text-white/70 transition-colors text-xs"
>
</button>
)}
</div>
</div>
);
}
+138
View File
@@ -0,0 +1,138 @@
import { useEffect, useState } from 'react';
import { GetProviders, GetSettings, SaveSettings } from 'wailsjs/go/main/App';
import type { handler, service } from 'wailsjs/go/models';
interface SettingsModalProps {
onClose: () => void;
}
const EMPTY: service.SettingsDTO = {
ai_provider: 'deepseek', base_url: '', api_key: '',
model: 'deepseek-chat', system_prompt: '', max_tokens: 1024, use_public_key: true,
};
export default function SettingsModal({ onClose }: SettingsModalProps) {
const [form, setForm] = useState<service.SettingsDTO>(EMPTY);
const [providers, setProviders] = useState<handler.ProviderPreset[]>([]);
const [saving, setSaving] = useState(false);
const [msg, setMsg] = useState('');
useEffect(() => {
Promise.all([GetSettings(), GetProviders()]).then(([s, p]) => {
if (s) setForm(s);
setProviders(p);
});
}, []);
const set = (k: keyof service.SettingsDTO, v: unknown) =>
setForm(f => ({ ...f, [k]: v }));
const handleProviderChange = (providerId: string) => {
const preset = providers.find(p => p.id === providerId);
set('ai_provider', providerId);
if (preset?.base_url) set('base_url', preset.base_url);
if (preset?.default_model) set('model', preset.default_model);
};
const handleSave = async () => {
setSaving(true); setMsg('');
const err = await SaveSettings(form);
setMsg(err || '✓ 已保存');
setSaving(false);
if (!err) setTimeout(onClose, 800);
};
const inp = 'search-input text-[12px]';
const lbl = 'text-[10px] text-white/45 mb-1';
return (
<div className="fixed inset-0 z-50 flex items-end pb-2 px-2">
<div className="w-full bg-[rgba(14,12,28,0.97)] border border-white/10 rounded-2xl
shadow-2xl overflow-hidden animate-slide-in">
{/* Header */}
<div className="flex items-center justify-between px-4 py-3 border-b border-white/8">
<span className="text-[13px] font-semibold text-white"> AI </span>
<button onClick={onClose} className="text-white/30 hover:text-white/70 text-xs"></button>
</div>
<div className="px-4 py-3 flex flex-col gap-3 overflow-y-auto max-h-[480px] results-scroll">
{/* Public key toggle */}
<label className="flex items-center justify-between cursor-pointer">
<span className="text-[12px] text-white/70">使线 Key</span>
<div onClick={() => set('use_public_key', !form.use_public_key)}
className={`w-10 h-5 rounded-full transition-colors relative ${form.use_public_key ? 'bg-accent' : 'bg-white/15'}`}>
<div className={`absolute top-0.5 w-4 h-4 rounded-full bg-white shadow transition-transform
${form.use_public_key ? 'translate-x-5' : 'translate-x-0.5'}`} />
</div>
</label>
{!form.use_public_key && (<>
{/* Provider */}
<div>
<p className={lbl}>AI </p>
<select value={form.ai_provider} onChange={e => handleProviderChange(e.target.value)}
className={inp + ' w-full bg-white/6 border border-white/12 rounded-xl px-3 py-2'}>
{providers.map(p => <option key={p.id} value={p.id}>{p.label}</option>)}
</select>
</div>
{/* Base URL (shown for custom) */}
{form.ai_provider === 'custom' && (
<div>
<p className={lbl}>API (Base URL)</p>
<input className={inp} placeholder="https://your-api/v1/chat/completions"
value={form.base_url} onChange={e => set('base_url', e.target.value)}
style={{ paddingLeft: '14px' }} />
</div>
)}
{/* API Key */}
<div>
<p className={lbl}>API Key</p>
<input className={inp} type="password" placeholder="sk-..."
value={form.api_key} onChange={e => set('api_key', e.target.value)}
style={{ paddingLeft: '14px' }} />
</div>
{/* Model */}
<div>
<p className={lbl}></p>
<input className={inp} placeholder="deepseek-chat"
value={form.model} onChange={e => set('model', e.target.value)}
style={{ paddingLeft: '14px' }} />
</div>
{/* Max tokens */}
<div>
<p className={lbl}>Max Tokens: {form.max_tokens}</p>
<input type="range" min={256} max={4096} step={128}
value={form.max_tokens} onChange={e => set('max_tokens', Number(e.target.value))}
className="w-full accent-accent" />
</div>
</>)}
{/* System prompt (always visible) */}
<div>
<p className={lbl}>使 RAG </p>
<textarea value={form.system_prompt} onChange={e => set('system_prompt', e.target.value)}
rows={3} placeholder="你是一位专业客服顾问…"
className="w-full bg-white/6 border border-white/12 rounded-xl px-3 py-2
text-[12px] text-white/80 resize-none focus:outline-none
focus:border-accent/50 focus:shadow-[0_0_0_3px_rgba(124,110,247,0.2)]"
style={{ userSelect: 'text' }} />
</div>
</div>
{/* Footer */}
<div className="px-4 pb-3 flex items-center gap-2">
{msg && <span className={`text-[11px] flex-1 ${msg.startsWith('✓') ? 'text-green-400' : 'text-red-400'}`}>{msg}</span>}
<button onClick={handleSave} disabled={saving}
className="ml-auto px-5 py-2 rounded-xl bg-accent text-white text-[12px] font-semibold
hover:bg-accent-light transition-all disabled:opacity-50">
{saving ? '保存中…' : '保存'}
</button>
</div>
</div>
</div>
);
}
+61
View File
@@ -0,0 +1,61 @@
import { useState } from 'react';
import { ToggleTopmost } from 'wailsjs/go/main/App';
import { Quit, WindowMinimise } from 'wailsjs/runtime/runtime';
interface TitleBarProps {
dbReady: boolean;
onSettings: () => void;
}
export default function TitleBar({ dbReady, onSettings }: TitleBarProps) {
const [pinned, setPinned] = useState(true);
const handlePin = async () => {
const next = !pinned;
setPinned(next);
await ToggleTopmost(next);
};
return (
<div className="drag-region flex items-center justify-between px-4 py-3 flex-shrink-0 border-b border-white/5">
{/* Logo */}
<div className="flex items-center gap-2 select-none pointer-events-none">
<div className="w-7 h-7 rounded-lg bg-gradient-to-br from-accent to-accent-dark flex items-center justify-center shadow-lg">
<span className="text-white text-xs">🤖</span>
</div>
<div>
<p className="text-[12px] font-semibold text-white leading-tight">AI Expert Sidebar</p>
<div className="flex items-center gap-1">
<span className={`w-1.5 h-1.5 rounded-full ${dbReady ? 'bg-green-400' : 'bg-amber-400'}`}
style={{ boxShadow: dbReady ? '0 0 5px #4ade80' : '0 0 5px #fbbf24' }} />
<span className="text-[9px] text-white/35">{dbReady ? '本地 SQLite' : '初始化…'}</span>
</div>
</div>
</div>
{/* Controls */}
<div className="flex items-center gap-1" style={{ '--wails-draggable': 'no-drag' } as React.CSSProperties}>
<button id="btn-settings" onClick={onSettings} title="AI 设置"
className="w-7 h-7 rounded-md flex items-center justify-center text-sm text-white/40
hover:bg-white/10 hover:text-white/70 transition-all">
</button>
<button id="btn-pin" onClick={handlePin} title={pinned ? '取消置顶' : '置顶'}
className={`w-7 h-7 rounded-md flex items-center justify-center text-sm transition-all
${pinned ? 'bg-accent/30 text-accent-light border border-accent/40'
: 'text-white/40 hover:bg-white/10'}`}>
📌
</button>
<button id="btn-min" onClick={() => WindowMinimise()} title="最小化"
className="w-7 h-7 rounded-md flex items-center justify-center text-xs text-white/40 hover:bg-white/10 transition-all">
</button>
<button id="btn-quit" onClick={() => Quit()} title="退出"
className="w-7 h-7 rounded-md flex items-center justify-center text-xs text-white/40
hover:bg-red-500/20 hover:text-red-400 transition-all">
</button>
</div>
</div>
);
}
+47
View File
@@ -0,0 +1,47 @@
import { useEffect, useRef, useState, useCallback } from 'react';
import { SearchExpert } from 'wailsjs/go/main/App';
export interface SearchResult {
id: number;
question: string;
answer: string;
category: string;
score: number;
is_fallback: boolean;
}
export function useSearch(debounceMs = 300) {
const [query, setQuery] = useState('');
const [results, setResults] = useState<SearchResult[]>([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const timerRef = useRef<ReturnType<typeof setTimeout>>();
const doSearch = useCallback(async (q: string) => {
if (!q.trim()) {
setResults([]);
setError(null);
return;
}
setLoading(true);
setError(null);
try {
const res = await SearchExpert(q) as SearchResult[] | null;
setResults(res ?? []);
} catch (e) {
console.error('[useSearch]', e);
setError('数据库连接失败,已进入本地基础库模式');
setResults([]);
} finally {
setLoading(false);
}
}, []);
useEffect(() => {
clearTimeout(timerRef.current);
timerRef.current = setTimeout(() => doSearch(query), debounceMs);
return () => clearTimeout(timerRef.current);
}, [query, debounceMs, doSearch]);
return { query, setQuery, results, loading, error };
}
+138
View File
@@ -0,0 +1,138 @@
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
@tailwind base;
@tailwind components;
@tailwind utilities;
/* ── Global Reset ────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body, #root {
height: 100%;
margin: 0;
padding: 0;
font-family: 'Inter', system-ui, sans-serif;
-webkit-font-smoothing: antialiased;
}
body {
background: transparent;
color: #e8e5ff;
overflow: hidden;
user-select: none;
}
/* ── Glassmorphism Variables ─────────────────────────── */
:root {
--glass-bg: rgba(14, 12, 28, 0.88);
--glass-border: rgba(124, 110, 247, 0.25);
--glass-blur: 20px;
--accent: #7c6ef7;
--accent-light: #a599f9;
--accent-glow: rgba(124,110,247,0.3);
--danger: #ff5c7c;
--success: #4ade80;
--text-primary: #e8e5ff;
--text-muted: rgba(232,229,255,0.5);
--radius: 16px;
}
/* ── Root Container ──────────────────────────────────── */
.sidebar-root {
width: 350px;
height: 700px;
background: var(--glass-bg);
backdrop-filter: blur(var(--glass-blur)) saturate(180%);
-webkit-backdrop-filter: blur(var(--glass-blur)) saturate(180%);
border: 1px solid var(--glass-border);
border-radius: var(--radius);
display: flex;
flex-direction: column;
overflow: hidden;
position: relative;
}
/* ── Drag Region ─────────────────────────────────────── */
.drag-region {
--wails-draggable: drag;
cursor: grab;
}
.drag-region:active { cursor: grabbing; }
/* ── Scrollbar ───────────────────────────────────────── */
.results-scroll::-webkit-scrollbar { width: 4px; }
.results-scroll::-webkit-scrollbar-track { background: transparent; }
.results-scroll::-webkit-scrollbar-thumb {
background: var(--glass-border);
border-radius: 4px;
}
/* ── Card ────────────────────────────────────────────── */
.result-card {
background: rgba(255,255,255,0.04);
border: 1px solid rgba(255,255,255,0.08);
border-radius: 12px;
padding: 14px;
transition: all 0.2s ease;
cursor: pointer;
animation: slideIn 0.3s cubic-bezier(0.34,1.56,0.64,1);
}
.result-card:hover {
background: rgba(124,110,247,0.12);
border-color: rgba(124,110,247,0.4);
transform: translateY(-1px);
box-shadow: 0 4px 20px var(--accent-glow);
}
.result-card:active { transform: translateY(0); }
/* ── Copy Toast ──────────────────────────────────────── */
.copy-toast {
animation: fadeIn 0.15s ease, fadeOut 0.15s ease 0.85s forwards;
}
@keyframes fadeOut { to { opacity: 0; transform: translateY(-4px); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } }
@keyframes slideIn { from { opacity:0; transform:translateY(10px); } to { opacity:1; transform:translateY(0); } }
/* ── Input ───────────────────────────────────────────── */
.search-input {
background: rgba(255,255,255,0.06);
border: 1px solid rgba(255,255,255,0.12);
border-radius: 10px;
color: var(--text-primary);
outline: none;
width: 100%;
padding: 10px 14px 10px 38px;
font-size: 14px;
transition: border-color 0.2s, box-shadow 0.2s;
}
.search-input:focus {
border-color: var(--accent);
box-shadow: 0 0 0 3px var(--accent-glow);
}
.search-input::placeholder { color: var(--text-muted); }
/* ── AI Panel ────────────────────────────────────────── */
.ai-panel {
background: rgba(124,110,247,0.07);
border: 1px solid rgba(124,110,247,0.2);
border-radius: 12px;
padding: 14px;
font-size: 13px;
line-height: 1.7;
color: var(--text-primary);
min-height: 80px;
white-space: pre-wrap;
word-break: break-word;
}
/* ── Gradient Orbs ───────────────────────────────────── */
.orb {
position: absolute;
border-radius: 50%;
filter: blur(60px);
pointer-events: none;
opacity: 0.18;
z-index: 0;
}
.orb-purple { width:200px; height:200px; background:#7c6ef7; top:-60px; right:-60px; }
.orb-blue { width:160px; height:160px; background:#38bdf8; bottom:-40px; left:-40px; }
+10
View File
@@ -0,0 +1,10 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App'
import './index.css'
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>,
)
+26
View File
@@ -0,0 +1,26 @@
html {
background-color: rgba(27, 38, 54, 1);
text-align: center;
color: white;
}
body {
margin: 0;
color: white;
font-family: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto",
"Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
sans-serif;
}
@font-face {
font-family: "Nunito";
font-style: normal;
font-weight: 400;
src: local(""),
url("assets/fonts/nunito-v16-latin-regular.woff2") format("woff2");
}
#app {
height: 100vh;
text-align: center;
}
+1
View File
@@ -0,0 +1 @@
/// <reference types="vite/client" />
+35
View File
@@ -0,0 +1,35 @@
/** @type {import('tailwindcss').Config} */
export default {
content: ["./index.html", "./src/**/*.{ts,tsx}"],
theme: {
extend: {
fontFamily: {
sans: ["Inter", "system-ui", "sans-serif"],
},
colors: {
accent: {
DEFAULT: "#7c6ef7",
light: "#a599f9",
dark: "#5b4de0",
},
surface: {
DEFAULT: "rgba(18, 16, 32, 0.92)",
card: "rgba(255,255,255,0.05)",
hover: "rgba(255,255,255,0.09)",
},
},
animation: {
"fade-in": "fadeIn 0.25s ease",
"slide-in": "slideIn 0.3s cubic-bezier(0.34,1.56,0.64,1)",
"pulse-dot": "pulseDot 1.4s ease-in-out infinite",
"typewriter":"typewriter 0.04s steps(1) forwards",
},
keyframes: {
fadeIn: { from: { opacity: 0 }, to: { opacity: 1 } },
slideIn: { from: { opacity: 0, transform: "translateY(10px)" }, to: { opacity: 1, transform: "translateY(0)" } },
pulseDot: { "0%,100%": { opacity: 0.3 }, "50%": { opacity: 1 } },
},
},
},
plugins: [],
};
+37
View File
@@ -0,0 +1,37 @@
{
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"lib": [
"DOM",
"DOM.Iterable",
"ESNext"
],
"allowJs": false,
"skipLibCheck": true,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"baseUrl": ".",
"paths": {
"../wailsjs/*": ["wailsjs/*"],
"../../wailsjs/*": ["wailsjs/*"]
},
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": [
"src",
"wailsjs"
],
"references": [
{
"path": "./tsconfig.node.json"
}
]
}
+11
View File
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"composite": true,
"module": "ESNext",
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true
},
"include": [
"vite.config.ts"
]
}
+14
View File
@@ -0,0 +1,14 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'path'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
resolve: {
alias: {
// Allow "wailsjs/..." absolute imports to resolve to ../wailsjs/
'wailsjs': path.resolve(__dirname, 'wailsjs'),
},
},
})
+32
View File
@@ -0,0 +1,32 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
import {handler} from '../models';
import {service} from '../models';
export function AskDeepSeek(arg1:string,arg2:string):Promise<string>;
export function CreateLibrary(arg1:string,arg2:string):Promise<string>;
export function DeleteLibrary(arg1:string):Promise<string>;
export function GetActiveLibrary():Promise<string>;
export function GetDBStatus():Promise<boolean>;
export function GetProviders():Promise<Array<handler.ProviderPreset>>;
export function GetSettings():Promise<service.SettingsDTO>;
export function ImportCSV():Promise<service.ImportResult>;
export function ListLibraries():Promise<Array<handler.LibraryInfo>>;
export function SaveSettings(arg1:service.SettingsDTO):Promise<string>;
export function SearchExpert(arg1:string):Promise<any>;
export function StopGeneration():Promise<void>;
export function SwitchLibrary(arg1:string):Promise<string>;
export function ToggleTopmost(arg1:boolean):Promise<void>;
+59
View File
@@ -0,0 +1,59 @@
// @ts-check
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
export function AskDeepSeek(arg1, arg2) {
return window['go']['main']['App']['AskDeepSeek'](arg1, arg2);
}
export function CreateLibrary(arg1, arg2) {
return window['go']['main']['App']['CreateLibrary'](arg1, arg2);
}
export function DeleteLibrary(arg1) {
return window['go']['main']['App']['DeleteLibrary'](arg1);
}
export function GetActiveLibrary() {
return window['go']['main']['App']['GetActiveLibrary']();
}
export function GetDBStatus() {
return window['go']['main']['App']['GetDBStatus']();
}
export function GetProviders() {
return window['go']['main']['App']['GetProviders']();
}
export function GetSettings() {
return window['go']['main']['App']['GetSettings']();
}
export function ImportCSV() {
return window['go']['main']['App']['ImportCSV']();
}
export function ListLibraries() {
return window['go']['main']['App']['ListLibraries']();
}
export function SaveSettings(arg1) {
return window['go']['main']['App']['SaveSettings'](arg1);
}
export function SearchExpert(arg1) {
return window['go']['main']['App']['SearchExpert'](arg1);
}
export function StopGeneration() {
return window['go']['main']['App']['StopGeneration']();
}
export function SwitchLibrary(arg1) {
return window['go']['main']['App']['SwitchLibrary'](arg1);
}
export function ToggleTopmost(arg1) {
return window['go']['main']['App']['ToggleTopmost'](arg1);
}
+88
View File
@@ -0,0 +1,88 @@
export namespace handler {
export class LibraryInfo {
id: number;
name: string;
description: string;
entry_count: number;
is_active: boolean;
static createFrom(source: any = {}) {
return new LibraryInfo(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.id = source["id"];
this.name = source["name"];
this.description = source["description"];
this.entry_count = source["entry_count"];
this.is_active = source["is_active"];
}
}
export class ProviderPreset {
id: string;
label: string;
base_url: string;
default_model: string;
static createFrom(source: any = {}) {
return new ProviderPreset(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.id = source["id"];
this.label = source["label"];
this.base_url = source["base_url"];
this.default_model = source["default_model"];
}
}
}
export namespace service {
export class ImportResult {
imported: number;
skipped: number;
error?: string;
static createFrom(source: any = {}) {
return new ImportResult(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.imported = source["imported"];
this.skipped = source["skipped"];
this.error = source["error"];
}
}
export class SettingsDTO {
ai_provider: string;
base_url: string;
api_key: string;
model: string;
system_prompt: string;
max_tokens: number;
use_public_key: boolean;
static createFrom(source: any = {}) {
return new SettingsDTO(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.ai_provider = source["ai_provider"];
this.base_url = source["base_url"];
this.api_key = source["api_key"];
this.model = source["model"];
this.system_prompt = source["system_prompt"];
this.max_tokens = source["max_tokens"];
this.use_public_key = source["use_public_key"];
}
}
}
+24
View File
@@ -0,0 +1,24 @@
{
"name": "@wailsapp/runtime",
"version": "2.0.0",
"description": "Wails Javascript runtime library",
"main": "runtime.js",
"types": "runtime.d.ts",
"scripts": {
},
"repository": {
"type": "git",
"url": "git+https://github.com/wailsapp/wails.git"
},
"keywords": [
"Wails",
"Javascript",
"Go"
],
"author": "Lea Anthony <lea.anthony@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/wailsapp/wails/issues"
},
"homepage": "https://github.com/wailsapp/wails#readme"
}
+330
View File
@@ -0,0 +1,330 @@
/*
_ __ _ __
| | / /___ _(_) /____
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
The electron alternative for Go
(c) Lea Anthony 2019-present
*/
export interface Position {
x: number;
y: number;
}
export interface Size {
w: number;
h: number;
}
export interface Screen {
isCurrent: boolean;
isPrimary: boolean;
width : number
height : number
}
// Environment information such as platform, buildtype, ...
export interface EnvironmentInfo {
buildType: string;
platform: string;
arch: string;
}
// [EventsEmit](https://wails.io/docs/reference/runtime/events#eventsemit)
// emits the given event. Optional data may be passed with the event.
// This will trigger any event listeners.
export function EventsEmit(eventName: string, ...data: any): void;
// [EventsOn](https://wails.io/docs/reference/runtime/events#eventson) sets up a listener for the given event name.
export function EventsOn(eventName: string, callback: (...data: any) => void): () => void;
// [EventsOnMultiple](https://wails.io/docs/reference/runtime/events#eventsonmultiple)
// sets up a listener for the given event name, but will only trigger a given number times.
export function EventsOnMultiple(eventName: string, callback: (...data: any) => void, maxCallbacks: number): () => void;
// [EventsOnce](https://wails.io/docs/reference/runtime/events#eventsonce)
// sets up a listener for the given event name, but will only trigger once.
export function EventsOnce(eventName: string, callback: (...data: any) => void): () => void;
// [EventsOff](https://wails.io/docs/reference/runtime/events#eventsoff)
// unregisters the listener for the given event name.
export function EventsOff(eventName: string, ...additionalEventNames: string[]): void;
// [EventsOffAll](https://wails.io/docs/reference/runtime/events#eventsoffall)
// unregisters all listeners.
export function EventsOffAll(): void;
// [LogPrint](https://wails.io/docs/reference/runtime/log#logprint)
// logs the given message as a raw message
export function LogPrint(message: string): void;
// [LogTrace](https://wails.io/docs/reference/runtime/log#logtrace)
// logs the given message at the `trace` log level.
export function LogTrace(message: string): void;
// [LogDebug](https://wails.io/docs/reference/runtime/log#logdebug)
// logs the given message at the `debug` log level.
export function LogDebug(message: string): void;
// [LogError](https://wails.io/docs/reference/runtime/log#logerror)
// logs the given message at the `error` log level.
export function LogError(message: string): void;
// [LogFatal](https://wails.io/docs/reference/runtime/log#logfatal)
// logs the given message at the `fatal` log level.
// The application will quit after calling this method.
export function LogFatal(message: string): void;
// [LogInfo](https://wails.io/docs/reference/runtime/log#loginfo)
// logs the given message at the `info` log level.
export function LogInfo(message: string): void;
// [LogWarning](https://wails.io/docs/reference/runtime/log#logwarning)
// logs the given message at the `warning` log level.
export function LogWarning(message: string): void;
// [WindowReload](https://wails.io/docs/reference/runtime/window#windowreload)
// Forces a reload by the main application as well as connected browsers.
export function WindowReload(): void;
// [WindowReloadApp](https://wails.io/docs/reference/runtime/window#windowreloadapp)
// Reloads the application frontend.
export function WindowReloadApp(): void;
// [WindowSetAlwaysOnTop](https://wails.io/docs/reference/runtime/window#windowsetalwaysontop)
// Sets the window AlwaysOnTop or not on top.
export function WindowSetAlwaysOnTop(b: boolean): void;
// [WindowSetSystemDefaultTheme](https://wails.io/docs/next/reference/runtime/window#windowsetsystemdefaulttheme)
// *Windows only*
// Sets window theme to system default (dark/light).
export function WindowSetSystemDefaultTheme(): void;
// [WindowSetLightTheme](https://wails.io/docs/next/reference/runtime/window#windowsetlighttheme)
// *Windows only*
// Sets window to light theme.
export function WindowSetLightTheme(): void;
// [WindowSetDarkTheme](https://wails.io/docs/next/reference/runtime/window#windowsetdarktheme)
// *Windows only*
// Sets window to dark theme.
export function WindowSetDarkTheme(): void;
// [WindowCenter](https://wails.io/docs/reference/runtime/window#windowcenter)
// Centers the window on the monitor the window is currently on.
export function WindowCenter(): void;
// [WindowSetTitle](https://wails.io/docs/reference/runtime/window#windowsettitle)
// Sets the text in the window title bar.
export function WindowSetTitle(title: string): void;
// [WindowFullscreen](https://wails.io/docs/reference/runtime/window#windowfullscreen)
// Makes the window full screen.
export function WindowFullscreen(): void;
// [WindowUnfullscreen](https://wails.io/docs/reference/runtime/window#windowunfullscreen)
// Restores the previous window dimensions and position prior to full screen.
export function WindowUnfullscreen(): void;
// [WindowIsFullscreen](https://wails.io/docs/reference/runtime/window#windowisfullscreen)
// Returns the state of the window, i.e. whether the window is in full screen mode or not.
export function WindowIsFullscreen(): Promise<boolean>;
// [WindowSetSize](https://wails.io/docs/reference/runtime/window#windowsetsize)
// Sets the width and height of the window.
export function WindowSetSize(width: number, height: number): void;
// [WindowGetSize](https://wails.io/docs/reference/runtime/window#windowgetsize)
// Gets the width and height of the window.
export function WindowGetSize(): Promise<Size>;
// [WindowSetMaxSize](https://wails.io/docs/reference/runtime/window#windowsetmaxsize)
// Sets the maximum window size. Will resize the window if the window is currently larger than the given dimensions.
// Setting a size of 0,0 will disable this constraint.
export function WindowSetMaxSize(width: number, height: number): void;
// [WindowSetMinSize](https://wails.io/docs/reference/runtime/window#windowsetminsize)
// Sets the minimum window size. Will resize the window if the window is currently smaller than the given dimensions.
// Setting a size of 0,0 will disable this constraint.
export function WindowSetMinSize(width: number, height: number): void;
// [WindowSetPosition](https://wails.io/docs/reference/runtime/window#windowsetposition)
// Sets the window position relative to the monitor the window is currently on.
export function WindowSetPosition(x: number, y: number): void;
// [WindowGetPosition](https://wails.io/docs/reference/runtime/window#windowgetposition)
// Gets the window position relative to the monitor the window is currently on.
export function WindowGetPosition(): Promise<Position>;
// [WindowHide](https://wails.io/docs/reference/runtime/window#windowhide)
// Hides the window.
export function WindowHide(): void;
// [WindowShow](https://wails.io/docs/reference/runtime/window#windowshow)
// Shows the window, if it is currently hidden.
export function WindowShow(): void;
// [WindowMaximise](https://wails.io/docs/reference/runtime/window#windowmaximise)
// Maximises the window to fill the screen.
export function WindowMaximise(): void;
// [WindowToggleMaximise](https://wails.io/docs/reference/runtime/window#windowtogglemaximise)
// Toggles between Maximised and UnMaximised.
export function WindowToggleMaximise(): void;
// [WindowUnmaximise](https://wails.io/docs/reference/runtime/window#windowunmaximise)
// Restores the window to the dimensions and position prior to maximising.
export function WindowUnmaximise(): void;
// [WindowIsMaximised](https://wails.io/docs/reference/runtime/window#windowismaximised)
// Returns the state of the window, i.e. whether the window is maximised or not.
export function WindowIsMaximised(): Promise<boolean>;
// [WindowMinimise](https://wails.io/docs/reference/runtime/window#windowminimise)
// Minimises the window.
export function WindowMinimise(): void;
// [WindowUnminimise](https://wails.io/docs/reference/runtime/window#windowunminimise)
// Restores the window to the dimensions and position prior to minimising.
export function WindowUnminimise(): void;
// [WindowIsMinimised](https://wails.io/docs/reference/runtime/window#windowisminimised)
// Returns the state of the window, i.e. whether the window is minimised or not.
export function WindowIsMinimised(): Promise<boolean>;
// [WindowIsNormal](https://wails.io/docs/reference/runtime/window#windowisnormal)
// Returns the state of the window, i.e. whether the window is normal or not.
export function WindowIsNormal(): Promise<boolean>;
// [WindowSetBackgroundColour](https://wails.io/docs/reference/runtime/window#windowsetbackgroundcolour)
// Sets the background colour of the window to the given RGBA colour definition. This colour will show through for all transparent pixels.
export function WindowSetBackgroundColour(R: number, G: number, B: number, A: number): void;
// [ScreenGetAll](https://wails.io/docs/reference/runtime/window#screengetall)
// Gets the all screens. Call this anew each time you want to refresh data from the underlying windowing system.
export function ScreenGetAll(): Promise<Screen[]>;
// [BrowserOpenURL](https://wails.io/docs/reference/runtime/browser#browseropenurl)
// Opens the given URL in the system browser.
export function BrowserOpenURL(url: string): void;
// [Environment](https://wails.io/docs/reference/runtime/intro#environment)
// Returns information about the environment
export function Environment(): Promise<EnvironmentInfo>;
// [Quit](https://wails.io/docs/reference/runtime/intro#quit)
// Quits the application.
export function Quit(): void;
// [Hide](https://wails.io/docs/reference/runtime/intro#hide)
// Hides the application.
export function Hide(): void;
// [Show](https://wails.io/docs/reference/runtime/intro#show)
// Shows the application.
export function Show(): void;
// [ClipboardGetText](https://wails.io/docs/reference/runtime/clipboard#clipboardgettext)
// Returns the current text stored on clipboard
export function ClipboardGetText(): Promise<string>;
// [ClipboardSetText](https://wails.io/docs/reference/runtime/clipboard#clipboardsettext)
// Sets a text on the clipboard
export function ClipboardSetText(text: string): Promise<boolean>;
// [OnFileDrop](https://wails.io/docs/reference/runtime/draganddrop#onfiledrop)
// OnFileDrop listens to drag and drop events and calls the callback with the coordinates of the drop and an array of path strings.
export function OnFileDrop(callback: (x: number, y: number ,paths: string[]) => void, useDropTarget: boolean) :void
// [OnFileDropOff](https://wails.io/docs/reference/runtime/draganddrop#dragandddropoff)
// OnFileDropOff removes the drag and drop listeners and handlers.
export function OnFileDropOff() :void
// Check if the file path resolver is available
export function CanResolveFilePaths(): boolean;
// Resolves file paths for an array of files
export function ResolveFilePaths(files: File[]): void
// Notification types
export interface NotificationOptions {
id: string;
title: string;
subtitle?: string; // macOS and Linux only
body?: string;
categoryId?: string;
data?: { [key: string]: any };
}
export interface NotificationAction {
id?: string;
title?: string;
destructive?: boolean; // macOS-specific
}
export interface NotificationCategory {
id?: string;
actions?: NotificationAction[];
hasReplyField?: boolean;
replyPlaceholder?: string;
replyButtonTitle?: string;
}
// [InitializeNotifications](https://wails.io/docs/reference/runtime/notification#initializenotifications)
// Initializes the notification service for the application.
// This must be called before sending any notifications.
export function InitializeNotifications(): Promise<void>;
// [CleanupNotifications](https://wails.io/docs/reference/runtime/notification#cleanupnotifications)
// Cleans up notification resources and releases any held connections.
export function CleanupNotifications(): Promise<void>;
// [IsNotificationAvailable](https://wails.io/docs/reference/runtime/notification#isnotificationavailable)
// Checks if notifications are available on the current platform.
export function IsNotificationAvailable(): Promise<boolean>;
// [RequestNotificationAuthorization](https://wails.io/docs/reference/runtime/notification#requestnotificationauthorization)
// Requests notification authorization from the user (macOS only).
export function RequestNotificationAuthorization(): Promise<boolean>;
// [CheckNotificationAuthorization](https://wails.io/docs/reference/runtime/notification#checknotificationauthorization)
// Checks the current notification authorization status (macOS only).
export function CheckNotificationAuthorization(): Promise<boolean>;
// [SendNotification](https://wails.io/docs/reference/runtime/notification#sendnotification)
// Sends a basic notification with the given options.
export function SendNotification(options: NotificationOptions): Promise<void>;
// [SendNotificationWithActions](https://wails.io/docs/reference/runtime/notification#sendnotificationwithactions)
// Sends a notification with action buttons. Requires a registered category.
export function SendNotificationWithActions(options: NotificationOptions): Promise<void>;
// [RegisterNotificationCategory](https://wails.io/docs/reference/runtime/notification#registernotificationcategory)
// Registers a notification category that can be used with SendNotificationWithActions.
export function RegisterNotificationCategory(category: NotificationCategory): Promise<void>;
// [RemoveNotificationCategory](https://wails.io/docs/reference/runtime/notification#removenotificationcategory)
// Removes a previously registered notification category.
export function RemoveNotificationCategory(categoryId: string): Promise<void>;
// [RemoveAllPendingNotifications](https://wails.io/docs/reference/runtime/notification#removeallpendingnotifications)
// Removes all pending notifications from the notification center.
export function RemoveAllPendingNotifications(): Promise<void>;
// [RemovePendingNotification](https://wails.io/docs/reference/runtime/notification#removependingnotification)
// Removes a specific pending notification by its identifier.
export function RemovePendingNotification(identifier: string): Promise<void>;
// [RemoveAllDeliveredNotifications](https://wails.io/docs/reference/runtime/notification#removealldeliverednotifications)
// Removes all delivered notifications from the notification center.
export function RemoveAllDeliveredNotifications(): Promise<void>;
// [RemoveDeliveredNotification](https://wails.io/docs/reference/runtime/notification#removedeliverednotification)
// Removes a specific delivered notification by its identifier.
export function RemoveDeliveredNotification(identifier: string): Promise<void>;
// [RemoveNotification](https://wails.io/docs/reference/runtime/notification#removenotification)
// Removes a notification by its identifier (cross-platform convenience function).
export function RemoveNotification(identifier: string): Promise<void>;
+298
View File
@@ -0,0 +1,298 @@
/*
_ __ _ __
| | / /___ _(_) /____
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
The electron alternative for Go
(c) Lea Anthony 2019-present
*/
export function LogPrint(message) {
window.runtime.LogPrint(message);
}
export function LogTrace(message) {
window.runtime.LogTrace(message);
}
export function LogDebug(message) {
window.runtime.LogDebug(message);
}
export function LogInfo(message) {
window.runtime.LogInfo(message);
}
export function LogWarning(message) {
window.runtime.LogWarning(message);
}
export function LogError(message) {
window.runtime.LogError(message);
}
export function LogFatal(message) {
window.runtime.LogFatal(message);
}
export function EventsOnMultiple(eventName, callback, maxCallbacks) {
return window.runtime.EventsOnMultiple(eventName, callback, maxCallbacks);
}
export function EventsOn(eventName, callback) {
return EventsOnMultiple(eventName, callback, -1);
}
export function EventsOff(eventName, ...additionalEventNames) {
return window.runtime.EventsOff(eventName, ...additionalEventNames);
}
export function EventsOffAll() {
return window.runtime.EventsOffAll();
}
export function EventsOnce(eventName, callback) {
return EventsOnMultiple(eventName, callback, 1);
}
export function EventsEmit(eventName) {
let args = [eventName].slice.call(arguments);
return window.runtime.EventsEmit.apply(null, args);
}
export function WindowReload() {
window.runtime.WindowReload();
}
export function WindowReloadApp() {
window.runtime.WindowReloadApp();
}
export function WindowSetAlwaysOnTop(b) {
window.runtime.WindowSetAlwaysOnTop(b);
}
export function WindowSetSystemDefaultTheme() {
window.runtime.WindowSetSystemDefaultTheme();
}
export function WindowSetLightTheme() {
window.runtime.WindowSetLightTheme();
}
export function WindowSetDarkTheme() {
window.runtime.WindowSetDarkTheme();
}
export function WindowCenter() {
window.runtime.WindowCenter();
}
export function WindowSetTitle(title) {
window.runtime.WindowSetTitle(title);
}
export function WindowFullscreen() {
window.runtime.WindowFullscreen();
}
export function WindowUnfullscreen() {
window.runtime.WindowUnfullscreen();
}
export function WindowIsFullscreen() {
return window.runtime.WindowIsFullscreen();
}
export function WindowGetSize() {
return window.runtime.WindowGetSize();
}
export function WindowSetSize(width, height) {
window.runtime.WindowSetSize(width, height);
}
export function WindowSetMaxSize(width, height) {
window.runtime.WindowSetMaxSize(width, height);
}
export function WindowSetMinSize(width, height) {
window.runtime.WindowSetMinSize(width, height);
}
export function WindowSetPosition(x, y) {
window.runtime.WindowSetPosition(x, y);
}
export function WindowGetPosition() {
return window.runtime.WindowGetPosition();
}
export function WindowHide() {
window.runtime.WindowHide();
}
export function WindowShow() {
window.runtime.WindowShow();
}
export function WindowMaximise() {
window.runtime.WindowMaximise();
}
export function WindowToggleMaximise() {
window.runtime.WindowToggleMaximise();
}
export function WindowUnmaximise() {
window.runtime.WindowUnmaximise();
}
export function WindowIsMaximised() {
return window.runtime.WindowIsMaximised();
}
export function WindowMinimise() {
window.runtime.WindowMinimise();
}
export function WindowUnminimise() {
window.runtime.WindowUnminimise();
}
export function WindowSetBackgroundColour(R, G, B, A) {
window.runtime.WindowSetBackgroundColour(R, G, B, A);
}
export function ScreenGetAll() {
return window.runtime.ScreenGetAll();
}
export function WindowIsMinimised() {
return window.runtime.WindowIsMinimised();
}
export function WindowIsNormal() {
return window.runtime.WindowIsNormal();
}
export function BrowserOpenURL(url) {
window.runtime.BrowserOpenURL(url);
}
export function Environment() {
return window.runtime.Environment();
}
export function Quit() {
window.runtime.Quit();
}
export function Hide() {
window.runtime.Hide();
}
export function Show() {
window.runtime.Show();
}
export function ClipboardGetText() {
return window.runtime.ClipboardGetText();
}
export function ClipboardSetText(text) {
return window.runtime.ClipboardSetText(text);
}
/**
* Callback for OnFileDrop returns a slice of file path strings when a drop is finished.
*
* @export
* @callback OnFileDropCallback
* @param {number} x - x coordinate of the drop
* @param {number} y - y coordinate of the drop
* @param {string[]} paths - A list of file paths.
*/
/**
* OnFileDrop listens to drag and drop events and calls the callback with the coordinates of the drop and an array of path strings.
*
* @export
* @param {OnFileDropCallback} callback - Callback for OnFileDrop returns a slice of file path strings when a drop is finished.
* @param {boolean} [useDropTarget=true] - Only call the callback when the drop finished on an element that has the drop target style. (--wails-drop-target)
*/
export function OnFileDrop(callback, useDropTarget) {
return window.runtime.OnFileDrop(callback, useDropTarget);
}
/**
* OnFileDropOff removes the drag and drop listeners and handlers.
*/
export function OnFileDropOff() {
return window.runtime.OnFileDropOff();
}
export function CanResolveFilePaths() {
return window.runtime.CanResolveFilePaths();
}
export function ResolveFilePaths(files) {
return window.runtime.ResolveFilePaths(files);
}
export function InitializeNotifications() {
return window.runtime.InitializeNotifications();
}
export function CleanupNotifications() {
return window.runtime.CleanupNotifications();
}
export function IsNotificationAvailable() {
return window.runtime.IsNotificationAvailable();
}
export function RequestNotificationAuthorization() {
return window.runtime.RequestNotificationAuthorization();
}
export function CheckNotificationAuthorization() {
return window.runtime.CheckNotificationAuthorization();
}
export function SendNotification(options) {
return window.runtime.SendNotification(options);
}
export function SendNotificationWithActions(options) {
return window.runtime.SendNotificationWithActions(options);
}
export function RegisterNotificationCategory(category) {
return window.runtime.RegisterNotificationCategory(category);
}
export function RemoveNotificationCategory(categoryId) {
return window.runtime.RemoveNotificationCategory(categoryId);
}
export function RemoveAllPendingNotifications() {
return window.runtime.RemoveAllPendingNotifications();
}
export function RemovePendingNotification(identifier) {
return window.runtime.RemovePendingNotification(identifier);
}
export function RemoveAllDeliveredNotifications() {
return window.runtime.RemoveAllDeliveredNotifications();
}
export function RemoveDeliveredNotification(identifier) {
return window.runtime.RemoveDeliveredNotification(identifier);
}
export function RemoveNotification(identifier) {
return window.runtime.RemoveNotification(identifier);
}
+62
View File
@@ -0,0 +1,62 @@
module AI-Expert-Sidebar
go 1.23.0
require (
github.com/glebarez/sqlite v1.11.0
github.com/spf13/viper v1.21.0
github.com/wailsapp/wails/v2 v2.12.0
gorm.io/gorm v1.31.1
)
require (
git.sr.ht/~jackmordaunt/go-toast/v2 v2.0.3 // indirect
github.com/bep/debounce v1.2.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/glebarez/go-sqlite v1.21.2 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/labstack/echo/v4 v4.13.3 // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/leaanthony/go-ansi-parser v1.6.1 // indirect
github.com/leaanthony/gosod v1.0.4 // indirect
github.com/leaanthony/slicer v1.6.0 // indirect
github.com/leaanthony/u v1.1.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/sagikazarmark/locafero v0.11.0 // indirect
github.com/samber/lo v1.49.1 // indirect
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect
github.com/spf13/afero v1.15.0 // indirect
github.com/spf13/cast v1.10.0 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tkrajina/go-reflector v0.5.8 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/wailsapp/go-webview2 v1.0.22 // indirect
github.com/wailsapp/mimetype v1.4.1 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/crypto v0.33.0 // indirect
golang.org/x/net v0.35.0 // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/text v0.28.0 // indirect
modernc.org/libc v1.22.5 // indirect
modernc.org/mathutil v1.5.0 // indirect
modernc.org/memory v1.5.0 // indirect
modernc.org/sqlite v1.23.1 // indirect
)
// replace github.com/wailsapp/wails/v2 v2.12.0 => /Users/blizzard/go/pkg/mod
+145
View File
@@ -0,0 +1,145 @@
git.sr.ht/~jackmordaunt/go-toast/v2 v2.0.3 h1:N3IGoHHp9pb6mj1cbXbuaSXV/UMKwmbKLf53nQmtqMA=
git.sr.ht/~jackmordaunt/go-toast/v2 v2.0.3/go.mod h1:QtOLZGz8olr4qH2vWK0QH0w0O4T9fEIjMuWpKUsH7nc=
github.com/bep/debounce v1.2.1 h1:v67fRdBA9UQu2NhLFXrSg0Brw7CexQekrBwDMM8bzeY=
github.com/bep/debounce v1.2.1/go.mod h1:H8yggRPQKLUhUoqrJC1bO2xNya7vanpDl7xR3ISbCJ0=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
github.com/glebarez/go-sqlite v1.21.2 h1:3a6LFC4sKahUunAmynQKLZceZCOzUthkRkEAl9gAXWo=
github.com/glebarez/go-sqlite v1.21.2/go.mod h1:sfxdZyhQjTM2Wry3gVYWaW072Ri1WMdWJi0k6+3382k=
github.com/glebarez/sqlite v1.11.0 h1:wSG0irqzP6VurnMEpFGer5Li19RpIRi2qvQz++w0GMw=
github.com/glebarez/sqlite v1.11.0/go.mod h1:h8/o8j5wiAsqSPoWELDUdJXhjAhsVliSn7bWZjOhrgQ=
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ=
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e h1:Q3+PugElBCf4PFpxhErSzU3/PY5sFL5Z6rfv4AbGAck=
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e/go.mod h1:alcuEEnZsY1WQsagKhZDsoPCRoOijYqhZvPwLG0kzVs=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/labstack/echo/v4 v4.13.3 h1:pwhpCPrTl5qry5HRdM5FwdXnhXSLSY+WE+YQSeCaafY=
github.com/labstack/echo/v4 v4.13.3/go.mod h1:o90YNEeQWjDozo584l7AwhJMHN0bOC4tAfg+Xox9q5g=
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU=
github.com/leaanthony/debme v1.2.1 h1:9Tgwf+kjcrbMQ4WnPcEIUcQuIZYqdWftzZkBr+i/oOc=
github.com/leaanthony/debme v1.2.1/go.mod h1:3V+sCm5tYAgQymvSOfYQ5Xx2JCr+OXiD9Jkw3otUjiA=
github.com/leaanthony/go-ansi-parser v1.6.1 h1:xd8bzARK3dErqkPFtoF9F3/HgN8UQk0ed1YDKpEz01A=
github.com/leaanthony/go-ansi-parser v1.6.1/go.mod h1:+vva/2y4alzVmmIEpk9QDhA7vLC5zKDTRwfZGOp3IWU=
github.com/leaanthony/gosod v1.0.4 h1:YLAbVyd591MRffDgxUOU1NwLhT9T1/YiwjKZpkNFeaI=
github.com/leaanthony/gosod v1.0.4/go.mod h1:GKuIL0zzPj3O1SdWQOdgURSuhkF+Urizzxh26t9f1cw=
github.com/leaanthony/slicer v1.6.0 h1:1RFP5uiPJvT93TAHi+ipd3NACobkW53yUiBqZheE/Js=
github.com/leaanthony/slicer v1.6.0/go.mod h1:o/Iz29g7LN0GqH3aMjWAe90381nyZlDNquK+mtH2Fj8=
github.com/leaanthony/u v1.1.1 h1:TUFjwDGlNX+WuwVEzDqQwC2lOv0P4uhTQw7CMFdiK7M=
github.com/leaanthony/u v1.1.1/go.mod h1:9+o6hejoRljvZ3BzdYlVL0JYCwtnAsVuN9pVTQcaRfI=
github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
github.com/matryer/is v1.4.1 h1:55ehd8zaGABKLXQUe2awZ99BD/PTc2ls+KV/dXphgEQ=
github.com/matryer/is v1.4.1/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/sagikazarmark/locafero v0.11.0 h1:1iurJgmM9G3PA/I+wWYIOw/5SyBtxapeHDcg+AAIFXc=
github.com/sagikazarmark/locafero v0.11.0/go.mod h1:nVIGvgyzw595SUSUE6tvCp3YYTeHs15MvlmU87WwIik=
github.com/samber/lo v1.49.1 h1:4BIFyVfuQSEpluc7Fua+j1NolZHiEHEpaSEKdsH0tew=
github.com/samber/lo v1.49.1/go.mod h1:dO6KHFzUKXgP8LDhU0oI8d2hekjXnGOu0DB8Jecxd6o=
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 h1:+jumHNA0Wrelhe64i8F6HNlS8pkoyMv5sreGx2Ry5Rw=
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8/go.mod h1:3n1Cwaq1E1/1lhQhtRK2ts/ZwZEhjcQeJQ1RuC6Q/8U=
github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I=
github.com/spf13/afero v1.15.0/go.mod h1:NC2ByUVxtQs4b3sIUphxK0NioZnmxgyCrfzeuq8lxMg=
github.com/spf13/cast v1.10.0 h1:h2x0u2shc1QuLHfxi+cTJvs30+ZAHOGRic8uyGTDWxY=
github.com/spf13/cast v1.10.0/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo=
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.21.0 h1:x5S+0EU27Lbphp4UKm1C+1oQO+rKx36vfCoaVebLFSU=
github.com/spf13/viper v1.21.0/go.mod h1:P0lhsswPGWD/1lZJ9ny3fYnVqxiegrlNrEmgLjbTCAY=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/tkrajina/go-reflector v0.5.8 h1:yPADHrwmUbMq4RGEyaOUpz2H90sRsETNVpjzo3DLVQQ=
github.com/tkrajina/go-reflector v0.5.8/go.mod h1:ECbqLgccecY5kPmPmXg1MrHW585yMcDkVl6IvJe64T4=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/wailsapp/go-webview2 v1.0.22 h1:YT61F5lj+GGaat5OB96Aa3b4QA+mybD0Ggq6NZijQ58=
github.com/wailsapp/go-webview2 v1.0.22/go.mod h1:qJmWAmAmaniuKGZPWwne+uor3AHMB5PFhqiK0Bbj8kc=
github.com/wailsapp/mimetype v1.4.1 h1:pQN9ycO7uo4vsUUuPeHEYoUkLVkaRntMnHJxVwYhwHs=
github.com/wailsapp/mimetype v1.4.1/go.mod h1:9aV5k31bBOv5z6u+QP8TltzvNGJPmNJD4XlAL3U+j3o=
github.com/wailsapp/wails/v2 v2.12.0 h1:BHO/kLNWFHYjCzucxbzAYZWUjub1Tvb4cSguQozHn5c=
github.com/wailsapp/wails/v2 v2.12.0/go.mod h1:mo1bzK1DEJrobt7YrBjgxvb5Sihb1mhAY09hppbibQg=
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
golang.org/x/net v0.0.0-20210505024714-0287a6fb4125/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
golang.org/x/sys v0.0.0-20200810151505-1b9f1253b3ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/gorm v1.31.1 h1:7CA8FTFz/gRfgqgpeKIBcervUn3xSyPUmr6B2WXJ7kg=
gorm.io/gorm v1.31.1/go.mod h1:XyQVbO2k6YkOis7C2437jSit3SsDK72s7n7rsSHd+Gs=
modernc.org/libc v1.22.5 h1:91BNch/e5B0uPbJFgqbxXuOnxBQjlS//icfQEGmvyjE=
modernc.org/libc v1.22.5/go.mod h1:jj+Z7dTNX8fBScMVNRAYZ/jF91K8fdT2hYMThc3YjBY=
modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ=
modernc.org/mathutil v1.5.0/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
modernc.org/memory v1.5.0 h1:N+/8c5rE6EqugZwHii4IFsaJ7MUhoWX07J5tC/iI5Ds=
modernc.org/memory v1.5.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU=
modernc.org/sqlite v1.23.1 h1:nrSBg4aRQQwq59JpvGEQ15tNxoO5pX/kUjcRNwSAGQM=
modernc.org/sqlite v1.23.1/go.mod h1:OrDj17Mggn6MhE+iPbBNf7RGKODDE9NFT0f3EwDzJqk=
+48
View File
@@ -0,0 +1,48 @@
package config
import (
"fmt"
"github.com/spf13/viper"
)
type DatabaseConfig struct {
DSN string `mapstructure:"dsn"`
}
type DeepSeekConfig struct {
APIKey string `mapstructure:"api_key"`
Model string `mapstructure:"model"`
TimeoutSeconds int `mapstructure:"timeout_seconds"`
MaxTokens int `mapstructure:"max_tokens"`
}
type AppConfig struct {
Database DatabaseConfig `mapstructure:"database"`
DeepSeek DeepSeekConfig `mapstructure:"deepseek"`
}
var Global AppConfig
func Load() error {
viper.SetConfigName("config")
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
viper.AddConfigPath("$HOME/.ai-expert-sidebar")
// Defaults
viper.SetDefault("database.dsn",
"root:password@tcp(127.0.0.1:3306)/ai_expert?charset=utf8mb4&parseTime=True&loc=Local")
viper.SetDefault("deepseek.api_key", "")
viper.SetDefault("deepseek.model", "deepseek-chat")
viper.SetDefault("deepseek.timeout_seconds", 60)
viper.SetDefault("deepseek.max_tokens", 1024)
if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
return fmt.Errorf("config read error: %w", err)
}
}
return viper.Unmarshal(&Global)
}
+65
View File
@@ -0,0 +1,65 @@
package crypto
import (
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"crypto/sha256"
"encoding/base64"
"fmt"
"io"
)
const appSecret = "ai-expert-sidebar-v1-local-©2026"
// deriveKey produces a 32-byte AES key from the application secret.
func deriveKey() []byte {
sum := sha256.Sum256([]byte(appSecret))
return sum[:]
}
// EncryptAPIKey encrypts a plaintext API key. Returns "" for empty input.
func EncryptAPIKey(plaintext string) (string, error) {
if plaintext == "" {
return "", nil
}
block, err := aes.NewCipher(deriveKey())
if err != nil {
return "", err
}
gcm, err := cipher.NewGCM(block)
if err != nil {
return "", err
}
nonce := make([]byte, gcm.NonceSize())
if _, err = io.ReadFull(rand.Reader, nonce); err != nil {
return "", err
}
sealed := gcm.Seal(nonce, nonce, []byte(plaintext), nil)
return base64.StdEncoding.EncodeToString(sealed), nil
}
// DecryptAPIKey decrypts a base64-encoded AES-256-GCM ciphertext. Returns "" for empty input.
func DecryptAPIKey(ciphertext64 string) (string, error) {
if ciphertext64 == "" {
return "", nil
}
data, err := base64.StdEncoding.DecodeString(ciphertext64)
if err != nil {
return "", fmt.Errorf("base64 decode: %w", err)
}
block, err := aes.NewCipher(deriveKey())
if err != nil {
return "", err
}
gcm, err := cipher.NewGCM(block)
if err != nil {
return "", err
}
ns := gcm.NonceSize()
if len(data) < ns {
return "", fmt.Errorf("ciphertext too short")
}
plain, err := gcm.Open(nil, data[:ns], data[ns:], nil)
return string(plain), err
}
+128
View File
@@ -0,0 +1,128 @@
package database
import (
"fmt"
"log"
"os"
"path/filepath"
"sync"
"github.com/glebarez/sqlite"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"AI-Expert-Sidebar/internal/models"
)
var (
mu sync.RWMutex
settingsDB *gorm.DB
activeLib *gorm.DB
activeLibNm string
DataDir string
)
// Init opens/creates the settings database ($HOME/Library/Application Support/AI-Expert-Sidebar/settings.db).
func Init() error {
dir, err := appDataDir()
if err != nil {
return err
}
DataDir = dir
if err := os.MkdirAll(dir, 0o750); err != nil {
return fmt.Errorf("create data dir: %w", err)
}
db, err := openSQLite(filepath.Join(dir, "settings.db"))
if err != nil {
return fmt.Errorf("open settings.db: %w", err)
}
if err := db.AutoMigrate(&models.AppSetting{}, &models.Library{}); err != nil {
return fmt.Errorf("migrate settings schema: %w", err)
}
mu.Lock()
settingsDB = db
mu.Unlock()
log.Printf("[DB] Settings DB ready at %s/settings.db", dir)
return nil
}
// OpenLibrary switches the active knowledge library.
func OpenLibrary(lib models.Library) error {
db, err := openSQLite(lib.FilePath)
if err != nil {
return fmt.Errorf("open library %q: %w", lib.Name, err)
}
if err := db.AutoMigrate(&models.Entry{}); err != nil {
return fmt.Errorf("migrate library %q: %w", lib.Name, err)
}
mu.Lock()
activeLib = db
activeLibNm = lib.Name
mu.Unlock()
// Persist preference
settingsDB.Exec(
"INSERT INTO app_settings(key,value) VALUES(?,?) ON CONFLICT(key) DO UPDATE SET value=excluded.value",
"active_library", lib.Name,
)
log.Printf("[DB] Active library: %s", lib.Name)
return nil
}
// NewLibraryDB creates a fresh SQLite DB at path and migrates the Entry schema.
func NewLibraryDB(path string) error {
db, err := openSQLite(path)
if err != nil {
return err
}
return db.AutoMigrate(&models.Entry{})
}
// NewLibraryDBReadOnly opens an existing SQLite DB read-only (for counting etc).
func NewLibraryDBReadOnly(path string) (*gorm.DB, error) {
return openSQLite(path + "?mode=ro")
}
// GetSettings returns the global settings DB (AppSetting + Library tables).
func GetSettings() *gorm.DB {
mu.RLock()
defer mu.RUnlock()
return settingsDB
}
// Get returns the active knowledge library DB.
func Get() *gorm.DB {
mu.RLock()
defer mu.RUnlock()
return activeLib
}
// GetActiveLibName returns the display name of the currently open library.
func GetActiveLibName() string {
mu.RLock()
defer mu.RUnlock()
return activeLibNm
}
// IsReady reports whether both the settings DB and an active library are open.
func IsReady() bool {
mu.RLock()
defer mu.RUnlock()
return settingsDB != nil && activeLib != nil
}
// ── helpers ───────────────────────────────────────────────────────────────────
func openSQLite(path string) (*gorm.DB, error) {
return gorm.Open(sqlite.Open(path), &gorm.Config{
Logger: logger.Default.LogMode(logger.Warn),
})
}
func appDataDir() (string, error) {
dir, err := os.UserConfigDir()
if err != nil {
return "", fmt.Errorf("user config dir: %w", err)
}
return filepath.Join(dir, "AI-Expert-Sidebar"), nil
}
+122
View File
@@ -0,0 +1,122 @@
package handler
import (
"context"
"fmt"
"log"
"strings"
"sync"
"AI-Expert-Sidebar/internal/database"
"AI-Expert-Sidebar/internal/service"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
// Expert handles search and AI streaming for the active library.
type Expert struct {
ctx context.Context
stopMu sync.Mutex
stopCancel context.CancelFunc
}
func NewExpert() *Expert { return &Expert{} }
func (e *Expert) SetContext(ctx context.Context) { e.ctx = ctx }
// SearchExpert fuzzy-searches the active knowledge library.
func (e *Expert) SearchExpert(query string) []service.SearchResult {
results, err := service.SearchKnowledge(query)
if err != nil {
log.Printf("[SearchExpert] %v", err)
return nil
}
return results
}
// AskDeepSeek performs RAG + streaming AI call.
func (e *Expert) AskDeepSeek(query, rawAnswer string) string {
aiCfg := service.ResolveAIConfig()
knowledgeCtx := e.buildKnowledgeContext(query)
var userMsg string
if rawAnswer != "" {
userMsg = fmt.Sprintf("用户问题:%s\n\n原始参考答案:%s", query, rawAnswer)
} else {
userMsg = fmt.Sprintf("用户问题:%s\n\n请直接回答上述问题。", query)
}
messages := service.BuildRAGMessages(knowledgeCtx, userMsg, aiCfg.SystemPrompt)
streamCh := make(chan string, 64)
var sb strings.Builder
streamCtx, cancel := context.WithCancel(e.ctx)
e.setStopCancel(cancel)
go func() {
defer func() { cancel(); close(streamCh) }()
if err := service.CallDeepSeekStream(streamCtx, aiCfg, messages, streamCh); err != nil {
if streamCtx.Err() == context.Canceled {
streamCh <- "__STOPPED__"
} else {
log.Printf("[AskDeepSeek] %v", err)
streamCh <- "__ERROR__"
}
}
}()
for chunk := range streamCh {
switch chunk {
case "__ERROR__":
runtime.EventsEmit(e.ctx, "ai:fallback", rawAnswer)
return rawAnswer
case "__STOPPED__":
runtime.EventsEmit(e.ctx, "ai:done", sb.String())
return sb.String()
default:
sb.WriteString(chunk)
runtime.EventsEmit(e.ctx, "ai:chunk", chunk)
}
}
runtime.EventsEmit(e.ctx, "ai:done", sb.String())
return sb.String()
}
func (e *Expert) StopGeneration() {
e.stopMu.Lock()
defer e.stopMu.Unlock()
if e.stopCancel != nil {
e.stopCancel()
e.stopCancel = nil
}
}
func (e *Expert) GetDBStatus() bool { return database.IsReady() }
func (e *Expert) ToggleTopmost(enabled bool) {
runtime.WindowSetAlwaysOnTop(e.ctx, enabled)
}
func (e *Expert) buildKnowledgeContext(query string) string {
results, err := service.SearchKnowledge(query)
if err != nil || len(results) == 0 {
return "(无相关本地知识)"
}
limit := 3
if len(results) < limit {
limit = len(results)
}
var sb strings.Builder
for i := 0; i < limit; i++ {
r := results[i]
sb.WriteString(fmt.Sprintf("%d. Q: %s\n A: %s\n 分类: %s\n", i+1, r.Question, r.Answer, r.Category))
}
return sb.String()
}
func (e *Expert) setStopCancel(fn context.CancelFunc) {
e.stopMu.Lock()
defer e.stopMu.Unlock()
if e.stopCancel != nil {
e.stopCancel()
}
e.stopCancel = fn
}
+94
View File
@@ -0,0 +1,94 @@
package handler
import (
"context"
"AI-Expert-Sidebar/internal/database"
"AI-Expert-Sidebar/internal/service"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
// LibraryHandler exposes library management and CSV import via Wails bindings.
type LibraryHandler struct{ ctx context.Context }
func NewLibraryHandler() *LibraryHandler { return &LibraryHandler{} }
func (h *LibraryHandler) SetContext(ctx context.Context) { h.ctx = ctx }
// ListLibraries returns all registered knowledge libraries.
func (h *LibraryHandler) ListLibraries() []LibraryInfo {
libs, err := service.ListLibraries()
if err != nil {
return nil
}
out := make([]LibraryInfo, len(libs))
for i, l := range libs {
out[i] = LibraryInfo{
ID: l.ID, Name: l.Name, Description: l.Description,
EntryCount: l.EntryCount, IsActive: l.Name == database.GetActiveLibName(),
}
}
return out
}
// GetActiveLibrary returns the name of the currently active library.
func (h *LibraryHandler) GetActiveLibrary() string {
return database.GetActiveLibName()
}
// CreateLibrary registers a new knowledge library.
func (h *LibraryHandler) CreateLibrary(name, description string) string {
if name == "" {
return "名称不能为空"
}
lib, err := service.CreateLibrary(name, description)
if err != nil {
return err.Error()
}
// Auto-switch to newly created library
service.SwitchLibrary(lib.Name) //nolint
return ""
}
// SwitchLibrary makes the named library active.
func (h *LibraryHandler) SwitchLibrary(name string) string {
if err := service.SwitchLibrary(name); err != nil {
return err.Error()
}
return ""
}
// DeleteLibrary removes a library from the registry (file is kept).
func (h *LibraryHandler) DeleteLibrary(name string) string {
if name == database.GetActiveLibName() {
return "不能删除当前使用中的知识库,请先切换到其他库"
}
if err := service.DeleteLibrary(name, false); err != nil {
return err.Error()
}
return ""
}
// ImportCSV opens a native file dialog then imports CSV data into the active library.
func (h *LibraryHandler) ImportCSV() service.ImportResult {
filePath, err := runtime.OpenFileDialog(h.ctx, runtime.OpenDialogOptions{
Title: "选择 CSV 文件",
Filters: []runtime.FileFilter{
{DisplayName: "CSV 文件", Pattern: "*.csv"},
{DisplayName: "所有文件", Pattern: "*"},
},
})
if err != nil || filePath == "" {
return service.ImportResult{Error: "已取消"}
}
return service.ImportCSV(filePath)
}
// LibraryInfo is the frontend-facing representation of a library.
type LibraryInfo struct {
ID uint `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
EntryCount int `json:"entry_count"`
IsActive bool `json:"is_active"`
}
+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"`
}
+16
View File
@@ -0,0 +1,16 @@
package models
import "time"
// Entry is a single Q&A row in a knowledge library .db file.
type Entry struct {
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
Keyword string `gorm:"index;size:255;not null" json:"keyword"`
Question string `gorm:"type:text;not null" json:"question"`
Answer string `gorm:"type:text;not null" json:"answer"`
Category string `gorm:"size:100;default:'通用'" json:"category"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (Entry) TableName() string { return "entries" }
+25
View File
@@ -0,0 +1,25 @@
package models
import "time"
// AppSetting is a key-value store for global application settings
// (AI provider, endpoint, API key, etc.) in settings.db.
type AppSetting struct {
Key string `gorm:"primaryKey;size:100" json:"key"`
Value string `gorm:"type:text" json:"value"`
}
func (AppSetting) TableName() string { return "app_settings" }
// Library represents a registered knowledge library in settings.db.
// Each library is a separate SQLite file.
type Library struct {
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
Name string `gorm:"uniqueIndex;size:100;not null" json:"name"`
Description string `gorm:"size:255" json:"description"`
FilePath string `gorm:"size:1024;not null" json:"file_path"`
EntryCount int `gorm:"-" json:"entry_count"` // populated on read
CreatedAt time.Time `json:"created_at"`
}
func (Library) TableName() string { return "libraries" }
+145
View File
@@ -0,0 +1,145 @@
package service
import (
"bufio"
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"strings"
"time"
)
// AICallConfig holds the resolved configuration for a single AI API call.
type AICallConfig struct {
BaseURL string
APIKey string
Model string
MaxTokens int
SystemPrompt string
}
// ── Request / Response types (OpenAI-compatible format) ──────────────────────
type dsMessage struct {
Role string `json:"role"`
Content string `json:"content"`
}
type dsRequest struct {
Model string `json:"model"`
Messages []dsMessage `json:"messages"`
Stream bool `json:"stream"`
MaxTokens int `json:"max_tokens,omitempty"`
}
type dsDelta struct {
Content string `json:"content"`
}
type dsChoice struct {
Delta dsDelta `json:"delta"`
FinishReason string `json:"finish_reason"`
}
type dsSSELine struct {
Choices []dsChoice `json:"choices"`
}
// ── Public API ────────────────────────────────────────────────────────────────
// CallDeepSeekStream sends a messages list to any OpenAI-compatible endpoint
// defined in cfg, with stream:true. Pushes each delta content chunk to streamCh.
func CallDeepSeekStream(ctx context.Context, cfg AICallConfig, messages []dsMessage, streamCh chan<- string) error {
if cfg.APIKey == "" {
return fmt.Errorf("API key 未配置,请在设置中填写或联系管理员")
}
payload := dsRequest{
Model: cfg.Model,
Messages: messages,
Stream: true,
MaxTokens: cfg.MaxTokens,
}
body, err := json.Marshal(payload)
if err != nil {
return fmt.Errorf("marshal request: %w", err)
}
client := &http.Client{Timeout: 60 * time.Second}
req, err := http.NewRequestWithContext(ctx, http.MethodPost, cfg.BaseURL, bytes.NewReader(body))
if err != nil {
return fmt.Errorf("build request: %w", err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "text/event-stream")
req.Header.Set("Authorization", "Bearer "+cfg.APIKey)
resp, err := client.Do(req)
if err != nil {
if ctx.Err() != nil {
return ctx.Err()
}
return fmt.Errorf("http request: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
errBody, _ := io.ReadAll(resp.Body)
return fmt.Errorf("upstream status %d: %s", resp.StatusCode, string(errBody))
}
return parseDeepSeekSSE(ctx, resp.Body, streamCh)
}
// BuildRAGMessages constructs the OpenAI-compatible messages slice.
// If customSystemPrompt is non-empty, it replaces the built-in RAG template.
func BuildRAGMessages(knowledgeContext, userQuery, customSystemPrompt string) []dsMessage {
var systemContent string
if customSystemPrompt != "" {
systemContent = customSystemPrompt
if knowledgeContext != "" && knowledgeContext != "(无相关本地知识)" {
systemContent += "\n\n以下是本地知识库中的相关内容供参考:\n---\n" + knowledgeContext + "\n---"
}
} else {
systemContent = fmt.Sprintf(
"你是一位专业的植物养护和客服顾问,擅长用温暖、自然、有亲和力的语气沟通。\n\n"+
"以下是来自本地知识库的相关内容,请优先参考:\n\n---\n%s\n---\n\n"+
"根据以上知识润色话术,直接输出内容,不加前缀或解释。",
knowledgeContext,
)
}
return []dsMessage{
{Role: "system", Content: systemContent},
{Role: "user", Content: userQuery},
}
}
func parseDeepSeekSSE(ctx context.Context, body io.Reader, ch chan<- string) error {
scanner := bufio.NewScanner(body)
scanner.Buffer(make([]byte, 64*1024), 64*1024)
for scanner.Scan() {
if ctx.Err() != nil {
return ctx.Err()
}
line := scanner.Text()
if !strings.HasPrefix(line, "data:") {
continue
}
data := strings.TrimSpace(strings.TrimPrefix(line, "data:"))
if data == "[DONE]" {
break
}
var event dsSSELine
if err := json.Unmarshal([]byte(data), &event); err != nil {
continue
}
if len(event.Choices) > 0 {
if chunk := event.Choices[0].Delta.Content; chunk != "" {
ch <- chunk
}
}
}
return scanner.Err()
}
+90
View File
@@ -0,0 +1,90 @@
package service
import (
"encoding/csv"
"fmt"
"io"
"os"
"strings"
"AI-Expert-Sidebar/internal/database"
"AI-Expert-Sidebar/internal/models"
)
// ImportResult summarises the outcome of a CSV import.
type ImportResult struct {
Imported int `json:"imported"`
Skipped int `json:"skipped"`
Error string `json:"error,omitempty"`
}
// ImportCSV reads a CSV file and inserts records into the active knowledge library.
//
// Required columns (case-insensitive): keyword, question, answer
// Optional column: category (defaults to "通用")
//
// The first row must be the header.
func ImportCSV(filePath string) ImportResult {
f, err := os.Open(filePath)
if err != nil {
return ImportResult{Error: fmt.Sprintf("无法打开文件: %v", err)}
}
defer f.Close()
db := database.Get()
if db == nil {
return ImportResult{Error: "知识库未初始化"}
}
r := csv.NewReader(f)
r.TrimLeadingSpace = true
r.LazyQuotes = true
// Read and normalise header
header, err := r.Read()
if err != nil {
return ImportResult{Error: fmt.Sprintf("读取表头失败: %v", err)}
}
colIdx := make(map[string]int)
for i, h := range header {
colIdx[strings.ToLower(strings.TrimSpace(h))] = i
}
for _, required := range []string{"keyword", "question", "answer"} {
if _, ok := colIdx[required]; !ok {
return ImportResult{Error: fmt.Sprintf("CSV 缺少必需列: %q (需要: keyword, question, answer)", required)}
}
}
catIdx, hasCat := colIdx["category"]
var imported, skipped int
for {
row, err := r.Read()
if err == io.EOF {
break
}
if err != nil {
skipped++
continue
}
keyword := strings.TrimSpace(row[colIdx["keyword"]])
question := strings.TrimSpace(row[colIdx["question"]])
answer := strings.TrimSpace(row[colIdx["answer"]])
if keyword == "" || question == "" || answer == "" {
skipped++
continue
}
cat := "通用"
if hasCat && catIdx < len(row) {
if v := strings.TrimSpace(row[catIdx]); v != "" {
cat = v
}
}
entry := models.Entry{Keyword: keyword, Question: question, Answer: answer, Category: cat}
if err := db.Create(&entry).Error; err != nil {
skipped++
} else {
imported++
}
}
return ImportResult{Imported: imported, Skipped: skipped}
}
+131
View File
@@ -0,0 +1,131 @@
package service
import (
"fmt"
"log"
"os"
"path/filepath"
"time"
"AI-Expert-Sidebar/internal/database"
"AI-Expert-Sidebar/internal/models"
)
// ListLibraries returns all registered knowledge libraries with entry counts.
func ListLibraries() ([]models.Library, error) {
sdb := database.GetSettings()
if sdb == nil {
return nil, fmt.Errorf("settings DB not ready")
}
var libs []models.Library
if err := sdb.Order("created_at asc").Find(&libs).Error; err != nil {
return nil, err
}
// Populate entry count for each library
for i, lib := range libs {
libs[i].EntryCount = countEntries(lib.FilePath)
}
return libs, nil
}
// CreateLibrary registers a new knowledge library and creates its SQLite file.
func CreateLibrary(name, description string) (*models.Library, error) {
sdb := database.GetSettings()
dir := database.DataDir
fileName := sanitizeFileName(name) + ".db"
filePath := filepath.Join(dir, fileName)
// Ensure uniqueness of file path
if _, err := os.Stat(filePath); err == nil {
filePath = filepath.Join(dir, sanitizeFileName(name)+"_"+fmt.Sprintf("%d", time.Now().Unix())+".db")
}
if err := database.NewLibraryDB(filePath); err != nil {
return nil, fmt.Errorf("create library DB: %w", err)
}
lib := models.Library{Name: name, Description: description, FilePath: filePath}
if err := sdb.Create(&lib).Error; err != nil {
os.Remove(filePath) // rollback file
return nil, err
}
log.Printf("[Library] Created: %s → %s", name, filePath)
return &lib, nil
}
// SwitchLibrary makes the named library active.
func SwitchLibrary(name string) error {
sdb := database.GetSettings()
var lib models.Library
if err := sdb.Where("name = ?", name).First(&lib).Error; err != nil {
return fmt.Errorf("library %q not found", name)
}
return database.OpenLibrary(lib)
}
// DeleteLibrary removes a library from the registry (and optionally its file).
func DeleteLibrary(name string, deleteFile bool) error {
sdb := database.GetSettings()
var lib models.Library
if err := sdb.Where("name = ?", name).First(&lib).Error; err != nil {
return fmt.Errorf("library %q not found", name)
}
if err := sdb.Delete(&lib).Error; err != nil {
return err
}
if deleteFile {
return os.Remove(lib.FilePath)
}
return nil
}
// InitLibraries restores the last active library or creates the default one.
func InitLibraries() error {
sdb := database.GetSettings()
// Check active_library preference
var setting models.AppSetting
if sdb.Where("key = ?", "active_library").First(&setting).Error == nil {
if err := SwitchLibrary(setting.Value); err == nil {
return nil // restored successfully
}
}
// No preference or stale — find first library
var lib models.Library
if sdb.Order("created_at asc").First(&lib).Error == nil {
return database.OpenLibrary(lib)
}
// No libraries at all — create default
lib2, err := CreateLibrary("默认知识库", "自动创建的默认知识库")
if err != nil {
return err
}
return database.OpenLibrary(*lib2)
}
// ── helpers ───────────────────────────────────────────────────────────────────
func countEntries(filePath string) int {
db, err := database.NewLibraryDBReadOnly(filePath)
if err != nil {
return -1
}
var count int64
db.Model(&models.Entry{}).Count(&count)
return int(count)
}
func sanitizeFileName(name string) string {
result := make([]rune, 0, len(name))
for _, r := range name {
if r == '/' || r == '\\' || r == ':' || r == '*' || r == '?' || r == '"' || r == '<' || r == '>' || r == '|' {
result = append(result, '_')
} else {
result = append(result, r)
}
}
if len(result) == 0 {
return "library"
}
return string(result)
}
+114
View File
@@ -0,0 +1,114 @@
package service
import (
"errors"
"log"
"AI-Expert-Sidebar/internal/database"
"AI-Expert-Sidebar/internal/models"
)
const maxResults = 5
var ErrDBUnavailable = errors.New("database unavailable")
// SearchResult is the DTO returned to the frontend.
type SearchResult struct {
ID uint `json:"id"`
Question string `json:"question"`
Answer string `json:"answer"`
Category string `json:"category"`
Score int `json:"score"` // 2=keyword, 1=question, 0=fallback
IsFallback bool `json:"is_fallback"`
}
// SearchKnowledge performs fuzzy search in the active knowledge library.
func SearchKnowledge(query string) ([]SearchResult, error) {
db := database.Get()
if db == nil {
return nil, ErrDBUnavailable
}
if len(query) < 1 {
return nil, nil
}
type res struct {
rows []SearchResult
err error
}
ch := make(chan res, 1)
go func() {
var total int64
db.Model(&models.Entry{}).Count(&total)
if total == 0 {
ch <- res{[]SearchResult{}, nil}
return
}
like := "%" + query + "%"
var rows []models.Entry
err := db.Where("keyword LIKE ? OR question LIKE ?", like, like).
Order("updated_at DESC").Limit(maxResults).Find(&rows).Error
if err != nil {
ch <- res{nil, err}
return
}
isFallback := len(rows) == 0
if isFallback {
log.Printf("[Search] No match for %q, returning fallback", query)
db.Order("updated_at DESC").Limit(3).Find(&rows)
}
out := make([]SearchResult, 0, len(rows))
for _, r := range rows {
score := 0
if !isFallback {
if containsIgnoreCase(r.Keyword, query) {
score = 2
} else if containsIgnoreCase(r.Question, query) {
score = 1
}
}
out = append(out, SearchResult{
ID: r.ID, Question: r.Question, Answer: r.Answer,
Category: r.Category, Score: score, IsFallback: isFallback,
})
}
ch <- res{out, nil}
}()
r := <-ch
return r.rows, r.err
}
func containsIgnoreCase(s, sub string) bool {
if len(sub) == 0 {
return true
}
sl, subl := []rune(s), []rune(sub)
if len(sl) < len(subl) {
return false
}
for i := 0; i <= len(sl)-len(subl); i++ {
match := true
for j, c := range subl {
if toLower(sl[i+j]) != toLower(c) {
match = false
break
}
}
if match {
return true
}
}
return false
}
func toLower(r rune) rune {
if r >= 'A' && r <= 'Z' {
return r + 32
}
return r
}
+131
View File
@@ -0,0 +1,131 @@
package service
import (
"fmt"
"AI-Expert-Sidebar/internal/config"
"AI-Expert-Sidebar/internal/crypto"
"AI-Expert-Sidebar/internal/database"
"AI-Expert-Sidebar/internal/models"
)
// SettingsDTO is what the frontend reads and writes.
type SettingsDTO struct {
AIProvider string `json:"ai_provider"`
BaseURL string `json:"base_url"`
APIKey string `json:"api_key"`
Model string `json:"model"`
SystemPrompt string `json:"system_prompt"`
MaxTokens int `json:"max_tokens"`
UsePublicKey bool `json:"use_public_key"`
}
// GetSettings reads AI config from settings.db key-value store.
func GetSettings() *SettingsDTO {
sdb := database.GetSettings()
if sdb == nil {
return defaultDTO()
}
var rows []models.AppSetting
sdb.Find(&rows)
m := make(map[string]string, len(rows))
for _, r := range rows {
m[r.Key] = r.Value
}
apiKey, _ := crypto.DecryptAPIKey(m["api_key_encrypted"])
maxTokens := 1024
fmt.Sscanf(m["max_tokens"], "%d", &maxTokens)
if maxTokens <= 0 {
maxTokens = 1024
}
return &SettingsDTO{
AIProvider: strOr(m["ai_provider"], "deepseek"),
BaseURL: m["base_url"],
APIKey: apiKey,
Model: strOr(m["model"], "deepseek-chat"),
SystemPrompt: m["system_prompt"],
MaxTokens: maxTokens,
UsePublicKey: m["use_public_key"] != "false",
}
}
// SaveSettings persists AI config into settings.db.
func SaveSettings(dto SettingsDTO) error {
sdb := database.GetSettings()
if sdb == nil {
return fmt.Errorf("settings DB not ready")
}
upsert := func(k, v string) {
sdb.Exec("INSERT INTO app_settings(key,value) VALUES(?,?) ON CONFLICT(key) DO UPDATE SET value=excluded.value", k, v)
}
upsert("ai_provider", dto.AIProvider)
upsert("base_url", dto.BaseURL)
upsert("model", dto.Model)
upsert("system_prompt", dto.SystemPrompt)
upsert("max_tokens", fmt.Sprintf("%d", dto.MaxTokens))
usePublic := "true"
if !dto.UsePublicKey {
usePublic = "false"
}
upsert("use_public_key", usePublic)
if !dto.UsePublicKey && dto.APIKey != "" {
enc, err := crypto.EncryptAPIKey(dto.APIKey)
if err != nil {
return err
}
upsert("api_key_encrypted", enc)
}
return nil
}
// ResolveAIConfig returns the effective AI call config (local settings or global fallback).
func ResolveAIConfig() AICallConfig {
base := AICallConfig{
BaseURL: "https://api.deepseek.com/chat/completions",
APIKey: config.Global.DeepSeek.APIKey,
Model: config.Global.DeepSeek.Model,
MaxTokens: config.Global.DeepSeek.MaxTokens,
}
dto := GetSettings()
if dto == nil {
return base
}
base.SystemPrompt = dto.SystemPrompt
if dto.UsePublicKey || dto.APIKey == "" {
return base
}
providerURL := dto.BaseURL
if providerURL == "" {
switch dto.AIProvider {
case "deepseek":
providerURL = "https://api.deepseek.com/chat/completions"
case "openai":
providerURL = "https://api.openai.com/v1/chat/completions"
case "grok":
providerURL = "https://api.x.ai/v1/chat/completions"
}
}
maxTok := dto.MaxTokens
if maxTok <= 0 {
maxTok = 1024
}
return AICallConfig{
BaseURL: strOr(providerURL, base.BaseURL),
APIKey: dto.APIKey,
Model: strOr(dto.Model, base.Model),
MaxTokens: maxTok,
SystemPrompt: dto.SystemPrompt,
}
}
func strOr(v, def string) string {
if v == "" {
return def
}
return v
}
func defaultDTO() *SettingsDTO {
return &SettingsDTO{AIProvider: "deepseek", Model: "deepseek-chat", MaxTokens: 1024, UsePublicKey: true}
}
+47
View File
@@ -0,0 +1,47 @@
package main
import (
"embed"
"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/options"
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
"github.com/wailsapp/wails/v2/pkg/options/mac"
)
//go:embed all:frontend/dist
var assets embed.FS
func main() {
app := NewApp()
err := wails.Run(&options.App{
Title: "AI Expert Sidebar",
Width: 350,
Height: 700,
MinWidth: 300,
MinHeight: 500,
Frameless: true,
AlwaysOnTop: true,
BackgroundColour: &options.RGBA{R: 0, G: 0, B: 0, A: 1},
AssetServer: &assetserver.Options{
Assets: assets,
},
Mac: &mac.Options{
WebviewIsTransparent: true,
WindowIsTranslucent: true,
TitleBar: mac.TitleBarHiddenInset(),
},
OnStartup: app.startup,
Bind: []interface{}{
app,
},
})
if err != nil {
println("Error:", err.Error())
}
}
+38
View File
@@ -0,0 +1,38 @@
-- AI Expert Sidebar — Demo Seed Data
-- Run: mysql -u root -p ai_expert < seed.sql
CREATE DATABASE IF NOT EXISTS ai_expert CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
USE ai_expert;
INSERT INTO knowledge_base (keyword, question, answer, category, created_at, updated_at) VALUES
('退款', '我想申请退款怎么操作?',
'您好!退款申请非常简单,请在订单页面点击"申请退款"按钮,填写退款原因后提交即可。正常情况下 1-3 个工作日退回原支付方式,请放心等待。如有疑问随时联系我们哦~',
'退款', NOW(), NOW()),
('物流', '我的快递什么时候到?',
'您好!您的订单已发货,预计 2-3 个工作日送达。您可以在"我的订单"中查看实时物流信息。若超过预计时间未到请及时联系我们,我们第一时间帮您跟进哦!',
'物流', NOW(), NOW()),
('质量', '收到商品有质量问题怎么办?',
'非常抱歉给您带来不好的购物体验!收到有质量问题的商品,请拍照发给我们,我们承诺 48 小时内为您安排补发或全额退款,完全保障您的权益!',
'产品', NOW(), NOW()),
('优惠券', '优惠券怎么使用?',
'您好!优惠券使用超简单:在结算页面的"优惠券"栏选择可用券,系统自动抵扣金额。注意查看券的有效期和适用范围哦,有任何不清楚欢迎随时问我!',
'促销', NOW(), NOW()),
('尺寸', '衣服尺码怎么选?',
'亲,我们的尺码表在商品详情页可以找到,建议对照您的身高体重选择。如果您在 M 和 L 之间拿不定主意,偏瘦建议选 M,正常或偏胖建议选 L。有疑问可以告诉我您的身高体重,我帮您推荐!',
'产品', NOW(), NOW()),
('发票', '可以开发票吗?',
'当然可以!我们支持开具电子普通发票和增值税专用发票。请在下单时备注您的开票信息(公司名称/税号),或者订单完成后在订单详情页申请,一般 3 个工作日内发送到您的邮箱。',
'通用', NOW(), NOW()),
('积分', '积分怎么兑换?',
'您好!您的积分可以在"我的账户→积分中心"中查看和兑换。100 积分 = 1 元优惠,可直接抵扣购物金额。积分活动不定期推送,记得关注我们哦!',
'促销', NOW(), NOW()),
('货到付款', '支持货到付款吗?',
'非常遗憾,目前我们暂不支持货到付款,支持微信支付、支付宝、银行卡等多种线上支付方式。如有任何支付问题随时联系我,我来帮您解决!',
'通用', NOW(), NOW());
+13
View File
@@ -0,0 +1,13 @@
{
"$schema": "https://wails.io/schemas/config.v2.json",
"name": "AI-Expert-Sidebar",
"outputfilename": "AI-Expert-Sidebar",
"frontend:install": "npm install",
"frontend:build": "npm run build",
"frontend:dev:watcher": "npm run dev",
"frontend:dev:serverUrl": "auto",
"author": {
"name": "Blizzard",
"email": "blizzardzhang@icloud.com"
}
}