fix(frontend): keep agent editor dependency loading alive for contributors
The agent editor's dependency chain resolves storage engine info through editorResources.ensureStorageEngine, which awaited the admin-only tenants/kv/storage-engine-config call and the Viewer-safe status call in one Promise.all. A Contributor opening the editor got 403 on the config call (it carries integration secrets), which rejected the whole chain and skipped every dropdown population — models, knowledge bases and web search providers stayed empty, so Contributors could not create agents at all (#2991). Downgrade permission rejections on the config call to "no admin config" (the only consumer of storageConfig already tolerates null and falls back to the status list); every other failure stays fatal. The predicate lives in a dependency-free module so it is unit-testable under tsx --test like the other store helpers.main
parent
694f0413dd
commit
a57e97c4e1
|
|
@ -15,6 +15,7 @@ import { listMCPServices, type MCPService } from '@/api/mcp-service'
|
|||
import { listSkillCatalog, listSkills, type SkillCatalogItem, type SkillInfo } from '@/api/skill'
|
||||
import { getAgentTypePresets, getPlaceholders, type AgentTypePreset, type PlaceholdersResponse } from '@/api/agent'
|
||||
import { getTenantRetrievalConfig } from '@/api/retrieval'
|
||||
import { isStorageConfigDenied } from './storageEngineAccess'
|
||||
|
||||
const CACHE_TTL_MS = 60_000
|
||||
|
||||
|
|
@ -87,7 +88,15 @@ export const useEditorResourcesStore = defineStore('editorResources', () => {
|
|||
async function ensureStorageEngine(force = false): Promise<void> {
|
||||
return runOnce('storageEngine', force, async () => {
|
||||
const [configRes, statusRes] = await Promise.all([
|
||||
getStorageEngineConfig(),
|
||||
// The config endpoint is admin-only (it carries integration secrets),
|
||||
// while every creator — Contributors included — needs the status list
|
||||
// to pick a usable provider. A permission rejection on the config
|
||||
// call must therefore degrade to "no admin config", not break the
|
||||
// whole editor dependency chain (#2991).
|
||||
getStorageEngineConfig().catch((error: unknown) => {
|
||||
if (isStorageConfigDenied(error)) return null
|
||||
throw error
|
||||
}),
|
||||
getStorageEngineStatus(),
|
||||
])
|
||||
storageConfig.value = configRes?.data ?? null
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
|
||||
import { isStorageConfigDenied } from './storageEngineAccess.ts'
|
||||
|
||||
/** Mirrors withHttpStatus in utils/request.ts: rejected values carry a
|
||||
* non-enumerable `status` property on the payload. */
|
||||
function rejectedWithStatus(status: number, message = 'forbidden'): unknown {
|
||||
const payload: Record<string, unknown> = { message }
|
||||
Object.defineProperty(payload, 'status', { value: status, enumerable: false })
|
||||
return payload
|
||||
}
|
||||
|
||||
test('isStorageConfigDenied accepts permission rejections', () => {
|
||||
assert.equal(isStorageConfigDenied(rejectedWithStatus(403)), true)
|
||||
assert.equal(isStorageConfigDenied(rejectedWithStatus(401)), true)
|
||||
})
|
||||
|
||||
test('isStorageConfigDenied rejects other failures so they stay fatal', () => {
|
||||
assert.equal(isStorageConfigDenied(rejectedWithStatus(500)), false)
|
||||
assert.equal(isStorageConfigDenied(rejectedWithStatus(404)), false)
|
||||
assert.equal(isStorageConfigDenied(new Error('network down')), false)
|
||||
assert.equal(isStorageConfigDenied(null), false)
|
||||
assert.equal(isStorageConfigDenied(undefined), false)
|
||||
assert.equal(isStorageConfigDenied('403'), false)
|
||||
})
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
/**
|
||||
* Whether a storage-engine config request was rejected for permissions.
|
||||
*
|
||||
* The tenant KV key `storage-engine-config` is admin-only (it carries
|
||||
* integration secrets), while every agent creator — Contributors included —
|
||||
* needs the Viewer-safe status list to pick a usable provider. The store's
|
||||
* ensureStorageEngine therefore downgrades a permission rejection on the
|
||||
* config call to "no admin config" instead of failing the whole editor
|
||||
* dependency chain (#2991).
|
||||
*
|
||||
* The rejected value carries a non-enumerable `status` property (see
|
||||
* `withHttpStatus` in utils/request.ts); only 401/403 mean "this caller
|
||||
* may not read the admin-only config". Anything else stays fatal.
|
||||
*/
|
||||
export function isStorageConfigDenied(error: unknown): boolean {
|
||||
const status = (error as { status?: unknown } | null | undefined)?.status
|
||||
return status === 401 || status === 403
|
||||
}
|
||||
Loading…
Reference in New Issue