Skip to content

Commit 05a30cd

Browse files
authored
Merge 24eb717 into 799de59
2 parents 799de59 + 24eb717 commit 05a30cd

14 files changed

+349
-30
lines changed

.changeset/healthy-moons-type.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'firebase': major
3+
'@firebase/ai': major
4+
---
5+
6+
Add support for `anyOf` schemas

common/api-review/ai.api.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ export interface AIOptions {
6565
backend: Backend;
6666
}
6767

68+
// @public
69+
export class AnyOfSchema extends Schema {
70+
constructor(schemaParams: SchemaParams & {
71+
anyOf: TypedSchema[];
72+
});
73+
// (undocumented)
74+
anyOf: TypedSchema[];
75+
// @internal (undocumented)
76+
toJSON(): SchemaRequest;
77+
}
78+
6879
// @public
6980
export class ArraySchema extends Schema {
7081
constructor(schemaParams: SchemaParams, items: TypedSchema);
@@ -776,6 +787,10 @@ export abstract class Schema implements SchemaInterface {
776787
constructor(schemaParams: SchemaInterface);
777788
[key: string]: unknown;
778789
// (undocumented)
790+
static anyOf(anyOfParams: SchemaParams & {
791+
anyOf: TypedSchema[];
792+
}): AnyOfSchema;
793+
// (undocumented)
779794
static array(arrayParams: SchemaParams & {
780795
items: Schema;
781796
}): ArraySchema;
@@ -804,12 +819,12 @@ export abstract class Schema implements SchemaInterface {
804819
static string(stringParams?: SchemaParams): StringSchema;
805820
// @internal
806821
toJSON(): SchemaRequest;
807-
type: SchemaType;
822+
type?: SchemaType;
808823
}
809824

810825
// @public
811826
export interface SchemaInterface extends SchemaShared<SchemaInterface> {
812-
type: SchemaType;
827+
type?: SchemaType;
813828
}
814829

815830
// @public
@@ -819,13 +834,14 @@ export interface SchemaParams extends SchemaShared<SchemaInterface> {
819834
// @public
820835
export interface SchemaRequest extends SchemaShared<SchemaRequest> {
821836
required?: string[];
822-
type: SchemaType;
837+
type?: SchemaType;
823838
}
824839

825840
// @public
826841
export interface SchemaShared<T> {
827842
// (undocumented)
828843
[key: string]: unknown;
844+
anyOf?: T[];
829845
description?: string;
830846
enum?: string[];
831847
example?: unknown;
@@ -900,7 +916,7 @@ export interface ToolConfig {
900916
}
901917

902918
// @public
903-
export type TypedSchema = IntegerSchema | NumberSchema | StringSchema | BooleanSchema | ObjectSchema | ArraySchema;
919+
export type TypedSchema = IntegerSchema | NumberSchema | StringSchema | BooleanSchema | ObjectSchema | ArraySchema | AnyOfSchema;
904920

905921
// @public
906922
export interface UsageMetadata {

docs-devsite/_toc.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ toc:
1212
path: /docs/reference/js/ai.aimodel.md
1313
- title: AIOptions
1414
path: /docs/reference/js/ai.aioptions.md
15+
- title: AnyOfSchema
16+
path: /docs/reference/js/ai.anyofschema.md
1517
- title: ArraySchema
1618
path: /docs/reference/js/ai.arrayschema.md
1719
- title: Backend

docs-devsite/ai.anyofschema.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
Project: /docs/reference/js/_project.yaml
2+
Book: /docs/reference/_book.yaml
3+
page_type: reference
4+
5+
{% comment %}
6+
DO NOT EDIT THIS FILE!
7+
This is generated by the JS SDK team, and any local changes will be
8+
overwritten. Changes should be made in the source code at
9+
https://github.com/firebase/firebase-js-sdk
10+
{% endcomment %}
11+
12+
# AnyOfSchema class
13+
Schema class representing a value that can conform to any of the provided sub-schemas. This is useful when a field can accept multiple distinct types or structures.
14+
15+
<b>Signature:</b>
16+
17+
```typescript
18+
export declare class AnyOfSchema extends Schema
19+
```
20+
<b>Extends:</b> [Schema](./ai.schema.md#schema_class)
21+
22+
## Constructors
23+
24+
| Constructor | Modifiers | Description |
25+
| --- | --- | --- |
26+
| [(constructor)(schemaParams)](./ai.anyofschema.md#anyofschemaconstructor) | | Constructs a new instance of the <code>AnyOfSchema</code> class |
27+
28+
## Properties
29+
30+
| Property | Modifiers | Type | Description |
31+
| --- | --- | --- | --- |
32+
| [anyOf](./ai.anyofschema.md#anyofschemaanyof) | | [TypedSchema](./ai.md#typedschema)<!-- -->\[\] | |
33+
34+
## AnyOfSchema.(constructor)
35+
36+
Constructs a new instance of the `AnyOfSchema` class
37+
38+
<b>Signature:</b>
39+
40+
```typescript
41+
constructor(schemaParams: SchemaParams & {
42+
anyOf: TypedSchema[];
43+
});
44+
```
45+
46+
#### Parameters
47+
48+
| Parameter | Type | Description |
49+
| --- | --- | --- |
50+
| schemaParams | [SchemaParams](./ai.schemaparams.md#schemaparams_interface) &amp; { anyOf: [TypedSchema](./ai.md#typedschema)<!-- -->\[\]; } | |
51+
52+
## AnyOfSchema.anyOf
53+
54+
<b>Signature:</b>
55+
56+
```typescript
57+
anyOf: TypedSchema[];
58+
```

docs-devsite/ai.generationconfig.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export interface GenerationConfig
2828
| [presencePenalty](./ai.generationconfig.md#generationconfigpresencepenalty) | number | |
2929
| [responseMimeType](./ai.generationconfig.md#generationconfigresponsemimetype) | string | Output response MIME type of the generated candidate text. Supported MIME types are <code>text/plain</code> (default, text output), <code>application/json</code> (JSON response in the candidates), and <code>text/x.enum</code>. |
3030
| [responseModalities](./ai.generationconfig.md#generationconfigresponsemodalities) | [ResponseModality](./ai.md#responsemodality)<!-- -->\[\] | <b><i>(Public Preview)</i></b> Generation modalities to be returned in generation responses. |
31-
| [responseSchema](./ai.generationconfig.md#generationconfigresponseschema) | [TypedSchema](./ai.md#typedschema) \| [SchemaRequest](./ai.schemarequest.md#schemarequest_interface) | Output response schema of the generated candidate text. This value can be a class generated with a [Schema](./ai.schema.md#schema_class) static method like <code>Schema.string()</code> or <code>Schema.object()</code> or it can be a plain JS object matching the [SchemaRequest](./ai.schemarequest.md#schemarequest_interface) interface. <br/>Note: This only applies when the specified <code>responseMIMEType</code> supports a schema; currently this is limited to <code>application/json</code> and <code>text/x.enum</code>. |
31+
| [responseSchema](./ai.generationconfig.md#generationconfigresponseschema) | [TypedSchema](./ai.md#typedschema) \| [SchemaRequest](./ai.schemarequest.md#schemarequest_interface) | Output response schema of the generated candidate text. This value can be a class generated with a [Schema](./ai.schema.md#schema_class) static method like <code>Schema.string()</code> or <code>Schema.object()</code> or it can be a plain JS object matching the [SchemaRequest](./ai.schemarequest.md#schemarequest_interface) interface. <br/>Note: This only applies when the specified <code>responseMimeType</code> supports a schema; currently this is limited to <code>application/json</code> and <code>text/x.enum</code>. |
3232
| [stopSequences](./ai.generationconfig.md#generationconfigstopsequences) | string\[\] | |
3333
| [temperature](./ai.generationconfig.md#generationconfigtemperature) | number | |
3434
| [topK](./ai.generationconfig.md#generationconfigtopk) | number | |
@@ -93,7 +93,7 @@ responseModalities?: ResponseModality[];
9393

9494
## GenerationConfig.responseSchema
9595

96-
Output response schema of the generated candidate text. This value can be a class generated with a [Schema](./ai.schema.md#schema_class) static method like `Schema.string()` or `Schema.object()` or it can be a plain JS object matching the [SchemaRequest](./ai.schemarequest.md#schemarequest_interface) interface. <br/>Note: This only applies when the specified `responseMIMEType` supports a schema; currently this is limited to `application/json` and `text/x.enum`<!-- -->.
96+
Output response schema of the generated candidate text. This value can be a class generated with a [Schema](./ai.schema.md#schema_class) static method like `Schema.string()` or `Schema.object()` or it can be a plain JS object matching the [SchemaRequest](./ai.schemarequest.md#schemarequest_interface) interface. <br/>Note: This only applies when the specified `responseMimeType` supports a schema; currently this is limited to `application/json` and `text/x.enum`<!-- -->.
9797

9898
<b>Signature:</b>
9999

docs-devsite/ai.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ The Firebase AI Web SDK.
2929
| --- | --- |
3030
| [AIError](./ai.aierror.md#aierror_class) | Error class for the Firebase AI SDK. |
3131
| [AIModel](./ai.aimodel.md#aimodel_class) | Base class for Firebase AI model APIs.<!-- -->Instances of this class are associated with a specific Firebase AI [Backend](./ai.backend.md#backend_class) and provide methods for interacting with the configured generative model. |
32+
| [AnyOfSchema](./ai.anyofschema.md#anyofschema_class) | Schema class representing a value that can conform to any of the provided sub-schemas. This is useful when a field can accept multiple distinct types or structures. |
3233
| [ArraySchema](./ai.arrayschema.md#arrayschema_class) | Schema class for "array" types. The <code>items</code> param should refer to the type of item that can be a member of the array. |
3334
| [Backend](./ai.backend.md#backend_class) | Abstract base class representing the configuration for an AI service backend. This class should not be instantiated directly. Use its subclasses; [GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class) for the Gemini Developer API (via [Google AI](https://ai.google/)<!-- -->), and [VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class) for the Vertex AI Gemini API. |
3435
| [BooleanSchema](./ai.booleanschema.md#booleanschema_class) | Schema class for "boolean" types. |
@@ -410,7 +411,7 @@ A type that includes all specific Schema types.
410411
<b>Signature:</b>
411412

412413
```typescript
413-
export type TypedSchema = IntegerSchema | NumberSchema | StringSchema | BooleanSchema | ObjectSchema | ArraySchema;
414+
export type TypedSchema = IntegerSchema | NumberSchema | StringSchema | BooleanSchema | ObjectSchema | ArraySchema | AnyOfSchema;
414415
```
415416

416417
## VertexAI

docs-devsite/ai.schema.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ export declare abstract class Schema implements SchemaInterface
3333
| [example](./ai.schema.md#schemaexample) | | unknown | Optional. The example of the property. |
3434
| [format](./ai.schema.md#schemaformat) | | string | Optional. The format of the property. Supported formats:<br/> <ul> <li>for NUMBER type: "float", "double"</li> <li>for INTEGER type: "int32", "int64"</li> <li>for STRING type: "email", "byte", etc</li> </ul> |
3535
| [nullable](./ai.schema.md#schemanullable) | | boolean | Optional. Whether the property is nullable. Defaults to false. |
36-
| [type](./ai.schema.md#schematype) | | [SchemaType](./ai.md#schematype) | Optional. The type of the property. [SchemaType](./ai.md#schematype)<!-- -->. |
36+
| [type](./ai.schema.md#schematype) | | [SchemaType](./ai.md#schematype) | Optional. The type of the property. [SchemaType](./ai.md#schematype)<!-- -->. This can only be undefined when using <code>anyOf</code> schemas, which do not have an explicit type in the . |
3737
3838
## Methods
3939
4040
| Method | Modifiers | Description |
4141
| --- | --- | --- |
42+
| [anyOf(anyOfParams)](./ai.schema.md#schemaanyof) | <code>static</code> | |
4243
| [array(arrayParams)](./ai.schema.md#schemaarray) | <code>static</code> | |
4344
| [boolean(booleanParams)](./ai.schema.md#schemaboolean) | <code>static</code> | |
4445
| [enumString(stringParams)](./ai.schema.md#schemaenumstring) | <code>static</code> | |
@@ -105,14 +106,34 @@ nullable: boolean;
105106
106107
## Schema.type
107108
108-
Optional. The type of the property. [SchemaType](./ai.md#schematype)<!-- -->.
109+
Optional. The type of the property. [SchemaType](./ai.md#schematype)<!-- -->. This can only be undefined when using `anyOf` schemas, which do not have an explicit type in the .
109110
110111
<b>Signature:</b>
111112
112113
```typescript
113-
type: SchemaType;
114+
type?: SchemaType;
114115
```
115116
117+
## Schema.anyOf()
118+
119+
<b>Signature:</b>
120+
121+
```typescript
122+
static anyOf(anyOfParams: SchemaParams & {
123+
anyOf: TypedSchema[];
124+
}): AnyOfSchema;
125+
```
126+
127+
#### Parameters
128+
129+
| Parameter | Type | Description |
130+
| --- | --- | --- |
131+
| anyOfParams | [SchemaParams](./ai.schemaparams.md#schemaparams_interface) &amp; { anyOf: [TypedSchema](./ai.md#typedschema)<!-- -->\[\]; } | |
132+
133+
<b>Returns:</b>
134+
135+
[AnyOfSchema](./ai.anyofschema.md#anyofschema_class)
136+
116137
## Schema.array()
117138
118139
<b>Signature:</b>

docs-devsite/ai.schemainterface.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ export interface SchemaInterface extends SchemaShared<SchemaInterface>
2323
2424
| Property | Type | Description |
2525
| --- | --- | --- |
26-
| [type](./ai.schemainterface.md#schemainterfacetype) | [SchemaType](./ai.md#schematype) | The type of the property. [SchemaType](./ai.md#schematype)<!-- -->. |
26+
| [type](./ai.schemainterface.md#schemainterfacetype) | [SchemaType](./ai.md#schematype) | The type of the property. this can only be undefined when using <code>anyof</code> schemas, which do not have an explicit type in the . |
2727
2828
## SchemaInterface.type
2929
30-
The type of the property. [SchemaType](./ai.md#schematype)<!-- -->.
30+
The type of the property. this can only be undefined when using `anyof` schemas, which do not have an explicit type in the .
3131
3232
<b>Signature:</b>
3333
3434
```typescript
35-
type: SchemaType;
35+
type?: SchemaType;
3636
```

docs-devsite/ai.schemarequest.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface SchemaRequest extends SchemaShared<SchemaRequest>
2424
| Property | Type | Description |
2525
| --- | --- | --- |
2626
| [required](./ai.schemarequest.md#schemarequestrequired) | string\[\] | Optional. Array of required property. |
27-
| [type](./ai.schemarequest.md#schemarequesttype) | [SchemaType](./ai.md#schematype) | The type of the property. [SchemaType](./ai.md#schematype)<!-- -->. |
27+
| [type](./ai.schemarequest.md#schemarequesttype) | [SchemaType](./ai.md#schematype) | The type of the property. this can only be undefined when using <code>anyof</code> schemas, which do not have an explicit type in the . |
2828
2929
## SchemaRequest.required
3030
@@ -38,10 +38,10 @@ required?: string[];
3838
3939
## SchemaRequest.type
4040
41-
The type of the property. [SchemaType](./ai.md#schematype)<!-- -->.
41+
The type of the property. this can only be undefined when using `anyof` schemas, which do not have an explicit type in the .
4242
4343
<b>Signature:</b>
4444
4545
```typescript
46-
type: SchemaType;
46+
type?: SchemaType;
4747
```

docs-devsite/ai.schemashared.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface SchemaShared<T>
2222

2323
| Property | Type | Description |
2424
| --- | --- | --- |
25+
| [anyOf](./ai.schemashared.md#schemasharedanyof) | T\[\] | An array of [Schema](./ai.schema.md#schema_class)<!-- -->. The generated data must be valid against any of the schemas listed in this array. This allows specifying multiple possible structures or types for a single field. |
2526
| [description](./ai.schemashared.md#schemashareddescription) | string | Optional. The description of the property. |
2627
| [enum](./ai.schemashared.md#schemasharedenum) | string\[\] | Optional. The enum of the property. |
2728
| [example](./ai.schemashared.md#schemasharedexample) | unknown | Optional. The example of the property. |
@@ -30,6 +31,16 @@ export interface SchemaShared<T>
3031
| [nullable](./ai.schemashared.md#schemasharednullable) | boolean | Optional. Whether the property is nullable. |
3132
| [properties](./ai.schemashared.md#schemasharedproperties) | { \[k: string\]: T; } | Optional. Map of <code>Schema</code> objects. |
3233

34+
## SchemaShared.anyOf
35+
36+
An array of [Schema](./ai.schema.md#schema_class)<!-- -->. The generated data must be valid against any of the schemas listed in this array. This allows specifying multiple possible structures or types for a single field.
37+
38+
<b>Signature:</b>
39+
40+
```typescript
41+
anyOf?: T[];
42+
```
43+
3344
## SchemaShared.description
3445

3546
Optional. The description of the property.

0 commit comments

Comments
 (0)