@ai-sdk/svelte 5.0.61 → 5.0.63

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,21 @@
1
1
  # @ai-sdk/svelte
2
2
 
3
+ ## 5.0.63
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [d0a5807]
8
+ - Updated dependencies [dcf33e8]
9
+ - ai@7.0.63
10
+
11
+ ## 5.0.62
12
+
13
+ ### Patch Changes
14
+
15
+ - e0bcf52: feat(ui): add typed custom bodies to Completion APIs
16
+ - Updated dependencies [e0bcf52]
17
+ - ai@7.0.62
18
+
3
19
  ## 5.0.61
4
20
 
5
21
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  import { type CompletionRequestOptions, type UseCompletionOptions } from 'ai';
2
- export type CompletionOptions = Readonly<UseCompletionOptions>;
3
- export declare class Completion {
2
+ export type CompletionOptions<BODY extends object = object> = Readonly<UseCompletionOptions<BODY>>;
3
+ export declare class Completion<BODY extends object = object> {
4
4
  #private;
5
5
  /** The current completion result */
6
6
  get completion(): string;
@@ -13,7 +13,7 @@ export declare class Completion {
13
13
  * Flag that indicates whether an API request is in progress.
14
14
  */
15
15
  get loading(): boolean;
16
- constructor(options?: CompletionOptions);
16
+ constructor(options?: CompletionOptions<NoInfer<BODY>>);
17
17
  /**
18
18
  * Abort the current request immediately, keep the generated tokens if any.
19
19
  */
@@ -21,7 +21,7 @@ export declare class Completion {
21
21
  /**
22
22
  * Send a new prompt to the API endpoint and update the completion state.
23
23
  */
24
- complete: (prompt: string, options?: CompletionRequestOptions) => Promise<string | null | undefined>;
24
+ complete: (prompt: string, options?: CompletionRequestOptions<BODY>) => Promise<string | null | undefined>;
25
25
  /** Form submission handler to automatically reset input and call the completion API */
26
26
  handleSubmit: (event?: {
27
27
  preventDefault?: () => void;
@@ -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,GAAU,QAAQ,MAAM,EAAE,UAAU,wBAAwB,wCAC5B;IAExC,uFAAuF;IACvF,YAAY,GAAU,QAAQ;QAAE,cAAc,CAAC,EAAE,MAAM,IAAI,CAAA;KAAE,mBAK3D;CAkCH"}
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,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM,IAAI,QAAQ,CACpE,oBAAoB,CAAC,IAAI,CAAC,CAC3B,CAAC;AAEF,qBAAa,UAAU,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM;;IASlD,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,iBAAiB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAM;IAS1D;;OAEG;IACH,IAAI,aASF;IAEF;;OAEG;IACH,QAAQ,GAAU,QAAQ,MAAM,EAAE,UAAU,wBAAwB,CAAC,IAAI,CAAC,wCAClC;IAExC,uFAAuF;IACvF,YAAY,GAAU,QAAQ;QAAE,cAAc,CAAC,EAAE,MAAM,IAAI,CAAA;KAAE,mBAK3D;CAkCH"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=completion.svelte.test-d.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"completion.svelte.test-d.d.ts","sourceRoot":"","sources":["../src/completion.svelte.test-d.ts"],"names":[],"mappings":""}
@@ -0,0 +1,19 @@
1
+ import { expectTypeOf } from 'vitest';
2
+ import { Completion } from './completion.svelte.js';
3
+ const typedCompletion = new Completion({
4
+ body: { model: 'fast' },
5
+ });
6
+ expectTypeOf(typedCompletion.complete)
7
+ .parameter(1)
8
+ .toEqualTypeOf();
9
+ typedCompletion.complete('prompt', { body: { model: 'smart' } });
10
+ typedCompletion.complete('prompt', {
11
+ body: {
12
+ // @ts-expect-error - model must match TestBody
13
+ model: 'slow',
14
+ },
15
+ });
16
+ const untypedCompletion = new Completion({
17
+ body: { sessionId: 'session-id' },
18
+ });
19
+ untypedCompletion.complete('prompt', { body: { model: 'fast' } });
@@ -3,8 +3,8 @@ type $$ComponentProps = {
3
3
  id?: string;
4
4
  };
5
5
  declare const CompletionSynchronization: import("svelte").Component<$$ComponentProps, {
6
- completion1: Completion;
7
- completion2: Completion;
6
+ completion1: Completion<object>;
7
+ completion2: Completion<object>;
8
8
  }, "">;
9
9
  type CompletionSynchronization = ReturnType<typeof CompletionSynchronization>;
10
10
  export default CompletionSynchronization;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/svelte",
3
- "version": "5.0.61",
3
+ "version": "5.0.63",
4
4
  "license": "Apache-2.0",
5
5
  "files": [
6
6
  "dist",
@@ -34,8 +34,8 @@
34
34
  "svelte": "^5.31.0"
35
35
  },
36
36
  "dependencies": {
37
- "@ai-sdk/provider-utils": "5.0.27",
38
- "ai": "7.0.61"
37
+ "ai": "7.0.63",
38
+ "@ai-sdk/provider-utils": "5.0.27"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@sveltejs/package": "^2.5.7",
@@ -0,0 +1,29 @@
1
+ import type { CompletionRequestOptions } from 'ai';
2
+ import { expectTypeOf } from 'vitest';
3
+ import { Completion } from './completion.svelte.js';
4
+
5
+ type TestBody = {
6
+ model: 'fast' | 'smart';
7
+ };
8
+
9
+ const typedCompletion = new Completion<TestBody>({
10
+ body: { model: 'fast' },
11
+ });
12
+
13
+ expectTypeOf(typedCompletion.complete)
14
+ .parameter(1)
15
+ .toEqualTypeOf<CompletionRequestOptions<TestBody> | undefined>();
16
+
17
+ typedCompletion.complete('prompt', { body: { model: 'smart' } });
18
+ typedCompletion.complete('prompt', {
19
+ body: {
20
+ // @ts-expect-error - model must match TestBody
21
+ model: 'slow',
22
+ },
23
+ });
24
+
25
+ const untypedCompletion = new Completion({
26
+ body: { sessionId: 'session-id' },
27
+ });
28
+
29
+ untypedCompletion.complete('prompt', { body: { model: 'fast' } });
@@ -10,10 +10,12 @@ import {
10
10
  hasCompletionContext,
11
11
  } from './completion-context.svelte.js';
12
12
 
13
- export type CompletionOptions = Readonly<UseCompletionOptions>;
13
+ export type CompletionOptions<BODY extends object = object> = Readonly<
14
+ UseCompletionOptions<BODY>
15
+ >;
14
16
 
15
- export class Completion {
16
- readonly #options: CompletionOptions = {};
17
+ export class Completion<BODY extends object = object> {
18
+ readonly #options: CompletionOptions<BODY> = {};
17
19
  readonly #api = $derived(this.#options.api ?? '/api/completion');
18
20
  readonly #id = $derived(this.#options.id ?? generateId());
19
21
  readonly #streamProtocol = $derived(this.#options.streamProtocol ?? 'data');
@@ -44,7 +46,7 @@ export class Completion {
44
46
  return this.#store.loading;
45
47
  }
46
48
 
47
- constructor(options: CompletionOptions = {}) {
49
+ constructor(options: CompletionOptions<NoInfer<BODY>> = {}) {
48
50
  this.#keyedStore = hasCompletionContext()
49
51
  ? getCompletionContext()
50
52
  : new KeyedCompletionStore();
@@ -70,7 +72,7 @@ export class Completion {
70
72
  /**
71
73
  * Send a new prompt to the API endpoint and update the completion state.
72
74
  */
73
- complete = async (prompt: string, options?: CompletionRequestOptions) =>
75
+ complete = async (prompt: string, options?: CompletionRequestOptions<BODY>) =>
74
76
  this.#triggerRequest(prompt, options);
75
77
 
76
78
  /** Form submission handler to automatically reset input and call the completion API */
@@ -83,7 +85,7 @@ export class Completion {
83
85
 
84
86
  #triggerRequest = async (
85
87
  prompt: string,
86
- options?: CompletionRequestOptions,
88
+ options?: CompletionRequestOptions<BODY>,
87
89
  ) => {
88
90
  return callCompletionApi({
89
91
  api: this.#api,