@konneal/engine 0.1.0 → 0.1.1

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.
Files changed (61) hide show
  1. package/dist/admin.d.ts +3 -0
  2. package/dist/{chunk-MB74PTRM.js → chunk-35ODH64W.js} +23 -4
  3. package/dist/chunk-CAEHIVG5.js +54 -0
  4. package/dist/{chunk-WWNCWKKC.js → chunk-EHJEELVB.js} +1 -1
  5. package/dist/{chunk-WOGQM7DJ.js → chunk-OCNLV7Q7.js} +2 -2
  6. package/dist/chunk-ROF3Q7UC.js +156 -0
  7. package/dist/codecs.d.ts +22 -0
  8. package/dist/context.d.ts +2 -9
  9. package/dist/modelplane.d.ts +1 -1
  10. package/dist/pipeline.d.ts +8 -1
  11. package/dist/profile.gen.d.ts +19 -0
  12. package/dist/profile2.gen.d.ts +89 -0
  13. package/dist/prompts/conversational.md +1 -1
  14. package/dist/prompts/enrichment.md +2 -2
  15. package/dist/prompts/precision.md +1 -1
  16. package/dist/prompts/research.md +1 -1
  17. package/dist/prompts/system.md +3 -3
  18. package/dist/prompts/understanding.md +4 -4
  19. package/dist/worker_mcp/src/index.d.ts +10 -0
  20. package/dist/worker_mcp/src/index.js +153 -0
  21. package/dist/{config.js → worker_public/src/config.js} +2 -2
  22. package/dist/{index.js → worker_public/src/index.js} +131 -207
  23. package/dist/{profile.js → worker_public/src/profile.js} +1 -1
  24. package/dist/{refusal.js → worker_public/src/refusal.js} +2 -2
  25. package/dist/worker_public/src/requestScope.js +10 -0
  26. package/package.json +16 -9
  27. package/profile/prompts.yaml +11 -0
  28. package/profile/publisher.yaml +9 -0
  29. package/profile/retrieval.yaml +4 -0
  30. package/scripts/gen_profile.mjs +6 -5
  31. package/workers/worker_internal/src/index.ts +1 -1
  32. package/workers/worker_mcp/src/index.ts +39 -26
  33. package/workers/worker_mcp/tsconfig.json +11 -4
  34. package/workers/worker_public/prompts/conversational.md +1 -1
  35. package/workers/worker_public/prompts/enrichment.md +2 -2
  36. package/workers/worker_public/prompts/precision.md +1 -1
  37. package/workers/worker_public/prompts/research.md +1 -1
  38. package/workers/worker_public/prompts/system.md +3 -3
  39. package/workers/worker_public/prompts/understanding.md +4 -4
  40. package/workers/worker_public/src/admin.ts +15 -3
  41. package/workers/worker_public/src/ask.ts +13 -10
  42. package/workers/worker_public/src/bubble.ts +13 -6
  43. package/workers/worker_public/src/codecs.ts +77 -0
  44. package/workers/worker_public/src/config.ts +1 -1
  45. package/workers/worker_public/src/context.ts +6 -26
  46. package/workers/worker_public/src/graph.ts +2 -3
  47. package/workers/worker_public/src/index.ts +5 -3
  48. package/workers/worker_public/src/lib/http.ts +5 -9
  49. package/workers/worker_public/src/livedata.ts +3 -2
  50. package/workers/worker_public/src/modelplane.ts +13 -5
  51. package/workers/worker_public/src/pipeline.ts +28 -13
  52. package/workers/worker_public/src/profile.gen.ts +23 -4
  53. package/workers/worker_public/src/profile2.gen.ts +122 -0
  54. package/workers/worker_public/src/refusal.ts +19 -21
  55. package/workers/worker_public/src/research.ts +4 -2
  56. package/workers/worker_public/src/stages/conceptGraph.ts +3 -2
  57. package/workers/worker_public/src/stages/corpusScope.ts +8 -2
  58. package/workers/worker_public/src/stages/editionCover.ts +2 -4
  59. package/workers/worker_public/src/understand.ts +2 -1
  60. package/dist/chunk-LLWPT2XV.js +0 -49
  61. package/dist/requestScope.js +0 -10
@@ -13,6 +13,8 @@ import { graphExpand, editionNote } from "./graph";
13
13
  import researchPromptText from "../prompts/research.md";
14
14
  import type { Env } from "./env";
15
15
  import type { Hit } from "../../shared/chunk.ts";
16
+ import { P } from "./profile.ts";
17
+ import { fill, promptVars } from "./pipeline.ts";
16
18
 
17
19
  /** Deep-research mode (G10 v1): bounded agentic loop for members —
18
20
  * retrieve → sufficiency judge → re-retrieve targeting the gap → answer
@@ -22,7 +24,7 @@ import type { Hit } from "../../shared/chunk.ts";
22
24
  * path when runs outgrow a single request. */
23
25
  export async function handleResearch(env: Env, ctx: ExecutionContext, req: Request, session: any): Promise<Response> {
24
26
  if (!session) {
25
- return err(403, "forbidden", "Deep research is a member feature — sign in with your OIML SMART account.");
27
+ return err(403, "forbidden", `Deep research is a member feature — sign in with your ${P().publisher.product_name} account.`);
26
28
  }
27
29
  const body = await readJson(req);
28
30
  const q = validateQuery(body);
@@ -71,7 +73,7 @@ export async function handleResearch(env: Env, ctx: ExecutionContext, req: Reque
71
73
  try {
72
74
  const res: any = await env.AI.run(MODELS.grader, {
73
75
  messages: [
74
- { role: "system", content: researchPromptText.trimEnd() },
76
+ { role: "system", content: fill(researchPromptText, promptVars()).trimEnd() },
75
77
  { role: "user", content: `Research question: ${q.query}\n\n${digest}Collected passages (${recent.length}):\n${recent.map((h, n) => `[${n + 1}] ${h.metadata.docidentifier ?? ""} §${h.metadata.clause_anchor ?? ""}: ${h.text.slice(0, 700)}`).join("\n")}` },
76
78
  ],
77
79
  max_tokens: 3072,
@@ -19,6 +19,7 @@
19
19
  // family's content reaches it).
20
20
  import { THRESHOLDS } from "../config.ts";
21
21
  import type { Stage } from "./types.ts";
22
+ import { refCodec } from "../codecs.ts";
22
23
 
23
24
  export const conceptGraph: Stage = {
24
25
  name: "concept-graph",
@@ -43,8 +44,8 @@ export const conceptGraph: Stage = {
43
44
  );
44
45
  for (const rows of termRows) {
45
46
  for (const r of rows.results ?? []) {
46
- const m = String(r.doc ?? "").match(/^doc:OIML-[A-Z]-(\d+)-/);
47
- if (m) numbers.add(m[1]!);
47
+ const mNum = refCodec().graphDocNumber(String(r.doc ?? ""));
48
+ if (mNum) numbers.add(mNum);
48
49
  }
49
50
  }
50
51
  if (numbers.size) {
@@ -7,8 +7,14 @@
7
7
  // the toggle model doesn't name (serving lanes, unknown values) pass
8
8
  // untouched: the toggles name DATASETS, not lanes.
9
9
  import type { Stage } from "./types.ts";
10
+ import { P } from "../profile.ts";
10
11
 
11
- const DATASET_CORPORA = new Set(["oiml", "dirty", "clean", "synthetic", "smart-model", "iso-internal"]);
12
+ /** The corpora a dataset toggle can name: the union of the datasets'
13
+ * declared corpora. Corpora outside it (serving lanes, unknown values)
14
+ * pass untouched — the toggles name datasets, not lanes. */
15
+ function datasetCorpora(): Set<string> {
16
+ return new Set(P().datasets.flatMap((d: { corpora?: string[] }) => d.corpora ?? []));
17
+ }
12
18
 
13
19
  export const corpusScope: Stage = {
14
20
  name: "corpus-scope",
@@ -17,7 +23,7 @@ export const corpusScope: Stage = {
17
23
  const before = c.hits.length;
18
24
  c.hits = c.hits.filter((h) => {
19
25
  const corpus = h.metadata.corpus;
20
- if (!corpus || !DATASET_CORPORA.has(corpus)) return true;
26
+ if (!corpus || !datasetCorpora().has(corpus)) return true;
21
27
  return c.opts.datasetScope!.has(corpus);
22
28
  });
23
29
  if (c.hits.length !== before) console.log("corpus scope:", before, "→", c.hits.length, "candidates");
@@ -11,10 +11,8 @@ import { toHits, type Stage } from "./types.ts";
11
11
 
12
12
  const maxDocs = 2;
13
13
 
14
- const familyOf = (di: string): string | null => {
15
- const m = /^(?:OIML\s+)?([A-Z])\s?(\d{1,3})(?:[-–]([0-9A-Za-z]+))?/.exec(di);
16
- return m ? `${m[1]}-${m[2]}` : null;
17
- };
14
+ import { refCodec } from "../codecs.ts";
15
+ const familyOf = (di: string): string | null => refCodec().familyOf(di);
18
16
 
19
17
  export const editionCover: Stage = {
20
18
  name: "edition-cover",
@@ -10,6 +10,7 @@ export type { QueryUnderstanding };
10
10
 
11
11
  // The prompt is data (prompts/understanding.md), bundled as text.
12
12
  import SYSTEM from "../prompts/understanding.md";
13
+ import { fill, promptVars } from "./pipeline.ts";
13
14
 
14
15
  /** Understand the query with the cheap model. Null = use the regex fallback. */
15
16
  export async function understandQuery(
@@ -29,7 +30,7 @@ export async function understandQuery(
29
30
  const user = `${convo ? "Conversation so far:\n" + convo + "\n\n" : ""}${entityLine}Question: ${query}`;
30
31
  const body = {
31
32
  messages: [
32
- { role: "system", content: SYSTEM },
33
+ { role: "system", content: fill(SYSTEM, promptVars()) },
33
34
  { role: "user", content: user },
34
35
  ],
35
36
  // the model always reasons; reasoning tokens share this budget — too
@@ -1,49 +0,0 @@
1
- import {
2
- P
3
- } from "./chunk-MB74PTRM.js";
4
-
5
- // workers/worker_public/src/refusal.ts
6
- function refusalAnswer() {
7
- return P().prompts.vars.refusal_sentence;
8
- }
9
- var REFUSAL_VARIANT = /^\s*I don[’']?t have information on .{1,120}? in the indexed OIML(?: \w+){0,2} (?:publications|passages|documents|corpus)\.?/i;
10
- var REFUSAL_DRIFT = [
11
- /\b(can'?t|cannot|couldn'?t|unable)\b[^.]{0,120}?\b(indexed )?OIML(?: \w+){0,2} publications\b/i,
12
- /\bno real answer to give\b[^.]{0,120}?\bOIML\b/i,
13
- /\b(?:falls|well) outside\b[^.]{0,120}?\b(?:what I can answer|my scope|the scope of)\b/i,
14
- /\boutside (?:of )?what (?:I|this service) can answer\b/i,
15
- // "I can't answer that — weather forecasting is outside my scope":
16
- // requires the refusal verb, so a scope DISCUSSION inside a real answer
17
- // ("this exemption is outside the scope of R 60") never matches
18
- /\bI can[’']?t answer\b[^.]{0,100}?\bscope\b/i,
19
- /^\s*I don[’']?t have any indexed OIML \w+(?:s)? (?:covering|about|on)\b/im
20
- ];
21
- function sentenceStart(answer, i) {
22
- let s = 0;
23
- for (const sep of [". ", "! ", "? ", "\n"]) {
24
- const j = answer.lastIndexOf(sep, i);
25
- if (j >= 0) s = Math.max(s, j + sep.length);
26
- }
27
- return s;
28
- }
29
- function sentenceEnd(answer, i) {
30
- const m = /[.!?\n]/.exec(answer.slice(i));
31
- return m ? i + m.index + 1 : answer.length;
32
- }
33
- function canonicalRefusal(answer) {
34
- const CANON = refusalAnswer();
35
- if (answer.includes(CANON)) return answer;
36
- const variant = answer.match(REFUSAL_VARIANT);
37
- if (variant) return answer.replace(variant[0], CANON);
38
- for (const drift of REFUSAL_DRIFT) {
39
- const m = drift.exec(answer);
40
- if (!m) continue;
41
- return answer.slice(0, sentenceStart(answer, m.index)) + CANON + answer.slice(sentenceEnd(answer, m.index));
42
- }
43
- return answer;
44
- }
45
-
46
- export {
47
- refusalAnswer,
48
- canonicalRefusal
49
- };
@@ -1,10 +0,0 @@
1
- import {
2
- requestSalt,
3
- resolveRequestScope
4
- } from "./chunk-WWNCWKKC.js";
5
- import "./chunk-WOGQM7DJ.js";
6
- import "./chunk-MB74PTRM.js";
7
- export {
8
- requestSalt,
9
- resolveRequestScope
10
- };