domain

package
v0.0.0-...-c20d9b3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2025 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AcceptCompletionReq

type AcceptCompletionReq struct {
	ID         string `json:"id"`         // 记录ID
	Completion string `json:"completion"` // 补全内容
}

type ActivityStats

type ActivityStats struct {
	ChatCount       int64   `json:"chat_count"`       // 对话次数
	CompletionCount int64   `json:"completion_count"` // 补全生成次数
	AcceptedCount   int64   `json:"accepted_count"`   // 补全采纳次数
	TotalCodeLines  int64   `json:"total_code_lines"` // 总代码量(行数)
	AcceptanceRate  float64 `json:"acceptance_rate"`  // 采纳率 (accepted_count / completion_count)
}

type AdminLoginHistory

type AdminLoginHistory struct {
	User          *AdminUser `json:"user"`           // 用户信息
	IPInfo        *IPInfo    `json:"ip_info"`        // IP信息
	ClientVersion string     `json:"client_version"` // 客户端版本
	Device        string     `json:"device"`         // 设备信息
	CreatedAt     int64      `json:"created_at"`     // 登录时间
}

func (*AdminLoginHistory) From

type AdminLoginReq

type AdminLoginReq struct {
	Account  string `json:"account"`  // 用户名
	Password string `json:"password"` // 密码
}

type AdminUser

type AdminUser struct {
	ID           uuid.UUID          `json:"id"`             // 用户ID
	Username     string             `json:"username"`       // 用户名
	LastActiveAt int64              `json:"last_active_at"` // 最后活跃时间
	Status       consts.AdminStatus `json:"status"`         // 用户状态 active: 正常 inactive: 禁用
	Role         *Role              `json:"role"`           // 角色
	CreatedAt    int64              `json:"created_at"`     // 创建时间
}

func (*AdminUser) From

func (a *AdminUser) From(e *db.Admin) *AdminUser

func (*AdminUser) IsAdmin

func (a *AdminUser) IsAdmin() bool

type AllModelResp

type AllModelResp struct {
	Providers []ProviderModel `json:"providers"` // 提供商列表
}

type ApiConfig

type ApiConfig struct {
	ApiProvider           string                `json:"apiProvider"`
	ApiModelId            string                `json:"apiModelId"`
	OpenAiBaseUrl         string                `json:"openAiBaseUrl"`
	OpenAiApiKey          string                `json:"openAiApiKey"`
	OpenAiModelId         string                `json:"openAiModelId"`
	OpenAiR1FormatEnabled bool                  `json:"openAiR1FormatEnabled"`
	OpenAiCustomModelInfo OpenAiCustomModelInfo `json:"openAiCustomModelInfo"`
	Id                    string                `json:"id"`
}

type ApiKey

type ApiKey struct {
	ID        string `json:"id"`
	CreatedAt int64  `json:"created_at"`
	UpdatedAt int64  `json:"updated_at"`
	UserID    string `json:"user_id"`
	Key       string `json:"key"`
}

func (*ApiKey) From

func (a *ApiKey) From(e *db.ApiKey) *ApiKey

type BatchCreateWorkspaceFileReq

type BatchCreateWorkspaceFileReq struct {
	UserID      string                    `json:"user_id" validate:"required"`      // 用户ID
	WorkspaceID string                    `json:"workspace_id" validate:"required"` // 工作区ID
	Files       []*CreateWorkspaceFileReq `json:"files" validate:"required,dive"`   // 文件列表
}

type BatchUpdateWorkspaceFileReq

type BatchUpdateWorkspaceFileReq struct {
	Files []*UpdateWorkspaceFileReq `json:"files" validate:"required,dive"` // 文件列表
}

type BillingQuota

type BillingQuota struct {
	ID        string `json:"id"`
	CreatedAt int64  `json:"created_at"`
	UpdatedAt int64  `json:"updated_at"`
	UserID    string `json:"user_id"`
	Total     int64  `json:"total"`
	Used      int64  `json:"used"`
	Remain    int64  `json:"remain"`
}

func (*BillingQuota) From

type BillingRepo

type BillingRepo interface {
	ListChatRecord(ctx context.Context, req ListRecordReq) (*ListChatRecordResp, error)
	ListCompletionRecord(ctx context.Context, req ListRecordReq) (*ListCompletionRecordResp, error)
	CompletionInfo(ctx context.Context, id, userID string) (*CompletionInfo, error)
	ChatInfo(ctx context.Context, id, userID string) (*ChatInfo, error)
}

type BillingUsage

type BillingUsage struct {
	ID        string `json:"id"`
	CreatedAt int64  `json:"created_at"`
	UpdatedAt int64  `json:"updated_at"`
	UserID    string `json:"user_id"`
	ModelName string `json:"model_name"`
	Tokens    int64  `json:"tokens"`
	Operation string `json:"operation"`
}

type BillingUsecase

type BillingUsecase interface {
	ListChatRecord(ctx context.Context, req ListRecordReq) (*ListChatRecordResp, error)
	ListCompletionRecord(ctx context.Context, req ListRecordReq) (*ListCompletionRecordResp, error)
	CompletionInfo(ctx context.Context, id, userID string) (*CompletionInfo, error)
	ChatInfo(ctx context.Context, id, userID string) (*ChatInfo, error)
}

type CategoryPoint

type CategoryPoint struct {
	Category string `json:"category"` // 分类
	Value    int64  `json:"value"`    // 值
}

type CategoryStat

type CategoryStat struct {
	WorkMode        []CategoryPoint `json:"work_mode"`        // 工作模式占比
	ProgramLanguage []CategoryPoint `json:"program_language"` // 编程语言占比
}

type ChatContent

type ChatContent struct {
	Role      consts.ChatRole `json:"role"`    // 角色,如user: 用户的提问 assistant: 机器人回复 system: 系统消息
	Content   string          `json:"content"` // 内容
	CreatedAt int64           `json:"created_at"`
}

func (*ChatContent) From

func (c *ChatContent) From(e *db.TaskRecord) *ChatContent

type ChatInfo

type ChatInfo struct {
	ID       string         `json:"id"`
	Contents []*ChatContent `json:"contents"` // 消息内容
}

func (*ChatInfo) From

func (c *ChatInfo) From(e *db.Task) *ChatInfo

type ChatRecord

type ChatRecord struct {
	ID           string `json:"id"`            // 记录ID
	User         *User  `json:"user"`          // 用户
	Model        *Model `json:"model"`         // 模型
	Question     string `json:"question"`      // 问题
	WorkMode     string `json:"work_mode"`     // 工作模式
	InputTokens  int64  `json:"input_tokens"`  // 输入token
	OutputTokens int64  `json:"output_tokens"` // 输出token
	CreatedAt    int64  `json:"created_at"`    // 创建时间
}

func (*ChatRecord) From

func (c *ChatRecord) From(e *db.Task) *ChatRecord

type CheckModelReq

type CheckModelReq struct {
	Type       consts.ModelType     `json:"type" validate:"required,oneof=llm coder embedding rerank"`
	Provider   consts.ModelProvider `json:"provider" validate:"required"`   // 提供商
	ModelName  string               `json:"model_name" validate:"required"` // 模型名称
	APIBase    string               `json:"api_base" validate:"required"`   // 接口地址
	APIKey     string               `json:"api_key"`                        // 接口密钥
	APIVersion string               `json:"api_version"`
	APIHeader  string               `json:"api_header"`
}

type CheckModelResp

type CheckModelResp struct {
	Error string `json:"error"`
	Model *Model `json:"model"`
}

type CodeFiles

type CodeFiles struct {
	Files []FileMeta `json:"files"`
}

type CodeLanguageType

type CodeLanguageType string
const (
	CodeLanguageTypeGo         CodeLanguageType = "go"
	CodeLanguageTypePython     CodeLanguageType = "python"
	CodeLanguageTypeJava       CodeLanguageType = "java"
	CodeLanguageTypeJavaScript CodeLanguageType = "javascript"
	CodeLanguageTypeTypeScript CodeLanguageType = "typescript"
	CodeLanguageTypeJSX        CodeLanguageType = "jsx"
	CodeLanguageTypeTSX        CodeLanguageType = "tsx"
	CodeLanguageTypeHTML       CodeLanguageType = "html"
	CodeLanguageTypeCSS        CodeLanguageType = "css"
	CodeLanguageTypePHP        CodeLanguageType = "php"
	CodeLanguageTypeRust       CodeLanguageType = "rust"
	CodeLanguageTypeSwift      CodeLanguageType = "swift"
	CodeLanguageTypeKotlin     CodeLanguageType = "kotlin"
	CodeLanguageTypeC          CodeLanguageType = "c"
	CodeLanguageTypeCpp        CodeLanguageType = "cpp"
)

type CodeSnippet

type CodeSnippet struct {
	ID              string           `json:"id"`                  // 代码片段ID
	WorkspaceFileID string           `json:"workspace_file_id"`   // 关联的workspace file ID
	Name            string           `json:"name"`                // 代码片段名称
	SnippetType     string           `json:"type"`                // 代码片段类型
	Language        string           `json:"language"`            // 编程语言
	Content         string           `json:"rangeText"`           // 代码片段内容
	Hash            string           `json:"fileHash"`            // 内容哈希
	StartLine       int              `json:"startLine"`           // 起始行号
	EndLine         int              `json:"endLine"`             // 结束行号
	StartColumn     int              `json:"startColumn"`         // 起始列号
	EndColumn       int              `json:"endColumn"`           // 结束列号
	FilePath        string           `json:"filePath"`            // 文件路径
	Namespace       string           `json:"namespace"`           // 命名空间
	ContainerName   string           `json:"field"`               // 容器名称
	Scope           []string         `json:"scope"`               // 作用域信息
	Dependencies    []string         `json:"dependencies"`        // 依赖项
	Parameters      []map[string]any `json:"parameters"`          // 参数列表
	Signature       string           `json:"signature"`           // 函数签名
	DefinitionText  string           `json:"definitionText"`      // 定义文本
	StructuredInfo  map[string]any   `json:"definition"`          // 结构化信息
	Embedding       []float32        `json:"embedding,omitempty"` // 向量嵌入
}

数据模型

func FromCodeSnippets

func FromCodeSnippets(snippets []*db.CodeSnippet) []*CodeSnippet

工具函数

func (*CodeSnippet) From

func (c *CodeSnippet) From(e *db.CodeSnippet) *CodeSnippet

func (*CodeSnippet) FromWithFile

func (c *CodeSnippet) FromWithFile(e *db.CodeSnippet) *CodeSnippet

从包含WorkspaceFile信息的CodeSnippet创建domain对象

type CodeSnippetRepo

type CodeSnippetRepo interface {
	Create(ctx context.Context, req *CreateCodeSnippetReq) (*db.CodeSnippet, error)
	ListByWorkspaceFile(ctx context.Context, workspaceFileID string) ([]*db.CodeSnippet, error)
	GetByID(ctx context.Context, id string) (*db.CodeSnippet, error)
	Delete(ctx context.Context, id string) error
	Search(ctx context.Context, name, snippetType, language string) ([]*db.CodeSnippet, error)
	SearchByWorkspace(ctx context.Context, userID, workspacePath, name, snippetType, language string) ([]*db.CodeSnippet, error)
	SemanticSearch(ctx context.Context, embedding []float32, limit int) ([]*db.CodeSnippet, error)
	SemanticSearchByWorkspace(ctx context.Context, userID, workspacePath string, embedding []float32, limit int) ([]*db.CodeSnippet, error)
}

CodeSnippetRepo 定义 CodeSnippet 数据访问接口

type CodeSnippetUsecase

type CodeSnippetUsecase interface {
	CreateFromIndexResult(ctx context.Context, workspaceFileID string, indexResult *IndexResult, workspacePath string) (*CodeSnippet, error)
	ListByWorkspaceFile(ctx context.Context, workspaceFileID string) ([]*CodeSnippet, error)
	GetByID(ctx context.Context, id string) (*CodeSnippet, error)
	Delete(ctx context.Context, id string) error
	Search(ctx context.Context, name, snippetType, language string) ([]*CodeSnippet, error)
	SearchByWorkspace(ctx context.Context, userID, workspacePath, name, snippetType, language string) ([]*CodeSnippet, error)
	SemanticSearch(ctx context.Context, embedding []float32, limit int) ([]*CodeSnippet, error)
	SemanticSearchByWorkspace(ctx context.Context, userID, workspacePath string, embedding []float32, limit int) ([]*CodeSnippet, error)
}

CodeSnippetUsecase 定义 CodeSnippet 业务逻辑接口

type CompletionData

type CompletionData struct {
	TaskID          string         `json:"task_id"`          // 任务ID
	UserID          string         `json:"user_id"`          // 用户ID
	ModelID         string         `json:"model_id"`         // 模型ID
	ModelName       string         `json:"model_name"`       // 模型名称
	RequestID       string         `json:"request_id"`       // 请求ID
	ModelType       string         `json:"model_type"`       // 模型类型
	ProgramLanguage string         `json:"program_language"` // 编程语言
	WorkMode        string         `json:"work_mode"`        // 工作模式
	Prompt          string         `json:"prompt"`           // 用户输入的提示
	Completion      string         `json:"completion"`       // LLM生成的补全代码
	SourceCode      string         `json:"source_code"`      // 当前文件原文
	CursorPosition  map[string]any `json:"cursor_position"`  // 光标位置 {"line": 10, "column": 5}
	UserInput       string         `json:"user_input"`       // 用户最终输入的内容
	IsAccept        bool           `json:"is_accept"`        // 用户是否接受补全
	IsSuggested     bool           `json:"is_suggested"`     // 是否为建议模式
	CodeLines       int64          `json:"code_lines"`       // 代码行数
	InputTokens     int64          `json:"input_tokens"`     // 输入token数
	OutputTokens    int64          `json:"output_tokens"`    // 输出token数
	CreatedAt       int64          `json:"created_at"`       // 创建时间戳
	UpdatedAt       int64          `json:"updated_at"`       // 更新时间戳
}

CompletionData 补全数据导出结构

type CompletionInfo

type CompletionInfo struct {
	ID        string `json:"id"`
	Prompt    string `json:"prompt"`
	Content   string `json:"content"`
	CreatedAt int64  `json:"created_at"`
}

func (*CompletionInfo) From

func (c *CompletionInfo) From(e *db.Task) *CompletionInfo

type CompletionRecord

type CompletionRecord struct {
	ID              string `json:"id"`               // 记录ID
	User            *User  `json:"user"`             // 用户
	IsAccept        bool   `json:"is_accept"`        // 是否采纳
	ProgramLanguage string `json:"program_language"` // 编程语言
	InputTokens     int64  `json:"input_tokens"`     // 输入token
	OutputTokens    int64  `json:"output_tokens"`    // 输出token
	CreatedAt       int64  `json:"created_at"`       // 创建时间
}

func (*CompletionRecord) From

type CompletionRequest

type CompletionRequest struct {
	openai.CompletionRequest
	Metadata map[string]string `json:"metadata"`
}

type ConfigReq

type ConfigReq struct {
	Type    consts.ConfigType `json:"type" query:"type"`
	Key     string            `json:"-"`
	BaseURL string            `json:"-"`
}

type ConfigResp

type ConfigResp struct {
	Type    consts.ConfigType `json:"type"`
	Content any               `json:"content"`
}

type CreateAdminReq

type CreateAdminReq struct {
	Username string `json:"username" validate:"required"` // 用户名
	Password string `json:"password" validate:"required"` // 密码
	RoleID   int64  `json:"role_id" validate:"required"`  // 角色ID
}

type CreateCodeSnippetReq

type CreateCodeSnippetReq struct {
	WorkspaceFileID string           `json:"workspace_file_id" validate:"required"` // 关联的workspace file ID
	WorkspacePath   string           `json:"workspace_path"`                        // 工作区路径
	Name            string           `json:"name"`                                  // 代码片段名称
	SnippetType     string           `json:"snippet_type"`                          // 代码片段类型 (function, class, variable, etc.)
	Language        string           `json:"language"`                              // 编程语言
	Content         string           `json:"content"`                               // 代码片段内容
	Hash            string           `json:"hash"`                                  // 内容哈希
	StartLine       int              `json:"start_line"`                            // 起始行号
	EndLine         int              `json:"end_line"`                              // 结束行号
	StartColumn     int              `json:"start_column"`                          // 起始列号
	EndColumn       int              `json:"end_column"`                            // 结束列号
	Namespace       string           `json:"namespace"`                             // 命名空间
	ContainerName   string           `json:"container_name"`                        // 容器名称 (类名、模块名等)
	Scope           []string         `json:"scope"`                                 // 作用域信息
	Dependencies    []string         `json:"dependencies"`                          // 依赖项
	Parameters      []map[string]any `json:"parameters"`                            // 参数列表
	Signature       string           `json:"signature"`                             // 函数签名
	DefinitionText  string           `json:"definition_text"`                       // 定义文本
	StructuredInfo  map[string]any   `json:"structured_info"`                       // 结构化信息
	Embedding       []float32        `json:"embedding,omitempty"`                   // 向量嵌入
}

请求结构体

type CreateModelReq

type CreateModelReq struct {
	AdminID    uuid.UUID            `json:"-"`
	ShowName   string               `json:"show_name"`                      // 模型显示名称
	ModelName  string               `json:"model_name" validate:"required"` // 模型名称 如: deepseek-v3
	Provider   consts.ModelProvider `json:"provider" validate:"required"`   // 提供商
	APIBase    string               `json:"api_base" validate:"required"`   // 接口地址 如:https://api.qwen.com
	APIKey     string               `json:"api_key"`                        // 接口密钥 如:sk-xxxx
	APIVersion string               `json:"api_version"`
	APIHeader  string               `json:"api_header"`
	ModelType  consts.ModelType     `json:"model_type"` // 模型类型 llm:对话模型 coder:代码模型
	Param      *ModelParam          `json:"param"`      // 高级参数
}

type CreateSecurityScanningReq

type CreateSecurityScanningReq struct {
	UserID    string                          `json:"user_id"`
	Workspace string                          `json:"workspace"` // 项目目录
	Language  consts.SecurityScanningLanguage `json:"language"`  // 扫描语言
}

type CreateWorkspaceFileReq

type CreateWorkspaceFileReq struct {
	UserID      string `json:"user_id" validate:"required"`      // 用户ID
	WorkspaceID string `json:"workspace_id" validate:"required"` // 工作区ID
	Path        string `json:"path" validate:"required"`         // 文件路径
	Content     string `json:"content"`                          // 文件内容
	Hash        string `json:"hash" validate:"required"`         // 文件哈希
	Language    string `json:"language"`                         // 编程语言
	Size        int64  `json:"size"`                             // 文件大小
}

type CreateWorkspaceReq

type CreateWorkspaceReq struct {
	UserID      string         `json:"user_id" validate:"required"`   // 用户ID
	Name        string         `json:"name" validate:"required"`      // 工作区名称
	Description string         `json:"description"`                   // 工作区描述
	RootPath    string         `json:"root_path" validate:"required"` // 工作区根路径
	Settings    map[string]any `json:"settings"`                      // 工作区设置
}

type CtcodeTabCompletions

type CtcodeTabCompletions struct {
	Enabled       bool   `json:"enabled"`
	ApiProvider   string `json:"apiProvider"`
	OpenAiBaseUrl string `json:"openAiBaseUrl"`
	OpenAiApiKey  string `json:"openAiApiKey"`
	OpenAiModelId string `json:"openAiModelId"`
}

type CustomOAuth

type CustomOAuth struct {
	Enable         bool     `json:"enable"`           // 自定义OAuth开关
	ClientID       string   `json:"client_id"`        // 自定义客户端ID
	ClientSecret   string   `json:"client_secret"`    // 自定义客户端密钥
	AuthorizeURL   string   `json:"authorize_url"`    // 自定义OAuth授权URL
	AccessTokenURL string   `json:"access_token_url"` // 自定义OAuth访问令牌URL
	UserInfoURL    string   `json:"userinfo_url"`     // 自定义OAuth用户信息URL
	Scopes         []string `json:"scopes"`           // 自定义OAuth Scope列表
	IDField        string   `json:"id_field"`         // 用户信息回包中的ID字段名
	NameField      string   `json:"name_field"`       // 用户信息回包中的用户名字段名
	AvatarField    string   `json:"avatar_field"`     // 用户信息回包中的头像URL字段名
	EmailField     string   `json:"email_field"`      // 用户信息回包中的邮箱字段名
}

func (*CustomOAuth) From

type CustomOAuthReq

type CustomOAuthReq struct {
	Enable         *bool    `json:"enable"`           // 自定义OAuth开关
	ClientID       *string  `json:"client_id"`        // 自定义客户端ID
	ClientSecret   *string  `json:"client_secret"`    // 自定义客户端密钥
	AuthorizeURL   *string  `json:"authorize_url"`    // 自定义OAuth授权URL
	AccessTokenURL *string  `json:"access_token_url"` // 自定义OAuth访问令牌URL
	UserInfoURL    *string  `json:"userinfo_url"`     // 自定义OAuth用户信息URL
	Scopes         []string `json:"scopes"`           // 自定义OAuth Scope列表
	IDField        *string  `json:"id_field"`         // 用户信息回包中的ID字段名
	NameField      *string  `json:"name_field"`       // 用户信息回包中的用户名字段名
	AvatarField    *string  `json:"avatar_field"`     // 用户信息回包中的头像URL字段名
	EmailField     *string  `json:"email_field"`      // 用户信息回包中的邮箱字段名
}

type DashboardRepo

type DashboardRepo interface {
	Statistics(ctx context.Context) (*Statistics, error)
	CategoryStat(ctx context.Context, req StatisticsFilter) (*CategoryStat, error)
	TimeStat(ctx context.Context, req StatisticsFilter) (*TimeStat, error)
	UserCodeRank(ctx context.Context, req StatisticsFilter) ([]*UserCodeRank, error)
	UserStat(ctx context.Context, req StatisticsFilter) (*UserStat, error)
	UserEvents(ctx context.Context, req StatisticsFilter) ([]*UserEvent, error)
	UserHeatmap(ctx context.Context, userID string) ([]*UserHeatmap, error)
}

type DashboardUsecase

type DashboardUsecase interface {
	Statistics(ctx context.Context) (*Statistics, error)
	CategoryStat(ctx context.Context, req StatisticsFilter) (*CategoryStat, error)
	TimeStat(ctx context.Context, req StatisticsFilter) (*TimeStat, error)
	UserCodeRank(ctx context.Context, req StatisticsFilter) ([]*UserCodeRank, error)
	UserStat(ctx context.Context, req StatisticsFilter) (*UserStat, error)
	UserEvents(ctx context.Context, req StatisticsFilter) ([]*UserEvent, error)
	UserHeatmap(ctx context.Context, userID string) (*UserHeatmapResp, error)
}

type DingtalkOAuth

type DingtalkOAuth struct {
	Enable       bool   `json:"enable"`        // 钉钉OAuth开关
	ClientID     string `json:"client_id"`     // 钉钉客户端ID
	ClientSecret string `json:"client_secret"` // 钉钉客户端密钥
}

func (*DingtalkOAuth) From

type DingtalkOAuthReq

type DingtalkOAuthReq struct {
	Enable       *bool   `json:"enable"`        // 钉钉OAuth开关
	ClientID     *string `json:"client_id"`     // 钉钉客户端ID
	ClientSecret *string `json:"client_secret"` // 钉钉客户端密钥
}

type ExportCompletionDataResp

type ExportCompletionDataResp struct {
	TotalCount int64             `json:"total_count"` // 总记录数
	Data       []*CompletionData `json:"data"`        // 补全数据列表
}

ExportCompletionDataResp 导出补全数据响应

type Extension

type Extension struct {
	ID        uuid.UUID `json:"id"`
	Version   string    `json:"version"`
	Path      string    `json:"path"`
	CreatedAt int64     `json:"created_at"`
}

func (*Extension) From

func (et *Extension) From(e *db.Extension) *Extension

type ExtensionRepo

type ExtensionRepo interface {
	Latest(ctx context.Context) (*db.Extension, error)
	Save(ctx context.Context, ext *db.Extension) (*db.Extension, error)
	GetByVersion(ctx context.Context, version string) (*db.Extension, error)
}

type ExtensionUsecase

type ExtensionUsecase interface {
	Latest(ctx context.Context) (*Extension, error)
	SyncLatest()
	GetByVersion(ctx context.Context, version string) (*Extension, error)
}

type FileMeta

type FileMeta struct {
	FilePath      string           `json:"filePath"`
	FileExtension string           `json:"fileExtension"`
	Language      CodeLanguageType `json:"language"` // 语言类型(可选)
	FileHash      string           `json:"fileHash"` // 文件哈希(可选)
	Content       string           `json:"content"`  // 文件内容(可选)
}

type GetAccessTokenReq

type GetAccessTokenReq struct {
	GrantType    string `json:"grant_type"`
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
	Code         string `json:"code"`
	RedirectURL  string `json:"redirect_uri"`
}

type GetAndSaveReq

type GetAndSaveReq struct {
	FileMetas   []FileMeta `json:"code_files"   validate:"required"` // 代码文件信息
	UserID      string     `json:"user_id"      validate:"required"` // 用户ID
	WorkspaceID string     `json:"workspace_id" validate:"required"` // 项目ID
}

type GetProviderModelListReq

type GetProviderModelListReq struct {
	Provider  consts.ModelProvider `json:"provider" query:"provider" validate:"required"`
	BaseURL   string               `json:"base_url" query:"base_url" validate:"required"`
	APIKey    string               `json:"api_key" query:"api_key"`
	APIHeader string               `json:"api_header" query:"api_header"`
	Type      consts.ModelType     `json:"type" query:"type" validate:"required,oneof=llm coder embedding rerank"`
}

type GetProviderModelListResp

type GetProviderModelListResp struct {
	Models []ProviderModelListItem `json:"models"`
	Error  string                  `json:"error"`
}

type GetTokenUsageReq

type GetTokenUsageReq struct {
	ModelType consts.ModelType `json:"model_type" query:"model_type" validate:"required,oneof=llm coder"` // 模型类型 llm:对话模型 coder:代码模型
}

type GlobalSettings

type GlobalSettings struct {
	AllowedCommands []string `json:"allowedCommands"`
	Mode            string   `json:"mode"`
	CustomModes     []string `json:"customModes"`
}

type GrantRoleReq

type GrantRoleReq struct {
	AdminID uuid.UUID `json:"admin_id"` // 管理员ID
	RoleIDs []int64   `json:"role_ids"` // 角色ID列表
}

type IPAddress

type IPAddress struct {
	IP       string `json:"ip"`
	Country  string `json:"country"`
	Province string `json:"province"`
	City     string `json:"city"`
}

type IPInfo

type IPInfo struct {
	IP       string `json:"ip"`       // IP地址
	Country  string `json:"country"`  // 国家
	Province string `json:"province"` // 省份
	City     string `json:"city"`     // 城市
	ISP      string `json:"isp"`      // 运营商
	ASN      string `json:"asn"`      // ASN
}

type IndexResult

type IndexResult struct {
	Name           string `json:"name"`
	Type           string `json:"type"`
	FilePath       string `json:"filePath"`
	StartLine      int    `json:"startLine"`
	EndLine        int    `json:"endLine"`
	RangeText      string `json:"rangeText"`
	DefinitionText string `json:"definitionText"`
	Scope          any    `json:"scope"`
	FileHash       string `json:"fileHash"`
	Definition     struct {
		Name       string `json:"name"`
		Type       string `json:"type"`
		ReturnType string `json:"returnType"`
	} `json:"definition"`
	Signature     string `json:"signature"`
	Language      string `json:"language"`
	ImplementText string `json:"implementText"`
}

type InviteResp

type InviteResp struct {
	Code string `json:"code"` // 邀请码
}

type ListAdminLoginHistoryResp

type ListAdminLoginHistoryResp struct {
	*db.PageInfo

	LoginHistories []*AdminLoginHistory `json:"login_histories"`
}

type ListAdminUserResp

type ListAdminUserResp struct {
	*db.PageInfo

	Users []*AdminUser `json:"users"`
}

type ListChatRecordResp

type ListChatRecordResp struct {
	*db.PageInfo

	Records []*ChatRecord `json:"records"`
}

type ListCompletionRecordResp

type ListCompletionRecordResp struct {
	*db.PageInfo

	Records []*CompletionRecord `json:"records"`
}

type ListLoginHistoryResp

type ListLoginHistoryResp struct {
	*db.PageInfo

	LoginHistories []*UserLoginHistory `json:"login_histories"`
}

type ListRecordReq

type ListRecordReq struct {
	*web.Pagination
	UserID   string `json:"-"`
	Author   string `json:"author" query:"author"`       // 作者
	Language string `json:"language" query:"language"`   // 语言
	WorkMode string `json:"work_mode" query:"work_mode"` // 工作模式
	IsAccept *bool  `json:"is_accept" query:"is_accept"` // 是否接受筛选
}

type ListReq

type ListReq struct {
	web.Pagination

	Search string `json:"search" query:"search"` // 搜索
}

type ListSecurityScanningBriefResp

type ListSecurityScanningBriefResp struct {
	*db.PageInfo

	Items []*SecurityScanningBrief `json:"items"`
}

type ListSecurityScanningDetailReq

type ListSecurityScanningDetailReq struct {
	web.Pagination
	ID     string `json:"id" query:"id"` // 扫描任务id
	UserID string `json:"-"`
}

type ListSecurityScanningDetailResp

type ListSecurityScanningDetailResp struct {
	*db.PageInfo

	Items []*SecurityScanningRiskDetail `json:"items"`
}

type ListSecurityScanningReq

type ListSecurityScanningReq struct {
	web.Pagination
	UserID      string `json:"-"`
	BaseURL     string `json:"-"`
	Author      string `json:"author" query:"author"`             // 作者
	ProjectName string `json:"project_name" query:"project_name"` // 项目名称
}

type ListSecurityScanningResp

type ListSecurityScanningResp struct {
	*db.PageInfo

	Items []*SecurityScanningResult `json:"items"`
}

type ListUserResp

type ListUserResp struct {
	*db.PageInfo

	Users []*User `json:"users"`
}

type ListWorkspaceFileReq

type ListWorkspaceFileReq struct {
	*web.Pagination
	UserID      string `json:"user_id" query:"user_id"`           // 用户ID
	WorkspaceID string `json:"workspace_id" query:"workspace_id"` // 工作区ID
	Language    string `json:"language" query:"language"`         // 编程语言筛选
	Search      string `json:"search" query:"search"`             // 搜索关键词(文件路径)
}

type ListWorkspaceFileResp

type ListWorkspaceFileResp struct {
	*db.PageInfo
	Files []*WorkspaceFile `json:"files"`
}

type ListWorkspaceReq

type ListWorkspaceReq struct {
	*web.Pagination
	UserID   string `json:"user_id" query:"user_id"`     // 用户ID
	Search   string `json:"search" query:"search"`       // 搜索关键词(工作区名称或描述)
	RootPath string `json:"root_path" query:"root_path"` // 根路径筛选
}

type ListWorkspaceResp

type ListWorkspaceResp struct {
	*db.PageInfo
	Workspaces []*Workspace `json:"workspaces"`
}

type LoginReq

type LoginReq struct {
	Source    consts.LoginSource `json:"source" validate:"required" default:"plugin"` // 登录来源 plugin: 插件 browser: 浏览器; 默认为 plugin
	SessionID string             `json:"session_id"`                                  // 会话Id插件登录时必填
	Username  string             `json:"username"`                                    // 用户名
	Password  string             `json:"password"`                                    // 密码
	IP        string             `json:"-"`                                           // IP地址
}

type LoginResp

type LoginResp struct {
	RedirectURL string `json:"redirect_url"`   // 重定向URL
	User        *User  `json:"user,omitempty"` // 用户信息
}

type Migrations

type Migrations struct {
	RateLimitSecondsMigrated bool `json:"rateLimitSecondsMigrated"`
	DiffSettingsMigrated     bool `json:"diffSettingsMigrated"`
}

type Model

type Model struct {
	ID         string               `json:"id"`          // 模型ID
	ShowName   string               `json:"show_name"`   // 模型显示名称
	ModelName  string               `json:"model_name"`  // 模型名称 如: deepseek-v3
	Provider   consts.ModelProvider `json:"provider"`    // 提供商
	APIBase    string               `json:"api_base"`    // 接口地址 如:https://api.qwen.com
	APIKey     string               `json:"api_key"`     // 接口密钥 如:sk-xxxx
	APIVersion string               `json:"api_version"` // 接口版本 如:2023-05-15
	APIHeader  string               `json:"api_header"`  // 接口头 如:Authorization: Bearer sk-xxxx
	ModelType  consts.ModelType     `json:"model_type"`  // 模型类型 llm:对话模型 coder:代码模型
	Status     consts.ModelStatus   `json:"status"`      // 状态 active:启用 inactive:禁用
	IsActive   bool                 `json:"is_active"`   // 是否启用
	Input      int64                `json:"input"`       // 输入token数
	Output     int64                `json:"output"`      // 输出token数
	Param      ModelParam           `json:"param"`       // 高级参数
	IsInternal bool                 `json:"is_internal"` // 是否内部模型
	CreatedAt  int64                `json:"created_at"`  // 创建时间
	UpdatedAt  int64                `json:"updated_at"`  // 更新时间
}

func (*Model) From

func (m *Model) From(e *db.Model) *Model

type ModelBasic

type ModelBasic struct {
	Name     string               `json:"name"`                         // 模型名称
	Provider consts.ModelProvider `json:"provider" validate:"required"` // 提供商
	APIBase  string               `json:"api_base"`                     // 接口地址 如:https://api.qwen.com
}

type ModelData

type ModelData struct {
	ID        string `json:"id"`
	Object    string `json:"object"`
	Created   int64  `json:"created"`
	OwnedBy   string `json:"owned_by"`
	Name      string `json:"name"`
	Type      string `json:"type"`
	BaseModel string `json:"base_model"`
	APIBase   string `json:"api_base"`
	IsActive  bool   `json:"is_active"`
}

func (*ModelData) From

func (m *ModelData) From(e *db.Model) *ModelData

type ModelListResp

type ModelListResp struct {
	Object string       `json:"object"`
	Data   []*ModelData `json:"data"`
}

type ModelParam

type ModelParam struct {
	R1Enabled          bool `json:"r1_enabled"`
	MaxTokens          int  `json:"max_tokens"`
	ContextWindow      int  `json:"context_window"`
	SupprtImages       bool `json:"support_images"`
	SupportComputerUse bool `json:"support_computer_use"`
	SupportPromptCache bool `json:"support_prompt_cache"`
}

func DefaultModelParam

func DefaultModelParam() *ModelParam

type ModelRepo

type ModelRepo interface {
	GetWithCache(ctx context.Context, modelType consts.ModelType) ([]*db.Model, error)
	List(ctx context.Context) (*AllModelResp, error)
	Create(ctx context.Context, m *CreateModelReq) (*db.Model, error)
	Update(ctx context.Context, id string, fn func(tx *db.Tx, old *db.Model, up *db.ModelUpdateOne) error) (*db.Model, error)
	Delete(ctx context.Context, id string) error
	MyModelList(ctx context.Context, req *MyModelListReq) ([]*db.Model, error)
	ModelUsage(ctx context.Context, ids []uuid.UUID) (map[uuid.UUID]ModelUsage, error)
	GetTokenUsage(ctx context.Context, modelType consts.ModelType) (*ModelTokenUsageResp, error)
	InitModel(ctx context.Context, modelName, modelKey, modelURL string) error
}

type ModelTokenUsage

type ModelTokenUsage struct {
	Timestamp int64 `json:"timestamp"` // 时间戳
	Tokens    int64 `json:"tokens"`    // 使用token数
}

type ModelTokenUsageResp

type ModelTokenUsageResp struct {
	TotalInput  int64             `json:"total_input"`  // 总输入token数
	TotalOutput int64             `json:"total_output"` // 总输出token数
	InputUsage  []ModelTokenUsage `json:"input_usage"`  // 输入token使用记录
	OutputUsage []ModelTokenUsage `json:"output_usage"` // 输出token使用记录
}

type ModelUsage

type ModelUsage struct {
	ModelID uuid.UUID `json:"model_id"` // 模型ID
	Input   int64     `json:"input"`    // 输入token数
	Output  int64     `json:"output"`   // 输出token数
}

type ModelUsecase

type ModelUsecase interface {
	List(ctx context.Context) (*AllModelResp, error)
	MyModelList(ctx context.Context, req *MyModelListReq) ([]*Model, error)
	Create(ctx context.Context, req *CreateModelReq) (*Model, error)
	Update(ctx context.Context, req *UpdateModelReq) (*Model, error)
	Delete(ctx context.Context, id string) error
	GetTokenUsage(ctx context.Context, modelType consts.ModelType) (*ModelTokenUsageResp, error)
	InitModel(ctx context.Context) error
}

type MyModelListReq

type MyModelListReq struct {
	ModelType consts.ModelType `json:"model_type" query:"model_type"` // 模型类型 llm:对话模型 coder:代码模型
}

type OAuthAccessToken

type OAuthAccessToken struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	ExpiresIn    int64  `json:"expires_in"`
	Scope        string `json:"scope"`
}

type OAuthCallbackReq

type OAuthCallbackReq struct {
	State   string `json:"state" query:"state" validate:"required"`
	Code    string `json:"code" query:"code" validate:"required"`
	IP      string `json:"-"`
	BaseURL string `json:"-"`
}

type OAuthConfig

type OAuthConfig struct {
	Debug        bool
	Platform     consts.UserPlatform
	ClientID     string
	ClientSecret string
	RedirectURI  string
	Scopes       []string
	AuthorizeURL string
	TokenURL     string
	UserInfoURL  string
	IDField      string
	NameField    string
	AvatarField  string
	EmailField   string
}

type OAuthSignUpOrInReq

type OAuthSignUpOrInReq struct {
	Source      consts.LoginSource  `json:"source" query:"source" validate:"required" default:"plugin"` // 登录来源 plugin: 插件 browser: 浏览器; 默认为 plugin
	Platform    consts.UserPlatform `json:"platform" query:"platform" validate:"required"`              // 第三方平台 dingtalk
	SessionID   string              `json:"session_id" query:"session_id"`                              // 会话ID
	RedirectURL string              `json:"redirect_url" query:"redirect_url"`                          // 登录成功后跳转的 URL
	InviteCode  string              `json:"inviate_code" query:"inviate_code"`                          // 邀请码
	BaseURL     string              `json:"-"`
}

func (OAuthSignUpOrInReq) OAuthKind

func (o OAuthSignUpOrInReq) OAuthKind() consts.OAuthKind

type OAuthState

type OAuthState struct {
	Source      consts.LoginSource  `json:"source"`                                        // 登录来源 plugin: 插件 browser: 浏览器; 默认为 plugin
	Kind        consts.OAuthKind    `json:"kind" query:"kind" validate:"required"`         // invite: 邀请登录 login: 登录
	SessionID   string              `json:"session_id"`                                    // 会话ID
	Platform    consts.UserPlatform `json:"platform" query:"platform" validate:"required"` // 第三方平台 dingtalk
	RedirectURL string              `json:"redirect_url" query:"redirect_url"`             // 登录成功后跳转的 URL
	InviteCode  string              `json:"inviate_code"`                                  // 邀请码
}

type OAuthURLResp

type OAuthURLResp struct {
	URL string `json:"url"`
}

type OAuthUserInfo

type OAuthUserInfo struct {
	ID        string `json:"id"`
	UnionID   string `json:"union_id"`
	Name      string `json:"name"`
	Email     string `json:"email"`
	AvatarURL string `json:"avatar_url"`
}

type OAuther

type OAuther interface {
	GetAuthorizeURL() (state string, url string)
	GetUserInfo(code string) (*OAuthUserInfo, error)
}

type OpenAIData

type OpenAIData struct {
	ID string `json:"id"`
}

type OpenAIRepo

type OpenAIRepo interface {
	GetApiKey(ctx context.Context, key string) (*db.ApiKey, error)
	ModelList(ctx context.Context) ([]*db.Model, error)
}

type OpenAIResp

type OpenAIResp struct {
	Object string        `json:"object"`
	Data   []*OpenAIData `json:"data"`
}

type OpenAIUsecase

type OpenAIUsecase interface {
	ModelList(ctx context.Context) (*ModelListResp, error)
	GetConfig(ctx context.Context, req *ConfigReq) (*ConfigResp, error)
}

type OpenAiCustomModelInfo

type OpenAiCustomModelInfo struct {
	MaxTokens           int  `json:"maxTokens"`
	ContextWindow       int  `json:"contextWindow"`
	SupportsImages      bool `json:"supportsImages"`
	SupportsComputerUse bool `json:"supportsComputerUse"`
	SupportsPromptCache bool `json:"supportsPromptCache"`
}

type Permissions

type Permissions struct {
	AdminID  uuid.UUID
	IsAdmin  bool
	Roles    []*Role
	UserIDs  []uuid.UUID
	GroupIDs []uuid.UUID
}

type PluginConfig

type PluginConfig struct {
	ProviderProfiles     ProviderProfiles     `json:"providerProfiles"`
	CtcodeTabCompletions CtcodeTabCompletions `json:"ctcodeTabCompletions"`
	GlobalSettings       GlobalSettings       `json:"globalSettings"`
}

type ProfileUpdateReq

type ProfileUpdateReq struct {
	UID         string  `json:"-"`
	Username    *string `json:"username"`     // 用户名
	Password    *string `json:"password"`     // 密码
	OldPassword *string `json:"old_password"` // 旧密码
	Avatar      *string `json:"avatar"`       // 头像
}

type ProviderModel

type ProviderModel struct {
	Provider string       `json:"provider"` // 提供商
	Models   []ModelBasic `json:"models"`   // 模型列表
}

type ProviderModelListItem

type ProviderModelListItem struct {
	Model string `json:"model"`
}

type ProviderProfiles

type ProviderProfiles struct {
	CurrentApiConfigName string               `json:"currentApiConfigName"`
	ApiConfigs           map[string]ApiConfig `json:"apiConfigs"`
	ModeApiConfigs       map[string]string    `json:"modeApiConfigs"`
	Migrations           Migrations           `json:"migrations"`
}

type ProxyRepo

type ProxyRepo interface {
	Record(ctx context.Context, record *RecordParam) error
	UpdateByTaskID(ctx context.Context, taskID string, fn func(*db.TaskUpdateOne)) error
	AcceptCompletion(ctx context.Context, req *AcceptCompletionReq) error
	Report(ctx context.Context, model *db.Model, req *ReportReq) error
	SelectModelWithLoadBalancing(modelName string, modelType consts.ModelType) (*db.Model, error)
	ValidateApiKey(ctx context.Context, key string) (*db.ApiKey, error)
}

type ProxyUsecase

type ProxyUsecase interface {
	SelectModelWithLoadBalancing(modelName string, modelType consts.ModelType) (*Model, error)
	Record(ctx context.Context, record *RecordParam) error
	ValidateApiKey(ctx context.Context, key string) (*ApiKey, error)
	AcceptCompletion(ctx context.Context, req *AcceptCompletionReq) error
	Report(ctx context.Context, req *ReportReq) error
	CreateSecurityScanning(ctx context.Context, req *CreateSecurityScanningReq) (string, error)
	ListSecurityScanning(ctx context.Context, req *ListSecurityScanningReq) (*ListSecurityScanningBriefResp, error)
	ListSecurityDetail(ctx context.Context, req *ListSecurityScanningDetailReq) (*ListSecurityScanningDetailResp, error)
}

type RecordParam

type RecordParam struct {
	RequestID       string
	TaskID          string
	UserID          string
	ModelID         string
	ModelType       consts.ModelType
	Role            consts.ChatRole
	Prompt          string
	ProgramLanguage string
	InputTokens     int64
	OutputTokens    int64
	IsAccept        bool
	Completion      string
	WorkMode        string
	CodeLines       int64
	Code            string
	SourceCode      string         // 当前文件的原文
	CursorPosition  map[string]any // 光标位置
	UserInput       string         // 用户实际输入的内容
}

func (*RecordParam) Clone

func (r *RecordParam) Clone() *RecordParam

type RegisterReq

type RegisterReq struct {
	Username string `json:"username" validate:"required"` // 用户名
	Email    string `json:"email" validate:"required"`    // 邮箱
	Password string `json:"password" validate:"required"` // 密码
	Code     string `json:"code" validate:"required"`     // 邀请码
}

type ReportData

type ReportData struct {
	Timestamp     string              `json:"timestamp"`      // 上报时间戳
	Version       string              `json:"version"`        // 系统版本号
	MachineID     string              `json:"machine_id"`     // 机器ID
	AdminCount    int64               `json:"admin_count"`    // 管理员数量
	MemberCount   int64               `json:"member_count"`   // 成员数量
	Last24Hours   *ActivityStats      `json:"last_24_hours"`  // 最近24小时统计
	CurrentModels []*ReportModelUsage `json:"current_models"` // 当前使用的模型列表
}

type ReportModelUsage

type ReportModelUsage struct {
	ModelID   string           `json:"model_id"`   // 模型ID
	ModelName string           `json:"model_name"` // 模型名称
	ModelType consts.ModelType `json:"model_type"` // 模型类型 (llm/coder)
}

type ReportRepo

type ReportRepo interface {
	GetAdminCount(ctx context.Context) (int64, error)
	GetMemberCount(ctx context.Context) (int64, error)
	GetLast24HoursStats(ctx context.Context) (*ActivityStats, error)
	GetCurrentModels(ctx context.Context) ([]*ReportModelUsage, error)
}

type ReportReq

type ReportReq struct {
	Action         consts.ReportAction `json:"action"`
	ID             string              `json:"id"`              // task_id or resp_id
	Content        string              `json:"content"`         // 内容
	Tool           string              `json:"tool"`            // 工具
	UserInput      string              `json:"user_input"`      // 用户输入的新文本(用于reject action)
	SourceCode     string              `json:"source_code"`     // 当前文件的原文(用于reject action)
	CursorPosition map[string]any      `json:"cursor_position"` // 光标位置(用于reject action)
	Mode           string              `json:"mode"`            // 模式
	UserID         string              `json:"-"`
}

type ReportUsecase

type ReportUsecase interface {
}

type Role

type Role struct {
	ID          int64  `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
}

func (*Role) From

func (r *Role) From(e *db.Role) *Role

type ScanReq

type ScanReq struct {
	TaskID    string `json:"task_id"`
	UserID    string `json:"user_id"`
	Workspace string `json:"workspace"` // 项目目录
	Language  string `json:"language"`  // 扫描语言
}

type SecurityScanningBrief

type SecurityScanningBrief struct {
	ID        string                        `json:"id"`         // 扫描任务id
	Workspace string                        `json:"workspace"`  // 项目目录
	Status    consts.SecurityScanningStatus `json:"status"`     // 扫描状态
	ReportURL string                        `json:"report_url"` // 报告url
	CreatedAt int64                         `json:"created_at"` // 创建时间
}

func (*SecurityScanningBrief) From

type SecurityScanningResult

type SecurityScanningResult struct {
	ID          string                        `json:"id"`           // 扫描任务id
	Name        string                        `json:"name"`         // 扫描任务
	ProjectName string                        `json:"project_name"` // 项目名称
	Path        string                        `json:"path"`         // 项目路径
	Status      consts.SecurityScanningStatus `json:"status"`       // 扫描状态
	Risk        SecurityScanningRiskResult    `json:"risk"`         // 风险结果
	User        *User                         `json:"user"`         // 用户
	Error       string                        `json:"error"`        // 错误信息
	CreatedAt   int64                         `json:"created_at"`   // 扫描开始时间
}

func (*SecurityScanningResult) From

type SecurityScanningRiskDetail

type SecurityScanningRiskDetail struct {
	ID       string                           `json:"id"`       // 风险id
	Level    consts.SecurityScanningRiskLevel `json:"level"`    // 风险等级
	Desc     string                           `json:"desc"`     // 风险描述
	Lines    string                           `json:"lines"`    // 风险代码行
	Start    *types.Position                  `json:"start"`    // 风险代码行开始位置
	End      *types.Position                  `json:"end"`      // 风险代码行结束位置
	Fix      string                           `json:"fix"`      // 修复建议
	Filename string                           `json:"filename"` // 风险文件名
	Content  string                           `json:"content"`  // 代码内容
}

func (*SecurityScanningRiskDetail) From

type SecurityScanningRiskResult

type SecurityScanningRiskResult struct {
	ID            uuid.UUID `json:"id"`
	SevereCount   int       `json:"severe_count"`   // 严重数
	CriticalCount int       `json:"critical_count"` // 高危数
	SuggestCount  int       `json:"suggest_count"`  // 建议数
}

type SecurityScanningUsecase

type SecurityScanningUsecase interface {
	List(ctx context.Context, req ListSecurityScanningReq) (*ListSecurityScanningResp, error)
	Detail(ctx context.Context, userID, id string) ([]*SecurityScanningRiskDetail, error)
}

type Setting

type Setting struct {
	EnableSSO            bool          `json:"enable_sso"`             // 是否开启SSO
	ForceTwoFactorAuth   bool          `json:"force_two_factor_auth"`  // 是否强制两步验证
	DisablePasswordLogin bool          `json:"disable_password_login"` // 是否禁用密码登录
	EnableAutoLogin      bool          `json:"enable_auto_login"`      // 是否开启自动登录
	DingtalkOAuth        DingtalkOAuth `json:"dingtalk_oauth"`         // 钉钉OAuth接入
	CustomOAuth          CustomOAuth   `json:"custom_oauth"`           // 自定义OAuth接入
	BaseURL              string        `json:"base_url,omitempty"`     // base url 配置,为了支持前置代理
	CreatedAt            int64         `json:"created_at"`             // 创建时间
	UpdatedAt            int64         `json:"updated_at"`             // 更新时间
}

func (*Setting) From

func (s *Setting) From(e *db.Setting) *Setting

type Statistics

type Statistics struct {
	TotalUsers    int64 `json:"total_users"`    // 总用户数
	DisabledUsers int64 `json:"disabled_users"` // 禁用用户数
}

type StatisticsFilter

type StatisticsFilter struct {
	Precision string `json:"precision" query:"precision"`       // 精度: "hour", "day"
	Duration  int    `json:"duration" query:"duration"`         // 持续时间 (小时或天数)`
	StartAt   int64  `json:"start_at" query:"start_at"`         // 开始时间, 时间范围优先级高于精度选择
	EndAt     int64  `json:"end_at" query:"end_at"`             // 结束时间, 时间范围优先级高于精度选择
	UserID    string `json:"user_id,omitempty" query:"user_id"` // 用户ID,可选参数
}

func (StatisticsFilter) EndTime

func (s StatisticsFilter) EndTime() time.Time

func (StatisticsFilter) MustPrecision

func (s StatisticsFilter) MustPrecision() string

func (StatisticsFilter) StartTime

func (s StatisticsFilter) StartTime() time.Time

type SyncWorkspaceFileReq

type SyncWorkspaceFileReq struct {
	UserID      string                    `json:"user_id" validate:"required"`      // 用户ID
	WorkspaceID string                    `json:"workspace_id" validate:"required"` // 工作区ID
	Files       []*CreateWorkspaceFileReq `json:"files" validate:"required,dive"`   // 要同步的文件列表
}

type SyncWorkspaceFileResp

type SyncWorkspaceFileResp struct {
	Created []*WorkspaceFile `json:"created"` // 新创建的文件
	Updated []*WorkspaceFile `json:"updated"` // 更新的文件
	Deleted []string         `json:"deleted"` // 删除的文件ID
	Total   int              `json:"total"`   // 处理的文件总数
}

type TimePoint

type TimePoint[V any] struct {
	Timestamp int64 `json:"timestamp"` // 时间戳
	Value     V     `json:"value"`     // 值
}

type TimeStat

type TimeStat struct {
	TotalUsers       int64                `json:"total_users"`         // 近90天活跃用户数
	TotalChats       int64                `json:"total_chats"`         // 近90天对话任务数
	TotalCompletions int64                `json:"total_completions"`   // 近90天补全任务数
	TotalLinesOfCode int64                `json:"total_lines_of_code"` // 近90天代码行数
	TotalAcceptedPer float64              `json:"total_accepted_per"`  // 近90天平均接受率
	ActiveUsers      []TimePoint[int64]   `json:"active_users"`        // 活跃用户数统计
	RealTimeTokens   []TimePoint[int64]   `json:"real_time_tokens"`    // 实时token数统计
	Chats            []TimePoint[int64]   `json:"chats"`               // 对话任务数统计
	Completions      []TimePoint[int64]   `json:"code_completions"`    // 补全任务数统计
	LinesOfCode      []TimePoint[int64]   `json:"lines_of_code"`       // 代码行数统计
	AcceptedPer      []TimePoint[float64] `json:"accepted_per"`        // 接受率统计
}

type UpdateModelReq

type UpdateModelReq struct {
	ID         string                `json:"id"`                           // 模型ID
	ModelName  *string               `json:"model_name"`                   // 模型名称
	ShowName   *string               `json:"show_name"`                    // 模型显示名称
	Provider   *consts.ModelProvider `json:"provider" validate:"required"` // 提供商
	APIBase    *string               `json:"api_base"`                     // 接口地址 如:https://api.qwen.com
	APIKey     *string               `json:"api_key"`                      // 接口密钥 如:sk-xxxx
	APIVersion *string               `json:"api_version"`
	APIHeader  *string               `json:"api_header"`
	Status     *consts.ModelStatus   `json:"status"`          // 状态 active:启用 inactive:禁用
	Param      *ModelParam           `json:"param,omitempty"` // 高级参数
}

type UpdateSettingReq

type UpdateSettingReq struct {
	EnableSSO            *bool             `json:"enable_sso"`             // 是否开启SSO
	ForceTwoFactorAuth   *bool             `json:"force_two_factor_auth"`  // 是否强制两步验证
	DisablePasswordLogin *bool             `json:"disable_password_login"` // 是否禁用密码登录
	EnableAutoLogin      *bool             `json:"enable_auto_login"`      // 是否开启自动登录
	DingtalkOAuth        *DingtalkOAuthReq `json:"dingtalk_oauth"`         // 钉钉OAuth配置
	CustomOAuth          *CustomOAuthReq   `json:"custom_oauth"`           // 自定义OAuth配置
	BaseURL              *string           `json:"base_url"`               // base url 配置,为了支持前置代理
}

type UpdateUserReq

type UpdateUserReq struct {
	ID       string             `json:"id" validate:"required"` // 用户ID
	Status   *consts.UserStatus `json:"status"`                 // 用户状态 active: 正常 locked: 锁定 inactive: 禁用
	Password *string            `json:"password"`               // 重置密码
}

type UpdateWorkspaceFileReq

type UpdateWorkspaceFileReq struct {
	ID       string  `json:"id" validate:"required"` // 文件ID
	Content  *string `json:"content"`                // 文件内容
	Hash     *string `json:"hash"`                   // 文件哈希
	Language *string `json:"language"`               // 编程语言
	Size     *int64  `json:"size"`                   // 文件大小
}

type UpdateWorkspaceReq

type UpdateWorkspaceReq struct {
	ID          string         `json:"id" validate:"required"` // 工作区ID
	Name        *string        `json:"name"`                   // 工作区名称
	Description *string        `json:"description"`            // 工作区描述
	Settings    map[string]any `json:"settings"`               // 工作区设置
}

type User

type User struct {
	ID           string            `json:"id"`             // 用户ID
	Username     string            `json:"username"`       // 用户名
	Email        string            `json:"email"`          // 邮箱
	TwoStepAuth  bool              `json:"two_step_auth"`  // 是否开启两步验证
	Status       consts.UserStatus `json:"status"`         // 用户状态 active: 正常 locked: 锁定 inactive: 禁用
	AvatarURL    string            `json:"avatar_url"`     // 头像URL
	CreatedAt    int64             `json:"created_at"`     // 创建时间
	IsDeleted    bool              `json:"is_deleted"`     // 是否删除
	LastActiveAt int64             `json:"last_active_at"` // 最后活跃时间
}

func (*User) From

func (u *User) From(e *db.User) *User

type UserCodeRank

type UserCodeRank struct {
	Username string `json:"username"` // 用户名
	Lines    int64  `json:"lines"`    // 代码行数
	User     *User  `json:"user"`     // 用户信息
}

func (*UserCodeRank) From

func (u *UserCodeRank) From(d *db.Task) *UserCodeRank

type UserEvent

type UserEvent struct {
	Name      string `json:"name"`       // 事件名称
	CreatedAt int64  `json:"created_at"` // 事件时间
}

type UserHeatmap

type UserHeatmap struct {
	Date  int64 `json:"date"`
	Count int64 `json:"count"`
}

type UserHeatmapResp

type UserHeatmapResp struct {
	MaxCount int64          `json:"max_count"`
	Points   []*UserHeatmap `json:"points"`
}

type UserLoginHistory

type UserLoginHistory struct {
	User          *User   `json:"user"`           // 用户信息
	IPInfo        *IPInfo `json:"ip_info"`        // IP信息
	ClientVersion string  `json:"client_version"` // 客户端版本
	Device        string  `json:"device"`         // 设备信息
	Hostname      string  `json:"hostname"`       // 主机名
	ClientID      string  `json:"client_id"`      // 插件ID vscode
	CreatedAt     int64   `json:"created_at"`     // 登录时间
}

func (*UserLoginHistory) From

type UserRepo

type UserRepo interface {
	List(ctx context.Context, page *web.Pagination) ([]*db.User, *db.PageInfo, error)
	Update(ctx context.Context, id string, fn func(*db.Tx, *db.User, *db.UserUpdateOne) error) (*db.User, error)
	Delete(ctx context.Context, id string) error
	InitAdmin(ctx context.Context, username, password string) error
	CreateUser(ctx context.Context, user *db.User) (*db.User, error)
	CreateAdmin(ctx context.Context, admin *db.Admin, roleID int64) (*db.Admin, error)
	DeleteAdmin(ctx context.Context, id string) error
	AdminByName(ctx context.Context, username string) (*db.Admin, error)
	GetByName(ctx context.Context, username string) (*db.User, error)
	GetOrCreateApiKey(ctx context.Context, userID string) (*db.ApiKey, error)
	GetUserByApiKey(ctx context.Context, apiKey string) (*db.User, error)
	AdminList(ctx context.Context, page *web.Pagination) ([]*db.Admin, *db.PageInfo, error)
	CreateInviteCode(ctx context.Context, userID string, code string) (*db.InviteCode, error)
	ValidateInviteCode(ctx context.Context, code string) (*db.InviteCode, error)
	UserLoginHistory(ctx context.Context, page *web.Pagination) ([]*db.UserLoginHistory, *db.PageInfo, error)
	AdminLoginHistory(ctx context.Context, page *web.Pagination) ([]*db.AdminLoginHistory, *db.PageInfo, error)
	GetSetting(ctx context.Context) (*db.Setting, error)
	UpdateSetting(ctx context.Context, fn func(*db.Setting, *db.SettingUpdateOne)) (*db.Setting, error)
	OAuthRegister(ctx context.Context, platform consts.UserPlatform, inviteCode string, req *OAuthUserInfo) (*db.User, error)
	OAuthLogin(ctx context.Context, platform consts.UserPlatform, req *OAuthUserInfo) (*db.User, error)
	SignUpOrIn(ctx context.Context, platform consts.UserPlatform, req *OAuthUserInfo) (*db.User, error)
	SaveAdminLoginHistory(ctx context.Context, adminID, ip string) error
	SaveUserLoginHistory(ctx context.Context, userID, ip string, session *VSCodeSession) error
	ExportCompletionData(ctx context.Context) ([]*CompletionData, error)
	GetUserCount(ctx context.Context) (int64, error)
	ListRole(ctx context.Context) ([]*db.Role, error)
	GrantRole(ctx context.Context, req *GrantRoleReq) error
	GetPermissions(ctx context.Context, id uuid.UUID) (*Permissions, error)
	CleanPermissionCache(ctx context.Context, id uuid.UUID)
}

type UserStat

type UserStat struct {
	TotalChats       int64                `json:"total_chats"`         // 总对话任务数
	TotalCompletions int64                `json:"total_completions"`   // 总补全任务数
	TotalLinesOfCode int64                `json:"total_lines_of_code"` // 总代码行数
	TotalAcceptedPer float64              `json:"total_accepted_per"`  // 总接受率
	Chats            []TimePoint[int64]   `json:"chats"`               // 对话任务数统计
	Completions      []TimePoint[int64]   `json:"code_completions"`    // 补全任务数统计
	LinesOfCode      []TimePoint[int64]   `json:"lines_of_code"`       // 代码行数统计
	AcceptedPer      []TimePoint[float64] `json:"accepted_per"`        // 接受率统计
	WorkMode         []CategoryPoint      `json:"work_mode"`           // 工作模式占比
	ProgramLanguage  []CategoryPoint      `json:"program_language"`    // 编程语言占比
}

type UserUsecase

type UserUsecase interface {
	Login(ctx context.Context, req *LoginReq) (*LoginResp, error)
	Update(ctx context.Context, req *UpdateUserReq) (*User, error)
	ProfileUpdate(ctx context.Context, req *ProfileUpdateReq) (*User, error)
	Delete(ctx context.Context, id string) error
	InitAdmin(ctx context.Context) error
	AdminLogin(ctx context.Context, req *LoginReq) (*AdminUser, error)
	DeleteAdmin(ctx context.Context, id string) error
	CreateAdmin(ctx context.Context, req *CreateAdminReq) (*AdminUser, error)
	VSCodeAuthInit(ctx context.Context, req *VSCodeAuthInitReq) (*VSCodeAuthInitResp, error)
	List(ctx context.Context, req ListReq) (*ListUserResp, error)
	AdminList(ctx context.Context, page *web.Pagination) (*ListAdminUserResp, error)
	LoginHistory(ctx context.Context, page *web.Pagination) (*ListLoginHistoryResp, error)
	AdminLoginHistory(ctx context.Context, page *web.Pagination) (*ListAdminLoginHistoryResp, error)
	Invite(ctx context.Context, userID string) (*InviteResp, error)
	Register(ctx context.Context, req *RegisterReq) (*User, error)
	GetSetting(ctx context.Context) (*Setting, error)
	UpdateSetting(ctx context.Context, req *UpdateSettingReq) (*Setting, error)
	OAuthSignUpOrIn(ctx context.Context, req *OAuthSignUpOrInReq) (*OAuthURLResp, error)
	OAuthCallback(ctx *web.Context, req *OAuthCallbackReq) error
	ExportCompletionData(ctx context.Context) (*ExportCompletionDataResp, error)
	GetUserByApiKey(ctx context.Context, apiKey string) (*db.User, error)
	GetUserCount(ctx context.Context) (int64, error)
	ListRole(ctx context.Context) ([]*Role, error)
	GrantRole(ctx context.Context, req *GrantRoleReq) error
	GetPermissions(ctx context.Context, id uuid.UUID) (*Permissions, error)
}

type VSCodeAuthInitReq

type VSCodeAuthInitReq struct {
	ClientID    string           `json:"client_id" validate:"required"`    // 客户端ID
	RedirectURI string           `json:"redirect_uri" validate:"required"` // 重定向URI
	State       string           `json:"state" validate:"required"`        // 状态
	Version     string           `json:"version"`                          // 版本
	OSType      consts.OSType    `json:"os_type"`                          // 操作系统类型
	OSRelease   consts.OSRelease `json:"os_release"`                       // 操作系统版本
	Hostname    string           `json:"hostname"`                         // 主机名
	BaseURL     string           `json:"-"`
}

type VSCodeAuthInitResp

type VSCodeAuthInitResp struct {
	AuthURL string `json:"auth_url"` // 授权URL
}

type VSCodeSession

type VSCodeSession struct {
	ID          string           `json:"id"`           // 会话ID
	ClientID    string           `json:"client_id"`    // 客户端ID
	State       string           `json:"state"`        // 状态
	RedirectURI string           `json:"redirect_uri"` // 重定向URI
	Version     string           `json:"version"`      // 版本
	OSType      consts.OSType    `json:"os_type"`      // 操作系统类型
	OSRelease   consts.OSRelease `json:"os_release"`   // 操作系统版本
	Hostname    string           `json:"hostname"`     // 主机名
}

type VersionInfo

type VersionInfo struct {
	Version string `json:"version"`
	URL     string `json:"url"`
}

type Workspace

type Workspace struct {
	ID             string         `json:"id"`               // 工作区ID
	UserID         string         `json:"user_id"`          // 用户ID
	Name           string         `json:"name"`             // 工作区名称
	Description    string         `json:"description"`      // 工作区描述
	RootPath       string         `json:"root_path"`        // 工作区根路径
	Settings       map[string]any `json:"settings"`         // 工作区设置
	LastAccessedAt int64          `json:"last_accessed_at"` // 最后访问时间
	CreatedAt      int64          `json:"created_at"`       // 创建时间
	UpdatedAt      int64          `json:"updated_at"`       // 更新时间
}

func FromWorkspaces

func FromWorkspaces(workspaces []*db.Workspace) []*Workspace

工具函数

func (*Workspace) From

func (w *Workspace) From(e *db.Workspace) *Workspace

type WorkspaceFile

type WorkspaceFile struct {
	ID          string `json:"id"`           // 文件ID
	UserID      string `json:"user_id"`      // 用户ID
	WorkspaceID string `json:"workspace_id"` // 工作区ID
	Path        string `json:"path"`         // 文件路径
	Content     string `json:"content"`      // 文件内容
	Hash        string `json:"hash"`         // 文件哈希
	Language    string `json:"language"`     // 编程语言
	Size        int64  `json:"size"`         // 文件大小
	CreatedAt   int64  `json:"created_at"`   // 创建时间
	UpdatedAt   int64  `json:"updated_at"`   // 更新时间
}

func FromWorkspaceFiles

func FromWorkspaceFiles(files []*db.WorkspaceFile) []*WorkspaceFile

func (*WorkspaceFile) From

type WorkspaceFileRepo

type WorkspaceFileRepo interface {
	Create(ctx context.Context, req *CreateWorkspaceFileReq) (*db.WorkspaceFile, error)
	Update(ctx context.Context, id string, fn func(*db.WorkspaceFileUpdateOne) error) (*db.WorkspaceFile, error)
	Delete(ctx context.Context, id string) error
	GetByID(ctx context.Context, id string) (*db.WorkspaceFile, error)
	GetByPath(ctx context.Context, userID, workspaceID, path string) (*db.WorkspaceFile, error)
	List(ctx context.Context, req *ListWorkspaceFileReq) ([]*db.WorkspaceFile, *db.PageInfo, error)
	BatchCreate(ctx context.Context, files []*CreateWorkspaceFileReq) ([]*db.WorkspaceFile, error)
	GetByHashes(ctx context.Context, workspaceID string, hashes []string) (map[string]*db.WorkspaceFile, error)
	CountByWorkspace(ctx context.Context, workspaceID string) (int64, error)
	GetWorkspaceFiles(ctx context.Context, workspaceID string) ([]*db.WorkspaceFile, error)
}

WorkspaceFileRepo 定义 WorkspaceFile 数据访问接口

type WorkspaceFileUsecase

type WorkspaceFileUsecase interface {
	Create(ctx context.Context, req *CreateWorkspaceFileReq) (*WorkspaceFile, error)
	Update(ctx context.Context, req *UpdateWorkspaceFileReq) (*WorkspaceFile, error)
	Delete(ctx context.Context, id string) error
	GetAndSave(ctx context.Context, req *GetAndSaveReq) error
	GetByID(ctx context.Context, id string) (*WorkspaceFile, error)
	GetByPath(ctx context.Context, userID, workspaceID, path string) (*WorkspaceFile, error)
	List(ctx context.Context, req *ListWorkspaceFileReq) (*ListWorkspaceFileResp, error)
	BatchCreate(ctx context.Context, req *BatchCreateWorkspaceFileReq) ([]*WorkspaceFile, error)
	BatchUpdate(ctx context.Context, req *BatchUpdateWorkspaceFileReq) ([]*WorkspaceFile, error)
	Sync(ctx context.Context, req *SyncWorkspaceFileReq) (*SyncWorkspaceFileResp, error)
}

WorkspaceFileUsecase 定义 WorkspaceFile 业务逻辑接口

type WorkspaceRepo

type WorkspaceRepo interface {
	Create(ctx context.Context, req *CreateWorkspaceReq) (*db.Workspace, error)
	GetByID(ctx context.Context, id string) (*db.Workspace, error)
	GetByUserAndPath(ctx context.Context, userID, rootPath string) (*db.Workspace, error)
	List(ctx context.Context, req *ListWorkspaceReq) ([]*db.Workspace, *db.PageInfo, error)
	Update(ctx context.Context, id string, fn func(*db.WorkspaceUpdateOne) error) (*db.Workspace, error)
	Delete(ctx context.Context, id string) error
}

WorkspaceRepo 定义 Workspace 数据访问接口

type WorkspaceUsecase

type WorkspaceUsecase interface {
	Create(ctx context.Context, req *CreateWorkspaceReq) (*Workspace, error)
	GetByID(ctx context.Context, id string) (*Workspace, error)
	GetByUserAndPath(ctx context.Context, userID, rootPath string) (*Workspace, error)
	List(ctx context.Context, req *ListWorkspaceReq) (*ListWorkspaceResp, error)
	Update(ctx context.Context, req *UpdateWorkspaceReq) (*Workspace, error)
	Delete(ctx context.Context, id string) error
	EnsureWorkspace(ctx context.Context, userID, rootPath, name string) (*Workspace, error)
}

WorkspaceUsecase 定义 Workspace 业务逻辑接口

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL