@firebase/ai 2.12.0 → 2.13.0-20260526192810

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.
@@ -363,7 +363,7 @@ export declare abstract class ChatSessionBase<ParamsType extends StartChatParams
363
363
  *
364
364
  * These methods should not be called directly by the user.
365
365
  *
366
- * @beta
366
+ * @public
367
367
  */
368
368
  export declare interface ChromeAdapter {
369
369
  /* Excluded from this release type: mode */
@@ -612,7 +612,7 @@ export declare interface EnhancedGenerateContentResponse extends GenerateContent
612
612
  /**
613
613
  * Indicates whether inference happened on-device or in-cloud.
614
614
  *
615
- * @beta
615
+ * @public
616
616
  */
617
617
  inferenceSource?: InferenceSource;
618
618
  }
@@ -1090,6 +1090,35 @@ export declare class GenerativeModel extends AIModel {
1090
1090
  toolConfig?: ToolConfig;
1091
1091
  systemInstruction?: Content;
1092
1092
  constructor(ai: AI, modelParams: ModelParams, requestOptions?: RequestOptions, chromeAdapter?: ChromeAdapter | undefined);
1093
+ /**
1094
+ * Initializes on-device models.
1095
+ *
1096
+ * @remarks
1097
+ * This may trigger a download on first
1098
+ * use. Wait for this promise to complete before calling inference
1099
+ * methods if you want to ensure the device models are ready before
1100
+ * any calls. Calling inference methods before the device is ready
1101
+ * will result in a cloud fallback if `inferenceMode` is set to
1102
+ * `PREFER_ON_DEVICE`, and an error if set to `ONLY_ON_DEVICE`.
1103
+ *
1104
+ * IMPORTANT: This call must be made on or after a user has interacted
1105
+ * with the page (for example, through a button click or key press).
1106
+ * If it is called without a user interaction, and it requires a download,
1107
+ * this will cause an error.
1108
+ *
1109
+ * See the
1110
+ * {@link https://developer.chrome.com/docs/ai/prompt-api#use_the_prompt_api | Prompt API docs }
1111
+ * for more details on this requirement.
1112
+ *
1113
+ * @param onDownloadProgress A callback called repeatedly as the
1114
+ * download progresses that provides a `progressValue` between 0
1115
+ * and 1 representing how much of the download is complete. This
1116
+ * will be ignored if `monitor` was populated in
1117
+ * {@link LanguageModelCreateOptions}.
1118
+ *
1119
+ * @public
1120
+ */
1121
+ initializeDeviceModel(onDownloadProgress?: (progressValue: number) => void): Promise<void>;
1093
1122
  /**
1094
1123
  * Makes a single non-streaming call to the model
1095
1124
  * and returns an object containing a single {@link GenerateContentResponse}.
@@ -1561,7 +1590,7 @@ export declare type HarmSeverity = (typeof HarmSeverity)[keyof typeof HarmSeveri
1561
1590
 
1562
1591
  /**
1563
1592
  * Configures hybrid inference.
1564
- * @beta
1593
+ * @public
1565
1594
  */
1566
1595
  export declare interface HybridParams {
1567
1596
  /**
@@ -2173,7 +2202,7 @@ export declare interface ImagenSafetySettings {
2173
2202
  * cloud-hosted model. If not available, the SDK will fall back to an
2174
2203
  * on-device model.
2175
2204
  *
2176
- * @beta
2205
+ * @public
2177
2206
  */
2178
2207
  export declare const InferenceMode: {
2179
2208
  readonly PREFER_ON_DEVICE: "prefer_on_device";
@@ -2185,14 +2214,14 @@ export declare const InferenceMode: {
2185
2214
  /**
2186
2215
  * Determines whether inference happens on-device or in-cloud.
2187
2216
  *
2188
- * @beta
2217
+ * @public
2189
2218
  */
2190
2219
  export declare type InferenceMode = (typeof InferenceMode)[keyof typeof InferenceMode];
2191
2220
 
2192
2221
  /**
2193
2222
  * Indicates whether inference happened on-device or in-cloud.
2194
2223
  *
2195
- * @beta
2224
+ * @public
2196
2225
  */
2197
2226
  export declare const InferenceSource: {
2198
2227
  readonly ON_DEVICE: "on_device";
@@ -2202,7 +2231,7 @@ export declare const InferenceSource: {
2202
2231
  /**
2203
2232
  * Indicates whether inference happened on-device or in-cloud.
2204
2233
  *
2205
- * @beta
2234
+ * @public
2206
2235
  */
2207
2236
  export declare type InferenceSource = (typeof InferenceSource)[keyof typeof InferenceSource];
2208
2237
 
@@ -2252,7 +2281,7 @@ export declare type Language = (typeof Language)[keyof typeof Language];
2252
2281
 
2253
2282
  /**
2254
2283
  * Configures the creation of an on-device language model session.
2255
- * @beta
2284
+ * @public
2256
2285
  */
2257
2286
  export declare interface LanguageModelCreateCoreOptions {
2258
2287
  /**
@@ -2263,21 +2292,52 @@ export declare interface LanguageModelCreateCoreOptions {
2263
2292
  * @deprecated
2264
2293
  */
2265
2294
  temperature?: number;
2295
+ /**
2296
+ * Defaults to image input and English text input
2297
+ * if not overriden.
2298
+ */
2266
2299
  expectedInputs?: LanguageModelExpected[];
2300
+ /**
2301
+ * Defaults to English text output if not overriden.
2302
+ */
2303
+ expectedOutputs?: LanguageModelExpected[];
2304
+ /**
2305
+ * The native download monitor provided by the Chrome API.
2306
+ * This provides direct access to the monitor object and is
2307
+ * only needed for advanced cases. For
2308
+ * a simpler download monitoring interface, provide an
2309
+ * `onDownloadProgress` callback
2310
+ * to {@link GenerativeModel.initializeDeviceModel} instead.
2311
+ */
2312
+ monitor?: (monitor: LanguageModelDownloadMonitor) => void;
2267
2313
  }
2268
2314
 
2269
2315
  /**
2270
2316
  * Configures the creation of an on-device language model session.
2271
- * @beta
2317
+ * @public
2272
2318
  */
2273
2319
  export declare interface LanguageModelCreateOptions extends LanguageModelCreateCoreOptions {
2274
2320
  signal?: AbortSignal;
2275
2321
  initialPrompts?: LanguageModelMessage[];
2276
2322
  }
2277
2323
 
2324
+ /**
2325
+ * Interface representing the Chrome Prompt API's native
2326
+ * download monitor object.
2327
+ * @public
2328
+ */
2329
+ export declare interface LanguageModelDownloadMonitor {
2330
+ addEventListener: (eventType: 'downloadprogress', eventListener: (e: {
2331
+ loaded: number;
2332
+ }) => void) => void;
2333
+ removeEventListener: (eventType: 'downloadprogress', eventListener: (e: {
2334
+ loaded: number;
2335
+ }) => void) => void;
2336
+ }
2337
+
2278
2338
  /**
2279
2339
  * Options for the expected inputs for an on-device language model.
2280
- * @beta
2340
+ * @public
2281
2341
  */ export declare interface LanguageModelExpected {
2282
2342
  type: LanguageModelMessageType;
2283
2343
  languages?: string[];
@@ -2285,7 +2345,7 @@ export declare interface LanguageModelCreateOptions extends LanguageModelCreateC
2285
2345
 
2286
2346
  /**
2287
2347
  * An on-device language model message.
2288
- * @beta
2348
+ * @public
2289
2349
  */
2290
2350
  export declare interface LanguageModelMessage {
2291
2351
  role: LanguageModelMessageRole;
@@ -2294,7 +2354,7 @@ export declare interface LanguageModelMessage {
2294
2354
 
2295
2355
  /**
2296
2356
  * An on-device language model content object.
2297
- * @beta
2357
+ * @public
2298
2358
  */
2299
2359
  export declare interface LanguageModelMessageContent {
2300
2360
  type: LanguageModelMessageType;
@@ -2303,25 +2363,25 @@ export declare interface LanguageModelMessageContent {
2303
2363
 
2304
2364
  /**
2305
2365
  * Content formats that can be provided as on-device message content.
2306
- * @beta
2366
+ * @public
2307
2367
  */
2308
2368
  export declare type LanguageModelMessageContentValue = ImageBitmapSource | AudioBuffer | BufferSource | string;
2309
2369
 
2310
2370
  /**
2311
2371
  * Allowable roles for on-device language model usage.
2312
- * @beta
2372
+ * @public
2313
2373
  */
2314
2374
  export declare type LanguageModelMessageRole = 'system' | 'user' | 'assistant';
2315
2375
 
2316
2376
  /**
2317
2377
  * Allowable types for on-device language model messages.
2318
- * @beta
2378
+ * @public
2319
2379
  */
2320
2380
  export declare type LanguageModelMessageType = 'text' | 'image' | 'audio';
2321
2381
 
2322
2382
  /**
2323
2383
  * Options for an on-device language model prompt.
2324
- * @beta
2384
+ * @public
2325
2385
  */
2326
2386
  export declare interface LanguageModelPromptOptions {
2327
2387
  responseConstraint?: object;
@@ -2846,7 +2906,7 @@ export declare interface ObjectSchemaRequest extends SchemaRequest {
2846
2906
  /**
2847
2907
  * Encapsulates configuration for on-device inference.
2848
2908
  *
2849
- * @beta
2909
+ * @public
2850
2910
  */
2851
2911
  export declare interface OnDeviceParams {
2852
2912
  createOptions?: LanguageModelCreateOptions;
package/dist/ai.d.ts CHANGED
@@ -468,7 +468,7 @@ export declare abstract class ChatSessionBase<ParamsType extends StartChatParams
468
468
  *
469
469
  * These methods should not be called directly by the user.
470
470
  *
471
- * @beta
471
+ * @public
472
472
  */
473
473
  export declare interface ChromeAdapter {
474
474
  /**
@@ -726,7 +726,7 @@ export declare interface EnhancedGenerateContentResponse extends GenerateContent
726
726
  /**
727
727
  * Indicates whether inference happened on-device or in-cloud.
728
728
  *
729
- * @beta
729
+ * @public
730
730
  */
731
731
  inferenceSource?: InferenceSource;
732
732
  }
@@ -1216,6 +1216,35 @@ export declare class GenerativeModel extends AIModel {
1216
1216
  toolConfig?: ToolConfig;
1217
1217
  systemInstruction?: Content;
1218
1218
  constructor(ai: AI, modelParams: ModelParams, requestOptions?: RequestOptions, chromeAdapter?: ChromeAdapter | undefined);
1219
+ /**
1220
+ * Initializes on-device models.
1221
+ *
1222
+ * @remarks
1223
+ * This may trigger a download on first
1224
+ * use. Wait for this promise to complete before calling inference
1225
+ * methods if you want to ensure the device models are ready before
1226
+ * any calls. Calling inference methods before the device is ready
1227
+ * will result in a cloud fallback if `inferenceMode` is set to
1228
+ * `PREFER_ON_DEVICE`, and an error if set to `ONLY_ON_DEVICE`.
1229
+ *
1230
+ * IMPORTANT: This call must be made on or after a user has interacted
1231
+ * with the page (for example, through a button click or key press).
1232
+ * If it is called without a user interaction, and it requires a download,
1233
+ * this will cause an error.
1234
+ *
1235
+ * See the
1236
+ * {@link https://developer.chrome.com/docs/ai/prompt-api#use_the_prompt_api | Prompt API docs }
1237
+ * for more details on this requirement.
1238
+ *
1239
+ * @param onDownloadProgress A callback called repeatedly as the
1240
+ * download progresses that provides a `progressValue` between 0
1241
+ * and 1 representing how much of the download is complete. This
1242
+ * will be ignored if `monitor` was populated in
1243
+ * {@link LanguageModelCreateOptions}.
1244
+ *
1245
+ * @public
1246
+ */
1247
+ initializeDeviceModel(onDownloadProgress?: (progressValue: number) => void): Promise<void>;
1219
1248
  /**
1220
1249
  * Makes a single non-streaming call to the model
1221
1250
  * and returns an object containing a single {@link GenerateContentResponse}.
@@ -1728,7 +1757,7 @@ export declare type HarmSeverity = (typeof HarmSeverity)[keyof typeof HarmSeveri
1728
1757
 
1729
1758
  /**
1730
1759
  * Configures hybrid inference.
1731
- * @beta
1760
+ * @public
1732
1761
  */
1733
1762
  export declare interface HybridParams {
1734
1763
  /**
@@ -2359,7 +2388,7 @@ export declare interface ImagenSafetySettings {
2359
2388
  * cloud-hosted model. If not available, the SDK will fall back to an
2360
2389
  * on-device model.
2361
2390
  *
2362
- * @beta
2391
+ * @public
2363
2392
  */
2364
2393
  export declare const InferenceMode: {
2365
2394
  readonly PREFER_ON_DEVICE: "prefer_on_device";
@@ -2371,14 +2400,14 @@ export declare const InferenceMode: {
2371
2400
  /**
2372
2401
  * Determines whether inference happens on-device or in-cloud.
2373
2402
  *
2374
- * @beta
2403
+ * @public
2375
2404
  */
2376
2405
  export declare type InferenceMode = (typeof InferenceMode)[keyof typeof InferenceMode];
2377
2406
 
2378
2407
  /**
2379
2408
  * Indicates whether inference happened on-device or in-cloud.
2380
2409
  *
2381
- * @beta
2410
+ * @public
2382
2411
  */
2383
2412
  export declare const InferenceSource: {
2384
2413
  readonly ON_DEVICE: "on_device";
@@ -2388,7 +2417,7 @@ export declare const InferenceSource: {
2388
2417
  /**
2389
2418
  * Indicates whether inference happened on-device or in-cloud.
2390
2419
  *
2391
- * @beta
2420
+ * @public
2392
2421
  */
2393
2422
  export declare type InferenceSource = (typeof InferenceSource)[keyof typeof InferenceSource];
2394
2423
 
@@ -2441,7 +2470,7 @@ export declare type Language = (typeof Language)[keyof typeof Language];
2441
2470
 
2442
2471
  /**
2443
2472
  * Configures the creation of an on-device language model session.
2444
- * @beta
2473
+ * @public
2445
2474
  */
2446
2475
  export declare interface LanguageModelCreateCoreOptions {
2447
2476
  /**
@@ -2452,21 +2481,52 @@ export declare interface LanguageModelCreateCoreOptions {
2452
2481
  * @deprecated
2453
2482
  */
2454
2483
  temperature?: number;
2484
+ /**
2485
+ * Defaults to image input and English text input
2486
+ * if not overriden.
2487
+ */
2455
2488
  expectedInputs?: LanguageModelExpected[];
2489
+ /**
2490
+ * Defaults to English text output if not overriden.
2491
+ */
2492
+ expectedOutputs?: LanguageModelExpected[];
2493
+ /**
2494
+ * The native download monitor provided by the Chrome API.
2495
+ * This provides direct access to the monitor object and is
2496
+ * only needed for advanced cases. For
2497
+ * a simpler download monitoring interface, provide an
2498
+ * `onDownloadProgress` callback
2499
+ * to {@link GenerativeModel.initializeDeviceModel} instead.
2500
+ */
2501
+ monitor?: (monitor: LanguageModelDownloadMonitor) => void;
2456
2502
  }
2457
2503
 
2458
2504
  /**
2459
2505
  * Configures the creation of an on-device language model session.
2460
- * @beta
2506
+ * @public
2461
2507
  */
2462
2508
  export declare interface LanguageModelCreateOptions extends LanguageModelCreateCoreOptions {
2463
2509
  signal?: AbortSignal;
2464
2510
  initialPrompts?: LanguageModelMessage[];
2465
2511
  }
2466
2512
 
2513
+ /**
2514
+ * Interface representing the Chrome Prompt API's native
2515
+ * download monitor object.
2516
+ * @public
2517
+ */
2518
+ export declare interface LanguageModelDownloadMonitor {
2519
+ addEventListener: (eventType: 'downloadprogress', eventListener: (e: {
2520
+ loaded: number;
2521
+ }) => void) => void;
2522
+ removeEventListener: (eventType: 'downloadprogress', eventListener: (e: {
2523
+ loaded: number;
2524
+ }) => void) => void;
2525
+ }
2526
+
2467
2527
  /**
2468
2528
  * Options for the expected inputs for an on-device language model.
2469
- * @beta
2529
+ * @public
2470
2530
  */ export declare interface LanguageModelExpected {
2471
2531
  type: LanguageModelMessageType;
2472
2532
  languages?: string[];
@@ -2474,7 +2534,7 @@ export declare interface LanguageModelCreateOptions extends LanguageModelCreateC
2474
2534
 
2475
2535
  /**
2476
2536
  * An on-device language model message.
2477
- * @beta
2537
+ * @public
2478
2538
  */
2479
2539
  export declare interface LanguageModelMessage {
2480
2540
  role: LanguageModelMessageRole;
@@ -2483,7 +2543,7 @@ export declare interface LanguageModelMessage {
2483
2543
 
2484
2544
  /**
2485
2545
  * An on-device language model content object.
2486
- * @beta
2546
+ * @public
2487
2547
  */
2488
2548
  export declare interface LanguageModelMessageContent {
2489
2549
  type: LanguageModelMessageType;
@@ -2492,25 +2552,25 @@ export declare interface LanguageModelMessageContent {
2492
2552
 
2493
2553
  /**
2494
2554
  * Content formats that can be provided as on-device message content.
2495
- * @beta
2555
+ * @public
2496
2556
  */
2497
2557
  export declare type LanguageModelMessageContentValue = ImageBitmapSource | AudioBuffer | BufferSource | string;
2498
2558
 
2499
2559
  /**
2500
2560
  * Allowable roles for on-device language model usage.
2501
- * @beta
2561
+ * @public
2502
2562
  */
2503
2563
  export declare type LanguageModelMessageRole = 'system' | 'user' | 'assistant';
2504
2564
 
2505
2565
  /**
2506
2566
  * Allowable types for on-device language model messages.
2507
- * @beta
2567
+ * @public
2508
2568
  */
2509
2569
  export declare type LanguageModelMessageType = 'text' | 'image' | 'audio';
2510
2570
 
2511
2571
  /**
2512
2572
  * Options for an on-device language model prompt.
2513
- * @beta
2573
+ * @public
2514
2574
  */
2515
2575
  export declare interface LanguageModelPromptOptions {
2516
2576
  responseConstraint?: object;
@@ -3076,7 +3136,7 @@ export declare interface ObjectSchemaRequest extends SchemaRequest {
3076
3136
  /**
3077
3137
  * Encapsulates configuration for on-device inference.
3078
3138
  *
3079
- * @beta
3139
+ * @public
3080
3140
  */
3081
3141
  export declare interface OnDeviceParams {
3082
3142
  createOptions?: LanguageModelCreateOptions;