From 0a84ee16267627922e18e129e2d7dd40d5940dbb Mon Sep 17 00:00:00 2001 From: Developing-Gamer Date: Tue, 14 Jul 2026 11:08:36 -0700 Subject: [PATCH] Add analytics table filter chat adapter. Use the filter-analytics-table prompt and inject the viewed table as leading context for row-filter-only AI replies. Co-authored-by: Cursor --- .../components/vibe-coding/chat-adapters.ts | 18 ++++++++++++++++-- .../src/components/vibe-coding/index.ts | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/apps/dashboard/src/components/vibe-coding/chat-adapters.ts b/apps/dashboard/src/components/vibe-coding/chat-adapters.ts index dc4af39a8..24e383c91 100644 --- a/apps/dashboard/src/components/vibe-coding/chat-adapters.ts +++ b/apps/dashboard/src/components/vibe-coding/chat-adapters.ts @@ -108,21 +108,35 @@ export function createChatAdapter( }); } -export function createAnalyticsQueryChatAdapter( +/** + * Chat adapter for the analytics table search bar's AI fallback. Uses the + * `filter-analytics-table` system prompt, which constrains the AI to row + * filters of the shape `SELECT * FROM WHERE ...` so the grid's + * columns never change. The table being viewed is injected as a leading + * context exchange, mirroring the source-context pattern in + * `createChatAdapter` above. + */ +export function createAnalyticsTableFilterChatAdapter( backendBaseUrl: string, currentUser: CurrentUser | undefined, projectId: string | undefined, + tableName: string, onError?: (error: Error) => void, ): ChatModelAdapter { return createUnifiedAiChatAdapter({ backendBaseUrl, currentUser, - systemPrompt: "build-analytics-query", + systemPrompt: "filter-analytics-table", tools: ["sql-query"], quality: "smart", speed: "fast", projectId, sanitizeContent: sanitizeAiContent, + transformMessages: (messages) => [ + { role: "user", content: `The table I'm viewing is \`${tableName}\`.` }, + { role: "assistant", content: `Got it — I'll only generate row filters of the form SELECT * FROM ${tableName} WHERE ... so the grid's columns stay the same.` }, + ...messages, + ], onError: () => { const wrapped = new Error("Failed to get AI response. Please try again."); onError?.(wrapped); diff --git a/apps/dashboard/src/components/vibe-coding/index.ts b/apps/dashboard/src/components/vibe-coding/index.ts index bf911ccf3..48ec3b69c 100644 --- a/apps/dashboard/src/components/vibe-coding/index.ts +++ b/apps/dashboard/src/components/vibe-coding/index.ts @@ -1,5 +1,5 @@ export { default as AssistantChat, type AssistantComposerApi } from './assistant-chat'; -export { createAnalyticsQueryChatAdapter, createChatAdapter, createDashboardChatAdapter, createHistoryAdapter } from './chat-adapters'; +export { createAnalyticsTableFilterChatAdapter, createChatAdapter, createDashboardChatAdapter, createHistoryAdapter } from './chat-adapters'; export { default as CodeEditor } from './code-editor'; export { default as VibeCodeLayout, type ViewportMode, type WysiwygDebugInfo } from './vibe-code-layout';