@ai-sdk/svelte 3.0.0-alpha.9 → 3.0.0-beta.1
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 +93 -0
- package/dist/chat.svelte.d.ts +3 -17
- package/dist/chat.svelte.d.ts.map +1 -1
- package/dist/chat.svelte.js +1 -23
- package/package.json +3 -3
- package/src/chat.svelte.ts +11 -63
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,98 @@
|
|
|
1
1
|
# @ai-sdk/svelte
|
|
2
2
|
|
|
3
|
+
## 3.0.0-beta.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [d88455d]
|
|
8
|
+
- Updated dependencies [45c1ea2]
|
|
9
|
+
- Updated dependencies [9ad0484]
|
|
10
|
+
- Updated dependencies [e025824]
|
|
11
|
+
- Updated dependencies [4048ce3]
|
|
12
|
+
- Updated dependencies [f2b041e]
|
|
13
|
+
- Updated dependencies [cb68df0]
|
|
14
|
+
- Updated dependencies [26695a3]
|
|
15
|
+
- Updated dependencies [bfdca8d]
|
|
16
|
+
- Updated dependencies [e7d2ce3]
|
|
17
|
+
- Updated dependencies [102b066]
|
|
18
|
+
- Updated dependencies [71f938d]
|
|
19
|
+
- Updated dependencies [28a5ed5]
|
|
20
|
+
- Updated dependencies [e862b5b]
|
|
21
|
+
- Updated dependencies [7bd025b]
|
|
22
|
+
- ai@5.0.0-beta.1
|
|
23
|
+
- @ai-sdk/provider-utils@3.0.0-beta.1
|
|
24
|
+
|
|
25
|
+
## 3.0.0-alpha.15
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- Updated dependencies [b1e3abd]
|
|
30
|
+
- Updated dependencies [8ba77a7]
|
|
31
|
+
- Updated dependencies [04d5063]
|
|
32
|
+
- Updated dependencies [b4b4bb2]
|
|
33
|
+
- Updated dependencies [d884051]
|
|
34
|
+
- Updated dependencies [954aa73]
|
|
35
|
+
- Updated dependencies [142576e]
|
|
36
|
+
- Updated dependencies [395c85e]
|
|
37
|
+
- Updated dependencies [60e2c56]
|
|
38
|
+
- ai@5.0.0-alpha.15
|
|
39
|
+
- @ai-sdk/provider-utils@3.0.0-alpha.15
|
|
40
|
+
|
|
41
|
+
## 3.0.0-alpha.14
|
|
42
|
+
|
|
43
|
+
### Patch Changes
|
|
44
|
+
|
|
45
|
+
- Updated dependencies [63f9e9b]
|
|
46
|
+
- ai@5.0.0-alpha.14
|
|
47
|
+
- @ai-sdk/provider-utils@3.0.0-alpha.14
|
|
48
|
+
|
|
49
|
+
## 3.0.0-alpha.13
|
|
50
|
+
|
|
51
|
+
### Major Changes
|
|
52
|
+
|
|
53
|
+
- 0a710d8: feat (ui): typed tool parts in ui messages
|
|
54
|
+
- 901df02: feat (ui): use UI_MESSAGE generic
|
|
55
|
+
|
|
56
|
+
### Patch Changes
|
|
57
|
+
|
|
58
|
+
- Updated dependencies [0a710d8]
|
|
59
|
+
- Updated dependencies [6a83f7d]
|
|
60
|
+
- Updated dependencies [1f55c21]
|
|
61
|
+
- Updated dependencies [33eb499]
|
|
62
|
+
- Updated dependencies [901df02]
|
|
63
|
+
- ai@5.0.0-alpha.13
|
|
64
|
+
- @ai-sdk/provider-utils@3.0.0-alpha.13
|
|
65
|
+
|
|
66
|
+
## 3.0.0-alpha.12
|
|
67
|
+
|
|
68
|
+
### Patch Changes
|
|
69
|
+
|
|
70
|
+
- Updated dependencies [da1e6f0]
|
|
71
|
+
- Updated dependencies [4892798]
|
|
72
|
+
- ai@5.0.0-alpha.12
|
|
73
|
+
- @ai-sdk/provider-utils@3.0.0-alpha.12
|
|
74
|
+
|
|
75
|
+
## 3.0.0-alpha.11
|
|
76
|
+
|
|
77
|
+
### Patch Changes
|
|
78
|
+
|
|
79
|
+
- Updated dependencies [e8324c5]
|
|
80
|
+
- ai@5.0.0-alpha.11
|
|
81
|
+
- @ai-sdk/provider-utils@3.0.0-alpha.11
|
|
82
|
+
|
|
83
|
+
## 3.0.0-alpha.10
|
|
84
|
+
|
|
85
|
+
### Major Changes
|
|
86
|
+
|
|
87
|
+
- 98f25e5: chore (ui): remove managed chat inputs
|
|
88
|
+
|
|
89
|
+
### Patch Changes
|
|
90
|
+
|
|
91
|
+
- Updated dependencies [98f25e5]
|
|
92
|
+
- Updated dependencies [7bb58d4]
|
|
93
|
+
- ai@5.0.0-alpha.10
|
|
94
|
+
- @ai-sdk/provider-utils@3.0.0-alpha.10
|
|
95
|
+
|
|
3
96
|
## 3.0.0-alpha.9
|
|
4
97
|
|
|
5
98
|
### Patch Changes
|
package/dist/chat.svelte.d.ts
CHANGED
|
@@ -1,20 +1,6 @@
|
|
|
1
|
-
import { AbstractChat, type
|
|
2
|
-
export type ChatInit<MESSAGE_METADATA = unknown, DATA_PART_SCHEMAS extends UIDataPartSchemas = UIDataPartSchemas> = Readonly<BaseChatInit<MESSAGE_METADATA, DATA_PART_SCHEMAS>> & {
|
|
3
|
-
/**
|
|
4
|
-
* Initial input of the chat.
|
|
5
|
-
*/
|
|
6
|
-
initialInput?: string;
|
|
7
|
-
};
|
|
1
|
+
import { AbstractChat, type ChatInit, type CreateUIMessage, type UIMessage } from 'ai';
|
|
8
2
|
export type { CreateUIMessage, UIMessage };
|
|
9
|
-
export declare class Chat<
|
|
10
|
-
|
|
11
|
-
input: string;
|
|
12
|
-
constructor(init: ChatInit<MESSAGE_METADATA, DATA_PART_SCHEMAS>);
|
|
13
|
-
/** Form submission handler to automatically reset input and append a user message */
|
|
14
|
-
handleSubmit: (event?: {
|
|
15
|
-
preventDefault?: () => void;
|
|
16
|
-
}, options?: ChatRequestOptions & {
|
|
17
|
-
files?: FileList;
|
|
18
|
-
}) => Promise<void>;
|
|
3
|
+
export declare class Chat<UI_MESSAGE extends UIMessage = UIMessage> extends AbstractChat<UI_MESSAGE> {
|
|
4
|
+
constructor(init: ChatInit<UI_MESSAGE>);
|
|
19
5
|
}
|
|
20
6
|
//# sourceMappingURL=chat.svelte.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.svelte.d.ts","sourceRoot":"","sources":["../src/chat.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,KAAK,
|
|
1
|
+
{"version":3,"file":"chat.svelte.d.ts","sourceRoot":"","sources":["../src/chat.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,KAAK,QAAQ,EAGb,KAAK,eAAe,EACpB,KAAK,SAAS,EACf,MAAM,IAAI,CAAC;AAEZ,YAAY,EAAE,eAAe,EAAE,SAAS,EAAE,CAAC;AAE3C,qBAAa,IAAI,CACf,UAAU,SAAS,SAAS,GAAG,SAAS,CACxC,SAAQ,YAAY,CAAC,UAAU,CAAC;gBACpB,IAAI,EAAE,QAAQ,CAAC,UAAU,CAAC;CAMvC"}
|
package/dist/chat.svelte.js
CHANGED
|
@@ -1,33 +1,11 @@
|
|
|
1
|
-
import { AbstractChat,
|
|
1
|
+
import { AbstractChat, } from 'ai';
|
|
2
2
|
export class Chat extends AbstractChat {
|
|
3
|
-
/** The current value of the input. Writable, so it can be bound to form inputs. */
|
|
4
|
-
input;
|
|
5
3
|
constructor(init) {
|
|
6
4
|
super({
|
|
7
5
|
...init,
|
|
8
6
|
state: new SvelteChatState(init.messages),
|
|
9
7
|
});
|
|
10
|
-
this.input = $state(init.initialInput ?? '');
|
|
11
8
|
}
|
|
12
|
-
/** Form submission handler to automatically reset input and append a user message */
|
|
13
|
-
handleSubmit = async (event, options = {}) => {
|
|
14
|
-
event?.preventDefault?.();
|
|
15
|
-
const fileParts = Array.isArray(options?.files)
|
|
16
|
-
? options.files
|
|
17
|
-
: await convertFileListToFileUIParts(options?.files);
|
|
18
|
-
if (!this.input && fileParts.length === 0)
|
|
19
|
-
return;
|
|
20
|
-
const request = this.append({
|
|
21
|
-
id: this.generateId(),
|
|
22
|
-
role: 'user',
|
|
23
|
-
parts: [...fileParts, { type: 'text', text: this.input }],
|
|
24
|
-
}, {
|
|
25
|
-
headers: options.headers,
|
|
26
|
-
body: options.body,
|
|
27
|
-
});
|
|
28
|
-
this.input = '';
|
|
29
|
-
await request;
|
|
30
|
-
};
|
|
31
9
|
}
|
|
32
10
|
class SvelteChatState {
|
|
33
11
|
messages;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/svelte",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-beta.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"
|
|
40
|
-
"ai": "
|
|
39
|
+
"ai": "5.0.0-beta.1",
|
|
40
|
+
"@ai-sdk/provider-utils": "3.0.0-beta.1"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/node": "20.17.24",
|
package/src/chat.svelte.ts
CHANGED
|
@@ -1,90 +1,41 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AbstractChat,
|
|
3
|
-
type
|
|
4
|
-
type ChatRequestOptions,
|
|
3
|
+
type ChatInit,
|
|
5
4
|
type ChatState,
|
|
6
5
|
type ChatStatus,
|
|
7
6
|
type CreateUIMessage,
|
|
8
|
-
type UIDataPartSchemas,
|
|
9
|
-
type UIDataTypes,
|
|
10
7
|
type UIMessage,
|
|
11
|
-
convertFileListToFileUIParts,
|
|
12
8
|
} from 'ai';
|
|
13
9
|
|
|
14
|
-
export type ChatInit<
|
|
15
|
-
MESSAGE_METADATA = unknown,
|
|
16
|
-
DATA_PART_SCHEMAS extends UIDataPartSchemas = UIDataPartSchemas,
|
|
17
|
-
> = Readonly<BaseChatInit<MESSAGE_METADATA, DATA_PART_SCHEMAS>> & {
|
|
18
|
-
/**
|
|
19
|
-
* Initial input of the chat.
|
|
20
|
-
*/
|
|
21
|
-
initialInput?: string;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
10
|
export type { CreateUIMessage, UIMessage };
|
|
25
11
|
|
|
26
12
|
export class Chat<
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
/** The current value of the input. Writable, so it can be bound to form inputs. */
|
|
31
|
-
input: string;
|
|
32
|
-
|
|
33
|
-
constructor(init: ChatInit<MESSAGE_METADATA, DATA_PART_SCHEMAS>) {
|
|
13
|
+
UI_MESSAGE extends UIMessage = UIMessage,
|
|
14
|
+
> extends AbstractChat<UI_MESSAGE> {
|
|
15
|
+
constructor(init: ChatInit<UI_MESSAGE>) {
|
|
34
16
|
super({
|
|
35
17
|
...init,
|
|
36
18
|
state: new SvelteChatState(init.messages),
|
|
37
19
|
});
|
|
38
|
-
|
|
39
|
-
this.input = $state(init.initialInput ?? '');
|
|
40
20
|
}
|
|
41
|
-
|
|
42
|
-
/** Form submission handler to automatically reset input and append a user message */
|
|
43
|
-
handleSubmit = async (
|
|
44
|
-
event?: { preventDefault?: () => void },
|
|
45
|
-
options: ChatRequestOptions & { files?: FileList } = {},
|
|
46
|
-
) => {
|
|
47
|
-
event?.preventDefault?.();
|
|
48
|
-
|
|
49
|
-
const fileParts = Array.isArray(options?.files)
|
|
50
|
-
? options.files
|
|
51
|
-
: await convertFileListToFileUIParts(options?.files);
|
|
52
|
-
|
|
53
|
-
if (!this.input && fileParts.length === 0) return;
|
|
54
|
-
|
|
55
|
-
const request = this.append(
|
|
56
|
-
{
|
|
57
|
-
id: this.generateId(),
|
|
58
|
-
role: 'user',
|
|
59
|
-
parts: [...fileParts, { type: 'text', text: this.input }],
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
headers: options.headers,
|
|
63
|
-
body: options.body,
|
|
64
|
-
},
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
this.input = '';
|
|
68
|
-
await request;
|
|
69
|
-
};
|
|
70
21
|
}
|
|
71
22
|
|
|
72
|
-
class SvelteChatState<
|
|
73
|
-
implements ChatState<
|
|
23
|
+
class SvelteChatState<UI_MESSAGE extends UIMessage>
|
|
24
|
+
implements ChatState<UI_MESSAGE>
|
|
74
25
|
{
|
|
75
|
-
messages:
|
|
26
|
+
messages: UI_MESSAGE[];
|
|
76
27
|
status = $state<ChatStatus>('ready');
|
|
77
28
|
error = $state<Error | undefined>(undefined);
|
|
78
29
|
|
|
79
|
-
constructor(messages:
|
|
30
|
+
constructor(messages: UI_MESSAGE[] = []) {
|
|
80
31
|
this.messages = $state(messages);
|
|
81
32
|
}
|
|
82
33
|
|
|
83
|
-
setMessages = (messages:
|
|
34
|
+
setMessages = (messages: UI_MESSAGE[]) => {
|
|
84
35
|
this.messages = messages;
|
|
85
36
|
};
|
|
86
37
|
|
|
87
|
-
pushMessage = (message:
|
|
38
|
+
pushMessage = (message: UI_MESSAGE) => {
|
|
88
39
|
this.messages.push(message);
|
|
89
40
|
};
|
|
90
41
|
|
|
@@ -92,10 +43,7 @@ class SvelteChatState<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes>
|
|
|
92
43
|
this.messages.pop();
|
|
93
44
|
};
|
|
94
45
|
|
|
95
|
-
replaceMessage = (
|
|
96
|
-
index: number,
|
|
97
|
-
message: UIMessage<MESSAGE_METADATA, DATA_TYPES>,
|
|
98
|
-
) => {
|
|
46
|
+
replaceMessage = (index: number, message: UI_MESSAGE) => {
|
|
99
47
|
this.messages[index] = message;
|
|
100
48
|
};
|
|
101
49
|
|