@myassis/gateway 1.0.19 → 1.0.20

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.
Files changed (66) hide show
  1. package/dist/api/index.js +27 -19
  2. package/dist/cli.js +10 -5
  3. package/dist/config/index.js +34 -11
  4. package/dist/index.js +1 -2
  5. package/dist/main.js +76 -71
  6. package/dist/middleware/auth.js +9 -5
  7. package/dist/middleware/errorHandler.js +9 -4
  8. package/dist/routes/agent.js +39 -37
  9. package/dist/routes/auth.js +32 -30
  10. package/dist/routes/chat.js +7 -5
  11. package/dist/routes/config.js +5 -3
  12. package/dist/routes/models.js +28 -23
  13. package/dist/routes/service.js +29 -24
  14. package/dist/routes/settings.js +26 -21
  15. package/dist/routes/skillHub.js +22 -17
  16. package/dist/routes/skills.js +25 -20
  17. package/dist/routes/tasks.js +24 -19
  18. package/dist/routes/upload.js +24 -17
  19. package/dist/routes/version.js +20 -19
  20. package/dist/services/HMSPushService.js +4 -1
  21. package/dist/services/LocalTaskService.js +12 -9
  22. package/dist/services/NotificationService.js +14 -11
  23. package/dist/services/ServiceManager.js +77 -65
  24. package/dist/services/TaskSchedulerService.js +33 -30
  25. package/dist/services/TaskService.js +27 -24
  26. package/dist/services/WebSocketService.js +14 -11
  27. package/dist/services/agent/Agent.js +13 -9
  28. package/dist/services/agent/AgentManager.js +32 -24
  29. package/dist/services/agent/AgentStore.js +7 -3
  30. package/dist/services/dataService.js +72 -69
  31. package/dist/services/index.js +25 -9
  32. package/dist/services/llm/LLMClient.js +17 -9
  33. package/dist/services/memory/MemoryManager.js +22 -18
  34. package/dist/services/model/ModelCapabilities.js +11 -7
  35. package/dist/services/model/index.js +17 -1
  36. package/dist/services/models.js +5 -1
  37. package/dist/services/session/MigrationManager.js +18 -11
  38. package/dist/services/session/Session.js +33 -29
  39. package/dist/services/session/SessionManager.js +26 -21
  40. package/dist/services/session/SessionStore.js +32 -25
  41. package/dist/services/session/index.js +8 -2
  42. package/dist/services/skills.js +4 -1
  43. package/dist/services/systemPrompt.js +23 -16
  44. package/dist/services/task/PushTokenStore.js +9 -5
  45. package/dist/services/task/TaskStore.js +10 -6
  46. package/dist/services/tools/calculator.js +4 -1
  47. package/dist/services/tools/edit.js +16 -10
  48. package/dist/services/tools/exec.js +25 -16
  49. package/dist/services/tools/fetch.js +30 -4
  50. package/dist/services/tools/file.js +41 -35
  51. package/dist/services/tools/index.js +44 -24
  52. package/dist/services/tools/keyboard.js +41 -38
  53. package/dist/services/tools/model.js +12 -9
  54. package/dist/services/tools/mouse.js +12 -9
  55. package/dist/services/tools/screenshot.js +9 -3
  56. package/dist/services/tools/search.js +34 -4
  57. package/dist/services/tools/sessionsSpawn.js +11 -8
  58. package/dist/services/tools/skill.js +19 -16
  59. package/dist/services/tools/task.js +12 -9
  60. package/dist/services/tools/types.js +2 -1
  61. package/dist/services/tools/webFetch.js +34 -4
  62. package/dist/stores/authStore.js +25 -19
  63. package/dist/stores/index.js +9 -3
  64. package/dist/stores/memoryStore.js +5 -2
  65. package/dist/stores/persistStore.js +20 -14
  66. package/package.json +11 -20
@@ -1,15 +1,18 @@
1
+ "use strict";
1
2
  /**
2
3
  * Gateway 任务调度服务
3
4
  * 基于 SQLite 数据库的任务调度
4
5
  * 每分钟检查待执行任务并发送通知
5
6
  */
6
- import { taskStore } from './task/TaskStore.js';
7
- import { webSocketService } from './WebSocketService.js';
8
- import { getSessionManager } from './session/index.js';
9
- import { getLogger, getUTCTimeKey, formatUTCForLog, holidayService } from '@myassis/shared';
10
- import { tasksService } from './dataService.js';
11
- import { authStore } from '../stores/authStore.js';
12
- const logger = getLogger('TaskSchedulerService');
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.taskSchedulerService = void 0;
9
+ const TaskStore_js_1 = require("./task/TaskStore.js");
10
+ const WebSocketService_js_1 = require("./WebSocketService.js");
11
+ const index_js_1 = require("./session/index.js");
12
+ const shared_1 = require("@myassis/shared");
13
+ const dataService_js_1 = require("./dataService.js");
14
+ const authStore_js_1 = require("../stores/authStore.js");
15
+ const logger = (0, shared_1.getLogger)('TaskSchedulerService');
13
16
  const EXPIRED_THRESHOLD = 60 * 60 * 1000; // 1小时
14
17
  const CHECK_INTERVAL = 60 * 1000; // 1分钟
15
18
  class TaskSchedulerService {
@@ -55,7 +58,7 @@ class TaskSchedulerService {
55
58
  */
56
59
  async preloadHolidayData() {
57
60
  try {
58
- await holidayService.preloadYears([new Date().getFullYear()]);
61
+ await shared_1.holidayService.preloadYears([new Date().getFullYear()]);
59
62
  logger.info('Holiday data preloaded');
60
63
  }
61
64
  catch (error) {
@@ -66,11 +69,11 @@ class TaskSchedulerService {
66
69
  try {
67
70
  const now = Date.now();
68
71
  const nowBeforeHour = now - EXPIRED_THRESHOLD;
69
- const authMap = authStore.getAll();
72
+ const authMap = authStore_js_1.authStore.getAll();
70
73
  if (!authMap) {
71
74
  return;
72
75
  }
73
- const response = await Promise.all(Array.from(authMap.values()).map(x => tasksService.list(x.user.id)));
76
+ const response = await Promise.all(Array.from(authMap.values()).map(x => dataService_js_1.tasksService.list(x.user.id)));
74
77
  if (response.some(x => !x.success)) {
75
78
  logger.error('获取任务失败');
76
79
  return;
@@ -79,7 +82,7 @@ class TaskSchedulerService {
79
82
  const tasks = response.flatMap(x => x.data).filter(x => x.scheduledAt < nowBeforeHour && x.status !== 'completed' && x.status !== 'expired' && x.status !== 'error');
80
83
  if (tasks.length > 0) {
81
84
  for (let task of tasks) {
82
- await tasksService.updateStatus(task.id, 'expired');
85
+ await dataService_js_1.tasksService.updateStatus(task.id, 'expired');
83
86
  }
84
87
  }
85
88
  }
@@ -94,12 +97,12 @@ class TaskSchedulerService {
94
97
  try {
95
98
  const now = Date.now();
96
99
  const nowBeforeHour = now - EXPIRED_THRESHOLD;
97
- const timeKey = getUTCTimeKey(new Date());
98
- const authMap = authStore.getAll();
100
+ const timeKey = (0, shared_1.getUTCTimeKey)(new Date());
101
+ const authMap = authStore_js_1.authStore.getAll();
99
102
  if (!authMap) {
100
103
  return;
101
104
  }
102
- const response = await Promise.all(Array.from(authMap.values()).map(x => tasksService.list(x.user.id)));
105
+ const response = await Promise.all(Array.from(authMap.values()).map(x => dataService_js_1.tasksService.list(x.user.id)));
103
106
  if (response.some(x => !x.success)) {
104
107
  logger.error('获取任务失败');
105
108
  return;
@@ -123,13 +126,13 @@ class TaskSchedulerService {
123
126
  async executeTask(task) {
124
127
  try {
125
128
  // 更新任务状态为 notifying
126
- taskStore.updateStatus(task.id, 'notifying');
129
+ TaskStore_js_1.taskStore.updateStatus(task.id, 'notifying');
127
130
  logger.info(`Executing task: ${task.title}`, {
128
131
  taskId: task.id,
129
- scheduledAt: formatUTCForLog(task.scheduledAt),
132
+ scheduledAt: (0, shared_1.formatUTCForLog)(task.scheduledAt),
130
133
  });
131
134
  // 优先通过 WebSocket 通知 Desktop 在线执行任务
132
- const wsSent = webSocketService.sendTaskTrigger({
135
+ const wsSent = WebSocketService_js_1.webSocketService.sendTaskTrigger({
133
136
  id: task.id,
134
137
  title: task.title,
135
138
  description: task.description,
@@ -140,19 +143,19 @@ class TaskSchedulerService {
140
143
  if (wsSent) {
141
144
  // Desktop 在线,由 Desktop 端播放铃声并执行任务
142
145
  logger.info(`Task ${task.title}: WebSocket notification sent to Desktop`);
143
- await tasksService.updateStatus(task.id, 'notifying');
146
+ await dataService_js_1.tasksService.updateStatus(task.id, 'notifying');
144
147
  }
145
148
  else {
146
149
  // Desktop 不在线,Gateway 本地直接执行任务
147
150
  logger.info(`Task ${task.title}: No WebSocket, executing locally`);
148
- await tasksService.updateStatus(task.id, 'running');
151
+ await dataService_js_1.tasksService.updateStatus(task.id, 'running');
149
152
  await this.executeTaskLocally(task);
150
- await tasksService.updateStatus(task.id, 'completed');
153
+ await dataService_js_1.tasksService.updateStatus(task.id, 'completed');
151
154
  }
152
155
  }
153
156
  catch (error) {
154
157
  logger.error(`Failed to execute task ${task.id}:`, error);
155
- taskStore.updateStatus(task.id, 'failed');
158
+ TaskStore_js_1.taskStore.updateStatus(task.id, 'failed');
156
159
  }
157
160
  }
158
161
  /**
@@ -161,7 +164,7 @@ class TaskSchedulerService {
161
164
  */
162
165
  async executeTaskLocally(task) {
163
166
  try {
164
- const currentSession = getSessionManager(task.userId).getCurrentSession();
167
+ const currentSession = (0, index_js_1.getSessionManager)(task.userId).getCurrentSession();
165
168
  if (!currentSession) {
166
169
  logger.warn(`No current session found, cannot execute task: ${task.title}`);
167
170
  return;
@@ -182,23 +185,23 @@ class TaskSchedulerService {
182
185
  * 获取调度器状态
183
186
  */
184
187
  getStatus() {
185
- const pendingCount = taskStore.findByStatus('pending').length;
186
- const notifyingCount = taskStore.findByStatus('notifying').length;
187
- const completedCount = taskStore.findByStatus('completed').length;
188
- const failedCount = taskStore.findByStatus('failed').length;
189
- const expiredCount = taskStore.findByStatus('expired').length;
188
+ const pendingCount = TaskStore_js_1.taskStore.findByStatus('pending').length;
189
+ const notifyingCount = TaskStore_js_1.taskStore.findByStatus('notifying').length;
190
+ const completedCount = TaskStore_js_1.taskStore.findByStatus('completed').length;
191
+ const failedCount = TaskStore_js_1.taskStore.findByStatus('failed').length;
192
+ const expiredCount = TaskStore_js_1.taskStore.findByStatus('expired').length;
190
193
  return {
191
194
  initialized: this.initialized,
192
195
  running: this.intervalId !== null,
193
196
  checkInterval: CHECK_INTERVAL,
194
- totalTasks: taskStore.count(),
197
+ totalTasks: TaskStore_js_1.taskStore.count(),
195
198
  pendingTasks: pendingCount,
196
199
  notifyingTasks: notifyingCount,
197
200
  completedTasks: completedCount,
198
201
  failedTasks: failedCount,
199
202
  expiredTasks: expiredCount,
200
- nextCheck: formatUTCForLog(Date.now() + CHECK_INTERVAL),
203
+ nextCheck: (0, shared_1.formatUTCForLog)(Date.now() + CHECK_INTERVAL),
201
204
  };
202
205
  }
203
206
  }
204
- export const taskSchedulerService = new TaskSchedulerService();
207
+ exports.taskSchedulerService = new TaskSchedulerService();
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  /**
2
3
  * Gateway 统一任务服务
3
4
  *
@@ -7,14 +8,16 @@
7
8
  * - platformApply === currentPlatform → 本地 SQLite 存储(localTaskService)
8
9
  * - platformApply !== currentPlatform → 服务器 API(tasksApi)
9
10
  */
10
- import { authStore } from '../stores/index.js';
11
- import { tasksApi } from '../api/index.js';
12
- import { localTaskService } from './LocalTaskService.js';
13
- import { getLogger } from '@myassis/shared';
14
- import { getPlatform } from '@myassis/shared/dist/utils/system.js';
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.taskService = void 0;
13
+ const index_js_1 = require("../stores/index.js");
14
+ const index_js_2 = require("../api/index.js");
15
+ const LocalTaskService_js_1 = require("./LocalTaskService.js");
16
+ const shared_1 = require("@myassis/shared");
17
+ const system_js_1 = require("@myassis/shared/dist/utils/system.js");
15
18
  // 当前网关平台标识
16
- const CURRENT_PLATFORM = process.env.GATEWAY_PLATFORM || getPlatform();
17
- const logger = getLogger('TaskService');
19
+ const CURRENT_PLATFORM = process.env.GATEWAY_PLATFORM || (0, system_js_1.getPlatform)();
20
+ const logger = (0, shared_1.getLogger)('TaskService');
18
21
  /**
19
22
  * 判断任务是否应该存储在本地
20
23
  */
@@ -39,7 +42,7 @@ class TaskService {
39
42
  route: isLocal ? 'local' : 'server',
40
43
  });
41
44
  if (isLocal) {
42
- const task = localTaskService.createTask({
45
+ const task = LocalTaskService_js_1.localTaskService.createTask({
43
46
  userId: data.userId,
44
47
  title: data.title,
45
48
  description: data.description,
@@ -56,7 +59,7 @@ class TaskService {
56
59
  return { id: task.id, isLocal: true };
57
60
  }
58
61
  else {
59
- const result = await tasksApi.create({
62
+ const result = await index_js_2.tasksApi.create({
60
63
  user_id: data.userId,
61
64
  title: data.title,
62
65
  description: data.description,
@@ -82,11 +85,11 @@ class TaskService {
82
85
  * 获取任务(自动路由 - 先本地后服务器)
83
86
  */
84
87
  async getTask(taskId, token) {
85
- const localTask = localTaskService.getTask(taskId);
88
+ const localTask = LocalTaskService_js_1.localTaskService.getTask(taskId);
86
89
  if (localTask)
87
90
  return localTask;
88
91
  try {
89
- const result = await tasksApi.get(taskId, token);
92
+ const result = await index_js_2.tasksApi.get(taskId, token);
90
93
  return this.transformServerTask(result);
91
94
  }
92
95
  catch (error) {
@@ -98,12 +101,12 @@ class TaskService {
98
101
  * 获取任务列表(合并本地和服务器)
99
102
  */
100
103
  async listTasks(params) {
101
- const localResult = localTaskService.listTasks(params);
104
+ const localResult = LocalTaskService_js_1.localTaskService.listTasks(params);
102
105
  let serverTasks = [];
103
106
  const userId = params.userId;
104
- const token = authStore.get(userId).accessToken;
107
+ const token = index_js_1.authStore.get(userId).accessToken;
105
108
  try {
106
- const serverResult = await tasksApi.list({
109
+ const serverResult = await index_js_2.tasksApi.list({
107
110
  status: params.status,
108
111
  page: params.page ? String(params.page) : undefined,
109
112
  pageSize: params.pageSize ? String(params.pageSize) : undefined,
@@ -130,14 +133,14 @@ class TaskService {
130
133
  * 更新任务(自动路由)
131
134
  */
132
135
  async updateTask(taskId, data, token) {
133
- const localTask = localTaskService.getTask(taskId);
136
+ const localTask = LocalTaskService_js_1.localTaskService.getTask(taskId);
134
137
  if (localTask) {
135
- const result = localTaskService.updateTask(taskId, data);
138
+ const result = LocalTaskService_js_1.localTaskService.updateTask(taskId, data);
136
139
  return result !== null;
137
140
  }
138
141
  else {
139
142
  try {
140
- await tasksApi.update(taskId, {
143
+ await index_js_2.tasksApi.update(taskId, {
141
144
  title: data.title,
142
145
  description: data.description,
143
146
  task_type: data.taskType,
@@ -167,13 +170,13 @@ class TaskService {
167
170
  * 删除任务(自动路由)
168
171
  */
169
172
  async deleteTask(taskId, token) {
170
- const localTask = localTaskService.getTask(taskId);
173
+ const localTask = LocalTaskService_js_1.localTaskService.getTask(taskId);
171
174
  if (localTask) {
172
- return localTaskService.deleteTask(taskId);
175
+ return LocalTaskService_js_1.localTaskService.deleteTask(taskId);
173
176
  }
174
177
  else {
175
178
  try {
176
- await tasksApi.delete(taskId, token);
179
+ await index_js_2.tasksApi.delete(taskId, token);
177
180
  return true;
178
181
  }
179
182
  catch (error) {
@@ -186,14 +189,14 @@ class TaskService {
186
189
  * 更新任务状态
187
190
  */
188
191
  async updateTaskStatus(taskId, status, token) {
189
- const localTask = localTaskService.getTask(taskId);
192
+ const localTask = LocalTaskService_js_1.localTaskService.getTask(taskId);
190
193
  if (localTask) {
191
- await localTaskService.updateTaskStatus(taskId, status);
194
+ await LocalTaskService_js_1.localTaskService.updateTaskStatus(taskId, status);
192
195
  return true;
193
196
  }
194
197
  else {
195
198
  try {
196
- await tasksApi.updateStatus(taskId, { status }, token);
199
+ await index_js_2.tasksApi.updateStatus(taskId, { status }, token);
197
200
  return true;
198
201
  }
199
202
  catch (error) {
@@ -240,4 +243,4 @@ class TaskService {
240
243
  };
241
244
  }
242
245
  }
243
- export const taskService = new TaskService();
246
+ exports.taskService = new TaskService();
@@ -1,11 +1,14 @@
1
+ "use strict";
1
2
  /**
2
3
  * WebSocket 服务
3
4
  * 负责实时消息推送,使用 ws 库实现
4
5
  */
5
- import { WebSocketServer, WebSocket } from 'ws';
6
- import { authStore } from '../stores/index.js';
7
- import { getLogger } from '@myassis/shared';
8
- const logger = getLogger('WebSocketService');
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.webSocketService = void 0;
8
+ const ws_1 = require("ws");
9
+ const index_js_1 = require("../stores/index.js");
10
+ const shared_1 = require("@myassis/shared");
11
+ const logger = (0, shared_1.getLogger)('WebSocketService');
9
12
  class WebSocketService {
10
13
  wss = null;
11
14
  clients = new Map();
@@ -14,7 +17,7 @@ class WebSocketService {
14
17
  * 初始化 WebSocket 服务器,挂载到 HTTP Server 上
15
18
  */
16
19
  initialize(server) {
17
- this.wss = new WebSocketServer({ server, path: '/ws' });
20
+ this.wss = new ws_1.WebSocketServer({ server, path: '/ws' });
18
21
  // 防止 WebSocketServer error 事件未监听导致进程崩溃(如 EADDRINUSE)
19
22
  this.wss.on('error', (err) => {
20
23
  logger.error('WebSocketServer error:', err);
@@ -36,7 +39,7 @@ class WebSocketService {
36
39
  };
37
40
  // 如果同一用户已有连接,关闭旧连接
38
41
  const existingClient = this.clients.get(userId);
39
- if (existingClient && existingClient.ws.readyState === WebSocket.OPEN) {
42
+ if (existingClient && existingClient.ws.readyState === ws_1.WebSocket.OPEN) {
40
43
  existingClient.ws.close(4002, 'Replaced by new connection');
41
44
  }
42
45
  this.clients.set(userId, client);
@@ -106,7 +109,7 @@ class WebSocketService {
106
109
  token = decodeURIComponent(match[1]);
107
110
  }
108
111
  if (token) {
109
- const userId = authStore.getUserId(token);
112
+ const userId = index_js_1.authStore.getUserId(token);
110
113
  if (userId) {
111
114
  return String(userId);
112
115
  }
@@ -133,7 +136,7 @@ class WebSocketService {
133
136
  */
134
137
  sendToUser(userId, message) {
135
138
  const client = this.clients.get(String(userId));
136
- if (!client || client.ws.readyState !== WebSocket.OPEN) {
139
+ if (!client || client.ws.readyState !== ws_1.WebSocket.OPEN) {
137
140
  return false;
138
141
  }
139
142
  try {
@@ -150,7 +153,7 @@ class WebSocketService {
150
153
  */
151
154
  isUserOnline(userId) {
152
155
  const client = this.clients.get(String(userId));
153
- return !!client && client.ws.readyState === WebSocket.OPEN;
156
+ return !!client && client.ws.readyState === ws_1.WebSocket.OPEN;
154
157
  }
155
158
  /**
156
159
  * 发送任务通知
@@ -202,7 +205,7 @@ class WebSocketService {
202
205
  broadcast(message) {
203
206
  const data = JSON.stringify(message);
204
207
  this.clients.forEach((client) => {
205
- if (client.ws.readyState === WebSocket.OPEN) {
208
+ if (client.ws.readyState === ws_1.WebSocket.OPEN) {
206
209
  try {
207
210
  client.ws.send(data);
208
211
  }
@@ -243,4 +246,4 @@ class WebSocketService {
243
246
  logger.info('WebSocket 服务已关闭');
244
247
  }
245
248
  }
246
- export const webSocketService = new WebSocketService();
249
+ exports.webSocketService = new WebSocketService();
@@ -1,10 +1,13 @@
1
- import { v4 as uuidv4 } from 'uuid';
2
- import { getSessionManager } from '../session/SessionManager.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Agent = void 0;
4
+ const uuid_1 = require("uuid");
5
+ const SessionManager_js_1 = require("../session/SessionManager.js");
3
6
  /**
4
7
  * Agent - Business logic entity
5
8
  * Represents an AI agent with independent system prompt and multiple sessions
6
9
  */
7
- export class Agent {
10
+ class Agent {
8
11
  id;
9
12
  userId;
10
13
  name;
@@ -33,15 +36,15 @@ export class Agent {
33
36
  * Get all sessions under this agent
34
37
  */
35
38
  getSessions() {
36
- const allSessions = getSessionManager(this.userId).getUserSessions();
39
+ const allSessions = (0, SessionManager_js_1.getSessionManager)(this.userId).getUserSessions();
37
40
  return allSessions.filter(s => s.agentId === this.id);
38
41
  }
39
42
  /**
40
43
  * Create new session under this agent
41
44
  */
42
45
  createSession(config = {}) {
43
- const session = getSessionManager(this.userId).createSession({
44
- id: config.id || uuidv4(),
46
+ const session = (0, SessionManager_js_1.getSessionManager)(this.userId).createSession({
47
+ id: config.id || (0, uuid_1.v4)(),
45
48
  title: config.title || '新会话',
46
49
  selectModelId: config.selectModelId,
47
50
  agentId: this.id, // Associate with this agent
@@ -55,7 +58,7 @@ export class Agent {
55
58
  const session = this.getSession(sessionId);
56
59
  if (!session)
57
60
  return null;
58
- return getSessionManager(this.userId).updateSession(sessionId, data);
61
+ return (0, SessionManager_js_1.getSessionManager)(this.userId).updateSession(sessionId, data);
59
62
  }
60
63
  /**
61
64
  * Delete session under this agent
@@ -64,13 +67,13 @@ export class Agent {
64
67
  const session = this.getSession(sessionId);
65
68
  if (!session)
66
69
  return false;
67
- return getSessionManager(this.userId).deleteSession(sessionId);
70
+ return (0, SessionManager_js_1.getSessionManager)(this.userId).deleteSession(sessionId);
68
71
  }
69
72
  /**
70
73
  * Get session under this agent
71
74
  */
72
75
  getSession(sessionId) {
73
- const session = getSessionManager(this.userId).getSession(sessionId);
76
+ const session = (0, SessionManager_js_1.getSessionManager)(this.userId).getSession(sessionId);
74
77
  if (session && session.agentId === this.id) {
75
78
  return session;
76
79
  }
@@ -118,3 +121,4 @@ export class Agent {
118
121
  this.store.delete(this.id);
119
122
  }
120
123
  }
124
+ exports.Agent = Agent;
@@ -1,15 +1,21 @@
1
- import { v4 as uuidv4 } from 'uuid';
2
- import { Agent } from './Agent.js';
3
- import { getSessionManager } from '../session/SessionManager.js';
4
- import { authStore } from '../../stores/authStore.js';
5
- import { getLogger } from '@myassis/shared';
6
- import appConfig from '../../config/index.js';
7
- const logger = getLogger('AgentManager');
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.initAgentManager = exports.agentManagerMap = exports.AgentManager = void 0;
7
+ const uuid_1 = require("uuid");
8
+ const Agent_js_1 = require("./Agent.js");
9
+ const SessionManager_js_1 = require("../session/SessionManager.js");
10
+ const authStore_js_1 = require("../../stores/authStore.js");
11
+ const shared_1 = require("@myassis/shared");
12
+ const index_js_1 = __importDefault(require("../../config/index.js"));
13
+ const logger = (0, shared_1.getLogger)('AgentManager');
8
14
  /**
9
15
  * AgentManager - Business logic layer
10
16
  * Manages multiple agents in memory
11
17
  */
12
- export class AgentManager {
18
+ class AgentManager {
13
19
  store;
14
20
  agents = null;
15
21
  initialized = false;
@@ -36,7 +42,7 @@ export class AgentManager {
36
42
  // Load all agents from database
37
43
  const agentDataList = this.store.findByUserId(userId);
38
44
  for (const agentData of agentDataList) {
39
- const agent = new Agent(agentData, this.store);
45
+ const agent = new Agent_js_1.Agent(agentData, this.store);
40
46
  this.agents.set(agent.id, agent);
41
47
  }
42
48
  // If no agents exist, create default "我的助手" agent
@@ -60,7 +66,7 @@ export class AgentManager {
60
66
  * Get current user ID
61
67
  */
62
68
  getCurrentUserId() {
63
- const user = authStore.getUser(this.userId);
69
+ const user = authStore_js_1.authStore.getUser(this.userId);
64
70
  return user ? String(user.id) : null;
65
71
  }
66
72
  /**
@@ -68,9 +74,9 @@ export class AgentManager {
68
74
  */
69
75
  createDefaultAgent(userId) {
70
76
  const agentData = {
71
- id: uuidv4(),
77
+ id: (0, uuid_1.v4)(),
72
78
  userId,
73
- name: appConfig.appName,
79
+ name: index_js_1.default.appName,
74
80
  description: '默认 AI 助手',
75
81
  systemPrompt: undefined,
76
82
  avatar: undefined,
@@ -80,7 +86,7 @@ export class AgentManager {
80
86
  isCurrent: true,
81
87
  };
82
88
  this.store.insert(agentData);
83
- const agent = new Agent(agentData, this.store);
89
+ const agent = new Agent_js_1.Agent(agentData, this.store);
84
90
  this.agents.set(agent.id, agent);
85
91
  // Create default session
86
92
  agent.createSession({ title: '新会话' });
@@ -97,7 +103,7 @@ export class AgentManager {
97
103
  return [];
98
104
  const agentDataList = this.store.findByUserId(userId);
99
105
  return agentDataList.map(data => {
100
- const sessions = getSessionManager(this.userId).getUserSessions();
106
+ const sessions = (0, SessionManager_js_1.getSessionManager)(this.userId).getUserSessions();
101
107
  const agentSessions = sessions
102
108
  .filter(s => s.agentId === data.id)
103
109
  .map(s => ({
@@ -137,7 +143,7 @@ export class AgentManager {
137
143
  throw new Error(`Agent with name "${config.name}" already exists`);
138
144
  }
139
145
  const agentData = {
140
- id: uuidv4(),
146
+ id: (0, uuid_1.v4)(),
141
147
  userId,
142
148
  name: config.name,
143
149
  description: config.description,
@@ -148,7 +154,7 @@ export class AgentManager {
148
154
  updatedAt: Date.now(),
149
155
  };
150
156
  this.store.insert(agentData);
151
- const agent = new Agent(agentData, this.store);
157
+ const agent = new Agent_js_1.Agent(agentData, this.store);
152
158
  this.agents.set(agent.id, agent);
153
159
  // Create default session
154
160
  agent.createSession({ title: '新会话' });
@@ -188,7 +194,7 @@ export class AgentManager {
188
194
  // Delete all sessions under this agent
189
195
  const sessions = agent.getSessions();
190
196
  for (const session of sessions) {
191
- getSessionManager(this.userId).deleteSession(session.id);
197
+ (0, SessionManager_js_1.getSessionManager)(this.userId).deleteSession(session.id);
192
198
  }
193
199
  // Delete agent
194
200
  this.store.delete(agentId);
@@ -235,7 +241,7 @@ export class AgentManager {
235
241
  * Get sessions under an agent
236
242
  */
237
243
  getAgentSessions(agentId) {
238
- const sessions = getSessionManager(this.userId).getUserSessions();
244
+ const sessions = (0, SessionManager_js_1.getSessionManager)(this.userId).getUserSessions();
239
245
  return sessions
240
246
  .filter(s => s.agentId === agentId)
241
247
  .map(s => ({
@@ -262,12 +268,14 @@ export class AgentManager {
262
268
  }
263
269
  }
264
270
  }
271
+ exports.AgentManager = AgentManager;
265
272
  // Export singleton
266
- export let agentManagerMap = new Map();
267
- export function initAgentManager(store, userId) {
268
- if (agentManagerMap.has(userId)) {
269
- return agentManagerMap.get(userId);
273
+ exports.agentManagerMap = new Map();
274
+ function initAgentManager(store, userId) {
275
+ if (exports.agentManagerMap.has(userId)) {
276
+ return exports.agentManagerMap.get(userId);
270
277
  }
271
- agentManagerMap.set(userId, new AgentManager(store, userId));
272
- return agentManagerMap.get(userId);
278
+ exports.agentManagerMap.set(userId, new AgentManager(store, userId));
279
+ return exports.agentManagerMap.get(userId);
273
280
  }
281
+ exports.initAgentManager = initAgentManager;
@@ -1,10 +1,13 @@
1
- import { getLogger } from '@myassis/shared';
2
- const logger = getLogger('AgentStore');
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AgentStore = void 0;
4
+ const shared_1 = require("@myassis/shared");
5
+ const logger = (0, shared_1.getLogger)('AgentStore');
3
6
  /**
4
7
  * AgentStore - Data access layer
5
8
  * Operates on SQLite database
6
9
  */
7
- export class AgentStore {
10
+ class AgentStore {
8
11
  db;
9
12
  constructor(db) {
10
13
  this.db = db;
@@ -71,3 +74,4 @@ export class AgentStore {
71
74
  };
72
75
  }
73
76
  }
77
+ exports.AgentStore = AgentStore;