@tanstack/ai-svelte 0.6.6 → 0.6.7

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.
@@ -38,6 +38,9 @@ export function createChat(options) {
38
38
  let isLoading = $state(false);
39
39
  let error = $state(undefined);
40
40
  let status = $state('ready');
41
+ let isSubscribed = $state(false);
42
+ let connectionStatus = $state('disconnected');
43
+ let sessionGenerating = $state(false);
41
44
  // Create ChatClient instance
42
45
  const client = new ChatClient({
43
46
  connection: options.connection,
@@ -67,7 +70,19 @@ export function createChat(options) {
67
70
  onErrorChange: (newError) => {
68
71
  error = newError;
69
72
  },
73
+ onSubscriptionChange: (nextIsSubscribed) => {
74
+ isSubscribed = nextIsSubscribed;
75
+ },
76
+ onConnectionStatusChange: (nextStatus) => {
77
+ connectionStatus = nextStatus;
78
+ },
79
+ onSessionGeneratingChange: (isGenerating) => {
80
+ sessionGenerating = isGenerating;
81
+ },
70
82
  });
83
+ if (options.live) {
84
+ client.subscribe();
85
+ }
71
86
  // Note: Cleanup is handled by calling stop() directly when needed.
72
87
  // Unlike React/Vue/Solid, Svelte 5 runes like $effect can only be used
73
88
  // during component initialization, so we don't add automatic cleanup here.
@@ -115,6 +130,15 @@ export function createChat(options) {
115
130
  get status() {
116
131
  return status;
117
132
  },
133
+ get isSubscribed() {
134
+ return isSubscribed;
135
+ },
136
+ get connectionStatus() {
137
+ return connectionStatus;
138
+ },
139
+ get sessionGenerating() {
140
+ return sessionGenerating;
141
+ },
118
142
  sendMessage,
119
143
  append,
120
144
  reload,
@@ -1,18 +1,18 @@
1
1
  import type { ImageGenerationResult, StreamChunk } from '@tanstack/ai';
2
- import type { ConnectionAdapter, GenerationClientState, GenerationFetcher, ImageGenerateInput, InferGenerationOutput } from '@tanstack/ai-client';
2
+ import type { ConnectConnectionAdapter, GenerationClientState, GenerationFetcher, ImageGenerateInput, InferGenerationOutput } from '@tanstack/ai-client';
3
3
  /**
4
4
  * Options for the createGenerateImage function.
5
5
  *
6
6
  * @template TOutput - The output type after optional transform (defaults to ImageGenerationResult)
7
7
  */
8
8
  export interface CreateGenerateImageOptions<TOutput = ImageGenerationResult> {
9
- /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */
10
- connection?: ConnectionAdapter;
9
+ /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
10
+ connection?: ConnectConnectionAdapter;
11
11
  /** Direct async function for image generation */
12
12
  fetcher?: GenerationFetcher<ImageGenerateInput, ImageGenerationResult>;
13
13
  /** Unique identifier for this generation instance */
14
14
  id?: string;
15
- /** Additional body parameters to send with ConnectionAdapter requests */
15
+ /** Additional body parameters to send with connect-based adapter requests */
16
16
  body?: Record<string, any>;
17
17
  /**
18
18
  * Callback when images are generated. Can optionally return a transformed value.
@@ -26,7 +26,7 @@ export interface CreateGenerateImageOptions<TOutput = ImageGenerationResult> {
26
26
  onError?: (error: Error) => void;
27
27
  /** Callback when progress is reported (0-100) */
28
28
  onProgress?: (progress: number, message?: string) => void;
29
- /** Callback for each stream chunk (ConnectionAdapter mode only) */
29
+ /** Callback for each stream chunk (connect-based adapter mode only) */
30
30
  onChunk?: (chunk: StreamChunk) => void;
31
31
  }
32
32
  /**
@@ -56,7 +56,7 @@ export interface CreateGenerateImageReturn<TOutput = ImageGenerationResult> {
56
56
  * Creates a reactive image generation instance for Svelte 5.
57
57
  *
58
58
  * Supports two transport modes:
59
- * - **ConnectionAdapter** -- Streaming transport (SSE, HTTP stream, custom)
59
+ * - **ConnectConnectionAdapter** -- Streaming transport (SSE, HTTP stream, custom)
60
60
  * - **Fetcher** -- Direct async function call
61
61
  *
62
62
  * @example
@@ -3,7 +3,7 @@ import { createGeneration } from './create-generation.svelte';
3
3
  * Creates a reactive image generation instance for Svelte 5.
4
4
  *
5
5
  * Supports two transport modes:
6
- * - **ConnectionAdapter** -- Streaming transport (SSE, HTTP stream, custom)
6
+ * - **ConnectConnectionAdapter** -- Streaming transport (SSE, HTTP stream, custom)
7
7
  * - **Fetcher** -- Direct async function call
8
8
  *
9
9
  * @example
@@ -1,18 +1,18 @@
1
1
  import type { StreamChunk, TTSResult } from '@tanstack/ai';
2
- import type { ConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutput, SpeechGenerateInput } from '@tanstack/ai-client';
2
+ import type { ConnectConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutput, SpeechGenerateInput } from '@tanstack/ai-client';
3
3
  /**
4
4
  * Options for the createGenerateSpeech function.
5
5
  *
6
6
  * @template TOutput - The output type after optional transform (defaults to TTSResult)
7
7
  */
8
8
  export interface CreateGenerateSpeechOptions<TOutput = TTSResult> {
9
- /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */
10
- connection?: ConnectionAdapter;
9
+ /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
10
+ connection?: ConnectConnectionAdapter;
11
11
  /** Direct async function for speech generation */
12
12
  fetcher?: GenerationFetcher<SpeechGenerateInput, TTSResult>;
13
13
  /** Unique identifier for this generation instance */
14
14
  id?: string;
15
- /** Additional body parameters to send with ConnectionAdapter requests */
15
+ /** Additional body parameters to send with connect-based adapter requests */
16
16
  body?: Record<string, any>;
17
17
  /**
18
18
  * Callback when speech is generated. Can optionally return a transformed value.
@@ -26,7 +26,7 @@ export interface CreateGenerateSpeechOptions<TOutput = TTSResult> {
26
26
  onError?: (error: Error) => void;
27
27
  /** Callback when progress is reported (0-100) */
28
28
  onProgress?: (progress: number, message?: string) => void;
29
- /** Callback for each stream chunk (ConnectionAdapter mode only) */
29
+ /** Callback for each stream chunk (connect-based adapter mode only) */
30
30
  onChunk?: (chunk: StreamChunk) => void;
31
31
  }
32
32
  /**
@@ -1,18 +1,18 @@
1
1
  import type { StreamChunk } from '@tanstack/ai';
2
- import type { ConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutput, VideoGenerateInput, VideoGenerateResult, VideoStatusInfo } from '@tanstack/ai-client';
2
+ import type { ConnectConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutput, VideoGenerateInput, VideoGenerateResult, VideoStatusInfo } from '@tanstack/ai-client';
3
3
  /**
4
4
  * Options for the createGenerateVideo function.
5
5
  *
6
6
  * @template TOutput - The output type after optional transform (defaults to VideoGenerateResult)
7
7
  */
8
8
  export interface CreateGenerateVideoOptions<TOutput = VideoGenerateResult> {
9
- /** Connection adapter for streaming transport (server handles polling) */
10
- connection?: ConnectionAdapter;
9
+ /** Connect-based adapter for streaming transport (server handles polling) */
10
+ connection?: ConnectConnectionAdapter;
11
11
  /** Direct async function that returns a completed video result */
12
12
  fetcher?: GenerationFetcher<VideoGenerateInput, VideoGenerateResult>;
13
13
  /** Unique identifier for this generation instance */
14
14
  id?: string;
15
- /** Additional body parameters to send with ConnectionAdapter requests */
15
+ /** Additional body parameters to send with connect-based adapter requests */
16
16
  body?: Record<string, any>;
17
17
  /**
18
18
  * Callback when video generation completes. Can optionally return a transformed value.
@@ -30,7 +30,7 @@ export interface CreateGenerateVideoOptions<TOutput = VideoGenerateResult> {
30
30
  onJobCreated?: (jobId: string) => void;
31
31
  /** Callback on each status update */
32
32
  onStatusUpdate?: (status: VideoStatusInfo) => void;
33
- /** Callback for each stream chunk (ConnectionAdapter mode only) */
33
+ /** Callback for each stream chunk (connect-based adapter mode only) */
34
34
  onChunk?: (chunk: StreamChunk) => void;
35
35
  }
36
36
  /**
@@ -1,5 +1,5 @@
1
1
  import type { StreamChunk } from '@tanstack/ai';
2
- import type { ConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutput } from '@tanstack/ai-client';
2
+ import type { ConnectConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutput } from '@tanstack/ai-client';
3
3
  /**
4
4
  * Options for the createGeneration function.
5
5
  *
@@ -10,13 +10,13 @@ import type { ConnectionAdapter, GenerationClientState, GenerationFetcher, Infer
10
10
  * @template TOutput - The output type after optional transform (defaults to TResult)
11
11
  */
12
12
  export interface CreateGenerationOptions<TInput, TResult, TOutput = TResult> {
13
- /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */
14
- connection?: ConnectionAdapter;
13
+ /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
14
+ connection?: ConnectConnectionAdapter;
15
15
  /** Direct async function for one-shot generation (no streaming protocol needed) */
16
16
  fetcher?: GenerationFetcher<TInput, TResult>;
17
17
  /** Unique identifier for this generation instance */
18
18
  id?: string;
19
- /** Additional body parameters to send with ConnectionAdapter requests */
19
+ /** Additional body parameters to send with connect-based adapter requests */
20
20
  body?: Record<string, any>;
21
21
  /**
22
22
  * Callback when a result is received. Can optionally return a transformed value.
@@ -30,7 +30,7 @@ export interface CreateGenerationOptions<TInput, TResult, TOutput = TResult> {
30
30
  onError?: (error: Error) => void;
31
31
  /** Callback when progress is reported (0-100) */
32
32
  onProgress?: (progress: number, message?: string) => void;
33
- /** Callback for each stream chunk (ConnectionAdapter mode only) */
33
+ /** Callback for each stream chunk (connect-based adapter mode only) */
34
34
  onChunk?: (chunk: StreamChunk) => void;
35
35
  }
36
36
  /**
@@ -1,18 +1,18 @@
1
1
  import type { StreamChunk, SummarizationResult } from '@tanstack/ai';
2
- import type { ConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutput, SummarizeGenerateInput } from '@tanstack/ai-client';
2
+ import type { ConnectConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutput, SummarizeGenerateInput } from '@tanstack/ai-client';
3
3
  /**
4
4
  * Options for the createSummarize function.
5
5
  *
6
6
  * @template TOutput - The output type after optional transform (defaults to SummarizationResult)
7
7
  */
8
8
  export interface CreateSummarizeOptions<TOutput = SummarizationResult> {
9
- /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */
10
- connection?: ConnectionAdapter;
9
+ /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
10
+ connection?: ConnectConnectionAdapter;
11
11
  /** Direct async function for summarization */
12
12
  fetcher?: GenerationFetcher<SummarizeGenerateInput, SummarizationResult>;
13
13
  /** Unique identifier for this generation instance */
14
14
  id?: string;
15
- /** Additional body parameters to send with ConnectionAdapter requests */
15
+ /** Additional body parameters to send with connect-based adapter requests */
16
16
  body?: Record<string, any>;
17
17
  /**
18
18
  * Callback when summarization is complete. Can optionally return a transformed value.
@@ -26,7 +26,7 @@ export interface CreateSummarizeOptions<TOutput = SummarizationResult> {
26
26
  onError?: (error: Error) => void;
27
27
  /** Callback when progress is reported (0-100) */
28
28
  onProgress?: (progress: number, message?: string) => void;
29
- /** Callback for each stream chunk (ConnectionAdapter mode only) */
29
+ /** Callback for each stream chunk (connect-based adapter mode only) */
30
30
  onChunk?: (chunk: StreamChunk) => void;
31
31
  }
32
32
  /**
@@ -1,18 +1,18 @@
1
1
  import type { StreamChunk, TranscriptionResult } from '@tanstack/ai';
2
- import type { ConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutput, TranscriptionGenerateInput } from '@tanstack/ai-client';
2
+ import type { ConnectConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutput, TranscriptionGenerateInput } from '@tanstack/ai-client';
3
3
  /**
4
4
  * Options for the createTranscription function.
5
5
  *
6
6
  * @template TOutput - The output type after optional transform (defaults to TranscriptionResult)
7
7
  */
8
8
  export interface CreateTranscriptionOptions<TOutput = TranscriptionResult> {
9
- /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */
10
- connection?: ConnectionAdapter;
9
+ /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
10
+ connection?: ConnectConnectionAdapter;
11
11
  /** Direct async function for transcription */
12
12
  fetcher?: GenerationFetcher<TranscriptionGenerateInput, TranscriptionResult>;
13
13
  /** Unique identifier for this generation instance */
14
14
  id?: string;
15
- /** Additional body parameters to send with ConnectionAdapter requests */
15
+ /** Additional body parameters to send with connect-based adapter requests */
16
16
  body?: Record<string, any>;
17
17
  /**
18
18
  * Callback when transcription is complete. Can optionally return a transformed value.
@@ -26,7 +26,7 @@ export interface CreateTranscriptionOptions<TOutput = TranscriptionResult> {
26
26
  onError?: (error: Error) => void;
27
27
  /** Callback when progress is reported (0-100) */
28
28
  onProgress?: (progress: number, message?: string) => void;
29
- /** Callback for each stream chunk (ConnectionAdapter mode only) */
29
+ /** Callback for each stream chunk (connect-based adapter mode only) */
30
30
  onChunk?: (chunk: StreamChunk) => void;
31
31
  }
32
32
  /**
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { AnyClientTool, ModelMessage } from '@tanstack/ai';
2
- import type { ChatClientOptions, ChatClientState, ChatRequestBody, MultimodalContent, UIMessage } from '@tanstack/ai-client';
2
+ import type { ChatClientOptions, ChatClientState, ChatRequestBody, ConnectionStatus, MultimodalContent, UIMessage } from '@tanstack/ai-client';
3
3
  export type { ChatRequestBody, MultimodalContent, UIMessage };
4
4
  /**
5
5
  * Options for the createChat function.
@@ -17,7 +17,9 @@ export type { ChatRequestBody, MultimodalContent, UIMessage };
17
17
  * Note: Connection and body changes will recreate the ChatClient instance.
18
18
  * To update these options, remount the component or use a key prop.
19
19
  */
20
- export type CreateChatOptions<TTools extends ReadonlyArray<AnyClientTool> = any> = Omit<ChatClientOptions<TTools>, 'onMessagesChange' | 'onLoadingChange' | 'onErrorChange' | 'onStatusChange'>;
20
+ export type CreateChatOptions<TTools extends ReadonlyArray<AnyClientTool> = any> = Omit<ChatClientOptions<TTools>, 'onMessagesChange' | 'onLoadingChange' | 'onErrorChange' | 'onStatusChange' | 'onSubscriptionChange' | 'onConnectionStatusChange' | 'onSessionGeneratingChange'> & {
21
+ live?: boolean;
22
+ };
21
23
  export interface CreateChatReturn<TTools extends ReadonlyArray<AnyClientTool> = any> {
22
24
  /**
23
25
  * Current messages in the conversation (reactive getter)
@@ -77,6 +79,21 @@ export interface CreateChatReturn<TTools extends ReadonlyArray<AnyClientTool> =
77
79
  * Current generation status (reactive getter)
78
80
  */
79
81
  readonly status: ChatClientState;
82
+ /**
83
+ * Whether the subscription loop is currently active (reactive getter)
84
+ */
85
+ readonly isSubscribed: boolean;
86
+ /**
87
+ * Current connection lifecycle status (reactive getter)
88
+ */
89
+ readonly connectionStatus: ConnectionStatus;
90
+ /**
91
+ * Whether the shared session is actively generating (reactive getter).
92
+ * Derived from stream run events (RUN_STARTED / RUN_FINISHED / RUN_ERROR).
93
+ * Unlike `isLoading` (request-local), this reflects shared generation
94
+ * activity visible to all subscribers (e.g. across tabs/devices).
95
+ */
96
+ readonly sessionGenerating: boolean;
80
97
  /**
81
98
  * Update the body sent with requests (e.g., for changing model selection)
82
99
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/ai-svelte",
3
- "version": "0.6.6",
3
+ "version": "0.6.7",
4
4
  "description": "Svelte bindings for TanStack AI",
5
5
  "author": "",
6
6
  "license": "MIT",
@@ -33,11 +33,11 @@
33
33
  "streaming"
34
34
  ],
35
35
  "dependencies": {
36
- "@tanstack/ai-client": "0.7.1"
36
+ "@tanstack/ai-client": "0.7.2"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "svelte": "^5.0.0",
40
- "@tanstack/ai": "^0.8.0"
40
+ "@tanstack/ai": "^0.8.1"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@sveltejs/package": "^2.3.10",
@@ -49,7 +49,7 @@
49
49
  "svelte-check": "^4.2.0",
50
50
  "typescript": "5.9.3",
51
51
  "vite": "^7.2.7",
52
- "@tanstack/ai": "0.8.0"
52
+ "@tanstack/ai": "0.8.1"
53
53
  },
54
54
  "scripts": {
55
55
  "clean": "rm -rf ./dist",
@@ -1,5 +1,5 @@
1
1
  import { ChatClient } from '@tanstack/ai-client'
2
- import type { ChatClientState } from '@tanstack/ai-client'
2
+ import type { ChatClientState, ConnectionStatus } from '@tanstack/ai-client'
3
3
  import type { AnyClientTool, ModelMessage } from '@tanstack/ai'
4
4
  import type {
5
5
  CreateChatOptions,
@@ -51,6 +51,9 @@ export function createChat<TTools extends ReadonlyArray<AnyClientTool> = any>(
51
51
  let isLoading = $state(false)
52
52
  let error = $state<Error | undefined>(undefined)
53
53
  let status = $state<ChatClientState>('ready')
54
+ let isSubscribed = $state(false)
55
+ let connectionStatus = $state<ConnectionStatus>('disconnected')
56
+ let sessionGenerating = $state(false)
54
57
 
55
58
  // Create ChatClient instance
56
59
  const client = new ChatClient({
@@ -81,8 +84,21 @@ export function createChat<TTools extends ReadonlyArray<AnyClientTool> = any>(
81
84
  onErrorChange: (newError: Error | undefined) => {
82
85
  error = newError
83
86
  },
87
+ onSubscriptionChange: (nextIsSubscribed: boolean) => {
88
+ isSubscribed = nextIsSubscribed
89
+ },
90
+ onConnectionStatusChange: (nextStatus: ConnectionStatus) => {
91
+ connectionStatus = nextStatus
92
+ },
93
+ onSessionGeneratingChange: (isGenerating: boolean) => {
94
+ sessionGenerating = isGenerating
95
+ },
84
96
  })
85
97
 
98
+ if (options.live) {
99
+ client.subscribe()
100
+ }
101
+
86
102
  // Note: Cleanup is handled by calling stop() directly when needed.
87
103
  // Unlike React/Vue/Solid, Svelte 5 runes like $effect can only be used
88
104
  // during component initialization, so we don't add automatic cleanup here.
@@ -149,6 +165,15 @@ export function createChat<TTools extends ReadonlyArray<AnyClientTool> = any>(
149
165
  get status() {
150
166
  return status
151
167
  },
168
+ get isSubscribed() {
169
+ return isSubscribed
170
+ },
171
+ get connectionStatus() {
172
+ return connectionStatus
173
+ },
174
+ get sessionGenerating() {
175
+ return sessionGenerating
176
+ },
152
177
  sendMessage,
153
178
  append,
154
179
  reload,
@@ -1,7 +1,7 @@
1
1
  import { createGeneration } from './create-generation.svelte'
2
2
  import type { ImageGenerationResult, StreamChunk } from '@tanstack/ai'
3
3
  import type {
4
- ConnectionAdapter,
4
+ ConnectConnectionAdapter,
5
5
  GenerationClientState,
6
6
  GenerationFetcher,
7
7
  ImageGenerateInput,
@@ -14,13 +14,13 @@ import type {
14
14
  * @template TOutput - The output type after optional transform (defaults to ImageGenerationResult)
15
15
  */
16
16
  export interface CreateGenerateImageOptions<TOutput = ImageGenerationResult> {
17
- /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */
18
- connection?: ConnectionAdapter
17
+ /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
18
+ connection?: ConnectConnectionAdapter
19
19
  /** Direct async function for image generation */
20
20
  fetcher?: GenerationFetcher<ImageGenerateInput, ImageGenerationResult>
21
21
  /** Unique identifier for this generation instance */
22
22
  id?: string
23
- /** Additional body parameters to send with ConnectionAdapter requests */
23
+ /** Additional body parameters to send with connect-based adapter requests */
24
24
  body?: Record<string, any>
25
25
  /**
26
26
  * Callback when images are generated. Can optionally return a transformed value.
@@ -34,7 +34,7 @@ export interface CreateGenerateImageOptions<TOutput = ImageGenerationResult> {
34
34
  onError?: (error: Error) => void
35
35
  /** Callback when progress is reported (0-100) */
36
36
  onProgress?: (progress: number, message?: string) => void
37
- /** Callback for each stream chunk (ConnectionAdapter mode only) */
37
+ /** Callback for each stream chunk (connect-based adapter mode only) */
38
38
  onChunk?: (chunk: StreamChunk) => void
39
39
  }
40
40
 
@@ -66,7 +66,7 @@ export interface CreateGenerateImageReturn<TOutput = ImageGenerationResult> {
66
66
  * Creates a reactive image generation instance for Svelte 5.
67
67
  *
68
68
  * Supports two transport modes:
69
- * - **ConnectionAdapter** -- Streaming transport (SSE, HTTP stream, custom)
69
+ * - **ConnectConnectionAdapter** -- Streaming transport (SSE, HTTP stream, custom)
70
70
  * - **Fetcher** -- Direct async function call
71
71
  *
72
72
  * @example
@@ -1,7 +1,7 @@
1
1
  import { createGeneration } from './create-generation.svelte'
2
2
  import type { StreamChunk, TTSResult } from '@tanstack/ai'
3
3
  import type {
4
- ConnectionAdapter,
4
+ ConnectConnectionAdapter,
5
5
  GenerationClientState,
6
6
  GenerationFetcher,
7
7
  InferGenerationOutput,
@@ -14,13 +14,13 @@ import type {
14
14
  * @template TOutput - The output type after optional transform (defaults to TTSResult)
15
15
  */
16
16
  export interface CreateGenerateSpeechOptions<TOutput = TTSResult> {
17
- /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */
18
- connection?: ConnectionAdapter
17
+ /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
18
+ connection?: ConnectConnectionAdapter
19
19
  /** Direct async function for speech generation */
20
20
  fetcher?: GenerationFetcher<SpeechGenerateInput, TTSResult>
21
21
  /** Unique identifier for this generation instance */
22
22
  id?: string
23
- /** Additional body parameters to send with ConnectionAdapter requests */
23
+ /** Additional body parameters to send with connect-based adapter requests */
24
24
  body?: Record<string, any>
25
25
  /**
26
26
  * Callback when speech is generated. Can optionally return a transformed value.
@@ -34,7 +34,7 @@ export interface CreateGenerateSpeechOptions<TOutput = TTSResult> {
34
34
  onError?: (error: Error) => void
35
35
  /** Callback when progress is reported (0-100) */
36
36
  onProgress?: (progress: number, message?: string) => void
37
- /** Callback for each stream chunk (ConnectionAdapter mode only) */
37
+ /** Callback for each stream chunk (connect-based adapter mode only) */
38
38
  onChunk?: (chunk: StreamChunk) => void
39
39
  }
40
40
 
@@ -1,7 +1,7 @@
1
1
  import { VideoGenerationClient } from '@tanstack/ai-client'
2
2
  import type { StreamChunk } from '@tanstack/ai'
3
3
  import type {
4
- ConnectionAdapter,
4
+ ConnectConnectionAdapter,
5
5
  GenerationClientState,
6
6
  GenerationFetcher,
7
7
  InferGenerationOutput,
@@ -16,13 +16,13 @@ import type {
16
16
  * @template TOutput - The output type after optional transform (defaults to VideoGenerateResult)
17
17
  */
18
18
  export interface CreateGenerateVideoOptions<TOutput = VideoGenerateResult> {
19
- /** Connection adapter for streaming transport (server handles polling) */
20
- connection?: ConnectionAdapter
19
+ /** Connect-based adapter for streaming transport (server handles polling) */
20
+ connection?: ConnectConnectionAdapter
21
21
  /** Direct async function that returns a completed video result */
22
22
  fetcher?: GenerationFetcher<VideoGenerateInput, VideoGenerateResult>
23
23
  /** Unique identifier for this generation instance */
24
24
  id?: string
25
- /** Additional body parameters to send with ConnectionAdapter requests */
25
+ /** Additional body parameters to send with connect-based adapter requests */
26
26
  body?: Record<string, any>
27
27
  /**
28
28
  * Callback when video generation completes. Can optionally return a transformed value.
@@ -40,7 +40,7 @@ export interface CreateGenerateVideoOptions<TOutput = VideoGenerateResult> {
40
40
  onJobCreated?: (jobId: string) => void
41
41
  /** Callback on each status update */
42
42
  onStatusUpdate?: (status: VideoStatusInfo) => void
43
- /** Callback for each stream chunk (ConnectionAdapter mode only) */
43
+ /** Callback for each stream chunk (connect-based adapter mode only) */
44
44
  onChunk?: (chunk: StreamChunk) => void
45
45
  }
46
46
 
@@ -1,7 +1,7 @@
1
1
  import { GenerationClient } from '@tanstack/ai-client'
2
2
  import type { StreamChunk } from '@tanstack/ai'
3
3
  import type {
4
- ConnectionAdapter,
4
+ ConnectConnectionAdapter,
5
5
  GenerationClientOptions,
6
6
  GenerationClientState,
7
7
  GenerationFetcher,
@@ -18,13 +18,13 @@ import type {
18
18
  * @template TOutput - The output type after optional transform (defaults to TResult)
19
19
  */
20
20
  export interface CreateGenerationOptions<TInput, TResult, TOutput = TResult> {
21
- /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */
22
- connection?: ConnectionAdapter
21
+ /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
22
+ connection?: ConnectConnectionAdapter
23
23
  /** Direct async function for one-shot generation (no streaming protocol needed) */
24
24
  fetcher?: GenerationFetcher<TInput, TResult>
25
25
  /** Unique identifier for this generation instance */
26
26
  id?: string
27
- /** Additional body parameters to send with ConnectionAdapter requests */
27
+ /** Additional body parameters to send with connect-based adapter requests */
28
28
  body?: Record<string, any>
29
29
  /**
30
30
  * Callback when a result is received. Can optionally return a transformed value.
@@ -38,7 +38,7 @@ export interface CreateGenerationOptions<TInput, TResult, TOutput = TResult> {
38
38
  onError?: (error: Error) => void
39
39
  /** Callback when progress is reported (0-100) */
40
40
  onProgress?: (progress: number, message?: string) => void
41
- /** Callback for each stream chunk (ConnectionAdapter mode only) */
41
+ /** Callback for each stream chunk (connect-based adapter mode only) */
42
42
  onChunk?: (chunk: StreamChunk) => void
43
43
  }
44
44
 
@@ -1,7 +1,7 @@
1
1
  import { createGeneration } from './create-generation.svelte'
2
2
  import type { StreamChunk, SummarizationResult } from '@tanstack/ai'
3
3
  import type {
4
- ConnectionAdapter,
4
+ ConnectConnectionAdapter,
5
5
  GenerationClientState,
6
6
  GenerationFetcher,
7
7
  InferGenerationOutput,
@@ -14,13 +14,13 @@ import type {
14
14
  * @template TOutput - The output type after optional transform (defaults to SummarizationResult)
15
15
  */
16
16
  export interface CreateSummarizeOptions<TOutput = SummarizationResult> {
17
- /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */
18
- connection?: ConnectionAdapter
17
+ /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
18
+ connection?: ConnectConnectionAdapter
19
19
  /** Direct async function for summarization */
20
20
  fetcher?: GenerationFetcher<SummarizeGenerateInput, SummarizationResult>
21
21
  /** Unique identifier for this generation instance */
22
22
  id?: string
23
- /** Additional body parameters to send with ConnectionAdapter requests */
23
+ /** Additional body parameters to send with connect-based adapter requests */
24
24
  body?: Record<string, any>
25
25
  /**
26
26
  * Callback when summarization is complete. Can optionally return a transformed value.
@@ -34,7 +34,7 @@ export interface CreateSummarizeOptions<TOutput = SummarizationResult> {
34
34
  onError?: (error: Error) => void
35
35
  /** Callback when progress is reported (0-100) */
36
36
  onProgress?: (progress: number, message?: string) => void
37
- /** Callback for each stream chunk (ConnectionAdapter mode only) */
37
+ /** Callback for each stream chunk (connect-based adapter mode only) */
38
38
  onChunk?: (chunk: StreamChunk) => void
39
39
  }
40
40
 
@@ -1,7 +1,7 @@
1
1
  import { createGeneration } from './create-generation.svelte'
2
2
  import type { StreamChunk, TranscriptionResult } from '@tanstack/ai'
3
3
  import type {
4
- ConnectionAdapter,
4
+ ConnectConnectionAdapter,
5
5
  GenerationClientState,
6
6
  GenerationFetcher,
7
7
  InferGenerationOutput,
@@ -14,13 +14,13 @@ import type {
14
14
  * @template TOutput - The output type after optional transform (defaults to TranscriptionResult)
15
15
  */
16
16
  export interface CreateTranscriptionOptions<TOutput = TranscriptionResult> {
17
- /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */
18
- connection?: ConnectionAdapter
17
+ /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
18
+ connection?: ConnectConnectionAdapter
19
19
  /** Direct async function for transcription */
20
20
  fetcher?: GenerationFetcher<TranscriptionGenerateInput, TranscriptionResult>
21
21
  /** Unique identifier for this generation instance */
22
22
  id?: string
23
- /** Additional body parameters to send with ConnectionAdapter requests */
23
+ /** Additional body parameters to send with connect-based adapter requests */
24
24
  body?: Record<string, any>
25
25
  /**
26
26
  * Callback when transcription is complete. Can optionally return a transformed value.
@@ -34,7 +34,7 @@ export interface CreateTranscriptionOptions<TOutput = TranscriptionResult> {
34
34
  onError?: (error: Error) => void
35
35
  /** Callback when progress is reported (0-100) */
36
36
  onProgress?: (progress: number, message?: string) => void
37
- /** Callback for each stream chunk (ConnectionAdapter mode only) */
37
+ /** Callback for each stream chunk (connect-based adapter mode only) */
38
38
  onChunk?: (chunk: StreamChunk) => void
39
39
  }
40
40
 
package/src/types.ts CHANGED
@@ -3,6 +3,7 @@ import type {
3
3
  ChatClientOptions,
4
4
  ChatClientState,
5
5
  ChatRequestBody,
6
+ ConnectionStatus,
6
7
  MultimodalContent,
7
8
  UIMessage,
8
9
  } from '@tanstack/ai-client'
@@ -30,8 +31,16 @@ export type CreateChatOptions<
30
31
  TTools extends ReadonlyArray<AnyClientTool> = any,
31
32
  > = Omit<
32
33
  ChatClientOptions<TTools>,
33
- 'onMessagesChange' | 'onLoadingChange' | 'onErrorChange' | 'onStatusChange'
34
- >
34
+ | 'onMessagesChange'
35
+ | 'onLoadingChange'
36
+ | 'onErrorChange'
37
+ | 'onStatusChange'
38
+ | 'onSubscriptionChange'
39
+ | 'onConnectionStatusChange'
40
+ | 'onSessionGeneratingChange'
41
+ > & {
42
+ live?: boolean
43
+ }
35
44
 
36
45
  export interface CreateChatReturn<
37
46
  TTools extends ReadonlyArray<AnyClientTool> = any,
@@ -105,6 +114,21 @@ export interface CreateChatReturn<
105
114
  * Current generation status (reactive getter)
106
115
  */
107
116
  readonly status: ChatClientState
117
+ /**
118
+ * Whether the subscription loop is currently active (reactive getter)
119
+ */
120
+ readonly isSubscribed: boolean
121
+ /**
122
+ * Current connection lifecycle status (reactive getter)
123
+ */
124
+ readonly connectionStatus: ConnectionStatus
125
+ /**
126
+ * Whether the shared session is actively generating (reactive getter).
127
+ * Derived from stream run events (RUN_STARTED / RUN_FINISHED / RUN_ERROR).
128
+ * Unlike `isLoading` (request-local), this reflects shared generation
129
+ * activity visible to all subscribers (e.g. across tabs/devices).
130
+ */
131
+ readonly sessionGenerating: boolean
108
132
  /**
109
133
  * Update the body sent with requests (e.g., for changing model selection)
110
134
  */