@konneal/engine 0.2.27 → 0.2.28

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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  handleAsk
3
- } from "./chunk-JVN6SQAT.js";
3
+ } from "./chunk-INCFGVH3.js";
4
4
  import "./chunk-4G5OGWXY.js";
5
5
  import "./chunk-2RKYO3OC.js";
6
6
  import "./chunk-A3QHHUN5.js";
@@ -2367,6 +2367,8 @@ export {
2367
2367
  handleMemories,
2368
2368
  checkQuoteAnchors,
2369
2369
  standardForDocNumber,
2370
+ bindModelNode,
2371
+ modelGroundingBlock,
2370
2372
  scoreJudge,
2371
2373
  handleAsk
2372
2374
  };
@@ -2,12 +2,14 @@ import {
2
2
  handleSearch
3
3
  } from "../../chunk-5LCPKJ6V.js";
4
4
  import {
5
+ bindModelNode,
5
6
  checkQuoteAnchors,
6
7
  handleAsk,
7
8
  handleMemories,
9
+ modelGroundingBlock,
8
10
  scoreJudge,
9
11
  standardForDocNumber
10
- } from "../../chunk-JVN6SQAT.js";
12
+ } from "../../chunk-INCFGVH3.js";
11
13
  import {
12
14
  buildMessages,
13
15
  citations,
@@ -25,6 +27,7 @@ import {
25
27
  parseAppliedContext,
26
28
  portModelRunner,
27
29
  promptVars,
30
+ refCodec,
28
31
  retrieve,
29
32
  sessionFrom,
30
33
  telemetry,
@@ -390,7 +393,7 @@ function parseVerdict(text) {
390
393
 
391
394
  // workers/worker_public/src/faithfulness-context.ts
392
395
  function buildJudgeContext(passages, machine = []) {
393
- const context = passages.slice(0, 8).map((p, i) => `[${i + 1}] ${p.replace(/\s+/g, " ").slice(0, 900)}`).join("\n");
396
+ const context = passages.slice(0, 8).map((p, i) => `[${i + 1}] ${p.replace(/\s+/g, " ").slice(0, 1400)}`).join("\n");
394
397
  const machineContext = machine.length ? "\n" + machine.slice(0, 6).map((m) => `[M] ${m.replace(/\s+/g, " ").slice(0, 400)}`).join("\n") : "";
395
398
  return context + machineContext;
396
399
  }
@@ -989,7 +992,7 @@ async function handleMcp(env, ctx, req, tier, key) {
989
992
  // stream:false forces the JSON lane (anon defaults to SSE)
990
993
  body: JSON.stringify({ ...args, stream: false })
991
994
  });
992
- const res = name === "ask" ? await (await import("../../ask-Y7L6MDAV.js")).handleAsk(env, ctx, inner, tier, key) : await (await import("../../search-4UK3RBEQ.js")).handleSearch(env, ctx, inner, tier, key);
995
+ const res = name === "ask" ? await (await import("../../ask-KELYM6RJ.js")).handleAsk(env, ctx, inner, tier, key) : await (await import("../../search-4UK3RBEQ.js")).handleSearch(env, ctx, inner, tier, key);
993
996
  return res.json().catch(() => ({ error: { message: "tool transport failed", status: res.status } }));
994
997
  });
995
998
  if (out.ok && "accepted" in out) return new Response(null, { status: 202 });
@@ -1448,7 +1451,18 @@ async function verifyRoute(c) {
1448
1451
  if (!answer || !query) return err(400, "invalid_input", "answer and query are required");
1449
1452
  try {
1450
1453
  const u = await understandQuery(env.AI, roleModel(env, "understand"), query, [], []);
1451
- const retrieved = await retrieve(env, query, { understanding: u, standardKeys: entitlementScope(standardKeysFrom(body)) });
1454
+ let lexicalBoost;
1455
+ try {
1456
+ const fam = u?.doc_number ? refCodec().familyOf(u.doc_number) : null;
1457
+ if (fam) {
1458
+ const row = await env.DB.prepare("SELECT edition FROM documents WHERE family = ?1 AND active = 1 ORDER BY edition DESC LIMIT 1").bind(fam).first().catch(() => null);
1459
+ if (row?.edition) lexicalBoost = String(row.edition);
1460
+ }
1461
+ } catch {
1462
+ }
1463
+ const bound = await bindModelNode(env, { query, standardKeys: entitlementScope(standardKeysFrom(body)) });
1464
+ const modelGrounding = bound && !bound.gated ? modelGroundingBlock(bound) : null;
1465
+ const retrieved = await retrieve(env, query, { understanding: u, standardKeys: entitlementScope(standardKeysFrom(body)), lexicalBoost });
1452
1466
  const passages = retrieved.hits.map((h) => h.text);
1453
1467
  const anchors = checkQuoteAnchors(answer, passages);
1454
1468
  const refs = [...answer.matchAll(/\[\[u:([^\]]+)\]\]/g)].map((m) => m[1]);
@@ -1459,6 +1473,7 @@ async function verifyRoute(c) {
1459
1473
  { name: "citations_present", deterministic: true, pass: new RegExp(`\\[[^\\]]*(${P().publisher.name})[^\\]]*\\]`).test(answer), detail: "normative claims should carry a passage citation" }
1460
1474
  ];
1461
1475
  const machine = (Array.isArray(body?.blocks) ? body.blocks : []).filter((b) => b?.type === "verdict" && b?.payload).map((b) => [b.payload.check, b.payload.meaning, b.payload.definition, b.payload.violation_meaning].filter((x) => typeof x === "string" && x).join(" \u2014 ")).filter(Boolean);
1476
+ if (modelGrounding) machine.unshift(modelGrounding);
1462
1477
  const faith = await scoreFaithfulness(env.AI, roleModel(env, "grader"), answer, retrieved.hits.map((h) => h.text), machine);
1463
1478
  return json({
1464
1479
  checks,
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.27",
30
+ "version": "0.2.28",
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",
@@ -7,7 +7,7 @@
7
7
  export function buildJudgeContext(passages: string[], machine: string[] = []): string {
8
8
  const context = passages
9
9
  .slice(0, 8)
10
- .map((p, i) => `[${i + 1}] ${p.replace(/\s+/g, " ").slice(0, 900)}`)
10
+ .map((p, i) => `[${i + 1}] ${p.replace(/\s+/g, " ").slice(0, 1400)}`)
11
11
  .join("\n");
12
12
  const machineContext = machine.length
13
13
  ? "\n" + machine.slice(0, 6).map((m) => `[M] ${m.replace(/\s+/g, " ").slice(0, 400)}`).join("\n")
@@ -13,7 +13,8 @@ import { ftsMatchQuery } from "./lexical";
13
13
  import { scoreFaithfulness } from "./faithfulness";
14
14
  import { checkQuoteAnchors } from "./anchors";
15
15
  import { namedDocumentIn } from "./context";
16
- import { standardForDocNumber } from "./modelplane";
16
+ import { standardForDocNumber, bindModelNode, modelGroundingBlock } from "./modelplane";
17
+ import { refCodec } from "./codecs";
17
18
  import { entitlementScope, standardKeysFrom } from "./requestScope";
18
19
  import type { Env } from "./env";
19
20
  export type { Env };
@@ -228,7 +229,24 @@ async function verifyRoute(c: RouteContext): Promise<Response> {
228
229
  if (!answer || !query) return err(400, "invalid_input", "answer and query are required");
229
230
  try {
230
231
  const u = await understandQuery(env.AI, roleModel(env, "understand"), query, [], []);
231
- const retrieved = await retrieve(env, query, { understanding: u, standardKeys: entitlementScope(standardKeysFrom(body)) });
232
+ // the grounding must MIRROR the ask path's: the edition boost (the
233
+ // publication's active edition, the codec's family) and the model
234
+ // grounding — a verify that grounds against different passages than
235
+ // the answer used judges a different answer
236
+ let lexicalBoost: string | undefined;
237
+ try {
238
+ const fam = u?.doc_number ? refCodec().familyOf(u.doc_number) : null;
239
+ if (fam) {
240
+ const row = await env.DB.prepare("SELECT edition FROM documents WHERE family = ?1 AND active = 1 ORDER BY edition DESC LIMIT 1")
241
+ .bind(fam).first().catch(() => null);
242
+ if (row?.edition) lexicalBoost = String(row.edition);
243
+ }
244
+ } catch {
245
+ // degrade to unsteered retrieval
246
+ }
247
+ const bound = await bindModelNode(env, { query, standardKeys: entitlementScope(standardKeysFrom(body)) });
248
+ const modelGrounding = bound && !bound.gated ? modelGroundingBlock(bound) : null;
249
+ const retrieved = await retrieve(env, query, { understanding: u, standardKeys: entitlementScope(standardKeysFrom(body)), lexicalBoost });
232
250
  const passages = retrieved.hits.map((h: Hit) => h.text);
233
251
  const anchors = checkQuoteAnchors(answer, passages);
234
252
  const refs = [...answer.matchAll(/\[\[u:([^\]]+)\]\]/g)].map((m) => m[1]);
@@ -246,6 +264,7 @@ async function verifyRoute(c: RouteContext): Promise<Response> {
246
264
  .map((b: any) => [b.payload.check, b.payload.meaning, b.payload.definition, b.payload.violation_meaning]
247
265
  .filter((x: unknown) => typeof x === "string" && x).join(" — "))
248
266
  .filter(Boolean);
267
+ if (modelGrounding) machine.unshift(modelGrounding);
249
268
  const faith = await scoreFaithfulness(env.AI, roleModel(env, "grader"), answer, retrieved.hits.map((h: Hit) => h.text), machine);
250
269
  return json({
251
270
  checks,