Documentation
¶
Overview ¶
Package gdrive provides a DataSource connector that enumerates Google Drive files in configured folders for vectorization. It uses the existing gdrive.Service to list and read file content; text files and Google Docs are included as NormalizedItems.
Index ¶
- func AllTools(name string, s Service) []tool.Tool
- func NewGetFileTool(name string, s Service) tool.CallableTool
- func NewListFolderTool(name string, s Service) tool.CallableTool
- func NewReadFileTool(name string, s Service) tool.CallableTool
- func NewSearchTool(name string, s Service) tool.CallableTool
- type Config
- type FileDetail
- type FileInfo
- type GDriveConnector
- type Service
- type ToolProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllTools ¶
AllTools returns all Google Drive tools wired to the service, with tool names prefixed by name.
func NewGetFileTool ¶
func NewGetFileTool(name string, s Service) tool.CallableTool
func NewListFolderTool ¶
func NewListFolderTool(name string, s Service) tool.CallableTool
func NewReadFileTool ¶
func NewReadFileTool(name string, s Service) tool.CallableTool
func NewSearchTool ¶
func NewSearchTool(name string, s Service) tool.CallableTool
Types ¶
type Config ¶
type Config struct {
CredentialsFile string `yaml:"credentials_file,omitempty" toml:"credentials_file,omitempty"` // Path to service account JSON
}
Config holds configuration for the Google Drive connector.
type FileDetail ¶
type FileDetail struct {
ID string `json:"id"`
Name string `json:"name"`
MimeType string `json:"mime_type"`
Size int64 `json:"size,omitempty"`
ModifiedTime string `json:"modified_time,omitempty"`
CreatedTime string `json:"created_time,omitempty"`
Owners []string `json:"owners,omitempty"`
WebViewLink string `json:"web_view_link,omitempty"`
IsFolder bool `json:"is_folder"`
}
FileDetail is an extended file description.
type FileInfo ¶
type FileInfo struct {
ID string `json:"id"`
Name string `json:"name"`
MimeType string `json:"mime_type"`
Size int64 `json:"size,omitempty"`
ModifiedTime string `json:"modified_time,omitempty"`
IsFolder bool `json:"is_folder"`
}
FileInfo describes a file or folder in Google Drive.
type GDriveConnector ¶
type GDriveConnector struct {
// contains filtered or unexported fields
}
GDriveConnector implements datasource.DataSource for Google Drive. It lists files in each folder in scope, reads text content where possible, and returns one NormalizedItem per file for the sync pipeline to vectorize.
func NewGDriveConnector ¶
func NewGDriveConnector(svc Service) *GDriveConnector
NewGDriveConnector returns a DataSource that lists and reads Drive files. The caller must provide an initialised gdrive.Service (credentials and auth are handled by the service).
func (*GDriveConnector) ListItems ¶
func (c *GDriveConnector) ListItems(ctx context.Context, scope datasource.Scope) ([]datasource.NormalizedItem, error)
ListItems lists files in each folder in scope.GDriveFolderIDs, reads content for supported types (Docs, plain text), and returns one NormalizedItem per file with ID "gdrive:fileId". Folders are skipped. Binary or unsupported files are included with content set to the file name only.
func (*GDriveConnector) ListItemsSince ¶
func (c *GDriveConnector) ListItemsSince(ctx context.Context, scope datasource.Scope, since time.Time) ([]datasource.NormalizedItem, error)
ListItemsSince returns only files modified after the given time (per folder). Uses the Drive API modifiedTime query so only changed files are fetched.
func (*GDriveConnector) Name ¶
func (c *GDriveConnector) Name() string
Name returns the source identifier for Google Drive.
type Service ¶
type Service interface {
// Search finds files matching a query string (Google Drive search syntax).
Search(ctx context.Context, query string, maxResults int) ([]FileInfo, error)
// ListFolder lists files in a specific folder by folder ID.
ListFolder(ctx context.Context, folderID string, maxResults int) ([]FileInfo, error)
// ListFolderModifiedSince lists files in a folder that were modified after the given time.
// Used for incremental sync; the Drive API supports modifiedTime in the query.
ListFolderModifiedSince(ctx context.Context, folderID string, since time.Time, maxResults int) ([]FileInfo, error)
// GetFile returns metadata about a file.
GetFile(ctx context.Context, fileID string) (*FileDetail, error)
// ReadFile reads the text content of a file (Google Docs, Sheets, text).
// For Google Docs/Sheets, it exports as plain text.
// For binary files, it returns an error with the MIME type.
ReadFile(ctx context.Context, fileID string) (string, error)
// Validate performs a lightweight health check.
Validate(ctx context.Context) error
}
Service defines the capabilities of the Google Drive connector. It gives the AI agent read-only access to search, list, and read files from Google Drive. Write operations are intentionally omitted to reduce blast radius.
func New ¶
New creates a new Google Drive Service based on the configuration. It delegates to the internal wrapper which uses the official Drive API v3 client library. Without this factory, callers would need to know about the wrapper's internal constructor, coupling them to implementation details.
func NewFromSecretProvider ¶
NewFromSecretProvider creates a Google Drive Service using the same logged-in user token as Gmail/Calendar (from TokenFile, Token/Password, or device keychain). One sign-in can be reused for Calendar, Contacts, Drive, and Gmail. Drive MUST use this path so it acts as the signed-in user.
type ToolProvider ¶
type ToolProvider struct {
// contains filtered or unexported fields
}
ToolProvider wraps a Google Drive Service and satisfies the tools.ToolProviders interface so Google Drive tools can be passed directly to tools.NewRegistry.
func NewToolProvider ¶
func NewToolProvider(svc Service) *ToolProvider
NewToolProvider creates a ToolProvider from an already-initialised Google Drive service.