@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
|
@@ -38,6 +38,11 @@ export interface TextPart {
|
|
|
38
38
|
inlineData?: never;
|
|
39
39
|
functionCall?: never;
|
|
40
40
|
functionResponse?: never;
|
|
41
|
+
thought?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
thoughtSignature?: string;
|
|
41
46
|
}
|
|
42
47
|
/**
|
|
43
48
|
* Content part interface if the part represents an image.
|
|
@@ -52,6 +57,11 @@ export interface InlineDataPart {
|
|
|
52
57
|
* Applicable if `inlineData` is a video.
|
|
53
58
|
*/
|
|
54
59
|
videoMetadata?: VideoMetadata;
|
|
60
|
+
thought?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* @internal
|
|
63
|
+
*/
|
|
64
|
+
thoughtSignature?: never;
|
|
55
65
|
}
|
|
56
66
|
/**
|
|
57
67
|
* Describes the input video content.
|
|
@@ -78,6 +88,11 @@ export interface FunctionCallPart {
|
|
|
78
88
|
inlineData?: never;
|
|
79
89
|
functionCall: FunctionCall;
|
|
80
90
|
functionResponse?: never;
|
|
91
|
+
thought?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* @internal
|
|
94
|
+
*/
|
|
95
|
+
thoughtSignature?: never;
|
|
81
96
|
}
|
|
82
97
|
/**
|
|
83
98
|
* Content part interface if the part represents {@link FunctionResponse}.
|
|
@@ -88,6 +103,11 @@ export interface FunctionResponsePart {
|
|
|
88
103
|
inlineData?: never;
|
|
89
104
|
functionCall?: never;
|
|
90
105
|
functionResponse: FunctionResponse;
|
|
106
|
+
thought?: boolean;
|
|
107
|
+
/**
|
|
108
|
+
* @internal
|
|
109
|
+
*/
|
|
110
|
+
thoughtSignature?: never;
|
|
91
111
|
}
|
|
92
112
|
/**
|
|
93
113
|
* Content part interface if the part represents {@link FileData}
|
|
@@ -99,6 +119,11 @@ export interface FileDataPart {
|
|
|
99
119
|
functionCall?: never;
|
|
100
120
|
functionResponse?: never;
|
|
101
121
|
fileData: FileData;
|
|
122
|
+
thought?: boolean;
|
|
123
|
+
/**
|
|
124
|
+
* @internal
|
|
125
|
+
*/
|
|
126
|
+
thoughtSignature?: never;
|
|
102
127
|
}
|
|
103
128
|
/**
|
|
104
129
|
* A predicted {@link FunctionCall} returned from the model
|
|
@@ -107,6 +132,15 @@ export interface FileDataPart {
|
|
|
107
132
|
* @public
|
|
108
133
|
*/
|
|
109
134
|
export interface FunctionCall {
|
|
135
|
+
/**
|
|
136
|
+
* The id of the function call. This must be sent back in the associated {@link FunctionResponse}.
|
|
137
|
+
*
|
|
138
|
+
*
|
|
139
|
+
* @remarks This property is only supported in the Gemini Developer API ({@link GoogleAIBackend}).
|
|
140
|
+
* When using the Gemini Developer API ({@link GoogleAIBackend}), this property will be
|
|
141
|
+
* `undefined`.
|
|
142
|
+
*/
|
|
143
|
+
id?: string;
|
|
110
144
|
name: string;
|
|
111
145
|
args: object;
|
|
112
146
|
}
|
|
@@ -120,6 +154,14 @@ export interface FunctionCall {
|
|
|
120
154
|
* @public
|
|
121
155
|
*/
|
|
122
156
|
export interface FunctionResponse {
|
|
157
|
+
/**
|
|
158
|
+
* The id of the {@link FunctionCall}.
|
|
159
|
+
*
|
|
160
|
+
* @remarks This property is only supported in the Gemini Developer API ({@link GoogleAIBackend}).
|
|
161
|
+
* When using the Gemini Developer API ({@link GoogleAIBackend}), this property will be
|
|
162
|
+
* `undefined`.
|
|
163
|
+
*/
|
|
164
|
+
id?: string;
|
|
123
165
|
name: string;
|
|
124
166
|
response: object;
|
|
125
167
|
}
|
|
@@ -60,6 +60,8 @@ export declare const AIErrorCode: {
|
|
|
60
60
|
readonly RESPONSE_ERROR: "response-error";
|
|
61
61
|
/** An error occurred while performing a fetch. */
|
|
62
62
|
readonly FETCH_ERROR: "fetch-error";
|
|
63
|
+
/** An error occurred because an operation was attempted on a closed session. */
|
|
64
|
+
readonly SESSION_CLOSED: "session-closed";
|
|
63
65
|
/** An error associated with a Content object. */
|
|
64
66
|
readonly INVALID_CONTENT: "invalid-content";
|
|
65
67
|
/** An error due to the Firebase API not being enabled in the Console. */
|
|
@@ -59,6 +59,14 @@ export interface ImagenResponseInternal {
|
|
|
59
59
|
* The reason why the image was filtered.
|
|
60
60
|
*/
|
|
61
61
|
raiFilteredReason?: string;
|
|
62
|
+
/**
|
|
63
|
+
* The safety attributes.
|
|
64
|
+
*
|
|
65
|
+
* This type is currently unused in the SDK. It is sent back because our requests set
|
|
66
|
+
* `includeSafetyAttributes`. This property is currently only used to avoid throwing an error
|
|
67
|
+
* when encountering this unsupported prediction type.
|
|
68
|
+
*/
|
|
69
|
+
safetyAttributes?: unknown;
|
|
62
70
|
}>;
|
|
63
71
|
}
|
|
64
72
|
/**
|
|
@@ -81,6 +89,7 @@ export interface ImagenResponseInternal {
|
|
|
81
89
|
* "personGeneration": "allow_all",
|
|
82
90
|
* "sampleCount": 2,
|
|
83
91
|
* "includeRaiReason": true,
|
|
92
|
+
* "includeSafetyAttributes": true,
|
|
84
93
|
* "aspectRatio": "9:16"
|
|
85
94
|
* }
|
|
86
95
|
* }
|
|
@@ -108,6 +117,7 @@ export interface PredictRequestBody {
|
|
|
108
117
|
safetyFilterLevel?: string;
|
|
109
118
|
personGeneration?: string;
|
|
110
119
|
includeRaiReason: boolean;
|
|
120
|
+
includeSafetyAttributes: boolean;
|
|
111
121
|
};
|
|
112
122
|
}
|
|
113
123
|
/**
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import { Content, GenerativeContentBlob, Part } from './content';
|
|
18
|
+
import { LiveGenerationConfig, Tool, ToolConfig } from './requests';
|
|
19
|
+
/**
|
|
20
|
+
* User input that is sent to the model.
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export interface _LiveClientContent {
|
|
25
|
+
clientContent: {
|
|
26
|
+
turns: [Content];
|
|
27
|
+
turnComplete: boolean;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* User input that is sent to the model in real time.
|
|
32
|
+
*
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
export interface _LiveClientRealtimeInput {
|
|
36
|
+
realtimeInput: {
|
|
37
|
+
mediaChunks: GenerativeContentBlob[];
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The first message in a Live session, used to configure generation options.
|
|
42
|
+
*
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
export interface _LiveClientSetup {
|
|
46
|
+
setup: {
|
|
47
|
+
model: string;
|
|
48
|
+
generationConfig?: LiveGenerationConfig;
|
|
49
|
+
tools?: Tool[];
|
|
50
|
+
toolConfig?: ToolConfig;
|
|
51
|
+
systemInstruction?: string | Part | Content;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -37,6 +37,17 @@ export interface ModelParams extends BaseParams {
|
|
|
37
37
|
toolConfig?: ToolConfig;
|
|
38
38
|
systemInstruction?: string | Part | Content;
|
|
39
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Params passed to {@link getLiveGenerativeModel}.
|
|
42
|
+
* @beta
|
|
43
|
+
*/
|
|
44
|
+
export interface LiveModelParams {
|
|
45
|
+
model: string;
|
|
46
|
+
generationConfig?: LiveGenerationConfig;
|
|
47
|
+
tools?: Tool[];
|
|
48
|
+
toolConfig?: ToolConfig;
|
|
49
|
+
systemInstruction?: string | Part | Content;
|
|
50
|
+
}
|
|
40
51
|
/**
|
|
41
52
|
* Request sent through {@link GenerativeModel.generateContent}
|
|
42
53
|
* @public
|
|
@@ -107,6 +118,56 @@ export interface GenerationConfig {
|
|
|
107
118
|
*/
|
|
108
119
|
thinkingConfig?: ThinkingConfig;
|
|
109
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Configuration parameters used by {@link LiveGenerativeModel} to control live content generation.
|
|
123
|
+
*
|
|
124
|
+
* @beta
|
|
125
|
+
*/
|
|
126
|
+
export interface LiveGenerationConfig {
|
|
127
|
+
/**
|
|
128
|
+
* Configuration for speech synthesis.
|
|
129
|
+
*/
|
|
130
|
+
speechConfig?: SpeechConfig;
|
|
131
|
+
/**
|
|
132
|
+
* Specifies the maximum number of tokens that can be generated in the response. The number of
|
|
133
|
+
* tokens per word varies depending on the language outputted. Is unbounded by default.
|
|
134
|
+
*/
|
|
135
|
+
maxOutputTokens?: number;
|
|
136
|
+
/**
|
|
137
|
+
* Controls the degree of randomness in token selection. A `temperature` value of 0 means that the highest
|
|
138
|
+
* probability tokens are always selected. In this case, responses for a given prompt are mostly
|
|
139
|
+
* deterministic, but a small amount of variation is still possible.
|
|
140
|
+
*/
|
|
141
|
+
temperature?: number;
|
|
142
|
+
/**
|
|
143
|
+
* Changes how the model selects tokens for output. Tokens are
|
|
144
|
+
* selected from the most to least probable until the sum of their probabilities equals the `topP`
|
|
145
|
+
* value. For example, if tokens A, B, and C have probabilities of 0.3, 0.2, and 0.1 respectively
|
|
146
|
+
* and the `topP` value is 0.5, then the model will select either A or B as the next token by using
|
|
147
|
+
* the `temperature` and exclude C as a candidate. Defaults to 0.95 if unset.
|
|
148
|
+
*/
|
|
149
|
+
topP?: number;
|
|
150
|
+
/**
|
|
151
|
+
* Changes how the model selects token for output. A `topK` value of 1 means the select token is
|
|
152
|
+
* the most probable among all tokens in the model's vocabulary, while a `topK` value 3 means that
|
|
153
|
+
* the next token is selected from among the 3 most probably using probabilities sampled. Tokens
|
|
154
|
+
* are then further filtered with the highest selected `temperature` sampling. Defaults to 40
|
|
155
|
+
* if unspecified.
|
|
156
|
+
*/
|
|
157
|
+
topK?: number;
|
|
158
|
+
/**
|
|
159
|
+
* Positive penalties.
|
|
160
|
+
*/
|
|
161
|
+
presencePenalty?: number;
|
|
162
|
+
/**
|
|
163
|
+
* Frequency penalties.
|
|
164
|
+
*/
|
|
165
|
+
frequencyPenalty?: number;
|
|
166
|
+
/**
|
|
167
|
+
* The modalities of the response.
|
|
168
|
+
*/
|
|
169
|
+
responseModalities?: ResponseModality[];
|
|
170
|
+
}
|
|
110
171
|
/**
|
|
111
172
|
* Params for {@link GenerativeModel.startChat}.
|
|
112
173
|
* @public
|
|
@@ -146,7 +207,10 @@ export interface RequestOptions {
|
|
|
146
207
|
*/
|
|
147
208
|
timeout?: number;
|
|
148
209
|
/**
|
|
149
|
-
* Base url for endpoint. Defaults to
|
|
210
|
+
* Base url for endpoint. Defaults to
|
|
211
|
+
* https://firebasevertexai.googleapis.com, which is the
|
|
212
|
+
* {@link https://console.cloud.google.com/apis/library/firebasevertexai.googleapis.com?project=_ | Firebase AI Logic API}
|
|
213
|
+
* (used regardless of your chosen Gemini API provider).
|
|
150
214
|
*/
|
|
151
215
|
baseUrl?: string;
|
|
152
216
|
}
|
|
@@ -302,4 +366,48 @@ export interface ThinkingConfig {
|
|
|
302
366
|
* feature or if the specified budget is not within the model's supported range.
|
|
303
367
|
*/
|
|
304
368
|
thinkingBudget?: number;
|
|
369
|
+
/**
|
|
370
|
+
* Whether to include "thought summaries" in the model's response.
|
|
371
|
+
*
|
|
372
|
+
* @remarks
|
|
373
|
+
* Thought summaries provide a brief overview of the model's internal thinking process,
|
|
374
|
+
* offering insight into how it arrived at the final answer. This can be useful for
|
|
375
|
+
* debugging, understanding the model's reasoning, and verifying its accuracy.
|
|
376
|
+
*/
|
|
377
|
+
includeThoughts?: boolean;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Configuration for a pre-built voice.
|
|
381
|
+
*
|
|
382
|
+
* @beta
|
|
383
|
+
*/
|
|
384
|
+
export interface PrebuiltVoiceConfig {
|
|
385
|
+
/**
|
|
386
|
+
* The voice name to use for speech synthesis.
|
|
387
|
+
*
|
|
388
|
+
* 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}.
|
|
389
|
+
*/
|
|
390
|
+
voiceName?: string;
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Configuration for the voice to used in speech synthesis.
|
|
394
|
+
*
|
|
395
|
+
* @beta
|
|
396
|
+
*/
|
|
397
|
+
export interface VoiceConfig {
|
|
398
|
+
/**
|
|
399
|
+
* Configures the voice using a pre-built voice configuration.
|
|
400
|
+
*/
|
|
401
|
+
prebuiltVoiceConfig?: PrebuiltVoiceConfig;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Configures speech synthesis.
|
|
405
|
+
*
|
|
406
|
+
* @beta
|
|
407
|
+
*/
|
|
408
|
+
export interface SpeechConfig {
|
|
409
|
+
/**
|
|
410
|
+
* Configures the voice to be used in speech synthesis.
|
|
411
|
+
*/
|
|
412
|
+
voiceConfig?: VoiceConfig;
|
|
305
413
|
}
|
|
@@ -48,15 +48,34 @@ export interface EnhancedGenerateContentResponse extends GenerateContentResponse
|
|
|
48
48
|
*/
|
|
49
49
|
text: () => string;
|
|
50
50
|
/**
|
|
51
|
-
* Aggregates and returns
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* @returns An array of {@link InlineDataPart}s containing data from the response, if available.
|
|
51
|
+
* Aggregates and returns every {@link InlineDataPart} from the first candidate of
|
|
52
|
+
* {@link GenerateContentResponse}.
|
|
55
53
|
*
|
|
56
54
|
* @throws If the prompt or candidate was blocked.
|
|
57
55
|
*/
|
|
58
56
|
inlineDataParts: () => InlineDataPart[] | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Aggregates and returns every {@link FunctionCall} from the first candidate of
|
|
59
|
+
* {@link GenerateContentResponse}.
|
|
60
|
+
*
|
|
61
|
+
* @throws If the prompt or candidate was blocked.
|
|
62
|
+
*/
|
|
59
63
|
functionCalls: () => FunctionCall[] | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Aggregates and returns every {@link TextPart} with their `thought` property set
|
|
66
|
+
* to `true` from the first candidate of {@link GenerateContentResponse}.
|
|
67
|
+
*
|
|
68
|
+
* @throws If the prompt or candidate was blocked.
|
|
69
|
+
*
|
|
70
|
+
* @remarks
|
|
71
|
+
* Thought summaries provide a brief overview of the model's internal thinking process,
|
|
72
|
+
* offering insight into how it arrived at the final answer. This can be useful for
|
|
73
|
+
* debugging, understanding the model's reasoning, and verifying its accuracy.
|
|
74
|
+
*
|
|
75
|
+
* Thoughts will only be included if {@link ThinkingConfig.includeThoughts} is
|
|
76
|
+
* set to `true`.
|
|
77
|
+
*/
|
|
78
|
+
thoughtSummary: () => string | undefined;
|
|
60
79
|
}
|
|
61
80
|
/**
|
|
62
81
|
* Individual response from {@link GenerativeModel.generateContent} and
|
|
@@ -378,3 +397,67 @@ export interface CountTokensResponse {
|
|
|
378
397
|
*/
|
|
379
398
|
promptTokensDetails?: ModalityTokenCount[];
|
|
380
399
|
}
|
|
400
|
+
/**
|
|
401
|
+
* An incremental content update from the model.
|
|
402
|
+
*
|
|
403
|
+
* @beta
|
|
404
|
+
*/
|
|
405
|
+
export interface LiveServerContent {
|
|
406
|
+
type: 'serverContent';
|
|
407
|
+
/**
|
|
408
|
+
* The content that the model has generated as part of the current conversation with the user.
|
|
409
|
+
*/
|
|
410
|
+
modelTurn?: Content;
|
|
411
|
+
/**
|
|
412
|
+
* Indicates whether the turn is complete. This is `undefined` if the turn is not complete.
|
|
413
|
+
*/
|
|
414
|
+
turnComplete?: boolean;
|
|
415
|
+
/**
|
|
416
|
+
* Indicates whether the model was interrupted by the client. An interruption occurs when
|
|
417
|
+
* the client sends a message before the model finishes it's turn. This is `undefined` if the
|
|
418
|
+
* model was not interrupted.
|
|
419
|
+
*/
|
|
420
|
+
interrupted?: boolean;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* A request from the model for the client to execute one or more functions.
|
|
424
|
+
*
|
|
425
|
+
* @beta
|
|
426
|
+
*/
|
|
427
|
+
export interface LiveServerToolCall {
|
|
428
|
+
type: 'toolCall';
|
|
429
|
+
/**
|
|
430
|
+
* An array of function calls to run.
|
|
431
|
+
*/
|
|
432
|
+
functionCalls: FunctionCall[];
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Notification to cancel a previous function call triggered by {@link LiveServerToolCall}.
|
|
436
|
+
*
|
|
437
|
+
* @beta
|
|
438
|
+
*/
|
|
439
|
+
export interface LiveServerToolCallCancellation {
|
|
440
|
+
type: 'toolCallCancellation';
|
|
441
|
+
/**
|
|
442
|
+
* IDs of function calls that were cancelled. These refer to the `id` property of a {@link FunctionCall}.
|
|
443
|
+
*/
|
|
444
|
+
functionIds: string[];
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* The types of responses that can be returned by {@link LiveSession.receive}.
|
|
448
|
+
*
|
|
449
|
+
* @beta
|
|
450
|
+
*/
|
|
451
|
+
export declare const LiveResponseType: {
|
|
452
|
+
SERVER_CONTENT: string;
|
|
453
|
+
TOOL_CALL: string;
|
|
454
|
+
TOOL_CALL_CANCELLATION: string;
|
|
455
|
+
};
|
|
456
|
+
/**
|
|
457
|
+
* The types of responses that can be returned by {@link LiveSession.receive}.
|
|
458
|
+
* This is a property on all messages that can be used for type narrowing. This property is not
|
|
459
|
+
* returned by the server, it is assigned to a server message object once it's parsed.
|
|
460
|
+
*
|
|
461
|
+
* @beta
|
|
462
|
+
*/
|
|
463
|
+
export type LiveResponseType = (typeof LiveResponseType)[keyof typeof LiveResponseType];
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* A standardized interface for interacting with a WebSocket connection.
|
|
19
|
+
* This abstraction allows the SDK to use the appropriate WebSocket implementation
|
|
20
|
+
* for the current JS environment (Browser vs. Node) without
|
|
21
|
+
* changing the core logic of the `LiveSession`.
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export interface WebSocketHandler {
|
|
25
|
+
/**
|
|
26
|
+
* Establishes a connection to the given URL.
|
|
27
|
+
*
|
|
28
|
+
* @param url The WebSocket URL (e.g., wss://...).
|
|
29
|
+
* @returns A promise that resolves on successful connection or rejects on failure.
|
|
30
|
+
*/
|
|
31
|
+
connect(url: string): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Sends data over the WebSocket.
|
|
34
|
+
*
|
|
35
|
+
* @param data The string or binary data to send.
|
|
36
|
+
*/
|
|
37
|
+
send(data: string | ArrayBuffer): void;
|
|
38
|
+
/**
|
|
39
|
+
* Returns an async generator that yields parsed JSON objects from the server.
|
|
40
|
+
* The yielded type is `unknown` because the handler cannot guarantee the shape of the data.
|
|
41
|
+
* The consumer is responsible for type validation.
|
|
42
|
+
* The generator terminates when the connection is closed.
|
|
43
|
+
*
|
|
44
|
+
* @returns A generator that allows consumers to pull messages using a `for await...of` loop.
|
|
45
|
+
*/
|
|
46
|
+
listen(): AsyncGenerator<unknown>;
|
|
47
|
+
/**
|
|
48
|
+
* Closes the WebSocket connection.
|
|
49
|
+
*
|
|
50
|
+
* @param code - A numeric status code explaining why the connection is closing.
|
|
51
|
+
* @param reason - A human-readable string explaining why the connection is closing.
|
|
52
|
+
*/
|
|
53
|
+
close(code?: number, reason?: string): Promise<void>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A wrapper for the native `WebSocket` available in both Browsers and Node >= 22.
|
|
57
|
+
*
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
60
|
+
export declare class WebSocketHandlerImpl implements WebSocketHandler {
|
|
61
|
+
private ws?;
|
|
62
|
+
constructor();
|
|
63
|
+
connect(url: string): Promise<void>;
|
|
64
|
+
send(data: string | ArrayBuffer): void;
|
|
65
|
+
listen(): AsyncGenerator<unknown>;
|
|
66
|
+
close(code?: number, reason?: string): Promise<void>;
|
|
67
|
+
}
|