@ai-sdk/svelte 3.0.0-canary.14 → 3.0.0-canary.15
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 +13 -0
- package/dist/chat.svelte.d.ts +4 -4
- package/dist/chat.svelte.d.ts.map +1 -1
- package/dist/chat.svelte.js +7 -8
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/chat.svelte.ts +20 -24
- package/src/index.ts +1 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @ai-sdk/svelte
|
|
2
2
|
|
|
3
|
+
## 3.0.0-canary.15
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [ec78cdc]
|
|
8
|
+
- Updated dependencies [9b4d074]
|
|
9
|
+
- Updated dependencies [8b86e99]
|
|
10
|
+
- Updated dependencies [28ad69e]
|
|
11
|
+
- Updated dependencies [2524fc7]
|
|
12
|
+
- Updated dependencies [ec5933d]
|
|
13
|
+
- Updated dependencies [175b868]
|
|
14
|
+
- ai@5.0.0-canary.16
|
|
15
|
+
|
|
3
16
|
## 3.0.0-canary.14
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/chat.svelte.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type ChatRequestOptions, type CreateUIMessage, type JSONValue, type UIMessage, type UseChatOptions } from 'ai';
|
|
2
2
|
export type ChatOptions = Readonly<Omit<UseChatOptions, 'keepLastMessageOnError'> & {
|
|
3
3
|
/**
|
|
4
4
|
* Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
|
|
@@ -9,7 +9,7 @@ export type ChatOptions = Readonly<Omit<UseChatOptions, 'keepLastMessageOnError'
|
|
|
9
9
|
*/
|
|
10
10
|
maxSteps?: number;
|
|
11
11
|
}>;
|
|
12
|
-
export type {
|
|
12
|
+
export type { CreateUIMessage, UIMessage };
|
|
13
13
|
export declare class Chat {
|
|
14
14
|
#private;
|
|
15
15
|
/**
|
|
@@ -44,7 +44,7 @@ export declare class Chat {
|
|
|
44
44
|
* trigger {@link reload} to regenerate the AI response.
|
|
45
45
|
*/
|
|
46
46
|
get messages(): UIMessage[];
|
|
47
|
-
set messages(value:
|
|
47
|
+
set messages(value: UIMessage[]);
|
|
48
48
|
constructor(options?: ChatOptions);
|
|
49
49
|
/**
|
|
50
50
|
* Append a user message to the chat list. This triggers the API call to fetch
|
|
@@ -52,7 +52,7 @@ export declare class Chat {
|
|
|
52
52
|
* @param message The message to append
|
|
53
53
|
* @param options Additional options to pass to the API call
|
|
54
54
|
*/
|
|
55
|
-
append: (message:
|
|
55
|
+
append: (message: UIMessage | CreateUIMessage, { data, headers, body, experimental_attachments }?: ChatRequestOptions) => Promise<void>;
|
|
56
56
|
/**
|
|
57
57
|
* Reload the last AI chat response for the given chat history. If the last
|
|
58
58
|
* message isn't from the assistant, it will request the API to generate a
|
|
@@ -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,EAUL,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,cAAc,EACpB,MAAM,IAAI,CAAC;AAQZ,MAAM,MAAM,WAAW,GAAG,QAAQ,CAChC,IAAI,CAAC,cAAc,EAAE,wBAAwB,CAAC,GAAG;IAC/C;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CACF,CAAC;AAEF,YAAY,EAAE,eAAe,EAAE,SAAS,EAAE,CAAC;AAE3C,qBAAa,IAAI;;IAOf;;;OAGG;IACH,QAAQ,CAAC,EAAE,SAAoD;IAI/D;;;;OAIG;IACH,IAAI,IAAI,IAGQ,SAAS,EAAE,GAAG,SAAS,CADtC;IACD,IAAI,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,SAAS,EAEtC;IAED;;;;;;;OAOG;IACH,IAAI,MAAM,kDAET;IAED,0CAA0C;IAC1C,IAAI,KAAK,sBAER;IAED,mFAAmF;IACnF,KAAK,SAAqB;IAE1B;;;;;OAKG;IACH,IAAI,QAAQ,IAAI,SAAS,EAAE,CAE1B;IACD,IAAI,QAAQ,CAAC,KAAK,EAAE,SAAS,EAAE,EAE9B;gBAEW,OAAO,GAAE,WAAgB;IAYrC;;;;;OAKG;IACH,MAAM,YACK,SAAS,GAAG,eAAe,sDACe,kBAAkB,mBAgBrE;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,mBA6B3B;IAEF,aAAa,4BAGV;QACD,UAAU,EAAE,MAAM,CAAC;QACnB,MAAM,EAAE,OAAO,CAAC;KACjB,mBAmBC;CA+GH"}
|
package/dist/chat.svelte.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { fillMessageParts, generateId, extractMaxToolInvocationStep, callChatApi, shouldResubmitMessages, prepareAttachmentsForRequest, getMessageParts, updateToolCallResult, isAssistantMessageWithCompletedToolCalls, } from 'ai';
|
|
2
1
|
import { isAbortError } from '@ai-sdk/provider-utils';
|
|
3
|
-
import {
|
|
2
|
+
import { callChatApi, extractMaxToolInvocationStep, generateId, getToolInvocations, isAssistantMessageWithCompletedToolCalls, prepareAttachmentsForRequest, 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');
|
|
@@ -54,7 +54,7 @@ export class Chat {
|
|
|
54
54
|
return this.#store.messages;
|
|
55
55
|
}
|
|
56
56
|
set messages(value) {
|
|
57
|
-
untrack(() => (this.#store.messages =
|
|
57
|
+
untrack(() => (this.#store.messages = value));
|
|
58
58
|
}
|
|
59
59
|
constructor(options = {}) {
|
|
60
60
|
if (hasChatContext()) {
|
|
@@ -80,7 +80,7 @@ export class Chat {
|
|
|
80
80
|
id: message.id ?? this.#generateId(),
|
|
81
81
|
createdAt: message.createdAt ?? new Date(),
|
|
82
82
|
experimental_attachments: attachmentsForRequest.length > 0 ? attachmentsForRequest : undefined,
|
|
83
|
-
parts:
|
|
83
|
+
parts: message.parts,
|
|
84
84
|
});
|
|
85
85
|
return this.#triggerRequest({ messages, headers, body, data });
|
|
86
86
|
};
|
|
@@ -161,9 +161,9 @@ export class Chat {
|
|
|
161
161
|
#triggerRequest = async (chatRequest) => {
|
|
162
162
|
this.#store.status = 'submitted';
|
|
163
163
|
this.#store.error = undefined;
|
|
164
|
-
const messages =
|
|
164
|
+
const messages = chatRequest.messages;
|
|
165
165
|
const messageCount = messages.length;
|
|
166
|
-
const maxStep = extractMaxToolInvocationStep(messages[messages.length - 1]
|
|
166
|
+
const maxStep = extractMaxToolInvocationStep(getToolInvocations(messages[messages.length - 1]));
|
|
167
167
|
try {
|
|
168
168
|
const abortController = new AbortController();
|
|
169
169
|
this.#abortController = abortController;
|
|
@@ -171,14 +171,13 @@ export class Chat {
|
|
|
171
171
|
this.messages = messages;
|
|
172
172
|
const constructedMessagesPayload = this.#options.sendExtraMessageFields
|
|
173
173
|
? messages
|
|
174
|
-
: messages.map(({ role, content, experimental_attachments, annotations,
|
|
174
|
+
: messages.map(({ role, content, experimental_attachments, annotations, parts, }) => ({
|
|
175
175
|
role,
|
|
176
176
|
content,
|
|
177
177
|
...(experimental_attachments !== undefined && {
|
|
178
178
|
experimental_attachments,
|
|
179
179
|
}),
|
|
180
180
|
...(annotations !== undefined && { annotations }),
|
|
181
|
-
...(toolInvocations !== undefined && { toolInvocations }),
|
|
182
181
|
...(parts !== undefined && { parts }),
|
|
183
182
|
}));
|
|
184
183
|
const existingData = this.data ?? [];
|
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"}
|
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.15",
|
|
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.13",
|
|
40
|
+
"ai": "5.0.0-canary.16"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/node": "20.17.24",
|
package/src/chat.svelte.ts
CHANGED
|
@@ -1,28 +1,26 @@
|
|
|
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,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
extractMaxToolInvocationStep,
|
|
5
|
+
generateId,
|
|
6
|
+
getToolInvocations,
|
|
7
|
+
isAssistantMessageWithCompletedToolCalls,
|
|
14
8
|
prepareAttachmentsForRequest,
|
|
15
|
-
|
|
9
|
+
shouldResubmitMessages,
|
|
16
10
|
updateToolCallResult,
|
|
17
|
-
|
|
11
|
+
type ChatRequest,
|
|
12
|
+
type ChatRequestOptions,
|
|
13
|
+
type CreateUIMessage,
|
|
14
|
+
type JSONValue,
|
|
15
|
+
type UIMessage,
|
|
16
|
+
type UseChatOptions,
|
|
18
17
|
} from 'ai';
|
|
19
|
-
import {
|
|
18
|
+
import { untrack } from 'svelte';
|
|
20
19
|
import {
|
|
21
20
|
KeyedChatStore,
|
|
22
21
|
getChatContext,
|
|
23
22
|
hasChatContext,
|
|
24
23
|
} from './chat-context.svelte.js';
|
|
25
|
-
import { untrack } from 'svelte';
|
|
26
24
|
|
|
27
25
|
export type ChatOptions = Readonly<
|
|
28
26
|
Omit<UseChatOptions, 'keepLastMessageOnError'> & {
|
|
@@ -37,7 +35,7 @@ export type ChatOptions = Readonly<
|
|
|
37
35
|
}
|
|
38
36
|
>;
|
|
39
37
|
|
|
40
|
-
export type {
|
|
38
|
+
export type { CreateUIMessage, UIMessage };
|
|
41
39
|
|
|
42
40
|
export class Chat {
|
|
43
41
|
readonly #options: ChatOptions = {};
|
|
@@ -95,8 +93,8 @@ export class Chat {
|
|
|
95
93
|
get messages(): UIMessage[] {
|
|
96
94
|
return this.#store.messages;
|
|
97
95
|
}
|
|
98
|
-
set messages(value:
|
|
99
|
-
untrack(() => (this.#store.messages =
|
|
96
|
+
set messages(value: UIMessage[]) {
|
|
97
|
+
untrack(() => (this.#store.messages = value));
|
|
100
98
|
}
|
|
101
99
|
|
|
102
100
|
constructor(options: ChatOptions = {}) {
|
|
@@ -118,7 +116,7 @@ export class Chat {
|
|
|
118
116
|
* @param options Additional options to pass to the API call
|
|
119
117
|
*/
|
|
120
118
|
append = async (
|
|
121
|
-
message:
|
|
119
|
+
message: UIMessage | CreateUIMessage,
|
|
122
120
|
{ data, headers, body, experimental_attachments }: ChatRequestOptions = {},
|
|
123
121
|
) => {
|
|
124
122
|
const attachmentsForRequest = await prepareAttachmentsForRequest(
|
|
@@ -131,7 +129,7 @@ export class Chat {
|
|
|
131
129
|
createdAt: message.createdAt ?? new Date(),
|
|
132
130
|
experimental_attachments:
|
|
133
131
|
attachmentsForRequest.length > 0 ? attachmentsForRequest : undefined,
|
|
134
|
-
parts:
|
|
132
|
+
parts: message.parts,
|
|
135
133
|
});
|
|
136
134
|
|
|
137
135
|
return this.#triggerRequest({ messages, headers, body, data });
|
|
@@ -238,10 +236,10 @@ export class Chat {
|
|
|
238
236
|
this.#store.status = 'submitted';
|
|
239
237
|
this.#store.error = undefined;
|
|
240
238
|
|
|
241
|
-
const messages =
|
|
239
|
+
const messages = chatRequest.messages;
|
|
242
240
|
const messageCount = messages.length;
|
|
243
241
|
const maxStep = extractMaxToolInvocationStep(
|
|
244
|
-
messages[messages.length - 1]
|
|
242
|
+
getToolInvocations(messages[messages.length - 1]),
|
|
245
243
|
);
|
|
246
244
|
|
|
247
245
|
try {
|
|
@@ -259,7 +257,6 @@ export class Chat {
|
|
|
259
257
|
content,
|
|
260
258
|
experimental_attachments,
|
|
261
259
|
annotations,
|
|
262
|
-
toolInvocations,
|
|
263
260
|
parts,
|
|
264
261
|
}) => ({
|
|
265
262
|
role,
|
|
@@ -268,7 +265,6 @@ export class Chat {
|
|
|
268
265
|
experimental_attachments,
|
|
269
266
|
}),
|
|
270
267
|
...(annotations !== undefined && { annotations }),
|
|
271
|
-
...(toolInvocations !== undefined && { toolInvocations }),
|
|
272
268
|
...(parts !== undefined && { parts }),
|
|
273
269
|
}),
|
|
274
270
|
);
|