@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.cjs.js
CHANGED
|
@@ -8,7 +8,7 @@ var util = require('@firebase/util');
|
|
|
8
8
|
var logger$1 = require('@firebase/logger');
|
|
9
9
|
|
|
10
10
|
var name = "@firebase/ai";
|
|
11
|
-
var version = "2.7.0-canary.
|
|
11
|
+
var version = "2.7.0-canary.f9254b6d2";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* @license
|
|
@@ -32,6 +32,7 @@ const DEFAULT_DOMAIN = 'firebasevertexai.googleapis.com';
|
|
|
32
32
|
const DEFAULT_API_VERSION = 'v1beta';
|
|
33
33
|
const PACKAGE_VERSION = version;
|
|
34
34
|
const LANGUAGE_TAG = 'gl-js';
|
|
35
|
+
const HYBRID_TAG = 'hybrid';
|
|
35
36
|
const DEFAULT_FETCH_TIMEOUT_MS = 180 * 1000;
|
|
36
37
|
/**
|
|
37
38
|
* Defines the name of the default in-cloud model to use for hybrid inference.
|
|
@@ -395,7 +396,7 @@ const InferenceSource = {
|
|
|
395
396
|
/**
|
|
396
397
|
* Represents the result of the code execution.
|
|
397
398
|
*
|
|
398
|
-
* @
|
|
399
|
+
* @public
|
|
399
400
|
*/
|
|
400
401
|
const Outcome = {
|
|
401
402
|
UNSPECIFIED: 'OUTCOME_UNSPECIFIED',
|
|
@@ -406,7 +407,7 @@ const Outcome = {
|
|
|
406
407
|
/**
|
|
407
408
|
* The programming language of the code.
|
|
408
409
|
*
|
|
409
|
-
* @
|
|
410
|
+
* @public
|
|
410
411
|
*/
|
|
411
412
|
const Language = {
|
|
412
413
|
UNSPECIFIED: 'LANGUAGE_UNSPECIFIED',
|
|
@@ -457,7 +458,7 @@ const ThinkingLevel = {
|
|
|
457
458
|
* <b>URL_RETRIEVAL_STATUS_UNSAFE:</b> The URL retrieval failed because the content is unsafe.
|
|
458
459
|
* <br/>
|
|
459
460
|
*
|
|
460
|
-
* @
|
|
461
|
+
* @public
|
|
461
462
|
*/
|
|
462
463
|
const URLRetrievalStatus = {
|
|
463
464
|
/**
|
|
@@ -489,7 +490,8 @@ const URLRetrievalStatus = {
|
|
|
489
490
|
const LiveResponseType = {
|
|
490
491
|
SERVER_CONTENT: 'serverContent',
|
|
491
492
|
TOOL_CALL: 'toolCall',
|
|
492
|
-
TOOL_CALL_CANCELLATION: 'toolCallCancellation'
|
|
493
|
+
TOOL_CALL_CANCELLATION: 'toolCallCancellation',
|
|
494
|
+
GOING_AWAY_NOTICE: 'goingAwayNotice'
|
|
493
495
|
};
|
|
494
496
|
|
|
495
497
|
/**
|
|
@@ -1208,16 +1210,25 @@ class WebSocketUrl {
|
|
|
1208
1210
|
/**
|
|
1209
1211
|
* Log language and "fire/version" to x-goog-api-client
|
|
1210
1212
|
*/
|
|
1211
|
-
function getClientHeaders() {
|
|
1213
|
+
function getClientHeaders(url) {
|
|
1212
1214
|
const loggingTags = [];
|
|
1213
1215
|
loggingTags.push(`${LANGUAGE_TAG}/${PACKAGE_VERSION}`);
|
|
1214
1216
|
loggingTags.push(`fire/${PACKAGE_VERSION}`);
|
|
1217
|
+
/**
|
|
1218
|
+
* No call would be made if ONLY_ON_DEVICE.
|
|
1219
|
+
* ONLY_IN_CLOUD does not indicate an intention to use hybrid.
|
|
1220
|
+
*/
|
|
1221
|
+
if (url.params.apiSettings.inferenceMode === InferenceMode.PREFER_ON_DEVICE ||
|
|
1222
|
+
url.params.apiSettings.inferenceMode === InferenceMode.PREFER_IN_CLOUD) {
|
|
1223
|
+
// No version
|
|
1224
|
+
loggingTags.push(HYBRID_TAG);
|
|
1225
|
+
}
|
|
1215
1226
|
return loggingTags.join(' ');
|
|
1216
1227
|
}
|
|
1217
1228
|
async function getHeaders(url) {
|
|
1218
1229
|
const headers = new Headers();
|
|
1219
1230
|
headers.append('Content-Type', 'application/json');
|
|
1220
|
-
headers.append('x-goog-api-client', getClientHeaders());
|
|
1231
|
+
headers.append('x-goog-api-client', getClientHeaders(url));
|
|
1221
1232
|
headers.append('x-goog-api-key', url.params.apiSettings.apiKey);
|
|
1222
1233
|
if (url.params.apiSettings.automaticDataCollectionEnabled) {
|
|
1223
1234
|
headers.append('X-Firebase-Appid', url.params.apiSettings.appId);
|
|
@@ -2834,6 +2845,13 @@ class LiveSession {
|
|
|
2834
2845
|
...message.toolCallCancellation
|
|
2835
2846
|
};
|
|
2836
2847
|
}
|
|
2848
|
+
else if ('goAway' in message) {
|
|
2849
|
+
const notice = message.goAway;
|
|
2850
|
+
yield {
|
|
2851
|
+
type: LiveResponseType.GOING_AWAY_NOTICE,
|
|
2852
|
+
timeLeft: parseDuration(notice.timeLeft)
|
|
2853
|
+
};
|
|
2854
|
+
}
|
|
2837
2855
|
else {
|
|
2838
2856
|
logger.warn(`Received an unknown message type from the server: ${JSON.stringify(message)}`);
|
|
2839
2857
|
}
|
|
@@ -2912,6 +2930,18 @@ class LiveSession {
|
|
|
2912
2930
|
}
|
|
2913
2931
|
}
|
|
2914
2932
|
}
|
|
2933
|
+
/**
|
|
2934
|
+
* Parses a duration string (e.g. "3.000000001s") into a number of seconds.
|
|
2935
|
+
*
|
|
2936
|
+
* @param duration - The duration string to parse.
|
|
2937
|
+
* @returns The duration in seconds.
|
|
2938
|
+
*/
|
|
2939
|
+
function parseDuration(duration) {
|
|
2940
|
+
if (!duration || !duration.endsWith('s')) {
|
|
2941
|
+
return 0;
|
|
2942
|
+
}
|
|
2943
|
+
return Number(duration.slice(0, -1)); // slice removes the trailing 's'.
|
|
2944
|
+
}
|
|
2915
2945
|
|
|
2916
2946
|
/**
|
|
2917
2947
|
* @license
|
|
@@ -4159,7 +4189,9 @@ function getGenerativeModel(ai, modelParams, requestOptions) {
|
|
|
4159
4189
|
* chromeAdapterFactory() method.
|
|
4160
4190
|
*/
|
|
4161
4191
|
const chromeAdapter = ai.chromeAdapterFactory?.(hybridParams.mode, typeof window === 'undefined' ? undefined : window, hybridParams.onDeviceParams);
|
|
4162
|
-
|
|
4192
|
+
const generativeModel = new GenerativeModel(ai, inCloudParams, requestOptions, chromeAdapter);
|
|
4193
|
+
generativeModel._apiSettings.inferenceMode = hybridParams.mode;
|
|
4194
|
+
return generativeModel;
|
|
4163
4195
|
}
|
|
4164
4196
|
/**
|
|
4165
4197
|
* Returns an {@link ImagenModel} class with methods for using Imagen.
|