@tanstack/ai 0.41.0 → 0.43.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 (272) hide show
  1. package/README.md +15 -1
  2. package/dist/esm/activities/chat/adapter.js +23 -16
  3. package/dist/esm/activities/chat/adapter.js.map +1 -1
  4. package/dist/esm/activities/chat/agent-loop-strategies.d.ts +10 -4
  5. package/dist/esm/activities/chat/agent-loop-strategies.js +75 -17
  6. package/dist/esm/activities/chat/agent-loop-strategies.js.map +1 -1
  7. package/dist/esm/activities/chat/cancel.d.ts +40 -0
  8. package/dist/esm/activities/chat/cancel.js +54 -0
  9. package/dist/esm/activities/chat/cancel.js.map +1 -0
  10. package/dist/esm/activities/chat/index.d.ts +28 -16
  11. package/dist/esm/activities/chat/index.js +2100 -1744
  12. package/dist/esm/activities/chat/index.js.map +1 -1
  13. package/dist/esm/activities/chat/mcp/manager.d.ts +2 -2
  14. package/dist/esm/activities/chat/mcp/manager.js +90 -77
  15. package/dist/esm/activities/chat/mcp/manager.js.map +1 -1
  16. package/dist/esm/activities/chat/mcp/types.d.ts +2 -2
  17. package/dist/esm/activities/chat/messages.js +397 -346
  18. package/dist/esm/activities/chat/messages.js.map +1 -1
  19. package/dist/esm/activities/chat/middleware/builder.js +17 -15
  20. package/dist/esm/activities/chat/middleware/builder.js.map +1 -1
  21. package/dist/esm/activities/chat/middleware/capabilities.js +78 -43
  22. package/dist/esm/activities/chat/middleware/capabilities.js.map +1 -1
  23. package/dist/esm/activities/chat/middleware/compose.d.ts +94 -1
  24. package/dist/esm/activities/chat/middleware/compose.js +623 -531
  25. package/dist/esm/activities/chat/middleware/compose.js.map +1 -1
  26. package/dist/esm/activities/chat/middleware/define.js +12 -5
  27. package/dist/esm/activities/chat/middleware/define.js.map +1 -1
  28. package/dist/esm/activities/chat/middleware/index.d.ts +5 -1
  29. package/dist/esm/activities/chat/middleware/locks.d.ts +50 -0
  30. package/dist/esm/activities/chat/middleware/locks.js +71 -0
  31. package/dist/esm/activities/chat/middleware/locks.js.map +1 -0
  32. package/dist/esm/activities/chat/middleware/pending-turn.d.ts +15 -0
  33. package/dist/esm/activities/chat/middleware/pending-turn.js +35 -0
  34. package/dist/esm/activities/chat/middleware/pending-turn.js.map +1 -0
  35. package/dist/esm/activities/chat/middleware/run-disconnect.d.ts +23 -0
  36. package/dist/esm/activities/chat/middleware/run-disconnect.js +42 -0
  37. package/dist/esm/activities/chat/middleware/run-disconnect.js.map +1 -0
  38. package/dist/esm/activities/chat/middleware/run-store.d.ts +283 -0
  39. package/dist/esm/activities/chat/middleware/run-store.js +176 -0
  40. package/dist/esm/activities/chat/middleware/run-store.js.map +1 -0
  41. package/dist/esm/activities/chat/middleware/sandbox-runtime.js +14 -8
  42. package/dist/esm/activities/chat/middleware/sandbox-runtime.js.map +1 -1
  43. package/dist/esm/activities/chat/middleware/tool-cache-middleware.js +79 -70
  44. package/dist/esm/activities/chat/middleware/tool-cache-middleware.js.map +1 -1
  45. package/dist/esm/activities/chat/middleware/types.d.ts +59 -2
  46. package/dist/esm/activities/chat/middleware/validate.js +23 -28
  47. package/dist/esm/activities/chat/middleware/validate.js.map +1 -1
  48. package/dist/esm/activities/chat/stream/json-parser.js +39 -25
  49. package/dist/esm/activities/chat/stream/json-parser.js.map +1 -1
  50. package/dist/esm/activities/chat/stream/message-updaters.js +275 -234
  51. package/dist/esm/activities/chat/stream/message-updaters.js.map +1 -1
  52. package/dist/esm/activities/chat/stream/processor.d.ts +24 -4
  53. package/dist/esm/activities/chat/stream/processor.js +1341 -1542
  54. package/dist/esm/activities/chat/stream/processor.js.map +1 -1
  55. package/dist/esm/activities/chat/stream/strategies.js +69 -53
  56. package/dist/esm/activities/chat/stream/strategies.js.map +1 -1
  57. package/dist/esm/activities/chat/tools/approval-schema.d.ts +19 -0
  58. package/dist/esm/activities/chat/tools/approval-schema.js +117 -0
  59. package/dist/esm/activities/chat/tools/approval-schema.js.map +1 -0
  60. package/dist/esm/activities/chat/tools/lazy-tool-manager.js +164 -191
  61. package/dist/esm/activities/chat/tools/lazy-tool-manager.js.map +1 -1
  62. package/dist/esm/activities/chat/tools/lazy-tools.js +24 -12
  63. package/dist/esm/activities/chat/tools/lazy-tools.js.map +1 -1
  64. package/dist/esm/activities/chat/tools/schema-converter.js +293 -146
  65. package/dist/esm/activities/chat/tools/schema-converter.js.map +1 -1
  66. package/dist/esm/activities/chat/tools/tool-calls.d.ts +18 -2
  67. package/dist/esm/activities/chat/tools/tool-calls.js +522 -531
  68. package/dist/esm/activities/chat/tools/tool-calls.js.map +1 -1
  69. package/dist/esm/activities/chat/tools/tool-definition.d.ts +75 -16
  70. package/dist/esm/activities/chat/tools/tool-definition.js +95 -23
  71. package/dist/esm/activities/chat/tools/tool-definition.js.map +1 -1
  72. package/dist/esm/activities/error-payload.js +85 -47
  73. package/dist/esm/activities/error-payload.js.map +1 -1
  74. package/dist/esm/activities/generateAudio/adapter.js +22 -15
  75. package/dist/esm/activities/generateAudio/adapter.js.map +1 -1
  76. package/dist/esm/activities/generateAudio/index.d.ts +4 -0
  77. package/dist/esm/activities/generateAudio/index.js +141 -105
  78. package/dist/esm/activities/generateAudio/index.js.map +1 -1
  79. package/dist/esm/activities/generateImage/adapter.js +22 -15
  80. package/dist/esm/activities/generateImage/adapter.js.map +1 -1
  81. package/dist/esm/activities/generateImage/index.d.ts +4 -0
  82. package/dist/esm/activities/generateImage/index.js +155 -111
  83. package/dist/esm/activities/generateImage/index.js.map +1 -1
  84. package/dist/esm/activities/generateSpeech/adapter.js +22 -15
  85. package/dist/esm/activities/generateSpeech/adapter.js.map +1 -1
  86. package/dist/esm/activities/generateSpeech/index.d.ts +4 -0
  87. package/dist/esm/activities/generateSpeech/index.js +159 -110
  88. package/dist/esm/activities/generateSpeech/index.js.map +1 -1
  89. package/dist/esm/activities/generateTranscription/adapter.js +22 -15
  90. package/dist/esm/activities/generateTranscription/adapter.js.map +1 -1
  91. package/dist/esm/activities/generateTranscription/index.d.ts +4 -0
  92. package/dist/esm/activities/generateTranscription/index.js +159 -100
  93. package/dist/esm/activities/generateTranscription/index.js.map +1 -1
  94. package/dist/esm/activities/generateVideo/adapter.js +36 -29
  95. package/dist/esm/activities/generateVideo/adapter.js.map +1 -1
  96. package/dist/esm/activities/generateVideo/index.d.ts +143 -19
  97. package/dist/esm/activities/generateVideo/index.js +456 -279
  98. package/dist/esm/activities/generateVideo/index.js.map +1 -1
  99. package/dist/esm/activities/generateVideo/snap.js +60 -48
  100. package/dist/esm/activities/generateVideo/snap.js.map +1 -1
  101. package/dist/esm/activities/index.js +8 -34
  102. package/dist/esm/activities/middleware/index.d.ts +1 -1
  103. package/dist/esm/activities/middleware/run.d.ts +10 -0
  104. package/dist/esm/activities/middleware/run.js +53 -29
  105. package/dist/esm/activities/middleware/run.js.map +1 -1
  106. package/dist/esm/activities/middleware/types.d.ts +44 -6
  107. package/dist/esm/activities/stream-generation-result.d.ts +4 -1
  108. package/dist/esm/activities/stream-generation-result.js +79 -44
  109. package/dist/esm/activities/stream-generation-result.js.map +1 -1
  110. package/dist/esm/activities/summarize/adapter.js +22 -15
  111. package/dist/esm/activities/summarize/adapter.js.map +1 -1
  112. package/dist/esm/activities/summarize/chat-stream-summarize.js +252 -202
  113. package/dist/esm/activities/summarize/chat-stream-summarize.js.map +1 -1
  114. package/dist/esm/activities/summarize/index.d.ts +27 -0
  115. package/dist/esm/activities/summarize/index.js +268 -102
  116. package/dist/esm/activities/summarize/index.js.map +1 -1
  117. package/dist/esm/adapter-internals.d.ts +2 -1
  118. package/dist/esm/adapter-internals.js +4 -11
  119. package/dist/esm/client.d.ts +25 -3
  120. package/dist/esm/client.js +131 -64
  121. package/dist/esm/client.js.map +1 -1
  122. package/dist/esm/custom-events.d.ts +76 -0
  123. package/dist/esm/custom-events.js +37 -0
  124. package/dist/esm/custom-events.js.map +1 -0
  125. package/dist/esm/delivery-detach.d.ts +50 -0
  126. package/dist/esm/delivery-detach.js +71 -0
  127. package/dist/esm/delivery-detach.js.map +1 -0
  128. package/dist/esm/delivery-disconnect.d.ts +62 -0
  129. package/dist/esm/delivery-disconnect.js +81 -0
  130. package/dist/esm/delivery-disconnect.js.map +1 -0
  131. package/dist/esm/extend-adapter.js +19 -17
  132. package/dist/esm/extend-adapter.js.map +1 -1
  133. package/dist/esm/index.d.ts +23 -5
  134. package/dist/esm/index.js +30 -97
  135. package/dist/esm/interrupt-resume.d.ts +71 -0
  136. package/dist/esm/interrupt-resume.js +438 -0
  137. package/dist/esm/interrupt-resume.js.map +1 -0
  138. package/dist/esm/interrupt-serialization.d.ts +12 -0
  139. package/dist/esm/interrupt-serialization.js +178 -0
  140. package/dist/esm/interrupt-serialization.js.map +1 -0
  141. package/dist/esm/interrupts.d.ts +84 -0
  142. package/dist/esm/interrupts.js +31 -0
  143. package/dist/esm/interrupts.js.map +1 -0
  144. package/dist/esm/locks.d.ts +10 -0
  145. package/dist/esm/locks.js +2 -0
  146. package/dist/esm/logger/console-logger.js +101 -78
  147. package/dist/esm/logger/console-logger.js.map +1 -1
  148. package/dist/esm/logger/internal-logger.js +104 -89
  149. package/dist/esm/logger/internal-logger.js.map +1 -1
  150. package/dist/esm/logger/resolve.js +54 -49
  151. package/dist/esm/logger/resolve.js.map +1 -1
  152. package/dist/esm/logger/types.d.ts +1 -1
  153. package/dist/esm/middlewares/content-guard.js +142 -148
  154. package/dist/esm/middlewares/content-guard.js.map +1 -1
  155. package/dist/esm/middlewares/index.js +2 -6
  156. package/dist/esm/middlewares/otel.js +598 -732
  157. package/dist/esm/middlewares/otel.js.map +1 -1
  158. package/dist/esm/middlewares/usage-attributes.js +47 -40
  159. package/dist/esm/middlewares/usage-attributes.js.map +1 -1
  160. package/dist/esm/realtime/event-emitter.js +24 -25
  161. package/dist/esm/realtime/event-emitter.js.map +1 -1
  162. package/dist/esm/realtime/index.d.ts +5 -9
  163. package/dist/esm/realtime/index.js +29 -6
  164. package/dist/esm/realtime/index.js.map +1 -1
  165. package/dist/esm/scope.d.ts +47 -0
  166. package/dist/esm/stream-durability.d.ts +171 -0
  167. package/dist/esm/stream-durability.js +295 -0
  168. package/dist/esm/stream-durability.js.map +1 -0
  169. package/dist/esm/stream-to-response.d.ts +178 -13
  170. package/dist/esm/stream-to-response.js +663 -115
  171. package/dist/esm/stream-to-response.js.map +1 -1
  172. package/dist/esm/strip-to-spec-middleware.js +30 -16
  173. package/dist/esm/strip-to-spec-middleware.js.map +1 -1
  174. package/dist/esm/system-prompts.js +27 -21
  175. package/dist/esm/system-prompts.js.map +1 -1
  176. package/dist/esm/tool-registry.js +72 -45
  177. package/dist/esm/tool-registry.js.map +1 -1
  178. package/dist/esm/tools/provider-tool.js +14 -5
  179. package/dist/esm/tools/provider-tool.js.map +1 -1
  180. package/dist/esm/types.d.ts +332 -21
  181. package/dist/esm/types.js +2 -0
  182. package/dist/esm/utilities/ag-ui-wire.js +79 -93
  183. package/dist/esm/utilities/ag-ui-wire.js.map +1 -1
  184. package/dist/esm/utilities/chat-params.d.ts +26 -4
  185. package/dist/esm/utilities/chat-params.js +218 -92
  186. package/dist/esm/utilities/chat-params.js.map +1 -1
  187. package/dist/esm/utilities/errors.js +28 -18
  188. package/dist/esm/utilities/errors.js.map +1 -1
  189. package/dist/esm/utilities/media-prompt.js +46 -41
  190. package/dist/esm/utilities/media-prompt.js.map +1 -1
  191. package/dist/esm/utilities/numbers.js +13 -10
  192. package/dist/esm/utilities/numbers.js.map +1 -1
  193. package/dist/esm/utilities/provider-executed.js +20 -11
  194. package/dist/esm/utilities/provider-executed.js.map +1 -1
  195. package/dist/esm/utilities/sampling-keys.js +31 -19
  196. package/dist/esm/utilities/sampling-keys.js.map +1 -1
  197. package/dist/esm/utilities/tool-result.js +42 -30
  198. package/dist/esm/utilities/tool-result.js.map +1 -1
  199. package/dist/esm/utilities/usage.js +27 -9
  200. package/dist/esm/utilities/usage.js.map +1 -1
  201. package/dist/esm/utils.js +26 -18
  202. package/dist/esm/utils.js.map +1 -1
  203. package/package.json +10 -6
  204. package/skills/ai-core/SKILL.md +69 -18
  205. package/skills/ai-core/adapter-configuration/SKILL.md +44 -21
  206. package/skills/ai-core/adapter-configuration/references/anthropic-adapter.md +1 -3
  207. package/skills/ai-core/adapter-configuration/references/byteplus-adapter.md +148 -0
  208. package/skills/ai-core/adapter-configuration/references/gemini-adapter.md +2 -6
  209. package/skills/ai-core/adapter-configuration/references/groq-adapter.md +2 -6
  210. package/skills/ai-core/adapter-configuration/references/openai-adapter.md +1 -3
  211. package/skills/ai-core/ag-ui-protocol/SKILL.md +1 -1
  212. package/skills/ai-core/chat-experience/SKILL.md +156 -11
  213. package/skills/ai-core/client-persistence/SKILL.md +277 -0
  214. package/skills/ai-core/custom-backend-integration/SKILL.md +1 -1
  215. package/skills/ai-core/debug-logging/SKILL.md +1 -1
  216. package/skills/ai-core/locks/SKILL.md +143 -0
  217. package/skills/ai-core/media-generation/SKILL.md +144 -12
  218. package/skills/ai-core/middleware/SKILL.md +258 -33
  219. package/skills/ai-core/structured-outputs/SKILL.md +1 -1
  220. package/skills/ai-core/tool-calling/SKILL.md +54 -59
  221. package/src/activities/chat/agent-loop-strategies.ts +10 -4
  222. package/src/activities/chat/cancel.ts +81 -0
  223. package/src/activities/chat/index.ts +1152 -153
  224. package/src/activities/chat/mcp/manager.ts +4 -4
  225. package/src/activities/chat/mcp/types.ts +2 -2
  226. package/src/activities/chat/messages.ts +5 -3
  227. package/src/activities/chat/middleware/builder.ts +1 -1
  228. package/src/activities/chat/middleware/compose.ts +186 -9
  229. package/src/activities/chat/middleware/index.ts +26 -0
  230. package/src/activities/chat/middleware/locks.ts +102 -0
  231. package/src/activities/chat/middleware/pending-turn.ts +47 -0
  232. package/src/activities/chat/middleware/run-disconnect.ts +62 -0
  233. package/src/activities/chat/middleware/run-store.ts +412 -0
  234. package/src/activities/chat/middleware/types.ts +62 -1
  235. package/src/activities/chat/stream/processor.ts +189 -5
  236. package/src/activities/chat/tools/approval-schema.ts +205 -0
  237. package/src/activities/chat/tools/tool-calls.ts +106 -13
  238. package/src/activities/chat/tools/tool-definition.ts +210 -39
  239. package/src/activities/generateAudio/index.ts +20 -3
  240. package/src/activities/generateImage/index.ts +20 -3
  241. package/src/activities/generateSpeech/index.ts +25 -3
  242. package/src/activities/generateTranscription/index.ts +26 -3
  243. package/src/activities/generateVideo/index.ts +345 -82
  244. package/src/activities/middleware/index.ts +2 -0
  245. package/src/activities/middleware/run.ts +31 -0
  246. package/src/activities/middleware/types.ts +49 -5
  247. package/src/activities/stream-generation-result.ts +30 -2
  248. package/src/activities/summarize/chat-stream-summarize.ts +5 -0
  249. package/src/activities/summarize/index.ts +200 -10
  250. package/src/adapter-internals.ts +10 -1
  251. package/src/client.ts +244 -0
  252. package/src/custom-events.ts +107 -0
  253. package/src/delivery-detach.ts +72 -0
  254. package/src/delivery-disconnect.ts +84 -0
  255. package/src/index.ts +138 -0
  256. package/src/interrupt-resume.ts +824 -0
  257. package/src/interrupt-serialization.ts +183 -0
  258. package/src/interrupts.ts +146 -0
  259. package/src/locks.ts +17 -0
  260. package/src/logger/types.ts +1 -1
  261. package/src/middlewares/otel.ts +1 -0
  262. package/src/realtime/index.ts +5 -9
  263. package/src/scope.ts +47 -0
  264. package/src/stream-durability.ts +598 -0
  265. package/src/stream-to-response.ts +1051 -95
  266. package/src/strip-to-spec-middleware.ts +3 -3
  267. package/src/types.ts +416 -24
  268. package/src/utilities/chat-params.ts +245 -55
  269. package/dist/esm/activities/index.js.map +0 -1
  270. package/dist/esm/adapter-internals.js.map +0 -1
  271. package/dist/esm/index.js.map +0 -1
  272. package/dist/esm/middlewares/index.js.map +0 -1
@@ -2,8 +2,11 @@ import { StandardJSONSchemaV1, StandardSchemaV1 } from '@standard-schema/spec';
2
2
  import { InternalLogger } from './logger/internal-logger.js';
3
3
  import { SystemPrompt } from './system-prompts.js';
4
4
  import { CapabilityContext } from './activities/chat/middleware/capabilities.js';
5
+ import { InterruptSubmissionError } from './interrupts.js';
6
+ import { ProviderTool } from './tools/provider-tool.js';
5
7
  import { CompletionTokensDetails, PromptTokensDetails, ProviderUsageDetails, TokenUsage, UsageCostBreakdown } from '@tanstack/ai-event-client';
6
- import { BaseEvent as AGUIBaseEvent, CustomEvent as AGUICustomEvent, MessagesSnapshotEvent as AGUIMessagesSnapshotEvent, ReasoningEncryptedValueEvent as AGUIReasoningEncryptedValueEvent, ReasoningEndEvent as AGUIReasoningEndEvent, ReasoningMessageContentEvent as AGUIReasoningMessageContentEvent, ReasoningMessageEndEvent as AGUIReasoningMessageEndEvent, ReasoningMessageStartEvent as AGUIReasoningMessageStartEvent, ReasoningStartEvent as AGUIReasoningStartEvent, RunErrorEvent as AGUIRunErrorEvent, RunFinishedEvent as AGUIRunFinishedEvent, RunStartedEvent as AGUIRunStartedEvent, StateDeltaEvent as AGUIStateDeltaEvent, StateSnapshotEvent as AGUIStateSnapshotEvent, StepFinishedEvent as AGUIStepFinishedEvent, StepStartedEvent as AGUIStepStartedEvent, TextMessageContentEvent as AGUITextMessageContentEvent, TextMessageEndEvent as AGUITextMessageEndEvent, TextMessageStartEvent as AGUITextMessageStartEvent, ToolCallArgsEvent as AGUIToolCallArgsEvent, ToolCallEndEvent as AGUIToolCallEndEvent, ToolCallResultEvent as AGUIToolCallResultEvent, ToolCallStartEvent as AGUIToolCallStartEvent, EventType } from '@ag-ui/core';
8
+ import { BaseEvent as AGUIBaseEvent, CustomEvent as AGUICustomEvent, Interrupt as AGUIInterrupt, MessagesSnapshotEvent as AGUIMessagesSnapshotEvent, ReasoningEncryptedValueEvent as AGUIReasoningEncryptedValueEvent, ReasoningEndEvent as AGUIReasoningEndEvent, ReasoningMessageContentEvent as AGUIReasoningMessageContentEvent, ReasoningMessageEndEvent as AGUIReasoningMessageEndEvent, ReasoningMessageStartEvent as AGUIReasoningMessageStartEvent, ReasoningStartEvent as AGUIReasoningStartEvent, ResumeEntry as AGUIResumeEntry, RunErrorEvent as AGUIRunErrorEvent, RunFinishedEvent as AGUIRunFinishedEvent, RunFinishedOutcome as AGUIRunFinishedOutcome, RunStartedEvent as AGUIRunStartedEvent, StateDeltaEvent as AGUIStateDeltaEvent, StateSnapshotEvent as AGUIStateSnapshotEvent, StepFinishedEvent as AGUIStepFinishedEvent, StepStartedEvent as AGUIStepStartedEvent, TextMessageContentEvent as AGUITextMessageContentEvent, TextMessageEndEvent as AGUITextMessageEndEvent, TextMessageStartEvent as AGUITextMessageStartEvent, ToolCallArgsEvent as AGUIToolCallArgsEvent, ToolCallEndEvent as AGUIToolCallEndEvent, ToolCallResultEvent as AGUIToolCallResultEvent, ToolCallStartEvent as AGUIToolCallStartEvent, EventType } from '@ag-ui/core';
9
+ export type { ProviderTool } from './tools/provider-tool.js';
7
10
  /**
8
11
  * Tool call states - track the lifecycle of a tool call
9
12
  */
@@ -247,6 +250,15 @@ export interface ModelMessage<TContent extends string | null | Array<ContentPart
247
250
  content: string;
248
251
  signature?: string;
249
252
  }>;
253
+ /**
254
+ * Optional stable message id. Providers ignore it; it exists so a persisted
255
+ * transcript can retain the streaming `messageId` and survive the
256
+ * persist → hydrate round-trip. When present, `modelMessagesToUIMessages`
257
+ * reuses it instead of generating a fresh id, so a hydrated message keeps the
258
+ * same identity as its live stream — which is what lets a mid-stream reload
259
+ * resume the SAME message bubble in place (see `@tanstack/ai-persistence`).
260
+ */
261
+ id?: string;
250
262
  }
251
263
  /**
252
264
  * Message parts - building blocks of UIMessage
@@ -426,7 +438,7 @@ export type ToolExecutionContext<TContext = unknown> = RuntimeContextField<TCont
426
438
  */
427
439
  emitCustomEvent: (eventName: string, value: Record<string, any>) => void;
428
440
  };
429
- export type ToolExecuteFunction<TInput extends SchemaInput = SchemaInput, TOutput extends SchemaInput = SchemaInput, TContext = unknown> = undefined extends TContext ? (args: InferSchemaType<TInput>, context?: ToolExecutionContext<TContext>) => Promise<InferSchemaType<TOutput>> | InferSchemaType<TOutput> : (args: InferSchemaType<TInput>, context: ToolExecutionContext<TContext>) => Promise<InferSchemaType<TOutput>> | InferSchemaType<TOutput>;
441
+ export type ToolExecuteFunction<TInput extends SchemaInput | undefined = SchemaInput, TOutput extends SchemaInput | undefined = SchemaInput, TContext = unknown> = undefined extends TContext ? (args: InferSchemaType<TInput>, context?: ToolExecutionContext<TContext>) => Promise<InferSchemaType<TOutput>> | InferSchemaType<TOutput> : (args: InferSchemaType<TInput>, context: ToolExecutionContext<TContext>) => Promise<InferSchemaType<TOutput>> | InferSchemaType<TOutput>;
430
442
  /**
431
443
  * Tool/Function definition for function calling.
432
444
  *
@@ -440,7 +452,7 @@ export type ToolExecuteFunction<TInput extends SchemaInput = SchemaInput, TOutpu
440
452
  * @see https://docs.anthropic.com/claude/docs/tool-use
441
453
  * @see https://standardschema.dev/json-schema
442
454
  */
443
- export interface Tool<TInput extends SchemaInput = SchemaInput, TOutput extends SchemaInput = SchemaInput, TName extends string = string, TContext = unknown> {
455
+ export interface Tool<TInput extends SchemaInput | undefined = SchemaInput, TOutput extends SchemaInput | undefined = SchemaInput, TName extends string = string, TContext = unknown> {
444
456
  /**
445
457
  * Unique name of the tool (used by the model to call it).
446
458
  *
@@ -654,12 +666,24 @@ export interface ResponseFormat<TData = any> {
654
666
  * State passed to agent loop strategy for determining whether to continue
655
667
  */
656
668
  export interface AgentLoopState {
657
- /** Current iteration count (0-indexed) */
669
+ /** Current iteration count (0-indexed). One iteration = one model turn. */
658
670
  iterationCount: number;
659
671
  /** Current messages array */
660
672
  messages: Array<ModelMessage>;
661
673
  /** Finish reason from the last response */
662
674
  finishReason: string | null;
675
+ /**
676
+ * Cumulative tool calls counted so far in this run (model-emitted during the
677
+ * agent loop, including ones skipped by middleware, and pending tools from
678
+ * the inbound message list when resumed). Not a recount of full message
679
+ * history; not model turns.
680
+ */
681
+ toolCallCount: number;
682
+ /**
683
+ * Tool calls in the most recent batch — a live model turn or a
684
+ * pending/resume batch (0 when the last phase produced no tool calls).
685
+ */
686
+ lastTurnToolCallCount: number;
663
687
  }
664
688
  /**
665
689
  * Strategy function that determines whether the agent loop should continue
@@ -669,8 +693,10 @@ export interface AgentLoopState {
669
693
  *
670
694
  * @example
671
695
  * ```typescript
672
- * // Continue for up to 5 iterations
696
+ * // Continue for up to 5 iterations (model turns, not tool calls)
673
697
  * const strategy: AgentLoopStrategy = ({ iterationCount }) => iterationCount < 5;
698
+ * // Cap total tool calls across the run (or use middleware onShouldContinue)
699
+ * const byTools: AgentLoopStrategy = ({ toolCallCount }) => toolCallCount < 20;
674
700
  * ```
675
701
  */
676
702
  export type AgentLoopStrategy = (state: AgentLoopState) => boolean;
@@ -792,6 +818,14 @@ export interface TextOptions<TProviderOptionsSuperset extends Record<string, any
792
818
  * Surfaced for observability/middleware; not consumed by the LLM call.
793
819
  */
794
820
  parentRunId?: string;
821
+ /** Application state mirrored in a STATE_SNAPSHOT before an interrupt terminal. */
822
+ state?: unknown;
823
+ /**
824
+ * AG-UI interrupt resume responses supplied by the client on a follow-up run.
825
+ * Threaded through request parsing now so later runtime behavior can resolve
826
+ * upstream-native interrupts.
827
+ */
828
+ resume?: Array<RunAgentResumeItem>;
795
829
  /**
796
830
  * Middleware capability context for this run. The engine populates it with
797
831
  * the live middleware context so harness adapters that declare
@@ -856,6 +890,9 @@ export type { CompletionTokensDetails, PromptTokensDetails, ProviderUsageDetails
856
890
  * future release.
857
891
  */
858
892
  export type UsageTotals = TokenUsage;
893
+ export type Interrupt = AGUIInterrupt;
894
+ export type RunFinishedOutcome = AGUIRunFinishedOutcome;
895
+ export type RunAgentResumeItem = AGUIResumeEntry;
859
896
  /**
860
897
  * Emitted when a run completes successfully.
861
898
  *
@@ -879,6 +916,8 @@ export interface RunFinishedEvent extends AGUIRunFinishedEvent {
879
916
  export interface RunErrorEvent extends AGUIRunErrorEvent {
880
917
  /** Model identifier for multi-model support */
881
918
  model?: string;
919
+ /** Exhaustive TanStack interrupt submission failures for this run. */
920
+ 'tanstack:interruptErrors'?: ReadonlyArray<InterruptSubmissionError>;
882
921
  /**
883
922
  * @deprecated Use top-level `message` and `code` fields instead.
884
923
  * Kept for backward compatibility.
@@ -925,15 +964,27 @@ export interface TextMessageEndEvent extends AGUITextMessageEndEvent {
925
964
  *
926
965
  * @ag-ui/core provides: `toolCallId`, `toolCallName`, `parentMessageId?`
927
966
  * TanStack AI adds: `model?`, `toolName` (deprecated alias), `index?`, `metadata?`
967
+ *
968
+ * Field shapes are taken from AG-UI via `Pick` (not `extends`) so Zod
969
+ * `.passthrough()` index signatures do not pollute the StreamChunk
970
+ * discriminated union — required for {@link TypedStreamChunk} narrowing.
971
+ *
972
+ * @typeParam TToolName - Constrained tool name type. Defaults to `string` (untyped).
973
+ * When the stream is returned from `chat()` with typed tools, `TypedStreamChunk`
974
+ * intersects a literal onto `toolCallName` and `toolName` for discrimination.
928
975
  */
929
- export interface ToolCallStartEvent extends AGUIToolCallStartEvent {
976
+ export interface ToolCallStartEvent<TToolName extends string = string> extends Pick<AGUIToolCallStartEvent, 'toolCallId' | 'toolCallName' | 'parentMessageId' | 'timestamp' | 'rawEvent'> {
977
+ type: 'TOOL_CALL_START';
930
978
  /** Model identifier for multi-model support */
931
979
  model?: string;
932
980
  /**
933
981
  * @deprecated Use `toolCallName` instead (from @ag-ui/core spec).
934
982
  * Kept for backward compatibility.
983
+ *
984
+ * Carries `TToolName` on the base interface; for `toolCallName` narrowing use
985
+ * {@link TypedStreamChunk} (distributed variants intersect the AG-UI field).
935
986
  */
936
- toolName: string;
987
+ toolName: TToolName;
937
988
  /** Index for parallel tool calls */
938
989
  index?: number;
939
990
  /** Provider-specific metadata to carry into the ToolCall.
@@ -958,21 +1009,35 @@ export interface ToolCallArgsEvent extends AGUIToolCallArgsEvent {
958
1009
  * Emitted when a tool call completes.
959
1010
  *
960
1011
  * @ag-ui/core provides: `toolCallId`
961
- * TanStack AI adds: `model?`, `toolCallName?`, `toolName?` (deprecated), `input?`, `result?`
1012
+ * TanStack AI adds: `model?`, `toolCallName?`, `toolName?` (deprecated), `input?`, `output?`, `result?`
1013
+ *
1014
+ * Same `Pick` (not `extends`) rationale as {@link ToolCallStartEvent}.
1015
+ *
1016
+ * @typeParam TToolName - Constrained tool name type. Defaults to `string` (untyped).
1017
+ * @typeParam TInput - Constrained input arguments type. Defaults to `unknown`.
1018
+ * @typeParam TOutput - Constrained output type from the tool's `outputSchema`. Defaults to `unknown`.
962
1019
  */
963
- export interface ToolCallEndEvent extends AGUIToolCallEndEvent {
1020
+ export interface ToolCallEndEvent<TToolName extends string = string, TInput = unknown, TOutput = unknown> extends Pick<AGUIToolCallEndEvent, 'toolCallId' | 'timestamp' | 'rawEvent'> {
1021
+ type: 'TOOL_CALL_END';
964
1022
  /** Model identifier for multi-model support */
965
1023
  model?: string;
966
- /** Name of the tool that completed */
967
- toolCallName?: string;
1024
+ /** Name of the tool that completed (AG-UI-compatible optional field) */
1025
+ toolCallName?: TToolName;
968
1026
  /**
969
1027
  * @deprecated Use `toolCallName` instead.
970
1028
  * Kept for backward compatibility.
971
1029
  */
972
- toolName?: string;
1030
+ toolName?: TToolName;
973
1031
  /** Final parsed input arguments (TanStack AI internal) */
974
- input?: unknown;
975
- /** Tool execution result (TanStack AI internal) */
1032
+ input?: TInput;
1033
+ /**
1034
+ * Tool execution output, validated against the tool's `outputSchema` when
1035
+ * one is declared. Prefer this over parsing `result` when present.
1036
+ * Undefined for tools without execute, client tools pending approval, or
1037
+ * when execution throws.
1038
+ */
1039
+ output?: TOutput;
1040
+ /** Tool execution result (TanStack AI internal / wire form) */
976
1041
  result?: string | Array<ContentPart>;
977
1042
  /** Tool execution output state (TanStack AI internal) */
978
1043
  state?: ToolOutputState;
@@ -1073,10 +1138,23 @@ export interface StateDeltaEvent extends AGUIStateDeltaEvent {
1073
1138
  *
1074
1139
  * @ag-ui/core provides: `name`, `value`
1075
1140
  * TanStack AI adds: `model?`
1141
+ *
1142
+ * Uses `Pick` (not `extends`) so the Zod passthrough index signature does not
1143
+ * erase discriminant property access on {@link KnownCustomEvent} /
1144
+ * {@link TypedStreamChunk} unions.
1076
1145
  */
1077
- export interface CustomEvent extends AGUICustomEvent {
1146
+ export interface CustomEvent extends Pick<AGUICustomEvent, 'name' | 'value' | 'timestamp' | 'rawEvent'> {
1147
+ type: 'CUSTOM';
1078
1148
  /** Model identifier for multi-model support */
1079
1149
  model?: string;
1150
+ /**
1151
+ * Routing metadata the TanStack engine attaches when emitting CUSTOM
1152
+ * events that need to be correlated with a specific thread/run.
1153
+ * Stripped by `strip-to-spec-middleware` before going on the wire so
1154
+ * the AG-UI consumer never sees them (when that middleware is enabled).
1155
+ */
1156
+ threadId?: string;
1157
+ runId?: string;
1080
1158
  }
1081
1159
  /**
1082
1160
  * Final event of a streaming structured-output run. Carries the validated
@@ -1125,6 +1203,10 @@ export interface StructuredOutputStartEvent extends CustomEvent {
1125
1203
  * (the agent-loop branch of `runStreamingStructuredOutputImpl` in
1126
1204
  * `activities/chat/index.ts` forwards CUSTOM events from `TextEngine.run()`).
1127
1205
  */
1206
+ /**
1207
+ * @deprecated Native interrupts use RUN_FINISHED interrupt outcomes. This
1208
+ * compatibility event remains readable until 1.0.
1209
+ */
1128
1210
  export interface ApprovalRequestedEvent extends CustomEvent {
1129
1211
  name: 'approval-requested';
1130
1212
  value: {
@@ -1143,6 +1225,10 @@ export interface ApprovalRequestedEvent extends CustomEvent {
1143
1225
  * will not fire for that run. Shape fixed by the agent-loop forwarding in
1144
1226
  * `runStreamingStructuredOutputImpl` in `activities/chat/index.ts`.
1145
1227
  */
1228
+ /**
1229
+ * @deprecated Native interrupts use RUN_FINISHED interrupt outcomes. This
1230
+ * compatibility event remains readable until 1.0.
1231
+ */
1146
1232
  export interface ToolInputAvailableEvent extends CustomEvent {
1147
1233
  name: 'tool-input-available';
1148
1234
  value: {
@@ -1279,11 +1365,15 @@ export type ChatStream = AsyncIterable<Exclude<StreamChunk, CustomEvent> | Known
1279
1365
  /**
1280
1366
  * Public type for streams returned by `chat({ outputSchema, stream: true })`.
1281
1367
  *
1282
- * Yields all standard `StreamChunk` lifecycle events plus the three tagged
1283
- * `CUSTOM` events the orchestrator can emit through this path:
1368
+ * Yields all standard `StreamChunk` lifecycle events plus the typed
1369
+ * structured-output `CUSTOM` event emitted through this path:
1284
1370
  * - `structured-output.complete` — terminal event with typed `value.object: T`
1285
- * - `approval-requested` — server tool needs approval (pauses the run)
1286
- * - `tool-input-available` — client tool invocation (pauses the run)
1371
+ *
1372
+ * User-actionable waits, such as tool approval and client tool input, are
1373
+ * represented by `RUN_FINISHED.outcome.type === 'interrupt'` in current core
1374
+ * streams. Legacy `approval-requested` and `tool-input-available` custom
1375
+ * events may still be consumed for replay and backward compatibility, but
1376
+ * they are not the current source of truth for waits.
1287
1377
  *
1288
1378
  * Each variant has a literal `name`, so a single discriminated narrow gives
1289
1379
  * you a typed `value` with no helper or cast:
@@ -1292,8 +1382,6 @@ export type ChatStream = AsyncIterable<Exclude<StreamChunk, CustomEvent> | Known
1292
1382
  * for await (const chunk of stream) {
1293
1383
  * if (chunk.type === 'CUSTOM' && chunk.name === 'structured-output.complete') {
1294
1384
  * chunk.value.object // typed as T
1295
- * } else if (chunk.type === 'CUSTOM' && chunk.name === 'approval-requested') {
1296
- * chunk.value.toolCallId // typed as string
1297
1385
  * }
1298
1386
  * }
1299
1387
  * ```
@@ -1376,6 +1464,167 @@ export type AGUIEvent = RunStartedEvent | RunFinishedEvent | RunErrorEvent | Tex
1376
1464
  * Uses the AG-UI protocol event format.
1377
1465
  */
1378
1466
  export type StreamChunk = AGUIEvent;
1467
+ /**
1468
+ * Detect the `any` type. Returns `true` for `any`, `false` for everything else.
1469
+ * @internal
1470
+ */
1471
+ type IsAny<T> = 0 extends 1 & T ? true : false;
1472
+ /**
1473
+ * Partition out provider-specific tools from a tools array. `ProviderTool`
1474
+ * carries opaque provider metadata (e.g. `webSearchTool` from
1475
+ * `@tanstack/ai-anthropic`) and intentionally has a generic `string` name —
1476
+ * if we included it in the discriminated union, it would widen `toolName`
1477
+ * back to `string` and defeat the entire typing exercise.
1478
+ *
1479
+ * @internal
1480
+ */
1481
+ type NonProviderTools<TTools extends ReadonlyArray<AnyTool>> = Exclude<TTools[number], ProviderTool<string, string>>;
1482
+ /**
1483
+ * Check whether the tools array carries typed tool definitions.
1484
+ * Returns `false` for empty arrays or arrays whose only entries are
1485
+ * `ProviderTool`s (which have generic `string` names).
1486
+ *
1487
+ * The partitioning step matters: a user who passes
1488
+ * `[webSearchTool, myTypedTool]` should still get typed narrowing for
1489
+ * `myTypedTool`. Evaluating `string extends TTools[number]['name']` without
1490
+ * filtering provider tools first would always return `false` (because
1491
+ * `ProviderTool`'s `name` is `string`) and silently fall through to the
1492
+ * untyped branch.
1493
+ *
1494
+ * @internal
1495
+ */
1496
+ type HasTypedTools<TTools extends ReadonlyArray<AnyTool>> = [
1497
+ NonProviderTools<TTools>
1498
+ ] extends [never] ? false : string extends NonProviderTools<TTools>['name'] ? false : true;
1499
+ /**
1500
+ * Safely infer input type for a single tool, guarding against `any` leaks.
1501
+ * Returns `unknown` when the tool has no inputSchema, when the schema
1502
+ * parameter defaults to `undefined` (no-schema tool definitions), or when
1503
+ * InferSchemaType produces `any` (e.g. for plain JSON Schema tools).
1504
+ * @internal
1505
+ */
1506
+ type SafeToolInput<T> = T extends {
1507
+ inputSchema?: infer TInput;
1508
+ } ? [TInput] extends [undefined] ? unknown : IsAny<InferSchemaType<NonNullable<TInput>>> extends true ? unknown : InferSchemaType<NonNullable<TInput>> : unknown;
1509
+ /**
1510
+ * Safely infer output type for a single tool. Mirrors `SafeToolInput`,
1511
+ * picking `outputSchema` instead. Returns `unknown` when the tool has no
1512
+ * `outputSchema` declared, when the schema parameter defaults to `undefined`,
1513
+ * or when `InferSchemaType` produces `any`.
1514
+ * @internal
1515
+ */
1516
+ type SafeToolOutput<T> = T extends {
1517
+ outputSchema?: infer TOutput;
1518
+ } ? [TOutput] extends [undefined] ? unknown : IsAny<InferSchemaType<NonNullable<TOutput>>> extends true ? unknown : InferSchemaType<NonNullable<TOutput>> : unknown;
1519
+ /**
1520
+ * Distribute over each non-provider tool to create a per-tool
1521
+ * `ToolCallStartEvent`.
1522
+ *
1523
+ * This produces a discriminated union — one variant per tool name literal.
1524
+ * We distribute over `NonProviderTools<TTools>` (not `TTools[number]`) so
1525
+ * that provider tools with generic `string` names do not leak into the
1526
+ * union and widen `toolCallName` / `toolName` back to `string`.
1527
+ *
1528
+ * The trailing `& { toolCallName: TName; toolName: TName }` intersection
1529
+ * narrows the base `AGUIToolCallStartEvent['toolCallName']` (declared as
1530
+ * `string`) to the literal name — TypeScript intersects `string & TName`
1531
+ * down to `TName` for literal `TName`.
1532
+ *
1533
+ * The `name` parameter constraint on the inner `extends` picks up any
1534
+ * tool-like shape — including `ServerTool`, `ClientTool`, and the bare
1535
+ * `Tool` definition — because all three expose `name: TName`.
1536
+ * @internal
1537
+ */
1538
+ type DistributedToolCallStart<TTools extends ReadonlyArray<AnyTool>> = NonProviderTools<TTools> extends infer T ? T extends {
1539
+ name: infer TName extends string;
1540
+ } ? ToolCallStartEvent<TName> & {
1541
+ toolCallName: TName;
1542
+ toolName: TName;
1543
+ } : never : never;
1544
+ /**
1545
+ * Distribute over each non-provider tool to create a per-tool
1546
+ * `ToolCallEndEvent`.
1547
+ *
1548
+ * Each variant pairs the tool's name literal with its specific input type,
1549
+ * enabling discriminated narrowing: checking `toolName === 'x'` narrows
1550
+ * `input`.
1551
+ *
1552
+ * `toolName`/`toolCallName` are intersected as required in the distributed
1553
+ * variants so that `Extract<..., { toolName: 'x' }>` works for consumers
1554
+ * relying on the discriminated-union pattern, even though the base
1555
+ * interface keeps them optional for compatibility with the broader AG-UI
1556
+ * surface.
1557
+ *
1558
+ * Distribution happens over `NonProviderTools<TTools>` for the same
1559
+ * reason as in `DistributedToolCallStart`.
1560
+ * @internal
1561
+ */
1562
+ type DistributedToolCallEnd<TTools extends ReadonlyArray<AnyTool>> = NonProviderTools<TTools> extends infer T ? T extends {
1563
+ name: infer TName extends string;
1564
+ } ? ToolCallEndEvent<TName, SafeToolInput<T>, SafeToolOutput<T>> & {
1565
+ toolCallName: TName;
1566
+ toolName: TName;
1567
+ } : never : never;
1568
+ /**
1569
+ * Discriminated union of the orchestrator-tagged `CUSTOM` events. Each variant
1570
+ * has a literal `name`, so a single narrow on `chunk.name` yields a typed
1571
+ * `value` with no helper or cast:
1572
+ *
1573
+ * ```ts
1574
+ * if (chunk.type === 'CUSTOM' && chunk.name === 'approval-requested') {
1575
+ * chunk.value.toolCallId // typed as string
1576
+ * }
1577
+ * ```
1578
+ *
1579
+ * The `StructuredOutputCompleteEvent` value is parameterized by `T`, which
1580
+ * the chat orchestrator narrows to the schema's inferred type after Standard
1581
+ * Schema validation. Adapters always emit it with `T = unknown`.
1582
+ *
1583
+ * Caveat: tools can emit arbitrary user-defined custom events via the
1584
+ * `emitCustomEvent(name, value)` context API. Those flow through the stream
1585
+ * at runtime but are intentionally absent from this union — including a bare
1586
+ * `CustomEvent` (whose `value: any` would poison the union) would collapse
1587
+ * `chunk.value` back to `any` after the narrow. If you rely on
1588
+ * `emitCustomEvent`, branch on `CUSTOM` outside the literal-`name` narrows
1589
+ * or cast the chunk to `StreamChunk` to recover the wider shape.
1590
+ */
1591
+ export type TaggedCustomEvent<T = unknown> = StructuredOutputStartEvent | StructuredOutputCompleteEvent<T> | ApprovalRequestedEvent | ToolInputAvailableEvent;
1592
+ /**
1593
+ * Stream chunk type parameterized by the tools array for type-safe tool call events.
1594
+ *
1595
+ * When specific tool types are provided (e.g. from `chat({ tools: [myTool] })`):
1596
+ * - `TOOL_CALL_START` and `TOOL_CALL_END` events form a **discriminated union**
1597
+ * over tool names — checking `toolName === 'x'` narrows `input` to that tool's type.
1598
+ * - `TOOL_CALL_END` events have `input` typed per-tool via Standard Schema inference.
1599
+ *
1600
+ * `CUSTOM` events are narrowed to the discriminated {@link KnownCustomEvent}
1601
+ * union (sandbox, code-mode, structured-output, approvals, UI resources, etc.).
1602
+ * Free-form user-emitted custom events (via `emitCustomEvent`) still flow at
1603
+ * runtime but are excluded from the type to avoid `any` poisoning the union;
1604
+ * cast to `StreamChunk` if you need to read those.
1605
+ *
1606
+ * When tools are untyped or absent, the tool-call events stay as plain
1607
+ * `ToolCallStartEvent` / `ToolCallEndEvent` (no per-tool name narrowing) and
1608
+ * the type is equivalent to the element type of {@link ChatStream}.
1609
+ */
1610
+ /**
1611
+ * Replace tool-call and bare CUSTOM variants; keep every other StreamChunk
1612
+ * arm. Matches on the string-literal `type` discriminant that TanStack tool
1613
+ * events declare (see ToolCallStartEvent / ToolCallEndEvent). AG-UI events
1614
+ * that still use the EventType enum are kept as-is via the final branch.
1615
+ *
1616
+ * Do **not** use `Exclude<StreamChunk, { type: 'TOOL_CALL_*' }>` — under
1617
+ * @ag-ui/core passthrough index signatures that form removes *every* arm.
1618
+ * @internal
1619
+ */
1620
+ type RemapStreamChunkForTools<TChunk, TTools extends ReadonlyArray<AnyTool>> = TChunk extends {
1621
+ type: 'TOOL_CALL_START';
1622
+ } ? DistributedToolCallStart<TTools> : TChunk extends {
1623
+ type: 'TOOL_CALL_END';
1624
+ } ? DistributedToolCallEnd<TTools> : TChunk extends {
1625
+ type: 'CUSTOM';
1626
+ } ? never : TChunk;
1627
+ export type TypedStreamChunk<TTools extends ReadonlyArray<AnyTool> = ReadonlyArray<AnyTool>> = HasTypedTools<TTools> extends true ? RemapStreamChunkForTools<StreamChunk, TTools> | KnownCustomEvent : Exclude<StreamChunk, CustomEvent> | KnownCustomEvent;
1379
1628
  export interface TextCompletionChunk {
1380
1629
  id: string;
1381
1630
  model: string;
@@ -1392,6 +1641,16 @@ export interface SummarizationOptions<TProviderOptions extends object = Record<s
1392
1641
  focus?: Array<string>;
1393
1642
  /** Provider-specific options forwarded by the summarize() activity. */
1394
1643
  modelOptions?: TProviderOptions;
1644
+ /**
1645
+ * Run identity forwarded from the summarize() activity. When set, the
1646
+ * streaming adapter stamps it onto the emitted `RUN_STARTED` (via the wrapped
1647
+ * chat), so a delivery-durable route keys the run's log by the same id the
1648
+ * client rejoins with — making a mid-run reload resumable, like the media
1649
+ * activities. Optional and non-breaking: adapters that ignore it just mint
1650
+ * their own.
1651
+ */
1652
+ runId?: string;
1653
+ threadId?: string;
1395
1654
  /**
1396
1655
  * Internal logger threaded from the summarize() entry point. Adapters must
1397
1656
  * call logger.request() before the SDK call and logger.errors() in catch blocks.
@@ -1518,6 +1777,42 @@ export type GeneratedMediaSource = {
1518
1777
  b64Json: string;
1519
1778
  url?: never;
1520
1779
  };
1780
+ export type PersistedArtifactRole = 'input' | 'output';
1781
+ export type PersistedArtifactActivity = 'image' | 'audio' | 'tts' | 'video' | 'transcription';
1782
+ export interface PersistedArtifactRef {
1783
+ role: PersistedArtifactRole;
1784
+ artifactId: string;
1785
+ threadId: string;
1786
+ runId: string;
1787
+ name: string;
1788
+ mimeType: string;
1789
+ size: number;
1790
+ createdAt: string;
1791
+ /**
1792
+ * Where these bytes were fetched FROM — the provider's original result URL,
1793
+ * or a caller-supplied prompt URL when `allowInputUrl` opted that in. Usually
1794
+ * expiring, and provenance only: serve from {@link PersistedArtifactRef.url}
1795
+ * instead.
1796
+ */
1797
+ sourceUrl?: string;
1798
+ /**
1799
+ * Durable app-origin URL that serves this artifact's persisted bytes (your
1800
+ * `GET` route around `retrieveArtifact` / `retrieveBlob`). Stamped by
1801
+ * `withGenerationPersistence`'s `artifactUrl` option, so clients render and
1802
+ * restore durable media from your own origin rather than the provider's
1803
+ * expiring link.
1804
+ */
1805
+ url?: string;
1806
+ source: {
1807
+ activity: PersistedArtifactActivity;
1808
+ path: string;
1809
+ provider: string;
1810
+ model: string;
1811
+ mediaType?: 'image' | 'audio' | 'video' | 'document' | 'json';
1812
+ jobId?: string;
1813
+ expiresAt?: string;
1814
+ };
1815
+ }
1521
1816
  /**
1522
1817
  * A single generated image
1523
1818
  */
@@ -1537,6 +1832,8 @@ export interface ImageGenerationResult {
1537
1832
  images: Array<GeneratedImage>;
1538
1833
  /** Token usage information (if available) */
1539
1834
  usage?: TokenUsage;
1835
+ /** Persisted artifact references for generated assets, when available */
1836
+ artifacts?: Array<PersistedArtifactRef>;
1540
1837
  }
1541
1838
  /**
1542
1839
  * Options for audio generation (music, sound effects, etc.).
@@ -1579,6 +1876,8 @@ export interface AudioGenerationResult {
1579
1876
  audio: GeneratedAudio;
1580
1877
  /** Token usage information (if available) */
1581
1878
  usage?: TokenUsage;
1879
+ /** Persisted artifact references for generated assets, when available */
1880
+ artifacts?: Array<PersistedArtifactRef>;
1582
1881
  }
1583
1882
  /**
1584
1883
  * Options for video generation.
@@ -1624,6 +1923,12 @@ export interface VideoJobResult {
1624
1923
  jobId: string;
1625
1924
  /** Model used for generation */
1626
1925
  model: string;
1926
+ /**
1927
+ * Durable artifact references, when generation persistence with an artifact +
1928
+ * blob store is wired. A submission has no video yet, so this only carries
1929
+ * refs for persisted prompt INPUTS (e.g. a start frame).
1930
+ */
1931
+ artifacts?: Array<PersistedArtifactRef>;
1627
1932
  }
1628
1933
  /**
1629
1934
  * Status of a video generation job.
@@ -1658,6 +1963,8 @@ export interface VideoUrlResult {
1658
1963
  * real billed quantity — so consumers can compute exact cost.
1659
1964
  */
1660
1965
  usage?: TokenUsage;
1966
+ /** Persisted artifact references for generated assets, when available */
1967
+ artifacts?: Array<PersistedArtifactRef>;
1661
1968
  }
1662
1969
  /**
1663
1970
  * Options for text-to-speech generation.
@@ -1701,6 +2008,8 @@ export interface TTSResult {
1701
2008
  contentType?: string;
1702
2009
  /** Token usage information (if provided by the adapter) */
1703
2010
  usage?: TokenUsage;
2011
+ /** Persisted artifact references for generated assets, when available */
2012
+ artifacts?: Array<PersistedArtifactRef>;
1704
2013
  }
1705
2014
  /**
1706
2015
  * Options for audio transcription.
@@ -1775,6 +2084,8 @@ export interface TranscriptionResult {
1775
2084
  words?: Array<TranscriptionWord>;
1776
2085
  /** Token usage information (if provided by the adapter) */
1777
2086
  usage?: TokenUsage;
2087
+ /** Persisted artifact references for generated assets, when available */
2088
+ artifacts?: Array<PersistedArtifactRef>;
1778
2089
  }
1779
2090
  /**
1780
2091
  * Default metadata type for adapters that don't define custom metadata.
@@ -0,0 +1,2 @@
1
+ import { EventType as EventType$1 } from "@ag-ui/core";
2
+ export { EventType$1 as EventType };