Documentation / @agentick/kernel / applyMiddleware
Function: applyMiddleware() ​
applyMiddleware<
TArgs,TOutput>(procedure, ...middleware):Procedure<(...args) =>TOutput>
Defined in: kernel/src/procedure.ts:1869
Type-safe helper to apply middleware to a Procedure while preserving types.
This helper ensures that middleware types are correctly matched to the Procedure's argument types, avoiding the need for type assertions.
Type Parameters ​
TArgs ​
TArgs extends any[]
TOutput ​
TOutput
Parameters ​
procedure ​
Procedure<(...args) => TOutput>
middleware ​
...(MiddlewarePipeline | Middleware<TArgs>)[]
Returns ​
Procedure<(...args) => TOutput>
Example ​
typescript
const proc = createProcedure({ name: 'test' }, async (input: string) => input);
const middleware: Middleware<[string]>[] = [...];
const procWithMw = applyMiddleware(proc, middleware);
// procWithMw is still Procedure<[string], string> - types preserved!