Skip to content

Commit 09c5c37

Browse files
renal128cursoragent
andcommitted
refactor: remove ElevenLabs enum namespace and global configure
Promote LogLevel, AgentState, and version to module-level API, move Events under Conversation, and replace ElevenLabs.configure with ConversationClient(logLevel:). Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 49d30e2 commit 09c5c37

22 files changed

Lines changed: 52 additions & 184 deletions

Documentation/Usage.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -716,9 +716,7 @@ The SDK uses `os.Logger` for high-performance logging. You can filter logs in Xc
716716
Adjust the verbosity of the SDK:
717717

718718
```swift
719-
ElevenLabs.configure(
720-
ElevenLabs.Configuration(logLevel: .debug) // .trace for full event logs
721-
)
719+
let client = ConversationClient(logLevel: .debug) // .trace for full event logs
722720
```
723721

724722
---

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,12 @@ Task {
222222

223223
## Configuration & Tuning
224224

225-
### Global Setup
225+
### Logging
226226

227-
Configure logging and global behaviors at app launch:
227+
Set verbosity per client:
228228

229229
```swift
230-
ElevenLabs.configure(
231-
ElevenLabs.Configuration(logLevel: .info)
232-
)
230+
let client = ConversationClient(logLevel: .info)
233231
```
234232

235233
### Custom Endpoints

Scripts/generate-version.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,15 @@ VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0")
1212
VERSION=${VERSION#v}
1313

1414
# Path to the Version.swift file
15-
VERSION_FILE="Sources/ElevenLabs/Internal/Version.swift"
15+
VERSION_FILE="Sources/ElevenLabs/Public/Version.swift"
1616

1717
# Generate the Version.swift file
1818
cat > "$VERSION_FILE" << EOF
1919
// This file is auto-generated from git tags
2020
// Run Scripts/generate-version.sh to update
2121
import Foundation
2222
23-
enum SDKVersion {
24-
static let version = "$VERSION"
25-
}
23+
public let version = "$VERSION"
2624
EOF
2725

2826
echo "Generated Version.swift with version: $VERSION"

Sources/ElevenLabs/Internal/Conversation/AgentStateManager.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ private typealias TimerTask = Task<Void, Never>
1515

1616
@MainActor
1717
final class AgentStateManager {
18-
private(set) var currentState: ElevenLabs.AgentState = .listening
19-
var onStateChange: ((ElevenLabs.AgentState) -> Void)?
18+
private(set) var currentState: AgentState = .listening
19+
var onStateChange: ((AgentState) -> Void)?
2020

2121
private let configuration: AgentStateConfiguration
2222

@@ -90,7 +90,7 @@ final class AgentStateManager {
9090
}
9191
}
9292

93-
private func transitionTo(_ newState: ElevenLabs.AgentState) {
93+
private func transitionTo(_ newState: AgentState) {
9494
guard newState != currentState else { return }
9595
currentState = newState
9696
onStateChange?(newState)

Sources/ElevenLabs/Internal/Conversation/Conversation.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ final class Conversation: ObservableObject {
1515

1616
@Published var state: ConversationState = .idle
1717
@Published var messages: [Message] = []
18-
@Published var agentState: ElevenLabs.AgentState = .listening
18+
@Published var agentState: AgentState = .listening
1919

2020
/// Stream of client tool calls that need to be executed by the app
2121
@Published var pendingToolCalls: [ClientToolCallEvent] = []
@@ -44,7 +44,7 @@ final class Conversation: ObservableObject {
4444
var agentStateManager: AgentStateManager?
4545

4646
/// Forward a signal to the event-based state manager, or fall back to directly setting `agentState`.
47-
func applyStateSignal(_ signal: AgentStateSignal, fallback: ElevenLabs.AgentState) {
47+
func applyStateSignal(_ signal: AgentStateSignal, fallback: AgentState) {
4848
if let manager = agentStateManager {
4949
manager.processSignal(signal)
5050
} else {

Sources/ElevenLabs/Internal/DI/Dependencies.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ final class Dependencies: ConversationDependencyProvider {
1414
let webRTCConnectionManager: any WebRTCConnectionManaging
1515
let webSocketConnectionManager: any WebSocketConnectionManaging
1616

17-
init(endpoints: Endpoints = .production) {
18-
let globalConfig = ElevenLabs.Global.shared.configuration
19-
let logger = SDKLogger(logLevel: globalConfig.logLevel)
17+
init(logLevel: LogLevel = .warning, endpoints: Endpoints = .production) {
18+
let logger = SDKLogger(logLevel: logLevel)
2019
self.logger = logger
2120
webRTCConnectionManager = WebRTCConnectionManager(
2221
logger: logger,

Sources/ElevenLabs/Internal/Utilities/EventSerializer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ enum EventSerializer {
120120
// Add source_info (equivalent to client in React Native)
121121
var sourceInfo: [String: Any] = [:]
122122
sourceInfo["source"] = "swift_sdk"
123-
sourceInfo["version"] = SDKVersion.version
123+
sourceInfo["version"] = version
124124
json["source_info"] = sourceInfo
125125

126126
// Add user_id if provided

Sources/ElevenLabs/Internal/Utilities/SDKLogger.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ extension Logging {
3737
struct SDKLogger: Logging {
3838
private let subsystem: String
3939
private let category: String
40-
private let logLevel: ElevenLabs.LogLevel
40+
private let logLevel: LogLevel
4141

4242
init(
4343
subsystem: String = "com.elevenlabs.sdk",
4444
category: String = "ElevenLabs",
45-
logLevel: ElevenLabs.LogLevel = .info
45+
logLevel: LogLevel = .info
4646
) {
4747
self.subsystem = subsystem
4848
self.category = category

Sources/ElevenLabs/Public/Authorization/TokenService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public struct TokenService: Sendable {
8888
queryItems += [
8989
URLQueryItem(name: "agent_id", value: agentId),
9090
URLQueryItem(name: "source", value: "swift_sdk"),
91-
URLQueryItem(name: "version", value: SDKVersion.version)
91+
URLQueryItem(name: "version", value: version)
9292
]
9393
if let environment {
9494
queryItems.append(URLQueryItem(name: "environment", value: environment))

Sources/ElevenLabs/Public/Conversation/AgentStateConfiguration.swift renamed to Sources/ElevenLabs/Public/Conversation/AgentState.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
import Foundation
22

3+
/// Agent state indicating what the agent is currently doing.
4+
public enum AgentState: Sendable, Equatable {
5+
/// Agent is listening to the user
6+
case listening
7+
/// Agent is speaking
8+
case speaking
9+
/// Agent is thinking (e.g. preparing a tool call)
10+
case thinking
11+
}
12+
313
/// Configuration for event-based agent state management using VAD and client events.
414
/// Pass `nil` to use the default LiveKit-based behaviour.
515
public struct AgentStateConfiguration: Sendable {

0 commit comments

Comments
 (0)