diff --git a/service/settings.go b/service/settings.go index ef34edf..e84e5c1 100644 --- a/service/settings.go +++ b/service/settings.go @@ -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") } diff --git a/web/src/stores/use-config-store.ts b/web/src/stores/use-config-store.ts index 08f2912..0bb7296 100644 --- a/web/src/stores/use-config-store.ts +++ b/web/src/stores/use-config-store.ts @@ -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}`; }