@urun-sh/openai 0.2.60 → 0.3.1

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 (53) hide show
  1. package/dist/ResponsesClient-BYx3YLGo.d.ts +26 -0
  2. package/dist/ResponsesClient-Dft3bg3b.d.cts +26 -0
  3. package/dist/chunk-54VWZJU7.js +6 -0
  4. package/dist/chunk-5NXM4IO3.js +2 -0
  5. package/dist/chunk-CWJRDBDC.js +1 -0
  6. package/dist/chunk-F2TEK34X.js +1 -0
  7. package/dist/chunk-G3NMGP4N.js +1 -0
  8. package/dist/chunk-M6ICU4F5.js +40 -0
  9. package/dist/chunk-UVAY7Q7Z.js +1 -0
  10. package/dist/chunk-XHIIEA6Z.js +1 -0
  11. package/dist/chunk-YSFSRI3D.js +1 -0
  12. package/dist/chunk-ZW6ENXZY.js +1 -0
  13. package/dist/gemini-live.cjs +2 -0
  14. package/dist/gemini-live.d.cts +120 -0
  15. package/dist/gemini-live.d.ts +79 -0
  16. package/dist/gemini-live.js +1 -0
  17. package/dist/hosted/bin.cjs +56 -0
  18. package/dist/hosted/bin.js +23 -0
  19. package/dist/hosted/index.cjs +34 -0
  20. package/dist/hosted/index.d.cts +621 -0
  21. package/dist/hosted/index.d.ts +226 -0
  22. package/dist/hosted/index.js +1 -0
  23. package/dist/index.cjs +1 -1
  24. package/dist/index.d.cts +4 -4
  25. package/dist/index.d.ts +4 -4
  26. package/dist/index.js +1 -1
  27. package/dist/pi-extension/index.cjs +4 -4
  28. package/dist/pi-extension/index.d.cts +2 -1
  29. package/dist/pi-extension/index.d.ts +2 -1
  30. package/dist/pi-extension/index.js +7 -7
  31. package/dist/pi-extension/standalone.cjs +54 -54
  32. package/dist/proxy/cli.cjs +39 -39
  33. package/dist/proxy/cli.js +14 -19
  34. package/dist/proxy/index.cjs +22 -22
  35. package/dist/proxy/index.d.cts +5 -182
  36. package/dist/proxy/index.d.ts +5 -67
  37. package/dist/proxy/index.js +1 -1
  38. package/dist/server-BfME37pQ.d.cts +200 -0
  39. package/dist/server-l1himPxc.d.ts +82 -0
  40. package/dist/translator-C9uPKypK.d.ts +130 -0
  41. package/dist/translator-CcDBEfvm.d.cts +227 -0
  42. package/dist/{ResponsesClient-y8g6OfNN.d.cts → types-lsVTbNcH.d.cts} +16 -24
  43. package/dist/{ResponsesClient-y8g6OfNN.d.ts → types-lsVTbNcH.d.ts} +8 -24
  44. package/dist/video-out-CWesbk12.d.ts +155 -0
  45. package/dist/video-out-D20UuJ8G.d.cts +298 -0
  46. package/package.json +22 -2
  47. package/dist/chunk-4FUBGLFN.js +0 -41
  48. package/dist/chunk-OLE2YJO3.js +0 -1
  49. package/dist/chunk-SSZL77P5.js +0 -1
  50. package/dist/chunk-VFHQZ4OM.js +0 -1
  51. package/dist/chunk-VXTNG2TP.js +0 -1
  52. package/dist/media-DCHTX3Ez.d.cts +0 -68
  53. package/dist/media-DCHTX3Ez.d.ts +0 -42
@@ -1,182 +1,5 @@
1
- import { Server } from 'node:http';
2
- import { a as AudioBridge, V as VideoFrameLane } from '../media-DCHTX3Ez.cjs';
3
-
4
- /**
5
- * WHAT a proxy serves — the `identity` block on `GET /stats`. Reuse of a
6
- * running proxy is allowed iff every field matches the launching invocation
7
- * EXACTLY: a partial match (same app, different fn; same everything, older
8
- * proxy_version) silently routes the agent at the wrong backend, which is
9
- * worse than any error.
10
- */
11
- interface ProxyIdentity {
12
- app: string;
13
- org: string;
14
- fn: string;
15
- /**
16
- * The control-plane URL the proxy's backhaul session opens against
17
- * (URUN_BASE_URL verbatim — same org/app/fn on staging vs prod are
18
- * DIFFERENT backends; review finding, #285). Compared exactly: a cosmetic
19
- * difference (trailing slash) merely refuses reuse and spawns an ephemeral
20
- * proxy — the safe direction.
21
- */
22
- base_url: string;
23
- proxy_version: string;
24
- }
25
-
26
- /**
27
- * The local OpenAI-compatible proxy — `npx @urun-sh/openai proxy`.
28
- *
29
- * A loopback HTTP server speaking the OpenAI REST surface (`/v1/models`,
30
- * `/v1/responses`, `/v1/chat/completions`, SSE streaming included), so any
31
- * OpenAI-env-var tool — coding agents first — integrates with uRun with ZERO
32
- * code changes: point `OPENAI_BASE_URL` at it and keep making plain, local,
33
- * "inefficient" HTTP requests. The proxy backhauls each request over the uRun
34
- * session transport (the `@urun-sh/openai` Responses client → session doc
35
- * lanes + streams — no public OpenAI-style HTTP leaves the machine), which is
36
- * also where the delta-sync chat-state doc lane (urun-python
37
- * `urun/serve/chat_state.py`) plugs in as the transport evolves.
38
- *
39
- * Local-trust model: binds 127.0.0.1 by default; `apiKey` (when set) must
40
- * match the agent's `Authorization: Bearer` — otherwise any local bearer is
41
- * accepted (the key the agent sends is NEVER forwarded upstream; uRun auth is
42
- * the session's own).
43
- */
44
-
45
- /** The request envelope every Responses-shaped upstream call carries. */
46
- interface ResponsesCreateParams {
47
- model?: string;
48
- input: unknown;
49
- stream?: boolean;
50
- tools?: unknown;
51
- tool_choice?: unknown;
52
- temperature?: number;
53
- max_output_tokens?: number;
54
- top_p?: number;
55
- stop?: string[];
56
- /**
57
- * Reasoning controls (urun-python #1667): forwarded VERBATIM to the serve
58
- * envelope — `chat_template_kwargs.enable_thinking:false` is the think-off
59
- * switch. Absent -> absent (no default injection; server-side validation).
60
- */
61
- reasoning_effort?: string;
62
- chat_template_kwargs?: Record<string, unknown>;
63
- }
64
- /** How one pinned session ended (the native phase machinery's terminal step). */
65
- interface SessionEndInfo {
66
- /**
67
- * Milliseconds until the session's native deadline (`endsAt`), or null when
68
- * the app declared no maximum session length. NOTE (missing primitive,
69
- * called out in the PR): core exposes no PRE-expiry notice event — this
70
- * callback fires AT terminal loss, so timeLeftMs is ~0 on expiry.
71
- */
72
- timeLeftMs: number | null;
73
- /** The terminal reason (expired / ended / error), for the loud close. */
74
- reason: string;
75
- }
76
- /** The upstream calls the proxy makes — injectable (tests; alt transports). */
77
- interface ProxyClients {
78
- /** `UrunResponses(session).responses.create` — an async iterable of Responses stream events. */
79
- createResponse(params: ResponsesCreateParams): Promise<AsyncIterable<unknown>> | AsyncIterable<unknown>;
80
- /** `listModels(...)` result (an OpenAI model list object). */
81
- listModels(): Promise<unknown>;
82
- /**
83
- * Open (or reuse) the NATIVE audio lanes on the pooled session `model` routes
84
- * to — the same first-party machinery as RealtimeClient.enableAudio
85
- * (transport/media.ts `enableSessionAudio`: AudioBridge over the session's
86
- * `rt-audio-in`/`rt-audio-out` stream lanes at 24 kHz). One lane per pooled
87
- * session; repeat calls return the same lane. Optional at the seam because
88
- * text-only embeddings exist — but a surface that RECEIVES audio while the
89
- * embedder wired no `openAudio` must fail LOUD, never drop chunks.
90
- */
91
- openAudio?(model: string | undefined): Promise<ProxyAudioLane>;
92
- /**
93
- * Open (or reuse) the NATIVE video FRAME lane on the pooled session `model`
94
- * routes to (transport/media.ts `enableSessionVideo`: discrete JPEG frames →
95
- * `stream('rt-video-in').emit`, the §5 named-DATA image-bytes path — NOT the
96
- * RTP media plane, which requires an already-H.264-encoded track). One lane
97
- * per pooled session; repeat calls return the same lane. Optional at the seam
98
- * because text-only embeddings exist — but a surface that RECEIVES video
99
- * frames while the embedder wired no `openVideo` must fail LOUD, never drop
100
- * frames.
101
- */
102
- openVideo?(model: string | undefined): Promise<ProxyVideoLane>;
103
- /**
104
- * SESSION-IDENTITY SEAM (ModelRouter.handleFor): the opaque stable handle
105
- * for the pooled session currently serving `model`'s turns. Derived from
106
- * native identity (app slug + uRun session id) — the same identity the
107
- * serve-side session-affinity tag rides (urun-python#1556/#1582).
108
- */
109
- sessionHandle(model: string | undefined): Promise<string>;
110
- /**
111
- * createResponse PINNED to the exact session a handle names
112
- * (ModelRouter.sessionForHandle). Throws SessionGoneError LOUDLY when that
113
- * session is gone or was replaced — never silently opens a fresh session
114
- * while claiming resume. Deliberately NO re-home on this path: re-homing
115
- * would swap the pinned session out from under the caller.
116
- */
117
- createResponseOn(handle: string, params: ResponsesCreateParams): Promise<AsyncIterable<unknown>> | AsyncIterable<unknown>;
118
- /**
119
- * Subscribe to the pinned session's terminal end via core's NATIVE phase
120
- * machinery (Session.onPhase → terminal 'expired'/'ended'/'error'). Fires
121
- * `cb` once. Throws SessionGoneError if the handle's session is already
122
- * gone — which doubles as the loud reattach check at resume time. Returns
123
- * the unsubscribe.
124
- */
125
- onSessionEnd(handle: string, cb: (end: SessionEndInfo) => void): Promise<() => void>;
126
- }
127
- /**
128
- * The audio lane handle `openAudio` returns — structurally the transport
129
- * AudioBridge (media.ts): base64 PCM16 @24 kHz mono in both directions.
130
- */
131
- type ProxyAudioLane = Pick<AudioBridge, 'appendInputAudio' | 'onOutputAudio'>;
132
- /**
133
- * The video frame-lane handle `openVideo` returns — structurally the transport
134
- * VideoFrameLane (media.ts): one raw encoded JPEG frame per call, input-only
135
- * (Live-style protocols have no video OUT modality).
136
- */
137
- type ProxyVideoLane = Pick<VideoFrameLane, 'sendInputFrame'>;
138
- interface OpenAIProxyOptions {
139
- clients: ProxyClients;
140
- /** Optional bearer the local agent must present (never forwarded upstream). */
141
- apiKey?: string;
142
- /**
143
- * WHAT this proxy serves (app/org/fn/base_url + proxy_version), surfaced as
144
- * the `identity` block on `GET /stats` so a second `urun compat` invocation
145
- * can reuse this proxy iff the identity matches its own exactly. Only the
146
- * standalone `urun compat proxy` command sets it — a launch-mode proxy is
147
- * child-owned (it dies with its child) and an embedder that omits it is
148
- * simply never reused.
149
- */
150
- identity?: ProxyIdentity;
151
- }
152
- /** Build (not listen) the proxy server — the caller owns listen/close. */
153
- declare function createOpenAIProxy(options: OpenAIProxyOptions): Server;
154
-
155
- /**
156
- * Gemini Live (BidiGenerateContent) ⇄ uRun Responses translation — PURE
157
- * functions only, no I/O and no session state. The wire shapes mirror the
158
- * official WebSocket reference (https://ai.google.dev/api/live): client
159
- * messages are a union of exactly one of `setup` / `clientContent` /
160
- * `realtimeInput` / `toolResponse`; server messages are a union of
161
- * `setupComplete` / `serverContent` / `toolCall` / … with `usageMetadata` as
162
- * a SIBLING of the union field on `BidiGenerateContentServerMessage`.
163
- *
164
- * Scope (this slice): setup + clientContent + realtimeInput TEXT + AUDIO +
165
- * VIDEO + serverContent streaming + toolCall/toolResponse + sessionResumption
166
- * (handles over the proxy's pooled-session identity seam) + goAway + MANUAL
167
- * VAD/activity (setup.realtimeInputConfig.automaticActivityDetection.disabled
168
- * + realtimeInput.activityStart/activityEnd + serverContent.interrupted
169
- * barge-in). AUTOMATIC (server-side) activity detection is the DECLARED
170
- * follow-up slice — requesting it fails loud naming the follow-up, never
171
- * silently ignored (repo mandate: one canonical path, no silent fallbacks).
172
- *
173
- * AUTOMATIC activity detection is deliberately NOT emulated here: server-side
174
- * VAD is a PLATFORM primitive (urun-python `urun.serve.turn_detection`
175
- * `detect_turns` — `turn_start`/`turn_end` events on the session's §5 stream
176
- * lane), never adapter-local DSP in the proxy. Until the Live lane's session
177
- * shapes emit those events, requesting automatic detection fails loud.
178
- */
179
- /** The Live WS endpoint path (v1beta), verbatim from the Google reference. */
180
- declare const GEMINI_LIVE_PATH = "/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent";
181
-
182
- export { GEMINI_LIVE_PATH, type OpenAIProxyOptions, type ProxyClients, type ProxyIdentity, createOpenAIProxy };
1
+ export { O as OpenAIProxyOptions, P as ProxyClients, a as ProxyIdentity, b as ProxyVideoOutLane, c as createOpenAIProxy } from '../server-BfME37pQ.cjs';
2
+ export { h as GEMINI_LIVE_PATH, V as VIDEO_OUT_SETUP_KEY } from '../translator-CcDBEfvm.cjs';
3
+ import 'node:http';
4
+ import '../video-out-D20UuJ8G.cjs';
5
+ import '../types-lsVTbNcH.cjs';
@@ -1,67 +1,5 @@
1
- import { Server } from 'node:http';
2
- import { a as AudioBridge, V as VideoFrameLane } from '../media-DCHTX3Ez.js';
3
-
4
- interface ProxyIdentity {
5
- app: string;
6
- org: string;
7
- fn: string;
8
-
9
- base_url: string;
10
- proxy_version: string;
11
- }
12
-
13
- interface ResponsesCreateParams {
14
- model?: string;
15
- input: unknown;
16
- stream?: boolean;
17
- tools?: unknown;
18
- tool_choice?: unknown;
19
- temperature?: number;
20
- max_output_tokens?: number;
21
- top_p?: number;
22
- stop?: string[];
23
-
24
- reasoning_effort?: string;
25
- chat_template_kwargs?: Record<string, unknown>;
26
- }
27
-
28
- interface SessionEndInfo {
29
-
30
- timeLeftMs: number | null;
31
-
32
- reason: string;
33
- }
34
-
35
- interface ProxyClients {
36
-
37
- createResponse(params: ResponsesCreateParams): Promise<AsyncIterable<unknown>> | AsyncIterable<unknown>;
38
-
39
- listModels(): Promise<unknown>;
40
-
41
- openAudio?(model: string | undefined): Promise<ProxyAudioLane>;
42
-
43
- openVideo?(model: string | undefined): Promise<ProxyVideoLane>;
44
-
45
- sessionHandle(model: string | undefined): Promise<string>;
46
-
47
- createResponseOn(handle: string, params: ResponsesCreateParams): Promise<AsyncIterable<unknown>> | AsyncIterable<unknown>;
48
-
49
- onSessionEnd(handle: string, cb: (end: SessionEndInfo) => void): Promise<() => void>;
50
- }
51
-
52
- type ProxyAudioLane = Pick<AudioBridge, 'appendInputAudio' | 'onOutputAudio'>;
53
-
54
- type ProxyVideoLane = Pick<VideoFrameLane, 'sendInputFrame'>;
55
- interface OpenAIProxyOptions {
56
- clients: ProxyClients;
57
-
58
- apiKey?: string;
59
-
60
- identity?: ProxyIdentity;
61
- }
62
-
63
- declare function createOpenAIProxy(options: OpenAIProxyOptions): Server;
64
-
65
- declare const GEMINI_LIVE_PATH = "/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent";
66
-
67
- export { GEMINI_LIVE_PATH, type OpenAIProxyOptions, type ProxyClients, type ProxyIdentity, createOpenAIProxy };
1
+ export { O as OpenAIProxyOptions, P as ProxyClients, a as ProxyIdentity, b as ProxyVideoOutLane, c as createOpenAIProxy } from '../server-l1himPxc.js';
2
+ export { h as GEMINI_LIVE_PATH, V as VIDEO_OUT_SETUP_KEY } from '../translator-C9uPKypK.js';
3
+ import 'node:http';
4
+ import '../video-out-CWesbk12.js';
5
+ import '../types-lsVTbNcH.js';
@@ -1 +1 @@
1
- import{a as r,b as e}from"../chunk-4FUBGLFN.js";import"../chunk-VFHQZ4OM.js";import"../chunk-VXTNG2TP.js";export{r as GEMINI_LIVE_PATH,e as createOpenAIProxy};
1
+ import{b as t}from"../chunk-M6ICU4F5.js";import"../chunk-XHIIEA6Z.js";import{a as r,h as o}from"../chunk-5NXM4IO3.js";import"../chunk-CWJRDBDC.js";import{c as e}from"../chunk-YSFSRI3D.js";e();export{r as GEMINI_LIVE_PATH,o as VIDEO_OUT_SETUP_KEY,t as createOpenAIProxy};
@@ -0,0 +1,200 @@
1
+ import { IncomingMessage, Server } from 'node:http';
2
+ import { a as AudioBridge, h as VideoFrameLane, j as VideoOutLane } from './video-out-D20UuJ8G.cjs';
3
+
4
+ /**
5
+ * WHAT a proxy serves — the `identity` block on `GET /stats`. Reuse of a
6
+ * running proxy is allowed iff every field matches the launching invocation
7
+ * EXACTLY: a partial match (same app, different fn; same everything, older
8
+ * proxy_version) silently routes the agent at the wrong backend, which is
9
+ * worse than any error.
10
+ */
11
+ interface ProxyIdentity {
12
+ app: string;
13
+ org: string;
14
+ fn: string;
15
+ /**
16
+ * The control-plane URL the proxy's backhaul session opens against
17
+ * (URUN_BASE_URL verbatim — same org/app/fn on staging vs prod are
18
+ * DIFFERENT backends; review finding, #285). Compared exactly: a cosmetic
19
+ * difference (trailing slash) merely refuses reuse and spawns an ephemeral
20
+ * proxy — the safe direction.
21
+ */
22
+ base_url: string;
23
+ proxy_version: string;
24
+ }
25
+
26
+ /**
27
+ * The local OpenAI-compatible proxy — `npx @urun-sh/openai proxy`.
28
+ *
29
+ * A loopback HTTP server speaking the OpenAI REST surface (`/v1/models`,
30
+ * `/v1/responses`, `/v1/chat/completions`, SSE streaming included), so any
31
+ * OpenAI-env-var tool — coding agents first — integrates with uRun with ZERO
32
+ * code changes: point `OPENAI_BASE_URL` at it and keep making plain, local,
33
+ * "inefficient" HTTP requests. The proxy backhauls each request over the uRun
34
+ * session transport (the `@urun-sh/openai` Responses client → session doc
35
+ * lanes + streams — no public OpenAI-style HTTP leaves the machine), which is
36
+ * also where the delta-sync chat-state doc lane (urun-python
37
+ * `urun/serve/chat_state.py`) plugs in as the transport evolves.
38
+ *
39
+ * Local-trust model: binds 127.0.0.1 by default; `apiKey` (when set) must
40
+ * match the agent's `Authorization: Bearer` — otherwise any local bearer is
41
+ * accepted (the key the agent sends is NEVER forwarded upstream; uRun auth is
42
+ * the session's own).
43
+ */
44
+
45
+ /** The request envelope every Responses-shaped upstream call carries. */
46
+ interface ResponsesCreateParams {
47
+ model?: string;
48
+ input: unknown;
49
+ stream?: boolean;
50
+ tools?: unknown;
51
+ tool_choice?: unknown;
52
+ temperature?: number;
53
+ max_output_tokens?: number;
54
+ top_p?: number;
55
+ stop?: string[];
56
+ /**
57
+ * Reasoning controls (urun-python #1667): forwarded VERBATIM to the serve
58
+ * envelope — `chat_template_kwargs.enable_thinking:false` is the think-off
59
+ * switch. Absent -> absent (no default injection; server-side validation).
60
+ */
61
+ reasoning_effort?: string;
62
+ chat_template_kwargs?: Record<string, unknown>;
63
+ }
64
+ /** How one pinned session ended (the native phase machinery's terminal step). */
65
+ interface SessionEndInfo {
66
+ /**
67
+ * Milliseconds until the session's native deadline (`endsAt`), or null when
68
+ * the app declared no maximum session length. NOTE (missing primitive,
69
+ * called out in the PR): core exposes no PRE-expiry notice event — this
70
+ * callback fires AT terminal loss, so timeLeftMs is ~0 on expiry.
71
+ */
72
+ timeLeftMs: number | null;
73
+ /** The terminal reason (expired / ended / error), for the loud close. */
74
+ reason: string;
75
+ }
76
+ /** The upstream calls the proxy makes — injectable (tests; alt transports). */
77
+ interface ProxyClients {
78
+ /** `UrunResponses(session).responses.create` — an async iterable of Responses stream events. */
79
+ createResponse(params: ResponsesCreateParams): Promise<AsyncIterable<unknown>> | AsyncIterable<unknown>;
80
+ /** `listModels(...)` result (an OpenAI model list object). */
81
+ listModels(): Promise<unknown>;
82
+ /**
83
+ * Open (or reuse) the NATIVE audio lanes on the pooled session `model` routes
84
+ * to — the same first-party machinery as RealtimeClient.enableAudio
85
+ * (transport/media.ts `enableSessionAudio`: AudioBridge over the session's
86
+ * `rt-audio-in`/`rt-audio-out` stream lanes at 24 kHz). One lane per pooled
87
+ * session; repeat calls return the same lane. Optional at the seam because
88
+ * text-only embeddings exist — but a surface that RECEIVES audio while the
89
+ * embedder wired no `openAudio` must fail LOUD, never drop chunks.
90
+ */
91
+ openAudio?(model: string | undefined): Promise<ProxyAudioLane>;
92
+ /**
93
+ * Open (or reuse) the NATIVE video FRAME lane on the pooled session `model`
94
+ * routes to (transport/media.ts `enableSessionVideo`: discrete JPEG frames →
95
+ * `stream('rt-video-in').emit`, the §5 named-DATA image-bytes path — NOT the
96
+ * RTP media plane, which requires an already-H.264-encoded track). One lane
97
+ * per pooled session; repeat calls return the same lane. Optional at the seam
98
+ * because text-only embeddings exist — but a surface that RECEIVES video
99
+ * frames while the embedder wired no `openVideo` must fail LOUD, never drop
100
+ * frames.
101
+ */
102
+ openVideo?(model: string | undefined): Promise<ProxyVideoLane>;
103
+ /**
104
+ * Open (or reuse) the NATIVE video OUTPUT lane on the pooled session
105
+ * `model` routes to (transport/video-out.ts `openSessionVideoOutLane`):
106
+ * decoded spec-v1 records consumed from the session's named §5
107
+ * `rt-video-out` downstream. The Live adapter fans each record onto the
108
+ * SAME Bidi WS as an extension server message (spec v2, WS-inline) — no
109
+ * side-channel transport. Optional at the seam; an ABSENT seam means the
110
+ * `urun.videoOut` capability is refused by omission in setupComplete
111
+ * (vanilla parity), while a wired seam that cannot open the lane must
112
+ * throw LOUD — never a quiet downgrade.
113
+ */
114
+ openVideoOut?(model: string | undefined): Promise<ProxyVideoOutLane>;
115
+ /**
116
+ * SESSION-IDENTITY SEAM (ModelRouter.handleFor): the opaque stable handle
117
+ * for the pooled session currently serving `model`'s turns. Derived from
118
+ * native identity (app slug + uRun session id) — the same identity the
119
+ * serve-side session-affinity tag rides (urun-python#1556/#1582).
120
+ */
121
+ sessionHandle(model: string | undefined): Promise<string>;
122
+ /**
123
+ * createResponse PINNED to the exact session a handle names
124
+ * (ModelRouter.sessionForHandle). Throws SessionGoneError LOUDLY when that
125
+ * session is gone or was replaced — never silently opens a fresh session
126
+ * while claiming resume. Deliberately NO re-home on this path: re-homing
127
+ * would swap the pinned session out from under the caller.
128
+ */
129
+ createResponseOn(handle: string, params: ResponsesCreateParams): Promise<AsyncIterable<unknown>> | AsyncIterable<unknown>;
130
+ /**
131
+ * Subscribe to the pinned session's terminal end via core's NATIVE phase
132
+ * machinery (Session.onPhase → terminal 'expired'/'ended'/'error'). Fires
133
+ * `cb` once. Throws SessionGoneError if the handle's session is already
134
+ * gone — which doubles as the loud reattach check at resume time. Returns
135
+ * the unsubscribe.
136
+ */
137
+ onSessionEnd(handle: string, cb: (end: SessionEndInfo) => void): Promise<() => void>;
138
+ }
139
+ /**
140
+ * The audio lane handle `openAudio` returns — structurally the transport
141
+ * AudioBridge (media.ts): base64 PCM16 @24 kHz mono in both directions.
142
+ */
143
+ type ProxyAudioLane = Pick<AudioBridge, 'appendInputAudio' | 'onOutputAudio'>;
144
+ /**
145
+ * The video frame-lane handle `openVideo` returns — structurally the transport
146
+ * VideoFrameLane (media.ts): one raw encoded JPEG frame per call, input-only
147
+ * (Live-style protocols have no video OUT modality).
148
+ */
149
+ type ProxyVideoLane = Pick<VideoFrameLane, 'sendInputFrame'>;
150
+ /**
151
+ * The video-OUT lane handle `openVideoOut` returns — structurally the
152
+ * transport VideoOutLane (video-out.ts): the codec plus frame/error fan-out
153
+ * the WS-inline delivery subscribes.
154
+ */
155
+ type ProxyVideoOutLane = Pick<VideoOutLane, 'codec' | 'onOutputFrame' | 'onLaneError'>;
156
+ /**
157
+ * Per-request `ProxyClients` resolution — the seam the HOSTED multi-tenant
158
+ * server (`src/hosted/`) plugs into so ONE handler implementation serves
159
+ * every org: the hosted server resolves the caller's org from its Bearer API
160
+ * key and returns THAT org's backhaul. The local CLI passes a fixed
161
+ * `ProxyClients` instead; both go through the identical handler body below.
162
+ *
163
+ * Throwing from here is the loud path: the thrown error surfaces in the
164
+ * lane's native error envelope (see {@link ProxyHandlerOptions.statusOf}).
165
+ */
166
+ type ProxyClientsFor = (req: IncomingMessage) => ProxyClients | Promise<ProxyClients>;
167
+ interface ProxyHandlerOptions {
168
+ /** A fixed backhaul (local CLI) or a per-request resolver (hosted server). */
169
+ clients: ProxyClients | ProxyClientsFor;
170
+ /** Optional bearer the local agent must present (never forwarded upstream). */
171
+ apiKey?: string;
172
+ /**
173
+ * WHAT this proxy serves (app/org/fn/base_url + proxy_version), surfaced as
174
+ * the `identity` block on `GET /stats` so a second `urun compat` invocation
175
+ * can reuse this proxy iff the identity matches its own exactly. Only the
176
+ * standalone `urun compat proxy` command sets it — a launch-mode proxy is
177
+ * child-owned (it dies with its child) and an embedder that omits it is
178
+ * simply never reused.
179
+ */
180
+ identity?: ProxyIdentity;
181
+ /**
182
+ * Map a thrown error onto an HTTP status + error `type` before the generic
183
+ * 500. The hosted server uses it to turn its auth/tenancy failures into a
184
+ * 401 in the OpenAI envelope. Returning null means "not mine" — the error
185
+ * takes the ordinary loud 500 path.
186
+ */
187
+ statusOf?: (err: unknown) => {
188
+ status: number;
189
+ openaiType: string;
190
+ anthropicType: string;
191
+ } | null;
192
+ }
193
+ /** The proxy server's own options: a FIXED backhaul (the local CLI lane). */
194
+ interface OpenAIProxyOptions extends ProxyHandlerOptions {
195
+ clients: ProxyClients;
196
+ }
197
+ /** Build (not listen) the proxy server — the caller owns listen/close. */
198
+ declare function createOpenAIProxy(options: OpenAIProxyOptions): Server;
199
+
200
+ export { type OpenAIProxyOptions as O, type ProxyClients as P, type ProxyIdentity as a, type ProxyVideoOutLane as b, createOpenAIProxy as c };
@@ -0,0 +1,82 @@
1
+ import { IncomingMessage, Server } from 'node:http';
2
+ import { a as AudioBridge, h as VideoFrameLane, j as VideoOutLane } from './video-out-CWesbk12.js';
3
+
4
+ interface ProxyIdentity {
5
+ app: string;
6
+ org: string;
7
+ fn: string;
8
+
9
+ base_url: string;
10
+ proxy_version: string;
11
+ }
12
+
13
+ interface ResponsesCreateParams {
14
+ model?: string;
15
+ input: unknown;
16
+ stream?: boolean;
17
+ tools?: unknown;
18
+ tool_choice?: unknown;
19
+ temperature?: number;
20
+ max_output_tokens?: number;
21
+ top_p?: number;
22
+ stop?: string[];
23
+
24
+ reasoning_effort?: string;
25
+ chat_template_kwargs?: Record<string, unknown>;
26
+ }
27
+
28
+ interface SessionEndInfo {
29
+
30
+ timeLeftMs: number | null;
31
+
32
+ reason: string;
33
+ }
34
+
35
+ interface ProxyClients {
36
+
37
+ createResponse(params: ResponsesCreateParams): Promise<AsyncIterable<unknown>> | AsyncIterable<unknown>;
38
+
39
+ listModels(): Promise<unknown>;
40
+
41
+ openAudio?(model: string | undefined): Promise<ProxyAudioLane>;
42
+
43
+ openVideo?(model: string | undefined): Promise<ProxyVideoLane>;
44
+
45
+ openVideoOut?(model: string | undefined): Promise<ProxyVideoOutLane>;
46
+
47
+ sessionHandle(model: string | undefined): Promise<string>;
48
+
49
+ createResponseOn(handle: string, params: ResponsesCreateParams): Promise<AsyncIterable<unknown>> | AsyncIterable<unknown>;
50
+
51
+ onSessionEnd(handle: string, cb: (end: SessionEndInfo) => void): Promise<() => void>;
52
+ }
53
+
54
+ type ProxyAudioLane = Pick<AudioBridge, 'appendInputAudio' | 'onOutputAudio'>;
55
+
56
+ type ProxyVideoLane = Pick<VideoFrameLane, 'sendInputFrame'>;
57
+
58
+ type ProxyVideoOutLane = Pick<VideoOutLane, 'codec' | 'onOutputFrame' | 'onLaneError'>;
59
+
60
+ type ProxyClientsFor = (req: IncomingMessage) => ProxyClients | Promise<ProxyClients>;
61
+ interface ProxyHandlerOptions {
62
+
63
+ clients: ProxyClients | ProxyClientsFor;
64
+
65
+ apiKey?: string;
66
+
67
+ identity?: ProxyIdentity;
68
+
69
+ statusOf?: (err: unknown) => {
70
+ status: number;
71
+ openaiType: string;
72
+ anthropicType: string;
73
+ } | null;
74
+ }
75
+
76
+ interface OpenAIProxyOptions extends ProxyHandlerOptions {
77
+ clients: ProxyClients;
78
+ }
79
+
80
+ declare function createOpenAIProxy(options: OpenAIProxyOptions): Server;
81
+
82
+ export { type OpenAIProxyOptions as O, type ProxyClients as P, type ProxyIdentity as a, type ProxyVideoOutLane as b, createOpenAIProxy as c };
@@ -0,0 +1,130 @@
1
+ import { k as VideoOutRecord } from './video-out-CWesbk12.js';
2
+
3
+ declare const GEMINI_LIVE_PATH = "/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent";
4
+
5
+ declare const CLOSE_PROTOCOL = 1007;
6
+
7
+ declare const CLOSE_UNKNOWN_MODEL = 1008;
8
+
9
+ declare const CLOSE_UPSTREAM = 1011;
10
+
11
+ declare const CLOSE_SESSION_GONE = 1008;
12
+
13
+ declare class GeminiLiveError extends Error {
14
+ readonly closeCode: number;
15
+ constructor(message: string, closeCode?: number);
16
+ }
17
+ type Rec = Record<string, unknown>;
18
+
19
+ type ClientMessage = {
20
+ kind: 'setup';
21
+ setup: Rec;
22
+ } | {
23
+ kind: 'clientContent';
24
+ clientContent: Rec;
25
+ } | {
26
+ kind: 'realtimeInput';
27
+ realtimeInput: Rec;
28
+ } | {
29
+ kind: 'toolResponse';
30
+ toolResponse: Rec;
31
+ };
32
+
33
+ declare function parseClientMessage(raw: string): ClientMessage;
34
+
35
+ type ActivityHandling = 'START_OF_ACTIVITY_INTERRUPTS' | 'NO_INTERRUPTION';
36
+
37
+ interface ActivityConfig {
38
+
39
+ manualActivity: boolean;
40
+
41
+ activityHandling: ActivityHandling;
42
+ }
43
+
44
+ interface LiveSessionConfig {
45
+
46
+ model: string;
47
+
48
+ systemItems: Rec[];
49
+
50
+ tools: Rec[] | undefined;
51
+ temperature: number | undefined;
52
+ maxOutputTokens: number | undefined;
53
+
54
+ audioModality: boolean;
55
+
56
+ activity: ActivityConfig;
57
+
58
+ sessionResumption: {
59
+ enabled: boolean;
60
+ handle: string | null;
61
+ };
62
+
63
+ videoOut: boolean;
64
+ }
65
+
66
+ declare const VIDEO_OUT_SETUP_KEY = "urun.videoOut";
67
+
68
+ declare function videoOutAck(codec: string): Rec;
69
+
70
+ declare function videoOutChunkMsg(record: VideoOutRecord): Rec;
71
+
72
+ declare function translateSetup(setup: Rec): LiveSessionConfig;
73
+
74
+ declare function sessionResumptionUpdateMsg(newHandle: string): Rec;
75
+
76
+ declare function goAwayMsg(timeLeftMs: number | null): Rec;
77
+
78
+ declare function translateClientContent(cc: Rec): {
79
+ items: Rec[];
80
+ turnComplete: boolean;
81
+ };
82
+
83
+ declare const GEMINI_AUDIO_IN_RATE = 16000;
84
+
85
+ declare const GEMINI_AUDIO_OUT_RATE = 24000;
86
+
87
+ declare const GEMINI_AUDIO_OUT_MIME = "audio/pcm;rate=24000";
88
+
89
+ declare const OUTBOUND_AUDIO_FLUSH_B64: string;
90
+
91
+ declare function resamplePcm16(samples: Int16Array, from: number, to: number): Int16Array;
92
+
93
+ type RealtimeInputAction = {
94
+ kind: 'text';
95
+ text: string;
96
+ } | {
97
+ kind: 'audio';
98
+ base64Pcm24k: string;
99
+ } | {
100
+ kind: 'audioStreamEnd';
101
+ } | {
102
+ kind: 'activityStart';
103
+ } | {
104
+ kind: 'activityEnd';
105
+ } | {
106
+ kind: 'video';
107
+ jpegFrame: Uint8Array;
108
+ };
109
+
110
+ declare function translateRealtimeInput(ri: Rec): RealtimeInputAction;
111
+
112
+ declare function translateToolResponse(tr: Rec): Rec[];
113
+
114
+ declare function serverContentOfDelta(ev: {
115
+ type?: unknown;
116
+ delta?: unknown;
117
+ }): Rec | null;
118
+
119
+ declare function serverContentOfAudio(base64Pcm24k: string): Rec;
120
+
121
+ interface TurnEnd {
122
+
123
+ messages: Rec[];
124
+
125
+ assistantItems: Rec[];
126
+ }
127
+
128
+ declare function turnEndOfCompleted(completed: unknown): TurnEnd;
129
+
130
+ export { type ActivityConfig as A, CLOSE_PROTOCOL as C, GEMINI_AUDIO_IN_RATE as G, type LiveSessionConfig as L, OUTBOUND_AUDIO_FLUSH_B64 as O, type RealtimeInputAction as R, type TurnEnd as T, VIDEO_OUT_SETUP_KEY as V, type ActivityHandling as a, CLOSE_SESSION_GONE as b, CLOSE_UNKNOWN_MODEL as c, CLOSE_UPSTREAM as d, type ClientMessage as e, GEMINI_AUDIO_OUT_MIME as f, GEMINI_AUDIO_OUT_RATE as g, GEMINI_LIVE_PATH as h, GeminiLiveError as i, goAwayMsg as j, serverContentOfDelta as k, sessionResumptionUpdateMsg as l, translateRealtimeInput as m, translateSetup as n, translateToolResponse as o, parseClientMessage as p, turnEndOfCompleted as q, resamplePcm16 as r, serverContentOfAudio as s, translateClientContent as t, videoOutChunkMsg as u, videoOutAck as v };