types.go 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. package service
  2. import "time"
  3. // BroadcastHub 描述 WebSocket Hub 的广播能力。
  4. type BroadcastHub interface {
  5. BroadcastMessage(conversationID uint, messageType string, data interface{})
  6. BroadcastToAllAgents(messageType string, data interface{})
  7. }
  8. // InitConversationInput 对话初始化需要的输入数据。
  9. type InitConversationInput struct {
  10. VisitorID uint
  11. Website string
  12. Referrer string
  13. Browser string
  14. OS string
  15. Language string
  16. IPAddress string
  17. ChatMode string // 对话模式:human(人工客服)、ai(AI客服)
  18. AIConfigID *uint // AI 配置 ID(访客选择的模型配置,AI 模式时必需)
  19. }
  20. // InitConversationResult 对话初始化后的返回结果。
  21. type InitConversationResult struct {
  22. ConversationID uint
  23. Status string
  24. }
  25. // UpdateConversationContactInput 更新访客联系信息时需要的参数。
  26. type UpdateConversationContactInput struct {
  27. ConversationID uint
  28. Email *string
  29. Phone *string
  30. Notes *string
  31. }
  32. // ConversationSummary 用于会话列表展示的概要信息。
  33. type ConversationSummary struct {
  34. ID uint
  35. ConversationType string // visitor | internal
  36. VisitorID uint
  37. AgentID uint
  38. Status string
  39. ChatMode string // human | ai
  40. CreatedAt time.Time
  41. UpdatedAt time.Time
  42. LastMessage *LastMessageSummary
  43. UnreadCount int64
  44. LastSeenAt *time.Time // 最后活跃时间,用于判断在线状态
  45. HasParticipated bool // 当前用户是否参与过该会话(是否发送过消息)
  46. }
  47. // LastMessageSummary 会话最后一条消息的摘要信息。
  48. type LastMessageSummary struct {
  49. ID uint
  50. Content string
  51. SenderIsAgent bool
  52. MessageType string
  53. IsRead bool
  54. ReadAt *time.Time
  55. CreatedAt time.Time
  56. }
  57. // ConversationDetail 在会话概要基础上附加访客信息。
  58. type ConversationDetail struct {
  59. ConversationSummary
  60. Website string
  61. Referrer string
  62. Browser string
  63. OS string
  64. Language string
  65. IPAddress string
  66. Location string
  67. Email string
  68. Phone string
  69. Notes string
  70. LastSeen *time.Time
  71. }
  72. // CreateMessageInput 创建消息时需要的参数。
  73. type CreateMessageInput struct {
  74. ConversationID uint
  75. Content string
  76. SenderID uint
  77. SenderIsAgent bool
  78. // 文件相关字段(可选)
  79. FileURL *string // 文件URL
  80. FileType *string // 文件类型:image, document
  81. FileName *string // 原始文件名
  82. FileSize *int64 // 文件大小(字节)
  83. MimeType *string // MIME类型
  84. }
  85. // CreateAgentInput 创建客服或管理员账号需要的参数。
  86. type CreateAgentInput struct {
  87. Username string
  88. Password string
  89. Role string
  90. }
  91. // MarkMessagesReadResult 消息标记已读后的返回信息。
  92. type MarkMessagesReadResult struct {
  93. ConversationID uint
  94. MessageIDs []uint
  95. UnreadCount int64
  96. ReadAt time.Time
  97. }
  98. // UpdateProfileInput 更新个人资料时需要的参数。
  99. type UpdateProfileInput struct {
  100. UserID uint
  101. Nickname *string
  102. Email *string
  103. ReceiveAIConversations *bool // 是否接收 AI 对话(可选)
  104. }
  105. // ProfileResult 个人资料信息。
  106. type ProfileResult struct {
  107. ID uint `json:"id"`
  108. Username string `json:"username"`
  109. Role string `json:"role"`
  110. AvatarURL string `json:"avatar_url"`
  111. Nickname string `json:"nickname"`
  112. Email string `json:"email"`
  113. ReceiveAIConversations bool `json:"receive_ai_conversations"` // 是否接收 AI 对话
  114. }
  115. // UserSummary 用户列表摘要信息(不包含密码)。
  116. type UserSummary struct {
  117. ID uint `json:"id"`
  118. Username string `json:"username"`
  119. Role string `json:"role"`
  120. Nickname string `json:"nickname"`
  121. Email string `json:"email"`
  122. AvatarURL string `json:"avatar_url"`
  123. ReceiveAIConversations bool `json:"receive_ai_conversations"`
  124. CreatedAt time.Time `json:"created_at"`
  125. UpdatedAt time.Time `json:"updated_at"`
  126. }
  127. // CreateUserInput 创建用户输入。
  128. type CreateUserInput struct {
  129. Username string // 用户名(必需)
  130. Password string // 密码(必需)
  131. Role string // 角色:"admin" 或 "agent"(必需)
  132. Nickname *string // 昵称(可选)
  133. Email *string // 邮箱(可选)
  134. }
  135. // UpdateUserInput 更新用户输入。
  136. type UpdateUserInput struct {
  137. UserID uint // 用户ID(必需)
  138. Role *string // 角色(可选)
  139. Nickname *string // 昵称(可选)
  140. Email *string // 邮箱(可选)
  141. ReceiveAIConversations *bool // 是否接收 AI 对话(可选)
  142. }
  143. // UpdatePasswordInput 更新密码输入。
  144. type UpdatePasswordInput struct {
  145. UserID uint // 用户ID(必需)
  146. OldPassword *string // 旧密码(可选,管理员修改其他用户密码时不需要)
  147. NewPassword string // 新密码(必需)
  148. IsAdmin bool // 是否是管理员操作(必需)
  149. }
  150. // FAQSummary FAQ(常见问题)摘要信息。
  151. type FAQSummary struct {
  152. ID uint `json:"id"`
  153. Question string `json:"question"` // 问题
  154. Answer string `json:"answer"` // 答案
  155. Keywords string `json:"keywords"` // 关键词(用于搜索)
  156. CreatedAt time.Time `json:"created_at"` // 创建时间
  157. UpdatedAt time.Time `json:"updated_at"` // 更新时间
  158. }
  159. // CreateFAQInput 创建 FAQ 输入。
  160. type CreateFAQInput struct {
  161. Question string // 问题(必需)
  162. Answer string // 答案(必需)
  163. Keywords string // 关键词(可选,用逗号或空格分隔)
  164. }
  165. // UpdateFAQInput 更新 FAQ 输入。
  166. type UpdateFAQInput struct {
  167. Question *string // 问题(可选)
  168. Answer *string // 答案(可选)
  169. Keywords *string // 关键词(可选)
  170. }
  171. // OnlineAgent 在线客服信息(供访客查看)。
  172. type OnlineAgent struct {
  173. ID uint `json:"id"` // 客服ID
  174. Nickname string `json:"nickname"` // 昵称
  175. AvatarURL string `json:"avatar_url"` // 头像URL
  176. }
  177. // DocumentSummary 文档摘要信息。
  178. type DocumentSummary struct {
  179. ID uint `json:"id"`
  180. KnowledgeBaseID uint `json:"knowledge_base_id"`
  181. Title string `json:"title"`
  182. Content string `json:"content"`
  183. Summary string `json:"summary"`
  184. Type string `json:"type"`
  185. Status string `json:"status"`
  186. EmbeddingStatus string `json:"embedding_status"`
  187. CreatedAt time.Time `json:"created_at"`
  188. UpdatedAt time.Time `json:"updated_at"`
  189. }
  190. // CreateDocumentInput 创建文档输入。
  191. type CreateDocumentInput struct {
  192. KnowledgeBaseID uint // 知识库 ID(必需)
  193. Title string // 文档标题(必需)
  194. Content string // 文档内容(必需)
  195. Summary string // 文档摘要(可选)
  196. Type string // 文档类型(可选,默认:document)
  197. Status string // 文档状态(可选,默认:draft)
  198. Metadata map[string]interface{} // 元数据(可选)
  199. }
  200. // UpdateDocumentInput 更新文档输入。
  201. type UpdateDocumentInput struct {
  202. Title *string // 文档标题(可选)
  203. Content *string // 文档内容(可选)
  204. Summary *string // 文档摘要(可选)
  205. Type *string // 文档类型(可选)
  206. Status *string // 文档状态(可选)
  207. Metadata *map[string]interface{} // 元数据(可选)
  208. }
  209. // DocumentListResult 文档列表查询结果。
  210. type DocumentListResult struct {
  211. Documents []DocumentSummary `json:"documents"` // 文档列表
  212. Total int64 `json:"total"` // 总记录数
  213. Page int `json:"page"` // 当前页码
  214. PageSize int `json:"page_size"` // 每页大小
  215. TotalPage int `json:"total_page"` // 总页数
  216. }
  217. // KnowledgeBaseSummary 知识库摘要信息。
  218. type KnowledgeBaseSummary struct {
  219. ID uint `json:"id"`
  220. Name string `json:"name"`
  221. Description string `json:"description"`
  222. DocumentCount int64 `json:"document_count"` // 文档数量(统计信息)
  223. RAGEnabled bool `json:"rag_enabled"` // 是否参与 RAG(对 AI 开放)
  224. CreatedAt time.Time `json:"created_at"`
  225. UpdatedAt time.Time `json:"updated_at"`
  226. }
  227. // CreateKnowledgeBaseInput 创建知识库输入。
  228. type CreateKnowledgeBaseInput struct {
  229. Name string // 知识库名称(必需)
  230. Description string // 知识库描述(可选)
  231. }
  232. // UpdateKnowledgeBaseInput 更新知识库输入。
  233. type UpdateKnowledgeBaseInput struct {
  234. Name *string // 知识库名称(可选)
  235. Description *string // 知识库描述(可选)
  236. RAGEnabled *bool // 是否参与 RAG(可选)
  237. }