@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
package/dist/ai-public.d.ts
CHANGED
|
@@ -165,6 +165,7 @@ declare interface ApiSettings {
|
|
|
165
165
|
backend: Backend;
|
|
166
166
|
getAuthToken?: () => Promise<FirebaseAuthTokenData | null>;
|
|
167
167
|
getAppCheckToken?: () => Promise<AppCheckTokenResult>;
|
|
168
|
+
inferenceMode?: InferenceMode;
|
|
168
169
|
}
|
|
169
170
|
|
|
170
171
|
/**
|
|
@@ -2124,6 +2125,7 @@ export declare const LiveResponseType: {
|
|
|
2124
2125
|
SERVER_CONTENT: string;
|
|
2125
2126
|
TOOL_CALL: string;
|
|
2126
2127
|
TOOL_CALL_CANCELLATION: string;
|
|
2128
|
+
GOING_AWAY_NOTICE: string;
|
|
2127
2129
|
};
|
|
2128
2130
|
|
|
2129
2131
|
/**
|
|
@@ -2166,6 +2168,19 @@ export declare interface LiveServerContent {
|
|
|
2166
2168
|
outputTranscription?: Transcription;
|
|
2167
2169
|
}
|
|
2168
2170
|
|
|
2171
|
+
/**
|
|
2172
|
+
* Notification that the server will not be able to service the client soon.
|
|
2173
|
+
*
|
|
2174
|
+
* @beta
|
|
2175
|
+
*/
|
|
2176
|
+
export declare interface LiveServerGoingAwayNotice {
|
|
2177
|
+
type: 'goingAwayNotice';
|
|
2178
|
+
/**
|
|
2179
|
+
* The remaining time (in seconds) before the connection will be terminated.
|
|
2180
|
+
*/
|
|
2181
|
+
timeLeft: number;
|
|
2182
|
+
}
|
|
2183
|
+
|
|
2169
2184
|
/**
|
|
2170
2185
|
* A request from the model for the client to execute one or more functions.
|
|
2171
2186
|
*
|
|
@@ -2294,7 +2309,7 @@ export declare class LiveSession {
|
|
|
2294
2309
|
*
|
|
2295
2310
|
* @beta
|
|
2296
2311
|
*/
|
|
2297
|
-
receive(): AsyncGenerator<LiveServerContent | LiveServerToolCall | LiveServerToolCallCancellation>;
|
|
2312
|
+
receive(): AsyncGenerator<LiveServerContent | LiveServerToolCall | LiveServerToolCallCancellation | LiveServerGoingAwayNotice>;
|
|
2298
2313
|
/**
|
|
2299
2314
|
* Closes this session.
|
|
2300
2315
|
* All methods on this session will throw an error once this resolves.
|
package/dist/ai.d.ts
CHANGED
|
@@ -202,6 +202,7 @@ declare interface ApiSettings {
|
|
|
202
202
|
backend: Backend;
|
|
203
203
|
getAuthToken?: () => Promise<FirebaseAuthTokenData | null>;
|
|
204
204
|
getAppCheckToken?: () => Promise<AppCheckTokenResult>;
|
|
205
|
+
inferenceMode?: InferenceMode;
|
|
205
206
|
}
|
|
206
207
|
|
|
207
208
|
/**
|
|
@@ -2264,6 +2265,7 @@ export declare const LiveResponseType: {
|
|
|
2264
2265
|
SERVER_CONTENT: string;
|
|
2265
2266
|
TOOL_CALL: string;
|
|
2266
2267
|
TOOL_CALL_CANCELLATION: string;
|
|
2268
|
+
GOING_AWAY_NOTICE: string;
|
|
2267
2269
|
};
|
|
2268
2270
|
|
|
2269
2271
|
/**
|
|
@@ -2306,6 +2308,19 @@ export declare interface LiveServerContent {
|
|
|
2306
2308
|
outputTranscription?: Transcription;
|
|
2307
2309
|
}
|
|
2308
2310
|
|
|
2311
|
+
/**
|
|
2312
|
+
* Notification that the server will not be able to service the client soon.
|
|
2313
|
+
*
|
|
2314
|
+
* @beta
|
|
2315
|
+
*/
|
|
2316
|
+
export declare interface LiveServerGoingAwayNotice {
|
|
2317
|
+
type: 'goingAwayNotice';
|
|
2318
|
+
/**
|
|
2319
|
+
* The remaining time (in seconds) before the connection will be terminated.
|
|
2320
|
+
*/
|
|
2321
|
+
timeLeft: number;
|
|
2322
|
+
}
|
|
2323
|
+
|
|
2309
2324
|
/**
|
|
2310
2325
|
* A request from the model for the client to execute one or more functions.
|
|
2311
2326
|
*
|
|
@@ -2437,7 +2452,7 @@ export declare class LiveSession {
|
|
|
2437
2452
|
*
|
|
2438
2453
|
* @beta
|
|
2439
2454
|
*/
|
|
2440
|
-
receive(): AsyncGenerator<LiveServerContent | LiveServerToolCall | LiveServerToolCallCancellation>;
|
|
2455
|
+
receive(): AsyncGenerator<LiveServerContent | LiveServerToolCall | LiveServerToolCallCancellation | LiveServerGoingAwayNotice>;
|
|
2441
2456
|
/**
|
|
2442
2457
|
* Closes this session.
|
|
2443
2458
|
* All methods on this session will throw an error once this resolves.
|
package/dist/esm/index.esm.js
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.8123231a1";
|
|
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.
|
|
@@ -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
|
/**
|
|
@@ -1512,16 +1514,25 @@ class WebSocketUrl {
|
|
|
1512
1514
|
/**
|
|
1513
1515
|
* Log language and "fire/version" to x-goog-api-client
|
|
1514
1516
|
*/
|
|
1515
|
-
function getClientHeaders() {
|
|
1517
|
+
function getClientHeaders(url) {
|
|
1516
1518
|
const loggingTags = [];
|
|
1517
1519
|
loggingTags.push(`${LANGUAGE_TAG}/${PACKAGE_VERSION}`);
|
|
1518
1520
|
loggingTags.push(`fire/${PACKAGE_VERSION}`);
|
|
1521
|
+
/**
|
|
1522
|
+
* No call would be made if ONLY_ON_DEVICE.
|
|
1523
|
+
* ONLY_IN_CLOUD does not indicate an intention to use hybrid.
|
|
1524
|
+
*/
|
|
1525
|
+
if (url.params.apiSettings.inferenceMode === InferenceMode.PREFER_ON_DEVICE ||
|
|
1526
|
+
url.params.apiSettings.inferenceMode === InferenceMode.PREFER_IN_CLOUD) {
|
|
1527
|
+
// No version
|
|
1528
|
+
loggingTags.push(HYBRID_TAG);
|
|
1529
|
+
}
|
|
1519
1530
|
return loggingTags.join(' ');
|
|
1520
1531
|
}
|
|
1521
1532
|
async function getHeaders(url) {
|
|
1522
1533
|
const headers = new Headers();
|
|
1523
1534
|
headers.append('Content-Type', 'application/json');
|
|
1524
|
-
headers.append('x-goog-api-client', getClientHeaders());
|
|
1535
|
+
headers.append('x-goog-api-client', getClientHeaders(url));
|
|
1525
1536
|
headers.append('x-goog-api-key', url.params.apiSettings.apiKey);
|
|
1526
1537
|
if (url.params.apiSettings.automaticDataCollectionEnabled) {
|
|
1527
1538
|
headers.append('X-Firebase-Appid', url.params.apiSettings.appId);
|
|
@@ -3138,6 +3149,13 @@ class LiveSession {
|
|
|
3138
3149
|
...message.toolCallCancellation
|
|
3139
3150
|
};
|
|
3140
3151
|
}
|
|
3152
|
+
else if ('goAway' in message) {
|
|
3153
|
+
const notice = message.goAway;
|
|
3154
|
+
yield {
|
|
3155
|
+
type: LiveResponseType.GOING_AWAY_NOTICE,
|
|
3156
|
+
timeLeft: parseDuration(notice.timeLeft)
|
|
3157
|
+
};
|
|
3158
|
+
}
|
|
3141
3159
|
else {
|
|
3142
3160
|
logger.warn(`Received an unknown message type from the server: ${JSON.stringify(message)}`);
|
|
3143
3161
|
}
|
|
@@ -3216,6 +3234,18 @@ class LiveSession {
|
|
|
3216
3234
|
}
|
|
3217
3235
|
}
|
|
3218
3236
|
}
|
|
3237
|
+
/**
|
|
3238
|
+
* Parses a duration string (e.g. "3.000000001s") into a number of seconds.
|
|
3239
|
+
*
|
|
3240
|
+
* @param duration - The duration string to parse.
|
|
3241
|
+
* @returns The duration in seconds.
|
|
3242
|
+
*/
|
|
3243
|
+
function parseDuration(duration) {
|
|
3244
|
+
if (!duration || !duration.endsWith('s')) {
|
|
3245
|
+
return 0;
|
|
3246
|
+
}
|
|
3247
|
+
return Number(duration.slice(0, -1)); // slice removes the trailing 's'.
|
|
3248
|
+
}
|
|
3219
3249
|
|
|
3220
3250
|
/**
|
|
3221
3251
|
* @license
|
|
@@ -4463,7 +4493,9 @@ function getGenerativeModel(ai, modelParams, requestOptions) {
|
|
|
4463
4493
|
* chromeAdapterFactory() method.
|
|
4464
4494
|
*/
|
|
4465
4495
|
const chromeAdapter = ai.chromeAdapterFactory?.(hybridParams.mode, typeof window === 'undefined' ? undefined : window, hybridParams.onDeviceParams);
|
|
4466
|
-
|
|
4496
|
+
const generativeModel = new GenerativeModel(ai, inCloudParams, requestOptions, chromeAdapter);
|
|
4497
|
+
generativeModel._apiSettings.inferenceMode = hybridParams.mode;
|
|
4498
|
+
return generativeModel;
|
|
4467
4499
|
}
|
|
4468
4500
|
/**
|
|
4469
4501
|
* Returns an {@link ImagenModel} class with methods for using Imagen.
|