@ai-sdk/svelte 3.0.0-canary.20 → 3.0.0-canary.22
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/CHANGELOG.md +22 -0
- package/dist/chat.svelte.d.ts +4 -4
- package/dist/chat.svelte.d.ts.map +1 -1
- package/dist/chat.svelte.js +8 -13
- package/dist/completion.svelte.d.ts.map +1 -1
- package/dist/completion.svelte.js +0 -1
- package/package.json +3 -3
- package/src/chat.svelte.ts +17 -26
- package/src/completion.svelte.ts +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @ai-sdk/svelte
|
|
2
2
|
|
|
3
|
+
## 3.0.0-canary.22
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 40acf9b: feat (ui): introduce ChatStore and ChatTransport
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [40acf9b]
|
|
12
|
+
- @ai-sdk/provider-utils@3.0.0-canary.18
|
|
13
|
+
- ai@5.0.0-canary.23
|
|
14
|
+
|
|
15
|
+
## 3.0.0-canary.21
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [e7dc6c7]
|
|
20
|
+
- Updated dependencies [a34eb39]
|
|
21
|
+
- Updated dependencies [b33ed7a]
|
|
22
|
+
- Updated dependencies [765f1cd]
|
|
23
|
+
- ai@5.0.0-canary.22
|
|
24
|
+
|
|
3
25
|
## 3.0.0-canary.20
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
package/dist/chat.svelte.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type ChatRequestOptions, type CreateUIMessage, type
|
|
2
|
-
export type ChatOptions<MESSAGE_METADATA = unknown> = Readonly<
|
|
1
|
+
import { type ChatRequestOptions, type CreateUIMessage, type OriginalUseChatOptions, type UIMessage } from 'ai';
|
|
2
|
+
export type ChatOptions<MESSAGE_METADATA = unknown> = Readonly<OriginalUseChatOptions<MESSAGE_METADATA>>;
|
|
3
3
|
export type { CreateUIMessage, UIMessage };
|
|
4
4
|
export declare class Chat<MESSAGE_METADATA = unknown> {
|
|
5
5
|
#private;
|
|
@@ -36,13 +36,13 @@ export declare class Chat<MESSAGE_METADATA = unknown> {
|
|
|
36
36
|
* @param message The message to append
|
|
37
37
|
* @param options Additional options to pass to the API call
|
|
38
38
|
*/
|
|
39
|
-
append: (message: UIMessage<MESSAGE_METADATA> | CreateUIMessage<MESSAGE_METADATA>, {
|
|
39
|
+
append: (message: UIMessage<MESSAGE_METADATA> | CreateUIMessage<MESSAGE_METADATA>, { headers, body }?: ChatRequestOptions) => Promise<void>;
|
|
40
40
|
/**
|
|
41
41
|
* Reload the last AI chat response for the given chat history. If the last
|
|
42
42
|
* message isn't from the assistant, it will request the API to generate a
|
|
43
43
|
* new response.
|
|
44
44
|
*/
|
|
45
|
-
reload: ({
|
|
45
|
+
reload: ({ headers, body }?: ChatRequestOptions) => Promise<void>;
|
|
46
46
|
/**
|
|
47
47
|
* Abort the current request immediately, keep the generated tokens if any.
|
|
48
48
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.svelte.d.ts","sourceRoot":"","sources":["../src/chat.svelte.ts"],"names":[],"mappings":"AACA,OAAO,EASL,KAAK,kBAAkB,EACvB,KAAK,eAAe,
|
|
1
|
+
{"version":3,"file":"chat.svelte.d.ts","sourceRoot":"","sources":["../src/chat.svelte.ts"],"names":[],"mappings":"AACA,OAAO,EASL,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,SAAS,EACf,MAAM,IAAI,CAAC;AAQZ,MAAM,MAAM,WAAW,CAAC,gBAAgB,GAAG,OAAO,IAAI,QAAQ,CAC5D,sBAAsB,CAAC,gBAAgB,CAAC,CACzC,CAAC;AAEF,YAAY,EAAE,eAAe,EAAE,SAAS,EAAE,CAAC;AAE3C,qBAAa,IAAI,CAAC,gBAAgB,GAAG,OAAO;;IAS1C;;;OAGG;IACH,QAAQ,CAAC,EAAE,SAAoD;IAS/D;;;;;;;OAOG;IACH,IAAI,MAAM,kDAET;IAED,0CAA0C;IAC1C,IAAI,KAAK,sBAER;IAED,mFAAmF;IACnF,KAAK,SAAqB;IAE1B;;;;;OAKG;IACH,IAAI,QAAQ,IAAI,SAAS,CAAC,gBAAgB,CAAC,EAAE,CAE5C;IACD,IAAI,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,gBAAgB,CAAC,EAAE,EAEhD;gBAEW,OAAO,GAAE,WAAW,CAAC,gBAAgB,CAAM;IAYvD;;;;;OAKG;IACH,MAAM,YACK,SAAS,CAAC,gBAAgB,CAAC,GAAG,eAAe,CAAC,gBAAgB,CAAC,sBACrD,kBAAkB,mBAQrC;IAEF;;;;OAIG;IACH,MAAM,uBAA6B,kBAAkB,mBAcnD;IAEF;;OAEG;IACH,IAAI,aASF;IAEF,qFAAqF;IACrF,YAAY,WACF;QAAE,cAAc,CAAC,EAAE,MAAM,IAAI,CAAA;KAAE,YAC9B,kBAAkB,GAAG;QAAE,KAAK,CAAC,EAAE,QAAQ,CAAA;KAAE,mBAwBlD;IAEF,aAAa,4BAGV;QACD,UAAU,EAAE,MAAM,CAAC;QACnB,MAAM,EAAE,OAAO,CAAC;KACjB,mBAmBC;CA4FH"}
|
package/dist/chat.svelte.js
CHANGED
|
@@ -7,7 +7,7 @@ export class Chat {
|
|
|
7
7
|
#api = $derived(this.#options.api ?? '/api/chat');
|
|
8
8
|
#generateId = $derived(this.#options.generateId ?? generateId);
|
|
9
9
|
#maxSteps = $derived(this.#options.maxSteps ?? 1);
|
|
10
|
-
#streamProtocol = $derived(this.#options.streamProtocol ?? '
|
|
10
|
+
#streamProtocol = $derived(this.#options.streamProtocol ?? 'ui-message');
|
|
11
11
|
#keyedStore = $state();
|
|
12
12
|
/**
|
|
13
13
|
* The id of the chat. If not provided through the constructor, a random ID will be generated
|
|
@@ -63,19 +63,19 @@ export class Chat {
|
|
|
63
63
|
* @param message The message to append
|
|
64
64
|
* @param options Additional options to pass to the API call
|
|
65
65
|
*/
|
|
66
|
-
append = async (message, {
|
|
66
|
+
append = async (message, { headers, body } = {}) => {
|
|
67
67
|
const messages = this.messages.concat({
|
|
68
68
|
...message,
|
|
69
69
|
id: message.id ?? this.#generateId(),
|
|
70
70
|
});
|
|
71
|
-
return this.#triggerRequest({ messages, headers, body
|
|
71
|
+
return this.#triggerRequest({ messages, headers, body });
|
|
72
72
|
};
|
|
73
73
|
/**
|
|
74
74
|
* Reload the last AI chat response for the given chat history. If the last
|
|
75
75
|
* message isn't from the assistant, it will request the API to generate a
|
|
76
76
|
* new response.
|
|
77
77
|
*/
|
|
78
|
-
reload = async ({
|
|
78
|
+
reload = async ({ headers, body } = {}) => {
|
|
79
79
|
if (this.messages.length === 0) {
|
|
80
80
|
return;
|
|
81
81
|
}
|
|
@@ -86,7 +86,6 @@ export class Chat {
|
|
|
86
86
|
: this.messages,
|
|
87
87
|
headers,
|
|
88
88
|
body,
|
|
89
|
-
data,
|
|
90
89
|
});
|
|
91
90
|
};
|
|
92
91
|
/**
|
|
@@ -107,23 +106,21 @@ export class Chat {
|
|
|
107
106
|
/** Form submission handler to automatically reset input and append a user message */
|
|
108
107
|
handleSubmit = async (event, options = {}) => {
|
|
109
108
|
event?.preventDefault?.();
|
|
110
|
-
if (!this.input && !options.allowEmptySubmit)
|
|
111
|
-
return;
|
|
112
109
|
const fileParts = Array.isArray(options?.files)
|
|
113
110
|
? options.files
|
|
114
111
|
: await convertFileListToFileUIParts(options?.files);
|
|
112
|
+
if (!this.input && fileParts.length === 0)
|
|
113
|
+
return;
|
|
115
114
|
const messages = this.messages.concat({
|
|
116
115
|
id: this.#generateId(),
|
|
117
116
|
role: 'user',
|
|
118
117
|
parts: [...fileParts, { type: 'text', text: this.input }],
|
|
119
118
|
});
|
|
120
|
-
const
|
|
119
|
+
const request = this.#triggerRequest({
|
|
121
120
|
messages,
|
|
122
121
|
headers: options.headers,
|
|
123
122
|
body: options.body,
|
|
124
|
-
|
|
125
|
-
};
|
|
126
|
-
const request = this.#triggerRequest(chatRequest);
|
|
123
|
+
});
|
|
127
124
|
this.input = '';
|
|
128
125
|
await request;
|
|
129
126
|
};
|
|
@@ -159,7 +156,6 @@ export class Chat {
|
|
|
159
156
|
body: {
|
|
160
157
|
id: this.id,
|
|
161
158
|
messages,
|
|
162
|
-
data: chatRequest.data,
|
|
163
159
|
...$state.snapshot(this.#options.body),
|
|
164
160
|
...chatRequest.body,
|
|
165
161
|
},
|
|
@@ -170,7 +166,6 @@ export class Chat {
|
|
|
170
166
|
...chatRequest.headers,
|
|
171
167
|
},
|
|
172
168
|
abortController: () => abortController,
|
|
173
|
-
onResponse: this.#options.onResponse,
|
|
174
169
|
onUpdate: ({ message }) => {
|
|
175
170
|
this.#store.status = 'streaming';
|
|
176
171
|
const replaceLastMessage = message.id === messages[messages.length - 1].id;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"completion.svelte.d.ts","sourceRoot":"","sources":["../src/completion.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,EAC1B,MAAM,IAAI,CAAC;AAOZ,MAAM,MAAM,iBAAiB,GAAG,QAAQ,CAAC,oBAAoB,CAAC,CAAC;AAE/D,qBAAa,UAAU;;IASrB,oCAAoC;IACpC,IAAI,UAAU,IAAI,MAAM,CAEvB;IACD,IAAI,UAAU,CAAC,KAAK,EAAE,MAAM,EAE3B;IAED,0CAA0C;IAC1C,IAAI,KAAK,sBAER;IAED,mFAAmF;IACnF,KAAK,SAAqB;IAE1B;;OAEG;IACH,IAAI,OAAO,YAEV;gBAEW,OAAO,GAAE,iBAAsB;IAS3C;;OAEG;IACH,IAAI,aASF;IAEF;;OAEG;IACH,QAAQ,WAAkB,MAAM,YAAY,wBAAwB,wCAC5B;IAExC,uFAAuF;IACvF,YAAY,WAAkB;QAAE,cAAc,CAAC,EAAE,MAAM,IAAI,CAAA;KAAE,mBAK3D;
|
|
1
|
+
{"version":3,"file":"completion.svelte.d.ts","sourceRoot":"","sources":["../src/completion.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,EAC1B,MAAM,IAAI,CAAC;AAOZ,MAAM,MAAM,iBAAiB,GAAG,QAAQ,CAAC,oBAAoB,CAAC,CAAC;AAE/D,qBAAa,UAAU;;IASrB,oCAAoC;IACpC,IAAI,UAAU,IAAI,MAAM,CAEvB;IACD,IAAI,UAAU,CAAC,KAAK,EAAE,MAAM,EAE3B;IAED,0CAA0C;IAC1C,IAAI,KAAK,sBAER;IAED,mFAAmF;IACnF,KAAK,SAAqB;IAE1B;;OAEG;IACH,IAAI,OAAO,YAEV;gBAEW,OAAO,GAAE,iBAAsB;IAS3C;;OAEG;IACH,IAAI,aASF;IAEF;;OAEG;IACH,QAAQ,WAAkB,MAAM,YAAY,wBAAwB,wCAC5B;IAExC,uFAAuF;IACvF,YAAY,WAAkB;QAAE,cAAc,CAAC,EAAE,MAAM,IAAI,CAAA;KAAE,mBAK3D;CAkCH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/svelte",
|
|
3
|
-
"version": "3.0.0-canary.
|
|
3
|
+
"version": "3.0.0-canary.22",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"ai": "
|
|
40
|
-
"
|
|
39
|
+
"@ai-sdk/provider-utils": "3.0.0-canary.18",
|
|
40
|
+
"ai": "5.0.0-canary.23"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/node": "20.17.24",
|
package/src/chat.svelte.ts
CHANGED
|
@@ -10,9 +10,8 @@ import {
|
|
|
10
10
|
updateToolCallResult,
|
|
11
11
|
type ChatRequestOptions,
|
|
12
12
|
type CreateUIMessage,
|
|
13
|
-
type
|
|
13
|
+
type OriginalUseChatOptions,
|
|
14
14
|
type UIMessage,
|
|
15
|
-
type UseChatOptions,
|
|
16
15
|
} from 'ai';
|
|
17
16
|
import { untrack } from 'svelte';
|
|
18
17
|
import {
|
|
@@ -22,7 +21,7 @@ import {
|
|
|
22
21
|
} from './chat-context.svelte.js';
|
|
23
22
|
|
|
24
23
|
export type ChatOptions<MESSAGE_METADATA = unknown> = Readonly<
|
|
25
|
-
|
|
24
|
+
OriginalUseChatOptions<MESSAGE_METADATA>
|
|
26
25
|
>;
|
|
27
26
|
|
|
28
27
|
export type { CreateUIMessage, UIMessage };
|
|
@@ -32,7 +31,9 @@ export class Chat<MESSAGE_METADATA = unknown> {
|
|
|
32
31
|
readonly #api = $derived(this.#options.api ?? '/api/chat');
|
|
33
32
|
readonly #generateId = $derived(this.#options.generateId ?? generateId);
|
|
34
33
|
readonly #maxSteps = $derived(this.#options.maxSteps ?? 1);
|
|
35
|
-
readonly #streamProtocol = $derived(
|
|
34
|
+
readonly #streamProtocol = $derived(
|
|
35
|
+
this.#options.streamProtocol ?? 'ui-message',
|
|
36
|
+
);
|
|
36
37
|
readonly #keyedStore = $state<KeyedChatStore<MESSAGE_METADATA>>()!;
|
|
37
38
|
/**
|
|
38
39
|
* The id of the chat. If not provided through the constructor, a random ID will be generated
|
|
@@ -100,14 +101,14 @@ export class Chat<MESSAGE_METADATA = unknown> {
|
|
|
100
101
|
*/
|
|
101
102
|
append = async (
|
|
102
103
|
message: UIMessage<MESSAGE_METADATA> | CreateUIMessage<MESSAGE_METADATA>,
|
|
103
|
-
{
|
|
104
|
+
{ headers, body }: ChatRequestOptions = {},
|
|
104
105
|
) => {
|
|
105
106
|
const messages = this.messages.concat({
|
|
106
107
|
...message,
|
|
107
108
|
id: message.id ?? this.#generateId(),
|
|
108
109
|
});
|
|
109
110
|
|
|
110
|
-
return this.#triggerRequest({ messages, headers, body
|
|
111
|
+
return this.#triggerRequest({ messages, headers, body });
|
|
111
112
|
};
|
|
112
113
|
|
|
113
114
|
/**
|
|
@@ -115,7 +116,7 @@ export class Chat<MESSAGE_METADATA = unknown> {
|
|
|
115
116
|
* message isn't from the assistant, it will request the API to generate a
|
|
116
117
|
* new response.
|
|
117
118
|
*/
|
|
118
|
-
reload = async ({
|
|
119
|
+
reload = async ({ headers, body }: ChatRequestOptions = {}) => {
|
|
119
120
|
if (this.messages.length === 0) {
|
|
120
121
|
return;
|
|
121
122
|
}
|
|
@@ -128,7 +129,6 @@ export class Chat<MESSAGE_METADATA = unknown> {
|
|
|
128
129
|
: this.messages,
|
|
129
130
|
headers,
|
|
130
131
|
body,
|
|
131
|
-
data,
|
|
132
132
|
});
|
|
133
133
|
};
|
|
134
134
|
|
|
@@ -152,31 +152,25 @@ export class Chat<MESSAGE_METADATA = unknown> {
|
|
|
152
152
|
options: ChatRequestOptions & { files?: FileList } = {},
|
|
153
153
|
) => {
|
|
154
154
|
event?.preventDefault?.();
|
|
155
|
-
if (!this.input && !options.allowEmptySubmit) return;
|
|
156
155
|
|
|
157
156
|
const fileParts = Array.isArray(options?.files)
|
|
158
157
|
? options.files
|
|
159
158
|
: await convertFileListToFileUIParts(options?.files);
|
|
160
159
|
|
|
160
|
+
if (!this.input && fileParts.length === 0) return;
|
|
161
|
+
|
|
161
162
|
const messages = this.messages.concat({
|
|
162
163
|
id: this.#generateId(),
|
|
163
164
|
role: 'user',
|
|
164
165
|
parts: [...fileParts, { type: 'text', text: this.input }],
|
|
165
166
|
});
|
|
166
167
|
|
|
167
|
-
const
|
|
168
|
-
headers?: Record<string, string> | Headers;
|
|
169
|
-
body?: object;
|
|
170
|
-
messages: UIMessage<MESSAGE_METADATA>[];
|
|
171
|
-
data?: JSONValue;
|
|
172
|
-
} = {
|
|
168
|
+
const request = this.#triggerRequest({
|
|
173
169
|
messages,
|
|
174
170
|
headers: options.headers,
|
|
175
171
|
body: options.body,
|
|
176
|
-
|
|
177
|
-
};
|
|
172
|
+
});
|
|
178
173
|
|
|
179
|
-
const request = this.#triggerRequest(chatRequest);
|
|
180
174
|
this.input = '';
|
|
181
175
|
await request;
|
|
182
176
|
};
|
|
@@ -208,12 +202,11 @@ export class Chat<MESSAGE_METADATA = unknown> {
|
|
|
208
202
|
}
|
|
209
203
|
};
|
|
210
204
|
|
|
211
|
-
#triggerRequest = async (
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}) => {
|
|
205
|
+
#triggerRequest = async (
|
|
206
|
+
chatRequest: ChatRequestOptions & {
|
|
207
|
+
messages: UIMessage<MESSAGE_METADATA>[];
|
|
208
|
+
},
|
|
209
|
+
) => {
|
|
217
210
|
this.#store.status = 'submitted';
|
|
218
211
|
this.#store.error = undefined;
|
|
219
212
|
|
|
@@ -235,7 +228,6 @@ export class Chat<MESSAGE_METADATA = unknown> {
|
|
|
235
228
|
body: {
|
|
236
229
|
id: this.id,
|
|
237
230
|
messages,
|
|
238
|
-
data: chatRequest.data,
|
|
239
231
|
...$state.snapshot(this.#options.body),
|
|
240
232
|
...chatRequest.body,
|
|
241
233
|
},
|
|
@@ -246,7 +238,6 @@ export class Chat<MESSAGE_METADATA = unknown> {
|
|
|
246
238
|
...chatRequest.headers,
|
|
247
239
|
},
|
|
248
240
|
abortController: () => abortController,
|
|
249
|
-
onResponse: this.#options.onResponse,
|
|
250
241
|
onUpdate: ({ message }) => {
|
|
251
242
|
this.#store.status = 'streaming';
|
|
252
243
|
|
package/src/completion.svelte.ts
CHANGED
|
@@ -109,7 +109,6 @@ export class Completion {
|
|
|
109
109
|
setAbortController: abortController => {
|
|
110
110
|
this.#abortController = abortController ?? undefined;
|
|
111
111
|
},
|
|
112
|
-
onResponse: this.#options.onResponse,
|
|
113
112
|
onFinish: this.#options.onFinish,
|
|
114
113
|
onError: this.#options.onError,
|
|
115
114
|
});
|