MCPcopy
hub / github.com/anomalyco/models.dev / detectChanges

Function detectChanges

packages/core/script/generate-digitalocean.ts:554–584  ·  view source on GitHub ↗
(existing: ExistingModel | null, merged: MergedModel)

Source from the content-addressed store, hash-verified

552}
553
554function detectChanges(existing: ExistingModel | null, merged: MergedModel): Change[] {
555 if (!existing) return [];
556
557 const changes: Change[] = [];
558 const EPSILON = 0.001;
559
560 const compare = (field: string, oldVal: unknown, newVal: unknown) => {
561 if (oldVal === undefined && newVal === undefined) return;
562 const isDiff = field.startsWith("cost.")
563 ? Math.abs((oldVal as number ?? 0) - (newVal as number ?? 0)) > EPSILON
564 : JSON.stringify(oldVal) !== JSON.stringify(newVal);
565 if (isDiff) changes.push({ field, oldValue: formatValue(oldVal), newValue: formatValue(newVal) });
566 };
567
568 compare("name", existing.name, merged.name);
569 compare("reasoning", existing.reasoning, merged.reasoning);
570 compare("tool_call", existing.tool_call, merged.tool_call);
571 compare("attachment", existing.attachment, merged.attachment);
572 compare("status", existing.status, merged.status);
573 compare("cost.input", existing.cost?.input, merged.cost?.input);
574 compare("cost.output", existing.cost?.output, merged.cost?.output);
575 const existingLongContextCost = getExistingLongContextCost(existing);
576 compare("cost.context_over_200k.input", existingLongContextCost?.input, merged.cost?.context_over_200k?.input);
577 compare("cost.context_over_200k.output", existingLongContextCost?.output, merged.cost?.context_over_200k?.output);
578 compare("limit.context", existing.limit?.context, merged.limit.context);
579 compare("limit.output", existing.limit?.output, merged.limit.output);
580 compare("modalities.input", existing.modalities?.input, merged.modalities.input);
581 compare("modalities.output", existing.modalities?.output, merged.modalities.output);
582
583 return changes;
584}
585
586// ---------------------------------------------------------------------------
587// Main

Callers 1

mainFunction · 0.70

Calls 2

compareFunction · 0.70

Tested by

no test coverage detected