@urun-sh/openai 0.5.4 → 0.5.5

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.
@@ -2,283 +2,10 @@ import { Server } from 'node:http';
2
2
  import { createClientToken } from '@urun-sh/core';
3
3
  import { U as UrunResponses } from '../ResponsesClient-Dft3bg3b.cjs';
4
4
  import { b as UrunSessionLike } from '../types-lsVTbNcH.cjs';
5
- import { C as CatalogRow } from '../models-NYMZrklp.cjs';
6
- import { P as ProxyClients } from '../server-wmUnMewW.cjs';
5
+ import { S as SessionGoneError, P as ProxyClients, M as ModelRouter } from '../responses-turn-OrO4euEN.cjs';
6
+ import '../models-NYMZrklp.cjs';
7
7
  import '../video-out-D20UuJ8G.cjs';
8
8
 
9
- /**
10
- * THE OPENROUTER PROVIDER DOCUMENT — `GET /v1/models?format=openrouter`.
11
- *
12
- * OpenRouter's provider monitor polls this document (schema 2.4, per
13
- * openrouter.ai/docs/guides/community/for-providers) to list a provider's
14
- * models on the marketplace. The `id` field is the EXACT model identifier
15
- * OpenRouter sends back as `model` on chat completions — which here is the
16
- * app slug, the same id the OpenAI surface lists. One id space, two views.
17
- *
18
- * MODALITY GATING: only rows whose catalog `task` names a chat-completions
19
- * shape (chat | code | agent | vl) are declared. A voice/video/image app
20
- * behind a chat surface would stream garbage into OpenRouter's baseline
21
- * tests; models the catalog cannot vouch for are OMITTED, never guessed.
22
- * With no catalog oracle configured the document is `{"data": []}` — honest
23
- * emptiness, not invented capability (the chart turns the oracle on).
24
- *
25
- * PRICING is deliberately omitted entirely: the schema's rule is "a modality
26
- * with no pricing array is simply unpriced", OpenRouter configures pricing
27
- * during provider onboarding, and the per-model price surface is
28
- * urun-infra U3 (model_prices) — when that lands, this module grows a
29
- * `prices` input and emits the input/output pricing arrays.
30
- *
31
- * The full closed-value-domain schema ships as OpenAPI 3.1 at
32
- * openrouter.ai/docs/assets/provider-monitor-schema-v2.openapi.json.
33
- */
34
-
35
- type OpenRouterProviderDoc = {
36
- data: OpenRouterProviderModel[];
37
- };
38
- interface OpenRouterProviderModel {
39
- schema_version: '2.4';
40
- /** The EXACT id OpenRouter sends back as `model` — the app slug. */
41
- id: string;
42
- name: string;
43
- created: number;
44
- /** Valid enum: int4|int8|fp4|mxfp4|nvfp4|fp6|fp8|mxfp8|fp16|bf16|fp32|null. */
45
- quantization: string | null;
46
- description: string;
47
- hugging_face_id: string;
48
- input_modalities: Array<Record<string, unknown>>;
49
- output_modalities: Array<Record<string, unknown>>;
50
- }
51
-
52
- /**
53
- * Per-model → per-app routing for the compat proxy (owner directive
54
- * 2026-08-07): swapping the model in a coding harness routes the request to
55
- * the org's DEPLOYED app for that model. v1 is deployed-only — a uRun model
56
- * that is not deployed gets a loud 404 naming `urun serve <id>`; a later
57
- * phase (explicitly out of scope here; urun-infra#1490 shared-endpoints)
58
- * auto-creates from the model catalog on first request.
59
- *
60
- * MODEL-ID SURFACE (the documented mapping): a model may be named by
61
- * - the app slug itself ("qwen3-6-27b-bf16"), or
62
- * - the catalog id ("qwen3.6-27b"), or
63
- * - the catalog id:variant ("qwen3.6-27b:bf16"),
64
- * where slugification mirrors urun-cli `serve.py _default_app_name` exactly:
65
- * lowercase, every non-alphanumeric-non-dash character becomes "-", leading/
66
- * trailing dashes stripped (catalog id "qwen3.6-27b" + variant "bf16" → app
67
- * "qwen3-6-27b-bf16"). COLLISION RULE: an exact slug match always wins over
68
- * the catalog-id (prefix) interpretation.
69
- *
70
- * RESOLUTION ORDER (one canonical path, documented end to end):
71
- * 1. model absent / "urun" / an alias of the startup app → DEFAULT app.
72
- * 2. exact slug match on a deployed serve app → that app.
73
- * 3. catalog-id form matching exactly one deployed app → that app
74
- * (two or more candidates → loud ambiguity error naming them).
75
- * 4. the name maps to an org app that is NOT an active app exposing the
76
- * proxy's serve function → loud 404
77
- * naming `urun serve <model>` and the available models.
78
- * 5. the name matches a catalog row but no deployed app → loud 404
79
- * naming `urun serve <id>` (deployed-only v1).
80
- * 6. anything else — a model name outside the uRun namespace entirely
81
- * (e.g. the harness's own upstream default, "claude-*"/"gpt-*") →
82
- * DEFAULT app. This IS today's single-app contract, kept deliberately
83
- * so `urun compat <agent>` with the agent's stock model keeps working
84
- * with zero new env; the per-model /stats table records every such
85
- * mapping so it is visible, never silent. Models the proxy ADVERTISES
86
- * on /v1/models can never land here — they resolve (2/3) or fail loud
87
- * (4/5) above.
88
- *
89
- * NO-DEFAULT MODE (`defaultApp: null`) — the HOSTED multi-tenant lane
90
- * (`src/hosted/`): a shared endpoint serving every org has no "the app this
91
- * proxy was started for", so rules 1 and 6 have nothing to fall back TO.
92
- * Rather than inventing one (picking "some" app for a caller would be the
93
- * worst kind of silent divergence), both rules become the SAME loud
94
- * {@link UnknownModelError} that rules 4/5 already raise: name a deployed
95
- * model, here is the list. Rules 2–5 are byte-for-byte the local behavior —
96
- * one router, one resolution order, two configurations.
97
- */
98
-
99
- /** One org app row from `GET {orgApi}/apps` (urun-cli `ApiClient.list_apps`). */
100
- interface DeployedApp {
101
- app_slug: string;
102
- function_name?: string | null;
103
- deployment_status?: string | null;
104
- [k: string]: unknown;
105
- }
106
- /**
107
- * A session handle names a pooled session that no longer exists (closed,
108
- * evicted after its pod died, replaced by a re-home, or the proxy restarted).
109
- * The caller asked to REATTACH that exact session — opening a fresh one and
110
- * calling it "resumed" would be a silent lie, so this is always loud.
111
- */
112
- declare class SessionGoneError extends Error {
113
- }
114
- /**
115
- * OpenAI-shaped model list (same shape as models.ts listModels). When the
116
- * catalog oracle is configured, each entry ALSO carries the catalog
117
- * enrichment fields (additive JSON — OpenAI clients ignore unknown fields;
118
- * the OpenRouter + Vercel AI Gateway provider listings need them). Entries
119
- * whose slug matches no catalog row stay at the bare four fields.
120
- */
121
- interface RouterModelEntry {
122
- id: string;
123
- object: 'model';
124
- created: number;
125
- owned_by: string;
126
- /** Display name — the canonical `<model_id>:<variant>` catalog ref. */
127
- name?: string;
128
- /** User-facing description from the catalog (console Endpoints copy). */
129
- description?: string;
130
- /** Catalog modality (chat | code | agent | vl | audio | image | ...). */
131
- task?: string;
132
- /** Serving engine (vllm | sglang | llamacpp | ...). */
133
- engine?: string;
134
- /** The catalog lane this app deploys, e.g. 'rtx6000:1'. */
135
- gpu_spec?: string;
136
- /** Context window in tokens (chat rows carry it in engine_args). */
137
- context_length?: number;
138
- }
139
- interface RouterModelList {
140
- object: 'list';
141
- data: RouterModelEntry[];
142
- }
143
- interface ModelRouterOptions<S> {
144
- /**
145
- * The startup app slug (URUN_APP) — the DEFAULT model — or `null` for the
146
- * hosted multi-tenant lane, which has no per-proxy default app: there,
147
- * every request must NAME a deployed model and an unnamed/unknown one
148
- * fails loud instead of silently landing somewhere (see the module header,
149
- * "NO-DEFAULT MODE").
150
- */
151
- defaultApp: string | null;
152
- /** The serve function name every routed app must expose (URUN_FUNCTION). */
153
- fnName: string;
154
- /** Open a backhaul session for an app slug (called at most once per app). */
155
- openSession: (appSlug: string) => S | Promise<S>;
156
- /** Terminal release for one pool entry (Session.end() underneath). */
157
- closeSession: (entry: S) => Promise<void>;
158
- /**
159
- * List the org's deployed apps, or null when the credentials cannot
160
- * (URUN_JWT lane: the pre-vended token is scoped to the default app, so
161
- * there is no org listing AND no cross-app session — routing degrades to
162
- * the default-app-only contract, which is exactly today's behavior).
163
- */
164
- listApps: (() => Promise<DeployedApp[]>) | null;
165
- /**
166
- * Catalog rows (models.ts fetchCatalogRows) as the uRun-namespace oracle
167
- * for rule 5 AND the /v1/models enrichment + OpenRouter provider-doc
168
- * source, or null when catalog access is not configured. Optional fields
169
- * beyond model_id/variant are tolerated (thin rows still typecheck).
170
- */
171
- listCatalog: (() => Promise<CatalogRow[]>) | null;
172
- /** Deployed-apps cache TTL (the list changes on deploys, not per request). */
173
- appsTtlMs?: number;
174
- /**
175
- * The stable NATIVE identity of one pooled entry (the uRun session id in
176
- * the proxy wiring — the same identity the serve-side session-affinity tag
177
- * rides, urun-python#1556). Powers the session-identity seam
178
- * ({@link ModelRouter.handleFor} / {@link ModelRouter.sessionForHandle});
179
- * a router without it fails LOUD on those calls, never approximates.
180
- */
181
- sessionKey?: (entry: S) => string;
182
- }
183
- /**
184
- * The session pool: one backhaul session per deployed app, keyed by app slug,
185
- * opened lazily on the first request that routes to it and reused for every
186
- * subsequent one. The startup app is seeded eagerly by the CLI. Sessions
187
- * close on proxy shutdown via {@link closeAll}; there is NO idle-close policy
188
- * (deliberate v1 simplification — noted as a follow-up in the PR).
189
- */
190
- declare class ModelRouter<S> {
191
- private readonly opts;
192
- private readonly pool;
193
- private appsCache;
194
- private rowsCache;
195
- constructor(opts: ModelRouterOptions<S>);
196
- /** Seed an already-open session (the CLI's eagerly-opened startup app). */
197
- seed(appSlug: string, entry: S): void;
198
- private deployedApps;
199
- /**
200
- * Catalog rows with the same TTL discipline as {@link deployedApps} (the
201
- * catalog changes on reseed migrations, not per request). Null when no
202
- * oracle is configured — callers degrade to the bare four-field entries.
203
- */
204
- private catalogRows;
205
- /** Apps this proxy may serve: active AND exposing the serve function. */
206
- private servable;
207
- private availableIds;
208
- /**
209
- * NO-DEFAULT MODE's terminal for rules 1 and 6: there is no app to fall
210
- * back to, so say so loudly and list what the CALLER'S org actually has.
211
- * Never returns.
212
- */
213
- private noDefaultApp;
214
- /**
215
- * Resolve a request's `model` to an app slug — the documented resolution
216
- * order from the module header. Throws {@link UnknownModelError} for a uRun
217
- * model that is not deployed (rules 4/5).
218
- */
219
- resolveApp(model: string | undefined): Promise<string>;
220
- /** The pooled session for a model — opened lazily, reused afterwards. */
221
- sessionFor(model: string | undefined): Promise<{
222
- app: string;
223
- entry: S;
224
- }>;
225
- private keyOf;
226
- /**
227
- * SESSION-IDENTITY SEAM (a): the opaque stable handle for the pooled
228
- * session currently serving `model`'s turns. Rides the SAME acquisition
229
- * path as every request ({@link sessionFor}) — the session opens lazily if
230
- * this model has none yet — and derives the handle from native identity
231
- * (app slug + uRun session id), zero bespoke bookkeeping.
232
- */
233
- handleFor(model: string | undefined): Promise<{
234
- app: string;
235
- handle: string;
236
- }>;
237
- /**
238
- * SESSION-IDENTITY SEAM (b): the exact pooled session a handle names.
239
- * NEVER opens a fresh session — a handle whose session is gone (closed,
240
- * evicted, re-homed to a replacement, proxy restarted) or malformed throws
241
- * {@link SessionGoneError} loudly. Resume is reattach-or-fail, not
242
- * reattach-or-quietly-restart.
243
- */
244
- sessionForHandle(handle: string): Promise<{
245
- app: string;
246
- entry: S;
247
- }>;
248
- /**
249
- * Drop ONE pooled session whose backhaul died (its pod was restarted /
250
- * drained / deleted) and release it — the next {@link sessionFor} opens a
251
- * fresh one, i.e. asks the control plane for a new assignment. Used by the
252
- * one-shot re-home (rehome.ts, urun-sh/urun-python#1592).
253
- *
254
- * IDENTITY-GUARDED (the same rule the pi lane's SessionPool follows): a
255
- * concurrent request that already re-homed this app has put a NEWER entry
256
- * under the key, and evicting that would close a healthy session out from
257
- * under it.
258
- */
259
- evict(app: string, entry: S): Promise<void>;
260
- /**
261
- * `GET /v1/models`: the org's deployed serve apps as model entries, the
262
- * default app FIRST. On the JWT lane (no org listing) this is the default
263
- * app plus any app already in the pool — the gap is called out loudly in
264
- * the PR, not papered over here.
265
- */
266
- modelList(): Promise<RouterModelList>;
267
- /**
268
- * The OpenRouter PROVIDER document (`GET /v1/models?format=openrouter`):
269
- * schema 2.4 per openrouter.ai/docs/guides/community/for-providers. Only
270
- * chat-completions-shaped models are declared (task chat | code | agent |
271
- * vl — a voice or video app behind a chat surface would stream garbage);
272
- * models the catalog cannot vouch for are OMITTED, never guessed. Pricing
273
- * is deliberately omitted entirely (schema rule: "A modality with no
274
- * pricing array is simply unpriced" — OpenRouter configures pricing during
275
- * provider onboarding; the per-model price surface is urun-infra U3).
276
- */
277
- openRouterModels(): Promise<OpenRouterProviderDoc>;
278
- /** Close every pooled session (Session.end() underneath) — proxy shutdown. */
279
- closeAll(): Promise<void>;
280
- }
281
-
282
9
  /**
283
10
  * HOSTED AUTH — the Bearer key IS the identity AND the tenancy.
284
11
  *
@@ -479,6 +206,14 @@ interface CatalogConfig {
479
206
  */
480
207
  type OwnedSession = UrunSessionLike & {
481
208
  end: () => Promise<unknown>;
209
+ /**
210
+ * The SDK's NATIVE local release (core `Session.detach`): drop the media
211
+ * transport and decrement the reference count while the named session
212
+ * stays live and attachable. Optional here because only the
213
+ * `release: 'detach'` lane requires it — that lane fails LOUD when a
214
+ * session object lacks it (no approximation, no fake detach).
215
+ */
216
+ detach?: () => void;
482
217
  id?: string;
483
218
  endsAt?: Date | null;
484
219
  onPhase?: (handler: (phase: {
@@ -592,6 +327,121 @@ declare class TenantRegistry {
592
327
  /** Shutdown: end every pooled session through `Session.end()`. */
593
328
  closeAll(): Promise<void>;
594
329
  }
330
+ /** The most distinct LIVE conversations one replica keeps private backhauls for. */
331
+ declare const MAX_CONVERSATIONS = 512;
332
+ /** The most resume handles the conversation index remembers (bounded memory). */
333
+ declare const MAX_CONVERSATION_HANDLES = 1024;
334
+ /**
335
+ * Every conversation slot holds a conversation (active or resumable) — a NEW
336
+ * bootstrap/setup is refused. Explicit and honest: never an LRU-detach of
337
+ * someone else's conversation to admit a new one.
338
+ */
339
+ declare class ConversationCapacityError extends Error {
340
+ constructor();
341
+ }
342
+ /**
343
+ * One conversation's private backhaul. Its pooled sessions are reachable by
344
+ * NO other conversation of any caller: the token subject is conversation-
345
+ * unique, so the platform's own session dedupe never coalesces them.
346
+ */
347
+ interface PrivateConversationBackhaul {
348
+ clients: ProxyClients;
349
+ /**
350
+ * LOCAL release of every pooled session — `release: 'detach'` underneath,
351
+ * i.e. core's NATIVE `Session.detach()`: the media transport drops, the
352
+ * refcount decrements, the NAMED session stays live and attachable. Never
353
+ * `Session.end()`: no caller has explicitly ended anything.
354
+ */
355
+ release(): Promise<void>;
356
+ }
357
+ interface ConversationBackhaulOptions {
358
+ /** The session-gateway base sessions are opened against. */
359
+ baseUrl: string;
360
+ /** The org control-plane API base (`GET {apiUrl}/apps`). */
361
+ apiUrl: string;
362
+ /** The model-catalog oracle for routing rule 5, or null. */
363
+ catalog: CatalogConfig | null;
364
+ /** Injected in tests; production builds real uRun backhauls. */
365
+ build?: (caller: CallerIdentity, conversation: {
366
+ id: string;
367
+ subject: string;
368
+ }) => PrivateConversationBackhaul;
369
+ }
370
+ /**
371
+ * The per-CONNECTION Live/realtime seam — transport-neutral (Gemini Live,
372
+ * OpenAI Realtime, ...). `clients` lazily opens the caller's PRIVATE
373
+ * conversation backhaul on first use; `bindResumeHandle` indexes each handle
374
+ * the protocol lane mints; `clientsForResume` re-attaches the conversation a
375
+ * handle belongs to — SAME native identity, owner binding enforced, loud
376
+ * SessionGoneError when the conversation is gone; `release` drops THIS
377
+ * attachment when the socket closes.
378
+ */
379
+ interface PrivateConversationConnection {
380
+ clients: ProxyClients;
381
+ bindResumeHandle(handle: string): void;
382
+ clientsForResume(handle: string): Promise<ProxyClients>;
383
+ /**
384
+ * Release THIS attachment: called by the surface when its socket closes.
385
+ * When the LAST attachment of a conversation goes, its native transport is
386
+ * detached immediately — while the conversation's native session
387
+ * REFERENCES (and its resume handles) are RETAINED, so a later resume
388
+ * re-attaches the SAME named session through canonical attach-by-name.
389
+ * Idempotent.
390
+ */
391
+ release(): Promise<void>;
392
+ }
393
+ /**
394
+ * Process-local registry of per-conversation private backhauls, bounded by
395
+ * {@link MAX_CONVERSATIONS}. A conversation whose last attachment closes
396
+ * KEEPS its entry: its native session references + resume handles survive so
397
+ * a later resume re-attaches the SAME named session (canonical
398
+ * attach-by-name). At capacity, only such DETACHED entries are evicted
399
+ * (oldest first — their resume capability is the only thing lost, the named
400
+ * sessions stay attachable server-side); ACTIVE conversations are never
401
+ * touched, and when every slot is active a new bootstrap/setup is refused
402
+ * with an explicit capacity error. NO HA CLAIM: this registry is
403
+ * per-process; a replica restart loses every conversation (loud gone), and
404
+ * no other replica can serve one.
405
+ */
406
+ declare class ConversationBackhauls {
407
+ private readonly opts;
408
+ /** apiKey → conversationId → entry (insertion-ordered = LRU). */
409
+ private readonly byCaller;
410
+ /** resume handle → owning conversation (the owner binding's index). */
411
+ private readonly byHandle;
412
+ constructor(opts: ConversationBackhaulOptions);
413
+ private build;
414
+ /** Find (LRU-refresh) or create the conversation entry, then ATTACH to it. */
415
+ private attachEntry;
416
+ private get conversationCount();
417
+ /**
418
+ * Free a slot for a NEW conversation: evict the OLDEST DETACHED
419
+ * conversation (one whose last attachment already closed — only its resume
420
+ * metadata is lost, no live transport is touched, no session is ended).
421
+ * ACTIVE conversations are never evicted. When every slot holds an active
422
+ * conversation, refuse LOUD with an explicit capacity error — the new
423
+ * bootstrap/setup fails, existing callers are untouched.
424
+ */
425
+ private evictOverflow;
426
+ private dropHandleIndexFor;
427
+ /**
428
+ * The per-upgrade seam for one authenticated caller — ONE attachment. The
429
+ * conversation backhaul opens on the FIRST seam call of a fresh connection;
430
+ * a resumed connection replaces `clients` wholesale via `clientsForResume`
431
+ * before any seam call, so the lazy path is never taken on resume. The
432
+ * attachment is released by `release()` (the socket's close path): when the
433
+ * LAST attachment of a conversation goes, its native transport is detached
434
+ * immediately and its resume metadata is retained — no resource keepalive,
435
+ * no resume loss.
436
+ */
437
+ connectionFor(caller: CallerIdentity): PrivateConversationConnection;
438
+ /**
439
+ * Drain-time LOCAL release: detach every conversation's sessions (native
440
+ * detach — the named sessions pause server-side, nothing is ended). Handles
441
+ * and conversations are forgotten; process exit is the conversation's end.
442
+ */
443
+ detachAll(): Promise<void>;
444
+ }
595
445
 
596
446
  /**
597
447
  * The hosted endpoint's configuration.
@@ -671,7 +521,12 @@ declare function resolveHostedConfig(env?: NodeJS.ProcessEnv): HostedConfig;
671
521
  * or list apps can serve nothing and must be pulled out of
672
522
  * the Service rather than answering 502s.
673
523
  * * /v1/... the compat surface, org-scoped by the Bearer key.
674
- * * anything else → 404 in the OpenAI error envelope.
524
+ * WS /ws/google.ai.generativelanguage.v1beta.GenerativeService.
525
+ * BidiGenerateContent — the Gemini Live surface, org-scoped by the
526
+ * Gemini credential (x-goog-api-key / Authorization: Bearer; `?key=`
527
+ * refused). Ingress/charts must allowlist that path.
528
+ * * anything else → 404 in the OpenAI error envelope (unclaimed WS
529
+ * upgrades get their own final refusal).
675
530
  *
676
531
  * WHAT IS DELIBERATELY NOT HERE: `/stats`. The local proxy exposes it for the
677
532
  * launcher's reuse probe; on a shared endpoint it would publish one tenant's
@@ -698,14 +553,20 @@ interface HostedProxyOptions extends HostedConfig {
698
553
  resolver?: OrgResolver;
699
554
  /** Injected in tests so backhauls are stubbed at the seam. */
700
555
  registry?: TenantRegistry;
556
+ /** Injected in tests so conversation backhauls are stubbed at the seam. */
557
+ conversations?: ConversationBackhauls;
701
558
  }
702
559
  /**
703
- * Build (not listen) the hosted endpoint. The caller owns listen/close, and
704
- * `closeAll` releases every pooled backhaul through `Session.end()`.
560
+ * Build (not listen) the hosted endpoint. The caller owns listen/close,
561
+ * `closeAll` releases every pooled backhaul through `Session.end()`, and
562
+ * `closeWebSockets` gracefully closes every attached WS surface — a drain
563
+ * must run it BEFORE `server.close()`/`closeAllConnections()` (see
564
+ * {@link drainServer}).
705
565
  */
706
566
  declare function createHostedProxy(options: HostedProxyOptions): {
707
567
  server: Server;
708
568
  closeAll: () => Promise<void>;
569
+ closeWebSockets: () => Promise<void>;
709
570
  };
710
571
 
711
- export { BIND_HOST, type CallerIdentity, ControlPlaneUnavailableError, DEFAULT_PORT, type HostedConfig, type HostedProxyOptions, MAX_CACHED_KEYS, MAX_TENANTS, ORG_BINDING_TTL_MS, OrgResolver, type OrgResolverOptions, ProxyAuthError, READINESS_TIMEOUT_MS, READINESS_TTL_MS, SERVE_FUNCTION, TenantRegistry, type TenantRegistryOptions, bearerFrom, createHostedProxy, resolveHostedConfig, tenantSubject };
572
+ export { BIND_HOST, type CallerIdentity, ControlPlaneUnavailableError, type ConversationBackhaulOptions, ConversationBackhauls, ConversationCapacityError, DEFAULT_PORT, type HostedConfig, type HostedProxyOptions, MAX_CACHED_KEYS, MAX_CONVERSATIONS, MAX_CONVERSATION_HANDLES, MAX_TENANTS, ORG_BINDING_TTL_MS, OrgResolver, type OrgResolverOptions, type PrivateConversationBackhaul, type PrivateConversationConnection, ProxyAuthError, READINESS_TIMEOUT_MS, READINESS_TTL_MS, SERVE_FUNCTION, TenantRegistry, type TenantRegistryOptions, bearerFrom, createHostedProxy, resolveHostedConfig, tenantSubject };
@@ -2,122 +2,10 @@ import { Server } from 'node:http';
2
2
  import { createClientToken } from '@urun-sh/core';
3
3
  import { U as UrunResponses } from '../ResponsesClient-BYx3YLGo.js';
4
4
  import { b as UrunSessionLike } from '../types-lsVTbNcH.js';
5
- import { C as CatalogRow } from '../models-NYMZrklp.js';
6
- import { P as ProxyClients } from '../server-DuH_5OD9.js';
5
+ import { S as SessionGoneError, P as ProxyClients, M as ModelRouter } from '../responses-turn-KOAoIqZ-.js';
6
+ import '../models-NYMZrklp.js';
7
7
  import '../video-out-CWesbk12.js';
8
8
 
9
- type OpenRouterProviderDoc = {
10
- data: OpenRouterProviderModel[];
11
- };
12
- interface OpenRouterProviderModel {
13
- schema_version: '2.4';
14
-
15
- id: string;
16
- name: string;
17
- created: number;
18
-
19
- quantization: string | null;
20
- description: string;
21
- hugging_face_id: string;
22
- input_modalities: Array<Record<string, unknown>>;
23
- output_modalities: Array<Record<string, unknown>>;
24
- }
25
-
26
- interface DeployedApp {
27
- app_slug: string;
28
- function_name?: string | null;
29
- deployment_status?: string | null;
30
- [k: string]: unknown;
31
- }
32
-
33
- declare class SessionGoneError extends Error {
34
- }
35
-
36
- interface RouterModelEntry {
37
- id: string;
38
- object: 'model';
39
- created: number;
40
- owned_by: string;
41
-
42
- name?: string;
43
-
44
- description?: string;
45
-
46
- task?: string;
47
-
48
- engine?: string;
49
-
50
- gpu_spec?: string;
51
-
52
- context_length?: number;
53
- }
54
- interface RouterModelList {
55
- object: 'list';
56
- data: RouterModelEntry[];
57
- }
58
- interface ModelRouterOptions<S> {
59
-
60
- defaultApp: string | null;
61
-
62
- fnName: string;
63
-
64
- openSession: (appSlug: string) => S | Promise<S>;
65
-
66
- closeSession: (entry: S) => Promise<void>;
67
-
68
- listApps: (() => Promise<DeployedApp[]>) | null;
69
-
70
- listCatalog: (() => Promise<CatalogRow[]>) | null;
71
-
72
- appsTtlMs?: number;
73
-
74
- sessionKey?: (entry: S) => string;
75
- }
76
-
77
- declare class ModelRouter<S> {
78
- private readonly opts;
79
- private readonly pool;
80
- private appsCache;
81
- private rowsCache;
82
- constructor(opts: ModelRouterOptions<S>);
83
-
84
- seed(appSlug: string, entry: S): void;
85
- private deployedApps;
86
-
87
- private catalogRows;
88
-
89
- private servable;
90
- private availableIds;
91
-
92
- private noDefaultApp;
93
-
94
- resolveApp(model: string | undefined): Promise<string>;
95
-
96
- sessionFor(model: string | undefined): Promise<{
97
- app: string;
98
- entry: S;
99
- }>;
100
- private keyOf;
101
-
102
- handleFor(model: string | undefined): Promise<{
103
- app: string;
104
- handle: string;
105
- }>;
106
-
107
- sessionForHandle(handle: string): Promise<{
108
- app: string;
109
- entry: S;
110
- }>;
111
-
112
- evict(app: string, entry: S): Promise<void>;
113
-
114
- modelList(): Promise<RouterModelList>;
115
-
116
- openRouterModels(): Promise<OpenRouterProviderDoc>;
117
-
118
- closeAll(): Promise<void>;
119
- }
120
-
121
9
  declare class ProxyAuthError extends Error {
122
10
  readonly status: number;
123
11
  constructor(message: string, status?: number);
@@ -174,6 +62,8 @@ interface CatalogConfig {
174
62
 
175
63
  type OwnedSession = UrunSessionLike & {
176
64
  end: () => Promise<unknown>;
65
+
66
+ detach?: () => void;
177
67
  id?: string;
178
68
  endsAt?: Date | null;
179
69
  onPhase?: (handler: (phase: {
@@ -218,6 +108,61 @@ declare class TenantRegistry {
218
108
  closeAll(): Promise<void>;
219
109
  }
220
110
 
111
+ declare const MAX_CONVERSATIONS = 512;
112
+
113
+ declare const MAX_CONVERSATION_HANDLES = 1024;
114
+
115
+ declare class ConversationCapacityError extends Error {
116
+ constructor();
117
+ }
118
+
119
+ interface PrivateConversationBackhaul {
120
+ clients: ProxyClients;
121
+
122
+ release(): Promise<void>;
123
+ }
124
+ interface ConversationBackhaulOptions {
125
+
126
+ baseUrl: string;
127
+
128
+ apiUrl: string;
129
+
130
+ catalog: CatalogConfig | null;
131
+
132
+ build?: (caller: CallerIdentity, conversation: {
133
+ id: string;
134
+ subject: string;
135
+ }) => PrivateConversationBackhaul;
136
+ }
137
+
138
+ interface PrivateConversationConnection {
139
+ clients: ProxyClients;
140
+ bindResumeHandle(handle: string): void;
141
+ clientsForResume(handle: string): Promise<ProxyClients>;
142
+
143
+ release(): Promise<void>;
144
+ }
145
+
146
+ declare class ConversationBackhauls {
147
+ private readonly opts;
148
+
149
+ private readonly byCaller;
150
+
151
+ private readonly byHandle;
152
+ constructor(opts: ConversationBackhaulOptions);
153
+ private build;
154
+
155
+ private attachEntry;
156
+ private get conversationCount();
157
+
158
+ private evictOverflow;
159
+ private dropHandleIndexFor;
160
+
161
+ connectionFor(caller: CallerIdentity): PrivateConversationConnection;
162
+
163
+ detachAll(): Promise<void>;
164
+ }
165
+
221
166
  declare const DEFAULT_PORT = 8080;
222
167
 
223
168
  declare const SERVE_FUNCTION = "serve";
@@ -250,11 +195,14 @@ interface HostedProxyOptions extends HostedConfig {
250
195
  resolver?: OrgResolver;
251
196
 
252
197
  registry?: TenantRegistry;
198
+
199
+ conversations?: ConversationBackhauls;
253
200
  }
254
201
 
255
202
  declare function createHostedProxy(options: HostedProxyOptions): {
256
203
  server: Server;
257
204
  closeAll: () => Promise<void>;
205
+ closeWebSockets: () => Promise<void>;
258
206
  };
259
207
 
260
- export { BIND_HOST, type CallerIdentity, ControlPlaneUnavailableError, DEFAULT_PORT, type HostedConfig, type HostedProxyOptions, MAX_CACHED_KEYS, MAX_TENANTS, ORG_BINDING_TTL_MS, OrgResolver, type OrgResolverOptions, ProxyAuthError, READINESS_TIMEOUT_MS, READINESS_TTL_MS, SERVE_FUNCTION, TenantRegistry, type TenantRegistryOptions, bearerFrom, createHostedProxy, resolveHostedConfig, tenantSubject };
208
+ export { BIND_HOST, type CallerIdentity, ControlPlaneUnavailableError, type ConversationBackhaulOptions, ConversationBackhauls, ConversationCapacityError, DEFAULT_PORT, type HostedConfig, type HostedProxyOptions, MAX_CACHED_KEYS, MAX_CONVERSATIONS, MAX_CONVERSATION_HANDLES, MAX_TENANTS, ORG_BINDING_TTL_MS, OrgResolver, type OrgResolverOptions, type PrivateConversationBackhaul, type PrivateConversationConnection, ProxyAuthError, READINESS_TIMEOUT_MS, READINESS_TTL_MS, SERVE_FUNCTION, TenantRegistry, type TenantRegistryOptions, bearerFrom, createHostedProxy, resolveHostedConfig, tenantSubject };
@@ -1 +1 @@
1
- import{a as e,b as o,c as t,d as n,e as p,f as s,g as T,h as E,i as _,j as a,k as S,l as f,m as x,n as i,o as y,p as O}from"../chunk-STFRT5OY.js";import"../chunk-RQBD4OAA.js";import"../chunk-K23AZPI4.js";import"../chunk-VNM4M4P3.js";import"../chunk-GBBY3PCZ.js";import"../chunk-4MSBS7M6.js";import"../chunk-5NXM4IO3.js";import"../chunk-CWJRDBDC.js";import"../chunk-OI2OY32M.js";import{c as r}from"../chunk-YSFSRI3D.js";r();export{_ as BIND_HOST,o as ControlPlaneUnavailableError,T as DEFAULT_PORT,p as MAX_CACHED_KEYS,S as MAX_TENANTS,n as ORG_BINDING_TTL_MS,s as OrgResolver,e as ProxyAuthError,y as READINESS_TIMEOUT_MS,i as READINESS_TTL_MS,E as SERVE_FUNCTION,x as TenantRegistry,t as bearerFrom,O as createHostedProxy,a as resolveHostedConfig,f as tenantSubject};
1
+ import{a as r,b as e,c as t,d as n,e as a,f as s,g as i,h as p,i as E,j as C,k as S,l as T,m as _,n as O,o as N,p as A,q as l,r as v,s as f,t as x}from"../chunk-5BZCM3RS.js";import"../chunk-I2Q3B3OG.js";import"../chunk-K23AZPI4.js";import"../chunk-QVF7NF7G.js";import"../chunk-GBBY3PCZ.js";import"../chunk-DMD5UENK.js";import"../chunk-5NXM4IO3.js";import"../chunk-CWJRDBDC.js";import"../chunk-OI2OY32M.js";import{c as o}from"../chunk-YSFSRI3D.js";o();export{E as BIND_HOST,e as ControlPlaneUnavailableError,l as ConversationBackhauls,A as ConversationCapacityError,i as DEFAULT_PORT,a as MAX_CACHED_KEYS,O as MAX_CONVERSATIONS,N as MAX_CONVERSATION_HANDLES,S as MAX_TENANTS,n as ORG_BINDING_TTL_MS,s as OrgResolver,r as ProxyAuthError,f as READINESS_TIMEOUT_MS,v as READINESS_TTL_MS,p as SERVE_FUNCTION,_ as TenantRegistry,t as bearerFrom,x as createHostedProxy,C as resolveHostedConfig,T as tenantSubject};