taskflow-ai
Version:
TaskFlow AI - 智能PRD文档解析与任务管理助手,支持多模型AI协同、MCP编辑器集成,专为开发团队设计的CLI工具
295 lines (294 loc) • 6.87 kB
TypeScript
/**
* 协作管理器 - 处理团队协作功能
* 支持多人协作、实时同步、冲突解决等功能
*/
import { EventEmitter } from 'events';
import { Logger } from '../../infra/logger';
import { TaskEvent } from './enhanced-task-manager';
/**
* 用户信息接口
*/
export interface User {
id: string;
name: string;
email: string;
role: UserRole;
avatar?: string;
isOnline: boolean;
lastSeen: Date;
preferences: UserPreferences;
}
/**
* 用户角色枚举
*/
export declare enum UserRole {
ADMIN = "admin",
PROJECT_MANAGER = "project_manager",
DEVELOPER = "developer",
DESIGNER = "designer",
TESTER = "tester",
VIEWER = "viewer"
}
/**
* 用户偏好设置
*/
export interface UserPreferences {
notifications: {
email: boolean;
push: boolean;
taskAssigned: boolean;
taskCompleted: boolean;
taskOverdue: boolean;
mentions: boolean;
};
display: {
theme: 'light' | 'dark' | 'auto';
language: string;
timezone: string;
};
workflow: {
autoAssignTasks: boolean;
defaultPriority: string;
workingHours: {
start: string;
end: string;
days: number[];
};
};
}
/**
* 协作会话接口
*/
export interface CollaborationSession {
id: string;
projectId: string;
participants: string[];
startedAt: Date;
lastActivity: Date;
isActive: boolean;
}
/**
* 冲突类型枚举
*/
export declare enum ConflictType {
CONCURRENT_EDIT = "concurrent_edit",
STATUS_CONFLICT = "status_conflict",
ASSIGNMENT_CONFLICT = "assignment_conflict",
DEPENDENCY_CONFLICT = "dependency_conflict"
}
/**
* 冲突信息接口
*/
export interface Conflict {
id: string;
type: ConflictType;
taskId: string;
users: string[];
description: string;
data: Record<string, unknown>;
createdAt: Date;
resolvedAt?: Date;
resolvedBy?: string;
resolution?: Record<string, unknown>;
}
/**
* 通知类型枚举
*/
export declare enum NotificationType {
TASK_ASSIGNED = "task_assigned",
TASK_COMPLETED = "task_completed",
TASK_OVERDUE = "task_overdue",
TASK_BLOCKED = "task_blocked",
MENTION = "mention",
CONFLICT = "conflict",
PROJECT_UPDATE = "project_update"
}
/**
* 通知接口
*/
export interface Notification {
id: string;
type: NotificationType;
userId: string;
title: string;
message: string;
data: Record<string, unknown>;
isRead: boolean;
createdAt: Date;
readAt?: Date;
}
/**
* 活动日志接口
*/
export interface ActivityLog {
id: string;
userId: string;
action: string;
targetType: 'task' | 'project' | 'user';
targetId: string;
description: string;
metadata: Record<string, unknown>;
timestamp: Date;
}
/**
* 协作管理器类
*/
export declare class CollaborationManager extends EventEmitter {
private logger;
private users;
private sessions;
private conflicts;
private notifications;
private activityLogs;
private onlineUsers;
constructor(logger: Logger);
/**
* 添加用户
* @param user 用户信息
*/
addUser(user: User): void;
/**
* 获取用户
* @param userId 用户ID
*/
getUser(userId: string): User | undefined;
/**
* 获取所有用户
*/
getAllUsers(): User[];
/**
* 用户上线
* @param userId 用户ID
*/
userOnline(userId: string): void;
/**
* 用户下线
* @param userId 用户ID
*/
userOffline(userId: string): void;
/**
* 获取在线用户
*/
getOnlineUsers(): User[];
/**
* 创建协作会话
* @param projectId 项目ID
* @param participants 参与者ID列表
*/
createSession(projectId: string, participants: string[]): CollaborationSession;
/**
* 加入协作会话
* @param sessionId 会话ID
* @param userId 用户ID
*/
joinSession(sessionId: string, userId: string): boolean;
/**
* 离开协作会话
* @param sessionId 会话ID
* @param userId 用户ID
*/
leaveSession(sessionId: string, userId: string): boolean;
/**
* 关闭协作会话
* @param sessionId 会话ID
*/
closeSession(sessionId: string): boolean;
/**
* 处理任务事件
* @param event 任务事件
*/
handleTaskEvent(event: TaskEvent): void;
/**
* 检测冲突
* @param event 任务事件
*/
private detectConflicts;
/**
* 创建冲突
* @param conflictData 冲突数据
*/
private createConflict;
/**
* 解决冲突
* @param conflictId 冲突ID
* @param resolution 解决方案
* @param resolvedBy 解决者ID
*/
resolveConflict(conflictId: string, resolution: Record<string, unknown>, resolvedBy: string): boolean;
/**
* 发送通知
* @param event 任务事件
*/
private sendNotifications;
/**
* 创建通知
* @param notificationData 通知数据
*/
private createNotification;
/**
* 通知项目成员
* @param task 任务
* @param notificationData 通知数据
*/
private notifyProjectMembers;
/**
* 检查是否应该发送通知
* @param user 用户
* @param notificationType 通知类型
*/
private shouldSendNotification;
/**
* 记录活动
* @param event 任务事件
*/
private logActivity;
/**
* 生成活动描述
* @param event 任务事件
*/
private generateActivityDescription;
/**
* 更新会话活动
* @param event 任务事件
*/
private updateSessionActivity;
/**
* 获取最近的任务事件
* @param taskId 任务ID
* @param timeWindow 时间窗口(毫秒)
*/
private getRecentTaskEvents;
/**
* 检查状态转换是否有效
* @param oldStatus 旧状态
* @param newStatus 新状态
*/
private isValidStatusTransition;
/**
* 获取用户通知
* @param userId 用户ID
* @param unreadOnly 只获取未读通知
*/
getUserNotifications(userId: string, unreadOnly?: boolean): Notification[];
/**
* 标记通知为已读
* @param notificationId 通知ID
* @param userId 用户ID
*/
markNotificationAsRead(notificationId: string, userId: string): boolean;
/**
* 获取活动日志
* @param filters 过滤条件
* @param limit 限制数量
*/
getActivityLogs(filters?: {
userId?: string;
targetType?: string;
targetId?: string;
after?: Date;
}, limit?: number): ActivityLog[];
/**
* 生成ID
*/
private generateId;
}