Agents: CRUD, DB table, session binding, replace model picker
- agents table with name, avatar, description, model, persona, instructions, soft-delete - AgentEndpoint (GET/POST/PUT/DELETE /api/agents) - sessions + chains now reference agent_id - ChatEndpoint resolves agent from session (no agent = no chat) - system prompt built from agent persona + instructions - frontend: agent editor with avatar upload, agent cards on dashboard - session: agent dropdown replaces model picker, choice persisted
This commit is contained in:
1 parent
0cd2d51d32
commit
449c872296
16 files changed
+552
-46
No files matched your search
+42
-13
@@ -39,7 +39,32 @@ public static class ChatEndpoint
|
||||
return;
|
||||
}
|
||||
|
||||
var modelId = body.Model switch
|
||||
var sessionId = body.SessionId;
|
||||
if (string.IsNullOrEmpty(sessionId))
|
||||
{
|
||||
res.StatusCode = 400;
|
||||
await res.WriteAsJsonAsync(new { error = "sessionId required" });
|
||||
return;
|
||||
}
|
||||
|
||||
// Agent aus Session auflösen
|
||||
var session = await db.GetSession(sessionId);
|
||||
if (session == null || string.IsNullOrEmpty(session.AgentId))
|
||||
{
|
||||
res.StatusCode = 400;
|
||||
await res.WriteAsJsonAsync(new { error = "Kein Agent ausgewählt" });
|
||||
return;
|
||||
}
|
||||
|
||||
var agent = await db.GetAgent(session.AgentId);
|
||||
if (agent == null)
|
||||
{
|
||||
res.StatusCode = 400;
|
||||
await res.WriteAsJsonAsync(new { error = "Agent nicht gefunden" });
|
||||
return;
|
||||
}
|
||||
|
||||
var modelId = agent.Model switch
|
||||
{
|
||||
"opus" => "claude-opus-4-6",
|
||||
"sonnet" => "claude-sonnet-4-6",
|
||||
@@ -50,20 +75,13 @@ public static class ChatEndpoint
|
||||
res.Headers["Cache-Control"] = "no-cache";
|
||||
res.Headers["Connection"] = "keep-alive";
|
||||
|
||||
var sessionId = body.SessionId;
|
||||
if (string.IsNullOrEmpty(sessionId))
|
||||
{
|
||||
res.StatusCode = 400;
|
||||
await res.WriteAsJsonAsync(new { error = "sessionId required" });
|
||||
return;
|
||||
}
|
||||
|
||||
var chainId = Guid.NewGuid().ToString("N");
|
||||
|
||||
await db.CreateChain(new ChainRecord
|
||||
{
|
||||
ChainId = chainId,
|
||||
SessionId = sessionId,
|
||||
AgentId = agent.AgentId,
|
||||
Model = modelId,
|
||||
SystemPrompt = body.SystemPrompt
|
||||
});
|
||||
@@ -89,13 +107,24 @@ public static class ChatEndpoint
|
||||
});
|
||||
}
|
||||
|
||||
var systemPrompt = new List<object>
|
||||
{
|
||||
new { type = "text", text = "You are Claude Code, Anthropic's official CLI for Claude." }
|
||||
};
|
||||
var systemPrompt = new List<object>();
|
||||
|
||||
// Agent Persona
|
||||
if (!string.IsNullOrWhiteSpace(agent.Persona))
|
||||
systemPrompt.Add(new { type = "text", text = agent.Persona });
|
||||
|
||||
// Agent Instructions
|
||||
if (!string.IsNullOrWhiteSpace(agent.Instructions))
|
||||
systemPrompt.Add(new { type = "text", text = agent.Instructions });
|
||||
|
||||
// Zusätzlicher System Prompt aus dem UI
|
||||
if (!string.IsNullOrWhiteSpace(body.SystemPrompt))
|
||||
systemPrompt.Add(new { type = "text", text = body.SystemPrompt });
|
||||
|
||||
// Fallback wenn gar nix gesetzt
|
||||
if (systemPrompt.Count == 0)
|
||||
systemPrompt.Add(new { type = "text", text = "Du bist ein hilfreicher Assistent." });
|
||||
|
||||
var anthropic = new AnthropicService(httpFactory, token, toolService, db);
|
||||
await anthropic.StreamChat(res, modelId, systemPrompt, messages, chainId);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user