@memberjunction/db-auto-doc 4.0.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -26
- package/dist/commands/generate-queries.d.ts.map +1 -1
- package/dist/commands/generate-queries.js +3 -0
- package/dist/commands/generate-queries.js.map +1 -1
- package/dist/core/AnalysisOrchestrator.d.ts.map +1 -1
- package/dist/core/AnalysisOrchestrator.js +18 -2
- package/dist/core/AnalysisOrchestrator.js.map +1 -1
- package/dist/database/Database.d.ts.map +1 -1
- package/dist/database/Database.js +32 -20
- package/dist/database/Database.js.map +1 -1
- package/dist/drivers/SQLServerDriver.d.ts.map +1 -1
- package/dist/drivers/SQLServerDriver.js +20 -13
- package/dist/drivers/SQLServerDriver.js.map +1 -1
- package/dist/prompts/PromptEngine.d.ts.map +1 -1
- package/dist/prompts/PromptEngine.js +17 -17
- package/dist/prompts/PromptEngine.js.map +1 -1
- package/dist/prompts/PromptFileLoader.d.ts +1 -1
- package/dist/prompts/PromptFileLoader.d.ts.map +1 -1
- package/dist/prompts/PromptFileLoader.js +1 -1
- package/dist/prompts/PromptFileLoader.js.map +1 -1
- package/package.json +7 -6
- package/prompts/backpropagation.md +55 -0
- package/prompts/convergence-check.md +79 -0
- package/prompts/cross-schema-check.md +61 -0
- package/prompts/cross-schema-sanity-check.md +133 -0
- package/prompts/dependency-level-sanity-check.md +92 -0
- package/prompts/query-fix.md +141 -0
- package/prompts/query-planning.md +144 -0
- package/prompts/query-refinement.md +151 -0
- package/prompts/schema-level-sanity-check.md +114 -0
- package/prompts/schema-sanity-check.md +54 -0
- package/prompts/semantic-comparison.md +78 -0
- package/prompts/single-query-generation.md +155 -0
- package/prompts/table-analysis.md +139 -0
- package/dist/ai/simple-ai-client.d.ts +0 -70
- package/dist/ai/simple-ai-client.d.ts.map +0 -1
- package/dist/ai/simple-ai-client.js +0 -181
- package/dist/ai/simple-ai-client.js.map +0 -1
- package/dist/analyzers/analyzer.d.ts +0 -23
- package/dist/analyzers/analyzer.d.ts.map +0 -1
- package/dist/analyzers/analyzer.js +0 -127
- package/dist/analyzers/analyzer.js.map +0 -1
- package/dist/cli-old/cli.d.ts +0 -3
- package/dist/cli-old/cli.d.ts.map +0 -1
- package/dist/cli-old/cli.js +0 -388
- package/dist/cli-old/cli.js.map +0 -1
- package/dist/commands/review.d.ts +0 -11
- package/dist/commands/review.d.ts.map +0 -1
- package/dist/commands/review.js +0 -82
- package/dist/commands/review.js.map +0 -1
- package/dist/database/connection.d.ts +0 -40
- package/dist/database/connection.d.ts.map +0 -1
- package/dist/database/connection.js +0 -136
- package/dist/database/connection.js.map +0 -1
- package/dist/database/introspection.d.ts +0 -59
- package/dist/database/introspection.d.ts.map +0 -1
- package/dist/database/introspection.js +0 -124
- package/dist/database/introspection.js.map +0 -1
- package/dist/generators/markdown-generator.d.ts +0 -8
- package/dist/generators/markdown-generator.d.ts.map +0 -1
- package/dist/generators/markdown-generator.js +0 -106
- package/dist/generators/markdown-generator.js.map +0 -1
- package/dist/generators/sql-generator.d.ts +0 -20
- package/dist/generators/sql-generator.d.ts.map +0 -1
- package/dist/generators/sql-generator.js +0 -83
- package/dist/generators/sql-generator.js.map +0 -1
- package/dist/state/state-manager.d.ts +0 -95
- package/dist/state/state-manager.d.ts.map +0 -1
- package/dist/state/state-manager.js +0 -236
- package/dist/state/state-manager.js.map +0 -1
- package/dist/types/state-file.d.ts +0 -124
- package/dist/types/state-file.d.ts.map +0 -1
- package/dist/types/state-file.js +0 -79
- package/dist/types/state-file.js.map +0 -1
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
You are analyzing a database table to generate comprehensive documentation. Your task is to infer the table's purpose based on the evidence provided.
|
|
2
|
+
|
|
3
|
+
## Table Information
|
|
4
|
+
- **Name**: {{ tableName }}
|
|
5
|
+
- **Schema**: {{ schemaName }}
|
|
6
|
+
- **Row Count**: {{ rowCount }}
|
|
7
|
+
{% if dependencyLevel is defined %}- **Dependency Level**: {{ dependencyLevel }} (0 = no dependencies){% endif %}
|
|
8
|
+
|
|
9
|
+
## Columns
|
|
10
|
+
{% for col in columns %}
|
|
11
|
+
- **{{ col.name }}** ({{ col.dataType }}){% if not col.isNullable %} NOT NULL{% endif %}
|
|
12
|
+
{% if col.isPrimaryKey %}- **PRIMARY KEY**{% endif %}
|
|
13
|
+
{% if col.isForeignKey %}- **FOREIGN KEY** → {{ col.foreignKeyReferences.schema }}.{{ col.foreignKeyReferences.table }}.{{ col.foreignKeyReferences.column }}{% endif %}
|
|
14
|
+
{% if col.checkConstraint %}- Check Constraint: {{ col.checkConstraint }}{% endif %}
|
|
15
|
+
{% if col.defaultValue %}- Default: {{ col.defaultValue }}{% endif %}
|
|
16
|
+
{% if col.statistics %}- Distinct Values: {{ col.statistics.distinctCount }} ({{ (col.statistics.uniquenessRatio * 100) | round(1) }}% unique){% endif %}
|
|
17
|
+
{% if col.statistics and col.statistics.nullPercentage > 0 %}- Nulls: {{ col.statistics.nullPercentage | round(1) }}%{% endif %}
|
|
18
|
+
{% if col.possibleValues %}- Possible Values: {{ col.possibleValues | join(', ') }}{% endif %}
|
|
19
|
+
{% if col.statistics and col.statistics.min is defined %}- Range: {{ col.statistics.min }} to {{ col.statistics.max }}{% if col.statistics.avg %} (avg: {{ col.statistics.avg | round(2) }}){% endif %}{% endif %}
|
|
20
|
+
{% if col.statistics and col.statistics.avgLength %}- Avg Length: {{ col.statistics.avgLength | round(1) }} chars{% endif %}
|
|
21
|
+
{% if col.statistics.sampleValues and col.statistics.sampleValues.length > 0 %}- Sample Values: {{ col.statistics.sampleValues | jsoninline }}{% endif %}
|
|
22
|
+
{% endfor %}
|
|
23
|
+
|
|
24
|
+
## Relationships
|
|
25
|
+
{% if dependsOn and dependsOn.length > 0 %}
|
|
26
|
+
**This table references (depends on):**
|
|
27
|
+
{% for dep in dependsOn %}
|
|
28
|
+
- {{ dep.schema }}.{{ dep.table }} (via column: {{ dep.column }} → {{ dep.referencedColumn }})
|
|
29
|
+
{% endfor %}
|
|
30
|
+
{% endif %}
|
|
31
|
+
|
|
32
|
+
{% if dependents and dependents.length > 0 %}
|
|
33
|
+
**Referenced by (dependents):**
|
|
34
|
+
{% for dep in dependents %}
|
|
35
|
+
- {{ dep.schema }}.{{ dep.table }}
|
|
36
|
+
{% endfor %}
|
|
37
|
+
{% endif %}
|
|
38
|
+
|
|
39
|
+
{% if not dependsOn or dependsOn.length === 0 %}
|
|
40
|
+
**Note**: This table has no foreign key dependencies (dependency level 0). It is likely a foundational/lookup table.
|
|
41
|
+
{% endif %}
|
|
42
|
+
|
|
43
|
+
{% if parentDescriptions and parentDescriptions.length > 0 %}
|
|
44
|
+
## Parent Table Context
|
|
45
|
+
Understanding from tables this table references:
|
|
46
|
+
|
|
47
|
+
{% for parent in parentDescriptions %}
|
|
48
|
+
**{{ parent.schema }}.{{ parent.table }}**: {{ parent.description }}
|
|
49
|
+
{% endfor %}
|
|
50
|
+
{% endif %}
|
|
51
|
+
|
|
52
|
+
{% if userNotes %}
|
|
53
|
+
## User Notes
|
|
54
|
+
{{ userNotes }}
|
|
55
|
+
{% endif %}
|
|
56
|
+
|
|
57
|
+
{% if seedContext %}
|
|
58
|
+
## Database Context
|
|
59
|
+
{% if seedContext.overallPurpose %}- **Purpose**: {{ seedContext.overallPurpose }}{% endif %}
|
|
60
|
+
{% if seedContext.businessDomains %}- **Business Domains**: {{ seedContext.businessDomains | join(', ') }}{% endif %}
|
|
61
|
+
{% if seedContext.industryContext %}- **Industry**: {{ seedContext.industryContext }}{% endif %}
|
|
62
|
+
{% if seedContext.customInstructions %}- **Special Instructions**: {{ seedContext.customInstructions }}{% endif %}
|
|
63
|
+
{% endif %}
|
|
64
|
+
|
|
65
|
+
{% if allTables %}
|
|
66
|
+
## All Database Tables
|
|
67
|
+
**IMPORTANT**: When referring to foreign key relationships, you MUST use one of these exact table names:
|
|
68
|
+
{% for tbl in allTables %}
|
|
69
|
+
- {{ tbl.schema }}.{{ tbl.name }}
|
|
70
|
+
{% endfor %}
|
|
71
|
+
|
|
72
|
+
**Do NOT make up table names** - only use the exact names listed above.
|
|
73
|
+
{% endif %}
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Your Task
|
|
78
|
+
|
|
79
|
+
Based on the evidence above, generate a JSON response with this exact structure:
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
{
|
|
83
|
+
"tableDescription": "A clear, concise description of what this table stores and its purpose in the database",
|
|
84
|
+
"reasoning": "Explain the evidence that led to this conclusion (column names, data types, relationships, sample values, etc.)",
|
|
85
|
+
"confidence": 0.95,
|
|
86
|
+
"columnDescriptions": [
|
|
87
|
+
{
|
|
88
|
+
"columnName": "ColumnName",
|
|
89
|
+
"description": "What this column represents and why it exists",
|
|
90
|
+
"reasoning": "Brief explanation of the evidence"
|
|
91
|
+
}
|
|
92
|
+
],
|
|
93
|
+
"foreignKeys": [
|
|
94
|
+
{
|
|
95
|
+
"columnName": "prd_id",
|
|
96
|
+
"referencesSchema": "inv",
|
|
97
|
+
"referencesTable": "prd",
|
|
98
|
+
"referencesColumn": "prd_id",
|
|
99
|
+
"confidence": 0.95
|
|
100
|
+
}
|
|
101
|
+
],
|
|
102
|
+
"inferredBusinessDomain": "Sales",
|
|
103
|
+
"parentTableInsights": [
|
|
104
|
+
{
|
|
105
|
+
"parentTable": "schema.table",
|
|
106
|
+
"insight": "What this analysis reveals about the parent table that wasn't known before",
|
|
107
|
+
"confidence": 0.85
|
|
108
|
+
}
|
|
109
|
+
]
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**Guidelines:**
|
|
114
|
+
1. **Table Description**: Focus on WHAT the table stores and WHY it exists. Be specific about the real-world entities or business processes it represents.
|
|
115
|
+
2. **Reasoning**: Reference specific evidence (column names, FK relationships, sample values, cardinality patterns)
|
|
116
|
+
3. **Confidence**: 0-1 scale. Be conservative. Use < 0.7 if ambiguous.
|
|
117
|
+
4. **Column Descriptions**: Every column should be described. Explain its role and meaning.
|
|
118
|
+
5. **Foreign Keys**: **CRITICAL** - Use structured format for ALL foreign key relationships:
|
|
119
|
+
- Include EVERY column that references another table
|
|
120
|
+
- Use EXACT schema and table names from the "All Database Tables" list above
|
|
121
|
+
- Specify confidence (0-1 scale) based on evidence strength
|
|
122
|
+
- Example: If `prd_id` exists, add: `{"columnName": "prd_id", "referencesSchema": "inv", "referencesTable": "prd", "referencesColumn": "prd_id", "confidence": 0.95}`
|
|
123
|
+
- **Leave empty array if no foreign keys detected**
|
|
124
|
+
6. **Business Domain**: Infer from table name and purpose (e.g., "Sales", "HR", "Inventory", "Billing", "Security")
|
|
125
|
+
7. **Parent Table Insights**: If analyzing this child table reveals new information about parent tables, include it. Examples:
|
|
126
|
+
- Discovering enum values in the parent (e.g., "Member table has a 'Type' column with values: Individual, Corporate, Student")
|
|
127
|
+
- Revealing parent table classification/purpose (e.g., "BoardMember reveals that Member table includes leadership roles, not just general members")
|
|
128
|
+
- Identifying parent table patterns (e.g., "Multiple child tables suggest Organization serves as a multi-tenant partition key")
|
|
129
|
+
- **Leave empty array if no new insights about parents**
|
|
130
|
+
|
|
131
|
+
**Important:**
|
|
132
|
+
- **When mentioning table names in descriptions, ALWAYS use the exact `schema.table` format from the "All Database Tables" list**
|
|
133
|
+
- If column has low cardinality (< 20 distinct values), those are likely enum/category values - use them to understand meaning
|
|
134
|
+
- Foreign keys reveal relationships and context - use parent table descriptions to inform your analysis
|
|
135
|
+
- High uniqueness ratio (> 95%) suggests identifier/code column
|
|
136
|
+
- String length patterns can reveal format (e.g., phone, email, code)
|
|
137
|
+
- Null percentage reveals whether column is required or optional
|
|
138
|
+
|
|
139
|
+
Return ONLY valid JSON. Do not include markdown code fences or explanatory text.
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Simplified AI client that doesn't depend on MJ AI infrastructure
|
|
3
|
-
* Uses direct HTTP calls to AI providers
|
|
4
|
-
*/
|
|
5
|
-
export interface AITableDocRequest {
|
|
6
|
-
schema: string;
|
|
7
|
-
table: string;
|
|
8
|
-
columns: Array<{
|
|
9
|
-
name: string;
|
|
10
|
-
type: string;
|
|
11
|
-
nullable: boolean;
|
|
12
|
-
isPK: boolean;
|
|
13
|
-
isFK: boolean;
|
|
14
|
-
}>;
|
|
15
|
-
foreignKeys: Array<{
|
|
16
|
-
column: string;
|
|
17
|
-
referencedTable: string;
|
|
18
|
-
}>;
|
|
19
|
-
sampleData?: Record<string, any>[];
|
|
20
|
-
existingDescription?: string;
|
|
21
|
-
userNotes?: string;
|
|
22
|
-
}
|
|
23
|
-
export interface AITableDocResponse {
|
|
24
|
-
description: string;
|
|
25
|
-
purpose?: string;
|
|
26
|
-
usageNotes?: string;
|
|
27
|
-
businessDomain?: string;
|
|
28
|
-
confidence: number;
|
|
29
|
-
columns: Array<{
|
|
30
|
-
name: string;
|
|
31
|
-
description: string;
|
|
32
|
-
purpose?: string;
|
|
33
|
-
validValues?: string;
|
|
34
|
-
confidence: number;
|
|
35
|
-
}>;
|
|
36
|
-
relationships?: Array<{
|
|
37
|
-
type: 'parent' | 'child';
|
|
38
|
-
table: string;
|
|
39
|
-
description: string;
|
|
40
|
-
}>;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Simple AI client - uses fetch() to call OpenAI directly
|
|
44
|
-
* TODO: Add support for other providers (Anthropic, Groq, etc.)
|
|
45
|
-
*/
|
|
46
|
-
export declare class SimpleAIClient {
|
|
47
|
-
private provider;
|
|
48
|
-
private model;
|
|
49
|
-
private apiKey;
|
|
50
|
-
constructor();
|
|
51
|
-
/**
|
|
52
|
-
* Generate table documentation
|
|
53
|
-
*/
|
|
54
|
-
generateTableDoc(request: AITableDocRequest): Promise<AITableDocResponse & {
|
|
55
|
-
tokensUsed?: number;
|
|
56
|
-
}>;
|
|
57
|
-
/**
|
|
58
|
-
* Call OpenAI API
|
|
59
|
-
*/
|
|
60
|
-
private callOpenAI;
|
|
61
|
-
/**
|
|
62
|
-
* Call Anthropic API
|
|
63
|
-
*/
|
|
64
|
-
private callAnthropic;
|
|
65
|
-
/**
|
|
66
|
-
* Build table documentation prompt
|
|
67
|
-
*/
|
|
68
|
-
private buildTablePrompt;
|
|
69
|
-
}
|
|
70
|
-
//# sourceMappingURL=simple-ai-client.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"simple-ai-client.d.ts","sourceRoot":"","sources":["../../src/ai/simple-ai-client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,KAAK,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,OAAO,CAAC;QAClB,IAAI,EAAE,OAAO,CAAC;QACd,IAAI,EAAE,OAAO,CAAC;KACf,CAAC,CAAC;IACH,WAAW,EAAE,KAAK,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;QACf,eAAe,EAAE,MAAM,CAAC;KACzB,CAAC,CAAC;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;IACnC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,KAAK,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC,CAAC;IACH,aAAa,CAAC,EAAE,KAAK,CAAC;QACpB,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC;QACzB,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC,CAAC;CACJ;AAED;;;GAGG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,MAAM,CAAS;;IAYvB;;OAEG;IACG,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,GAAG;QAAE,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAYzG;;OAEG;YACW,UAAU;IA8CxB;;OAEG;YACW,aAAa;IA2C3B;;OAEG;IACH,OAAO,CAAC,gBAAgB;CA+DzB"}
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Simplified AI client that doesn't depend on MJ AI infrastructure
|
|
4
|
-
* Uses direct HTTP calls to AI providers
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.SimpleAIClient = void 0;
|
|
8
|
-
/**
|
|
9
|
-
* Simple AI client - uses fetch() to call OpenAI directly
|
|
10
|
-
* TODO: Add support for other providers (Anthropic, Groq, etc.)
|
|
11
|
-
*/
|
|
12
|
-
class SimpleAIClient {
|
|
13
|
-
constructor() {
|
|
14
|
-
this.provider = process.env.AI_PROVIDER || 'openai';
|
|
15
|
-
this.model = process.env.AI_MODEL || 'gpt-4';
|
|
16
|
-
this.apiKey = process.env.AI_API_KEY || '';
|
|
17
|
-
if (!this.apiKey) {
|
|
18
|
-
throw new Error('AI_API_KEY environment variable is required');
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Generate table documentation
|
|
23
|
-
*/
|
|
24
|
-
async generateTableDoc(request) {
|
|
25
|
-
const prompt = this.buildTablePrompt(request);
|
|
26
|
-
if (this.provider === 'openai') {
|
|
27
|
-
return await this.callOpenAI(prompt);
|
|
28
|
-
}
|
|
29
|
-
else if (this.provider === 'anthropic') {
|
|
30
|
-
return await this.callAnthropic(prompt);
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
throw new Error(`Unsupported AI provider: ${this.provider}`);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Call OpenAI API
|
|
38
|
-
*/
|
|
39
|
-
async callOpenAI(prompt) {
|
|
40
|
-
const response = await fetch('https://api.openai.com/v1/chat/completions', {
|
|
41
|
-
method: 'POST',
|
|
42
|
-
headers: {
|
|
43
|
-
'Content-Type': 'application/json',
|
|
44
|
-
'Authorization': `Bearer ${this.apiKey}`,
|
|
45
|
-
},
|
|
46
|
-
body: JSON.stringify({
|
|
47
|
-
model: this.model,
|
|
48
|
-
messages: [
|
|
49
|
-
{
|
|
50
|
-
role: 'system',
|
|
51
|
-
content: 'You are a database documentation expert. Generate clear, business-friendly descriptions for database tables and columns. Always respond with valid JSON only.',
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
role: 'user',
|
|
55
|
-
content: prompt,
|
|
56
|
-
},
|
|
57
|
-
],
|
|
58
|
-
temperature: 0.3,
|
|
59
|
-
max_tokens: 2000,
|
|
60
|
-
}),
|
|
61
|
-
});
|
|
62
|
-
if (!response.ok) {
|
|
63
|
-
throw new Error(`OpenAI API error: ${response.statusText}`);
|
|
64
|
-
}
|
|
65
|
-
const data = await response.json();
|
|
66
|
-
const content = data.choices?.[0]?.message?.content;
|
|
67
|
-
if (!content) {
|
|
68
|
-
throw new Error('No content in AI response');
|
|
69
|
-
}
|
|
70
|
-
// Parse JSON response
|
|
71
|
-
const jsonMatch = content.match(/```json\s*([\s\S]*?)\s*```/) || content.match(/\{[\s\S]*\}/);
|
|
72
|
-
const jsonStr = jsonMatch ? (jsonMatch[1] || jsonMatch[0]) : content;
|
|
73
|
-
const doc = JSON.parse(jsonStr);
|
|
74
|
-
return {
|
|
75
|
-
...doc,
|
|
76
|
-
tokensUsed: data.usage?.total_tokens || 0,
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Call Anthropic API
|
|
81
|
-
*/
|
|
82
|
-
async callAnthropic(prompt) {
|
|
83
|
-
const response = await fetch('https://api.anthropic.com/v1/messages', {
|
|
84
|
-
method: 'POST',
|
|
85
|
-
headers: {
|
|
86
|
-
'Content-Type': 'application/json',
|
|
87
|
-
'x-api-key': this.apiKey,
|
|
88
|
-
'anthropic-version': '2023-06-01',
|
|
89
|
-
},
|
|
90
|
-
body: JSON.stringify({
|
|
91
|
-
model: this.model,
|
|
92
|
-
max_tokens: 2000,
|
|
93
|
-
temperature: 0.3,
|
|
94
|
-
messages: [
|
|
95
|
-
{
|
|
96
|
-
role: 'user',
|
|
97
|
-
content: `You are a database documentation expert. Generate clear, business-friendly descriptions for database tables and columns. Always respond with valid JSON only.\n\n${prompt}`,
|
|
98
|
-
},
|
|
99
|
-
],
|
|
100
|
-
}),
|
|
101
|
-
});
|
|
102
|
-
if (!response.ok) {
|
|
103
|
-
throw new Error(`Anthropic API error: ${response.statusText}`);
|
|
104
|
-
}
|
|
105
|
-
const data = await response.json();
|
|
106
|
-
const content = data.content?.[0]?.text;
|
|
107
|
-
if (!content) {
|
|
108
|
-
throw new Error('No content in AI response');
|
|
109
|
-
}
|
|
110
|
-
// Parse JSON response
|
|
111
|
-
const jsonMatch = content.match(/```json\s*([\s\S]*?)\s*```/) || content.match(/\{[\s\S]*\}/);
|
|
112
|
-
const jsonStr = jsonMatch ? (jsonMatch[1] || jsonMatch[0]) : content;
|
|
113
|
-
const doc = JSON.parse(jsonStr);
|
|
114
|
-
return {
|
|
115
|
-
...doc,
|
|
116
|
-
tokensUsed: (data.usage?.input_tokens || 0) + (data.usage?.output_tokens || 0),
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Build table documentation prompt
|
|
121
|
-
*/
|
|
122
|
-
buildTablePrompt(request) {
|
|
123
|
-
const lines = [];
|
|
124
|
-
lines.push(`# Table: ${request.schema}.${request.table}`);
|
|
125
|
-
lines.push('');
|
|
126
|
-
lines.push('## Columns');
|
|
127
|
-
for (const col of request.columns) {
|
|
128
|
-
const flags = [];
|
|
129
|
-
if (col.isPK)
|
|
130
|
-
flags.push('PK');
|
|
131
|
-
if (col.isFK)
|
|
132
|
-
flags.push('FK');
|
|
133
|
-
if (!col.nullable)
|
|
134
|
-
flags.push('NOT NULL');
|
|
135
|
-
lines.push(`- ${col.name} (${col.type}) ${flags.join(', ')}`);
|
|
136
|
-
}
|
|
137
|
-
if (request.foreignKeys.length > 0) {
|
|
138
|
-
lines.push('');
|
|
139
|
-
lines.push('## Foreign Keys');
|
|
140
|
-
for (const fk of request.foreignKeys) {
|
|
141
|
-
lines.push(`- ${fk.column} → ${fk.referencedTable}`);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
if (request.sampleData && request.sampleData.length > 0) {
|
|
145
|
-
lines.push('');
|
|
146
|
-
lines.push('## Sample Data');
|
|
147
|
-
lines.push(JSON.stringify(request.sampleData.slice(0, 3), null, 2));
|
|
148
|
-
}
|
|
149
|
-
if (request.existingDescription) {
|
|
150
|
-
lines.push('');
|
|
151
|
-
lines.push('## Existing Description');
|
|
152
|
-
lines.push(request.existingDescription);
|
|
153
|
-
}
|
|
154
|
-
if (request.userNotes) {
|
|
155
|
-
lines.push('');
|
|
156
|
-
lines.push('## User Notes');
|
|
157
|
-
lines.push(request.userNotes);
|
|
158
|
-
}
|
|
159
|
-
lines.push('');
|
|
160
|
-
lines.push('## Task');
|
|
161
|
-
lines.push('Generate documentation for this table. Return ONLY a JSON object with this exact structure:');
|
|
162
|
-
lines.push('```json');
|
|
163
|
-
lines.push('{');
|
|
164
|
-
lines.push(' "description": "What this table stores (2-3 sentences)",');
|
|
165
|
-
lines.push(' "purpose": "Why this table exists (1 sentence)",');
|
|
166
|
-
lines.push(' "businessDomain": "e.g., Sales, HR, Inventory",');
|
|
167
|
-
lines.push(' "confidence": 0.85,');
|
|
168
|
-
lines.push(' "columns": [');
|
|
169
|
-
lines.push(' {');
|
|
170
|
-
lines.push(' "name": "ColumnName",');
|
|
171
|
-
lines.push(' "description": "What this column contains",');
|
|
172
|
-
lines.push(' "confidence": 0.9');
|
|
173
|
-
lines.push(' }');
|
|
174
|
-
lines.push(' ]');
|
|
175
|
-
lines.push('}');
|
|
176
|
-
lines.push('```');
|
|
177
|
-
return lines.join('\n');
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
exports.SimpleAIClient = SimpleAIClient;
|
|
181
|
-
//# sourceMappingURL=simple-ai-client.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"simple-ai-client.js","sourceRoot":"","sources":["../../src/ai/simple-ai-client.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAyCH;;;GAGG;AACH,MAAa,cAAc;IAKzB;QACE,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,QAAQ,CAAC;QACpD,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,OAAO,CAAC;QAC7C,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,EAAE,CAAC;QAE3C,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;QACjE,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,gBAAgB,CAAC,OAA0B;QAC/C,MAAM,MAAM,GAAG,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;QAE9C,IAAI,IAAI,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;YAC/B,OAAO,MAAM,IAAI,CAAC,UAA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AAC,SAAS,CAAC,CAAC;QAChC,CAAC;QAED,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACf,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACtB,KAAK,CAAC,IAAI,CAAC,6FAA6F,CAAC,CAAC;QAC1G,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACtB,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAChB,KAAK,CAAC,IAAI,CAAC,4DAA4D,CAAC,CAAC;QACzE,KAAK,CAAC,IAAI,CAAC,oDAAoD,CAAC,CAAC;QACjE,KAAK,CAAC,IAAI,CAAC,mDAAmD,CAAC,CAAC;QAChE,KAAK,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;QACpC,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAC7B,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpB,KAAK,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;QAC1C,KAAK,CAAC,IAAI,CAAC,mDAAmD,CAAC,CAAC;QAChE,KAAK,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;QACtC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpB,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAClB,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAChB,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAElB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CACF;AA/LD,wCA+LC"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { DatabaseConnection } from '../database/connection.js';
|
|
2
|
-
import { StateManager } from '../state/state-manager.js';
|
|
3
|
-
import { SimpleAIClient as AIClient } from '../ai/simple-ai-client.js';
|
|
4
|
-
export interface AnalyzerOptions {
|
|
5
|
-
schemas?: string[];
|
|
6
|
-
excludeSchemas?: string[];
|
|
7
|
-
interactive?: boolean;
|
|
8
|
-
incremental?: boolean;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Main analyzer orchestrating the documentation process
|
|
12
|
-
*/
|
|
13
|
-
export declare class DatabaseAnalyzer {
|
|
14
|
-
private connection;
|
|
15
|
-
private stateManager;
|
|
16
|
-
private aiClient;
|
|
17
|
-
constructor(connection: DatabaseConnection, stateManager: StateManager, aiClient: AIClient);
|
|
18
|
-
/**
|
|
19
|
-
* Analyze database and generate documentation
|
|
20
|
-
*/
|
|
21
|
-
analyze(options?: AnalyzerOptions): Promise<void>;
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=analyzer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"analyzer.d.ts","sourceRoot":"","sources":["../../src/analyzers/analyzer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE5D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,cAAc,IAAI,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAGpE,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;GAEG;AACH,qBAAa,gBAAgB;IAEzB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,QAAQ;gBAFR,UAAU,EAAE,kBAAkB,EAC9B,YAAY,EAAE,YAAY,EAC1B,QAAQ,EAAE,QAAQ;IAG5B;;OAEG;IACG,OAAO,CAAC,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;CA8H5D"}
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.DatabaseAnalyzer = void 0;
|
|
7
|
-
const introspection_1 = require("../database/introspection.js");
|
|
8
|
-
const ora_1 = __importDefault(require("ora"));
|
|
9
|
-
/**
|
|
10
|
-
* Main analyzer orchestrating the documentation process
|
|
11
|
-
*/
|
|
12
|
-
class DatabaseAnalyzer {
|
|
13
|
-
constructor(connection, stateManager, aiClient) {
|
|
14
|
-
this.connection = connection;
|
|
15
|
-
this.stateManager = stateManager;
|
|
16
|
-
this.aiClient = aiClient;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Analyze database and generate documentation
|
|
20
|
-
*/
|
|
21
|
-
async analyze(options = {}) {
|
|
22
|
-
const spinner = (0, ora_1.default)('Analyzing database...').start();
|
|
23
|
-
try {
|
|
24
|
-
const introspector = new introspection_1.DatabaseIntrospector(this.connection);
|
|
25
|
-
// Get tables to process
|
|
26
|
-
const tables = await introspector.getTables(options.schemas, options.excludeSchemas);
|
|
27
|
-
spinner.succeed(`Found ${tables.length} tables`);
|
|
28
|
-
let processed = 0;
|
|
29
|
-
let skipped = 0;
|
|
30
|
-
let totalTokens = 0;
|
|
31
|
-
for (const tableInfo of tables) {
|
|
32
|
-
const tableSpinner = (0, ora_1.default)(`Processing ${tableInfo.schema}.${tableInfo.table}`).start();
|
|
33
|
-
try {
|
|
34
|
-
// Check if already processed (incremental mode)
|
|
35
|
-
if (options.incremental) {
|
|
36
|
-
const state = this.stateManager.getState();
|
|
37
|
-
const schema = state.schemas[tableInfo.schema];
|
|
38
|
-
if (schema?.tables[tableInfo.table]?.aiGenerated) {
|
|
39
|
-
tableSpinner.info(`Skipping ${tableInfo.schema}.${tableInfo.table} (already processed)`);
|
|
40
|
-
skipped++;
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
// Get table details
|
|
45
|
-
const [columns, foreignKeys, extProps, sampleData] = await Promise.all([
|
|
46
|
-
introspector.getColumns(tableInfo.schema, tableInfo.table),
|
|
47
|
-
introspector.getForeignKeys(tableInfo.schema, tableInfo.table),
|
|
48
|
-
introspector.getExtendedProperties(tableInfo.schema, tableInfo.table),
|
|
49
|
-
introspector.sampleData(tableInfo.schema, tableInfo.table, 5),
|
|
50
|
-
]);
|
|
51
|
-
// Get existing description
|
|
52
|
-
const existingDesc = extProps.find(p => p.objectType === 'TABLE')?.value;
|
|
53
|
-
// Generate documentation with AI
|
|
54
|
-
const aiDoc = await this.aiClient.generateTableDoc({
|
|
55
|
-
schema: tableInfo.schema,
|
|
56
|
-
table: tableInfo.table,
|
|
57
|
-
columns: columns.map(c => ({
|
|
58
|
-
name: c.name,
|
|
59
|
-
type: c.dataType,
|
|
60
|
-
nullable: c.isNullable,
|
|
61
|
-
isPK: c.isPrimaryKey,
|
|
62
|
-
isFK: c.isForeignKey,
|
|
63
|
-
})),
|
|
64
|
-
foreignKeys: foreignKeys.map(fk => ({
|
|
65
|
-
column: fk.column,
|
|
66
|
-
referencedTable: `${fk.referencedSchema}.${fk.referencedTable}`,
|
|
67
|
-
})),
|
|
68
|
-
sampleData,
|
|
69
|
-
existingDescription: existingDesc,
|
|
70
|
-
});
|
|
71
|
-
// Update state with table documentation
|
|
72
|
-
this.stateManager.updateTableAI(tableInfo.schema, tableInfo.table, {
|
|
73
|
-
description: aiDoc.description,
|
|
74
|
-
purpose: aiDoc.purpose,
|
|
75
|
-
usageNotes: aiDoc.usageNotes,
|
|
76
|
-
businessDomain: aiDoc.businessDomain,
|
|
77
|
-
confidence: aiDoc.confidence,
|
|
78
|
-
model: process.env.AI_MODEL || 'gpt-4',
|
|
79
|
-
tokensUsed: aiDoc.tokensUsed,
|
|
80
|
-
relationships: aiDoc.relationships,
|
|
81
|
-
});
|
|
82
|
-
// Update columns
|
|
83
|
-
for (const colDoc of aiDoc.columns) {
|
|
84
|
-
this.stateManager.updateColumnAI(tableInfo.schema, tableInfo.table, colDoc.name, {
|
|
85
|
-
description: colDoc.description,
|
|
86
|
-
purpose: colDoc.purpose,
|
|
87
|
-
validValues: colDoc.validValues,
|
|
88
|
-
confidence: colDoc.confidence,
|
|
89
|
-
model: process.env.AI_MODEL || 'gpt-4',
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
if (aiDoc.tokensUsed) {
|
|
93
|
-
totalTokens += aiDoc.tokensUsed;
|
|
94
|
-
}
|
|
95
|
-
processed++;
|
|
96
|
-
tableSpinner.succeed(`Processed ${tableInfo.schema}.${tableInfo.table} (confidence: ${(aiDoc.confidence * 100).toFixed(0)}%)`);
|
|
97
|
-
}
|
|
98
|
-
catch (error) {
|
|
99
|
-
tableSpinner.fail(`Failed to process ${tableInfo.schema}.${tableInfo.table}: ${error}`);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
// Save state
|
|
103
|
-
await this.stateManager.save();
|
|
104
|
-
// Add run history
|
|
105
|
-
this.stateManager.addRunHistory({
|
|
106
|
-
timestamp: new Date().toISOString(),
|
|
107
|
-
phase: 'analyze',
|
|
108
|
-
tablesProcessed: processed,
|
|
109
|
-
tokensUsed: totalTokens,
|
|
110
|
-
cost: totalTokens * 0.000002, // Rough estimate
|
|
111
|
-
});
|
|
112
|
-
await this.stateManager.save();
|
|
113
|
-
console.log('');
|
|
114
|
-
console.log(`✅ Analysis complete!`);
|
|
115
|
-
console.log(` Processed: ${processed} tables`);
|
|
116
|
-
console.log(` Skipped: ${skipped} tables`);
|
|
117
|
-
console.log(` Tokens used: ${totalTokens.toLocaleString()}`);
|
|
118
|
-
console.log(` Estimated cost: $${(totalTokens * 0.000002).toFixed(4)}`);
|
|
119
|
-
}
|
|
120
|
-
catch (error) {
|
|
121
|
-
spinner.fail(`Analysis failed: ${error}`);
|
|
122
|
-
throw error;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
exports.DatabaseAnalyzer = DatabaseAnalyzer;
|
|
127
|
-
//# sourceMappingURL=analyzer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"analyzer.js","sourceRoot":"","sources":["../../src/analyzers/analyzer.ts"],"names":[],"mappings":";;;;;;AACA,6DAAiE;AAGjE,8CAAsB;AAStB;;GAEG;AACH,MAAa,gBAAgB;IAC3B,YACU,UAA8B,EAC9B,YAA0B,EAC1B,QAAkB;QAFlB,eAAU,GAAV,UAAU,CAAoB;QAC9B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,aAAQ,GAAR,QAAQ,CAAU;IACzB,CAAC;IAEJ;;OAEG;IACH,KAAK,CAAC,OAAO,CAAC,UAA2B,EAAE;QACzC,MAAM,OAAO,GAAG,IAAA,aAAG,EAAC,uBAAuB,CAAC,CAAC,KAAK,EAAE,CAAC;QAErD,IAAI,CAAC;YACH,MAAM,YAAY,GAAG,IAAI,oCAAoB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAE/D,wBAAwB;YACxB,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;YAErF,OAAO,CAAC,OAAO,CAAC,SAAS,MAAM,CAAC,MAAM,SAAS,CAAC,CAAC;YAEjD,IAAI,SAAS,GAAG,CAAC,CAAC;YAClB,IAAI,OAAO,GAAG,CAAC,CAAC;YAChB,IAAI,WAAW,GAAG,CAAC,CAAC;YAEpB,KAAK,MAAM,SAAS,IAAI,MAAM,EAAE,CAAC;gBAC/B,MAAM,YAAY,GAAG,IAAA,aAAG,EAAC,cAAc,SAAS,CAAC,MAAM,IAAI,SAAS,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;gBAEtF,IAAI,CAAC;oBACH,gDAAgD;oBAChD,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;wBACxB,MAAM,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