@tanstack/ai 0.47.3 → 0.48.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 +2 -1
- package/dist/esm/activities/chat/adapter.d.ts +5 -4
- package/dist/esm/activities/chat/adapter.js.map +1 -1
- package/dist/esm/activities/chat/index.d.ts +4 -7
- package/dist/esm/activities/chat/index.js +201 -243
- package/dist/esm/activities/chat/index.js.map +1 -1
- package/dist/esm/activities/chat/messages.js +115 -25
- package/dist/esm/activities/chat/messages.js.map +1 -1
- package/dist/esm/activities/chat/stream/processor.d.ts +38 -17
- package/dist/esm/activities/chat/stream/processor.js +186 -101
- package/dist/esm/activities/chat/stream/processor.js.map +1 -1
- package/dist/esm/activities/chat/tools/tool-calls.d.ts +3 -2
- package/dist/esm/activities/chat/tools/tool-calls.js +15 -10
- package/dist/esm/activities/chat/tools/tool-calls.js.map +1 -1
- package/dist/esm/activities/generateVideo/index.js +6 -6
- package/dist/esm/activities/generateVideo/index.js.map +1 -1
- package/dist/esm/activities/stream-generation-result.js +7 -8
- package/dist/esm/activities/stream-generation-result.js.map +1 -1
- package/dist/esm/activities/summarize/chat-stream-summarize.d.ts +2 -1
- package/dist/esm/activities/summarize/chat-stream-summarize.js +56 -53
- package/dist/esm/activities/summarize/chat-stream-summarize.js.map +1 -1
- package/dist/esm/adapter-internals.d.ts +2 -0
- package/dist/esm/adapter-internals.js +3 -1
- package/dist/esm/client.d.ts +8 -1
- package/dist/esm/client.js +7 -2
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.js +6 -2
- package/dist/esm/middlewares/otel.js +11 -4
- package/dist/esm/middlewares/otel.js.map +1 -1
- package/dist/esm/stream-to-response.js +8 -5
- package/dist/esm/stream-to-response.js.map +1 -1
- package/dist/esm/stream-to-websocket.js +4 -2
- package/dist/esm/stream-to-websocket.js.map +1 -1
- package/dist/esm/strip-to-spec-middleware.d.ts +10 -13
- package/dist/esm/strip-to-spec-middleware.js +24 -22
- package/dist/esm/strip-to-spec-middleware.js.map +1 -1
- package/dist/esm/types.d.ts +82 -305
- package/dist/esm/utilities/adapter-yield-chunk.d.ts +31 -0
- package/dist/esm/utilities/ag-ui-usage.d.ts +24 -0
- package/dist/esm/utilities/ag-ui-usage.js +66 -0
- package/dist/esm/utilities/ag-ui-usage.js.map +1 -0
- package/dist/esm/utilities/ag-ui-wire.d.ts +14 -7
- package/dist/esm/utilities/ag-ui-wire.js +71 -30
- package/dist/esm/utilities/ag-ui-wire.js.map +1 -1
- package/dist/esm/utilities/chat-params.d.ts +3 -3
- package/dist/esm/utilities/chat-params.js +10 -30
- package/dist/esm/utilities/chat-params.js.map +1 -1
- package/dist/esm/utilities/chunk-ids.d.ts +5 -0
- package/dist/esm/utilities/chunk-ids.js +25 -0
- package/dist/esm/utilities/chunk-ids.js.map +1 -0
- package/dist/esm/utilities/merge-metadata.d.ts +14 -0
- package/dist/esm/utilities/merge-metadata.js +43 -0
- package/dist/esm/utilities/merge-metadata.js.map +1 -0
- package/dist/esm/utilities/normalize-stream-chunk.d.ts +3 -0
- package/dist/esm/utilities/normalize-stream-chunk.js +100 -0
- package/dist/esm/utilities/normalize-stream-chunk.js.map +1 -0
- package/dist/esm/utilities/reasoning-encrypted-value.d.ts +8 -0
- package/dist/esm/utilities/reasoning-encrypted-value.js +16 -0
- package/dist/esm/utilities/reasoning-encrypted-value.js.map +1 -0
- package/dist/esm/utilities/restore-inbound-chunk.d.ts +15 -0
- package/dist/esm/utilities/restore-inbound-chunk.js +43 -0
- package/dist/esm/utilities/restore-inbound-chunk.js.map +1 -0
- package/dist/esm/utilities/spec-event-keys.d.ts +2 -0
- package/dist/esm/utilities/spec-event-keys.js +56 -0
- package/dist/esm/utilities/spec-event-keys.js.map +1 -0
- package/dist/esm/utilities/structured-output-events.d.ts +3 -3
- package/dist/esm/utilities/structured-output-events.js.map +1 -1
- package/package.json +2 -2
- package/src/activities/chat/adapter.ts +4 -4
- package/src/activities/chat/index.ts +398 -400
- package/src/activities/chat/messages.ts +174 -34
- package/src/activities/chat/stream/processor.ts +289 -218
- package/src/activities/chat/tools/tool-calls.ts +23 -22
- package/src/activities/generateVideo/index.ts +7 -6
- package/src/activities/stream-generation-result.ts +8 -12
- package/src/activities/summarize/chat-stream-summarize.ts +94 -70
- package/src/adapter-internals.ts +2 -0
- package/src/client.ts +13 -0
- package/src/index.ts +6 -0
- package/src/middlewares/otel.ts +16 -8
- package/src/stream-to-response.ts +11 -4
- package/src/stream-to-websocket.ts +3 -1
- package/src/strip-to-spec-middleware.ts +48 -24
- package/src/types.ts +109 -393
- package/src/utilities/adapter-yield-chunk.ts +30 -0
- package/src/utilities/ag-ui-usage.test.ts +194 -0
- package/src/utilities/ag-ui-usage.ts +148 -0
- package/src/utilities/ag-ui-wire.ts +149 -31
- package/src/utilities/chat-params.ts +22 -39
- package/src/utilities/chunk-ids.ts +24 -0
- package/src/utilities/merge-metadata.test.ts +117 -0
- package/src/utilities/merge-metadata.ts +59 -0
- package/src/utilities/normalize-stream-chunk.test.ts +423 -0
- package/src/utilities/normalize-stream-chunk.ts +186 -0
- package/src/utilities/reasoning-encrypted-value.ts +18 -0
- package/src/utilities/restore-inbound-chunk.test.ts +133 -0
- package/src/utilities/restore-inbound-chunk.ts +72 -0
- package/src/utilities/spec-event-keys.test.ts +34 -0
- package/src/utilities/spec-event-keys.ts +74 -0
- package/src/utilities/structured-output-events.ts +3 -3
package/src/types.ts
CHANGED
|
@@ -6,7 +6,6 @@ import type { InternalLogger } from './logger/internal-logger'
|
|
|
6
6
|
import type { SystemPrompt } from './system-prompts'
|
|
7
7
|
import type { CapabilityContext } from './activities/chat/middleware/capabilities'
|
|
8
8
|
import type { InterruptSubmissionError } from './interrupts'
|
|
9
|
-
import type { ProviderTool } from './tools/provider-tool'
|
|
10
9
|
// The canonical usage types live in the leaf `@tanstack/ai-event-client`
|
|
11
10
|
// package (which `@tanstack/ai` already depends on) so there is a single source
|
|
12
11
|
// of truth without a dependency cycle. They are re-exported below.
|
|
@@ -48,6 +47,10 @@ import type {
|
|
|
48
47
|
ToolCallStartEvent as AGUIToolCallStartEvent,
|
|
49
48
|
EventType,
|
|
50
49
|
} from '@ag-ui/core'
|
|
50
|
+
import type {
|
|
51
|
+
SpecTokenUsage,
|
|
52
|
+
TokenUsageLeftover,
|
|
53
|
+
} from './utilities/ag-ui-usage'
|
|
51
54
|
|
|
52
55
|
// Re-export ProviderTool so the type is reachable from `@tanstack/ai`'s root
|
|
53
56
|
// entry via `export * from './types'` without forcing the subpath import.
|
|
@@ -510,6 +513,43 @@ export type MessagePart<TData = unknown> =
|
|
|
510
513
|
| StructuredOutputPart<TData>
|
|
511
514
|
| UIResourcePart
|
|
512
515
|
|
|
516
|
+
/**
|
|
517
|
+
* Shape of `metadata.tanstack` on a message.
|
|
518
|
+
* `createdAt` is an ISO-8601 string.
|
|
519
|
+
*/
|
|
520
|
+
export interface TanStackMessageMetadata {
|
|
521
|
+
createdAt?: string
|
|
522
|
+
model?: string
|
|
523
|
+
/** Thinking signature for a `role: 'reasoning'` fan-out message. */
|
|
524
|
+
signature?: string
|
|
525
|
+
/** Per-tool-call provider metadata keyed by tool call id (e.g. Gemini thoughtSignature). */
|
|
526
|
+
toolCallMetadata?: Record<string, unknown>
|
|
527
|
+
structuredOutput?: {
|
|
528
|
+
status?: 'streaming' | 'complete' | 'error'
|
|
529
|
+
raw?: string
|
|
530
|
+
errorMessage?: string
|
|
531
|
+
}
|
|
532
|
+
uiResources?: Array<UIResourcePart>
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Shape of `metadata.tanstack` on run events.
|
|
537
|
+
*/
|
|
538
|
+
export interface TanStackRunMetadata {
|
|
539
|
+
model?: string
|
|
540
|
+
finishReason?: 'stop' | 'length' | 'content_filter' | 'tool_calls' | null
|
|
541
|
+
/** TokenUsage fields that have no AG-UI `usage[]` equivalent. */
|
|
542
|
+
usage?: TokenUsageLeftover
|
|
543
|
+
interruptErrors?: ReadonlyArray<InterruptSubmissionError>
|
|
544
|
+
threadId?: string
|
|
545
|
+
runId?: string
|
|
546
|
+
sessionId?: string
|
|
547
|
+
index?: number
|
|
548
|
+
state?: ToolOutputState
|
|
549
|
+
/** Parsed `TOOL_CALL_END` input. Spec `TOOL_CALL_END` has no top-level `input`. */
|
|
550
|
+
input?: unknown
|
|
551
|
+
}
|
|
552
|
+
|
|
513
553
|
/**
|
|
514
554
|
* UIMessage - Domain-specific message format optimized for building chat UIs
|
|
515
555
|
* Contains parts that can be text, tool calls, or tool results. Generic over
|
|
@@ -522,6 +562,11 @@ export interface UIMessage<TData = unknown> {
|
|
|
522
562
|
role: 'system' | 'user' | 'assistant'
|
|
523
563
|
parts: Array<MessagePart<TData>>
|
|
524
564
|
createdAt?: Date
|
|
565
|
+
/**
|
|
566
|
+
* Optional AG-UI metadata bag. TanStack writes the `tanstack` key.
|
|
567
|
+
* User keys stay at the top.
|
|
568
|
+
*/
|
|
569
|
+
metadata?: Record<string, any>
|
|
525
570
|
}
|
|
526
571
|
|
|
527
572
|
export type InputModalitiesTypes = {
|
|
@@ -1084,14 +1129,12 @@ export type StreamChunkType = AGUIEventType
|
|
|
1084
1129
|
|
|
1085
1130
|
/**
|
|
1086
1131
|
* Base structure for AG-UI events.
|
|
1087
|
-
* Extends @ag-ui/core BaseEvent
|
|
1132
|
+
* Extends @ag-ui/core BaseEvent. TanStack extras ride in `metadata`.
|
|
1088
1133
|
*
|
|
1089
1134
|
* @ag-ui/core provides: `type`, `timestamp?`, `rawEvent?`
|
|
1090
|
-
* TanStack AI adds: `model?`
|
|
1091
1135
|
*/
|
|
1092
1136
|
export interface BaseAGUIEvent extends AGUIBaseEvent {
|
|
1093
|
-
|
|
1094
|
-
model?: string
|
|
1137
|
+
metadata?: Record<string, any>
|
|
1095
1138
|
}
|
|
1096
1139
|
|
|
1097
1140
|
// ============================================================================
|
|
@@ -1103,12 +1146,8 @@ export interface BaseAGUIEvent extends AGUIBaseEvent {
|
|
|
1103
1146
|
* This is the first event in any streaming response.
|
|
1104
1147
|
*
|
|
1105
1148
|
* @ag-ui/core provides: `threadId`, `runId`, `parentRunId?`, `input?`
|
|
1106
|
-
* TanStack AI adds: `model?`
|
|
1107
1149
|
*/
|
|
1108
|
-
export interface RunStartedEvent extends AGUIRunStartedEvent {
|
|
1109
|
-
/** Model identifier for multi-model support */
|
|
1110
|
-
model?: string
|
|
1111
|
-
}
|
|
1150
|
+
export interface RunStartedEvent extends AGUIRunStartedEvent {}
|
|
1112
1151
|
|
|
1113
1152
|
// Re-export the canonical usage types (defined in `@tanstack/ai-event-client`)
|
|
1114
1153
|
// so `@tanstack/ai` consumers keep importing them from here unchanged.
|
|
@@ -1141,223 +1180,132 @@ export type RunAgentResumeItem = AGUIResumeEntry & {
|
|
|
1141
1180
|
/**
|
|
1142
1181
|
* Emitted when a run completes successfully.
|
|
1143
1182
|
*
|
|
1144
|
-
* @ag-ui/core provides: `threadId`, `runId`, `result?`
|
|
1145
|
-
*
|
|
1183
|
+
* @ag-ui/core provides: `threadId`, `runId`, `result?`, `outcome?`
|
|
1184
|
+
* Spec `usage[]` is provider/model token counts. TanStack leftovers live in
|
|
1185
|
+
* `metadata.tanstack`.
|
|
1146
1186
|
*/
|
|
1147
|
-
export interface RunFinishedEvent extends
|
|
1148
|
-
|
|
1187
|
+
export interface RunFinishedEvent extends Pick<
|
|
1188
|
+
AGUIRunFinishedEvent,
|
|
1189
|
+
'threadId' | 'runId' | 'result' | 'outcome' | 'timestamp' | 'rawEvent'
|
|
1190
|
+
> {
|
|
1191
|
+
type: EventType.RUN_FINISHED
|
|
1192
|
+
usage?: Array<SpecTokenUsage> | TokenUsage
|
|
1193
|
+
/** Restored on the client from `metadata.tanstack`. */
|
|
1149
1194
|
model?: string
|
|
1150
|
-
/**
|
|
1195
|
+
/** Restored on the client from `metadata.tanstack`. */
|
|
1151
1196
|
finishReason?: 'stop' | 'length' | 'content_filter' | 'tool_calls' | null
|
|
1152
|
-
|
|
1153
|
-
usage?: TokenUsage
|
|
1197
|
+
metadata?: { tanstack?: TanStackRunMetadata } & Record<string, any>
|
|
1154
1198
|
}
|
|
1155
1199
|
|
|
1156
1200
|
/**
|
|
1157
1201
|
* Emitted when an error occurs during a run.
|
|
1158
1202
|
*
|
|
1159
1203
|
* @ag-ui/core provides: `message`, `code?`
|
|
1160
|
-
*
|
|
1204
|
+
* Spec `usage[]` is provider/model token counts. Interrupt errors live in
|
|
1205
|
+
* `metadata.tanstack.interruptErrors`.
|
|
1161
1206
|
*/
|
|
1162
|
-
export interface RunErrorEvent extends
|
|
1163
|
-
|
|
1207
|
+
export interface RunErrorEvent extends Pick<
|
|
1208
|
+
AGUIRunErrorEvent,
|
|
1209
|
+
'message' | 'code' | 'timestamp' | 'rawEvent'
|
|
1210
|
+
> {
|
|
1211
|
+
type: EventType.RUN_ERROR
|
|
1212
|
+
usage?: Array<SpecTokenUsage> | TokenUsage
|
|
1213
|
+
/** Restored on the client from `metadata.tanstack`. */
|
|
1214
|
+
threadId?: string
|
|
1215
|
+
/** Restored on the client from `metadata.tanstack`. */
|
|
1216
|
+
runId?: string
|
|
1217
|
+
/** Restored on the client from `metadata.tanstack`. */
|
|
1164
1218
|
model?: string
|
|
1165
|
-
/**
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
* @deprecated Use top-level `message` and `code` fields instead.
|
|
1169
|
-
* Kept for backward compatibility.
|
|
1170
|
-
*/
|
|
1171
|
-
error?:
|
|
1172
|
-
| {
|
|
1173
|
-
message: string
|
|
1174
|
-
code?: string | undefined
|
|
1175
|
-
}
|
|
1176
|
-
| undefined
|
|
1219
|
+
/** Nested payload kept for in-process / durability consumers. */
|
|
1220
|
+
error?: { message: string; code?: string }
|
|
1221
|
+
metadata?: { tanstack?: TanStackRunMetadata } & Record<string, any>
|
|
1177
1222
|
}
|
|
1178
1223
|
|
|
1179
1224
|
/**
|
|
1180
1225
|
* Emitted when a text message starts.
|
|
1181
1226
|
*
|
|
1182
1227
|
* @ag-ui/core provides: `messageId`, `role?`, `name?`
|
|
1183
|
-
* TanStack AI adds: `model?`
|
|
1184
1228
|
*/
|
|
1185
|
-
export interface TextMessageStartEvent extends AGUITextMessageStartEvent {
|
|
1186
|
-
/** Model identifier for multi-model support */
|
|
1187
|
-
model?: string
|
|
1188
|
-
}
|
|
1229
|
+
export interface TextMessageStartEvent extends AGUITextMessageStartEvent {}
|
|
1189
1230
|
|
|
1190
1231
|
/**
|
|
1191
1232
|
* Emitted when text content is generated (streaming tokens).
|
|
1192
1233
|
*
|
|
1193
1234
|
* @ag-ui/core provides: `messageId`, `delta`
|
|
1194
|
-
* TanStack AI adds: `model?`, `content?` (accumulated)
|
|
1195
1235
|
*/
|
|
1196
|
-
export interface TextMessageContentEvent extends AGUITextMessageContentEvent {
|
|
1197
|
-
/** Model identifier for multi-model support */
|
|
1198
|
-
model?: string
|
|
1199
|
-
/** Full accumulated content so far (TanStack AI internal, for debugging) */
|
|
1200
|
-
content?: string
|
|
1201
|
-
}
|
|
1236
|
+
export interface TextMessageContentEvent extends AGUITextMessageContentEvent {}
|
|
1202
1237
|
|
|
1203
1238
|
/**
|
|
1204
1239
|
* Emitted when a text message completes.
|
|
1205
1240
|
*
|
|
1206
1241
|
* @ag-ui/core provides: `messageId`
|
|
1207
|
-
* TanStack AI adds: `model?`
|
|
1208
1242
|
*/
|
|
1209
|
-
export interface TextMessageEndEvent extends AGUITextMessageEndEvent {
|
|
1210
|
-
/** Model identifier for multi-model support */
|
|
1211
|
-
model?: string
|
|
1212
|
-
}
|
|
1243
|
+
export interface TextMessageEndEvent extends AGUITextMessageEndEvent {}
|
|
1213
1244
|
|
|
1214
1245
|
/**
|
|
1215
1246
|
* Emitted when a tool call starts.
|
|
1216
1247
|
*
|
|
1217
1248
|
* @ag-ui/core provides: `toolCallId`, `toolCallName`, `parentMessageId?`
|
|
1218
|
-
* TanStack AI adds: `model?`, `toolName` (deprecated alias), `index?`, `metadata?`
|
|
1219
1249
|
*
|
|
1220
1250
|
* Field shapes are taken from AG-UI via `Pick` (not `extends`) so Zod
|
|
1221
1251
|
* `.passthrough()` index signatures do not pollute the StreamChunk
|
|
1222
|
-
* discriminated union — required for {@link
|
|
1223
|
-
*
|
|
1224
|
-
* @typeParam TToolName - Constrained tool name type. Defaults to `string` (untyped).
|
|
1225
|
-
* When the stream is returned from `chat()` with typed tools, `TypedStreamChunk`
|
|
1226
|
-
* intersects a literal onto `toolCallName` and `toolName` for discrimination.
|
|
1252
|
+
* discriminated union — required for {@link KnownCustomEvent} narrowing.
|
|
1227
1253
|
*/
|
|
1228
|
-
export interface ToolCallStartEvent<
|
|
1229
|
-
TToolName extends string = string,
|
|
1230
|
-
> extends Pick<
|
|
1254
|
+
export interface ToolCallStartEvent extends Pick<
|
|
1231
1255
|
AGUIToolCallStartEvent,
|
|
1232
1256
|
'toolCallId' | 'toolCallName' | 'parentMessageId' | 'timestamp' | 'rawEvent'
|
|
1233
1257
|
> {
|
|
1234
1258
|
type: 'TOOL_CALL_START'
|
|
1235
|
-
/**
|
|
1236
|
-
|
|
1237
|
-
/**
|
|
1238
|
-
|
|
1239
|
-
* Kept for backward compatibility.
|
|
1240
|
-
*
|
|
1241
|
-
* Carries `TToolName` on the base interface; for `toolCallName` narrowing use
|
|
1242
|
-
* {@link TypedStreamChunk} (distributed variants intersect the AG-UI field).
|
|
1243
|
-
*/
|
|
1244
|
-
toolName: TToolName
|
|
1245
|
-
/** Index for parallel tool calls */
|
|
1246
|
-
index?: number
|
|
1247
|
-
/** Provider-specific metadata to carry into the ToolCall.
|
|
1248
|
-
* Untyped at the event layer because events flow through a discriminated
|
|
1249
|
-
* union that does not survive generics; adapters cast it to their typed
|
|
1250
|
-
* `TToolCallMetadata` shape when emitting. */
|
|
1251
|
-
metadata?: Record<string, unknown>
|
|
1259
|
+
/** Alias of `toolCallName`. Kept so existing stream readers still compile. */
|
|
1260
|
+
toolName?: string
|
|
1261
|
+
/** Provider-specific metadata to carry into the ToolCall. */
|
|
1262
|
+
metadata?: Record<string, any>
|
|
1252
1263
|
}
|
|
1253
1264
|
|
|
1254
1265
|
/**
|
|
1255
1266
|
* Emitted when tool call arguments are streaming.
|
|
1256
1267
|
*
|
|
1257
1268
|
* @ag-ui/core provides: `toolCallId`, `delta`
|
|
1258
|
-
* TanStack AI adds: `model?`, `args?` (accumulated)
|
|
1259
1269
|
*/
|
|
1260
|
-
export interface ToolCallArgsEvent extends AGUIToolCallArgsEvent {
|
|
1261
|
-
/** Model identifier for multi-model support */
|
|
1262
|
-
model?: string
|
|
1263
|
-
/** Full accumulated arguments so far (TanStack AI internal) */
|
|
1264
|
-
args?: string
|
|
1265
|
-
}
|
|
1270
|
+
export interface ToolCallArgsEvent extends AGUIToolCallArgsEvent {}
|
|
1266
1271
|
|
|
1267
1272
|
/**
|
|
1268
1273
|
* Emitted when a tool call completes.
|
|
1269
1274
|
*
|
|
1270
1275
|
* @ag-ui/core provides: `toolCallId`
|
|
1271
|
-
* TanStack AI adds: `model?`, `toolCallName?`, `toolName?` (deprecated), `input?`, `output?`, `result?`
|
|
1272
1276
|
*
|
|
1273
1277
|
* Same `Pick` (not `extends`) rationale as {@link ToolCallStartEvent}.
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
export interface ToolCallEndEvent<
|
|
1280
|
-
TToolName extends string = string,
|
|
1281
|
-
TInput = unknown,
|
|
1282
|
-
TOutput = unknown,
|
|
1283
|
-
> extends Pick<AGUIToolCallEndEvent, 'toolCallId' | 'timestamp' | 'rawEvent'> {
|
|
1278
|
+
*/
|
|
1279
|
+
export interface ToolCallEndEvent extends Pick<
|
|
1280
|
+
AGUIToolCallEndEvent,
|
|
1281
|
+
'toolCallId' | 'timestamp' | 'rawEvent'
|
|
1282
|
+
> {
|
|
1284
1283
|
type: 'TOOL_CALL_END'
|
|
1285
|
-
/**
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
toolCallName?: TToolName
|
|
1289
|
-
/**
|
|
1290
|
-
* @deprecated Use `toolCallName` instead.
|
|
1291
|
-
* Kept for backward compatibility.
|
|
1292
|
-
*/
|
|
1293
|
-
toolName?: TToolName
|
|
1294
|
-
/** Final parsed input arguments (TanStack AI internal) */
|
|
1295
|
-
input?: TInput
|
|
1296
|
-
/**
|
|
1297
|
-
* Tool execution output, validated against the tool's `outputSchema` when
|
|
1298
|
-
* one is declared. Prefer this over parsing `result` when present.
|
|
1299
|
-
* Undefined for tools without execute, client tools pending approval, or
|
|
1300
|
-
* when execution throws.
|
|
1301
|
-
*/
|
|
1302
|
-
output?: TOutput
|
|
1303
|
-
/** Tool execution result (TanStack AI internal / wire form) */
|
|
1304
|
-
result?: string | Array<ContentPart>
|
|
1305
|
-
/** Tool execution output state (TanStack AI internal) */
|
|
1306
|
-
state?: ToolOutputState
|
|
1284
|
+
/** Parsed tool arguments when the adapter already parsed them. */
|
|
1285
|
+
input?: unknown
|
|
1286
|
+
metadata?: Record<string, any>
|
|
1307
1287
|
}
|
|
1308
1288
|
|
|
1309
1289
|
/**
|
|
1310
1290
|
* Emitted when a tool call result is available.
|
|
1311
1291
|
*
|
|
1312
1292
|
* @ag-ui/core provides: `messageId`, `toolCallId`, `content`, `role?`
|
|
1313
|
-
* TanStack AI adds: `model?`
|
|
1314
1293
|
*/
|
|
1315
|
-
export interface ToolCallResultEvent extends AGUIToolCallResultEvent {
|
|
1316
|
-
/** Model identifier for multi-model support */
|
|
1317
|
-
model?: string
|
|
1318
|
-
/** Tool execution output state (TanStack AI internal) */
|
|
1319
|
-
state?: ToolOutputState
|
|
1320
|
-
}
|
|
1294
|
+
export interface ToolCallResultEvent extends AGUIToolCallResultEvent {}
|
|
1321
1295
|
|
|
1322
1296
|
/**
|
|
1323
1297
|
* Emitted when a thinking/reasoning step starts.
|
|
1324
1298
|
*
|
|
1325
1299
|
* @ag-ui/core provides: `stepName`
|
|
1326
|
-
* TanStack AI adds: `model?`, `stepId?` (deprecated alias), `stepType?`
|
|
1327
1300
|
*/
|
|
1328
|
-
export interface StepStartedEvent extends AGUIStepStartedEvent {
|
|
1329
|
-
/** Model identifier for multi-model support */
|
|
1330
|
-
model?: string
|
|
1331
|
-
/**
|
|
1332
|
-
* @deprecated Use `stepName` instead (from @ag-ui/core spec).
|
|
1333
|
-
* Kept for backward compatibility.
|
|
1334
|
-
*/
|
|
1335
|
-
stepId?: string
|
|
1336
|
-
/** Type of step (e.g., 'thinking', 'planning') */
|
|
1337
|
-
stepType?: string
|
|
1338
|
-
}
|
|
1301
|
+
export interface StepStartedEvent extends AGUIStepStartedEvent {}
|
|
1339
1302
|
|
|
1340
1303
|
/**
|
|
1341
1304
|
* Emitted when a thinking/reasoning step finishes.
|
|
1342
1305
|
*
|
|
1343
1306
|
* @ag-ui/core provides: `stepName`
|
|
1344
|
-
* TanStack AI adds: `model?`, `stepId?` (deprecated alias), `delta?`, `content?`
|
|
1345
1307
|
*/
|
|
1346
|
-
export interface StepFinishedEvent extends AGUIStepFinishedEvent {
|
|
1347
|
-
/** Model identifier for multi-model support */
|
|
1348
|
-
model?: string
|
|
1349
|
-
/**
|
|
1350
|
-
* @deprecated Use `stepName` instead (from @ag-ui/core spec).
|
|
1351
|
-
* Kept for backward compatibility.
|
|
1352
|
-
*/
|
|
1353
|
-
stepId?: string
|
|
1354
|
-
/** Incremental thinking content (TanStack AI internal) */
|
|
1355
|
-
delta?: string
|
|
1356
|
-
/** Full accumulated thinking content (TanStack AI internal) */
|
|
1357
|
-
content?: string
|
|
1358
|
-
/** Provider signature for the thinking block */
|
|
1359
|
-
signature?: string
|
|
1360
|
-
}
|
|
1308
|
+
export interface StepFinishedEvent extends AGUIStepFinishedEvent {}
|
|
1361
1309
|
|
|
1362
1310
|
/**
|
|
1363
1311
|
* Emitted to provide a snapshot of all messages in a conversation.
|
|
@@ -1366,68 +1314,40 @@ export interface StepFinishedEvent extends AGUIStepFinishedEvent {
|
|
|
1366
1314
|
* MessagesSnapshot specifically delivers the conversation transcript.
|
|
1367
1315
|
*
|
|
1368
1316
|
* @ag-ui/core provides: `messages` (as @ag-ui/core Message[])
|
|
1369
|
-
* TanStack AI adds: `model?`
|
|
1370
1317
|
*
|
|
1371
1318
|
* Note: The `messages` field uses the @ag-ui/core Message type.
|
|
1372
1319
|
* Use converters to transform to/from TanStack UIMessage format.
|
|
1373
1320
|
*/
|
|
1374
|
-
export interface MessagesSnapshotEvent extends AGUIMessagesSnapshotEvent {
|
|
1375
|
-
/** Model identifier for multi-model support */
|
|
1376
|
-
model?: string
|
|
1377
|
-
}
|
|
1321
|
+
export interface MessagesSnapshotEvent extends AGUIMessagesSnapshotEvent {}
|
|
1378
1322
|
|
|
1379
1323
|
/**
|
|
1380
1324
|
* Emitted to provide a full state snapshot.
|
|
1381
1325
|
*
|
|
1382
1326
|
* @ag-ui/core provides: `snapshot` (any)
|
|
1383
|
-
* TanStack AI adds: `model?`, `state?` (deprecated alias for snapshot)
|
|
1384
1327
|
*/
|
|
1385
|
-
export interface StateSnapshotEvent extends AGUIStateSnapshotEvent {
|
|
1386
|
-
/** Model identifier for multi-model support */
|
|
1387
|
-
model?: string
|
|
1388
|
-
/**
|
|
1389
|
-
* @deprecated Use `snapshot` instead (from @ag-ui/core spec).
|
|
1390
|
-
* Kept for backward compatibility.
|
|
1391
|
-
*/
|
|
1392
|
-
state?: Record<string, unknown>
|
|
1393
|
-
}
|
|
1328
|
+
export interface StateSnapshotEvent extends AGUIStateSnapshotEvent {}
|
|
1394
1329
|
|
|
1395
1330
|
/**
|
|
1396
1331
|
* Emitted to provide an incremental state update.
|
|
1397
1332
|
*
|
|
1398
1333
|
* @ag-ui/core provides: `delta` (any[] - JSON Patch RFC 6902)
|
|
1399
|
-
* TanStack AI adds: `model?`
|
|
1400
1334
|
*/
|
|
1401
|
-
export interface StateDeltaEvent extends AGUIStateDeltaEvent {
|
|
1402
|
-
/** Model identifier for multi-model support */
|
|
1403
|
-
model?: string
|
|
1404
|
-
}
|
|
1335
|
+
export interface StateDeltaEvent extends AGUIStateDeltaEvent {}
|
|
1405
1336
|
|
|
1406
1337
|
/**
|
|
1407
1338
|
* Custom event for extensibility.
|
|
1408
1339
|
*
|
|
1409
1340
|
* @ag-ui/core provides: `name`, `value`
|
|
1410
|
-
* TanStack AI adds: `model?`
|
|
1411
1341
|
*
|
|
1412
1342
|
* Uses `Pick` (not `extends`) so the Zod passthrough index signature does not
|
|
1413
|
-
* erase discriminant property access on {@link KnownCustomEvent}
|
|
1414
|
-
* {@link TypedStreamChunk} unions.
|
|
1343
|
+
* erase discriminant property access on {@link KnownCustomEvent} unions.
|
|
1415
1344
|
*/
|
|
1416
1345
|
export interface CustomEvent extends Pick<
|
|
1417
1346
|
AGUICustomEvent,
|
|
1418
1347
|
'name' | 'value' | 'timestamp' | 'rawEvent'
|
|
1419
1348
|
> {
|
|
1420
1349
|
type: 'CUSTOM'
|
|
1421
|
-
|
|
1422
|
-
model?: string
|
|
1423
|
-
/**
|
|
1424
|
-
* Routing metadata the TanStack engine attaches when emitting CUSTOM
|
|
1425
|
-
* events that need to be correlated with a specific thread/run.
|
|
1426
|
-
* Stripped by `strip-to-spec-middleware` before going on the wire so
|
|
1427
|
-
* the AG-UI consumer never sees them (when that middleware is enabled).
|
|
1428
|
-
*/
|
|
1429
|
-
threadId?: string
|
|
1430
|
-
runId?: string
|
|
1350
|
+
metadata?: Record<string, any>
|
|
1431
1351
|
}
|
|
1432
1352
|
|
|
1433
1353
|
/**
|
|
@@ -1673,67 +1593,43 @@ export type StructuredOutputStream<T = unknown> = AsyncIterable<
|
|
|
1673
1593
|
* Emitted when reasoning starts for a message.
|
|
1674
1594
|
*
|
|
1675
1595
|
* @ag-ui/core provides: `messageId`
|
|
1676
|
-
* TanStack AI adds: `model?`
|
|
1677
1596
|
*/
|
|
1678
|
-
export interface ReasoningStartEvent extends AGUIReasoningStartEvent {
|
|
1679
|
-
/** Model identifier for multi-model support */
|
|
1680
|
-
model?: string
|
|
1681
|
-
}
|
|
1597
|
+
export interface ReasoningStartEvent extends AGUIReasoningStartEvent {}
|
|
1682
1598
|
|
|
1683
1599
|
/**
|
|
1684
1600
|
* Emitted when a reasoning message starts.
|
|
1685
1601
|
*
|
|
1686
1602
|
* @ag-ui/core provides: `messageId`, `role` ("reasoning")
|
|
1687
|
-
* TanStack AI adds: `model?`
|
|
1688
1603
|
*/
|
|
1689
|
-
export interface ReasoningMessageStartEvent extends AGUIReasoningMessageStartEvent {
|
|
1690
|
-
/** Model identifier for multi-model support */
|
|
1691
|
-
model?: string
|
|
1692
|
-
}
|
|
1604
|
+
export interface ReasoningMessageStartEvent extends AGUIReasoningMessageStartEvent {}
|
|
1693
1605
|
|
|
1694
1606
|
/**
|
|
1695
1607
|
* Emitted when reasoning message content is generated.
|
|
1696
1608
|
*
|
|
1697
1609
|
* @ag-ui/core provides: `messageId`, `delta`
|
|
1698
|
-
* TanStack AI adds: `model?`
|
|
1699
1610
|
*/
|
|
1700
|
-
export interface ReasoningMessageContentEvent extends AGUIReasoningMessageContentEvent {
|
|
1701
|
-
/** Model identifier for multi-model support */
|
|
1702
|
-
model?: string
|
|
1703
|
-
}
|
|
1611
|
+
export interface ReasoningMessageContentEvent extends AGUIReasoningMessageContentEvent {}
|
|
1704
1612
|
|
|
1705
1613
|
/**
|
|
1706
1614
|
* Emitted when a reasoning message ends.
|
|
1707
1615
|
*
|
|
1708
1616
|
* @ag-ui/core provides: `messageId`
|
|
1709
|
-
* TanStack AI adds: `model?`
|
|
1710
1617
|
*/
|
|
1711
|
-
export interface ReasoningMessageEndEvent extends AGUIReasoningMessageEndEvent {
|
|
1712
|
-
/** Model identifier for multi-model support */
|
|
1713
|
-
model?: string
|
|
1714
|
-
}
|
|
1618
|
+
export interface ReasoningMessageEndEvent extends AGUIReasoningMessageEndEvent {}
|
|
1715
1619
|
|
|
1716
1620
|
/**
|
|
1717
1621
|
* Emitted when reasoning ends for a message.
|
|
1718
1622
|
*
|
|
1719
1623
|
* @ag-ui/core provides: `messageId`
|
|
1720
|
-
* TanStack AI adds: `model?`
|
|
1721
1624
|
*/
|
|
1722
|
-
export interface ReasoningEndEvent extends AGUIReasoningEndEvent {
|
|
1723
|
-
/** Model identifier for multi-model support */
|
|
1724
|
-
model?: string
|
|
1725
|
-
}
|
|
1625
|
+
export interface ReasoningEndEvent extends AGUIReasoningEndEvent {}
|
|
1726
1626
|
|
|
1727
1627
|
/**
|
|
1728
1628
|
* Emitted for encrypted reasoning values.
|
|
1729
1629
|
*
|
|
1730
1630
|
* @ag-ui/core provides: `subtype`, `entityId`, `encryptedValue`
|
|
1731
|
-
* TanStack AI adds: `model?`
|
|
1732
1631
|
*/
|
|
1733
|
-
export interface ReasoningEncryptedValueEvent extends AGUIReasoningEncryptedValueEvent {
|
|
1734
|
-
/** Model identifier for multi-model support */
|
|
1735
|
-
model?: string
|
|
1736
|
-
}
|
|
1632
|
+
export interface ReasoningEncryptedValueEvent extends AGUIReasoningEncryptedValueEvent {}
|
|
1737
1633
|
|
|
1738
1634
|
// ============================================================================
|
|
1739
1635
|
// AG-UI Event Union
|
|
@@ -1772,140 +1668,6 @@ export type AGUIEvent =
|
|
|
1772
1668
|
*/
|
|
1773
1669
|
export type StreamChunk = AGUIEvent
|
|
1774
1670
|
|
|
1775
|
-
// ============================================================================
|
|
1776
|
-
// Typed Stream Chunks (tool-aware)
|
|
1777
|
-
// ============================================================================
|
|
1778
|
-
|
|
1779
|
-
/**
|
|
1780
|
-
* Detect the `any` type. Returns `true` for `any`, `false` for everything else.
|
|
1781
|
-
* @internal
|
|
1782
|
-
*/
|
|
1783
|
-
type IsAny<T> = 0 extends 1 & T ? true : false
|
|
1784
|
-
|
|
1785
|
-
/**
|
|
1786
|
-
* Partition out provider-specific tools from a tools array. `ProviderTool`
|
|
1787
|
-
* carries opaque provider metadata (e.g. `webSearchTool` from
|
|
1788
|
-
* `@tanstack/ai-anthropic`) and intentionally has a generic `string` name —
|
|
1789
|
-
* if we included it in the discriminated union, it would widen `toolName`
|
|
1790
|
-
* back to `string` and defeat the entire typing exercise.
|
|
1791
|
-
*
|
|
1792
|
-
* @internal
|
|
1793
|
-
*/
|
|
1794
|
-
type NonProviderTools<TTools extends ReadonlyArray<AnyTool>> = Exclude<
|
|
1795
|
-
TTools[number],
|
|
1796
|
-
ProviderTool<string, string>
|
|
1797
|
-
>
|
|
1798
|
-
|
|
1799
|
-
/**
|
|
1800
|
-
* Check whether the tools array carries typed tool definitions.
|
|
1801
|
-
* Returns `false` for empty arrays or arrays whose only entries are
|
|
1802
|
-
* `ProviderTool`s (which have generic `string` names).
|
|
1803
|
-
*
|
|
1804
|
-
* The partitioning step matters: a user who passes
|
|
1805
|
-
* `[webSearchTool, myTypedTool]` should still get typed narrowing for
|
|
1806
|
-
* `myTypedTool`. Evaluating `string extends TTools[number]['name']` without
|
|
1807
|
-
* filtering provider tools first would always return `false` (because
|
|
1808
|
-
* `ProviderTool`'s `name` is `string`) and silently fall through to the
|
|
1809
|
-
* untyped branch.
|
|
1810
|
-
*
|
|
1811
|
-
* @internal
|
|
1812
|
-
*/
|
|
1813
|
-
type HasTypedTools<TTools extends ReadonlyArray<AnyTool>> = [
|
|
1814
|
-
NonProviderTools<TTools>,
|
|
1815
|
-
] extends [never]
|
|
1816
|
-
? false
|
|
1817
|
-
: string extends NonProviderTools<TTools>['name']
|
|
1818
|
-
? false
|
|
1819
|
-
: true
|
|
1820
|
-
|
|
1821
|
-
/**
|
|
1822
|
-
* Safely infer input type for a single tool, guarding against `any` leaks.
|
|
1823
|
-
* Returns `unknown` when the tool has no inputSchema, when the schema
|
|
1824
|
-
* parameter defaults to `undefined` (no-schema tool definitions), or when
|
|
1825
|
-
* InferSchemaType produces `any` (e.g. for plain JSON Schema tools).
|
|
1826
|
-
* @internal
|
|
1827
|
-
*/
|
|
1828
|
-
type SafeToolInput<T> = T extends {
|
|
1829
|
-
inputSchema?: infer TInput
|
|
1830
|
-
}
|
|
1831
|
-
? [TInput] extends [undefined]
|
|
1832
|
-
? unknown
|
|
1833
|
-
: IsAny<InferSchemaType<NonNullable<TInput>>> extends true
|
|
1834
|
-
? unknown
|
|
1835
|
-
: InferSchemaType<NonNullable<TInput>>
|
|
1836
|
-
: unknown
|
|
1837
|
-
|
|
1838
|
-
/**
|
|
1839
|
-
* Safely infer output type for a single tool. Mirrors `SafeToolInput`,
|
|
1840
|
-
* picking `outputSchema` instead. Returns `unknown` when the tool has no
|
|
1841
|
-
* `outputSchema` declared, when the schema parameter defaults to `undefined`,
|
|
1842
|
-
* or when `InferSchemaType` produces `any`.
|
|
1843
|
-
* @internal
|
|
1844
|
-
*/
|
|
1845
|
-
type SafeToolOutput<T> = T extends {
|
|
1846
|
-
outputSchema?: infer TOutput
|
|
1847
|
-
}
|
|
1848
|
-
? [TOutput] extends [undefined]
|
|
1849
|
-
? unknown
|
|
1850
|
-
: IsAny<InferSchemaType<NonNullable<TOutput>>> extends true
|
|
1851
|
-
? unknown
|
|
1852
|
-
: InferSchemaType<NonNullable<TOutput>>
|
|
1853
|
-
: unknown
|
|
1854
|
-
|
|
1855
|
-
/**
|
|
1856
|
-
* Distribute over each non-provider tool to create a per-tool
|
|
1857
|
-
* `ToolCallStartEvent`.
|
|
1858
|
-
*
|
|
1859
|
-
* This produces a discriminated union — one variant per tool name literal.
|
|
1860
|
-
* We distribute over `NonProviderTools<TTools>` (not `TTools[number]`) so
|
|
1861
|
-
* that provider tools with generic `string` names do not leak into the
|
|
1862
|
-
* union and widen `toolCallName` / `toolName` back to `string`.
|
|
1863
|
-
*
|
|
1864
|
-
* The trailing `& { toolCallName: TName; toolName: TName }` intersection
|
|
1865
|
-
* narrows the base `AGUIToolCallStartEvent['toolCallName']` (declared as
|
|
1866
|
-
* `string`) to the literal name — TypeScript intersects `string & TName`
|
|
1867
|
-
* down to `TName` for literal `TName`.
|
|
1868
|
-
*
|
|
1869
|
-
* The `name` parameter constraint on the inner `extends` picks up any
|
|
1870
|
-
* tool-like shape — including `ServerTool`, `ClientTool`, and the bare
|
|
1871
|
-
* `Tool` definition — because all three expose `name: TName`.
|
|
1872
|
-
* @internal
|
|
1873
|
-
*/
|
|
1874
|
-
type DistributedToolCallStart<TTools extends ReadonlyArray<AnyTool>> =
|
|
1875
|
-
NonProviderTools<TTools> extends infer T
|
|
1876
|
-
? T extends { name: infer TName extends string }
|
|
1877
|
-
? ToolCallStartEvent<TName> & { toolCallName: TName; toolName: TName }
|
|
1878
|
-
: never
|
|
1879
|
-
: never
|
|
1880
|
-
|
|
1881
|
-
/**
|
|
1882
|
-
* Distribute over each non-provider tool to create a per-tool
|
|
1883
|
-
* `ToolCallEndEvent`.
|
|
1884
|
-
*
|
|
1885
|
-
* Each variant pairs the tool's name literal with its specific input type,
|
|
1886
|
-
* enabling discriminated narrowing: checking `toolName === 'x'` narrows
|
|
1887
|
-
* `input`.
|
|
1888
|
-
*
|
|
1889
|
-
* `toolName`/`toolCallName` are intersected as required in the distributed
|
|
1890
|
-
* variants so that `Extract<..., { toolName: 'x' }>` works for consumers
|
|
1891
|
-
* relying on the discriminated-union pattern, even though the base
|
|
1892
|
-
* interface keeps them optional for compatibility with the broader AG-UI
|
|
1893
|
-
* surface.
|
|
1894
|
-
*
|
|
1895
|
-
* Distribution happens over `NonProviderTools<TTools>` for the same
|
|
1896
|
-
* reason as in `DistributedToolCallStart`.
|
|
1897
|
-
* @internal
|
|
1898
|
-
*/
|
|
1899
|
-
type DistributedToolCallEnd<TTools extends ReadonlyArray<AnyTool>> =
|
|
1900
|
-
NonProviderTools<TTools> extends infer T
|
|
1901
|
-
? T extends { name: infer TName extends string }
|
|
1902
|
-
? ToolCallEndEvent<TName, SafeToolInput<T>, SafeToolOutput<T>> & {
|
|
1903
|
-
toolCallName: TName
|
|
1904
|
-
toolName: TName
|
|
1905
|
-
}
|
|
1906
|
-
: never
|
|
1907
|
-
: never
|
|
1908
|
-
|
|
1909
1671
|
/**
|
|
1910
1672
|
* Discriminated union of the orchestrator-tagged `CUSTOM` events. Each variant
|
|
1911
1673
|
* has a literal `name`, so a single narrow on `chunk.name` yields a typed
|
|
@@ -1935,52 +1697,6 @@ export type TaggedCustomEvent<T = unknown> =
|
|
|
1935
1697
|
| ApprovalRequestedEvent
|
|
1936
1698
|
| ToolInputAvailableEvent
|
|
1937
1699
|
|
|
1938
|
-
/**
|
|
1939
|
-
* Stream chunk type parameterized by the tools array for type-safe tool call events.
|
|
1940
|
-
*
|
|
1941
|
-
* When specific tool types are provided (e.g. from `chat({ tools: [myTool] })`):
|
|
1942
|
-
* - `TOOL_CALL_START` and `TOOL_CALL_END` events form a **discriminated union**
|
|
1943
|
-
* over tool names — checking `toolName === 'x'` narrows `input` to that tool's type.
|
|
1944
|
-
* - `TOOL_CALL_END` events have `input` typed per-tool via Standard Schema inference.
|
|
1945
|
-
*
|
|
1946
|
-
* `CUSTOM` events are narrowed to the discriminated {@link KnownCustomEvent}
|
|
1947
|
-
* union (sandbox, code-mode, structured-output, approvals, UI resources, etc.).
|
|
1948
|
-
* Free-form user-emitted custom events (via `emitCustomEvent`) still flow at
|
|
1949
|
-
* runtime but are excluded from the type to avoid `any` poisoning the union;
|
|
1950
|
-
* cast to `StreamChunk` if you need to read those.
|
|
1951
|
-
*
|
|
1952
|
-
* When tools are untyped or absent, the tool-call events stay as plain
|
|
1953
|
-
* `ToolCallStartEvent` / `ToolCallEndEvent` (no per-tool name narrowing) and
|
|
1954
|
-
* the type is equivalent to the element type of {@link ChatStream}.
|
|
1955
|
-
*/
|
|
1956
|
-
/**
|
|
1957
|
-
* Replace tool-call and bare CUSTOM variants; keep every other StreamChunk
|
|
1958
|
-
* arm. Matches on the string-literal `type` discriminant that TanStack tool
|
|
1959
|
-
* events declare (see ToolCallStartEvent / ToolCallEndEvent). AG-UI events
|
|
1960
|
-
* that still use the EventType enum are kept as-is via the final branch.
|
|
1961
|
-
*
|
|
1962
|
-
* Do **not** use `Exclude<StreamChunk, { type: 'TOOL_CALL_*' }>` — under
|
|
1963
|
-
* @ag-ui/core passthrough index signatures that form removes *every* arm.
|
|
1964
|
-
* @internal
|
|
1965
|
-
*/
|
|
1966
|
-
type RemapStreamChunkForTools<
|
|
1967
|
-
TChunk,
|
|
1968
|
-
TTools extends ReadonlyArray<AnyTool>,
|
|
1969
|
-
> = TChunk extends { type: 'TOOL_CALL_START' }
|
|
1970
|
-
? DistributedToolCallStart<TTools>
|
|
1971
|
-
: TChunk extends { type: 'TOOL_CALL_END' }
|
|
1972
|
-
? DistributedToolCallEnd<TTools>
|
|
1973
|
-
: TChunk extends { type: 'CUSTOM' }
|
|
1974
|
-
? never
|
|
1975
|
-
: TChunk
|
|
1976
|
-
|
|
1977
|
-
export type TypedStreamChunk<
|
|
1978
|
-
TTools extends ReadonlyArray<AnyTool> = ReadonlyArray<AnyTool>,
|
|
1979
|
-
> =
|
|
1980
|
-
HasTypedTools<TTools> extends true
|
|
1981
|
-
? RemapStreamChunkForTools<StreamChunk, TTools> | KnownCustomEvent
|
|
1982
|
-
: Exclude<StreamChunk, CustomEvent> | KnownCustomEvent
|
|
1983
|
-
|
|
1984
1700
|
// Simple streaming format for basic text completions
|
|
1985
1701
|
// Converted to StreamChunk format by convertTextCompletionStream()
|
|
1986
1702
|
export interface TextCompletionChunk {
|