🎨 优化扩展模块,完成ai接入和对话功能
This commit is contained in:
64
server/model/app/response/chat.go
Normal file
64
server/model/app/response/chat.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package response
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// ChatResponse 对话响应
|
||||
type ChatResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Title string `json:"title"`
|
||||
CharacterID *uint `json:"characterId"`
|
||||
CharacterName string `json:"characterName"`
|
||||
CharacterAvatar string `json:"characterAvatar"`
|
||||
ChatType string `json:"chatType"`
|
||||
LastMessageAt *time.Time `json:"lastMessageAt"`
|
||||
MessageCount int `json:"messageCount"`
|
||||
IsPinned bool `json:"isPinned"`
|
||||
LastMessage *MessageBrief `json:"lastMessage,omitempty"` // 最后一条消息摘要
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
}
|
||||
|
||||
// MessageBrief 消息摘要(用于对话列表显示)
|
||||
type MessageBrief struct {
|
||||
Content string `json:"content"`
|
||||
Role string `json:"role"`
|
||||
}
|
||||
|
||||
// ChatListResponse 对话列表响应
|
||||
type ChatListResponse struct {
|
||||
List []ChatResponse `json:"list"`
|
||||
Total int64 `json:"total"`
|
||||
Page int `json:"page"`
|
||||
PageSize int `json:"pageSize"`
|
||||
}
|
||||
|
||||
// MessageResponse 消息响应
|
||||
type MessageResponse struct {
|
||||
ID uint `json:"id"`
|
||||
ChatID uint `json:"chatId"`
|
||||
Content string `json:"content"`
|
||||
Role string `json:"role"` // user / assistant / system
|
||||
CharacterID *uint `json:"characterId"`
|
||||
CharacterName string `json:"characterName,omitempty"`
|
||||
Model string `json:"model,omitempty"`
|
||||
PromptTokens int `json:"promptTokens,omitempty"`
|
||||
CompletionTokens int `json:"completionTokens,omitempty"`
|
||||
TotalTokens int `json:"totalTokens,omitempty"`
|
||||
SequenceNumber int `json:"sequenceNumber"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
}
|
||||
|
||||
// MessageListResponse 消息列表响应
|
||||
type MessageListResponse struct {
|
||||
List []MessageResponse `json:"list"`
|
||||
Total int64 `json:"total"`
|
||||
Page int `json:"page"`
|
||||
PageSize int `json:"pageSize"`
|
||||
}
|
||||
|
||||
// ChatDetailResponse 对话详情响应(包含角色信息 + 消息列表)
|
||||
type ChatDetailResponse struct {
|
||||
Chat ChatResponse `json:"chat"`
|
||||
Messages []MessageResponse `json:"messages"`
|
||||
}
|
||||
@@ -8,39 +8,44 @@ import (
|
||||
|
||||
// ExtensionResponse 扩展响应
|
||||
type ExtensionResponse struct {
|
||||
ID uint `json:"id"`
|
||||
UserID uint `json:"userId"`
|
||||
Name string `json:"name"`
|
||||
DisplayName string `json:"displayName"`
|
||||
Version string `json:"version"`
|
||||
Author string `json:"author"`
|
||||
Description string `json:"description"`
|
||||
Homepage string `json:"homepage"`
|
||||
Repository string `json:"repository"`
|
||||
License string `json:"license"`
|
||||
Tags []string `json:"tags"`
|
||||
ExtensionType string `json:"extensionType"`
|
||||
Category string `json:"category"`
|
||||
Dependencies map[string]string `json:"dependencies"`
|
||||
Conflicts []string `json:"conflicts"`
|
||||
ManifestData map[string]interface{} `json:"manifestData"`
|
||||
ScriptPath string `json:"scriptPath"`
|
||||
StylePath string `json:"stylePath"`
|
||||
AssetsPaths []string `json:"assetsPaths"`
|
||||
Settings map[string]interface{} `json:"settings"`
|
||||
Options map[string]interface{} `json:"options"`
|
||||
IsEnabled bool `json:"isEnabled"`
|
||||
IsInstalled bool `json:"isInstalled"`
|
||||
IsSystemExt bool `json:"isSystemExt"`
|
||||
InstallSource string `json:"installSource"`
|
||||
InstallDate time.Time `json:"installDate"`
|
||||
LastEnabled time.Time `json:"lastEnabled"`
|
||||
UsageCount int `json:"usageCount"`
|
||||
ErrorCount int `json:"errorCount"`
|
||||
LoadTime int `json:"loadTime"`
|
||||
Metadata map[string]interface{} `json:"metadata"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
ID uint `json:"id"`
|
||||
UserID uint `json:"userId"`
|
||||
Name string `json:"name"`
|
||||
DisplayName string `json:"displayName"`
|
||||
Version string `json:"version"`
|
||||
Author string `json:"author"`
|
||||
Description string `json:"description"`
|
||||
Homepage string `json:"homepage"`
|
||||
Repository string `json:"repository"`
|
||||
License string `json:"license"`
|
||||
Tags []string `json:"tags"`
|
||||
ExtensionType string `json:"extensionType"`
|
||||
Category string `json:"category"`
|
||||
Dependencies map[string]string `json:"dependencies"`
|
||||
Conflicts []string `json:"conflicts"`
|
||||
ManifestData map[string]interface{} `json:"manifestData"`
|
||||
ScriptPath string `json:"scriptPath"`
|
||||
StylePath string `json:"stylePath"`
|
||||
AssetsPaths []string `json:"assetsPaths"`
|
||||
Settings map[string]interface{} `json:"settings"`
|
||||
Options map[string]interface{} `json:"options"`
|
||||
IsEnabled bool `json:"isEnabled"`
|
||||
IsInstalled bool `json:"isInstalled"`
|
||||
IsSystemExt bool `json:"isSystemExt"`
|
||||
InstallSource string `json:"installSource"`
|
||||
SourceURL string `json:"sourceUrl"`
|
||||
Branch string `json:"branch"`
|
||||
AutoUpdate bool `json:"autoUpdate"`
|
||||
InstallDate time.Time `json:"installDate"`
|
||||
LastEnabled time.Time `json:"lastEnabled"`
|
||||
LastUpdateCheck *time.Time `json:"lastUpdateCheck"`
|
||||
AvailableVersion string `json:"availableVersion"`
|
||||
UsageCount int `json:"usageCount"`
|
||||
ErrorCount int `json:"errorCount"`
|
||||
LoadTime int `json:"loadTime"`
|
||||
Metadata map[string]interface{} `json:"metadata"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
// ExtensionListResponse 扩展列表响应
|
||||
@@ -151,38 +156,43 @@ func ToExtensionResponse(ext *app.AIExtension) ExtensionResponse {
|
||||
}
|
||||
|
||||
return ExtensionResponse{
|
||||
ID: ext.ID,
|
||||
UserID: ext.UserID,
|
||||
Name: ext.Name,
|
||||
DisplayName: ext.DisplayName,
|
||||
Version: ext.Version,
|
||||
Author: ext.Author,
|
||||
Description: ext.Description,
|
||||
Homepage: ext.Homepage,
|
||||
Repository: ext.Repository,
|
||||
License: ext.License,
|
||||
Tags: tags,
|
||||
ExtensionType: ext.ExtensionType,
|
||||
Category: ext.Category,
|
||||
Dependencies: dependencies,
|
||||
Conflicts: conflicts,
|
||||
ManifestData: manifestData,
|
||||
ScriptPath: ext.ScriptPath,
|
||||
StylePath: ext.StylePath,
|
||||
AssetsPaths: assetsPaths,
|
||||
Settings: settings,
|
||||
Options: options,
|
||||
IsEnabled: ext.IsEnabled,
|
||||
IsInstalled: ext.IsInstalled,
|
||||
IsSystemExt: ext.IsSystemExt,
|
||||
InstallSource: ext.InstallSource,
|
||||
InstallDate: ext.InstallDate,
|
||||
LastEnabled: ext.LastEnabled,
|
||||
UsageCount: ext.UsageCount,
|
||||
ErrorCount: ext.ErrorCount,
|
||||
LoadTime: ext.LoadTime,
|
||||
Metadata: metadata,
|
||||
CreatedAt: ext.CreatedAt,
|
||||
UpdatedAt: ext.UpdatedAt,
|
||||
ID: ext.ID,
|
||||
UserID: ext.UserID,
|
||||
Name: ext.Name,
|
||||
DisplayName: ext.DisplayName,
|
||||
Version: ext.Version,
|
||||
Author: ext.Author,
|
||||
Description: ext.Description,
|
||||
Homepage: ext.Homepage,
|
||||
Repository: ext.Repository,
|
||||
License: ext.License,
|
||||
Tags: tags,
|
||||
ExtensionType: ext.ExtensionType,
|
||||
Category: ext.Category,
|
||||
Dependencies: dependencies,
|
||||
Conflicts: conflicts,
|
||||
ManifestData: manifestData,
|
||||
ScriptPath: ext.ScriptPath,
|
||||
StylePath: ext.StylePath,
|
||||
AssetsPaths: assetsPaths,
|
||||
Settings: settings,
|
||||
Options: options,
|
||||
IsEnabled: ext.IsEnabled,
|
||||
IsInstalled: ext.IsInstalled,
|
||||
IsSystemExt: ext.IsSystemExt,
|
||||
InstallSource: ext.InstallSource,
|
||||
SourceURL: ext.SourceURL,
|
||||
Branch: ext.Branch,
|
||||
AutoUpdate: ext.AutoUpdate,
|
||||
InstallDate: ext.InstallDate,
|
||||
LastEnabled: ext.LastEnabled,
|
||||
LastUpdateCheck: ext.LastUpdateCheck,
|
||||
AvailableVersion: ext.AvailableVersion,
|
||||
UsageCount: ext.UsageCount,
|
||||
ErrorCount: ext.ErrorCount,
|
||||
LoadTime: ext.LoadTime,
|
||||
Metadata: metadata,
|
||||
CreatedAt: ext.CreatedAt,
|
||||
UpdatedAt: ext.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
92
server/model/app/response/provider.go
Normal file
92
server/model/app/response/provider.go
Normal file
@@ -0,0 +1,92 @@
|
||||
package response
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ProviderResponse 提供商响应
|
||||
type ProviderResponse struct {
|
||||
ID uint `json:"id"`
|
||||
ProviderName string `json:"providerName"`
|
||||
ProviderType string `json:"providerType"`
|
||||
BaseURL string `json:"baseUrl"`
|
||||
APIKeySet bool `json:"apiKeySet"` // 是否已设置API密钥(不返回明文)
|
||||
APIKeyHint string `json:"apiKeyHint"` // API密钥提示(如 sk-****1234)
|
||||
APIConfig json.RawMessage `json:"apiConfig"`
|
||||
Capabilities json.RawMessage `json:"capabilities"`
|
||||
IsEnabled bool `json:"isEnabled"`
|
||||
IsDefault bool `json:"isDefault"`
|
||||
SortOrder int `json:"sortOrder"`
|
||||
Models []ModelResponse `json:"models"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
// ModelResponse 模型响应
|
||||
type ModelResponse struct {
|
||||
ID uint `json:"id"`
|
||||
ProviderID uint `json:"providerId"`
|
||||
ModelName string `json:"modelName"`
|
||||
DisplayName string `json:"displayName"`
|
||||
ModelType string `json:"modelType"`
|
||||
Config json.RawMessage `json:"config"`
|
||||
IsEnabled bool `json:"isEnabled"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
}
|
||||
|
||||
// ProviderListResponse 提供商列表响应
|
||||
type ProviderListResponse struct {
|
||||
List []ProviderResponse `json:"list"`
|
||||
Total int64 `json:"total"`
|
||||
Page int `json:"page"`
|
||||
PageSize int `json:"pageSize"`
|
||||
}
|
||||
|
||||
// TestProviderResponse 测试连通性响应
|
||||
type TestProviderResponse struct {
|
||||
Success bool `json:"success"`
|
||||
Message string `json:"message"`
|
||||
Models []string `json:"models,omitempty"` // 获取到的可用模型列表
|
||||
Latency int64 `json:"latency"` // 响应延迟(毫秒)
|
||||
}
|
||||
|
||||
// ProviderTypeOption 提供商类型选项(前端下拉用)
|
||||
type ProviderTypeOption struct {
|
||||
Value string `json:"value"` // 类型标识
|
||||
Label string `json:"label"` // 显示名称
|
||||
Description string `json:"description"` // 描述
|
||||
DefaultURL string `json:"defaultUrl"` // 默认API地址
|
||||
}
|
||||
|
||||
// PresetModelOption 预设模型选项
|
||||
type PresetModelOption struct {
|
||||
ModelName string `json:"modelName"`
|
||||
DisplayName string `json:"displayName"`
|
||||
ModelType string `json:"modelType"` // chat / image_gen
|
||||
}
|
||||
|
||||
// RemoteModel 远程获取到的模型信息
|
||||
type RemoteModel struct {
|
||||
ID string `json:"id"` // 模型标识(API调用用)
|
||||
DisplayName string `json:"displayName"` // 显示名称
|
||||
OwnedBy string `json:"ownedBy"` // 所有者/来源
|
||||
}
|
||||
|
||||
// FetchRemoteModelsResponse 获取远程模型列表响应
|
||||
type FetchRemoteModelsResponse struct {
|
||||
Success bool `json:"success"`
|
||||
Message string `json:"message"`
|
||||
Models []RemoteModel `json:"models"`
|
||||
Latency int64 `json:"latency"` // 响应延迟(毫秒)
|
||||
}
|
||||
|
||||
// SendTestMessageResponse 发送测试消息响应
|
||||
type SendTestMessageResponse struct {
|
||||
Success bool `json:"success"`
|
||||
Message string `json:"message"` // 状态信息
|
||||
Reply string `json:"reply"` // AI 回复内容
|
||||
Model string `json:"model"` // 实际使用的模型
|
||||
Latency int64 `json:"latency"` // 响应延迟(毫秒)
|
||||
Tokens int `json:"tokens"` // 消耗的token数
|
||||
}
|
||||
Reference in New Issue
Block a user