@firebase/ai 2.1.0 → 2.2.0-canary.095c098de
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 +443 -10
- package/dist/ai.d.ts +525 -11
- package/dist/esm/index.esm.js +1255 -368
- package/dist/esm/index.esm.js.map +1 -1
- package/dist/esm/src/api.d.ts +18 -3
- package/dist/esm/src/constants.d.ts +1 -1
- package/dist/esm/src/index.d.ts +2 -1
- package/dist/esm/src/methods/chrome-adapter.d.ts +30 -24
- package/dist/esm/src/methods/live-session-helpers.d.ts +154 -0
- package/dist/esm/src/methods/live-session.d.ts +90 -0
- package/dist/esm/src/models/ai-model.d.ts +1 -1
- package/dist/esm/src/models/index.d.ts +1 -0
- package/dist/esm/src/models/live-generative-model.d.ts +55 -0
- package/dist/esm/src/public-types.d.ts +10 -1
- package/dist/esm/src/requests/request.d.ts +6 -0
- package/dist/esm/src/requests/response-helpers.d.ts +9 -5
- package/dist/esm/src/service.d.ts +7 -2
- package/dist/esm/src/types/chrome-adapter.d.ts +6 -4
- package/dist/esm/src/types/content.d.ts +42 -0
- package/dist/esm/src/types/enums.d.ts +5 -0
- package/dist/esm/src/types/error.d.ts +2 -0
- package/dist/esm/src/types/imagen/internal.d.ts +10 -0
- package/dist/esm/src/types/live-responses.d.ts +53 -0
- package/dist/esm/src/types/requests.d.ts +109 -1
- package/dist/esm/src/types/responses.d.ts +87 -4
- package/dist/esm/src/websocket.d.ts +67 -0
- package/dist/index.cjs.js +1258 -366
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.node.cjs.js +907 -311
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/index.node.mjs +904 -313
- package/dist/index.node.mjs.map +1 -1
- package/dist/src/api.d.ts +18 -3
- package/dist/src/constants.d.ts +1 -1
- package/dist/src/index.d.ts +2 -1
- package/dist/src/methods/chrome-adapter.d.ts +30 -24
- package/dist/src/methods/live-session-helpers.d.ts +154 -0
- package/dist/src/methods/live-session.d.ts +90 -0
- package/dist/src/models/ai-model.d.ts +1 -1
- package/dist/src/models/index.d.ts +1 -0
- package/dist/src/models/live-generative-model.d.ts +55 -0
- package/dist/src/public-types.d.ts +10 -1
- package/dist/src/requests/request.d.ts +6 -0
- package/dist/src/requests/response-helpers.d.ts +9 -5
- package/dist/src/service.d.ts +7 -2
- package/dist/src/types/chrome-adapter.d.ts +6 -4
- package/dist/src/types/content.d.ts +42 -0
- package/dist/src/types/enums.d.ts +5 -0
- package/dist/src/types/error.d.ts +2 -0
- package/dist/src/types/imagen/internal.d.ts +10 -0
- package/dist/src/types/live-responses.d.ts +53 -0
- package/dist/src/types/requests.d.ts +109 -1
- package/dist/src/types/responses.d.ts +87 -4
- package/dist/src/websocket.d.ts +67 -0
- package/package.json +10 -8
package/dist/ai-public.d.ts
CHANGED
|
@@ -27,6 +27,10 @@ export declare interface AI {
|
|
|
27
27
|
* Vertex AI Gemini API (using {@link VertexAIBackend}).
|
|
28
28
|
*/
|
|
29
29
|
backend: Backend;
|
|
30
|
+
/**
|
|
31
|
+
* Options applied to this {@link AI} instance.
|
|
32
|
+
*/
|
|
33
|
+
options?: AIOptions;
|
|
30
34
|
/**
|
|
31
35
|
* @deprecated use `AI.backend.location` instead.
|
|
32
36
|
*
|
|
@@ -67,6 +71,8 @@ export declare const AIErrorCode: {
|
|
|
67
71
|
readonly RESPONSE_ERROR: "response-error";
|
|
68
72
|
/** An error occurred while performing a fetch. */
|
|
69
73
|
readonly FETCH_ERROR: "fetch-error";
|
|
74
|
+
/** An error occurred because an operation was attempted on a closed session. */
|
|
75
|
+
readonly SESSION_CLOSED: "session-closed";
|
|
70
76
|
/** An error associated with a Content object. */
|
|
71
77
|
readonly INVALID_CONTENT: "invalid-content";
|
|
72
78
|
/** An error due to the Firebase API not being enabled in the Console. */
|
|
@@ -125,8 +131,13 @@ export declare abstract class AIModel {
|
|
|
125
131
|
export declare interface AIOptions {
|
|
126
132
|
/**
|
|
127
133
|
* The backend configuration to use for the AI service instance.
|
|
134
|
+
* Defaults to the Gemini Developer API backend ({@link GoogleAIBackend}).
|
|
128
135
|
*/
|
|
129
|
-
backend
|
|
136
|
+
backend?: Backend;
|
|
137
|
+
/**
|
|
138
|
+
* Whether to use App Check limited use tokens. Defaults to false.
|
|
139
|
+
*/
|
|
140
|
+
useLimitedUseAppCheckTokens?: boolean;
|
|
130
141
|
}
|
|
131
142
|
|
|
132
143
|
/**
|
|
@@ -168,6 +179,19 @@ export declare class ArraySchema extends Schema {
|
|
|
168
179
|
/* Excluded from this release type: toJSON */
|
|
169
180
|
}
|
|
170
181
|
|
|
182
|
+
/**
|
|
183
|
+
* A controller for managing an active audio conversation.
|
|
184
|
+
*
|
|
185
|
+
* @beta
|
|
186
|
+
*/
|
|
187
|
+
export declare interface AudioConversationController {
|
|
188
|
+
/**
|
|
189
|
+
* Stops the audio conversation, closes the microphone connection, and
|
|
190
|
+
* cleans up resources. Returns a promise that resolves when cleanup is complete.
|
|
191
|
+
*/
|
|
192
|
+
stop: () => Promise<void>;
|
|
193
|
+
}
|
|
194
|
+
|
|
171
195
|
/**
|
|
172
196
|
* Abstract base class representing the configuration for an AI service backend.
|
|
173
197
|
* This class should not be instantiated directly. Use its subclasses; {@link GoogleAIBackend} for
|
|
@@ -320,16 +344,18 @@ export declare interface ChromeAdapter {
|
|
|
320
344
|
/**
|
|
321
345
|
* Generates content using on-device inference.
|
|
322
346
|
*
|
|
323
|
-
*
|
|
324
|
-
*
|
|
347
|
+
* @remarks
|
|
348
|
+
* This is comparable to {@link GenerativeModel.generateContent} for generating
|
|
349
|
+
* content using in-cloud inference.
|
|
325
350
|
* @param request - a standard Firebase AI {@link GenerateContentRequest}
|
|
326
351
|
*/
|
|
327
352
|
generateContent(request: GenerateContentRequest): Promise<Response>;
|
|
328
353
|
/**
|
|
329
354
|
* Generates a content stream using on-device inference.
|
|
330
355
|
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
356
|
+
* @remarks
|
|
357
|
+
* This is comparable to {@link GenerativeModel.generateContentStream} for generating
|
|
358
|
+
* a content stream using in-cloud inference.
|
|
333
359
|
* @param request - a standard Firebase AI {@link GenerateContentRequest}
|
|
334
360
|
*/
|
|
335
361
|
generateContentStream(request: GenerateContentRequest): Promise<Response>;
|
|
@@ -457,15 +483,34 @@ export declare interface EnhancedGenerateContentResponse extends GenerateContent
|
|
|
457
483
|
*/
|
|
458
484
|
text: () => string;
|
|
459
485
|
/**
|
|
460
|
-
* Aggregates and returns
|
|
461
|
-
*
|
|
462
|
-
*
|
|
463
|
-
* @returns An array of {@link InlineDataPart}s containing data from the response, if available.
|
|
486
|
+
* Aggregates and returns every {@link InlineDataPart} from the first candidate of
|
|
487
|
+
* {@link GenerateContentResponse}.
|
|
464
488
|
*
|
|
465
489
|
* @throws If the prompt or candidate was blocked.
|
|
466
490
|
*/
|
|
467
491
|
inlineDataParts: () => InlineDataPart[] | undefined;
|
|
492
|
+
/**
|
|
493
|
+
* Aggregates and returns every {@link FunctionCall} from the first candidate of
|
|
494
|
+
* {@link GenerateContentResponse}.
|
|
495
|
+
*
|
|
496
|
+
* @throws If the prompt or candidate was blocked.
|
|
497
|
+
*/
|
|
468
498
|
functionCalls: () => FunctionCall[] | undefined;
|
|
499
|
+
/**
|
|
500
|
+
* Aggregates and returns every {@link TextPart} with their `thought` property set
|
|
501
|
+
* to `true` from the first candidate of {@link GenerateContentResponse}.
|
|
502
|
+
*
|
|
503
|
+
* @throws If the prompt or candidate was blocked.
|
|
504
|
+
*
|
|
505
|
+
* @remarks
|
|
506
|
+
* Thought summaries provide a brief overview of the model's internal thinking process,
|
|
507
|
+
* offering insight into how it arrived at the final answer. This can be useful for
|
|
508
|
+
* debugging, understanding the model's reasoning, and verifying its accuracy.
|
|
509
|
+
*
|
|
510
|
+
* Thoughts will only be included if {@link ThinkingConfig.includeThoughts} is
|
|
511
|
+
* set to `true`.
|
|
512
|
+
*/
|
|
513
|
+
thoughtSummary: () => string | undefined;
|
|
469
514
|
}
|
|
470
515
|
|
|
471
516
|
/**
|
|
@@ -504,6 +549,8 @@ export declare interface FileDataPart {
|
|
|
504
549
|
functionCall?: never;
|
|
505
550
|
functionResponse?: never;
|
|
506
551
|
fileData: FileData;
|
|
552
|
+
thought?: boolean;
|
|
553
|
+
/* Excluded from this release type: thoughtSignature */
|
|
507
554
|
}
|
|
508
555
|
|
|
509
556
|
/**
|
|
@@ -562,6 +609,15 @@ export declare type FinishReason = (typeof FinishReason)[keyof typeof FinishReas
|
|
|
562
609
|
* @public
|
|
563
610
|
*/
|
|
564
611
|
export declare interface FunctionCall {
|
|
612
|
+
/**
|
|
613
|
+
* The id of the function call. This must be sent back in the associated {@link FunctionResponse}.
|
|
614
|
+
*
|
|
615
|
+
*
|
|
616
|
+
* @remarks This property is only supported in the Gemini Developer API ({@link GoogleAIBackend}).
|
|
617
|
+
* When using the Gemini Developer API ({@link GoogleAIBackend}), this property will be
|
|
618
|
+
* `undefined`.
|
|
619
|
+
*/
|
|
620
|
+
id?: string;
|
|
565
621
|
name: string;
|
|
566
622
|
args: object;
|
|
567
623
|
}
|
|
@@ -611,6 +667,8 @@ export declare interface FunctionCallPart {
|
|
|
611
667
|
inlineData?: never;
|
|
612
668
|
functionCall: FunctionCall;
|
|
613
669
|
functionResponse?: never;
|
|
670
|
+
thought?: boolean;
|
|
671
|
+
/* Excluded from this release type: thoughtSignature */
|
|
614
672
|
}
|
|
615
673
|
|
|
616
674
|
/**
|
|
@@ -672,6 +730,14 @@ export declare interface FunctionDeclarationsTool {
|
|
|
672
730
|
* @public
|
|
673
731
|
*/
|
|
674
732
|
export declare interface FunctionResponse {
|
|
733
|
+
/**
|
|
734
|
+
* The id of the {@link FunctionCall}.
|
|
735
|
+
*
|
|
736
|
+
* @remarks This property is only supported in the Gemini Developer API ({@link GoogleAIBackend}).
|
|
737
|
+
* When using the Gemini Developer API ({@link GoogleAIBackend}), this property will be
|
|
738
|
+
* `undefined`.
|
|
739
|
+
*/
|
|
740
|
+
id?: string;
|
|
675
741
|
name: string;
|
|
676
742
|
response: object;
|
|
677
743
|
}
|
|
@@ -685,6 +751,8 @@ export declare interface FunctionResponsePart {
|
|
|
685
751
|
inlineData?: never;
|
|
686
752
|
functionCall?: never;
|
|
687
753
|
functionResponse: FunctionResponse;
|
|
754
|
+
thought?: boolean;
|
|
755
|
+
/* Excluded from this release type: thoughtSignature */
|
|
688
756
|
}
|
|
689
757
|
|
|
690
758
|
/**
|
|
@@ -894,6 +962,20 @@ export declare function getGenerativeModel(ai: AI, modelParams: ModelParams | Hy
|
|
|
894
962
|
*/
|
|
895
963
|
export declare function getImagenModel(ai: AI, modelParams: ImagenModelParams, requestOptions?: RequestOptions): ImagenModel;
|
|
896
964
|
|
|
965
|
+
/**
|
|
966
|
+
* Returns a {@link LiveGenerativeModel} class for real-time, bidirectional communication.
|
|
967
|
+
*
|
|
968
|
+
* The Live API is only supported in modern browser windows and Node >= 22.
|
|
969
|
+
*
|
|
970
|
+
* @param ai - An {@link AI} instance.
|
|
971
|
+
* @param modelParams - Parameters to use when setting up a {@link LiveSession}.
|
|
972
|
+
* @throws If the `apiKey` or `projectId` fields are missing in your
|
|
973
|
+
* Firebase config.
|
|
974
|
+
*
|
|
975
|
+
* @beta
|
|
976
|
+
*/
|
|
977
|
+
export declare function getLiveGenerativeModel(ai: AI, modelParams: LiveModelParams): LiveGenerativeModel;
|
|
978
|
+
|
|
897
979
|
/**
|
|
898
980
|
* Configuration class for the Gemini Developer API.
|
|
899
981
|
*
|
|
@@ -1663,6 +1745,8 @@ export declare interface InlineDataPart {
|
|
|
1663
1745
|
* Applicable if `inlineData` is a video.
|
|
1664
1746
|
*/
|
|
1665
1747
|
videoMetadata?: VideoMetadata;
|
|
1748
|
+
thought?: boolean;
|
|
1749
|
+
/* Excluded from this release type: thoughtSignature */
|
|
1666
1750
|
}
|
|
1667
1751
|
|
|
1668
1752
|
/**
|
|
@@ -1753,6 +1837,234 @@ export declare interface LanguageModelPromptOptions {
|
|
|
1753
1837
|
responseConstraint?: object;
|
|
1754
1838
|
}
|
|
1755
1839
|
|
|
1840
|
+
/**
|
|
1841
|
+
* Configuration parameters used by {@link LiveGenerativeModel} to control live content generation.
|
|
1842
|
+
*
|
|
1843
|
+
* @beta
|
|
1844
|
+
*/
|
|
1845
|
+
export declare interface LiveGenerationConfig {
|
|
1846
|
+
/**
|
|
1847
|
+
* Configuration for speech synthesis.
|
|
1848
|
+
*/
|
|
1849
|
+
speechConfig?: SpeechConfig;
|
|
1850
|
+
/**
|
|
1851
|
+
* Specifies the maximum number of tokens that can be generated in the response. The number of
|
|
1852
|
+
* tokens per word varies depending on the language outputted. Is unbounded by default.
|
|
1853
|
+
*/
|
|
1854
|
+
maxOutputTokens?: number;
|
|
1855
|
+
/**
|
|
1856
|
+
* Controls the degree of randomness in token selection. A `temperature` value of 0 means that the highest
|
|
1857
|
+
* probability tokens are always selected. In this case, responses for a given prompt are mostly
|
|
1858
|
+
* deterministic, but a small amount of variation is still possible.
|
|
1859
|
+
*/
|
|
1860
|
+
temperature?: number;
|
|
1861
|
+
/**
|
|
1862
|
+
* Changes how the model selects tokens for output. Tokens are
|
|
1863
|
+
* selected from the most to least probable until the sum of their probabilities equals the `topP`
|
|
1864
|
+
* value. For example, if tokens A, B, and C have probabilities of 0.3, 0.2, and 0.1 respectively
|
|
1865
|
+
* and the `topP` value is 0.5, then the model will select either A or B as the next token by using
|
|
1866
|
+
* the `temperature` and exclude C as a candidate. Defaults to 0.95 if unset.
|
|
1867
|
+
*/
|
|
1868
|
+
topP?: number;
|
|
1869
|
+
/**
|
|
1870
|
+
* Changes how the model selects token for output. A `topK` value of 1 means the select token is
|
|
1871
|
+
* the most probable among all tokens in the model's vocabulary, while a `topK` value 3 means that
|
|
1872
|
+
* the next token is selected from among the 3 most probably using probabilities sampled. Tokens
|
|
1873
|
+
* are then further filtered with the highest selected `temperature` sampling. Defaults to 40
|
|
1874
|
+
* if unspecified.
|
|
1875
|
+
*/
|
|
1876
|
+
topK?: number;
|
|
1877
|
+
/**
|
|
1878
|
+
* Positive penalties.
|
|
1879
|
+
*/
|
|
1880
|
+
presencePenalty?: number;
|
|
1881
|
+
/**
|
|
1882
|
+
* Frequency penalties.
|
|
1883
|
+
*/
|
|
1884
|
+
frequencyPenalty?: number;
|
|
1885
|
+
/**
|
|
1886
|
+
* The modalities of the response.
|
|
1887
|
+
*/
|
|
1888
|
+
responseModalities?: ResponseModality[];
|
|
1889
|
+
}
|
|
1890
|
+
|
|
1891
|
+
/**
|
|
1892
|
+
* Class for Live generative model APIs. The Live API enables low-latency, two-way multimodal
|
|
1893
|
+
* interactions with Gemini.
|
|
1894
|
+
*
|
|
1895
|
+
* This class should only be instantiated with {@link getLiveGenerativeModel}.
|
|
1896
|
+
*
|
|
1897
|
+
* @beta
|
|
1898
|
+
*/
|
|
1899
|
+
export declare class LiveGenerativeModel extends AIModel {
|
|
1900
|
+
/* Excluded from this release type: _webSocketHandler */
|
|
1901
|
+
generationConfig: LiveGenerationConfig;
|
|
1902
|
+
tools?: Tool[];
|
|
1903
|
+
toolConfig?: ToolConfig;
|
|
1904
|
+
systemInstruction?: Content;
|
|
1905
|
+
/* Excluded from this release type: __constructor */
|
|
1906
|
+
/**
|
|
1907
|
+
* Starts a {@link LiveSession}.
|
|
1908
|
+
*
|
|
1909
|
+
* @returns A {@link LiveSession}.
|
|
1910
|
+
* @throws If the connection failed to be established with the server.
|
|
1911
|
+
*
|
|
1912
|
+
* @beta
|
|
1913
|
+
*/
|
|
1914
|
+
connect(): Promise<LiveSession>;
|
|
1915
|
+
}
|
|
1916
|
+
|
|
1917
|
+
/**
|
|
1918
|
+
* Params passed to {@link getLiveGenerativeModel}.
|
|
1919
|
+
* @beta
|
|
1920
|
+
*/
|
|
1921
|
+
export declare interface LiveModelParams {
|
|
1922
|
+
model: string;
|
|
1923
|
+
generationConfig?: LiveGenerationConfig;
|
|
1924
|
+
tools?: Tool[];
|
|
1925
|
+
toolConfig?: ToolConfig;
|
|
1926
|
+
systemInstruction?: string | Part | Content;
|
|
1927
|
+
}
|
|
1928
|
+
|
|
1929
|
+
/**
|
|
1930
|
+
* The types of responses that can be returned by {@link LiveSession.receive}.
|
|
1931
|
+
*
|
|
1932
|
+
* @beta
|
|
1933
|
+
*/
|
|
1934
|
+
export declare const LiveResponseType: {
|
|
1935
|
+
SERVER_CONTENT: string;
|
|
1936
|
+
TOOL_CALL: string;
|
|
1937
|
+
TOOL_CALL_CANCELLATION: string;
|
|
1938
|
+
};
|
|
1939
|
+
|
|
1940
|
+
/**
|
|
1941
|
+
* The types of responses that can be returned by {@link LiveSession.receive}.
|
|
1942
|
+
* This is a property on all messages that can be used for type narrowing. This property is not
|
|
1943
|
+
* returned by the server, it is assigned to a server message object once it's parsed.
|
|
1944
|
+
*
|
|
1945
|
+
* @beta
|
|
1946
|
+
*/
|
|
1947
|
+
export declare type LiveResponseType = (typeof LiveResponseType)[keyof typeof LiveResponseType];
|
|
1948
|
+
|
|
1949
|
+
/**
|
|
1950
|
+
* An incremental content update from the model.
|
|
1951
|
+
*
|
|
1952
|
+
* @beta
|
|
1953
|
+
*/
|
|
1954
|
+
export declare interface LiveServerContent {
|
|
1955
|
+
type: 'serverContent';
|
|
1956
|
+
/**
|
|
1957
|
+
* The content that the model has generated as part of the current conversation with the user.
|
|
1958
|
+
*/
|
|
1959
|
+
modelTurn?: Content;
|
|
1960
|
+
/**
|
|
1961
|
+
* Indicates whether the turn is complete. This is `undefined` if the turn is not complete.
|
|
1962
|
+
*/
|
|
1963
|
+
turnComplete?: boolean;
|
|
1964
|
+
/**
|
|
1965
|
+
* Indicates whether the model was interrupted by the client. An interruption occurs when
|
|
1966
|
+
* the client sends a message before the model finishes it's turn. This is `undefined` if the
|
|
1967
|
+
* model was not interrupted.
|
|
1968
|
+
*/
|
|
1969
|
+
interrupted?: boolean;
|
|
1970
|
+
}
|
|
1971
|
+
|
|
1972
|
+
/**
|
|
1973
|
+
* A request from the model for the client to execute one or more functions.
|
|
1974
|
+
*
|
|
1975
|
+
* @beta
|
|
1976
|
+
*/
|
|
1977
|
+
export declare interface LiveServerToolCall {
|
|
1978
|
+
type: 'toolCall';
|
|
1979
|
+
/**
|
|
1980
|
+
* An array of function calls to run.
|
|
1981
|
+
*/
|
|
1982
|
+
functionCalls: FunctionCall[];
|
|
1983
|
+
}
|
|
1984
|
+
|
|
1985
|
+
/**
|
|
1986
|
+
* Notification to cancel a previous function call triggered by {@link LiveServerToolCall}.
|
|
1987
|
+
*
|
|
1988
|
+
* @beta
|
|
1989
|
+
*/
|
|
1990
|
+
export declare interface LiveServerToolCallCancellation {
|
|
1991
|
+
type: 'toolCallCancellation';
|
|
1992
|
+
/**
|
|
1993
|
+
* IDs of function calls that were cancelled. These refer to the `id` property of a {@link FunctionCall}.
|
|
1994
|
+
*/
|
|
1995
|
+
functionIds: string[];
|
|
1996
|
+
}
|
|
1997
|
+
|
|
1998
|
+
/**
|
|
1999
|
+
* Represents an active, real-time, bidirectional conversation with the model.
|
|
2000
|
+
*
|
|
2001
|
+
* This class should only be instantiated by calling {@link LiveGenerativeModel.connect}.
|
|
2002
|
+
*
|
|
2003
|
+
* @beta
|
|
2004
|
+
*/
|
|
2005
|
+
export declare class LiveSession {
|
|
2006
|
+
private webSocketHandler;
|
|
2007
|
+
private serverMessages;
|
|
2008
|
+
/**
|
|
2009
|
+
* Indicates whether this Live session is closed.
|
|
2010
|
+
*
|
|
2011
|
+
* @beta
|
|
2012
|
+
*/
|
|
2013
|
+
isClosed: boolean;
|
|
2014
|
+
/**
|
|
2015
|
+
* Indicates whether this Live session is being controlled by an `AudioConversationController`.
|
|
2016
|
+
*
|
|
2017
|
+
* @beta
|
|
2018
|
+
*/
|
|
2019
|
+
inConversation: boolean;
|
|
2020
|
+
/* Excluded from this release type: __constructor */
|
|
2021
|
+
/**
|
|
2022
|
+
* Sends content to the server.
|
|
2023
|
+
*
|
|
2024
|
+
* @param request - The message to send to the model.
|
|
2025
|
+
* @param turnComplete - Indicates if the turn is complete. Defaults to false.
|
|
2026
|
+
* @throws If this session has been closed.
|
|
2027
|
+
*
|
|
2028
|
+
* @beta
|
|
2029
|
+
*/
|
|
2030
|
+
send(request: string | Array<string | Part>, turnComplete?: boolean): Promise<void>;
|
|
2031
|
+
/**
|
|
2032
|
+
* Sends realtime input to the server.
|
|
2033
|
+
*
|
|
2034
|
+
* @param mediaChunks - The media chunks to send.
|
|
2035
|
+
* @throws If this session has been closed.
|
|
2036
|
+
*
|
|
2037
|
+
* @beta
|
|
2038
|
+
*/
|
|
2039
|
+
sendMediaChunks(mediaChunks: GenerativeContentBlob[]): Promise<void>;
|
|
2040
|
+
/**
|
|
2041
|
+
* Sends a stream of {@link GenerativeContentBlob}.
|
|
2042
|
+
*
|
|
2043
|
+
* @param mediaChunkStream - The stream of {@link GenerativeContentBlob} to send.
|
|
2044
|
+
* @throws If this session has been closed.
|
|
2045
|
+
*
|
|
2046
|
+
* @beta
|
|
2047
|
+
*/
|
|
2048
|
+
sendMediaStream(mediaChunkStream: ReadableStream<GenerativeContentBlob>): Promise<void>;
|
|
2049
|
+
/**
|
|
2050
|
+
* Yields messages received from the server.
|
|
2051
|
+
* This can only be used by one consumer at a time.
|
|
2052
|
+
*
|
|
2053
|
+
* @returns An `AsyncGenerator` that yields server messages as they arrive.
|
|
2054
|
+
* @throws If the session is already closed, or if we receive a response that we don't support.
|
|
2055
|
+
*
|
|
2056
|
+
* @beta
|
|
2057
|
+
*/
|
|
2058
|
+
receive(): AsyncGenerator<LiveServerContent | LiveServerToolCall | LiveServerToolCallCancellation>;
|
|
2059
|
+
/**
|
|
2060
|
+
* Closes this session.
|
|
2061
|
+
* All methods on this session will throw an error once this resolves.
|
|
2062
|
+
*
|
|
2063
|
+
* @beta
|
|
2064
|
+
*/
|
|
2065
|
+
close(): Promise<void>;
|
|
2066
|
+
}
|
|
2067
|
+
|
|
1756
2068
|
/**
|
|
1757
2069
|
* Content part modality.
|
|
1758
2070
|
* @public
|
|
@@ -1878,6 +2190,20 @@ export declare type Part = TextPart | InlineDataPart | FunctionCallPart | Functi
|
|
|
1878
2190
|
*/
|
|
1879
2191
|
export declare const POSSIBLE_ROLES: readonly ["user", "model", "function", "system"];
|
|
1880
2192
|
|
|
2193
|
+
/**
|
|
2194
|
+
* Configuration for a pre-built voice.
|
|
2195
|
+
*
|
|
2196
|
+
* @beta
|
|
2197
|
+
*/
|
|
2198
|
+
export declare interface PrebuiltVoiceConfig {
|
|
2199
|
+
/**
|
|
2200
|
+
* The voice name to use for speech synthesis.
|
|
2201
|
+
*
|
|
2202
|
+
* For a full list of names and demos of what each voice sounds like, see {@link https://cloud.google.com/text-to-speech/docs/chirp3-hd | Chirp 3: HD Voices}.
|
|
2203
|
+
*/
|
|
2204
|
+
voiceName?: string;
|
|
2205
|
+
}
|
|
2206
|
+
|
|
1881
2207
|
/**
|
|
1882
2208
|
* If the prompt was blocked, this will be populated with `blockReason` and
|
|
1883
2209
|
* the relevant `safetyRatings`.
|
|
@@ -1904,7 +2230,10 @@ export declare interface RequestOptions {
|
|
|
1904
2230
|
*/
|
|
1905
2231
|
timeout?: number;
|
|
1906
2232
|
/**
|
|
1907
|
-
* Base url for endpoint. Defaults to
|
|
2233
|
+
* Base url for endpoint. Defaults to
|
|
2234
|
+
* https://firebasevertexai.googleapis.com, which is the
|
|
2235
|
+
* {@link https://console.cloud.google.com/apis/library/firebasevertexai.googleapis.com?project=_ | Firebase AI Logic API}
|
|
2236
|
+
* (used regardless of your chosen Gemini API provider).
|
|
1908
2237
|
*/
|
|
1909
2238
|
baseUrl?: string;
|
|
1910
2239
|
}
|
|
@@ -1925,6 +2254,11 @@ export declare const ResponseModality: {
|
|
|
1925
2254
|
* @beta
|
|
1926
2255
|
*/
|
|
1927
2256
|
readonly IMAGE: "IMAGE";
|
|
2257
|
+
/**
|
|
2258
|
+
* Audio.
|
|
2259
|
+
* @beta
|
|
2260
|
+
*/
|
|
2261
|
+
readonly AUDIO: "AUDIO";
|
|
1928
2262
|
};
|
|
1929
2263
|
|
|
1930
2264
|
/**
|
|
@@ -2243,6 +2577,80 @@ export declare interface Segment {
|
|
|
2243
2577
|
text: string;
|
|
2244
2578
|
}
|
|
2245
2579
|
|
|
2580
|
+
/**
|
|
2581
|
+
* Configures speech synthesis.
|
|
2582
|
+
*
|
|
2583
|
+
* @beta
|
|
2584
|
+
*/
|
|
2585
|
+
export declare interface SpeechConfig {
|
|
2586
|
+
/**
|
|
2587
|
+
* Configures the voice to be used in speech synthesis.
|
|
2588
|
+
*/
|
|
2589
|
+
voiceConfig?: VoiceConfig;
|
|
2590
|
+
}
|
|
2591
|
+
|
|
2592
|
+
/**
|
|
2593
|
+
* Starts a real-time, bidirectional audio conversation with the model. This helper function manages
|
|
2594
|
+
* the complexities of microphone access, audio recording, playback, and interruptions.
|
|
2595
|
+
*
|
|
2596
|
+
* @remarks Important: This function must be called in response to a user gesture
|
|
2597
|
+
* (for example, a button click) to comply with {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Best_practices#autoplay_policy | browser autoplay policies}.
|
|
2598
|
+
*
|
|
2599
|
+
* @example
|
|
2600
|
+
* ```javascript
|
|
2601
|
+
* const liveSession = await model.connect();
|
|
2602
|
+
* let conversationController;
|
|
2603
|
+
*
|
|
2604
|
+
* // This function must be called from within a click handler.
|
|
2605
|
+
* async function startConversation() {
|
|
2606
|
+
* try {
|
|
2607
|
+
* conversationController = await startAudioConversation(liveSession);
|
|
2608
|
+
* } catch (e) {
|
|
2609
|
+
* // Handle AI-specific errors
|
|
2610
|
+
* if (e instanceof AIError) {
|
|
2611
|
+
* console.error("AI Error:", e.message);
|
|
2612
|
+
* }
|
|
2613
|
+
* // Handle microphone permission and hardware errors
|
|
2614
|
+
* else if (e instanceof DOMException) {
|
|
2615
|
+
* console.error("Microphone Error:", e.message);
|
|
2616
|
+
* }
|
|
2617
|
+
* // Handle other unexpected errors
|
|
2618
|
+
* else {
|
|
2619
|
+
* console.error("An unexpected error occurred:", e);
|
|
2620
|
+
* }
|
|
2621
|
+
* }
|
|
2622
|
+
* }
|
|
2623
|
+
*
|
|
2624
|
+
* // Later, to stop the conversation:
|
|
2625
|
+
* // if (conversationController) {
|
|
2626
|
+
* // await conversationController.stop();
|
|
2627
|
+
* // }
|
|
2628
|
+
* ```
|
|
2629
|
+
*
|
|
2630
|
+
* @param liveSession - An active {@link LiveSession} instance.
|
|
2631
|
+
* @param options - Configuration options for the audio conversation.
|
|
2632
|
+
* @returns A `Promise` that resolves with an {@link AudioConversationController}.
|
|
2633
|
+
* @throws `AIError` if the environment does not support required Web APIs (`UNSUPPORTED`), if a conversation is already active (`REQUEST_ERROR`), the session is closed (`SESSION_CLOSED`), or if an unexpected initialization error occurs (`ERROR`).
|
|
2634
|
+
* @throws `DOMException` Thrown by `navigator.mediaDevices.getUserMedia()` if issues occur with microphone access, such as permissions being denied (`NotAllowedError`) or no compatible hardware being found (`NotFoundError`). See the {@link https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia#exceptions | MDN documentation} for a full list of exceptions.
|
|
2635
|
+
*
|
|
2636
|
+
* @beta
|
|
2637
|
+
*/
|
|
2638
|
+
export declare function startAudioConversation(liveSession: LiveSession, options?: StartAudioConversationOptions): Promise<AudioConversationController>;
|
|
2639
|
+
|
|
2640
|
+
/**
|
|
2641
|
+
* Options for {@link startAudioConversation}.
|
|
2642
|
+
*
|
|
2643
|
+
* @beta
|
|
2644
|
+
*/
|
|
2645
|
+
export declare interface StartAudioConversationOptions {
|
|
2646
|
+
/**
|
|
2647
|
+
* An async handler that is called when the model requests a function to be executed.
|
|
2648
|
+
* The handler should perform the function call and return the result as a `Part`,
|
|
2649
|
+
* which will then be sent back to the model.
|
|
2650
|
+
*/
|
|
2651
|
+
functionCallingHandler?: (functionCalls: LiveServerToolCall['functionCalls']) => Promise<Part>;
|
|
2652
|
+
}
|
|
2653
|
+
|
|
2246
2654
|
/**
|
|
2247
2655
|
* Params for {@link GenerativeModel.startChat}.
|
|
2248
2656
|
* @public
|
|
@@ -2274,6 +2682,8 @@ export declare interface TextPart {
|
|
|
2274
2682
|
inlineData?: never;
|
|
2275
2683
|
functionCall?: never;
|
|
2276
2684
|
functionResponse?: never;
|
|
2685
|
+
thought?: boolean;
|
|
2686
|
+
/* Excluded from this release type: thoughtSignature */
|
|
2277
2687
|
}
|
|
2278
2688
|
|
|
2279
2689
|
/**
|
|
@@ -2299,6 +2709,15 @@ export declare interface ThinkingConfig {
|
|
|
2299
2709
|
* feature or if the specified budget is not within the model's supported range.
|
|
2300
2710
|
*/
|
|
2301
2711
|
thinkingBudget?: number;
|
|
2712
|
+
/**
|
|
2713
|
+
* Whether to include "thought summaries" in the model's response.
|
|
2714
|
+
*
|
|
2715
|
+
* @remarks
|
|
2716
|
+
* Thought summaries provide a brief overview of the model's internal thinking process,
|
|
2717
|
+
* offering insight into how it arrived at the final answer. This can be useful for
|
|
2718
|
+
* debugging, understanding the model's reasoning, and verifying its accuracy.
|
|
2719
|
+
*/
|
|
2720
|
+
includeThoughts?: boolean;
|
|
2302
2721
|
}
|
|
2303
2722
|
|
|
2304
2723
|
/**
|
|
@@ -2380,6 +2799,18 @@ export declare interface VideoMetadata {
|
|
|
2380
2799
|
endOffset: string;
|
|
2381
2800
|
}
|
|
2382
2801
|
|
|
2802
|
+
/**
|
|
2803
|
+
* Configuration for the voice to used in speech synthesis.
|
|
2804
|
+
*
|
|
2805
|
+
* @beta
|
|
2806
|
+
*/
|
|
2807
|
+
export declare interface VoiceConfig {
|
|
2808
|
+
/**
|
|
2809
|
+
* Configures the voice using a pre-built voice configuration.
|
|
2810
|
+
*/
|
|
2811
|
+
prebuiltVoiceConfig?: PrebuiltVoiceConfig;
|
|
2812
|
+
}
|
|
2813
|
+
|
|
2383
2814
|
/**
|
|
2384
2815
|
* @public
|
|
2385
2816
|
*/
|
|
@@ -2415,4 +2846,6 @@ export declare interface WebGroundingChunk {
|
|
|
2415
2846
|
domain?: string;
|
|
2416
2847
|
}
|
|
2417
2848
|
|
|
2849
|
+
/* Excluded from this release type: WebSocketHandler */
|
|
2850
|
+
|
|
2418
2851
|
export { }
|