MCPcopy
hub / github.com/TanStack/ai / createChatMiddleware

Function createChatMiddleware

packages/ai/src/activities/chat/middleware/builder.ts:89–109  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

87
88/** Create an order-aware middleware builder. */
89export function createChatMiddleware(): ChatMiddlewareBuilder<
90 readonly [],
91 never
92> {
93 const list: Array<ChatMiddleware<unknown>> = []
94 const builder = {
95 use(middleware: ChatMiddleware<unknown>) {
96 list.push(middleware)
97 return builder
98 },
99 build() {
100 return list
101 },
102 }
103 // The only sanctioned assertion in this PR: the runtime `builder` is a single
104 // object reused across `.use()` calls, but the type accumulates `TProvided`
105 // and `TList` per call — TypeScript cannot derive that from runtime values, so
106 // a structural `as` is impossible and the double assertion is irreducible.
107 // eslint-disable-next-line no-restricted-syntax -- irreducible: type-level accumulation cannot be expressed from a single runtime object
108 return builder as unknown as ChatMiddlewareBuilder<readonly [], never>
109}

Calls

no outgoing calls

Tested by

no test coverage detected