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,285 @@
|
|
|
1
|
+
import { jsonFormatSchema, textFormatSchema, getPredefinedSchema, isPredefinedSchema, predefinedSchemas, } from './schemas.js';
|
|
2
|
+
// ── Helpers ─────────────────────────────────────────────────────
|
|
3
|
+
function formatZodErrors(error) {
|
|
4
|
+
return error.errors.map((err) => ({
|
|
5
|
+
path: err.path.join('.'),
|
|
6
|
+
message: err.message,
|
|
7
|
+
code: err.code,
|
|
8
|
+
}));
|
|
9
|
+
}
|
|
10
|
+
// ── Validators ──────────────────────────────────────────────────
|
|
11
|
+
/**
|
|
12
|
+
* Validate content as JSON, optionally against a predefined schema.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* When `content` is a string it is first parsed with `JSON.parse`. The
|
|
16
|
+
* parsed value is then checked against the generic JSON schema and,
|
|
17
|
+
* when a `schemaName` is provided, against the matching predefined
|
|
18
|
+
* schema from the registry.
|
|
19
|
+
*
|
|
20
|
+
* @param content - The raw content to validate (string or pre-parsed value).
|
|
21
|
+
* @param schemaName - Optional name of a predefined schema to enforce.
|
|
22
|
+
* @returns A {@link ValidationResult} indicating success or listing errors.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* const result = validateJson('{"key": "value"}');
|
|
27
|
+
* if (result.success) console.log(result.data);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export function validateJson(content, schemaName) {
|
|
31
|
+
let parsedContent;
|
|
32
|
+
if (typeof content === 'string') {
|
|
33
|
+
try {
|
|
34
|
+
parsedContent = JSON.parse(content);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
return {
|
|
38
|
+
success: false,
|
|
39
|
+
errors: [{
|
|
40
|
+
path: '',
|
|
41
|
+
message: `Invalid JSON: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
42
|
+
code: 'invalid_json',
|
|
43
|
+
}],
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
parsedContent = content;
|
|
49
|
+
}
|
|
50
|
+
const jsonResult = jsonFormatSchema.safeParse(parsedContent);
|
|
51
|
+
if (!jsonResult.success) {
|
|
52
|
+
return { success: false, errors: formatZodErrors(jsonResult.error) };
|
|
53
|
+
}
|
|
54
|
+
if (schemaName) {
|
|
55
|
+
if (!isPredefinedSchema(schemaName)) {
|
|
56
|
+
return {
|
|
57
|
+
success: false,
|
|
58
|
+
errors: [{
|
|
59
|
+
path: 'schema',
|
|
60
|
+
message: `Unknown schema '${schemaName}'. Available schemas: ${Object.keys(predefinedSchemas).join(', ')}`,
|
|
61
|
+
code: 'unknown_schema',
|
|
62
|
+
}],
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const schema = getPredefinedSchema(schemaName);
|
|
66
|
+
if (schema) {
|
|
67
|
+
const schemaResult = schema.safeParse(parsedContent);
|
|
68
|
+
if (!schemaResult.success) {
|
|
69
|
+
return { success: false, errors: formatZodErrors(schemaResult.error) };
|
|
70
|
+
}
|
|
71
|
+
return { success: true, data: schemaResult.data, format: 'json' };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return { success: true, data: jsonResult.data, format: 'json' };
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Validate content as plain text or markdown.
|
|
78
|
+
*
|
|
79
|
+
* @remarks
|
|
80
|
+
* Checks that the value is a string using the text format schema.
|
|
81
|
+
*
|
|
82
|
+
* @param content - The value to validate as text.
|
|
83
|
+
* @returns A {@link ValidationResult} with `format` set to `"text"` on success.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* const result = validateText('# Hello');
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export function validateText(content) {
|
|
91
|
+
const result = textFormatSchema.safeParse(content);
|
|
92
|
+
if (!result.success) {
|
|
93
|
+
return { success: false, errors: formatZodErrors(result.error) };
|
|
94
|
+
}
|
|
95
|
+
return { success: true, data: result.data, format: 'text' };
|
|
96
|
+
}
|
|
97
|
+
// Markdown signals used by detectFormat — must match disclosure.ts heuristics
|
|
98
|
+
const MARKDOWN_SIGNALS = [
|
|
99
|
+
/^#{1,6}\s/m, // Headers
|
|
100
|
+
/^\s*[-*]\s/m, // Unordered lists
|
|
101
|
+
/^\s*\d+\.\s/m, // Ordered lists
|
|
102
|
+
/```/, // Code blocks
|
|
103
|
+
/\[.+\]\(.+\)/, // Links
|
|
104
|
+
];
|
|
105
|
+
/**
|
|
106
|
+
* Auto-detect whether a string is JSON, markdown, or plain text.
|
|
107
|
+
*
|
|
108
|
+
* @remarks
|
|
109
|
+
* Attempts JSON parsing first. For non-JSON content, applies markdown
|
|
110
|
+
* heuristics (headings, lists, code blocks, links) — 2+ signals returns
|
|
111
|
+
* `"markdown"`, otherwise `"text"`. This is now consistent with the
|
|
112
|
+
* disclosure module's `detectDocumentFormat`.
|
|
113
|
+
*
|
|
114
|
+
* @param content - The string to inspect.
|
|
115
|
+
* @returns The detected format: `"json"`, `"markdown"`, or `"text"`.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* detectFormat('{"a":1}'); // "json"
|
|
120
|
+
* detectFormat('# Title\n- item'); // "markdown"
|
|
121
|
+
* detectFormat('Hello'); // "text"
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
export function detectFormat(content) {
|
|
125
|
+
try {
|
|
126
|
+
JSON.parse(content);
|
|
127
|
+
return 'json';
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
const markdownScore = MARKDOWN_SIGNALS.filter(r => r.test(content)).length;
|
|
131
|
+
return markdownScore >= 2 ? 'markdown' : 'text';
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/** Default maximum content size in bytes (5 MB). */
|
|
135
|
+
export const DEFAULT_MAX_CONTENT_BYTES = 5 * 1024 * 1024;
|
|
136
|
+
/** Default maximum line length in bytes (64 KB). */
|
|
137
|
+
export const DEFAULT_MAX_LINE_BYTES = 64 * 1024;
|
|
138
|
+
/**
|
|
139
|
+
* Check for binary content by scanning for control characters (0x00-0x08)
|
|
140
|
+
* in the first 8KB.
|
|
141
|
+
*/
|
|
142
|
+
function containsBinaryContent(content) {
|
|
143
|
+
const scanLength = Math.min(content.length, 8192);
|
|
144
|
+
for (let i = 0; i < scanLength; i++) {
|
|
145
|
+
const code = content.charCodeAt(i);
|
|
146
|
+
if (code >= 0 && code <= 8)
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Check if any line exceeds the maximum line length.
|
|
153
|
+
*/
|
|
154
|
+
function findOverlongLine(content, maxBytes) {
|
|
155
|
+
let lineStart = 0;
|
|
156
|
+
for (let i = 0; i <= content.length; i++) {
|
|
157
|
+
if (i === content.length || content[i] === '\n') {
|
|
158
|
+
const lineLength = i - lineStart;
|
|
159
|
+
if (lineLength > maxBytes)
|
|
160
|
+
return lineStart + 1; // 1-indexed
|
|
161
|
+
lineStart = i + 1;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Validate content for a given format, with optional schema enforcement
|
|
168
|
+
* and content size limits.
|
|
169
|
+
*
|
|
170
|
+
* @remarks
|
|
171
|
+
* Dispatches to {@link validateJson} for JSON content or
|
|
172
|
+
* {@link validateText} for text/markdown. Enforces a byte-size limit
|
|
173
|
+
* (default 5 MB) before format validation. Returns an error result when
|
|
174
|
+
* an unsupported format string is supplied or content exceeds the limit.
|
|
175
|
+
*
|
|
176
|
+
* @param content - The raw content to validate.
|
|
177
|
+
* @param format - The expected content format.
|
|
178
|
+
* @param schemaNameOrOptions - A schema name string (backward compat) or options object.
|
|
179
|
+
* @returns A {@link ValidationResult} indicating success or listing errors.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```ts
|
|
183
|
+
* validateContent(payload, 'json', 'prompt-v1');
|
|
184
|
+
* validateContent(payload, 'text', { maxBytes: 10 * 1024 * 1024 });
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
export function validateContent(content, format, schemaNameOrOptions) {
|
|
188
|
+
// Normalize options — backward compat with string schemaName
|
|
189
|
+
const opts = typeof schemaNameOrOptions === 'string'
|
|
190
|
+
? { schemaName: schemaNameOrOptions }
|
|
191
|
+
: schemaNameOrOptions ?? {};
|
|
192
|
+
const maxBytes = opts.maxBytes ?? DEFAULT_MAX_CONTENT_BYTES;
|
|
193
|
+
// Enforce content size limit
|
|
194
|
+
if (maxBytes > 0 && typeof content === 'string') {
|
|
195
|
+
const byteLength = Buffer.byteLength(content, 'utf-8');
|
|
196
|
+
if (byteLength > maxBytes) {
|
|
197
|
+
const maxMB = (maxBytes / (1024 * 1024)).toFixed(1);
|
|
198
|
+
const actualMB = (byteLength / (1024 * 1024)).toFixed(2);
|
|
199
|
+
return {
|
|
200
|
+
success: false,
|
|
201
|
+
errors: [{
|
|
202
|
+
path: '',
|
|
203
|
+
message: `Content size ${actualMB} MB exceeds maximum ${maxMB} MB`,
|
|
204
|
+
code: 'content_too_large',
|
|
205
|
+
}],
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
// Reject binary content (control chars 0x00-0x08 in first 8KB)
|
|
210
|
+
const rejectBinary = opts.rejectBinary ?? true;
|
|
211
|
+
if (rejectBinary && typeof content === 'string' && containsBinaryContent(content)) {
|
|
212
|
+
return {
|
|
213
|
+
success: false,
|
|
214
|
+
errors: [{
|
|
215
|
+
path: '',
|
|
216
|
+
message: 'Content contains binary control characters (0x00-0x08). Only text content is accepted.',
|
|
217
|
+
code: 'binary_content',
|
|
218
|
+
}],
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
// Enforce max line length
|
|
222
|
+
const maxLineBytes = opts.maxLineBytes ?? DEFAULT_MAX_LINE_BYTES;
|
|
223
|
+
if (maxLineBytes > 0 && typeof content === 'string') {
|
|
224
|
+
const overlongLine = findOverlongLine(content, maxLineBytes);
|
|
225
|
+
if (overlongLine !== null) {
|
|
226
|
+
const maxKB = (maxLineBytes / 1024).toFixed(0);
|
|
227
|
+
return {
|
|
228
|
+
success: false,
|
|
229
|
+
errors: [{
|
|
230
|
+
path: '',
|
|
231
|
+
message: `Line near position ${overlongLine} exceeds maximum line length of ${maxKB} KB`,
|
|
232
|
+
code: 'line_too_long',
|
|
233
|
+
}],
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
switch (format) {
|
|
238
|
+
case 'json':
|
|
239
|
+
return validateJson(content, opts.schemaName);
|
|
240
|
+
case 'text':
|
|
241
|
+
case 'markdown':
|
|
242
|
+
return validateText(content);
|
|
243
|
+
default:
|
|
244
|
+
return {
|
|
245
|
+
success: false,
|
|
246
|
+
errors: [{
|
|
247
|
+
path: 'format',
|
|
248
|
+
message: `Invalid format '${format}'. Must be 'json', 'text', or 'markdown'`,
|
|
249
|
+
code: 'invalid_format',
|
|
250
|
+
}],
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Auto-detect the content format and then validate accordingly.
|
|
256
|
+
*
|
|
257
|
+
* @remarks
|
|
258
|
+
* Combines {@link detectFormat} and {@link validateContent} into a single
|
|
259
|
+
* call. The content must be a string; non-string values immediately fail
|
|
260
|
+
* with an `invalid_type` error.
|
|
261
|
+
*
|
|
262
|
+
* @param content - The raw content to auto-detect and validate.
|
|
263
|
+
* @param schemaName - Optional predefined schema name for JSON validation.
|
|
264
|
+
* @returns A {@link ValidationResult} with the detected format and validated data.
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* ```ts
|
|
268
|
+
* const result = autoValidate('{"messages":[{"role":"user","content":"hi"}]}', 'prompt-v1');
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
export function autoValidate(content, schemaName) {
|
|
272
|
+
if (typeof content !== 'string') {
|
|
273
|
+
return {
|
|
274
|
+
success: false,
|
|
275
|
+
errors: [{
|
|
276
|
+
path: '',
|
|
277
|
+
message: 'Content must be a string',
|
|
278
|
+
code: 'invalid_type',
|
|
279
|
+
}],
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
const format = detectFormat(content);
|
|
283
|
+
return validateContent(content, format, schemaName);
|
|
284
|
+
}
|
|
285
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AAyCtB,mEAAmE;AAEnE,SAAS,eAAe,CAAC,KAAe;IACtC,OAAO,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAChC,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;QACxB,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,IAAI,EAAE,GAAG,CAAC,IAAI;KACf,CAAC,CAAC,CAAC;AACN,CAAC;AAED,mEAAmE;AAEnE;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,YAAY,CAAC,OAAgB,EAAE,UAAmB;IAChE,IAAI,aAAsB,CAAC;IAE3B,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,IAAI,CAAC;YACH,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,C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OAAO,EAAE,0BAA0B;oBACnC,IAAI,EAAE,cAAc;iBACrB,CAAC;SACH,CAAC;IACJ,CAAC;IAED,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;IACrC,OAAO,eAAe,CAAC,OAAO,EAAE,MAAyB,EAAE,UAAU,CAAC,CAAC;AACzE,CAAC"}
|
package/dist/wasm.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare function compress(data: string): Promise<Buffer>;
|
|
2
|
+
export declare function decompress(data: Buffer): Promise<string>;
|
|
3
|
+
export declare function encodeBase62(num: number): string;
|
|
4
|
+
export declare function decodeBase62(str: string): number;
|
|
5
|
+
export declare function generateId(): string;
|
|
6
|
+
export declare function hashContent(data: string): string;
|
|
7
|
+
export declare function calculateTokens(text: string): number;
|
|
8
|
+
export declare function calculateCompressionRatio(originalSize: number, compressedSize: number): number;
|
|
9
|
+
export declare function computeSignature(slug: string, agentId: string, conversationId: string, expiresAt: number, secret: string): string;
|
|
10
|
+
export declare function computeSignatureWithLength(slug: string, agentId: string, conversationId: string, expiresAt: number, secret: string, sigLength: number): string;
|
|
11
|
+
export declare function computeOrgSignature(slug: string, agentId: string, conversationId: string, orgId: string, expiresAt: number, secret: string): string;
|
|
12
|
+
export declare function computeOrgSignatureWithLength(slug: string, agentId: string, conversationId: string, orgId: string, expiresAt: number, secret: string, sigLength: number): string;
|
|
13
|
+
export declare function deriveSigningKey(apiKey: string): string;
|
|
14
|
+
export declare function createPatch(original: string, modified: string): string;
|
|
15
|
+
export declare function applyPatch(original: string, patchText: string): string;
|
|
16
|
+
export declare function reconstructVersion(base: string, patchesJson: string, target: number): string;
|
|
17
|
+
export declare function squashPatchesWasm(base: string, patchesJson: string): string;
|
|
18
|
+
export declare function wasmTextSimilarity(a: string, b: string): number;
|
|
19
|
+
export declare function wasmTextSimilarityNgram(a: string, b: string, n: number): number;
|
|
20
|
+
export declare function isExpired(expiresAtMs: number): boolean;
|
|
21
|
+
export interface DiffResult {
|
|
22
|
+
addedLines: number;
|
|
23
|
+
removedLines: number;
|
|
24
|
+
addedTokens: number;
|
|
25
|
+
removedTokens: number;
|
|
26
|
+
}
|
|
27
|
+
export declare function computeDiff(oldText: string, newText: string): DiffResult;
|
|
28
|
+
//# sourceMappingURL=wasm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasm.d.ts","sourceRoot":"","sources":["../src/wasm.ts"],"names":[],"mappings":"AAYA,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAG5D;AAED,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAE9D;AAID,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEhD;AAID,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAID,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhD;AAID,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpD;AAID,wBAAgB,yBAAyB,CACvC,YAAY,EAAE,MAAM,EACpB,cAAc,EAAE,MAAM,GACrB,MAAM,CAER;AAID,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,MAAM,EACtB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GACb,MAAM,CAER;AAED,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,MAAM,EACtB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,GAChB,MAAM,CAER;AAED,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,OAAO,EA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OAAO,EAAE,MAAM,GAAG,UAAU,CAUxE"}
|
package/dist/wasm.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WASM bridge — loads the Rust-compiled WASM module and re-exports
|
|
3
|
+
* portable core functions with TypeScript-friendly signatures.
|
|
4
|
+
*
|
|
5
|
+
* This module is the bridge between the Rust single-source-of-truth
|
|
6
|
+
* and the TypeScript API surface. All portable primitives (compression,
|
|
7
|
+
* hashing, signing, encoding) are delegated to WASM.
|
|
8
|
+
*/
|
|
9
|
+
import * as wasmModule from '../wasm/llmtxt_core.js';
|
|
10
|
+
// ── Compression ─────────────────────────────────────────────────
|
|
11
|
+
export async function compress(data) {
|
|
12
|
+
const bytes = wasmModule.compress(data);
|
|
13
|
+
return Buffer.from(bytes);
|
|
14
|
+
}
|
|
15
|
+
export async function decompress(data) {
|
|
16
|
+
return wasmModule.decompress(new Uint8Array(data));
|
|
17
|
+
}
|
|
18
|
+
// ── Base62 ──────────────────────────────────────────────────────
|
|
19
|
+
export function encodeBase62(num) {
|
|
20
|
+
return wasmModule.encode_base62(BigInt(num));
|
|
21
|
+
}
|
|
22
|
+
export function decodeBase62(str) {
|
|
23
|
+
return Number(wasmModule.decode_base62(str));
|
|
24
|
+
}
|
|
25
|
+
// ── ID Generation ───────────────────────────────────────────────
|
|
26
|
+
export function generateId() {
|
|
27
|
+
return wasmModule.generate_id();
|
|
28
|
+
}
|
|
29
|
+
// ── Hashing ─────────────────────────────────────────────────────
|
|
30
|
+
export function hashContent(data) {
|
|
31
|
+
return wasmModule.hash_content(data);
|
|
32
|
+
}
|
|
33
|
+
// ── Token Estimation ────────────────────────────────────────────
|
|
34
|
+
export function calculateTokens(text) {
|
|
35
|
+
return wasmModule.calculate_tokens(text);
|
|
36
|
+
}
|
|
37
|
+
// ── Compression Ratio ───────────────────────────────────────────
|
|
38
|
+
export function calculateCompressionRatio(originalSize, compressedSize) {
|
|
39
|
+
return wasmModule.calculate_compression_ratio(originalSize, compressedSize);
|
|
40
|
+
}
|
|
41
|
+
// ── HMAC Signing ────────────────────────────────────────────────
|
|
42
|
+
export function computeSignature(slug, agentId, conversationId, expiresAt, secret) {
|
|
43
|
+
return wasmModule.compute_signature(slug, agentId, conversationId, expiresAt, secret);
|
|
44
|
+
}
|
|
45
|
+
export function computeSignatureWithLength(slug, agentId, conversationId, expiresAt, secret, sigLength) {
|
|
46
|
+
return wasmModule.compute_signature_with_length(slug, agentId, conversationId, expiresAt, secret, sigLength);
|
|
47
|
+
}
|
|
48
|
+
export function computeOrgSignature(slug, agentId, conversationId, orgId, expiresAt, secret) {
|
|
49
|
+
return wasmModule.compute_org_signature(slug, agentId, conversationId, orgId, expiresAt, secret);
|
|
50
|
+
}
|
|
51
|
+
export function computeOrgSignatureWithLength(slug, agentId, conversationId, orgId, expiresAt, secret, sigLength) {
|
|
52
|
+
return wasmModule.compute_org_signature_with_length(slug, agentId, conversationId, orgId, expiresAt, secret, sigLength);
|
|
53
|
+
}
|
|
54
|
+
export function deriveSigningKey(apiKey) {
|
|
55
|
+
return wasmModule.derive_signing_key(apiKey);
|
|
56
|
+
}
|
|
57
|
+
// ── Patching ─────────────────────────────────────────────────────
|
|
58
|
+
export function createPatch(original, modified) {
|
|
59
|
+
return wasmModule.create_patch(original, modified);
|
|
60
|
+
}
|
|
61
|
+
export function applyPatch(original, patchText) {
|
|
62
|
+
return wasmModule.apply_patch(original, patchText);
|
|
63
|
+
}
|
|
64
|
+
export function reconstructVersion(base, patchesJson, target) {
|
|
65
|
+
return wasmModule.reconstruct_version(base, patchesJson, target);
|
|
66
|
+
}
|
|
67
|
+
export function squashPatchesWasm(base, patchesJson) {
|
|
68
|
+
return wasmModule.squash_patches(base, patchesJson);
|
|
69
|
+
}
|
|
70
|
+
// ── Similarity (WASM-backed) ────────────────────────────────────
|
|
71
|
+
export function wasmTextSimilarity(a, b) {
|
|
72
|
+
return wasmModule.text_similarity(a, b);
|
|
73
|
+
}
|
|
74
|
+
export function wasmTextSimilarityNgram(a, b, n) {
|
|
75
|
+
return wasmModule.text_similarity_ngram(a, b, n);
|
|
76
|
+
}
|
|
77
|
+
// ── Expiration ──────────────────────────────────────────────────
|
|
78
|
+
export function isExpired(expiresAtMs) {
|
|
79
|
+
return wasmModule.is_expired(expiresAtMs);
|
|
80
|
+
}
|
|
81
|
+
export function computeDiff(oldText, newText) {
|
|
82
|
+
const result = wasmModule.compute_diff(oldText, newText);
|
|
83
|
+
const out = {
|
|
84
|
+
addedLines: result.added_lines,
|
|
85
|
+
removedLines: result.removed_lines,
|
|
86
|
+
addedTokens: result.added_tokens,
|
|
87
|
+
removedTokens: result.removed_tokens,
|
|
88
|
+
};
|
|
89
|
+
result.free();
|
|
90
|
+
return out;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=wasm.js.map
|
package/dist/wasm.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasm.js","sourceRoot":"","sources":["../src/wasm.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAErD,mEAAmE;AAEnE,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,IAAY;IACzC,MAAM,KAAK,GAAG,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACxC,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC5B,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,IAAY;IAC3C,OAAO,UAAU,CAAC,UAAU,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;AACrD,CAAC;AAED,mEAAmE;AAEnE,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,OAAO,UAAU,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,OAAO,MAAM,CAAC,UAAU,CAAC,a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S,CAAC,WAAmB;IAC3C,OAAO,UAAU,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;AAC5C,CAAC;AAWD,MAAM,UAAU,WAAW,CAAC,OAAe,EAAE,OAAe;IAC1D,MAAM,MAAM,GAAG,UAAU,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACzD,MAAM,GAAG,GAAe;QACtB,UAAU,EAAE,MAAM,CAAC,WAAW;QAC9B,YAAY,EAAE,MAAM,CAAC,aAAa;QAClC,WAAW,EAAE,MAAM,CAAC,YAAY;QAChC,aAAa,EAAE,MAAM,CAAC,cAAc;KACrC,CAAC;IACF,MAAM,CAAC,IAAI,EAAE,CAAC;IACd,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "llmtxt",
|
|
3
|
+
"version": "2026.4.0",
|
|
4
|
+
"description": "Primitives and SDK for LLM agent content workflows: compression, patching, progressive disclosure, signed URLs, collaborative document lifecycle, and retrieval planning",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./sdk": {
|
|
14
|
+
"types": "./dist/sdk/index.d.ts",
|
|
15
|
+
"import": "./dist/sdk/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./disclosure": {
|
|
18
|
+
"types": "./dist/disclosure.d.ts",
|
|
19
|
+
"import": "./dist/disclosure.js"
|
|
20
|
+
},
|
|
21
|
+
"./similarity": {
|
|
22
|
+
"types": "./dist/similarity.d.ts",
|
|
23
|
+
"import": "./dist/similarity.js"
|
|
24
|
+
},
|
|
25
|
+
"./graph": {
|
|
26
|
+
"types": "./dist/graph.d.ts",
|
|
27
|
+
"import": "./dist/graph.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"wasm",
|
|
33
|
+
"README.md",
|
|
34
|
+
"CHANGELOG.md",
|
|
35
|
+
"LICENSE"
|
|
36
|
+
],
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsc",
|
|
39
|
+
"build:wasm": "bash -lc \"cd ../../crates/llmtxt-core && wasm-pack build --target nodejs --out-dir ../../packages/llmtxt/wasm && rm -f ../../packages/llmtxt/wasm/.gitignore\"",
|
|
40
|
+
"build:all": "pnpm run build:wasm && pnpm run build",
|
|
41
|
+
"dev": "tsc --watch",
|
|
42
|
+
"clean": "rm -rf dist",
|
|
43
|
+
"typecheck": "tsc --noEmit",
|
|
44
|
+
"validate": "pnpm run typecheck && pnpm exec forge-ts check && pnpm exec versionguard validate"
|
|
45
|
+
},
|
|
46
|
+
"keywords": [
|
|
47
|
+
"llm",
|
|
48
|
+
"agent",
|
|
49
|
+
"compression",
|
|
50
|
+
"content",
|
|
51
|
+
"patch",
|
|
52
|
+
"signed-urls",
|
|
53
|
+
"versioning",
|
|
54
|
+
"collaborative-docs",
|
|
55
|
+
"sdk",
|
|
56
|
+
"wasm"
|
|
57
|
+
],
|
|
58
|
+
"license": "MIT",
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"zod": "^3.25.3"
|
|
61
|
+
},
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"@cleocode/lafs": ">=2026.3"
|
|
64
|
+
},
|
|
65
|
+
"peerDependenciesMeta": {
|
|
66
|
+
"@cleocode/lafs": {
|
|
67
|
+
"optional": true
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"devDependencies": {
|
|
71
|
+
"@cleocode/lafs": "^2026.3.74",
|
|
72
|
+
"@codluv/versionguard": "^0.9.0",
|
|
73
|
+
"@forge-ts/api": "^0.21.1",
|
|
74
|
+
"@forge-ts/cli": "^0.21.1",
|
|
75
|
+
"@forge-ts/doctest": "^0.21.1",
|
|
76
|
+
"@forge-ts/enforcer": "^0.21.1",
|
|
77
|
+
"@forge-ts/gen": "^0.21.1",
|
|
78
|
+
"@types/node": "^22.19.15",
|
|
79
|
+
"typescript": "^5.9.3",
|
|
80
|
+
"@forge-ts/core": "^0.21.1"
|
|
81
|
+
},
|
|
82
|
+
"engines": {
|
|
83
|
+
"node": ">=22.0.0"
|
|
84
|
+
},
|
|
85
|
+
"publishConfig": {
|
|
86
|
+
"access": "public",
|
|
87
|
+
"provenance": true
|
|
88
|
+
},
|
|
89
|
+
"repository": {
|
|
90
|
+
"type": "git",
|
|
91
|
+
"url": "https://github.com/kryptobaseddev/llmtxt.git",
|
|
92
|
+
"directory": "packages/llmtxt"
|
|
93
|
+
},
|
|
94
|
+
"homepage": "https://github.com/kryptobaseddev/llmtxt/tree/main/packages/llmtxt",
|
|
95
|
+
"bugs": {
|
|
96
|
+
"url": "https://github.com/kryptobaseddev/llmtxt/issues"
|
|
97
|
+
}
|
|
98
|
+
}
|
package/wasm/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Codluv
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/wasm/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# llmtxt-core
|
|
2
|
+
|
|
3
|
+
Portable Rust primitives for llmtxt content workflows.
|
|
4
|
+
|
|
5
|
+
`llmtxt-core` is the single source of truth for compression, hashing, signing,
|
|
6
|
+
patch creation/application, and other low-level text utilities used by both:
|
|
7
|
+
|
|
8
|
+
- native Rust consumers like SignalDock
|
|
9
|
+
- the TypeScript package `llmtxt` via WASM bindings
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```toml
|
|
14
|
+
[dependencies]
|
|
15
|
+
llmtxt-core = "0.3"
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
During active development you can also pin the GitHub repository directly.
|
|
19
|
+
|
|
20
|
+
```toml
|
|
21
|
+
[dependencies]
|
|
22
|
+
llmtxt-core = { git = "https://github.com/kryptobaseddev/llmtxt.git", package = "llmtxt-core" }
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## What It Provides
|
|
26
|
+
|
|
27
|
+
- zlib-compatible `compress` / `decompress`
|
|
28
|
+
- SHA-256 content hashing
|
|
29
|
+
- token estimation and compression ratios
|
|
30
|
+
- signed URL generation and verification
|
|
31
|
+
- unified diff `create_patch` / `apply_patch` for attachment versioning
|
|
32
|
+
- base62 encoding helpers
|
|
33
|
+
- WASM-exported functions for TypeScript consumers
|
|
34
|
+
|
|
35
|
+
## Example
|
|
36
|
+
|
|
37
|
+
```rust
|
|
38
|
+
use llmtxt_core::{apply_patch, create_patch, generate_signed_url, SignedUrlBuildRequest};
|
|
39
|
+
|
|
40
|
+
let original = "hello\n";
|
|
41
|
+
let modified = "hello world\n";
|
|
42
|
+
let patch = create_patch(original, modified);
|
|
43
|
+
let rebuilt = apply_patch(original, &patch)?;
|
|
44
|
+
assert_eq!(rebuilt, modified);
|
|
45
|
+
|
|
46
|
+
let url = generate_signed_url(&SignedUrlBuildRequest {
|
|
47
|
+
base_url: "https://api.example.com",
|
|
48
|
+
path_prefix: "attachments",
|
|
49
|
+
slug: "xK9mP2nQ",
|
|
50
|
+
agent_id: "agent-1",
|
|
51
|
+
conversation_id: "conv-1",
|
|
52
|
+
expires_at: 1_800_000_000_000,
|
|
53
|
+
secret: "derived-secret",
|
|
54
|
+
sig_length: 32,
|
|
55
|
+
})?;
|
|
56
|
+
println!("{url}");
|
|
57
|
+
# Ok::<(), String>(())
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Publishing
|
|
61
|
+
|
|
62
|
+
This crate is designed to be consumable both directly from Rust and indirectly
|
|
63
|
+
through the WASM-backed TypeScript package in `packages/llmtxt`.
|