models

package
v0.0.0-...-9714d49 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HashToken

func HashToken(token string) string

HashToken creates a SHA-256 hash of the token for secure storage

Types

type AIRecipe

type AIRecipe struct {
	Name        string        `json:"name" description:"The name of the recipe."`
	Ingredients []*Ingredient `json:"ingredients" description:"The ingredients used in the recipe."`
	Directions  []*Direction  `json:"directions" description:"The steps to make the recipe."`
	Equipment   []*Equipment  `json:"equipment" description:"The equipment used while making the recipe."`
}

type ApiKey

type ApiKey struct {
	Model
	Name       string     `json:"name" gorm:"not null"`                   // Human-readable name for the key
	Token      string     `json:"token,omitempty" gorm:"unique;not null"` // The actual API key token
	TokenHash  string     `json:"-" gorm:"not null"`                      // Hashed version stored in DB
	UserID     string     `json:"user_id" gorm:"index;not null"`
	LastUsedAt *time.Time `json:"last_used_at,omitempty"`
	ExpiresAt  *time.Time `json:"expires_at,omitempty"`
	IsActive   bool       `json:"is_active" gorm:"default:true"`
	Scopes     string     `json:"scopes" gorm:"default:'read,write'"` // Comma-separated permissions
	User       *User      `gorm:"foreignKey:UserID"`
}

func NewApiKey

func NewApiKey(name, userID string, scopes []string) *ApiKey

NewApiKey creates a new API key with secure token generation

func (*ApiKey) HasScope

func (ak *ApiKey) HasScope(scope string) bool

HasScope checks if the API key has the specified scope

func (*ApiKey) UpdateLastUsed

func (ak *ApiKey) UpdateLastUsed()

UpdateLastUsed updates the last used timestamp

func (*ApiKey) ValidateToken

func (ak *ApiKey) ValidateToken(token string) bool

ValidateToken checks if the provided token matches this API key

type ChatMessage

type ChatMessage struct {
	Role      string    `json:"role"` // "user" or "assistant"
	Content   string    `json:"content"`
	Timestamp time.Time `json:"timestamp"`
	Type      string    `json:"type"` // "initial", "expansion", "reaction", etc.
}

ChatMessage represents a message in the ideation chat history

type ClaudeDoc

type ClaudeDoc struct {
	Model
	Title       string `json:"title" gorm:"not null"`
	Description string `json:"description"`
	Content     string `json:"content" gorm:"type:text"`
	UserID      string `json:"user_id" gorm:"index;not null"`
	IsPublic    bool   `json:"is_public" gorm:"default:true"`
	Downloads   int    `json:"downloads" gorm:"default:0"`
	Stars       int    `json:"stars" gorm:"default:0"`
	Views       int    `json:"views" gorm:"default:0"`
	User        *User  `gorm:"foreignKey:UserID"`
	Tags        []*Tag `gorm:"many2many:claude_doc_tags;"`
}

type ClaudeDocStar

type ClaudeDocStar struct {
	Model
	ClaudeDocID string     `json:"claude_doc_id" gorm:"index;not null"`
	UserID      string     `json:"user_id" gorm:"index;not null"`
	ClaudeDoc   *ClaudeDoc `gorm:"foreignKey:ClaudeDocID"`
	User        *User      `gorm:"foreignKey:UserID"`
}

type ClaudeDocTag

type ClaudeDocTag struct {
	ClaudeDocID string     `json:"claude_doc_id" gorm:"primaryKey"`
	TagID       string     `json:"tag_id" gorm:"primaryKey"`
	CreatedAt   time.Time  `json:"created_at"`
	ClaudeDoc   *ClaudeDoc `gorm:"foreignKey:ClaudeDocID"`
	Tag         *Tag       `gorm:"foreignKey:TagID"`
}

type ClaudeSession

type ClaudeSession struct {
	Model
	SessionID string                             `json:"session_id" gorm:"unique;not null;index"`
	UserID    string                             `json:"user_id" gorm:"index;not null"`
	User      *User                              `gorm:"foreignKey:UserID"`
	Title     string                             `json:"title"`
	Messages  JSONField[interface{}]             `json:"messages" gorm:"type:json"`
	Metadata  *JSONField[map[string]interface{}] `json:"metadata,omitempty"`
}

type Container

type Container struct {
	Model
	ContainerID  string                        `json:"container_id" gorm:"unique;not null"`
	Name         string                        `json:"name" gorm:"not null"`
	Image        string                        `json:"image" gorm:"not null"`
	Status       string                        `json:"status"`
	Command      string                        `json:"command"`
	Ports        *JSONField[map[string]string] `json:"ports"`
	Environment  *JSONField[map[string]string] `json:"environment"`
	UserID       string                        `json:"user_id" gorm:"index"`
	DockerHostID string                        `json:"docker_host_id" gorm:"index"`
	SessionID    string                        `json:"session_id,omitempty" gorm:"index"`
	User         *User                         `gorm:"foreignKey:UserID"`
	DockerHost   *DockerHost                   `gorm:"foreignKey:DockerHostID"`
}

type ContainerSession

type ContainerSession struct {
	Model
	ContainerID string     `json:"container_id" gorm:"index"`
	SessionID   string     `json:"session_id" gorm:"unique;not null"`
	Command     string     `json:"command"`
	UserID      string     `json:"user_id" gorm:"index"`
	Container   *Container `gorm:"foreignKey:ContainerID"`
	User        *User      `gorm:"foreignKey:UserID"`
}

type Content

type Content struct {
	Model
	Type     string                             `json:"type" gorm:"not null"`  // text, image, audio, clipboard
	Data     string                             `json:"data" gorm:"type:text"` // Text content or file path
	MediaURL string                             `json:"media_url,omitempty"`   // URL for media files
	MimeType string                             `json:"mime_type,omitempty"`   // MIME type for media
	FileSize int64                              `json:"file_size,omitempty"`   // File size in bytes
	GroupID  string                             `json:"group_id" gorm:"index;not null"`
	UserID   string                             `json:"user_id" gorm:"index;not null"`
	Group    *Group                             `gorm:"foreignKey:GroupID"`
	User     *User                              `gorm:"foreignKey:UserID"`
	Tags     []*Tag                             `gorm:"many2many:content_tags;"`
	Metadata *JSONField[map[string]interface{}] `json:"metadata,omitempty"` // Additional metadata
}

func NewContent

func NewContent(contentType, data, groupID, userID string, metadata map[string]interface{}) *Content

NewContent creates a new Content instance with proper initialization

type ContentTag

type ContentTag struct {
	ContentID string    `json:"content_id" gorm:"primaryKey"`
	TagID     string    `json:"tag_id" gorm:"primaryKey"`
	CreatedAt time.Time `json:"created_at"`
	Content   *Content  `gorm:"foreignKey:ContentID"`
	Tag       *Tag      `gorm:"foreignKey:TagID"`
}

type Direction

type Direction struct {
	Model
	Text      string `json:"text" description:"The direction text."`
	StartTime int    `json:"start_time" description:"The time in seconds when direction starts in the transcript."`
	EndTime   int    `json:"end_time" description:"The time in seconds when direction ends in the transcript."`
	RecipeID  string `json:"recipe_id" description:"The ID of the recipe."`
}

type DockerHost

type DockerHost struct {
	Model
	Name      string `json:"name" gorm:"unique;not null"`
	Endpoint  string `json:"endpoint" gorm:"not null"`
	TLSCert   string `json:"tls_cert,omitempty"`
	TLSKey    string `json:"tls_key,omitempty"`
	TLSCA     string `json:"tls_ca,omitempty"`
	TLSVerify bool   `json:"tls_verify"`
	IsDefault bool   `json:"is_default"`
	UserID    string `json:"user_id" gorm:"index"`
	User      *User  `gorm:"foreignKey:UserID"`
}

type Equipment

type Equipment struct {
	Model
	Name     string `json:"name" description:"The name of the equipment."`
	Comment  string `json:"comment" description:"The comment of the equipment."`
	RecipeID string `json:"recipe_id" description:"The ID of the recipe."`
}

type Feature

type Feature struct {
	ID          string `json:"id"`
	Title       string `json:"title"`
	Description string `json:"description"`
	Category    string `json:"category"`
	Priority    string `json:"priority"`
	Complexity  string `json:"complexity"`
}

Feature represents a feature in ideation sessions

type Food

type Food struct {
	FDCID       int64 `gorm:"primaryKey"`
	CreatedAt   time.Time
	Description string         `gorm:"index"`
	Raw         datatypes.JSON `gorm:"type:jsonb"`
}

type FoodName

type FoodName struct {
	FDCID int64
	Food  *Food `gorm:"foreignKey:FDCID"`
	Name  string
}

type Group

type Group struct {
	ID        string             `gorm:"primaryKey" json:"id"`
	CreatedAt time.Time          `json:"created_at"`
	Name      string             `gorm:"unique;not null" json:"name"`
	JoinCode  string             `gorm:"unique" json:"join_code"`
	Members   []*GroupMembership `gorm:"foreignKey:GroupID" json:"members,omitempty"`
	Pages     []*Page            `gorm:"foreignKey:GroupID" json:"pages,omitempty"`
}

type GroupMembership

type GroupMembership struct {
	ID        string `gorm:"primaryKey"`
	CreatedAt time.Time
	UserID    string `gorm:"index"`
	GroupID   string `gorm:"index"`
	Role      string
	User      *User  `gorm:"foreignKey:UserID"`
	Group     *Group `gorm:"foreignKey:GroupID"`
}

type Identity

type Identity struct {
	ID        string `gorm:"primaryKey"`
	CreatedAt time.Time
	Provider  string
	UserID    string
	User      *User `gorm:"foreignKey:UserID"`
}

type Ingredient

type Ingredient struct {
	Model
	Name     string `json:"name" description:"The name of the ingredient."`
	Amount   string `json:"amount" description:"The amount of the ingredient."`
	Unit     string `json:"unit" description:"The unit of the ingredient."`
	Comment  string `json:"comment" description:"The comment of the ingredient."`
	RecipeID string `json:"recipe_id" description:"The ID of the recipe."`
}

type JSONField

type JSONField[T any] struct {
	Data T
}

func MakeJSONField

func MakeJSONField[T any](data T) *JSONField[T]

func (JSONField[T]) MarshalJSON

func (j JSONField[T]) MarshalJSON() ([]byte, error)

func (*JSONField[T]) Scan

func (j *JSONField[T]) Scan(src any) error

func (*JSONField[T]) UnmarshalJSON

func (j *JSONField[T]) UnmarshalJSON(b []byte) error

func (JSONField[T]) Value

func (j JSONField[T]) Value() (driver.Value, error)

type Model

type Model struct {
	ID        string         `gorm:"primaryKey" json:"id"`
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"index"`
}

type Page

type Page struct {
	Model
	URL       string `json:"url"`
	Title     string `json:"title"`
	HTML      string `json:"html"`
	CreatedAt int64  `json:"created_at"`
	Article   string `json:"article"`
	HitCount  int    `json:"hit_count"`
	GroupID   string `json:"group_id"`
}

type PinnedFile

type PinnedFile struct {
	Model
	UserID   string `json:"user_id" gorm:"index;not null;uniqueIndex:idx_user_file"`
	FilePath string `json:"file_path" gorm:"not null;uniqueIndex:idx_user_file"`
	User     *User  `gorm:"foreignKey:UserID"`
}

type Prompt

type Prompt struct {
	Model
	Title    string
	Content  string `gorm:"type:text"`
	UserID   string
	ParentID string
	Forks    []Prompt `gorm:"foreignKey:ParentID"`
	Runs     []PromptRun
}

type PromptContext

type PromptContext struct {
	Model
	ID        string `gorm:"primaryKey"`
	ContextID string
	Request   *JSONField[openai.ChatCompletionRequest]
	Response  *JSONField[openai.ChatCompletionResponse]
}

type PromptRun

type PromptRun struct {
	Model
	PromptID string
	Input    string `gorm:"type:text"`
	Output   string `gorm:"type:text"`
}

type Recipe

type Recipe struct {
	Model
	Domain      string        `json:"domain" description:"The domain of the recipe."`
	URL         string        `json:"url" description:"The url of the recipe."`
	Name        string        `json:"name"`
	Ingredients []*Ingredient `json:"ingredients" gorm:"foreignKey:RecipeID"`
	Directions  []*Direction  `json:"directions" gorm:"foreignKey:RecipeID"`
	Equipment   []*Equipment  `json:"equipment" description:"The equipment used while making the recipe."`
	Transcript  *JSONField[youtube.VideoTranscript]
}

func AIRecipeToModel

func AIRecipeToModel(ar AIRecipe, id, domain string, ts youtube.VideoTranscript) Recipe

type SessionKVStore

type SessionKVStore struct {
	Model
	SessionID string                             `json:"session_id" gorm:"index;not null"`
	Namespace string                             `json:"namespace" gorm:"not null;default:'default'"`
	Key       string                             `json:"key" gorm:"not null"`
	Value     *JSONField[map[string]interface{}] `json:"value" gorm:"type:jsonb;not null"`
}

SessionKVStore represents key-value data for session-based prototypes

func NewSessionKVStore

func NewSessionKVStore(sessionID, namespace, key string, value map[string]interface{}) *SessionKVStore

NewSessionKVStore creates a new SessionKVStore entry

type SlackFileUpload

type SlackFileUpload struct {
	Model
	ThreadTS     string     `json:"thread_ts" gorm:"index;not null"`
	ChannelID    string     `json:"channel_id" gorm:"index;not null"`
	UserID       string     `json:"user_id" gorm:"index;not null"`
	User         *User      `gorm:"foreignKey:UserID"`
	SlackFileID  string     `json:"slack_file_id" gorm:"index;not null"` // Slack's file ID
	FileName     string     `json:"file_name" gorm:"not null"`
	OriginalName string     `json:"original_name" gorm:"not null"`
	MimeType     string     `json:"mime_type"`
	Category     string     `json:"category" gorm:"index"` // File category: image, document, code, text, archive, etc.
	FileSize     int64      `json:"file_size"`
	LocalPath    string     `json:"local_path" gorm:"not null"` // Path where file is stored locally
	UploadedAt   time.Time  `json:"uploaded_at"`
	Downloaded   bool       `json:"downloaded" gorm:"default:false"`
	DownloadedAt *time.Time `json:"downloaded_at"`
	SessionID    string     `json:"session_id" gorm:"index"` // Associated Claude session ID if any
}

SlackFileUpload represents a file uploaded to a Slack thread

type SlackIdeationSession

type SlackIdeationSession struct {
	Model
	SessionID    string                       `json:"session_id" gorm:"unique;not null;index"`
	ThreadID     string                       `json:"thread_id" gorm:"index;not null"`
	ChannelID    string                       `json:"channel_id" gorm:"index;not null"`
	UserID       string                       `json:"user_id" gorm:"index;not null"`
	User         *User                        `gorm:"foreignKey:UserID"`
	OriginalIdea string                       `json:"original_idea"`
	Features     JSONField[[]Feature]         `json:"features" gorm:"type:json"`
	Preferences  JSONField[map[string]int]    `json:"preferences" gorm:"type:json"` // emoji -> count
	ChatHistory  JSONField[[]ChatMessage]     `json:"chat_history" gorm:"type:json"`
	LastActivity time.Time                    `json:"last_activity"`
	Active       bool                         `json:"active" gorm:"default:true"`
	MessageTS    JSONField[map[string]string] `json:"message_ts" gorm:"type:json"` // feature_id -> message timestamp
}

SlackIdeationSession represents an ideation session tied to a Slack thread (database version)

type SlackSession

type SlackSession struct {
	Model
	ThreadTS     string    `json:"thread_ts" gorm:"index;not null"`
	ChannelID    string    `json:"channel_id" gorm:"index;not null"`
	UserID       string    `json:"user_id" gorm:"index;not null"`
	User         *User     `gorm:"foreignKey:UserID"`
	SessionID    string    `json:"session_id" gorm:"index"`
	ProcessID    string    `json:"process_id"`
	LastActivity time.Time `json:"last_activity"`
	Context      string    `json:"context"` // Working directory context
	Active       bool      `json:"active" gorm:"default:true"`
	Resumed      bool      `json:"resumed" gorm:"default:false"`
}

SlackSession represents a Claude session tied to a Slack thread (database version)

type SlackUserActivity

type SlackUserActivity struct {
	Model
	UserID       string    `json:"user_id" gorm:"index;not null"`
	User         *User     `gorm:"foreignKey:UserID"`
	ThreadTS     string    `json:"thread_ts" gorm:"index;not null"`
	LastSeen     time.Time `json:"last_seen"`
	MessageCount int       `json:"message_count"`
	SessionStart time.Time `json:"session_start"`
}

SlackUserActivity tracks user activity patterns in threads (database version)

type Tag

type Tag struct {
	Model
	Name     string     `json:"name" gorm:"unique;not null;index"`
	Color    string     `json:"color,omitempty"`               // Hex color for display
	UserID   string     `json:"user_id" gorm:"index;not null"` // Tag creator
	User     *User      `gorm:"foreignKey:UserID"`
	Contents []*Content `gorm:"many2many:content_tags;"`
}

type ThreadContext

type ThreadContext struct {
	Model
	ThreadTS       string                            `json:"thread_ts" gorm:"index;not null"`
	ChannelID      string                            `json:"channel_id" gorm:"index;not null"`
	SessionType    string                            `json:"session_type"` // "ideation", "claude", "worklet"
	OriginalPrompt string                            `json:"original_prompt"`
	LastActivity   time.Time                         `json:"last_activity"`
	Summary        string                            `json:"summary"`
	NextSteps      JSONField[[]string]               `json:"next_steps" gorm:"type:json"`
	KeyMetrics     JSONField[map[string]interface{}] `json:"key_metrics" gorm:"type:json"`
	PinnedMessage  string                            `json:"pinned_message"` // Timestamp of pinned context message
	UserID         string                            `json:"user_id" gorm:"index;not null"`
	User           *User                             `gorm:"foreignKey:UserID"`
	Active         bool                              `json:"active" gorm:"default:true"`
}

ThreadContext represents a context summary for a Slack thread (database version)

type User

type User struct {
	ID               string `gorm:"primaryKey"`
	CreatedAt        time.Time
	Username         string             `gorm:"unique"`
	Identities       []*Identity        `gorm:"foreignKey:UserID"`
	GroupMemberships []*GroupMembership `gorm:"foreignKey:UserID"`
	Secrets          []*UserSecret      `gorm:"foreignKey:UserID"`
	Password         string
}

type UserSecret

type UserSecret struct {
	ID        string `gorm:"primaryKey"`
	CreatedAt time.Time
	Secret    string
	UserID    string `gorm:"index"`
	User      *User  `gorm:"foreignKey:UserID"`
}

type WorkletKVEntry

type WorkletKVEntry struct {
	Key       string                 `json:"key"`
	Value     map[string]interface{} `json:"value"`
	Namespace string                 `json:"namespace"`
	CreatedAt time.Time              `json:"created_at"`
	UpdatedAt time.Time              `json:"updated_at"`
}

WorkletKVEntry represents a single key-value entry for API responses

type WorkletKVStore

type WorkletKVStore struct {
	Model
	WorkletID string                             `json:"worklet_id" gorm:"index;not null"`
	Namespace string                             `json:"namespace" gorm:"not null;default:'default'"`
	Key       string                             `json:"key" gorm:"not null"`
	Value     *JSONField[map[string]interface{}] `json:"value" gorm:"type:jsonb;not null"`
}

WorkletKVStore represents key-value data for worklet prototypes DEPRECATED: Use SessionKVStore instead

func NewWorkletKVStore

func NewWorkletKVStore(workletID, namespace, key string, value map[string]interface{}) *WorkletKVStore

NewWorkletKVStore creates a new WorkletKVStore entry DEPRECATED: Use NewSessionKVStore instead

func (*WorkletKVStore) ToEntry

func (kv *WorkletKVStore) ToEntry() WorkletKVEntry

ToEntry converts a WorkletKVStore model to a WorkletKVEntry response

Jump to

Keyboard shortcuts

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