llm-large-files 0.1.0 → 0.2.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.
Files changed (69) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/README.md +1 -1
  3. package/dist/analyze.d.ts.map +1 -1
  4. package/dist/analyze.js +5 -1
  5. package/dist/analyze.js.map +1 -1
  6. package/dist/extract.d.ts +17 -1
  7. package/dist/extract.d.ts.map +1 -1
  8. package/dist/extract.js +73 -23
  9. package/dist/extract.js.map +1 -1
  10. package/dist/gemini/chat.d.ts +22 -2
  11. package/dist/gemini/chat.d.ts.map +1 -1
  12. package/dist/gemini/chat.js +41 -24
  13. package/dist/gemini/chat.js.map +1 -1
  14. package/dist/gemini/generate.d.ts.map +1 -1
  15. package/dist/gemini/generate.js +4 -1
  16. package/dist/gemini/generate.js.map +1 -1
  17. package/dist/index.d.ts +2 -1
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +1 -1
  20. package/dist/index.js.map +1 -1
  21. package/dist/library.d.ts +6 -0
  22. package/dist/library.d.ts.map +1 -1
  23. package/dist/library.js +15 -1
  24. package/dist/library.js.map +1 -1
  25. package/dist/map-reduce.d.ts +7 -0
  26. package/dist/map-reduce.d.ts.map +1 -1
  27. package/dist/map-reduce.js +58 -16
  28. package/dist/map-reduce.js.map +1 -1
  29. package/dist/pdf-layout.d.ts +32 -0
  30. package/dist/pdf-layout.d.ts.map +1 -0
  31. package/dist/pdf-layout.js +790 -0
  32. package/dist/pdf-layout.js.map +1 -0
  33. package/dist/plan.d.ts.map +1 -1
  34. package/dist/plan.js +6 -2
  35. package/dist/plan.js.map +1 -1
  36. package/dist/search.d.ts +8 -4
  37. package/dist/search.d.ts.map +1 -1
  38. package/dist/search.js +49 -24
  39. package/dist/search.js.map +1 -1
  40. package/dist/text.d.ts +18 -4
  41. package/dist/text.d.ts.map +1 -1
  42. package/dist/text.js +155 -15
  43. package/dist/text.js.map +1 -1
  44. package/dist/tools.d.ts.map +1 -1
  45. package/dist/tools.js +11 -3
  46. package/dist/tools.js.map +1 -1
  47. package/dist/types.d.ts +6 -0
  48. package/dist/types.d.ts.map +1 -1
  49. package/docs/api.md +20 -3
  50. package/docs/configuration.md +73 -5
  51. package/docs/getting-started.md +7 -4
  52. package/docs/how-it-works.md +26 -8
  53. package/docs/security.md +18 -5
  54. package/package.json +91 -91
  55. package/src/analyze.ts +3 -1
  56. package/src/extract.ts +77 -22
  57. package/src/gemini/chat.ts +60 -25
  58. package/src/gemini/generate.ts +3 -1
  59. package/src/index.ts +2 -1
  60. package/src/library.ts +241 -226
  61. package/src/map-reduce.ts +69 -16
  62. package/src/node/handlers.ts +122 -122
  63. package/src/pdf-layout.ts +771 -0
  64. package/src/plan.ts +100 -98
  65. package/src/search.ts +48 -25
  66. package/src/stores.ts +132 -132
  67. package/src/text.ts +131 -14
  68. package/src/tools.ts +274 -264
  69. package/src/types.ts +174 -168
package/src/types.ts CHANGED
@@ -1,168 +1,174 @@
1
- // Public types. Everything a consumer touches is defined here, so the package can be
2
- // published without exposing internal module layout.
3
-
4
- export type DocumentFormat = "text" | "markdown" | "log" | "json" | "csv" | "pdf" | "docx" | "pptx";
5
-
6
- export type OutlineEntry = {
7
- /** 1-based line number in the extracted text. */
8
- line: number;
9
- /** 1 is the top level. */
10
- level: number;
11
- title: string;
12
- };
13
-
14
- export type LogIssue = {
15
- /** The message with numbers, IDs, addresses, and quoted values replaced by placeholders. */
16
- template: string;
17
- level: string;
18
- count: number;
19
- firstLine: number;
20
- };
21
-
22
- export type LogProfile = {
23
- levels: Record<string, number>;
24
- firstTimestamp?: string;
25
- lastTimestamp?: string;
26
- /** The most frequent ERROR/FATAL/WARN message shapes. */
27
- topIssues: LogIssue[];
28
- };
29
-
30
- export type DocumentMeta = {
31
- id: string;
32
- /** Who may use this document. Set it at ingest; access with another owner is refused. */
33
- owner?: string;
34
- name: string;
35
- mimeType: string;
36
- format: DocumentFormat;
37
- /** Size of the uploaded file. */
38
- bytes: number;
39
- /** UTF-8 size of the extracted text. */
40
- textBytes: number;
41
- characters: number;
42
- lines: number;
43
- estimatedTokens: number;
44
- /** Lines longer than the wrap limit are split so every line stays readable by line number. */
45
- wrappedLines: number;
46
- pages?: number;
47
- outline: OutlineEntry[];
48
- logProfile?: LogProfile;
49
- createdAt: string;
50
- expiresAt: string;
51
- };
52
-
53
- export type StoredDocument = { meta: DocumentMeta; text: string };
54
-
55
- /** A JSON-safe summary for API responses and browser state. */
56
- export type DocumentSummary = {
57
- id: string;
58
- name: string;
59
- mimeType: string;
60
- format: DocumentFormat;
61
- bytes: number;
62
- lines: number;
63
- estimatedTokens: number;
64
- pages?: number;
65
- expiresAt: string;
66
- };
67
-
68
- /** Where extracted text lives. Implement this for Redis, S3, a database, etc. */
69
- export interface DocumentStore {
70
- put(document: StoredDocument): Promise<void>;
71
- /** Returns undefined for unknown or expired documents. */
72
- get(id: string): Promise<StoredDocument | undefined>;
73
- getMeta(id: string): Promise<DocumentMeta | undefined>;
74
- delete(id: string): Promise<boolean>;
75
- /** Removes expired documents and returns how many were removed. */
76
- sweep?(now?: Date): Promise<number>;
77
- }
78
-
79
- export type ExtractedText = { text: string; pages?: number };
80
-
81
- export type ExtractInput = {
82
- name: string;
83
- mimeType: string;
84
- format: DocumentFormat;
85
- };
86
-
87
- export type Extractor = (bytes: Uint8Array, input: ExtractInput) => Promise<ExtractedText>;
88
-
89
- /** The limits of the model connection the documents must fit through. */
90
- export type Budget = {
91
- /** The model's context window, in tokens. */
92
- contextTokens: number;
93
- /** The largest request body the model connector accepts, in bytes. */
94
- maxRequestBytes: number;
95
- /** The most document text to include in full in one request, in tokens. */
96
- inlineTokens: number;
97
- /** Tokens kept free for the answer, tool results, and conversation growth. */
98
- reservedTokens: number;
99
- /** Size of each part when a whole document is read with map-reduce. */
100
- mapChunkTokens: number;
101
- /** Refuse whole-document reads that would need more parts than this. */
102
- maxMapChunks: number;
103
- /** Cap on the characters of one tool result sent back to the model. */
104
- toolResultCharacters: number;
105
- };
106
-
107
- /** A JSON Schema subset accepted by Gemini, OpenAI, and Anthropic function declarations. */
108
- export type JsonSchema = {
109
- type: "string" | "integer" | "number" | "boolean" | "object" | "array";
110
- description?: string;
111
- enum?: string[];
112
- properties?: Record<string, JsonSchema>;
113
- required?: string[];
114
- items?: JsonSchema;
115
- };
116
-
117
- export type ToolDeclaration = {
118
- name: string;
119
- description: string;
120
- parameters: JsonSchema & { type: "object" };
121
- };
122
-
123
- export type ToolResult = Record<string, unknown>;
124
-
125
- export type ToolSet = {
126
- declarations: ToolDeclaration[];
127
- has(name: string): boolean;
128
- /** Runs a tool call. Bad arguments come back as `{ error }` so the model can correct itself. */
129
- execute(name: string, args: Record<string, unknown>): Promise<ToolResult>;
130
- /** A short, human-readable line describing a call, for progress UIs. */
131
- describe(name: string, args: Record<string, unknown>): string;
132
- };
133
-
134
- /** A plain text completion. The package stays provider-neutral by taking this as a function. */
135
- export type GenerateText = (request: {
136
- system: string;
137
- prompt: string;
138
- maxOutputTokens: number;
139
- signal?: AbortSignal;
140
- }) => Promise<string>;
141
-
142
- export type ProgressEvent = {
143
- kind: "map" | "reduce";
144
- message: string;
145
- done: number;
146
- total: number;
147
- };
148
-
149
- export type ProgressListener = (event: ProgressEvent) => void;
150
-
151
- export type DocumentPlan = {
152
- /** Documents whose full text goes into the prompt. */
153
- inline: DocumentMeta[];
154
- /** Documents the model reaches only through tools. */
155
- searchable: DocumentMeta[];
156
- inlineTokens: number;
157
- inlineBytes: number;
158
- };
159
-
160
- export type PreparedContext = {
161
- plan: DocumentPlan;
162
- /** Prompt text per document ID: the full text for inline documents, a summary card otherwise. */
163
- blocks: Map<string, string>;
164
- /** System instruction to add when any document is searchable, else an empty string. */
165
- instruction: string;
166
- /** IDs that were not found (never uploaded, deleted, or expired). */
167
- missing: string[];
168
- };
1
+ // Public types. Everything a consumer touches is defined here, so the package can be
2
+ // published without exposing internal module layout.
3
+
4
+ export type DocumentFormat = "text" | "markdown" | "log" | "json" | "csv" | "pdf" | "docx" | "pptx";
5
+
6
+ export type OutlineEntry = {
7
+ /** 1-based line number in the extracted text. */
8
+ line: number;
9
+ /** 1 is the top level. */
10
+ level: number;
11
+ title: string;
12
+ };
13
+
14
+ export type LogIssue = {
15
+ /** The message with numbers, IDs, addresses, and quoted values replaced by placeholders. */
16
+ template: string;
17
+ level: string;
18
+ count: number;
19
+ firstLine: number;
20
+ };
21
+
22
+ export type LogProfile = {
23
+ levels: Record<string, number>;
24
+ firstTimestamp?: string;
25
+ lastTimestamp?: string;
26
+ /** The most frequent ERROR/FATAL/WARN message shapes. */
27
+ topIssues: LogIssue[];
28
+ };
29
+
30
+ export type DocumentMeta = {
31
+ id: string;
32
+ /** Who may use this document. Set it at ingest; access with another owner is refused. */
33
+ owner?: string;
34
+ name: string;
35
+ mimeType: string;
36
+ format: DocumentFormat;
37
+ /** Size of the uploaded file. */
38
+ bytes: number;
39
+ /** UTF-8 size of the extracted text. */
40
+ textBytes: number;
41
+ characters: number;
42
+ lines: number;
43
+ estimatedTokens: number;
44
+ /** Lines longer than the wrap limit are split so every line stays readable by line number. */
45
+ wrappedLines: number;
46
+ pages?: number;
47
+ outline: OutlineEntry[];
48
+ logProfile?: LogProfile;
49
+ createdAt: string;
50
+ expiresAt: string;
51
+ };
52
+
53
+ export type StoredDocument = { meta: DocumentMeta; text: string };
54
+
55
+ /** A JSON-safe summary for API responses and browser state. */
56
+ export type DocumentSummary = {
57
+ id: string;
58
+ name: string;
59
+ mimeType: string;
60
+ format: DocumentFormat;
61
+ bytes: number;
62
+ lines: number;
63
+ estimatedTokens: number;
64
+ pages?: number;
65
+ expiresAt: string;
66
+ };
67
+
68
+ /** Where extracted text lives. Implement this for Redis, S3, a database, etc. */
69
+ export interface DocumentStore {
70
+ put(document: StoredDocument): Promise<void>;
71
+ /** Returns undefined for unknown or expired documents. */
72
+ get(id: string): Promise<StoredDocument | undefined>;
73
+ getMeta(id: string): Promise<DocumentMeta | undefined>;
74
+ delete(id: string): Promise<boolean>;
75
+ /** Removes expired documents and returns how many were removed. */
76
+ sweep?(now?: Date): Promise<number>;
77
+ }
78
+
79
+ export type ExtractedText = { text: string; pages?: number };
80
+
81
+ export type ExtractInput = {
82
+ name: string;
83
+ mimeType: string;
84
+ format: DocumentFormat;
85
+ };
86
+
87
+ export type Extractor = (bytes: Uint8Array, input: ExtractInput) => Promise<ExtractedText>;
88
+
89
+ /** The limits of the model connection the documents must fit through. */
90
+ export type Budget = {
91
+ /** The model's context window, in tokens. */
92
+ contextTokens: number;
93
+ /** The largest request body the model connector accepts, in bytes. */
94
+ maxRequestBytes: number;
95
+ /** The most document text to include in full in one request, in tokens. */
96
+ inlineTokens: number;
97
+ /** Tokens kept free for the answer, tool results, and conversation growth. */
98
+ reservedTokens: number;
99
+ /** Size of each part when a whole document is read with map-reduce. */
100
+ mapChunkTokens: number;
101
+ /** Refuse whole-document reads that would need more parts than this. */
102
+ maxMapChunks: number;
103
+ /** Cap on the characters of one tool result sent back to the model. */
104
+ toolResultCharacters: number;
105
+ };
106
+
107
+ /** A JSON Schema subset accepted by Gemini, OpenAI, and Anthropic function declarations. */
108
+ export type JsonSchema = {
109
+ type: "string" | "integer" | "number" | "boolean" | "object" | "array";
110
+ description?: string;
111
+ enum?: string[];
112
+ properties?: Record<string, JsonSchema>;
113
+ required?: string[];
114
+ items?: JsonSchema;
115
+ };
116
+
117
+ export type ToolDeclaration = {
118
+ name: string;
119
+ description: string;
120
+ parameters: JsonSchema & { type: "object" };
121
+ };
122
+
123
+ export type ToolResult = Record<string, unknown>;
124
+
125
+ export type ToolSet = {
126
+ declarations: ToolDeclaration[];
127
+ has(name: string): boolean;
128
+ /** Runs a tool call. Bad arguments come back as `{ error }` so the model can correct itself. */
129
+ execute(name: string, args: Record<string, unknown>): Promise<ToolResult>;
130
+ /** A short, human-readable line describing a call, for progress UIs. */
131
+ describe(name: string, args: Record<string, unknown>): string;
132
+ };
133
+
134
+ /** A plain text completion. The package stays provider-neutral by taking this as a function. */
135
+ export type GenerateText = (request: {
136
+ system: string;
137
+ prompt: string;
138
+ maxOutputTokens: number;
139
+ signal?: AbortSignal;
140
+ /**
141
+ * Call this when the model stopped because it reached `maxOutputTokens`, so a whole-document
142
+ * read can say its result is incomplete. Optional: an implementation that never calls it works
143
+ * as before, without that warning.
144
+ */
145
+ onTruncated?: () => void;
146
+ }) => Promise<string>;
147
+
148
+ export type ProgressEvent = {
149
+ kind: "map" | "reduce";
150
+ message: string;
151
+ done: number;
152
+ total: number;
153
+ };
154
+
155
+ export type ProgressListener = (event: ProgressEvent) => void;
156
+
157
+ export type DocumentPlan = {
158
+ /** Documents whose full text goes into the prompt. */
159
+ inline: DocumentMeta[];
160
+ /** Documents the model reaches only through tools. */
161
+ searchable: DocumentMeta[];
162
+ inlineTokens: number;
163
+ inlineBytes: number;
164
+ };
165
+
166
+ export type PreparedContext = {
167
+ plan: DocumentPlan;
168
+ /** Prompt text per document ID: the full text for inline documents, a summary card otherwise. */
169
+ blocks: Map<string, string>;
170
+ /** System instruction to add when any document is searchable, else an empty string. */
171
+ instruction: string;
172
+ /** IDs that were not found (never uploaded, deleted, or expired). */
173
+ missing: string[];
174
+ };