@tanstack/ai-client 0.6.0 → 0.7.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.
- package/README.md +6 -6
- package/dist/esm/chat-client.d.ts +62 -3
- package/dist/esm/chat-client.js +264 -54
- package/dist/esm/chat-client.js.map +1 -1
- package/dist/esm/connection-adapters.d.ts +28 -12
- package/dist/esm/connection-adapters.js +93 -0
- package/dist/esm/connection-adapters.js.map +1 -1
- package/dist/esm/events.js +1 -1
- package/dist/esm/events.js.map +1 -1
- package/dist/esm/generation-client.d.ts +5 -5
- package/dist/esm/generation-client.js +1 -1
- package/dist/esm/generation-client.js.map +1 -1
- package/dist/esm/generation-types.d.ts +5 -5
- package/dist/esm/generation-types.js.map +1 -1
- package/dist/esm/index.d.ts +4 -2
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/realtime-client.d.ts +98 -0
- package/dist/esm/realtime-client.js +384 -0
- package/dist/esm/realtime-client.js.map +1 -0
- package/dist/esm/realtime-types.d.ts +118 -0
- package/dist/esm/types.d.ts +23 -2
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/video-generation-client.d.ts +5 -5
- package/dist/esm/video-generation-client.js +1 -1
- package/dist/esm/video-generation-client.js.map +1 -1
- package/package.json +3 -2
- package/src/chat-client.ts +355 -86
- package/src/connection-adapters.ts +147 -12
- package/src/events.ts +1 -1
- package/src/generation-client.ts +7 -7
- package/src/generation-types.ts +5 -5
- package/src/index.ts +11 -0
- package/src/realtime-client.ts +526 -0
- package/src/realtime-types.ts +180 -0
- package/src/types.ts +31 -2
- package/src/video-generation-client.ts +6 -6
package/src/types.ts
CHANGED
|
@@ -36,6 +36,15 @@ export type ToolResultState =
|
|
|
36
36
|
*/
|
|
37
37
|
export type ChatClientState = 'ready' | 'submitted' | 'streaming' | 'error'
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Connection lifecycle state for the subscription loop.
|
|
41
|
+
*/
|
|
42
|
+
export type ConnectionStatus =
|
|
43
|
+
| 'disconnected'
|
|
44
|
+
| 'connecting'
|
|
45
|
+
| 'connected'
|
|
46
|
+
| 'error'
|
|
47
|
+
|
|
39
48
|
/**
|
|
40
49
|
* Multimodal content input for sending messages with rich media.
|
|
41
50
|
* Allows sending text, images, audio, video, and documents to the LLM.
|
|
@@ -178,8 +187,9 @@ export interface ChatClientOptions<
|
|
|
178
187
|
TTools extends ReadonlyArray<AnyClientTool> = any,
|
|
179
188
|
> {
|
|
180
189
|
/**
|
|
181
|
-
* Connection adapter for streaming
|
|
182
|
-
*
|
|
190
|
+
* Connection adapter for streaming.
|
|
191
|
+
* Supports mutually exclusive modes: request-response via `connect()`, or
|
|
192
|
+
* subscribe/send mode via `subscribe()` + `send()`.
|
|
183
193
|
*/
|
|
184
194
|
connection: ConnectionAdapter
|
|
185
195
|
|
|
@@ -239,6 +249,25 @@ export interface ChatClientOptions<
|
|
|
239
249
|
*/
|
|
240
250
|
onStatusChange?: (status: ChatClientState) => void
|
|
241
251
|
|
|
252
|
+
/**
|
|
253
|
+
* Callback when subscription lifecycle changes.
|
|
254
|
+
* This is independent from request lifecycle (`isLoading`, `status`).
|
|
255
|
+
*/
|
|
256
|
+
onSubscriptionChange?: (isSubscribed: boolean) => void
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Callback when connection lifecycle changes.
|
|
260
|
+
*/
|
|
261
|
+
onConnectionStatusChange?: (status: ConnectionStatus) => void
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Callback when session generation activity changes.
|
|
265
|
+
* Derived from stream run events (RUN_STARTED / RUN_FINISHED / RUN_ERROR).
|
|
266
|
+
* Unlike `onLoadingChange` (request-local), this reflects shared generation
|
|
267
|
+
* activity visible to all subscribers (e.g. across tabs/devices).
|
|
268
|
+
*/
|
|
269
|
+
onSessionGeneratingChange?: (isGenerating: boolean) => void
|
|
270
|
+
|
|
242
271
|
/**
|
|
243
272
|
* Callback when a custom event is received from a server-side tool.
|
|
244
273
|
* Custom events are emitted by tools using `context.emitCustomEvent()` during execution.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GENERATION_EVENTS } from './generation-types'
|
|
2
2
|
import { parseSSEResponse } from './sse-parser'
|
|
3
3
|
import type { StreamChunk } from '@tanstack/ai'
|
|
4
|
-
import type {
|
|
4
|
+
import type { ConnectConnectionAdapter } from './connection-adapters'
|
|
5
5
|
import type {
|
|
6
6
|
GenerationClientState,
|
|
7
7
|
GenerationFetcher,
|
|
@@ -36,14 +36,14 @@ interface VideoCallbacks<TOutput> {
|
|
|
36
36
|
* until completion. This client handles the full lifecycle.
|
|
37
37
|
*
|
|
38
38
|
* Supports two transport modes:
|
|
39
|
-
* - **
|
|
39
|
+
* - **ConnectConnectionAdapter** — Server handles the polling loop internally and
|
|
40
40
|
* streams status updates via CUSTOM events.
|
|
41
41
|
* - **Fetcher** — Direct async function that returns a completed
|
|
42
42
|
* `VideoGenerateResult`.
|
|
43
43
|
*
|
|
44
44
|
* @example
|
|
45
45
|
* ```typescript
|
|
46
|
-
* // With
|
|
46
|
+
* // With streaming connection adapter (server-driven polling)
|
|
47
47
|
* const client = new VideoGenerationClient({
|
|
48
48
|
* connection: fetchServerSentEvents('/api/generate/video'),
|
|
49
49
|
* onResultChange: setResult,
|
|
@@ -65,7 +65,7 @@ interface VideoCallbacks<TOutput> {
|
|
|
65
65
|
* ```
|
|
66
66
|
*/
|
|
67
67
|
export class VideoGenerationClient<TOutput = VideoGenerateResult> {
|
|
68
|
-
private connection:
|
|
68
|
+
private connection: ConnectConnectionAdapter | undefined
|
|
69
69
|
private fetcher:
|
|
70
70
|
| GenerationFetcher<VideoGenerateInput, VideoGenerateResult>
|
|
71
71
|
| undefined
|
|
@@ -83,7 +83,7 @@ export class VideoGenerationClient<TOutput = VideoGenerateResult> {
|
|
|
83
83
|
constructor(
|
|
84
84
|
options: VideoGenerationClientOptions<TOutput> &
|
|
85
85
|
(
|
|
86
|
-
| { connection:
|
|
86
|
+
| { connection: ConnectConnectionAdapter; fetcher?: never }
|
|
87
87
|
| {
|
|
88
88
|
fetcher: GenerationFetcher<VideoGenerateInput, VideoGenerateResult>
|
|
89
89
|
connection?: never
|
|
@@ -174,7 +174,7 @@ export class VideoGenerationClient<TOutput = VideoGenerateResult> {
|
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
/**
|
|
177
|
-
* Process a stream of AG-UI events from the
|
|
177
|
+
* Process a stream of AG-UI events from the streaming connection adapter.
|
|
178
178
|
* The server handles the polling loop and streams status updates.
|
|
179
179
|
*/
|
|
180
180
|
private async processStream(
|