embeddedSnapshot returns the catalog baked into the binary at build time. The JSON is parsed once and cached. A malformed snapshot yields an empty (non-nil) database rather than a panic, so a bad embed degrades to "provider not found" instead of crashing the process. The parse failure is logged beca
()
| 38 | // logged because, with the hardcoded context-limit fallback gone, a corrupt |
| 39 | // snapshot would otherwise silently clamp large-context models with no signal. |
| 40 | func embeddedSnapshot() *Database { |
| 41 | snapshotOnce.Do(func() { |
| 42 | var providers map[string]Provider |
| 43 | if err := json.Unmarshal(snapshotJSON, &providers); err != nil { |
| 44 | slog.Warn("embedded models.dev snapshot is malformed; context-window limits will be wrong", "error", err) |
| 45 | snapshotDB = &Database{} |
| 46 | return |
| 47 | } |
| 48 | snapshotDB = &Database{Providers: providers} |
| 49 | }) |
| 50 | return snapshotDB |
| 51 | } |
| 52 | |
| 53 | // SnapshotDate returns the time the embedded models.dev snapshot was |
| 54 | // generated. The zero value is returned when the recorded date can't be |