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

chatParamsFromRequestBody.md

63 lines1.7 KB

1---
2id: chatParamsFromRequestBody
3title: chatParamsFromRequestBody
4---
5​
6# Function: chatParamsFromRequestBody()
7​
8```ts
9function chatParamsFromRequestBody(body): Promise<{
10 context: object[];
11 forwardedProps: Record<string, unknown>;
12 messages: (
13 | ModelMessage<
14 | string
15 | ContentPart<unknown, unknown, unknown, unknown, unknown>[]
16 | null>
17 | UIMessage<unknown>)[];
18 parentRunId?: string;
19 runId: string;
20 state: unknown;
21 threadId: string;
22 tools: object[];
23}>;
24```
25​
26Defined in: [packages/typescript/ai/src/utilities/chat-params.ts:38](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/utilities/chat-params.ts#L38)
27​
28Parse and validate an HTTP request body as an AG-UI `RunAgentInput`.
29​
30Returns a spread-friendly object whose `messages` field is suitable for
31passing directly to `chat({ messages })`. The existing
32`convertMessagesToModelMessages` handles AG-UI fan-out dedup and
33reasoning/activity/developer-role normalization internally.
34​
35## Parameters
36​
37### body
38​
39`unknown`
40​
41## Returns
42​
43`Promise`\<\{
44 `context`: `object`[];
45 `forwardedProps`: `Record`\<`string`, `unknown`\>;
46 `messages`: (
47 \| [`ModelMessage`](../interfaces/ModelMessage.md)\<
48 \| `string`
49 \| [`ContentPart`](../type-aliases/ContentPart.md)\<`unknown`, `unknown`, `unknown`, `unknown`, `unknown`\>[]
50 \| `null`\>
51 \| [`UIMessage`](../interfaces/UIMessage.md)\<`unknown`\>)[];
52 `parentRunId?`: `string`;
53 `runId`: `string`;
54 `state`: `unknown`;
55 `threadId`: `string`;
56 `tools`: `object`[];
57\}\>
58​
59## Throws
60​
61An error with a migration-pointing message when the body does
62 not conform to AG-UI 0.0.52 `RunAgentInputSchema`. Surface this as a
63 400 Bad Request to the client.