@firebase/ai 2.5.0 → 2.6.0-20251112180857

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.
package/dist/src/api.d.ts CHANGED
@@ -21,11 +21,13 @@ import { AI, AIOptions } from './public-types';
21
21
  import { ImagenModelParams, HybridParams, ModelParams, RequestOptions, LiveModelParams } from './types';
22
22
  import { AIError } from './errors';
23
23
  import { AIModel, GenerativeModel, LiveGenerativeModel, ImagenModel } from './models';
24
+ import { TemplateGenerativeModel } from './models/template-generative-model';
25
+ import { TemplateImagenModel } from './models/template-imagen-model';
24
26
  export { ChatSession } from './methods/chat-session';
25
27
  export { LiveSession } from './methods/live-session';
26
28
  export * from './requests/schema-builder';
27
29
  export { ImagenImageFormat } from './requests/imagen-image-format';
28
- export { AIModel, GenerativeModel, LiveGenerativeModel, ImagenModel, AIError };
30
+ export { AIModel, GenerativeModel, LiveGenerativeModel, ImagenModel, TemplateGenerativeModel, TemplateImagenModel, AIError };
29
31
  export { Backend, VertexAIBackend, GoogleAIBackend } from './backend';
30
32
  export { startAudioConversation, AudioConversationController, StartAudioConversationOptions } from './methods/live-session-helpers';
31
33
  declare module '@firebase/component' {
@@ -97,3 +99,23 @@ export declare function getImagenModel(ai: AI, modelParams: ImagenModelParams, r
97
99
  * @beta
98
100
  */
99
101
  export declare function getLiveGenerativeModel(ai: AI, modelParams: LiveModelParams): LiveGenerativeModel;
102
+ /**
103
+ * Returns a {@link TemplateGenerativeModel} class for executing server-side
104
+ * templates.
105
+ *
106
+ * @param ai - An {@link AI} instance.
107
+ * @param requestOptions - Additional options to use when making requests.
108
+ *
109
+ * @beta
110
+ */
111
+ export declare function getTemplateGenerativeModel(ai: AI, requestOptions?: RequestOptions): TemplateGenerativeModel;
112
+ /**
113
+ * Returns a {@link TemplateImagenModel} class for executing server-side
114
+ * Imagen templates.
115
+ *
116
+ * @param ai - An {@link AI} instance.
117
+ * @param requestOptions - Additional options to use when making requests.
118
+ *
119
+ * @beta
120
+ */
121
+ export declare function getTemplateImagenModel(ai: AI, requestOptions?: RequestOptions): TemplateImagenModel;
@@ -33,6 +33,14 @@ export declare abstract class Backend {
33
33
  * @param type - The backend type.
34
34
  */
35
35
  protected constructor(type: BackendType);
36
+ /**
37
+ * @internal
38
+ */
39
+ abstract _getModelPath(project: string, model: string): string;
40
+ /**
41
+ * @internal
42
+ */
43
+ abstract _getTemplatePath(project: string, templateId: string): string;
36
44
  }
37
45
  /**
38
46
  * Configuration class for the Gemini Developer API.
@@ -47,6 +55,14 @@ export declare class GoogleAIBackend extends Backend {
47
55
  * Creates a configuration object for the Gemini Developer API backend.
48
56
  */
49
57
  constructor();
58
+ /**
59
+ * @internal
60
+ */
61
+ _getModelPath(project: string, model: string): string;
62
+ /**
63
+ * @internal
64
+ */
65
+ _getTemplatePath(project: string, templateId: string): string;
50
66
  }
51
67
  /**
52
68
  * Configuration class for the Vertex AI Gemini API.
@@ -71,4 +87,12 @@ export declare class VertexAIBackend extends Backend {
71
87
  * for a list of supported locations.
72
88
  */
73
89
  constructor(location?: string);
90
+ /**
91
+ * @internal
92
+ */
93
+ _getModelPath(project: string, model: string): string;
94
+ /**
95
+ * @internal
96
+ */
97
+ _getTemplatePath(project: string, templateId: string): string;
74
98
  }
@@ -17,6 +17,7 @@
17
17
  export declare const AI_TYPE = "AI";
18
18
  export declare const DEFAULT_LOCATION = "us-central1";
19
19
  export declare const DEFAULT_DOMAIN = "firebasevertexai.googleapis.com";
20
+ export declare const STAGING_URL = "https://staging-firebasevertexai.sandbox.googleapis.com";
20
21
  export declare const DEFAULT_API_VERSION = "v1beta";
21
22
  export declare const PACKAGE_VERSION: string;
22
23
  export declare const LANGUAGE_TAG = "gl-js";
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { ComponentContainer, InstanceFactoryOptions } from '@firebase/component';
18
+ import { AIService } from './service';
19
+ export declare function factory(container: ComponentContainer, { instanceIdentifier }: InstanceFactoryOptions): AIService;
@@ -18,4 +18,6 @@ import { GenerateContentRequest, GenerateContentResult, GenerateContentStreamRes
18
18
  import { ApiSettings } from '../types/internal';
19
19
  import { ChromeAdapter } from '../types/chrome-adapter';
20
20
  export declare function generateContentStream(apiSettings: ApiSettings, model: string, params: GenerateContentRequest, chromeAdapter?: ChromeAdapter, requestOptions?: RequestOptions): Promise<GenerateContentStreamResult>;
21
+ export declare function templateGenerateContent(apiSettings: ApiSettings, templateId: string, templateParams: object, requestOptions?: RequestOptions): Promise<GenerateContentResult>;
22
+ export declare function templateGenerateContentStream(apiSettings: ApiSettings, templateId: string, templateParams: object, requestOptions?: RequestOptions): Promise<GenerateContentStreamResult>;
21
23
  export declare function generateContent(apiSettings: ApiSettings, model: string, params: GenerateContentRequest, chromeAdapter?: ChromeAdapter, requestOptions?: RequestOptions): Promise<GenerateContentResult>;
@@ -0,0 +1,64 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { GenerateContentResult, RequestOptions } from '../types';
18
+ import { AI, GenerateContentStreamResult } from '../public-types';
19
+ import { ApiSettings } from '../types/internal';
20
+ /**
21
+ * {@link GenerativeModel} APIs that execute on a server-side template.
22
+ *
23
+ * This class should only be instantiated with {@link getTemplateGenerativeModel}.
24
+ *
25
+ * @beta
26
+ */
27
+ export declare class TemplateGenerativeModel {
28
+ /**
29
+ * @internal
30
+ */
31
+ _apiSettings: ApiSettings;
32
+ /**
33
+ * Additional options to use when making requests.
34
+ */
35
+ requestOptions?: RequestOptions;
36
+ /**
37
+ * @hideconstructor
38
+ */
39
+ constructor(ai: AI, requestOptions?: RequestOptions);
40
+ /**
41
+ * Makes a single non-streaming call to the model and returns an object
42
+ * containing a single {@link GenerateContentResponse}.
43
+ *
44
+ * @param templateId - The ID of the server-side template to execute.
45
+ * @param templateVariables - A key-value map of variables to populate the
46
+ * template with.
47
+ *
48
+ * @beta
49
+ */
50
+ generateContent(templateId: string, templateVariables: object): Promise<GenerateContentResult>;
51
+ /**
52
+ * Makes a single streaming call to the model and returns an object
53
+ * containing an iterable stream that iterates over all chunks in the
54
+ * streaming response as well as a promise that returns the final aggregated
55
+ * response.
56
+ *
57
+ * @param templateId - The ID of the server-side template to execute.
58
+ * @param templateVariables - A key-value map of variables to populate the
59
+ * template with.
60
+ *
61
+ * @beta
62
+ */
63
+ generateContentStream(templateId: string, templateVariables: object): Promise<GenerateContentStreamResult>;
64
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { RequestOptions } from '../types';
18
+ import { AI, ImagenGenerationResponse, ImagenInlineImage } from '../public-types';
19
+ import { ApiSettings } from '../types/internal';
20
+ /**
21
+ * Class for Imagen model APIs that execute on a server-side template.
22
+ *
23
+ * This class should only be instantiated with {@link getTemplateImagenModel}.
24
+ *
25
+ * @beta
26
+ */
27
+ export declare class TemplateImagenModel {
28
+ /**
29
+ * @internal
30
+ */
31
+ _apiSettings: ApiSettings;
32
+ /**
33
+ * Additional options to use when making requests.
34
+ */
35
+ requestOptions?: RequestOptions;
36
+ /**
37
+ * @hideconstructor
38
+ */
39
+ constructor(ai: AI, requestOptions?: RequestOptions);
40
+ /**
41
+ * Makes a single call to the model and returns an object containing a single
42
+ * {@link ImagenGenerationResponse}.
43
+ *
44
+ * @param templateId - The ID of the server-side template to execute.
45
+ * @param templateVariables - A key-value map of variables to populate the
46
+ * template with.
47
+ *
48
+ * @beta
49
+ */
50
+ generateImages(templateId: string, templateVariables: object): Promise<ImagenGenerationResponse<ImagenInlineImage>>;
51
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { AI } from '../public-types';
18
+ import { ApiSettings } from '../types/internal';
19
+ /**
20
+ * Initializes an {@link ApiSettings} object from an {@link AI} instance.
21
+ *
22
+ * If this is a Server App, the {@link ApiSettings} object's `getAppCheckToken()` will resolve
23
+ * with the `FirebaseServerAppSettings.appCheckToken`, instead of requiring that an App Check
24
+ * instance is initialized.
25
+ */
26
+ export declare function initApiSettings(ai: AI): ApiSettings;
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2024 Google LLC
3
+ * Copyright 2025 Google LLC
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -16,23 +16,44 @@
16
16
  */
17
17
  import { RequestOptions } from '../types';
18
18
  import { ApiSettings } from '../types/internal';
19
- export declare enum Task {
19
+ export declare const enum Task {
20
20
  GENERATE_CONTENT = "generateContent",
21
21
  STREAM_GENERATE_CONTENT = "streamGenerateContent",
22
22
  COUNT_TOKENS = "countTokens",
23
23
  PREDICT = "predict"
24
24
  }
25
- export declare class RequestUrl {
26
- model: string;
27
- task: Task;
25
+ export declare const enum ServerPromptTemplateTask {
26
+ TEMPLATE_GENERATE_CONTENT = "templateGenerateContent",
27
+ TEMPLATE_STREAM_GENERATE_CONTENT = "templateStreamGenerateContent",
28
+ TEMPLATE_PREDICT = "templatePredict"
29
+ }
30
+ interface BaseRequestURLParams {
28
31
  apiSettings: ApiSettings;
29
32
  stream: boolean;
30
- requestOptions?: RequestOptions | undefined;
31
- constructor(model: string, task: Task, apiSettings: ApiSettings, stream: boolean, requestOptions?: RequestOptions | undefined);
33
+ requestOptions?: RequestOptions;
34
+ }
35
+ /**
36
+ * Parameters used to construct the URL of a request to use a model.
37
+ */
38
+ interface ModelRequestURLParams extends BaseRequestURLParams {
39
+ task: Task;
40
+ model: string;
41
+ templateId?: never;
42
+ }
43
+ /**
44
+ * Parameters used to construct the URL of a request to use server side prompt templates.
45
+ */
46
+ interface TemplateRequestURLParams extends BaseRequestURLParams {
47
+ task: ServerPromptTemplateTask;
48
+ templateId: string;
49
+ model?: never;
50
+ }
51
+ export declare class RequestURL {
52
+ readonly params: ModelRequestURLParams | TemplateRequestURLParams;
53
+ constructor(params: ModelRequestURLParams | TemplateRequestURLParams);
32
54
  toString(): string;
55
+ private get pathname();
33
56
  private get baseUrl();
34
- private get apiVersion();
35
- private get modelPath();
36
57
  private get queryParams();
37
58
  }
38
59
  export declare class WebSocketUrl {
@@ -41,9 +62,6 @@ export declare class WebSocketUrl {
41
62
  toString(): string;
42
63
  private get pathname();
43
64
  }
44
- export declare function getHeaders(url: RequestUrl): Promise<Headers>;
45
- export declare function constructRequest(model: string, task: Task, apiSettings: ApiSettings, stream: boolean, body: string, requestOptions?: RequestOptions): Promise<{
46
- url: string;
47
- fetchOptions: RequestInit;
48
- }>;
49
- export declare function makeRequest(model: string, task: Task, apiSettings: ApiSettings, stream: boolean, body: string, requestOptions?: RequestOptions): Promise<Response>;
65
+ export declare function getHeaders(url: RequestURL): Promise<Headers>;
66
+ export declare function makeRequest(requestUrlParams: TemplateRequestURLParams | ModelRequestURLParams, body: string): Promise<Response>;
67
+ export {};
@@ -15,21 +15,20 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  import { FirebaseApp, _FirebaseService } from '@firebase/app';
18
- import { AI, AIOptions, InferenceMode, OnDeviceParams } from './public-types';
18
+ import { AI, AIOptions, ChromeAdapter, InferenceMode, OnDeviceParams } from './public-types';
19
19
  import { AppCheckInternalComponentName, FirebaseAppCheckInternal } from '@firebase/app-check-interop-types';
20
20
  import { Provider } from '@firebase/component';
21
21
  import { FirebaseAuthInternal, FirebaseAuthInternalName } from '@firebase/auth-interop-types';
22
22
  import { Backend } from './backend';
23
- import { ChromeAdapterImpl } from './methods/chrome-adapter';
24
23
  export declare class AIService implements AI, _FirebaseService {
25
24
  app: FirebaseApp;
26
25
  backend: Backend;
27
- chromeAdapterFactory?: ((mode: InferenceMode, window?: Window, params?: OnDeviceParams) => ChromeAdapterImpl | undefined) | undefined;
26
+ chromeAdapterFactory?: ((mode: InferenceMode, window?: Window, params?: OnDeviceParams) => ChromeAdapter | undefined) | undefined;
28
27
  auth: FirebaseAuthInternal | null;
29
28
  appCheck: FirebaseAppCheckInternal | null;
30
29
  _options?: Omit<AIOptions, 'backend'>;
31
30
  location: string;
32
- constructor(app: FirebaseApp, backend: Backend, authProvider?: Provider<FirebaseAuthInternalName>, appCheckProvider?: Provider<AppCheckInternalComponentName>, chromeAdapterFactory?: ((mode: InferenceMode, window?: Window, params?: OnDeviceParams) => ChromeAdapterImpl | undefined) | undefined);
31
+ constructor(app: FirebaseApp, backend: Backend, authProvider?: Provider<FirebaseAuthInternalName>, appCheckProvider?: Provider<AppCheckInternalComponentName>, chromeAdapterFactory?: ((mode: InferenceMode, window?: Window, params?: OnDeviceParams) => ChromeAdapter | undefined) | undefined);
33
32
  _delete(): Promise<void>;
34
33
  set options(optionsToSet: AIOptions);
35
34
  get options(): AIOptions | undefined;
@@ -14,6 +14,7 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
+ import { InferenceMode } from './enums';
17
18
  import { CountTokensRequest, GenerateContentRequest } from './requests';
18
19
  /**
19
20
  * Defines an inference "backend" that uses Chrome's on-device model,
@@ -25,6 +26,10 @@ import { CountTokensRequest, GenerateContentRequest } from './requests';
25
26
  * @beta
26
27
  */
27
28
  export interface ChromeAdapter {
29
+ /**
30
+ * @internal
31
+ */
32
+ mode: InferenceMode;
28
33
  /**
29
34
  * Checks if the on-device model is capable of handling a given
30
35
  * request.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firebase/ai",
3
- "version": "2.5.0",
3
+ "version": "2.6.0-20251112180857",
4
4
  "description": "The Firebase AI SDK",
5
5
  "author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",
6
6
  "engines": {