@depup/firebase__ai 2.9.0-depup.0

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 (119) hide show
  1. package/README.md +31 -0
  2. package/changes.json +10 -0
  3. package/dist/ai-public.d.ts +3472 -0
  4. package/dist/ai.d.ts +3712 -0
  5. package/dist/esm/index.esm.js +4765 -0
  6. package/dist/esm/index.esm.js.map +1 -0
  7. package/dist/esm/package.json +1 -0
  8. package/dist/esm/src/api.d.ts +121 -0
  9. package/dist/esm/src/backend.d.ts +98 -0
  10. package/dist/esm/src/constants.d.ts +29 -0
  11. package/dist/esm/src/errors.d.ts +35 -0
  12. package/dist/esm/src/factory-browser.d.ts +19 -0
  13. package/dist/esm/src/factory-node.d.ts +19 -0
  14. package/dist/esm/src/googleai-mappers.d.ts +73 -0
  15. package/dist/esm/src/helpers.d.ts +30 -0
  16. package/dist/esm/src/index.d.ts +13 -0
  17. package/dist/esm/src/index.node.d.ts +7 -0
  18. package/dist/esm/src/logger.d.ts +18 -0
  19. package/dist/esm/src/methods/chat-session-helpers.d.ts +18 -0
  20. package/dist/esm/src/methods/chat-session.d.ts +77 -0
  21. package/dist/esm/src/methods/chrome-adapter.d.ts +124 -0
  22. package/dist/esm/src/methods/count-tokens.d.ts +21 -0
  23. package/dist/esm/src/methods/generate-content.d.ts +25 -0
  24. package/dist/esm/src/methods/live-session-helpers.d.ts +154 -0
  25. package/dist/esm/src/methods/live-session.d.ts +154 -0
  26. package/dist/esm/src/models/ai-model.d.ts +72 -0
  27. package/dist/esm/src/models/generative-model.d.ts +56 -0
  28. package/dist/esm/src/models/imagen-model.d.ts +102 -0
  29. package/dist/esm/src/models/index.d.ts +20 -0
  30. package/dist/esm/src/models/live-generative-model.d.ts +55 -0
  31. package/dist/esm/src/models/template-generative-model.d.ts +64 -0
  32. package/dist/esm/src/models/template-imagen-model.d.ts +51 -0
  33. package/dist/esm/src/models/utils.d.ts +26 -0
  34. package/dist/esm/src/public-types.d.ts +97 -0
  35. package/dist/esm/src/requests/hybrid-helpers.d.ts +33 -0
  36. package/dist/esm/src/requests/imagen-image-format.d.ts +61 -0
  37. package/dist/esm/src/requests/request-helpers.d.ts +28 -0
  38. package/dist/esm/src/requests/request.d.ts +69 -0
  39. package/dist/esm/src/requests/response-helpers.d.ts +57 -0
  40. package/dist/esm/src/requests/schema-builder.d.ts +170 -0
  41. package/dist/esm/src/requests/stream-reader.d.ts +39 -0
  42. package/dist/esm/src/service.d.ts +35 -0
  43. package/dist/esm/src/types/chrome-adapter.d.ts +61 -0
  44. package/dist/esm/src/types/content.d.ts +266 -0
  45. package/dist/esm/src/types/enums.d.ts +419 -0
  46. package/dist/esm/src/types/error.d.ts +89 -0
  47. package/dist/esm/src/types/googleai.d.ts +57 -0
  48. package/dist/esm/src/types/imagen/index.d.ts +18 -0
  49. package/dist/esm/src/types/imagen/internal.d.ts +134 -0
  50. package/dist/esm/src/types/imagen/requests.d.ts +245 -0
  51. package/dist/esm/src/types/imagen/responses.d.ts +79 -0
  52. package/dist/esm/src/types/index.d.ts +26 -0
  53. package/dist/esm/src/types/internal.d.ts +35 -0
  54. package/dist/esm/src/types/language-model.d.ts +107 -0
  55. package/dist/esm/src/types/live-responses.d.ts +79 -0
  56. package/dist/esm/src/types/requests.d.ts +543 -0
  57. package/dist/esm/src/types/responses.d.ts +607 -0
  58. package/dist/esm/src/types/schema.d.ts +139 -0
  59. package/dist/esm/src/websocket.d.ts +67 -0
  60. package/dist/index.cjs.js +4820 -0
  61. package/dist/index.cjs.js.map +1 -0
  62. package/dist/index.node.cjs.js +4512 -0
  63. package/dist/index.node.cjs.js.map +1 -0
  64. package/dist/index.node.mjs +4457 -0
  65. package/dist/index.node.mjs.map +1 -0
  66. package/dist/src/api.d.ts +121 -0
  67. package/dist/src/backend.d.ts +98 -0
  68. package/dist/src/constants.d.ts +29 -0
  69. package/dist/src/errors.d.ts +35 -0
  70. package/dist/src/factory-browser.d.ts +19 -0
  71. package/dist/src/factory-node.d.ts +19 -0
  72. package/dist/src/googleai-mappers.d.ts +73 -0
  73. package/dist/src/helpers.d.ts +30 -0
  74. package/dist/src/index.d.ts +13 -0
  75. package/dist/src/index.node.d.ts +7 -0
  76. package/dist/src/logger.d.ts +18 -0
  77. package/dist/src/methods/chat-session-helpers.d.ts +18 -0
  78. package/dist/src/methods/chat-session.d.ts +77 -0
  79. package/dist/src/methods/chrome-adapter.d.ts +124 -0
  80. package/dist/src/methods/count-tokens.d.ts +21 -0
  81. package/dist/src/methods/generate-content.d.ts +25 -0
  82. package/dist/src/methods/live-session-helpers.d.ts +154 -0
  83. package/dist/src/methods/live-session.d.ts +154 -0
  84. package/dist/src/models/ai-model.d.ts +72 -0
  85. package/dist/src/models/generative-model.d.ts +56 -0
  86. package/dist/src/models/imagen-model.d.ts +102 -0
  87. package/dist/src/models/index.d.ts +20 -0
  88. package/dist/src/models/live-generative-model.d.ts +55 -0
  89. package/dist/src/models/template-generative-model.d.ts +64 -0
  90. package/dist/src/models/template-imagen-model.d.ts +51 -0
  91. package/dist/src/models/utils.d.ts +26 -0
  92. package/dist/src/public-types.d.ts +97 -0
  93. package/dist/src/requests/hybrid-helpers.d.ts +33 -0
  94. package/dist/src/requests/imagen-image-format.d.ts +61 -0
  95. package/dist/src/requests/request-helpers.d.ts +28 -0
  96. package/dist/src/requests/request.d.ts +69 -0
  97. package/dist/src/requests/response-helpers.d.ts +57 -0
  98. package/dist/src/requests/schema-builder.d.ts +170 -0
  99. package/dist/src/requests/stream-reader.d.ts +39 -0
  100. package/dist/src/service.d.ts +35 -0
  101. package/dist/src/tsdoc-metadata.json +11 -0
  102. package/dist/src/types/chrome-adapter.d.ts +61 -0
  103. package/dist/src/types/content.d.ts +266 -0
  104. package/dist/src/types/enums.d.ts +419 -0
  105. package/dist/src/types/error.d.ts +89 -0
  106. package/dist/src/types/googleai.d.ts +57 -0
  107. package/dist/src/types/imagen/index.d.ts +18 -0
  108. package/dist/src/types/imagen/internal.d.ts +134 -0
  109. package/dist/src/types/imagen/requests.d.ts +245 -0
  110. package/dist/src/types/imagen/responses.d.ts +79 -0
  111. package/dist/src/types/index.d.ts +26 -0
  112. package/dist/src/types/internal.d.ts +35 -0
  113. package/dist/src/types/language-model.d.ts +107 -0
  114. package/dist/src/types/live-responses.d.ts +79 -0
  115. package/dist/src/types/requests.d.ts +543 -0
  116. package/dist/src/types/responses.d.ts +607 -0
  117. package/dist/src/types/schema.d.ts +139 -0
  118. package/dist/src/websocket.d.ts +67 -0
  119. package/package.json +106 -0
@@ -0,0 +1,121 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2024 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 { FirebaseApp } from '@firebase/app';
18
+ import { AI_TYPE } from './constants';
19
+ import { AIService } from './service';
20
+ import { AI, AIOptions } from './public-types';
21
+ import { ImagenModelParams, HybridParams, ModelParams, RequestOptions, LiveModelParams } from './types';
22
+ import { AIError } from './errors';
23
+ import { AIModel, GenerativeModel, LiveGenerativeModel, ImagenModel } from './models';
24
+ import { TemplateGenerativeModel } from './models/template-generative-model';
25
+ import { TemplateImagenModel } from './models/template-imagen-model';
26
+ export { ChatSession } from './methods/chat-session';
27
+ export { LiveSession } from './methods/live-session';
28
+ export * from './requests/schema-builder';
29
+ export { ImagenImageFormat } from './requests/imagen-image-format';
30
+ export { AIModel, GenerativeModel, LiveGenerativeModel, ImagenModel, TemplateGenerativeModel, TemplateImagenModel, AIError };
31
+ export { Backend, VertexAIBackend, GoogleAIBackend } from './backend';
32
+ export { startAudioConversation, AudioConversationController, StartAudioConversationOptions } from './methods/live-session-helpers';
33
+ declare module '@firebase/component' {
34
+ interface NameServiceMapping {
35
+ [AI_TYPE]: AIService;
36
+ }
37
+ }
38
+ /**
39
+ * Returns the default {@link AI} instance that is associated with the provided
40
+ * {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new instance with the
41
+ * default settings.
42
+ *
43
+ * @example
44
+ * ```javascript
45
+ * const ai = getAI(app);
46
+ * ```
47
+ *
48
+ * @example
49
+ * ```javascript
50
+ * // Get an AI instance configured to use the Gemini Developer API (via Google AI).
51
+ * const ai = getAI(app, { backend: new GoogleAIBackend() });
52
+ * ```
53
+ *
54
+ * @example
55
+ * ```javascript
56
+ * // Get an AI instance configured to use the Vertex AI Gemini API.
57
+ * const ai = getAI(app, { backend: new VertexAIBackend() });
58
+ * ```
59
+ *
60
+ * @param app - The {@link @firebase/app#FirebaseApp} to use.
61
+ * @param options - {@link AIOptions} that configure the AI instance.
62
+ * @returns The default {@link AI} instance for the given {@link @firebase/app#FirebaseApp}.
63
+ *
64
+ * @public
65
+ */
66
+ export declare function getAI(app?: FirebaseApp, options?: AIOptions): AI;
67
+ /**
68
+ * Returns a {@link GenerativeModel} class with methods for inference
69
+ * and other functionality.
70
+ *
71
+ * @public
72
+ */
73
+ export declare function getGenerativeModel(ai: AI, modelParams: ModelParams | HybridParams, requestOptions?: RequestOptions): GenerativeModel;
74
+ /**
75
+ * Returns an {@link ImagenModel} class with methods for using Imagen.
76
+ *
77
+ * Only Imagen 3 models (named `imagen-3.0-*`) are supported.
78
+ *
79
+ * @param ai - An {@link AI} instance.
80
+ * @param modelParams - Parameters to use when making Imagen requests.
81
+ * @param requestOptions - Additional options to use when making requests.
82
+ *
83
+ * @throws If the `apiKey` or `projectId` fields are missing in your
84
+ * Firebase config.
85
+ *
86
+ * @public
87
+ */
88
+ export declare function getImagenModel(ai: AI, modelParams: ImagenModelParams, requestOptions?: RequestOptions): ImagenModel;
89
+ /**
90
+ * Returns a {@link LiveGenerativeModel} class for real-time, bidirectional communication.
91
+ *
92
+ * The Live API is only supported in modern browser windows and Node >= 22.
93
+ *
94
+ * @param ai - An {@link AI} instance.
95
+ * @param modelParams - Parameters to use when setting up a {@link LiveSession}.
96
+ * @throws If the `apiKey` or `projectId` fields are missing in your
97
+ * Firebase config.
98
+ *
99
+ * @beta
100
+ */
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;
@@ -0,0 +1,98 @@
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 { BackendType } from './public-types';
18
+ /**
19
+ * Abstract base class representing the configuration for an AI service backend.
20
+ * This class should not be instantiated directly. Use its subclasses; {@link GoogleAIBackend} for
21
+ * the Gemini Developer API (via {@link https://ai.google/ | Google AI}), and
22
+ * {@link VertexAIBackend} for the Vertex AI Gemini API.
23
+ *
24
+ * @public
25
+ */
26
+ export declare abstract class Backend {
27
+ /**
28
+ * Specifies the backend type.
29
+ */
30
+ readonly backendType: BackendType;
31
+ /**
32
+ * Protected constructor for use by subclasses.
33
+ * @param type - The backend type.
34
+ */
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;
44
+ }
45
+ /**
46
+ * Configuration class for the Gemini Developer API.
47
+ *
48
+ * Use this with {@link AIOptions} when initializing the AI service via
49
+ * {@link getAI | getAI()} to specify the Gemini Developer API as the backend.
50
+ *
51
+ * @public
52
+ */
53
+ export declare class GoogleAIBackend extends Backend {
54
+ /**
55
+ * Creates a configuration object for the Gemini Developer API backend.
56
+ */
57
+ constructor();
58
+ /**
59
+ * @internal
60
+ */
61
+ _getModelPath(project: string, model: string): string;
62
+ /**
63
+ * @internal
64
+ */
65
+ _getTemplatePath(project: string, templateId: string): string;
66
+ }
67
+ /**
68
+ * Configuration class for the Vertex AI Gemini API.
69
+ *
70
+ * Use this with {@link AIOptions} when initializing the AI service via
71
+ * {@link getAI | getAI()} to specify the Vertex AI Gemini API as the backend.
72
+ *
73
+ * @public
74
+ */
75
+ export declare class VertexAIBackend extends Backend {
76
+ /**
77
+ * The region identifier.
78
+ * See {@link https://firebase.google.com/docs/vertex-ai/locations#available-locations | Vertex AI locations}
79
+ * for a list of supported locations.
80
+ */
81
+ readonly location: string;
82
+ /**
83
+ * Creates a configuration object for the Vertex AI backend.
84
+ *
85
+ * @param location - The region identifier, defaulting to `us-central1`;
86
+ * see {@link https://firebase.google.com/docs/vertex-ai/locations#available-locations | Vertex AI locations}
87
+ * for a list of supported locations.
88
+ */
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;
98
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2024 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
+ export declare const AI_TYPE = "AI";
18
+ export declare const DEFAULT_LOCATION = "us-central1";
19
+ export declare const DEFAULT_DOMAIN = "firebasevertexai.googleapis.com";
20
+ export declare const STAGING_URL = "https://staging-firebasevertexai.sandbox.googleapis.com";
21
+ export declare const DEFAULT_API_VERSION = "v1beta";
22
+ export declare const PACKAGE_VERSION: string;
23
+ export declare const LANGUAGE_TAG = "gl-js";
24
+ export declare const HYBRID_TAG = "hybrid";
25
+ export declare const DEFAULT_FETCH_TIMEOUT_MS: number;
26
+ /**
27
+ * Defines the name of the default in-cloud model to use for hybrid inference.
28
+ */
29
+ export declare const DEFAULT_HYBRID_IN_CLOUD_MODEL = "gemini-2.5-flash-lite";
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2024 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 { FirebaseError } from '@firebase/util';
18
+ import { AIErrorCode, CustomErrorData } from './types';
19
+ /**
20
+ * Error class for the Firebase AI SDK.
21
+ *
22
+ * @public
23
+ */
24
+ export declare class AIError extends FirebaseError {
25
+ readonly code: AIErrorCode;
26
+ readonly customErrorData?: CustomErrorData | undefined;
27
+ /**
28
+ * Constructs a new instance of the `AIError` class.
29
+ *
30
+ * @param code - The error code from {@link (AIErrorCode:type)}.
31
+ * @param message - A human-readable message describing the error.
32
+ * @param customErrorData - Optional error data.
33
+ */
34
+ constructor(code: AIErrorCode, message: string, customErrorData?: CustomErrorData | undefined);
35
+ }
@@ -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;
@@ -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;
@@ -0,0 +1,73 @@
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 { CountTokensRequest, GenerateContentCandidate, GenerateContentRequest, GenerateContentResponse, PromptFeedback } from './types';
18
+ import { GoogleAIGenerateContentResponse, GoogleAIGenerateContentCandidate, GoogleAICountTokensRequest } from './types/googleai';
19
+ /**
20
+ * This SDK supports both the Vertex AI Gemini API and the Gemini Developer API (using Google AI).
21
+ * The public API prioritizes the format used by the Vertex AI Gemini API.
22
+ * We avoid having two sets of types by translating requests and responses between the two API formats.
23
+ * This translation allows developers to switch between the Vertex AI Gemini API and the Gemini Developer API
24
+ * with minimal code changes.
25
+ *
26
+ * In here are functions that map requests and responses between the two API formats.
27
+ * Requests in the Vertex AI format are mapped to the Google AI format before being sent.
28
+ * Responses from the Google AI backend are mapped back to the Vertex AI format before being returned to the user.
29
+ */
30
+ /**
31
+ * Maps a Vertex AI {@link GenerateContentRequest} to a format that can be sent to Google AI.
32
+ *
33
+ * @param generateContentRequest The {@link GenerateContentRequest} to map.
34
+ * @returns A {@link GenerateContentResponse} that conforms to the Google AI format.
35
+ *
36
+ * @throws If the request contains properties that are unsupported by Google AI.
37
+ *
38
+ * @internal
39
+ */
40
+ export declare function mapGenerateContentRequest(generateContentRequest: GenerateContentRequest): GenerateContentRequest;
41
+ /**
42
+ * Maps a {@link GenerateContentResponse} from Google AI to the format of the
43
+ * {@link GenerateContentResponse} that we get from VertexAI that is exposed in the public API.
44
+ *
45
+ * @param googleAIResponse The {@link GenerateContentResponse} from Google AI.
46
+ * @returns A {@link GenerateContentResponse} that conforms to the public API's format.
47
+ *
48
+ * @internal
49
+ */
50
+ export declare function mapGenerateContentResponse(googleAIResponse: GoogleAIGenerateContentResponse): GenerateContentResponse;
51
+ /**
52
+ * Maps a Vertex AI {@link CountTokensRequest} to a format that can be sent to Google AI.
53
+ *
54
+ * @param countTokensRequest The {@link CountTokensRequest} to map.
55
+ * @param model The model to count tokens with.
56
+ * @returns A {@link CountTokensRequest} that conforms to the Google AI format.
57
+ *
58
+ * @internal
59
+ */
60
+ export declare function mapCountTokensRequest(countTokensRequest: CountTokensRequest, model: string): GoogleAICountTokensRequest;
61
+ /**
62
+ * Maps a Google AI {@link GoogleAIGenerateContentCandidate} to a format that conforms
63
+ * to the Vertex AI API format.
64
+ *
65
+ * @param candidates The {@link GoogleAIGenerateContentCandidate} to map.
66
+ * @returns A {@link GenerateContentCandidate} that conforms to the Vertex AI format.
67
+ *
68
+ * @throws If any {@link Part} in the candidates has a `videoMetadata` property.
69
+ *
70
+ * @internal
71
+ */
72
+ export declare function mapGenerateContentCandidates(candidates: GoogleAIGenerateContentCandidate[]): GenerateContentCandidate[];
73
+ export declare function mapPromptFeedback(promptFeedback: PromptFeedback): PromptFeedback;
@@ -0,0 +1,30 @@
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 { Backend } from './backend';
18
+ /**
19
+ * Encodes a {@link Backend} into a string that will be used to uniquely identify {@link AI}
20
+ * instances by backend type.
21
+ *
22
+ * @internal
23
+ */
24
+ export declare function encodeInstanceIdentifier(backend: Backend): string;
25
+ /**
26
+ * Decodes an instance identifier string into a {@link Backend}.
27
+ *
28
+ * @internal
29
+ */
30
+ export declare function decodeInstanceIdentifier(instanceIdentifier: string): Backend;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The Firebase AI Web SDK.
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ import { LanguageModel } from './types/language-model';
7
+ declare global {
8
+ interface Window {
9
+ LanguageModel: LanguageModel;
10
+ }
11
+ }
12
+ export * from './api';
13
+ export * from './public-types';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The Firebase AI Web SDK.
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ export * from './api';
7
+ export * from './public-types';
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2024 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 { Logger } from '@firebase/logger';
18
+ export declare const logger: Logger;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2024 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 { Content } from '../types';
18
+ export declare function validateChatHistory(history: Content[]): void;
@@ -0,0 +1,77 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2024 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 { Content, FunctionCall, FunctionResponsePart, GenerateContentRequest, GenerateContentResponse, GenerateContentResult, GenerateContentStreamResult, Part, RequestOptions, SingleRequestOptions, StartChatParams } from '../types';
18
+ import { ApiSettings } from '../types/internal';
19
+ import { ChromeAdapter } from '../types/chrome-adapter';
20
+ /**
21
+ * ChatSession class that enables sending chat messages and stores
22
+ * history of sent and received messages so far.
23
+ *
24
+ * @public
25
+ */
26
+ export declare class ChatSession {
27
+ model: string;
28
+ private chromeAdapter?;
29
+ params?: StartChatParams | undefined;
30
+ requestOptions?: RequestOptions | undefined;
31
+ private _apiSettings;
32
+ private _history;
33
+ /**
34
+ * Ensures sequential execution of chat messages to maintain history order.
35
+ * Each call waits for the previous one to settle before proceeding.
36
+ */
37
+ private _sendPromise;
38
+ constructor(apiSettings: ApiSettings, model: string, chromeAdapter?: ChromeAdapter | undefined, params?: StartChatParams | undefined, requestOptions?: RequestOptions | undefined);
39
+ /**
40
+ * Gets the chat history so far. Blocked prompts are not added to history.
41
+ * Neither blocked candidates nor the prompts that generated them are added
42
+ * to history.
43
+ */
44
+ getHistory(): Promise<Content[]>;
45
+ /**
46
+ * Format Content into a request for generateContent or
47
+ * generateContentStream.
48
+ * @internal
49
+ */
50
+ _formatRequest(incomingContent: Content, tempHistory: Content[]): GenerateContentRequest;
51
+ /**
52
+ * Sends a chat message and receives a non-streaming
53
+ * {@link GenerateContentResult}
54
+ */
55
+ sendMessage(request: string | Array<string | Part>, singleRequestOptions?: SingleRequestOptions): Promise<GenerateContentResult>;
56
+ /**
57
+ * Sends a chat message and receives the response as a
58
+ * {@link GenerateContentStreamResult} containing an iterable stream
59
+ * and a response promise.
60
+ */
61
+ sendMessageStream(request: string | Array<string | Part>, singleRequestOptions?: SingleRequestOptions): Promise<GenerateContentStreamResult>;
62
+ /**
63
+ * Get function calls that the SDK has references to actually call.
64
+ * This is all-or-nothing. If the model is requesting multiple
65
+ * function calls, all of them must have references in order for
66
+ * automatic function calling to work.
67
+ *
68
+ * @internal
69
+ */
70
+ _getCallableFunctionCalls(response?: GenerateContentResponse): FunctionCall[] | undefined;
71
+ /**
72
+ * Call user-defined functions if requested by the model, and return
73
+ * the response that should be sent to the model.
74
+ * @internal
75
+ */
76
+ _callFunctionsAsNeeded(functionCalls: FunctionCall[]): Promise<FunctionResponsePart[]>;
77
+ }