@firebase/ai 2.11.1 → 2.12.0-20260505164105

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.
@@ -480,6 +480,26 @@ export declare interface Content {
480
480
  parts: Part[];
481
481
  }
482
482
 
483
+ /**
484
+ * Enables context window compression to manage the model's context window.
485
+ *
486
+ * @remarks
487
+ * This mechanism prevents the context from exceeding a given length.
488
+ *
489
+ * @beta
490
+ */
491
+ export declare interface ContextWindowCompressionConfig {
492
+ /**
493
+ * The number of tokens (before running a turn) that triggers the context
494
+ * window compression.
495
+ */
496
+ triggerTokens?: number;
497
+ /**
498
+ * The sliding window compression mechanism.
499
+ */
500
+ slidingWindow?: SlidingWindow;
501
+ }
502
+
483
503
  /**
484
504
  * Params for calling {@link GenerativeModel.countTokens}
485
505
  * @public
@@ -713,6 +733,46 @@ export declare const FinishReason: {
713
733
  * The function call generated by the model was invalid.
714
734
  */
715
735
  readonly MALFORMED_FUNCTION_CALL: "MALFORMED_FUNCTION_CALL";
736
+ /**
737
+ * Token generation stopped because generated images contain safety violations.
738
+ */
739
+ readonly IMAGE_SAFETY: "IMAGE_SAFETY";
740
+ /**
741
+ * Image generation stopped because generated images have other prohibited content.
742
+ */
743
+ readonly IMAGE_PROHIBITED_CONTENT: "IMAGE_PROHIBITED_CONTENT";
744
+ /**
745
+ * Image generation stopped because of other miscellaneous issue.
746
+ */
747
+ readonly IMAGE_OTHER: "IMAGE_OTHER";
748
+ /**
749
+ * The model was expected to generate an image, but none was generated.
750
+ */
751
+ readonly NO_IMAGE: "NO_IMAGE";
752
+ /**
753
+ * Image generation stopped due to recitation.
754
+ */
755
+ readonly IMAGE_RECITATION: "IMAGE_RECITATION";
756
+ /**
757
+ * The response candidate content was flagged for using an unsupported language.
758
+ */
759
+ readonly LANGUAGE: "LANGUAGE";
760
+ /**
761
+ * Model generated a tool call but no tools were enabled in the request.
762
+ */
763
+ readonly UNEXPECTED_TOOL_CALL: "UNEXPECTED_TOOL_CALL";
764
+ /**
765
+ * Model called too many tools consecutively, thus the system exited execution.
766
+ */
767
+ readonly TOO_MANY_TOOL_CALLS: "TOO_MANY_TOOL_CALLS";
768
+ /**
769
+ * Request has at least one thought signature missing.
770
+ */
771
+ readonly MISSING_THOUGHT_SIGNATURE: "MISSING_THOUGHT_SIGNATURE";
772
+ /**
773
+ * Finished due to malformed response.
774
+ */
775
+ readonly MALFORMED_RESPONSE: "MALFORMED_RESPONSE";
716
776
  };
717
777
 
718
778
  /**
@@ -998,6 +1058,11 @@ export declare interface GenerationConfig {
998
1058
  * Configuration for "thinking" behavior of compatible Gemini models.
999
1059
  */
1000
1060
  thinkingConfig?: ThinkingConfig;
1061
+ /**
1062
+ * Configuration options for generating images with Gemini models.
1063
+ * @public
1064
+ */
1065
+ imageConfig?: ImageConfig;
1001
1066
  }
1002
1067
 
1003
1068
  /**
@@ -1171,6 +1236,66 @@ export declare class GoogleAIBackend extends Backend {
1171
1236
 
1172
1237
  /* Excluded from this release type: GoogleAIGenerateContentResponse */
1173
1238
 
1239
+ /**
1240
+ * Specifies the Google Maps configuration.
1241
+ *
1242
+ * @public
1243
+ */
1244
+ export declare interface GoogleMaps {
1245
+ enableWidget?: boolean;
1246
+ }
1247
+
1248
+ /**
1249
+ * A grounding chunk from Google Maps.
1250
+ *
1251
+ * Important: If using Grounding with Google Maps, you are required to comply with the
1252
+ * {@link https://cloud.google.com/terms/service-terms | Service Specific Terms} for "Grounding with Google Maps".
1253
+ *
1254
+ * @public
1255
+ */
1256
+ export declare interface GoogleMapsGroundingChunk {
1257
+ /**
1258
+ * The URI of the place.
1259
+ */
1260
+ uri?: string;
1261
+ /**
1262
+ * The title of the place.
1263
+ */
1264
+ title?: string;
1265
+ /**
1266
+ * The text of the place answer.
1267
+ */
1268
+ text?: string;
1269
+ /**
1270
+ * This Place's resource name, in `places/{place_id}` format. This can be used to look up the
1271
+ * place in the Google Maps API.
1272
+ */
1273
+ placeId?: string;
1274
+ }
1275
+
1276
+ /**
1277
+ * A tool that allows a Gemini model to connect to Google Maps to access and incorporate
1278
+ * location-based information into its responses.
1279
+ *
1280
+ * Important: If using Grounding with Google Maps, you are required to comply with the
1281
+ * "Grounding with Google Maps" usage requirements for your chosen API provider: {@link https://ai.google.dev/gemini-api/terms#grounding-with-google-maps | Gemini Developer API}
1282
+ * or Vertex AI Gemini API (see {@link https://cloud.google.com/terms/service-terms | Service Terms}
1283
+ * section within the Service Specific Terms).
1284
+ *
1285
+ * @public
1286
+ */
1287
+ export declare interface GoogleMapsTool {
1288
+ /**
1289
+ * Specifies the Google Maps configuration.
1290
+ *
1291
+ * When using this feature, you are required to comply with the "Grounding with Google Maps"
1292
+ * usage requirements for your chosen API provider: {@link https://ai.google.dev/gemini-api/terms#grounding-with-google-maps | Gemini Developer API}
1293
+ * or Vertex AI Gemini API (see {@link https://cloud.google.com/terms/service-terms | Service Terms}
1294
+ * section within the Service Specific Terms).
1295
+ */
1296
+ googleMaps: GoogleMaps;
1297
+ }
1298
+
1174
1299
  /**
1175
1300
  * Specifies the Google Search configuration.
1176
1301
  *
@@ -1216,18 +1341,28 @@ export declare interface GroundingChunk {
1216
1341
  * Contains details if the grounding chunk is from a web source.
1217
1342
  */
1218
1343
  web?: WebGroundingChunk;
1344
+ /**
1345
+ * Contains details if the grounding chunk is from a Google Maps source.
1346
+ */
1347
+ maps?: GoogleMapsGroundingChunk;
1219
1348
  }
1220
1349
 
1221
1350
  /**
1222
1351
  * Metadata returned when grounding is enabled.
1223
1352
  *
1224
- * Currently, only Grounding with Google Search is supported (see {@link GoogleSearchTool}).
1353
+ * Currently, only Grounding with Google Search and Grounding with Google Maps are supported
1354
+ * (see {@link GoogleSearchTool} and {@link GoogleMapsTool}, respectively).
1225
1355
  *
1226
1356
  * Important: If using Grounding with Google Search, you are required to comply with the
1227
1357
  * "Grounding with Google Search" usage requirements for your chosen API provider: {@link https://ai.google.dev/gemini-api/terms#grounding-with-google-search | Gemini Developer API}
1228
1358
  * or Vertex AI Gemini API (see {@link https://cloud.google.com/terms/service-terms | Service Terms}
1229
1359
  * section within the Service Specific Terms).
1230
1360
  *
1361
+ * Important: If using Grounding with Google Maps, you are required to comply with the
1362
+ * "Grounding with Google Maps" usage requirements for your chosen API provider: {@link https://ai.google.dev/gemini-api/terms#grounding-with-google-maps | Gemini Developer API}
1363
+ * or Vertex AI Gemini API (see {@link https://cloud.google.com/terms/service-terms | Service Terms}
1364
+ * section within the Service Specific Terms).
1365
+ *
1231
1366
  * @public
1232
1367
  */
1233
1368
  export declare interface GroundingMetadata {
@@ -1256,6 +1391,12 @@ export declare interface GroundingMetadata {
1256
1391
  * @deprecated Use {@link GroundingSupport} instead.
1257
1392
  */
1258
1393
  retrievalQueries?: string[];
1394
+ /**
1395
+ * Resource name of the Google Maps widget context token that can be used with the
1396
+ * `PlacesContextElement` widget in order to render contextual data. Only populated in the case
1397
+ * that grounding with Google Maps is enabled.
1398
+ */
1399
+ googleMapsWidgetContextToken?: string;
1259
1400
  }
1260
1401
 
1261
1402
  /**
@@ -1437,6 +1578,65 @@ export declare interface HybridParams {
1437
1578
  inCloudParams?: ModelParams;
1438
1579
  }
1439
1580
 
1581
+ /**
1582
+ * Configuration options for generating images with Gemini models.
1583
+ * @public
1584
+ */
1585
+ export declare interface ImageConfig {
1586
+ /**
1587
+ * The aspect ratio of generated images.
1588
+ */
1589
+ aspectRatio?: ImageConfigAspectRatio;
1590
+ /**
1591
+ * The size of the generated images.
1592
+ */
1593
+ imageSize?: ImageConfigImageSize;
1594
+ }
1595
+
1596
+ /**
1597
+ * Aspect ratios for generated images.
1598
+ * @public
1599
+ */
1600
+ export declare const ImageConfigAspectRatio: {
1601
+ readonly SQUARE_1x1: "1:1";
1602
+ readonly PORTRAIT_9x16: "9:16";
1603
+ readonly LANDSCAPE_16x9: "16:9";
1604
+ readonly PORTRAIT_3x4: "3:4";
1605
+ readonly LANDSCAPE_4x3: "4:3";
1606
+ readonly PORTRAIT_2x3: "2:3";
1607
+ readonly LANDSCAPE_3x2: "3:2";
1608
+ readonly PORTRAIT_4x5: "4:5";
1609
+ readonly LANDSCAPE_5x4: "5:4";
1610
+ readonly PORTRAIT_1x4: "1:4";
1611
+ readonly LANDSCAPE_4x1: "4:1";
1612
+ readonly PORTRAIT_1x8: "1:8";
1613
+ readonly LANDSCAPE_8x1: "8:1";
1614
+ readonly ULTRAWIDE_21x9: "21:9";
1615
+ };
1616
+
1617
+ /**
1618
+ * Aspect ratios for generated images.
1619
+ * @public
1620
+ */
1621
+ export declare type ImageConfigAspectRatio = (typeof ImageConfigAspectRatio)[keyof typeof ImageConfigAspectRatio];
1622
+
1623
+ /**
1624
+ * Sizes for generated images. For example, '1K' is 1024px, '2K' is 2048px, and '4K' is 4096px.
1625
+ * @public
1626
+ */
1627
+ export declare const ImageConfigImageSize: {
1628
+ readonly SIZE_512: "512";
1629
+ readonly SIZE_1K: "1K";
1630
+ readonly SIZE_2K: "2K";
1631
+ readonly SIZE_4K: "4K";
1632
+ };
1633
+
1634
+ /**
1635
+ * Sizes for generated images.
1636
+ * @public
1637
+ */
1638
+ export declare type ImageConfigImageSize = (typeof ImageConfigImageSize)[keyof typeof ImageConfigImageSize];
1639
+
1440
1640
  /**
1441
1641
  * Aspect ratios for Imagen images.
1442
1642
  *
@@ -2127,6 +2327,23 @@ export declare interface LanguageModelPromptOptions {
2127
2327
  responseConstraint?: object;
2128
2328
  }
2129
2329
 
2330
+ /**
2331
+ * An object that represents a latitude/longitude pair.
2332
+ * @public
2333
+ */
2334
+ export declare interface LatLng {
2335
+ /**
2336
+ * The latitude in degrees. It must be in the range `[-90.0, +90.0]`.
2337
+ */
2338
+ latitude?: number;
2339
+ /**
2340
+ * The longitude in degrees. It must be in the range `[-180.0, +180.0]`.
2341
+ */
2342
+ longitude?: number;
2343
+ }
2344
+
2345
+ /* Excluded from this release type: _LiveClientSetup */
2346
+
2130
2347
  /**
2131
2348
  * Configuration parameters used by {@link LiveGenerativeModel} to control live content generation.
2132
2349
  *
@@ -2194,8 +2411,22 @@ export declare interface LiveGenerationConfig {
2194
2411
  * "How are you today?", the model may transcribe that output across three messages, broken up as "How a", "re yo", "u today?".
2195
2412
  */
2196
2413
  outputAudioTranscription?: AudioTranscriptionConfig;
2414
+ /**
2415
+ * The context window compression configuration.
2416
+ *
2417
+ * @beta
2418
+ */
2419
+ contextWindowCompression?: ContextWindowCompressionConfig;
2197
2420
  }
2198
2421
 
2422
+ /**
2423
+ * The Live Generation Config.
2424
+ *
2425
+ * The public API ({@link LiveGenerationConfig}) has `inputAudioTranscription` and `outputAudioTranscription`,
2426
+ * but the server expects these fields to be in the top-level `setup` message. This was a conscious API decision.
2427
+ */
2428
+ declare type _LiveGenerationConfig = Omit<LiveGenerationConfig, 'inputAudioTranscription' | 'outputAudioTranscription'>;
2429
+
2199
2430
  /**
2200
2431
  * Class for Live generative model APIs. The Live API enables low-latency, two-way multimodal
2201
2432
  * interactions with Gemini.
@@ -2219,7 +2450,7 @@ export declare class LiveGenerativeModel extends AIModel {
2219
2450
  *
2220
2451
  * @beta
2221
2452
  */
2222
- connect(): Promise<LiveSession>;
2453
+ connect(sessionResumption?: SessionResumptionConfig): Promise<LiveSession>;
2223
2454
  }
2224
2455
 
2225
2456
  /**
@@ -2244,6 +2475,7 @@ export declare const LiveResponseType: {
2244
2475
  TOOL_CALL: string;
2245
2476
  TOOL_CALL_CANCELLATION: string;
2246
2477
  GOING_AWAY_NOTICE: string;
2478
+ SESSION_RESUMPTION_UPDATE: string;
2247
2479
  };
2248
2480
 
2249
2481
  /**
@@ -2333,8 +2565,9 @@ export declare interface LiveServerToolCallCancellation {
2333
2565
  * @beta
2334
2566
  */
2335
2567
  export declare class LiveSession {
2336
- private webSocketHandler;
2337
- private serverMessages;
2568
+ private _setupMessage;
2569
+ private _apiSettings;
2570
+ private _sessionResumption?;
2338
2571
  /**
2339
2572
  * Indicates whether this Live session is closed.
2340
2573
  *
@@ -2347,7 +2580,33 @@ export declare class LiveSession {
2347
2580
  * @beta
2348
2581
  */
2349
2582
  inConversation: boolean;
2583
+ /**
2584
+ * Allows external code to await the opening of the WebSocket connection.
2585
+ */
2586
+ connectionPromise: Promise<void>;
2587
+ /**
2588
+ * Generator yielding WebSocket messages from the server.
2589
+ */
2590
+ private _serverMessages;
2591
+ /**
2592
+ * WebSocket handler. Injectable for testing.
2593
+ */
2594
+ private _webSocketHandler;
2350
2595
  /* Excluded from this release type: __constructor */
2596
+ /* Excluded from this release type: _connectSession */
2597
+ /**
2598
+ * Resumes an existing live session with the server.
2599
+ *
2600
+ * This closes the current WebSocket connection and establishes a new one using
2601
+ * the same configuration (URI, headers, model, system instruction, tools, etc.)
2602
+ * as the original session.
2603
+ *
2604
+ * @param sessionResumption - The configuration for session resumption, such as the handle to the previous session state to restore.
2605
+ * @throws If the session resumption configuration is unsupported.
2606
+ *
2607
+ * @beta
2608
+ */
2609
+ resumeSession(sessionResumption?: SessionResumptionConfig): Promise<void>;
2351
2610
  /**
2352
2611
  * Sends content to the server.
2353
2612
  *
@@ -2427,7 +2686,7 @@ export declare class LiveSession {
2427
2686
  *
2428
2687
  * @beta
2429
2688
  */
2430
- receive(): AsyncGenerator<LiveServerContent | LiveServerToolCall | LiveServerToolCallCancellation | LiveServerGoingAwayNotice>;
2689
+ receive(): AsyncGenerator<LiveServerContent | LiveServerToolCall | LiveServerToolCallCancellation | LiveServerGoingAwayNotice | LiveSessionResumptionUpdate>;
2431
2690
  /**
2432
2691
  * Closes this session.
2433
2692
  * All methods on this session will throw an error once this resolves.
@@ -2459,6 +2718,30 @@ export declare class LiveSession {
2459
2718
  sendMediaStream(mediaChunkStream: ReadableStream<GenerativeContentBlob>): Promise<void>;
2460
2719
  }
2461
2720
 
2721
+ /**
2722
+ * An update of the session resumption state.
2723
+ *
2724
+ * This message is only sent if {@link SessionResumptionConfig} was set in the
2725
+ * session setup.
2726
+ *
2727
+ * @beta
2728
+ */
2729
+ export declare interface LiveSessionResumptionUpdate {
2730
+ type: 'sessionResumptionUpdate';
2731
+ /**
2732
+ * The new handle that represents the state that can be resumed. Empty if `resumable` is false.
2733
+ */
2734
+ newHandle?: string;
2735
+ /**
2736
+ * Indicates if the session can be resumed at this point.
2737
+ */
2738
+ resumable?: boolean;
2739
+ /**
2740
+ * The index of the last client message that is included in the state represented by this update.
2741
+ */
2742
+ lastConsumedClientMessageIndex?: number;
2743
+ }
2744
+
2462
2745
  /**
2463
2746
  * Content part modality.
2464
2747
  * @public
@@ -2689,6 +2972,21 @@ export declare const ResponseModality: {
2689
2972
  */
2690
2973
  export declare type ResponseModality = (typeof ResponseModality)[keyof typeof ResponseModality];
2691
2974
 
2975
+ /**
2976
+ * Configuration options for data retrieval tools.
2977
+ * @public
2978
+ */
2979
+ export declare interface RetrievalConfig {
2980
+ /**
2981
+ * The location of the user.
2982
+ */
2983
+ latLng?: LatLng;
2984
+ /**
2985
+ * The language code of the user.
2986
+ */
2987
+ languageCode?: string;
2988
+ }
2989
+
2692
2990
  /**
2693
2991
  * @public
2694
2992
  */
@@ -2983,7 +3281,7 @@ export declare interface Segment {
2983
3281
  /**
2984
3282
  * The zero-based start index of the segment within the specified `Part`,
2985
3283
  * measured in UTF-8 bytes. This offset is inclusive, starting from 0 at the
2986
- * beginning of the part's content (e.g., `Part.text`).
3284
+ * beginning of the part's content (for example, `Part.text`).
2987
3285
  */
2988
3286
  startIndex: number;
2989
3287
  /**
@@ -2998,6 +3296,24 @@ export declare interface Segment {
2998
3296
  text: string;
2999
3297
  }
3000
3298
 
3299
+ /**
3300
+ * Configuration for the session resumption mechanism.
3301
+ *
3302
+ * @remarks
3303
+ * When included in the session setup, the server will send
3304
+ * {@link LiveSessionResumptionUpdate} messages in the response stream.
3305
+ *
3306
+ * @beta
3307
+ */
3308
+ export declare interface SessionResumptionConfig {
3309
+ /**
3310
+ * The session resumption handle of the previous session to restore.
3311
+ *
3312
+ * If not present, a new session will be started.
3313
+ */
3314
+ handle?: string;
3315
+ }
3316
+
3001
3317
  /**
3002
3318
  * Options that can be provided per-request.
3003
3319
  * Extends the base {@link RequestOptions} (like `timeout` and `baseUrl`)
@@ -3039,6 +3355,25 @@ export declare interface SingleRequestOptions extends RequestOptions {
3039
3355
  signal?: AbortSignal;
3040
3356
  }
3041
3357
 
3358
+ /**
3359
+ * Configures the sliding window context compression mechanism.
3360
+ *
3361
+ * @remarks
3362
+ * The sliding window discards content at the beginning of the
3363
+ * context window. The resulting context will always begin at
3364
+ * the start of a `user` role turn. System instructions
3365
+ * will always remain at the start of the result.
3366
+ *
3367
+ * @beta
3368
+ */
3369
+ export declare interface SlidingWindow {
3370
+ /**
3371
+ * The session reduction target, for example, how many tokens the model
3372
+ * should keep.
3373
+ */
3374
+ targetTokens?: number;
3375
+ }
3376
+
3042
3377
  /**
3043
3378
  * Configures speech synthesis.
3044
3379
  *
@@ -3254,10 +3589,12 @@ export declare class TemplateGenerativeModel {
3254
3589
  * @param templateId - The ID of the server-side template to execute.
3255
3590
  * @param templateVariables - A key-value map of variables to populate the
3256
3591
  * template with.
3592
+ * @param singleRequestOptions - Optional. Options to use for this request.
3593
+ * @param templateToolConfig - Optional. Configuration for tools to use with this request.
3257
3594
  *
3258
3595
  * @beta
3259
3596
  */
3260
- generateContent(templateId: string, templateVariables: Record<string, unknown>, singleRequestOptions?: SingleRequestOptions): Promise<GenerateContentResult>;
3597
+ generateContent(templateId: string, templateVariables: Record<string, unknown>, singleRequestOptions?: SingleRequestOptions, templateToolConfig?: TemplateToolConfig): Promise<GenerateContentResult>;
3261
3598
  /**
3262
3599
  * Makes a single streaming call to the model and returns an object
3263
3600
  * containing an iterable stream that iterates over all chunks in the
@@ -3267,10 +3604,12 @@ export declare class TemplateGenerativeModel {
3267
3604
  * @param templateId - The ID of the server-side template to execute.
3268
3605
  * @param templateVariables - A key-value map of variables to populate the
3269
3606
  * template with.
3607
+ * @param singleRequestOptions - Optional.Options to use for this request.
3608
+ * @param templateToolConfig - Optional. Configuration for tools to use with this request.
3270
3609
  *
3271
3610
  * @beta
3272
3611
  */
3273
- generateContentStream(templateId: string, templateVariables: Record<string, unknown>, singleRequestOptions?: SingleRequestOptions): Promise<GenerateContentStreamResult>;
3612
+ generateContentStream(templateId: string, templateVariables: Record<string, unknown>, singleRequestOptions?: SingleRequestOptions, templateToolConfig?: TemplateToolConfig): Promise<GenerateContentStreamResult>;
3274
3613
  /**
3275
3614
  * Starts a {@link TemplateChatSession} that will use this template to
3276
3615
  * respond to messages.
@@ -3326,6 +3665,15 @@ export declare class TemplateImagenModel {
3326
3665
  */
3327
3666
  export declare type TemplateTool = TemplateFunctionDeclarationsTool;
3328
3667
 
3668
+ /**
3669
+ * Tool configuration for `TemplateGenerativeModel`s.
3670
+ * This config is shared for all tools provided in the server prompt template request.
3671
+ * @public
3672
+ */
3673
+ export declare interface TemplateToolConfig {
3674
+ retrievalConfig?: RetrievalConfig;
3675
+ }
3676
+
3329
3677
  /**
3330
3678
  * Content part interface if the part represents a text string.
3331
3679
  * @public
@@ -3427,7 +3775,7 @@ export declare type ThinkingLevel = (typeof ThinkingLevel)[keyof typeof Thinking
3427
3775
  * Defines a tool that model can call to access external knowledge.
3428
3776
  * @public
3429
3777
  */
3430
- export declare type Tool = FunctionDeclarationsTool | GoogleSearchTool | CodeExecutionTool | URLContextTool;
3778
+ export declare type Tool = FunctionDeclarationsTool | GoogleMapsTool | GoogleSearchTool | CodeExecutionTool | URLContextTool;
3431
3779
 
3432
3780
  /**
3433
3781
  * Tool config. This config is shared for all tools provided in the request.
@@ -3435,6 +3783,7 @@ export declare type Tool = FunctionDeclarationsTool | GoogleSearchTool | CodeExe
3435
3783
  */
3436
3784
  export declare interface ToolConfig {
3437
3785
  functionCallingConfig?: FunctionCallingConfig;
3786
+ retrievalConfig?: RetrievalConfig;
3438
3787
  }
3439
3788
 
3440
3789
  /**