@pgsage/core 0.1.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 +126 -0
- package/dist/corrector/index.d.ts +72 -0
- package/dist/corrector/index.d.ts.map +1 -0
- package/dist/corrector/index.js +113 -0
- package/dist/corrector/index.js.map +1 -0
- package/dist/db/index.d.ts +3 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +2 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/pool.d.ts +46 -0
- package/dist/db/pool.d.ts.map +1 -0
- package/dist/db/pool.js +46 -0
- package/dist/db/pool.js.map +1 -0
- package/dist/embeddings/index.d.ts +4 -0
- package/dist/embeddings/index.d.ts.map +1 -0
- package/dist/embeddings/index.js +2 -0
- package/dist/embeddings/index.js.map +1 -0
- package/dist/embeddings/types.d.ts +39 -0
- package/dist/embeddings/types.d.ts.map +1 -0
- package/dist/embeddings/types.js +16 -0
- package/dist/embeddings/types.js.map +1 -0
- package/dist/embeddings/voyage.d.ts +70 -0
- package/dist/embeddings/voyage.d.ts.map +1 -0
- package/dist/embeddings/voyage.js +163 -0
- package/dist/embeddings/voyage.js.map +1 -0
- package/dist/estimator/index.d.ts +53 -0
- package/dist/estimator/index.d.ts.map +1 -0
- package/dist/estimator/index.js +57 -0
- package/dist/estimator/index.js.map +1 -0
- package/dist/executor/index.d.ts +56 -0
- package/dist/executor/index.d.ts.map +1 -0
- package/dist/executor/index.js +86 -0
- package/dist/executor/index.js.map +1 -0
- package/dist/explainer/index.d.ts +39 -0
- package/dist/explainer/index.d.ts.map +1 -0
- package/dist/explainer/index.js +79 -0
- package/dist/explainer/index.js.map +1 -0
- package/dist/explainer/prompt.d.ts +37 -0
- package/dist/explainer/prompt.d.ts.map +1 -0
- package/dist/explainer/prompt.js +102 -0
- package/dist/explainer/prompt.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/introspector/index.d.ts +127 -0
- package/dist/introspector/index.d.ts.map +1 -0
- package/dist/introspector/index.js +460 -0
- package/dist/introspector/index.js.map +1 -0
- package/dist/orchestrator/index.d.ts +113 -0
- package/dist/orchestrator/index.d.ts.map +1 -0
- package/dist/orchestrator/index.js +126 -0
- package/dist/orchestrator/index.js.map +1 -0
- package/dist/planner/index.d.ts +83 -0
- package/dist/planner/index.d.ts.map +1 -0
- package/dist/planner/index.js +67 -0
- package/dist/planner/index.js.map +1 -0
- package/dist/planner/prompt.d.ts +37 -0
- package/dist/planner/prompt.d.ts.map +1 -0
- package/dist/planner/prompt.js +436 -0
- package/dist/planner/prompt.js.map +1 -0
- package/dist/retriever/index.d.ts +90 -0
- package/dist/retriever/index.d.ts.map +1 -0
- package/dist/retriever/index.js +164 -0
- package/dist/retriever/index.js.map +1 -0
- package/dist/validator/index.d.ts +26 -0
- package/dist/validator/index.d.ts.map +1 -0
- package/dist/validator/index.js +205 -0
- package/dist/validator/index.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Explainer prompt utilities
|
|
3
|
+
*
|
|
4
|
+
* Contains:
|
|
5
|
+
* - EXPLAINER_SYSTEM_PROMPT: instructs the model to produce a concise
|
|
6
|
+
* natural-language answer from query results
|
|
7
|
+
* - buildExplainerMessage(): formats the question, plan metadata, and
|
|
8
|
+
* result rows into a compact user message for the explainer LLM call
|
|
9
|
+
*/
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
// System prompt
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
export const EXPLAINER_SYSTEM_PROMPT = `\
|
|
14
|
+
You are a data analyst summarizing SQL query results in plain English.
|
|
15
|
+
|
|
16
|
+
## Your task
|
|
17
|
+
Given the user's original question, the SQL query results (column names + rows),
|
|
18
|
+
and some metadata about the query, produce a concise natural-language answer.
|
|
19
|
+
|
|
20
|
+
## Rules
|
|
21
|
+
- Answer the question DIRECTLY. Start with the key finding, not "Based on the data…" or "The query returned…".
|
|
22
|
+
- Reference specific values from the data. Format numbers with proper units:
|
|
23
|
+
- Currency: $78,787 (with commas, dollar sign)
|
|
24
|
+
- Percentages: 34.2%
|
|
25
|
+
- Counts: 1,234,567 (with commas)
|
|
26
|
+
- Margins of error: ±$1,722 or ±2.3%
|
|
27
|
+
- Keep it to 1–3 sentences. Be direct and informative.
|
|
28
|
+
- Do NOT repeat the question back.
|
|
29
|
+
- Do NOT list assumptions — those are displayed separately in the UI.
|
|
30
|
+
- Do NOT say "the data shows" or "according to the results" — just state the facts.
|
|
31
|
+
- If the displayHint is "big" (single value), state the value and its context clearly.
|
|
32
|
+
- If the displayHint is "bar" (ranked list), mention the top entry and give a sense of the range.
|
|
33
|
+
- If the displayHint is "statrow" (multiple metrics), briefly cover each metric.
|
|
34
|
+
- If the displayHint is "grouped" (comparison), highlight the key comparison.
|
|
35
|
+
- If the displayHint is "table" (general), summarize the key pattern or finding.
|
|
36
|
+
- If there are zero rows, say that no matching data was found and briefly suggest why.
|
|
37
|
+
|
|
38
|
+
## Output format
|
|
39
|
+
Respond with a JSON object:
|
|
40
|
+
{
|
|
41
|
+
"answer": "<your 1–3 sentence answer>"
|
|
42
|
+
}
|
|
43
|
+
Do not include any text outside the JSON object.`;
|
|
44
|
+
/**
|
|
45
|
+
* Cap the number of rows sent to the explainer to keep token usage low.
|
|
46
|
+
* The explainer doesn't need every row — just enough to summarize.
|
|
47
|
+
*/
|
|
48
|
+
const MAX_EXPLAINER_ROWS = 20;
|
|
49
|
+
/**
|
|
50
|
+
* Builds the user message for the explainer LLM call.
|
|
51
|
+
*
|
|
52
|
+
* Includes the question, display hint, field names, and a compact
|
|
53
|
+
* representation of the first N rows.
|
|
54
|
+
*/
|
|
55
|
+
export function buildExplainerMessage(input) {
|
|
56
|
+
const parts = [];
|
|
57
|
+
parts.push(`## Question`);
|
|
58
|
+
parts.push(input.question);
|
|
59
|
+
parts.push("");
|
|
60
|
+
parts.push(`## Display Layout`);
|
|
61
|
+
parts.push(input.displayHint);
|
|
62
|
+
parts.push("");
|
|
63
|
+
parts.push(`## Query Results`);
|
|
64
|
+
parts.push(`Columns: ${input.fields.join(", ")}`);
|
|
65
|
+
parts.push(`Total rows: ${String(input.rowCount)}${input.truncated ? " (truncated)" : ""}`);
|
|
66
|
+
parts.push("");
|
|
67
|
+
// Render rows as a compact table
|
|
68
|
+
const cappedRows = input.rows.slice(0, MAX_EXPLAINER_ROWS);
|
|
69
|
+
if (cappedRows.length === 0) {
|
|
70
|
+
parts.push("(no rows returned)");
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
for (let i = 0; i < cappedRows.length; i++) {
|
|
74
|
+
const row = cappedRows[i];
|
|
75
|
+
const cells = input.fields.map((f) => {
|
|
76
|
+
const val = row[f];
|
|
77
|
+
if (val === null || val === undefined)
|
|
78
|
+
return "NULL";
|
|
79
|
+
if (typeof val === "string")
|
|
80
|
+
return val;
|
|
81
|
+
if (typeof val === "number" || typeof val === "boolean" || typeof val === "bigint") {
|
|
82
|
+
return String(val);
|
|
83
|
+
}
|
|
84
|
+
return JSON.stringify(val);
|
|
85
|
+
});
|
|
86
|
+
parts.push(`Row ${String(i + 1)}: ${cells.join(" | ")}`);
|
|
87
|
+
}
|
|
88
|
+
if (cappedRows.length < input.rowCount) {
|
|
89
|
+
parts.push(`... and ${String(input.rowCount - cappedRows.length)} more rows`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
parts.push("");
|
|
93
|
+
// Include assumptions so the explainer knows not to repeat them
|
|
94
|
+
if (input.assumptions.length > 0) {
|
|
95
|
+
parts.push(`## Assumptions (already shown to user — do NOT repeat these)`);
|
|
96
|
+
for (const a of input.assumptions) {
|
|
97
|
+
parts.push(`- ${a}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return parts.join("\n");
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=prompt.js.map
|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MAAM,GAAG,CAAC,EAAE,CAAC;QACjC,KAAK,CAAC,IAAI,CAAC,8DAA8D,CAAC,CAAC;QAC3E,KAAK,MAAM,CAAC,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC;YAClC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export * as db from "./db/index.js";
|
|
2
|
+
export * as embeddings from "./embeddings/index.js";
|
|
3
|
+
export * as introspector from "./introspector/index.js";
|
|
4
|
+
export * as retriever from "./retriever/index.js";
|
|
5
|
+
export * as planner from "./planner/index.js";
|
|
6
|
+
export * as validator from "./validator/index.js";
|
|
7
|
+
export * as estimator from "./estimator/index.js";
|
|
8
|
+
export * as executor from "./executor/index.js";
|
|
9
|
+
export * as corrector from "./corrector/index.js";
|
|
10
|
+
export * as explainer from "./explainer/index.js";
|
|
11
|
+
export * as orchestrator from "./orchestrator/index.js";
|
|
12
|
+
export { createAgent } from "./orchestrator/index.js";
|
|
13
|
+
export type { OrchestratorConfig, QueryResponse, QueryOptions, Agent, } from "./orchestrator/index.js";
|
|
14
|
+
export type { DisplayHint } from "./planner/index.js";
|
|
15
|
+
export { createPool, createReadonlyPool } from "./db/index.js";
|
|
16
|
+
export type { PoolOptions } from "./db/index.js";
|
|
17
|
+
export { VoyageEmbeddingProvider } from "./embeddings/index.js";
|
|
18
|
+
export type { EmbeddingProvider, VoyageConfig, VoyageModel, } from "./embeddings/index.js";
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,YAAY,MAAM,yBAAyB,CAAC;AACxD,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAC;AAC9C,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAC;AAChD,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,YAAY,MAAM,yBAAyB,CAAC;AAOxD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,YAAY,EACV,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,KAAK,GACN,MAAM,yBAAyB,CAAC;AAGjC,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGtD,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAC/D,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAGjD,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,YAAY,EACV,iBAAiB,EACjB,YAAY,EACZ,WAAW,GACZ,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Namespace exports — power users who need individual stages
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
export * as db from "./db/index.js";
|
|
5
|
+
export * as embeddings from "./embeddings/index.js";
|
|
6
|
+
export * as introspector from "./introspector/index.js";
|
|
7
|
+
export * as retriever from "./retriever/index.js";
|
|
8
|
+
export * as planner from "./planner/index.js";
|
|
9
|
+
export * as validator from "./validator/index.js";
|
|
10
|
+
export * as estimator from "./estimator/index.js";
|
|
11
|
+
export * as executor from "./executor/index.js";
|
|
12
|
+
export * as corrector from "./corrector/index.js";
|
|
13
|
+
export * as explainer from "./explainer/index.js";
|
|
14
|
+
export * as orchestrator from "./orchestrator/index.js";
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
// Primary public API — direct top-level exports for SDK consumers
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
// Agent factory — the main entrypoint
|
|
19
|
+
export { createAgent } from "./orchestrator/index.js";
|
|
20
|
+
// Connection pools
|
|
21
|
+
export { createPool, createReadonlyPool } from "./db/index.js";
|
|
22
|
+
// Embedding provider
|
|
23
|
+
export { VoyageEmbeddingProvider } from "./embeddings/index.js";
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,6DAA6D;AAC7D,8EAA8E;AAC9E,OAAO,KAAK,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,YAAY,MAAM,yBAAyB,CAAC;AACxD,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAC;AAC9C,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAC;AAChD,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,YAAY,MAAM,yBAAyB,CAAC;AAExD,8EAA8E;AAC9E,kEAAkE;AAClE,8EAA8E;AAE9E,sCAAsC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAWtD,mBAAmB;AACnB,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAG/D,qBAAqB;AACrB,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Introspector
|
|
3
|
+
*
|
|
4
|
+
* Crawls information_schema and pg_catalog to produce a fully-typed
|
|
5
|
+
* IntrospectedSchema describing every table, view, column, constraint,
|
|
6
|
+
* index, and enum in the target database.
|
|
7
|
+
*
|
|
8
|
+
* All queries run as a single-client transaction (READ ONLY) to give a
|
|
9
|
+
* consistent snapshot. The introspector is deliberately read-only and
|
|
10
|
+
* dataset-agnostic — it works against any Postgres database (Chinook,
|
|
11
|
+
* Census schema, arbitrary user schemas, etc.).
|
|
12
|
+
*/
|
|
13
|
+
import type { Pool } from "pg";
|
|
14
|
+
export interface IntrospectedColumn {
|
|
15
|
+
/** Column name. */
|
|
16
|
+
name: string;
|
|
17
|
+
/** SQL data type as returned by information_schema (e.g. 'character varying'). */
|
|
18
|
+
dataType: string;
|
|
19
|
+
/** Underlying pg type name (e.g. 'varchar', 'int4', 'uuid'). */
|
|
20
|
+
udtName: string;
|
|
21
|
+
/** True if the column allows NULL values. */
|
|
22
|
+
isNullable: boolean;
|
|
23
|
+
/** Column default expression, or null if none. */
|
|
24
|
+
defaultValue: string | null;
|
|
25
|
+
/** 1-based position in the table definition. */
|
|
26
|
+
ordinalPosition: number;
|
|
27
|
+
/** True if this column is part of the table's primary key. */
|
|
28
|
+
isPrimaryKey: boolean;
|
|
29
|
+
/** COMMENT ON COLUMN value, or null. */
|
|
30
|
+
comment: string | null;
|
|
31
|
+
}
|
|
32
|
+
export interface ForeignKey {
|
|
33
|
+
/** Constraint name. */
|
|
34
|
+
constraintName: string;
|
|
35
|
+
/** Columns in this table that form the FK (in key order). */
|
|
36
|
+
columns: string[];
|
|
37
|
+
/** Schema of the referenced table. */
|
|
38
|
+
referencedSchema: string;
|
|
39
|
+
/** Name of the referenced table. */
|
|
40
|
+
referencedTable: string;
|
|
41
|
+
/** Columns in the referenced table (parallel to columns[]). */
|
|
42
|
+
referencedColumns: string[];
|
|
43
|
+
}
|
|
44
|
+
export interface UniqueConstraint {
|
|
45
|
+
/** Constraint name. */
|
|
46
|
+
name: string;
|
|
47
|
+
/** Columns covered by the constraint (in key order). */
|
|
48
|
+
columns: string[];
|
|
49
|
+
}
|
|
50
|
+
export interface CheckConstraint {
|
|
51
|
+
/** Constraint name. */
|
|
52
|
+
name: string;
|
|
53
|
+
/** The CHECK expression as stored in pg_catalog. */
|
|
54
|
+
expression: string;
|
|
55
|
+
}
|
|
56
|
+
export interface Index {
|
|
57
|
+
/** Index name. */
|
|
58
|
+
name: string;
|
|
59
|
+
/** Columns covered by the index (in index order). */
|
|
60
|
+
columns: string[];
|
|
61
|
+
/** True if this is a unique index. */
|
|
62
|
+
isUnique: boolean;
|
|
63
|
+
/** Index access method: 'btree', 'hash', 'gin', 'gist', 'hnsw', etc. */
|
|
64
|
+
indexType: string;
|
|
65
|
+
}
|
|
66
|
+
export interface EnumType {
|
|
67
|
+
/** Enum type name. */
|
|
68
|
+
name: string;
|
|
69
|
+
/** Schema the type belongs to. */
|
|
70
|
+
schema: string;
|
|
71
|
+
/** Enum labels in sort order. */
|
|
72
|
+
values: string[];
|
|
73
|
+
}
|
|
74
|
+
export interface IntrospectedTable {
|
|
75
|
+
/** Table (or view) name. */
|
|
76
|
+
name: string;
|
|
77
|
+
/** Schema name. */
|
|
78
|
+
schema: string;
|
|
79
|
+
/** 'table' or 'view'. */
|
|
80
|
+
tableType: "table" | "view";
|
|
81
|
+
/** All columns, ordered by ordinal_position. */
|
|
82
|
+
columns: IntrospectedColumn[];
|
|
83
|
+
/** Column names that form the primary key (empty for views). */
|
|
84
|
+
primaryKey: string[];
|
|
85
|
+
/** Foreign key constraints defined on this table. */
|
|
86
|
+
foreignKeys: ForeignKey[];
|
|
87
|
+
/** Non-PK indexes (primary key index is not included). */
|
|
88
|
+
indexes: Index[];
|
|
89
|
+
/** UNIQUE constraints (excluding primary key). */
|
|
90
|
+
uniqueConstraints: UniqueConstraint[];
|
|
91
|
+
/** CHECK constraints (NOT NULL checks excluded — they appear in isNullable). */
|
|
92
|
+
checkConstraints: CheckConstraint[];
|
|
93
|
+
/**
|
|
94
|
+
* Postgres row estimate from pg_class.reltuples.
|
|
95
|
+
* -1 means the table has never been analyzed (ANALYZE not yet run).
|
|
96
|
+
*/
|
|
97
|
+
estimatedRowCount: number;
|
|
98
|
+
/** COMMENT ON TABLE value, or null. */
|
|
99
|
+
comment: string | null;
|
|
100
|
+
}
|
|
101
|
+
export interface IntrospectedSchema {
|
|
102
|
+
/** All tables and views discovered, sorted schema then name. */
|
|
103
|
+
tables: IntrospectedTable[];
|
|
104
|
+
/** All enum types discovered, sorted schema then name. */
|
|
105
|
+
enums: EnumType[];
|
|
106
|
+
}
|
|
107
|
+
export interface IntrospectOptions {
|
|
108
|
+
/**
|
|
109
|
+
* Limit introspection to these schema names.
|
|
110
|
+
* If omitted all user schemas are included (pg_catalog, information_schema,
|
|
111
|
+
* pg_toast, and pg_temp_* are always excluded).
|
|
112
|
+
*/
|
|
113
|
+
schemas?: string[];
|
|
114
|
+
/**
|
|
115
|
+
* Include views in the result.
|
|
116
|
+
* Default: true.
|
|
117
|
+
*/
|
|
118
|
+
includeViews?: boolean;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Introspect the target database and return a fully-typed schema description.
|
|
122
|
+
*
|
|
123
|
+
* @param pool A pg Pool connected to the target database.
|
|
124
|
+
* @param options Filtering options.
|
|
125
|
+
*/
|
|
126
|
+
export declare function introspect(pool: Pool, options?: IntrospectOptions): Promise<IntrospectedSchema>;
|
|
127
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/introspector/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAW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