aidk-nestjs
v0.1.8
Published
NestJS module for AIDK
Readme
aidk-nestjs
NestJS integration for AIDK.
Installation
pnpm add aidk-nestjs aidk @nestjs/common @nestjs/core rxjsUsage
Basic Setup
// app.module.ts
import { Module } from '@nestjs/common';
import { EngineModule } from 'aidk-nestjs';
import { createEngine } from 'aidk';
@Module({
imports: [
EngineModule.forRoot({
engine: createEngine(),
}),
],
})
export class AppModule {}Controller with Streaming
// agent.controller.ts
import { Controller, Post, Body, Res } from '@nestjs/common';
import { Response } from 'express';
import { Stream } from 'aidk-nestjs';
import { EngineInput } from 'aidk';
import { TaskAssistant } from './agents/task-assistant';
@Controller('api/run')
export class RunController {
@Post('stream')
@Stream(<TaskAssistant />)
async stream(@Body() input: EngineInput, @Res() res: Response) {
// Handler will be wrapped by interceptor
return input;
}
}Using SSE Transport
// agent.controller.ts
import { Controller, Get, Query, Res } from '@nestjs/common';
import { Response } from 'express';
import { SSETransport } from 'aidk-nestjs';
@Controller('api/stream')
export class StreamController {
private transport = new SSETransport({ debug: true });
@Get('sse')
async sse(@Query('connectionId') connectionId: string, @Res() res: Response) {
await this.transport.connect(connectionId, {
res,
metadata: {
userId: 'user-123',
threadId: 'thread-456',
},
});
}
}Key Exports
EngineModule- NestJS module for engine integrationStream()- Decorator for streaming executionExecute()- Decorator for non-streaming executionEngineContextInterceptor- Interceptor that sets up execution contextEngineContextGuard- Guard that verifies context is availableSSETransport- SSE transport for real-time communication
Documentation
See the full documentation.
