|
|
using System.ComponentModel;
|
|
|
using LiveMarkdown.Avalonia;
|
|
|
using AI.Models.SpecialMessages;
|
|
|
|
|
|
namespace AI.Models
|
|
|
{
|
|
|
public enum AuthorType
|
|
|
{
|
|
|
User,
|
|
|
AI,
|
|
|
Tool, // 用于显示工具调用记录
|
|
|
}
|
|
|
|
|
|
public enum MessageType
|
|
|
{
|
|
|
Text,
|
|
|
File,
|
|
|
WorkflowStatus, // 工作流状态消息
|
|
|
Form, // 表单消息
|
|
|
Table, // 表格数据预览(如导入数据预览)
|
|
|
ColumnMatch, // 必需列与预览列匹配展示
|
|
|
ParameterSet, // 参数集展示(名称/值/描述)
|
|
|
KnowledgeBase, // 知识库查询结果(已写入 Store,供 LLM 与 UI 使用)
|
|
|
XyzLoadCard, // 散点文件加载综合卡片(打开文件+数据预览+列头匹配)
|
|
|
GriddingParamCard, // 网格化参数设置综合卡片(参数加载+编辑+成图按钮)
|
|
|
// 未来可扩展:Code, Image, Chart 等
|
|
|
}
|
|
|
|
|
|
public class ChatMessageModel(AuthorType authorType, string message, bool lastMessage = false) : INotifyPropertyChanged
|
|
|
{
|
|
|
public AuthorType Author { get; set; } = authorType;
|
|
|
public MessageType Type { get; set; } = MessageType.Text;
|
|
|
|
|
|
private ObservableStringBuilder _markdownBuilder = InitializeMarkdownBuilder(message);
|
|
|
public ObservableStringBuilder MarkdownBuilder
|
|
|
{
|
|
|
get => _markdownBuilder;
|
|
|
set
|
|
|
{
|
|
|
if (_markdownBuilder != value)
|
|
|
{
|
|
|
_markdownBuilder = value;
|
|
|
OnPropertyChanged(nameof(MarkdownBuilder));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private string _message = message;
|
|
|
public string Message
|
|
|
{
|
|
|
get => _message;
|
|
|
set
|
|
|
{
|
|
|
if (_message != value)
|
|
|
{
|
|
|
_message = value;
|
|
|
if (_markdownBuilder != null)
|
|
|
{
|
|
|
_markdownBuilder.Clear();
|
|
|
_markdownBuilder.Append(value);
|
|
|
}
|
|
|
OnPropertyChanged(nameof(Message));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public string FileName { get; set; } = string.Empty;
|
|
|
public string FilePath { get; set; } = string.Empty;
|
|
|
public long FileSize { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 特殊消息内容(用于扩展消息类型)
|
|
|
/// </summary>
|
|
|
public ISpecialMessage? SpecialContent { get; set; }
|
|
|
|
|
|
private bool _lastMessage = lastMessage;
|
|
|
public bool LastMessage
|
|
|
{
|
|
|
get => _lastMessage;
|
|
|
set
|
|
|
{
|
|
|
if (_lastMessage != value)
|
|
|
{
|
|
|
_lastMessage = value;
|
|
|
OnPropertyChanged(nameof(LastMessage));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
|
protected void OnPropertyChanged(string propertyName)
|
|
|
{
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
}
|
|
|
|
|
|
private static ObservableStringBuilder InitializeMarkdownBuilder(string message)
|
|
|
{
|
|
|
var builder = new ObservableStringBuilder();
|
|
|
if (!string.IsNullOrEmpty(message))
|
|
|
{
|
|
|
builder.Append(message);
|
|
|
}
|
|
|
return builder;
|
|
|
}
|
|
|
}
|
|
|
}
|