Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

session.go 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package model
  2. import (
  3. "time"
  4. "go.mongodb.org/mongo-driver/bson/primitive"
  5. )
  6. // SessionStatus 会话状态枚举
  7. const (
  8. StatusRequirementDocument = "requirement_document" // 需求文档
  9. StatusTechnicalDocument = "technical_document" // 技术文档
  10. StatusCode = "code" // 代码
  11. StatusTest = "test" // 测试
  12. StatusRelease = "release" // 发布
  13. )
  14. // IsValidStatus 验证状态是否有效
  15. func IsValidStatus(status string) bool {
  16. validStatuses := []string{
  17. StatusRequirementDocument,
  18. StatusTechnicalDocument,
  19. StatusCode,
  20. StatusTest,
  21. StatusRelease,
  22. }
  23. for _, s := range validStatuses {
  24. if s == status {
  25. return true
  26. }
  27. }
  28. return false
  29. }
  30. // Agent 智能体枚举
  31. const (
  32. AgentReplenish = "replenish" // 补货
  33. AgentTransfer = "transfer" // 调拨
  34. AgentAllocation = "allocation" // 配货
  35. AgentReport = "report" // 报表
  36. )
  37. // AgentDisplayName 智能体显示名称映射
  38. var AgentDisplayName = map[string]string{
  39. AgentReplenish: "补货",
  40. AgentTransfer: "调拨",
  41. AgentAllocation: "配货",
  42. AgentReport: "报表",
  43. }
  44. // GetAllAgents 获取所有智能体列表
  45. func GetAllAgents() []map[string]string {
  46. agents := []map[string]string{}
  47. for id, name := range AgentDisplayName {
  48. agents = append(agents, map[string]string{
  49. "id": id,
  50. "name": name,
  51. })
  52. }
  53. return agents
  54. }
  55. // IsValidAgent 验证智能体名称是否有效
  56. func IsValidAgent(agentName string) bool {
  57. _, exists := AgentDisplayName[agentName]
  58. return exists
  59. }
  60. // Session 主会话文档
  61. type Session struct {
  62. ID string `bson:"_id" json:"id"` // opencode会话ID,作为主键
  63. ProjectID string `bson:"project_id" json:"project_id"` // 项目ID(新增)
  64. Title string `bson:"title" json:"title"` // 标题
  65. AgentName string `bson:"agent_name" json:"agent_name"` // 智能体名称
  66. Description string `bson:"description" json:"description"` // 项目描述(新增)
  67. Status string `bson:"status" json:"status"` // 状态
  68. UserID string `bson:"user_id" json:"user_id"` // 用户ID
  69. TenantID string `bson:"tenant_id" json:"tenant_id"` // 租户ID
  70. CreatedAt time.Time `bson:"created_at" json:"created_at"` // 创建时间
  71. UpdatedAt time.Time `bson:"updated_at" json:"updated_at"` // 更新时间
  72. }
  73. // CodeItem 代码项
  74. type CodeItem struct {
  75. Order int `bson:"order" json:"order"` // 执行次序
  76. Title string `bson:"title" json:"title"` // 步骤标题(新增)
  77. SelectPart string `bson:"select_part" json:"select_part"` // select 部分SQL代码
  78. FromPart string `bson:"from_part" json:"from_part"` // from 部分代码
  79. WherePart string `bson:"where_part" json:"where_part"` // where 部分
  80. GroupByPart string `bson:"group_by_part" json:"group_by_part"` // group by 部分
  81. OrderByPart string `bson:"order_by_part" json:"order_by_part"` // order by 部分
  82. TempTableName string `bson:"temp_table_name" json:"temp_table_name"` // 临时表名称
  83. Parameters map[string]interface{} `bson:"parameters" json:"parameters"` // 参数集合
  84. ReturnColumns map[string]string `bson:"return_columns" json:"return_columns"` // 返回的列名称和对应的中文名称(映射)
  85. }
  86. // SessionDetail 明细文档
  87. type SessionDetail struct {
  88. ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"` // MongoDB自动生成的ID
  89. SessionID string `bson:"session_id" json:"session_id"` // 关联的会话ID
  90. RequirementDoc string `bson:"requirement_doc" json:"requirement_doc"` // 需求文档
  91. TechnicalDoc string `bson:"technical_doc" json:"technical_doc"` // 技术文档
  92. CodeItems []CodeItem `bson:"code_items" json:"code_items"` // 代码数组
  93. HistorySessions []string `bson:"history_sessions" json:"history_sessions"` // 历史会话ID数组(新增)
  94. CreatedAt time.Time `bson:"created_at" json:"created_at"` // 创建时间
  95. UpdatedAt time.Time `bson:"updated_at" json:"updated_at"` // 更新时间
  96. }
  97. // SessionWithDetail 包含主会话和明细的完整响应
  98. type SessionWithDetail struct {
  99. Session *Session `json:"session"`
  100. Detail *SessionDetail `json:"detail,omitempty"`
  101. HistoryCount int `json:"history_count,omitempty"` // 历史消息数量
  102. }
  103. // SessionCollectionName 返回会话集合名称
  104. func (Session) CollectionName() string {
  105. return "code_sessions"
  106. }
  107. // SessionDetailCollectionName 返回会话明细集合名称
  108. func (SessionDetail) CollectionName() string {
  109. return "code_session_details"
  110. }