Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix(agent): improve page-agent AI not configured recovery (#19780)
p0nye6e89045b245
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 90130910cc..9f83fbb092 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -3022,6 +3022,12 @@"tool-answer": "Answer:","tool-value": "Value:","tool-completed": "Completed",- "tool-failed": "Completed with issues"+ "tool-failed": "Completed with issues",+ "ai-not-configured": {+ "title": "AI Assistant isn’t configured for this workspace",+ "description": "To continue with the page agent, enable AI Assistant in workspace settings.",+ "configure": "Configure AI",+ "contact-admin": "Please contact your org administrator to configure AI Assistant."+ }}}diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex 6bc4eeae3c..00aaa2fe56 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -2531,7 +2531,13 @@"tool-answer": "Respuesta:","tool-value": "Valor:","tool-completed": "Completado",- "tool-failed": "Completado con problemas"+ "tool-failed": "Completado con problemas",+ "ai-not-configured": {+ "title": "El asistente de IA no está configurado para este espacio de trabajo",+ "description": "Para continuar con el agente de página, habilita el asistente de IA en la configuración del espacio de trabajo.",+ "configure": "Configurar IA",+ "contact-admin": "Ponte en contacto con el administrador de tu organización para configurar el asistente de IA."+ }},"audit-log": {"export-finished": "Exportación finalizada",diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.jsonindex bd75acd558..c0efd9bbfc 100644--- a/frontend/src/locales/ja-JP.json+++ b/frontend/src/locales/ja-JP.json@@ -2531,7 +2531,13 @@"tool-answer": "回答:","tool-value": "値:","tool-completed": "完了",- "tool-failed": "問題ありで完了"+ "tool-failed": "問題ありで完了",+ "ai-not-configured": {+ "title": "このワークスペースでは AI アシスタントが設定されていません",+ "description": "ページエージェントを続けるには、ワークスペース設定で AI アシスタントを有効にしてください。",+ "configure": "AI を設定",+ "contact-admin": "AI アシスタントを設定するには、組織の管理者に連絡してください。"+ }},"audit-log": {"export-finished": "エクスポートが完了しました",diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.jsonindex d9b473961d..2371e23c39 100644--- a/frontend/src/locales/vi-VN.json+++ b/frontend/src/locales/vi-VN.json@@ -2531,7 +2531,13 @@"tool-answer": "Câu trả lời:","tool-value": "Giá trị:","tool-completed": "Hoàn tất",- "tool-failed": "Hoàn tất kèm vấn đề"+ "tool-failed": "Hoàn tất kèm vấn đề",+ "ai-not-configured": {+ "title": "Trợ lý AI chưa được cấu hình cho workspace này",+ "description": "Để tiếp tục với page agent, hãy bật Trợ lý AI trong cài đặt workspace.",+ "configure": "Cấu hình AI",+ "contact-admin": "Vui lòng liên hệ quản trị viên của tổ chức để cấu hình Trợ lý AI."+ }},"audit-log": {"export-finished": "Xuất hoàn tất",diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex b1365c9646..2fba40beb4 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -3022,6 +3022,12 @@"tool-answer": "回答:","tool-value": "值:","tool-completed": "已完成",- "tool-failed": "已完成,但存在问题"+ "tool-failed": "已完成,但存在问题",+ "ai-not-configured": {+ "title": "此工作空间尚未配置 AI 助手",+ "description": "要继续使用页面助手,请先在工作空间设置中启用 AI 助手。",+ "configure": "配置 AI",+ "contact-admin": "请联系你的组织管理员来配置 AI 助手。"+ }}}diff --git a/frontend/src/plugins/agent/components/AgentChat.vue b/frontend/src/plugins/agent/components/AgentChat.vueindex a78b8f05a1..bc1dc7b392 100644--- a/frontend/src/plugins/agent/components/AgentChat.vue+++ b/frontend/src/plugins/agent/components/AgentChat.vue@@ -1,9 +1,13 @@<script setup lang="ts">+import { NButton } from "naive-ui";import remarkGfm from "remark-gfm";import remarkParse from "remark-parse";import { unified } from "unified";import { computed, nextTick, ref, watch } from "vue";+import { useRouter } from "vue-router";import AstToMarkdown from "@/plugins/ai/components/ChatView/Markdown/AstToVNode.vue";+import { SETTING_ROUTE_WORKSPACE_GENERAL } from "@/router/dashboard/workspaceSetting";+import { hasWorkspacePermissionV2 } from "@/utils";import type { AgentMessage } from "../logic/types";import { useAgentStore } from "../store/agent";import ToolCallCard from "./ToolCallCard.vue";@@ -14,9 +18,16 @@ const parseMarkdown = (content: string) => {return markdownProcessor.parse(content ?? "");};+const router = useRouter();const agentStore = useAgentStore();const chatContainer = ref<HTMLElement | null>(null);+const allowConfigure = computed(() =>+ hasWorkspacePermissionV2("bb.settings.set")+);+const showAIConfigurationRecovery = computed(+ () => agentStore.currentChatRequiresAIConfiguration+);const displayMessages = computed(() =>agentStore.messages.filter((message): message is AgentMessage =>@@ -51,6 +62,17 @@ function getToolResult(return undefined;}+function goConfigure() {+ agentStore.clearError(agentStore.currentChatId);+ router.push({+ name: SETTING_ROUTE_WORKSPACE_GENERAL,+ hash: "#ai-assistant",+ });+}++function dismissAIConfigurationRecovery() {+ agentStore.clearError(agentStore.currentChatId);+}watch([() => agentStore.currentChatId, () => agentStore.messages.length],async () => {@@ -92,7 +114,29 @@ watch(<span class="animate-pulse">●</span> {{ $t("common.loading") }}</div><div- v-if="agentStore.error"+ v-if="showAIConfigurationRecovery"+ class="max-w-[80%] rounded-lg border border-amber-200 bg-amber-50 px-3 py-3 text-sm text-amber-900"+ >+ <div class="font-medium">+ {{ $t("agent.ai-not-configured.title") }}+ </div>+ <div class="mt-1">+ {{ $t("agent.ai-not-configured.description") }}+ </div>+ <div class="mt-3 flex flex-wrap gap-x-2 gap-y-2">+ <NButton v-if="allowConfigure" type="primary" size="small" @click="goConfigure">+ {{ $t("agent.ai-not-configured.configure") }}+ </NButton>+ <NButton size="small" @click="dismissAIConfigurationRecovery">+ {{ $t("common.dismiss") }}+ </NButton>+ </div>+ <div v-if="!allowConfigure" class="mt-1 text-amber-800">+ {{ $t("agent.ai-not-configured.contact-admin") }}+ </div>+ </div>+ <div+ v-else-if="agentStore.error"class="rounded-lg bg-red-50 px-3 py-2 text-sm text-red-600">{{ agentStore.error }}diff --git a/frontend/src/plugins/agent/components/AgentInput.vue b/frontend/src/plugins/agent/components/AgentInput.vueindex cfd866baca..5eee5b6793 100644--- a/frontend/src/plugins/agent/components/AgentInput.vue+++ b/frontend/src/plugins/agent/components/AgentInput.vue@@ -7,6 +7,7 @@ import { useRoute, useRouter } from "vue-router";import type { DomRefSuggestion } from "../dom";import { lazyExtractDomRefSuggestions } from "../dom";import { runAgentLoop } from "../logic/agentLoop";+import { isAgentAIConfigurationError } from "../logic/aiConfiguration";import { buildOutboundHistory } from "../logic/outboundHistory";import { buildSystemPrompt } from "../logic/prompt";import { createToolExecutor, getToolDefinitions } from "../logic/tools";@@ -56,11 +57,15 @@ const cancelLabel = computed(const isCurrentChatRunning = computed(() =>agentStore.isChatRunning(currentChat.value?.id));+const isAIConfigurationBlocked = computed(+ () => agentStore.currentChatRequiresAIConfiguration+);const isSendDisabled = computed(() => {if (isCurrentChatRunning.value ||isAwaitingConfirm.value ||- isAwaitingChoose.value+ isAwaitingChoose.value ||+ isAIConfigurationBlocked.value) {return true;}@@ -250,21 +255,25 @@ const handleOutcome = (case "aborted":agentStore.interruptChatRun(chatId, getCurrentPageSnapshot());return;- case "error":- agentStore.addMessage({- chatId,- role: "assistant",- content: `${errorPrefix}${outcome.error.message}`,- metadata: {- route: page.path,- error: outcome.error.message,- },- });+ case "error": {+ if (!isAgentAIConfigurationError(outcome.error)) {+ agentStore.addMessage({+ chatId,+ role: "assistant",+ content: `${errorPrefix}${outcome.error.message}`,+ metadata: {+ route: page.path,+ error: outcome.error.message,+ },+ });+ }agentStore.finishChatRun(chatId, {status: "error",lastError: outcome.error.message,+ requiresAIConfiguration: isAgentAIConfigurationError(outcome.error),});return;+ }}};@@ -637,7 +646,7 @@ watch(maxRows: 6,}":placeholder="inputPlaceholder"- :disabled="isCurrentChatRunning"+ :disabled="isCurrentChatRunning || isAIConfigurationBlocked"prefix="@":options="domRefMentionOptions":filter="() => true"diff --git a/frontend/src/plugins/agent/logic/aiConfiguration.test.ts b/frontend/src/plugins/agent/logic/aiConfiguration.test.tsnew file mode 100644index 0000000000..7d8a88fb99--- /dev/null+++ b/frontend/src/plugins/agent/logic/aiConfiguration.test.ts@@ -0,0 +1,31 @@+import { Code, ConnectError } from "@connectrpc/connect";+import { describe, expect, test } from "vitest";+import { isAgentAIConfigurationError } from "./aiConfiguration";++describe("isAgentAIConfigurationError", () => {+ test("returns true for the AI-not-enabled failed precondition", () => {+ const error = new ConnectError(+ "AI is not enabled",+ Code.FailedPrecondition+ );++ expect(error.rawMessage).toBe("AI is not enabled");+ expect(isAgentAIConfigurationError(error)).toBe(true);+ });++ test("returns false for other errors", () => {+ expect(+ isAgentAIConfigurationError(+ new ConnectError("AI is not enabled", Code.PermissionDenied)+ )+ ).toBe(false);+ expect(+ isAgentAIConfigurationError(+ new ConnectError("Other failure", Code.FailedPrecondition)+ )+ ).toBe(false);+ expect(isAgentAIConfigurationError(new Error("AI is not enabled"))).toBe(+ false+ );+ });+});diff --git a/frontend/src/plugins/agent/logic/aiConfiguration.ts b/frontend/src/plugins/agent/logic/aiConfiguration.tsnew file mode 100644index 0000000000..2edd6465f6--- /dev/null+++ b/frontend/src/plugins/agent/logic/aiConfiguration.ts@@ -0,0 +1,12 @@+import { Code, ConnectError } from "@connectrpc/connect";++const AI_NOT_ENABLED_MESSAGE = "AI is not enabled";++export const isAgentAIConfigurationError = (error: unknown): boolean => {+ return (+ error instanceof ConnectError &&+ error.code === Code.FailedPrecondition &&+ (error.rawMessage === AI_NOT_ENABLED_MESSAGE ||+ error.message === AI_NOT_ENABLED_MESSAGE)+ );+};diff --git a/frontend/src/plugins/agent/logic/types.ts b/frontend/src/plugins/agent/logic/types.tsindex 36ca968fb0..bcc99c8093 100644--- a/frontend/src/plugins/agent/logic/types.ts+++ b/frontend/src/plugins/agent/logic/types.ts@@ -50,6 +50,7 @@ export interface AgentChat {page?: AgentChatSnapshot;archived: boolean;lastError?: string | null;+ requiresAIConfiguration?: boolean;interrupted?: boolean;runId?: string | null;}diff --git a/frontend/src/plugins/agent/store/agent.ts b/frontend/src/plugins/agent/store/agent.tsindex 27133434ed..dcb517b485 100644--- a/frontend/src/plugins/agent/store/agent.ts+++ b/frontend/src/plugins/agent/store/agent.ts@@ -48,6 +48,7 @@ const createChatRecord = (options: CreateChatOptions = {}): AgentChat => {page: options.page,archived: options.archived ?? false,lastError: null,+ requiresAIConfiguration: false,interrupted: false,runId: null,};@@ -206,6 +207,7 @@ const normalizeChat = (raw: unknown): AgentChat => {: chat.lastError === null? null: null,+ requiresAIConfiguration: Boolean(chat.requiresAIConfiguration),interrupted: Boolean(chat.interrupted),runId: typeof chat.runId === "string" ? chat.runId : null,};@@ -273,6 +275,7 @@ const normalizePersistedState = (raw: unknown): PersistedAgentState => {chat.status = DEFAULT_CHAT_STATUS;chat.interrupted = true;chat.lastError = null;+ chat.requiresAIConfiguration = false;}const pendingAsk = normalizePendingAsk(rawPendingAskByChatId[chat.id]);@@ -347,6 +350,9 @@ export const useAgentStore = defineStore("agent", () => {);const loading = computed(() => currentChat.value?.status === "running");const error = computed(() => currentChat.value?.lastError ?? null);+ const currentChatRequiresAIConfiguration = computed(+ () => currentChat.value?.requiresAIConfiguration ?? false+ );const runningChatIds = computed(() =>chats.value.filter((chat) => chat.status === "running")@@ -427,6 +433,7 @@ export const useAgentStore = defineStore("agent", () => {options: {interrupted?: boolean;lastError?: string | null;+ requiresAIConfiguration?: boolean;page?: AgentChatSnapshot;} = {}) => {@@ -437,6 +444,7 @@ export const useAgentStore = defineStore("agent", () => {chat.status = status;chat.interrupted = options.interrupted ?? false;chat.lastError = options.lastError ?? null;+ chat.requiresAIConfiguration = options.requiresAIConfiguration ?? false;if (options.page) {chat.page = options.page;}@@ -558,6 +566,7 @@ export const useAgentStore = defineStore("agent", () => {chat.title = getChatTitleFromMessage(message.content);}chat.lastError = null;+ chat.requiresAIConfiguration = false;chat.interrupted = false;chat.updatedTs = createdTs;return agentMessage;@@ -656,6 +665,7 @@ export const useAgentStore = defineStore("agent", () => {return;}chat.lastError = null;+ chat.requiresAIConfiguration = false;chat.interrupted = false;chat.runId = null;if (chat.status === "error") {@@ -692,10 +702,12 @@ export const useAgentStore = defineStore("agent", () => {options: {status?: Extract<AgentChatStatus, "idle" | "error">;lastError?: string | null;+ requiresAIConfiguration?: boolean;} = {}) => {setChatStatus(chatId, options.status ?? DEFAULT_CHAT_STATUS, {lastError: options.lastError ?? null,+ requiresAIConfiguration: options.requiresAIConfiguration ?? false,interrupted: false,});const chat = getChat(chatId);@@ -821,6 +833,7 @@ export const useAgentStore = defineStore("agent", () => {currentPendingAsk,loading,error,+ currentChatRequiresAIConfiguration,runningChatIds,hasRunningChat,abortControllersByChatId,