@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,102 @@
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 { ImagenGCSImage, ImagenGenerationConfig, ImagenInlineImage, RequestOptions, ImagenModelParams, ImagenGenerationResponse, ImagenSafetySettings, SingleRequestOptions } from '../types';
19
+ import { AIModel } from './ai-model';
20
+ /**
21
+ * Class for Imagen model APIs.
22
+ *
23
+ * This class provides methods for generating images using the Imagen model.
24
+ *
25
+ * @example
26
+ * ```javascript
27
+ * const imagen = new ImagenModel(
28
+ * ai,
29
+ * {
30
+ * model: 'imagen-3.0-generate-002'
31
+ * }
32
+ * );
33
+ *
34
+ * const response = await imagen.generateImages('A photo of a cat');
35
+ * if (response.images.length > 0) {
36
+ * console.log(response.images[0].bytesBase64Encoded);
37
+ * }
38
+ * ```
39
+ *
40
+ * @public
41
+ */
42
+ export declare class ImagenModel extends AIModel {
43
+ requestOptions?: RequestOptions | undefined;
44
+ /**
45
+ * The Imagen generation configuration.
46
+ */
47
+ generationConfig?: ImagenGenerationConfig;
48
+ /**
49
+ * Safety settings for filtering inappropriate content.
50
+ */
51
+ safetySettings?: ImagenSafetySettings;
52
+ /**
53
+ * Constructs a new instance of the {@link ImagenModel} class.
54
+ *
55
+ * @param ai - an {@link AI} instance.
56
+ * @param modelParams - Parameters to use when making requests to Imagen.
57
+ * @param requestOptions - Additional options to use when making requests.
58
+ *
59
+ * @throws If the `apiKey` or `projectId` fields are missing in your
60
+ * Firebase config.
61
+ */
62
+ constructor(ai: AI, modelParams: ImagenModelParams, requestOptions?: RequestOptions | undefined);
63
+ /**
64
+ * Generates images using the Imagen model and returns them as
65
+ * base64-encoded strings.
66
+ *
67
+ * @param prompt - A text prompt describing the image(s) to generate.
68
+ * @returns A promise that resolves to an {@link ImagenGenerationResponse}
69
+ * object containing the generated images.
70
+ *
71
+ * @throws If the request to generate images fails. This happens if the
72
+ * prompt is blocked.
73
+ *
74
+ * @remarks
75
+ * If the prompt was not blocked, but one or more of the generated images were filtered, the
76
+ * returned object will have a `filteredReason` property.
77
+ * If all images are filtered, the `images` array will be empty.
78
+ *
79
+ * @public
80
+ */
81
+ generateImages(prompt: string, singleRequestOptions?: SingleRequestOptions): Promise<ImagenGenerationResponse<ImagenInlineImage>>;
82
+ /**
83
+ * Generates images to Cloud Storage for Firebase using the Imagen model.
84
+ *
85
+ * @internal This method is temporarily internal.
86
+ *
87
+ * @param prompt - A text prompt describing the image(s) to generate.
88
+ * @param gcsURI - The URI of file stored in a Cloud Storage for Firebase bucket.
89
+ * This should be a directory. For example, `gs://my-bucket/my-directory/`.
90
+ * @returns A promise that resolves to an {@link ImagenGenerationResponse}
91
+ * object containing the URLs of the generated images.
92
+ *
93
+ * @throws If the request fails to generate images fails. This happens if
94
+ * the prompt is blocked.
95
+ *
96
+ * @remarks
97
+ * If the prompt was not blocked, but one or more of the generated images were filtered, the
98
+ * returned object will have a `filteredReason` property.
99
+ * If all images are filtered, the `images` array will be empty.
100
+ */
101
+ generateImagesGCS(prompt: string, gcsURI: string, singleRequestOptions?: SingleRequestOptions): Promise<ImagenGenerationResponse<ImagenGCSImage>>;
102
+ }
@@ -0,0 +1,20 @@
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
+ export * from './ai-model';
18
+ export * from './generative-model';
19
+ export * from './live-generative-model';
20
+ export * from './imagen-model';
@@ -0,0 +1,55 @@
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 { AIModel } from './ai-model';
18
+ import { LiveSession } from '../methods/live-session';
19
+ import { AI, Content, LiveGenerationConfig, LiveModelParams, Tool, ToolConfig } from '../public-types';
20
+ import { WebSocketHandler } from '../websocket';
21
+ /**
22
+ * Class for Live generative model APIs. The Live API enables low-latency, two-way multimodal
23
+ * interactions with Gemini.
24
+ *
25
+ * This class should only be instantiated with {@link getLiveGenerativeModel}.
26
+ *
27
+ * @beta
28
+ */
29
+ export declare class LiveGenerativeModel extends AIModel {
30
+ /**
31
+ * @internal
32
+ */
33
+ private _webSocketHandler;
34
+ generationConfig: LiveGenerationConfig;
35
+ tools?: Tool[];
36
+ toolConfig?: ToolConfig;
37
+ systemInstruction?: Content;
38
+ /**
39
+ * @internal
40
+ */
41
+ constructor(ai: AI, modelParams: LiveModelParams,
42
+ /**
43
+ * @internal
44
+ */
45
+ _webSocketHandler: WebSocketHandler);
46
+ /**
47
+ * Starts a {@link LiveSession}.
48
+ *
49
+ * @returns A {@link LiveSession}.
50
+ * @throws If the connection failed to be established with the server.
51
+ *
52
+ * @beta
53
+ */
54
+ connect(): Promise<LiveSession>;
55
+ }
@@ -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, SingleRequestOptions } 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, singleRequestOptions?: SingleRequestOptions): 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, singleRequestOptions?: SingleRequestOptions): 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, SingleRequestOptions } 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, singleRequestOptions?: SingleRequestOptions): 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;
@@ -0,0 +1,97 @@
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 { Backend } from './backend';
19
+ export * from './types';
20
+ /**
21
+ * An instance of the Firebase AI SDK.
22
+ *
23
+ * Do not create this instance directly. Instead, use {@link getAI | getAI()}.
24
+ *
25
+ * @public
26
+ */
27
+ export interface AI {
28
+ /**
29
+ * The {@link @firebase/app#FirebaseApp} this {@link AI} instance is associated with.
30
+ */
31
+ app: FirebaseApp;
32
+ /**
33
+ * A {@link Backend} instance that specifies the configuration for the target backend,
34
+ * either the Gemini Developer API (using {@link GoogleAIBackend}) or the
35
+ * Vertex AI Gemini API (using {@link VertexAIBackend}).
36
+ */
37
+ backend: Backend;
38
+ /**
39
+ * Options applied to this {@link AI} instance.
40
+ */
41
+ options?: AIOptions;
42
+ /**
43
+ * @deprecated use `AI.backend.location` instead.
44
+ *
45
+ * The location configured for this AI service instance, relevant for Vertex AI backends.
46
+ */
47
+ location: string;
48
+ }
49
+ /**
50
+ * An enum-like object containing constants that represent the supported backends
51
+ * for the Firebase AI SDK.
52
+ * This determines which backend service (Vertex AI Gemini API or Gemini Developer API)
53
+ * the SDK will communicate with.
54
+ *
55
+ * These values are assigned to the `backendType` property within the specific backend
56
+ * configuration objects ({@link GoogleAIBackend} or {@link VertexAIBackend}) to identify
57
+ * which service to target.
58
+ *
59
+ * @public
60
+ */
61
+ export declare const BackendType: {
62
+ /**
63
+ * Identifies the backend service for the Vertex AI Gemini API provided through Google Cloud.
64
+ * Use this constant when creating a {@link VertexAIBackend} configuration.
65
+ */
66
+ readonly VERTEX_AI: "VERTEX_AI";
67
+ /**
68
+ * Identifies the backend service for the Gemini Developer API ({@link https://ai.google/ | Google AI}).
69
+ * Use this constant when creating a {@link GoogleAIBackend} configuration.
70
+ */
71
+ readonly GOOGLE_AI: "GOOGLE_AI";
72
+ };
73
+ /**
74
+ * Type alias representing valid backend types.
75
+ * It can be either `'VERTEX_AI'` or `'GOOGLE_AI'`.
76
+ *
77
+ * @public
78
+ */
79
+ export type BackendType = (typeof BackendType)[keyof typeof BackendType];
80
+ /**
81
+ * Options for initializing the AI service using {@link getAI | getAI()}.
82
+ * This allows specifying which backend to use (Vertex AI Gemini API or Gemini Developer API)
83
+ * and configuring its specific options (like location for Vertex AI).
84
+ *
85
+ * @public
86
+ */
87
+ export interface AIOptions {
88
+ /**
89
+ * The backend configuration to use for the AI service instance.
90
+ * Defaults to the Gemini Developer API backend ({@link GoogleAIBackend}).
91
+ */
92
+ backend?: Backend;
93
+ /**
94
+ * Whether to use App Check limited use tokens. Defaults to false.
95
+ */
96
+ useLimitedUseAppCheckTokens?: boolean;
97
+ }
@@ -0,0 +1,33 @@
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 { GenerateContentRequest, ChromeAdapter, InferenceSource } from '../types';
18
+ interface CallResult<Response> {
19
+ response: Response;
20
+ inferenceSource: InferenceSource;
21
+ }
22
+ /**
23
+ * Dispatches a request to the appropriate backend (on-device or in-cloud)
24
+ * based on the inference mode.
25
+ *
26
+ * @param request - The request to be sent.
27
+ * @param chromeAdapter - The on-device model adapter.
28
+ * @param onDeviceCall - The function to call for on-device inference.
29
+ * @param inCloudCall - The function to call for in-cloud inference.
30
+ * @returns The response from the backend.
31
+ */
32
+ export declare function callCloudOrDevice<Response>(request: GenerateContentRequest, chromeAdapter: ChromeAdapter | undefined, onDeviceCall: () => Promise<Response>, inCloudCall: () => Promise<Response>): Promise<CallResult<Response>>;
33
+ export {};
@@ -0,0 +1,61 @@
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
+ /**
18
+ * Defines the image format for images generated by Imagen.
19
+ *
20
+ * Use this class to specify the desired format (JPEG or PNG) and compression quality
21
+ * for images generated by Imagen. This is typically included as part of
22
+ * {@link ImagenModelParams}.
23
+ *
24
+ * @example
25
+ * ```javascript
26
+ * const imagenModelParams = {
27
+ * // ... other ImagenModelParams
28
+ * imageFormat: ImagenImageFormat.jpeg(75) // JPEG with a compression level of 75.
29
+ * }
30
+ * ```
31
+ *
32
+ * @public
33
+ */
34
+ export declare class ImagenImageFormat {
35
+ /**
36
+ * The MIME type.
37
+ */
38
+ mimeType: string;
39
+ /**
40
+ * The level of compression (a number between 0 and 100).
41
+ */
42
+ compressionQuality?: number;
43
+ private constructor();
44
+ /**
45
+ * Creates an {@link ImagenImageFormat} for a JPEG image.
46
+ *
47
+ * @param compressionQuality - The level of compression (a number between 0 and 100).
48
+ * @returns An {@link ImagenImageFormat} object for a JPEG image.
49
+ *
50
+ * @public
51
+ */
52
+ static jpeg(compressionQuality?: number): ImagenImageFormat;
53
+ /**
54
+ * Creates an {@link ImagenImageFormat} for a PNG image.
55
+ *
56
+ * @returns An {@link ImagenImageFormat} object for a PNG image.
57
+ *
58
+ * @public
59
+ */
60
+ static png(): ImagenImageFormat;
61
+ }
@@ -0,0 +1,28 @@
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, GenerateContentRequest, Part } from '../types';
18
+ import { ImagenGenerationParams, PredictRequestBody } from '../types/internal';
19
+ export declare function formatSystemInstruction(input?: string | Part | Content): Content | undefined;
20
+ export declare function formatNewContent(request: string | Array<string | Part>): Content;
21
+ export declare function formatGenerateContentInput(params: GenerateContentRequest | string | Array<string | Part>): GenerateContentRequest;
22
+ /**
23
+ * Convert the user-defined parameters in {@link ImagenGenerationParams} to the format
24
+ * that is expected from the REST API.
25
+ *
26
+ * @internal
27
+ */
28
+ export declare function createPredictRequestBody(prompt: string, { gcsURI, imageFormat, addWatermark, numberOfImages, negativePrompt, aspectRatio, safetyFilterLevel, personFilterLevel }: ImagenGenerationParams): PredictRequestBody;
@@ -0,0 +1,69 @@
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 { SingleRequestOptions } from '../types';
18
+ import { ApiSettings } from '../types/internal';
19
+ export declare const TIMEOUT_EXPIRED_MESSAGE = "Timeout has expired.";
20
+ export declare const ABORT_ERROR_NAME = "AbortError";
21
+ export declare const enum Task {
22
+ GENERATE_CONTENT = "generateContent",
23
+ STREAM_GENERATE_CONTENT = "streamGenerateContent",
24
+ COUNT_TOKENS = "countTokens",
25
+ PREDICT = "predict"
26
+ }
27
+ export declare const enum ServerPromptTemplateTask {
28
+ TEMPLATE_GENERATE_CONTENT = "templateGenerateContent",
29
+ TEMPLATE_STREAM_GENERATE_CONTENT = "templateStreamGenerateContent",
30
+ TEMPLATE_PREDICT = "templatePredict"
31
+ }
32
+ interface BaseRequestURLParams {
33
+ apiSettings: ApiSettings;
34
+ stream: boolean;
35
+ singleRequestOptions?: SingleRequestOptions;
36
+ }
37
+ /**
38
+ * Parameters used to construct the URL of a request to use a model.
39
+ */
40
+ interface ModelRequestURLParams extends BaseRequestURLParams {
41
+ task: Task;
42
+ model: string;
43
+ templateId?: never;
44
+ }
45
+ /**
46
+ * Parameters used to construct the URL of a request to use server side prompt templates.
47
+ */
48
+ interface TemplateRequestURLParams extends BaseRequestURLParams {
49
+ task: ServerPromptTemplateTask;
50
+ templateId: string;
51
+ model?: never;
52
+ }
53
+ export declare class RequestURL {
54
+ readonly params: ModelRequestURLParams | TemplateRequestURLParams;
55
+ constructor(params: ModelRequestURLParams | TemplateRequestURLParams);
56
+ toString(): string;
57
+ private get pathname();
58
+ private get baseUrl();
59
+ private get queryParams();
60
+ }
61
+ export declare class WebSocketUrl {
62
+ apiSettings: ApiSettings;
63
+ constructor(apiSettings: ApiSettings);
64
+ toString(): string;
65
+ private get pathname();
66
+ }
67
+ export declare function getHeaders(url: RequestURL): Promise<Headers>;
68
+ export declare function makeRequest(requestUrlParams: TemplateRequestURLParams | ModelRequestURLParams, body: string): Promise<Response>;
69
+ export {};
@@ -0,0 +1,57 @@
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 { EnhancedGenerateContentResponse, FunctionCall, GenerateContentResponse, ImagenGCSImage, ImagenInlineImage, InlineDataPart, Part, InferenceSource } from '../types';
18
+ /**
19
+ * Creates an EnhancedGenerateContentResponse object that has helper functions and
20
+ * other modifications that improve usability.
21
+ */
22
+ export declare function createEnhancedContentResponse(response: GenerateContentResponse, inferenceSource?: InferenceSource): EnhancedGenerateContentResponse;
23
+ /**
24
+ * Adds convenience helper methods to a response object, including stream
25
+ * chunks (as long as each chunk is a complete GenerateContentResponse JSON).
26
+ */
27
+ export declare function addHelpers(response: GenerateContentResponse): EnhancedGenerateContentResponse;
28
+ /**
29
+ * Returns all text from the first candidate's parts, filtering by whether
30
+ * `partFilter()` returns true.
31
+ *
32
+ * @param response - The `GenerateContentResponse` from which to extract text.
33
+ * @param partFilter - Only return `Part`s for which this returns true
34
+ */
35
+ export declare function getText(response: GenerateContentResponse, partFilter: (part: Part) => boolean): string;
36
+ /**
37
+ * Returns every {@link FunctionCall} associated with first candidate.
38
+ */
39
+ export declare function getFunctionCalls(response?: GenerateContentResponse): FunctionCall[] | undefined;
40
+ /**
41
+ * Returns every {@link InlineDataPart} in the first candidate if present.
42
+ *
43
+ * @internal
44
+ */
45
+ export declare function getInlineDataParts(response: GenerateContentResponse): InlineDataPart[] | undefined;
46
+ export declare function formatBlockErrorMessage(response: GenerateContentResponse): string;
47
+ /**
48
+ * Convert a generic successful fetch response body to an Imagen response object
49
+ * that can be returned to the user. This converts the REST APIs response format to our
50
+ * APIs representation of a response.
51
+ *
52
+ * @internal
53
+ */
54
+ export declare function handlePredictResponse<T extends ImagenInlineImage | ImagenGCSImage>(response: Response): Promise<{
55
+ images: T[];
56
+ filteredReason?: string;
57
+ }>;