|
|
|
|
|
using Microsoft.SemanticKernel.ChatCompletion;
|
|
|
|
|
|
|
|
|
|
|
|
namespace AI.Models.Store
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 会话存储条目的抽象基类。每条为 TextEntry(角色+文本)或 SpecialEntry(类型+YAML 载荷)。
|
|
|
|
|
|
/// 存储由 ChatSession 持有,作为 UI 与 Prompt 构建的唯一事实来源。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public abstract class ConversationEntry
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 条目种类:Text 或 Special,用于序列化/反序列化与类型判别。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public abstract string Kind { get; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 纯文本消息条目:角色(User/Assistant/System)+ 文本内容。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public sealed class TextConversationEntry : ConversationEntry
|
|
|
|
|
|
{
|
|
|
|
|
|
public override string Kind => "Text";
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>角色</summary>
|
|
|
|
|
|
public AuthorRole Role { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>文本内容</summary>
|
|
|
|
|
|
public string Content { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
public TextConversationEntry() { }
|
|
|
|
|
|
|
|
|
|
|
|
public TextConversationEntry(AuthorRole role, string content)
|
|
|
|
|
|
{
|
|
|
|
|
|
Role = role;
|
|
|
|
|
|
Content = content ?? string.Empty;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 特殊消息条目:类型(Form/ParameterSet/Table/ColumnMatch/WorkflowStatus)+ YAML 载荷。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public sealed class SpecialConversationEntry : ConversationEntry
|
|
|
|
|
|
{
|
|
|
|
|
|
public override string Kind => "Special";
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>特殊消息类型名</summary>
|
|
|
|
|
|
public string Type { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>YAML 载荷(与 ISpecialMessage 可序列化/反序列化对应)</summary>
|
|
|
|
|
|
public string Payload { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
public SpecialConversationEntry() { }
|
|
|
|
|
|
|
|
|
|
|
|
public SpecialConversationEntry(string type, string payload)
|
|
|
|
|
|
{
|
|
|
|
|
|
Type = type ?? string.Empty;
|
|
|
|
|
|
Payload = payload ?? string.Empty;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|