@firebase/ai 2.2.1 → 2.3.0-canary.0bb2fe636

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
package/dist/ai.d.ts CHANGED
@@ -366,13 +366,13 @@ export declare class ChatSession {
366
366
  }
367
367
 
368
368
  /**
369
- * <b>(EXPERIMENTAL)</b> Defines an inference "backend" that uses Chrome's on-device model,
369
+ * Defines an inference "backend" that uses Chrome's on-device model,
370
370
  * and encapsulates logic for detecting when on-device inference is
371
371
  * possible.
372
372
  *
373
373
  * These methods should not be called directly by the user.
374
374
  *
375
- * @public
375
+ * @beta
376
376
  */
377
377
  export declare interface ChromeAdapter {
378
378
  /**
@@ -436,6 +436,56 @@ export declare interface CitationMetadata {
436
436
  citations: Citation[];
437
437
  }
438
438
 
439
+ /**
440
+ * The results of code execution run by the model.
441
+ *
442
+ * @beta
443
+ */
444
+ export declare interface CodeExecutionResult {
445
+ /**
446
+ * The result of the code execution.
447
+ */
448
+ outcome?: Outcome;
449
+ /**
450
+ * The output from the code execution, or an error message
451
+ * if it failed.
452
+ */
453
+ output?: string;
454
+ }
455
+
456
+ /**
457
+ * Represents the code execution result from the model.
458
+ *
459
+ * @beta
460
+ */
461
+ export declare interface CodeExecutionResultPart {
462
+ text?: never;
463
+ inlineData?: never;
464
+ functionCall?: never;
465
+ functionResponse?: never;
466
+ fileData: never;
467
+ thought?: never;
468
+ /**
469
+ * @internal
470
+ */
471
+ thoughtSignature?: never;
472
+ executableCode?: never;
473
+ codeExecutionResult?: CodeExecutionResult;
474
+ }
475
+
476
+ /**
477
+ * A tool that enables the model to use code execution.
478
+ *
479
+ * @beta
480
+ */
481
+ export declare interface CodeExecutionTool {
482
+ /**
483
+ * Specifies the Google Search configuration.
484
+ * Currently, this is an empty object, but it's reserved for future configuration options.
485
+ */
486
+ codeExecution: {};
487
+ }
488
+
439
489
  /**
440
490
  * Content type for both prompts and response candidates.
441
491
  * @public
@@ -573,6 +623,42 @@ export declare interface ErrorDetails {
573
623
  [key: string]: unknown;
574
624
  }
575
625
 
626
+ /**
627
+ * An interface for executable code returned by the model.
628
+ *
629
+ * @beta
630
+ */
631
+ export declare interface ExecutableCode {
632
+ /**
633
+ * The programming language of the code.
634
+ */
635
+ language?: Language;
636
+ /**
637
+ * The source code to be executed.
638
+ */
639
+ code?: string;
640
+ }
641
+
642
+ /**
643
+ * Represents the code that is executed by the model.
644
+ *
645
+ * @beta
646
+ */
647
+ export declare interface ExecutableCodePart {
648
+ text?: never;
649
+ inlineData?: never;
650
+ functionCall?: never;
651
+ functionResponse?: never;
652
+ fileData: never;
653
+ thought?: never;
654
+ /**
655
+ * @internal
656
+ */
657
+ thoughtSignature?: never;
658
+ executableCode?: ExecutableCode;
659
+ codeExecutionResult?: never;
660
+ }
661
+
576
662
  /**
577
663
  * Data pointing to a file uploaded on Google Cloud Storage.
578
664
  * @public
@@ -597,6 +683,8 @@ export declare interface FileDataPart {
597
683
  * @internal
598
684
  */
599
685
  thoughtSignature?: never;
686
+ executableCode?: never;
687
+ codeExecutionResult?: never;
600
688
  }
601
689
 
602
690
  /**
@@ -718,6 +806,8 @@ export declare interface FunctionCallPart {
718
806
  * @internal
719
807
  */
720
808
  thoughtSignature?: never;
809
+ executableCode?: never;
810
+ codeExecutionResult?: never;
721
811
  }
722
812
 
723
813
  /**
@@ -805,6 +895,8 @@ export declare interface FunctionResponsePart {
805
895
  * @internal
806
896
  */
807
897
  thoughtSignature?: never;
898
+ executableCode?: never;
899
+ codeExecutionResult?: never;
808
900
  }
809
901
 
810
902
  /**
@@ -819,6 +911,7 @@ export declare interface GenerateContentCandidate {
819
911
  safetyRatings?: SafetyRating[];
820
912
  citationMetadata?: CitationMetadata;
821
913
  groundingMetadata?: GroundingMetadata;
914
+ urlContextMetadata?: URLContextMetadata;
822
915
  }
823
916
 
824
917
  /**
@@ -1074,6 +1167,7 @@ export declare interface GoogleAIGenerateContentCandidate {
1074
1167
  safetyRatings?: SafetyRating[];
1075
1168
  citationMetadata?: GoogleAICitationMetadata;
1076
1169
  groundingMetadata?: GroundingMetadata;
1170
+ urlContextMetadata?: URLContextMetadata;
1077
1171
  }
1078
1172
 
1079
1173
  /**
@@ -1110,8 +1204,6 @@ export declare interface GoogleSearchTool {
1110
1204
  /**
1111
1205
  * Specifies the Google Search configuration.
1112
1206
  * Currently, this is an empty object, but it's reserved for future configuration options.
1113
- * Specifies the Google Search configuration. Currently, this is an empty object, but it's
1114
- * reserved for future configuration options.
1115
1207
  *
1116
1208
  * When using this feature, you are required to comply with the "Grounding with Google Search"
1117
1209
  * usage requirements for your chosen API provider: {@link https://ai.google.dev/gemini-api/terms#grounding-with-google-search | Gemini Developer API}
@@ -1335,9 +1427,8 @@ export declare const HarmSeverity: {
1335
1427
  export declare type HarmSeverity = (typeof HarmSeverity)[keyof typeof HarmSeverity];
1336
1428
 
1337
1429
  /**
1338
- * <b>(EXPERIMENTAL)</b>
1339
1430
  * Configures hybrid inference.
1340
- * @public
1431
+ * @beta
1341
1432
  */
1342
1433
  export declare interface HybridParams {
1343
1434
  /**
@@ -1820,20 +1911,37 @@ export declare interface ImagenSafetySettings {
1820
1911
  }
1821
1912
 
1822
1913
  /**
1823
- * <b>(EXPERIMENTAL)</b>
1824
1914
  * Determines whether inference happens on-device or in-cloud.
1825
- * @public
1915
+ *
1916
+ * @remarks
1917
+ * <b>PREFER_ON_DEVICE:</b> Attempt to make inference calls using an
1918
+ * on-device model. If on-device inference is not available, the SDK
1919
+ * will fall back to using a cloud-hosted model.
1920
+ * <br/>
1921
+ * <b>ONLY_ON_DEVICE:</b> Only attempt to make inference calls using an
1922
+ * on-device model. The SDK will not fall back to a cloud-hosted model.
1923
+ * If on-device inference is not available, inference methods will throw.
1924
+ * <br/>
1925
+ * <b>ONLY_IN_CLOUD:</b> Only attempt to make inference calls using a
1926
+ * cloud-hosted model. The SDK will not fall back to an on-device model.
1927
+ * <br/>
1928
+ * <b>PREFER_IN_CLOUD:</b> Attempt to make inference calls to a
1929
+ * cloud-hosted model. If not available, the SDK will fall back to an
1930
+ * on-device model.
1931
+ *
1932
+ * @beta
1826
1933
  */
1827
1934
  export declare const InferenceMode: {
1828
1935
  readonly PREFER_ON_DEVICE: "prefer_on_device";
1829
1936
  readonly ONLY_ON_DEVICE: "only_on_device";
1830
1937
  readonly ONLY_IN_CLOUD: "only_in_cloud";
1938
+ readonly PREFER_IN_CLOUD: "prefer_in_cloud";
1831
1939
  };
1832
1940
 
1833
1941
  /**
1834
- * <b>(EXPERIMENTAL)</b>
1835
1942
  * Determines whether inference happens on-device or in-cloud.
1836
- * @public
1943
+ *
1944
+ * @beta
1837
1945
  */
1838
1946
  export declare type InferenceMode = (typeof InferenceMode)[keyof typeof InferenceMode];
1839
1947
 
@@ -1855,6 +1963,8 @@ export declare interface InlineDataPart {
1855
1963
  * @internal
1856
1964
  */
1857
1965
  thoughtSignature?: never;
1966
+ executableCode?: never;
1967
+ codeExecutionResult?: never;
1858
1968
  }
1859
1969
 
1860
1970
  /**
@@ -1866,9 +1976,25 @@ export declare class IntegerSchema extends Schema {
1866
1976
  }
1867
1977
 
1868
1978
  /**
1869
- * <b>(EXPERIMENTAL)</b>
1979
+ * The programming language of the code.
1980
+ *
1981
+ * @beta
1982
+ */
1983
+ export declare const Language: {
1984
+ UNSPECIFIED: string;
1985
+ PYTHON: string;
1986
+ };
1987
+
1988
+ /**
1989
+ * The programming language of the code.
1990
+ *
1991
+ * @beta
1992
+ */
1993
+ export declare type Language = (typeof Language)[keyof typeof Language];
1994
+
1995
+ /**
1870
1996
  * Configures the creation of an on-device language model session.
1871
- * @public
1997
+ * @beta
1872
1998
  */
1873
1999
  export declare interface LanguageModelCreateCoreOptions {
1874
2000
  topK?: number;
@@ -1877,9 +2003,8 @@ export declare interface LanguageModelCreateCoreOptions {
1877
2003
  }
1878
2004
 
1879
2005
  /**
1880
- * <b>(EXPERIMENTAL)</b>
1881
2006
  * Configures the creation of an on-device language model session.
1882
- * @public
2007
+ * @beta
1883
2008
  */
1884
2009
  export declare interface LanguageModelCreateOptions extends LanguageModelCreateCoreOptions {
1885
2010
  signal?: AbortSignal;
@@ -1887,18 +2012,16 @@ export declare interface LanguageModelCreateOptions extends LanguageModelCreateC
1887
2012
  }
1888
2013
 
1889
2014
  /**
1890
- * <b>(EXPERIMENTAL)</b>
1891
2015
  * Options for the expected inputs for an on-device language model.
1892
- * @public
2016
+ * @beta
1893
2017
  */ export declare interface LanguageModelExpected {
1894
2018
  type: LanguageModelMessageType;
1895
2019
  languages?: string[];
1896
2020
  }
1897
2021
 
1898
2022
  /**
1899
- * <b>(EXPERIMENTAL)</b>
1900
2023
  * An on-device language model message.
1901
- * @public
2024
+ * @beta
1902
2025
  */
1903
2026
  export declare interface LanguageModelMessage {
1904
2027
  role: LanguageModelMessageRole;
@@ -1906,9 +2029,8 @@ export declare interface LanguageModelMessage {
1906
2029
  }
1907
2030
 
1908
2031
  /**
1909
- * <b>(EXPERIMENTAL)</b>
1910
2032
  * An on-device language model content object.
1911
- * @public
2033
+ * @beta
1912
2034
  */
1913
2035
  export declare interface LanguageModelMessageContent {
1914
2036
  type: LanguageModelMessageType;
@@ -1916,30 +2038,26 @@ export declare interface LanguageModelMessageContent {
1916
2038
  }
1917
2039
 
1918
2040
  /**
1919
- * <b>(EXPERIMENTAL)</b>
1920
2041
  * Content formats that can be provided as on-device message content.
1921
- * @public
2042
+ * @beta
1922
2043
  */
1923
2044
  export declare type LanguageModelMessageContentValue = ImageBitmapSource | AudioBuffer | BufferSource | string;
1924
2045
 
1925
2046
  /**
1926
- * <b>(EXPERIMENTAL)</b>
1927
2047
  * Allowable roles for on-device language model usage.
1928
- * @public
2048
+ * @beta
1929
2049
  */
1930
2050
  export declare type LanguageModelMessageRole = 'system' | 'user' | 'assistant';
1931
2051
 
1932
2052
  /**
1933
- * <b>(EXPERIMENTAL)</b>
1934
2053
  * Allowable types for on-device language model messages.
1935
- * @public
2054
+ * @beta
1936
2055
  */
1937
2056
  export declare type LanguageModelMessageType = 'text' | 'image' | 'audio';
1938
2057
 
1939
2058
  /**
1940
- * <b>(EXPERIMENTAL)</b>
1941
2059
  * Options for an on-device language model prompt.
1942
- * @public
2060
+ * @beta
1943
2061
  */
1944
2062
  export declare interface LanguageModelPromptOptions {
1945
2063
  responseConstraint?: object;
@@ -2158,6 +2276,15 @@ export declare class LiveSession {
2158
2276
  * @beta
2159
2277
  */
2160
2278
  sendMediaChunks(mediaChunks: GenerativeContentBlob[]): Promise<void>;
2279
+ /**
2280
+ * Sends function responses to the server.
2281
+ *
2282
+ * @param functionResponses - The function responses to send.
2283
+ * @throws If this session has been closed.
2284
+ *
2285
+ * @beta
2286
+ */
2287
+ sendFunctionResponses(functionResponses: FunctionResponse[]): Promise<void>;
2161
2288
  /**
2162
2289
  * Sends a stream of {@link GenerativeContentBlob}.
2163
2290
  *
@@ -2291,22 +2418,40 @@ export declare interface ObjectSchemaRequest extends SchemaRequest {
2291
2418
  }
2292
2419
 
2293
2420
  /**
2294
- * <b>(EXPERIMENTAL)</b>
2295
2421
  * Encapsulates configuration for on-device inference.
2296
2422
  *
2297
- * @public
2423
+ * @beta
2298
2424
  */
2299
2425
  export declare interface OnDeviceParams {
2300
2426
  createOptions?: LanguageModelCreateOptions;
2301
2427
  promptOptions?: LanguageModelPromptOptions;
2302
2428
  }
2303
2429
 
2430
+ /**
2431
+ * Represents the result of the code execution.
2432
+ *
2433
+ * @beta
2434
+ */
2435
+ export declare const Outcome: {
2436
+ UNSPECIFIED: string;
2437
+ OK: string;
2438
+ FAILED: string;
2439
+ DEADLINE_EXCEEDED: string;
2440
+ };
2441
+
2442
+ /**
2443
+ * Represents the result of the code execution.
2444
+ *
2445
+ * @beta
2446
+ */
2447
+ export declare type Outcome = (typeof Outcome)[keyof typeof Outcome];
2448
+
2304
2449
  /**
2305
2450
  * Content part - includes text, image/video, or function call/response
2306
2451
  * part types.
2307
2452
  * @public
2308
2453
  */
2309
- export declare type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart;
2454
+ export declare type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart | ExecutableCodePart | CodeExecutionResultPart;
2310
2455
 
2311
2456
  /**
2312
2457
  * Possible roles.
@@ -2777,7 +2922,7 @@ export declare interface StartAudioConversationOptions {
2777
2922
  * The handler should perform the function call and return the result as a `Part`,
2778
2923
  * which will then be sent back to the model.
2779
2924
  */
2780
- functionCallingHandler?: (functionCalls: LiveServerToolCall['functionCalls']) => Promise<Part>;
2925
+ functionCallingHandler?: (functionCalls: FunctionCall[]) => Promise<FunctionResponse>;
2781
2926
  }
2782
2927
 
2783
2928
  /**
@@ -2819,6 +2964,8 @@ export declare interface TextPart {
2819
2964
  * @internal
2820
2965
  */
2821
2966
  thoughtSignature?: string;
2967
+ executableCode?: never;
2968
+ codeExecutionResult?: never;
2822
2969
  }
2823
2970
 
2824
2971
  /**
@@ -2859,7 +3006,7 @@ export declare interface ThinkingConfig {
2859
3006
  * Defines a tool that model can call to access external knowledge.
2860
3007
  * @public
2861
3008
  */
2862
- export declare type Tool = FunctionDeclarationsTool | GoogleSearchTool;
3009
+ export declare type Tool = FunctionDeclarationsTool | GoogleSearchTool | CodeExecutionTool | URLContextTool;
2863
3010
 
2864
3011
  /**
2865
3012
  * Tool config. This config is shared for all tools provided in the request.
@@ -2875,6 +3022,115 @@ export declare interface ToolConfig {
2875
3022
  */
2876
3023
  export declare type TypedSchema = IntegerSchema | NumberSchema | StringSchema | BooleanSchema | ObjectSchema | ArraySchema | AnyOfSchema;
2877
3024
 
3025
+ /**
3026
+ * Specifies the URL Context configuration.
3027
+ *
3028
+ * @beta
3029
+ */
3030
+ export declare interface URLContext {
3031
+ }
3032
+
3033
+ /**
3034
+ * Metadata related to {@link URLContextTool}.
3035
+ *
3036
+ * @beta
3037
+ */
3038
+ export declare interface URLContextMetadata {
3039
+ /**
3040
+ * List of URL metadata used to provide context to the Gemini model.
3041
+ */
3042
+ urlMetadata: URLMetadata[];
3043
+ }
3044
+
3045
+ /**
3046
+ * A tool that allows you to provide additional context to the models in the form of public web
3047
+ * URLs. By including URLs in your request, the Gemini model will access the content from those
3048
+ * pages to inform and enhance its response.
3049
+ *
3050
+ * @beta
3051
+ */
3052
+ export declare interface URLContextTool {
3053
+ /**
3054
+ * Specifies the URL Context configuration.
3055
+ */
3056
+ urlContext: URLContext;
3057
+ }
3058
+
3059
+ /**
3060
+ * Metadata for a single URL retrieved by the {@link URLContextTool} tool.
3061
+ *
3062
+ * @beta
3063
+ */
3064
+ export declare interface URLMetadata {
3065
+ /**
3066
+ * The retrieved URL.
3067
+ */
3068
+ retrievedUrl?: string;
3069
+ /**
3070
+ * The status of the URL retrieval.
3071
+ */
3072
+ urlRetrievalStatus?: URLRetrievalStatus;
3073
+ }
3074
+
3075
+ /**
3076
+ * The status of a URL retrieval.
3077
+ *
3078
+ * @remarks
3079
+ * <b>URL_RETRIEVAL_STATUS_UNSPECIFIED:</b> Unspecified retrieval status.
3080
+ * <br/>
3081
+ * <b>URL_RETRIEVAL_STATUS_SUCCESS:</b> The URL retrieval was successful.
3082
+ * <br/>
3083
+ * <b>URL_RETRIEVAL_STATUS_ERROR:</b> The URL retrieval failed.
3084
+ * <br/>
3085
+ * <b>URL_RETRIEVAL_STATUS_PAYWALL:</b> The URL retrieval failed because the content is behind a paywall.
3086
+ * <br/>
3087
+ * <b>URL_RETRIEVAL_STATUS_UNSAFE:</b> The URL retrieval failed because the content is unsafe.
3088
+ * <br/>
3089
+ *
3090
+ * @beta
3091
+ */
3092
+ export declare const URLRetrievalStatus: {
3093
+ /**
3094
+ * Unspecified retrieval status.
3095
+ */
3096
+ URL_RETRIEVAL_STATUS_UNSPECIFIED: string;
3097
+ /**
3098
+ * The URL retrieval was successful.
3099
+ */
3100
+ URL_RETRIEVAL_STATUS_SUCCESS: string;
3101
+ /**
3102
+ * The URL retrieval failed.
3103
+ */
3104
+ URL_RETRIEVAL_STATUS_ERROR: string;
3105
+ /**
3106
+ * The URL retrieval failed because the content is behind a paywall.
3107
+ */
3108
+ URL_RETRIEVAL_STATUS_PAYWALL: string;
3109
+ /**
3110
+ * The URL retrieval failed because the content is unsafe.
3111
+ */
3112
+ URL_RETRIEVAL_STATUS_UNSAFE: string;
3113
+ };
3114
+
3115
+ /**
3116
+ * The status of a URL retrieval.
3117
+ *
3118
+ * @remarks
3119
+ * <b>URL_RETRIEVAL_STATUS_UNSPECIFIED:</b> Unspecified retrieval status.
3120
+ * <br/>
3121
+ * <b>URL_RETRIEVAL_STATUS_SUCCESS:</b> The URL retrieval was successful.
3122
+ * <br/>
3123
+ * <b>URL_RETRIEVAL_STATUS_ERROR:</b> The URL retrieval failed.
3124
+ * <br/>
3125
+ * <b>URL_RETRIEVAL_STATUS_PAYWALL:</b> The URL retrieval failed because the content is behind a paywall.
3126
+ * <br/>
3127
+ * <b>URL_RETRIEVAL_STATUS_UNSAFE:</b> The URL retrieval failed because the content is unsafe.
3128
+ * <br/>
3129
+ *
3130
+ * @beta
3131
+ */
3132
+ export declare type URLRetrievalStatus = (typeof URLRetrievalStatus)[keyof typeof URLRetrievalStatus];
3133
+
2878
3134
  /**
2879
3135
  * Usage metadata about a {@link GenerateContentResponse}.
2880
3136
  *
@@ -2888,8 +3144,16 @@ export declare interface UsageMetadata {
2888
3144
  */
2889
3145
  thoughtsTokenCount?: number;
2890
3146
  totalTokenCount: number;
3147
+ /**
3148
+ * The number of tokens used by tools.
3149
+ */
3150
+ toolUsePromptTokenCount?: number;
2891
3151
  promptTokensDetails?: ModalityTokenCount[];
2892
3152
  candidatesTokensDetails?: ModalityTokenCount[];
3153
+ /**
3154
+ * A list of tokens used by tools, broken down by modality.
3155
+ */
3156
+ toolUsePromptTokensDetails?: ModalityTokenCount[];
2893
3157
  }
2894
3158
 
2895
3159
  /**