Add Studio Query Insights#1515
Conversation
|
Compute preview deployed. Branch: |
tylerhogarth
left a comment
There was a problem hiding this comment.
FYI from a local review pass: three things I'd flag as worth a look before merge. Not blockers, just heads-up.
| * adapter. If their BFF does not support the procedure, omit it from the | ||
| * adapter so Studio hides the Queries view. | ||
| */ | ||
| queryInsights: StudioQueryInsights; |
There was a problem hiding this comment.
FYI: StudioBFFClient.queryInsights is non-optional, so every embedder receives a queryInsights object even when their BFF doesn't implement the "query-insights" procedure. The architecture says embedders MUST omit it from the adapter in that case, but the type doesn't push them there; the demo gates it at runtime via config.queries.enabled === true ? bffClient.queryInsights : undefined, which is easy to forget for a new embedder. If they copy the wiring without the gate, Studio renders the Queries view and then fails on every poll because the BFF returns "unknown procedure".
Consider accepting a capability flag on createStudioBFFClient(...) and making queryInsights?: StudioQueryInsights optional on the returned client, so opting in is explicit at the construction site.
| @@ -573,6 +693,7 @@ export function SqlView(_props: ViewProps) { | |||
| abortControllerRef.current = abortController; | |||
There was a problem hiding this comment.
FYI: runSqlRequest stores its AbortController in abortControllerRef but there's no cleanup effect that aborts it on unmount. If the user navigates away mid-query (e.g. switches to view=queries), the adapter call and subsequent state updates keep running. QueriesView already does the right thing on cleanup; SqlView should match. Same applies to the AI generation AbortController if it lacks an unmount cleanup.
useEffect(() => {
return () => {
abortControllerRef.current?.abort();
abortControllerRef.current = null;
};
}, []);| return false; | ||
| } | ||
|
|
||
| return Number.isFinite(Date.parse(value)); |
There was a problem hiding this comment.
FYI: Date.parse is notoriously lenient. Date.parse("12345") returns year 12345; Date.parse("123 456") may succeed depending on the runtime. The architecture constrains line-chart x-keys to "ISO dates, ISO datetimes, or epoch milliseconds," much tighter than Date.parse enforces. The validator will OK line charts on non-time data and the model will keep being encouraged to produce such configs.
function isDateLike(value: unknown): boolean {
if (typeof value === "number") {
return Number.isFinite(value) && value >= 0 && value <= 4_102_444_800_000;
}
if (typeof value !== "string") return false;
return /^\d{4}-\d{2}-\d{2}(T[\d:.+\-Z]*)?$/.test(value);
}
Summary
Adds Studio-owned Query Insights and moves the Console Query Insights experience into the Studio surface behind the optional adapter/BFF bridge. The new
Queriesnavigation item appears directly underVisualizeronly when the adapter providesqueryInsights; stale#view=queriesURLs fall back to the normal default view when the capability is absent.Also updates the SQL view AI flow so generated SQL is validated and corrected before it is shown, and replaces SQL result visualizations with Studio-owned Bklit chart configs/components.
Screenshots
Queries view
Query analysis details
SQL result visualization
Query Insights
Adapter.queryInsightscontract and BFFprocedure: "query-insights"snapshot bridge.#view=queries.README.md,FEATURES.md, andArchitecture/query-insights.md, including the lowest-fidelity provider Studio supports, counter semantics, traffic exclusion, sanitization, sidecar topology, and sqlcommenter metadata mapping.pnpm demo:ppgthat records successful demo BFF query executions and excludes Studio metadata/lint/introspection traffic.Query Insights UI And Data Model
Queriesview with a live activity chart, table filter/sort controls, query list, and detail sheet.1m,5m,15m, or1h.ReadsUI toRows Returnedwhile retaining reads as an internal/advisory signal.Query Insights AI Analysis
llm({ task: "query-insights", prompt })hook instead of adding a Query-specific AI transport.Analysiscolumn with queued/running state, manualAnalyze, and completedGood,Info, orWarnbadges.SQL AI Generation
sqlLintcapability before inserting it into the editor.SQL Result Visualization
bar,horizontal-bar,line,pie,doughnut, and stackedbar/horizontal-barcharts.Demo And Dependencies
@prisma/devdependency available for this branch.impeccableskill into.agents/skills/impeccableand updates repo agent guidance for future UI work.ui/components/charts.Validation
pnpm typecheckpnpm test ui/hooks/use-introspection.test.tsx ui/studio/tanstack-db-performance-architecture.test.ts ui/studio/CommandPalette.test.tsx ui/studio/Navigation.test.tsx ui/studio/Studio.test.tsx ui/studio/views/queries/QueriesView.test.tsx ui/studio/views/queries/query-insights-ai.test.ts ui/studio/views/sql/SqlView.test.tsx ui/studio/views/sql/sql-ai-generation.test.ts ui/studio/views/sql/sql-result-visualization.test.tsx data/bff/bff-client.test.ts demo/ppg-dev/query-insights.test.ts demo/ppg-dev/config.test.ts ui/components/ui/select.test.tsx -- --runpnpm buildCOREPACK_ENABLE_STRICT=0 pnpm check:exportspnpm exec eslint ui/hooks/use-introspection.test.tsx ui/studio/CommandPalette.test.tsx ui/studio/tanstack-db-performance-architecture.test.ts ui/studio/views/queries/QueriesView.tsx ui/studio/views/queries/query-insights-ai.ts ui/studio/views/sql/SqlView.tsx ui/studio/views/sql/SqlResultVisualization.tsx ui/studio/views/sql/sql-ai-generation.ts ui/studio/views/sql/sql-result-visualization.ts data/bff/bff-client.ts demo/ppg-dev/query-insights.ts demo/ppg-dev/server.ts ui/studio/Navigation.tsx ui/studio/Studio.tsx ui/components/ui/select.tsxhttp://localhost:4310/#view=queriesandhttp://localhost:4310/#view=sqlNote: a full
pnpm test -- --runpass printed all test-file success lines after the test-harness fixes, but Vitest retained a worker process and did not return to the shell. The focused regression suite above exits cleanly.