@tanstack/ai 0.53.0 → 0.55.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 (68) hide show
  1. package/README.md +14 -13
  2. package/dist/esm/activities/chat/index.js +22 -4
  3. package/dist/esm/activities/chat/index.js.map +1 -1
  4. package/dist/esm/activities/chat/messages.d.ts +21 -1
  5. package/dist/esm/activities/chat/messages.js +50 -1
  6. package/dist/esm/activities/chat/messages.js.map +1 -1
  7. package/dist/esm/activities/chat/stream/processor.d.ts +17 -0
  8. package/dist/esm/activities/chat/stream/processor.js +27 -0
  9. package/dist/esm/activities/chat/stream/processor.js.map +1 -1
  10. package/dist/esm/activities/generateLiveVideo/adapter.d.ts +69 -0
  11. package/dist/esm/activities/generateLiveVideo/adapter.js +23 -0
  12. package/dist/esm/activities/generateLiveVideo/adapter.js.map +1 -0
  13. package/dist/esm/activities/generateLiveVideo/index.d.ts +99 -0
  14. package/dist/esm/activities/generateLiveVideo/index.js +162 -0
  15. package/dist/esm/activities/generateLiveVideo/index.js.map +1 -0
  16. package/dist/esm/activities/generateVideo/index.js +3 -1
  17. package/dist/esm/activities/generateVideo/index.js.map +1 -1
  18. package/dist/esm/activities/generateWorld/adapter.d.ts +69 -0
  19. package/dist/esm/activities/generateWorld/adapter.js +23 -0
  20. package/dist/esm/activities/generateWorld/adapter.js.map +1 -0
  21. package/dist/esm/activities/generateWorld/index.d.ts +99 -0
  22. package/dist/esm/activities/generateWorld/index.js +162 -0
  23. package/dist/esm/activities/generateWorld/index.js.map +1 -0
  24. package/dist/esm/activities/index.d.ts +8 -2
  25. package/dist/esm/activities/index.js +11 -7
  26. package/dist/esm/activities/middleware/types.d.ts +1 -1
  27. package/dist/esm/client.d.ts +4 -2
  28. package/dist/esm/client.js +3 -1
  29. package/dist/esm/client.js.map +1 -1
  30. package/dist/esm/index.d.ts +4 -2
  31. package/dist/esm/index.js +3 -1
  32. package/dist/esm/middlewares/otel.js +3 -1
  33. package/dist/esm/middlewares/otel.js.map +1 -1
  34. package/dist/esm/types.d.ts +112 -0
  35. package/package.json +3 -3
  36. package/skills/ai-core/adapter-configuration/SKILL.md +91 -43
  37. package/skills/ai-core/adapter-configuration/references/anthropic-adapter.md +39 -21
  38. package/skills/ai-core/adapter-configuration/references/byteplus-adapter.md +5 -0
  39. package/skills/ai-core/adapter-configuration/references/gemini-adapter.md +14 -6
  40. package/skills/ai-core/adapter-configuration/references/grok-adapter.md +33 -25
  41. package/skills/ai-core/adapter-configuration/references/groq-adapter.md +7 -2
  42. package/skills/ai-core/adapter-configuration/references/ollama-adapter.md +25 -12
  43. package/skills/ai-core/adapter-configuration/references/openai-adapter.md +19 -9
  44. package/skills/ai-core/adapter-configuration/references/openrouter-adapter.md +34 -21
  45. package/skills/ai-core/ag-ui-protocol/SKILL.md +16 -10
  46. package/skills/ai-core/chat-experience/SKILL.md +228 -108
  47. package/skills/ai-core/client-persistence/SKILL.md +21 -9
  48. package/skills/ai-core/custom-backend-integration/SKILL.md +86 -52
  49. package/skills/ai-core/debug-logging/SKILL.md +100 -18
  50. package/skills/ai-core/locks/SKILL.md +35 -7
  51. package/skills/ai-core/media-generation/SKILL.md +136 -61
  52. package/skills/ai-core/middleware/SKILL.md +174 -69
  53. package/skills/ai-core/structured-outputs/SKILL.md +98 -49
  54. package/skills/ai-core/tool-calling/SKILL.md +245 -158
  55. package/src/activities/chat/index.ts +29 -7
  56. package/src/activities/chat/messages.ts +60 -0
  57. package/src/activities/chat/stream/processor.ts +31 -0
  58. package/src/activities/generateLiveVideo/adapter.ts +99 -0
  59. package/src/activities/generateLiveVideo/index.ts +339 -0
  60. package/src/activities/generateVideo/index.ts +3 -4
  61. package/src/activities/generateWorld/adapter.ts +96 -0
  62. package/src/activities/generateWorld/index.ts +339 -0
  63. package/src/activities/index.ts +44 -0
  64. package/src/activities/middleware/types.ts +2 -0
  65. package/src/client.ts +8 -0
  66. package/src/index.ts +8 -0
  67. package/src/middlewares/otel.ts +2 -0
  68. package/src/types.ts +128 -0
package/README.md CHANGED
@@ -202,19 +202,20 @@ Learn more in the
202
202
 
203
203
  Official adapters include:
204
204
 
205
- | Package | Use it for |
206
- | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ |
207
- | [`@tanstack/ai-openrouter`](https://tanstack.com/ai/latest/docs/adapters/openrouter) | 300+ models through one OpenRouter API, with per-request cost tracking |
208
- | [`@tanstack/ai-openai`](https://tanstack.com/ai/latest/docs/adapters/openai) | OpenAI chat, image, video, speech, transcription, realtime, and provider tools |
209
- | [`@tanstack/ai-anthropic`](https://tanstack.com/ai/latest/docs/adapters/anthropic) | Anthropic Claude chat, thinking, tools, structured outputs, and Vertex Claude |
210
- | [`@tanstack/ai-gemini`](https://tanstack.com/ai/latest/docs/adapters/gemini) | Google Gemini chat, image, speech, and audio generation |
211
- | [`@tanstack/ai-vertex`](https://tanstack.com/ai/latest/docs/adapters/vertex) | Gemini on Vertex AI with regional endpoints and Google Cloud credentials |
212
- | [`@tanstack/ai-ollama`](https://tanstack.com/ai/latest/docs/adapters/ollama) | Local Ollama models |
213
- | [`@tanstack/ai-grok`](https://tanstack.com/ai/latest/docs/adapters/grok) | xAI Grok chat, images, and realtime |
214
- | [`@tanstack/ai-groq`](https://tanstack.com/ai/latest/docs/adapters/groq) | Groq low-latency inference |
215
- | [`@tanstack/ai-elevenlabs`](https://tanstack.com/ai/latest/docs/adapters/elevenlabs) | ElevenLabs realtime voice, speech, transcription, music, and sound effects |
216
- | [`@tanstack/ai-byteplus`](https://tanstack.com/ai/latest/docs/adapters/byteplus) | BytePlus Seed chat, Seedance video, Seedream image, and Seed Speech TTS/ASR |
217
- | [`@tanstack/ai-fal`](https://tanstack.com/ai/latest/docs/adapters/fal) | fal.ai image, video, audio, speech, and transcription models |
205
+ | Package | Use it for |
206
+ | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------ |
207
+ | [`@tanstack/ai-openrouter`](https://tanstack.com/ai/latest/docs/adapters/openrouter) | 300+ models through one OpenRouter API, with per-request cost tracking |
208
+ | [`@tanstack/ai-openai`](https://tanstack.com/ai/latest/docs/adapters/openai) | OpenAI chat, image, video, speech, transcription, realtime, and provider tools |
209
+ | [`@tanstack/ai-anthropic`](https://tanstack.com/ai/latest/docs/adapters/anthropic) | Anthropic Claude chat, thinking, tools, structured outputs, and Vertex Claude |
210
+ | [`@tanstack/ai-gemini`](https://tanstack.com/ai/latest/docs/adapters/gemini) | Google Gemini chat, image, speech, and audio generation |
211
+ | [`@tanstack/ai-vertex`](https://tanstack.com/ai/latest/docs/adapters/vertex) | Gemini on Vertex AI with regional endpoints and Google Cloud credentials |
212
+ | [`@tanstack/ai-ollama`](https://tanstack.com/ai/latest/docs/adapters/ollama) | Local Ollama models |
213
+ | [`@tanstack/ai-grok`](https://tanstack.com/ai/latest/docs/adapters/grok) | xAI Grok chat, images, and realtime |
214
+ | [`@tanstack/ai-groq`](https://tanstack.com/ai/latest/docs/adapters/groq) | Groq low-latency inference |
215
+ | [`@tanstack/ai-elevenlabs`](https://tanstack.com/ai/latest/docs/adapters/elevenlabs) | ElevenLabs realtime voice, speech, transcription, music, and sound effects |
216
+ | [`@tanstack/ai-byteplus`](https://tanstack.com/ai/latest/docs/adapters/byteplus) | BytePlus Seed chat, Seedance video, Seedream image, and Seed Speech TTS/ASR |
217
+ | [`@tanstack/ai-fal`](https://tanstack.com/ai/latest/docs/adapters/fal) | fal.ai image, video, audio, speech, and transcription models |
218
+ | [`@tanstack/ai-cloudflare`](https://tanstack.com/ai/latest/docs/adapters/cloudflare) | Cloudflare Workers AI chat, embeddings, image, speech, transcription, and AI Gateway |
218
219
 
219
220
  The adapter system is tree-shakeable by activity. Import `openaiText` for chat,
220
221
  `openaiImage` for images, `falVideo` for video, `geminiSpeech` for TTS, and so
@@ -18,7 +18,7 @@ import { INTERRUPT_PAYLOAD_METADATA_KEY, createInterruptBinding, rehydrateInterr
18
18
  import { readGenericInterruptContinuation } from "../../generic-interrupt-continuation.js";
19
19
  import { normalizeToolResult } from "../../utilities/tool-result.js";
20
20
  import { isProviderExecutedToolCall } from "../../utilities/provider-executed.js";
21
- import { convertMessagesToModelMessages, generateMessageId, modelMessagesToUIMessages, safeJsonStringify } from "./messages.js";
21
+ import { appendUiResourceToModelMessages, convertMessagesToModelMessages, generateMessageId, modelMessagesToUIMessages, safeJsonStringify, uiResourcePartFromCustomValue } from "./messages.js";
22
22
  import { uiMessagesToWire } from "../../utilities/ag-ui-wire.js";
23
23
  import { restorePublicUsage } from "../../utilities/restore-inbound-chunk.js";
24
24
  import { LazyToolManager } from "./tools/lazy-tool-manager.js";
@@ -361,14 +361,16 @@ var TextEngine = class {
361
361
  if (this.shouldExecuteToolPhase()) {
362
362
  this.deferredToolCallRunFinishedChunks.push(...this.deferredModelRunFinishedChunks);
363
363
  this.deferredModelRunFinishedChunks = [];
364
- } else yield* this.flushDeferredModelRunFinishedChunks();
364
+ } else if (!this.finalStructuredOutput?.nativeCombined) yield* this.flushDeferredModelRunFinishedChunks();
365
365
  } else yield* this.processToolCalls();
366
366
  this.endCycle();
367
367
  } while (yield* this.runWhileYielding(this.shouldContinue()));
368
368
  this.logger.agentLoop("run finished", { finishReason: this.lastFinishReason });
369
369
  if (this.finalStructuredOutput && this.toolPhase !== "wait" && !this.isCancelled() && !this.finalizationError && !this.earlyTermination) {
370
- if (this.finalStructuredOutput.nativeCombined === true) yield* this.harvestCombinedStructuredOutput();
371
- else yield* this.runStructuredFinalization();
370
+ if (this.finalStructuredOutput.nativeCombined === true) {
371
+ yield* this.harvestCombinedStructuredOutput();
372
+ if (!this.finalizationError && !this.isCancelled()) yield* this.flushDeferredModelRunFinishedChunks();
373
+ } else yield* this.runStructuredFinalization();
372
374
  }
373
375
  if (!this.terminalHookCalled && this.toolPhase !== "wait" && !this.isCancelled()) {
374
376
  if (this.finalizationError) {
@@ -1205,6 +1207,21 @@ var TextEngine = class {
1205
1207
  }
1206
1208
  };
1207
1209
  }
1210
+ /**
1211
+ * Record a `ui-resource` CUSTOM chunk on the assistant ModelMessage owning
1212
+ * its `toolCallId` so the resource survives later MESSAGES_SNAPSHOT chunks
1213
+ * (e.g. the interrupt snapshot emitted when the run pauses on a client
1214
+ * tool). Mirrors the anchor-preserving approach used for
1215
+ * `toolCallMetadata` (#867). See #1397.
1216
+ */
1217
+ recordEmittedUiResource(value) {
1218
+ const part = uiResourcePartFromCustomValue(value);
1219
+ if (!part) return;
1220
+ const next = appendUiResourceToModelMessages(this.messages, part);
1221
+ if (next === this.messages) return;
1222
+ this.messages = next;
1223
+ this.middlewareCtx.messages = this.messages;
1224
+ }
1208
1225
  buildMessagesSnapshotChunk() {
1209
1226
  const withIds = this.messages.map((message, index) => ({
1210
1227
  ...message,
@@ -2118,6 +2135,7 @@ var TextEngine = class {
2118
2135
  if (this.hasPublicRunStarted) continue;
2119
2136
  this.hasPublicRunStarted = true;
2120
2137
  }
2138
+ if (spec.type === EventType.CUSTOM && spec.name === "ui-resource") this.recordEmittedUiResource(spec.value);
2121
2139
  yield spec;
2122
2140
  this.middlewareCtx.chunkIndex++;
2123
2141
  }