Spaces:
Running
Running
File size: 7,833 Bytes
05f86a6 7be508e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
// 动态消息发送者枚举 - 现在支持自定义角色名称
export enum MessageSender {
User = '用户',
System = '系统',
// 动态角色将在运行时创建,这里保留一些常用的默认值
Cognito = 'Cognito',
Muse = 'Muse',
}
// 消息用途枚举
export enum MessagePurpose {
UserInput = 'user-input',
SystemNotification = 'system-notification',
CognitoToMuse = 'cognito-to-muse', // AI角色之间的讨论(保持兼容性)
MuseToCognito = 'muse-to-cognito', // AI角色之间的讨论(保持兼容性)
FinalResponse = 'final-response', // 最终回复用户
RoleDiscussion = 'role-discussion', // 通用的角色间讨论
}
// 聊天消息接口
export interface ChatMessage {
id: string;
text: string;
sender: MessageSender | string; // 现在支持动态角色名称
purpose: MessagePurpose;
timestamp: Date;
durationMs?: number; // AI消息的生成时间
image?: { // 用户消息的可选图片数据
dataUrl: string; // 用于显示的base64数据URL
name: string;
type: string;
};
roleId?: string; // 可选的角色ID,用于关联具体的AI角色配置
isStreaming?: boolean; // 标记消息是否正在流式传输
}
// 讨论记录接口
export interface DiscussionRecord {
id: string;
timestamp: Date;
userQuery: string;
userImage?: {
name: string;
type: string;
size: number;
};
discussionMode: string;
activeRoles: Array<{
id: string;
name: string;
modelName: string;
channelName: string;
}>;
turns: Array<{
id: string;
role: string;
roleId?: string;
message: string;
timestamp: Date;
durationMs?: number;
purpose: MessagePurpose;
}>;
notepadUpdates: Array<{
id: string;
updater: string;
updaterId?: string;
content: string;
timestamp: Date;
}>;
finalAnswer?: {
content: string;
provider: string;
providerId?: string;
timestamp: Date;
durationMs?: number;
};
totalDuration: number; // 总讨论时长(毫秒)
isCompleted: boolean; // 讨论是否正常完成
wasInterrupted: boolean; // 是否被用户中断
interruptedAt?: Date; // 中断时间
settings: {
discussionMode: string;
manualFixedTurns?: number;
isReducedCapacityEnabled: boolean;
activeRoleCount: number;
};
metadata: {
version: string;
exportedAt?: Date;
messageCount: number;
notepadUpdateCount: number;
};
}
// 讨论统计接口
export interface DiscussionStats {
totalTurns: number;
averageResponseTime: number;
longestResponseTime: number;
shortestResponseTime: number;
totalTokensUsed?: number; // 如果API提供token使用情况
roleParticipation: Record<string, {
turnCount: number;
totalResponseTime: number;
averageResponseTime: number;
}>;
notepadUpdateFrequency: number;
}
// 流式传输状态接口
export interface StreamingState {
messageId: string;
currentText: string;
targetText: string;
isComplete: boolean;
startTime: Date;
speed: number; // 字符/秒
}
// AI模型配置接口(从constants.ts导入,但在这里声明以保持类型完整性)
export interface AiModelConfig {
id: string;
name: string;
apiName: string;
baseUrl?: string;
supportsImages: boolean;
supportsReducedCapacity: boolean;
category: string;
maxTokens: number;
temperature: number;
isCustom: boolean;
createdAt: Date;
}
// AI角色配置接口
export interface AiRoleConfig {
id: string;
name: string;
systemPrompt: string;
modelId: string;
isActive: boolean;
color?: string; // 可选的UI显示颜色
description?: string; // 可选的角色描述
}
// 讨论配置接口
export interface DiscussionConfig {
mode: 'fixed' | 'ai-driven';
fixedTurns?: number;
maxTurnsPerRole?: number;
allowSameModel?: boolean; // 是否允许多个角色使用相同模型
enableNotepadSharing?: boolean; // 是否启用记事本共享
enableStreamingTypewriter?: boolean; // 是否启用流式打字机效果
typewriterSpeed?: number; // 打字机速度(毫秒/字符)
}
// API响应接口
export interface ApiResponse {
text: string;
durationMs: number;
error?: string;
usage?: {
promptTokens: number;
completionTokens: number;
totalTokens: number;
};
streamingChunks?: string[]; // 流式响应的块
}
// 配置导出/导入接口
export interface ConfigExportData {
models: AiModelConfig[];
roles: AiRoleConfig[];
discussionConfig?: DiscussionConfig;
discussionRecords?: DiscussionRecord[]; // 可选的讨论记录
exportedAt: string;
version: string;
}
// 讨论记录导出接口
export interface DiscussionExportData {
record: DiscussionRecord;
stats: DiscussionStats;
fullTranscript: string; // 完整的文本记录
exportFormat: 'json' | 'markdown' | 'html' | 'txt';
exportedAt: string;
version: string;
}
// 验证结果接口
export interface ValidationResult {
isValid: boolean;
errors: string[];
warnings?: string[];
}
// 角色状态接口(运行时使用)
export interface RoleState {
id: string;
name: string;
isProcessing: boolean;
lastResponse?: string;
totalResponseTime?: number;
messageCount?: number;
currentStreamingMessageId?: string; // 当前正在流式传输的消息ID
}
// 会话状态接口
export interface SessionState {
isActive: boolean;
startTime?: Date;
currentTurn: number;
activeRoles: RoleState[];
discussionLog: Array<{
roleId: string;
roleName: string;
message: string;
timestamp: Date;
}>;
canBeInterrupted: boolean; // 是否可以被中断
interruptionRequested: boolean; // 是否请求了中断
}
// 讨论控制接口
export interface DiscussionControl {
canStart: boolean;
canPause: boolean;
canResume: boolean;
canInterrupt: boolean;
canExport: boolean;
currentPhase: 'idle' | 'initializing' | 'discussing' | 'synthesizing' | 'completed' | 'interrupted';
estimatedTimeRemaining?: number; // 估算剩余时间(毫秒)
}
// 导出选项接口
export interface ExportOptions {
format: 'json' | 'markdown' | 'html' | 'txt';
includeMetadata: boolean;
includeStats: boolean;
includeNotepadHistory: boolean;
includeSystemMessages: boolean;
timestampFormat: 'iso' | 'local' | 'relative';
compressOutput: boolean;
}
// 消息过滤器接口
export interface MessageFilter {
senders?: (MessageSender | string)[];
purposes?: MessagePurpose[];
dateRange?: {
start: Date;
end: Date;
};
textSearch?: string;
hasDuration?: boolean;
hasImage?: boolean;
minDuration?: number;
maxDuration?: number;
}
// 通知接口
export interface Notification {
id: string;
type: 'info' | 'success' | 'warning' | 'error';
title: string;
message: string;
timestamp: Date;
duration?: number; // 自动消失时间(毫秒)
actions?: Array<{
label: string;
action: () => void;
style?: 'primary' | 'secondary' | 'danger';
}>;
}
// 应用状态接口
export interface AppState {
ui: {
theme: 'light' | 'dark' | 'auto';
sidebarCollapsed: boolean;
roleManagerOpen: boolean;
configManagerOpen: boolean;
notifications: Notification[];
};
discussion: {
current?: DiscussionRecord;
history: DiscussionRecord[];
control: DiscussionControl;
streaming: Map<string, StreamingState>;
};
session: SessionState;
config: {
channels: any[];
models: any[];
roles: any[];
discussionSettings: DiscussionConfig;
};
} |