@tanstack/ai-client 0.9.2 → 0.11.0
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 +0 -4
- package/dist/esm/chat-client.d.ts +5 -1
- package/dist/esm/chat-client.js +28 -10
- package/dist/esm/chat-client.js.map +1 -1
- package/dist/esm/connection-adapters.d.ts +20 -2
- package/dist/esm/connection-adapters.js +71 -15
- package/dist/esm/connection-adapters.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/types.d.ts +34 -7
- package/dist/esm/types.js.map +1 -1
- package/package.json +4 -4
- package/src/chat-client.ts +69 -14
- package/src/connection-adapters.ts +108 -19
- package/src/index.ts +1 -0
- package/src/types.ts +44 -5
package/src/index.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -9,10 +9,13 @@ import type {
|
|
|
9
9
|
InferToolOutput,
|
|
10
10
|
ModelMessage,
|
|
11
11
|
StreamChunk,
|
|
12
|
+
StructuredOutputPart,
|
|
12
13
|
VideoPart,
|
|
13
14
|
} from '@tanstack/ai'
|
|
14
15
|
import type { ConnectionAdapter } from './connection-adapters'
|
|
15
16
|
|
|
17
|
+
export type { StructuredOutputPart } from '@tanstack/ai'
|
|
18
|
+
|
|
16
19
|
/**
|
|
17
20
|
* Tool call states - track the lifecycle of a tool call
|
|
18
21
|
*/
|
|
@@ -162,7 +165,10 @@ export interface ThinkingPart {
|
|
|
162
165
|
content: string
|
|
163
166
|
}
|
|
164
167
|
|
|
165
|
-
export type MessagePart<
|
|
168
|
+
export type MessagePart<
|
|
169
|
+
TTools extends ReadonlyArray<AnyClientTool> = any,
|
|
170
|
+
TData = unknown,
|
|
171
|
+
> =
|
|
166
172
|
| TextPart
|
|
167
173
|
| ImagePart
|
|
168
174
|
| AudioPart
|
|
@@ -171,15 +177,27 @@ export type MessagePart<TTools extends ReadonlyArray<AnyClientTool> = any> =
|
|
|
171
177
|
| ToolCallPart<TTools>
|
|
172
178
|
| ToolResultPart
|
|
173
179
|
| ThinkingPart
|
|
180
|
+
| StructuredOutputPart<TData>
|
|
174
181
|
|
|
175
182
|
/**
|
|
176
183
|
* UIMessage - Domain-specific message format optimized for building chat UIs
|
|
177
|
-
* Contains parts that can be text, tool calls, or tool results
|
|
184
|
+
* Contains parts that can be text, tool calls, or tool results.
|
|
185
|
+
*
|
|
186
|
+
* `TTools` narrows the tool-call/result part types based on the registered
|
|
187
|
+
* tools. `TData` is the schema-inferred type for any `structured-output` part
|
|
188
|
+
* on the message — defaulted to `unknown` so untyped consumers (the core
|
|
189
|
+
* stream processor, the wire converter) don't need to thread a schema generic
|
|
190
|
+
* everywhere; the hook layer (`useChat({ outputSchema })`) substitutes it on
|
|
191
|
+
* the public return so `m.parts.find(p => p.type === 'structured-output').data`
|
|
192
|
+
* is typed without manual casts.
|
|
178
193
|
*/
|
|
179
|
-
export interface UIMessage<
|
|
194
|
+
export interface UIMessage<
|
|
195
|
+
TTools extends ReadonlyArray<AnyClientTool> = any,
|
|
196
|
+
TData = unknown,
|
|
197
|
+
> {
|
|
180
198
|
id: string
|
|
181
199
|
role: 'system' | 'user' | 'assistant'
|
|
182
|
-
parts: Array<MessagePart<TTools>>
|
|
200
|
+
parts: Array<MessagePart<TTools, TData>>
|
|
183
201
|
createdAt?: Date
|
|
184
202
|
}
|
|
185
203
|
|
|
@@ -205,7 +223,28 @@ export interface ChatClientOptions<
|
|
|
205
223
|
id?: string
|
|
206
224
|
|
|
207
225
|
/**
|
|
208
|
-
*
|
|
226
|
+
* Thread ID to use for this chat session. Persists across sends within
|
|
227
|
+
* the session. If omitted, a unique thread ID is generated.
|
|
228
|
+
*/
|
|
229
|
+
threadId?: string
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Arbitrary client-controlled JSON forwarded to the server in the
|
|
233
|
+
* AG-UI `RunAgentInput.forwardedProps` field. Use this for per-session
|
|
234
|
+
* options like provider/model selection or feature flags that the
|
|
235
|
+
* server endpoint should read.
|
|
236
|
+
*
|
|
237
|
+
* Replaces the legacy `body` option. If both are provided,
|
|
238
|
+
* `forwardedProps` wins on key collision.
|
|
239
|
+
*/
|
|
240
|
+
forwardedProps?: Record<string, any>
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* @deprecated Use `forwardedProps` instead. `body` continues to work
|
|
244
|
+
* unchanged — its values are merged into the AG-UI
|
|
245
|
+
* `RunAgentInput.forwardedProps` field on the wire and are also
|
|
246
|
+
* mirrored under the legacy `data` field for servers that have not
|
|
247
|
+
* migrated yet. Will be removed in a future major release.
|
|
209
248
|
*/
|
|
210
249
|
body?: Record<string, any>
|
|
211
250
|
|