diff --git a/backend/src/agent-ws.ts b/backend/src/agent-ws.ts index 0b08774..7531310 100644 --- a/backend/src/agent-ws.ts +++ b/backend/src/agent-ws.ts @@ -4,6 +4,7 @@ * и остаются подключёнными для получения команд */ import { FastifyInstance } from 'fastify' +import type { SocketStream } from '@fastify/websocket' import { WebSocket } from 'ws' import { db } from './db' @@ -71,7 +72,9 @@ async function markOnline(workstationId: string, ip?: string) { // Регистрируем route для WebSocket агентов export function setupAgentWsRoute(fastify: FastifyInstance) { - fastify.get('/ws/agent', { websocket: true }, async (socket: AgentSocket, req) => { + fastify.get('/ws/agent', { websocket: true }, async (connection: SocketStream, req) => { + const socket = connection.socket as AgentSocket + // Аутентификация по токену из заголовка try { const authHeader = req.headers.authorization ?? '' @@ -112,7 +115,6 @@ export function setupAgentWsRoute(fastify: FastifyInstance) { // Обрабатываем ответы агента (результаты команд) if (msg.type === 'result') { fastify.log.info({ workstation: wsId, result: msg }, 'Agent command result') - // TODO: можно эмитить в EventEmitter для ожидающих промисов } if (msg.type === 'hello') { console.log(`[agent-ws] Hello from ${msg.agent_id} (${wsId})`) diff --git a/backend/src/routes/workstations.ts b/backend/src/routes/workstations.ts index 6dd6fdd..78fbeec 100644 --- a/backend/src/routes/workstations.ts +++ b/backend/src/routes/workstations.ts @@ -173,7 +173,8 @@ const workstationRoutes: FastifyPluginAsync = async (fastify) => { ) // Выдаём токен агенту (подписываем как обычный JWT с role=agent) - const token = fastify.jwt.sign( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const token = (fastify.jwt.sign as any)( { sub: agent_id, role: 'agent', diff --git a/backend/src/types.ts b/backend/src/types.ts index 8b7d24b..01d8f7d 100644 --- a/backend/src/types.ts +++ b/backend/src/types.ts @@ -2,7 +2,7 @@ export interface JwtPayload { sub: string // user.id (UUID) email: string name: string - role: 'hotel_admin' | 'manager' | 'housekeeper' | 'super_admin' | 'receptionist' | 'accountant' | 'security' | 'technician' + role: 'hotel_admin' | 'manager' | 'housekeeper' | 'super_admin' | 'receptionist' | 'accountant' | 'security' | 'technician' | 'agent' hotelId: string | null hotelSlug: string | null }