@tanstack/ai 0.36.0 → 0.38.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 (215) hide show
  1. package/dist/esm/activities/chat/adapter.d.ts +163 -0
  2. package/dist/esm/activities/chat/adapter.js +17 -0
  3. package/dist/esm/activities/chat/adapter.js.map +1 -0
  4. package/dist/esm/activities/chat/agent-loop-strategies.d.ts +59 -0
  5. package/dist/esm/activities/chat/agent-loop-strategies.js +23 -0
  6. package/dist/esm/activities/chat/agent-loop-strategies.js.map +1 -0
  7. package/dist/esm/activities/chat/index.d.ts +270 -0
  8. package/dist/esm/activities/chat/index.js +1724 -0
  9. package/dist/esm/activities/chat/index.js.map +1 -0
  10. package/dist/esm/activities/chat/mcp/manager.d.ts +25 -0
  11. package/dist/esm/activities/chat/mcp/manager.js +80 -0
  12. package/dist/esm/activities/chat/mcp/manager.js.map +1 -0
  13. package/dist/esm/activities/chat/mcp/types.d.ts +78 -0
  14. package/dist/esm/activities/chat/messages.d.ts +78 -0
  15. package/dist/esm/activities/chat/messages.js +374 -0
  16. package/dist/esm/activities/chat/messages.js.map +1 -0
  17. package/dist/esm/activities/chat/middleware/builder.d.ts +46 -0
  18. package/dist/esm/activities/chat/middleware/builder.js +17 -0
  19. package/dist/esm/activities/chat/middleware/builder.js.map +1 -0
  20. package/dist/esm/activities/chat/middleware/capabilities.d.ts +93 -0
  21. package/dist/esm/activities/chat/middleware/capabilities.js +45 -0
  22. package/dist/esm/activities/chat/middleware/capabilities.js.map +1 -0
  23. package/dist/esm/activities/chat/middleware/compose.d.ts +87 -0
  24. package/dist/esm/activities/chat/middleware/compose.js +510 -0
  25. package/dist/esm/activities/chat/middleware/compose.js.map +1 -0
  26. package/dist/esm/activities/chat/middleware/define.d.ts +20 -0
  27. package/dist/esm/activities/chat/middleware/define.js +7 -0
  28. package/dist/esm/activities/chat/middleware/define.js.map +1 -0
  29. package/dist/esm/activities/chat/middleware/index.d.ts +10 -0
  30. package/dist/esm/activities/chat/middleware/tool-cache-middleware.d.ts +89 -0
  31. package/dist/esm/activities/chat/middleware/tool-cache-middleware.js +76 -0
  32. package/dist/esm/activities/chat/middleware/tool-cache-middleware.js.map +1 -0
  33. package/dist/esm/activities/chat/middleware/types.d.ts +405 -0
  34. package/dist/esm/activities/chat/middleware/validate.d.ts +19 -0
  35. package/dist/esm/activities/chat/middleware/validate.js +30 -0
  36. package/dist/esm/activities/chat/middleware/validate.js.map +1 -0
  37. package/dist/esm/activities/chat/runtime-context-types.d.ts +43 -0
  38. package/dist/esm/activities/chat/stream/index.d.ts +11 -0
  39. package/dist/esm/activities/chat/stream/json-parser.d.ts +38 -0
  40. package/dist/esm/activities/chat/stream/json-parser.js +28 -0
  41. package/dist/esm/activities/chat/stream/json-parser.js.map +1 -0
  42. package/dist/esm/activities/chat/stream/message-updaters.d.ts +81 -0
  43. package/dist/esm/activities/chat/stream/message-updaters.js +253 -0
  44. package/dist/esm/activities/chat/stream/message-updaters.js.map +1 -0
  45. package/dist/esm/activities/chat/stream/processor.d.ts +439 -0
  46. package/dist/esm/activities/chat/stream/processor.js +1449 -0
  47. package/dist/esm/activities/chat/stream/processor.js.map +1 -0
  48. package/dist/esm/activities/chat/stream/strategies.d.ts +43 -0
  49. package/dist/esm/activities/chat/stream/strategies.js +54 -0
  50. package/dist/esm/activities/chat/stream/strategies.js.map +1 -0
  51. package/dist/esm/activities/chat/stream/types.d.ts +90 -0
  52. package/dist/esm/activities/chat/tools/lazy-tool-manager.d.ts +82 -0
  53. package/dist/esm/activities/chat/tools/lazy-tool-manager.js +194 -0
  54. package/dist/esm/activities/chat/tools/lazy-tool-manager.js.map +1 -0
  55. package/dist/esm/activities/chat/tools/lazy-tools.d.ts +15 -0
  56. package/dist/esm/activities/chat/tools/lazy-tools.js +16 -0
  57. package/dist/esm/activities/chat/tools/lazy-tools.js.map +1 -0
  58. package/dist/esm/activities/chat/tools/schema-converter.d.ts +140 -0
  59. package/dist/esm/activities/chat/tools/schema-converter.js +167 -0
  60. package/dist/esm/activities/chat/tools/schema-converter.js.map +1 -0
  61. package/dist/esm/activities/chat/tools/tool-calls.d.ts +145 -0
  62. package/dist/esm/activities/chat/tools/tool-calls.js +548 -0
  63. package/dist/esm/activities/chat/tools/tool-calls.js.map +1 -0
  64. package/dist/esm/activities/chat/tools/tool-definition.d.ts +135 -0
  65. package/dist/esm/activities/chat/tools/tool-definition.js +25 -0
  66. package/dist/esm/activities/chat/tools/tool-definition.js.map +1 -0
  67. package/dist/esm/activities/error-payload.d.ts +30 -0
  68. package/dist/esm/activities/error-payload.js +54 -0
  69. package/dist/esm/activities/error-payload.js.map +1 -0
  70. package/dist/esm/activities/generateAudio/adapter.d.ts +62 -0
  71. package/dist/esm/activities/generateAudio/adapter.js +16 -0
  72. package/dist/esm/activities/generateAudio/adapter.js.map +1 -0
  73. package/dist/esm/activities/generateAudio/index.d.ts +85 -0
  74. package/dist/esm/activities/generateAudio/index.js +114 -0
  75. package/dist/esm/activities/generateAudio/index.js.map +1 -0
  76. package/dist/esm/activities/generateImage/adapter.d.ts +78 -0
  77. package/dist/esm/activities/generateImage/adapter.js +16 -0
  78. package/dist/esm/activities/generateImage/adapter.js.map +1 -0
  79. package/dist/esm/activities/generateImage/index.d.ts +134 -0
  80. package/dist/esm/activities/generateImage/index.js +121 -0
  81. package/dist/esm/activities/generateImage/index.js.map +1 -0
  82. package/dist/esm/activities/generateSpeech/adapter.d.ts +62 -0
  83. package/dist/esm/activities/generateSpeech/adapter.js +16 -0
  84. package/dist/esm/activities/generateSpeech/adapter.js.map +1 -0
  85. package/dist/esm/activities/generateSpeech/index.d.ts +96 -0
  86. package/dist/esm/activities/generateSpeech/index.js +119 -0
  87. package/dist/esm/activities/generateSpeech/index.js.map +1 -0
  88. package/dist/esm/activities/generateTranscription/adapter.d.ts +62 -0
  89. package/dist/esm/activities/generateTranscription/adapter.js +16 -0
  90. package/dist/esm/activities/generateTranscription/adapter.js.map +1 -0
  91. package/dist/esm/activities/generateTranscription/index.d.ts +109 -0
  92. package/dist/esm/activities/generateTranscription/index.js +109 -0
  93. package/dist/esm/activities/generateTranscription/index.js.map +1 -0
  94. package/dist/esm/activities/generateVideo/adapter.d.ts +145 -0
  95. package/dist/esm/activities/generateVideo/adapter.js +30 -0
  96. package/dist/esm/activities/generateVideo/adapter.js.map +1 -0
  97. package/dist/esm/activities/generateVideo/index.d.ts +223 -0
  98. package/dist/esm/activities/generateVideo/index.js +295 -0
  99. package/dist/esm/activities/generateVideo/index.js.map +1 -0
  100. package/dist/esm/activities/generateVideo/snap.d.ts +14 -0
  101. package/dist/esm/activities/generateVideo/snap.js +54 -0
  102. package/dist/esm/activities/generateVideo/snap.js.map +1 -0
  103. package/dist/esm/activities/index.d.ts +27 -0
  104. package/dist/esm/activities/index.js +43 -0
  105. package/dist/esm/activities/index.js.map +1 -0
  106. package/dist/esm/activities/middleware/index.d.ts +2 -0
  107. package/dist/esm/activities/middleware/run.d.ts +20 -0
  108. package/dist/esm/activities/middleware/run.js +42 -0
  109. package/dist/esm/activities/middleware/run.js.map +1 -0
  110. package/dist/esm/activities/middleware/types.d.ts +118 -0
  111. package/dist/esm/activities/stream-generation-result.d.ts +15 -0
  112. package/dist/esm/activities/stream-generation-result.js +49 -0
  113. package/dist/esm/activities/stream-generation-result.js.map +1 -0
  114. package/dist/esm/activities/summarize/adapter.d.ts +74 -0
  115. package/dist/esm/activities/summarize/adapter.js +16 -0
  116. package/dist/esm/activities/summarize/adapter.js.map +1 -0
  117. package/dist/esm/activities/summarize/chat-stream-summarize.d.ts +45 -0
  118. package/dist/esm/activities/summarize/chat-stream-summarize.js +212 -0
  119. package/dist/esm/activities/summarize/chat-stream-summarize.js.map +1 -0
  120. package/dist/esm/activities/summarize/index.d.ts +108 -0
  121. package/dist/esm/activities/summarize/index.js +113 -0
  122. package/dist/esm/activities/summarize/index.js.map +1 -0
  123. package/dist/esm/adapter-internals.d.ts +5 -0
  124. package/dist/esm/adapter-internals.js +10 -0
  125. package/dist/esm/adapter-internals.js.map +1 -0
  126. package/dist/esm/client.d.ts +44 -0
  127. package/dist/esm/client.js +67 -0
  128. package/dist/esm/client.js.map +1 -0
  129. package/dist/esm/extend-adapter.d.ts +152 -0
  130. package/dist/esm/extend-adapter.js +21 -0
  131. package/dist/esm/extend-adapter.js.map +1 -0
  132. package/dist/esm/index.d.ts +45 -0
  133. package/dist/esm/index.js +109 -0
  134. package/dist/esm/index.js.map +1 -0
  135. package/dist/esm/logger/console-logger.d.ts +29 -0
  136. package/dist/esm/logger/console-logger.js +83 -0
  137. package/dist/esm/logger/console-logger.js.map +1 -0
  138. package/dist/esm/logger/internal-logger.d.ts +41 -0
  139. package/dist/esm/logger/internal-logger.js +86 -0
  140. package/dist/esm/logger/internal-logger.js.map +1 -0
  141. package/dist/esm/logger/resolve.d.ts +14 -0
  142. package/dist/esm/logger/resolve.js +54 -0
  143. package/dist/esm/logger/resolve.js.map +1 -0
  144. package/dist/esm/logger/types.d.ts +75 -0
  145. package/dist/esm/middlewares/content-guard.d.ts +77 -0
  146. package/dist/esm/middlewares/content-guard.js +156 -0
  147. package/dist/esm/middlewares/content-guard.js.map +1 -0
  148. package/dist/esm/middlewares/index.d.ts +2 -0
  149. package/dist/esm/middlewares/index.js +7 -0
  150. package/dist/esm/middlewares/index.js.map +1 -0
  151. package/dist/esm/middlewares/otel.d.ts +81 -0
  152. package/dist/esm/middlewares/otel.js +745 -0
  153. package/dist/esm/middlewares/otel.js.map +1 -0
  154. package/dist/esm/middlewares/tool-cache.d.ts +1 -0
  155. package/dist/esm/middlewares/usage-attributes.d.ts +24 -0
  156. package/dist/esm/middlewares/usage-attributes.js +43 -0
  157. package/dist/esm/middlewares/usage-attributes.js.map +1 -0
  158. package/dist/esm/realtime/index.d.ts +28 -0
  159. package/dist/esm/realtime/index.js +8 -0
  160. package/dist/esm/realtime/index.js.map +1 -0
  161. package/dist/esm/realtime/types.d.ts +282 -0
  162. package/dist/esm/stream-to-response.d.ts +102 -0
  163. package/dist/esm/stream-to-response.js +121 -0
  164. package/dist/esm/stream-to-response.js.map +1 -0
  165. package/dist/esm/strip-to-spec-middleware.d.ts +18 -0
  166. package/dist/esm/strip-to-spec-middleware.js +20 -0
  167. package/dist/esm/strip-to-spec-middleware.js.map +1 -0
  168. package/dist/esm/system-prompts.d.ts +66 -0
  169. package/dist/esm/system-prompts.js +23 -0
  170. package/dist/esm/system-prompts.js.map +1 -0
  171. package/dist/esm/tool-registry.d.ts +81 -0
  172. package/dist/esm/tool-registry.js +49 -0
  173. package/dist/esm/tool-registry.js.map +1 -0
  174. package/dist/esm/tools/provider-tool.d.ts +30 -0
  175. package/dist/esm/tools/provider-tool.js +7 -0
  176. package/dist/esm/tools/provider-tool.js.map +1 -0
  177. package/dist/esm/types.d.ts +1627 -0
  178. package/dist/esm/utilities/ag-ui-wire.d.ts +44 -0
  179. package/dist/esm/utilities/ag-ui-wire.js +107 -0
  180. package/dist/esm/utilities/ag-ui-wire.js.map +1 -0
  181. package/dist/esm/utilities/chat-params.d.ts +85 -0
  182. package/dist/esm/utilities/chat-params.js +100 -0
  183. package/dist/esm/utilities/chat-params.js.map +1 -0
  184. package/dist/esm/utilities/errors.d.ts +13 -0
  185. package/dist/esm/utilities/errors.js +22 -0
  186. package/dist/esm/utilities/errors.js.map +1 -0
  187. package/dist/esm/utilities/media-prompt.d.ts +35 -0
  188. package/dist/esm/utilities/media-prompt.js +43 -0
  189. package/dist/esm/utilities/media-prompt.js.map +1 -0
  190. package/dist/esm/utilities/numbers.d.ts +8 -0
  191. package/dist/esm/utilities/numbers.js +12 -0
  192. package/dist/esm/utilities/numbers.js.map +1 -0
  193. package/dist/esm/utilities/sampling-keys.d.ts +20 -0
  194. package/dist/esm/utilities/sampling-keys.js +20 -0
  195. package/dist/esm/utilities/sampling-keys.js.map +1 -0
  196. package/dist/esm/utilities/tool-result.d.ts +21 -0
  197. package/dist/esm/utilities/tool-result.js +37 -0
  198. package/dist/esm/utilities/tool-result.js.map +1 -0
  199. package/dist/esm/utilities/usage.d.ts +31 -0
  200. package/dist/esm/utilities/usage.js +11 -0
  201. package/dist/esm/utilities/usage.js.map +1 -0
  202. package/dist/esm/utils.d.ts +17 -0
  203. package/dist/esm/utils.js +20 -0
  204. package/dist/esm/utils.js.map +1 -0
  205. package/package.json +3 -3
  206. package/skills/ai-core/chat-experience/SKILL.md +30 -2
  207. package/skills/ai-core/media-generation/SKILL.md +13 -0
  208. package/skills/ai-core/tool-calling/SKILL.md +10 -3
  209. package/src/activities/chat/mcp/manager.ts +31 -1
  210. package/src/activities/chat/mcp/types.ts +23 -0
  211. package/src/activities/chat/messages.ts +5 -0
  212. package/src/activities/chat/stream/processor.ts +42 -0
  213. package/src/activities/chat/tools/tool-calls.ts +96 -2
  214. package/src/client.ts +1 -0
  215. package/src/types.ts +31 -0
@@ -0,0 +1,145 @@
1
+ import { ModelInputModalitiesByName, VideoGenerationOptions, VideoJobResult, VideoStatusResult, VideoUrlResult } from '../../types.js';
2
+ /**
3
+ * Structured description of the durations a video model accepts.
4
+ *
5
+ * Tagged union so the same shape can express discrete enums (OpenAI Sora,
6
+ * Veo), continuous ranges, mixed shapes, and models with no duration field.
7
+ * Consumed by `VideoAdapter.availableDurations()`.
8
+ *
9
+ * @experimental Video generation is an experimental feature and may change.
10
+ */
11
+ export type DurationOptions<T extends string | number | undefined> = {
12
+ kind: 'discrete';
13
+ values: ReadonlyArray<NonNullable<T>>;
14
+ } | {
15
+ kind: 'range';
16
+ min: number;
17
+ max: number;
18
+ step?: number;
19
+ unit: 'seconds';
20
+ } | {
21
+ kind: 'mixed';
22
+ values: ReadonlyArray<NonNullable<T>>;
23
+ range?: {
24
+ min: number;
25
+ max: number;
26
+ step?: number;
27
+ };
28
+ } | {
29
+ kind: 'none';
30
+ };
31
+ /**
32
+ * Configuration for video adapter instances
33
+ *
34
+ * @experimental Video generation is an experimental feature and may change.
35
+ */
36
+ export interface VideoAdapterConfig {
37
+ apiKey?: string;
38
+ baseUrl?: string;
39
+ timeout?: number;
40
+ maxRetries?: number;
41
+ headers?: Record<string, string>;
42
+ }
43
+ /**
44
+ * Video adapter interface with pre-resolved generics.
45
+ *
46
+ * An adapter is created by a provider function: `provider('model')` → `adapter`
47
+ * All type resolution happens at the provider call site, not in this interface.
48
+ *
49
+ * @experimental Video generation is an experimental feature and may change.
50
+ *
51
+ * Generic parameters:
52
+ * - TModel: The specific model name (e.g., 'sora-2')
53
+ * - TProviderOptions: Provider-specific options (already resolved)
54
+ * - TModelProviderOptionsByName: Map from model name to its specific provider options
55
+ * - TModelSizeByName: Map from model name to its supported sizes
56
+ * - TModelInputModalitiesByName: Map from model name to the non-text prompt
57
+ * modalities it accepts (constrains the `prompt` part types at compile time)
58
+ * - TModelDurationByName: Map from model name to its supported duration
59
+ * union. Defaults to `Record<string, number>` so adapters that haven't
60
+ * declared a map keep today's `duration?: number` typing.
61
+ */
62
+ export interface VideoAdapter<TModel extends string = string, TProviderOptions extends object = Record<string, unknown>, TModelProviderOptionsByName extends Record<string, any> = Record<string, any>, TModelSizeByName extends Record<string, string | undefined> = Record<string, string>, TModelInputModalitiesByName extends ModelInputModalitiesByName = ModelInputModalitiesByName, TModelDurationByName extends Record<string, string | number | undefined> = Record<string, number>> {
63
+ /** Discriminator for adapter kind - used to determine API shape */
64
+ readonly kind: 'video';
65
+ /** Adapter name identifier */
66
+ readonly name: string;
67
+ /** The model this adapter is configured for */
68
+ readonly model: TModel;
69
+ /**
70
+ * @internal Type-only properties for inference. Not assigned at runtime.
71
+ */
72
+ '~types': {
73
+ providerOptions: TProviderOptions;
74
+ modelProviderOptionsByName: TModelProviderOptionsByName;
75
+ modelSizeByName: TModelSizeByName;
76
+ modelInputModalitiesByName: TModelInputModalitiesByName;
77
+ modelDurationByName: TModelDurationByName;
78
+ };
79
+ /**
80
+ * Create a new video generation job.
81
+ * Returns a job ID that can be used to poll for status and retrieve the video.
82
+ */
83
+ createVideoJob: (options: VideoGenerationOptions<TProviderOptions, TModelSizeByName[TModel], TModelDurationByName[TModel]>) => Promise<VideoJobResult>;
84
+ /**
85
+ * Get the current status of a video generation job.
86
+ */
87
+ getVideoStatus: (jobId: string) => Promise<VideoStatusResult>;
88
+ /**
89
+ * Get the URL to download/view the generated video.
90
+ * Should only be called after status is 'completed'.
91
+ */
92
+ getVideoUrl: (jobId: string) => Promise<VideoUrlResult>;
93
+ /**
94
+ * Describe the durations this adapter's model accepts. Returns a tagged
95
+ * union so consumers can render UI / coerce input without provider-specific
96
+ * knowledge.
97
+ */
98
+ availableDurations: () => DurationOptions<TModelDurationByName[TModel]>;
99
+ /**
100
+ * Coerce a raw seconds value to the closest valid duration for this model.
101
+ * Returns `undefined` for models with no duration field.
102
+ */
103
+ snapDuration: (seconds: number) => TModelDurationByName[TModel] | undefined;
104
+ }
105
+ /**
106
+ * A VideoAdapter with any/unknown type parameters.
107
+ * Useful as a constraint in generic functions and interfaces.
108
+ */
109
+ export type AnyVideoAdapter = VideoAdapter<any, any, any, any, any, any>;
110
+ /**
111
+ * Abstract base class for video generation adapters.
112
+ * Extend this class to implement a video adapter for a specific provider.
113
+ *
114
+ * @experimental Video generation is an experimental feature and may change.
115
+ *
116
+ * Generic parameters match VideoAdapter - all pre-resolved by the provider function.
117
+ */
118
+ export declare abstract class BaseVideoAdapter<TModel extends string = string, TProviderOptions extends object = Record<string, unknown>, TModelProviderOptionsByName extends Record<string, any> = Record<string, any>, TModelSizeByName extends Record<string, string | undefined> = Record<string, string>, TModelInputModalitiesByName extends ModelInputModalitiesByName = ModelInputModalitiesByName, TModelDurationByName extends Record<string, string | number | undefined> = Record<string, number>> implements VideoAdapter<TModel, TProviderOptions, TModelProviderOptionsByName, TModelSizeByName, TModelInputModalitiesByName, TModelDurationByName> {
119
+ readonly kind: "video";
120
+ abstract readonly name: string;
121
+ readonly model: TModel;
122
+ '~types': {
123
+ providerOptions: TProviderOptions;
124
+ modelProviderOptionsByName: TModelProviderOptionsByName;
125
+ modelSizeByName: TModelSizeByName;
126
+ modelInputModalitiesByName: TModelInputModalitiesByName;
127
+ modelDurationByName: TModelDurationByName;
128
+ };
129
+ protected config: VideoAdapterConfig;
130
+ constructor(config: VideoAdapterConfig | undefined, model: TModel);
131
+ abstract createVideoJob(options: VideoGenerationOptions<TProviderOptions, TModelSizeByName[TModel], TModelDurationByName[TModel]>): Promise<VideoJobResult>;
132
+ abstract getVideoStatus(jobId: string): Promise<VideoStatusResult>;
133
+ abstract getVideoUrl(jobId: string): Promise<VideoUrlResult>;
134
+ /**
135
+ * Default implementation returns `{ kind: 'none' }`. Adapters that have
136
+ * declared their per-model duration map should override this.
137
+ */
138
+ availableDurations(): DurationOptions<TModelDurationByName[TModel]>;
139
+ /**
140
+ * Default implementation returns `undefined`. Adapters that have declared
141
+ * their per-model duration map should override.
142
+ */
143
+ snapDuration(_seconds: number): TModelDurationByName[TModel] | undefined;
144
+ protected generateId(): string;
145
+ }
@@ -0,0 +1,30 @@
1
+ class BaseVideoAdapter {
2
+ kind = "video";
3
+ model;
4
+ config;
5
+ constructor(config = {}, model) {
6
+ this.config = config;
7
+ this.model = model;
8
+ }
9
+ /**
10
+ * Default implementation returns `{ kind: 'none' }`. Adapters that have
11
+ * declared their per-model duration map should override this.
12
+ */
13
+ availableDurations() {
14
+ return { kind: "none" };
15
+ }
16
+ /**
17
+ * Default implementation returns `undefined`. Adapters that have declared
18
+ * their per-model duration map should override.
19
+ */
20
+ snapDuration(_seconds) {
21
+ return void 0;
22
+ }
23
+ generateId() {
24
+ return `${this.name}-${Date.now()}-${Math.random().toString(36).substring(7)}`;
25
+ }
26
+ }
27
+ export {
28
+ BaseVideoAdapter
29
+ };
30
+ //# sourceMappingURL=adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.js","sources":["../../../../src/activities/generateVideo/adapter.ts"],"sourcesContent":["import type {\n ModelInputModalitiesByName,\n VideoGenerationOptions,\n VideoJobResult,\n VideoStatusResult,\n VideoUrlResult,\n} from '../../types'\n\n/**\n * Structured description of the durations a video model accepts.\n *\n * Tagged union so the same shape can express discrete enums (OpenAI Sora,\n * Veo), continuous ranges, mixed shapes, and models with no duration field.\n * Consumed by `VideoAdapter.availableDurations()`.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport type DurationOptions<T extends string | number | undefined> =\n | { kind: 'discrete'; values: ReadonlyArray<NonNullable<T>> }\n | { kind: 'range'; min: number; max: number; step?: number; unit: 'seconds' }\n | {\n kind: 'mixed'\n values: ReadonlyArray<NonNullable<T>>\n range?: { min: number; max: number; step?: number }\n }\n | { kind: 'none' }\n\n/**\n * Configuration for video adapter instances\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport interface VideoAdapterConfig {\n apiKey?: string\n baseUrl?: string\n timeout?: number\n maxRetries?: number\n headers?: Record<string, string>\n}\n\n/**\n * Video adapter interface with pre-resolved generics.\n *\n * An adapter is created by a provider function: `provider('model')` → `adapter`\n * All type resolution happens at the provider call site, not in this interface.\n *\n * @experimental Video generation is an experimental feature and may change.\n *\n * Generic parameters:\n * - TModel: The specific model name (e.g., 'sora-2')\n * - TProviderOptions: Provider-specific options (already resolved)\n * - TModelProviderOptionsByName: Map from model name to its specific provider options\n * - TModelSizeByName: Map from model name to its supported sizes\n * - TModelInputModalitiesByName: Map from model name to the non-text prompt\n * modalities it accepts (constrains the `prompt` part types at compile time)\n * - TModelDurationByName: Map from model name to its supported duration\n * union. Defaults to `Record<string, number>` so adapters that haven't\n * declared a map keep today's `duration?: number` typing.\n */\nexport interface VideoAdapter<\n TModel extends string = string,\n TProviderOptions extends object = Record<string, unknown>,\n TModelProviderOptionsByName extends Record<string, any> = Record<string, any>,\n TModelSizeByName extends Record<string, string | undefined> = Record<\n string,\n string\n >,\n TModelInputModalitiesByName extends ModelInputModalitiesByName =\n ModelInputModalitiesByName,\n TModelDurationByName extends Record<string, string | number | undefined> =\n Record<string, number>,\n> {\n /** Discriminator for adapter kind - used to determine API shape */\n readonly kind: 'video'\n /** Adapter name identifier */\n readonly name: string\n /** The model this adapter is configured for */\n readonly model: TModel\n\n /**\n * @internal Type-only properties for inference. Not assigned at runtime.\n */\n '~types': {\n providerOptions: TProviderOptions\n modelProviderOptionsByName: TModelProviderOptionsByName\n modelSizeByName: TModelSizeByName\n modelInputModalitiesByName: TModelInputModalitiesByName\n modelDurationByName: TModelDurationByName\n }\n\n /**\n * Create a new video generation job.\n * Returns a job ID that can be used to poll for status and retrieve the video.\n */\n createVideoJob: (\n options: VideoGenerationOptions<\n TProviderOptions,\n TModelSizeByName[TModel],\n TModelDurationByName[TModel]\n >,\n ) => Promise<VideoJobResult>\n\n /**\n * Get the current status of a video generation job.\n */\n getVideoStatus: (jobId: string) => Promise<VideoStatusResult>\n\n /**\n * Get the URL to download/view the generated video.\n * Should only be called after status is 'completed'.\n */\n getVideoUrl: (jobId: string) => Promise<VideoUrlResult>\n\n /**\n * Describe the durations this adapter's model accepts. Returns a tagged\n * union so consumers can render UI / coerce input without provider-specific\n * knowledge.\n */\n availableDurations: () => DurationOptions<TModelDurationByName[TModel]>\n\n /**\n * Coerce a raw seconds value to the closest valid duration for this model.\n * Returns `undefined` for models with no duration field.\n */\n snapDuration: (seconds: number) => TModelDurationByName[TModel] | undefined\n}\n\n/**\n * A VideoAdapter with any/unknown type parameters.\n * Useful as a constraint in generic functions and interfaces.\n */\nexport type AnyVideoAdapter = VideoAdapter<any, any, any, any, any, any>\n\n/**\n * Abstract base class for video generation adapters.\n * Extend this class to implement a video adapter for a specific provider.\n *\n * @experimental Video generation is an experimental feature and may change.\n *\n * Generic parameters match VideoAdapter - all pre-resolved by the provider function.\n */\nexport abstract class BaseVideoAdapter<\n TModel extends string = string,\n TProviderOptions extends object = Record<string, unknown>,\n TModelProviderOptionsByName extends Record<string, any> = Record<string, any>,\n TModelSizeByName extends Record<string, string | undefined> = Record<\n string,\n string\n >,\n TModelInputModalitiesByName extends ModelInputModalitiesByName =\n ModelInputModalitiesByName,\n TModelDurationByName extends Record<string, string | number | undefined> =\n Record<string, number>,\n> implements VideoAdapter<\n TModel,\n TProviderOptions,\n TModelProviderOptionsByName,\n TModelSizeByName,\n TModelInputModalitiesByName,\n TModelDurationByName\n> {\n readonly kind = 'video' as const\n abstract readonly name: string\n readonly model: TModel\n\n // Type-only property - never assigned at runtime\n declare '~types': {\n providerOptions: TProviderOptions\n modelProviderOptionsByName: TModelProviderOptionsByName\n modelSizeByName: TModelSizeByName\n modelInputModalitiesByName: TModelInputModalitiesByName\n modelDurationByName: TModelDurationByName\n }\n\n protected config: VideoAdapterConfig\n\n constructor(config: VideoAdapterConfig = {}, model: TModel) {\n this.config = config\n this.model = model\n }\n\n abstract createVideoJob(\n options: VideoGenerationOptions<\n TProviderOptions,\n TModelSizeByName[TModel],\n TModelDurationByName[TModel]\n >,\n ): Promise<VideoJobResult>\n\n abstract getVideoStatus(jobId: string): Promise<VideoStatusResult>\n\n abstract getVideoUrl(jobId: string): Promise<VideoUrlResult>\n\n /**\n * Default implementation returns `{ kind: 'none' }`. Adapters that have\n * declared their per-model duration map should override this.\n */\n availableDurations(): DurationOptions<TModelDurationByName[TModel]> {\n return { kind: 'none' }\n }\n\n /**\n * Default implementation returns `undefined`. Adapters that have declared\n * their per-model duration map should override.\n */\n snapDuration(_seconds: number): TModelDurationByName[TModel] | undefined {\n return undefined\n }\n\n protected generateId(): string {\n return `${this.name}-${Date.now()}-${Math.random().toString(36).substring(7)}`\n }\n}\n"],"names":[],"mappings":"AA6IO,MAAe,iBAmBpB;AAAA,EACS,OAAO;AAAA,EAEP;AAAA,EAWC;AAAA,EAEV,YAAY,SAA6B,CAAA,GAAI,OAAe;AAC1D,SAAK,SAAS;AACd,SAAK,QAAQ;AAAA,EACf;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBA,qBAAoE;AAClE,WAAO,EAAE,MAAM,OAAA;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,aAAa,UAA4D;AACvE,WAAO;AAAA,EACT;AAAA,EAEU,aAAqB;AAC7B,WAAO,GAAG,KAAK,IAAI,IAAI,KAAK,KAAK,IAAI,KAAK,OAAA,EAAS,SAAS,EAAE,EAAE,UAAU,CAAC,CAAC;AAAA,EAC9E;AACF;"}
@@ -0,0 +1,223 @@
1
+ import { DebugOption } from '../../logger/types.js';
2
+ import { GenerationMiddleware } from '../middleware.js';
3
+ import { VideoAdapter } from './adapter.js';
4
+ import { MediaPrompt, MediaPromptFor, StreamChunk, TokenUsage, VideoJobResult, VideoStatusResult, VideoUrlResult } from '../../types.js';
5
+ /** The adapter kind this activity handles */
6
+ export declare const kind: "video";
7
+ /**
8
+ * Extract provider options from a VideoAdapter via ~types.
9
+ */
10
+ export type VideoProviderOptions<TAdapter> = TAdapter extends VideoAdapter<any, any, any, any> ? TAdapter['~types']['providerOptions'] : object;
11
+ /**
12
+ * Extract the size type for a VideoAdapter's model via ~types.
13
+ */
14
+ export type VideoSizeForAdapter<TAdapter> = TAdapter extends VideoAdapter<infer TModel, any, any, infer TSizeMap> ? TModel extends keyof TSizeMap ? TSizeMap[TModel] : string : string;
15
+ /**
16
+ * Extract the prompt type a model accepts from a VideoAdapter via ~types.
17
+ * Mirrors `ImagePromptForModel`: models in the adapter's input-modality map
18
+ * get a `prompt` narrowed to text + their supported part types; adapters
19
+ * without a map fall back to the full MediaPrompt.
20
+ */
21
+ export type VideoPromptForAdapter<TAdapter> = TAdapter extends VideoAdapter<infer TModel, any, any, any, infer ModsByName> ? string extends keyof ModsByName ? MediaPrompt : TModel extends keyof ModsByName ? MediaPromptFor<ModsByName[TModel][number]> : MediaPrompt : MediaPrompt;
22
+ /**
23
+ * Extract the duration type for a VideoAdapter's model via ~types.
24
+ * Mirrors `VideoSizeForAdapter`. Falls back to `number` for adapters that
25
+ * haven't declared per-model duration constraints.
26
+ */
27
+ export type VideoDurationForAdapter<TAdapter> = TAdapter extends VideoAdapter<infer TModel, any, any, any, any, infer TDurationMap> ? TModel extends keyof TDurationMap ? TDurationMap[TModel] : number : number;
28
+ /**
29
+ * Base options shared by all video activity operations.
30
+ * The model is extracted from the adapter's model property.
31
+ */
32
+ interface VideoActivityBaseOptions<TAdapter extends VideoAdapter<string, any, any, any>> {
33
+ /** The video adapter to use (must be created with a model) */
34
+ adapter: TAdapter & {
35
+ kind: typeof kind;
36
+ };
37
+ }
38
+ /**
39
+ * Options for creating a new video generation job.
40
+ * The model is extracted from the adapter's model property.
41
+ *
42
+ * @template TAdapter - The video adapter type
43
+ * @template TStream - Whether to stream the output
44
+ *
45
+ * @experimental Video generation is an experimental feature and may change.
46
+ */
47
+ export type VideoCreateOptions<TAdapter extends VideoAdapter<string, any, any, any>, TStream extends boolean = false> = VideoActivityBaseOptions<TAdapter> & {
48
+ /** Request type - create a new job (default if not specified) */
49
+ request?: 'create';
50
+ /**
51
+ * Description of the desired video. Either a plain string, or — for models
52
+ * that support image-conditioned generation — an ordered array of content
53
+ * parts interleaving text with image inputs. Image parts may carry
54
+ * `metadata.role` (`'start_frame' | 'end_frame' | 'reference' |
55
+ * 'character'`) to disambiguate intent; positional fallback otherwise. The
56
+ * accepted part types are narrowed per model via the adapter's
57
+ * input-modality map.
58
+ */
59
+ prompt: VideoPromptForAdapter<TAdapter>;
60
+ /** Video size — format depends on the provider (e.g., "16:9", "1280x720") */
61
+ size?: VideoSizeForAdapter<TAdapter>;
62
+ /**
63
+ * Video duration in seconds. Adapters that declare a per-model duration
64
+ * map narrow this to the model's valid union (e.g. `4 | 6 | 8` for Veo 3).
65
+ * Pass `adapter.snapDuration(seconds)` to coerce raw seconds to a valid
66
+ * value.
67
+ */
68
+ duration?: VideoDurationForAdapter<TAdapter>;
69
+ /**
70
+ * Whether to stream the video generation lifecycle.
71
+ * When true, returns an AsyncIterable<StreamChunk> that handles the full
72
+ * job lifecycle: create job, poll for status, yield updates, and yield final result.
73
+ * When false or not provided, returns a Promise<VideoJobResult>.
74
+ *
75
+ * @default false
76
+ */
77
+ stream?: TStream;
78
+ /** Polling interval in milliseconds (stream mode only). @default 2000 */
79
+ pollingInterval?: number;
80
+ /** Maximum time to wait before timing out in milliseconds (stream mode only). @default 600000 */
81
+ maxDuration?: number;
82
+ /** Custom run ID (stream mode only) */
83
+ runId?: string;
84
+ /**
85
+ * Enable debug logging. Pass `true` to enable all categories, `false` to
86
+ * silence everything including errors, or a `DebugConfig` object for granular
87
+ * control and/or a custom `Logger`.
88
+ */
89
+ debug?: DebugOption;
90
+ /**
91
+ * Observe-only middleware notified on start, usage, success, and error. Pass
92
+ * `otelMiddleware()` to emit OpenTelemetry spans, or implement the
93
+ * `GenerationMiddleware` contract for a custom backend. In streaming mode the
94
+ * span covers the full create→poll→complete lifecycle; in non-streaming mode
95
+ * it covers job submission. An abandoned stream fires `onAbort`.
96
+ */
97
+ middleware?: Array<GenerationMiddleware>;
98
+ } & ({} extends VideoProviderOptions<TAdapter> ? {
99
+ /** Provider-specific options for video generation */ modelOptions?: VideoProviderOptions<TAdapter>;
100
+ } : {
101
+ /** Provider-specific options for video generation */ modelOptions: VideoProviderOptions<TAdapter>;
102
+ });
103
+ /**
104
+ * Options for polling the status of a video generation job.
105
+ *
106
+ * @experimental Video generation is an experimental feature and may change.
107
+ */
108
+ export interface VideoStatusOptions<TAdapter extends VideoAdapter<string, any, any, any>> extends VideoActivityBaseOptions<TAdapter> {
109
+ /** Request type - get job status */
110
+ request: 'status';
111
+ /** The job ID to check status for */
112
+ jobId: string;
113
+ }
114
+ /**
115
+ * Options for getting the URL of a completed video.
116
+ *
117
+ * @experimental Video generation is an experimental feature and may change.
118
+ */
119
+ export interface VideoUrlOptions<TAdapter extends VideoAdapter<string, any, any, any>> extends VideoActivityBaseOptions<TAdapter> {
120
+ /** Request type - get video URL */
121
+ request: 'url';
122
+ /** The job ID to get URL for */
123
+ jobId: string;
124
+ }
125
+ /**
126
+ * Union type for all video activity options.
127
+ * Discriminated by the `request` field.
128
+ *
129
+ * @experimental Video generation is an experimental feature and may change.
130
+ */
131
+ export type VideoActivityOptions<TAdapter extends VideoAdapter<string, any, any, any>, TRequest extends 'create' | 'status' | 'url' = 'create', TStream extends boolean = false> = TRequest extends 'status' ? VideoStatusOptions<TAdapter> : TRequest extends 'url' ? VideoUrlOptions<TAdapter> : VideoCreateOptions<TAdapter, TStream>;
132
+ /**
133
+ * Result type for the video activity, based on request type and streaming.
134
+ * - If stream is true (create request): AsyncIterable<StreamChunk>
135
+ * - Otherwise: Promise<VideoJobResult | VideoStatusResult | VideoUrlResult>
136
+ *
137
+ * @experimental Video generation is an experimental feature and may change.
138
+ */
139
+ export type VideoActivityResult<TRequest extends 'create' | 'status' | 'url' = 'create', TStream extends boolean = false> = TRequest extends 'status' ? Promise<VideoStatusResult> : TRequest extends 'url' ? Promise<VideoUrlResult> : TStream extends true ? AsyncIterable<StreamChunk> : Promise<VideoJobResult>;
140
+ /**
141
+ * Generate video - creates a video generation job from a text prompt.
142
+ *
143
+ * Uses AI video generation models to create videos based on natural language descriptions.
144
+ * Unlike image generation, video generation is asynchronous and requires polling for completion.
145
+ *
146
+ * When `stream: true` is passed, handles the full job lifecycle automatically:
147
+ * create job → poll for status → stream updates → yield final result.
148
+ *
149
+ * @experimental Video generation is an experimental feature and may change.
150
+ *
151
+ * @example Create a video generation job
152
+ * ```ts
153
+ * import { generateVideo } from '@tanstack/ai'
154
+ * import { openaiVideo } from '@tanstack/ai-openai'
155
+ *
156
+ * // Start a video generation job
157
+ * const { jobId } = await generateVideo({
158
+ * adapter: openaiVideo('sora-2'),
159
+ * prompt: 'A cat chasing a dog in a sunny park'
160
+ * })
161
+ *
162
+ * console.log('Job started:', jobId)
163
+ * ```
164
+ *
165
+ * @example Stream the full video generation lifecycle
166
+ * ```ts
167
+ * import { generateVideo, toServerSentEventsResponse } from '@tanstack/ai'
168
+ * import { openaiVideo } from '@tanstack/ai-openai'
169
+ *
170
+ * const stream = generateVideo({
171
+ * adapter: openaiVideo('sora-2'),
172
+ * prompt: 'A cat chasing a dog in a sunny park',
173
+ * stream: true,
174
+ * pollingInterval: 3000,
175
+ * })
176
+ *
177
+ * return toServerSentEventsResponse(stream)
178
+ * ```
179
+ */
180
+ export declare function generateVideo<TAdapter extends VideoAdapter<string, any, any, any>, TStream extends boolean = false>(options: VideoCreateOptions<TAdapter, TStream>): VideoActivityResult<'create', TStream>;
181
+ /**
182
+ * Get video job status - returns the current status, progress, and URL if available.
183
+ *
184
+ * This function combines status checking and URL retrieval. If the job is completed,
185
+ * it will automatically fetch and include the video URL.
186
+ *
187
+ * @experimental Video generation is an experimental feature and may change.
188
+ *
189
+ * @example Check job status
190
+ * ```ts
191
+ * import { getVideoJobStatus } from '@tanstack/ai'
192
+ * import { openaiVideo } from '@tanstack/ai-openai'
193
+ *
194
+ * const result = await getVideoJobStatus({
195
+ * adapter: openaiVideo('sora-2'),
196
+ * jobId: 'job-123'
197
+ * })
198
+ *
199
+ * console.log('Status:', result.status)
200
+ * console.log('Progress:', result.progress)
201
+ * if (result.url) {
202
+ * console.log('Video URL:', result.url)
203
+ * }
204
+ * ```
205
+ */
206
+ export declare function getVideoJobStatus<TAdapter extends VideoAdapter<string, any, any, any>>(options: {
207
+ adapter: TAdapter & {
208
+ kind: typeof kind;
209
+ };
210
+ jobId: string;
211
+ }): Promise<{
212
+ status: 'pending' | 'processing' | 'completed' | 'failed';
213
+ progress?: number;
214
+ url?: string;
215
+ error?: string;
216
+ usage?: TokenUsage;
217
+ }>;
218
+ /**
219
+ * Create typed options for the generateVideo() function without executing.
220
+ */
221
+ export declare function createVideoOptions<TAdapter extends VideoAdapter<string, any, any, any>, TStream extends boolean = false>(options: VideoCreateOptions<TAdapter, TStream>): VideoCreateOptions<TAdapter, TStream>;
222
+ export type { VideoAdapter, VideoAdapterConfig, AnyVideoAdapter, } from './adapter.js';
223
+ export { BaseVideoAdapter } from './adapter.js';