@firebase/ai 1.4.0 → 1.4.1-canary.25b60fdaa

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.
Files changed (34) hide show
  1. package/dist/ai-public.d.ts +462 -213
  2. package/dist/ai.d.ts +465 -213
  3. package/dist/esm/{index.esm2017.js → index.esm.js} +349 -276
  4. package/dist/esm/index.esm.js.map +1 -0
  5. package/dist/esm/src/api.d.ts +2 -38
  6. package/dist/esm/src/errors.d.ts +1 -1
  7. package/dist/esm/src/public-types.d.ts +0 -18
  8. package/dist/esm/src/requests/schema-builder.d.ts +25 -6
  9. package/dist/esm/src/types/enums.d.ts +102 -60
  10. package/dist/esm/src/types/error.d.ts +21 -15
  11. package/dist/esm/src/types/imagen/requests.d.ts +53 -19
  12. package/dist/esm/src/types/imagen/responses.d.ts +2 -2
  13. package/dist/esm/src/types/requests.d.ts +69 -7
  14. package/dist/esm/src/types/responses.d.ts +135 -12
  15. package/dist/esm/src/types/schema.d.ts +41 -20
  16. package/dist/index.cjs.js +364 -279
  17. package/dist/index.cjs.js.map +1 -1
  18. package/dist/index.node.cjs.js +364 -279
  19. package/dist/index.node.cjs.js.map +1 -1
  20. package/dist/index.node.mjs +348 -275
  21. package/dist/index.node.mjs.map +1 -1
  22. package/dist/src/api.d.ts +2 -38
  23. package/dist/src/errors.d.ts +1 -1
  24. package/dist/src/public-types.d.ts +0 -18
  25. package/dist/src/requests/schema-builder.d.ts +25 -6
  26. package/dist/src/types/enums.d.ts +102 -60
  27. package/dist/src/types/error.d.ts +21 -15
  28. package/dist/src/types/imagen/requests.d.ts +53 -19
  29. package/dist/src/types/imagen/responses.d.ts +2 -2
  30. package/dist/src/types/requests.d.ts +69 -7
  31. package/dist/src/types/responses.d.ts +135 -12
  32. package/dist/src/types/schema.d.ts +41 -20
  33. package/package.json +14 -13
  34. package/dist/esm/index.esm2017.js.map +0 -1
@@ -78,6 +78,10 @@ export interface GenerateContentResponse {
78
78
  export interface UsageMetadata {
79
79
  promptTokenCount: number;
80
80
  candidatesTokenCount: number;
81
+ /**
82
+ * The number of tokens used by the model's internal "thinking" process.
83
+ */
84
+ thoughtsTokenCount?: number;
81
85
  totalTokenCount: number;
82
86
  promptTokensDetails?: ModalityTokenCount[];
83
87
  candidatesTokensDetails?: ModalityTokenCount[];
@@ -151,34 +155,154 @@ export interface Citation {
151
155
  publicationDate?: Date;
152
156
  }
153
157
  /**
154
- * Metadata returned to client when grounding is enabled.
158
+ * Metadata returned when grounding is enabled.
159
+ *
160
+ * Currently, only Grounding with Google Search is supported (see {@link GoogleSearchTool}).
161
+ *
162
+ * Important: If using Grounding with Google Search, you are required to comply with the
163
+ * "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}
164
+ * or Vertex AI Gemini API (see {@link https://cloud.google.com/terms/service-terms | Service Terms}
165
+ * section within the Service Specific Terms).
166
+ *
155
167
  * @public
156
168
  */
157
169
  export interface GroundingMetadata {
170
+ /**
171
+ * Google Search entry point for web searches. This contains an HTML/CSS snippet that must be
172
+ * embedded in an app to display a Google Search entry point for follow-up web searches related to
173
+ * a model's “Grounded Response”.
174
+ */
175
+ searchEntryPoint?: SearchEntrypoint;
176
+ /**
177
+ * A list of {@link GroundingChunk} objects. Each chunk represents a piece of retrieved content
178
+ * (for example, from a web page). that the model used to ground its response.
179
+ */
180
+ groundingChunks?: GroundingChunk[];
181
+ /**
182
+ * A list of {@link GroundingSupport} objects. Each object details how specific segments of the
183
+ * model's response are supported by the `groundingChunks`.
184
+ */
185
+ groundingSupports?: GroundingSupport[];
186
+ /**
187
+ * A list of web search queries that the model performed to gather the grounding information.
188
+ * These can be used to allow users to explore the search results themselves.
189
+ */
158
190
  webSearchQueries?: string[];
191
+ /**
192
+ * @deprecated Use {@link GroundingSupport} instead.
193
+ */
159
194
  retrievalQueries?: string[];
195
+ }
196
+ /**
197
+ * Google search entry point.
198
+ *
199
+ * @public
200
+ */
201
+ export interface SearchEntrypoint {
160
202
  /**
161
- * @deprecated
203
+ * HTML/CSS snippet that must be embedded in a web page. The snippet is designed to avoid
204
+ * undesired interaction with the rest of the page's CSS.
205
+ *
206
+ * To ensure proper rendering and prevent CSS conflicts, it is recommended
207
+ * to encapsulate this `renderedContent` within a shadow DOM when embedding it
208
+ * into a webpage. See {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_shadow_DOM | MDN: Using shadow DOM}.
209
+ *
210
+ * @example
211
+ * ```javascript
212
+ * const container = document.createElement('div');
213
+ * document.body.appendChild(container);
214
+ * container.attachShadow({ mode: 'open' }).innerHTML = renderedContent;
215
+ * ```
162
216
  */
163
- groundingAttributions: GroundingAttribution[];
217
+ renderedContent?: string;
164
218
  }
165
219
  /**
166
- * @deprecated
220
+ * Represents a chunk of retrieved data that supports a claim in the model's response. This is part
221
+ * of the grounding information provided when grounding is enabled.
222
+ *
167
223
  * @public
168
224
  */
169
- export interface GroundingAttribution {
170
- segment: Segment;
171
- confidenceScore?: number;
172
- web?: WebAttribution;
173
- retrievedContext?: RetrievedContextAttribution;
225
+ export interface GroundingChunk {
226
+ /**
227
+ * Contains details if the grounding chunk is from a web source.
228
+ */
229
+ web?: WebGroundingChunk;
174
230
  }
175
231
  /**
232
+ * A grounding chunk from the web.
233
+ *
234
+ * Important: If using Grounding with Google Search, you are required to comply with the
235
+ * {@link https://cloud.google.com/terms/service-terms | Service Specific Terms} for "Grounding with Google Search".
236
+ *
237
+ * @public
238
+ */
239
+ export interface WebGroundingChunk {
240
+ /**
241
+ * The URI of the retrieved web page.
242
+ */
243
+ uri?: string;
244
+ /**
245
+ * The title of the retrieved web page.
246
+ */
247
+ title?: string;
248
+ /**
249
+ * The domain of the original URI from which the content was retrieved.
250
+ *
251
+ * This property is only supported in the Vertex AI Gemini API ({@link VertexAIBackend}).
252
+ * When using the Gemini Developer API ({@link GoogleAIBackend}), this property will be
253
+ * `undefined`.
254
+ */
255
+ domain?: string;
256
+ }
257
+ /**
258
+ * Provides information about how a specific segment of the model's response is supported by the
259
+ * retrieved grounding chunks.
260
+ *
261
+ * @public
262
+ */
263
+ export interface GroundingSupport {
264
+ /**
265
+ * Specifies the segment of the model's response content that this grounding support pertains to.
266
+ */
267
+ segment?: Segment;
268
+ /**
269
+ * A list of indices that refer to specific {@link GroundingChunk} objects within the
270
+ * {@link GroundingMetadata.groundingChunks} array. These referenced chunks
271
+ * are the sources that support the claim made in the associated `segment` of the response.
272
+ * For example, an array `[1, 3, 4]` means that `groundingChunks[1]`, `groundingChunks[3]`,
273
+ * and `groundingChunks[4]` are the retrieved content supporting this part of the response.
274
+ */
275
+ groundingChunkIndices?: number[];
276
+ }
277
+ /**
278
+ * Represents a specific segment within a {@link Content} object, often used to
279
+ * pinpoint the exact location of text or data that grounding information refers to.
280
+ *
176
281
  * @public
177
282
  */
178
283
  export interface Segment {
284
+ /**
285
+ * The zero-based index of the {@link Part} object within the `parts` array
286
+ * of its parent {@link Content} object. This identifies which part of the
287
+ * content the segment belongs to.
288
+ */
179
289
  partIndex: number;
290
+ /**
291
+ * The zero-based start index of the segment within the specified `Part`,
292
+ * measured in UTF-8 bytes. This offset is inclusive, starting from 0 at the
293
+ * beginning of the part's content (e.g., `Part.text`).
294
+ */
180
295
  startIndex: number;
296
+ /**
297
+ * The zero-based end index of the segment within the specified `Part`,
298
+ * measured in UTF-8 bytes. This offset is exclusive, meaning the character
299
+ * at this index is not included in the segment.
300
+ */
181
301
  endIndex: number;
302
+ /**
303
+ * The text corresponding to the segment from the response.
304
+ */
305
+ text: string;
182
306
  }
183
307
  /**
184
308
  * @public
@@ -243,11 +367,10 @@ export interface CountTokensResponse {
243
367
  */
244
368
  totalTokens: number;
245
369
  /**
370
+ * @deprecated Use `totalTokens` instead. This property is undefined when using models greater than `gemini-1.5-*`.
371
+ *
246
372
  * The total number of billable characters counted across all instances
247
373
  * from the request.
248
- *
249
- * This property is only supported when using the Vertex AI Gemini API ({@link VertexAIBackend}).
250
- * When using the Gemini Developer API ({@link GoogleAIBackend}), this property is not supported and will default to 0.
251
374
  */
252
375
  totalBillableCharacters?: number;
253
376
  /**
@@ -20,26 +20,39 @@
20
20
  * {@link https://swagger.io/docs/specification/data-models/data-types/ | OpenAPI specification}
21
21
  * @public
22
22
  */
23
- export declare enum SchemaType {
23
+ export declare const SchemaType: {
24
24
  /** String type. */
25
- STRING = "string",
25
+ readonly STRING: "string";
26
26
  /** Number type. */
27
- NUMBER = "number",
27
+ readonly NUMBER: "number";
28
28
  /** Integer type. */
29
- INTEGER = "integer",
29
+ readonly INTEGER: "integer";
30
30
  /** Boolean type. */
31
- BOOLEAN = "boolean",
31
+ readonly BOOLEAN: "boolean";
32
32
  /** Array type. */
33
- ARRAY = "array",
33
+ readonly ARRAY: "array";
34
34
  /** Object type. */
35
- OBJECT = "object"
36
- }
35
+ readonly OBJECT: "object";
36
+ };
37
+ /**
38
+ * Contains the list of OpenAPI data types
39
+ * as defined by the
40
+ * {@link https://swagger.io/docs/specification/data-models/data-types/ | OpenAPI specification}
41
+ * @public
42
+ */
43
+ export type SchemaType = (typeof SchemaType)[keyof typeof SchemaType];
37
44
  /**
38
45
  * Basic {@link Schema} properties shared across several Schema-related
39
46
  * types.
40
47
  * @public
41
48
  */
42
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[];
43
56
  /** Optional. The format of the property.
44
57
  * When using the Gemini Developer API ({@link GoogleAIBackend}), this must be either `'enum'` or
45
58
  * `'date-time'`, otherwise requests will fail.
@@ -55,9 +68,9 @@ export interface SchemaShared<T> {
55
68
  title?: string;
56
69
  /** Optional. The items of the property. */
57
70
  items?: T;
58
- /** The minimum number of items (elements) in a schema of type {@link SchemaType.ARRAY}. */
71
+ /** The minimum number of items (elements) in a schema of {@link (SchemaType:type)} `array`. */
59
72
  minItems?: number;
60
- /** The maximum number of items (elements) in a schema of type {@link SchemaType.ARRAY}. */
73
+ /** The maximum number of items (elements) in a schema of {@link (SchemaType:type)} `array`. */
61
74
  maxItems?: number;
62
75
  /** Optional. Map of `Schema` objects. */
63
76
  properties?: {
@@ -90,10 +103,10 @@ export interface SchemaParams extends SchemaShared<SchemaInterface> {
90
103
  */
91
104
  export interface SchemaRequest extends SchemaShared<SchemaRequest> {
92
105
  /**
93
- * The type of the property. {@link
94
- * SchemaType}.
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 }.
95
108
  */
96
- type: SchemaType;
109
+ type?: SchemaType;
97
110
  /** Optional. Array of required property. */
98
111
  required?: string[];
99
112
  }
@@ -103,16 +116,24 @@ export interface SchemaRequest extends SchemaShared<SchemaRequest> {
103
116
  */
104
117
  export interface SchemaInterface extends SchemaShared<SchemaInterface> {
105
118
  /**
106
- * The type of the property. {@link
107
- * SchemaType}.
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}.
108
121
  */
109
- type: SchemaType;
122
+ type?: SchemaType;
110
123
  }
111
124
  /**
112
- * Interface for {@link ObjectSchema} class.
125
+ * Interface for JSON parameters in a schema of {@link SchemaType}
126
+ * "object" when not using the `Schema.object()` helper.
113
127
  * @public
114
128
  */
115
- export interface ObjectSchemaInterface extends SchemaInterface {
116
- type: SchemaType.OBJECT;
117
- optionalProperties?: string[];
129
+ export interface ObjectSchemaRequest extends SchemaRequest {
130
+ type: 'object';
131
+ /**
132
+ * This is not a property accepted in the final request to the backend, but is
133
+ * a client-side convenience property that is only usable by constructing
134
+ * a schema through the `Schema.object()` helper method. Populating this
135
+ * property will cause response errors if the object is not wrapped with
136
+ * `Schema.object()`.
137
+ */
138
+ optionalProperties?: never;
118
139
  }