@myassis/gateway 1.0.96 → 1.0.97
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/config/index.js
CHANGED
|
@@ -87,6 +87,12 @@ const defaultServerBaseUrl = resolvedNodeEnv === 'production' ? PROD_SERVER_BASE
|
|
|
87
87
|
// 环境变量配置
|
|
88
88
|
exports.appConfig = {
|
|
89
89
|
serverBaseUrl: (process.env.SERVER_BASE_URL || defaultServerBaseUrl).replace(/\/+$/, ''),
|
|
90
|
+
/**
|
|
91
|
+
* Desktop Web 站点地址。会话结束推送到手机 App 的通知点击后打开该地址。
|
|
92
|
+
* 可通过 DESKTOP_WEB_URL 覆盖(私有化部署)。
|
|
93
|
+
*/
|
|
94
|
+
desktopWebUrl: (process.env.DESKTOP_WEB_URL
|
|
95
|
+
|| (resolvedNodeEnv === 'production' ? 'https://web.my-assis.com' : 'http://192.168.1.36:5005')).replace(/\/+$/, ''),
|
|
90
96
|
port: parseInt(process.env.PORT || '3001', 10),
|
|
91
97
|
clientUrl: process.env.CLIENT_URL || 'http://localhost:3000',
|
|
92
98
|
nodeEnv: resolvedNodeEnv,
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* 会话结束消息通知服务
|
|
4
|
+
*
|
|
5
|
+
* Desktop agent 会话结束后,调用 Server 的推送接口向用户手机 App 推送消息。
|
|
6
|
+
* 点击通知会打开 Desktop Web 站点(由 Server / Gateway 配置决定)。
|
|
7
|
+
*
|
|
8
|
+
* 是否真正推送由用户设置 sessionNotificationEnabled 控制(Server 端校验)。
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.sessionNotificationService = void 0;
|
|
12
|
+
const index_js_1 = require("../config/index.js");
|
|
13
|
+
const authStore_js_1 = require("../stores/authStore.js");
|
|
14
|
+
const shared_1 = require("@myassis/shared");
|
|
15
|
+
const logger = (0, shared_1.getLogger)('SessionNotificationService');
|
|
16
|
+
class SessionNotificationService {
|
|
17
|
+
/**
|
|
18
|
+
* 通知 Server 推送「会话已结束」消息到用户手机 App(fire-and-forget)。
|
|
19
|
+
*/
|
|
20
|
+
async notifySessionCompleted(userId, payload) {
|
|
21
|
+
try {
|
|
22
|
+
const auth = authStore_js_1.authStore.get(userId);
|
|
23
|
+
const token = auth?.accessToken;
|
|
24
|
+
if (!token) {
|
|
25
|
+
logger.debug('未找到用户 accessToken,跳过会话结束推送', { userId });
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const response = await fetch(`${index_js_1.appConfig.serverBaseUrl}/api/v1/push-tokens/session-completed`, {
|
|
29
|
+
method: 'POST',
|
|
30
|
+
headers: {
|
|
31
|
+
'Content-Type': 'application/json',
|
|
32
|
+
Authorization: `Bearer ${token}`,
|
|
33
|
+
},
|
|
34
|
+
body: JSON.stringify({
|
|
35
|
+
title: payload.title,
|
|
36
|
+
body: payload.body || '',
|
|
37
|
+
sessionId: payload.sessionId,
|
|
38
|
+
agentId: payload.agentId,
|
|
39
|
+
url: index_js_1.appConfig.desktopWebUrl,
|
|
40
|
+
}),
|
|
41
|
+
});
|
|
42
|
+
if (!response.ok) {
|
|
43
|
+
const text = await response.text().catch(() => '');
|
|
44
|
+
logger.warn('会话结束推送接口返回异常', { status: response.status, body: text });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
logger.error('会话结束推送请求失败', { error: error?.message });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.sessionNotificationService = new SessionNotificationService();
|
|
@@ -38,6 +38,7 @@ const MemoryManager_js_1 = require("../memory/MemoryManager.js");
|
|
|
38
38
|
const index_js_2 = require("../../config/index.js");
|
|
39
39
|
const ContextBuilder_js_1 = require("../memory/ContextBuilder.js");
|
|
40
40
|
const SessionManager_js_1 = require("./SessionManager.js");
|
|
41
|
+
const SessionNotificationService_js_1 = require("../SessionNotificationService.js");
|
|
41
42
|
const logger = (0, shared_1.getLogger)('Session');
|
|
42
43
|
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
43
44
|
/**
|
|
@@ -1458,8 +1459,10 @@ class Session {
|
|
|
1458
1459
|
return llmResult.content;
|
|
1459
1460
|
}
|
|
1460
1461
|
};
|
|
1462
|
+
let completedContent;
|
|
1461
1463
|
try {
|
|
1462
1464
|
const result = await processModelResponse();
|
|
1465
|
+
completedContent = result;
|
|
1463
1466
|
return { success: true, data: result };
|
|
1464
1467
|
}
|
|
1465
1468
|
catch (error) {
|
|
@@ -1507,6 +1510,10 @@ class Session {
|
|
|
1507
1510
|
// 后台预压缩:本轮已结束,提前生成摘要让下一轮直接命中,降低首字延迟。
|
|
1508
1511
|
// 延迟启动是为了给用户的连续追问让路(追问会取消它)。
|
|
1509
1512
|
this.schedulePrecompression();
|
|
1513
|
+
// 会话正常结束:按用户设置推送消息到手机 App
|
|
1514
|
+
if (completedContent !== undefined) {
|
|
1515
|
+
void this.sendSessionCompletedNotification(completedContent);
|
|
1516
|
+
}
|
|
1510
1517
|
}
|
|
1511
1518
|
}
|
|
1512
1519
|
}
|
|
@@ -1595,6 +1602,34 @@ class Session {
|
|
|
1595
1602
|
logger.error('推送会话停止事件失败:', error);
|
|
1596
1603
|
}
|
|
1597
1604
|
}
|
|
1605
|
+
/**
|
|
1606
|
+
* 会话正常结束后,推送消息通知到用户手机 App。
|
|
1607
|
+
* 具体是否推送由 Server 根据用户设置 sessionNotificationEnabled 决定。
|
|
1608
|
+
*/
|
|
1609
|
+
sendSessionCompletedNotification(content) {
|
|
1610
|
+
try {
|
|
1611
|
+
let title = this.title;
|
|
1612
|
+
if (this.agentId) {
|
|
1613
|
+
const agent = getAgentStore().findById(this.agentId);
|
|
1614
|
+
if (agent?.name)
|
|
1615
|
+
title = agent.name;
|
|
1616
|
+
}
|
|
1617
|
+
const snippet = (content || '')
|
|
1618
|
+
.replace(/[\r\n]+/g, ' ')
|
|
1619
|
+
.replace(/[#*`>\[\]]/g, '')
|
|
1620
|
+
.trim()
|
|
1621
|
+
.slice(0, 80);
|
|
1622
|
+
void SessionNotificationService_js_1.sessionNotificationService.notifySessionCompleted(String(this.userId), {
|
|
1623
|
+
title,
|
|
1624
|
+
body: snippet,
|
|
1625
|
+
sessionId: this.id,
|
|
1626
|
+
agentId: this.agentId,
|
|
1627
|
+
});
|
|
1628
|
+
}
|
|
1629
|
+
catch (error) {
|
|
1630
|
+
logger.error('发送会话结束通知失败:', error);
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1598
1633
|
/**
|
|
1599
1634
|
* 获取 AbortController 用于中断请求
|
|
1600
1635
|
*/
|