@askdb/core 1.0.0-beta.52 → 1.0.0-beta.53
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/dist/retrieval/synthesize-ddl.d.ts +19 -4
- package/dist/retrieval/synthesize-ddl.d.ts.map +1 -1
- package/dist/retrieval/synthesize-ddl.js +82 -19
- package/dist/retrieval/synthesize-ddl.js.map +1 -1
- package/dist/schema/v2/format.d.ts +55 -9
- package/dist/schema/v2/format.d.ts.map +1 -1
- package/dist/schema/v2/format.js +131 -11
- package/dist/schema/v2/format.js.map +1 -1
- package/dist/schema/v2/loader.js +36 -1
- package/dist/schema/v2/loader.js.map +1 -1
- package/dist/schema/v2/normalized.d.ts +4 -0
- package/dist/schema/v2/normalized.d.ts.map +1 -1
- package/dist/sql/readings.d.ts +7 -3
- package/dist/sql/readings.d.ts.map +1 -1
- package/dist/sql/readings.js +31 -8
- package/dist/sql/readings.js.map +1 -1
- package/dist/sql/tenant-guardrail.d.ts +9 -4
- package/dist/sql/tenant-guardrail.d.ts.map +1 -1
- package/dist/sql/tenant-guardrail.js +869 -160
- package/dist/sql/tenant-guardrail.js.map +1 -1
- package/package.json +1 -1
|
@@ -7,11 +7,26 @@ import type { RetrievedResult } from "./types.js";
|
|
|
7
7
|
* 1. Each table referenced by any retrieved chunk gets a TABLE block with
|
|
8
8
|
* its full column definitions (so the model has complete column lists).
|
|
9
9
|
* Each column line carries the schema's own `-- aliases / values / desc`
|
|
10
|
-
* annotation
|
|
10
|
+
* annotation, with the column's note (ADR 0042, amended for #898); a
|
|
11
|
+
* retrieved column chunk only picks its table.
|
|
12
|
+
* Then the table's foreign keys to other shown tables, as the
|
|
13
|
+
* full-schema prompt prints them (#898).
|
|
11
14
|
* 2. CQL chunks land as a `-- common query language --` block under the
|
|
12
|
-
* table
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
+
* table, then `Business context` chunks as a `-- business context --`
|
|
16
|
+
* block, its parts in body order (#894).
|
|
17
|
+
* 3. Concept, example-question and tenant-policy chunks follow the tables,
|
|
18
|
+
* each kind as its own `-- … --` block, in that order. A concept the
|
|
19
|
+
* schema has prints as the full-schema prompt prints it
|
|
20
|
+
* (`conceptRenderer`); another keeps its chunk text and heading, as a
|
|
21
|
+
* tenant-policy chunk does (the policy section's name). A relationship
|
|
22
|
+
* chunk only picks its two tables: their foreign key prints from the
|
|
23
|
+
* schema (#898).
|
|
24
|
+
*
|
|
25
|
+
* `@askdb/rag` types a `Business context` chunk `table`; its id
|
|
26
|
+
* (`…<table-id>#biz`, `…#biz#bc:<n>` for part n of a long body; the schema v2
|
|
27
|
+
* contract's chunking rules) tells it apart from the table chunk. A sensitive
|
|
28
|
+
* table's CQL and business context never show, like the schema's own
|
|
29
|
+
* describable text.
|
|
15
30
|
*
|
|
16
31
|
* Sensitive identifiers retain their `(sensitive)` tagging exactly as
|
|
17
32
|
* `formatSchemaV2ForNlToSql` does. With `omitSensitiveIdentifiersFromPrompt`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"synthesize-ddl.d.ts","sourceRoot":"","sources":["../../src/retrieval/synthesize-ddl.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"synthesize-ddl.d.ts","sourceRoot":"","sources":["../../src/retrieval/synthesize-ddl.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE;IAC3C,MAAM,EAAE,kBAAkB,CAAC;IAC3B,OAAO,EAAE,eAAe,EAAE,CAAC;IAC3B,iFAAiF;IACjF,kCAAkC,CAAC,EAAE,OAAO,CAAC;IAC7C,mEAAmE;IACnE,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,8DAA8D;IAC9D,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CAC5C,GAAG;IACF,GAAG,EAAE,MAAM,CAAC;IACZ,aAAa,EAAE,MAAM,CAAC;IACtB,sGAAsG;IACtG,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,0HAA0H;IAC1H,mBAAmB,EAAE,MAAM,CAAC;CAC7B,CAgLA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { columnAnnotation, listAsStored, promptTableName, promptTextGate, tableAliasNote, } from "../schema/v2/format.js";
|
|
1
|
+
import { businessContextLines, columnAnnotation, conceptRenderer, foreignKeyLinesByTable, listAsStored, promptTableName, promptTextGate, tableAliasNote, } from "../schema/v2/format.js";
|
|
2
2
|
/**
|
|
3
3
|
* Build a focused DDL block for NL→SQL prompts from retrieved chunks.
|
|
4
4
|
*
|
|
@@ -6,11 +6,26 @@ import { columnAnnotation, listAsStored, promptTableName, promptTextGate, tableA
|
|
|
6
6
|
* 1. Each table referenced by any retrieved chunk gets a TABLE block with
|
|
7
7
|
* its full column definitions (so the model has complete column lists).
|
|
8
8
|
* Each column line carries the schema's own `-- aliases / values / desc`
|
|
9
|
-
* annotation
|
|
9
|
+
* annotation, with the column's note (ADR 0042, amended for #898); a
|
|
10
|
+
* retrieved column chunk only picks its table.
|
|
11
|
+
* Then the table's foreign keys to other shown tables, as the
|
|
12
|
+
* full-schema prompt prints them (#898).
|
|
10
13
|
* 2. CQL chunks land as a `-- common query language --` block under the
|
|
11
|
-
* table
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
+
* table, then `Business context` chunks as a `-- business context --`
|
|
15
|
+
* block, its parts in body order (#894).
|
|
16
|
+
* 3. Concept, example-question and tenant-policy chunks follow the tables,
|
|
17
|
+
* each kind as its own `-- … --` block, in that order. A concept the
|
|
18
|
+
* schema has prints as the full-schema prompt prints it
|
|
19
|
+
* (`conceptRenderer`); another keeps its chunk text and heading, as a
|
|
20
|
+
* tenant-policy chunk does (the policy section's name). A relationship
|
|
21
|
+
* chunk only picks its two tables: their foreign key prints from the
|
|
22
|
+
* schema (#898).
|
|
23
|
+
*
|
|
24
|
+
* `@askdb/rag` types a `Business context` chunk `table`; its id
|
|
25
|
+
* (`…<table-id>#biz`, `…#biz#bc:<n>` for part n of a long body; the schema v2
|
|
26
|
+
* contract's chunking rules) tells it apart from the table chunk. A sensitive
|
|
27
|
+
* table's CQL and business context never show, like the schema's own
|
|
28
|
+
* describable text.
|
|
14
29
|
*
|
|
15
30
|
* Sensitive identifiers retain their `(sensitive)` tagging exactly as
|
|
16
31
|
* `formatSchemaV2ForNlToSql` does. With `omitSensitiveIdentifiersFromPrompt`,
|
|
@@ -24,9 +39,12 @@ export function synthesizeRetrievedDdl(args) {
|
|
|
24
39
|
const omit = args.omitSensitiveIdentifiersFromPrompt === true;
|
|
25
40
|
const quoteIdentifier = args.quoteIdentifier ?? listAsStored;
|
|
26
41
|
const gate = promptTextGate(schema, omit);
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Renders a retrieved chunk's text as the prompt shows it, then lets the gate check exactly that.
|
|
44
|
+
* `keepHeading` keeps the chunk's `# heading` line, without its `#`.
|
|
45
|
+
*/
|
|
46
|
+
const shown = (p, render, into, keepHeading = false) => {
|
|
47
|
+
const text = render(keepHeading ? headingKept(p.text) : stripHeaderLine(p.text));
|
|
30
48
|
if (gate.allows(text, p.sensitive))
|
|
31
49
|
into.push(text);
|
|
32
50
|
};
|
|
@@ -35,14 +53,30 @@ export function synthesizeRetrievedDdl(args) {
|
|
|
35
53
|
const joinedLines = (body) => body.replace(/\n+/g, "; ");
|
|
36
54
|
const tableIds = new Set();
|
|
37
55
|
const cqlPerTable = new Map();
|
|
56
|
+
const businessPerTable = new Map();
|
|
38
57
|
const concepts = [];
|
|
39
58
|
const questions = [];
|
|
40
|
-
const relationships = [];
|
|
41
59
|
const tenantPolicyChunks = [];
|
|
60
|
+
const renderConcept = conceptRenderer(schema, { unqualifiedNamespace: args.unqualifiedNamespace, quoteIdentifier });
|
|
42
61
|
for (const r of results) {
|
|
43
62
|
const p = r.payload;
|
|
44
63
|
switch (p.type) {
|
|
45
|
-
case "table":
|
|
64
|
+
case "table": {
|
|
65
|
+
const tid = p.refs[0];
|
|
66
|
+
if (!tid)
|
|
67
|
+
break;
|
|
68
|
+
tableIds.add(tid);
|
|
69
|
+
const part = businessContextPart(p.id, tid);
|
|
70
|
+
if (part !== undefined) {
|
|
71
|
+
const kept = [];
|
|
72
|
+
shown(p, asIs, kept);
|
|
73
|
+
const list = businessPerTable.get(tid) ?? [];
|
|
74
|
+
for (const text of kept)
|
|
75
|
+
list.push({ part, text });
|
|
76
|
+
businessPerTable.set(tid, list);
|
|
77
|
+
}
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
46
80
|
case "column": {
|
|
47
81
|
const tid = p.refs[0];
|
|
48
82
|
if (tid)
|
|
@@ -66,7 +100,15 @@ export function synthesizeRetrievedDdl(args) {
|
|
|
66
100
|
break;
|
|
67
101
|
}
|
|
68
102
|
case "concept": {
|
|
69
|
-
|
|
103
|
+
const concept = schema.concepts?.find((c) => c.id === p.refs[0]);
|
|
104
|
+
if (concept) {
|
|
105
|
+
const rendered = renderConcept(concept);
|
|
106
|
+
if (rendered && gate.allows(rendered.text, p.sensitive || rendered.linksSensitive))
|
|
107
|
+
concepts.push(rendered.body);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
shown(p, joinedLines, concepts, true);
|
|
111
|
+
}
|
|
70
112
|
for (const ref of p.refs) {
|
|
71
113
|
if (ref.startsWith("table:")) {
|
|
72
114
|
const hash = ref.indexOf("#");
|
|
@@ -76,7 +118,6 @@ export function synthesizeRetrievedDdl(args) {
|
|
|
76
118
|
break;
|
|
77
119
|
}
|
|
78
120
|
case "relationship": {
|
|
79
|
-
shown(p, oneLine, relationships);
|
|
80
121
|
for (const ref of p.refs) {
|
|
81
122
|
if (ref.startsWith("table:") && !ref.includes("#"))
|
|
82
123
|
tableIds.add(ref);
|
|
@@ -84,13 +125,19 @@ export function synthesizeRetrievedDdl(args) {
|
|
|
84
125
|
break;
|
|
85
126
|
}
|
|
86
127
|
case "tenant-policy": {
|
|
87
|
-
shown(p, joinedLines, tenantPolicyChunks);
|
|
128
|
+
shown(p, joinedLines, tenantPolicyChunks, true);
|
|
88
129
|
break;
|
|
89
130
|
}
|
|
90
131
|
}
|
|
91
132
|
}
|
|
92
133
|
const lines = [];
|
|
93
134
|
const emittedIds = [];
|
|
135
|
+
const foreignKeys = foreignKeyLinesByTable(schema, {
|
|
136
|
+
omit,
|
|
137
|
+
shown: (tableId) => tableIds.has(tableId),
|
|
138
|
+
unqualifiedNamespace: args.unqualifiedNamespace,
|
|
139
|
+
quoteIdentifier,
|
|
140
|
+
});
|
|
94
141
|
for (const t of schema.tables) {
|
|
95
142
|
if (!tableIds.has(t.id))
|
|
96
143
|
continue;
|
|
@@ -120,6 +167,7 @@ export function synthesizeRetrievedDdl(args) {
|
|
|
120
167
|
}
|
|
121
168
|
lines.push(line);
|
|
122
169
|
}
|
|
170
|
+
lines.push(...(foreignKeys.get(t.id) ?? []));
|
|
123
171
|
const cqlList = cqlPerTable.get(t.id);
|
|
124
172
|
if (cqlList && cqlList.length > 0 && !t.sensitive) {
|
|
125
173
|
lines.push(`-- common query language --`);
|
|
@@ -129,12 +177,10 @@ export function synthesizeRetrievedDdl(args) {
|
|
|
129
177
|
}
|
|
130
178
|
}
|
|
131
179
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
for (const r of relationships)
|
|
137
|
-
lines.push(`-- ${r}`);
|
|
180
|
+
const businessList = businessPerTable.get(t.id);
|
|
181
|
+
if (businessList && !t.sensitive) {
|
|
182
|
+
lines.push(...businessContextLines([...businessList].sort((a, b) => a.part - b.part).map(({ text }) => text)));
|
|
183
|
+
}
|
|
138
184
|
lines.push("");
|
|
139
185
|
}
|
|
140
186
|
if (concepts.length > 0) {
|
|
@@ -163,6 +209,23 @@ export function synthesizeRetrievedDdl(args) {
|
|
|
163
209
|
mentionDroppedCount: gate.withheld,
|
|
164
210
|
};
|
|
165
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* For a `table` chunk built from `tableId`'s `Business context` section, the part's position in
|
|
214
|
+
* the body (0 when the body wasn't split); `undefined` for any other chunk, the table chunk included.
|
|
215
|
+
*/
|
|
216
|
+
function businessContextPart(chunkId, tableId) {
|
|
217
|
+
const marker = `${tableId}#biz`;
|
|
218
|
+
if (chunkId.endsWith(marker))
|
|
219
|
+
return 0;
|
|
220
|
+
const split = /#bc:(\d+)$/.exec(chunkId);
|
|
221
|
+
if (split && chunkId.slice(0, split.index).endsWith(marker))
|
|
222
|
+
return Number(split[1]);
|
|
223
|
+
return undefined;
|
|
224
|
+
}
|
|
225
|
+
/** The chunk's text with its `# heading` line kept as a plain line. */
|
|
226
|
+
function headingKept(text) {
|
|
227
|
+
return text.trim().replace(/^#+\s*/, "");
|
|
228
|
+
}
|
|
166
229
|
function stripHeaderLine(text) {
|
|
167
230
|
if (text.startsWith("#")) {
|
|
168
231
|
const nl = text.indexOf("\n");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"synthesize-ddl.js","sourceRoot":"","sources":["../../src/retrieval/synthesize-ddl.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,cAAc,EACd,cAAc,GACf,MAAM,wBAAwB,CAAC;AAIhC
|
|
1
|
+
{"version":3,"file":"synthesize-ddl.js","sourceRoot":"","sources":["../../src/retrieval/synthesize-ddl.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,sBAAsB,EACtB,YAAY,EACZ,eAAe,EACf,cAAc,EACd,cAAc,GACf,MAAM,wBAAwB,CAAC;AAIhC;;;;;;;;;;;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BAAmB,CAAC,OAAe,EAAE,OAAe;IAC3D,MAAM,MAAM,GAAG,GAAG,OAAO,MAAM,CAAC;IAChC,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,CAAC,CAAC;IACvC,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACzC,IAAI,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACrF,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,uEAAuE;AACvE,SAAS,WAAW,CAAC,IAAY;IAC/B,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;AAC3C,CAAC;AAED,SAAS,eAAe,CAAC,IAAY;IACnC,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACzB,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC9B,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACpD,CAAC;IACD,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC;AACrB,CAAC"}
|
|
@@ -3,12 +3,13 @@ import type { FormatNlToSqlOptions, NlToSqlSchemaFormatStats } from "../normaliz
|
|
|
3
3
|
/**
|
|
4
4
|
* Format a NormalizedSchemaV2 for NL→SQL prompts.
|
|
5
5
|
*
|
|
6
|
-
* Interleaves table descriptions, aliases, column descriptions,
|
|
7
|
-
* `Common query language`
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
6
|
+
* Interleaves table descriptions, aliases, column descriptions and notes, each
|
|
7
|
+
* table's foreign keys ({@link foreignKeyLinesByTable}), `Common query language`
|
|
8
|
+
* and `Business context` blocks when present in the describable layer, then the
|
|
9
|
+
* schema's concepts ({@link conceptLines}). Sensitive describable-layer fields
|
|
10
|
+
* (descriptions/aliases/enum) are excluded per the schema-v2 contract. With
|
|
11
|
+
* `omitSensitiveIdentifiersFromPrompt`, describable text that names a sensitive
|
|
12
|
+
* column is withheld too ({@link promptTextGate}).
|
|
12
13
|
*/
|
|
13
14
|
export declare function formatSchemaV2ForNlToSql(schema: NormalizedSchemaV2, options?: FormatNlToSqlOptions): {
|
|
14
15
|
ddl: string;
|
|
@@ -34,9 +35,10 @@ export declare function promptTextGate(schema: NormalizedSchemaV2, omit: boolean
|
|
|
34
35
|
/** A non-sensitive table's ` -- aliases: …` header note, each alias shown only when the gate allows it. */
|
|
35
36
|
export declare function tableAliasNote(t: NormalizedSchemaV2["tables"][0], gate: PromptTextGate): string;
|
|
36
37
|
/**
|
|
37
|
-
* A non-sensitive column's annotation (`aliases: …; values: …; description
|
|
38
|
-
* The
|
|
39
|
-
* withholds all of them.
|
|
38
|
+
* A non-sensitive column's annotation (`aliases: …; values: …; description; note: …`), or `""`.
|
|
39
|
+
* The parts are one unit, checked as rendered: when they name a sensitive column, the gate
|
|
40
|
+
* withholds all of them. The note joins the unit, as it joins the column's describable layer in
|
|
41
|
+
* `@askdb/rag`'s chunker (ADR 0042).
|
|
40
42
|
*/
|
|
41
43
|
export declare function columnAnnotation(c: NormalizedSchemaV2["tables"][0]["columns"][0], gate: PromptTextGate): string;
|
|
42
44
|
/**
|
|
@@ -44,6 +46,50 @@ export declare function columnAnnotation(c: NormalizedSchemaV2["tables"][0]["col
|
|
|
44
46
|
* namespace, each part passed through `quoteIdentifier`.
|
|
45
47
|
*/
|
|
46
48
|
export declare function promptTableName(table: Pick<NormalizedSchemaV2["tables"][0], "schema" | "name">, unqualifiedNamespace: string | undefined, quoteIdentifier?: (name: string) => string): string;
|
|
49
|
+
/** How a prompt names tables and columns: the options both NL→SQL prompt builders take. */
|
|
50
|
+
export type PromptNaming = {
|
|
51
|
+
unqualifiedNamespace: string | undefined;
|
|
52
|
+
quoteIdentifier: (name: string) => string;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* The schema's foreign keys as both NL→SQL prompts print them (#898), keyed by the id of the
|
|
56
|
+
* table that owns each key's column: ` FK (user_id) -> public.users (id)`, after the table's
|
|
57
|
+
* column lines. Each key prints once, from any table's `relationships`. A key is left out when
|
|
58
|
+
* either column doesn't resolve, either table is untracked or not `shown`, or, with `omit`,
|
|
59
|
+
* either column or table is sensitive, so a key never names a column the prompt withholds. A
|
|
60
|
+
* composite key prints one line per column pair until the artifact groups them (#349).
|
|
61
|
+
*/
|
|
62
|
+
export declare function foreignKeyLinesByTable(schema: NormalizedSchemaV2, options: PromptNaming & {
|
|
63
|
+
omit: boolean;
|
|
64
|
+
shown?: (tableId: string) => boolean;
|
|
65
|
+
}): Map<string, string[]>;
|
|
66
|
+
/** A concept as both NL→SQL prompts list it: the line's text, what the gate checks, and whether it links anything sensitive. */
|
|
67
|
+
export type RenderedConcept = {
|
|
68
|
+
body: string;
|
|
69
|
+
text: string;
|
|
70
|
+
linksSensitive: boolean;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Renders a concept as both NL→SQL prompts list it (#898): its label, synonyms, links (named as
|
|
74
|
+
* the prompt names tables and columns) and description, as one line. A link to an untracked
|
|
75
|
+
* table, or to a column of one, is dropped, and a concept whose links were all untracked
|
|
76
|
+
* renders as `undefined`; a link to a table or column the schema doesn't have is dropped too.
|
|
77
|
+
* `text` is the line without its fixed labels, for the gate (see {@link columnAnnotation});
|
|
78
|
+
* `linksSensitive` flags a concept that links a sensitive table or column.
|
|
79
|
+
*/
|
|
80
|
+
export declare function conceptRenderer(schema: NormalizedSchemaV2, naming: PromptNaming): (concept: NonNullable<NormalizedSchemaV2["concepts"]>[number]) => RenderedConcept | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* The schema's concepts as the full-schema prompt lists them after the tables (#898): a
|
|
83
|
+
* `-- concepts --` block, one {@link conceptRenderer} line per concept the gate allows (a
|
|
84
|
+
* concept that links a sensitive table or column is flagged, so omission withholds it too).
|
|
85
|
+
* `[]` when no concept is left.
|
|
86
|
+
*/
|
|
87
|
+
export declare function conceptLines(schema: NormalizedSchemaV2, gate: PromptTextGate, naming: PromptNaming): string[];
|
|
88
|
+
/**
|
|
89
|
+
* A table's `-- business context --` block: each body's lines as `--` comments, blank lines
|
|
90
|
+
* dropped (paragraphs are separated by them; an empty `--` line adds nothing). `[]` for none.
|
|
91
|
+
*/
|
|
92
|
+
export declare function businessContextLines(bodies: string[]): string[];
|
|
47
93
|
/** The default `quoteIdentifier`: a name listed exactly as stored. */
|
|
48
94
|
export declare function listAsStored(name: string): string;
|
|
49
95
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../src/schema/v2/format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAGtF
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../src/schema/v2/format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAGtF;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,kBAAkB,EAC1B,OAAO,GAAE,oBAAyB,GACjC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,wBAAwB,CAAA;CAAE,CAuFlD;AAED;;;;GAIG;AACH,KAA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GAC9E,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAsBvB;AAED,gIAAgI;AAChI,MAAM,MAAM,eAAe,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,OAAO,CAAA;CAAE,CAAC;AAEtF;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,kBAAkB,EAC1B,MAAM,EAAE,YAAY,GACnB,CAAC,OAAO,EAAE,WAAW,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,eAAe,GAAG,SAAS,CAkC/F;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,kBAAkB,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,YAAY,GAAG,MAAM,EAAE,CAQ7G;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAG/D;AAED,sEAAsE;AACtE,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEjD"}
|
package/dist/schema/v2/format.js
CHANGED
|
@@ -2,12 +2,13 @@ import { createMentionMatcher, sensitiveMentionNames } from "./mentions.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* Format a NormalizedSchemaV2 for NL→SQL prompts.
|
|
4
4
|
*
|
|
5
|
-
* Interleaves table descriptions, aliases, column descriptions,
|
|
6
|
-
* `Common query language`
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
5
|
+
* Interleaves table descriptions, aliases, column descriptions and notes, each
|
|
6
|
+
* table's foreign keys ({@link foreignKeyLinesByTable}), `Common query language`
|
|
7
|
+
* and `Business context` blocks when present in the describable layer, then the
|
|
8
|
+
* schema's concepts ({@link conceptLines}). Sensitive describable-layer fields
|
|
9
|
+
* (descriptions/aliases/enum) are excluded per the schema-v2 contract. With
|
|
10
|
+
* `omitSensitiveIdentifiersFromPrompt`, describable text that names a sensitive
|
|
11
|
+
* column is withheld too ({@link promptTextGate}).
|
|
11
12
|
*/
|
|
12
13
|
export function formatSchemaV2ForNlToSql(schema, options = {}) {
|
|
13
14
|
const omit = options.omitSensitiveIdentifiersFromPrompt === true;
|
|
@@ -18,6 +19,8 @@ export function formatSchemaV2ForNlToSql(schema, options = {}) {
|
|
|
18
19
|
let listedSensitiveColumnCount = 0;
|
|
19
20
|
let untrackedTableCount = 0;
|
|
20
21
|
const lines = [];
|
|
22
|
+
const naming = { unqualifiedNamespace: options.unqualifiedNamespace, quoteIdentifier };
|
|
23
|
+
const foreignKeys = foreignKeyLinesByTable(schema, { omit, ...naming });
|
|
21
24
|
for (const t of schema.tables) {
|
|
22
25
|
if (t.tracked === false) {
|
|
23
26
|
untrackedTableCount++;
|
|
@@ -58,6 +61,7 @@ export function formatSchemaV2ForNlToSql(schema, options = {}) {
|
|
|
58
61
|
lines.push(buildColumnLine(c, c.sensitive, t.sensitive, quoteIdentifier, gate));
|
|
59
62
|
}
|
|
60
63
|
}
|
|
64
|
+
lines.push(...(foreignKeys.get(t.id) ?? []));
|
|
61
65
|
// Common query language block
|
|
62
66
|
if (!t.sensitive && t.commonQueryLanguage && gate.allows(t.commonQueryLanguage)) {
|
|
63
67
|
lines.push(`-- common query language --`);
|
|
@@ -65,8 +69,13 @@ export function formatSchemaV2ForNlToSql(schema, options = {}) {
|
|
|
65
69
|
lines.push(`-- ${cqlLine}`);
|
|
66
70
|
}
|
|
67
71
|
}
|
|
72
|
+
// Business context block, under the same rules as common query language (#898)
|
|
73
|
+
if (!t.sensitive && t.businessContext && gate.allows(t.businessContext)) {
|
|
74
|
+
lines.push(...businessContextLines([t.businessContext]));
|
|
75
|
+
}
|
|
68
76
|
lines.push("");
|
|
69
77
|
}
|
|
78
|
+
lines.push(...conceptLines(schema, gate, naming));
|
|
70
79
|
const ddl = lines.join("\n").trimEnd();
|
|
71
80
|
return {
|
|
72
81
|
ddl,
|
|
@@ -104,19 +113,23 @@ export function tableAliasNote(t, gate) {
|
|
|
104
113
|
return aliases.length ? ` -- aliases: ${aliases.join(", ")}` : "";
|
|
105
114
|
}
|
|
106
115
|
/**
|
|
107
|
-
* A non-sensitive column's annotation (`aliases: …; values: …; description
|
|
108
|
-
* The
|
|
109
|
-
* withholds all of them.
|
|
116
|
+
* A non-sensitive column's annotation (`aliases: …; values: …; description; note: …`), or `""`.
|
|
117
|
+
* The parts are one unit, checked as rendered: when they name a sensitive column, the gate
|
|
118
|
+
* withholds all of them. The note joins the unit, as it joins the column's describable layer in
|
|
119
|
+
* `@askdb/rag`'s chunker (ADR 0042).
|
|
110
120
|
*/
|
|
111
121
|
export function columnAnnotation(c, gate) {
|
|
112
122
|
const aliases = c.aliases?.length ? c.aliases.join(", ") : "";
|
|
113
123
|
const values = c.enum?.length ? c.enum.join("|") : "";
|
|
114
124
|
const description = c.description ?? "";
|
|
115
|
-
const
|
|
125
|
+
const note = c.note ?? "";
|
|
126
|
+
const shown = [aliases, values, description, note].filter(Boolean);
|
|
116
127
|
// The fixed labels stay out of the check: a sensitive column named `values` names no annotation.
|
|
117
128
|
if (shown.length === 0 || !gate.allows(shown.join("; ")))
|
|
118
129
|
return "";
|
|
119
|
-
return [aliases && `aliases: ${aliases}`, values && `values: ${values}`, description]
|
|
130
|
+
return [aliases && `aliases: ${aliases}`, values && `values: ${values}`, description, note && `note: ${note}`]
|
|
131
|
+
.filter(Boolean)
|
|
132
|
+
.join("; ");
|
|
120
133
|
}
|
|
121
134
|
/**
|
|
122
135
|
* A table's name as the NL→SQL prompt lists it: `schema.name`, or `name` in the unqualified
|
|
@@ -126,6 +139,113 @@ export function promptTableName(table, unqualifiedNamespace, quoteIdentifier = l
|
|
|
126
139
|
const name = quoteIdentifier(table.name);
|
|
127
140
|
return table.schema === unqualifiedNamespace ? name : `${quoteIdentifier(table.schema)}.${name}`;
|
|
128
141
|
}
|
|
142
|
+
function columnRefs(schema) {
|
|
143
|
+
const refs = new Map();
|
|
144
|
+
for (const table of schema.tables)
|
|
145
|
+
for (const column of table.columns)
|
|
146
|
+
refs.set(column.id, { table, column });
|
|
147
|
+
return refs;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* The schema's foreign keys as both NL→SQL prompts print them (#898), keyed by the id of the
|
|
151
|
+
* table that owns each key's column: ` FK (user_id) -> public.users (id)`, after the table's
|
|
152
|
+
* column lines. Each key prints once, from any table's `relationships`. A key is left out when
|
|
153
|
+
* either column doesn't resolve, either table is untracked or not `shown`, or, with `omit`,
|
|
154
|
+
* either column or table is sensitive, so a key never names a column the prompt withholds. A
|
|
155
|
+
* composite key prints one line per column pair until the artifact groups them (#349).
|
|
156
|
+
*/
|
|
157
|
+
export function foreignKeyLinesByTable(schema, options) {
|
|
158
|
+
const refs = columnRefs(schema);
|
|
159
|
+
const { quoteIdentifier, unqualifiedNamespace } = options;
|
|
160
|
+
const visible = (ref) => ref !== undefined &&
|
|
161
|
+
ref.table.tracked !== false &&
|
|
162
|
+
(options.shown?.(ref.table.id) ?? true) &&
|
|
163
|
+
!(options.omit && (ref.table.sensitive || ref.column.sensitive));
|
|
164
|
+
const byTable = new Map();
|
|
165
|
+
const printed = new Set();
|
|
166
|
+
for (const table of schema.tables) {
|
|
167
|
+
for (const key of table.relationships ?? []) {
|
|
168
|
+
const from = refs.get(key.from);
|
|
169
|
+
const to = refs.get(key.to);
|
|
170
|
+
if (!visible(from) || !visible(to) || printed.has(`${key.from}->${key.to}`))
|
|
171
|
+
continue;
|
|
172
|
+
printed.add(`${key.from}->${key.to}`);
|
|
173
|
+
const target = promptTableName(to.table, unqualifiedNamespace, quoteIdentifier);
|
|
174
|
+
const line = ` FK (${quoteIdentifier(from.column.name)}) -> ${target} (${quoteIdentifier(to.column.name)})`;
|
|
175
|
+
byTable.set(from.table.id, [...(byTable.get(from.table.id) ?? []), line]);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return byTable;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Renders a concept as both NL→SQL prompts list it (#898): its label, synonyms, links (named as
|
|
182
|
+
* the prompt names tables and columns) and description, as one line. A link to an untracked
|
|
183
|
+
* table, or to a column of one, is dropped, and a concept whose links were all untracked
|
|
184
|
+
* renders as `undefined`; a link to a table or column the schema doesn't have is dropped too.
|
|
185
|
+
* `text` is the line without its fixed labels, for the gate (see {@link columnAnnotation});
|
|
186
|
+
* `linksSensitive` flags a concept that links a sensitive table or column.
|
|
187
|
+
*/
|
|
188
|
+
export function conceptRenderer(schema, naming) {
|
|
189
|
+
const refs = columnRefs(schema);
|
|
190
|
+
const tables = new Map(schema.tables.map((table) => [table.id, table]));
|
|
191
|
+
return (concept) => {
|
|
192
|
+
const links = [];
|
|
193
|
+
let untracked = 0;
|
|
194
|
+
let linksSensitive = false;
|
|
195
|
+
for (const id of concept.links ?? []) {
|
|
196
|
+
const hash = id.indexOf("#");
|
|
197
|
+
const column = refs.get(id);
|
|
198
|
+
const table = column?.table ?? tables.get(hash === -1 ? id : id.slice(0, hash));
|
|
199
|
+
if (table?.tracked === false) {
|
|
200
|
+
untracked++;
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (!table || (hash !== -1 && !column))
|
|
204
|
+
continue;
|
|
205
|
+
const tableName = promptTableName(table, naming.unqualifiedNamespace, naming.quoteIdentifier);
|
|
206
|
+
links.push(column ? `${tableName}.${naming.quoteIdentifier(column.column.name)}` : tableName);
|
|
207
|
+
linksSensitive ||= table.sensitive || (column?.column.sensitive ?? false);
|
|
208
|
+
}
|
|
209
|
+
if (untracked > 0 && links.length === 0)
|
|
210
|
+
return undefined;
|
|
211
|
+
const fields = [
|
|
212
|
+
[undefined, concept.label],
|
|
213
|
+
["synonyms", concept.synonyms?.join(", ") ?? ""],
|
|
214
|
+
["links", links.join(", ")],
|
|
215
|
+
[undefined, concept.description?.replace(/\s*\n\s*/g, " ") ?? ""],
|
|
216
|
+
];
|
|
217
|
+
const shown = fields.filter(([, value]) => value);
|
|
218
|
+
return {
|
|
219
|
+
body: shown.map(([label, value]) => (label ? `${label}: ${value}` : value)).join("; "),
|
|
220
|
+
text: shown.map(([, value]) => value).join("; "),
|
|
221
|
+
linksSensitive,
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* The schema's concepts as the full-schema prompt lists them after the tables (#898): a
|
|
227
|
+
* `-- concepts --` block, one {@link conceptRenderer} line per concept the gate allows (a
|
|
228
|
+
* concept that links a sensitive table or column is flagged, so omission withholds it too).
|
|
229
|
+
* `[]` when no concept is left.
|
|
230
|
+
*/
|
|
231
|
+
export function conceptLines(schema, gate, naming) {
|
|
232
|
+
const render = conceptRenderer(schema, naming);
|
|
233
|
+
const lines = [];
|
|
234
|
+
for (const concept of schema.concepts ?? []) {
|
|
235
|
+
const rendered = render(concept);
|
|
236
|
+
if (rendered && gate.allows(rendered.text, rendered.linksSensitive))
|
|
237
|
+
lines.push(`-- ${rendered.body}`);
|
|
238
|
+
}
|
|
239
|
+
return lines.length > 0 ? ["-- concepts --", ...lines, ""] : [];
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* A table's `-- business context --` block: each body's lines as `--` comments, blank lines
|
|
243
|
+
* dropped (paragraphs are separated by them; an empty `--` line adds nothing). `[]` for none.
|
|
244
|
+
*/
|
|
245
|
+
export function businessContextLines(bodies) {
|
|
246
|
+
const lines = bodies.flatMap((body) => body.split("\n").filter((line) => line.trim()).map((line) => `-- ${line}`));
|
|
247
|
+
return lines.length > 0 ? ["-- business context --", ...lines] : [];
|
|
248
|
+
}
|
|
129
249
|
/** The default `quoteIdentifier`: a name listed exactly as stored. */
|
|
130
250
|
export function listAsStored(name) {
|
|
131
251
|
return name;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../../src/schema/v2/format.ts"],"names":[],"mappings":"AAEA,OAAO,EA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