@tanstack/ai-remix 0.7.0 → 1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/ai-remix",
3
- "version": "0.7.0",
3
+ "version": "1.0.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,11 +47,11 @@
47
47
  "README.md"
48
48
  ],
49
49
  "dependencies": {
50
- "@tanstack/ai-client": "^0.40.0"
50
+ "@tanstack/ai-client": "^1.0.0"
51
51
  },
52
52
  "peerDependencies": {
53
53
  "remix": "^3.0.0-rc.1",
54
- "@tanstack/ai": "^0.70.0"
54
+ "@tanstack/ai": "^1.0.0"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@types/node": "^24.10.1",
@@ -60,7 +60,7 @@
60
60
  "remix": "^3.0.0-rc.1",
61
61
  "vite": "^8.2.1",
62
62
  "vitest": "^4.1.10",
63
- "@tanstack/ai": "0.70.0"
63
+ "@tanstack/ai": "1.0.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
  }
@@ -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,
@@ -16,12 +16,6 @@ export type CreateRegisterWebMCPToolsOptions<
16
16
  onError?: (error: unknown) => void
17
17
  }
18
18
 
19
- /** @deprecated Use `CreateRegisterWebMCPToolsOptions`. Removed in 1.0.0. */
20
- export type CreateWebMCPToolsOptions<
21
- TTools extends ReadonlyArray<AnyClientTool>,
22
- TContext = InferredClientContext<TTools>,
23
- > = CreateRegisterWebMCPToolsOptions<TTools, TContext>
24
-
25
19
  type CreateRegisterWebMCPToolsArguments<
26
20
  TTools extends ReadonlyArray<AnyClientTool>,
27
21
  TContext,
@@ -65,12 +59,6 @@ export function createRegisterWebMCPTools<
65
59
  })
66
60
  }
67
61
 
68
- /**
69
- * @deprecated Use `createRegisterWebMCPTools`. Removed in 1.0.0.
70
- * @alias
71
- */
72
- export const createWebMCPTools = createRegisterWebMCPTools
73
-
74
62
  /** Options for {@link createPageWebMCPTools}. */
75
63
  export type CreatePageWebMCPToolsOptions = Omit<
76
64
  SubscribeWebMCPToolsOptions,
@@ -92,6 +80,7 @@ export type CreatePageWebMCPToolsOptions = Omit<
92
80
  * function Chat(handle: Handle) {
93
81
  * const page = createPageWebMCPTools(handle)
94
82
  * const chat = createChat(handle, {
83
+ * threadId: 'support-1',
95
84
  * connection,
96
85
  * get tools() {
97
86
  * return page.tools
package/src/index.ts CHANGED
@@ -6,12 +6,10 @@ export type { CreateMcpAppBridgeOptions } from './create-mcp-app-bridge.ts'
6
6
  export {
7
7
  createPageWebMCPTools,
8
8
  createRegisterWebMCPTools,
9
- createWebMCPTools,
10
9
  } from './create-web-mcp-tools.ts'
11
10
  export type {
12
11
  CreatePageWebMCPToolsOptions,
13
12
  CreateRegisterWebMCPToolsOptions,
14
- CreateWebMCPToolsOptions,
15
13
  } from './create-web-mcp-tools.ts'
16
14
  export type {
17
15
  DeepPartial,
@@ -1,5 +1,6 @@
1
1
  import type {
2
2
  AnyClientTool,
3
+ RealtimeAdapter,
3
4
  RealtimeMessage,
4
5
  RealtimeMode,
5
6
  RealtimeSessionConfig,
@@ -7,7 +8,6 @@ import type {
7
8
  RealtimeToken,
8
9
  UsageInfo,
9
10
  } from '@tanstack/ai'
10
- import type { RealtimeAdapter } from '@tanstack/ai-client'
11
11
 
12
12
  /**
13
13
  * Options for the createRealtimeChat helper.
package/src/types.ts CHANGED
@@ -60,7 +60,7 @@ export type DeepPartial<T> =
60
60
  *
61
61
  * Call `createChat(handle, options)` in Remix setup with Handle from
62
62
  * `remix/ui`. Handle is the first argument of the helper. It is not part of
63
- * this type. The default id is `options.threadId ?? handle.id`.
63
+ * this type. `threadId` is required.
64
64
  *
65
65
  * Pass either `connection` or `fetcher`. The XOR is enforced at the type
66
66
  * level via `ChatTransport`.
@@ -210,15 +210,6 @@ interface BaseCreateChatReturn<
210
210
  errorText?: string
211
211
  }) => Promise<void>
212
212
 
213
- /**
214
- * @deprecated Use a bound `tool-approval` interrupt and
215
- * `interrupt.resolveInterrupt`.
216
- */
217
- addToolApprovalResponse: (response: {
218
- id: string // approval.id, not toolCallId
219
- approved: boolean
220
- }) => Promise<void>
221
-
222
213
  /**
223
214
  * The id of the run this client has in flight (one it started or rejoined),
224
215
  * or `null` when there is none (including while a run sits paused on an
@@ -232,8 +223,6 @@ interface BaseCreateChatReturn<
232
223
  */
233
224
  runId: string | null
234
225
  interrupts: BoundInterrupts<TTools, TInterrupts>
235
- /** @deprecated Use `interrupts`. */
236
- pendingInterrupts: BoundInterrupts<TTools, TInterrupts>
237
226
  interruptErrors: ChatInterruptState<TTools, TInterrupts>['interruptErrors']
238
227
  resuming: boolean
239
228
  resolveInterrupts: {
@@ -250,11 +239,6 @@ interface BaseCreateChatReturn<
250
239
  resume: Array<RunAgentResumeItem>,
251
240
  state?: ChatResumeState,
252
241
  ) => Promise<boolean>
253
- /** @deprecated Use bound interrupt methods or `resumeInterruptsUnsafe`. */
254
- resumeInterrupts: (
255
- resume: Array<RunAgentResumeItem>,
256
- state?: ChatResumeState,
257
- ) => Promise<boolean>
258
242
 
259
243
  /**
260
244
  * Reload the last assistant message
package/src/ui.ts CHANGED
@@ -14,26 +14,6 @@ export {
14
14
  type ToolProps,
15
15
  } from './chat-ui/create-ui.tsx'
16
16
  export { createChatHook } from './chat-ui/create-chat-hook.ts'
17
- export { Chat, useChatContext, type ChatProps } from './chat-ui/chat.tsx'
18
- export {
19
- ChatMessages,
20
- type ChatMessagesProps,
21
- } from './chat-ui/chat-messages.tsx'
22
- export {
23
- ChatMessage,
24
- type ChatMessageProps,
25
- type ToolCallRenderProps,
26
- } from './chat-ui/chat-message.tsx'
27
- export {
28
- ChatInput,
29
- type ChatInputProps,
30
- type ChatInputRenderProps,
31
- } from './chat-ui/chat-input.tsx'
32
- export {
33
- ToolApproval,
34
- type ToolApprovalProps,
35
- type ToolApprovalRenderProps,
36
- } from './chat-ui/tool-approval.tsx'
37
17
  export { TextPart, type TextPartProps } from './chat-ui/text-part.tsx'
38
18
  export {
39
19
  ThinkingPart,
@@ -1,125 +0,0 @@
1
- import { on } from 'remix/ui'
2
- import type { Handle, RemixNode } from 'remix/ui'
3
- import { useChatContext } from './chat.tsx'
4
-
5
- export interface ChatInputRenderProps {
6
- value: string
7
- onChange: (value: string) => void
8
- onSubmit: () => void
9
- isLoading: boolean
10
- disabled: boolean
11
- }
12
-
13
- /** @deprecated Use `createChatUI()` and an application-owned input component. Removed in 1.0.0. */
14
- export interface ChatInputProps {
15
- children?: (props: ChatInputRenderProps) => RemixNode
16
- class?: string
17
- placeholder?: string
18
- disabled?: boolean
19
- submitOnEnter?: boolean
20
- }
21
-
22
- /**
23
- * @deprecated Use `createChatUI()` and an application-owned input component.
24
- * Removed in 1.0.0.
25
- */
26
- export function ChatInput(handle: Handle<ChatInputProps>) {
27
- let value = ''
28
-
29
- return () => {
30
- const { sendMessage, isLoading } = useChatContext(handle)
31
- const disabled = Boolean(handle.props.disabled || isLoading)
32
- const submitOnEnter = handle.props.submitOnEnter !== false
33
-
34
- function onChange(next: string) {
35
- value = next
36
- void handle.update()
37
- }
38
-
39
- function onSubmit() {
40
- if (!value.trim() || disabled) return
41
- void sendMessage(value)
42
- value = ''
43
- void handle.update()
44
- }
45
-
46
- const renderProps: ChatInputRenderProps = {
47
- value,
48
- onChange,
49
- onSubmit,
50
- isLoading,
51
- disabled,
52
- }
53
-
54
- if (typeof handle.props.children === 'function') {
55
- return handle.props.children(renderProps)
56
- }
57
-
58
- return (
59
- <div
60
- class={handle.props.class}
61
- data-chat-input
62
- style={{
63
- display: 'flex',
64
- gap: '0.75rem',
65
- alignItems: 'center',
66
- width: '100%',
67
- }}
68
- >
69
- <input
70
- data-chat-textarea
71
- disabled={disabled}
72
- placeholder={handle.props.placeholder ?? 'Type a message...'}
73
- type="text"
74
- value={value}
75
- mix={[
76
- on('input', (event) => {
77
- onChange((event.currentTarget as HTMLInputElement).value)
78
- }),
79
- on('keydown', (event) => {
80
- if (
81
- submitOnEnter &&
82
- event.key === 'Enter' &&
83
- !event.isComposing
84
- ) {
85
- event.preventDefault()
86
- onSubmit()
87
- }
88
- }),
89
- ]}
90
- style={{
91
- flex: '1',
92
- padding: '0.75rem 1rem',
93
- fontSize: '0.875rem',
94
- border: '1px solid rgba(255, 255, 255, 0.1)',
95
- borderRadius: '0.75rem',
96
- backgroundColor: 'rgba(31, 41, 55, 0.5)',
97
- color: 'white',
98
- outline: 'none',
99
- }}
100
- />
101
- <button
102
- data-chat-submit
103
- disabled={disabled || !value.trim()}
104
- mix={[on('click', onSubmit)]}
105
- style={{
106
- padding: '0.75rem 1.5rem',
107
- fontSize: '0.875rem',
108
- fontWeight: 500,
109
- color: 'white',
110
- backgroundColor:
111
- disabled || !value.trim()
112
- ? 'rgba(107, 114, 128, 0.5)'
113
- : 'rgb(249, 115, 22)',
114
- border: 'none',
115
- borderRadius: '0.75rem',
116
- cursor: disabled || !value.trim() ? 'not-allowed' : 'pointer',
117
- whiteSpace: 'nowrap',
118
- }}
119
- >
120
- {isLoading ? 'Sending...' : 'Send'}
121
- </button>
122
- </div>
123
- )
124
- }
125
- }
@@ -1,197 +0,0 @@
1
- import type { Handle, RemixNode } from 'remix/ui'
2
- import { ThinkingPart } from './thinking-part.tsx'
3
- import type { UIMessage } from '../types.ts'
4
-
5
- export interface ToolCallRenderProps {
6
- id: string
7
- name: string
8
- arguments: string
9
- state: string
10
- approval?: {
11
- id: string
12
- needsApproval: boolean
13
- approved?: boolean
14
- }
15
- output?: unknown
16
- }
17
-
18
- /** @deprecated Use `createChatUI()` Message instead. Removed in 1.0.0. */
19
- export interface ChatMessageProps {
20
- message: UIMessage
21
- class?: string
22
- userClass?: string
23
- assistantClass?: string
24
- textPartRenderer?: (props: { content: string }) => RemixNode
25
- thinkingPartRenderer?: (props: {
26
- content: string
27
- isComplete?: boolean
28
- }) => RemixNode
29
- toolsRenderer?: Record<string, (props: ToolCallRenderProps) => RemixNode>
30
- defaultToolRenderer?: (props: ToolCallRenderProps) => RemixNode
31
- toolResultRenderer?: (props: {
32
- toolCallId: string
33
- content: string
34
- state: string
35
- }) => RemixNode
36
- }
37
-
38
- function toolResultContentToString(
39
- content: string | Array<{ type: string; content?: string }>,
40
- ): string {
41
- if (typeof content === 'string') return content
42
- return content
43
- .filter((part) => part.type === 'text')
44
- .map((part) => part.content ?? '')
45
- .join('')
46
- }
47
-
48
- /** @deprecated Use `createChatUI()` Message instead. Removed in 1.0.0. */
49
- export function ChatMessage(handle: Handle<ChatMessageProps>) {
50
- return () => {
51
- const message = handle.props.message
52
- const roleClass =
53
- message.role === 'user'
54
- ? handle.props.userClass
55
- : handle.props.assistantClass
56
- const combinedClass = [handle.props.class, roleClass]
57
- .filter(Boolean)
58
- .join(' ')
59
-
60
- return (
61
- <div
62
- class={combinedClass || undefined}
63
- data-message-id={message.id}
64
- data-message-role={message.role}
65
- data-message-created={message.createdAt?.toISOString()}
66
- >
67
- {message.parts.map((part, index) => (
68
- <MessagePart
69
- key={`${message.id}-part-${index}`}
70
- defaultToolRenderer={handle.props.defaultToolRenderer}
71
- isThinkingComplete={
72
- part.type === 'thinking' &&
73
- message.parts.slice(index + 1).some((p) => p.type === 'text')
74
- }
75
- part={part}
76
- textPartRenderer={handle.props.textPartRenderer}
77
- thinkingPartRenderer={handle.props.thinkingPartRenderer}
78
- toolResultRenderer={handle.props.toolResultRenderer}
79
- toolsRenderer={handle.props.toolsRenderer}
80
- />
81
- ))}
82
- </div>
83
- )
84
- }
85
- }
86
-
87
- function MessagePart(
88
- handle: Handle<{
89
- part: UIMessage['parts'][number]
90
- isThinkingComplete?: boolean
91
- textPartRenderer?: ChatMessageProps['textPartRenderer']
92
- thinkingPartRenderer?: ChatMessageProps['thinkingPartRenderer']
93
- toolsRenderer?: ChatMessageProps['toolsRenderer']
94
- defaultToolRenderer?: ChatMessageProps['defaultToolRenderer']
95
- toolResultRenderer?: ChatMessageProps['toolResultRenderer']
96
- }>,
97
- ) {
98
- return () => {
99
- const part = handle.props.part
100
-
101
- if (part.type === 'text') {
102
- if (handle.props.textPartRenderer) {
103
- return handle.props.textPartRenderer({ content: part.content })
104
- }
105
- return (
106
- <div data-part-type="text" data-part-content>
107
- {part.content}
108
- </div>
109
- )
110
- }
111
-
112
- if (part.type === 'thinking') {
113
- if (handle.props.thinkingPartRenderer) {
114
- return handle.props.thinkingPartRenderer({
115
- content: part.content,
116
- isComplete: handle.props.isThinkingComplete,
117
- })
118
- }
119
- return (
120
- <ThinkingPart
121
- content={part.content}
122
- isComplete={handle.props.isThinkingComplete}
123
- />
124
- )
125
- }
126
-
127
- if (part.type === 'tool-call') {
128
- const toolProps: ToolCallRenderProps = {
129
- id: part.id,
130
- name: part.name,
131
- arguments: part.arguments,
132
- state: part.state,
133
- approval: part.approval,
134
- output: part.output,
135
- }
136
- const named = handle.props.toolsRenderer?.[part.name]
137
- if (named) return named(toolProps)
138
- if (handle.props.defaultToolRenderer) {
139
- return handle.props.defaultToolRenderer(toolProps)
140
- }
141
- return (
142
- <div
143
- data-part-type="tool-call"
144
- data-tool-id={part.id}
145
- data-tool-name={part.name}
146
- data-tool-state={part.state}
147
- >
148
- <div data-tool-header>
149
- <strong>{part.name}</strong>
150
- <span data-tool-state-badge>{part.state}</span>
151
- </div>
152
- {part.arguments ? (
153
- <div data-tool-arguments>
154
- <pre>{part.arguments}</pre>
155
- </div>
156
- ) : null}
157
- {part.approval ? (
158
- <div data-tool-approval>
159
- {part.approval.approved !== undefined
160
- ? part.approval.approved
161
- ? 'Approved'
162
- : 'Denied'
163
- : 'Awaiting approval...'}
164
- </div>
165
- ) : null}
166
- {part.output ? (
167
- <div data-tool-output>
168
- <pre>{JSON.stringify(part.output, null, 2)}</pre>
169
- </div>
170
- ) : null}
171
- </div>
172
- )
173
- }
174
-
175
- if (part.type === 'tool-result') {
176
- const content = toolResultContentToString(part.content)
177
- if (handle.props.toolResultRenderer) {
178
- return handle.props.toolResultRenderer({
179
- toolCallId: part.toolCallId,
180
- content,
181
- state: part.state,
182
- })
183
- }
184
- return (
185
- <div
186
- data-part-type="tool-result"
187
- data-tool-call-id={part.toolCallId}
188
- data-tool-result-state={part.state}
189
- >
190
- <div data-tool-result-content>{content}</div>
191
- </div>
192
- )
193
- }
194
-
195
- return null
196
- }
197
- }
@@ -1,67 +0,0 @@
1
- import { ref } from 'remix/ui'
2
- import type { Handle, RemixNode } from 'remix/ui'
3
- import { useChatContext } from './chat.tsx'
4
- import { ChatMessage } from './chat-message.tsx'
5
- import type { UIMessage } from '../types.ts'
6
-
7
- /** @deprecated Use `createChatUI()` Messages instead. Removed in 1.0.0. */
8
- export interface ChatMessagesProps {
9
- children?: (message: UIMessage, index: number) => RemixNode
10
- class?: string
11
- emptyState?: RemixNode
12
- loadingState?: RemixNode
13
- errorState?: (props: {
14
- error: Error
15
- reload: () => Promise<void>
16
- }) => RemixNode
17
- autoScroll?: boolean
18
- }
19
-
20
- /** @deprecated Use `createChatUI()` Messages instead. Removed in 1.0.0. */
21
- export function ChatMessages(handle: Handle<ChatMessagesProps>) {
22
- let container: HTMLElement | null = null
23
-
24
- return () => {
25
- const { messages, isLoading, error, reload } = useChatContext(handle)
26
- const autoScroll = handle.props.autoScroll !== false
27
-
28
- if (autoScroll && container) {
29
- container.scrollTop = container.scrollHeight
30
- }
31
-
32
- if (error && handle.props.errorState) {
33
- return handle.props.errorState({ error, reload })
34
- }
35
-
36
- if (isLoading && messages.length === 0 && handle.props.loadingState) {
37
- return handle.props.loadingState
38
- }
39
-
40
- if (messages.length === 0 && handle.props.emptyState) {
41
- return handle.props.emptyState
42
- }
43
-
44
- return (
45
- <div
46
- class={handle.props.class}
47
- data-chat-messages
48
- data-message-count={messages.length}
49
- mix={[
50
- ref((node) => {
51
- container = node
52
- }),
53
- ]}
54
- >
55
- {messages.map((message, index) =>
56
- typeof handle.props.children === 'function' ? (
57
- <div key={message.id} data-message-id={message.id}>
58
- {handle.props.children(message, index)}
59
- </div>
60
- ) : (
61
- <ChatMessage key={message.id} message={message} />
62
- ),
63
- )}
64
- </div>
65
- )
66
- }
67
- }
@@ -1,48 +0,0 @@
1
- import type { ConnectionAdapter } from '@tanstack/ai-client'
2
- import type { Handle, RemixNode } from 'remix/ui'
3
- import { createChat } from '../create-chat.ts'
4
- import type { CreateChatReturn, UIMessage } from '../types.ts'
5
-
6
- /** @deprecated Use `createChatUI()` Chat/Provider instead. Removed in 1.0.0. */
7
- export interface ChatProps {
8
- children?: RemixNode
9
- class?: string
10
- connection: ConnectionAdapter
11
- initialMessages?: Array<UIMessage>
12
- id?: string
13
- body?: Record<string, any>
14
- tools?: Array<any>
15
- }
16
-
17
- /** @deprecated Use `createChatHook().useChatContext(handle)` from `@tanstack/ai-remix/ui` instead. Removed in 1.0.0. */
18
- export function useChatContext(handle: Handle<any>): CreateChatReturn {
19
- const chat = handle.context.get(Chat)
20
- if (!chat) {
21
- throw new Error(
22
- 'Chat components must be wrapped in <Chat>. Make sure you use Chat.Messages, Chat.Input, and the rest inside a <Chat> component.',
23
- )
24
- }
25
- return chat
26
- }
27
-
28
- /**
29
- * @deprecated Use `createChatHook()` from `@tanstack/ai-remix/ui` instead.
30
- * Removed in 1.0.0.
31
- */
32
- export function Chat(handle: Handle<ChatProps, CreateChatReturn>) {
33
- const chat = createChat(handle, {
34
- connection: handle.props.connection,
35
- ...(handle.props.initialMessages !== undefined
36
- ? { initialMessages: handle.props.initialMessages }
37
- : {}),
38
- ...(handle.props.id !== undefined ? { threadId: handle.props.id } : {}),
39
- ...(handle.props.body !== undefined ? { body: handle.props.body } : {}),
40
- ...(handle.props.tools !== undefined ? { tools: handle.props.tools } : {}),
41
- })
42
- handle.context.set(chat)
43
- return () => (
44
- <div class={handle.props.class} data-chat-root>
45
- {handle.props.children}
46
- </div>
47
- )
48
- }
@@ -1,94 +0,0 @@
1
- import { on } from 'remix/ui'
2
- import type { Handle, RemixNode } from 'remix/ui'
3
- import { useChatContext } from './chat.tsx'
4
-
5
- export interface ToolApprovalRenderProps {
6
- toolName: string
7
- input: unknown
8
- onApprove: () => void
9
- onDeny: () => void
10
- hasResponded: boolean
11
- approved?: boolean
12
- }
13
-
14
- /** @deprecated Use `createChatUI()` interrupt components with `chat.interrupts`. Removed in 1.0.0. */
15
- export interface ToolApprovalProps {
16
- toolCallId: string
17
- toolName: string
18
- input: unknown
19
- approval: {
20
- id: string
21
- needsApproval: boolean
22
- approved?: boolean
23
- }
24
- class?: string
25
- children?: (props: ToolApprovalRenderProps) => RemixNode
26
- }
27
-
28
- /**
29
- * @deprecated Use `createChatUI()` interrupt components with `chat.interrupts`.
30
- * Removed in 1.0.0.
31
- */
32
- export function ToolApproval(handle: Handle<ToolApprovalProps>) {
33
- return () => {
34
- const { addToolApprovalResponse } = useChatContext(handle)
35
- const approval = handle.props.approval
36
-
37
- function onApprove() {
38
- void addToolApprovalResponse({ id: approval.id, approved: true })
39
- }
40
-
41
- function onDeny() {
42
- void addToolApprovalResponse({ id: approval.id, approved: false })
43
- }
44
-
45
- const hasResponded = approval.approved !== undefined
46
- const renderProps: ToolApprovalRenderProps = {
47
- toolName: handle.props.toolName,
48
- input: handle.props.input,
49
- onApprove,
50
- onDeny,
51
- hasResponded,
52
- approved: approval.approved,
53
- }
54
-
55
- if (typeof handle.props.children === 'function') {
56
- return handle.props.children(renderProps)
57
- }
58
-
59
- if (hasResponded) {
60
- return (
61
- <div
62
- class={handle.props.class}
63
- data-approval-status={approval.approved ? 'approved' : 'denied'}
64
- data-tool-approval
65
- >
66
- {approval.approved ? 'Approved' : 'Denied'}
67
- </div>
68
- )
69
- }
70
-
71
- return (
72
- <div
73
- class={handle.props.class}
74
- data-approval-status="pending"
75
- data-tool-approval
76
- >
77
- <div data-approval-header>
78
- <strong>{handle.props.toolName}</strong> requires approval
79
- </div>
80
- <div data-approval-input>
81
- <pre>{JSON.stringify(handle.props.input, null, 2)}</pre>
82
- </div>
83
- <div data-approval-actions>
84
- <button data-approval-approve mix={[on('click', onApprove)]}>
85
- Approve
86
- </button>
87
- <button data-approval-deny mix={[on('click', onDeny)]}>
88
- Deny
89
- </button>
90
- </div>
91
- </div>
92
- )
93
- }
94
- }