# Changelog

All notable changes to `@absolutejs/ai`.

This file is generated by `absolute-changelog` from the entries in
`changelog/`. Edit an entry, not this file — and add new ones under
`changelog/unreleased/`.

## 0.7.0 — 2026-11-03

### Breaking

- **codeExecutionTool and codeModeTool refuse to run model-written code on a Worker isolate that is not locked down** (`codeExecutionTool`, `codeModeTool`, `CodeExecutionToolOptions`, `CodeModeToolOptions`)
  Both tools take a new `requireLockdown` option, default `true`. On the Worker backend, stock Bun lets sandboxed code reach the `Bun` global through indirect eval and load any module with `import()`, so model-written code could spawn processes or read files. isolated-jsc 0.13 locks Worker isolates down on AbsoluteJS patched Bun 1.4.4+absolute.2 and later, and these tools now insist on it: on stock Bun without libJavaScriptCore a run fails with `LockdownUnavailableError` instead of running escapable code. The FFI backend is unaffected. The `@absolutejs/isolated-jsc` peer range is now `>=0.13.0`, since older versions ignore the option.
  _Migration:_ Run on AbsoluteJS patched Bun 1.4.4+absolute.2 or later (the AbsoluteJS CLI installs it), or install libJavaScriptCore so the FFI backend is used, and upgrade @absolutejs/isolated-jsc to 0.13 or later. To keep the old behavior for code you trust, pass `requireLockdown: false`.

## 0.6.10 — 2026-10-28

### Fixed

- **Stop cancelled tool workflows before another provider request, including forced final synthesis; expose completed non-streaming turns for graceful between-request cancellation and usage observation.** (`generateAIWithTools`, `streamAIWithTools`, `GenerateAIWithToolsOptions`)

## 0.6.9 — 2026-10-28

### Added

- **Provide cancellable per-request provider deadlines that exclude host tool execution and preserve provider capabilities and usage chunks.** (`withProviderRequestTimeout`)

### Fixed

- **Document awaiting sandbox host functions so code execution works across both worker and FFI backends.** (`codeExecutionTool`)

## 0.6.8 — 2026-10-23

### Added

- **Separate compact model-facing tool results from complete UI and audit output across all agent loops** (`toolOutputModelText`, `AIToolResult`)

## 0.6.7 — 2026-10-22

### Fixed

- **Retain the requested model when validating legacy document checkpoints after provider recovery**

## 0.6.6 — 2026-10-22

### Changed

- **Recover approved providers in either direction across preparation and streaming; preserve checkpoints, normalize finite-key OpenAI schemas, and clear cancelled billing probes** (`AIInputError`, `PrepareAITextInputOptions`, `AIContextPolicy`, `streamWithProviderFallback`)

## 0.6.5 — 2026-10-22

### Changed

- **Preserve Sync 3 peer compatibility alongside provider recovery**

## 0.6.4 — 2026-10-22

### Added

- **Stream approved fallback models before output or tool execution** (`streamWithProviderFallback`)

### Changed

- **Expose provider billing rejection and credential-scoped suppression** (`ProviderError`, `ProviderErrorInit`)

## 0.6.3 — 2026-10-22

### Changed

- **Accepts @absolutejs/sync 3**
  The `@absolutejs/sync` peer range stopped below 3, so an app on sync 3 (built against Elysia 2.0.0-rc.0) installed a second copy for ai. sync 3.0.0 changed no API, so the range now runs from 2.14.0 below 4.

## 0.6.2 — 2026-10-22

### Added

- **Add stopAfterToolTurn to complete sibling tool actions before a UI handoff and retain error recovery without an unnecessary model turn** (`streamAIWithTools`, `StreamAIWithToolsOptions`)
- **Support current Sonnet 5.5, Haiku 5.5, GPT-6.1 Sol and GPT-6 Luna reasoning and input capacity** (`MODEL_REASONING`, `openaiResponses`, `anthropic`)

## 0.6.1 — 2026-10-20

### Added

- **Add typed forms and shared task next actions for top-up continuation** (`FormField`, `formCard`, `parseFormSpec`, `prepareFormSubmission`, `FormSubmission`, `BackgroundWorkCard`, `backgroundWorkNextAction`)

## 0.6.0 — 2026-10-20

### Added

- **Load tools on demand (deferLoading, through Anthropic tool search) and clear old tool results past a threshold (toolResultClearing); both cross the provider proxy** (`AIToolResultClearing`, `AIToolDefinition`, `AIProviderToolDefinition`, `AIProviderStreamParams`, `StreamAIOptions`)

## 0.5.0 — 2026-10-19

### Breaking

- **AIToolDefinition.handler may return { text, images } as well as a string** (`AIToolDefinition`, `toolOutputText`)
  _Migration:_ Code that calls a tool's handler itself (a wrapper, a test) now receives AIToolOutput, a string or { text, images }. Read its text with toolOutputText(output). Handlers that return a string need no change.

### Added

- **Tools can return images for the model to see, such as a screenshot: a handler returns { text, images } and the tool loops send the images inside the tool result, mapped for Anthropic, OpenAI Responses, OpenAI Chat Completions, Gemini and Ollama** (`AIToolResult`, `AIToolOutput`, `toolOutputText`, `AIProviderContentBlock`, `anthropic`, `openai`, `openaiResponses`, `gemini`, `ollama`, `streamAIToSSE`, `streamAIWithTools`, `generateAIWithTools`, `hardenUntrustedTool`, `createAIStoredToolResultRecovery`)

## 0.4.1 — 2026-10-17

### Fixed

- **Preserve provider usage snapshots through stream interruptions, distinguish partial from final usage, and retain tool-input start events without application patches** (`AIUsageUpdateChunk`, `anthropic`, `openai`, `openaiResponses`, `AIChunk`, `StreamAIWithToolsEvent`, `AIToolInputStartChunk`)

## 0.4.0 — 2026-10-16

### Added

- **Report a tool call's input while it streams: a `tool_input` chunk, and a `preparing` tools event from streamAIToSSE** (`AIChunk`, `AIToolInputChunk`, `streamAIToSSE`)
  A tool call with a long input, such as a whole file, takes the model a minute or more to write, and until now nothing arrived meanwhile. The Anthropic provider now yields a `tool_input` chunk when a tool call starts and every 2 KB of its input, with the tool name, the characters received and the top-level string fields already complete (a path, a name; at most 200 characters each, never read from inside other values). With structured events, streamAIToSSE turns it into a `tools` event with status `preparing`. Consumers that do not know the chunk can ignore it.

### Fixed

- **streamAIToSSE sends a turn's text back as one block, not one per streamed delta, so agent loops stop re-writing their prompt cache** (`streamAIToSSE`)
  streamAIToSSE stored every streamed text delta as its own content block, so an agent loop sent each turn's text back as dozens of blocks. Anthropic looks back only 20 blocks for an earlier cache entry, and a turn with a few sentences of text pushed the previous request's entry out of reach: the next request re-wrote the whole history at the cache-write price. A run of text is now one block, as generateAI and streamAIWithTools already kept it.

## 0.3.4 — 2026-10-15

### Fixed

- **Keep a prompt-cache breakpoint on the previous turn's user message as well as the last message, so an agent loop's next request reads its cached history by exact position instead of re-writing it; a production Studio build re-wrote its whole history on 7 of 48 requests and those writes were about half its cost.** (`anthropic`)

## 0.3.3 — 2026-10-10

### Fixed

- **Preserve complete choice-card questions, labels and descriptions within explicit schema limits; reject oversized choices instead of silently clipping text or dropping alternatives. Validate all UI card tool inputs before acknowledging success, returning UiCardValidationError so streaming and non-streaming tool loops can request a repair.** (`parseChoiceSpec`, `choiceCard`, `createUiCards`, `UiCardValidationError`, `CHOICE_TITLE_MAX_CHARS`, `CHOICE_LABEL_MAX_CHARS`, `CHOICE_DESCRIPTION_MAX_CHARS`, `UiCardDefinition`)

## 0.3.2 — 2026-10-01

### Fixed

- **Give structured-output repair bounded field diagnostics for TypeBox and Zod validation failures; expose StructuredOutputError with attempts, cause and accumulated usage when repair is exhausted.** (`generateObjectAI`, `StructuredOutputError`)

## 0.3.1 — 2026-09-29

### Fixed

- **OpenAI Responses: reasoning models (GPT-5/6, o-series) no longer receive temperature or top_p, which they reject; function tools are sent strict only when their schema is strict-compatible, so optional properties stay optional instead of being filled with placeholders; replayed tool calls drop their output item id, which made every reasoning-model conversation fail after its first tool round** (`openaiResponses`)

## 0.3.0 — 2026-09-28

### Added

- **Return generated images from the tool loops: generateAI and generateAIWithTools results carry finished images, and streamAIWithTools yields image events (previews and finished) with the finished ones in its summary** (`GenerateAIResult`, `GenerateAIWithToolsResult`, `StreamAIWithToolsEvent`, `StreamAIWithToolsSummary`)

### Fixed

- **OpenAI Responses: send image input as a plain image_url string, PDFs as flat input_file with file_data, and linked PDFs as file_url, which the API previously rejected** (`openaiResponses`)

## 0.2.11 — 2026-09-27

### Changed

- **Name capacity HTTP metadata providerStatus instead of status so application HTTP frameworks do not treat an upstream billing/auth 4xx as a caller error and skip server-error capture. Preserve provider diagnostics and request IDs. Supersedes 0.2.10.** (`AIInputError`, `inspectAIInput`)

## 0.2.10 — 2026-09-27

### Changed

- **Add optional HTTP status and request ID to AIInputError and preserve bounded provider failure reasons across capacity checks and bundled provider entry points, so billing and rate-limit failures remain diagnosable.** (`AIInputError`, `inspectAIInput`, `anthropic`, `gemini`, `openaiResponses`)

## 0.2.9 — 2026-09-25

### Added

- **Add model tiers and a shared `recommendModel` for automatic model choice (fast for quick questions and edits, frontier for deep analysis, balanced otherwise), and feature exactly one frontier model per provider** (`recommendModel`, `recommendTier`, `ModelTier`, `ModelDirectoryEntry`, `MODEL_DIRECTORY`)

## 0.2.8 — 2026-09-25

### Added

- **Add a shared model directory for pickers (names, descriptions, featured and legacy flags) with `listModels`, and refresh Anthropic metadata from the Models API: add Claude Opus 5.5, Fable 5, Opus 4.8, Opus 4.7, Opus 4.5 and Sonnet 4.5, record 1M context for Opus 4.6 and Sonnet 4.6, and add their reasoning effort levels** (`MODEL_DIRECTORY`, `MODEL_PROVIDERS`, `listModels`, `findModel`, `modelKey`, `ListedModel`, `ModelDirectoryEntry`, `MODEL_METADATA`, `MODEL_REASONING`)

## 0.2.7 — 2026-09-24

### Added

- **Add injected evidence research orchestration and per-request transport retry limits for host-owned accounting** (`GenerateAIOptions`, `GenerateObjectAIOptions`, `AIProviderStreamParams`)

## 0.2.6 — 2026-09-20

### Fixed

- **Count supported Anthropic caller input when hosted tools cannot be pre-counted, preserving full generation requests and exposing honest count scope** (`anthropic`, `inspectAIInput`, `AIInputCapacity`, `AIProviderConfig`, `createAIProviderRouter`)

## 0.2.5 — 2026-09-20

### Fixed

- **Allow SSE tool loops to reread changed files without silently completing; retain turn, time and token limits** (`streamAIToSSE`)

## 0.2.4 — 2026-09-20

### Added

- **Add reviewed per-model reasoning controls, provider translations, and compatible thinking stream replay.** (`MODEL_REASONING`, `REASONING_EFFORTS`, `getModelReasoning`, `isReasoningSelection`, `supportsReasoningSelection`, `reasoningSelectionLabel`, `ModelReasoning`, `ReasoningSelection`, `ReasoningEffort`)

## 0.2.3 — 2026-09-20

### Internal

- **Republish the capability catalog using npm packaging after the 0.2.2 registry artifact remained unavailable**

## 0.2.2 — 2026-09-20

### Added

- **Add browser-safe typed model capability metadata with verified provider sources, separate input and output modalities, context windows, and capability descriptions** (`ModelModality`, `ModelFeature`, `ModelMetadata`, `ModelCapability`, `MODEL_CAPABILITY_DESCRIPTIONS`, `MODEL_METADATA`, `modelCapabilities`, `getModelMetadata`)

## 0.2.1 — 2026-09-16

### Fixed

- **Preserve provider output reservations and context-error recognition when routing models** (`createAIProviderRouter`)

## 0.2.0 — 2026-09-16

### Added

- **Expose each tool-loop turn response metadata so consumers can price the actual served processing tier** (`streamAIWithTools`, `StreamAIWithToolsEvent`)
- **Route exact model IDs to the same provider for token counting, capacity checks, preparation and generation** (`createAIProviderRouter`)

## 0.1.3 — 2026-09-16

### Fixed

- **Exclude OpenAI cache-write tokens from ordinary input so cache-aware billing never charges the same tokens twice** (`openai`, `openaiResponses`)

## 0.1.2 — 2026-09-16

### Fixed

- **Preserve every parallel OpenAI tool result and subsequent conversation turn without overwriting expanded messages** (`openai`)

## 0.1.1 — 2026-09-16

### Added

- **Allow a separate preparation model with its own verified capacity while preserving the final answer model and invalidating notes when the preparation model changes** (`PrepareAITextInputOptions`, `prepareAITextInput`, `prepareAITextInputStep`)

### Fixed

- **Fill preparation sections with bounded tokenizer-checked refinement, avoid duplicate final counting, and honor cancellation before generation** (`prepareAITextInput`, `prepareAITextInputStep`)

## 0.1.0 — 2026-09-16

### Added

- **Add one-section text preparation steps for durable workers, with explicit pending/ready outcomes and checkpoint persistence before yielding** (`prepareAITextInputStep`, `AITextPreparationStep`)
- **Budget final retrieval instructions and tools before compacting text, with matching checkpoint invalidation** (`PrepareAITextInputOptions`, `prepareAITextInput`)

### Changed

- **Validate model capacity by default across generation, structured output, WebSocket and SSE entry points; reserve token headroom and support one protocol-preserving context recovery attempt. Providers without counting capability now fail explicitly; contextPolicy: false opts into raw behavior.** (`generateAI`, `generateAIWithTools`, `generateObjectAI`, `streamAI`, `streamAIToSSE`, `streamAIWithTools`, `inspectAIContext`, `createAIStoredToolResultRecovery`, `StreamAIWithToolsOptions`, `GenerateAIOptions`, `GenerateAIResult`, `GenerateObjectAIOptions`, `AIProviderConfig`, `StreamAIOptions`, `AIChatPluginConfig`)

### Fixed

- **Preserve conversation origin across long-text preparation sections, distinguish source facts from embedded instructions, reserve more of the available context for factual notes, and invalidate checkpoints from the previous preparation policy** (`prepareAITextInput`, `prepareAITextInputStep`)

## 0.0.58 — 2026-09-15

### Added

- **Keep compacted text useful with read-only original-source search, checkpointed ingestion, and capacity-checked terminal tool loops** (`createAITextSource`, `prepareAITextInput`, `PrepareAITextInputOptions`, `streamAIWithTools`, `StreamAIWithToolsOptions`)

## 0.0.57 — 2026-09-15

### Added

- **Add model-specific token capacity, optional provider capacity configuration, and recoverable long-text preparation** (`inspectAIInput`, `prepareAITextInput`, `AIProviderConfig`, `OpenAIConfig`, `OpenAIResponsesConfig`)

### Internal

- **Regenerate the OpenRouter client declaration with equivalent reordered response union types** (`createOpenRouterClient`)
