@konneal/engine 0.2.17 → 0.2.18
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.
|
@@ -960,7 +960,7 @@ function pickTable(nodes, query) {
|
|
|
960
960
|
for (const t of tokens(n.node_id.replace("/table/", ""))) {
|
|
961
961
|
if (t.length >= 3 && queryLower.includes(t)) score += 2;
|
|
962
962
|
}
|
|
963
|
-
for (const w of String(c.name ?? "").toLowerCase().split(/[^a-z0-9.]+/)) {
|
|
963
|
+
for (const w of String(c.name ?? c.definition ?? "").toLowerCase().split(/[^a-z0-9.]+/)) {
|
|
964
964
|
if (w.length >= 4 && queryLower.includes(w)) score += 1;
|
|
965
965
|
}
|
|
966
966
|
if (intervalPairs(cols).some((p) => p.low.unit && stated.has(p.low.unit))) score += 3;
|
|
@@ -981,7 +981,9 @@ function evaluateAggregation(nodes, query) {
|
|
|
981
981
|
const cols = Array.isArray(payload.columns) ? payload.columns : [];
|
|
982
982
|
const rows = (Array.isArray(payload.rows) ? payload.rows : []).filter((r) => Array.isArray(r));
|
|
983
983
|
if (!cols.length || !rows.length) return null;
|
|
984
|
-
const
|
|
984
|
+
const rawTitle = String(content.name ?? content.definition ?? node.node_id.replace("/table/", ""));
|
|
985
|
+
const cut = rawTitle.indexOf(" (");
|
|
986
|
+
const tableTitle = cut > 0 ? rawTitle.slice(0, cut) : rawTitle.slice(0, 120);
|
|
985
987
|
const cite = (what) => `COMPUTED (${operation}) \u2014 ${what}, read from the typed table "${tableTitle}" (${node.node_id}). Present this result and cite the table's clause; the value is machine-computed from the table payload, do not recompute or round it differently.`;
|
|
986
988
|
if (operation === "count") {
|
|
987
989
|
const cc2 = classColumn(cols);
|
|
@@ -1864,6 +1866,17 @@ ${summary}` }] : [],
|
|
|
1864
1866
|
const modelNote = boundModel && !boundModel.gated ? modelGroundingBlock(boundModel) : void 0;
|
|
1865
1867
|
const machineVerdict = boundModel && !boundModel.gated ? evaluate(boundModel.content, q.query) : null;
|
|
1866
1868
|
const machineNote = machineVerdict && boundModel ? verdictNote(machineVerdict, boundModel) : void 0;
|
|
1869
|
+
const modelNodeRows = async (kind, docNum) => {
|
|
1870
|
+
const attempt = (num3) => {
|
|
1871
|
+
const sql = num3 ? `SELECT standard, node_id, content FROM model_nodes WHERE kind = '${kind}' AND standard LIKE '%' || ?1` : `SELECT standard, node_id, content FROM model_nodes WHERE kind = '${kind}'`;
|
|
1872
|
+
return num3 ? env.DB.prepare(sql).bind(num3) : env.DB.prepare(sql);
|
|
1873
|
+
};
|
|
1874
|
+
let rows = await attempt(docNum).all().catch(() => ({ results: [] }));
|
|
1875
|
+
if (!(rows.results ?? []).length && docNum && docNum.includes("-")) {
|
|
1876
|
+
rows = await attempt(docNum.replace(/-\d+$/, "")).all().catch(() => ({ results: [] }));
|
|
1877
|
+
}
|
|
1878
|
+
return rows;
|
|
1879
|
+
};
|
|
1867
1880
|
let conditionVerdict = null;
|
|
1868
1881
|
let conditionStandard = null;
|
|
1869
1882
|
if (!machineVerdict && !boundModel && P().publisher.features?.model_plane) {
|
|
@@ -1872,9 +1885,7 @@ ${summary}` }] : [],
|
|
|
1872
1885
|
const stated = quantitiesIn(q.query);
|
|
1873
1886
|
if (severityWord && Object.keys(stated).length >= 1) {
|
|
1874
1887
|
const docNum = modelDocHint?.doc_number;
|
|
1875
|
-
const
|
|
1876
|
-
const stmt = docNum ? env.DB.prepare(sql).bind(docNum) : env.DB.prepare(sql);
|
|
1877
|
-
const rows = await stmt.all().catch(() => ({ results: [] }));
|
|
1888
|
+
const rows = await modelNodeRows("condition_set", docNum);
|
|
1878
1889
|
const candidates = (rows.results ?? []).filter((r) => {
|
|
1879
1890
|
const entry = licensedEntryForPackage(String(r.standard));
|
|
1880
1891
|
return !entry || (standardKeys?.has(entry.key) ?? false);
|
|
@@ -1923,9 +1934,7 @@ ${summary}` }] : [],
|
|
|
1923
1934
|
let aggregationStandard = null;
|
|
1924
1935
|
if (!machineVerdict && !boundModel && !conditionVerdict && P().publisher.features?.model_plane) {
|
|
1925
1936
|
const docNum = modelDocHint?.doc_number;
|
|
1926
|
-
const
|
|
1927
|
-
const stmt = docNum ? env.DB.prepare(sql).bind(docNum) : env.DB.prepare(sql);
|
|
1928
|
-
const rows = await stmt.all().catch(() => ({ results: [] }));
|
|
1937
|
+
const rows = await modelNodeRows("table", docNum);
|
|
1929
1938
|
const candidates = (rows.results ?? []).filter((r) => {
|
|
1930
1939
|
const entry = licensedEntryForPackage(String(r.standard));
|
|
1931
1940
|
return !entry || (standardKeys?.has(entry.key) ?? false);
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
handleMemories,
|
|
8
8
|
scoreJudge,
|
|
9
9
|
standardForDocNumber
|
|
10
|
-
} from "../../chunk-
|
|
10
|
+
} from "../../chunk-PBXE2LFD.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-4O753Y4T.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.18",
|
|
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",
|
|
@@ -173,7 +173,8 @@ function pickTable(nodes: { node_id: string; content: any }[], query: string): {
|
|
|
173
173
|
for (const t of tokens(n.node_id.replace("/table/", ""))) {
|
|
174
174
|
if (t.length >= 3 && queryLower.includes(t)) score += 2;
|
|
175
175
|
}
|
|
176
|
-
|
|
176
|
+
// the D1 projection keeps the title under `definition`
|
|
177
|
+
for (const w of String(c.name ?? c.definition ?? "").toLowerCase().split(/[^a-z0-9.]+/)) {
|
|
177
178
|
if (w.length >= 4 && queryLower.includes(w)) score += 1;
|
|
178
179
|
}
|
|
179
180
|
// the question's stated unit existing as this table's interval unit,
|
|
@@ -206,13 +207,18 @@ export function evaluateAggregation(
|
|
|
206
207
|
: "lookup";
|
|
207
208
|
if (!nodes.length) return null;
|
|
208
209
|
const node = pickTable(nodes, query);
|
|
210
|
+
|
|
209
211
|
if (!node) return null;
|
|
210
212
|
const content = (node.content && typeof node.content === "object" ? node.content : {}) as Record<string, any>;
|
|
211
213
|
const payload = (content.payload ?? {}) as { columns?: Column[]; rows?: unknown[] };
|
|
212
214
|
const cols = Array.isArray(payload.columns) ? payload.columns : [];
|
|
213
215
|
const rows = (Array.isArray(payload.rows) ? payload.rows : []).filter((r) => Array.isArray(r)) as string[][];
|
|
214
216
|
if (!cols.length || !rows.length) return null;
|
|
215
|
-
const
|
|
217
|
+
const rawTitle = String(content.name ?? content.definition ?? node.node_id.replace("/table/", ""));
|
|
218
|
+
// display titles are cut before the normative parenthetical and at a
|
|
219
|
+
// word boundary — the full definition stays in the payload
|
|
220
|
+
const cut = rawTitle.indexOf(" (");
|
|
221
|
+
const tableTitle = cut > 0 ? rawTitle.slice(0, cut) : rawTitle.slice(0, 120);
|
|
216
222
|
|
|
217
223
|
const cite = (what: string) =>
|
|
218
224
|
`COMPUTED (${operation}) — ${what}, read from the typed table "${tableTitle}" (${node.node_id}). Present this result and cite the table's clause; the value is machine-computed from the table payload, do not recompute or round it differently.`;
|
|
@@ -725,6 +725,22 @@ async function handleAsk(
|
|
|
725
725
|
// quantities alongside severity vocabulary; the candidate sets come
|
|
726
726
|
// from the model node store (kind condition_set), license-gated like
|
|
727
727
|
// every model lane.
|
|
728
|
+
// the model lanes' node store read: the doc hint joins the STANDARD id
|
|
729
|
+
// (iec-60068-2-78 carries the part; oiml-r60 does not) — when the hint
|
|
730
|
+
// names a part of a part-less package ("R 60-1"), retry on the stem
|
|
731
|
+
const modelNodeRows = async (kind: string, docNum: string | undefined) => {
|
|
732
|
+
const attempt = (num: string | undefined) => {
|
|
733
|
+
const sql = num
|
|
734
|
+
? `SELECT standard, node_id, content FROM model_nodes WHERE kind = '${kind}' AND standard LIKE '%' || ?1`
|
|
735
|
+
: `SELECT standard, node_id, content FROM model_nodes WHERE kind = '${kind}'`;
|
|
736
|
+
return num ? env.DB.prepare(sql).bind(num) : env.DB.prepare(sql);
|
|
737
|
+
};
|
|
738
|
+
let rows = await attempt(docNum).all().catch(() => ({ results: [] }));
|
|
739
|
+
if (!(rows.results ?? []).length && docNum && docNum.includes("-")) {
|
|
740
|
+
rows = await attempt(docNum.replace(/-\d+$/, "")).all().catch(() => ({ results: [] }));
|
|
741
|
+
}
|
|
742
|
+
return rows;
|
|
743
|
+
};
|
|
728
744
|
let conditionVerdict: ConditionVerdict | null = null;
|
|
729
745
|
let conditionStandard: string | null = null;
|
|
730
746
|
if (!machineVerdict && !boundModel && P().publisher.features?.model_plane) {
|
|
@@ -735,11 +751,7 @@ async function handleAsk(
|
|
|
735
751
|
const docNum = modelDocHint?.doc_number;
|
|
736
752
|
// the doc number joins the STANDARD id (iec-60068-2-78), which is
|
|
737
753
|
// the doc number prefixed with the package-family prefix
|
|
738
|
-
const
|
|
739
|
-
? "SELECT standard, node_id, content FROM model_nodes WHERE kind = 'condition_set' AND standard LIKE '%' || ?1"
|
|
740
|
-
: "SELECT standard, node_id, content FROM model_nodes WHERE kind = 'condition_set'";
|
|
741
|
-
const stmt = docNum ? env.DB.prepare(sql).bind(docNum) : env.DB.prepare(sql);
|
|
742
|
-
const rows = await stmt.all().catch(() => ({ results: [] }));
|
|
754
|
+
const rows = await modelNodeRows("condition_set", docNum);
|
|
743
755
|
const candidates = (rows.results ?? []).filter((r: any) => {
|
|
744
756
|
const entry = licensedEntryForPackage(String(r.standard));
|
|
745
757
|
return !entry || (standardKeys?.has(entry.key) ?? false);
|
|
@@ -801,11 +813,7 @@ async function handleAsk(
|
|
|
801
813
|
let aggregationStandard: string | null = null;
|
|
802
814
|
if (!machineVerdict && !boundModel && !conditionVerdict && P().publisher.features?.model_plane) {
|
|
803
815
|
const docNum = modelDocHint?.doc_number;
|
|
804
|
-
const
|
|
805
|
-
? "SELECT standard, node_id, content FROM model_nodes WHERE kind = 'table' AND standard LIKE '%' || ?1"
|
|
806
|
-
: "SELECT standard, node_id, content FROM model_nodes WHERE kind = 'table'";
|
|
807
|
-
const stmt = docNum ? env.DB.prepare(sql).bind(docNum) : env.DB.prepare(sql);
|
|
808
|
-
const rows = await stmt.all().catch(() => ({ results: [] }));
|
|
816
|
+
const rows = await modelNodeRows("table", docNum);
|
|
809
817
|
const candidates = (rows.results ?? []).filter((r: any) => {
|
|
810
818
|
const entry = licensedEntryForPackage(String(r.standard));
|
|
811
819
|
return !entry || (standardKeys?.has(entry.key) ?? false);
|