Commit d5015be
feat(gom-53): integrated external model registry for metadata enrichment and cost tracking + Dashboard/Usage page (#82)
* Integrate external model registry for metadata enrichment and cost tracking
Fetch, cache, and merge the ai-model-list registry (models.json) to enrich
discovered models with pricing, capabilities, and context limits. Models not
in the registry still work — the fetch is best-effort and never gates.
- Add ModelListConfig (URL + timeout) to CacheConfig with env var support
- Add ModelListData to ModelCache for raw JSON persistence across restarts
- Add ModelMetadata/ModelPricing to core.Model (omitempty, pointer numerics)
- New internal/modeldata package: fetcher, 3-layer merger, enricher
- Registry integration: enrich on Initialize, LoadFromCache, and refresh
- Background refresh re-fetches model list alongside provider models
- Add cost fields (InputCost/OutputCost/TotalCost) to UsageEntry
- CalculateCost + variadic pricing param on all three usage extractors
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Address code review: enable model list by default, harden fetcher and fix race
- Set MODEL_LIST_URL default to ENTERPILOT/ai-model-list so the external
model registry is enabled out of the box
- Document MODEL_LIST_URL and MODEL_LIST_TIMEOUT in .env.template
- Bound fetcher response body reads with io.LimitReader (10 MB cap)
- Fix data race in EnrichModels by holding write lock for the entire
enrichment instead of releasing it before SetMetadata mutations
- Use tolerance-based float comparison in merger tests (math.Abs + epsilon)
- Add doc comment to calculateCostHelper explaining intentional duplication
- Add TODO to convertPricing documenting unmapped PricingEntry fields
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Remove redundant dual timeout from modeldata.Fetch
Fetch was receiving both a context with a deadline and a separate timeout
duration used to set http.Client.Timeout, applying the same limit twice.
Remove the timeout parameter and rely solely on the caller-provided context
for cancellation, which http.NewRequestWithContext already propagates.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Remove MODEL_LIST_TIMEOUT config; hardcode 45s fetch timeout
A configurable timeout for downloading a small JSON metadata file adds
unnecessary complexity. Remove the Timeout field from ModelListConfig,
the MODEL_LIST_TIMEOUT env var, and simplify StartBackgroundRefresh and
refreshModelList signatures by dropping the timeout parameter.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Fix estimated cost calculation via reverse model ID lookup
The dashboard "Estimated Cost" was nearly zero because the usage DB
stores provider response model IDs (e.g., gpt-4o-2024-08-06) while
the registry keys come from ListModels (e.g., gpt-4o). Add a reverse
index built from provider_model_id fields in models.json so Resolve()
can map dated variants back to canonical keys, and add a
ResolveMetadata fallback in calculateCosts(). Also include the
provider column in GetUsageByModel queries and add dashboard UI for
cost display.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* feat: next features
* Migrate to new ai-model-list schema
Mode→Modes ([]string), ProviderModelID→CustomModelID, add new pricing
fields (cache_write, batch, audio per MTok + tiers), new model metadata
fields, and multi-category support throughout registry and dashboard.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* feat: calculating costs in the usage table/document based on the pricing list
* feat: enriched usage data
* feat: populate raw_data for non-streaming responses
Extended core.Usage and ResponsesUsage with typed PromptTokensDetails
and CompletionTokensDetails structs so json.Unmarshal captures OpenAI/xAI
nested usage fields. Added cache fields to Anthropic's anthropicUsage
and populate RawUsage in both convert functions. Added
buildRawUsageFromDetails helper in the extractor to merge typed fields
into RawData using the same key convention as the streaming path.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: resolve merge conflict and fix NewHandler test calls
Resolved merge conflict in admin handler (kept both swagger annotations
and category filter comment). Added missing pricingResolver arg to
NewHandler calls in handlers_test.go.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* refactor: remove dead code, unify pricing types, fix date filters
- Delete unused CalculateCost() and its duplicated test/helper
- Unify PricingEntry/PricingTier into core.ModelPricing directly,
eliminating convertPricing()/convertPricingTiers() mapping layer
- Add missing end-only date filter branch to SQLite/PostgreSQL/MongoDB
readers (GetSummary, GetUsageByModel, GetDailyUsage, GetUsageLog)
- Extract extendedFieldSet from providerMappings as single source of
truth, replacing hard-coded list in stream_wrapper.go
- Extract shared buildWhereClause() and clampLimitOffset() helpers
- Simplify buildReverseIndex with strings.IndexByte
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: eliminate false cost caveat warnings; replace donut chart with vertical bar
Remove false-positive "no pricing for X" and "unmapped token field" caveats
on reasoning models (o3-mini, o4-mini, grok-3-mini) where costs are actually
correct. Add xAI prefixed key mappings and informational fields allowlist.
Replace doughnut chart with vertical bar chart using earth-tone palette.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* refactor: extract date-picker into a Go template partial
Eliminates ~178 lines of duplicated date-picker markup between the
overview and usage pages by extracting it into a shared template.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* docs/test: add doc comments and pricing branch tests
Add doc comments to ModelListData (cache.go) and Metadata (types.go)
fields. Add extractor tests exercising the pricing cost calculation path
for both ChatResponse and ResponsesResponse.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: address review comments across pricing estimation feature
- Unquote Menlo/Consolas in CSS and JS chart font-family
- Fix fetchUsagePage to call fetchUsageLog(true)
- Add swagger annotations for admin API endpoints
- Add nil guard in enricher test for InputPerMtok
- Add TestFetch_OversizedBody for 10MB body limit
- Replace unbounded recursion in merger with inline lookup
- Add Capabilities override in merger
- Refactor types.go with strings.Cut
- Replace hardcoded category count with len(core.AllCategories())
- Add CategoryCount display name fallback
- Use shared HTTP client in fetcher with 60s timeout
- Fix init goroutine to use parent context
- Escape SQL LIKE wildcards to prevent injection
- Add slog.Warn for json.Unmarshal errors
- Add appliedFields pointer tracking to prevent cost double-counting
- Add Go doc comments on reader methods
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: log unavailable provider as WARN instead of INFO
Skipping a configured provider at startup is noteworthy—WARN better
signals that Ollama (or similar) was expected but unreachable.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: address code review findings across pricing estimation feature
- Fix TotalCost bug: use || instead of && so cost is set with one-sided pricing
- Add COALESCE wrappers for all aggregate and per-row cost/caveat SQL columns
- Fix slice aliasing bug in dataArgs construction (SQLite + PostgreSQL)
- Validate category query parameter, return 400 for invalid values
- Add aria-labels to date-picker navigation buttons
- Add timestamp parse failure warning in SQLite reader
- Add category-specific empty state message on models page
- Fix forEach lint: add block bodies for arrow functions
- Clarify registryAccessor and Init doc comments
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: fixed disappering chart on the usage page
* fix: make the usage/costs linkable and persistant place with page refresh
* fix: rename donut chart symbols to match actual bar chart type
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: for the ui
* fix: align overview chart colors with usage page bar chart palette
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent 4f6df74 commit d5015be
47 files changed
Lines changed: 6213 additions & 245 deletions
File tree
- cmd/gomodel/docs
- config
- internal
- admin
- dashboard
- static
- css
- js
- templates
- app
- cache
- core
- modeldata
- providers
- anthropic
- server
- usage
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
39 | 43 | | |
40 | 44 | | |
41 | 45 | | |
| |||
0 commit comments