MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / MiddlewarePipeline

Class MiddlewarePipeline

ai/ai.ts:2358–2386  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2356
2357class MiddlewarePipeline {
2358 private middlewares: Middleware[] = [];
2359
2360 use(middleware: Middleware): void {
2361 this.middlewares.push(middleware);
2362 }
2363
2364 async execute<T>(
2365 input: T,
2366 finalHandler: (input: T, token?: AbortToken) => Promise<any>,
2367 token?: AbortToken,
2368 ): Promise<any> {
2369 const exec = async (
2370 idx: number,
2371 curInput: T,
2372 curToken?: AbortToken,
2373 ): Promise<any> => {
2374 if (idx >= this.middlewares.length)
2375 return await finalHandler(curInput, curToken);
2376 const mw = this.middlewares[idx];
2377 return await mw.process(
2378 curInput,
2379 (nextInput, nextToken) => exec(idx + 1, nextInput, nextToken),
2380 curToken,
2381 );
2382 };
2383 return await exec(0, input, token);
2384 }
2385}
2386
2387class TimeoutMiddleware implements Middleware {
2388 private configManagerPromise: Promise<ConfigManager>;
2389

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected