@urun-sh/openai 0.5.6 → 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 (52) hide show
  1. package/dist/{ResponsesClient-BE3-hx3m.d.ts → ResponsesClient-CSSrOYD8.d.ts} +5 -1
  2. package/dist/{ResponsesClient-DjZWjlFH.d.cts → ResponsesClient-_OZERUjH.d.cts} +9 -1
  3. package/dist/{chunk-7M6LY6DR.js → chunk-3JWYIKHM.js} +1 -1
  4. package/dist/chunk-45FJ5GTP.js +7 -0
  5. package/dist/{chunk-BSHT6RZZ.js → chunk-6M5JK4YC.js} +1 -1
  6. package/dist/{chunk-5HKWNK3O.js → chunk-K23AZPI4.js} +1 -1
  7. package/dist/chunk-QTVTCMJU.js +1 -0
  8. package/dist/chunk-TDRZZGUK.js +1 -0
  9. package/dist/chunk-TPH77ZOW.js +58 -0
  10. package/dist/chunk-WCMX5VOF.js +4 -0
  11. package/dist/chunk-YXK42SKC.js +1 -0
  12. package/dist/gemini-live.cjs +2 -2
  13. package/dist/gemini-live.d.cts +64 -7
  14. package/dist/gemini-live.d.ts +27 -7
  15. package/dist/gemini-live.js +1 -1
  16. package/dist/hosted/bin.cjs +37 -35
  17. package/dist/hosted/bin.js +1 -1
  18. package/dist/hosted/index.cjs +33 -31
  19. package/dist/hosted/index.d.cts +70 -4
  20. package/dist/hosted/index.d.ts +21 -4
  21. package/dist/hosted/index.js +1 -1
  22. package/dist/index.cjs +1 -1
  23. package/dist/index.d.cts +4 -4
  24. package/dist/index.d.ts +4 -4
  25. package/dist/index.js +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 +47 -45
  32. package/dist/proxy/cli.js +15 -14
  33. package/dist/proxy/index.cjs +28 -27
  34. package/dist/proxy/index.d.cts +54 -16
  35. package/dist/proxy/index.d.ts +18 -11
  36. package/dist/proxy/index.js +1 -1
  37. package/dist/{responses-turn-tNUHq5b0.d.cts → responses-turn-BfdBbey8.d.cts} +610 -23
  38. package/dist/{responses-turn-Dr37N3kH.d.ts → responses-turn-CdhIre_a.d.ts} +173 -7
  39. package/dist/{translator-Bh0Bp_Ie.d.cts → translator-CO8W_hmJ.d.cts} +1 -1
  40. package/dist/{translator-BCoRFaTs.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-CCksIcj8.d.cts → video-out-BsuLqlID.d.cts} +1 -1
  44. package/dist/{video-out-IGQ4YQ-c.d.ts → video-out-Cawtm7SF.d.ts} +1 -1
  45. package/package.json +4 -2
  46. package/dist/chunk-2T2YYBVX.js +0 -1
  47. package/dist/chunk-3WAJD62J.js +0 -4
  48. package/dist/chunk-FP4RSAIE.js +0 -1
  49. package/dist/chunk-HR5H6S7L.js +0 -1
  50. package/dist/chunk-NY23USZF.js +0 -57
  51. package/dist/chunk-VLRMJRLS.js +0 -6
  52. /package/dist/{chunk-5CCJUNH7.js → chunk-YSFSRI3D.js} +0 -0
@@ -1,11 +1,11 @@
1
1
  import { Server, IncomingMessage } from 'node:http';
2
- import { f as ProxyHandlerOptions, P as ProxyClients } from '../responses-turn-tNUHq5b0.cjs';
3
- export { D as DialObserver, a as DialReport, g as ProxyIdentity, h as ProxyVideoOutLane, S as SessionGoneError, U as UnknownModelError } from '../responses-turn-tNUHq5b0.cjs';
4
- export { h as GEMINI_LIVE_PATH, V as VIDEO_OUT_SETUP_KEY } from '../translator-Bh0Bp_Ie.cjs';
2
+ import { f as ProxyHandlerOptions, P as ProxyClients } from '../responses-turn-BfdBbey8.cjs';
3
+ export { D as DialObserver, a as DialReport, g as ProxyIdentity, h as ProxyVideoOutLane, S as SessionGoneError, U as UnknownModelError } from '../responses-turn-BfdBbey8.cjs';
4
+ export { h as GEMINI_LIVE_PATH, V as VIDEO_OUT_SETUP_KEY } from '../translator-CO8W_hmJ.cjs';
5
5
  import { WebSocket } from 'ws';
6
6
  import '../models-DUdx_Y6X.cjs';
7
- import '../video-out-CCksIcj8.cjs';
8
- import '../types-lsVTbNcH.cjs';
7
+ import '../video-out-BsuLqlID.cjs';
8
+ import '../types-CHPtJx6d.cjs';
9
9
 
10
10
  /**
11
11
  * The local OpenAI-compatible proxy — `npx @urun-sh/openai proxy`.
@@ -253,9 +253,19 @@ declare function serveGeminiLiveSocket(ws: WebSocket, call: GeminiLiveCall, regi
253
253
  * `next()` listener, so sibling lanes (Gemini Live, Responses WS) and the
254
254
  * hosted composition keep their own upgrade hooks.
255
255
  * - Clients are resolved/authenticated ASYNCHRONOUSLY BEFORE the upgrade is
256
- * accepted: no 101 is written until `resolver.resolve(req)` settles. A
257
- * thrown error maps `err.status` (default 502) to the HTTP reject;
258
- * 401/403 keep their status.
256
+ * accepted: no 101 is written until `resolver.resolve(req, signal)`
257
+ * settles. A thrown error maps `err.status` (default 502) to the HTTP
258
+ * reject; 401/403 keep their status.
259
+ * - THE CLIENT SOCKET'S OWN CLOSE is the cancellation signal for the wait:
260
+ * a `close`/`error` on the raw pre-upgrade socket aborts the signal the
261
+ * resolver rides. A resolver that settles AFTER the client vanished never
262
+ * upgrades — its binding is released through the binding's own `release`
263
+ * seam (the native detach; a still-queued admission ticket is cancelled
264
+ * underneath it by the backhaul's abort path). A client that closes after
265
+ * admission tears down through the connection's own ws-close wiring.
266
+ * - ONE structured log line per upgrade lifecycle event (`realtime_upgrade`:
267
+ * accept → admit → close, with the binding's session id and the client
268
+ * close reason) — the lane was previously invisible in the process log.
259
269
  * - The resolved binding carries a PRIVATE native uRun session (fresh or
260
270
  * explicitly-resumed) and, iff voice, a PRIVATE audio bridge — never the
261
271
  * pooled tenant lane. The connection's cross-caller claim is invariant
@@ -271,11 +281,16 @@ declare const OPENAI_REALTIME_PATH = "/v1/realtime";
271
281
  * The resolver seam — the ONLY credential, modality, and session-allocation
272
282
  * authority this adapter recognizes. Implemented by Main's composition (and
273
283
  * by tests with an injected fake). Accepted in EITHER form: a bare
274
- * `(req) => Promise<binding>` (the {@link ProxyClientsFor}-style convention)
275
- * or a `{ resolve(req) }` object.
284
+ * `(req, signal) => Promise<binding>` (the {@link ProxyClientsFor}-style
285
+ * convention) or a `{ resolve(req, signal) }` object. `signal` aborts when
286
+ * the CLIENT SOCKET closes/errors before the upgrade is accepted — the
287
+ * resolver SHOULD abandon its admission wait on it (the backhaul's
288
+ * `openAudio` rides the same signal into core `whenLive`'s own abort
289
+ * support); a resolver that ignores it still cannot admit an upgrade to a
290
+ * vanished client: the settled binding is released, never upgraded.
276
291
  */
277
- type OpenAIRealtimeResolver<S = unknown> = ((req: IncomingMessage) => Promise<RealtimeBinding<S>>) | {
278
- resolve(req: IncomingMessage): Promise<RealtimeBinding<S>>;
292
+ type OpenAIRealtimeResolver<S = unknown> = ((req: IncomingMessage, signal?: AbortSignal) => Promise<RealtimeBinding<S>>) | {
293
+ resolve(req: IncomingMessage, signal?: AbortSignal): Promise<RealtimeBinding<S>>;
279
294
  };
280
295
  interface RealtimeBinding<S = unknown> {
281
296
  /**
@@ -291,7 +306,7 @@ interface RealtimeBinding<S = unknown> {
291
306
  * A binding with neither is rejected at upgrade time, LOUD.
292
307
  */
293
308
  session?: S & {
294
- sendResponseCreate?(params: unknown, input: unknown[], requestId: string): AsyncIterable<unknown>;
309
+ sendResponseCreate?(params: unknown, input: unknown[], requestId: string): Promise<AsyncIterable<unknown>>;
295
310
  };
296
311
  clients?: Pick<ProxyClients, 'createResponse'>;
297
312
  /**
@@ -305,6 +320,15 @@ interface RealtimeBinding<S = unknown> {
305
320
  audio: {
306
321
  appendInputAudio(base64Pcm16: string): void;
307
322
  onOutputAudio(handler: (b64: string) => void): () => void;
323
+ /**
324
+ * The pooled uRun session this lane rides (backhaul `openAudio` reports
325
+ * core `Session.id`), when the backhaul knows it — the field the
326
+ * `realtime_upgrade` log line puts on every lifecycle event so an
327
+ * orphaned session is traceable from the proxy log alone. Null is the
328
+ * honest absence (an id-less session reports no id); sessionIdOf
329
+ * normalizes it to the omitted field below.
330
+ */
331
+ sessionId?: string | null;
308
332
  };
309
333
  /** Cross-caller reuse registry (invariant validation; see connection.ts). */
310
334
  openaiRealtimeClaims?: Set<RealtimeBinding['audioSession']>;
@@ -340,6 +364,17 @@ interface RealtimeBinding<S = unknown> {
340
364
  }
341
365
  interface OpenAIRealtimeOptions<S = unknown> {
342
366
  resolver: OpenAIRealtimeResolver<S>;
367
+ /**
368
+ * Where the per-upgrade structured `realtime_upgrade` lines go (ONE
369
+ * newline-terminated JSON object per lifecycle event: accept → admit →
370
+ * close). Absent, the line goes to this process's stdout through the repo's
371
+ * canonical guarded write — the hosted container's collected log stream.
372
+ * Emitted unconditionally, never behind a verbosity flag: this lane's
373
+ * lifecycle was previously invisible in the process log, which is exactly
374
+ * why an orphaned queued admission could only be diagnosed from the
375
+ * session-server side.
376
+ */
377
+ log?: (line: string) => void;
343
378
  }
344
379
  /**
345
380
  * Attach the OpenAI Realtime WS endpoint to `server`. Upgrades on any other
@@ -398,7 +433,10 @@ declare class OpenAIRealtimeConnection<S = unknown> {
398
433
  constructor(opts: {
399
434
  ws: WebSocket;
400
435
  binding: RealtimeBinding<S>;
401
- onClosed?: (conn: OpenAIRealtimeConnection<S>) => void;
436
+ /** Fired once at teardown, with the reason (the surface's structured close log rides it). */
437
+ onClosed?: (conn: OpenAIRealtimeConnection<S>, info: {
438
+ reason: string;
439
+ }) => void;
402
440
  });
403
441
  /**
404
442
  * Consume the backend's OWN turn/transcript lane (§5 stt stream): the
@@ -531,7 +569,7 @@ declare function realtimeModelOf(req: IncomingMessage): string | undefined;
531
569
  * - A voice verdict with no `openAudio` seam ⇒ 501 (a voice binding cannot
532
570
  * be served without its bridge; a voiceless downgrade is never silent).
533
571
  */
534
- declare function realtimeBindingFor(clients: Pick<ProxyClients, 'createResponse'> & Partial<Pick<ProxyClients, 'supportsAudio' | 'openAudio'>>, model: string | undefined): Promise<RealtimeBinding<ProxyClients>>;
572
+ declare function realtimeBindingFor(clients: Pick<ProxyClients, 'createResponse'> & Partial<Pick<ProxyClients, 'supportsAudio' | 'openAudio'>>, model: string | undefined, signal?: AbortSignal): Promise<RealtimeBinding<ProxyClients>>;
535
573
  /**
536
574
  * The LOCAL lane resolver: fixed pooled clients, optional fixed apiKey (the
537
575
  * same shared-secret rule the local Gemini Live lane applies — a mismatched
@@ -541,7 +579,7 @@ declare function realtimeBindingFor(clients: Pick<ProxyClients, 'createResponse'
541
579
  * {@link realtimeBindingFor} for the binding itself.
542
580
  */
543
581
  declare function fixedClientsResolver(clients: ProxyClients, apiKey?: string): {
544
- resolve(req: IncomingMessage): Promise<RealtimeBinding<ProxyClients>>;
582
+ resolve(req: IncomingMessage, signal?: AbortSignal): Promise<RealtimeBinding<ProxyClients>>;
545
583
  };
546
584
 
547
585
  export { type GeminiLiveCall, type GeminiLiveClients, OPENAI_REALTIME_PATH, type OpenAIProxyOptions, OpenAIRealtimeConnection, type OpenAIRealtimeOptions, type OpenAIRealtimeResolver, ProxyClients, type RealtimeBinding, ResumptionRegistry, attachGeminiLive, attachOpenAIRealtime, createOpenAIProxy, fixedClientsResolver, realtimeBindingFor, realtimeModelOf, serveGeminiLiveSocket };
@@ -1,11 +1,11 @@
1
1
  import { Server, IncomingMessage } from 'node:http';
2
- import { f as ProxyHandlerOptions, P as ProxyClients } from '../responses-turn-Dr37N3kH.js';
3
- export { D as DialObserver, a as DialReport, g as ProxyIdentity, h as ProxyVideoOutLane, S as SessionGoneError, U as UnknownModelError } from '../responses-turn-Dr37N3kH.js';
4
- export { h as GEMINI_LIVE_PATH, V as VIDEO_OUT_SETUP_KEY } from '../translator-BCoRFaTs.js';
2
+ import { f as ProxyHandlerOptions, P as ProxyClients } from '../responses-turn-CdhIre_a.js';
3
+ export { D as DialObserver, a as DialReport, g as ProxyIdentity, h as ProxyVideoOutLane, S as SessionGoneError, U as UnknownModelError } from '../responses-turn-CdhIre_a.js';
4
+ export { h as GEMINI_LIVE_PATH, V as VIDEO_OUT_SETUP_KEY } from '../translator-Ddd65sXR.js';
5
5
  import { WebSocket } from 'ws';
6
6
  import '../models-DUdx_Y6X.js';
7
- import '../video-out-IGQ4YQ-c.js';
8
- import '../types-lsVTbNcH.js';
7
+ import '../video-out-Cawtm7SF.js';
8
+ import '../types-CHPtJx6d.js';
9
9
 
10
10
  interface OpenAIProxyOptions extends ProxyHandlerOptions {
11
11
  clients: ProxyClients;
@@ -56,13 +56,13 @@ declare function serveGeminiLiveSocket(ws: WebSocket, call: GeminiLiveCall, regi
56
56
 
57
57
  declare const OPENAI_REALTIME_PATH = "/v1/realtime";
58
58
 
59
- type OpenAIRealtimeResolver<S = unknown> = ((req: IncomingMessage) => Promise<RealtimeBinding<S>>) | {
60
- resolve(req: IncomingMessage): Promise<RealtimeBinding<S>>;
59
+ type OpenAIRealtimeResolver<S = unknown> = ((req: IncomingMessage, signal?: AbortSignal) => Promise<RealtimeBinding<S>>) | {
60
+ resolve(req: IncomingMessage, signal?: AbortSignal): Promise<RealtimeBinding<S>>;
61
61
  };
62
62
  interface RealtimeBinding<S = unknown> {
63
63
 
64
64
  session?: S & {
65
- sendResponseCreate?(params: unknown, input: unknown[], requestId: string): AsyncIterable<unknown>;
65
+ sendResponseCreate?(params: unknown, input: unknown[], requestId: string): Promise<AsyncIterable<unknown>>;
66
66
  };
67
67
  clients?: Pick<ProxyClients, 'createResponse'>;
68
68
 
@@ -72,6 +72,8 @@ interface RealtimeBinding<S = unknown> {
72
72
  audio: {
73
73
  appendInputAudio(base64Pcm16: string): void;
74
74
  onOutputAudio(handler: (b64: string) => void): () => void;
75
+
76
+ sessionId?: string | null;
75
77
  };
76
78
 
77
79
  openaiRealtimeClaims?: Set<RealtimeBinding['audioSession']>;
@@ -92,6 +94,8 @@ interface RealtimeBinding<S = unknown> {
92
94
  }
93
95
  interface OpenAIRealtimeOptions<S = unknown> {
94
96
  resolver: OpenAIRealtimeResolver<S>;
97
+
98
+ log?: (line: string) => void;
95
99
  }
96
100
 
97
101
  declare function attachOpenAIRealtime<S = unknown>(server: Server, options: OpenAIRealtimeOptions<S>): () => Promise<void>;
@@ -130,7 +134,10 @@ declare class OpenAIRealtimeConnection<S = unknown> {
130
134
  constructor(opts: {
131
135
  ws: WebSocket;
132
136
  binding: RealtimeBinding<S>;
133
- onClosed?: (conn: OpenAIRealtimeConnection<S>) => void;
137
+
138
+ onClosed?: (conn: OpenAIRealtimeConnection<S>, info: {
139
+ reason: string;
140
+ }) => void;
134
141
  });
135
142
 
136
143
  private startTurnLane;
@@ -177,10 +184,10 @@ declare class OpenAIRealtimeConnection<S = unknown> {
177
184
 
178
185
  declare function realtimeModelOf(req: IncomingMessage): string | undefined;
179
186
 
180
- declare function realtimeBindingFor(clients: Pick<ProxyClients, 'createResponse'> & Partial<Pick<ProxyClients, 'supportsAudio' | 'openAudio'>>, model: string | undefined): Promise<RealtimeBinding<ProxyClients>>;
187
+ declare function realtimeBindingFor(clients: Pick<ProxyClients, 'createResponse'> & Partial<Pick<ProxyClients, 'supportsAudio' | 'openAudio'>>, model: string | undefined, signal?: AbortSignal): Promise<RealtimeBinding<ProxyClients>>;
181
188
 
182
189
  declare function fixedClientsResolver(clients: ProxyClients, apiKey?: string): {
183
- resolve(req: IncomingMessage): Promise<RealtimeBinding<ProxyClients>>;
190
+ resolve(req: IncomingMessage, signal?: AbortSignal): Promise<RealtimeBinding<ProxyClients>>;
184
191
  };
185
192
 
186
193
  export { type GeminiLiveCall, type GeminiLiveClients, OPENAI_REALTIME_PATH, type OpenAIProxyOptions, OpenAIRealtimeConnection, type OpenAIRealtimeOptions, type OpenAIRealtimeResolver, ProxyClients, type RealtimeBinding, ResumptionRegistry, attachGeminiLive, attachOpenAIRealtime, createOpenAIProxy, fixedClientsResolver, realtimeBindingFor, realtimeModelOf, serveGeminiLiveSocket };
@@ -1 +1 @@
1
- import{Q as I,a as n,b as p,c as m,f as l,g as a,h as x,i as s,j as O,k as f}from"../chunk-NY23USZF.js";import{d as r,e as i}from"../chunk-3WAJD62J.js";import{a as o,h as t}from"../chunk-7M6LY6DR.js";import"../chunk-BSHT6RZZ.js";import{c as e}from"../chunk-5CCJUNH7.js";e();export{o as GEMINI_LIVE_PATH,a as OPENAI_REALTIME_PATH,l as OpenAIRealtimeConnection,n as ResumptionRegistry,i as SessionGoneError,r as UnknownModelError,t as VIDEO_OUT_SETUP_KEY,p as attachGeminiLive,x as attachOpenAIRealtime,I as createOpenAIProxy,f as fixedClientsResolver,O as realtimeBindingFor,s as realtimeModelOf,m as serveGeminiLiveSocket};
1
+ import{B as l,C as a,D as x,E as s,F as O,G as f,S as I,a as n,b as p,c as m}from"../chunk-TPH77ZOW.js";import{d as r,e as i}from"../chunk-WCMX5VOF.js";import{a as o,h as t}from"../chunk-3JWYIKHM.js";import"../chunk-6M5JK4YC.js";import{c as e}from"../chunk-YSFSRI3D.js";e();export{o as GEMINI_LIVE_PATH,a as OPENAI_REALTIME_PATH,l as OpenAIRealtimeConnection,n as ResumptionRegistry,i as SessionGoneError,r as UnknownModelError,t as VIDEO_OUT_SETUP_KEY,p as attachGeminiLive,x as attachOpenAIRealtime,I as createOpenAIProxy,f as fixedClientsResolver,O as realtimeBindingFor,s as realtimeModelOf,m as serveGeminiLiveSocket};