@tanstack/ai-svelte 0.6.2 → 0.6.4

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.
@@ -0,0 +1,120 @@
1
+ import { createGeneration } from './create-generation.svelte'
2
+ import type { StreamChunk, TTSResult } from '@tanstack/ai'
3
+ import type {
4
+ ConnectionAdapter,
5
+ GenerationClientState,
6
+ GenerationFetcher,
7
+ InferGenerationOutput,
8
+ SpeechGenerateInput,
9
+ } from '@tanstack/ai-client'
10
+
11
+ /**
12
+ * Options for the createGenerateSpeech function.
13
+ *
14
+ * @template TOutput - The output type after optional transform (defaults to TTSResult)
15
+ */
16
+ export interface CreateGenerateSpeechOptions<TOutput = TTSResult> {
17
+ /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */
18
+ connection?: ConnectionAdapter
19
+ /** Direct async function for speech generation */
20
+ fetcher?: GenerationFetcher<SpeechGenerateInput, TTSResult>
21
+ /** Unique identifier for this generation instance */
22
+ id?: string
23
+ /** Additional body parameters to send with ConnectionAdapter requests */
24
+ body?: Record<string, any>
25
+ /**
26
+ * Callback when speech is generated. Can optionally return a transformed value.
27
+ *
28
+ * - Return a non-null value to transform and store it as the result
29
+ * - Return `null` to keep the previous result unchanged
30
+ * - Return nothing (`void`) to store the raw result as-is
31
+ */
32
+ onResult?: (result: TTSResult) => TOutput | null | void
33
+ /** Callback when an error occurs */
34
+ onError?: (error: Error) => void
35
+ /** Callback when progress is reported (0-100) */
36
+ onProgress?: (progress: number, message?: string) => void
37
+ /** Callback for each stream chunk (ConnectionAdapter mode only) */
38
+ onChunk?: (chunk: StreamChunk) => void
39
+ }
40
+
41
+ /**
42
+ * Return type for the createGenerateSpeech function.
43
+ *
44
+ * @template TOutput - The output type (after optional transform)
45
+ */
46
+ export interface CreateGenerateSpeechReturn<TOutput = TTSResult> {
47
+ /** The TTS result containing audio data, or null */
48
+ readonly result: TOutput | null
49
+ /** Whether generation is in progress */
50
+ readonly isLoading: boolean
51
+ /** Current error, if any */
52
+ readonly error: Error | undefined
53
+ /** Current state of the generation */
54
+ readonly status: GenerationClientState
55
+ /** Trigger speech generation */
56
+ generate: (input: SpeechGenerateInput) => Promise<void>
57
+ /** Abort the current generation */
58
+ stop: () => void
59
+ /** Clear result, error, and return to idle */
60
+ reset: () => void
61
+ /** Update additional body parameters */
62
+ updateBody: (body: Record<string, any>) => void
63
+ }
64
+
65
+ /**
66
+ * Creates a reactive speech generation (text-to-speech) instance for Svelte 5.
67
+ *
68
+ * @example
69
+ * ```svelte
70
+ * <script>
71
+ * import { createGenerateSpeech, fetchServerSentEvents } from '@tanstack/ai-svelte'
72
+ *
73
+ * const speech = createGenerateSpeech({
74
+ * connection: fetchServerSentEvents('/api/generate/speech'),
75
+ * })
76
+ * </script>
77
+ *
78
+ * <div>
79
+ * <button onclick={() => speech.generate({ text: 'Hello world', voice: 'alloy' })}>
80
+ * Generate Speech
81
+ * </button>
82
+ * {#if speech.isLoading}
83
+ * <p>Generating...</p>
84
+ * {/if}
85
+ * {#if speech.result}
86
+ * <audio src={`data:audio/${speech.result.format};base64,${speech.result.audio}`} controls></audio>
87
+ * {/if}
88
+ * </div>
89
+ * ```
90
+ */
91
+ export function createGenerateSpeech<
92
+ TOnResult extends ((result: TTSResult) => any) | undefined = undefined,
93
+ >(
94
+ options: Omit<CreateGenerateSpeechOptions, 'onResult'> & {
95
+ onResult?: TOnResult
96
+ },
97
+ ): CreateGenerateSpeechReturn<InferGenerationOutput<TTSResult, TOnResult>> {
98
+ const gen = createGeneration<SpeechGenerateInput, TTSResult, TOnResult>(
99
+ options,
100
+ )
101
+
102
+ return {
103
+ get result() {
104
+ return gen.result
105
+ },
106
+ get isLoading() {
107
+ return gen.isLoading
108
+ },
109
+ get error() {
110
+ return gen.error
111
+ },
112
+ get status() {
113
+ return gen.status
114
+ },
115
+ generate: gen.generate as (input: SpeechGenerateInput) => Promise<void>,
116
+ stop: gen.stop,
117
+ reset: gen.reset,
118
+ updateBody: gen.updateBody,
119
+ }
120
+ }
@@ -0,0 +1,220 @@
1
+ import { VideoGenerationClient } from '@tanstack/ai-client'
2
+ import type { StreamChunk } from '@tanstack/ai'
3
+ import type {
4
+ ConnectionAdapter,
5
+ GenerationClientState,
6
+ GenerationFetcher,
7
+ InferGenerationOutput,
8
+ VideoGenerateInput,
9
+ VideoGenerateResult,
10
+ VideoStatusInfo,
11
+ } from '@tanstack/ai-client'
12
+
13
+ /**
14
+ * Options for the createGenerateVideo function.
15
+ *
16
+ * @template TOutput - The output type after optional transform (defaults to VideoGenerateResult)
17
+ */
18
+ export interface CreateGenerateVideoOptions<TOutput = VideoGenerateResult> {
19
+ /** Connection adapter for streaming transport (server handles polling) */
20
+ connection?: ConnectionAdapter
21
+ /** Direct async function that returns a completed video result */
22
+ fetcher?: GenerationFetcher<VideoGenerateInput, VideoGenerateResult>
23
+ /** Unique identifier for this generation instance */
24
+ id?: string
25
+ /** Additional body parameters to send with ConnectionAdapter requests */
26
+ body?: Record<string, any>
27
+ /**
28
+ * Callback when video generation completes. Can optionally return a transformed value.
29
+ *
30
+ * - Return a non-null value to transform and store it as the result
31
+ * - Return `null` to keep the previous result unchanged
32
+ * - Return nothing (`void`) to store the raw result as-is
33
+ */
34
+ onResult?: (result: VideoGenerateResult) => TOutput | null | void
35
+ /** Callback when an error occurs */
36
+ onError?: (error: Error) => void
37
+ /** Callback when progress is reported (0-100) */
38
+ onProgress?: (progress: number, message?: string) => void
39
+ /** Callback when a video job is created */
40
+ onJobCreated?: (jobId: string) => void
41
+ /** Callback on each status update */
42
+ onStatusUpdate?: (status: VideoStatusInfo) => void
43
+ /** Callback for each stream chunk (ConnectionAdapter mode only) */
44
+ onChunk?: (chunk: StreamChunk) => void
45
+ }
46
+
47
+ /**
48
+ * Return type for the createGenerateVideo function.
49
+ *
50
+ * @template TOutput - The output type (after optional transform)
51
+ */
52
+ export interface CreateGenerateVideoReturn<TOutput = VideoGenerateResult> {
53
+ /** The final video result (with URL), or null */
54
+ readonly result: TOutput | null
55
+ /** The current job ID, or null */
56
+ readonly jobId: string | null
57
+ /** Current video generation status info, or null */
58
+ readonly videoStatus: VideoStatusInfo | null
59
+ /** Whether generation/polling is in progress */
60
+ readonly isLoading: boolean
61
+ /** Current error, if any */
62
+ readonly error: Error | undefined
63
+ /** Current state of the generation */
64
+ readonly status: GenerationClientState
65
+ /** Trigger video generation */
66
+ generate: (input: VideoGenerateInput) => Promise<void>
67
+ /** Abort the current generation/polling */
68
+ stop: () => void
69
+ /** Clear all state and return to idle */
70
+ reset: () => void
71
+ /** Update additional body parameters */
72
+ updateBody: (body: Record<string, any>) => void
73
+ }
74
+
75
+ /**
76
+ * Creates a reactive video generation instance for Svelte 5.
77
+ *
78
+ * Video generation is asynchronous: a job is created, then polled for status
79
+ * until completion. This function handles the full lifecycle.
80
+ *
81
+ * @example
82
+ * ```svelte
83
+ * <script>
84
+ * import { createGenerateVideo, fetchServerSentEvents } from '@tanstack/ai-svelte'
85
+ *
86
+ * const video = createGenerateVideo({
87
+ * connection: fetchServerSentEvents('/api/generate/video'),
88
+ * onStatusUpdate: (status) => console.log(`Progress: ${status.progress}%`),
89
+ * })
90
+ * </script>
91
+ *
92
+ * <div>
93
+ * <button onclick={() => video.generate({ prompt: 'A flying car over a city' })}>
94
+ * Generate Video
95
+ * </button>
96
+ * {#if video.isLoading && video.videoStatus}
97
+ * <p>Status: {video.videoStatus.status} ({video.videoStatus.progress}%)</p>
98
+ * {/if}
99
+ * {#if video.result}
100
+ * <video src={video.result.url} controls></video>
101
+ * {/if}
102
+ * </div>
103
+ * ```
104
+ */
105
+ export function createGenerateVideo<
106
+ TOnResult extends ((result: VideoGenerateResult) => any) | undefined =
107
+ undefined,
108
+ >(
109
+ options: Omit<CreateGenerateVideoOptions, 'onResult'> & {
110
+ onResult?: TOnResult
111
+ },
112
+ ): CreateGenerateVideoReturn<
113
+ InferGenerationOutput<VideoGenerateResult, TOnResult>
114
+ > {
115
+ type TOutput = InferGenerationOutput<VideoGenerateResult, TOnResult>
116
+ const clientId =
117
+ options.id ||
118
+ `video-${Date.now()}-${Math.random().toString(36).substring(7)}`
119
+
120
+ // Create reactive state using Svelte 5 runes
121
+ let result = $state<TOutput | null>(null)
122
+ let jobId = $state<string | null>(null)
123
+ let videoStatus = $state<VideoStatusInfo | null>(null)
124
+ let isLoading = $state(false)
125
+ let error = $state<Error | undefined>(undefined)
126
+ let status = $state<GenerationClientState>('idle')
127
+
128
+ const baseOptions = {
129
+ id: clientId,
130
+ body: options.body,
131
+ onResult: (r: VideoGenerateResult) => options.onResult?.(r),
132
+ onError: (e: Error) => options.onError?.(e),
133
+ onProgress: (p: number, m?: string) => options.onProgress?.(p, m),
134
+ onChunk: (c: StreamChunk) => options.onChunk?.(c),
135
+ onJobCreated: (id: string) => options.onJobCreated?.(id),
136
+ onStatusUpdate: (s: VideoStatusInfo) => options.onStatusUpdate?.(s),
137
+ onResultChange: (r: TOutput | null) => {
138
+ result = r
139
+ },
140
+ onLoadingChange: (l: boolean) => {
141
+ isLoading = l
142
+ },
143
+ onErrorChange: (e: Error | undefined) => {
144
+ error = e
145
+ },
146
+ onStatusChange: (s: GenerationClientState) => {
147
+ status = s
148
+ },
149
+ onJobIdChange: (id: string | null) => {
150
+ jobId = id
151
+ },
152
+ onVideoStatusChange: (s: VideoStatusInfo | null) => {
153
+ videoStatus = s
154
+ },
155
+ }
156
+
157
+ let client: VideoGenerationClient<TOutput>
158
+
159
+ if (options.connection) {
160
+ client = new VideoGenerationClient<TOutput>({
161
+ ...baseOptions,
162
+ connection: options.connection,
163
+ })
164
+ } else if (options.fetcher) {
165
+ client = new VideoGenerationClient<TOutput>({
166
+ ...baseOptions,
167
+ fetcher: options.fetcher,
168
+ })
169
+ } else {
170
+ throw new Error(
171
+ 'createGenerateVideo requires either a connection or fetcher option',
172
+ )
173
+ }
174
+
175
+ // Note: Cleanup is handled by calling stop() directly when needed.
176
+ // Unlike React/Vue/Solid, Svelte 5 runes like $effect can only be used
177
+ // during component initialization, so we don't add automatic cleanup here.
178
+ // Users should call video.stop() in their component's cleanup if needed.
179
+
180
+ const generate = async (input: VideoGenerateInput) => {
181
+ await client.generate(input)
182
+ }
183
+
184
+ const stop = () => {
185
+ client.stop()
186
+ }
187
+
188
+ const reset = () => {
189
+ client.reset()
190
+ }
191
+
192
+ const updateBody = (newBody: Record<string, any>) => {
193
+ client.updateOptions({ body: newBody })
194
+ }
195
+
196
+ return {
197
+ get result() {
198
+ return result
199
+ },
200
+ get jobId() {
201
+ return jobId
202
+ },
203
+ get videoStatus() {
204
+ return videoStatus
205
+ },
206
+ get isLoading() {
207
+ return isLoading
208
+ },
209
+ get error() {
210
+ return error
211
+ },
212
+ get status() {
213
+ return status
214
+ },
215
+ generate,
216
+ stop,
217
+ reset,
218
+ updateBody,
219
+ }
220
+ }
@@ -0,0 +1,197 @@
1
+ import { GenerationClient } from '@tanstack/ai-client'
2
+ import type { StreamChunk } from '@tanstack/ai'
3
+ import type {
4
+ ConnectionAdapter,
5
+ GenerationClientOptions,
6
+ GenerationClientState,
7
+ GenerationFetcher,
8
+ InferGenerationOutput,
9
+ } from '@tanstack/ai-client'
10
+
11
+ /**
12
+ * Options for the createGeneration function.
13
+ *
14
+ * Accepts either a `connection` (streaming transport) or a `fetcher` (direct async call).
15
+ *
16
+ * @template TInput - The input type for the generation request
17
+ * @template TResult - The result type returned by the generation
18
+ * @template TOutput - The output type after optional transform (defaults to TResult)
19
+ */
20
+ export interface CreateGenerationOptions<TInput, TResult, TOutput = TResult> {
21
+ /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */
22
+ connection?: ConnectionAdapter
23
+ /** Direct async function for one-shot generation (no streaming protocol needed) */
24
+ fetcher?: GenerationFetcher<TInput, TResult>
25
+ /** Unique identifier for this generation instance */
26
+ id?: string
27
+ /** Additional body parameters to send with ConnectionAdapter requests */
28
+ body?: Record<string, any>
29
+ /**
30
+ * Callback when a result is received. Can optionally return a transformed value.
31
+ *
32
+ * - Return a non-null value to transform and store it as the result
33
+ * - Return `null` to keep the previous result unchanged
34
+ * - Return nothing (`void`) to store the raw result as-is
35
+ */
36
+ onResult?: (result: TResult) => TOutput | null | void
37
+ /** Callback when an error occurs */
38
+ onError?: (error: Error) => void
39
+ /** Callback when progress is reported (0-100) */
40
+ onProgress?: (progress: number, message?: string) => void
41
+ /** Callback for each stream chunk (ConnectionAdapter mode only) */
42
+ onChunk?: (chunk: StreamChunk) => void
43
+ }
44
+
45
+ /**
46
+ * Return type for the createGeneration function.
47
+ *
48
+ * @template TOutput - The output type (after optional transform)
49
+ */
50
+ export interface CreateGenerationReturn<TOutput> {
51
+ /** The generation result, or null if not yet generated */
52
+ readonly result: TOutput | null
53
+ /** Whether a generation is currently in progress */
54
+ readonly isLoading: boolean
55
+ /** Current error, if any */
56
+ readonly error: Error | undefined
57
+ /** Current state of the generation client */
58
+ readonly status: GenerationClientState
59
+ /** Trigger a generation request */
60
+ generate: (input: Record<string, any>) => Promise<void>
61
+ /** Abort the current generation */
62
+ stop: () => void
63
+ /** Clear result, error, and return to idle */
64
+ reset: () => void
65
+ /** Update additional body parameters */
66
+ updateBody: (body: Record<string, any>) => void
67
+ }
68
+
69
+ /**
70
+ * Creates a reactive generation instance for Svelte 5.
71
+ *
72
+ * This is the base function used by `createGenerateImage`, `createGenerateSpeech`,
73
+ * `createTranscription`, and `createSummarize`. You can also use it directly
74
+ * for custom generation types.
75
+ *
76
+ * @template TInput - The input type for the generation request
77
+ * @template TResult - The result type returned by the generation
78
+ *
79
+ * @example
80
+ * ```svelte
81
+ * <script>
82
+ * import { createGeneration, fetchServerSentEvents } from '@tanstack/ai-svelte'
83
+ *
84
+ * const gen = createGeneration({
85
+ * connection: fetchServerSentEvents('/api/generate/custom'),
86
+ * })
87
+ * </script>
88
+ *
89
+ * <div>
90
+ * <button onclick={() => gen.generate({ prompt: 'Hello' })}>Generate</button>
91
+ * {#if gen.isLoading}
92
+ * <p>Generating...</p>
93
+ * {/if}
94
+ * {#if gen.result}
95
+ * <p>{JSON.stringify(gen.result)}</p>
96
+ * {/if}
97
+ * </div>
98
+ * ```
99
+ */
100
+ export function createGeneration<
101
+ TInput extends Record<string, any>,
102
+ TResult,
103
+ TOnResult extends ((result: TResult) => any) | undefined = undefined,
104
+ >(
105
+ options: Omit<CreateGenerationOptions<TInput, TResult>, 'onResult'> & {
106
+ onResult?: TOnResult
107
+ },
108
+ ): CreateGenerationReturn<InferGenerationOutput<TResult, TOnResult>> {
109
+ type TOutput = InferGenerationOutput<TResult, TOnResult>
110
+ const clientId =
111
+ options.id || `gen-${Date.now()}-${Math.random().toString(36).substring(7)}`
112
+
113
+ // Create reactive state using Svelte 5 runes
114
+ let result = $state<TOutput | null>(null)
115
+ let isLoading = $state(false)
116
+ let error = $state<Error | undefined>(undefined)
117
+ let status = $state<GenerationClientState>('idle')
118
+
119
+ const clientOptions: GenerationClientOptions<TInput, TResult, TOutput> = {
120
+ id: clientId,
121
+ body: options.body,
122
+ onResult: (r: TResult) => options.onResult?.(r),
123
+ onError: (e: Error) => options.onError?.(e),
124
+ onProgress: (p: number, m?: string) => options.onProgress?.(p, m),
125
+ onChunk: (c: StreamChunk) => options.onChunk?.(c),
126
+ onResultChange: (r: TOutput | null) => {
127
+ result = r
128
+ },
129
+ onLoadingChange: (l: boolean) => {
130
+ isLoading = l
131
+ },
132
+ onErrorChange: (e: Error | undefined) => {
133
+ error = e
134
+ },
135
+ onStatusChange: (s: GenerationClientState) => {
136
+ status = s
137
+ },
138
+ }
139
+
140
+ let client: GenerationClient<TInput, TResult, TOutput>
141
+
142
+ if (options.connection) {
143
+ client = new GenerationClient<TInput, TResult, TOutput>({
144
+ ...clientOptions,
145
+ connection: options.connection,
146
+ })
147
+ } else if (options.fetcher) {
148
+ client = new GenerationClient<TInput, TResult, TOutput>({
149
+ ...clientOptions,
150
+ fetcher: options.fetcher,
151
+ })
152
+ } else {
153
+ throw new Error(
154
+ 'createGeneration requires either a connection or fetcher option',
155
+ )
156
+ }
157
+
158
+ // Note: Cleanup is handled by calling stop() directly when needed.
159
+ // Unlike React/Vue/Solid, Svelte 5 runes like $effect can only be used
160
+ // during component initialization, so we don't add automatic cleanup here.
161
+ // Users should call gen.stop() in their component's cleanup if needed.
162
+
163
+ const generate = async (input: TInput) => {
164
+ await client.generate(input)
165
+ }
166
+
167
+ const stop = () => {
168
+ client.stop()
169
+ }
170
+
171
+ const reset = () => {
172
+ client.reset()
173
+ }
174
+
175
+ const updateBody = (newBody: Record<string, any>) => {
176
+ client.updateOptions({ body: newBody })
177
+ }
178
+
179
+ return {
180
+ get result() {
181
+ return result
182
+ },
183
+ get isLoading() {
184
+ return isLoading
185
+ },
186
+ get error() {
187
+ return error
188
+ },
189
+ get status() {
190
+ return status
191
+ },
192
+ generate: generate as (input: Record<string, any>) => Promise<void>,
193
+ stop,
194
+ reset,
195
+ updateBody,
196
+ }
197
+ }
@@ -0,0 +1,129 @@
1
+ import { createGeneration } from './create-generation.svelte'
2
+ import type { StreamChunk, SummarizationResult } from '@tanstack/ai'
3
+ import type {
4
+ ConnectionAdapter,
5
+ GenerationClientState,
6
+ GenerationFetcher,
7
+ InferGenerationOutput,
8
+ SummarizeGenerateInput,
9
+ } from '@tanstack/ai-client'
10
+
11
+ /**
12
+ * Options for the createSummarize function.
13
+ *
14
+ * @template TOutput - The output type after optional transform (defaults to SummarizationResult)
15
+ */
16
+ export interface CreateSummarizeOptions<TOutput = SummarizationResult> {
17
+ /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */
18
+ connection?: ConnectionAdapter
19
+ /** Direct async function for summarization */
20
+ fetcher?: GenerationFetcher<SummarizeGenerateInput, SummarizationResult>
21
+ /** Unique identifier for this generation instance */
22
+ id?: string
23
+ /** Additional body parameters to send with ConnectionAdapter requests */
24
+ body?: Record<string, any>
25
+ /**
26
+ * Callback when summarization is complete. Can optionally return a transformed value.
27
+ *
28
+ * - Return a non-null value to transform and store it as the result
29
+ * - Return `null` to keep the previous result unchanged
30
+ * - Return nothing (`void`) to store the raw result as-is
31
+ */
32
+ onResult?: (result: SummarizationResult) => TOutput | null | void
33
+ /** Callback when an error occurs */
34
+ onError?: (error: Error) => void
35
+ /** Callback when progress is reported (0-100) */
36
+ onProgress?: (progress: number, message?: string) => void
37
+ /** Callback for each stream chunk (ConnectionAdapter mode only) */
38
+ onChunk?: (chunk: StreamChunk) => void
39
+ }
40
+
41
+ /**
42
+ * Return type for the createSummarize function.
43
+ *
44
+ * @template TOutput - The output type (after optional transform)
45
+ */
46
+ export interface CreateSummarizeReturn<TOutput = SummarizationResult> {
47
+ /** The summarization result, or null */
48
+ readonly result: TOutput | null
49
+ /** Whether summarization is in progress */
50
+ readonly isLoading: boolean
51
+ /** Current error, if any */
52
+ readonly error: Error | undefined
53
+ /** Current state of the generation */
54
+ readonly status: GenerationClientState
55
+ /** Trigger summarization */
56
+ generate: (input: SummarizeGenerateInput) => Promise<void>
57
+ /** Abort the current summarization */
58
+ stop: () => void
59
+ /** Clear result, error, and return to idle */
60
+ reset: () => void
61
+ /** Update additional body parameters */
62
+ updateBody: (body: Record<string, any>) => void
63
+ }
64
+
65
+ /**
66
+ * Creates a reactive text summarization instance for Svelte 5.
67
+ *
68
+ * @example
69
+ * ```svelte
70
+ * <script>
71
+ * import { createSummarize, fetchServerSentEvents } from '@tanstack/ai-svelte'
72
+ *
73
+ * const summarizer = createSummarize({
74
+ * connection: fetchServerSentEvents('/api/summarize'),
75
+ * })
76
+ * </script>
77
+ *
78
+ * <div>
79
+ * <button onclick={() => summarizer.generate({
80
+ * text: 'Long article text...',
81
+ * style: 'bullet-points',
82
+ * maxLength: 200,
83
+ * })}>
84
+ * Summarize
85
+ * </button>
86
+ * {#if summarizer.isLoading}
87
+ * <p>Summarizing...</p>
88
+ * {/if}
89
+ * {#if summarizer.result}
90
+ * <p>{summarizer.result.summary}</p>
91
+ * {/if}
92
+ * </div>
93
+ * ```
94
+ */
95
+ export function createSummarize<
96
+ TOnResult extends ((result: SummarizationResult) => any) | undefined =
97
+ undefined,
98
+ >(
99
+ options: Omit<CreateSummarizeOptions, 'onResult'> & {
100
+ onResult?: TOnResult
101
+ },
102
+ ): CreateSummarizeReturn<
103
+ InferGenerationOutput<SummarizationResult, TOnResult>
104
+ > {
105
+ const gen = createGeneration<
106
+ SummarizeGenerateInput,
107
+ SummarizationResult,
108
+ TOnResult
109
+ >(options)
110
+
111
+ return {
112
+ get result() {
113
+ return gen.result
114
+ },
115
+ get isLoading() {
116
+ return gen.isLoading
117
+ },
118
+ get error() {
119
+ return gen.error
120
+ },
121
+ get status() {
122
+ return gen.status
123
+ },
124
+ generate: gen.generate as (input: SummarizeGenerateInput) => Promise<void>,
125
+ stop: gen.stop,
126
+ reset: gen.reset,
127
+ updateBody: gen.updateBody,
128
+ }
129
+ }