@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
package/readme.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# @memberjunction/ai-gemini
|
|
4
4
|
|
|
5
|
-
MemberJunction AI provider for Google Gemini models. Provides
|
|
5
|
+
MemberJunction AI provider for Google Gemini models. Provides LLM, image generation, embedding and realtime (Gemini Live) capabilities, supporting Gemini 2.5, Gemini 3, and Flash model families with native multimodal support, thinking/reasoning, and streaming.
|
|
6
6
|
|
|
7
7
|
## Architecture
|
|
8
8
|
|
|
@@ -52,6 +52,16 @@ graph TD
|
|
|
52
52
|
- **Cross-Modal Retrieval**: Embed text and media together so a text query can match an image, audio, or video
|
|
53
53
|
- **Text and Batch**: Single and batch text embedding
|
|
54
54
|
|
|
55
|
+
### Realtime (GeminiRealtime)
|
|
56
|
+
- **Gemini Live sessions** on the Gemini Developer API: server-side sessions and browser sessions minted with an ephemeral token
|
|
57
|
+
- **Per-model, per-endpoint profiles**: what each Live model accepts, and what it renders on each endpoint
|
|
58
|
+
- **Live avatars** where the endpoint renders them (Gemini Enterprise, through `@memberjunction/ai-vertex`'s `GeminiEnterpriseRealtime`)
|
|
59
|
+
- **Video in**: camera and screen frames as JPEG at the model's rate
|
|
60
|
+
- **Session resumption** and default context-window compression
|
|
61
|
+
- **The relay pieces** MJAPI's realtime relay uses: the setup writer and the frame policy
|
|
62
|
+
|
|
63
|
+
See [Gemini Live (realtime)](#gemini-live-realtime) below.
|
|
64
|
+
|
|
55
65
|
## Installation
|
|
56
66
|
|
|
57
67
|
```bash
|
|
@@ -154,11 +164,66 @@ The provider maps MJ effort levels to Gemini's thinking system:
|
|
|
154
164
|
| presencePenalty | No | Not supported by Gemini |
|
|
155
165
|
| minP | No | Not supported by Gemini |
|
|
156
166
|
|
|
167
|
+
## Gemini Live (realtime)
|
|
168
|
+
|
|
169
|
+
`GeminiRealtime` (`@RegisterClass(BaseRealtimeModel, 'GeminiRealtime')`, key `AI_VENDOR_API_KEY__GeminiRealtime`) runs Gemini Live on the Gemini Developer API. `GeminiEnterpriseRealtime` in `@memberjunction/ai-vertex` extends it for Gemini Enterprise (Vertex AI) and overrides only the endpoint, the credentials and how the browser connects. The realtime architecture is in [the Real-Time Co-Agents Guide](../../../../guides/REALTIME_CO_AGENTS_GUIDE.md); its §12 covers video-capable providers, with Gemini as the reference.
|
|
170
|
+
|
|
171
|
+
### Sessions
|
|
172
|
+
|
|
173
|
+
- **Server-side** (`StartSession`): the node SDK's `live.connect`, used by bridged meetings and phone calls.
|
|
174
|
+
- **Browser** (`CreateClientSession`): an ephemeral token from the `v1alpha` `auth_tokens` API (open within 10 minutes, usable for 30), locking the mask-safe part of the config (`responseModalities`, `speechConfig`, generation parameters, `sessionResumption`) with `liveConnectConstraints`. The system prompt and tools can't be locked in the token; they ride the private `SessionConfig` pact, which the `'gemini'` browser driver applies verbatim. The pact also carries the model's facts on its endpoint (idle signal, tooling, inbound video limits) and, for a granted avatar, an `avatar` block.
|
|
175
|
+
|
|
176
|
+
Every session's config comes from `BuildConnectConfig`: AUDIO output, input and output transcription, the system prompt, sliding-window context compression (`DefaultContextWindowCompression`), session resumption (left off a zero-data-retention session), the tools, the neutral `voice` mapped to `speechConfig`, then the open config bag. The model's legality rules, zero data retention and the avatar rule run last, so the bag can't reintroduce what they remove.
|
|
177
|
+
|
|
178
|
+
**Session length.** Without compression, Google ends a session when its context fills: about 15 minutes for audio and about 2 for audio plus video. With compression on (the default) the server drops the oldest turns. Resumption handles a different limit: one connection lasts about 10 minutes (on Vertex AI, `goAway` came about 9 minutes after a connection opened, with 30 s left), so when Google announces the end (`goAway`) or the socket drops, the session moves to a new connection with Google's resumption handle, server-side and in the browser.
|
|
179
|
+
|
|
180
|
+
### Model profiles
|
|
181
|
+
|
|
182
|
+
`src/geminiLiveProfiles.ts` holds what each Live model accepts, as data rather than branches. Metadata (`ModelConfiguration.Realtime`) is the authority; the table is the fallback for a model whose rows are missing or stale.
|
|
183
|
+
|
|
184
|
+
| Model row | Thinking level | Tool scheduling | Idle signal | Video in | Provider default turn coverage |
|
|
185
|
+
|---|---|---|---|---|---|
|
|
186
|
+
| `gemini-3.8-live-extended-thinking` | `low` / `medium` / `high` (default `medium`) | no; blocking is an error | `interactionStatus` | 1 stream, 1 fps | all video |
|
|
187
|
+
| `gemini-3.8-live` | not accepted (thinkingConfig omitted) | yes; blocking allowed | `turnComplete` | 1 stream, 1 fps | all video |
|
|
188
|
+
| `gemini-3.1-flash-live` | `minimal` to `high` | no | `turnComplete` | none | audio activity |
|
|
189
|
+
| any other model | not sent | no | `turnComplete` | none | audio activity |
|
|
190
|
+
|
|
191
|
+
A model id matches the longest prefix. `MJ_GEMINI_LIVE_MODEL_ALIASES` (`<model id>=<known model id>`, comma-separated, read on each resolution) gives a model id the table doesn't know the profile of one it does; the catalog's `APIName` is still what Google is sent.
|
|
192
|
+
|
|
193
|
+
**Per endpoint.** `ResolveGeminiLiveProfile(model, endpoint)` resolves a row for `'developer'` (the default) or `'enterprise'`, adding:
|
|
194
|
+
|
|
195
|
+
- what the model renders there (`GEMINI_LIVE_ENDPOINT_OVERLAYS`): `SupportsAvatarOutput`, `AvatarOutputEncoding`, `AvatarAudioMuxed`. Only `gemini-3.8-live` on Gemini Enterprise renders a live avatar (`video/mp4; codecs="avc1.42c01f, mp4a.40.2"`, voice inside the MP4). An overlay matches one row exactly, so Extended Thinking never inherits it. On the Developer API, `gemini-3.8-live` refuses every avatar field and returns audio for a VIDEO request.
|
|
196
|
+
- what the endpoint accepts whatever the model (`GEMINI_LIVE_ENDPOINT_PROFILES`): `AcceptedTurnCoverages`. The Developer API accepts `audioActivityOnly` and `audioActivityAndAllVideo`; Gemini Enterprise accepts only `audioActivityOnly` (Vertex AI closes the setup on `TURN_INCLUDES_AUDIO_ACTIVITY_AND_ALL_VIDEO`).
|
|
197
|
+
|
|
198
|
+
**Turn coverage** is stated on every session, never inherited: the catalog's `Realtime.TurnDetection.Coverage` when the endpoint accepts it, else `audioActivityOnly` with one log line naming what was asked for and what was sent; `audioActivityOnly` when nothing is configured. The Google rows of Gemini 3.8 Live and Extended Thinking ask for all video; the Vertex AI row of Gemini 3.8 Live asks for `audioActivityOnly`.
|
|
199
|
+
|
|
200
|
+
### Live avatars
|
|
201
|
+
|
|
202
|
+
`BuildConnectConfig` applies the session's avatar request (`RealtimeSessionParams.Avatar`) last:
|
|
203
|
+
|
|
204
|
+
- **Granted** where the profile renders avatars: the VIDEO response modality and `avatarConfig.avatarName`, with `videoBitrateBps` from `MJ_GEMINI_AVATAR_VIDEO_BITRATE_BPS` (2,000,000 when unset; `0` leaves the field out and lets Google choose; anything else logs once and uses the default). The variable is read each time a config is built, so a restart applies it to browser mints, the relay's setup and server-side sessions.
|
|
205
|
+
- **Refused** anywhere else, with one log line and an audio-only session: `endpoint` (the model renders none here), `custom-disabled`, `unknown-avatar`, and on a server-side session whose host doesn't publish video into a room (`Delivery` other than `'room'`), `bridged`. A VIDEO modality or `avatarConfig` from the config bag is removed: an avatar comes only from the avatar request.
|
|
206
|
+
- The mint returns the decision as `ClientRealtimeSessionConfig.AvatarStatus`; a server-side session reports it as `IRealtimeSession.AvatarStatus`.
|
|
207
|
+
|
|
208
|
+
**A server-side avatar** (a meeting bot that publishes it, `Delivery: 'room'`) sends the model's MP4 pieces to the host as `RealtimeVideoFrame`s through `OnVideoFrame` (`src/geminiBridgedAvatar.ts`). A part that opens with an MP4 box is a piece of the avatar whatever MIME type it names; a `video/*` part that isn't MP4 is dropped and reported once; PCM plays as the voice only while the turn has no video yet (the MP4 carries the voice); any other part is dropped and reported once. From `interrupted` until that turn's `turnComplete`, media parts are dropped. The seconds of video generated in a turn go to `OnUsage` (`OutputTokenDetails.VideoSeconds`) at the turn's end; video after `generationComplete` is forwarded but not counted.
|
|
209
|
+
|
|
210
|
+
### Usage
|
|
211
|
+
|
|
212
|
+
Each `usageMetadata` Google sends becomes one `OnUsage` update: the prompt and response token counts, and their per-modality split (`TEXT`, `AUDIO`, `IMAGE`, `VIDEO` into `TextTokens`, `AudioTokens`, `ImageTokens`, `VideoTokens`). Google reports usage per turn, not as running totals, so consumers add the updates up. A generated avatar's tokens arrive as the response's VIDEO.
|
|
213
|
+
|
|
214
|
+
### The relay pieces
|
|
215
|
+
|
|
216
|
+
A browser session on Gemini Enterprise runs through MJAPI's realtime relay (see `@memberjunction/ai-vertex`). This package provides the Gemini half:
|
|
217
|
+
|
|
218
|
+
- **`BuildGeminiLiveSetup(target, config)`** writes the Live `setup` message from a connect config the way `@google/genai` would inside `live.connect`, for both endpoints (`GeminiLiveSetupTarget`: `Endpoint`, `Model`, `Project`, `Location`, or `UsesApiKey` for an API key on Google's global route). A key the SDK would refuse on an endpoint is left out and named in one log line. A parity test runs the installed SDK's `live.connect` against a local socket in both modes and compares, which catches a mapping an SDK upgrade changes. `BuildGeminiLiveModelPath(target)` writes the model's resource name (`models/<id>`, `projects/<p>/locations/<l>/publishers/google/models/<id>`, or `publishers/google/models/<id>` on the API-key global route).
|
|
219
|
+
- **`GeminiLiveRelayPolicy`** is the relay's frame policy (`IRealtimeRelayPolicy`): every upstream connection opens with the server's setup and the headers `UpstreamHeaders` mints for it; from the browser's own setup it reads only a resumption handle and a request for audio only (a downgrade, never an upgrade); after that it forwards only `realtimeInput` (audio, video, text, activity markers), `clientContent` whose turns are all `user`, and `toolResponse`, with known keys and media types only, and drops everything else under a short label the relay counts. It finds resumption handles in server frames with a byte search before any parse. Widening what passes lets a browser change the agent mid-session, so any widening is a security change.
|
|
220
|
+
|
|
157
221
|
## Class Registration
|
|
158
222
|
|
|
159
223
|
- `GeminiLLM` -- Registered via `@RegisterClass(BaseLLM, 'GeminiLLM')`
|
|
160
224
|
- `GeminiImageGenerator` -- Registered via `@RegisterClass(BaseImageGenerator, 'GeminiImageGenerator')`
|
|
161
225
|
- `GeminiEmbedding` -- Registered via `@RegisterClass(BaseEmbeddings, 'GeminiEmbedding')`
|
|
226
|
+
- `GeminiRealtime` -- Registered via `@RegisterClass(BaseRealtimeModel, 'GeminiRealtime')`
|
|
162
227
|
|
|
163
228
|
## Dependencies
|
|
164
229
|
|