@texion/core 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +26 -2
- package/dist/index.d.ts +420 -0
- package/dist/index.js +2483 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Texion contributors
|
|
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/README.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @texion/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Document parsing and file state for text and attachment inputs, without React.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install @texion/core
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { processDocument } from '@texion/core';
|
|
11
|
+
|
|
12
|
+
const document = await processDocument('# Hello from Texion');
|
|
13
|
+
|
|
14
|
+
if (document.status === 'ready') {
|
|
15
|
+
console.log(document.raw, document.getPreview());
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Pass a `File`, `Blob`, or text source. Markdown, TXT, JSON, CSV, PDF, DOCX, and PNG/JPEG/GIF/WebP attachments use the same document shape. PDF and Word extraction load their parsers on demand. Images keep their original bytes and metadata; they do not automatically provide extracted text.
|
|
20
|
+
|
|
21
|
+
Use `createController` to manage multiple files, cancellation, duplicates, and pending/processing/ready/error states. Limits bound file sizes, document pages, extracted characters, and DOCX decompression. Safe previews escape content and apply a URL policy; Texion is not a malware scanner.
|
|
22
|
+
|
|
23
|
+
Parsing runs locally. Your app owns uploads, storage, and anything sent to an AI service. Default PDF extraction reads native text; optional OCR packages support scanned PDFs. Complex PDF reading order and table reconstruction are not guaranteed.
|
|
24
|
+
|
|
25
|
+
Experimental release. Works in the browser and Node. Node 20 or newer is required.
|
|
26
|
+
|
|
27
|
+
[Documentation](https://texion.pages.dev/docs) · [Source](https://github.com/Sirily23/texion/tree/main/packages/core) · [MIT license](LICENSE)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
interface OcrScheduler {
|
|
2
|
+
run<T>(work: () => Promise<T>, signal: AbortSignal): Promise<T>;
|
|
3
|
+
}
|
|
4
|
+
/** Share one scheduler across adapters/controllers to bound active OCR sessions. */
|
|
5
|
+
declare function createOcrScheduler(concurrency?: number): OcrScheduler;
|
|
6
|
+
|
|
7
|
+
type OcrErrorCode = 'ocr-unavailable' | 'ocr-consent-denied' | 'ocr-timeout' | 'ocr-limit-exceeded' | 'ocr-page-failed';
|
|
8
|
+
type ErrorCode = 'unsupported' | 'too-large' | 'too-many' | 'empty' | 'binary' | 'read-failed' | 'invalid-image' | 'invalid-document' | OcrErrorCode;
|
|
9
|
+
interface DocumentError {
|
|
10
|
+
readonly code: ErrorCode;
|
|
11
|
+
readonly message: string;
|
|
12
|
+
}
|
|
13
|
+
interface DocumentWarning {
|
|
14
|
+
readonly code: 'no-text' | 'invalid-utf8' | 'parse-failed' | 'truncated' | 'invalid-json' | 'invalid-csv' | 'too-complex' | OcrErrorCode;
|
|
15
|
+
readonly message: string;
|
|
16
|
+
}
|
|
17
|
+
declare class IngestionError extends Error {
|
|
18
|
+
readonly code: ErrorCode;
|
|
19
|
+
constructor(code: ErrorCode, message: string);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface DocumentBlock {
|
|
23
|
+
readonly text: string;
|
|
24
|
+
readonly bbox?: {
|
|
25
|
+
readonly x: number;
|
|
26
|
+
readonly y: number;
|
|
27
|
+
readonly w: number;
|
|
28
|
+
readonly h: number;
|
|
29
|
+
};
|
|
30
|
+
readonly confidence?: number;
|
|
31
|
+
readonly kind?: 'paragraph' | 'line' | 'word' | 'table';
|
|
32
|
+
}
|
|
33
|
+
interface DocumentPage {
|
|
34
|
+
readonly pageNumber: number;
|
|
35
|
+
readonly text: string;
|
|
36
|
+
readonly source: string;
|
|
37
|
+
readonly classification: 'native' | 'ocr-candidate';
|
|
38
|
+
readonly confidence?: number;
|
|
39
|
+
readonly nativeText?: string;
|
|
40
|
+
readonly image?: {
|
|
41
|
+
readonly width: number;
|
|
42
|
+
readonly height: number;
|
|
43
|
+
readonly dpi: number;
|
|
44
|
+
readonly rotation?: number;
|
|
45
|
+
};
|
|
46
|
+
readonly blocks?: readonly DocumentBlock[];
|
|
47
|
+
readonly error?: DocumentError;
|
|
48
|
+
}
|
|
49
|
+
interface OcrSummary {
|
|
50
|
+
readonly engineId: string;
|
|
51
|
+
readonly state: 'off' | 'denied' | 'done' | 'partial' | 'failed';
|
|
52
|
+
readonly pagesAttempted: number;
|
|
53
|
+
readonly pagesProcessed: number;
|
|
54
|
+
readonly pagesSkipped: number;
|
|
55
|
+
readonly pagesFailed: number;
|
|
56
|
+
}
|
|
57
|
+
interface DocumentProgress {
|
|
58
|
+
readonly phase: 'extracting' | 'pending-consent' | 'initializing-ocr' | 'ocr';
|
|
59
|
+
readonly done: number;
|
|
60
|
+
readonly total: number;
|
|
61
|
+
readonly pageNumber?: number;
|
|
62
|
+
}
|
|
63
|
+
interface OcrImage {
|
|
64
|
+
readonly rotation?: number;
|
|
65
|
+
readonly encoding: 'png';
|
|
66
|
+
readonly bytes: Uint8Array;
|
|
67
|
+
readonly width: number;
|
|
68
|
+
readonly height: number;
|
|
69
|
+
readonly dpi: number;
|
|
70
|
+
}
|
|
71
|
+
interface OcrPageInput extends OcrImage {
|
|
72
|
+
readonly pageNumber: number;
|
|
73
|
+
readonly signal: AbortSignal;
|
|
74
|
+
}
|
|
75
|
+
interface OcrPageResult {
|
|
76
|
+
readonly text: string;
|
|
77
|
+
/** Normalized 0..1, only when provided by the engine. */
|
|
78
|
+
readonly confidence?: number;
|
|
79
|
+
readonly blocks?: readonly DocumentBlock[];
|
|
80
|
+
}
|
|
81
|
+
/** A session belongs to exactly one recognition operation. terminate must release owned work. */
|
|
82
|
+
interface OcrSession {
|
|
83
|
+
initialize?(signal: AbortSignal): Promise<void>;
|
|
84
|
+
recognize(input: OcrPageInput): Promise<OcrPageResult>;
|
|
85
|
+
terminate(): void | Promise<void>;
|
|
86
|
+
}
|
|
87
|
+
interface OcrEngine {
|
|
88
|
+
readonly id: string;
|
|
89
|
+
readonly kind: 'local' | 'server' | 'hosted';
|
|
90
|
+
/** Trusted application declaration, not a network sandbox. Non-local engines always require approval. */
|
|
91
|
+
readonly uploadsData: boolean;
|
|
92
|
+
/** Create a cancellable session synchronously; defer model initialization to recognize. */
|
|
93
|
+
createSession(): OcrSession;
|
|
94
|
+
}
|
|
95
|
+
interface OcrRenderRequest {
|
|
96
|
+
readonly pageNumber: number;
|
|
97
|
+
readonly dpi: number;
|
|
98
|
+
readonly maxPixels: number;
|
|
99
|
+
readonly maxBytes: number;
|
|
100
|
+
readonly signal: AbortSignal;
|
|
101
|
+
}
|
|
102
|
+
type OcrRenderer = (request: OcrRenderRequest) => Promise<OcrImage>;
|
|
103
|
+
interface OcrApproval {
|
|
104
|
+
readonly document?: {
|
|
105
|
+
readonly id: string;
|
|
106
|
+
readonly name: string;
|
|
107
|
+
};
|
|
108
|
+
readonly engineId: string;
|
|
109
|
+
readonly uploadsData: boolean;
|
|
110
|
+
readonly pageNumbers: readonly number[];
|
|
111
|
+
readonly signal: AbortSignal;
|
|
112
|
+
}
|
|
113
|
+
interface OcrOptions {
|
|
114
|
+
readonly engine: OcrEngine;
|
|
115
|
+
readonly scheduler?: OcrScheduler;
|
|
116
|
+
readonly trigger?: 'auto' | 'ask' | 'off';
|
|
117
|
+
readonly requestApproval?: (request: OcrApproval) => boolean | Promise<boolean>;
|
|
118
|
+
readonly maxPages?: number;
|
|
119
|
+
readonly pageTimeoutMs?: number;
|
|
120
|
+
readonly totalTimeoutMs?: number;
|
|
121
|
+
readonly approvalTimeoutMs?: number;
|
|
122
|
+
readonly concurrency?: number;
|
|
123
|
+
readonly dpi?: number;
|
|
124
|
+
readonly minCharsPerPage?: number;
|
|
125
|
+
readonly maxImagePixels?: number;
|
|
126
|
+
readonly maxImageBytes?: number;
|
|
127
|
+
readonly maxBlocksPerPage?: number;
|
|
128
|
+
readonly onPageError?: 'skip' | 'fail';
|
|
129
|
+
}
|
|
130
|
+
interface OcrOutput {
|
|
131
|
+
readonly raw: string;
|
|
132
|
+
readonly pages: readonly DocumentPage[];
|
|
133
|
+
readonly ocr: OcrSummary;
|
|
134
|
+
readonly warnings: readonly DocumentWarning[];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
interface PreviewNode {
|
|
138
|
+
readonly type: string;
|
|
139
|
+
readonly value?: string;
|
|
140
|
+
readonly language?: string;
|
|
141
|
+
readonly children?: readonly PreviewNode[];
|
|
142
|
+
readonly url?: string;
|
|
143
|
+
readonly depth?: number;
|
|
144
|
+
readonly ordered?: boolean;
|
|
145
|
+
readonly start?: number;
|
|
146
|
+
readonly checked?: boolean;
|
|
147
|
+
}
|
|
148
|
+
declare function safeUrl(url: string): string | undefined;
|
|
149
|
+
|
|
150
|
+
type DocumentStatus = 'pending' | 'processing' | 'ready' | 'error';
|
|
151
|
+
type DocumentSource = 'file' | 'paste' | 'text';
|
|
152
|
+
interface TextInput {
|
|
153
|
+
readonly text: string;
|
|
154
|
+
readonly name?: string;
|
|
155
|
+
readonly source?: 'paste' | 'text';
|
|
156
|
+
readonly format?: string;
|
|
157
|
+
}
|
|
158
|
+
type DocumentInput = string | Blob | TextInput;
|
|
159
|
+
interface ImageInfo {
|
|
160
|
+
readonly mimeType: 'image/png' | 'image/jpeg' | 'image/gif' | 'image/webp';
|
|
161
|
+
readonly width: number;
|
|
162
|
+
readonly height: number;
|
|
163
|
+
}
|
|
164
|
+
interface DocumentPreview {
|
|
165
|
+
readonly image?: ImageInfo;
|
|
166
|
+
readonly nodes: readonly PreviewNode[];
|
|
167
|
+
readonly truncated: boolean;
|
|
168
|
+
readonly warnings: readonly DocumentWarning[];
|
|
169
|
+
}
|
|
170
|
+
interface TexionDocument {
|
|
171
|
+
readonly id: string;
|
|
172
|
+
readonly name: string;
|
|
173
|
+
readonly format: string;
|
|
174
|
+
readonly source: DocumentSource;
|
|
175
|
+
readonly status: DocumentStatus;
|
|
176
|
+
readonly size: number;
|
|
177
|
+
/** Decoded text source, or extracted PDF/DOCX text. Absent for image attachments. */
|
|
178
|
+
readonly raw?: string;
|
|
179
|
+
readonly pages?: readonly DocumentPage[];
|
|
180
|
+
readonly ocr?: OcrSummary;
|
|
181
|
+
readonly progress?: DocumentProgress;
|
|
182
|
+
readonly file?: File;
|
|
183
|
+
readonly blob?: Blob;
|
|
184
|
+
readonly metadata: Readonly<Record<string, unknown>>;
|
|
185
|
+
readonly warnings: readonly DocumentWarning[];
|
|
186
|
+
readonly error?: DocumentError;
|
|
187
|
+
readonly getPreview?: () => DocumentPreview;
|
|
188
|
+
}
|
|
189
|
+
interface DocumentSnapshot {
|
|
190
|
+
readonly documents: readonly TexionDocument[];
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
interface Limits {
|
|
194
|
+
readonly maxExtractedCharacters: number;
|
|
195
|
+
readonly maxDocumentPages: number;
|
|
196
|
+
readonly maxArchiveBytes: number;
|
|
197
|
+
readonly maxImagePixels: number;
|
|
198
|
+
readonly maxFiles: number;
|
|
199
|
+
readonly maxFileSize: number;
|
|
200
|
+
readonly maxPreviewCharacters: number;
|
|
201
|
+
readonly maxPreviewNodes: number;
|
|
202
|
+
readonly maxPreviewDepth: number;
|
|
203
|
+
}
|
|
204
|
+
declare const defaultLimits: Limits;
|
|
205
|
+
|
|
206
|
+
interface AdapterInspection {
|
|
207
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
208
|
+
readonly warnings?: readonly DocumentWarning[];
|
|
209
|
+
}
|
|
210
|
+
interface BinaryExtractionResult extends AdapterInspection {
|
|
211
|
+
readonly raw: string;
|
|
212
|
+
readonly pages?: readonly DocumentPage[];
|
|
213
|
+
readonly ocr?: OcrSummary;
|
|
214
|
+
}
|
|
215
|
+
interface ExtractionContext {
|
|
216
|
+
readonly document?: {
|
|
217
|
+
readonly id: string;
|
|
218
|
+
readonly name: string;
|
|
219
|
+
};
|
|
220
|
+
readonly reportProgress: (progress: DocumentProgress) => void;
|
|
221
|
+
}
|
|
222
|
+
interface AdapterIdentity {
|
|
223
|
+
readonly format: string;
|
|
224
|
+
readonly extensions: readonly string[];
|
|
225
|
+
readonly mimeTypes: readonly string[];
|
|
226
|
+
}
|
|
227
|
+
interface TextFormatAdapter extends AdapterIdentity {
|
|
228
|
+
readonly kind?: 'text';
|
|
229
|
+
readonly detect: (text: string) => boolean;
|
|
230
|
+
readonly metadata?: (text: string) => Readonly<Record<string, unknown>>;
|
|
231
|
+
readonly inspect?: (text: string, limits: Limits) => AdapterInspection;
|
|
232
|
+
readonly parse: (text: string, limits: Limits, metadata?: Readonly<Record<string, unknown>>) => DocumentPreview;
|
|
233
|
+
}
|
|
234
|
+
interface BinaryFormatAdapter extends AdapterIdentity {
|
|
235
|
+
readonly kind: 'binary';
|
|
236
|
+
/** Extract document text during processing; heavy parsers can load on demand. */
|
|
237
|
+
readonly extract?: (bytes: Uint8Array, limits: Limits, signal: AbortSignal, context?: ExtractionContext) => Promise<BinaryExtractionResult>;
|
|
238
|
+
readonly detectBytes: (bytes: Uint8Array) => boolean;
|
|
239
|
+
readonly inspect: (bytes: Uint8Array, limits: Limits, source: {
|
|
240
|
+
readonly name: string;
|
|
241
|
+
readonly mime: string;
|
|
242
|
+
}) => AdapterInspection;
|
|
243
|
+
readonly parse: (bytes: Uint8Array, limits: Limits, metadata: Readonly<Record<string, unknown>>) => DocumentPreview;
|
|
244
|
+
}
|
|
245
|
+
/** Third-party adapters are trusted code. Preview generation stays synchronous and lazy; binary text extraction can be async. */
|
|
246
|
+
type FormatAdapter = TextFormatAdapter | BinaryFormatAdapter;
|
|
247
|
+
|
|
248
|
+
interface ControllerOptions extends Partial<Limits> {
|
|
249
|
+
readonly adapters?: readonly FormatAdapter[];
|
|
250
|
+
readonly acceptedFormats?: readonly string[];
|
|
251
|
+
}
|
|
252
|
+
declare function createController(options?: ControllerOptions): {
|
|
253
|
+
getSnapshot: () => DocumentSnapshot;
|
|
254
|
+
subscribe: (listener: () => void) => () => void;
|
|
255
|
+
add: (input: DocumentInput) => string;
|
|
256
|
+
remove: (id: string) => void;
|
|
257
|
+
cancel: (id: string) => void;
|
|
258
|
+
clear: () => void;
|
|
259
|
+
setText(text: string, format?: string): void;
|
|
260
|
+
whenSettled(id: string): Promise<TexionDocument | undefined>;
|
|
261
|
+
waitForIdle(): Promise<void>;
|
|
262
|
+
};
|
|
263
|
+
type DocumentController = ReturnType<typeof createController>;
|
|
264
|
+
|
|
265
|
+
declare function processDocument(input: DocumentInput, options?: ControllerOptions & {
|
|
266
|
+
readonly signal?: AbortSignal;
|
|
267
|
+
}): Promise<TexionDocument>;
|
|
268
|
+
|
|
269
|
+
declare function createRegistry(adapters?: readonly FormatAdapter[], acceptedFormats?: readonly string[]): readonly FormatAdapter[];
|
|
270
|
+
|
|
271
|
+
declare function detectMarkdown(text: string): boolean;
|
|
272
|
+
declare const markdownAdapter: TextFormatAdapter;
|
|
273
|
+
|
|
274
|
+
interface DecodeResult {
|
|
275
|
+
readonly text: string;
|
|
276
|
+
readonly warnings: readonly DocumentWarning[];
|
|
277
|
+
}
|
|
278
|
+
declare function decode(bytes: Uint8Array): DecodeResult;
|
|
279
|
+
|
|
280
|
+
type HighlightKind = 'heading' | 'bold' | 'italic' | 'code' | 'link' | 'strikethrough' | 'list-marker' | 'blockquote' | 'frontmatter' | 'thematic-break' | 'property' | 'string' | 'number' | 'boolean' | 'null' | 'punctuation' | 'keyword' | 'comment';
|
|
281
|
+
/** Half-open offsets measured in JavaScript UTF-16 code units, including Markdown markers. */
|
|
282
|
+
interface HighlightToken {
|
|
283
|
+
readonly start: number;
|
|
284
|
+
readonly end: number;
|
|
285
|
+
readonly kind: HighlightKind;
|
|
286
|
+
}
|
|
287
|
+
interface HighlightLimits {
|
|
288
|
+
readonly maxCharacters?: number;
|
|
289
|
+
readonly maxTokens?: number;
|
|
290
|
+
readonly maxDepth?: number;
|
|
291
|
+
}
|
|
292
|
+
declare const defaultHighlightLimits: Readonly<{
|
|
293
|
+
maxCharacters: 20000;
|
|
294
|
+
maxTokens: 2000;
|
|
295
|
+
maxDepth: 64;
|
|
296
|
+
}>;
|
|
297
|
+
declare function tokenizeMarkdownSource(text: string, options?: HighlightLimits): {
|
|
298
|
+
readonly tokens: readonly HighlightToken[];
|
|
299
|
+
readonly limited: boolean;
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
type TextFormat = 'markdown' | 'json' | 'csv' | 'text';
|
|
303
|
+
type ContentFormat = TextFormat | (string & {});
|
|
304
|
+
type BuiltinFormat = TextFormat | 'image' | 'pdf' | 'docx';
|
|
305
|
+
/** Framework-independent, JSON-serializable content exchanged by editors and viewers. */
|
|
306
|
+
interface TexionContent {
|
|
307
|
+
readonly version: 1;
|
|
308
|
+
readonly format: ContentFormat;
|
|
309
|
+
readonly source: string;
|
|
310
|
+
/** Original imported Markdown, when available. Rich edits may normalize source. */
|
|
311
|
+
readonly originalSource?: string;
|
|
312
|
+
}
|
|
313
|
+
/** Persistable attachment metadata. reference is an opaque key owned by the host. */
|
|
314
|
+
interface TexionAttachmentReference {
|
|
315
|
+
readonly id: string;
|
|
316
|
+
readonly name: string;
|
|
317
|
+
readonly format: string;
|
|
318
|
+
readonly size: number;
|
|
319
|
+
readonly reference: string;
|
|
320
|
+
readonly mimeType?: string;
|
|
321
|
+
}
|
|
322
|
+
/** A saved message contains no File/Blob objects, functions, or temporary object URLs. */
|
|
323
|
+
interface TexionMessage {
|
|
324
|
+
readonly version: 1;
|
|
325
|
+
readonly content: TexionContent;
|
|
326
|
+
readonly attachments: readonly TexionAttachmentReference[];
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
interface HighlightSegment {
|
|
330
|
+
readonly start: number;
|
|
331
|
+
readonly end: number;
|
|
332
|
+
readonly kind?: HighlightKind;
|
|
333
|
+
}
|
|
334
|
+
interface HighlightModel {
|
|
335
|
+
readonly text: string;
|
|
336
|
+
readonly enabled: boolean;
|
|
337
|
+
readonly reason?: 'disabled' | 'too-large' | 'too-complex' | 'parse-failed';
|
|
338
|
+
readonly tokens: readonly HighlightToken[];
|
|
339
|
+
readonly segments: readonly HighlightSegment[];
|
|
340
|
+
}
|
|
341
|
+
interface HighlightOptions extends HighlightLimits {
|
|
342
|
+
readonly enabled?: boolean;
|
|
343
|
+
readonly format?: TextFormat;
|
|
344
|
+
}
|
|
345
|
+
declare function createHighlightModel(text: string, options?: HighlightOptions): HighlightModel;
|
|
346
|
+
|
|
347
|
+
declare function isTexionContent(value: unknown): value is TexionContent;
|
|
348
|
+
declare function createContent(source: string, options?: {
|
|
349
|
+
readonly originalSource?: string;
|
|
350
|
+
readonly format?: ContentFormat;
|
|
351
|
+
}): TexionContent;
|
|
352
|
+
|
|
353
|
+
declare function serializeContent(content: TexionContent): string;
|
|
354
|
+
declare function deserializeContent(serialized: string): TexionContent;
|
|
355
|
+
declare function exportMarkdown(content: TexionContent): string;
|
|
356
|
+
declare function exportSource(content: TexionContent): string;
|
|
357
|
+
|
|
358
|
+
/** Inspect bounded Markdown syntax without rendering HTML or changing the source. */
|
|
359
|
+
declare function inspectMarkdownSource(source: string, maxCharacters?: number): {
|
|
360
|
+
readonly nodeTypes: readonly string[];
|
|
361
|
+
readonly limited: boolean;
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
declare const jsonAdapter: TextFormatAdapter;
|
|
365
|
+
|
|
366
|
+
declare const csvAdapter: TextFormatAdapter;
|
|
367
|
+
|
|
368
|
+
declare const imageAdapter: BinaryFormatAdapter;
|
|
369
|
+
|
|
370
|
+
declare const textAdapter: TextFormatAdapter;
|
|
371
|
+
|
|
372
|
+
/** A host-supplied canvas module; interpreted by the pinned unpdf runtime. */
|
|
373
|
+
type PdfCanvasImport = () => Promise<unknown>;
|
|
374
|
+
/** Original PDF bytes plus bounded page rendering instructions. Copy before transferring bytes to a worker. */
|
|
375
|
+
type PdfOcrRenderer = (bytes: Uint8Array, request: OcrRenderRequest) => Promise<OcrImage>;
|
|
376
|
+
|
|
377
|
+
interface PdfAdapterOptions {
|
|
378
|
+
readonly ocr?: OcrOptions;
|
|
379
|
+
readonly renderer?: PdfOcrRenderer;
|
|
380
|
+
readonly canvasImport?: PdfCanvasImport;
|
|
381
|
+
}
|
|
382
|
+
declare function createPdfAdapter(options?: PdfAdapterOptions): BinaryFormatAdapter;
|
|
383
|
+
declare const pdfAdapter: BinaryFormatAdapter;
|
|
384
|
+
|
|
385
|
+
declare const docxAdapter: BinaryFormatAdapter;
|
|
386
|
+
|
|
387
|
+
declare function isTextFormat(value: string): value is TextFormat;
|
|
388
|
+
declare function detectTextFormat(source: string, allowed?: readonly TextFormat[]): TextFormat;
|
|
389
|
+
declare function detectTextFormat(source: string, allowed?: readonly string[], adapters?: readonly FormatAdapter[]): ContentFormat;
|
|
390
|
+
declare function sourceWarnings(source: string, format: ContentFormat, maxCharacters?: number): readonly DocumentWarning[];
|
|
391
|
+
|
|
392
|
+
declare function tokenizeDataSource(source: string, format: 'json' | 'csv', options?: HighlightLimits): {
|
|
393
|
+
tokens: readonly HighlightToken[];
|
|
394
|
+
limited: boolean;
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
declare function isAttachmentReference(value: unknown): value is TexionAttachmentReference;
|
|
398
|
+
declare function isTexionMessage(value: unknown): value is TexionMessage;
|
|
399
|
+
declare function createMessage(content: TexionContent, options?: {
|
|
400
|
+
readonly attachments?: readonly TexionAttachmentReference[];
|
|
401
|
+
}): TexionMessage;
|
|
402
|
+
/** The callback stores each attachment in the host's storage and returns its stable key. */
|
|
403
|
+
declare function createMessageFromDocuments(content: TexionContent, documents: readonly TexionDocument[], referenceFor: (document: TexionDocument) => string | Promise<string>): Promise<TexionMessage>;
|
|
404
|
+
declare function serializeMessage(message: TexionMessage): string;
|
|
405
|
+
declare function deserializeMessage(serialized: string): TexionMessage;
|
|
406
|
+
|
|
407
|
+
/** Bounded lexical highlighting; SQL is highlighted, never executed or syntax-validated. */
|
|
408
|
+
declare function inspectCodeBlock(source: string, language?: string, options?: HighlightLimits): Readonly<{
|
|
409
|
+
language: string;
|
|
410
|
+
tokens: readonly HighlightToken[];
|
|
411
|
+
warnings: readonly DocumentWarning[];
|
|
412
|
+
limited: boolean;
|
|
413
|
+
}>;
|
|
414
|
+
|
|
415
|
+
/** A routing heuristic; short text does not prove that a page is scanned or empty. */
|
|
416
|
+
declare function classifyPdfPage(text: string, minCharsPerPage?: number): 'native' | 'ocr-candidate';
|
|
417
|
+
|
|
418
|
+
declare function recognizePdfPages(nativePages: readonly DocumentPage[], options: OcrOptions, render: OcrRenderer, limits: Limits, signal: AbortSignal, report?: (progress: DocumentProgress) => void, document?: OcrApproval['document']): Promise<OcrOutput>;
|
|
419
|
+
|
|
420
|
+
export { type AdapterInspection, type BinaryExtractionResult, type BinaryFormatAdapter, type BuiltinFormat, type ContentFormat, type ControllerOptions, type DocumentBlock, type DocumentController, type DocumentError, type DocumentInput, type DocumentPage, type DocumentPreview, type DocumentProgress, type DocumentSnapshot, type DocumentSource, type DocumentStatus, type DocumentWarning, type ErrorCode, type ExtractionContext, type FormatAdapter, type HighlightKind, type HighlightLimits, type HighlightModel, type HighlightOptions, type HighlightSegment, type HighlightToken, type ImageInfo, IngestionError, type Limits, type OcrApproval, type OcrEngine, type OcrImage, type OcrOptions, type OcrOutput, type OcrPageInput, type OcrPageResult, type OcrRenderRequest, type OcrRenderer, type OcrScheduler, type OcrSession, type OcrSummary, type PdfAdapterOptions, type PdfCanvasImport, type PdfOcrRenderer, type PreviewNode, type TexionAttachmentReference, type TexionContent, type TexionDocument, type TexionMessage, type TextFormat, type TextFormatAdapter, type TextInput, classifyPdfPage, createContent, createController, createHighlightModel, createMessage, createMessageFromDocuments, createOcrScheduler, createPdfAdapter, createRegistry, csvAdapter, decode, defaultHighlightLimits, defaultLimits, deserializeContent, deserializeMessage, detectMarkdown, detectTextFormat, docxAdapter, exportMarkdown, exportSource, imageAdapter, inspectCodeBlock, inspectMarkdownSource, isAttachmentReference, isTexionContent, isTexionMessage, isTextFormat, jsonAdapter, markdownAdapter, pdfAdapter, processDocument, recognizePdfPages, safeUrl, serializeContent, serializeMessage, sourceWarnings, textAdapter, tokenizeDataSource, tokenizeMarkdownSource };
|