@firebase/ai 2.4.0-20251007135320 → 2.4.0-canary.22e0a1adb
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 +87 -9
- package/dist/ai.d.ts +87 -9
- package/dist/esm/index.esm.js +195 -66
- package/dist/esm/index.esm.js.map +1 -1
- package/dist/esm/src/methods/chrome-adapter.d.ts +1 -1
- package/dist/esm/src/methods/live-session.d.ts +64 -9
- package/dist/esm/src/requests/hybrid-helpers.d.ts +7 -2
- package/dist/esm/src/requests/response-helpers.d.ts +2 -2
- package/dist/esm/src/requests/stream-reader.d.ts +2 -1
- package/dist/esm/src/types/enums.d.ts +15 -0
- package/dist/esm/src/types/live-responses.d.ts +7 -1
- package/dist/esm/src/types/responses.d.ts +7 -1
- package/dist/index.cjs.js +195 -65
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.node.cjs.js +175 -58
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/index.node.mjs +175 -59
- package/dist/index.node.mjs.map +1 -1
- package/dist/src/methods/chrome-adapter.d.ts +1 -1
- package/dist/src/methods/live-session.d.ts +64 -9
- package/dist/src/requests/hybrid-helpers.d.ts +7 -2
- package/dist/src/requests/response-helpers.d.ts +2 -2
- package/dist/src/requests/stream-reader.d.ts +2 -1
- package/dist/src/types/enums.d.ts +15 -0
- package/dist/src/types/live-responses.d.ts +7 -1
- package/dist/src/types/responses.d.ts +7 -1
- package/package.json +8 -8
|
@@ -25,11 +25,11 @@ import { LanguageModel } from '../types/language-model';
|
|
|
25
25
|
export declare class ChromeAdapterImpl implements ChromeAdapter {
|
|
26
26
|
languageModelProvider: LanguageModel;
|
|
27
27
|
mode: InferenceMode;
|
|
28
|
-
onDeviceParams: OnDeviceParams;
|
|
29
28
|
static SUPPORTED_MIME_TYPES: string[];
|
|
30
29
|
private isDownloading;
|
|
31
30
|
private downloadPromise;
|
|
32
31
|
private oldSession;
|
|
32
|
+
onDeviceParams: OnDeviceParams;
|
|
33
33
|
constructor(languageModelProvider: LanguageModel, mode: InferenceMode, onDeviceParams?: OnDeviceParams);
|
|
34
34
|
/**
|
|
35
35
|
* Checks if a given request can be made on-device.
|
|
@@ -53,32 +53,65 @@ export declare class LiveSession {
|
|
|
53
53
|
*/
|
|
54
54
|
send(request: string | Array<string | Part>, turnComplete?: boolean): Promise<void>;
|
|
55
55
|
/**
|
|
56
|
-
* Sends
|
|
56
|
+
* Sends text to the server in realtime.
|
|
57
57
|
*
|
|
58
|
-
* @
|
|
58
|
+
* @example
|
|
59
|
+
* ```javascript
|
|
60
|
+
* liveSession.sendTextRealtime("Hello, how are you?");
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @param text - The text data to send.
|
|
59
64
|
* @throws If this session has been closed.
|
|
60
65
|
*
|
|
61
66
|
* @beta
|
|
62
67
|
*/
|
|
63
|
-
|
|
68
|
+
sendTextRealtime(text: string): Promise<void>;
|
|
64
69
|
/**
|
|
65
|
-
* Sends
|
|
70
|
+
* Sends audio data to the server in realtime.
|
|
66
71
|
*
|
|
67
|
-
* @
|
|
72
|
+
* @remarks The server requires that the audio data is base64-encoded 16-bit PCM at 16kHz
|
|
73
|
+
* little-endian.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```javascript
|
|
77
|
+
* // const pcmData = ... base64-encoded 16-bit PCM at 16kHz little-endian.
|
|
78
|
+
* const blob = { mimeType: "audio/pcm", data: pcmData };
|
|
79
|
+
* liveSession.sendAudioRealtime(blob);
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @param blob - The base64-encoded PCM data to send to the server in realtime.
|
|
68
83
|
* @throws If this session has been closed.
|
|
69
84
|
*
|
|
70
85
|
* @beta
|
|
71
86
|
*/
|
|
72
|
-
|
|
87
|
+
sendAudioRealtime(blob: GenerativeContentBlob): Promise<void>;
|
|
73
88
|
/**
|
|
74
|
-
* Sends
|
|
89
|
+
* Sends video data to the server in realtime.
|
|
75
90
|
*
|
|
76
|
-
* @
|
|
91
|
+
* @remarks The server requires that the video is sent as individual video frames at 1 FPS. It
|
|
92
|
+
* is recommended to set `mimeType` to `image/jpeg`.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```javascript
|
|
96
|
+
* // const videoFrame = ... base64-encoded JPEG data
|
|
97
|
+
* const blob = { mimeType: "image/jpeg", data: videoFrame };
|
|
98
|
+
* liveSession.sendVideoRealtime(blob);
|
|
99
|
+
* ```
|
|
100
|
+
* @param blob - The base64-encoded video data to send to the server in realtime.
|
|
77
101
|
* @throws If this session has been closed.
|
|
78
102
|
*
|
|
79
103
|
* @beta
|
|
80
104
|
*/
|
|
81
|
-
|
|
105
|
+
sendVideoRealtime(blob: GenerativeContentBlob): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Sends function responses to the server.
|
|
108
|
+
*
|
|
109
|
+
* @param functionResponses - The function responses to send.
|
|
110
|
+
* @throws If this session has been closed.
|
|
111
|
+
*
|
|
112
|
+
* @beta
|
|
113
|
+
*/
|
|
114
|
+
sendFunctionResponses(functionResponses: FunctionResponse[]): Promise<void>;
|
|
82
115
|
/**
|
|
83
116
|
* Yields messages received from the server.
|
|
84
117
|
* This can only be used by one consumer at a time.
|
|
@@ -96,4 +129,26 @@ export declare class LiveSession {
|
|
|
96
129
|
* @beta
|
|
97
130
|
*/
|
|
98
131
|
close(): Promise<void>;
|
|
132
|
+
/**
|
|
133
|
+
* Sends realtime input to the server.
|
|
134
|
+
*
|
|
135
|
+
* @deprecated Use `sendTextRealtime()`, `sendAudioRealtime()`, and `sendVideoRealtime()` instead.
|
|
136
|
+
*
|
|
137
|
+
* @param mediaChunks - The media chunks to send.
|
|
138
|
+
* @throws If this session has been closed.
|
|
139
|
+
*
|
|
140
|
+
* @beta
|
|
141
|
+
*/
|
|
142
|
+
sendMediaChunks(mediaChunks: GenerativeContentBlob[]): Promise<void>;
|
|
143
|
+
/**
|
|
144
|
+
* @deprecated Use `sendTextRealtime()`, `sendAudioRealtime()`, and `sendVideoRealtime()` instead.
|
|
145
|
+
*
|
|
146
|
+
* Sends a stream of {@link GenerativeContentBlob}.
|
|
147
|
+
*
|
|
148
|
+
* @param mediaChunkStream - The stream of {@link GenerativeContentBlob} to send.
|
|
149
|
+
* @throws If this session has been closed.
|
|
150
|
+
*
|
|
151
|
+
* @beta
|
|
152
|
+
*/
|
|
153
|
+
sendMediaStream(mediaChunkStream: ReadableStream<GenerativeContentBlob>): Promise<void>;
|
|
99
154
|
}
|
|
@@ -14,7 +14,11 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
import { GenerateContentRequest, ChromeAdapter } from '../types';
|
|
17
|
+
import { GenerateContentRequest, ChromeAdapter, InferenceSource } from '../types';
|
|
18
|
+
interface CallResult<Response> {
|
|
19
|
+
response: Response;
|
|
20
|
+
inferenceSource: InferenceSource;
|
|
21
|
+
}
|
|
18
22
|
/**
|
|
19
23
|
* Dispatches a request to the appropriate backend (on-device or in-cloud)
|
|
20
24
|
* based on the inference mode.
|
|
@@ -25,4 +29,5 @@ import { GenerateContentRequest, ChromeAdapter } from '../types';
|
|
|
25
29
|
* @param inCloudCall - The function to call for in-cloud inference.
|
|
26
30
|
* @returns The response from the backend.
|
|
27
31
|
*/
|
|
28
|
-
export declare function callCloudOrDevice<Response>(request: GenerateContentRequest, chromeAdapter: ChromeAdapter | undefined, onDeviceCall: () => Promise<Response>, inCloudCall: () => Promise<Response>): Promise<Response
|
|
32
|
+
export declare function callCloudOrDevice<Response>(request: GenerateContentRequest, chromeAdapter: ChromeAdapter | undefined, onDeviceCall: () => Promise<Response>, inCloudCall: () => Promise<Response>): Promise<CallResult<Response>>;
|
|
33
|
+
export {};
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
import { EnhancedGenerateContentResponse, FunctionCall, GenerateContentResponse, ImagenGCSImage, ImagenInlineImage, InlineDataPart, Part } from '../types';
|
|
17
|
+
import { EnhancedGenerateContentResponse, FunctionCall, GenerateContentResponse, ImagenGCSImage, ImagenInlineImage, InlineDataPart, Part, InferenceSource } from '../types';
|
|
18
18
|
/**
|
|
19
19
|
* Creates an EnhancedGenerateContentResponse object that has helper functions and
|
|
20
20
|
* other modifications that improve usability.
|
|
21
21
|
*/
|
|
22
|
-
export declare function createEnhancedContentResponse(response: GenerateContentResponse): EnhancedGenerateContentResponse;
|
|
22
|
+
export declare function createEnhancedContentResponse(response: GenerateContentResponse, inferenceSource?: InferenceSource): EnhancedGenerateContentResponse;
|
|
23
23
|
/**
|
|
24
24
|
* Adds convenience helper methods to a response object, including stream
|
|
25
25
|
* chunks (as long as each chunk is a complete GenerateContentResponse JSON).
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import { GenerateContentResponse, GenerateContentStreamResult } from '../types';
|
|
18
18
|
import { ApiSettings } from '../types/internal';
|
|
19
|
+
import { InferenceSource } from '../public-types';
|
|
19
20
|
/**
|
|
20
21
|
* Process a response.body stream from the backend and return an
|
|
21
22
|
* iterator that provides one complete GenerateContentResponse at a time
|
|
@@ -24,7 +25,7 @@ import { ApiSettings } from '../types/internal';
|
|
|
24
25
|
*
|
|
25
26
|
* @param response - Response from a fetch call
|
|
26
27
|
*/
|
|
27
|
-
export declare function processStream(response: Response, apiSettings: ApiSettings): GenerateContentStreamResult;
|
|
28
|
+
export declare function processStream(response: Response, apiSettings: ApiSettings, inferenceSource?: InferenceSource): GenerateContentStreamResult;
|
|
28
29
|
/**
|
|
29
30
|
* Reads a raw stream from the fetch response and join incomplete
|
|
30
31
|
* chunks, returning a new stream that provides a single complete
|
|
@@ -349,6 +349,21 @@ export declare const InferenceMode: {
|
|
|
349
349
|
* @beta
|
|
350
350
|
*/
|
|
351
351
|
export type InferenceMode = (typeof InferenceMode)[keyof typeof InferenceMode];
|
|
352
|
+
/**
|
|
353
|
+
* Indicates whether inference happened on-device or in-cloud.
|
|
354
|
+
*
|
|
355
|
+
* @beta
|
|
356
|
+
*/
|
|
357
|
+
export declare const InferenceSource: {
|
|
358
|
+
readonly ON_DEVICE: "on_device";
|
|
359
|
+
readonly IN_CLOUD: "in_cloud";
|
|
360
|
+
};
|
|
361
|
+
/**
|
|
362
|
+
* Indicates whether inference happened on-device or in-cloud.
|
|
363
|
+
*
|
|
364
|
+
* @beta
|
|
365
|
+
*/
|
|
366
|
+
export type InferenceSource = (typeof InferenceSource)[keyof typeof InferenceSource];
|
|
352
367
|
/**
|
|
353
368
|
* Represents the result of the code execution.
|
|
354
369
|
*
|
|
@@ -34,7 +34,13 @@ export interface _LiveClientContent {
|
|
|
34
34
|
*/
|
|
35
35
|
export interface _LiveClientRealtimeInput {
|
|
36
36
|
realtimeInput: {
|
|
37
|
-
|
|
37
|
+
text?: string;
|
|
38
|
+
audio?: GenerativeContentBlob;
|
|
39
|
+
video?: GenerativeContentBlob;
|
|
40
|
+
/**
|
|
41
|
+
* @deprecated Use `text`, `audio`, and `video` instead.
|
|
42
|
+
*/
|
|
43
|
+
mediaChunks?: GenerativeContentBlob[];
|
|
38
44
|
};
|
|
39
45
|
}
|
|
40
46
|
/**
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
import { Content, FunctionCall, InlineDataPart } from './content';
|
|
18
|
-
import { BlockReason, FinishReason, HarmCategory, HarmProbability, HarmSeverity, Modality } from './enums';
|
|
18
|
+
import { BlockReason, FinishReason, HarmCategory, HarmProbability, HarmSeverity, InferenceSource, Modality } from './enums';
|
|
19
19
|
/**
|
|
20
20
|
* Result object returned from {@link GenerativeModel.generateContent} call.
|
|
21
21
|
*
|
|
@@ -76,6 +76,12 @@ export interface EnhancedGenerateContentResponse extends GenerateContentResponse
|
|
|
76
76
|
* set to `true`.
|
|
77
77
|
*/
|
|
78
78
|
thoughtSummary: () => string | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Indicates whether inference happened on-device or in-cloud.
|
|
81
|
+
*
|
|
82
|
+
* @beta
|
|
83
|
+
*/
|
|
84
|
+
inferenceSource?: InferenceSource;
|
|
79
85
|
}
|
|
80
86
|
/**
|
|
81
87
|
* Individual response from {@link GenerativeModel.generateContent} and
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firebase/ai",
|
|
3
|
-
"version": "2.4.0-
|
|
3
|
+
"version": "2.4.0-canary.22e0a1adb",
|
|
4
4
|
"description": "The Firebase AI SDK",
|
|
5
5
|
"author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",
|
|
6
6
|
"engines": {
|
|
@@ -48,19 +48,19 @@
|
|
|
48
48
|
"trusted-type-check": "tsec -p tsconfig.json --noEmit"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@firebase/app": "0.
|
|
52
|
-
"@firebase/app-types": "0.
|
|
51
|
+
"@firebase/app": "0.14.4-canary.22e0a1adb",
|
|
52
|
+
"@firebase/app-types": "0.9.3-canary.22e0a1adb"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@firebase/app-check-interop-types": "0.3.3",
|
|
56
|
-
"@firebase/component": "0.7.0",
|
|
57
|
-
"@firebase/logger": "0.5.0",
|
|
58
|
-
"@firebase/util": "1.13.0",
|
|
55
|
+
"@firebase/app-check-interop-types": "0.3.3-canary.22e0a1adb",
|
|
56
|
+
"@firebase/component": "0.7.0-canary.22e0a1adb",
|
|
57
|
+
"@firebase/logger": "0.5.0-canary.22e0a1adb",
|
|
58
|
+
"@firebase/util": "1.13.0-canary.22e0a1adb",
|
|
59
59
|
"tslib": "^2.1.0"
|
|
60
60
|
},
|
|
61
61
|
"license": "Apache-2.0",
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@firebase/app": "0.14.
|
|
63
|
+
"@firebase/app": "0.14.4-canary.22e0a1adb",
|
|
64
64
|
"@rollup/plugin-json": "6.1.0",
|
|
65
65
|
"rollup": "2.79.2",
|
|
66
66
|
"rollup-plugin-replace": "2.2.0",
|