@tanstack/ai 0.0.2 → 0.1.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 (147) hide show
  1. package/README.md +26 -0
  2. package/dist/esm/activities/chat/adapter.d.ts +100 -0
  3. package/dist/esm/activities/chat/adapter.js +14 -0
  4. package/dist/esm/activities/chat/adapter.js.map +1 -0
  5. package/dist/esm/{utilities → activities/chat}/agent-loop-strategies.d.ts +4 -4
  6. package/dist/esm/activities/chat/agent-loop-strategies.js.map +1 -0
  7. package/dist/esm/activities/chat/index.d.ts +165 -0
  8. package/dist/esm/{core/chat.js → activities/chat/index.js} +131 -33
  9. package/dist/esm/activities/chat/index.js.map +1 -0
  10. package/dist/esm/{message-converters.d.ts → activities/chat/messages.d.ts} +1 -1
  11. package/dist/esm/{message-converters.js → activities/chat/messages.js} +7 -7
  12. package/dist/esm/activities/chat/messages.js.map +1 -0
  13. package/dist/esm/activities/chat/stream/json-parser.js.map +1 -0
  14. package/dist/esm/{stream → activities/chat/stream}/message-updaters.d.ts +1 -1
  15. package/dist/esm/activities/chat/stream/message-updaters.js.map +1 -0
  16. package/dist/esm/{stream → activities/chat/stream}/processor.d.ts +1 -1
  17. package/dist/esm/{stream → activities/chat/stream}/processor.js +1 -1
  18. package/dist/esm/activities/chat/stream/processor.js.map +1 -0
  19. package/dist/esm/activities/chat/stream/strategies.js.map +1 -0
  20. package/dist/esm/{stream → activities/chat/stream}/types.d.ts +2 -9
  21. package/dist/esm/{tools → activities/chat/tools}/tool-calls.d.ts +1 -1
  22. package/dist/esm/{tools → activities/chat/tools}/tool-calls.js +9 -5
  23. package/dist/esm/activities/chat/tools/tool-calls.js.map +1 -0
  24. package/dist/esm/{tools → activities/chat/tools}/tool-definition.d.ts +14 -14
  25. package/dist/esm/activities/chat/tools/tool-definition.js.map +1 -0
  26. package/dist/esm/activities/chat/tools/zod-converter.d.ts +69 -0
  27. package/dist/esm/activities/chat/tools/zod-converter.js +99 -0
  28. package/dist/esm/activities/chat/tools/zod-converter.js.map +1 -0
  29. package/dist/esm/activities/generateImage/adapter.d.ts +68 -0
  30. package/dist/esm/activities/generateImage/adapter.js +14 -0
  31. package/dist/esm/activities/generateImage/adapter.js.map +1 -0
  32. package/dist/esm/activities/generateImage/index.d.ts +89 -0
  33. package/dist/esm/activities/generateImage/index.js +15 -0
  34. package/dist/esm/activities/generateImage/index.js.map +1 -0
  35. package/dist/esm/activities/generateSpeech/adapter.d.ts +62 -0
  36. package/dist/esm/activities/generateSpeech/adapter.js +14 -0
  37. package/dist/esm/activities/generateSpeech/adapter.js.map +1 -0
  38. package/dist/esm/activities/generateSpeech/index.d.ts +69 -0
  39. package/dist/esm/activities/generateSpeech/index.js +15 -0
  40. package/dist/esm/activities/generateSpeech/index.js.map +1 -0
  41. package/dist/esm/activities/generateTranscription/adapter.d.ts +62 -0
  42. package/dist/esm/activities/generateTranscription/adapter.js +14 -0
  43. package/dist/esm/activities/generateTranscription/adapter.js.map +1 -0
  44. package/dist/esm/activities/generateTranscription/index.d.ts +71 -0
  45. package/dist/esm/activities/generateTranscription/index.js +15 -0
  46. package/dist/esm/activities/generateTranscription/index.js.map +1 -0
  47. package/dist/esm/activities/generateVideo/adapter.d.ts +80 -0
  48. package/dist/esm/activities/generateVideo/adapter.js +14 -0
  49. package/dist/esm/activities/generateVideo/adapter.js.map +1 -0
  50. package/dist/esm/activities/generateVideo/index.d.ts +136 -0
  51. package/dist/esm/activities/generateVideo/index.js +47 -0
  52. package/dist/esm/activities/generateVideo/index.js.map +1 -0
  53. package/dist/esm/activities/index.d.ts +22 -0
  54. package/dist/esm/activities/index.js +34 -0
  55. package/dist/esm/activities/index.js.map +1 -0
  56. package/dist/esm/activities/summarize/adapter.d.ts +74 -0
  57. package/dist/esm/activities/summarize/adapter.js +14 -0
  58. package/dist/esm/activities/summarize/adapter.js.map +1 -0
  59. package/dist/esm/activities/summarize/index.d.ts +100 -0
  60. package/dist/esm/activities/summarize/index.js +90 -0
  61. package/dist/esm/activities/summarize/index.js.map +1 -0
  62. package/dist/esm/event-client.d.ts +4 -45
  63. package/dist/esm/event-client.js +0 -49
  64. package/dist/esm/event-client.js.map +1 -1
  65. package/dist/esm/index.d.ts +16 -14
  66. package/dist/esm/index.js +28 -19
  67. package/dist/esm/stream-to-response.d.ts +95 -0
  68. package/dist/esm/stream-to-response.js +118 -0
  69. package/dist/esm/stream-to-response.js.map +1 -0
  70. package/dist/esm/types.d.ts +347 -129
  71. package/package.json +6 -2
  72. package/src/activities/chat/adapter.ts +150 -0
  73. package/src/{utilities → activities/chat}/agent-loop-strategies.ts +4 -4
  74. package/src/{core/chat.ts → activities/chat/index.ts} +427 -79
  75. package/src/{message-converters.ts → activities/chat/messages.ts} +10 -13
  76. package/src/{stream → activities/chat/stream}/message-updaters.ts +1 -1
  77. package/src/{stream → activities/chat/stream}/processor.ts +2 -5
  78. package/src/{stream → activities/chat/stream}/types.ts +8 -18
  79. package/src/{tools → activities/chat/tools}/tool-calls.ts +36 -11
  80. package/src/{tools → activities/chat/tools}/tool-definition.ts +36 -27
  81. package/src/activities/chat/tools/zod-converter.ts +235 -0
  82. package/src/activities/generateImage/adapter.ts +104 -0
  83. package/src/activities/generateImage/index.ts +162 -0
  84. package/src/activities/generateSpeech/adapter.ts +87 -0
  85. package/src/activities/generateSpeech/index.ts +122 -0
  86. package/src/activities/generateTranscription/adapter.ts +89 -0
  87. package/src/activities/generateTranscription/index.ts +132 -0
  88. package/src/activities/generateVideo/adapter.ts +116 -0
  89. package/src/activities/generateVideo/index.ts +261 -0
  90. package/src/activities/index.ts +164 -0
  91. package/src/activities/summarize/adapter.ts +107 -0
  92. package/src/activities/summarize/index.ts +287 -0
  93. package/src/event-client.ts +5 -101
  94. package/src/index.ts +58 -15
  95. package/src/stream-to-response.ts +237 -0
  96. package/src/types.ts +404 -280
  97. package/dist/esm/base-adapter.d.ts +0 -36
  98. package/dist/esm/base-adapter.js +0 -12
  99. package/dist/esm/base-adapter.js.map +0 -1
  100. package/dist/esm/core/chat-common-options.d.ts +0 -52
  101. package/dist/esm/core/chat.d.ts +0 -30
  102. package/dist/esm/core/chat.js.map +0 -1
  103. package/dist/esm/core/embedding.d.ts +0 -8
  104. package/dist/esm/core/embedding.js +0 -33
  105. package/dist/esm/core/embedding.js.map +0 -1
  106. package/dist/esm/core/summarize.d.ts +0 -9
  107. package/dist/esm/core/summarize.js +0 -36
  108. package/dist/esm/core/summarize.js.map +0 -1
  109. package/dist/esm/message-converters.js.map +0 -1
  110. package/dist/esm/stream/json-parser.js.map +0 -1
  111. package/dist/esm/stream/message-updaters.js.map +0 -1
  112. package/dist/esm/stream/processor.js.map +0 -1
  113. package/dist/esm/stream/strategies.js.map +0 -1
  114. package/dist/esm/tools/tool-calls.js.map +0 -1
  115. package/dist/esm/tools/tool-definition.js.map +0 -1
  116. package/dist/esm/tools/zod-converter.d.ts +0 -30
  117. package/dist/esm/tools/zod-converter.js +0 -36
  118. package/dist/esm/tools/zod-converter.js.map +0 -1
  119. package/dist/esm/utilities/agent-loop-strategies.js.map +0 -1
  120. package/dist/esm/utilities/chat-options.d.ts +0 -6
  121. package/dist/esm/utilities/chat-options.js +0 -7
  122. package/dist/esm/utilities/chat-options.js.map +0 -1
  123. package/dist/esm/utilities/messages.d.ts +0 -30
  124. package/dist/esm/utilities/messages.js +0 -7
  125. package/dist/esm/utilities/messages.js.map +0 -1
  126. package/dist/esm/utilities/stream-to-response.d.ts +0 -48
  127. package/dist/esm/utilities/stream-to-response.js +0 -62
  128. package/dist/esm/utilities/stream-to-response.js.map +0 -1
  129. package/src/base-adapter.ts +0 -86
  130. package/src/core/chat-common-options.ts +0 -55
  131. package/src/core/embedding.ts +0 -54
  132. package/src/core/summarize.ts +0 -56
  133. package/src/tools/zod-converter.ts +0 -85
  134. package/src/utilities/chat-options.ts +0 -35
  135. package/src/utilities/messages.ts +0 -63
  136. package/src/utilities/stream-to-response.ts +0 -116
  137. /package/dist/esm/{utilities → activities/chat}/agent-loop-strategies.js +0 -0
  138. /package/dist/esm/{stream → activities/chat/stream}/index.d.ts +0 -0
  139. /package/dist/esm/{stream → activities/chat/stream}/json-parser.d.ts +0 -0
  140. /package/dist/esm/{stream → activities/chat/stream}/json-parser.js +0 -0
  141. /package/dist/esm/{stream → activities/chat/stream}/message-updaters.js +0 -0
  142. /package/dist/esm/{stream → activities/chat/stream}/strategies.d.ts +0 -0
  143. /package/dist/esm/{stream → activities/chat/stream}/strategies.js +0 -0
  144. /package/dist/esm/{tools → activities/chat/tools}/tool-definition.js +0 -0
  145. /package/src/{stream → activities/chat/stream}/index.ts +0 -0
  146. /package/src/{stream → activities/chat/stream}/json-parser.ts +0 -0
  147. /package/src/{stream → activities/chat/stream}/strategies.ts +0 -0
@@ -0,0 +1,14 @@
1
+ class BaseTranscriptionAdapter {
2
+ constructor(config = {}, model) {
3
+ this.kind = "transcription";
4
+ this.config = config;
5
+ this.model = model;
6
+ }
7
+ generateId() {
8
+ return `${this.name}-${Date.now()}-${Math.random().toString(36).substring(7)}`;
9
+ }
10
+ }
11
+ export {
12
+ BaseTranscriptionAdapter
13
+ };
14
+ //# sourceMappingURL=adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.js","sources":["../../../../src/activities/generateTranscription/adapter.ts"],"sourcesContent":["import type { TranscriptionOptions, TranscriptionResult } from '../../types'\n\n/**\n * Configuration for transcription adapter instances\n */\nexport interface TranscriptionAdapterConfig {\n apiKey?: string\n baseUrl?: string\n timeout?: number\n maxRetries?: number\n headers?: Record<string, string>\n}\n\n/**\n * Transcription 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 * Generic parameters:\n * - TModel: The specific model name (e.g., 'whisper-1')\n * - TProviderOptions: Provider-specific options (already resolved)\n */\nexport interface TranscriptionAdapter<\n TModel extends string = string,\n TProviderOptions extends object = Record<string, unknown>,\n> {\n /** Discriminator for adapter kind - used to determine API shape */\n readonly kind: 'transcription'\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 }\n\n /**\n * Transcribe audio to text\n */\n transcribe: (\n options: TranscriptionOptions<TProviderOptions>,\n ) => Promise<TranscriptionResult>\n}\n\n/**\n * A TranscriptionAdapter with any/unknown type parameters.\n * Useful as a constraint in generic functions and interfaces.\n */\nexport type AnyTranscriptionAdapter = TranscriptionAdapter<any, any>\n\n/**\n * Abstract base class for audio transcription adapters.\n * Extend this class to implement a transcription adapter for a specific provider.\n *\n * Generic parameters match TranscriptionAdapter - all pre-resolved by the provider function.\n */\nexport abstract class BaseTranscriptionAdapter<\n TModel extends string = string,\n TProviderOptions extends object = Record<string, unknown>,\n> implements TranscriptionAdapter<TModel, TProviderOptions> {\n readonly kind = 'transcription' 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 }\n\n protected config: TranscriptionAdapterConfig\n\n constructor(config: TranscriptionAdapterConfig = {}, model: TModel) {\n this.config = config\n this.model = model\n }\n\n abstract transcribe(\n options: TranscriptionOptions<TProviderOptions>,\n ): Promise<TranscriptionResult>\n\n protected generateId(): string {\n return `${this.name}-${Date.now()}-${Math.random().toString(36).substring(7)}`\n }\n}\n"],"names":[],"mappings":"AA6DO,MAAe,yBAGsC;AAAA,EAY1D,YAAY,SAAqC,CAAA,GAAI,OAAe;AAXpE,SAAS,OAAO;AAYd,SAAK,SAAS;AACd,SAAK,QAAQ;AAAA,EACf;AAAA,EAMU,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,71 @@
1
+ import { TranscriptionAdapter } from './adapter.js';
2
+ import { TranscriptionResult } from '../../types.js';
3
+ /** The adapter kind this activity handles */
4
+ export declare const kind: "transcription";
5
+ /**
6
+ * Extract provider options from a TranscriptionAdapter via ~types.
7
+ */
8
+ export type TranscriptionProviderOptions<TAdapter> = TAdapter extends TranscriptionAdapter<any, any> ? TAdapter['~types']['providerOptions'] : object;
9
+ /**
10
+ * Options for the transcription activity.
11
+ * The model is extracted from the adapter's model property.
12
+ *
13
+ * @template TAdapter - The transcription adapter type
14
+ */
15
+ export interface TranscriptionActivityOptions<TAdapter extends TranscriptionAdapter<string, object>> {
16
+ /** The transcription adapter to use (must be created with a model) */
17
+ adapter: TAdapter & {
18
+ kind: typeof kind;
19
+ };
20
+ /** The audio data to transcribe - can be base64 string, File, Blob, or Buffer */
21
+ audio: string | File | Blob | ArrayBuffer;
22
+ /** The language of the audio in ISO-639-1 format (e.g., 'en') */
23
+ language?: string;
24
+ /** An optional prompt to guide the transcription */
25
+ prompt?: string;
26
+ /** The format of the transcription output */
27
+ responseFormat?: 'json' | 'text' | 'srt' | 'verbose_json' | 'vtt';
28
+ /** Provider-specific options for transcription */
29
+ modelOptions?: TranscriptionProviderOptions<TAdapter>;
30
+ }
31
+ /** Result type for the transcription activity */
32
+ export type TranscriptionActivityResult = Promise<TranscriptionResult>;
33
+ /**
34
+ * Transcription activity - converts audio to text.
35
+ *
36
+ * Uses AI speech-to-text models to transcribe audio content.
37
+ *
38
+ * @example Transcribe an audio file
39
+ * ```ts
40
+ * import { generateTranscription } from '@tanstack/ai'
41
+ * import { openaiTranscription } from '@tanstack/ai-openai'
42
+ *
43
+ * const result = await generateTranscription({
44
+ * adapter: openaiTranscription('whisper-1'),
45
+ * audio: audioFile, // File, Blob, or base64 string
46
+ * language: 'en'
47
+ * })
48
+ *
49
+ * console.log(result.text)
50
+ * ```
51
+ *
52
+ * @example With verbose output for timestamps
53
+ * ```ts
54
+ * const result = await generateTranscription({
55
+ * adapter: openaiTranscription('whisper-1'),
56
+ * audio: audioFile,
57
+ * responseFormat: 'verbose_json'
58
+ * })
59
+ *
60
+ * result.segments?.forEach(segment => {
61
+ * console.log(`[${segment.start}s - ${segment.end}s]: ${segment.text}`)
62
+ * })
63
+ * ```
64
+ */
65
+ export declare function generateTranscription<TAdapter extends TranscriptionAdapter<string, object>>(options: TranscriptionActivityOptions<TAdapter>): TranscriptionActivityResult;
66
+ /**
67
+ * Create typed options for the generateTranscription() function without executing.
68
+ */
69
+ export declare function createTranscriptionOptions<TAdapter extends TranscriptionAdapter<string, object>>(options: TranscriptionActivityOptions<TAdapter>): TranscriptionActivityOptions<TAdapter>;
70
+ export type { TranscriptionAdapter, TranscriptionAdapterConfig, AnyTranscriptionAdapter, } from './adapter.js';
71
+ export { BaseTranscriptionAdapter } from './adapter.js';
@@ -0,0 +1,15 @@
1
+ const kind = "transcription";
2
+ async function generateTranscription(options) {
3
+ const { adapter, ...rest } = options;
4
+ const model = adapter.model;
5
+ return adapter.transcribe({ ...rest, model });
6
+ }
7
+ function createTranscriptionOptions(options) {
8
+ return options;
9
+ }
10
+ export {
11
+ createTranscriptionOptions,
12
+ generateTranscription,
13
+ kind
14
+ };
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../src/activities/generateTranscription/index.ts"],"sourcesContent":["/**\n * Transcription Activity\n *\n * Transcribes audio to text using speech-to-text models.\n * This is a self-contained module with implementation, types, and JSDoc.\n */\n\nimport type { TranscriptionAdapter } from './adapter'\nimport type { TranscriptionResult } from '../../types'\n\n// ===========================\n// Activity Kind\n// ===========================\n\n/** The adapter kind this activity handles */\nexport const kind = 'transcription' as const\n\n// ===========================\n// Type Extraction Helpers\n// ===========================\n\n/**\n * Extract provider options from a TranscriptionAdapter via ~types.\n */\nexport type TranscriptionProviderOptions<TAdapter> =\n TAdapter extends TranscriptionAdapter<any, any>\n ? TAdapter['~types']['providerOptions']\n : object\n\n// ===========================\n// Activity Options Type\n// ===========================\n\n/**\n * Options for the transcription activity.\n * The model is extracted from the adapter's model property.\n *\n * @template TAdapter - The transcription adapter type\n */\nexport interface TranscriptionActivityOptions<\n TAdapter extends TranscriptionAdapter<string, object>,\n> {\n /** The transcription adapter to use (must be created with a model) */\n adapter: TAdapter & { kind: typeof kind }\n /** The audio data to transcribe - can be base64 string, File, Blob, or Buffer */\n audio: string | File | Blob | ArrayBuffer\n /** The language of the audio in ISO-639-1 format (e.g., 'en') */\n language?: string\n /** An optional prompt to guide the transcription */\n prompt?: string\n /** The format of the transcription output */\n responseFormat?: 'json' | 'text' | 'srt' | 'verbose_json' | 'vtt'\n /** Provider-specific options for transcription */\n modelOptions?: TranscriptionProviderOptions<TAdapter>\n}\n\n// ===========================\n// Activity Result Type\n// ===========================\n\n/** Result type for the transcription activity */\nexport type TranscriptionActivityResult = Promise<TranscriptionResult>\n\n// ===========================\n// Activity Implementation\n// ===========================\n\n/**\n * Transcription activity - converts audio to text.\n *\n * Uses AI speech-to-text models to transcribe audio content.\n *\n * @example Transcribe an audio file\n * ```ts\n * import { generateTranscription } from '@tanstack/ai'\n * import { openaiTranscription } from '@tanstack/ai-openai'\n *\n * const result = await generateTranscription({\n * adapter: openaiTranscription('whisper-1'),\n * audio: audioFile, // File, Blob, or base64 string\n * language: 'en'\n * })\n *\n * console.log(result.text)\n * ```\n *\n * @example With verbose output for timestamps\n * ```ts\n * const result = await generateTranscription({\n * adapter: openaiTranscription('whisper-1'),\n * audio: audioFile,\n * responseFormat: 'verbose_json'\n * })\n *\n * result.segments?.forEach(segment => {\n * console.log(`[${segment.start}s - ${segment.end}s]: ${segment.text}`)\n * })\n * ```\n */\nexport async function generateTranscription<\n TAdapter extends TranscriptionAdapter<string, object>,\n>(\n options: TranscriptionActivityOptions<TAdapter>,\n): TranscriptionActivityResult {\n const { adapter, ...rest } = options\n const model = adapter.model\n\n return adapter.transcribe({ ...rest, model })\n}\n\n// ===========================\n// Options Factory\n// ===========================\n\n/**\n * Create typed options for the generateTranscription() function without executing.\n */\nexport function createTranscriptionOptions<\n TAdapter extends TranscriptionAdapter<string, object>,\n>(\n options: TranscriptionActivityOptions<TAdapter>,\n): TranscriptionActivityOptions<TAdapter> {\n return options\n}\n\n// Re-export adapter types\nexport type {\n TranscriptionAdapter,\n TranscriptionAdapterConfig,\n AnyTranscriptionAdapter,\n} from './adapter'\nexport { BaseTranscriptionAdapter } from './adapter'\n"],"names":[],"mappings":"AAeO,MAAM,OAAO;AAoFpB,eAAsB,sBAGpB,SAC6B;AAC7B,QAAM,EAAE,SAAS,GAAG,KAAA,IAAS;AAC7B,QAAM,QAAQ,QAAQ;AAEtB,SAAO,QAAQ,WAAW,EAAE,GAAG,MAAM,OAAO;AAC9C;AASO,SAAS,2BAGd,SACwC;AACxC,SAAO;AACT;"}
@@ -0,0 +1,80 @@
1
+ import { VideoGenerationOptions, VideoJobResult, VideoStatusResult, VideoUrlResult } from '../../types.js';
2
+ /**
3
+ * Configuration for video adapter instances
4
+ *
5
+ * @experimental Video generation is an experimental feature and may change.
6
+ */
7
+ export interface VideoAdapterConfig {
8
+ apiKey?: string;
9
+ baseUrl?: string;
10
+ timeout?: number;
11
+ maxRetries?: number;
12
+ headers?: Record<string, string>;
13
+ }
14
+ /**
15
+ * Video adapter interface with pre-resolved generics.
16
+ *
17
+ * An adapter is created by a provider function: `provider('model')` → `adapter`
18
+ * All type resolution happens at the provider call site, not in this interface.
19
+ *
20
+ * @experimental Video generation is an experimental feature and may change.
21
+ *
22
+ * Generic parameters:
23
+ * - TModel: The specific model name (e.g., 'sora-2')
24
+ * - TProviderOptions: Provider-specific options (already resolved)
25
+ */
26
+ export interface VideoAdapter<TModel extends string = string, TProviderOptions extends object = Record<string, unknown>> {
27
+ /** Discriminator for adapter kind - used to determine API shape */
28
+ readonly kind: 'video';
29
+ /** Adapter name identifier */
30
+ readonly name: string;
31
+ /** The model this adapter is configured for */
32
+ readonly model: TModel;
33
+ /**
34
+ * @internal Type-only properties for inference. Not assigned at runtime.
35
+ */
36
+ '~types': {
37
+ providerOptions: TProviderOptions;
38
+ };
39
+ /**
40
+ * Create a new video generation job.
41
+ * Returns a job ID that can be used to poll for status and retrieve the video.
42
+ */
43
+ createVideoJob: (options: VideoGenerationOptions<TProviderOptions>) => Promise<VideoJobResult>;
44
+ /**
45
+ * Get the current status of a video generation job.
46
+ */
47
+ getVideoStatus: (jobId: string) => Promise<VideoStatusResult>;
48
+ /**
49
+ * Get the URL to download/view the generated video.
50
+ * Should only be called after status is 'completed'.
51
+ */
52
+ getVideoUrl: (jobId: string) => Promise<VideoUrlResult>;
53
+ }
54
+ /**
55
+ * A VideoAdapter with any/unknown type parameters.
56
+ * Useful as a constraint in generic functions and interfaces.
57
+ */
58
+ export type AnyVideoAdapter = VideoAdapter<any, any>;
59
+ /**
60
+ * Abstract base class for video generation adapters.
61
+ * Extend this class to implement a video adapter for a specific provider.
62
+ *
63
+ * @experimental Video generation is an experimental feature and may change.
64
+ *
65
+ * Generic parameters match VideoAdapter - all pre-resolved by the provider function.
66
+ */
67
+ export declare abstract class BaseVideoAdapter<TModel extends string = string, TProviderOptions extends object = Record<string, unknown>> implements VideoAdapter<TModel, TProviderOptions> {
68
+ readonly kind: "video";
69
+ abstract readonly name: string;
70
+ readonly model: TModel;
71
+ '~types': {
72
+ providerOptions: TProviderOptions;
73
+ };
74
+ protected config: VideoAdapterConfig;
75
+ constructor(config: VideoAdapterConfig | undefined, model: TModel);
76
+ abstract createVideoJob(options: VideoGenerationOptions<TProviderOptions>): Promise<VideoJobResult>;
77
+ abstract getVideoStatus(jobId: string): Promise<VideoStatusResult>;
78
+ abstract getVideoUrl(jobId: string): Promise<VideoUrlResult>;
79
+ protected generateId(): string;
80
+ }
@@ -0,0 +1,14 @@
1
+ class BaseVideoAdapter {
2
+ constructor(config = {}, model) {
3
+ this.kind = "video";
4
+ this.config = config;
5
+ this.model = model;
6
+ }
7
+ generateId() {
8
+ return `${this.name}-${Date.now()}-${Math.random().toString(36).substring(7)}`;
9
+ }
10
+ }
11
+ export {
12
+ BaseVideoAdapter
13
+ };
14
+ //# sourceMappingURL=adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.js","sources":["../../../../src/activities/generateVideo/adapter.ts"],"sourcesContent":["import type {\n VideoGenerationOptions,\n VideoJobResult,\n VideoStatusResult,\n VideoUrlResult,\n} from '../../types'\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 */\nexport interface VideoAdapter<\n TModel extends string = string,\n TProviderOptions extends object = Record<string, unknown>,\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 }\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<TProviderOptions>,\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/**\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>\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> implements VideoAdapter<TModel, TProviderOptions> {\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 }\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<TProviderOptions>,\n ): Promise<VideoJobResult>\n\n abstract getVideoStatus(jobId: string): Promise<VideoStatusResult>\n\n abstract getVideoUrl(jobId: string): Promise<VideoUrlResult>\n\n protected generateId(): string {\n return `${this.name}-${Date.now()}-${Math.random().toString(36).substring(7)}`\n }\n}\n"],"names":[],"mappings":"AAoFO,MAAe,iBAG8B;AAAA,EAYlD,YAAY,SAA6B,CAAA,GAAI,OAAe;AAX5D,SAAS,OAAO;AAYd,SAAK,SAAS;AACd,SAAK,QAAQ;AAAA,EACf;AAAA,EAUU,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,136 @@
1
+ import { VideoAdapter } from './adapter.js';
2
+ import { VideoJobResult, VideoStatusResult, VideoUrlResult } from '../../types.js';
3
+ /** The adapter kind this activity handles */
4
+ export declare const kind: "video";
5
+ /**
6
+ * Extract provider options from a VideoAdapter via ~types.
7
+ */
8
+ export type VideoProviderOptions<TAdapter> = TAdapter extends VideoAdapter<any, any> ? TAdapter['~types']['providerOptions'] : object;
9
+ /**
10
+ * Base options shared by all video activity operations.
11
+ * The model is extracted from the adapter's model property.
12
+ */
13
+ interface VideoActivityBaseOptions<TAdapter extends VideoAdapter<string, object>> {
14
+ /** The video adapter to use (must be created with a model) */
15
+ adapter: TAdapter & {
16
+ kind: typeof kind;
17
+ };
18
+ }
19
+ /**
20
+ * Options for creating a new video generation job.
21
+ * The model is extracted from the adapter's model property.
22
+ *
23
+ * @experimental Video generation is an experimental feature and may change.
24
+ */
25
+ export interface VideoCreateOptions<TAdapter extends VideoAdapter<string, object>> extends VideoActivityBaseOptions<TAdapter> {
26
+ /** Request type - create a new job (default if not specified) */
27
+ request?: 'create';
28
+ /** Text description of the desired video */
29
+ prompt: string;
30
+ /** Video size in WIDTHxHEIGHT format (e.g., "1280x720") */
31
+ size?: string;
32
+ /** Video duration in seconds */
33
+ duration?: number;
34
+ /** Provider-specific options for video generation */
35
+ modelOptions?: VideoProviderOptions<TAdapter>;
36
+ }
37
+ /**
38
+ * Options for polling the status of a video generation job.
39
+ *
40
+ * @experimental Video generation is an experimental feature and may change.
41
+ */
42
+ export interface VideoStatusOptions<TAdapter extends VideoAdapter<string, object>> extends VideoActivityBaseOptions<TAdapter> {
43
+ /** Request type - get job status */
44
+ request: 'status';
45
+ /** The job ID to check status for */
46
+ jobId: string;
47
+ }
48
+ /**
49
+ * Options for getting the URL of a completed video.
50
+ *
51
+ * @experimental Video generation is an experimental feature and may change.
52
+ */
53
+ export interface VideoUrlOptions<TAdapter extends VideoAdapter<string, object>> extends VideoActivityBaseOptions<TAdapter> {
54
+ /** Request type - get video URL */
55
+ request: 'url';
56
+ /** The job ID to get URL for */
57
+ jobId: string;
58
+ }
59
+ /**
60
+ * Union type for all video activity options.
61
+ * Discriminated by the `request` field.
62
+ *
63
+ * @experimental Video generation is an experimental feature and may change.
64
+ */
65
+ export type VideoActivityOptions<TAdapter extends VideoAdapter<string, object>, TRequest extends 'create' | 'status' | 'url' = 'create'> = TRequest extends 'status' ? VideoStatusOptions<TAdapter> : TRequest extends 'url' ? VideoUrlOptions<TAdapter> : VideoCreateOptions<TAdapter>;
66
+ /**
67
+ * Result type for the video activity, based on request type.
68
+ *
69
+ * @experimental Video generation is an experimental feature and may change.
70
+ */
71
+ export type VideoActivityResult<TRequest extends 'create' | 'status' | 'url' = 'create'> = TRequest extends 'status' ? Promise<VideoStatusResult> : TRequest extends 'url' ? Promise<VideoUrlResult> : Promise<VideoJobResult>;
72
+ /**
73
+ * Generate video - creates a video generation job from a text prompt.
74
+ *
75
+ * Uses AI video generation models to create videos based on natural language descriptions.
76
+ * Unlike image generation, video generation is asynchronous and requires polling for completion.
77
+ *
78
+ * @experimental Video generation is an experimental feature and may change.
79
+ *
80
+ * @example Create a video generation job
81
+ * ```ts
82
+ * import { generateVideo } from '@tanstack/ai'
83
+ * import { openaiVideo } from '@tanstack/ai-openai'
84
+ *
85
+ * // Start a video generation job
86
+ * const { jobId } = await generateVideo({
87
+ * adapter: openaiVideo('sora-2'),
88
+ * prompt: 'A cat chasing a dog in a sunny park'
89
+ * })
90
+ *
91
+ * console.log('Job started:', jobId)
92
+ * ```
93
+ */
94
+ export declare function generateVideo<TAdapter extends VideoAdapter<string, object>>(options: VideoCreateOptions<TAdapter>): Promise<VideoJobResult>;
95
+ /**
96
+ * Get video job status - returns the current status, progress, and URL if available.
97
+ *
98
+ * This function combines status checking and URL retrieval. If the job is completed,
99
+ * it will automatically fetch and include the video URL.
100
+ *
101
+ * @experimental Video generation is an experimental feature and may change.
102
+ *
103
+ * @example Check job status
104
+ * ```ts
105
+ * import { getVideoJobStatus } from '@tanstack/ai'
106
+ * import { openaiVideo } from '@tanstack/ai-openai'
107
+ *
108
+ * const result = await getVideoJobStatus({
109
+ * adapter: openaiVideo('sora-2'),
110
+ * jobId: 'job-123'
111
+ * })
112
+ *
113
+ * console.log('Status:', result.status)
114
+ * console.log('Progress:', result.progress)
115
+ * if (result.url) {
116
+ * console.log('Video URL:', result.url)
117
+ * }
118
+ * ```
119
+ */
120
+ export declare function getVideoJobStatus<TAdapter extends VideoAdapter<string, object>>(options: {
121
+ adapter: TAdapter & {
122
+ kind: typeof kind;
123
+ };
124
+ jobId: string;
125
+ }): Promise<{
126
+ status: 'pending' | 'processing' | 'completed' | 'failed';
127
+ progress?: number;
128
+ url?: string;
129
+ error?: string;
130
+ }>;
131
+ /**
132
+ * Create typed options for the generateVideo() function without executing.
133
+ */
134
+ export declare function createVideoOptions<TAdapter extends VideoAdapter<string, object>>(options: VideoCreateOptions<TAdapter>): VideoCreateOptions<TAdapter>;
135
+ export type { VideoAdapter, VideoAdapterConfig, AnyVideoAdapter, } from './adapter.js';
136
+ export { BaseVideoAdapter } from './adapter.js';
@@ -0,0 +1,47 @@
1
+ const kind = "video";
2
+ async function generateVideo(options) {
3
+ const { adapter, prompt, size, duration, modelOptions } = options;
4
+ const model = adapter.model;
5
+ return adapter.createVideoJob({
6
+ model,
7
+ prompt,
8
+ size,
9
+ duration,
10
+ modelOptions
11
+ });
12
+ }
13
+ async function getVideoJobStatus(options) {
14
+ const { adapter, jobId } = options;
15
+ const statusResult = await adapter.getVideoStatus(jobId);
16
+ if (statusResult.status === "completed") {
17
+ try {
18
+ const urlResult = await adapter.getVideoUrl(jobId);
19
+ return {
20
+ status: statusResult.status,
21
+ progress: statusResult.progress,
22
+ url: urlResult.url
23
+ };
24
+ } catch (error) {
25
+ return {
26
+ status: statusResult.status,
27
+ progress: statusResult.progress,
28
+ error: error instanceof Error ? error.message : "Failed to get video URL"
29
+ };
30
+ }
31
+ }
32
+ return {
33
+ status: statusResult.status,
34
+ progress: statusResult.progress,
35
+ error: statusResult.error
36
+ };
37
+ }
38
+ function createVideoOptions(options) {
39
+ return options;
40
+ }
41
+ export {
42
+ createVideoOptions,
43
+ generateVideo,
44
+ getVideoJobStatus,
45
+ kind
46
+ };
47
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../src/activities/generateVideo/index.ts"],"sourcesContent":["/**\n * Video Activity (Experimental)\n *\n * Generates videos from text prompts using a jobs/polling architecture.\n * This is a self-contained module with implementation, types, and JSDoc.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\n\nimport type { VideoAdapter } from './adapter'\nimport type {\n VideoJobResult,\n VideoStatusResult,\n VideoUrlResult,\n} from '../../types'\n\n// ===========================\n// Activity Kind\n// ===========================\n\n/** The adapter kind this activity handles */\nexport const kind = 'video' as const\n\n// ===========================\n// Type Extraction Helpers\n// ===========================\n\n/**\n * Extract provider options from a VideoAdapter via ~types.\n */\nexport type VideoProviderOptions<TAdapter> =\n TAdapter extends VideoAdapter<any, any>\n ? TAdapter['~types']['providerOptions']\n : object\n\n// ===========================\n// Activity Options Types\n// ===========================\n\n/**\n * Base options shared by all video activity operations.\n * The model is extracted from the adapter's model property.\n */\ninterface VideoActivityBaseOptions<\n TAdapter extends VideoAdapter<string, object>,\n> {\n /** The video adapter to use (must be created with a model) */\n adapter: TAdapter & { kind: typeof kind }\n}\n\n/**\n * Options for creating a new video generation job.\n * The model is extracted from the adapter's model property.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport interface VideoCreateOptions<\n TAdapter extends VideoAdapter<string, object>,\n> extends VideoActivityBaseOptions<TAdapter> {\n /** Request type - create a new job (default if not specified) */\n request?: 'create'\n /** Text description of the desired video */\n prompt: string\n /** Video size in WIDTHxHEIGHT format (e.g., \"1280x720\") */\n size?: string\n /** Video duration in seconds */\n duration?: number\n /** Provider-specific options for video generation */\n modelOptions?: VideoProviderOptions<TAdapter>\n}\n\n/**\n * Options for polling the status of a video generation job.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport interface VideoStatusOptions<\n TAdapter extends VideoAdapter<string, object>,\n> extends VideoActivityBaseOptions<TAdapter> {\n /** Request type - get job status */\n request: 'status'\n /** The job ID to check status for */\n jobId: string\n}\n\n/**\n * Options for getting the URL of a completed video.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport interface VideoUrlOptions<\n TAdapter extends VideoAdapter<string, object>,\n> extends VideoActivityBaseOptions<TAdapter> {\n /** Request type - get video URL */\n request: 'url'\n /** The job ID to get URL for */\n jobId: string\n}\n\n/**\n * Union type for all video activity options.\n * Discriminated by the `request` field.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport type VideoActivityOptions<\n TAdapter extends VideoAdapter<string, object>,\n TRequest extends 'create' | 'status' | 'url' = 'create',\n> = TRequest extends 'status'\n ? VideoStatusOptions<TAdapter>\n : TRequest extends 'url'\n ? VideoUrlOptions<TAdapter>\n : VideoCreateOptions<TAdapter>\n\n// ===========================\n// Activity Result Types\n// ===========================\n\n/**\n * Result type for the video activity, based on request type.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport type VideoActivityResult<\n TRequest extends 'create' | 'status' | 'url' = 'create',\n> = TRequest extends 'status'\n ? Promise<VideoStatusResult>\n : TRequest extends 'url'\n ? Promise<VideoUrlResult>\n : Promise<VideoJobResult>\n\n// ===========================\n// Activity Implementation\n// ===========================\n\n/**\n * Generate video - creates a video generation job from a text prompt.\n *\n * Uses AI video generation models to create videos based on natural language descriptions.\n * Unlike image generation, video generation is asynchronous and requires polling for completion.\n *\n * @experimental Video generation is an experimental feature and may change.\n *\n * @example Create a video generation job\n * ```ts\n * import { generateVideo } from '@tanstack/ai'\n * import { openaiVideo } from '@tanstack/ai-openai'\n *\n * // Start a video generation job\n * const { jobId } = await generateVideo({\n * adapter: openaiVideo('sora-2'),\n * prompt: 'A cat chasing a dog in a sunny park'\n * })\n *\n * console.log('Job started:', jobId)\n * ```\n */\nexport async function generateVideo<\n TAdapter extends VideoAdapter<string, object>,\n>(options: VideoCreateOptions<TAdapter>): Promise<VideoJobResult> {\n const { adapter, prompt, size, duration, modelOptions } = options\n const model = adapter.model\n\n return adapter.createVideoJob({\n model,\n prompt,\n size,\n duration,\n modelOptions,\n })\n}\n\n/**\n * Get video job status - returns the current status, progress, and URL if available.\n *\n * This function combines status checking and URL retrieval. If the job is completed,\n * it will automatically fetch and include the video URL.\n *\n * @experimental Video generation is an experimental feature and may change.\n *\n * @example Check job status\n * ```ts\n * import { getVideoJobStatus } from '@tanstack/ai'\n * import { openaiVideo } from '@tanstack/ai-openai'\n *\n * const result = await getVideoJobStatus({\n * adapter: openaiVideo('sora-2'),\n * jobId: 'job-123'\n * })\n *\n * console.log('Status:', result.status)\n * console.log('Progress:', result.progress)\n * if (result.url) {\n * console.log('Video URL:', result.url)\n * }\n * ```\n */\nexport async function getVideoJobStatus<\n TAdapter extends VideoAdapter<string, object>,\n>(options: {\n adapter: TAdapter & { kind: typeof kind }\n jobId: string\n}): Promise<{\n status: 'pending' | 'processing' | 'completed' | 'failed'\n progress?: number\n url?: string\n error?: string\n}> {\n const { adapter, jobId } = options\n\n // Get status first\n const statusResult = await adapter.getVideoStatus(jobId)\n\n // If completed, also get the URL\n if (statusResult.status === 'completed') {\n try {\n const urlResult = await adapter.getVideoUrl(jobId)\n return {\n status: statusResult.status,\n progress: statusResult.progress,\n url: urlResult.url,\n }\n } catch (error) {\n // If URL fetch fails, still return status\n return {\n status: statusResult.status,\n progress: statusResult.progress,\n error:\n error instanceof Error ? error.message : 'Failed to get video URL',\n }\n }\n }\n\n // Return status for non-completed jobs\n return {\n status: statusResult.status,\n progress: statusResult.progress,\n error: statusResult.error,\n }\n}\n\n// ===========================\n// Options Factory\n// ===========================\n\n/**\n * Create typed options for the generateVideo() function without executing.\n */\nexport function createVideoOptions<\n TAdapter extends VideoAdapter<string, object>,\n>(options: VideoCreateOptions<TAdapter>): VideoCreateOptions<TAdapter> {\n return options\n}\n\n// Re-export adapter types\nexport type {\n VideoAdapter,\n VideoAdapterConfig,\n AnyVideoAdapter,\n} from './adapter'\nexport { BaseVideoAdapter } from './adapter'\n"],"names":[],"mappings":"AAqBO,MAAM,OAAO;AAwIpB,eAAsB,cAEpB,SAAgE;AAChE,QAAM,EAAE,SAAS,QAAQ,MAAM,UAAU,iBAAiB;AAC1D,QAAM,QAAQ,QAAQ;AAEtB,SAAO,QAAQ,eAAe;AAAA,IAC5B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACD;AACH;AA2BA,eAAsB,kBAEpB,SAQC;AACD,QAAM,EAAE,SAAS,MAAA,IAAU;AAG3B,QAAM,eAAe,MAAM,QAAQ,eAAe,KAAK;AAGvD,MAAI,aAAa,WAAW,aAAa;AACvC,QAAI;AACF,YAAM,YAAY,MAAM,QAAQ,YAAY,KAAK;AACjD,aAAO;AAAA,QACL,QAAQ,aAAa;AAAA,QACrB,UAAU,aAAa;AAAA,QACvB,KAAK,UAAU;AAAA,MAAA;AAAA,IAEnB,SAAS,OAAO;AAEd,aAAO;AAAA,QACL,QAAQ,aAAa;AAAA,QACrB,UAAU,aAAa;AAAA,QACvB,OACE,iBAAiB,QAAQ,MAAM,UAAU;AAAA,MAAA;AAAA,IAE/C;AAAA,EACF;AAGA,SAAO;AAAA,IACL,QAAQ,aAAa;AAAA,IACrB,UAAU,aAAa;AAAA,IACvB,OAAO,aAAa;AAAA,EAAA;AAExB;AASO,SAAS,mBAEd,SAAqE;AACrE,SAAO;AACT;"}
@@ -0,0 +1,22 @@
1
+ import { AnyTextAdapter } from './chat/adapter.js';
2
+ import { AnySummarizeAdapter } from './summarize/adapter.js';
3
+ import { AnyImageAdapter } from './generateImage/adapter.js';
4
+ import { AnyVideoAdapter } from './generateVideo/adapter.js';
5
+ import { AnyTTSAdapter } from './generateSpeech/adapter.js';
6
+ import { AnyTranscriptionAdapter } from './generateTranscription/adapter.js';
7
+ export { kind as textKind, chat, type TextActivityOptions, type TextActivityResult, } from './chat/index.js';
8
+ export { BaseTextAdapter, type AnyTextAdapter, type TextAdapter, type TextAdapterConfig, type StructuredOutputOptions, type StructuredOutputResult, } from './chat/adapter.js';
9
+ export { kind as summarizeKind, summarize, type SummarizeActivityOptions, type SummarizeActivityResult, type SummarizeProviderOptions, } from './summarize/index.js';
10
+ export { BaseSummarizeAdapter, type SummarizeAdapter, type SummarizeAdapterConfig, type AnySummarizeAdapter, } from './summarize/adapter.js';
11
+ export { kind as imageKind, generateImage, type ImageActivityOptions, type ImageActivityResult, type ImageProviderOptionsForModel, type ImageSizeForModel, } from './generateImage/index.js';
12
+ export { BaseImageAdapter, type ImageAdapter, type ImageAdapterConfig, type AnyImageAdapter, } from './generateImage/adapter.js';
13
+ export { kind as videoKind, generateVideo, getVideoJobStatus, type VideoActivityOptions, type VideoActivityResult, type VideoProviderOptions, type VideoCreateOptions, type VideoStatusOptions, type VideoUrlOptions, } from './generateVideo/index.js';
14
+ export { BaseVideoAdapter, type VideoAdapter, type VideoAdapterConfig, type AnyVideoAdapter, } from './generateVideo/adapter.js';
15
+ export { kind as ttsKind, generateSpeech, type TTSActivityOptions, type TTSActivityResult, type TTSProviderOptions, } from './generateSpeech/index.js';
16
+ export { BaseTTSAdapter, type TTSAdapter, type TTSAdapterConfig, type AnyTTSAdapter, } from './generateSpeech/adapter.js';
17
+ export { kind as transcriptionKind, generateTranscription, type TranscriptionActivityOptions, type TranscriptionActivityResult, type TranscriptionProviderOptions, } from './generateTranscription/index.js';
18
+ export { BaseTranscriptionAdapter, type TranscriptionAdapter, type TranscriptionAdapterConfig, type AnyTranscriptionAdapter, } from './generateTranscription/adapter.js';
19
+ /** Union of all adapter types that can be passed to chat() */
20
+ export type AIAdapter = AnyTextAdapter | AnySummarizeAdapter | AnyImageAdapter | AnyVideoAdapter | AnyTTSAdapter | AnyTranscriptionAdapter;
21
+ /** Union type of all adapter kinds */
22
+ export type AdapterKind = 'text' | 'summarize' | 'image' | 'video' | 'tts' | 'transcription';
@@ -0,0 +1,34 @@
1
+ import { chat, kind } from "./chat/index.js";
2
+ import { BaseTextAdapter } from "./chat/adapter.js";
3
+ import { summarize, kind as kind2 } from "./summarize/index.js";
4
+ import { BaseSummarizeAdapter } from "./summarize/adapter.js";
5
+ import { generateImage, kind as kind3 } from "./generateImage/index.js";
6
+ import { BaseImageAdapter } from "./generateImage/adapter.js";
7
+ import { generateVideo, getVideoJobStatus, kind as kind4 } from "./generateVideo/index.js";
8
+ import { BaseVideoAdapter } from "./generateVideo/adapter.js";
9
+ import { generateSpeech, kind as kind5 } from "./generateSpeech/index.js";
10
+ import { BaseTTSAdapter } from "./generateSpeech/adapter.js";
11
+ import { generateTranscription, kind as kind6 } from "./generateTranscription/index.js";
12
+ import { BaseTranscriptionAdapter } from "./generateTranscription/adapter.js";
13
+ export {
14
+ BaseImageAdapter,
15
+ BaseSummarizeAdapter,
16
+ BaseTTSAdapter,
17
+ BaseTextAdapter,
18
+ BaseTranscriptionAdapter,
19
+ BaseVideoAdapter,
20
+ chat,
21
+ generateImage,
22
+ generateSpeech,
23
+ generateTranscription,
24
+ generateVideo,
25
+ getVideoJobStatus,
26
+ kind3 as imageKind,
27
+ summarize,
28
+ kind2 as summarizeKind,
29
+ kind as textKind,
30
+ kind6 as transcriptionKind,
31
+ kind5 as ttsKind,
32
+ kind4 as videoKind
33
+ };
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;"}
@@ -0,0 +1,74 @@
1
+ import { StreamChunk, SummarizationOptions, SummarizationResult } from '../../types.js';
2
+ /**
3
+ * Configuration for summarize adapter instances
4
+ */
5
+ export interface SummarizeAdapterConfig {
6
+ apiKey?: string;
7
+ baseUrl?: string;
8
+ timeout?: number;
9
+ maxRetries?: number;
10
+ headers?: Record<string, string>;
11
+ }
12
+ /**
13
+ * Summarize adapter interface with pre-resolved generics.
14
+ *
15
+ * An adapter is created by a provider function: `provider('model')` → `adapter`
16
+ * All type resolution happens at the provider call site, not in this interface.
17
+ *
18
+ * Generic parameters:
19
+ * - TModel: The specific model name (e.g., 'gpt-4o')
20
+ * - TProviderOptions: Provider-specific options (already resolved)
21
+ */
22
+ export interface SummarizeAdapter<TModel extends string = string, TProviderOptions extends object = Record<string, unknown>> {
23
+ /** Discriminator for adapter kind - used by generate() to determine API shape */
24
+ readonly kind: 'summarize';
25
+ /** Adapter name identifier */
26
+ readonly name: string;
27
+ /** The model this adapter is configured for */
28
+ readonly model: TModel;
29
+ /**
30
+ * @internal Type-only properties for inference. Not assigned at runtime.
31
+ */
32
+ '~types': {
33
+ providerOptions: TProviderOptions;
34
+ };
35
+ /**
36
+ * Summarize the given text
37
+ */
38
+ summarize: (options: SummarizationOptions) => Promise<SummarizationResult>;
39
+ /**
40
+ * Stream summarization of the given text.
41
+ * Optional - if not implemented, the activity layer will fall back to
42
+ * non-streaming summarize and yield the result as a single chunk.
43
+ */
44
+ summarizeStream?: (options: SummarizationOptions) => AsyncIterable<StreamChunk>;
45
+ }
46
+ /**
47
+ * A SummarizeAdapter with any/unknown type parameters.
48
+ * Useful as a constraint in generic functions and interfaces.
49
+ */
50
+ export type AnySummarizeAdapter = SummarizeAdapter<any, any>;
51
+ /**
52
+ * Abstract base class for summarize adapters.
53
+ * Extend this class to implement a summarize adapter for a specific provider.
54
+ *
55
+ * Generic parameters match SummarizeAdapter - all pre-resolved by the provider function.
56
+ */
57
+ export declare abstract class BaseSummarizeAdapter<TModel extends string = string, TProviderOptions extends object = Record<string, unknown>> implements SummarizeAdapter<TModel, TProviderOptions> {
58
+ readonly kind: "summarize";
59
+ abstract readonly name: string;
60
+ readonly model: TModel;
61
+ '~types': {
62
+ providerOptions: TProviderOptions;
63
+ };
64
+ protected config: SummarizeAdapterConfig;
65
+ constructor(config: SummarizeAdapterConfig | undefined, model: TModel);
66
+ abstract summarize(options: SummarizationOptions): Promise<SummarizationResult>;
67
+ /**
68
+ * Stream summarization of the given text.
69
+ * Override this method in concrete implementations to enable streaming.
70
+ * If not overridden, the activity layer will fall back to non-streaming.
71
+ */
72
+ summarizeStream?(options: SummarizationOptions): AsyncIterable<StreamChunk>;
73
+ protected generateId(): string;
74
+ }
@@ -0,0 +1,14 @@
1
+ class BaseSummarizeAdapter {
2
+ constructor(config = {}, model) {
3
+ this.kind = "summarize";
4
+ this.config = config;
5
+ this.model = model;
6
+ }
7
+ generateId() {
8
+ return `${this.name}-${Date.now()}-${Math.random().toString(36).substring(7)}`;
9
+ }
10
+ }
11
+ export {
12
+ BaseSummarizeAdapter
13
+ };
14
+ //# sourceMappingURL=adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.js","sources":["../../../../src/activities/summarize/adapter.ts"],"sourcesContent":["import type {\n StreamChunk,\n SummarizationOptions,\n SummarizationResult,\n} from '../../types'\n\n/**\n * Configuration for summarize adapter instances\n */\nexport interface SummarizeAdapterConfig {\n apiKey?: string\n baseUrl?: string\n timeout?: number\n maxRetries?: number\n headers?: Record<string, string>\n}\n\n/**\n * Summarize 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 * Generic parameters:\n * - TModel: The specific model name (e.g., 'gpt-4o')\n * - TProviderOptions: Provider-specific options (already resolved)\n */\nexport interface SummarizeAdapter<\n TModel extends string = string,\n TProviderOptions extends object = Record<string, unknown>,\n> {\n /** Discriminator for adapter kind - used by generate() to determine API shape */\n readonly kind: 'summarize'\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 }\n\n /**\n * Summarize the given text\n */\n summarize: (options: SummarizationOptions) => Promise<SummarizationResult>\n\n /**\n * Stream summarization of the given text.\n * Optional - if not implemented, the activity layer will fall back to\n * non-streaming summarize and yield the result as a single chunk.\n */\n summarizeStream?: (\n options: SummarizationOptions,\n ) => AsyncIterable<StreamChunk>\n}\n\n/**\n * A SummarizeAdapter with any/unknown type parameters.\n * Useful as a constraint in generic functions and interfaces.\n */\nexport type AnySummarizeAdapter = SummarizeAdapter<any, any>\n\n/**\n * Abstract base class for summarize adapters.\n * Extend this class to implement a summarize adapter for a specific provider.\n *\n * Generic parameters match SummarizeAdapter - all pre-resolved by the provider function.\n */\nexport abstract class BaseSummarizeAdapter<\n TModel extends string = string,\n TProviderOptions extends object = Record<string, unknown>,\n> implements SummarizeAdapter<TModel, TProviderOptions> {\n readonly kind = 'summarize' 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 }\n\n protected config: SummarizeAdapterConfig\n\n constructor(config: SummarizeAdapterConfig = {}, model: TModel) {\n this.config = config\n this.model = model\n }\n\n abstract summarize(\n options: SummarizationOptions,\n ): Promise<SummarizationResult>\n\n /**\n * Stream summarization of the given text.\n * Override this method in concrete implementations to enable streaming.\n * If not overridden, the activity layer will fall back to non-streaming.\n */\n summarizeStream?(options: SummarizationOptions): AsyncIterable<StreamChunk>\n\n protected generateId(): string {\n return `${this.name}-${Date.now()}-${Math.random().toString(36).substring(7)}`\n }\n}\n"],"names":[],"mappings":"AAwEO,MAAe,qBAGkC;AAAA,EAYtD,YAAY,SAAiC,CAAA,GAAI,OAAe;AAXhE,SAAS,OAAO;AAYd,SAAK,SAAS;AACd,SAAK,QAAQ;AAAA,EACf;AAAA,EAaU,aAAqB;AAC7B,WAAO,GAAG,KAAK,IAAI,IAAI,KAAK,KAAK,IAAI,KAAK,OAAA,EAAS,SAAS,EAAE,EAAE,UAAU,CAAC,CAAC;AAAA,EAC9E;AACF;"}