|
| 1 | +/** |
| 2 | + * Post-connect feature suggestions and progressive disclosure. |
| 3 | + * |
| 4 | + * After warehouse connect, users often don't know what to do next. |
| 5 | + * This module provides contextual suggestions based on the user's |
| 6 | + * environment and progressive next-step hints after tool usage. |
| 7 | + */ |
| 8 | + |
| 9 | +import { Telemetry } from "../../telemetry" |
| 10 | + |
| 11 | +export namespace PostConnectSuggestions { |
| 12 | + export interface SuggestionContext { |
| 13 | + warehouseType: string |
| 14 | + schemaIndexed: boolean |
| 15 | + dbtDetected: boolean |
| 16 | + connectionCount: number |
| 17 | + toolsUsedInSession: string[] |
| 18 | + } |
| 19 | + |
| 20 | + export function getPostConnectSuggestions(ctx: SuggestionContext): string { |
| 21 | + const suggestions: string[] = [] |
| 22 | + |
| 23 | + if (!ctx.schemaIndexed) { |
| 24 | + suggestions.push( |
| 25 | + "Index your schema — enables SQL analysis, column-level lineage, and data quality checks. Use the schema_index tool.", |
| 26 | + ) |
| 27 | + } |
| 28 | + |
| 29 | + suggestions.push( |
| 30 | + "Run SQL queries against your " + |
| 31 | + ctx.warehouseType + |
| 32 | + " warehouse using sql_execute", |
| 33 | + ) |
| 34 | + suggestions.push( |
| 35 | + "Analyze SQL quality and find potential issues with sql_analyze", |
| 36 | + ) |
| 37 | + |
| 38 | + if (ctx.dbtDetected) { |
| 39 | + suggestions.push( |
| 40 | + "dbt project detected — try /dbt-develop to help build models or /dbt-troubleshoot to debug issues", |
| 41 | + ) |
| 42 | + } |
| 43 | + |
| 44 | + suggestions.push( |
| 45 | + "Trace data lineage across your models with lineage_check", |
| 46 | + ) |
| 47 | + suggestions.push("Audit for PII exposure with schema_detect_pii") |
| 48 | + |
| 49 | + if (ctx.connectionCount > 1) { |
| 50 | + suggestions.push("Compare data across warehouses with data_diff") |
| 51 | + } |
| 52 | + |
| 53 | + return ( |
| 54 | + "\n\n---\nAvailable capabilities for your " + |
| 55 | + ctx.warehouseType + |
| 56 | + " warehouse:\n" + |
| 57 | + suggestions.map((s, i) => `${i + 1}. ${s}`).join("\n") |
| 58 | + ) |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * Progressive disclosure: suggest next tool based on what was just used. |
| 63 | + * Returns null if no suggestion applies or tool is unknown. |
| 64 | + */ |
| 65 | + export function getProgressiveSuggestion( |
| 66 | + lastToolUsed: string, |
| 67 | + ): string | null { |
| 68 | + const progression: Record<string, string | null> = { |
| 69 | + sql_execute: |
| 70 | + "Tip: Use sql_analyze to check this query for potential issues, performance optimizations, and best practices.", |
| 71 | + sql_analyze: |
| 72 | + "Tip: Use schema_inspect to explore the tables and columns referenced in your query.", |
| 73 | + schema_inspect: |
| 74 | + "Tip: Use lineage_check to see how this data flows through your models.", |
| 75 | + schema_index: |
| 76 | + "Schema indexed! You can now use sql_analyze for quality checks, schema_inspect for exploration, and lineage_check for data flow analysis.", |
| 77 | + warehouse_add: null, // Handled by post-connect suggestions |
| 78 | + } |
| 79 | + return progression[lastToolUsed] ?? null |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * Track that feature suggestions were shown, for measuring discovery rates. |
| 84 | + */ |
| 85 | + export function trackSuggestions(opts: { |
| 86 | + suggestionType: |
| 87 | + | "post_warehouse_connect" |
| 88 | + | "dbt_detected" |
| 89 | + | "progressive_disclosure" |
| 90 | + suggestionsShown: string[] |
| 91 | + warehouseType?: string |
| 92 | + }): void { |
| 93 | + try { |
| 94 | + Telemetry.track({ |
| 95 | + type: "feature_suggestion", |
| 96 | + timestamp: Date.now(), |
| 97 | + session_id: Telemetry.getContext().sessionId, |
| 98 | + suggestion_type: opts.suggestionType, |
| 99 | + suggestions_shown: opts.suggestionsShown, |
| 100 | + warehouse_type: opts.warehouseType ?? "unknown", |
| 101 | + }) |
| 102 | + } catch { |
| 103 | + // Telemetry must never break tool execution |
| 104 | + } |
| 105 | + } |
| 106 | +} |
0 commit comments