fix: skip model API requests when no auth token is present (#643)
Prevents infinite retry loop on /api/hermes/available-models when accessing the app without a token, which triggers server-side 429 rate limiting. Both loadModels() and fetchProviders() now bail out early if hasApiKey() returns false. Closes #606 Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -12,6 +12,7 @@ import {
|
|||||||
type ModelVisibility,
|
type ModelVisibility,
|
||||||
type ModelVisibilityRule,
|
type ModelVisibilityRule,
|
||||||
} from '@/api/hermes/system'
|
} from '@/api/hermes/system'
|
||||||
|
import { hasApiKey } from '@/api/client'
|
||||||
|
|
||||||
const WEB_UI_VERSION = __APP_VERSION__
|
const WEB_UI_VERSION = __APP_VERSION__
|
||||||
|
|
||||||
@@ -128,6 +129,7 @@ export const useAppStore = defineStore('app', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function loadModels() {
|
async function loadModels() {
|
||||||
|
if (!hasApiKey()) return
|
||||||
try {
|
try {
|
||||||
const res = await fetchAvailableModels()
|
const res = await fetchAvailableModels()
|
||||||
applyAvailableModelsResponse(res)
|
applyAvailableModelsResponse(res)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { defineStore } from 'pinia'
|
|||||||
import { ref, computed } from 'vue'
|
import { ref, computed } from 'vue'
|
||||||
import * as systemApi from '@/api/hermes/system'
|
import * as systemApi from '@/api/hermes/system'
|
||||||
import type { AvailableModelGroup, CustomProvider } from '@/api/hermes/system'
|
import type { AvailableModelGroup, CustomProvider } from '@/api/hermes/system'
|
||||||
|
import { hasApiKey } from '@/api/client'
|
||||||
import { useAppStore } from './app'
|
import { useAppStore } from './app'
|
||||||
|
|
||||||
export const useModelsStore = defineStore('models', () => {
|
export const useModelsStore = defineStore('models', () => {
|
||||||
@@ -31,6 +32,7 @@ export const useModelsStore = defineStore('models', () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
async function fetchProviders() {
|
async function fetchProviders() {
|
||||||
|
if (!hasApiKey()) return
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
const res = await systemApi.fetchAvailableModels()
|
const res = await systemApi.fetchAvailableModels()
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ const mockSystemApi = vi.hoisted(() => ({
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
vi.mock('@/api/hermes/system', () => mockSystemApi)
|
vi.mock('@/api/hermes/system', () => mockSystemApi)
|
||||||
|
vi.mock('@/api/client', () => ({ hasApiKey: () => true }))
|
||||||
|
|
||||||
import { useAppStore } from '@/stores/hermes/app'
|
import { useAppStore } from '@/stores/hermes/app'
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ const mockSystemApi = vi.hoisted(() => ({
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
vi.mock('@/api/hermes/system', () => mockSystemApi)
|
vi.mock('@/api/hermes/system', () => mockSystemApi)
|
||||||
|
vi.mock('@/api/client', () => ({ hasApiKey: () => true }))
|
||||||
|
|
||||||
import { useAppStore } from '@/stores/hermes/app'
|
import { useAppStore } from '@/stores/hermes/app'
|
||||||
import { useModelsStore } from '@/stores/hermes/models'
|
import { useModelsStore } from '@/stores/hermes/models'
|
||||||
|
|||||||
Reference in New Issue
Block a user