@konneal/engine 0.2.73 → 0.2.74
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-MFFOHVQ2.js → ask-FHA56VIN.js} +2 -2
- package/dist/{chunk-LL3LWBZH.js → chunk-7HWJOFTQ.js} +10 -7
- package/dist/{chunk-V7PEVNNO.js → chunk-CNSTPYX3.js} +14 -3
- package/dist/{chunk-OXTRNMTZ.js → chunk-KO6DRI7C.js} +1 -1
- package/dist/{search-LN5Q7OSZ.js → search-LVUQLA3C.js} +2 -2
- package/dist/worker_public/src/index.js +4 -4
- package/package.json +1 -1
- package/workers/worker_public/src/ai.ts +13 -7
- package/workers/worker_public/src/ask.ts +6 -1
- package/workers/worker_public/src/operations.ts +16 -3
|
@@ -45,13 +45,16 @@ async function rerank(ai, model, query, texts) {
|
|
|
45
45
|
async function generateOnce(env, model, messages, effort) {
|
|
46
46
|
for (let attempt2 = 0; attempt2 < 2; attempt2++) {
|
|
47
47
|
try {
|
|
48
|
-
const res = await
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
const res = await Promise.race([
|
|
49
|
+
env.AI.run(model, {
|
|
50
|
+
messages,
|
|
51
|
+
max_tokens: effortBudget(effort ?? answerEffort(env)),
|
|
52
|
+
reasoning_effort: effort ?? answerEffort(env),
|
|
53
|
+
temperature: 0.6,
|
|
54
|
+
top_p: 0.95
|
|
55
|
+
}),
|
|
56
|
+
new Promise((r) => setTimeout(() => r(null), 12e4))
|
|
57
|
+
]);
|
|
55
58
|
if (typeof res?.response === "string" && res.response.trim()) return res.response;
|
|
56
59
|
if (typeof res?.choices?.[0]?.message?.content === "string" && res.choices[0].message.content.trim()) return res.choices[0].message.content;
|
|
57
60
|
if (attempt2 === 0) console.error("generate returned empty:", model);
|
|
@@ -39,7 +39,7 @@ import {
|
|
|
39
39
|
tokenBudget,
|
|
40
40
|
understandQuery,
|
|
41
41
|
usageTotal
|
|
42
|
-
} from "./chunk-
|
|
42
|
+
} from "./chunk-7HWJOFTQ.js";
|
|
43
43
|
import {
|
|
44
44
|
corsHeaders,
|
|
45
45
|
err,
|
|
@@ -1994,6 +1994,13 @@ ${anchors.map((a) => `- ${a}`).join("\n")}`;
|
|
|
1994
1994
|
}
|
|
1995
1995
|
async function operationsCatalogNote(db, query) {
|
|
1996
1996
|
if (!isOperationIntent(query)) return void 0;
|
|
1997
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
1998
|
+
const note = await operationsCatalogNoteOnce(db, query, attempt > 0);
|
|
1999
|
+
if (note !== void 0) return note;
|
|
2000
|
+
}
|
|
2001
|
+
return void 0;
|
|
2002
|
+
}
|
|
2003
|
+
async function operationsCatalogNoteOnce(db, query, retried) {
|
|
1997
2004
|
try {
|
|
1998
2005
|
const rows = (await db.prepare("SELECT clause_anchor AS anchor, substr(text, 1, 300) AS text FROM chunks WHERE corpus = 'smart-ops' AND clause_anchor IS NOT NULL ORDER BY clause_anchor").all()).results ?? [];
|
|
1999
2006
|
const opRows = rows.map((r) => ({ anchor: String(r.anchor ?? ""), text: String(r.text ?? "") })).filter((r) => r.anchor);
|
|
@@ -2005,7 +2012,8 @@ ${matched.map((m) => `- ${m.text}`).join("\n")}`);
|
|
|
2005
2012
|
}
|
|
2006
2013
|
parts.push(catalogNote(opRows.map((r) => r.anchor)));
|
|
2007
2014
|
return parts.filter(Boolean).join("\n\n") || void 0;
|
|
2008
|
-
} catch {
|
|
2015
|
+
} catch (e) {
|
|
2016
|
+
console.error(`operations-catalog: D1 read failed${retried ? " twice" : ""} \u2014 the note is dropped`, String(e).slice(0, 120));
|
|
2009
2017
|
return void 0;
|
|
2010
2018
|
}
|
|
2011
2019
|
}
|
|
@@ -2191,7 +2199,10 @@ async function* sseTokens(stream, stats) {
|
|
|
2191
2199
|
const decoder = new TextDecoder();
|
|
2192
2200
|
let buf = "";
|
|
2193
2201
|
while (true) {
|
|
2194
|
-
const { done, value } = await
|
|
2202
|
+
const { done, value } = await Promise.race([
|
|
2203
|
+
reader.read(),
|
|
2204
|
+
new Promise((r) => setTimeout(() => r({ done: true }), 12e4))
|
|
2205
|
+
]);
|
|
2195
2206
|
if (done) break;
|
|
2196
2207
|
buf += decoder.decode(value, { stream: true });
|
|
2197
2208
|
const lines = buf.split("\n");
|
|
@@ -6,10 +6,10 @@ import {
|
|
|
6
6
|
modelGroundingBlock,
|
|
7
7
|
scoreFaithfulness,
|
|
8
8
|
scoreJudge
|
|
9
|
-
} from "../../chunk-
|
|
9
|
+
} from "../../chunk-CNSTPYX3.js";
|
|
10
10
|
import {
|
|
11
11
|
handleSearch
|
|
12
|
-
} from "../../chunk-
|
|
12
|
+
} from "../../chunk-KO6DRI7C.js";
|
|
13
13
|
import {
|
|
14
14
|
buildMessages,
|
|
15
15
|
cfBlobs,
|
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
sessionFrom,
|
|
36
36
|
telemetry,
|
|
37
37
|
understandQuery
|
|
38
|
-
} from "../../chunk-
|
|
38
|
+
} from "../../chunk-7HWJOFTQ.js";
|
|
39
39
|
import {
|
|
40
40
|
authenticate,
|
|
41
41
|
corsHeaders,
|
|
@@ -959,7 +959,7 @@ async function handleMcp(env, ctx, req, tier, key) {
|
|
|
959
959
|
// stream:false forces the JSON lane (anon defaults to SSE)
|
|
960
960
|
body: JSON.stringify({ ...args, stream: false })
|
|
961
961
|
});
|
|
962
|
-
const res = name === "ask" ? await (await import("../../ask-
|
|
962
|
+
const res = name === "ask" ? await (await import("../../ask-FHA56VIN.js")).handleAsk(env, ctx, inner, tier, key) : await (await import("../../search-LVUQLA3C.js")).handleSearch(env, ctx, inner, tier, key);
|
|
963
963
|
return res.json().catch(() => ({ error: { message: "tool transport failed", status: res.status } }));
|
|
964
964
|
});
|
|
965
965
|
if (out.ok && "accepted" in out) return new Response(null, { status: 202 });
|
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.74",
|
|
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",
|
|
@@ -54,13 +54,19 @@ export async function generateOnce(env: any, model: string, messages: any[], eff
|
|
|
54
54
|
// silently blindfolds figure answers)
|
|
55
55
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
56
56
|
try {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
57
|
+
// bounded: a STALLED call (no error, no response — observed live
|
|
58
|
+
// 2026-09-29, asks hanging at zero bytes for minutes) must fall
|
|
59
|
+
// through to the retry/fallback, never hang the ask forever
|
|
60
|
+
const res: any = await Promise.race([
|
|
61
|
+
env.AI.run(model, {
|
|
62
|
+
messages,
|
|
63
|
+
max_tokens: effortBudget(effort ?? answerEffort(env)),
|
|
64
|
+
reasoning_effort: effort ?? answerEffort(env),
|
|
65
|
+
temperature: 0.6,
|
|
66
|
+
top_p: 0.95,
|
|
67
|
+
}),
|
|
68
|
+
new Promise<null>((r) => setTimeout(() => r(null), 120_000)),
|
|
69
|
+
]);
|
|
64
70
|
// an EMPTY string is a failed generation, not an answer: the
|
|
65
71
|
// platform intermittently returns empty bodies with a 200 (observed
|
|
66
72
|
// live 2026-09-20 — answers went blank platform-wide while retrieval
|
|
@@ -232,7 +232,12 @@ async function* sseTokens(stream: ReadableStream<Uint8Array>, stats?: { usage?:
|
|
|
232
232
|
const decoder = new TextDecoder();
|
|
233
233
|
let buf = "";
|
|
234
234
|
while (true) {
|
|
235
|
-
|
|
235
|
+
// bounded read: a stalled stream (no error, no chunk) delivers what
|
|
236
|
+
// it has instead of hanging the ask at zero tokens
|
|
237
|
+
const { done, value } = await Promise.race([
|
|
238
|
+
reader.read(),
|
|
239
|
+
new Promise<{ done: true; value?: undefined }>((r) => setTimeout(() => r({ done: true }), 120_000)),
|
|
240
|
+
]);
|
|
236
241
|
if (done) break;
|
|
237
242
|
buf += decoder.decode(value, { stream: true });
|
|
238
243
|
const lines = buf.split("\n");
|
|
@@ -70,7 +70,18 @@ export function catalogNote(anchors: string[]): string {
|
|
|
70
70
|
|
|
71
71
|
export async function operationsCatalogNote(db: any, query: string): Promise<string | undefined> {
|
|
72
72
|
if (!isOperationIntent(query)) return undefined;
|
|
73
|
-
|
|
73
|
+
// one retry, and the failure is LOUD: a silently dropped note answers
|
|
74
|
+
// an operation question with the OIML refusal (observed live 2026-09-29
|
|
75
|
+
// — a transient D1 read failed into the catch and the lane vanished)
|
|
76
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
77
|
+
const note = await operationsCatalogNoteOnce(db, query, attempt > 0);
|
|
78
|
+
if (note !== undefined) return note;
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async function operationsCatalogNoteOnce(db: any, query: string, retried: boolean): Promise<string | undefined> {
|
|
84
|
+
try {
|
|
74
85
|
const rows = (await db.prepare("SELECT clause_anchor AS anchor, substr(text, 1, 300) AS text FROM chunks WHERE corpus = 'smart-ops' AND clause_anchor IS NOT NULL ORDER BY clause_anchor").all()).results ?? [];
|
|
75
86
|
const opRows = (rows as any[]).map((r) => ({ anchor: String(r.anchor ?? ""), text: String(r.text ?? "") })).filter((r) => r.anchor);
|
|
76
87
|
const matched = matchOperations(query, opRows);
|
|
@@ -80,7 +91,9 @@ export async function operationsCatalogNote(db: any, query: string): Promise<str
|
|
|
80
91
|
}
|
|
81
92
|
parts.push(catalogNote(opRows.map((r) => r.anchor)));
|
|
82
93
|
return parts.filter(Boolean).join("\n\n") || undefined;
|
|
83
|
-
} catch {
|
|
84
|
-
|
|
94
|
+
} catch (e) {
|
|
95
|
+
// the lane is optional — but never silent (the blind-failure lesson)
|
|
96
|
+
console.error(`operations-catalog: D1 read failed${retried ? " twice" : ""} — the note is dropped`, String(e).slice(0, 120));
|
|
97
|
+
return undefined;
|
|
85
98
|
}
|
|
86
99
|
}
|