@tanstack/ai-svelte 0.18.3 → 0.19.1

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.
@@ -0,0 +1,4 @@
1
+ import type { ByokClient, ByokSnapshot } from '@tanstack/ai-client/byok';
2
+ export declare function createByok(client: ByokClient): {
3
+ readonly snapshot: ByokSnapshot;
4
+ };
@@ -0,0 +1,18 @@
1
+ import { onDestroy } from 'svelte';
2
+ export function createByok(client) {
3
+ let snapshot = $state(client.getSnapshot());
4
+ const unsubscribe = client.subscribe(() => {
5
+ snapshot = client.getSnapshot();
6
+ });
7
+ try {
8
+ onDestroy(unsubscribe);
9
+ }
10
+ catch {
11
+ // Svelte lifecycle hooks are only valid during component initialization.
12
+ }
13
+ return {
14
+ get snapshot() {
15
+ return snapshot;
16
+ },
17
+ };
18
+ }
@@ -87,6 +87,8 @@ export function createChat(options) {
87
87
  ...(options.forwardedProps !== undefined && {
88
88
  forwardedProps: options.forwardedProps,
89
89
  }),
90
+ ...(options.byok !== undefined && { byok: options.byok }),
91
+ byokProvider: () => options.byokProvider?.(),
90
92
  ...(options.context !== undefined && { context: options.context }),
91
93
  devtools: {
92
94
  ...options.devtools,
@@ -6,7 +6,7 @@ import type { AIDevtoolsDisplayOptions, AudioGenerateInput, ConnectConnectionAda
6
6
  *
7
7
  * @template TOutput - The output type after optional transform (defaults to AudioGenerationResult)
8
8
  */
9
- export interface CreateGenerateAudioOptions<TOutput = AudioGenerationResult> extends Pick<CreateGenerationOptions<AudioGenerateInput, AudioGenerationResult, TOutput>, 'persistence' | 'threadId' | 'hydrateGeneration' | 'joinRun'> {
9
+ export interface CreateGenerateAudioOptions<TOutput = AudioGenerationResult> extends Pick<CreateGenerationOptions<AudioGenerateInput, AudioGenerationResult, TOutput>, 'persistence' | 'threadId' | 'hydrateGeneration' | 'joinRun' | 'byok' | 'byokProvider'> {
10
10
  /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
11
11
  connection?: ConnectConnectionAdapter;
12
12
  /** Direct async function for audio generation */
@@ -6,7 +6,7 @@ import type { AIDevtoolsDisplayOptions, ConnectConnectionAdapter, GenerationClie
6
6
  *
7
7
  * @template TOutput - The output type after optional transform (defaults to ImageGenerationResult)
8
8
  */
9
- export interface CreateGenerateImageOptions<TOutput = ImageGenerationResult> extends Pick<CreateGenerationOptions<ImageGenerateInput, ImageGenerationResult, TOutput>, 'persistence' | 'threadId' | 'hydrateGeneration' | 'joinRun'> {
9
+ export interface CreateGenerateImageOptions<TOutput = ImageGenerationResult> extends Pick<CreateGenerationOptions<ImageGenerateInput, ImageGenerationResult, TOutput>, 'persistence' | 'threadId' | 'hydrateGeneration' | 'joinRun' | 'byok' | 'byokProvider'> {
10
10
  /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
11
11
  connection?: ConnectConnectionAdapter;
12
12
  /** Direct async function for image generation */
@@ -6,7 +6,7 @@ import type { AIDevtoolsDisplayOptions, ConnectConnectionAdapter, GenerationClie
6
6
  *
7
7
  * @template TOutput - The output type after optional transform (defaults to TTSResult)
8
8
  */
9
- export interface CreateGenerateSpeechOptions<TOutput = TTSResult> extends Pick<CreateGenerationOptions<SpeechGenerateInput, TTSResult, TOutput>, 'persistence' | 'threadId' | 'hydrateGeneration' | 'joinRun'> {
9
+ export interface CreateGenerateSpeechOptions<TOutput = TTSResult> extends Pick<CreateGenerationOptions<SpeechGenerateInput, TTSResult, TOutput>, 'persistence' | 'threadId' | 'hydrateGeneration' | 'joinRun' | 'byok' | 'byokProvider'> {
10
10
  /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
11
11
  connection?: ConnectConnectionAdapter;
12
12
  /** Direct async function for speech generation */
@@ -1,5 +1,7 @@
1
1
  import type { StreamChunk } from '@tanstack/ai';
2
2
  import type { AIDevtoolsDisplayOptions, ConnectConnectionAdapter, GenerationClientState, GenerationFetcher, GenerationPersistenceOptions, InferGenerationOutputFromReturn, VideoGenerateInput, VideoGenerateResult, VideoStatusInfo } from '@tanstack/ai-client';
3
+ import type { ByokClient } from '@tanstack/ai-client/byok';
4
+ import type { ProviderId } from '@tanstack/ai/byok';
3
5
  /**
4
6
  * Options for the createGenerateVideo function.
5
7
  *
@@ -12,6 +14,10 @@ export interface CreateGenerateVideoOptions<TOutput = VideoGenerateResult> {
12
14
  fetcher?: GenerationFetcher<VideoGenerateInput, VideoGenerateResult>;
13
15
  /** Additional body parameters to send with connect-based adapter requests */
14
16
  body?: Record<string, any>;
17
+ /** Optional BYOK keyring. Keys go in `x-byok-*` headers, never the body. */
18
+ byok?: ByokClient;
19
+ /** Optional provider id. If it returns a slug, only that key is sent. If no slug resolves (`byokProvider`, then `body.provider`), generate throws. */
20
+ byokProvider?: () => ProviderId | undefined;
15
21
  /** Display options for TanStack AI Devtools. */
16
22
  devtools?: AIDevtoolsDisplayOptions;
17
23
  /**
@@ -63,6 +63,8 @@ export function createGenerateVideo(options) {
63
63
  hydrateGeneration: options.hydrateGeneration,
64
64
  }),
65
65
  ...(options.joinRun !== undefined && { joinRun: options.joinRun }),
66
+ ...(options.byok !== undefined && { byok: options.byok }),
67
+ byokProvider: () => options.byokProvider?.(),
66
68
  devtoolsBridgeFactory: createVideoDevtoolsBridge,
67
69
  devtools: {
68
70
  ...options.devtools,
@@ -1,5 +1,7 @@
1
1
  import type { StreamChunk } from '@tanstack/ai';
2
2
  import type { AIDevtoolsDisplayOptions, ConnectConnectionAdapter, GenerationClientState, GenerationFetcher, GenerationPersistenceOptions, GenerationRestoredResult, InferGenerationOutputFromReturn } from '@tanstack/ai-client';
3
+ import type { ByokClient } from '@tanstack/ai-client/byok';
4
+ import type { ProviderId } from '@tanstack/ai/byok';
3
5
  /**
4
6
  * Options for the createGeneration function.
5
7
  *
@@ -16,6 +18,10 @@ export interface CreateGenerationOptions<TInput, TResult, TOutput = TResult> {
16
18
  fetcher?: GenerationFetcher<TInput, TResult>;
17
19
  /** Additional body parameters to send with connect-based adapter requests */
18
20
  body?: Record<string, any>;
21
+ /** Optional BYOK keyring. Keys go in `x-byok-*` headers, never the body. */
22
+ byok?: ByokClient;
23
+ /** Optional provider id. If it returns a slug, only that key is sent. If no slug resolves (`byokProvider`, then `body.provider`), generate throws. */
24
+ byokProvider?: () => ProviderId | undefined;
19
25
  /** Display options for TanStack AI Devtools. */
20
26
  devtools?: AIDevtoolsDisplayOptions;
21
27
  /**
@@ -56,6 +56,8 @@ export function createGeneration(options) {
56
56
  hydrateGeneration: options.hydrateGeneration,
57
57
  }),
58
58
  ...(options.joinRun !== undefined && { joinRun: options.joinRun }),
59
+ ...(options.byok !== undefined && { byok: options.byok }),
60
+ byokProvider: () => options.byokProvider?.(),
59
61
  ...(options.reconstructResult
60
62
  ? { reconstructResult: options.reconstructResult }
61
63
  : {}),
@@ -6,7 +6,7 @@ import type { AIDevtoolsDisplayOptions, ConnectConnectionAdapter, GenerationClie
6
6
  *
7
7
  * @template TOutput - The output type after optional transform (defaults to SummarizationResult)
8
8
  */
9
- export interface CreateSummarizeOptions<TOutput = SummarizationResult> extends Pick<CreateGenerationOptions<SummarizeGenerateInput, SummarizationResult, TOutput>, 'persistence' | 'threadId' | 'hydrateGeneration' | 'joinRun'> {
9
+ export interface CreateSummarizeOptions<TOutput = SummarizationResult> extends Pick<CreateGenerationOptions<SummarizeGenerateInput, SummarizationResult, TOutput>, 'persistence' | 'threadId' | 'hydrateGeneration' | 'joinRun' | 'byok' | 'byokProvider'> {
10
10
  /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
11
11
  connection?: ConnectConnectionAdapter;
12
12
  /** Direct async function for summarization */
@@ -6,7 +6,7 @@ import type { AIDevtoolsDisplayOptions, ConnectConnectionAdapter, GenerationClie
6
6
  *
7
7
  * @template TOutput - The output type after optional transform (defaults to TranscriptionResult)
8
8
  */
9
- export interface CreateTranscriptionOptions<TOutput = TranscriptionResult> extends Pick<CreateGenerationOptions<TranscriptionGenerateInput, TranscriptionResult, TOutput>, 'persistence' | 'threadId' | 'hydrateGeneration' | 'joinRun'> {
9
+ export interface CreateTranscriptionOptions<TOutput = TranscriptionResult> extends Pick<CreateGenerationOptions<TranscriptionGenerateInput, TranscriptionResult, TOutput>, 'persistence' | 'threadId' | 'hydrateGeneration' | 'joinRun' | 'byok' | 'byokProvider'> {
10
10
  /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
11
11
  connection?: ConnectConnectionAdapter;
12
12
  /** Direct async function for transcription */
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { createChat } from './create-chat.svelte';
2
+ export { createByok } from './create-byok.svelte';
2
3
  export type { CreateChatOptions, CreateChatReturn, DeepPartial, UIMessage, ChatRequestBody, QueuedMessage, SendMessageOptions, WhenBusy, QueueConfig, QueueStrategy, QueueOption, } from './types';
3
4
  export { createGeneration } from './create-generation.svelte';
4
5
  export type { CreateGenerationOptions, CreateGenerationReturn, } from './create-generation.svelte';
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { createChat } from './create-chat.svelte';
2
+ export { createByok } from './create-byok.svelte';
2
3
  // Generation hooks
3
4
  export { createGeneration } from './create-generation.svelte';
4
5
  export { createGenerateImage } from './create-generate-image.svelte';
package/dist/types.d.ts CHANGED
@@ -69,6 +69,8 @@ interface BaseCreateChatReturn<TTools extends ReadonlyArray<AnyClientTool> = any
69
69
  /**
70
70
  * Send a message and get a response.
71
71
  * Can be a simple string or multimodal content with images, audio, etc.
72
+ * Pass `{ whenBusy }` to override the queue policy for a single send, or
73
+ * `{ body }` to merge per-call JSON into this request's `forwardedProps`.
72
74
  */
73
75
  sendMessage: (content: string | MultimodalContent, options?: SendMessageOptions) => Promise<void>;
74
76
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/ai-svelte",
3
- "version": "0.18.3",
3
+ "version": "0.19.1",
4
4
  "description": "Svelte 5 bindings for TanStack AI streaming chat, structured outputs, and media generation.",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -46,11 +46,11 @@
46
46
  "media-generation"
47
47
  ],
48
48
  "dependencies": {
49
- "@tanstack/ai-client": "^0.26.0"
49
+ "@tanstack/ai-client": "^0.28.0"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "svelte": "^5.0.0",
53
- "@tanstack/ai": "^0.48.0"
53
+ "@tanstack/ai": "^0.49.1"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@standard-schema/spec": "^1.1.0",
@@ -63,7 +63,7 @@
63
63
  "svelte-check": "^4.2.0",
64
64
  "typescript": "5.9.3",
65
65
  "vite": "^8.2.1",
66
- "@tanstack/ai": "0.48.0"
66
+ "@tanstack/ai": "0.49.1"
67
67
  },
68
68
  "scripts": {
69
69
  "clean": "rm -rf ./dist",
@@ -0,0 +1,22 @@
1
+ import { onDestroy } from 'svelte'
2
+ import type { ByokClient, ByokSnapshot } from '@tanstack/ai-client/byok'
3
+
4
+ export function createByok(client: ByokClient): {
5
+ readonly snapshot: ByokSnapshot
6
+ } {
7
+ let snapshot = $state(client.getSnapshot())
8
+ const unsubscribe = client.subscribe(() => {
9
+ snapshot = client.getSnapshot()
10
+ })
11
+ try {
12
+ onDestroy(unsubscribe)
13
+ } catch {
14
+ // Svelte lifecycle hooks are only valid during component initialization.
15
+ }
16
+
17
+ return {
18
+ get snapshot() {
19
+ return snapshot
20
+ },
21
+ }
22
+ }
@@ -134,6 +134,8 @@ export function createChat<
134
134
  ...(options.forwardedProps !== undefined && {
135
135
  forwardedProps: options.forwardedProps,
136
136
  }),
137
+ ...(options.byok !== undefined && { byok: options.byok }),
138
+ byokProvider: () => options.byokProvider?.(),
137
139
  ...(options.context !== undefined && { context: options.context }),
138
140
  devtools: {
139
141
  ...options.devtools,
@@ -24,7 +24,12 @@ export interface CreateGenerateAudioOptions<
24
24
  TOutput = AudioGenerationResult,
25
25
  > extends Pick<
26
26
  CreateGenerationOptions<AudioGenerateInput, AudioGenerationResult, TOutput>,
27
- 'persistence' | 'threadId' | 'hydrateGeneration' | 'joinRun'
27
+ | 'persistence'
28
+ | 'threadId'
29
+ | 'hydrateGeneration'
30
+ | 'joinRun'
31
+ | 'byok'
32
+ | 'byokProvider'
28
33
  > {
29
34
  /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
30
35
  connection?: ConnectConnectionAdapter
@@ -24,7 +24,12 @@ export interface CreateGenerateImageOptions<
24
24
  TOutput = ImageGenerationResult,
25
25
  > extends Pick<
26
26
  CreateGenerationOptions<ImageGenerateInput, ImageGenerationResult, TOutput>,
27
- 'persistence' | 'threadId' | 'hydrateGeneration' | 'joinRun'
27
+ | 'persistence'
28
+ | 'threadId'
29
+ | 'hydrateGeneration'
30
+ | 'joinRun'
31
+ | 'byok'
32
+ | 'byokProvider'
28
33
  > {
29
34
  /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
30
35
  connection?: ConnectConnectionAdapter
@@ -22,7 +22,12 @@ import type {
22
22
  */
23
23
  export interface CreateGenerateSpeechOptions<TOutput = TTSResult> extends Pick<
24
24
  CreateGenerationOptions<SpeechGenerateInput, TTSResult, TOutput>,
25
- 'persistence' | 'threadId' | 'hydrateGeneration' | 'joinRun'
25
+ | 'persistence'
26
+ | 'threadId'
27
+ | 'hydrateGeneration'
28
+ | 'joinRun'
29
+ | 'byok'
30
+ | 'byokProvider'
26
31
  > {
27
32
  /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
28
33
  connection?: ConnectConnectionAdapter
@@ -12,6 +12,8 @@ import type {
12
12
  VideoGenerateResult,
13
13
  VideoStatusInfo,
14
14
  } from '@tanstack/ai-client'
15
+ import type { ByokClient } from '@tanstack/ai-client/byok'
16
+ import type { ProviderId } from '@tanstack/ai/byok'
15
17
 
16
18
  /**
17
19
  * Options for the createGenerateVideo function.
@@ -25,6 +27,10 @@ export interface CreateGenerateVideoOptions<TOutput = VideoGenerateResult> {
25
27
  fetcher?: GenerationFetcher<VideoGenerateInput, VideoGenerateResult>
26
28
  /** Additional body parameters to send with connect-based adapter requests */
27
29
  body?: Record<string, any>
30
+ /** Optional BYOK keyring. Keys go in `x-byok-*` headers, never the body. */
31
+ byok?: ByokClient
32
+ /** Optional provider id. If it returns a slug, only that key is sent. If no slug resolves (`byokProvider`, then `body.provider`), generate throws. */
33
+ byokProvider?: () => ProviderId | undefined
28
34
  /** Display options for TanStack AI Devtools. */
29
35
  devtools?: AIDevtoolsDisplayOptions
30
36
  /**
@@ -199,6 +205,8 @@ export function createGenerateVideo<TTransformed = void>(
199
205
  hydrateGeneration: options.hydrateGeneration,
200
206
  }),
201
207
  ...(options.joinRun !== undefined && { joinRun: options.joinRun }),
208
+ ...(options.byok !== undefined && { byok: options.byok }),
209
+ byokProvider: () => options.byokProvider?.(),
202
210
  devtoolsBridgeFactory: createVideoDevtoolsBridge,
203
211
  devtools: {
204
212
  ...options.devtools,
@@ -11,6 +11,8 @@ import type {
11
11
  GenerationRestoredResult,
12
12
  InferGenerationOutputFromReturn,
13
13
  } from '@tanstack/ai-client'
14
+ import type { ByokClient } from '@tanstack/ai-client/byok'
15
+ import type { ProviderId } from '@tanstack/ai/byok'
14
16
 
15
17
  /**
16
18
  * Options for the createGeneration function.
@@ -28,6 +30,10 @@ export interface CreateGenerationOptions<TInput, TResult, TOutput = TResult> {
28
30
  fetcher?: GenerationFetcher<TInput, TResult>
29
31
  /** Additional body parameters to send with connect-based adapter requests */
30
32
  body?: Record<string, any>
33
+ /** Optional BYOK keyring. Keys go in `x-byok-*` headers, never the body. */
34
+ byok?: ByokClient
35
+ /** Optional provider id. If it returns a slug, only that key is sent. If no slug resolves (`byokProvider`, then `body.provider`), generate throws. */
36
+ byokProvider?: () => ProviderId | undefined
31
37
  /** Display options for TanStack AI Devtools. */
32
38
  devtools?: AIDevtoolsDisplayOptions
33
39
  /**
@@ -201,6 +207,8 @@ export function createGeneration<
201
207
  hydrateGeneration: options.hydrateGeneration,
202
208
  }),
203
209
  ...(options.joinRun !== undefined && { joinRun: options.joinRun }),
210
+ ...(options.byok !== undefined && { byok: options.byok }),
211
+ byokProvider: () => options.byokProvider?.(),
204
212
  ...(options.reconstructResult
205
213
  ? { reconstructResult: options.reconstructResult }
206
214
  : {}),
@@ -24,7 +24,12 @@ export interface CreateSummarizeOptions<
24
24
  TOutput = SummarizationResult,
25
25
  > extends Pick<
26
26
  CreateGenerationOptions<SummarizeGenerateInput, SummarizationResult, TOutput>,
27
- 'persistence' | 'threadId' | 'hydrateGeneration' | 'joinRun'
27
+ | 'persistence'
28
+ | 'threadId'
29
+ | 'hydrateGeneration'
30
+ | 'joinRun'
31
+ | 'byok'
32
+ | 'byokProvider'
28
33
  > {
29
34
  /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
30
35
  connection?: ConnectConnectionAdapter
@@ -28,7 +28,12 @@ export interface CreateTranscriptionOptions<
28
28
  TranscriptionResult,
29
29
  TOutput
30
30
  >,
31
- 'persistence' | 'threadId' | 'hydrateGeneration' | 'joinRun'
31
+ | 'persistence'
32
+ | 'threadId'
33
+ | 'hydrateGeneration'
34
+ | 'joinRun'
35
+ | 'byok'
36
+ | 'byokProvider'
32
37
  > {
33
38
  /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
34
39
  connection?: ConnectConnectionAdapter
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { createChat } from './create-chat.svelte'
2
+ export { createByok } from './create-byok.svelte'
2
3
  export type {
3
4
  CreateChatOptions,
4
5
  CreateChatReturn,
package/src/types.ts CHANGED
@@ -157,6 +157,8 @@ interface BaseCreateChatReturn<
157
157
  /**
158
158
  * Send a message and get a response.
159
159
  * Can be a simple string or multimodal content with images, audio, etc.
160
+ * Pass `{ whenBusy }` to override the queue policy for a single send, or
161
+ * `{ body }` to merge per-call JSON into this request's `forwardedProps`.
160
162
  */
161
163
  sendMessage: (
162
164
  content: string | MultimodalContent,