@tanstack/ai-client 0.18.4 → 0.18.5
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/package.json +3 -3
- package/dist/esm/chat-client.d.ts +0 -264
- package/dist/esm/chat-client.js +0 -1097
- package/dist/esm/chat-client.js.map +0 -1
- package/dist/esm/client-persistor.d.ts +0 -86
- package/dist/esm/client-persistor.js +0 -243
- package/dist/esm/client-persistor.js.map +0 -1
- package/dist/esm/connection-adapters.d.ts +0 -203
- package/dist/esm/connection-adapters.js +0 -611
- package/dist/esm/connection-adapters.js.map +0 -1
- package/dist/esm/devtools-noop.d.ts +0 -63
- package/dist/esm/devtools-noop.js +0 -141
- package/dist/esm/devtools-noop.js.map +0 -1
- package/dist/esm/devtools.d.ts +0 -276
- package/dist/esm/devtools.js +0 -1178
- package/dist/esm/devtools.js.map +0 -1
- package/dist/esm/events.d.ts +0 -129
- package/dist/esm/events.js +0 -227
- package/dist/esm/events.js.map +0 -1
- package/dist/esm/generation-client.d.ts +0 -99
- package/dist/esm/generation-client.js +0 -325
- package/dist/esm/generation-client.js.map +0 -1
- package/dist/esm/generation-types.d.ts +0 -242
- package/dist/esm/generation-types.js +0 -14
- package/dist/esm/generation-types.js.map +0 -1
- package/dist/esm/index.d.ts +0 -16
- package/dist/esm/index.js +0 -44
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/realtime-client.d.ts +0 -98
- package/dist/esm/realtime-client.js +0 -403
- package/dist/esm/realtime-client.js.map +0 -1
- package/dist/esm/realtime-types.d.ts +0 -78
- package/dist/esm/response-stream.d.ts +0 -7
- package/dist/esm/response-stream.js +0 -32
- package/dist/esm/response-stream.js.map +0 -1
- package/dist/esm/sse-parser.d.ts +0 -8
- package/dist/esm/sse-parser.js +0 -52
- package/dist/esm/sse-parser.js.map +0 -1
- package/dist/esm/sse-utils.d.ts +0 -1
- package/dist/esm/sse-utils.js +0 -11
- package/dist/esm/sse-utils.js.map +0 -1
- package/dist/esm/tool-types.d.ts +0 -20
- package/dist/esm/types.d.ts +0 -419
- package/dist/esm/types.js +0 -11
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/video-generation-client.d.ts +0 -110
- package/dist/esm/video-generation-client.js +0 -382
- package/dist/esm/video-generation-client.js.map +0 -1
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
import { MediaPrompt, StreamChunk } from '@tanstack/ai/client';
|
|
2
|
-
import { ConnectConnectionAdapter } from './connection-adapters.js';
|
|
3
|
-
import { AIDevtoolsClientMetadata } from './devtools.js';
|
|
4
|
-
import { GenerationDevtoolsBridgeFactory, VideoDevtoolsBridgeFactory } from './devtools-noop.js';
|
|
5
|
-
/**
|
|
6
|
-
* Infers the output type from an `onResult` callback's return type.
|
|
7
|
-
*
|
|
8
|
-
* - If the callback returns a concrete type (excluding null/void/undefined), uses that type.
|
|
9
|
-
* - If the callback only returns null/void/undefined, or is not provided, falls back to TResult.
|
|
10
|
-
*
|
|
11
|
-
* @template TResult - The raw result type from the generation
|
|
12
|
-
* @template TFn - The onResult callback type (or undefined if not provided)
|
|
13
|
-
*/
|
|
14
|
-
export type InferGenerationOutput<TResult, TFn> = TFn extends (result: any) => infer R ? [Exclude<R, null | void | undefined>] extends [never] ? TResult : Exclude<R, null | void | undefined> : TResult;
|
|
15
|
-
/**
|
|
16
|
-
* State machine for generation clients.
|
|
17
|
-
* Simpler than ChatClientState since generation is a single request/response cycle.
|
|
18
|
-
*/
|
|
19
|
-
export type GenerationClientState = 'idle' | 'generating' | 'success' | 'error';
|
|
20
|
-
/**
|
|
21
|
-
* Well-known CUSTOM event names used by generation clients.
|
|
22
|
-
* These events are emitted by the server-side streaming helpers
|
|
23
|
-
* and consumed by the client-side GenerationClient.
|
|
24
|
-
*/
|
|
25
|
-
export declare const GENERATION_EVENTS: {
|
|
26
|
-
/** The generation result payload */
|
|
27
|
-
readonly RESULT: "generation:result";
|
|
28
|
-
/** Progress update (0-100) with optional message */
|
|
29
|
-
readonly PROGRESS: "generation:progress";
|
|
30
|
-
/** Video job created with jobId */
|
|
31
|
-
readonly VIDEO_JOB_CREATED: "video:job:created";
|
|
32
|
-
/** Video job status update */
|
|
33
|
-
readonly VIDEO_STATUS: "video:status";
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* Options passed to a fetcher function by the generation client.
|
|
37
|
-
*/
|
|
38
|
-
export interface GenerationFetcherOptions {
|
|
39
|
-
/** AbortSignal that is triggered when the user calls `stop()` */
|
|
40
|
-
signal: AbortSignal;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* A direct async function that performs a generation request.
|
|
44
|
-
*
|
|
45
|
-
* Can return the result directly, or return a `Response` with an SSE body
|
|
46
|
-
* (e.g., from a TanStack Start server function using `toServerSentEventsResponse()`).
|
|
47
|
-
* When a `Response` is returned, the client will parse it as an SSE stream.
|
|
48
|
-
*
|
|
49
|
-
* @template TInput - The input type for the generation request
|
|
50
|
-
* @template TResult - The result type returned by the generation
|
|
51
|
-
*/
|
|
52
|
-
export type GenerationFetcher<TInput, TResult> = (input: TInput, options?: GenerationFetcherOptions) => Promise<TResult | Response>;
|
|
53
|
-
/**
|
|
54
|
-
* Transport configuration for generation clients.
|
|
55
|
-
* Supports either a connect-based streaming adapter or a direct fetcher function.
|
|
56
|
-
*/
|
|
57
|
-
export type GenerationTransport<TInput, TResult> = {
|
|
58
|
-
connection: ConnectConnectionAdapter;
|
|
59
|
-
fetcher?: never;
|
|
60
|
-
} | {
|
|
61
|
-
fetcher: GenerationFetcher<TInput, TResult>;
|
|
62
|
-
connection?: never;
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* Options for the GenerationClient.
|
|
66
|
-
*
|
|
67
|
-
* @template TInput - The input type for the generation request (used by consuming code)
|
|
68
|
-
* @template TResult - The result type returned by the generation
|
|
69
|
-
* @template TOutput - The output type after optional transform (defaults to TResult)
|
|
70
|
-
*/
|
|
71
|
-
export interface GenerationClientOptions<_TInput, TResult, TOutput = TResult> {
|
|
72
|
-
/** Unique identifier for this generation client instance */
|
|
73
|
-
id?: string;
|
|
74
|
-
/** Additional body parameters to send with connect-based adapter requests */
|
|
75
|
-
body?: Record<string, any>;
|
|
76
|
-
/** Metadata used to register this generation hook with TanStack AI Devtools */
|
|
77
|
-
devtools?: Partial<AIDevtoolsClientMetadata>;
|
|
78
|
-
/**
|
|
79
|
-
* Factory that constructs the devtools bridge. Default is a no-op
|
|
80
|
-
* factory; the real implementation lives in `@tanstack/ai-client/devtools`.
|
|
81
|
-
*/
|
|
82
|
-
devtoolsBridgeFactory?: GenerationDevtoolsBridgeFactory;
|
|
83
|
-
/**
|
|
84
|
-
* Callback when a result is received. Can optionally return a transformed value
|
|
85
|
-
* that replaces the stored result.
|
|
86
|
-
*
|
|
87
|
-
* - Return a non-null value to transform and store it as the result
|
|
88
|
-
* - Return `null` to keep the previous result unchanged
|
|
89
|
-
* - Return nothing (`void`) to store the raw result as-is
|
|
90
|
-
*/
|
|
91
|
-
onResult?: (result: TResult) => TOutput | null | void;
|
|
92
|
-
/** Callback when an error occurs */
|
|
93
|
-
onError?: (error: Error) => void;
|
|
94
|
-
/** Callback when progress is reported (0-100) */
|
|
95
|
-
onProgress?: (progress: number, message?: string) => void;
|
|
96
|
-
/** Callback for each stream chunk (connect-based adapter mode only) */
|
|
97
|
-
onChunk?: (chunk: StreamChunk) => void;
|
|
98
|
-
/** @internal Called when result changes */
|
|
99
|
-
onResultChange?: (result: TOutput | null) => void;
|
|
100
|
-
/** @internal Called when loading state changes */
|
|
101
|
-
onLoadingChange?: (isLoading: boolean) => void;
|
|
102
|
-
/** @internal Called when error state changes */
|
|
103
|
-
onErrorChange?: (error: Error | undefined) => void;
|
|
104
|
-
/** @internal Called when generation status changes */
|
|
105
|
-
onStatusChange?: (status: GenerationClientState) => void;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Video status information returned during job polling.
|
|
109
|
-
*/
|
|
110
|
-
export interface VideoStatusInfo {
|
|
111
|
-
/** Job identifier */
|
|
112
|
-
jobId: string;
|
|
113
|
-
/** Current status of the video generation job */
|
|
114
|
-
status: 'pending' | 'processing' | 'completed' | 'failed';
|
|
115
|
-
/** Progress percentage (0-100), if available */
|
|
116
|
-
progress?: number;
|
|
117
|
-
/** URL to the generated video (when completed) */
|
|
118
|
-
url?: string;
|
|
119
|
-
/** Error message if status is 'failed' */
|
|
120
|
-
error?: string;
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Composite result for video generation (job completion).
|
|
124
|
-
*/
|
|
125
|
-
export interface VideoGenerateResult {
|
|
126
|
-
/** Job identifier */
|
|
127
|
-
jobId: string;
|
|
128
|
-
/** Final status */
|
|
129
|
-
status: 'completed';
|
|
130
|
-
/** URL to the generated video */
|
|
131
|
-
url: string;
|
|
132
|
-
/** When the URL expires, if applicable */
|
|
133
|
-
expiresAt?: Date;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Options for the VideoGenerationClient.
|
|
137
|
-
*/
|
|
138
|
-
export interface VideoGenerationClientOptions<TOutput = VideoGenerateResult> extends Omit<GenerationClientOptions<VideoGenerateInput, VideoGenerateResult, TOutput>, 'devtoolsBridgeFactory'> {
|
|
139
|
-
/**
|
|
140
|
-
* Factory that constructs the video devtools bridge. Default is a no-op
|
|
141
|
-
* factory; the real implementation lives in `@tanstack/ai-client/devtools`.
|
|
142
|
-
*/
|
|
143
|
-
devtoolsBridgeFactory?: VideoDevtoolsBridgeFactory;
|
|
144
|
-
/** Callback when a video job is created */
|
|
145
|
-
onJobCreated?: (jobId: string) => void;
|
|
146
|
-
/** Callback on each status update */
|
|
147
|
-
onStatusUpdate?: (status: VideoStatusInfo) => void;
|
|
148
|
-
/** @internal Called when jobId changes */
|
|
149
|
-
onJobIdChange?: (jobId: string | null) => void;
|
|
150
|
-
/** @internal Called when video status changes */
|
|
151
|
-
onVideoStatusChange?: (status: VideoStatusInfo | null) => void;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Input for image generation.
|
|
155
|
-
*/
|
|
156
|
-
export interface ImageGenerateInput {
|
|
157
|
-
/**
|
|
158
|
-
* Description of the desired image(s): plain text, or an ordered array of
|
|
159
|
-
* content parts (text + image) for image-conditioned generation
|
|
160
|
-
* (image-to-image, multi-reference, edit / inpaint).
|
|
161
|
-
*/
|
|
162
|
-
prompt: MediaPrompt;
|
|
163
|
-
/** Number of images to generate (default: 1) */
|
|
164
|
-
numberOfImages?: number;
|
|
165
|
-
/** Image size in WIDTHxHEIGHT format (e.g., "1024x1024") */
|
|
166
|
-
size?: string;
|
|
167
|
-
/** Model-specific options */
|
|
168
|
-
modelOptions?: Record<string, any>;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Input for audio generation (music, sound effects).
|
|
172
|
-
*/
|
|
173
|
-
export interface AudioGenerateInput {
|
|
174
|
-
/** Text description of the desired audio */
|
|
175
|
-
prompt: string;
|
|
176
|
-
/** Desired duration in seconds */
|
|
177
|
-
duration?: number;
|
|
178
|
-
/** Model-specific options */
|
|
179
|
-
modelOptions?: Record<string, any>;
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Input for text-to-speech generation.
|
|
183
|
-
*/
|
|
184
|
-
export interface SpeechGenerateInput {
|
|
185
|
-
/** The text to convert to speech */
|
|
186
|
-
text: string;
|
|
187
|
-
/** The voice to use for generation */
|
|
188
|
-
voice?: string;
|
|
189
|
-
/** The output audio format */
|
|
190
|
-
format?: 'mp3' | 'opus' | 'aac' | 'flac' | 'wav' | 'pcm';
|
|
191
|
-
/** The speed of the generated audio (0.25 to 4.0) */
|
|
192
|
-
speed?: number;
|
|
193
|
-
/** Model-specific options */
|
|
194
|
-
modelOptions?: Record<string, any>;
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Input for audio transcription.
|
|
198
|
-
*/
|
|
199
|
-
export interface TranscriptionGenerateInput {
|
|
200
|
-
/** The audio data to transcribe - can be base64 string, File, Blob, or ArrayBuffer */
|
|
201
|
-
audio: string | File | Blob | ArrayBuffer;
|
|
202
|
-
/** The language of the audio in ISO-639-1 format (e.g., 'en') */
|
|
203
|
-
language?: string;
|
|
204
|
-
/** An optional prompt to guide the transcription */
|
|
205
|
-
prompt?: string;
|
|
206
|
-
/** The format of the transcription output */
|
|
207
|
-
responseFormat?: 'json' | 'text' | 'srt' | 'verbose_json' | 'vtt';
|
|
208
|
-
/** Model-specific options */
|
|
209
|
-
modelOptions?: Record<string, any>;
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* Input for text summarization.
|
|
213
|
-
*/
|
|
214
|
-
export interface SummarizeGenerateInput {
|
|
215
|
-
/** The text to summarize */
|
|
216
|
-
text: string;
|
|
217
|
-
/** Maximum length of the summary */
|
|
218
|
-
maxLength?: number;
|
|
219
|
-
/** Style of the summary */
|
|
220
|
-
style?: 'bullet-points' | 'paragraph' | 'concise';
|
|
221
|
-
/** Topics to focus on */
|
|
222
|
-
focus?: Array<string>;
|
|
223
|
-
/** Model-specific options */
|
|
224
|
-
modelOptions?: Record<string, any>;
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Input for video generation.
|
|
228
|
-
*/
|
|
229
|
-
export interface VideoGenerateInput {
|
|
230
|
-
/**
|
|
231
|
-
* Description of the desired video: plain text, or an ordered array of
|
|
232
|
-
* content parts (text + image) for image-conditioned generation
|
|
233
|
-
* (image-to-video, start/end frames).
|
|
234
|
-
*/
|
|
235
|
-
prompt: MediaPrompt;
|
|
236
|
-
/** Video size — format depends on provider (e.g., "16:9", "1280x720") */
|
|
237
|
-
size?: string;
|
|
238
|
-
/** Video duration in seconds */
|
|
239
|
-
duration?: number;
|
|
240
|
-
/** Model-specific options */
|
|
241
|
-
modelOptions?: Record<string, any>;
|
|
242
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
const GENERATION_EVENTS = {
|
|
2
|
-
/** The generation result payload */
|
|
3
|
-
RESULT: "generation:result",
|
|
4
|
-
/** Progress update (0-100) with optional message */
|
|
5
|
-
PROGRESS: "generation:progress",
|
|
6
|
-
/** Video job created with jobId */
|
|
7
|
-
VIDEO_JOB_CREATED: "video:job:created",
|
|
8
|
-
/** Video job status update */
|
|
9
|
-
VIDEO_STATUS: "video:status"
|
|
10
|
-
};
|
|
11
|
-
export {
|
|
12
|
-
GENERATION_EVENTS
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=generation-types.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generation-types.js","sources":["../../src/generation-types.ts"],"sourcesContent":["import type { MediaPrompt, StreamChunk } from '@tanstack/ai/client'\nimport type { ConnectConnectionAdapter } from './connection-adapters'\nimport type { AIDevtoolsClientMetadata } from './devtools'\nimport type {\n GenerationDevtoolsBridgeFactory,\n VideoDevtoolsBridgeFactory,\n} from './devtools-noop'\n\n// ===========================\n// Inference Utilities\n// ===========================\n\n/**\n * Infers the output type from an `onResult` callback's return type.\n *\n * - If the callback returns a concrete type (excluding null/void/undefined), uses that type.\n * - If the callback only returns null/void/undefined, or is not provided, falls back to TResult.\n *\n * @template TResult - The raw result type from the generation\n * @template TFn - The onResult callback type (or undefined if not provided)\n */\nexport type InferGenerationOutput<TResult, TFn> = TFn extends (\n result: any,\n) => infer R\n ? [Exclude<R, null | void | undefined>] extends [never]\n ? TResult\n : Exclude<R, null | void | undefined>\n : TResult\n\n// ===========================\n// State\n// ===========================\n\n/**\n * State machine for generation clients.\n * Simpler than ChatClientState since generation is a single request/response cycle.\n */\nexport type GenerationClientState = 'idle' | 'generating' | 'success' | 'error'\n\n// ===========================\n// Event Constants\n// ===========================\n\n/**\n * Well-known CUSTOM event names used by generation clients.\n * These events are emitted by the server-side streaming helpers\n * and consumed by the client-side GenerationClient.\n */\nexport const GENERATION_EVENTS = {\n /** The generation result payload */\n RESULT: 'generation:result',\n /** Progress update (0-100) with optional message */\n PROGRESS: 'generation:progress',\n /** Video job created with jobId */\n VIDEO_JOB_CREATED: 'video:job:created',\n /** Video job status update */\n VIDEO_STATUS: 'video:status',\n} as const\n\n// ===========================\n// Transport Types\n// ===========================\n\n/**\n * Options passed to a fetcher function by the generation client.\n */\nexport interface GenerationFetcherOptions {\n /** AbortSignal that is triggered when the user calls `stop()` */\n signal: AbortSignal\n}\n\n/**\n * A direct async function that performs a generation request.\n *\n * Can return the result directly, or return a `Response` with an SSE body\n * (e.g., from a TanStack Start server function using `toServerSentEventsResponse()`).\n * When a `Response` is returned, the client will parse it as an SSE stream.\n *\n * @template TInput - The input type for the generation request\n * @template TResult - The result type returned by the generation\n */\nexport type GenerationFetcher<TInput, TResult> = (\n input: TInput,\n options?: GenerationFetcherOptions,\n) => Promise<TResult | Response>\n\n/**\n * Transport configuration for generation clients.\n * Supports either a connect-based streaming adapter or a direct fetcher function.\n */\nexport type GenerationTransport<TInput, TResult> =\n | { connection: ConnectConnectionAdapter; fetcher?: never }\n | { fetcher: GenerationFetcher<TInput, TResult>; connection?: never }\n\n// ===========================\n// Client Options\n// ===========================\n\n/**\n * Options for the GenerationClient.\n *\n * @template TInput - The input type for the generation request (used by consuming code)\n * @template TResult - The result type returned by the generation\n * @template TOutput - The output type after optional transform (defaults to TResult)\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention -- _TInput is unused in the interface body but part of the public positional generic API (callers supply it for inference)\nexport interface GenerationClientOptions<_TInput, TResult, TOutput = TResult> {\n /** Unique identifier for this generation client instance */\n id?: string\n\n /** Additional body parameters to send with connect-based adapter requests */\n body?: Record<string, any>\n\n /** Metadata used to register this generation hook with TanStack AI Devtools */\n devtools?: Partial<AIDevtoolsClientMetadata>\n\n /**\n * Factory that constructs the devtools bridge. Default is a no-op\n * factory; the real implementation lives in `@tanstack/ai-client/devtools`.\n */\n devtoolsBridgeFactory?: GenerationDevtoolsBridgeFactory\n\n /**\n * Callback when a result is received. Can optionally return a transformed value\n * that replaces the stored result.\n *\n * - Return a non-null value to transform and store it as the result\n * - Return `null` to keep the previous result unchanged\n * - Return nothing (`void`) to store the raw result as-is\n */\n onResult?: (result: TResult) => TOutput | null | void\n /** Callback when an error occurs */\n onError?: (error: Error) => void\n /** Callback when progress is reported (0-100) */\n onProgress?: (progress: number, message?: string) => void\n /** Callback for each stream chunk (connect-based adapter mode only) */\n onChunk?: (chunk: StreamChunk) => void\n\n // Framework state callbacks (set by hooks, not users)\n /** @internal Called when result changes */\n onResultChange?: (result: TOutput | null) => void\n /** @internal Called when loading state changes */\n onLoadingChange?: (isLoading: boolean) => void\n /** @internal Called when error state changes */\n onErrorChange?: (error: Error | undefined) => void\n /** @internal Called when generation status changes */\n onStatusChange?: (status: GenerationClientState) => void\n}\n\n// ===========================\n// Video-Specific Options\n// ===========================\n\n/**\n * Video status information returned during job polling.\n */\nexport interface VideoStatusInfo {\n /** Job identifier */\n jobId: string\n /** Current status of the video generation job */\n status: 'pending' | 'processing' | 'completed' | 'failed'\n /** Progress percentage (0-100), if available */\n progress?: number\n /** URL to the generated video (when completed) */\n url?: string\n /** Error message if status is 'failed' */\n error?: string\n}\n\n/**\n * Composite result for video generation (job completion).\n */\nexport interface VideoGenerateResult {\n /** Job identifier */\n jobId: string\n /** Final status */\n status: 'completed'\n /** URL to the generated video */\n url: string\n /** When the URL expires, if applicable */\n expiresAt?: Date\n}\n\n/**\n * Options for the VideoGenerationClient.\n */\nexport interface VideoGenerationClientOptions<\n TOutput = VideoGenerateResult,\n> extends Omit<\n GenerationClientOptions<VideoGenerateInput, VideoGenerateResult, TOutput>,\n 'devtoolsBridgeFactory'\n> {\n /**\n * Factory that constructs the video devtools bridge. Default is a no-op\n * factory; the real implementation lives in `@tanstack/ai-client/devtools`.\n */\n devtoolsBridgeFactory?: VideoDevtoolsBridgeFactory\n\n /** Callback when a video job is created */\n onJobCreated?: (jobId: string) => void\n /** Callback on each status update */\n onStatusUpdate?: (status: VideoStatusInfo) => void\n\n // Framework state callbacks\n /** @internal Called when jobId changes */\n onJobIdChange?: (jobId: string | null) => void\n /** @internal Called when video status changes */\n onVideoStatusChange?: (status: VideoStatusInfo | null) => void\n}\n\n// ===========================\n// Input Types\n// ===========================\n\n/**\n * Input for image generation.\n */\nexport interface ImageGenerateInput {\n /**\n * Description of the desired image(s): plain text, or an ordered array of\n * content parts (text + image) for image-conditioned generation\n * (image-to-image, multi-reference, edit / inpaint).\n */\n prompt: MediaPrompt\n /** Number of images to generate (default: 1) */\n numberOfImages?: number\n /** Image size in WIDTHxHEIGHT format (e.g., \"1024x1024\") */\n size?: string\n /** Model-specific options */\n modelOptions?: Record<string, any>\n}\n\n/**\n * Input for audio generation (music, sound effects).\n */\nexport interface AudioGenerateInput {\n /** Text description of the desired audio */\n prompt: string\n /** Desired duration in seconds */\n duration?: number\n /** Model-specific options */\n modelOptions?: Record<string, any>\n}\n\n/**\n * Input for text-to-speech generation.\n */\nexport interface SpeechGenerateInput {\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 /** Model-specific options */\n modelOptions?: Record<string, any>\n}\n\n/**\n * Input for audio transcription.\n */\nexport interface TranscriptionGenerateInput {\n /** The audio data to transcribe - can be base64 string, File, Blob, or ArrayBuffer */\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 /** Model-specific options */\n modelOptions?: Record<string, any>\n}\n\n/**\n * Input for text summarization.\n */\nexport interface SummarizeGenerateInput {\n /** The text to summarize */\n text: string\n /** Maximum length of the summary */\n maxLength?: number\n /** Style of the summary */\n style?: 'bullet-points' | 'paragraph' | 'concise'\n /** Topics to focus on */\n focus?: Array<string>\n /** Model-specific options */\n modelOptions?: Record<string, any>\n}\n\n/**\n * Input for video generation.\n */\nexport interface VideoGenerateInput {\n /**\n * Description of the desired video: plain text, or an ordered array of\n * content parts (text + image) for image-conditioned generation\n * (image-to-video, start/end frames).\n */\n prompt: MediaPrompt\n /** Video size — format depends on provider (e.g., \"16:9\", \"1280x720\") */\n size?: string\n /** Video duration in seconds */\n duration?: number\n /** Model-specific options */\n modelOptions?: Record<string, any>\n}\n"],"names":[],"mappings":"AAgDO,MAAM,oBAAoB;AAAA;AAAA,EAE/B,QAAQ;AAAA;AAAA,EAER,UAAU;AAAA;AAAA,EAEV,mBAAmB;AAAA;AAAA,EAEnB,cAAc;AAChB;"}
|
package/dist/esm/index.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export { ChatClient } from './chat-client.js';
|
|
2
|
-
export { RealtimeClient } from './realtime-client.js';
|
|
3
|
-
export { GenerationClient } from './generation-client.js';
|
|
4
|
-
export { VideoGenerationClient } from './video-generation-client.js';
|
|
5
|
-
export type { UIMessage, MessagePart, TextPart, ToolCallPart, ToolResultPart, ThinkingPart, StructuredOutputPart, ChatClientPersistence, ChatClientOptions, ClientContextOptionFromTools, ChatRequestBody, InferChatMessages, InferredClientContext, ChatClientState, ConnectionStatus, ChatFetcher, ChatFetcherInput, ChatFetcherOptions, ChatTransport, DistributedOmit, MultimodalContent, } from './types.js';
|
|
6
|
-
export type { InferGenerationOutput, GenerationClientState, GenerationClientOptions, GenerationFetcher, GenerationFetcherOptions, GenerationTransport, VideoGenerationClientOptions, VideoStatusInfo, VideoGenerateResult, ImageGenerateInput, AudioGenerateInput, SpeechGenerateInput, TranscriptionGenerateInput, SummarizeGenerateInput, VideoGenerateInput, } from './generation-types.js';
|
|
7
|
-
export { GENERATION_EVENTS } from './generation-types.js';
|
|
8
|
-
export { UnsupportedResponseStreamError } from './response-stream.js';
|
|
9
|
-
export { clientTools, createChatClientOptions } from './types.js';
|
|
10
|
-
export { createAIDevtoolsGenerationPreview, type AIDevtoolsClientMetadata, type AIDevtoolsDisplayOptions, type AIDevtoolsGenerationMediaItem, type AIDevtoolsGenerationPreview, type AIDevtoolsGenerationProgress, type AIDevtoolsGenerationVideoJob, } from './devtools.js';
|
|
11
|
-
export type { ExtractToolNames, ExtractToolInput, ExtractToolOutput, } from './tool-types.js';
|
|
12
|
-
export type { AnyClientTool } from '@tanstack/ai/client';
|
|
13
|
-
export type { RealtimeAdapter, RealtimeConnection, RealtimeClientOptions, RealtimeClientState, RealtimeStateChangeCallback, } from './realtime-types.js';
|
|
14
|
-
export { fetchServerSentEvents, fetchHttpStream, xhrServerSentEvents, xhrHttpStream, stream, rpcStream, StreamTruncatedError, type ConnectConnectionAdapter, type ConnectionAdapter, type FetchConnectionOptions, type RunAgentInputContext, type SubscribeConnectionAdapter, type XhrConnectionOptions, } from './connection-adapters.js';
|
|
15
|
-
export { uiMessageToModelMessages, modelMessageToUIMessage, modelMessagesToUIMessages, convertMessagesToModelMessages, normalizeToUIMessage, generateMessageId, } from '@tanstack/ai/client';
|
|
16
|
-
export { StreamProcessor, ImmediateStrategy, PunctuationStrategy, BatchStrategy, WordBoundaryStrategy, CompositeStrategy, parsePartialJSON, PartialJSONParser, defaultJSONParser, type ChunkStrategy, type StreamProcessorOptions, type StreamProcessorEvents, type InternalToolCallState, type ToolCallState, type ToolResultState, type JSONParser, type ChunkRecording, type ProcessorResult, type ProcessorState, } from '@tanstack/ai/client';
|
package/dist/esm/index.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { ChatClient } from "./chat-client.js";
|
|
2
|
-
import { RealtimeClient } from "./realtime-client.js";
|
|
3
|
-
import { GenerationClient } from "./generation-client.js";
|
|
4
|
-
import { VideoGenerationClient } from "./video-generation-client.js";
|
|
5
|
-
import { GENERATION_EVENTS } from "./generation-types.js";
|
|
6
|
-
import { UnsupportedResponseStreamError } from "./response-stream.js";
|
|
7
|
-
import { clientTools, createChatClientOptions } from "./types.js";
|
|
8
|
-
import { createAIDevtoolsGenerationPreview } from "./devtools.js";
|
|
9
|
-
import { StreamTruncatedError, fetchHttpStream, fetchServerSentEvents, rpcStream, stream, xhrHttpStream, xhrServerSentEvents } from "./connection-adapters.js";
|
|
10
|
-
import { BatchStrategy, CompositeStrategy, ImmediateStrategy, PartialJSONParser, PunctuationStrategy, StreamProcessor, WordBoundaryStrategy, convertMessagesToModelMessages, defaultJSONParser, generateMessageId, modelMessageToUIMessage, modelMessagesToUIMessages, normalizeToUIMessage, parsePartialJSON, uiMessageToModelMessages } from "@tanstack/ai/client";
|
|
11
|
-
export {
|
|
12
|
-
BatchStrategy,
|
|
13
|
-
ChatClient,
|
|
14
|
-
CompositeStrategy,
|
|
15
|
-
GENERATION_EVENTS,
|
|
16
|
-
GenerationClient,
|
|
17
|
-
ImmediateStrategy,
|
|
18
|
-
PartialJSONParser,
|
|
19
|
-
PunctuationStrategy,
|
|
20
|
-
RealtimeClient,
|
|
21
|
-
StreamProcessor,
|
|
22
|
-
StreamTruncatedError,
|
|
23
|
-
UnsupportedResponseStreamError,
|
|
24
|
-
VideoGenerationClient,
|
|
25
|
-
WordBoundaryStrategy,
|
|
26
|
-
clientTools,
|
|
27
|
-
convertMessagesToModelMessages,
|
|
28
|
-
createAIDevtoolsGenerationPreview,
|
|
29
|
-
createChatClientOptions,
|
|
30
|
-
defaultJSONParser,
|
|
31
|
-
fetchHttpStream,
|
|
32
|
-
fetchServerSentEvents,
|
|
33
|
-
generateMessageId,
|
|
34
|
-
modelMessageToUIMessage,
|
|
35
|
-
modelMessagesToUIMessages,
|
|
36
|
-
normalizeToUIMessage,
|
|
37
|
-
parsePartialJSON,
|
|
38
|
-
rpcStream,
|
|
39
|
-
stream,
|
|
40
|
-
uiMessageToModelMessages,
|
|
41
|
-
xhrHttpStream,
|
|
42
|
-
xhrServerSentEvents
|
|
43
|
-
};
|
|
44
|
-
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { AudioVisualization, RealtimeMessage, RealtimeMode, RealtimeStatus } from '@tanstack/ai/client';
|
|
2
|
-
import { RealtimeClientOptions, RealtimeStateChangeCallback } from './realtime-types.js';
|
|
3
|
-
/**
|
|
4
|
-
* Client for managing realtime voice conversations.
|
|
5
|
-
*
|
|
6
|
-
* Handles connection lifecycle, audio I/O, message state,
|
|
7
|
-
* and tool execution for realtime voice-to-voice AI interactions.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```typescript
|
|
11
|
-
* import { RealtimeClient } from '@tanstack/ai-client'
|
|
12
|
-
* import { openaiRealtime } from '@tanstack/ai-openai'
|
|
13
|
-
*
|
|
14
|
-
* const client = new RealtimeClient({
|
|
15
|
-
* getToken: () => fetch('/api/realtime-token').then(r => r.json()),
|
|
16
|
-
* adapter: openaiRealtime(),
|
|
17
|
-
* tools: [myTool.client(handler)],
|
|
18
|
-
* onMessage: (msg) => console.log('Message:', msg),
|
|
19
|
-
* })
|
|
20
|
-
*
|
|
21
|
-
* await client.connect()
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export declare class RealtimeClient {
|
|
25
|
-
private readonly options;
|
|
26
|
-
private connection;
|
|
27
|
-
private token;
|
|
28
|
-
private tokenRefreshTimeout;
|
|
29
|
-
private readonly clientTools;
|
|
30
|
-
private readonly stateChangeCallbacks;
|
|
31
|
-
private unsubscribers;
|
|
32
|
-
private state;
|
|
33
|
-
constructor(options: RealtimeClientOptions);
|
|
34
|
-
/**
|
|
35
|
-
* Connect to the realtime session.
|
|
36
|
-
* Fetches a token and establishes the connection.
|
|
37
|
-
*/
|
|
38
|
-
connect(): Promise<void>;
|
|
39
|
-
/**
|
|
40
|
-
* Disconnect from the realtime session.
|
|
41
|
-
*/
|
|
42
|
-
disconnect(): Promise<void>;
|
|
43
|
-
/**
|
|
44
|
-
* Start listening for voice input.
|
|
45
|
-
* Only needed when vadMode is 'manual'.
|
|
46
|
-
*/
|
|
47
|
-
startListening(): void;
|
|
48
|
-
/**
|
|
49
|
-
* Stop listening for voice input.
|
|
50
|
-
* Only needed when vadMode is 'manual'.
|
|
51
|
-
*/
|
|
52
|
-
stopListening(): void;
|
|
53
|
-
/**
|
|
54
|
-
* Interrupt the current assistant response.
|
|
55
|
-
*/
|
|
56
|
-
interrupt(): void;
|
|
57
|
-
/**
|
|
58
|
-
* Send a text message instead of voice.
|
|
59
|
-
*/
|
|
60
|
-
sendText(text: string): void;
|
|
61
|
-
/**
|
|
62
|
-
* Send an image to the conversation.
|
|
63
|
-
* @param imageData - Base64-encoded image data or a URL
|
|
64
|
-
* @param mimeType - MIME type of the image (e.g., 'image/png', 'image/jpeg')
|
|
65
|
-
*/
|
|
66
|
-
sendImage(imageData: string, mimeType: string): void;
|
|
67
|
-
/** Get current connection status */
|
|
68
|
-
get status(): RealtimeStatus;
|
|
69
|
-
/** Get current mode */
|
|
70
|
-
get mode(): RealtimeMode;
|
|
71
|
-
/** Get conversation messages */
|
|
72
|
-
get messages(): Array<RealtimeMessage>;
|
|
73
|
-
/** Get current error, if any */
|
|
74
|
-
get error(): Error | null;
|
|
75
|
-
/** Get pending user transcript (while user is speaking) */
|
|
76
|
-
get pendingUserTranscript(): string | null;
|
|
77
|
-
/** Get pending assistant transcript (while assistant is speaking) */
|
|
78
|
-
get pendingAssistantTranscript(): string | null;
|
|
79
|
-
/** Get audio visualization data */
|
|
80
|
-
get audio(): AudioVisualization | null;
|
|
81
|
-
/**
|
|
82
|
-
* Subscribe to state changes.
|
|
83
|
-
* @returns Unsubscribe function
|
|
84
|
-
*/
|
|
85
|
-
onStateChange(callback: RealtimeStateChangeCallback): () => void;
|
|
86
|
-
/**
|
|
87
|
-
* Clean up resources.
|
|
88
|
-
* Call this when disposing of the client.
|
|
89
|
-
*/
|
|
90
|
-
destroy(): void;
|
|
91
|
-
private updateState;
|
|
92
|
-
private addMessage;
|
|
93
|
-
private scheduleTokenRefresh;
|
|
94
|
-
private refreshToken;
|
|
95
|
-
private subscribeToConnectionEvents;
|
|
96
|
-
private applySessionConfig;
|
|
97
|
-
private generateId;
|
|
98
|
-
}
|