heartcode 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/usage.js CHANGED
@@ -88,6 +88,20 @@ function indexOf(t) {
88
88
  return index
89
89
  }
90
90
 
91
+ // A "…-latest" name models.dev doesn't list: the newest dated version it does list
92
+ // (magistral-small-latest → magistral-small-2509), its entries at every provider. [] if none.
93
+ function newestOf(name) {
94
+ const base = /^(.+?)[-_.:]?latest$/i.exec(name)?.[1]
95
+ if (!base) return []
96
+ const re = new RegExp(`^[a-z]{0,12}${norm(base)}(\\d{4,8})$`) // a date or version after the name: 2509, 20250929; a vendor before it (mistral.magistral-small-2509)
97
+ let best = null
98
+ for (const [k, list] of indexOf(table)) {
99
+ const d = re.exec(k)?.[1]
100
+ if (d && (!best || Number(d) > Number(best.d))) best = { d, list }
101
+ }
102
+ return best ? [...best.list].sort((a, b) => a.n - b.n) : []
103
+ }
104
+
91
105
  // What models.dev says of a model: { context, output (tokens), tools, thinking, images }, or null. Found by its name
92
106
  // however it's written (google/gemini-2.5-flash, models/gemini-2.5-flash, gpt-oss:120b ≈
93
107
  // gpt-oss-120b): at this provider first; else, among all that list it, the size most say (a
@@ -98,7 +112,8 @@ export function limitsOf(provider, baseUrl, model) {
98
112
  const want = new Set([model, model.replace(/^models\//, ''), last(model), last(model).replace(/:(free|beta|extended|nitro|floor|online|cloud)$/, '').replace(/-cloud$/, '')].map(norm))
99
113
  const own = ownBy(provider, baseUrl)
100
114
  const found = { own: [], all: [] }
101
- const hits = [...new Set([...want].flatMap((w) => indexOf(table).get(w) ?? []))].sort((a, b) => a.n - b.n)
115
+ let hits = [...new Set([...want].flatMap((w) => indexOf(table).get(w) ?? []))].sort((a, b) => a.n - b.n)
116
+ if (!hits.length) hits = newestOf(last(model)) // "magistral-small-latest" by its dated names only
102
117
  for (const { entry, info } of hits) {
103
118
  const it = { ...info.limit, ...(info.can ?? { tools: true, thinking: false, images: false }) }
104
119
  found.all.push(it)