@tanstack/ai-remix 0.7.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/ai-remix",
3
- "version": "0.7.1",
3
+ "version": "1.1.0",
4
4
  "description": "Remix 3 bindings for TanStack AI streaming chat, structured outputs, and media generation.",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -47,20 +47,20 @@
47
47
  "README.md"
48
48
  ],
49
49
  "dependencies": {
50
- "@tanstack/ai-client": "^0.40.1"
50
+ "@tanstack/ai-client": "^1.2.0"
51
51
  },
52
52
  "peerDependencies": {
53
53
  "remix": "^3.0.0-rc.1",
54
- "@tanstack/ai": "^0.71.0"
54
+ "@tanstack/ai": "^1.7.0"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@types/node": "^24.10.1",
58
- "@vitest/coverage-v8": "4.1.10",
59
- "happy-dom": "^20.11.2",
58
+ "@vitest/coverage-v8": "4.1.12",
59
+ "happy-dom": "^20.14.6",
60
60
  "remix": "^3.0.0-rc.1",
61
- "vite": "^8.2.1",
62
- "vitest": "^4.1.10",
63
- "@tanstack/ai": "0.71.0"
61
+ "vite": "^8.3.8",
62
+ "vitest": "^4.1.12",
63
+ "@tanstack/ai": "1.7.0"
64
64
  },
65
65
  "scripts": {
66
66
  "lint:fix": "oxlint src --type-aware --fix",
@@ -18,10 +18,9 @@ type HeadlessOptions<TOptions> = CreateChatOptions<
18
18
  >
19
19
 
20
20
  type ChatInstanceOverrides<TOptions> = {
21
- threadId?: string
21
+ threadId: string
22
22
  live?: boolean
23
23
  forwardedProps?: Record<string, any>
24
- body?: Record<string, any>
25
24
  initialMessages?: HeadlessOptions<TOptions>['initialMessages']
26
25
  }
27
26
 
@@ -29,9 +28,9 @@ type ChatInstanceOverrides<TOptions> = {
29
28
  * Bind chat options and UI widgets once at module scope.
30
29
  *
31
30
  * Returns a bound `createAppChat`, the UI kit (`ui`), and `useChatContext`.
32
- * Call `createAppChat(handle)` in a Remix setup function. Render
33
- * `<ui.Chat chat={chat} />`. Pass instance overrides such as `threadId`
34
- * into `createAppChat(handle, overrides)`.
31
+ * Call `createAppChat(handle, { threadId })` in a Remix setup function.
32
+ * The overrides argument is required and must carry `threadId`. Render
33
+ * `<ui.Chat chat={chat} />`.
35
34
  */
36
35
  export function createChatHook<const TOptions>({
37
36
  options,
@@ -46,14 +45,12 @@ export function createChatHook<const TOptions>({
46
45
 
47
46
  function createAppChat(
48
47
  handle: Handle<any>,
49
- overrides?: ChatInstanceOverrides<TOptions>,
48
+ overrides: ChatInstanceOverrides<TOptions>,
50
49
  ): ChatUIHost<TOptions> {
51
- const chat = overrides
52
- ? createUnboundChat(handle, {
53
- ...(options as HeadlessOptions<TOptions>),
54
- ...overrides,
55
- })
56
- : createUnboundChat(handle, options as HeadlessOptions<TOptions>)
50
+ const chat = createUnboundChat(handle, {
51
+ ...(options as HeadlessOptions<TOptions>),
52
+ ...overrides,
53
+ })
57
54
  // oxlint-disable-next-line eslint-js/no-restricted-syntax -- return shape always includes partial/final; ChatUIHost gates those on TSchema
58
55
  return chat as unknown as ChatUIHost<TOptions>
59
56
  }
@@ -32,8 +32,7 @@ import type {
32
32
  * wraps ChatClient and calls `handle.update()` when the client snapshot
33
33
  * changes, so render reads the latest frozen snapshot through getters.
34
34
  *
35
- * The default thread id is `options.threadId ?? handle.id`. Cleanup runs when
36
- * `handle.signal` aborts. Do not pass identification in `options.devtools`;
35
+ * `options.threadId` is required. Cleanup runs when `handle.signal` aborts. Do not pass identification in `options.devtools`;
37
36
  * the helper sets `framework: 'remix'` and `hookName: 'createChat'`.
38
37
  *
39
38
  * @param handle Remix component handle from setup.
@@ -48,6 +47,7 @@ import type {
48
47
  * function Chat(handle: Handle) {
49
48
  * const chat = createChat(handle, {
50
49
  * connection: fetchServerSentEvents('/api/chat'),
50
+ * threadId: 'support-1',
51
51
  * })
52
52
  * return () => (
53
53
  * <div>
@@ -70,7 +70,7 @@ export function createChat<
70
70
  InterruptDefinition<any, any, any, any>
71
71
  > = readonly [],
72
72
  >(
73
- handle: Pick<Handle, 'id' | 'update' | 'signal'>,
73
+ handle: Pick<Handle, 'update' | 'signal'>,
74
74
  options: CreateChatOptions<TTools, TSchema, TContext, TInterrupts>,
75
75
  ) {
76
76
  let closed = false
@@ -78,7 +78,6 @@ export function createChat<
78
78
  type Partial = DeepPartial<InferSchemaType<NonNullable<TSchema>>>
79
79
  type Final = InferSchemaType<NonNullable<TSchema>>
80
80
 
81
- const threadId = options.threadId ?? handle.id
82
81
  const transport = options.connection
83
82
  ? { connection: options.connection }
84
83
  : { fetcher: options.fetcher }
@@ -94,24 +93,18 @@ export function createChat<
94
93
  ...(options.initialMessages !== undefined && {
95
94
  initialMessages: options.initialMessages,
96
95
  }),
96
+ threadId: options.threadId,
97
97
  ...(options.persistence === true
98
98
  ? {
99
99
  persistence: true,
100
- threadId,
101
100
  ...(options.history !== undefined && {
102
101
  history: options.history,
103
102
  }),
104
103
  }
105
- : options.persistence
106
- ? {
107
- persistence: options.persistence,
108
- threadId,
109
- }
110
- : { threadId }),
104
+ : { persistence: options.persistence }),
111
105
  ...(options.initialResumeSnapshot !== undefined && {
112
106
  initialResumeSnapshot: options.initialResumeSnapshot,
113
107
  }),
114
- ...(options.body !== undefined && { body: options.body }),
115
108
  ...(options.forwardedProps !== undefined && {
116
109
  forwardedProps: options.forwardedProps,
117
110
  }),
@@ -232,23 +225,6 @@ export function createChat<
232
225
  await client.addToolResult(result)
233
226
  }
234
227
 
235
- /** @deprecated Use a bound `tool-approval` interrupt and `interrupt.resolveInterrupt`. */
236
- const addToolApprovalResponse = async (response: {
237
- id: string
238
- approved: boolean
239
- }) => {
240
- syncTools()
241
- await client.addToolApprovalResponse(response)
242
- }
243
-
244
- const resumeInterrupts = async (
245
- resumeItems: Array<RunAgentResumeItem>,
246
- state?: ChatResumeState,
247
- ) => {
248
- syncTools()
249
- return await client.resumeInterrupts(resumeItems, state)
250
- }
251
-
252
228
  const resolveInterrupts = (
253
229
  resolution:
254
230
  | boolean
@@ -339,9 +315,6 @@ export function createChat<
339
315
  get interrupts() {
340
316
  return client.getSnapshot().interruptState.interrupts
341
317
  },
342
- get pendingInterrupts() {
343
- return client.getSnapshot().interruptState.interrupts
344
- },
345
318
  get interruptErrors() {
346
319
  return client.getSnapshot().interruptState.interruptErrors
347
320
  },
@@ -368,11 +341,9 @@ export function createChat<
368
341
  setMessages,
369
342
  clear,
370
343
  addToolResult,
371
- addToolApprovalResponse,
372
344
  resolveInterrupts,
373
345
  cancelInterrupts,
374
346
  retryInterrupts,
375
347
  resumeInterruptsUnsafe,
376
- resumeInterrupts,
377
348
  }
378
349
  }
@@ -0,0 +1,97 @@
1
+ import { createGeneration } from './create-generation.ts'
2
+ import type { Handle } from 'remix/ui'
3
+ import type { Model3DResult } from '@tanstack/ai'
4
+ import type { Model3DGenerateInput } from '@tanstack/ai-client'
5
+ import type {
6
+ CreateGenerationOptions,
7
+ CreateGenerationReturn,
8
+ } from './create-generation.ts'
9
+
10
+ /**
11
+ * Options for the createGenerate3DModel helper.
12
+ *
13
+ * Handle is the first argument of the helper. It is not part of this type.
14
+ *
15
+ * @experimental 3D model generation is experimental. The shape can change in
16
+ * a minor release.
17
+ *
18
+ * @template TOutput - The output type after optional transform (defaults to Model3DResult)
19
+ */
20
+ export type CreateGenerate3DModelOptions<TOutput = Model3DResult> = Omit<
21
+ CreateGenerationOptions<Model3DGenerateInput, Model3DResult, TOutput>,
22
+ | 'onResult'
23
+ | 'reconstructResult'
24
+ | 'persistence'
25
+ | 'hydrateGeneration'
26
+ | 'joinRun'
27
+ > & {
28
+ onResult?: (result: Model3DResult) => TOutput | null | void
29
+ }
30
+
31
+ /**
32
+ * Return type for the createGenerate3DModel helper.
33
+ *
34
+ * @experimental 3D model generation is experimental. The shape can change in
35
+ * a minor release.
36
+ *
37
+ * @template TOutput - The output type (after optional transform)
38
+ */
39
+ export type CreateGenerate3DModelReturn<TOutput = Model3DResult> =
40
+ CreateGenerationReturn<TOutput, Model3DGenerateInput>
41
+
42
+ /**
43
+ * Creates a 3D model generation helper for Remix setup (text-to-3D,
44
+ * image-to-3D, 3D-to-3D).
45
+ *
46
+ * Supports two transport modes:
47
+ * - **ConnectConnectionAdapter**: streaming transport (SSE, HTTP stream, custom)
48
+ * - **Fetcher**: direct async function call
49
+ *
50
+ * The server streams a `generation:progress` event for each provider poll and
51
+ * one `generation:result` event with the finished model.
52
+ *
53
+ * Call this in a Remix component setup function. Pass the component Handle as
54
+ * the first argument.
55
+ *
56
+ * @experimental 3D model generation is experimental. The shape can change in
57
+ * a minor release.
58
+ *
59
+ * @example
60
+ * ```tsx
61
+ * import { createGenerate3DModel } from '@tanstack/ai-remix'
62
+ * import { fetchServerSentEvents } from '@tanstack/ai-client'
63
+ * import type { Handle } from 'remix/ui'
64
+ *
65
+ * function ModelGenerator(handle: Handle) {
66
+ * const model = createGenerate3DModel(handle, {
67
+ * threadId: 'hero-model',
68
+ * connection: fetchServerSentEvents('/api/3d-model'),
69
+ * })
70
+ *
71
+ * return () => (
72
+ * <div>
73
+ * <button onClick={() => model.generate({ prompt: 'A low-poly fox' })}>
74
+ * Generate
75
+ * </button>
76
+ * {model.isLoading ? <p>Generating...</p> : null}
77
+ * {model.result ? (
78
+ * <a href={model.result.url}>Download .{model.result.format}</a>
79
+ * ) : null}
80
+ * </div>
81
+ * )
82
+ * }
83
+ * ```
84
+ */
85
+ export function createGenerate3DModel<TTransformed = void>(
86
+ handle: Pick<Handle, 'update' | 'signal'>,
87
+ options: Omit<CreateGenerate3DModelOptions, 'onResult'> & {
88
+ onResult?: (result: Model3DResult) => TTransformed
89
+ },
90
+ ) {
91
+ const devtools = { ...options.devtools, hookName: 'createGenerate3DModel' }
92
+ return createGeneration<Model3DGenerateInput, Model3DResult, TTransformed>(
93
+ handle,
94
+ // 3D results are never persisted, even if an untyped caller sets it.
95
+ { ...options, devtools, persistence: false },
96
+ )
97
+ }
@@ -2,10 +2,7 @@ import { createGeneration } from './create-generation.ts'
2
2
  import { reconstructAudioResult } from '@tanstack/ai-client'
3
3
  import type { Handle } from 'remix/ui'
4
4
  import type { AudioGenerationResult } from '@tanstack/ai'
5
- import type {
6
- AudioGenerateInput,
7
- GenerationPersistenceOptions,
8
- } from '@tanstack/ai-client'
5
+ import type { AudioGenerateInput } from '@tanstack/ai-client'
9
6
  import type {
10
7
  CreateGenerationOptions,
11
8
  CreateGenerationReturn,
@@ -47,6 +44,7 @@ export type CreateGenerateAudioReturn<TOutput = AudioGenerationResult> =
47
44
  *
48
45
  * function AudioGenerator(handle: Handle) {
49
46
  * const audio = createGenerateAudio(handle, {
47
+ * threadId: 'theme-audio',
50
48
  * connection: fetchServerSentEvents('/api/generate/audio'),
51
49
  * })
52
50
  *
@@ -68,13 +66,10 @@ export type CreateGenerateAudioReturn<TOutput = AudioGenerationResult> =
68
66
  * ```
69
67
  */
70
68
  export function createGenerateAudio<TTransformed = void>(
71
- handle: Pick<Handle, 'id' | 'update' | 'signal'>,
72
- options: Omit<
73
- CreateGenerateAudioOptions,
74
- 'onResult' | 'persistence' | 'threadId'
75
- > & {
69
+ handle: Pick<Handle, 'update' | 'signal'>,
70
+ options: Omit<CreateGenerateAudioOptions, 'onResult'> & {
76
71
  onResult?: (result: AudioGenerationResult) => TTransformed
77
- } & GenerationPersistenceOptions,
72
+ },
78
73
  ) {
79
74
  const devtools = {
80
75
  ...options.devtools,
@@ -2,10 +2,7 @@ import { createGeneration } from './create-generation.ts'
2
2
  import { reconstructImageResult } from '@tanstack/ai-client'
3
3
  import type { Handle } from 'remix/ui'
4
4
  import type { ImageGenerationResult } from '@tanstack/ai'
5
- import type {
6
- GenerationPersistenceOptions,
7
- ImageGenerateInput,
8
- } from '@tanstack/ai-client'
5
+ import type { ImageGenerateInput } from '@tanstack/ai-client'
9
6
  import type {
10
7
  CreateGenerationOptions,
11
8
  CreateGenerationReturn,
@@ -51,6 +48,7 @@ export type CreateGenerateImageReturn<TOutput = ImageGenerationResult> =
51
48
  *
52
49
  * function ImageGenerator(handle: Handle) {
53
50
  * const image = createGenerateImage(handle, {
51
+ * threadId: 'hero-image',
54
52
  * connection: fetchServerSentEvents('/api/generate/image'),
55
53
  * })
56
54
  *
@@ -69,13 +67,10 @@ export type CreateGenerateImageReturn<TOutput = ImageGenerationResult> =
69
67
  * ```
70
68
  */
71
69
  export function createGenerateImage<TTransformed = void>(
72
- handle: Pick<Handle, 'id' | 'update' | 'signal'>,
73
- options: Omit<
74
- CreateGenerateImageOptions,
75
- 'onResult' | 'persistence' | 'threadId'
76
- > & {
70
+ handle: Pick<Handle, 'update' | 'signal'>,
71
+ options: Omit<CreateGenerateImageOptions, 'onResult'> & {
77
72
  onResult?: (result: ImageGenerationResult) => TTransformed
78
- } & GenerationPersistenceOptions,
73
+ },
79
74
  ) {
80
75
  const devtools = {
81
76
  ...options.devtools,
@@ -2,10 +2,7 @@ import { createGeneration } from './create-generation.ts'
2
2
  import { reconstructSpeechResult } from '@tanstack/ai-client'
3
3
  import type { Handle } from 'remix/ui'
4
4
  import type { TTSResult } from '@tanstack/ai'
5
- import type {
6
- GenerationPersistenceOptions,
7
- SpeechGenerateInput,
8
- } from '@tanstack/ai-client'
5
+ import type { SpeechGenerateInput } from '@tanstack/ai-client'
9
6
  import type {
10
7
  CreateGenerationOptions,
11
8
  CreateGenerationReturn,
@@ -47,6 +44,7 @@ export type CreateGenerateSpeechReturn<TOutput = TTSResult> =
47
44
  *
48
45
  * function SpeechGenerator(handle: Handle) {
49
46
  * const speech = createGenerateSpeech(handle, {
47
+ * threadId: 'welcome-speech',
50
48
  * connection: fetchServerSentEvents('/api/generate/speech'),
51
49
  * })
52
50
  *
@@ -69,13 +67,10 @@ export type CreateGenerateSpeechReturn<TOutput = TTSResult> =
69
67
  * ```
70
68
  */
71
69
  export function createGenerateSpeech<TTransformed = void>(
72
- handle: Pick<Handle, 'id' | 'update' | 'signal'>,
73
- options: Omit<
74
- CreateGenerateSpeechOptions,
75
- 'onResult' | 'persistence' | 'threadId'
76
- > & {
70
+ handle: Pick<Handle, 'update' | 'signal'>,
71
+ options: Omit<CreateGenerateSpeechOptions, 'onResult'> & {
77
72
  onResult?: (result: TTSResult) => TTransformed
78
- } & GenerationPersistenceOptions,
73
+ },
79
74
  ) {
80
75
  const devtools = {
81
76
  ...options.devtools,
@@ -7,7 +7,6 @@ import type {
7
7
  ConnectConnectionAdapter,
8
8
  GenerationClientState,
9
9
  GenerationFetcher,
10
- GenerationPersistenceOptions,
11
10
  InferGenerationOutputFromReturn,
12
11
  VideoGenerateInput,
13
12
  VideoGenerateResult,
@@ -55,11 +54,10 @@ export interface CreateGenerateVideoOptions<TOutput = VideoGenerateResult> {
55
54
  * `` `video-${videoId}-start-frame` ``). It is also sent as the AG-UI thread
56
55
  * id on the wire, which the protocol requires.
57
56
  *
58
- * **Required whenever `persistence` is set** — an app that cannot name the
59
- * scope has nothing to restore to. Optional for ephemeral generations. If
60
- * omitted, the helper uses `handle.id`.
57
+ * Required. A generated id would change on every reload, so persistence
58
+ * would restore nothing.
61
59
  */
62
- threadId?: string
60
+ threadId: string
63
61
  /**
64
62
  * Server-driven hydration handler for `persistence: true` when the
65
63
  * connection doesn't carry one (e.g. alongside `fetcher`, or a `stream()` /
@@ -147,6 +145,7 @@ export interface CreateGenerateVideoReturn<TOutput = VideoGenerateResult> {
147
145
  *
148
146
  * function VideoGenerator(handle: Handle) {
149
147
  * const video = createGenerateVideo(handle, {
148
+ * threadId: 'intro-video',
150
149
  * connection: fetchServerSentEvents('/api/generate/video'),
151
150
  * onStatusUpdate: (status) => console.log(`Progress: ${status.progress}%`),
152
151
  * })
@@ -171,13 +170,10 @@ export interface CreateGenerateVideoReturn<TOutput = VideoGenerateResult> {
171
170
  // parameter is typed as `VideoGenerateResult` and `result` narrows to the
172
171
  // transform's return. See issue #848.
173
172
  export function createGenerateVideo<TTransformed = void>(
174
- handle: Pick<Handle, 'id' | 'update' | 'signal'>,
175
- options: Omit<
176
- CreateGenerateVideoOptions,
177
- 'onResult' | 'persistence' | 'threadId'
178
- > & {
173
+ handle: Pick<Handle, 'update' | 'signal'>,
174
+ options: Omit<CreateGenerateVideoOptions, 'onResult'> & {
179
175
  onResult?: (result: VideoGenerateResult) => TTransformed
180
- } & GenerationPersistenceOptions,
176
+ },
181
177
  ) {
182
178
  type TOutput = InferGenerationOutputFromReturn<
183
179
  VideoGenerateResult,
@@ -198,12 +194,9 @@ export function createGenerateVideo<TTransformed = void>(
198
194
  void handle.update()
199
195
  }
200
196
 
201
- const threadId = options.threadId ?? handle.id
202
-
203
- const baseOptions: Omit<
204
- VideoGenerationClientOptions<TOutput>,
205
- 'persistence' | 'threadId'
206
- > = {
197
+ const baseOptions: VideoGenerationClientOptions<TOutput> = {
198
+ persistence: options.persistence,
199
+ threadId: options.threadId,
207
200
  ...(options.body !== undefined && { body: options.body }),
208
201
  ...(options.hydrateGeneration !== undefined && {
209
202
  hydrateGeneration: options.hydrateGeneration,
@@ -276,27 +269,15 @@ export function createGenerateVideo<TTransformed = void>(
276
269
  },
277
270
  }
278
271
 
279
- const persistenceProps =
280
- typeof options.threadId === 'string' && options.persistence
281
- ? {
282
- persistence: options.persistence,
283
- threadId: options.threadId,
284
- }
285
- : {
286
- threadId,
287
- }
288
-
289
272
  let client: VideoGenerationClient<TOutput>
290
273
  if (options.connection) {
291
274
  client = new VideoGenerationClient<TOutput>({
292
275
  ...baseOptions,
293
- ...persistenceProps,
294
276
  connection: options.connection,
295
277
  })
296
278
  } else if (options.fetcher) {
297
279
  client = new VideoGenerationClient<TOutput>({
298
280
  ...baseOptions,
299
- ...persistenceProps,
300
281
  fetcher: options.fetcher,
301
282
  })
302
283
  } else {
@@ -8,14 +8,13 @@ import type {
8
8
  GenerationClientOptions,
9
9
  GenerationClientState,
10
10
  GenerationFetcher,
11
- GenerationPersistenceOptions,
12
11
  GenerationRestoredResult,
13
12
  InferGenerationOutputFromReturn,
14
13
  } from '@tanstack/ai-client'
15
14
  import type { ByokClient } from '@tanstack/ai-client/byok'
16
15
  import type { ProviderId } from '@tanstack/ai/byok'
17
16
 
18
- type RemixHandle = Pick<Handle, 'id' | 'update' | 'signal'>
17
+ type RemixHandle = Pick<Handle, 'update' | 'signal'>
19
18
 
20
19
  /**
21
20
  * Options for the createGeneration helper.
@@ -58,11 +57,10 @@ export interface CreateGenerationOptions<TInput, TResult, TOutput = TResult> {
58
57
  * `` `video-${videoId}-start-frame` ``). It is also sent as the AG-UI thread
59
58
  * id on the wire, which the protocol requires.
60
59
  *
61
- * **Required whenever `persistence` is set** — an app that cannot name the
62
- * scope has nothing to restore to. Optional for ephemeral generations. If
63
- * omitted, the helper uses `handle.id`.
60
+ * Required. A generated id would change on every reload, so persistence
61
+ * would restore nothing.
64
62
  */
65
- threadId?: string
63
+ threadId: string
66
64
  /**
67
65
  * Server-driven hydration handler for `persistence: true` when the
68
66
  * connection doesn't carry one (e.g. alongside `fetcher`, or a `stream()` /
@@ -153,6 +151,7 @@ export interface CreateGenerationReturn<
153
151
  *
154
152
  * function CustomGenerator(handle: Handle) {
155
153
  * const gen = createGeneration(handle, {
154
+ * threadId: 'custom-gen',
156
155
  * connection: fetchServerSentEvents('/api/generate/custom'),
157
156
  * })
158
157
  *
@@ -179,12 +178,9 @@ export function createGeneration<
179
178
  TTransformed = void,
180
179
  >(
181
180
  handle: RemixHandle,
182
- options: Omit<
183
- CreateGenerationOptions<TInput, TResult>,
184
- 'onResult' | 'persistence' | 'threadId'
185
- > & {
181
+ options: Omit<CreateGenerationOptions<TInput, TResult>, 'onResult'> & {
186
182
  onResult?: (result: TResult) => TTransformed
187
- } & GenerationPersistenceOptions,
183
+ },
188
184
  ) {
189
185
  type TOutput = InferGenerationOutputFromReturn<TResult, TTransformed>
190
186
 
@@ -200,16 +196,13 @@ export function createGeneration<
200
196
  void handle.update()
201
197
  }
202
198
 
203
- const threadId = options.threadId ?? handle.id
204
-
205
199
  // Conditional spread for `body` (strict-optional in target;
206
200
  // local source is `Record<string, any> | undefined`). Callbacks
207
201
  // wrap optional ones in non-returning bodies so `?.()`'s
208
202
  // implicit `undefined` doesn't pollute the function return type.
209
- const clientOptions: Omit<
210
- GenerationClientOptions<TInput, TResult, TOutput>,
211
- 'persistence' | 'threadId'
212
- > = {
203
+ const clientOptions: GenerationClientOptions<TInput, TResult, TOutput> = {
204
+ persistence: options.persistence,
205
+ threadId: options.threadId,
213
206
  ...(options.body !== undefined && { body: options.body }),
214
207
  ...(options.hydrateGeneration !== undefined && {
215
208
  hydrateGeneration: options.hydrateGeneration,
@@ -268,27 +261,15 @@ export function createGeneration<
268
261
  },
269
262
  }
270
263
 
271
- const persistenceProps =
272
- typeof options.threadId === 'string' && options.persistence
273
- ? {
274
- persistence: options.persistence,
275
- threadId: options.threadId,
276
- }
277
- : {
278
- threadId,
279
- }
280
-
281
264
  let client: GenerationClient<TInput, TResult, TOutput>
282
265
  if (options.connection) {
283
266
  client = new GenerationClient<TInput, TResult, TOutput>({
284
267
  ...clientOptions,
285
- ...persistenceProps,
286
268
  connection: options.connection,
287
269
  })
288
270
  } else if (options.fetcher) {
289
271
  client = new GenerationClient<TInput, TResult, TOutput>({
290
272
  ...clientOptions,
291
- ...persistenceProps,
292
273
  fetcher: options.fetcher,
293
274
  })
294
275
  } else {
@@ -2,10 +2,7 @@ import { createGeneration } from './create-generation.ts'
2
2
  import { reconstructSummarizeResult } from '@tanstack/ai-client'
3
3
  import type { Handle } from 'remix/ui'
4
4
  import type { SummarizationResult } from '@tanstack/ai'
5
- import type {
6
- GenerationPersistenceOptions,
7
- SummarizeGenerateInput,
8
- } from '@tanstack/ai-client'
5
+ import type { SummarizeGenerateInput } from '@tanstack/ai-client'
9
6
  import type {
10
7
  CreateGenerationOptions,
11
8
  CreateGenerationReturn,
@@ -47,6 +44,7 @@ export type CreateSummarizeReturn<TOutput = SummarizationResult> =
47
44
  *
48
45
  * function Summarizer(handle: Handle) {
49
46
  * const summarizer = createSummarize(handle, {
47
+ * threadId: 'article-summary',
50
48
  * connection: fetchServerSentEvents('/api/summarize'),
51
49
  * })
52
50
  *
@@ -71,13 +69,10 @@ export type CreateSummarizeReturn<TOutput = SummarizationResult> =
71
69
  * ```
72
70
  */
73
71
  export function createSummarize<TTransformed = void>(
74
- handle: Pick<Handle, 'id' | 'update' | 'signal'>,
75
- options: Omit<
76
- CreateSummarizeOptions,
77
- 'onResult' | 'persistence' | 'threadId'
78
- > & {
72
+ handle: Pick<Handle, 'update' | 'signal'>,
73
+ options: Omit<CreateSummarizeOptions, 'onResult'> & {
79
74
  onResult?: (result: SummarizationResult) => TTransformed
80
- } & GenerationPersistenceOptions,
75
+ },
81
76
  ) {
82
77
  const devtools = {
83
78
  ...options.devtools,
@@ -2,10 +2,7 @@ import { createGeneration } from './create-generation.ts'
2
2
  import { reconstructTranscriptionResult } from '@tanstack/ai-client'
3
3
  import type { Handle } from 'remix/ui'
4
4
  import type { TranscriptionResult } from '@tanstack/ai'
5
- import type {
6
- GenerationPersistenceOptions,
7
- TranscriptionGenerateInput,
8
- } from '@tanstack/ai-client'
5
+ import type { TranscriptionGenerateInput } from '@tanstack/ai-client'
9
6
  import type {
10
7
  CreateGenerationOptions,
11
8
  CreateGenerationReturn,
@@ -51,6 +48,7 @@ export type CreateTranscriptionReturn<TOutput = TranscriptionResult> =
51
48
  *
52
49
  * function Transcriber(handle: Handle) {
53
50
  * const transcription = createTranscription(handle, {
51
+ * threadId: 'meeting-transcript',
54
52
  * connection: fetchServerSentEvents('/api/transcribe'),
55
53
  * })
56
54
  *
@@ -80,13 +78,10 @@ export type CreateTranscriptionReturn<TOutput = TranscriptionResult> =
80
78
  * ```
81
79
  */
82
80
  export function createTranscription<TTransformed = void>(
83
- handle: Pick<Handle, 'id' | 'update' | 'signal'>,
84
- options: Omit<
85
- CreateTranscriptionOptions,
86
- 'onResult' | 'persistence' | 'threadId'
87
- > & {
81
+ handle: Pick<Handle, 'update' | 'signal'>,
82
+ options: Omit<CreateTranscriptionOptions, 'onResult'> & {
88
83
  onResult?: (result: TranscriptionResult) => TTransformed
89
- } & GenerationPersistenceOptions,
84
+ },
90
85
  ) {
91
86
  const devtools = {
92
87
  ...options.devtools,