fix: 搜索走 SearXNG + 工具调用分页修复

- ai-core DevTools 启动配置补充 SEARXNG_URL,避免回退到 DuckDuckGo 导致超时
- 工具调用 API 加入 offset 分页,修复 page 参数不生效问题
- 响应新增 total_pages 字段,修复前端分页栏不渲染

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-26 20:58:37 +08:00
parent dffaf7e123
commit 12e9f7da6e
3 changed files with 38 additions and 21 deletions
+13 -7
View File
@@ -397,19 +397,25 @@ func main() {
if limit > 500 { if limit > 500 {
limit = 500 limit = 500
} }
calls := toolRegistry.GetCallLogs(toolName, limit) page, _ := strconv.Atoi(r.URL.Query().Get("page"))
if calls == nil {
calls = []plgManager.CallLogRecord{}
}
page, _ := strconv.Atoi(r.URL.Query().Get("page"))
if page < 1 { if page < 1 {
page = 1 page = 1
} }
offset := (page - 1) * limit
calls, total := toolRegistry.GetCallLogs(toolName, limit, offset)
if calls == nil {
calls = []plgManager.CallLogRecord{}
}
totalPages := total / limit
if total%limit != 0 {
totalPages++
}
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]interface{}{ json.NewEncoder(w).Encode(map[string]interface{}{
"calls": calls, "total": len(calls), "page": page, "limit": limit, "calls": calls, "total": total, "total_pages": totalPages,
"page": page, "limit": limit,
})
}) })
})
// 工具调用统计 // 工具调用统计
mux.HandleFunc("/api/v1/tools/calls/stats", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/api/v1/tools/calls/stats", func(w http.ResponseWriter, r *http.Request) {
+24 -14
View File
@@ -230,25 +230,35 @@ func (r *ToolRegistry) UnregisterAll(toolIDs []string) {
} }
} }
// GetCallLogs 获取工具调用记录(最新在前,支持按工具名过滤) // GetCallLogs 获取工具调用记录(最新在前,支持按工具名过滤、分页
func (r *ToolRegistry) GetCallLogs(toolName string, limit int) []CallLogRecord { func (r *ToolRegistry) GetCallLogs(toolName string, limit, offset int) ([]CallLogRecord, int) {
all := r.callLog.getAll() all := r.callLog.getAll()
// 过滤
var filtered []CallLogRecord
if toolName == "" { if toolName == "" {
if limit > 0 && limit < len(all) { filtered = all
return all[:limit] } else {
} filtered = make([]CallLogRecord, 0)
return all for _, rec := range all {
} if rec.ToolName == toolName {
filtered := make([]CallLogRecord, 0) filtered = append(filtered, rec)
for _, rec := range all {
if rec.ToolName == toolName {
filtered = append(filtered, rec)
if limit > 0 && len(filtered) >= limit {
break
} }
} }
} }
return filtered
total := len(filtered)
// 分页
if offset >= len(filtered) {
return []CallLogRecord{}, total
}
page := filtered[offset:]
if limit > 0 && limit < len(page) {
page = page[:limit]
}
return page, total
} }
// GetCallStats 获取工具调用统计 // GetCallStats 获取工具调用统计
+1
View File
@@ -68,6 +68,7 @@ export const SERVICES = {
env: { env: {
AI_CORE_PORT: '8081', AI_CORE_PORT: '8081',
PERSONA_DIR: './internal/persona', PERSONA_DIR: './internal/persona',
SEARXNG_URL: process.env.SEARXNG_URL || 'http://localhost:8088',
IOT_SERVICE_URL: process.env.IOT_SERVICE_URL || process.env.IOT_DEBUG_SERVICE_URL || 'http://localhost:8083', IOT_SERVICE_URL: process.env.IOT_SERVICE_URL || process.env.IOT_DEBUG_SERVICE_URL || 'http://localhost:8083',
ENABLE_BACKGROUND_THINKING: process.env.ENABLE_BACKGROUND_THINKING || 'true', ENABLE_BACKGROUND_THINKING: process.env.ENABLE_BACKGROUND_THINKING || 'true',
}, },