mirror of
https://github.com/stack-auth/stack.git
synced 2026-07-20 21:29:36 +08:00
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 <cursoragent@cursor.com>
This commit is contained in:
parent
75fc9556c8
commit
0a84ee1626
@ -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 <table> 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);
|
||||
|
||||
@ -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';
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user