@firebase/ai 1.4.1-canary.2d720995d → 1.4.1-canary.a9be6757f

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.
@@ -129,6 +129,19 @@ export declare interface AIOptions {
129
129
  backend: Backend;
130
130
  }
131
131
 
132
+ /**
133
+ * Schema class representing a value that can conform to any of the provided sub-schemas. This is
134
+ * useful when a field can accept multiple distinct types or structures.
135
+ * @public
136
+ */
137
+ export declare class AnyOfSchema extends Schema {
138
+ anyOf: TypedSchema[];
139
+ constructor(schemaParams: SchemaParams & {
140
+ anyOf: TypedSchema[];
141
+ });
142
+ /* Excluded from this release type: toJSON */
143
+ }
144
+
132
145
  declare interface ApiSettings {
133
146
  apiKey: string;
134
147
  project: string;
@@ -720,7 +733,7 @@ export declare interface GenerationConfig {
720
733
  * value can be a class generated with a {@link Schema} static method
721
734
  * like `Schema.string()` or `Schema.object()` or it can be a plain
722
735
  * JS object matching the {@link SchemaRequest} interface.
723
- * <br/>Note: This only applies when the specified `responseMIMEType` supports a schema; currently
736
+ * <br/>Note: This only applies when the specified `responseMimeType` supports a schema; currently
724
737
  * this is limited to `application/json` and `text/x.enum`.
725
738
  */
726
739
  responseSchema?: TypedSchema | SchemaRequest;
@@ -900,17 +913,6 @@ export declare interface GoogleSearchTool {
900
913
  googleSearch: GoogleSearch;
901
914
  }
902
915
 
903
- /**
904
- * @deprecated
905
- * @public
906
- */
907
- export declare interface GroundingAttribution {
908
- segment: Segment;
909
- confidenceScore?: number;
910
- web?: WebAttribution;
911
- retrievedContext?: RetrievedContextAttribution;
912
- }
913
-
914
916
  /**
915
917
  * Represents a chunk of retrieved data that supports a claim in the model's response. This is part
916
918
  * of the grounding information provided when grounding is enabled.
@@ -962,10 +964,6 @@ export declare interface GroundingMetadata {
962
964
  * @deprecated Use {@link GroundingSupport} instead.
963
965
  */
964
966
  retrievalQueries?: string[];
965
- /**
966
- * @deprecated Use {@link GroundingChunk} instead.
967
- */
968
- groundingAttributions: GroundingAttribution[];
969
967
  }
970
968
 
971
969
  /**
@@ -1853,10 +1851,11 @@ export declare interface SafetySetting {
1853
1851
  */
1854
1852
  export declare abstract class Schema implements SchemaInterface {
1855
1853
  /**
1856
- * Optional. The type of the property. {@link
1857
- * (SchemaType:type)}.
1854
+ * Optional. The type of the property.
1855
+ * This can only be undefined when using `anyOf` schemas, which do not have an
1856
+ * explicit type in the {@link https://swagger.io/docs/specification/v3_0/data-models/data-types/#any-type | OpenAPI specification}.
1858
1857
  */
1859
- type: SchemaType;
1858
+ type?: SchemaType;
1860
1859
  /** Optional. The format of the property.
1861
1860
  * Supported formats:<br/>
1862
1861
  * <ul>
@@ -1901,6 +1900,9 @@ export declare abstract class Schema implements SchemaInterface {
1901
1900
  static integer(integerParams?: SchemaParams): IntegerSchema;
1902
1901
  static number(numberParams?: SchemaParams): NumberSchema;
1903
1902
  static boolean(booleanParams?: SchemaParams): BooleanSchema;
1903
+ static anyOf(anyOfParams: SchemaParams & {
1904
+ anyOf: TypedSchema[];
1905
+ }): AnyOfSchema;
1904
1906
  }
1905
1907
 
1906
1908
  /**
@@ -1909,10 +1911,10 @@ export declare abstract class Schema implements SchemaInterface {
1909
1911
  */
1910
1912
  export declare interface SchemaInterface extends SchemaShared<SchemaInterface> {
1911
1913
  /**
1912
- * The type of the property. {@link
1913
- * (SchemaType:type)}.
1914
+ * The type of the property. this can only be undefined when using `anyof` schemas,
1915
+ * which do not have an explicit type in the {@link https://swagger.io/docs/specification/v3_0/data-models/data-types/#any-type | OpenAPI Specification}.
1914
1916
  */
1915
- type: SchemaType;
1917
+ type?: SchemaType;
1916
1918
  }
1917
1919
 
1918
1920
  /**
@@ -1929,10 +1931,10 @@ export declare interface SchemaParams extends SchemaShared<SchemaInterface> {
1929
1931
  */
1930
1932
  export declare interface SchemaRequest extends SchemaShared<SchemaRequest> {
1931
1933
  /**
1932
- * The type of the property. {@link
1933
- * (SchemaType:type)}.
1934
+ * The type of the property. this can only be undefined when using `anyOf` schemas,
1935
+ * which do not have an explicit type in the {@link https://swagger.io/docs/specification/v3_0/data-models/data-types/#any-type | OpenAPI specification }.
1934
1936
  */
1935
- type: SchemaType;
1937
+ type?: SchemaType;
1936
1938
  /** Optional. Array of required property. */
1937
1939
  required?: string[];
1938
1940
  }
@@ -1943,6 +1945,12 @@ export declare interface SchemaRequest extends SchemaShared<SchemaRequest> {
1943
1945
  * @public
1944
1946
  */
1945
1947
  export declare interface SchemaShared<T> {
1948
+ /**
1949
+ * An array of {@link Schema}. The generated data must be valid against any of the schemas
1950
+ * listed in this array. This allows specifying multiple possible structures or types for a
1951
+ * single field.
1952
+ */
1953
+ anyOf?: T[];
1946
1954
  /** Optional. The format of the property.
1947
1955
  * When using the Gemini Developer API ({@link GoogleAIBackend}), this must be either `'enum'` or
1948
1956
  * `'date-time'`, otherwise requests will fail.
@@ -2141,7 +2149,7 @@ export declare interface ToolConfig {
2141
2149
  * A type that includes all specific Schema types.
2142
2150
  * @public
2143
2151
  */
2144
- export declare type TypedSchema = IntegerSchema | NumberSchema | StringSchema | BooleanSchema | ObjectSchema | ArraySchema;
2152
+ export declare type TypedSchema = IntegerSchema | NumberSchema | StringSchema | BooleanSchema | ObjectSchema | ArraySchema | AnyOfSchema;
2145
2153
 
2146
2154
  /**
2147
2155
  * Usage metadata about a {@link GenerateContentResponse}.
package/dist/ai.d.ts CHANGED
@@ -163,6 +163,22 @@ export declare interface AIOptions {
163
163
  backend: Backend;
164
164
  }
165
165
 
166
+ /**
167
+ * Schema class representing a value that can conform to any of the provided sub-schemas. This is
168
+ * useful when a field can accept multiple distinct types or structures.
169
+ * @public
170
+ */
171
+ export declare class AnyOfSchema extends Schema {
172
+ anyOf: TypedSchema[];
173
+ constructor(schemaParams: SchemaParams & {
174
+ anyOf: TypedSchema[];
175
+ });
176
+ /**
177
+ * @internal
178
+ */
179
+ toJSON(): SchemaRequest;
180
+ }
181
+
166
182
  declare interface ApiSettings {
167
183
  apiKey: string;
168
184
  project: string;
@@ -757,7 +773,7 @@ export declare interface GenerationConfig {
757
773
  * value can be a class generated with a {@link Schema} static method
758
774
  * like `Schema.string()` or `Schema.object()` or it can be a plain
759
775
  * JS object matching the {@link SchemaRequest} interface.
760
- * <br/>Note: This only applies when the specified `responseMIMEType` supports a schema; currently
776
+ * <br/>Note: This only applies when the specified `responseMimeType` supports a schema; currently
761
777
  * this is limited to `application/json` and `text/x.enum`.
762
778
  */
763
779
  responseSchema?: TypedSchema | SchemaRequest;
@@ -971,17 +987,6 @@ export declare interface GoogleSearchTool {
971
987
  googleSearch: GoogleSearch;
972
988
  }
973
989
 
974
- /**
975
- * @deprecated
976
- * @public
977
- */
978
- export declare interface GroundingAttribution {
979
- segment: Segment;
980
- confidenceScore?: number;
981
- web?: WebAttribution;
982
- retrievedContext?: RetrievedContextAttribution;
983
- }
984
-
985
990
  /**
986
991
  * Represents a chunk of retrieved data that supports a claim in the model's response. This is part
987
992
  * of the grounding information provided when grounding is enabled.
@@ -1033,10 +1038,6 @@ export declare interface GroundingMetadata {
1033
1038
  * @deprecated Use {@link GroundingSupport} instead.
1034
1039
  */
1035
1040
  retrievalQueries?: string[];
1036
- /**
1037
- * @deprecated Use {@link GroundingChunk} instead.
1038
- */
1039
- groundingAttributions: GroundingAttribution[];
1040
1041
  }
1041
1042
 
1042
1043
  /**
@@ -1946,10 +1947,11 @@ export declare interface SafetySetting {
1946
1947
  */
1947
1948
  export declare abstract class Schema implements SchemaInterface {
1948
1949
  /**
1949
- * Optional. The type of the property. {@link
1950
- * (SchemaType:type)}.
1950
+ * Optional. The type of the property.
1951
+ * This can only be undefined when using `anyOf` schemas, which do not have an
1952
+ * explicit type in the {@link https://swagger.io/docs/specification/v3_0/data-models/data-types/#any-type | OpenAPI specification}.
1951
1953
  */
1952
- type: SchemaType;
1954
+ type?: SchemaType;
1953
1955
  /** Optional. The format of the property.
1954
1956
  * Supported formats:<br/>
1955
1957
  * <ul>
@@ -1999,6 +2001,9 @@ export declare abstract class Schema implements SchemaInterface {
1999
2001
  static integer(integerParams?: SchemaParams): IntegerSchema;
2000
2002
  static number(numberParams?: SchemaParams): NumberSchema;
2001
2003
  static boolean(booleanParams?: SchemaParams): BooleanSchema;
2004
+ static anyOf(anyOfParams: SchemaParams & {
2005
+ anyOf: TypedSchema[];
2006
+ }): AnyOfSchema;
2002
2007
  }
2003
2008
 
2004
2009
  /**
@@ -2007,10 +2012,10 @@ export declare abstract class Schema implements SchemaInterface {
2007
2012
  */
2008
2013
  export declare interface SchemaInterface extends SchemaShared<SchemaInterface> {
2009
2014
  /**
2010
- * The type of the property. {@link
2011
- * (SchemaType:type)}.
2015
+ * The type of the property. this can only be undefined when using `anyof` schemas,
2016
+ * which do not have an explicit type in the {@link https://swagger.io/docs/specification/v3_0/data-models/data-types/#any-type | OpenAPI Specification}.
2012
2017
  */
2013
- type: SchemaType;
2018
+ type?: SchemaType;
2014
2019
  }
2015
2020
 
2016
2021
  /**
@@ -2027,10 +2032,10 @@ export declare interface SchemaParams extends SchemaShared<SchemaInterface> {
2027
2032
  */
2028
2033
  export declare interface SchemaRequest extends SchemaShared<SchemaRequest> {
2029
2034
  /**
2030
- * The type of the property. {@link
2031
- * (SchemaType:type)}.
2035
+ * The type of the property. this can only be undefined when using `anyOf` schemas,
2036
+ * which do not have an explicit type in the {@link https://swagger.io/docs/specification/v3_0/data-models/data-types/#any-type | OpenAPI specification }.
2032
2037
  */
2033
- type: SchemaType;
2038
+ type?: SchemaType;
2034
2039
  /** Optional. Array of required property. */
2035
2040
  required?: string[];
2036
2041
  }
@@ -2041,6 +2046,12 @@ export declare interface SchemaRequest extends SchemaShared<SchemaRequest> {
2041
2046
  * @public
2042
2047
  */
2043
2048
  export declare interface SchemaShared<T> {
2049
+ /**
2050
+ * An array of {@link Schema}. The generated data must be valid against any of the schemas
2051
+ * listed in this array. This allows specifying multiple possible structures or types for a
2052
+ * single field.
2053
+ */
2054
+ anyOf?: T[];
2044
2055
  /** Optional. The format of the property.
2045
2056
  * When using the Gemini Developer API ({@link GoogleAIBackend}), this must be either `'enum'` or
2046
2057
  * `'date-time'`, otherwise requests will fail.
@@ -2242,7 +2253,7 @@ export declare interface ToolConfig {
2242
2253
  * A type that includes all specific Schema types.
2243
2254
  * @public
2244
2255
  */
2245
- export declare type TypedSchema = IntegerSchema | NumberSchema | StringSchema | BooleanSchema | ObjectSchema | ArraySchema;
2256
+ export declare type TypedSchema = IntegerSchema | NumberSchema | StringSchema | BooleanSchema | ObjectSchema | ArraySchema | AnyOfSchema;
2246
2257
 
2247
2258
  /**
2248
2259
  * Usage metadata about a {@link GenerateContentResponse}.
@@ -4,7 +4,7 @@ import { FirebaseError, getModularInstance } from '@firebase/util';
4
4
  import { Logger } from '@firebase/logger';
5
5
 
6
6
  var name = "@firebase/ai";
7
- var version = "1.4.1-canary.2d720995d";
7
+ var version = "1.4.1-canary.a9be6757f";
8
8
 
9
9
  /**
10
10
  * @license
@@ -2307,12 +2307,19 @@ class ImagenModel extends AIModel {
2307
2307
  */
2308
2308
  class Schema {
2309
2309
  constructor(schemaParams) {
2310
+ // TODO(dlarocque): Enforce this with union types
2311
+ if (!schemaParams.type && !schemaParams.anyOf) {
2312
+ throw new AIError(AIErrorCode.INVALID_SCHEMA, "A schema must have either a 'type' or an 'anyOf' array of sub-schemas.");
2313
+ }
2310
2314
  // eslint-disable-next-line guard-for-in
2311
2315
  for (const paramKey in schemaParams) {
2312
2316
  this[paramKey] = schemaParams[paramKey];
2313
2317
  }
2314
2318
  // Ensure these are explicitly set to avoid TS errors.
2315
2319
  this.type = schemaParams.type;
2320
+ this.format = schemaParams.hasOwnProperty('format')
2321
+ ? schemaParams.format
2322
+ : undefined;
2316
2323
  this.nullable = schemaParams.hasOwnProperty('nullable')
2317
2324
  ? !!schemaParams.nullable
2318
2325
  : false;
@@ -2359,6 +2366,9 @@ class Schema {
2359
2366
  static boolean(booleanParams) {
2360
2367
  return new BooleanSchema(booleanParams);
2361
2368
  }
2369
+ static anyOf(anyOfParams) {
2370
+ return new AnyOfSchema(anyOfParams);
2371
+ }
2362
2372
  }
2363
2373
  /**
2364
2374
  * Schema class for "integer" types.
@@ -2486,6 +2496,34 @@ class ObjectSchema extends Schema {
2486
2496
  return obj;
2487
2497
  }
2488
2498
  }
2499
+ /**
2500
+ * Schema class representing a value that can conform to any of the provided sub-schemas. This is
2501
+ * useful when a field can accept multiple distinct types or structures.
2502
+ * @public
2503
+ */
2504
+ class AnyOfSchema extends Schema {
2505
+ constructor(schemaParams) {
2506
+ if (schemaParams.anyOf.length === 0) {
2507
+ throw new AIError(AIErrorCode.INVALID_SCHEMA, "The 'anyOf' array must not be empty.");
2508
+ }
2509
+ super({
2510
+ ...schemaParams,
2511
+ type: undefined // anyOf schemas do not have an explicit type
2512
+ });
2513
+ this.anyOf = schemaParams.anyOf;
2514
+ }
2515
+ /**
2516
+ * @internal
2517
+ */
2518
+ toJSON() {
2519
+ const obj = super.toJSON();
2520
+ // Ensure the 'anyOf' property contains serialized SchemaRequest objects.
2521
+ if (this.anyOf && Array.isArray(this.anyOf)) {
2522
+ obj.anyOf = this.anyOf.map(s => s.toJSON());
2523
+ }
2524
+ return obj;
2525
+ }
2526
+ }
2489
2527
 
2490
2528
  /**
2491
2529
  * @license
@@ -2660,5 +2698,5 @@ function registerAI() {
2660
2698
  }
2661
2699
  registerAI();
2662
2700
 
2663
- export { AIError, AIErrorCode, AIModel, ArraySchema, Backend, BackendType, BlockReason, BooleanSchema, ChatSession, FinishReason, FunctionCallingMode, GenerativeModel, GoogleAIBackend, HarmBlockMethod, HarmBlockThreshold, HarmCategory, HarmProbability, HarmSeverity, ImagenAspectRatio, ImagenImageFormat, ImagenModel, ImagenPersonFilterLevel, ImagenSafetyFilterLevel, IntegerSchema, Modality, NumberSchema, ObjectSchema, POSSIBLE_ROLES, ResponseModality, Schema, SchemaType, StringSchema, VertexAIBackend, getAI, getGenerativeModel, getImagenModel };
2701
+ export { AIError, AIErrorCode, AIModel, AnyOfSchema, ArraySchema, Backend, BackendType, BlockReason, BooleanSchema, ChatSession, FinishReason, FunctionCallingMode, GenerativeModel, GoogleAIBackend, HarmBlockMethod, HarmBlockThreshold, HarmCategory, HarmProbability, HarmSeverity, ImagenAspectRatio, ImagenImageFormat, ImagenModel, ImagenPersonFilterLevel, ImagenSafetyFilterLevel, IntegerSchema, Modality, NumberSchema, ObjectSchema, POSSIBLE_ROLES, ResponseModality, Schema, SchemaType, StringSchema, VertexAIBackend, getAI, getGenerativeModel, getImagenModel };
2664
2702
  //# sourceMappingURL=index.esm.js.map