Documentation
¶
Index ¶
- Constants
- Variables
- func CacheKey(workspaceId uint, integration, path, operation string) string
- func DefaultFilenameFormat(integration string) string
- func GenerateErrorJSON(err error) []byte
- func GenerateSourceReadme(integration string, connected bool, scope string, workspaceId string) []byte
- func NowUnix() int64
- func SanitizeFilename(s string) string
- type CacheEntry
- type CacheStats
- type DirEntry
- type FileInfo
- type Provider
- type ProviderContext
- type QueryExecutor
- type QueryResponse
- type QueryResult
- type QuerySpec
- type RateLimitConfig
- type RateLimiter
- type Registry
- type SearchResult
- type SourceCache
- func (c *SourceCache) DoOnce(key string, fn func() (any, error)) (any, error)
- func (c *SourceCache) GetData(key string) ([]byte, bool)
- func (c *SourceCache) GetEntries(key string) ([]DirEntry, bool)
- func (c *SourceCache) GetInfo(key string) (*FileInfo, bool)
- func (c *SourceCache) Invalidate(key string)
- func (c *SourceCache) InvalidatePrefix(prefix string)
- func (c *SourceCache) SetData(key string, data []byte)
- func (c *SourceCache) SetEntries(key string, entries []DirEntry)
- func (c *SourceCache) SetEntriesWithTTL(key string, entries []DirEntry, ttl time.Duration)
- func (c *SourceCache) SetInfo(key string, info *FileInfo)
- func (c *SourceCache) Stats() CacheStats
- type SourceStatus
Constants ¶
const ( DefaultCacheTTL = 30 * time.Second // DefaultCacheTTL is the default TTL for cached source data DefaultCacheSize = 10000 // DefaultCacheSize is the maximum number of cache entries )
const ( ModeDir = syscall.S_IFDIR | 0755 ModeFile = syscall.S_IFREG | 0644 ModeLink = syscall.S_IFLNK | 0777 )
Common file modes
Variables ¶
var ErrIsDir = fmt.Errorf("is a directory")
ErrIsDir is returned when path is a directory but file was expected
var ErrNotConnected = fmt.Errorf("integration not connected")
ErrNotConnected is returned when the integration is not connected
var ErrNotDir = fmt.Errorf("not a directory")
ErrNotDir is returned when path is not a directory
var ErrNotFound = fmt.Errorf("not found")
ErrNotFound is returned when a path doesn't exist
var ErrRateLimited = fmt.Errorf("rate limited")
ErrRateLimited is returned when a request is rate limited
var ErrSearchNotSupported = errors.New("search not supported")
ErrSearchNotSupported is returned when a provider doesn't support search
Functions ¶
func DefaultFilenameFormat ¶
DefaultFilenameFormat returns a sensible default filename format for an integration.
func GenerateErrorJSON ¶
GenerateErrorJSON creates a JSON error response
func GenerateSourceReadme ¶
func GenerateSourceReadme(integration string, connected bool, scope string, workspaceId string) []byte
GenerateSourceReadme creates the README.md content for an integration
func SanitizeFilename ¶
SanitizeFilename makes a string safe for use as a filename. It removes emojis, non-ASCII characters, and filesystem-unsafe characters, keeping only alphanumeric, underscores, hyphens, and dots. This is the canonical sanitization function for all providers.
Types ¶
type CacheEntry ¶
CacheEntry holds a cached response with expiration
func (*CacheEntry) IsExpired ¶
func (e *CacheEntry) IsExpired() bool
IsExpired returns true if the entry has expired
type CacheStats ¶
CacheStats contains cache statistics
type FileInfo ¶
type FileInfo struct {
Size int64
Mode uint32
Mtime int64 // Unix timestamp
IsDir bool
IsLink bool
}
FileInfo contains file/directory metadata
func FileInfoFromBytes ¶
FileInfoFromBytes creates FileInfo for file content
type Provider ¶
type Provider interface {
// Name returns the integration name (e.g., "github", "gmail")
Name() string
// Stat returns file/directory attributes for a path within the integration
// Path is relative to the integration root (e.g., "views/repos.json" not "github/views/repos.json")
Stat(ctx context.Context, pctx *ProviderContext, path string) (*FileInfo, error)
// ReadDir lists directory contents
ReadDir(ctx context.Context, pctx *ProviderContext, path string) ([]DirEntry, error)
// Read reads file content
// Returns the data and any error
Read(ctx context.Context, pctx *ProviderContext, path string, offset, length int64) ([]byte, error)
// Readlink reads a symbolic link target (optional, return empty string if not supported)
Readlink(ctx context.Context, pctx *ProviderContext, path string) (string, error)
// Search executes a provider-specific query and returns results
// The query format is provider-specific (e.g., Gmail search syntax, Drive query syntax)
// Returns ErrSearchNotSupported if the provider doesn't support search
Search(ctx context.Context, pctx *ProviderContext, query string, limit int) ([]SearchResult, error)
}
Provider defines the interface for source integrations. Each integration (github, gmail, notion, etc.) implements this interface.
type ProviderContext ¶
type ProviderContext struct {
WorkspaceId uint
MemberId uint
Credentials *types.IntegrationCredentials
}
ProviderContext contains workspace and credential info for provider operations
type QueryExecutor ¶
type QueryExecutor interface {
// ExecuteQuery runs a query and returns results with pagination metadata.
// The spec contains the provider-specific query string, filename format,
// and optional PageToken for fetching subsequent pages.
// Returns a QueryResponse containing results and pagination info.
ExecuteQuery(ctx context.Context, pctx *ProviderContext, spec QuerySpec) (*QueryResponse, error)
// ReadResult fetches content for a specific result by its provider ID.
// This is called when a user reads a file from a smart query folder.
ReadResult(ctx context.Context, pctx *ProviderContext, resultID string) ([]byte, error)
// FormatFilename generates a filename from metadata using the format template.
// Supported placeholders vary by provider but typically include:
// - {id}: Unique identifier
// - {date}: Date in YYYY-MM-DD format
// - {subject}, {from}, {to}: Email-specific
// - {title}, {name}: Document-specific
// The result should be sanitized for filesystem use.
FormatFilename(format string, metadata map[string]string) string
}
QueryExecutor is an optional interface implemented by providers that support filesystem query operations. This enables the smart query filesystem feature where users create virtual folders/files that execute queries on access.
type QueryResponse ¶
type QueryResponse struct {
Results []QueryResult // Results for this page
NextPageToken string // Token for fetching the next page (empty if no more pages)
HasMore bool // True if there are more results beyond this page
}
QueryResponse wraps query results with pagination metadata. Providers return this to indicate whether more results are available.
type QueryResult ¶
type QueryResult struct {
ID string // Provider-specific ID (e.g., Gmail message ID, GDrive file ID)
Filename string // Generated filename using FilenameFormat
Metadata map[string]string // Key-value metadata (date, subject, from, etc.)
Size int64 // Content size in bytes (0 if unknown)
Mtime int64 // Last modified time (Unix timestamp)
}
QueryResult represents a single result from executing a filesystem query. This is used by QueryExecutor to return search results with metadata.
type QuerySpec ¶
type QuerySpec struct {
Query string // Provider-specific query string (e.g., "is:unread", "mimeType='application/pdf'")
Limit int // Page size - number of results per page (default 50)
MaxResults int // Total cap on results across all pages (default 500)
FilenameFormat string // Format template for generating filenames (e.g., "{date}_{subject}_{id}.txt")
PageToken string // Pagination token for fetching subsequent pages
Metadata map[string]string // Additional provider-specific metadata (e.g., content_type for GitHub)
}
QuerySpec contains the parsed query specification from a FilesystemQuery.
type RateLimitConfig ¶
type RateLimitConfig struct {
// RequestsPerSecond is the rate limit per integration per workspace
RequestsPerSecond float64
// BurstSize is the maximum burst size
BurstSize int
// CleanupInterval is how often to clean up stale limiters
CleanupInterval time.Duration
}
RateLimitConfig configures the rate limiter
func DefaultRateLimitConfig ¶
func DefaultRateLimitConfig() RateLimitConfig
DefaultRateLimitConfig returns sensible defaults
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter provides per-integration, per-workspace rate limiting to prevent hammering upstream APIs when multiple agents are active.
func NewRateLimiter ¶
func NewRateLimiter(config RateLimitConfig) *RateLimiter
NewRateLimiter creates a new rate limiter
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages registered source providers
type SearchResult ¶
type SearchResult struct {
Name string // filename for the result (e.g., "2026-01-28_invoice_abc123.txt")
Id string // internal ID for fetching content (e.g., message ID, file ID)
Mode uint32 // file mode
Size int64 // file size if known, 0 otherwise
Mtime int64 // modification time (Unix timestamp)
Preview string // optional preview/snippet of content
}
SearchResult represents a single search result from a provider
type SourceCache ¶
type SourceCache struct {
// contains filtered or unexported fields
}
SourceCache provides caching and request coalescing for source operations. It helps prevent upstream API hammering when multiple agents read the same data.
func NewSourceCache ¶
func NewSourceCache(ttl time.Duration, maxSize int) *SourceCache
NewSourceCache creates a new source cache
func (*SourceCache) DoOnce ¶
DoOnce executes a function only once for concurrent requests with the same key. Other callers with the same key will wait and receive the same result.
func (*SourceCache) GetData ¶
func (c *SourceCache) GetData(key string) ([]byte, bool)
GetData returns cached data if available and not expired
func (*SourceCache) GetEntries ¶
func (c *SourceCache) GetEntries(key string) ([]DirEntry, bool)
GetEntries returns cached DirEntry list if available and not expired
func (*SourceCache) GetInfo ¶
func (c *SourceCache) GetInfo(key string) (*FileInfo, bool)
GetInfo returns cached FileInfo if available and not expired
func (*SourceCache) Invalidate ¶
func (c *SourceCache) Invalidate(key string)
Invalidate removes a cache entry
func (*SourceCache) InvalidatePrefix ¶
func (c *SourceCache) InvalidatePrefix(prefix string)
InvalidatePrefix removes all cache entries matching a prefix
func (*SourceCache) SetData ¶
func (c *SourceCache) SetData(key string, data []byte)
SetData caches data with the default TTL
func (*SourceCache) SetEntries ¶
func (c *SourceCache) SetEntries(key string, entries []DirEntry)
SetEntries caches directory entries with the default TTL
func (*SourceCache) SetEntriesWithTTL ¶
func (c *SourceCache) SetEntriesWithTTL(key string, entries []DirEntry, ttl time.Duration)
SetEntriesWithTTL caches directory entries with a custom TTL
func (*SourceCache) SetInfo ¶
func (c *SourceCache) SetInfo(key string, info *FileInfo)
SetInfo caches FileInfo with the default TTL
Directories
¶
| Path | Synopsis |
|---|---|
|
Package queries provides smart query inference and execution for integration sources.
|
Package queries provides smart query inference and execution for integration sources. |