From a57e97c4e1f85147b7499332ddae00600e498b3e Mon Sep 17 00:00:00 2001 From: vicfei Date: Tue, 8 Sep 2026 09:00:10 +0800 Subject: [PATCH] fix(frontend): keep agent editor dependency loading alive for contributors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- frontend/src/stores/editorResources.ts | 11 +++++++- .../src/stores/storageEngineAccess.test.ts | 26 +++++++++++++++++++ frontend/src/stores/storageEngineAccess.ts | 18 +++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 frontend/src/stores/storageEngineAccess.test.ts create mode 100644 frontend/src/stores/storageEngineAccess.ts diff --git a/frontend/src/stores/editorResources.ts b/frontend/src/stores/editorResources.ts index 5041ff3e..080f204c 100644 --- a/frontend/src/stores/editorResources.ts +++ b/frontend/src/stores/editorResources.ts @@ -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 { 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 diff --git a/frontend/src/stores/storageEngineAccess.test.ts b/frontend/src/stores/storageEngineAccess.test.ts new file mode 100644 index 00000000..a0d8329b --- /dev/null +++ b/frontend/src/stores/storageEngineAccess.test.ts @@ -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 = { 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) +}) diff --git a/frontend/src/stores/storageEngineAccess.ts b/frontend/src/stores/storageEngineAccess.ts new file mode 100644 index 00000000..4f8a3df5 --- /dev/null +++ b/frontend/src/stores/storageEngineAccess.ts @@ -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 +}