package response import ( "encoding/json" "git.echol.cn/loser/st/server/model/app" "time" ) // WorldBookResponse 世界书响应 type WorldBookResponse struct { ID uint `json:"id"` UserID uint `json:"userId"` BookName string `json:"bookName"` IsGlobal bool `json:"isGlobal"` Entries []app.AIWorldInfoEntry `json:"entries"` LinkedChars []string `json:"linkedChars"` EntryCount int `json:"entryCount"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` } // WorldBookListResponse 世界书列表响应 type WorldBookListResponse struct { List []WorldBookResponse `json:"list"` Total int64 `json:"total"` Page int `json:"page"` PageSize int `json:"pageSize"` } // WorldBookExportData 世界书导出数据 type WorldBookExportData struct { Name string `json:"name"` Entries []app.AIWorldInfoEntry `json:"entries"` } // MatchedWorldInfoEntry 匹配到的世界书条目 type MatchedWorldInfoEntry struct { Content string `json:"content"` Position string `json:"position"` Order int `json:"order"` Source string `json:"source"` // 来源世界书名称 } // MatchWorldInfoResponse 匹配世界书响应 type MatchWorldInfoResponse struct { Entries []MatchedWorldInfoEntry `json:"entries"` TotalTokens int `json:"totalTokens"` } // ToWorldBookResponse 转换为世界书响应 func ToWorldBookResponse(book *app.AIWorldInfo) WorldBookResponse { var entries []app.AIWorldInfoEntry if book.Entries != nil { _ = json.Unmarshal([]byte(book.Entries), &entries) } if entries == nil { entries = []app.AIWorldInfoEntry{} } linkedChars := book.LinkedChars if linkedChars == nil { linkedChars = []string{} } return WorldBookResponse{ ID: book.ID, UserID: book.UserID, BookName: book.BookName, IsGlobal: book.IsGlobal, Entries: entries, LinkedChars: linkedChars, EntryCount: len(entries), CreatedAt: book.CreatedAt, UpdatedAt: book.UpdatedAt, } }