Skip to content

Commit d347c85

Browse files
authored
Merge branch 'main' into fix/cjs-output-and-json-response
2 parents 43e59bb + d6a2588 commit d347c85

251 files changed

Lines changed: 14946 additions & 940 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@tanstack/ai-isolate-cloudflare': patch
3+
---
4+
5+
fix(ai-isolate-cloudflare): accumulate `toolResults` across rounds in the driver round-trip
6+
7+
The Cloudflare isolate driver was wiping `toolResults` between rounds. `wrap-code` uses sequential `tc_<idx>` ids that are re-derived every round when the Worker re-executes user code, so prior-round results must remain in the cache. With the wipe, multi-tool programs (e.g. `await A(); await B();`) would ping-pong between `{tc_0}` and `{tc_1}` and exhaust `maxToolRounds`, surfacing as `MaxRoundsExceeded`.
8+
9+
Single-tool code worked because only one cache entry was ever needed in a given round. Existing tests covered single-round flows only and did not exercise real `wrap-code` ids end-to-end, so the regression slipped through.
10+
11+
Added a `tc_<idx>`-shaped regression test that fails on the prior implementation and passes with the merge.

.changeset/audio-activity.md

Lines changed: 0 additions & 12 deletions
This file was deleted.

.changeset/audio-example-pages.md

Lines changed: 0 additions & 15 deletions
This file was deleted.

.changeset/audio-generation-hook.md

Lines changed: 0 additions & 24 deletions
This file was deleted.

.changeset/fal-audio-speech-transcription.md

Lines changed: 0 additions & 11 deletions
This file was deleted.

.changeset/gemini-audio.md

Lines changed: 0 additions & 14 deletions
This file was deleted.

.changeset/generated-media-union.md

Lines changed: 0 additions & 20 deletions
This file was deleted.

.changeset/otel-middleware.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@tanstack/ai': minor
3+
---
4+
5+
**OpenTelemetry middleware.** `otelMiddleware({ tracer, meter?, captureContent?, redact?, ... })` emits GenAI-semantic-convention traces and metrics for every `chat()` call.
6+
7+
- Root span per `chat()` + child span per agent-loop iteration (named `chat <model> #<iteration>`) + grandchild span per tool call.
8+
- `gen_ai.client.operation.duration` (seconds) recorded **once per `chat()` call**; `gen_ai.client.token.usage` (tokens) recorded **per iteration** (one input + one output record). Metric attributes are kept low-cardinality — `gen_ai.response.model` and `gen_ai.response.id` are intentionally excluded.
9+
- `captureContent: true` attaches prompt/completion content as `gen_ai.{user,system,assistant,tool}.message` and `gen_ai.choice` span events. Redactor failures fail closed to a `"[redaction_failed]"` sentinel — raw content never leaks. Assistant text is capped at `maxContentLength` (default 100 000).
10+
- Four extension points for custom attributes, names, span-options, and end-of-span callbacks. Thrown callbacks are caught and logged to `console.warn` with a label so failures remain diagnosable.
11+
- `@opentelemetry/api` is an optional peer dependency. The middleware is exported from the dedicated subpath `@tanstack/ai/middlewares/otel` so that importing `@tanstack/ai/middlewares` does not eagerly require OTel.
12+
13+
See `docs/advanced/otel.md` for the full guide.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
'@tanstack/ai': minor
3+
'@tanstack/ai-anthropic': patch
4+
'@tanstack/ai-client': minor
5+
---
6+
7+
**Fix thinking blocks getting merged across steps and lost on turn 2+ of Anthropic tool loops.**
8+
9+
Each thinking step emitted by the adapter now produces its own `ThinkingPart` on the `UIMessage` instead of being merged into a single part, and thinking content + Anthropic signatures are preserved in server-side message history so multi-turn tool flows with extended thinking work correctly.
10+
11+
This includes a public callback signature change: `StreamProcessorEvents.onThinkingUpdate` now receives `(messageId, stepId, content)` instead of `(messageId, content)`. `ChatClient` has been updated to handle the new `stepId` argument internally, but consumers implementing `StreamProcessorEvents` directly need to add the new parameter.
12+
13+
`@tanstack/ai`:
14+
15+
- `ThinkingPart` gains optional `stepId` and `signature` fields.
16+
- `ModelMessage` gains an optional `thinking?: Array<{ content; signature? }>` field so prior thinking can be replayed in subsequent turns.
17+
- `StepFinishedEvent` gains an optional `signature` field for provider-supplied thinking signatures.
18+
- `StreamProcessor` tracks thinking per-step via `stepId` and keeps step ordering. `getState().thinking` / `getResult().thinking` concatenate step contents in order.
19+
- The `onThinkingUpdate` callback on `StreamProcessorEvents` now receives `(messageId, stepId, content)` — consumers implementing it directly must add the `stepId` parameter.
20+
- `TextEngine` accumulates thinking + signatures per iteration and includes them in assistant messages with tool calls so the next turn can replay them.
21+
22+
`@tanstack/ai-anthropic`:
23+
24+
- Captures `signature_delta` stream events and emits the final `STEP_FINISHED` with the signature on `content_block_stop`.
25+
- Includes thinking blocks with signatures in `formatMessages` for multi-turn history.
26+
- Passes `betas: ['interleaved-thinking-2025-05-14']` to the `beta.messages.create` call site when a thinking budget is configured. The beta flag is scoped to the streaming path only, so `structuredOutput` (which uses the non-beta `messages.create` endpoint) is unaffected.
27+
28+
`@tanstack/ai-client`:
29+
30+
- `ChatClient`'s internal `onThinkingUpdate` wiring is updated for the new `stepId` parameter.

.changeset/tricky-wings-sniff.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/ai-client': patch
3+
---
4+
5+
Fixes a race condition in ChatClient.streamResponse() where this.abortController.signal could reference a stale or null controller by the time it is passed to this.connection.connect()

0 commit comments

Comments
 (0)