@urun-sh/openai 0.5.5 → 0.6.0

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 (56) hide show
  1. package/dist/{ResponsesClient-BYx3YLGo.d.ts → ResponsesClient-CSSrOYD8.d.ts} +7 -1
  2. package/dist/{ResponsesClient-Dft3bg3b.d.cts → ResponsesClient-_OZERUjH.d.cts} +11 -1
  3. package/dist/chunk-3JWYIKHM.js +2 -0
  4. package/dist/chunk-45FJ5GTP.js +7 -0
  5. package/dist/chunk-6M5JK4YC.js +1 -0
  6. package/dist/chunk-QTVTCMJU.js +1 -0
  7. package/dist/chunk-TDRZZGUK.js +1 -0
  8. package/dist/chunk-TPH77ZOW.js +58 -0
  9. package/dist/chunk-WCMX5VOF.js +4 -0
  10. package/dist/chunk-YXK42SKC.js +1 -0
  11. package/dist/gemini-live.cjs +2 -2
  12. package/dist/gemini-live.d.cts +79 -7
  13. package/dist/gemini-live.d.ts +32 -7
  14. package/dist/gemini-live.js +1 -1
  15. package/dist/hosted/bin.cjs +43 -27
  16. package/dist/hosted/bin.js +4 -4
  17. package/dist/hosted/index.cjs +41 -26
  18. package/dist/hosted/index.d.cts +710 -17
  19. package/dist/hosted/index.d.ts +171 -6
  20. package/dist/hosted/index.js +1 -1
  21. package/dist/index.cjs +1 -1
  22. package/dist/index.d.cts +5 -5
  23. package/dist/index.d.ts +5 -5
  24. package/dist/index.js +1 -1
  25. package/dist/{models-NYMZrklp.d.cts → models-DUdx_Y6X.d.cts} +1 -1
  26. package/dist/pi-extension/index.cjs +7 -7
  27. package/dist/pi-extension/index.d.cts +2 -2
  28. package/dist/pi-extension/index.d.ts +2 -2
  29. package/dist/pi-extension/index.js +1 -1
  30. package/dist/pi-extension/standalone.cjs +53 -53
  31. package/dist/proxy/cli.cjs +55 -43
  32. package/dist/proxy/cli.js +14 -13
  33. package/dist/proxy/index.cjs +31 -28
  34. package/dist/proxy/index.d.cts +132 -18
  35. package/dist/proxy/index.d.ts +28 -11
  36. package/dist/proxy/index.js +1 -6
  37. package/dist/responses-turn-BfdBbey8.d.cts +2394 -0
  38. package/dist/responses-turn-CdhIre_a.d.ts +652 -0
  39. package/dist/{translator-CcDBEfvm.d.cts → translator-CO8W_hmJ.d.cts} +3 -3
  40. package/dist/{translator-C9uPKypK.d.ts → translator-Ddd65sXR.d.ts} +1 -1
  41. package/dist/{types-lsVTbNcH.d.cts → types-CHPtJx6d.d.cts} +13 -0
  42. package/dist/{types-lsVTbNcH.d.ts → types-CHPtJx6d.d.ts} +4 -0
  43. package/dist/{video-out-D20UuJ8G.d.cts → video-out-BsuLqlID.d.cts} +6 -6
  44. package/dist/{video-out-CWesbk12.d.ts → video-out-Cawtm7SF.d.ts} +1 -1
  45. package/package.json +14 -11
  46. package/dist/chunk-5BZCM3RS.js +0 -4
  47. package/dist/chunk-5NXM4IO3.js +0 -2
  48. package/dist/chunk-CWJRDBDC.js +0 -1
  49. package/dist/chunk-DMD5UENK.js +0 -1
  50. package/dist/chunk-GBBY3PCZ.js +0 -1
  51. package/dist/chunk-I2Q3B3OG.js +0 -6
  52. package/dist/chunk-OI2OY32M.js +0 -1
  53. package/dist/chunk-QVF7NF7G.js +0 -44
  54. package/dist/responses-turn-KOAoIqZ-.d.ts +0 -200
  55. package/dist/responses-turn-OrO4euEN.d.cts +0 -513
  56. /package/dist/{models-NYMZrklp.d.ts → models-DUdx_Y6X.d.ts} +0 -0
@@ -1,513 +0,0 @@
1
- import { C as CatalogRow } from './models-NYMZrklp.cjs';
2
- import { IncomingMessage } from 'node:http';
3
- import { a as AudioBridge, h as VideoFrameLane, j as VideoOutLane } from './video-out-D20UuJ8G.cjs';
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
- /**
28
- * THE OPENROUTER PROVIDER DOCUMENT — `GET /v1/models?format=openrouter`.
29
- *
30
- * OpenRouter's provider monitor polls this document (schema 2.4, per
31
- * openrouter.ai/docs/guides/community/for-providers) to list a provider's
32
- * models on the marketplace. The `id` field is the EXACT model identifier
33
- * OpenRouter sends back as `model` on chat completions — which here is the
34
- * app slug, the same id the OpenAI surface lists. One id space, two views.
35
- *
36
- * MODALITY GATING: only rows whose catalog `task` names a chat-completions
37
- * shape (chat | code | agent | vl) are declared. A voice/video/image app
38
- * behind a chat surface would stream garbage into OpenRouter's baseline
39
- * tests; models the catalog cannot vouch for are OMITTED, never guessed.
40
- * With no catalog oracle configured the document is `{"data": []}` — honest
41
- * emptiness, not invented capability (the chart turns the oracle on).
42
- *
43
- * PRICING is deliberately omitted entirely: the schema's rule is "a modality
44
- * with no pricing array is simply unpriced", OpenRouter configures pricing
45
- * during provider onboarding, and the per-model price surface is
46
- * urun-infra U3 (model_prices) — when that lands, this module grows a
47
- * `prices` input and emits the input/output pricing arrays.
48
- *
49
- * The full closed-value-domain schema ships as OpenAPI 3.1 at
50
- * openrouter.ai/docs/assets/provider-monitor-schema-v2.openapi.json.
51
- */
52
-
53
- type OpenRouterProviderDoc = {
54
- data: OpenRouterProviderModel[];
55
- };
56
- interface OpenRouterProviderModel {
57
- schema_version: '2.4';
58
- /** The EXACT id OpenRouter sends back as `model` — the app slug. */
59
- id: string;
60
- name: string;
61
- created: number;
62
- /** Valid enum: int4|int8|fp4|mxfp4|nvfp4|fp6|fp8|mxfp8|fp16|bf16|fp32|null. */
63
- quantization: string | null;
64
- description: string;
65
- hugging_face_id: string;
66
- input_modalities: Array<Record<string, unknown>>;
67
- output_modalities: Array<Record<string, unknown>>;
68
- }
69
-
70
- /**
71
- * Per-model → per-app routing for the compat proxy (owner directive
72
- * 2026-08-07): swapping the model in a coding harness routes the request to
73
- * the org's DEPLOYED app for that model. v1 is deployed-only — a uRun model
74
- * that is not deployed gets a loud 404 naming `urun serve <id>`; a later
75
- * phase (explicitly out of scope here; urun-infra#1490 shared-endpoints)
76
- * auto-creates from the model catalog on first request.
77
- *
78
- * MODEL-ID SURFACE (the documented mapping): a model may be named by
79
- * - the app slug itself ("qwen3-6-27b-bf16"), or
80
- * - the catalog id ("qwen3.6-27b"), or
81
- * - the catalog id:variant ("qwen3.6-27b:bf16"),
82
- * where slugification mirrors urun-cli `serve.py _default_app_name` exactly:
83
- * lowercase, every non-alphanumeric-non-dash character becomes "-", leading/
84
- * trailing dashes stripped (catalog id "qwen3.6-27b" + variant "bf16" → app
85
- * "qwen3-6-27b-bf16"). COLLISION RULE: an exact slug match always wins over
86
- * the catalog-id (prefix) interpretation.
87
- *
88
- * RESOLUTION ORDER (one canonical path, documented end to end):
89
- * 1. model absent / "urun" / an alias of the startup app → DEFAULT app.
90
- * 2. exact slug match on a deployed serve app → that app.
91
- * 3. catalog-id form matching exactly one deployed app → that app
92
- * (two or more candidates → loud ambiguity error naming them).
93
- * 4. the name maps to an org app that is NOT an active app exposing the
94
- * proxy's serve function → loud 404
95
- * naming `urun serve <model>` and the available models.
96
- * 5. the name matches a catalog row but no deployed app → loud 404
97
- * naming `urun serve <id>` (deployed-only v1).
98
- * 6. anything else — a model name outside the uRun namespace entirely
99
- * (e.g. the harness's own upstream default, "claude-*"/"gpt-*") →
100
- * DEFAULT app. This IS today's single-app contract, kept deliberately
101
- * so `urun compat <agent>` with the agent's stock model keeps working
102
- * with zero new env; the per-model /stats table records every such
103
- * mapping so it is visible, never silent. Models the proxy ADVERTISES
104
- * on /v1/models can never land here — they resolve (2/3) or fail loud
105
- * (4/5) above.
106
- *
107
- * NO-DEFAULT MODE (`defaultApp: null`) — the HOSTED multi-tenant lane
108
- * (`src/hosted/`): a shared endpoint serving every org has no "the app this
109
- * proxy was started for", so rules 1 and 6 have nothing to fall back TO.
110
- * Rather than inventing one (picking "some" app for a caller would be the
111
- * worst kind of silent divergence), both rules become the SAME loud
112
- * {@link UnknownModelError} that rules 4/5 already raise: name a deployed
113
- * model, here is the list. Rules 2–5 are byte-for-byte the local behavior —
114
- * one router, one resolution order, two configurations.
115
- */
116
-
117
- /** One org app row from `GET {orgApi}/apps` (urun-cli `ApiClient.list_apps`). */
118
- interface DeployedApp {
119
- app_slug: string;
120
- function_name?: string | null;
121
- deployment_status?: string | null;
122
- [k: string]: unknown;
123
- }
124
- /**
125
- * A model that does not resolve to a deployed app the proxy may serve.
126
- * Rendered by the server in each lane's NATIVE error format as a 404 — never
127
- * silently served by the default app.
128
- */
129
- declare class UnknownModelError extends Error {
130
- }
131
- /**
132
- * A session handle names a pooled session that no longer exists (closed,
133
- * evicted after its pod died, replaced by a re-home, or the proxy restarted).
134
- * The caller asked to REATTACH that exact session — opening a fresh one and
135
- * calling it "resumed" would be a silent lie, so this is always loud.
136
- */
137
- declare class SessionGoneError extends Error {
138
- }
139
- /**
140
- * OpenAI-shaped model list (same shape as models.ts listModels). When the
141
- * catalog oracle is configured, each entry ALSO carries the catalog
142
- * enrichment fields (additive JSON — OpenAI clients ignore unknown fields;
143
- * the OpenRouter + Vercel AI Gateway provider listings need them). Entries
144
- * whose slug matches no catalog row stay at the bare four fields.
145
- */
146
- interface RouterModelEntry {
147
- id: string;
148
- object: 'model';
149
- created: number;
150
- owned_by: string;
151
- /** Display name — the canonical `<model_id>:<variant>` catalog ref. */
152
- name?: string;
153
- /** User-facing description from the catalog (console Endpoints copy). */
154
- description?: string;
155
- /** Catalog modality (chat | code | agent | vl | audio | image | ...). */
156
- task?: string;
157
- /** Serving engine (vllm | sglang | llamacpp | ...). */
158
- engine?: string;
159
- /** The catalog lane this app deploys, e.g. 'rtx6000:1'. */
160
- gpu_spec?: string;
161
- /** Context window in tokens (chat rows carry it in engine_args). */
162
- context_length?: number;
163
- }
164
- interface RouterModelList {
165
- object: 'list';
166
- data: RouterModelEntry[];
167
- }
168
- interface ModelRouterOptions<S> {
169
- /**
170
- * The startup app slug (URUN_APP) — the DEFAULT model — or `null` for the
171
- * hosted multi-tenant lane, which has no per-proxy default app: there,
172
- * every request must NAME a deployed model and an unnamed/unknown one
173
- * fails loud instead of silently landing somewhere (see the module header,
174
- * "NO-DEFAULT MODE").
175
- */
176
- defaultApp: string | null;
177
- /** The serve function name every routed app must expose (URUN_FUNCTION). */
178
- fnName: string;
179
- /** Open a backhaul session for an app slug (called at most once per app). */
180
- openSession: (appSlug: string) => S | Promise<S>;
181
- /** Terminal release for one pool entry (Session.end() underneath). */
182
- closeSession: (entry: S) => Promise<void>;
183
- /**
184
- * List the org's deployed apps, or null when the credentials cannot
185
- * (URUN_JWT lane: the pre-vended token is scoped to the default app, so
186
- * there is no org listing AND no cross-app session — routing degrades to
187
- * the default-app-only contract, which is exactly today's behavior).
188
- */
189
- listApps: (() => Promise<DeployedApp[]>) | null;
190
- /**
191
- * Catalog rows (models.ts fetchCatalogRows) as the uRun-namespace oracle
192
- * for rule 5 AND the /v1/models enrichment + OpenRouter provider-doc
193
- * source, or null when catalog access is not configured. Optional fields
194
- * beyond model_id/variant are tolerated (thin rows still typecheck).
195
- */
196
- listCatalog: (() => Promise<CatalogRow[]>) | null;
197
- /** Deployed-apps cache TTL (the list changes on deploys, not per request). */
198
- appsTtlMs?: number;
199
- /**
200
- * The stable NATIVE identity of one pooled entry (the uRun session id in
201
- * the proxy wiring — the same identity the serve-side session-affinity tag
202
- * rides, urun-python#1556). Powers the session-identity seam
203
- * ({@link ModelRouter.handleFor} / {@link ModelRouter.sessionForHandle});
204
- * a router without it fails LOUD on those calls, never approximates.
205
- */
206
- sessionKey?: (entry: S) => string;
207
- }
208
- /**
209
- * The image-capability modes the Images lane gates on (images.ts's
210
- * ImageCapabilityMode — declared here because the router is the LOWER layer:
211
- * the lane's gate type stays structurally satisfied by
212
- * {@link ModelRouter.supportsImages} with no router→lane import).
213
- */
214
- type ImageCapabilityMode = 'generation' | 'edit';
215
- /**
216
- * The session pool: one backhaul session per deployed app, keyed by app slug,
217
- * opened lazily on the first request that routes to it and reused for every
218
- * subsequent one. The startup app is seeded eagerly by the CLI. Sessions
219
- * close on proxy shutdown via {@link closeAll}; there is NO idle-close policy
220
- * (deliberate v1 simplification — noted as a follow-up in the PR).
221
- */
222
- declare class ModelRouter<S> {
223
- private readonly opts;
224
- private readonly pool;
225
- private appsCache;
226
- private rowsCache;
227
- constructor(opts: ModelRouterOptions<S>);
228
- /** Seed an already-open session (the CLI's eagerly-opened startup app). */
229
- seed(appSlug: string, entry: S): void;
230
- private deployedApps;
231
- /**
232
- * Catalog rows with the same TTL discipline as {@link deployedApps} (the
233
- * catalog changes on reseed migrations, not per request). Null when no
234
- * oracle is configured — callers degrade to the bare four-field entries.
235
- */
236
- private catalogRows;
237
- /** Apps this proxy may serve: active AND exposing the serve function. */
238
- private servable;
239
- private availableIds;
240
- /**
241
- * NO-DEFAULT MODE's terminal for rules 1 and 6: there is no app to fall
242
- * back to, so say so loudly and list what the CALLER'S org actually has.
243
- * Never returns.
244
- */
245
- private noDefaultApp;
246
- /**
247
- * Resolve a request's `model` to an app slug — the documented resolution
248
- * order from the module header. Throws {@link UnknownModelError} for a uRun
249
- * model that is not deployed (rules 4/5).
250
- */
251
- resolveApp(model: string | undefined): Promise<string>;
252
- /** The pooled session for a model — opened lazily, reused afterwards. */
253
- sessionFor(model: string | undefined): Promise<{
254
- app: string;
255
- entry: S;
256
- }>;
257
- private keyOf;
258
- /**
259
- * SESSION-IDENTITY SEAM (a): the opaque stable handle for the pooled
260
- * session currently serving `model`'s turns. Rides the SAME acquisition
261
- * path as every request ({@link sessionFor}) — the session opens lazily if
262
- * this model has none yet — and derives the handle from native identity
263
- * (app slug + uRun session id), zero bespoke bookkeeping.
264
- */
265
- handleFor(model: string | undefined): Promise<{
266
- app: string;
267
- handle: string;
268
- }>;
269
- /**
270
- * SESSION-IDENTITY SEAM (b): the exact pooled session a handle names.
271
- * NEVER opens a fresh session — a handle whose session is gone (closed,
272
- * evicted, re-homed to a replacement, proxy restarted) or malformed throws
273
- * {@link SessionGoneError} loudly. Resume is reattach-or-fail, not
274
- * reattach-or-quietly-restart.
275
- */
276
- sessionForHandle(handle: string): Promise<{
277
- app: string;
278
- entry: S;
279
- }>;
280
- /**
281
- * Drop ONE pooled session whose backhaul died (its pod was restarted /
282
- * drained / deleted) and release it — the next {@link sessionFor} opens a
283
- * fresh one, i.e. asks the control plane for a new assignment. Used by the
284
- * one-shot re-home (rehome.ts, urun-sh/urun-python#1592).
285
- *
286
- * IDENTITY-GUARDED (the same rule the pi lane's SessionPool follows): a
287
- * concurrent request that already re-homed this app has put a NEWER entry
288
- * under the key, and evicting that would close a healthy session out from
289
- * under it.
290
- */
291
- evict(app: string, entry: S): Promise<void>;
292
- /**
293
- * `GET /v1/models`: the org's deployed serve apps as model entries, the
294
- * default app FIRST. On the JWT lane (no org listing) this is the default
295
- * app plus any app already in the pool — the gap is called out loudly in
296
- * the PR, not papered over here.
297
- */
298
- modelList(): Promise<RouterModelList>;
299
- /**
300
- * The OpenRouter PROVIDER document (`GET /v1/models?format=openrouter`):
301
- * schema 2.4 per openrouter.ai/docs/guides/community/for-providers. Only
302
- * chat-completions-shaped models are declared (task chat | code | agent |
303
- * vl — a voice or video app behind a chat surface would stream garbage);
304
- * models the catalog cannot vouch for are OMITTED, never guessed. Pricing
305
- * is deliberately omitted entirely (schema rule: "A modality with no
306
- * pricing array is simply unpriced" — OpenRouter configures pricing during
307
- * provider onboarding; the per-model price surface is urun-infra U3).
308
- */
309
- openRouterModels(): Promise<OpenRouterProviderDoc>;
310
- /**
311
- * IMAGE CAPABILITY GATE (the Images lane's `imageModels` oracle, images.ts):
312
- * is `model`'s deployed app a native destination for `mode`? Authorized
313
- * resolution ({@link resolveApp} — undeployed uRun models throw
314
- * {@link UnknownModelError}, which the lane renders as a 404) then the
315
- * SAME catalog join as the /v1/models enrichment (PR421's rowForSlug):
316
- * exact `<model_id>-<variant>` slug across ALL its GPU-placement rows, a
317
- * bare model_id only when one variant owns it.
318
- *
319
- * Capability is read ONLY from catalog modality metadata, never from the
320
- * serve function name: every row must carry task 'image' INVARIANTLY across
321
- * the placements, and the mode comes from engine_args.expects_image —
322
- * false ⇒ pure text-to-image ('generation'; diffusers v0.38.0
323
- * pipeline_qwenimage_edit_plus raises torch.cat on an EMPTY image list, so
324
- * an edit destination is never generation-capable); true or ABSENT (the
325
- * native default) ⇒ 'edit'. The consensus rule is per-placement:
326
- * capability must agree across every placement — a CONFLICTING flag (mixed
327
- * true/false/absent) or a non-boolean one is a refused capability, never
328
- * silently defaulted to edit.
329
- *
330
- * A CONFIGURED catalog oracle that FAILS propagates its rejection — the
331
- * gate never fabricates a `false` (which would render as a misleading 404)
332
- * out of an infrastructure outage. No oracle configured, no matching row,
333
- * or a slug the catalog cannot vouch for ⇒ false (loud 404 upstream).
334
- */
335
- supportsImages(model: string | undefined, mode: ImageCapabilityMode): Promise<boolean>;
336
- /** Close every pooled session (Session.end() underneath) — proxy shutdown. */
337
- closeAll(): Promise<void>;
338
- }
339
-
340
- /**
341
- * The shared Responses execution/store seam — the ONE execution + event-
342
- * envelope path and the authorized tenant store, imported by BOTH the HTTP
343
- * SSE lane (server.ts) and the `/v1/responses` WebSocket lane
344
- * (responses-ws.ts). This module deliberately imports NO transport acceptor
345
- * and NO HTTP lane module: its only imports are type-only, so the module
346
- * graph server.ts → responses-ws.ts → responses-turn.ts is acyclic and no
347
- * Vitest/Bun/Node module-evaluation order can observe an uninitialized
348
- * binding (the constructor-failure class of bug this extraction removes).
349
- */
350
-
351
- /** The request envelope every Responses-shaped upstream call carries. */
352
- interface ResponsesCreateParams {
353
- model?: string;
354
- input: unknown;
355
- stream?: boolean;
356
- tools?: unknown;
357
- tool_choice?: unknown;
358
- temperature?: number;
359
- max_output_tokens?: number;
360
- /**
361
- * System/developer instructions, forwarded to the serve envelope — where
362
- * they become ONE prepended `system`-role message (the protocol's native
363
- * per-request system input; there is NO envelope-level instructions field).
364
- * Typed `string` end to end (transport/encode.ts) so no cast bridges the seam.
365
- */
366
- instructions?: string;
367
- top_p?: number;
368
- stop?: string[];
369
- /**
370
- * Reasoning controls (urun-python #1667): forwarded VERBATIM to the serve
371
- * envelope — `chat_template_kwargs.enable_thinking:false` is the think-off
372
- * switch. Absent -> absent (no default injection; server-side validation).
373
- */
374
- reasoning_effort?: string;
375
- chat_template_kwargs?: Record<string, unknown>;
376
- }
377
- /** How one pinned session ended (the native phase machinery's terminal step). */
378
- interface SessionEndInfo {
379
- /**
380
- * Milliseconds until the session's native deadline (`endsAt`), or null when
381
- * the app declared no maximum session length. NOTE (missing primitive,
382
- * called out in the PR): core exposes no PRE-expiry notice event — this
383
- * callback fires AT terminal loss, so timeLeftMs is ~0 on expiry.
384
- */
385
- timeLeftMs: number | null;
386
- /** The terminal reason (expired / ended / error), for the loud close. */
387
- reason: string;
388
- }
389
- /** The upstream calls the proxy makes — injectable (tests; alt transports). */
390
- interface ProxyClients {
391
- /** `UrunResponses(session).responses.create` — an async iterable of Responses stream events. */
392
- createResponse(params: ResponsesCreateParams): Promise<AsyncIterable<unknown>> | AsyncIterable<unknown>;
393
- /** `listModels(...)` result (an OpenAI model list object). */
394
- listModels(): Promise<unknown>;
395
- /**
396
- * The OpenRouter provider document (`GET /v1/models?format=openrouter`).
397
- * Optional at the seam: hand-built test clients may omit it, in which case
398
- * the format=openrouter branch answers 501 — loud, never a silent empty.
399
- */
400
- openRouterModels?(): Promise<unknown>;
401
- /**
402
- * Open (or reuse) the NATIVE audio lanes on the pooled session `model` routes
403
- * to — the same first-party machinery as RealtimeClient.enableAudio
404
- * (transport/media.ts `enableSessionAudio`: AudioBridge over the session's
405
- * `rt-audio-in`/`rt-audio-out` stream lanes at 24 kHz). One lane per pooled
406
- * session; repeat calls return the same lane. Optional at the seam because
407
- * text-only embeddings exist — but a surface that RECEIVES audio while the
408
- * embedder wired no `openAudio` must fail LOUD, never drop chunks.
409
- */
410
- openAudio?(model: string | undefined): Promise<ProxyAudioLane>;
411
- /**
412
- * Open (or reuse) the NATIVE video FRAME lane on the pooled session `model`
413
- * routes to (transport/media.ts `enableSessionVideo`: discrete JPEG frames →
414
- * `stream('rt-video-in').emit`, the §5 named-DATA image-bytes path — NOT the
415
- * RTP media plane, which requires an already-H.264-encoded track). One lane
416
- * per pooled session; repeat calls return the same lane. Optional at the seam
417
- * because text-only embeddings exist — but a surface that RECEIVES video
418
- * frames while the embedder wired no `openVideo` must fail LOUD, never drop
419
- * frames.
420
- */
421
- openVideo?(model: string | undefined): Promise<ProxyVideoLane>;
422
- /**
423
- * Open (or reuse) the NATIVE video OUTPUT lane on the pooled session
424
- * `model` routes to (transport/video-out.ts `openSessionVideoOutLane`):
425
- * decoded spec-v1 records consumed from the session's named §5
426
- * `rt-video-out` downstream. The Live adapter fans each record onto the
427
- * SAME Bidi WS as an extension server message (spec v2, WS-inline) — no
428
- * side-channel transport. Optional at the seam; an ABSENT seam means the
429
- * `urun.videoOut` capability is refused by omission in setupComplete
430
- * (vanilla parity), while a wired seam that cannot open the lane must
431
- * throw LOUD — never a quiet downgrade.
432
- */
433
- openVideoOut?(model: string | undefined): Promise<ProxyVideoOutLane>;
434
- /**
435
- * SESSION-IDENTITY SEAM (ModelRouter.handleFor): the opaque stable handle
436
- * for the pooled session currently serving `model`'s turns. Derived from
437
- * native identity (app slug + uRun session id) — the same identity the
438
- * serve-side session-affinity tag rides (urun-python#1556/#1582).
439
- */
440
- sessionHandle(model: string | undefined): Promise<string>;
441
- /**
442
- * createResponse PINNED to the exact session a handle names
443
- * (ModelRouter.sessionForHandle). Throws SessionGoneError LOUDLY when that
444
- * session is gone or was replaced — never silently opens a fresh session
445
- * while claiming resume. Deliberately NO re-home on this path: re-homing
446
- * would swap the pinned session out from under the caller.
447
- */
448
- createResponseOn(handle: string, params: ResponsesCreateParams): Promise<AsyncIterable<unknown>> | AsyncIterable<unknown>;
449
- /**
450
- * Subscribe to the pinned session's terminal end via core's NATIVE phase
451
- * machinery (Session.onPhase → terminal 'expired'/'ended'/'error'). Fires
452
- * `cb` once. Throws SessionGoneError if the handle's session is already
453
- * gone — which doubles as the loud reattach check at resume time. Returns
454
- * the unsubscribe.
455
- */
456
- onSessionEnd(handle: string, cb: (end: SessionEndInfo) => void): Promise<() => void>;
457
- }
458
- /**
459
- * The audio lane handle `openAudio` returns — structurally the transport
460
- * AudioBridge (media.ts): base64 PCM16 @24 kHz mono in both directions.
461
- */
462
- type ProxyAudioLane = Pick<AudioBridge, 'appendInputAudio' | 'onOutputAudio'>;
463
- /**
464
- * The video frame-lane handle `openVideo` returns — structurally the
465
- * transport VideoFrameLane (media.ts): one raw encoded JPEG frame per call,
466
- * input-only (Live-style protocols have no video OUT modality).
467
- */
468
- type ProxyVideoLane = Pick<VideoFrameLane, 'sendInputFrame'>;
469
- /**
470
- * The video-OUT lane handle `openVideoOut` returns — structurally the
471
- * transport VideoOutLane (video-out.ts): the codec plus frame/error fan-out
472
- * the WS-inline delivery subscribes.
473
- */
474
- type ProxyVideoOutLane = Pick<VideoOutLane, 'codec' | 'onOutputFrame' | 'onLaneError'>;
475
- /**
476
- * Per-request `ProxyClients` resolution — the seam the HOSTED multi-tenant
477
- * server (`src/hosted/`) plugs into so ONE handler implementation serves
478
- * every org: the hosted server resolves the caller's org from its Bearer API
479
- * key and returns THAT org's backhaul. The local CLI passes a fixed
480
- * `ProxyClients` instead; both go through the identical handler body.
481
- *
482
- * Throwing from here is the loud path: the thrown error surfaces in the
483
- * lane's native error envelope (see {@link ProxyHandlerOptions.statusOf}).
484
- */
485
- type ProxyClientsFor = (req: IncomingMessage) => ProxyClients | Promise<ProxyClients>;
486
- interface ProxyHandlerOptions {
487
- /** A fixed backhaul (local CLI) or a per-request resolver (hosted server). */
488
- clients: ProxyClients | ProxyClientsFor;
489
- /** Optional bearer the local agent must present (never forwarded upstream). */
490
- apiKey?: string;
491
- /**
492
- * WHAT this proxy serves (app/org/fn/base_url + proxy_version), surfaced as
493
- * the `identity` block on `GET /stats` so a second `urun compat` invocation
494
- * can reuse this proxy iff the identity matches its own exactly. Only the
495
- * standalone `urun compat proxy` command sets it — a launch-mode proxy is
496
- * child-owned (it dies with its child) and an embedder that omits it is
497
- * simply never reused.
498
- */
499
- identity?: ProxyIdentity;
500
- /**
501
- * Map a thrown error onto an HTTP status + error `type` before the generic
502
- * 500. The hosted server uses it to turn its auth/tenancy failures into a
503
- * 401 in the OpenAI envelope. Returning null means "not mine" — the error
504
- * takes the ordinary loud 500 path.
505
- */
506
- statusOf?: (err: unknown) => {
507
- status: number;
508
- openaiType: string;
509
- anthropicType: string;
510
- } | null;
511
- }
512
-
513
- export { ModelRouter as M, type ProxyClients as P, SessionGoneError as S, UnknownModelError as U, type ProxyHandlerOptions as a, type ProxyIdentity as b, type ProxyVideoOutLane as c };