@absolutejs/ai 0.0.56 → 0.0.58

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 ADDED
@@ -0,0 +1,23 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@absolutejs/ai`.
4
+
5
+ This file is generated by `absolute-changelog` from the entries in
6
+ `changelog/`. Edit an entry, not this file — and add new ones under
7
+ `changelog/unreleased/`.
8
+
9
+ ## 0.0.58 — 2026-09-15
10
+
11
+ ### Added
12
+
13
+ - **Keep compacted text useful with read-only original-source search, checkpointed ingestion, and capacity-checked terminal tool loops** (`createAITextSource`, `prepareAITextInput`, `PrepareAITextInputOptions`, `streamAIWithTools`, `StreamAIWithToolsOptions`)
14
+
15
+ ## 0.0.57 — 2026-09-15
16
+
17
+ ### Added
18
+
19
+ - **Add model-specific token capacity, optional provider capacity configuration, and recoverable long-text preparation** (`inspectAIInput`, `prepareAITextInput`, `AIProviderConfig`, `OpenAIConfig`, `OpenAIResponsesConfig`)
20
+
21
+ ### Internal
22
+
23
+ - **Regenerate the OpenRouter client declaration with equivalent reordered response union types** (`createOpenRouterClient`)
package/README.md CHANGED
@@ -329,3 +329,77 @@ Use `openrouterResponses(config)` when an AbsoluteJS agent should stream through
329
329
  OpenRouter's stateless Responses API, or `openrouterMessages(config)` for the
330
330
  native Anthropic Messages protocol. Both accept the same model/provider policies
331
331
  and `providerOptions.openrouter` controls, including replayable hosted-tool data.
332
+
333
+ ### Model capacity and long text
334
+
335
+ Use `inspectAIInput(provider, params)` to count the complete request, including
336
+ instructions and tools, and reserve room for the requested reply. The result
337
+ includes `inputTokens`, `availableInputTokens`, model `limits`, and `fits`.
338
+ There is no package-wide character limit or character-to-token estimate.
339
+
340
+ For text conversations, `prepareAITextInput(provider, params, options)` returns
341
+ `{ params, compacted, sectionsProcessed }`. Requests that fit pass through
342
+ unchanged. Oversized text is read in counted sections into rolling notes; the
343
+ final request is counted again before being returned. Summaries can lose detail,
344
+ so persist the original source first and retain it for download and resume.
345
+
346
+ ```ts
347
+ import { prepareAITextInput } from "@absolutejs/ai";
348
+
349
+ // Save original messages before preparation. This may make additional model calls.
350
+ const prepared = await prepareAITextInput(provider, params, {
351
+ onProgress: ({ processedCharacters, totalCharacters }) => {
352
+ reportProgress(processedCharacters, totalCharacters);
353
+ },
354
+ onUsage: (usage) => recordSectionUsage(usage),
355
+ });
356
+ for await (const chunk of provider.stream(prepared.params)) {
357
+ // Render the reply and record its usage as usual.
358
+ }
359
+ ```
360
+
361
+ Anthropic and Gemini retrieve native model metadata and count using their native
362
+ APIs. OpenAI uses its input-token counting API and an exact, documented model
363
+ catalog because its model-list API does not expose context limits. OpenAI
364
+ providers accept `modelLimits` for additional model IDs or compatible endpoints.
365
+ Unknown models/providers fail with `AIInputError` (`capacity_unavailable`) rather
366
+ than guessing. Custom providers can implement the optional `inputCapacity`
367
+ capability. Existing `stream` calls remain unchanged.
368
+
369
+ Automatic preparation supports text-only history. It rejects oversized tool or
370
+ multimodal histories rather than flattening them. Handle preparation errors in
371
+ the UI while preserving the original input; expose retry without clearing the
372
+ conversation. File upload/storage limits are application transport limits and
373
+ should be reported separately from model capacity.
374
+
375
+ #### Keep originals useful after compaction
376
+
377
+ `createAITextSource(messages)` builds a session-scoped, read-only source index.
378
+ Its `tools` map exposes `search_text_source` and `read_text_source` for use with
379
+ `streamAIWithTools`. Search returns bounded **verbatim** passages with stable
380
+ message IDs and character offsets; read can retrieve adjoining passages. This
381
+ is lexical search, so ask the model to try alternate terms and never treat no
382
+ matches as proof a fact is absent. Keep originals persisted and rebuild the
383
+ index on resume. The index performs no model calls or external network access.
384
+
385
+ Attach these tools when using compacted notes, and instruct the model to verify
386
+ numbers, dates, exceptions, and corrections in the originals before finalizing.
387
+ Never make the rolling summary the only accessible copy of a large document.
388
+
389
+ `prepareAITextInput` accepts a server-owned `checkpoint` and calls
390
+ `onCheckpoint` after each completed section. Store that checkpoint for retries;
391
+ its model/task and original-prefix fingerprints must match before it is reused.
392
+ Edited input or changed instructions invalidate it. Original text remains the
393
+ source of truth. Do not accept checkpoints or generated notes from a client.
394
+
395
+ `streamAIWithTools({ validateInput: true, ... })` checks every model request,
396
+ including accumulated tool results, before sending it. It also rejects streams
397
+ that end without a completion marker. `stopAfterTools: ["finish"]` stops after a
398
+ named tool succeeds, avoiding an extra generation or later tool side effects
399
+ when the application is ready to validate and persist a result.
400
+
401
+ For a bounded live regression against the intake model, set `ANTHROPIC_API_KEY`
402
+ and run `bun scripts/eval-text-source.ts`. It uses synthetic text, simulates a
403
+ small context, and verifies that original-source lookups recover later budget
404
+ and deadline corrections omitted from the notes. It makes real, billed model
405
+ calls; the ordinary test suite uses deterministic local providers instead.
package/changelog.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "contract": 1,
3
+ "name": "@absolutejs/ai",
4
+ "releases": [
5
+ {
6
+ "changes": [
7
+ {
8
+ "kind": "added",
9
+ "summary": "Keep compacted text useful with read-only original-source search, checkpointed ingestion, and capacity-checked terminal tool loops",
10
+ "symbols": [
11
+ "createAITextSource",
12
+ "prepareAITextInput",
13
+ "PrepareAITextInputOptions",
14
+ "streamAIWithTools",
15
+ "StreamAIWithToolsOptions"
16
+ ]
17
+ }
18
+ ],
19
+ "date": "2026-09-15",
20
+ "version": "0.0.58"
21
+ },
22
+ {
23
+ "changes": [
24
+ {
25
+ "kind": "internal",
26
+ "summary": "Regenerate the OpenRouter client declaration with equivalent reordered response union types",
27
+ "symbols": [
28
+ "createOpenRouterClient"
29
+ ]
30
+ },
31
+ {
32
+ "kind": "added",
33
+ "summary": "Add model-specific token capacity, optional provider capacity configuration, and recoverable long-text preparation",
34
+ "symbols": [
35
+ "inspectAIInput",
36
+ "prepareAITextInput",
37
+ "AIProviderConfig",
38
+ "OpenAIConfig",
39
+ "OpenAIResponsesConfig"
40
+ ]
41
+ }
42
+ ],
43
+ "date": "2026-09-15",
44
+ "version": "0.0.57"
45
+ }
46
+ ]
47
+ }