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

chatParamsFromRequestBody.md

68 lines1.9 KB

1---
2id: chatParamsFromRequestBody
3title: chatParamsFromRequestBody
4---
5​
6```ts
7function chatParamsFromRequestBody(body): Promise<{
8 aguiContext: Context[];
9 context: Context[];
10 forwardedProps: Record<string, unknown>;
11 messages: (
12 | UIMessage<unknown>
13 | ModelMessage<
14 | string
15 | ContentPart<unknown, unknown, unknown, unknown, unknown>[]
16 | null>)[];
17 parentRunId?: string;
18 resume?: RunAgentResumeItem[];
19 runId: string;
20 state: unknown;
21 threadId: string;
22 tools: object[];
23}>;
24```
25​
26Defined in: [packages/ai/src/utilities/chat-params.ts:204](https://github.com/TanStack/ai/blob/main/packages/ai/src/utilities/chat-params.ts#L204)
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​
35Validated structurally against the AG-UI `RunAgentInput` contract without a
36schema library, so this package pulls in no validation runtime of its own.
37​
38## Parameters
39​
40### body
41​
42`unknown`
43​
44## Returns
45​
46`Promise`\<\{
47 `aguiContext`: `Context`[];
48 `context`: `Context`[];
49 `forwardedProps`: `Record`\<`string`, `unknown`\>;
50 `messages`: (
51 \| [`UIMessage`](../interfaces/UIMessage.md)\<`unknown`\>
52 \| [`ModelMessage`](../interfaces/ModelMessage.md)\<
53 \| `string`
54 \| [`ContentPart`](../type-aliases/ContentPart.md)\<`unknown`, `unknown`, `unknown`, `unknown`, `unknown`\>[]
55 \| `null`\>)[];
56 `parentRunId?`: `string`;
57 `resume?`: [`RunAgentResumeItem`](../type-aliases/RunAgentResumeItem.md)[];
58 `runId`: `string`;
59 `state`: `unknown`;
60 `threadId`: `string`;
61 `tools`: `object`[];
62\}\>
63​
64## Throws
65​
66An error with a migration-pointing message when the body does
67 not conform to AG-UI `RunAgentInput`. Surface this as a
68 400 Bad Request to the client.