Skip to content

AIDK API Reference / aidk-express / withEngine

Function: withEngine() ​

ts
function withEngine<TBody>(config: ExpressEngineConfig<TBody>): (req: Request, res: Response, next: NextFunction) => void;

Defined in: packages/express/src/middleware/engine.ts:116

Creates middleware that extracts execution context from the request.

Type Parameters ​

Type ParameterDefault type
TBodyany

Parameters ​

ParameterTypeDescription
configExpressEngineConfig<TBody>Configuration for context extraction

Returns ​

Express middleware

ts
(
   req: Request, 
   res: Response, 
   next: NextFunction): void;

Parameters ​

ParameterType
reqRequest
resResponse
nextNextFunction

Returns ​

void

Example ​

typescript
app.use(withEngine({ engine: getEngine() }));

// In handler:
router.post('/execute', (req: EngineRequest, res) => {
  const { engine, input, executionId } = req.engineContext;
  const result = await engine.execute.withContext(req.engineContext.withContext)(
    input,
    <MyWorkflow />
  );
});

Released under the MIT License.