@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.
@@ -24,10 +24,11 @@ import { SchemaInterface, SchemaType, SchemaParams, SchemaRequest } from '../typ
24
24
  */
25
25
  export declare abstract class Schema implements SchemaInterface {
26
26
  /**
27
- * Optional. The type of the property. {@link
28
- * (SchemaType:type)}.
27
+ * Optional. The type of the property.
28
+ * This can only be undefined when using `anyOf` schemas, which do not have an
29
+ * explicit type in the {@link https://swagger.io/docs/specification/v3_0/data-models/data-types/#any-type | OpenAPI specification}.
29
30
  */
30
- type: SchemaType;
31
+ type?: SchemaType;
31
32
  /** Optional. The format of the property.
32
33
  * Supported formats:<br/>
33
34
  * <ul>
@@ -77,12 +78,15 @@ export declare abstract class Schema implements SchemaInterface {
77
78
  static integer(integerParams?: SchemaParams): IntegerSchema;
78
79
  static number(numberParams?: SchemaParams): NumberSchema;
79
80
  static boolean(booleanParams?: SchemaParams): BooleanSchema;
81
+ static anyOf(anyOfParams: SchemaParams & {
82
+ anyOf: TypedSchema[];
83
+ }): AnyOfSchema;
80
84
  }
81
85
  /**
82
86
  * A type that includes all specific Schema types.
83
87
  * @public
84
88
  */
85
- export type TypedSchema = IntegerSchema | NumberSchema | StringSchema | BooleanSchema | ObjectSchema | ArraySchema;
89
+ export type TypedSchema = IntegerSchema | NumberSchema | StringSchema | BooleanSchema | ObjectSchema | ArraySchema | AnyOfSchema;
86
90
  /**
87
91
  * Schema class for "integer" types.
88
92
  * @public
@@ -149,3 +153,18 @@ export declare class ObjectSchema extends Schema {
149
153
  */
150
154
  toJSON(): SchemaRequest;
151
155
  }
156
+ /**
157
+ * Schema class representing a value that can conform to any of the provided sub-schemas. This is
158
+ * useful when a field can accept multiple distinct types or structures.
159
+ * @public
160
+ */
161
+ export declare class AnyOfSchema extends Schema {
162
+ anyOf: TypedSchema[];
163
+ constructor(schemaParams: SchemaParams & {
164
+ anyOf: TypedSchema[];
165
+ });
166
+ /**
167
+ * @internal
168
+ */
169
+ toJSON(): SchemaRequest;
170
+ }
@@ -87,7 +87,7 @@ export interface GenerationConfig {
87
87
  * value can be a class generated with a {@link Schema} static method
88
88
  * like `Schema.string()` or `Schema.object()` or it can be a plain
89
89
  * JS object matching the {@link SchemaRequest} interface.
90
- * <br/>Note: This only applies when the specified `responseMIMEType` supports a schema; currently
90
+ * <br/>Note: This only applies when the specified `responseMimeType` supports a schema; currently
91
91
  * this is limited to `application/json` and `text/x.enum`.
92
92
  */
93
93
  responseSchema?: TypedSchema | SchemaRequest;
@@ -192,10 +192,6 @@ export interface GroundingMetadata {
192
192
  * @deprecated Use {@link GroundingSupport} instead.
193
193
  */
194
194
  retrievalQueries?: string[];
195
- /**
196
- * @deprecated Use {@link GroundingChunk} instead.
197
- */
198
- groundingAttributions: GroundingAttribution[];
199
195
  }
200
196
  /**
201
197
  * Google search entry point.
@@ -308,16 +304,6 @@ export interface Segment {
308
304
  */
309
305
  text: string;
310
306
  }
311
- /**
312
- * @deprecated
313
- * @public
314
- */
315
- export interface GroundingAttribution {
316
- segment: Segment;
317
- confidenceScore?: number;
318
- web?: WebAttribution;
319
- retrievedContext?: RetrievedContextAttribution;
320
- }
321
307
  /**
322
308
  * @public
323
309
  */
@@ -47,6 +47,12 @@ export type SchemaType = (typeof SchemaType)[keyof typeof SchemaType];
47
47
  * @public
48
48
  */
49
49
  export interface SchemaShared<T> {
50
+ /**
51
+ * An array of {@link Schema}. The generated data must be valid against any of the schemas
52
+ * listed in this array. This allows specifying multiple possible structures or types for a
53
+ * single field.
54
+ */
55
+ anyOf?: T[];
50
56
  /** Optional. The format of the property.
51
57
  * When using the Gemini Developer API ({@link GoogleAIBackend}), this must be either `'enum'` or
52
58
  * `'date-time'`, otherwise requests will fail.
@@ -97,10 +103,10 @@ export interface SchemaParams extends SchemaShared<SchemaInterface> {
97
103
  */
98
104
  export interface SchemaRequest extends SchemaShared<SchemaRequest> {
99
105
  /**
100
- * The type of the property. {@link
101
- * (SchemaType:type)}.
106
+ * The type of the property. this can only be undefined when using `anyOf` schemas,
107
+ * 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 }.
102
108
  */
103
- type: SchemaType;
109
+ type?: SchemaType;
104
110
  /** Optional. Array of required property. */
105
111
  required?: string[];
106
112
  }
@@ -110,10 +116,10 @@ export interface SchemaRequest extends SchemaShared<SchemaRequest> {
110
116
  */
111
117
  export interface SchemaInterface extends SchemaShared<SchemaInterface> {
112
118
  /**
113
- * The type of the property. {@link
114
- * (SchemaType:type)}.
119
+ * The type of the property. this can only be undefined when using `anyof` schemas,
120
+ * 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}.
115
121
  */
116
- type: SchemaType;
122
+ type?: SchemaType;
117
123
  }
118
124
  /**
119
125
  * Interface for JSON parameters in a schema of {@link SchemaType}
package/dist/index.cjs.js CHANGED
@@ -8,7 +8,7 @@ var util = require('@firebase/util');
8
8
  var logger$1 = require('@firebase/logger');
9
9
 
10
10
  var name = "@firebase/ai";
11
- var version = "1.4.1-canary.2d720995d";
11
+ var version = "1.4.1-canary.a9be6757f";
12
12
 
13
13
  /**
14
14
  * @license
@@ -2311,12 +2311,19 @@ class ImagenModel extends AIModel {
2311
2311
  */
2312
2312
  class Schema {
2313
2313
  constructor(schemaParams) {
2314
+ // TODO(dlarocque): Enforce this with union types
2315
+ if (!schemaParams.type && !schemaParams.anyOf) {
2316
+ throw new AIError(AIErrorCode.INVALID_SCHEMA, "A schema must have either a 'type' or an 'anyOf' array of sub-schemas.");
2317
+ }
2314
2318
  // eslint-disable-next-line guard-for-in
2315
2319
  for (const paramKey in schemaParams) {
2316
2320
  this[paramKey] = schemaParams[paramKey];
2317
2321
  }
2318
2322
  // Ensure these are explicitly set to avoid TS errors.
2319
2323
  this.type = schemaParams.type;
2324
+ this.format = schemaParams.hasOwnProperty('format')
2325
+ ? schemaParams.format
2326
+ : undefined;
2320
2327
  this.nullable = schemaParams.hasOwnProperty('nullable')
2321
2328
  ? !!schemaParams.nullable
2322
2329
  : false;
@@ -2363,6 +2370,9 @@ class Schema {
2363
2370
  static boolean(booleanParams) {
2364
2371
  return new BooleanSchema(booleanParams);
2365
2372
  }
2373
+ static anyOf(anyOfParams) {
2374
+ return new AnyOfSchema(anyOfParams);
2375
+ }
2366
2376
  }
2367
2377
  /**
2368
2378
  * Schema class for "integer" types.
@@ -2490,6 +2500,34 @@ class ObjectSchema extends Schema {
2490
2500
  return obj;
2491
2501
  }
2492
2502
  }
2503
+ /**
2504
+ * Schema class representing a value that can conform to any of the provided sub-schemas. This is
2505
+ * useful when a field can accept multiple distinct types or structures.
2506
+ * @public
2507
+ */
2508
+ class AnyOfSchema extends Schema {
2509
+ constructor(schemaParams) {
2510
+ if (schemaParams.anyOf.length === 0) {
2511
+ throw new AIError(AIErrorCode.INVALID_SCHEMA, "The 'anyOf' array must not be empty.");
2512
+ }
2513
+ super({
2514
+ ...schemaParams,
2515
+ type: undefined // anyOf schemas do not have an explicit type
2516
+ });
2517
+ this.anyOf = schemaParams.anyOf;
2518
+ }
2519
+ /**
2520
+ * @internal
2521
+ */
2522
+ toJSON() {
2523
+ const obj = super.toJSON();
2524
+ // Ensure the 'anyOf' property contains serialized SchemaRequest objects.
2525
+ if (this.anyOf && Array.isArray(this.anyOf)) {
2526
+ obj.anyOf = this.anyOf.map(s => s.toJSON());
2527
+ }
2528
+ return obj;
2529
+ }
2530
+ }
2493
2531
 
2494
2532
  /**
2495
2533
  * @license
@@ -2667,6 +2705,7 @@ registerAI();
2667
2705
  exports.AIError = AIError;
2668
2706
  exports.AIErrorCode = AIErrorCode;
2669
2707
  exports.AIModel = AIModel;
2708
+ exports.AnyOfSchema = AnyOfSchema;
2670
2709
  exports.ArraySchema = ArraySchema;
2671
2710
  exports.Backend = Backend;
2672
2711
  exports.BackendType = BackendType;