llmtxt 2026.4.0
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/CHANGELOG.md +66 -0
- package/LICENSE +21 -0
- package/README.md +64 -0
- package/dist/cache.d.ts +155 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +193 -0
- package/dist/cache.js.map +1 -0
- package/dist/client.d.ts +80 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +143 -0
- package/dist/client.js.map +1 -0
- package/dist/compression.d.ts +9 -0
- package/dist/compression.d.ts.map +1 -0
- package/dist/compression.js +8 -0
- package/dist/compression.js.map +1 -0
- package/dist/disclosure.d.ts +215 -0
- package/dist/disclosure.d.ts.map +1 -0
- package/dist/disclosure.js +532 -0
- package/dist/disclosure.js.map +1 -0
- package/dist/graph.d.ts +76 -0
- package/dist/graph.d.ts.map +1 -0
- package/dist/graph.js +137 -0
- package/dist/graph.js.map +1 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/patch.d.ts +8 -0
- package/dist/patch.d.ts.map +1 -0
- package/dist/patch.js +8 -0
- package/dist/patch.js.map +1 -0
- package/dist/schemas.d.ts +290 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +154 -0
- package/dist/schemas.js.map +1 -0
- package/dist/sdk/attribution.d.ts +59 -0
- package/dist/sdk/attribution.d.ts.map +1 -0
- package/dist/sdk/attribution.js +99 -0
- package/dist/sdk/attribution.js.map +1 -0
- package/dist/sdk/consensus.d.ts +73 -0
- package/dist/sdk/consensus.d.ts.map +1 -0
- package/dist/sdk/consensus.js +110 -0
- package/dist/sdk/consensus.js.map +1 -0
- package/dist/sdk/document.d.ts +92 -0
- package/dist/sdk/document.d.ts.map +1 -0
- package/dist/sdk/document.js +182 -0
- package/dist/sdk/document.js.map +1 -0
- package/dist/sdk/index.d.ts +22 -0
- package/dist/sdk/index.d.ts.map +1 -0
- package/dist/sdk/index.js +15 -0
- package/dist/sdk/index.js.map +1 -0
- package/dist/sdk/lifecycle.d.ts +66 -0
- package/dist/sdk/lifecycle.d.ts.map +1 -0
- package/dist/sdk/lifecycle.js +80 -0
- package/dist/sdk/lifecycle.js.map +1 -0
- package/dist/sdk/retrieval.d.ts +64 -0
- package/dist/sdk/retrieval.d.ts.map +1 -0
- package/dist/sdk/retrieval.js +102 -0
- package/dist/sdk/retrieval.js.map +1 -0
- package/dist/sdk/storage-adapter.d.ts +53 -0
- package/dist/sdk/storage-adapter.d.ts.map +1 -0
- package/dist/sdk/storage-adapter.js +2 -0
- package/dist/sdk/storage-adapter.js.map +1 -0
- package/dist/sdk/storage.d.ts +86 -0
- package/dist/sdk/storage.d.ts.map +1 -0
- package/dist/sdk/storage.js +69 -0
- package/dist/sdk/storage.js.map +1 -0
- package/dist/sdk/versions.d.ts +107 -0
- package/dist/sdk/versions.d.ts.map +1 -0
- package/dist/sdk/versions.js +129 -0
- package/dist/sdk/versions.js.map +1 -0
- package/dist/signed-url.d.ts +90 -0
- package/dist/signed-url.d.ts.map +1 -0
- package/dist/signed-url.js +159 -0
- package/dist/signed-url.js.map +1 -0
- package/dist/similarity.d.ts +57 -0
- package/dist/similarity.d.ts.map +1 -0
- package/dist/similarity.js +134 -0
- package/dist/similarity.js.map +1 -0
- package/dist/snapshot.d.ts +54 -0
- package/dist/snapshot.d.ts.map +1 -0
- package/dist/snapshot.js +94 -0
- package/dist/snapshot.js.map +1 -0
- package/dist/types.d.ts +92 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/dist/validation.d.ts +146 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +285 -0
- package/dist/validation.js.map +1 -0
- package/dist/wasm.d.ts +28 -0
- package/dist/wasm.d.ts.map +1 -0
- package/dist/wasm.js +92 -0
- package/dist/wasm.js.map +1 -0
- package/package.json +98 -0
- package/wasm/LICENSE +21 -0
- package/wasm/README.md +63 -0
- package/wasm/llmtxt_core.d.ts +176 -0
- package/wasm/llmtxt_core.js +719 -0
- package/wasm/llmtxt_core_bg.wasm +0 -0
- package/wasm/llmtxt_core_bg.wasm.d.ts +37 -0
- package/wasm/package.json +25 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signed-url.js","sourceRoot":"","sources":["../src/signed-url.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,gBAAgB,IAAI,oBAAoB,EACxC,0BAA0B,IAAI,8BAA8B,EAC5D,mBAAmB,IAAI,uBAAuB,EAC9C,6BAA6B,IAAI,iCAAiC,EAClE,gBAAgB,IAAI,oBAAoB,EACxC,SAAS,IAAI,aAAa,GAC3B,MAAM,WAAW,CAAC;AAmCnB,mEAAmE;AAEnE;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAuB,EAAE,MAAc;IACtE,OAAO,oBAAoB,CACzB,MAAM,CAAC,IAAI,EACX,MAAM,CAAC,OAAO,EACd,MAAM,CAAC,cAAc,EACrB,MAAM,CAAC,SAAS,EAChB,MAAM,CACP,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,0BAA0B,CACxC,MAAuB,EACvB,MAAc,EACd,SAAiB;IAEjB,OAAO,8BAA8B,CACnC,MAAM,CAAC,IAAI,EACX,MAAM,CAAC,OAAO,EACd,MAAM,CAAC,cAAc,EACrB,MAAM,CAAC,SAAS,EAChB,MAAM,EACN,SAAS,CACV,CAAC;AACJ,CAAC;AAED,mEAAmE;AAEnE;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAuB,EAAE,MAAuB;IAChF,MAAM,eAAe,GAAG,MAAM,CAAC,eAAe,IAAI,EAAE,CAAC;IACrD,MAAM,SAAS,GAAG,0BAA0B,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACrF,MAAM,GAAG,GAAG,I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CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACzD,OAAO,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAC/B,CAAC;AAED,mEAAmE;AAEnE;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,SAAoC;IAC5D,IAAI,SAAS,IAAI,IAAI;QAAE,OAAO,KAAK,CAAC;IACpC,OAAO,aAAa,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lightweight content similarity using n-gram fingerprinting.
|
|
3
|
+
* No external dependencies — uses only string operations.
|
|
4
|
+
*
|
|
5
|
+
* Designed for agent use cases: find similar messages in a conversation
|
|
6
|
+
* without vector embeddings or external APIs.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Extract character-level n-grams from text.
|
|
10
|
+
* Normalizes whitespace and lowercases before extraction.
|
|
11
|
+
*/
|
|
12
|
+
export declare function extractNgrams(text: string, n?: number): Set<string>;
|
|
13
|
+
/**
|
|
14
|
+
* Extract word-level n-grams (shingles) from text.
|
|
15
|
+
* Better for longer content where word order matters.
|
|
16
|
+
*/
|
|
17
|
+
export declare function extractWordShingles(text: string, n?: number): Set<string>;
|
|
18
|
+
/**
|
|
19
|
+
* Jaccard similarity: |A ∩ B| / |A ∪ B|.
|
|
20
|
+
* Returns 0.0 (no overlap) to 1.0 (identical).
|
|
21
|
+
*/
|
|
22
|
+
export declare function jaccardSimilarity(a: Set<string>, b: Set<string>): number;
|
|
23
|
+
/**
|
|
24
|
+
* Compute similarity between two texts using character n-grams.
|
|
25
|
+
* Returns 0.0 to 1.0.
|
|
26
|
+
*/
|
|
27
|
+
export declare function textSimilarity(a: string, b: string, ngramSize?: number): number;
|
|
28
|
+
/**
|
|
29
|
+
* Compute similarity using word shingles.
|
|
30
|
+
* Better for comparing messages or documents where word choice matters more than character patterns.
|
|
31
|
+
*/
|
|
32
|
+
export declare function contentSimilarity(a: string, b: string, shingleSize?: number): number;
|
|
33
|
+
/**
|
|
34
|
+
* Generate a compact fingerprint for content using MinHash.
|
|
35
|
+
* The fingerprint is an array of hash values that can be compared
|
|
36
|
+
* for approximate similarity without storing the full n-gram set.
|
|
37
|
+
*
|
|
38
|
+
* Two fingerprints with many matching values indicate similar content.
|
|
39
|
+
*/
|
|
40
|
+
export declare function minHashFingerprint(text: string, numHashes?: number, ngramSize?: number): number[];
|
|
41
|
+
/**
|
|
42
|
+
* Estimate similarity between two MinHash fingerprints.
|
|
43
|
+
* Returns approximate Jaccard similarity (0.0 to 1.0).
|
|
44
|
+
*/
|
|
45
|
+
export declare function fingerprintSimilarity(a: number[], b: number[]): number;
|
|
46
|
+
/**
|
|
47
|
+
* Rank a list of texts by similarity to a query.
|
|
48
|
+
* Returns indices sorted by descending similarity, with scores.
|
|
49
|
+
*/
|
|
50
|
+
export declare function rankBySimilarity(query: string, candidates: string[], options?: {
|
|
51
|
+
method?: 'ngram' | 'shingle';
|
|
52
|
+
threshold?: number;
|
|
53
|
+
}): Array<{
|
|
54
|
+
index: number;
|
|
55
|
+
score: number;
|
|
56
|
+
}>;
|
|
57
|
+
//# sourceMappingURL=similarity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"similarity.d.ts","sourceRoot":"","sources":["../src/similarity.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,SAAI,GAAG,GAAG,CAAC,MAAM,CAAC,CAO9D;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,SAAI,GAAG,GAAG,CAAC,MAAM,CAAC,CAOpE;AAID;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,CAaxE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,SAAS,SAAI,GAAG,MAAM,CAE1E;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,WAAW,SAAI,GAAG,MAAM,CAE/E;AAID;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,SAAK,EAAE,SAAS,SAAI,GAAG,MAAM,EAAE,CAcxF;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAStE;AAID;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,EAAE,EACpB,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GACjE,KAAK,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAczC"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lightweight content similarity using n-gram fingerprinting.
|
|
3
|
+
* No external dependencies — uses only string operations.
|
|
4
|
+
*
|
|
5
|
+
* Designed for agent use cases: find similar messages in a conversation
|
|
6
|
+
* without vector embeddings or external APIs.
|
|
7
|
+
*/
|
|
8
|
+
// ── N-gram Generation ───────────────────────────────────────────
|
|
9
|
+
/**
|
|
10
|
+
* Extract character-level n-grams from text.
|
|
11
|
+
* Normalizes whitespace and lowercases before extraction.
|
|
12
|
+
*/
|
|
13
|
+
export function extractNgrams(text, n = 3) {
|
|
14
|
+
const normalized = text.toLowerCase().replace(/\s+/g, ' ').trim();
|
|
15
|
+
const grams = new Set();
|
|
16
|
+
for (let i = 0; i <= normalized.length - n; i++) {
|
|
17
|
+
grams.add(normalized.slice(i, i + n));
|
|
18
|
+
}
|
|
19
|
+
return grams;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Extract word-level n-grams (shingles) from text.
|
|
23
|
+
* Better for longer content where word order matters.
|
|
24
|
+
*/
|
|
25
|
+
export function extractWordShingles(text, n = 2) {
|
|
26
|
+
const words = text.toLowerCase().replace(/[^\w\s]/g, '').split(/\s+/).filter(Boolean);
|
|
27
|
+
const shingles = new Set();
|
|
28
|
+
for (let i = 0; i <= words.length - n; i++) {
|
|
29
|
+
shingles.add(words.slice(i, i + n).join(' '));
|
|
30
|
+
}
|
|
31
|
+
return shingles;
|
|
32
|
+
}
|
|
33
|
+
// ── Similarity Metrics ──────────────────────────────────────────
|
|
34
|
+
/**
|
|
35
|
+
* Jaccard similarity: |A ∩ B| / |A ∪ B|.
|
|
36
|
+
* Returns 0.0 (no overlap) to 1.0 (identical).
|
|
37
|
+
*/
|
|
38
|
+
export function jaccardSimilarity(a, b) {
|
|
39
|
+
if (a.size === 0 && b.size === 0)
|
|
40
|
+
return 1.0;
|
|
41
|
+
if (a.size === 0 || b.size === 0)
|
|
42
|
+
return 0.0;
|
|
43
|
+
let intersection = 0;
|
|
44
|
+
const smaller = a.size <= b.size ? a : b;
|
|
45
|
+
const larger = a.size <= b.size ? b : a;
|
|
46
|
+
for (const item of smaller) {
|
|
47
|
+
if (larger.has(item))
|
|
48
|
+
intersection++;
|
|
49
|
+
}
|
|
50
|
+
const union = a.size + b.size - intersection;
|
|
51
|
+
return union === 0 ? 0 : intersection / union;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Compute similarity between two texts using character n-grams.
|
|
55
|
+
* Returns 0.0 to 1.0.
|
|
56
|
+
*/
|
|
57
|
+
export function textSimilarity(a, b, ngramSize = 3) {
|
|
58
|
+
return jaccardSimilarity(extractNgrams(a, ngramSize), extractNgrams(b, ngramSize));
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Compute similarity using word shingles.
|
|
62
|
+
* Better for comparing messages or documents where word choice matters more than character patterns.
|
|
63
|
+
*/
|
|
64
|
+
export function contentSimilarity(a, b, shingleSize = 2) {
|
|
65
|
+
return jaccardSimilarity(extractWordShingles(a, shingleSize), extractWordShingles(b, shingleSize));
|
|
66
|
+
}
|
|
67
|
+
// ── Fingerprinting ──────────────────────────────────────────────
|
|
68
|
+
/**
|
|
69
|
+
* Generate a compact fingerprint for content using MinHash.
|
|
70
|
+
* The fingerprint is an array of hash values that can be compared
|
|
71
|
+
* for approximate similarity without storing the full n-gram set.
|
|
72
|
+
*
|
|
73
|
+
* Two fingerprints with many matching values indicate similar content.
|
|
74
|
+
*/
|
|
75
|
+
export function minHashFingerprint(text, numHashes = 64, ngramSize = 3) {
|
|
76
|
+
const ngrams = extractNgrams(text, ngramSize);
|
|
77
|
+
const fingerprint = new Array(numHashes).fill(Infinity);
|
|
78
|
+
for (const gram of ngrams) {
|
|
79
|
+
for (let i = 0; i < numHashes; i++) {
|
|
80
|
+
const hash = simpleHash(gram, i);
|
|
81
|
+
if (hash < fingerprint[i]) {
|
|
82
|
+
fingerprint[i] = hash;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return fingerprint;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Estimate similarity between two MinHash fingerprints.
|
|
90
|
+
* Returns approximate Jaccard similarity (0.0 to 1.0).
|
|
91
|
+
*/
|
|
92
|
+
export function fingerprintSimilarity(a, b) {
|
|
93
|
+
if (a.length !== b.length)
|
|
94
|
+
return 0;
|
|
95
|
+
if (a.length === 0)
|
|
96
|
+
return 0;
|
|
97
|
+
let matches = 0;
|
|
98
|
+
for (let i = 0; i < a.length; i++) {
|
|
99
|
+
if (a[i] === b[i])
|
|
100
|
+
matches++;
|
|
101
|
+
}
|
|
102
|
+
return matches / a.length;
|
|
103
|
+
}
|
|
104
|
+
// ── Ranking ─────────────────────────────────────────────────────
|
|
105
|
+
/**
|
|
106
|
+
* Rank a list of texts by similarity to a query.
|
|
107
|
+
* Returns indices sorted by descending similarity, with scores.
|
|
108
|
+
*/
|
|
109
|
+
export function rankBySimilarity(query, candidates, options = {}) {
|
|
110
|
+
const { method = 'shingle', threshold = 0.0 } = options;
|
|
111
|
+
const similarityFn = method === 'ngram' ? textSimilarity : contentSimilarity;
|
|
112
|
+
const results = [];
|
|
113
|
+
for (let i = 0; i < candidates.length; i++) {
|
|
114
|
+
const score = similarityFn(query, candidates[i]);
|
|
115
|
+
if (score > threshold) {
|
|
116
|
+
results.push({ index: i, score });
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
results.sort((a, b) => b.score - a.score);
|
|
120
|
+
return results;
|
|
121
|
+
}
|
|
122
|
+
// ── Internal ────────────────────────────────────────────────────
|
|
123
|
+
/**
|
|
124
|
+
* Simple hash function for MinHash. Uses FNV-1a variant with seed mixing.
|
|
125
|
+
*/
|
|
126
|
+
function simpleHash(str, seed) {
|
|
127
|
+
let hash = 2166136261 ^ seed;
|
|
128
|
+
for (let i = 0; i < str.length; i++) {
|
|
129
|
+
hash ^= str.charCodeAt(i);
|
|
130
|
+
hash = Math.imul(hash, 16777619);
|
|
131
|
+
}
|
|
132
|
+
return hash >>> 0;
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=similarity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"similarity.js","sourceRoot":"","sources":["../src/similarity.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,mEAAmE;AAEnE;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,CAAC,GAAG,CAAC;IAC/C,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IAClE,MAAM,KAAK,GAAG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IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3C,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;QACjD,IAAI,KAAK,GAAG,SAAS,EAAE,CAAC;YACtB,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;IAED,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;IAC1C,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,mEAAmE;AAEnE;;GAEG;AACH,SAAS,UAAU,CAAC,GAAW,EAAE,IAAY;IAC3C,IAAI,IAAI,GAAG,UAAU,GAAG,IAAI,CAAC;IAC7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,IAAI,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAC1B,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,IAAI,KAAK,CAAC,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session Snapshot Compression Service.
|
|
3
|
+
* Compresses/decompresses CLEO session.serialize() JSON snapshots
|
|
4
|
+
* for efficient storage and cross-session handoff.
|
|
5
|
+
*
|
|
6
|
+
* Phase 3: Session continuity infrastructure.
|
|
7
|
+
*/
|
|
8
|
+
export interface SnapshotMeta {
|
|
9
|
+
sessionId: string;
|
|
10
|
+
agentId: string;
|
|
11
|
+
createdAt: string;
|
|
12
|
+
originalSize: number;
|
|
13
|
+
compressedSize: number;
|
|
14
|
+
compressionRatio: number;
|
|
15
|
+
tokens: number;
|
|
16
|
+
contentHash: string;
|
|
17
|
+
}
|
|
18
|
+
export interface CompressedSnapshot {
|
|
19
|
+
meta: SnapshotMeta;
|
|
20
|
+
data: Buffer;
|
|
21
|
+
}
|
|
22
|
+
export interface SnapshotOptions {
|
|
23
|
+
/** Include full decision log (default: true) */
|
|
24
|
+
includeDecisions?: boolean;
|
|
25
|
+
/** Include brain observations (default: true) */
|
|
26
|
+
includeObservations?: boolean;
|
|
27
|
+
/** Max content size before compression in bytes (default: 5MB) */
|
|
28
|
+
maxSize?: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Compress a session snapshot JSON string.
|
|
32
|
+
* Returns compressed data + metadata for storage/retrieval.
|
|
33
|
+
*/
|
|
34
|
+
export declare function compressSnapshot(jsonStr: string, sessionId: string, agentId: string): Promise<CompressedSnapshot>;
|
|
35
|
+
/**
|
|
36
|
+
* Decompress a snapshot back to JSON string.
|
|
37
|
+
* Verifies integrity via content hash if provided.
|
|
38
|
+
*/
|
|
39
|
+
export declare function decompressSnapshot(data: Buffer, expectedHash?: string): Promise<string>;
|
|
40
|
+
/**
|
|
41
|
+
* Compress a session snapshot object directly.
|
|
42
|
+
* Serializes to JSON, then compresses.
|
|
43
|
+
*/
|
|
44
|
+
export declare function compressSessionData(sessionData: Record<string, unknown>, sessionId: string, agentId: string, options?: SnapshotOptions): Promise<CompressedSnapshot>;
|
|
45
|
+
/**
|
|
46
|
+
* Decompress and parse a snapshot back to an object.
|
|
47
|
+
*/
|
|
48
|
+
export declare function decompressSessionData<T = Record<string, unknown>>(data: Buffer, expectedHash?: string): Promise<T>;
|
|
49
|
+
/**
|
|
50
|
+
* Generate a human-readable summary of a snapshot for handoff messages.
|
|
51
|
+
* Useful for agents posting session summaries to ClawMsgr.
|
|
52
|
+
*/
|
|
53
|
+
export declare function snapshotSummary(meta: SnapshotMeta): string;
|
|
54
|
+
//# sourceMappingURL=snapshot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../src/snapshot.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,eAAe;IAC9B,gDAAgD;IAChD,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,iDAAiD;IACjD,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,kEAAkE;IAClE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAID;;;GAGG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,kBAAkB,CAAC,CAyB7B;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,MAAM,EACZ,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,MAAM,CAAC,CAcjB;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACpC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,kBAAkB,CAAC,CAmB7B;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrE,IAAI,EAAE,MAAM,EACZ,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,CAAC,CAAC,CAGZ;AAID;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,CAS1D"}
|
package/dist/snapshot.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session Snapshot Compression Service.
|
|
3
|
+
* Compresses/decompresses CLEO session.serialize() JSON snapshots
|
|
4
|
+
* for efficient storage and cross-session handoff.
|
|
5
|
+
*
|
|
6
|
+
* Phase 3: Session continuity infrastructure.
|
|
7
|
+
*/
|
|
8
|
+
import { compress, decompress } from './wasm.js';
|
|
9
|
+
// ── Compression ─────────────────────────────────────────────────
|
|
10
|
+
/**
|
|
11
|
+
* Compress a session snapshot JSON string.
|
|
12
|
+
* Returns compressed data + metadata for storage/retrieval.
|
|
13
|
+
*/
|
|
14
|
+
export async function compressSnapshot(jsonStr, sessionId, agentId) {
|
|
15
|
+
const originalSize = Buffer.byteLength(jsonStr, 'utf-8');
|
|
16
|
+
const tokens = Math.ceil(originalSize / 4);
|
|
17
|
+
const data = await compress(jsonStr);
|
|
18
|
+
const compressedSize = data.length;
|
|
19
|
+
const compressionRatio = compressedSize > 0 ? originalSize / compressedSize : 1;
|
|
20
|
+
// Hash for integrity verification
|
|
21
|
+
const { createHash } = await import('node:crypto');
|
|
22
|
+
const contentHash = createHash('sha256').update(jsonStr).digest('hex');
|
|
23
|
+
return {
|
|
24
|
+
meta: {
|
|
25
|
+
sessionId,
|
|
26
|
+
agentId,
|
|
27
|
+
createdAt: new Date().toISOString(),
|
|
28
|
+
originalSize,
|
|
29
|
+
compressedSize,
|
|
30
|
+
compressionRatio,
|
|
31
|
+
tokens,
|
|
32
|
+
contentHash,
|
|
33
|
+
},
|
|
34
|
+
data,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Decompress a snapshot back to JSON string.
|
|
39
|
+
* Verifies integrity via content hash if provided.
|
|
40
|
+
*/
|
|
41
|
+
export async function decompressSnapshot(data, expectedHash) {
|
|
42
|
+
const jsonStr = await decompress(data);
|
|
43
|
+
if (expectedHash) {
|
|
44
|
+
const { createHash } = await import('node:crypto');
|
|
45
|
+
const actualHash = createHash('sha256').update(jsonStr).digest('hex');
|
|
46
|
+
if (actualHash !== expectedHash) {
|
|
47
|
+
throw new Error(`Snapshot integrity check failed: expected ${expectedHash.slice(0, 16)}..., got ${actualHash.slice(0, 16)}...`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return jsonStr;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Compress a session snapshot object directly.
|
|
54
|
+
* Serializes to JSON, then compresses.
|
|
55
|
+
*/
|
|
56
|
+
export async function compressSessionData(sessionData, sessionId, agentId, options = {}) {
|
|
57
|
+
const { includeDecisions = true, includeObservations = true, maxSize = 5 * 1024 * 1024 } = options;
|
|
58
|
+
// Optionally strip large fields before compression
|
|
59
|
+
const filtered = { ...sessionData };
|
|
60
|
+
if (!includeDecisions && 'decisions' in filtered) {
|
|
61
|
+
delete filtered.decisions;
|
|
62
|
+
}
|
|
63
|
+
if (!includeObservations && 'observations' in filtered) {
|
|
64
|
+
delete filtered.observations;
|
|
65
|
+
}
|
|
66
|
+
const jsonStr = JSON.stringify(filtered);
|
|
67
|
+
if (Buffer.byteLength(jsonStr, 'utf-8') > maxSize) {
|
|
68
|
+
throw new Error(`Snapshot exceeds max size: ${Buffer.byteLength(jsonStr, 'utf-8')} > ${maxSize}`);
|
|
69
|
+
}
|
|
70
|
+
return compressSnapshot(jsonStr, sessionId, agentId);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Decompress and parse a snapshot back to an object.
|
|
74
|
+
*/
|
|
75
|
+
export async function decompressSessionData(data, expectedHash) {
|
|
76
|
+
const jsonStr = await decompressSnapshot(data, expectedHash);
|
|
77
|
+
return JSON.parse(jsonStr);
|
|
78
|
+
}
|
|
79
|
+
// ── Summary ─────────────────────────────────────────────────────
|
|
80
|
+
/**
|
|
81
|
+
* Generate a human-readable summary of a snapshot for handoff messages.
|
|
82
|
+
* Useful for agents posting session summaries to ClawMsgr.
|
|
83
|
+
*/
|
|
84
|
+
export function snapshotSummary(meta) {
|
|
85
|
+
return [
|
|
86
|
+
`Session: ${meta.sessionId}`,
|
|
87
|
+
`Agent: ${meta.agentId}`,
|
|
88
|
+
`Size: ${meta.originalSize} → ${meta.compressedSize} bytes (${meta.compressionRatio.toFixed(1)}x)`,
|
|
89
|
+
`Tokens: ~${meta.tokens}`,
|
|
90
|
+
`Hash: ${meta.contentHash.slice(0, 16)}...`,
|
|
91
|
+
`Created: ${meta.createdAt}`,
|
|
92
|
+
].join('\n');
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=snapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.js","sourceRoot":"","sources":["../src/snapshot.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AA6BjD,mEAAmE;AAEnE;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAAe,EACf,SAAiB,EACjB,OAAe;IAEf,MAAM,YAAY,GAAG,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACzD,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;IAE3C,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,CAAC;IACrC,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC;IACnC,MAAM,gBAAgB,GAAG,cAAc,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,C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AI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK;QAC3C,YAAY,IAAI,CAAC,SAAS,EAAE;KAC7B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types for llmtxt content workflows.
|
|
3
|
+
*
|
|
4
|
+
* These interfaces define the data shapes used across the llmtxt ecosystem.
|
|
5
|
+
* They are intentionally decoupled from any ORM or database layer.
|
|
6
|
+
*/
|
|
7
|
+
/** Supported content formats. */
|
|
8
|
+
export type ContentFormat = 'json' | 'text' | 'markdown';
|
|
9
|
+
/** Lifecycle state for collaborative documents. */
|
|
10
|
+
export type DocumentMode = 'draft' | 'review' | 'locked' | 'archived';
|
|
11
|
+
/** Metadata for a stored document. */
|
|
12
|
+
export interface DocumentMeta {
|
|
13
|
+
id: string;
|
|
14
|
+
slug: string;
|
|
15
|
+
format: ContentFormat;
|
|
16
|
+
contentHash: string;
|
|
17
|
+
originalSize: number;
|
|
18
|
+
compressedSize: number;
|
|
19
|
+
tokenCount: number;
|
|
20
|
+
createdAt: number;
|
|
21
|
+
expiresAt: number | null;
|
|
22
|
+
accessCount: number;
|
|
23
|
+
lastAccessedAt: number | null;
|
|
24
|
+
/** Lifecycle state (collaborative documents). */
|
|
25
|
+
mode?: DocumentMode;
|
|
26
|
+
/** Total number of versions. */
|
|
27
|
+
versionCount?: number;
|
|
28
|
+
/** Current version number. */
|
|
29
|
+
currentVersion?: number;
|
|
30
|
+
/** Object storage key when content lives in S3 instead of inline. */
|
|
31
|
+
storageKey?: string;
|
|
32
|
+
}
|
|
33
|
+
/** Metadata for a single document version. */
|
|
34
|
+
export interface VersionMeta {
|
|
35
|
+
id: string;
|
|
36
|
+
documentId: string;
|
|
37
|
+
versionNumber: number;
|
|
38
|
+
contentHash: string;
|
|
39
|
+
tokenCount: number;
|
|
40
|
+
createdAt: number;
|
|
41
|
+
createdBy?: string;
|
|
42
|
+
changelog?: string;
|
|
43
|
+
}
|
|
44
|
+
/** Summary of a version for listing (no content). */
|
|
45
|
+
export interface VersionSummary {
|
|
46
|
+
versionNumber: number;
|
|
47
|
+
tokenCount: number;
|
|
48
|
+
createdAt: number;
|
|
49
|
+
createdBy?: string;
|
|
50
|
+
changelog?: string;
|
|
51
|
+
}
|
|
52
|
+
/** Result of comparing two versions. */
|
|
53
|
+
export interface VersionDiff {
|
|
54
|
+
documentId: string;
|
|
55
|
+
fromVersion: number;
|
|
56
|
+
toVersion: number;
|
|
57
|
+
addedTokens: number;
|
|
58
|
+
removedTokens: number;
|
|
59
|
+
addedLines: number;
|
|
60
|
+
removedLines: number;
|
|
61
|
+
}
|
|
62
|
+
/** Reference to an llmtxt document shared in a message. */
|
|
63
|
+
export interface LlmtxtRef {
|
|
64
|
+
slug: string;
|
|
65
|
+
url: string;
|
|
66
|
+
format: ContentFormat;
|
|
67
|
+
tokenCount: number;
|
|
68
|
+
preview: string;
|
|
69
|
+
}
|
|
70
|
+
/** Options for creating an attachment via the bridge. */
|
|
71
|
+
export interface AttachmentOptions {
|
|
72
|
+
content: string;
|
|
73
|
+
format?: ContentFormat;
|
|
74
|
+
conversationId: string;
|
|
75
|
+
fromAgentId: string;
|
|
76
|
+
expiresInMs?: number;
|
|
77
|
+
}
|
|
78
|
+
/** Attachment fetch mode supported by the bridge/API layer. */
|
|
79
|
+
export type AttachmentAccessMode = 'signed_url' | 'conversation' | 'owner' | 'public';
|
|
80
|
+
/** Share state persisted by the API layer for an attachment. */
|
|
81
|
+
export type AttachmentSharingMode = 'signed_url' | 'conversation' | 'public';
|
|
82
|
+
/** Options for re-sharing an existing attachment. */
|
|
83
|
+
export interface AttachmentReshareOptions {
|
|
84
|
+
expiresIn?: number;
|
|
85
|
+
mode?: AttachmentSharingMode;
|
|
86
|
+
}
|
|
87
|
+
/** Options for appending a version to an existing attachment slug. */
|
|
88
|
+
export interface AttachmentVersionOptions {
|
|
89
|
+
baseVersion?: number;
|
|
90
|
+
changelog?: string;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,iCAAiC;AACjC,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,CAAC;AAEzD,mDAAmD;AACnD,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,UAAU,CAAC;AAEtE,sCAAsC;AACtC,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,aAAa,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,iDAAiD;IACjD,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,gCAAgC;IAChC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8BAA8B;IAC9B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,qEAAqE;IACrE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAID,8CAA8C;AAC9C,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CA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;AAED,sEAAsE;AACtE,MAAM,WAAW,wBAAwB;IACvC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Outcome of a content validation operation.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Returned by every validation function in this module. When `success` is
|
|
6
|
+
* `true`, `data` holds the parsed value and `format` indicates the detected
|
|
7
|
+
* content type. When `success` is `false`, `errors` describes what went wrong.
|
|
8
|
+
*
|
|
9
|
+
* @typeParam T - The expected shape of the validated data (defaults to `unknown`).
|
|
10
|
+
*/
|
|
11
|
+
export interface ValidationResult<T = unknown> {
|
|
12
|
+
/** Whether the validation passed without errors. */
|
|
13
|
+
success: boolean;
|
|
14
|
+
/** The parsed/validated data, present only when `success` is `true`. */
|
|
15
|
+
data?: T;
|
|
16
|
+
/** List of validation errors, present only when `success` is `false`. */
|
|
17
|
+
errors?: ValidationError[];
|
|
18
|
+
/** The detected or requested content format, when determinable. */
|
|
19
|
+
format?: 'json' | 'text' | 'markdown';
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A single validation error with location, message, and error code.
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* Modeled after Zod issue objects but flattened for easy serialization.
|
|
26
|
+
* The `path` uses dot-delimited notation (empty string for the root value).
|
|
27
|
+
*/
|
|
28
|
+
export interface ValidationError {
|
|
29
|
+
/** Dot-delimited path to the field that failed validation (empty string for root). */
|
|
30
|
+
path: string;
|
|
31
|
+
/** Human-readable description of the validation failure. */
|
|
32
|
+
message: string;
|
|
33
|
+
/** Machine-readable error code (e.g. `"invalid_json"`, `"unknown_schema"`). */
|
|
34
|
+
code: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Validate content as JSON, optionally against a predefined schema.
|
|
38
|
+
*
|
|
39
|
+
* @remarks
|
|
40
|
+
* When `content` is a string it is first parsed with `JSON.parse`. The
|
|
41
|
+
* parsed value is then checked against the generic JSON schema and,
|
|
42
|
+
* when a `schemaName` is provided, against the matching predefined
|
|
43
|
+
* schema from the registry.
|
|
44
|
+
*
|
|
45
|
+
* @param content - The raw content to validate (string or pre-parsed value).
|
|
46
|
+
* @param schemaName - Optional name of a predefined schema to enforce.
|
|
47
|
+
* @returns A {@link ValidationResult} indicating success or listing errors.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* const result = validateJson('{"key": "value"}');
|
|
52
|
+
* if (result.success) console.log(result.data);
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare function validateJson(content: unknown, schemaName?: string): ValidationResult;
|
|
56
|
+
/**
|
|
57
|
+
* Validate content as plain text or markdown.
|
|
58
|
+
*
|
|
59
|
+
* @remarks
|
|
60
|
+
* Checks that the value is a string using the text format schema.
|
|
61
|
+
*
|
|
62
|
+
* @param content - The value to validate as text.
|
|
63
|
+
* @returns A {@link ValidationResult} with `format` set to `"text"` on success.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* const result = validateText('# Hello');
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare function validateText(content: unknown): ValidationResult<string>;
|
|
71
|
+
/**
|
|
72
|
+
* Auto-detect whether a string is JSON, markdown, or plain text.
|
|
73
|
+
*
|
|
74
|
+
* @remarks
|
|
75
|
+
* Attempts JSON parsing first. For non-JSON content, applies markdown
|
|
76
|
+
* heuristics (headings, lists, code blocks, links) — 2+ signals returns
|
|
77
|
+
* `"markdown"`, otherwise `"text"`. This is now consistent with the
|
|
78
|
+
* disclosure module's `detectDocumentFormat`.
|
|
79
|
+
*
|
|
80
|
+
* @param content - The string to inspect.
|
|
81
|
+
* @returns The detected format: `"json"`, `"markdown"`, or `"text"`.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* detectFormat('{"a":1}'); // "json"
|
|
86
|
+
* detectFormat('# Title\n- item'); // "markdown"
|
|
87
|
+
* detectFormat('Hello'); // "text"
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export declare function detectFormat(content: string): 'json' | 'text' | 'markdown';
|
|
91
|
+
/** Default maximum content size in bytes (5 MB). */
|
|
92
|
+
export declare const DEFAULT_MAX_CONTENT_BYTES: number;
|
|
93
|
+
/** Default maximum line length in bytes (64 KB). */
|
|
94
|
+
export declare const DEFAULT_MAX_LINE_BYTES: number;
|
|
95
|
+
/** Options for content validation. */
|
|
96
|
+
export interface ValidateContentOptions {
|
|
97
|
+
/** Optional predefined schema name for JSON validation. */
|
|
98
|
+
schemaName?: string;
|
|
99
|
+
/** Maximum content size in bytes. Set to 0 to disable. Default: 5 MB. */
|
|
100
|
+
maxBytes?: number;
|
|
101
|
+
/** Maximum line length in bytes. Set to 0 to disable. Default: 64 KB. */
|
|
102
|
+
maxLineBytes?: number;
|
|
103
|
+
/** Reject content with binary control characters (0x00-0x08). Default: true. */
|
|
104
|
+
rejectBinary?: boolean;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Validate content for a given format, with optional schema enforcement
|
|
108
|
+
* and content size limits.
|
|
109
|
+
*
|
|
110
|
+
* @remarks
|
|
111
|
+
* Dispatches to {@link validateJson} for JSON content or
|
|
112
|
+
* {@link validateText} for text/markdown. Enforces a byte-size limit
|
|
113
|
+
* (default 5 MB) before format validation. Returns an error result when
|
|
114
|
+
* an unsupported format string is supplied or content exceeds the limit.
|
|
115
|
+
*
|
|
116
|
+
* @param content - The raw content to validate.
|
|
117
|
+
* @param format - The expected content format.
|
|
118
|
+
* @param schemaNameOrOptions - A schema name string (backward compat) or options object.
|
|
119
|
+
* @returns A {@link ValidationResult} indicating success or listing errors.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* validateContent(payload, 'json', 'prompt-v1');
|
|
124
|
+
* validateContent(payload, 'text', { maxBytes: 10 * 1024 * 1024 });
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
export declare function validateContent(content: unknown, format: 'json' | 'text' | 'markdown', schemaNameOrOptions?: string | ValidateContentOptions): ValidationResult;
|
|
128
|
+
/**
|
|
129
|
+
* Auto-detect the content format and then validate accordingly.
|
|
130
|
+
*
|
|
131
|
+
* @remarks
|
|
132
|
+
* Combines {@link detectFormat} and {@link validateContent} into a single
|
|
133
|
+
* call. The content must be a string; non-string values immediately fail
|
|
134
|
+
* with an `invalid_type` error.
|
|
135
|
+
*
|
|
136
|
+
* @param content - The raw content to auto-detect and validate.
|
|
137
|
+
* @param schemaName - Optional predefined schema name for JSON validation.
|
|
138
|
+
* @returns A {@link ValidationResult} with the detected format and validated data.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```ts
|
|
142
|
+
* const result = autoValidate('{"messages":[{"role":"user","content":"hi"}]}', 'prompt-v1');
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
export declare function autoValidate(content: unknown, schemaName?: string): ValidationResult;
|
|
146
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAeA;;;;;;;;;GASG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC,GAAG,OAAO;IAC3C,oDAAoD;IACpD,OAAO,EAAE,OAAO,CAAC;IACjB,wEAAwE;IACxE,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,yEAAyE;IACzE,MAAM,CAAC,EAAE,eAAe,EAAE,CAAC;IAC3B,mEAAmE;IACnE,MAAM,CAAC,EAAE,MAA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