@askdb/core 0.5.0-beta.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/LICENSE +201 -0
- package/NOTICE +10 -0
- package/README.md +74 -0
- package/dist/ai/provider.d.ts +122 -0
- package/dist/ai/provider.d.ts.map +1 -0
- package/dist/ai/provider.js +224 -0
- package/dist/ai/provider.js.map +1 -0
- package/dist/ask.d.ts +81 -0
- package/dist/ask.d.ts.map +1 -0
- package/dist/ask.js +83 -0
- package/dist/ask.js.map +1 -0
- package/dist/enrichment/index.d.ts +4 -0
- package/dist/enrichment/index.d.ts.map +1 -0
- package/dist/enrichment/index.js +3 -0
- package/dist/enrichment/index.js.map +1 -0
- package/dist/enrichment/prompt.d.ts +4 -0
- package/dist/enrichment/prompt.d.ts.map +1 -0
- package/dist/enrichment/prompt.js +72 -0
- package/dist/enrichment/prompt.js.map +1 -0
- package/dist/enrichment/suggest.d.ts +23 -0
- package/dist/enrichment/suggest.d.ts.map +1 -0
- package/dist/enrichment/suggest.js +38 -0
- package/dist/enrichment/suggest.js.map +1 -0
- package/dist/enrichment/types.d.ts +44 -0
- package/dist/enrichment/types.d.ts.map +1 -0
- package/dist/enrichment/types.js +2 -0
- package/dist/enrichment/types.js.map +1 -0
- package/dist/errors.d.ts +21 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +33 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/logging/askdb-logger.d.ts +13 -0
- package/dist/logging/askdb-logger.d.ts.map +1 -0
- package/dist/logging/askdb-logger.js +2 -0
- package/dist/logging/askdb-logger.js.map +1 -0
- package/dist/logging/create-askdb-logger.d.ts +25 -0
- package/dist/logging/create-askdb-logger.d.ts.map +1 -0
- package/dist/logging/create-askdb-logger.js +47 -0
- package/dist/logging/create-askdb-logger.js.map +1 -0
- package/dist/logging/log-contract.d.ts +16 -0
- package/dist/logging/log-contract.d.ts.map +1 -0
- package/dist/logging/log-contract.js +23 -0
- package/dist/logging/log-contract.js.map +1 -0
- package/dist/logging/log-events.d.ts +32 -0
- package/dist/logging/log-events.d.ts.map +1 -0
- package/dist/logging/log-events.js +31 -0
- package/dist/logging/log-events.js.map +1 -0
- package/dist/logging/pino-supported-levels.d.ts +9 -0
- package/dist/logging/pino-supported-levels.d.ts.map +1 -0
- package/dist/logging/pino-supported-levels.js +16 -0
- package/dist/logging/pino-supported-levels.js.map +1 -0
- package/dist/modes/types.d.ts +8 -0
- package/dist/modes/types.d.ts.map +1 -0
- package/dist/modes/types.js +20 -0
- package/dist/modes/types.js.map +1 -0
- package/dist/retrieval/synthesize-ddl.d.ts +29 -0
- package/dist/retrieval/synthesize-ddl.d.ts.map +1 -0
- package/dist/retrieval/synthesize-ddl.js +160 -0
- package/dist/retrieval/synthesize-ddl.js.map +1 -0
- package/dist/retrieval/types.d.ts +31 -0
- package/dist/retrieval/types.d.ts.map +1 -0
- package/dist/retrieval/types.js +2 -0
- package/dist/retrieval/types.js.map +1 -0
- package/dist/schema/format.d.ts +76 -0
- package/dist/schema/format.d.ts.map +1 -0
- package/dist/schema/format.js +20 -0
- package/dist/schema/format.js.map +1 -0
- package/dist/schema/normalize.d.ts +31 -0
- package/dist/schema/normalize.d.ts.map +1 -0
- package/dist/schema/normalize.js +89 -0
- package/dist/schema/normalize.js.map +1 -0
- package/dist/schema/parse.d.ts +5 -0
- package/dist/schema/parse.d.ts.map +1 -0
- package/dist/schema/parse.js +37 -0
- package/dist/schema/parse.js.map +1 -0
- package/dist/schema/types.d.ts +23 -0
- package/dist/schema/types.d.ts.map +1 -0
- package/dist/schema/types.js +2 -0
- package/dist/schema/types.js.map +1 -0
- package/dist/schema/v2/describable.d.ts +155 -0
- package/dist/schema/v2/describable.d.ts.map +1 -0
- package/dist/schema/v2/describable.js +44 -0
- package/dist/schema/v2/describable.js.map +1 -0
- package/dist/schema/v2/format.d.ts +15 -0
- package/dist/schema/v2/format.d.ts.map +1 -0
- package/dist/schema/v2/format.js +97 -0
- package/dist/schema/v2/format.js.map +1 -0
- package/dist/schema/v2/index.d.ts +10 -0
- package/dist/schema/v2/index.d.ts.map +1 -0
- package/dist/schema/v2/index.js +7 -0
- package/dist/schema/v2/index.js.map +1 -0
- package/dist/schema/v2/loader.d.ts +18 -0
- package/dist/schema/v2/loader.d.ts.map +1 -0
- package/dist/schema/v2/loader.js +230 -0
- package/dist/schema/v2/loader.js.map +1 -0
- package/dist/schema/v2/normalized.d.ts +58 -0
- package/dist/schema/v2/normalized.d.ts.map +1 -0
- package/dist/schema/v2/normalized.js +2 -0
- package/dist/schema/v2/normalized.js.map +1 -0
- package/dist/schema/v2/parser.d.ts +12 -0
- package/dist/schema/v2/parser.d.ts.map +1 -0
- package/dist/schema/v2/parser.js +48 -0
- package/dist/schema/v2/parser.js.map +1 -0
- package/dist/schema/v2/physical.d.ts +229 -0
- package/dist/schema/v2/physical.d.ts.map +1 -0
- package/dist/schema/v2/physical.js +28 -0
- package/dist/schema/v2/physical.js.map +1 -0
- package/dist/schema/v2/writer.d.ts +14 -0
- package/dist/schema/v2/writer.d.ts.map +1 -0
- package/dist/schema/v2/writer.js +49 -0
- package/dist/schema/v2/writer.js.map +1 -0
- package/dist/sql/extract-sql.d.ts +5 -0
- package/dist/sql/extract-sql.d.ts.map +1 -0
- package/dist/sql/extract-sql.js +12 -0
- package/dist/sql/extract-sql.js.map +1 -0
- package/package.json +60 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { mkdirSync } from "node:fs";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
import pino from "pino";
|
|
4
|
+
function wrapPinoAsAskDbLogger(pinoLogger) {
|
|
5
|
+
return {
|
|
6
|
+
info(context, message) {
|
|
7
|
+
pinoLogger.info(context, message);
|
|
8
|
+
},
|
|
9
|
+
error(context, message) {
|
|
10
|
+
pinoLogger.error(context, message);
|
|
11
|
+
},
|
|
12
|
+
debug(context, message) {
|
|
13
|
+
pinoLogger.debug(context, message);
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Builds an {@link AskDbLogger} backed by Pino (multi-destination per ADR 0001).
|
|
19
|
+
* Uses a single `destination` when only one sink is configured (simpler flushing); otherwise `pino.multistream`.
|
|
20
|
+
*/
|
|
21
|
+
export function createAskDbLogger(options) {
|
|
22
|
+
const level = options.level ?? "silent";
|
|
23
|
+
if (level === "silent") {
|
|
24
|
+
return wrapPinoAsAskDbLogger(pino({ level: "silent" }));
|
|
25
|
+
}
|
|
26
|
+
const stderrOn = options.stderr !== false;
|
|
27
|
+
const destinations = [];
|
|
28
|
+
if (stderrOn) {
|
|
29
|
+
destinations.push(pino.destination(2));
|
|
30
|
+
}
|
|
31
|
+
if (options.logStdout) {
|
|
32
|
+
destinations.push(pino.destination(1));
|
|
33
|
+
}
|
|
34
|
+
if (options.logFile) {
|
|
35
|
+
mkdirSync(dirname(options.logFile), { recursive: true });
|
|
36
|
+
destinations.push(pino.destination({ dest: options.logFile, sync: true }));
|
|
37
|
+
}
|
|
38
|
+
if (destinations.length === 0) {
|
|
39
|
+
return wrapPinoAsAskDbLogger(pino({ level: "silent" }));
|
|
40
|
+
}
|
|
41
|
+
const dest = destinations.length === 1
|
|
42
|
+
? destinations[0]
|
|
43
|
+
: pino.multistream(destinations.map((stream) => ({ stream })));
|
|
44
|
+
const pinoLogger = pino({ level }, dest).child({ correlationId: options.correlationId });
|
|
45
|
+
return wrapPinoAsAskDbLogger(pinoLogger);
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=create-askdb-logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-askdb-logger.js","sourceRoot":"","sources":["../../src/logging/create-askdb-logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,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IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAC7E,CAAC;IAED,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC9B,OAAO,qBAAqB,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;IAC1D,CAAC;IAED,MAAM,IAAI,GACR,YAAY,CAAC,MAAM,KAAK,CAAC;QACvB,CAAC,CAAC,YAAY,CAAC,CAAC,CAAE;QAClB,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;IAEnE,MAAM,UAAU,GAAG,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,IAAI,CAAC,CAAC,KAAK,CAAC,EAAE,aAAa,EAAE,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;IACzF,OAAO,qBAAqB,CAAC,UAAU,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal structured-log contract intended for headless surfaces (CLI now; reused by servers later).
|
|
3
|
+
*
|
|
4
|
+
* This is deliberately small:
|
|
5
|
+
* - Tests should fail on removal/rename of required fields/events (drift).
|
|
6
|
+
* - Tests should tolerate additive fields/events.
|
|
7
|
+
*/
|
|
8
|
+
export declare const ASKDB_LOG_REQUIRED_FIELDS: readonly ["event", "correlationId"];
|
|
9
|
+
/**
|
|
10
|
+
* Minimal event taxonomy for an end-to-end run.
|
|
11
|
+
*
|
|
12
|
+
* These are the best “merge bar” anchors for CI spawn tests because they appear
|
|
13
|
+
* across common paths without depending on optional execution.
|
|
14
|
+
*/
|
|
15
|
+
export declare const ASKDB_LOG_REQUIRED_EVENTS: readonly ["askdb.run.start", "askdb.pipeline.mode", "askdb.pipeline.generate.start", "askdb.pipeline.generate.complete", "askdb.run.end"];
|
|
16
|
+
//# sourceMappingURL=log-contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-contract.d.ts","sourceRoot":"","sources":["../../src/logging/log-contract.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,qCAAsC,CAAC;AAE7E;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,2IAMW,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AskDbLogEvent } from "./log-events.js";
|
|
2
|
+
/**
|
|
3
|
+
* Minimal structured-log contract intended for headless surfaces (CLI now; reused by servers later).
|
|
4
|
+
*
|
|
5
|
+
* This is deliberately small:
|
|
6
|
+
* - Tests should fail on removal/rename of required fields/events (drift).
|
|
7
|
+
* - Tests should tolerate additive fields/events.
|
|
8
|
+
*/
|
|
9
|
+
export const ASKDB_LOG_REQUIRED_FIELDS = ["event", "correlationId"];
|
|
10
|
+
/**
|
|
11
|
+
* Minimal event taxonomy for an end-to-end run.
|
|
12
|
+
*
|
|
13
|
+
* These are the best “merge bar” anchors for CI spawn tests because they appear
|
|
14
|
+
* across common paths without depending on optional execution.
|
|
15
|
+
*/
|
|
16
|
+
export const ASKDB_LOG_REQUIRED_EVENTS = [
|
|
17
|
+
AskDbLogEvent.RunStart,
|
|
18
|
+
AskDbLogEvent.PipelineMode,
|
|
19
|
+
AskDbLogEvent.PipelineGenerateStart,
|
|
20
|
+
AskDbLogEvent.PipelineGenerateComplete,
|
|
21
|
+
AskDbLogEvent.RunEnd,
|
|
22
|
+
];
|
|
23
|
+
//# sourceMappingURL=log-contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-contract.js","sourceRoot":"","sources":["../../src/logging/log-contract.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,OAAO,EAAE,eAAe,CAAU,CAAC;AAE7E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACvC,aAAa,CAAC,QAAQ;IACtB,aAAa,CAAC,YAAY;IAC1B,aAAa,CAAC,qBAAqB;IACnC,aAAa,CAAC,wBAAwB;IACtC,aAAa,CAAC,MAAM;CAC2B,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stable `event` field values for structured logs (JSON lines).
|
|
3
|
+
* See Phase 2 spec: observability / correlation ID contract.
|
|
4
|
+
*/
|
|
5
|
+
export declare const AskDbLogEvent: {
|
|
6
|
+
readonly RunStart: "askdb.run.start";
|
|
7
|
+
readonly RunEnd: "askdb.run.end";
|
|
8
|
+
readonly RunError: "askdb.run.error";
|
|
9
|
+
/** Operating mode for this pipeline run (`mode` field). Emitted before NL→SQL. */
|
|
10
|
+
readonly PipelineMode: "askdb.pipeline.mode";
|
|
11
|
+
readonly PipelineGenerateStart: "askdb.pipeline.generate.start";
|
|
12
|
+
readonly PipelineGenerateComplete: "askdb.pipeline.generate.complete";
|
|
13
|
+
/** NL→SQL prompt DDL omitted sensitive tables/columns — counts only (no identifiers). */
|
|
14
|
+
readonly PromptSensitiveRedacted: "askdb.prompt.sensitive_redacted";
|
|
15
|
+
/** Sensitive identifiers included in DDL for grounding — counts only (see `listedSensitiveColumnCount`). */
|
|
16
|
+
readonly PromptSensitiveIdentifiersListed: "askdb.prompt.sensitive_identifiers_listed";
|
|
17
|
+
/** Generation failed after pipeline logging began (includes `phase`). */
|
|
18
|
+
readonly PipelineFailed: "askdb.pipeline.failed";
|
|
19
|
+
/**
|
|
20
|
+
* Retriever was supplied to `ask()` and used to synthesize a focused DDL
|
|
21
|
+
* block (counts only — `tablesEmitted`, `resultCount`, `k`, `threshold`).
|
|
22
|
+
*/
|
|
23
|
+
readonly PipelineRetrievalUsed: "askdb.pipeline.retrieval.used";
|
|
24
|
+
/**
|
|
25
|
+
* Retriever was supplied but **not** used (`reason`: `below_threshold` |
|
|
26
|
+
* `schema_not_v2` | `no_results`). Lets operators tell "supplied but
|
|
27
|
+
* skipped" apart from "never wired up".
|
|
28
|
+
*/
|
|
29
|
+
readonly PipelineRetrievalSkipped: "askdb.pipeline.retrieval.skipped";
|
|
30
|
+
};
|
|
31
|
+
export type AskDbLogEventName = (typeof AskDbLogEvent)[keyof typeof AskDbLogEvent];
|
|
32
|
+
//# sourceMappingURL=log-events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-events.d.ts","sourceRoot":"","sources":["../../src/logging/log-events.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,aAAa;;;;IAIxB,kFAAkF;;;;IAIlF,yFAAyF;;IAEzF,4GAA4G;;IAE5G,yEAAyE;;IAEzE;;;OAGG;;IAEH;;;;OAIG;;CAEK,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,OAAO,aAAa,CAAC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stable `event` field values for structured logs (JSON lines).
|
|
3
|
+
* See Phase 2 spec: observability / correlation ID contract.
|
|
4
|
+
*/
|
|
5
|
+
export const AskDbLogEvent = {
|
|
6
|
+
RunStart: "askdb.run.start",
|
|
7
|
+
RunEnd: "askdb.run.end",
|
|
8
|
+
RunError: "askdb.run.error",
|
|
9
|
+
/** Operating mode for this pipeline run (`mode` field). Emitted before NL→SQL. */
|
|
10
|
+
PipelineMode: "askdb.pipeline.mode",
|
|
11
|
+
PipelineGenerateStart: "askdb.pipeline.generate.start",
|
|
12
|
+
PipelineGenerateComplete: "askdb.pipeline.generate.complete",
|
|
13
|
+
/** NL→SQL prompt DDL omitted sensitive tables/columns — counts only (no identifiers). */
|
|
14
|
+
PromptSensitiveRedacted: "askdb.prompt.sensitive_redacted",
|
|
15
|
+
/** Sensitive identifiers included in DDL for grounding — counts only (see `listedSensitiveColumnCount`). */
|
|
16
|
+
PromptSensitiveIdentifiersListed: "askdb.prompt.sensitive_identifiers_listed",
|
|
17
|
+
/** Generation failed after pipeline logging began (includes `phase`). */
|
|
18
|
+
PipelineFailed: "askdb.pipeline.failed",
|
|
19
|
+
/**
|
|
20
|
+
* Retriever was supplied to `ask()` and used to synthesize a focused DDL
|
|
21
|
+
* block (counts only — `tablesEmitted`, `resultCount`, `k`, `threshold`).
|
|
22
|
+
*/
|
|
23
|
+
PipelineRetrievalUsed: "askdb.pipeline.retrieval.used",
|
|
24
|
+
/**
|
|
25
|
+
* Retriever was supplied but **not** used (`reason`: `below_threshold` |
|
|
26
|
+
* `schema_not_v2` | `no_results`). Lets operators tell "supplied but
|
|
27
|
+
* skipped" apart from "never wired up".
|
|
28
|
+
*/
|
|
29
|
+
PipelineRetrievalSkipped: "askdb.pipeline.retrieval.skipped",
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=log-events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-events.js","sourceRoot":"","sources":["../../src/logging/log-events.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,QAAQ,EAAE,iBAAiB;IAC3B,MAAM,EAAE,eAAe;IACvB,QAAQ,EAAE,iBAAiB;IAC3B,kFAAkF;IAClF,YAAY,EAAE,qBAAqB;IACnC,qBAAqB,EAAE,+BAA+B;IACtD,wBAAwB,EAAE,kCAAkC;IAC5D,yFAAyF;IACzF,uBAAuB,EAAE,iCAAiC;IAC1D,4GAA4G;IAC5G,gCAAgC,EAAE,2CAA2C;IAC7E,yEAAyE;IACzE,cAAc,EAAE,uBAAuB;IACvC;;;OAGG;IACH,qBAAqB,EAAE,+BAA+B;IACtD;;;;OAIG;IACH,wBAAwB,EAAE,kCAAkC;CACpD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AskDbLogLevel } from "./create-askdb-logger.js";
|
|
2
|
+
/**
|
|
3
|
+
* Valid `--log-level` / `ASKDB_LOG_LEVEL` strings: Pino's default levels from
|
|
4
|
+
* `pino.levels.values` plus `silent` (accepted by `LoggerOptions.level` but not a numeric level).
|
|
5
|
+
*/
|
|
6
|
+
export declare const SUPPORTED_ASKDB_LOG_LEVELS: ReadonlySet<string>;
|
|
7
|
+
export declare function formatSupportedAskDbLogLevels(): string;
|
|
8
|
+
export declare function isSupportedAskDbLogLevel(s: string): s is AskDbLogLevel;
|
|
9
|
+
//# sourceMappingURL=pino-supported-levels.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pino-supported-levels.d.ts","sourceRoot":"","sources":["../../src/logging/pino-supported-levels.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAE9D;;;GAGG;AACH,eAAO,MAAM,0BAA0B,EAAE,WAAW,CAAC,MAAM,CAGzD,CAAC;AAEH,wBAAgB,6BAA6B,IAAI,MAAM,CAEtD;AAED,wBAAgB,wBAAwB,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,IAAI,aAAa,CAEtE"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import pino from "pino";
|
|
2
|
+
/**
|
|
3
|
+
* Valid `--log-level` / `ASKDB_LOG_LEVEL` strings: Pino's default levels from
|
|
4
|
+
* `pino.levels.values` plus `silent` (accepted by `LoggerOptions.level` but not a numeric level).
|
|
5
|
+
*/
|
|
6
|
+
export const SUPPORTED_ASKDB_LOG_LEVELS = new Set([
|
|
7
|
+
...Object.keys(pino.levels.values),
|
|
8
|
+
"silent",
|
|
9
|
+
]);
|
|
10
|
+
export function formatSupportedAskDbLogLevels() {
|
|
11
|
+
return [...SUPPORTED_ASKDB_LOG_LEVELS].sort().join(", ");
|
|
12
|
+
}
|
|
13
|
+
export function isSupportedAskDbLogLevel(s) {
|
|
14
|
+
return SUPPORTED_ASKDB_LOG_LEVELS.has(s);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=pino-supported-levels.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pino-supported-levels.js","sourceRoot":"","sources":["../../src/logging/pino-supported-levels.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAwB,IAAI,GAAG,CAAS;IAC7E,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IAClC,QAAQ;CACT,CAAC,CAAC;AAEH,MAAM,UAAU,6BAA6B;IAC3C,OAAO,CAAC,GAAG,0BAA0B,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC3D,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,CAAS;IAChD,OAAO,0BAA0B,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Operating modes selectable in Phase 2 v1 (see `docs/contracts/modes-v1.md`). */
|
|
2
|
+
export declare const ASKDB_MODES_V1: readonly ["schema_only", "bounded_results"];
|
|
3
|
+
export type AskDbModeV1 = (typeof ASKDB_MODES_V1)[number];
|
|
4
|
+
/** Default mode when unset — strictest trust boundary. */
|
|
5
|
+
export declare const DEFAULT_ASKDB_MODE: AskDbModeV1;
|
|
6
|
+
export declare function parseAskDbModeV1(raw: string | undefined): AskDbModeV1;
|
|
7
|
+
export declare function formatAskDbModesV1(): string;
|
|
8
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/modes/types.ts"],"names":[],"mappings":"AAEA,mFAAmF;AACnF,eAAO,MAAM,cAAc,6CAA8C,CAAC;AAC1E,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAI1D,0DAA0D;AAC1D,eAAO,MAAM,kBAAkB,EAAE,WAA2B,CAAC;AAE7D,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,WAAW,CAWrE;AAED,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AskDbError } from "../errors.js";
|
|
2
|
+
/** Operating modes selectable in Phase 2 v1 (see `docs/contracts/modes-v1.md`). */
|
|
3
|
+
export const ASKDB_MODES_V1 = ["schema_only", "bounded_results"];
|
|
4
|
+
const MODE_SET = new Set(ASKDB_MODES_V1);
|
|
5
|
+
/** Default mode when unset — strictest trust boundary. */
|
|
6
|
+
export const DEFAULT_ASKDB_MODE = "schema_only";
|
|
7
|
+
export function parseAskDbModeV1(raw) {
|
|
8
|
+
if (raw === undefined || raw === "") {
|
|
9
|
+
return DEFAULT_ASKDB_MODE;
|
|
10
|
+
}
|
|
11
|
+
const n = raw.trim().toLowerCase().replace(/-/g, "_");
|
|
12
|
+
if (!MODE_SET.has(n)) {
|
|
13
|
+
throw new AskDbError(`Invalid mode: ${JSON.stringify(raw)}. Expected one of: ${ASKDB_MODES_V1.join(", ")}.`);
|
|
14
|
+
}
|
|
15
|
+
return n;
|
|
16
|
+
}
|
|
17
|
+
export function formatAskDbModesV1() {
|
|
18
|
+
return ASKDB_MODES_V1.join("|");
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/modes/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,mFAAmF;AACnF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,aAAa,EAAE,iBAAiB,CAAU,CAAC;AAG1E,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAS,cAAc,CAAC,CAAC;AAEjD,0DAA0D;AAC1D,MAAM,CAAC,MAAM,kBAAkB,GAAgB,aAAa,CAAC;AAE7D,MAAM,UAAU,gBAAgB,CAAC,GAAuB;IACtD,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,EAAE,EAAE,CAAC;QACpC,OAAO,kBAAkB,CAAC;IAC5B,CAAC;IACD,MAAM,CAAC,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACtD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACrB,MAAM,IAAI,UAAU,CAClB,iBAAiB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,sBAAsB,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CACvF,CAAC;IACJ,CAAC;IACD,OAAO,CAAgB,CAAC;AAC1B,CAAC;AAED,MAAM,UAAU,kBAAkB;IAChC,OAAO,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { NormalizedSchemaV2 } from "../schema/v2/normalized.js";
|
|
2
|
+
import type { RetrievedResult } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Build a focused DDL block for NL→SQL prompts from retrieved chunks.
|
|
5
|
+
*
|
|
6
|
+
* Layout (decided in implementation, per Phase 8 spec's "open choice"):
|
|
7
|
+
* 1. Each table referenced by any retrieved chunk gets a TABLE block with
|
|
8
|
+
* its full column definitions (so the model has complete column lists).
|
|
9
|
+
* 2. Column-chunk descriptions become inline `-- aliases / values / desc`
|
|
10
|
+
* annotations on the matching column line.
|
|
11
|
+
* 3. CQL chunks land as a `-- common query language --` block under the
|
|
12
|
+
* table.
|
|
13
|
+
* 4. Concept and question chunks attach as system-context paragraphs at
|
|
14
|
+
* the bottom (before the question).
|
|
15
|
+
*
|
|
16
|
+
* Sensitive identifiers retain their `(sensitive)` tagging exactly as
|
|
17
|
+
* `formatSchemaV2ForNlToSql` does.
|
|
18
|
+
*/
|
|
19
|
+
export declare function synthesizeRetrievedDdl(args: {
|
|
20
|
+
schema: NormalizedSchemaV2;
|
|
21
|
+
results: RetrievedResult[];
|
|
22
|
+
/** Mirrors `formatSchemaV2ForNlToSql`'s `omitSensitiveIdentifiersFromPrompt`. */
|
|
23
|
+
omitSensitiveIdentifiersFromPrompt?: boolean;
|
|
24
|
+
}): {
|
|
25
|
+
ddl: string;
|
|
26
|
+
tablesEmitted: number;
|
|
27
|
+
chunksUsed: number;
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=synthesize-ddl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"synthesize-ddl.d.ts","sourceRoot":"","sources":["../../src/retrieval/synthesize-ddl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD;;;;;;;;;;;;;;;GAeG;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;CAC9C,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAuI7D"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build a focused DDL block for NL→SQL prompts from retrieved chunks.
|
|
3
|
+
*
|
|
4
|
+
* Layout (decided in implementation, per Phase 8 spec's "open choice"):
|
|
5
|
+
* 1. Each table referenced by any retrieved chunk gets a TABLE block with
|
|
6
|
+
* its full column definitions (so the model has complete column lists).
|
|
7
|
+
* 2. Column-chunk descriptions become inline `-- aliases / values / desc`
|
|
8
|
+
* annotations on the matching column line.
|
|
9
|
+
* 3. CQL chunks land as a `-- common query language --` block under the
|
|
10
|
+
* table.
|
|
11
|
+
* 4. Concept and question chunks attach as system-context paragraphs at
|
|
12
|
+
* the bottom (before the question).
|
|
13
|
+
*
|
|
14
|
+
* Sensitive identifiers retain their `(sensitive)` tagging exactly as
|
|
15
|
+
* `formatSchemaV2ForNlToSql` does.
|
|
16
|
+
*/
|
|
17
|
+
export function synthesizeRetrievedDdl(args) {
|
|
18
|
+
const { schema, results } = args;
|
|
19
|
+
const omit = args.omitSensitiveIdentifiersFromPrompt === true;
|
|
20
|
+
const tableIds = new Set();
|
|
21
|
+
const cqlPerTable = new Map();
|
|
22
|
+
const concepts = [];
|
|
23
|
+
const questions = [];
|
|
24
|
+
const relationships = [];
|
|
25
|
+
for (const r of results) {
|
|
26
|
+
const p = r.payload;
|
|
27
|
+
switch (p.type) {
|
|
28
|
+
case "table": {
|
|
29
|
+
const tid = p.refs[0];
|
|
30
|
+
if (tid)
|
|
31
|
+
tableIds.add(tid);
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
case "column": {
|
|
35
|
+
const tid = p.refs[0];
|
|
36
|
+
if (tid)
|
|
37
|
+
tableIds.add(tid);
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
case "cql": {
|
|
41
|
+
const tid = p.refs[0];
|
|
42
|
+
if (tid) {
|
|
43
|
+
tableIds.add(tid);
|
|
44
|
+
const list = cqlPerTable.get(tid) ?? [];
|
|
45
|
+
list.push(p);
|
|
46
|
+
cqlPerTable.set(tid, list);
|
|
47
|
+
}
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
case "question": {
|
|
51
|
+
questions.push(p);
|
|
52
|
+
if (p.refs[0])
|
|
53
|
+
tableIds.add(p.refs[0]);
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
case "concept": {
|
|
57
|
+
concepts.push(p);
|
|
58
|
+
for (const ref of p.refs) {
|
|
59
|
+
if (ref.startsWith("table:")) {
|
|
60
|
+
const hash = ref.indexOf("#");
|
|
61
|
+
tableIds.add(hash === -1 ? ref : ref.slice(0, hash));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
case "relationship": {
|
|
67
|
+
relationships.push(p);
|
|
68
|
+
for (const ref of p.refs) {
|
|
69
|
+
if (ref.startsWith("table:") && !ref.includes("#"))
|
|
70
|
+
tableIds.add(ref);
|
|
71
|
+
}
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const lines = [];
|
|
77
|
+
let tablesEmitted = 0;
|
|
78
|
+
for (const t of schema.tables) {
|
|
79
|
+
if (!tableIds.has(t.id))
|
|
80
|
+
continue;
|
|
81
|
+
tablesEmitted++;
|
|
82
|
+
const qualifiedName = `${t.schema}.${t.name}`;
|
|
83
|
+
const aliasNote = !t.sensitive && t.aliases?.length ? ` -- aliases: ${t.aliases.join(", ")}` : "";
|
|
84
|
+
lines.push(`TABLE ${qualifiedName}${aliasNote}`);
|
|
85
|
+
if (!t.sensitive && t.description)
|
|
86
|
+
lines.push(`-- ${t.description}`);
|
|
87
|
+
if (omit && t.sensitive) {
|
|
88
|
+
lines.push(` (sensitive table — column definitions withheld from model context)`);
|
|
89
|
+
lines.push("");
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
for (const c of t.columns) {
|
|
93
|
+
if (omit && c.sensitive)
|
|
94
|
+
continue;
|
|
95
|
+
const flags = [];
|
|
96
|
+
if (c.primaryKey)
|
|
97
|
+
flags.push("PK");
|
|
98
|
+
flags.push(c.nullable ? "NULL" : "NOT NULL");
|
|
99
|
+
const sensitiveTag = c.sensitive || t.sensitive ? " (sensitive)" : "";
|
|
100
|
+
let line = ` - ${c.name} ${c.type} (${flags.join(" ")})${sensitiveTag}`;
|
|
101
|
+
if (!c.sensitive && !t.sensitive) {
|
|
102
|
+
const extras = [];
|
|
103
|
+
if (c.aliases?.length)
|
|
104
|
+
extras.push(`aliases: ${c.aliases.join(", ")}`);
|
|
105
|
+
if (c.enum?.length)
|
|
106
|
+
extras.push(`values: ${c.enum.join("|")}`);
|
|
107
|
+
if (c.description)
|
|
108
|
+
extras.push(c.description);
|
|
109
|
+
if (extras.length)
|
|
110
|
+
line += ` -- ${extras.join("; ")}`;
|
|
111
|
+
}
|
|
112
|
+
lines.push(line);
|
|
113
|
+
}
|
|
114
|
+
const cqlList = cqlPerTable.get(t.id);
|
|
115
|
+
if (cqlList && cqlList.length > 0 && !t.sensitive) {
|
|
116
|
+
lines.push(`-- common query language --`);
|
|
117
|
+
for (const cql of cqlList) {
|
|
118
|
+
const body = stripHeaderLine(cql.text);
|
|
119
|
+
for (const cqlLine of body.split("\n")) {
|
|
120
|
+
lines.push(`-- ${cqlLine}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
lines.push("");
|
|
125
|
+
}
|
|
126
|
+
if (relationships.length > 0) {
|
|
127
|
+
lines.push("-- relationships --");
|
|
128
|
+
for (const r of relationships) {
|
|
129
|
+
lines.push(`-- ${stripHeaderLine(r.text).replace(/\n+/g, " ")}`);
|
|
130
|
+
}
|
|
131
|
+
lines.push("");
|
|
132
|
+
}
|
|
133
|
+
if (concepts.length > 0) {
|
|
134
|
+
lines.push("-- concepts --");
|
|
135
|
+
for (const c of concepts) {
|
|
136
|
+
lines.push(`-- ${stripHeaderLine(c.text).replace(/\n+/g, "; ")}`);
|
|
137
|
+
}
|
|
138
|
+
lines.push("");
|
|
139
|
+
}
|
|
140
|
+
if (questions.length > 0) {
|
|
141
|
+
lines.push("-- example questions for context --");
|
|
142
|
+
for (const q of questions) {
|
|
143
|
+
lines.push(`-- ${stripHeaderLine(q.text).replace(/\n+/g, " ")}`);
|
|
144
|
+
}
|
|
145
|
+
lines.push("");
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
ddl: lines.join("\n").trimEnd(),
|
|
149
|
+
tablesEmitted,
|
|
150
|
+
chunksUsed: results.length,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function stripHeaderLine(text) {
|
|
154
|
+
if (text.startsWith("#")) {
|
|
155
|
+
const nl = text.indexOf("\n");
|
|
156
|
+
return nl === -1 ? "" : text.slice(nl + 1).trim();
|
|
157
|
+
}
|
|
158
|
+
return text.trim();
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=synthesize-ddl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"synthesize-ddl.js","sourceRoot":"","sources":["../../src/retrieval/synthesize-ddl.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,sBAAsB,CAAC,IAKtC;IACC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACjC,MAAM,IAAI,GAAG,IAAI,CAAC,kCAAkC,KAAK,IAAI,CAAC;IAE9D,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAU,CAAC;IACnC,MAAM,WAAW,GAAG,IAAI,GAAG,EAAwC,CAAC;IACpE,MAAM,QAAQ,GAAiC,EAAE,CAAC;IAClD,MAAM,SAAS,GAAiC,EAAE,CAAC;IACnD,MAAM,aAAa,GAAiC,EAAE,CAAC;IAEvD,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;QACxB,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC;QACpB,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC;YACf,KAAK,OAAO,CAAC,CAAC,CAAC;gBACb,MAAM,GAAG,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;gBACtB,IAAI,GAAG;oBAAE,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+
* Minimal chunk-shaped payload that `@askdb/core` understands. The full
|
|
3
|
+
* `ChunkPayload` from `@askdb/rag` is assignable to this — splitting the
|
|
4
|
+
* shape this way avoids `@askdb/core` taking a hard dependency on
|
|
5
|
+
* `@askdb/rag` while keeping the retrieval seam in `ask()`.
|
|
6
|
+
*/
|
|
7
|
+
export type RetrievedChunkType = "table" | "column" | "cql" | "question" | "concept" | "relationship";
|
|
8
|
+
export type RetrievedChunk = {
|
|
9
|
+
id: string;
|
|
10
|
+
type: RetrievedChunkType;
|
|
11
|
+
text: string;
|
|
12
|
+
schemaId: string;
|
|
13
|
+
refs: string[];
|
|
14
|
+
sensitive: boolean;
|
|
15
|
+
};
|
|
16
|
+
export type RetrievedResult = {
|
|
17
|
+
id: string;
|
|
18
|
+
score: number;
|
|
19
|
+
payload: RetrievedChunk;
|
|
20
|
+
};
|
|
21
|
+
/** Shape consumed by `ask({ retriever })`. */
|
|
22
|
+
export type Retriever = (params: {
|
|
23
|
+
question: string;
|
|
24
|
+
k?: number;
|
|
25
|
+
filter?: {
|
|
26
|
+
schemaId?: string;
|
|
27
|
+
types?: RetrievedChunkType[];
|
|
28
|
+
refs?: string[];
|
|
29
|
+
};
|
|
30
|
+
}) => Promise<RetrievedResult[]>;
|
|
31
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/retrieval/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,kBAAkB,GAC1B,OAAO,GACP,QAAQ,GACR,KAAK,GACL,UAAU,GACV,SAAS,GACT,cAAc,CAAC;AAEnB,MAAM,MAAM,cAAc,GAAG;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,kBAAkB,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,cAAc,CAAC;CACzB,CAAC;AAEF,8CAA8C;AAC9C,MAAM,MAAM,SAAS,GAAG,CAAC,MAAM,EAAE;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,MAAM,CAAC,EAAE;QACP,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,KAAK,CAAC,EAAE,kBAAkB,EAAE,CAAC;QAC7B,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;KACjB,CAAC;CACH,KAAK,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/retrieval/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const askDbSchemaFileSchema: z.ZodObject<{
|
|
3
|
+
version: z.ZodLiteral<1>;
|
|
4
|
+
tables: z.ZodArray<z.ZodObject<{
|
|
5
|
+
name: z.ZodString;
|
|
6
|
+
columns: z.ZodArray<z.ZodObject<{
|
|
7
|
+
name: z.ZodString;
|
|
8
|
+
type: z.ZodString;
|
|
9
|
+
nullable: z.ZodOptional<z.ZodBoolean>;
|
|
10
|
+
primaryKey: z.ZodOptional<z.ZodBoolean>;
|
|
11
|
+
/** When true, column metadata is omitted from NL→SQL prompts (Phase 2 sensitive-field plumbing). */
|
|
12
|
+
sensitive: z.ZodOptional<z.ZodBoolean>;
|
|
13
|
+
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
name: string;
|
|
15
|
+
type: string;
|
|
16
|
+
nullable?: boolean | undefined;
|
|
17
|
+
primaryKey?: boolean | undefined;
|
|
18
|
+
sensitive?: boolean | undefined;
|
|
19
|
+
}, {
|
|
20
|
+
name: string;
|
|
21
|
+
type: string;
|
|
22
|
+
nullable?: boolean | undefined;
|
|
23
|
+
primaryKey?: boolean | undefined;
|
|
24
|
+
sensitive?: boolean | undefined;
|
|
25
|
+
}>, "many">;
|
|
26
|
+
/** When true, all column definitions for this table are withheld from NL→SQL prompts. */
|
|
27
|
+
sensitive: z.ZodOptional<z.ZodBoolean>;
|
|
28
|
+
}, "strip", z.ZodTypeAny, {
|
|
29
|
+
name: string;
|
|
30
|
+
columns: {
|
|
31
|
+
name: string;
|
|
32
|
+
type: string;
|
|
33
|
+
nullable?: boolean | undefined;
|
|
34
|
+
primaryKey?: boolean | undefined;
|
|
35
|
+
sensitive?: boolean | undefined;
|
|
36
|
+
}[];
|
|
37
|
+
sensitive?: boolean | undefined;
|
|
38
|
+
}, {
|
|
39
|
+
name: string;
|
|
40
|
+
columns: {
|
|
41
|
+
name: string;
|
|
42
|
+
type: string;
|
|
43
|
+
nullable?: boolean | undefined;
|
|
44
|
+
primaryKey?: boolean | undefined;
|
|
45
|
+
sensitive?: boolean | undefined;
|
|
46
|
+
}[];
|
|
47
|
+
sensitive?: boolean | undefined;
|
|
48
|
+
}>, "many">;
|
|
49
|
+
}, "strip", z.ZodTypeAny, {
|
|
50
|
+
version: 1;
|
|
51
|
+
tables: {
|
|
52
|
+
name: string;
|
|
53
|
+
columns: {
|
|
54
|
+
name: string;
|
|
55
|
+
type: string;
|
|
56
|
+
nullable?: boolean | undefined;
|
|
57
|
+
primaryKey?: boolean | undefined;
|
|
58
|
+
sensitive?: boolean | undefined;
|
|
59
|
+
}[];
|
|
60
|
+
sensitive?: boolean | undefined;
|
|
61
|
+
}[];
|
|
62
|
+
}, {
|
|
63
|
+
version: 1;
|
|
64
|
+
tables: {
|
|
65
|
+
name: string;
|
|
66
|
+
columns: {
|
|
67
|
+
name: string;
|
|
68
|
+
type: string;
|
|
69
|
+
nullable?: boolean | undefined;
|
|
70
|
+
primaryKey?: boolean | undefined;
|
|
71
|
+
sensitive?: boolean | undefined;
|
|
72
|
+
}[];
|
|
73
|
+
sensitive?: boolean | undefined;
|
|
74
|
+
}[];
|
|
75
|
+
}>;
|
|
76
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/schema/format.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAkBxB,eAAO,MAAM,qBAAqB;;;;;;;;;YAXhC,oGAAoG;;;;;;;;;;;;;;;QAOpG,yFAAyF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAOzF,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const columnSchema = z.object({
|
|
3
|
+
name: z.string().min(1),
|
|
4
|
+
type: z.string().min(1),
|
|
5
|
+
nullable: z.boolean().optional(),
|
|
6
|
+
primaryKey: z.boolean().optional(),
|
|
7
|
+
/** When true, column metadata is omitted from NL→SQL prompts (Phase 2 sensitive-field plumbing). */
|
|
8
|
+
sensitive: z.boolean().optional(),
|
|
9
|
+
});
|
|
10
|
+
const tableSchema = z.object({
|
|
11
|
+
name: z.string().min(1),
|
|
12
|
+
columns: z.array(columnSchema).min(1),
|
|
13
|
+
/** When true, all column definitions for this table are withheld from NL→SQL prompts. */
|
|
14
|
+
sensitive: z.boolean().optional(),
|
|
15
|
+
});
|
|
16
|
+
export const askDbSchemaFileSchema = z.object({
|
|
17
|
+
version: z.literal(1),
|
|
18
|
+
tables: z.array(tableSchema).min(1),
|
|
19
|
+
});
|
|
20
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/schema/format.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5B,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAChC,UAAU,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAClC,oGAAoG;IACpG,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;CAClC,CAAC,CAAC;AAEH,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3B,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACrC,yFAAyF;IACzF,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;CAClC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5C,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IACrB,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;CACpC,CAAC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { AskDbSchemaFile, NormalizedSchema } from "./types.js";
|
|
2
|
+
export declare function normalizeAskDbSchema(parsed: AskDbSchemaFile): NormalizedSchema;
|
|
3
|
+
/** Options for {@link formatSchemaForNlToSql}. */
|
|
4
|
+
export type FormatNlToSqlOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* When true, sensitive table/column identifiers are **omitted** from NL→SQL DDL (stricter).
|
|
7
|
+
* Default **false** — names are **included** and tagged `(sensitive)` so the model can ground SQL without hallucinating missing columns.
|
|
8
|
+
*/
|
|
9
|
+
omitSensitiveIdentifiersFromPrompt?: boolean;
|
|
10
|
+
};
|
|
11
|
+
/** Stats when building DDL for NL→SQL (meaning depends on {@link FormatNlToSqlOptions.omitSensitiveIdentifiersFromPrompt}). */
|
|
12
|
+
export type NlToSqlSchemaFormatStats = {
|
|
13
|
+
omitSensitiveIdentifiersFromPrompt: boolean;
|
|
14
|
+
/** When omitting: columns withheld from DDL. When including: always 0. */
|
|
15
|
+
redactedColumnCount: number;
|
|
16
|
+
/** When omitting: tables fully stubbed. When including: always 0. */
|
|
17
|
+
sensitiveTableStubCount: number;
|
|
18
|
+
/** When including: sensitive-marked columns listed in DDL (with `(sensitive)`). When omitting: always 0. */
|
|
19
|
+
listedSensitiveColumnCount: number;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Format schema for LLM prompts. By default, **includes** sensitive column/table names (tagged) so NL→SQL can
|
|
23
|
+
* ground identifiers; set {@link FormatNlToSqlOptions.omitSensitiveIdentifiersFromPrompt} to omit them.
|
|
24
|
+
*/
|
|
25
|
+
export declare function formatSchemaForNlToSql(schema: NormalizedSchema, options?: FormatNlToSqlOptions): {
|
|
26
|
+
ddl: string;
|
|
27
|
+
stats: NlToSqlSchemaFormatStats;
|
|
28
|
+
};
|
|
29
|
+
/** Same DDL as {@link formatSchemaForNlToSql} with default options (sensitive names included, tagged). */
|
|
30
|
+
export declare function formatSchemaForPrompt(schema: NormalizedSchema, options?: FormatNlToSqlOptions): string;
|
|
31
|
+
//# sourceMappingURL=normalize.d.ts.map
|