@konneal/engine 0.2.180 → 0.2.184
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-7DFXT4DJ.js +16 -0
- package/dist/{chunk-FNQ7UOEB.js → chunk-5HCVX34C.js} +1 -1
- package/dist/{chunk-ZHT4456M.js → chunk-7RZ2D64X.js} +1 -1
- package/dist/{chunk-HWWJAJWM.js → chunk-QYTCQIA6.js} +3 -0
- package/dist/{chunk-D7MO4RVQ.js → chunk-XMUG75ZV.js} +1 -1
- package/dist/{chunk-ROXOL4GF.js → chunk-XO26UIFH.js} +5 -5
- package/dist/{chunk-CLDMP5YH.js → chunk-XTWH3PS6.js} +21 -4
- package/dist/{chunk-KINFFYQH.js → chunk-YGQCVPX6.js} +6 -0
- package/dist/{chunk-MUWO2EV6.js → chunk-YQQ3W5CE.js} +5 -5
- package/dist/{chunk-UMF7Y6JH.js → chunk-ZFOODZWO.js} +238 -8
- package/dist/config.d.ts +3 -0
- package/dist/{env-CNO44VN2.js → env-BZWHCSCL.js} +1 -1
- package/dist/env.d.ts +2 -0
- package/dist/openapi-surface.gen.d.ts +1 -1
- package/dist/openapi-types.d.ts +160 -0
- package/dist/search-4FWS4HVI.js +14 -0
- package/dist/{tools-UCUNOJR4.js → tools-BTH6YAOB.js} +5 -5
- package/dist/userDocuments.d.ts +72 -0
- package/dist/worker_mcp/src/index.js +2 -2
- package/dist/worker_public/src/config.js +1 -1
- package/dist/worker_public/src/index.js +82 -11
- package/dist/worker_public/src/requestScope.js +2 -2
- package/package.json +1 -1
- package/workers/worker_public/migrations/0020_user_documents.sql +18 -0
- package/workers/worker_public/openapi.yaml +72 -0
- package/workers/worker_public/schema.sql +16 -0
- package/workers/worker_public/src/ask.ts +11 -2
- package/workers/worker_public/src/config.ts +3 -0
- package/workers/worker_public/src/env.ts +2 -0
- package/workers/worker_public/src/index.ts +48 -1
- package/workers/worker_public/src/openapi-surface.gen.ts +24 -0
- package/workers/worker_public/src/ports/cloudflare/adapters.ts +3 -0
- package/workers/worker_public/src/ports/vector.ts +3 -0
- package/workers/worker_public/src/stages/index.ts +2 -0
- package/workers/worker_public/src/stages/types.ts +3 -0
- package/workers/worker_public/src/stages/userLane.ts +22 -0
- package/workers/worker_public/src/userDocuments.ts +329 -0
- package/workers/worker_public/wrangler.toml +8 -0
- package/dist/ask-TOJKDMU7.js +0 -16
- package/dist/search-KNPPTHMG.js +0 -14
package/dist/openapi-types.d.ts
CHANGED
|
@@ -454,6 +454,48 @@ export interface paths {
|
|
|
454
454
|
patch?: never;
|
|
455
455
|
trace?: never;
|
|
456
456
|
};
|
|
457
|
+
"/api/user-documents": {
|
|
458
|
+
parameters: {
|
|
459
|
+
query?: never;
|
|
460
|
+
header?: never;
|
|
461
|
+
path?: never;
|
|
462
|
+
cookie?: never;
|
|
463
|
+
};
|
|
464
|
+
/** List the member's imported documents */
|
|
465
|
+
get: operations["listUserDocuments"];
|
|
466
|
+
put?: never;
|
|
467
|
+
/**
|
|
468
|
+
* Import a document (a certificate or a test report)
|
|
469
|
+
* @description Member-gated. Upload one PNG/JPEG/WebP image or a PDF (20 MB max, 10 documents held per member until deleted). The import runs asynchronously: the route answers 202 with the importing row, the status endpoint (or a re-list) tells the rest. Images ride the vision lane; a PDF's text layer is extracted (a scanned PDF with no text layer is answered honestly with the no_text_layer status). Retention: held until the member deletes; deletion is immediate and total.
|
|
470
|
+
*/
|
|
471
|
+
post: operations["createUserDocument"];
|
|
472
|
+
delete?: never;
|
|
473
|
+
options?: never;
|
|
474
|
+
head?: never;
|
|
475
|
+
patch?: never;
|
|
476
|
+
trace?: never;
|
|
477
|
+
};
|
|
478
|
+
"/api/user-documents/{id}": {
|
|
479
|
+
parameters: {
|
|
480
|
+
query?: never;
|
|
481
|
+
header?: never;
|
|
482
|
+
path?: never;
|
|
483
|
+
cookie?: never;
|
|
484
|
+
};
|
|
485
|
+
/** One imported document's status and extracted fields */
|
|
486
|
+
get: operations["getUserDocument"];
|
|
487
|
+
put?: never;
|
|
488
|
+
post?: never;
|
|
489
|
+
/**
|
|
490
|
+
* Delete an imported document
|
|
491
|
+
* @description Immediate and total — the stored file, the private-lane vectors and the row go together.
|
|
492
|
+
*/
|
|
493
|
+
delete: operations["deleteUserDocument"];
|
|
494
|
+
options?: never;
|
|
495
|
+
head?: never;
|
|
496
|
+
patch?: never;
|
|
497
|
+
trace?: never;
|
|
498
|
+
};
|
|
457
499
|
"/api/projects": {
|
|
458
500
|
parameters: {
|
|
459
501
|
query?: never;
|
|
@@ -1766,6 +1808,124 @@ export interface operations {
|
|
|
1766
1808
|
};
|
|
1767
1809
|
};
|
|
1768
1810
|
};
|
|
1811
|
+
listUserDocuments: {
|
|
1812
|
+
parameters: {
|
|
1813
|
+
query?: never;
|
|
1814
|
+
header?: never;
|
|
1815
|
+
path?: never;
|
|
1816
|
+
cookie?: never;
|
|
1817
|
+
};
|
|
1818
|
+
requestBody?: never;
|
|
1819
|
+
responses: {
|
|
1820
|
+
/** @description The documents with their import status and the quota. */
|
|
1821
|
+
200: {
|
|
1822
|
+
headers: {
|
|
1823
|
+
[name: string]: unknown;
|
|
1824
|
+
};
|
|
1825
|
+
content?: never;
|
|
1826
|
+
};
|
|
1827
|
+
};
|
|
1828
|
+
};
|
|
1829
|
+
createUserDocument: {
|
|
1830
|
+
parameters: {
|
|
1831
|
+
query?: never;
|
|
1832
|
+
header?: never;
|
|
1833
|
+
path?: never;
|
|
1834
|
+
cookie?: never;
|
|
1835
|
+
};
|
|
1836
|
+
requestBody: {
|
|
1837
|
+
content: {
|
|
1838
|
+
"multipart/form-data": {
|
|
1839
|
+
/** Format: binary */
|
|
1840
|
+
file: string;
|
|
1841
|
+
};
|
|
1842
|
+
};
|
|
1843
|
+
};
|
|
1844
|
+
responses: {
|
|
1845
|
+
/** @description The import is running; the row carries its status. */
|
|
1846
|
+
202: {
|
|
1847
|
+
headers: {
|
|
1848
|
+
[name: string]: unknown;
|
|
1849
|
+
};
|
|
1850
|
+
content?: never;
|
|
1851
|
+
};
|
|
1852
|
+
/** @description The member holds the maximum of 10 documents. */
|
|
1853
|
+
403: {
|
|
1854
|
+
headers: {
|
|
1855
|
+
[name: string]: unknown;
|
|
1856
|
+
};
|
|
1857
|
+
content?: never;
|
|
1858
|
+
};
|
|
1859
|
+
/** @description The document exceeds the 20 MB limit. */
|
|
1860
|
+
413: {
|
|
1861
|
+
headers: {
|
|
1862
|
+
[name: string]: unknown;
|
|
1863
|
+
};
|
|
1864
|
+
content?: never;
|
|
1865
|
+
};
|
|
1866
|
+
/** @description Unsupported media type. */
|
|
1867
|
+
415: {
|
|
1868
|
+
headers: {
|
|
1869
|
+
[name: string]: unknown;
|
|
1870
|
+
};
|
|
1871
|
+
content?: never;
|
|
1872
|
+
};
|
|
1873
|
+
};
|
|
1874
|
+
};
|
|
1875
|
+
getUserDocument: {
|
|
1876
|
+
parameters: {
|
|
1877
|
+
query?: never;
|
|
1878
|
+
header?: never;
|
|
1879
|
+
path: {
|
|
1880
|
+
id: string;
|
|
1881
|
+
};
|
|
1882
|
+
cookie?: never;
|
|
1883
|
+
};
|
|
1884
|
+
requestBody?: never;
|
|
1885
|
+
responses: {
|
|
1886
|
+
/** @description The document row. */
|
|
1887
|
+
200: {
|
|
1888
|
+
headers: {
|
|
1889
|
+
[name: string]: unknown;
|
|
1890
|
+
};
|
|
1891
|
+
content?: never;
|
|
1892
|
+
};
|
|
1893
|
+
/** @description No such document for this member. */
|
|
1894
|
+
404: {
|
|
1895
|
+
headers: {
|
|
1896
|
+
[name: string]: unknown;
|
|
1897
|
+
};
|
|
1898
|
+
content?: never;
|
|
1899
|
+
};
|
|
1900
|
+
};
|
|
1901
|
+
};
|
|
1902
|
+
deleteUserDocument: {
|
|
1903
|
+
parameters: {
|
|
1904
|
+
query?: never;
|
|
1905
|
+
header?: never;
|
|
1906
|
+
path: {
|
|
1907
|
+
id: string;
|
|
1908
|
+
};
|
|
1909
|
+
cookie?: never;
|
|
1910
|
+
};
|
|
1911
|
+
requestBody?: never;
|
|
1912
|
+
responses: {
|
|
1913
|
+
/** @description The document is deleted. */
|
|
1914
|
+
200: {
|
|
1915
|
+
headers: {
|
|
1916
|
+
[name: string]: unknown;
|
|
1917
|
+
};
|
|
1918
|
+
content?: never;
|
|
1919
|
+
};
|
|
1920
|
+
/** @description No such document for this member. */
|
|
1921
|
+
404: {
|
|
1922
|
+
headers: {
|
|
1923
|
+
[name: string]: unknown;
|
|
1924
|
+
};
|
|
1925
|
+
content?: never;
|
|
1926
|
+
};
|
|
1927
|
+
};
|
|
1928
|
+
};
|
|
1769
1929
|
listProjects: {
|
|
1770
1930
|
parameters: {
|
|
1771
1931
|
query?: never;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
handleSearch
|
|
3
|
+
} from "./chunk-YQQ3W5CE.js";
|
|
4
|
+
import "./chunk-XTWH3PS6.js";
|
|
5
|
+
import "./chunk-7RZ2D64X.js";
|
|
6
|
+
import "./chunk-XMUG75ZV.js";
|
|
7
|
+
import "./chunk-ETLSWSZ7.js";
|
|
8
|
+
import "./chunk-5HCVX34C.js";
|
|
9
|
+
import "./chunk-QYTCQIA6.js";
|
|
10
|
+
import "./chunk-3FYJM7LH.js";
|
|
11
|
+
import "./chunk-YGQCVPX6.js";
|
|
12
|
+
export {
|
|
13
|
+
handleSearch
|
|
14
|
+
};
|
|
@@ -4,12 +4,12 @@ import {
|
|
|
4
4
|
parseToolCall,
|
|
5
5
|
runTool,
|
|
6
6
|
toolNote
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-
|
|
10
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-XO26UIFH.js";
|
|
8
|
+
import "./chunk-7RZ2D64X.js";
|
|
9
|
+
import "./chunk-5HCVX34C.js";
|
|
10
|
+
import "./chunk-QYTCQIA6.js";
|
|
11
11
|
import "./chunk-3FYJM7LH.js";
|
|
12
|
-
import "./chunk-
|
|
12
|
+
import "./chunk-YGQCVPX6.js";
|
|
13
13
|
export {
|
|
14
14
|
TOOLS_REGISTRY,
|
|
15
15
|
TOOL_DECLARATION,
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { Blobs } from "./ports/blobs.ts";
|
|
2
|
+
import type { StoreQuery } from "./ports/store.ts";
|
|
3
|
+
import type { VectorIndex } from "./ports/vector.ts";
|
|
4
|
+
import type { ModelRunner } from "./ports/model.ts";
|
|
5
|
+
import type { Hit } from "../../shared/chunk.ts";
|
|
6
|
+
export declare const USER_DOC_LIMIT = 10;
|
|
7
|
+
export declare const USER_DOC_MAX_BYTES: number;
|
|
8
|
+
export interface UserDocumentRow {
|
|
9
|
+
id: string;
|
|
10
|
+
owner_sub: string;
|
|
11
|
+
name: string;
|
|
12
|
+
kind: string | null;
|
|
13
|
+
status: string;
|
|
14
|
+
bytes: number;
|
|
15
|
+
r2_key: string | null;
|
|
16
|
+
fields: string | null;
|
|
17
|
+
error: string | null;
|
|
18
|
+
created_at: string;
|
|
19
|
+
updated_at: string;
|
|
20
|
+
}
|
|
21
|
+
export interface UserDocumentPorts {
|
|
22
|
+
store: StoreQuery;
|
|
23
|
+
blobs: Blobs;
|
|
24
|
+
lane: VectorIndex;
|
|
25
|
+
model: ModelRunner;
|
|
26
|
+
}
|
|
27
|
+
export interface UploadBlob {
|
|
28
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
29
|
+
size: number;
|
|
30
|
+
type: string;
|
|
31
|
+
name: string;
|
|
32
|
+
}
|
|
33
|
+
/** The lane's one chunk id per document — deterministic, so deletion
|
|
34
|
+
* can drop it by id without an index listing round-trip. */
|
|
35
|
+
export declare function userDocumentChunkId(docId: string): string;
|
|
36
|
+
export declare function listUserDocuments(store: StoreQuery, sub: string): Promise<{
|
|
37
|
+
documents: UserDocumentRow[];
|
|
38
|
+
}>;
|
|
39
|
+
export declare function getUserDocument(store: StoreQuery, sub: string, id: string): Promise<UserDocumentRow | null>;
|
|
40
|
+
/** The quota guard: 10 documents per member. Returns the refusal
|
|
41
|
+
* response or null. */
|
|
42
|
+
export declare function quotaRefusal(store: StoreQuery, sub: string): Promise<Response | null>;
|
|
43
|
+
/** The import: validate, store the original, record the row, and run
|
|
44
|
+
* the extraction under the request's waitUntil — the route answers
|
|
45
|
+
* 202 with the importing row and the status endpoint tells the rest.
|
|
46
|
+
* Every quota rule is checked BEFORE anything is stored. */
|
|
47
|
+
export declare function createImport(ports: UserDocumentPorts, waitUntil: (p: Promise<unknown>) => void, sub: string, file: UploadBlob): Promise<{
|
|
48
|
+
document: UserDocumentRow;
|
|
49
|
+
} | {
|
|
50
|
+
error: Response;
|
|
51
|
+
}>;
|
|
52
|
+
/** The worker's half of the extraction: get text (vision for images,
|
|
53
|
+
* the PDF text layer for digital-born PDFs), then one structuring
|
|
54
|
+
* call. Statuses land on the row either way — importing | ready |
|
|
55
|
+
* no_text_layer | failed, never a silent empty import. */
|
|
56
|
+
export declare function processImport(ports: UserDocumentPorts, row: UserDocumentRow, mime: string, bytes: Uint8Array): Promise<void>;
|
|
57
|
+
/** The digital-born PDF's text layer: inflate FlateDecode content
|
|
58
|
+
* streams and scan the text-showing operators (Tj/TJ/'/"). Scanned
|
|
59
|
+
* PDFs have no text layer — the honest no_text_layer status answers
|
|
60
|
+
* them. No external dependency; Workers' DecompressionStream does the
|
|
61
|
+
* inflate. */
|
|
62
|
+
export declare function pdfTextLayer(bytes: Uint8Array): Promise<string>;
|
|
63
|
+
/** Pull the string literals out of one content stream's text ops. */
|
|
64
|
+
export declare function pdfTextOps(content: string): string;
|
|
65
|
+
/** The federation's one door: the caller's OWN lane, filtered by their
|
|
66
|
+
* sub — the filter is a required parameter, there is no unfiltered
|
|
67
|
+
* path. Returns Hit-shaped matches (toHits convention: text from
|
|
68
|
+
* metadata.chunk_text). */
|
|
69
|
+
export declare function queryUserLane(model: ModelRunner, lane: VectorIndex, sub: string, query: string, k: number): Promise<Hit[]>;
|
|
70
|
+
/** Deletion is immediate and total: the R2 object, the lane vectors,
|
|
71
|
+
* the row. The caller has already checked ownership. */
|
|
72
|
+
export declare function deleteUserDocument(ports: UserDocumentPorts, sub: string, id: string): Promise<UserDocumentRow | null>;
|
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
|
+
USER_DOC_LIMIT,
|
|
2
3
|
checkQuoteAnchors,
|
|
4
|
+
createImport,
|
|
5
|
+
deleteUserDocument,
|
|
6
|
+
getUserDocument,
|
|
3
7
|
handleAsk,
|
|
4
8
|
handleMemories,
|
|
9
|
+
listUserDocuments,
|
|
5
10
|
scoreFaithfulness,
|
|
6
11
|
scoreJudge
|
|
7
|
-
} from "../../chunk-
|
|
12
|
+
} from "../../chunk-ZFOODZWO.js";
|
|
8
13
|
import "../../chunk-IRCDOFP4.js";
|
|
9
14
|
import {
|
|
10
15
|
TOOLS_REGISTRY,
|
|
11
16
|
bindModelNode,
|
|
12
17
|
modelGroundingBlock
|
|
13
|
-
} from "../../chunk-
|
|
18
|
+
} from "../../chunk-XO26UIFH.js";
|
|
14
19
|
import {
|
|
15
20
|
handleSearch
|
|
16
|
-
} from "../../chunk-
|
|
21
|
+
} from "../../chunk-YQQ3W5CE.js";
|
|
17
22
|
import {
|
|
18
23
|
buildMessages,
|
|
19
24
|
citations,
|
|
@@ -38,11 +43,11 @@ import {
|
|
|
38
43
|
sessionFrom,
|
|
39
44
|
telemetry,
|
|
40
45
|
understandQuery
|
|
41
|
-
} from "../../chunk-
|
|
46
|
+
} from "../../chunk-XTWH3PS6.js";
|
|
42
47
|
import {
|
|
43
48
|
embed,
|
|
44
49
|
generateOnce
|
|
45
|
-
} from "../../chunk-
|
|
50
|
+
} from "../../chunk-7RZ2D64X.js";
|
|
46
51
|
import {
|
|
47
52
|
authenticate,
|
|
48
53
|
corsHeaders,
|
|
@@ -51,14 +56,14 @@ import {
|
|
|
51
56
|
readJson,
|
|
52
57
|
validateQuery,
|
|
53
58
|
withCors
|
|
54
|
-
} from "../../chunk-
|
|
59
|
+
} from "../../chunk-XMUG75ZV.js";
|
|
55
60
|
import {
|
|
56
61
|
canonicalRefusal
|
|
57
62
|
} from "../../chunk-ETLSWSZ7.js";
|
|
58
63
|
import {
|
|
59
64
|
entitlementScope,
|
|
60
65
|
standardKeysFrom
|
|
61
|
-
} from "../../chunk-
|
|
66
|
+
} from "../../chunk-5HCVX34C.js";
|
|
62
67
|
import {
|
|
63
68
|
LIMITS,
|
|
64
69
|
MODELS,
|
|
@@ -69,15 +74,18 @@ import {
|
|
|
69
74
|
roleModel,
|
|
70
75
|
sha256Hex,
|
|
71
76
|
today
|
|
72
|
-
} from "../../chunk-
|
|
77
|
+
} from "../../chunk-QYTCQIA6.js";
|
|
73
78
|
import {
|
|
74
79
|
P,
|
|
75
80
|
setProfile
|
|
76
81
|
} from "../../chunk-3FYJM7LH.js";
|
|
77
82
|
import {
|
|
78
83
|
cfBlobs,
|
|
84
|
+
cfModelRunner,
|
|
85
|
+
cfStore,
|
|
86
|
+
cfVectorIndex,
|
|
79
87
|
portModelRunner
|
|
80
|
-
} from "../../chunk-
|
|
88
|
+
} from "../../chunk-YGQCVPX6.js";
|
|
81
89
|
|
|
82
90
|
// workers/worker_public/src/conversations.ts
|
|
83
91
|
var ID_RE = /^[a-zA-Z0-9_-]{8,64}$/;
|
|
@@ -1175,13 +1183,13 @@ async function callToolOnce(env, ctx, _req, tier, key, name, args, t0) {
|
|
|
1175
1183
|
// stream:false forces the JSON lane (anon defaults to SSE)
|
|
1176
1184
|
body: JSON.stringify({ ...args, stream: false })
|
|
1177
1185
|
});
|
|
1178
|
-
const { runTool, TOOLS_REGISTRY: TOOLS_REGISTRY2 } = await import("../../tools-
|
|
1186
|
+
const { runTool, TOOLS_REGISTRY: TOOLS_REGISTRY2 } = await import("../../tools-BTH6YAOB.js");
|
|
1179
1187
|
let payload;
|
|
1180
1188
|
if (TOOLS_REGISTRY2.some((t) => t.name === name && t.audiences.includes("mcp"))) {
|
|
1181
1189
|
const r = await runTool({ ...env, DB: env.DB }, { name, args }, "mcp");
|
|
1182
1190
|
payload = r ? { tool: r.name, query: r.query, result: r.output } : { error: { message: `tool ${name} returned nothing for the given arguments` } };
|
|
1183
1191
|
} else {
|
|
1184
|
-
const res = name === "ask" ? await (await import("../../ask-
|
|
1192
|
+
const res = name === "ask" ? await (await import("../../ask-7DFXT4DJ.js")).handleAsk(env, ctx, inner, tier, key) : await (await import("../../search-4FWS4HVI.js")).handleSearch(env, ctx, inner, tier, key);
|
|
1185
1193
|
payload = await res.json().catch(() => ({ error: { message: "tool transport failed", status: res.status } }));
|
|
1186
1194
|
}
|
|
1187
1195
|
telemetry(env, ctx, tier, `mcp:${name}`, null, !payload?.error, JSON.stringify(payload).length, await sha256Hex(`${name}:${JSON.stringify(args ?? {})}`), void 0, void 0, { durationMs: Date.now() - t0 });
|
|
@@ -1363,6 +1371,26 @@ var OPENAPI_SURFACE = [
|
|
|
1363
1371
|
"pattern": "/api/memories/:id",
|
|
1364
1372
|
"operationId": "deleteMemory"
|
|
1365
1373
|
},
|
|
1374
|
+
{
|
|
1375
|
+
"method": "GET",
|
|
1376
|
+
"pattern": "/api/user-documents",
|
|
1377
|
+
"operationId": "listUserDocuments"
|
|
1378
|
+
},
|
|
1379
|
+
{
|
|
1380
|
+
"method": "POST",
|
|
1381
|
+
"pattern": "/api/user-documents",
|
|
1382
|
+
"operationId": "createUserDocument"
|
|
1383
|
+
},
|
|
1384
|
+
{
|
|
1385
|
+
"method": "GET",
|
|
1386
|
+
"pattern": "/api/user-documents/:id",
|
|
1387
|
+
"operationId": "getUserDocument"
|
|
1388
|
+
},
|
|
1389
|
+
{
|
|
1390
|
+
"method": "DELETE",
|
|
1391
|
+
"pattern": "/api/user-documents/:id",
|
|
1392
|
+
"operationId": "deleteUserDocument"
|
|
1393
|
+
},
|
|
1366
1394
|
{
|
|
1367
1395
|
"method": "GET",
|
|
1368
1396
|
"pattern": "/api/projects",
|
|
@@ -1576,6 +1604,45 @@ async function memoriesRoute(c) {
|
|
|
1576
1604
|
if (refused) return withCors(refused, corsHeaders(c.req));
|
|
1577
1605
|
return withCors(await handleMemories(c.env, who.sub, c.req, { method: c.req.method, id: c.params.id }), corsHeaders(c.req));
|
|
1578
1606
|
}
|
|
1607
|
+
function userDocumentPorts(env) {
|
|
1608
|
+
return { store: cfStore(env.DB), blobs: cfBlobs(env.USER_DOCS), lane: cfVectorIndex(env.USER_DOCS_INDEX), model: cfModelRunner(env.AI) };
|
|
1609
|
+
}
|
|
1610
|
+
async function userDocumentsRoute(c) {
|
|
1611
|
+
const who = await opIdentity(c, "Sign in to manage your documents");
|
|
1612
|
+
if (who instanceof Response) return withCors(who, corsHeaders(c.req));
|
|
1613
|
+
if (c.req.method === "GET") {
|
|
1614
|
+
const out = await listUserDocuments(userDocumentPorts(c.env).store, who.sub);
|
|
1615
|
+
return withCors(json({ ...out, quota: { used: out.documents.length, limit: USER_DOC_LIMIT } }), corsHeaders(c.req));
|
|
1616
|
+
}
|
|
1617
|
+
if (c.req.method === "POST") {
|
|
1618
|
+
const refused = opWriteRefused(c, who);
|
|
1619
|
+
if (refused) return withCors(refused, corsHeaders(c.req));
|
|
1620
|
+
const form = await c.req.formData().catch(() => null);
|
|
1621
|
+
const file = form?.get("file");
|
|
1622
|
+
if (!file || typeof file !== "object" || !("arrayBuffer" in file) || !("size" in file)) {
|
|
1623
|
+
return err(400, "invalid_input", 'Upload a file in the multipart "file" field.');
|
|
1624
|
+
}
|
|
1625
|
+
const blob = file;
|
|
1626
|
+
const out = await createImport(userDocumentPorts(c.env), c.ctx.waitUntil.bind(c.ctx), who.sub, blob);
|
|
1627
|
+
if ("error" in out) return withCors(out.error, corsHeaders(c.req));
|
|
1628
|
+
return withCors(json({ document: out.document }, 202), corsHeaders(c.req));
|
|
1629
|
+
}
|
|
1630
|
+
return err(405, "method_not_allowed", `The path is served, but not with ${c.req.method}`);
|
|
1631
|
+
}
|
|
1632
|
+
async function userDocumentItemRoute(c) {
|
|
1633
|
+
const who = await opIdentity(c, "Sign in to manage your documents");
|
|
1634
|
+
if (who instanceof Response) return withCors(who, corsHeaders(c.req));
|
|
1635
|
+
if (c.req.method === "GET") {
|
|
1636
|
+
const row = await getUserDocument(userDocumentPorts(c.env).store, who.sub, c.params.id);
|
|
1637
|
+
if (!row) return err(404, "not_found", "No such document for this member");
|
|
1638
|
+
return withCors(json({ document: row }), corsHeaders(c.req));
|
|
1639
|
+
}
|
|
1640
|
+
const refused = opWriteRefused(c, who);
|
|
1641
|
+
if (refused) return withCors(refused, corsHeaders(c.req));
|
|
1642
|
+
const gone = await deleteUserDocument(userDocumentPorts(c.env), who.sub, c.params.id);
|
|
1643
|
+
if (!gone) return err(404, "not_found", "No such document for this member");
|
|
1644
|
+
return withCors(json({ ok: true }), corsHeaders(c.req));
|
|
1645
|
+
}
|
|
1579
1646
|
async function projectsRoute(c) {
|
|
1580
1647
|
const who = await opIdentity(c, "Sign in to use projects");
|
|
1581
1648
|
if (who instanceof Response) return withCors(who, corsHeaders(c.req));
|
|
@@ -1974,6 +2041,10 @@ var OPENAPI_HANDLERS = {
|
|
|
1974
2041
|
getAttachment: attachmentsGetRoute,
|
|
1975
2042
|
deleteAttachment: attachmentsDeleteRoute,
|
|
1976
2043
|
listMemories: memoriesRoute,
|
|
2044
|
+
listUserDocuments: userDocumentsRoute,
|
|
2045
|
+
createUserDocument: userDocumentsRoute,
|
|
2046
|
+
getUserDocument: userDocumentItemRoute,
|
|
2047
|
+
deleteUserDocument: userDocumentItemRoute,
|
|
1977
2048
|
createMemory: memoriesRoute,
|
|
1978
2049
|
deleteMemory: memoriesRoute,
|
|
1979
2050
|
listProjects: projectsRoute,
|
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
requestSalt,
|
|
5
5
|
resolveRequestScope,
|
|
6
6
|
standardKeysFrom
|
|
7
|
-
} from "../../chunk-
|
|
8
|
-
import "../../chunk-
|
|
7
|
+
} from "../../chunk-5HCVX34C.js";
|
|
8
|
+
import "../../chunk-QYTCQIA6.js";
|
|
9
9
|
import "../../chunk-3FYJM7LH.js";
|
|
10
10
|
export {
|
|
11
11
|
entitlementScope,
|
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.184",
|
|
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",
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
-- The member's own documents (TODO.sota/20 v1): imported certificates
|
|
2
|
+
-- and scanned reports, privately indexed in the user lane, answered
|
|
3
|
+
-- beside the public corpus. 10 documents per member, 20 MB each, held
|
|
4
|
+
-- until the member deletes; deletion is immediate and total.
|
|
5
|
+
CREATE TABLE IF NOT EXISTS user_documents (
|
|
6
|
+
id TEXT PRIMARY KEY,
|
|
7
|
+
owner_sub TEXT NOT NULL,
|
|
8
|
+
name TEXT NOT NULL,
|
|
9
|
+
kind TEXT,
|
|
10
|
+
status TEXT NOT NULL,
|
|
11
|
+
bytes INTEGER NOT NULL,
|
|
12
|
+
r2_key TEXT,
|
|
13
|
+
fields TEXT,
|
|
14
|
+
error TEXT,
|
|
15
|
+
created_at TEXT NOT NULL,
|
|
16
|
+
updated_at TEXT NOT NULL
|
|
17
|
+
);
|
|
18
|
+
CREATE INDEX IF NOT EXISTS idx_user_documents_owner ON user_documents (owner_sub);
|
|
@@ -633,6 +633,78 @@ paths:
|
|
|
633
633
|
responses:
|
|
634
634
|
'200':
|
|
635
635
|
description: The note is deleted.
|
|
636
|
+
/api/user-documents:
|
|
637
|
+
get:
|
|
638
|
+
tags: [UserDocuments]
|
|
639
|
+
summary: List the member's imported documents
|
|
640
|
+
operationId: listUserDocuments
|
|
641
|
+
responses:
|
|
642
|
+
'200':
|
|
643
|
+
description: The documents with their import status and the quota.
|
|
644
|
+
post:
|
|
645
|
+
tags: [UserDocuments]
|
|
646
|
+
summary: Import a document (a certificate or a test report)
|
|
647
|
+
description: >-
|
|
648
|
+
Member-gated. Upload one PNG/JPEG/WebP image or a PDF (20 MB
|
|
649
|
+
max, 10 documents held per member until deleted). The import
|
|
650
|
+
runs asynchronously: the route answers 202 with the importing
|
|
651
|
+
row, the status endpoint (or a re-list) tells the rest. Images
|
|
652
|
+
ride the vision lane; a PDF's text layer is extracted (a
|
|
653
|
+
scanned PDF with no text layer is answered honestly with the
|
|
654
|
+
no_text_layer status). Retention: held until the member
|
|
655
|
+
deletes; deletion is immediate and total.
|
|
656
|
+
operationId: createUserDocument
|
|
657
|
+
requestBody:
|
|
658
|
+
required: true
|
|
659
|
+
content:
|
|
660
|
+
multipart/form-data:
|
|
661
|
+
schema:
|
|
662
|
+
type: object
|
|
663
|
+
required: [file]
|
|
664
|
+
properties:
|
|
665
|
+
file:
|
|
666
|
+
type: string
|
|
667
|
+
format: binary
|
|
668
|
+
responses:
|
|
669
|
+
'202':
|
|
670
|
+
description: The import is running; the row carries its status.
|
|
671
|
+
'413':
|
|
672
|
+
description: The document exceeds the 20 MB limit.
|
|
673
|
+
'415':
|
|
674
|
+
description: Unsupported media type.
|
|
675
|
+
'403':
|
|
676
|
+
description: The member holds the maximum of 10 documents.
|
|
677
|
+
/api/user-documents/{id}:
|
|
678
|
+
get:
|
|
679
|
+
tags: [UserDocuments]
|
|
680
|
+
summary: One imported document's status and extracted fields
|
|
681
|
+
operationId: getUserDocument
|
|
682
|
+
parameters:
|
|
683
|
+
- name: id
|
|
684
|
+
in: path
|
|
685
|
+
required: true
|
|
686
|
+
schema: { type: string }
|
|
687
|
+
responses:
|
|
688
|
+
'200':
|
|
689
|
+
description: The document row.
|
|
690
|
+
'404':
|
|
691
|
+
description: No such document for this member.
|
|
692
|
+
delete:
|
|
693
|
+
tags: [UserDocuments]
|
|
694
|
+
summary: Delete an imported document
|
|
695
|
+
description: Immediate and total — the stored file, the private-lane vectors and the row go together.
|
|
696
|
+
operationId: deleteUserDocument
|
|
697
|
+
parameters:
|
|
698
|
+
- name: id
|
|
699
|
+
in: path
|
|
700
|
+
required: true
|
|
701
|
+
schema: { type: string }
|
|
702
|
+
responses:
|
|
703
|
+
'200':
|
|
704
|
+
description: The document is deleted.
|
|
705
|
+
'404':
|
|
706
|
+
description: No such document for this member.
|
|
707
|
+
|
|
636
708
|
/api/projects:
|
|
637
709
|
get:
|
|
638
710
|
tags: [Projects]
|
|
@@ -262,3 +262,19 @@ CREATE INDEX IF NOT EXISTS idx_attachments_sub ON attachments (sub);
|
|
|
262
262
|
|
|
263
263
|
-- Tier-2 image reuse: the user message's stored attachment
|
|
264
264
|
ALTER TABLE messages ADD COLUMN attachment_id TEXT;
|
|
265
|
+
|
|
266
|
+
-- The member's own documents (TODO.sota/20 v1): the import lane.
|
|
267
|
+
CREATE TABLE IF NOT EXISTS user_documents (
|
|
268
|
+
id TEXT PRIMARY KEY,
|
|
269
|
+
owner_sub TEXT NOT NULL,
|
|
270
|
+
name TEXT NOT NULL,
|
|
271
|
+
kind TEXT,
|
|
272
|
+
status TEXT NOT NULL,
|
|
273
|
+
bytes INTEGER NOT NULL,
|
|
274
|
+
r2_key TEXT,
|
|
275
|
+
fields TEXT,
|
|
276
|
+
error TEXT,
|
|
277
|
+
created_at TEXT NOT NULL,
|
|
278
|
+
updated_at TEXT NOT NULL
|
|
279
|
+
);
|
|
280
|
+
CREATE INDEX IF NOT EXISTS idx_user_documents_owner ON user_documents (owner_sub);
|
|
@@ -47,6 +47,8 @@ import { json, err, corsHeaders, readJson, validateQuery, type ApiKey } from "./
|
|
|
47
47
|
import { chargeTokens, checkQuota, clientIp, creditBudget, creditEstimate, estimateTokens, telemetry, tokenBudget, usageTotal } from "./quota";
|
|
48
48
|
import { graphExpand, editionNote } from "./graph";
|
|
49
49
|
import { registerNote, searchRegister, certificateLinks, registerAggregateIntent, registerAggregate, aggregateNote, aggregateBlock, queryFamily, registerBypassesCache } from "./certificates";
|
|
50
|
+
import { queryUserLane } from "./userDocuments";
|
|
51
|
+
import { cfModelRunner, cfVectorIndex } from "./ports/cloudflare/adapters";
|
|
50
52
|
import { TOOL_DECLARATION, parseToolCall, runTool, toolNote } from "./tools";
|
|
51
53
|
import { operationsLane } from "./operations.ts";
|
|
52
54
|
import { extractNameplate, nameplateRegisterQuery } from "./nameplate.ts";
|
|
@@ -518,6 +520,13 @@ async function handleAsk(
|
|
|
518
520
|
const federate = (member || keyLicensed) && service && isoOn
|
|
519
521
|
? (q2: string) => retrieveInternal(service, fedAuth, q2)
|
|
520
522
|
: undefined;
|
|
523
|
+
// The member's OWN documents federate beside the corpus (TODO.sota/20
|
|
524
|
+
// slice 4): their lane, filtered by their sub inside the callback —
|
|
525
|
+
// no unfiltered path exists. The lane hits carry the member's
|
|
526
|
+
// citations ("Member document — <name>").
|
|
527
|
+
const userDocs = member && env.USER_DOCS_INDEX
|
|
528
|
+
? (q2: string) => queryUserLane(cfModelRunner(env.AI), cfVectorIndex(env.USER_DOCS_INDEX), member.sub, q2, THRESHOLDS.userLaneK)
|
|
529
|
+
: undefined;
|
|
521
530
|
|
|
522
531
|
const ns = tier === "key" ? `k:${key!.id}` : member ? `m:${member.sub}` : "anon";
|
|
523
532
|
const model = member ? MODELS.member : MODELS.anon;
|
|
@@ -1380,7 +1389,7 @@ let convEntities: Array<{ entity: string; kind: string }> = [];
|
|
|
1380
1389
|
// top-N before a post-hoc seal ever sees one. A document named IN THE
|
|
1381
1390
|
// QUESTION keeps the soft steer by design (the widen covers sparse
|
|
1382
1391
|
// publications there).
|
|
1383
|
-
retrieved = await retrieve(env, q.query, { prev, understanding, federate, warmEmbed, graphDocNumbers,
|
|
1392
|
+
retrieved = await retrieve(env, q.query, { prev, understanding, federate, userDocs, warmEmbed, graphDocNumbers,
|
|
1384
1393
|
sealScope: declaredScoped ? docScope : null, optimisticHits, optimisticVec,
|
|
1385
1394
|
datasetScope: narrowed ? corpora : null, standardKeys, lexicalBoost, licensedDocNumbers,
|
|
1386
1395
|
...(routeSubset ? { stageSubset: routeSubset } : {}) });
|
|
@@ -1418,7 +1427,7 @@ let convEntities: Array<{ entity: string; kind: string }> = [];
|
|
|
1418
1427
|
if (grade === "weak" && understanding?.docidentifier) {
|
|
1419
1428
|
const broaden = `${understanding.standalone_query || q.query} ${understanding.docidentifier}`.trim();
|
|
1420
1429
|
const tc = Date.now();
|
|
1421
|
-
const second = await retrieve(env, q.query, { prev, understanding, queryOverride: broaden, federate, datasetScope: narrowed ? corpora : null, standardKeys, sealScope: declaredScoped ? docScope : null, lexicalBoost, ...(routeSubset ? { stageSubset: routeSubset } : {}) });
|
|
1430
|
+
const second = await retrieve(env, q.query, { prev, understanding, queryOverride: broaden, federate, userDocs, datasetScope: narrowed ? corpora : null, standardKeys, sealScope: declaredScoped ? docScope : null, lexicalBoost, ...(routeSubset ? { stageSubset: routeSubset } : {}) });
|
|
1422
1431
|
const grade2 = await gradeRetrieval(env.AI, roleModel(env, "grader"), q.query, second.hits.map((h: Hit) => h.text));
|
|
1423
1432
|
stageTiming.corrective = Date.now() - tc;
|
|
1424
1433
|
if (grade2 === "good") retrieved = second; // corrective retry must be strictly better
|
|
@@ -121,6 +121,9 @@ export const THRESHOLDS = {
|
|
|
121
121
|
/** Federated-ISO discount — the public corpus answers by default;
|
|
122
122
|
* internal ISO passages compete but don't preempt. */
|
|
123
123
|
federateDiscount: 0.95,
|
|
124
|
+
/** the member's own imported documents: how many lane hits may join
|
|
125
|
+
* the pool (TODO.sota/20 slice 4) — their content, their question */
|
|
126
|
+
userLaneK: 3,
|
|
124
127
|
/** Standard-reference nudge (L5): when the question asks about an
|
|
125
128
|
* invoked ISO/IEC standard, chunks that CARRY such a citation (their
|
|
126
129
|
* text contains an ISO/IEC identifier) get a spread-scaled boost —
|