fake-hermes.mjs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. import { createServer } from 'node:http'
  2. import WebSocket, { WebSocketServer } from 'ws'
  3. const port = Number(process.env.FAKE_HERMES_PORT || 19119)
  4. const epoch = '11111111-1111-4111-8111-111111111111'
  5. const roomId = '22222222-2222-4222-8222-222222222222'
  6. const agentId = '33333333-3333-4333-8333-333333333333'
  7. const secondAgentId = '34343434-3434-4434-8434-343434343434'
  8. const topicId = '77777777-7777-4777-8777-777777777777'
  9. const releaseTopicId = '88888888-8888-4888-8888-888888888888'
  10. const now = () => Date.now() / 1000
  11. let groupCursor = 0
  12. const groupClients = new Set()
  13. let groupConnectionCount = 0
  14. let groupAvailable = true
  15. function broadcastGroup(event, payload) {
  16. groupCursor += 1
  17. const frame = JSON.stringify({ type: 'group.event', epoch, cursor: groupCursor, roomId, event, payload })
  18. for (const client of groupClients) if (client.readyState === WebSocket.OPEN) client.send(frame)
  19. }
  20. function authenticated(request) {
  21. return String(request.headers.cookie || '').includes('fake_session=authenticated')
  22. }
  23. function json(response, status, value, headers = {}) {
  24. const body = Buffer.from(JSON.stringify(value))
  25. response.writeHead(status, {
  26. 'Content-Type': 'application/json',
  27. 'Content-Length': body.length,
  28. ...headers,
  29. })
  30. response.end(body)
  31. }
  32. async function body(request) {
  33. const chunks = []
  34. for await (const chunk of request) chunks.push(Buffer.from(chunk))
  35. if (!chunks.length) return {}
  36. return JSON.parse(Buffer.concat(chunks).toString('utf8'))
  37. }
  38. const profiles = [
  39. { name: 'yaoyao', description: '夭夭', is_default: true, model: 'gpt-5.6', provider: 'openai', gateway_running: true },
  40. { name: 'yaoer', description: '瑶儿', is_default: false, model: 'gpt-5.6', provider: 'openai', gateway_running: true },
  41. ]
  42. // This intentionally differs from local timestamp/pin ranking. Browser tests
  43. // verify that the WebUI preserves the ordering returned by 9119.
  44. const sessions = [
  45. { id: 'session-second', profile: 'yaoyao', source: 'web', title: '第二个会话', preview: '用于验证列表和切换', message_count: 2, tool_call_count: 0, started_at: now() - 7200, last_active_at: now() - 600, model: 'gpt-5.5', provider: 'openai' },
  46. { id: 'session-demo', profile: 'yaoyao', source: 'web', title: '夭夭 Web 验收会话', preview: '文件库与群聊已经就绪', message_count: 4, tool_call_count: 1, started_at: now() - 3600, last_active_at: now(), pinned: true, model: 'gpt-5.6', provider: 'openai' },
  47. { id: 'session-yaoer', profile: 'yaoer', source: 'web', title: '瑶儿专属会话', message_count: 1, tool_call_count: 0, started_at: now() - 3500, last_active_at: now() - 20, model: 'gpt-5.6', provider: 'openai' },
  48. ...Array.from({ length: 101 }, (_, index) => ({ id: `session-page-${index + 1}`, profile: 'yaoyao', source: 'web', title: `分页会话 ${index + 1}`, message_count: 0, tool_call_count: 0, started_at: now() - 10_000 - index, last_active_at: now() - 10_000 - index })),
  49. ]
  50. const messages = [
  51. { id: 'message-user', role: 'user', content: '请检查今天生成的产物。MEDIA:/brand/AppIcon-1024.png', timestamp: now() - 180 },
  52. { id: 'message-user-file', role: 'user', content: '查看附件\n\n[用户附加文件:测试报告.docx]\n@file:`attachments/测试报告.docx`', timestamp: now() - 179 },
  53. { id: 'message-user-image', role: 'user', content: '[用户附加图片:测试图片.png]\n@image:/Users/samien/.hermes/images/upload_test.png\n[screenshot]', timestamp: now() - 178 },
  54. { id: 'message-thinking-tool', role: 'assistant', content: '', reasoning_content: '先检索文件,再归纳结果。', tool_calls: [{ id: 'tool-thinking', type: 'function', function: { name: 'file_search', arguments: '{"query":"产物"}' } }], timestamp: now() - 177 },
  55. { id: 'message-tool-call', role: 'assistant', content: '', tool_calls: [{ id: 'tool-1', type: 'function', function: { name: 'file_search', arguments: '{"query":"产物"}' } }], timestamp: now() - 176 },
  56. { id: 'message-tool', role: 'tool', tool_name: 'file_search', tool_call_id: 'tool-1', summary: '扫描产物目录', result: { path: '/tmp/demo-report.pdf', count: 1 }, timestamp: now() - 175 },
  57. { id: 'message-assistant', role: 'assistant', content: '已整理完成。下面是 **验收摘要**:\n\n## 验收摘要\n\n- 普通聊天已连接\n- 群聊 v4 已就绪\n- [打开报告](https://example.com/report)', reasoning_content: '先核对会话与文件索引。', timestamp: now() - 170 },
  58. { id: 'message-image', role: 'assistant', content: '预览图:![夭夭 Logo](/brand/AppIcon-1024.png)', timestamp: now() - 160 },
  59. { id: 'message-image-second', role: 'assistant', content: '第二张:![夭夭 Logo 2](/brand/AppIcon-1024.png?variant=2)', timestamp: now() - 155 },
  60. { id: 'message-legacy-media', role: 'assistant', content: '历史兼容:MEDIA:/brand/AppIcon-1024.png', timestamp: now() - 150 },
  61. { id: 'message-local-link', role: 'assistant', content: '[方案草稿.md](/Users/samien/Agents/方案草稿.md)', timestamp: now() - 145 },
  62. { id: 'message-compaction', role: 'user', content: '[CONTEXT COMPACTION — REFERENCE ONLY]\n\n## Historical Task Snapshot\n\n- 已完成普通聊天验收\n- 保留当前会话上下文', timestamp: now() - 143 },
  63. { id: 'message-delegation', role: 'user', content: '[ASYNC DELEGATION BATCH COMPLETE]\n后台子任务已经完成。', display_kind: 'async_delegation_complete', display_metadata: { task_count: 2, completed_count: 2, failed_count: 0, duration_seconds: 71 }, timestamp: now() - 140 },
  64. { id: 'message-system', role: 'user', content: '[System: The active model for this chat has changed to gpt-5.6-terra via provider openai.]', timestamp: now() - 130 },
  65. ]
  66. const groupAgent = { id: agentId, roomId, profile: 'yaoyao', displayName: '夭夭', description: '主 Agent', enabled: true, replyWithoutMention: true, isHost: true, model: 'gpt-5.6', provider: 'openai', reasoningEffort: 'high', fastMode: true, status: 'idle', createdAt: now() - 2000, updatedAt: now() }
  67. const secondGroupAgent = { id: secondAgentId, roomId, profile: 'yaoer', displayName: '瑶儿', description: '评审 Agent', enabled: true, replyWithoutMention: false, isHost: false, model: 'gpt-5.6', provider: 'openai', reasoningEffort: 'medium', fastMode: false, status: 'idle', createdAt: now() - 1900, updatedAt: now() }
  68. const groupAgents = [groupAgent, secondGroupAgent]
  69. const groupMessage = { seq: 1, id: '44444444-4444-4444-8444-444444444444', roomId, topicId, senderKind: 'human', senderId: 'demo-user', senderName: '验收用户', content: '大家好,检查一下群聊输入框。', status: 'completed', createdAt: now() - 120, updatedAt: now() - 120 }
  70. const groupAssistantMessage = { seq: 2, id: '55555555-5555-4555-8555-555555555555', roomId, topicId, senderKind: 'agent', senderId: agentId, senderName: '夭夭', content: '历史兼容:MEDIA:/brand/AppIcon-1024.png', status: 'completed', createdAt: now() - 100, updatedAt: now() - 100 }
  71. const releaseTopicMessage = { seq: 3, id: '99999999-9999-4999-8999-999999999999', roomId, topicId: releaseTopicId, senderKind: 'human', senderId: 'demo-user', senderName: '验收用户', content: '请核对发布话题的独立历史。', status: 'completed', createdAt: now() - 500, updatedAt: now() - 500 }
  72. const groupMessages = [groupMessage, groupAssistantMessage, releaseTopicMessage]
  73. const groupTopics = [
  74. { id: topicId, roomId, title: '设计验收', preview: groupAssistantMessage.content, messageCount: 2, createdAt: now() - 120, updatedAt: now() - 100 },
  75. { id: releaseTopicId, roomId, title: '发布检查', preview: releaseTopicMessage.content, messageCount: 1, createdAt: now() - 500, updatedAt: now() - 500 },
  76. ]
  77. let nextGroupSeq = 4
  78. const room = { id: roomId, name: '设计与工程协作', cwd: '/tmp', createdAt: now() - 2000, updatedAt: now(), archived: false, agentCount: groupAgents.length, maxReplyRounds: -1, lastMessage: groupAssistantMessage, unreadCount: 0 }
  79. const rpcRequests = []
  80. const previewPdf = Buffer.from('JVBERi0xLjQKMSAwIG9iago8PC9UeXBlL0NhdGFsb2cvUGFnZXMgMiAwIFI+PgplbmRvYmoKMiAwIG9iago8PC9UeXBlL1BhZ2VzL0tpZHNbMyAwIFJdL0NvdW50IDE+PgplbmRvYmoKMyAwIG9iago8PC9UeXBlL1BhZ2UvUGFyZW50IDIgMCBSL01lZGlhQm94WzAgMCAyMDAgMjAwXT4+CmVuZG9iagp4cmVmCjAgNAowMDAwMDAwMDAwIDY1NTM1IGYgCjAwMDAwMDAwMTAgMDAwMDAgbiAKMDAwMDAwMDA1MyAwMDAwMCBuIAowMDAwMDAwMTA1IDAwMDAwIG4gCnRyYWlsZXIKPDwvU2l6ZSA0L1Jvb3QgMSAwIFI+PgpzdGFydHhyZWYKMTY2CiUlRU9G', 'base64')
  81. const server = createServer(async (request, response) => {
  82. const url = new URL(request.url || '/', `http://${request.headers.host}`)
  83. if (url.pathname === '/__test/group-connections' && request.method === 'GET') return json(response, 200, { count: groupConnectionCount })
  84. if (url.pathname === '/__test/groups/availability' && request.method === 'POST') {
  85. groupAvailable = (await body(request)).available !== false
  86. return json(response, 200, { available: groupAvailable })
  87. }
  88. if (url.pathname === '/__test/groups/disconnect' && request.method === 'POST') {
  89. for (const client of groupClients) client.terminate()
  90. return json(response, 200, { ok: true })
  91. }
  92. if (url.pathname === '/__test/rpc-requests' && request.method === 'GET') return json(response, 200, { requests: rpcRequests })
  93. if (url.pathname === '/__test/rpc-requests/reset' && request.method === 'POST') {
  94. rpcRequests.length = 0
  95. return json(response, 200, { ok: true })
  96. }
  97. if (url.pathname === '/api/status') return json(response, 200, { version: 'test', overall: 'ok', auth_required: true, auth_providers: ['basic'], gateway_running: true, gateway_state: 'running' })
  98. if (url.pathname === '/api/auth/providers') return json(response, 200, { providers: [{ name: 'basic', display_name: '账号密码', supports_password: true }] })
  99. if (url.pathname === '/auth/password-login' && request.method === 'POST') {
  100. const input = await body(request)
  101. if (input.username !== 'test' || input.password !== 'test') return json(response, 401, { detail: 'Invalid credentials' })
  102. return json(response, 200, { ok: true, next: '' }, { 'Set-Cookie': 'fake_session=authenticated; Path=/; HttpOnly; SameSite=Lax' })
  103. }
  104. if (url.pathname === '/auth/logout' && request.method === 'POST') return json(response, 200, { ok: true }, { 'Set-Cookie': 'fake_session=; Path=/; Max-Age=0; HttpOnly; SameSite=Lax' })
  105. if (!authenticated(request)) return json(response, 401, { detail: 'Unauthorized' })
  106. if (url.pathname.startsWith('/api/plugins/yaoyao/v1/') && !groupAvailable) return json(response, 503, { detail: 'Group service temporarily unavailable' })
  107. if (url.pathname === '/api/auth/me') return json(response, 200, { user_id: 'demo-user', display_name: '验收用户', email: 'demo@example.invalid', provider: 'basic' })
  108. if (url.pathname === '/api/auth/ws-ticket' && request.method === 'POST') return json(response, 200, { ticket: 'fake-ticket' })
  109. if (url.pathname === '/api/profiles') return json(response, 200, { profiles })
  110. if (url.pathname === '/api/plugins/yaoyao/profiles') return json(response, 200, { profiles: [
  111. { name: 'yaoyao', label: '夭夭', agentName: '夭夭', isDefault: true },
  112. { name: 'yaoer', label: '瑶儿', agentName: '瑶儿', isDefault: false },
  113. ] })
  114. if (url.pathname === '/api/model/options') return json(response, 200, { model: 'gpt-5.6', provider: 'openai', providers: [{ slug: 'openai', name: 'OpenAI', models: ['gpt-5.6', 'gpt-5.5'] }] })
  115. if (url.pathname === '/api/profiles/sessions' || url.pathname === '/api/sessions') {
  116. const offset = Math.max(0, Number(url.searchParams.get('offset') || 0))
  117. const limit = Math.max(1, Number(url.searchParams.get('limit') || 100))
  118. const scoped = url.searchParams.get('profile') ? sessions.filter(item => item.profile === url.searchParams.get('profile')) : sessions
  119. return json(response, 200, { sessions: scoped.slice(offset, offset + limit), total: scoped.length, offset, limit })
  120. }
  121. if (/^\/api\/sessions\/[^/]+\/messages$/.test(url.pathname)) {
  122. const id = decodeURIComponent(url.pathname.split('/')[3])
  123. const scopedMessages = id === 'session-yaoer' ? [{ id: 'yaoer-history', role: 'assistant', content: '瑶儿历史消息', timestamp: now() - 10 }] : messages
  124. return json(response, 200, { messages: scopedMessages, pagination: { total: scopedMessages.length, returned: scopedMessages.length, limit: 150, hasMore: false } })
  125. }
  126. if (/^\/api\/sessions\/[^/]+$/.test(url.pathname)) {
  127. const id = decodeURIComponent(url.pathname.split('/').at(-1))
  128. const session = sessions.find(item => item.id === id && (!url.searchParams.get('profile') || item.profile === url.searchParams.get('profile')))
  129. if (session && request.method === 'PATCH') {
  130. const input = await body(request)
  131. if (typeof input.pinned === 'boolean') session.pinned = input.pinned
  132. if (typeof input.title === 'string' && input.title.trim()) session.title = input.title.trim()
  133. return json(response, 200, { ok: true, pinned: session.pinned, title: session.title })
  134. }
  135. return session ? json(response, 200, session) : json(response, 404, { detail: 'Not found' })
  136. }
  137. if (url.pathname === '/api/session-unread') return json(response, 200, { items: { 'session-demo': 0 } })
  138. if (url.pathname === '/api/plugins/yaoyao/v1/capabilities') return json(response, 200, { protocolVersion: 7, journalEpoch: epoch, latestCursor: groupCursor, limits: { maxAgentsPerRoom: 8, maxMessageBytes: 65536, maxMessagePageSize: 100, defaultMaxReplyRounds: 3, unlimitedReplyRoundsValue: -1, maxAgentDisplayNameLength: 100 }, eventTypes: ['message.upsert', 'topic.updated', 'run.updated', 'agent.status', 'agent.updated'] })
  139. if (url.pathname === '/api/plugins/yaoyao/v1/rooms') return json(response, 200, { items: [room], nextCursor: null })
  140. if (url.pathname === `/api/plugins/yaoyao/v1/rooms/${roomId}`) return json(response, 200, { ...room, agents: groupAgents, runs: [], pendingInteractions: [], latestCursor: groupCursor })
  141. const agentPatchMatch = new RegExp(`^/api/plugins/yaoyao/v1/rooms/${roomId}/agents/([^/]+)$`).exec(url.pathname)
  142. if (agentPatchMatch && request.method === 'PATCH') {
  143. const target = groupAgents.find(agent => agent.id === decodeURIComponent(agentPatchMatch[1]))
  144. if (!target) return json(response, 404, { detail: 'Agent not found' })
  145. const input = await body(request)
  146. if (input.displayName === '所有人') return json(response, 409, { detail: '成员名称不能使用“所有人”' })
  147. const changed = []
  148. if (input.isHost === true) {
  149. for (const agent of groupAgents) {
  150. if (agent.id !== target.id && agent.isHost) {
  151. agent.isHost = false
  152. agent.updatedAt = now()
  153. changed.push(agent)
  154. }
  155. }
  156. }
  157. for (const key of ['displayName', 'description', 'enabled', 'replyWithoutMention', 'isHost', 'model', 'provider', 'reasoningEffort', 'fastMode']) {
  158. if (Object.prototype.hasOwnProperty.call(input, key)) target[key] = input[key]
  159. }
  160. target.updatedAt = now()
  161. changed.push(target)
  162. json(response, 200, target)
  163. setTimeout(() => {
  164. for (const agent of changed) broadcastGroup('agent.updated', agent)
  165. }, 10)
  166. return
  167. }
  168. if (url.pathname === `/api/plugins/yaoyao/v1/rooms/${roomId}/topics`) {
  169. return json(response, 200, { items: [...groupTopics].sort((a, b) => b.updatedAt - a.updatedAt), nextCursor: null })
  170. }
  171. if (url.pathname === `/api/plugins/yaoyao/v1/rooms/${roomId}/messages` && request.method === 'POST') {
  172. const input = await body(request)
  173. if (typeof input.topicId !== 'string' || !input.topicId) return json(response, 400, { detail: 'topicId is required for group protocol v4' })
  174. const sentAt = now()
  175. const sent = { ...groupMessage, seq: nextGroupSeq++, id: input.clientMessageId, topicId: input.topicId, clientMessageId: input.clientMessageId, content: input.content, createdAt: sentAt, updatedAt: sentAt }
  176. groupMessages.push(sent)
  177. let topic = groupTopics.find(item => item.id === input.topicId)
  178. if (topic) {
  179. topic.preview = sent.content
  180. topic.messageCount = groupMessages.filter(message => message.topicId === input.topicId).length
  181. topic.updatedAt = sentAt
  182. } else {
  183. topic = { id: input.topicId, roomId, title: String(input.content || '').trim().split('\n')[0].slice(0, 40) || '新话题', preview: sent.content, messageCount: 1, createdAt: sentAt, updatedAt: sentAt }
  184. groupTopics.push(topic)
  185. }
  186. room.lastMessage = sent
  187. room.updatedAt = sentAt
  188. const runId = '66666666-6666-4666-8666-666666666666'
  189. const run = { id: runId, roomId, topicId: input.topicId, agentId, triggerMessageId: sent.id, responseMessageId: '', rootMessageId: sent.id, depth: 0, status: 'queued', runtimeSessionId: null, error: '', replyMode: 'automatic', createdAt: sentAt, updatedAt: sentAt }
  190. json(response, 200, { message: sent, runs: [run] })
  191. setTimeout(() => broadcastGroup('message.upsert', sent), 20)
  192. setTimeout(() => broadcastGroup('topic.updated', topic), 30)
  193. setTimeout(() => broadcastGroup('run.updated', { ...run, status: 'queued', updatedAt: now() }), 40)
  194. setTimeout(() => broadcastGroup('agent.status', { roomId, agentId, status: 'queued', runId }), 40)
  195. setTimeout(() => broadcastGroup('run.updated', { ...run, status: 'running', runtimeSessionId: 'group-runtime-demo', updatedAt: now() }), 650)
  196. setTimeout(() => broadcastGroup('agent.status', { roomId, agentId, status: 'running', runId }), 650)
  197. setTimeout(() => broadcastGroup('run.updated', { ...run, status: 'completed', runtimeSessionId: 'group-runtime-demo', updatedAt: now() }), 1800)
  198. setTimeout(() => broadcastGroup('agent.status', { roomId, agentId, status: 'idle', runId: null }), 1800)
  199. return
  200. }
  201. if (url.pathname === `/api/plugins/yaoyao/v1/rooms/${roomId}/messages`) {
  202. const selectedTopicId = url.searchParams.get('topicId')
  203. const items = selectedTopicId ? groupMessages.filter(message => message.topicId === selectedTopicId) : groupMessages
  204. return json(response, 200, { items })
  205. }
  206. if (url.pathname === '/api/plugins/yaoyao/files') return json(response, 200, { items: [{ id: 1, path: '/tmp/demo-report.pdf', name: 'demo-report.pdf', extension: 'pdf', mimeType: 'application/pdf', size: 204800, modifiedAt: now(), exists: true, origins: [{ profile: 'yaoyao', sessionId: 'session-demo', sessionTitle: '夭夭 Web 验收会话', messageId: 'message-assistant', authorKind: 'assistant', authorName: '夭夭', observedAt: now() }] }], nextCursor: null, total: 1 })
  207. if (url.pathname === '/api/plugins/yaoyao/1/download') {
  208. response.writeHead(200, { 'Content-Type': 'application/pdf', 'Content-Length': previewPdf.length })
  209. return response.end(previewPdf)
  210. }
  211. json(response, 404, { detail: `No fake route for ${request.method} ${url.pathname}` })
  212. })
  213. const sockets = new WebSocketServer({ noServer: true })
  214. server.on('upgrade', (request, socket, head) => {
  215. const url = new URL(request.url || '/', `http://${request.headers.host}`)
  216. if (url.searchParams.get('ticket') !== 'fake-ticket') return socket.destroy()
  217. sockets.handleUpgrade(request, socket, head, client => {
  218. if (url.pathname.endsWith('/events')) {
  219. groupConnectionCount += 1
  220. groupClients.add(client)
  221. client.once('close', () => groupClients.delete(client))
  222. client.send(JSON.stringify({ type: 'group.ready', epoch, cursor: groupCursor, heartbeatSeconds: 20 }))
  223. return
  224. }
  225. client.send(JSON.stringify({ jsonrpc: '2.0', method: 'event', params: { type: 'gateway.ready', payload: { capabilities: ['safe_interrupt', 'session_reasoning_config'] } } }))
  226. client.on('message', raw => {
  227. const requestFrame = JSON.parse(raw.toString())
  228. rpcRequests.push(requestFrame)
  229. const respond = result => client.send(JSON.stringify({ jsonrpc: '2.0', id: requestFrame.id, result }))
  230. if (requestFrame.method === 'session.resume') return respond({ session_id: 'runtime-demo', stored_session_id: requestFrame.params.session_id, fast: requestFrame.params.session_id === 'session-yaoer', messages: [] })
  231. if (requestFrame.method === 'session.create') return respond({ session_id: 'runtime-new', stored_session_id: 'session-new', fast: requestFrame.params.fast === true })
  232. if (requestFrame.method === 'session.usage') return respond({ context_used: 12500, context_max: 114688, total: 12500, input: 9000, output: 3500 })
  233. if (requestFrame.method === 'prompt.submit') {
  234. respond({ status: 'accepted' })
  235. setTimeout(() => {
  236. client.send(JSON.stringify({ jsonrpc: '2.0', method: 'event', params: { type: 'message.start', session_id: requestFrame.params.session_id, profile: 'yaoyao', payload: { message_id: 'stream-demo' } } }))
  237. client.send(JSON.stringify({ jsonrpc: '2.0', method: 'event', params: { type: 'message.delta', session_id: requestFrame.params.session_id, profile: 'yaoyao', payload: { message_id: 'stream-demo', delta: '这是来自假 Gateway 的流式回复。' } } }))
  238. client.send(JSON.stringify({ jsonrpc: '2.0', method: 'event', params: { type: 'message.complete', session_id: requestFrame.params.session_id, profile: 'yaoyao', payload: { message_id: 'stream-demo', text: '这是来自假 Gateway 的流式回复。', status: 'complete' } } }))
  239. }, 1200)
  240. return
  241. }
  242. respond({ ok: true })
  243. })
  244. })
  245. })
  246. server.listen(port, '127.0.0.1', () => process.stdout.write(`Fake Hermes listening on 127.0.0.1:${port}\n`))
  247. for (const signal of ['SIGTERM', 'SIGINT']) process.once(signal, () => server.close(() => process.exit(0)))