@konneal/engine 0.2.162 → 0.2.164
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 +5 -0
- package/dist/ask-B7XXKYZP.js +16 -0
- package/dist/{chunk-4NXH5ZI6.js → chunk-D6UUAL7I.js} +1 -1
- package/dist/{chunk-MTIAHAOK.js → chunk-E74MNLBC.js} +82 -34
- package/dist/{chunk-NI4CIK6W.js → chunk-FHRGC6TP.js} +1 -1
- package/dist/{chunk-W7J5SFXJ.js → chunk-GJATVGBS.js} +1 -1
- package/dist/{chunk-AEVDR7DA.js → chunk-GVCOGEJC.js} +20 -12
- package/dist/{chunk-PBHMQZKA.js → chunk-K5WL3DKH.js} +12 -8
- package/dist/{chunk-IGAGXQHV.js → chunk-K7UGBTBZ.js} +4 -4
- package/dist/{chunk-VT7DR6NQ.js → chunk-ZD6TYLET.js} +3 -0
- package/dist/completion.d.ts +1 -1
- package/dist/config.d.ts +1 -0
- package/dist/pipeline.d.ts +5 -1
- package/dist/search-IXNVNOOY.js +14 -0
- package/dist/{tools-W5HGME7W.js → tools-JZY6GSYC.js} +4 -4
- package/dist/worker_mcp/src/index.js +2 -2
- package/dist/worker_public/src/config.js +1 -1
- package/dist/worker_public/src/index.js +11 -57
- package/dist/worker_public/src/requestScope.js +2 -2
- package/package.json +1 -1
- package/workers/worker_public/src/ablate.ts +8 -2
- package/workers/worker_public/src/ask.ts +3 -2
- package/workers/worker_public/src/completion.ts +13 -0
- package/workers/worker_public/src/config.ts +3 -0
- package/workers/worker_public/src/pipeline.ts +11 -1
- package/workers/worker_public/src/refs.ts +19 -5
- package/dist/ask-ND63B3CF.js +0 -16
- package/dist/search-FW5O32BY.js +0 -14
package/dist/ablate.d.ts
CHANGED
|
@@ -13,6 +13,11 @@ 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): each passage
|
|
17
|
+
* body is query-weighted sentence selection at a fraction of its
|
|
18
|
+
* budget before the answer model reads it. Off in serving; the grid
|
|
19
|
+
* arms it per ask (the row's accuracy-at-token-budget gate). */
|
|
20
|
+
compress: boolean;
|
|
16
21
|
}
|
|
17
22
|
export type AblateParse = {
|
|
18
23
|
ok: true;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
handleAsk
|
|
3
|
+
} from "./chunk-GVCOGEJC.js";
|
|
4
|
+
import "./chunk-ECOYO7EX.js";
|
|
5
|
+
import "./chunk-K5WL3DKH.js";
|
|
6
|
+
import "./chunk-E74MNLBC.js";
|
|
7
|
+
import "./chunk-FHRGC6TP.js";
|
|
8
|
+
import "./chunk-GJATVGBS.js";
|
|
9
|
+
import "./chunk-ETLSWSZ7.js";
|
|
10
|
+
import "./chunk-D6UUAL7I.js";
|
|
11
|
+
import "./chunk-ZD6TYLET.js";
|
|
12
|
+
import "./chunk-3FYJM7LH.js";
|
|
13
|
+
import "./chunk-LSZTJI7V.js";
|
|
14
|
+
export {
|
|
15
|
+
handleAsk
|
|
16
|
+
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
embed,
|
|
3
3
|
rerank
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-FHRGC6TP.js";
|
|
5
5
|
import {
|
|
6
6
|
bubbleConfirmPage,
|
|
7
7
|
isAllowedBubbleOrigin
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-GJATVGBS.js";
|
|
9
9
|
import {
|
|
10
10
|
DATASETS,
|
|
11
11
|
LIMITS,
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
processExpansion,
|
|
16
16
|
sha256Hex,
|
|
17
17
|
today
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-ZD6TYLET.js";
|
|
19
19
|
import {
|
|
20
20
|
P
|
|
21
21
|
} from "./chunk-3FYJM7LH.js";
|
|
@@ -1747,13 +1747,13 @@ var UnBuilder = class extends BaseBuilder {
|
|
|
1747
1747
|
return key === "token";
|
|
1748
1748
|
}
|
|
1749
1749
|
build(data) {
|
|
1750
|
-
const
|
|
1751
|
-
if (
|
|
1750
|
+
const tokens2 = this.extractTokens(Array.isArray(data) ? data : data["token"]);
|
|
1751
|
+
if (tokens2.length === 0)
|
|
1752
1752
|
throw new ParseFailed("UN identifier has no tokens", 0);
|
|
1753
|
-
const path =
|
|
1753
|
+
const path = tokens2.slice(0, -1);
|
|
1754
1754
|
const yearToken = [...path].reverse().find((t) => /^\d{4}$/.test(t));
|
|
1755
1755
|
const attrs = {
|
|
1756
|
-
number:
|
|
1756
|
+
number: tokens2[tokens2.length - 1],
|
|
1757
1757
|
path
|
|
1758
1758
|
};
|
|
1759
1759
|
if (yearToken)
|
|
@@ -3778,7 +3778,7 @@ function jisGrammarImplementation() {
|
|
|
3778
3778
|
}
|
|
3779
3779
|
|
|
3780
3780
|
// node_modules/@pubid/pubid/dist/flavors/iec/model.js
|
|
3781
|
-
var TS = (code, stageCode, typeCode, abbr, harmonized,
|
|
3781
|
+
var TS = (code, stageCode, typeCode, abbr, harmonized, tokens2) => ({ code, stageCode, typeCode, abbr, harmonized, tokens: tokens2 });
|
|
3782
3782
|
var TYPED_STAGES = [
|
|
3783
3783
|
TS("is", "published", "is", ""),
|
|
3784
3784
|
TS("tr", "published", "tr", "TR"),
|
|
@@ -4332,8 +4332,8 @@ function parseLanguages2(tree) {
|
|
|
4332
4332
|
const raw = s(tree);
|
|
4333
4333
|
if (raw === void 0)
|
|
4334
4334
|
return [];
|
|
4335
|
-
const
|
|
4336
|
-
return
|
|
4335
|
+
const tokens2 = raw.split(",").flatMap((chunk) => chunk.split("/"));
|
|
4336
|
+
return tokens2.map((token) => token.trim()).filter((token) => token !== "").map((original) => {
|
|
4337
4337
|
const code = original.length === 1 ? Language.CHAR_MAP[original] ?? original.toLowerCase() : original;
|
|
4338
4338
|
return new Language({ code, originalCode: original });
|
|
4339
4339
|
});
|
|
@@ -5582,8 +5582,8 @@ var TYPE_WORD_TO_CODE = (() => {
|
|
|
5582
5582
|
return map;
|
|
5583
5583
|
})();
|
|
5584
5584
|
var LANGUAGE_ALIASES = { EN: "E", FR: "F" };
|
|
5585
|
-
function alternation(
|
|
5586
|
-
const sorted = [...
|
|
5585
|
+
function alternation(tokens2) {
|
|
5586
|
+
const sorted = [...tokens2].sort((a, b) => b.length - a.length);
|
|
5587
5587
|
return sorted.map((t) => str(t)).reduce((a, b) => a.or(b));
|
|
5588
5588
|
}
|
|
5589
5589
|
function buildRules24() {
|
|
@@ -6863,8 +6863,8 @@ function publishedStage(typeKey) {
|
|
|
6863
6863
|
}
|
|
6864
6864
|
function stageTokens2(typeKeys) {
|
|
6865
6865
|
const stages = typeKeys === void 0 ? ISO_TYPED_STAGES : ISO_TYPED_STAGES.filter((s8) => typeKeys.includes(s8.typeKey));
|
|
6866
|
-
const
|
|
6867
|
-
return [...new Set(
|
|
6866
|
+
const tokens2 = stages.flatMap((s8) => s8.abbr.filter((a) => a !== ""));
|
|
6867
|
+
return [...new Set(tokens2)].sort((a, b) => b.length - a.length);
|
|
6868
6868
|
}
|
|
6869
6869
|
function stageAbbr(entry, formatLong, originalAbbr) {
|
|
6870
6870
|
if (formatLong && entry.longAbbr !== void 0)
|
|
@@ -7697,8 +7697,8 @@ var WG_TYPES = [
|
|
|
7697
7697
|
"JTAG",
|
|
7698
7698
|
"JTG"
|
|
7699
7699
|
];
|
|
7700
|
-
function literalAlternation(
|
|
7701
|
-
const sorted = [...new Set(
|
|
7700
|
+
function literalAlternation(tokens2) {
|
|
7701
|
+
const sorted = [...new Set(tokens2)].sort((a, b) => b.length - a.length);
|
|
7702
7702
|
return sorted.map((t) => str(t)).reduce((a, b) => a.or(b));
|
|
7703
7703
|
}
|
|
7704
7704
|
function buildRules25() {
|
|
@@ -8171,8 +8171,8 @@ var MONTHS = [
|
|
|
8171
8171
|
"Nov",
|
|
8172
8172
|
"Dec"
|
|
8173
8173
|
];
|
|
8174
|
-
function literalAlternation2(
|
|
8175
|
-
const sorted = [...new Set(
|
|
8174
|
+
function literalAlternation2(tokens2) {
|
|
8175
|
+
const sorted = [...new Set(tokens2)].sort((a, b) => b.length - a.length);
|
|
8176
8176
|
return sorted.map((t) => str(t)).reduce((a, b) => a.or(b));
|
|
8177
8177
|
}
|
|
8178
8178
|
function buildRules26() {
|
|
@@ -10543,8 +10543,8 @@ var MONTHS2 = [
|
|
|
10543
10543
|
"Nov",
|
|
10544
10544
|
"Dec"
|
|
10545
10545
|
];
|
|
10546
|
-
function literalAlternation3(
|
|
10547
|
-
const sorted = [...new Set(
|
|
10546
|
+
function literalAlternation3(tokens2) {
|
|
10547
|
+
const sorted = [...new Set(tokens2)].sort((a, b) => b.length - a.length);
|
|
10548
10548
|
return sorted.map((t) => str(t)).reduce((a, b) => a.or(b));
|
|
10549
10549
|
}
|
|
10550
10550
|
function buildRules27() {
|
|
@@ -14930,8 +14930,8 @@ var RM_ABBRS = [
|
|
|
14930
14930
|
"RM"
|
|
14931
14931
|
];
|
|
14932
14932
|
var SUPPLEMENT_ABBRS = ["AMD", "COR"];
|
|
14933
|
-
function abbrAlternation(
|
|
14934
|
-
const sorted = [...new Set(
|
|
14933
|
+
function abbrAlternation(tokens2) {
|
|
14934
|
+
const sorted = [...new Set(tokens2)].sort((a, b) => b.length - a.length);
|
|
14935
14935
|
return sorted.map((t) => str(t)).reduce((a, b) => a.or(b));
|
|
14936
14936
|
}
|
|
14937
14937
|
function buildRules30() {
|
|
@@ -15857,9 +15857,9 @@ function adoptIdentifier(raw) {
|
|
|
15857
15857
|
function splitPrefix(text) {
|
|
15858
15858
|
if (text === void 0)
|
|
15859
15859
|
return [void 0, void 0];
|
|
15860
|
-
const
|
|
15861
|
-
const copublisher = normalizeCopublisher(
|
|
15862
|
-
const subtype =
|
|
15860
|
+
const tokens2 = text.trim().split(/\s+/);
|
|
15861
|
+
const copublisher = normalizeCopublisher(tokens2[0]);
|
|
15862
|
+
const subtype = tokens2.length > 1 ? normalizeSubtype(tokens2.slice(1).join(" ")) : void 0;
|
|
15863
15863
|
return [copublisher, subtype];
|
|
15864
15864
|
}
|
|
15865
15865
|
function normalizeCopublisher(raw) {
|
|
@@ -16710,7 +16710,7 @@ function stri(input) {
|
|
|
16710
16710
|
}
|
|
16711
16711
|
return parts.reduce((a, b) => a.then(b));
|
|
16712
16712
|
}
|
|
16713
|
-
var alt = (
|
|
16713
|
+
var alt = (tokens2) => tokens2.map((t) => str(t)).reduce((a, b) => a.or(b));
|
|
16714
16714
|
function buildRules34() {
|
|
16715
16715
|
const rules = {};
|
|
16716
16716
|
const rule = (name, build) => {
|
|
@@ -19512,9 +19512,9 @@ function parseCsa(input) {
|
|
|
19512
19512
|
}
|
|
19513
19513
|
}
|
|
19514
19514
|
if (baseInput === void 0 || baseInput === "") {
|
|
19515
|
-
const
|
|
19515
|
+
const tokens2 = input.split(/\s+/);
|
|
19516
19516
|
let acc = "";
|
|
19517
|
-
for (const token of
|
|
19517
|
+
for (const token of tokens2) {
|
|
19518
19518
|
if (/^PACKAGE$/i.test(token))
|
|
19519
19519
|
break;
|
|
19520
19520
|
const testInput = acc === "" ? token : `${acc} ${token}`;
|
|
@@ -19557,7 +19557,7 @@ function csaGrammarImplementation() {
|
|
|
19557
19557
|
}
|
|
19558
19558
|
|
|
19559
19559
|
// node_modules/@pubid/pubid/dist/flavors/asme/grammar.js
|
|
19560
|
-
var alt2 = (
|
|
19560
|
+
var alt2 = (tokens2) => tokens2.map((t) => str(t)).reduce((a, b) => a.or(b));
|
|
19561
19561
|
function buildRules36() {
|
|
19562
19562
|
const rules = {};
|
|
19563
19563
|
const rule = (name, build) => {
|
|
@@ -23474,6 +23474,53 @@ columns: ${colKeep.map((i) => `${t.columns[i]?.label ?? ""}${t.columns[i]?.unit
|
|
|
23474
23474
|
${lines.join("\n")}${elided}`, cols: colKeep.map((i) => `${t.columns[i]?.label ?? ""}${t.columns[i]?.unit ? ` [${t.columns[i].unit}]` : ""}`), rowsShown: shown.length, rowsTotal: t.rows.length };
|
|
23475
23475
|
}
|
|
23476
23476
|
|
|
23477
|
+
// workers/worker_public/src/compress.ts
|
|
23478
|
+
var STOP2 = new Set(
|
|
23479
|
+
"the a an and or of to in on for with by as at is are was were be been from that this these those it its their there which who what when where how why not no than then also such may must shall can could should would per within under over into about between during before after each any all more most less least other only same both few many some own very one two".split(
|
|
23480
|
+
" "
|
|
23481
|
+
)
|
|
23482
|
+
);
|
|
23483
|
+
function tokens(text) {
|
|
23484
|
+
return (text.toLowerCase().match(/[a-z0-9]+(?:[.][0-9]+)?/g) ?? []).filter(
|
|
23485
|
+
(t) => /^[0-9]/.test(t) || t.length >= 3 && !STOP2.has(t)
|
|
23486
|
+
);
|
|
23487
|
+
}
|
|
23488
|
+
function splitSentences(text) {
|
|
23489
|
+
const parts = text.replace(/\r/g, "").split(/(?<=[.!?;])\s+|\n+/).map((s8) => s8.trim()).filter(Boolean);
|
|
23490
|
+
return parts;
|
|
23491
|
+
}
|
|
23492
|
+
function scoreSentence(sentence, qTerms) {
|
|
23493
|
+
const toks = tokens(sentence);
|
|
23494
|
+
if (!toks.length) return 0;
|
|
23495
|
+
let hits = 0;
|
|
23496
|
+
for (const t of toks) if (qTerms.has(t)) hits += 1;
|
|
23497
|
+
const density = hits / Math.sqrt(toks.length);
|
|
23498
|
+
const numeric = /\d/.test(sentence) ? 0.35 : 0;
|
|
23499
|
+
return density + numeric;
|
|
23500
|
+
}
|
|
23501
|
+
function compressText(text, query, budgetChars) {
|
|
23502
|
+
const clean = text.replace(/\s+/g, " ").trim();
|
|
23503
|
+
if (!clean || clean.length <= budgetChars) return clean;
|
|
23504
|
+
const qTerms = new Set(tokens(query));
|
|
23505
|
+
const sentences = splitSentences(clean);
|
|
23506
|
+
if (sentences.length <= 1) {
|
|
23507
|
+
const cut = clean.slice(0, Math.max(0, budgetChars));
|
|
23508
|
+
const end = cut.lastIndexOf(" ");
|
|
23509
|
+
return (end > 40 ? cut.slice(0, end) : cut).trim();
|
|
23510
|
+
}
|
|
23511
|
+
const scored = sentences.map((s8, i) => ({ s: s8, i, score: scoreSentence(s8, qTerms) }));
|
|
23512
|
+
const keep = /* @__PURE__ */ new Set([0]);
|
|
23513
|
+
const ranked = scored.slice(1).sort((a, b) => b.score - a.score || a.i - b.i);
|
|
23514
|
+
let used = sentences[0].length + 1;
|
|
23515
|
+
for (const r of ranked) {
|
|
23516
|
+
if (used + r.s.length + 1 > budgetChars) continue;
|
|
23517
|
+
keep.add(r.i);
|
|
23518
|
+
used += r.s.length + 1;
|
|
23519
|
+
}
|
|
23520
|
+
const out = scored.filter((r) => keep.has(r.i)).map((r) => r.s).join(" ").trim();
|
|
23521
|
+
return out.slice(0, budgetChars);
|
|
23522
|
+
}
|
|
23523
|
+
|
|
23477
23524
|
// workers/worker_public/src/pipeline.ts
|
|
23478
23525
|
function promptVars(extra = {}) {
|
|
23479
23526
|
const out = { PUBLISHER_NAME: P().publisher.name };
|
|
@@ -23596,7 +23643,7 @@ ${listing}` }
|
|
|
23596
23643
|
return null;
|
|
23597
23644
|
}
|
|
23598
23645
|
}
|
|
23599
|
-
function buildMessages(query, hits, lang, history = [], retrievalNote, conversationSummary, budgetTokens = LIMITS.inputTokenBudget) {
|
|
23646
|
+
function buildMessages(query, hits, lang, history = [], retrievalNote, conversationSummary, budgetTokens = LIMITS.inputTokenBudget, compress) {
|
|
23600
23647
|
const corpusNotes = DATASETS().filter(
|
|
23601
23648
|
(d) => d.note && hits.some((h) => h.metadata.corpus === d.id)
|
|
23602
23649
|
).map((d) => d.note).join("\n");
|
|
@@ -23641,7 +23688,7 @@ Context passages:
|
|
|
23641
23688
|
const pruned = tableSel?.text ?? null;
|
|
23642
23689
|
if (tableSel) h.metadata.table_selection = { cols: tableSel.cols, rowsShown: tableSel.rowsShown, rowsTotal: tableSel.rowsTotal };
|
|
23643
23690
|
const figDesc = h.metadata.block === "figure" ? String(h.metadata.figure_description ?? "").trim() : "";
|
|
23644
|
-
const raw = clipToTokens(pruned ?? h.text, LIMITS.maxPassageTokens);
|
|
23691
|
+
const raw = compress ? compressText(String(pruned ?? h.text ?? ""), query, Math.floor(LIMITS.maxPassageTokens * 4 * THRESHOLDS.compressShare)) : clipToTokens(pruned ?? h.text, LIMITS.maxPassageTokens);
|
|
23645
23692
|
const body = figDesc ? `${raw}
|
|
23646
23693
|
Caption: ${figDesc}` : raw;
|
|
23647
23694
|
const t = estTokens(head) + estTokens(body);
|
|
@@ -24718,9 +24765,9 @@ async function tokenBudget(env, bucketId) {
|
|
|
24718
24765
|
const used = Number(await env.CACHE.get(`t:${today()}:ask:${await sha256Hex(bucketId)}`) ?? "0");
|
|
24719
24766
|
return { used, limit: tokenLimit(env, bucketId) };
|
|
24720
24767
|
}
|
|
24721
|
-
async function chargeTokens(env, bucketId,
|
|
24722
|
-
if (!(
|
|
24723
|
-
await kvIncr(env.CACHE, `t:${today()}:ask:${await sha256Hex(bucketId)}`,
|
|
24768
|
+
async function chargeTokens(env, bucketId, tokens2) {
|
|
24769
|
+
if (!(tokens2 > 0)) return;
|
|
24770
|
+
await kvIncr(env.CACHE, `t:${today()}:ask:${await sha256Hex(bucketId)}`, tokens2);
|
|
24724
24771
|
}
|
|
24725
24772
|
function usageTotal(usage) {
|
|
24726
24773
|
if (!usage || typeof usage !== "object") return null;
|
|
@@ -24789,6 +24836,7 @@ Family summary (precomputed from the registry and the successor graph): ${summar
|
|
|
24789
24836
|
}
|
|
24790
24837
|
|
|
24791
24838
|
export {
|
|
24839
|
+
compressText,
|
|
24792
24840
|
refCodec,
|
|
24793
24841
|
NO_CONTEXT,
|
|
24794
24842
|
machineOffers,
|
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
tableRetyped,
|
|
33
33
|
toolNote,
|
|
34
34
|
verdictNote
|
|
35
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-K5WL3DKH.js";
|
|
36
36
|
import {
|
|
37
37
|
NO_CONTEXT,
|
|
38
38
|
STAGE_NAMES,
|
|
@@ -75,18 +75,18 @@ import {
|
|
|
75
75
|
tokenBudget,
|
|
76
76
|
understandQuery,
|
|
77
77
|
usageTotal
|
|
78
|
-
} from "./chunk-
|
|
78
|
+
} from "./chunk-E74MNLBC.js";
|
|
79
79
|
import {
|
|
80
80
|
embed,
|
|
81
81
|
generateOnce
|
|
82
|
-
} from "./chunk-
|
|
82
|
+
} from "./chunk-FHRGC6TP.js";
|
|
83
83
|
import {
|
|
84
84
|
corsHeaders,
|
|
85
85
|
err,
|
|
86
86
|
json,
|
|
87
87
|
readJson,
|
|
88
88
|
validateQuery
|
|
89
|
-
} from "./chunk-
|
|
89
|
+
} from "./chunk-GJATVGBS.js";
|
|
90
90
|
import {
|
|
91
91
|
cacheableAnswer,
|
|
92
92
|
canonicalRefusal,
|
|
@@ -99,7 +99,7 @@ import {
|
|
|
99
99
|
requestSalt,
|
|
100
100
|
resolveRequestScope,
|
|
101
101
|
standardKeysFrom
|
|
102
|
-
} from "./chunk-
|
|
102
|
+
} from "./chunk-D6UUAL7I.js";
|
|
103
103
|
import {
|
|
104
104
|
LIMITS,
|
|
105
105
|
MODELS,
|
|
@@ -110,7 +110,7 @@ import {
|
|
|
110
110
|
requestEffort,
|
|
111
111
|
roleModel,
|
|
112
112
|
sha256Hex
|
|
113
|
-
} from "./chunk-
|
|
113
|
+
} from "./chunk-ZD6TYLET.js";
|
|
114
114
|
import {
|
|
115
115
|
P
|
|
116
116
|
} from "./chunk-3FYJM7LH.js";
|
|
@@ -470,13 +470,19 @@ async function completeTables(db, answer, used) {
|
|
|
470
470
|
}
|
|
471
471
|
return blocks;
|
|
472
472
|
}
|
|
473
|
-
async function completeFigures(db, answer, alreadyAttached, used = []) {
|
|
473
|
+
async function completeFigures(db, answer, alreadyAttached, used = [], query) {
|
|
474
474
|
const unitForm = (answer.match(/u:fig[\w.-]*/g) ?? []).map((x) => x.replace(/[.,;:)]+$/, ""));
|
|
475
475
|
const bareForm = (answer.match(/\bfig-[\w.-]+\b/g) ?? []).map((x) => x.replace(/[.,;:)]+$/, ""));
|
|
476
476
|
let mentioned = [.../* @__PURE__ */ new Set([...unitForm, ...bareForm.map((x) => x.startsWith("u:") ? x : "u:" + x)])].slice(0, 6);
|
|
477
477
|
const proseNums = new Set(
|
|
478
478
|
(answer.match(/\bFig(?:ure|\.)s?\s*([0-9]{1,2}[a-z]?)/g) ?? []).map((x) => x.replace(/\bFig(?:ure|\.)s?\s*/i, "").toLowerCase())
|
|
479
479
|
);
|
|
480
|
+
if (query && /\bfig(ure|s)?\b/i.test(query)) {
|
|
481
|
+
for (const h of used.slice(0, 12)) {
|
|
482
|
+
if (h.metadata.unit_id && h.metadata.block === "figure") mentioned.push(h.metadata.unit_id);
|
|
483
|
+
}
|
|
484
|
+
mentioned = [...new Set(mentioned)].slice(0, 6);
|
|
485
|
+
}
|
|
480
486
|
if (proseNums.size) {
|
|
481
487
|
const fams = [...new Set(used.map((h) => h.metadata.docidentifier).filter(Boolean))].slice(0, 3);
|
|
482
488
|
for (const fam of fams) {
|
|
@@ -1397,9 +1403,10 @@ function parseAblate(body, adminToken, presentedToken, knownStages) {
|
|
|
1397
1403
|
const noVerdict = body?.ablate_no_verdict === true;
|
|
1398
1404
|
const rawRoute = body?.ablate_route;
|
|
1399
1405
|
const speculative = body?.ablate_speculative === true;
|
|
1406
|
+
const compress = body?.ablate_compress === true;
|
|
1400
1407
|
const namesAblation = rawStages !== void 0 && rawStages !== null;
|
|
1401
1408
|
const routeAblation = rawRoute !== void 0 && rawRoute !== null && rawRoute !== "adaptive";
|
|
1402
|
-
if (!namesAblation && !noVerdict && !routeAblation && !speculative) return { ok: true, config: null };
|
|
1409
|
+
if (!namesAblation && !noVerdict && !routeAblation && !speculative && !compress) return { ok: true, config: null };
|
|
1403
1410
|
if (!adminToken || presentedToken !== adminToken) {
|
|
1404
1411
|
return {
|
|
1405
1412
|
ok: false,
|
|
@@ -1430,7 +1437,7 @@ function parseAblate(body, adminToken, presentedToken, knownStages) {
|
|
|
1430
1437
|
}
|
|
1431
1438
|
stages = [...new Set(rawStages)];
|
|
1432
1439
|
}
|
|
1433
|
-
return { ok: true, config: { stages, noVerdict, route, speculative } };
|
|
1440
|
+
return { ok: true, config: { stages, noVerdict, route, speculative, compress } };
|
|
1434
1441
|
}
|
|
1435
1442
|
|
|
1436
1443
|
// workers/worker_public/src/route.ts
|
|
@@ -2636,7 +2643,8 @@ Answer account questions from these records ONLY: name the record when you use i
|
|
|
2636
2643
|
// stage-extracted graph facts (GraphRAG) ride the same note channel
|
|
2637
2644
|
[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,
|
|
2638
2645
|
summary,
|
|
2639
|
-
budget
|
|
2646
|
+
budget,
|
|
2647
|
+
ablate?.compress === true
|
|
2640
2648
|
);
|
|
2641
2649
|
await attachFigureImages(env, messages, usedHits, q2.query);
|
|
2642
2650
|
const pendingTools = [];
|
|
@@ -2946,7 +2954,7 @@ Answer account questions from these records ONLY: name the record when you use i
|
|
|
2946
2954
|
...routeSubset ? { stageSubset: routeSubset ?? void 0 } : {}
|
|
2947
2955
|
});
|
|
2948
2956
|
if (retryRetrieve.hits.length > 0) {
|
|
2949
|
-
const { messages: retryMessages, usedHits: retryUsed } = buildMessages(q2.query, retryRetrieve.hits, q2.lang, keptHistory, void 0, summary, budget);
|
|
2957
|
+
const { messages: retryMessages, usedHits: retryUsed } = buildMessages(q2.query, retryRetrieve.hits, q2.lang, keptHistory, void 0, summary, budget, ablate?.compress === true);
|
|
2950
2958
|
const retryAnswer = await generateOnce(env, model, retryMessages, routeEffort(routed.route));
|
|
2951
2959
|
if (retryAnswer) {
|
|
2952
2960
|
answer = canonicalRefusal(retryAnswer, refusalScope(answerCites(retryAnswer)));
|
|
@@ -2971,7 +2979,7 @@ Answer account questions from these records ONLY: name the record when you use i
|
|
|
2971
2979
|
completionBlocks = await completeTables(env.DB, answer, used);
|
|
2972
2980
|
if (completionBlocks.length) console.log("contract completion:", completionBlocks.length, "table block(s) attached server-side");
|
|
2973
2981
|
}
|
|
2974
|
-
completionBlocks.push(...await completeFigures(env.DB, answer, [...c2ns.blocks, ...completionBlocks], used));
|
|
2982
|
+
completionBlocks.push(...await completeFigures(env.DB, answer, [...c2ns.blocks, ...completionBlocks], used, q2.query));
|
|
2975
2983
|
if (withImage && register?.rows?.length && answer.includes(refusalAnswer())) {
|
|
2976
2984
|
console.log("blind-answer: the register note carried rows but the answer refused \u2014 regenerating once");
|
|
2977
2985
|
mark("Re-answering from the register results");
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
embed
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-FHRGC6TP.js";
|
|
4
4
|
import {
|
|
5
5
|
standardKeysFrom
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-D6UUAL7I.js";
|
|
7
7
|
import {
|
|
8
8
|
THRESHOLDS
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-ZD6TYLET.js";
|
|
10
10
|
import {
|
|
11
11
|
P
|
|
12
12
|
} from "./chunk-3FYJM7LH.js";
|
|
@@ -18,7 +18,10 @@ import {
|
|
|
18
18
|
} from "./chunk-LSZTJI7V.js";
|
|
19
19
|
|
|
20
20
|
// workers/worker_public/src/refs.ts
|
|
21
|
-
var REF = /\[\[(u:[A-Za-z0-9_-]+)\]\]/g;
|
|
21
|
+
var REF = /\[\[(u:(?:u:)?[A-Za-z0-9_-]+)\]\]/g;
|
|
22
|
+
function normalizeRef(id) {
|
|
23
|
+
return id.startsWith("u:u:") ? id.slice(2) : id;
|
|
24
|
+
}
|
|
22
25
|
function availableUnitIds(hits) {
|
|
23
26
|
const ids = /* @__PURE__ */ new Set();
|
|
24
27
|
for (const h of hits) {
|
|
@@ -28,13 +31,14 @@ function availableUnitIds(hits) {
|
|
|
28
31
|
return ids;
|
|
29
32
|
}
|
|
30
33
|
function parseRefs(text) {
|
|
31
|
-
return [...text.matchAll(REF)].map((m) => m[1]);
|
|
34
|
+
return [...text.matchAll(REF)].map((m) => normalizeRef(m[1]));
|
|
32
35
|
}
|
|
33
36
|
function sanitizeRefs(text, available) {
|
|
34
37
|
const dropped = [];
|
|
35
|
-
const out = text.replace(REF, (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
const out = text.replace(REF, (_full, id) => {
|
|
39
|
+
const normalized = normalizeRef(id);
|
|
40
|
+
if (available.has(normalized)) return `[[${normalized}]]`;
|
|
41
|
+
dropped.push(normalized);
|
|
38
42
|
return "";
|
|
39
43
|
});
|
|
40
44
|
return { text: out, dropped };
|
|
@@ -6,24 +6,24 @@ import {
|
|
|
6
6
|
sessionFrom,
|
|
7
7
|
telemetry,
|
|
8
8
|
understandQuery
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-E74MNLBC.js";
|
|
10
10
|
import {
|
|
11
11
|
corsHeaders,
|
|
12
12
|
err,
|
|
13
13
|
json,
|
|
14
14
|
readJson,
|
|
15
15
|
validateQuery
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-GJATVGBS.js";
|
|
17
17
|
import {
|
|
18
18
|
entitlementScope,
|
|
19
19
|
standardKeysFrom
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-D6UUAL7I.js";
|
|
21
21
|
import {
|
|
22
22
|
LIMITS,
|
|
23
23
|
MODELS,
|
|
24
24
|
num,
|
|
25
25
|
sha256Hex
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-ZD6TYLET.js";
|
|
27
27
|
import {
|
|
28
28
|
portModelRunner
|
|
29
29
|
} from "./chunk-LSZTJI7V.js";
|
|
@@ -81,6 +81,9 @@ var THRESHOLDS = {
|
|
|
81
81
|
* then states a measurement — claim support in the cited passages —
|
|
82
82
|
* not only the source rung. Fails open (a slow or unparseable check
|
|
83
83
|
* leaves the source-rung note unchanged). */
|
|
84
|
+
// the extractive compression arm (TODO.sota/02 row 5): when ablated
|
|
85
|
+
// on, each passage body is compressed to this share of its budget
|
|
86
|
+
compressShare: 0.6,
|
|
84
87
|
entailmentGate: true,
|
|
85
88
|
entailmentBudgetMs: 6e3,
|
|
86
89
|
entailmentSupportedFloor: 0.9,
|
package/dist/completion.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ import type { StoreQuery } from "./ports/store.ts";
|
|
|
2
2
|
import { type ResolvedBlock } from "./refs.ts";
|
|
3
3
|
import type { Hit } from "./pipeline.ts";
|
|
4
4
|
export declare function completeTables(db: StoreQuery, answer: string, used: Hit[]): Promise<ResolvedBlock[]>;
|
|
5
|
-
export declare function completeFigures(db: StoreQuery, answer: string, alreadyAttached: ResolvedBlock[], used?: Hit[]): Promise<ResolvedBlock[]>;
|
|
5
|
+
export declare function completeFigures(db: StoreQuery, answer: string, alreadyAttached: ResolvedBlock[], used?: Hit[], query?: string): Promise<ResolvedBlock[]>;
|
package/dist/config.d.ts
CHANGED
|
@@ -49,6 +49,7 @@ export declare const THRESHOLDS: {
|
|
|
49
49
|
* then states a measurement — claim support in the cited passages —
|
|
50
50
|
* not only the source rung. Fails open (a slow or unparseable check
|
|
51
51
|
* leaves the source-rung note unchanged). */
|
|
52
|
+
readonly compressShare: 0.6;
|
|
52
53
|
readonly entailmentGate: true;
|
|
53
54
|
readonly entailmentBudgetMs: 6000;
|
|
54
55
|
readonly entailmentSupportedFloor: 0.9;
|
package/dist/pipeline.d.ts
CHANGED
|
@@ -50,7 +50,11 @@ export declare function splitHistory(history: HistoryTurn[], budgetTokens: numbe
|
|
|
50
50
|
* hard queries (cascade stage after the cross-encoder). Null = keep the
|
|
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
|
-
export declare function buildMessages(query: string, hits: Hit[], lang?: string, history?: HistoryTurn[], retrievalNote?: string, conversationSummary?: string, budgetTokens?: number
|
|
53
|
+
export declare function buildMessages(query: string, hits: Hit[], lang?: string, history?: HistoryTurn[], retrievalNote?: string, conversationSummary?: string, budgetTokens?: number,
|
|
54
|
+
/** the extractive compression arm (TODO.sota/02 row 5): ablate_compress
|
|
55
|
+
* arms it per ask — each passage body becomes query-weighted sentence
|
|
56
|
+
* selection at compressShare of its budget. Off in serving. */
|
|
57
|
+
compress?: boolean): BuiltMessages;
|
|
54
58
|
export declare function citations(hits: Hit[]): {
|
|
55
59
|
doc_id: string;
|
|
56
60
|
docidentifier: string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
handleSearch
|
|
3
|
+
} from "./chunk-K7UGBTBZ.js";
|
|
4
|
+
import "./chunk-E74MNLBC.js";
|
|
5
|
+
import "./chunk-FHRGC6TP.js";
|
|
6
|
+
import "./chunk-GJATVGBS.js";
|
|
7
|
+
import "./chunk-ETLSWSZ7.js";
|
|
8
|
+
import "./chunk-D6UUAL7I.js";
|
|
9
|
+
import "./chunk-ZD6TYLET.js";
|
|
10
|
+
import "./chunk-3FYJM7LH.js";
|
|
11
|
+
import "./chunk-LSZTJI7V.js";
|
|
12
|
+
export {
|
|
13
|
+
handleSearch
|
|
14
|
+
};
|
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
parseToolCall,
|
|
5
5
|
runTool,
|
|
6
6
|
toolNote
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-
|
|
10
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-K5WL3DKH.js";
|
|
8
|
+
import "./chunk-FHRGC6TP.js";
|
|
9
|
+
import "./chunk-D6UUAL7I.js";
|
|
10
|
+
import "./chunk-ZD6TYLET.js";
|
|
11
11
|
import "./chunk-3FYJM7LH.js";
|
|
12
12
|
import "./chunk-LSZTJI7V.js";
|
|
13
13
|
export {
|
|
@@ -4,20 +4,21 @@ import {
|
|
|
4
4
|
handleMemories,
|
|
5
5
|
scoreFaithfulness,
|
|
6
6
|
scoreJudge
|
|
7
|
-
} from "../../chunk-
|
|
7
|
+
} from "../../chunk-GVCOGEJC.js";
|
|
8
8
|
import "../../chunk-ECOYO7EX.js";
|
|
9
9
|
import {
|
|
10
10
|
TOOLS_REGISTRY,
|
|
11
11
|
bindModelNode,
|
|
12
12
|
modelGroundingBlock
|
|
13
|
-
} from "../../chunk-
|
|
13
|
+
} from "../../chunk-K5WL3DKH.js";
|
|
14
14
|
import {
|
|
15
15
|
handleSearch
|
|
16
|
-
} from "../../chunk-
|
|
16
|
+
} from "../../chunk-K7UGBTBZ.js";
|
|
17
17
|
import {
|
|
18
18
|
buildMessages,
|
|
19
19
|
citations,
|
|
20
20
|
clientIp,
|
|
21
|
+
compressText,
|
|
21
22
|
creditBudget,
|
|
22
23
|
editionNote,
|
|
23
24
|
fill,
|
|
@@ -37,11 +38,11 @@ import {
|
|
|
37
38
|
sessionFrom,
|
|
38
39
|
telemetry,
|
|
39
40
|
understandQuery
|
|
40
|
-
} from "../../chunk-
|
|
41
|
+
} from "../../chunk-E74MNLBC.js";
|
|
41
42
|
import {
|
|
42
43
|
embed,
|
|
43
44
|
generateOnce
|
|
44
|
-
} from "../../chunk-
|
|
45
|
+
} from "../../chunk-FHRGC6TP.js";
|
|
45
46
|
import {
|
|
46
47
|
authenticate,
|
|
47
48
|
corsHeaders,
|
|
@@ -50,14 +51,14 @@ import {
|
|
|
50
51
|
readJson,
|
|
51
52
|
validateQuery,
|
|
52
53
|
withCors
|
|
53
|
-
} from "../../chunk-
|
|
54
|
+
} from "../../chunk-GJATVGBS.js";
|
|
54
55
|
import {
|
|
55
56
|
canonicalRefusal
|
|
56
57
|
} from "../../chunk-ETLSWSZ7.js";
|
|
57
58
|
import {
|
|
58
59
|
entitlementScope,
|
|
59
60
|
standardKeysFrom
|
|
60
|
-
} from "../../chunk-
|
|
61
|
+
} from "../../chunk-D6UUAL7I.js";
|
|
61
62
|
import {
|
|
62
63
|
LIMITS,
|
|
63
64
|
MODELS,
|
|
@@ -68,7 +69,7 @@ import {
|
|
|
68
69
|
roleModel,
|
|
69
70
|
sha256Hex,
|
|
70
71
|
today
|
|
71
|
-
} from "../../chunk-
|
|
72
|
+
} from "../../chunk-ZD6TYLET.js";
|
|
72
73
|
import {
|
|
73
74
|
P,
|
|
74
75
|
setProfile
|
|
@@ -757,53 +758,6 @@ async function handleRevokeKey(env, req, id) {
|
|
|
757
758
|
return json({ ok: true, updated: r.meta?.changes ?? 0 });
|
|
758
759
|
}
|
|
759
760
|
|
|
760
|
-
// workers/worker_public/src/compress.ts
|
|
761
|
-
var STOP = new Set(
|
|
762
|
-
"the a an and or of to in on for with by as at is are was were be been from that this these those it its their there which who what when where how why not no than then also such may must shall can could should would per within under over into about between during before after each any all more most less least other only same both few many some own very one two".split(
|
|
763
|
-
" "
|
|
764
|
-
)
|
|
765
|
-
);
|
|
766
|
-
function tokens(text) {
|
|
767
|
-
return (text.toLowerCase().match(/[a-z0-9]+(?:[.][0-9]+)?/g) ?? []).filter(
|
|
768
|
-
(t) => /^[0-9]/.test(t) || t.length >= 3 && !STOP.has(t)
|
|
769
|
-
);
|
|
770
|
-
}
|
|
771
|
-
function splitSentences(text) {
|
|
772
|
-
const parts = text.replace(/\r/g, "").split(/(?<=[.!?;])\s+|\n+/).map((s) => s.trim()).filter(Boolean);
|
|
773
|
-
return parts;
|
|
774
|
-
}
|
|
775
|
-
function scoreSentence(sentence, qTerms) {
|
|
776
|
-
const toks = tokens(sentence);
|
|
777
|
-
if (!toks.length) return 0;
|
|
778
|
-
let hits = 0;
|
|
779
|
-
for (const t of toks) if (qTerms.has(t)) hits += 1;
|
|
780
|
-
const density = hits / Math.sqrt(toks.length);
|
|
781
|
-
const numeric = /\d/.test(sentence) ? 0.35 : 0;
|
|
782
|
-
return density + numeric;
|
|
783
|
-
}
|
|
784
|
-
function compressText(text, query, budgetChars) {
|
|
785
|
-
const clean = text.replace(/\s+/g, " ").trim();
|
|
786
|
-
if (!clean || clean.length <= budgetChars) return clean;
|
|
787
|
-
const qTerms = new Set(tokens(query));
|
|
788
|
-
const sentences = splitSentences(clean);
|
|
789
|
-
if (sentences.length <= 1) {
|
|
790
|
-
const cut = clean.slice(0, Math.max(0, budgetChars));
|
|
791
|
-
const end = cut.lastIndexOf(" ");
|
|
792
|
-
return (end > 40 ? cut.slice(0, end) : cut).trim();
|
|
793
|
-
}
|
|
794
|
-
const scored = sentences.map((s, i) => ({ s, i, score: scoreSentence(s, qTerms) }));
|
|
795
|
-
const keep = /* @__PURE__ */ new Set([0]);
|
|
796
|
-
const ranked = scored.slice(1).sort((a, b) => b.score - a.score || a.i - b.i);
|
|
797
|
-
let used = sentences[0].length + 1;
|
|
798
|
-
for (const r of ranked) {
|
|
799
|
-
if (used + r.s.length + 1 > budgetChars) continue;
|
|
800
|
-
keep.add(r.i);
|
|
801
|
-
used += r.s.length + 1;
|
|
802
|
-
}
|
|
803
|
-
const out = scored.filter((r) => keep.has(r.i)).map((r) => r.s).join(" ").trim();
|
|
804
|
-
return out.slice(0, budgetChars);
|
|
805
|
-
}
|
|
806
|
-
|
|
807
761
|
// workers/worker_public/prompts/research.md
|
|
808
762
|
var research_default = `You are a sufficiency judge for a research loop over {{PUBLISHER_NAME}} publications. Given the research question and the passages collected so far (across iterations), decide whether the collected evidence is SUFFICIENT to write a complete, well-grounded answer.
|
|
809
763
|
|
|
@@ -1165,13 +1119,13 @@ async function callToolOnce(env, ctx, _req, tier, key, name, args, t0) {
|
|
|
1165
1119
|
// stream:false forces the JSON lane (anon defaults to SSE)
|
|
1166
1120
|
body: JSON.stringify({ ...args, stream: false })
|
|
1167
1121
|
});
|
|
1168
|
-
const { runTool, TOOLS_REGISTRY: TOOLS_REGISTRY2 } = await import("../../tools-
|
|
1122
|
+
const { runTool, TOOLS_REGISTRY: TOOLS_REGISTRY2 } = await import("../../tools-JZY6GSYC.js");
|
|
1169
1123
|
let payload;
|
|
1170
1124
|
if (TOOLS_REGISTRY2.some((t) => t.name === name && t.audiences.includes("mcp"))) {
|
|
1171
1125
|
const r = await runTool({ ...env, DB: env.DB }, { name, args }, "mcp");
|
|
1172
1126
|
payload = r ? { tool: r.name, query: r.query, result: r.output } : { error: { message: `tool ${name} returned nothing for the given arguments` } };
|
|
1173
1127
|
} else {
|
|
1174
|
-
const res = name === "ask" ? await (await import("../../ask-
|
|
1128
|
+
const res = name === "ask" ? await (await import("../../ask-B7XXKYZP.js")).handleAsk(env, ctx, inner, tier, key) : await (await import("../../search-IXNVNOOY.js")).handleSearch(env, ctx, inner, tier, key);
|
|
1175
1129
|
payload = await res.json().catch(() => ({ error: { message: "tool transport failed", status: res.status } }));
|
|
1176
1130
|
}
|
|
1177
1131
|
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 });
|
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
requestSalt,
|
|
5
5
|
resolveRequestScope,
|
|
6
6
|
standardKeysFrom
|
|
7
|
-
} from "../../chunk-
|
|
8
|
-
import "../../chunk-
|
|
7
|
+
} from "../../chunk-D6UUAL7I.js";
|
|
8
|
+
import "../../chunk-ZD6TYLET.js";
|
|
9
9
|
import "../../chunk-3FYJM7LH.js";
|
|
10
10
|
export {
|
|
11
11
|
entitlementScope,
|
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.164",
|
|
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,6 +34,11 @@ 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): each passage
|
|
38
|
+
* body is query-weighted sentence selection at a fraction of its
|
|
39
|
+
* budget before the answer model reads it. Off in serving; the grid
|
|
40
|
+
* arms it per ask (the row's accuracy-at-token-budget gate). */
|
|
41
|
+
compress: boolean;
|
|
37
42
|
}
|
|
38
43
|
|
|
39
44
|
export type AblateParse =
|
|
@@ -55,10 +60,11 @@ export function parseAblate(
|
|
|
55
60
|
const noVerdict = body?.ablate_no_verdict === true;
|
|
56
61
|
const rawRoute = body?.ablate_route;
|
|
57
62
|
const speculative = body?.ablate_speculative === true;
|
|
63
|
+
const compress = body?.ablate_compress === true;
|
|
58
64
|
const namesAblation = rawStages !== undefined && rawStages !== null;
|
|
59
65
|
const routeAblation = rawRoute !== undefined && rawRoute !== null && rawRoute !== "adaptive";
|
|
60
66
|
|
|
61
|
-
if (!namesAblation && !noVerdict && !routeAblation && !speculative) return { ok: true, config: null };
|
|
67
|
+
if (!namesAblation && !noVerdict && !routeAblation && !speculative && !compress) return { ok: true, config: null };
|
|
62
68
|
|
|
63
69
|
if (!adminToken || presentedToken !== adminToken) {
|
|
64
70
|
return {
|
|
@@ -93,5 +99,5 @@ export function parseAblate(
|
|
|
93
99
|
stages = [...new Set(rawStages as string[])];
|
|
94
100
|
}
|
|
95
101
|
|
|
96
|
-
return { ok: true, config: { stages, noVerdict, route, speculative } };
|
|
102
|
+
return { ok: true, config: { stages, noVerdict, route, speculative, compress } };
|
|
97
103
|
}
|
|
@@ -1500,6 +1500,7 @@ let convEntities: Array<{ entity: string; kind: string }> = [];
|
|
|
1500
1500
|
[ops.note, processNote, eNote, regNote, contextNote(declaredCtx, docScope), accountNote, modelNote, vocabNote, memNote, machineNote, conditionNote, aggregationNote, boundaryNote, licenseNote, ...(retrieved.notes ?? [])].filter(Boolean).join("\n") || undefined,
|
|
1501
1501
|
summary,
|
|
1502
1502
|
budget,
|
|
1503
|
+
ablate?.compress === true,
|
|
1503
1504
|
);
|
|
1504
1505
|
await attachFigureImages(env, messages, usedHits, q.query);
|
|
1505
1506
|
// the agent loop (the owner's 2026-09-28 direction): ONE bounded tool
|
|
@@ -1953,7 +1954,7 @@ let convEntities: Array<{ entity: string; kind: string }> = [];
|
|
|
1953
1954
|
...(routeSubset ? { stageSubset: routeSubset ?? undefined } : {}),
|
|
1954
1955
|
});
|
|
1955
1956
|
if (retryRetrieve.hits.length > 0) {
|
|
1956
|
-
const { messages: retryMessages, usedHits: retryUsed } = buildMessages(q.query, retryRetrieve.hits, q.lang, keptHistory, undefined, summary, budget);
|
|
1957
|
+
const { messages: retryMessages, usedHits: retryUsed } = buildMessages(q.query, retryRetrieve.hits, q.lang, keptHistory, undefined, summary, budget, ablate?.compress === true);
|
|
1957
1958
|
const retryAnswer = await generateOnce(env, model, retryMessages, routeEffort(routed.route));
|
|
1958
1959
|
// the answer now comes from the retry passages — citations must follow
|
|
1959
1960
|
if (retryAnswer) {
|
|
@@ -1993,7 +1994,7 @@ let convEntities: Array<{ entity: string; kind: string }> = [];
|
|
|
1993
1994
|
}
|
|
1994
1995
|
|
|
1995
1996
|
// figure completion (#172) — see ./completion for the rationale
|
|
1996
|
-
completionBlocks.push(...(await completeFigures(env.DB, answer!, [...c2ns.blocks, ...completionBlocks], used)));
|
|
1997
|
+
completionBlocks.push(...(await completeFigures(env.DB, answer!, [...c2ns.blocks, ...completionBlocks], used, q.query)));
|
|
1997
1998
|
|
|
1998
1999
|
// the blind-answer regeneration (2026-10-03, live on the photo case):
|
|
1999
2000
|
// the multimodal call can answer AROUND an attached image — a 200 whose
|
|
@@ -59,6 +59,7 @@ export async function completeFigures(
|
|
|
59
59
|
answer: string,
|
|
60
60
|
alreadyAttached: ResolvedBlock[],
|
|
61
61
|
used: Hit[] = [],
|
|
62
|
+
query?: string,
|
|
62
63
|
): Promise<ResolvedBlock[]> {
|
|
63
64
|
// the model names figures BOTH ways: unit ids (u:fig-3) and bare
|
|
64
65
|
// producer anchors (fig-2a of D 36) — collect both forms; bare
|
|
@@ -74,6 +75,18 @@ export async function completeFigures(
|
|
|
74
75
|
(answer.match(/\bFig(?:ure|\.)s?\s*([0-9]{1,2}[a-z]?)/g) ?? [])
|
|
75
76
|
.map((x) => x.replace(/\bFig(?:ure|\.)s?\s*/i, "").toLowerCase()),
|
|
76
77
|
);
|
|
78
|
+
// the figure-SEEKING question (the MKO typed units carry UUID ids —
|
|
79
|
+
// no fig-N the model could name, and "sketch"/"drawing" prose the
|
|
80
|
+
// prose-number scan cannot see): when the question asks about a
|
|
81
|
+
// figure and a figure unit grounded the answer, the contract
|
|
82
|
+
// completes with THAT unit — the tables' mechanical philosophy, not
|
|
83
|
+
// a hope that the model names an unnameable id
|
|
84
|
+
if (query && /\bfig(ure|s)?\b/i.test(query)) {
|
|
85
|
+
for (const h of used.slice(0, 12)) {
|
|
86
|
+
if (h.metadata.unit_id && h.metadata.block === "figure") mentioned.push(h.metadata.unit_id);
|
|
87
|
+
}
|
|
88
|
+
mentioned = [...new Set(mentioned)].slice(0, 6);
|
|
89
|
+
}
|
|
77
90
|
if (proseNums.size) {
|
|
78
91
|
const fams = [...new Set(used.map((h) => h.metadata.docidentifier).filter(Boolean))].slice(0, 3);
|
|
79
92
|
for (const fam of fams) {
|
|
@@ -78,6 +78,9 @@ export const THRESHOLDS = {
|
|
|
78
78
|
* then states a measurement — claim support in the cited passages —
|
|
79
79
|
* not only the source rung. Fails open (a slow or unparseable check
|
|
80
80
|
* leaves the source-rung note unchanged). */
|
|
81
|
+
// the extractive compression arm (TODO.sota/02 row 5): when ablated
|
|
82
|
+
// on, each passage body is compressed to this share of its budget
|
|
83
|
+
compressShare: 0.6,
|
|
81
84
|
entailmentGate: true,
|
|
82
85
|
entailmentBudgetMs: 6000,
|
|
83
86
|
entailmentSupportedFloor: 0.9,
|
|
@@ -5,6 +5,7 @@ import systemPromptText from "../prompts/system.md";
|
|
|
5
5
|
import conversationalPromptText from "../prompts/conversational.md";
|
|
6
6
|
import listwisePromptText from "../prompts/listwise.md";
|
|
7
7
|
import { tableSelection } from "./tablecontext";
|
|
8
|
+
import { compressText } from "./compress";
|
|
8
9
|
|
|
9
10
|
// the pinned refusal sentence lives with the canonicalizer in ./refusal
|
|
10
11
|
// (refusals are never cached: a refusal says "retrieval found nothing",
|
|
@@ -287,6 +288,10 @@ export function buildMessages(
|
|
|
287
288
|
retrievalNote?: string,
|
|
288
289
|
conversationSummary?: string,
|
|
289
290
|
budgetTokens: number = LIMITS.inputTokenBudget,
|
|
291
|
+
/** the extractive compression arm (TODO.sota/02 row 5): ablate_compress
|
|
292
|
+
* arms it per ask — each passage body becomes query-weighted sentence
|
|
293
|
+
* selection at compressShare of its budget. Off in serving. */
|
|
294
|
+
compress?: boolean,
|
|
290
295
|
): BuiltMessages {
|
|
291
296
|
// per-corpus guidance travels WITH the dataset (config.ts): every
|
|
292
297
|
// dataset whose corpus appears in the passages contributes its note —
|
|
@@ -365,7 +370,12 @@ export function buildMessages(
|
|
|
365
370
|
// the drawing and a reason to cite the unit; absent for every other
|
|
366
371
|
// block type and for uncaptioned figures
|
|
367
372
|
const figDesc = (h.metadata as any).block === "figure" ? String((h.metadata as any).figure_description ?? "").trim() : "";
|
|
368
|
-
|
|
373
|
+
// the compression arm replaces clipping: the query-weighted extractor
|
|
374
|
+
// bounds the text itself (deterministic, never grows it); clipping
|
|
375
|
+
// stays the default
|
|
376
|
+
const raw = compress
|
|
377
|
+
? compressText(String(pruned ?? h.text ?? ""), query, Math.floor(LIMITS.maxPassageTokens * 4 * THRESHOLDS.compressShare))
|
|
378
|
+
: clipToTokens(pruned ?? h.text, LIMITS.maxPassageTokens);
|
|
369
379
|
const body = figDesc ? `${raw}\nCaption: ${figDesc}` : raw;
|
|
370
380
|
const t = estTokens(head) + estTokens(body);
|
|
371
381
|
if (t <= remain) {
|
|
@@ -15,7 +15,18 @@ export interface ResolvedBlock {
|
|
|
15
15
|
payload: Record<string, unknown>;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
// The passage headers show `unit u:<id> (table)`, so the model copies
|
|
19
|
+
// the WHOLE prefixed id into the token — `[[u:u:<id>]]` — and the inner
|
|
20
|
+
// colon makes the strict grammar unparseable: neither resolved nor
|
|
21
|
+
// sanitized, the raw token leaked to the client (observed live on the
|
|
22
|
+
// R 134-2 figure question, 0.2.162). The grammar tolerates the doubled
|
|
23
|
+
// prefix; normalizeRef folds it back to the single form every other
|
|
24
|
+
// layer keys on.
|
|
25
|
+
const REF = /\[\[(u:(?:u:)?[A-Za-z0-9_-]+)\]\]/g;
|
|
26
|
+
|
|
27
|
+
function normalizeRef(id: string): string {
|
|
28
|
+
return id.startsWith("u:u:") ? id.slice(2) : id;
|
|
29
|
+
}
|
|
19
30
|
|
|
20
31
|
/** unit ids the passages actually contain (chunk metadata carries
|
|
21
32
|
* unit_id on typed MKO chunks). */
|
|
@@ -29,16 +40,19 @@ export function availableUnitIds(hits: ReadonlyArray<{ metadata: { unit_id?: str
|
|
|
29
40
|
}
|
|
30
41
|
|
|
31
42
|
export function parseRefs(text: string): string[] {
|
|
32
|
-
return [...text.matchAll(REF)].map((m) => m[1]);
|
|
43
|
+
return [...text.matchAll(REF)].map((m) => normalizeRef(m[1]));
|
|
33
44
|
}
|
|
34
45
|
|
|
35
46
|
/** Drop refs that don't resolve to a used passage unit — a dangling ref
|
|
36
47
|
* renders as nothing (the token removed), and the violation is logged. */
|
|
37
48
|
export function sanitizeRefs(text: string, available: ReadonlySet<string>): { text: string; dropped: string[] } {
|
|
38
49
|
const dropped: string[] = [];
|
|
39
|
-
const out = text.replace(REF, (
|
|
40
|
-
|
|
41
|
-
|
|
50
|
+
const out = text.replace(REF, (_full, id: string) => {
|
|
51
|
+
const normalized = normalizeRef(id);
|
|
52
|
+
// normalized already carries the single "u:" prefix — the template
|
|
53
|
+
// must not add another
|
|
54
|
+
if (available.has(normalized)) return `[[${normalized}]]`;
|
|
55
|
+
dropped.push(normalized);
|
|
42
56
|
return "";
|
|
43
57
|
});
|
|
44
58
|
return { text: out, dropped };
|
package/dist/ask-ND63B3CF.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
handleAsk
|
|
3
|
-
} from "./chunk-AEVDR7DA.js";
|
|
4
|
-
import "./chunk-ECOYO7EX.js";
|
|
5
|
-
import "./chunk-PBHMQZKA.js";
|
|
6
|
-
import "./chunk-MTIAHAOK.js";
|
|
7
|
-
import "./chunk-NI4CIK6W.js";
|
|
8
|
-
import "./chunk-W7J5SFXJ.js";
|
|
9
|
-
import "./chunk-ETLSWSZ7.js";
|
|
10
|
-
import "./chunk-4NXH5ZI6.js";
|
|
11
|
-
import "./chunk-VT7DR6NQ.js";
|
|
12
|
-
import "./chunk-3FYJM7LH.js";
|
|
13
|
-
import "./chunk-LSZTJI7V.js";
|
|
14
|
-
export {
|
|
15
|
-
handleAsk
|
|
16
|
-
};
|
package/dist/search-FW5O32BY.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
handleSearch
|
|
3
|
-
} from "./chunk-IGAGXQHV.js";
|
|
4
|
-
import "./chunk-MTIAHAOK.js";
|
|
5
|
-
import "./chunk-NI4CIK6W.js";
|
|
6
|
-
import "./chunk-W7J5SFXJ.js";
|
|
7
|
-
import "./chunk-ETLSWSZ7.js";
|
|
8
|
-
import "./chunk-4NXH5ZI6.js";
|
|
9
|
-
import "./chunk-VT7DR6NQ.js";
|
|
10
|
-
import "./chunk-3FYJM7LH.js";
|
|
11
|
-
import "./chunk-LSZTJI7V.js";
|
|
12
|
-
export {
|
|
13
|
-
handleSearch
|
|
14
|
-
};
|