@konneal/engine 0.1.4 → 0.2.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 +1 -0
- package/dist/ask-47RNGK2R.js +12 -0
- package/dist/chunk-3OXSQH7Y.js +1852 -0
- package/dist/chunk-6GOSMLRH.js +2781 -0
- package/dist/{chunk-EHJEELVB.js → chunk-LNSDBEKS.js} +1 -1
- package/dist/{chunk-35ODH64W.js → chunk-Q327B27J.js} +33 -0
- package/dist/{chunk-OCNLV7Q7.js → chunk-Q6LI4T7M.js} +6 -1
- package/dist/{chunk-ROF3Q7UC.js → chunk-SN3ANQ3Y.js} +2 -2
- package/dist/chunk-VJZLVU3S.js +64 -0
- package/dist/{chunk-CAEHIVG5.js → chunk-WGXATDXY.js} +1 -1
- package/dist/codecs.d.ts +3 -3
- package/dist/completion.d.ts +1 -1
- package/dist/config.d.ts +9 -0
- package/dist/faithfulness.d.ts +1 -0
- package/dist/mcp-proto.d.ts +25 -0
- package/dist/mcp.d.ts +4 -0
- package/dist/openapi-surface.gen.d.ts +9 -0
- package/dist/openapi-types.d.ts +2141 -0
- package/dist/profile.gen.d.ts +1 -0
- package/dist/prompts/system.md +1 -0
- package/dist/quota.d.ts +4 -1
- package/dist/search-OMPBMZT4.js +11 -0
- package/dist/tablecontext.d.ts +7 -0
- package/dist/verdict-parse.d.ts +5 -0
- package/dist/worker_mcp/src/index.js +3 -3
- package/dist/worker_public/src/config.js +4 -2
- package/dist/worker_public/src/index.js +1193 -4932
- package/dist/worker_public/src/profile.js +1 -1
- package/dist/worker_public/src/refusal.js +2 -2
- package/dist/worker_public/src/requestScope.js +3 -3
- package/docs/spec-api.md +27 -13
- package/package.json +12 -3
- package/profile/prompts.yaml +3 -0
- package/workers/shared/router.ts +23 -16
- package/workers/worker_public/migrations/0014_usage_cache.sql +5 -0
- package/workers/worker_public/openapi.yaml +1169 -0
- package/workers/worker_public/prompts/system.md +1 -0
- package/workers/worker_public/schema.sql +3 -1
- package/workers/worker_public/src/admin.ts +51 -7
- package/workers/worker_public/src/ai.ts +10 -2
- package/workers/worker_public/src/ask.ts +94 -22
- package/workers/worker_public/src/codecs.ts +35 -10
- package/workers/worker_public/src/completion.ts +24 -1
- package/workers/worker_public/src/config.ts +10 -0
- package/workers/worker_public/src/faithfulness.ts +10 -17
- package/workers/worker_public/src/grader.ts +2 -2
- package/workers/worker_public/src/index.ts +106 -58
- package/workers/worker_public/src/lib/router.ts +1 -1
- package/workers/worker_public/src/mcp-proto.ts +71 -0
- package/workers/worker_public/src/mcp.ts +47 -0
- package/workers/worker_public/src/openapi-surface.gen.ts +318 -0
- package/workers/worker_public/src/pipeline.ts +4 -2
- package/workers/worker_public/src/profile.gen.ts +1 -0
- package/workers/worker_public/src/projects.ts +4 -2
- package/workers/worker_public/src/quota.ts +4 -2
- package/workers/worker_public/src/research.ts +55 -3
- package/workers/worker_public/src/tablecontext.ts +13 -2
- package/workers/worker_public/src/verdict-parse.ts +60 -0
|
@@ -1,3 +1,33 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
try {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
} catch (e) {
|
|
11
|
+
throw mod = 0, e;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
28
|
+
mod
|
|
29
|
+
));
|
|
30
|
+
|
|
1
31
|
// workers/worker_public/src/profile.gen.ts
|
|
2
32
|
var PROFILE = {
|
|
3
33
|
"publisher": {
|
|
@@ -103,6 +133,7 @@ var PROFILE = {
|
|
|
103
133
|
},
|
|
104
134
|
"prompts": {
|
|
105
135
|
"vars": {
|
|
136
|
+
"publisher_identity": "the Fixture Organization \u2014 a worldwide organization that publishes the fixture corpus",
|
|
106
137
|
"assistant_identity": "the fixture assistant \u2014 a public service answering questions about the fixture publisher's documents",
|
|
107
138
|
"refusal_sentence": "I don't have information on this in the indexed fixture documents.",
|
|
108
139
|
"account_note_source": "the user's own fixture account",
|
|
@@ -128,6 +159,8 @@ function P() {
|
|
|
128
159
|
}
|
|
129
160
|
|
|
130
161
|
export {
|
|
162
|
+
__commonJS,
|
|
163
|
+
__toESM,
|
|
131
164
|
setProfile,
|
|
132
165
|
P
|
|
133
166
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
P
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-Q327B27J.js";
|
|
4
4
|
|
|
5
5
|
// workers/worker_public/src/config.ts
|
|
6
6
|
var MODELS = {
|
|
@@ -165,6 +165,10 @@ function datasetsFor(session) {
|
|
|
165
165
|
function SUGGESTIONS() {
|
|
166
166
|
return [...P().ui.suggestions];
|
|
167
167
|
}
|
|
168
|
+
function STARTERS() {
|
|
169
|
+
const groups = P().ui.starter_groups;
|
|
170
|
+
return Array.isArray(groups) && groups.length ? groups.map((g) => ({ label: g.label, q: g.q })) : SUGGESTIONS().map((q) => ({ label: "", q }));
|
|
171
|
+
}
|
|
168
172
|
function num(env, key, fallback) {
|
|
169
173
|
const v = Number(env[key]);
|
|
170
174
|
return Number.isFinite(v) && v > 0 ? v : fallback;
|
|
@@ -191,6 +195,7 @@ export {
|
|
|
191
195
|
datasetAllowed,
|
|
192
196
|
datasetsFor,
|
|
193
197
|
SUGGESTIONS,
|
|
198
|
+
STARTERS,
|
|
194
199
|
num,
|
|
195
200
|
today,
|
|
196
201
|
sha256Hex
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
LIMITS,
|
|
3
3
|
sha256Hex
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-Q6LI4T7M.js";
|
|
5
5
|
import {
|
|
6
6
|
P
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-Q327B27J.js";
|
|
8
8
|
|
|
9
9
|
// workers/worker_public/src/bubble.ts
|
|
10
10
|
function isAllowedBubbleOrigin(origin) {
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {
|
|
2
|
+
checkQuota,
|
|
3
|
+
clientIp,
|
|
4
|
+
graphExpand,
|
|
5
|
+
portModelRunner,
|
|
6
|
+
retrieve,
|
|
7
|
+
sessionFrom,
|
|
8
|
+
telemetry,
|
|
9
|
+
understandQuery
|
|
10
|
+
} from "./chunk-6GOSMLRH.js";
|
|
11
|
+
import {
|
|
12
|
+
corsHeaders,
|
|
13
|
+
err,
|
|
14
|
+
json,
|
|
15
|
+
readJson,
|
|
16
|
+
validateQuery
|
|
17
|
+
} from "./chunk-SN3ANQ3Y.js";
|
|
18
|
+
import {
|
|
19
|
+
LIMITS,
|
|
20
|
+
MODELS,
|
|
21
|
+
num,
|
|
22
|
+
sha256Hex
|
|
23
|
+
} from "./chunk-Q6LI4T7M.js";
|
|
24
|
+
|
|
25
|
+
// workers/worker_public/src/search.ts
|
|
26
|
+
async function handleSearch(env, ctx, req, tier, key) {
|
|
27
|
+
const body = await readJson(req);
|
|
28
|
+
const q = validateQuery(body);
|
|
29
|
+
if (!q) return err(400, "invalid_input", `query is required (1-${LIMITS.maxInputChars} chars)`);
|
|
30
|
+
const member = tier === "member" ? await sessionFrom(req, env) : null;
|
|
31
|
+
const limit = tier === "key" || member ? Number.MAX_SAFE_INTEGER : num(env, "ANON_DAY_SEARCH", 50);
|
|
32
|
+
const bucketId = tier === "key" ? `key:${key.id}` : member ? `sub:${member.sub}` : clientIp(req);
|
|
33
|
+
const quota = await checkQuota(env, "search", bucketId, limit);
|
|
34
|
+
if (!quota.ok) {
|
|
35
|
+
return err(429, "quota_exceeded", `Daily search limit reached (${quota.limit}). Try again tomorrow.`);
|
|
36
|
+
}
|
|
37
|
+
const understanding = await understandQuery(portModelRunner(env), MODELS.understand, q.query, []);
|
|
38
|
+
const graphDocNumbers = await graphExpand(env, understanding);
|
|
39
|
+
let retrieved;
|
|
40
|
+
try {
|
|
41
|
+
retrieved = await retrieve(env, q.query, { understanding, graphDocNumbers });
|
|
42
|
+
} catch {
|
|
43
|
+
return err(503, "retrieval_unavailable", "Search is briefly busy \u2014 please retry in a moment.");
|
|
44
|
+
}
|
|
45
|
+
const { hits, filters } = retrieved;
|
|
46
|
+
const results = hits.map((h) => ({
|
|
47
|
+
doc_id: h.metadata.doc_id,
|
|
48
|
+
docidentifier: h.metadata.docidentifier,
|
|
49
|
+
edition: h.metadata.edition,
|
|
50
|
+
language: h.metadata.language,
|
|
51
|
+
clause_anchor: h.metadata.clause_anchor,
|
|
52
|
+
clause_title: h.metadata.clause_title,
|
|
53
|
+
status: h.metadata.status ?? "unknown",
|
|
54
|
+
superseded_by: h.metadata.superseded_by || void 0,
|
|
55
|
+
text: h.text,
|
|
56
|
+
score: h.rerank_score ?? h.score
|
|
57
|
+
}));
|
|
58
|
+
telemetry(env, ctx, tier, "search", MODELS.embed, true, 0, await sha256Hex(q.query), q.lang);
|
|
59
|
+
return json({ results, filters, quota, ...corsHeaders(req) });
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export {
|
|
63
|
+
handleSearch
|
|
64
|
+
};
|
package/dist/codecs.d.ts
CHANGED
|
@@ -13,9 +13,9 @@ export interface RefCodec {
|
|
|
13
13
|
/** A docidentifier's family key ("R-60") for edition steering — null when not of the grammar. */
|
|
14
14
|
familyOf(docidentifier: string): string | null;
|
|
15
15
|
}
|
|
16
|
-
/** OIML's grammar: type letter
|
|
17
|
-
* optional edition year;
|
|
18
|
-
*
|
|
16
|
+
/** OIML's grammar (delegated): type letter + 1–3 digits, optional part,
|
|
17
|
+
* optional edition year; part numbers are significant (R 60-1), the
|
|
18
|
+
* edition is never part of the number. */
|
|
19
19
|
export declare const oimlPubid: RefCodec;
|
|
20
20
|
/** The generic floor: the identifier is whatever string it is. */
|
|
21
21
|
export declare const plainSlug: RefCodec;
|
package/dist/completion.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ import type { StoreQuery } from "./ports/store.ts";
|
|
|
2
2
|
import { type ResolvedBlock } from "./refs.ts";
|
|
3
3
|
import type { Hit } from "./pipeline.ts";
|
|
4
4
|
export declare function completeTables(db: StoreQuery, answer: string, used: Hit[]): Promise<ResolvedBlock[]>;
|
|
5
|
-
export declare function completeFigures(db: StoreQuery, answer: string, alreadyAttached: ResolvedBlock[]): Promise<ResolvedBlock[]>;
|
|
5
|
+
export declare function completeFigures(db: StoreQuery, answer: string, alreadyAttached: ResolvedBlock[], used?: Hit[]): Promise<ResolvedBlock[]>;
|
package/dist/config.d.ts
CHANGED
|
@@ -149,6 +149,15 @@ export declare function datasetsFor(session: unknown): unknown[];
|
|
|
149
149
|
/** Empty-state starter questions, served by /api/datasets — UI content
|
|
150
150
|
* comes from the API, never hardcoded in the client. */
|
|
151
151
|
export declare function SUGGESTIONS(): string[];
|
|
152
|
+
/** The first-run starters as the publisher structures them: one question
|
|
153
|
+
* per capability, labelled, so the interface's first presentation of
|
|
154
|
+
* the service shows what it can do rather than a flat cloud of
|
|
155
|
+
* definition lookups. Falls back to the flat list when the profile
|
|
156
|
+
* declares none. */
|
|
157
|
+
export declare function STARTERS(): {
|
|
158
|
+
label: string;
|
|
159
|
+
q: string;
|
|
160
|
+
}[];
|
|
152
161
|
export declare function num(env: Record<string, unknown>, key: string, fallback: number): number;
|
|
153
162
|
export declare function today(): string;
|
|
154
163
|
export declare function sha256Hex(s: string): Promise<string>;
|
package/dist/faithfulness.d.ts
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare const PROTOCOL_VERSION = "2025-06-18";
|
|
2
|
+
export interface McpTool {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
inputSchema: {
|
|
6
|
+
type: "object";
|
|
7
|
+
properties: Record<string, unknown>;
|
|
8
|
+
required: string[];
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export declare const TOOLS: McpTool[];
|
|
12
|
+
export type McpResult = {
|
|
13
|
+
ok: true;
|
|
14
|
+
result: unknown;
|
|
15
|
+
} | {
|
|
16
|
+
ok: true;
|
|
17
|
+
accepted: true;
|
|
18
|
+
} | {
|
|
19
|
+
ok: false;
|
|
20
|
+
code: number;
|
|
21
|
+
message: string;
|
|
22
|
+
};
|
|
23
|
+
/** Dispatch one JSON-RPC request; `callTool` adapts a tool call to the
|
|
24
|
+
* real handlers (the route adapter's job). */
|
|
25
|
+
export declare function dispatch(method: string | null, params: any, callTool: (name: string, args: Record<string, unknown>) => Promise<unknown>): Promise<McpResult>;
|
package/dist/mcp.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type ApiKey } from "./lib/http";
|
|
2
|
+
import type { Env } from "./env.ts";
|
|
3
|
+
import type { Background } from "./ports/runtime.ts";
|
|
4
|
+
export declare function handleMcp(env: Env, ctx: Background, req: Request, tier: "anon" | "key" | "member", key: ApiKey | null): Promise<Response>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface OpenApiRoute {
|
|
2
|
+
method: string;
|
|
3
|
+
pattern: string;
|
|
4
|
+
operationId: string;
|
|
5
|
+
}
|
|
6
|
+
export type OpenApiOperationId = "askAnonymous" | "askKeyed" | "search" | "searchKeyed" | "absence" | "absenceKeyed" | "verify" | "verifyKeyed" | "research" | "researchKeyed" | "mcp" | "datasets" | "keyUsage" | "health" | "listConversations" | "createConversation" | "getConversation" | "renameConversation" | "deleteConversation" | "appendMessage" | "shareConversation" | "getShared" | "listMemories" | "createMemory" | "deleteMemory" | "listProjects" | "createProject" | "deleteProject" | "listProjectFiles" | "attachProjectFile" | "detachProjectFile" | "laneQuery" | "laneKeyed" | "feedback" | "adminEnrich" | "adminEnrichAlias" | "adminSection" | "adminSectionAlias" | "adminVectors" | "adminCaption" | "adminJudge" | "adminJudgeAlias" | "adminRevokeKey" | "authMe" | "authLogin" | "authCallback" | "authLogout" | "authLogoutLink" | "adminStats" | "adminListKeys" | "adminCreateKey";
|
|
7
|
+
export declare const OPENAPI_SURFACE: readonly (Omit<OpenApiRoute, "operationId"> & {
|
|
8
|
+
operationId: OpenApiOperationId;
|
|
9
|
+
})[];
|