Skip to content

Commit 88fa653

Browse files
committed
Move live session error to public folder
1 parent 029ee0d commit 88fa653

File tree

2 files changed

+95
-80
lines changed

2 files changed

+95
-80
lines changed

FirebaseAI/Sources/Types/Internal/Live/LiveSessionService.swift

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -346,83 +346,3 @@ actor LiveSessionService {
346346
return AsyncWebSocket(urlSession: urlSession, urlRequest: urlRequest)
347347
}
348348
}
349-
350-
/// The live model sent a message that the SDK failed to parse.
351-
///
352-
/// This may indicate that the SDK version needs updating, a model is too old for the current SDK
353-
/// version, or that the model is just
354-
/// not supported.
355-
///
356-
/// Check the `NSUnderlyingErrorKey` entry in ``errorUserInfo`` for the error that caused this.
357-
public struct LiveSessionUnsupportedMessageError: Error, Sendable, CustomNSError {
358-
let underlyingError: Error
359-
360-
init(underlyingError: Error) {
361-
self.underlyingError = underlyingError
362-
}
363-
364-
public var errorUserInfo: [String: Any] {
365-
[
366-
NSLocalizedDescriptionKey: "Failed to parse a live message from the model. Cause: \(underlyingError.localizedDescription)",
367-
NSUnderlyingErrorKey: underlyingError,
368-
]
369-
}
370-
}
371-
372-
/// The live session was closed, because the network connection was lost.
373-
///
374-
/// Check the `NSUnderlyingErrorKey` entry in ``errorUserInfo`` for the error that caused this.
375-
public struct LiveSessionLostConnectionError: Error, Sendable, CustomNSError {
376-
let underlyingError: Error
377-
378-
init(underlyingError: Error) {
379-
self.underlyingError = underlyingError
380-
}
381-
382-
public var errorUserInfo: [String: Any] {
383-
[
384-
NSLocalizedDescriptionKey: "The live session lost connection to the server. Cause: \(underlyingError.localizedDescription)",
385-
NSUnderlyingErrorKey: underlyingError,
386-
]
387-
}
388-
}
389-
390-
/// The live session was closed, but not for a reason the SDK expected.
391-
///
392-
/// Check the `NSUnderlyingErrorKey` entry in ``errorUserInfo`` for the error that caused this.
393-
public struct LiveSessionUnexpectedClosureError: Error, Sendable, CustomNSError {
394-
let underlyingError: WebSocketClosedError
395-
396-
init(underlyingError: WebSocketClosedError) {
397-
self.underlyingError = underlyingError
398-
}
399-
400-
public var errorUserInfo: [String: Any] {
401-
[
402-
NSLocalizedDescriptionKey: "The live session was closed for some unexpected reason. Cause: \(underlyingError.localizedDescription)",
403-
NSUnderlyingErrorKey: underlyingError,
404-
]
405-
}
406-
}
407-
408-
/// The live model refused our request to setup a live session.
409-
///
410-
/// This can occur due to the model not supporting the requested response modalities, the project
411-
/// not having access to the model,
412-
/// the model being invalid, or some internal error.
413-
///
414-
/// Check the `NSUnderlyingErrorKey` entry in ``errorUserInfo`` for the error that caused this.
415-
public struct LiveSessionSetupError: Error, Sendable, CustomNSError {
416-
let underlyingError: Error
417-
418-
init(underlyingError: Error) {
419-
self.underlyingError = underlyingError
420-
}
421-
422-
public var errorUserInfo: [String: Any] {
423-
[
424-
NSLocalizedDescriptionKey: "The model did not accept the live session request. Reason: \(underlyingError.localizedDescription)",
425-
NSUnderlyingErrorKey: underlyingError,
426-
]
427-
}
428-
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import Foundation
16+
17+
/// The live model sent a message that the SDK failed to parse.
18+
///
19+
/// This may indicate that the SDK version needs updating, a model is too old for the current SDK
20+
/// version, or that the model is just
21+
/// not supported.
22+
///
23+
/// Check the `NSUnderlyingErrorKey` entry in ``errorUserInfo`` for the error that caused this.
24+
public struct LiveSessionUnsupportedMessageError: Error, Sendable, CustomNSError {
25+
let underlyingError: Error
26+
27+
init(underlyingError: Error) {
28+
self.underlyingError = underlyingError
29+
}
30+
31+
public var errorUserInfo: [String: Any] {
32+
[
33+
NSLocalizedDescriptionKey: "Failed to parse a live message from the model. Cause: \(underlyingError.localizedDescription)",
34+
NSUnderlyingErrorKey: underlyingError,
35+
]
36+
}
37+
}
38+
39+
/// The live session was closed, because the network connection was lost.
40+
///
41+
/// Check the `NSUnderlyingErrorKey` entry in ``errorUserInfo`` for the error that caused this.
42+
public struct LiveSessionLostConnectionError: Error, Sendable, CustomNSError {
43+
let underlyingError: Error
44+
45+
init(underlyingError: Error) {
46+
self.underlyingError = underlyingError
47+
}
48+
49+
public var errorUserInfo: [String: Any] {
50+
[
51+
NSLocalizedDescriptionKey: "The live session lost connection to the server. Cause: \(underlyingError.localizedDescription)",
52+
NSUnderlyingErrorKey: underlyingError,
53+
]
54+
}
55+
}
56+
57+
/// The live session was closed, but not for a reason the SDK expected.
58+
///
59+
/// Check the `NSUnderlyingErrorKey` entry in ``errorUserInfo`` for the error that caused this.
60+
public struct LiveSessionUnexpectedClosureError: Error, Sendable, CustomNSError {
61+
let underlyingError: WebSocketClosedError
62+
63+
init(underlyingError: WebSocketClosedError) {
64+
self.underlyingError = underlyingError
65+
}
66+
67+
public var errorUserInfo: [String: Any] {
68+
[
69+
NSLocalizedDescriptionKey: "The live session was closed for some unexpected reason. Cause: \(underlyingError.localizedDescription)",
70+
NSUnderlyingErrorKey: underlyingError,
71+
]
72+
}
73+
}
74+
75+
/// The live model refused our request to setup a live session.
76+
///
77+
/// This can occur due to the model not supporting the requested response modalities, the project
78+
/// not having access to the model,
79+
/// the model being invalid, or some internal error.
80+
///
81+
/// Check the `NSUnderlyingErrorKey` entry in ``errorUserInfo`` for the error that caused this.
82+
public struct LiveSessionSetupError: Error, Sendable, CustomNSError {
83+
let underlyingError: Error
84+
85+
init(underlyingError: Error) {
86+
self.underlyingError = underlyingError
87+
}
88+
89+
public var errorUserInfo: [String: Any] {
90+
[
91+
NSLocalizedDescriptionKey: "The model did not accept the live session request. Reason: \(underlyingError.localizedDescription)",
92+
NSUnderlyingErrorKey: underlyingError,
93+
]
94+
}
95+
}

0 commit comments

Comments
 (0)