-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathpost-connect-suggestions.ts
More file actions
132 lines (116 loc) · 4.17 KB
/
Copy pathpost-connect-suggestions.ts
File metadata and controls
132 lines (116 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/**
* Post-connect feature suggestions and progressive disclosure.
*
* After warehouse connect, users often don't know what to do next.
* This module provides contextual suggestions based on the user's
* environment and progressive next-step hints after tool usage.
*
* Deduplication: progressive suggestions are shown at most once per
* session per tool to avoid repetitive hints.
*/
import { Telemetry } from "../../telemetry"
export namespace PostConnectSuggestions {
export interface SuggestionContext {
warehouseType: string
schemaIndexed: boolean
dbtDetected: boolean
connectionCount: number
toolsUsedInSession: string[]
}
/**
* Set of progressive suggestion keys already shown in this process.
* Reset when the process restarts (per-session lifetime).
*/
const shownProgressiveSuggestions = new Set<string>()
/** Reset shown suggestions (useful for testing). */
export function resetShownSuggestions(): void {
shownProgressiveSuggestions.clear()
}
export function getPostConnectSuggestions(ctx: SuggestionContext): string {
const suggestions: string[] = []
if (!ctx.schemaIndexed) {
suggestions.push(
"Index your schema — enables SQL analysis, column-level lineage, and data quality checks. Use the schema_index tool.",
)
}
suggestions.push(
"Run SQL queries against your " +
ctx.warehouseType +
" warehouse using sql_execute",
)
suggestions.push(
"Analyze SQL quality and find potential issues with sql_analyze",
)
if (ctx.dbtDetected) {
suggestions.push(
"dbt project detected — try /dbt-develop to help build models or /dbt-troubleshoot to debug issues",
)
}
suggestions.push(
"Trace data lineage across your models with lineage_check",
)
suggestions.push("Audit for PII exposure with schema_detect_pii")
if (ctx.connectionCount > 1) {
suggestions.push("Compare data across warehouses with data_diff")
}
return (
"\n\n---\nAvailable capabilities for your " +
ctx.warehouseType +
" warehouse:\n" +
suggestions.map((s, i) => `${i + 1}. ${s}`).join("\n")
)
}
/**
* Progressive disclosure: suggest next tool based on what was just used.
* Returns null if no suggestion applies, tool is unknown, or the
* suggestion was already shown in this session (deduplication).
*/
export function getProgressiveSuggestion(
lastToolUsed: string,
): string | null {
const progression: Record<string, string | null> = {
sql_execute:
"Tip: Use sql_analyze to check this query for potential issues, performance optimizations, and best practices.",
sql_analyze:
"Tip: Use schema_inspect to explore the tables and columns referenced in your query.",
schema_inspect:
"Tip: Use lineage_check to see how this data flows through your models.",
schema_index:
"Schema indexed! You can now use sql_analyze for quality checks, schema_inspect for exploration, and lineage_check for data flow analysis.",
warehouse_add: null, // Handled by post-connect suggestions
}
const suggestion = progression[lastToolUsed] ?? null
if (!suggestion) return null
// Deduplicate: only show each progressive suggestion once per session
if (shownProgressiveSuggestions.has(lastToolUsed)) {
return null
}
shownProgressiveSuggestions.add(lastToolUsed)
return suggestion
}
/**
* Track that feature suggestions were shown, for measuring discovery rates.
*/
export function trackSuggestions(opts: {
suggestionType:
| "post_warehouse_connect"
| "dbt_detected"
| "progressive_disclosure"
suggestionsShown: string[]
warehouseType?: string
}): void {
try {
const sessionId = Telemetry.getContext().sessionId || "unknown-session"
Telemetry.track({
type: "feature_suggestion",
timestamp: Date.now(),
session_id: sessionId,
suggestion_type: opts.suggestionType,
suggestions_shown: opts.suggestionsShown,
warehouse_type: opts.warehouseType ?? "unknown",
})
} catch {
// Telemetry must never break tool execution
}
}
}