@tanstack/ai 0.0.3 → 0.2.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.
- package/README.md +26 -0
- package/dist/esm/activities/chat/adapter.d.ts +100 -0
- package/dist/esm/activities/chat/adapter.js +14 -0
- package/dist/esm/activities/chat/adapter.js.map +1 -0
- package/dist/esm/{utilities → activities/chat}/agent-loop-strategies.d.ts +4 -4
- package/dist/esm/activities/chat/agent-loop-strategies.js.map +1 -0
- package/dist/esm/activities/chat/index.d.ts +166 -0
- package/dist/esm/{core/chat.js → activities/chat/index.js} +131 -33
- package/dist/esm/activities/chat/index.js.map +1 -0
- package/dist/esm/{message-converters.d.ts → activities/chat/messages.d.ts} +1 -1
- package/dist/esm/{message-converters.js → activities/chat/messages.js} +7 -7
- package/dist/esm/activities/chat/messages.js.map +1 -0
- package/dist/esm/activities/chat/stream/json-parser.js.map +1 -0
- package/dist/esm/{stream → activities/chat/stream}/message-updaters.d.ts +1 -1
- package/dist/esm/activities/chat/stream/message-updaters.js.map +1 -0
- package/dist/esm/{stream → activities/chat/stream}/processor.d.ts +1 -1
- package/dist/esm/{stream → activities/chat/stream}/processor.js +1 -1
- package/dist/esm/activities/chat/stream/processor.js.map +1 -0
- package/dist/esm/activities/chat/stream/strategies.js.map +1 -0
- package/dist/esm/{stream → activities/chat/stream}/types.d.ts +2 -9
- package/dist/esm/activities/chat/tools/schema-converter.d.ts +116 -0
- package/dist/esm/activities/chat/tools/schema-converter.js +115 -0
- package/dist/esm/activities/chat/tools/schema-converter.js.map +1 -0
- package/dist/esm/{tools → activities/chat/tools}/tool-calls.d.ts +1 -1
- package/dist/esm/{tools → activities/chat/tools}/tool-calls.js +23 -30
- package/dist/esm/activities/chat/tools/tool-calls.js.map +1 -0
- package/dist/esm/{tools → activities/chat/tools}/tool-definition.d.ts +22 -18
- package/dist/esm/activities/chat/tools/tool-definition.js.map +1 -0
- package/dist/esm/activities/generateImage/adapter.d.ts +68 -0
- package/dist/esm/activities/generateImage/adapter.js +14 -0
- package/dist/esm/activities/generateImage/adapter.js.map +1 -0
- package/dist/esm/activities/generateImage/index.d.ts +89 -0
- package/dist/esm/activities/generateImage/index.js +15 -0
- package/dist/esm/activities/generateImage/index.js.map +1 -0
- package/dist/esm/activities/generateSpeech/adapter.d.ts +62 -0
- package/dist/esm/activities/generateSpeech/adapter.js +14 -0
- package/dist/esm/activities/generateSpeech/adapter.js.map +1 -0
- package/dist/esm/activities/generateSpeech/index.d.ts +69 -0
- package/dist/esm/activities/generateSpeech/index.js +15 -0
- package/dist/esm/activities/generateSpeech/index.js.map +1 -0
- package/dist/esm/activities/generateTranscription/adapter.d.ts +62 -0
- package/dist/esm/activities/generateTranscription/adapter.js +14 -0
- package/dist/esm/activities/generateTranscription/adapter.js.map +1 -0
- package/dist/esm/activities/generateTranscription/index.d.ts +71 -0
- package/dist/esm/activities/generateTranscription/index.js +15 -0
- package/dist/esm/activities/generateTranscription/index.js.map +1 -0
- package/dist/esm/activities/generateVideo/adapter.d.ts +80 -0
- package/dist/esm/activities/generateVideo/adapter.js +14 -0
- package/dist/esm/activities/generateVideo/adapter.js.map +1 -0
- package/dist/esm/activities/generateVideo/index.d.ts +136 -0
- package/dist/esm/activities/generateVideo/index.js +47 -0
- package/dist/esm/activities/generateVideo/index.js.map +1 -0
- package/dist/esm/activities/index.d.ts +22 -0
- package/dist/esm/activities/index.js +34 -0
- package/dist/esm/activities/index.js.map +1 -0
- package/dist/esm/activities/summarize/adapter.d.ts +74 -0
- package/dist/esm/activities/summarize/adapter.js +14 -0
- package/dist/esm/activities/summarize/adapter.js.map +1 -0
- package/dist/esm/activities/summarize/index.d.ts +100 -0
- package/dist/esm/activities/summarize/index.js +90 -0
- package/dist/esm/activities/summarize/index.js.map +1 -0
- package/dist/esm/event-client.d.ts +4 -18
- package/dist/esm/event-client.js.map +1 -1
- package/dist/esm/index.d.ts +16 -14
- package/dist/esm/index.js +29 -20
- package/dist/esm/stream-to-response.d.ts +95 -0
- package/dist/esm/stream-to-response.js +118 -0
- package/dist/esm/stream-to-response.js.map +1 -0
- package/dist/esm/types.d.ts +370 -133
- package/package.json +7 -6
- package/src/activities/chat/adapter.ts +150 -0
- package/src/{utilities → activities/chat}/agent-loop-strategies.ts +4 -4
- package/src/{core/chat.ts → activities/chat/index.ts} +435 -79
- package/src/{message-converters.ts → activities/chat/messages.ts} +10 -13
- package/src/{stream → activities/chat/stream}/message-updaters.ts +1 -1
- package/src/{stream → activities/chat/stream}/processor.ts +2 -5
- package/src/{stream → activities/chat/stream}/types.ts +8 -18
- package/src/activities/chat/tools/schema-converter.ts +332 -0
- package/src/{tools → activities/chat/tools}/tool-calls.ts +63 -44
- package/src/{tools → activities/chat/tools}/tool-definition.ts +51 -38
- package/src/activities/generateImage/adapter.ts +104 -0
- package/src/activities/generateImage/index.ts +162 -0
- package/src/activities/generateSpeech/adapter.ts +87 -0
- package/src/activities/generateSpeech/index.ts +122 -0
- package/src/activities/generateTranscription/adapter.ts +89 -0
- package/src/activities/generateTranscription/index.ts +132 -0
- package/src/activities/generateVideo/adapter.ts +116 -0
- package/src/activities/generateVideo/index.ts +261 -0
- package/src/activities/index.ts +164 -0
- package/src/activities/summarize/adapter.ts +107 -0
- package/src/activities/summarize/index.ts +287 -0
- package/src/event-client.ts +5 -21
- package/src/index.ts +60 -15
- package/src/stream-to-response.ts +237 -0
- package/src/types.ts +429 -284
- package/dist/esm/base-adapter.d.ts +0 -36
- package/dist/esm/base-adapter.js +0 -12
- package/dist/esm/base-adapter.js.map +0 -1
- package/dist/esm/core/chat-common-options.d.ts +0 -52
- package/dist/esm/core/chat.d.ts +0 -30
- package/dist/esm/core/chat.js.map +0 -1
- package/dist/esm/core/embedding.d.ts +0 -8
- package/dist/esm/core/embedding.js +0 -33
- package/dist/esm/core/embedding.js.map +0 -1
- package/dist/esm/core/summarize.d.ts +0 -9
- package/dist/esm/core/summarize.js +0 -36
- package/dist/esm/core/summarize.js.map +0 -1
- package/dist/esm/message-converters.js.map +0 -1
- package/dist/esm/stream/json-parser.js.map +0 -1
- package/dist/esm/stream/message-updaters.js.map +0 -1
- package/dist/esm/stream/processor.js.map +0 -1
- package/dist/esm/stream/strategies.js.map +0 -1
- package/dist/esm/tools/tool-calls.js.map +0 -1
- package/dist/esm/tools/tool-definition.js.map +0 -1
- package/dist/esm/tools/zod-converter.d.ts +0 -30
- package/dist/esm/tools/zod-converter.js +0 -36
- package/dist/esm/tools/zod-converter.js.map +0 -1
- package/dist/esm/utilities/agent-loop-strategies.js.map +0 -1
- package/dist/esm/utilities/chat-options.d.ts +0 -6
- package/dist/esm/utilities/chat-options.js +0 -7
- package/dist/esm/utilities/chat-options.js.map +0 -1
- package/dist/esm/utilities/messages.d.ts +0 -30
- package/dist/esm/utilities/messages.js +0 -7
- package/dist/esm/utilities/messages.js.map +0 -1
- package/dist/esm/utilities/stream-to-response.d.ts +0 -48
- package/dist/esm/utilities/stream-to-response.js +0 -62
- package/dist/esm/utilities/stream-to-response.js.map +0 -1
- package/src/base-adapter.ts +0 -86
- package/src/core/chat-common-options.ts +0 -55
- package/src/core/embedding.ts +0 -54
- package/src/core/summarize.ts +0 -56
- package/src/tools/zod-converter.ts +0 -85
- package/src/utilities/chat-options.ts +0 -35
- package/src/utilities/messages.ts +0 -63
- package/src/utilities/stream-to-response.ts +0 -116
- /package/dist/esm/{utilities → activities/chat}/agent-loop-strategies.js +0 -0
- /package/dist/esm/{stream → activities/chat/stream}/index.d.ts +0 -0
- /package/dist/esm/{stream → activities/chat/stream}/json-parser.d.ts +0 -0
- /package/dist/esm/{stream → activities/chat/stream}/json-parser.js +0 -0
- /package/dist/esm/{stream → activities/chat/stream}/message-updaters.js +0 -0
- /package/dist/esm/{stream → activities/chat/stream}/strategies.d.ts +0 -0
- /package/dist/esm/{stream → activities/chat/stream}/strategies.js +0 -0
- /package/dist/esm/{tools → activities/chat/tools}/tool-definition.js +0 -0
- /package/src/{stream → activities/chat/stream}/index.ts +0 -0
- /package/src/{stream → activities/chat/stream}/json-parser.ts +0 -0
- /package/src/{stream → activities/chat/stream}/strategies.ts +0 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
class BaseTTSAdapter {
|
|
2
|
+
constructor(config = {}, model) {
|
|
3
|
+
this.kind = "tts";
|
|
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
|
+
BaseTTSAdapter
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sources":["../../../../src/activities/generateSpeech/adapter.ts"],"sourcesContent":["import type { TTSOptions, TTSResult } from '../../types'\n\n/**\n * Configuration for TTS adapter instances\n */\nexport interface TTSAdapterConfig {\n apiKey?: string\n baseUrl?: string\n timeout?: number\n maxRetries?: number\n headers?: Record<string, string>\n}\n\n/**\n * TTS 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., 'tts-1')\n * - TProviderOptions: Provider-specific options (already resolved)\n */\nexport interface TTSAdapter<\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: 'tts'\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 * Generate speech from text\n */\n generateSpeech: (options: TTSOptions<TProviderOptions>) => Promise<TTSResult>\n}\n\n/**\n * A TTSAdapter with any/unknown type parameters.\n * Useful as a constraint in generic functions and interfaces.\n */\nexport type AnyTTSAdapter = TTSAdapter<any, any>\n\n/**\n * Abstract base class for text-to-speech adapters.\n * Extend this class to implement a TTS adapter for a specific provider.\n *\n * Generic parameters match TTSAdapter - all pre-resolved by the provider function.\n */\nexport abstract class BaseTTSAdapter<\n TModel extends string = string,\n TProviderOptions extends object = Record<string, unknown>,\n> implements TTSAdapter<TModel, TProviderOptions> {\n readonly kind = 'tts' 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: TTSAdapterConfig\n\n constructor(config: TTSAdapterConfig = {}, model: TModel) {\n this.config = config\n this.model = model\n }\n\n abstract generateSpeech(\n options: TTSOptions<TProviderOptions>,\n ): Promise<TTSResult>\n\n protected generateId(): string {\n return `${this.name}-${Date.now()}-${Math.random().toString(36).substring(7)}`\n }\n}\n"],"names":[],"mappings":"AA2DO,MAAe,eAG4B;AAAA,EAYhD,YAAY,SAA2B,CAAA,GAAI,OAAe;AAX1D,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,69 @@
|
|
|
1
|
+
import { TTSAdapter } from './adapter.js';
|
|
2
|
+
import { TTSResult } from '../../types.js';
|
|
3
|
+
/** The adapter kind this activity handles */
|
|
4
|
+
export declare const kind: "tts";
|
|
5
|
+
/**
|
|
6
|
+
* Extract provider options from a TTSAdapter via ~types.
|
|
7
|
+
*/
|
|
8
|
+
export type TTSProviderOptions<TAdapter> = TAdapter extends TTSAdapter<any, any> ? TAdapter['~types']['providerOptions'] : object;
|
|
9
|
+
/**
|
|
10
|
+
* Options for the TTS activity.
|
|
11
|
+
* The model is extracted from the adapter's model property.
|
|
12
|
+
*
|
|
13
|
+
* @template TAdapter - The TTS adapter type
|
|
14
|
+
*/
|
|
15
|
+
export interface TTSActivityOptions<TAdapter extends TTSAdapter<string, object>> {
|
|
16
|
+
/** The TTS adapter to use (must be created with a model) */
|
|
17
|
+
adapter: TAdapter & {
|
|
18
|
+
kind: typeof kind;
|
|
19
|
+
};
|
|
20
|
+
/** The text to convert to speech */
|
|
21
|
+
text: string;
|
|
22
|
+
/** The voice to use for generation */
|
|
23
|
+
voice?: string;
|
|
24
|
+
/** The output audio format */
|
|
25
|
+
format?: 'mp3' | 'opus' | 'aac' | 'flac' | 'wav' | 'pcm';
|
|
26
|
+
/** The speed of the generated audio (0.25 to 4.0) */
|
|
27
|
+
speed?: number;
|
|
28
|
+
/** Provider-specific options for TTS generation */
|
|
29
|
+
modelOptions?: TTSProviderOptions<TAdapter>;
|
|
30
|
+
}
|
|
31
|
+
/** Result type for the TTS activity */
|
|
32
|
+
export type TTSActivityResult = Promise<TTSResult>;
|
|
33
|
+
/**
|
|
34
|
+
* TTS activity - generates speech from text.
|
|
35
|
+
*
|
|
36
|
+
* Uses AI text-to-speech models to create audio from natural language text.
|
|
37
|
+
*
|
|
38
|
+
* @example Generate speech from text
|
|
39
|
+
* ```ts
|
|
40
|
+
* import { generateSpeech } from '@tanstack/ai'
|
|
41
|
+
* import { openaiTTS } from '@tanstack/ai-openai'
|
|
42
|
+
*
|
|
43
|
+
* const result = await generateSpeech({
|
|
44
|
+
* adapter: openaiTTS('tts-1-hd'),
|
|
45
|
+
* text: 'Hello, welcome to TanStack AI!',
|
|
46
|
+
* voice: 'nova'
|
|
47
|
+
* })
|
|
48
|
+
*
|
|
49
|
+
* console.log(result.audio) // base64-encoded audio
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @example With format and speed options
|
|
53
|
+
* ```ts
|
|
54
|
+
* const result = await generateSpeech({
|
|
55
|
+
* adapter: openaiTTS('tts-1'),
|
|
56
|
+
* text: 'This is slower speech.',
|
|
57
|
+
* voice: 'alloy',
|
|
58
|
+
* format: 'wav',
|
|
59
|
+
* speed: 0.8
|
|
60
|
+
* })
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function generateSpeech<TAdapter extends TTSAdapter<string, object>>(options: TTSActivityOptions<TAdapter>): TTSActivityResult;
|
|
64
|
+
/**
|
|
65
|
+
* Create typed options for the generateSpeech() function without executing.
|
|
66
|
+
*/
|
|
67
|
+
export declare function createSpeechOptions<TAdapter extends TTSAdapter<string, object>>(options: TTSActivityOptions<TAdapter>): TTSActivityOptions<TAdapter>;
|
|
68
|
+
export type { TTSAdapter, TTSAdapterConfig, AnyTTSAdapter } from './adapter.js';
|
|
69
|
+
export { BaseTTSAdapter } from './adapter.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const kind = "tts";
|
|
2
|
+
async function generateSpeech(options) {
|
|
3
|
+
const { adapter, ...rest } = options;
|
|
4
|
+
const model = adapter.model;
|
|
5
|
+
return adapter.generateSpeech({ ...rest, model });
|
|
6
|
+
}
|
|
7
|
+
function createSpeechOptions(options) {
|
|
8
|
+
return options;
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
createSpeechOptions,
|
|
12
|
+
generateSpeech,
|
|
13
|
+
kind
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/activities/generateSpeech/index.ts"],"sourcesContent":["/**\n * TTS Activity\n *\n * Generates speech audio from text using text-to-speech models.\n * This is a self-contained module with implementation, types, and JSDoc.\n */\n\nimport type { TTSAdapter } from './adapter'\nimport type { TTSResult } from '../../types'\n\n// ===========================\n// Activity Kind\n// ===========================\n\n/** The adapter kind this activity handles */\nexport const kind = 'tts' as const\n\n// ===========================\n// Type Extraction Helpers\n// ===========================\n\n/**\n * Extract provider options from a TTSAdapter via ~types.\n */\nexport type TTSProviderOptions<TAdapter> =\n TAdapter extends TTSAdapter<any, any>\n ? TAdapter['~types']['providerOptions']\n : object\n\n// ===========================\n// Activity Options Type\n// ===========================\n\n/**\n * Options for the TTS activity.\n * The model is extracted from the adapter's model property.\n *\n * @template TAdapter - The TTS adapter type\n */\nexport interface TTSActivityOptions<\n TAdapter extends TTSAdapter<string, object>,\n> {\n /** The TTS adapter to use (must be created with a model) */\n adapter: TAdapter & { kind: typeof kind }\n /** The text to convert to speech */\n text: string\n /** The voice to use for generation */\n voice?: string\n /** The output audio format */\n format?: 'mp3' | 'opus' | 'aac' | 'flac' | 'wav' | 'pcm'\n /** The speed of the generated audio (0.25 to 4.0) */\n speed?: number\n /** Provider-specific options for TTS generation */\n modelOptions?: TTSProviderOptions<TAdapter>\n}\n\n// ===========================\n// Activity Result Type\n// ===========================\n\n/** Result type for the TTS activity */\nexport type TTSActivityResult = Promise<TTSResult>\n\n// ===========================\n// Activity Implementation\n// ===========================\n\n/**\n * TTS activity - generates speech from text.\n *\n * Uses AI text-to-speech models to create audio from natural language text.\n *\n * @example Generate speech from text\n * ```ts\n * import { generateSpeech } from '@tanstack/ai'\n * import { openaiTTS } from '@tanstack/ai-openai'\n *\n * const result = await generateSpeech({\n * adapter: openaiTTS('tts-1-hd'),\n * text: 'Hello, welcome to TanStack AI!',\n * voice: 'nova'\n * })\n *\n * console.log(result.audio) // base64-encoded audio\n * ```\n *\n * @example With format and speed options\n * ```ts\n * const result = await generateSpeech({\n * adapter: openaiTTS('tts-1'),\n * text: 'This is slower speech.',\n * voice: 'alloy',\n * format: 'wav',\n * speed: 0.8\n * })\n * ```\n */\nexport async function generateSpeech<\n TAdapter extends TTSAdapter<string, object>,\n>(options: TTSActivityOptions<TAdapter>): TTSActivityResult {\n const { adapter, ...rest } = options\n const model = adapter.model\n\n return adapter.generateSpeech({ ...rest, model })\n}\n\n// ===========================\n// Options Factory\n// ===========================\n\n/**\n * Create typed options for the generateSpeech() function without executing.\n */\nexport function createSpeechOptions<\n TAdapter extends TTSAdapter<string, object>,\n>(options: TTSActivityOptions<TAdapter>): TTSActivityOptions<TAdapter> {\n return options\n}\n\n// Re-export adapter types\nexport type { TTSAdapter, TTSAdapterConfig, AnyTTSAdapter } from './adapter'\nexport { BaseTTSAdapter } from './adapter'\n"],"names":[],"mappings":"AAeO,MAAM,OAAO;AAkFpB,eAAsB,eAEpB,SAA0D;AAC1D,QAAM,EAAE,SAAS,GAAG,KAAA,IAAS;AAC7B,QAAM,QAAQ,QAAQ;AAEtB,SAAO,QAAQ,eAAe,EAAE,GAAG,MAAM,OAAO;AAClD;AASO,SAAS,oBAEd,SAAqE;AACrE,SAAO;AACT;"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { TranscriptionOptions, TranscriptionResult } from '../../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration for transcription adapter instances
|
|
4
|
+
*/
|
|
5
|
+
export interface TranscriptionAdapterConfig {
|
|
6
|
+
apiKey?: string;
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
timeout?: number;
|
|
9
|
+
maxRetries?: number;
|
|
10
|
+
headers?: Record<string, string>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Transcription 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., 'whisper-1')
|
|
20
|
+
* - TProviderOptions: Provider-specific options (already resolved)
|
|
21
|
+
*/
|
|
22
|
+
export interface TranscriptionAdapter<TModel extends string = string, TProviderOptions extends object = Record<string, unknown>> {
|
|
23
|
+
/** Discriminator for adapter kind - used to determine API shape */
|
|
24
|
+
readonly kind: 'transcription';
|
|
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
|
+
* Transcribe audio to text
|
|
37
|
+
*/
|
|
38
|
+
transcribe: (options: TranscriptionOptions<TProviderOptions>) => Promise<TranscriptionResult>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A TranscriptionAdapter with any/unknown type parameters.
|
|
42
|
+
* Useful as a constraint in generic functions and interfaces.
|
|
43
|
+
*/
|
|
44
|
+
export type AnyTranscriptionAdapter = TranscriptionAdapter<any, any>;
|
|
45
|
+
/**
|
|
46
|
+
* Abstract base class for audio transcription adapters.
|
|
47
|
+
* Extend this class to implement a transcription adapter for a specific provider.
|
|
48
|
+
*
|
|
49
|
+
* Generic parameters match TranscriptionAdapter - all pre-resolved by the provider function.
|
|
50
|
+
*/
|
|
51
|
+
export declare abstract class BaseTranscriptionAdapter<TModel extends string = string, TProviderOptions extends object = Record<string, unknown>> implements TranscriptionAdapter<TModel, TProviderOptions> {
|
|
52
|
+
readonly kind: "transcription";
|
|
53
|
+
abstract readonly name: string;
|
|
54
|
+
readonly model: TModel;
|
|
55
|
+
'~types': {
|
|
56
|
+
providerOptions: TProviderOptions;
|
|
57
|
+
};
|
|
58
|
+
protected config: TranscriptionAdapterConfig;
|
|
59
|
+
constructor(config: TranscriptionAdapterConfig | undefined, model: TModel);
|
|
60
|
+
abstract transcribe(options: TranscriptionOptions<TProviderOptions>): Promise<TranscriptionResult>;
|
|
61
|
+
protected generateId(): string;
|
|
62
|
+
}
|
|
@@ -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';
|