@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,12 +1,205 @@
1
- import { Server, IncomingMessage } from 'node:http';
2
- import { f as ProxyHandlerOptions, P as ProxyClients } from '../responses-turn-DXrwiPJh.cjs';
3
- export { D as DialObserver, a as DialReport, g as ProxyIdentity, h as ProxyVideoOutLane, S as SessionGoneError, U as UnknownModelError } from '../responses-turn-DXrwiPJh.cjs';
1
+ import { IncomingMessage, Server } from 'node:http';
2
+ import { P as ProxyClients, f as ProxyHandlerOptions, R as RealtimeCompanionsFor } from '../composite-DtBebn0Y.cjs';
3
+ export { D as DialObserver, a as DialReport, g as ProxyIdentity, h as ProxyVideoOutLane, S as SessionGoneError, U as UnknownModelError } from '../composite-DtBebn0Y.cjs';
4
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
- import '../models-DUdx_Y6X.cjs';
6
+ import '../models-D7F0bLJ3.cjs';
7
7
  import '../video-out-BsuLqlID.cjs';
8
8
  import '../types-CHPtJx6d.cjs';
9
9
 
10
+ /**
11
+ * `attachOpenAIRealtime(server, options)` — the WS upgrade hook for the OpenAI
12
+ * Realtime surface (GA protocol subset; see protocol.ts for the event subset).
13
+ *
14
+ * Contract (Main-owned composition; this lane claims ONLY `/v1/realtime`):
15
+ * - Upgrades on any other path are passed through UNTOUCHED — a plain
16
+ * `next()` listener, so sibling lanes (Gemini Live, Responses WS) and the
17
+ * hosted composition keep their own upgrade hooks.
18
+ * - Clients are resolved/authenticated ASYNCHRONOUSLY BEFORE the upgrade is
19
+ * accepted: no 101 is written until `resolver.resolve(req, signal)`
20
+ * settles. A thrown error maps `err.status` (default 502) to the HTTP
21
+ * reject; 401/403 keep their status.
22
+ * - THE CLIENT SOCKET'S OWN CLOSE is the cancellation signal for the wait:
23
+ * a `close`/`error` on the raw pre-upgrade socket aborts the signal the
24
+ * resolver rides. A resolver that settles AFTER the client vanished never
25
+ * upgrades — its binding is released through the binding's own `release`
26
+ * seam (the native detach; a still-queued admission ticket is cancelled
27
+ * underneath it by the backhaul's abort path). A client that closes after
28
+ * admission tears down through the connection's own ws-close wiring.
29
+ * - ONE structured log line per upgrade lifecycle event (`realtime_upgrade`:
30
+ * accept → admit → close, with the binding's session id and the client
31
+ * close reason) — the lane was previously invisible in the process log.
32
+ * - The resolved binding carries a PRIVATE native uRun session (fresh or
33
+ * explicitly-resumed) and, iff voice, a PRIVATE audio bridge — never the
34
+ * pooled tenant lane. The connection's cross-caller claim is invariant
35
+ * validation, not capacity policy.
36
+ * - Returns an async close function: waits for every touched socket to
37
+ * settle, then closes the internal WebSocketServer. It does NOT end the
38
+ * native uRun sessions (detach ≠ session death — resume is Main-owned;
39
+ * the binding seam decides lifetime).
40
+ */
41
+
42
+ declare const OPENAI_REALTIME_PATH = "/v1/realtime";
43
+ /**
44
+ * The resolver seam — the ONLY credential, modality, and session-allocation
45
+ * authority this adapter recognizes. Implemented by Main's composition (and
46
+ * by tests with an injected fake). Accepted in EITHER form: a bare
47
+ * `(req, signal) => Promise<binding>` (the {@link ProxyClientsFor}-style
48
+ * convention) or a `{ resolve(req, signal) }` object. `signal` aborts when
49
+ * the CLIENT SOCKET closes/errors before the upgrade is accepted — the
50
+ * resolver SHOULD abandon its admission wait on it (the backhaul's
51
+ * `openAudioOn` rides the same signal into core `whenLive`'s own abort
52
+ * support); a resolver that ignores it still cannot admit an upgrade to a
53
+ * vanished client: the settled binding is released, never upgraded.
54
+ */
55
+ type OpenAIRealtimeResolver<S = unknown> = ((req: IncomingMessage, signal?: AbortSignal) => Promise<RealtimeBinding<S>>) | {
56
+ resolve(req: IncomingMessage, signal?: AbortSignal): Promise<RealtimeBinding<S>>;
57
+ };
58
+ interface RealtimeBinding<S = unknown> {
59
+ /**
60
+ * The PRIVATE native uRun session serving this conversation (the shared
61
+ * per-conversation factory in hosted/tenants.ts allocates it; reuse/multi-
62
+ * attach is sanctioned ONLY for the SAME authorized conversation on an
63
+ * explicit resume — two different conversations MUST NOT receive one
64
+ * session). The upstream turn seam is EITHER form:
65
+ * - `session.sendResponseCreate(params, input, requestId)` (the direct
66
+ * SdkTransport-style seam), or
67
+ * - `clients.createResponse(params)` — the canonical ProxyClients seam
68
+ * shape (`input` rides inside `params`). The shared binding composition
69
+ * (binding.ts, ENG-446) hands out a PINNED view of it: the call dials
70
+ * `createResponseOn(handle, …)` on the ONE pooled session the binding
71
+ * resolved with the audio bridge, so no turn on the connection can
72
+ * reach a second pooled session behind the bridge's back.
73
+ * A binding with neither is rejected at upgrade time, LOUD.
74
+ */
75
+ session?: S & {
76
+ sendResponseCreate?(params: unknown, input: unknown[], requestId: string): Promise<AsyncIterable<unknown>>;
77
+ };
78
+ clients?: Pick<ProxyClients, 'createResponse'>;
79
+ /**
80
+ * Authoritative modality verdict from the resolver. A function NAME proves
81
+ * nothing — without `voice: true`, audio events are refused and no audio
82
+ * primitive is ever opened on the session.
83
+ */
84
+ voice: boolean;
85
+ /** The PRIVATE audio bridge for THIS conversation (required iff `voice`). */
86
+ audioSession?: {
87
+ audio: {
88
+ appendInputAudio(base64Pcm16: string): void;
89
+ onOutputAudio(handler: (b64: string) => void): () => void;
90
+ /**
91
+ * The pooled uRun session this lane rides (backhaul `openAudioOn`
92
+ * reports core `Session.id`), when the backhaul knows it — the field the
93
+ * `realtime_upgrade` log line puts on every lifecycle event so an
94
+ * orphaned session is traceable from the proxy log alone. Null is the
95
+ * honest absence (an id-less session reports no id); sessionIdOf
96
+ * normalizes it to the omitted field below.
97
+ */
98
+ sessionId?: string | null;
99
+ };
100
+ /** Cross-caller reuse registry (invariant validation; see connection.ts). */
101
+ openaiRealtimeClaims?: Set<RealtimeBinding['audioSession']>;
102
+ };
103
+ /** `model` the binding names for this conversation (overrides session config default). */
104
+ model?: string;
105
+ /**
106
+ * The GA transcription-session intent (`?intent=transcription`): this
107
+ * connection is a TRANSCRIPTION session — transcription events flow
108
+ * without the client opting in, and `response.create` answers the loud
109
+ * `unsupported` error (the connection stays open) because there are no
110
+ * model turns to create. Set by the shared binding composition (binding.ts)
111
+ * only when the resolver's URL carried the intent AND the model's catalog
112
+ * row vouches stt (the binding carries `turns`). Absent = the realtime
113
+ * (voice) session, today's behaviour.
114
+ */
115
+ intent?: 'transcription';
116
+ /** True when `session` is a resumed authorized session (vs a fresh private one). */
117
+ resumed?: boolean;
118
+ /**
119
+ * The backend's OWN turn/transcript lane — the §5 `stt` named stream
120
+ * (urun.serve.transcribe_bridge wire shape: `t` = delta/final/turn_start/
121
+ * turn_end/turn_eager_end/turn_resumed, `delta` text, additive `start_ms`
122
+ * and semantic-VAD `confidence`). The resolver maps `session.stream('stt')
123
+ * .messages()` onto this. Its `turn_end` IS the native commit and
124
+ * `turn_start` IS the native barge-in — the adapter drives server-VAD
125
+ * emulation, real transcription events, and model-visible committed audio
126
+ * from it. Absent = the backend wired no turn lane: manual mode only.
127
+ *
128
+ * The CONSUMER passes its own lifecycle `signal` (the realtime connection's
129
+ * turn-lane controller): the lane must END its stream subscription when it
130
+ * aborts — the transport races its pulls against it — so the subscription
131
+ * never outlives the consumer. A consumer that passes none gets an
132
+ * un-raced lane (its own teardown is then its own problem).
133
+ */
134
+ turns?: (signal?: AbortSignal) => AsyncIterable<{
135
+ kind: 'delta' | 'final' | 'turn_start' | 'turn_end' | 'turn_eager_end' | 'turn_resumed';
136
+ text?: string;
137
+ confidence?: number;
138
+ startMs?: number;
139
+ }>;
140
+ /**
141
+ * THE COMPOSITE LANE (ENG-451, openai-realtime/composite.ts): this binding
142
+ * composes THREE pinned sessions — the `stt` leg behind `turns` and the
143
+ * composed bridge's IN side, the bound chat row behind
144
+ * `clients.createResponse`, and the `tts` leg behind the bridge's OUT side
145
+ * and the per-sentence synthesis turns. The connection keys its
146
+ * live-transcription-in semantics on this marker: appends stream to the
147
+ * stt leg live, the client's commits own turn boundaries, a committed
148
+ * item's pending transcript gates the model turn (and is written into the
149
+ * item — it is the chat leg's input), and `turn_detection: null` is the
150
+ * only accepted mode. A dead leg's failure is a `SessionGoneError` NAMING
151
+ * the leg — the loud `session_gone` close carries the name.
152
+ */
153
+ composite?: true;
154
+ /**
155
+ * THE COMPOSITE TURN'S PROMPT CANCEL (ENG-451): stop the ACTIVE turn's
156
+ * legs beyond the turn seam — the composite binding aborts its per-turn
157
+ * controller, which unwinds the tts leg's in-flight synthesis read and
158
+ * drops its queued sentence chunks NOW. The connection calls it from
159
+ * `response.cancel` and from teardown; the for-await `break` alone only
160
+ * unwinds at the turn stream's NEXT event, which is too late for legs
161
+ * that keep consuming GPU on their own. Absent (every one-session
162
+ * binding) = nothing to stop beyond the stream, exactly as before.
163
+ */
164
+ cancelActiveTurn?: () => void;
165
+ /**
166
+ * Release THIS attachment when the socket closes (the hosted
167
+ * conversation-factory seam — the twin of the Gemini Live binding's
168
+ * `release`): per-attachment release, native detach underneath, the named
169
+ * session itself stays live. Absent (the local fixed-clients lane) = the
170
+ * pooled sessions are the process's own and outlive the socket.
171
+ */
172
+ release?: () => Promise<void> | void;
173
+ }
174
+ interface OpenAIRealtimeOptions<S = unknown> {
175
+ resolver: OpenAIRealtimeResolver<S>;
176
+ /**
177
+ * Where the per-upgrade structured `realtime_upgrade` lines go (ONE
178
+ * newline-terminated JSON object per lifecycle event: accept → admit →
179
+ * close). Absent, the line goes to this process's stdout through the repo's
180
+ * canonical guarded write — the hosted container's collected log stream.
181
+ * Emitted unconditionally, never behind a verbosity flag: this lane's
182
+ * lifecycle was previously invisible in the process log, which is exactly
183
+ * why an orphaned queued admission could only be diagnosed from the
184
+ * session-server side.
185
+ */
186
+ log?: (line: string) => void;
187
+ /**
188
+ * Where the caller-message boundary's WITHHOLD receipts go (ENG-538): every
189
+ * time a realtime event keeps raw error text off the wire, the raw text is
190
+ * owed here — one newline-terminated line per withheld failure, carrying the
191
+ * connection/session ids for correlation. Absent, the receipt goes to
192
+ * `console.error` of THIS process; the hosted proxy passes its canonical
193
+ * operator sink so nothing is ever dropped on the floor.
194
+ */
195
+ operatorLog?: (line: string) => void;
196
+ }
197
+ /**
198
+ * Attach the OpenAI Realtime WS endpoint to `server`. Upgrades on any other
199
+ * path pass through untouched. Returns an async close function.
200
+ */
201
+ declare function attachOpenAIRealtime<S = unknown>(server: Server, options: OpenAIRealtimeOptions<S>): () => Promise<void>;
202
+
10
203
  /**
11
204
  * The local OpenAI-compatible proxy — `npx @urun-sh/openai proxy`.
12
205
  *
@@ -29,6 +222,15 @@ import '../types-CHPtJx6d.cjs';
29
222
  /** The proxy server's own options: a FIXED backhaul (the local CLI lane). */
30
223
  interface OpenAIProxyOptions extends ProxyHandlerOptions {
31
224
  clients: ProxyClients;
225
+ /**
226
+ * THE COMPOSITE REALTIME LANE'S PAIRING SOURCE (ENG-451): for each chat-row
227
+ * model, the `{stt, tts, voice?}` trio that makes it realtime-capable on
228
+ * `WS /v1/realtime` (openai-realtime/composite.ts). Absent ⇒ the seam
229
+ * answers `null` ⇒ a chat model keeps today's loud 404. The PRODUCTION
230
+ * source of the pairing (catalog field vs proxy config) is an open owner
231
+ * decision — this option is the seam the eventual source wires into.
232
+ */
233
+ realtimeCompanions?: RealtimeCompanionsFor;
32
234
  }
33
235
  /** Build (not listen) the proxy server — the caller owns listen/close. */
34
236
  declare function createOpenAIProxy(options: OpenAIProxyOptions): Server;
@@ -244,165 +446,6 @@ declare function attachGeminiLive(server: Server, options: GeminiLiveOptions): (
244
446
  */
245
447
  declare function serveGeminiLiveSocket(ws: WebSocket, call: GeminiLiveCall, registry?: ResumptionRegistry): void;
246
448
 
247
- /**
248
- * `attachOpenAIRealtime(server, options)` — the WS upgrade hook for the OpenAI
249
- * Realtime surface (GA protocol subset; see protocol.ts for the event subset).
250
- *
251
- * Contract (Main-owned composition; this lane claims ONLY `/v1/realtime`):
252
- * - Upgrades on any other path are passed through UNTOUCHED — a plain
253
- * `next()` listener, so sibling lanes (Gemini Live, Responses WS) and the
254
- * hosted composition keep their own upgrade hooks.
255
- * - Clients are resolved/authenticated ASYNCHRONOUSLY BEFORE the upgrade is
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.
269
- * - The resolved binding carries a PRIVATE native uRun session (fresh or
270
- * explicitly-resumed) and, iff voice, a PRIVATE audio bridge — never the
271
- * pooled tenant lane. The connection's cross-caller claim is invariant
272
- * validation, not capacity policy.
273
- * - Returns an async close function: waits for every touched socket to
274
- * settle, then closes the internal WebSocketServer. It does NOT end the
275
- * native uRun sessions (detach ≠ session death — resume is Main-owned;
276
- * the binding seam decides lifetime).
277
- */
278
-
279
- declare const OPENAI_REALTIME_PATH = "/v1/realtime";
280
- /**
281
- * The resolver seam — the ONLY credential, modality, and session-allocation
282
- * authority this adapter recognizes. Implemented by Main's composition (and
283
- * by tests with an injected fake). Accepted in EITHER form: a bare
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
- * `openAudioOn` 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.
291
- */
292
- type OpenAIRealtimeResolver<S = unknown> = ((req: IncomingMessage, signal?: AbortSignal) => Promise<RealtimeBinding<S>>) | {
293
- resolve(req: IncomingMessage, signal?: AbortSignal): Promise<RealtimeBinding<S>>;
294
- };
295
- interface RealtimeBinding<S = unknown> {
296
- /**
297
- * The PRIVATE native uRun session serving this conversation (the shared
298
- * per-conversation factory in hosted/tenants.ts allocates it; reuse/multi-
299
- * attach is sanctioned ONLY for the SAME authorized conversation on an
300
- * explicit resume — two different conversations MUST NOT receive one
301
- * session). The upstream turn seam is EITHER form:
302
- * - `session.sendResponseCreate(params, input, requestId)` (the direct
303
- * SdkTransport-style seam), or
304
- * - `clients.createResponse(params)` — the canonical ProxyClients seam
305
- * shape (`input` rides inside `params`). The shared binding composition
306
- * (binding.ts, ENG-446) hands out a PINNED view of it: the call dials
307
- * `createResponseOn(handle, …)` on the ONE pooled session the binding
308
- * resolved with the audio bridge, so no turn on the connection can
309
- * reach a second pooled session behind the bridge's back.
310
- * A binding with neither is rejected at upgrade time, LOUD.
311
- */
312
- session?: S & {
313
- sendResponseCreate?(params: unknown, input: unknown[], requestId: string): Promise<AsyncIterable<unknown>>;
314
- };
315
- clients?: Pick<ProxyClients, 'createResponse'>;
316
- /**
317
- * Authoritative modality verdict from the resolver. A function NAME proves
318
- * nothing — without `voice: true`, audio events are refused and no audio
319
- * primitive is ever opened on the session.
320
- */
321
- voice: boolean;
322
- /** The PRIVATE audio bridge for THIS conversation (required iff `voice`). */
323
- audioSession?: {
324
- audio: {
325
- appendInputAudio(base64Pcm16: string): void;
326
- onOutputAudio(handler: (b64: string) => void): () => void;
327
- /**
328
- * The pooled uRun session this lane rides (backhaul `openAudioOn`
329
- * reports core `Session.id`), when the backhaul knows it — the field the
330
- * `realtime_upgrade` log line puts on every lifecycle event so an
331
- * orphaned session is traceable from the proxy log alone. Null is the
332
- * honest absence (an id-less session reports no id); sessionIdOf
333
- * normalizes it to the omitted field below.
334
- */
335
- sessionId?: string | null;
336
- };
337
- /** Cross-caller reuse registry (invariant validation; see connection.ts). */
338
- openaiRealtimeClaims?: Set<RealtimeBinding['audioSession']>;
339
- };
340
- /** `model` the binding names for this conversation (overrides session config default). */
341
- model?: string;
342
- /**
343
- * The GA transcription-session intent (`?intent=transcription`): this
344
- * connection is a TRANSCRIPTION session — transcription events flow
345
- * without the client opting in, and `response.create` answers the loud
346
- * `unsupported` error (the connection stays open) because there are no
347
- * model turns to create. Set by the shared binding composition (binding.ts)
348
- * only when the resolver's URL carried the intent AND the model's catalog
349
- * row vouches stt (the binding carries `turns`). Absent = the realtime
350
- * (voice) session, today's behaviour.
351
- */
352
- intent?: 'transcription';
353
- /** True when `session` is a resumed authorized session (vs a fresh private one). */
354
- resumed?: boolean;
355
- /**
356
- * The backend's OWN turn/transcript lane — the §5 `stt` named stream
357
- * (urun.serve.transcribe_bridge wire shape: `t` = delta/final/turn_start/
358
- * turn_end/turn_eager_end/turn_resumed, `delta` text, additive `start_ms`
359
- * and semantic-VAD `confidence`). The resolver maps `session.stream('stt')
360
- * .messages()` onto this. Its `turn_end` IS the native commit and
361
- * `turn_start` IS the native barge-in — the adapter drives server-VAD
362
- * emulation, real transcription events, and model-visible committed audio
363
- * from it. Absent = the backend wired no turn lane: manual mode only.
364
- *
365
- * The CONSUMER passes its own lifecycle `signal` (the realtime connection's
366
- * turn-lane controller): the lane must END its stream subscription when it
367
- * aborts — the transport races its pulls against it — so the subscription
368
- * never outlives the consumer. A consumer that passes none gets an
369
- * un-raced lane (its own teardown is then its own problem).
370
- */
371
- turns?: (signal?: AbortSignal) => AsyncIterable<{
372
- kind: 'delta' | 'final' | 'turn_start' | 'turn_end' | 'turn_eager_end' | 'turn_resumed';
373
- text?: string;
374
- confidence?: number;
375
- startMs?: number;
376
- }>;
377
- /**
378
- * Release THIS attachment when the socket closes (the hosted
379
- * conversation-factory seam — the twin of the Gemini Live binding's
380
- * `release`): per-attachment release, native detach underneath, the named
381
- * session itself stays live. Absent (the local fixed-clients lane) = the
382
- * pooled sessions are the process's own and outlive the socket.
383
- */
384
- release?: () => Promise<void> | void;
385
- }
386
- interface OpenAIRealtimeOptions<S = unknown> {
387
- resolver: OpenAIRealtimeResolver<S>;
388
- /**
389
- * Where the per-upgrade structured `realtime_upgrade` lines go (ONE
390
- * newline-terminated JSON object per lifecycle event: accept → admit →
391
- * close). Absent, the line goes to this process's stdout through the repo's
392
- * canonical guarded write — the hosted container's collected log stream.
393
- * Emitted unconditionally, never behind a verbosity flag: this lane's
394
- * lifecycle was previously invisible in the process log, which is exactly
395
- * why an orphaned queued admission could only be diagnosed from the
396
- * session-server side.
397
- */
398
- log?: (line: string) => void;
399
- }
400
- /**
401
- * Attach the OpenAI Realtime WS endpoint to `server`. Upgrades on any other
402
- * path pass through untouched. Returns an async close function.
403
- */
404
- declare function attachOpenAIRealtime<S = unknown>(server: Server, options: OpenAIRealtimeOptions<S>): () => Promise<void>;
405
-
406
449
  /**
407
450
  * One authenticated OpenAI Realtime WS connection — the adapter's core.
408
451
  *
@@ -441,6 +484,13 @@ declare class OpenAIRealtimeConnection<S = unknown> {
441
484
  private readonly ws;
442
485
  private readonly binding;
443
486
  private readonly onClosed?;
487
+ /**
488
+ * THE OPERATOR ERROR SINK (ENG-538): where this connection's caller-message
489
+ * projections send the internal detail they withhold from a caller frame.
490
+ * Absent, this process's stderr — the `buildOpenRouterDoc` warn-sink
491
+ * convention, never nothing.
492
+ */
493
+ private readonly operatorLog;
444
494
  private config;
445
495
  private readonly sessionId;
446
496
  private readonly conversationId;
@@ -455,6 +505,12 @@ declare class OpenAIRealtimeConnection<S = unknown> {
455
505
  /** Output events already flowed for the active response (post-flush faults → error event, pre-flush → response.failed). */
456
506
  private responseFlushed;
457
507
  private cancelled;
508
+ /**
509
+ * Resolves a composite turn parked on a pending committed transcript (the
510
+ * engine's final/turn_end that completes the item). Set by the park,
511
+ * resolved by the completion, by `response.cancel`, and by teardown.
512
+ */
513
+ private pendingTranscriptSettled;
458
514
  private voiceClaimed;
459
515
  private audioLaneOwner;
460
516
  private audioUnsubscribe;
@@ -503,6 +559,11 @@ declare class OpenAIRealtimeConnection<S = unknown> {
503
559
  onClosed?: (conn: OpenAIRealtimeConnection<S>, info: {
504
560
  reason: string;
505
561
  }) => void;
562
+ /**
563
+ * THE OPERATOR ERROR SINK (ENG-538): where withheld internal detail goes.
564
+ * Absent, this process's stderr.
565
+ */
566
+ operatorLog?: (line: string) => void;
506
567
  });
507
568
  /**
508
569
  * Consume the backend's OWN turn/transcript lane (§5 stt stream): the
@@ -526,8 +587,20 @@ declare class OpenAIRealtimeConnection<S = unknown> {
526
587
  * `session.type: "transcription"` — the latter only accepted behind a
527
588
  * turns lane, so a transcription session always has a transcript source). */
528
589
  private isTranscriptionSession;
590
+ /**
591
+ * True when this session's input audio rides a LIVE transcription leg
592
+ * (ENG-451): a transcription session, or the composite lane's stt leg.
593
+ * Appends stream to the engine as they arrive (it transcribes while the
594
+ * user speaks — the byte counter is the only local hold), the client's
595
+ * commits own the turn boundaries, and a committed item's transcript
596
+ * completes on the lane's own `final`/`turn_end`. The composite differs
597
+ * from a transcription session in exactly one thing: `response.create`
598
+ * opens the model turn (over the chat leg).
599
+ */
600
+ private liveSttIn;
529
601
  /** True when input-transcription events flow: the client opted in on a
530
- * voice session, or ALWAYS on a transcription session (no opt-in needed). */
602
+ * voice session, or ALWAYS on a live-transcription-leg session (no opt-in
603
+ * needed). */
531
604
  private transcriptionEventsOn;
532
605
  /**
533
606
  * Discharge a pending manual transcription commit: the ONE
@@ -537,6 +610,23 @@ declare class OpenAIRealtimeConnection<S = unknown> {
537
610
  * lane's own boundary events drive this — no timers anywhere.
538
611
  */
539
612
  private completePendingTranscription;
613
+ /**
614
+ * The lane failed under a committed item still awaiting its transcript:
615
+ * the GA per-item `…transcription.failed` (the item gets NO `completed`)
616
+ * and the item's `conversation.item.done` — the item is final, untranscribed.
617
+ */
618
+ private failPendingTranscription;
619
+ /** Write the delivered transcript back onto the item's audio part (the
620
+ * item's own echo — `conversation.item.done`, retrieve, later-turn input —
621
+ * must carry the text the completed event named). */
622
+ private writeItemTranscript;
623
+ /**
624
+ * `conversation.item.done` — the item's final form, named with the item
625
+ * that precedes it in the conversation. Silent when the item is no longer
626
+ * in the transcript (client-deleted, evicted): a done for an item the
627
+ * conversation no longer holds would be a phantom.
628
+ */
629
+ private emitItemDone;
540
630
  /** One backend turn/transcript event → REAL GA protocol events. */
541
631
  private onTurnEvent;
542
632
  /** The committed turn's transcript, consumed once (null = none). */
@@ -571,6 +661,15 @@ declare class OpenAIRealtimeConnection<S = unknown> {
571
661
  */
572
662
  private upstreamStream;
573
663
  private startResponse;
664
+ /**
665
+ * The composite turn's tts-leg control keys (ENG-451): the effective
666
+ * output-modality ask — the turn's `output_modalities`/`modalities` when it
667
+ * carries one, else the session's negotiated modalities (the composite's
668
+ * honest default `['text','audio']`). These keys are THIS lane's controls;
669
+ * the composite binding strips them off the chat leg's envelope and reads
670
+ * them to decide whether the tts leg runs at all.
671
+ */
672
+ private compositeTurnAsk;
574
673
  /**
575
674
  * Bridge voice OUT frame → `response.output_audio.delta` on the open turn.
576
675
  *
@@ -589,11 +688,39 @@ declare class OpenAIRealtimeConnection<S = unknown> {
589
688
  private messageItemAdded;
590
689
  /** true when an audio delta opened the message item this turn. */
591
690
  private messageItemOpenForAudio;
691
+ /**
692
+ * The last item this turn announced via `conversation.item.added`. Mid-turn
693
+ * added events chain `previous_item_id` from it, not from the transcript
694
+ * tail: the turn's items are adopted into `this.items` only at turn close
695
+ * (closeOpenItems), so while the turn streams the tail still names the
696
+ * pre-turn item and every added event after the first would repeat it —
697
+ * disagreeing with the done events, which emit in first-open order.
698
+ * Seeded from the transcript tail at startResponse, like messageItemAdded.
699
+ */
700
+ private turnLastAnnouncedItemId;
701
+ /**
702
+ * True when the turn's text output is the SPOKEN transcript (audio
703
+ * modality): the session negotiated audio output, or the audio lane has
704
+ * already spoken this turn. The text delta family for such a turn is
705
+ * `response.output_audio_transcript.*`.
706
+ */
707
+ private turnOutputIsAudio;
708
+ /**
709
+ * The assistant message item entering the conversation — GA mirrors every
710
+ * `response.output_item.added` as `conversation.item.added` (the event
711
+ * Pipecat's realtime lane opens the LLM response on, and tracks function
712
+ * calls by). `previous_item_id` chains from the turn's last announced item
713
+ * so a turn with a message and function calls (or several calls) keeps its
714
+ * added events in order, agreeing with the done events.
715
+ */
716
+ private emitAssistantItemAdded;
592
717
  private beginMessageItem;
593
718
  private beginAudioMessageItem;
594
719
  /**
595
720
  * Close every item the turn opened, in first-open order, adopt them into
596
- * the transcript, and emit their `done` events.
721
+ * the transcript, and emit their `done` events — each `response.output_item
722
+ * .done` mirrored as the GA `conversation.item.done` that finalizes the
723
+ * item in the conversation.
597
724
  */
598
725
  private closeOpenItems;
599
726
  private responseObject;
@@ -656,6 +783,21 @@ declare class OpenAIRealtimeConnection<S = unknown> {
656
783
  private pushItem;
657
784
  private itemToProtocol;
658
785
  private send;
786
+ /**
787
+ * THE CALLER-MESSAGE BOUNDARY (ENG-538, final review round 5) for the
788
+ * realtime lane — this surface's twin of the HTTP/WS lanes' projection. A
789
+ * thrown failure reaching a caller-facing event goes through the boundary's
790
+ * typed table: caller-authored messages relay verbatim, operator-authored
791
+ * ones map to their caller line, and everything unclassified fails CLOSED —
792
+ * the generic line, with the raw text owed to the operator sink.
793
+ *
794
+ * This surface has NO inference id to quote (its ids are the connection and
795
+ * session ids, and `genericCallerMessage` without one says only "an
796
+ * internal error occurred while serving this request"); the operator line
797
+ * therefore carries the connection/session ids for correlation — the caller
798
+ * never sees them.
799
+ */
800
+ private callerLine;
659
801
  private fail;
660
802
  /**
661
803
  * Socket-level teardown ONLY (never session death): the native uRun session
@@ -732,7 +874,7 @@ declare function realtimeModelOf(req: IncomingMessage): string | undefined;
732
874
  * and the bridge opens — a refused upgrade admits nothing. On an stt row
733
875
  * the intent is recorded on the binding (a transcription session).
734
876
  */
735
- declare function realtimeBindingFor(clients: Pick<ProxyClients, 'sessionHandle' | 'createResponseOn'> & Partial<Pick<ProxyClients, 'supportsAudio' | 'openAudioOn' | 'supportsTranscription' | 'openTurnsOn' | 'transcriptStreamFor'>>, model: string | undefined, signal?: AbortSignal, intent?: string): Promise<RealtimeBinding<ProxyClients>>;
877
+ declare function realtimeBindingFor(clients: Pick<ProxyClients, 'sessionHandle' | 'createResponseOn'> & Partial<Pick<ProxyClients, 'supportsAudio' | 'openAudioOn' | 'supportsTranscription' | 'openTurnsOn' | 'transcriptStreamFor' | 'realtimeCompanionsFor' | 'releaseSessionHandle'>>, model: string | undefined, signal?: AbortSignal, intent?: string): Promise<RealtimeBinding<ProxyClients>>;
736
878
  /**
737
879
  * The LOCAL lane resolver: fixed pooled clients, optional fixed apiKey (the
738
880
  * same shared-secret rule the local Gemini Live lane applies — a mismatched
@@ -740,8 +882,14 @@ declare function realtimeBindingFor(clients: Pick<ProxyClients, 'sessionHandle'
740
882
  * consulted). The HOSTED lane builds its own resolver per request (org
741
883
  * resolution + per-conversation private backhaul) and reuses
742
884
  * {@link realtimeBindingFor} for the binding itself.
885
+ *
886
+ * `realtimeCompanions` is the composite lane's PAIRING SOURCE (ENG-451) —
887
+ * the constructor option both compositions thread the
888
+ * {@link RealtimeCompanionsFor} seam from. An absent source wires the seam
889
+ * to answer `null`, so a chat model keeps today's 404; the lane NEVER
890
+ * invents a default pairing.
743
891
  */
744
- declare function fixedClientsResolver(clients: ProxyClients, apiKey?: string): {
892
+ declare function fixedClientsResolver(clients: ProxyClients, apiKey?: string, realtimeCompanions?: RealtimeCompanionsFor): {
745
893
  resolve(req: IncomingMessage, signal?: AbortSignal): Promise<RealtimeBinding<ProxyClients>>;
746
894
  };
747
895