@tanstack/ai-svelte 0.21.0 → 0.22.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/dist/create-chat.svelte.js +25 -5
- package/dist/types.d.ts +9 -0
- package/package.json +4 -4
- package/src/create-chat.svelte.ts +26 -5
- package/src/types.ts +11 -0
|
@@ -37,6 +37,7 @@ export function createChat(options) {
|
|
|
37
37
|
// Create reactive state using Svelte 5 runes
|
|
38
38
|
let messages = $state(options.initialMessages || []);
|
|
39
39
|
let isLoading = $state(false);
|
|
40
|
+
let hasOlderMessages = $state(false);
|
|
40
41
|
let error = $state(undefined);
|
|
41
42
|
let status = $state('ready');
|
|
42
43
|
let isSubscribed = $state(false);
|
|
@@ -72,14 +73,24 @@ export function createChat(options) {
|
|
|
72
73
|
...(options.initialMessages !== undefined && {
|
|
73
74
|
initialMessages: options.initialMessages,
|
|
74
75
|
}),
|
|
75
|
-
...(typeof options.threadId === 'string' && options.persistence
|
|
76
|
+
...(typeof options.threadId === 'string' && options.persistence === true
|
|
76
77
|
? {
|
|
77
|
-
persistence:
|
|
78
|
+
persistence: true,
|
|
78
79
|
threadId: options.threadId,
|
|
80
|
+
...(options.history !== undefined && {
|
|
81
|
+
history: options.history,
|
|
82
|
+
}),
|
|
79
83
|
}
|
|
80
|
-
:
|
|
81
|
-
|
|
82
|
-
|
|
84
|
+
: typeof options.threadId === 'string' && options.persistence
|
|
85
|
+
? {
|
|
86
|
+
persistence: options.persistence,
|
|
87
|
+
threadId: options.threadId,
|
|
88
|
+
}
|
|
89
|
+
: {
|
|
90
|
+
...(options.threadId !== undefined && {
|
|
91
|
+
threadId: options.threadId,
|
|
92
|
+
}),
|
|
93
|
+
}),
|
|
83
94
|
...(options.initialResumeSnapshot !== undefined && {
|
|
84
95
|
initialResumeSnapshot: options.initialResumeSnapshot,
|
|
85
96
|
}),
|
|
@@ -118,6 +129,7 @@ export function createChat(options) {
|
|
|
118
129
|
}),
|
|
119
130
|
onMessagesChange: (newMessages) => {
|
|
120
131
|
messages = newMessages;
|
|
132
|
+
hasOlderMessages = client.getHasOlderMessages();
|
|
121
133
|
},
|
|
122
134
|
onLoadingChange: (newIsLoading) => {
|
|
123
135
|
isLoading = newIsLoading;
|
|
@@ -215,6 +227,10 @@ export function createChat(options) {
|
|
|
215
227
|
syncResumeState();
|
|
216
228
|
}
|
|
217
229
|
};
|
|
230
|
+
const loadOlderMessages = async () => {
|
|
231
|
+
await client.loadOlderMessages();
|
|
232
|
+
hasOlderMessages = client.getHasOlderMessages();
|
|
233
|
+
};
|
|
218
234
|
const stop = () => {
|
|
219
235
|
client.stop();
|
|
220
236
|
};
|
|
@@ -313,6 +329,9 @@ export function createChat(options) {
|
|
|
313
329
|
get isLoading() {
|
|
314
330
|
return isLoading;
|
|
315
331
|
},
|
|
332
|
+
get hasOlderMessages() {
|
|
333
|
+
return hasOlderMessages;
|
|
334
|
+
},
|
|
316
335
|
get error() {
|
|
317
336
|
return error;
|
|
318
337
|
},
|
|
@@ -356,6 +375,7 @@ export function createChat(options) {
|
|
|
356
375
|
cancelQueued,
|
|
357
376
|
append,
|
|
358
377
|
reload,
|
|
378
|
+
loadOlderMessages,
|
|
359
379
|
stop,
|
|
360
380
|
dispose,
|
|
361
381
|
setMessages,
|
package/dist/types.d.ts
CHANGED
|
@@ -144,6 +144,15 @@ interface BaseCreateChatReturn<TTools extends ReadonlyArray<AnyClientTool> = any
|
|
|
144
144
|
* Whether a response is currently being generated (reactive getter)
|
|
145
145
|
*/
|
|
146
146
|
readonly isLoading: boolean;
|
|
147
|
+
/**
|
|
148
|
+
* True when the last hydrate or older-page response said more messages exist
|
|
149
|
+
* (reactive getter).
|
|
150
|
+
*/
|
|
151
|
+
readonly hasOlderMessages: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Fetch the next older window and put it in front of the painted messages.
|
|
154
|
+
*/
|
|
155
|
+
loadOlderMessages: () => Promise<void>;
|
|
147
156
|
/**
|
|
148
157
|
* Current error, if any (reactive getter)
|
|
149
158
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/ai-svelte",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.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",
|
|
@@ -51,11 +51,11 @@
|
|
|
51
51
|
"media-generation"
|
|
52
52
|
],
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@tanstack/ai-client": "^0.
|
|
54
|
+
"@tanstack/ai-client": "^0.32.0"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
57
|
"svelte": "^5.0.0",
|
|
58
|
-
"@tanstack/ai": "^0.
|
|
58
|
+
"@tanstack/ai": "^0.55.0"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@standard-schema/spec": "^1.1.0",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"svelte-check": "^4.2.0",
|
|
69
69
|
"typescript": "5.9.3",
|
|
70
70
|
"vite": "^8.2.1",
|
|
71
|
-
"@tanstack/ai": "0.
|
|
71
|
+
"@tanstack/ai": "0.55.0"
|
|
72
72
|
},
|
|
73
73
|
"scripts": {
|
|
74
74
|
"clean": "rm -rf ./dist",
|
|
@@ -75,6 +75,7 @@ export function createChat<
|
|
|
75
75
|
// Create reactive state using Svelte 5 runes
|
|
76
76
|
let messages = $state<Array<UIMessage<TTools>>>(options.initialMessages || [])
|
|
77
77
|
let isLoading = $state(false)
|
|
78
|
+
let hasOlderMessages = $state(false)
|
|
78
79
|
let error = $state<Error | undefined>(undefined)
|
|
79
80
|
let status = $state<ChatClientState>('ready')
|
|
80
81
|
let isSubscribed = $state(false)
|
|
@@ -119,14 +120,24 @@ export function createChat<
|
|
|
119
120
|
...(options.initialMessages !== undefined && {
|
|
120
121
|
initialMessages: options.initialMessages,
|
|
121
122
|
}),
|
|
122
|
-
...(typeof options.threadId === 'string' && options.persistence
|
|
123
|
+
...(typeof options.threadId === 'string' && options.persistence === true
|
|
123
124
|
? {
|
|
124
|
-
persistence:
|
|
125
|
+
persistence: true,
|
|
125
126
|
threadId: options.threadId,
|
|
127
|
+
...(options.history !== undefined && {
|
|
128
|
+
history: options.history,
|
|
129
|
+
}),
|
|
126
130
|
}
|
|
127
|
-
:
|
|
128
|
-
|
|
129
|
-
|
|
131
|
+
: typeof options.threadId === 'string' && options.persistence
|
|
132
|
+
? {
|
|
133
|
+
persistence: options.persistence,
|
|
134
|
+
threadId: options.threadId,
|
|
135
|
+
}
|
|
136
|
+
: {
|
|
137
|
+
...(options.threadId !== undefined && {
|
|
138
|
+
threadId: options.threadId,
|
|
139
|
+
}),
|
|
140
|
+
}),
|
|
130
141
|
...(options.initialResumeSnapshot !== undefined && {
|
|
131
142
|
initialResumeSnapshot: options.initialResumeSnapshot,
|
|
132
143
|
}),
|
|
@@ -165,6 +176,7 @@ export function createChat<
|
|
|
165
176
|
}),
|
|
166
177
|
onMessagesChange: (newMessages: Array<UIMessage<TTools>>) => {
|
|
167
178
|
messages = newMessages
|
|
179
|
+
hasOlderMessages = client.getHasOlderMessages()
|
|
168
180
|
},
|
|
169
181
|
onLoadingChange: (newIsLoading: boolean) => {
|
|
170
182
|
isLoading = newIsLoading
|
|
@@ -272,6 +284,11 @@ export function createChat<
|
|
|
272
284
|
}
|
|
273
285
|
}
|
|
274
286
|
|
|
287
|
+
const loadOlderMessages = async () => {
|
|
288
|
+
await client.loadOlderMessages()
|
|
289
|
+
hasOlderMessages = client.getHasOlderMessages()
|
|
290
|
+
}
|
|
291
|
+
|
|
275
292
|
const stop = () => {
|
|
276
293
|
client.stop()
|
|
277
294
|
}
|
|
@@ -407,6 +424,9 @@ export function createChat<
|
|
|
407
424
|
get isLoading() {
|
|
408
425
|
return isLoading
|
|
409
426
|
},
|
|
427
|
+
get hasOlderMessages() {
|
|
428
|
+
return hasOlderMessages
|
|
429
|
+
},
|
|
410
430
|
get error() {
|
|
411
431
|
return error
|
|
412
432
|
},
|
|
@@ -450,6 +470,7 @@ export function createChat<
|
|
|
450
470
|
cancelQueued,
|
|
451
471
|
append,
|
|
452
472
|
reload,
|
|
473
|
+
loadOlderMessages,
|
|
453
474
|
stop,
|
|
454
475
|
dispose,
|
|
455
476
|
setMessages,
|
package/src/types.ts
CHANGED
|
@@ -259,6 +259,17 @@ interface BaseCreateChatReturn<
|
|
|
259
259
|
*/
|
|
260
260
|
readonly isLoading: boolean
|
|
261
261
|
|
|
262
|
+
/**
|
|
263
|
+
* True when the last hydrate or older-page response said more messages exist
|
|
264
|
+
* (reactive getter).
|
|
265
|
+
*/
|
|
266
|
+
readonly hasOlderMessages: boolean
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Fetch the next older window and put it in front of the painted messages.
|
|
270
|
+
*/
|
|
271
|
+
loadOlderMessages: () => Promise<void>
|
|
272
|
+
|
|
262
273
|
/**
|
|
263
274
|
* Current error, if any (reactive getter)
|
|
264
275
|
*/
|