Documentation
¶
Index ¶
- func DetermineFileType(mimeType string) string
- func HandleFilesCleanup(fm *FileManager) http.HandlerFunc
- func HandleFilesCreateOrList(fm *FileManager) http.HandlerFunc
- func HandleFilesDelete(fm *FileManager) http.HandlerFunc
- func HandleFilesDownload(fm *FileManager) http.HandlerFunc
- func HandleFilesGet(fm *FileManager) http.HandlerFunc
- func HandleFilesList(fm *FileManager) http.HandlerFunc
- func HandleFilesStats(fm *FileManager) http.HandlerFunc
- func HasFileReferences(blocks []ContentBlock) bool
- type CleanupJob
- type ContentBlock
- type ContentSource
- type DeletionCallback
- type File
- type FileManager
- func (fm *FileManager) CleanupExpired(ctx context.Context) (int, error)
- func (fm *FileManager) CleanupOrphans(ctx context.Context) (int, error)
- func (fm *FileManager) Delete(ctx context.Context, fileID string) error
- func (fm *FileManager) DeleteByID(fileID string) error
- func (fm *FileManager) ExpandFileReferences(blocks []ContentBlock) ([]ContentBlock, error)
- func (fm *FileManager) ExtractImagesFromToolResult(result interface{}, threadID, source string) (interface{}, []string, error)
- func (fm *FileManager) FindByChecksum(ctx context.Context, checksum string) (*File, error)
- func (fm *FileManager) Get(ctx context.Context, fileID string) (*File, error)
- func (fm *FileManager) GetAsBase64(ctx context.Context, fileID string) (string, error)
- func (fm *FileManager) GetGlobalStats(ctx context.Context) (*GlobalStorageStats, error)
- func (fm *FileManager) GetMetadata(fileID string) (*File, error)
- func (fm *FileManager) GetPublicURL(fileID string) (string, error)
- func (fm *FileManager) GetStats(ctx context.Context) (*StorageStats, error)
- func (fm *FileManager) GetStatsByThread(ctx context.Context, threadID string) (*ThreadStorageStats, error)
- func (fm *FileManager) IsEnabled() bool
- func (fm *FileManager) ListFiles(ctx context.Context, threadID string, limit int) ([]*File, error)
- func (fm *FileManager) ListFilesFiltered(threadID, fileType string, limit int) ([]*File, error)
- func (fm *FileManager) ProcessContentBlocks(blocks []ContentBlock, threadID, messageID, source string) ([]ContentBlock, error)
- func (fm *FileManager) SearchFiles(query, fileType string, limit int) ([]*File, error)
- func (fm *FileManager) SetDeletionCallback(callback DeletionCallback)
- func (fm *FileManager) SetIngestionCallback(callback IngestionCallback)
- func (fm *FileManager) Store(ctx context.Context, file *File) (string, error)
- func (fm *FileManager) StripFileReferences(blocks []ContentBlock) []ContentBlock
- type GlobalStorageStats
- type IngestionCallback
- type StorageStats
- type ThreadStorageStats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DetermineFileType ¶
DetermineFileType determines the file type from MIME type
func HandleFilesCleanup ¶
func HandleFilesCleanup(fm *FileManager) http.HandlerFunc
HandleFilesCleanup handles POST /files/cleanup
func HandleFilesCreateOrList ¶
func HandleFilesCreateOrList(fm *FileManager) http.HandlerFunc
HandleFilesCreateOrList handles POST /files (upload) and returns list metadata Supports both multipart form upload and JSON with base64 data
func HandleFilesDelete ¶
func HandleFilesDelete(fm *FileManager) http.HandlerFunc
HandleFilesDelete handles DELETE /files/{id}
func HandleFilesDownload ¶
func HandleFilesDownload(fm *FileManager) http.HandlerFunc
HandleFilesDownload handles GET /files/{id}/download
func HandleFilesGet ¶
func HandleFilesGet(fm *FileManager) http.HandlerFunc
HandleFilesGet handles GET /files/{id}
func HandleFilesList ¶
func HandleFilesList(fm *FileManager) http.HandlerFunc
HandleFilesList handles GET /files
func HandleFilesStats ¶
func HandleFilesStats(fm *FileManager) http.HandlerFunc
HandleFilesStats handles GET /files/stats Query params:
- thread_id: Get stats for a specific thread
- global=true: Get global stats with per-thread breakdown
func HasFileReferences ¶
func HasFileReferences(blocks []ContentBlock) bool
HasFileReferences checks if content blocks contain file references
Types ¶
type CleanupJob ¶
type CleanupJob struct {
// contains filtered or unexported fields
}
CleanupJob runs periodic cleanup tasks
func NewCleanupJob ¶
func NewCleanupJob(fm *FileManager, interval time.Duration) *CleanupJob
NewCleanupJob creates a new cleanup job
type ContentBlock ¶
type ContentBlock struct {
Type string `json:"type"` // "text", "image", "document", "tool_use", "tool_result"
Text string `json:"text,omitempty"` // for text blocks
Source *ContentSource `json:"source,omitempty"` // for image and document blocks
ID string `json:"id,omitempty"` // for tool_use
Name string `json:"name,omitempty"` // for tool_use
Input map[string]interface{} `json:"input,omitempty"` // for tool_use
ToolUseID string `json:"tool_use_id,omitempty"` // for tool_result
Content interface{} `json:"content,omitempty"` // for tool_result
IsError bool `json:"is_error,omitempty"` // for tool_result
}
ContentBlock represents a content block in a message
type ContentSource ¶
type ContentSource struct {
Type string `json:"type"` // "base64", "url", "file"
MediaType string `json:"media_type,omitempty"` // "image/jpeg", "application/pdf", etc.
Data string `json:"data,omitempty"` // For base64
URL string `json:"url,omitempty"` // For URL
FileID string `json:"file_id,omitempty"` // For file reference
}
ContentSource represents a source for image/document content
type DeletionCallback ¶
type DeletionCallback func(fileID string)
DeletionCallback is called before a file is deleted to clean up associated data (e.g., memories)
type File ¶
type File struct {
ID string `json:"id"`
ThreadID string `json:"thread_id,omitempty"`
MessageID string `json:"message_id,omitempty"`
Filename string `json:"filename"`
MimeType string `json:"mime_type"`
FileType string `json:"file_type"`
SizeBytes int64 `json:"size_bytes"`
Checksum string `json:"checksum"`
Data []byte `json:"-"` // Exclude from JSON
Width *int `json:"width,omitempty"`
Height *int `json:"height,omitempty"`
Duration *int `json:"duration,omitempty"`
Metadata map[string]interface{} `json:"metadata"`
Source string `json:"source"`
SourceTool string `json:"source_tool,omitempty"`
CreatedAt time.Time `json:"created_at"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
}
File represents a stored file
type FileManager ¶
type FileManager struct {
// contains filtered or unexported fields
}
FileManager handles file storage operations
func NewFileManager ¶
func NewFileManager(db *sql.DB, cfg *config.FileSystemConfig) *FileManager
NewFileManager creates a new FileManager instance
func (*FileManager) CleanupExpired ¶
func (fm *FileManager) CleanupExpired(ctx context.Context) (int, error)
CleanupExpired removes expired files based on retention policy
func (*FileManager) CleanupOrphans ¶
func (fm *FileManager) CleanupOrphans(ctx context.Context) (int, error)
CleanupOrphans is disabled - files are never automatically deleted
func (*FileManager) Delete ¶
func (fm *FileManager) Delete(ctx context.Context, fileID string) error
Delete removes a file by ID
func (*FileManager) DeleteByID ¶
func (fm *FileManager) DeleteByID(fileID string) error
DeleteByID removes a file by ID (without context for simpler tool usage)
func (*FileManager) ExpandFileReferences ¶
func (fm *FileManager) ExpandFileReferences(blocks []ContentBlock) ([]ContentBlock, error)
ExpandFileReferences converts file references back to base64 for LLM calls
func (*FileManager) ExtractImagesFromToolResult ¶
func (fm *FileManager) ExtractImagesFromToolResult(result interface{}, threadID, source string) (interface{}, []string, error)
ExtractImagesFromToolResult recursively finds and extracts base64 images from any nested structure Returns the modified result with images replaced by file references, and a list of extracted file IDs
func (*FileManager) FindByChecksum ¶
FindByChecksum finds a file by its checksum (for deduplication)
func (*FileManager) GetAsBase64 ¶
GetAsBase64 retrieves a file and returns it as base64 encoded string
func (*FileManager) GetGlobalStats ¶
func (fm *FileManager) GetGlobalStats(ctx context.Context) (*GlobalStorageStats, error)
GetGlobalStats returns storage statistics with per-thread breakdown
func (*FileManager) GetMetadata ¶
func (fm *FileManager) GetMetadata(fileID string) (*File, error)
GetMetadata retrieves file metadata by ID (without the data blob)
func (*FileManager) GetPublicURL ¶
func (fm *FileManager) GetPublicURL(fileID string) (string, error)
GetPublicURL generates a public download URL for a file
func (*FileManager) GetStats ¶
func (fm *FileManager) GetStats(ctx context.Context) (*StorageStats, error)
GetStats returns storage statistics
func (*FileManager) GetStatsByThread ¶
func (fm *FileManager) GetStatsByThread(ctx context.Context, threadID string) (*ThreadStorageStats, error)
GetStatsByThread returns storage statistics for a specific thread
func (*FileManager) IsEnabled ¶
func (fm *FileManager) IsEnabled() bool
IsEnabled returns whether the filesystem is enabled
func (*FileManager) ListFilesFiltered ¶
func (fm *FileManager) ListFilesFiltered(threadID, fileType string, limit int) ([]*File, error)
ListFilesFiltered returns a list of files with optional filtering by thread and file type
func (*FileManager) ProcessContentBlocks ¶
func (fm *FileManager) ProcessContentBlocks(blocks []ContentBlock, threadID, messageID, source string) ([]ContentBlock, error)
ProcessContentBlocks extracts base64 content and stores as files
func (*FileManager) SearchFiles ¶
func (fm *FileManager) SearchFiles(query, fileType string, limit int) ([]*File, error)
SearchFiles searches files by filename pattern
func (*FileManager) SetDeletionCallback ¶
func (fm *FileManager) SetDeletionCallback(callback DeletionCallback)
SetDeletionCallback sets the callback for cleanup when a file is deleted
func (*FileManager) SetIngestionCallback ¶
func (fm *FileManager) SetIngestionCallback(callback IngestionCallback)
SetIngestionCallback sets the callback for memory ingestion after file storage
func (*FileManager) StripFileReferences ¶
func (fm *FileManager) StripFileReferences(blocks []ContentBlock) []ContentBlock
StripFileReferences removes file references from content blocks Used for context management when stripping old images
type GlobalStorageStats ¶
type GlobalStorageStats struct {
TotalFiles int `json:"total_files"`
TotalSizeBytes int64 `json:"total_size_bytes"`
FilesByType map[string]int `json:"files_by_type"`
BytesByType map[string]int64 `json:"bytes_by_type"`
ByThread map[string]*ThreadStorageStats `json:"by_thread"`
OldestFile *time.Time `json:"oldest_file,omitempty"`
NewestFile *time.Time `json:"newest_file,omitempty"`
}
GlobalStorageStats represents storage statistics with per-thread breakdown
type IngestionCallback ¶
IngestionCallback is called after a file is stored to trigger memory ingestion
type StorageStats ¶
type StorageStats struct {
TotalFiles int `json:"total_files"`
TotalSizeBytes int64 `json:"total_size_bytes"`
FilesByType map[string]int `json:"files_by_type"`
BytesByType map[string]int64 `json:"bytes_by_type"`
OldestFile *time.Time `json:"oldest_file,omitempty"`
NewestFile *time.Time `json:"newest_file,omitempty"`
}
StorageStats represents storage statistics
type ThreadStorageStats ¶
type ThreadStorageStats struct {
ThreadID string `json:"thread_id"`
TotalFiles int `json:"total_files"`
TotalSizeBytes int64 `json:"total_size_bytes"`
FilesByType map[string]int `json:"files_by_type"`
BytesByType map[string]int64 `json:"bytes_by_type"`
}
ThreadStorageStats represents per-thread storage statistics