services

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package services implements the driving port interfaces. Services contain the core business logic and orchestrate calls to driven ports (adapters).

Services are pure Go with no CGO or external dependencies.

Index

Constants

This section is empty.

Variables

View Source
var ErrRefreshNotImplemented = errors.New("document refresh not yet implemented")

Sentinel errors for stub implementations.

Functions

func FindAvailablePort

func FindAvailablePort(startPort, endPort int) (int, error)

FindAvailablePort finds an available port in the given range.

Types

type AuthProviderService

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

AuthProviderService manages authentication provider configurations.

func NewAuthProviderService

func NewAuthProviderService(store driven.AuthProviderStore, sourceStore driven.SourceStore) *AuthProviderService

NewAuthProviderService creates a new auth provider service.

func (*AuthProviderService) Delete

func (s *AuthProviderService) Delete(ctx context.Context, id string) error

Delete removes an auth provider. Returns an error if the provider is still in use by any source.

func (*AuthProviderService) Get

Get retrieves an auth provider by ID.

func (*AuthProviderService) List

List returns all auth providers.

func (*AuthProviderService) ListByProvider

func (s *AuthProviderService) ListByProvider(
	ctx context.Context,
	providerType domain.ProviderType,
) ([]domain.AuthProvider, error)

ListByProvider returns auth providers for a specific provider type.

func (*AuthProviderService) Save

Save creates or updates an auth provider.

type ConnectorRegistry

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

ConnectorRegistry provides information about available connector types.

func NewConnectorRegistry

func NewConnectorRegistry(connectorFactory driven.ConnectorFactory) *ConnectorRegistry

NewConnectorRegistry creates a new connector registry with built-in connectors.

func (*ConnectorRegistry) BuildAuthURL

func (r *ConnectorRegistry) BuildAuthURL(
	connectorType string,
	authProvider *domain.AuthProvider,
	redirectURI, state, codeChallenge string,
) (string, error)

BuildAuthURL constructs the OAuth authorization URL for a connector type. Includes provider-specific parameters (e.g., access_type=offline for Google).

func (*ConnectorRegistry) ExchangeCode added in v0.2.3

func (r *ConnectorRegistry) ExchangeCode(
	ctx context.Context,
	connectorType string,
	authProvider *domain.AuthProvider,
	code, redirectURI, codeVerifier string,
) (*domain.OAuthToken, error)

ExchangeCode exchanges an authorization code for tokens using connector-specific logic.

func (*ConnectorRegistry) Get

Get returns a specific connector type by ID.

func (*ConnectorRegistry) GetConnectorsForProvider added in v0.2.3

func (r *ConnectorRegistry) GetConnectorsForProvider(provider domain.ProviderType) []domain.ConnectorType

GetConnectorsForProvider returns all connector types for a given provider.

func (*ConnectorRegistry) GetOAuthDefaults

func (r *ConnectorRegistry) GetOAuthDefaults(connectorType string) *driving.OAuthDefaults

GetOAuthDefaults returns default OAuth URLs and scopes for a connector type. Returns nil if the connector type doesn't support OAuth.

func (*ConnectorRegistry) GetSetupHint

func (r *ConnectorRegistry) GetSetupHint(connectorType string) string

GetSetupHint returns guidance text for setting up OAuth/PAT with a provider.

func (*ConnectorRegistry) GetUserInfo

func (r *ConnectorRegistry) GetUserInfo(
	ctx context.Context,
	connectorType string,
	accessToken string,
) (string, error)

GetUserInfo fetches the account identifier (email/username) for a connector type.

func (*ConnectorRegistry) List

List returns all available connector types.

func (*ConnectorRegistry) SupportsOAuth

func (r *ConnectorRegistry) SupportsOAuth(connectorType string) bool

SupportsOAuth returns true if the connector type supports OAuth authentication.

func (*ConnectorRegistry) ValidateConfig

func (r *ConnectorRegistry) ValidateConfig(connectorID string, config map[string]string) error

ValidateConfig validates configuration for a connector type.

type CredentialsService

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

CredentialsService manages user-specific authentication credentials.

func NewCredentialsService

func NewCredentialsService(store driven.CredentialsStore) *CredentialsService

NewCredentialsService creates a new credentials service.

func (*CredentialsService) Delete

func (s *CredentialsService) Delete(ctx context.Context, id string) error

Delete removes credentials by ID.

func (*CredentialsService) Get

Get retrieves credentials by ID.

func (*CredentialsService) GetBySourceID

func (s *CredentialsService) GetBySourceID(ctx context.Context, sourceID string) (*domain.Credentials, error)

GetBySourceID retrieves credentials for a specific source.

func (*CredentialsService) Save

Save creates or updates credentials.

type DocumentService

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

DocumentService manages documents within sources.

func NewDocumentService

func NewDocumentService(
	docStore driven.DocumentStore,
	sourceStore driven.SourceStore,
	exclusionStore driven.ExclusionStore,
	connectorRegistry driving.ConnectorRegistry,
) *DocumentService

NewDocumentService creates a new document service.

func (*DocumentService) Exclude

func (s *DocumentService) Exclude(ctx context.Context, documentID, reason string) error

Exclude removes a document and marks it to skip during re-sync.

func (*DocumentService) Get

func (s *DocumentService) Get(ctx context.Context, documentID string) (*domain.Document, error)

Get retrieves a document by ID.

func (*DocumentService) GetContent

func (s *DocumentService) GetContent(ctx context.Context, documentID string) (string, error)

GetContent returns the concatenated content of all chunks.

func (*DocumentService) GetDetails

func (s *DocumentService) GetDetails(ctx context.Context, documentID string) (*driving.DocumentDetails, error)

GetDetails returns connector-agnostic metadata for display.

func (*DocumentService) ListBySource

func (s *DocumentService) ListBySource(ctx context.Context, sourceID string) ([]domain.Document, error)

ListBySource returns all documents for a source.

func (*DocumentService) Open

func (s *DocumentService) Open(ctx context.Context, documentID string) error

Open opens the document in the default application.

func (*DocumentService) Refresh

func (s *DocumentService) Refresh(_ context.Context, _ string) error

Refresh re-syncs a single document from its source. TODO: Implement when sync infrastructure supports single-document refresh.

type ProviderRegistry

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

ProviderRegistry provides information about providers and their compatible connectors. It derives all provider information from the registered connectors, ensuring no hardcoded provider knowledge exists in this service.

func NewProviderRegistry

func NewProviderRegistry(
	connectorRegistry driving.ConnectorRegistry,
	connectorFactory driven.ConnectorFactory,
) *ProviderRegistry

NewProviderRegistry creates a new ProviderRegistry. Both dependencies are required for full functionality but can be nil for limited use.

func (*ProviderRegistry) GetAuthCapability

func (r *ProviderRegistry) GetAuthCapability(provider domain.ProviderType) domain.AuthCapability

GetAuthCapability returns the authentication capabilities for a provider. Derives this from the first connector registered for the provider.

func (*ProviderRegistry) GetConnectorsForProvider

func (r *ProviderRegistry) GetConnectorsForProvider(provider domain.ProviderType) []string

GetConnectorsForProvider returns connector types compatible with a provider.

func (*ProviderRegistry) GetDefaultAuthMethod

func (r *ProviderRegistry) GetDefaultAuthMethod(provider domain.ProviderType) domain.AuthMethod

GetDefaultAuthMethod returns the typical auth method for a provider. For providers supporting multiple methods, returns the recommended default.

func (*ProviderRegistry) GetOAuthEndpoints

func (r *ProviderRegistry) GetOAuthEndpoints(provider domain.ProviderType) *driving.OAuthEndpoints

GetOAuthEndpoints returns the OAuth endpoints for a provider. Delegates to the connector factory to get default OAuth config from the connector's OAuthHandler.

func (*ProviderRegistry) GetProviderForConnector

func (r *ProviderRegistry) GetProviderForConnector(connectorType string) (domain.ProviderType, error)

GetProviderForConnector returns the provider type for a connector.

func (*ProviderRegistry) GetProviders

func (r *ProviderRegistry) GetProviders() []domain.ProviderType

GetProviders returns all available provider types. Derives the list from registered connectors.

func (*ProviderRegistry) GetSupportedAuthMethods

func (r *ProviderRegistry) GetSupportedAuthMethods(provider domain.ProviderType) []domain.AuthMethod

GetSupportedAuthMethods returns all auth methods supported by a provider.

func (*ProviderRegistry) HasMultipleConnectors

func (r *ProviderRegistry) HasMultipleConnectors(provider domain.ProviderType) bool

HasMultipleConnectors returns true if the provider supports multiple distinct connectors that can share an OAuth app. For example, Google has Drive, Gmail, Calendar as separate connectors that can share the same OAuth app credentials.

func (*ProviderRegistry) IsCompatible

func (r *ProviderRegistry) IsCompatible(provider domain.ProviderType, connectorType string) bool

IsCompatible checks if a connector can use a provider.

func (*ProviderRegistry) SupportsMultipleAuthMethods

func (r *ProviderRegistry) SupportsMultipleAuthMethods(provider domain.ProviderType) bool

SupportsMultipleAuthMethods returns true if the provider supports choosing between auth methods.

type ResultActionService

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

ResultActionService provides actions on search results.

func NewResultActionService

func NewResultActionService(
	sourceStore driven.SourceStore,
	connectorRegistry driving.ConnectorRegistry,
) *ResultActionService

NewResultActionService creates a new result action service.

func (*ResultActionService) CopyToClipboard

func (s *ResultActionService) CopyToClipboard(_ context.Context, result *domain.SearchResult) error

CopyToClipboard copies the result's content to the system clipboard.

func (*ResultActionService) OpenDocument

func (s *ResultActionService) OpenDocument(ctx context.Context, result *domain.SearchResult) error

OpenDocument opens the result's document in the default application.

type Scheduler

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

Scheduler manages background task execution. It is a pure core service with no external control API.

func NewScheduler

func NewScheduler(
	config domain.SchedulerConfig,
	store driven.SchedulerStore,
	syncOrch driving.SyncOrchestrator,
) *Scheduler

NewScheduler creates a scheduler with configuration.

func (*Scheduler) Start

func (s *Scheduler) Start(ctx context.Context) error

Start begins the scheduler loop. This method blocks until Stop is called.

func (*Scheduler) Stop

func (s *Scheduler) Stop() error

Stop gracefully shuts down the scheduler.

type SearchService

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

SearchService provides hybrid search functionality.

func NewSearchService

func NewSearchService(
	docStore driven.DocumentStore,
	searchIndex driven.SearchEngine,
	vectorIndex driven.VectorIndex,
	embeddingService driven.EmbeddingService,
	llmService driven.LLMService,
) *SearchService

NewSearchService creates a new search service. The embeddingService and llmService parameters are optional (can be nil).

func (*SearchService) Search

func (s *SearchService) Search(
	ctx context.Context, query string, opts domain.SearchOptions,
) ([]domain.SearchResult, error)

Search performs hybrid search across all indexed documents.

func (*SearchService) SetCredentialsStore

func (s *SearchService) SetCredentialsStore(store driven.CredentialsStore)

SetCredentialsStore sets the credentials store for SourceName enrichment.

func (*SearchService) SetSourceStore

func (s *SearchService) SetSourceStore(store driven.SourceStore)

SetSourceStore sets the source store for SourceName enrichment.

type SettingsService

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

SettingsService manages application settings.

func NewSettingsService

func NewSettingsService(configStore driven.ConfigStore, aiValidator driven.AIConfigValidator) *SettingsService

NewSettingsService creates a new settings service.

func (*SettingsService) Get

func (s *SettingsService) Get() (*domain.AppSettings, error)

Get retrieves current application settings.

func (*SettingsService) GetDefaults

func (s *SettingsService) GetDefaults() domain.AppSettings

GetDefaults returns default settings.

func (*SettingsService) GetPipelineConfig

func (s *SettingsService) GetPipelineConfig() domain.PipelineConfig

GetPipelineConfig returns the post-processor pipeline configuration. Returns default configuration if nothing is configured.

func (*SettingsService) GetSchedulerConfig

func (s *SettingsService) GetSchedulerConfig() domain.SchedulerConfig

GetSchedulerConfig returns the scheduler configuration. Returns default configuration if nothing is configured.

func (*SettingsService) RequiresEmbedding

func (s *SettingsService) RequiresEmbedding() bool

RequiresEmbedding returns true if current mode needs embedding.

func (*SettingsService) RequiresLLM

func (s *SettingsService) RequiresLLM() bool

RequiresLLM returns true if current mode needs LLM.

func (*SettingsService) Save

func (s *SettingsService) Save(settings *domain.AppSettings) error

Save persists application settings.

func (*SettingsService) SetEmbeddingProvider

func (s *SettingsService) SetEmbeddingProvider(provider domain.AIProvider, model, apiKey string) error

SetEmbeddingProvider configures the embedding provider.

func (*SettingsService) SetLLMProvider

func (s *SettingsService) SetLLMProvider(provider domain.AIProvider, model, apiKey string) error

SetLLMProvider configures the LLM provider.

func (*SettingsService) SetSearchMode

func (s *SettingsService) SetSearchMode(mode domain.SearchMode) error

SetSearchMode updates the search mode.

func (*SettingsService) Validate

func (s *SettingsService) Validate() error

Validate checks if current settings are valid for the configured mode.

func (*SettingsService) ValidateEmbeddingConfig

func (s *SettingsService) ValidateEmbeddingConfig() error

ValidateEmbeddingConfig validates the current embedding configuration by pinging the provider.

func (*SettingsService) ValidateLLMConfig

func (s *SettingsService) ValidateLLMConfig() error

ValidateLLMConfig validates the current LLM configuration by pinging the provider.

type SourceService

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

SourceService manages source configurations.

func NewSourceService

func NewSourceService(
	sourceStore driven.SourceStore,
	syncStore driven.SyncStateStore,
	docStore driven.DocumentStore,
) *SourceService

NewSourceService creates a new source service.

func (*SourceService) Add

func (s *SourceService) Add(ctx context.Context, source domain.Source) error

Add creates a new source configuration.

func (*SourceService) Get

func (s *SourceService) Get(ctx context.Context, id string) (*domain.Source, error)

Get retrieves a source by ID.

func (*SourceService) List

func (s *SourceService) List(ctx context.Context) ([]domain.Source, error)

List returns all configured sources.

func (*SourceService) Remove

func (s *SourceService) Remove(ctx context.Context, id string) error

Remove deletes a source and its indexed data.

func (*SourceService) SetConnectorRegistry

func (s *SourceService) SetConnectorRegistry(registry driving.ConnectorRegistry)

SetConnectorRegistry sets the connector registry for config validation.

func (*SourceService) Update

func (s *SourceService) Update(ctx context.Context, source domain.Source) error

Update modifies an existing source configuration.

func (*SourceService) ValidateConfig

func (s *SourceService) ValidateConfig(_ context.Context, connectorType string, config map[string]string) error

ValidateConfig validates source configuration for a connector type.

type SyncOrchestrator

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

SyncOrchestrator coordinates document synchronisation.

func NewSyncOrchestrator

func NewSyncOrchestrator(
	sourceStore driven.SourceStore,
	syncStore driven.SyncStateStore,
	docStore driven.DocumentStore,
	exclusionStore driven.ExclusionStore,
	factory driven.ConnectorFactory,
	registry driven.NormaliserRegistry,
	pipeline driven.PostProcessorPipeline,
	searchIndex driven.SearchEngine,
	vectorIndex driven.VectorIndex,
	embeddingService driven.EmbeddingService,
) *SyncOrchestrator

NewSyncOrchestrator creates a new sync orchestrator. The searchIndex, vectorIndex and embeddingService are used when creating Indexers for sync. VectorIndex and embeddingService are optional - if nil, semantic indexing is disabled.

func (*SyncOrchestrator) Status

func (o *SyncOrchestrator) Status(_ context.Context, sourceID string) (*driving.SyncStatus, error)

Status returns sync status for a source.

func (*SyncOrchestrator) Sync

func (o *SyncOrchestrator) Sync(ctx context.Context, sourceID string) error

Sync triggers synchronisation for a source.

func (*SyncOrchestrator) SyncAll

func (o *SyncOrchestrator) SyncAll(ctx context.Context) error

SyncAll triggers synchronisation for all configured sources.

Jump to

Keyboard shortcuts

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