@tanstack/ai 0.58.0 → 0.61.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/dist/esm/activities/chat/adapter.d.ts +9 -0
- package/dist/esm/activities/chat/adapter.js +1 -0
- package/dist/esm/activities/chat/adapter.js.map +1 -1
- package/dist/esm/activities/chat/agents/define-agent.d.ts +81 -0
- package/dist/esm/activities/chat/agents/define-agent.js +34 -0
- package/dist/esm/activities/chat/agents/define-agent.js.map +1 -0
- package/dist/esm/activities/chat/agents/route.d.ts +53 -0
- package/dist/esm/activities/chat/agents/route.js +59 -0
- package/dist/esm/activities/chat/agents/route.js.map +1 -0
- package/dist/esm/activities/chat/agents/spawn.d.ts +124 -0
- package/dist/esm/activities/chat/agents/spawn.js +490 -0
- package/dist/esm/activities/chat/agents/spawn.js.map +1 -0
- package/dist/esm/activities/chat/agents/turn.d.ts +36 -0
- package/dist/esm/activities/chat/agents/turn.js +78 -0
- package/dist/esm/activities/chat/agents/turn.js.map +1 -0
- package/dist/esm/activities/chat/index.d.ts +13 -3
- package/dist/esm/activities/chat/index.js +462 -26
- package/dist/esm/activities/chat/index.js.map +1 -1
- package/dist/esm/activities/chat/messages.d.ts +7 -1
- package/dist/esm/activities/chat/messages.js +99 -19
- package/dist/esm/activities/chat/messages.js.map +1 -1
- package/dist/esm/activities/chat/middleware/run-store.d.ts +43 -7
- package/dist/esm/activities/chat/middleware/run-store.js +8 -1
- package/dist/esm/activities/chat/middleware/run-store.js.map +1 -1
- package/dist/esm/activities/chat/middleware/types.d.ts +47 -1
- package/dist/esm/activities/chat/middleware/types.js.map +1 -1
- package/dist/esm/activities/chat/stream/message-updaters.js +9 -2
- package/dist/esm/activities/chat/stream/message-updaters.js.map +1 -1
- package/dist/esm/activities/chat/stream/processor.d.ts +46 -1
- package/dist/esm/activities/chat/stream/processor.js +294 -18
- package/dist/esm/activities/chat/stream/processor.js.map +1 -1
- package/dist/esm/activities/chat/tools/tool-calls.d.ts +17 -3
- package/dist/esm/activities/chat/tools/tool-calls.js +56 -5
- package/dist/esm/activities/chat/tools/tool-calls.js.map +1 -1
- package/dist/esm/activities/embed/adapter.d.ts +7 -0
- package/dist/esm/activities/embed/adapter.js +1 -0
- package/dist/esm/activities/embed/adapter.js.map +1 -1
- package/dist/esm/activities/embed/index.js +2 -0
- package/dist/esm/activities/embed/index.js.map +1 -1
- package/dist/esm/activities/files/adapter.d.ts +97 -0
- package/dist/esm/activities/files/adapter.js +45 -0
- package/dist/esm/activities/files/adapter.js.map +1 -0
- package/dist/esm/activities/files/index.d.ts +66 -0
- package/dist/esm/activities/files/index.js +78 -0
- package/dist/esm/activities/files/index.js.map +1 -0
- package/dist/esm/activities/generateAudio/index.js +1 -1
- package/dist/esm/activities/generateImage/adapter.d.ts +8 -0
- package/dist/esm/activities/generateImage/adapter.js +1 -0
- package/dist/esm/activities/generateImage/adapter.js.map +1 -1
- package/dist/esm/activities/generateImage/index.js +3 -1
- package/dist/esm/activities/generateImage/index.js.map +1 -1
- package/dist/esm/activities/generateLiveVideo/index.js +1 -1
- package/dist/esm/activities/generateSpeech/index.js +1 -1
- package/dist/esm/activities/generateTranscription/index.js +1 -1
- package/dist/esm/activities/generateVideo/adapter.d.ts +8 -0
- package/dist/esm/activities/generateVideo/adapter.js +1 -0
- package/dist/esm/activities/generateVideo/adapter.js.map +1 -1
- package/dist/esm/activities/generateVideo/index.js +3 -0
- package/dist/esm/activities/generateVideo/index.js.map +1 -1
- package/dist/esm/activities/generateVoice/index.js +1 -1
- package/dist/esm/activities/generateWorld/adapter.d.ts +4 -2
- package/dist/esm/activities/generateWorld/adapter.js.map +1 -1
- package/dist/esm/activities/generateWorld/index.d.ts +4 -3
- package/dist/esm/activities/generateWorld/index.js +6 -5
- package/dist/esm/activities/generateWorld/index.js.map +1 -1
- package/dist/esm/activities/index.d.ts +9 -3
- package/dist/esm/activities/index.js +17 -13
- package/dist/esm/activities/summarize/chat-stream-summarize.d.ts +2 -0
- package/dist/esm/activities/summarize/chat-stream-summarize.js +8 -8
- package/dist/esm/activities/summarize/chat-stream-summarize.js.map +1 -1
- package/dist/esm/activities/summarize/index.js +1 -1
- package/dist/esm/client.d.ts +7 -36
- package/dist/esm/client.js +5 -37
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/index.d.ts +8 -2
- package/dist/esm/index.js +9 -4
- package/dist/esm/middlewares/content-guard.js.map +1 -1
- package/dist/esm/types.d.ts +179 -98
- package/dist/esm/utilities/adapter-yield-chunk.d.ts +5 -1
- package/dist/esm/utilities/ag-ui-usage.d.ts +9 -9
- package/dist/esm/utilities/ag-ui-usage.js +66 -3
- package/dist/esm/utilities/ag-ui-usage.js.map +1 -1
- package/dist/esm/utilities/ag-ui-wire.js +90 -13
- package/dist/esm/utilities/ag-ui-wire.js.map +1 -1
- package/dist/esm/utilities/content-source.d.ts +60 -0
- package/dist/esm/utilities/content-source.js +85 -0
- package/dist/esm/utilities/content-source.js.map +1 -0
- package/dist/esm/utilities/normalize-stream-chunk.js +7 -2
- package/dist/esm/utilities/normalize-stream-chunk.js.map +1 -1
- package/dist/esm/utilities/provider-executed.d.ts +7 -0
- package/dist/esm/utilities/provider-executed.js +10 -1
- package/dist/esm/utilities/provider-executed.js.map +1 -1
- package/dist/esm/utilities/spec-event-keys.js +13 -8
- package/dist/esm/utilities/spec-event-keys.js.map +1 -1
- package/dist/esm/utilities/subagent-wire.d.ts +36 -0
- package/dist/esm/utilities/subagent-wire.js +131 -0
- package/dist/esm/utilities/subagent-wire.js.map +1 -0
- package/dist/esm/utilities/tool-result.d.ts +12 -2
- package/dist/esm/utilities/tool-result.js +23 -3
- package/dist/esm/utilities/tool-result.js.map +1 -1
- package/package.json +3 -3
- package/skills/ai-core/adapter-configuration/SKILL.md +62 -0
- package/skills/ai-core/adapter-configuration/references/grok-adapter.md +1 -1
- package/skills/ai-core/chat-experience/SKILL.md +14 -0
- package/skills/ai-core/media-generation/SKILL.md +10 -2
- package/skills/ai-core/middleware/SKILL.md +7 -4
- package/src/activities/chat/adapter.ts +10 -0
- package/src/activities/chat/agents/define-agent.ts +121 -0
- package/src/activities/chat/agents/route.ts +115 -0
- package/src/activities/chat/agents/spawn.ts +806 -0
- package/src/activities/chat/agents/turn.ts +151 -0
- package/src/activities/chat/index.ts +734 -30
- package/src/activities/chat/messages.ts +137 -16
- package/src/activities/chat/middleware/run-store.ts +56 -7
- package/src/activities/chat/middleware/types.ts +47 -0
- package/src/activities/chat/stream/message-updaters.ts +24 -2
- package/src/activities/chat/stream/processor.ts +452 -30
- package/src/activities/chat/tools/tool-calls.ts +83 -11
- package/src/activities/embed/adapter.ts +7 -0
- package/src/activities/embed/index.ts +5 -0
- package/src/activities/files/adapter.ts +120 -0
- package/src/activities/files/index.ts +113 -0
- package/src/activities/generateImage/adapter.ts +8 -0
- package/src/activities/generateImage/index.ts +4 -0
- package/src/activities/generateVideo/adapter.ts +8 -0
- package/src/activities/generateVideo/index.ts +7 -0
- package/src/activities/generateWorld/adapter.ts +4 -2
- package/src/activities/generateWorld/index.ts +7 -6
- package/src/activities/index.ts +40 -1
- package/src/activities/summarize/chat-stream-summarize.ts +22 -12
- package/src/client.ts +29 -35
- package/src/index.ts +39 -0
- package/src/middlewares/content-guard.ts +7 -5
- package/src/types.ts +226 -103
- package/src/utilities/adapter-yield-chunk.ts +10 -2
- package/src/utilities/ag-ui-usage.test.ts +38 -0
- package/src/utilities/ag-ui-usage.ts +98 -11
- package/src/utilities/ag-ui-wire.ts +134 -16
- package/src/utilities/content-source.ts +138 -0
- package/src/utilities/normalize-stream-chunk.ts +10 -2
- package/src/utilities/provider-executed.ts +13 -0
- package/src/utilities/spec-event-keys.ts +34 -7
- package/src/utilities/subagent-wire.ts +184 -0
- package/src/utilities/tool-result.ts +38 -2
package/dist/esm/types.d.ts
CHANGED
|
@@ -4,8 +4,9 @@ import { SystemPrompt } from './system-prompts.js';
|
|
|
4
4
|
import { CapabilityContext } from './activities/chat/middleware/capabilities.js';
|
|
5
5
|
import { InterruptSubmissionError } from './interrupts.js';
|
|
6
6
|
import { BilledUsage, BillingUnit, CompletionTokensDetails, PromptTokensDetails, ProviderUsageDetails, TokenUsage, UsageCostBreakdown } from '@tanstack/ai-event-client';
|
|
7
|
-
import { BaseEvent as AGUIBaseEvent, CustomEvent as AGUICustomEvent, Interrupt as AGUIInterrupt, MessagesSnapshotEvent as AGUIMessagesSnapshotEvent, ReasoningEncryptedValueEvent as AGUIReasoningEncryptedValueEvent, ReasoningEndEvent as AGUIReasoningEndEvent, ReasoningMessageContentEvent as AGUIReasoningMessageContentEvent, ReasoningMessageEndEvent as AGUIReasoningMessageEndEvent, ReasoningMessageStartEvent as AGUIReasoningMessageStartEvent, ReasoningStartEvent as AGUIReasoningStartEvent, ResumeEntry as AGUIResumeEntry, RunErrorEvent as AGUIRunErrorEvent, RunFinishedEvent as AGUIRunFinishedEvent, RunFinishedOutcome as AGUIRunFinishedOutcome, RunStartedEvent as AGUIRunStartedEvent, StateDeltaEvent as AGUIStateDeltaEvent, StateSnapshotEvent as AGUIStateSnapshotEvent, StepFinishedEvent as AGUIStepFinishedEvent, StepStartedEvent as AGUIStepStartedEvent, TextMessageContentEvent as AGUITextMessageContentEvent, TextMessageEndEvent as AGUITextMessageEndEvent, TextMessageStartEvent as AGUITextMessageStartEvent, ToolCallArgsEvent as AGUIToolCallArgsEvent, ToolCallEndEvent as AGUIToolCallEndEvent, ToolCallResultEvent as AGUIToolCallResultEvent, ToolCallStartEvent as AGUIToolCallStartEvent, EventType } from '@ag-ui/core';
|
|
7
|
+
import { ActivityDeltaEvent as AGUIActivityDeltaEvent, ActivitySnapshotEvent as AGUIActivitySnapshotEvent, AudioPart as AGUIAudioPart, BaseEvent as AGUIBaseEvent, ContentPart as AGUIContentPart, CustomEvent as AGUICustomEvent, DataSource as AGUIDataSource, DocumentPart as AGUIDocumentPart, FileSource as AGUIFileSource, ImagePart as AGUIImagePart, Interrupt as AGUIInterrupt, MessagesSnapshotEvent as AGUIMessagesSnapshotEvent, ReasoningEncryptedValueEvent as AGUIReasoningEncryptedValueEvent, ReasoningEndEvent as AGUIReasoningEndEvent, RawEvent as AGUIRawEvent, ReasoningMessageChunkEvent as AGUIReasoningMessageChunkEvent, ReasoningMessageContentEvent as AGUIReasoningMessageContentEvent, ReasoningMessageEndEvent as AGUIReasoningMessageEndEvent, ReasoningMessageStartEvent as AGUIReasoningMessageStartEvent, ReasoningStartEvent as AGUIReasoningStartEvent, ResumeEntry as AGUIResumeEntry, RunErrorEvent as AGUIRunErrorEvent, RunFinishedEvent as AGUIRunFinishedEvent, RunFinishedOutcome as AGUIRunFinishedOutcome, RunStartedEvent as AGUIRunStartedEvent, StateDeltaEvent as AGUIStateDeltaEvent, StateSnapshotEvent as AGUIStateSnapshotEvent, StepFinishedEvent as AGUIStepFinishedEvent, StepStartedEvent as AGUIStepStartedEvent, SubagentErrorEvent as AGUISubagentErrorEvent, SubagentFinishedEvent as AGUISubagentFinishedEvent, SubagentFinishedSuspendedOutcome as AGUISubagentFinishedSuspendedOutcome, SubagentInfo as AGUISubagentInfo, SubagentRunId as AGUISubagentRunId, SubagentStartedEvent as AGUISubagentStartedEvent, TextMessageChunkEvent as AGUITextMessageChunkEvent, TextMessageContentEvent as AGUITextMessageContentEvent, TextMessageEndEvent as AGUITextMessageEndEvent, TextMessageStartEvent as AGUITextMessageStartEvent, ToolCall as AGUIToolCall, ToolCallArgsEvent as AGUIToolCallArgsEvent, ToolCallChunkEvent as AGUIToolCallChunkEvent, ToolCallEndEvent as AGUIToolCallEndEvent, ToolCallResultEvent as AGUIToolCallResultEvent, ToolCallStartEvent as AGUIToolCallStartEvent, UrlSource as AGUIUrlSource, VideoPart as AGUIVideoPart, EventType } from '@ag-ui/core';
|
|
8
8
|
import { SpecTokenUsage, TokenUsageLeftover } from './utilities/ag-ui-usage.js';
|
|
9
|
+
import { SubagentWireInfo } from './utilities/subagent-wire.js';
|
|
9
10
|
export type { ProviderTool } from './tools/provider-tool.js';
|
|
10
11
|
/**
|
|
11
12
|
* Tool call states - track the lifecycle of a tool call
|
|
@@ -87,13 +88,8 @@ export type SchemaInput = StandardJSONSchemaV1<any, any> | StandardSchemaV1<any,
|
|
|
87
88
|
* JSON Schema at compile time.
|
|
88
89
|
*/
|
|
89
90
|
export type InferSchemaType<T> = T extends StandardJSONSchemaV1<infer TInput, unknown> ? TInput : T extends StandardSchemaV1<infer TInput, unknown> ? TInput : unknown;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
type: 'function';
|
|
93
|
-
function: {
|
|
94
|
-
name: string;
|
|
95
|
-
arguments: string;
|
|
96
|
-
};
|
|
91
|
+
/** AG-UI `ToolCall` with typed metadata. `function.arguments` is a JSON string. */
|
|
92
|
+
export interface ToolCall<TMetadata = unknown> extends Omit<AGUIToolCall, 'metadata'> {
|
|
97
93
|
/** Provider-specific metadata to carry through the tool call lifecycle.
|
|
98
94
|
* Typed per-adapter via `TToolCallMetadata`. For example,
|
|
99
95
|
* `@tanstack/ai-gemini` sets this to `{ thoughtSignature?: string }`. */
|
|
@@ -119,99 +115,73 @@ export interface ProviderExecutedToolMetadata {
|
|
|
119
115
|
[key: string]: unknown;
|
|
120
116
|
}
|
|
121
117
|
/**
|
|
122
|
-
* Supported input modality types for multimodal content
|
|
123
|
-
* -
|
|
124
|
-
* - 'image': Image content (base64 or URL)
|
|
125
|
-
* - 'audio': Audio content (base64 or URL)
|
|
126
|
-
* - 'video': Video content (base64 or URL)
|
|
127
|
-
* - 'document': Document content like PDFs (base64 or URL)
|
|
118
|
+
* Supported input modality types for multimodal content: the `type` of each
|
|
119
|
+
* AG-UI `ContentPart` (text, image, audio, video, document).
|
|
128
120
|
*/
|
|
129
|
-
export type Modality = '
|
|
121
|
+
export type Modality = AGUIContentPart['type'];
|
|
130
122
|
/**
|
|
131
|
-
*
|
|
132
|
-
* Requires a mimeType to ensure providers receive proper content type information.
|
|
123
|
+
* Inline base64 content. AG-UI `DataSource`: `mimeType` is required.
|
|
133
124
|
*/
|
|
134
|
-
export interface ContentPartDataSource {
|
|
135
|
-
/**
|
|
136
|
-
* Indicates this is inline data content.
|
|
137
|
-
*/
|
|
138
|
-
type: 'data';
|
|
139
|
-
/**
|
|
140
|
-
* The base64-encoded content value.
|
|
141
|
-
*/
|
|
142
|
-
value: string;
|
|
143
|
-
/**
|
|
144
|
-
* The MIME type of the content (e.g., 'image/png', 'audio/wav').
|
|
145
|
-
* Required for data sources to ensure proper handling by providers.
|
|
146
|
-
*/
|
|
147
|
-
mimeType: string;
|
|
125
|
+
export interface ContentPartDataSource extends AGUIDataSource {
|
|
148
126
|
}
|
|
149
127
|
/**
|
|
150
|
-
*
|
|
151
|
-
* mimeType is optional as it can often be inferred from the URL or response headers.
|
|
128
|
+
* URL-referenced content. AG-UI `UrlSource`: `mimeType` is optional.
|
|
152
129
|
*/
|
|
153
|
-
export interface ContentPartUrlSource {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
130
|
+
export interface ContentPartUrlSource extends AGUIUrlSource {
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* A provider-issued file handle (Files API). AG-UI `FileSource`: the handle
|
|
134
|
+
* is opaque, do not fetch or parse it.
|
|
135
|
+
*
|
|
136
|
+
* The media is uploaded once via a `files` adapter (`openaiFiles()`,
|
|
137
|
+
* `anthropicFiles()`, `geminiFiles()`, `grokFiles()`, `falFiles()`) and
|
|
138
|
+
* referenced here by the returned handle instead of re-sending base64 or a
|
|
139
|
+
* public URL on each request. Only the provider that minted a handle can
|
|
140
|
+
* resolve it. Adapters that cannot consume file handles at all are rejected
|
|
141
|
+
* by the activity-layer preflight before mapping starts.
|
|
142
|
+
*/
|
|
143
|
+
export interface ContentPartFileSource<TProvider extends string = string> extends AGUIFileSource {
|
|
162
144
|
/**
|
|
163
|
-
*
|
|
145
|
+
* The adapter name of the provider that issued the handle (`'openai'`,
|
|
146
|
+
* `'gemini'`, ...), the same id TanStack reports as the usage provider.
|
|
147
|
+
* When present, an adapter rejects a handle another provider issued.
|
|
164
148
|
*/
|
|
165
|
-
|
|
149
|
+
provider?: TProvider;
|
|
166
150
|
}
|
|
167
151
|
/**
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
* - For 'data' sources: mimeType is required
|
|
171
|
-
* - For 'url' sources: mimeType is optional
|
|
152
|
+
* Where a media part's bytes come from: inline data, a URL, or a provider
|
|
153
|
+
* file handle. Same members as AG-UI `PartSource`.
|
|
172
154
|
*/
|
|
173
|
-
export type ContentPartSource = ContentPartDataSource | ContentPartUrlSource;
|
|
155
|
+
export type ContentPartSource = ContentPartDataSource | ContentPartUrlSource | ContentPartFileSource;
|
|
174
156
|
/**
|
|
175
|
-
* Image content part for multimodal messages.
|
|
157
|
+
* Image content part for multimodal messages. AG-UI `ImagePart` with typed metadata.
|
|
176
158
|
* @template TMetadata - Provider-specific metadata type (e.g., OpenAI's detail level)
|
|
177
159
|
*/
|
|
178
|
-
export interface ImagePart<TMetadata = unknown> {
|
|
179
|
-
type: 'image';
|
|
180
|
-
/** Source of the image content */
|
|
181
|
-
source: ContentPartSource;
|
|
160
|
+
export interface ImagePart<TMetadata = unknown> extends AGUIImagePart {
|
|
182
161
|
/** Provider-specific metadata (e.g., OpenAI's detail: 'auto' | 'low' | 'high') */
|
|
183
162
|
metadata?: TMetadata;
|
|
184
163
|
}
|
|
185
164
|
/**
|
|
186
|
-
* Audio content part for multimodal messages.
|
|
165
|
+
* Audio content part for multimodal messages. AG-UI `AudioPart` with typed metadata.
|
|
187
166
|
* @template TMetadata - Provider-specific metadata type
|
|
188
167
|
*/
|
|
189
|
-
export interface AudioPart<TMetadata = unknown> {
|
|
190
|
-
type: 'audio';
|
|
191
|
-
/** Source of the audio content */
|
|
192
|
-
source: ContentPartSource;
|
|
168
|
+
export interface AudioPart<TMetadata = unknown> extends AGUIAudioPart {
|
|
193
169
|
/** Provider-specific metadata (e.g., format, sample rate) */
|
|
194
170
|
metadata?: TMetadata;
|
|
195
171
|
}
|
|
196
172
|
/**
|
|
197
|
-
* Video content part for multimodal messages.
|
|
173
|
+
* Video content part for multimodal messages. AG-UI `VideoPart` with typed metadata.
|
|
198
174
|
* @template TMetadata - Provider-specific metadata type
|
|
199
175
|
*/
|
|
200
|
-
export interface VideoPart<TMetadata = unknown> {
|
|
201
|
-
type: 'video';
|
|
202
|
-
/** Source of the video content */
|
|
203
|
-
source: ContentPartSource;
|
|
176
|
+
export interface VideoPart<TMetadata = unknown> extends AGUIVideoPart {
|
|
204
177
|
/** Provider-specific metadata (e.g., duration, resolution) */
|
|
205
178
|
metadata?: TMetadata;
|
|
206
179
|
}
|
|
207
180
|
/**
|
|
208
|
-
* Document content part for multimodal messages (e.g., PDFs).
|
|
181
|
+
* Document content part for multimodal messages (e.g., PDFs). AG-UI `DocumentPart` with typed metadata.
|
|
209
182
|
* @template TMetadata - Provider-specific metadata type (e.g., Anthropic's media_type)
|
|
210
183
|
*/
|
|
211
|
-
export interface DocumentPart<TMetadata = unknown> {
|
|
212
|
-
type: 'document';
|
|
213
|
-
/** Source of the document content */
|
|
214
|
-
source: ContentPartSource;
|
|
184
|
+
export interface DocumentPart<TMetadata = unknown> extends AGUIDocumentPart {
|
|
215
185
|
/** Provider-specific metadata (e.g., media_type for PDFs) */
|
|
216
186
|
metadata?: TMetadata;
|
|
217
187
|
}
|
|
@@ -360,6 +330,28 @@ export interface StructuredOutputPart<TData = unknown> {
|
|
|
360
330
|
/** Populated when `status === 'error'`. */
|
|
361
331
|
errorMessage?: string;
|
|
362
332
|
}
|
|
333
|
+
export type SubagentStatus = 'running' | 'finished' | 'error' | 'suspended';
|
|
334
|
+
/**
|
|
335
|
+
* One child invocation as the client sees it. AG-UI `SubagentInfo` names the
|
|
336
|
+
* child; the other AG-UI fields come from its `SUBAGENT_STARTED`,
|
|
337
|
+
* `SUBAGENT_FINISHED` and `SUBAGENT_ERROR` events. `id` is the AG-UI
|
|
338
|
+
* `subagentRunId`. `status`, `parentRunId` and `messages` are client state the
|
|
339
|
+
* spec does not model.
|
|
340
|
+
*/
|
|
341
|
+
export interface SubagentHandleData extends AGUISubagentInfo, Pick<AGUISubagentStartedEvent, 'parentSubagentRunId' | 'parentToolCallId' | 'metadata'> {
|
|
342
|
+
id: AGUISubagentRunId;
|
|
343
|
+
status: SubagentStatus;
|
|
344
|
+
/** The parent chat run that started this child. */
|
|
345
|
+
parentRunId?: string;
|
|
346
|
+
/** Interrupts this child raised, while `status` is `'suspended'`. */
|
|
347
|
+
interruptIds?: AGUISubagentFinishedSuspendedOutcome['interruptIds'];
|
|
348
|
+
messages: Array<UIMessage>;
|
|
349
|
+
error?: Pick<AGUISubagentErrorEvent, 'message' | 'code'>;
|
|
350
|
+
}
|
|
351
|
+
export interface SubagentPart {
|
|
352
|
+
type: 'subagent';
|
|
353
|
+
subagent: SubagentHandleData;
|
|
354
|
+
}
|
|
363
355
|
export interface UIResourcePart {
|
|
364
356
|
type: 'ui-resource';
|
|
365
357
|
/** The ui:// resource object in MCP-native shape — fed straight to the renderer. */
|
|
@@ -381,7 +373,7 @@ export interface UIResourcePart {
|
|
|
381
373
|
* Currently always `undefined` — nothing populates this field yet. */
|
|
382
374
|
meta?: Record<string, unknown>;
|
|
383
375
|
}
|
|
384
|
-
export type MessagePart<TData = unknown> = TextPart | ImagePart | AudioPart | VideoPart | DocumentPart | ToolCallPart | ToolResultPart | ThinkingPart | StructuredOutputPart<TData> | UIResourcePart;
|
|
376
|
+
export type MessagePart<TData = unknown> = TextPart | ImagePart | AudioPart | VideoPart | DocumentPart | ToolCallPart | ToolResultPart | ThinkingPart | StructuredOutputPart<TData> | UIResourcePart | SubagentPart;
|
|
385
377
|
/**
|
|
386
378
|
* Shape of `metadata.tanstack` on a message.
|
|
387
379
|
* `createdAt` is an ISO-8601 string.
|
|
@@ -389,6 +381,10 @@ export type MessagePart<TData = unknown> = TextPart | ImagePart | AudioPart | Vi
|
|
|
389
381
|
export interface TanStackMessageMetadata {
|
|
390
382
|
createdAt?: string;
|
|
391
383
|
model?: string;
|
|
384
|
+
/** Parent chat run that produced this assistant message. */
|
|
385
|
+
runId?: string;
|
|
386
|
+
/** Card data on a child wire message. See `uiMessagesToWire`. */
|
|
387
|
+
subagent?: SubagentWireInfo;
|
|
392
388
|
/** Thinking signature for a `role: 'reasoning'` fan-out message. */
|
|
393
389
|
signature?: string;
|
|
394
390
|
/** Per-tool-call provider metadata keyed by tool call id (e.g. Gemini thoughtSignature). */
|
|
@@ -907,6 +903,12 @@ export interface TextOptions<TProviderOptionsSuperset extends Record<string, any
|
|
|
907
903
|
* Surfaced for observability/middleware; not consumed by the LLM call.
|
|
908
904
|
*/
|
|
909
905
|
parentRunId?: string;
|
|
906
|
+
/**
|
|
907
|
+
* AG-UI subagent run id when this chat runs as a child of another run.
|
|
908
|
+
* A child `chat()` passes `ctx.subagentRunId`. Middleware reads it as
|
|
909
|
+
* `ctx.subagentRunId`. Absent on a top-level run.
|
|
910
|
+
*/
|
|
911
|
+
subagentRunId?: string;
|
|
910
912
|
/** Application state mirrored in a STATE_SNAPSHOT before an interrupt terminal. */
|
|
911
913
|
state?: unknown;
|
|
912
914
|
/**
|
|
@@ -1046,13 +1048,10 @@ export interface TextMessageEndEvent extends AGUITextMessageEndEvent {
|
|
|
1046
1048
|
/**
|
|
1047
1049
|
* Emitted when a tool call starts.
|
|
1048
1050
|
*
|
|
1049
|
-
* @ag-ui/core provides: `toolCallId`, `toolCallName`, `parentMessageId
|
|
1050
|
-
*
|
|
1051
|
-
* Field shapes are taken from AG-UI via `Pick` (not `extends`) so Zod
|
|
1052
|
-
* `.passthrough()` index signatures do not pollute the StreamChunk
|
|
1053
|
-
* discriminated union — required for {@link KnownCustomEvent} narrowing.
|
|
1051
|
+
* @ag-ui/core provides: `toolCallId`, `toolCallName`, `parentMessageId?`,
|
|
1052
|
+
* `subagentRunId?`
|
|
1054
1053
|
*/
|
|
1055
|
-
export interface ToolCallStartEvent extends
|
|
1054
|
+
export interface ToolCallStartEvent extends Omit<AGUIToolCallStartEvent, 'type'> {
|
|
1056
1055
|
type: 'TOOL_CALL_START';
|
|
1057
1056
|
/** Alias of `toolCallName`. Kept so existing stream readers still compile. */
|
|
1058
1057
|
toolName?: string;
|
|
@@ -1069,11 +1068,9 @@ export interface ToolCallArgsEvent extends AGUIToolCallArgsEvent {
|
|
|
1069
1068
|
/**
|
|
1070
1069
|
* Emitted when a tool call completes.
|
|
1071
1070
|
*
|
|
1072
|
-
* @ag-ui/core provides: `toolCallId`
|
|
1073
|
-
*
|
|
1074
|
-
* Same `Pick` (not `extends`) rationale as {@link ToolCallStartEvent}.
|
|
1071
|
+
* @ag-ui/core provides: `toolCallId`, `subagentRunId?`
|
|
1075
1072
|
*/
|
|
1076
|
-
export interface ToolCallEndEvent extends
|
|
1073
|
+
export interface ToolCallEndEvent extends Omit<AGUIToolCallEndEvent, 'type'> {
|
|
1077
1074
|
type: 'TOOL_CALL_END';
|
|
1078
1075
|
/** Parsed tool arguments when the adapter already parsed them. */
|
|
1079
1076
|
input?: unknown;
|
|
@@ -1130,12 +1127,9 @@ export interface StateDeltaEvent extends AGUIStateDeltaEvent {
|
|
|
1130
1127
|
/**
|
|
1131
1128
|
* Custom event for extensibility.
|
|
1132
1129
|
*
|
|
1133
|
-
* @ag-ui/core provides: `name`, `value`
|
|
1134
|
-
*
|
|
1135
|
-
* Uses `Pick` (not `extends`) so the Zod passthrough index signature does not
|
|
1136
|
-
* erase discriminant property access on {@link KnownCustomEvent} unions.
|
|
1130
|
+
* @ag-ui/core provides: `name`, `value`, `subagentRunId?`
|
|
1137
1131
|
*/
|
|
1138
|
-
export interface CustomEvent extends
|
|
1132
|
+
export interface CustomEvent extends Omit<AGUICustomEvent, 'type'> {
|
|
1139
1133
|
type: 'CUSTOM';
|
|
1140
1134
|
metadata?: Record<string, any>;
|
|
1141
1135
|
}
|
|
@@ -1420,10 +1414,51 @@ export interface ReasoningEndEvent extends AGUIReasoningEndEvent {
|
|
|
1420
1414
|
*/
|
|
1421
1415
|
export interface ReasoningEncryptedValueEvent extends AGUIReasoningEncryptedValueEvent {
|
|
1422
1416
|
}
|
|
1417
|
+
/** AG-UI 1.0 ActivitySnapshotEvent shape. */
|
|
1418
|
+
export interface ActivitySnapshotEvent extends AGUIActivitySnapshotEvent {
|
|
1419
|
+
}
|
|
1420
|
+
/** AG-UI 1.0 ActivityDeltaEvent shape. */
|
|
1421
|
+
export interface ActivityDeltaEvent extends AGUIActivityDeltaEvent {
|
|
1422
|
+
}
|
|
1423
|
+
/** AG-UI 1.0 RawEvent shape. */
|
|
1424
|
+
export interface RawEvent extends AGUIRawEvent {
|
|
1425
|
+
}
|
|
1426
|
+
/** AG-UI 1.0 TextMessageChunkEvent shape. */
|
|
1427
|
+
export interface TextMessageChunkEvent extends AGUITextMessageChunkEvent {
|
|
1428
|
+
}
|
|
1429
|
+
/** AG-UI 1.0 ToolCallChunkEvent shape. */
|
|
1430
|
+
export interface ToolCallChunkEvent extends AGUIToolCallChunkEvent {
|
|
1431
|
+
}
|
|
1432
|
+
/** AG-UI 1.0 ReasoningMessageChunkEvent shape. */
|
|
1433
|
+
export interface ReasoningMessageChunkEvent extends AGUIReasoningMessageChunkEvent {
|
|
1434
|
+
}
|
|
1423
1435
|
/**
|
|
1424
1436
|
* Union of all AG-UI events.
|
|
1425
1437
|
*/
|
|
1426
|
-
export type AGUIEvent = RunStartedEvent | RunFinishedEvent | RunErrorEvent | TextMessageStartEvent | TextMessageContentEvent | TextMessageEndEvent | ToolCallStartEvent | ToolCallArgsEvent | ToolCallEndEvent | ToolCallResultEvent | StepStartedEvent | StepFinishedEvent | MessagesSnapshotEvent | StateSnapshotEvent | StateDeltaEvent | CustomEvent | ReasoningStartEvent | ReasoningMessageStartEvent | ReasoningMessageContentEvent | ReasoningMessageEndEvent | ReasoningEndEvent | ReasoningEncryptedValueEvent;
|
|
1438
|
+
export type AGUIEvent = ActivitySnapshotEvent | ActivityDeltaEvent | RawEvent | TextMessageChunkEvent | ToolCallChunkEvent | ReasoningMessageChunkEvent | RunStartedEvent | RunFinishedEvent | RunErrorEvent | TextMessageStartEvent | TextMessageContentEvent | TextMessageEndEvent | ToolCallStartEvent | ToolCallArgsEvent | ToolCallEndEvent | ToolCallResultEvent | StepStartedEvent | StepFinishedEvent | MessagesSnapshotEvent | StateSnapshotEvent | StateDeltaEvent | CustomEvent | ReasoningStartEvent | ReasoningMessageStartEvent | ReasoningMessageContentEvent | ReasoningMessageEndEvent | ReasoningEndEvent | ReasoningEncryptedValueEvent | SubagentStartedEvent | SubagentFinishedEvent | SubagentErrorEvent;
|
|
1439
|
+
/**
|
|
1440
|
+
* A child agent started. The later chunks for that child carry the same
|
|
1441
|
+
* `subagentRunId`.
|
|
1442
|
+
*
|
|
1443
|
+
* @ag-ui/core provides: `subagentRunId`, `name`, `description?`,
|
|
1444
|
+
* `parentSubagentRunId?`, `parentToolCallId?`, `parentMessageId?`, `metadata?`
|
|
1445
|
+
*/
|
|
1446
|
+
export interface SubagentStartedEvent extends AGUISubagentStartedEvent {
|
|
1447
|
+
}
|
|
1448
|
+
/**
|
|
1449
|
+
* A child agent's segment of this run ended.
|
|
1450
|
+
*
|
|
1451
|
+
* @ag-ui/core provides: `subagentRunId`, `result?`, `outcome?`
|
|
1452
|
+
*/
|
|
1453
|
+
export interface SubagentFinishedEvent extends AGUISubagentFinishedEvent {
|
|
1454
|
+
}
|
|
1455
|
+
/**
|
|
1456
|
+
* A child agent failed. The parent run can continue.
|
|
1457
|
+
*
|
|
1458
|
+
* @ag-ui/core provides: `subagentRunId`, `message`, `code?`
|
|
1459
|
+
*/
|
|
1460
|
+
export interface SubagentErrorEvent extends AGUISubagentErrorEvent {
|
|
1461
|
+
}
|
|
1427
1462
|
/**
|
|
1428
1463
|
* Chunk returned by the SDK during streaming chat completions.
|
|
1429
1464
|
* Uses the AG-UI protocol event format.
|
|
@@ -1883,7 +1918,7 @@ export interface VideoUrlResult {
|
|
|
1883
1918
|
artifacts?: Array<PersistedArtifactRef>;
|
|
1884
1919
|
}
|
|
1885
1920
|
/**
|
|
1886
|
-
* Options for world generation (live
|
|
1921
|
+
* Options for world generation (live session or finished job).
|
|
1887
1922
|
*
|
|
1888
1923
|
* @experimental World generation is an experimental feature and may change.
|
|
1889
1924
|
*/
|
|
@@ -1893,8 +1928,10 @@ export interface WorldGenerationOptions<TProviderOptions extends object = object
|
|
|
1893
1928
|
/** Natural-language description of the world or scene */
|
|
1894
1929
|
prompt: string;
|
|
1895
1930
|
/**
|
|
1896
|
-
* Provider
|
|
1897
|
-
*
|
|
1931
|
+
* Provider-specific options. Live adapters (Reactor) use mint fields here.
|
|
1932
|
+
* Job adapters (World Labs) use image/video inputs, `wait`, and poll.
|
|
1933
|
+
* Reactor resolution/seed/audio are browser `sendCommand` fields, not
|
|
1934
|
+
* token-mint fields.
|
|
1898
1935
|
*/
|
|
1899
1936
|
modelOptions?: TProviderOptions;
|
|
1900
1937
|
/**
|
|
@@ -1910,28 +1947,72 @@ export interface WorldGenerationOptions<TProviderOptions extends object = object
|
|
|
1910
1947
|
*/
|
|
1911
1948
|
abortSignal?: AbortSignal;
|
|
1912
1949
|
}
|
|
1950
|
+
/**
|
|
1951
|
+
* Assets from a finished world job. Live session adapters omit this.
|
|
1952
|
+
* URLs are often signed CDN links. They can expire and may need a proxy
|
|
1953
|
+
* to fetch from a browser.
|
|
1954
|
+
*
|
|
1955
|
+
* @experimental World generation is an experimental feature and may change.
|
|
1956
|
+
*/
|
|
1957
|
+
export interface WorldGenerationAssets {
|
|
1958
|
+
/** Auto-generated scene description */
|
|
1959
|
+
caption?: string;
|
|
1960
|
+
/** Preview image URL */
|
|
1961
|
+
thumbnailUrl?: string;
|
|
1962
|
+
splats?: {
|
|
1963
|
+
/** Quality-key map of splat URLs (`100k`, `500k`, `full_res`, …) */
|
|
1964
|
+
spzUrls?: Record<string, string>;
|
|
1965
|
+
metricScaleFactor?: number;
|
|
1966
|
+
groundPlaneOffset?: number;
|
|
1967
|
+
};
|
|
1968
|
+
mesh?: {
|
|
1969
|
+
colliderMeshUrl?: string;
|
|
1970
|
+
hqMeshUrl?: string;
|
|
1971
|
+
fullResMeshUrl?: string;
|
|
1972
|
+
};
|
|
1973
|
+
imagery?: {
|
|
1974
|
+
panoUrl?: string;
|
|
1975
|
+
};
|
|
1976
|
+
}
|
|
1913
1977
|
/**
|
|
1914
1978
|
* Result of world generation. JSON-serializable so a server route can return
|
|
1915
|
-
* it to a browser.
|
|
1916
|
-
*
|
|
1979
|
+
* it to a browser.
|
|
1980
|
+
*
|
|
1981
|
+
* Live adapters (Reactor): `status: 'ready'` with `token` and token
|
|
1982
|
+
* `expiresAt`. The browser uses `token` + `model` to open the session.
|
|
1983
|
+
*
|
|
1984
|
+
* Job adapters (World Labs): `status: 'ready'` with viewer `url` and
|
|
1985
|
+
* `worldId`, or `status: 'waiting'` with `operationId` and no `url`.
|
|
1986
|
+
* `expiresAt` on a job is operation expiry, not a session token.
|
|
1917
1987
|
*
|
|
1918
1988
|
* @experimental World generation is an experimental feature and may change.
|
|
1919
1989
|
*/
|
|
1920
1990
|
export interface WorldGenerationResult {
|
|
1921
1991
|
/** Unique identifier for this generation */
|
|
1922
1992
|
id: string;
|
|
1923
|
-
/** Model used for generation (provider connect slug) */
|
|
1993
|
+
/** Model used for generation (provider connect slug or model id) */
|
|
1924
1994
|
model: string;
|
|
1925
|
-
/** Short-lived session token for
|
|
1926
|
-
token
|
|
1927
|
-
/**
|
|
1928
|
-
|
|
1929
|
-
|
|
1995
|
+
/** Short-lived session token for a live client connection */
|
|
1996
|
+
token?: string;
|
|
1997
|
+
/**
|
|
1998
|
+
* Expiry as milliseconds since epoch. Live adapters: session token.
|
|
1999
|
+
* Job adapters: operation expiry when the provider sends it.
|
|
2000
|
+
*/
|
|
2001
|
+
expiresAt?: number;
|
|
2002
|
+
/** Prompt used to generate the world, or the prompt the client should send */
|
|
1930
2003
|
prompt: string;
|
|
1931
|
-
/**
|
|
2004
|
+
/** Status after the server half finishes */
|
|
1932
2005
|
status: 'ready' | 'waiting';
|
|
1933
2006
|
/** Provider session id, when the adapter created one */
|
|
1934
2007
|
sessionId?: string;
|
|
2008
|
+
/** Viewer URL for a finished world job (not an asset download URL) */
|
|
2009
|
+
url?: string;
|
|
2010
|
+
/** Provider world id for a finished or in-progress job */
|
|
2011
|
+
worldId?: string;
|
|
2012
|
+
/** Provider operation id for a long-running world job */
|
|
2013
|
+
operationId?: string;
|
|
2014
|
+
/** Assets when a world job has finished and the provider returned them */
|
|
2015
|
+
assets?: WorldGenerationAssets;
|
|
1935
2016
|
/** Token usage / billing, when the adapter can report it */
|
|
1936
2017
|
usage?: TokenUsage;
|
|
1937
2018
|
}
|
|
@@ -3,8 +3,9 @@ import { ContentPart, StreamChunk, ToolOutputState } from '../types.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* Adapter / engine yield before normalize. Public StreamChunk is spec-only.
|
|
5
5
|
* This type still allows the old extra fields.
|
|
6
|
+
* Extras never override a spec field (see WithAdapterExtras).
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
+
type AdapterExtras = {
|
|
8
9
|
model?: string;
|
|
9
10
|
finishReason?: 'stop' | 'length' | 'content_filter' | 'tool_calls' | null;
|
|
10
11
|
usage?: any;
|
|
@@ -29,3 +30,6 @@ export type AdapterYieldChunk = StreamChunk & {
|
|
|
29
30
|
threadId?: string;
|
|
30
31
|
runId?: string;
|
|
31
32
|
};
|
|
33
|
+
type WithAdapterExtras<T> = T extends StreamChunk ? T & Omit<AdapterExtras, keyof T> : never;
|
|
34
|
+
export type AdapterYieldChunk = WithAdapterExtras<StreamChunk>;
|
|
35
|
+
export {};
|
|
@@ -1,14 +1,7 @@
|
|
|
1
|
+
import { TokenUsage as SpecTokenUsage } from '@ag-ui/core';
|
|
1
2
|
import { TokenUsage } from '../types.js';
|
|
2
3
|
/** AG-UI spec `usage[]` item (provider/model labels + token counts only). */
|
|
3
|
-
export
|
|
4
|
-
provider?: string;
|
|
5
|
-
model?: string;
|
|
6
|
-
inputTokens?: number;
|
|
7
|
-
outputTokens?: number;
|
|
8
|
-
totalTokens?: number;
|
|
9
|
-
reasoningTokens?: number;
|
|
10
|
-
cachedInputTokens?: number;
|
|
11
|
-
}
|
|
4
|
+
export type { TokenUsage as SpecTokenUsage } from '@ag-ui/core';
|
|
12
5
|
export interface ToSpecTokenUsageOptions {
|
|
13
6
|
provider?: string;
|
|
14
7
|
model?: string;
|
|
@@ -20,5 +13,12 @@ export declare function toSpecTokenUsage(usage: TokenUsage, options?: ToSpecToke
|
|
|
20
13
|
usage: Array<SpecTokenUsage>;
|
|
21
14
|
leftover?: TokenUsageLeftover;
|
|
22
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* Add two usage totals, as for a parent run and its children. Numbers add
|
|
18
|
+
* up. `billed` adds up only in the same unit. `providerUsageDetails` is
|
|
19
|
+
* opaque, so the latest one stays. `@tanstack/ai-persistence` sums per-run
|
|
20
|
+
* usage with the same rules.
|
|
21
|
+
*/
|
|
22
|
+
export declare function addTokenUsage(current: TokenUsage, next: TokenUsage): TokenUsage;
|
|
23
23
|
export declare function rebuildTokenUsage(usage: unknown, leftover?: TokenUsageLeftover): TokenUsage | undefined;
|
|
24
24
|
export declare function fromSpecTokenUsage(usage: ReadonlyArray<SpecTokenUsage> | undefined, leftover?: TokenUsageLeftover): TokenUsage | undefined;
|
|
@@ -21,6 +21,7 @@ function toSpecTokenUsage(usage, options) {
|
|
|
21
21
|
};
|
|
22
22
|
const cachedInputTokens = promptTokensDetails?.cachedTokens;
|
|
23
23
|
if (cachedInputTokens !== void 0) spec.cachedInputTokens = cachedInputTokens;
|
|
24
|
+
if (promptTokensDetails?.cacheWriteTokens !== void 0) spec.cacheWriteInputTokens = promptTokensDetails.cacheWriteTokens;
|
|
24
25
|
const reasoningTokens = completionTokensDetails?.reasoningTokens;
|
|
25
26
|
if (reasoningTokens !== void 0) spec.reasoningTokens = reasoningTokens;
|
|
26
27
|
const leftoverPrompt = promptTokensDetails ? definedDetails(withoutKey(promptTokensDetails, "cachedTokens")) : void 0;
|
|
@@ -34,17 +35,79 @@ function toSpecTokenUsage(usage, options) {
|
|
|
34
35
|
})
|
|
35
36
|
};
|
|
36
37
|
}
|
|
38
|
+
function sumNumbers(current, next) {
|
|
39
|
+
if (!current) return next;
|
|
40
|
+
if (!next) return current;
|
|
41
|
+
const result = { ...current };
|
|
42
|
+
for (const key of Object.keys(next)) {
|
|
43
|
+
const value = next[key];
|
|
44
|
+
if (typeof value !== "number") continue;
|
|
45
|
+
const previous = current[key];
|
|
46
|
+
result[key] = (typeof previous === "number" ? previous : 0) + value;
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
function sumOptional(current, next) {
|
|
51
|
+
if (current === void 0) return next;
|
|
52
|
+
if (next === void 0) return current;
|
|
53
|
+
return current + next;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Add two usage totals, as for a parent run and its children. Numbers add
|
|
57
|
+
* up. `billed` adds up only in the same unit. `providerUsageDetails` is
|
|
58
|
+
* opaque, so the latest one stays. `@tanstack/ai-persistence` sums per-run
|
|
59
|
+
* usage with the same rules.
|
|
60
|
+
*/
|
|
61
|
+
function addTokenUsage(current, next) {
|
|
62
|
+
const promptTokensDetails = sumNumbers(current.promptTokensDetails, next.promptTokensDetails);
|
|
63
|
+
const completionTokensDetails = sumNumbers(current.completionTokensDetails, next.completionTokensDetails);
|
|
64
|
+
const costDetails = sumNumbers(current.costDetails, next.costDetails);
|
|
65
|
+
const cost = sumOptional(current.cost, next.cost);
|
|
66
|
+
const durationSeconds = sumOptional(current.durationSeconds, next.durationSeconds);
|
|
67
|
+
const unitsBilled = sumOptional(current.unitsBilled, next.unitsBilled);
|
|
68
|
+
const billed = current.billed && next.billed && current.billed.unit === next.billed.unit ? {
|
|
69
|
+
quantity: current.billed.quantity + next.billed.quantity,
|
|
70
|
+
unit: current.billed.unit
|
|
71
|
+
} : next.billed ?? current.billed;
|
|
72
|
+
const providerUsageDetails = next.providerUsageDetails ?? current.providerUsageDetails;
|
|
73
|
+
return {
|
|
74
|
+
...current,
|
|
75
|
+
...next,
|
|
76
|
+
promptTokens: current.promptTokens + next.promptTokens,
|
|
77
|
+
completionTokens: current.completionTokens + next.completionTokens,
|
|
78
|
+
totalTokens: current.totalTokens + next.totalTokens,
|
|
79
|
+
...promptTokensDetails && { promptTokensDetails },
|
|
80
|
+
...completionTokensDetails && { completionTokensDetails },
|
|
81
|
+
...cost !== void 0 && { cost },
|
|
82
|
+
...costDetails && { costDetails },
|
|
83
|
+
...durationSeconds !== void 0 && { durationSeconds },
|
|
84
|
+
...unitsBilled !== void 0 && { unitsBilled },
|
|
85
|
+
...billed && { billed },
|
|
86
|
+
...providerUsageDetails && { providerUsageDetails }
|
|
87
|
+
};
|
|
88
|
+
}
|
|
37
89
|
function rebuildTokenUsage(usage, leftover) {
|
|
38
90
|
if (isTanstackUsage(usage)) return usage;
|
|
39
91
|
if (Array.isArray(usage)) return fromSpecTokenUsage(usage, leftover);
|
|
40
92
|
return fromSpecTokenUsage(void 0, leftover);
|
|
41
93
|
}
|
|
42
94
|
function fromSpecTokenUsage(usage, leftover) {
|
|
43
|
-
const spec = usage?.
|
|
44
|
-
|
|
95
|
+
const spec = usage?.reduce((total, entry) => {
|
|
96
|
+
for (const key of [
|
|
97
|
+
"inputTokens",
|
|
98
|
+
"outputTokens",
|
|
99
|
+
"totalTokens",
|
|
100
|
+
"cachedInputTokens",
|
|
101
|
+
"cacheWriteInputTokens",
|
|
102
|
+
"reasoningTokens"
|
|
103
|
+
]) if (entry[key] !== void 0) total[key] = (total[key] ?? 0) + entry[key];
|
|
104
|
+
return total;
|
|
105
|
+
}, {});
|
|
106
|
+
if ((usage === void 0 || usage.length === 0) && leftover == null) return;
|
|
45
107
|
const { promptTokensDetails: leftoverPromptDetails, completionTokensDetails: leftoverCompletionDetails, ...leftoverRest } = leftover ?? {};
|
|
46
108
|
const promptTokensDetails = definedDetails({
|
|
47
109
|
...spec?.cachedInputTokens !== void 0 ? { cachedTokens: spec.cachedInputTokens } : {},
|
|
110
|
+
...spec?.cacheWriteInputTokens !== void 0 ? { cacheWriteTokens: spec.cacheWriteInputTokens } : {},
|
|
48
111
|
...leftoverPromptDetails
|
|
49
112
|
});
|
|
50
113
|
const completionTokensDetails = definedDetails({
|
|
@@ -61,6 +124,6 @@ function fromSpecTokenUsage(usage, leftover) {
|
|
|
61
124
|
};
|
|
62
125
|
}
|
|
63
126
|
//#endregion
|
|
64
|
-
export { fromSpecTokenUsage, isTanstackUsage, rebuildTokenUsage, toSpecTokenUsage };
|
|
127
|
+
export { addTokenUsage, fromSpecTokenUsage, isTanstackUsage, rebuildTokenUsage, toSpecTokenUsage };
|
|
65
128
|
|
|
66
129
|
//# sourceMappingURL=ag-ui-usage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ag-ui-usage.js","names":[],"sources":["../../../src/utilities/ag-ui-usage.ts"],"sourcesContent":["import type { TokenUsage } from '../types'\n\n/** AG-UI spec `usage[]` item (provider/model labels + token counts only). */\nexport interface SpecTokenUsage {\n provider?: string\n model?: string\n inputTokens?: number\n outputTokens?: number\n totalTokens?: number\n reasoningTokens?: number\n cachedInputTokens?: number\n}\n\nexport interface ToSpecTokenUsageOptions {\n provider?: string\n model?: string\n}\n\n/** TokenUsage fields that have no AG-UI `usage[]` equivalent. */\nexport type TokenUsageLeftover = Omit<\n TokenUsage,\n 'promptTokens' | 'completionTokens' | 'totalTokens'\n>\n\nfunction definedDetails<T extends object>(value: T): T | undefined {\n return Object.keys(value).length > 0 ? value : undefined\n}\n\nfunction withoutKey<T extends object, K extends keyof T>(\n value: T,\n key: K,\n): Omit<T, K> {\n const next = { ...value }\n delete next[key]\n return next\n}\n\nexport function isTanstackUsage(usage: unknown): usage is TokenUsage {\n return (\n typeof usage === 'object' &&\n usage != null &&\n !Array.isArray(usage) &&\n 'promptTokens' in usage\n )\n}\n\nexport function toSpecTokenUsage(\n usage: TokenUsage,\n options?: ToSpecTokenUsageOptions,\n): { usage: Array<SpecTokenUsage>; leftover?: TokenUsageLeftover } {\n const {\n promptTokens,\n completionTokens,\n totalTokens,\n promptTokensDetails,\n completionTokensDetails,\n ...rest\n } = usage\n\n const spec: SpecTokenUsage = {\n ...(options?.provider !== undefined ? { provider: options.provider } : {}),\n ...(options?.model !== undefined ? { model: options.model } : {}),\n inputTokens: promptTokens,\n outputTokens: completionTokens,\n totalTokens,\n }\n const cachedInputTokens = promptTokensDetails?.cachedTokens\n if (cachedInputTokens !== undefined) {\n spec.cachedInputTokens = cachedInputTokens\n }\n const reasoningTokens = completionTokensDetails?.reasoningTokens\n if (reasoningTokens !== undefined) {\n spec.reasoningTokens = reasoningTokens\n }\n\n const leftoverPrompt = promptTokensDetails\n ? definedDetails(withoutKey(promptTokensDetails, 'cachedTokens'))\n : undefined\n const leftoverCompletion = completionTokensDetails\n ? definedDetails(withoutKey(completionTokensDetails, 'reasoningTokens'))\n : undefined\n\n return {\n usage: [spec],\n leftover: definedDetails({\n ...rest,\n ...(leftoverPrompt !== undefined\n ? { promptTokensDetails: leftoverPrompt }\n : {}),\n ...(leftoverCompletion !== undefined\n ? { completionTokensDetails: leftoverCompletion }\n : {}),\n }),\n }\n}\n\nexport function rebuildTokenUsage(\n usage: unknown,\n leftover?: TokenUsageLeftover,\n): TokenUsage | undefined {\n if (isTanstackUsage(usage)) {\n return usage\n }\n if (Array.isArray(usage)) {\n return fromSpecTokenUsage(usage, leftover)\n }\n return fromSpecTokenUsage(undefined, leftover)\n}\n\nexport function fromSpecTokenUsage(\n usage: ReadonlyArray<SpecTokenUsage> | undefined,\n leftover?: TokenUsageLeftover,\n): TokenUsage | undefined {\n const spec = usage?.[0]\n if (spec == null && leftover == null) {\n return undefined\n }\n\n const {\n promptTokensDetails: leftoverPromptDetails,\n completionTokensDetails: leftoverCompletionDetails,\n ...leftoverRest\n } = leftover ?? {}\n\n const promptTokensDetails = definedDetails({\n ...(spec?.cachedInputTokens !== undefined\n ? { cachedTokens: spec.cachedInputTokens }\n : {}),\n ...leftoverPromptDetails,\n })\n const completionTokensDetails = definedDetails({\n ...(spec?.reasoningTokens !== undefined\n ? { reasoningTokens: spec.reasoningTokens }\n : {}),\n ...leftoverCompletionDetails,\n })\n\n return {\n promptTokens: spec?.inputTokens ?? 0,\n completionTokens: spec?.outputTokens ?? 0,\n totalTokens: spec?.totalTokens ?? 0,\n ...leftoverRest,\n ...(promptTokensDetails !== undefined ? { promptTokensDetails } : {}),\n ...(completionTokensDetails !== undefined\n ? { completionTokensDetails }\n : {}),\n }\n}\n"],"mappings":";AAwBA,SAAS,eAAiC,OAAyB;CACjE,OAAO,OAAO,KAAK,KAAK,CAAC,CAAC,SAAS,IAAI,QAAQ,KAAA;AACjD;AAEA,SAAS,WACP,OACA,KACY;CACZ,MAAM,OAAO,EAAE,GAAG,MAAM;CACxB,OAAO,KAAK;CACZ,OAAO;AACT;AAEA,SAAgB,gBAAgB,OAAqC;CACnE,OACE,OAAO,UAAU,YACjB,SAAS,QACT,CAAC,MAAM,QAAQ,KAAK,KACpB,kBAAkB;AAEtB;AAEA,SAAgB,iBACd,OACA,SACiE;CACjE,MAAM,EACJ,cACA,kBACA,aACA,qBACA,yBACA,GAAG,SACD;CAEJ,MAAM,OAAuB;EAC3B,GAAI,SAAS,aAAa,KAAA,IAAY,EAAE,UAAU,QAAQ,SAAS,IAAI,CAAC;EACxE,GAAI,SAAS,UAAU,KAAA,IAAY,EAAE,OAAO,QAAQ,MAAM,IAAI,CAAC;EAC/D,aAAa;EACb,cAAc;EACd;CACF;CACA,MAAM,oBAAoB,qBAAqB;CAC/C,IAAI,sBAAsB,KAAA,GACxB,KAAK,oBAAoB;CAE3B,MAAM,kBAAkB,yBAAyB;CACjD,IAAI,oBAAoB,KAAA,GACtB,KAAK,kBAAkB;CAGzB,MAAM,iBAAiB,sBACnB,eAAe,WAAW,qBAAqB,cAAc,CAAC,IAC9D,KAAA;CACJ,MAAM,qBAAqB,0BACvB,eAAe,WAAW,yBAAyB,iBAAiB,CAAC,IACrE,KAAA;CAEJ,OAAO;EACL,OAAO,CAAC,IAAI;EACZ,UAAU,eAAe;GACvB,GAAG;GACH,GAAI,mBAAmB,KAAA,IACnB,EAAE,qBAAqB,eAAe,IACtC,CAAC;GACL,GAAI,uBAAuB,KAAA,IACvB,EAAE,yBAAyB,mBAAmB,IAC9C,CAAC;EACP,CAAC;CACH;AACF;AAEA,SAAgB,kBACd,OACA,UACwB;CACxB,IAAI,gBAAgB,KAAK,GACvB,OAAO;CAET,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO,mBAAmB,OAAO,QAAQ;CAE3C,OAAO,mBAAmB,KAAA,GAAW,QAAQ;AAC/C;AAEA,SAAgB,mBACd,OACA,UACwB;CACxB,MAAM,OAAO,QAAQ;CACrB,IAAI,QAAQ,QAAQ,YAAY,MAC9B;CAGF,MAAM,EACJ,qBAAqB,uBACrB,yBAAyB,2BACzB,GAAG,iBACD,YAAY,CAAC;CAEjB,MAAM,sBAAsB,eAAe;EACzC,GAAI,MAAM,sBAAsB,KAAA,IAC5B,EAAE,cAAc,KAAK,kBAAkB,IACvC,CAAC;EACL,GAAG;CACL,CAAC;CACD,MAAM,0BAA0B,eAAe;EAC7C,GAAI,MAAM,oBAAoB,KAAA,IAC1B,EAAE,iBAAiB,KAAK,gBAAgB,IACxC,CAAC;EACL,GAAG;CACL,CAAC;CAED,OAAO;EACL,cAAc,MAAM,eAAe;EACnC,kBAAkB,MAAM,gBAAgB;EACxC,aAAa,MAAM,eAAe;EAClC,GAAG;EACH,GAAI,wBAAwB,KAAA,IAAY,EAAE,oBAAoB,IAAI,CAAC;EACnE,GAAI,4BAA4B,KAAA,IAC5B,EAAE,wBAAwB,IAC1B,CAAC;CACP;AACF"}
|
|
1
|
+
{"version":3,"file":"ag-ui-usage.js","names":[],"sources":["../../../src/utilities/ag-ui-usage.ts"],"sourcesContent":["import type { TokenUsage as SpecTokenUsage } from '@ag-ui/core'\nimport type { TokenUsage } from '../types'\n\n/** AG-UI spec `usage[]` item (provider/model labels + token counts only). */\nexport type { TokenUsage as SpecTokenUsage } from '@ag-ui/core'\n\nexport interface ToSpecTokenUsageOptions {\n provider?: string\n model?: string\n}\n\n/** TokenUsage fields that have no AG-UI `usage[]` equivalent. */\nexport type TokenUsageLeftover = Omit<\n TokenUsage,\n 'promptTokens' | 'completionTokens' | 'totalTokens'\n>\n\nfunction definedDetails<T extends object>(value: T): T | undefined {\n return Object.keys(value).length > 0 ? value : undefined\n}\n\nfunction withoutKey<T extends object, K extends keyof T>(\n value: T,\n key: K,\n): Omit<T, K> {\n const next = { ...value }\n delete next[key]\n return next\n}\n\nexport function isTanstackUsage(usage: unknown): usage is TokenUsage {\n return (\n typeof usage === 'object' &&\n usage != null &&\n !Array.isArray(usage) &&\n 'promptTokens' in usage\n )\n}\n\nexport function toSpecTokenUsage(\n usage: TokenUsage,\n options?: ToSpecTokenUsageOptions,\n): { usage: Array<SpecTokenUsage>; leftover?: TokenUsageLeftover } {\n const {\n promptTokens,\n completionTokens,\n totalTokens,\n promptTokensDetails,\n completionTokensDetails,\n ...rest\n } = usage\n\n const spec: SpecTokenUsage = {\n ...(options?.provider !== undefined ? { provider: options.provider } : {}),\n ...(options?.model !== undefined ? { model: options.model } : {}),\n inputTokens: promptTokens,\n outputTokens: completionTokens,\n totalTokens,\n }\n const cachedInputTokens = promptTokensDetails?.cachedTokens\n if (cachedInputTokens !== undefined) {\n spec.cachedInputTokens = cachedInputTokens\n }\n if (promptTokensDetails?.cacheWriteTokens !== undefined) {\n spec.cacheWriteInputTokens = promptTokensDetails.cacheWriteTokens\n }\n const reasoningTokens = completionTokensDetails?.reasoningTokens\n if (reasoningTokens !== undefined) {\n spec.reasoningTokens = reasoningTokens\n }\n\n // cacheWriteTokens stays in the leftover too, so clients built before\n // cacheWriteInputTokens existed still rebuild it.\n const leftoverPrompt = promptTokensDetails\n ? definedDetails(withoutKey(promptTokensDetails, 'cachedTokens'))\n : undefined\n const leftoverCompletion = completionTokensDetails\n ? definedDetails(withoutKey(completionTokensDetails, 'reasoningTokens'))\n : undefined\n\n return {\n usage: [spec],\n leftover: definedDetails({\n ...rest,\n ...(leftoverPrompt !== undefined\n ? { promptTokensDetails: leftoverPrompt }\n : {}),\n ...(leftoverCompletion !== undefined\n ? { completionTokensDetails: leftoverCompletion }\n : {}),\n }),\n }\n}\n\nfunction sumNumbers<T extends object>(\n current: T | undefined,\n next: T | undefined,\n): T | undefined {\n if (!current) return next\n if (!next) return current\n const result = { ...current }\n for (const key of Object.keys(next) as Array<keyof T>) {\n const value = next[key]\n if (typeof value !== 'number') continue\n const previous = current[key]\n result[key] = ((typeof previous === 'number' ? previous : 0) +\n value) as T[keyof T]\n }\n return result\n}\n\nfunction sumOptional(current?: number, next?: number): number | undefined {\n if (current === undefined) return next\n if (next === undefined) return current\n return current + next\n}\n\n/**\n * Add two usage totals, as for a parent run and its children. Numbers add\n * up. `billed` adds up only in the same unit. `providerUsageDetails` is\n * opaque, so the latest one stays. `@tanstack/ai-persistence` sums per-run\n * usage with the same rules.\n */\nexport function addTokenUsage(\n current: TokenUsage,\n next: TokenUsage,\n): TokenUsage {\n const promptTokensDetails = sumNumbers(\n current.promptTokensDetails,\n next.promptTokensDetails,\n )\n const completionTokensDetails = sumNumbers(\n current.completionTokensDetails,\n next.completionTokensDetails,\n )\n const costDetails = sumNumbers(current.costDetails, next.costDetails)\n const cost = sumOptional(current.cost, next.cost)\n const durationSeconds = sumOptional(\n current.durationSeconds,\n next.durationSeconds,\n )\n const unitsBilled = sumOptional(current.unitsBilled, next.unitsBilled)\n const billed =\n current.billed && next.billed && current.billed.unit === next.billed.unit\n ? {\n quantity: current.billed.quantity + next.billed.quantity,\n unit: current.billed.unit,\n }\n : (next.billed ?? current.billed)\n const providerUsageDetails =\n next.providerUsageDetails ?? current.providerUsageDetails\n return {\n ...current,\n ...next,\n promptTokens: current.promptTokens + next.promptTokens,\n completionTokens: current.completionTokens + next.completionTokens,\n totalTokens: current.totalTokens + next.totalTokens,\n ...(promptTokensDetails && { promptTokensDetails }),\n ...(completionTokensDetails && { completionTokensDetails }),\n ...(cost !== undefined && { cost }),\n ...(costDetails && { costDetails }),\n ...(durationSeconds !== undefined && { durationSeconds }),\n ...(unitsBilled !== undefined && { unitsBilled }),\n ...(billed && { billed }),\n ...(providerUsageDetails && { providerUsageDetails }),\n }\n}\n\nexport function rebuildTokenUsage(\n usage: unknown,\n leftover?: TokenUsageLeftover,\n): TokenUsage | undefined {\n if (isTanstackUsage(usage)) {\n return usage\n }\n if (Array.isArray(usage)) {\n return fromSpecTokenUsage(usage, leftover)\n }\n return fromSpecTokenUsage(undefined, leftover)\n}\n\nexport function fromSpecTokenUsage(\n usage: ReadonlyArray<SpecTokenUsage> | undefined,\n leftover?: TokenUsageLeftover,\n): TokenUsage | undefined {\n const spec = usage?.reduce<SpecTokenUsage>((total, entry) => {\n for (const key of [\n 'inputTokens',\n 'outputTokens',\n 'totalTokens',\n 'cachedInputTokens',\n 'cacheWriteInputTokens',\n 'reasoningTokens',\n ] as const) {\n if (entry[key] !== undefined) total[key] = (total[key] ?? 0) + entry[key]\n }\n return total\n }, {})\n if ((usage === undefined || usage.length === 0) && leftover == null) {\n return undefined\n }\n\n const {\n promptTokensDetails: leftoverPromptDetails,\n completionTokensDetails: leftoverCompletionDetails,\n ...leftoverRest\n } = leftover ?? {}\n\n const promptTokensDetails = definedDetails({\n ...(spec?.cachedInputTokens !== undefined\n ? { cachedTokens: spec.cachedInputTokens }\n : {}),\n ...(spec?.cacheWriteInputTokens !== undefined\n ? { cacheWriteTokens: spec.cacheWriteInputTokens }\n : {}),\n ...leftoverPromptDetails,\n })\n const completionTokensDetails = definedDetails({\n ...(spec?.reasoningTokens !== undefined\n ? { reasoningTokens: spec.reasoningTokens }\n : {}),\n ...leftoverCompletionDetails,\n })\n\n return {\n promptTokens: spec?.inputTokens ?? 0,\n completionTokens: spec?.outputTokens ?? 0,\n totalTokens: spec?.totalTokens ?? 0,\n ...leftoverRest,\n ...(promptTokensDetails !== undefined ? { promptTokensDetails } : {}),\n ...(completionTokensDetails !== undefined\n ? { completionTokensDetails }\n : {}),\n }\n}\n"],"mappings":"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"}
|