SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
fix(ai-assistant): page context for the V2 panel editor (edit + create) and the v2 dashboards list in the picker (#12291)
Ashwin Bhatkal5ede27e8fb40
diff --git a/frontend/src/container/AIAssistant/__tests__/getAutoContexts.test.ts b/frontend/src/container/AIAssistant/__tests__/getAutoContexts.test.tsindex 709872e943..1a9c37c791 100644--- a/frontend/src/container/AIAssistant/__tests__/getAutoContexts.test.ts+++ b/frontend/src/container/AIAssistant/__tests__/getAutoContexts.test.ts@@ -167,6 +167,56 @@ describe('getAutoContexts', () => {]);});+ it('returns panel edit context on the V2 panel editor', () => {+ const dashboardId = 'dash-123';+ const panelId = 'panel-abc';+ const pathname = ROUTES.DASHBOARD_PANEL_EDITOR.replace(+ ':dashboardId',+ dashboardId,+ ).replace(':panelId', panelId);++ const contexts = getAutoContexts(pathname, '');++ expect(contexts).toStrictEqual([+ {+ source: 'auto',+ type: 'dashboard',+ resourceId: dashboardId,+ metadata: {+ page: 'panel_edit',+ widgetId: panelId,+ },+ },+ ]);+ });++ it('returns new panel context on the unsaved new-panel editor', () => {+ const dashboardId = 'dash-123';+ const pathname = ROUTES.DASHBOARD_PANEL_EDITOR.replace(+ ':dashboardId',+ dashboardId,+ ).replace(':panelId', 'new');+ const startTime = '1700000000000';+ const endTime = '1700003600000';++ const contexts = getAutoContexts(+ pathname,+ `?panelKind=TimeSeries&${QueryParams.startTime}=${startTime}&${QueryParams.endTime}=${endTime}`,+ );++ expect(contexts).toStrictEqual([+ {+ source: 'auto',+ type: 'dashboard',+ resourceId: dashboardId,+ metadata: {+ page: 'panel_create',+ timeRange: { start: Number(startTime), end: Number(endTime) },+ },+ },+ ]);+ });+it('returns empty array on alert overview without ruleId', () => {const contexts = getAutoContexts(ROUTES.ALERT_OVERVIEW, '');diff --git a/frontend/src/container/AIAssistant/__tests__/resolvePageType.test.ts b/frontend/src/container/AIAssistant/__tests__/resolvePageType.test.tsindex e4f90e2cdb..0e8004825d 100644--- a/frontend/src/container/AIAssistant/__tests__/resolvePageType.test.ts+++ b/frontend/src/container/AIAssistant/__tests__/resolvePageType.test.ts@@ -17,6 +17,28 @@ describe('resolvePageType', () => {expect(resolvePageType(pathname, '')).toBe(PageTypeDTO.dashboard_detail);});+ it('returns panel_edit on the V2 panel editor', () => {+ const pathname = ROUTES.DASHBOARD_PANEL_EDITOR.replace(+ ':dashboardId',+ 'dash-123',+ ).replace(':panelId', 'panel-abc');++ expect(resolvePageType(pathname, '')).toBe(PageTypeDTO.panel_edit);+ });++ // `panel_create` has no PageTypeDTO counterpart yet, so it reports+ // `panel_edit` rather than degrading to `other`.+ it('returns panel_edit on the unsaved new-panel editor', () => {+ const pathname = ROUTES.DASHBOARD_PANEL_EDITOR.replace(+ ':dashboardId',+ 'dash-123',+ ).replace(':panelId', 'new');++ expect(resolvePageType(pathname, '?panelKind=TimeSeries')).toBe(+ PageTypeDTO.panel_edit,+ );+ });+it('returns alerts_triggered on alert history without ruleId', () => {expect(resolvePageType(ROUTES.ALERT_HISTORY, '')).toBe(PageTypeDTO.alerts_triggered,diff --git a/frontend/src/container/AIAssistant/components/ChatInput/ChatInput.tsx b/frontend/src/container/AIAssistant/components/ChatInput/ChatInput.tsxindex bbfd7d75d4..6b6128e373 100644--- a/frontend/src/container/AIAssistant/components/ChatInput/ChatInput.tsx+++ b/frontend/src/container/AIAssistant/components/ChatInput/ChatInput.tsx@@ -16,17 +16,22 @@ import { TooltipSimple } from '@signozhq/ui/tooltip';import type { UploadFile } from 'antd';import getSessionStorage from 'api/browser/sessionstorage/get';import setSessionStorage from 'api/browser/sessionstorage/set';+import {+ getListDashboardsForUserV2QueryKey,+ useListDashboardsForUserV2,+} from 'api/generated/services/dashboard';import {getListRulesQueryKey,useListRules,} from 'api/generated/services/rules';-import type { ListRules200 } from 'api/generated/services/sigNoz.schemas';+import type {+ DashboardtypesListedDashboardForUserV2DTO,+ ListDashboardsForUserV2200,+ ListDashboardsForUserV2Params,+ ListRules200,+} from 'api/generated/services/sigNoz.schemas';import logEvent from 'api/common/logEvent';-import { REACT_QUERY_KEY } from 'constants/reactQueryKeys';-import { useGetAllDashboard } from 'hooks/dashboard/useGetAllDashboard';import { useQueryService } from 'hooks/useQueryService';-import type { SuccessResponseV2 } from 'types/api';-import type { Dashboard } from 'types/api/dashboard/getAll';// eslint-disable-next-lineimport { useSelector } from 'react-redux';import { AppState } from 'store/reducers';@@ -100,6 +105,8 @@ function autoContextLabel(ctx: MessageContext): string {return 'Current dashboard';case 'panel_edit':return 'Editing panel';+ case 'panel_create':+ return 'New panel';case 'panel_fullscreen':return 'Panel (fullscreen)';case 'dashboard_list':@@ -164,6 +171,18 @@ const TEXTAREA_MAX_HEIGHT_PX = 200;const HOME_SERVICES_INTERVAL = 30 * 60 * 1000;/** sessionStorage key for the "voice input failed this tab" flag. */const VOICE_UNAVAILABLE_KEY = 'ai-assistant-voice-unavailable';+/**+ * The picker filters client-side, so it pulls one large page instead of+ * paginating. Shared with `getQueryData` below — the params are part of the+ * generated query key, so both sides must use the same object.+ */+const DASHBOARD_LIST_PARAMS: ListDashboardsForUserV2Params = { limit: 1000 };++function dashboardTitle(+ dashboard: DashboardtypesListedDashboardForUserV2DTO,+): string {+ return dashboard.spec.display?.name || dashboard.name || 'Untitled';+}interface SelectedContextItem {category: ContextCategory;@@ -716,9 +735,11 @@ export default function ChatInput({data: dashboardsResponse,isLoading: isDashboardsLoading,isError: isDashboardsError,- } = useGetAllDashboard({- enabled: isContextPickerOpen && activeContextCategory === 'Dashboards',- staleTime: Infinity,+ } = useListDashboardsForUserV2(DASHBOARD_LIST_PARAMS, {+ query: {+ enabled: isContextPickerOpen && activeContextCategory === 'Dashboards',+ staleTime: Infinity,+ },});const {@@ -765,12 +786,12 @@ export default function ChatInput({return ctx.resourceId;}if (ctx.type === 'dashboard' && ctx.resourceId) {- const cached = queryClient.getQueryData<SuccessResponseV2<Dashboard[]>>(- REACT_QUERY_KEY.GET_ALL_DASHBOARDS,+ const cached = queryClient.getQueryData<ListDashboardsForUserV2200>(+ getListDashboardsForUserV2QueryKey(DASHBOARD_LIST_PARAMS),);- const dash = cached?.data?.find((d) => d.id === ctx.resourceId);- if (dash?.data.title) {- return dash.data.title;+ const dash = cached?.data?.dashboards?.find((d) => d.id === ctx.resourceId);+ if (dash) {+ return dashboardTitle(dash);}}if (ctx.type === 'alert' && ctx.resourceId) {@@ -800,9 +821,9 @@ export default function ChatInput({const contextEntitiesByCategory: Record<ContextCategory, ContextEntityItem[]> ={Dashboards:- dashboardsResponse?.data?.map((dashboard) => ({+ dashboardsResponse?.data?.dashboards?.map((dashboard) => ({id: dashboard.id,- value: dashboard.data.title ?? 'Untitled',+ value: dashboardTitle(dashboard),})) ?? [],Alerts:alertsResponse?.datadiff --git a/frontend/src/container/AIAssistant/components/ChatInput/__tests__/ChatInput.prefill.test.tsx b/frontend/src/container/AIAssistant/components/ChatInput/__tests__/ChatInput.prefill.test.tsxindex 9c0a6c7fbd..80f0c4f2b3 100644--- a/frontend/src/container/AIAssistant/components/ChatInput/__tests__/ChatInput.prefill.test.tsx+++ b/frontend/src/container/AIAssistant/components/ChatInput/__tests__/ChatInput.prefill.test.tsx@@ -2,12 +2,13 @@ import { render, screen, userEvent, waitFor } from 'tests/test-utils';// The prefill flow only depends on the context-picker data hooks resolving to// empty lists (so the empty state renders) — mock them to skip real fetches.-jest.mock('hooks/dashboard/useGetAllDashboard', () => ({- useGetAllDashboard: (): unknown => ({- data: [],+jest.mock('api/generated/services/dashboard', () => ({+ useListDashboardsForUserV2: (): unknown => ({+ data: undefined,isLoading: false,isError: false,}),+ getListDashboardsForUserV2QueryKey: (): string[] => ['dashboards'],}));jest.mock('api/generated/services/rules', () => ({diff --git a/frontend/src/container/AIAssistant/getAutoContexts.ts b/frontend/src/container/AIAssistant/getAutoContexts.tsindex 5821825468..273e4008f7 100644--- a/frontend/src/container/AIAssistant/getAutoContexts.ts+++ b/frontend/src/container/AIAssistant/getAutoContexts.ts@@ -2,6 +2,7 @@ import type { MessageContext } from 'api/ai-assistant/chat';import { QueryParams } from 'constants/query';import ROUTES from 'constants/routes';import { AlertListTabs } from 'pages/AlertList/types';+import { NEW_PANEL_ID } from 'pages/DashboardPageV2/DashboardContainer/PanelEditor/newPanelRoute';import { matchPath } from 'react-router-dom';/**@@ -30,22 +31,23 @@ export function getAutoContexts(// ── Dashboards ────────────────────────────────────────────────────────────- // Widget edit (panel_edit) — `/dashboard/:dashboardId/:widgetId`.- const widgetMatch = matchPath<{ dashboardId: string; widgetId: string }>(+ // Panel editor (V2). `panel/new` has no widget id yet and the schema requires+ // a non-empty `panel_edit.widgetId`, so it reports `panel_create` instead.+ const panelEditorMatch = matchPath<{ dashboardId: string; panelId: string }>(pathname,- { path: ROUTES.DASHBOARD_WIDGET, exact: true },+ { path: ROUTES.DASHBOARD_PANEL_EDITOR, exact: true },);- if (widgetMatch) {+ if (panelEditorMatch) {+ const { dashboardId, panelId } = panelEditorMatch.params;+ const isNewPanel = panelId === NEW_PANEL_ID;return [{source: 'auto',type: 'dashboard',- resourceId: widgetMatch.params.dashboardId,- metadata: {- page: 'panel_edit',- widgetId: widgetMatch.params.widgetId,- ...sharedMetadata,- },+ resourceId: dashboardId,+ metadata: isNewPanel+ ? { page: 'panel_create', ...sharedMetadata }+ : { page: 'panel_edit', widgetId: panelId, ...sharedMetadata },},];}diff --git a/frontend/src/container/AIAssistant/resolvePageType.ts b/frontend/src/container/AIAssistant/resolvePageType.tsindex 2f71262195..2f1bbbdfcd 100644--- a/frontend/src/container/AIAssistant/resolvePageType.ts+++ b/frontend/src/container/AIAssistant/resolvePageType.ts@@ -9,6 +9,8 @@ const PAGE_METADATA_TO_DTO: Record<string, PageTypeDTO> = {dashboard_detail: PageTypeDTO.dashboard_detail,dashboard_list: PageTypeDTO.dashboard_list,panel_edit: PageTypeDTO.panel_edit,+ // There is no panel_create, so sending panel_edit temporarily+ panel_create: PageTypeDTO.panel_edit,panel_fullscreen: PageTypeDTO.panel_fullscreen,logs_explorer: PageTypeDTO.logs_explorer,trace_detail: PageTypeDTO.trace_detail,