@tanstack/ai-svelte 0.14.3 → 0.15.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.
@@ -31,4 +31,4 @@ import type { CreateChatOptions, CreateChatReturn } from './types';
31
31
  * </div>
32
32
  * ```
33
33
  */
34
- export declare function createChat<TTools extends ReadonlyArray<AnyClientTool> = any, TSchema extends SchemaInput | undefined = undefined, TContext = InferredClientContext<TTools>>(options: CreateChatOptions<TTools, TSchema, TContext>): CreateChatReturn<TTools, TSchema, TContext>;
34
+ export declare function createChat<const TTools extends ReadonlyArray<AnyClientTool> = any, TSchema extends SchemaInput | undefined = undefined, TContext = InferredClientContext<TTools>>(options: CreateChatOptions<TTools, TSchema, TContext>): CreateChatReturn<TTools, TSchema, TContext>;
@@ -42,6 +42,7 @@ export function createChat(options) {
42
42
  let isSubscribed = $state(false);
43
43
  let connectionStatus = $state('disconnected');
44
44
  let sessionGenerating = $state(false);
45
+ let queue = $state([]);
45
46
  // Create ChatClient instance.
46
47
  // Note: Svelte's createChat runs once per instance and `options` is captured
47
48
  // by reference. Callbacks are therefore frozen to whatever the caller passed
@@ -115,6 +116,10 @@ export function createChat(options) {
115
116
  onSessionGeneratingChange: (isGenerating) => {
116
117
  sessionGenerating = isGenerating;
117
118
  },
119
+ ...(options.queue !== undefined && { queue: options.queue }),
120
+ onQueueChange: (nextQueue) => {
121
+ queue = nextQueue;
122
+ },
118
123
  });
119
124
  messages = client.getMessages();
120
125
  if (options.live) {
@@ -126,9 +131,10 @@ export function createChat(options) {
126
131
  // during component initialization, so we don't add automatic cleanup here.
127
132
  // Users should call chat.stop() in their component's cleanup if needed.
128
133
  // Define methods
129
- const sendMessage = async (content) => {
130
- await client.sendMessage(content);
134
+ const sendMessage = async (content, sendOptions) => {
135
+ await client.sendMessage(content, undefined, sendOptions);
131
136
  };
137
+ const cancelQueued = (id) => client.cancelQueued(id);
132
138
  const append = async (message) => {
133
139
  await client.append(message);
134
140
  };
@@ -226,6 +232,9 @@ export function createChat(options) {
226
232
  get sessionGenerating() {
227
233
  return sessionGenerating;
228
234
  },
235
+ get queue() {
236
+ return queue;
237
+ },
229
238
  get partial() {
230
239
  return partial;
231
240
  },
@@ -233,6 +242,7 @@ export function createChat(options) {
233
242
  return final;
234
243
  },
235
244
  sendMessage,
245
+ cancelQueued,
236
246
  append,
237
247
  reload,
238
248
  stop,
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { createChat } from './create-chat.svelte';
2
- export type { CreateChatOptions, CreateChatReturn, DeepPartial, UIMessage, ChatRequestBody, } from './types';
2
+ export type { CreateChatOptions, CreateChatReturn, DeepPartial, UIMessage, ChatRequestBody, QueuedMessage, SendMessageOptions, WhenBusy, QueueConfig, QueueStrategy, QueueOption, } from './types';
3
3
  export { createGeneration } from './create-generation.svelte';
4
4
  export type { CreateGenerationOptions, CreateGenerationReturn, } from './create-generation.svelte';
5
5
  export { createGenerateImage } from './create-generate-image.svelte';
package/dist/types.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { AnyClientTool, InferSchemaType, ModelMessage, SchemaInput } from '@tanstack/ai';
2
- import type { AIDevtoolsDisplayOptions, ChatClientOptions, ChatClientState, ChatRequestBody, ClientContextOptionFromTools, ConnectionStatus, DistributedOmit, InferredClientContext, MultimodalContent, UIMessage } from '@tanstack/ai-client';
3
- export type { ChatRequestBody, MultimodalContent, UIMessage };
2
+ import type { AIDevtoolsDisplayOptions, ChatClientOptions, ChatClientState, ChatRequestBody, ClientContextOptionFromTools, ConnectionStatus, DistributedOmit, InferredClientContext, MultimodalContent, QueueConfig, QueueOption, QueueStrategy, QueuedMessage, SendMessageOptions, UIMessage, WhenBusy } from '@tanstack/ai-client';
3
+ export type { ChatRequestBody, MultimodalContent, QueueConfig, QueuedMessage, QueueOption, QueueStrategy, SendMessageOptions, UIMessage, WhenBusy, };
4
4
  /**
5
5
  * Recursive partial — every property and every nested array element is
6
6
  * optional. Used to type the in-flight `partial` getter while a structured-
@@ -30,7 +30,7 @@ export type DeepPartial<T> = T extends ReadonlyArray<infer U> ? Array<DeepPartia
30
30
  * Note: Connection and body changes will recreate the ChatClient instance.
31
31
  * To update these options, remount the component or use a key prop.
32
32
  */
33
- export type CreateChatOptions<TTools extends ReadonlyArray<AnyClientTool> = any, TSchema extends SchemaInput | undefined = undefined, TContext = InferredClientContext<TTools>> = DistributedOmit<ChatClientOptions<TTools, TContext>, 'onMessagesChange' | 'onLoadingChange' | 'onErrorChange' | 'onStatusChange' | 'onSubscriptionChange' | 'onConnectionStatusChange' | 'onSessionGeneratingChange' | 'context' | 'devtools'> & {
33
+ export type CreateChatOptions<TTools extends ReadonlyArray<AnyClientTool> = any, TSchema extends SchemaInput | undefined = undefined, TContext = InferredClientContext<TTools>> = DistributedOmit<ChatClientOptions<TTools, TContext>, 'onMessagesChange' | 'onLoadingChange' | 'onErrorChange' | 'onStatusChange' | 'onSubscriptionChange' | 'onConnectionStatusChange' | 'onSessionGeneratingChange' | 'onQueueChange' | 'context' | 'devtools'> & {
34
34
  live?: boolean;
35
35
  /** Display options for TanStack AI Devtools. */
36
36
  devtools?: AIDevtoolsDisplayOptions;
@@ -70,7 +70,15 @@ interface BaseCreateChatReturn<TTools extends ReadonlyArray<AnyClientTool> = any
70
70
  * Send a message and get a response.
71
71
  * Can be a simple string or multimodal content with images, audio, etc.
72
72
  */
73
- sendMessage: (content: string | MultimodalContent) => Promise<void>;
73
+ sendMessage: (content: string | MultimodalContent, options?: SendMessageOptions) => Promise<void>;
74
+ /**
75
+ * Pending messages queued while a stream is in flight.
76
+ */
77
+ readonly queue: Array<QueuedMessage>;
78
+ /**
79
+ * Cancel a queued message before it drains. No-op if already sent.
80
+ */
81
+ cancelQueued: (id: string) => void;
74
82
  /**
75
83
  * Append a message to the conversation
76
84
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/ai-svelte",
3
- "version": "0.14.3",
3
+ "version": "0.15.0",
4
4
  "description": "Svelte 5 bindings for TanStack AI streaming chat, structured outputs, and media generation.",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -46,11 +46,11 @@
46
46
  "media-generation"
47
47
  ],
48
48
  "dependencies": {
49
- "@tanstack/ai-client": "0.20.0"
49
+ "@tanstack/ai-client": "0.22.0"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "svelte": "^5.0.0",
53
- "@tanstack/ai": "^0.40.0"
53
+ "@tanstack/ai": "^0.41.0"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@standard-schema/spec": "^1.1.0",
@@ -63,7 +63,7 @@
63
63
  "svelte-check": "^4.2.0",
64
64
  "typescript": "5.9.3",
65
65
  "vite": "^7.3.3",
66
- "@tanstack/ai": "0.40.0"
66
+ "@tanstack/ai": "0.41.0"
67
67
  },
68
68
  "scripts": {
69
69
  "clean": "rm -rf ./dist",
@@ -4,6 +4,8 @@ import type {
4
4
  ChatClientState,
5
5
  ConnectionStatus,
6
6
  InferredClientContext,
7
+ QueuedMessage,
8
+ SendMessageOptions,
7
9
  StructuredOutputPart,
8
10
  } from '@tanstack/ai-client'
9
11
  import type {
@@ -52,7 +54,7 @@ import type {
52
54
  * ```
53
55
  */
54
56
  export function createChat<
55
- TTools extends ReadonlyArray<AnyClientTool> = any,
57
+ const TTools extends ReadonlyArray<AnyClientTool> = any,
56
58
  TSchema extends SchemaInput | undefined = undefined,
57
59
  TContext = InferredClientContext<TTools>,
58
60
  >(
@@ -71,6 +73,7 @@ export function createChat<
71
73
  let isSubscribed = $state(false)
72
74
  let connectionStatus = $state<ConnectionStatus>('disconnected')
73
75
  let sessionGenerating = $state(false)
76
+ let queue = $state<Array<QueuedMessage>>([])
74
77
 
75
78
  // Structured-output `partial` / `final` are derived from `messages` —
76
79
  // specifically from the structured-output part on the latest assistant
@@ -153,6 +156,10 @@ export function createChat<
153
156
  onSessionGeneratingChange: (isGenerating: boolean) => {
154
157
  sessionGenerating = isGenerating
155
158
  },
159
+ ...(options.queue !== undefined && { queue: options.queue }),
160
+ onQueueChange: (nextQueue: Array<QueuedMessage>) => {
161
+ queue = nextQueue
162
+ },
156
163
  })
157
164
 
158
165
  messages = client.getMessages()
@@ -169,10 +176,15 @@ export function createChat<
169
176
  // Users should call chat.stop() in their component's cleanup if needed.
170
177
 
171
178
  // Define methods
172
- const sendMessage = async (content: string | MultimodalContent) => {
173
- await client.sendMessage(content)
179
+ const sendMessage = async (
180
+ content: string | MultimodalContent,
181
+ sendOptions?: SendMessageOptions,
182
+ ) => {
183
+ await client.sendMessage(content, undefined, sendOptions)
174
184
  }
175
185
 
186
+ const cancelQueued = (id: string) => client.cancelQueued(id)
187
+
176
188
  const append = async (message: ModelMessage | UIMessage<TTools>) => {
177
189
  await client.append(message)
178
190
  }
@@ -293,6 +305,9 @@ export function createChat<
293
305
  get sessionGenerating() {
294
306
  return sessionGenerating
295
307
  },
308
+ get queue() {
309
+ return queue
310
+ },
296
311
  get partial() {
297
312
  return partial
298
313
  },
@@ -300,6 +315,7 @@ export function createChat<
300
315
  return final
301
316
  },
302
317
  sendMessage,
318
+ cancelQueued,
303
319
  append,
304
320
  reload,
305
321
  stop,
package/src/index.ts CHANGED
@@ -5,6 +5,12 @@ export type {
5
5
  DeepPartial,
6
6
  UIMessage,
7
7
  ChatRequestBody,
8
+ QueuedMessage,
9
+ SendMessageOptions,
10
+ WhenBusy,
11
+ QueueConfig,
12
+ QueueStrategy,
13
+ QueueOption,
8
14
  } from './types'
9
15
 
10
16
  // Generation hooks
package/src/types.ts CHANGED
@@ -14,11 +14,27 @@ import type {
14
14
  DistributedOmit,
15
15
  InferredClientContext,
16
16
  MultimodalContent,
17
+ QueueConfig,
18
+ QueueOption,
19
+ QueueStrategy,
20
+ QueuedMessage,
21
+ SendMessageOptions,
17
22
  UIMessage,
23
+ WhenBusy,
18
24
  } from '@tanstack/ai-client'
19
25
 
20
26
  // Re-export types from ai-client
21
- export type { ChatRequestBody, MultimodalContent, UIMessage }
27
+ export type {
28
+ ChatRequestBody,
29
+ MultimodalContent,
30
+ QueueConfig,
31
+ QueuedMessage,
32
+ QueueOption,
33
+ QueueStrategy,
34
+ SendMessageOptions,
35
+ UIMessage,
36
+ WhenBusy,
37
+ }
22
38
 
23
39
  /**
24
40
  * Recursive partial — every property and every nested array element is
@@ -66,6 +82,7 @@ export type CreateChatOptions<
66
82
  | 'onSubscriptionChange'
67
83
  | 'onConnectionStatusChange'
68
84
  | 'onSessionGeneratingChange'
85
+ | 'onQueueChange'
69
86
  | 'context'
70
87
  | 'devtools'
71
88
  > & {
@@ -126,7 +143,20 @@ interface BaseCreateChatReturn<
126
143
  * Send a message and get a response.
127
144
  * Can be a simple string or multimodal content with images, audio, etc.
128
145
  */
129
- sendMessage: (content: string | MultimodalContent) => Promise<void>
146
+ sendMessage: (
147
+ content: string | MultimodalContent,
148
+ options?: SendMessageOptions,
149
+ ) => Promise<void>
150
+
151
+ /**
152
+ * Pending messages queued while a stream is in flight.
153
+ */
154
+ readonly queue: Array<QueuedMessage>
155
+
156
+ /**
157
+ * Cancel a queued message before it drains. No-op if already sent.
158
+ */
159
+ cancelQueued: (id: string) => void
130
160
 
131
161
  /**
132
162
  * Append a message to the conversation