@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.
- package/dist/admin.d.ts +3 -0
- package/dist/{chunk-MB74PTRM.js → chunk-35ODH64W.js} +23 -4
- package/dist/chunk-CAEHIVG5.js +54 -0
- package/dist/{chunk-WWNCWKKC.js → chunk-EHJEELVB.js} +1 -1
- package/dist/{chunk-WOGQM7DJ.js → chunk-OCNLV7Q7.js} +2 -2
- package/dist/chunk-ROF3Q7UC.js +156 -0
- package/dist/codecs.d.ts +22 -0
- package/dist/context.d.ts +2 -9
- package/dist/modelplane.d.ts +1 -1
- package/dist/pipeline.d.ts +8 -1
- package/dist/profile.gen.d.ts +19 -0
- package/dist/profile2.gen.d.ts +89 -0
- package/dist/prompts/conversational.md +1 -1
- package/dist/prompts/enrichment.md +2 -2
- package/dist/prompts/precision.md +1 -1
- package/dist/prompts/research.md +1 -1
- package/dist/prompts/system.md +3 -3
- package/dist/prompts/understanding.md +4 -4
- package/dist/worker_mcp/src/index.d.ts +10 -0
- package/dist/worker_mcp/src/index.js +153 -0
- package/dist/{config.js → worker_public/src/config.js} +2 -2
- package/dist/{index.js → worker_public/src/index.js} +131 -207
- package/dist/{profile.js → worker_public/src/profile.js} +1 -1
- package/dist/{refusal.js → worker_public/src/refusal.js} +2 -2
- package/dist/worker_public/src/requestScope.js +10 -0
- package/package.json +16 -9
- package/profile/prompts.yaml +11 -0
- package/profile/publisher.yaml +9 -0
- package/profile/retrieval.yaml +4 -0
- package/scripts/gen_profile.mjs +6 -5
- package/workers/worker_internal/src/index.ts +1 -1
- package/workers/worker_mcp/src/index.ts +39 -26
- package/workers/worker_mcp/tsconfig.json +11 -4
- package/workers/worker_public/prompts/conversational.md +1 -1
- package/workers/worker_public/prompts/enrichment.md +2 -2
- package/workers/worker_public/prompts/precision.md +1 -1
- package/workers/worker_public/prompts/research.md +1 -1
- package/workers/worker_public/prompts/system.md +3 -3
- package/workers/worker_public/prompts/understanding.md +4 -4
- package/workers/worker_public/src/admin.ts +15 -3
- package/workers/worker_public/src/ask.ts +13 -10
- package/workers/worker_public/src/bubble.ts +13 -6
- package/workers/worker_public/src/codecs.ts +77 -0
- package/workers/worker_public/src/config.ts +1 -1
- package/workers/worker_public/src/context.ts +6 -26
- package/workers/worker_public/src/graph.ts +2 -3
- package/workers/worker_public/src/index.ts +5 -3
- package/workers/worker_public/src/lib/http.ts +5 -9
- package/workers/worker_public/src/livedata.ts +3 -2
- package/workers/worker_public/src/modelplane.ts +13 -5
- package/workers/worker_public/src/pipeline.ts +28 -13
- package/workers/worker_public/src/profile.gen.ts +23 -4
- package/workers/worker_public/src/profile2.gen.ts +122 -0
- package/workers/worker_public/src/refusal.ts +19 -21
- package/workers/worker_public/src/research.ts +4 -2
- package/workers/worker_public/src/stages/conceptGraph.ts +3 -2
- package/workers/worker_public/src/stages/corpusScope.ts +8 -2
- package/workers/worker_public/src/stages/editionCover.ts +2 -4
- package/workers/worker_public/src/understand.ts +2 -1
- package/dist/chunk-LLWPT2XV.js +0 -49
- package/dist/requestScope.js +0 -10
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import {
|
|
2
|
+
authenticate
|
|
3
|
+
} from "../../chunk-ROF3Q7UC.js";
|
|
4
|
+
import "../../chunk-OCNLV7Q7.js";
|
|
5
|
+
import {
|
|
6
|
+
P
|
|
7
|
+
} from "../../chunk-35ODH64W.js";
|
|
8
|
+
|
|
9
|
+
// workers/worker_mcp/src/index.ts
|
|
10
|
+
var PROTOCOL_VERSION = "2025-06-18";
|
|
11
|
+
var json = (body, status = 200, extra = {}) => new Response(JSON.stringify(body), {
|
|
12
|
+
status,
|
|
13
|
+
headers: { "content-type": "application/json", ...extra }
|
|
14
|
+
});
|
|
15
|
+
var rpcResult = (id, result) => json({ jsonrpc: "2.0", id, result });
|
|
16
|
+
var rpcError = (id, code, message) => json({ jsonrpc: "2.0", id, error: { code, message } });
|
|
17
|
+
var publisherId = () => P().publisher.id;
|
|
18
|
+
var bearer = (req) => (req.headers.get("authorization") ?? "").replace(/^Bearer\s+/i, "").trim();
|
|
19
|
+
var publisherName = () => P().publisher.name;
|
|
20
|
+
var TOOLS = [
|
|
21
|
+
{
|
|
22
|
+
name: `${publisherId()}_search`,
|
|
23
|
+
description: `Search the ${publisherName()} publications corpus. Returns ranked passages with publication identifier, edition, clause and snippet.`,
|
|
24
|
+
inputSchema: {
|
|
25
|
+
type: "object",
|
|
26
|
+
properties: {
|
|
27
|
+
query: { type: "string", description: "Natural-language search query" },
|
|
28
|
+
top_k: { type: "integer", description: "Number of passages (default 5, max 10)", default: 5 }
|
|
29
|
+
},
|
|
30
|
+
required: ["query"]
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: `${publisherId()}_documents`,
|
|
35
|
+
description: `Look up the publication registry for a ${publisherName()} family: every edition with its derived status (in-force/superseded), which edition is ACTIVE (terminal of the successor chain), and supersession links. Use for 'current/latest edition' and edition-history questions.`,
|
|
36
|
+
inputSchema: {
|
|
37
|
+
type: "object",
|
|
38
|
+
properties: {
|
|
39
|
+
family: { type: "string", description: "Family key, e.g. 'R-60' (series letter-number)" }
|
|
40
|
+
},
|
|
41
|
+
required: ["family"]
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: `${publisherId()}_ask`,
|
|
46
|
+
description: `Ask a question about ${publisherName()} publications and get a grounded, citation-linked answer. Every claim cites the exact publication and clause it comes from.`,
|
|
47
|
+
inputSchema: {
|
|
48
|
+
type: "object",
|
|
49
|
+
properties: {
|
|
50
|
+
query: { type: "string", description: "The question" },
|
|
51
|
+
fresh: { type: "boolean", description: "Skip the answer cache and regenerate from the live corpus (default false)" }
|
|
52
|
+
},
|
|
53
|
+
required: ["query"]
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
];
|
|
57
|
+
async function rag(env, auth, path, body) {
|
|
58
|
+
const res = await fetch(`${env.RAG_BASE}${path}`, {
|
|
59
|
+
method: "POST",
|
|
60
|
+
headers: { "content-type": "application/json", authorization: auth },
|
|
61
|
+
body: JSON.stringify(body)
|
|
62
|
+
});
|
|
63
|
+
if (!res.ok) throw new Error(`rag-public ${path} \u2192 ${res.status}`);
|
|
64
|
+
return res.json();
|
|
65
|
+
}
|
|
66
|
+
function searchResultText(r) {
|
|
67
|
+
const anchor = r.clause_anchor && r.clause_anchor !== "overview" ? ` \xA7${r.clause_anchor}` : "";
|
|
68
|
+
return `${r.docidentifier ?? r.doc_id}${r.edition ? ":" + r.edition : ""}${anchor}${r.clause_title ? " \u2014 " + r.clause_title : ""}
|
|
69
|
+
${r.snippet ?? ""}`;
|
|
70
|
+
}
|
|
71
|
+
async function callTool(env, auth, name, args) {
|
|
72
|
+
if (name === `${publisherId()}_search`) {
|
|
73
|
+
const query = String(args?.query ?? "").slice(0, 2e3);
|
|
74
|
+
if (!query) throw new Error("query is required");
|
|
75
|
+
const data = await rag(env, auth, "/api/search", { query, top_k: Math.min(10, Math.max(1, Number(args?.top_k) || 5)) });
|
|
76
|
+
const text = (data.results ?? []).map(searchResultText).join("\n\n") || "No passages matched.";
|
|
77
|
+
return { content: [{ type: "text", text }] };
|
|
78
|
+
}
|
|
79
|
+
if (name === `${publisherId()}_documents`) {
|
|
80
|
+
const family = String(args?.family ?? "").trim().slice(0, 20);
|
|
81
|
+
if (!/^[A-Z]-\d{1,3}$/i.test(family)) throw new Error("family must look like 'R-60'");
|
|
82
|
+
const rows = await env.DB.prepare(
|
|
83
|
+
"SELECT d.docidentifier, d.derived_status, d.active, s.docidentifier AS succ FROM documents d LEFT JOIN documents s ON d.superseded_by = s.canonical_id WHERE d.family = ?1 ORDER BY d.part, d.edition"
|
|
84
|
+
).bind(family.toUpperCase()).all();
|
|
85
|
+
const lines = (rows.results ?? []).map(
|
|
86
|
+
(r) => `${r.docidentifier} \u2014 ${r.derived_status}${r.active ? " [ACTIVE]" : ""}${r.succ ? ` \u2192 superseded by ${r.succ}` : ""}`
|
|
87
|
+
);
|
|
88
|
+
return { content: [{ type: "text", text: lines.join("\n") || `No editions found for ${family}` }] };
|
|
89
|
+
}
|
|
90
|
+
if (name === `${publisherId()}_ask`) {
|
|
91
|
+
const query = String(args?.query ?? "").slice(0, 2e3);
|
|
92
|
+
if (!query) throw new Error("query is required");
|
|
93
|
+
const data = await rag(env, auth, "/api/ask", { query, stream: false, ...args?.fresh ? { fresh: true } : {} });
|
|
94
|
+
const cites = (data.citations ?? []).map((c) => `${c.docidentifier}${c.clause_anchor ? " \xA7" + c.clause_anchor : ""}`).join(", ");
|
|
95
|
+
const text = `${data.answer ?? ""}${cites ? `
|
|
96
|
+
|
|
97
|
+
Sources: ${cites}` : ""}`;
|
|
98
|
+
return { content: [{ type: "text", text }] };
|
|
99
|
+
}
|
|
100
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
101
|
+
}
|
|
102
|
+
var src_default = {
|
|
103
|
+
async fetch(req, env) {
|
|
104
|
+
const url = new URL(req.url);
|
|
105
|
+
if (req.method === "GET" && url.pathname === "/") {
|
|
106
|
+
return json({
|
|
107
|
+
server: "rag-mcp",
|
|
108
|
+
transport: "streamable-http",
|
|
109
|
+
endpoint: "/mcp",
|
|
110
|
+
tools: TOOLS.map((t) => t.name)
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
if (url.pathname !== "/mcp") return json({ error: "not_found" }, 404);
|
|
114
|
+
if (req.method !== "POST") return json({ error: "method_not_allowed \u2014 POST JSON-RPC to /mcp" }, 405);
|
|
115
|
+
const key = await authenticate(env, req);
|
|
116
|
+
if (!key) return json({ jsonrpc: "2.0", id: null, error: { code: -32001, message: "Unauthorized: configure this MCP server with an API key (Authorization: Bearer <key>)" } }, 401);
|
|
117
|
+
let msg;
|
|
118
|
+
try {
|
|
119
|
+
msg = await req.json();
|
|
120
|
+
} catch {
|
|
121
|
+
return rpcError(null, -32700, "Parse error");
|
|
122
|
+
}
|
|
123
|
+
if (msg?.id === void 0 || msg?.id === null) return new Response(null, { status: 202 });
|
|
124
|
+
try {
|
|
125
|
+
switch (msg.method) {
|
|
126
|
+
case "initialize":
|
|
127
|
+
return rpcResult(msg.id, {
|
|
128
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
129
|
+
capabilities: { tools: {} },
|
|
130
|
+
serverInfo: { name: "rag-mcp", version: "1.0.0", title: `${P().publisher.product_name} \u2014 public corpus` }
|
|
131
|
+
});
|
|
132
|
+
case "tools/list":
|
|
133
|
+
return rpcResult(msg.id, { tools: TOOLS });
|
|
134
|
+
case "tools/call": {
|
|
135
|
+
const out = await callTool(env, bearer(req), String(msg.params?.name ?? ""), msg.params?.arguments ?? {});
|
|
136
|
+
return rpcResult(msg.id, out);
|
|
137
|
+
}
|
|
138
|
+
case "ping":
|
|
139
|
+
return rpcResult(msg.id, {});
|
|
140
|
+
default:
|
|
141
|
+
return rpcError(msg.id, -32601, `Method not found: ${msg.method}`);
|
|
142
|
+
}
|
|
143
|
+
} catch (e) {
|
|
144
|
+
return rpcResult(msg.id, {
|
|
145
|
+
content: [{ type: "text", text: `Error: ${String(e?.message ?? e)}` }],
|
|
146
|
+
isError: true
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
export {
|
|
152
|
+
src_default as default
|
|
153
|
+
};
|