MCPcopy
hub / github.com/marimo-team/marimo / syncModels

Function syncModels

packages/llm-info/src/sync-models.ts:239–275  ·  view source on GitHub ↗
(options: SyncOptions)

Source from the content-addressed store, hash-verified

237}
238
239export async function syncModels(options: SyncOptions): Promise<SyncResult> {
240 const {
241 modelsYamlPath,
242 write = true,
243 mode = "append",
244 maxPerProvider,
245 providers,
246 } = options;
247 const modelsDev = options.modelsDev ?? (await fetchModelsDev());
248
249 // `replace` mode pretends the file is empty so everything is treated as new.
250 const existingText =
251 mode === "replace" ? "" : readFileSync(modelsYamlPath, "utf-8");
252 const existing = parseExistingModels(existingText);
253 const summary = mergeModels(existing, modelsDev, {
254 maxPerProvider,
255 providers,
256 });
257
258 const addedCount = countEntries(summary.newEntries);
259 const isFresh = mode === "replace" || existingText.trim() === "";
260 const yaml = isFresh
261 ? renderFresh(summary.newEntries)
262 : addedCount > 0
263 ? insertIntoDocument(existingText, summary.newEntries)
264 : existingText;
265
266 if (write && (addedCount > 0 || mode === "replace")) {
267 writeFileSync(modelsYamlPath, yaml);
268 }
269
270 return {
271 added: addedCount,
272 preserved: summary.preservedCount,
273 yaml,
274 };
275}
276
277async function main(): Promise<void> {
278 try {

Callers 2

mainFunction · 0.85

Calls 6

fetchModelsDevFunction · 0.90
mergeModelsFunction · 0.90
parseExistingModelsFunction · 0.85
countEntriesFunction · 0.85
renderFreshFunction · 0.85
insertIntoDocumentFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…