马良AI写作初始化仓库

This commit is contained in:
邓滨杰
2025-09-10 00:07:52 +08:00
parent 3c06bb1a03
commit 39c0f8840f
1309 changed files with 318528 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,177 @@
import 'package:equatable/equatable.dart';
import '../../models/chat_models.dart';
import '../../models/ai_request_models.dart';
abstract class ChatEvent extends Equatable {
const ChatEvent();
@override
List<Object?> get props => [];
}
// 加载聊天会话列表
class LoadChatSessions extends ChatEvent {
const LoadChatSessions({required this.novelId});
final String novelId;
@override
List<Object?> get props => [novelId];
}
// 创建新的聊天会话
class CreateChatSession extends ChatEvent {
const CreateChatSession({
required this.title,
required this.novelId,
this.chapterId,
this.metadata,
});
final String title;
final String novelId;
final String? chapterId;
final Map<String, dynamic>? metadata;
@override
List<Object?> get props => [title, novelId, chapterId];
}
// 选择聊天会话
class SelectChatSession extends ChatEvent {
const SelectChatSession({required this.sessionId, this.novelId});
final String sessionId;
final String? novelId;
@override
List<Object?> get props => [sessionId, novelId];
}
// 发送消息
class SendMessage extends ChatEvent {
// <<< Add configId field
// <<< Modify existing constructor
const SendMessage({required this.content, this.configId});
final String content;
final String? configId;
@override
List<Object?> get props => [content, configId]; // <<< Add configId to props
}
// 加载更多消息
class LoadMoreMessages extends ChatEvent {
const LoadMoreMessages();
}
// 更新聊天标题
class UpdateChatTitle extends ChatEvent {
const UpdateChatTitle({required this.newTitle});
final String newTitle;
@override
List<Object?> get props => [newTitle];
}
// 执行操作
class ExecuteAction extends ChatEvent {
const ExecuteAction({required this.action});
final MessageAction action;
@override
List<Object?> get props => [action];
}
// 删除聊天会话
class DeleteChatSession extends ChatEvent {
const DeleteChatSession({required this.sessionId});
final String sessionId;
@override
List<Object?> get props => [sessionId];
}
// 取消正在进行的请求
class CancelOngoingRequest extends ChatEvent {
const CancelOngoingRequest();
}
class UpdateActiveChatConfig extends ChatEvent {
const UpdateActiveChatConfig({required this.configId});
final String? configId;
@override
List<Object?> get props => [configId];
}
// 更新聊天上下文
class UpdateChatContext extends ChatEvent {
const UpdateChatContext({required this.context});
final ChatContext context;
@override
List<Object?> get props => [context];
}
// 更新聊天模型
class UpdateChatModel extends ChatEvent {
// Pass the ID, Bloc will resolve the model
const UpdateChatModel({
required this.sessionId,
required this.modelConfigId,
});
final String sessionId;
final String modelConfigId;
@override
List<Object?> get props => [sessionId, modelConfigId];
}
// 加载设定和片段数据
class LoadContextData extends ChatEvent {
const LoadContextData({required this.novelId});
final String novelId;
@override
List<Object?> get props => [novelId];
}
// 缓存设定数据
class CacheSettingsData extends ChatEvent {
const CacheSettingsData({
required this.novelId,
required this.settings,
required this.settingGroups,
});
final String novelId;
final List<dynamic> settings; // 使用dynamic避免循环导入
final List<dynamic> settingGroups;
@override
List<Object?> get props => [novelId, settings, settingGroups];
}
// 缓存片段数据
class CacheSnippetsData extends ChatEvent {
const CacheSnippetsData({
required this.novelId,
required this.snippets,
});
final String novelId;
final List<dynamic> snippets; // 使用dynamic避免循环导入
@override
List<Object?> get props => [novelId, snippets];
}
// 🚀 新增:更新聊天配置
class UpdateChatConfiguration extends ChatEvent {
const UpdateChatConfiguration({
required this.sessionId,
required this.config,
});
final String sessionId;
final UniversalAIRequest config;
@override
List<Object?> get props => [sessionId, config];
}

View File

@@ -0,0 +1,146 @@
import 'package:equatable/equatable.dart';
import '../../models/chat_models.dart';
import '../../models/user_ai_model_config_model.dart';
import '../../models/ai_request_models.dart';
abstract class ChatState extends Equatable {
const ChatState();
@override
List<Object?> get props => [];
}
// 初始状态
class ChatInitial extends ChatState {}
// 加载会话列表中
class ChatSessionsLoading extends ChatState {}
// 会话列表加载完成
class ChatSessionsLoaded extends ChatState {
const ChatSessionsLoaded({
required this.sessions,
this.error,
});
final List<ChatSession> sessions;
final String? error;
@override
List<Object?> get props => [sessions, error];
ChatSessionsLoaded copyWith({
List<ChatSession>? sessions,
String? error,
bool clearError = false,
}) {
return ChatSessionsLoaded(
sessions: sessions ?? this.sessions,
error: clearError ? null : error ?? this.error,
);
}
}
// 加载单个会话中
class ChatSessionLoading extends ChatState {}
// 会话激活状态
class ChatSessionActive extends ChatState {
const ChatSessionActive({
required this.session,
required this.context,
this.messages = const [],
this.selectedModel,
this.isGenerating = false,
this.isLoadingHistory = false,
this.error,
this.cachedSettings = const [],
this.cachedSettingGroups = const [],
this.cachedSnippets = const [],
this.isLoadingContextData = false,
this.configUpdateTimestamp,
});
final ChatSession session;
final ChatContext context;
final List<ChatMessage> messages;
final UserAIModelConfigModel? selectedModel;
final bool isGenerating;
final bool isLoadingHistory;
final String? error;
// 缓存的上下文数据
final List<dynamic> cachedSettings; // NovelSettingItem列表
final List<dynamic> cachedSettingGroups; // SettingGroup列表
final List<dynamic> cachedSnippets; // NovelSnippet列表
final bool isLoadingContextData;
final DateTime? configUpdateTimestamp; // 配置更新时间戳用于触发UI重建
@override
List<Object?> get props => [
session,
context,
messages,
selectedModel,
isGenerating,
isLoadingHistory,
error,
cachedSettings,
cachedSettingGroups,
cachedSnippets,
isLoadingContextData,
configUpdateTimestamp,
];
ChatSessionActive copyWith({
ChatSession? session,
ChatContext? context,
List<ChatMessage>? messages,
Object? selectedModel = const Object(),
bool? isGenerating,
bool? isLoadingHistory,
String? error,
bool clearError = false,
List<dynamic>? cachedSettings,
List<dynamic>? cachedSettingGroups,
List<dynamic>? cachedSnippets,
bool? isLoadingContextData,
DateTime? configUpdateTimestamp,
}) {
UserAIModelConfigModel? updatedSelectedModel;
if (selectedModel is UserAIModelConfigModel?){
updatedSelectedModel = selectedModel;
} else {
updatedSelectedModel = this.selectedModel;
}
return ChatSessionActive(
session: session ?? this.session,
context: context ?? this.context,
messages: messages ?? this.messages,
selectedModel: updatedSelectedModel,
isGenerating: isGenerating ?? this.isGenerating,
isLoadingHistory: isLoadingHistory ?? this.isLoadingHistory,
error: clearError ? null : error ?? this.error,
cachedSettings: cachedSettings ?? this.cachedSettings,
cachedSettingGroups: cachedSettingGroups ?? this.cachedSettingGroups,
cachedSnippets: cachedSnippets ?? this.cachedSnippets,
isLoadingContextData: isLoadingContextData ?? this.isLoadingContextData,
configUpdateTimestamp: configUpdateTimestamp ?? this.configUpdateTimestamp,
);
}
}
// 错误状态
class ChatError extends ChatState {
const ChatError({required this.message});
final String message;
@override
List<Object?> get props => [message];
}