Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
fix(web-studio): pin assumed account to admin key's own account (#2910)
Zayn Jarvise1fdaf458a77
diff --git a/web-studio/src/hooks/use-app-connection.tsx b/web-studio/src/hooks/use-app-connection.tsxindex d053c1d2f..cf559f99c 100644--- a/web-studio/src/hooks/use-app-connection.tsx+++ b/web-studio/src/hooks/use-app-connection.tsx@@ -171,9 +171,14 @@ function applyConnection(})}-async function detectConnectionRole(+type ConnectionIdentity = {+ accountId: string+ role: ConnectionRole+}++async function detectConnectionIdentity(connection: ConnectionDraft,-): Promise<ConnectionRole> {+): Promise<ConnectionIdentity> {const headers: Record<string, string> = {}const apiKey = connection.adminApiKey || connection.apiKeyif (apiKey) {@@ -185,13 +190,20 @@ async function detectConnectionRole({ headers },)if (!response.ok) {- return 'unknown'+ return { accountId: '', role: 'unknown' }}+ // /health resolves the presented key and echoes back its identity:+ // { role, account_id, user_id }. We use role to gate the admin UI and+ // account_id to pin the assumed account for an account-admin key.const data = (await response.json().catch(() => null)) as {+ account_id?: unknownrole?: unknown} | null- return isConnectionRole(data?.role) ? data.role : 'unknown'+ return {+ accountId: typeof data?.account_id === 'string' ? data.account_id : '',+ role: isConnectionRole(data?.role) ? data.role : 'unknown',+ }}function readInitialConnection(): ConnectionDraft {@@ -328,13 +340,23 @@ export function AppConnectionProvider({}}- void detectConnectionRole(connection)- .then((role) => {+ void detectConnectionIdentity(connection)+ .then(({ accountId, role }) => {if (cancelled) {return}setConnectionRole(role)setConnectionRoleLoading(false)+ // An account-admin Root key is scoped to its own account. Pin that+ // account as the assumed identity so admin and data calls target the+ // right tenant instead of failing with a mismatch (the server rejects+ // a foreign account with "ADMIN can only manage account: <x>"). A root+ // key is not account-scoped, so its account selection is left intact.+ if (role === 'admin' && accountId) {+ setConnection((prev) =>+ prev.accountId === accountId ? prev : { ...prev, accountId },+ )+ }}).catch(() => {if (!cancelled) {diff --git a/web-studio/src/i18n/locales/en.ts b/web-studio/src/i18n/locales/en.tsindex e6e4d18a8..36f87175c 100644--- a/web-studio/src/i18n/locales/en.ts+++ b/web-studio/src/i18n/locales/en.ts@@ -158,7 +158,7 @@ const en = {apiKey: 'API key',baseUrl: 'Server URL',dataApiKey: 'User API key',- rootApiKey: 'Root API Key',+ rootApiKey: 'Root or Admin API Key',userApiKey: 'User API Key',role: 'Role',user: 'User',diff --git a/web-studio/src/i18n/locales/zh-CN.ts b/web-studio/src/i18n/locales/zh-CN.tsindex f3910ed82..faccf7f71 100644--- a/web-studio/src/i18n/locales/zh-CN.ts+++ b/web-studio/src/i18n/locales/zh-CN.ts@@ -157,7 +157,7 @@ const zhCN = {apiKey: 'API key',baseUrl: '服务地址',dataApiKey: 'User API key',- rootApiKey: 'Root API Key',+ rootApiKey: 'Root or Admin API Key',userApiKey: 'User API Key',role: '角色',user: 'User',