@adminiumjs/llm 0.1.0-rc.1
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 +661 -0
- package/dist/apply/diff.d.ts +79 -0
- package/dist/apply/diff.d.ts.map +1 -0
- package/dist/apply/diff.js +459 -0
- package/dist/apply/diff.js.map +1 -0
- package/dist/apply/index.d.ts +6 -0
- package/dist/apply/index.d.ts.map +1 -0
- package/dist/apply/index.js +6 -0
- package/dist/apply/index.js.map +1 -0
- package/dist/apply/normalize.d.ts +55 -0
- package/dist/apply/normalize.d.ts.map +1 -0
- package/dist/apply/normalize.js +232 -0
- package/dist/apply/normalize.js.map +1 -0
- package/dist/apply/plan.d.ts +206 -0
- package/dist/apply/plan.d.ts.map +1 -0
- package/dist/apply/plan.js +422 -0
- package/dist/apply/plan.js.map +1 -0
- package/dist/apply/suggestion-id.d.ts +103 -0
- package/dist/apply/suggestion-id.d.ts.map +1 -0
- package/dist/apply/suggestion-id.js +121 -0
- package/dist/apply/suggestion-id.js.map +1 -0
- package/dist/crypto.d.ts +48 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +35 -0
- package/dist/crypto.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/prompt/builder.d.ts +27 -0
- package/dist/prompt/builder.d.ts.map +1 -0
- package/dist/prompt/builder.js +263 -0
- package/dist/prompt/builder.js.map +1 -0
- package/dist/prompt/chunker.d.ts +89 -0
- package/dist/prompt/chunker.d.ts.map +1 -0
- package/dist/prompt/chunker.js +383 -0
- package/dist/prompt/chunker.js.map +1 -0
- package/dist/prompt/index.d.ts +14 -0
- package/dist/prompt/index.d.ts.map +1 -0
- package/dist/prompt/index.js +14 -0
- package/dist/prompt/index.js.map +1 -0
- package/dist/prompt/serializer.d.ts +138 -0
- package/dist/prompt/serializer.d.ts.map +1 -0
- package/dist/prompt/serializer.js +178 -0
- package/dist/prompt/serializer.js.map +1 -0
- package/dist/prompt/templates/v1.d.ts +41 -0
- package/dist/prompt/templates/v1.d.ts.map +1 -0
- package/dist/prompt/templates/v1.js +312 -0
- package/dist/prompt/templates/v1.js.map +1 -0
- package/dist/prompt/token-estimate.d.ts +16 -0
- package/dist/prompt/token-estimate.d.ts.map +1 -0
- package/dist/prompt/token-estimate.js +20 -0
- package/dist/prompt/token-estimate.js.map +1 -0
- package/dist/prompt/types.d.ts +134 -0
- package/dist/prompt/types.d.ts.map +1 -0
- package/dist/prompt/types.js +44 -0
- package/dist/prompt/types.js.map +1 -0
- package/dist/providers/anthropic.d.ts +3 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +65 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/factory.d.ts +3 -0
- package/dist/providers/factory.d.ts.map +1 -0
- package/dist/providers/factory.js +37 -0
- package/dist/providers/factory.js.map +1 -0
- package/dist/providers/http.d.ts +56 -0
- package/dist/providers/http.d.ts.map +1 -0
- package/dist/providers/http.js +148 -0
- package/dist/providers/http.js.map +1 -0
- package/dist/providers/index.d.ts +15 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +15 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/model-catalog.d.ts +21 -0
- package/dist/providers/model-catalog.d.ts.map +1 -0
- package/dist/providers/model-catalog.js +121 -0
- package/dist/providers/model-catalog.js.map +1 -0
- package/dist/providers/ollama.d.ts +3 -0
- package/dist/providers/ollama.d.ts.map +1 -0
- package/dist/providers/ollama.js +55 -0
- package/dist/providers/ollama.js.map +1 -0
- package/dist/providers/openai-compatible.d.ts +3 -0
- package/dist/providers/openai-compatible.d.ts.map +1 -0
- package/dist/providers/openai-compatible.js +50 -0
- package/dist/providers/openai-compatible.js.map +1 -0
- package/dist/providers/openai.d.ts +18 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/openai.js +68 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers/types.d.ts +112 -0
- package/dist/providers/types.d.ts.map +1 -0
- package/dist/providers/types.js +55 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/response/errors.d.ts +60 -0
- package/dist/response/errors.d.ts.map +1 -0
- package/dist/response/errors.js +101 -0
- package/dist/response/errors.js.map +1 -0
- package/dist/response/extract.d.ts +38 -0
- package/dist/response/extract.d.ts.map +1 -0
- package/dist/response/extract.js +77 -0
- package/dist/response/extract.js.map +1 -0
- package/dist/response/index.d.ts +8 -0
- package/dist/response/index.d.ts.map +1 -0
- package/dist/response/index.js +8 -0
- package/dist/response/index.js.map +1 -0
- package/dist/response/merge.d.ts +53 -0
- package/dist/response/merge.d.ts.map +1 -0
- package/dist/response/merge.js +348 -0
- package/dist/response/merge.js.map +1 -0
- package/dist/response/referential.d.ts +113 -0
- package/dist/response/referential.d.ts.map +1 -0
- package/dist/response/referential.js +556 -0
- package/dist/response/referential.js.map +1 -0
- package/dist/response/schema.d.ts +506 -0
- package/dist/response/schema.d.ts.map +1 -0
- package/dist/response/schema.js +191 -0
- package/dist/response/schema.js.map +1 -0
- package/dist/response/validate.d.ts +29 -0
- package/dist/response/validate.d.ts.map +1 -0
- package/dist/response/validate.js +167 -0
- package/dist/response/validate.js.map +1 -0
- package/dist/types.d.ts +95 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +49 -0
- package/dist/types.js.map +1 -0
- package/package.json +30 -0
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `chunker.ts` — token-budget map-phase chunking for huge schemas
|
|
3
|
+
* (06-llm-assist.md §4.5, acceptance criterion 7).
|
|
4
|
+
*
|
|
5
|
+
* When the assembled prompt for a whole schema would exceed the per-prompt token
|
|
6
|
+
* budget, the schema is split **by domain**: a connected-component clustering
|
|
7
|
+
* over the FK graph (declared + inferred relations + column FK mirrors) keeps
|
|
8
|
+
* related tables together, clusters are greedily packed into chunks of
|
|
9
|
+
* ≤ `chunkTokenBudget` estimated tokens, and any single cluster too large for one
|
|
10
|
+
* chunk is split by table row-count descending as a last resort.
|
|
11
|
+
*
|
|
12
|
+
* Each chunk is SELF-CONTAINED: it carries its own tables in full plus **stub
|
|
13
|
+
* entries** for every out-of-chunk FK target its tables reference, so
|
|
14
|
+
* cross-chunk relations stay inferable and every prompt validates on its own.
|
|
15
|
+
* The map phase produces one prompt per chunk; `response/merge.ts` performs the
|
|
16
|
+
* deterministic reduce.
|
|
17
|
+
*
|
|
18
|
+
* Determinism (a hard requirement — the diff UI and golden tests depend on it):
|
|
19
|
+
* every ordering here is content-derived (cluster weight, table id, row count),
|
|
20
|
+
* never insertion order or `Math.random`/`Date.now`. The same model + stats
|
|
21
|
+
* always chunk identically.
|
|
22
|
+
*
|
|
23
|
+
* Browser-safe: `parseDatabaseModel` is pure Zod (no DB driver), and only
|
|
24
|
+
* pure-TS engine TYPES are imported. This never creates an engine→llm edge.
|
|
25
|
+
*/
|
|
26
|
+
import { parseDatabaseModel } from '@adminium/engine';
|
|
27
|
+
import { buildPrompt, normalizeSections } from './builder.js';
|
|
28
|
+
import { qualifyTableRef, serializeSamplingPayload, serializeSchemaIr, serializeStats, } from './serializer.js';
|
|
29
|
+
import { estimateTokens } from './token-estimate.js';
|
|
30
|
+
/** Per-chunk token ceiling (§4.5: "chunks of ≤ 45,000 tokens"). */
|
|
31
|
+
export const DEFAULT_CHUNK_TOKEN_BUDGET = 45_000;
|
|
32
|
+
/**
|
|
33
|
+
* Slack subtracted from the per-chunk table capacity to absorb the small
|
|
34
|
+
* discrepancy between summed per-fragment token estimates (each `ceil`-ed
|
|
35
|
+
* independently) and the single `ceil` over the assembled prompt. Purely a
|
|
36
|
+
* safety cushion — the built prompt always lands under budget.
|
|
37
|
+
*/
|
|
38
|
+
const SAFETY_TOKENS = 512;
|
|
39
|
+
/**
|
|
40
|
+
* Fraction of a split cluster's per-chunk table capacity reserved for stub
|
|
41
|
+
* entries. Stubs are column-NAME lists only (no types/flags/stats), empirically
|
|
42
|
+
* a tiny fraction of a full table's serialized size, so 20 % is very
|
|
43
|
+
* conservative and guarantees a split chunk stays under budget once its stubs
|
|
44
|
+
* are added. Whole-cluster packing needs no reserve: clusters are FK-connected
|
|
45
|
+
* components, so packing distinct clusters together never creates a cross-chunk
|
|
46
|
+
* FK (and thus no stubs).
|
|
47
|
+
*/
|
|
48
|
+
const SPLIT_STUB_RESERVE_RATIO = 0.2;
|
|
49
|
+
// ─── FK-connectivity clustering (§4.5 "split by domain") ─────────────────────
|
|
50
|
+
function ensureSet(map, id) {
|
|
51
|
+
let set = map.get(id);
|
|
52
|
+
if (set === undefined) {
|
|
53
|
+
set = new Set();
|
|
54
|
+
map.set(id, set);
|
|
55
|
+
}
|
|
56
|
+
return set;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Partition the model's tables into FK-connected components. The graph is
|
|
60
|
+
* undirected over declared + inferred relations (both endpoints, and the join
|
|
61
|
+
* table for m2m) and column FK mirrors. Tables touched by no relation are
|
|
62
|
+
* singleton components. Each component is returned id-sorted, and the outer list
|
|
63
|
+
* is sorted by smallest member id — fully deterministic.
|
|
64
|
+
*/
|
|
65
|
+
export function clusterTables(model) {
|
|
66
|
+
const adjacency = new Map();
|
|
67
|
+
for (const table of model.tables)
|
|
68
|
+
ensureSet(adjacency, table.id);
|
|
69
|
+
const link = (a, b) => {
|
|
70
|
+
if (a === b)
|
|
71
|
+
return;
|
|
72
|
+
ensureSet(adjacency, a).add(b);
|
|
73
|
+
ensureSet(adjacency, b).add(a);
|
|
74
|
+
};
|
|
75
|
+
for (const relation of model.relations) {
|
|
76
|
+
link(relation.from.tableId, relation.to.tableId);
|
|
77
|
+
if (relation.through !== null) {
|
|
78
|
+
link(relation.from.tableId, relation.through.tableId);
|
|
79
|
+
link(relation.to.tableId, relation.through.tableId);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
for (const table of model.tables) {
|
|
83
|
+
for (const column of table.columns) {
|
|
84
|
+
if (column.references !== null)
|
|
85
|
+
link(table.id, column.references.tableId);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const seen = new Set();
|
|
89
|
+
const clusters = [];
|
|
90
|
+
for (const table of model.tables) {
|
|
91
|
+
if (seen.has(table.id))
|
|
92
|
+
continue;
|
|
93
|
+
const component = [table.id];
|
|
94
|
+
seen.add(table.id);
|
|
95
|
+
const stack = [table.id];
|
|
96
|
+
while (stack.length > 0) {
|
|
97
|
+
const current = stack.pop();
|
|
98
|
+
if (current === undefined)
|
|
99
|
+
break;
|
|
100
|
+
for (const neighbor of adjacency.get(current) ?? new Set()) {
|
|
101
|
+
if (seen.has(neighbor))
|
|
102
|
+
continue;
|
|
103
|
+
seen.add(neighbor);
|
|
104
|
+
component.push(neighbor);
|
|
105
|
+
stack.push(neighbor);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
component.sort((a, b) => a.localeCompare(b));
|
|
109
|
+
clusters.push(component);
|
|
110
|
+
}
|
|
111
|
+
clusters.sort((a, b) => (a[0] ?? '').localeCompare(b[0] ?? ''));
|
|
112
|
+
return clusters;
|
|
113
|
+
}
|
|
114
|
+
// ─── Per-table weights + fixed overhead ──────────────────────────────────────
|
|
115
|
+
/**
|
|
116
|
+
* Estimated token contribution of each full table to a prompt: its serialized
|
|
117
|
+
* schema-IR entry + any enum-column entries + declared relations it owns + its
|
|
118
|
+
* statistics entry + (opt-in) its sampling entry. Measured off the real
|
|
119
|
+
* serializers so it tracks the actual prompt bytes; a couple of tokens per
|
|
120
|
+
* fragment cover the surrounding commas.
|
|
121
|
+
*/
|
|
122
|
+
export function computeTableWeights(input) {
|
|
123
|
+
const model = input.schemaIr;
|
|
124
|
+
const stats = input.stats;
|
|
125
|
+
const weights = new Map();
|
|
126
|
+
const bump = (id, tokens) => {
|
|
127
|
+
weights.set(id, (weights.get(id) ?? 0) + tokens);
|
|
128
|
+
};
|
|
129
|
+
const ir = serializeSchemaIr(model, { stats });
|
|
130
|
+
for (const table of ir.tables)
|
|
131
|
+
bump(table.table, estimateTokens(JSON.stringify(table)) + 2);
|
|
132
|
+
for (const enumColumn of ir.enumColumns)
|
|
133
|
+
bump(enumColumn.table, estimateTokens(JSON.stringify(enumColumn)) + 1);
|
|
134
|
+
for (const relation of ir.declaredRelations) {
|
|
135
|
+
bump(relation.fromTable, estimateTokens(JSON.stringify(relation)) + 1);
|
|
136
|
+
}
|
|
137
|
+
const statsBlock = serializeStats(stats, { defaultSchema: model.defaultSchema });
|
|
138
|
+
for (const table of statsBlock.tables)
|
|
139
|
+
bump(table.table, estimateTokens(JSON.stringify(table)) + 1);
|
|
140
|
+
if (input.sampling !== null) {
|
|
141
|
+
const sampling = serializeSamplingPayload(model, stats, input.sampling.maxValuesPerColumn);
|
|
142
|
+
for (const table of sampling.tables)
|
|
143
|
+
bump(table.table, estimateTokens(JSON.stringify(table)) + 1);
|
|
144
|
+
}
|
|
145
|
+
for (const table of model.tables)
|
|
146
|
+
if (!weights.has(table.id))
|
|
147
|
+
bump(table.id, 0);
|
|
148
|
+
return weights;
|
|
149
|
+
}
|
|
150
|
+
/** Estimated token cost of rendering a table as a names-only stub (§4.5). */
|
|
151
|
+
export function computeStubWeights(model) {
|
|
152
|
+
const weights = new Map();
|
|
153
|
+
for (const table of model.tables) {
|
|
154
|
+
const stub = { table: table.id, stub: true, columns: table.columns.map((column) => column.name) };
|
|
155
|
+
weights.set(table.id, estimateTokens(JSON.stringify(stub)) + 1);
|
|
156
|
+
}
|
|
157
|
+
return weights;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* The fixed per-chunk overhead (system section + full instruction template +
|
|
161
|
+
* allow-lists + locales + the chunk-info sentence + the empty structural JSON
|
|
162
|
+
* wrappers), measured by rendering a prompt for a table-less model. Every chunk
|
|
163
|
+
* repeats this cost regardless of how many tables it carries.
|
|
164
|
+
*/
|
|
165
|
+
export function computeOverheadTokens(input, options) {
|
|
166
|
+
const model = input.schemaIr;
|
|
167
|
+
const emptyModel = parseDatabaseModel({
|
|
168
|
+
dialect: model.dialect,
|
|
169
|
+
name: model.name,
|
|
170
|
+
defaultSchema: model.defaultSchema,
|
|
171
|
+
schemas: model.schemas,
|
|
172
|
+
tables: [],
|
|
173
|
+
});
|
|
174
|
+
const overhead = buildPrompt({ ...input, schemaIr: emptyModel, stats: [], chunk: { index: 1, total: 2, stubTables: [] } }, options);
|
|
175
|
+
return overhead.tokenEstimate;
|
|
176
|
+
}
|
|
177
|
+
// ─── Stub computation ────────────────────────────────────────────────────────
|
|
178
|
+
/**
|
|
179
|
+
* The out-of-chunk FK targets a chunk's full tables reference: the `to` (and
|
|
180
|
+
* join `through`) tables of every relation the chunk owns (relation `from` side
|
|
181
|
+
* is in the chunk), plus every column FK-mirror target — restricted to tables
|
|
182
|
+
* not in the chunk. These become the chunk's stub entries so no rendered
|
|
183
|
+
* relation or `references` points at a missing table.
|
|
184
|
+
*/
|
|
185
|
+
export function computeStubsForChunk(model, fullTables) {
|
|
186
|
+
const stubs = new Set();
|
|
187
|
+
for (const relation of model.relations) {
|
|
188
|
+
if (!fullTables.has(relation.from.tableId))
|
|
189
|
+
continue;
|
|
190
|
+
if (!fullTables.has(relation.to.tableId))
|
|
191
|
+
stubs.add(relation.to.tableId);
|
|
192
|
+
if (relation.through !== null && !fullTables.has(relation.through.tableId)) {
|
|
193
|
+
stubs.add(relation.through.tableId);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
for (const table of model.tables) {
|
|
197
|
+
if (!fullTables.has(table.id))
|
|
198
|
+
continue;
|
|
199
|
+
for (const column of table.columns) {
|
|
200
|
+
if (column.references !== null && !fullTables.has(column.references.tableId)) {
|
|
201
|
+
stubs.add(column.references.tableId);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return stubs;
|
|
206
|
+
}
|
|
207
|
+
// ─── Planning: cluster → chunk partition (§4.5) ──────────────────────────────
|
|
208
|
+
/**
|
|
209
|
+
* Partition a schema into map-phase chunks. FFD-packs whole FK clusters into
|
|
210
|
+
* chunks of ≤ `chunkTokenBudget`; any cluster too big for one chunk is split by
|
|
211
|
+
* table row-count descending. Every chunk records the out-of-chunk FK targets it
|
|
212
|
+
* must stub. Deterministic for a given (model, stats, options).
|
|
213
|
+
*/
|
|
214
|
+
export function planSchemaChunks(input, options) {
|
|
215
|
+
const model = input.schemaIr;
|
|
216
|
+
const budget = options.chunkTokenBudget ?? DEFAULT_CHUNK_TOKEN_BUDGET;
|
|
217
|
+
const overhead = computeOverheadTokens(input, options);
|
|
218
|
+
const tableCapacity = budget - overhead - SAFETY_TOKENS;
|
|
219
|
+
if (tableCapacity <= 0) {
|
|
220
|
+
throw new Error(`chunker: token budget ${budget} too small for the fixed prompt overhead ${overhead} (06-llm-assist.md §4.5).`);
|
|
221
|
+
}
|
|
222
|
+
const splitCapacity = Math.max(1, Math.floor(tableCapacity * (1 - SPLIT_STUB_RESERVE_RATIO)));
|
|
223
|
+
const tableWeight = computeTableWeights(input);
|
|
224
|
+
const weightOf = (id) => tableWeight.get(id) ?? 0;
|
|
225
|
+
const clusterWeight = (cluster) => cluster.reduce((sum, id) => sum + weightOf(id), 0);
|
|
226
|
+
const modelOrder = new Map(model.tables.map((table, index) => [table.id, index]));
|
|
227
|
+
const orderOf = (id) => modelOrder.get(id) ?? Number.MAX_SAFE_INTEGER;
|
|
228
|
+
const rowCount = rowCountLookup(model, input.stats);
|
|
229
|
+
const clusters = clusterTables(model);
|
|
230
|
+
const normal = [];
|
|
231
|
+
const oversized = [];
|
|
232
|
+
for (const cluster of clusters) {
|
|
233
|
+
if (clusterWeight(cluster) <= tableCapacity)
|
|
234
|
+
normal.push(cluster);
|
|
235
|
+
else
|
|
236
|
+
oversized.push(cluster);
|
|
237
|
+
}
|
|
238
|
+
// First-fit-decreasing over whole clusters (no cross-chunk FKs possible).
|
|
239
|
+
normal.sort((a, b) => clusterWeight(b) - clusterWeight(a) || (a[0] ?? '').localeCompare(b[0] ?? ''));
|
|
240
|
+
const ffdBins = [];
|
|
241
|
+
const ffdLoads = [];
|
|
242
|
+
for (const cluster of normal) {
|
|
243
|
+
const weight = clusterWeight(cluster);
|
|
244
|
+
let placed = false;
|
|
245
|
+
for (let i = 0; i < ffdBins.length; i += 1) {
|
|
246
|
+
if ((ffdLoads[i] ?? 0) + weight <= tableCapacity) {
|
|
247
|
+
ffdBins[i]?.push(...cluster);
|
|
248
|
+
ffdLoads[i] = (ffdLoads[i] ?? 0) + weight;
|
|
249
|
+
placed = true;
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (!placed) {
|
|
254
|
+
ffdBins.push([...cluster]);
|
|
255
|
+
ffdLoads.push(weight);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
// Split each oversized cluster by row-count descending (last resort, §4.5).
|
|
259
|
+
const splitBins = [];
|
|
260
|
+
oversized.sort((a, b) => (a[0] ?? '').localeCompare(b[0] ?? ''));
|
|
261
|
+
for (const cluster of oversized) {
|
|
262
|
+
const ordered = [...cluster].sort((a, b) => rowCount(b) - rowCount(a) || a.localeCompare(b));
|
|
263
|
+
let current = [];
|
|
264
|
+
let load = 0;
|
|
265
|
+
for (const id of ordered) {
|
|
266
|
+
const weight = weightOf(id);
|
|
267
|
+
if (current.length > 0 && load + weight > splitCapacity) {
|
|
268
|
+
splitBins.push(current);
|
|
269
|
+
current = [];
|
|
270
|
+
load = 0;
|
|
271
|
+
}
|
|
272
|
+
current.push(id);
|
|
273
|
+
load += weight;
|
|
274
|
+
}
|
|
275
|
+
if (current.length > 0)
|
|
276
|
+
splitBins.push(current);
|
|
277
|
+
}
|
|
278
|
+
const bins = [...ffdBins, ...splitBins];
|
|
279
|
+
const total = bins.length;
|
|
280
|
+
return bins.map((bin, index) => {
|
|
281
|
+
const fullSet = new Set(bin);
|
|
282
|
+
const stubs = computeStubsForChunk(model, fullSet);
|
|
283
|
+
return {
|
|
284
|
+
index: index + 1,
|
|
285
|
+
total,
|
|
286
|
+
tableIds: [...bin].sort((a, b) => orderOf(a) - orderOf(b)),
|
|
287
|
+
stubTables: [...stubs].sort((a, b) => a.localeCompare(b)),
|
|
288
|
+
};
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
function rowCountLookup(model, stats) {
|
|
292
|
+
const counts = new Map();
|
|
293
|
+
for (const table of model.tables) {
|
|
294
|
+
if (table.rowCountEstimate !== null)
|
|
295
|
+
counts.set(table.id, table.rowCountEstimate);
|
|
296
|
+
}
|
|
297
|
+
for (const result of stats) {
|
|
298
|
+
if (result.rowCountEstimate !== null) {
|
|
299
|
+
counts.set(qualifyTableRef(result.table, model.defaultSchema), result.rowCountEstimate);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return (id) => counts.get(id) ?? 0;
|
|
303
|
+
}
|
|
304
|
+
// ─── Building the map-phase prompts ──────────────────────────────────────────
|
|
305
|
+
/**
|
|
306
|
+
* Build a self-contained sub-model for one chunk: its full tables plus its stub
|
|
307
|
+
* tables (rendered names-only by the serializer via the chunk's `stubTables`
|
|
308
|
+
* set), with enums narrowed to those the full tables reference and relations
|
|
309
|
+
* narrowed to those the chunk owns (`from` in the chunk, `to`/`through` present
|
|
310
|
+
* as full or stub).
|
|
311
|
+
*/
|
|
312
|
+
export function subModelForChunk(model, fullTables, stubTables) {
|
|
313
|
+
const keptTables = model.tables.filter((table) => fullTables.has(table.id) || stubTables.has(table.id));
|
|
314
|
+
const referencedEnums = new Set();
|
|
315
|
+
for (const table of model.tables) {
|
|
316
|
+
if (!fullTables.has(table.id))
|
|
317
|
+
continue;
|
|
318
|
+
for (const column of table.columns) {
|
|
319
|
+
if (column.enumRef !== null)
|
|
320
|
+
referencedEnums.add(column.enumRef);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
const keptEnums = model.enums.filter((def) => referencedEnums.has(def.id));
|
|
324
|
+
const present = (id) => fullTables.has(id) || stubTables.has(id);
|
|
325
|
+
const keptRelations = model.relations.filter((relation) => fullTables.has(relation.from.tableId) &&
|
|
326
|
+
present(relation.to.tableId) &&
|
|
327
|
+
(relation.through === null || present(relation.through.tableId)));
|
|
328
|
+
return { ...model, tables: keptTables, enums: keptEnums, relations: keptRelations };
|
|
329
|
+
}
|
|
330
|
+
function statsForChunk(stats, fullTables, defaultSchema) {
|
|
331
|
+
return stats.filter((result) => fullTables.has(qualifyTableRef(result.table, defaultSchema)));
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Build the map-phase prompt(s) for a schema. Split ONLY when the assembled user
|
|
335
|
+
* section exceeds the per-prompt `tokenBudget` (default 60,000 — §4.5); a schema
|
|
336
|
+
* that fits in one prompt is returned unchunked (no stubs, no chunk-info
|
|
337
|
+
* sentence) even when it is larger than the 45,000-token per-chunk packing
|
|
338
|
+
* ceiling. When it does not fit, it is chunked per {@link planSchemaChunks}, each
|
|
339
|
+
* chunk a self-contained prompt with correct FK stubs and each within
|
|
340
|
+
* `chunkTokenBudget`.
|
|
341
|
+
*/
|
|
342
|
+
export function buildChunkedPrompts(input, options) {
|
|
343
|
+
const model = input.schemaIr;
|
|
344
|
+
const sections = normalizeSections(input.sections);
|
|
345
|
+
// Split decision: the 60k tokenBudget (§4.5), NOT the 45k per-chunk ceiling.
|
|
346
|
+
// `buildPrompt.overBudget` measures the assembled user section against
|
|
347
|
+
// `options.tokenBudget` (default DEFAULT_TOKEN_BUDGET = 60k) — exactly the
|
|
348
|
+
// "assembled user section exceeds budget" test §4.5 specifies.
|
|
349
|
+
const whole = buildPrompt(input, options);
|
|
350
|
+
if (!whole.overBudget) {
|
|
351
|
+
return {
|
|
352
|
+
chunked: false,
|
|
353
|
+
chunks: whole.chunks,
|
|
354
|
+
plan: [
|
|
355
|
+
{
|
|
356
|
+
index: 1,
|
|
357
|
+
total: 1,
|
|
358
|
+
tableIds: model.tables.map((table) => table.id),
|
|
359
|
+
stubTables: [],
|
|
360
|
+
},
|
|
361
|
+
],
|
|
362
|
+
sections,
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
const plan = planSchemaChunks(input, options);
|
|
366
|
+
const chunks = plan.map((chunk) => {
|
|
367
|
+
const fullSet = new Set(chunk.tableIds);
|
|
368
|
+
const stubSet = new Set(chunk.stubTables);
|
|
369
|
+
const artifact = buildPrompt({
|
|
370
|
+
...input,
|
|
371
|
+
schemaIr: subModelForChunk(model, fullSet, stubSet),
|
|
372
|
+
stats: statsForChunk(input.stats, fullSet, model.defaultSchema),
|
|
373
|
+
chunk: { index: chunk.index, total: chunk.total, stubTables: chunk.stubTables },
|
|
374
|
+
}, options);
|
|
375
|
+
const built = artifact.chunks[0];
|
|
376
|
+
if (built === undefined) {
|
|
377
|
+
throw new Error('chunker: buildPrompt produced no chunk artifact.');
|
|
378
|
+
}
|
|
379
|
+
return built;
|
|
380
|
+
});
|
|
381
|
+
return { chunked: true, chunks, plan, sections };
|
|
382
|
+
}
|
|
383
|
+
//# sourceMappingURL=chunker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunker.js","sourceRoot":"","sources":["../../src/prompt/chunker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAGtD,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EACL,eAAe,EACf,wBAAwB,EACxB,iBAAiB,EACjB,cAAc,GACf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAQrD,mEAAmE;AACnE,MAAM,CAAC,MAAM,0BAA0B,GAAG,MAAM,CAAC;AAEjD;;;;;GAKG;AACH,MAAM,aAAa,GAAG,GAAG,CAAC;AAE1B;;;;;;;;GAQG;AACH,MAAM,wBAAwB,GAAG,GAAG,CAAC;AA+BrC,gFAAgF;AAEhF,SAAS,SAAS,CAAC,GAA6B,EAAE,E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CAAC;QACxC,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC1C,MAAM,QAAQ,GAAG,WAAW,CAC1B;YACE,GAAG,KAAK;YACR,QAAQ,EAAE,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC;YACnD,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,aAAa,CAAC;YAC/D,KAAK,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,EAAE;SAChF,EACD,OAAO,CACR,CAAC;QACF,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACjC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;QACtE,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;IAEH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@adminium/llm` prompt-builder barrel — 06-llm-assist.md §4, §5.
|
|
3
|
+
*
|
|
4
|
+
* `buildPrompt` is the single producer of prompt text shared by the direct-API
|
|
5
|
+
* and BYO paths. `PROMPT_VERSION` / `SCHEMA_VERSION` are intentionally NOT
|
|
6
|
+
* re-exported here — the `response/` barrel owns them.
|
|
7
|
+
*/
|
|
8
|
+
export * from './types.js';
|
|
9
|
+
export * from './token-estimate.js';
|
|
10
|
+
export * from './serializer.js';
|
|
11
|
+
export * from './templates/v1.js';
|
|
12
|
+
export * from './builder.js';
|
|
13
|
+
export * from './chunker.js';
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/prompt/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@adminium/llm` prompt-builder barrel — 06-llm-assist.md §4, §5.
|
|
3
|
+
*
|
|
4
|
+
* `buildPrompt` is the single producer of prompt text shared by the direct-API
|
|
5
|
+
* and BYO paths. `PROMPT_VERSION` / `SCHEMA_VERSION` are intentionally NOT
|
|
6
|
+
* re-exported here — the `response/` barrel owns them.
|
|
7
|
+
*/
|
|
8
|
+
export * from './types.js';
|
|
9
|
+
export * from './token-estimate.js';
|
|
10
|
+
export * from './serializer.js';
|
|
11
|
+
export * from './templates/v1.js';
|
|
12
|
+
export * from './builder.js';
|
|
13
|
+
export * from './chunker.js';
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/prompt/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema IR + statistics serialization for the prompt (06-llm-assist.md §4.1,
|
|
3
|
+
* §4.2, §5.2).
|
|
4
|
+
*
|
|
5
|
+
* Three producers, mapping onto the three `=== INPUT: … ===` blocks of the user
|
|
6
|
+
* section:
|
|
7
|
+
* - {@link serializeSchemaIr} → `{{SCHEMA_IR_JSON}}` (structure only)
|
|
8
|
+
* - {@link serializeStats} → `{{STATS_JSON}}` (aggregates only)
|
|
9
|
+
* - {@link serializeSampling} → `{{SAMPLING_BLOCK}}` (opt-in cell values)
|
|
10
|
+
*
|
|
11
|
+
* SAMPLE-FREE BY DEFAULT (§1 invariant 5, acceptance criterion 8): with sampling
|
|
12
|
+
* off, NO cell value from any table can appear. The schema IR carries only
|
|
13
|
+
* structure (types, flags, DECLARED enum values — which are schema, not data);
|
|
14
|
+
* the stats block carries only row counts, null fractions and distinct counts —
|
|
15
|
+
* it NEVER copies `min`/`max`/`sampleValues` off a `StatsResult`. Cell values
|
|
16
|
+
* live exclusively in the sampling block, which is empty unless the caller opts
|
|
17
|
+
* in, and even then excludes PII-suspected and secret columns.
|
|
18
|
+
*
|
|
19
|
+
* Deterministic: objects are built in a fixed key order and arrays follow input
|
|
20
|
+
* order, so `JSON.stringify` output is stable (no sorting, no timestamps).
|
|
21
|
+
*/
|
|
22
|
+
import type { Cardinality, DatabaseModel, Dialect, LogicalType, StatsResult, StatsScalar, TableRef, TableRole } from '@adminium/engine';
|
|
23
|
+
import type { Sampling } from './types.js';
|
|
24
|
+
/** Text columns with `distinctCount` at or below this are pseudo-enum candidates (§4.2). */
|
|
25
|
+
export declare const PSEUDO_ENUM_MAX_DISTINCT = 24;
|
|
26
|
+
/** Header line the opt-in sampling block leads with (§5.2 builder note). */
|
|
27
|
+
export declare const SAMPLING_BLOCK_HEADER = "=== INPUT: SAMPLE VALUES (user opted in; PII columns excluded) ===";
|
|
28
|
+
export interface SerializedColumn {
|
|
29
|
+
column: string;
|
|
30
|
+
type: LogicalType;
|
|
31
|
+
nullable: boolean;
|
|
32
|
+
primaryKey?: true;
|
|
33
|
+
unique?: true;
|
|
34
|
+
/** `EnumDef.id` when the column is enum-typed (values listed under `enumColumns`). */
|
|
35
|
+
enum?: string;
|
|
36
|
+
/** Declared FK target as `"schema.table.column"`. */
|
|
37
|
+
references?: string;
|
|
38
|
+
/** Heuristic PII suspicion — the model confirms/rejects (§4.2, decision 8). */
|
|
39
|
+
piiSuspected?: true;
|
|
40
|
+
/** Secret column — never contributes any value-touching statistic. */
|
|
41
|
+
secret?: true;
|
|
42
|
+
/** Low-cardinality non-PII text: values sent only under sampling opt-in (§4.2). */
|
|
43
|
+
pseudoEnumCandidate?: true;
|
|
44
|
+
}
|
|
45
|
+
export interface SerializedFullTable {
|
|
46
|
+
table: string;
|
|
47
|
+
role?: TableRole;
|
|
48
|
+
columns: SerializedColumn[];
|
|
49
|
+
}
|
|
50
|
+
/** Out-of-chunk FK target: names only, no suggestions requested (§4.5). */
|
|
51
|
+
export interface SerializedStubTable {
|
|
52
|
+
table: string;
|
|
53
|
+
stub: true;
|
|
54
|
+
columns: string[];
|
|
55
|
+
}
|
|
56
|
+
export type SerializedTable = SerializedFullTable | SerializedStubTable;
|
|
57
|
+
export interface SerializedEnumColumn {
|
|
58
|
+
table: string;
|
|
59
|
+
column: string;
|
|
60
|
+
values: string[];
|
|
61
|
+
}
|
|
62
|
+
export interface SerializedDeclaredRelation {
|
|
63
|
+
fromTable: string;
|
|
64
|
+
fromColumns: string[];
|
|
65
|
+
toTable: string;
|
|
66
|
+
toColumns: string[];
|
|
67
|
+
cardinality: Cardinality;
|
|
68
|
+
}
|
|
69
|
+
export interface SerializedSchemaIr {
|
|
70
|
+
database: {
|
|
71
|
+
name: string;
|
|
72
|
+
dialect: Dialect;
|
|
73
|
+
defaultSchema: string;
|
|
74
|
+
};
|
|
75
|
+
tables: SerializedTable[];
|
|
76
|
+
enumColumns: SerializedEnumColumn[];
|
|
77
|
+
declaredRelations: SerializedDeclaredRelation[];
|
|
78
|
+
}
|
|
79
|
+
export interface SerializedColumnStats {
|
|
80
|
+
column: string;
|
|
81
|
+
nullFraction: number | null;
|
|
82
|
+
distinctCount: number | null;
|
|
83
|
+
}
|
|
84
|
+
export interface SerializedTableStats {
|
|
85
|
+
table: string;
|
|
86
|
+
rowCountEstimate: number | null;
|
|
87
|
+
rowCountExact: boolean;
|
|
88
|
+
columns: SerializedColumnStats[];
|
|
89
|
+
}
|
|
90
|
+
export interface SerializedStats {
|
|
91
|
+
tables: SerializedTableStats[];
|
|
92
|
+
}
|
|
93
|
+
export interface SerializedSampleColumn {
|
|
94
|
+
column: string;
|
|
95
|
+
min?: StatsScalar;
|
|
96
|
+
max?: StatsScalar;
|
|
97
|
+
sampleValues?: StatsScalar[];
|
|
98
|
+
}
|
|
99
|
+
export interface SerializedSampleTable {
|
|
100
|
+
table: string;
|
|
101
|
+
columns: SerializedSampleColumn[];
|
|
102
|
+
}
|
|
103
|
+
export interface SerializedSampling {
|
|
104
|
+
tables: SerializedSampleTable[];
|
|
105
|
+
}
|
|
106
|
+
/** Compact, deterministic JSON for injection into the prompt. */
|
|
107
|
+
export declare function toPromptJson(value: unknown): string;
|
|
108
|
+
/** `TableRef` → the model's qualified `"schema.table"` id (mysql/sqlite have a null schema). */
|
|
109
|
+
export declare function qualifyTableRef(ref: TableRef, defaultSchema: string): string;
|
|
110
|
+
export interface SerializeSchemaIrOptions {
|
|
111
|
+
/** Qualified ids to render as `"stub": true` context (§4.5). */
|
|
112
|
+
stubTables?: ReadonlySet<string>;
|
|
113
|
+
/** Stats used solely to compute `pseudoEnumCandidate` (distinct-count driven). */
|
|
114
|
+
stats?: readonly StatsResult[];
|
|
115
|
+
}
|
|
116
|
+
export declare function serializeSchemaIr(model: DatabaseModel, options?: SerializeSchemaIrOptions): SerializedSchemaIr;
|
|
117
|
+
export interface SerializeStatsOptions {
|
|
118
|
+
/** Qualified-id fallback schema for null-schema dialects. Defaults to `"public"`. */
|
|
119
|
+
defaultSchema?: string;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Format `StatsResult[]` into the aggregates-only stats block. Deliberately
|
|
123
|
+
* copies ONLY row counts, null fractions and distinct counts — never `min`,
|
|
124
|
+
* `max` or `sampleValues`, which are cell values and belong to the opt-in
|
|
125
|
+
* sampling block. This is what guarantees the sample-free default at the stats
|
|
126
|
+
* layer regardless of what the adapter happened to collect.
|
|
127
|
+
*/
|
|
128
|
+
export declare function serializeStats(stats: readonly StatsResult[], options?: SerializeStatsOptions): SerializedStats;
|
|
129
|
+
/**
|
|
130
|
+
* Build the `{{SAMPLING_BLOCK}}` text. Returns `''` when `sampling` is null
|
|
131
|
+
* (sample-free default). When opted in, renders the header plus a JSON object of
|
|
132
|
+
* per-column `min`/`max`/`sampleValues` — EXCLUDING every PII-suspected or
|
|
133
|
+
* secret column (looked up from the model), and truncating each column's value
|
|
134
|
+
* list to `sampling.maxValuesPerColumn`.
|
|
135
|
+
*/
|
|
136
|
+
export declare function serializeSampling(model: DatabaseModel, stats: readonly StatsResult[], sampling: Sampling): string;
|
|
137
|
+
export declare function serializeSamplingPayload(model: DatabaseModel, stats: readonly StatsResult[], maxValuesPerColumn: number): SerializedSampling;
|
|
138
|
+
//# sourceMappingURL=serializer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializer.d.ts","sourceRoot":"","sources":["../../src/prompt/serializer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,EACV,WAAW,EAEX,aAAa,EACb,OAAO,EACP,WAAW,EACX,WAAW,EACX,WAAW,EACX,QAAQ,EACR,SAAS,EACV,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,4FAA4F;AAC5F,eAAO,MAAM,wBAAwB,KAAK,CAAC;AAE3C,4EAA4E;AAC5E,eAAO,MAAM,qBAAqB,uEACoC,CAAC;AAIvE,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,WAAW,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,IAAI,CAAC;IAClB,MAAM,CAAC,EAAE,IAAI,CAAC;IACd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