sync

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package sync provides options and utilities for synchronizing the catalog with provider APIs.

Index

Constants

View Source
const (
	// ProjectionStatusApplied reports that the workspace projection was written.
	ProjectionStatusApplied = projection.StatusApplied
	// ProjectionStatusPendingRepair reports that publication succeeded but the
	// workspace projection needs repair.
	ProjectionStatusPendingRepair = projection.StatusPendingRepair
	// ProjectionIssueWorkspaceFailed identifies a workspace projection failure.
	ProjectionIssueWorkspaceFailed = projection.IssueWorkspaceFailed
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DependencyDecision added in v0.1.0

type DependencyDecision uint8

DependencyDecision describes how an interactive adapter wants to handle one missing source dependency.

const (
	// DependencyDecisionInstall requests automatic installation.
	DependencyDecisionInstall DependencyDecision = iota + 1
	// DependencyDecisionSkip requests skipping the source.
	DependencyDecisionSkip
	// DependencyDecisionCancel cancels synchronization.
	DependencyDecisionCancel
)

type DependencyDecisionHandler added in v0.1.0

type DependencyDecisionHandler func(context.Context, sources.ID, sources.Dependency, bool) (DependencyDecision, error)

DependencyDecisionHandler lets an interactive adapter decide how to handle a missing dependency. Core synchronization never installs a terminal reader or prompts on its own.

type Option

type Option func(*Options)

Option is a function that configures sync Options.

func WithAutoInstallDeps added in v0.0.17

func WithAutoInstallDeps(autoInstall bool) Option

WithAutoInstallDeps configures whether to automatically install missing dependencies.

func WithCatalogPath added in v0.2.0

func WithCatalogPath(path string) Option

WithCatalogPath configures the single human workspace used for local observation and post-commit materialization.

func WithCleanModelsDevRepo

func WithCleanModelsDevRepo(cleanup bool) Option

WithCleanModelsDevRepo configures whether to remove temporary models.dev repository after update.

func WithDependencyDecisionHandler added in v0.1.0

func WithDependencyDecisionHandler(handler DependencyDecisionHandler) Option

WithDependencyDecisionHandler configures the interactive dependency decision adapter. Noninteractive callers should leave it unset.

func WithDryRun

func WithDryRun(dryRun bool) Option

WithDryRun configures dry run mode.

func WithFresh

func WithFresh(fresh bool) Option

WithFresh configures whether to delete existing models and fetch fresh from APIs.

func WithModelsDevGitCommit added in v0.1.0

func WithModelsDevGitCommit(commit string) Option

WithModelsDevGitCommit pins explicit models.dev Git verification to one commit.

func WithProvider

func WithProvider(providerID catalogs.ProviderID) Option

WithProvider configures syncing for a specific provider only.

func WithReformat

func WithReformat(reformat bool) Option

WithReformat configures whether to reformat providers.yaml file even without changes.

func WithRequireAllSources added in v0.0.17

func WithRequireAllSources(require bool) Option

WithRequireAllSources requires every configured source to be available and return a complete, successful observation containing at least one model.

func WithSkipDepPrompts added in v0.0.17

func WithSkipDepPrompts(skip bool) Option

WithSkipDepPrompts skips optional sources with missing dependencies without consulting a configured DependencyDecisionHandler.

func WithSources

func WithSources(types ...sources.ID) Option

WithSources configures which sources to use.

func WithSourcesDir

func WithSourcesDir(dir string) Option

WithSourcesDir configures the directory for external source data (models.dev cache/git).

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout configures the sync timeout.

type Options

type Options struct {
	// Orchestration control
	DryRun  bool          // Show changes without applying them
	Timeout time.Duration // Timeout for the entire sync operation

	// Source selection
	Sources    []sources.ID         // Which external/human sources to use; verified embedded always participates.
	ProviderID *catalogs.ProviderID // Filter for specific provider

	// Human workspace used for both local observation and materialization.
	CatalogPath string

	// Source behavior control
	Fresh              bool   // Delete existing models and fetch fresh from APIs (destructive)
	CleanModelsDevRepo bool   // Remove temporary models.dev repository after update
	Reformat           bool   // Reformat providers.yaml file even without changes
	SourcesDir         string // Directory for external source data (models.dev cache/git)
	ModelsDevGitCommit string // Exact models.dev commit required by Git verification

	// Dependency control
	AutoInstallDeps   bool // Automatically install missing dependencies without prompting
	SkipDepPrompts    bool // Skip dependency prompts and continue without optional dependencies
	RequireAllSources bool // Require every configured source to return a complete, successful, nonempty observation

	// DependencyDecisionHandler is supplied by an interactive adapter. It is nil
	// for library, server, scheduler, and other noninteractive callers.
	DependencyDecisionHandler DependencyDecisionHandler
}

Options controls one explicit acquisition.Syncer.Sync operation.

func Defaults

func Defaults() *Options

Defaults returns the default sync options.

func (*Options) Apply

func (s *Options) Apply(opts ...Option) *Options

Apply applies the given options to the sync options.

func (*Options) SourceOptions

func (s *Options) SourceOptions() []sources.Option

SourceOptions converts sync options to properly typed source options.

func (*Options) Validate

func (s *Options) Validate(providers catalogs.ProvidersReader) error

Validate checks if the sync options are valid.

func (*Options) ValidateFilesystemLayout added in v0.2.0

func (s *Options) ValidateFilesystemLayout() error

ValidateFilesystemLayout rejects machine-owned source/cache roots that overlap the configured human provider-YAML workspace. It is safe to call before reading the workspace or creating any source state.

type ProjectionResult added in v0.2.0

type ProjectionResult = projection.Result

ProjectionResult is the optional post-commit workspace projection result.

type ProjectionStatus added in v0.2.0

type ProjectionStatus = projection.Status

ProjectionStatus is the synchronization spelling of the shared projection lifecycle type.

type ProviderResult

type ProviderResult struct {
	ProviderID catalogs.ProviderID  // The provider that was synced
	Added      []catalogs.Model     // New models not in catalog
	Updated    []differ.ModelUpdate // Existing models with changes
	Removed    []catalogs.Model     // Models in catalog but not in API (informational only)

	// Summary counts
	AddedCount   int // Number of models added
	UpdatedCount int // Number of models updated
	RemovedCount int // Number of models removed from API (not deleted from catalog)

	// Metadata
	APIModelsCount      int // Total models fetched from API
	ExistingModelsCount int // Total models that existed in catalog
	EnhancedCount       int // Number of models enhanced with models.dev data
}

ProviderResult represents sync results for a single provider.

func (*ProviderResult) HasChanges

func (spr *ProviderResult) HasChanges() bool

HasChanges returns true if the provider result contains any changes.

func (*ProviderResult) Summary

func (spr *ProviderResult) Summary() string

Summary returns a human-readable summary of the provider result.

type Result

type Result struct {
	// Overall statistics
	TotalChanges     int                                     // Total number of changes across all providers
	ProvidersChanged int                                     // Number of providers with changes
	ProviderResults  map[catalogs.ProviderID]*ProviderResult // Results per provider

	// Operation metadata
	DryRun      bool   // Whether this was a dry run
	Fresh       bool   // Whether this was a fresh sync
	CatalogPath string // Human workspace used by the synchronization
	Sources     []sources.ID
	// SourceObservations contains caller-owned freshness/audit projections from
	// every source used by this attempt, including no-change synchronizations.
	SourceObservations []catalogs.SourceObservationLink
	GenerationID       string // Durable generation activated by a non-dry sync
	SyncRunID          string // Correlation ID for the synchronization attempt
	Projection         *ProjectionResult
	// ReviewCandidates contains deterministic non-fatal records excluded
	// from the published canonical catalog after source authority resolution.
	ReviewCandidates []evidence.ReviewCandidate
}

Result represents the complete result of a sync operation.

func ChangesetToResult

func ChangesetToResult(changeset *differ.Changeset, dryRun bool, catalogPath string, providerAPICounts map[catalogs.ProviderID]int, modelProviderMap map[string]catalogs.ProviderID, activeSources ...sources.ID) *Result

ChangesetToResult converts a reconcile.Changeset to a SyncResult.

func ChangesetToResultWithProvenance added in v0.1.0

func ChangesetToResultWithProvenance(changeset *differ.Changeset, dryRun bool, catalogPath string, providerAPICounts map[catalogs.ProviderID]int, modelProviderMap map[string]catalogs.ProviderID, fieldProvenance provenance.Map, activeSources ...sources.ID) *Result

ChangesetToResultWithProvenance converts a reconcile.Changeset to a SyncResult and uses field-level provenance to report models.dev enrichment counts.

func (*Result) HasChanges

func (sr *Result) HasChanges() bool

HasChanges returns true if the sync result contains any changes.

func (*Result) Summary

func (sr *Result) Summary() string

Summary returns a human-readable summary of the sync result.

Jump to

Keyboard shortcuts

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