mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-06-07 15:09:34 +08:00
🐛 fix(ai/wails-binding): 修复生命周期绑定生成类型错误
- 收敛 App 与 AI Service 的内部生命周期方法,避免被 Wails 误导出到前端 - 将启动初始化改为包级生命周期接线,保持主程序启动流程不变 - 隐藏内部清理方法,移除生成绑定中的无效 context/time 类型声明 - 同步更新 frontend/wailsjs 绑定文件,清理 Service 与 App 的错误导出 - 调整相关测试调用,确保内部方法重命名后行为一致
This commit is contained in:
@@ -31,7 +31,7 @@ type Service struct {
|
||||
safetyLevel ai.SQLPermissionLevel
|
||||
contextLevel ai.ContextLevel
|
||||
guard *safety.Guard
|
||||
configDir string // 配置存储目录
|
||||
configDir string // 配置存储目录
|
||||
cancelFuncs map[string]context.CancelFunc // 记录每个 session 的 context 取消函数
|
||||
}
|
||||
|
||||
@@ -56,8 +56,13 @@ func NewService() *Service {
|
||||
}
|
||||
}
|
||||
|
||||
// Startup Wails 生命周期回调
|
||||
func (s *Service) Startup(ctx context.Context) {
|
||||
// InitializeLifecycle attaches runtime context without exposing lifecycle internals to Wails bindings.
|
||||
func InitializeLifecycle(s *Service, ctx context.Context) {
|
||||
s.startup(ctx)
|
||||
}
|
||||
|
||||
// startup Wails 生命周期回调
|
||||
func (s *Service) startup(ctx context.Context) {
|
||||
s.ctx = ctx
|
||||
s.configDir = resolveConfigDir()
|
||||
s.loadConfig()
|
||||
@@ -588,8 +593,8 @@ func (s *Service) AIChatSend(messages []ai.Message, tools []ai.Tool) map[string]
|
||||
}
|
||||
|
||||
return map[string]interface{}{
|
||||
"success": true,
|
||||
"content": resp.Content,
|
||||
"success": true,
|
||||
"content": resp.Content,
|
||||
"tool_calls": resp.ToolCalls,
|
||||
"tokensUsed": map[string]int{
|
||||
"promptTokens": resp.TokensUsed.PromptTokens,
|
||||
|
||||
@@ -64,9 +64,14 @@ func NewApp() *App {
|
||||
}
|
||||
}
|
||||
|
||||
// Startup is called when the app starts. The context is saved
|
||||
// so we can call the runtime methods
|
||||
func (a *App) Startup(ctx context.Context) {
|
||||
// InitializeLifecycle attaches runtime context without exposing lifecycle internals to Wails bindings.
|
||||
func InitializeLifecycle(a *App, ctx context.Context) {
|
||||
a.startup(ctx)
|
||||
}
|
||||
|
||||
// startup is called when the app starts. The context is saved
|
||||
// so we can call the runtime methods.
|
||||
func (a *App) startup(ctx context.Context) {
|
||||
a.ctx = ctx
|
||||
a.startedAt = time.Now()
|
||||
logger.Init()
|
||||
@@ -700,8 +705,8 @@ func (a *App) CancelQuery(queryID string) connection.QueryResult {
|
||||
return connection.QueryResult{Success: false, Message: "查询不存在或已完成"}
|
||||
}
|
||||
|
||||
// CleanupStaleQueries removes queries older than maxAge
|
||||
func (a *App) CleanupStaleQueries(maxAge time.Duration) {
|
||||
// cleanupStaleQueries removes queries older than maxAge.
|
||||
func (a *App) cleanupStaleQueries(maxAge time.Duration) {
|
||||
a.queryMu.Lock()
|
||||
defer a.queryMu.Unlock()
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ func TestCleanupStaleQueries(t *testing.T) {
|
||||
app.queryMu.Unlock()
|
||||
|
||||
// Cleanup queries older than 1 hour
|
||||
app.CleanupStaleQueries(1 * time.Hour)
|
||||
app.cleanupStaleQueries(1 * time.Hour)
|
||||
|
||||
// Verify stale query was removed
|
||||
app.queryMu.Lock()
|
||||
@@ -110,7 +110,7 @@ func TestCleanupStaleQueries(t *testing.T) {
|
||||
defer cancel2()
|
||||
|
||||
// Cleanup queries older than 1 hour
|
||||
app.CleanupStaleQueries(1 * time.Hour)
|
||||
app.cleanupStaleQueries(1 * time.Hour)
|
||||
|
||||
// Verify fresh query still exists
|
||||
app.queryMu.Lock()
|
||||
|
||||
Reference in New Issue
Block a user