Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

ModelMessage.md

192 lines4.5 KB

1---
2id: ModelMessage
3title: ModelMessage
4---
5​
6Defined in: [packages/ai/src/types.ts:428](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L428)
7​
8## Type Parameters
9​
10### TContent
11​
12`TContent` *extends* `string` \| `null` \| [`ContentPart`](../type-aliases/ContentPart.md)[] = `string` \| `null` \| [`ContentPart`](../type-aliases/ContentPart.md)[]
13​
14## Properties
15​
16### blockOrder?
17​
18```ts
19optional blockOrder?: ModelMessageBlock[];
20```
21​
22Defined in: [packages/ai/src/types.ts:452](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L452)
23​
24The order of the blocks of an assistant message, when it is not the
25default order (all thinking, then the text, then the tool calls). Each
26entry points into `thinking`, into `content` (a string, by UTF-16 length),
27or into `toolCalls`. The library writes and reads this field. A reader
28that finds a map that does not match the message uses the default order.
29​
30***
31​
32### content
33​
34```ts
35content: TContent;
36```
37​
38Defined in: [packages/ai/src/types.ts:435](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L435)
39​
40***
41​
42### createdAt?
43​
44```ts
45optional createdAt?: Date;
46```
47​
48Defined in: [packages/ai/src/types.ts:482](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L482)
49​
50Optional message creation timestamp. When present, message converters
51preserve it across persist → hydrate round-trips.
52​
53***
54​
55### error?
56​
57```ts
58optional error?: string;
59```
60​
61Defined in: [packages/ai/src/types.ts:454](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L454)
62​
63Error reported by an AG-UI tool message.
64​
65***
66​
67### id?
68​
69```ts
70optional id?: string;
71```
72​
73Defined in: [packages/ai/src/types.ts:477](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L477)
74​
75Optional stable message id. Providers ignore it; it exists so a persisted
76transcript can retain the streaming `messageId` and survive the
77persist → hydrate round-trip. When present, `modelMessagesToUIMessages`
78reuses it instead of generating a fresh id, so a hydrated message keeps the
79same identity as its live stream — which is what lets a mid-stream reload
80resume the SAME message bubble in place (see `@tanstack/ai-persistence`).
81​
82***
83​
84### metadata?
85​
86```ts
87optional metadata?: Record<string, any>;
88```
89​
90Defined in: [packages/ai/src/types.ts:462](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L462)
91​
92Optional AG-UI message metadata. TanStack-owned fields live under `tanstack`.
93​
94***
95​
96### midConversationChange?
97​
98```ts
99optional midConversationChange?: MidConversationChange;
100```
101​
102Defined in: [packages/ai/src/types.ts:460](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L460)
103​
104The tools and system prompts that changed before this assistant message.
105`chat()` writes it when the adapter has a mid-conversation channel.
106Providers ignore it: adapters read `TextOptions.midConversationChanges`.
107​
108***
109​
110### name?
111​
112```ts
113optional name?: string;
114```
115​
116Defined in: [packages/ai/src/types.ts:436](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L436)
117​
118***
119​
120### role
121​
122```ts
123role: "assistant" | "user" | "tool";
124```
125​
126Defined in: [packages/ai/src/types.ts:434](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L434)
127​
128***
129​
130### structuredOutput?
131​
132```ts
133optional structuredOutput?: StructuredOutputPart<unknown>;
134```
135​
136Defined in: [packages/ai/src/types.ts:468](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L468)
137​
138Completed structured output represented by this assistant message.
139`content` remains the provider-facing JSON text; this field preserves the
140typed UI part across persistence and message conversion.
141​
142***
143​
144### thinking?
145​
146```ts
147optional thinking?: object[];
148```
149​
150Defined in: [packages/ai/src/types.ts:444](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L444)
151​
152Signed thinking to send back to the provider. `redacted: true` marks a
153block the provider encrypted: `content` is empty and `signature` holds its
154opaque data. See `ThinkingPart.signature` for the planned rename.
155​
156#### content
157​
158```ts
159content: string;
160```
161​
162#### redacted?
163​
164```ts
165optional redacted?: boolean;
166```
167​
168#### signature?
169​
170```ts
171optional signature?: string;
172```
173​
174***
175​
176### toolCallId?
177​
178```ts
179optional toolCallId?: string;
180```
181​
182Defined in: [packages/ai/src/types.ts:438](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L438)
183​
184***
185​
186### toolCalls?
187​
188```ts
189optional toolCalls?: ToolCall<unknown>[];
190```
191​
192Defined in: [packages/ai/src/types.ts:437](https://github.com/TanStack/ai/blob/main/packages/ai/src/types.ts#L437)