Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions Sources/OpenAI/Private/Realtime/OpenAIRealtimeSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,34 @@ open class OpenAIRealtimeSession {

continuation?.yield(.mcpListToolsFailed(fullError))

case "response.done":
// Handle response completion (may contain errors like insufficient_quota)
if
let response = json["response"] as? [String: Any],
let status = response["status"] as? String
{
logger.debug("Response done with status: \(status)")

// Pass the full response object for detailed error handling
continuation?.yield(.responseDone(status: status, statusDetails: response))

// Log errors for debugging
if
let statusDetails = response["status_details"] as? [String: Any],
let error = statusDetails["error"] as? [String: Any]
{
let code = error["code"] as? String ?? "unknown"
let message = error["message"] as? String ?? "Unknown error"
logger.error("Response error: [\(code)] \(message)")
}
} else {
logger.warning("Received response.done with unexpected format")
}

default:
// Log unhandled message types for debugging
logger.debug("Unhandled message type: \(messageType)")
// Log unhandled message types with more detail for debugging
logger.warning("⚠️ Unhandled message type: \(messageType)")
logger.debug("Full JSON: \(String(describing: json))")
break
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ public enum OpenAIRealtimeMessage: Sendable {
case mcpListToolsInProgress // "mcp_list_tools.in_progress"
case mcpListToolsCompleted([String: Any]) // "mcp_list_tools.completed" with tools data
case mcpListToolsFailed(String?) // "mcp_list_tools.failed" with error details

/// Response completion with potential errors
case responseDone(status: String, statusDetails: [String: Any]?) // "response.done"
}