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

ChatMiddlewareConfig.md

168 lines4.6 KB

Defined in: packages/ai/src/activities/chat/middleware/types.ts:354

Chat configuration that middleware can observe or transform. This is a subset of the chat engine's effective configuration that middleware is allowed to modify.

Properties

activities?

optional activities?: ActivityRecord[];

Defined in: packages/ai/src/activities/chat/middleware/types.ts:361

Frontend-only AG-UI activity sidecar. Persistence loads and saves this when an ActivityStore is configured. Never model input.


messages

messages: ModelMessage<
  | string
  | ContentPart<unknown, unknown, unknown, unknown, unknown>[]
  | null>[];

Defined in: packages/ai/src/activities/chat/middleware/types.ts:356

Canonical conversation history. Middleware and persistence read this.


metadata?

optional metadata?: Record<string, unknown>;

Defined in: packages/ai/src/activities/chat/middleware/types.ts:368


modelOptions?

optional modelOptions?: Record<string, unknown>;

Defined in: packages/ai/src/activities/chat/middleware/types.ts:369


promptCache?

optional promptCache?: ResolvedPromptCache;

Defined in: packages/ai/src/activities/chat/middleware/types.ts:382

The prompt cache of the next model call. A returned value stays until a middleware changes it.


providerMessages?

optional providerMessages?: ModelMessage<
  | string
  | ContentPart<unknown, unknown, unknown, unknown, unknown>[]
  | null>[];

Defined in: packages/ai/src/activities/chat/middleware/types.ts:363

Provider-only context. Defaults to messages when it is not set.


reasoning?

optional reasoning?: ReasoningRequest;

Defined in: packages/ai/src/activities/chat/middleware/types.ts:371

How hard the model thinks at this call. A middleware can set or change it.


resume?

optional resume?: RunAgentResumeItem[];

Defined in: packages/ai/src/activities/chat/middleware/types.ts:366


resumeToolState?

optional resumeToolState?: ChatResumeToolState;

Defined in: packages/ai/src/activities/chat/middleware/types.ts:367


systemPrompts

systemPrompts: SystemPrompt[];

Defined in: packages/ai/src/activities/chat/middleware/types.ts:364


toolChoice?

optional toolChoice?: ToolChoice;

Defined in: packages/ai/src/activities/chat/middleware/types.ts:377

How the model uses the tools of the next model call. A returned value applies to that call only. The next call starts again from the chat() option. A call with no tools sends no tool choice.


tools

tools: Tool<SchemaInput, SchemaInput, string, unknown, SchemaInput | undefined>[];

Defined in: packages/ai/src/activities/chat/middleware/types.ts:365


wrapFetch?

optional wrapFetch?: FetchWrapper;

Defined in: packages/ai/src/activities/chat/middleware/types.ts:388

Wraps the fetch of the next model call. A returned wrapper chains inside the wrappers before it, so it does not replace them. It applies to that call only. The next call starts again from the chat() option.