@firebase/ai 1.4.0-canary.d590889d6 → 1.4.0-canary.e59cd7da1

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.
@@ -14,10 +14,10 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import { TypedSchema } from '../requests/schema-builder';
17
+ import { ObjectSchema, TypedSchema } from '../requests/schema-builder';
18
18
  import { Content, Part } from './content';
19
19
  import { FunctionCallingMode, HarmBlockMethod, HarmBlockThreshold, HarmCategory, ResponseModality } from './enums';
20
- import { ObjectSchemaInterface, SchemaRequest } from './schema';
20
+ import { ObjectSchemaRequest, SchemaRequest } from './schema';
21
21
  /**
22
22
  * Base parameters for a number of methods.
23
23
  * @public
@@ -101,6 +101,10 @@ export interface GenerationConfig {
101
101
  * @beta
102
102
  */
103
103
  responseModalities?: ResponseModality[];
104
+ /**
105
+ * Configuration for "thinking" behavior of compatible Gemini models.
106
+ */
107
+ thinkingConfig?: ThinkingConfig;
104
108
  }
105
109
  /**
106
110
  * Params for {@link GenerativeModel.startChat}.
@@ -149,7 +153,7 @@ export interface RequestOptions {
149
153
  * Defines a tool that model can call to access external knowledge.
150
154
  * @public
151
155
  */
152
- export declare type Tool = FunctionDeclarationsTool;
156
+ export type Tool = FunctionDeclarationsTool | GoogleSearchTool;
153
157
  /**
154
158
  * Structured representation of a function declaration as defined by the
155
159
  * {@link https://spec.openapis.org/oas/v3.0.3 | OpenAPI 3.0 specification}.
@@ -159,7 +163,7 @@ export declare type Tool = FunctionDeclarationsTool;
159
163
  * as a Tool by the model and executed by the client.
160
164
  * @public
161
165
  */
162
- export declare interface FunctionDeclaration {
166
+ export interface FunctionDeclaration {
163
167
  /**
164
168
  * The name of the function to call. Must start with a letter or an
165
169
  * underscore. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with
@@ -176,7 +180,41 @@ export declare interface FunctionDeclaration {
176
180
  * format. Reflects the Open API 3.03 Parameter Object. Parameter names are
177
181
  * case-sensitive. For a function with no parameters, this can be left unset.
178
182
  */
179
- parameters?: ObjectSchemaInterface;
183
+ parameters?: ObjectSchema | ObjectSchemaRequest;
184
+ }
185
+ /**
186
+ * A tool that allows a Gemini model to connect to Google Search to access and incorporate
187
+ * up-to-date information from the web into its responses.
188
+ *
189
+ * Important: If using Grounding with Google Search, you are required to comply with the
190
+ * "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}
191
+ * or Vertex AI Gemini API (see {@link https://cloud.google.com/terms/service-terms | Service Terms}
192
+ * section within the Service Specific Terms).
193
+ *
194
+ * @public
195
+ */
196
+ export interface GoogleSearchTool {
197
+ /**
198
+ * Specifies the Google Search configuration.
199
+ * Currently, this is an empty object, but it's reserved for future configuration options.
200
+ * Specifies the Google Search configuration. Currently, this is an empty object, but it's
201
+ * reserved for future configuration options.
202
+ *
203
+ * When using this feature, you are required to comply with the "Grounding with Google Search"
204
+ * usage requirements for your chosen API provider: {@link https://ai.google.dev/gemini-api/terms#grounding-with-google-search | Gemini Developer API}
205
+ * or Vertex AI Gemini API (see {@link https://cloud.google.com/terms/service-terms | Service Terms}
206
+ * section within the Service Specific Terms).
207
+ */
208
+ googleSearch: GoogleSearch;
209
+ }
210
+ /**
211
+ * Specifies the Google Search configuration.
212
+ *
213
+ * @remarks Currently, this is an empty object, but it's reserved for future configuration options.
214
+ *
215
+ * @public
216
+ */
217
+ export interface GoogleSearch {
180
218
  }
181
219
  /**
182
220
  * A `FunctionDeclarationsTool` is a piece of code that enables the system to
@@ -184,7 +222,7 @@ export declare interface FunctionDeclaration {
184
222
  * outside of knowledge and scope of the model.
185
223
  * @public
186
224
  */
187
- export declare interface FunctionDeclarationsTool {
225
+ export interface FunctionDeclarationsTool {
188
226
  /**
189
227
  * Optional. One or more function declarations
190
228
  * to be passed to the model along with the current user query. Model may
@@ -211,3 +249,27 @@ export interface FunctionCallingConfig {
211
249
  mode?: FunctionCallingMode;
212
250
  allowedFunctionNames?: string[];
213
251
  }
252
+ /**
253
+ * Configuration for "thinking" behavior of compatible Gemini models.
254
+ *
255
+ * Certain models utilize a thinking process before generating a response. This allows them to
256
+ * reason through complex problems and plan a more coherent and accurate answer.
257
+ *
258
+ * @public
259
+ */
260
+ export interface ThinkingConfig {
261
+ /**
262
+ * The thinking budget, in tokens.
263
+ *
264
+ * This parameter sets an upper limit on the number of tokens the model can use for its internal
265
+ * "thinking" process. A higher budget may result in higher quality responses for complex tasks
266
+ * but can also increase latency and cost.
267
+ *
268
+ * If you don't specify a budget, the model will determine the appropriate amount
269
+ * of thinking based on the complexity of the prompt.
270
+ *
271
+ * An error will be thrown if you set a thinking budget for a model that does not support this
272
+ * feature or if the specified budget is not within the model's supported range.
273
+ */
274
+ thinkingBudget?: number;
275
+ }
@@ -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;
222
+ }
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;
174
234
  }
175
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
@@ -243,11 +381,10 @@ export interface CountTokensResponse {
243
381
  */
244
382
  totalTokens: number;
245
383
  /**
384
+ * @deprecated Use `totalTokens` instead. This property is undefined when using models greater than `gemini-1.5-*`.
385
+ *
246
386
  * The total number of billable characters counted across all instances
247
387
  * 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
388
  */
252
389
  totalBillableCharacters?: number;
253
390
  /**
@@ -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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firebase/ai",
3
- "version": "1.4.0-canary.d590889d6",
3
+ "version": "1.4.0-canary.e59cd7da1",
4
4
  "description": "The Firebase AI SDK",
5
5
  "author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",
6
6
  "engines": {
@@ -45,19 +45,19 @@
45
45
  "trusted-type-check": "tsec -p tsconfig.json --noEmit"
46
46
  },
47
47
  "peerDependencies": {
48
- "@firebase/app": "0.13.1-canary.d590889d6",
49
- "@firebase/app-types": "0.9.3-canary.d590889d6"
48
+ "@firebase/app": "0.13.1-canary.e59cd7da1",
49
+ "@firebase/app-types": "0.9.3-canary.e59cd7da1"
50
50
  },
51
51
  "dependencies": {
52
- "@firebase/app-check-interop-types": "0.3.3-canary.d590889d6",
53
- "@firebase/component": "0.6.17-canary.d590889d6",
54
- "@firebase/logger": "0.4.4-canary.d590889d6",
55
- "@firebase/util": "1.12.0-canary.d590889d6",
52
+ "@firebase/app-check-interop-types": "0.3.3-canary.e59cd7da1",
53
+ "@firebase/component": "0.6.17-canary.e59cd7da1",
54
+ "@firebase/logger": "0.4.4-canary.e59cd7da1",
55
+ "@firebase/util": "1.12.0-canary.e59cd7da1",
56
56
  "tslib": "^2.1.0"
57
57
  },
58
58
  "license": "Apache-2.0",
59
59
  "devDependencies": {
60
- "@firebase/app": "0.13.1-canary.d590889d6",
60
+ "@firebase/app": "0.13.1-canary.e59cd7da1",
61
61
  "@rollup/plugin-json": "6.1.0",
62
62
  "rollup": "2.79.2",
63
63
  "rollup-plugin-replace": "2.2.0",