gmail

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package gmail provides a DataSource connector that enumerates Gmail messages for given labels for vectorization. It uses the existing Gmail Service to list messages (by label) and optionally fetches full body for richer content.

Package gmail provides Gmail API tools for agents. It enables list, get, and send operations using the Gmail API with the shared Google OAuth token (Calendar, Contacts, Drive, Gmail). One sign-in can power all Google tools.

Available tools (prefixed with google_gmail_ when registered):

  • google_gmail_list_messages — list messages with optional query
  • google_gmail_get_message — get a single message by ID
  • google_gmail_send — send an email

Authentication: Same as other pkg/tools/google packages — TokenFile, Token/Password, or device keyring; CredentialsFile for OAuth client config.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllTools

func AllTools(name string, svc Service) []tool.Tool

AllTools returns all Gmail tools with the given name prefix (e.g. google_gmail).

Types

type GmailConnector

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

GmailConnector implements datasource.DataSource for Gmail. It lists messages for each label in scope.GmailLabelIDs and returns one NormalizedItem per message (subject + snippet, or full body when fetched).

func NewGmailConnector

func NewGmailConnector(svc Service) *GmailConnector

NewGmailConnector returns a DataSource that lists Gmail messages by label. The caller must provide an initialised Gmail Service.

func (*GmailConnector) ListItems

ListItems lists messages for each label in scope.GmailLabelIDs (query "label:<id>") and returns one NormalizedItem per message with ID "gmail:messageId". Content is subject + snippet from the list response only; full-body fetch is not performed here to avoid N+1 API calls and rate limits. The sync layer can add optional full-body enrichment in a later step if needed.

func (*GmailConnector) ListItemsSince

func (c *GmailConnector) ListItemsSince(ctx context.Context, scope datasource.Scope, since time.Time) ([]datasource.NormalizedItem, error)

ListItemsSince returns only messages updated (internal date) after the given time. It uses Gmail search "after:YYYY/MM/DD" so the API returns only new/updated messages.

func (*GmailConnector) Name

func (c *GmailConnector) Name() string

Name returns the source identifier for Gmail.

type MessageDetail

type MessageDetail struct {
	ID          string   `json:"id"`
	ThreadID    string   `json:"thread_id"`
	Subject     string   `json:"subject"`
	From        string   `json:"from"`
	To          []string `json:"to"`
	Date        string   `json:"date"`
	BodyPlain   string   `json:"body_plain"`
	BodyHTML    string   `json:"body_html,omitempty"`
	Snippet     string   `json:"snippet"`
	Attachments []string `json:"attachments,omitempty"`
}

MessageDetail is a full message for get_message.

type MessageSummary

type MessageSummary struct {
	ID       string `json:"id"`
	ThreadID string `json:"thread_id"`
	Subject  string `json:"subject,omitempty"`
	From     string `json:"from,omitempty"`
	Date     string `json:"date,omitempty"`
	Snippet  string `json:"snippet,omitempty"`
}

MessageSummary is a lightweight message entry for list results.

type Service

type Service interface {
	ListMessages(ctx context.Context, query string, maxResults int) ([]*MessageSummary, error)
	GetMessage(ctx context.Context, id string) (*MessageDetail, error)
	Send(ctx context.Context, to []string, subject, body string) error
	Validate(ctx context.Context) error
}

Service provides Gmail operations for tools.

func NewFromSecretProvider

func NewFromSecretProvider(ctx context.Context, sp security.SecretProvider) (Service, error)

NewFromSecretProvider creates a Gmail Service using the shared Google OAuth token (TokenFile, Token/Password, or device keyring). One sign-in can power Calendar, Contacts, Drive, and Gmail.

type ToolProvider

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

ToolProvider wraps a Gmail Service and satisfies the tools.ToolProviders interface so Gmail tools can be passed to tools.NewRegistry. Tools are prefixed with the given name (e.g. google_gmail).

func NewToolProvider

func NewToolProvider(svc Service) *ToolProvider

NewToolProvider creates a ToolProvider from an initialized Gmail service.

func (*ToolProvider) GetTools

func (p *ToolProvider) GetTools(name string) []tool.Tool

GetTools returns all Gmail tools with the given name prefix.

Jump to

Keyboard shortcuts

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