@urun-sh/openai 0.6.30 → 0.6.32

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.
Files changed (49) hide show
  1. package/dist/chunk-5473ZAQ4.js +17 -0
  2. package/dist/chunk-7OH7UJ2H.js +60 -0
  3. package/dist/chunk-CAR4AEQJ.js +1 -0
  4. package/dist/{chunk-76BZLCGT.js → chunk-GL7EWL3V.js} +1 -1
  5. package/dist/chunk-KTMDSM7F.js +2 -0
  6. package/dist/chunk-L6HTHDVV.js +1 -0
  7. package/dist/chunk-LM4E5YM2.js +19 -0
  8. package/dist/chunk-M3YMNU5P.js +6 -0
  9. package/dist/chunk-NN6TQQUG.js +1 -0
  10. package/dist/chunk-OOCRI7ZM.js +6 -0
  11. package/dist/chunk-PAYCMH5F.js +1 -0
  12. package/dist/{responses-turn-BGb_XPOa.d.ts → composite-DMawda97.d.ts} +125 -83
  13. package/dist/{responses-turn-DXrwiPJh.d.cts → composite-DtBebn0Y.d.cts} +545 -309
  14. package/dist/gemini-live.cjs +2 -2
  15. package/dist/gemini-live.d.cts +85 -105
  16. package/dist/gemini-live.d.ts +48 -48
  17. package/dist/gemini-live.js +1 -1
  18. package/dist/hosted/bin.cjs +56 -42
  19. package/dist/hosted/bin.js +4 -22
  20. package/dist/hosted/index.cjs +52 -38
  21. package/dist/hosted/index.d.cts +230 -7
  22. package/dist/hosted/index.d.ts +114 -3
  23. package/dist/hosted/index.js +1 -1
  24. package/dist/index.cjs +1 -1
  25. package/dist/index.d.cts +1 -1
  26. package/dist/index.d.ts +1 -1
  27. package/dist/index.js +1 -1
  28. package/dist/{models-DUdx_Y6X.d.cts → models-D7F0bLJ3.d.cts} +14 -0
  29. package/dist/{models-DUdx_Y6X.d.ts → models-D7F0bLJ3.d.ts} +6 -0
  30. package/dist/pi-extension/index.cjs +6 -6
  31. package/dist/pi-extension/index.js +1 -1
  32. package/dist/pi-extension/standalone.cjs +33 -33
  33. package/dist/pooler/bin.cjs +335 -0
  34. package/dist/pooler/bin.js +316 -0
  35. package/dist/proxy/cli.cjs +58 -53
  36. package/dist/proxy/cli.js +1 -1
  37. package/dist/proxy/conformance-probe.cjs +1 -0
  38. package/dist/proxy/conformance-probe.js +1 -0
  39. package/dist/proxy/index.cjs +31 -28
  40. package/dist/proxy/index.d.cts +315 -167
  41. package/dist/proxy/index.d.ts +85 -53
  42. package/dist/proxy/index.js +1 -1
  43. package/package.json +14 -4
  44. package/dist/chunk-55LV3IXW.js +0 -62
  45. package/dist/chunk-7V2JKPIG.js +0 -1
  46. package/dist/chunk-CUDFHFNX.js +0 -4
  47. package/dist/chunk-K23AZPI4.js +0 -1
  48. package/dist/chunk-OPMTYD3Z.js +0 -2
  49. package/dist/chunk-WUNJ3FMI.js +0 -8
@@ -1,29 +1,7 @@
1
- import { C as CatalogRow } from './models-DUdx_Y6X.cjs';
1
+ import { C as CatalogRow } from './models-D7F0bLJ3.cjs';
2
2
  import { IncomingMessage } from 'node:http';
3
3
  import { a as AudioBridge, h as VideoFrameLane, j as VideoOutLane } from './video-out-BsuLqlID.cjs';
4
4
 
5
- /**
6
- * WHAT a proxy serves — the `identity` block on `GET /stats`. Reuse of a
7
- * running proxy is allowed iff every field matches the launching invocation
8
- * EXACTLY: a partial match (same app, different fn; same everything, older
9
- * proxy_version) silently routes the agent at the wrong backend, which is
10
- * worse than any error.
11
- */
12
- interface ProxyIdentity {
13
- app: string;
14
- org: string;
15
- fn: string;
16
- /**
17
- * The control-plane URL the proxy's backhaul session opens against
18
- * (URUN_BASE_URL verbatim — same org/app/fn on staging vs prod are
19
- * DIFFERENT backends; review finding, #285). Compared exactly: a cosmetic
20
- * difference (trailing slash) merely refuses reuse and spawns an ephemeral
21
- * proxy — the safe direction.
22
- */
23
- base_url: string;
24
- proxy_version: string;
25
- }
26
-
27
5
  /**
28
6
  * THE BILLING CORRELATION SEAM — one uuid per `/v1` request, returned as the
29
7
  * `Inference-Id` response header, carried as the suffix of the body id the
@@ -195,90 +173,62 @@ interface InferenceRecord {
195
173
  }
196
174
 
197
175
  /**
198
- * THE SHARED-MODEL LANE (shared-endpoints U8, urun-infra#1490 §7) — the pure
199
- * per-request resolver over the catalog edge function's `shared` block:
200
- *
201
- * { shared_org_id, endpoints: [{ model_id, variant, gpu_spec, app_slug,
202
- * function, warm, ready, ready_runtimes,
203
- * ready_since }],
204
- * regions: [...], compliance: { zdr, hipaa } }
176
+ * THE TURN/TRANSCRIPT LANE over the named §5 `stt` data stream — the
177
+ * engine's OWN transcript source for the OpenAI Realtime transcription
178
+ * intent (ENG-461).
205
179
  *
206
- * Every function here is PURE and synchronous over the parsed block: the
207
- * catalog fetch (U5's edge-function surface) is a separate seam and is NOT
208
- * built yet — a caller hands the block in, or doesn't. An absent/empty
209
- * `shared` block means "no shared models" and every lookup says so (null),
210
- * never a stub.
180
+ * The delivery path is the platform's existing one (urun-python
181
+ * `urun.serve.transcribe_bridge`): the streaming STT engine emits its own
182
+ * transcript events on the session-scoped named stream {@link
183
+ * STT_TRANSCRIPT_STREAM} — the SAME §5 named-DATA mechanism the text-lane
184
+ * token deltas ride, in the text lane's own wire shape (`{"t": kind,
185
+ * "delta": text, "start_ms": int}`). Nothing here invents a framing: the
186
+ * lane is `session.stream('stt').messages()` (core `SessionStream.messages`,
187
+ * contract §5 — the downstream twin of the `emit` produce seam), and this
188
+ * module only DECODES each payload onto the `RealtimeBinding.turns` event
189
+ * shape the realtime adapter already consumes.
211
190
  *
212
- * POSTURE (the two error classes, deliberately distinct):
213
- * - `null` → this model is not in the shared block. The caller
214
- * keeps its own resolution order; on the hosted lane that ends in the
215
- * loud UnknownModelError 404. NOT an error — "not mine" is an answer.
216
- * - `SharedCatalogError` → the block itself is broken (malformed shape, or
217
- * a bare model id whose compat_default flag is not unique). This is a
218
- * platform catalog defect, not a caller mistake: it surfaces as a LOUD
219
- * 500 naming the row, never a silent resolution to "some" variant.
191
+ * `confidence` in the wire payload is SEMANTIC END-OF-TURN confidence (the
192
+ * engine's own VAD verdict that the user finished speaking), NOT
193
+ * transcription confidence — carrying it onto the GA surface would
194
+ * misrepresent it, so the decoder DROPS it by design (the adapter reads the
195
+ * boundary from `turn_end`, which is the same verdict as an event).
220
196
  */
221
- /** One shared endpoint row — the edge function's `endpoints[]` element. */
222
- interface SharedEndpointRow {
223
- model_id: string;
224
- variant: string;
225
- /** The shared org's deployed app slug the session dial targets. */
226
- app_slug: string;
227
- /** The serve function name on that app. */
228
- function: string;
229
- /** PLACEMENT-level GPU spec, e.g. 'rtx6000:1' (mirrors CatalogRow). */
230
- gpu_spec?: string | null;
231
- /** Idle-floor replica count (the reconciler's `warm`, U6). */
232
- warm?: number | null;
233
- /**
234
- * The compat_default flag (U4): a BARE model id resolves to THE flagged
235
- * row. Exactly one per model_id — zero or two is a loud catalog defect.
236
- */
237
- compat_default?: boolean | null;
238
- /**
239
- * The catalog row's output-free opt-in (owner decision 2026-09-21, the
240
- * `reflex-latest:bf16` decision lane): a ZERO per-token OUTPUT rate is a
241
- * deliberate published price for this endpoint — the model is a
242
- * non-generative decision/action surface whose tokens are billed on
243
- * input alone, so the OpenRouter document emits `cost_usd: '0'`
244
- * completion pricing instead of refusing it. Absent (pre-flag edge
245
- * function) and null both mean NOT opted in — the zero-output refusal
246
- * stands.
247
- */
248
- output_free?: boolean | null;
249
- /**
250
- * Runtime-plane readiness (up-debounce, down-immediate upstream). ABSENT
251
- * on blocks from an edge function that predates the readiness seam — the
252
- * OpenRouter document builder treats that as NOT ready, loudly (see
253
- * openrouter-doc.ts); `null` is likewise unknown, not ready.
254
- */
255
- ready?: boolean | null;
256
- /** How many ready runtimes stand behind `ready` (null when unknown). */
257
- ready_runtimes?: number | null;
258
- /** ISO 8601 instant the endpoint became (and stayed) ready; null when not. */
259
- ready_since?: string | null;
197
+
198
+ /** The turn kinds the transcribe bridge emits (TranscriptEvent kinds). */
199
+ type SessionTurnKind = 'delta' | 'final' | 'turn_start' | 'turn_end' | 'turn_eager_end' | 'turn_resumed';
200
+ /**
201
+ * One decoded transcript-lane event — the `RealtimeBinding.turns` event
202
+ * shape. `text` is the wire `delta` field (a transcript PIECE — the adapter
203
+ * accumulates), `startMs` the additive `start_ms` clock. The wire
204
+ * `confidence` (semantic end-of-turn confidence) is deliberately absent.
205
+ */
206
+ interface SessionTurnLaneEvent {
207
+ kind: SessionTurnKind;
208
+ text?: string;
209
+ startMs?: number;
260
210
  }
261
- /** The catalog edge function's `shared` block. */
262
- interface SharedCatalogBlock {
263
- shared_org_id: string;
264
- endpoints: SharedEndpointRow[];
265
- /**
266
- * Deployment-topology region codes (AWS-style, e.g. 'us-west-2') — the
267
- * physical surface the shared endpoints serve from. Absent/empty means the
268
- * topology is undeclared.
269
- */
270
- regions?: string[] | null;
211
+
212
+ /**
213
+ * WHAT a proxy serves — the `identity` block on `GET /stats`. Reuse of a
214
+ * running proxy is allowed iff every field matches the launching invocation
215
+ * EXACTLY: a partial match (same app, different fn; same everything, older
216
+ * proxy_version) silently routes the agent at the wrong backend, which is
217
+ * worse than any error.
218
+ */
219
+ interface ProxyIdentity {
220
+ app: string;
221
+ org: string;
222
+ fn: string;
271
223
  /**
272
- * Operator-declared data-handling posture (zero data retention, HIPAA).
273
- * Present ONLY when an operator has declared BOTH flags — and nothing
274
- * else: the wire contract is exactly {zdr, hipaa}, and the parser treats
275
- * a further key as a catalog defect. ABSENT means UNDECLARED — never a
276
- * default, because these are claims about where customer data goes.
224
+ * The control-plane URL the proxy's backhaul session opens against
225
+ * (URUN_BASE_URL verbatim — same org/app/fn on staging vs prod are
226
+ * DIFFERENT backends; review finding, #285). Compared exactly: a cosmetic
227
+ * difference (trailing slash) merely refuses reuse and spawns an ephemeral
228
+ * proxy — the safe direction.
277
229
  */
278
- compliance?: {
279
- zdr: boolean;
280
- hipaa: boolean;
281
- } | null;
230
+ base_url: string;
231
+ proxy_version: string;
282
232
  }
283
233
 
284
234
  /**
@@ -395,159 +345,102 @@ interface ModelPriceRow {
395
345
  }
396
346
 
397
347
  /**
398
- * THE OPENROUTER PROVIDER DOCUMENT — `GET /partners/openrouter/models`
399
- * (`GET /v1/models?format=openrouter` answers 308 here for one release).
400
- *
401
- * OpenRouter's provider monitor polls this document (schema 2.4, per
402
- * openrouter.ai/docs/guides/community/for-providers §1) to list a provider's
403
- * models on the marketplace. The document answers ONE question: "all models
404
- * that should be served by OpenRouter" — the platform's SELLABLE surface.
405
- * That surface is the catalog edge function's SHARED block (the shared
406
- * endpoints OpenRouter's callers resolve by `model_id:variant` on the chat
407
- * surface); caller-org apps are deliberately NOT in it. A caller-org app is
408
- * a tenancy-private chat surface behind one org's key — declaring it here
409
- * would sell another tenant's private deployment as a public marketplace
410
- * SKU. The document still rides the tenancy seam (`openRouterModels` on the
411
- * tenant client), so each caller sees the same sellable listing.
412
- *
413
- * THE SHARED JOIN: each endpoint joins the catalog EXACTLY on
414
- * (model_id, variant) — the SAME join the shared-lane consumers (supportsAudio,
415
- * modelList's shared arm, imageModelList) already apply. No slug heuristics: the
416
- * shared org's app slug need not exist in
417
- * the caller's catalog, and a slug guess would be a second, bespoke join.
418
- *
419
- * MODALITY GATING: only rows whose catalog `task` names a chat-completions
420
- * shape (chat | code | agent | vl) are declared. A voice/video/image app
421
- * behind a chat surface would stream garbage into OpenRouter's baseline
422
- * tests; models the catalog cannot vouch for are OMITTED, never guessed.
423
- * With no shared block (or no catalog oracle) configured the document is
424
- * `{"data": []}` — honest emptiness, not invented capability.
348
+ * THE SHARED-MODEL LANE (shared-endpoints U8, urun-infra#1490 §7) — the pure
349
+ * per-request resolver over the catalog edge function's `shared` block:
425
350
  *
426
- * PRICING — schema 2.4 nests `pricing` arrays on the modality that owns
427
- * them ({type 'prompt'} on the text INPUT modality, {type 'completion'} on
428
- * the text OUTPUT modality, `cost_usd` a USD string PER TOKEN). The price
429
- * source is model-prices.ts — the SAME per-token join the OpenAI listing
430
- * uses ({@link pricingFor}); the per-million rate is shifted to per-token
431
- * on its decimal string, never by float division. An entry with no
432
- * per-token row — today MOST of them, because `model_prices` prices GPU
433
- * minutes (`per_minute` et al.), which is not evidence about tokens —
434
- * carries NO pricing array at all: the schema's rule is "a modality with
435
- * no pricing array is simply unpriced". Never a zero, never a GPU-minute
436
- * rate relabelled as a token rate (ENG-317 owns the human pricing
437
- * decision that would make such rows exist) — with ONE owner-ratified
438
- * exception: `reflex-latest:bf16` is a non-generative decision lane whose
439
- * catalog row declares `output_free` (owner decision 2026-09-21), so its
440
- * ZERO completion rate is the published price (`cost_usd: '0'`), billed
441
- * on input alone. The zero reaches this builder only through
442
- * model-prices.ts's allowlist (routing resolves prices against the
443
- * shared block's `output_free` set); the builder itself just renders
444
- * whatever a resolved price says.
351
+ * { shared_org_id, endpoints: [{ model_id, variant, gpu_spec, app_slug,
352
+ * app_id, function, warm, ready,
353
+ * ready_runtimes, ready_since }],
354
+ * regions: [...], compliance: { zdr, hipaa } }
445
355
  *
446
- * The full closed-value-domain schema ships as OpenAPI 3.1 at
447
- * openrouter.ai/docs/assets/provider-monitor-schema-v2.openapi.json.
356
+ * Every function here is PURE and synchronous over the parsed block: the
357
+ * catalog fetch (U5's edge-function surface) is a separate seam and is NOT
358
+ * built yet — a caller hands the block in, or doesn't. An absent/empty
359
+ * `shared` block means "no shared models" and every lookup says so (null),
360
+ * never a stub.
448
361
  *
449
- * THE OPERATIONAL FIELDS (schema 2.4, the "launch control" surface):
450
- * - `is_ready` is the shared endpoint's SELLABLE readiness:
451
- * `runtime ready AND priced` — `endpoint.ready === true` AND a per-token
452
- * price row for this exact (model_id, variant). Priced means the price
453
- * book RESOLVES a pair for the SKU: an output-free row's `{input: >0,
454
- * output: 0}` is a resolved pair (model-prices.ts's allowlist decides,
455
- * from the shared block's `output_free` flag), so an input-priced,
456
- * output-free, runtime-ready endpoint IS ready. An unpriced SKU is
457
- * never sellable: OpenRouter's `is_ready: false` keeps an endpoint
458
- * hidden, and we must never expose a model we cannot bill, so a ready
459
- * runtime without a price is emitted NOT ready. Runtime readiness is
460
- * THE ONE DELIBERATELY CONSERVATIVE DEFAULT
461
- * in this module: a block whose endpoints carry NO `ready` field at all
462
- * predates the readiness seam (the catalog edge function is not yet
463
- * redeployed), and UNKNOWN READINESS IS NOT READINESS — every such
464
- * endpoint is declared `is_ready: false` AND one loud warning per
465
- * document build names the missing seam, so the default is visible,
466
- * never silent. A `null` ready is likewise unknown, not ready. Endpoints
467
- * of the SAME identity follow the existing dedup rule (first occurrence
468
- * in the deterministic shared-block order wins).
469
- * - `is_free` is `false` for every declared model: we bill. An unpriced row
470
- * is UNPRICED, not free — `is_free: true` would mint a `:free` SKU whose
471
- * every price OpenRouter ignores. The same holds for an output-free row:
472
- * its input side bills, so it is not a `:free` SKU either — the zero
473
- * lives in the completion `cost_usd`, nowhere else.
474
- * - `deprecation_date` is OMITTED: the schema makes it optional and no
475
- * shared endpoint has a deprecation schedule to declare.
476
- * - `datacenters` maps the block's deployment-topology region codes
477
- * (AWS-style) to the schema's `{ country_code, region }` elements through
478
- * an EXPLICIT region→country table (a country cannot be derived from a
479
- * prefix — sa-east-1 is BR). Unmappable codes are omitted and WARNED,
480
- * never guessed; absent/empty topology omits the field.
481
- * - `compliance` is emitted ONLY when the block's `compliance` is present:
482
- * zdr/hipaa are claims about where customer data goes, DECLARED by an
483
- * operator — never inferred, never defaulted, and never half-emitted.
484
- * - `tokenizer` names the model family the catalog row's `hf_repo`
485
- * carries (e.g. `Inferact/Qwen3.8-27B-NVFP4` → `Qwen`) through an
486
- * explicit, BOUNDED table over the repo's model-NAME tokens — whole
487
- * tokens only, version-aware for the families whose generations differ
488
- * (llama-2 is not llama-3); a repo that names no known family OMITS the
489
- * field.
362
+ * POSTURE (the two error classes, deliberately distinct):
363
+ * - `null` → this model is not in the shared block. The caller
364
+ * keeps its own resolution order; on the hosted lane that ends in the
365
+ * loud UnknownModelError 404. NOT an error — "not mine" is an answer.
366
+ * - `SharedCatalogError` → the block itself is broken (malformed shape, or
367
+ * a bare model id whose compat_default flag is not unique). This is a
368
+ * platform catalog defect, not a caller mistake: it surfaces as a LOUD
369
+ * 500 naming the row, never a silent resolution to "some" variant.
490
370
  */
491
-
492
- type OpenRouterProviderDoc = {
493
- data: OpenRouterProviderModel[];
494
- };
495
- /** One schema-2.4 `datacenters` element: ISO 3166-1 alpha-2 country + region. */
496
- interface OpenRouterDatacenter {
497
- country_code: string;
498
- region?: string;
499
- }
500
- /** The operator-declared data-handling posture (schema-2.4 `compliance`). */
501
- interface OpenRouterCompliance {
502
- zdr: boolean;
503
- hipaa: boolean;
504
- }
505
- interface OpenRouterProviderModel {
506
- schema_version: '2.4';
371
+ /** One shared endpoint row — the edge function's `endpoints[]` element. */
372
+ interface SharedEndpointRow {
373
+ model_id: string;
374
+ variant: string;
375
+ /** The shared org's deployed app slug the session dial targets. */
376
+ app_slug: string;
507
377
  /**
508
- * The EXACT id OpenRouter sends back as `model`: the verbatim
509
- * `<model_id>:<variant>` external identity (see MODEL-IDENTITY.md) — never
510
- * the deployment slug.
378
+ * The SAME app's CANONICAL id (`apps.id`, e.g.
379
+ * `org_01M…_qwen3_8_27b_nvfp4_app`): the shared lane's dispatch pool is
380
+ * named from THIS, never from the slug — slugs hyphenate
381
+ * (`qwen3-8-27b-nvfp4`) while `apps.id` underscores, so a slug-derived
382
+ * pool name is a ghost queue no scheduler drains (ENG-520). ABSENT/null
383
+ * is a pre-seam edge function: the listing tolerates it, and the lane
384
+ * DIAL fails loud on it (laneDispatchPoolOf) rather than guessing a
385
+ * pool. A PRESENT non-string or empty value is a broken row →
386
+ * {@link SharedCatalogError}.
387
+ */
388
+ app_id?: string | null;
389
+ /** The serve function name on that app. */
390
+ function: string;
391
+ /** PLACEMENT-level GPU spec, e.g. 'rtx6000:1' (mirrors CatalogRow). */
392
+ gpu_spec?: string | null;
393
+ /** Idle-floor replica count (the reconciler's `warm`, U6). */
394
+ warm?: number | null;
395
+ /**
396
+ * The compat_default flag (U4): a BARE model id resolves to THE flagged
397
+ * row. Exactly one per model_id — zero or two is a loud catalog defect.
511
398
  */
512
- id: string;
513
- name: string;
514
- created: number;
515
- /** Valid enum: int4|int8|fp4|mxfp4|nvfp4|fp6|fp8|mxfp8|fp16|bf16|fp32|null. */
516
- quantization: string | null;
517
- /** Tokenizer family name (e.g. 'Qwen'); omitted when the repo names none. */
518
- tokenizer?: string;
519
- description: string;
520
- hugging_face_id: string;
521
- /** SELLABLE readiness — `endpoint.ready === true` AND a per-token price. */
522
- is_ready: boolean;
523
- /** `false` always: we bill; an unpriced row is unpriced, not free. */
524
- is_free: boolean;
525
- input_modalities: Array<Record<string, unknown>>;
526
- output_modalities: Array<Record<string, unknown>>;
527
- /** Physical serving topology; omitted when the block declares none. */
528
- datacenters?: OpenRouterDatacenter[];
529
- /** Operator-declared posture; omitted entirely when undeclared. */
530
- compliance?: OpenRouterCompliance;
399
+ compat_default?: boolean | null;
400
+ /**
401
+ * The catalog row's output-free opt-in (owner decision 2026-09-21, the
402
+ * `reflex-latest:bf16` decision lane): a ZERO per-token OUTPUT rate is a
403
+ * deliberate published price for this endpoint — the model is a
404
+ * non-generative decision/action surface whose tokens are billed on
405
+ * input alone, so the OpenRouter document emits `cost_usd: '0'`
406
+ * completion pricing instead of refusing it. Absent (pre-flag edge
407
+ * function) and null both mean NOT opted in — the zero-output refusal
408
+ * stands.
409
+ */
410
+ output_free?: boolean | null;
411
+ /**
412
+ * Runtime-plane readiness (up-debounce, down-immediate upstream). ABSENT
413
+ * on blocks from an edge function that predates the readiness seam — the
414
+ * OpenRouter document builder treats that as NOT ready, loudly (see
415
+ * openrouter-doc.ts); `null` is likewise unknown, not ready.
416
+ */
417
+ ready?: boolean | null;
418
+ /** How many ready runtimes stand behind `ready` (null when unknown). */
419
+ ready_runtimes?: number | null;
420
+ /** ISO 8601 instant the endpoint became (and stayed) ready; null when not. */
421
+ ready_since?: string | null;
531
422
  }
532
- /**
533
- * The resolution of ONE tts model's voice set — ONE answer BOTH consumers
534
- * read, so the lane can never drift from the listing:
535
- * - `published` is the set the model's /v1/models entry carries ([] =
536
- * publish none).
537
- * - `defect` is non-null ONLY when the catalog PRESENTED
538
- * `engine_args.voices` that could not be vouched (empty, malformed, or
539
- * not an identical non-empty string array on every GPU placement). The
540
- * publish side keeps its long-standing posture through a defect (the
541
- * card list for the qwen3 class, nothing otherwise — the listing is a
542
- * best-effort enrichment), but the speech lane must never silently
543
- * validate against the card's nine over a catalog that SPOKE — it fails
544
- * loud (500) on `defect` instead.
545
- */
546
- interface SpeechVoicesResolution {
547
- /** The voices the /v1/models entry publishes for this model ([] = none). */
548
- readonly published: readonly string[];
549
- /** Why the catalog's own voices value could not be vouched, when it presented one. */
550
- readonly defect: string | null;
423
+ /** The catalog edge function's `shared` block. */
424
+ interface SharedCatalogBlock {
425
+ shared_org_id: string;
426
+ endpoints: SharedEndpointRow[];
427
+ /**
428
+ * Deployment-topology region codes (AWS-style, e.g. 'us-west-2') — the
429
+ * physical surface the shared endpoints serve from. Absent/empty means the
430
+ * topology is undeclared.
431
+ */
432
+ regions?: string[] | null;
433
+ /**
434
+ * Operator-declared data-handling posture (zero data retention, HIPAA).
435
+ * Present ONLY when an operator has declared BOTH flags — and nothing
436
+ * else: the wire contract is exactly {zdr, hipaa}, and the parser treats
437
+ * a further key as a catalog defect. ABSENT means UNDECLARED — never a
438
+ * default, because these are claims about where customer data goes.
439
+ */
440
+ compliance?: {
441
+ zdr: boolean;
442
+ hipaa: boolean;
443
+ } | null;
551
444
  }
552
445
 
553
446
  /**
@@ -565,13 +458,21 @@ interface SpeechVoicesResolution {
565
458
  * where slugification mirrors urun-cli `serve.py _default_app_name` exactly:
566
459
  * lowercase, every non-alphanumeric-non-dash character becomes "-", leading/
567
460
  * trailing dashes stripped (catalog id "qwen3.6-27b" + variant "bf16" → app
568
- * "qwen3-6-27b-bf16"). COLLISION RULE: an exact slug match always wins over
569
- * the catalog-id (prefix) interpretation.
461
+ * "qwen3-6-27b-bf16"). COLLISION RULE (within one namespace): an exact slug
462
+ * match always wins over the catalog-id (prefix) interpretation. ACROSS
463
+ * namespaces the SHARED catalog wins: a raw id that names a catalog `shared`
464
+ * model resolves to the shared lane even when the caller's own org deploys an
465
+ * app with a colliding slug (see rule 2).
570
466
  *
571
467
  * RESOLUTION ORDER (one canonical path, documented end to end):
572
468
  * 1. model absent / "urun" / an alias of the startup app → DEFAULT app.
573
- * 2. exact slug match on a deployed app that declares serves="openai" →
574
- * that app.
469
+ * 2. the raw id names a catalog `shared` model — exact id, `id:variant`, or
470
+ * the slugified-equal id form → the SHARED org's app (`sharedApp: true`,
471
+ * the cross-org dial). THIS OUTRANKS the caller-org slug match below:
472
+ * the shared block is the platform namespace every surface advertises, so
473
+ * a caller-org app whose slug collides with a shared model must not
474
+ * shadow it (the pre-2026-10-06 rule let it). ELSEWISE, an exact slug
475
+ * match on a deployed app that declares serves="openai" → that app.
575
476
  * 3. catalog-id form matching exactly one deployed app → that app
576
477
  * (two or more candidates → loud ambiguity error naming them).
577
478
  * 4. the name maps to an org app that has NO function declaring the
@@ -639,7 +540,14 @@ interface RouterModelEntry {
639
540
  id: string;
640
541
  /** OpenAI `Model`: always "model". */
641
542
  object: 'model';
642
- /** OpenAI `Model`: the Unix time the model id first appeared in the uRun catalog (0 until the catalog carries it). */
543
+ /**
544
+ * OpenAI `Model`: the Unix time the model id first appeared in the uRun
545
+ * catalog (openrouter-doc.ts `createdOf` — the catalog's immutable
546
+ * `created_at`, midnight UTC, per model id). `0` is the unjoined
547
+ * exception ONLY: a row with no catalog identity (a custom `--name`
548
+ * deploy) has no appearance date to publish; a catalog-joined row whose
549
+ * `created_at` is missing or drifts fails the listing loudly, never 0.
550
+ */
643
551
  created: number;
644
552
  /** OpenAI `Model`: the organization that owns the model. */
645
553
  owned_by: string;
@@ -701,6 +609,35 @@ interface RouterImageModelList {
701
609
  object: 'list';
702
610
  data: RouterImageModelEntry[];
703
611
  }
612
+ /**
613
+ * A SHARED-lane endpoint's OWN catalog rows — the exact (model_id, variant)
614
+ * the shared block pins, across every GPU placement. The shared block is
615
+ * DERIVED from model_catalog (the catalog edge function joins flagged rows
616
+ * to the shared org's marked apps), so a shared endpoint whose (model_id,
617
+ * variant) has no model_catalog row is a SELF-CONTRADICTORY catalog: a
618
+ * platform defect that fails LOUD (SharedCatalogError → the 500 path),
619
+ * never a silently unvouchable gate or a silently dropped listing entry.
620
+ * Likewise a shared dial on a router with NO catalog oracle configured:
621
+ * capability cannot be vouched from nothing.
622
+ */
623
+ /**
624
+ * THE PER-MODEL SERVING-POOL TUNING (urun-ts#636 option A): the pool
625
+ * parameters one model's catalog row dials, parsed from
626
+ * `engine_args.pool`. Every field optional — absent keeps the deployment's
627
+ * env default.
628
+ */
629
+ interface PoolTuning {
630
+ /** THE WARM FLOOR (owner ruling 2026-10-08: "never fully drains"). */
631
+ min?: number;
632
+ /** Hard slot ceiling. */
633
+ max?: number;
634
+ /** In-flight decisions one attached session carries. */
635
+ in_flight_cap?: number;
636
+ /** Idle duration after which an attached slot above `min` is ended. */
637
+ idle_grace_s?: number;
638
+ /** THE SYNC WARM-WAIT bound for the request path (owner: "how about 20s"). */
639
+ warm_wait_s?: number;
640
+ }
704
641
  /**
705
642
  * The dial target one resolved model names: the app slug plus — for a SHARED
706
643
  * lane (the catalog `shared` block, the cross-org session dial) — the exact
@@ -732,6 +669,21 @@ interface RouteTarget {
732
669
  * pod-org identity cannot drift.
733
670
  */
734
671
  sharedOrgId?: string;
672
+ /**
673
+ * Shared lanes only: the row's PLACEMENT gpu_spec (e.g. `rtx6000:1`) —
674
+ * the lane dispatch pool's shape component comes from it, so the lane
675
+ * demand lands on the scheduler that drains the model's own shape.
676
+ */
677
+ gpuSpec?: string;
678
+ /**
679
+ * Shared lanes only: the shared app's CANONICAL id (`apps.id`) from the
680
+ * SAME block row that resolved the lane. The lane dispatch pool is
681
+ * named from this verbatim (laneDispatchPoolOf) — never from the slug,
682
+ * whose hyphens mint a ghost queue no scheduler drains (ENG-520).
683
+ * Absent on a block from a pre-app_id edge function: the lane DIAL then
684
+ * fails loud rather than guessing a pool.
685
+ */
686
+ appId?: string;
735
687
  }
736
688
  /**
737
689
  * THE BILLING IDENTITY one resolved target carries, in the LEDGER's vocabulary
@@ -857,33 +809,41 @@ interface ModelRouterOptions<S> {
857
809
  * {@link ModelRouter.supportsImages} with no router→lane import).
858
810
  */
859
811
  type ImageCapabilityMode = 'generation' | 'edit';
860
- /**
861
- * The session pool: one backhaul session per deployed app, keyed by app slug,
862
- * opened lazily on the first request that routes to it and reused for every
863
- * subsequent one. The startup app is seeded eagerly by the CLI. Sessions
864
- * close on proxy shutdown via {@link closeAll}; there is NO idle-close policy
865
- * (deliberate v1 simplification — noted as a follow-up in the PR).
866
- */
867
812
  declare class ModelRouter<S> {
868
813
  private readonly opts;
869
814
  private readonly pool;
870
- private appsCache;
871
- private rowsCache;
815
+ /** One STALE-WHILE-REVALIDATE catalog cache slot: `refreshing` dedupes the
816
+ * in-flight background refresh across concurrent expired reads. */
817
+ private apps;
818
+ private rows;
819
+ private shared;
872
820
  constructor(opts: ModelRouterOptions<S>);
821
+ /**
822
+ * STALE-WHILE-REVALIDATE over one cache slot. A cache present but past its
823
+ * TTL serves the STALE entry immediately and refreshes in the BACKGROUND —
824
+ * the request path NEVER awaits the fetch (prod-usw2 2026-10-07: every
825
+ * APPS_TTL_MS expiry parked one `/v1/systemone` decision ~500-600 ms on the
826
+ * catalog fetch, visible as `decision_resolve_ms` spans). Concurrent expired
827
+ * reads dedupe onto the same in-flight refresh. Only a COLD cache (nothing
828
+ * stale to serve) awaits the fetch. A FAILED refresh keeps the stale entry —
829
+ * the next expired read retries.
830
+ */
831
+ private swr;
873
832
  /** Seed an already-open session (the CLI's eagerly-opened startup app). */
874
833
  seed(appSlug: string, entry: S): void;
875
834
  private deployedApps;
876
835
  /**
877
- * The shared block with the same TTL discipline as {@link deployedApps}.
878
- * Null when not configured. Malformed blocks throw loudly
879
- * (SharedCatalogError) on first use — never a silently half-empty table.
836
+ * The shared block with the same stale-while-revalidate discipline as
837
+ * {@link deployedApps}. Null when not configured. Malformed blocks throw
838
+ * loudly (SharedCatalogError) on first use — never a silently half-empty
839
+ * table.
880
840
  */
881
841
  private sharedBlock;
882
- private sharedCache;
883
842
  /**
884
- * Catalog rows with the same TTL discipline as {@link deployedApps} (the
885
- * catalog changes on reseed migrations, not per request). Null when no
886
- * oracle is configured — callers degrade to the bare four-field entries.
843
+ * Catalog rows with the same stale-while-revalidate discipline as
844
+ * {@link deployedApps} (the catalog changes on reseed migrations, not per
845
+ * request). Null when no oracle is configured — callers degrade to the bare
846
+ * four-field entries.
887
847
  */
888
848
  private catalogRows;
889
849
  private pricesCache;
@@ -963,6 +923,30 @@ declare class ModelRouter<S> {
963
923
  * Never returns.
964
924
  */
965
925
  private noDefaultApp;
926
+ /**
927
+ * Resolve the raw `model` against the catalog `shared` block — the
928
+ * PLATFORM's model namespace. Null when shared routing is off, the block is
929
+ * absent, or the id names no shared endpoint.
930
+ *
931
+ * Matches the raw id in the three caller-typing forms the module header
932
+ * documents: the exact `model_id`, the exact `model_id:variant` pin, and
933
+ * the SLUGIFIED-equal id (the slug surface mirrors urun-cli
934
+ * `_default_app_name`, so `qwen-qwen3-8b` names catalog id `Qwen/Qwen3-8B`).
935
+ * `resolveSharedModel` is exact-string by design (the block is the
936
+ * platform's canonical naming); the slug form is the router's, so
937
+ * canonicalise to the model_id and let it pin/derive the variant.
938
+ *
939
+ * OUTAGE POLICY. A shared-catalog READ or PARSE failure (SharedCatalogError,
940
+ * or a transport rejection) propagates to the loud-500 path — it is NEVER
941
+ * swallowed into "no shared match". The shared block is AUTHORITATIVE for
942
+ * id resolution, so guessing "not shared" while the catalog is unreadable
943
+ * would silently reintroduce the very shadowing this precedence removes
944
+ * (bare `sense` falling back to a caller-org app). The alternative — a
945
+ * last-known-good block — is an availability policy the owner has not
946
+ * adopted; it would also change the /v1/models listing's shared arm, so it
947
+ * is deliberately out of scope here.
948
+ */
949
+ private sharedLane;
966
950
  /**
967
951
  * Resolve a request's `model` to its dial target — the documented
968
952
  * resolution order from the module header. Throws
@@ -1001,6 +985,30 @@ declare class ModelRouter<S> {
1001
985
  model_id: string;
1002
986
  variant: string;
1003
987
  } | null>;
988
+ /**
989
+ * THE PER-MODEL SERVING-POOL TUNING (urun-ts#636 option A, owner ruling
990
+ * 2026-10-08: "configurable in their rows in supabase, periodically synced
991
+ * to valkey and looked up there, and we should dial these numbers in per
992
+ * model"): the serving-pool parameters live on the model's OWN catalog row
993
+ * under `engine_args.pool` — the same per-model dial surface as
994
+ * `engine_args.voices`/`realtime`/`context_length`, flowing Supabase → the
995
+ * catalog publisher → the Valkey mirror on the existing cadence (no new
996
+ * sync lane, no proxy restart). The proxy looks the numbers up HERE, on
997
+ * the SAME stale-while-revalidate cached rows every other capability join
998
+ * rides.
999
+ *
1000
+ * Shape: `{ min, max, in_flight_cap, idle_grace_s, warm_wait_s }` — every
1001
+ * field OPTIONAL; a missing field keeps the deployment's env default.
1002
+ * GARBAGE IS LOUD: one malformed value skips the model's WHOLE pool block
1003
+ * (null → the caller applies the env defaults) with a stderr notice — the
1004
+ * same posture `createValkeyCatalog` takes on a malformed row — never a
1005
+ * silent partial parse.
1006
+ *
1007
+ * Row join: the shared lane's pinned `(model_id, variant)` when the target
1008
+ * carries one; otherwise the app slug joins the row's `serve_app_slug`
1009
+ * arm (the PR421 rowForSlug join). No row ⇒ null (env defaults).
1010
+ */
1011
+ poolTuningFor(target: RouteTarget): Promise<PoolTuning | null>;
1004
1012
  /**
1005
1013
  * THE CALLER-ORG APP LANE's OWN IDENTITY (ENG-412) — the app slug this
1006
1014
  * request actually resolves to.
@@ -1200,8 +1208,10 @@ declare class ModelRouter<S> {
1200
1208
  supportsImages(model: string | undefined, mode: ImageCapabilityMode): Promise<boolean>;
1201
1209
  /**
1202
1210
  * AUDIO MODALITY GATE (the OpenAI Realtime lane's modality oracle): does
1203
- * `model`'s deployed app carry catalog `task` stt or tts — INVARIANTLY
1204
- * across every GPU-placement row ({@link audioModalityForRows})? The SAME
1211
+ * `model`'s deployed app carry an audio modality — catalog `task` stt or
1212
+ * tts, or the EXPLICIT `engine_args.realtime === true` vouch that admits a
1213
+ * decision model on the realtime lane ({@link audioModalityForRows}) —
1214
+ * INVARIANTLY across every GPU-placement row? The SAME
1205
1215
  * shape as {@link supportsImages}: authorized resolution
1206
1216
  * ({@link resolveTarget} — undeployed uRun models throw
1207
1217
  * {@link UnknownModelError}), then the SAME catalog join
@@ -1210,7 +1220,10 @@ declare class ModelRouter<S> {
1210
1220
  *
1211
1221
  * A SHARED-lane hit joins on the lane's catalog id + variant (the SAME
1212
1222
  * join {@link imageModelList} uses for the shared block) — the shared org's
1213
- * app slug need not exist in the caller's own catalog by slug.
1223
+ * app slug need not exist in the caller's own catalog by slug. An APP dial
1224
+ * joins {@link audioRowsForTarget}: the slug join first, then the row's
1225
+ * `serve_app_slug` override (an app-backed row's model id is not the app's
1226
+ * dial name — `sense` serves `sense-latest`).
1214
1227
  *
1215
1228
  * A CONFIGURED catalog oracle that FAILS propagates its rejection — the
1216
1229
  * gate never fabricates a `false` out of an infrastructure outage. No
@@ -1259,7 +1272,7 @@ declare class ModelRouter<S> {
1259
1272
  * the platform's {@link STT_TRANSCRIPT_STREAM} when no row carries the
1260
1273
  * field, over the SAME catalog join {@link supportsTranscription} uses
1261
1274
  * (exact `(model_id, variant)` for a shared-lane hit,
1262
- * {@link catalogRowsForSlug} for a caller-org app). Deliberately NOT
1275
+ * {@link audioRowsForTarget} for a caller-org app). Deliberately NOT
1263
1276
  * task-gated: the binding consults it only behind a `transcribes` verdict,
1264
1277
  * and the resolution itself is a pure field consensus. The lane's consume
1265
1278
  * side reads the PLATFORM DEFAULT only — a row that OVERRIDES the default
@@ -1277,8 +1290,11 @@ declare class ModelRouter<S> {
1277
1290
  * listing's enrichment applies (openrouter-doc.ts `speechVoicesFor`, via
1278
1291
  * {@link speechVoicesForMatches}) over the SAME catalog join
1279
1292
  * {@link supportsSpeech} uses (exact `(model_id, variant)` for a
1280
- * shared-lane hit, {@link catalogRowsForSlug} for a caller-org app), so
1281
- * the lane enforces exactly ONE list: the one the listing publishes — the
1293
+ * shared-lane hit, {@link audioRowsForTarget} for a caller-org app), so
1294
+ * the lane enforces exactly ONE list: the one the listing publishes —
1295
+ * the enrichment's `rowForSlug` joins the SAME app-backed arm
1296
+ * ({@link appBackedRowsForSlug}), so an APP-BACKED tts row publishes its
1297
+ * voices under the app dial the lane enforces them on — the
1282
1298
  * catalog-vouched `engine_args.voices`, else the qwen3 CustomVoice card's
1283
1299
  * nine for that one model class. A catalog that PRESENTS a voices value
1284
1300
  * it cannot vouch answers WITH the defect set on the resolution — the
@@ -1307,7 +1323,10 @@ declare class ModelRouter<S> {
1307
1323
  * the model surface — the audio twin of {@link imageModelList}: the
1308
1324
  * caller-org deployed apps whose catalog rows vouch `stt`
1309
1325
  * ({@link audioModalityForRows} answering exactly `'stt'`, the SAME
1310
- * consensus {@link supportsTranscription} applies), plus the shared block's
1326
+ * consensus AND the SAME join {@link supportsTranscription} applies —
1327
+ * {@link audioRowsForAppSlug}, so an APP-BACKED stt row whose
1328
+ * `serve_app_slug` names the app is listed exactly when the gate admits
1329
+ * it), plus the shared block's
1311
1330
  * endpoints joined against each endpoint's OWN catalog row (exact model_id +
1312
1331
  * variant; a definite non-stt task is simply skipped, never a loud defect —
1313
1332
  * the task column IS the vouch, there is no expects_image-style flag to
@@ -1322,40 +1341,159 @@ declare class ModelRouter<S> {
1322
1341
  }
1323
1342
 
1324
1343
  /**
1325
- * THE TURN/TRANSCRIPT LANE over the named §5 `stt` data stream — the
1326
- * engine's OWN transcript source for the OpenAI Realtime transcription
1327
- * intent (ENG-461).
1344
+ * THE OPENROUTER PROVIDER DOCUMENT — `GET /partners/openrouter/models`
1345
+ * (`GET /v1/models?format=openrouter` answers 308 here for one release).
1328
1346
  *
1329
- * The delivery path is the platform's existing one (urun-python
1330
- * `urun.serve.transcribe_bridge`): the streaming STT engine emits its own
1331
- * transcript events on the session-scoped named stream {@link
1332
- * STT_TRANSCRIPT_STREAM} — the SAME §5 named-DATA mechanism the text-lane
1333
- * token deltas ride, in the text lane's own wire shape (`{"t": kind,
1334
- * "delta": text, "start_ms": int}`). Nothing here invents a framing: the
1335
- * lane is `session.stream('stt').messages()` (core `SessionStream.messages`,
1336
- * contract §5 — the downstream twin of the `emit` produce seam), and this
1337
- * module only DECODES each payload onto the `RealtimeBinding.turns` event
1338
- * shape the realtime adapter already consumes.
1347
+ * OpenRouter's provider monitor polls this document (schema 2.4, per
1348
+ * openrouter.ai/docs/guides/community/for-providers §1) to list a provider's
1349
+ * models on the marketplace. The document answers ONE question: "all models
1350
+ * that should be served by OpenRouter" — the platform's SELLABLE surface.
1351
+ * That surface is the catalog edge function's SHARED block (the shared
1352
+ * endpoints OpenRouter's callers resolve by `model_id:variant` on the chat
1353
+ * surface); caller-org apps are deliberately NOT in it. A caller-org app is
1354
+ * a tenancy-private chat surface behind one org's key — declaring it here
1355
+ * would sell another tenant's private deployment as a public marketplace
1356
+ * SKU. The document still rides the tenancy seam (`openRouterModels` on the
1357
+ * tenant client), so each caller sees the same sellable listing.
1339
1358
  *
1340
- * `confidence` in the wire payload is SEMANTIC END-OF-TURN confidence (the
1341
- * engine's own VAD verdict that the user finished speaking), NOT
1342
- * transcription confidence — carrying it onto the GA surface would
1343
- * misrepresent it, so the decoder DROPS it by design (the adapter reads the
1344
- * boundary from `turn_end`, which is the same verdict as an event).
1359
+ * THE SHARED JOIN: each endpoint joins the catalog EXACTLY on
1360
+ * (model_id, variant) — the SAME join the shared-lane consumers (supportsAudio,
1361
+ * modelList's shared arm, imageModelList) already apply. No slug heuristics: the
1362
+ * shared org's app slug need not exist in
1363
+ * the caller's catalog, and a slug guess would be a second, bespoke join.
1364
+ *
1365
+ * MODALITY GATING: only rows whose catalog `task` names a chat-completions
1366
+ * shape (chat | code | agent | vl) are declared. A voice/video/image app
1367
+ * behind a chat surface would stream garbage into OpenRouter's baseline
1368
+ * tests; models the catalog cannot vouch for are OMITTED, never guessed.
1369
+ * With no shared block (or no catalog oracle) configured the document is
1370
+ * `{"data": []}` — honest emptiness, not invented capability.
1371
+ *
1372
+ * PRICING — schema 2.4 nests `pricing` arrays on the modality that owns
1373
+ * them ({type 'prompt'} on the text INPUT modality, {type 'completion'} on
1374
+ * the text OUTPUT modality, `cost_usd` a USD string PER TOKEN). The price
1375
+ * source is model-prices.ts — the SAME per-token join the OpenAI listing
1376
+ * uses ({@link pricingFor}); the per-million rate is shifted to per-token
1377
+ * on its decimal string, never by float division. An entry with no
1378
+ * per-token row — today MOST of them, because `model_prices` prices GPU
1379
+ * minutes (`per_minute` et al.), which is not evidence about tokens —
1380
+ * carries NO pricing array at all: the schema's rule is "a modality with
1381
+ * no pricing array is simply unpriced". Never a zero, never a GPU-minute
1382
+ * rate relabelled as a token rate (ENG-317 owns the human pricing
1383
+ * decision that would make such rows exist) — with ONE owner-ratified
1384
+ * exception: `reflex-latest:bf16` is a non-generative decision lane whose
1385
+ * catalog row declares `output_free` (owner decision 2026-09-21), so its
1386
+ * ZERO completion rate is the published price (`cost_usd: '0'`), billed
1387
+ * on input alone. The zero reaches this builder only through
1388
+ * model-prices.ts's allowlist (routing resolves prices against the
1389
+ * shared block's `output_free` set); the builder itself just renders
1390
+ * whatever a resolved price says.
1391
+ *
1392
+ * The full closed-value-domain schema ships as OpenAPI 3.1 at
1393
+ * openrouter.ai/docs/assets/provider-monitor-schema-v2.openapi.json.
1394
+ *
1395
+ * THE OPERATIONAL FIELDS (schema 2.4, the "launch control" surface):
1396
+ * - `is_ready` is the shared endpoint's SELLABLE readiness:
1397
+ * `runtime ready AND priced` — `endpoint.ready === true` AND a per-token
1398
+ * price row for this exact (model_id, variant). Priced means the price
1399
+ * book RESOLVES a pair for the SKU: an output-free row's `{input: >0,
1400
+ * output: 0}` is a resolved pair (model-prices.ts's allowlist decides,
1401
+ * from the shared block's `output_free` flag), so an input-priced,
1402
+ * output-free, runtime-ready endpoint IS ready. An unpriced SKU is
1403
+ * never sellable: OpenRouter's `is_ready: false` keeps an endpoint
1404
+ * hidden, and we must never expose a model we cannot bill, so a ready
1405
+ * runtime without a price is emitted NOT ready. Runtime readiness is
1406
+ * THE ONE DELIBERATELY CONSERVATIVE DEFAULT
1407
+ * in this module: a block whose endpoints carry NO `ready` field at all
1408
+ * predates the readiness seam (the catalog edge function is not yet
1409
+ * redeployed), and UNKNOWN READINESS IS NOT READINESS — every such
1410
+ * endpoint is declared `is_ready: false` AND one loud warning per
1411
+ * document build names the missing seam, so the default is visible,
1412
+ * never silent. A `null` ready is likewise unknown, not ready. Endpoints
1413
+ * of the SAME identity follow the existing dedup rule (first occurrence
1414
+ * in the deterministic shared-block order wins).
1415
+ * - `is_free` is `false` for every declared model: we bill. An unpriced row
1416
+ * is UNPRICED, not free — `is_free: true` would mint a `:free` SKU whose
1417
+ * every price OpenRouter ignores. The same holds for an output-free row:
1418
+ * its input side bills, so it is not a `:free` SKU either — the zero
1419
+ * lives in the completion `cost_usd`, nowhere else.
1420
+ * - `deprecation_date` is OMITTED: the schema makes it optional and no
1421
+ * shared endpoint has a deprecation schedule to declare.
1422
+ * - `datacenters` maps the block's deployment-topology region codes
1423
+ * (AWS-style) to the schema's `{ country_code, region }` elements through
1424
+ * an EXPLICIT region→country table (a country cannot be derived from a
1425
+ * prefix — sa-east-1 is BR). Unmappable codes are omitted and WARNED,
1426
+ * never guessed; absent/empty topology omits the field.
1427
+ * - `compliance` is emitted ONLY when the block's `compliance` is present:
1428
+ * zdr/hipaa are claims about where customer data goes, DECLARED by an
1429
+ * operator — never inferred, never defaulted, and never half-emitted.
1430
+ * - `tokenizer` names the model family the catalog row's `hf_repo`
1431
+ * carries (e.g. `Inferact/Qwen3.8-27B-NVFP4` → `Qwen`) through an
1432
+ * explicit, BOUNDED table over the repo's model-NAME tokens — whole
1433
+ * tokens only, version-aware for the families whose generations differ
1434
+ * (llama-2 is not llama-3); a repo that names no known family OMITS the
1435
+ * field.
1345
1436
  */
1346
1437
 
1347
- /** The turn kinds the transcribe bridge emits (TranscriptEvent kinds). */
1348
- type SessionTurnKind = 'delta' | 'final' | 'turn_start' | 'turn_end' | 'turn_eager_end' | 'turn_resumed';
1438
+ type OpenRouterProviderDoc = {
1439
+ data: OpenRouterProviderModel[];
1440
+ };
1441
+ /** One schema-2.4 `datacenters` element: ISO 3166-1 alpha-2 country + region. */
1442
+ interface OpenRouterDatacenter {
1443
+ country_code: string;
1444
+ region?: string;
1445
+ }
1446
+ /** The operator-declared data-handling posture (schema-2.4 `compliance`). */
1447
+ interface OpenRouterCompliance {
1448
+ zdr: boolean;
1449
+ hipaa: boolean;
1450
+ }
1451
+ interface OpenRouterProviderModel {
1452
+ schema_version: '2.4';
1453
+ /**
1454
+ * The EXACT id OpenRouter sends back as `model`: the verbatim
1455
+ * `<model_id>:<variant>` external identity (see MODEL-IDENTITY.md) — never
1456
+ * the deployment slug.
1457
+ */
1458
+ id: string;
1459
+ name: string;
1460
+ created: number;
1461
+ /** Valid enum: int4|int8|fp4|mxfp4|nvfp4|fp6|fp8|mxfp8|fp16|bf16|fp32|null. */
1462
+ quantization: string | null;
1463
+ /** Tokenizer family name (e.g. 'Qwen'); omitted when the repo names none. */
1464
+ tokenizer?: string;
1465
+ description: string;
1466
+ hugging_face_id: string;
1467
+ /** SELLABLE readiness — `endpoint.ready === true` AND a per-token price. */
1468
+ is_ready: boolean;
1469
+ /** `false` always: we bill; an unpriced row is unpriced, not free. */
1470
+ is_free: boolean;
1471
+ input_modalities: Array<Record<string, unknown>>;
1472
+ output_modalities: Array<Record<string, unknown>>;
1473
+ /** Physical serving topology; omitted when the block declares none. */
1474
+ datacenters?: OpenRouterDatacenter[];
1475
+ /** Operator-declared posture; omitted entirely when undeclared. */
1476
+ compliance?: OpenRouterCompliance;
1477
+ }
1349
1478
  /**
1350
- * One decoded transcript-lane event — the `RealtimeBinding.turns` event
1351
- * shape. `text` is the wire `delta` field (a transcript PIECE — the adapter
1352
- * accumulates), `startMs` the additive `start_ms` clock. The wire
1353
- * `confidence` (semantic end-of-turn confidence) is deliberately absent.
1479
+ * The resolution of ONE tts model's voice set — ONE answer BOTH consumers
1480
+ * read, so the lane can never drift from the listing:
1481
+ * - `published` is the set the model's /v1/models entry carries ([] =
1482
+ * publish none).
1483
+ * - `defect` is non-null ONLY when the catalog PRESENTED
1484
+ * `engine_args.voices` that could not be vouched (empty, malformed, or
1485
+ * not an identical non-empty string array on every GPU placement). The
1486
+ * publish side keeps its long-standing posture through a defect (the
1487
+ * card list for the qwen3 class, nothing otherwise — the listing is a
1488
+ * best-effort enrichment), but the speech lane must never silently
1489
+ * validate against the card's nine over a catalog that SPOKE — it fails
1490
+ * loud (500) on `defect` instead.
1354
1491
  */
1355
- interface SessionTurnLaneEvent {
1356
- kind: SessionTurnKind;
1357
- text?: string;
1358
- startMs?: number;
1492
+ interface SpeechVoicesResolution {
1493
+ /** The voices the /v1/models entry publishes for this model ([] = none). */
1494
+ readonly published: readonly string[];
1495
+ /** Why the catalog's own voices value could not be vouched, when it presented one. */
1496
+ readonly defect: string | null;
1359
1497
  }
1360
1498
 
1361
1499
  /**
@@ -2154,6 +2292,19 @@ interface ProxyClients {
2154
2292
  * transcribe.
2155
2293
  */
2156
2294
  supportsTranscription?(model: string | undefined): Promise<boolean>;
2295
+ /**
2296
+ * THE COMPOSITE REALTIME LANE'S PAIRING SEAM (ENG-451,
2297
+ * openai-realtime/composite.ts): for a CHAT-row `model`, the pinned
2298
+ * `{stt, tts, voice?}` trio that makes it realtime-capable — or `null`
2299
+ * when it is not (the realtime lane's 404, unchanged). The PRODUCTION
2300
+ * source of the pairing (catalog field vs proxy config) is an open owner
2301
+ * decision: BOTH compositions wire this seam from a constructor option,
2302
+ * and an unconfigured source answers `null`, so behaviour on main is
2303
+ * unchanged. Optional at the seam exactly like {@link supportsTranscription}:
2304
+ * a hand-built client that wires none behaves exactly like `null` — the
2305
+ * lane NEVER invents a default pairing.
2306
+ */
2307
+ realtimeCompanionsFor?(model: string | undefined): Promise<RealtimeCompanions | null>;
2157
2308
  /**
2158
2309
  * THE SPEECH LANE'S VOICE-SET RESOLUTION (proxy/speech.ts): the voices
2159
2310
  * `/v1/models` publishes for `model` (ModelRouter.speechVoices — the SAME
@@ -2289,7 +2440,7 @@ interface ProxyClients {
2289
2440
  * one of several waiters aborting rejects only that caller's open, the
2290
2441
  * queued admission going back only at the LAST waiter's abort.
2291
2442
  */
2292
- openAudioOn?(handle: string, signal?: AbortSignal): Promise<PinnedAudioLane>;
2443
+ openAudioOn?(handle: string, signal?: AbortSignal, connectionTag?: string): Promise<PinnedAudioLane>;
2293
2444
  /**
2294
2445
  * THE TURN/TRANSCRIPT LANE OPEN (the realtime transcription intent,
2295
2446
  * ENG-461): the STT engine's OWN transcript events — the §5 `stt` named
@@ -2355,11 +2506,15 @@ interface ProxyClients {
2355
2506
  openVideoOut?(model: string | undefined): Promise<ProxyVideoOutLane>;
2356
2507
  /**
2357
2508
  * SESSION-IDENTITY SEAM (ModelRouter.handleFor): the opaque stable handle
2358
- * for the pooled session currently serving `model`'s turns. Derived from
2359
- * native identity (app slug + uRun session id) — the same identity the
2360
- * serve-side session-affinity tag rides (urun-python#1556/#1582).
2509
+ * for the session currently serving `model`'s turns. Derived from native
2510
+ * identity (app slug + uRun session id) — the same identity the serve-side
2511
+ * session-affinity tag rides (urun-python#1556/#1582). A SHARED model with
2512
+ * lane pools answers a LANE handle (the lane the req/resp path also rides)
2513
+ * whose pick lease lives until {@link releaseSessionHandle}.
2361
2514
  */
2362
2515
  sessionHandle(model: string | undefined): Promise<string>;
2516
+ /** Release the lease {@link sessionHandle} took on a lane; a no-op for a pooled handle. */
2517
+ releaseSessionHandle?(handle: string): void;
2363
2518
  /**
2364
2519
  * THE SPEECH LANE'S OWN HANDLE (greptile urun-ts#500): the opaque handle
2365
2520
  * for the SPEECH-SCOPED pooled session (`speech:<pool key>` — routing.ts
@@ -2399,7 +2554,17 @@ interface ProxyClients {
2399
2554
  * while claiming resume. Deliberately NO re-home on this path: re-homing
2400
2555
  * would swap the pinned session out from under the caller.
2401
2556
  */
2402
- createResponseOn(handle: string, params: ResponsesCreateParams): Promise<AsyncIterable<unknown>> | AsyncIterable<unknown>;
2557
+ createResponseOn(handle: string, params: ResponsesCreateParams,
2558
+ /**
2559
+ * PER-CONNECTION CONSUMER IDENTITY (the lane audio plane): the realtime
2560
+ * connection's tag (binding.ts mints one per connection). On a LANE
2561
+ * handle the request envelope's `consumer_id` carries this tag instead
2562
+ * of the lane default `lane-<laneId>` — the SAME tag the connection's
2563
+ * audio frames carry in their `c` field (lane-audio.ts), so the runtime
2564
+ * routes each connection's responses and audio to its own state. A
2565
+ * pooled (non-lane) handle or an absent tag is unchanged.
2566
+ */
2567
+ connectionTag?: string): Promise<AsyncIterable<unknown>> | AsyncIterable<unknown>;
2403
2568
  /**
2404
2569
  * Subscribe to the pinned session's terminal end via core's NATIVE phase
2405
2570
  * machinery (Session.onPhase → terminal 'expired'/'ended'/'error'). Fires
@@ -2479,11 +2644,19 @@ interface ProxyHandlerOptions {
2479
2644
  * 500. The hosted server uses it to turn its auth/tenancy failures into a
2480
2645
  * 401 in the OpenAI envelope. Returning null means "not mine" — the error
2481
2646
  * takes the ordinary loud 500 path.
2647
+ *
2648
+ * `operatorDetail`, when present, is evidence the CALLER must not see but
2649
+ * the operator log must keep (the caller-message boundary's rule: withheld,
2650
+ * never dropped) — e.g. the control-plane gateway URL and underlying
2651
+ * failure text behind an authored 502 line. The classified relay branches
2652
+ * log it to the operator sink while the caller sees the error's own
2653
+ * authored `message`.
2482
2654
  */
2483
2655
  statusOf?: (err: unknown) => {
2484
2656
  status: number;
2485
2657
  openaiType: string;
2486
2658
  anthropicType: string;
2659
+ operatorDetail?: string;
2487
2660
  } | null;
2488
2661
  /**
2489
2662
  * Where the per-request structured log line goes — ONE newline-terminated
@@ -2502,6 +2675,15 @@ interface ProxyHandlerOptions {
2502
2675
  * without racing the process streams.
2503
2676
  */
2504
2677
  requestLog?: (line: string) => void;
2678
+ /**
2679
+ * THE OPERATOR ERROR SINK (ENG-538, caller-messages.ts): one plain line per
2680
+ * error the caller-message boundary projects — the internal detail it
2681
+ * withheld from a caller-facing response, kept diagnosable. Absent, the line
2682
+ * goes to this process's stderr (`console.error`), which is the hosted
2683
+ * container's collected log stream; injectable so tests assert the withheld
2684
+ * text without racing the process streams.
2685
+ */
2686
+ operatorLog?: (line: string) => void;
2505
2687
  /**
2506
2688
  * THE CANONICAL USAGE-QUERY SEAM (`POST /v1/usage/requests`, and the
2507
2689
  * Hugging Face translator over it) — a batch lookup of what the per-request
@@ -2544,4 +2726,58 @@ interface ProxyHandlerOptions {
2544
2726
  observe?: (record: InferenceRecord) => void;
2545
2727
  }
2546
2728
 
2547
- export { type DialObserver as D, type InferenceRecord as I, type LedgerFailure as L, ModelRouter as M, type ProxyClients as P, SessionGoneError as S, UnknownModelError as U, type DialReport as a, type InferenceUsageRecord as b, type LedgerOutcome as c, type LedgerRecorded as d, type LedgerWrite as e, type ProxyHandlerOptions as f, type ProxyIdentity as g, type ProxyVideoOutLane as h, type UsageRowReporter as i, billingIdentityOf as j };
2729
+ /**
2730
+ * THE COMPOSITE REALTIME LANE (ENG-451) — Pipecat's stock
2731
+ * `OpenAIRealtimeLLMService` points at `wss://<host>/v1/realtime?model=<chat
2732
+ * model>` with `turn_detection: null`: it appends audio, commits, sends
2733
+ * `response.create`, and expects ONE spoken answer. A chat row cannot serve
2734
+ * that alone — this module makes it work by composing THREE pooled sessions
2735
+ * per connection, every leg PINNED to the handle it resolved ONCE (the
2736
+ * ENG-446 pin, per leg):
2737
+ *
2738
+ * - the `stt` companion: the user's audio in (its own audio bridge) and the
2739
+ * engine's own transcript lane (the §5 `stt` stream), wired onto
2740
+ * `RealtimeBinding.turns` exactly as a transcription session does;
2741
+ * - the bound chat row: every model turn (`createResponseOn(chatHandle, …)`)
2742
+ * over the connection's serialized items — user transcripts, assistant
2743
+ * text, tool calls and outputs;
2744
+ * - the `tts` companion: the synthesized audio OUT (its own audio bridge
2745
+ * is the composed bridge's OUT side) plus one synthesis turn per flushed
2746
+ * sentence chunk, so audio starts speaking BEFORE the chat turn ends.
2747
+ *
2748
+ * The PAIRING (which stt/tts rows + voice speak for which chat model) is an
2749
+ * OWNED CONFIGURATION decision, not a guess this module makes: it arrives
2750
+ * through the `realtimeCompanionsFor` seam ({@link RealtimeCompanionsFor}),
2751
+ * wired by BOTH compositions from a constructor option. A seam that answers
2752
+ * `null` — or an absent seam — is today's loud 404, unchanged: the lane NEVER
2753
+ * invents a default pairing.
2754
+ *
2755
+ * FAILURE IS LOUD, per leg: a dead or re-homed leg is rethrown as a
2756
+ * {@link SessionGoneError} NAMING the leg (the connection's `session_gone`
2757
+ * close carries the name), never a silent skip of that leg. Barge-in stops
2758
+ * the chat read AND the tts queue promptly through the turn signal the
2759
+ * connection threads into `clients.createResponse(params, signal)`.
2760
+ */
2761
+
2762
+ /**
2763
+ * The pinned trio a realtime-capable chat model composes: the `stt` row that
2764
+ * transcribes the user's audio, the `tts` row that speaks the chat row's
2765
+ * answer, and the optional synthesis voice for the tts leg (absent = the tts
2766
+ * row's catalog-configured default speaker).
2767
+ */
2768
+ interface RealtimeCompanions {
2769
+ readonly stt: string;
2770
+ readonly tts: string;
2771
+ readonly voice?: string;
2772
+ }
2773
+ /**
2774
+ * THE PAIRING SEAM: for `model`, the pinned trio above — or `null` when the
2775
+ * model is not realtime-capable (today's 404). The PRODUCTION source of the
2776
+ * pairing (catalog field vs proxy config) is an open owner decision; the
2777
+ * compositions wire this seam from a constructor option, and an unconfigured
2778
+ * source answers `null` so behaviour on main is unchanged. A hand-built
2779
+ * client that wires no seam behaves exactly like `null`.
2780
+ */
2781
+ type RealtimeCompanionsFor = (model: string | undefined) => Promise<RealtimeCompanions | null>;
2782
+
2783
+ export { type DialObserver as D, type InferenceRecord as I, type LedgerFailure as L, ModelRouter as M, type ProxyClients as P, type RealtimeCompanionsFor as R, SessionGoneError as S, UnknownModelError as U, type DialReport as a, type InferenceUsageRecord as b, type LedgerOutcome as c, type LedgerRecorded as d, type LedgerWrite as e, type ProxyHandlerOptions as f, type ProxyIdentity as g, type ProxyVideoOutLane as h, type RouteTarget as i, type UsageRowReporter as j, billingIdentityOf as k };