feat(image): 新建 knowai-core:1.0.0 镜像并完成推送
Some checks reported errors
continuous-integration/drone/push Build was killed

- 搭建 api、auth、utils 等逻辑模块
- 通过 tsc、eslint、vitest 测试验证

BREAKING CHANGE: 新镜像分支
This commit is contained in:
tobegold574
2025-11-10 20:20:25 +08:00
commit 6a81b7bb13
73 changed files with 10511 additions and 0 deletions

10
types/README.md Normal file
View File

@@ -0,0 +1,10 @@
# Types 模块
## 架构设计
Types模块用于定义前端数据模型提供给其他模块进行API或行为封装。
## 包含
1. **chat**
- 包

96
types/chat/api.d.ts vendored Normal file
View File

@@ -0,0 +1,96 @@
import type { ChatSession, ChatMessage } from './base';
import type { ChatMessageType } from './enum';
// 创建聊天会话请求接口
export interface CreateChatSessionRequest {
participantId: string;
}
// 更新聊天会话请求接口
export interface UpdateChatSessionRequest {
sessionId: string;
}
// 发送消息请求接口
export interface SendMessageRequest {
sessionId: string;
content: string;
type: ChatMessageType;
metadata?: Record<string, unknown>;
}
// 获取聊天会话列表请求接口
export interface GetChatSessionsRequest {
page?: number;
limit?: number;
}
// 获取聊天会话列表响应接口
export interface GetChatSessionsResponse {
sessions: ChatSession[];
total: number;
page: number;
limit: number;
}
// 获取聊天消息请求接口
export interface GetChatMessagesRequest {
sessionId: string;
page?: number;
limit?: number;
before?: string; // 消息ID获取该消息之前的消息
after?: string; // 消息ID获取该消息之后的消息
}
// 获取聊天消息响应接口
export interface GetChatMessagesResponse {
messages: ChatMessage[];
total: number;
page: number;
limit: number;
hasMore: boolean;
}
// 标记消息已读请求接口
export interface MarkMessagesAsReadRequest {
sessionId: string;
messageIds: string[];
}
// 标记消息已读响应接口
export interface MarkMessagesAsReadResponse {
success: boolean;
markedMessageIds: string[]; // 成功标记的消息ID
failedMessageIds?: string[]; // 失败的消息ID
}
// 搜索聊天消息请求接口
export interface SearchChatMessagesRequest {
sessionId?: string;
query: string;
page?: number;
limit?: number;
}
// 搜索聊天消息响应接口
export interface SearchChatMessagesResponse {
messages: ChatMessage[];
total: number;
page: number;
limit: number;
}
// 搜索聊天会话请求接口
export interface SearchChatSessionsRequest {
query: string;
page?: number;
limit?: number;
}
// 搜索聊天会话响应接口
export interface SearchChatSessionsResponse {
sessions: ChatSession[];
total: number;
page: number;
limit: number;
}

45
types/chat/base.d.ts vendored Normal file
View File

@@ -0,0 +1,45 @@
import type { User } from '../index';
import type { ChatMessageType, ChatMessageStatus } from './enum';
// 聊天消息接口
export interface ChatMessage {
id: string;
sessionId: string;
sender: User;
receiver: User;
content: string;
type: ChatMessageType;
status: ChatMessageStatus;
createdAt: Date;
// 非文本消息类型的元数据
metadata?: {
fileName?: string;
fileSize?: number;
duration?: number;
thumbnail?: string;
[key: string]: unknown;
};
}
// 聊天会话接口
export interface ChatSession {
id: string;
participant1Id: string;
participant2Id: string;
participant1: User;
participant2: User;
lastMessage?: {
id: string;
content: string;
senderId: string;
createdAt: Date;
};
unreadCount1: number; // 参与者1的未读消息数
unreadCount2: number; // 参与者2的未读消息数
createdAt: Date;
updatedAt: Date;
// 会话元数据(特殊标记、背景设置、自定义属性等等)
metadata?: {
[key: string]: unknown;
};
}

19
types/chat/enum.d.ts vendored Normal file
View File

@@ -0,0 +1,19 @@
// 聊天消息类型枚举
export enum ChatMessageType {
TEXT = 'text',
IMAGE = 'image',
FILE = 'file',
VOICE = 'voice',
VIDEO = 'video',
SYSTEM = 'system'
}
// 聊天消息状态枚举
export enum ChatMessageStatus {
SENDING = 'sending',
SENT = 'sent',
DELIVERED = 'delivered',
READ = 'read',
FAILED = 'failed'
}

3
types/chat/index.d.ts vendored Normal file
View File

@@ -0,0 +1,3 @@
export * from './enum';
export * from './base';
export * from './api';

5
types/index.d.ts vendored Normal file
View File

@@ -0,0 +1,5 @@
// 导出所有类型定义模块
export * from './chat';
export * from './model';
export * from './post';
export * from './user';

160
types/model/api.d.ts vendored Normal file
View File

@@ -0,0 +1,160 @@
import type { ModelComment, AIModel } from './base';
import type { CommentSortType } from './enum';
// AI模型榜单项接口
export interface AIModelRankingItem {
model: AIModel;
rank: number;
change?: 'up' | 'down' | 'same'; // 排名变化,未来扩展
}
// 获取AI模型广场数据请求接口
export interface GetAIPlazaRequest {
// 模型卡片数据是静态配置(手动维护)的,不需要分页参数
}
// 获取AI模型广场数据响应接口
export interface GetAIPlazaResponse {
models: AIModel[]; // 模型卡片列表,由管理员预定义
hotRankings: AIModelRankingItem[]; // 热评模型榜单
clickRankings: AIModelRankingItem[]; // 点击排行榜
}
// 获取模型详情请求接口
export interface GetModelDetailRequest {
modelId: string;
page?: number; // 评论页码
limit?: number; // 每页评论数量
sortBy?: CommentSortType; // 评论排序方式,未来扩展功能
}
// 获取模型详情响应接口
export interface GetModelDetailResponse {
model: AIModel;
comments: ModelComment[]; // 使用新的ModelComment类型已经是数组
totalComments: number;
hasMoreComments: boolean; // 是否还有更多评论,支持无限滚动加载
}
// 批量获取模型评论请求接口
export interface GetModelCommentsRequest {
modelId: string;
page?: number; // 页码
limit?: number; // 每页评论数量
sortBy?: CommentSortType; // 评论排序方式
parentId?: string; // 父评论ID用于获取回复
}
// 批量获取模型评论响应接口
export interface GetModelCommentsResponse {
comments: ModelComment[]; // 评论列表
total: number; // 总数
page: number; // 当前页码
limit: number; // 每页数量
hasMore: boolean; // 是否有更多数据
}
// 发表模型评论请求接口
export interface CreateModelCommentRequest {
modelId: string;
content: string;
parentId?: string; // 父评论ID用于回复评论
}
// 发表模型评论响应接口
export interface CreateModelCommentResponse {
comment: ModelComment; // 使用新的ModelComment类型
}
// 点赞模型评论请求接口
export interface LikeModelCommentRequest {
commentId: string;
}
// 点赞模型评论响应接口
export interface LikeModelCommentResponse {
success: boolean;
}
// 记录模型点击请求接口
export interface RecordModelClickRequest {
modelId: string;
}
// 记录模型点击响应接口
export interface RecordModelClickResponse {
success: boolean;
clickCount: number; // 更新后的总点击数
}
// 后面的都暂时不考虑
// 删除模型评论请求接口
export interface DeleteModelCommentRequest {
commentId: string;
}
// 删除模型评论响应接口
export interface DeleteModelCommentResponse {
success: boolean;
}
// 更新模型评论请求接口
export interface UpdateModelCommentRequest {
commentId: string;
content?: string; // 更新内容
}
// 更新模型评论响应接口
export interface UpdateModelCommentResponse {
success: boolean;
comment: ModelComment; // 返回更新后的评论
}
// 批量点赞模型评论请求接口
export interface BatchLikeModelCommentsRequest {
commentIds: string[]; // 评论ID列表
}
// 批量点赞模型评论响应接口
export interface BatchLikeModelCommentsResponse {
results: Array<{
commentId: string;
success: boolean;
comment?: ModelComment; // 成功时返回更新后的评论
error?: string; // 失败时的错误信息
}>;
}
// 批量删除模型评论请求接口
export interface BatchDeleteModelCommentsRequest {
commentIds: string[]; // 评论ID列表
}
// 批量删除模型评论响应接口
export interface BatchDeleteModelCommentsResponse {
results: Array<{
commentId: string;
success: boolean;
error?: string; // 失败时的错误信息
}>;
}
// 批量更新模型评论请求接口
export interface BatchUpdateModelCommentsRequest {
updates: Array<{
commentId: string;
content?: string; // 更新内容
rating?: number; // 更新评分
}>;
}
// 批量更新模型评论响应接口
export interface BatchUpdateModelCommentsResponse {
results: Array<{
commentId: string;
success: boolean;
comment?: ModelComment; // 成功时返回更新后的评论
error?: string; // 失败时的错误信息
}>;
}

31
types/model/base.d.ts vendored Normal file
View File

@@ -0,0 +1,31 @@
import type { BaseEntity, BaseUser } from '../post/base';
// AI模型评论统计信息接口
export interface ModelCommentStats {
stars: number; // 收藏数
likes: number; // 点赞数
comments: number; // 评论数
replies: number; // 回复数
}
// AI模型评论接口
export interface ModelComment extends BaseEntity {
modelId: string; // 模型ID
authorId: string; // 作者ID
author: BaseUser; // 作者信息
content: string; // 评论内容
parentId?: string; // 父评论ID用于嵌套评论
stats: ModelCommentStats; // 统计信息
}
// AI模型接口
export interface AIModel {
id: string;
name: string;
description: string;
avatar?: string; // 模型头像
tags?: string[]; // 模型标签
website?: string; // 官方网站
clickCount?: number; // 点击次数
likeCount?: number; // 点赞次数
}

6
types/model/enum.d.ts vendored Normal file
View File

@@ -0,0 +1,6 @@
// AI模型评论排序枚举
export enum CommentSortType {
LATEST = 'latest', // 最新
HOTTEST = 'hottest', // 最热
HIGHEST_RATING = 'highest_rating' // 评分最高
}

4
types/model/index.d.ts vendored Normal file
View File

@@ -0,0 +1,4 @@
// 导出所有模型相关的类型定义
export * from './base';
export * from './api';
export * from './enum';

124
types/post/api.d.ts vendored Normal file
View File

@@ -0,0 +1,124 @@
import type { BaseEntityContent, Post, PostComment } from './base';
import type {
PostType,
PostSortBy,
CommentSortBy,
SortOrder
} from './enum';
// 创建帖子请求接口
export interface CreatePostRequest extends BaseEntityContent {
type: PostType; // 帖子类型:提问或文章
images?: string[]; // 图片
publishedAt?: Date; // 发布时间
}
// 创建帖子响应接口
export interface CreatePostResponse {
post: Post;
}
// 获取帖子列表请求接口
export interface GetPostsRequest {
page?: number; // 页码
limit?: number; // 每页数量
sortBy?: PostSortBy; // 帖子排序方式
type?: PostType; // 帖子类型:提问或文章
sortOrder?: SortOrder; // 排序方向
authorId?: string;
search?: string;
}
// 获取帖子列表响应接口
export interface GetPostsResponse {
data: Post[]; // 数据列表
total: number; // 总数
page: number; // 当前页码
limit: number; // 每页数量
hasMore: boolean; // 是否有更多数据
sortBy?: PostSortBy; // 帖子排序方式
}
// 获取帖子详情请求接口
export interface GetPostRequest {
postId: string;
}
// 获取帖子详情响应接口
export interface GetPostResponse {
post: Post;
}
// 点赞帖子请求接口
export interface LikePostRequest {
postId: string;
}
// 点赞帖子响应接口
export interface LikePostResponse {
success: boolean;
}
// 收藏帖子请求接口
export interface BookmarkPostRequest {
postId: string;
}
// 收藏帖子响应接口
export interface BookmarkPostResponse {
success: boolean;
}
// 创建评论请求接口
export interface CreateCommentRequest {
postId: string;
content: string;
parentId?: string;
}
// 创建评论响应接口
export interface CreateCommentResponse {
comment: PostComment;
}
// 获取评论列表请求接口
export interface GetCommentsRequest {
page?: number; // 页码
limit?: number; // 每页数量
sortOrder?: SortOrder; // 排序方向
postId: string;
parentId?: string;
sortBy?: CommentSortBy;
}
// 获取评论列表响应接口
export interface GetCommentsResponse {
data: PostComment[]; // 数据列表
total: number; // 总数
page: number; // 当前页码
limit: number; // 每页数量
hasMore: boolean; // 是否有更多数据
}
// 点赞评论请求接口
export interface LikeCommentRequest {
commentId: string;
}
// 点赞评论响应接口
export interface LikeCommentResponse {
success: boolean;
}
// 后面全部暂时不考虑
// 删除帖子请求接口
export interface DeletePostRequest {
postId: string;
}
// 删除帖子响应接口
export interface DeletePostResponse {
success: boolean;
}

41
types/post/base.d.ts vendored Normal file
View File

@@ -0,0 +1,41 @@
import type {User} from '../user/base';
import type {PostType} from './enum';
// 基础实体接口
export interface BaseEntity {
id: string; // 唯一标识符
createdAt: Date; // 创建时间
updatedAt: Date; // 更新时间
}
// 用户基础信息接口
export interface BaseUser {
user: User;
}
export interface PostComment extends BaseEntity {
authorId: string; // 作者ID
author: BaseUser; // 作者信息
content: string; // 评论内容
parentId?: string; // 父评论ID用于嵌套评论
}
// 实体内容和统计信息基础接口
export interface BaseEntityContent {
title?: string; // 标题
excerpt: string; // 摘要
tags?: string[]; // 标签数组
metadata?: Record<string, unknown>; // 元数据
stars: number; // 收藏数
likes: number; // 点赞数
comments: number; // 评论数
}
// 帖子接口
export interface Post extends BaseEntity, BaseEntityContent {
type: PostType; // 帖子类型:提问或文章
authorId: string; // 作者ID
author: BaseUser; // 作者信息
images?: string[]; // 图片数组
publishedAt?: Date; // 发布时间
}

28
types/post/enum.d.ts vendored Normal file
View File

@@ -0,0 +1,28 @@
// 排序方式枚举
export enum SortOrder {
ASC = 'asc',
DESC = 'desc'
}
// 排序字段枚举
export enum PostSortBy {
CREATED_AT = 'createdAt',
UPDATED_AT = 'updatedAt',
PUBLISHED_AT = 'publishedAt',
VIEWS = 'views',
LIKES = 'likes',
COMMENTS = 'comments'
}
// 评论排序字段枚举
export enum CommentSortBy {
CREATED_AT = 'createdAt',
LIKES = 'likes',
REPLIES = 'replies'
}
// 帖子类型枚举
export enum PostType {
QUESTION = 'question',
ARTICLE = 'article'
}

4
types/post/index.d.ts vendored Normal file
View File

@@ -0,0 +1,4 @@
// 导出帖子系统所有类型定义
export * from './base';
export * from './enum';
export * from './api';

52
types/user/base.d.ts vendored Normal file
View File

@@ -0,0 +1,52 @@
import { NotificationType } from './enum';
// 最小用户信息
export interface User{
id: string;
username: string;
}
// 认证
export interface LoginRequest{
username: string;
password: string;
}
export interface LoginResponse{
user: User;
sessionId: string;
}
export interface RegisterRequest {
username: string;
email: string;
password: string;
}
export interface RegisterResponse {
user: User;
sessionId: string;
}
export interface ChangePasswordRequest { // 暂时用不到
oldPassword: string;
newPassword: string;
}
export interface RefreshTokenRequest {
sessionId: string;
}
export interface RefreshTokenResponse {
sessionId: string;
}
// 用户通知
export interface UserNotification { // 暂时用不到
id: string;
userId: string;
type: NotificationType;
content: string;
isRead: boolean;
createdAt: Date;
}

8
types/user/enum.d.ts vendored Normal file
View File

@@ -0,0 +1,8 @@
// 通知类型枚举
export enum NotificationType {
LIKE = 'like',
COMMENT = 'comment',
FOLLOW = 'follow',
MENTION = 'mention'
}

4
types/user/index.d.ts vendored Normal file
View File

@@ -0,0 +1,4 @@
export * from './base';
export * from './profile';
export * from './search';
export * from './enum';

36
types/user/profile.d.ts vendored Normal file
View File

@@ -0,0 +1,36 @@
import type { User } from './base';
// 用户档案以及更新
export interface UserProfile{
user: User;
avatar: string;
introduction: string;
level: string;
}
export interface UserProfileUpdateRequest {
avatar?: string;
introduction?: string;
level?: string;
}
export interface UserProfileUpdateResponse {
profile: UserProfile;
}
// 用户关系
export interface UserRelation {
id: string;
followerId: string[];
followingId: string[];
}
export interface UserFollowRequest {
userId: string;
}
export interface UserFollowResponse {
success: boolean;
}

12
types/user/search.d.ts vendored Normal file
View File

@@ -0,0 +1,12 @@
import type { UserProfile } from './profile';
// 用户搜索结果
export interface UserSearchRequest {
keyword: string;
}
export interface UserSearchResponse {
users: Array<UserProfile>
total: number;
}