@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.
- package/dist/geminiAvatarVideoBitrate.d.ts +29 -0
- package/dist/geminiAvatarVideoBitrate.d.ts.map +1 -0
- package/dist/geminiAvatarVideoBitrate.js +58 -0
- package/dist/geminiAvatarVideoBitrate.js.map +1 -0
- package/dist/geminiBridgedAvatar.d.ts +119 -0
- package/dist/geminiBridgedAvatar.d.ts.map +1 -0
- package/dist/geminiBridgedAvatar.js +196 -0
- package/dist/geminiBridgedAvatar.js.map +1 -0
- package/dist/geminiLiveProfiles.d.ts +111 -4
- package/dist/geminiLiveProfiles.d.ts.map +1 -1
- package/dist/geminiLiveProfiles.js +169 -4
- package/dist/geminiLiveProfiles.js.map +1 -1
- package/dist/geminiLiveRelayPolicy.d.ts +87 -0
- package/dist/geminiLiveRelayPolicy.d.ts.map +1 -0
- package/dist/geminiLiveRelayPolicy.js +425 -0
- package/dist/geminiLiveRelayPolicy.js.map +1 -0
- package/dist/geminiLiveSetup.d.ts +79 -0
- package/dist/geminiLiveSetup.d.ts.map +1 -0
- package/dist/geminiLiveSetup.js +287 -0
- package/dist/geminiLiveSetup.js.map +1 -0
- package/dist/geminiRealtime.d.ts +152 -11
- package/dist/geminiRealtime.d.ts.map +1 -1
- package/dist/geminiRealtime.js +912 -133
- package/dist/geminiRealtime.js.map +1 -1
- package/dist/index.d.ts +24 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +58 -12
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/readme.md +66 -1
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The Gemini Live `setup` message, written by MJ 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 { Modality, } from '@google/genai';
|
|
30
|
+
/** Config keys that go under `generationConfig` on both endpoints. */
|
|
31
|
+
const GENERATION_KEYS = [
|
|
32
|
+
'responseModalities',
|
|
33
|
+
'temperature',
|
|
34
|
+
'topP',
|
|
35
|
+
'topK',
|
|
36
|
+
'maxOutputTokens',
|
|
37
|
+
'mediaResolution',
|
|
38
|
+
'seed',
|
|
39
|
+
'speechConfig',
|
|
40
|
+
'thinkingConfig',
|
|
41
|
+
'enableAffectiveDialog',
|
|
42
|
+
];
|
|
43
|
+
/** Config keys copied to the top level of the setup (the Developer API's narrower forms are applied after). */
|
|
44
|
+
const SETUP_KEYS = [
|
|
45
|
+
'realtimeInputConfig',
|
|
46
|
+
'sessionResumption',
|
|
47
|
+
'contextWindowCompression',
|
|
48
|
+
'inputAudioTranscription',
|
|
49
|
+
'outputAudioTranscription',
|
|
50
|
+
'proactivity',
|
|
51
|
+
'explicitVadSignal',
|
|
52
|
+
'avatarConfig',
|
|
53
|
+
'safetySettings',
|
|
54
|
+
];
|
|
55
|
+
/** Every config key the builder maps; any other key is left out of the setup and logged. */
|
|
56
|
+
const MAPPED_KEYS = new Set([...GENERATION_KEYS, ...SETUP_KEYS, 'systemInstruction', 'tools', 'translationConfig']);
|
|
57
|
+
/** The endpoints' names in log lines. */
|
|
58
|
+
const ENDPOINT_NAMES = { developer: 'the Gemini Developer API', enterprise: 'Gemini Enterprise' };
|
|
59
|
+
/**
|
|
60
|
+
* Writes the Live `setup` message for a connect config, the way `@google/genai` 2.8 writes it inside `live.connect` for
|
|
61
|
+
* the target's endpoint (see the module's table). The result is plain JSON that shares nothing with `config`.
|
|
62
|
+
*
|
|
63
|
+
* @param target The endpoint, the model and, on Gemini Enterprise, the project and location.
|
|
64
|
+
* @param config The connect config, as `GeminiRealtime.BuildConnectConfig` builds it.
|
|
65
|
+
* @returns The `setup` message's body.
|
|
66
|
+
* @throws When the model id is empty or malformed, or a Gemini Enterprise target has no project or location.
|
|
67
|
+
*/
|
|
68
|
+
export function BuildGeminiLiveSetup(target, config) {
|
|
69
|
+
const leftOut = [];
|
|
70
|
+
const setup = { model: liveModelPath(target) };
|
|
71
|
+
const generation = buildGenerationConfig(config, target.Endpoint, leftOut);
|
|
72
|
+
if (Object.keys(generation).length > 0) {
|
|
73
|
+
setup.generationConfig = generation;
|
|
74
|
+
}
|
|
75
|
+
const instruction = systemInstructionContent(config.systemInstruction, leftOut);
|
|
76
|
+
if (instruction) {
|
|
77
|
+
setup.systemInstruction = instruction;
|
|
78
|
+
}
|
|
79
|
+
if (config.tools != null) {
|
|
80
|
+
setup.tools = config.tools;
|
|
81
|
+
warnRawSchemas(config.tools, target.Model);
|
|
82
|
+
}
|
|
83
|
+
Object.assign(setup, buildSetupFields(config, target.Endpoint, leftOut));
|
|
84
|
+
leftOut.push(...Object.keys(config).filter((key) => !MAPPED_KEYS.has(key)));
|
|
85
|
+
if (leftOut.length > 0) {
|
|
86
|
+
console.warn(`[GeminiLiveSetup] Left out of the setup for ${target.Model} on ${ENDPOINT_NAMES[target.Endpoint]}: ` +
|
|
87
|
+
`${[...new Set(leftOut)].join(', ')}. These are not Live setup fields there.`);
|
|
88
|
+
}
|
|
89
|
+
return cloneJson(setup);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The setup a session opens with when the browser asked for audio only: the same setup without video output (AUDIO
|
|
93
|
+
* modality, no `avatarConfig`). A setup that asks for no video comes back unchanged, so a browser can lower what the
|
|
94
|
+
* server minted and never raise it.
|
|
95
|
+
*
|
|
96
|
+
* @param setup A setup from {@link BuildGeminiLiveSetup}.
|
|
97
|
+
* @returns A copy, with video output removed when there was any.
|
|
98
|
+
*/
|
|
99
|
+
export function BuildGeminiLiveAudioOnlySetup(setup) {
|
|
100
|
+
const copy = cloneJson(setup);
|
|
101
|
+
const modalities = copy.generationConfig?.responseModalities ?? [];
|
|
102
|
+
if (!modalities.includes(Modality.VIDEO) && copy.avatarConfig === undefined) {
|
|
103
|
+
return copy;
|
|
104
|
+
}
|
|
105
|
+
delete copy.avatarConfig;
|
|
106
|
+
copy.generationConfig = { ...copy.generationConfig, responseModalities: [Modality.AUDIO] };
|
|
107
|
+
return copy;
|
|
108
|
+
}
|
|
109
|
+
// ── Model path ──────────────────────────────────────────────────────────────────────────────────────
|
|
110
|
+
/**
|
|
111
|
+
* The model's resource name a Live setup carries on the target's endpoint, as {@link BuildGeminiLiveSetup} writes it:
|
|
112
|
+
* `models/<id>` on the Developer API; `projects/<p>/locations/<l>/publishers/<publisher>/models/<id>` on Gemini
|
|
113
|
+
* Enterprise, or `publishers/<publisher>/models/<id>` with `UsesApiKey`. A server-side session hands it to the SDK where
|
|
114
|
+
* the SDK would not write it the same way itself: a Google Cloud API key on the regional route, which the SDK has no
|
|
115
|
+
* mode for (it adds the project prefix only without a key).
|
|
116
|
+
*
|
|
117
|
+
* @param target The endpoint, the model and, on Gemini Enterprise, the project and location.
|
|
118
|
+
* @throws When the model id is empty or malformed, or a Gemini Enterprise target has no project or location.
|
|
119
|
+
*/
|
|
120
|
+
export function BuildGeminiLiveModelPath(target) {
|
|
121
|
+
return liveModelPath(target);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The model's resource name on the target's endpoint (the SDK's `tModel`, plus the project prefix on Enterprise unless an
|
|
125
|
+
* API key serves the session: the SDK adds the prefix only with a project and location, which API-key mode clears).
|
|
126
|
+
*/
|
|
127
|
+
function liveModelPath(target) {
|
|
128
|
+
const model = target.Model;
|
|
129
|
+
if (typeof model !== 'string' || model.length === 0 || model.includes('..') || model.includes('?') || model.includes('&')) {
|
|
130
|
+
throw new Error(`Gemini Live setup: the model id "${String(model)}" is empty or malformed.`);
|
|
131
|
+
}
|
|
132
|
+
if (target.Endpoint === 'developer') {
|
|
133
|
+
return model.startsWith('models/') || model.startsWith('tunedModels/') ? model : `models/${model}`;
|
|
134
|
+
}
|
|
135
|
+
const path = publisherModelPath(model);
|
|
136
|
+
if (!path.startsWith('publishers/') || target.UsesApiKey) {
|
|
137
|
+
return path; // already a projects/… (or models/…) name, or an API key's short name
|
|
138
|
+
}
|
|
139
|
+
if (!target.Project || !target.Location) {
|
|
140
|
+
throw new Error(`Gemini Live setup: ${model} on Gemini Enterprise needs a Google Cloud project and location.`);
|
|
141
|
+
}
|
|
142
|
+
return `projects/${target.Project}/locations/${target.Location}/${path}`;
|
|
143
|
+
}
|
|
144
|
+
/** A Gemini Enterprise model name before the project prefix: `publishers/<publisher>/models/<id>`, or as given. */
|
|
145
|
+
function publisherModelPath(model) {
|
|
146
|
+
if (model.startsWith('publishers/') || model.startsWith('projects/') || model.startsWith('models/')) {
|
|
147
|
+
return model;
|
|
148
|
+
}
|
|
149
|
+
if (model.includes('/')) {
|
|
150
|
+
const [publisher, id] = model.split('/', 2);
|
|
151
|
+
return `publishers/${publisher}/models/${id}`;
|
|
152
|
+
}
|
|
153
|
+
return `publishers/google/models/${model}`;
|
|
154
|
+
}
|
|
155
|
+
// ── generationConfig ────────────────────────────────────────────────────────────────────────────────
|
|
156
|
+
/** The setup's `generationConfig`: the generation keys, the endpoint's translation rule, and Enterprise's AUDIO default. */
|
|
157
|
+
function buildGenerationConfig(config, endpoint, leftOut) {
|
|
158
|
+
const generation = pickDefined(config, GENERATION_KEYS);
|
|
159
|
+
if (generation.speechConfig) {
|
|
160
|
+
generation.speechConfig = liveSpeechConfig(generation.speechConfig, leftOut);
|
|
161
|
+
}
|
|
162
|
+
if (endpoint === 'enterprise') {
|
|
163
|
+
if (config.responseModalities === undefined) {
|
|
164
|
+
generation.responseModalities = [Modality.AUDIO]; // the SDK's default in Enterprise mode
|
|
165
|
+
}
|
|
166
|
+
if (config.translationConfig != null) {
|
|
167
|
+
leftOut.push('translationConfig');
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
else if (config.translationConfig != null) {
|
|
171
|
+
generation.translationConfig = config.translationConfig;
|
|
172
|
+
}
|
|
173
|
+
return generation;
|
|
174
|
+
}
|
|
175
|
+
/** The speech config without `multiSpeakerVoiceConfig`, which the Live API refuses on both endpoints. */
|
|
176
|
+
function liveSpeechConfig(speech, leftOut) {
|
|
177
|
+
if (typeof speech !== 'object' || !('multiSpeakerVoiceConfig' in speech)) {
|
|
178
|
+
return speech;
|
|
179
|
+
}
|
|
180
|
+
const rest = { ...speech };
|
|
181
|
+
delete rest.multiSpeakerVoiceConfig;
|
|
182
|
+
leftOut.push('speechConfig.multiSpeakerVoiceConfig');
|
|
183
|
+
return rest;
|
|
184
|
+
}
|
|
185
|
+
// ── systemInstruction and tools ─────────────────────────────────────────────────────────────────────
|
|
186
|
+
/**
|
|
187
|
+
* The system instruction as a Content with text parts: a string or parts become a `user` Content (the SDK's
|
|
188
|
+
* `tContent`); a Content keeps its role. Parts other than text are left out (Google: "only text should be used").
|
|
189
|
+
*/
|
|
190
|
+
function systemInstructionContent(value, leftOut) {
|
|
191
|
+
if (value === undefined || value === null) {
|
|
192
|
+
return undefined;
|
|
193
|
+
}
|
|
194
|
+
const content = isContent(value) ? value : { role: 'user', parts: toParts(value) };
|
|
195
|
+
const parts = content.parts ?? [];
|
|
196
|
+
const textParts = parts.flatMap((part) => (isTextPart(part) ? [{ text: part.text }] : []));
|
|
197
|
+
if (textParts.length !== parts.length || parts.some((part) => Object.keys(part).length > 1)) {
|
|
198
|
+
leftOut.push('systemInstruction.parts (other than text)');
|
|
199
|
+
}
|
|
200
|
+
return content.role != null ? { parts: textParts, role: content.role } : { parts: textParts };
|
|
201
|
+
}
|
|
202
|
+
/** Whether a system instruction is already a Content (an object with a `parts` array). */
|
|
203
|
+
function isContent(value) {
|
|
204
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value) && 'parts' in value && Array.isArray(value.parts);
|
|
205
|
+
}
|
|
206
|
+
/** Whether a part is an object carrying text. */
|
|
207
|
+
function isTextPart(part) {
|
|
208
|
+
return typeof part === 'object' && part !== null && typeof part.text === 'string';
|
|
209
|
+
}
|
|
210
|
+
/** A part list from parts or strings (the SDK's `tParts`). */
|
|
211
|
+
function toParts(value) {
|
|
212
|
+
const items = Array.isArray(value) ? value : [value];
|
|
213
|
+
return items.map((item) => (typeof item === 'string' ? { text: item } : item));
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Tools go as given. The SDK rewrites a JSON schema in a declaration's `parameters` (`processJsonSchema`); the setup
|
|
217
|
+
* does not, so one line names the declarations that use `parameters` instead of `parametersJsonSchema`.
|
|
218
|
+
*/
|
|
219
|
+
function warnRawSchemas(tools, model) {
|
|
220
|
+
const names = (Array.isArray(tools) ? tools : [])
|
|
221
|
+
.flatMap((tool) => typeof tool === 'object' && tool !== null && 'functionDeclarations' in tool && Array.isArray(tool.functionDeclarations) ? tool.functionDeclarations : [])
|
|
222
|
+
.filter((declaration) => typeof declaration === 'object' && declaration !== null && declaration.parameters !== undefined)
|
|
223
|
+
.map((declaration) => declaration.name ?? '(unnamed)');
|
|
224
|
+
if (names.length > 0) {
|
|
225
|
+
console.warn(`[GeminiLiveSetup] Tool(s) ${names.join(', ')} for ${model} declare \`parameters\`, which the setup sends as given ` +
|
|
226
|
+
'(the SDK would rewrite a JSON schema there). Declare `parametersJsonSchema` instead.');
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
// ── Top-level fields ────────────────────────────────────────────────────────────────────────────────
|
|
230
|
+
/** The setup's top-level fields, narrowed to what the Developer API takes when that is the endpoint. */
|
|
231
|
+
function buildSetupFields(config, endpoint, leftOut) {
|
|
232
|
+
const fields = pickDefined(config, SETUP_KEYS);
|
|
233
|
+
if (endpoint === 'developer') {
|
|
234
|
+
narrowForDeveloper(fields, leftOut);
|
|
235
|
+
}
|
|
236
|
+
return fields;
|
|
237
|
+
}
|
|
238
|
+
/** The Developer API's forms: no explicit VAD signal, a bare resumption handle, empty transcription configs, plain safety settings. */
|
|
239
|
+
function narrowForDeveloper(fields, leftOut) {
|
|
240
|
+
if (fields.explicitVadSignal !== undefined) {
|
|
241
|
+
delete fields.explicitVadSignal;
|
|
242
|
+
leftOut.push('explicitVadSignal');
|
|
243
|
+
}
|
|
244
|
+
if (fields.sessionResumption) {
|
|
245
|
+
fields.sessionResumption = keepFields(fields.sessionResumption, ['handle'], 'sessionResumption', leftOut);
|
|
246
|
+
}
|
|
247
|
+
if (fields.inputAudioTranscription) {
|
|
248
|
+
fields.inputAudioTranscription = keepFields(fields.inputAudioTranscription, [], 'inputAudioTranscription', leftOut);
|
|
249
|
+
}
|
|
250
|
+
if (fields.outputAudioTranscription) {
|
|
251
|
+
fields.outputAudioTranscription = keepFields(fields.outputAudioTranscription, [], 'outputAudioTranscription', leftOut);
|
|
252
|
+
}
|
|
253
|
+
if (Array.isArray(fields.safetySettings)) {
|
|
254
|
+
fields.safetySettings = fields.safetySettings.map((setting) => keepFields(setting, ['category', 'threshold'], 'safetySettings', leftOut));
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
// ── Helpers ─────────────────────────────────────────────────────────────────────────────────────────
|
|
258
|
+
/** The listed keys of `value` that hold something other than `null` or `undefined` (the SDK's `!= null` test). */
|
|
259
|
+
function pickDefined(source, keys) {
|
|
260
|
+
const picked = {};
|
|
261
|
+
for (const key of keys) {
|
|
262
|
+
const value = source[key];
|
|
263
|
+
if (value !== undefined && value !== null) {
|
|
264
|
+
picked[key] = value;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return picked;
|
|
268
|
+
}
|
|
269
|
+
/** `value` with only `keys` kept; every other key is named in `leftOut` under `path`. A non-object becomes `{}`. */
|
|
270
|
+
function keepFields(value, keys, path, leftOut) {
|
|
271
|
+
if (typeof value !== 'object' || value === null) {
|
|
272
|
+
leftOut.push(path);
|
|
273
|
+
return {};
|
|
274
|
+
}
|
|
275
|
+
const allowed = keys;
|
|
276
|
+
for (const key of Object.keys(value)) {
|
|
277
|
+
if (!allowed.includes(key)) {
|
|
278
|
+
leftOut.push(`${path}.${key}`);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return pickDefined(value, keys);
|
|
282
|
+
}
|
|
283
|
+
/** A deep copy through JSON, which is also what the wire carries (no `undefined`, no functions). */
|
|
284
|
+
function cloneJson(value) {
|
|
285
|
+
return JSON.parse(JSON.stringify(value));
|
|
286
|
+
}
|
|
287
|
+
//# sourceMappingURL=geminiLiveSetup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"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C,GAAG,CAAC,CAAC;QAC1B,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACxC,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACxB,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,oHAAoH;AACpH,SAAS,UAAU,CAAsC,KAAQ,EAAE,IAAkB,EAAE,IAAY,EAAE,OAAiB;IAClH,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAC9C,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnB,OAAO,EAAE,CAAC;IACd,CAAC;IACD,MAAM,OAAO,GAA2B,IAAI,CAAC;IAC7C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACnC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACzB,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,GAAG,EAAE,CAAC,CAAC;QACnC,CAAC;IACL,CAAC;IACD,OAAO,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AACpC,CAAC;AAED,oGAAoG;AACpG,SAAS,SAAS,CAAI,KAAQ;IAC1B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAM,CAAC;AAClD,CAAC"}
|
package/dist/geminiRealtime.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Behavior, FunctionResponseScheduling, type AuthToken, type CreateAuthTokenParameters, type LiveServerMessage, type LiveConnectConfig, type FunctionDeclaration, type FunctionResponse, type Content, type Blob as GeminiBlob, type ActivityStart, type ActivityEnd, ThinkingLevel } from '@google/genai';
|
|
2
|
-
import { BaseRealtimeModel, type ClientRealtimeSessionConfig, type IRealtimeSession, type RealtimeSessionParams, type RealtimeToolDefinition, type RealtimeVoiceOption } from '@memberjunction/ai';
|
|
3
|
-
import { type GeminiThinkingLevel } from './geminiLiveProfiles.js';
|
|
1
|
+
import { Behavior, FunctionResponseScheduling, type AuthToken, type CreateAuthTokenParameters, type LiveServerMessage, type LiveConnectConfig, type ContextWindowCompressionConfig, type FunctionDeclaration, type FunctionResponse, type Content, type Blob as GeminiBlob, type ActivityStart, type ActivityEnd, ThinkingLevel } from '@google/genai';
|
|
2
|
+
import { BaseRealtimeModel, type ClientRealtimeSessionConfig, type IRealtimeSession, type RealtimeSessionParams, type RealtimeToolDefinition, type JSONObject, type RealtimeVoiceOption, type RealtimeAvatarStatus } from '@memberjunction/ai';
|
|
3
|
+
import { type GeminiThinkingLevel, type GeminiLiveEndpoint, type GeminiLiveResolvedProfile } from './geminiLiveProfiles.js';
|
|
4
4
|
/**
|
|
5
5
|
* The minimal subset of `@google/genai`'s `Session` that the realtime driver depends on. Declaring
|
|
6
6
|
* the seam as an interface (rather than the concrete SDK `Session`) lets unit tests inject a fully
|
|
@@ -16,13 +16,18 @@ export interface GeminiLiveSession {
|
|
|
16
16
|
*/
|
|
17
17
|
sendRealtimeInput(params: {
|
|
18
18
|
audio?: GeminiBlob;
|
|
19
|
+
/** One video frame: an encoded image (JPEG or PNG). */
|
|
20
|
+
video?: GeminiBlob;
|
|
19
21
|
media?: GeminiBlob;
|
|
20
22
|
text?: string;
|
|
21
23
|
/** Manual activity markers — used in MEETING mode (automatic activity detection disabled). */
|
|
22
24
|
activityStart?: ActivityStart;
|
|
23
25
|
activityEnd?: ActivityEnd;
|
|
24
26
|
}): void;
|
|
25
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Appends client content to the conversation: the initial context and context notes (`turnComplete: false`), or a
|
|
29
|
+
* bare `turnComplete: true` that closes the turn a note left open.
|
|
30
|
+
*/
|
|
26
31
|
sendClientContent(params: {
|
|
27
32
|
turns?: Content[];
|
|
28
33
|
turnComplete?: boolean;
|
|
@@ -86,6 +91,19 @@ export declare class GeminiRealtime extends BaseRealtimeModel {
|
|
|
86
91
|
* the token via `liveConnectConstraints`.
|
|
87
92
|
*/
|
|
88
93
|
get SupportsClientDirect(): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* The Gemini endpoint this driver talks to. The Developer API here; the Gemini Enterprise driver (Vertex AI)
|
|
96
|
+
* overrides it. Every profile lookup passes it, because what a model renders depends on the endpoint (live avatars
|
|
97
|
+
* are Enterprise only).
|
|
98
|
+
*/
|
|
99
|
+
protected get Endpoint(): GeminiLiveEndpoint;
|
|
100
|
+
/**
|
|
101
|
+
* Whether the model renders a live avatar on this driver's endpoint, from its Live profile: never on the Developer
|
|
102
|
+
* API; on Gemini Enterprise for the models whose profile says so.
|
|
103
|
+
*
|
|
104
|
+
* @param model The model's API name.
|
|
105
|
+
*/
|
|
106
|
+
SupportsAvatarOutput(model: string): boolean;
|
|
89
107
|
/**
|
|
90
108
|
* Gemini Live sessions accept dynamically-defined tools at connect/mint time.
|
|
91
109
|
*/
|
|
@@ -94,7 +112,7 @@ export declare class GeminiRealtime extends BaseRealtimeModel {
|
|
|
94
112
|
* Mints an ephemeral, server-scoped Live credential for a **client-direct** session.
|
|
95
113
|
*
|
|
96
114
|
* The connect config is built EXACTLY as {@link StartSession} builds it (same
|
|
97
|
-
* {@link
|
|
115
|
+
* {@link BuildConnectConfig}: audio modality, input+output transcription, system instruction,
|
|
98
116
|
* mapped tools) and is **locked into the token** via `liveConnectConstraints` +
|
|
99
117
|
* `lockAdditionalFields: []` — so the API ignores any attempt by the browser to change the
|
|
100
118
|
* locked fields. The same config is ALSO carried in `SessionConfig` (as `{ model, config }`)
|
|
@@ -109,6 +127,17 @@ export declare class GeminiRealtime extends BaseRealtimeModel {
|
|
|
109
127
|
* @returns The minted {@link ClientRealtimeSessionConfig} the browser authenticates + applies.
|
|
110
128
|
*/
|
|
111
129
|
CreateClientSession(params: RealtimeSessionParams): Promise<ClientRealtimeSessionConfig>;
|
|
130
|
+
/**
|
|
131
|
+
* The minted session config, the private pact with the browser driver: a plain-JSON copy of the model and the config
|
|
132
|
+
* the browser passes to `live.connect`, plus the model's facts on this driver's endpoint (idle signal, tooling, inbound
|
|
133
|
+
* video limits, and the `avatar` block when the session renders one).
|
|
134
|
+
*
|
|
135
|
+
* @param model The model id.
|
|
136
|
+
* @param config The session's connect config, as {@link BuildConnectConfig} built it. It decides the avatar block.
|
|
137
|
+
* @param browserConfig The config the browser passes to `live.connect`: the full config here; a driver whose sessions
|
|
138
|
+
* go through MJAPI's relay, which writes the setup, passes a smaller one.
|
|
139
|
+
*/
|
|
140
|
+
protected SessionPactFor(model: string, config: LiveConnectConfig, browserConfig?: LiveConnectConfig): JSONObject;
|
|
112
141
|
/**
|
|
113
142
|
* Mint seam for the ephemeral auth token. Production routes through the SDK's
|
|
114
143
|
* `authTokens.create` on a `v1alpha` client (ephemeral tokens are v1alpha-only); unit tests
|
|
@@ -145,6 +174,13 @@ export declare class GeminiRealtime extends BaseRealtimeModel {
|
|
|
145
174
|
* there — `systemInstruction`, `tools`, and the transcription configs are NOT, and their
|
|
146
175
|
* presence 400s the entire mint. Only defined fields are copied (an absent key must stay
|
|
147
176
|
* absent so it doesn't enter the mask).
|
|
177
|
+
*
|
|
178
|
+
* `contextWindowCompression` is left out on purpose. No test or doc shows the mask accepts
|
|
179
|
+
* it, and a rejected mask would fail every client-direct session. The browser applies it from
|
|
180
|
+
* `SessionConfig`, like the other server-built keys the token cannot lock.
|
|
181
|
+
*
|
|
182
|
+
* `sessionResumption: {}` is locked as in Google's ephemeral-token example. The browser adds
|
|
183
|
+
* the handle when it resumes, and Google accepts the same token for that until `expireTime`.
|
|
148
184
|
*/
|
|
149
185
|
static BuildConstraintConfig(config: LiveConnectConfig): LiveConnectConfig;
|
|
150
186
|
/**
|
|
@@ -168,18 +204,106 @@ export declare class GeminiRealtime extends BaseRealtimeModel {
|
|
|
168
204
|
* this a pure calculation.
|
|
169
205
|
*/
|
|
170
206
|
private static buildSpeechConfig;
|
|
207
|
+
/**
|
|
208
|
+
* Deletes every key in {@link REALTIME_SHARED_CONFIG_KEYS} from the copy of the config bag that is merged into the
|
|
209
|
+
* connect config, so none reaches the Live SDK raw, and logs what the session will not apply:
|
|
210
|
+
*
|
|
211
|
+
* - the keys Gemini Live has no use for, in one line;
|
|
212
|
+
* - a key the driver applies after the merge ({@link GEMINI_SHARED_KEYS_APPLIED_AFTER_MERGE}) whose value is of a
|
|
213
|
+
* type it cannot read, one line each. `null` reads as unset, the way a config layer clears an inherited value.
|
|
214
|
+
*
|
|
215
|
+
* A key the driver applies, with a value it can read, gets no line here: `applyModelLegality` applies it and logs a
|
|
216
|
+
* value the model or endpoint doesn't accept (a turn coverage, a thinking level).
|
|
217
|
+
*
|
|
218
|
+
* @param cfg The copy of the session config bag that is merged into the connect config. The keys are deleted from it.
|
|
219
|
+
*/
|
|
220
|
+
private static scrubSharedKeys;
|
|
221
|
+
/**
|
|
222
|
+
* Keeps a config-bag `contextWindowCompression` only when it is an object. The bag is untyped
|
|
223
|
+
* JSON, so a string, array or null would otherwise reach the wire and fail the session at
|
|
224
|
+
* connect. A malformed value is replaced by the default and reported; a well-formed one wins
|
|
225
|
+
* over the default, like every other bag key.
|
|
226
|
+
*/
|
|
227
|
+
private static ensureContextWindowCompression;
|
|
171
228
|
/** Narrows an unenforced config-bag value to a real object — not a string, array, or null. */
|
|
172
229
|
private static isPlainObject;
|
|
230
|
+
/**
|
|
231
|
+
* The context-window compression every Gemini Live session gets unless the config bag sets
|
|
232
|
+
* its own: a server-side sliding window with Google's default trigger and target sizes.
|
|
233
|
+
*
|
|
234
|
+
* Without compression, Google ends a session when its context fills: about 15 minutes for
|
|
235
|
+
* audio only and about 2 minutes for audio plus video (Google's Live API session-management
|
|
236
|
+
* docs). With compression the server drops the oldest turns and the session continues.
|
|
237
|
+
* Session resumption handles a different limit (a single connection lasts about 10 minutes)
|
|
238
|
+
* and does not lift this one.
|
|
239
|
+
*
|
|
240
|
+
* Returns a new object on each call so no session shares mutable config with another.
|
|
241
|
+
*/
|
|
242
|
+
static DefaultContextWindowCompression(): ContextWindowCompressionConfig;
|
|
173
243
|
/**
|
|
174
244
|
* Builds the {@link LiveConnectConfig} from the Core session params: audio response modality,
|
|
175
|
-
* input/output transcription, system instruction,
|
|
176
|
-
*
|
|
177
|
-
*
|
|
245
|
+
* input/output transcription, system instruction, sliding-window context compression
|
|
246
|
+
* ({@link GeminiRealtime.DefaultContextWindowCompression}), session resumption (unless the
|
|
247
|
+
* session is zero-data-retention), mapped tools, the neutral `voice` key mapped via
|
|
248
|
+
* {@link GeminiRealtime.buildSpeechConfig}, plus any provider-specific overrides from the open
|
|
249
|
+
* config bag.
|
|
250
|
+
*/
|
|
251
|
+
protected BuildConnectConfig(params: RealtimeSessionParams): LiveConnectConfig;
|
|
252
|
+
/**
|
|
253
|
+
* Renders the requested avatar when the model can on this endpoint: video output and the avatar's name, at the
|
|
254
|
+
* bitrate the deployment asks for (`MJ_GEMINI_AVATAR_VIDEO_BITRATE_BPS`, 2 Mbps by default; `0` leaves the field out).
|
|
255
|
+
* Otherwise the session stays audio-only and one line says why. Either way a VIDEO modality or an `avatarConfig` from
|
|
256
|
+
* the config bag is removed: an avatar comes only from the session's avatar request. Applied last, like the legality
|
|
257
|
+
* rules. Every session's setup comes from here: the browser mint, the relay's setup and server-side sessions.
|
|
258
|
+
*/
|
|
259
|
+
private applyAvatarOutput;
|
|
260
|
+
/** Why this session can't render the requested avatar, or `undefined` when it can. */
|
|
261
|
+
private avatarUnavailableReason;
|
|
262
|
+
/** The one log line for an avatar the session asked for and won't render. */
|
|
263
|
+
private avatarUnavailableMessage;
|
|
264
|
+
/** Removes a VIDEO response modality and any `avatarConfig` that came from somewhere other than an avatar request. */
|
|
265
|
+
private static removeVideoOutput;
|
|
266
|
+
/**
|
|
267
|
+
* A server-side session (a meeting bot) asks for an avatar only when its host publishes the video into a room
|
|
268
|
+
* (`Delivery: 'room'`, a bot that decodes it). Anywhere else nothing on the server can show it: returns the params
|
|
269
|
+
* without the request, logging the reason once. A phone call never gets here with a request: its session prep asks
|
|
270
|
+
* for none (`'phone'`).
|
|
271
|
+
*/
|
|
272
|
+
private withoutAvatarOnServer;
|
|
273
|
+
/**
|
|
274
|
+
* What the mint tells the call about the avatar the session asked for: granted, or audio only and why. `undefined` when
|
|
275
|
+
* it asked for none. Read from the connect config {@link BuildConnectConfig} built, so it says what the session does:
|
|
276
|
+
* an `avatarConfig` there is the grant. Every Gemini driver returns it on its minted config.
|
|
277
|
+
*
|
|
278
|
+
* @param params The session parameters (the avatar request).
|
|
279
|
+
* @param config The connect config the session was built with.
|
|
280
|
+
*/
|
|
281
|
+
protected AvatarStatusFor(params: RealtimeSessionParams, config: LiveConnectConfig): RealtimeAvatarStatus | undefined;
|
|
282
|
+
/**
|
|
283
|
+
* What became of a server-side session's avatar request: {@link AvatarStatusFor}, except that a session whose host
|
|
284
|
+
* can't publish the avatar (no `Delivery: 'room'`) is audio only as `bridged`. `undefined` without a request.
|
|
285
|
+
*
|
|
286
|
+
* @param params The session parameters as the host passed them (the avatar request included).
|
|
287
|
+
* @param config The connect config the session was built with.
|
|
288
|
+
*/
|
|
289
|
+
private serverAvatarStatus;
|
|
290
|
+
/**
|
|
291
|
+
* The minted session config's avatar block: present only when this session renders an avatar, so the browser driver
|
|
292
|
+
* knows to expect video parts, their encoding, and whether they carry the voice.
|
|
293
|
+
*
|
|
294
|
+
* @param config The connect config the session was built with.
|
|
295
|
+
* @param profile The model's profile on this driver's endpoint.
|
|
178
296
|
*/
|
|
179
|
-
|
|
297
|
+
protected AvatarPactFor(config: LiveConnectConfig, profile: GeminiLiveResolvedProfile): JSONObject;
|
|
180
298
|
/**
|
|
181
|
-
*
|
|
182
|
-
*
|
|
299
|
+
* Keeps session resumption off a zero-data-retention session, even when the config bag asks
|
|
300
|
+
* for it: Google stores resumable session state, which such a model promises not to do.
|
|
301
|
+
* Applied after the bag merge, like the legality rules, so the bag cannot turn it back on.
|
|
302
|
+
*/
|
|
303
|
+
private static applyZeroDataRetention;
|
|
304
|
+
/**
|
|
305
|
+
* Enforces what the TARGET model, on the session's endpoint, actually accepts, and states what MJ
|
|
306
|
+
* wants rather than inheriting a provider default.
|
|
183
307
|
*
|
|
184
308
|
* Every rule here fails at SESSION MINT if broken — upstream of all UI code, the same failure
|
|
185
309
|
* class as an illegal tool name — so none of it can be left to discover at connect time. Facts
|
|
@@ -187,6 +311,23 @@ export declare class GeminiRealtime extends BaseRealtimeModel {
|
|
|
187
311
|
* `plans/realtime/gemini-3-8-live.md` §3 for their sourcing.
|
|
188
312
|
*/
|
|
189
313
|
private applyModelLegality;
|
|
314
|
+
/**
|
|
315
|
+
* C4 — turn coverage is STATED, never inherited. The SDK's enum doc says coverage defaults to
|
|
316
|
+
* TURN_INCLUDES_ONLY_ACTIVITY while the 3.8 model page says the default includes all video; sending it explicitly
|
|
317
|
+
* makes that contradiction irrelevant. Absent config means audio only, because video frames are billed and consume
|
|
318
|
+
* context, so the expensive option must be asked for rather than inherited. Only a coverage the session's endpoint
|
|
319
|
+
* accepts is sent ({@link ResolveGeminiTurnCoverage}): Gemini Enterprise closes the setup on
|
|
320
|
+
* TURN_INCLUDES_AUDIO_ACTIVITY_AND_ALL_VIDEO, so a session there that asks for it gets audio only, and one line names
|
|
321
|
+
* what was asked for and what was sent. The setup the relay writes and a bridged session's both come from here.
|
|
322
|
+
*
|
|
323
|
+
* @param config The connect config being built.
|
|
324
|
+
* @param requested The bag's `turnDetection.Coverage`, if any.
|
|
325
|
+
* @param profile The model's profile on the session's endpoint.
|
|
326
|
+
* @param model The model id, for the log line.
|
|
327
|
+
*/
|
|
328
|
+
private static applyTurnCoverage;
|
|
329
|
+
/** Maps MJ's turn coverage onto the SDK's {@link TurnCoverage} wire value. */
|
|
330
|
+
private static mapTurnCoverage;
|
|
190
331
|
/**
|
|
191
332
|
* Narrows a bag value to a plain object, or `undefined`.
|
|
192
333
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geminiRealtime.d.ts","sourceRoot":"","sources":["../src/geminiRealtime.ts"],"names":[],"mappings":"AACA,OAAO,EAGH,QAAQ,EACR,0BAA0B,EAC1B,KAAK,SAAS,EACd,KAAK,yBAAyB,EAC9B,KAAK,iBAAiB,EAEtB,KAAK,iBAAiB,
|
|
1
|
+
{"version":3,"file":"geminiRealtime.d.ts","sourceRoot":"","sources":["../src/geminiRealtime.ts"],"names":[],"mappings":"AACA,OAAO,EAGH,QAAQ,EACR,0BAA0B,EAC1B,KAAK,SAAS,EACd,KAAK,yBAAyB,EAC9B,KAAK,iBAAiB,EAEtB,KAAK,iBAAiB,EACtB,KAAK,8BAA8B,EAEnC,KAAK,mBAAmB,EAExB,KAAK,gBAAgB,EACrB,KAAK,OAAO,EAEZ,KAAK,IAAI,IAAI,UAAU,EACvB,KAAK,aAAa,EAClB,KAAK,WAAW,EAEhB,aAAa,EAChB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACH,iBAAiB,EAGjB,KAAK,2BAA2B,EAChC,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAK3B,KAAK,UAAU,EAGf,KAAK,mBAAmB,EAYxB,KAAK,oBAAoB,EAI5B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAMH,KAAK,mBAAmB,EAExB,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,EACjC,MAAM,sBAAsB,CAAC;AAuD9B;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAC9B;;;;;OAKG;IACH,iBAAiB,CAAC,MAAM,EAAE;QACtB,KAAK,CAAC,EAAE,UAAU,CAAC;QACnB,uDAAuD;QACvD,KAAK,CAAC,EAAE,UAAU,CAAC;QACnB,KAAK,CAAC,EAAE,UAAU,CAAC;QACnB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,8FAA8F;QAC9F,aAAa,CAAC,EAAE,aAAa,CAAC;QAC9B,WAAW,CAAC,EAAE,WAAW,CAAC;KAC7B,GAAG,IAAI,C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