@firebase/ai 2.7.0-canary.c4a3a5643 → 2.7.0-canary.f9254b6d2
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/ai-public.d.ts +40 -13
- package/dist/ai.d.ts +40 -13
- package/dist/esm/index.esm.js +40 -8
- package/dist/esm/index.esm.js.map +1 -1
- package/dist/esm/src/constants.d.ts +1 -0
- package/dist/esm/src/methods/live-session.d.ts +2 -2
- package/dist/esm/src/types/content.d.ts +4 -4
- package/dist/esm/src/types/enums.d.ts +4 -4
- package/dist/esm/src/types/internal.d.ts +2 -0
- package/dist/esm/src/types/responses.d.ts +29 -4
- package/dist/index.cjs.js +40 -8
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.node.cjs.js +40 -8
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/index.node.mjs +40 -8
- package/dist/index.node.mjs.map +1 -1
- package/dist/src/constants.d.ts +1 -0
- package/dist/src/methods/live-session.d.ts +2 -2
- package/dist/src/types/content.d.ts +4 -4
- package/dist/src/types/enums.d.ts +4 -4
- package/dist/src/types/internal.d.ts +2 -0
- package/dist/src/types/responses.d.ts +29 -4
- package/package.json +8 -8
package/dist/index.node.mjs
CHANGED
|
@@ -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.7.0-canary.
|
|
7
|
+
var version = "2.7.0-canary.f9254b6d2";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* @license
|
|
@@ -28,6 +28,7 @@ const DEFAULT_DOMAIN = 'firebasevertexai.googleapis.com';
|
|
|
28
28
|
const DEFAULT_API_VERSION = 'v1beta';
|
|
29
29
|
const PACKAGE_VERSION = version;
|
|
30
30
|
const LANGUAGE_TAG = 'gl-js';
|
|
31
|
+
const HYBRID_TAG = 'hybrid';
|
|
31
32
|
const DEFAULT_FETCH_TIMEOUT_MS = 180 * 1000;
|
|
32
33
|
/**
|
|
33
34
|
* Defines the name of the default in-cloud model to use for hybrid inference.
|
|
@@ -391,7 +392,7 @@ const InferenceSource = {
|
|
|
391
392
|
/**
|
|
392
393
|
* Represents the result of the code execution.
|
|
393
394
|
*
|
|
394
|
-
* @
|
|
395
|
+
* @public
|
|
395
396
|
*/
|
|
396
397
|
const Outcome = {
|
|
397
398
|
UNSPECIFIED: 'OUTCOME_UNSPECIFIED',
|
|
@@ -402,7 +403,7 @@ const Outcome = {
|
|
|
402
403
|
/**
|
|
403
404
|
* The programming language of the code.
|
|
404
405
|
*
|
|
405
|
-
* @
|
|
406
|
+
* @public
|
|
406
407
|
*/
|
|
407
408
|
const Language = {
|
|
408
409
|
UNSPECIFIED: 'LANGUAGE_UNSPECIFIED',
|
|
@@ -453,7 +454,7 @@ const ThinkingLevel = {
|
|
|
453
454
|
* <b>URL_RETRIEVAL_STATUS_UNSAFE:</b> The URL retrieval failed because the content is unsafe.
|
|
454
455
|
* <br/>
|
|
455
456
|
*
|
|
456
|
-
* @
|
|
457
|
+
* @public
|
|
457
458
|
*/
|
|
458
459
|
const URLRetrievalStatus = {
|
|
459
460
|
/**
|
|
@@ -485,7 +486,8 @@ const URLRetrievalStatus = {
|
|
|
485
486
|
const LiveResponseType = {
|
|
486
487
|
SERVER_CONTENT: 'serverContent',
|
|
487
488
|
TOOL_CALL: 'toolCall',
|
|
488
|
-
TOOL_CALL_CANCELLATION: 'toolCallCancellation'
|
|
489
|
+
TOOL_CALL_CANCELLATION: 'toolCallCancellation',
|
|
490
|
+
GOING_AWAY_NOTICE: 'goingAwayNotice'
|
|
489
491
|
};
|
|
490
492
|
|
|
491
493
|
/**
|
|
@@ -1204,16 +1206,25 @@ class WebSocketUrl {
|
|
|
1204
1206
|
/**
|
|
1205
1207
|
* Log language and "fire/version" to x-goog-api-client
|
|
1206
1208
|
*/
|
|
1207
|
-
function getClientHeaders() {
|
|
1209
|
+
function getClientHeaders(url) {
|
|
1208
1210
|
const loggingTags = [];
|
|
1209
1211
|
loggingTags.push(`${LANGUAGE_TAG}/${PACKAGE_VERSION}`);
|
|
1210
1212
|
loggingTags.push(`fire/${PACKAGE_VERSION}`);
|
|
1213
|
+
/**
|
|
1214
|
+
* No call would be made if ONLY_ON_DEVICE.
|
|
1215
|
+
* ONLY_IN_CLOUD does not indicate an intention to use hybrid.
|
|
1216
|
+
*/
|
|
1217
|
+
if (url.params.apiSettings.inferenceMode === InferenceMode.PREFER_ON_DEVICE ||
|
|
1218
|
+
url.params.apiSettings.inferenceMode === InferenceMode.PREFER_IN_CLOUD) {
|
|
1219
|
+
// No version
|
|
1220
|
+
loggingTags.push(HYBRID_TAG);
|
|
1221
|
+
}
|
|
1211
1222
|
return loggingTags.join(' ');
|
|
1212
1223
|
}
|
|
1213
1224
|
async function getHeaders(url) {
|
|
1214
1225
|
const headers = new Headers();
|
|
1215
1226
|
headers.append('Content-Type', 'application/json');
|
|
1216
|
-
headers.append('x-goog-api-client', getClientHeaders());
|
|
1227
|
+
headers.append('x-goog-api-client', getClientHeaders(url));
|
|
1217
1228
|
headers.append('x-goog-api-key', url.params.apiSettings.apiKey);
|
|
1218
1229
|
if (url.params.apiSettings.automaticDataCollectionEnabled) {
|
|
1219
1230
|
headers.append('X-Firebase-Appid', url.params.apiSettings.appId);
|
|
@@ -2830,6 +2841,13 @@ class LiveSession {
|
|
|
2830
2841
|
...message.toolCallCancellation
|
|
2831
2842
|
};
|
|
2832
2843
|
}
|
|
2844
|
+
else if ('goAway' in message) {
|
|
2845
|
+
const notice = message.goAway;
|
|
2846
|
+
yield {
|
|
2847
|
+
type: LiveResponseType.GOING_AWAY_NOTICE,
|
|
2848
|
+
timeLeft: parseDuration(notice.timeLeft)
|
|
2849
|
+
};
|
|
2850
|
+
}
|
|
2833
2851
|
else {
|
|
2834
2852
|
logger.warn(`Received an unknown message type from the server: ${JSON.stringify(message)}`);
|
|
2835
2853
|
}
|
|
@@ -2908,6 +2926,18 @@ class LiveSession {
|
|
|
2908
2926
|
}
|
|
2909
2927
|
}
|
|
2910
2928
|
}
|
|
2929
|
+
/**
|
|
2930
|
+
* Parses a duration string (e.g. "3.000000001s") into a number of seconds.
|
|
2931
|
+
*
|
|
2932
|
+
* @param duration - The duration string to parse.
|
|
2933
|
+
* @returns The duration in seconds.
|
|
2934
|
+
*/
|
|
2935
|
+
function parseDuration(duration) {
|
|
2936
|
+
if (!duration || !duration.endsWith('s')) {
|
|
2937
|
+
return 0;
|
|
2938
|
+
}
|
|
2939
|
+
return Number(duration.slice(0, -1)); // slice removes the trailing 's'.
|
|
2940
|
+
}
|
|
2911
2941
|
|
|
2912
2942
|
/**
|
|
2913
2943
|
* @license
|
|
@@ -4155,7 +4185,9 @@ function getGenerativeModel(ai, modelParams, requestOptions) {
|
|
|
4155
4185
|
* chromeAdapterFactory() method.
|
|
4156
4186
|
*/
|
|
4157
4187
|
const chromeAdapter = ai.chromeAdapterFactory?.(hybridParams.mode, typeof window === 'undefined' ? undefined : window, hybridParams.onDeviceParams);
|
|
4158
|
-
|
|
4188
|
+
const generativeModel = new GenerativeModel(ai, inCloudParams, requestOptions, chromeAdapter);
|
|
4189
|
+
generativeModel._apiSettings.inferenceMode = hybridParams.mode;
|
|
4190
|
+
return generativeModel;
|
|
4159
4191
|
}
|
|
4160
4192
|
/**
|
|
4161
4193
|
* Returns an {@link ImagenModel} class with methods for using Imagen.
|