@firebase/ai 2.5.0-canary.0800a8bed → 2.5.0-canary.180b1ad9b

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.
@@ -4,7 +4,7 @@ import { FirebaseError, Deferred, getModularInstance } from '@firebase/util';
4
4
  import { Logger } from '@firebase/logger';
5
5
 
6
6
  var name = "@firebase/ai";
7
- var version = "2.5.0-canary.0800a8bed";
7
+ var version = "2.5.0-canary.180b1ad9b";
8
8
 
9
9
  /**
10
10
  * @license
@@ -766,6 +766,18 @@ class GoogleAIBackend extends Backend {
766
766
  constructor() {
767
767
  super(BackendType.GOOGLE_AI);
768
768
  }
769
+ /**
770
+ * @internal
771
+ */
772
+ _getModelPath(project, model) {
773
+ return `/${DEFAULT_API_VERSION}/projects/${project}/${model}`;
774
+ }
775
+ /**
776
+ * @internal
777
+ */
778
+ _getTemplatePath(project, templateId) {
779
+ return `/${DEFAULT_API_VERSION}/projects/${project}/templates/${templateId}`;
780
+ }
769
781
  }
770
782
  /**
771
783
  * Configuration class for the Vertex AI Gemini API.
@@ -792,6 +804,18 @@ class VertexAIBackend extends Backend {
792
804
  this.location = location;
793
805
  }
794
806
  }
807
+ /**
808
+ * @internal
809
+ */
810
+ _getModelPath(project, model) {
811
+ return `/${DEFAULT_API_VERSION}/projects/${project}/locations/${this.location}/${model}`;
812
+ }
813
+ /**
814
+ * @internal
815
+ */
816
+ _getTemplatePath(project, templateId) {
817
+ return `/${DEFAULT_API_VERSION}/projects/${project}/locations/${this.location}/templates/${templateId}`;
818
+ }
795
819
  }
796
820
 
797
821
  /**
@@ -923,6 +947,67 @@ function factory(container, { instanceIdentifier }) {
923
947
  return new AIService(app, backend, auth, appCheckProvider);
924
948
  }
925
949
 
950
+ /**
951
+ * @license
952
+ * Copyright 2025 Google LLC
953
+ *
954
+ * Licensed under the Apache License, Version 2.0 (the "License");
955
+ * you may not use this file except in compliance with the License.
956
+ * You may obtain a copy of the License at
957
+ *
958
+ * http://www.apache.org/licenses/LICENSE-2.0
959
+ *
960
+ * Unless required by applicable law or agreed to in writing, software
961
+ * distributed under the License is distributed on an "AS IS" BASIS,
962
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
963
+ * See the License for the specific language governing permissions and
964
+ * limitations under the License.
965
+ */
966
+ /**
967
+ * Initializes an {@link ApiSettings} object from an {@link AI} instance.
968
+ *
969
+ * If this is a Server App, the {@link ApiSettings} object's `getAppCheckToken()` will resolve
970
+ * with the `FirebaseServerAppSettings.appCheckToken`, instead of requiring that an App Check
971
+ * instance is initialized.
972
+ */
973
+ function initApiSettings(ai) {
974
+ if (!ai.app?.options?.apiKey) {
975
+ throw new AIError(AIErrorCode.NO_API_KEY, `The "apiKey" field is empty in the local Firebase config. Firebase AI requires this field to contain a valid API key.`);
976
+ }
977
+ else if (!ai.app?.options?.projectId) {
978
+ throw new AIError(AIErrorCode.NO_PROJECT_ID, `The "projectId" field is empty in the local Firebase config. Firebase AI requires this field to contain a valid project ID.`);
979
+ }
980
+ else if (!ai.app?.options?.appId) {
981
+ throw new AIError(AIErrorCode.NO_APP_ID, `The "appId" field is empty in the local Firebase config. Firebase AI requires this field to contain a valid app ID.`);
982
+ }
983
+ const apiSettings = {
984
+ apiKey: ai.app.options.apiKey,
985
+ project: ai.app.options.projectId,
986
+ appId: ai.app.options.appId,
987
+ automaticDataCollectionEnabled: ai.app.automaticDataCollectionEnabled,
988
+ location: ai.location,
989
+ backend: ai.backend
990
+ };
991
+ if (_isFirebaseServerApp(ai.app) && ai.app.settings.appCheckToken) {
992
+ const token = ai.app.settings.appCheckToken;
993
+ apiSettings.getAppCheckToken = () => {
994
+ return Promise.resolve({ token });
995
+ };
996
+ }
997
+ else if (ai.appCheck) {
998
+ if (ai.options?.useLimitedUseAppCheckTokens) {
999
+ apiSettings.getAppCheckToken = () => ai.appCheck.getLimitedUseToken();
1000
+ }
1001
+ else {
1002
+ apiSettings.getAppCheckToken = () => ai.appCheck.getToken();
1003
+ }
1004
+ }
1005
+ if (ai.auth) {
1006
+ apiSettings.getAuthToken = () => ai.auth.getToken();
1007
+ }
1008
+ return apiSettings;
1009
+ }
1010
+
926
1011
  /**
927
1012
  * @license
928
1013
  * Copyright 2025 Google LLC
@@ -966,43 +1051,8 @@ class AIModel {
966
1051
  * @internal
967
1052
  */
968
1053
  constructor(ai, modelName) {
969
- if (!ai.app?.options?.apiKey) {
970
- throw new AIError(AIErrorCode.NO_API_KEY, `The "apiKey" field is empty in the local Firebase config. Firebase AI requires this field to contain a valid API key.`);
971
- }
972
- else if (!ai.app?.options?.projectId) {
973
- throw new AIError(AIErrorCode.NO_PROJECT_ID, `The "projectId" field is empty in the local Firebase config. Firebase AI requires this field to contain a valid project ID.`);
974
- }
975
- else if (!ai.app?.options?.appId) {
976
- throw new AIError(AIErrorCode.NO_APP_ID, `The "appId" field is empty in the local Firebase config. Firebase AI requires this field to contain a valid app ID.`);
977
- }
978
- else {
979
- this._apiSettings = {
980
- apiKey: ai.app.options.apiKey,
981
- project: ai.app.options.projectId,
982
- appId: ai.app.options.appId,
983
- automaticDataCollectionEnabled: ai.app.automaticDataCollectionEnabled,
984
- location: ai.location,
985
- backend: ai.backend
986
- };
987
- if (_isFirebaseServerApp(ai.app) && ai.app.settings.appCheckToken) {
988
- const token = ai.app.settings.appCheckToken;
989
- this._apiSettings.getAppCheckToken = () => {
990
- return Promise.resolve({ token });
991
- };
992
- }
993
- else if (ai.appCheck) {
994
- if (ai.options?.useLimitedUseAppCheckTokens) {
995
- this._apiSettings.getAppCheckToken = () => ai.appCheck.getLimitedUseToken();
996
- }
997
- else {
998
- this._apiSettings.getAppCheckToken = () => ai.appCheck.getToken();
999
- }
1000
- }
1001
- if (ai.auth) {
1002
- this._apiSettings.getAuthToken = () => ai.auth.getToken();
1003
- }
1004
- this.model = AIModel.normalizeModelName(modelName, this._apiSettings.backend.backendType);
1005
- }
1054
+ this._apiSettings = initApiSettings(ai);
1055
+ this.model = AIModel.normalizeModelName(modelName, this._apiSettings.backend.backendType);
1006
1056
  }
1007
1057
  /**
1008
1058
  * Normalizes the given model name to a fully qualified model resource name.
@@ -1069,7 +1119,7 @@ const logger = new Logger('@firebase/vertexai');
1069
1119
 
1070
1120
  /**
1071
1121
  * @license
1072
- * Copyright 2024 Google LLC
1122
+ * Copyright 2025 Google LLC
1073
1123
  *
1074
1124
  * Licensed under the Apache License, Version 2.0 (the "License");
1075
1125
  * you may not use this file except in compliance with the License.
@@ -1083,47 +1133,33 @@ const logger = new Logger('@firebase/vertexai');
1083
1133
  * See the License for the specific language governing permissions and
1084
1134
  * limitations under the License.
1085
1135
  */
1086
- var Task;
1087
- (function (Task) {
1088
- Task["GENERATE_CONTENT"] = "generateContent";
1089
- Task["STREAM_GENERATE_CONTENT"] = "streamGenerateContent";
1090
- Task["COUNT_TOKENS"] = "countTokens";
1091
- Task["PREDICT"] = "predict";
1092
- })(Task || (Task = {}));
1093
- class RequestUrl {
1094
- constructor(model, task, apiSettings, stream, requestOptions) {
1095
- this.model = model;
1096
- this.task = task;
1097
- this.apiSettings = apiSettings;
1098
- this.stream = stream;
1099
- this.requestOptions = requestOptions;
1136
+ class RequestURL {
1137
+ constructor(params) {
1138
+ this.params = params;
1100
1139
  }
1101
1140
  toString() {
1102
1141
  const url = new URL(this.baseUrl); // Throws if the URL is invalid
1103
- url.pathname = `/${this.apiVersion}/${this.modelPath}:${this.task}`;
1142
+ url.pathname = this.pathname;
1104
1143
  url.search = this.queryParams.toString();
1105
1144
  return url.toString();
1106
1145
  }
1107
- get baseUrl() {
1108
- return this.requestOptions?.baseUrl || `https://${DEFAULT_DOMAIN}`;
1109
- }
1110
- get apiVersion() {
1111
- return DEFAULT_API_VERSION; // TODO: allow user-set options if that feature becomes available
1112
- }
1113
- get modelPath() {
1114
- if (this.apiSettings.backend instanceof GoogleAIBackend) {
1115
- return `projects/${this.apiSettings.project}/${this.model}`;
1116
- }
1117
- else if (this.apiSettings.backend instanceof VertexAIBackend) {
1118
- return `projects/${this.apiSettings.project}/locations/${this.apiSettings.backend.location}/${this.model}`;
1146
+ get pathname() {
1147
+ // We need to construct a different URL if the request is for server side prompt templates,
1148
+ // since the URL patterns are different. Server side prompt templates expect a templateId
1149
+ // instead of a model name.
1150
+ if (this.params.templateId) {
1151
+ return `${this.params.apiSettings.backend._getTemplatePath(this.params.apiSettings.project, this.params.templateId)}:${this.params.task}`;
1119
1152
  }
1120
1153
  else {
1121
- throw new AIError(AIErrorCode.ERROR, `Invalid backend: ${JSON.stringify(this.apiSettings.backend)}`);
1154
+ return `${this.params.apiSettings.backend._getModelPath(this.params.apiSettings.project, this.params.model)}:${this.params.task}`;
1122
1155
  }
1123
1156
  }
1157
+ get baseUrl() {
1158
+ return this.params.requestOptions?.baseUrl ?? `https://${DEFAULT_DOMAIN}`;
1159
+ }
1124
1160
  get queryParams() {
1125
1161
  const params = new URLSearchParams();
1126
- if (this.stream) {
1162
+ if (this.params.stream) {
1127
1163
  params.set('alt', 'sse');
1128
1164
  }
1129
1165
  return params;
@@ -1163,12 +1199,12 @@ async function getHeaders(url) {
1163
1199
  const headers = new Headers();
1164
1200
  headers.append('Content-Type', 'application/json');
1165
1201
  headers.append('x-goog-api-client', getClientHeaders());
1166
- headers.append('x-goog-api-key', url.apiSettings.apiKey);
1167
- if (url.apiSettings.automaticDataCollectionEnabled) {
1168
- headers.append('X-Firebase-Appid', url.apiSettings.appId);
1202
+ headers.append('x-goog-api-key', url.params.apiSettings.apiKey);
1203
+ if (url.params.apiSettings.automaticDataCollectionEnabled) {
1204
+ headers.append('X-Firebase-Appid', url.params.apiSettings.appId);
1169
1205
  }
1170
- if (url.apiSettings.getAppCheckToken) {
1171
- const appCheckToken = await url.apiSettings.getAppCheckToken();
1206
+ if (url.params.apiSettings.getAppCheckToken) {
1207
+ const appCheckToken = await url.params.apiSettings.getAppCheckToken();
1172
1208
  if (appCheckToken) {
1173
1209
  headers.append('X-Firebase-AppCheck', appCheckToken.token);
1174
1210
  if (appCheckToken.error) {
@@ -1176,39 +1212,33 @@ async function getHeaders(url) {
1176
1212
  }
1177
1213
  }
1178
1214
  }
1179
- if (url.apiSettings.getAuthToken) {
1180
- const authToken = await url.apiSettings.getAuthToken();
1215
+ if (url.params.apiSettings.getAuthToken) {
1216
+ const authToken = await url.params.apiSettings.getAuthToken();
1181
1217
  if (authToken) {
1182
1218
  headers.append('Authorization', `Firebase ${authToken.accessToken}`);
1183
1219
  }
1184
1220
  }
1185
1221
  return headers;
1186
1222
  }
1187
- async function constructRequest(model, task, apiSettings, stream, body, requestOptions) {
1188
- const url = new RequestUrl(model, task, apiSettings, stream, requestOptions);
1189
- return {
1190
- url: url.toString(),
1191
- fetchOptions: {
1192
- method: 'POST',
1193
- headers: await getHeaders(url),
1194
- body
1195
- }
1196
- };
1197
- }
1198
- async function makeRequest(model, task, apiSettings, stream, body, requestOptions) {
1199
- const url = new RequestUrl(model, task, apiSettings, stream, requestOptions);
1223
+ async function makeRequest(requestUrlParams, body) {
1224
+ const url = new RequestURL(requestUrlParams);
1200
1225
  let response;
1201
1226
  let fetchTimeoutId;
1202
1227
  try {
1203
- const request = await constructRequest(model, task, apiSettings, stream, body, requestOptions);
1204
- // Timeout is 180s by default
1205
- const timeoutMillis = requestOptions?.timeout != null && requestOptions.timeout >= 0
1206
- ? requestOptions.timeout
1228
+ const fetchOptions = {
1229
+ method: 'POST',
1230
+ headers: await getHeaders(url),
1231
+ body
1232
+ };
1233
+ // Timeout is 180s by default.
1234
+ const timeoutMillis = requestUrlParams.requestOptions?.timeout != null &&
1235
+ requestUrlParams.requestOptions.timeout >= 0
1236
+ ? requestUrlParams.requestOptions.timeout
1207
1237
  : DEFAULT_FETCH_TIMEOUT_MS;
1208
1238
  const abortController = new AbortController();
1209
1239
  fetchTimeoutId = setTimeout(() => abortController.abort(), timeoutMillis);
1210
- request.fetchOptions.signal = abortController.signal;
1211
- response = await fetch(request.url, request.fetchOptions);
1240
+ fetchOptions.signal = abortController.signal;
1241
+ response = await fetch(url.toString(), fetchOptions);
1212
1242
  if (!response.ok) {
1213
1243
  let message = '';
1214
1244
  let errorDetails;
@@ -1230,7 +1260,7 @@ async function makeRequest(model, task, apiSettings, stream, body, requestOption
1230
1260
  throw new AIError(AIErrorCode.API_NOT_ENABLED, `The Firebase AI SDK requires the Firebase AI ` +
1231
1261
  `API ('firebasevertexai.googleapis.com') to be enabled in your ` +
1232
1262
  `Firebase project. Enable this API by visiting the Firebase Console ` +
1233
- `at https://console.firebase.google.com/project/${url.apiSettings.project}/genai/ ` +
1263
+ `at https://console.firebase.google.com/project/${url.params.apiSettings.project}/genai/ ` +
1234
1264
  `and clicking "Get started". If you enabled this API recently, ` +
1235
1265
  `wait a few minutes for the action to propagate to our systems and ` +
1236
1266
  `then retry.`, {
@@ -1971,8 +2001,13 @@ async function generateContentStreamOnCloud(apiSettings, model, params, requestO
1971
2001
  if (apiSettings.backend.backendType === BackendType.GOOGLE_AI) {
1972
2002
  params = mapGenerateContentRequest(params);
1973
2003
  }
1974
- return makeRequest(model, Task.STREAM_GENERATE_CONTENT, apiSettings,
1975
- /* stream */ true, JSON.stringify(params), requestOptions);
2004
+ return makeRequest({
2005
+ task: "streamGenerateContent" /* Task.STREAM_GENERATE_CONTENT */,
2006
+ model,
2007
+ apiSettings,
2008
+ stream: true,
2009
+ requestOptions
2010
+ }, JSON.stringify(params));
1976
2011
  }
1977
2012
  async function generateContentStream(apiSettings, model, params, chromeAdapter, requestOptions) {
1978
2013
  const callResult = await callCloudOrDevice(params, chromeAdapter, () => chromeAdapter.generateContentStream(params), () => generateContentStreamOnCloud(apiSettings, model, params, requestOptions));
@@ -1982,8 +2017,37 @@ async function generateContentOnCloud(apiSettings, model, params, requestOptions
1982
2017
  if (apiSettings.backend.backendType === BackendType.GOOGLE_AI) {
1983
2018
  params = mapGenerateContentRequest(params);
1984
2019
  }
1985
- return makeRequest(model, Task.GENERATE_CONTENT, apiSettings,
1986
- /* stream */ false, JSON.stringify(params), requestOptions);
2020
+ return makeRequest({
2021
+ model,
2022
+ task: "generateContent" /* Task.GENERATE_CONTENT */,
2023
+ apiSettings,
2024
+ stream: false,
2025
+ requestOptions
2026
+ }, JSON.stringify(params));
2027
+ }
2028
+ async function templateGenerateContent(apiSettings, templateId, templateParams, requestOptions) {
2029
+ const response = await makeRequest({
2030
+ task: "templateGenerateContent" /* ServerPromptTemplateTask.TEMPLATE_GENERATE_CONTENT */,
2031
+ templateId,
2032
+ apiSettings,
2033
+ stream: false,
2034
+ requestOptions
2035
+ }, JSON.stringify(templateParams));
2036
+ const generateContentResponse = await processGenerateContentResponse(response, apiSettings);
2037
+ const enhancedResponse = createEnhancedContentResponse(generateContentResponse);
2038
+ return {
2039
+ response: enhancedResponse
2040
+ };
2041
+ }
2042
+ async function templateGenerateContentStream(apiSettings, templateId, templateParams, requestOptions) {
2043
+ const response = await makeRequest({
2044
+ task: "templateStreamGenerateContent" /* ServerPromptTemplateTask.TEMPLATE_STREAM_GENERATE_CONTENT */,
2045
+ templateId,
2046
+ apiSettings,
2047
+ stream: true,
2048
+ requestOptions
2049
+ }, JSON.stringify(templateParams));
2050
+ return processStream(response, apiSettings);
1987
2051
  }
1988
2052
  async function generateContent(apiSettings, model, params, chromeAdapter, requestOptions) {
1989
2053
  const callResult = await callCloudOrDevice(params, chromeAdapter, () => chromeAdapter.generateContent(params), () => generateContentOnCloud(apiSettings, model, params, requestOptions));
@@ -2395,7 +2459,13 @@ async function countTokensOnCloud(apiSettings, model, params, requestOptions) {
2395
2459
  else {
2396
2460
  body = JSON.stringify(params);
2397
2461
  }
2398
- const response = await makeRequest(model, Task.COUNT_TOKENS, apiSettings, false, body, requestOptions);
2462
+ const response = await makeRequest({
2463
+ model,
2464
+ task: "countTokens" /* Task.COUNT_TOKENS */,
2465
+ apiSettings,
2466
+ stream: false,
2467
+ requestOptions
2468
+ }, body);
2399
2469
  return response.json();
2400
2470
  }
2401
2471
  async function countTokens(apiSettings, model, params, chromeAdapter, requestOptions) {
@@ -2948,8 +3018,13 @@ class ImagenModel extends AIModel {
2948
3018
  ...this.generationConfig,
2949
3019
  ...this.safetySettings
2950
3020
  });
2951
- const response = await makeRequest(this.model, Task.PREDICT, this._apiSettings,
2952
- /* stream */ false, JSON.stringify(body), this.requestOptions);
3021
+ const response = await makeRequest({
3022
+ task: "predict" /* Task.PREDICT */,
3023
+ model: this.model,
3024
+ apiSettings: this._apiSettings,
3025
+ stream: false,
3026
+ requestOptions: this.requestOptions
3027
+ }, JSON.stringify(body));
2953
3028
  return handlePredictResponse(response);
2954
3029
  }
2955
3030
  /**
@@ -2977,8 +3052,13 @@ class ImagenModel extends AIModel {
2977
3052
  ...this.generationConfig,
2978
3053
  ...this.safetySettings
2979
3054
  });
2980
- const response = await makeRequest(this.model, Task.PREDICT, this._apiSettings,
2981
- /* stream */ false, JSON.stringify(body), this.requestOptions);
3055
+ const response = await makeRequest({
3056
+ task: "predict" /* Task.PREDICT */,
3057
+ model: this.model,
3058
+ apiSettings: this._apiSettings,
3059
+ stream: false,
3060
+ requestOptions: this.requestOptions
3061
+ }, JSON.stringify(body));
2982
3062
  return handlePredictResponse(response);
2983
3063
  }
2984
3064
  }
@@ -3130,6 +3210,121 @@ class WebSocketHandlerImpl {
3130
3210
  }
3131
3211
  }
3132
3212
 
3213
+ /**
3214
+ * @license
3215
+ * Copyright 2025 Google LLC
3216
+ *
3217
+ * Licensed under the Apache License, Version 2.0 (the "License");
3218
+ * you may not use this file except in compliance with the License.
3219
+ * You may obtain a copy of the License at
3220
+ *
3221
+ * http://www.apache.org/licenses/LICENSE-2.0
3222
+ *
3223
+ * Unless required by applicable law or agreed to in writing, software
3224
+ * distributed under the License is distributed on an "AS IS" BASIS,
3225
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3226
+ * See the License for the specific language governing permissions and
3227
+ * limitations under the License.
3228
+ */
3229
+ /**
3230
+ * {@link GenerativeModel} APIs that execute on a server-side template.
3231
+ *
3232
+ * This class should only be instantiated with {@link getTemplateGenerativeModel}.
3233
+ *
3234
+ * @beta
3235
+ */
3236
+ class TemplateGenerativeModel {
3237
+ /**
3238
+ * @hideconstructor
3239
+ */
3240
+ constructor(ai, requestOptions) {
3241
+ this.requestOptions = requestOptions || {};
3242
+ this._apiSettings = initApiSettings(ai);
3243
+ }
3244
+ /**
3245
+ * Makes a single non-streaming call to the model and returns an object
3246
+ * containing a single {@link GenerateContentResponse}.
3247
+ *
3248
+ * @param templateId - The ID of the server-side template to execute.
3249
+ * @param templateVariables - A key-value map of variables to populate the
3250
+ * template with.
3251
+ *
3252
+ * @beta
3253
+ */
3254
+ async generateContent(templateId, templateVariables // anything!
3255
+ ) {
3256
+ return templateGenerateContent(this._apiSettings, templateId, { inputs: templateVariables }, this.requestOptions);
3257
+ }
3258
+ /**
3259
+ * Makes a single streaming call to the model and returns an object
3260
+ * containing an iterable stream that iterates over all chunks in the
3261
+ * streaming response as well as a promise that returns the final aggregated
3262
+ * response.
3263
+ *
3264
+ * @param templateId - The ID of the server-side template to execute.
3265
+ * @param templateVariables - A key-value map of variables to populate the
3266
+ * template with.
3267
+ *
3268
+ * @beta
3269
+ */
3270
+ async generateContentStream(templateId, templateVariables) {
3271
+ return templateGenerateContentStream(this._apiSettings, templateId, { inputs: templateVariables }, this.requestOptions);
3272
+ }
3273
+ }
3274
+
3275
+ /**
3276
+ * @license
3277
+ * Copyright 2025 Google LLC
3278
+ *
3279
+ * Licensed under the Apache License, Version 2.0 (the "License");
3280
+ * you may not use this file except in compliance with the License.
3281
+ * You may obtain a copy of the License at
3282
+ *
3283
+ * http://www.apache.org/licenses/LICENSE-2.0
3284
+ *
3285
+ * Unless required by applicable law or agreed to in writing, software
3286
+ * distributed under the License is distributed on an "AS IS" BASIS,
3287
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3288
+ * See the License for the specific language governing permissions and
3289
+ * limitations under the License.
3290
+ */
3291
+ /**
3292
+ * Class for Imagen model APIs that execute on a server-side template.
3293
+ *
3294
+ * This class should only be instantiated with {@link getTemplateImagenModel}.
3295
+ *
3296
+ * @beta
3297
+ */
3298
+ class TemplateImagenModel {
3299
+ /**
3300
+ * @hideconstructor
3301
+ */
3302
+ constructor(ai, requestOptions) {
3303
+ this.requestOptions = requestOptions || {};
3304
+ this._apiSettings = initApiSettings(ai);
3305
+ }
3306
+ /**
3307
+ * Makes a single call to the model and returns an object containing a single
3308
+ * {@link ImagenGenerationResponse}.
3309
+ *
3310
+ * @param templateId - The ID of the server-side template to execute.
3311
+ * @param templateVariables - A key-value map of variables to populate the
3312
+ * template with.
3313
+ *
3314
+ * @beta
3315
+ */
3316
+ async generateImages(templateId, templateVariables) {
3317
+ const response = await makeRequest({
3318
+ task: "templatePredict" /* ServerPromptTemplateTask.TEMPLATE_PREDICT */,
3319
+ templateId,
3320
+ apiSettings: this._apiSettings,
3321
+ stream: false,
3322
+ requestOptions: this.requestOptions
3323
+ }, JSON.stringify({ inputs: templateVariables }));
3324
+ return handlePredictResponse(response);
3325
+ }
3326
+ }
3327
+
3133
3328
  /**
3134
3329
  * @license
3135
3330
  * Copyright 2024 Google LLC
@@ -3921,6 +4116,30 @@ function getLiveGenerativeModel(ai, modelParams) {
3921
4116
  const webSocketHandler = new WebSocketHandlerImpl();
3922
4117
  return new LiveGenerativeModel(ai, modelParams, webSocketHandler);
3923
4118
  }
4119
+ /**
4120
+ * Returns a {@link TemplateGenerativeModel} class for executing server-side
4121
+ * templates.
4122
+ *
4123
+ * @param ai - An {@link AI} instance.
4124
+ * @param requestOptions - Additional options to use when making requests.
4125
+ *
4126
+ * @beta
4127
+ */
4128
+ function getTemplateGenerativeModel(ai, requestOptions) {
4129
+ return new TemplateGenerativeModel(ai, requestOptions);
4130
+ }
4131
+ /**
4132
+ * Returns a {@link TemplateImagenModel} class for executing server-side
4133
+ * Imagen templates.
4134
+ *
4135
+ * @param ai - An {@link AI} instance.
4136
+ * @param requestOptions - Additional options to use when making requests.
4137
+ *
4138
+ * @beta
4139
+ */
4140
+ function getTemplateImagenModel(ai, requestOptions) {
4141
+ return new TemplateImagenModel(ai, requestOptions);
4142
+ }
3924
4143
 
3925
4144
  /**
3926
4145
  * The Firebase AI Web SDK.
@@ -3935,5 +4154,5 @@ function registerAI() {
3935
4154
  }
3936
4155
  registerAI();
3937
4156
 
3938
- export { AIError, AIErrorCode, AIModel, AnyOfSchema, ArraySchema, Backend, BackendType, BlockReason, BooleanSchema, ChatSession, FinishReason, FunctionCallingMode, GenerativeModel, GoogleAIBackend, HarmBlockMethod, HarmBlockThreshold, HarmCategory, HarmProbability, HarmSeverity, ImagenAspectRatio, ImagenImageFormat, ImagenModel, ImagenPersonFilterLevel, ImagenSafetyFilterLevel, InferenceMode, InferenceSource, IntegerSchema, Language, LiveGenerativeModel, LiveResponseType, LiveSession, Modality, NumberSchema, ObjectSchema, Outcome, POSSIBLE_ROLES, ResponseModality, Schema, SchemaType, StringSchema, URLRetrievalStatus, VertexAIBackend, getAI, getGenerativeModel, getImagenModel, getLiveGenerativeModel, startAudioConversation };
4157
+ export { AIError, AIErrorCode, AIModel, AnyOfSchema, ArraySchema, Backend, BackendType, BlockReason, BooleanSchema, ChatSession, FinishReason, FunctionCallingMode, GenerativeModel, GoogleAIBackend, HarmBlockMethod, HarmBlockThreshold, HarmCategory, HarmProbability, HarmSeverity, ImagenAspectRatio, ImagenImageFormat, ImagenModel, ImagenPersonFilterLevel, ImagenSafetyFilterLevel, InferenceMode, InferenceSource, IntegerSchema, Language, LiveGenerativeModel, LiveResponseType, LiveSession, Modality, NumberSchema, ObjectSchema, Outcome, POSSIBLE_ROLES, ResponseModality, Schema, SchemaType, StringSchema, TemplateGenerativeModel, TemplateImagenModel, URLRetrievalStatus, VertexAIBackend, getAI, getGenerativeModel, getImagenModel, getLiveGenerativeModel, getTemplateGenerativeModel, getTemplateImagenModel, startAudioConversation };
3939
4158
  //# sourceMappingURL=index.node.mjs.map