backend

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateConfig

func ValidateConfig(cfg Config) error

ValidateConfig validates the configuration

Types

type Agent

type Agent struct {
	// contains filtered or unexported fields
}

Agent handles AI operations for generating notes and chat responses

func NewAgent

func NewAgent(cfg Config, vectorStore *VectorStore) (*Agent, error)

NewAgent creates a new agent

func (*Agent) Chat

func (a *Agent) Chat(ctx context.Context, notebookID, message string, history []ChatMessage) (*ChatResponse, error)

Chat performs a chat query with RAG

func (*Agent) GenerateFAQ

func (a *Agent) GenerateFAQ(ctx context.Context, sources []Source) (string, error)

GenerateFAQ generates an FAQ from sources

func (*Agent) GenerateInfographImage

func (a *Agent) GenerateInfographImage(ctx context.Context, prompt string) (string, error)

GenerateInfographImage generates an infographic image using the Nano Banana Pro SDK

func (*Agent) GenerateOutline

func (a *Agent) GenerateOutline(ctx context.Context, sources []Source) (string, error)

GenerateOutline generates an outline from sources

func (*Agent) GeneratePodcastScript

func (a *Agent) GeneratePodcastScript(ctx context.Context, sources []Source, voice string) (string, error)

GeneratePodcastScript generates a podcast script from sources

func (*Agent) GenerateStudyGuide

func (a *Agent) GenerateStudyGuide(ctx context.Context, sources []Source) (string, error)

GenerateStudyGuide generates a study guide from sources

func (*Agent) GenerateSummary

func (a *Agent) GenerateSummary(ctx context.Context, sources []Source, length string) (string, error)

GenerateSummary generates a summary from sources

func (*Agent) GenerateTransformation

func (a *Agent) GenerateTransformation(ctx context.Context, req *TransformationRequest, sources []Source) (*TransformationResponse, error)

GenerateTransformation generates a note based on transformation type

type ChatMessage

type ChatMessage struct {
	ID        string                 `json:"id"`
	SessionID string                 `json:"session_id"`
	Role      string                 `json:"role"` // "user", "assistant", "system"
	Content   string                 `json:"content"`
	Sources   []string               `json:"sources,omitempty"` // Source IDs referenced
	CreatedAt time.Time              `json:"created_at"`
	Metadata  map[string]interface{} `json:"metadata,omitempty"`
}

ChatMessage represents a chat message

type ChatRequest

type ChatRequest struct {
	Message   string                 `json:"message"`
	SessionID string                 `json:"session_id,omitempty"`
	Context   map[string]interface{} `json:"context,omitempty"`
}

ChatRequest represents a chat request

type ChatResponse

type ChatResponse struct {
	Message   string                 `json:"message"`
	Sources   []SourceSummary        `json:"sources"`
	SessionID string                 `json:"session_id"`
	MessageID string                 `json:"message_id"`
	Metadata  map[string]interface{} `json:"metadata,omitempty"`
}

ChatResponse represents a chat response

type ChatSession

type ChatSession struct {
	ID         string                 `json:"id"`
	NotebookID string                 `json:"notebook_id"`
	Title      string                 `json:"title"`
	Messages   []ChatMessage          `json:"messages"`
	CreatedAt  time.Time              `json:"created_at"`
	UpdatedAt  time.Time              `json:"updated_at"`
	Metadata   map[string]interface{} `json:"metadata,omitempty"`
}

ChatSession represents a chat session within a notebook

type Config

type Config struct {
	// Server settings
	ServerHost string
	ServerPort string

	// LLM settings
	OpenAIAPIKey   string
	OpenAIBaseURL  string
	OpenAIModel    string
	EmbeddingModel string
	GoogleAPIKey   string
	OllamaBaseURL  string
	OllamaModel    string

	// Vector store settings
	VectorStoreType string // "memory", "supabase", "pgvector", "redis", "sqlite"
	SupabaseURL     string
	SupabaseKey     string
	PostgreSQLURL   string
	RedisURL        string
	SQLitePath      string

	// Store settings (for checkpoints)
	StoreType string // "memory", "sqlite", "postgres", "redis"
	StorePath string

	// Application settings
	MaxSources       int
	MaxContextLength int
	ChunkSize        int
	ChunkOverlap     int

	// Podcast generation
	EnablePodcast bool
	PodcastVoice  string

	// Document conversion
	EnableMarkitdown bool

	// LangSmith tracing (optional)
	LangChainAPIKey  string
	LangChainProject string
}

Config holds the application configuration

func LoadConfig

func LoadConfig() Config

LoadConfig loads configuration from environment variables with defaults

func (*Config) GetBaseURL

func (c *Config) GetBaseURL() string

GetBaseURL returns the appropriate base URL for the LLM provider

func (*Config) IsOllama

func (c *Config) IsOllama() bool

IsOllama returns true if using Ollama as the LLM provider

func (*Config) SupportsFunctionCalling

func (c *Config) SupportsFunctionCalling() bool

SupportsFunctionCalling returns true if the configured model supports function calling

type ErrorResponse

type ErrorResponse struct {
	Error   string `json:"error"`
	Code    string `json:"code,omitempty"`
	Details string `json:"details,omitempty"`
}

ErrorResponse represents an error response

type HealthResponse

type HealthResponse struct {
	Status    string            `json:"status"`
	Version   string            `json:"version"`
	Timestamp int64             `json:"timestamp"`
	Services  map[string]string `json:"services"`
}

HealthResponse represents the health check response

type Note

type Note struct {
	ID         string                 `json:"id"`
	NotebookID string                 `json:"notebook_id"`
	Title      string                 `json:"title"`
	Content    string                 `json:"content"`
	Type       string                 `json:"type"` // "summary", "faq", "study_guide", "outline", "custom"
	SourceIDs  []string               `json:"source_ids"`
	CreatedAt  time.Time              `json:"created_at"`
	UpdatedAt  time.Time              `json:"updated_at"`
	Metadata   map[string]interface{} `json:"metadata,omitempty"`
}

Note represents a note generated from sources

type Notebook

type Notebook struct {
	ID          string                 `json:"id"`
	Name        string                 `json:"name"`
	Description string                 `json:"description,omitempty"`
	CreatedAt   time.Time              `json:"created_at"`
	UpdatedAt   time.Time              `json:"updated_at"`
	Metadata    map[string]interface{} `json:"metadata,omitempty"`
}

Notebook represents a collection of sources and notes

type Podcast

type Podcast struct {
	ID         string                 `json:"id"`
	NotebookID string                 `json:"notebook_id"`
	Title      string                 `json:"title"`
	Script     string                 `json:"script"`
	AudioURL   string                 `json:"audio_url,omitempty"`
	Duration   int                    `json:"duration,omitempty"` // in seconds
	Voice      string                 `json:"voice"`
	Status     string                 `json:"status"` // "pending", "generating", "completed", "error"
	SourceIDs  []string               `json:"source_ids"`
	CreatedAt  time.Time              `json:"created_at"`
	UpdatedAt  time.Time              `json:"updated_at"`
	Metadata   map[string]interface{} `json:"metadata,omitempty"`
}

Podcast represents an audio podcast generated from sources

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server handles HTTP requests

func NewServer

func NewServer(cfg Config) (*Server, error)

NewServer creates a new server

func (*Server) Start

func (s *Server) Start() error

Start starts the server

type Source

type Source struct {
	ID         string                 `json:"id"`
	NotebookID string                 `json:"notebook_id"`
	Name       string                 `json:"name"`
	Type       string                 `json:"type"` // "file", "url", "text", "youtube"
	URL        string                 `json:"url,omitempty"`
	Content    string                 `json:"content,omitempty"`
	FileName   string                 `json:"file_name,omitempty"`
	FileSize   int64                  `json:"file_size,omitempty"`
	ChunkCount int                    `json:"chunk_count"`
	CreatedAt  time.Time              `json:"created_at"`
	UpdatedAt  time.Time              `json:"updated_at"`
	Metadata   map[string]interface{} `json:"metadata,omitempty"`
}

Source represents a document source added to a notebook

type SourceSummary

type SourceSummary struct {
	ID   string `json:"id"`
	Name string `json:"name"`
	Type string `json:"type"`
}

SourceSummary is a lightweight source reference

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store handles data persistence for notebooks, sources, notes, and chat sessions

func NewStore

func NewStore(cfg Config) (*Store, error)

NewStore creates a new store

func (*Store) AddChatMessage

func (s *Store) AddChatMessage(ctx context.Context, sessionID, role, content string, sources []string) (*ChatMessage, error)

AddChatMessage adds a message to a chat session

func (*Store) Close

func (s *Store) Close() error

Close closes the database connection

func (*Store) CreateChatSession

func (s *Store) CreateChatSession(ctx context.Context, notebookID, title string) (*ChatSession, error)

CreateChatSession creates a new chat session

func (*Store) CreateNote

func (s *Store) CreateNote(ctx context.Context, note *Note) error

CreateNote creates a new note

func (*Store) CreateNotebook

func (s *Store) CreateNotebook(ctx context.Context, name, description string, metadata map[string]interface{}) (*Notebook, error)

CreateNotebook creates a new notebook

func (*Store) CreateSource

func (s *Store) CreateSource(ctx context.Context, source *Source) error

CreateSource creates a new source

func (*Store) DeleteChatSession

func (s *Store) DeleteChatSession(ctx context.Context, id string) error

DeleteChatSession deletes a chat session

func (*Store) DeleteNote

func (s *Store) DeleteNote(ctx context.Context, id string) error

DeleteNote deletes a note

func (*Store) DeleteNotebook

func (s *Store) DeleteNotebook(ctx context.Context, id string) error

DeleteNotebook deletes a notebook and all its data

func (*Store) DeleteSource

func (s *Store) DeleteSource(ctx context.Context, id string) error

DeleteSource deletes a source

func (*Store) GetChatSession

func (s *Store) GetChatSession(ctx context.Context, id string) (*ChatSession, error)

GetChatSession retrieves a chat session by ID

func (*Store) GetNote

func (s *Store) GetNote(ctx context.Context, id string) (*Note, error)

GetNote retrieves a note by ID

func (*Store) GetNotebook

func (s *Store) GetNotebook(ctx context.Context, id string) (*Notebook, error)

GetNotebook retrieves a notebook by ID

func (*Store) GetSource

func (s *Store) GetSource(ctx context.Context, id string) (*Source, error)

GetSource retrieves a source by ID

func (*Store) ListChatSessions

func (s *Store) ListChatSessions(ctx context.Context, notebookID string) ([]ChatSession, error)

ListChatSessions retrieves all chat sessions for a notebook

func (*Store) ListNotebooks

func (s *Store) ListNotebooks(ctx context.Context) ([]Notebook, error)

ListNotebooks retrieves all notebooks

func (*Store) ListNotes

func (s *Store) ListNotes(ctx context.Context, notebookID string) ([]Note, error)

ListNotes retrieves all notes for a notebook

func (*Store) ListSources

func (s *Store) ListSources(ctx context.Context, notebookID string) ([]Source, error)

ListSources retrieves all sources for a notebook

func (*Store) UpdateNotebook

func (s *Store) UpdateNotebook(ctx context.Context, id string, name, description string, metadata map[string]interface{}) (*Notebook, error)

UpdateNotebook updates a notebook

func (*Store) UpdateSourceChunkCount

func (s *Store) UpdateSourceChunkCount(ctx context.Context, id string, chunkCount int) error

UpdateSourceChunkCount updates the chunk count for a source

type TransformationRequest

type TransformationRequest struct {
	Type      string   `json:"type"`       // "summary", "faq", "study_guide", "outline", "podcast", "custom"
	Prompt    string   `json:"prompt"`     // Custom prompt for "custom" type
	SourceIDs []string `json:"source_ids"` // Specific sources to use, empty = all
	Length    string   `json:"length"`     // "short", "medium", "long"
	Format    string   `json:"format"`     // "markdown", "bullet_points", "paragraphs"
}

TransformationRequest represents a request to generate a note

type TransformationResponse

type TransformationResponse struct {
	ID        string                 `json:"id"`
	Type      string                 `json:"type"`
	Content   string                 `json:"content"`
	Sources   []SourceSummary        `json:"sources"`
	CreatedAt time.Time              `json:"created_at"`
	Metadata  map[string]interface{} `json:"metadata,omitempty"`
}

TransformationResponse represents the response from a transformation

type VectorStats

type VectorStats struct {
	TotalDocuments int
	TotalVectors   int
	Dimension      int
}

VectorStats contains statistics about the vector store

type VectorStore

type VectorStore struct {
	// contains filtered or unexported fields
}

VectorStore wraps different vector store implementations

func NewVectorStore

func NewVectorStore(cfg Config) (*VectorStore, error)

NewVectorStore creates a new vector store based on configuration

func (*VectorStore) Delete

func (vs *VectorStore) Delete(ctx context.Context, source string) error

Delete removes documents by source

func (*VectorStore) ExtractDocument

func (vs *VectorStore) ExtractDocument(ctx context.Context, path string) (string, error)

ExtractDocument reads and converts a document to text/markdown

func (*VectorStore) GetStats

func (vs *VectorStore) GetStats(ctx context.Context) (VectorStats, error)

GetStats returns statistics about the vector store

func (*VectorStore) IngestDocuments

func (vs *VectorStore) IngestDocuments(ctx context.Context, paths []string) error

IngestDocuments loads and indexes documents from file paths

func (*VectorStore) IngestText

func (vs *VectorStore) IngestText(ctx context.Context, sourceName, content string) error

IngestText ingests raw text content

func (*VectorStore) SimilaritySearch

func (vs *VectorStore) SimilaritySearch(ctx context.Context, query string, numDocs int) ([]schema.Document, error)

SimilaritySearch performs a similarity search (simple keyword matching for now)

Jump to

Keyboard shortcuts

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