@tanstack/ai
Version:
Type-safe TypeScript AI SDK for streaming chat, tool calling, agents, structured outputs, and multimodal generation.
52 lines (51 loc) • 1.58 kB
TypeScript
import { ContentPart, UIMessage } from '../types.js';
import { MetadataRecord } from './merge-metadata.js';
type AGUITextInputContent = {
type: 'text';
text: string;
};
type AGUIInputContent = AGUITextInputContent | (ContentPart & {
type: 'image' | 'audio' | 'video' | 'document';
});
type AGUIToolCallMirror = {
id: string;
type: 'function';
function: {
name: string;
arguments: string;
};
encryptedValue?: string;
};
type AGUIToolMessage = {
role: 'tool';
id: string;
toolCallId: string;
content: string;
error?: string;
};
type AGUIReasoningMessage = {
role: 'reasoning';
id: string;
content: string;
encryptedValue?: string;
metadata?: MetadataRecord;
};
/** Spec AG-UI message. No `parts`, no `createdAt` Date. */
type WireAnchorMessage = {
id: string;
role: UIMessage['role'];
name?: string;
content?: string | Array<AGUIInputContent>;
toolCalls?: Array<AGUIToolCallMirror>;
metadata?: MetadataRecord;
};
export type WireMessage = WireAnchorMessage | AGUIToolMessage | AGUIReasoningMessage;
/**
* Serialize TanStack `UIMessage`s into the AG-UI `RunAgentInput.messages`
* wire shape. Anchors are spec-only (`id`, `role`, `name`, `content`,
* `toolCalls`, `metadata`). Tool results and thinking parts on assistant
* messages are additionally emitted as fan-out `{role:'tool',...}` and
* `{role:'reasoning',...}` entries for strict AG-UI server consumers.
*/
export declare function uiMessagesToWire(messages: Array<UIMessage>): Array<WireMessage>;
export {};