@myassis/gateway 1.0.31 → 1.0.32

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.
@@ -12,6 +12,13 @@ const DEFAULT_CONFIG = {
12
12
  summaryThreshold: 10,
13
13
  enabled: true,
14
14
  };
15
+ /** SSE 辅助方法:res 为 null 时跳过写入(本地执行模式) */
16
+ const sendSSE = (res, data) => {
17
+ if (!res)
18
+ return;
19
+ res.write(`data: ${JSON.stringify(data)}\n\n`);
20
+ res.flush?.();
21
+ };
15
22
  /**
16
23
  * 记忆管理器
17
24
  * 实现总结式记忆:当对话超过一定长度时,自动生成对话摘要
@@ -21,10 +28,12 @@ class MemoryManager {
21
28
  signal;
22
29
  config = DEFAULT_CONFIG;
23
30
  childAgent;
24
- constructor(session, signal, childAgent) {
31
+ res;
32
+ constructor(session, signal, childAgent, res = null) {
25
33
  this.session = session;
26
34
  this.signal = signal;
27
35
  this.childAgent = childAgent;
36
+ this.res = res;
28
37
  }
29
38
  toSummaryMessage(summary, createdAt, modelName) {
30
39
  return {
@@ -184,6 +193,10 @@ ${conversation}
184
193
  * 生成对话摘要(支持分层摘要)
185
194
  */
186
195
  async generateSummaryAsync(messages, lastSummary) {
196
+ // 非 childAgent 会话通知 Desktop 显示"上下文压缩中"
197
+ if (!this.childAgent) {
198
+ sendSSE(this.res, { type: 'context_compressing' });
199
+ }
187
200
  const MAX_INPUT_CHARS = 30000; // 单次摘要最大输入字符数
188
201
  // 格式化所有消息用于估算长度
189
202
  const formattedMessages = messages
@@ -434,7 +434,7 @@ class Session {
434
434
  const settings = await dataService_js_1.settingsService.get(token);
435
435
  const streamDelay = this.getStreamDelay(settings.streamSpeed);
436
436
  this.currentMessageId = assistantMessageId;
437
- const memoryManager = new MemoryManager_js_1.MemoryManager(this, this.abortController.signal, childAgent);
437
+ const memoryManager = new MemoryManager_js_1.MemoryManager(this, this.abortController.signal, childAgent, res);
438
438
  const historyMessages = await memoryManager.getHistoryMessagesAsync();
439
439
  // SSE 辅助方法:res 为 null 时跳过写入(本地执行模式)
440
440
  const sendSSE = (res, data) => {
@@ -33,10 +33,11 @@ const model_js_1 = require("./model.js");
33
33
  const edit_js_1 = require("./edit.js");
34
34
  const webFetch_js_1 = require("./webFetch.js");
35
35
  const sessionsSpawn_js_1 = require("./sessionsSpawn.js");
36
+ const setSessionTitle_js_1 = require("./setSessionTitle.js");
36
37
  exports.tools = [
37
38
  search_js_1.searchTool, calculator_js_1.calculatorTool, screenshot_js_1.screenshotTool, keyboard_js_1.keyboardTool, mouse_js_1.mouseTool,
38
39
  skill_js_1.skillTool, exec_js_1.execTool, task_js_1.taskTool, model_js_1.modelTool, fetch_js_1.fetchTool,
39
- edit_js_1.editTool, webFetch_js_1.webFetchTool, file_js_1.fileTool, sessionsSpawn_js_1.sessionsSpawnTool
40
+ edit_js_1.editTool, webFetch_js_1.webFetchTool, file_js_1.fileTool, sessionsSpawn_js_1.sessionsSpawnTool, setSessionTitle_js_1.setSessionTitleTool
40
41
  ];
41
42
  function getToolByName(name) {
42
43
  return exports.tools.find(tool => tool.name === name);
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setSessionTitleTool = void 0;
4
+ const AgentManager_js_1 = require("../agent/AgentManager.js");
5
+ const WebSocketService_js_1 = require("../WebSocketService.js");
6
+ exports.setSessionTitleTool = {
7
+ name: 'setSessionTitle',
8
+ description: '修改当前会话的标题。调用此工具后,Desktop 端侧边栏的会话名称会立即更新为新标题。',
9
+ parameters: {
10
+ type: 'object',
11
+ properties: {
12
+ title: {
13
+ type: 'string',
14
+ description: '新的会话标题,建议简洁准确,长度不超过 50 字符',
15
+ },
16
+ },
17
+ required: ['title'],
18
+ },
19
+ handler: async (args, sessionId, _messageId, userId) => {
20
+ try {
21
+ const { title } = args;
22
+ if (!title || typeof title !== 'string' || title.trim().length === 0) {
23
+ return { success: false, errorMessage: '会话标题不能为空' };
24
+ }
25
+ if (!sessionId) {
26
+ return { success: false, errorMessage: '无当前会话,无法修改标题' };
27
+ }
28
+ if (!userId) {
29
+ return { success: false, errorMessage: '未登录' };
30
+ }
31
+ const manager = AgentManager_js_1.agentManagerMap.get(String(userId));
32
+ if (!manager) {
33
+ return { success: false, errorMessage: '无法获取会话管理器' };
34
+ }
35
+ // 找到该 session 所属的 agent
36
+ let targetAgent = null;
37
+ for (const agentInfo of manager.getAgentList()) {
38
+ const agent = manager.getAgent(agentInfo.id);
39
+ const found = agent?.getSessions().find(s => s.id === sessionId);
40
+ if (found) {
41
+ targetAgent = agent;
42
+ break;
43
+ }
44
+ }
45
+ if (!targetAgent) {
46
+ return { success: false, errorMessage: '会话不存在' };
47
+ }
48
+ const updated = targetAgent.updateSession(sessionId, { title: title.trim() });
49
+ if (!updated) {
50
+ return { success: false, errorMessage: '更新会话标题失败' };
51
+ }
52
+ // 推送 session_updated 到 Desktop,触发 UI 刷新
53
+ WebSocketService_js_1.webSocketService.sendToUser(String(userId), {
54
+ type: 'session_updated',
55
+ payload: {
56
+ sessionId,
57
+ agentId: targetAgent.id,
58
+ title: title.trim(),
59
+ updatedAt: updated.updatedAt,
60
+ },
61
+ });
62
+ return {
63
+ success: true,
64
+ output: JSON.stringify({
65
+ sessionId,
66
+ title: title.trim(),
67
+ updatedAt: updated.updatedAt,
68
+ }),
69
+ };
70
+ }
71
+ catch (error) {
72
+ return { success: false, errorMessage: `修改会话标题失败: ${error?.message}` };
73
+ }
74
+ },
75
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myassis/gateway",
3
- "version": "1.0.31",
3
+ "version": "1.0.32",
4
4
  "description": "我的助手 Gateway Service - 本地 AI 网关服务,支持认证、WebSocket 实时通信和任务调度",
5
5
  "main": "dist/index.js",
6
6
  "bin": {