@ai-sdk/svelte 3.0.0-canary.20 → 3.0.0-canary.21

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