@konneal/engine 0.2.18 → 0.2.19
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-4O753Y4T.js → ask-HCZ4CDUR.js} +1 -1
- package/dist/boundary.d.ts +17 -0
- package/dist/{chunk-PBXE2LFD.js → chunk-AN4VFBBZ.js} +67 -1
- package/dist/worker_public/src/index.js +2 -2
- package/package.json +1 -1
- package/workers/worker_public/src/ask.ts +25 -1
- package/workers/worker_public/src/boundary.ts +69 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface LicensedEntry {
|
|
2
|
+
key: string;
|
|
3
|
+
package?: string;
|
|
4
|
+
doc_number?: string;
|
|
5
|
+
title?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface LicensedMatch {
|
|
8
|
+
entry: LicensedEntry;
|
|
9
|
+
matched: string[];
|
|
10
|
+
}
|
|
11
|
+
export declare function distinctiveTokens(title: string): string[];
|
|
12
|
+
/** The licensed entry whose distinctive title tokens best match the
|
|
13
|
+
* question. Needs TWO token hits (or one hyphenated-compound hit) —
|
|
14
|
+
* a single shared word is not a topic match. */
|
|
15
|
+
export declare function matchLicensedTopic(query: string, licensed: LicensedEntry[]): LicensedMatch | null;
|
|
16
|
+
/** The note text: the posture instruction for an unentitled match. */
|
|
17
|
+
export declare function boundaryNoteText(match: LicensedMatch, citing: string[]): string;
|
|
@@ -1074,6 +1074,54 @@ function evaluateAggregation(nodes, query) {
|
|
|
1074
1074
|
return null;
|
|
1075
1075
|
}
|
|
1076
1076
|
|
|
1077
|
+
// workers/worker_public/src/boundary.ts
|
|
1078
|
+
var TITLE_STOPWORDS = /* @__PURE__ */ new Set([
|
|
1079
|
+
"environmental",
|
|
1080
|
+
"testing",
|
|
1081
|
+
"test",
|
|
1082
|
+
"tests",
|
|
1083
|
+
"guidance",
|
|
1084
|
+
"generic",
|
|
1085
|
+
"standards",
|
|
1086
|
+
"standard",
|
|
1087
|
+
"electromagnetic",
|
|
1088
|
+
"compatibility",
|
|
1089
|
+
"environment",
|
|
1090
|
+
"description",
|
|
1091
|
+
"measurement",
|
|
1092
|
+
"techniques",
|
|
1093
|
+
"immunity",
|
|
1094
|
+
"residential",
|
|
1095
|
+
"commercial",
|
|
1096
|
+
"industrial",
|
|
1097
|
+
"environments",
|
|
1098
|
+
"and",
|
|
1099
|
+
"for",
|
|
1100
|
+
"the",
|
|
1101
|
+
"iec",
|
|
1102
|
+
"iso"
|
|
1103
|
+
]);
|
|
1104
|
+
function distinctiveTokens(title) {
|
|
1105
|
+
return title.toLowerCase().split(/[^a-z0-9.]+/).filter((w) => w.length >= 3 && !TITLE_STOPWORDS.has(w) && !/^[0-9:-]+$/.test(w));
|
|
1106
|
+
}
|
|
1107
|
+
function matchLicensedTopic(query, licensed) {
|
|
1108
|
+
const words = new Set(query.toLowerCase().split(/[^a-z0-9.]+/).filter(Boolean));
|
|
1109
|
+
let best = null;
|
|
1110
|
+
for (const entry of licensed) {
|
|
1111
|
+
if (!entry.title) continue;
|
|
1112
|
+
const matched = distinctiveTokens(entry.title).filter((w) => words.has(w));
|
|
1113
|
+
if (matched.length < 2) continue;
|
|
1114
|
+
if (!best || matched.length > best.matched.length) best = { entry, matched };
|
|
1115
|
+
}
|
|
1116
|
+
return best;
|
|
1117
|
+
}
|
|
1118
|
+
function boundaryNoteText(match, citing) {
|
|
1119
|
+
const doc = match.entry.doc_number ?? match.entry.key;
|
|
1120
|
+
const title = match.entry.title ?? doc;
|
|
1121
|
+
const refs = citing.length ? `The public corpus references it from ${citing.join(", ")}.` : "";
|
|
1122
|
+
return `LICENSED BOUNDARY \u2014 ${title} (IEC ${doc}) is licensed content in this deployment; its procedure is NOT part of the public corpus you are grounded in. ${refs} When answering: name the licensed document as the authoritative source of the procedure and say it is available to entitled callers; do NOT recite its conditioning or severity parameters (specific temperatures, humidity levels, durations or cycle counts) as if from the source \u2014 describe only what the public grounding passages themselves state, attributed to their own publications.`;
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1077
1125
|
// workers/worker_public/src/drafts.ts
|
|
1078
1126
|
var ACT_VERB = "(?:draft|prepare|pre-?fill|fill\\s+(?:in|out)|start|submit|file|lodge)";
|
|
1079
1127
|
var ACT_TARGET = "(?:new\\s+)?(?:certification\\s+|type[ -]evaluation\\s+|OIML[- ]CS\\s+)?application";
|
|
@@ -1963,6 +2011,24 @@ ${summary}` }] : [],
|
|
|
1963
2011
|
}
|
|
1964
2012
|
} : null;
|
|
1965
2013
|
if (aggregationVerdict) console.log("aggregation engine:", aggregationVerdict.operation, aggregationVerdict.table, "\u2192", aggregationVerdict.value);
|
|
2014
|
+
let boundaryNote = null;
|
|
2015
|
+
if (P().sources?.licensed?.length) {
|
|
2016
|
+
const match = matchLicensedTopic(q.query, P().sources.licensed);
|
|
2017
|
+
if (match && !(standardKeys?.has(match.entry.key) ?? false)) {
|
|
2018
|
+
const docNum = match.entry.doc_number ?? "";
|
|
2019
|
+
let citing = [];
|
|
2020
|
+
if (docNum) {
|
|
2021
|
+
const rows = await env.DB.prepare(
|
|
2022
|
+
"SELECT n.label AS label FROM graph_edges e JOIN graph_nodes n ON e.src = n.id WHERE e.kind = 'cites' AND e.dst LIKE ?1 LIMIT 4"
|
|
2023
|
+
).bind(`%${docNum}%`).all().catch(() => ({ results: [] }));
|
|
2024
|
+
citing = (rows.results ?? []).map((r) => {
|
|
2025
|
+
const m = String(r.label ?? "").match(/^OIML-([A-Z]+)-(\d+)(?:-([A-Za-z0-9]+))?-(\d{4})$/);
|
|
2026
|
+
return m ? `OIML ${m[1]} ${m[2]}${m[3] ? `-${m[3]}` : ""} (${m[4]})` : String(r.label ?? "");
|
|
2027
|
+
});
|
|
2028
|
+
}
|
|
2029
|
+
boundaryNote = boundaryNoteText(match, citing);
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
1966
2032
|
try {
|
|
1967
2033
|
const tR = Date.now();
|
|
1968
2034
|
if (declaredCtx?.kind === "account") {
|
|
@@ -2056,7 +2122,7 @@ Answer account questions from these records ONLY: name the record when you use i
|
|
|
2056
2122
|
q.lang,
|
|
2057
2123
|
keptHistory,
|
|
2058
2124
|
// stage-extracted graph facts (GraphRAG) ride the same note channel
|
|
2059
|
-
[processNote, eNote, contextNote(declaredCtx, docScope), accountNote, modelNote, vocabNote, memNote, machineNote, conditionNote, aggregationNote, licenseNote, ...retrieved.notes ?? []].filter(Boolean).join("\n") || void 0,
|
|
2125
|
+
[processNote, eNote, contextNote(declaredCtx, docScope), accountNote, modelNote, vocabNote, memNote, machineNote, conditionNote, aggregationNote, boundaryNote, licenseNote, ...retrieved.notes ?? []].filter(Boolean).join("\n") || void 0,
|
|
2060
2126
|
summary,
|
|
2061
2127
|
budget
|
|
2062
2128
|
);
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
handleMemories,
|
|
8
8
|
scoreJudge,
|
|
9
9
|
standardForDocNumber
|
|
10
|
-
} from "../../chunk-
|
|
10
|
+
} from "../../chunk-AN4VFBBZ.js";
|
|
11
11
|
import {
|
|
12
12
|
buildMessages,
|
|
13
13
|
citations,
|
|
@@ -979,7 +979,7 @@ async function handleMcp(env, ctx, req, tier, key) {
|
|
|
979
979
|
// stream:false forces the JSON lane (anon defaults to SSE)
|
|
980
980
|
body: JSON.stringify({ ...args, stream: false })
|
|
981
981
|
});
|
|
982
|
-
const res = name === "ask" ? await (await import("../../ask-
|
|
982
|
+
const res = name === "ask" ? await (await import("../../ask-HCZ4CDUR.js")).handleAsk(env, ctx, inner, tier, key) : await (await import("../../search-RFKT7ZZY.js")).handleSearch(env, ctx, inner, tier, key);
|
|
983
983
|
return res.json().catch(() => ({ error: { message: "tool transport failed", status: res.status } }));
|
|
984
984
|
});
|
|
985
985
|
if (out.ok && "accepted" in out) return new Response(null, { status: 202 });
|
package/package.json
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@oimlsmart/oiml-pubid": "^1.2.1"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {},
|
|
37
|
-
"version": "0.2.
|
|
37
|
+
"version": "0.2.19",
|
|
38
38
|
"description": "The Konneal engine: the publisher-agnostic build pipeline and API plane for standards intelligence (retrieval, answer contract, verdicts, evaluation).",
|
|
39
39
|
"license": "BSD-3-Clause",
|
|
40
40
|
"type": "module",
|
|
@@ -23,6 +23,7 @@ import { bindModelNode, licenseBoundaryNote, licenseBoundaryRefusal, licensedEnt
|
|
|
23
23
|
import { evaluate as machineEvaluate, verdictNote } from "./verdict";
|
|
24
24
|
import { evaluateConditionSets, quantitiesIn, type ConditionVerdict } from "./conditions";
|
|
25
25
|
import { evaluateAggregation, type AggregationVerdict } from "./aggregation";
|
|
26
|
+
import { matchLicensedTopic, boundaryNoteText } from "./boundary";
|
|
26
27
|
import { detectDraftIntent, prepareDraft } from "./drafts";
|
|
27
28
|
import { memoryNote } from "./memories";
|
|
28
29
|
import { entitlementScope, resolveRequestScope, requestSalt } from "./requestScope";
|
|
@@ -846,6 +847,29 @@ async function handleAsk(
|
|
|
846
847
|
}
|
|
847
848
|
: null;
|
|
848
849
|
if (aggregationVerdict) console.log("aggregation engine:", aggregationVerdict.operation, aggregationVerdict.table, "→", aggregationVerdict.value);
|
|
850
|
+
// ── the licensed boundary note (TODO.rag/12): an unentitled question
|
|
851
|
+
// that is topically ABOUT a licensed standard gets the boundary
|
|
852
|
+
// posture — the citation graph names the public publications that
|
|
853
|
+
// reference the licensed document, and the note instructs the model
|
|
854
|
+
// to attribute, never to recite the licensed parameters.
|
|
855
|
+
let boundaryNote: string | null = null;
|
|
856
|
+
if (P().sources?.licensed?.length) {
|
|
857
|
+
const match = matchLicensedTopic(q.query, P().sources.licensed);
|
|
858
|
+
if (match && !(standardKeys?.has(match.entry.key) ?? false)) {
|
|
859
|
+
const docNum = match.entry.doc_number ?? "";
|
|
860
|
+
let citing: string[] = [];
|
|
861
|
+
if (docNum) {
|
|
862
|
+
const rows = await env.DB.prepare(
|
|
863
|
+
"SELECT n.label AS label FROM graph_edges e JOIN graph_nodes n ON e.src = n.id WHERE e.kind = 'cites' AND e.dst LIKE ?1 LIMIT 4",
|
|
864
|
+
).bind(`%${docNum}%`).all().catch(() => ({ results: [] }));
|
|
865
|
+
citing = (rows.results ?? []).map((r: any) => {
|
|
866
|
+
const m = String(r.label ?? "").match(/^OIML-([A-Z]+)-(\d+)(?:-([A-Za-z0-9]+))?-(\d{4})$/);
|
|
867
|
+
return m ? `OIML ${m[1]} ${m[2]}${m[3] ? `-${m[3]}` : ""} (${m[4]})` : String(r.label ?? "");
|
|
868
|
+
});
|
|
869
|
+
}
|
|
870
|
+
boundaryNote = boundaryNoteText(match, citing);
|
|
871
|
+
}
|
|
872
|
+
}
|
|
849
873
|
try {
|
|
850
874
|
const tR = Date.now();
|
|
851
875
|
// ── The "my account" live read (TODO.ai-platform/03) — resolved
|
|
@@ -995,7 +1019,7 @@ async function handleAsk(
|
|
|
995
1019
|
q.lang,
|
|
996
1020
|
keptHistory,
|
|
997
1021
|
// stage-extracted graph facts (GraphRAG) ride the same note channel
|
|
998
|
-
[processNote, eNote, contextNote(declaredCtx, docScope), accountNote, modelNote, vocabNote, memNote, machineNote, conditionNote, aggregationNote, licenseNote, ...(retrieved.notes ?? [])].filter(Boolean).join("\n") || undefined,
|
|
1022
|
+
[processNote, eNote, contextNote(declaredCtx, docScope), accountNote, modelNote, vocabNote, memNote, machineNote, conditionNote, aggregationNote, boundaryNote, licenseNote, ...(retrieved.notes ?? [])].filter(Boolean).join("\n") || undefined,
|
|
999
1023
|
summary,
|
|
1000
1024
|
budget,
|
|
1001
1025
|
);
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// The licensed boundary note (TODO.rag/12): when a question is about a
|
|
2
|
+
// topic that matches a LICENSED standard the caller is not entitled to,
|
|
3
|
+
// the note gives the answer model the boundary posture — name the
|
|
4
|
+
// licensed document as the authoritative procedure, name the public
|
|
5
|
+
// publications that reference it, and never recite the licensed
|
|
6
|
+
// parameters as if from the source. Pure matching/text lives here; the
|
|
7
|
+
// inverse-cites D1 read lives at the call site.
|
|
8
|
+
|
|
9
|
+
export interface LicensedEntry {
|
|
10
|
+
key: string;
|
|
11
|
+
package?: string;
|
|
12
|
+
doc_number?: string;
|
|
13
|
+
title?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface LicensedMatch {
|
|
17
|
+
entry: LicensedEntry;
|
|
18
|
+
matched: string[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// title words that carry no topical identity — a question about "tests"
|
|
22
|
+
// or "immunity" must not alone light the boundary
|
|
23
|
+
const TITLE_STOPWORDS = new Set([
|
|
24
|
+
"environmental", "testing", "test", "tests", "guidance", "generic",
|
|
25
|
+
"standards", "standard", "electromagnetic", "compatibility",
|
|
26
|
+
"environment", "description", "measurement", "techniques", "immunity",
|
|
27
|
+
"residential", "commercial", "industrial", "environments", "and", "for", "the",
|
|
28
|
+
"iec", "iso",
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
export function distinctiveTokens(title: string): string[] {
|
|
32
|
+
return title
|
|
33
|
+
.toLowerCase()
|
|
34
|
+
.split(/[^a-z0-9.]+/)
|
|
35
|
+
.filter((w) => w.length >= 3 && !TITLE_STOPWORDS.has(w) && !/^[0-9:-]+$/.test(w));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The licensed entry whose distinctive title tokens best match the
|
|
39
|
+
* question. Needs TWO token hits (or one hyphenated-compound hit) —
|
|
40
|
+
* a single shared word is not a topic match. */
|
|
41
|
+
export function matchLicensedTopic(query: string, licensed: LicensedEntry[]): LicensedMatch | null {
|
|
42
|
+
const words = new Set(query.toLowerCase().split(/[^a-z0-9.]+/).filter(Boolean));
|
|
43
|
+
let best: { entry: LicensedEntry; matched: string[] } | null = null;
|
|
44
|
+
for (const entry of licensed) {
|
|
45
|
+
if (!entry.title) continue;
|
|
46
|
+
const matched = distinctiveTokens(entry.title).filter((w) => words.has(w));
|
|
47
|
+
if (matched.length < 2) continue;
|
|
48
|
+
if (!best || matched.length > best.matched.length) best = { entry, matched };
|
|
49
|
+
}
|
|
50
|
+
return best;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The note text: the posture instruction for an unentitled match. */
|
|
54
|
+
export function boundaryNoteText(match: LicensedMatch, citing: string[]): string {
|
|
55
|
+
const doc = match.entry.doc_number ?? match.entry.key;
|
|
56
|
+
const title = match.entry.title ?? doc;
|
|
57
|
+
const refs = citing.length
|
|
58
|
+
? `The public corpus references it from ${citing.join(", ")}.`
|
|
59
|
+
: "";
|
|
60
|
+
return (
|
|
61
|
+
`LICENSED BOUNDARY — ${title} (IEC ${doc}) is licensed content in this ` +
|
|
62
|
+
`deployment; its procedure is NOT part of the public corpus you are grounded in. ` +
|
|
63
|
+
`${refs} When answering: name the licensed document as the authoritative source of ` +
|
|
64
|
+
`the procedure and say it is available to entitled callers; do NOT recite its ` +
|
|
65
|
+
`conditioning or severity parameters (specific temperatures, humidity levels, ` +
|
|
66
|
+
`durations or cycle counts) as if from the source — describe only what the public ` +
|
|
67
|
+
`grounding passages themselves state, attributed to their own publications.`
|
|
68
|
+
);
|
|
69
|
+
}
|