@ai-sdk/svelte 3.0.0-canary.2 → 3.0.0-canary.20
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 +208 -0
- package/README.md +5 -5
- package/dist/chat.svelte.d.ts +11 -25
- package/dist/chat.svelte.d.ts.map +1 -1
- package/dist/chat.svelte.js +15 -47
- package/dist/completion.svelte.d.ts +2 -9
- package/dist/completion.svelte.d.ts.map +1 -1
- package/dist/completion.svelte.js +4 -21
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/structured-object-context.svelte.d.ts +1 -1
- package/dist/structured-object-context.svelte.d.ts.map +1 -1
- package/dist/structured-object.svelte.d.ts +1 -1
- package/dist/structured-object.svelte.d.ts.map +1 -1
- package/dist/structured-object.svelte.js +5 -5
- package/dist/tests/chat-synchronization.svelte.d.ts +2 -2
- package/dist/tests/structured-object-synchronization.svelte +1 -1
- package/dist/tests/structured-object-synchronization.svelte.d.ts +1 -1
- package/dist/tests/structured-object-synchronization.svelte.d.ts.map +1 -1
- package/package.json +10 -7
- package/src/chat-context.svelte.ts +10 -5
- package/src/chat.svelte.ts +60 -106
- package/src/completion-context.svelte.ts +1 -1
- package/src/completion.svelte.ts +11 -27
- package/src/index.ts +1 -2
- package/src/structured-object-context.svelte.ts +1 -1
- package/src/structured-object.svelte.ts +5 -5
- package/src/tests/structured-object-synchronization.svelte +1 -1
- package/dist/chat-context.svelte.d.ts +0 -14
- package/dist/chat-context.svelte.d.ts.map +0 -1
- package/dist/completion-context.svelte.d.ts +0 -15
- package/dist/completion-context.svelte.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,213 @@
|
|
|
1
1
|
# @ai-sdk/svelte
|
|
2
2
|
|
|
3
|
+
## 3.0.0-canary.20
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [d964901]
|
|
8
|
+
- Updated dependencies [0560977]
|
|
9
|
+
- Updated dependencies [66af894]
|
|
10
|
+
- Updated dependencies [516be5b]
|
|
11
|
+
- Updated dependencies [bfbfc4c]
|
|
12
|
+
- Updated dependencies [ea7a7c9]
|
|
13
|
+
- Updated dependencies [1409e13]
|
|
14
|
+
- ai@5.0.0-canary.21
|
|
15
|
+
- @ai-sdk/provider-utils@3.0.0-canary.17
|
|
16
|
+
|
|
17
|
+
## 3.0.0-canary.19
|
|
18
|
+
|
|
19
|
+
### Major Changes
|
|
20
|
+
|
|
21
|
+
- 496bbc1: chore (ui): inline/remove ChatRequest type
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [13fef90]
|
|
26
|
+
- Updated dependencies [e90d45d]
|
|
27
|
+
- Updated dependencies [bc3109f]
|
|
28
|
+
- Updated dependencies [496bbc1]
|
|
29
|
+
- Updated dependencies [da70d79]
|
|
30
|
+
- Updated dependencies [bcea599]
|
|
31
|
+
- Updated dependencies [48d675a]
|
|
32
|
+
- Updated dependencies [c7710a9]
|
|
33
|
+
- Updated dependencies [87b828f]
|
|
34
|
+
- Updated dependencies [35fc02c]
|
|
35
|
+
- Updated dependencies [b983b51]
|
|
36
|
+
- ai@5.0.0-canary.20
|
|
37
|
+
- @ai-sdk/provider-utils@3.0.0-canary.16
|
|
38
|
+
|
|
39
|
+
## 3.0.0-canary.18
|
|
40
|
+
|
|
41
|
+
### Patch Changes
|
|
42
|
+
|
|
43
|
+
- Updated dependencies [2d03e19]
|
|
44
|
+
- Updated dependencies [319b989]
|
|
45
|
+
- Updated dependencies [441d042]
|
|
46
|
+
- Updated dependencies [dcc549b]
|
|
47
|
+
- Updated dependencies [cb2b53a]
|
|
48
|
+
- Updated dependencies [e244a78]
|
|
49
|
+
- ai@5.0.0-canary.19
|
|
50
|
+
|
|
51
|
+
## 3.0.0-canary.17
|
|
52
|
+
|
|
53
|
+
### Patch Changes
|
|
54
|
+
|
|
55
|
+
- Updated dependencies [a571d6e]
|
|
56
|
+
- Updated dependencies [c60f895]
|
|
57
|
+
- Updated dependencies [332167b]
|
|
58
|
+
- Updated dependencies [a8c8bd5]
|
|
59
|
+
- Updated dependencies [a662dea]
|
|
60
|
+
- Updated dependencies [41fa418]
|
|
61
|
+
- @ai-sdk/provider-utils@3.0.0-canary.15
|
|
62
|
+
- ai@5.0.0-canary.18
|
|
63
|
+
|
|
64
|
+
## 3.0.0-canary.16
|
|
65
|
+
|
|
66
|
+
### Patch Changes
|
|
67
|
+
|
|
68
|
+
- Updated dependencies [f04fb4a]
|
|
69
|
+
- Updated dependencies [fd1924b]
|
|
70
|
+
- Updated dependencies [957b739]
|
|
71
|
+
- Updated dependencies [fafc3f2]
|
|
72
|
+
- Updated dependencies [c9ad635]
|
|
73
|
+
- Updated dependencies [9bd5ab5]
|
|
74
|
+
- Updated dependencies [92cb0a2]
|
|
75
|
+
- ai@5.0.0-canary.17
|
|
76
|
+
- @ai-sdk/provider-utils@3.0.0-canary.14
|
|
77
|
+
|
|
78
|
+
## 3.0.0-canary.15
|
|
79
|
+
|
|
80
|
+
### Patch Changes
|
|
81
|
+
|
|
82
|
+
- Updated dependencies [ec78cdc]
|
|
83
|
+
- Updated dependencies [9b4d074]
|
|
84
|
+
- Updated dependencies [8b86e99]
|
|
85
|
+
- Updated dependencies [28ad69e]
|
|
86
|
+
- Updated dependencies [2524fc7]
|
|
87
|
+
- Updated dependencies [ec5933d]
|
|
88
|
+
- Updated dependencies [175b868]
|
|
89
|
+
- ai@5.0.0-canary.16
|
|
90
|
+
|
|
91
|
+
## 3.0.0-canary.14
|
|
92
|
+
|
|
93
|
+
### Patch Changes
|
|
94
|
+
|
|
95
|
+
- Updated dependencies [d9209ca]
|
|
96
|
+
- Updated dependencies [ea27cc6]
|
|
97
|
+
- Updated dependencies [0ff02bb]
|
|
98
|
+
- Updated dependencies [4bfe9ec]
|
|
99
|
+
- Updated dependencies [2877a74]
|
|
100
|
+
- ai@5.0.0-canary.15
|
|
101
|
+
- @ai-sdk/provider-utils@3.0.0-canary.13
|
|
102
|
+
|
|
103
|
+
## 3.0.0-canary.13
|
|
104
|
+
|
|
105
|
+
### Patch Changes
|
|
106
|
+
|
|
107
|
+
- Updated dependencies [9bf7291]
|
|
108
|
+
- Updated dependencies [4617fab]
|
|
109
|
+
- Updated dependencies [a76a62b]
|
|
110
|
+
- ai@5.0.0-canary.14
|
|
111
|
+
- @ai-sdk/provider-utils@3.0.0-canary.12
|
|
112
|
+
|
|
113
|
+
## 3.0.0-canary.12
|
|
114
|
+
|
|
115
|
+
### Patch Changes
|
|
116
|
+
|
|
117
|
+
- Updated dependencies [14cb3be]
|
|
118
|
+
- Updated dependencies [66962ed]
|
|
119
|
+
- Updated dependencies [9301f86]
|
|
120
|
+
- ai@5.0.0-canary.13
|
|
121
|
+
- @ai-sdk/provider-utils@3.0.0-canary.11
|
|
122
|
+
|
|
123
|
+
## 3.0.0-canary.11
|
|
124
|
+
|
|
125
|
+
### Patch Changes
|
|
126
|
+
|
|
127
|
+
- ai@5.0.0-canary.12
|
|
128
|
+
- @ai-sdk/provider-utils@3.0.0-canary.10
|
|
129
|
+
|
|
130
|
+
## 3.0.0-canary.10
|
|
131
|
+
|
|
132
|
+
### Patch Changes
|
|
133
|
+
|
|
134
|
+
- Updated dependencies [8e64e9c]
|
|
135
|
+
- ai@5.0.0-canary.11
|
|
136
|
+
- @ai-sdk/provider-utils@3.0.0-canary.9
|
|
137
|
+
|
|
138
|
+
## 3.0.0-canary.9
|
|
139
|
+
|
|
140
|
+
### Patch Changes
|
|
141
|
+
|
|
142
|
+
- Updated dependencies [d8aeaef]
|
|
143
|
+
- Updated dependencies [3e10408]
|
|
144
|
+
- ai@5.0.0-canary.10
|
|
145
|
+
|
|
146
|
+
## 3.0.0-canary.8
|
|
147
|
+
|
|
148
|
+
### Patch Changes
|
|
149
|
+
|
|
150
|
+
- Updated dependencies [a847c3e]
|
|
151
|
+
- Updated dependencies [5d142ab]
|
|
152
|
+
- Updated dependencies [cb9c9e4]
|
|
153
|
+
- Updated dependencies [8aa9e20]
|
|
154
|
+
- Updated dependencies [b32e192]
|
|
155
|
+
- ai@5.0.0-canary.9
|
|
156
|
+
- @ai-sdk/provider-utils@3.0.0-canary.8
|
|
157
|
+
|
|
158
|
+
## 3.0.0-canary.7
|
|
159
|
+
|
|
160
|
+
### Patch Changes
|
|
161
|
+
|
|
162
|
+
- Updated dependencies [5d1e3ba]
|
|
163
|
+
- Updated dependencies [26735b5]
|
|
164
|
+
- Updated dependencies [14c9410]
|
|
165
|
+
- Updated dependencies [7827a49]
|
|
166
|
+
- Updated dependencies [bd8a36c]
|
|
167
|
+
- Updated dependencies [b6f9f3c]
|
|
168
|
+
- Updated dependencies [92c8e66]
|
|
169
|
+
- Updated dependencies [fd65bc6]
|
|
170
|
+
- Updated dependencies [5bdff05]
|
|
171
|
+
- ai@5.0.0-canary.8
|
|
172
|
+
- @ai-sdk/provider-utils@3.0.0-canary.7
|
|
173
|
+
|
|
174
|
+
## 3.0.0-canary.6
|
|
175
|
+
|
|
176
|
+
### Patch Changes
|
|
177
|
+
|
|
178
|
+
- Updated dependencies [0b78e17]
|
|
179
|
+
- Updated dependencies [6fba4c7]
|
|
180
|
+
- Updated dependencies [3e3b9df]
|
|
181
|
+
- Updated dependencies [1766ede]
|
|
182
|
+
- Updated dependencies [f10304b]
|
|
183
|
+
- ai@5.0.0-canary.7
|
|
184
|
+
- @ai-sdk/provider-utils@3.0.0-canary.6
|
|
185
|
+
|
|
186
|
+
## 3.0.0-canary.5
|
|
187
|
+
|
|
188
|
+
### Patch Changes
|
|
189
|
+
|
|
190
|
+
- ai@5.0.0-canary.6
|
|
191
|
+
- @ai-sdk/provider-utils@3.0.0-canary.5
|
|
192
|
+
|
|
193
|
+
## 3.0.0-canary.4
|
|
194
|
+
|
|
195
|
+
### Patch Changes
|
|
196
|
+
|
|
197
|
+
- Updated dependencies [b71fe8d]
|
|
198
|
+
- Updated dependencies [d91b50d]
|
|
199
|
+
- ai@5.0.0-canary.5
|
|
200
|
+
- @ai-sdk/provider-utils@3.0.0-canary.4
|
|
201
|
+
|
|
202
|
+
## 3.0.0-canary.3
|
|
203
|
+
|
|
204
|
+
### Patch Changes
|
|
205
|
+
|
|
206
|
+
- Updated dependencies [a166433]
|
|
207
|
+
- Updated dependencies [9f95b35]
|
|
208
|
+
- @ai-sdk/provider-utils@3.0.0-canary.3
|
|
209
|
+
- @ai-sdk/ui-utils@2.0.0-canary.3
|
|
210
|
+
|
|
3
211
|
## 3.0.0-canary.2
|
|
4
212
|
|
|
5
213
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# AI SDK: Svelte provider
|
|
2
2
|
|
|
3
|
-
[Svelte](https://svelte.dev/) UI components for the [AI SDK](https://sdk.
|
|
3
|
+
[Svelte](https://svelte.dev/) UI components for the [AI SDK](https://ai-sdk.dev/docs):
|
|
4
4
|
|
|
5
|
-
- [`Chat`](https://sdk.
|
|
6
|
-
- [`Completion`](https://sdk.
|
|
7
|
-
- [`StructuredObject`](https://sdk.
|
|
5
|
+
- [`Chat`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat)
|
|
6
|
+
- [`Completion`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-completion)
|
|
7
|
+
- [`StructuredObject`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-object)
|
|
8
8
|
|
|
9
|
-
For information on the few ways the Svelte APIs differ from the React ones, see [the docs](https://sdk.
|
|
9
|
+
For information on the few ways the Svelte APIs differ from the React ones, see [the docs](https://ai-sdk.dev/docs/getting-started/svelte#how-does-ai-sdksvelte-differ-from-ai-sdkreact)
|
package/dist/chat.svelte.d.ts
CHANGED
|
@@ -1,29 +1,13 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export type ChatOptions = Readonly<
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* Must be at least 1.
|
|
6
|
-
* A maximum number is required to prevent infinite loops in the case of misconfigured tools.
|
|
7
|
-
* By default, it's set to 1, which means that only a single LLM call is made.
|
|
8
|
-
* @default 1
|
|
9
|
-
*/
|
|
10
|
-
maxSteps?: number;
|
|
11
|
-
}>;
|
|
12
|
-
export type { CreateMessage, Message, UIMessage };
|
|
13
|
-
export declare class Chat {
|
|
1
|
+
import { type ChatRequestOptions, type CreateUIMessage, type UIMessage, type UseChatOptions } from 'ai';
|
|
2
|
+
export type ChatOptions<MESSAGE_METADATA = unknown> = Readonly<UseChatOptions<MESSAGE_METADATA>>;
|
|
3
|
+
export type { CreateUIMessage, UIMessage };
|
|
4
|
+
export declare class Chat<MESSAGE_METADATA = unknown> {
|
|
14
5
|
#private;
|
|
15
6
|
/**
|
|
16
7
|
* The id of the chat. If not provided through the constructor, a random ID will be generated
|
|
17
8
|
* using the provided `generateId` function, or a built-in function if not provided.
|
|
18
9
|
*/
|
|
19
10
|
readonly id: string;
|
|
20
|
-
/**
|
|
21
|
-
* Additional data added on the server via StreamData.
|
|
22
|
-
*
|
|
23
|
-
* This is writable, so you can use it to transform or clear the chat data.
|
|
24
|
-
*/
|
|
25
|
-
get data(): JSONValue[] | undefined;
|
|
26
|
-
set data(value: JSONValue[] | undefined);
|
|
27
11
|
/**
|
|
28
12
|
* Hook status:
|
|
29
13
|
*
|
|
@@ -43,16 +27,16 @@ export declare class Chat {
|
|
|
43
27
|
* This is writable, which is useful when you want to edit the messages on the client, and then
|
|
44
28
|
* trigger {@link reload} to regenerate the AI response.
|
|
45
29
|
*/
|
|
46
|
-
get messages(): UIMessage[];
|
|
47
|
-
set messages(value:
|
|
48
|
-
constructor(options?: ChatOptions);
|
|
30
|
+
get messages(): UIMessage<MESSAGE_METADATA>[];
|
|
31
|
+
set messages(value: UIMessage<MESSAGE_METADATA>[]);
|
|
32
|
+
constructor(options?: ChatOptions<MESSAGE_METADATA>);
|
|
49
33
|
/**
|
|
50
34
|
* Append a user message to the chat list. This triggers the API call to fetch
|
|
51
35
|
* the assistant's response.
|
|
52
36
|
* @param message The message to append
|
|
53
37
|
* @param options Additional options to pass to the API call
|
|
54
38
|
*/
|
|
55
|
-
append: (message:
|
|
39
|
+
append: (message: UIMessage<MESSAGE_METADATA> | CreateUIMessage<MESSAGE_METADATA>, { data, headers, body }?: ChatRequestOptions) => Promise<void>;
|
|
56
40
|
/**
|
|
57
41
|
* Reload the last AI chat response for the given chat history. If the last
|
|
58
42
|
* message isn't from the assistant, it will request the API to generate a
|
|
@@ -66,7 +50,9 @@ export declare class Chat {
|
|
|
66
50
|
/** Form submission handler to automatically reset input and append a user message */
|
|
67
51
|
handleSubmit: (event?: {
|
|
68
52
|
preventDefault?: () => void;
|
|
69
|
-
}, options?: ChatRequestOptions
|
|
53
|
+
}, options?: ChatRequestOptions & {
|
|
54
|
+
files?: FileList;
|
|
55
|
+
}) => Promise<void>;
|
|
70
56
|
addToolResult: ({ toolCallId, result, }: {
|
|
71
57
|
toolCallId: string;
|
|
72
58
|
result: unknown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.svelte.d.ts","sourceRoot":"","sources":["../src/chat.svelte.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"chat.svelte.d.ts","sourceRoot":"","sources":["../src/chat.svelte.ts"],"names":[],"mappings":"AACA,OAAO,EASL,KAAK,kBAAkB,EACvB,KAAK,eAAe,EAEpB,KAAK,SAAS,EACd,KAAK,cAAc,EACpB,MAAM,IAAI,CAAC;AAQZ,MAAM,MAAM,WAAW,CAAC,gBAAgB,GAAG,OAAO,IAAI,QAAQ,CAC5D,cAAc,CAAC,gBAAgB,CAAC,CACjC,CAAC;AAEF,YAAY,EAAE,eAAe,EAAE,SAAS,EAAE,CAAC;AAE3C,qBAAa,IAAI,CAAC,gBAAgB,GAAG,OAAO;;IAO1C;;;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,4BAC/C,kBAAkB,mBAQ3C;IAEF;;;;OAIG;IACH,MAAM,6BAAmC,kBAAkB,mBAezD;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,mBA8BlD;IAEF,aAAa,4BAGV;QACD,UAAU,EAAE,MAAM,CAAC;QACnB,MAAM,EAAE,OAAO,CAAC;KACjB,mBAmBC;CA+FH"}
|
package/dist/chat.svelte.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { fillMessageParts, generateId, extractMaxToolInvocationStep, callChatApi, shouldResubmitMessages, prepareAttachmentsForRequest, getMessageParts, updateToolCallResult, isAssistantMessageWithCompletedToolCalls, } from '@ai-sdk/ui-utils';
|
|
2
1
|
import { isAbortError } from '@ai-sdk/provider-utils';
|
|
3
|
-
import {
|
|
2
|
+
import { callChatApi, convertFileListToFileUIParts, extractMaxToolInvocationStep, generateId, getToolInvocations, isAssistantMessageWithCompletedToolCalls, shouldResubmitMessages, updateToolCallResult, } from 'ai';
|
|
4
3
|
import { untrack } from 'svelte';
|
|
4
|
+
import { KeyedChatStore, getChatContext, hasChatContext, } from './chat-context.svelte.js';
|
|
5
5
|
export class Chat {
|
|
6
6
|
#options = {};
|
|
7
7
|
#api = $derived(this.#options.api ?? '/api/chat');
|
|
@@ -15,18 +15,8 @@ export class Chat {
|
|
|
15
15
|
*/
|
|
16
16
|
id = $derived(this.#options.id ?? this.#generateId());
|
|
17
17
|
#store = $derived(this.#keyedStore.get(this.id));
|
|
18
|
+
#messageMetadataSchema = $derived(this.#options.messageMetadataSchema);
|
|
18
19
|
#abortController;
|
|
19
|
-
/**
|
|
20
|
-
* Additional data added on the server via StreamData.
|
|
21
|
-
*
|
|
22
|
-
* This is writable, so you can use it to transform or clear the chat data.
|
|
23
|
-
*/
|
|
24
|
-
get data() {
|
|
25
|
-
return this.#store.data;
|
|
26
|
-
}
|
|
27
|
-
set data(value) {
|
|
28
|
-
this.#store.data = value;
|
|
29
|
-
}
|
|
30
20
|
/**
|
|
31
21
|
* Hook status:
|
|
32
22
|
*
|
|
@@ -54,7 +44,7 @@ export class Chat {
|
|
|
54
44
|
return this.#store.messages;
|
|
55
45
|
}
|
|
56
46
|
set messages(value) {
|
|
57
|
-
untrack(() => (this.#store.messages =
|
|
47
|
+
untrack(() => (this.#store.messages = value));
|
|
58
48
|
}
|
|
59
49
|
constructor(options = {}) {
|
|
60
50
|
if (hasChatContext()) {
|
|
@@ -73,14 +63,10 @@ export class Chat {
|
|
|
73
63
|
* @param message The message to append
|
|
74
64
|
* @param options Additional options to pass to the API call
|
|
75
65
|
*/
|
|
76
|
-
append = async (message, { data, headers, body
|
|
77
|
-
const attachmentsForRequest = await prepareAttachmentsForRequest(experimental_attachments);
|
|
66
|
+
append = async (message, { data, headers, body } = {}) => {
|
|
78
67
|
const messages = this.messages.concat({
|
|
79
68
|
...message,
|
|
80
69
|
id: message.id ?? this.#generateId(),
|
|
81
|
-
createdAt: message.createdAt ?? new Date(),
|
|
82
|
-
experimental_attachments: attachmentsForRequest.length > 0 ? attachmentsForRequest : undefined,
|
|
83
|
-
parts: getMessageParts(message),
|
|
84
70
|
});
|
|
85
71
|
return this.#triggerRequest({ messages, headers, body, data });
|
|
86
72
|
};
|
|
@@ -123,14 +109,13 @@ export class Chat {
|
|
|
123
109
|
event?.preventDefault?.();
|
|
124
110
|
if (!this.input && !options.allowEmptySubmit)
|
|
125
111
|
return;
|
|
126
|
-
const
|
|
112
|
+
const fileParts = Array.isArray(options?.files)
|
|
113
|
+
? options.files
|
|
114
|
+
: await convertFileListToFileUIParts(options?.files);
|
|
127
115
|
const messages = this.messages.concat({
|
|
128
116
|
id: this.#generateId(),
|
|
129
|
-
createdAt: new Date(),
|
|
130
117
|
role: 'user',
|
|
131
|
-
|
|
132
|
-
experimental_attachments: attachmentsForRequest.length > 0 ? attachmentsForRequest : undefined,
|
|
133
|
-
parts: [{ type: 'text', text: this.input }],
|
|
118
|
+
parts: [...fileParts, { type: 'text', text: this.input }],
|
|
134
119
|
});
|
|
135
120
|
const chatRequest = {
|
|
136
121
|
messages,
|
|
@@ -161,33 +146,19 @@ export class Chat {
|
|
|
161
146
|
#triggerRequest = async (chatRequest) => {
|
|
162
147
|
this.#store.status = 'submitted';
|
|
163
148
|
this.#store.error = undefined;
|
|
164
|
-
const messages =
|
|
149
|
+
const messages = chatRequest.messages;
|
|
165
150
|
const messageCount = messages.length;
|
|
166
|
-
const maxStep = extractMaxToolInvocationStep(messages[messages.length - 1]
|
|
151
|
+
const maxStep = extractMaxToolInvocationStep(getToolInvocations(messages[messages.length - 1]));
|
|
167
152
|
try {
|
|
168
153
|
const abortController = new AbortController();
|
|
169
154
|
this.#abortController = abortController;
|
|
170
155
|
// Optimistically update messages
|
|
171
156
|
this.messages = messages;
|
|
172
|
-
const constructedMessagesPayload = this.#options.sendExtraMessageFields
|
|
173
|
-
? messages
|
|
174
|
-
: messages.map(({ role, content, experimental_attachments, data, annotations, toolInvocations, parts, }) => ({
|
|
175
|
-
role,
|
|
176
|
-
content,
|
|
177
|
-
...(experimental_attachments !== undefined && {
|
|
178
|
-
experimental_attachments,
|
|
179
|
-
}),
|
|
180
|
-
...(data !== undefined && { data }),
|
|
181
|
-
...(annotations !== undefined && { annotations }),
|
|
182
|
-
...(toolInvocations !== undefined && { toolInvocations }),
|
|
183
|
-
...(parts !== undefined && { parts }),
|
|
184
|
-
}));
|
|
185
|
-
const existingData = this.data ?? [];
|
|
186
157
|
await callChatApi({
|
|
187
158
|
api: this.#api,
|
|
188
159
|
body: {
|
|
189
160
|
id: this.id,
|
|
190
|
-
messages
|
|
161
|
+
messages,
|
|
191
162
|
data: chatRequest.data,
|
|
192
163
|
...$state.snapshot(this.#options.body),
|
|
193
164
|
...chatRequest.body,
|
|
@@ -199,10 +170,10 @@ export class Chat {
|
|
|
199
170
|
...chatRequest.headers,
|
|
200
171
|
},
|
|
201
172
|
abortController: () => abortController,
|
|
202
|
-
restoreMessagesOnFailure: () => { },
|
|
203
173
|
onResponse: this.#options.onResponse,
|
|
204
|
-
onUpdate: ({ message
|
|
174
|
+
onUpdate: ({ message }) => {
|
|
205
175
|
this.#store.status = 'streaming';
|
|
176
|
+
const replaceLastMessage = message.id === messages[messages.length - 1].id;
|
|
206
177
|
this.messages = messages;
|
|
207
178
|
if (replaceLastMessage) {
|
|
208
179
|
this.messages[this.messages.length - 1] = message;
|
|
@@ -210,10 +181,6 @@ export class Chat {
|
|
|
210
181
|
else {
|
|
211
182
|
this.messages.push(message);
|
|
212
183
|
}
|
|
213
|
-
if (data?.length) {
|
|
214
|
-
this.data = existingData;
|
|
215
|
-
this.data.push(...data);
|
|
216
|
-
}
|
|
217
184
|
},
|
|
218
185
|
onToolCall: this.#options.onToolCall,
|
|
219
186
|
onFinish: this.#options.onFinish,
|
|
@@ -221,6 +188,7 @@ export class Chat {
|
|
|
221
188
|
fetch: this.#options.fetch,
|
|
222
189
|
// callChatApi calls structuredClone on the message
|
|
223
190
|
lastMessage: $state.snapshot(this.messages[this.messages.length - 1]),
|
|
191
|
+
messageMetadataSchema: this.#messageMetadataSchema,
|
|
224
192
|
});
|
|
225
193
|
this.#abortController = undefined;
|
|
226
194
|
this.#store.status = 'ready';
|
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type CompletionRequestOptions, type UseCompletionOptions } from 'ai';
|
|
2
2
|
export type CompletionOptions = Readonly<UseCompletionOptions>;
|
|
3
3
|
export declare class Completion {
|
|
4
4
|
#private;
|
|
5
5
|
/** The current completion result */
|
|
6
6
|
get completion(): string;
|
|
7
7
|
set completion(value: string);
|
|
8
|
-
/**
|
|
9
|
-
* Additional data added on the server via StreamData.
|
|
10
|
-
*
|
|
11
|
-
* This is writable, so you can use it to transform or clear the chat data.
|
|
12
|
-
*/
|
|
13
|
-
get data(): JSONValue[];
|
|
14
|
-
set data(value: JSONValue[]);
|
|
15
8
|
/** The error object of the API request */
|
|
16
9
|
get error(): Error | undefined;
|
|
17
10
|
/** The current value of the input. Writable, so it can be bound to form inputs. */
|
|
@@ -28,7 +21,7 @@ export declare class Completion {
|
|
|
28
21
|
/**
|
|
29
22
|
* Send a new prompt to the API endpoint and update the completion state.
|
|
30
23
|
*/
|
|
31
|
-
complete: (prompt: string, options?:
|
|
24
|
+
complete: (prompt: string, options?: CompletionRequestOptions) => Promise<string | null | undefined>;
|
|
32
25
|
/** Form submission handler to automatically reset input and call the completion API */
|
|
33
26
|
handleSubmit: (event?: {
|
|
34
27
|
preventDefault?: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"completion.svelte.d.ts","sourceRoot":"","sources":["../src/completion.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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;CAmCH"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { callCompletionApi, generateId, } from 'ai';
|
|
2
2
|
import { KeyedCompletionStore, getCompletionContext, hasCompletionContext, } from './completion-context.svelte.js';
|
|
3
3
|
export class Completion {
|
|
4
4
|
#options = {};
|
|
@@ -15,17 +15,6 @@ export class Completion {
|
|
|
15
15
|
set completion(value) {
|
|
16
16
|
this.#store.completions.set(this.#id, value);
|
|
17
17
|
}
|
|
18
|
-
/**
|
|
19
|
-
* Additional data added on the server via StreamData.
|
|
20
|
-
*
|
|
21
|
-
* This is writable, so you can use it to transform or clear the chat data.
|
|
22
|
-
*/
|
|
23
|
-
get data() {
|
|
24
|
-
return this.#store.data;
|
|
25
|
-
}
|
|
26
|
-
set data(value) {
|
|
27
|
-
this.#store.data = value;
|
|
28
|
-
}
|
|
29
18
|
/** The error object of the API request */
|
|
30
19
|
get error() {
|
|
31
20
|
return this.#store.error;
|
|
@@ -39,12 +28,9 @@ export class Completion {
|
|
|
39
28
|
return this.#store.loading;
|
|
40
29
|
}
|
|
41
30
|
constructor(options = {}) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
else {
|
|
46
|
-
this.#keyedStore = new KeyedCompletionStore();
|
|
47
|
-
}
|
|
31
|
+
this.#keyedStore = hasCompletionContext()
|
|
32
|
+
? getCompletionContext()
|
|
33
|
+
: new KeyedCompletionStore();
|
|
48
34
|
this.#options = options;
|
|
49
35
|
this.completion = options.initialCompletion ?? '';
|
|
50
36
|
this.input = options.initialInput ?? '';
|
|
@@ -91,9 +77,6 @@ export class Completion {
|
|
|
91
77
|
setCompletion: completion => {
|
|
92
78
|
this.completion = completion;
|
|
93
79
|
},
|
|
94
|
-
onData: data => {
|
|
95
|
-
this.data.push(...data);
|
|
96
|
-
},
|
|
97
80
|
setLoading: loading => {
|
|
98
81
|
this.#store.loading = loading;
|
|
99
82
|
},
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { Chat, type ChatOptions, type
|
|
1
|
+
export { Chat, type ChatOptions, type CreateUIMessage, type UIMessage, } from './chat.svelte.js';
|
|
2
2
|
export { StructuredObject as Experimental_StructuredObject, type Experimental_StructuredObjectOptions, } from './structured-object.svelte.js';
|
|
3
3
|
export { Completion, type CompletionOptions } from './completion.svelte.js';
|
|
4
4
|
export { createAIContext } from './context-provider.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,KAAK,WAAW,EAChB,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,SAAS,GACf,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,gBAAgB,IAAI,6BAA6B,EACjD,KAAK,oCAAoC,GAC1C,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE5E,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"structured-object-context.svelte.d.ts","sourceRoot":"","sources":["../src/structured-object-context.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"structured-object-context.svelte.d.ts","sourceRoot":"","sources":["../src/structured-object-context.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AACtC,OAAO,EAAiB,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE9D,qBAAa,qBAAqB,CAAC,MAAM;IACvC,MAAM,kCAAiC;IACvC,OAAO,UAAiB;IACxB,KAAK,oBAAmB;CACzB;AAED,qBAAa,0BAA2B,SAAQ,UAAU,CACxD,qBAAqB,CAAC,OAAO,CAAC,CAC/B;gBAEG,KAAK,CAAC,EACF,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC,GAC3D,IAAI,GACJ,SAAS;CAIhB;AAED,eAAO,MACO,0BAA0B,iBAC1B,0BAA0B,oCAC1B,0BAA0B,mEACyB,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type FetchFunction } from '@ai-sdk/provider-utils';
|
|
2
|
-
import { type DeepPartial, type Schema } from '
|
|
2
|
+
import { type DeepPartial, type Schema } from 'ai';
|
|
3
3
|
import { type z } from 'zod';
|
|
4
4
|
export type Experimental_StructuredObjectOptions<RESULT> = {
|
|
5
5
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"structured-object.svelte.d.ts","sourceRoot":"","sources":["../src/structured-object.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,aAAa,EACnB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAIL,KAAK,WAAW,EAChB,KAAK,MAAM,EACZ,MAAM,
|
|
1
|
+
{"version":3,"file":"structured-object.svelte.d.ts","sourceRoot":"","sources":["../src/structured-object.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,aAAa,EACnB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAIL,KAAK,WAAW,EAChB,KAAK,MAAM,EACZ,MAAM,IAAI,CAAC;AACZ,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,CAAC;AAQ7B,MAAM,MAAM,oCAAoC,CAAC,MAAM,IAAI;IACzD;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAEjE;;;;OAIG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,YAAY,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAEnC;;;OAGG;IACH,KAAK,CAAC,EAAE,aAAa,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE;QACjB;;;WAGG;QACH,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;QAE3B;;WAEG;QACH,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;KAC1B,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAE3B;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAEjC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC;IAE3C;;;;OAIG;IACH,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC,CAAC;AAEF,qBAAa,gBAAgB,CAAC,MAAM,EAAE,KAAK,GAAG,OAAO;;IAUnD;;OAEG;IACH,IAAI,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC,GAAG,SAAS,CAE5C;IAKD,0CAA0C;IAC1C,IAAI,KAAK,sBAER;IAED;;OAEG;IACH,IAAI,OAAO,YAEV;gBAEW,OAAO,EAAE,oCAAoC,CAAC,MAAM,CAAC;IAUjE;;OAEG;IACH,IAAI,aASF;IAEF;;OAEG;IACH,MAAM,UAAiB,KAAK,mBAqF1B;CACH"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { generateId, isAbortError, safeValidateTypes, } from '@ai-sdk/provider-utils';
|
|
2
|
-
import { asSchema, isDeepEqualData, parsePartialJson, } from '
|
|
2
|
+
import { asSchema, isDeepEqualData, parsePartialJson, } from 'ai';
|
|
3
3
|
import {} from 'zod';
|
|
4
4
|
import { getStructuredObjectContext, hasStructuredObjectContext, KeyedStructuredObjectStore, } from './structured-object-context.svelte.js';
|
|
5
5
|
export class StructuredObject {
|
|
@@ -82,23 +82,23 @@ export class StructuredObject {
|
|
|
82
82
|
let accumulatedText = '';
|
|
83
83
|
let latestObject = undefined;
|
|
84
84
|
await response.body.pipeThrough(new TextDecoderStream()).pipeTo(new WritableStream({
|
|
85
|
-
write: chunk => {
|
|
85
|
+
write: async (chunk) => {
|
|
86
86
|
if (abortController?.signal.aborted) {
|
|
87
87
|
throw new DOMException('Stream aborted', 'AbortError');
|
|
88
88
|
}
|
|
89
89
|
accumulatedText += chunk;
|
|
90
|
-
const { value } = parsePartialJson(accumulatedText);
|
|
90
|
+
const { value } = await parsePartialJson(accumulatedText);
|
|
91
91
|
const currentObject = value;
|
|
92
92
|
if (!isDeepEqualData(latestObject, currentObject)) {
|
|
93
93
|
latestObject = currentObject;
|
|
94
94
|
this.#store.object = currentObject;
|
|
95
95
|
}
|
|
96
96
|
},
|
|
97
|
-
close: () => {
|
|
97
|
+
close: async () => {
|
|
98
98
|
this.#store.loading = false;
|
|
99
99
|
this.#abortController = undefined;
|
|
100
100
|
if (this.#options.onFinish != null) {
|
|
101
|
-
const validationResult = safeValidateTypes({
|
|
101
|
+
const validationResult = await safeValidateTypes({
|
|
102
102
|
value: latestObject,
|
|
103
103
|
schema: asSchema(this.#options.schema),
|
|
104
104
|
});
|
|
@@ -3,8 +3,8 @@ type $$ComponentProps = {
|
|
|
3
3
|
id?: string;
|
|
4
4
|
};
|
|
5
5
|
declare const ChatSynchronization: import("svelte").Component<$$ComponentProps, {
|
|
6
|
-
chat1: Chat
|
|
7
|
-
chat2: Chat
|
|
6
|
+
chat1: Chat<unknown>;
|
|
7
|
+
chat2: Chat<unknown>;
|
|
8
8
|
}, "">;
|
|
9
9
|
type ChatSynchronization = ReturnType<typeof ChatSynchronization>;
|
|
10
10
|
export default ChatSynchronization;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts" generics="RESULT">
|
|
2
2
|
import { createAIContext } from '../context-provider.js';
|
|
3
3
|
import { StructuredObject } from '../structured-object.svelte.js';
|
|
4
|
-
import type { Schema } from '
|
|
4
|
+
import type { Schema } from 'ai';
|
|
5
5
|
import type { z } from 'zod';
|
|
6
6
|
|
|
7
7
|
let {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"structured-object-synchronization.svelte.d.ts","sourceRoot":"","sources":["../../src/tests/structured-object-synchronization.svelte.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"structured-object-synchronization.svelte.d.ts","sourceRoot":"","sources":["../../src/tests/structured-object-synchronization.svelte.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AACjC,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA2B7B,cAAM,iBAAiB,CAAC,MAAM;IAC1B,KAAK;aArBA,MAAM;aACN,MAAM;;;IAuBX,MAAM;IAGN,KAAK;IAGL,QAAQ;IACR,OAAO;;;;CACV;AAED,UAAU,qBAAqB;IAC3B,KAAK,MAAM,EAAE,OAAO,EAAE,OAAO,QAAQ,EAAE,2BAA2B,CAAC,UAAU,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,QAAQ,EAAE,eAAe,CAAC,UAAU,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG;QAAE,UAAU,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,CAAC,CAAA;KAAE,GAAG,UAAU,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IAC/Z,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,GAAG,UAAU,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IAC1I,YAAY,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;CACjE;AACD,QAAA,MAAM,+BAA+B,EAAE,qBAAmC,CAAC;AACzD,KAAK,+BAA+B,CAAC,MAAM,IAAI,YAAY,CAAC,OAAO,+BAA+B,CAAC,MAAM,CAAC,CAAC,CAAC;AAC9G,eAAe,+BAA+B,CAAC"}
|
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.20",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -36,10 +36,11 @@
|
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"
|
|
40
|
-
"@ai-sdk/
|
|
39
|
+
"ai": "5.0.0-canary.21",
|
|
40
|
+
"@ai-sdk/provider-utils": "3.0.0-canary.17"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
+
"@types/node": "20.17.24",
|
|
43
44
|
"@eslint/compat": "^1.2.5",
|
|
44
45
|
"@eslint/js": "^9.18.0",
|
|
45
46
|
"@sveltejs/package": "^2.0.0",
|
|
@@ -57,9 +58,10 @@
|
|
|
57
58
|
"typescript-eslint": "^8.20.0",
|
|
58
59
|
"vite": "^6.0.0",
|
|
59
60
|
"vitest": "^3.0.0",
|
|
60
|
-
"zod": "3.23.8"
|
|
61
|
+
"zod": "3.23.8",
|
|
62
|
+
"@vercel/ai-tsconfig": "0.0.0"
|
|
61
63
|
},
|
|
62
|
-
"homepage": "https://sdk.
|
|
64
|
+
"homepage": "https://ai-sdk.dev/docs",
|
|
63
65
|
"repository": {
|
|
64
66
|
"type": "git",
|
|
65
67
|
"url": "git+https://github.com/vercel/ai.git",
|
|
@@ -74,7 +76,7 @@
|
|
|
74
76
|
],
|
|
75
77
|
"scripts": {
|
|
76
78
|
"build": "pnpm prepack",
|
|
77
|
-
"build:watch": "svelte-package --input=src --watch",
|
|
79
|
+
"build:watch": "pnpm clean && pnpm --filter svelte build && svelte-package --input=src --watch",
|
|
78
80
|
"preview": "vite preview",
|
|
79
81
|
"type-check": "svelte-check --tsconfig ./tsconfig.json",
|
|
80
82
|
"type-check:watch": "svelte-check --tsconfig ./tsconfig.json --watch",
|
|
@@ -82,7 +84,8 @@
|
|
|
82
84
|
"prettier-check": "prettier --check .",
|
|
83
85
|
"lint": "eslint .",
|
|
84
86
|
"test": "vitest --run",
|
|
87
|
+
"test:update": "vitest --run -u",
|
|
85
88
|
"test:watch": "vitest",
|
|
86
|
-
"clean": "rm -rf dist"
|
|
89
|
+
"clean": "rm -rf dist *.tsbuildinfo"
|
|
87
90
|
}
|
|
88
91
|
}
|
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
import type { JSONValue, UIMessage } from '
|
|
1
|
+
import type { JSONValue, UIMessage } from 'ai';
|
|
2
2
|
import { createContext, KeyedStore } from './utils.svelte.js';
|
|
3
3
|
|
|
4
|
-
class ChatStore {
|
|
5
|
-
messages = $state<UIMessage[]>([]);
|
|
4
|
+
class ChatStore<MESSAGE_METADATA = unknown> {
|
|
5
|
+
messages = $state<UIMessage<MESSAGE_METADATA>[]>([]);
|
|
6
6
|
data = $state<JSONValue[]>();
|
|
7
7
|
status = $state<'submitted' | 'streaming' | 'ready' | 'error'>('ready');
|
|
8
8
|
error = $state<Error>();
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export class KeyedChatStore extends KeyedStore<
|
|
11
|
+
export class KeyedChatStore<MESSAGE_METADATA = unknown> extends KeyedStore<
|
|
12
|
+
ChatStore<MESSAGE_METADATA>
|
|
13
|
+
> {
|
|
12
14
|
constructor(
|
|
13
|
-
value?:
|
|
15
|
+
value?:
|
|
16
|
+
| Iterable<readonly [string, ChatStore<MESSAGE_METADATA>]>
|
|
17
|
+
| null
|
|
18
|
+
| undefined,
|
|
14
19
|
) {
|
|
15
20
|
super(ChatStore, value);
|
|
16
21
|
}
|
package/src/chat.svelte.ts
CHANGED
|
@@ -1,70 +1,51 @@
|
|
|
1
|
+
import { isAbortError } from '@ai-sdk/provider-utils';
|
|
1
2
|
import {
|
|
2
|
-
fillMessageParts,
|
|
3
|
-
generateId,
|
|
4
|
-
type UIMessage,
|
|
5
|
-
type UseChatOptions,
|
|
6
|
-
type JSONValue,
|
|
7
|
-
type ChatRequest,
|
|
8
|
-
extractMaxToolInvocationStep,
|
|
9
3
|
callChatApi,
|
|
4
|
+
convertFileListToFileUIParts,
|
|
5
|
+
extractMaxToolInvocationStep,
|
|
6
|
+
generateId,
|
|
7
|
+
getToolInvocations,
|
|
8
|
+
isAssistantMessageWithCompletedToolCalls,
|
|
10
9
|
shouldResubmitMessages,
|
|
11
|
-
type Message,
|
|
12
|
-
type CreateMessage,
|
|
13
|
-
type ChatRequestOptions,
|
|
14
|
-
prepareAttachmentsForRequest,
|
|
15
|
-
getMessageParts,
|
|
16
10
|
updateToolCallResult,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
type ChatRequestOptions,
|
|
12
|
+
type CreateUIMessage,
|
|
13
|
+
type JSONValue,
|
|
14
|
+
type UIMessage,
|
|
15
|
+
type UseChatOptions,
|
|
16
|
+
} from 'ai';
|
|
17
|
+
import { untrack } from 'svelte';
|
|
20
18
|
import {
|
|
21
19
|
KeyedChatStore,
|
|
22
20
|
getChatContext,
|
|
23
21
|
hasChatContext,
|
|
24
22
|
} from './chat-context.svelte.js';
|
|
25
|
-
import { untrack } from 'svelte';
|
|
26
23
|
|
|
27
|
-
export type ChatOptions = Readonly<
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
|
|
31
|
-
* Must be at least 1.
|
|
32
|
-
* A maximum number is required to prevent infinite loops in the case of misconfigured tools.
|
|
33
|
-
* By default, it's set to 1, which means that only a single LLM call is made.
|
|
34
|
-
* @default 1
|
|
35
|
-
*/
|
|
36
|
-
maxSteps?: number;
|
|
37
|
-
}
|
|
24
|
+
export type ChatOptions<MESSAGE_METADATA = unknown> = Readonly<
|
|
25
|
+
UseChatOptions<MESSAGE_METADATA>
|
|
38
26
|
>;
|
|
39
27
|
|
|
40
|
-
export type {
|
|
28
|
+
export type { CreateUIMessage, UIMessage };
|
|
41
29
|
|
|
42
|
-
export class Chat {
|
|
43
|
-
readonly #options: ChatOptions = {};
|
|
30
|
+
export class Chat<MESSAGE_METADATA = unknown> {
|
|
31
|
+
readonly #options: ChatOptions<MESSAGE_METADATA> = {};
|
|
44
32
|
readonly #api = $derived(this.#options.api ?? '/api/chat');
|
|
45
33
|
readonly #generateId = $derived(this.#options.generateId ?? generateId);
|
|
46
34
|
readonly #maxSteps = $derived(this.#options.maxSteps ?? 1);
|
|
47
35
|
readonly #streamProtocol = $derived(this.#options.streamProtocol ?? 'data');
|
|
48
|
-
readonly #keyedStore = $state<KeyedChatStore
|
|
36
|
+
readonly #keyedStore = $state<KeyedChatStore<MESSAGE_METADATA>>()!;
|
|
49
37
|
/**
|
|
50
38
|
* The id of the chat. If not provided through the constructor, a random ID will be generated
|
|
51
39
|
* using the provided `generateId` function, or a built-in function if not provided.
|
|
52
40
|
*/
|
|
53
41
|
readonly id = $derived(this.#options.id ?? this.#generateId());
|
|
54
42
|
readonly #store = $derived(this.#keyedStore.get(this.id));
|
|
55
|
-
#abortController: AbortController | undefined;
|
|
56
43
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
get data() {
|
|
63
|
-
return this.#store.data;
|
|
64
|
-
}
|
|
65
|
-
set data(value: JSONValue[] | undefined) {
|
|
66
|
-
this.#store.data = value;
|
|
67
|
-
}
|
|
44
|
+
readonly #messageMetadataSchema = $derived(
|
|
45
|
+
this.#options.messageMetadataSchema,
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
#abortController: AbortController | undefined;
|
|
68
49
|
|
|
69
50
|
/**
|
|
70
51
|
* Hook status:
|
|
@@ -92,18 +73,18 @@ export class Chat {
|
|
|
92
73
|
* This is writable, which is useful when you want to edit the messages on the client, and then
|
|
93
74
|
* trigger {@link reload} to regenerate the AI response.
|
|
94
75
|
*/
|
|
95
|
-
get messages(): UIMessage[] {
|
|
76
|
+
get messages(): UIMessage<MESSAGE_METADATA>[] {
|
|
96
77
|
return this.#store.messages;
|
|
97
78
|
}
|
|
98
|
-
set messages(value:
|
|
99
|
-
untrack(() => (this.#store.messages =
|
|
79
|
+
set messages(value: UIMessage<MESSAGE_METADATA>[]) {
|
|
80
|
+
untrack(() => (this.#store.messages = value));
|
|
100
81
|
}
|
|
101
82
|
|
|
102
|
-
constructor(options: ChatOptions = {}) {
|
|
83
|
+
constructor(options: ChatOptions<MESSAGE_METADATA> = {}) {
|
|
103
84
|
if (hasChatContext()) {
|
|
104
|
-
this.#keyedStore = getChatContext()
|
|
85
|
+
this.#keyedStore = getChatContext() as KeyedChatStore<MESSAGE_METADATA>;
|
|
105
86
|
} else {
|
|
106
|
-
this.#keyedStore = new KeyedChatStore();
|
|
87
|
+
this.#keyedStore = new KeyedChatStore<MESSAGE_METADATA>();
|
|
107
88
|
}
|
|
108
89
|
|
|
109
90
|
this.#options = options;
|
|
@@ -118,20 +99,12 @@ export class Chat {
|
|
|
118
99
|
* @param options Additional options to pass to the API call
|
|
119
100
|
*/
|
|
120
101
|
append = async (
|
|
121
|
-
message:
|
|
122
|
-
{ data, headers, body
|
|
102
|
+
message: UIMessage<MESSAGE_METADATA> | CreateUIMessage<MESSAGE_METADATA>,
|
|
103
|
+
{ data, headers, body }: ChatRequestOptions = {},
|
|
123
104
|
) => {
|
|
124
|
-
const attachmentsForRequest = await prepareAttachmentsForRequest(
|
|
125
|
-
experimental_attachments,
|
|
126
|
-
);
|
|
127
|
-
|
|
128
105
|
const messages = this.messages.concat({
|
|
129
106
|
...message,
|
|
130
107
|
id: message.id ?? this.#generateId(),
|
|
131
|
-
createdAt: message.createdAt ?? new Date(),
|
|
132
|
-
experimental_attachments:
|
|
133
|
-
attachmentsForRequest.length > 0 ? attachmentsForRequest : undefined,
|
|
134
|
-
parts: getMessageParts(message),
|
|
135
108
|
});
|
|
136
109
|
|
|
137
110
|
return this.#triggerRequest({ messages, headers, body, data });
|
|
@@ -176,26 +149,27 @@ export class Chat {
|
|
|
176
149
|
/** Form submission handler to automatically reset input and append a user message */
|
|
177
150
|
handleSubmit = async (
|
|
178
151
|
event?: { preventDefault?: () => void },
|
|
179
|
-
options: ChatRequestOptions = {},
|
|
152
|
+
options: ChatRequestOptions & { files?: FileList } = {},
|
|
180
153
|
) => {
|
|
181
154
|
event?.preventDefault?.();
|
|
182
155
|
if (!this.input && !options.allowEmptySubmit) return;
|
|
183
156
|
|
|
184
|
-
const
|
|
185
|
-
options.
|
|
186
|
-
|
|
157
|
+
const fileParts = Array.isArray(options?.files)
|
|
158
|
+
? options.files
|
|
159
|
+
: await convertFileListToFileUIParts(options?.files);
|
|
187
160
|
|
|
188
161
|
const messages = this.messages.concat({
|
|
189
162
|
id: this.#generateId(),
|
|
190
|
-
createdAt: new Date(),
|
|
191
163
|
role: 'user',
|
|
192
|
-
|
|
193
|
-
experimental_attachments:
|
|
194
|
-
attachmentsForRequest.length > 0 ? attachmentsForRequest : undefined,
|
|
195
|
-
parts: [{ type: 'text', text: this.input }],
|
|
164
|
+
parts: [...fileParts, { type: 'text', text: this.input }],
|
|
196
165
|
});
|
|
197
166
|
|
|
198
|
-
const chatRequest:
|
|
167
|
+
const chatRequest: {
|
|
168
|
+
headers?: Record<string, string> | Headers;
|
|
169
|
+
body?: object;
|
|
170
|
+
messages: UIMessage<MESSAGE_METADATA>[];
|
|
171
|
+
data?: JSONValue;
|
|
172
|
+
} = {
|
|
199
173
|
messages,
|
|
200
174
|
headers: options.headers,
|
|
201
175
|
body: options.body,
|
|
@@ -234,14 +208,19 @@ export class Chat {
|
|
|
234
208
|
}
|
|
235
209
|
};
|
|
236
210
|
|
|
237
|
-
#triggerRequest = async (chatRequest:
|
|
211
|
+
#triggerRequest = async (chatRequest: {
|
|
212
|
+
headers?: Record<string, string> | Headers;
|
|
213
|
+
body?: object;
|
|
214
|
+
messages: UIMessage<MESSAGE_METADATA>[];
|
|
215
|
+
data?: JSONValue;
|
|
216
|
+
}) => {
|
|
238
217
|
this.#store.status = 'submitted';
|
|
239
218
|
this.#store.error = undefined;
|
|
240
219
|
|
|
241
|
-
const messages =
|
|
220
|
+
const messages = chatRequest.messages;
|
|
242
221
|
const messageCount = messages.length;
|
|
243
222
|
const maxStep = extractMaxToolInvocationStep(
|
|
244
|
-
messages[messages.length - 1]
|
|
223
|
+
getToolInvocations(messages[messages.length - 1]),
|
|
245
224
|
);
|
|
246
225
|
|
|
247
226
|
try {
|
|
@@ -251,36 +230,11 @@ export class Chat {
|
|
|
251
230
|
// Optimistically update messages
|
|
252
231
|
this.messages = messages;
|
|
253
232
|
|
|
254
|
-
const constructedMessagesPayload = this.#options.sendExtraMessageFields
|
|
255
|
-
? messages
|
|
256
|
-
: messages.map(
|
|
257
|
-
({
|
|
258
|
-
role,
|
|
259
|
-
content,
|
|
260
|
-
experimental_attachments,
|
|
261
|
-
data,
|
|
262
|
-
annotations,
|
|
263
|
-
toolInvocations,
|
|
264
|
-
parts,
|
|
265
|
-
}) => ({
|
|
266
|
-
role,
|
|
267
|
-
content,
|
|
268
|
-
...(experimental_attachments !== undefined && {
|
|
269
|
-
experimental_attachments,
|
|
270
|
-
}),
|
|
271
|
-
...(data !== undefined && { data }),
|
|
272
|
-
...(annotations !== undefined && { annotations }),
|
|
273
|
-
...(toolInvocations !== undefined && { toolInvocations }),
|
|
274
|
-
...(parts !== undefined && { parts }),
|
|
275
|
-
}),
|
|
276
|
-
);
|
|
277
|
-
|
|
278
|
-
const existingData = this.data ?? [];
|
|
279
233
|
await callChatApi({
|
|
280
234
|
api: this.#api,
|
|
281
235
|
body: {
|
|
282
236
|
id: this.id,
|
|
283
|
-
messages
|
|
237
|
+
messages,
|
|
284
238
|
data: chatRequest.data,
|
|
285
239
|
...$state.snapshot(this.#options.body),
|
|
286
240
|
...chatRequest.body,
|
|
@@ -292,29 +246,29 @@ export class Chat {
|
|
|
292
246
|
...chatRequest.headers,
|
|
293
247
|
},
|
|
294
248
|
abortController: () => abortController,
|
|
295
|
-
restoreMessagesOnFailure: () => {},
|
|
296
249
|
onResponse: this.#options.onResponse,
|
|
297
|
-
onUpdate: ({ message
|
|
250
|
+
onUpdate: ({ message }) => {
|
|
298
251
|
this.#store.status = 'streaming';
|
|
299
252
|
|
|
253
|
+
const replaceLastMessage =
|
|
254
|
+
message.id === messages[messages.length - 1].id;
|
|
255
|
+
|
|
300
256
|
this.messages = messages;
|
|
301
257
|
if (replaceLastMessage) {
|
|
302
258
|
this.messages[this.messages.length - 1] = message;
|
|
303
259
|
} else {
|
|
304
260
|
this.messages.push(message);
|
|
305
261
|
}
|
|
306
|
-
|
|
307
|
-
if (data?.length) {
|
|
308
|
-
this.data = existingData;
|
|
309
|
-
this.data.push(...data);
|
|
310
|
-
}
|
|
311
262
|
},
|
|
312
263
|
onToolCall: this.#options.onToolCall,
|
|
313
264
|
onFinish: this.#options.onFinish,
|
|
314
265
|
generateId: this.#generateId,
|
|
315
266
|
fetch: this.#options.fetch,
|
|
316
267
|
// callChatApi calls structuredClone on the message
|
|
317
|
-
lastMessage: $state.snapshot(
|
|
268
|
+
lastMessage: $state.snapshot(
|
|
269
|
+
this.messages[this.messages.length - 1],
|
|
270
|
+
) as UIMessage<MESSAGE_METADATA>,
|
|
271
|
+
messageMetadataSchema: this.#messageMetadataSchema,
|
|
318
272
|
});
|
|
319
273
|
|
|
320
274
|
this.#abortController = undefined;
|
package/src/completion.svelte.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
+
callCompletionApi,
|
|
2
3
|
generateId,
|
|
4
|
+
type CompletionRequestOptions,
|
|
3
5
|
type UseCompletionOptions,
|
|
4
|
-
|
|
5
|
-
type RequestOptions,
|
|
6
|
-
callCompletionApi,
|
|
7
|
-
} from '@ai-sdk/ui-utils';
|
|
6
|
+
} from 'ai';
|
|
8
7
|
import {
|
|
9
8
|
KeyedCompletionStore,
|
|
10
9
|
getCompletionContext,
|
|
@@ -30,18 +29,6 @@ export class Completion {
|
|
|
30
29
|
this.#store.completions.set(this.#id, value);
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
/**
|
|
34
|
-
* Additional data added on the server via StreamData.
|
|
35
|
-
*
|
|
36
|
-
* This is writable, so you can use it to transform or clear the chat data.
|
|
37
|
-
*/
|
|
38
|
-
get data() {
|
|
39
|
-
return this.#store.data;
|
|
40
|
-
}
|
|
41
|
-
set data(value: JSONValue[]) {
|
|
42
|
-
this.#store.data = value;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
32
|
/** The error object of the API request */
|
|
46
33
|
get error() {
|
|
47
34
|
return this.#store.error;
|
|
@@ -58,12 +45,9 @@ export class Completion {
|
|
|
58
45
|
}
|
|
59
46
|
|
|
60
47
|
constructor(options: CompletionOptions = {}) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
this.#keyedStore = new KeyedCompletionStore();
|
|
65
|
-
}
|
|
66
|
-
|
|
48
|
+
this.#keyedStore = hasCompletionContext()
|
|
49
|
+
? getCompletionContext()
|
|
50
|
+
: new KeyedCompletionStore();
|
|
67
51
|
this.#options = options;
|
|
68
52
|
this.completion = options.initialCompletion ?? '';
|
|
69
53
|
this.input = options.initialInput ?? '';
|
|
@@ -86,7 +70,7 @@ export class Completion {
|
|
|
86
70
|
/**
|
|
87
71
|
* Send a new prompt to the API endpoint and update the completion state.
|
|
88
72
|
*/
|
|
89
|
-
complete = async (prompt: string, options?:
|
|
73
|
+
complete = async (prompt: string, options?: CompletionRequestOptions) =>
|
|
90
74
|
this.#triggerRequest(prompt, options);
|
|
91
75
|
|
|
92
76
|
/** Form submission handler to automatically reset input and call the completion API */
|
|
@@ -97,7 +81,10 @@ export class Completion {
|
|
|
97
81
|
}
|
|
98
82
|
};
|
|
99
83
|
|
|
100
|
-
#triggerRequest = async (
|
|
84
|
+
#triggerRequest = async (
|
|
85
|
+
prompt: string,
|
|
86
|
+
options?: CompletionRequestOptions,
|
|
87
|
+
) => {
|
|
101
88
|
return callCompletionApi({
|
|
102
89
|
api: this.#api,
|
|
103
90
|
prompt,
|
|
@@ -113,9 +100,6 @@ export class Completion {
|
|
|
113
100
|
setCompletion: completion => {
|
|
114
101
|
this.completion = completion;
|
|
115
102
|
},
|
|
116
|
-
onData: data => {
|
|
117
|
-
this.data.push(...data);
|
|
118
|
-
},
|
|
119
103
|
setLoading: loading => {
|
|
120
104
|
this.#store.loading = loading;
|
|
121
105
|
},
|
package/src/index.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
parsePartialJson,
|
|
11
11
|
type DeepPartial,
|
|
12
12
|
type Schema,
|
|
13
|
-
} from '
|
|
13
|
+
} from 'ai';
|
|
14
14
|
import { type z } from 'zod';
|
|
15
15
|
import {
|
|
16
16
|
getStructuredObjectContext,
|
|
@@ -177,13 +177,13 @@ export class StructuredObject<RESULT, INPUT = unknown> {
|
|
|
177
177
|
|
|
178
178
|
await response.body.pipeThrough(new TextDecoderStream()).pipeTo(
|
|
179
179
|
new WritableStream<string>({
|
|
180
|
-
write: chunk => {
|
|
180
|
+
write: async chunk => {
|
|
181
181
|
if (abortController?.signal.aborted) {
|
|
182
182
|
throw new DOMException('Stream aborted', 'AbortError');
|
|
183
183
|
}
|
|
184
184
|
accumulatedText += chunk;
|
|
185
185
|
|
|
186
|
-
const { value } = parsePartialJson(accumulatedText);
|
|
186
|
+
const { value } = await parsePartialJson(accumulatedText);
|
|
187
187
|
const currentObject = value as DeepPartial<RESULT>;
|
|
188
188
|
|
|
189
189
|
if (!isDeepEqualData(latestObject, currentObject)) {
|
|
@@ -193,12 +193,12 @@ export class StructuredObject<RESULT, INPUT = unknown> {
|
|
|
193
193
|
}
|
|
194
194
|
},
|
|
195
195
|
|
|
196
|
-
close: () => {
|
|
196
|
+
close: async () => {
|
|
197
197
|
this.#store.loading = false;
|
|
198
198
|
this.#abortController = undefined;
|
|
199
199
|
|
|
200
200
|
if (this.#options.onFinish != null) {
|
|
201
|
-
const validationResult = safeValidateTypes({
|
|
201
|
+
const validationResult = await safeValidateTypes({
|
|
202
202
|
value: latestObject,
|
|
203
203
|
schema: asSchema(this.#options.schema),
|
|
204
204
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts" generics="RESULT">
|
|
2
2
|
import { createAIContext } from '../context-provider.js';
|
|
3
3
|
import { StructuredObject } from '../structured-object.svelte.js';
|
|
4
|
-
import type { Schema } from '
|
|
4
|
+
import type { Schema } from 'ai';
|
|
5
5
|
import type { z } from 'zod';
|
|
6
6
|
|
|
7
7
|
let {
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { JSONValue, UIMessage } from '@ai-sdk/ui-utils';
|
|
2
|
-
import { KeyedStore } from './utils.svelte.js';
|
|
3
|
-
declare class ChatStore {
|
|
4
|
-
messages: UIMessage[];
|
|
5
|
-
data: JSONValue[] | undefined;
|
|
6
|
-
status: "submitted" | "streaming" | "ready" | "error";
|
|
7
|
-
error: Error | undefined;
|
|
8
|
-
}
|
|
9
|
-
export declare class KeyedChatStore extends KeyedStore<ChatStore> {
|
|
10
|
-
constructor(value?: Iterable<readonly [string, ChatStore]> | null | undefined);
|
|
11
|
-
}
|
|
12
|
-
export declare const hasChatContext: () => boolean, getChatContext: () => KeyedChatStore, setChatContext: (value: KeyedChatStore) => KeyedChatStore;
|
|
13
|
-
export {};
|
|
14
|
-
//# sourceMappingURL=chat-context.svelte.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"chat-context.svelte.d.ts","sourceRoot":"","sources":["../src/chat-context.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAiB,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE9D,cAAM,SAAS;IACb,QAAQ,cAA2B;IACnC,IAAI,0BAAyB;IAC7B,MAAM,gDAAkE;IACxE,KAAK,oBAAmB;CACzB;AAED,qBAAa,cAAe,SAAQ,UAAU,CAAC,SAAS,CAAC;gBAErD,KAAK,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS;CAIpE;AAED,eAAO,MACO,cAAc,iBACd,cAAc,wBACd,cAAc,2CACa,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { JSONValue } from '@ai-sdk/ui-utils';
|
|
2
|
-
import { SvelteMap } from 'svelte/reactivity';
|
|
3
|
-
import { KeyedStore } from './utils.svelte.js';
|
|
4
|
-
declare class CompletionStore {
|
|
5
|
-
completions: SvelteMap<string, string>;
|
|
6
|
-
data: JSONValue[];
|
|
7
|
-
loading: boolean;
|
|
8
|
-
error: Error | undefined;
|
|
9
|
-
}
|
|
10
|
-
export declare class KeyedCompletionStore extends KeyedStore<CompletionStore> {
|
|
11
|
-
constructor(value?: Iterable<readonly [string, CompletionStore]> | null | undefined);
|
|
12
|
-
}
|
|
13
|
-
export declare const hasCompletionContext: () => boolean, getCompletionContext: () => KeyedCompletionStore, setCompletionContext: (value: KeyedCompletionStore) => KeyedCompletionStore;
|
|
14
|
-
export {};
|
|
15
|
-
//# sourceMappingURL=completion-context.svelte.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"completion-context.svelte.d.ts","sourceRoot":"","sources":["../src/completion-context.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAiB,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE9D,cAAM,eAAe;IACnB,WAAW,4BAAmC;IAC9C,IAAI,cAA2B;IAC/B,OAAO,UAAiB;IACxB,KAAK,oBAAmB;CACzB;AAED,qBAAa,oBAAqB,SAAQ,UAAU,CAAC,eAAe,CAAC;gBAEjE,KAAK,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS;CAI1E;AAED,eAAO,MACO,oBAAoB,iBACpB,oBAAoB,8BACpB,oBAAoB,uDACmB,CAAC"}
|