sync

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

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 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 WithOutputPath

func WithOutputPath(path string) Option

WithOutputPath configures the output path for saving.

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 configures whether all sources are required to succeed.

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 sources to use (empty means default providers/local/models.dev HTTP)
	ProviderID *catalogs.ProviderID // Filter for specific provider

	// Output control (used AFTER merging)
	OutputPath string // Where to save final catalog (empty means default location)

	// 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 all sources to succeed (fail if any dependencies are missing)

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

Options controls the overall sync orchestration in Starmap.Sync().

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.

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
	OutputDir string // Where files were written (empty means default)
	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
}

Result represents the complete result of a sync operation.

func ChangesetToResult

func ChangesetToResult(changeset *differ.Changeset, dryRun bool, outputDir 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, outputDir 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