This is the initial commit for the CODEX_ADK project, a full-stack AI agent management platform featuring: BACKEND (ASP.NET Core 8.0): - CQRS architecture with 6 commands and 7 queries - 16 API endpoints (all working and tested) - PostgreSQL database with 5 entities - AES-256 encryption for API keys - FluentValidation on all commands - Rate limiting and CORS configured - OpenAPI/Swagger documentation - Docker Compose setup (PostgreSQL + Ollama) FRONTEND (Flutter 3.x): - Dark theme with Svrnty branding - Collapsible sidebar navigation - CQRS API client with Result<T> error handling - Type-safe endpoints from OpenAPI schema - Multi-platform support (Web, iOS, Android, macOS, Linux, Windows) DOCUMENTATION: - Comprehensive API reference - Architecture documentation - Development guidelines for Claude Code - API integration guides - context-claude.md project overview Status: Backend ready (Grade A-), Frontend integration pending 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
125 lines
3.8 KiB
C#
125 lines
3.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Codex.Dal;
|
|
using Codex.Dal.Enums;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using OpenHarbor.CQRS.Abstractions;
|
|
|
|
namespace Codex.CQRS.Queries;
|
|
|
|
/// <summary>
|
|
/// Get conversation with all messages by ID
|
|
/// </summary>
|
|
public record GetConversationQuery
|
|
{
|
|
/// <summary>Conversation ID</summary>
|
|
public Guid Id { get; init; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Detailed conversation information with messages
|
|
/// </summary>
|
|
public record ConversationDetails
|
|
{
|
|
/// <summary>Unique conversation identifier</summary>
|
|
public Guid Id { get; init; }
|
|
|
|
/// <summary>Conversation title</summary>
|
|
public string Title { get; init; } = string.Empty;
|
|
|
|
/// <summary>Conversation summary</summary>
|
|
public string? Summary { get; init; }
|
|
|
|
/// <summary>Whether conversation is active</summary>
|
|
public bool IsActive { get; init; }
|
|
|
|
/// <summary>Conversation start timestamp</summary>
|
|
public DateTime StartedAt { get; init; }
|
|
|
|
/// <summary>Last message timestamp</summary>
|
|
public DateTime LastMessageAt { get; init; }
|
|
|
|
/// <summary>Total message count</summary>
|
|
public int MessageCount { get; init; }
|
|
|
|
/// <summary>All messages in conversation</summary>
|
|
public List<ConversationMessageItem> Messages { get; init; } = new();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Individual message within a conversation
|
|
/// </summary>
|
|
public record ConversationMessageItem
|
|
{
|
|
/// <summary>Message identifier</summary>
|
|
public Guid Id { get; init; }
|
|
|
|
/// <summary>Conversation identifier</summary>
|
|
public Guid ConversationId { get; init; }
|
|
|
|
/// <summary>Execution identifier if from agent execution</summary>
|
|
public Guid? ExecutionId { get; init; }
|
|
|
|
/// <summary>Message role (user, assistant, system, tool)</summary>
|
|
public MessageRole Role { get; init; }
|
|
|
|
/// <summary>Message content</summary>
|
|
public string Content { get; init; } = string.Empty;
|
|
|
|
/// <summary>Message index/order in conversation</summary>
|
|
public int MessageIndex { get; init; }
|
|
|
|
/// <summary>Whether message is in active context window</summary>
|
|
public bool IsInActiveWindow { get; init; }
|
|
|
|
/// <summary>Message creation timestamp</summary>
|
|
public DateTime CreatedAt { get; init; }
|
|
}
|
|
|
|
public class GetConversationQueryHandler : IQueryHandler<GetConversationQuery, ConversationDetails?>
|
|
{
|
|
private readonly CodexDbContext _dbContext;
|
|
|
|
public GetConversationQueryHandler(CodexDbContext dbContext)
|
|
{
|
|
_dbContext = dbContext;
|
|
}
|
|
|
|
public async Task<ConversationDetails?> HandleAsync(
|
|
GetConversationQuery query,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
return await _dbContext.Conversations
|
|
.AsNoTracking()
|
|
.Where(c => c.Id == query.Id)
|
|
.Select(c => new ConversationDetails
|
|
{
|
|
Id = c.Id,
|
|
Title = c.Title,
|
|
Summary = c.Summary,
|
|
IsActive = c.IsActive,
|
|
StartedAt = c.StartedAt,
|
|
LastMessageAt = c.LastMessageAt,
|
|
MessageCount = c.MessageCount,
|
|
Messages = c.Messages
|
|
.OrderBy(m => m.MessageIndex)
|
|
.Select(m => new ConversationMessageItem
|
|
{
|
|
Id = m.Id,
|
|
ConversationId = m.ConversationId,
|
|
ExecutionId = m.ExecutionId,
|
|
Role = m.Role,
|
|
Content = m.Content,
|
|
MessageIndex = m.MessageIndex,
|
|
IsInActiveWindow = m.IsInActiveWindow,
|
|
CreatedAt = m.CreatedAt
|
|
})
|
|
.ToList()
|
|
})
|
|
.FirstOrDefaultAsync(cancellationToken);
|
|
}
|
|
}
|