@firebase/ai 1.4.1-canary.2d720995d → 1.4.1-canary.5200f7bb7

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.
@@ -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.5200f7bb7";
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;