Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ public enum AlibabaCodingPlanAPIRegion: String, CaseIterable, Sendable {
case .international:
"https://bailian-singapore-cs.alibabacloud.com"
case .chinaMainland:
"https://bailian-beijing-cs.aliyuncs.com"
// bailian-beijing-cs.aliyuncs.com and other *-cs.aliyuncs.com endpoints have SSL issues
// Use main console domain instead which has working SSL
"https://bailian.console.aliyun.com"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ struct AlibabaCodingPlanWebFetchStrategy: ProviderFetchStrategy {
return true
case .invalidCredentials:
return true
case .apiKeyUnavailableInRegion:
return false
case let .apiError(message):
return message.contains("HTTP 404") || message.contains("HTTP 403")
case .networkError:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,7 @@ public struct AlibabaCodingPlanUsageFetcher: Sendable {
let normalizedCode = codeText.lowercased()
if normalizedCode.contains("needlogin") || normalizedCode.contains("login") {
if authMode == .apiKey {
throw AlibabaCodingPlanUsageError.apiError(
"This Alibaba endpoint requires a console session for this account/region. " +
"API key mode may be unavailable in CN on this endpoint.")
throw AlibabaCodingPlanUsageError.apiKeyUnavailableInRegion
}
throw AlibabaCodingPlanUsageError.loginRequired
}
Expand All @@ -491,12 +489,13 @@ public struct AlibabaCodingPlanUsageFetcher: Sendable {
let normalizedMessage = messageText.lowercased()
if normalizedMessage.contains("log in") || normalizedMessage.contains("login") {
if authMode == .apiKey {
throw AlibabaCodingPlanUsageError.apiError(
"This Alibaba endpoint requires a console session for this account/region. " +
"API key mode may be unavailable in CN on this endpoint.")
throw AlibabaCodingPlanUsageError.apiKeyUnavailableInRegion
}
throw AlibabaCodingPlanUsageError.loginRequired
}
if authMode == .apiKey && (normalizedMessage.contains("console session") || normalizedMessage.contains("api key mode may be unavailable")) {
throw AlibabaCodingPlanUsageError.apiKeyUnavailableInRegion
}
}

let instanceInfo = self.findActiveInstanceInfo(in: dictionary, now: now)
Expand Down Expand Up @@ -1079,13 +1078,16 @@ public enum AlibabaCodingPlanUsageError: LocalizedError, Sendable, Equatable {
case networkError(String)
case apiError(String)
case parseFailed(String)
case apiKeyUnavailableInRegion

var shouldRetryOnAlternateRegion: Bool {
switch self {
case .loginRequired:
true
case .invalidCredentials:
true
case .apiKeyUnavailableInRegion:
false
case let .apiError(message):
message.contains("HTTP 404") || message.contains("HTTP 403")
case let .parseFailed(message):
Expand All @@ -1099,9 +1101,13 @@ public enum AlibabaCodingPlanUsageError: LocalizedError, Sendable, Equatable {
switch self {
case .loginRequired:
"Alibaba Coding Plan console login is required. " +
"Sign in to Model Studio in a supported browser or paste a Cookie header."
"Sign in to Model Studio/Bailian in a supported browser or paste a Cookie header."
case .invalidCredentials:
"Alibaba Coding Plan API credentials are invalid or expired."
case .apiKeyUnavailableInRegion:
"Alibaba Coding Plan API key mode is not available for this account/region. " +
"Please use cookie authentication instead by enabling \"Cookie source\" in Settings → Providers → Alibaba, " +
"or switch to API key mode if your account supports it."
case let .networkError(message):
"Alibaba Coding Plan network error: \(message)"
case let .apiError(message):
Expand Down