@ai-sdk/svelte 3.0.0-canary.14 → 3.0.0-canary.16
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 +27 -0
- package/dist/chat.svelte.d.ts +11 -5
- package/dist/chat.svelte.d.ts.map +1 -1
- package/dist/chat.svelte.js +16 -19
- 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 +43 -57
- package/src/index.ts +1 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @ai-sdk/svelte
|
|
2
2
|
|
|
3
|
+
## 3.0.0-canary.16
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [f04fb4a]
|
|
8
|
+
- Updated dependencies [fd1924b]
|
|
9
|
+
- Updated dependencies [957b739]
|
|
10
|
+
- Updated dependencies [fafc3f2]
|
|
11
|
+
- Updated dependencies [c9ad635]
|
|
12
|
+
- Updated dependencies [9bd5ab5]
|
|
13
|
+
- Updated dependencies [92cb0a2]
|
|
14
|
+
- ai@5.0.0-canary.17
|
|
15
|
+
- @ai-sdk/provider-utils@3.0.0-canary.14
|
|
16
|
+
|
|
17
|
+
## 3.0.0-canary.15
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [ec78cdc]
|
|
22
|
+
- Updated dependencies [9b4d074]
|
|
23
|
+
- Updated dependencies [8b86e99]
|
|
24
|
+
- Updated dependencies [28ad69e]
|
|
25
|
+
- Updated dependencies [2524fc7]
|
|
26
|
+
- Updated dependencies [ec5933d]
|
|
27
|
+
- Updated dependencies [175b868]
|
|
28
|
+
- ai@5.0.0-canary.16
|
|
29
|
+
|
|
3
30
|
## 3.0.0-canary.14
|
|
4
31
|
|
|
5
32
|
### 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.
|
|
@@ -8,8 +8,11 @@ export type ChatOptions = Readonly<Omit<UseChatOptions, 'keepLastMessageOnError'
|
|
|
8
8
|
* @default 1
|
|
9
9
|
*/
|
|
10
10
|
maxSteps?: number;
|
|
11
|
+
'~internal'?: {
|
|
12
|
+
currentDate?: () => Date;
|
|
13
|
+
};
|
|
11
14
|
}>;
|
|
12
|
-
export type {
|
|
15
|
+
export type { CreateUIMessage, UIMessage };
|
|
13
16
|
export declare class Chat {
|
|
14
17
|
#private;
|
|
15
18
|
/**
|
|
@@ -44,7 +47,8 @@ export declare class Chat {
|
|
|
44
47
|
* trigger {@link reload} to regenerate the AI response.
|
|
45
48
|
*/
|
|
46
49
|
get messages(): UIMessage[];
|
|
47
|
-
set messages(value:
|
|
50
|
+
set messages(value: UIMessage[]);
|
|
51
|
+
private currentDate;
|
|
48
52
|
constructor(options?: ChatOptions);
|
|
49
53
|
/**
|
|
50
54
|
* Append a user message to the chat list. This triggers the API call to fetch
|
|
@@ -52,7 +56,7 @@ export declare class Chat {
|
|
|
52
56
|
* @param message The message to append
|
|
53
57
|
* @param options Additional options to pass to the API call
|
|
54
58
|
*/
|
|
55
|
-
append: (message:
|
|
59
|
+
append: (message: UIMessage | CreateUIMessage, { data, headers, body }?: ChatRequestOptions) => Promise<void>;
|
|
56
60
|
/**
|
|
57
61
|
* Reload the last AI chat response for the given chat history. If the last
|
|
58
62
|
* message isn't from the assistant, it will request the API to generate a
|
|
@@ -66,7 +70,9 @@ export declare class Chat {
|
|
|
66
70
|
/** Form submission handler to automatically reset input and append a user message */
|
|
67
71
|
handleSubmit: (event?: {
|
|
68
72
|
preventDefault?: () => void;
|
|
69
|
-
}, options?: ChatRequestOptions
|
|
73
|
+
}, options?: ChatRequestOptions & {
|
|
74
|
+
files?: FileList;
|
|
75
|
+
}) => Promise<void>;
|
|
70
76
|
addToolResult: ({ toolCallId, result, }: {
|
|
71
77
|
toolCallId: string;
|
|
72
78
|
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,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;IAElB,WAAW,CAAC,EAAE;QACZ,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;KAC1B,CAAC;CACH,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;IAED,OAAO,CAAC,WAAW,CAEjB;gBAEU,OAAO,GAAE,WAAgB;IAYrC;;;;;OAKG;IACH,MAAM,YACK,SAAS,GAAG,eAAe,4BACX,kBAAkB,mBAU3C;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,mBA2BlD;IAEF,aAAa,4BAGV;QACD,UAAU,EAAE,MAAM,CAAC;QACnB,MAAM,EAAE,OAAO,CAAC;KACjB,mBAmBC;CAqGH"}
|
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, 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');
|
|
@@ -54,8 +54,9 @@ 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
|
+
currentDate = $derived(this.#options['~internal']?.currentDate ?? (() => new Date()));
|
|
59
60
|
constructor(options = {}) {
|
|
60
61
|
if (hasChatContext()) {
|
|
61
62
|
this.#keyedStore = getChatContext();
|
|
@@ -73,14 +74,12 @@ export class Chat {
|
|
|
73
74
|
* @param message The message to append
|
|
74
75
|
* @param options Additional options to pass to the API call
|
|
75
76
|
*/
|
|
76
|
-
append = async (message, { data, headers, body
|
|
77
|
-
const attachmentsForRequest = await prepareAttachmentsForRequest(experimental_attachments);
|
|
77
|
+
append = async (message, { data, headers, body } = {}) => {
|
|
78
78
|
const messages = this.messages.concat({
|
|
79
79
|
...message,
|
|
80
80
|
id: message.id ?? this.#generateId(),
|
|
81
|
-
createdAt: message.createdAt ??
|
|
82
|
-
|
|
83
|
-
parts: getMessageParts(message),
|
|
81
|
+
createdAt: message.createdAt ?? this.currentDate(),
|
|
82
|
+
parts: message.parts,
|
|
84
83
|
});
|
|
85
84
|
return this.#triggerRequest({ messages, headers, body, data });
|
|
86
85
|
};
|
|
@@ -123,14 +122,15 @@ export class Chat {
|
|
|
123
122
|
event?.preventDefault?.();
|
|
124
123
|
if (!this.input && !options.allowEmptySubmit)
|
|
125
124
|
return;
|
|
126
|
-
const
|
|
125
|
+
const fileParts = Array.isArray(options?.files)
|
|
126
|
+
? options.files
|
|
127
|
+
: await convertFileListToFileUIParts(options?.files);
|
|
127
128
|
const messages = this.messages.concat({
|
|
128
129
|
id: this.#generateId(),
|
|
129
|
-
createdAt:
|
|
130
|
+
createdAt: this.currentDate(),
|
|
130
131
|
role: 'user',
|
|
131
132
|
content: this.input,
|
|
132
|
-
|
|
133
|
-
parts: [{ type: 'text', text: this.input }],
|
|
133
|
+
parts: [...fileParts, { type: 'text', text: this.input }],
|
|
134
134
|
});
|
|
135
135
|
const chatRequest = {
|
|
136
136
|
messages,
|
|
@@ -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,10 @@ export class Chat {
|
|
|
171
171
|
this.messages = messages;
|
|
172
172
|
const constructedMessagesPayload = this.#options.sendExtraMessageFields
|
|
173
173
|
? messages
|
|
174
|
-
: messages.map(({ role, content,
|
|
174
|
+
: messages.map(({ role, content, annotations, parts }) => ({
|
|
175
175
|
role,
|
|
176
176
|
content,
|
|
177
|
-
...(experimental_attachments !== undefined && {
|
|
178
|
-
experimental_attachments,
|
|
179
|
-
}),
|
|
180
177
|
...(annotations !== undefined && { annotations }),
|
|
181
|
-
...(toolInvocations !== undefined && { toolInvocations }),
|
|
182
178
|
...(parts !== undefined && { parts }),
|
|
183
179
|
}));
|
|
184
180
|
const existingData = this.data ?? [];
|
|
@@ -217,6 +213,7 @@ export class Chat {
|
|
|
217
213
|
onToolCall: this.#options.onToolCall,
|
|
218
214
|
onFinish: this.#options.onFinish,
|
|
219
215
|
generateId: this.#generateId,
|
|
216
|
+
getCurrentDate: this.currentDate,
|
|
220
217
|
fetch: this.#options.fetch,
|
|
221
218
|
// callChatApi calls structuredClone on the message
|
|
222
219
|
lastMessage: $state.snapshot(this.messages[this.messages.length - 1]),
|
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.16",
|
|
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.14",
|
|
40
|
+
"ai": "5.0.0-canary.17"
|
|
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,
|
|
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
|
-
|
|
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'> & {
|
|
@@ -34,10 +32,14 @@ export type ChatOptions = Readonly<
|
|
|
34
32
|
* @default 1
|
|
35
33
|
*/
|
|
36
34
|
maxSteps?: number;
|
|
35
|
+
|
|
36
|
+
'~internal'?: {
|
|
37
|
+
currentDate?: () => Date;
|
|
38
|
+
};
|
|
37
39
|
}
|
|
38
40
|
>;
|
|
39
41
|
|
|
40
|
-
export type {
|
|
42
|
+
export type { CreateUIMessage, UIMessage };
|
|
41
43
|
|
|
42
44
|
export class Chat {
|
|
43
45
|
readonly #options: ChatOptions = {};
|
|
@@ -95,10 +97,14 @@ export class Chat {
|
|
|
95
97
|
get messages(): UIMessage[] {
|
|
96
98
|
return this.#store.messages;
|
|
97
99
|
}
|
|
98
|
-
set messages(value:
|
|
99
|
-
untrack(() => (this.#store.messages =
|
|
100
|
+
set messages(value: UIMessage[]) {
|
|
101
|
+
untrack(() => (this.#store.messages = value));
|
|
100
102
|
}
|
|
101
103
|
|
|
104
|
+
private currentDate = $derived(
|
|
105
|
+
this.#options['~internal']?.currentDate ?? (() => new Date()),
|
|
106
|
+
);
|
|
107
|
+
|
|
102
108
|
constructor(options: ChatOptions = {}) {
|
|
103
109
|
if (hasChatContext()) {
|
|
104
110
|
this.#keyedStore = getChatContext();
|
|
@@ -118,20 +124,14 @@ export class Chat {
|
|
|
118
124
|
* @param options Additional options to pass to the API call
|
|
119
125
|
*/
|
|
120
126
|
append = async (
|
|
121
|
-
message:
|
|
122
|
-
{ data, headers, body
|
|
127
|
+
message: UIMessage | CreateUIMessage,
|
|
128
|
+
{ data, headers, body }: ChatRequestOptions = {},
|
|
123
129
|
) => {
|
|
124
|
-
const attachmentsForRequest = await prepareAttachmentsForRequest(
|
|
125
|
-
experimental_attachments,
|
|
126
|
-
);
|
|
127
|
-
|
|
128
130
|
const messages = this.messages.concat({
|
|
129
131
|
...message,
|
|
130
132
|
id: message.id ?? this.#generateId(),
|
|
131
|
-
createdAt: message.createdAt ??
|
|
132
|
-
|
|
133
|
-
attachmentsForRequest.length > 0 ? attachmentsForRequest : undefined,
|
|
134
|
-
parts: getMessageParts(message),
|
|
133
|
+
createdAt: message.createdAt ?? this.currentDate(),
|
|
134
|
+
parts: message.parts,
|
|
135
135
|
});
|
|
136
136
|
|
|
137
137
|
return this.#triggerRequest({ messages, headers, body, data });
|
|
@@ -176,23 +176,21 @@ export class Chat {
|
|
|
176
176
|
/** Form submission handler to automatically reset input and append a user message */
|
|
177
177
|
handleSubmit = async (
|
|
178
178
|
event?: { preventDefault?: () => void },
|
|
179
|
-
options: ChatRequestOptions = {},
|
|
179
|
+
options: ChatRequestOptions & { files?: FileList } = {},
|
|
180
180
|
) => {
|
|
181
181
|
event?.preventDefault?.();
|
|
182
182
|
if (!this.input && !options.allowEmptySubmit) return;
|
|
183
183
|
|
|
184
|
-
const
|
|
185
|
-
options.
|
|
186
|
-
|
|
184
|
+
const fileParts = Array.isArray(options?.files)
|
|
185
|
+
? options.files
|
|
186
|
+
: await convertFileListToFileUIParts(options?.files);
|
|
187
187
|
|
|
188
188
|
const messages = this.messages.concat({
|
|
189
189
|
id: this.#generateId(),
|
|
190
|
-
createdAt:
|
|
190
|
+
createdAt: this.currentDate(),
|
|
191
191
|
role: 'user',
|
|
192
192
|
content: this.input,
|
|
193
|
-
|
|
194
|
-
attachmentsForRequest.length > 0 ? attachmentsForRequest : undefined,
|
|
195
|
-
parts: [{ type: 'text', text: this.input }],
|
|
193
|
+
parts: [...fileParts, { type: 'text', text: this.input }],
|
|
196
194
|
});
|
|
197
195
|
|
|
198
196
|
const chatRequest: ChatRequest = {
|
|
@@ -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 {
|
|
@@ -253,25 +251,12 @@ export class Chat {
|
|
|
253
251
|
|
|
254
252
|
const constructedMessagesPayload = this.#options.sendExtraMessageFields
|
|
255
253
|
? messages
|
|
256
|
-
: messages.map(
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
toolInvocations,
|
|
263
|
-
parts,
|
|
264
|
-
}) => ({
|
|
265
|
-
role,
|
|
266
|
-
content,
|
|
267
|
-
...(experimental_attachments !== undefined && {
|
|
268
|
-
experimental_attachments,
|
|
269
|
-
}),
|
|
270
|
-
...(annotations !== undefined && { annotations }),
|
|
271
|
-
...(toolInvocations !== undefined && { toolInvocations }),
|
|
272
|
-
...(parts !== undefined && { parts }),
|
|
273
|
-
}),
|
|
274
|
-
);
|
|
254
|
+
: messages.map(({ role, content, annotations, parts }) => ({
|
|
255
|
+
role,
|
|
256
|
+
content,
|
|
257
|
+
...(annotations !== undefined && { annotations }),
|
|
258
|
+
...(parts !== undefined && { parts }),
|
|
259
|
+
}));
|
|
275
260
|
|
|
276
261
|
const existingData = this.data ?? [];
|
|
277
262
|
await callChatApi({
|
|
@@ -310,6 +295,7 @@ export class Chat {
|
|
|
310
295
|
onToolCall: this.#options.onToolCall,
|
|
311
296
|
onFinish: this.#options.onFinish,
|
|
312
297
|
generateId: this.#generateId,
|
|
298
|
+
getCurrentDate: this.currentDate,
|
|
313
299
|
fetch: this.#options.fetch,
|
|
314
300
|
// callChatApi calls structuredClone on the message
|
|
315
301
|
lastMessage: $state.snapshot(this.messages[this.messages.length - 1]),
|