@firebase/ai 2.1.0-canary.44d8d742f → 2.1.0-canary.84b8bed35

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.
@@ -4,10 +4,17 @@
4
4
  * @packageDocumentation
5
5
  */
6
6
 
7
+ import { AppCheckInternalComponentName } from '@firebase/app-check-interop-types';
7
8
  import { AppCheckTokenResult } from '@firebase/app-check-interop-types';
9
+ import { ComponentContainer } from '@firebase/component';
8
10
  import { FirebaseApp } from '@firebase/app';
11
+ import { FirebaseAppCheckInternal } from '@firebase/app-check-interop-types';
12
+ import { FirebaseAuthInternal } from '@firebase/auth-interop-types';
13
+ import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
9
14
  import { FirebaseAuthTokenData } from '@firebase/auth-interop-types';
10
15
  import { FirebaseError } from '@firebase/util';
16
+ import { InstanceFactoryOptions } from '@firebase/component';
17
+ import { Provider } from '@firebase/component';
11
18
 
12
19
  /**
13
20
  * An instance of the Firebase AI SDK.
@@ -27,6 +34,10 @@ export declare interface AI {
27
34
  * Vertex AI Gemini API (using {@link VertexAIBackend}).
28
35
  */
29
36
  backend: Backend;
37
+ /**
38
+ * Options applied to this {@link AI} instance.
39
+ */
40
+ options?: AIOptions;
30
41
  /**
31
42
  * @deprecated use `AI.backend.location` instead.
32
43
  *
@@ -125,8 +136,26 @@ export declare abstract class AIModel {
125
136
  export declare interface AIOptions {
126
137
  /**
127
138
  * The backend configuration to use for the AI service instance.
139
+ * Defaults to the Gemini Developer API backend ({@link GoogleAIBackend}).
140
+ */
141
+ backend?: Backend;
142
+ /**
143
+ * Whether to use App Check limited use tokens. Defaults to false.
128
144
  */
145
+ useLimitedUseAppCheckTokens?: boolean;
146
+ }
147
+
148
+ declare class AIService implements AI, _FirebaseService {
149
+ app: FirebaseApp;
129
150
  backend: Backend;
151
+ auth: FirebaseAuthInternal | null;
152
+ appCheck: FirebaseAppCheckInternal | null;
153
+ _options?: Omit<AIOptions, 'backend'>;
154
+ location: string;
155
+ constructor(app: FirebaseApp, backend: Backend, authProvider?: Provider<FirebaseAuthInternalName>, appCheckProvider?: Provider<AppCheckInternalComponentName>);
156
+ _delete(): Promise<void>;
157
+ set options(optionsToSet: AIOptions);
158
+ get options(): AIOptions | undefined;
130
159
  }
131
160
 
132
161
  /**
@@ -320,16 +349,18 @@ export declare interface ChromeAdapter {
320
349
  /**
321
350
  * Generates content using on-device inference.
322
351
  *
323
- * <p>This is comparable to {@link GenerativeModel.generateContent} for generating
324
- * content using in-cloud inference.</p>
352
+ * @remarks
353
+ * This is comparable to {@link GenerativeModel.generateContent} for generating
354
+ * content using in-cloud inference.
325
355
  * @param request - a standard Firebase AI {@link GenerateContentRequest}
326
356
  */
327
357
  generateContent(request: GenerateContentRequest): Promise<Response>;
328
358
  /**
329
359
  * Generates a content stream using on-device inference.
330
360
  *
331
- * <p>This is comparable to {@link GenerativeModel.generateContentStream} for generating
332
- * a content stream using in-cloud inference.</p>
361
+ * @remarks
362
+ * This is comparable to {@link GenerativeModel.generateContentStream} for generating
363
+ * a content stream using in-cloud inference.
333
364
  * @param request - a standard Firebase AI {@link GenerateContentRequest}
334
365
  */
335
366
  generateContentStream(request: GenerateContentRequest): Promise<Response>;
@@ -457,15 +488,34 @@ export declare interface EnhancedGenerateContentResponse extends GenerateContent
457
488
  */
458
489
  text: () => string;
459
490
  /**
460
- * Aggregates and returns all {@link InlineDataPart}s from the {@link GenerateContentResponse}'s
461
- * first candidate.
462
- *
463
- * @returns An array of {@link InlineDataPart}s containing data from the response, if available.
491
+ * Aggregates and returns every {@link InlineDataPart} from the first candidate of
492
+ * {@link GenerateContentResponse}.
464
493
  *
465
494
  * @throws If the prompt or candidate was blocked.
466
495
  */
467
496
  inlineDataParts: () => InlineDataPart[] | undefined;
497
+ /**
498
+ * Aggregates and returns every {@link FunctionCall} from the first candidate of
499
+ * {@link GenerateContentResponse}.
500
+ *
501
+ * @throws If the prompt or candidate was blocked.
502
+ */
468
503
  functionCalls: () => FunctionCall[] | undefined;
504
+ /**
505
+ * Aggregates and returns every {@link TextPart} with their `thought` property set
506
+ * to `true` from the first candidate of {@link GenerateContentResponse}.
507
+ *
508
+ * @throws If the prompt or candidate was blocked.
509
+ *
510
+ * @remarks
511
+ * Thought summaries provide a brief overview of the model's internal thinking process,
512
+ * offering insight into how it arrived at the final answer. This can be useful for
513
+ * debugging, understanding the model's reasoning, and verifying its accuracy.
514
+ *
515
+ * Thoughts will only be included if {@link ThinkingConfig.includeThoughts} is
516
+ * set to `true`.
517
+ */
518
+ thoughtSummary: () => string | undefined;
469
519
  }
470
520
 
471
521
  /**
@@ -485,6 +535,8 @@ export declare interface ErrorDetails {
485
535
  [key: string]: unknown;
486
536
  }
487
537
 
538
+ export declare function factory(container: ComponentContainer, { instanceIdentifier }: InstanceFactoryOptions): AIService;
539
+
488
540
  /**
489
541
  * Data pointing to a file uploaded on Google Cloud Storage.
490
542
  * @public
@@ -504,6 +556,8 @@ export declare interface FileDataPart {
504
556
  functionCall?: never;
505
557
  functionResponse?: never;
506
558
  fileData: FileData;
559
+ thought?: boolean;
560
+ /* Excluded from this release type: thoughtSignature */
507
561
  }
508
562
 
509
563
  /**
@@ -555,6 +609,8 @@ export declare const FinishReason: {
555
609
  */
556
610
  export declare type FinishReason = (typeof FinishReason)[keyof typeof FinishReason];
557
611
 
612
+ /* Excluded from this release type: _FirebaseService */
613
+
558
614
  /**
559
615
  * A predicted {@link FunctionCall} returned from the model
560
616
  * that contains a string representing the {@link FunctionDeclaration.name}
@@ -611,6 +667,8 @@ export declare interface FunctionCallPart {
611
667
  inlineData?: never;
612
668
  functionCall: FunctionCall;
613
669
  functionResponse?: never;
670
+ thought?: boolean;
671
+ /* Excluded from this release type: thoughtSignature */
614
672
  }
615
673
 
616
674
  /**
@@ -685,6 +743,8 @@ export declare interface FunctionResponsePart {
685
743
  inlineData?: never;
686
744
  functionCall?: never;
687
745
  functionResponse: FunctionResponse;
746
+ thought?: boolean;
747
+ /* Excluded from this release type: thoughtSignature */
688
748
  }
689
749
 
690
750
  /**
@@ -1663,6 +1723,8 @@ export declare interface InlineDataPart {
1663
1723
  * Applicable if `inlineData` is a video.
1664
1724
  */
1665
1725
  videoMetadata?: VideoMetadata;
1726
+ thought?: boolean;
1727
+ /* Excluded from this release type: thoughtSignature */
1666
1728
  }
1667
1729
 
1668
1730
  /**
@@ -1904,7 +1966,10 @@ export declare interface RequestOptions {
1904
1966
  */
1905
1967
  timeout?: number;
1906
1968
  /**
1907
- * Base url for endpoint. Defaults to https://firebasevertexai.googleapis.com
1969
+ * Base url for endpoint. Defaults to
1970
+ * https://firebasevertexai.googleapis.com, which is the
1971
+ * {@link https://console.cloud.google.com/apis/library/firebasevertexai.googleapis.com?project=_ | Firebase AI Logic API}
1972
+ * (used regardless of your chosen Gemini API provider).
1908
1973
  */
1909
1974
  baseUrl?: string;
1910
1975
  }
@@ -2274,6 +2339,8 @@ export declare interface TextPart {
2274
2339
  inlineData?: never;
2275
2340
  functionCall?: never;
2276
2341
  functionResponse?: never;
2342
+ thought?: boolean;
2343
+ /* Excluded from this release type: thoughtSignature */
2277
2344
  }
2278
2345
 
2279
2346
  /**
@@ -2299,6 +2366,15 @@ export declare interface ThinkingConfig {
2299
2366
  * feature or if the specified budget is not within the model's supported range.
2300
2367
  */
2301
2368
  thinkingBudget?: number;
2369
+ /**
2370
+ * Whether to include "thought summaries" in the model's response.
2371
+ *
2372
+ * @remarks
2373
+ * Thought summaries provide a brief overview of the model's internal thinking process,
2374
+ * offering insight into how it arrived at the final answer. This can be useful for
2375
+ * debugging, understanding the model's reasoning, and verifying its accuracy.
2376
+ */
2377
+ includeThoughts?: boolean;
2302
2378
  }
2303
2379
 
2304
2380
  /**
package/dist/ai.d.ts CHANGED
@@ -4,10 +4,18 @@
4
4
  * @packageDocumentation
5
5
  */
6
6
 
7
+ import { AppCheckInternalComponentName } from '@firebase/app-check-interop-types';
7
8
  import { AppCheckTokenResult } from '@firebase/app-check-interop-types';
9
+ import { ComponentContainer } from '@firebase/component';
8
10
  import { FirebaseApp } from '@firebase/app';
11
+ import { FirebaseAppCheckInternal } from '@firebase/app-check-interop-types';
12
+ import { FirebaseAuthInternal } from '@firebase/auth-interop-types';
13
+ import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
9
14
  import { FirebaseAuthTokenData } from '@firebase/auth-interop-types';
10
15
  import { FirebaseError } from '@firebase/util';
16
+ import { _FirebaseService } from '@firebase/app';
17
+ import { InstanceFactoryOptions } from '@firebase/component';
18
+ import { Provider } from '@firebase/component';
11
19
 
12
20
  /**
13
21
  * An instance of the Firebase AI SDK.
@@ -27,6 +35,10 @@ export declare interface AI {
27
35
  * Vertex AI Gemini API (using {@link VertexAIBackend}).
28
36
  */
29
37
  backend: Backend;
38
+ /**
39
+ * Options applied to this {@link AI} instance.
40
+ */
41
+ options?: AIOptions;
30
42
  /**
31
43
  * @deprecated use `AI.backend.location` instead.
32
44
  *
@@ -111,7 +123,7 @@ export declare abstract class AIModel {
111
123
  /**
112
124
  * @internal
113
125
  */
114
- protected _apiSettings: ApiSettings;
126
+ _apiSettings: ApiSettings;
115
127
  /**
116
128
  * Constructs a new instance of the {@link AIModel} class.
117
129
  *
@@ -159,8 +171,26 @@ export declare abstract class AIModel {
159
171
  export declare interface AIOptions {
160
172
  /**
161
173
  * The backend configuration to use for the AI service instance.
174
+ * Defaults to the Gemini Developer API backend ({@link GoogleAIBackend}).
175
+ */
176
+ backend?: Backend;
177
+ /**
178
+ * Whether to use App Check limited use tokens. Defaults to false.
162
179
  */
180
+ useLimitedUseAppCheckTokens?: boolean;
181
+ }
182
+
183
+ declare class AIService implements AI, _FirebaseService {
184
+ app: FirebaseApp;
163
185
  backend: Backend;
186
+ auth: FirebaseAuthInternal | null;
187
+ appCheck: FirebaseAppCheckInternal | null;
188
+ _options?: Omit<AIOptions, 'backend'>;
189
+ location: string;
190
+ constructor(app: FirebaseApp, backend: Backend, authProvider?: Provider<FirebaseAuthInternalName>, appCheckProvider?: Provider<AppCheckInternalComponentName>);
191
+ _delete(): Promise<void>;
192
+ set options(optionsToSet: AIOptions);
193
+ get options(): AIOptions | undefined;
164
194
  }
165
195
 
166
196
  /**
@@ -360,16 +390,18 @@ export declare interface ChromeAdapter {
360
390
  /**
361
391
  * Generates content using on-device inference.
362
392
  *
363
- * <p>This is comparable to {@link GenerativeModel.generateContent} for generating
364
- * content using in-cloud inference.</p>
393
+ * @remarks
394
+ * This is comparable to {@link GenerativeModel.generateContent} for generating
395
+ * content using in-cloud inference.
365
396
  * @param request - a standard Firebase AI {@link GenerateContentRequest}
366
397
  */
367
398
  generateContent(request: GenerateContentRequest): Promise<Response>;
368
399
  /**
369
400
  * Generates a content stream using on-device inference.
370
401
  *
371
- * <p>This is comparable to {@link GenerativeModel.generateContentStream} for generating
372
- * a content stream using in-cloud inference.</p>
402
+ * @remarks
403
+ * This is comparable to {@link GenerativeModel.generateContentStream} for generating
404
+ * a content stream using in-cloud inference.
373
405
  * @param request - a standard Firebase AI {@link GenerateContentRequest}
374
406
  */
375
407
  generateContentStream(request: GenerateContentRequest): Promise<Response>;
@@ -500,15 +532,34 @@ export declare interface EnhancedGenerateContentResponse extends GenerateContent
500
532
  */
501
533
  text: () => string;
502
534
  /**
503
- * Aggregates and returns all {@link InlineDataPart}s from the {@link GenerateContentResponse}'s
504
- * first candidate.
505
- *
506
- * @returns An array of {@link InlineDataPart}s containing data from the response, if available.
535
+ * Aggregates and returns every {@link InlineDataPart} from the first candidate of
536
+ * {@link GenerateContentResponse}.
507
537
  *
508
538
  * @throws If the prompt or candidate was blocked.
509
539
  */
510
540
  inlineDataParts: () => InlineDataPart[] | undefined;
541
+ /**
542
+ * Aggregates and returns every {@link FunctionCall} from the first candidate of
543
+ * {@link GenerateContentResponse}.
544
+ *
545
+ * @throws If the prompt or candidate was blocked.
546
+ */
511
547
  functionCalls: () => FunctionCall[] | undefined;
548
+ /**
549
+ * Aggregates and returns every {@link TextPart} with their `thought` property set
550
+ * to `true` from the first candidate of {@link GenerateContentResponse}.
551
+ *
552
+ * @throws If the prompt or candidate was blocked.
553
+ *
554
+ * @remarks
555
+ * Thought summaries provide a brief overview of the model's internal thinking process,
556
+ * offering insight into how it arrived at the final answer. This can be useful for
557
+ * debugging, understanding the model's reasoning, and verifying its accuracy.
558
+ *
559
+ * Thoughts will only be included if {@link ThinkingConfig.includeThoughts} is
560
+ * set to `true`.
561
+ */
562
+ thoughtSummary: () => string | undefined;
512
563
  }
513
564
 
514
565
  /**
@@ -528,6 +579,8 @@ export declare interface ErrorDetails {
528
579
  [key: string]: unknown;
529
580
  }
530
581
 
582
+ export declare function factory(container: ComponentContainer, { instanceIdentifier }: InstanceFactoryOptions): AIService;
583
+
531
584
  /**
532
585
  * Data pointing to a file uploaded on Google Cloud Storage.
533
586
  * @public
@@ -547,6 +600,11 @@ export declare interface FileDataPart {
547
600
  functionCall?: never;
548
601
  functionResponse?: never;
549
602
  fileData: FileData;
603
+ thought?: boolean;
604
+ /**
605
+ * @internal
606
+ */
607
+ thoughtSignature?: never;
550
608
  }
551
609
 
552
610
  /**
@@ -654,6 +712,11 @@ export declare interface FunctionCallPart {
654
712
  inlineData?: never;
655
713
  functionCall: FunctionCall;
656
714
  functionResponse?: never;
715
+ thought?: boolean;
716
+ /**
717
+ * @internal
718
+ */
719
+ thoughtSignature?: never;
657
720
  }
658
721
 
659
722
  /**
@@ -728,6 +791,11 @@ export declare interface FunctionResponsePart {
728
791
  inlineData?: never;
729
792
  functionCall?: never;
730
793
  functionResponse: FunctionResponse;
794
+ thought?: boolean;
795
+ /**
796
+ * @internal
797
+ */
798
+ thoughtSignature?: never;
731
799
  }
732
800
 
733
801
  /**
@@ -1759,6 +1827,11 @@ export declare interface InlineDataPart {
1759
1827
  * Applicable if `inlineData` is a video.
1760
1828
  */
1761
1829
  videoMetadata?: VideoMetadata;
1830
+ thought?: boolean;
1831
+ /**
1832
+ * @internal
1833
+ */
1834
+ thoughtSignature?: never;
1762
1835
  }
1763
1836
 
1764
1837
  /**
@@ -2003,7 +2076,10 @@ export declare interface RequestOptions {
2003
2076
  */
2004
2077
  timeout?: number;
2005
2078
  /**
2006
- * Base url for endpoint. Defaults to https://firebasevertexai.googleapis.com
2079
+ * Base url for endpoint. Defaults to
2080
+ * https://firebasevertexai.googleapis.com, which is the
2081
+ * {@link https://console.cloud.google.com/apis/library/firebasevertexai.googleapis.com?project=_ | Firebase AI Logic API}
2082
+ * (used regardless of your chosen Gemini API provider).
2007
2083
  */
2008
2084
  baseUrl?: string;
2009
2085
  }
@@ -2381,6 +2457,11 @@ export declare interface TextPart {
2381
2457
  inlineData?: never;
2382
2458
  functionCall?: never;
2383
2459
  functionResponse?: never;
2460
+ thought?: boolean;
2461
+ /**
2462
+ * @internal
2463
+ */
2464
+ thoughtSignature?: string;
2384
2465
  }
2385
2466
 
2386
2467
  /**
@@ -2406,6 +2487,15 @@ export declare interface ThinkingConfig {
2406
2487
  * feature or if the specified budget is not within the model's supported range.
2407
2488
  */
2408
2489
  thinkingBudget?: number;
2490
+ /**
2491
+ * Whether to include "thought summaries" in the model's response.
2492
+ *
2493
+ * @remarks
2494
+ * Thought summaries provide a brief overview of the model's internal thinking process,
2495
+ * offering insight into how it arrived at the final answer. This can be useful for
2496
+ * debugging, understanding the model's reasoning, and verifying its accuracy.
2497
+ */
2498
+ includeThoughts?: boolean;
2409
2499
  }
2410
2500
 
2411
2501
  /**