@konneal/engine 0.2.134 → 0.2.135
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-PFU74MIP.js → ask-JX55WMFR.js} +2 -2
- package/dist/{chunk-JYJJ4SYF.js → chunk-27NZR4HF.js} +4 -3
- package/dist/{chunk-WPOKSNPE.js → chunk-XBZIJMS7.js} +6 -1
- package/dist/refusal.d.ts +8 -0
- package/dist/{search-NIRCPRMW.js → search-LFS5HHMZ.js} +1 -1
- package/dist/worker_public/src/index.js +3 -3
- package/dist/worker_public/src/refusal.js +3 -1
- package/package.json +1 -1
- package/workers/worker_public/src/ask.ts +3 -3
- package/workers/worker_public/src/refusal.ts +12 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
handleAsk
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-27NZR4HF.js";
|
|
4
4
|
import "./chunk-J6LBR6GI.js";
|
|
5
5
|
import "./chunk-7AXXR7GD.js";
|
|
6
6
|
import "./chunk-TH5XGPD5.js";
|
|
7
7
|
import "./chunk-W7J5SFXJ.js";
|
|
8
|
-
import "./chunk-
|
|
8
|
+
import "./chunk-XBZIJMS7.js";
|
|
9
9
|
import "./chunk-4NXH5ZI6.js";
|
|
10
10
|
import "./chunk-VT7DR6NQ.js";
|
|
11
11
|
import "./chunk-GBGRHXRU.js";
|
|
@@ -80,10 +80,11 @@ import {
|
|
|
80
80
|
validateQuery
|
|
81
81
|
} from "./chunk-W7J5SFXJ.js";
|
|
82
82
|
import {
|
|
83
|
+
cacheableAnswer,
|
|
83
84
|
canonicalRefusal,
|
|
84
85
|
exciseMisplacedPin,
|
|
85
86
|
refusalAnswer
|
|
86
|
-
} from "./chunk-
|
|
87
|
+
} from "./chunk-XBZIJMS7.js";
|
|
87
88
|
import {
|
|
88
89
|
entitlementScope,
|
|
89
90
|
requestSalt,
|
|
@@ -2659,7 +2660,7 @@ ${q.query}`.replace("\n\n\n\n", "\n\n") }];
|
|
|
2659
2660
|
if (streamed.violations.length > 0) {
|
|
2660
2661
|
console.log("anchors:", streamed.violations.length, "of", streamed.total, "unverified \u2014 not caching");
|
|
2661
2662
|
}
|
|
2662
|
-
if (streamed.violations.length === 0 && canonical.length > 0 && !contextual && !declaredCtx &&
|
|
2663
|
+
if (streamed.violations.length === 0 && canonical.length > 0 && !contextual && !declaredCtx && cacheableAnswer(canonical, refusalScope(usedHits.length > 0)) && !ablate) {
|
|
2663
2664
|
ctx.waitUntil(
|
|
2664
2665
|
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 })
|
|
2665
2666
|
);
|
|
@@ -2807,7 +2808,7 @@ ${q.query}`.replace("\n\n\n\n", "\n\n") }];
|
|
|
2807
2808
|
}
|
|
2808
2809
|
}
|
|
2809
2810
|
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: understanding?.follow_ups ?? [], blocks: [...c2ns.blocks, ...verdictBlock ? [verdictBlock] : [], ...conditionBlock ? [conditionBlock] : [], ...aggregationBlock ? [aggregationBlock] : [], ...registerBlock ? [registerBlock] : [], ...completionBlocks], context_applied: ctxApplied, ...liveRecords ? { records: liveRecords } : {}, ...ablate ? { ablate } : {}, route: { route: routed.route, features: routed.features } };
|
|
2810
|
-
const cacheable = !contextual && !declaredCtx && !ablate &&
|
|
2811
|
+
const cacheable = !contextual && !declaredCtx && !ablate && cacheableAnswer(answer, refusalScope(usedHits.length > 0)) && finalAnchors.violations.length === 0;
|
|
2811
2812
|
if (cacheable) {
|
|
2812
2813
|
const ck = exactCacheKey(env.INDEX_VERSION, gen, ns, await sha256Hex(cacheKeyMaterial(q.query, q.lang, salt)));
|
|
2813
2814
|
ctx.waitUntil(env.CACHE.put(ck, JSON.stringify(out), { expirationTtl: LIMITS.cacheTtlSec }));
|
|
@@ -97,9 +97,14 @@ function exciseMisplacedPin(answer, cites) {
|
|
|
97
97
|
}
|
|
98
98
|
return out.replace(/^[ \t\n]+/, "").replace(/\n{3,}/g, "\n\n").trim();
|
|
99
99
|
}
|
|
100
|
+
function cacheableAnswer(answer, scope) {
|
|
101
|
+
if (answer.includes(refusalAnswer())) return false;
|
|
102
|
+
return canonicalRefusal(answer, scope) === answer;
|
|
103
|
+
}
|
|
100
104
|
|
|
101
105
|
export {
|
|
102
106
|
refusalAnswer,
|
|
103
107
|
canonicalRefusal,
|
|
104
|
-
exciseMisplacedPin
|
|
108
|
+
exciseMisplacedPin,
|
|
109
|
+
cacheableAnswer
|
|
105
110
|
};
|
package/dist/refusal.d.ts
CHANGED
|
@@ -32,3 +32,11 @@ export declare function canonicalRefusal(answer: string, scope?: RefusalScope):
|
|
|
32
32
|
* the pin sentence (and its refusal-shaped paraphrases) are excised —
|
|
33
33
|
* the surrounding content stands on its own. */
|
|
34
34
|
export declare function exciseMisplacedPin(answer: string, cites: boolean): string;
|
|
35
|
+
/** Cacheable under the refusal law (2026-10-11, the poisoned-entry
|
|
36
|
+
* lesson): "refusals are never cached" was enforced as "answers
|
|
37
|
+
* containing the pin are never cached" — backwards for DRIFT, which
|
|
38
|
+
* lacks the pin and cached itself across deploy windows (an edge
|
|
39
|
+
* instance running pre-wall code wrote a drifted refusal that served
|
|
40
|
+
* every later ask). An answer is cacheable only when it carries no
|
|
41
|
+
* pin AND the wall would not rewrite it. */
|
|
42
|
+
export declare function cacheableAnswer(answer: string, scope?: RefusalScope): boolean;
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
handleMemories,
|
|
5
5
|
scoreFaithfulness,
|
|
6
6
|
scoreJudge
|
|
7
|
-
} from "../../chunk-
|
|
7
|
+
} from "../../chunk-27NZR4HF.js";
|
|
8
8
|
import {
|
|
9
9
|
TOOLS_REGISTRY,
|
|
10
10
|
bindModelNode,
|
|
@@ -54,7 +54,7 @@ import {
|
|
|
54
54
|
} from "../../chunk-W7J5SFXJ.js";
|
|
55
55
|
import {
|
|
56
56
|
canonicalRefusal
|
|
57
|
-
} from "../../chunk-
|
|
57
|
+
} from "../../chunk-XBZIJMS7.js";
|
|
58
58
|
import {
|
|
59
59
|
entitlementScope,
|
|
60
60
|
standardKeysFrom
|
|
@@ -1052,7 +1052,7 @@ async function callToolOnce(env, ctx, _req, tier, key, name, args, t0) {
|
|
|
1052
1052
|
const r = await runTool({ ...env, DB: env.DB }, { name, args }, "mcp");
|
|
1053
1053
|
payload = r ? { tool: r.name, query: r.query, result: r.output } : { error: { message: `tool ${name} returned nothing for the given arguments` } };
|
|
1054
1054
|
} else {
|
|
1055
|
-
const res = name === "ask" ? await (await import("../../ask-
|
|
1055
|
+
const res = name === "ask" ? await (await import("../../ask-JX55WMFR.js")).handleAsk(env, ctx, inner, tier, key) : await (await import("../../search-LFS5HHMZ.js")).handleSearch(env, ctx, inner, tier, key);
|
|
1056
1056
|
payload = await res.json().catch(() => ({ error: { message: "tool transport failed", status: res.status } }));
|
|
1057
1057
|
}
|
|
1058
1058
|
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 });
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
+
cacheableAnswer,
|
|
2
3
|
canonicalRefusal,
|
|
3
4
|
exciseMisplacedPin,
|
|
4
5
|
refusalAnswer
|
|
5
|
-
} from "../../chunk-
|
|
6
|
+
} from "../../chunk-XBZIJMS7.js";
|
|
6
7
|
import "../../chunk-3FYJM7LH.js";
|
|
7
8
|
export {
|
|
9
|
+
cacheableAnswer,
|
|
8
10
|
canonicalRefusal,
|
|
9
11
|
exciseMisplacedPin,
|
|
10
12
|
refusalAnswer
|
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.135",
|
|
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",
|
|
@@ -17,7 +17,7 @@ import { reflect } from "./reflect";
|
|
|
17
17
|
import { scoreFaithfulness } from "./faithfulness";
|
|
18
18
|
import { entailmentVerdict } from "./entailment";
|
|
19
19
|
import { checkQuoteAnchors, ANCHOR_CORRECTION_NOTE } from "./anchors";
|
|
20
|
-
import { canonicalRefusal, exciseMisplacedPin } from "./refusal";
|
|
20
|
+
import { cacheableAnswer, canonicalRefusal, exciseMisplacedPin } from "./refusal";
|
|
21
21
|
import { contractV2, tableRetyped } from "./refs";
|
|
22
22
|
import { completeTables, completeFigures } from "./completion";
|
|
23
23
|
import { NO_CONTEXT, appliedContext, contextNote, namedDocumentIn, parseContext, resolveDocScope, syntheticUnderstanding } from "./context";
|
|
@@ -1582,7 +1582,7 @@ let convEntities: Array<{ entity: string; kind: string }> = [];
|
|
|
1582
1582
|
if (streamed.violations.length > 0) {
|
|
1583
1583
|
console.log("anchors:", streamed.violations.length, "of", streamed.total, "unverified — not caching");
|
|
1584
1584
|
}
|
|
1585
|
-
if (streamed.violations.length === 0 && canonical.length > 0 && !contextual && !declaredCtx &&
|
|
1585
|
+
if (streamed.violations.length === 0 && canonical.length > 0 && !contextual && !declaredCtx && cacheableAnswer(canonical, refusalScope(usedHits.length > 0)) && !ablate) {
|
|
1586
1586
|
ctx.waitUntil(
|
|
1587
1587
|
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 }),
|
|
1588
1588
|
);
|
|
@@ -1811,7 +1811,7 @@ let convEntities: Array<{ entity: string; kind: string }> = [];
|
|
|
1811
1811
|
}
|
|
1812
1812
|
}
|
|
1813
1813
|
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: understanding?.follow_ups ?? [], blocks: [...c2ns.blocks, ...(verdictBlock ? [verdictBlock] : []), ...(conditionBlock ? [conditionBlock] : []), ...(aggregationBlock ? [aggregationBlock] : []), ...(registerBlock ? [registerBlock] : []), ...completionBlocks], context_applied: ctxApplied, ...(liveRecords ? { records: liveRecords } : {}), ...(ablate ? { ablate } : {}), route: { route: routed.route, features: routed.features } };
|
|
1814
|
-
const cacheable = !contextual && !declaredCtx && !ablate &&
|
|
1814
|
+
const cacheable = !contextual && !declaredCtx && !ablate && cacheableAnswer(answer, refusalScope(usedHits.length > 0)) && finalAnchors.violations.length === 0;
|
|
1815
1815
|
if (cacheable) {
|
|
1816
1816
|
const ck = exactCacheKey(env.INDEX_VERSION, gen, ns, await sha256Hex(cacheKeyMaterial(q.query, q.lang, salt)));
|
|
1817
1817
|
ctx.waitUntil(env.CACHE.put(ck, JSON.stringify(out), { expirationTtl: LIMITS.cacheTtlSec }));
|
|
@@ -146,3 +146,15 @@ export function exciseMisplacedPin(answer: string, cites: boolean): string {
|
|
|
146
146
|
}
|
|
147
147
|
return out.replace(/^[ \t\n]+/, "").replace(/\n{3,}/g, "\n\n").trim();
|
|
148
148
|
}
|
|
149
|
+
|
|
150
|
+
/** Cacheable under the refusal law (2026-10-11, the poisoned-entry
|
|
151
|
+
* lesson): "refusals are never cached" was enforced as "answers
|
|
152
|
+
* containing the pin are never cached" — backwards for DRIFT, which
|
|
153
|
+
* lacks the pin and cached itself across deploy windows (an edge
|
|
154
|
+
* instance running pre-wall code wrote a drifted refusal that served
|
|
155
|
+
* every later ask). An answer is cacheable only when it carries no
|
|
156
|
+
* pin AND the wall would not rewrite it. */
|
|
157
|
+
export function cacheableAnswer(answer: string, scope?: RefusalScope): boolean {
|
|
158
|
+
if (answer.includes(refusalAnswer())) return false;
|
|
159
|
+
return canonicalRefusal(answer, scope) === answer;
|
|
160
|
+
}
|