@memberjunction/ai-gemini 6.2.0-edge.3 → 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 +909 -133
- package/dist/geminiRealtime.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/readme.md +66 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The video bitrate a Gemini Live avatar session asks Google for (`avatarConfig.videoBitrateBps`), and the
|
|
3
|
+
* deployment setting that changes it.
|
|
4
|
+
*
|
|
5
|
+
* MJ asks for 2 Mbps: Google's sample avatar streams run at about 8.5 Mbps, and MJAPI relays the avatar to the browser.
|
|
6
|
+
* The field is in `@google/genai`'s types but not on Google's pages, so a deployment can change the number, or leave the
|
|
7
|
+
* field out and let Google choose, without a rebuild: `MJ_GEMINI_AVATAR_VIDEO_BITRATE_BPS` (bits per second; `0` leaves
|
|
8
|
+
* the field out). It is read each time a session's connect config is built, so a restart of the server applies it to the
|
|
9
|
+
* browser mint, the relay's setup and server-side (meeting) sessions alike.
|
|
10
|
+
*
|
|
11
|
+
* @module @memberjunction/ai-gemini
|
|
12
|
+
* @author MemberJunction.com
|
|
13
|
+
*/
|
|
14
|
+
/** The environment variable that sets the avatar's video bitrate, in bits per second (`0` leaves the field out). */
|
|
15
|
+
export declare const GEMINI_AVATAR_VIDEO_BITRATE_ENV = "MJ_GEMINI_AVATAR_VIDEO_BITRATE_BPS";
|
|
16
|
+
/** The bitrate MJ asks for when the variable is unset or not a whole number: 2 Mbps. */
|
|
17
|
+
export declare const GEMINI_AVATAR_VIDEO_BITRATE_BPS_DEFAULT = 2000000;
|
|
18
|
+
/**
|
|
19
|
+
* The video bitrate for a Gemini Live avatar session's `avatarConfig.videoBitrateBps`, or `null` to leave the field out.
|
|
20
|
+
*
|
|
21
|
+
* - Unset or blank: {@link GEMINI_AVATAR_VIDEO_BITRATE_BPS_DEFAULT}.
|
|
22
|
+
* - `0`: `null`, so Google uses its own bitrate.
|
|
23
|
+
* - A whole number of bits per second: that number.
|
|
24
|
+
* - Anything else: the default, with one log line per such value.
|
|
25
|
+
*
|
|
26
|
+
* @param env The environment to read; the process's by default.
|
|
27
|
+
*/
|
|
28
|
+
export declare function ResolveGeminiAvatarVideoBitrateBps(env?: Readonly<Record<string, string | undefined>>): number | null;
|
|
29
|
+
//# sourceMappingURL=geminiAvatarVideoBitrate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geminiAvatarVideoBitrate.d.ts","sourceRoot":"","sources":["../src/geminiAvatarVideoBitrate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,oHAAoH;AACpH,eAAO,MAAM,+BAA+B,uCAAuC,CAAC;AAEpF,wFAAwF;AACxF,eAAO,MAAM,uCAAuC,UAAY,CAAC;AAQjE;;;;;;;;;GASG;AACH,wBAAgB,kCAAkC,CAAC,GAAG,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAwB,GAAG,MAAM,GAAG,IAAI,CAW1I"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The video bitrate a Gemini Live avatar session asks Google for (`avatarConfig.videoBitrateBps`), and the
|
|
3
|
+
* deployment setting that changes it.
|
|
4
|
+
*
|
|
5
|
+
* MJ asks for 2 Mbps: Google's sample avatar streams run at about 8.5 Mbps, and MJAPI relays the avatar to the browser.
|
|
6
|
+
* The field is in `@google/genai`'s types but not on Google's pages, so a deployment can change the number, or leave the
|
|
7
|
+
* field out and let Google choose, without a rebuild: `MJ_GEMINI_AVATAR_VIDEO_BITRATE_BPS` (bits per second; `0` leaves
|
|
8
|
+
* the field out). It is read each time a session's connect config is built, so a restart of the server applies it to the
|
|
9
|
+
* browser mint, the relay's setup and server-side (meeting) sessions alike.
|
|
10
|
+
*
|
|
11
|
+
* @module @memberjunction/ai-gemini
|
|
12
|
+
* @author MemberJunction.com
|
|
13
|
+
*/
|
|
14
|
+
/** The environment variable that sets the avatar's video bitrate, in bits per second (`0` leaves the field out). */
|
|
15
|
+
export const GEMINI_AVATAR_VIDEO_BITRATE_ENV = 'MJ_GEMINI_AVATAR_VIDEO_BITRATE_BPS';
|
|
16
|
+
/** The bitrate MJ asks for when the variable is unset or not a whole number: 2 Mbps. */
|
|
17
|
+
export const GEMINI_AVATAR_VIDEO_BITRATE_BPS_DEFAULT = 2_000_000;
|
|
18
|
+
/** The longest part of an unusable value quoted in the log line. */
|
|
19
|
+
const MAX_QUOTED_CHARS = 40;
|
|
20
|
+
/** Unusable values already reported, so each is logged once per process. */
|
|
21
|
+
const reportedValues = new Set();
|
|
22
|
+
/**
|
|
23
|
+
* The video bitrate for a Gemini Live avatar session's `avatarConfig.videoBitrateBps`, or `null` to leave the field out.
|
|
24
|
+
*
|
|
25
|
+
* - Unset or blank: {@link GEMINI_AVATAR_VIDEO_BITRATE_BPS_DEFAULT}.
|
|
26
|
+
* - `0`: `null`, so Google uses its own bitrate.
|
|
27
|
+
* - A whole number of bits per second: that number.
|
|
28
|
+
* - Anything else: the default, with one log line per such value.
|
|
29
|
+
*
|
|
30
|
+
* @param env The environment to read; the process's by default.
|
|
31
|
+
*/
|
|
32
|
+
export function ResolveGeminiAvatarVideoBitrateBps(env = processEnvironment()) {
|
|
33
|
+
const raw = env[GEMINI_AVATAR_VIDEO_BITRATE_ENV]?.trim() ?? '';
|
|
34
|
+
if (raw.length === 0) {
|
|
35
|
+
return GEMINI_AVATAR_VIDEO_BITRATE_BPS_DEFAULT;
|
|
36
|
+
}
|
|
37
|
+
const value = /^\d+$/.test(raw) ? Number(raw) : Number.NaN;
|
|
38
|
+
if (Number.isSafeInteger(value)) {
|
|
39
|
+
return value === 0 ? null : value;
|
|
40
|
+
}
|
|
41
|
+
reportUnusable(raw);
|
|
42
|
+
return GEMINI_AVATAR_VIDEO_BITRATE_BPS_DEFAULT;
|
|
43
|
+
}
|
|
44
|
+
/** One log line per unusable value, quoting it shortened and with only printable characters. */
|
|
45
|
+
function reportUnusable(raw) {
|
|
46
|
+
if (reportedValues.has(raw)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
reportedValues.add(raw);
|
|
50
|
+
const shown = raw.replace(/[^\x20-\x7E]/g, '?').slice(0, MAX_QUOTED_CHARS);
|
|
51
|
+
console.warn(`[GeminiRealtime] ${GEMINI_AVATAR_VIDEO_BITRATE_ENV} "${shown}" is not a whole number of bits per second; avatar sessions ask for ` +
|
|
52
|
+
`${GEMINI_AVATAR_VIDEO_BITRATE_BPS_DEFAULT}. Set a number such as 2000000; 0 leaves the field out.`);
|
|
53
|
+
}
|
|
54
|
+
/** The process's environment, or none on a runtime without `process`. */
|
|
55
|
+
function processEnvironment() {
|
|
56
|
+
return typeof process !== 'undefined' && process.env ? process.env : {};
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=geminiAvatarVideoBitrate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geminiAvatarVideoBitrate.js","sourceRoot":"","sources":["../src/geminiAvatarVideoBitrate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,oHAAoH;AACpH,MAAM,CAAC,MAAM,+BAA+B,GAAG,oCAAoC,CAAC;AAEpF,wFAAwF;AACxF,MAAM,CAAC,MAAM,uCAAuC,GAAG,SAAS,CAAC;AAEjE,oEAAoE;AACpE,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAE5B,4EAA4E;AAC5E,MAAM,cAAc,GAAG,IAAI,GAAG,EAAU,CAAC;AAEzC;;;;;;;;;GASG;AACH,MAAM,UAAU,kCAAkC,CAAC,MAAoD,kBAAkB,EAAE;IACvH,MAAM,GAAG,GAAG,GAAG,CAAC,+BAA+B,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAC/D,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACnB,OAAO,uCAAuC,CAAC;IACnD,CAAC;IACD,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;IAC3D,IAAI,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9B,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;IACtC,CAAC;IACD,cAAc,CAAC,GAAG,CAAC,CAAC;IACpB,OAAO,uCAAuC,CAAC;AACnD,CAAC;AAED,gGAAgG;AAChG,SAAS,cAAc,CAAC,GAAW;IAC/B,IAAI,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1B,OAAO;IACX,CAAC;IACD,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACxB,MAAM,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC,eAAe,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAC;IAC3E,OAAO,CAAC,IAAI,CACR,oBAAoB,+BAA+B,KAAK,KAAK,sEAAsE;QAC/H,GAAG,uCAAuC,yDAAyD,CAC1G,CAAC;AACN,CAAC;AAED,yEAAyE;AACzE,SAAS,kBAAkB;IACvB,OAAO,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;AAC5E,CAAC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The avatar half of a server-side (bridged) Gemini Live session whose host publishes the avatar into a
|
|
3
|
+
* meeting room: where each model part goes, what each turn boundary does, and how many seconds of avatar video the
|
|
4
|
+
* session generated.
|
|
5
|
+
*
|
|
6
|
+
* - **Parts.** A part that opens with an MP4 box (`ftyp`, `moov`, `moof`, `styp`) is a piece of the avatar's fragmented
|
|
7
|
+
* MP4 whatever MIME type it names, and so is a `video/*` part. Each goes to the host as a `RealtimeVideoFrame` (Core's
|
|
8
|
+
* `Fmp4PieceToVideoFrame`: init or fragment, with its time and key-frame flag) typed `video/mp4`, keeping a `video/mp4`
|
|
9
|
+
* type's codecs, which is what the room's bridge publishes. A `video/*` part that is neither labelled `video/mp4` nor
|
|
10
|
+
* opens with an MP4 box is dropped and reported once per type. A part with no MIME type that is not MP4 is PCM. A PCM
|
|
11
|
+
* part plays as the voice only while the turn has no video yet: the MP4's audio track carries the voice, so later PCM
|
|
12
|
+
* in the turn would play it twice and is dropped (reported once). Any other part is dropped and reported once per
|
|
13
|
+
* type: unknown data never plays.
|
|
14
|
+
* - **Turns.** From `interrupted` until that turn's `turnComplete`, media parts are dropped (Google sends
|
|
15
|
+
* `interrupted` before `turn_complete`; anything in between is stale after the barge-in).
|
|
16
|
+
* - **Answer or idle.** Vertex AI streams the avatar's video between answers too. The model's answer is under way from
|
|
17
|
+
* its first spoken words (the session reports its output transcription with
|
|
18
|
+
* {@link GeminiBridgedAvatarOutput.AnswerStarted}) or a PCM voice part that plays, until its `generationComplete`, the
|
|
19
|
+
* turn's `turnComplete`, a barge-in, a tool call, a resume or the session's close. Before a part of the answer goes to
|
|
20
|
+
* the host, {@link GeminiBridgedAvatarSinks.OnAnswer} says the model is answering, so the session holds its sends; the
|
|
21
|
+
* video outside an answer goes to the host as well (the avatar keeps its face), marked `Idle`, so a room's floor gate
|
|
22
|
+
* doesn't count it as the agent speaking, whatever its audio track holds. An answer's first pieces can come before its
|
|
23
|
+
* first transcribed words; they are marked `Idle` too.
|
|
24
|
+
* - **Usage.** The seconds of avatar video generated in a turn (its video samples' durations, read from the fragments)
|
|
25
|
+
* are reported as deltas at the turn's end: `generationComplete`, `interrupted`, `turnComplete`, a resume, or the
|
|
26
|
+
* session's close. Video after `generationComplete` is forwarded (idle frames, if Google sends any) but not counted;
|
|
27
|
+
* an interrupted turn counts what arrived before the interruption. The count does not follow the answer above: all
|
|
28
|
+
* video from the session's start, a `turnComplete` or a resume until the next `generationComplete` counts, idle or
|
|
29
|
+
* not, while how Google bills avatar video is open (#5312).
|
|
30
|
+
*
|
|
31
|
+
* @module @memberjunction/ai-gemini
|
|
32
|
+
* @author MemberJunction.com
|
|
33
|
+
*/
|
|
34
|
+
import { type RealtimeVideoFrame } from '@memberjunction/ai';
|
|
35
|
+
/** Where a bridged avatar session's media and usage go. */
|
|
36
|
+
export interface GeminiBridgedAvatarSinks {
|
|
37
|
+
/** A piece of the avatar's fragmented MP4 as a frame, in the order the model sent it; marked `Idle` outside an answer. */
|
|
38
|
+
OnVideoFrame(frame: RealtimeVideoFrame): void;
|
|
39
|
+
/** PCM voice: a turn's audio before any of its video arrived. */
|
|
40
|
+
OnPcm(pcm: ArrayBuffer): void;
|
|
41
|
+
/** Seconds of avatar video generated since the last report (a delta, never a total). */
|
|
42
|
+
OnVideoSeconds(seconds: number): void;
|
|
43
|
+
/**
|
|
44
|
+
* The model is answering: called before each part of its answer goes to the host (its avatar's video while the answer
|
|
45
|
+
* is under way, or voice that plays). Never called for the video the avatar streams between answers.
|
|
46
|
+
*/
|
|
47
|
+
OnAnswer(): void;
|
|
48
|
+
/** One line about a part that was dropped; called once per kind of drop. */
|
|
49
|
+
Report(message: string): void;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Routes a granted bridged avatar session's model parts to the host (avatar pieces) and the session's audio output
|
|
53
|
+
* (PCM before the turn's first video), says which of them are the model's answer, applies each turn boundary, and reports
|
|
54
|
+
* the avatar video seconds generated. The Gemini session creates one when the driver granted an avatar to a host that
|
|
55
|
+
* publishes it into a room.
|
|
56
|
+
*/
|
|
57
|
+
export declare class GeminiBridgedAvatarOutput {
|
|
58
|
+
private readonly sinks;
|
|
59
|
+
private readonly reported;
|
|
60
|
+
private turn;
|
|
61
|
+
/** The stream's latest readable init segment: its tracks and timescales let the fragments' durations be read. */
|
|
62
|
+
private init;
|
|
63
|
+
/** Avatar video seconds counted and not yet reported. */
|
|
64
|
+
private pendingVideoSeconds;
|
|
65
|
+
/** Whether the model's answer is under way (see the module's "Answer or idle"): video outside it is idle. */
|
|
66
|
+
private answering;
|
|
67
|
+
/** @param sinks Where the media, the voice, the usage and the drop reports go. */
|
|
68
|
+
constructor(sinks: GeminiBridgedAvatarSinks);
|
|
69
|
+
/**
|
|
70
|
+
* Plays one model part, or drops it.
|
|
71
|
+
*
|
|
72
|
+
* @param mimeType The part's `inlineData.mimeType`, when it names one.
|
|
73
|
+
* @param data The part's bytes.
|
|
74
|
+
*/
|
|
75
|
+
Accept(mimeType: string | undefined, data: ArrayBuffer): void;
|
|
76
|
+
/**
|
|
77
|
+
* The model's answer is under way: its output transcription has words. The video that follows is the answer's until
|
|
78
|
+
* its generation completes, the turn completes, a barge-in stops it, or the model calls a tool.
|
|
79
|
+
*/
|
|
80
|
+
AnswerStarted(): void;
|
|
81
|
+
/** The model called a tool: its answer stops there, and the video until it speaks again is idle. */
|
|
82
|
+
ToolCalled(): void;
|
|
83
|
+
/**
|
|
84
|
+
* `generationComplete`: the turn's media is all in, and the answer is over. Its avatar seconds are reported; later
|
|
85
|
+
* video is idle and not counted.
|
|
86
|
+
*/
|
|
87
|
+
GenerationComplete(): void;
|
|
88
|
+
/** `turnComplete`: reports what is still uncounted, ends the answer and a barge-in's drop window, and starts a new turn. */
|
|
89
|
+
TurnComplete(): void;
|
|
90
|
+
/**
|
|
91
|
+
* `interrupted`: the turn counts what arrived and its answer ends; its late parts are dropped (and not counted) until
|
|
92
|
+
* its `turnComplete`.
|
|
93
|
+
*/
|
|
94
|
+
Interrupted(): void;
|
|
95
|
+
/** The session resumed on a new connection, where a turn the drop cut off never completes: the answer ends, a new turn starts. */
|
|
96
|
+
Resumed(): void;
|
|
97
|
+
/** The session is closing: what was generated and not yet reported is reported now, and no answer is under way. */
|
|
98
|
+
Close(): void;
|
|
99
|
+
/**
|
|
100
|
+
* How a part plays. Its bytes decide first: a part that opens with an MP4 box is the avatar's whatever type it names,
|
|
101
|
+
* since Google does not document the type of avatar parts. Then its type: none means PCM; a `video/*` type is the
|
|
102
|
+
* avatar's (a `video/mp4` piece may start inside a box; any other video type that isn't MP4 is then dropped); a PCM
|
|
103
|
+
* type is the voice; anything else never plays.
|
|
104
|
+
*/
|
|
105
|
+
private static kindOf;
|
|
106
|
+
/**
|
|
107
|
+
* Makes the piece a frame, counts its video seconds (before the host may take the buffer), then hands it on: saying
|
|
108
|
+
* first that the model is answering when the piece is the answer's, or marking it `Idle` when it isn't. The frame is
|
|
109
|
+
* typed `video/mp4`, keeping the part's own type when it names `video/mp4` with its codecs: the room's bridge
|
|
110
|
+
* publishes a piece as the avatar only when its type is `video/mp4`, and every piece of the stream is. A piece that
|
|
111
|
+
* isn't MP4 is dropped, reported once per type.
|
|
112
|
+
*/
|
|
113
|
+
private acceptAvatar;
|
|
114
|
+
/** Plays a PCM part as the voice, unless the turn's video carries it. Voice that plays means the answer is under way. */
|
|
115
|
+
private acceptVoice;
|
|
116
|
+
private reportVideoSeconds;
|
|
117
|
+
private reportOnce;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=geminiBridgedAvatar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geminiBridgedAvatar.d.ts","sourceRoot":"","sources":["../src/geminiBridgedAvatar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EAOH,KAAK,kBAAkB,EAC1B,MAAM,oBAAoB,CAAC;AAE5B,2DAA2D;AAC3D,MAAM,WAAW,wBAAwB;IACrC,0HAA0H;IAC1H,YAAY,CAAC,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAC9C,iEAAiE;IACjE,KAAK,CAAC,GAAG,EAAE,WAAW,GAAG,IAAI,CAAC;IAC9B,wFAAwF;IACxF,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACtC;;;OAGG;IACH,QAAQ,IAAI,IAAI,CAAC;IACjB,4EAA4E;IAC5E,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC;AAmBD;;;;;GAKG;AACH,qBAAa,yBAAyB;IAWtB,OAAO,CAAC,QAAQ,CAAC,KAAK;IAVlC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqB;IAC9C,OAAO,CAAC,IAAI,CAAgC;IAC5C,iHAAiH;IACjH,OAAO,CAAC,IAAI,CAAyB;IACrC,yDAAyD;IACzD,OAAO,CAAC,mBAAmB,CAAK;IAChC,6GAA6G;IAC7G,OAAO,CAAC,SAAS,CAAS;IAE1B,kFAAkF;gBACrD,KAAK,EAAE,wBAAwB;IAE5D;;;;;OAKG;IACI,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI;IAcpE;;;OAGG;IACI,aAAa,IAAI,IAAI;IAI5B,oGAAoG;IAC7F,UAAU,IAAI,IAAI;IAIzB;;;OAGG;IACI,kBAAkB,IAAI,IAAI;IAMjC,4HAA4H;IACrH,YAAY,IAAI,IAAI;IAM3B;;;OAGG;IACI,WAAW,IAAI,IAAI;IAM1B,kIAAkI;IAC3H,OAAO,IAAI,IAAI;IAMtB,mHAAmH;IAC5G,KAAK,IAAI,IAAI;IAKpB;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,MAAM;IAcrB;;;;;;OAMG;IACH,OAAO,CAAC,YAAY;IAqBpB,yHAAyH;IACzH,OAAO,CAAC,WAAW;IAUnB,OAAO,CAAC,kBAAkB;IAS1B,OAAO,CAAC,UAAU;CAMrB"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The avatar half of a server-side (bridged) Gemini Live session whose host publishes the avatar into a
|
|
3
|
+
* meeting room: where each model part goes, what each turn boundary does, and how many seconds of avatar video the
|
|
4
|
+
* session generated.
|
|
5
|
+
*
|
|
6
|
+
* - **Parts.** A part that opens with an MP4 box (`ftyp`, `moov`, `moof`, `styp`) is a piece of the avatar's fragmented
|
|
7
|
+
* MP4 whatever MIME type it names, and so is a `video/*` part. Each goes to the host as a `RealtimeVideoFrame` (Core's
|
|
8
|
+
* `Fmp4PieceToVideoFrame`: init or fragment, with its time and key-frame flag) typed `video/mp4`, keeping a `video/mp4`
|
|
9
|
+
* type's codecs, which is what the room's bridge publishes. A `video/*` part that is neither labelled `video/mp4` nor
|
|
10
|
+
* opens with an MP4 box is dropped and reported once per type. A part with no MIME type that is not MP4 is PCM. A PCM
|
|
11
|
+
* part plays as the voice only while the turn has no video yet: the MP4's audio track carries the voice, so later PCM
|
|
12
|
+
* in the turn would play it twice and is dropped (reported once). Any other part is dropped and reported once per
|
|
13
|
+
* type: unknown data never plays.
|
|
14
|
+
* - **Turns.** From `interrupted` until that turn's `turnComplete`, media parts are dropped (Google sends
|
|
15
|
+
* `interrupted` before `turn_complete`; anything in between is stale after the barge-in).
|
|
16
|
+
* - **Answer or idle.** Vertex AI streams the avatar's video between answers too. The model's answer is under way from
|
|
17
|
+
* its first spoken words (the session reports its output transcription with
|
|
18
|
+
* {@link GeminiBridgedAvatarOutput.AnswerStarted}) or a PCM voice part that plays, until its `generationComplete`, the
|
|
19
|
+
* turn's `turnComplete`, a barge-in, a tool call, a resume or the session's close. Before a part of the answer goes to
|
|
20
|
+
* the host, {@link GeminiBridgedAvatarSinks.OnAnswer} says the model is answering, so the session holds its sends; the
|
|
21
|
+
* video outside an answer goes to the host as well (the avatar keeps its face), marked `Idle`, so a room's floor gate
|
|
22
|
+
* doesn't count it as the agent speaking, whatever its audio track holds. An answer's first pieces can come before its
|
|
23
|
+
* first transcribed words; they are marked `Idle` too.
|
|
24
|
+
* - **Usage.** The seconds of avatar video generated in a turn (its video samples' durations, read from the fragments)
|
|
25
|
+
* are reported as deltas at the turn's end: `generationComplete`, `interrupted`, `turnComplete`, a resume, or the
|
|
26
|
+
* session's close. Video after `generationComplete` is forwarded (idle frames, if Google sends any) but not counted;
|
|
27
|
+
* an interrupted turn counts what arrived before the interruption. The count does not follow the answer above: all
|
|
28
|
+
* video from the session's start, a `turnComplete` or a resume until the next `generationComplete` counts, idle or
|
|
29
|
+
* not, while how Google bills avatar video is open (#5312).
|
|
30
|
+
*
|
|
31
|
+
* @module @memberjunction/ai-gemini
|
|
32
|
+
* @author MemberJunction.com
|
|
33
|
+
*/
|
|
34
|
+
import { Fmp4PieceToVideoFrame, Fmp4VideoSeconds, IsPcmAudioMimeType, ReadFmp4Init, SniffFmp4Piece, } from '@memberjunction/ai';
|
|
35
|
+
function newTurn() {
|
|
36
|
+
return { HasVideo: false, GenerationEnded: false, Dropping: false };
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Routes a granted bridged avatar session's model parts to the host (avatar pieces) and the session's audio output
|
|
40
|
+
* (PCM before the turn's first video), says which of them are the model's answer, applies each turn boundary, and reports
|
|
41
|
+
* the avatar video seconds generated. The Gemini session creates one when the driver granted an avatar to a host that
|
|
42
|
+
* publishes it into a room.
|
|
43
|
+
*/
|
|
44
|
+
export class GeminiBridgedAvatarOutput {
|
|
45
|
+
/** @param sinks Where the media, the voice, the usage and the drop reports go. */
|
|
46
|
+
constructor(sinks) {
|
|
47
|
+
this.sinks = sinks;
|
|
48
|
+
this.reported = new Set();
|
|
49
|
+
this.turn = newTurn();
|
|
50
|
+
/** The stream's latest readable init segment: its tracks and timescales let the fragments' durations be read. */
|
|
51
|
+
this.init = null;
|
|
52
|
+
/** Avatar video seconds counted and not yet reported. */
|
|
53
|
+
this.pendingVideoSeconds = 0;
|
|
54
|
+
/** Whether the model's answer is under way (see the module's "Answer or idle"): video outside it is idle. */
|
|
55
|
+
this.answering = false;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Plays one model part, or drops it.
|
|
59
|
+
*
|
|
60
|
+
* @param mimeType The part's `inlineData.mimeType`, when it names one.
|
|
61
|
+
* @param data The part's bytes.
|
|
62
|
+
*/
|
|
63
|
+
Accept(mimeType, data) {
|
|
64
|
+
if (this.turn.Dropping) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const kind = GeminiBridgedAvatarOutput.kindOf(mimeType, data);
|
|
68
|
+
if (kind === 'avatar') {
|
|
69
|
+
this.acceptAvatar(mimeType, data);
|
|
70
|
+
}
|
|
71
|
+
else if (kind === 'voice') {
|
|
72
|
+
this.acceptVoice(data);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
this.reportOnce(`type:${mimeType}`, `[GeminiRealtime] Dropped model output of type ${mimeType}: an avatar session in a meeting plays its MP4 avatar and PCM audio only.`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The model's answer is under way: its output transcription has words. The video that follows is the answer's until
|
|
80
|
+
* its generation completes, the turn completes, a barge-in stops it, or the model calls a tool.
|
|
81
|
+
*/
|
|
82
|
+
AnswerStarted() {
|
|
83
|
+
this.answering = true;
|
|
84
|
+
}
|
|
85
|
+
/** The model called a tool: its answer stops there, and the video until it speaks again is idle. */
|
|
86
|
+
ToolCalled() {
|
|
87
|
+
this.answering = false;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* `generationComplete`: the turn's media is all in, and the answer is over. Its avatar seconds are reported; later
|
|
91
|
+
* video is idle and not counted.
|
|
92
|
+
*/
|
|
93
|
+
GenerationComplete() {
|
|
94
|
+
this.reportVideoSeconds();
|
|
95
|
+
this.turn.GenerationEnded = true;
|
|
96
|
+
this.answering = false;
|
|
97
|
+
}
|
|
98
|
+
/** `turnComplete`: reports what is still uncounted, ends the answer and a barge-in's drop window, and starts a new turn. */
|
|
99
|
+
TurnComplete() {
|
|
100
|
+
this.reportVideoSeconds();
|
|
101
|
+
this.answering = false;
|
|
102
|
+
this.turn = newTurn();
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* `interrupted`: the turn counts what arrived and its answer ends; its late parts are dropped (and not counted) until
|
|
106
|
+
* its `turnComplete`.
|
|
107
|
+
*/
|
|
108
|
+
Interrupted() {
|
|
109
|
+
this.reportVideoSeconds();
|
|
110
|
+
this.answering = false;
|
|
111
|
+
this.turn.Dropping = true;
|
|
112
|
+
}
|
|
113
|
+
/** The session resumed on a new connection, where a turn the drop cut off never completes: the answer ends, a new turn starts. */
|
|
114
|
+
Resumed() {
|
|
115
|
+
this.reportVideoSeconds();
|
|
116
|
+
this.answering = false;
|
|
117
|
+
this.turn = newTurn();
|
|
118
|
+
}
|
|
119
|
+
/** The session is closing: what was generated and not yet reported is reported now, and no answer is under way. */
|
|
120
|
+
Close() {
|
|
121
|
+
this.reportVideoSeconds();
|
|
122
|
+
this.answering = false;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* How a part plays. Its bytes decide first: a part that opens with an MP4 box is the avatar's whatever type it names,
|
|
126
|
+
* since Google does not document the type of avatar parts. Then its type: none means PCM; a `video/*` type is the
|
|
127
|
+
* avatar's (a `video/mp4` piece may start inside a box; any other video type that isn't MP4 is then dropped); a PCM
|
|
128
|
+
* type is the voice; anything else never plays.
|
|
129
|
+
*/
|
|
130
|
+
static kindOf(mimeType, data) {
|
|
131
|
+
if (SniffFmp4Piece(data)) {
|
|
132
|
+
return 'avatar';
|
|
133
|
+
}
|
|
134
|
+
const type = mimeType?.trim() ?? '';
|
|
135
|
+
if (type.length === 0) {
|
|
136
|
+
return 'voice';
|
|
137
|
+
}
|
|
138
|
+
if (/^video\//i.test(type)) {
|
|
139
|
+
return 'avatar';
|
|
140
|
+
}
|
|
141
|
+
return IsPcmAudioMimeType(type) ? 'voice' : 'other';
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Makes the piece a frame, counts its video seconds (before the host may take the buffer), then hands it on: saying
|
|
145
|
+
* first that the model is answering when the piece is the answer's, or marking it `Idle` when it isn't. The frame is
|
|
146
|
+
* typed `video/mp4`, keeping the part's own type when it names `video/mp4` with its codecs: the room's bridge
|
|
147
|
+
* publishes a piece as the avatar only when its type is `video/mp4`, and every piece of the stream is. A piece that
|
|
148
|
+
* isn't MP4 is dropped, reported once per type.
|
|
149
|
+
*/
|
|
150
|
+
acceptAvatar(mimeType, data) {
|
|
151
|
+
const frame = Fmp4PieceToVideoFrame(data, mimeType, this.init);
|
|
152
|
+
if (!frame) {
|
|
153
|
+
const message = `[GeminiRealtime] Dropped model output of type ${mimeType}: it is not fragmented MP4, the only video an avatar plays.`;
|
|
154
|
+
this.reportOnce(`type:${mimeType}`, message);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (frame.Piece === 'init') {
|
|
158
|
+
this.init = ReadFmp4Init(data) ?? this.init;
|
|
159
|
+
}
|
|
160
|
+
else if (!this.turn.GenerationEnded && this.init) {
|
|
161
|
+
this.pendingVideoSeconds += Fmp4VideoSeconds(data, this.init) ?? 0;
|
|
162
|
+
}
|
|
163
|
+
this.turn.HasVideo = true;
|
|
164
|
+
if (!this.answering) {
|
|
165
|
+
this.sinks.OnVideoFrame({ ...frame, Idle: true });
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
this.sinks.OnAnswer();
|
|
169
|
+
this.sinks.OnVideoFrame(frame);
|
|
170
|
+
}
|
|
171
|
+
/** Plays a PCM part as the voice, unless the turn's video carries it. Voice that plays means the answer is under way. */
|
|
172
|
+
acceptVoice(pcm) {
|
|
173
|
+
if (this.turn.HasVideo) {
|
|
174
|
+
this.reportOnce('pcm-with-video', '[GeminiRealtime] Dropped PCM audio in a turn whose avatar video carries the voice.');
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
this.answering = true;
|
|
178
|
+
this.sinks.OnAnswer();
|
|
179
|
+
this.sinks.OnPcm(pcm);
|
|
180
|
+
}
|
|
181
|
+
reportVideoSeconds() {
|
|
182
|
+
if (this.pendingVideoSeconds <= 0) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const seconds = this.pendingVideoSeconds;
|
|
186
|
+
this.pendingVideoSeconds = 0;
|
|
187
|
+
this.sinks.OnVideoSeconds(seconds);
|
|
188
|
+
}
|
|
189
|
+
reportOnce(key, message) {
|
|
190
|
+
if (!this.reported.has(key)) {
|
|
191
|
+
this.reported.add(key);
|
|
192
|
+
this.sinks.Report(message);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
//# sourceMappingURL=geminiBridgedAvatar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geminiBridgedAvatar.js","sourceRoot":"","sources":["../src/geminiBridgedAvatar.ts"],"names":[],"m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C,CAAC;IAED,yHAAyH;IACjH,WAAW,CAAC,GAAgB;QAChC,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACrB,IAAI,CAAC,UAAU,CAAC,gBAAgB,EAAE,oFAAoF,CAAC,CAAC;YACxH,OAAO;QACX,CAAC;QACD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;QACtB,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;IAEO,kBAAkB;QACtB,IAAI,IAAI,CAAC,mBAAmB,IAAI,CAAC,EAAE,CAAC;YAChC,OAAO;QACX,CAAC;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,mBAAmB,CAAC;QACzC,IAAI,CAAC,mBAAmB,GAAG,CAAC,CAAC;QAC7B,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC;IAEO,UAAU,CAAC,GAAW,EAAE,OAAe;QAC3C,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACvB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC/B,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -23,9 +23,49 @@
|
|
|
23
23
|
* @module @memberjunction/ai-gemini
|
|
24
24
|
* @author MemberJunction.com
|
|
25
25
|
*/
|
|
26
|
-
import type
|
|
26
|
+
import { type RealtimeIdleSignal, type RealtimeToolingSettings, type RealtimeTurnCoverage } from '@memberjunction/ai';
|
|
27
27
|
/** Thinking levels the Live API accepts. `'minimal'` is legal on 3.1 but NOT on 3.8 Extended Thinking. */
|
|
28
28
|
export type GeminiThinkingLevel = 'minimal' | 'low' | 'medium' | 'high';
|
|
29
|
+
/**
|
|
30
|
+
* Which Gemini endpoint serves a Live session: the Gemini Developer API (an API key) or Gemini Enterprise (Vertex AI,
|
|
31
|
+
* Google Cloud credentials). The protocol is the same; some outputs and values are not. On the Developer API,
|
|
32
|
+
* `gemini-3.8-live` refuses every avatar field and returns audio for a VIDEO request (probed 2026-10-08); Gemini
|
|
33
|
+
* Enterprise refuses one turn coverage ({@link GEMINI_LIVE_ENDPOINT_PROFILES}).
|
|
34
|
+
*/
|
|
35
|
+
export type GeminiLiveEndpoint = 'developer' | 'enterprise';
|
|
36
|
+
/** What a Live model renders as video output on one endpoint: a live avatar, or nothing. */
|
|
37
|
+
export interface GeminiLiveAvatarFacts {
|
|
38
|
+
/** Whether the model renders a live avatar on this endpoint. */
|
|
39
|
+
SupportsAvatarOutput: boolean;
|
|
40
|
+
/** The avatar stream's media type when it does: fragmented MP4 with its codecs, as Media Source Extensions name it. */
|
|
41
|
+
AvatarOutputEncoding?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Whether the avatar's video stream carries the voice. When it does, separate PCM must not also play, or the voice
|
|
44
|
+
* doubles. From Google's sample stream (an AAC track inside the MP4); a player still follows the stream itself.
|
|
45
|
+
*/
|
|
46
|
+
AvatarAudioMuxed?: boolean;
|
|
47
|
+
}
|
|
48
|
+
/** What an endpoint accepts whatever the model: facts of the endpoint's API, which every profile resolved for it carries. */
|
|
49
|
+
export interface GeminiLiveEndpointProfile {
|
|
50
|
+
/**
|
|
51
|
+
* The turn coverages the endpoint accepts in `realtimeInputConfig.turnCoverage`. A session sends one of these
|
|
52
|
+
* ({@link ResolveGeminiTurnCoverage}); a configured coverage outside the list is sent as `audioActivityOnly`, which
|
|
53
|
+
* every endpoint accepts.
|
|
54
|
+
*/
|
|
55
|
+
AcceptedTurnCoverages: readonly RealtimeTurnCoverage[];
|
|
56
|
+
}
|
|
57
|
+
/** A model profile resolved for one endpoint: the model's facts, what it renders there, and what the endpoint accepts. */
|
|
58
|
+
export interface GeminiLiveResolvedProfile extends GeminiLiveModelProfile, GeminiLiveAvatarFacts, GeminiLiveEndpointProfile {
|
|
59
|
+
/** The endpoint this profile was resolved for. */
|
|
60
|
+
Endpoint: GeminiLiveEndpoint;
|
|
61
|
+
}
|
|
62
|
+
/** Endpoint-specific facts for one model row, matched by that row's exact {@link GeminiLiveModelProfile.MatchPrefix}. */
|
|
63
|
+
export interface GeminiLiveEndpointOverlay extends GeminiLiveAvatarFacts {
|
|
64
|
+
/** The endpoint these facts hold on. */
|
|
65
|
+
Endpoint: GeminiLiveEndpoint;
|
|
66
|
+
/** The model row they belong to: equal to its `MatchPrefix`, so a longer model id never inherits another row's facts. */
|
|
67
|
+
ModelPrefix: string;
|
|
68
|
+
}
|
|
29
69
|
/** What a given Gemini Live model accepts. Every field is a documented fact, not a preference. */
|
|
30
70
|
export interface GeminiLiveModelProfile {
|
|
31
71
|
/** Model id prefix this profile matches (longest match wins). */
|
|
@@ -68,7 +108,11 @@ export interface GeminiLiveModelProfile {
|
|
|
68
108
|
* preference.
|
|
69
109
|
*/
|
|
70
110
|
ProactiveAudioAlwaysOn: boolean;
|
|
71
|
-
/**
|
|
111
|
+
/**
|
|
112
|
+
* The model's OWN turn-coverage default, i.e. what we get if we say nothing, as the Developer API documents it. MJ
|
|
113
|
+
* never relies on it: every session states its coverage, one its endpoint accepts
|
|
114
|
+
* ({@link GeminiLiveEndpointProfile.AcceptedTurnCoverages}).
|
|
115
|
+
*/
|
|
72
116
|
ProviderDefaultTurnCoverage: RealtimeTurnCoverage;
|
|
73
117
|
/** Whether the model supports inbound video input stream. */
|
|
74
118
|
SupportsInboundVideo: boolean;
|
|
@@ -87,7 +131,23 @@ export interface GeminiLiveModelProfile {
|
|
|
87
131
|
* declare it for every video-capable model.
|
|
88
132
|
*/
|
|
89
133
|
MaxInboundVideoRate?: number;
|
|
134
|
+
/**
|
|
135
|
+
* How many concurrent inbound video streams this model accepts when {@link SupportsInboundVideo} is
|
|
136
|
+
* true. Read it through {@link ResolveGeminiMaxInboundVideoStreams}, which returns `0` for a model
|
|
137
|
+
* that does not accept video at all and `1` when a video model declares no limit.
|
|
138
|
+
*
|
|
139
|
+
* Every Live model shipped so far takes ONE stream, so a source arbiter chooses which of several
|
|
140
|
+
* sources the model sees and tells it on each switch. A future model that accepts several says so
|
|
141
|
+
* HERE and the arbiter passes sources through untouched; no consumer hardcodes the number.
|
|
142
|
+
*/
|
|
143
|
+
MaxInboundVideoStreams?: number;
|
|
90
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* The inbound video stream count a profile ACTUALLY allows: `0` when the model accepts no video (whatever
|
|
147
|
+
* the table says, so a stale number on a non-video row cannot enable streams), else its declared maximum
|
|
148
|
+
* or `1`.
|
|
149
|
+
*/
|
|
150
|
+
export declare function ResolveGeminiMaxInboundVideoStreams(profile: GeminiLiveModelProfile): number;
|
|
91
151
|
/**
|
|
92
152
|
* The known Live models. Order is irrelevant — resolution takes the LONGEST matching prefix, so
|
|
93
153
|
* `gemini-3.8-live-extended-thinking` cannot be captured by `gemini-3.8-live`.
|
|
@@ -102,14 +162,42 @@ export declare const GEMINI_LIVE_MODEL_PROFILES: readonly GeminiLiveModelProfile
|
|
|
102
162
|
*/
|
|
103
163
|
export declare const GEMINI_LIVE_FALLBACK_PROFILE: GeminiLiveModelProfile;
|
|
104
164
|
/**
|
|
105
|
-
*
|
|
165
|
+
* What each model renders on each endpoint, beyond its row's facts. A model with no overlay for an endpoint renders no
|
|
166
|
+
* avatar there. Matched by the row's exact `MatchPrefix`, so `gemini-3.8-live-extended-thinking` never inherits
|
|
167
|
+
* `gemini-3.8-live`'s avatar.
|
|
168
|
+
*/
|
|
169
|
+
export declare const GEMINI_LIVE_ENDPOINT_OVERLAYS: readonly GeminiLiveEndpointOverlay[];
|
|
170
|
+
/**
|
|
171
|
+
* What each endpoint accepts whatever the model.
|
|
172
|
+
*
|
|
173
|
+
* Turn coverage: the Developer API takes both of MJ's coverages; its `RealtimeInputConfig.TurnCoverage` enum documents
|
|
174
|
+
* `TURN_INCLUDES_ONLY_ACTIVITY` and `TURN_INCLUDES_AUDIO_ACTIVITY_AND_ALL_VIDEO`. Gemini Enterprise does not take the
|
|
175
|
+
* second: a live Vertex AI session (2026-10-09) closed at setup with 1007 "Invalid value at
|
|
176
|
+
* 'setup.realtime_input_config.turn_coverage'" on both `v1` and `v1beta1`, and opened with `TURN_INCLUDES_ONLY_ACTIVITY`.
|
|
177
|
+
*/
|
|
178
|
+
export declare const GEMINI_LIVE_ENDPOINT_PROFILES: Readonly<Record<GeminiLiveEndpoint, GeminiLiveEndpointProfile>>;
|
|
179
|
+
/**
|
|
180
|
+
* The environment variable that gives a model id this table doesn't know the profile of one it does:
|
|
181
|
+
* `<model id>=<known model id>`, comma-separated (`gemini-live-3.8-preview-1009=gemini-3.8-live`). For when Google names
|
|
182
|
+
* a model differently from the table: the catalog's `APIName` is still what Google is sent; only what the model accepts
|
|
183
|
+
* and renders (an avatar on Gemini Enterprise, for `gemini-3.8-live`) comes from the known model's row. An id matches
|
|
184
|
+
* whole, ignoring case and spaces, and an alias wins over the table. Read on each resolution: a restart applies a change.
|
|
185
|
+
*/
|
|
186
|
+
export declare const GEMINI_LIVE_MODEL_ALIASES_ENV = "MJ_GEMINI_LIVE_MODEL_ALIASES";
|
|
187
|
+
/**
|
|
188
|
+
* Resolves the profile for a model id on an endpoint: the model's row (an alias from
|
|
189
|
+
* {@link GEMINI_LIVE_MODEL_ALIASES_ENV}, else the longest prefix), plus what it renders on that endpoint
|
|
190
|
+
* ({@link GEMINI_LIVE_ENDPOINT_OVERLAYS}) and what the endpoint accepts ({@link GEMINI_LIVE_ENDPOINT_PROFILES}).
|
|
106
191
|
*
|
|
107
192
|
* Case- and whitespace-insensitive because model ids reach us from metadata that humans edit.
|
|
108
193
|
* Never throws and never returns undefined — an unknown model gets
|
|
109
194
|
* {@link GEMINI_LIVE_FALLBACK_PROFILE} so a new model release degrades to "treated conservatively"
|
|
110
195
|
* rather than "cannot connect".
|
|
196
|
+
*
|
|
197
|
+
* @param model The model id.
|
|
198
|
+
* @param endpoint The endpoint serving the session. Default: the Developer API.
|
|
111
199
|
*/
|
|
112
|
-
export declare function ResolveGeminiLiveProfile(model: string | null | undefined):
|
|
200
|
+
export declare function ResolveGeminiLiveProfile(model: string | null | undefined, endpoint?: GeminiLiveEndpoint): GeminiLiveResolvedProfile;
|
|
113
201
|
/**
|
|
114
202
|
* Picks the thinking level to send, or `undefined` for "send no thinkingConfig at all".
|
|
115
203
|
*
|
|
@@ -124,4 +212,23 @@ export declare function ResolveGeminiThinkingLevel(requested: string | null | un
|
|
|
124
212
|
Level?: GeminiThinkingLevel;
|
|
125
213
|
Warning?: string;
|
|
126
214
|
};
|
|
215
|
+
/** The turn coverage a session sends, and the configured one it doesn't send, if any. */
|
|
216
|
+
export interface GeminiTurnCoverageResolution {
|
|
217
|
+
/** The coverage to send. */
|
|
218
|
+
Coverage: RealtimeTurnCoverage;
|
|
219
|
+
/** The configured coverage that is not sent: one the endpoint doesn't accept, or a value that is not a coverage. */
|
|
220
|
+
Refused?: string;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Picks the turn coverage to send on the profile's endpoint.
|
|
224
|
+
*
|
|
225
|
+
* Nothing configured gives audio only: video frames are billed and use context, so the costly coverage is asked for,
|
|
226
|
+
* never inherited. A configured coverage the endpoint accepts is sent. Any other value (`audioActivityAndAllVideo` on
|
|
227
|
+
* Gemini Enterprise, or one that is not a coverage) gives audio only as well and comes back as `Refused`, so the caller
|
|
228
|
+
* can name both in its log line. Never throws: a coverage Google would refuse must not cost the user the session.
|
|
229
|
+
*
|
|
230
|
+
* @param requested The configured coverage (`ModelConfiguration.Realtime.TurnDetection.Coverage`), if any.
|
|
231
|
+
* @param profile A profile resolved for the session's endpoint; its {@link GeminiLiveEndpointProfile.AcceptedTurnCoverages} decide.
|
|
232
|
+
*/
|
|
233
|
+
export declare function ResolveGeminiTurnCoverage(requested: string | null | undefined, profile: GeminiLiveEndpointProfile): GeminiTurnCoverageResolution;
|
|
127
234
|
//# sourceMappingURL=geminiLiveProfiles.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geminiLiveProfiles.d.ts","sourceRoot":"","sources":["../src/geminiLiveProfiles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"geminiLiveProfiles.d.ts","sourceRoot":"","sources":["../src/geminiLiveProfiles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAiC,KAAK,kBAAkB,EAAE,KAAK,uBAAuB,EAAE,KAAK,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAErJ,0GAA0G;AAC1G,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;AAExE;;;;;GAKG;AACH,MAAM,MAAM,kBAAkB,GAAG,WAAW,GAAG,YAAY,CAAC;AAE5D,4FAA4F;AAC5F,MAAM,WAAW,qBAAqB;IAClC,gEAAgE;IAChE,oBAAoB,EAAE,OAAO,CAAC;IAC9B,uHAAuH;IACvH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,6HAA6H;AAC7H,MAAM,WAAW,yBAAyB;IACtC;;;;OAIG;IACH,qBAAqB,EAAE,SAAS,oBAAoB,EAAE,CAAC;CAC1D;AAED,0HAA0H;AAC1H,MAAM,WAAW,yBAA0B,SAAQ,sBAAsB,EAAE,qBAAqB,EAAE,yBAAyB;IACvH,kDAAkD;IAClD,QAAQ,EAAE,kBAAkB,CAAC;CAChC;AAED,yHAAyH;AACzH,MAAM,WAAW,yBAA0B,SAAQ,qBAAqB;IACpE,wCAAwC;IACxC,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,yHAAyH;IACzH,WAAW,EAAE,MAAM,CAAC;CACvB;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