@myassis/gateway 1.0.19 → 1.0.21

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,8 +1,14 @@
1
- import path from 'path';
2
- import fs from 'fs';
3
- import { getLogger } from '@myassis/shared';
4
- const logger = getLogger('MigrationManager');
5
- export class MigrationManager {
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.MigrationManager = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const shared_1 = require("@myassis/shared");
10
+ const logger = (0, shared_1.getLogger)('MigrationManager');
11
+ class MigrationManager {
6
12
  db;
7
13
  migrationsDir;
8
14
  constructor(db, migrationsDir) {
@@ -43,11 +49,11 @@ export class MigrationManager {
43
49
  const appliedMigrations = this.getAppliedMigrations();
44
50
  const appliedNames = new Set(appliedMigrations.map(m => m.name));
45
51
  // 读取迁移目录下的所有 SQL 文件
46
- if (!fs.existsSync(this.migrationsDir)) {
52
+ if (!fs_1.default.existsSync(this.migrationsDir)) {
47
53
  logger.info(`Migrations directory does not exist: ${this.migrationsDir}`);
48
54
  return;
49
55
  }
50
- const migrationFiles = fs.readdirSync(this.migrationsDir)
56
+ const migrationFiles = fs_1.default.readdirSync(this.migrationsDir)
51
57
  .filter(file => file.endsWith('.sql'))
52
58
  .sort(); // 按文件名排序
53
59
  let applied = 0;
@@ -72,8 +78,8 @@ export class MigrationManager {
72
78
  continue;
73
79
  }
74
80
  // 读取并执行 SQL 文件
75
- const filePath = path.join(this.migrationsDir, file);
76
- const sql = fs.readFileSync(filePath, 'utf-8');
81
+ const filePath = path_1.default.join(this.migrationsDir, file);
82
+ const sql = fs_1.default.readFileSync(filePath, 'utf-8');
77
83
  logger.info(`Applying migration: ${name} (version: ${version})`);
78
84
  try {
79
85
  // 分割多条 SQL 语句并执行
@@ -154,10 +160,10 @@ export class MigrationManager {
154
160
  getStatus() {
155
161
  const currentVersion = this.getCurrentVersion();
156
162
  const appliedMigrations = this.getAppliedMigrations();
157
- if (!fs.existsSync(this.migrationsDir)) {
163
+ if (!fs_1.default.existsSync(this.migrationsDir)) {
158
164
  return { currentVersion, applied: appliedMigrations, pending: [], error: 'Migrations directory not found' };
159
165
  }
160
- const migrationFiles = fs.readdirSync(this.migrationsDir)
166
+ const migrationFiles = fs_1.default.readdirSync(this.migrationsDir)
161
167
  .filter(file => file.endsWith('.sql'))
162
168
  .sort();
163
169
  const pending = [];
@@ -174,3 +180,4 @@ export class MigrationManager {
174
180
  return { currentVersion, applied: appliedMigrations, pending };
175
181
  }
176
182
  }
183
+ exports.MigrationManager = MigrationManager;
@@ -1,17 +1,20 @@
1
- import { v4 as uuidv4 } from 'uuid';
2
- import { getLogger } from '@myassis/shared';
3
- import { SessionStore } from './SessionStore.js';
4
- import { AgentStore } from '../../services/agent/AgentStore.js';
5
- import { authStore } from '../../stores/authStore.js';
6
- import { toModel } from '../../services/models.js';
7
- import { executeTool, getToolDefinitions } from '../../services/tools/index.js';
8
- import { getSystemPromptAsync } from '../systemPrompt.js';
9
- import { LLMClient, parseAruments } from '../llm/LLMClient.js';
10
- import { modelsService, settingsService } from '../../services/dataService.js';
11
- import { MemoryManager } from '../memory/MemoryManager.js';
12
- import { appConfig } from '../../config/index.js';
13
- import { getSessionManager } from './SessionManager.js';
14
- const logger = getLogger('Session');
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Session = void 0;
4
+ const uuid_1 = require("uuid");
5
+ const shared_1 = require("@myassis/shared");
6
+ const SessionStore_js_1 = require("./SessionStore.js");
7
+ const AgentStore_js_1 = require("../../services/agent/AgentStore.js");
8
+ const authStore_js_1 = require("../../stores/authStore.js");
9
+ const models_js_1 = require("../../services/models.js");
10
+ const index_js_1 = require("../../services/tools/index.js");
11
+ const systemPrompt_js_1 = require("../systemPrompt.js");
12
+ const LLMClient_js_1 = require("../llm/LLMClient.js");
13
+ const dataService_js_1 = require("../../services/dataService.js");
14
+ const MemoryManager_js_1 = require("../memory/MemoryManager.js");
15
+ const index_js_2 = require("../../config/index.js");
16
+ const SessionManager_js_1 = require("./SessionManager.js");
17
+ const logger = (0, shared_1.getLogger)('Session');
15
18
  const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
16
19
  // AgentStore 单例 - 需要通过 SessionStore 获取数据库实例
17
20
  let agentStoreInstance = null;
@@ -22,14 +25,14 @@ function getAgentStore() {
22
25
  if (!sessionStore) {
23
26
  throw new Error('SessionStore not initialized');
24
27
  }
25
- agentStoreInstance = new AgentStore(sessionStore.getDb());
28
+ agentStoreInstance = new AgentStore_js_1.AgentStore(sessionStore.getDb());
26
29
  }
27
30
  return agentStoreInstance;
28
31
  }
29
32
  /**
30
33
  * Session - session entity
31
34
  */
32
- export class Session {
35
+ class Session {
33
36
  id;
34
37
  userId;
35
38
  agentId;
@@ -62,7 +65,7 @@ export class Session {
62
65
  this.isCurrent = data.isCurrent ?? false;
63
66
  this.createdAt = data.createdAt || Date.now();
64
67
  this.updatedAt = data.updatedAt || Date.now();
65
- this.store = new SessionStore();
68
+ this.store = new SessionStore_js_1.SessionStore();
66
69
  this.toInsertMessages = [];
67
70
  }
68
71
  store;
@@ -159,7 +162,7 @@ export class Session {
159
162
  addAssistantMessage(content, toolCalls, modelName, id) {
160
163
  const message = {
161
164
  sessionId: this.id,
162
- id: id ? id : uuidv4(),
165
+ id: id ? id : (0, uuid_1.v4)(),
163
166
  role: 'assistant',
164
167
  content,
165
168
  toolCalls,
@@ -395,11 +398,11 @@ export class Session {
395
398
  // Add user message
396
399
  this.getAbortController();
397
400
  this.isGenerating = true;
398
- const token = authStore.get(this.userId).accessToken;
399
- const settings = await settingsService.get(token);
401
+ const token = authStore_js_1.authStore.get(this.userId).accessToken;
402
+ const settings = await dataService_js_1.settingsService.get(token);
400
403
  const streamDelay = this.getStreamDelay(settings.streamSpeed);
401
404
  this.currentMessageId = assistantMessageId;
402
- const memoryManager = new MemoryManager(this, this.abortController.signal, childAgent);
405
+ const memoryManager = new MemoryManager_js_1.MemoryManager(this, this.abortController.signal, childAgent);
403
406
  const historyMessages = await memoryManager.getHistoryMessagesAsync();
404
407
  // SSE 辅助方法:res 为 null 时跳过写入(本地执行模式)
405
408
  const sendSSE = (res, data) => {
@@ -441,7 +444,7 @@ export class Session {
441
444
  systemPrompt = agent.systemPrompt;
442
445
  }
443
446
  }
444
- systemPrompt = await getSystemPromptAsync(agent, systemPrompt);
447
+ systemPrompt = await (0, systemPrompt_js_1.getSystemPromptAsync)(agent, systemPrompt);
445
448
  if (messages.some(x => x.role === 'system')) {
446
449
  messages = messages.map(m => m.role == 'system' ? { ...m, content: systemPrompt + '\n以下为之前对话内容摘要:\n' + m.content } : m);
447
450
  }
@@ -460,7 +463,7 @@ export class Session {
460
463
  let modelNames = [];
461
464
  //用于后续的消息滑动处理
462
465
  const messagesLength = messages.length;
463
- const keep = appConfig.messageKeep;
466
+ const keep = index_js_2.appConfig.messageKeep;
464
467
  //具体调用逻辑函数
465
468
  // 辅助函数:截断消息内容
466
469
  const truncateMessageContent = (message) => {
@@ -519,13 +522,13 @@ export class Session {
519
522
  }
520
523
  }
521
524
  // 获取本地工具定义
522
- const tools = getToolDefinitions();
523
- const models = (await modelsService.list(token)).data.map(x => toModel(x));
525
+ const tools = (0, index_js_1.getToolDefinitions)();
526
+ const models = (await dataService_js_1.modelsService.list(token)).data.map(x => (0, models_js_1.toModel)(x));
524
527
  // 使用 LLMClient 进行流式调用
525
528
  if (!this.abortController || !this.abortController.signal || this.abortController.signal.aborted) {
526
529
  throw Error('aborted');
527
530
  }
528
- const llmClient = new LLMClient(models, messages, this.abortController.signal, tools);
531
+ const llmClient = new LLMClient_js_1.LLMClient(models, messages, this.abortController.signal, tools);
529
532
  llmClient.setPreferredModel(this.selectModelId);
530
533
  // 使用 streamChat 调用模型
531
534
  const llmResult = await llmClient.Chat();
@@ -545,7 +548,7 @@ export class Session {
545
548
  });
546
549
  const content = llmResult.content || llmResult.reasoningContent;
547
550
  if (content || toolCall == null) {
548
- const toolCallId = uuidv4();
551
+ const toolCallId = (0, uuid_1.v4)();
549
552
  toolCall = {
550
553
  id: toolCallId,
551
554
  content: llmResult.content,
@@ -603,7 +606,7 @@ export class Session {
603
606
  };
604
607
  sendSSE(res, toolStartEvent);
605
608
  try {
606
- const result = await executeTool(pendingToolCall.toolName, parseAruments(pendingToolCall.input), this.id, this.currentMessageId, this.userId);
609
+ const result = await (0, index_js_1.executeTool)(pendingToolCall.toolName, (0, LLMClient_js_1.parseAruments)(pendingToolCall.input), this.id, this.currentMessageId, this.userId);
607
610
  toolResults.push({
608
611
  id: pendingToolCall.id,
609
612
  name: pendingToolCall.toolName,
@@ -727,7 +730,7 @@ export class Session {
727
730
  res.end();
728
731
  }
729
732
  // 非当前查看的 session,助手回复完成后增加未读计数
730
- getSessionManager(this.userId).onMessageComplete(this.id);
733
+ (0, SessionManager_js_1.getSessionManager)(this.userId).onMessageComplete(this.id);
731
734
  // 只在非 abort 的情况下保存(abort 由 stopGenerating 负责保存)
732
735
  if (this.currentMessageId !== null) {
733
736
  this.saveMessage();
@@ -755,3 +758,4 @@ export class Session {
755
758
  return this.abortController;
756
759
  }
757
760
  }
761
+ exports.Session = Session;
@@ -1,14 +1,17 @@
1
- import { v4 as uuidv4 } from 'uuid';
2
- import { getLogger } from '@myassis/shared';
3
- const logger = getLogger('SessionManager');
4
- import { sessionStore } from './SessionStore.js';
5
- import { authStore } from '../../stores/authStore.js';
6
- import { Session } from './Session.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSessionManager = exports.sessionManagerMap = exports.SessionManager = void 0;
4
+ const uuid_1 = require("uuid");
5
+ const shared_1 = require("@myassis/shared");
6
+ const logger = (0, shared_1.getLogger)('SessionManager');
7
+ const SessionStore_js_1 = require("./SessionStore.js");
8
+ const authStore_js_1 = require("../../stores/authStore.js");
9
+ const Session_js_1 = require("./Session.js");
7
10
  /**
8
11
  * SessionManager - Business logic layer
9
12
  * Manages sessions in memory
10
13
  */
11
- export class SessionManager {
14
+ class SessionManager {
12
15
  sessions = null;
13
16
  initialized = false;
14
17
  userId;
@@ -30,7 +33,7 @@ export class SessionManager {
30
33
  return;
31
34
  }
32
35
  this.sessions = new Map();
33
- const sessionDataList = sessionStore.findSessionsByUserId(userId);
36
+ const sessionDataList = SessionStore_js_1.sessionStore.findSessionsByUserId(userId);
34
37
  for (const sessionData of sessionDataList) {
35
38
  const session = this.createSessionFromData(sessionData);
36
39
  this.sessions.set(session.id, session);
@@ -42,14 +45,14 @@ export class SessionManager {
42
45
  * Get current user ID
43
46
  */
44
47
  getCurrentUserId() {
45
- const user = authStore.getUser(this.userId);
48
+ const user = authStore_js_1.authStore.getUser(this.userId);
46
49
  return user ? String(user.id) : null;
47
50
  }
48
51
  /**
49
52
  * Create Session instance from data
50
53
  */
51
54
  createSessionFromData(data) {
52
- const session = new Session({
55
+ const session = new Session_js_1.Session({
53
56
  id: data.id,
54
57
  userId: data.userId,
55
58
  agentId: data.agentId,
@@ -77,8 +80,8 @@ export class SessionManager {
77
80
  if (!userId) {
78
81
  throw new Error('No user logged in, cannot create session');
79
82
  }
80
- const session = new Session({
81
- id: config.id || uuidv4(),
83
+ const session = new Session_js_1.Session({
84
+ id: config.id || (0, uuid_1.v4)(),
82
85
  userId,
83
86
  agentId: config.agentId,
84
87
  title: config.title || 'New Chat',
@@ -142,9 +145,9 @@ export class SessionManager {
142
145
  const session = this.sessions.get(sessionId);
143
146
  if (!session)
144
147
  return false;
145
- sessionStore.transaction(() => {
146
- sessionStore.deleteMessagesBySessionId(sessionId);
147
- sessionStore.deleteSession(sessionId);
148
+ SessionStore_js_1.sessionStore.transaction(() => {
149
+ SessionStore_js_1.sessionStore.deleteMessagesBySessionId(sessionId);
150
+ SessionStore_js_1.sessionStore.deleteSession(sessionId);
148
151
  });
149
152
  this.sessions.delete(sessionId);
150
153
  logger.info(`Deleted session ${sessionId}`);
@@ -250,13 +253,15 @@ export class SessionManager {
250
253
  * Get migration status
251
254
  */
252
255
  getMigrationStatus() {
253
- return sessionStore.getMigrationStatus();
256
+ return SessionStore_js_1.sessionStore.getMigrationStatus();
254
257
  }
255
258
  }
256
- export let sessionManagerMap = new Map();
257
- export function getSessionManager(userId) {
258
- if (!sessionManagerMap.has(userId)) {
259
- sessionManagerMap.set(userId, new SessionManager(userId));
259
+ exports.SessionManager = SessionManager;
260
+ exports.sessionManagerMap = new Map();
261
+ function getSessionManager(userId) {
262
+ if (!exports.sessionManagerMap.has(userId)) {
263
+ exports.sessionManagerMap.set(userId, new SessionManager(userId));
260
264
  }
261
- return sessionManagerMap.get(userId);
265
+ return exports.sessionManagerMap.get(userId);
262
266
  }
267
+ exports.getSessionManager = getSessionManager;
@@ -1,54 +1,60 @@
1
- import Database from 'better-sqlite3';
2
- import path from 'path';
3
- import fs from 'fs';
4
- import { fileURLToPath } from 'url';
5
- import { getLogger } from '@myassis/shared';
6
- import { MigrationManager } from './MigrationManager.js';
7
- const __filename = fileURLToPath(import.meta.url);
8
- const __dirname = path.dirname(__filename);
9
- const logger = getLogger('SessionStore');
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.sessionStore = exports.SessionStore = exports.getMigrationsDir = exports.getDbPath = exports.getDataDir = void 0;
7
+ const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const fs_1 = __importDefault(require("fs"));
10
+ const shared_1 = require("@myassis/shared");
11
+ const MigrationManager_js_1 = require("./MigrationManager.js");
12
+ const logger = (0, shared_1.getLogger)('SessionStore');
10
13
  /**
11
14
  * 获取包安装根目录(npm install -g 后的包目录)
12
- * ESM 下用 import.meta.url 定位,比 process.execPath 可靠
15
+ * __dirname 定位,比 process.execPath 可靠
13
16
  */
14
17
  function getPackageRootDir() {
15
18
  // dist/services/session/SessionStore.js → 包根目录
16
- return path.resolve(__dirname, '..', '..', '..');
19
+ return path_1.default.resolve(__dirname, '..', '..', '..');
17
20
  }
18
- export function getDataDir() {
21
+ function getDataDir() {
19
22
  // 优先使用用户工作目录下的 data(运行时数据应存放在用户空间)
20
- const defaultDataDir = path.join(getPackageRootDir(), 'data');
21
- if (!fs.existsSync(defaultDataDir)) {
22
- fs.mkdirSync(defaultDataDir, { recursive: true });
23
+ const defaultDataDir = path_1.default.join(getPackageRootDir(), 'data');
24
+ if (!fs_1.default.existsSync(defaultDataDir)) {
25
+ fs_1.default.mkdirSync(defaultDataDir, { recursive: true });
23
26
  }
24
27
  return defaultDataDir;
25
28
  }
26
- export function getDbPath() {
29
+ exports.getDataDir = getDataDir;
30
+ function getDbPath() {
27
31
  const dataDir = getDataDir();
28
- return path.join(dataDir, 'sessions.db');
32
+ return path_1.default.join(dataDir, 'sessions.db');
29
33
  }
30
- export function getMigrationsDir() {
34
+ exports.getDbPath = getDbPath;
35
+ function getMigrationsDir() {
31
36
  // migrations 随包发布,从包安装目录读取
32
- const pkgMigrations = path.join(getPackageRootDir(), 'migrations');
33
- if (fs.existsSync(pkgMigrations)) {
37
+ const pkgMigrations = path_1.default.join(getPackageRootDir(), 'migrations');
38
+ if (fs_1.default.existsSync(pkgMigrations)) {
34
39
  return pkgMigrations;
35
40
  }
36
41
  // 回退到 CWD(开发环境)
37
- return path.join(process.cwd(), 'migrations');
42
+ return path_1.default.join(process.cwd(), 'migrations');
38
43
  }
44
+ exports.getMigrationsDir = getMigrationsDir;
39
45
  /**
40
46
  * SessionStore - Data access layer
41
47
  * Responsible for direct SQLite operations
42
48
  */
43
- export class SessionStore {
49
+ class SessionStore {
44
50
  db;
45
51
  migrationManager;
46
52
  constructor() {
47
53
  const dbPath = getDbPath();
48
- this.db = new Database(dbPath);
54
+ this.db = new better_sqlite3_1.default(dbPath);
49
55
  this.db.pragma('foreign_keys = ON');
50
56
  const migrationsDir = getMigrationsDir();
51
- this.migrationManager = new MigrationManager(this.db, migrationsDir);
57
+ this.migrationManager = new MigrationManager_js_1.MigrationManager(this.db, migrationsDir);
52
58
  this.migrationManager.migrate();
53
59
  logger.info(`Initialized at ${dbPath}`);
54
60
  // 注册到全局供 Session 使用
@@ -185,4 +191,5 @@ export class SessionStore {
185
191
  return this.db;
186
192
  }
187
193
  }
188
- export const sessionStore = new SessionStore();
194
+ exports.SessionStore = SessionStore;
195
+ exports.sessionStore = new SessionStore();
@@ -1,3 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Session = exports.getSessionManager = exports.SessionManager = void 0;
1
4
  // 导出 SessionManager(业务逻辑层)
2
- export { SessionManager, getSessionManager } from './SessionManager.js';
3
- export { Session } from './Session.js';
5
+ var SessionManager_js_1 = require("./SessionManager.js");
6
+ Object.defineProperty(exports, "SessionManager", { enumerable: true, get: function () { return SessionManager_js_1.SessionManager; } });
7
+ Object.defineProperty(exports, "getSessionManager", { enumerable: true, get: function () { return SessionManager_js_1.getSessionManager; } });
8
+ var Session_js_1 = require("./Session.js");
9
+ Object.defineProperty(exports, "Session", { enumerable: true, get: function () { return Session_js_1.Session; } });
@@ -1,4 +1,7 @@
1
- export const mockSkills = [
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mockSkills = void 0;
4
+ exports.mockSkills = [
2
5
  {
3
6
  id: 'web-search',
4
7
  name: 'Web Search',
@@ -1,10 +1,16 @@
1
- import { authStore } from '../stores/index.js';
2
- import os from 'os';
3
- import { settingsService, skillsService } from './dataService.js';
4
- import { getLogger } from '@myassis/shared';
5
- const logger = getLogger('SystemPrompt');
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.getSystemPromptAsync = exports.LANGUAGES = exports.CHAT_STYLE_TEMPLATES = void 0;
7
+ const index_js_1 = require("../stores/index.js");
8
+ const os_1 = __importDefault(require("os"));
9
+ const dataService_js_1 = require("./dataService.js");
10
+ const shared_1 = require("@myassis/shared");
11
+ const logger = (0, shared_1.getLogger)('SystemPrompt');
6
12
  // 预设的对话风格模板
7
- export const CHAT_STYLE_TEMPLATES = [
13
+ exports.CHAT_STYLE_TEMPLATES = [
8
14
  {
9
15
  id: 'friendly',
10
16
  icon: 'face-smile',
@@ -35,7 +41,7 @@ export const CHAT_STYLE_TEMPLATES = [
35
41
  },
36
42
  ];
37
43
  // 支持的语言列表
38
- export const LANGUAGES = [
44
+ exports.LANGUAGES = [
39
45
  { code: 'zh-CN', name: 'Simplified Chinese', nativeName: '简体中文', chineseName: '简体中文' },
40
46
  { code: 'en-US', name: 'English', nativeName: 'English', chineseName: '英文' },
41
47
  ];
@@ -43,9 +49,9 @@ export const LANGUAGES = [
43
49
  * 获取操作系统信息
44
50
  */
45
51
  function getOSInfo() {
46
- const platform = os.platform();
47
- const release = os.release();
48
- const arch = os.arch();
52
+ const platform = os_1.default.platform();
53
+ const release = os_1.default.release();
54
+ const arch = os_1.default.arch();
49
55
  let osName = 'Unknown';
50
56
  switch (platform) {
51
57
  case 'darwin':
@@ -66,7 +72,7 @@ function getChatStyle(settings) {
66
72
  // 这里可以根据需要返回不同的提示词风格
67
73
  const chatStyleId = settings.chatStyleId;
68
74
  if (chatStyleId) {
69
- return CHAT_STYLE_TEMPLATES.find(s => s.id === chatStyleId)?.style || '';
75
+ return exports.CHAT_STYLE_TEMPLATES.find(s => s.id === chatStyleId)?.style || '';
70
76
  }
71
77
  return '';
72
78
  }
@@ -102,13 +108,13 @@ function getInstalledSkillsPrompt(skills) {
102
108
  * @param customPrompt - 自定义提示词(可选)
103
109
  * @returns 完整的系统提示词
104
110
  */
105
- export async function getSystemPromptAsync(agent, customPrompt) {
111
+ async function getSystemPromptAsync(agent, customPrompt) {
106
112
  const osInfo = getOSInfo();
107
- const token = authStore.get(agent.userId).accessToken;
108
- const settings = (await settingsService.get(token)).data;
109
- const skills = (await skillsService.list(token)).data;
113
+ const token = index_js_1.authStore.get(agent.userId).accessToken;
114
+ const settings = (await dataService_js_1.settingsService.get(token)).data;
115
+ const skills = (await dataService_js_1.skillsService.list(token)).data;
110
116
  const skillPrompts = getInstalledSkillsPrompt(skills);
111
- const chineseLocalName = LANGUAGES.filter(x => x.code === settings.language)[0]?.chineseName ?? '简体中文';
117
+ const chineseLocalName = exports.LANGUAGES.filter(x => x.code === settings.language)[0]?.chineseName ?? '简体中文';
112
118
  const date = new Date();
113
119
  let prompt = `${getIndentityInfoAsync(settings, agent)}。
114
120
  【当前运行环境】:${osInfo}。
@@ -152,3 +158,4 @@ export async function getSystemPromptAsync(agent, customPrompt) {
152
158
  }
153
159
  return prompt;
154
160
  }
161
+ exports.getSystemPromptAsync = getSystemPromptAsync;
@@ -1,14 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PushTokenStore = void 0;
1
4
  /**
2
5
  * PushTokenStore - 用户设备推送 Token 存储
3
6
  * 使用 SQLite 管理用户的多设备推送 Token
4
7
  */
5
- import { getLogger } from '@myassis/shared';
6
- const logger = getLogger('PushTokenStore');
7
- import { sessionStore } from '../session/SessionStore.js';
8
- export class PushTokenStore {
8
+ const shared_1 = require("@myassis/shared");
9
+ const logger = (0, shared_1.getLogger)('PushTokenStore');
10
+ const SessionStore_js_1 = require("../session/SessionStore.js");
11
+ class PushTokenStore {
9
12
  db;
10
13
  constructor() {
11
- this.db = sessionStore.getDb();
14
+ this.db = SessionStore_js_1.sessionStore.getDb();
12
15
  this.initTable();
13
16
  }
14
17
  initTable() {
@@ -104,3 +107,4 @@ export class PushTokenStore {
104
107
  return !!row;
105
108
  }
106
109
  }
110
+ exports.PushTokenStore = PushTokenStore;
@@ -1,10 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.taskStore = exports.TaskStore = void 0;
1
4
  /**
2
5
  * TaskStore - Gateway 任务数据访问层
3
6
  * 操作 SQLite 数据库,与 AgentStore/SessionStore 共享同一个数据库实例
4
7
  */
5
- import { getLogger } from '@myassis/shared';
6
- import { sessionStore } from '../session/SessionStore.js';
7
- const logger = getLogger('TaskStore');
8
+ const shared_1 = require("@myassis/shared");
9
+ const SessionStore_js_1 = require("../session/SessionStore.js");
10
+ const logger = (0, shared_1.getLogger)('TaskStore');
8
11
  function rowToTaskData(row) {
9
12
  return {
10
13
  id: row.id,
@@ -25,7 +28,7 @@ function rowToTaskData(row) {
25
28
  updatedAt: row.updated_at,
26
29
  };
27
30
  }
28
- export class TaskStore {
31
+ class TaskStore {
29
32
  db;
30
33
  constructor(db) {
31
34
  // 如果传入了 db 实例(测试用),直接使用
@@ -34,7 +37,7 @@ export class TaskStore {
34
37
  this.db = db;
35
38
  }
36
39
  else {
37
- this.db = sessionStore.getDb();
40
+ this.db = SessionStore_js_1.sessionStore.getDb();
38
41
  }
39
42
  this.initTable();
40
43
  }
@@ -121,4 +124,5 @@ export class TaskStore {
121
124
  return result.count;
122
125
  }
123
126
  }
124
- export const taskStore = new TaskStore();
127
+ exports.TaskStore = TaskStore;
128
+ exports.taskStore = new TaskStore();
@@ -1,7 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculatorTool = void 0;
1
4
  /**
2
5
  * 计算器工具 - 执行数学计算
3
6
  */
4
- export const calculatorTool = {
7
+ exports.calculatorTool = {
5
8
  name: 'calculator',
6
9
  description: '执行数学计算,支持加减乘除和括号',
7
10
  parameters: {
@@ -1,3 +1,9 @@
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.editTool = void 0;
1
7
  /**
2
8
  * 文件编辑工具(内容匹配模式)
3
9
  *
@@ -23,10 +29,10 @@
23
29
  * 3. 可选:replaceAll: true 替换所有匹配;oldRange 辅助校验特定位置
24
30
  * 4. 匹配失败时工具返回实际内容片段,LLM 据此修正后重试
25
31
  */
26
- import fs from 'fs/promises';
27
- import path from 'path';
28
- import { getLogger } from '@myassis/shared';
29
- const logger = getLogger('edit');
32
+ const promises_1 = __importDefault(require("fs/promises"));
33
+ const path_1 = __importDefault(require("path"));
34
+ const shared_1 = require("@myassis/shared");
35
+ const logger = (0, shared_1.getLogger)('edit');
30
36
  // ---------- 常量 ----------
31
37
  /** 最大文件大小(10MB) */
32
38
  const MAX_FILE_SIZE = 10 * 1024 * 1024;
@@ -166,14 +172,14 @@ const editTool = {
166
172
  // ---- 文件存在性 & 大小校验 ----
167
173
  let original;
168
174
  try {
169
- const stats = await fs.stat(filePath);
175
+ const stats = await promises_1.default.stat(filePath);
170
176
  if (stats.size > MAX_FILE_SIZE) {
171
177
  return {
172
178
  success: false,
173
179
  errorMessage: `文件过大(${stats.size} 字节),超出最大允许 ${MAX_FILE_SIZE} 字节`,
174
180
  };
175
181
  }
176
- original = await fs.readFile(filePath, 'utf-8');
182
+ original = await promises_1.default.readFile(filePath, 'utf-8');
177
183
  }
178
184
  catch (err) {
179
185
  if (err.code === 'ENOENT') {
@@ -252,9 +258,9 @@ const editTool = {
252
258
  };
253
259
  }
254
260
  // ---- 写入文件(仅当目录已存在时) ----
255
- const dir = path.dirname(filePath);
261
+ const dir = path_1.default.dirname(filePath);
256
262
  try {
257
- const dirStat = await fs.stat(dir);
263
+ const dirStat = await promises_1.default.stat(dir);
258
264
  if (!dirStat.isDirectory()) {
259
265
  return { success: false, errorMessage: `目标路径不是目录: ${dir}` };
260
266
  }
@@ -263,7 +269,7 @@ const editTool = {
263
269
  return { success: false, errorMessage: `目标目录不存在,拒绝创建新目录: ${dir}` };
264
270
  }
265
271
  // ---- 写入修改后的内容 ----
266
- await fs.writeFile(filePath, modified, 'utf-8');
272
+ await promises_1.default.writeFile(filePath, modified, 'utf-8');
267
273
  logger.info(`edit 完成: ${filePath}`, {
268
274
  editCount: edits.length,
269
275
  originalSize: original.length,
@@ -289,4 +295,4 @@ const editTool = {
289
295
  }
290
296
  },
291
297
  };
292
- export { editTool };
298
+ exports.editTool = editTool;