@konneal/engine 0.2.175 → 0.2.177
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ablate.d.ts +9 -4
- package/dist/{ask-7TNQCRD6.js → ask-2UHDJPEU.js} +3 -3
- package/dist/{certificates-F5G7GRWK.js → certificates-QHFH2KLH.js} +5 -1
- package/dist/certificates.d.ts +17 -0
- package/dist/{chunk-ECOYO7EX.js → chunk-JKBU2IPM.js} +27 -4
- package/dist/{chunk-ZZLUGHZ2.js → chunk-K4IEKILQ.js} +12 -9
- package/dist/{chunk-B2MU4ZWM.js → chunk-RO5LNSPH.js} +1 -1
- package/dist/pipeline.d.ts +4 -3
- package/dist/{tools-VHN54DWH.js → tools-DKQZGSWK.js} +1 -1
- package/dist/worker_public/src/index.js +5 -5
- package/package.json +1 -1
- package/workers/worker_public/src/ablate.ts +12 -6
- package/workers/worker_public/src/ask.ts +7 -6
- package/workers/worker_public/src/certificates.ts +44 -4
- package/workers/worker_public/src/pipeline.ts +4 -3
package/dist/ablate.d.ts
CHANGED
|
@@ -13,11 +13,16 @@ export interface AblateConfig {
|
|
|
13
13
|
* diversified subset + one strong verifier. Off in serving until the
|
|
14
14
|
* gate promotes it; the grid arms it per ask. */
|
|
15
15
|
speculative: boolean;
|
|
16
|
-
/** Extractive prompt compression (TODO.sota/02 row 5):
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
16
|
+
/** Extractive prompt compression (TODO.sota/02 row 5): PROMOTED — the
|
|
17
|
+
* passage bodies are query-weighted sentence selection at a fraction
|
|
18
|
+
* of their budget in serving (the row's gate: identical accuracy at
|
|
19
|
+
* ~1/20th the prompt, the whole-document baseline measured it).
|
|
20
|
+
* ablate_compress survives for the grid's explicit arm;
|
|
21
|
+
* ablate_no_compress is the measurement stand-down. */
|
|
20
22
|
compress: boolean;
|
|
23
|
+
/** Per-request stand-down for the promoted compressor (the
|
|
24
|
+
* measurement arm; the serving default is on). */
|
|
25
|
+
noCompress: boolean;
|
|
21
26
|
/** The decision pass (TODO.decisions/01): per-request stand-down for
|
|
22
27
|
* the measurement — the serving switch is DECISIONS_ENABLED. */
|
|
23
28
|
noDecisions: boolean;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
handleAsk
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-K4IEKILQ.js";
|
|
4
|
+
import "./chunk-JKBU2IPM.js";
|
|
5
|
+
import "./chunk-RO5LNSPH.js";
|
|
6
6
|
import "./chunk-CLDMP5YH.js";
|
|
7
7
|
import "./chunk-ZHT4456M.js";
|
|
8
8
|
import "./chunk-D7MO4RVQ.js";
|
|
@@ -6,12 +6,14 @@ import {
|
|
|
6
6
|
isRegisterShaped,
|
|
7
7
|
printedCertificateNumber,
|
|
8
8
|
queryFamily,
|
|
9
|
+
rankRegisterRows,
|
|
9
10
|
registerAggregate,
|
|
10
11
|
registerAggregateIntent,
|
|
12
|
+
registerBypassesCache,
|
|
11
13
|
registerNote,
|
|
12
14
|
registerTokens,
|
|
13
15
|
searchRegister
|
|
14
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-JKBU2IPM.js";
|
|
15
17
|
import "./chunk-3FYJM7LH.js";
|
|
16
18
|
export {
|
|
17
19
|
aggregateBlock,
|
|
@@ -21,8 +23,10 @@ export {
|
|
|
21
23
|
isRegisterShaped,
|
|
22
24
|
printedCertificateNumber,
|
|
23
25
|
queryFamily,
|
|
26
|
+
rankRegisterRows,
|
|
24
27
|
registerAggregate,
|
|
25
28
|
registerAggregateIntent,
|
|
29
|
+
registerBypassesCache,
|
|
26
30
|
registerNote,
|
|
27
31
|
registerTokens,
|
|
28
32
|
searchRegister
|
package/dist/certificates.d.ts
CHANGED
|
@@ -20,6 +20,14 @@ export declare function isRegisterShaped(query: string): boolean;
|
|
|
20
20
|
* narrates it (TODO.sota/04's machine-checkable ground truth, applied
|
|
21
21
|
* to the register plane 2026-10-11). */
|
|
22
22
|
export declare function registerAggregateIntent(query: string): "count" | "latest" | null;
|
|
23
|
+
/** The register's answers derive from the D1 snapshot, not the indexed
|
|
24
|
+
* corpus — but the answer cache (namespaced by INDEX_VERSION +
|
|
25
|
+
* corpus_gen) knows nothing about D1-plane loads, so a cached
|
|
26
|
+
* pre-register refusal preempted register-shaped questions the register
|
|
27
|
+
* answers (measured live 2026-10-28: cached refusals served over
|
|
28
|
+
* register-shaped asks until fresh). Such asks skip both cache reads
|
|
29
|
+
* and writes. */
|
|
30
|
+
export declare function registerBypassesCache(query: string): boolean;
|
|
23
31
|
export interface RegisterAggregate {
|
|
24
32
|
family: string;
|
|
25
33
|
count: number;
|
|
@@ -84,6 +92,15 @@ export declare function searchRegister(db: any, query: string, force?: boolean):
|
|
|
84
92
|
rows: RegisterRow[];
|
|
85
93
|
tokens: string[];
|
|
86
94
|
} | null>;
|
|
95
|
+
/** Rank the OR-matched candidates so the note's six rows carry the
|
|
96
|
+
* QUESTION's model, not just its holder: the live probes showed a
|
|
97
|
+
* distinctive model token losing its place to generic holder words
|
|
98
|
+
* ("Rice Lake Weighing Systems" matched 6 rows before "RL116XP" was
|
|
99
|
+
* ever consulted — the answer then denied a certificate the register
|
|
100
|
+
* holds). A model-token hit outranks a holder-token hit; numbers must
|
|
101
|
+
* match as standalone values (the "190 must not catch XK3190" rule).
|
|
102
|
+
* Measured 2026-10-28, the register-lane eval. */
|
|
103
|
+
export declare function rankRegisterRows(rows: RegisterRow[], tokens: string[]): RegisterRow[];
|
|
87
104
|
export declare function registerNote(rows: RegisterRow[]): string;
|
|
88
105
|
/** Each certificate's location rides the note as a link when its PDF
|
|
89
106
|
* is in the R2 plane (TODO 7) — the user gets the document, not just
|
|
@@ -12,6 +12,9 @@ function registerAggregateIntent(query) {
|
|
|
12
12
|
if (/\b(how many|count|number of|total|how much)\b/i.test(query)) return "count";
|
|
13
13
|
return null;
|
|
14
14
|
}
|
|
15
|
+
function registerBypassesCache(query) {
|
|
16
|
+
return isRegisterShaped(query) || registerAggregateIntent(query) !== null;
|
|
17
|
+
}
|
|
15
18
|
async function registerAggregate(db, family) {
|
|
16
19
|
try {
|
|
17
20
|
const digits = family.replace(/^[A-Za-z]+/, "");
|
|
@@ -156,7 +159,7 @@ function buildRegisterQuery(tokens) {
|
|
|
156
159
|
return `(holder LIKE ?${n} OR model LIKE ?${n} OR num LIKE ?${n})`;
|
|
157
160
|
});
|
|
158
161
|
return {
|
|
159
|
-
sql: `SELECT num, family, holder, model, year, status, pdf_key FROM certificates WHERE family = ?FAMILY AND (${clauses.join(" OR ")}) LIMIT
|
|
162
|
+
sql: `SELECT num, family, holder, model, year, status, pdf_key FROM certificates WHERE family = ?FAMILY AND (${clauses.join(" OR ")}) LIMIT 40`,
|
|
160
163
|
params
|
|
161
164
|
};
|
|
162
165
|
}
|
|
@@ -190,18 +193,36 @@ async function searchRegister(db, query, force = false) {
|
|
|
190
193
|
}
|
|
191
194
|
try {
|
|
192
195
|
const res = await db.prepare(sql).bind(...params).all();
|
|
193
|
-
|
|
196
|
+
const rows = rankRegisterRows(res.results ?? [], tokens);
|
|
197
|
+
return { rows, tokens };
|
|
194
198
|
} catch {
|
|
195
199
|
return { rows: [], tokens };
|
|
196
200
|
}
|
|
197
201
|
}
|
|
202
|
+
function rankRegisterRows(rows, tokens) {
|
|
203
|
+
const score = (row) => {
|
|
204
|
+
const model = (row.model || "").toLowerCase();
|
|
205
|
+
const holder = (row.holder || "").toLowerCase();
|
|
206
|
+
let s = 0;
|
|
207
|
+
for (const t of tokens) {
|
|
208
|
+
const tl = t.toLowerCase();
|
|
209
|
+
if (/^\d+$/.test(t)) {
|
|
210
|
+
if (new RegExp(`(^|[^a-z0-9])${tl}([^a-z0-9]|$)`).test(model)) s += 3;
|
|
211
|
+
else if (holder.includes(tl)) s += 1;
|
|
212
|
+
} else if (model.includes(tl)) s += 2;
|
|
213
|
+
else if (holder.includes(tl)) s += 1;
|
|
214
|
+
}
|
|
215
|
+
return s;
|
|
216
|
+
};
|
|
217
|
+
return [...rows].sort((a, b) => score(b) - score(a) || Number(b.year) - Number(a.year)).slice(0, 6);
|
|
218
|
+
}
|
|
198
219
|
function registerNote(rows) {
|
|
199
220
|
if (!rows.length) {
|
|
200
|
-
return `Certificate register
|
|
221
|
+
return `Certificate register \u2014 THIS NOTE ANSWERS THE QUESTION. NO certificate matching the asked holder or model appears in the ${P().publisher.name}-CS register snapshot. Answer from THIS note: state plainly that no such certificate is in this register \u2014 never fall back to the indexed publications' absence phrasing \u2014 and say the register is a snapshot rather than the live certification status.`;
|
|
201
222
|
}
|
|
202
223
|
const lines = rows.map((r) => `- ${r.num}: holder ${r.holder}, model "${r.model}"${r.year ? `, issued ${r.year}` : ""} \u2014 status ${r.status}`);
|
|
203
224
|
return [
|
|
204
|
-
"Certificate register \u2014
|
|
225
|
+
"Certificate register \u2014 THIS NOTE ANSWERS THE QUESTION. The following certificates matched the asked holder or model; answer from THIS note. A model the note does not list is not among the matched rows \u2014 say so plainly instead of falling back to the indexed publications. Quote the certificate number, the holder and the status verbatim; the register is a snapshot, so qualify any statement about current certification accordingly.",
|
|
205
226
|
...lines
|
|
206
227
|
].join("\n");
|
|
207
228
|
}
|
|
@@ -219,6 +240,7 @@ ${absent.join("\n")}`);
|
|
|
219
240
|
export {
|
|
220
241
|
isRegisterShaped,
|
|
221
242
|
registerAggregateIntent,
|
|
243
|
+
registerBypassesCache,
|
|
222
244
|
registerAggregate,
|
|
223
245
|
aggregateNote,
|
|
224
246
|
aggregateBlock,
|
|
@@ -227,6 +249,7 @@ export {
|
|
|
227
249
|
registerTokens,
|
|
228
250
|
buildRegisterQuery,
|
|
229
251
|
searchRegister,
|
|
252
|
+
rankRegisterRows,
|
|
230
253
|
registerNote,
|
|
231
254
|
certificateLinks
|
|
232
255
|
};
|
|
@@ -5,9 +5,10 @@ import {
|
|
|
5
5
|
queryFamily,
|
|
6
6
|
registerAggregate,
|
|
7
7
|
registerAggregateIntent,
|
|
8
|
+
registerBypassesCache,
|
|
8
9
|
registerNote,
|
|
9
10
|
searchRegister
|
|
10
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-JKBU2IPM.js";
|
|
11
12
|
import {
|
|
12
13
|
TOOL_DECLARATION,
|
|
13
14
|
bindConstraintByQuantities,
|
|
@@ -32,7 +33,7 @@ import {
|
|
|
32
33
|
tableRetyped,
|
|
33
34
|
toolNote,
|
|
34
35
|
verdictNote
|
|
35
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-RO5LNSPH.js";
|
|
36
37
|
import {
|
|
37
38
|
NO_CONTEXT,
|
|
38
39
|
STAGE_NAMES,
|
|
@@ -1404,10 +1405,11 @@ function parseAblate(body, adminToken, presentedToken, knownStages) {
|
|
|
1404
1405
|
const rawRoute = body?.ablate_route;
|
|
1405
1406
|
const speculative = body?.ablate_speculative === true;
|
|
1406
1407
|
const compress = body?.ablate_compress === true;
|
|
1408
|
+
const noCompress = body?.ablate_no_compress === true;
|
|
1407
1409
|
const noDecisions = body?.ablate_no_decisions === true;
|
|
1408
1410
|
const namesAblation = rawStages !== void 0 && rawStages !== null;
|
|
1409
1411
|
const routeAblation = rawRoute !== void 0 && rawRoute !== null && rawRoute !== "adaptive";
|
|
1410
|
-
if (!namesAblation && !noVerdict && !routeAblation && !speculative && !compress && !noDecisions) return { ok: true, config: null };
|
|
1412
|
+
if (!namesAblation && !noVerdict && !routeAblation && !speculative && !compress && !noCompress && !noDecisions) return { ok: true, config: null };
|
|
1411
1413
|
if (!adminToken || presentedToken !== adminToken) {
|
|
1412
1414
|
return {
|
|
1413
1415
|
ok: false,
|
|
@@ -1438,7 +1440,7 @@ function parseAblate(body, adminToken, presentedToken, knownStages) {
|
|
|
1438
1440
|
}
|
|
1439
1441
|
stages = [...new Set(rawStages)];
|
|
1440
1442
|
}
|
|
1441
|
-
return { ok: true, config: { stages, noVerdict, route, speculative, compress, noDecisions } };
|
|
1443
|
+
return { ok: true, config: { stages, noVerdict, route, speculative, compress, noCompress, noDecisions } };
|
|
1442
1444
|
}
|
|
1443
1445
|
|
|
1444
1446
|
// workers/worker_public/src/decisions.ts
|
|
@@ -2220,7 +2222,8 @@ async function handleAsk(env, ctx, req, tier, key) {
|
|
|
2220
2222
|
const multiTurn = body?.multi_turn !== false;
|
|
2221
2223
|
const gen = await corpusGen(env.CACHE);
|
|
2222
2224
|
const withImage = effectiveImage || storedImage;
|
|
2223
|
-
const
|
|
2225
|
+
const registerBypass = registerBypassesCache(q.query);
|
|
2226
|
+
const cached = fresh || contextual || declaredCtx || draftAct || apiCallIntent || withImage || ablate || registerBypass ? null : await cacheGet(env, gen, ns, q.query, q.lang, salt);
|
|
2224
2227
|
let probeTokensUsed = 0;
|
|
2225
2228
|
const pipeline = async (channel, qq) => {
|
|
2226
2229
|
const live2 = channel;
|
|
@@ -2837,7 +2840,7 @@ Answer account questions from these records ONLY: name the record when you use i
|
|
|
2837
2840
|
[ops.note, processNote, eNote, regNote, contextNote(declaredCtx, docScope), accountNote, modelNote, vocabNote, memNote, machineNote, conditionNote, aggregationNote, boundaryNote, licenseNote, ...retrieved.notes ?? []].filter(Boolean).join("\n") || void 0,
|
|
2838
2841
|
summary,
|
|
2839
2842
|
budget,
|
|
2840
|
-
ablate?.
|
|
2843
|
+
ablate?.noCompress !== true
|
|
2841
2844
|
);
|
|
2842
2845
|
const decisionPromise = decisionsArmed && decisionsGatePromise ? decisionsGatePromise.then((g) => g != null && g >= THRESHOLDS.decisionsGateMin ? runDecisionPass(env, {
|
|
2843
2846
|
question: q2.query,
|
|
@@ -3079,7 +3082,7 @@ Answer account questions from these records ONLY: name the record when you use i
|
|
|
3079
3082
|
} catch {
|
|
3080
3083
|
}
|
|
3081
3084
|
}
|
|
3082
|
-
if (streamed.violations.length === 0 && canonical.length > 0 && !contextual && !declaredCtx && cacheableAnswer(canonical, refusalScope(answerCites(canonical))) && !ablate) {
|
|
3085
|
+
if (streamed.violations.length === 0 && canonical.length > 0 && !contextual && !declaredCtx && !registerBypass && cacheableAnswer(canonical, refusalScope(answerCites(canonical))) && !ablate) {
|
|
3083
3086
|
ctx.waitUntil(
|
|
3084
3087
|
env.CACHE.put(exactCacheKey(env.INDEX_VERSION, gen, ns, await sha256Hex(cacheKeyMaterial(q2.query, q2.lang, salt))), JSON.stringify({ answer: canonical, citations: cites, model, query_hash: queryHash, ...sourceQuality ? { source_quality: sourceQuality, confidence_note: streamedNote || qualityNote(sourceQuality) } : {}, ...streamedEntailment ? { entailment: streamedEntailment } : {} }), { expirationTtl: LIMITS.cacheTtlSec })
|
|
3085
3088
|
);
|
|
@@ -3175,7 +3178,7 @@ Answer account questions from these records ONLY: name the record when you use i
|
|
|
3175
3178
|
...routeSubset ? { stageSubset: routeSubset ?? void 0 } : {}
|
|
3176
3179
|
});
|
|
3177
3180
|
if (retryRetrieve.hits.length > 0) {
|
|
3178
|
-
const { messages: retryMessages, usedHits: retryUsed } = buildMessages(q2.query, retryRetrieve.hits, q2.lang, keptHistory, void 0, summary, budget, ablate?.
|
|
3181
|
+
const { messages: retryMessages, usedHits: retryUsed } = buildMessages(q2.query, retryRetrieve.hits, q2.lang, keptHistory, void 0, summary, budget, ablate?.noCompress !== true);
|
|
3179
3182
|
const retryAnswer = await generateOnce(env, model, retryMessages, routeEffort(routed.route));
|
|
3180
3183
|
if (retryAnswer) {
|
|
3181
3184
|
answer = canonicalRefusal(retryAnswer, refusalScope(answerCites(retryAnswer)));
|
|
@@ -3239,7 +3242,7 @@ Answer account questions from these records ONLY: name the record when you use i
|
|
|
3239
3242
|
telemetryDecisions(env, ctx, tier, queryHash, decisionsOut ?? null, Date.now() - tStart);
|
|
3240
3243
|
}
|
|
3241
3244
|
const out = { answer, citations: finalCites, ...jsonQuality ? { source_quality: jsonQuality, confidence_note: entailmentNote || qualityNote(jsonQuality), ...entailment ? { entailment } : {}, ...jsonQuality === "ocr" ? { experimental_sources: experimentalSourceLabels(finalCites) } : {} } : {}, model: MODELS.member, query_hash: queryHash, follow_ups: refusalShaped(answer, refusalScope(answerCites(answer))) ? [] : understanding?.follow_ups ?? [], blocks: [...c2ns.blocks, ...verdictBlock ? [verdictBlock] : [], ...conditionBlock ? [conditionBlock] : [], ...aggregationBlock ? [aggregationBlock] : [], ...registerBlock ? [registerBlock] : [], ...completionBlocks], context_applied: ctxApplied, ...liveRecords ? { records: liveRecords } : {}, ...decisionsOut ? { decisions: decisionsOut } : {}, ...ablate ? { ablate } : {}, route: { route: routed.route, features: routed.features } };
|
|
3242
|
-
const cacheable = !contextual && !declaredCtx && !ablate && cacheableAnswer(answer, refusalScope(answerCites(answer))) && finalAnchors.violations.length === 0;
|
|
3245
|
+
const cacheable = !contextual && !declaredCtx && !ablate && !registerBypass && cacheableAnswer(answer, refusalScope(answerCites(answer))) && finalAnchors.violations.length === 0;
|
|
3243
3246
|
if (cacheable) {
|
|
3244
3247
|
const ck = exactCacheKey(env.INDEX_VERSION, gen, ns, await sha256Hex(cacheKeyMaterial(q2.query, q2.lang, salt)));
|
|
3245
3248
|
ctx.waitUntil(env.CACHE.put(ck, JSON.stringify(out), { expirationTtl: LIMITS.cacheTtlSec }));
|
|
@@ -1565,7 +1565,7 @@ var certificatesSearch = {
|
|
|
1565
1565
|
handler: async (env, args) => {
|
|
1566
1566
|
const query = String(args?.query ?? "").trim().slice(0, 160);
|
|
1567
1567
|
if (!query) return null;
|
|
1568
|
-
const { searchRegister, registerNote, certificateLinks } = await import("./certificates-
|
|
1568
|
+
const { searchRegister, registerNote, certificateLinks } = await import("./certificates-QHFH2KLH.js");
|
|
1569
1569
|
const reg = await searchRegister(env.DB, query, true);
|
|
1570
1570
|
const output = reg?.rows?.length ? [registerNote(reg.rows), certificateLinks(reg.rows)].filter(Boolean).join("\n") : `No certificate was found for "${query}" in the certificates database (the register snapshot). State this as the search's result, with the searched string visible.`;
|
|
1571
1571
|
return { name: "certificates.search", query, output };
|
package/dist/pipeline.d.ts
CHANGED
|
@@ -51,9 +51,10 @@ export declare function splitHistory(history: HistoryTurn[], budgetTokens: numbe
|
|
|
51
51
|
* incoming order (timeout/parse failure never blocks serving). */
|
|
52
52
|
export declare function listwiseRerank(env: any, model: string, query: string, hits: Hit[]): Promise<Hit[] | null>;
|
|
53
53
|
export declare function buildMessages(query: string, hits: Hit[], lang?: string, history?: HistoryTurn[], retrievalNote?: string, conversationSummary?: string, budgetTokens?: number,
|
|
54
|
-
/** the extractive compression
|
|
55
|
-
*
|
|
56
|
-
*
|
|
54
|
+
/** the extractive compression (TODO.sota/02 row 5): PROMOTED — on in
|
|
55
|
+
* serving; ablate_no_compress stands it down per ask for the
|
|
56
|
+
* measurement. Each passage body becomes query-weighted sentence
|
|
57
|
+
* selection at compressShare of its budget. */
|
|
57
58
|
compress?: boolean): BuiltMessages;
|
|
58
59
|
export declare function citations(hits: Hit[]): {
|
|
59
60
|
doc_id: string;
|
|
@@ -4,13 +4,13 @@ import {
|
|
|
4
4
|
handleMemories,
|
|
5
5
|
scoreFaithfulness,
|
|
6
6
|
scoreJudge
|
|
7
|
-
} from "../../chunk-
|
|
8
|
-
import "../../chunk-
|
|
7
|
+
} from "../../chunk-K4IEKILQ.js";
|
|
8
|
+
import "../../chunk-JKBU2IPM.js";
|
|
9
9
|
import {
|
|
10
10
|
TOOLS_REGISTRY,
|
|
11
11
|
bindModelNode,
|
|
12
12
|
modelGroundingBlock
|
|
13
|
-
} from "../../chunk-
|
|
13
|
+
} from "../../chunk-RO5LNSPH.js";
|
|
14
14
|
import {
|
|
15
15
|
handleSearch
|
|
16
16
|
} from "../../chunk-MUWO2EV6.js";
|
|
@@ -1175,13 +1175,13 @@ async function callToolOnce(env, ctx, _req, tier, key, name, args, t0) {
|
|
|
1175
1175
|
// stream:false forces the JSON lane (anon defaults to SSE)
|
|
1176
1176
|
body: JSON.stringify({ ...args, stream: false })
|
|
1177
1177
|
});
|
|
1178
|
-
const { runTool, TOOLS_REGISTRY: TOOLS_REGISTRY2 } = await import("../../tools-
|
|
1178
|
+
const { runTool, TOOLS_REGISTRY: TOOLS_REGISTRY2 } = await import("../../tools-DKQZGSWK.js");
|
|
1179
1179
|
let payload;
|
|
1180
1180
|
if (TOOLS_REGISTRY2.some((t) => t.name === name && t.audiences.includes("mcp"))) {
|
|
1181
1181
|
const r = await runTool({ ...env, DB: env.DB }, { name, args }, "mcp");
|
|
1182
1182
|
payload = r ? { tool: r.name, query: r.query, result: r.output } : { error: { message: `tool ${name} returned nothing for the given arguments` } };
|
|
1183
1183
|
} else {
|
|
1184
|
-
const res = name === "ask" ? await (await import("../../ask-
|
|
1184
|
+
const res = name === "ask" ? await (await import("../../ask-2UHDJPEU.js")).handleAsk(env, ctx, inner, tier, key) : await (await import("../../search-KNPPTHMG.js")).handleSearch(env, ctx, inner, tier, key);
|
|
1185
1185
|
payload = await res.json().catch(() => ({ error: { message: "tool transport failed", status: res.status } }));
|
|
1186
1186
|
}
|
|
1187
1187
|
telemetry(env, ctx, tier, `mcp:${name}`, null, !payload?.error, JSON.stringify(payload).length, await sha256Hex(`${name}:${JSON.stringify(args ?? {})}`), void 0, void 0, { durationMs: Date.now() - t0 });
|
package/package.json
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"playwright": "^1.62.1",
|
|
28
28
|
"yaml": "^2.9.1"
|
|
29
29
|
},
|
|
30
|
-
"version": "0.2.
|
|
30
|
+
"version": "0.2.177",
|
|
31
31
|
"description": "The Konneal engine: the publisher-agnostic build pipeline and API plane for standards intelligence (retrieval, answer contract, verdicts, evaluation).",
|
|
32
32
|
"license": "BSD-3-Clause",
|
|
33
33
|
"type": "module",
|
|
@@ -34,11 +34,16 @@ export interface AblateConfig {
|
|
|
34
34
|
* diversified subset + one strong verifier. Off in serving until the
|
|
35
35
|
* gate promotes it; the grid arms it per ask. */
|
|
36
36
|
speculative: boolean;
|
|
37
|
-
/** Extractive prompt compression (TODO.sota/02 row 5):
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
37
|
+
/** Extractive prompt compression (TODO.sota/02 row 5): PROMOTED — the
|
|
38
|
+
* passage bodies are query-weighted sentence selection at a fraction
|
|
39
|
+
* of their budget in serving (the row's gate: identical accuracy at
|
|
40
|
+
* ~1/20th the prompt, the whole-document baseline measured it).
|
|
41
|
+
* ablate_compress survives for the grid's explicit arm;
|
|
42
|
+
* ablate_no_compress is the measurement stand-down. */
|
|
41
43
|
compress: boolean;
|
|
44
|
+
/** Per-request stand-down for the promoted compressor (the
|
|
45
|
+
* measurement arm; the serving default is on). */
|
|
46
|
+
noCompress: boolean;
|
|
42
47
|
/** The decision pass (TODO.decisions/01): per-request stand-down for
|
|
43
48
|
* the measurement — the serving switch is DECISIONS_ENABLED. */
|
|
44
49
|
noDecisions: boolean;
|
|
@@ -64,11 +69,12 @@ export function parseAblate(
|
|
|
64
69
|
const rawRoute = body?.ablate_route;
|
|
65
70
|
const speculative = body?.ablate_speculative === true;
|
|
66
71
|
const compress = body?.ablate_compress === true;
|
|
72
|
+
const noCompress = body?.ablate_no_compress === true;
|
|
67
73
|
const noDecisions = body?.ablate_no_decisions === true;
|
|
68
74
|
const namesAblation = rawStages !== undefined && rawStages !== null;
|
|
69
75
|
const routeAblation = rawRoute !== undefined && rawRoute !== null && rawRoute !== "adaptive";
|
|
70
76
|
|
|
71
|
-
if (!namesAblation && !noVerdict && !routeAblation && !speculative && !compress && !noDecisions) return { ok: true, config: null };
|
|
77
|
+
if (!namesAblation && !noVerdict && !routeAblation && !speculative && !compress && !noCompress && !noDecisions) return { ok: true, config: null };
|
|
72
78
|
|
|
73
79
|
if (!adminToken || presentedToken !== adminToken) {
|
|
74
80
|
return {
|
|
@@ -103,5 +109,5 @@ export function parseAblate(
|
|
|
103
109
|
stages = [...new Set(rawStages as string[])];
|
|
104
110
|
}
|
|
105
111
|
|
|
106
|
-
return { ok: true, config: { stages, noVerdict, route, speculative, compress, noDecisions } };
|
|
112
|
+
return { ok: true, config: { stages, noVerdict, route, speculative, compress, noCompress, noDecisions } };
|
|
107
113
|
}
|
|
@@ -46,7 +46,7 @@ export type { Env };
|
|
|
46
46
|
import { json, err, corsHeaders, readJson, validateQuery, type ApiKey } from "./lib/http";
|
|
47
47
|
import { chargeTokens, checkQuota, clientIp, creditBudget, creditEstimate, estimateTokens, telemetry, tokenBudget, usageTotal } from "./quota";
|
|
48
48
|
import { graphExpand, editionNote } from "./graph";
|
|
49
|
-
import { registerNote, searchRegister, certificateLinks, registerAggregateIntent, registerAggregate, aggregateNote, aggregateBlock, queryFamily } from "./certificates";
|
|
49
|
+
import { registerNote, searchRegister, certificateLinks, registerAggregateIntent, registerAggregate, aggregateNote, aggregateBlock, queryFamily, registerBypassesCache } from "./certificates";
|
|
50
50
|
import { TOOL_DECLARATION, parseToolCall, runTool, toolNote } from "./tools";
|
|
51
51
|
import { operationsLane } from "./operations.ts";
|
|
52
52
|
import { extractNameplate, nameplateRegisterQuery } from "./nameplate.ts";
|
|
@@ -594,7 +594,8 @@ async function handleAsk(
|
|
|
594
594
|
// cache.py) and old-generation entries miss (oimlsmart/rag#72)
|
|
595
595
|
const gen = await corpusGen(env.CACHE);
|
|
596
596
|
const withImage = effectiveImage || storedImage;
|
|
597
|
-
const
|
|
597
|
+
const registerBypass = registerBypassesCache(q.query);
|
|
598
|
+
const cached = fresh || contextual || declaredCtx || draftAct || apiCallIntent || withImage || ablate || registerBypass ? null : await cacheGet(env, gen, ns, q.query, q.lang, salt);
|
|
598
599
|
let probeTokensUsed = 0;
|
|
599
600
|
|
|
600
601
|
// THE PIPELINE: one body, two deliveries. Every `return` inside is an
|
|
@@ -1507,7 +1508,7 @@ let convEntities: Array<{ entity: string; kind: string }> = [];
|
|
|
1507
1508
|
[ops.note, processNote, eNote, regNote, contextNote(declaredCtx, docScope), accountNote, modelNote, vocabNote, memNote, machineNote, conditionNote, aggregationNote, boundaryNote, licenseNote, ...(retrieved.notes ?? [])].filter(Boolean).join("\n") || undefined,
|
|
1508
1509
|
summary,
|
|
1509
1510
|
budget,
|
|
1510
|
-
ablate?.
|
|
1511
|
+
ablate?.noCompress !== true,
|
|
1511
1512
|
);
|
|
1512
1513
|
// the decision pass (TODO.decisions/01): starts here so its calls run
|
|
1513
1514
|
// concurrently with generation — the checklist section arrives the
|
|
@@ -1837,7 +1838,7 @@ let convEntities: Array<{ entity: string; kind: string }> = [];
|
|
|
1837
1838
|
} });
|
|
1838
1839
|
} catch { /* the client may have closed; never block the close */ }
|
|
1839
1840
|
}
|
|
1840
|
-
if (streamed.violations.length === 0 && canonical.length > 0 && !contextual && !declaredCtx && cacheableAnswer(canonical, refusalScope(answerCites(canonical))) && !ablate) {
|
|
1841
|
+
if (streamed.violations.length === 0 && canonical.length > 0 && !contextual && !declaredCtx && !registerBypass && cacheableAnswer(canonical, refusalScope(answerCites(canonical))) && !ablate) {
|
|
1841
1842
|
ctx.waitUntil(
|
|
1842
1843
|
env.CACHE.put(exactCacheKey(env.INDEX_VERSION, gen, ns, await sha256Hex(cacheKeyMaterial(q.query, q.lang, salt))), JSON.stringify({ answer: canonical, citations: cites, model, query_hash: queryHash, ...(sourceQuality ? { source_quality: sourceQuality, confidence_note: streamedNote || qualityNote(sourceQuality) } : {}), ...(streamedEntailment ? { entailment: streamedEntailment } : {}) }), { expirationTtl: LIMITS.cacheTtlSec }),
|
|
1843
1844
|
);
|
|
@@ -2005,7 +2006,7 @@ let convEntities: Array<{ entity: string; kind: string }> = [];
|
|
|
2005
2006
|
...(routeSubset ? { stageSubset: routeSubset ?? undefined } : {}),
|
|
2006
2007
|
});
|
|
2007
2008
|
if (retryRetrieve.hits.length > 0) {
|
|
2008
|
-
const { messages: retryMessages, usedHits: retryUsed } = buildMessages(q.query, retryRetrieve.hits, q.lang, keptHistory, undefined, summary, budget, ablate?.
|
|
2009
|
+
const { messages: retryMessages, usedHits: retryUsed } = buildMessages(q.query, retryRetrieve.hits, q.lang, keptHistory, undefined, summary, budget, ablate?.noCompress !== true);
|
|
2009
2010
|
const retryAnswer = await generateOnce(env, model, retryMessages, routeEffort(routed.route));
|
|
2010
2011
|
// the answer now comes from the retry passages — citations must follow
|
|
2011
2012
|
if (retryAnswer) {
|
|
@@ -2096,7 +2097,7 @@ let convEntities: Array<{ entity: string; kind: string }> = [];
|
|
|
2096
2097
|
telemetryDecisions(env, ctx, tier, queryHash, decisionsOut ?? null, Date.now() - tStart);
|
|
2097
2098
|
}
|
|
2098
2099
|
const out = { answer, citations: finalCites, ...(jsonQuality ? { source_quality: jsonQuality!, confidence_note: entailmentNote || qualityNote(jsonQuality!), ...(entailment ? { entailment } : {}), ...(jsonQuality === "ocr" ? { experimental_sources: experimentalSourceLabels(finalCites) } : {}) } : {}), model: MODELS.member, query_hash: queryHash, follow_ups: refusalShaped(answer!, refusalScope(answerCites(answer!))) ? [] : (understanding?.follow_ups ?? []), blocks: [...c2ns.blocks, ...(verdictBlock ? [verdictBlock] : []), ...(conditionBlock ? [conditionBlock] : []), ...(aggregationBlock ? [aggregationBlock] : []), ...(registerBlock ? [registerBlock] : []), ...completionBlocks], context_applied: ctxApplied, ...(liveRecords ? { records: liveRecords } : {}), ...(decisionsOut ? { decisions: decisionsOut } : {}), ...(ablate ? { ablate } : {}), route: { route: routed.route, features: routed.features } };
|
|
2099
|
-
const cacheable = !contextual && !declaredCtx && !ablate && cacheableAnswer(answer!, refusalScope(answerCites(answer!))) && finalAnchors.violations.length === 0;
|
|
2100
|
+
const cacheable = !contextual && !declaredCtx && !ablate && !registerBypass && cacheableAnswer(answer!, refusalScope(answerCites(answer!))) && finalAnchors.violations.length === 0;
|
|
2100
2101
|
if (cacheable) {
|
|
2101
2102
|
const ck = exactCacheKey(env.INDEX_VERSION, gen, ns, await sha256Hex(cacheKeyMaterial(q.query, q.lang, salt)));
|
|
2102
2103
|
ctx.waitUntil(env.CACHE.put(ck, JSON.stringify(out), { expirationTtl: LIMITS.cacheTtlSec }));
|
|
@@ -40,6 +40,17 @@ export function registerAggregateIntent(query: string): "count" | "latest" | nul
|
|
|
40
40
|
return null;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
/** The register's answers derive from the D1 snapshot, not the indexed
|
|
44
|
+
* corpus — but the answer cache (namespaced by INDEX_VERSION +
|
|
45
|
+
* corpus_gen) knows nothing about D1-plane loads, so a cached
|
|
46
|
+
* pre-register refusal preempted register-shaped questions the register
|
|
47
|
+
* answers (measured live 2026-10-28: cached refusals served over
|
|
48
|
+
* register-shaped asks until fresh). Such asks skip both cache reads
|
|
49
|
+
* and writes. */
|
|
50
|
+
export function registerBypassesCache(query: string): boolean {
|
|
51
|
+
return isRegisterShaped(query) || registerAggregateIntent(query) !== null;
|
|
52
|
+
}
|
|
53
|
+
|
|
43
54
|
export interface RegisterAggregate {
|
|
44
55
|
family: string;
|
|
45
56
|
count: number;
|
|
@@ -208,7 +219,7 @@ export function buildRegisterQuery(tokens: string[]): { sql: string; params: str
|
|
|
208
219
|
return `(holder LIKE ?${n} OR model LIKE ?${n} OR num LIKE ?${n})`;
|
|
209
220
|
});
|
|
210
221
|
return {
|
|
211
|
-
sql: `SELECT num, family, holder, model, year, status, pdf_key FROM certificates WHERE family = ?FAMILY AND (${clauses.join(" OR ")}) LIMIT
|
|
222
|
+
sql: `SELECT num, family, holder, model, year, status, pdf_key FROM certificates WHERE family = ?FAMILY AND (${clauses.join(" OR ")}) LIMIT 40`,
|
|
212
223
|
params,
|
|
213
224
|
};
|
|
214
225
|
}
|
|
@@ -257,20 +268,49 @@ export async function searchRegister(db: any, query: string, force = false): Pro
|
|
|
257
268
|
}
|
|
258
269
|
try {
|
|
259
270
|
const res = await db.prepare(sql).bind(...params).all();
|
|
260
|
-
|
|
271
|
+
const rows = rankRegisterRows((res.results ?? []) as RegisterRow[], tokens);
|
|
272
|
+
return { rows, tokens };
|
|
261
273
|
} catch {
|
|
262
274
|
// a missing table or a D1 hiccup degrades to no-note honestly
|
|
263
275
|
return { rows: [], tokens };
|
|
264
276
|
}
|
|
265
277
|
}
|
|
266
278
|
|
|
279
|
+
/** Rank the OR-matched candidates so the note's six rows carry the
|
|
280
|
+
* QUESTION's model, not just its holder: the live probes showed a
|
|
281
|
+
* distinctive model token losing its place to generic holder words
|
|
282
|
+
* ("Rice Lake Weighing Systems" matched 6 rows before "RL116XP" was
|
|
283
|
+
* ever consulted — the answer then denied a certificate the register
|
|
284
|
+
* holds). A model-token hit outranks a holder-token hit; numbers must
|
|
285
|
+
* match as standalone values (the "190 must not catch XK3190" rule).
|
|
286
|
+
* Measured 2026-10-28, the register-lane eval. */
|
|
287
|
+
export function rankRegisterRows(rows: RegisterRow[], tokens: string[]): RegisterRow[] {
|
|
288
|
+
const score = (row: RegisterRow): number => {
|
|
289
|
+
const model = (row.model || "").toLowerCase();
|
|
290
|
+
const holder = (row.holder || "").toLowerCase();
|
|
291
|
+
let s = 0;
|
|
292
|
+
for (const t of tokens) {
|
|
293
|
+
const tl = t.toLowerCase();
|
|
294
|
+
if (/^\d+$/.test(t)) {
|
|
295
|
+
if (new RegExp(`(^|[^a-z0-9])${tl}([^a-z0-9]|$)`).test(model)) s += 3;
|
|
296
|
+
else if (holder.includes(tl)) s += 1;
|
|
297
|
+
} else if (model.includes(tl)) s += 2;
|
|
298
|
+
else if (holder.includes(tl)) s += 1;
|
|
299
|
+
}
|
|
300
|
+
return s;
|
|
301
|
+
};
|
|
302
|
+
return [...rows]
|
|
303
|
+
.sort((a, b) => score(b) - score(a) || Number(b.year) - Number(a.year))
|
|
304
|
+
.slice(0, 6);
|
|
305
|
+
}
|
|
306
|
+
|
|
267
307
|
export function registerNote(rows: RegisterRow[]): string {
|
|
268
308
|
if (!rows.length) {
|
|
269
|
-
return `Certificate register
|
|
309
|
+
return `Certificate register — THIS NOTE ANSWERS THE QUESTION. NO certificate matching the asked holder or model appears in the ${P().publisher.name}-CS register snapshot. Answer from THIS note: state plainly that no such certificate is in this register — never fall back to the indexed publications' absence phrasing — and say the register is a snapshot rather than the live certification status.`;
|
|
270
310
|
}
|
|
271
311
|
const lines = rows.map((r) => `- ${r.num}: holder ${r.holder}, model "${r.model}"${r.year ? `, issued ${r.year}` : ""} — status ${r.status}`);
|
|
272
312
|
return [
|
|
273
|
-
"Certificate register —
|
|
313
|
+
"Certificate register — THIS NOTE ANSWERS THE QUESTION. The following certificates matched the asked holder or model; answer from THIS note. A model the note does not list is not among the matched rows — say so plainly instead of falling back to the indexed publications. Quote the certificate number, the holder and the status verbatim; the register is a snapshot, so qualify any statement about current certification accordingly.",
|
|
274
314
|
...lines,
|
|
275
315
|
].join("\n");
|
|
276
316
|
}
|
|
@@ -288,9 +288,10 @@ export function buildMessages(
|
|
|
288
288
|
retrievalNote?: string,
|
|
289
289
|
conversationSummary?: string,
|
|
290
290
|
budgetTokens: number = LIMITS.inputTokenBudget,
|
|
291
|
-
/** the extractive compression
|
|
292
|
-
*
|
|
293
|
-
*
|
|
291
|
+
/** the extractive compression (TODO.sota/02 row 5): PROMOTED — on in
|
|
292
|
+
* serving; ablate_no_compress stands it down per ask for the
|
|
293
|
+
* measurement. Each passage body becomes query-weighted sentence
|
|
294
|
+
* selection at compressShare of its budget. */
|
|
294
295
|
compress?: boolean,
|
|
295
296
|
): BuiltMessages {
|
|
296
297
|
// per-corpus guidance travels WITH the dataset (config.ts): every
|