@konneal/engine 0.2.189 → 0.2.190
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-LPNODCPM.js → ask-6SWT3KSC.js} +1 -1
- package/dist/{chunk-FCRTWZQE.js → chunk-WRSUXIS7.js} +18 -3
- package/dist/operations.d.ts +34 -0
- package/dist/worker_public/src/index.js +2 -2
- package/package.json +1 -1
- package/workers/worker_public/src/ask.ts +35 -5
- package/workers/worker_public/src/operations.ts +40 -0
|
@@ -105,6 +105,7 @@ import {
|
|
|
105
105
|
standardKeysFrom
|
|
106
106
|
} from "./chunk-7YMIUTPY.js";
|
|
107
107
|
import {
|
|
108
|
+
DATASETS,
|
|
108
109
|
ESCALATION_DAILY_DEFAULT,
|
|
109
110
|
LIMITS,
|
|
110
111
|
MODELS,
|
|
@@ -2077,6 +2078,17 @@ function anchorWords(anchor) {
|
|
|
2077
2078
|
return anchor.replace(/([a-z0-9])([A-Z])/g, "$1 $2").toLowerCase().split(/[^a-z0-9]+/).filter(Boolean);
|
|
2078
2079
|
}
|
|
2079
2080
|
var singular = (w) => w.length > 3 && w.endsWith("s") ? w.slice(0, -1) : w;
|
|
2081
|
+
function platformCorporaOf(datasets) {
|
|
2082
|
+
return datasets.filter((d) => (d.corpora ?? []).some((c) => /^smart-(ops|guides)$/.test(c))).flatMap((d) => [...d.corpora ?? []]);
|
|
2083
|
+
}
|
|
2084
|
+
function platformKnowledgeQuestion(query, ops, pool = [], datasets = []) {
|
|
2085
|
+
const platformCorpora = platformCorporaOf(datasets);
|
|
2086
|
+
if (!platformCorpora.length) return { knowledge: false, corpora: platformCorpora };
|
|
2087
|
+
const objects = query.toLowerCase().split(/[^a-z0-9]+/).filter((w) => w.length > 2 && !STOP_WORDS.has(w)).map(singular);
|
|
2088
|
+
const byName = isOperationIntent(query) && ops.matched.some((m) => anchorWords(m.anchor).map(singular).some((w) => objects.includes(w)));
|
|
2089
|
+
const inPool = pool.some((h) => platformCorpora.includes(String(h.metadata?.corpus ?? "")));
|
|
2090
|
+
return { knowledge: byName || inPool, corpora: platformCorpora };
|
|
2091
|
+
}
|
|
2080
2092
|
function matchOperations(query, rows) {
|
|
2081
2093
|
const q = query.toLowerCase();
|
|
2082
2094
|
const stems = ACTION_STEMS.filter((s) => q.includes(s));
|
|
@@ -2628,7 +2640,7 @@ async function handleAsk(env, ctx, req, tier, key) {
|
|
|
2628
2640
|
}
|
|
2629
2641
|
let understanding = null;
|
|
2630
2642
|
const answerCites = (t) => /\[[^\]]+\]/.test(t);
|
|
2631
|
-
const refusalScope = (cited) => ({ cited, conversational: understanding?.intent === "conversational" });
|
|
2643
|
+
const refusalScope = (cited) => ({ cited, conversational: understanding?.intent === "conversational" && !platformQuestion.knowledge });
|
|
2632
2644
|
let optimisticVec = null;
|
|
2633
2645
|
let optimisticHits = [];
|
|
2634
2646
|
const t0 = Date.now();
|
|
@@ -2774,11 +2786,14 @@ Certificates are issued per recommendation family \u2014 the register carries no
|
|
|
2774
2786
|
}
|
|
2775
2787
|
}
|
|
2776
2788
|
const regNote = aggregateNoteText ?? (register ? [registerNote(register.rows), certificateLinks(register.rows)].filter(Boolean).join("\n") : void 0);
|
|
2777
|
-
const
|
|
2789
|
+
const platformCorpora = platformCorporaOf(DATASETS());
|
|
2790
|
+
const ops = platformCorpora.length ? await operationsLane(env.DB, q2.query) : { matched: [] };
|
|
2778
2791
|
const registerOwns = !!register?.rows?.length;
|
|
2779
2792
|
const registerCitation = registerOwns ? [{ docidentifier: `${P().publisher.name}-CS certificate register`, corpus: "register" }] : [];
|
|
2780
2793
|
const escalationCitation = () => escalatedDoc ? [{ docidentifier: `${escalatedDoc.docidentifier} (the complete publication)`, corpus: "escalated" }] : [];
|
|
2781
|
-
|
|
2794
|
+
const platformQuestion = understanding?.intent === "conversational" ? platformKnowledgeQuestion(q2.query, ops, [], DATASETS()) : { knowledge: false, corpora: platformCorpora };
|
|
2795
|
+
const conversational = understanding?.intent === "conversational" && !platformQuestion.knowledge;
|
|
2796
|
+
if (conversational) {
|
|
2782
2797
|
const queryHash2 = await sha256Hex(q2.query);
|
|
2783
2798
|
const messages2 = [
|
|
2784
2799
|
{ role: "system", content: identityNote(!!member) },
|
package/dist/operations.d.ts
CHANGED
|
@@ -3,6 +3,40 @@ export declare function isOperationIntent(query: string): boolean;
|
|
|
3
3
|
* entity record" must reach putEntityRecord even when its description
|
|
4
4
|
* words the action differently ("replaces the stored…"). */
|
|
5
5
|
export declare function anchorWords(anchor: string): string[];
|
|
6
|
+
/** The platform-source corpora a deployment serves — the ones its
|
|
7
|
+
* datasets name (the API plane, the guides). The operations lane and
|
|
8
|
+
* the conversational yield both key on this: the SAME engine serves the
|
|
9
|
+
* public origin, whose datasets name no platform corpus. */
|
|
10
|
+
export declare function platformCorporaOf(datasets: readonly {
|
|
11
|
+
corpora?: readonly string[];
|
|
12
|
+
}[]): string[];
|
|
13
|
+
/** A platform-knowledge question the understanding step filed as
|
|
14
|
+
* "conversational". On the operations origin the assistant's own
|
|
15
|
+
* identity is "you answer questions about the platform's API
|
|
16
|
+
* operations", so a question about the PLATFORM reads to the
|
|
17
|
+
* classifier as a question about the SERVICE — measured 2026-12-04:
|
|
18
|
+
* "Which platform operation updates an entity record?" came back
|
|
19
|
+
* intent=conversational in 5 of 12 draws and the turn answered from
|
|
20
|
+
* the identity prompt, no retrieval. The subject decides: the
|
|
21
|
+
* deterministic operations lane matched an operation by name, or the
|
|
22
|
+
* retrieval pool holds a passage from a platform-source corpus — the
|
|
23
|
+
* indexed material answers it, so it is a knowledge question. Only the
|
|
24
|
+
* operations lane's own NAME match counts (a verb-only match is the
|
|
25
|
+
* lane's documented noise), and a service that indexes no platform
|
|
26
|
+
* source never re-routes. Pure service questions ("who are you?",
|
|
27
|
+
* "what can you do?") match no operation by name and hold no platform
|
|
28
|
+
* passage — they stay conversational. */
|
|
29
|
+
export declare function platformKnowledgeQuestion(query: string, ops: Pick<OperationsLane, "matched">, pool?: readonly {
|
|
30
|
+
metadata?: {
|
|
31
|
+
corpus?: string;
|
|
32
|
+
};
|
|
33
|
+
}[], datasets?: readonly {
|
|
34
|
+
corpora?: readonly string[];
|
|
35
|
+
session?: boolean;
|
|
36
|
+
}[]): {
|
|
37
|
+
knowledge: boolean;
|
|
38
|
+
corpora: string[];
|
|
39
|
+
};
|
|
6
40
|
export declare function matchOperations(query: string, rows: {
|
|
7
41
|
anchor: string;
|
|
8
42
|
text: string;
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
listUserDocuments,
|
|
10
10
|
scoreFaithfulness,
|
|
11
11
|
scoreJudge
|
|
12
|
-
} from "../../chunk-
|
|
12
|
+
} from "../../chunk-WRSUXIS7.js";
|
|
13
13
|
import "../../chunk-IRCDOFP4.js";
|
|
14
14
|
import {
|
|
15
15
|
TOOLS_REGISTRY,
|
|
@@ -1189,7 +1189,7 @@ async function callToolOnce(env, ctx, _req, tier, key, name, args, t0) {
|
|
|
1189
1189
|
const r = await runTool({ ...env, DB: env.DB }, { name, args }, "mcp");
|
|
1190
1190
|
payload = r ? { tool: r.name, query: r.query, result: r.output } : { error: { message: `tool ${name} returned nothing for the given arguments` } };
|
|
1191
1191
|
} else {
|
|
1192
|
-
const res = name === "ask" ? await (await import("../../ask-
|
|
1192
|
+
const res = name === "ask" ? await (await import("../../ask-6SWT3KSC.js")).handleAsk(env, ctx, inner, tier, key) : await (await import("../../search-DE5ADCVM.js")).handleSearch(env, ctx, inner, tier, key);
|
|
1193
1193
|
payload = await res.json().catch(() => ({ error: { message: "tool transport failed", status: res.status } }));
|
|
1194
1194
|
}
|
|
1195
1195
|
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.190",
|
|
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,7 +3,7 @@
|
|
|
3
3
|
// echo — everything between "request validated" and "response written".
|
|
4
4
|
// index.ts routes here; this module owns the answer contract.
|
|
5
5
|
|
|
6
|
-
import { LIMITS, MODELS, THRESHOLDS, num, sha256Hex, roleModel, answerEffort, requestEffort, effortBudget, generationSampling } from "./config";
|
|
6
|
+
import { LIMITS, MODELS, THRESHOLDS, num, sha256Hex, roleModel, answerEffort, requestEffort, effortBudget, generationSampling, DATASETS } from "./config";
|
|
7
7
|
import { portModelRunner } from "./env.ts";
|
|
8
8
|
import { refCodec } from "./codecs";
|
|
9
9
|
import { buildMessages, citations, fill, promptVars, retrieve, retrievalQuery, identityNote, splitHistory, listwiseRerank, refusalAnswer, Hit } from "./pipeline";
|
|
@@ -53,7 +53,7 @@ import { assembleDocument, verifyAnchors, escalationAllowed, chargeEscalation, e
|
|
|
53
53
|
import { ESCALATION_DAILY_DEFAULT } from "./config";
|
|
54
54
|
import { cfModelRunner, cfStore, cfVectorIndex } from "./ports/cloudflare/adapters";
|
|
55
55
|
import { TOOL_DECLARATION, parseToolCall, runTool, toolNote } from "./tools";
|
|
56
|
-
import { operationsLane } from "./operations.ts";
|
|
56
|
+
import { operationsLane, platformCorporaOf, platformKnowledgeQuestion, type OperationsLane } from "./operations.ts";
|
|
57
57
|
import { extractNameplate, nameplateRegisterQuery } from "./nameplate.ts";
|
|
58
58
|
import { P } from "./profile.ts";
|
|
59
59
|
import { toolNarration, intentPreamble, TOOL_NARRATION_NOTICE, INTENT_PREAMBLE_NOTICE } from "./answerGuards.ts";
|
|
@@ -726,7 +726,7 @@ let convEntities: Array<{ entity: string; kind: string }> = [];
|
|
|
726
726
|
// refusal) — gating on usedHits left every refusal "cited" and the
|
|
727
727
|
// wall dark through three deploys (2026-10-11)
|
|
728
728
|
const answerCites = (t: string) => /\[[^\]]+\]/.test(t);
|
|
729
|
-
const refusalScope = (cited: boolean) => ({ cited, conversational: understanding?.intent === "conversational" });
|
|
729
|
+
const refusalScope = (cited: boolean) => ({ cited, conversational: understanding?.intent === "conversational" && !platformQuestion.knowledge });
|
|
730
730
|
// a query naming a model node (/req/…, /term/…) is node-SCOPED: its
|
|
731
731
|
// ── Option C: optimistic parallel retrieval ──
|
|
732
732
|
// The dense lane (folded-query embed + unfiltered Vectorize query) runs
|
|
@@ -932,7 +932,17 @@ let convEntities: Array<{ entity: string; kind: string }> = [];
|
|
|
932
932
|
}
|
|
933
933
|
const regNote = aggregateNoteText
|
|
934
934
|
?? (register ? [registerNote(register.rows), certificateLinks(register.rows)].filter(Boolean).join("\n") : undefined);
|
|
935
|
-
|
|
935
|
+
// The operations catalog lane belongs to a deployment that serves the
|
|
936
|
+
// API plane: it runs only where the profile's datasets name a platform
|
|
937
|
+
// corpus (the operations origin). The same engine serves the public
|
|
938
|
+
// origin, whose datasets name none — there the lane's AUTHORITATIVE
|
|
939
|
+
// note and its citable operation passages must never enter the prompt
|
|
940
|
+
// (observed 2026-12-04, the moment the lane's rows returned to D1: the
|
|
941
|
+
// public origin began answering platform-operation questions).
|
|
942
|
+
const platformCorpora = platformCorporaOf(DATASETS());
|
|
943
|
+
const ops = platformCorpora.length
|
|
944
|
+
? await operationsLane(env.DB, q.query)
|
|
945
|
+
: { matched: [] as OperationsLane["matched"] };
|
|
936
946
|
// The register lane owns the answer surface when it holds rows — the
|
|
937
947
|
// aggregate path's philosophy (the note answers the structure, the
|
|
938
948
|
// model narrates) extended to the standing lane. Measured 2026-10-28:
|
|
@@ -953,13 +963,33 @@ let convEntities: Array<{ entity: string; kind: string }> = [];
|
|
|
953
963
|
? [{ docidentifier: `${escalatedDoc.docidentifier} (the complete publication)`, corpus: "escalated" }]
|
|
954
964
|
: [];
|
|
955
965
|
|
|
966
|
+
// A platform-knowledge question the understanding step filed as
|
|
967
|
+
// "conversational" takes the knowledge route instead (./operations
|
|
968
|
+
// platformKnowledgeQuestion): on the operations origin the assistant's
|
|
969
|
+
// identity is "you answer questions about the platform's API
|
|
970
|
+
// operations", so a question about the PLATFORM reads to the
|
|
971
|
+
// classifier as one about the SERVICE — measured 2026-12-04: the
|
|
972
|
+
// deploy smoke's "Which platform operation updates an entity record?"
|
|
973
|
+
// classified conversational in 5 of 12 draws and answered 1/6 from
|
|
974
|
+
// the identity prompt, no retrieval. The deterministic operations
|
|
975
|
+
// lane matching an operation BY NAME is the evidence the indexed
|
|
976
|
+
// material answers it; the matched operation rides the pool as a
|
|
977
|
+
// citable passage either way. Everything else keeps the classifier's
|
|
978
|
+
// verdict — this is a narrow yield, not a second classifier.
|
|
979
|
+
const platformQuestion = understanding?.intent === "conversational"
|
|
980
|
+
? platformKnowledgeQuestion(q.query, ops, [], DATASETS())
|
|
981
|
+
: { knowledge: false, corpora: platformCorpora };
|
|
982
|
+
// the refusal scope and the read echo report the route the turn
|
|
983
|
+
// actually took
|
|
984
|
+
const conversational = understanding?.intent === "conversational" && !platformQuestion.knowledge;
|
|
985
|
+
|
|
956
986
|
// Conversational route, decided by query UNDERSTANDING (any language, any
|
|
957
987
|
// phrasing) — not string matching. No retrieval: nothing in the corpus
|
|
958
988
|
// answers "who are you". The model speaks for itself from the service
|
|
959
989
|
// facts in identityNote (composed from the DATASETS catalog). A declared
|
|
960
990
|
// context is honestly NOT applied here (nothing grounds a conversational
|
|
961
991
|
// turn) — the echo reports none.
|
|
962
|
-
if (
|
|
992
|
+
if (conversational) {
|
|
963
993
|
const queryHash = await sha256Hex(q.query);
|
|
964
994
|
const messages = [
|
|
965
995
|
{ role: "system", content: identityNote(!!member) },
|
|
@@ -38,6 +38,46 @@ export function anchorWords(anchor: string): string[] {
|
|
|
38
38
|
|
|
39
39
|
const singular = (w: string) => (w.length > 3 && w.endsWith("s") ? w.slice(0, -1) : w);
|
|
40
40
|
|
|
41
|
+
/** The platform-source corpora a deployment serves — the ones its
|
|
42
|
+
* datasets name (the API plane, the guides). The operations lane and
|
|
43
|
+
* the conversational yield both key on this: the SAME engine serves the
|
|
44
|
+
* public origin, whose datasets name no platform corpus. */
|
|
45
|
+
export function platformCorporaOf(datasets: readonly { corpora?: readonly string[] }[]): string[] {
|
|
46
|
+
return datasets.filter((d) => (d.corpora ?? []).some((c) => /^smart-(ops|guides)$/.test(c))).flatMap((d) => [...(d.corpora ?? [])]);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** A platform-knowledge question the understanding step filed as
|
|
50
|
+
* "conversational". On the operations origin the assistant's own
|
|
51
|
+
* identity is "you answer questions about the platform's API
|
|
52
|
+
* operations", so a question about the PLATFORM reads to the
|
|
53
|
+
* classifier as a question about the SERVICE — measured 2026-12-04:
|
|
54
|
+
* "Which platform operation updates an entity record?" came back
|
|
55
|
+
* intent=conversational in 5 of 12 draws and the turn answered from
|
|
56
|
+
* the identity prompt, no retrieval. The subject decides: the
|
|
57
|
+
* deterministic operations lane matched an operation by name, or the
|
|
58
|
+
* retrieval pool holds a passage from a platform-source corpus — the
|
|
59
|
+
* indexed material answers it, so it is a knowledge question. Only the
|
|
60
|
+
* operations lane's own NAME match counts (a verb-only match is the
|
|
61
|
+
* lane's documented noise), and a service that indexes no platform
|
|
62
|
+
* source never re-routes. Pure service questions ("who are you?",
|
|
63
|
+
* "what can you do?") match no operation by name and hold no platform
|
|
64
|
+
* passage — they stay conversational. */
|
|
65
|
+
export function platformKnowledgeQuestion(
|
|
66
|
+
query: string,
|
|
67
|
+
ops: Pick<OperationsLane, "matched">,
|
|
68
|
+
pool: readonly { metadata?: { corpus?: string } }[] = [],
|
|
69
|
+
datasets: readonly { corpora?: readonly string[]; session?: boolean }[] = [],
|
|
70
|
+
): { knowledge: boolean; corpora: string[] } {
|
|
71
|
+
const platformCorpora = platformCorporaOf(datasets);
|
|
72
|
+
if (!platformCorpora.length) return { knowledge: false, corpora: platformCorpora };
|
|
73
|
+
// an explicit operation question needs the lane's name match; a
|
|
74
|
+
// pool-derived re-route needs a platform passage actually in it
|
|
75
|
+
const objects = query.toLowerCase().split(/[^a-z0-9]+/).filter((w) => w.length > 2 && !STOP_WORDS.has(w)).map(singular);
|
|
76
|
+
const byName = isOperationIntent(query) && ops.matched.some((m) => anchorWords(m.anchor).map(singular).some((w) => objects.includes(w)));
|
|
77
|
+
const inPool = pool.some((h) => platformCorpora.includes(String(h.metadata?.corpus ?? "")));
|
|
78
|
+
return { knowledge: byName || inPool, corpora: platformCorpora };
|
|
79
|
+
}
|
|
80
|
+
|
|
41
81
|
export function matchOperations(query: string, rows: { anchor: string; text: string; docidentifier?: string }[]): { anchor: string; text: string; docidentifier?: string }[] {
|
|
42
82
|
const q = query.toLowerCase();
|
|
43
83
|
const stems = ACTION_STEMS.filter((s) => q.includes(s));
|