@firebase/ai 1.4.0-canary.86155b3c8 → 1.4.0-canary.91fa484b5

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.
@@ -568,7 +568,7 @@ export declare interface FunctionDeclaration {
568
568
  * format. Reflects the Open API 3.03 Parameter Object. Parameter names are
569
569
  * case-sensitive. For a function with no parameters, this can be left unset.
570
570
  */
571
- parameters?: ObjectSchemaInterface;
571
+ parameters?: ObjectSchema | ObjectSchemaRequest;
572
572
  }
573
573
 
574
574
  /**
@@ -857,6 +857,42 @@ export declare class GoogleAIBackend extends Backend {
857
857
 
858
858
  /* Excluded from this release type: GoogleAIGenerateContentResponse */
859
859
 
860
+ /**
861
+ * Specifies the Google Search configuration.
862
+ *
863
+ * @remarks Currently, this is an empty object, but it's reserved for future configuration options.
864
+ *
865
+ * @public
866
+ */
867
+ export declare interface GoogleSearch {
868
+ }
869
+
870
+ /**
871
+ * A tool that allows a Gemini model to connect to Google Search to access and incorporate
872
+ * up-to-date information from the web into its responses.
873
+ *
874
+ * Important: If using Grounding with Google Search, you are required to comply with the
875
+ * "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}
876
+ * or Vertex AI Gemini API (see {@link https://cloud.google.com/terms/service-terms | Service Terms}
877
+ * section within the Service Specific Terms).
878
+ *
879
+ * @public
880
+ */
881
+ export declare interface GoogleSearchTool {
882
+ /**
883
+ * Specifies the Google Search configuration.
884
+ * Currently, this is an empty object, but it's reserved for future configuration options.
885
+ * Specifies the Google Search configuration. Currently, this is an empty object, but it's
886
+ * reserved for future configuration options.
887
+ *
888
+ * When using this feature, you are required to comply with the "Grounding with Google Search"
889
+ * usage requirements for your chosen API provider: {@link https://ai.google.dev/gemini-api/terms#grounding-with-google-search | Gemini Developer API}
890
+ * or Vertex AI Gemini API (see {@link https://cloud.google.com/terms/service-terms | Service Terms}
891
+ * section within the Service Specific Terms).
892
+ */
893
+ googleSearch: GoogleSearch;
894
+ }
895
+
860
896
  /**
861
897
  * @deprecated
862
898
  * @public
@@ -869,18 +905,83 @@ export declare interface GroundingAttribution {
869
905
  }
870
906
 
871
907
  /**
872
- * Metadata returned to client when grounding is enabled.
908
+ * Represents a chunk of retrieved data that supports a claim in the model's response. This is part
909
+ * of the grounding information provided when grounding is enabled.
910
+ *
911
+ * @public
912
+ */
913
+ export declare interface GroundingChunk {
914
+ /**
915
+ * Contains details if the grounding chunk is from a web source.
916
+ */
917
+ web?: WebGroundingChunk;
918
+ }
919
+
920
+ /**
921
+ * Metadata returned when grounding is enabled.
922
+ *
923
+ * Currently, only Grounding with Google Search is supported (see {@link GoogleSearchTool}).
924
+ *
925
+ * Important: If using Grounding with Google Search, you are required to comply with the
926
+ * "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}
927
+ * or Vertex AI Gemini API (see {@link https://cloud.google.com/terms/service-terms | Service Terms}
928
+ * section within the Service Specific Terms).
929
+ *
873
930
  * @public
874
931
  */
875
932
  export declare interface GroundingMetadata {
933
+ /**
934
+ * Google Search entry point for web searches. This contains an HTML/CSS snippet that must be
935
+ * embedded in an app to display a Google Search entry point for follow-up web searches related to
936
+ * a model's “Grounded Response”.
937
+ */
938
+ searchEntryPoint?: SearchEntrypoint;
939
+ /**
940
+ * A list of {@link GroundingChunk} objects. Each chunk represents a piece of retrieved content
941
+ * (for example, from a web page). that the model used to ground its response.
942
+ */
943
+ groundingChunks?: GroundingChunk[];
944
+ /**
945
+ * A list of {@link GroundingSupport} objects. Each object details how specific segments of the
946
+ * model's response are supported by the `groundingChunks`.
947
+ */
948
+ groundingSupports?: GroundingSupport[];
949
+ /**
950
+ * A list of web search queries that the model performed to gather the grounding information.
951
+ * These can be used to allow users to explore the search results themselves.
952
+ */
876
953
  webSearchQueries?: string[];
954
+ /**
955
+ * @deprecated Use {@link GroundingSupport} instead.
956
+ */
877
957
  retrievalQueries?: string[];
878
958
  /**
879
- * @deprecated
959
+ * @deprecated Use {@link GroundingChunk} instead.
880
960
  */
881
961
  groundingAttributions: GroundingAttribution[];
882
962
  }
883
963
 
964
+ /**
965
+ * Provides information about how a specific segment of the model's response is supported by the
966
+ * retrieved grounding chunks.
967
+ *
968
+ * @public
969
+ */
970
+ export declare interface GroundingSupport {
971
+ /**
972
+ * Specifies the segment of the model's response content that this grounding support pertains to.
973
+ */
974
+ segment?: Segment;
975
+ /**
976
+ * A list of indices that refer to specific {@link GroundingChunk} objects within the
977
+ * {@link GroundingMetadata.groundingChunks} array. These referenced chunks
978
+ * are the sources that support the claim made in the associated `segment` of the response.
979
+ * For example, an array `[1, 3, 4]` means that `groundingChunks[1]`, `groundingChunks[3]`,
980
+ * and `groundingChunks[4]` are the retrieved content supporting this part of the response.
981
+ */
982
+ groundingChunkIndices?: number[];
983
+ }
984
+
884
985
  /**
885
986
  * This property is not supported in the Gemini Developer API ({@link GoogleAIBackend}).
886
987
  *
@@ -1499,12 +1600,20 @@ export declare class ObjectSchema extends Schema {
1499
1600
  }
1500
1601
 
1501
1602
  /**
1502
- * Interface for {@link ObjectSchema} class.
1603
+ * Interface for JSON parameters in {@link SchemaType.OBJECT} format when
1604
+ * not using the {@link ObjectSchema} helper.
1503
1605
  * @public
1504
1606
  */
1505
- export declare interface ObjectSchemaInterface extends SchemaInterface {
1607
+ export declare interface ObjectSchemaRequest extends SchemaRequest {
1506
1608
  type: SchemaType.OBJECT;
1507
- optionalProperties?: string[];
1609
+ /**
1610
+ * This is not a property accepted in the final request to the backend, but is
1611
+ * a client-side convenience property that is only usable by constructing
1612
+ * a schema through the `Schema.object()` helper method. Populating this
1613
+ * property will cause response errors if the object is not wrapped with
1614
+ * `Schema.object()`.
1615
+ */
1616
+ optionalProperties?: never;
1508
1617
  }
1509
1618
 
1510
1619
  /**
@@ -1829,12 +1938,58 @@ export declare enum SchemaType {
1829
1938
  }
1830
1939
 
1831
1940
  /**
1941
+ * Google search entry point.
1942
+ *
1943
+ * @public
1944
+ */
1945
+ export declare interface SearchEntrypoint {
1946
+ /**
1947
+ * HTML/CSS snippet that must be embedded in a web page. The snippet is designed to avoid
1948
+ * undesired interaction with the rest of the page's CSS.
1949
+ *
1950
+ * To ensure proper rendering and prevent CSS conflicts, it is recommended
1951
+ * to encapsulate this `renderedContent` within a shadow DOM when embedding it
1952
+ * into a webpage. See {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_shadow_DOM | MDN: Using shadow DOM}.
1953
+ *
1954
+ * @example
1955
+ * ```javascript
1956
+ * const container = document.createElement('div');
1957
+ * document.body.appendChild(container);
1958
+ * container.attachShadow({ mode: 'open' }).innerHTML = renderedContent;
1959
+ * ```
1960
+ */
1961
+ renderedContent?: string;
1962
+ }
1963
+
1964
+ /**
1965
+ * Represents a specific segment within a {@link Content} object, often used to
1966
+ * pinpoint the exact location of text or data that grounding information refers to.
1967
+ *
1832
1968
  * @public
1833
1969
  */
1834
1970
  export declare interface Segment {
1971
+ /**
1972
+ * The zero-based index of the {@link Part} object within the `parts` array
1973
+ * of its parent {@link Content} object. This identifies which part of the
1974
+ * content the segment belongs to.
1975
+ */
1835
1976
  partIndex: number;
1977
+ /**
1978
+ * The zero-based start index of the segment within the specified `Part`,
1979
+ * measured in UTF-8 bytes. This offset is inclusive, starting from 0 at the
1980
+ * beginning of the part's content (e.g., `Part.text`).
1981
+ */
1836
1982
  startIndex: number;
1983
+ /**
1984
+ * The zero-based end index of the segment within the specified `Part`,
1985
+ * measured in UTF-8 bytes. This offset is exclusive, meaning the character
1986
+ * at this index is not included in the segment.
1987
+ */
1837
1988
  endIndex: number;
1989
+ /**
1990
+ * The text corresponding to the segment from the response.
1991
+ */
1992
+ text: string;
1838
1993
  }
1839
1994
 
1840
1995
  /**
@@ -1874,7 +2029,7 @@ export declare interface TextPart {
1874
2029
  * Defines a tool that model can call to access external knowledge.
1875
2030
  * @public
1876
2031
  */
1877
- export declare type Tool = FunctionDeclarationsTool;
2032
+ export declare type Tool = FunctionDeclarationsTool | GoogleSearchTool;
1878
2033
 
1879
2034
  /**
1880
2035
  * Tool config. This config is shared for all tools provided in the request.
@@ -1995,4 +2150,31 @@ export declare interface WebAttribution {
1995
2150
  title: string;
1996
2151
  }
1997
2152
 
2153
+ /**
2154
+ * A grounding chunk from the web.
2155
+ *
2156
+ * Important: If using Grounding with Google Search, you are required to comply with the
2157
+ * {@link https://cloud.google.com/terms/service-terms | Service Specific Terms} for "Grounding with Google Search".
2158
+ *
2159
+ * @public
2160
+ */
2161
+ export declare interface WebGroundingChunk {
2162
+ /**
2163
+ * The URI of the retrieved web page.
2164
+ */
2165
+ uri?: string;
2166
+ /**
2167
+ * The title of the retrieved web page.
2168
+ */
2169
+ title?: string;
2170
+ /**
2171
+ * The domain of the original URI from which the content was retrieved.
2172
+ *
2173
+ * This property is only supported in the Vertex AI Gemini API ({@link VertexAIBackend}).
2174
+ * When using the Gemini Developer API ({@link GoogleAIBackend}), this property will be
2175
+ * `undefined`.
2176
+ */
2177
+ domain?: string;
2178
+ }
2179
+
1998
2180
  export { }
package/dist/ai.d.ts CHANGED
@@ -605,7 +605,7 @@ export declare interface FunctionDeclaration {
605
605
  * format. Reflects the Open API 3.03 Parameter Object. Parameter names are
606
606
  * case-sensitive. For a function with no parameters, this can be left unset.
607
607
  */
608
- parameters?: ObjectSchemaInterface;
608
+ parameters?: ObjectSchema | ObjectSchemaRequest;
609
609
  }
610
610
 
611
611
  /**
@@ -928,6 +928,42 @@ export declare interface GoogleAIGenerateContentResponse {
928
928
  usageMetadata?: UsageMetadata;
929
929
  }
930
930
 
931
+ /**
932
+ * Specifies the Google Search configuration.
933
+ *
934
+ * @remarks Currently, this is an empty object, but it's reserved for future configuration options.
935
+ *
936
+ * @public
937
+ */
938
+ export declare interface GoogleSearch {
939
+ }
940
+
941
+ /**
942
+ * A tool that allows a Gemini model to connect to Google Search to access and incorporate
943
+ * up-to-date information from the web into its responses.
944
+ *
945
+ * Important: If using Grounding with Google Search, you are required to comply with the
946
+ * "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}
947
+ * or Vertex AI Gemini API (see {@link https://cloud.google.com/terms/service-terms | Service Terms}
948
+ * section within the Service Specific Terms).
949
+ *
950
+ * @public
951
+ */
952
+ export declare interface GoogleSearchTool {
953
+ /**
954
+ * Specifies the Google Search configuration.
955
+ * Currently, this is an empty object, but it's reserved for future configuration options.
956
+ * Specifies the Google Search configuration. Currently, this is an empty object, but it's
957
+ * reserved for future configuration options.
958
+ *
959
+ * When using this feature, you are required to comply with the "Grounding with Google Search"
960
+ * usage requirements for your chosen API provider: {@link https://ai.google.dev/gemini-api/terms#grounding-with-google-search | Gemini Developer API}
961
+ * or Vertex AI Gemini API (see {@link https://cloud.google.com/terms/service-terms | Service Terms}
962
+ * section within the Service Specific Terms).
963
+ */
964
+ googleSearch: GoogleSearch;
965
+ }
966
+
931
967
  /**
932
968
  * @deprecated
933
969
  * @public
@@ -940,18 +976,83 @@ export declare interface GroundingAttribution {
940
976
  }
941
977
 
942
978
  /**
943
- * Metadata returned to client when grounding is enabled.
979
+ * Represents a chunk of retrieved data that supports a claim in the model's response. This is part
980
+ * of the grounding information provided when grounding is enabled.
981
+ *
982
+ * @public
983
+ */
984
+ export declare interface GroundingChunk {
985
+ /**
986
+ * Contains details if the grounding chunk is from a web source.
987
+ */
988
+ web?: WebGroundingChunk;
989
+ }
990
+
991
+ /**
992
+ * Metadata returned when grounding is enabled.
993
+ *
994
+ * Currently, only Grounding with Google Search is supported (see {@link GoogleSearchTool}).
995
+ *
996
+ * Important: If using Grounding with Google Search, you are required to comply with the
997
+ * "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}
998
+ * or Vertex AI Gemini API (see {@link https://cloud.google.com/terms/service-terms | Service Terms}
999
+ * section within the Service Specific Terms).
1000
+ *
944
1001
  * @public
945
1002
  */
946
1003
  export declare interface GroundingMetadata {
1004
+ /**
1005
+ * Google Search entry point for web searches. This contains an HTML/CSS snippet that must be
1006
+ * embedded in an app to display a Google Search entry point for follow-up web searches related to
1007
+ * a model's “Grounded Response”.
1008
+ */
1009
+ searchEntryPoint?: SearchEntrypoint;
1010
+ /**
1011
+ * A list of {@link GroundingChunk} objects. Each chunk represents a piece of retrieved content
1012
+ * (for example, from a web page). that the model used to ground its response.
1013
+ */
1014
+ groundingChunks?: GroundingChunk[];
1015
+ /**
1016
+ * A list of {@link GroundingSupport} objects. Each object details how specific segments of the
1017
+ * model's response are supported by the `groundingChunks`.
1018
+ */
1019
+ groundingSupports?: GroundingSupport[];
1020
+ /**
1021
+ * A list of web search queries that the model performed to gather the grounding information.
1022
+ * These can be used to allow users to explore the search results themselves.
1023
+ */
947
1024
  webSearchQueries?: string[];
1025
+ /**
1026
+ * @deprecated Use {@link GroundingSupport} instead.
1027
+ */
948
1028
  retrievalQueries?: string[];
949
1029
  /**
950
- * @deprecated
1030
+ * @deprecated Use {@link GroundingChunk} instead.
951
1031
  */
952
1032
  groundingAttributions: GroundingAttribution[];
953
1033
  }
954
1034
 
1035
+ /**
1036
+ * Provides information about how a specific segment of the model's response is supported by the
1037
+ * retrieved grounding chunks.
1038
+ *
1039
+ * @public
1040
+ */
1041
+ export declare interface GroundingSupport {
1042
+ /**
1043
+ * Specifies the segment of the model's response content that this grounding support pertains to.
1044
+ */
1045
+ segment?: Segment;
1046
+ /**
1047
+ * A list of indices that refer to specific {@link GroundingChunk} objects within the
1048
+ * {@link GroundingMetadata.groundingChunks} array. These referenced chunks
1049
+ * are the sources that support the claim made in the associated `segment` of the response.
1050
+ * For example, an array `[1, 3, 4]` means that `groundingChunks[1]`, `groundingChunks[3]`,
1051
+ * and `groundingChunks[4]` are the retrieved content supporting this part of the response.
1052
+ */
1053
+ groundingChunkIndices?: number[];
1054
+ }
1055
+
955
1056
  /**
956
1057
  * This property is not supported in the Gemini Developer API ({@link GoogleAIBackend}).
957
1058
  *
@@ -1592,12 +1693,20 @@ export declare class ObjectSchema extends Schema {
1592
1693
  }
1593
1694
 
1594
1695
  /**
1595
- * Interface for {@link ObjectSchema} class.
1696
+ * Interface for JSON parameters in {@link SchemaType.OBJECT} format when
1697
+ * not using the {@link ObjectSchema} helper.
1596
1698
  * @public
1597
1699
  */
1598
- export declare interface ObjectSchemaInterface extends SchemaInterface {
1700
+ export declare interface ObjectSchemaRequest extends SchemaRequest {
1599
1701
  type: SchemaType.OBJECT;
1600
- optionalProperties?: string[];
1702
+ /**
1703
+ * This is not a property accepted in the final request to the backend, but is
1704
+ * a client-side convenience property that is only usable by constructing
1705
+ * a schema through the `Schema.object()` helper method. Populating this
1706
+ * property will cause response errors if the object is not wrapped with
1707
+ * `Schema.object()`.
1708
+ */
1709
+ optionalProperties?: never;
1601
1710
  }
1602
1711
 
1603
1712
  /**
@@ -1927,12 +2036,58 @@ export declare enum SchemaType {
1927
2036
  }
1928
2037
 
1929
2038
  /**
2039
+ * Google search entry point.
2040
+ *
2041
+ * @public
2042
+ */
2043
+ export declare interface SearchEntrypoint {
2044
+ /**
2045
+ * HTML/CSS snippet that must be embedded in a web page. The snippet is designed to avoid
2046
+ * undesired interaction with the rest of the page's CSS.
2047
+ *
2048
+ * To ensure proper rendering and prevent CSS conflicts, it is recommended
2049
+ * to encapsulate this `renderedContent` within a shadow DOM when embedding it
2050
+ * into a webpage. See {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_shadow_DOM | MDN: Using shadow DOM}.
2051
+ *
2052
+ * @example
2053
+ * ```javascript
2054
+ * const container = document.createElement('div');
2055
+ * document.body.appendChild(container);
2056
+ * container.attachShadow({ mode: 'open' }).innerHTML = renderedContent;
2057
+ * ```
2058
+ */
2059
+ renderedContent?: string;
2060
+ }
2061
+
2062
+ /**
2063
+ * Represents a specific segment within a {@link Content} object, often used to
2064
+ * pinpoint the exact location of text or data that grounding information refers to.
2065
+ *
1930
2066
  * @public
1931
2067
  */
1932
2068
  export declare interface Segment {
2069
+ /**
2070
+ * The zero-based index of the {@link Part} object within the `parts` array
2071
+ * of its parent {@link Content} object. This identifies which part of the
2072
+ * content the segment belongs to.
2073
+ */
1933
2074
  partIndex: number;
2075
+ /**
2076
+ * The zero-based start index of the segment within the specified `Part`,
2077
+ * measured in UTF-8 bytes. This offset is inclusive, starting from 0 at the
2078
+ * beginning of the part's content (e.g., `Part.text`).
2079
+ */
1934
2080
  startIndex: number;
2081
+ /**
2082
+ * The zero-based end index of the segment within the specified `Part`,
2083
+ * measured in UTF-8 bytes. This offset is exclusive, meaning the character
2084
+ * at this index is not included in the segment.
2085
+ */
1935
2086
  endIndex: number;
2087
+ /**
2088
+ * The text corresponding to the segment from the response.
2089
+ */
2090
+ text: string;
1936
2091
  }
1937
2092
 
1938
2093
  /**
@@ -1975,7 +2130,7 @@ export declare interface TextPart {
1975
2130
  * Defines a tool that model can call to access external knowledge.
1976
2131
  * @public
1977
2132
  */
1978
- export declare type Tool = FunctionDeclarationsTool;
2133
+ export declare type Tool = FunctionDeclarationsTool | GoogleSearchTool;
1979
2134
 
1980
2135
  /**
1981
2136
  * Tool config. This config is shared for all tools provided in the request.
@@ -2096,4 +2251,31 @@ export declare interface WebAttribution {
2096
2251
  title: string;
2097
2252
  }
2098
2253
 
2254
+ /**
2255
+ * A grounding chunk from the web.
2256
+ *
2257
+ * Important: If using Grounding with Google Search, you are required to comply with the
2258
+ * {@link https://cloud.google.com/terms/service-terms | Service Specific Terms} for "Grounding with Google Search".
2259
+ *
2260
+ * @public
2261
+ */
2262
+ export declare interface WebGroundingChunk {
2263
+ /**
2264
+ * The URI of the retrieved web page.
2265
+ */
2266
+ uri?: string;
2267
+ /**
2268
+ * The title of the retrieved web page.
2269
+ */
2270
+ title?: string;
2271
+ /**
2272
+ * The domain of the original URI from which the content was retrieved.
2273
+ *
2274
+ * This property is only supported in the Vertex AI Gemini API ({@link VertexAIBackend}).
2275
+ * When using the Gemini Developer API ({@link GoogleAIBackend}), this property will be
2276
+ * `undefined`.
2277
+ */
2278
+ domain?: string;
2279
+ }
2280
+
2099
2281
  export { }
@@ -5,7 +5,7 @@ import { Logger } from '@firebase/logger';
5
5
  import { __asyncGenerator, __await } from 'tslib';
6
6
 
7
7
  var name = "@firebase/ai";
8
- var version = "1.4.0-canary.86155b3c8";
8
+ var version = "1.4.0-canary.91fa484b5";
9
9
 
10
10
  /**
11
11
  * @license
@@ -996,6 +996,7 @@ async function makeRequest(model, task, apiSettings, stream, body, requestOption
996
996
  // ignored
997
997
  }
998
998
  if (response.status === 403 &&
999
+ errorDetails &&
999
1000
  errorDetails.some((detail) => detail.reason === 'SERVICE_DISABLED') &&
1000
1001
  errorDetails.some((detail) => {
1001
1002
  var _a, _b;
@@ -1575,6 +1576,8 @@ function aggregateResponses(responses) {
1575
1576
  candidate.finishMessage;
1576
1577
  aggregatedResponse.candidates[i].safetyRatings =
1577
1578
  candidate.safetyRatings;
1579
+ aggregatedResponse.candidates[i].groundingMetadata =
1580
+ candidate.groundingMetadata;
1578
1581
  /**
1579
1582
  * Candidates should always have content and parts, but this handles
1580
1583
  * possible malformed responses.