From 89122e2170b4c1e9f58693952bc5ea8df0a06c80 Mon Sep 17 00:00:00 2001 From: Meleki Date: Fri, 13 Mar 2026 08:26:15 +0100 Subject: [PATCH] feat: GitHub Code Search als Agent-Tool + Dashboard-Badges MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - UseGitHubSearch Property im AgentRecord (Default: false) - DB-Migration: use_github_search Spalte in agents - Checkbox im Agent-Formular (Standard: unchecked) - Tool nur aktiv wenn Agent-Checkbox UND GitHubToken konfiguriert - includeGitHubSearch Parameter durch StreamChat/AddToolsToPayload - Dashboard-Badges: 🔮 Auto-Kontext + 🐙 GitHub Search --- Endpoints/AgentEndpoint.cs | 3 +++ Endpoints/ChatEndpoint.cs | 2 +- Models/AgentRecord.cs | 1 + Services/AnthropicService.cs | 6 +++--- Services/ChatService.cs | 2 +- Services/DatabaseService.Agents.cs | 6 +++--- Services/DatabaseService.cs | 1 + wwwroot/index.html | 4 ++++ wwwroot/js/cards.js | 2 ++ wwwroot/js/pages/agent-page.js | 3 +++ 10 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Endpoints/AgentEndpoint.cs b/Endpoints/AgentEndpoint.cs index 2d56646..0dca9e7 100644 --- a/Endpoints/AgentEndpoint.cs +++ b/Endpoints/AgentEndpoint.cs @@ -65,6 +65,7 @@ public static class AgentEndpoint a.UseUserInfo, a.UseMemory, a.UseAutoContext, + a.UseGitHubSearch, a.UseWebSearch, a.WebSearchVersion, a.AllowUserChoice, @@ -121,6 +122,7 @@ public static class AgentEndpoint UseUserInfo = !body.TryGetProperty("useUserInfo", out var uu) || uu.GetBoolean(), UseMemory = !body.TryGetProperty("useMemory", out var um) || um.GetBoolean(), UseAutoContext = !body.TryGetProperty("useAutoContext", out var uac) || uac.GetBoolean(), + UseGitHubSearch = body.TryGetProperty("useGitHubSearch", out var ughs) && ughs.GetBoolean(), UseWebSearch = body.TryGetProperty("webSearchVersion", out var wsv) && !string.IsNullOrEmpty(wsv.GetString()), WebSearchVersion = body.TryGetProperty("webSearchVersion", out var wsv2) ? wsv2.GetString() ?? "" : "", AllowUserChoice = !body.TryGetProperty("allowUserChoice", out var auc) || auc.GetBoolean(), @@ -163,6 +165,7 @@ public static class AgentEndpoint if (body.TryGetProperty("useUserInfo", out var uu)) agent.UseUserInfo = uu.GetBoolean(); if (body.TryGetProperty("useMemory", out var um)) agent.UseMemory = um.GetBoolean(); if (body.TryGetProperty("useAutoContext", out var uac)) agent.UseAutoContext = uac.GetBoolean(); + if (body.TryGetProperty("useGitHubSearch", out var ughs)) agent.UseGitHubSearch = ughs.GetBoolean(); if (body.TryGetProperty("webSearchVersion", out var wsv)) { agent.WebSearchVersion = wsv.GetString() ?? ""; diff --git a/Endpoints/ChatEndpoint.cs b/Endpoints/ChatEndpoint.cs index b52a25b..2a9fcfc 100644 --- a/Endpoints/ChatEndpoint.cs +++ b/Endpoints/ChatEndpoint.cs @@ -216,7 +216,7 @@ public static class ChatEndpoint else { // Standard: Anthropic - await anthropic.StreamChat(res, ctx.ModelId, ctx.SystemPrompt, messages, ctx.ChainId, ctx.Workspace, sessionId, agentId: ctx.AgentId, userId: userId, useMemory: ctx.UseMemory, webSearchVersion: ctx.WebSearchVersion, maxIterations: ctx.MaxIterations, toolChoice: effectiveToolChoice, review: ctx.Review, finalizer: ctx.Finalizer, allowUserChoice: ctx.Agent?.AllowUserChoice ?? true, planMode: ctx.PlanMode, useAutoContext: ctx.Agent?.UseAutoContext ?? true, workCt: workCt, hardCt: hardCt, sseCt: sseCt, remoteMgr: remoteMgr); + await anthropic.StreamChat(res, ctx.ModelId, ctx.SystemPrompt, messages, ctx.ChainId, ctx.Workspace, sessionId, agentId: ctx.AgentId, userId: userId, useMemory: ctx.UseMemory, webSearchVersion: ctx.WebSearchVersion, maxIterations: ctx.MaxIterations, toolChoice: effectiveToolChoice, review: ctx.Review, finalizer: ctx.Finalizer, allowUserChoice: ctx.Agent?.AllowUserChoice ?? true, planMode: ctx.PlanMode, useAutoContext: ctx.Agent?.UseAutoContext ?? true, useGitHubSearch: ctx.Agent?.UseGitHubSearch ?? false, workCt: workCt, hardCt: hardCt, sseCt: sseCt, remoteMgr: remoteMgr); } } finally diff --git a/Models/AgentRecord.cs b/Models/AgentRecord.cs index f4e6e33..b4980c1 100644 --- a/Models/AgentRecord.cs +++ b/Models/AgentRecord.cs @@ -17,6 +17,7 @@ public class AgentRecord public bool UseUserInfo { get; set; } = true; public bool UseMemory { get; set; } = true; public bool UseAutoContext { get; set; } = true; + public bool UseGitHubSearch { get; set; } public bool UseWebSearch { get; set; } public string WebSearchVersion { get; set; } = ""; public bool AllowUserChoice { get; set; } = true; diff --git a/Services/AnthropicService.cs b/Services/AnthropicService.cs index add3061..5a730f2 100644 --- a/Services/AnthropicService.cs +++ b/Services/AnthropicService.cs @@ -96,6 +96,7 @@ public class AnthropicService bool allowUserChoice = true, bool planMode = false, bool useAutoContext = true, + bool useGitHubSearch = false, CancellationToken workCt = default, CancellationToken hardCt = default, CancellationToken sseCt = default, @@ -177,7 +178,7 @@ public class AnthropicService payload["system"] = systemPrompt; var hasRemote = remoteMgr?.GetBySessionId(sessionId) != null; - AddToolsToPayload(payload, workspace, agentId, useMemory, webSearchVersion, toolChoice, iterations, allowUserChoice, planMode, includeRemote: hasRemote); + AddToolsToPayload(payload, workspace, agentId, useMemory, webSearchVersion, toolChoice, iterations, allowUserChoice, planMode, includeRemote: hasRemote, includeGitHubSearch: useGitHubSearch && _toolService.HasGitHubToken); var client = CreateClient(); var json = JsonSerializer.Serialize(payload, new JsonSerializerOptions { WriteIndented = true }); @@ -1619,13 +1620,12 @@ public class AnthropicService /// /// Fügt Tool-Definitionen und WebSearch zum Payload hinzu. /// - private void AddToolsToPayload(Dictionary payload, string workspace, string agentId, bool useMemory, string webSearchVersion, string toolChoice, int iteration, bool allowUserChoice = false, bool planMode = false, bool includeRemote = false) + private void AddToolsToPayload(Dictionary payload, string workspace, string agentId, bool useMemory, string webSearchVersion, string toolChoice, int iteration, bool allowUserChoice = false, bool planMode = false, bool includeRemote = false, bool includeGitHubSearch = false) { var hasWorkspace = !string.IsNullOrEmpty(workspace); var includeMemory = useMemory && _memoryService != null && !string.IsNullOrEmpty(agentId); var includeMemorySearch = _vectorSearch != null && _vectorSearch.GetEmbeddingCount() > 0; var includeSendToSession = _db != null && _chatService != null; - var includeGitHubSearch = _toolService.HasGitHubToken; var hasTools = hasWorkspace || includeMemory || includeRemote || includeMemorySearch || includeSendToSession || includeGitHubSearch; var hasWebSearch = !string.IsNullOrEmpty(webSearchVersion); diff --git a/Services/ChatService.cs b/Services/ChatService.cs index 52ecf39..544c2da 100644 --- a/Services/ChatService.cs +++ b/Services/ChatService.cs @@ -79,7 +79,7 @@ public class ChatService var hasWorkspace = !string.IsNullOrEmpty(workspace); var includeMemory = agent.UseMemory && !string.IsNullOrEmpty(agent.AgentId); - var includeGitHubSearch = _toolService.HasGitHubToken; + var includeGitHubSearch = agent.UseGitHubSearch && _toolService.HasGitHubToken; var hasTools = hasWorkspace || includeMemory || includeGitHubSearch; var toolChoice = hasTools ? "any" : null; diff --git a/Services/DatabaseService.Agents.cs b/Services/DatabaseService.Agents.cs index 5fd151b..d7af6c5 100644 --- a/Services/DatabaseService.Agents.cs +++ b/Services/DatabaseService.Agents.cs @@ -19,8 +19,8 @@ public partial class DatabaseService agent.CreatedAt = now; agent.UpdatedAt = now; await conn.ExecuteAsync(@" - INSERT INTO agents (agent_id, user_id, name, avatar, avatar_small, description, model, tool_choice, custom_commands, auto_commit, use_soul, use_identity, use_user_info, use_memory, use_auto_context, use_web_search, web_search_version, allow_user_choice, task_instruction, avatar_scale, avatar_offset_x, avatar_offset_y, is_deleted, created_at, updated_at) - VALUES (@AgentId, @UserId, @Name, @Avatar, @AvatarSmall, @Description, @Model, @ToolChoice, @CustomCommands, @AutoCommit, @UseSoul, @UseIdentity, @UseUserInfo, @UseMemory, @UseAutoContext, @UseWebSearch, @WebSearchVersion, @AllowUserChoice, @TaskInstruction, @AvatarScale, @AvatarOffsetX, @AvatarOffsetY, 0, @CreatedAt, @UpdatedAt) + INSERT INTO agents (agent_id, user_id, name, avatar, avatar_small, description, model, tool_choice, custom_commands, auto_commit, use_soul, use_identity, use_user_info, use_memory, use_auto_context, use_github_search, use_web_search, web_search_version, allow_user_choice, task_instruction, avatar_scale, avatar_offset_x, avatar_offset_y, is_deleted, created_at, updated_at) + VALUES (@AgentId, @UserId, @Name, @Avatar, @AvatarSmall, @Description, @Model, @ToolChoice, @CustomCommands, @AutoCommit, @UseSoul, @UseIdentity, @UseUserInfo, @UseMemory, @UseAutoContext, @UseGitHubSearch, @UseWebSearch, @WebSearchVersion, @AllowUserChoice, @TaskInstruction, @AvatarScale, @AvatarOffsetX, @AvatarOffsetY, 0, @CreatedAt, @UpdatedAt) ", agent); return agent; } @@ -54,7 +54,7 @@ public partial class DatabaseService UPDATE agents SET name = @Name, avatar = @Avatar, avatar_small = @AvatarSmall, description = @Description, model = @Model, tool_choice = @ToolChoice, custom_commands = @CustomCommands, auto_commit = @AutoCommit, - use_soul = @UseSoul, use_identity = @UseIdentity, use_user_info = @UseUserInfo, use_memory = @UseMemory, use_auto_context = @UseAutoContext, use_web_search = @UseWebSearch, web_search_version = @WebSearchVersion, + use_soul = @UseSoul, use_identity = @UseIdentity, use_user_info = @UseUserInfo, use_memory = @UseMemory, use_auto_context = @UseAutoContext, use_github_search = @UseGitHubSearch, use_web_search = @UseWebSearch, web_search_version = @WebSearchVersion, allow_user_choice = @AllowUserChoice, task_instruction = @TaskInstruction, avatar_scale = @AvatarScale, avatar_offset_x = @AvatarOffsetX, avatar_offset_y = @AvatarOffsetY, is_public = @IsPublic, updated_at = @UpdatedAt diff --git a/Services/DatabaseService.cs b/Services/DatabaseService.cs index aac55e2..ef039ba 100644 --- a/Services/DatabaseService.cs +++ b/Services/DatabaseService.cs @@ -151,6 +151,7 @@ public partial class DatabaseService TryAddColumn(conn, "agents", "use_user_info", "INTEGER NOT NULL DEFAULT 1"); TryAddColumn(conn, "agents", "use_memory", "INTEGER NOT NULL DEFAULT 1"); TryAddColumn(conn, "agents", "use_auto_context", "INTEGER NOT NULL DEFAULT 1"); + TryAddColumn(conn, "agents", "use_github_search", "INTEGER NOT NULL DEFAULT 0"); TryAddColumn(conn, "messages", "deleted_on", "TEXT"); TryAddColumn(conn, "agents", "use_web_search", "INTEGER NOT NULL DEFAULT 0"); diff --git a/wwwroot/index.html b/wwwroot/index.html index a7b5bea..b0029ad 100644 --- a/wwwroot/index.html +++ b/wwwroot/index.html @@ -241,6 +241,10 @@ Automatischer Kontext (Relevante Erinnerungen werden automatisch abgerufen) +