MCPcopy Index your code
hub / github.com/docker/docker-agent / NewStore

Function NewStore

pkg/modelsdev/store.go:109–137  ·  view source on GitHub ↗

NewStore creates a new Store backed by an on-disk cache. By default the cache lives at ~/.cagent/models_dev.json; use WithCache to override the location. Callers should create one Store and share it rather than calling NewStore repeatedly. RuntimeConfig.ModelsDevStore() is the standard way to obtain

(opts ...Opt)

Source from the content-addressed store, hash-verified

107// repeatedly. RuntimeConfig.ModelsDevStore() is the standard way to obtain
108// a shared instance.
109func NewStore(opts ...Opt) (*Store, error) {
110 var options storeOptions
111 for _, opt := range opts {
112 opt(&options)
113 }
114
115 cacheFile := options.cacheFile
116 if cacheFile == "" {
117 homeDir, err := os.UserHomeDir()
118 if err != nil {
119 return nil, fmt.Errorf("failed to get user home directory: %w", err)
120 }
121 cacheFile = filepath.Join(homeDir, ".cagent", CacheFileName)
122 }
123
124 if err := os.MkdirAll(filepath.Dir(cacheFile), 0o700); err != nil {
125 return nil, fmt.Errorf("failed to create cache directory: %w", err)
126 }
127
128 fetch := options.fetch
129 if fetch == nil {
130 fetch = fetchFromAPI
131 }
132 return &Store{
133 cacheFile: cacheFile,
134 knownProvider: options.knownProvider,
135 fetch: fetch,
136 }, nil
137}
138
139// NewDatabaseStore creates a Store pre-populated with the given database.
140// The returned store serves data entirely from memory and never fetches

Calls 1

DirMethod · 0.80