@gtrabanco/pi-nan-provider 1.5.8 → 1.6.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/AGENTS.md +61 -3
- package/README.es.md +61 -3
- package/README.md +57 -3
- package/package.json +3 -3
- package/scripts/generate-models.ts +17 -0
- package/scripts/model-facts.ts +247 -0
- package/scripts/models.generated.ts +8 -8
- package/src/index.ts +26 -0
- package/src/model-facts-core.ts +424 -0
- package/src/model-facts.ts +98 -0
package/AGENTS.md
CHANGED
|
@@ -317,6 +317,28 @@ Since 1.0.0 the package version **aligns its MAJOR.MINOR with the pi release lin
|
|
|
317
317
|
A model with a confirmed per-token price can still override `cost` through
|
|
318
318
|
`MANUAL_OVERRIDES`; to adopt models.dev's numbers everywhere, delete the constant.
|
|
319
319
|
Regression test: `test/larger-models-2026-11-17.test.ts`.
|
|
320
|
+
- **`NAN_MODEL_FACTS` is the public facts surface (issue #47, package 1.6.1).**
|
|
321
|
+
`src/model-facts.ts` exports the deep-frozen record keyed by chat model id plus
|
|
322
|
+
`NAN_ENDPOINT_FACTS` and `NAN_MODEL_FACTS_META`; `src/model-facts-core.ts` owns
|
|
323
|
+
the value unions, the `NAN_FACT_SOURCES` citation table, the builder guards and
|
|
324
|
+
the freezer (deliberately free of catalog imports so the generator can validate
|
|
325
|
+
the entries it just built before writing them); the manual values live in
|
|
326
|
+
`scripts/model-facts.ts`, next to the override path they belong to. The
|
|
327
|
+
generator fails when a catalog id has no declaration, a declaration names a
|
|
328
|
+
ghost id, a value falls outside its documented union, or a cell carries no
|
|
329
|
+
provenance id — an unsourced cell can never reach a published catalog. Carried
|
|
330
|
+
cells (limits, cost, modalities, reasoning list/map, compat) are read from the
|
|
331
|
+
generated catalog entry; the eight new cells come from the manual layer with a
|
|
332
|
+
per-cell source id. Two rules the data encodes: `"unmeasured"` is never
|
|
333
|
+
"false" (nothing was measured — `parallelToolCalls` is unmeasured on every
|
|
334
|
+
model, `structuredOutput` is a boolean only where the docs name
|
|
335
|
+
`json_object`/`json_schema`), and the cold-prompt ceiling is endpoint-wide, so
|
|
336
|
+
every `coldCeilingTokens` cell is `"unmeasured"` while the 200,000-token
|
|
337
|
+
measurement ships as `NAN_ENDPOINT_FACTS.coldCacheCeilingTokens` (measured
|
|
338
|
+
2026-10-01, scope "not a model capability"). Importing the record performs no
|
|
339
|
+
network read and never feeds provider registration: the #19 read-time overlay
|
|
340
|
+
stays the only thing that shapes the models a session sees.
|
|
341
|
+
Regression test: `test/issue-47-model-facts.test.ts`.
|
|
320
342
|
- A NaN request that still exceeds the destination model's context window (the
|
|
321
343
|
cross-model thinking guard is disabled with `NAN_THINKING_GUARD=0`, the
|
|
322
344
|
inflation is not a `thinking` block, or the window is smaller) gets NaN's
|
|
@@ -416,8 +438,44 @@ Since 1.0.0 the package version **aligns its MAJOR.MINOR with the pi release lin
|
|
|
416
438
|
`src/reasoning-only-stream-guard.ts` (issue #21) keys on that marker;
|
|
417
439
|
earlier comment/message text said "60,000 characters" and was corrected to
|
|
418
440
|
the documented figures.
|
|
419
|
-
- **pi 1.
|
|
420
|
-
baseline
|
|
441
|
+
- **pi 1.6.0 / pi-ai 1.6.0 compat** (verified 2026-11-21, the current verified
|
|
442
|
+
baseline; devDependencies 1.5.1 → 1.6.0, package 1.5.8 → 1.6.0, peer range
|
|
443
|
+
unchanged at `^1.4.0` because nothing here needs 1.6.0). **No `src/` change:** pi-ai
|
|
444
|
+
`dist/index.d.ts`, `dist/compat.d.ts`, `dist/api/openai-completions.d.ts` and
|
|
445
|
+
pi-coding-agent `dist/index.d.ts` are byte-identical to 1.5.1, and a base-vs-change
|
|
446
|
+
capture of every catalog model × `off`/`low`/`max` (tool history + thinking blocks
|
|
447
|
+
included) is byte-identical on the wire. What DID move, and why it does or does not
|
|
448
|
+
touch this package:
|
|
449
|
+
- `detectCompat()` now defaults `supportsDeveloperRole` to **true only for
|
|
450
|
+
api.openai.com** (#10741), sending `system` everywhere else. The generated catalog
|
|
451
|
+
pins `supportsDeveloperRole: false` per entry, so NaN's wire never moved — pinned by
|
|
452
|
+
`test/pi-ai-1-6-0-contract.test.ts`.
|
|
453
|
+
- `parseChunkUsage` falls back to a **top-level `usage.reasoning_tokens`** when
|
|
454
|
+
`completion_tokens_details.reasoning_tokens` is absent (0 on 1.5.1). NaN reports the
|
|
455
|
+
nested field, so this is tolerance only.
|
|
456
|
+
- `RETRYABLE_PROVIDER_ERROR_PATTERN` gains `connection.?closed`, bare
|
|
457
|
+
`ECONNRESET|ECONNABORTED|ECONNREFUSED|ETIMEDOUT|EPIPE` (lookaround-guarded),
|
|
458
|
+
`connection reset by peer` and the Codex websocket lifetime text (#12064, #12128,
|
|
459
|
+
#12124). Directly relevant to NaN's LiteLLM gateway, which closes SSE streams
|
|
460
|
+
mid-turn (issue #2): those drops are now retried with no package change. The
|
|
461
|
+
deterministic NaN 400 stays non-retryable.
|
|
462
|
+
- `constrained-sampling.js` rejects schema nodes without `type` in strict mode
|
|
463
|
+
(#12049). Unreachable for NaN: `openai-completions` keeps
|
|
464
|
+
`supportsStrictMode: false` in `detectCompat()`, so no `strict` field is ever sent
|
|
465
|
+
(pinned by the same contract test). The `supportsStrictMode` compat key itself is
|
|
466
|
+
documented and added to the Mistral schema only.
|
|
467
|
+
- pi-coding-agent: the **breaking** change (extension components `render()` returning
|
|
468
|
+
`readonly string[]`) does not apply — this package registers no TUI components;
|
|
469
|
+
`core/model-resolver.d.ts` drops `resolveModelScope` / `restoreModelFromSession`
|
|
470
|
+
(never imported); `ExtensionRuntime.reportError` is additive. Upstream fixes that
|
|
471
|
+
help NaN users: MCP `tool_search` tools survive resume/`/reload`, and
|
|
472
|
+
`AgentSession.reload()` emits `session_start` again under
|
|
473
|
+
`bindExtensions({})`, so the media MCP server reconnects.
|
|
474
|
+
- `env-api-keys.js` gains the Qwen Token Plan per-plan variables; `PI_AI_VERSION` is
|
|
475
|
+
`1.6.0`. Neither is used by this package.
|
|
476
|
+
Regression test: `test/pi-ai-1-6-0-contract.test.ts` (RED on 1.5.1 for the flat
|
|
477
|
+
reasoning-token and retry-coverage groups, green on 1.6.0). Issue #45.
|
|
478
|
+
- **pi 1.4.0 / pi-ai 1.4.0 compat** (verified 2026-10-24): devDependencies bumped 1.3.0 → 1.4.0; **the peer range floor rose to
|
|
421
479
|
`"^1.3.0"`** and the version-gated cross-model thinking guard plus
|
|
422
480
|
`src/pi-ai-version.ts` were REMOVED as scheduled (pi-ai >= 1.3.0 drops
|
|
423
481
|
cross-model thinking itself). The pi-ai 1.4.0 type surface only ADDS exports
|
|
@@ -587,7 +645,7 @@ uno cite una versión o requisito que el otro no lleve.
|
|
|
587
645
|
5. **Cita el peer floor real, no la historia.** El peer range se actualiza con cada
|
|
588
646
|
release de pi: lee `package.json` peerDependencies, no AGENTS.md (que documenta
|
|
589
647
|
releases históricos y puede quedar obsoleto). Para este paquete: el floor es
|
|
590
|
-
`^1.4.0` (desde package 1.5.0), verificado contra pi 1.
|
|
648
|
+
`^1.4.0` (desde package 1.5.0), verificado contra pi 1.6.0 / pi-ai 1.6.0.
|
|
591
649
|
6. **Las cifras de catálogo van contra `scripts/models.generated.ts`, no contra AGENTS.md.**
|
|
592
650
|
AGENTS.md es documentación de releases y puede contener floor o ranges ya antiguos;
|
|
593
651
|
el catálogo generado es la fuente viva de `contextWindow`/`maxTokens`/`reasoningEffortValues`
|
package/README.es.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @gtrabanco/𝜋-nan-provider
|
|
2
2
|
|
|
3
3
|
[](https://opensource.org/licenses/MIT)
|
|
4
|
-
[](https://github.com/gtrabanco/pi-nan-provider/releases)
|
|
5
5
|
[](https://cloud.nan.builders/r/7GK06FX8)
|
|
6
6
|
|
|
7
7
|
[NaN Builders](https://cloud.nan.builders/r/7GK06FX8) model provider + MCP nativo para [pi](https://github.com/earendil-works/pi).
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
Registra el proveedor `nan` vía `pi.registerProvider()` usando la API OpenAI-compatible de NaN (`https://api.nan.builders/v1`), y registra el servidor MCP de media de la comunidad con `pi.registerMcpServer()`.
|
|
10
10
|
|
|
11
11
|
> [!NOTE]
|
|
12
|
-
> **Requisitos:** pi **≥ 1.4.0** (rango peer `^1.4.0`). El paquete está verificado contra **pi 1.
|
|
12
|
+
> **Requisitos:** pi **≥ 1.4.0** (rango peer `^1.4.0`). El paquete está verificado contra **pi 1.6.0 / pi-ai 1.6.0**; el floor del rango peer solo sube con los re-aligns de menor de pi.
|
|
13
13
|
|
|
14
14
|
## ✨ Funciones
|
|
15
15
|
|
|
@@ -23,6 +23,7 @@ Registra el proveedor `nan` vía `pi.registerProvider()` usando la API OpenAI-co
|
|
|
23
23
|
| **Reintento de streams truncados** | `supportsFinishReason: true` convierte un stream SSE cerrado antes de `finish_reason` en un error reintentable en vez de un stall silencioso ([#2](https://github.com/gtrabanco/pi-nan-provider/issues/2)). |
|
|
24
24
|
| **Uso de tokens en streaming** | `stream_options.include_usage` activo por defecto, así que pi reporta recuentos reales de entrada/salida/razonamiento/caché ([#4](https://github.com/gtrabanco/pi-nan-provider/issues/4), [#7](https://github.com/gtrabanco/pi-nan-provider/issues/7)). |
|
|
25
25
|
| **Controles de razonamiento** | `reasoningEffortValues` + `thinkingLevelMap` por modelo ([#16](https://github.com/gtrabanco/pi-nan-provider/issues/16)), el guard de stream solo-razonamiento ([#21](https://github.com/gtrabanco/pi-nan-provider/issues/21)) y el campo de tokens máximo por modelo (`qwen3.8-max` mantiene `max_completion_tokens`; `qwen3.8-flash` volvió a `max_tokens` tras el arreglo del gateway de NaN, [#34](https://github.com/gtrabanco/pi-nan-provider/issues/34) → [#36](https://github.com/gtrabanco/pi-nan-provider/issues/36)). |
|
|
26
|
+
| **Export de model facts** | `NAN_MODEL_FACTS` — una entrada congelada y tipada por modelo de chat facturado: límites, tarifas, contrato de razonamiento, protocolo de herramientas, semántica de `max_tokens`, presupuesto de pensamiento, modo de caché y clase de facturación, con un id de procedencia en cada celda ([#47](https://github.com/gtrabanco/pi-nan-provider/issues/47)). |
|
|
26
27
|
| **Cabecera de atribución** | `X-Pi-Provider: gtrabanco/pi-nan-provider@<version>` en cada petición, eliminada cuando la telemetría de instalación de pi está desactivada. |
|
|
27
28
|
| **Modelos de imagen nativos** | `flux-2-klein` y `qwen-image-2.1` registrados como modelos de pi `type: "image"`, accesibles desde codemode y extensiones. |
|
|
28
29
|
| **Puente MCP nativo de media** | El servidor `nan-media` (10 herramientas) registrado con `pi.registerMcpServer()`, gestionado con `/nan-mcp`. |
|
|
@@ -120,7 +121,7 @@ Puedes sobrescribir el `compat` de cualquier modelo en `~/.pi/agent/models.json`
|
|
|
120
121
|
|
|
121
122
|
> Poner `supportsFinishReason: false` restaura el antiguo stall silencioso — no recomendado.
|
|
122
123
|
|
|
123
|
-
**Escape hatches de compatibilidad de pi-ai 1.5.1
|
|
124
|
+
**Escape hatches de compatibilidad de pi-ai 1.5.1+** (`~/.pi/agent/models.json`, por modelo, sin cambios en 1.6.0): `compat.requiresToolsWithToolHistory: true` restaura el envío de `tools: []` en conversaciones con historial de tools (pi-ai 1.5.1 lo omite por defecto, arreglando los rechazos `tools must not be an empty array` de vLLM 0.20+ detrás de LiteLLM); `compat.requiresNonNullAssistantContent: true` envía `""` en vez de `null` en mensajes de asistente que solo llevan tool calls; `compat.promptCacheKeyMode: "disabled"` garantiza que nunca se envíe `prompt_cache_key` al gateway (el valor por defecto `auto` ya nunca lo activa para NaN).
|
|
124
125
|
|
|
125
126
|
**Uso de tokens en streaming:** `supportsUsageInStreaming` es `true` por defecto. El esquema publicado de NaN no documenta `stream_options`, pero el gateway real lo acepta y lo aplica — medido el 2026-09-16 ([#7](https://github.com/gtrabanco/pi-nan-provider/issues/7)): dos llamadas de streaming idénticas por modelo, 0 chunks de usage sin el flag y exactamente 1 con él, en `deepseek-v4-flash`, `glm5.3-flash`, `qwen3.6`, `gemma4` y `mimo-v2.5` (ya eliminado). Por eso pi muestra tokens reales de entrada/salida/reasoning/caché en lugar de ceros. Si un modelo resulta no devolver el usage en streaming, desactívalo por modelo — el sanitizer entonces elimina `stream_options` y el payload vuelve a ser estricto:
|
|
126
127
|
|
|
@@ -457,6 +458,63 @@ redactado y reproducible para NaN:
|
|
|
457
458
|
([#44](https://github.com/gtrabanco/pi-nan-provider/issues/44)), solo con
|
|
458
459
|
`cwd` hasheado. Entradas idénticas producen bytes de zip idénticos.
|
|
459
460
|
|
|
461
|
+
## 🧭 Model facts: `NAN_MODEL_FACTS`
|
|
462
|
+
|
|
463
|
+
Casi todo lo que este paquete sabe de la flota vivía en este README y en
|
|
464
|
+
comentarios del código. El issue [#47](https://github.com/gtrabanco/pi-nan-provider/issues/47)
|
|
465
|
+
lo convierte en datos: un registro congelado y tipado, exportado desde el punto
|
|
466
|
+
de entrada, para que tus scripts planifiquen contexto, caché y gasto sin leer
|
|
467
|
+
prosa ni entrar en `scripts/`.
|
|
468
|
+
|
|
469
|
+
```ts
|
|
470
|
+
import { NAN_MODEL_FACTS, NAN_ENDPOINT_FACTS, NAN_MODEL_FACTS_META } from "@gtrabanco/pi-nan-provider";
|
|
471
|
+
|
|
472
|
+
const facts = NAN_MODEL_FACTS["deepseek-v4-flash"];
|
|
473
|
+
facts.contextWindow; // 1048576
|
|
474
|
+
facts.maxTokens; // 32768
|
|
475
|
+
facts.cost; // { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }
|
|
476
|
+
facts.input; // ["text", "image"]
|
|
477
|
+
facts.toolCalling; // "openai-tools" | "xml"
|
|
478
|
+
facts.maxTokensSemantics; // "bounds-total" | "bounds-visible-answer"
|
|
479
|
+
facts.thinkingBudget; // "honoured" | "ignored" | "unmeasured"
|
|
480
|
+
facts.cacheMode; // "automatic" | "opt-in" | "unsupported" | "unmeasured"
|
|
481
|
+
facts.billingClass; // "quota-only" | "credit-standard" | "credit-larger"
|
|
482
|
+
facts.parallelToolCalls; // boolean | "unmeasured"
|
|
483
|
+
facts.structuredOutput; // boolean | "unmeasured"
|
|
484
|
+
|
|
485
|
+
facts.provenance.toolCalling; // "docs"
|
|
486
|
+
NAN_MODEL_FACTS_META.sources["docs"]; // URL + fecha de comprobación
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
- **Hechos, no política.** El registro dice qué *es* un modelo. Cómo lo uses —
|
|
490
|
+
fases por contexto, una escalera de enrutado, una estrategia de caché — sigue
|
|
491
|
+
siendo tuyo.
|
|
492
|
+
- **Una entrada por modelo de chat facturado** (13 hoy), con el id de modelo como
|
|
493
|
+
clave. Los endpoints que no son de chat (embedding, rerank, TTS, STT, imagen,
|
|
494
|
+
vídeo) no son modelos de chat y no se exportan.
|
|
495
|
+
- **Procedencia por celda.** Cada celda nombra un id de fuente;
|
|
496
|
+
`NAN_MODEL_FACTS_META.sources` lo resuelve a una URL con su fecha de
|
|
497
|
+
comprobación o a una medición fechada registrada en este repo. Los ids
|
|
498
|
+
`override`, `compat` y `catalog-cost` apuntan a las `notes` de la propia
|
|
499
|
+
entrada, que ya llevan esas citas.
|
|
500
|
+
- **`"unmeasured"` significa que no se afirma nada**, nunca "falso".
|
|
501
|
+
`parallelToolCalls` es `"unmeasured"` en todos los modelos porque nada
|
|
502
|
+
documenta ni mide varias llamadas de herramienta por turno; `structuredOutput`
|
|
503
|
+
es booleano solo donde los docs de NaN documentan `json_object` /
|
|
504
|
+
`json_schema` para ese modelo.
|
|
505
|
+
- **Techo de prompt frío.** `coldCeilingTokens` es `"unmeasured"` en todas las
|
|
506
|
+
entradas: la única medición es de extremo a extremo, así que viaja aparte como
|
|
507
|
+
`NAN_ENDPOINT_FACTS.coldCacheCeilingTokens` (200.000 tokens, medido el
|
|
508
|
+
2026-10-01) con un `coldCeilingScope` que aclara que es el límite de lectura
|
|
509
|
+
del proxy de Cloudflare (120 s), no una capacidad del modelo. Dimensiona la
|
|
510
|
+
primera petición en frío por debajo de ese valor.
|
|
511
|
+
- **Offline y congelado.** El registro se deriva del catálogo generado que se
|
|
512
|
+
publica más la capa de hechos de build, así que leerlo no hace ninguna llamada
|
|
513
|
+
de red, y está congelado en profundidad: un consumidor no puede cambiar lo que
|
|
514
|
+
lee el siguiente. Nunca alimenta el registro del proveedor — el overlay de
|
|
515
|
+
lectura ([#19](https://github.com/gtrabanco/pi-nan-provider/issues/19)) sigue
|
|
516
|
+
decidiendo los modelos que ve una sesión.
|
|
517
|
+
|
|
460
518
|
## 📊 Modelos
|
|
461
519
|
|
|
462
520
|
Catálogo base (verificado contra [docs de NaN](https://nan.builders/docs/models) y [OpenAPI](https://nan.builders/openapi.json)).
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @gtrabanco/𝜋-nan-provider
|
|
2
2
|
|
|
3
3
|
[](https://opensource.org/licenses/MIT)
|
|
4
|
-
[](https://github.com/gtrabanco/pi-nan-provider/releases)
|
|
5
5
|
[](https://cloud.nan.builders/r/7GK06FX8)
|
|
6
6
|
|
|
7
7
|
[NaN Builders](https://cloud.nan.builders/r/7GK06FX8) model provider + a native MCP server for [pi](https://github.com/earendil-works/pi).
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
Registers the `nan` provider via `pi.registerProvider()` using NaN's OpenAI-compatible API (`https://api.nan.builders/v1`), and registers the community media MCP server via pi's native `pi.registerMcpServer()`.
|
|
10
10
|
|
|
11
11
|
> [!NOTE]
|
|
12
|
-
> **Requirements:** pi **≥ 1.4.0** (peer range `^1.4.0`). The package is verified against **pi 1.
|
|
12
|
+
> **Requirements:** pi **≥ 1.4.0** (peer range `^1.4.0`). The package is verified against **pi 1.6.0 / pi-ai 1.6.0**; the peer floor only rises on pi minor realigns.
|
|
13
13
|
|
|
14
14
|
## ✨ Features
|
|
15
15
|
|
|
@@ -23,6 +23,7 @@ Registers the `nan` provider via `pi.registerProvider()` using NaN's OpenAI-comp
|
|
|
23
23
|
| **Truncated-stream retry** | `supportsFinishReason: true` turns an SSE stream closed before `finish_reason` into a retryable error instead of a silent stall ([#2](https://github.com/gtrabanco/pi-nan-provider/issues/2)). |
|
|
24
24
|
| **Streaming token usage** | `stream_options.include_usage` is on by default, so pi reports real input/output/reasoning/cache counts ([#4](https://github.com/gtrabanco/pi-nan-provider/issues/4), [#7](https://github.com/gtrabanco/pi-nan-provider/issues/7)). |
|
|
25
25
|
| **Reasoning controls** | Per-model `reasoningEffortValues` + `thinkingLevelMap` ([#16](https://github.com/gtrabanco/pi-nan-provider/issues/16)), the reasoning-only stream guard ([#21](https://github.com/gtrabanco/pi-nan-provider/issues/21)), and the per-model max-token field (`qwen3.8-max` keeps `max_completion_tokens`; `qwen3.8-flash` returned to `max_tokens` after NaN's gateway fix, [#34](https://github.com/gtrabanco/pi-nan-provider/issues/34) → [#36](https://github.com/gtrabanco/pi-nan-provider/issues/36)). |
|
|
26
|
+
| **Model-facts export** | `NAN_MODEL_FACTS` — one frozen, typed entry per billed chat model: limits, cost rates, reasoning contract, tool protocol, `max_tokens` semantics, thinking budget, cache mode and billing class, every cell carrying a provenance id ([#47](https://github.com/gtrabanco/pi-nan-provider/issues/47)). |
|
|
26
27
|
| **Attribution header** | `X-Pi-Provider: gtrabanco/pi-nan-provider@<version>` on every request, stripped when pi's install telemetry is disabled. |
|
|
27
28
|
| **Native image models** | `flux-2-klein` and `qwen-image-2.1` registered as pi `type: "image"` models, reachable from codemode and extensions. |
|
|
28
29
|
| **Native MCP media bridge** | The `nan-media` server (10 tools) registered through `pi.registerMcpServer()`, managed with `/nan-mcp`. |
|
|
@@ -120,7 +121,7 @@ You can override any model's `compat` per-model in `~/.pi/agent/models.json` (pi
|
|
|
120
121
|
|
|
121
122
|
> Setting `supportsFinishReason: false` restores the old silent-stall behavior — not recommended.
|
|
122
123
|
|
|
123
|
-
**pi-ai 1.5.1 compat escape hatches** (`~/.pi/agent/models.json`, per model): `compat.requiresToolsWithToolHistory: true` restores sending `tools: []` in conversations with tool history (pi-ai 1.5.1 omits it by default, fixing vLLM 0.20+ `tools must not be an empty array` rejections behind LiteLLM); `compat.requiresNonNullAssistantContent: true` sends `""` instead of `null` in assistant messages that only carry tool calls; `compat.promptCacheKeyMode: "disabled"` guarantees `prompt_cache_key` is never sent to the gateway (the default `auto` already never enables it for NaN).
|
|
124
|
+
**pi-ai 1.5.1+ compat escape hatches** (`~/.pi/agent/models.json`, per model, unchanged in 1.6.0): `compat.requiresToolsWithToolHistory: true` restores sending `tools: []` in conversations with tool history (pi-ai 1.5.1 omits it by default, fixing vLLM 0.20+ `tools must not be an empty array` rejections behind LiteLLM); `compat.requiresNonNullAssistantContent: true` sends `""` instead of `null` in assistant messages that only carry tool calls; `compat.promptCacheKeyMode: "disabled"` guarantees `prompt_cache_key` is never sent to the gateway (the default `auto` already never enables it for NaN).
|
|
124
125
|
|
|
125
126
|
**Streaming token usage:** `supportsUsageInStreaming` is `true` by default. NaN's published schema does not document `stream_options`, but the live gateway honors it — measured 2026-09-16 ([#7](https://github.com/gtrabanco/pi-nan-provider/issues/7)): two identical streaming calls per model, 0 usage chunks without the flag and exactly 1 with it, on `deepseek-v4-flash`, `glm5.3-flash`, `qwen3.6`, `gemma4` and `mimo-v2.5` (since removed). pi therefore reports real input/output/reasoning/cache token counts instead of zeros. If a model turns out not to report streaming usage, opt out per model — the request sanitizer then strips `stream_options` and the payload stays strict:
|
|
126
127
|
|
|
@@ -450,6 +451,59 @@ reproducible evidence package for NaN:
|
|
|
450
451
|
request ([#44](https://github.com/gtrabanco/pi-nan-provider/issues/44)), with
|
|
451
452
|
only `cwd` hashed. Identical inputs produce byte-identical zip bytes.
|
|
452
453
|
|
|
454
|
+
## 🧭 Model facts: `NAN_MODEL_FACTS`
|
|
455
|
+
|
|
456
|
+
Most of what this package knows about the fleet used to live in this README and
|
|
457
|
+
in inline comments. Issue [#47](https://github.com/gtrabanco/pi-nan-provider/issues/47)
|
|
458
|
+
promotes it to data: one frozen, typed record, exported from the package entry
|
|
459
|
+
point, so your own scripts can plan context, caching and spend without parsing
|
|
460
|
+
prose or reaching into `scripts/`.
|
|
461
|
+
|
|
462
|
+
```ts
|
|
463
|
+
import { NAN_MODEL_FACTS, NAN_ENDPOINT_FACTS, NAN_MODEL_FACTS_META } from "@gtrabanco/pi-nan-provider";
|
|
464
|
+
|
|
465
|
+
const facts = NAN_MODEL_FACTS["deepseek-v4-flash"];
|
|
466
|
+
facts.contextWindow; // 1048576
|
|
467
|
+
facts.maxTokens; // 32768
|
|
468
|
+
facts.cost; // { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }
|
|
469
|
+
facts.input; // ["text", "image"]
|
|
470
|
+
facts.toolCalling; // "openai-tools" | "xml"
|
|
471
|
+
facts.maxTokensSemantics; // "bounds-total" | "bounds-visible-answer"
|
|
472
|
+
facts.thinkingBudget; // "honoured" | "ignored" | "unmeasured"
|
|
473
|
+
facts.cacheMode; // "automatic" | "opt-in" | "unsupported" | "unmeasured"
|
|
474
|
+
facts.billingClass; // "quota-only" | "credit-standard" | "credit-larger"
|
|
475
|
+
facts.parallelToolCalls; // boolean | "unmeasured"
|
|
476
|
+
facts.structuredOutput; // boolean | "unmeasured"
|
|
477
|
+
|
|
478
|
+
facts.provenance.toolCalling; // "docs"
|
|
479
|
+
NAN_MODEL_FACTS_META.sources["docs"]; // URL + check date
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
- **Facts, not policy.** The record says what a model *is*. How you use it —
|
|
483
|
+
phases per context, a routing ladder, a cache-warming strategy — stays yours.
|
|
484
|
+
- **One entry per billed chat model** (13 today), keyed by model id. Non-chat
|
|
485
|
+
endpoints (embedding, rerank, TTS, STT, image, video) are not chat models and
|
|
486
|
+
are not exported.
|
|
487
|
+
- **Provenance per cell.** Every cell names a source id; `NAN_MODEL_FACTS_META.sources`
|
|
488
|
+
resolves it to a URL with its check date or to a dated measurement recorded in
|
|
489
|
+
this repo. The `override`, `compat` and `catalog-cost` ids point at the
|
|
490
|
+
entry's own `notes`, which already carry those citations.
|
|
491
|
+
- **`"unmeasured"` means no claim was made**, never "false". `parallelToolCalls`
|
|
492
|
+
is `"unmeasured"` on every model because nothing documents or measures several
|
|
493
|
+
tool calls per turn; `structuredOutput` is a boolean only where the NaN docs
|
|
494
|
+
document `json_object` / `json_schema` for that model.
|
|
495
|
+
- **Cold-prompt ceiling.** `coldCeilingTokens` is `"unmeasured"` on every entry:
|
|
496
|
+
the only measurement is endpoint-wide, so it ships separately as
|
|
497
|
+
`NAN_ENDPOINT_FACTS.coldCacheCeilingTokens` (200,000 tokens, measured
|
|
498
|
+
2026-10-01) with a `coldCeilingScope` stating it is Cloudflare's 120 s
|
|
499
|
+
proxy-read limit, not a model capability. Size a first cold request under it.
|
|
500
|
+
- **Offline and frozen.** The record is derived from the shipped generated
|
|
501
|
+
catalog plus the build-time facts layer, so reading it performs no network
|
|
502
|
+
call, and it is deep-frozen: one consumer cannot change what the next one
|
|
503
|
+
reads. It never feeds provider registration — the read-time overlay
|
|
504
|
+
([#19](https://github.com/gtrabanco/pi-nan-provider/issues/19)) still decides
|
|
505
|
+
the models a session sees.
|
|
506
|
+
|
|
453
507
|
## 📊 Models
|
|
454
508
|
|
|
455
509
|
Baseline catalog (verified against [NaN docs](https://nan.builders/docs/models) and [OpenAPI](https://nan.builders/openapi.json)).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gtrabanco/pi-nan-provider",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "NaN Builders (api.nan.builders) model provider for pi - OpenAI-compatible registration with a models.dev-generated fallback, tier-aware live catalog, and an optional community media MCP bridge",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi",
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"@earendil-works/pi-coding-agent": "^1.4.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@earendil-works/pi-ai": "1.
|
|
51
|
-
"@earendil-works/pi-coding-agent": "1.
|
|
50
|
+
"@earendil-works/pi-ai": "1.6.0",
|
|
51
|
+
"@earendil-works/pi-coding-agent": "1.6.0",
|
|
52
52
|
"@types/bun": "1.4",
|
|
53
53
|
"typescript": "7"
|
|
54
54
|
},
|
|
@@ -36,8 +36,10 @@
|
|
|
36
36
|
|
|
37
37
|
import type { GeneratedModelEntry } from "../src/fetch-models.ts";
|
|
38
38
|
import { NON_CHAT_MODEL_IDS } from "../src/fetch-models.ts";
|
|
39
|
+
import { buildModelFacts, overrideFieldKeys } from "../src/model-facts-core.ts";
|
|
39
40
|
import type { ManualModelOverride } from "./manual-overrides.ts";
|
|
40
41
|
import { MANUAL_OVERRIDES, MANUAL_ONLY_MODEL_IDS } from "./manual-overrides.ts";
|
|
42
|
+
import { MODEL_FACTS } from "./model-facts.ts";
|
|
41
43
|
|
|
42
44
|
const MODELS_DEV_API_URL = "https://models.dev/api.json";
|
|
43
45
|
const SOURCE_PROVIDER_ID = "nan";
|
|
@@ -362,7 +364,22 @@ async function main(): Promise<void> {
|
|
|
362
364
|
);
|
|
363
365
|
}
|
|
364
366
|
|
|
367
|
+
// Validate the manual facts layer against the catalog just built: a missing
|
|
368
|
+
// declaration, a ghost id, a value outside its documented union or a cell
|
|
369
|
+
// without provenance is a build failure, never a silently incomplete export.
|
|
365
370
|
const fetchedAt = new Date().toISOString();
|
|
371
|
+
const factsMeta = {
|
|
372
|
+
source: MODELS_DEV_API_URL,
|
|
373
|
+
modelsDevProvider: SOURCE_PROVIDER_ID,
|
|
374
|
+
fetchedAt,
|
|
375
|
+
modelCount: entries.length,
|
|
376
|
+
};
|
|
377
|
+
try {
|
|
378
|
+
buildModelFacts(entries, MODEL_FACTS, overrideFieldKeys(MANUAL_OVERRIDES), factsMeta);
|
|
379
|
+
} catch (error) {
|
|
380
|
+
fail(error instanceof Error ? error.message : String(error));
|
|
381
|
+
}
|
|
382
|
+
console.log(`generate-models: model-facts catalog validated (${entries.length} models)`);
|
|
366
383
|
const allNotes = [
|
|
367
384
|
...new Set([
|
|
368
385
|
...skipped,
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MODEL_FACTS — the manual layer of the exported model-facts catalog
|
|
3
|
+
* (issue #47).
|
|
4
|
+
*
|
|
5
|
+
* Same posture as `MANUAL_OVERRIDES`: this is the place a hand-maintained fact
|
|
6
|
+
* enters the build, with provenance, instead of being transcribed from README
|
|
7
|
+
* prose by a consumer. `scripts/generate-models.ts` validates these
|
|
8
|
+
* declarations against the catalog it just generated (every catalog id
|
|
9
|
+
* declared, no ghost ids, every value inside its documented union, every cell
|
|
10
|
+
* sourced), and `src/model-facts.ts` projects them into the frozen public
|
|
11
|
+
* record.
|
|
12
|
+
*
|
|
13
|
+
* The carried capabilities (context window, max tokens, cost, modalities,
|
|
14
|
+
* reasoning map, compat) are NOT repeated here — they are read from the
|
|
15
|
+
* generated catalog entry, which already carries its own provenance notes.
|
|
16
|
+
* Only the eight facts this issue promotes out of prose are declared.
|
|
17
|
+
*
|
|
18
|
+
* Sources (`sources` ids) resolve through `NAN_FACT_SOURCES` in
|
|
19
|
+
* `src/model-facts-core.ts`:
|
|
20
|
+
* - `docs` / `docs-reasoning` / `docs-cross-model`: https://nan.builders/docs/models
|
|
21
|
+
* (checked 2026-11-23). `docs-cross-model` marks a statement made on the
|
|
22
|
+
* deepseek-v4-flash card about the GLM models, qwen3.6 and gemma4.
|
|
23
|
+
* - `model-guide`: https://nan.builders/model-guide (the NaN community guide
|
|
24
|
+
* that publishes a cache rate per model).
|
|
25
|
+
* - `measured-36`: the qwen3.8-flash 2026-11-18 probe recorded in issue #36 —
|
|
26
|
+
* a measurement beats the docs, which still describe the pre-fix exception.
|
|
27
|
+
* - `none`: no positive claim (the `unmeasured` sentinel, or a field the
|
|
28
|
+
* catalog does not declare).
|
|
29
|
+
*
|
|
30
|
+
* Per-model evidence, all from the sources above:
|
|
31
|
+
* - Tool protocol: the docs spell it on every card — "Tool calling (XML
|
|
32
|
+
* format)" on qwen3.8-flash, qwen3.6 and gemma4, "Tool calling (function
|
|
33
|
+
* calling)" on the other ten.
|
|
34
|
+
* - `max_tokens` semantics: the docs' reasoning section says the output budget
|
|
35
|
+
* "is used exactly as you send it on every model … Reasoning tokens are spent
|
|
36
|
+
* from that same budget", and names qwen3.8-max as the model where
|
|
37
|
+
* "`max_tokens` only bounds the visible answer". qwen3.8-flash is the same
|
|
38
|
+
* exception on paper, but the 2026-11-18 probe (max_tokens=64 →
|
|
39
|
+
* completion_tokens=64, all reasoning) measured the fixed behaviour, so that
|
|
40
|
+
* cell follows the measurement.
|
|
41
|
+
* - Thinking budget: the docs make `thinking_budget`/`thinking_token_budget` a
|
|
42
|
+
* hard 1–32768 cap on qwen3.6, gemma4 and qwen3.8-flash, state it "is not
|
|
43
|
+
* honoured on this model" for qwen3.8-max, and keep every other model out of
|
|
44
|
+
* the contract ("depending on the model it is rejected with a 400 or
|
|
45
|
+
* ignored") — which is `unmeasured`, not `ignored`.
|
|
46
|
+
* - Cache mode: the model guide publishes a cache rate for eleven models and no
|
|
47
|
+
* opt-in parameter is documented anywhere, so the cache engages
|
|
48
|
+
* automatically; qwen3.6 and gemma4 have no published rate and stay
|
|
49
|
+
* `unmeasured`.
|
|
50
|
+
* - Billing class: the docs' Billing row reads "credits · larger model" on the
|
|
51
|
+
* six larger models and "credits" on the rest; no chat model is quota-billed.
|
|
52
|
+
* - Structured output: documented per model (json_object and/or json_schema);
|
|
53
|
+
* silence is `unmeasured`, never a guessed `true`.
|
|
54
|
+
* - Parallel tool calls: nothing documents or measures several tool calls per
|
|
55
|
+
* assistant turn, so every cell is `unmeasured`.
|
|
56
|
+
* - Cold ceiling: the only measurement is endpoint-wide, so every model carries
|
|
57
|
+
* `unmeasured` and the number ships as `NAN_ENDPOINT_FACTS`.
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
import type { ModelFactsDeclaration, ModelFactsDeclarations, NanFactSource, NanNewFactCell } from "../src/model-facts-core.ts";
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Default provenance per cell. A model overrides only the cells whose evidence
|
|
64
|
+
* differs from "documented on its own card, with a published cache rate".
|
|
65
|
+
*/
|
|
66
|
+
const BASE_SOURCES: Readonly<Record<NanNewFactCell, NanFactSource>> = {
|
|
67
|
+
toolCalling: "docs",
|
|
68
|
+
maxTokensSemantics: "docs",
|
|
69
|
+
thinkingBudget: "none",
|
|
70
|
+
coldCeilingTokens: "none",
|
|
71
|
+
cacheMode: "model-guide",
|
|
72
|
+
billingClass: "docs",
|
|
73
|
+
parallelToolCalls: "none",
|
|
74
|
+
structuredOutput: "none",
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/** Compact declaration: the eight values, with provenance defaulting to BASE_SOURCES. */
|
|
78
|
+
function declaration(
|
|
79
|
+
facts: Omit<ModelFactsDeclaration, "sources">,
|
|
80
|
+
sources: Partial<Record<NanNewFactCell, NanFactSource>> = {},
|
|
81
|
+
): ModelFactsDeclaration {
|
|
82
|
+
return { ...facts, sources: { ...BASE_SOURCES, ...sources } };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Per-model declarations, keyed by catalog id. A model missing here fails the
|
|
87
|
+
* build (`bun run generate-models`) and the test corpus.
|
|
88
|
+
*/
|
|
89
|
+
export const MODEL_FACTS: ModelFactsDeclarations = {
|
|
90
|
+
"deepseek-v4-flash": declaration(
|
|
91
|
+
{
|
|
92
|
+
toolCalling: "openai-tools",
|
|
93
|
+
maxTokensSemantics: "bounds-total",
|
|
94
|
+
thinkingBudget: "unmeasured",
|
|
95
|
+
coldCeilingTokens: "unmeasured",
|
|
96
|
+
cacheMode: "automatic",
|
|
97
|
+
billingClass: "credit-standard",
|
|
98
|
+
parallelToolCalls: "unmeasured",
|
|
99
|
+
structuredOutput: true,
|
|
100
|
+
},
|
|
101
|
+
{ structuredOutput: "docs" },
|
|
102
|
+
),
|
|
103
|
+
"deepseek-v4-pro": declaration({
|
|
104
|
+
toolCalling: "openai-tools",
|
|
105
|
+
maxTokensSemantics: "bounds-total",
|
|
106
|
+
thinkingBudget: "unmeasured",
|
|
107
|
+
coldCeilingTokens: "unmeasured",
|
|
108
|
+
cacheMode: "automatic",
|
|
109
|
+
billingClass: "credit-larger",
|
|
110
|
+
parallelToolCalls: "unmeasured",
|
|
111
|
+
structuredOutput: "unmeasured",
|
|
112
|
+
}),
|
|
113
|
+
gemma4: declaration(
|
|
114
|
+
{
|
|
115
|
+
toolCalling: "xml",
|
|
116
|
+
maxTokensSemantics: "bounds-total",
|
|
117
|
+
thinkingBudget: "honoured",
|
|
118
|
+
coldCeilingTokens: "unmeasured",
|
|
119
|
+
cacheMode: "unmeasured",
|
|
120
|
+
billingClass: "credit-standard",
|
|
121
|
+
parallelToolCalls: "unmeasured",
|
|
122
|
+
structuredOutput: true,
|
|
123
|
+
},
|
|
124
|
+
{ thinkingBudget: "docs-reasoning", cacheMode: "none", structuredOutput: "docs-cross-model" },
|
|
125
|
+
),
|
|
126
|
+
"glm5.3": declaration(
|
|
127
|
+
{
|
|
128
|
+
toolCalling: "openai-tools",
|
|
129
|
+
maxTokensSemantics: "bounds-total",
|
|
130
|
+
thinkingBudget: "unmeasured",
|
|
131
|
+
coldCeilingTokens: "unmeasured",
|
|
132
|
+
cacheMode: "automatic",
|
|
133
|
+
billingClass: "credit-larger",
|
|
134
|
+
parallelToolCalls: "unmeasured",
|
|
135
|
+
structuredOutput: true,
|
|
136
|
+
},
|
|
137
|
+
{ structuredOutput: "docs-cross-model" },
|
|
138
|
+
),
|
|
139
|
+
"glm5.3-flash": declaration(
|
|
140
|
+
{
|
|
141
|
+
toolCalling: "openai-tools",
|
|
142
|
+
maxTokensSemantics: "bounds-total",
|
|
143
|
+
thinkingBudget: "unmeasured",
|
|
144
|
+
coldCeilingTokens: "unmeasured",
|
|
145
|
+
cacheMode: "automatic",
|
|
146
|
+
billingClass: "credit-standard",
|
|
147
|
+
parallelToolCalls: "unmeasured",
|
|
148
|
+
structuredOutput: true,
|
|
149
|
+
},
|
|
150
|
+
{ structuredOutput: "docs-cross-model" },
|
|
151
|
+
),
|
|
152
|
+
hy4: declaration({
|
|
153
|
+
toolCalling: "openai-tools",
|
|
154
|
+
maxTokensSemantics: "bounds-total",
|
|
155
|
+
thinkingBudget: "unmeasured",
|
|
156
|
+
coldCeilingTokens: "unmeasured",
|
|
157
|
+
cacheMode: "automatic",
|
|
158
|
+
billingClass: "credit-larger",
|
|
159
|
+
parallelToolCalls: "unmeasured",
|
|
160
|
+
structuredOutput: "unmeasured",
|
|
161
|
+
}),
|
|
162
|
+
"hy4-flash": declaration(
|
|
163
|
+
{
|
|
164
|
+
toolCalling: "openai-tools",
|
|
165
|
+
maxTokensSemantics: "bounds-total",
|
|
166
|
+
thinkingBudget: "unmeasured",
|
|
167
|
+
coldCeilingTokens: "unmeasured",
|
|
168
|
+
cacheMode: "automatic",
|
|
169
|
+
billingClass: "credit-standard",
|
|
170
|
+
parallelToolCalls: "unmeasured",
|
|
171
|
+
structuredOutput: true,
|
|
172
|
+
},
|
|
173
|
+
{ structuredOutput: "docs" },
|
|
174
|
+
),
|
|
175
|
+
"kimi-k3.1-pro": declaration({
|
|
176
|
+
toolCalling: "openai-tools",
|
|
177
|
+
maxTokensSemantics: "bounds-total",
|
|
178
|
+
thinkingBudget: "unmeasured",
|
|
179
|
+
coldCeilingTokens: "unmeasured",
|
|
180
|
+
cacheMode: "automatic",
|
|
181
|
+
billingClass: "credit-larger",
|
|
182
|
+
parallelToolCalls: "unmeasured",
|
|
183
|
+
structuredOutput: "unmeasured",
|
|
184
|
+
}),
|
|
185
|
+
"mimo-v2.6-flash": declaration({
|
|
186
|
+
toolCalling: "openai-tools",
|
|
187
|
+
maxTokensSemantics: "bounds-total",
|
|
188
|
+
thinkingBudget: "unmeasured",
|
|
189
|
+
coldCeilingTokens: "unmeasured",
|
|
190
|
+
cacheMode: "automatic",
|
|
191
|
+
billingClass: "credit-standard",
|
|
192
|
+
parallelToolCalls: "unmeasured",
|
|
193
|
+
structuredOutput: "unmeasured",
|
|
194
|
+
}),
|
|
195
|
+
"qwen3.6": declaration(
|
|
196
|
+
{
|
|
197
|
+
toolCalling: "xml",
|
|
198
|
+
maxTokensSemantics: "bounds-total",
|
|
199
|
+
thinkingBudget: "honoured",
|
|
200
|
+
coldCeilingTokens: "unmeasured",
|
|
201
|
+
cacheMode: "unmeasured",
|
|
202
|
+
billingClass: "credit-standard",
|
|
203
|
+
parallelToolCalls: "unmeasured",
|
|
204
|
+
structuredOutput: true,
|
|
205
|
+
},
|
|
206
|
+
{ thinkingBudget: "docs-reasoning", cacheMode: "none", structuredOutput: "docs-cross-model" },
|
|
207
|
+
),
|
|
208
|
+
"qwen3.8-flash": declaration(
|
|
209
|
+
{
|
|
210
|
+
toolCalling: "xml",
|
|
211
|
+
maxTokensSemantics: "bounds-total",
|
|
212
|
+
thinkingBudget: "honoured",
|
|
213
|
+
coldCeilingTokens: "unmeasured",
|
|
214
|
+
cacheMode: "automatic",
|
|
215
|
+
billingClass: "credit-standard",
|
|
216
|
+
parallelToolCalls: "unmeasured",
|
|
217
|
+
structuredOutput: "unmeasured",
|
|
218
|
+
},
|
|
219
|
+
{ thinkingBudget: "docs-reasoning", maxTokensSemantics: "measured-36" },
|
|
220
|
+
),
|
|
221
|
+
"qwen3.8-max": declaration(
|
|
222
|
+
{
|
|
223
|
+
toolCalling: "openai-tools",
|
|
224
|
+
maxTokensSemantics: "bounds-visible-answer",
|
|
225
|
+
thinkingBudget: "ignored",
|
|
226
|
+
coldCeilingTokens: "unmeasured",
|
|
227
|
+
cacheMode: "automatic",
|
|
228
|
+
billingClass: "credit-larger",
|
|
229
|
+
parallelToolCalls: "unmeasured",
|
|
230
|
+
structuredOutput: "unmeasured",
|
|
231
|
+
},
|
|
232
|
+
{ maxTokensSemantics: "docs-reasoning", thinkingBudget: "docs-reasoning" },
|
|
233
|
+
),
|
|
234
|
+
"qwen4-max": declaration(
|
|
235
|
+
{
|
|
236
|
+
toolCalling: "openai-tools",
|
|
237
|
+
maxTokensSemantics: "bounds-total",
|
|
238
|
+
thinkingBudget: "unmeasured",
|
|
239
|
+
coldCeilingTokens: "unmeasured",
|
|
240
|
+
cacheMode: "automatic",
|
|
241
|
+
billingClass: "credit-larger",
|
|
242
|
+
parallelToolCalls: "unmeasured",
|
|
243
|
+
structuredOutput: true,
|
|
244
|
+
},
|
|
245
|
+
{ structuredOutput: "docs" },
|
|
246
|
+
),
|
|
247
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// This file is auto-generated by scripts/generate-models.ts
|
|
2
2
|
// Do not edit manually — run `bun run generate-models` to update.
|
|
3
3
|
//
|
|
4
|
-
// Source: https://models.dev/api.json (provider "nan"), fetched 2026-11-
|
|
4
|
+
// Source: https://models.dev/api.json (provider "nan"), fetched 2026-11-23T00:46:05.244Z
|
|
5
5
|
// Provenance: every contextWindow/maxTokens/input/cost value traces to
|
|
6
6
|
// models.dev or to the per-entry notes below. Nothing is invented; entries
|
|
7
7
|
// models.dev documents incompletely are omitted and flagged instead.
|
|
@@ -136,7 +136,7 @@ export const NAN_GENERATED_MODELS: readonly GeneratedModelEntry[] = [
|
|
|
136
136
|
"id": "deepseek-v4-pro",
|
|
137
137
|
"name": "DeepSeek V4 Pro 0813",
|
|
138
138
|
"description": "DeepSeek V4 Pro snapshot with million-token context and support for thinking and non-thinking modes",
|
|
139
|
-
"family": "deepseek-
|
|
139
|
+
"family": "deepseek-pro",
|
|
140
140
|
"attachment": false,
|
|
141
141
|
"reasoning": true,
|
|
142
142
|
"reasoning_options": [
|
|
@@ -480,7 +480,7 @@ export const NAN_GENERATED_MODELS: readonly GeneratedModelEntry[] = [
|
|
|
480
480
|
"id": "hy4",
|
|
481
481
|
"name": "Hy4",
|
|
482
482
|
"description": "A next-generation multimodal productivity model with significantly enhanced Agent and complex task execution capabilities.",
|
|
483
|
-
"family": "
|
|
483
|
+
"family": "hy",
|
|
484
484
|
"attachment": true,
|
|
485
485
|
"reasoning": true,
|
|
486
486
|
"reasoning_options": [
|
|
@@ -591,7 +591,7 @@ export const NAN_GENERATED_MODELS: readonly GeneratedModelEntry[] = [
|
|
|
591
591
|
"id": "kimi-k3.1-pro",
|
|
592
592
|
"name": "Kimi K3.1 Pro",
|
|
593
593
|
"description": "Multimodal Kimi model with a 1M-token context window and always-on reasoning, for coding, 3D creation and financial research",
|
|
594
|
-
"family": "kimi-
|
|
594
|
+
"family": "kimi-pro",
|
|
595
595
|
"attachment": true,
|
|
596
596
|
"reasoning": true,
|
|
597
597
|
"reasoning_options": [
|
|
@@ -676,7 +676,7 @@ export const NAN_GENERATED_MODELS: readonly GeneratedModelEntry[] = [
|
|
|
676
676
|
"id": "mimo-v2.6-flash",
|
|
677
677
|
"name": "MiMo-V2.6-Flash",
|
|
678
678
|
"description": "MiMo Flash model for multimodal coding agents and long-context automation",
|
|
679
|
-
"family": "mimo",
|
|
679
|
+
"family": "mimo-flash",
|
|
680
680
|
"attachment": true,
|
|
681
681
|
"reasoning": true,
|
|
682
682
|
"reasoning_options": [
|
|
@@ -849,7 +849,7 @@ export const NAN_GENERATED_MODELS: readonly GeneratedModelEntry[] = [
|
|
|
849
849
|
"id": "qwen3.8-flash",
|
|
850
850
|
"name": "Qwen3.8 Flash",
|
|
851
851
|
"description": "Qwen vision-language model for visual reasoning, documents, and agent tasks",
|
|
852
|
-
"family": "qwen",
|
|
852
|
+
"family": "qwen-flash",
|
|
853
853
|
"attachment": true,
|
|
854
854
|
"reasoning": true,
|
|
855
855
|
"reasoning_options": [
|
|
@@ -937,7 +937,7 @@ export const NAN_GENERATED_MODELS: readonly GeneratedModelEntry[] = [
|
|
|
937
937
|
"id": "qwen3.8-max",
|
|
938
938
|
"name": "Qwen3.8 Max",
|
|
939
939
|
"description": "2.4-trillion-parameter MoE flagship for coding, professional work, multimodal understanding, and long-horizon agentic workflows",
|
|
940
|
-
"family": "qwen",
|
|
940
|
+
"family": "qwen-max",
|
|
941
941
|
"attachment": true,
|
|
942
942
|
"reasoning": true,
|
|
943
943
|
"reasoning_options": [
|
|
@@ -1027,7 +1027,7 @@ export const NAN_GENERATED_MODELS: readonly GeneratedModelEntry[] = [
|
|
|
1027
1027
|
export const GENERATED_CATALOG_META = {
|
|
1028
1028
|
source: "https://models.dev/api.json",
|
|
1029
1029
|
modelsDevProvider: "nan",
|
|
1030
|
-
fetchedAt: "2026-11-
|
|
1030
|
+
fetchedAt: "2026-11-23T00:46:05.244Z",
|
|
1031
1031
|
modelCount: 13,
|
|
1032
1032
|
models: ["deepseek-v4-flash","deepseek-v4-pro","gemma4","glm5.3","glm5.3-flash","hy4","hy4-flash","kimi-k3.1-pro","mimo-v2.6-flash","qwen3.6","qwen3.8-flash","qwen3.8-max","qwen4-max"],
|
|
1033
1033
|
notes: [
|
package/src/index.ts
CHANGED
|
@@ -168,6 +168,32 @@ export default async function nanProviderExtension(pi: ExtensionAPI): Promise<vo
|
|
|
168
168
|
/** Exposed for tests: the env var this package uses for every NaN surface. */
|
|
169
169
|
export { NAN_API_KEY_ENV };
|
|
170
170
|
|
|
171
|
+
/**
|
|
172
|
+
* The model-facts catalog (issue #47): a frozen, provenance-carrying record of
|
|
173
|
+
* what each billed NaN model is. Plain data — no pi-ai Model objects and no
|
|
174
|
+
* policy — so a consumer can plan context, caching and spend from it without
|
|
175
|
+
* reading this package's internals.
|
|
176
|
+
*/
|
|
177
|
+
export {
|
|
178
|
+
NAN_ENDPOINT_FACTS,
|
|
179
|
+
NAN_FACT_SOURCES,
|
|
180
|
+
NAN_MODEL_FACTS,
|
|
181
|
+
NAN_MODEL_FACTS_META,
|
|
182
|
+
type ModelFactsDeclaration,
|
|
183
|
+
type NanBillingClass,
|
|
184
|
+
type NanCacheMode,
|
|
185
|
+
type NanEndpointFacts,
|
|
186
|
+
type NanFactCell,
|
|
187
|
+
type NanFactSource,
|
|
188
|
+
type NanMaxTokensSemantics,
|
|
189
|
+
type NanModelCostFact,
|
|
190
|
+
type NanModelFacts,
|
|
191
|
+
type NanModelFactsMeta,
|
|
192
|
+
type NanThinkingBudget,
|
|
193
|
+
type NanToolCalling,
|
|
194
|
+
type NanTriState,
|
|
195
|
+
} from "./model-facts.ts";
|
|
196
|
+
|
|
171
197
|
/** Exposed for advanced consumers that want the typed provider factory directly. */
|
|
172
198
|
export { createNanCompatibleProvider, type OpenAICompatibleProviderConfig } from "./provider-factory.ts";
|
|
173
199
|
export { PROVIDERS, NAN_PROVIDER } from "./providers.ts";
|
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NaN model-facts schema, provenance table and builder (issue #47).
|
|
3
|
+
*
|
|
4
|
+
* The provider already knows the fleet's limits, but they live in prose and in
|
|
5
|
+
* pi-only capability data. This module turns them into one typed record that a
|
|
6
|
+
* consumer can read: facts only (what a model *is*), never policy (how a
|
|
7
|
+
* consumer should batch or route work), and every cell carrying a provenance id
|
|
8
|
+
* from the closed set below.
|
|
9
|
+
*
|
|
10
|
+
* Why a separate module from `src/model-facts.ts`: this file must stay free of
|
|
11
|
+
* catalog imports so `scripts/generate-models.ts` can validate the freshly
|
|
12
|
+
* generated entries before they are written. The public frozen record lives in
|
|
13
|
+
* `src/model-facts.ts`, which imports the generated catalog and this builder.
|
|
14
|
+
*
|
|
15
|
+
* Provenance model: a cell's value is always paired with a `NanFactSource` id.
|
|
16
|
+
* `NAN_FACT_SOURCES` resolves each id to its citation (URL and check date, or a
|
|
17
|
+
* dated measurement already recorded in the repo). Three ids point into the
|
|
18
|
+
* entry's own `notes` — `override`, `compat` and `catalog-cost` — because the
|
|
19
|
+
* generated catalog already records those provenance notes there; duplicating
|
|
20
|
+
* them per cell would fork the same truth into two places.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import type { OpenAICompletionsCompat, ThinkingLevelMap } from "@earendil-works/pi-ai";
|
|
24
|
+
import type { GeneratedModelEntry } from "./fetch-models.ts";
|
|
25
|
+
|
|
26
|
+
// ── Documented value sets (membership-pinned) ───────────────────────────────
|
|
27
|
+
|
|
28
|
+
/** Tool protocol the model's tool calling rides on (docs `capabilities`). */
|
|
29
|
+
export type NanToolCalling = "openai-tools" | "xml" | "unmeasured";
|
|
30
|
+
export const NAN_TOOL_CALLING_VALUES: readonly NanToolCalling[] = ["openai-tools", "xml", "unmeasured"];
|
|
31
|
+
|
|
32
|
+
/** Whether `max_tokens` caps reasoning + answer, or only the visible answer. */
|
|
33
|
+
export type NanMaxTokensSemantics = "bounds-total" | "bounds-visible-answer" | "unmeasured";
|
|
34
|
+
export const NAN_MAX_TOKENS_SEMANTICS_VALUES: readonly NanMaxTokensSemantics[] = [
|
|
35
|
+
"bounds-total",
|
|
36
|
+
"bounds-visible-answer",
|
|
37
|
+
"unmeasured",
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
/** Whether the gateway honours a `thinking_budget` on the model. */
|
|
41
|
+
export type NanThinkingBudget = "honoured" | "ignored" | "unmeasured";
|
|
42
|
+
export const NAN_THINKING_BUDGET_VALUES: readonly NanThinkingBudget[] = [
|
|
43
|
+
"honoured",
|
|
44
|
+
"ignored",
|
|
45
|
+
"unmeasured",
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
/** Whether the prompt cache engages automatically or needs an opt-in. */
|
|
49
|
+
export type NanCacheMode = "automatic" | "opt-in" | "unsupported" | "unmeasured";
|
|
50
|
+
export const NAN_CACHE_MODE_VALUES: readonly NanCacheMode[] = [
|
|
51
|
+
"automatic",
|
|
52
|
+
"opt-in",
|
|
53
|
+
"unsupported",
|
|
54
|
+
"unmeasured",
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
/** How NaN bills the model: credits standard, credits faster (larger), or quota. */
|
|
58
|
+
export type NanBillingClass = "quota-only" | "credit-standard" | "credit-larger";
|
|
59
|
+
export const NAN_BILLING_CLASS_VALUES: readonly NanBillingClass[] = [
|
|
60
|
+
"quota-only",
|
|
61
|
+
"credit-standard",
|
|
62
|
+
"credit-larger",
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
/** A tri-state capability fact: measured true, measured false, or not measured. */
|
|
66
|
+
export type NanTriState = boolean | "unmeasured";
|
|
67
|
+
|
|
68
|
+
// ── Provenance ──────────────────────────────────────────────────────────────
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Closed set of provenance ids. Every exported cell names one of these, and
|
|
72
|
+
* `NAN_MODEL_FACTS_META.sources` resolves it for a consumer. Adding a fact
|
|
73
|
+
* means adding a citation here first; a cell cannot be sourced from nowhere.
|
|
74
|
+
*/
|
|
75
|
+
export const NAN_FACT_SOURCES = Object.freeze({
|
|
76
|
+
"models.dev":
|
|
77
|
+
"https://models.dev/api.json, provider \"nan\" — the numeric limits, modalities and reasoning flag come from the generated catalog (fetch date in NAN_MODEL_FACTS_META.fetchedAt)",
|
|
78
|
+
override:
|
|
79
|
+
"scripts/manual-overrides.ts MANUAL_OVERRIDES — the value is a recorded override, and the entry's notes carry its per-model provenance note (source URL and date)",
|
|
80
|
+
compat:
|
|
81
|
+
"the shared NAN_COMPAT constant in scripts/generate-models.ts — the compat note in the entry's notes carries its provenance (2026-09-04 config, 2026-09-13 stream close, 2026-09-16 streaming usage)",
|
|
82
|
+
"catalog-cost":
|
|
83
|
+
"the shared NAN_CATALOG_COST constant in scripts/generate-models.ts — the cost note in the entry's notes records the credit-pool decision (NaN bills credits, not per-token USD)",
|
|
84
|
+
docs: "https://nan.builders/docs/models (checked 2026-11-23)",
|
|
85
|
+
"docs-reasoning": "https://nan.builders/docs/models#controlling-reasoning (checked 2026-11-23)",
|
|
86
|
+
"docs-cross-model":
|
|
87
|
+
"https://nan.builders/docs/models (checked 2026-11-23) — stated on the deepseek-v4-flash model card, which names the GLM models, qwen3.6 and gemma4",
|
|
88
|
+
"model-guide": "https://nan.builders/model-guide (NaN community model guide, November 2026)",
|
|
89
|
+
"measured-18":
|
|
90
|
+
"issue #18 cold-prompt probe, 2026-10-01 — endpoint-wide (Cloudflare 120 s proxy read timeout), not a model capability",
|
|
91
|
+
"measured-36":
|
|
92
|
+
"issue #36 closing probe, 2026-11-18 — qwen3.8-flash with max_tokens=64 returned completion_tokens=64 (reasoning_tokens=64, empty content), so max_tokens bounds the total again",
|
|
93
|
+
none: "no source: the cell is the \"unmeasured\" sentinel or a field the catalog does not declare; the entry's notes explain why",
|
|
94
|
+
} as const);
|
|
95
|
+
|
|
96
|
+
/** Provenance id of a single exported cell. */
|
|
97
|
+
export type NanFactSource = keyof typeof NAN_FACT_SOURCES;
|
|
98
|
+
|
|
99
|
+
// ── Cells ───────────────────────────────────────────────────────────────────
|
|
100
|
+
|
|
101
|
+
/** Cells the generated catalog already carried (issue #47, "already carried"). */
|
|
102
|
+
export const CARRIED_FACT_CELLS = [
|
|
103
|
+
"contextWindow",
|
|
104
|
+
"maxTokens",
|
|
105
|
+
"input",
|
|
106
|
+
"cost",
|
|
107
|
+
"reasoning",
|
|
108
|
+
"reasoningEffortValues",
|
|
109
|
+
"thinkingLevelMap",
|
|
110
|
+
"compat",
|
|
111
|
+
] as const;
|
|
112
|
+
|
|
113
|
+
/** Cells this issue promotes out of README prose into data. */
|
|
114
|
+
export const NEW_FACT_CELLS = [
|
|
115
|
+
"toolCalling",
|
|
116
|
+
"maxTokensSemantics",
|
|
117
|
+
"thinkingBudget",
|
|
118
|
+
"coldCeilingTokens",
|
|
119
|
+
"cacheMode",
|
|
120
|
+
"billingClass",
|
|
121
|
+
"parallelToolCalls",
|
|
122
|
+
"structuredOutput",
|
|
123
|
+
] as const;
|
|
124
|
+
|
|
125
|
+
/** Every exported fact cell. A record row carries one provenance id per entry. */
|
|
126
|
+
export const FACT_CELLS = [...CARRIED_FACT_CELLS, ...NEW_FACT_CELLS] as const;
|
|
127
|
+
export type NanCarriedFactCell = (typeof CARRIED_FACT_CELLS)[number];
|
|
128
|
+
export type NanNewFactCell = (typeof NEW_FACT_CELLS)[number];
|
|
129
|
+
export type NanFactCell = (typeof FACT_CELLS)[number];
|
|
130
|
+
|
|
131
|
+
// ── The exported record ─────────────────────────────────────────────────────
|
|
132
|
+
|
|
133
|
+
/** Cost rates the catalog carries (all pinned to 0 by the credit-pool decision). */
|
|
134
|
+
export interface NanModelCostFact {
|
|
135
|
+
input: number;
|
|
136
|
+
output: number;
|
|
137
|
+
cacheRead: number;
|
|
138
|
+
cacheWrite: number;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* One model's facts. Plain data only: no pi Model object, no `api`/`baseUrl`,
|
|
143
|
+
* no policy (batching, routing ladders), no rate limits — deliberately out of
|
|
144
|
+
* scope per issue #47 (S18/C15): the docs publish rpm/concurrency figures
|
|
145
|
+
* (checked 2026-11-23), so their absence here is the frozen scope decision,
|
|
146
|
+
* and adding the field is a future owner decision.
|
|
147
|
+
*/
|
|
148
|
+
export interface NanModelFacts {
|
|
149
|
+
id: string;
|
|
150
|
+
name: string;
|
|
151
|
+
contextWindow: number;
|
|
152
|
+
maxTokens: number;
|
|
153
|
+
input: readonly ("text" | "image")[];
|
|
154
|
+
cost: Readonly<NanModelCostFact>;
|
|
155
|
+
reasoning: boolean;
|
|
156
|
+
/** Empty array = the effort parameter is accepted but depth is model-managed. */
|
|
157
|
+
reasoningEffortValues: readonly string[];
|
|
158
|
+
/** Empty map = no thinking level is mapped for this model. */
|
|
159
|
+
thinkingLevelMap: Readonly<ThinkingLevelMap>;
|
|
160
|
+
compat: Readonly<OpenAICompletionsCompat>;
|
|
161
|
+
toolCalling: NanToolCalling;
|
|
162
|
+
maxTokensSemantics: NanMaxTokensSemantics;
|
|
163
|
+
thinkingBudget: NanThinkingBudget;
|
|
164
|
+
/**
|
|
165
|
+
* Per-model cold-prompt ceiling. Always `"unmeasured"` today: the only
|
|
166
|
+
* measurement is endpoint-wide, so it ships as `NAN_ENDPOINT_FACTS` rather
|
|
167
|
+
* than as a per-model claim.
|
|
168
|
+
*/
|
|
169
|
+
coldCeilingTokens: number | "unmeasured";
|
|
170
|
+
cacheMode: NanCacheMode;
|
|
171
|
+
billingClass: NanBillingClass;
|
|
172
|
+
parallelToolCalls: NanTriState;
|
|
173
|
+
structuredOutput: NanTriState;
|
|
174
|
+
/** One provenance id per exported cell. */
|
|
175
|
+
provenance: Readonly<Record<NanFactCell, NanFactSource>>;
|
|
176
|
+
/** The generated catalog's provenance notes (they carry the override/compat/cost citations). */
|
|
177
|
+
notes: readonly string[];
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Build-time metadata every facts record is stamped with. */
|
|
181
|
+
export interface ModelFactsBuildMeta {
|
|
182
|
+
source: string;
|
|
183
|
+
modelsDevProvider: string;
|
|
184
|
+
fetchedAt: string;
|
|
185
|
+
modelCount: number;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** Public metadata: the build stamp plus the citation table. */
|
|
189
|
+
export interface NanModelFactsMeta extends ModelFactsBuildMeta {
|
|
190
|
+
sources: typeof NAN_FACT_SOURCES;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** The measured, endpoint-wide cold-prompt ceiling (not a model capability). */
|
|
194
|
+
export interface NanEndpointFacts {
|
|
195
|
+
/** Conservative ceiling below the last working cold measurement (208,036 tokens). */
|
|
196
|
+
coldCacheCeilingTokens: number;
|
|
197
|
+
/** Date the cold probes ran. */
|
|
198
|
+
coldCeilingMeasuredAt: string;
|
|
199
|
+
/** What the number describes — never a per-model capability. */
|
|
200
|
+
coldCeilingScope: string;
|
|
201
|
+
/** The measurement itself, as recorded in the repo. */
|
|
202
|
+
coldCeilingSources: string;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// ── The manual declaration a model must ship ────────────────────────────────
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* The eight new facts plus one provenance id per fact. Declared per model in
|
|
209
|
+
* `scripts/model-facts.ts` (the manual-override path), validated at generation
|
|
210
|
+
* time and again when the public record is built.
|
|
211
|
+
*/
|
|
212
|
+
export interface ModelFactsDeclaration {
|
|
213
|
+
toolCalling: NanToolCalling;
|
|
214
|
+
maxTokensSemantics: NanMaxTokensSemantics;
|
|
215
|
+
thinkingBudget: NanThinkingBudget;
|
|
216
|
+
coldCeilingTokens: number | "unmeasured";
|
|
217
|
+
cacheMode: NanCacheMode;
|
|
218
|
+
billingClass: NanBillingClass;
|
|
219
|
+
parallelToolCalls: NanTriState;
|
|
220
|
+
structuredOutput: NanTriState;
|
|
221
|
+
sources: Readonly<Record<NanNewFactCell, NanFactSource>>;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** Declarations keyed by model id. */
|
|
225
|
+
export type ModelFactsDeclarations = Readonly<Record<string, ModelFactsDeclaration>>;
|
|
226
|
+
|
|
227
|
+
// ── Builder ─────────────────────────────────────────────────────────────────
|
|
228
|
+
|
|
229
|
+
/** The fields of an override entry that change a carried cell's provenance. */
|
|
230
|
+
const CARRIED_OVERRIDE_FIELDS = [
|
|
231
|
+
"contextWindow",
|
|
232
|
+
"maxTokens",
|
|
233
|
+
"input",
|
|
234
|
+
"reasoning",
|
|
235
|
+
"cost",
|
|
236
|
+
"reasoningEffortValues",
|
|
237
|
+
"thinkingLevelMap",
|
|
238
|
+
"maxTokensField",
|
|
239
|
+
] as const;
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Reduce an override map to the field names each model declares. Keeping this
|
|
243
|
+
* as a key list (instead of the override objects) keeps this module free of a
|
|
244
|
+
* runtime import from `scripts/`, so the generator can use it safely.
|
|
245
|
+
*/
|
|
246
|
+
export function overrideFieldKeys(
|
|
247
|
+
overrides: Readonly<Record<string, object>>,
|
|
248
|
+
): Readonly<Record<string, readonly string[]>> {
|
|
249
|
+
const keys: Record<string, readonly string[]> = {};
|
|
250
|
+
for (const [id, override] of Object.entries(overrides)) {
|
|
251
|
+
keys[id] = Object.keys(override);
|
|
252
|
+
}
|
|
253
|
+
return keys;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const VALUED_NEW_FACTS: Record<string, readonly unknown[]> = {
|
|
257
|
+
toolCalling: NAN_TOOL_CALLING_VALUES,
|
|
258
|
+
maxTokensSemantics: NAN_MAX_TOKENS_SEMANTICS_VALUES,
|
|
259
|
+
thinkingBudget: NAN_THINKING_BUDGET_VALUES,
|
|
260
|
+
cacheMode: NAN_CACHE_MODE_VALUES,
|
|
261
|
+
billingClass: NAN_BILLING_CLASS_VALUES,
|
|
262
|
+
parallelToolCalls: [true, false, "unmeasured"],
|
|
263
|
+
structuredOutput: [true, false, "unmeasured"],
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
function validateDeclaration(
|
|
267
|
+
id: string,
|
|
268
|
+
declaration: ModelFactsDeclaration,
|
|
269
|
+
problems: string[],
|
|
270
|
+
): void {
|
|
271
|
+
for (const [cell, allowed] of Object.entries(VALUED_NEW_FACTS)) {
|
|
272
|
+
const value = (declaration as unknown as Record<string, unknown>)[cell];
|
|
273
|
+
if (!allowed.includes(value)) {
|
|
274
|
+
problems.push(
|
|
275
|
+
`model-facts: ${id}: ${cell} value ${JSON.stringify(value)} is not one of ${allowed
|
|
276
|
+
.map((v) => JSON.stringify(v))
|
|
277
|
+
.join(", ")}`,
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
const cold = declaration.coldCeilingTokens;
|
|
282
|
+
if (cold !== "unmeasured" && !(typeof cold === "number" && Number.isFinite(cold) && cold > 0)) {
|
|
283
|
+
problems.push(
|
|
284
|
+
`model-facts: ${id}: coldCeilingTokens must be a positive number or "unmeasured" (got ${JSON.stringify(cold)})`,
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
const sources = declaration.sources as Readonly<Record<string, unknown>> | undefined;
|
|
288
|
+
for (const cell of NEW_FACT_CELLS) {
|
|
289
|
+
const source = sources?.[cell];
|
|
290
|
+
if (typeof source !== "string" || !Object.hasOwn(NAN_FACT_SOURCES, source)) {
|
|
291
|
+
problems.push(
|
|
292
|
+
`model-facts: ${id}: ${cell} has no provenance source (expected one of ${Object.keys(
|
|
293
|
+
NAN_FACT_SOURCES,
|
|
294
|
+
).join(", ")}, got ${JSON.stringify(source)})`,
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function carriedSource(
|
|
301
|
+
declaredFields: readonly string[],
|
|
302
|
+
field: (typeof CARRIED_OVERRIDE_FIELDS)[number],
|
|
303
|
+
fallback: NanFactSource,
|
|
304
|
+
): NanFactSource {
|
|
305
|
+
return declaredFields.includes(field) ? "override" : fallback;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Build the per-model facts record from generated catalog entries plus the
|
|
310
|
+
* manual declarations. Throws (aggregating every problem) when the catalog and
|
|
311
|
+
* the declarations disagree, when a documented value is outside its union, or
|
|
312
|
+
* when a cell has no provenance — the generator turns that throw into a
|
|
313
|
+
* non-zero exit, so a published catalog can never carry an unsourced cell.
|
|
314
|
+
*/
|
|
315
|
+
export function buildModelFacts(
|
|
316
|
+
entries: readonly GeneratedModelEntry[],
|
|
317
|
+
declarations: ModelFactsDeclarations,
|
|
318
|
+
overrideKeys: Readonly<Record<string, readonly string[]>>,
|
|
319
|
+
meta: ModelFactsBuildMeta,
|
|
320
|
+
): Record<string, NanModelFacts> {
|
|
321
|
+
const problems: string[] = [];
|
|
322
|
+
const entryIds = new Set(entries.map((entry) => entry.id));
|
|
323
|
+
|
|
324
|
+
for (const id of entryIds) {
|
|
325
|
+
if (!Object.hasOwn(declarations, id)) {
|
|
326
|
+
problems.push(`model-facts: ${id}: catalog model has no facts declaration in scripts/model-facts.ts`);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
for (const id of Object.keys(declarations)) {
|
|
330
|
+
if (!entryIds.has(id)) {
|
|
331
|
+
problems.push(`model-facts: ${id}: declared in scripts/model-facts.ts but absent from the catalog`);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const record: Record<string, NanModelFacts> = {};
|
|
336
|
+
for (const entry of [...entries].sort((a, b) => a.id.localeCompare(b.id))) {
|
|
337
|
+
const declaration = declarations[entry.id];
|
|
338
|
+
if (!declaration) continue; // already reported above
|
|
339
|
+
validateDeclaration(entry.id, declaration, problems);
|
|
340
|
+
|
|
341
|
+
const declaredFields = overrideKeys[entry.id] ?? [];
|
|
342
|
+
const provenance: Record<NanFactCell, NanFactSource> = {
|
|
343
|
+
contextWindow: carriedSource(declaredFields, "contextWindow", "models.dev"),
|
|
344
|
+
maxTokens: carriedSource(declaredFields, "maxTokens", "models.dev"),
|
|
345
|
+
input: carriedSource(declaredFields, "input", "models.dev"),
|
|
346
|
+
reasoning: carriedSource(declaredFields, "reasoning", "models.dev"),
|
|
347
|
+
cost: carriedSource(declaredFields, "cost", "catalog-cost"),
|
|
348
|
+
compat: carriedSource(declaredFields, "maxTokensField", entry.compat ? "compat" : "none"),
|
|
349
|
+
reasoningEffortValues: declaredFields.includes("reasoningEffortValues") ? "override" : "none",
|
|
350
|
+
thinkingLevelMap: declaredFields.includes("thinkingLevelMap") ? "override" : "none",
|
|
351
|
+
toolCalling: declaration.sources.toolCalling,
|
|
352
|
+
maxTokensSemantics: declaration.sources.maxTokensSemantics,
|
|
353
|
+
thinkingBudget: declaration.sources.thinkingBudget,
|
|
354
|
+
coldCeilingTokens: declaration.sources.coldCeilingTokens,
|
|
355
|
+
cacheMode: declaration.sources.cacheMode,
|
|
356
|
+
billingClass: declaration.sources.billingClass,
|
|
357
|
+
parallelToolCalls: declaration.sources.parallelToolCalls,
|
|
358
|
+
structuredOutput: declaration.sources.structuredOutput,
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
// An `unmeasured` new-fact cell means "no claim". Sourcing it from a
|
|
362
|
+
// document would read as a claim that the document says so.
|
|
363
|
+
for (const cell of NEW_FACT_CELLS) {
|
|
364
|
+
const value = declaration[cell];
|
|
365
|
+
if (value === "unmeasured" && provenance[cell] !== "none") {
|
|
366
|
+
problems.push(
|
|
367
|
+
`model-facts: ${entry.id}: ${cell} is "unmeasured" but is sourced as ${JSON.stringify(
|
|
368
|
+
provenance[cell],
|
|
369
|
+
)} — an unmeasured cell carries no source`,
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
record[entry.id] = {
|
|
375
|
+
id: entry.id,
|
|
376
|
+
name: entry.name,
|
|
377
|
+
contextWindow: entry.contextWindow,
|
|
378
|
+
maxTokens: entry.maxTokens,
|
|
379
|
+
input: [...entry.input],
|
|
380
|
+
cost: { ...entry.cost },
|
|
381
|
+
reasoning: entry.reasoning,
|
|
382
|
+
reasoningEffortValues: [...(entry.reasoningEffortValues ?? [])],
|
|
383
|
+
thinkingLevelMap: { ...(entry.thinkingLevelMap ?? {}) },
|
|
384
|
+
compat: { ...(entry.compat ?? {}) },
|
|
385
|
+
toolCalling: declaration.toolCalling,
|
|
386
|
+
maxTokensSemantics: declaration.maxTokensSemantics,
|
|
387
|
+
thinkingBudget: declaration.thinkingBudget,
|
|
388
|
+
coldCeilingTokens: declaration.coldCeilingTokens,
|
|
389
|
+
cacheMode: declaration.cacheMode,
|
|
390
|
+
billingClass: declaration.billingClass,
|
|
391
|
+
parallelToolCalls: declaration.parallelToolCalls,
|
|
392
|
+
structuredOutput: declaration.structuredOutput,
|
|
393
|
+
provenance,
|
|
394
|
+
notes: [...(entry.notes ?? [])],
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
if (problems.length > 0) {
|
|
399
|
+
throw new Error(problems.join("\n"));
|
|
400
|
+
}
|
|
401
|
+
if (Object.keys(record).length !== meta.modelCount) {
|
|
402
|
+
throw new Error(
|
|
403
|
+
`model-facts: built ${Object.keys(record).length} entries but the catalog reports ${meta.modelCount}`,
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
return record;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/** Deep-freeze the built record so a consumer cannot mutate another's view. */
|
|
410
|
+
export function freezeModelFacts(
|
|
411
|
+
facts: Record<string, NanModelFacts>,
|
|
412
|
+
): Readonly<Record<string, NanModelFacts>> {
|
|
413
|
+
for (const entry of Object.values(facts)) {
|
|
414
|
+
Object.freeze(entry.cost);
|
|
415
|
+
Object.freeze(entry.compat);
|
|
416
|
+
Object.freeze(entry.input);
|
|
417
|
+
Object.freeze(entry.reasoningEffortValues);
|
|
418
|
+
Object.freeze(entry.thinkingLevelMap);
|
|
419
|
+
Object.freeze(entry.provenance);
|
|
420
|
+
Object.freeze(entry.notes);
|
|
421
|
+
Object.freeze(entry);
|
|
422
|
+
}
|
|
423
|
+
return Object.freeze(facts);
|
|
424
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The public model-facts catalog (issue #47).
|
|
3
|
+
*
|
|
4
|
+
* A frozen, typed record keyed by model id: one entry per billed chat model,
|
|
5
|
+
* facts only — what the model *is* (limits, modalities, cost rates, reasoning
|
|
6
|
+
* contract, tool protocol, `max_tokens` semantics, thinking budget, cache mode,
|
|
7
|
+
* billing class), never how a consumer should batch or route work.
|
|
8
|
+
*
|
|
9
|
+
* Derivation, and why the two-layer contract holds: the record is built from
|
|
10
|
+
* the shipped generated catalog plus the manual facts layer, both of which are
|
|
11
|
+
* baked at publish time. Reading it performs no network call, and it never
|
|
12
|
+
* feeds back into provider registration — the read-time overlay
|
|
13
|
+
* (`withStaleCatalogOverlay`, issue #19) stays the only thing that shapes the
|
|
14
|
+
* pi models a session sees.
|
|
15
|
+
*
|
|
16
|
+
* Every cell is paired with a provenance id; `NAN_MODEL_FACTS_META.sources`
|
|
17
|
+
* resolves it to a citation. The cold-prompt ceiling is the one number that is
|
|
18
|
+
* not per-model by measurement, so it ships as `NAN_ENDPOINT_FACTS` instead.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { GENERATED_CATALOG_META, NAN_GENERATED_MODELS } from "../scripts/models.generated.ts";
|
|
22
|
+
import { MANUAL_OVERRIDES } from "../scripts/manual-overrides.ts";
|
|
23
|
+
import { MODEL_FACTS } from "../scripts/model-facts.ts";
|
|
24
|
+
import {
|
|
25
|
+
buildModelFacts,
|
|
26
|
+
freezeModelFacts,
|
|
27
|
+
NAN_FACT_SOURCES,
|
|
28
|
+
overrideFieldKeys,
|
|
29
|
+
type ModelFactsBuildMeta,
|
|
30
|
+
type NanEndpointFacts,
|
|
31
|
+
type NanModelFacts,
|
|
32
|
+
type NanModelFactsMeta,
|
|
33
|
+
} from "./model-facts-core.ts";
|
|
34
|
+
|
|
35
|
+
const BUILD_META: ModelFactsBuildMeta = {
|
|
36
|
+
source: GENERATED_CATALOG_META.source,
|
|
37
|
+
modelsDevProvider: GENERATED_CATALOG_META.modelsDevProvider,
|
|
38
|
+
fetchedAt: GENERATED_CATALOG_META.fetchedAt,
|
|
39
|
+
modelCount: GENERATED_CATALOG_META.modelCount,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* One entry per billed chat model, keyed by model id, deep-frozen.
|
|
44
|
+
*
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { NAN_MODEL_FACTS } from "@gtrabanco/pi-nan-provider";
|
|
47
|
+
* const facts = NAN_MODEL_FACTS["deepseek-v4-flash"];
|
|
48
|
+
* facts.contextWindow; // 1048576
|
|
49
|
+
* facts.toolCalling; // "openai-tools"
|
|
50
|
+
* facts.maxTokensSemantics // "bounds-total"
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export const NAN_MODEL_FACTS: Readonly<Record<string, NanModelFacts>> = freezeModelFacts(
|
|
54
|
+
buildModelFacts(NAN_GENERATED_MODELS, MODEL_FACTS, overrideFieldKeys(MANUAL_OVERRIDES), BUILD_META),
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The measured cold-prompt ceiling, which is endpoint-wide rather than a model
|
|
59
|
+
* capability: Cloudflare's 120 s proxy read timeout answers HTTP 524 past it,
|
|
60
|
+
* whatever model is called. Use it to size a first cold request; do not read it
|
|
61
|
+
* as a per-model limit (every `coldCeilingTokens` cell stays `"unmeasured"`).
|
|
62
|
+
*/
|
|
63
|
+
export const NAN_ENDPOINT_FACTS: NanEndpointFacts = Object.freeze({
|
|
64
|
+
coldCacheCeilingTokens: 200_000,
|
|
65
|
+
coldCeilingMeasuredAt: "2026-10-01",
|
|
66
|
+
coldCeilingScope:
|
|
67
|
+
"endpoint-wide practical ceiling for cold (uncached) prompts — Cloudflare's 120 s proxy read timeout answers HTTP 524 past it, regardless of model; it is NOT a model capability, so no per-model coldCeilingTokens value is claimed",
|
|
68
|
+
coldCeilingSources:
|
|
69
|
+
"measured 2026-10-01 (issue #18): a cold 208,036-token prompt answered in 12.9 s; ~220,000 and ~286,000 tokens returned HTTP 524 origin_response_timeout at ~126 s. The shipped ceiling is the conservative 200,000 midpoint, not a measured boundary.",
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
/** Build stamp (models.dev fetch date) plus the provenance citation table. */
|
|
73
|
+
export const NAN_MODEL_FACTS_META: NanModelFactsMeta = Object.freeze({
|
|
74
|
+
...BUILD_META,
|
|
75
|
+
sources: NAN_FACT_SOURCES,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
export { NAN_FACT_SOURCES };
|
|
79
|
+
export {
|
|
80
|
+
CARRIED_FACT_CELLS,
|
|
81
|
+
FACT_CELLS,
|
|
82
|
+
NEW_FACT_CELLS,
|
|
83
|
+
type ModelFactsBuildMeta,
|
|
84
|
+
type ModelFactsDeclaration,
|
|
85
|
+
type ModelFactsDeclarations,
|
|
86
|
+
type NanBillingClass,
|
|
87
|
+
type NanCacheMode,
|
|
88
|
+
type NanEndpointFacts,
|
|
89
|
+
type NanFactCell,
|
|
90
|
+
type NanFactSource,
|
|
91
|
+
type NanMaxTokensSemantics,
|
|
92
|
+
type NanModelCostFact,
|
|
93
|
+
type NanModelFacts,
|
|
94
|
+
type NanModelFactsMeta,
|
|
95
|
+
type NanThinkingBudget,
|
|
96
|
+
type NanToolCalling,
|
|
97
|
+
type NanTriState,
|
|
98
|
+
} from "./model-facts-core.ts";
|