llm-large-files 0.8.2 → 0.10.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 (288) hide show
  1. package/CHANGELOG.md +981 -0
  2. package/README.md +22 -17
  3. package/dist/access.d.ts +128 -0
  4. package/dist/access.d.ts.map +1 -0
  5. package/dist/access.js +234 -0
  6. package/dist/access.js.map +1 -0
  7. package/dist/aggregate.d.ts +6 -0
  8. package/dist/aggregate.d.ts.map +1 -1
  9. package/dist/aggregate.js +86 -13
  10. package/dist/aggregate.js.map +1 -1
  11. package/dist/analyze.d.ts +4 -0
  12. package/dist/analyze.d.ts.map +1 -1
  13. package/dist/analyze.js +2 -2
  14. package/dist/analyze.js.map +1 -1
  15. package/dist/answer-info.d.ts +26 -0
  16. package/dist/answer-info.d.ts.map +1 -0
  17. package/dist/answer-info.js +32 -0
  18. package/dist/answer-info.js.map +1 -0
  19. package/dist/anthropic/adapter.d.ts +5 -1
  20. package/dist/anthropic/adapter.d.ts.map +1 -1
  21. package/dist/anthropic/adapter.js +35 -10
  22. package/dist/anthropic/adapter.js.map +1 -1
  23. package/dist/ask.d.ts +159 -14
  24. package/dist/ask.d.ts.map +1 -1
  25. package/dist/ask.js +743 -113
  26. package/dist/ask.js.map +1 -1
  27. package/dist/cache.d.ts +12 -3
  28. package/dist/cache.d.ts.map +1 -1
  29. package/dist/cache.js +18 -5
  30. package/dist/cache.js.map +1 -1
  31. package/dist/citations.d.ts +36 -0
  32. package/dist/citations.d.ts.map +1 -0
  33. package/dist/citations.js +291 -0
  34. package/dist/citations.js.map +1 -0
  35. package/dist/encoding.js +5 -3
  36. package/dist/encoding.js.map +1 -1
  37. package/dist/error-info.d.ts +70 -0
  38. package/dist/error-info.d.ts.map +1 -0
  39. package/dist/error-info.js +253 -0
  40. package/dist/error-info.js.map +1 -0
  41. package/dist/errors.d.ts +74 -8
  42. package/dist/errors.d.ts.map +1 -1
  43. package/dist/errors.js +104 -15
  44. package/dist/errors.js.map +1 -1
  45. package/dist/events.d.ts +57 -13
  46. package/dist/events.d.ts.map +1 -1
  47. package/dist/events.js +42 -11
  48. package/dist/events.js.map +1 -1
  49. package/dist/evidence.d.ts +4 -2
  50. package/dist/evidence.d.ts.map +1 -1
  51. package/dist/evidence.js +35 -5
  52. package/dist/evidence.js.map +1 -1
  53. package/dist/extract.d.ts +32 -8
  54. package/dist/extract.d.ts.map +1 -1
  55. package/dist/extract.js +52 -36
  56. package/dist/extract.js.map +1 -1
  57. package/dist/gemini/adapter.d.ts +54 -7
  58. package/dist/gemini/adapter.d.ts.map +1 -1
  59. package/dist/gemini/adapter.js +152 -41
  60. package/dist/gemini/adapter.js.map +1 -1
  61. package/dist/gemini/chat.d.ts +38 -53
  62. package/dist/gemini/chat.d.ts.map +1 -1
  63. package/dist/gemini/chat.js +20 -25
  64. package/dist/gemini/chat.js.map +1 -1
  65. package/dist/gemini/endpoints.d.ts +59 -11
  66. package/dist/gemini/endpoints.d.ts.map +1 -1
  67. package/dist/gemini/endpoints.js +33 -7
  68. package/dist/gemini/endpoints.js.map +1 -1
  69. package/dist/gemini/errors.d.ts +39 -5
  70. package/dist/gemini/errors.d.ts.map +1 -1
  71. package/dist/gemini/errors.js +70 -9
  72. package/dist/gemini/errors.js.map +1 -1
  73. package/dist/gemini/generate.d.ts +53 -2
  74. package/dist/gemini/generate.d.ts.map +1 -1
  75. package/dist/gemini/generate.js +100 -50
  76. package/dist/gemini/generate.js.map +1 -1
  77. package/dist/gemini/index.d.ts +4 -4
  78. package/dist/gemini/index.d.ts.map +1 -1
  79. package/dist/http.d.ts +41 -3
  80. package/dist/http.d.ts.map +1 -1
  81. package/dist/http.js +40 -2
  82. package/dist/http.js.map +1 -1
  83. package/dist/index.d.ts +13 -8
  84. package/dist/index.d.ts.map +1 -1
  85. package/dist/index.js +8 -5
  86. package/dist/index.js.map +1 -1
  87. package/dist/ingest.d.ts +78 -0
  88. package/dist/ingest.d.ts.map +1 -0
  89. package/dist/ingest.js +893 -0
  90. package/dist/ingest.js.map +1 -0
  91. package/dist/library.d.ts +295 -33
  92. package/dist/library.d.ts.map +1 -1
  93. package/dist/library.js +458 -650
  94. package/dist/library.js.map +1 -1
  95. package/dist/map-reduce.d.ts +176 -10
  96. package/dist/map-reduce.d.ts.map +1 -1
  97. package/dist/map-reduce.js +807 -61
  98. package/dist/map-reduce.js.map +1 -1
  99. package/dist/model.d.ts +79 -6
  100. package/dist/model.d.ts.map +1 -1
  101. package/dist/model.js +80 -4
  102. package/dist/model.js.map +1 -1
  103. package/dist/node/handlers.d.ts +247 -14
  104. package/dist/node/handlers.d.ts.map +1 -1
  105. package/dist/node/handlers.js +491 -227
  106. package/dist/node/handlers.js.map +1 -1
  107. package/dist/node/index.d.ts +3 -2
  108. package/dist/node/index.d.ts.map +1 -1
  109. package/dist/node/index.js +2 -1
  110. package/dist/node/index.js.map +1 -1
  111. package/dist/node/ingest-child.d.ts +7 -1
  112. package/dist/node/ingest-child.d.ts.map +1 -1
  113. package/dist/node/ingest-child.js +19 -4
  114. package/dist/node/ingest-child.js.map +1 -1
  115. package/dist/node/isolated.d.ts +3 -1
  116. package/dist/node/isolated.d.ts.map +1 -1
  117. package/dist/node/isolated.js +11 -4
  118. package/dist/node/isolated.js.map +1 -1
  119. package/dist/node/originals.d.ts +19 -0
  120. package/dist/node/originals.d.ts.map +1 -0
  121. package/dist/node/originals.js +82 -0
  122. package/dist/node/originals.js.map +1 -0
  123. package/dist/node/spool.d.ts +106 -0
  124. package/dist/node/spool.d.ts.map +1 -0
  125. package/dist/node/spool.js +378 -0
  126. package/dist/node/spool.js.map +1 -0
  127. package/dist/node/sse.d.ts +6 -4
  128. package/dist/node/sse.d.ts.map +1 -1
  129. package/dist/node/sse.js +9 -7
  130. package/dist/node/sse.js.map +1 -1
  131. package/dist/openai/adapter.d.ts +5 -1
  132. package/dist/openai/adapter.d.ts.map +1 -1
  133. package/dist/openai/adapter.js +53 -12
  134. package/dist/openai/adapter.js.map +1 -1
  135. package/dist/output-limit.d.ts +2 -1
  136. package/dist/output-limit.d.ts.map +1 -1
  137. package/dist/output-limit.js +5 -2
  138. package/dist/output-limit.js.map +1 -1
  139. package/dist/pdf-layout.d.ts.map +1 -1
  140. package/dist/pdf-layout.js +71 -12
  141. package/dist/pdf-layout.js.map +1 -1
  142. package/dist/pdf-outline.d.ts +71 -0
  143. package/dist/pdf-outline.d.ts.map +1 -0
  144. package/dist/pdf-outline.js +414 -0
  145. package/dist/pdf-outline.js.map +1 -0
  146. package/dist/plan.d.ts +137 -7
  147. package/dist/plan.d.ts.map +1 -1
  148. package/dist/plan.js +248 -26
  149. package/dist/plan.js.map +1 -1
  150. package/dist/prepare.d.ts +50 -0
  151. package/dist/prepare.d.ts.map +1 -0
  152. package/dist/prepare.js +207 -0
  153. package/dist/prepare.js.map +1 -0
  154. package/dist/ranged.d.ts +16 -11
  155. package/dist/ranged.d.ts.map +1 -1
  156. package/dist/ranged.js +56 -12
  157. package/dist/ranged.js.map +1 -1
  158. package/dist/retry.d.ts +3 -1
  159. package/dist/retry.d.ts.map +1 -1
  160. package/dist/retry.js +6 -2
  161. package/dist/retry.js.map +1 -1
  162. package/dist/scope.d.ts +25 -0
  163. package/dist/scope.d.ts.map +1 -0
  164. package/dist/scope.js +60 -0
  165. package/dist/scope.js.map +1 -0
  166. package/dist/search.d.ts +7 -0
  167. package/dist/search.d.ts.map +1 -1
  168. package/dist/search.js +72 -10
  169. package/dist/search.js.map +1 -1
  170. package/dist/source.d.ts +60 -0
  171. package/dist/source.d.ts.map +1 -0
  172. package/dist/source.js +170 -0
  173. package/dist/source.js.map +1 -0
  174. package/dist/stores.d.ts +126 -31
  175. package/dist/stores.d.ts.map +1 -1
  176. package/dist/stores.js +655 -141
  177. package/dist/stores.js.map +1 -1
  178. package/dist/testing/fake-fetch.d.ts +31 -0
  179. package/dist/testing/fake-fetch.d.ts.map +1 -0
  180. package/dist/testing/fake-fetch.js +66 -0
  181. package/dist/testing/fake-fetch.js.map +1 -0
  182. package/dist/testing/fake-model.d.ts +38 -0
  183. package/dist/testing/fake-model.d.ts.map +1 -0
  184. package/dist/testing/fake-model.js +62 -0
  185. package/dist/testing/fake-model.js.map +1 -0
  186. package/dist/testing/index.d.ts +7 -0
  187. package/dist/testing/index.d.ts.map +1 -0
  188. package/dist/testing/index.js +9 -0
  189. package/dist/testing/index.js.map +1 -0
  190. package/dist/testing/store-checks.d.ts +72 -0
  191. package/dist/testing/store-checks.d.ts.map +1 -0
  192. package/dist/testing/store-checks.js +619 -0
  193. package/dist/testing/store-checks.js.map +1 -0
  194. package/dist/tools.d.ts +47 -2
  195. package/dist/tools.d.ts.map +1 -1
  196. package/dist/tools.js +440 -71
  197. package/dist/tools.js.map +1 -1
  198. package/dist/types.d.ts +165 -14
  199. package/dist/types.d.ts.map +1 -1
  200. package/dist/whole-cost.d.ts +37 -0
  201. package/dist/whole-cost.d.ts.map +1 -0
  202. package/dist/whole-cost.js +46 -0
  203. package/dist/whole-cost.js.map +1 -0
  204. package/docs/README.md +21 -8
  205. package/docs/getting-started.md +18 -13
  206. package/docs/guides/anthropic.md +17 -10
  207. package/docs/guides/conversations.md +112 -47
  208. package/docs/guides/costs-and-limits.md +147 -42
  209. package/docs/guides/deployment.md +380 -86
  210. package/docs/guides/errors-and-reliability.md +317 -67
  211. package/docs/guides/explorer-model.md +4 -1
  212. package/docs/guides/openai-compatible.md +47 -7
  213. package/docs/guides/own-adapter-and-loop.md +60 -16
  214. package/docs/guides/pdfs.md +219 -36
  215. package/docs/guides/storage.md +676 -145
  216. package/docs/guides/testing.md +149 -129
  217. package/docs/guides/vertex-and-gemini.md +169 -57
  218. package/docs/guides/web-app.md +318 -80
  219. package/docs/how-it-works.md +155 -30
  220. package/docs/measurements.md +215 -13
  221. package/docs/publishing.md +185 -37
  222. package/docs/reference/anthropic.md +12 -7
  223. package/docs/reference/ask.md +415 -47
  224. package/docs/reference/errors-and-retries.md +194 -14
  225. package/docs/reference/events.md +77 -27
  226. package/docs/reference/gemini.md +252 -87
  227. package/docs/reference/library.md +886 -178
  228. package/docs/reference/node.md +659 -111
  229. package/docs/reference/openai.md +21 -10
  230. package/docs/reference/testing.md +311 -0
  231. package/docs/reference/tools.md +285 -30
  232. package/docs/security.md +404 -78
  233. package/docs/troubleshooting.md +151 -70
  234. package/docs/upgrading-0.10.md +472 -0
  235. package/docs/upgrading-0.9.md +890 -0
  236. package/package.json +16 -3
  237. package/src/access.ts +267 -0
  238. package/src/aggregate.ts +92 -14
  239. package/src/analyze.ts +2 -2
  240. package/src/answer-info.ts +45 -0
  241. package/src/anthropic/adapter.ts +40 -11
  242. package/src/ask.ts +866 -115
  243. package/src/cache.ts +20 -5
  244. package/src/citations.ts +294 -0
  245. package/src/encoding.ts +6 -4
  246. package/src/error-info.ts +290 -0
  247. package/src/errors.ts +131 -15
  248. package/src/events.ts +112 -24
  249. package/src/evidence.ts +35 -5
  250. package/src/extract.ts +56 -34
  251. package/src/gemini/adapter.ts +196 -43
  252. package/src/gemini/chat.ts +63 -78
  253. package/src/gemini/endpoints.ts +89 -16
  254. package/src/gemini/errors.ts +74 -11
  255. package/src/gemini/generate.ts +147 -57
  256. package/src/gemini/index.ts +4 -4
  257. package/src/http.ts +65 -4
  258. package/src/index.ts +13 -8
  259. package/src/ingest.ts +958 -0
  260. package/src/library.ts +711 -651
  261. package/src/map-reduce.ts +858 -70
  262. package/src/model.ts +113 -9
  263. package/src/node/handlers.ts +709 -221
  264. package/src/node/index.ts +14 -2
  265. package/src/node/ingest-child.ts +24 -6
  266. package/src/node/isolated.ts +11 -4
  267. package/src/node/originals.ts +78 -0
  268. package/src/node/spool.ts +379 -0
  269. package/src/node/sse.ts +9 -7
  270. package/src/openai/adapter.ts +56 -13
  271. package/src/output-limit.ts +5 -2
  272. package/src/pdf-layout.ts +69 -11
  273. package/src/pdf-outline.ts +400 -0
  274. package/src/plan.ts +287 -36
  275. package/src/prepare.ts +253 -0
  276. package/src/ranged.ts +48 -14
  277. package/src/retry.ts +6 -2
  278. package/src/scope.ts +63 -0
  279. package/src/search.ts +69 -13
  280. package/src/source.ts +178 -0
  281. package/src/stores.ts +702 -142
  282. package/src/testing/fake-fetch.ts +80 -0
  283. package/src/testing/fake-model.ts +78 -0
  284. package/src/testing/index.ts +11 -0
  285. package/src/testing/store-checks.ts +660 -0
  286. package/src/tools.ts +461 -73
  287. package/src/types.ts +151 -14
  288. package/src/whole-cost.ts +64 -0
@@ -2,7 +2,7 @@
2
2
 
3
3
  For maintainers. This page covers how a version of `llm-large-files` reaches npm: the changelog
4
4
  while the version is in development, the release pull request, the tag that starts the release
5
- workflow, and publishing by hand when the workflow's publish step fails. Working on the code
5
+ workflow, and publishing by hand when the workflow's publish job fails. Working on the code
6
6
  itself is in [CONTRIBUTING.md](https://github.com/renanbazinin/llm-large-files/blob/main/CONTRIBUTING.md).
7
7
 
8
8
  ## The changelog
@@ -58,6 +58,13 @@ an app receives (a `ModelErrorKind`, a `DocumentFormat`) goes in **Upgrading**:
58
58
  `switch`, or a `Record` keyed by the union, needs the new case. A new export, a new optional option
59
59
  or field, or a wider parameter type goes in **New**.
60
60
 
61
+ A new optional parameter at the end of a function or method goes in **Upgrading** too, for the code
62
+ that already fills its place: a store, or a subclass of a library class, whose method takes an extra
63
+ parameter of its own there, and a function passed as a callback (`.map(fromGeminiContents)` gets the
64
+ index in it). 0.9.0's `context` on every store method and `options` of `fromGeminiContents` did
65
+ both. Compile a probe of each case against the old and the new version before writing that a change
66
+ is only an addition.
67
+
61
68
  ### At release
62
69
 
63
70
  The release pull request makes two edits:
@@ -100,15 +107,23 @@ Pushing the tag starts the release workflow.
100
107
  3. Run the checks, and look at what npm will publish:
101
108
 
102
109
  ```bash
103
- npm run check # typecheck, tests, build
104
- npm pack --dry-run # dist/, src/, docs/, CHANGELOG.md, README.md, LICENSE, package.json
110
+ npm run check # typecheck, tests, build
111
+ npm pack --dry-run # dist/, src/, docs/, CHANGELOG.md, README.md, LICENSE, package.json
112
+ node scripts/check-tarball.mjs # builds, packs, and checks the tarball as npm installs it
105
113
  ```
106
114
 
107
115
  `files` in package.json publishes all of `dist/`, `src/` and `docs/`. CONTRIBUTING.md,
108
- `examples/` and `test/` are not published.
116
+ `evals/`, `examples/`, `scripts/` and `test/` are not published. `check-tarball.mjs` is what the release
117
+ workflow runs on the tarball it publishes ([below](#what-the-release-workflow-does)); it
118
+ installs into temporary projects from the npm registry, so it needs the network.
109
119
 
110
120
  4. Commit, push, and open a pull request titled "Release 0.6.0: what the version is about". Wait
111
- for CI (Node 20, 22 and 24, on Ubuntu and Windows), then squash-merge it.
121
+ for CI (the tests on Node 22, 24 and 26, on Ubuntu and Windows; the tarball check on Node 22
122
+ and 26; the coverage report; the replayed evals), then squash-merge it. When release.yml
123
+ changed since the last release, run its dry run first
124
+ ([below](#the-first-run-of-a-changed-workflow)): on the branch when the release.yml of `main`
125
+ already has the `workflow_dispatch` trigger, or else on `main` after the merge and before the
126
+ tag.
112
127
 
113
128
  5. Tag the merged commit and push the tag:
114
129
 
@@ -132,7 +147,9 @@ Pushing the tag starts the release workflow.
132
147
  gh run watch <run-id>
133
148
  ```
134
149
 
135
- If its publish step fails, see [When the publish step fails](#when-the-publish-step-fails).
150
+ If its build job fails, nothing was staged: see the end of
151
+ [What the release workflow does](#what-the-release-workflow-does). If its publish job fails, see
152
+ [When the publish job fails](#when-the-publish-job-fails).
136
153
 
137
154
  7. Approve the staged version. The workflow stages it (`npm stage publish`): it is uploaded with
138
155
  its provenance, but not installable yet. Open npmjs.com → your account → **Staged Packages**,
@@ -159,21 +176,66 @@ Pushing the tag starts the release workflow.
159
176
 
160
177
  ## What the release workflow does
161
178
 
162
- `.github/workflows/release.yml` runs when a tag that starts with `v` is pushed. It runs on Ubuntu
163
- with Node 24 and no dependency cache (a poisoned cache could expose the publish token), and asks
164
- GitHub for `contents: read` and `id-token: write`. Its steps:
179
+ `.github/workflows/release.yml` runs when a tag that starts with `v` is pushed. It has two jobs, on
180
+ Ubuntu with Node 24 and no dependency cache (a poisoned cache would run its code in the job). The
181
+ actions it uses are pinned by the commit of their release, as in `ci.yml`, which says how to update
182
+ them. Run by hand, it is a dry run with a third job in place of the publish job:
183
+ [A dry run of the release workflow](#a-dry-run-of-the-release-workflow).
184
+
185
+ **The build job** has `contents: read` and no identity token: the tests and the dependencies run in
186
+ a job that cannot ask npm for a token. Its steps:
165
187
 
166
188
  | Step | Fails when |
167
189
  | --- | --- |
168
- | `npm ci` | package-lock.json does not match package.json. |
169
- | Check the tag matches package.json | The tag is not `v` + the `version` in package.json: for example `v0.6.0` on a commit whose package.json still says 0.5.0. |
190
+ | `npm ci --ignore-scripts` | package-lock.json does not match package.json. No install script runs: nothing in the tree needs one (esbuild, under Vitest, finds its binary without its `postinstall`). |
191
+ | A dispatch that stages must run on a tag | Only in a run by hand with `dry_run` off: the run is on a branch. |
192
+ | Check the tag matches package.json | The tag is not `v` + the `version` in package.json: for example `v0.6.0` on a commit whose package.json still says 0.5.0. Skipped on a branch (a dry run). |
170
193
  | `npm run check` | The typecheck, a test or the build fails. |
194
+ | Pack | `npm pack` fails. The step prints the tarball's `npm shasum`, `npm integrity` and SHA-256: npm shows the first two for the version once it is published. |
195
+ | Check the tarball as npm installs it | `node scripts/check-tarball.mjs` on that tarball finds a fault (below). |
196
+ | Upload the tarball | It is kept as the artifact `package` of the run, for 7 days. |
197
+
198
+ `scripts/check-tarball.mjs` checks the tarball itself, not the checkout:
199
+
200
+ - the files in it: only those of `files` in package.json, and every file that `exports`, `main`,
201
+ `types` and `typesVersions` name is there;
202
+ - installed into a new project without the optional peers: `import` and `require()` of every
203
+ subpath of `exports`, `./testing` included, give the same module, and a PDF is refused with the
204
+ message that names `unpdf`;
205
+ - `llm-large-files/node/ingest-child.js` resolves, and a text file is ingested in a child process
206
+ of `createIsolatedExtractors`;
207
+ - a consumer compiles with the checkout's TypeScript under `moduleResolution` NodeNext (an ES module
208
+ and a CommonJS one), Bundler and Node10, with `skipLibCheck: false`;
209
+ - installed with `unpdf`, `jszip` and `@cantoo/pdf-lib` at the versions of package-lock.json, a PDF
210
+ and a DOCX are read, in the process and in a child process;
211
+ - `publint` and `@arethetypeswrong/cli` (`attw`) pass, at the versions pinned in the script. `attw`
212
+ ignores `cjs-resolves-to-esm` (the package is ESM, and `require()` of it works from Node 22.12)
213
+ and does not check `./node/ingest-child.js` (a script that child processes run, not a module to
214
+ import).
215
+
216
+ CI's `package` job runs the same script on Node 22.12.0 (the floor of `engines`), the newest 22,
217
+ and 26 for every pull request.
218
+
219
+ **The publish job** runs after the build job passed. It has `contents: read` and `id-token: write`,
220
+ and does not check out the repository or install anything: no code of the package or of its
221
+ dependencies runs where the identity token is. Its steps:
222
+
223
+ | Step | Fails when |
224
+ | --- | --- |
225
+ | Download the tarball | The artifact `package` of this run is missing, or its digest does not match what was uploaded. |
226
+ | Check the tarball is the one the build job checked | Its SHA-256 is not the one the build job computed. |
227
+ | Check this npm can stage | The npm of Node 24 is older than 11.15.0, which has no `npm stage`. |
171
228
  | Check that this job can identify itself to npm | The job has no identity token: "No identity token for this job. The workflow needs the id-token write permission." |
172
- | `npm stage publish --provenance --access public --loglevel verbose` | npm does not accept the job's identity for this package, or the trusted publisher does not allow staging (see below). The version is staged, not public, until a maintainer approves it. |
229
+ | `npm stage publish ./release/llm-large-files-<version>.tgz --provenance --access public --loglevel verbose` | npm does not accept the job's identity for this package, or the trusted publisher does not allow staging (see below). The version is staged, not public, until a maintainer approves it. |
230
+
231
+ `npm stage publish` takes a package spec as `npm publish` does, a tarball included (`npm help
232
+ stage`; it shares the code of `npm publish`). Given a tarball, npm stages those bytes as they are,
233
+ and runs no script of the package: `prepublishOnly` runs only when npm publishes a folder. So the
234
+ version on npm is the tarball that the build job checked, byte for byte. The path starts with `./`:
235
+ without it npm reads `release/llm-large-files-0.6.0.tgz` as a GitHub repository.
173
236
 
174
- When a step before the publish fails, nothing was published. Fix the cause on `main` with a pull
175
- request, delete the tag (`git tag -d v0.6.0`, then `git push origin :refs/tags/v0.6.0`), and tag
176
- the fixed commit.
237
+ When the build job fails, nothing was staged. Fix the cause on `main` with a pull request, delete
238
+ the tag (`git tag -d v0.6.0`, then `git push origin :refs/tags/v0.6.0`), and tag the fixed commit.
177
239
 
178
240
  ### Trusted publishing
179
241
 
@@ -202,7 +264,76 @@ that built it. npm can make one only inside a supported CI job, so a version pub
202
264
  none. npm checks the trusted publisher only at publish time, and says why it refused an identity
203
265
  only in the verbose log: that is why the step runs with `--loglevel verbose`.
204
266
 
205
- ## When the publish step fails
267
+ ## A dry run of the release workflow
268
+
269
+ The release workflow also runs by hand, from the Actions tab (Release, then Run workflow) or with
270
+ `gh`, on any branch or tag. Its one input, `dry_run`, is on by default. GitHub offers the run only
271
+ when the release.yml of the default branch, `main`, has the `workflow_dispatch` trigger; the run
272
+ then uses the release.yml of the branch or tag it runs on. So the release that adds the trigger
273
+ (0.10.0) cannot be dry-run on its branch before it merges: see
274
+ [The first run of a changed workflow](#the-first-run-of-a-changed-workflow).
275
+
276
+ ```bash
277
+ gh workflow run release.yml --ref release/0.6.0 # a dry run
278
+ gh run list --workflow release.yml --limit 1
279
+ gh run watch <run-id>
280
+ ```
281
+
282
+ With `dry_run` on, the build job runs as for a release, without the tag check on a branch: the
283
+ checks, the tarball, the tarball check, the artifact `package`. Then the `publish-dry` job runs in
284
+ place of the publish job. It has `contents: read` and no identity token, so nothing in it can reach
285
+ npm as the package. Its steps:
286
+
287
+ | Step | Fails when |
288
+ | --- | --- |
289
+ | Download the tarball | As in the publish job. |
290
+ | Check the tarball is the one the build job checked | As in the publish job. |
291
+ | Check this npm can stage | As in the publish job. |
292
+ | Check that this job has no identity token | The job has one: its permissions grant `id-token`. |
293
+ | `npm publish ./release/llm-large-files-<version>.tgz --access public --dry-run` | npm cannot read the tarball, or refuses the version. npm prints what it would publish (the files, the version, the shasum) and sends nothing. |
294
+
295
+ Run it on the release branch, after the version bump of [At release](#at-release): there the
296
+ version is not on npm yet. On `main` between releases, package.json names a version npm already
297
+ has, and npm may refuse the dry run for it.
298
+
299
+ With `dry_run` off, the run stages the version as a pushed tag does, and only on a tag: on a branch
300
+ the build job stops at its first check. Use it to run the release of a pushed tag again, instead of
301
+ deleting and pushing the tag.
302
+
303
+ ### The first run of a changed workflow
304
+
305
+ A change to release.yml is tried in a dry run before a tag depends on it. A change that is wrong
306
+ there costs a deleted tag and a new pull request; in a dry run, nothing.
307
+
308
+ 1. The pull request that changes the workflow passed CI.
309
+ 2. Run the workflow by hand with `dry_run` on. When the release.yml of `main` already has the
310
+ `workflow_dispatch` trigger, run it on the release branch (or the branch of that pull request):
311
+ the run uses that branch's release.yml. When it does not, because this change adds the trigger,
312
+ GitHub refuses a run on any ref (`gh workflow run release.yml --ref release/0.10.0` fails). Then
313
+ either merge the release.yml change to `main` in a pull request of its own first, and run the
314
+ dry run on the release branch; or merge the release pull request, run the dry run on `main`
315
+ before you tag (the version is not on npm yet, so npm takes the dry run), and tag only once it
316
+ passed.
317
+ 3. In the build job: `npm ci --ignore-scripts`, `npm run check`, Pack and the tarball check passed;
318
+ the tag check was skipped (on a branch); Pack printed the npm shasum, the integrity and the
319
+ SHA-256.
320
+ 4. The run has the artifact `package`, with one tarball named for the version of package.json.
321
+ 5. In `publish-dry`: the SHA-256 check, the npm version check and the identity-token check passed,
322
+ and `npm publish --dry-run` listed the files of `files` in package.json and ended with
323
+ `+ llm-large-files@<version>`, without publishing.
324
+ 6. The publish job was skipped.
325
+ 7. Each `uses:` the change added is pinned by a full commit SHA, with its tag in a comment (ci.yml
326
+ says how to find it).
327
+ 8. The publish job still checks out nothing and installs nothing, and has `contents: read` and
328
+ `id-token: write` only: no code of the repository or of a dependency runs where the identity
329
+ token is.
330
+ 9. Merge (unless step 2 merged already), and tag as in [Releasing a version](#releasing-a-version). Watch the first tagged run to
331
+ its end (step 6 there): the dry run cannot try trusted publishing itself.
332
+
333
+ ## When the publish job fails
334
+
335
+ The build job passed, so the tagged commit is good and the checked tarball is kept as the artifact
336
+ `package` of the run, for 7 days. Find why npm refused in the verbose log of the publish step.
206
337
 
207
338
  **`403 Forbidden … OIDC permission denied for this action`.** npm accepted the job's identity
208
339
  (`npm verbose oidc Successfully retrieved and set token`) but the trusted publisher does not allow
@@ -221,41 +352,57 @@ npm error 404 Not Found - PUT https://registry.npmjs.org/llm-large-files - Not f
221
352
  ```
222
353
 
223
354
  npm did not accept the job's identity for this package: the trusted publisher on npmjs.com is
224
- missing, or does not match the values above. Every step before the publish passed, so the tagged
225
- commit is good. There are two ways to finish the release.
355
+ missing, or does not match the values above. There are two ways to finish the release.
226
356
 
227
- **Fix trusted publishing, then run the job again.** Correct the setting on npmjs.com (this needs an
228
- npm account that may publish the package), then `gh run rerun <run-id> --failed`. The version is
229
- published with provenance. This works only while the version is not on npm yet.
357
+ **Fix trusted publishing, then run the publish job again.** Correct the setting on npmjs.com (this
358
+ needs an npm account that may publish the package), then `gh run rerun <run-id> --failed`. Only the
359
+ failed job runs again: it stages the same tarball, from the artifact, with provenance. This works
360
+ while the artifact is kept and the version is not on npm yet. After 7 days, run the whole workflow
361
+ again (`gh run rerun <run-id>`): its build job builds and checks a new tarball of the same commit.
230
362
 
231
- **Publish by hand from a clean checkout of the tag:**
363
+ **Publish by hand the tarball the build job checked:**
232
364
 
233
365
  ```bash
234
- git clone --depth 1 --branch v0.6.0 https://github.com/renanbazinin/llm-large-files.git release-v0.6.0
235
- cd release-v0.6.0
236
- npm ci
366
+ gh run download <run-id> --name package --dir release-v0.6.0
367
+ sha256sum release-v0.6.0/llm-large-files-0.6.0.tgz # the SHA-256 the Pack step printed
237
368
  npm whoami # an npm account that may publish the package; run npm login if not
238
- npm publish --access public
369
+ npm publish ./release-v0.6.0/llm-large-files-0.6.0.tgz --access public
239
370
  ```
240
371
 
241
- - Use a clean checkout, not your working copy. `files` publishes everything under `dist/`, `src/`
242
- and `docs/`, so an untracked or changed file there would go to npm too. The checkout also makes
243
- sure the version is exactly the tag's.
244
- - `prepublishOnly` runs `npm run check` first; its build deletes `dist/` and builds it again.
372
+ - The tarball is the one the build job checked, so nothing is built again: npm runs no script of
373
+ the package when it publishes a tarball. Keep the `./`: npm reads `release-v0.6.0/…` as a GitHub
374
+ repository without it.
245
375
  - npm asks for the account's two-factor approval: it prints
246
376
  `Authenticate your account at: https://www.npmjs.com/auth/cli/…` (or asks for a one-time code).
247
377
  Open the link, on any device, and approve. npm waits only a few minutes (about five in past
248
378
  releases) and then gives up, so the person who approves must be there before you run it.
249
379
  - Leave out `--provenance`: it works only inside a supported CI job.
250
- - Before it publishes, npm prints `npm notice shasum:` for the package. The failed job's log has
251
- the same line. When the two match, npm got the same build that CI checked; for 0.5.0 they
252
- matched.
380
+ - Before it publishes, npm prints `npm notice shasum:` for the package. The Pack step of the build
381
+ job printed the same `npm shasum:`. When the two match, npm got the tarball that CI checked. (For
382
+ 0.5.0, published by hand from a checkout, the shasum matched that of the failed job.)
383
+
384
+ When the artifact is gone (after 7 days), publish from a clean checkout of the tag, and check its
385
+ tarball first:
386
+
387
+ ```bash
388
+ git clone --depth 1 --branch v0.6.0 https://github.com/renanbazinin/llm-large-files.git release-v0.6.0
389
+ cd release-v0.6.0
390
+ npm ci --ignore-scripts
391
+ npm run check
392
+ npm pack
393
+ node scripts/check-tarball.mjs llm-large-files-0.6.0.tgz
394
+ npm publish ./llm-large-files-0.6.0.tgz --access public
395
+ ```
396
+
397
+ Use a clean checkout, not your working copy. `files` publishes everything under `dist/`, `src/` and
398
+ `docs/`, so an untracked or changed file there would go to npm too. The checkout also makes sure the
399
+ version is exactly the tag's.
253
400
 
254
401
  ## Checking a release
255
402
 
256
403
  ```bash
257
404
  npm view llm-large-files version # the latest version
258
- npm view llm-large-files@0.6.0 dist.shasum
405
+ npm view llm-large-files@0.6.0 dist.shasum # the npm shasum the Pack step of the build job printed
259
406
  ```
260
407
 
261
408
  After npm prints `+ llm-large-files@0.6.0`, the registry can take several minutes to list the
@@ -293,8 +440,9 @@ Versions follow [semantic versioning](https://semver.org). While the version is
293
440
 
294
441
  These are public, and a change to them can need a change in someone's code:
295
442
 
296
- - Everything exported from the five entry points (`llm-large-files`, `llm-large-files/gemini`,
297
- `llm-large-files/openai`, `llm-large-files/anthropic`, `llm-large-files/node`): names,
443
+ - Everything exported from the six entry points (`llm-large-files`, `llm-large-files/gemini`,
444
+ `llm-large-files/openai`, `llm-large-files/anthropic`, `llm-large-files/node`,
445
+ `llm-large-files/testing`): names,
298
446
  signatures, options and their defaults. That includes the types an app implements:
299
447
  `ModelAdapter`, `DocumentStore` and `Extractor`. A new required member or argument breaks every
300
448
  adapter, store or extractor written for the previous version, so make new members optional.
@@ -305,5 +453,5 @@ These are public, and a change to them can need a change in someone's code:
305
453
  - The routes, requests, responses and statuses of the HTTP handlers in `llm-large-files/node`.
306
454
  - What a store already holds: a new version reads documents an older one stored. (0.4.0 gave
307
455
  documents stored by older versions their line index the first time they were used.)
308
- - The supported Node versions (`engines`: 20.19 or later) and the version ranges of the optional
456
+ - The supported Node versions (`engines`: 22.12 or later) and the version ranges of the optional
309
457
  peers `jszip`, `unpdf` and `@cantoo/pdf-lib`.
@@ -148,11 +148,14 @@ or not: the explorer's requests too. Each piece of text goes to `onText` as it a
148
148
  `outputTokens` is `output_tokens`; `thoughtTokens` stays 0, as the adapter reads no count of
149
149
  thinking apart. With fallbacks, the attempts in `usage.iterations` are added up. `providerUsage`
150
150
  is the API's `usage` as it came; in a stream, that of `message_start` updated by `message_delta`.
151
+ - `responseId` and `responseModel` are the message's `id` and `model` (in a stream, those of
152
+ `message_start`), when the API gives them. New in 0.10.0.
151
153
 
152
154
  **Part reads** (`generateText`, for `analyze_whole_document`) go to the same URL with the same
153
155
  headers and are never streamed. The body is `model`, `max_tokens` (the limit of that read),
154
156
  `system`, one user message, then the fields of `analysisBody(limit)`: no `body`, no
155
- `cache_control`, no `fallbacks`, no tools. Each request may take `timeoutMs` (180 s). A reply that
157
+ `cache_control`, no `fallbacks`, no tools. Each request may take `timeoutMs` (180 s; 0 for none,
158
+ since 0.10.0). A reply that
156
159
  stopped for `refusal` or `model_context_window_exceeded` is kept and marked incomplete, as one cut
157
160
  off at its limit is. A reply cut off with nothing written, or with half its limit or more spent
158
161
  thinking, while the limit was below 32,768, is asked again with 32,768 output tokens
@@ -182,11 +185,13 @@ turns the larger limit off only when the window it names is 32,768 tokens or les
182
185
 
183
186
  A part read throws as `send` does for an HTTP error, a connection that failed, an empty body, an
184
187
  abort and a body that is not JSON. It has no waits of `firstByteTimeoutMs` and `idleTimeoutMs`;
185
- instead, a request that ran past `timeoutMs` throws the error of its abort (a `TimeoutError`). A
186
- reply with no text throws `Error("The model returned no text (refusal).")`, the reason in brackets
187
- being `stop_reason`. These two have no `status`. In a whole-file read, the model is told why a part
188
- failed by the error's kind and status, never by the API's message: "The model took too long to
189
- answer." for the `TimeoutError`, "The model returned no text (refusal)." for a reply with no text
188
+ instead, a request that ran past `timeoutMs` throws an `AnthropicRequestError` "Claude took longer
189
+ than 180 s to answer.", status 0, kind `"timeout"` (since 0.10.0; before, the error of its abort, a
190
+ `TimeoutError` with no status), which a whole-file read sends again once. A reply with no text
191
+ throws `Error("The model returned no text (refusal).")`, the reason in brackets being
192
+ `stop_reason`; it has no `status`. In a whole-file read, the model is told why a part failed by the
193
+ error's kind and status, never by the API's message: "The model took too long to answer." for a
194
+ timeout, "The model returned no text (refusal)." for a reply with no text
190
195
  (see [`analyze_whole_document`](./tools.md#analyze_whole_document)).
191
196
 
192
197
  ```ts
@@ -271,7 +276,7 @@ The options of [`anthropic()`](#anthropicoptions).
271
276
  | `maxRequestBytes` | `number` | `32_000_000` | The largest request body in bytes, the limit of the Claude API (32 MB). It keeps the budget within it. |
272
277
  | `pageTokens` | `number` | `3_500` | Tokens billed for one PDF page shown by `view_pages`: its text and its picture. The loop sizes the pages a question may look at from it. |
273
278
  | `tokenScale` | `number` | `1.35` | Claude's tokens for one token of the library's estimate, which is fitted to Gemini: documents are planned for a window that much smaller. 1.35 is a cautious guess for the tokenizer of the current models; during a question, the token count the API reports with each reply corrects the estimate. |
274
- | `timeoutMs` | `number` | `180_000` | The longest a part read's request may take, in milliseconds, each try counted apart. A request that runs longer is aborted. Not used for chat requests. |
279
+ | `timeoutMs` | `number` | `180_000` | The longest a part read's request may take, in milliseconds, each try counted apart. A request that runs longer is aborted, and is an `AnthropicRequestError` of kind `"timeout"` and status 0 (since 0.10.0). 0 sets no limit (since 0.10.0; before, it aborted every part read at once). Not used for chat requests. |
275
280
  | `firstByteTimeoutMs` | `number` | `600_000` | The longest wait, in milliseconds, for the first piece of a chat reply. Headers do not count: a model that thinks sends nothing until it has thought, and a reply that is not streamed comes whole at the end. A request that gets nothing for that long is aborted with an `AnthropicRequestError` (`status` 0, `kind` `"timeout"`), which `askWithFiles` sends again once. 0, a negative or a non-finite number waits without end. The key, token and headers are resolved before the wait starts. Not used for part reads. |
276
281
  | `idleTimeoutMs` | `number` | `300_000` | The longest wait, in milliseconds, between two pieces of a chat reply once it has started to arrive. Any bytes count, Claude's `ping` events included. The same error; `askWithFiles` sends the request again once, unless text of it was shown. 0 waits without end. Not used for part reads. |
277
282
  | `id` | `string` | `model` | The name of the model in `usage.byModel` and in messages. |