@tanstack/ai-svelte 0.3.0 → 0.4.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/README.md CHANGED
@@ -65,8 +65,8 @@ This library uses Svelte 5 runes (`$state`) internally, providing a clean API wh
65
65
 
66
66
  ```svelte
67
67
  <script>
68
- const chat = createChat({ ... })
69
-
68
+ const chat = createChat({})
69
+
70
70
  // No $ needed - these are reactive getters!
71
71
  console.log(chat.messages)
72
72
  console.log(chat.isLoading)
@@ -37,6 +37,7 @@ export function createChat(options) {
37
37
  let messages = $state(options.initialMessages || []);
38
38
  let isLoading = $state(false);
39
39
  let error = $state(undefined);
40
+ let status = $state('ready');
40
41
  // Create ChatClient instance
41
42
  const client = new ChatClient({
42
43
  connection: options.connection,
@@ -45,8 +46,12 @@ export function createChat(options) {
45
46
  body: options.body,
46
47
  onResponse: options.onResponse,
47
48
  onChunk: options.onChunk,
48
- onFinish: options.onFinish,
49
- onError: options.onError,
49
+ onFinish: (message) => {
50
+ options.onFinish?.(message);
51
+ },
52
+ onError: (err) => {
53
+ options.onError?.(err);
54
+ },
50
55
  tools: options.tools,
51
56
  streamProcessor: options.streamProcessor,
52
57
  onMessagesChange: (newMessages) => {
@@ -55,6 +60,9 @@ export function createChat(options) {
55
60
  onLoadingChange: (newIsLoading) => {
56
61
  isLoading = newIsLoading;
57
62
  },
63
+ onStatusChange: (newStatus) => {
64
+ status = newStatus;
65
+ },
58
66
  onErrorChange: (newError) => {
59
67
  error = newError;
60
68
  },
@@ -103,6 +111,9 @@ export function createChat(options) {
103
111
  get error() {
104
112
  return error;
105
113
  },
114
+ get status() {
115
+ return status;
116
+ },
106
117
  sendMessage,
107
118
  append,
108
119
  reload,
package/dist/types.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { AnyClientTool, ModelMessage } from '@tanstack/ai';
2
- import type { ChatClientOptions, ChatRequestBody, UIMessage } from '@tanstack/ai-client';
3
- export type { UIMessage, ChatRequestBody };
2
+ import type { ChatClientOptions, ChatClientState, ChatRequestBody, UIMessage } from '@tanstack/ai-client';
3
+ export type { ChatRequestBody, UIMessage };
4
4
  /**
5
5
  * Options for the createChat function.
6
6
  *
@@ -9,6 +9,7 @@ export type { UIMessage, ChatRequestBody };
9
9
  * - `onMessagesChange` - Managed by Svelte state (exposed as `messages`)
10
10
  * - `onLoadingChange` - Managed by Svelte state (exposed as `isLoading`)
11
11
  * - `onErrorChange` - Managed by Svelte state (exposed as `error`)
12
+ * - `onStatusChange` - Managed by Svelte state (exposed as `status`)
12
13
  *
13
14
  * All other callbacks (onResponse, onChunk, onFinish, onError) are
14
15
  * passed through to the underlying ChatClient and can be used for side effects.
@@ -16,7 +17,7 @@ export type { UIMessage, ChatRequestBody };
16
17
  * Note: Connection and body changes will recreate the ChatClient instance.
17
18
  * To update these options, remount the component or use a key prop.
18
19
  */
19
- export type CreateChatOptions<TTools extends ReadonlyArray<AnyClientTool> = any> = Omit<ChatClientOptions<TTools>, 'onMessagesChange' | 'onLoadingChange' | 'onErrorChange'>;
20
+ export type CreateChatOptions<TTools extends ReadonlyArray<AnyClientTool> = any> = Omit<ChatClientOptions<TTools>, 'onMessagesChange' | 'onLoadingChange' | 'onErrorChange' | 'onStatusChange'>;
20
21
  export interface CreateChatReturn<TTools extends ReadonlyArray<AnyClientTool> = any> {
21
22
  /**
22
23
  * Current messages in the conversation (reactive getter)
@@ -71,6 +72,10 @@ export interface CreateChatReturn<TTools extends ReadonlyArray<AnyClientTool> =
71
72
  * Clear all messages
72
73
  */
73
74
  clear: () => void;
75
+ /**
76
+ * Current generation status (reactive getter)
77
+ */
78
+ readonly status: ChatClientState;
74
79
  /**
75
80
  * Update the body sent with requests (e.g., for changing model selection)
76
81
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/ai-svelte",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Svelte bindings for TanStack AI",
5
5
  "author": "",
6
6
  "license": "MIT",
@@ -33,11 +33,11 @@
33
33
  "streaming"
34
34
  ],
35
35
  "dependencies": {
36
- "@tanstack/ai-client": "0.3.0"
36
+ "@tanstack/ai-client": "0.4.0"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "svelte": "^5.0.0",
40
- "@tanstack/ai": "^0.3.0"
40
+ "@tanstack/ai": "^0.3.1"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@sveltejs/package": "^2.3.10",
@@ -49,7 +49,7 @@
49
49
  "svelte-check": "^4.2.0",
50
50
  "typescript": "5.9.3",
51
51
  "vite": "^7.2.7",
52
- "@tanstack/ai": "0.3.0"
52
+ "@tanstack/ai": "0.3.1"
53
53
  },
54
54
  "scripts": {
55
55
  "clean": "rm -rf ./dist",
@@ -1,4 +1,5 @@
1
1
  import { ChatClient } from '@tanstack/ai-client'
2
+ import type { ChatClientState } from '@tanstack/ai-client'
2
3
  import type { AnyClientTool, ModelMessage } from '@tanstack/ai'
3
4
  import type { CreateChatOptions, CreateChatReturn, UIMessage } from './types'
4
5
 
@@ -44,6 +45,7 @@ export function createChat<TTools extends ReadonlyArray<AnyClientTool> = any>(
44
45
  let messages = $state<Array<UIMessage<TTools>>>(options.initialMessages || [])
45
46
  let isLoading = $state(false)
46
47
  let error = $state<Error | undefined>(undefined)
48
+ let status = $state<ChatClientState>('ready')
47
49
 
48
50
  // Create ChatClient instance
49
51
  const client = new ChatClient({
@@ -53,8 +55,12 @@ export function createChat<TTools extends ReadonlyArray<AnyClientTool> = any>(
53
55
  body: options.body,
54
56
  onResponse: options.onResponse,
55
57
  onChunk: options.onChunk,
56
- onFinish: options.onFinish,
57
- onError: options.onError,
58
+ onFinish: (message) => {
59
+ options.onFinish?.(message)
60
+ },
61
+ onError: (err) => {
62
+ options.onError?.(err)
63
+ },
58
64
  tools: options.tools,
59
65
  streamProcessor: options.streamProcessor,
60
66
  onMessagesChange: (newMessages: Array<UIMessage<TTools>>) => {
@@ -63,6 +69,9 @@ export function createChat<TTools extends ReadonlyArray<AnyClientTool> = any>(
63
69
  onLoadingChange: (newIsLoading: boolean) => {
64
70
  isLoading = newIsLoading
65
71
  },
72
+ onStatusChange: (newStatus: ChatClientState) => {
73
+ status = newStatus
74
+ },
66
75
  onErrorChange: (newError: Error | undefined) => {
67
76
  error = newError
68
77
  },
@@ -131,6 +140,9 @@ export function createChat<TTools extends ReadonlyArray<AnyClientTool> = any>(
131
140
  get error() {
132
141
  return error
133
142
  },
143
+ get status() {
144
+ return status
145
+ },
134
146
  sendMessage,
135
147
  append,
136
148
  reload,
package/src/types.ts CHANGED
@@ -1,12 +1,13 @@
1
1
  import type { AnyClientTool, ModelMessage } from '@tanstack/ai'
2
2
  import type {
3
3
  ChatClientOptions,
4
+ ChatClientState,
4
5
  ChatRequestBody,
5
6
  UIMessage,
6
7
  } from '@tanstack/ai-client'
7
8
 
8
9
  // Re-export types from ai-client
9
- export type { UIMessage, ChatRequestBody }
10
+ export type { ChatRequestBody, UIMessage }
10
11
 
11
12
  /**
12
13
  * Options for the createChat function.
@@ -16,6 +17,7 @@ export type { UIMessage, ChatRequestBody }
16
17
  * - `onMessagesChange` - Managed by Svelte state (exposed as `messages`)
17
18
  * - `onLoadingChange` - Managed by Svelte state (exposed as `isLoading`)
18
19
  * - `onErrorChange` - Managed by Svelte state (exposed as `error`)
20
+ * - `onStatusChange` - Managed by Svelte state (exposed as `status`)
19
21
  *
20
22
  * All other callbacks (onResponse, onChunk, onFinish, onError) are
21
23
  * passed through to the underlying ChatClient and can be used for side effects.
@@ -27,7 +29,7 @@ export type CreateChatOptions<
27
29
  TTools extends ReadonlyArray<AnyClientTool> = any,
28
30
  > = Omit<
29
31
  ChatClientOptions<TTools>,
30
- 'onMessagesChange' | 'onLoadingChange' | 'onErrorChange'
32
+ 'onMessagesChange' | 'onLoadingChange' | 'onErrorChange' | 'onStatusChange'
31
33
  >
32
34
 
33
35
  export interface CreateChatReturn<
@@ -97,6 +99,10 @@ export interface CreateChatReturn<
97
99
  */
98
100
  clear: () => void
99
101
 
102
+ /**
103
+ * Current generation status (reactive getter)
104
+ */
105
+ readonly status: ChatClientState
100
106
  /**
101
107
  * Update the body sent with requests (e.g., for changing model selection)
102
108
  */