feat(p5): messaging, push gateway and AI assistant services

P5 阶段交付物:
- services/msg: 消息通知服务(NestJS)
  - notifications: 发送通知 + ES 全文检索 + search
  - config/elasticsearch.ts: ES Client 单例
  - package.json: 补充 @opentelemetry/sdk-node + exporter-trace-otlp-http
- services/push-gateway: WebSocket 推送网关(Go Gin)
  - internal/hub/hub.go: WebSocket 连接池管理(Register/Unregister/SendToUser)
  - internal/ws/handler.go: JWT 鉴权 + WebSocket 升级 + 内部推送 API
- services/ai: AI 辅助服务(Python FastAPI)
  - /chat + /chat/stream(SSE 流式)
  - /generate/question + /optimize/expression
  - config.py: OpenAI 兼容 API 配置
- packages/shared-proto/proto/msg.proto: NotificationService 契约(send/search)
- packages/shared-proto/proto/ai.proto: AiService 契约(含 stream 方法)
This commit is contained in:
SpecialX
2026-07-08 01:39:02 +08:00
parent 9850bfcfd1
commit 7474a92e3b
34 changed files with 1264 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
import { Body, Controller, Get, Param, Post, Query, Req } from '@nestjs/common';
import { NotificationsService } from './notifications.service.js';
import type { SendNotificationDto } from './notifications.service.js';
@Controller('notifications')
export class NotificationsController {
constructor(private readonly service: NotificationsService) {}
@Post()
async send(@Body() body: unknown) {
const result = await this.service.send(body as SendNotificationDto);
return { success: true, data: result };
}
@Get()
async list(@Req() req: { userId: string }, @Query('unread') unread: string) {
const result = await this.service.listByUser(req.userId, unread === 'true');
return { success: true, data: result };
}
@Post(':id/read')
async markAsRead(@Param('id') id: string) {
await this.service.markAsRead(id);
return { success: true };
}
@Get('search')
async search(@Req() req: { userId: string }, @Query('q') q: string) {
const result = await this.service.search(req.userId, q);
return { success: true, data: result };
}
}