@firebase/ai 2.2.1 → 2.3.0-caching-fdc.9f17eac6e

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.
Files changed (35) hide show
  1. package/dist/ai-public.d.ts +290 -33
  2. package/dist/ai.d.ts +297 -33
  3. package/dist/esm/index.esm.js +2801 -2617
  4. package/dist/esm/index.esm.js.map +1 -1
  5. package/dist/esm/src/factory-browser.d.ts +19 -0
  6. package/dist/esm/src/methods/live-session-helpers.d.ts +2 -2
  7. package/dist/esm/src/methods/live-session.d.ts +10 -1
  8. package/dist/esm/src/requests/hybrid-helpers.d.ts +28 -0
  9. package/dist/esm/src/types/chrome-adapter.d.ts +2 -2
  10. package/dist/esm/src/types/content.d.ts +81 -2
  11. package/dist/esm/src/types/enums.d.ts +53 -4
  12. package/dist/esm/src/types/googleai.d.ts +2 -1
  13. package/dist/esm/src/types/language-model.d.ts +10 -20
  14. package/dist/esm/src/types/live-responses.d.ts +9 -1
  15. package/dist/esm/src/types/requests.d.ts +35 -7
  16. package/dist/esm/src/types/responses.d.ts +92 -0
  17. package/dist/index.cjs.js +2803 -2616
  18. package/dist/index.cjs.js.map +1 -1
  19. package/dist/index.node.cjs.js +212 -42
  20. package/dist/index.node.cjs.js.map +1 -1
  21. package/dist/index.node.mjs +210 -43
  22. package/dist/index.node.mjs.map +1 -1
  23. package/dist/src/factory-browser.d.ts +19 -0
  24. package/dist/src/methods/live-session-helpers.d.ts +2 -2
  25. package/dist/src/methods/live-session.d.ts +10 -1
  26. package/dist/src/requests/hybrid-helpers.d.ts +28 -0
  27. package/dist/src/types/chrome-adapter.d.ts +2 -2
  28. package/dist/src/types/content.d.ts +81 -2
  29. package/dist/src/types/enums.d.ts +53 -4
  30. package/dist/src/types/googleai.d.ts +2 -1
  31. package/dist/src/types/language-model.d.ts +10 -20
  32. package/dist/src/types/live-responses.d.ts +9 -1
  33. package/dist/src/types/requests.d.ts +35 -7
  34. package/dist/src/types/responses.d.ts +92 -0
  35. package/package.json +10 -9
@@ -326,13 +326,13 @@ export declare class ChatSession {
326
326
  }
327
327
 
328
328
  /**
329
- * <b>(EXPERIMENTAL)</b> Defines an inference "backend" that uses Chrome's on-device model,
329
+ * Defines an inference "backend" that uses Chrome's on-device model,
330
330
  * and encapsulates logic for detecting when on-device inference is
331
331
  * possible.
332
332
  *
333
333
  * These methods should not be called directly by the user.
334
334
  *
335
- * @public
335
+ * @beta
336
336
  */
337
337
  export declare interface ChromeAdapter {
338
338
  /**
@@ -393,6 +393,53 @@ export declare interface CitationMetadata {
393
393
  citations: Citation[];
394
394
  }
395
395
 
396
+ /**
397
+ * The results of code execution run by the model.
398
+ *
399
+ * @beta
400
+ */
401
+ export declare interface CodeExecutionResult {
402
+ /**
403
+ * The result of the code execution.
404
+ */
405
+ outcome?: Outcome;
406
+ /**
407
+ * The output from the code execution, or an error message
408
+ * if it failed.
409
+ */
410
+ output?: string;
411
+ }
412
+
413
+ /**
414
+ * Represents the code execution result from the model.
415
+ *
416
+ * @beta
417
+ */
418
+ export declare interface CodeExecutionResultPart {
419
+ text?: never;
420
+ inlineData?: never;
421
+ functionCall?: never;
422
+ functionResponse?: never;
423
+ fileData: never;
424
+ thought?: never;
425
+ /* Excluded from this release type: thoughtSignature */
426
+ executableCode?: never;
427
+ codeExecutionResult?: CodeExecutionResult;
428
+ }
429
+
430
+ /**
431
+ * A tool that enables the model to use code execution.
432
+ *
433
+ * @beta
434
+ */
435
+ export declare interface CodeExecutionTool {
436
+ /**
437
+ * Specifies the Google Search configuration.
438
+ * Currently, this is an empty object, but it's reserved for future configuration options.
439
+ */
440
+ codeExecution: {};
441
+ }
442
+
396
443
  /**
397
444
  * Content type for both prompts and response candidates.
398
445
  * @public
@@ -530,6 +577,39 @@ export declare interface ErrorDetails {
530
577
  [key: string]: unknown;
531
578
  }
532
579
 
580
+ /**
581
+ * An interface for executable code returned by the model.
582
+ *
583
+ * @beta
584
+ */
585
+ export declare interface ExecutableCode {
586
+ /**
587
+ * The programming language of the code.
588
+ */
589
+ language?: Language;
590
+ /**
591
+ * The source code to be executed.
592
+ */
593
+ code?: string;
594
+ }
595
+
596
+ /**
597
+ * Represents the code that is executed by the model.
598
+ *
599
+ * @beta
600
+ */
601
+ export declare interface ExecutableCodePart {
602
+ text?: never;
603
+ inlineData?: never;
604
+ functionCall?: never;
605
+ functionResponse?: never;
606
+ fileData: never;
607
+ thought?: never;
608
+ /* Excluded from this release type: thoughtSignature */
609
+ executableCode?: ExecutableCode;
610
+ codeExecutionResult?: never;
611
+ }
612
+
533
613
  /**
534
614
  * Data pointing to a file uploaded on Google Cloud Storage.
535
615
  * @public
@@ -551,6 +631,8 @@ export declare interface FileDataPart {
551
631
  fileData: FileData;
552
632
  thought?: boolean;
553
633
  /* Excluded from this release type: thoughtSignature */
634
+ executableCode?: never;
635
+ codeExecutionResult?: never;
554
636
  }
555
637
 
556
638
  /**
@@ -669,6 +751,8 @@ export declare interface FunctionCallPart {
669
751
  functionResponse?: never;
670
752
  thought?: boolean;
671
753
  /* Excluded from this release type: thoughtSignature */
754
+ executableCode?: never;
755
+ codeExecutionResult?: never;
672
756
  }
673
757
 
674
758
  /**
@@ -753,6 +837,8 @@ export declare interface FunctionResponsePart {
753
837
  functionResponse: FunctionResponse;
754
838
  thought?: boolean;
755
839
  /* Excluded from this release type: thoughtSignature */
840
+ executableCode?: never;
841
+ codeExecutionResult?: never;
756
842
  }
757
843
 
758
844
  /**
@@ -767,6 +853,7 @@ export declare interface GenerateContentCandidate {
767
853
  safetyRatings?: SafetyRating[];
768
854
  citationMetadata?: CitationMetadata;
769
855
  groundingMetadata?: GroundingMetadata;
856
+ urlContextMetadata?: URLContextMetadata;
770
857
  }
771
858
 
772
859
  /**
@@ -1024,8 +1111,6 @@ export declare interface GoogleSearchTool {
1024
1111
  /**
1025
1112
  * Specifies the Google Search configuration.
1026
1113
  * Currently, this is an empty object, but it's reserved for future configuration options.
1027
- * Specifies the Google Search configuration. Currently, this is an empty object, but it's
1028
- * reserved for future configuration options.
1029
1114
  *
1030
1115
  * When using this feature, you are required to comply with the "Grounding with Google Search"
1031
1116
  * usage requirements for your chosen API provider: {@link https://ai.google.dev/gemini-api/terms#grounding-with-google-search | Gemini Developer API}
@@ -1249,9 +1334,8 @@ export declare const HarmSeverity: {
1249
1334
  export declare type HarmSeverity = (typeof HarmSeverity)[keyof typeof HarmSeverity];
1250
1335
 
1251
1336
  /**
1252
- * <b>(EXPERIMENTAL)</b>
1253
1337
  * Configures hybrid inference.
1254
- * @public
1338
+ * @beta
1255
1339
  */
1256
1340
  export declare interface HybridParams {
1257
1341
  /**
@@ -1715,20 +1799,37 @@ export declare interface ImagenSafetySettings {
1715
1799
  }
1716
1800
 
1717
1801
  /**
1718
- * <b>(EXPERIMENTAL)</b>
1719
1802
  * Determines whether inference happens on-device or in-cloud.
1720
- * @public
1803
+ *
1804
+ * @remarks
1805
+ * <b>PREFER_ON_DEVICE:</b> Attempt to make inference calls using an
1806
+ * on-device model. If on-device inference is not available, the SDK
1807
+ * will fall back to using a cloud-hosted model.
1808
+ * <br/>
1809
+ * <b>ONLY_ON_DEVICE:</b> Only attempt to make inference calls using an
1810
+ * on-device model. The SDK will not fall back to a cloud-hosted model.
1811
+ * If on-device inference is not available, inference methods will throw.
1812
+ * <br/>
1813
+ * <b>ONLY_IN_CLOUD:</b> Only attempt to make inference calls using a
1814
+ * cloud-hosted model. The SDK will not fall back to an on-device model.
1815
+ * <br/>
1816
+ * <b>PREFER_IN_CLOUD:</b> Attempt to make inference calls to a
1817
+ * cloud-hosted model. If not available, the SDK will fall back to an
1818
+ * on-device model.
1819
+ *
1820
+ * @beta
1721
1821
  */
1722
1822
  export declare const InferenceMode: {
1723
1823
  readonly PREFER_ON_DEVICE: "prefer_on_device";
1724
1824
  readonly ONLY_ON_DEVICE: "only_on_device";
1725
1825
  readonly ONLY_IN_CLOUD: "only_in_cloud";
1826
+ readonly PREFER_IN_CLOUD: "prefer_in_cloud";
1726
1827
  };
1727
1828
 
1728
1829
  /**
1729
- * <b>(EXPERIMENTAL)</b>
1730
1830
  * Determines whether inference happens on-device or in-cloud.
1731
- * @public
1831
+ *
1832
+ * @beta
1732
1833
  */
1733
1834
  export declare type InferenceMode = (typeof InferenceMode)[keyof typeof InferenceMode];
1734
1835
 
@@ -1747,6 +1848,8 @@ export declare interface InlineDataPart {
1747
1848
  videoMetadata?: VideoMetadata;
1748
1849
  thought?: boolean;
1749
1850
  /* Excluded from this release type: thoughtSignature */
1851
+ executableCode?: never;
1852
+ codeExecutionResult?: never;
1750
1853
  }
1751
1854
 
1752
1855
  /**
@@ -1758,9 +1861,25 @@ export declare class IntegerSchema extends Schema {
1758
1861
  }
1759
1862
 
1760
1863
  /**
1761
- * <b>(EXPERIMENTAL)</b>
1864
+ * The programming language of the code.
1865
+ *
1866
+ * @beta
1867
+ */
1868
+ export declare const Language: {
1869
+ UNSPECIFIED: string;
1870
+ PYTHON: string;
1871
+ };
1872
+
1873
+ /**
1874
+ * The programming language of the code.
1875
+ *
1876
+ * @beta
1877
+ */
1878
+ export declare type Language = (typeof Language)[keyof typeof Language];
1879
+
1880
+ /**
1762
1881
  * Configures the creation of an on-device language model session.
1763
- * @public
1882
+ * @beta
1764
1883
  */
1765
1884
  export declare interface LanguageModelCreateCoreOptions {
1766
1885
  topK?: number;
@@ -1769,9 +1888,8 @@ export declare interface LanguageModelCreateCoreOptions {
1769
1888
  }
1770
1889
 
1771
1890
  /**
1772
- * <b>(EXPERIMENTAL)</b>
1773
1891
  * Configures the creation of an on-device language model session.
1774
- * @public
1892
+ * @beta
1775
1893
  */
1776
1894
  export declare interface LanguageModelCreateOptions extends LanguageModelCreateCoreOptions {
1777
1895
  signal?: AbortSignal;
@@ -1779,18 +1897,16 @@ export declare interface LanguageModelCreateOptions extends LanguageModelCreateC
1779
1897
  }
1780
1898
 
1781
1899
  /**
1782
- * <b>(EXPERIMENTAL)</b>
1783
1900
  * Options for the expected inputs for an on-device language model.
1784
- * @public
1901
+ * @beta
1785
1902
  */ export declare interface LanguageModelExpected {
1786
1903
  type: LanguageModelMessageType;
1787
1904
  languages?: string[];
1788
1905
  }
1789
1906
 
1790
1907
  /**
1791
- * <b>(EXPERIMENTAL)</b>
1792
1908
  * An on-device language model message.
1793
- * @public
1909
+ * @beta
1794
1910
  */
1795
1911
  export declare interface LanguageModelMessage {
1796
1912
  role: LanguageModelMessageRole;
@@ -1798,9 +1914,8 @@ export declare interface LanguageModelMessage {
1798
1914
  }
1799
1915
 
1800
1916
  /**
1801
- * <b>(EXPERIMENTAL)</b>
1802
1917
  * An on-device language model content object.
1803
- * @public
1918
+ * @beta
1804
1919
  */
1805
1920
  export declare interface LanguageModelMessageContent {
1806
1921
  type: LanguageModelMessageType;
@@ -1808,30 +1923,26 @@ export declare interface LanguageModelMessageContent {
1808
1923
  }
1809
1924
 
1810
1925
  /**
1811
- * <b>(EXPERIMENTAL)</b>
1812
1926
  * Content formats that can be provided as on-device message content.
1813
- * @public
1927
+ * @beta
1814
1928
  */
1815
1929
  export declare type LanguageModelMessageContentValue = ImageBitmapSource | AudioBuffer | BufferSource | string;
1816
1930
 
1817
1931
  /**
1818
- * <b>(EXPERIMENTAL)</b>
1819
1932
  * Allowable roles for on-device language model usage.
1820
- * @public
1933
+ * @beta
1821
1934
  */
1822
1935
  export declare type LanguageModelMessageRole = 'system' | 'user' | 'assistant';
1823
1936
 
1824
1937
  /**
1825
- * <b>(EXPERIMENTAL)</b>
1826
1938
  * Allowable types for on-device language model messages.
1827
- * @public
1939
+ * @beta
1828
1940
  */
1829
1941
  export declare type LanguageModelMessageType = 'text' | 'image' | 'audio';
1830
1942
 
1831
1943
  /**
1832
- * <b>(EXPERIMENTAL)</b>
1833
1944
  * Options for an on-device language model prompt.
1834
- * @public
1945
+ * @beta
1835
1946
  */
1836
1947
  export declare interface LanguageModelPromptOptions {
1837
1948
  responseConstraint?: object;
@@ -2037,6 +2148,15 @@ export declare class LiveSession {
2037
2148
  * @beta
2038
2149
  */
2039
2150
  sendMediaChunks(mediaChunks: GenerativeContentBlob[]): Promise<void>;
2151
+ /**
2152
+ * Sends function responses to the server.
2153
+ *
2154
+ * @param functionResponses - The function responses to send.
2155
+ * @throws If this session has been closed.
2156
+ *
2157
+ * @beta
2158
+ */
2159
+ sendFunctionResponses(functionResponses: FunctionResponse[]): Promise<void>;
2040
2160
  /**
2041
2161
  * Sends a stream of {@link GenerativeContentBlob}.
2042
2162
  *
@@ -2167,22 +2287,40 @@ export declare interface ObjectSchemaRequest extends SchemaRequest {
2167
2287
  }
2168
2288
 
2169
2289
  /**
2170
- * <b>(EXPERIMENTAL)</b>
2171
2290
  * Encapsulates configuration for on-device inference.
2172
2291
  *
2173
- * @public
2292
+ * @beta
2174
2293
  */
2175
2294
  export declare interface OnDeviceParams {
2176
2295
  createOptions?: LanguageModelCreateOptions;
2177
2296
  promptOptions?: LanguageModelPromptOptions;
2178
2297
  }
2179
2298
 
2299
+ /**
2300
+ * Represents the result of the code execution.
2301
+ *
2302
+ * @beta
2303
+ */
2304
+ export declare const Outcome: {
2305
+ UNSPECIFIED: string;
2306
+ OK: string;
2307
+ FAILED: string;
2308
+ DEADLINE_EXCEEDED: string;
2309
+ };
2310
+
2311
+ /**
2312
+ * Represents the result of the code execution.
2313
+ *
2314
+ * @beta
2315
+ */
2316
+ export declare type Outcome = (typeof Outcome)[keyof typeof Outcome];
2317
+
2180
2318
  /**
2181
2319
  * Content part - includes text, image/video, or function call/response
2182
2320
  * part types.
2183
2321
  * @public
2184
2322
  */
2185
- export declare type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart;
2323
+ export declare type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart | ExecutableCodePart | CodeExecutionResultPart;
2186
2324
 
2187
2325
  /**
2188
2326
  * Possible roles.
@@ -2648,7 +2786,7 @@ export declare interface StartAudioConversationOptions {
2648
2786
  * The handler should perform the function call and return the result as a `Part`,
2649
2787
  * which will then be sent back to the model.
2650
2788
  */
2651
- functionCallingHandler?: (functionCalls: LiveServerToolCall['functionCalls']) => Promise<Part>;
2789
+ functionCallingHandler?: (functionCalls: FunctionCall[]) => Promise<FunctionResponse>;
2652
2790
  }
2653
2791
 
2654
2792
  /**
@@ -2684,6 +2822,8 @@ export declare interface TextPart {
2684
2822
  functionResponse?: never;
2685
2823
  thought?: boolean;
2686
2824
  /* Excluded from this release type: thoughtSignature */
2825
+ executableCode?: never;
2826
+ codeExecutionResult?: never;
2687
2827
  }
2688
2828
 
2689
2829
  /**
@@ -2724,7 +2864,7 @@ export declare interface ThinkingConfig {
2724
2864
  * Defines a tool that model can call to access external knowledge.
2725
2865
  * @public
2726
2866
  */
2727
- export declare type Tool = FunctionDeclarationsTool | GoogleSearchTool;
2867
+ export declare type Tool = FunctionDeclarationsTool | GoogleSearchTool | CodeExecutionTool | URLContextTool;
2728
2868
 
2729
2869
  /**
2730
2870
  * Tool config. This config is shared for all tools provided in the request.
@@ -2740,6 +2880,115 @@ export declare interface ToolConfig {
2740
2880
  */
2741
2881
  export declare type TypedSchema = IntegerSchema | NumberSchema | StringSchema | BooleanSchema | ObjectSchema | ArraySchema | AnyOfSchema;
2742
2882
 
2883
+ /**
2884
+ * Specifies the URL Context configuration.
2885
+ *
2886
+ * @beta
2887
+ */
2888
+ export declare interface URLContext {
2889
+ }
2890
+
2891
+ /**
2892
+ * Metadata related to {@link URLContextTool}.
2893
+ *
2894
+ * @beta
2895
+ */
2896
+ export declare interface URLContextMetadata {
2897
+ /**
2898
+ * List of URL metadata used to provide context to the Gemini model.
2899
+ */
2900
+ urlMetadata: URLMetadata[];
2901
+ }
2902
+
2903
+ /**
2904
+ * A tool that allows you to provide additional context to the models in the form of public web
2905
+ * URLs. By including URLs in your request, the Gemini model will access the content from those
2906
+ * pages to inform and enhance its response.
2907
+ *
2908
+ * @beta
2909
+ */
2910
+ export declare interface URLContextTool {
2911
+ /**
2912
+ * Specifies the URL Context configuration.
2913
+ */
2914
+ urlContext: URLContext;
2915
+ }
2916
+
2917
+ /**
2918
+ * Metadata for a single URL retrieved by the {@link URLContextTool} tool.
2919
+ *
2920
+ * @beta
2921
+ */
2922
+ export declare interface URLMetadata {
2923
+ /**
2924
+ * The retrieved URL.
2925
+ */
2926
+ retrievedUrl?: string;
2927
+ /**
2928
+ * The status of the URL retrieval.
2929
+ */
2930
+ urlRetrievalStatus?: URLRetrievalStatus;
2931
+ }
2932
+
2933
+ /**
2934
+ * The status of a URL retrieval.
2935
+ *
2936
+ * @remarks
2937
+ * <b>URL_RETRIEVAL_STATUS_UNSPECIFIED:</b> Unspecified retrieval status.
2938
+ * <br/>
2939
+ * <b>URL_RETRIEVAL_STATUS_SUCCESS:</b> The URL retrieval was successful.
2940
+ * <br/>
2941
+ * <b>URL_RETRIEVAL_STATUS_ERROR:</b> The URL retrieval failed.
2942
+ * <br/>
2943
+ * <b>URL_RETRIEVAL_STATUS_PAYWALL:</b> The URL retrieval failed because the content is behind a paywall.
2944
+ * <br/>
2945
+ * <b>URL_RETRIEVAL_STATUS_UNSAFE:</b> The URL retrieval failed because the content is unsafe.
2946
+ * <br/>
2947
+ *
2948
+ * @beta
2949
+ */
2950
+ export declare const URLRetrievalStatus: {
2951
+ /**
2952
+ * Unspecified retrieval status.
2953
+ */
2954
+ URL_RETRIEVAL_STATUS_UNSPECIFIED: string;
2955
+ /**
2956
+ * The URL retrieval was successful.
2957
+ */
2958
+ URL_RETRIEVAL_STATUS_SUCCESS: string;
2959
+ /**
2960
+ * The URL retrieval failed.
2961
+ */
2962
+ URL_RETRIEVAL_STATUS_ERROR: string;
2963
+ /**
2964
+ * The URL retrieval failed because the content is behind a paywall.
2965
+ */
2966
+ URL_RETRIEVAL_STATUS_PAYWALL: string;
2967
+ /**
2968
+ * The URL retrieval failed because the content is unsafe.
2969
+ */
2970
+ URL_RETRIEVAL_STATUS_UNSAFE: string;
2971
+ };
2972
+
2973
+ /**
2974
+ * The status of a URL retrieval.
2975
+ *
2976
+ * @remarks
2977
+ * <b>URL_RETRIEVAL_STATUS_UNSPECIFIED:</b> Unspecified retrieval status.
2978
+ * <br/>
2979
+ * <b>URL_RETRIEVAL_STATUS_SUCCESS:</b> The URL retrieval was successful.
2980
+ * <br/>
2981
+ * <b>URL_RETRIEVAL_STATUS_ERROR:</b> The URL retrieval failed.
2982
+ * <br/>
2983
+ * <b>URL_RETRIEVAL_STATUS_PAYWALL:</b> The URL retrieval failed because the content is behind a paywall.
2984
+ * <br/>
2985
+ * <b>URL_RETRIEVAL_STATUS_UNSAFE:</b> The URL retrieval failed because the content is unsafe.
2986
+ * <br/>
2987
+ *
2988
+ * @beta
2989
+ */
2990
+ export declare type URLRetrievalStatus = (typeof URLRetrievalStatus)[keyof typeof URLRetrievalStatus];
2991
+
2743
2992
  /**
2744
2993
  * Usage metadata about a {@link GenerateContentResponse}.
2745
2994
  *
@@ -2753,8 +3002,16 @@ export declare interface UsageMetadata {
2753
3002
  */
2754
3003
  thoughtsTokenCount?: number;
2755
3004
  totalTokenCount: number;
3005
+ /**
3006
+ * The number of tokens used by tools.
3007
+ */
3008
+ toolUsePromptTokenCount?: number;
2756
3009
  promptTokensDetails?: ModalityTokenCount[];
2757
3010
  candidatesTokensDetails?: ModalityTokenCount[];
3011
+ /**
3012
+ * A list of tokens used by tools, broken down by modality.
3013
+ */
3014
+ toolUsePromptTokensDetails?: ModalityTokenCount[];
2758
3015
  }
2759
3016
 
2760
3017
  /**