@ai-sdk/svelte 2.1.12 → 3.0.0-alpha.2

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +265 -24
  2. package/dist/chat.svelte.d.ts +13 -27
  3. package/dist/chat.svelte.d.ts.map +1 -1
  4. package/dist/chat.svelte.js +24 -61
  5. package/dist/completion.svelte.d.ts +2 -9
  6. package/dist/completion.svelte.d.ts.map +1 -1
  7. package/dist/completion.svelte.js +4 -22
  8. package/dist/index.d.ts +1 -1
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/structured-object-context.svelte.d.ts +1 -1
  11. package/dist/structured-object-context.svelte.d.ts.map +1 -1
  12. package/dist/structured-object.svelte.d.ts +1 -1
  13. package/dist/structured-object.svelte.d.ts.map +1 -1
  14. package/dist/structured-object.svelte.js +5 -5
  15. package/dist/tests/chat-synchronization.svelte +3 -3
  16. package/dist/tests/chat-synchronization.svelte.d.ts +3 -3
  17. package/dist/tests/chat-synchronization.svelte.d.ts.map +1 -1
  18. package/dist/tests/structured-object-synchronization.svelte +1 -1
  19. package/dist/tests/structured-object-synchronization.svelte.d.ts +1 -1
  20. package/dist/tests/structured-object-synchronization.svelte.d.ts.map +1 -1
  21. package/package.json +9 -6
  22. package/src/chat-context.svelte.ts +10 -5
  23. package/src/chat.svelte.ts +64 -119
  24. package/src/completion-context.svelte.ts +1 -1
  25. package/src/completion.svelte.ts +11 -28
  26. package/src/index.ts +1 -2
  27. package/src/structured-object-context.svelte.ts +1 -1
  28. package/src/structured-object.svelte.ts +5 -5
  29. package/src/tests/chat-synchronization.svelte +3 -3
  30. package/src/tests/structured-object-synchronization.svelte +1 -1
  31. package/dist/chat-context.svelte.d.ts +0 -14
  32. package/dist/chat-context.svelte.d.ts.map +0 -1
  33. package/dist/completion-context.svelte.d.ts +0 -15
  34. package/dist/completion-context.svelte.d.ts.map +0 -1
@@ -10,7 +10,7 @@ import {
10
10
  parsePartialJson,
11
11
  type DeepPartial,
12
12
  type Schema,
13
- } from '@ai-sdk/ui-utils';
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
  });
@@ -2,11 +2,11 @@
2
2
  import { Chat } from '../chat.svelte.js';
3
3
  import { createAIContext } from '../context-provider.js';
4
4
 
5
- let { id }: { id?: string } = $props();
5
+ let { chatId }: { chatId?: string } = $props();
6
6
 
7
7
  createAIContext();
8
- const chat1 = new Chat({ id });
9
- const chat2 = new Chat({ id });
8
+ const chat1 = new Chat({ chatId });
9
+ const chat2 = new Chat({ chatId });
10
10
 
11
11
  export { chat1, chat2 };
12
12
  </script>
@@ -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 '@ai-sdk/ui-utils';
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"}