@konneal/engine 0.2.115 → 0.2.117
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/{ask-RLMNWTHA.js → ask-2XVGJYUK.js} +2 -2
- package/dist/{chunk-MUAY4BXY.js → chunk-ABHZUXZ5.js} +1 -1
- package/dist/{chunk-ZD7SNNGW.js → chunk-CTUT57OK.js} +1 -1
- package/dist/{chunk-A6YQYN3O.js → chunk-KRSSSTMV.js} +21 -1
- package/dist/{search-AH4A4SFJ.js → search-GGSBFGQ5.js} +2 -2
- package/dist/worker_public/src/index.js +4 -4
- package/package.json +1 -1
- package/workers/worker_public/src/stages/seal.ts +44 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
handleAsk
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-ABHZUXZ5.js";
|
|
4
4
|
import "./chunk-32UDKBA2.js";
|
|
5
|
-
import "./chunk-
|
|
5
|
+
import "./chunk-KRSSSTMV.js";
|
|
6
6
|
import "./chunk-TH5XGPD5.js";
|
|
7
7
|
import "./chunk-DJ65EF5G.js";
|
|
8
8
|
import "./chunk-A3QHHUN5.js";
|
|
@@ -22694,15 +22694,35 @@ var federate = {
|
|
|
22694
22694
|
};
|
|
22695
22695
|
|
|
22696
22696
|
// workers/worker_public/src/stages/seal.ts
|
|
22697
|
+
async function familyChunks(env, familyNumber, query, keep) {
|
|
22698
|
+
const match2 = ftsMatchQuery(query) ?? `"${familyNumber}"`;
|
|
22699
|
+
const rows = await portStore(env).prepare(
|
|
22700
|
+
"SELECT id, doc_id, docidentifier, doctype, doc_number, edition, language, clause_anchor, clause_title, status, superseded_by, corpus, tier, text, unit_id, block, bm25(chunks_fts) AS rank FROM chunks_fts JOIN chunks c ON c.rowid = chunks_fts.rowid WHERE chunks_fts MATCH ?1 AND c.doc_number = ?2 ORDER BY rank LIMIT ?3"
|
|
22701
|
+
).bind(match2, familyNumber, keep * 4).all().catch(() => ({ results: [] }));
|
|
22702
|
+
return (rows.results ?? []).map((r) => ({
|
|
22703
|
+
id: String(r.id),
|
|
22704
|
+
score: 0,
|
|
22705
|
+
metadata: r,
|
|
22706
|
+
text: String(r.text ?? "")
|
|
22707
|
+
}));
|
|
22708
|
+
}
|
|
22697
22709
|
var seal = {
|
|
22698
22710
|
name: "seal",
|
|
22699
22711
|
when: (c) => !!c.opts.sealScope || !!c.opts.editionSteer || !!c.opts.editionExclude,
|
|
22700
|
-
run: (c) => {
|
|
22712
|
+
run: async (c) => {
|
|
22701
22713
|
const before = c.hits.length;
|
|
22702
22714
|
const scope = c.opts.sealScope;
|
|
22703
22715
|
if (scope) {
|
|
22704
22716
|
c.hits = c.hits.filter((h) => matchesDocScope(h.metadata, scope.doc_number) && (!scope.edition || h.metadata.edition === scope.edition));
|
|
22705
22717
|
console.log("context seal:", before, "\u2192", c.hits.length, "candidates within", `doc#${scope.doc_number}${scope.edition ? "@" + scope.edition : ""}`);
|
|
22718
|
+
if (c.hits.length === 0) {
|
|
22719
|
+
const familyNumber = scope.doc_number.includes("-") ? scope.doc_number.split("-")[0] : scope.doc_number;
|
|
22720
|
+
const pulled = (await familyChunks(c.env, familyNumber, c.rq || c.query, 12)).filter((h) => matchesDocScope(h.metadata, scope.doc_number) && (!scope.edition || h.metadata.edition === scope.edition)).slice(0, 8).map((h) => ({ ...h, score: 0.5 }));
|
|
22721
|
+
if (pulled.length) {
|
|
22722
|
+
c.hits = pulled;
|
|
22723
|
+
console.log("context seal: pool empty \u2014 pulled", pulled.length, "family chunks from the corpus for", `doc#${scope.doc_number}`);
|
|
22724
|
+
}
|
|
22725
|
+
}
|
|
22706
22726
|
return;
|
|
22707
22727
|
}
|
|
22708
22728
|
const exclude = c.opts.editionExclude;
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
handleMemories,
|
|
5
5
|
scoreFaithfulness,
|
|
6
6
|
scoreJudge
|
|
7
|
-
} from "../../chunk-
|
|
7
|
+
} from "../../chunk-ABHZUXZ5.js";
|
|
8
8
|
import {
|
|
9
9
|
TOOLS_REGISTRY,
|
|
10
10
|
bindModelNode,
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from "../../chunk-32UDKBA2.js";
|
|
13
13
|
import {
|
|
14
14
|
handleSearch
|
|
15
|
-
} from "../../chunk-
|
|
15
|
+
} from "../../chunk-CTUT57OK.js";
|
|
16
16
|
import {
|
|
17
17
|
buildMessages,
|
|
18
18
|
citations,
|
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
sessionFrom,
|
|
35
35
|
telemetry,
|
|
36
36
|
understandQuery
|
|
37
|
-
} from "../../chunk-
|
|
37
|
+
} from "../../chunk-KRSSSTMV.js";
|
|
38
38
|
import {
|
|
39
39
|
cfBlobs,
|
|
40
40
|
embed,
|
|
@@ -1000,7 +1000,7 @@ async function callToolOnce(env, ctx, _req, tier, key, name, args, t0) {
|
|
|
1000
1000
|
const r = await runTool({ ...env, DB: env.DB }, { name, args }, "mcp");
|
|
1001
1001
|
payload = r ? { tool: r.name, query: r.query, result: r.output } : { error: { message: `tool ${name} returned nothing for the given arguments` } };
|
|
1002
1002
|
} else {
|
|
1003
|
-
const res = name === "ask" ? await (await import("../../ask-
|
|
1003
|
+
const res = name === "ask" ? await (await import("../../ask-2XVGJYUK.js")).handleAsk(env, ctx, inner, tier, key) : await (await import("../../search-GGSBFGQ5.js")).handleSearch(env, ctx, inner, tier, key);
|
|
1004
1004
|
payload = await res.json().catch(() => ({ error: { message: "tool transport failed", status: res.status } }));
|
|
1005
1005
|
}
|
|
1006
1006
|
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.117",
|
|
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",
|
|
@@ -3,17 +3,60 @@
|
|
|
3
3
|
// outside the declared family competes for the window; everything
|
|
4
4
|
// inside it does.
|
|
5
5
|
import { matchesDocScope } from "../context.ts";
|
|
6
|
+
import { portStore } from "../env.ts";
|
|
7
|
+
import { ftsMatchQuery } from "../lexical.ts";
|
|
8
|
+
import type { ChunkMeta, Hit } from "../../../shared/chunk";
|
|
6
9
|
import type { Stage } from "./types.ts";
|
|
7
10
|
|
|
11
|
+
/** The sealed family's chunks, from the D1 corpus directly (the l6a
|
|
12
|
+
* law): the declared context's guarantee is that the publication CAN
|
|
13
|
+
* answer — a generic question's global ranking need not contain the
|
|
14
|
+
* family at all, so an emptied pool pulls the family's own text. */
|
|
15
|
+
async function familyChunks(env: any, familyNumber: string, query: string, keep: number): Promise<Hit[]> {
|
|
16
|
+
// ftsMatchQuery's OR shape: FTS5's implicit AND over a question's
|
|
17
|
+
// tokens matches nothing on standards prose (measured: 0 rows for
|
|
18
|
+
// the exact ask that needed this pull; the OR shape returns the
|
|
19
|
+
// family). Fetch wide — the edition filter downstream keeps only the
|
|
20
|
+
// declared edition, and the ranking then does its work.
|
|
21
|
+
const match = ftsMatchQuery(query) ?? `"${familyNumber}"`;
|
|
22
|
+
const rows = await portStore(env).prepare(
|
|
23
|
+
"SELECT id, doc_id, docidentifier, doctype, doc_number, edition, language, clause_anchor, clause_title, status, superseded_by, corpus, tier, text, unit_id, block, bm25(chunks_fts) AS rank FROM chunks_fts JOIN chunks c ON c.rowid = chunks_fts.rowid WHERE chunks_fts MATCH ?1 AND c.doc_number = ?2 ORDER BY rank LIMIT ?3",
|
|
24
|
+
)
|
|
25
|
+
.bind(match, familyNumber, keep * 4)
|
|
26
|
+
.all()
|
|
27
|
+
.catch(() => ({ results: [] }));
|
|
28
|
+
return (rows.results ?? []).map((r: any) => ({
|
|
29
|
+
id: String(r.id),
|
|
30
|
+
score: 0,
|
|
31
|
+
metadata: r as unknown as ChunkMeta,
|
|
32
|
+
text: String(r.text ?? ""),
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
|
|
8
36
|
export const seal: Stage = {
|
|
9
37
|
name: "seal",
|
|
10
38
|
when: (c) => !!c.opts.sealScope || !!c.opts.editionSteer || !!c.opts.editionExclude,
|
|
11
|
-
run: (c) => {
|
|
39
|
+
run: async (c) => {
|
|
12
40
|
const before = c.hits.length;
|
|
13
41
|
const scope = c.opts.sealScope!;
|
|
14
42
|
if (scope) {
|
|
15
43
|
c.hits = c.hits.filter((h) => matchesDocScope(h.metadata, scope.doc_number) && (!scope.edition || h.metadata.edition === scope.edition));
|
|
16
44
|
console.log("context seal:", before, "→", c.hits.length, "candidates within", `doc#${scope.doc_number}${scope.edition ? "@" + scope.edition : ""}`);
|
|
45
|
+
if (c.hits.length === 0) {
|
|
46
|
+
// the declared-context guarantee: the family's own text enters
|
|
47
|
+
// even when no global ranking carried it — the FTS ranking over
|
|
48
|
+
// the family grain (the part identity steers by docidentifier
|
|
49
|
+
// downstream, the same grain law matchesDocScope enforces)
|
|
50
|
+
const familyNumber = scope.doc_number.includes("-") ? scope.doc_number.split("-")[0] : scope.doc_number;
|
|
51
|
+
const pulled = (await familyChunks(c.env, familyNumber, c.rq || c.query, 12))
|
|
52
|
+
.filter((h) => matchesDocScope(h.metadata, scope.doc_number) && (!scope.edition || h.metadata.edition === scope.edition))
|
|
53
|
+
.slice(0, 8)
|
|
54
|
+
.map((h) => ({ ...h, score: 0.5 }));
|
|
55
|
+
if (pulled.length) {
|
|
56
|
+
c.hits = pulled;
|
|
57
|
+
console.log("context seal: pool empty — pulled", pulled.length, "family chunks from the corpus for", `doc#${scope.doc_number}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
17
60
|
return;
|
|
18
61
|
}
|
|
19
62
|
const exclude = c.opts.editionExclude!;
|