@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.
@@ -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,
@@ -66,6 +64,11 @@ export type {
66
64
  CreateGenerateVideoOptions,
67
65
  CreateGenerateVideoReturn,
68
66
  } from './create-generate-video.ts'
67
+ export { createGenerate3DModel } from './create-generate-3d-model.ts'
68
+ export type {
69
+ CreateGenerate3DModelOptions,
70
+ CreateGenerate3DModelReturn,
71
+ } from './create-generate-3d-model.ts'
69
72
  export { createAudioRecorder } from './create-audio-recorder.ts'
70
73
  export type { CreateAudioRecorderOptions } from './create-audio-recorder.ts'
71
74
 
@@ -139,6 +142,7 @@ export {
139
142
  type TranscriptionGenerateInput,
140
143
  type SummarizeGenerateInput,
141
144
  type VideoGenerateInput,
145
+ type Model3DGenerateInput,
142
146
  type VideoGenerateResult,
143
147
  type VideoStatusInfo,
144
148
  } from '@tanstack/ai-client'
@@ -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
- }