llm-large-files 0.7.0 → 0.8.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 +319 -1
- package/README.md +10 -8
- package/dist/analyze.d.ts +3 -1
- package/dist/analyze.d.ts.map +1 -1
- package/dist/analyze.js +109 -14
- package/dist/analyze.js.map +1 -1
- package/dist/anthropic/adapter.d.ts.map +1 -1
- package/dist/anthropic/adapter.js +4 -1
- package/dist/anthropic/adapter.js.map +1 -1
- package/dist/ask.d.ts +3 -3
- package/dist/ask.d.ts.map +1 -1
- package/dist/ask.js +72 -17
- package/dist/ask.js.map +1 -1
- package/dist/decode.d.ts +19 -0
- package/dist/decode.d.ts.map +1 -0
- package/dist/decode.js +97 -0
- package/dist/decode.js.map +1 -0
- package/dist/errors.d.ts +55 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +65 -0
- package/dist/errors.js.map +1 -1
- package/dist/events.d.ts +6 -0
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +5 -1
- package/dist/events.js.map +1 -1
- package/dist/evidence.d.ts.map +1 -1
- package/dist/evidence.js +6 -0
- package/dist/evidence.js.map +1 -1
- package/dist/extract.d.ts +7 -20
- package/dist/extract.d.ts.map +1 -1
- package/dist/extract.js +49 -751
- package/dist/extract.js.map +1 -1
- package/dist/gemini/adapter.d.ts.map +1 -1
- package/dist/gemini/adapter.js +9 -5
- package/dist/gemini/adapter.js.map +1 -1
- package/dist/gemini/endpoints.d.ts +5 -1
- package/dist/gemini/endpoints.d.ts.map +1 -1
- package/dist/gemini/endpoints.js +11 -2
- package/dist/gemini/endpoints.js.map +1 -1
- package/dist/gemini/generate.d.ts.map +1 -1
- package/dist/gemini/generate.js +20 -3
- package/dist/gemini/generate.js.map +1 -1
- package/dist/groups.d.ts +54 -0
- package/dist/groups.d.ts.map +1 -0
- package/dist/groups.js +136 -0
- package/dist/groups.js.map +1 -0
- package/dist/html.d.ts +11 -0
- package/dist/html.d.ts.map +1 -0
- package/dist/html.js +1112 -0
- package/dist/html.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/library.d.ts.map +1 -1
- package/dist/library.js +48 -12
- package/dist/library.js.map +1 -1
- package/dist/limiter.d.ts +2 -1
- package/dist/limiter.d.ts.map +1 -1
- package/dist/limiter.js +3 -2
- package/dist/limiter.js.map +1 -1
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +8 -1
- package/dist/model.js.map +1 -1
- package/dist/node/handlers.d.ts.map +1 -1
- package/dist/node/handlers.js +69 -15
- package/dist/node/handlers.js.map +1 -1
- package/dist/node/index.d.ts +2 -0
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +1 -0
- package/dist/node/index.js.map +1 -1
- package/dist/node/ingest-child.d.ts +38 -0
- package/dist/node/ingest-child.d.ts.map +1 -0
- package/dist/node/ingest-child.js +42 -0
- package/dist/node/ingest-child.js.map +1 -0
- package/dist/node/isolated.d.ts +88 -0
- package/dist/node/isolated.d.ts.map +1 -0
- package/dist/node/isolated.js +381 -0
- package/dist/node/isolated.js.map +1 -0
- package/dist/office.d.ts +105 -0
- package/dist/office.d.ts.map +1 -0
- package/dist/office.js +1092 -0
- package/dist/office.js.map +1 -0
- package/dist/openai/adapter.d.ts.map +1 -1
- package/dist/openai/adapter.js +15 -1
- package/dist/openai/adapter.js.map +1 -1
- package/dist/pdf-pages.d.ts.map +1 -1
- package/dist/pdf-pages.js +2 -6
- package/dist/pdf-pages.js.map +1 -1
- package/dist/peers.d.ts +8 -0
- package/dist/peers.d.ts.map +1 -0
- package/dist/peers.js +32 -0
- package/dist/peers.js.map +1 -0
- package/dist/plan.d.ts.map +1 -1
- package/dist/plan.js +1 -1
- package/dist/plan.js.map +1 -1
- package/dist/ranged.d.ts.map +1 -1
- package/dist/ranged.js +4 -2
- package/dist/ranged.js.map +1 -1
- package/dist/search.d.ts +99 -22
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +744 -140
- package/dist/search.js.map +1 -1
- package/dist/text-index.d.ts +3 -1
- package/dist/text-index.d.ts.map +1 -1
- package/dist/text-index.js +3 -1
- package/dist/text-index.js.map +1 -1
- package/dist/text.d.ts +27 -3
- package/dist/text.d.ts.map +1 -1
- package/dist/text.js +225 -23
- package/dist/text.js.map +1 -1
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +200 -12
- package/dist/tools.js.map +1 -1
- package/dist/types.d.ts +3 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/word-styles.d.ts +102 -0
- package/dist/word-styles.d.ts.map +1 -0
- package/dist/word-styles.js +419 -0
- package/dist/word-styles.js.map +1 -0
- package/dist/xlsx.d.ts +23 -0
- package/dist/xlsx.d.ts.map +1 -0
- package/dist/xlsx.js +511 -0
- package/dist/xlsx.js.map +1 -0
- package/dist/xml-stream.d.ts +55 -0
- package/dist/xml-stream.d.ts.map +1 -0
- package/dist/xml-stream.js +235 -0
- package/dist/xml-stream.js.map +1 -0
- package/docs/README.md +8 -8
- package/docs/getting-started.md +1 -1
- package/docs/guides/costs-and-limits.md +7 -5
- package/docs/guides/deployment.md +95 -29
- package/docs/guides/errors-and-reliability.md +23 -10
- package/docs/guides/pdfs.md +127 -74
- package/docs/guides/storage.md +1 -1
- package/docs/guides/testing.md +5 -1
- package/docs/guides/web-app.md +10 -9
- package/docs/how-it-works.md +73 -50
- package/docs/reference/ask.md +26 -8
- package/docs/reference/errors-and-retries.md +5 -3
- package/docs/reference/events.md +14 -6
- package/docs/reference/gemini.md +6 -2
- package/docs/reference/library.md +205 -74
- package/docs/reference/node.md +200 -22
- package/docs/reference/openai.md +1 -1
- package/docs/reference/tools.md +170 -22
- package/docs/security.md +114 -69
- package/docs/troubleshooting.md +40 -20
- package/package.json +6 -2
- package/src/analyze.ts +117 -13
- package/src/anthropic/adapter.ts +4 -1
- package/src/ask.ts +73 -17
- package/src/decode.ts +89 -0
- package/src/errors.ts +108 -0
- package/src/events.ts +10 -1
- package/src/evidence.ts +6 -0
- package/src/extract.ts +52 -709
- package/src/gemini/adapter.ts +9 -5
- package/src/gemini/endpoints.ts +12 -2
- package/src/gemini/generate.ts +19 -3
- package/src/groups.ts +162 -0
- package/src/html.ts +1071 -0
- package/src/index.ts +2 -1
- package/src/library.ts +43 -12
- package/src/limiter.ts +6 -1
- package/src/model.ts +8 -1
- package/src/node/handlers.ts +66 -16
- package/src/node/index.ts +2 -0
- package/src/node/ingest-child.ts +61 -0
- package/src/node/isolated.ts +464 -0
- package/src/office.ts +1047 -0
- package/src/openai/adapter.ts +14 -1
- package/src/pdf-pages.ts +2 -5
- package/src/peers.ts +29 -0
- package/src/plan.ts +2 -0
- package/src/ranged.ts +4 -2
- package/src/search.ts +738 -146
- package/src/text-index.ts +4 -2
- package/src/text.ts +214 -23
- package/src/tools.ts +192 -12
- package/src/types.ts +3 -3
- package/src/word-styles.ts +420 -0
- package/src/xlsx.ts +478 -0
- package/src/xml-stream.ts +224 -0
package/docs/reference/tools.md
CHANGED
|
@@ -38,7 +38,7 @@ the [loop reference](./ask.md).
|
|
|
38
38
|
|
|
39
39
|
| Tool | What it does |
|
|
40
40
|
|---|---|
|
|
41
|
-
| `search_document` | Finds lines that contain a text or match a regex, with an exact count, the first of them and the last one; or the passages that match keywords best. |
|
|
41
|
+
| `search_document` | Finds lines that contain a text or match a regex, with an exact count, the first of them and the last one, the last ones, or a count for each group (hour, code, message shape); or the passages that match keywords best. In all of a file or in a range of its lines. |
|
|
42
42
|
| `read_document` | Reads a range of lines, numbered, up to 600 a call. |
|
|
43
43
|
| `get_document_overview` | The outline, the log profile, the first 30 and last 20 lines, and what a whole-file read would take. |
|
|
44
44
|
| `analyze_whole_document` | Reads the whole file in parts with other model calls (map-reduce) and answers a task that needs all of it. |
|
|
@@ -92,7 +92,10 @@ whole numbers; a value that is neither a number nor a numeric string takes the d
|
|
|
92
92
|
blank string counts as 0, so it is clamped to the minimum); line numbers and counts out of range
|
|
93
93
|
are clamped, not refused. Page numbers are the exception: `view_pages` refuses a page that is not a
|
|
94
94
|
number of 1 or more. A `mode` other than `"exact"` or `"regex"` is `"keywords"`, and
|
|
95
|
-
`case_sensitive`
|
|
95
|
+
`case_sensitive` and `whole_word` are on only when they are `true`, `1`, or the same as text
|
|
96
|
+
(`"true"` in any case, or `"1"`), and off for any other value. Until 0.8.0, `case_sensitive: "true"`
|
|
97
|
+
was off. An `order` other than `"last"` is `"first"`. A `group_by` that is missing, `null`, `""` or `"none"` counts no groups; any other
|
|
98
|
+
value that is not one of its five is refused.
|
|
96
99
|
|
|
97
100
|
**Scope.** A call reaches only the documents its tool set was made for. A `document_id` outside
|
|
98
101
|
them is refused with the IDs the model may use, so that the next call is right (`view_pages`
|
|
@@ -131,7 +134,9 @@ lower the cap of one call with [`ToolCallLimits.maxResultCharacters`](#toolcalll
|
|
|
131
134
|
not known. Showing K of N results to stay within the size limit. Narrow the query or read
|
|
132
135
|
specific lines."
|
|
133
136
|
- An exact or regex search that read the whole file and has 2 matches or more is cut its own way:
|
|
134
|
-
it loses matches from the end of the first ones, and keeps the last one
|
|
137
|
+
it loses matches from the end of the first ones, and keeps the last one. With `order: "last"` it
|
|
138
|
+
loses the earliest of the last ones, and keeps the very last; with `group_by` it loses the
|
|
139
|
+
smallest groups, and keeps at least one, and by time the groups it keeps stay in time order (see
|
|
135
140
|
[`search_document`](#search_document)).
|
|
136
141
|
- When even one entry is too large, the result becomes
|
|
137
142
|
`{ "truncated": true, "partial": "<the start of the result as JSON text>", "note": "Result cut to the size limit. Ask for a smaller range." }`.
|
|
@@ -150,28 +155,57 @@ The description the model sees:
|
|
|
150
155
|
|
|
151
156
|
> Search a large attached file. mode "keywords" returns the most relevant passages for a question;
|
|
152
157
|
> "exact" finds the lines that contain the text; "regex" finds the lines that match a JavaScript
|
|
153
|
-
> regular expression
|
|
154
|
-
>
|
|
155
|
-
>
|
|
158
|
+
> regular expression (\w and \b know the letters of every language). For exact and regex,
|
|
159
|
+
> total_matching_lines counts every matching line, and the result shows the first max_results of
|
|
160
|
+
> them and the last one; search again from next_from_line for the ones after those shown, or with
|
|
161
|
+
> order "last" for the last ones. To count by group (per hour or day, per error code, per message
|
|
162
|
+
> shape), pass group_by: the result then counts each group, and shows no lines. from_line and
|
|
163
|
+
> to_line search part of the file. Results include line numbers to read further with read_document.
|
|
156
164
|
|
|
157
165
|
Until 0.6.0 it said that `exact` "returns every line containing the text", while the result showed
|
|
158
166
|
the first lines only: a model asked when something last happened named the last line it was shown.
|
|
167
|
+
0.8.0 added `from_line`, `to_line`, `order`, `group_by` and `whole_word`, and the sentences that
|
|
168
|
+
name them.
|
|
159
169
|
|
|
160
170
|
| Argument | Type | Required | Default and limits | Meaning |
|
|
161
171
|
|---|---|---|---|---|
|
|
162
172
|
| `document_id` | string | yes | | The `document_id` from the file's card. |
|
|
163
173
|
| `query` | string | yes | Not blank (`query is required.`) | Keywords, exact text, or a regex, by `mode`. |
|
|
164
174
|
| `mode` | `"keywords"` \| `"exact"` \| `"regex"` | no | `"keywords"` | How to search. |
|
|
165
|
-
| `max_results` | integer | no | keywords: 5, from 1 to 10. exact and regex: 20, from 1 to 50 | Passages,
|
|
166
|
-
| `context_lines` | integer | no | 0, from 0 to 5 | exact and regex: lines shown before and after each match. |
|
|
175
|
+
| `max_results` | integer | no | keywords: 5, from 1 to 10. exact and regex: 20, from 1 to 50. With `group_by`: 50 groups, from 1 to 200 | Passages, matching lines or groups returned. It does not limit the count. exact and regex also show the last matching line after them, when it is not among them. |
|
|
176
|
+
| `context_lines` | integer | no | 0, from 0 to 5 | exact and regex: lines shown before and after each match. None with `group_by`. |
|
|
167
177
|
| `case_sensitive` | boolean | no | `false` | exact and regex: match case. Keywords never do. |
|
|
178
|
+
| `from_line` | integer | no | 1. Past the last line: refused | Search only from this line on, in every mode. Pass a result's `next_from_line` to see the matches after those it shows. New in 0.8.0. |
|
|
179
|
+
| `to_line` | integer | no | The last line. Past it: the last line. Before `from_line`: refused | Search only up to this line, in every mode. New in 0.8.0. |
|
|
180
|
+
| `order` | `"first"` \| `"last"` | no | `"first"` | exact and regex: `"last"` shows the last `max_results` matching lines, in file order, in place of the first ones. New in 0.8.0. |
|
|
181
|
+
| `group_by` | `"capture"` \| `"minute"` \| `"hour"` \| `"day"` \| `"shape"` | no | none | exact and regex: count the matching lines by group, and show none ([below](#counts-by-group-group_by)). `"capture"` needs mode `regex`. `order` and `context_lines` are ignored with it. New in 0.8.0. |
|
|
182
|
+
| `whole_word` | boolean | no | `false` | exact only: match the text only as a whole word, not inside a longer one. Ignored in regex mode, where `\b` does it. New in 0.8.0. |
|
|
183
|
+
|
|
184
|
+
With `from_line` or `to_line`, the counts are of the lines searched, and the result says which in
|
|
185
|
+
`searched_lines` (`"1941-3000"`). In keywords mode, the passages ranked are those with at least one
|
|
186
|
+
line in the range, each with all its lines. The errors of these arguments:
|
|
187
|
+
|
|
188
|
+
| Error | When |
|
|
189
|
+
|---|---|
|
|
190
|
+
| `from_line 9000 is past the end of the file, which has 3000 lines.` | `from_line` is past the last line. |
|
|
191
|
+
| `to_line 20 is before from_line 100.` | `to_line` is before `from_line` (1 when it is not given). |
|
|
192
|
+
| `group_by counts the lines of an exact or regex search: use mode "exact" or "regex".` | `group_by` in keywords mode. |
|
|
193
|
+
| `group_by "capture" counts by the first group of a regex: use mode "regex" with a group, as in PAY-(\d+).` | `group_by: "capture"` in exact mode. |
|
|
194
|
+
| `group_by must be one of "capture", "minute", "hour", "day", "shape".` | Any other `group_by`. |
|
|
168
195
|
|
|
169
196
|
**`keywords`** ranks passages with BM25, computed at query time from substring hits: no index, any
|
|
170
197
|
language.
|
|
171
198
|
|
|
172
|
-
- The query is
|
|
173
|
-
|
|
174
|
-
|
|
199
|
+
- The query is composed (NFC) and folded as exact search folds it (see below), then split at
|
|
200
|
+
anything that is not a letter, a mark, a digit or `_`, so a mark stays with its letter (Hindi,
|
|
201
|
+
Bengali, Tamil, Thai, pointed Hebrew). A run of Chinese, Japanese, Thai, Lao, Khmer or Myanmar
|
|
202
|
+
text is split into words with `Intl.Segmenter`. Terms of fewer than 2 characters (a Han or kana
|
|
203
|
+
word may have one) and common English and Hebrew words are dropped; at most 12 distinct terms are
|
|
204
|
+
kept. A term also matches inside longer words: "timeout" matches "timeouts".
|
|
205
|
+
- A Hebrew term loses its points. One that starts with prefix letters (ו ה ב כ ל מ ש: בחוזה,
|
|
206
|
+
והחוזה) also searches its stem without them (חוזה), up to three letters off while three are
|
|
207
|
+
left, so passages with the word as written rank first. One that ends in a final letter also
|
|
208
|
+
matches its plain form, as inside a longer word: כסף finds כספים. New in 0.8.0.
|
|
175
209
|
- A passage is a run of whole lines of about 1,500 characters, or 40 lines at most. A passage that
|
|
176
210
|
contains the whole query as a phrase (more than one term, up to 200 characters) is ranked higher.
|
|
177
211
|
- Passages come best first. `score` is rounded to two decimals and only orders the results.
|
|
@@ -179,18 +213,28 @@ language.
|
|
|
179
213
|
these keywords. Try other words, synonyms, or exact mode."
|
|
180
214
|
|
|
181
215
|
**`exact`** finds every line that contains the text. A line counts once, however many times it
|
|
182
|
-
contains the text. A text with a line break matches across lines and counts on
|
|
183
|
-
starts
|
|
216
|
+
contains the text. A text with a line break matches across lines and counts on each line where it
|
|
217
|
+
starts, overlapping ones included: "a\na" counts 2 lines of "a\na\na" (1 until 0.8.0). The scan
|
|
218
|
+
stops after 1,000,000 matching lines, and with `whole_word` or `group_by` after 3 seconds. The query is composed (NFC), as the text is at ingest, so
|
|
219
|
+
"é" typed as "e" and an accent finds "é". Without `case_sensitive`, both sides are folded: lower
|
|
220
|
+
case, Greek final sigma as σ, curly quotes and primes as `'` and `"`, dashes and the minus sign as
|
|
221
|
+
`-`, no-break and thin spaces as a space, Hebrew geresh, gershayim and maqaf as `'`, `"` and `-`,
|
|
222
|
+
and full-width forms as ASCII. So "don't" finds "don’t", and צה"ל finds צה״ל (new in 0.8.0). With
|
|
223
|
+
`whole_word`, a match must not touch a letter, mark, digit or `_` of any script where the text
|
|
224
|
+
starts or ends with one.
|
|
184
225
|
|
|
185
226
|
**`regex`** tests a JavaScript regular expression against each line on its own, so a match cannot
|
|
186
227
|
span lines. It runs with the `i` flag unless `case_sensitive` is `true`, and with the `u` flag when
|
|
187
228
|
the pattern is valid with it (so `\p{L}` means a letter); a pattern valid only without it, such as
|
|
188
|
-
`[\w-.]`, runs without it.
|
|
229
|
+
`[\w-.]`, runs without it. With the `u` flag, `\w`, `\W`, `\b` and `\B` know the letters, marks and
|
|
230
|
+
digits of every script: `\bחוזה\b` finds the word, and `\w+` does not stop at "é" (new in 0.8.0;
|
|
231
|
+
a pattern with `\W` inside a class is run as written). The pattern is composed (NFC) first. The
|
|
232
|
+
folds of exact search do not apply. Limits:
|
|
189
233
|
|
|
190
234
|
| Limit | Value | When it is reached |
|
|
191
235
|
|---|---|---|
|
|
192
236
|
| Pattern length | 300 characters | Refused: `Regex is longer than 300 characters.` |
|
|
193
|
-
| Nested quantifier, such as `(a+)+` | Refused up front | `Regex has a nested quantifier like (a+)+, which can hang on large files. Simplify it.` |
|
|
237
|
+
| Nested quantifier, such as `(a+)+` | Refused up front, unless each repeat ends at a literal character that none of its quantified parts can match, as in `(\d{1,3}\.){3}\d{1,3}` or `(\w+\.)+com` (accepted since 0.8.0) | `Regex has a nested quantifier like (a+)+, which can hang on large files. Simplify it.` |
|
|
194
238
|
| Invalid pattern | | `Invalid regex: ` and the engine's message. |
|
|
195
239
|
| One search | 3,000 ms of matching, or what is left of the tool set's time when that is less | The scan stops; the result has the lines found so far and the note below. |
|
|
196
240
|
| A line the pattern cannot get past | Two whole slices of 250 ms on the same line | The scan stops there, the same way. |
|
|
@@ -206,9 +250,12 @@ Results of `exact` and `regex`:
|
|
|
206
250
|
|---|---|---|
|
|
207
251
|
| `document` | string | The file name. |
|
|
208
252
|
| `mode` | `"exact"` \| `"regex"` | The mode that ran. |
|
|
209
|
-
| `
|
|
210
|
-
| `
|
|
211
|
-
| `
|
|
253
|
+
| `searched_lines` | string, optional | With `from_line` or `to_line`: the lines searched, as `"1941-3000"`. The counts are of those lines. Keyword results have it too. New in 0.8.0. |
|
|
254
|
+
| `total_matching_lines` | number | Every matching line in the file (or in `searched_lines`), not only those shown. This is the number to count with. |
|
|
255
|
+
| `order` | `"last"`, optional | With `order: "last"` ([below](#the-last-matches-order-last)). |
|
|
256
|
+
| `note` | string, optional | When more lines match than are shown: "N of the M matching lines are shown: the first K and the last (line L). To see the ones in between, search again with from_line F, or count them with group_by." ("the first and the last" when K is 1). Until 0.8.0 it ended "narrow the search." When the scan stopped (1,000,000 lines, 3 seconds of a `whole_word` or `group_by` search, or a regex limit): "The scan stopped early; the total is a lower bound, and the last match in the file is not known." Or a size-limit note (below). Absent when every match is shown. |
|
|
257
|
+
| `next_from_line` | number, optional | When matches between the first ones and the last one are not shown: the line after the last of the first ones (F above). A search with `from_line` set to it shows the ones after. Absent when every match is shown, when the scan stopped early, with `order: "last"` and with `group_by`. New in 0.8.0. |
|
|
258
|
+
| `matches` | array | The first `max_results` matching lines, in file order, then the last matching line of the file when it is not among them. A scan that stopped early shows no last line, since it did not reach the end. With `order: "last"`, the last `max_results` matching lines, in file order. |
|
|
212
259
|
| `matches[].line` | number | The line number. |
|
|
213
260
|
| `matches[].page` | number, optional | The page of the line, for a PDF whose pages can be shown. |
|
|
214
261
|
| `matches[].text` | string | The line. A line longer than 400 characters is cut to 400 around the match, with `…` where it was cut. |
|
|
@@ -221,7 +268,8 @@ A search with `max_results: 1` and `context_lines: 1`:
|
|
|
221
268
|
"document": "app.log",
|
|
222
269
|
"mode": "exact",
|
|
223
270
|
"total_matching_lines": 51,
|
|
224
|
-
"note": "2 of the 51 matching lines are shown: the first and the last (line 4987). To see the ones in between,
|
|
271
|
+
"note": "2 of the 51 matching lines are shown: the first and the last (line 4987). To see the ones in between, search again with from_line 1204, or count them with group_by.",
|
|
272
|
+
"next_from_line": 1204,
|
|
225
273
|
"matches": [
|
|
226
274
|
{
|
|
227
275
|
"line": 1203,
|
|
@@ -244,7 +292,8 @@ has 2 matches or more loses matches from the end of the first ones, and keeps th
|
|
|
244
292
|
note is then one of:
|
|
245
293
|
|
|
246
294
|
- "Showing N of the M matching lines to stay within the size limit: the first K and the last (line
|
|
247
|
-
L).
|
|
295
|
+
L). To see the ones in between, search again with from_line F, or count them with group_by."
|
|
296
|
+
(N is K + 1; "the first and the last" when K is 1), with `next_from_line` F;
|
|
248
297
|
- "Showing 1 of the M matching lines to stay within the size limit: the last (line L). Narrow the
|
|
249
298
|
query or read specific lines.", when only the last one fits;
|
|
250
299
|
- "Showing 1 of the M matching lines: the last (line L). Narrow the search.", when the last one
|
|
@@ -255,12 +304,99 @@ When not even that fits, the result is cut as text, as any other (see
|
|
|
255
304
|
"Showing " marks a result that was cut: a call made again runs again. A result with the note "N of
|
|
256
305
|
the M matching lines are shown" is whole, and a call made again gets a pointer to it.
|
|
257
306
|
|
|
307
|
+
### The last matches: `order: "last"`
|
|
308
|
+
|
|
309
|
+
New in 0.8.0. With `order: "last"`, an exact or regex search shows the last `max_results` matching
|
|
310
|
+
lines, in file order, and no others: unlike a search in the default order, it adds no match from
|
|
311
|
+
the other end of the file. When not every match is shown, the note names the line of the last
|
|
312
|
+
match and of the first. A search with `max_results: 2`:
|
|
313
|
+
|
|
314
|
+
```json
|
|
315
|
+
{
|
|
316
|
+
"document": "app.log",
|
|
317
|
+
"mode": "exact",
|
|
318
|
+
"total_matching_lines": 51,
|
|
319
|
+
"order": "last",
|
|
320
|
+
"note": "These are the last 2 of the 51 matching lines, in the order of the file: the last match is on line 4987, and the first on line 1203.",
|
|
321
|
+
"matches": [
|
|
322
|
+
{ "line": 4410, "text": "2026-05-01 13:12:30 ERROR payment-service: timeout after 4410ms calling ledger" },
|
|
323
|
+
{ "line": 4987, "text": "2026-05-01 13:22:47 ERROR payment-service: timeout after 4987ms calling ledger" }
|
|
324
|
+
]
|
|
325
|
+
}
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
To fit its room, it loses the earliest of them first, and keeps the very last. The note is then
|
|
329
|
+
"Showing the last N of the M matching lines to stay within the size limit, in the order of the
|
|
330
|
+
file: the last match is on line L, and the first on line F. Narrow the query or read specific
|
|
331
|
+
lines."
|
|
332
|
+
|
|
333
|
+
When the scan stopped early (1,000,000 lines, 3 seconds of a `whole_word` or `group_by` search, or a regex limit), the lines shown are the last of
|
|
334
|
+
those it found, and the line of the first match is not named. The note is then "The scan stopped
|
|
335
|
+
early; the total is a lower bound. These are the last N matching lines it found, in the order of
|
|
336
|
+
the file. There may be later ones, after line L: search again with from_line F." (F is L + 1;
|
|
337
|
+
" and to_line T" follows it when the call gave `to_line`, T being the last line searched). Cut to
|
|
338
|
+
its room, the second sentence is "Showing the last N matching lines it found to stay within the
|
|
339
|
+
size limit, in the order of the file." When L is the last line searched, the last sentence is left
|
|
340
|
+
out. When the scan found no matching line before it stopped (a regex out of time), the note is
|
|
341
|
+
"The scan stopped early, out of time, before it found a matching line: the lines it did not reach
|
|
342
|
+
may have some. Try a simpler pattern, mode "exact", or fewer lines with from_line and to_line."
|
|
343
|
+
Like every note that starts with "The scan stopped early", it marks a result that a call made
|
|
344
|
+
again runs again: a later question has time of its own.
|
|
345
|
+
|
|
346
|
+
### Counts by group: `group_by`
|
|
347
|
+
|
|
348
|
+
New in 0.8.0. With `group_by`, an exact or regex search counts its matching lines by group, and
|
|
349
|
+
shows no line. One call answers "how many errors per hour" or "which codes, how often":
|
|
350
|
+
|
|
351
|
+
| `group_by` | The key of a line |
|
|
352
|
+
|---|---|
|
|
353
|
+
| `"capture"` | The text of the regex's first group: `PAY-(\d+)` counts each code. A line where that group took no part has no key. Regex mode only. |
|
|
354
|
+
| `"minute"`, `"hour"`, `"day"` | The first timestamp on the line, as written there (an offset such as `+02:00` or `Z` is not applied): `"2026-11-10 14:03"`, `"2026-11-10 14:00"`, `"2026-11-10"`. Read: ISO 8601 (`2026-11-10T14:03:17Z`, `2026-11-10 14:03:17,123`), nginx's error log (`2026/11/10 14:03:17`), the access logs of Apache and nginx (`10/Nov/2026:14:03:17 +0000`), epoch times in a JSON field `time`, `ts`, `timestamp` or `@timestamp` (10 or 13 digits, as UTC), `10.11.2026 14:03` (day first), `10/11/2026 14:03` (kept as `"10/11/2026"`, since day and month cannot be told apart), syslog (`Nov 10 14:03:17`) and klog (`I1110 14:03:17.123456`), the last two without a year (`"11-10 14:00"`). A line without one has no key. |
|
|
355
|
+
| `"shape"` | The line with its timestamp taken out, and its UUIDs, IP addresses, hex, quoted values and numbers replaced by `<id>`, `<ip>`, `<hex>`, `<s>` and `<n>`, as the log profile groups problems. |
|
|
356
|
+
|
|
357
|
+
Keys are cut at 120 characters. At most 10,000 groups are counted one by one; the lines of further
|
|
358
|
+
groups are counted together in `other_count`. Results, besides `document`, `mode`, `searched_lines`
|
|
359
|
+
and `total_matching_lines`:
|
|
360
|
+
|
|
361
|
+
| Field | Type | Meaning |
|
|
362
|
+
|---|---|---|
|
|
363
|
+
| `group_by` | string | The grouping that ran. |
|
|
364
|
+
| `total_groups` | number | The groups counted, at most 10,000. |
|
|
365
|
+
| `other_count` | number, optional | Matching lines of groups past the first 10,000, with `other_note`: "Lines of groups past the first 10,000 found." |
|
|
366
|
+
| `lines_without_group` | number, optional | Matching lines with no key: no timestamp, or a regex group that took no part. |
|
|
367
|
+
| `note` | string, optional | When not every group is shown: "K of the N groups are shown, the largest first. Narrow the search, or use from_line and to_line, for the others." By time, "the largest, in time order". A result cut to its room says "Showing K of the N groups to stay within the size limit, …". After the note of a scan that stopped early, when there is one. |
|
|
368
|
+
| `groups` | array | Up to `max_results` groups (50 by default, 200 at most). By `capture` and `shape`, the largest first. By time, in time order; when there are more groups than are shown, the largest of them, in time order. A result cut to its room keeps the largest groups as well: by `capture` and `shape` it loses the end of its list, and by time the smallest groups, keeping the others in time order. |
|
|
369
|
+
| `groups[].key` | string | The group. |
|
|
370
|
+
| `groups[].count` | number | Its matching lines. |
|
|
371
|
+
| `groups[].first_line`, `groups[].last_line` | number | Its first and last matching line, to read with `read_document`. |
|
|
372
|
+
|
|
373
|
+
A search for `PAY-5031` with `group_by: "hour"`:
|
|
374
|
+
|
|
375
|
+
```json
|
|
376
|
+
{
|
|
377
|
+
"document": "payments.log",
|
|
378
|
+
"mode": "exact",
|
|
379
|
+
"total_matching_lines": 214,
|
|
380
|
+
"group_by": "hour",
|
|
381
|
+
"total_groups": 3,
|
|
382
|
+
"groups": [
|
|
383
|
+
{ "key": "2026-11-10 13:00", "count": 9, "first_line": 40211, "last_line": 41876 },
|
|
384
|
+
{ "key": "2026-11-10 14:00", "count": 187, "first_line": 42003, "last_line": 47950 },
|
|
385
|
+
{ "key": "2026-11-10 15:00", "count": 18, "first_line": 48012, "last_line": 48990 }
|
|
386
|
+
]
|
|
387
|
+
}
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
Its step reads `Search payments.log (exact) for “PAY-5031”, counted by hour — 214 matching lines in
|
|
391
|
+
3 groups`.
|
|
392
|
+
|
|
258
393
|
Results of `keywords`:
|
|
259
394
|
|
|
260
395
|
| Field | Type | Meaning |
|
|
261
396
|
|---|---|---|
|
|
262
397
|
| `document` | string | The file name. |
|
|
263
398
|
| `mode` | `"keywords"` | |
|
|
399
|
+
| `searched_lines` | string, optional | With `from_line` or `to_line`: the lines searched, as `"1941-3000"`. New in 0.8.0. |
|
|
264
400
|
| `passages` | array | The best passages, best first. |
|
|
265
401
|
| `passages[].lines` | string | `"412-436"`: the passage's first and last line. |
|
|
266
402
|
| `passages[].pages` | string, optional | `"37"` or `"37-38"`, for a PDF whose pages can be shown. |
|
|
@@ -484,6 +620,13 @@ your own adds it to its system prompt). In short, it tells the model:
|
|
|
484
620
|
- what each text tool is for, and this rule: "To count or list what can be matched as text (a word,
|
|
485
621
|
an ID, an error code, a log level, a pattern), use search_document in exact or regex mode: its
|
|
486
622
|
total_matching_lines is exact.";
|
|
623
|
+
- since 0.8.0, how to count by group and see the rest of a list: "To count per group (per hour or
|
|
624
|
+
day, per error code or ID with a regex group, per message shape), pass group_by: one call gives
|
|
625
|
+
every count. For more matches than a result shows, search again from its next_from_line, or with
|
|
626
|
+
order "last" for the last ones.";
|
|
627
|
+
- since 0.8.0, what to search for: "Search for the bare form of a word: a search matches inside
|
|
628
|
+
longer words, so "timeout" also finds "timeouts", and a Hebrew word without its prefix letters
|
|
629
|
+
(חוזה, not בחוזה) finds every form of it.";
|
|
487
630
|
- to read around search hits before relying on them;
|
|
488
631
|
- to use `analyze_whole_document` only when the task needs all of the file and cannot be done by
|
|
489
632
|
matching text (a full summary, a timeline, items judged by meaning), and that it is slow, costly,
|
|
@@ -640,7 +783,7 @@ throws.
|
|
|
640
783
|
| The result has | The suffix |
|
|
641
784
|
|---|---|
|
|
642
785
|
| `error` | ` — failed:` and the error, as in ` — failed: Unknown tool “do_magic”.` |
|
|
643
|
-
| `total_matching_lines` (exact, regex) | ` — 1,203 matching lines` (numbers in en-US form), ` — 1 matching line` for one |
|
|
786
|
+
| `total_matching_lines` (exact, regex) | ` — 1,203 matching lines` (numbers in en-US form), ` — 1 matching line` for one. With `total_groups` (`group_by`): ` — 214 matching lines in 3 groups`, ` in 1 group` for one |
|
|
644
787
|
| `passages` (keywords) | ` — 5 passages`, ` — 1 passage` for one |
|
|
645
788
|
| `parts_read` (whole-file read) | ` — 9 parts, 3 relevant` (` — 1 part, 1 relevant` for one), then `, notes only` with `notes_only`, or `, incomplete` with `notes_cut_short` or `answer_cut_short` |
|
|
646
789
|
| `lines` and `total_lines` (read) | ` — got 1200-1342` when the label does not end with the lines shown, else `""` |
|
|
@@ -682,7 +825,7 @@ type ToolSet = {
|
|
|
682
825
|
| `has(name)` | `true` for each declared tool. Also `true` for `analyze_whole_document` when `generate` was given and the text tools are declared, even if it is not declared because no document is small enough: a call then gets the reason. Use it to tell the calls of this tool set from others. |
|
|
683
826
|
| `execute(name, args)` | Runs a call and returns its JSON result, within the tool's own cap. Failures come back as `{ error }`, as listed above. `view_pages` answers with an error here: it returns a file. |
|
|
684
827
|
| `executeWithFiles(name, args, limits?, hooks?)` | Runs any call with [`ToolCallLimits`](#toolcalllimits), and returns the result with the files it produced (`files` is empty for every tool but `view_pages`). Use it in a loop that can send files to the model. `hooks` ([`ToolCallHooks`](./library.md#toolcallhooks), new in 0.7.0) are listeners for this call alone: the progress of a whole-file read, in place of `ToolOptions.onProgress`, and each of its model requests with their retries. Only `analyze_whole_document` calls them. |
|
|
685
|
-
| `describe(name, args)` | A short line for a progress UI, read from the arguments the way the tool reads them: `Search app.log (exact) for “timeout”` (the query cut to 80 characters), `Read app.log lines 1200-1260` (`-1260` only when `end_line` is a number not below `start_line`), `Overview of app.log`, `Read all of novel.txt for “list every character”` (the task cut to 100 characters), `Look at report.pdf pages 2-3`. A cut never splits an emoji. A file not yet known is "the file"; an unknown tool is its name, as it came (`askWithFiles` labels it `Call “NAME”` instead). The line quotes the model's words as they are: show it as plain text, or clean it as `askWithFiles` does its steps. In `askWithFiles`, this line, made one line of plain text, is the `label` of the call's `tool.start` event, the line `onActivity` gets with "…", and the start of its step. |
|
|
828
|
+
| `describe(name, args)` | A short line for a progress UI, read from the arguments the way the tool reads them: `Search app.log (exact) for “timeout”` (the query cut to 80 characters; since 0.8.0 followed by ` in lines 1941-end` with `from_line` or `to_line`, and by `, counted by hour` with `group_by` or `, the last ones` with `order: "last"` in exact and regex mode), `Read app.log lines 1200-1260` (`-1260` only when `end_line` is a number not below `start_line`), `Overview of app.log`, `Read all of novel.txt for “list every character”` (the task cut to 100 characters), `Look at report.pdf pages 2-3`. A cut never splits an emoji. A file not yet known is "the file"; an unknown tool is its name, as it came (`askWithFiles` labels it `Call “NAME”` instead). The line quotes the model's words as they are: show it as plain text, or clean it as `askWithFiles` does its steps. In `askWithFiles`, this line, made one line of plain text, is the `label` of the call's `tool.start` event, the line `onActivity` gets with "…", and the start of its step. |
|
|
686
829
|
| `resultCharacters(name)` | The most characters of a result of this tool: the larger of `toolResultCharacters` and 40,000 for `analyze_whole_document`, 600 for `view_pages` (its file is counted in bytes), and `toolResultCharacters` for any other name. What a loop sets aside in its request before it runs a call. |
|
|
687
830
|
|
|
688
831
|
`execute` and `executeWithFiles` throw only when the tool set's `signal` was aborted: the error
|
|
@@ -881,3 +1024,8 @@ a question with files to search, that is nothing where the tools come first (Cla
|
|
|
881
1024
|
OpenAI-compatible endpoints), and at most your own system text on Gemini, where the guide follows
|
|
882
1025
|
it in the system instruction. For a question whose files are all sent whole, it is your own system
|
|
883
1026
|
text, and `view_pages` with its guide when the pages of a PDF can be looked at.
|
|
1027
|
+
|
|
1028
|
+
0.8.0 changed the description of `search_document` (its new arguments), the guide (two lines: counts
|
|
1029
|
+
by group and paging; searching the bare form of a word) and the closing requests
|
|
1030
|
+
([`FINAL_ANSWER_REQUEST`](./ask.md#final_answer_request) and the two others), so the cache misses
|
|
1031
|
+
once after upgrading to it too, the same way.
|