This repository has been archived on 2026-04-03. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
core/server/models/models.go

148 lines
5.0 KiB
Go

package models
import (
"time"
)
// BaseModel contains fields common to all models
type BaseModel struct {
ID string `json:"id" db:"id"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
}
// User represents a user in the system
type User struct {
BaseModel
Email string `json:"email" db:"email"`
PasswordHash string `json:"-" db:"password_hash"`
Name string `json:"name" db:"name"`
Role string `json:"role" db:"role"`
LastLoginAt *time.Time `json:"last_login_at,omitempty" db:"last_login_at"`
IsActive bool `json:"is_active" db:"is_active"`
}
// UserRole constants
const (
UserRoleUser = "user"
UserRoleAdmin = "admin"
)
// Chat represents a chat conversation
type Chat struct {
BaseModel
UserID string `json:"user_id" db:"user_id"`
Title string `json:"title" db:"title"`
Model string `json:"model" db:"model"`
SystemPrompt string `json:"system_prompt,omitempty" db:"system_prompt"`
IsArchived bool `json:"is_archived" db:"is_archived"`
}
// Message represents a chat message
type Message struct {
BaseModel
ChatID string `json:"chat_id" db:"chat_id"`
Role string `json:"role" db:"role"` // "user", "assistant", "system"
Content string `json:"content" db:"content"`
Tokens int `json:"tokens,omitempty" db:"tokens"`
Model string `json:"model,omitempty" db:"model"`
FinishReason string `json:"finish_reason,omitempty" db:"finish_reason"`
}
// MessageRole constants
const (
MessageRoleUser = "user"
MessageRoleAssistant = "assistant"
MessageRoleSystem = "system"
)
// APIConfig represents a configured API provider
type APIConfig struct {
BaseModel
UserID string `json:"user_id" db:"user_id"`
Name string `json:"name" db:"name"`
Provider string `json:"provider" db:"provider"` // "openai", "anthropic", "google", etc.
APIKey string `json:"-" db:"api_key"`
BaseURL string `json:"base_url,omitempty" db:"base_url"`
Model string `json:"model" db:"model"`
IsDefault bool `json:"is_default" db:"is_default"`
}
// Channel represents a chat channel
type Channel struct {
BaseModel
Name string `json:"name" db:"name"`
Description string `json:"description,omitempty" db:"description"`
IsPrivate bool `json:"is_private" db:"is_private"`
OwnerID string `json:"owner_id" db:"owner_id"`
}
// ChannelMember represents a member of a channel
type ChannelMember struct {
BaseModel
ChannelID string `json:"channel_id" db:"channel_id"`
UserID string `json:"user_id" db:"user_id"`
Role string `json:"role" db:"role"` // "member", "moderator", "admin"
}
// ChannelMessage represents a message in a channel
type ChannelMessage struct {
BaseModel
ChannelID string `json:"channel_id" db:"channel_id"`
UserID string `json:"user_id" db:"user_id"`
Content string `json:"content" db:"content"`
ParentID string `json:"parent_id,omitempty" db:"parent_id"`
}
// Note represents a user note
type Note struct {
BaseModel
UserID string `json:"user_id" db:"user_id"`
Title string `json:"title" db:"title"`
Content string `json:"content" db:"content"`
Tags []string `json:"tags,omitempty" db:"tags"`
FolderID string `json:"folder_id,omitempty" db:"folder_id"`
IsShared bool `json:"is_shared" db:"is_shared"`
}
// KnowledgeBase represents a knowledge base collection
type KnowledgeBase struct {
BaseModel
UserID string `json:"user_id" db:"user_id"`
Name string `json:"name" db:"name"`
Source string `json:"source" db:"source"` // "url", "file", "text"
Settings string `json:"settings,omitempty" db:"settings"` // JSON settings
}
// Workflow represents a workflow definition
type Workflow struct {
BaseModel
UserID string `json:"user_id" db:"user_id"`
Name string `json:"name" db:"name"`
Steps string `json:"steps" db:"steps"` // JSON array of steps
Settings string `json:"settings,omitempty" db:"settings"`
IsPublic bool `json:"is_public" db:"is_public"`
}
// Settings represents user settings
type Settings struct {
UserID string `json:"user_id" db:"user_id"`
Theme string `json:"theme" db:"theme"`
Language string `json:"language" db:"language"`
Model string `json:"model" db:"model"`
SystemPrompt string `json:"system_prompt,omitempty" db:"system_prompt"`
MaxTokens int `json:"max_tokens" db:"max_tokens"`
Temperature float64 `json:"temperature" db:"temperature"`
DefaultAPIConfigID string `json:"default_api_config_id,omitempty" db:"default_api_config_id"`
}
// APIToken represents an API token for external access
type APIToken struct {
BaseModel
UserID string `json:"user_id" db:"user_id"`
Name string `json:"name" db:"name"`
Token string `json:"-" db:"token"`
ExpiresAt time.Time `json:"expires_at,omitempty" db:"expires_at"`
LastUsedAt *time.Time `json:"last_used_at,omitempty" db:"last_used_at"`
IsActive bool `json:"is_active" db:"is_active"`
}