@tanstack/ai-octane 0.0.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.
@@ -0,0 +1,60 @@
1
+ import { useMemo, useRef } from 'octane'
2
+ import { createMcpAppBridge } from '@tanstack/ai-client'
3
+ import type {
4
+ CreateMcpAppBridgeOptions,
5
+ McpAppBridge,
6
+ } from '@tanstack/ai-client'
7
+
8
+ export type UseMcpAppBridgeOptions = CreateMcpAppBridgeOptions
9
+
10
+ /**
11
+ * Octane wrapper around `createMcpAppBridge` that returns a **stable** bridge for
12
+ * the given `threadId`/`callEndpoint`, while always invoking the latest
13
+ * `chat.sendMessage` and `onLink` (kept in refs). This avoids both recreating
14
+ * the bridge on every render and the stale-closure / `exhaustive-deps` dance
15
+ * you'd otherwise write by hand:
16
+ *
17
+ * ```tsx
18
+ * const { sendMessage } = useChat({ threadId, connection })
19
+ * const bridge = useMcpAppBridge({
20
+ * threadId,
21
+ * callEndpoint: '/api/mcp-apps-call',
22
+ * chat: { sendMessage: async (content) => void sendMessage(content) },
23
+ * onLink: (url) => window.open(url, '_blank', 'noopener,noreferrer'),
24
+ * })
25
+ * // pass `bridge` to <MCPAppResource bridge={bridge} … />
26
+ * ```
27
+ *
28
+ * The bridge is recreated only when `threadId`, `callEndpoint`, `fetchImpl`, or
29
+ * the *presence* of `onLink` changes — passing a new inline `onLink`/`sendMessage`
30
+ * each render does not churn it.
31
+ */
32
+ export function useMcpAppBridge(options: UseMcpAppBridgeOptions): McpAppBridge {
33
+ const { threadId, callEndpoint, chat, fetchImpl, onLink } = options
34
+
35
+ // Latest-value refs so the bridge identity stays stable but its callbacks are
36
+ // never stale (the bridge calls `.current` at invocation time, not creation).
37
+ const chatRef = useRef(chat)
38
+ chatRef.current = chat
39
+ const onLinkRef = useRef(onLink)
40
+ onLinkRef.current = onLink
41
+
42
+ // Whether a link handler was supplied governs the bridge's link behavior
43
+ // (forward vs. display-only warn), so it's part of the bridge's identity.
44
+ const hasOnLink = onLink != null
45
+
46
+ return useMemo(
47
+ () =>
48
+ createMcpAppBridge({
49
+ threadId,
50
+ callEndpoint,
51
+ fetchImpl,
52
+ chat: {
53
+ sendMessage: (content, body) =>
54
+ chatRef.current.sendMessage(content, body),
55
+ },
56
+ onLink: hasOnLink ? (url) => onLinkRef.current?.(url) : undefined,
57
+ }),
58
+ [threadId, callEndpoint, fetchImpl, hasOnLink],
59
+ )
60
+ }
@@ -0,0 +1,31 @@
1
+ // Declaration companion generated from use-mcp-app-bridge.tsrx.
2
+ import type {
3
+ CreateMcpAppBridgeOptions,
4
+ McpAppBridge,
5
+ } from '@tanstack/ai-client'
6
+ export type UseMcpAppBridgeOptions = CreateMcpAppBridgeOptions
7
+ /**
8
+ * Octane wrapper around `createMcpAppBridge` that returns a **stable** bridge for
9
+ * the given `threadId`/`callEndpoint`, while always invoking the latest
10
+ * `chat.sendMessage` and `onLink` (kept in refs). This avoids both recreating
11
+ * the bridge on every render and the stale-closure / `exhaustive-deps` dance
12
+ * you'd otherwise write by hand:
13
+ *
14
+ * ```tsx
15
+ * const { sendMessage } = useChat({ threadId, connection })
16
+ * const bridge = useMcpAppBridge({
17
+ * threadId,
18
+ * callEndpoint: '/api/mcp-apps-call',
19
+ * chat: { sendMessage: async (content) => void sendMessage(content) },
20
+ * onLink: (url) => window.open(url, '_blank', 'noopener,noreferrer'),
21
+ * })
22
+ * // pass `bridge` to <MCPAppResource bridge={bridge} … />
23
+ * ```
24
+ *
25
+ * The bridge is recreated only when `threadId`, `callEndpoint`, `fetchImpl`, or
26
+ * the *presence* of `onLink` changes — passing a new inline `onLink`/`sendMessage`
27
+ * each render does not churn it.
28
+ */
29
+ export declare function useMcpAppBridge(
30
+ options: UseMcpAppBridgeOptions,
31
+ ): McpAppBridge
@@ -0,0 +1,307 @@
1
+ import { useCallback, useEffect, useRef, useState } from 'octane'
2
+ import { RealtimeClient } from '@tanstack/ai-client'
3
+ import type {
4
+ RealtimeMessage,
5
+ RealtimeMode,
6
+ RealtimeSessionConfig,
7
+ RealtimeStatus,
8
+ } from '@tanstack/ai'
9
+ import type {
10
+ UseRealtimeChatOptions,
11
+ UseRealtimeChatReturn,
12
+ } from './realtime-types'
13
+
14
+ // Empty frequency data for when client is not connected
15
+ const emptyFrequencyData = new Uint8Array(128)
16
+ const emptyTimeDomainData = new Uint8Array(128).fill(128)
17
+
18
+ /**
19
+ * Octane hook for realtime voice conversations.
20
+ *
21
+ * Provides a simple interface for voice-to-voice AI interactions
22
+ * with support for multiple providers (OpenAI, ElevenLabs, etc.).
23
+ *
24
+ * @param options - Configuration options including adapter and callbacks
25
+ * @returns Hook return value with state and control methods
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * import { useRealtimeChat } from '@tanstack/ai-octane'
30
+ * import { openaiRealtime } from '@tanstack/ai-openai'
31
+ *
32
+ * function VoiceChat() {
33
+ * const {
34
+ * status,
35
+ * mode,
36
+ * messages,
37
+ * connect,
38
+ * disconnect,
39
+ * inputLevel,
40
+ * outputLevel,
41
+ * } = useRealtimeChat({
42
+ * getToken: () => fetch('/api/realtime-token').then(r => r.json()),
43
+ * adapter: openaiRealtime(),
44
+ * })
45
+ *
46
+ * return (
47
+ * <div>
48
+ * <p>Status: {status}</p>
49
+ * <p>Mode: {mode}</p>
50
+ * <button onClick={status === 'idle' ? connect : disconnect}>
51
+ * {status === 'idle' ? 'Start' : 'Stop'}
52
+ * </button>
53
+ * </div>
54
+ * )
55
+ * }
56
+ * ```
57
+ */
58
+ export function useRealtimeChat(
59
+ options: UseRealtimeChatOptions,
60
+ ): UseRealtimeChatReturn {
61
+ // State
62
+ const [status, setStatus] = useState<RealtimeStatus>('idle')
63
+ const [mode, setMode] = useState<RealtimeMode>('idle')
64
+ const [messages, setMessages] = useState<Array<RealtimeMessage>>([])
65
+ const [pendingUserTranscript, setPendingUserTranscript] = useState<
66
+ string | null
67
+ >(null)
68
+ const [pendingAssistantTranscript, setPendingAssistantTranscript] = useState<
69
+ string | null
70
+ >(null)
71
+ const [error, setError] = useState<Error | null>(null)
72
+ const [inputLevel, setInputLevel] = useState(0)
73
+ const [outputLevel, setOutputLevel] = useState(0)
74
+
75
+ // Refs
76
+ const clientRef = useRef<RealtimeClient | null>(null)
77
+ const optionsRef = useRef(options)
78
+ optionsRef.current = options
79
+ const animationFrameRef = useRef<number | null>(null)
80
+
81
+ // Create client instance - use ref to ensure we reuse the same instance
82
+ // This handles React StrictMode double-rendering
83
+ if (!clientRef.current) {
84
+ // Each optional source field is spread conditionally because the
85
+ // `RealtimeClientOptions` target declares strict optionals
86
+ // (`field?: T`) and `exactOptionalPropertyTypes` rejects passing
87
+ // `undefined` for absent values.
88
+ const initial = optionsRef.current
89
+ clientRef.current = new RealtimeClient({
90
+ // OCTANE DIVERGENCE: upstream captures the first transport callbacks.
91
+ // Ref-backed delegates keep the client stable while reconnects and token
92
+ // refreshes observe the latest render's authentication and adapter.
93
+ getToken: () => optionsRef.current.getToken(),
94
+ adapter: {
95
+ get provider() {
96
+ return optionsRef.current.adapter.provider
97
+ },
98
+ connect(token, tools) {
99
+ return optionsRef.current.adapter.connect(token, tools)
100
+ },
101
+ },
102
+ ...(initial.tools !== undefined && { tools: initial.tools }),
103
+ ...(initial.instructions !== undefined && {
104
+ instructions: initial.instructions,
105
+ }),
106
+ ...(initial.voice !== undefined && { voice: initial.voice }),
107
+ ...(initial.autoPlayback !== undefined && {
108
+ autoPlayback: initial.autoPlayback,
109
+ }),
110
+ ...(initial.autoCapture !== undefined && {
111
+ autoCapture: initial.autoCapture,
112
+ }),
113
+ ...(initial.vadMode !== undefined && { vadMode: initial.vadMode }),
114
+ ...(initial.outputModalities !== undefined && {
115
+ outputModalities: initial.outputModalities,
116
+ }),
117
+ ...(initial.temperature !== undefined && {
118
+ temperature: initial.temperature,
119
+ }),
120
+ ...(initial.maxOutputTokens !== undefined && {
121
+ maxOutputTokens: initial.maxOutputTokens,
122
+ }),
123
+ ...(initial.semanticEagerness !== undefined && {
124
+ semanticEagerness: initial.semanticEagerness,
125
+ }),
126
+ onStatusChange: (newStatus) => {
127
+ setStatus(newStatus)
128
+ // OCTANE DIVERGENCE: upstream declares this callback but does not
129
+ // forward status changes beyond its own hook state.
130
+ optionsRef.current.onStatusChange?.(newStatus)
131
+ },
132
+ onModeChange: (newMode) => {
133
+ setMode(newMode)
134
+ optionsRef.current.onModeChange?.(newMode)
135
+ },
136
+ onMessage: (message) => {
137
+ setMessages((prev) => [...prev, message])
138
+ optionsRef.current.onMessage?.(message)
139
+ },
140
+ onUsage: (usage) => {
141
+ optionsRef.current.onUsage?.(usage)
142
+ },
143
+ onGoAway: (timeLeft) => {
144
+ optionsRef.current.onGoAway?.(timeLeft)
145
+ },
146
+ onError: (err) => {
147
+ setError(err)
148
+ optionsRef.current.onError?.(err)
149
+ },
150
+ onConnect: () => {
151
+ setError(null)
152
+ optionsRef.current.onConnect?.()
153
+ },
154
+ onDisconnect: () => {
155
+ optionsRef.current.onDisconnect?.()
156
+ },
157
+ onInterrupted: () => {
158
+ setPendingAssistantTranscript(null)
159
+ optionsRef.current.onInterrupted?.()
160
+ },
161
+ })
162
+
163
+ // Subscribe to state changes for transcripts
164
+ clientRef.current.onStateChange((state) => {
165
+ setPendingUserTranscript(state.pendingUserTranscript)
166
+ setPendingAssistantTranscript(state.pendingAssistantTranscript)
167
+ })
168
+ }
169
+
170
+ const client = clientRef.current
171
+
172
+ // Audio level animation loop
173
+ useEffect(() => {
174
+ function updateLevels() {
175
+ if (clientRef.current?.audio) {
176
+ setInputLevel(clientRef.current.audio.inputLevel)
177
+ setOutputLevel(clientRef.current.audio.outputLevel)
178
+ }
179
+ animationFrameRef.current = requestAnimationFrame(updateLevels)
180
+ }
181
+
182
+ if (status === 'connected') {
183
+ updateLevels()
184
+ }
185
+
186
+ return () => {
187
+ if (animationFrameRef.current) {
188
+ cancelAnimationFrame(animationFrameRef.current)
189
+ animationFrameRef.current = null
190
+ }
191
+ }
192
+ }, [status])
193
+
194
+ // Cleanup on unmount
195
+ useEffect(() => {
196
+ return () => {
197
+ clientRef.current?.destroy()
198
+ }
199
+ }, [])
200
+
201
+ // Connection methods
202
+ const connect = useCallback(async () => {
203
+ setError(null)
204
+ setMessages([])
205
+ setPendingUserTranscript(null)
206
+ setPendingAssistantTranscript(null)
207
+ await client.connect()
208
+ }, [client])
209
+
210
+ const disconnect = useCallback(async () => {
211
+ await client.disconnect()
212
+ }, [client])
213
+
214
+ // Voice control methods
215
+ const startListening = useCallback(() => {
216
+ client.startListening()
217
+ }, [client])
218
+
219
+ const stopListening = useCallback(() => {
220
+ client.stopListening()
221
+ }, [client])
222
+
223
+ const interrupt = useCallback(() => {
224
+ client.interrupt()
225
+ }, [client])
226
+
227
+ // Text input
228
+ const sendText = useCallback(
229
+ (text: string) => {
230
+ client.sendText(text)
231
+ },
232
+ [client],
233
+ )
234
+
235
+ // Image input
236
+ const sendImage = useCallback(
237
+ (imageData: string, mimeType: string) => {
238
+ client.sendImage(imageData, mimeType)
239
+ },
240
+ [client],
241
+ )
242
+
243
+ // Audio visualization
244
+ const getInputFrequencyData = useCallback(() => {
245
+ return (
246
+ clientRef.current?.audio?.getInputFrequencyData() ?? emptyFrequencyData
247
+ )
248
+ }, [])
249
+
250
+ const getOutputFrequencyData = useCallback(() => {
251
+ return (
252
+ clientRef.current?.audio?.getOutputFrequencyData() ?? emptyFrequencyData
253
+ )
254
+ }, [])
255
+
256
+ const getInputTimeDomainData = useCallback(() => {
257
+ return (
258
+ clientRef.current?.audio?.getInputTimeDomainData() ?? emptyTimeDomainData
259
+ )
260
+ }, [])
261
+
262
+ const getOutputTimeDomainData = useCallback(() => {
263
+ return (
264
+ clientRef.current?.audio?.getOutputTimeDomainData() ?? emptyTimeDomainData
265
+ )
266
+ }, [])
267
+
268
+ const updateSession = useCallback((config: RealtimeSessionConfig) => {
269
+ clientRef.current?.updateSession(config)
270
+ }, [])
271
+
272
+ return {
273
+ // Connection state
274
+ status,
275
+ error,
276
+ connect,
277
+ disconnect,
278
+
279
+ // Conversation state
280
+ mode,
281
+ messages,
282
+ pendingUserTranscript,
283
+ pendingAssistantTranscript,
284
+
285
+ // Voice control
286
+ startListening,
287
+ stopListening,
288
+ interrupt,
289
+
290
+ // Text input
291
+ sendText,
292
+
293
+ // Image input
294
+ sendImage,
295
+
296
+ // Audio visualization
297
+ inputLevel,
298
+ outputLevel,
299
+ getInputFrequencyData,
300
+ getOutputFrequencyData,
301
+ getInputTimeDomainData,
302
+ getOutputTimeDomainData,
303
+
304
+ // Session control
305
+ updateSession,
306
+ }
307
+ }
@@ -0,0 +1,48 @@
1
+ // Declaration companion generated from use-realtime-chat.tsrx.
2
+ import type {
3
+ UseRealtimeChatOptions,
4
+ UseRealtimeChatReturn,
5
+ } from './realtime-types'
6
+ /**
7
+ * Octane hook for realtime voice conversations.
8
+ *
9
+ * Provides a simple interface for voice-to-voice AI interactions
10
+ * with support for multiple providers (OpenAI, ElevenLabs, etc.).
11
+ *
12
+ * @param options - Configuration options including adapter and callbacks
13
+ * @returns Hook return value with state and control methods
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { useRealtimeChat } from '@tanstack/ai-octane'
18
+ * import { openaiRealtime } from '@tanstack/ai-openai'
19
+ *
20
+ * function VoiceChat() {
21
+ * const {
22
+ * status,
23
+ * mode,
24
+ * messages,
25
+ * connect,
26
+ * disconnect,
27
+ * inputLevel,
28
+ * outputLevel,
29
+ * } = useRealtimeChat({
30
+ * getToken: () => fetch('/api/realtime-token').then(r => r.json()),
31
+ * adapter: openaiRealtime(),
32
+ * })
33
+ *
34
+ * return (
35
+ * <div>
36
+ * <p>Status: {status}</p>
37
+ * <p>Mode: {mode}</p>
38
+ * <button onClick={status === 'idle' ? connect : disconnect}>
39
+ * {status === 'idle' ? 'Start' : 'Stop'}
40
+ * </button>
41
+ * </div>
42
+ * )
43
+ * }
44
+ * ```
45
+ */
46
+ export declare function useRealtimeChat(
47
+ options: UseRealtimeChatOptions,
48
+ ): UseRealtimeChatReturn
@@ -0,0 +1,124 @@
1
+ import { useGeneration } from './use-generation.tsrx'
2
+ import type { StreamChunk, SummarizationResult } from '@tanstack/ai'
3
+ import type {
4
+ AIDevtoolsDisplayOptions,
5
+ ConnectConnectionAdapter,
6
+ GenerationClientState,
7
+ GenerationFetcher,
8
+ InferGenerationOutputFromReturn,
9
+ SummarizeGenerateInput,
10
+ } from '@tanstack/ai-client'
11
+
12
+ /**
13
+ * Options for the useSummarize hook.
14
+ *
15
+ * @template TOutput - The output type after optional transform (defaults to SummarizationResult)
16
+ */
17
+ export interface UseSummarizeOptions<TOutput = SummarizationResult> {
18
+ /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
19
+ connection?: ConnectConnectionAdapter
20
+ /** Direct async function for summarization */
21
+ fetcher?: GenerationFetcher<SummarizeGenerateInput, SummarizationResult>
22
+ /** Unique identifier for this generation instance */
23
+ id?: string
24
+ /** Additional body parameters to send with connect-based adapter requests */
25
+ body?: Record<string, any>
26
+ /** Display options for TanStack AI Devtools. */
27
+ devtools?: AIDevtoolsDisplayOptions
28
+ /**
29
+ * Callback when summarization is complete. Can optionally return a transformed value.
30
+ *
31
+ * - Return a non-null value to transform and store it as the result
32
+ * - Return `null` to keep the previous result unchanged
33
+ * - Return nothing (`void`) to store the raw result as-is
34
+ */
35
+ onResult?: (result: SummarizationResult) => TOutput | null | void
36
+ /** Callback when an error occurs */
37
+ onError?: (error: Error) => void
38
+ /** Callback when progress is reported (0-100) */
39
+ onProgress?: (progress: number, message?: string) => void
40
+ /** Callback for each stream chunk (connect-based adapter mode only) */
41
+ onChunk?: (chunk: StreamChunk) => void
42
+ }
43
+
44
+ /**
45
+ * Return type for the useSummarize hook.
46
+ *
47
+ * @template TOutput - The output type (after optional transform)
48
+ */
49
+ export interface UseSummarizeReturn<TOutput = SummarizationResult> {
50
+ /** Trigger summarization */
51
+ generate: (input: SummarizeGenerateInput) => Promise<void>
52
+ /** The summarization result, or null */
53
+ result: TOutput | null
54
+ /** Whether summarization is in progress */
55
+ isLoading: boolean
56
+ /** Current error, if any */
57
+ error: Error | undefined
58
+ /** Current state of the generation */
59
+ status: GenerationClientState
60
+ /** Abort the current summarization */
61
+ stop: () => void
62
+ /** Clear result, error, and return to idle */
63
+ reset: () => void
64
+ }
65
+
66
+ /**
67
+ * Octane hook for summarizing text using AI models.
68
+ *
69
+ * @example
70
+ * ```tsx
71
+ * import { useSummarize } from '@tanstack/ai-octane'
72
+ * import { fetchServerSentEvents } from '@tanstack/ai-client'
73
+ *
74
+ * function Summarizer() {
75
+ * const { generate, result, isLoading } = useSummarize({
76
+ * connection: fetchServerSentEvents('/api/summarize'),
77
+ * })
78
+ *
79
+ * return (
80
+ * <div>
81
+ * <button onClick={() => generate({
82
+ * text: 'Long article text...',
83
+ * style: 'bullet-points',
84
+ * maxLength: 200,
85
+ * })}>
86
+ * Summarize
87
+ * </button>
88
+ * {isLoading && <p>Summarizing...</p>}
89
+ * {result && <p>{result.summary}</p>}
90
+ * </div>
91
+ * )
92
+ * }
93
+ * ```
94
+ */
95
+ export function useSummarize<TTransformed = void>(
96
+ options: Omit<UseSummarizeOptions, 'onResult'> & {
97
+ onResult?: (result: SummarizationResult) => TTransformed
98
+ },
99
+ ): UseSummarizeReturn<
100
+ InferGenerationOutputFromReturn<SummarizationResult, TTransformed>
101
+ > {
102
+ const devtools = {
103
+ ...options.devtools,
104
+ // OCTANE DIVERGENCE: identify this binding as Octane (not 'react') in TanStack AI Devtools.
105
+ framework: 'octane',
106
+ hookName: 'useSummarize',
107
+ outputKind: 'text' as const,
108
+ }
109
+ const { generate, result, isLoading, error, status, stop, reset } =
110
+ useGeneration<SummarizeGenerateInput, SummarizationResult, TTransformed>({
111
+ ...options,
112
+ devtools,
113
+ })
114
+
115
+ return {
116
+ generate: generate as (input: SummarizeGenerateInput) => Promise<void>,
117
+ result,
118
+ isLoading,
119
+ error,
120
+ status,
121
+ stop,
122
+ reset,
123
+ }
124
+ }
@@ -0,0 +1,98 @@
1
+ // Declaration companion generated from use-summarize.tsrx.
2
+ import type { StreamChunk, SummarizationResult } from '@tanstack/ai'
3
+ import type {
4
+ AIDevtoolsDisplayOptions,
5
+ ConnectConnectionAdapter,
6
+ GenerationClientState,
7
+ GenerationFetcher,
8
+ InferGenerationOutputFromReturn,
9
+ SummarizeGenerateInput,
10
+ } from '@tanstack/ai-client'
11
+ /**
12
+ * Options for the useSummarize hook.
13
+ *
14
+ * @template TOutput - The output type after optional transform (defaults to SummarizationResult)
15
+ */
16
+ export interface UseSummarizeOptions<TOutput = SummarizationResult> {
17
+ /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
18
+ connection?: ConnectConnectionAdapter
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 connect-based adapter requests */
24
+ body?: Record<string, any>
25
+ /** Display options for TanStack AI Devtools. */
26
+ devtools?: AIDevtoolsDisplayOptions
27
+ /**
28
+ * Callback when summarization is complete. 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: SummarizationResult) => 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 for each stream chunk (connect-based adapter mode only) */
40
+ onChunk?: (chunk: StreamChunk) => void
41
+ }
42
+ /**
43
+ * Return type for the useSummarize hook.
44
+ *
45
+ * @template TOutput - The output type (after optional transform)
46
+ */
47
+ export interface UseSummarizeReturn<TOutput = SummarizationResult> {
48
+ /** Trigger summarization */
49
+ generate: (input: SummarizeGenerateInput) => Promise<void>
50
+ /** The summarization result, or null */
51
+ result: TOutput | null
52
+ /** Whether summarization is in progress */
53
+ isLoading: boolean
54
+ /** Current error, if any */
55
+ error: Error | undefined
56
+ /** Current state of the generation */
57
+ status: GenerationClientState
58
+ /** Abort the current summarization */
59
+ stop: () => void
60
+ /** Clear result, error, and return to idle */
61
+ reset: () => void
62
+ }
63
+ /**
64
+ * Octane hook for summarizing text using AI models.
65
+ *
66
+ * @example
67
+ * ```tsx
68
+ * import { useSummarize } from '@tanstack/ai-octane'
69
+ * import { fetchServerSentEvents } from '@tanstack/ai-client'
70
+ *
71
+ * function Summarizer() {
72
+ * const { generate, result, isLoading } = useSummarize({
73
+ * connection: fetchServerSentEvents('/api/summarize'),
74
+ * })
75
+ *
76
+ * return (
77
+ * <div>
78
+ * <button onClick={() => generate({
79
+ * text: 'Long article text...',
80
+ * style: 'bullet-points',
81
+ * maxLength: 200,
82
+ * })}>
83
+ * Summarize
84
+ * </button>
85
+ * {isLoading && <p>Summarizing...</p>}
86
+ * {result && <p>{result.summary}</p>}
87
+ * </div>
88
+ * )
89
+ * }
90
+ * ```
91
+ */
92
+ export declare function useSummarize<TTransformed = void>(
93
+ options: Omit<UseSummarizeOptions, 'onResult'> & {
94
+ onResult?: (result: SummarizationResult) => TTransformed
95
+ },
96
+ ): UseSummarizeReturn<
97
+ InferGenerationOutputFromReturn<SummarizationResult, TTransformed>
98
+ >