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 @@ -99,7 +99,7 @@ struct MiniMaxProviderImplementation: ProviderImplementation {
subtitle: "Choose the MiniMax host (global .io or China mainland .com).",
binding: regionBinding,
options: regionOptions,
isVisible: { authMode().allowsCookies },
isVisible: nil,
onChange: nil),
]
}
Expand Down
13 changes: 13 additions & 0 deletions Sources/CodexBarCore/Providers/MiniMax/MiniMaxAPIRegion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ public enum MiniMaxAPIRegion: String, CaseIterable, Sendable {
}
}

public var apiBaseURLString: String {
switch self {
case .global:
"https://api.minimax.io"
case .chinaMainland:
"https://api.minimaxi.com"
}
}

public var codingPlanURL: URL {
var components = URLComponents(string: self.baseURLString)!
components.path = "/" + Self.codingPlanPath
Expand All @@ -42,4 +51,8 @@ public enum MiniMaxAPIRegion: String, CaseIterable, Sendable {
public var remainsURL: URL {
URL(string: self.baseURLString)!.appendingPathComponent(Self.remainsPath)
}

public var apiRemainsURL: URL {
URL(string: self.apiBaseURLString)!.appendingPathComponent(Self.remainsPath)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ struct MiniMaxAPIFetchStrategy: ProviderFetchStrategy {
guard let apiToken = ProviderTokenResolver.minimaxToken(environment: context.env) else {
throw MiniMaxAPISettingsError.missingToken
}
let usage = try await MiniMaxUsageFetcher.fetchUsage(apiToken: apiToken)
let region = context.settings?.minimax?.apiRegion ?? .global
let usage = try await MiniMaxUsageFetcher.fetchUsage(apiToken: apiToken, region: region)
return self.makeResult(
usage: usage.toUsageSnapshot(),
sourceLabel: "api")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public struct MiniMaxUsageFetcher: Sendable {
private static let codingPlanPath = "user-center/payment/coding-plan"
private static let codingPlanQuery = "cycle_type=3"
private static let codingPlanRemainsPath = "v1/api/openplatform/coding_plan/remains"
private static let apiRemainsURL = URL(string: "https://api.minimaxi.com/v1/api/openplatform/coding_plan/remains")!
private struct RemainsContext: Sendable {
let authorizationToken: String?
let groupID: String?
Expand Down Expand Up @@ -51,14 +50,15 @@ public struct MiniMaxUsageFetcher: Sendable {

public static func fetchUsage(
apiToken: String,
region: MiniMaxAPIRegion = .global,
now: Date = Date()) async throws -> MiniMaxUsageSnapshot
{
let cleaned = apiToken.trimmingCharacters(in: .whitespacesAndNewlines)
guard !cleaned.isEmpty else {
throw MiniMaxUsageError.invalidCredentials
}

var request = URLRequest(url: self.apiRemainsURL)
var request = URLRequest(url: region.apiRemainsURL)
request.httpMethod = "GET"
request.setValue("Bearer \(cleaned)", forHTTPHeaderField: "Authorization")
request.setValue("application/json", forHTTPHeaderField: "accept")
Expand Down