@memberjunction/ai-gemini 6.2.0-edge.2 → 6.2.0-edge.4

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.
@@ -0,0 +1,425 @@
1
+ /**
2
+ * @fileoverview Gemini Live's half of MJAPI's realtime relay: the server writes the setup, the browser streams input.
3
+ *
4
+ * A browser cannot hold a Gemini Enterprise credential, so a client-direct Enterprise session runs through MJAPI's relay
5
+ * (`/realtime/relay/<ticket>/…`; `IRealtimeRelayPolicy` in `@memberjunction/ai`). Enterprise also lets a client replace
6
+ * the system instruction and tools mid-session (`system` turns, `contextUpdate`), so checking the browser's first frame
7
+ * would lock nothing. This policy:
8
+ *
9
+ * - opens every upstream connection with the setup the server wrote (`BuildGeminiLiveSetup`), and reads only two things
10
+ * from the browser's setup: a resumption handle (the relay accepts only handles it forwarded to the session) and a
11
+ * request for audio only (a downgrade, never an upgrade);
12
+ * - forwards only `realtimeInput` (audio, video, text, activity markers, `audioStreamEnd`), `clientContent` whose turns
13
+ * are all `user` (an empty `turnComplete` commit included) and `toolResponse`, in camelCase or snake_case, with known
14
+ * keys only and media of the types Gemini Live takes; it drops everything else under a short label the relay counts;
15
+ * - finds resumption handles in server frames with a byte search before any parse (avatar video frames run to
16
+ * megabytes).
17
+ *
18
+ * Widening what passes lets a browser change the agent mid-session, so any widening is a security change.
19
+ *
20
+ * @module @memberjunction/ai-gemini
21
+ * @author MemberJunction.com
22
+ */
23
+ import { BuildGeminiLiveAudioOnlySetup } from './geminiLiveSetup.js';
24
+ /**
25
+ * The longest client message the policy reads, in UTF-16 code units. The relay closes on larger frames first (2 MiB of
26
+ * bytes, never fewer code units), so this guards only a caller without that cap.
27
+ */
28
+ const MAX_CLIENT_MESSAGE_CHARS = 2 * 1024 * 1024;
29
+ /** Microphone audio Gemini Live takes: 16-bit PCM at 16 kHz. */
30
+ const AUDIO_MIME_TYPES = new Set(['audio/pcm;rate=16000']);
31
+ /** Images Gemini Live takes as video frames. */
32
+ const IMAGE_MIME_TYPES = new Set(['image/jpeg', 'image/png']);
33
+ /** Media a user turn may carry inline: the same audio and image types. */
34
+ const TURN_MIME_TYPES = new Set([...AUDIO_MIME_TYPES, ...IMAGE_MIME_TYPES]);
35
+ /** The server message field that carries a resumption handle, searched for as bytes before a frame is parsed. */
36
+ const RESUMPTION_UPDATE_KEY = 'sessionResumptionUpdate';
37
+ const RESUMPTION_UPDATE_BYTES = Buffer.from(RESUMPTION_UPDATE_KEY, 'utf8');
38
+ /** A camelCase field name in snake_case, the other spelling Google's JSON parser accepts. */
39
+ function snakeCase(camelName) {
40
+ return camelName.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
41
+ }
42
+ /** Maps each field's camelCase and snake_case wire names to its camelCase name. */
43
+ function wireNames(...camelNames) {
44
+ const names = new Map();
45
+ for (const name of camelNames) {
46
+ names.set(name, name);
47
+ names.set(snakeCase(name), name);
48
+ }
49
+ return names;
50
+ }
51
+ /** An object that may have no fields at all (an activity marker). */
52
+ const NO_FIELDS = new Map();
53
+ const MESSAGE_TYPES = wireNames('realtimeInput', 'clientContent', 'toolResponse');
54
+ const REALTIME_INPUT_FIELDS = wireNames('audio', 'video', 'text', 'activityStart', 'activityEnd', 'audioStreamEnd');
55
+ const BLOB_FIELDS = wireNames('data', 'mimeType');
56
+ const CLIENT_CONTENT_FIELDS = wireNames('turns', 'turnComplete');
57
+ const CONTENT_FIELDS = wireNames('role', 'parts');
58
+ const PART_FIELDS = wireNames('text', 'inlineData');
59
+ const TOOL_RESPONSE_FIELDS = wireNames('functionResponses');
60
+ const FUNCTION_RESPONSE_FIELDS = wireNames('id', 'name', 'response', 'scheduling', 'willContinue');
61
+ /** The value each function response field must hold. */
62
+ const FUNCTION_RESPONSE_CHECKS = new Map([
63
+ ['id', (value) => typeof value === 'string'],
64
+ ['name', (value) => typeof value === 'string'],
65
+ ['response', (value) => isJsonObject(value)],
66
+ ['scheduling', (value) => typeof value === 'string'],
67
+ ['willContinue', (value) => typeof value === 'boolean'],
68
+ ]);
69
+ /**
70
+ * The Gemini Live frame policy for one relayed session: it writes the setup, filters what the browser sends after it,
71
+ * and finds the resumption handles Google sends (see the module notes).
72
+ *
73
+ * Drop labels (counted by the relay, never payload): `oversize`, `invalid`, `empty`, `multi-key`, `setup`,
74
+ * `contextUpdate`, `unknown`, and `<type>.<reason>` for a `realtimeInput`, `clientContent` or `toolResponse` that fails
75
+ * its checks (`invalid`, `unknown`, `duplicate`, `media-type`; `system`, `model`, `role` and `part` for turns).
76
+ */
77
+ export class GeminiLiveRelayPolicy {
78
+ /**
79
+ * @param options The minted setup and, on Gemini Enterprise, the header source.
80
+ * @throws When the setup names no model.
81
+ */
82
+ constructor(options) {
83
+ const model = options.Setup?.model;
84
+ if (typeof model !== 'string' || model.length === 0) {
85
+ throw new Error('GeminiLiveRelayPolicy: the setup names no model; write it with BuildGeminiLiveSetup.');
86
+ }
87
+ this.setupJson = JSON.stringify(options.Setup);
88
+ this.upstreamHeaders = options.UpstreamHeaders;
89
+ }
90
+ /** The upstream handshake's headers for this connection: the header source's, or none. */
91
+ async UpstreamHeaders() {
92
+ return this.upstreamHeaders ? this.upstreamHeaders() : {};
93
+ }
94
+ /**
95
+ * Reads the browser's setup (the connection's first frame): its resumption handle and whether it asks for audio
96
+ * only. Nothing else in it is read. `null` when the frame is not a lone, well-formed `setup` message.
97
+ *
98
+ * @param firstClientFrame The browser's first text frame.
99
+ */
100
+ ReadOpenIntent(firstClientFrame) {
101
+ const setup = readBrowserSetup(firstClientFrame);
102
+ if (!setup) {
103
+ return null;
104
+ }
105
+ const handle = readResumeHandle(setup);
106
+ return handle === undefined ? null : { ResumeHandle: handle, AudioOnly: asksForAudioOnly(setup) };
107
+ }
108
+ /**
109
+ * The connection's one opening frame: the minted setup, with the browser's resumption handle on a resume and without
110
+ * video output when the browser asked for audio only.
111
+ *
112
+ * @param intent What the first frame asked for, as {@link ReadOpenIntent} read it and the relay granted it.
113
+ * @throws On a resume when the minted setup has resumption off (never opens a fresh session in its place).
114
+ */
115
+ OpeningFrames(intent) {
116
+ const minted = JSON.parse(this.setupJson);
117
+ const setup = intent.AudioOnly ? BuildGeminiLiveAudioOnlySetup(minted) : minted;
118
+ if (intent.ResumeHandle !== null) {
119
+ if (!setup.sessionResumption) {
120
+ throw new Error('GeminiLiveRelayPolicy: a resume was granted, but the minted setup has session resumption off.');
121
+ }
122
+ setup.sessionResumption = { ...setup.sessionResumption, handle: intent.ResumeHandle };
123
+ }
124
+ return [JSON.stringify({ setup })];
125
+ }
126
+ /**
127
+ * Forwards a `realtimeInput`, a `clientContent` of `user` turns or a `toolResponse` that passes its checks, as JSON
128
+ * re-serialized from what was checked (so a duplicate key or another parser difference cannot carry an unchecked
129
+ * value through). Drops anything else, under a label (see the class notes).
130
+ *
131
+ * @param frame A client text frame after the first.
132
+ */
133
+ FilterClientFrame(frame) {
134
+ if (frame.length > MAX_CLIENT_MESSAGE_CHARS) {
135
+ return { Drop: 'oversize' };
136
+ }
137
+ const message = parseJsonObject(frame);
138
+ if (!message) {
139
+ return { Drop: 'invalid' };
140
+ }
141
+ const keys = Object.keys(message);
142
+ if (keys.length !== 1) {
143
+ return { Drop: keys.length === 0 ? 'empty' : 'multi-key' };
144
+ }
145
+ const problem = checkClientMessage(keys[0], message[keys[0]]);
146
+ return problem ? { Drop: problem } : { Forward: JSON.stringify(message) };
147
+ }
148
+ /**
149
+ * The resumption handle a server frame carries, else `null`. Text and binary frames alike (Google sends its JSON in
150
+ * binary frames); a frame without the bytes `sessionResumptionUpdate` is never parsed. A handle counts only when
151
+ * Google marks it resumable, as the browser client does.
152
+ *
153
+ * @param data The frame's bytes.
154
+ * @param isBinary Whether it came as a binary frame (not needed: both kinds hold the same JSON).
155
+ */
156
+ ObserveServerFrame(data, isBinary) {
157
+ const bytes = Buffer.isBuffer(data) ? data : Buffer.from(data.buffer, data.byteOffset, data.byteLength);
158
+ if (!bytes.includes(RESUMPTION_UPDATE_BYTES)) {
159
+ return null;
160
+ }
161
+ const update = parseJsonObject(bytes.toString('utf8'))?.[RESUMPTION_UPDATE_KEY];
162
+ if (!isJsonObject(update) || update['resumable'] === false) {
163
+ return null;
164
+ }
165
+ const handle = update['newHandle'];
166
+ return typeof handle === 'string' && handle.length > 0 ? handle : null;
167
+ }
168
+ }
169
+ // ── The browser's setup ─────────────────────────────────────────────────────────────────────────────
170
+ /** The `setup` body of a first frame that is a lone setup message, else `null`. */
171
+ function readBrowserSetup(frame) {
172
+ if (frame.length > MAX_CLIENT_MESSAGE_CHARS) {
173
+ return null;
174
+ }
175
+ const message = parseJsonObject(frame);
176
+ const keys = message ? Object.keys(message) : [];
177
+ if (!message || keys.length !== 1 || keys[0] !== 'setup') {
178
+ return null;
179
+ }
180
+ const setup = message['setup'];
181
+ return isJsonObject(setup) ? setup : null;
182
+ }
183
+ /** The browser's resumption handle: a string, `null` for a fresh session, `undefined` when it is malformed. */
184
+ function readResumeHandle(setup) {
185
+ const resumption = readAliased(setup, 'sessionResumption');
186
+ if (!resumption) {
187
+ return undefined;
188
+ }
189
+ if (resumption.Value === undefined || resumption.Value === null) {
190
+ return null;
191
+ }
192
+ if (!isJsonObject(resumption.Value)) {
193
+ return undefined;
194
+ }
195
+ const handle = resumption.Value['handle'];
196
+ if (handle === undefined || handle === null || handle === '') {
197
+ return null;
198
+ }
199
+ return typeof handle === 'string' ? handle : undefined;
200
+ }
201
+ /** Whether the browser's setup asks for audio output only (`responseModalities` of AUDIO and nothing else). */
202
+ function asksForAudioOnly(setup) {
203
+ const generation = readAliased(setup, 'generationConfig')?.Value;
204
+ if (!isJsonObject(generation)) {
205
+ return false;
206
+ }
207
+ const modalities = readAliased(generation, 'responseModalities')?.Value;
208
+ return (Array.isArray(modalities) &&
209
+ modalities.length > 0 &&
210
+ modalities.every((modality) => typeof modality === 'string' && modality.toUpperCase() === 'AUDIO'));
211
+ }
212
+ /** One field by its camelCase name or its snake_case name; `null` when both are present. */
213
+ function readAliased(value, camelName) {
214
+ const snakeName = snakeCase(camelName);
215
+ const hasCamel = Object.hasOwn(value, camelName);
216
+ const hasSnake = snakeName !== camelName && Object.hasOwn(value, snakeName);
217
+ if (hasCamel && hasSnake) {
218
+ return null;
219
+ }
220
+ return { Value: hasCamel ? value[camelName] : hasSnake ? value[snakeName] : undefined };
221
+ }
222
+ // ── Client messages ─────────────────────────────────────────────────────────────────────────────────
223
+ /** Why a one-key client message is dropped, or `null` when it may pass. */
224
+ function checkClientMessage(key, body) {
225
+ switch (MESSAGE_TYPES.get(key)) {
226
+ case 'realtimeInput':
227
+ return prefixed('realtimeInput', checkRealtimeInput(body));
228
+ case 'clientContent':
229
+ return prefixed('clientContent', checkClientContent(body));
230
+ case 'toolResponse':
231
+ return prefixed('toolResponse', checkToolResponse(body));
232
+ default:
233
+ return droppedTypeLabel(key);
234
+ }
235
+ }
236
+ /** The label for a message type that never passes: a second `setup`, a `contextUpdate`, or an unknown type. */
237
+ function droppedTypeLabel(key) {
238
+ if (key === 'setup') {
239
+ return 'setup';
240
+ }
241
+ return key === 'contextUpdate' || key === 'context_update' ? 'contextUpdate' : 'unknown';
242
+ }
243
+ /** A message type's drop label (`realtimeInput.media-type`), or `null` when there is no problem. */
244
+ function prefixed(type, problem) {
245
+ return problem === null ? null : `${type}.${problem}`;
246
+ }
247
+ /** Realtime input: audio and video blobs of the allowed types, text, the two activity markers, and `audioStreamEnd`. */
248
+ function checkRealtimeInput(body) {
249
+ const fields = readFields(body, REALTIME_INPUT_FIELDS);
250
+ if (typeof fields === 'string') {
251
+ return fields;
252
+ }
253
+ for (const [name, value] of fields) {
254
+ const problem = checkRealtimeField(name, value);
255
+ if (problem) {
256
+ return problem;
257
+ }
258
+ }
259
+ return null;
260
+ }
261
+ /** One realtime input field, by its camelCase name. */
262
+ function checkRealtimeField(name, value) {
263
+ switch (name) {
264
+ case 'audio':
265
+ return checkBlob(value, AUDIO_MIME_TYPES);
266
+ case 'video':
267
+ return checkBlob(value, IMAGE_MIME_TYPES);
268
+ case 'text':
269
+ return typeof value === 'string' ? null : 'invalid';
270
+ case 'audioStreamEnd':
271
+ return typeof value === 'boolean' ? null : 'invalid';
272
+ case 'activityStart':
273
+ case 'activityEnd':
274
+ return checkMarker(value);
275
+ default:
276
+ return 'unknown';
277
+ }
278
+ }
279
+ /** An activity marker: an empty object (the SDK's `ActivityStart` and `ActivityEnd` have no fields). */
280
+ function checkMarker(value) {
281
+ const fields = readFields(value, NO_FIELDS);
282
+ return typeof fields === 'string' ? fields : null;
283
+ }
284
+ /** Inline media: base64 `data` and a `mimeType` from `types`. */
285
+ function checkBlob(value, types) {
286
+ const fields = readFields(value, BLOB_FIELDS);
287
+ if (typeof fields === 'string') {
288
+ return fields;
289
+ }
290
+ const mimeType = fields.get('mimeType');
291
+ if (typeof mimeType !== 'string' || !types.has(mimeType)) {
292
+ return 'media-type';
293
+ }
294
+ return typeof fields.get('data') === 'string' ? null : 'invalid';
295
+ }
296
+ /** Client content: `user` turns only (or none, for the `turnComplete` commit), and a boolean `turnComplete`. */
297
+ function checkClientContent(body) {
298
+ const fields = readFields(body, CLIENT_CONTENT_FIELDS);
299
+ if (typeof fields === 'string') {
300
+ return fields;
301
+ }
302
+ const turnComplete = fields.get('turnComplete');
303
+ if (turnComplete !== undefined && typeof turnComplete !== 'boolean') {
304
+ return 'invalid';
305
+ }
306
+ const turns = fields.get('turns');
307
+ if (turns === undefined) {
308
+ return null;
309
+ }
310
+ if (!Array.isArray(turns)) {
311
+ return 'invalid';
312
+ }
313
+ for (const turn of turns) {
314
+ const problem = checkUserTurn(turn);
315
+ if (problem) {
316
+ return problem;
317
+ }
318
+ }
319
+ return null;
320
+ }
321
+ /** One turn: role `user` exactly, and parts of text or inline media of the allowed types. */
322
+ function checkUserTurn(turn) {
323
+ const fields = readFields(turn, CONTENT_FIELDS);
324
+ if (typeof fields === 'string') {
325
+ return fields;
326
+ }
327
+ const role = fields.get('role');
328
+ if (role !== 'user') {
329
+ return role === 'system' || role === 'model' ? role : 'role';
330
+ }
331
+ const parts = fields.get('parts');
332
+ if (parts === undefined) {
333
+ return null;
334
+ }
335
+ if (!Array.isArray(parts)) {
336
+ return 'invalid';
337
+ }
338
+ for (const part of parts) {
339
+ const problem = checkPart(part);
340
+ if (problem) {
341
+ return problem;
342
+ }
343
+ }
344
+ return null;
345
+ }
346
+ /** One part of a user turn: `text`, or `inlineData` of an allowed type; any other kind of part is `part`. */
347
+ function checkPart(part) {
348
+ const fields = readFields(part, PART_FIELDS);
349
+ if (typeof fields === 'string') {
350
+ return fields === 'unknown' ? 'part' : fields;
351
+ }
352
+ const text = fields.get('text');
353
+ if (text !== undefined && typeof text !== 'string') {
354
+ return 'invalid';
355
+ }
356
+ const inline = fields.get('inlineData');
357
+ return inline === undefined ? null : checkBlob(inline, TURN_MIME_TYPES);
358
+ }
359
+ /** A tool response: a non-empty list of function responses with the known fields only. */
360
+ function checkToolResponse(body) {
361
+ const fields = readFields(body, TOOL_RESPONSE_FIELDS);
362
+ if (typeof fields === 'string') {
363
+ return fields;
364
+ }
365
+ const responses = fields.get('functionResponses');
366
+ if (!Array.isArray(responses) || responses.length === 0) {
367
+ return 'invalid';
368
+ }
369
+ for (const response of responses) {
370
+ const problem = checkFunctionResponse(response);
371
+ if (problem) {
372
+ return problem;
373
+ }
374
+ }
375
+ return null;
376
+ }
377
+ /** One function response: `id`, `name`, `response` (an object), `scheduling`, `willContinue`, of the right types. */
378
+ function checkFunctionResponse(value) {
379
+ const fields = readFields(value, FUNCTION_RESPONSE_FIELDS);
380
+ if (typeof fields === 'string') {
381
+ return fields;
382
+ }
383
+ for (const [name, field] of fields) {
384
+ if (!(FUNCTION_RESPONSE_CHECKS.get(name)?.(field) ?? false)) {
385
+ return 'invalid';
386
+ }
387
+ }
388
+ return null;
389
+ }
390
+ // ── JSON ────────────────────────────────────────────────────────────────────────────────────────────
391
+ /**
392
+ * An object's fields under their camelCase names, or the problem: not an object, a key outside `allowed`, or one field
393
+ * under both of its names.
394
+ */
395
+ function readFields(value, allowed) {
396
+ if (!isJsonObject(value)) {
397
+ return 'invalid';
398
+ }
399
+ const fields = new Map();
400
+ for (const key of Object.keys(value)) {
401
+ const name = allowed.get(key);
402
+ if (name === undefined) {
403
+ return 'unknown';
404
+ }
405
+ if (fields.has(name)) {
406
+ return 'duplicate';
407
+ }
408
+ fields.set(name, value[key]);
409
+ }
410
+ return fields;
411
+ }
412
+ /** Parses text that should hold a JSON object; `null` for anything else. */
413
+ function parseJsonObject(text) {
414
+ try {
415
+ const value = JSON.parse(text);
416
+ return isJsonObject(value) ? value : null;
417
+ }
418
+ catch {
419
+ return null;
420
+ }
421
+ }
422
+ function isJsonObject(value) {
423
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
424
+ }
425
+ //# sourceMappingURL=geminiLiveRelayPolicy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geminiLiveRelayPolicy.js","sourceRoot":"","sources":["../src/geminiLiveRelayPolicy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,OAAO,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAC;AAalE;;;GAGG;AACH,MAAM,wBAAwB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAEjD,gEAAgE;AAChE,MAAM,gBAAgB,GAAwB,IAAI,GAAG,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC;AAEhF,gDAAgD;AAChD,MAAM,gBAAgB,GAAwB,IAAI,GAAG,CAAC,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC,CAAC;AAEnF,0EAA0E;AAC1E,MAAM,eAAe,GAAwB,IAAI,GAAG,CAAC,CAAC,GAAG,gBAAgB,EAAE,GAAG,gBAAgB,CAAC,CAAC,CAAC;AAEjG,iHAAiH;AACjH,MAAM,qBAAqB,GAAG,yBAAyB,CAAC;AACxD,MAAM,uBAAuB,GAAG,MAAM,CAAC,IAAI,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AAQ3E,6FAA6F;A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J from a {@link LiveConnectConfig}.
3
+ *
4
+ * MJAPI's relay sends this setup on every upstream connection of a relayed session and discards the browser's (see
5
+ * `GeminiLiveRelayPolicy`), so the agent's model, instructions, tools, voice, modalities and avatar come only from the
6
+ * server. `@google/genai` turns a config into this wire form inside `live.connect`, with converters it does not export,
7
+ * so this module maps a config the same way, for both endpoints:
8
+ *
9
+ * | Config key | Developer API | Gemini Enterprise |
10
+ * |---|---|---|
11
+ * | model | `models/<id>` | `projects/<p>/locations/<l>/publishers/google/models/<id>`; with an API key on Google's global route `publishers/google/models/<id>` |
12
+ * | modalities, temperature, topP, topK, maxOutputTokens, mediaResolution, seed, speechConfig, thinkingConfig, enableAffectiveDialog | under `generationConfig` | the same; modalities default to AUDIO |
13
+ * | `translationConfig` | under `generationConfig` | left out |
14
+ * | `systemInstruction` | a Content (text parts) | the same |
15
+ * | `tools` | as given | as given |
16
+ * | realtimeInputConfig, contextWindowCompression, proactivity, avatarConfig | top level, as given | the same |
17
+ * | `sessionResumption` | top level, `handle` only | top level, as given |
18
+ * | input/output transcription | top level, `{}` | top level, as given |
19
+ * | `safetySettings` | top level, `category` and `threshold` | top level, as given |
20
+ * | `explicitVadSignal` | left out | top level |
21
+ *
22
+ * Where the SDK would refuse a key on an endpoint (it throws), the setup leaves it out instead; every key left out is
23
+ * named in one log line. A parity test runs the installed SDK's `live.connect` against a local socket in both modes and
24
+ * compares, which is what catches a mapping the SDK changes on an upgrade.
25
+ *
26
+ * @module @memberjunction/ai-gemini
27
+ * @author MemberJunction.com
28
+ */
29
+ import { type LiveClientSetup, type LiveConnectConfig } from '@google/genai';
30
+ import type { GeminiLiveEndpoint } from './geminiLiveProfiles.js';
31
+ /** Where a Live setup is sent: the endpoint, the model and, on Gemini Enterprise, the Google Cloud project and location. */
32
+ export interface GeminiLiveSetupTarget {
33
+ /** The endpoint the setup is written for. It decides the model path and which keys the setup may carry. */
34
+ Endpoint: GeminiLiveEndpoint;
35
+ /** The model id (`gemini-3.8-live`), or a resource name, which is used as given when it already has the endpoint's prefix. */
36
+ Model: string;
37
+ /** The Google Cloud project. Required on Gemini Enterprise unless `Model` is a full `projects/…` resource name. */
38
+ Project?: string;
39
+ /** The Google Cloud location (`us-central1`, `us`, `eu`, `global`). Required with `Project`. */
40
+ Location?: string;
41
+ /**
42
+ * Gemini Enterprise with a Google Cloud API key on Google's global route: the model is written
43
+ * `publishers/<publisher>/models/<id>`, with no project or location (any given are ignored), as `@google/genai` writes
44
+ * it in API-key mode, where the key names the project and the socket is Google's global endpoint. (An API key on the
45
+ * regional route gives `Project` and `Location` instead, and the full name.)
46
+ */
47
+ UsesApiKey?: boolean;
48
+ }
49
+ /**
50
+ * Writes the Live `setup` message for a connect config, the way `@google/genai` 2.8 writes it inside `live.connect` for
51
+ * the target's endpoint (see the module's table). The result is plain JSON that shares nothing with `config`.
52
+ *
53
+ * @param target The endpoint, the model and, on Gemini Enterprise, the project and location.
54
+ * @param config The connect config, as `GeminiRealtime.BuildConnectConfig` builds it.
55
+ * @returns The `setup` message's body.
56
+ * @throws When the model id is empty or malformed, or a Gemini Enterprise target has no project or location.
57
+ */
58
+ export declare function BuildGeminiLiveSetup(target: GeminiLiveSetupTarget, config: LiveConnectConfig): LiveClientSetup;
59
+ /**
60
+ * The setup a session opens with when the browser asked for audio only: the same setup without video output (AUDIO
61
+ * modality, no `avatarConfig`). A setup that asks for no video comes back unchanged, so a browser can lower what the
62
+ * server minted and never raise it.
63
+ *
64
+ * @param setup A setup from {@link BuildGeminiLiveSetup}.
65
+ * @returns A copy, with video output removed when there was any.
66
+ */
67
+ export declare function BuildGeminiLiveAudioOnlySetup(setup: LiveClientSetup): LiveClientSetup;
68
+ /**
69
+ * The model's resource name a Live setup carries on the target's endpoint, as {@link BuildGeminiLiveSetup} writes it:
70
+ * `models/<id>` on the Developer API; `projects/<p>/locations/<l>/publishers/<publisher>/models/<id>` on Gemini
71
+ * Enterprise, or `publishers/<publisher>/models/<id>` with `UsesApiKey`. A server-side session hands it to the SDK where
72
+ * the SDK would not write it the same way itself: a Google Cloud API key on the regional route, which the SDK has no
73
+ * mode for (it adds the project prefix only without a key).
74
+ *
75
+ * @param target The endpoint, the model and, on Gemini Enterprise, the project and location.
76
+ * @throws When the model id is empty or malformed, or a Gemini Enterprise target has no project or location.
77
+ */
78
+ export declare function BuildGeminiLiveModelPath(target: GeminiLiveSetupTarget): string;
79
+ //# sourceMappingURL=geminiLiveSetup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geminiLiveSetup.d.ts","sourceRoot":"","sources":["../src/geminiLiveSetup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAKH,KAAK,eAAe,EACpB,KAAK,iBAAiB,EAMzB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE/D,4HAA4H;AAC5H,MAAM,WAAW,qBAAqB;IAClC,2GAA2G;IAC3G,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,8HAA8H;IAC9H,KAAK,EAAE,MAAM,CAAC;IACd,mHAAmH;IACnH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gGAAgG;IAChG,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACxB;AA2CD;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,qBAAqB,EAAE,MAAM,EAAE,iBAAiB,GAAG,eAAe,CAwB9G;AAED;;;;;;;GAOG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,eAAe,GAAG,eAAe,CASrF;AAID;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,qBAAqB,GAAG,MAAM,CAE9E"}