@firebase/ai 2.7.0-canary.65a553baf → 2.7.0-canary.8123231a1
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 +16 -1
- package/dist/ai.d.ts +16 -1
- package/dist/esm/index.esm.js +37 -5
- 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/internal.d.ts +2 -0
- package/dist/esm/src/types/responses.d.ts +13 -0
- package/dist/index.cjs.js +37 -5
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.node.cjs.js +37 -5
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/index.node.mjs +37 -5
- 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/internal.d.ts +2 -0
- package/dist/src/types/responses.d.ts +13 -0
- package/package.json +8 -8
|
@@ -21,6 +21,7 @@ export declare const STAGING_URL = "https://staging-firebasevertexai.sandbox.goo
|
|
|
21
21
|
export declare const DEFAULT_API_VERSION = "v1beta";
|
|
22
22
|
export declare const PACKAGE_VERSION: string;
|
|
23
23
|
export declare const LANGUAGE_TAG = "gl-js";
|
|
24
|
+
export declare const HYBRID_TAG = "hybrid";
|
|
24
25
|
export declare const DEFAULT_FETCH_TIMEOUT_MS: number;
|
|
25
26
|
/**
|
|
26
27
|
* Defines the name of the default in-cloud model to use for hybrid inference.
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
import { FunctionResponse, GenerativeContentBlob, LiveServerContent, LiveServerToolCall, LiveServerToolCallCancellation, Part } from '../public-types';
|
|
17
|
+
import { FunctionResponse, GenerativeContentBlob, LiveServerContent, LiveServerGoingAwayNotice, LiveServerToolCall, LiveServerToolCallCancellation, Part } from '../public-types';
|
|
18
18
|
import { WebSocketHandler } from '../websocket';
|
|
19
19
|
/**
|
|
20
20
|
* Represents an active, real-time, bidirectional conversation with the model.
|
|
@@ -121,7 +121,7 @@ export declare class LiveSession {
|
|
|
121
121
|
*
|
|
122
122
|
* @beta
|
|
123
123
|
*/
|
|
124
|
-
receive(): AsyncGenerator<LiveServerContent | LiveServerToolCall | LiveServerToolCallCancellation>;
|
|
124
|
+
receive(): AsyncGenerator<LiveServerContent | LiveServerToolCall | LiveServerToolCallCancellation | LiveServerGoingAwayNotice>;
|
|
125
125
|
/**
|
|
126
126
|
* Closes this session.
|
|
127
127
|
* All methods on this session will throw an error once this resolves.
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
import { AppCheckTokenResult } from '@firebase/app-check-interop-types';
|
|
18
18
|
import { FirebaseAuthTokenData } from '@firebase/auth-interop-types';
|
|
19
19
|
import { Backend } from '../backend';
|
|
20
|
+
import { InferenceMode } from './enums';
|
|
20
21
|
export * from './imagen/internal';
|
|
21
22
|
export interface ApiSettings {
|
|
22
23
|
apiKey: string;
|
|
@@ -30,4 +31,5 @@ export interface ApiSettings {
|
|
|
30
31
|
backend: Backend;
|
|
31
32
|
getAuthToken?: () => Promise<FirebaseAuthTokenData | null>;
|
|
32
33
|
getAppCheckToken?: () => Promise<AppCheckTokenResult>;
|
|
34
|
+
inferenceMode?: InferenceMode;
|
|
33
35
|
}
|
|
@@ -574,6 +574,18 @@ export interface LiveServerToolCallCancellation {
|
|
|
574
574
|
*/
|
|
575
575
|
functionIds: string[];
|
|
576
576
|
}
|
|
577
|
+
/**
|
|
578
|
+
* Notification that the server will not be able to service the client soon.
|
|
579
|
+
*
|
|
580
|
+
* @beta
|
|
581
|
+
*/
|
|
582
|
+
export interface LiveServerGoingAwayNotice {
|
|
583
|
+
type: 'goingAwayNotice';
|
|
584
|
+
/**
|
|
585
|
+
* The remaining time (in seconds) before the connection will be terminated.
|
|
586
|
+
*/
|
|
587
|
+
timeLeft: number;
|
|
588
|
+
}
|
|
577
589
|
/**
|
|
578
590
|
* The types of responses that can be returned by {@link LiveSession.receive}.
|
|
579
591
|
*
|
|
@@ -583,6 +595,7 @@ export declare const LiveResponseType: {
|
|
|
583
595
|
SERVER_CONTENT: string;
|
|
584
596
|
TOOL_CALL: string;
|
|
585
597
|
TOOL_CALL_CANCELLATION: string;
|
|
598
|
+
GOING_AWAY_NOTICE: string;
|
|
586
599
|
};
|
|
587
600
|
/**
|
|
588
601
|
* The types of responses that can be returned by {@link LiveSession.receive}.
|
package/dist/index.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.8123231a1";
|
|
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.
|
|
@@ -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
|
/**
|
|
@@ -1516,16 +1518,25 @@ class WebSocketUrl {
|
|
|
1516
1518
|
/**
|
|
1517
1519
|
* Log language and "fire/version" to x-goog-api-client
|
|
1518
1520
|
*/
|
|
1519
|
-
function getClientHeaders() {
|
|
1521
|
+
function getClientHeaders(url) {
|
|
1520
1522
|
const loggingTags = [];
|
|
1521
1523
|
loggingTags.push(`${LANGUAGE_TAG}/${PACKAGE_VERSION}`);
|
|
1522
1524
|
loggingTags.push(`fire/${PACKAGE_VERSION}`);
|
|
1525
|
+
/**
|
|
1526
|
+
* No call would be made if ONLY_ON_DEVICE.
|
|
1527
|
+
* ONLY_IN_CLOUD does not indicate an intention to use hybrid.
|
|
1528
|
+
*/
|
|
1529
|
+
if (url.params.apiSettings.inferenceMode === InferenceMode.PREFER_ON_DEVICE ||
|
|
1530
|
+
url.params.apiSettings.inferenceMode === InferenceMode.PREFER_IN_CLOUD) {
|
|
1531
|
+
// No version
|
|
1532
|
+
loggingTags.push(HYBRID_TAG);
|
|
1533
|
+
}
|
|
1523
1534
|
return loggingTags.join(' ');
|
|
1524
1535
|
}
|
|
1525
1536
|
async function getHeaders(url) {
|
|
1526
1537
|
const headers = new Headers();
|
|
1527
1538
|
headers.append('Content-Type', 'application/json');
|
|
1528
|
-
headers.append('x-goog-api-client', getClientHeaders());
|
|
1539
|
+
headers.append('x-goog-api-client', getClientHeaders(url));
|
|
1529
1540
|
headers.append('x-goog-api-key', url.params.apiSettings.apiKey);
|
|
1530
1541
|
if (url.params.apiSettings.automaticDataCollectionEnabled) {
|
|
1531
1542
|
headers.append('X-Firebase-Appid', url.params.apiSettings.appId);
|
|
@@ -3142,6 +3153,13 @@ class LiveSession {
|
|
|
3142
3153
|
...message.toolCallCancellation
|
|
3143
3154
|
};
|
|
3144
3155
|
}
|
|
3156
|
+
else if ('goAway' in message) {
|
|
3157
|
+
const notice = message.goAway;
|
|
3158
|
+
yield {
|
|
3159
|
+
type: LiveResponseType.GOING_AWAY_NOTICE,
|
|
3160
|
+
timeLeft: parseDuration(notice.timeLeft)
|
|
3161
|
+
};
|
|
3162
|
+
}
|
|
3145
3163
|
else {
|
|
3146
3164
|
logger.warn(`Received an unknown message type from the server: ${JSON.stringify(message)}`);
|
|
3147
3165
|
}
|
|
@@ -3220,6 +3238,18 @@ class LiveSession {
|
|
|
3220
3238
|
}
|
|
3221
3239
|
}
|
|
3222
3240
|
}
|
|
3241
|
+
/**
|
|
3242
|
+
* Parses a duration string (e.g. "3.000000001s") into a number of seconds.
|
|
3243
|
+
*
|
|
3244
|
+
* @param duration - The duration string to parse.
|
|
3245
|
+
* @returns The duration in seconds.
|
|
3246
|
+
*/
|
|
3247
|
+
function parseDuration(duration) {
|
|
3248
|
+
if (!duration || !duration.endsWith('s')) {
|
|
3249
|
+
return 0;
|
|
3250
|
+
}
|
|
3251
|
+
return Number(duration.slice(0, -1)); // slice removes the trailing 's'.
|
|
3252
|
+
}
|
|
3223
3253
|
|
|
3224
3254
|
/**
|
|
3225
3255
|
* @license
|
|
@@ -4467,7 +4497,9 @@ function getGenerativeModel(ai, modelParams, requestOptions) {
|
|
|
4467
4497
|
* chromeAdapterFactory() method.
|
|
4468
4498
|
*/
|
|
4469
4499
|
const chromeAdapter = ai.chromeAdapterFactory?.(hybridParams.mode, typeof window === 'undefined' ? undefined : window, hybridParams.onDeviceParams);
|
|
4470
|
-
|
|
4500
|
+
const generativeModel = new GenerativeModel(ai, inCloudParams, requestOptions, chromeAdapter);
|
|
4501
|
+
generativeModel._apiSettings.inferenceMode = hybridParams.mode;
|
|
4502
|
+
return generativeModel;
|
|
4471
4503
|
}
|
|
4472
4504
|
/**
|
|
4473
4505
|
* Returns an {@link ImagenModel} class with methods for using Imagen.
|