@tanstack/ai-client 0.18.4 → 0.18.5
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/package.json +3 -3
- package/dist/esm/chat-client.d.ts +0 -264
- package/dist/esm/chat-client.js +0 -1097
- package/dist/esm/chat-client.js.map +0 -1
- package/dist/esm/client-persistor.d.ts +0 -86
- package/dist/esm/client-persistor.js +0 -243
- package/dist/esm/client-persistor.js.map +0 -1
- package/dist/esm/connection-adapters.d.ts +0 -203
- package/dist/esm/connection-adapters.js +0 -611
- package/dist/esm/connection-adapters.js.map +0 -1
- package/dist/esm/devtools-noop.d.ts +0 -63
- package/dist/esm/devtools-noop.js +0 -141
- package/dist/esm/devtools-noop.js.map +0 -1
- package/dist/esm/devtools.d.ts +0 -276
- package/dist/esm/devtools.js +0 -1178
- package/dist/esm/devtools.js.map +0 -1
- package/dist/esm/events.d.ts +0 -129
- package/dist/esm/events.js +0 -227
- package/dist/esm/events.js.map +0 -1
- package/dist/esm/generation-client.d.ts +0 -99
- package/dist/esm/generation-client.js +0 -325
- package/dist/esm/generation-client.js.map +0 -1
- package/dist/esm/generation-types.d.ts +0 -242
- package/dist/esm/generation-types.js +0 -14
- package/dist/esm/generation-types.js.map +0 -1
- package/dist/esm/index.d.ts +0 -16
- package/dist/esm/index.js +0 -44
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/realtime-client.d.ts +0 -98
- package/dist/esm/realtime-client.js +0 -403
- package/dist/esm/realtime-client.js.map +0 -1
- package/dist/esm/realtime-types.d.ts +0 -78
- package/dist/esm/response-stream.d.ts +0 -7
- package/dist/esm/response-stream.js +0 -32
- package/dist/esm/response-stream.js.map +0 -1
- package/dist/esm/sse-parser.d.ts +0 -8
- package/dist/esm/sse-parser.js +0 -52
- package/dist/esm/sse-parser.js.map +0 -1
- package/dist/esm/sse-utils.d.ts +0 -1
- package/dist/esm/sse-utils.js +0 -11
- package/dist/esm/sse-utils.js.map +0 -1
- package/dist/esm/tool-types.d.ts +0 -20
- package/dist/esm/types.d.ts +0 -419
- package/dist/esm/types.js +0 -11
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/video-generation-client.d.ts +0 -110
- package/dist/esm/video-generation-client.js +0 -382
- package/dist/esm/video-generation-client.js.map +0 -1
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
import { ModelMessage, StreamChunk, UIMessage } from '@tanstack/ai/client';
|
|
2
|
-
import { ChatFetcher } from './types.js';
|
|
3
|
-
/**
|
|
4
|
-
* Resolve a chunk's run id, preferring the value on the chunk itself
|
|
5
|
-
* (RUN_STARTED / RUN_FINISHED / RUN_ERROR carry one) and falling back to the
|
|
6
|
-
* run the connect wrapper stamped it with.
|
|
7
|
-
*/
|
|
8
|
-
export declare function getChunkRunId(chunk: StreamChunk): string | undefined;
|
|
9
|
-
/**
|
|
10
|
-
* Thrown when an SSE/HTTP stream ends with a non-empty unterminated buffer.
|
|
11
|
-
* Indicates the connection was cut mid-line (server crash, dropped TCP, proxy
|
|
12
|
-
* timeout) so the partial content cannot be safely parsed.
|
|
13
|
-
*/
|
|
14
|
-
export declare class StreamTruncatedError extends Error {
|
|
15
|
-
constructor();
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Per-send context provided by the chat client to the connection adapter.
|
|
19
|
-
* The adapter combines this with serialized messages to build a full
|
|
20
|
-
* AG-UI `RunAgentInput` payload.
|
|
21
|
-
*/
|
|
22
|
-
export interface RunAgentInputContext {
|
|
23
|
-
threadId: string;
|
|
24
|
-
runId: string;
|
|
25
|
-
parentRunId?: string;
|
|
26
|
-
/** Client-declared tools to advertise in the request payload. */
|
|
27
|
-
clientTools?: Array<{
|
|
28
|
-
name: string;
|
|
29
|
-
description: string;
|
|
30
|
-
parameters: unknown;
|
|
31
|
-
}>;
|
|
32
|
-
/** Arbitrary user-controlled passthrough data. */
|
|
33
|
-
forwardedProps?: Record<string, unknown>;
|
|
34
|
-
}
|
|
35
|
-
export interface ConnectConnectionAdapter {
|
|
36
|
-
/**
|
|
37
|
-
* Connect and return an async iterable of StreamChunks.
|
|
38
|
-
*/
|
|
39
|
-
connect: (messages: Array<UIMessage> | Array<ModelMessage>, data?: Record<string, any>, abortSignal?: AbortSignal, runContext?: RunAgentInputContext) => AsyncIterable<StreamChunk>;
|
|
40
|
-
}
|
|
41
|
-
export interface SubscribeConnectionAdapter {
|
|
42
|
-
/**
|
|
43
|
-
* Subscribe to stream chunks.
|
|
44
|
-
*/
|
|
45
|
-
subscribe: (abortSignal?: AbortSignal) => AsyncIterable<StreamChunk>;
|
|
46
|
-
/**
|
|
47
|
-
* Send a request; chunks arrive through subscribe().
|
|
48
|
-
*/
|
|
49
|
-
send: (messages: Array<UIMessage> | Array<ModelMessage>, data?: Record<string, any>, abortSignal?: AbortSignal, runContext?: RunAgentInputContext) => Promise<void>;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Connection adapter union.
|
|
53
|
-
* Provide either `connect`, or `subscribe` + `send`.
|
|
54
|
-
*/
|
|
55
|
-
export type ConnectionAdapter = ConnectConnectionAdapter | SubscribeConnectionAdapter;
|
|
56
|
-
/**
|
|
57
|
-
* Normalize a ConnectionAdapter to subscribe/send operations.
|
|
58
|
-
*
|
|
59
|
-
* If a connection provides native subscribe/send, that mode is used.
|
|
60
|
-
* Otherwise, connect() is wrapped using an async queue.
|
|
61
|
-
*/
|
|
62
|
-
export declare function normalizeConnectionAdapter(connection: ConnectionAdapter | undefined): SubscribeConnectionAdapter;
|
|
63
|
-
/**
|
|
64
|
-
* Options for fetch-based connection adapters
|
|
65
|
-
*/
|
|
66
|
-
export interface FetchConnectionOptions {
|
|
67
|
-
headers?: Record<string, string> | Headers;
|
|
68
|
-
credentials?: RequestCredentials;
|
|
69
|
-
signal?: AbortSignal;
|
|
70
|
-
body?: Record<string, any>;
|
|
71
|
-
fetchClient?: typeof globalThis.fetch;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Options for XHR-based connection adapters.
|
|
75
|
-
*/
|
|
76
|
-
export interface XhrConnectionOptions {
|
|
77
|
-
headers?: Record<string, string> | Headers;
|
|
78
|
-
withCredentials?: boolean;
|
|
79
|
-
signal?: AbortSignal;
|
|
80
|
-
body?: Record<string, any>;
|
|
81
|
-
xhrFactory?: () => XMLHttpRequest;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Create a Server-Sent Events connection adapter
|
|
85
|
-
*
|
|
86
|
-
* @param url - The API endpoint URL (or a function that returns the URL)
|
|
87
|
-
* @param options - Fetch options (headers, credentials, body, etc.) or a function that returns options (can be async)
|
|
88
|
-
* @returns A connection adapter for SSE streams
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```typescript
|
|
92
|
-
* // Static URL
|
|
93
|
-
* const connection = fetchServerSentEvents('/api/chat');
|
|
94
|
-
*
|
|
95
|
-
* // Dynamic URL
|
|
96
|
-
* const connection = fetchServerSentEvents(() => `/api/chat?user=${userId}`);
|
|
97
|
-
*
|
|
98
|
-
* // With options
|
|
99
|
-
* const connection = fetchServerSentEvents('/api/chat', {
|
|
100
|
-
* headers: { 'Authorization': 'Bearer token' }
|
|
101
|
-
* });
|
|
102
|
-
*
|
|
103
|
-
* // With dynamic options
|
|
104
|
-
* const connection = fetchServerSentEvents('/api/chat', () => ({
|
|
105
|
-
* headers: { 'Authorization': `Bearer ${getToken()}` }
|
|
106
|
-
* }));
|
|
107
|
-
*
|
|
108
|
-
* // With additional body data
|
|
109
|
-
* const connection = fetchServerSentEvents('/api/chat', async () => ({
|
|
110
|
-
* body: {
|
|
111
|
-
* provider: 'openai',
|
|
112
|
-
* model: 'gpt-4o',
|
|
113
|
-
* }
|
|
114
|
-
* }));
|
|
115
|
-
* ```
|
|
116
|
-
*/
|
|
117
|
-
export declare function fetchServerSentEvents(url: string | (() => string), options?: FetchConnectionOptions | (() => FetchConnectionOptions | Promise<FetchConnectionOptions>)): ConnectConnectionAdapter;
|
|
118
|
-
/**
|
|
119
|
-
* Create an HTTP streaming connection adapter (for raw streaming without SSE format)
|
|
120
|
-
*
|
|
121
|
-
* @param url - The API endpoint URL (or a function that returns the URL)
|
|
122
|
-
* @param options - Fetch options (headers, credentials, body, etc.) or a function that returns options (can be async)
|
|
123
|
-
* @returns A connection adapter for HTTP streams
|
|
124
|
-
*
|
|
125
|
-
* @example
|
|
126
|
-
* ```typescript
|
|
127
|
-
* // Static URL
|
|
128
|
-
* const connection = fetchHttpStream('/api/chat');
|
|
129
|
-
*
|
|
130
|
-
* // Dynamic URL
|
|
131
|
-
* const connection = fetchHttpStream(() => `/api/chat?user=${userId}`);
|
|
132
|
-
*
|
|
133
|
-
* // With options
|
|
134
|
-
* const connection = fetchHttpStream('/api/chat', {
|
|
135
|
-
* headers: { 'Authorization': 'Bearer token' }
|
|
136
|
-
* });
|
|
137
|
-
*
|
|
138
|
-
* // With dynamic options
|
|
139
|
-
* const connection = fetchHttpStream('/api/chat', () => ({
|
|
140
|
-
* headers: { 'Authorization': `Bearer ${getToken()}` }
|
|
141
|
-
* }));
|
|
142
|
-
*
|
|
143
|
-
* // With additional body data
|
|
144
|
-
* const connection = fetchHttpStream('/api/chat', async () => ({
|
|
145
|
-
* body: {
|
|
146
|
-
* provider: 'openai',
|
|
147
|
-
* model: 'gpt-4o',
|
|
148
|
-
* }
|
|
149
|
-
* }));
|
|
150
|
-
* ```
|
|
151
|
-
*/
|
|
152
|
-
export declare function fetchHttpStream(url: string | (() => string), options?: FetchConnectionOptions | (() => FetchConnectionOptions | Promise<FetchConnectionOptions>)): ConnectConnectionAdapter;
|
|
153
|
-
type XhrConnectionOptionsResolver = XhrConnectionOptions | (() => XhrConnectionOptions | Promise<XhrConnectionOptions>);
|
|
154
|
-
/**
|
|
155
|
-
* Create an XMLHttpRequest-backed Server-Sent Events connection adapter.
|
|
156
|
-
*/
|
|
157
|
-
export declare function xhrServerSentEvents(url: string | (() => string), options?: XhrConnectionOptionsResolver): ConnectConnectionAdapter;
|
|
158
|
-
/**
|
|
159
|
-
* Create an XMLHttpRequest-backed newline-delimited JSON stream adapter.
|
|
160
|
-
*/
|
|
161
|
-
export declare function xhrHttpStream(url: string | (() => string), options?: XhrConnectionOptionsResolver): ConnectConnectionAdapter;
|
|
162
|
-
/**
|
|
163
|
-
* Create a direct stream connection adapter (for server functions or direct streams)
|
|
164
|
-
*
|
|
165
|
-
* @param streamFactory - A function that returns an async iterable of StreamChunks
|
|
166
|
-
* @returns A connection adapter for direct streams
|
|
167
|
-
*
|
|
168
|
-
* @example
|
|
169
|
-
* ```typescript
|
|
170
|
-
* // With TanStack Start server function
|
|
171
|
-
* const connection = stream(() => serverFunction({ messages }));
|
|
172
|
-
*
|
|
173
|
-
* const client = new ChatClient({ connection });
|
|
174
|
-
* ```
|
|
175
|
-
*/
|
|
176
|
-
export declare function stream(streamFactory: (messages: Array<UIMessage> | Array<ModelMessage>, data?: Record<string, any>, abortSignal?: AbortSignal) => AsyncIterable<StreamChunk>): ConnectConnectionAdapter;
|
|
177
|
-
/**
|
|
178
|
-
* Wrap a `ChatFetcher` as a `ConnectConnectionAdapter` so the chat client can
|
|
179
|
-
* consume it through the same `subscribe`/`send` plumbing used for SSE /
|
|
180
|
-
* HTTP-stream / RPC connections. May return either a `Response` (parsed as
|
|
181
|
-
* SSE) or an `AsyncIterable<StreamChunk>` (yielded directly).
|
|
182
|
-
*
|
|
183
|
-
* @internal
|
|
184
|
-
*/
|
|
185
|
-
export declare function fetcherToConnectionAdapter(fetcher: ChatFetcher): ConnectConnectionAdapter;
|
|
186
|
-
/**
|
|
187
|
-
* Create an RPC stream connection adapter (for RPC-based streaming like Cap'n Web RPC)
|
|
188
|
-
*
|
|
189
|
-
* @param rpcCall - A function that accepts messages and returns an async iterable of StreamChunks
|
|
190
|
-
* @returns A connection adapter for RPC streams
|
|
191
|
-
*
|
|
192
|
-
* @example
|
|
193
|
-
* ```typescript
|
|
194
|
-
* // With Cap'n Web RPC
|
|
195
|
-
* const connection = rpcStream((messages, data) =>
|
|
196
|
-
* api.streamMurfResponse(messages, data)
|
|
197
|
-
* );
|
|
198
|
-
*
|
|
199
|
-
* const client = new ChatClient({ connection });
|
|
200
|
-
* ```
|
|
201
|
-
*/
|
|
202
|
-
export declare function rpcStream(rpcCall: (messages: Array<UIMessage> | Array<ModelMessage>, data?: Record<string, any>, abortSignal?: AbortSignal) => AsyncIterable<StreamChunk>): ConnectConnectionAdapter;
|
|
203
|
-
export {};
|