Memory-Tools unabhängig vom Workspace verfügbar machen

- Tools werden jetzt auch gesendet wenn kein Workspace aber useMemory=true
- GetToolDefinitions(includeFileTools, includeMemory) für granulare Steuerung
- File-Tools geben saubere Fehlermeldung wenn workspace null
This commit is contained in:
Meleki committed 2026-03-01 15:19:56 +01:00
1 parent 342284dd3e
commit 632424fb73
2 files changed
+23 -13

No files matched your search

+18 -10
View File
@@ -11,18 +11,14 @@ namespace Gott.Services;
public class ToolService
{
public object[] GetToolDefinitions(bool includeMemory = false)
public object[] GetToolDefinitions(bool includeFileTools = false, bool includeMemory = false)
{
var tools = GetFileTools();
var allTools = new List<object>();
if (includeFileTools)
allTools.AddRange(GetFileTools());
if (includeMemory)
{
var memTools = GetMemoryToolDefinitions();
var all = new object[tools.Length + memTools.Length];
tools.CopyTo(all, 0);
memTools.CopyTo(all, tools.Length);
return all;
}
return tools;
allTools.AddRange(GetMemoryToolDefinitions());
return allTools.ToArray();
}
private object[] GetFileTools()
@@ -176,6 +172,8 @@ public class ToolService
{
case "read_file":
{
if (string.IsNullOrEmpty(workspace))
return "Fehler: Kein Workspace konfiguriert";
var path = ResolvePath(input.GetProperty("path").GetString() ?? "", workspace);
if (!File.Exists(path))
return $"Fehler: Datei nicht gefunden: {Path.GetRelativePath(workspace, path)}";
@@ -183,6 +181,8 @@ public class ToolService
}
case "write_file":
{
if (string.IsNullOrEmpty(workspace))
return "Fehler: Kein Workspace konfiguriert";
var path = ResolvePath(input.GetProperty("path").GetString() ?? "", workspace);
var dir = Path.GetDirectoryName(path);
if (dir != null) Directory.CreateDirectory(dir);
@@ -192,6 +192,8 @@ public class ToolService
}
case "edit_file":
{
if (string.IsNullOrEmpty(workspace))
return "Fehler: Kein Workspace konfiguriert";
var path = ResolvePath(input.GetProperty("path").GetString() ?? "", workspace);
if (!File.Exists(path))
return $"Fehler: Datei nicht gefunden: {Path.GetRelativePath(workspace, path)}";
@@ -206,6 +208,8 @@ public class ToolService
}
case "list_files":
{
if (string.IsNullOrEmpty(workspace))
return "Fehler: Kein Workspace konfiguriert";
var path = ResolvePath(input.TryGetProperty("path", out var p) ? p.GetString() ?? "" : "", workspace);
if (!Directory.Exists(path))
return $"Fehler: Verzeichnis nicht gefunden: {Path.GetRelativePath(workspace, path)}";
@@ -218,6 +222,8 @@ public class ToolService
}
case "delete_file":
{
if (string.IsNullOrEmpty(workspace))
return "Fehler: Kein Workspace konfiguriert";
var path = ResolvePath(input.GetProperty("path").GetString() ?? "", workspace);
if (File.Exists(path))
{
@@ -233,6 +239,8 @@ public class ToolService
}
case "execute":
{
if (string.IsNullOrEmpty(workspace))
return "Fehler: Kein Workspace konfiguriert";
var command = input.GetProperty("command").GetString() ?? "";
var psi = new ProcessStartInfo
{