@firebase/ai 2.7.0-canary.691a506ec → 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.
@@ -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.
@@ -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.691a506ec";
11
+ var version = "2.7.0-canary.8123231a1";
12
12
 
13
13
  /**
14
14
  * @license
@@ -490,7 +490,8 @@ const URLRetrievalStatus = {
490
490
  const LiveResponseType = {
491
491
  SERVER_CONTENT: 'serverContent',
492
492
  TOOL_CALL: 'toolCall',
493
- TOOL_CALL_CANCELLATION: 'toolCallCancellation'
493
+ TOOL_CALL_CANCELLATION: 'toolCallCancellation',
494
+ GOING_AWAY_NOTICE: 'goingAwayNotice'
494
495
  };
495
496
 
496
497
  /**
@@ -3152,6 +3153,13 @@ class LiveSession {
3152
3153
  ...message.toolCallCancellation
3153
3154
  };
3154
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
+ }
3155
3163
  else {
3156
3164
  logger.warn(`Received an unknown message type from the server: ${JSON.stringify(message)}`);
3157
3165
  }
@@ -3230,6 +3238,18 @@ class LiveSession {
3230
3238
  }
3231
3239
  }
3232
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
+ }
3233
3253
 
3234
3254
  /**
3235
3255
  * @license