99 lines
3.1 KiB
TypeScript
99 lines
3.1 KiB
TypeScript
import { Body, Controller, Get, Headers, Inject, Post, Query, Res } from '@nestjs/common';
|
|
import type { Response } from 'express';
|
|
import { ok } from '../common/api-response.js';
|
|
import { actorFromHeaders } from '../common/auth-context.js';
|
|
import { ChatAskInput, ChatConnectionInput, ChatDefaultModelInput, ChatService } from './chat.service.js';
|
|
|
|
@Controller('api/v1/chat')
|
|
export class ChatController {
|
|
constructor(@Inject(ChatService) private readonly svc: ChatService) {}
|
|
|
|
@Post('ask')
|
|
ask(@Headers() headers: Record<string, string | string[] | undefined>, @Body() body: ChatAskInput) {
|
|
return ok(this.svc.ask(body, actorFromHeaders(headers)));
|
|
}
|
|
|
|
@Post('ask/stream')
|
|
askStream(
|
|
@Headers() headers: Record<string, string | string[] | undefined>,
|
|
@Body() body: ChatAskInput,
|
|
@Res() res: Response,
|
|
) {
|
|
this.svc.streamAsk(body, actorFromHeaders(headers), res);
|
|
}
|
|
|
|
@Get('audit/verify')
|
|
verifyAudit() {
|
|
return ok(this.svc.verifyAudit());
|
|
}
|
|
|
|
@Get('history')
|
|
history(
|
|
@Headers() headers: Record<string, string | string[] | undefined>,
|
|
@Query('chatId') chatId?: string,
|
|
@Query('limit') limit?: string,
|
|
) {
|
|
return ok(this.svc.history(actorFromHeaders(headers), chatId || '', Number(limit ?? 50)));
|
|
}
|
|
|
|
@Get('replay')
|
|
replay(@Query('chatId') chatId?: string, @Query('turnId') turnId?: string, @Query('tenant') tenant?: string) {
|
|
return ok(this.svc.replay(chatId || '', turnId || '', tenant || ''));
|
|
}
|
|
|
|
@Get('actions')
|
|
actions(@Headers() headers: Record<string, string | string[] | undefined>) {
|
|
return ok(this.svc.listActions(actorFromHeaders(headers)));
|
|
}
|
|
|
|
@Get('agents')
|
|
agents(@Headers() headers: Record<string, string | string[] | undefined>) {
|
|
return ok(this.svc.listAgents(actorFromHeaders(headers)));
|
|
}
|
|
|
|
@Get('models')
|
|
models(
|
|
@Headers() headers: Record<string, string | string[] | undefined>,
|
|
@Query('modelRole') modelRole?: string,
|
|
) {
|
|
return ok(this.svc.listModels(actorFromHeaders(headers), modelRole || 'read_only'));
|
|
}
|
|
|
|
@Get('connections')
|
|
connections(@Headers() headers: Record<string, string | string[] | undefined>) {
|
|
return ok(this.svc.connections(actorFromHeaders(headers)));
|
|
}
|
|
|
|
@Post('connections/connect')
|
|
connect(
|
|
@Headers() headers: Record<string, string | string[] | undefined>,
|
|
@Body() body: ChatConnectionInput,
|
|
) {
|
|
return ok(this.svc.connectProvider(body, actorFromHeaders(headers)));
|
|
}
|
|
|
|
@Post('connections/refresh')
|
|
refreshConnection(
|
|
@Headers() headers: Record<string, string | string[] | undefined>,
|
|
@Body() body: { provider: string },
|
|
) {
|
|
return ok(this.svc.refreshProvider(body.provider, actorFromHeaders(headers)));
|
|
}
|
|
|
|
@Post('connections/default')
|
|
defaultModel(
|
|
@Headers() headers: Record<string, string | string[] | undefined>,
|
|
@Body() body: ChatDefaultModelInput,
|
|
) {
|
|
return ok(this.svc.setDefaultModel(body, actorFromHeaders(headers)));
|
|
}
|
|
|
|
@Post('connections/disconnect')
|
|
disconnect(
|
|
@Headers() headers: Record<string, string | string[] | undefined>,
|
|
@Body() body: { provider: string },
|
|
) {
|
|
return ok(this.svc.disconnectProvider(body.provider, actorFromHeaders(headers)));
|
|
}
|
|
}
|