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

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 +437 -195
  2. package/dist/ai.d.ts +437 -195
  3. package/dist/esm/{index.esm2017.js → index.esm.js} +311 -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 +3 -3
  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 +68 -6
  14. package/dist/esm/src/types/responses.d.ts +146 -8
  15. package/dist/esm/src/types/schema.d.ts +31 -16
  16. package/dist/index.cjs.js +325 -279
  17. package/dist/index.cjs.js.map +1 -1
  18. package/dist/index.node.cjs.js +325 -279
  19. package/dist/index.node.cjs.js.map +1 -1
  20. package/dist/index.node.mjs +310 -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 +3 -3
  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 +68 -6
  31. package/dist/src/types/responses.d.ts +146 -8
  32. package/dist/src/types/schema.d.ts +31 -16
  33. package/package.json +12 -12
  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,168 @@ 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[];
160
195
  /**
161
- * @deprecated
196
+ * @deprecated Use {@link GroundingChunk} instead.
162
197
  */
163
198
  groundingAttributions: GroundingAttribution[];
164
199
  }
165
200
  /**
166
- * @deprecated
201
+ * Google search entry point.
202
+ *
167
203
  * @public
168
204
  */
169
- export interface GroundingAttribution {
170
- segment: Segment;
171
- confidenceScore?: number;
172
- web?: WebAttribution;
173
- retrievedContext?: RetrievedContextAttribution;
205
+ export interface SearchEntrypoint {
206
+ /**
207
+ * HTML/CSS snippet that must be embedded in a web page. The snippet is designed to avoid
208
+ * undesired interaction with the rest of the page's CSS.
209
+ *
210
+ * To ensure proper rendering and prevent CSS conflicts, it is recommended
211
+ * to encapsulate this `renderedContent` within a shadow DOM when embedding it
212
+ * into a webpage. See {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_shadow_DOM | MDN: Using shadow DOM}.
213
+ *
214
+ * @example
215
+ * ```javascript
216
+ * const container = document.createElement('div');
217
+ * document.body.appendChild(container);
218
+ * container.attachShadow({ mode: 'open' }).innerHTML = renderedContent;
219
+ * ```
220
+ */
221
+ renderedContent?: string;
174
222
  }
175
223
  /**
224
+ * Represents a chunk of retrieved data that supports a claim in the model's response. This is part
225
+ * of the grounding information provided when grounding is enabled.
226
+ *
227
+ * @public
228
+ */
229
+ export interface GroundingChunk {
230
+ /**
231
+ * Contains details if the grounding chunk is from a web source.
232
+ */
233
+ web?: WebGroundingChunk;
234
+ }
235
+ /**
236
+ * A grounding chunk from the web.
237
+ *
238
+ * Important: If using Grounding with Google Search, you are required to comply with the
239
+ * {@link https://cloud.google.com/terms/service-terms | Service Specific Terms} for "Grounding with Google Search".
240
+ *
241
+ * @public
242
+ */
243
+ export interface WebGroundingChunk {
244
+ /**
245
+ * The URI of the retrieved web page.
246
+ */
247
+ uri?: string;
248
+ /**
249
+ * The title of the retrieved web page.
250
+ */
251
+ title?: string;
252
+ /**
253
+ * The domain of the original URI from which the content was retrieved.
254
+ *
255
+ * This property is only supported in the Vertex AI Gemini API ({@link VertexAIBackend}).
256
+ * When using the Gemini Developer API ({@link GoogleAIBackend}), this property will be
257
+ * `undefined`.
258
+ */
259
+ domain?: string;
260
+ }
261
+ /**
262
+ * Provides information about how a specific segment of the model's response is supported by the
263
+ * retrieved grounding chunks.
264
+ *
265
+ * @public
266
+ */
267
+ export interface GroundingSupport {
268
+ /**
269
+ * Specifies the segment of the model's response content that this grounding support pertains to.
270
+ */
271
+ segment?: Segment;
272
+ /**
273
+ * A list of indices that refer to specific {@link GroundingChunk} objects within the
274
+ * {@link GroundingMetadata.groundingChunks} array. These referenced chunks
275
+ * are the sources that support the claim made in the associated `segment` of the response.
276
+ * For example, an array `[1, 3, 4]` means that `groundingChunks[1]`, `groundingChunks[3]`,
277
+ * and `groundingChunks[4]` are the retrieved content supporting this part of the response.
278
+ */
279
+ groundingChunkIndices?: number[];
280
+ }
281
+ /**
282
+ * Represents a specific segment within a {@link Content} object, often used to
283
+ * pinpoint the exact location of text or data that grounding information refers to.
284
+ *
176
285
  * @public
177
286
  */
178
287
  export interface Segment {
288
+ /**
289
+ * The zero-based index of the {@link Part} object within the `parts` array
290
+ * of its parent {@link Content} object. This identifies which part of the
291
+ * content the segment belongs to.
292
+ */
179
293
  partIndex: number;
294
+ /**
295
+ * The zero-based start index of the segment within the specified `Part`,
296
+ * measured in UTF-8 bytes. This offset is inclusive, starting from 0 at the
297
+ * beginning of the part's content (e.g., `Part.text`).
298
+ */
180
299
  startIndex: number;
300
+ /**
301
+ * The zero-based end index of the segment within the specified `Part`,
302
+ * measured in UTF-8 bytes. This offset is exclusive, meaning the character
303
+ * at this index is not included in the segment.
304
+ */
181
305
  endIndex: number;
306
+ /**
307
+ * The text corresponding to the segment from the response.
308
+ */
309
+ text: string;
310
+ }
311
+ /**
312
+ * @deprecated
313
+ * @public
314
+ */
315
+ export interface GroundingAttribution {
316
+ segment: Segment;
317
+ confidenceScore?: number;
318
+ web?: WebAttribution;
319
+ retrievedContext?: RetrievedContextAttribution;
182
320
  }
183
321
  /**
184
322
  * @public
@@ -20,20 +20,27 @@
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.
@@ -55,9 +62,9 @@ export interface SchemaShared<T> {
55
62
  title?: string;
56
63
  /** Optional. The items of the property. */
57
64
  items?: T;
58
- /** The minimum number of items (elements) in a schema of type {@link SchemaType.ARRAY}. */
65
+ /** The minimum number of items (elements) in a schema of {@link (SchemaType:type)} `array`. */
59
66
  minItems?: number;
60
- /** The maximum number of items (elements) in a schema of type {@link SchemaType.ARRAY}. */
67
+ /** The maximum number of items (elements) in a schema of {@link (SchemaType:type)} `array`. */
61
68
  maxItems?: number;
62
69
  /** Optional. Map of `Schema` objects. */
63
70
  properties?: {
@@ -91,7 +98,7 @@ export interface SchemaParams extends SchemaShared<SchemaInterface> {
91
98
  export interface SchemaRequest extends SchemaShared<SchemaRequest> {
92
99
  /**
93
100
  * The type of the property. {@link
94
- * SchemaType}.
101
+ * (SchemaType:type)}.
95
102
  */
96
103
  type: SchemaType;
97
104
  /** Optional. Array of required property. */
@@ -104,15 +111,23 @@ export interface SchemaRequest extends SchemaShared<SchemaRequest> {
104
111
  export interface SchemaInterface extends SchemaShared<SchemaInterface> {
105
112
  /**
106
113
  * The type of the property. {@link
107
- * SchemaType}.
114
+ * (SchemaType:type)}.
108
115
  */
109
116
  type: SchemaType;
110
117
  }
111
118
  /**
112
- * Interface for {@link ObjectSchema} class.
119
+ * Interface for JSON parameters in a schema of {@link SchemaType}
120
+ * "object" when not using the `Schema.object()` helper.
113
121
  * @public
114
122
  */
115
- export interface ObjectSchemaInterface extends SchemaInterface {
116
- type: SchemaType.OBJECT;
117
- optionalProperties?: string[];
123
+ export interface ObjectSchemaRequest extends SchemaRequest {
124
+ type: 'object';
125
+ /**
126
+ * This is not a property accepted in the final request to the backend, but is
127
+ * a client-side convenience property that is only usable by constructing
128
+ * a schema through the `Schema.object()` helper method. Populating this
129
+ * property will cause response errors if the object is not wrapped with
130
+ * `Schema.object()`.
131
+ */
132
+ optionalProperties?: never;
118
133
  }