fix: normalize ark agent plan base url
This commit is contained in:
+11
-2
@@ -185,15 +185,24 @@ func SelectModelChannel(modelName string) (model.ModelChannel, error) {
|
||||
}
|
||||
|
||||
func BuildModelChannelURL(channel model.ModelChannel, path string) string {
|
||||
baseURL := strings.TrimRight(channel.BaseURL, "/")
|
||||
baseURL := normalizeModelChannelBaseURL(channel.BaseURL)
|
||||
if !strings.HasSuffix(baseURL, "/v1") && !strings.HasSuffix(baseURL, "/api/v3") && !strings.HasSuffix(baseURL, "/api/plan/v3") {
|
||||
baseURL += "/v1"
|
||||
}
|
||||
return baseURL + path
|
||||
}
|
||||
|
||||
func normalizeModelChannelBaseURL(baseURL string) string {
|
||||
baseURL = strings.TrimRight(strings.TrimSpace(baseURL), "/")
|
||||
lowerBaseURL := strings.ToLower(baseURL)
|
||||
if index := strings.Index(lowerBaseURL, "/api/plan/v3"); index >= 0 {
|
||||
return baseURL[:index+len("/api/plan/v3")]
|
||||
}
|
||||
return baseURL
|
||||
}
|
||||
|
||||
func isArkAgentPlanChannel(channel model.ModelChannel) bool {
|
||||
baseURL := strings.TrimRight(strings.ToLower(strings.TrimSpace(channel.BaseURL)), "/")
|
||||
baseURL := strings.ToLower(normalizeModelChannelBaseURL(channel.BaseURL))
|
||||
return strings.HasSuffix(baseURL, "/api/plan/v3")
|
||||
}
|
||||
|
||||
|
||||
@@ -125,7 +125,9 @@ export function useEffectiveConfig() {
|
||||
}
|
||||
|
||||
export function buildApiUrl(baseUrl: string, path: string) {
|
||||
const normalizedBaseUrl = baseUrl.trim().replace(/\/+$/, "");
|
||||
let normalizedBaseUrl = baseUrl.trim().replace(/\/+$/, "");
|
||||
const arkPlanIndex = normalizedBaseUrl.toLowerCase().indexOf("/api/plan/v3");
|
||||
if (arkPlanIndex >= 0) normalizedBaseUrl = normalizedBaseUrl.slice(0, arkPlanIndex + "/api/plan/v3".length);
|
||||
const apiBaseUrl = normalizedBaseUrl.endsWith("/v1") || normalizedBaseUrl.endsWith("/api/v3") || normalizedBaseUrl.endsWith("/api/plan/v3") ? normalizedBaseUrl : `${normalizedBaseUrl}/v1`;
|
||||
return `${apiBaseUrl}${path}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user