@myassis/gateway 1.0.4 → 1.0.5

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.
@@ -3,7 +3,7 @@
3
3
  * 从请求头 Authorization: Bearer <token> 解码 JWT,提取 userId
4
4
  * 同时保留原始 token 供路由转发给 Server
5
5
  */
6
- import { authStore } from '..\stores.js';
6
+ import { authStore } from '../stores';
7
7
  import { getLogger } from '@myassis/shared';
8
8
  const logger = getLogger('middleware/auth');
9
9
  const JWT_SECRET = process.env.JWT_SECRET || 'your-secret-key-change-in-production';
@@ -1,12 +1,12 @@
1
1
  import { Router } from 'express';
2
- import { requireAuth } from '..\middleware\auth.js';
3
- import { runWithToken } from '..\api\index.js';
4
- import { getSessionManager } from '..\services\session.js';
5
- import { initAgentManager, agentManagerMap } from '..\services\agent\AgentManager.js';
6
- import { AgentStore } from '..\services\agent\AgentStore.js';
2
+ import { requireAuth } from '../middleware/auth.js';
3
+ import { runWithToken } from '../api/index.js';
4
+ import { getSessionManager } from '../services/session';
5
+ import { initAgentManager, agentManagerMap } from '../services/agent/AgentManager';
6
+ import { AgentStore } from '../services/agent/AgentStore';
7
7
  import { getLogger } from '@myassis/shared';
8
8
  const logger = getLogger('AgentRoutes');
9
- import { sessionStore } from '..\services\session\SessionStore.js';
9
+ import { sessionStore } from '../services/session/SessionStore';
10
10
  const router = Router();
11
11
  // 所有路由需要认证
12
12
  router.use(requireAuth, (req, _res, next) => {
@@ -1,8 +1,8 @@
1
1
  import { Router } from 'express';
2
2
  import multer from 'multer';
3
- import { appConfig } from '..\config\index.js';
4
- import { requireAuth } from '..\middleware\auth.js';
5
- import { runWithToken } from '..\api\index.js';
3
+ import { appConfig } from '../config/index.js';
4
+ import { requireAuth } from '../middleware/auth.js';
5
+ import { runWithToken } from '../api/index.js';
6
6
  import { getLogger } from '@myassis/shared';
7
7
  const logger = getLogger('UploadRoutes');
8
8
  const router = Router();
@@ -8,7 +8,7 @@ import { webSocketService } from './WebSocketService';
8
8
  import { getSessionManager } from './session';
9
9
  import { getLogger, getUTCTimeKey, formatUTCForLog, holidayService } from '@myassis/shared';
10
10
  import { tasksService } from './dataService';
11
- import { authStore } from '..\stores.js';
11
+ import { authStore } from '../stores';
12
12
  const logger = getLogger('TaskSchedulerService');
13
13
  const EXPIRED_THRESHOLD = 60 * 60 * 1000; // 1小时
14
14
  const CHECK_INTERVAL = 60 * 1000; // 1分钟
@@ -7,7 +7,7 @@
7
7
  * - platformApply === currentPlatform → 本地 SQLite 存储(localTaskService)
8
8
  * - platformApply !== currentPlatform → 服务器 API(tasksApi)
9
9
  */
10
- import { authStore } from '..\stores.js';
10
+ import { authStore } from '../stores';
11
11
  import { tasksApi } from '../api';
12
12
  import { localTaskService } from './LocalTaskService';
13
13
  import { getLogger } from '@myassis/shared';
@@ -1,9 +1,9 @@
1
1
  import { v4 as uuidv4 } from 'uuid';
2
2
  import { Agent } from './Agent';
3
3
  import { getSessionManager } from '../session/SessionManager';
4
- import { authStore } from '..\..\stores\authStore.js';
4
+ import { authStore } from '../../stores/authStore';
5
5
  import { getLogger } from '@myassis/shared';
6
- import appConfig from '..\..\config.js';
6
+ import appConfig from '../../config';
7
7
  const logger = getLogger('AgentManager');
8
8
  /**
9
9
  * AgentManager - Business logic layer
@@ -1,4 +1,4 @@
1
- import { persistStore } from '..\..\stores.js';
1
+ import { persistStore } from "../../stores";
2
2
  import { getLogger } from '@myassis/shared';
3
3
  import fs from 'fs/promises';
4
4
  const logger = getLogger('LLMClient');
@@ -2,9 +2,9 @@ import { getLogger } from '@myassis/shared';
2
2
  const logger = getLogger('MemoryManager');
3
3
  import { toModel } from '../models';
4
4
  import { modelsService } from '../dataService';
5
- import { authStore } from '..\..\stores.js';
5
+ import { authStore } from '../../stores';
6
6
  import { LLMClient } from '../llm/LLMClient';
7
- import { appConfig } from '..\..\config.js';
7
+ import { appConfig } from '../../config';
8
8
  const DEFAULT_CONFIG = {
9
9
  summaryThreshold: 10,
10
10
  enabled: true,
@@ -1,15 +1,15 @@
1
1
  import { v4 as uuidv4 } from 'uuid';
2
2
  import { getLogger } from '@myassis/shared';
3
3
  import { SessionStore } from './SessionStore';
4
- import { AgentStore } from '..\agent\AgentStore.js';
5
- import { authStore } from '..\..\stores\authStore.js';
6
- import { toModel } from '..\models.js';
7
- import { executeTool, getToolDefinitions } from '..\tools.js';
4
+ import { AgentStore } from '../../services/agent/AgentStore';
5
+ import { authStore } from '../../stores/authStore';
6
+ import { toModel } from '../../services/models';
7
+ import { executeTool, getToolDefinitions } from '../../services/tools';
8
8
  import { getSystemPromptAsync } from '../systemPrompt';
9
9
  import { LLMClient, parseAruments } from '../llm/LLMClient';
10
- import { modelsService, settingsService } from '..\dataService.js';
10
+ import { modelsService, settingsService } from '../../services/dataService';
11
11
  import { MemoryManager } from '../memory/MemoryManager';
12
- import { appConfig } from '..\..\config.js';
12
+ import { appConfig } from '../../config';
13
13
  import { getSessionManager } from './SessionManager';
14
14
  const logger = getLogger('Session');
15
15
  const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
@@ -2,7 +2,7 @@ import { v4 as uuidv4 } from 'uuid';
2
2
  import { getLogger } from '@myassis/shared';
3
3
  const logger = getLogger('SessionManager');
4
4
  import { sessionStore } from './SessionStore';
5
- import { authStore } from '..\..\stores\authStore.js';
5
+ import { authStore } from '../../stores/authStore';
6
6
  import { Session } from './Session';
7
7
  /**
8
8
  * SessionManager - Business logic layer
@@ -1,4 +1,4 @@
1
- import { authStore } from '..\stores.js';
1
+ import { authStore } from '../stores';
2
2
  import os from 'os';
3
3
  import { settingsService, skillsService } from './dataService';
4
4
  import { getLogger } from '@myassis/shared';
@@ -1,5 +1,5 @@
1
1
  import { modelsService } from '../dataService';
2
- import { authStore } from '..\..\stores.js';
2
+ import { authStore } from '../../stores';
3
3
  export const modelTool = {
4
4
  name: 'model',
5
5
  description: '模型管理工具',
@@ -1,5 +1,5 @@
1
1
  import { skillsService, skillHubService } from '../dataService';
2
- import { authStore, persistStore } from '..\..\stores.js';
2
+ import { authStore, persistStore } from '../../stores';
3
3
  import { getLogger } from '@myassis/shared';
4
4
  const logger = getLogger('skill');
5
5
  export const skillTool = {
@@ -63,7 +63,7 @@ export const taskTool = {
63
63
  return { success: true, output: JSON.stringify({ task: response.data }) };
64
64
  }
65
65
  case 'list': {
66
- const response = await tasksService.list({ status });
66
+ const response = await tasksService.list(userId, { status });
67
67
  if (!response.success)
68
68
  return { success: false, errorMessage: '获取任务列表失败' };
69
69
  const tasks = response.data || [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myassis/gateway",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "我的助手 Gateway Service - 本地 AI 网关服务,支持认证、WebSocket 实时通信和任务调度",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -23,8 +23,8 @@
23
23
  "scripts": {
24
24
  "dev": "tsx watch src/index.ts",
25
25
  "start": "node dist/index.js",
26
- "build": "tsc",
27
- "postbuild": "node scripts/fix-dist-aliases.js && node scripts/fix-dist-imports.js",
26
+ "build": "tsc --skipLibCheck",
27
+ "postbuild": "npx tsc-alias",
28
28
  "pkg:win": "pkg . --targets node18-win-x64 --output myassis-gateway-win.exe",
29
29
  "pkg:linux": "pkg . --targets node18-linux-x64 --output myassis-gateway-linux",
30
30
  "pkg:all": "npm run pkg:win && npm run pkg:linux",
@@ -46,7 +46,7 @@
46
46
  "url": "git+https://github.com/myassis/myassis.git"
47
47
  },
48
48
  "dependencies": {
49
- "@nut-tree-fork/nut-js": "^4.2.0",
49
+ "@nut-tree/nut-js": "^4.2.0",
50
50
  "@myassis/shared": "latest",
51
51
  "axios": "^1.15.2",
52
52
  "bcryptjs": "^2.4.3",
@@ -79,7 +79,8 @@
79
79
  "@types/ws": "^8.5.10",
80
80
  "pkg": "^5.8.1",
81
81
  "tsx": "^4.7.0",
82
- "typescript": "^5.3.3"
82
+ "typescript": "^5.3.3",
83
+ "tsc-alias": "^1.8.10"
83
84
  },
84
85
  "pkg": {
85
86
  "scripts": [
@@ -0,0 +1,112 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * 最终修复脚本:将所有 @/ 路径别名替换为相对路径
4
+ */
5
+
6
+ import fs from 'fs';
7
+ import path from 'path';
8
+ import { fileURLToPath } from 'url';
9
+
10
+ const __filename = fileURLToPath(import.meta.url);
11
+ const __dirname = path.dirname(__filename);
12
+
13
+ const srcDir = path.join(__dirname, '..', 'src');
14
+
15
+ // 计算两个路径之间的相对路径
16
+ function getRelativePath(fromFile, toModule) {
17
+ // toModule: @/services/session -> src/services/session
18
+ const targetPath = toModule.replace(/^@\//, '');
19
+ const targetFullPath = path.resolve(srcDir, targetPath);
20
+
21
+ // 计算相对路径
22
+ let relativePath = path.relative(path.dirname(fromFile), targetFullPath);
23
+
24
+ // Windows 路径转换为 Unix 风格
25
+ relativePath = relativePath.replace(/\\/g, '/');
26
+
27
+ // 确保以 ./ 或 ../ 开头
28
+ if (!relativePath.startsWith('.')) {
29
+ relativePath = './' + relativePath;
30
+ }
31
+
32
+ // 添加 .js 扩展名(ES Module 要求)
33
+ if (!relativePath.endsWith('.js') && !relativePath.endsWith('.ts')) {
34
+ relativePath += '.js';
35
+ }
36
+
37
+ return relativePath;
38
+ }
39
+
40
+ // 修复文件内容
41
+ function fixFileContent(filePath, content) {
42
+ let modified = false;
43
+
44
+ // 匹配 import ... from '@/...' 或 export ... from '@/...'
45
+ const importRegex = /(import|export)\s+([\s\S]+?)\s+from\s+['"]@\/([^'"]+)['"]/g;
46
+
47
+ const newContent = content.replace(importRegex, (match, keyword, imports, modulePath) => {
48
+ const relativePath = getRelativePath(filePath, '@/' + modulePath);
49
+ modified = true;
50
+ return `${keyword} ${imports} from '${relativePath}'`;
51
+ });
52
+
53
+ return { content: newContent, modified };
54
+ }
55
+
56
+ // 处理单个文件
57
+ function processFile(filePath) {
58
+ const content = fs.readFileSync(filePath, 'utf8');
59
+ const { content: newContent, modified } = fixFileContent(filePath, content);
60
+
61
+ if (modified) {
62
+ fs.writeFileSync(filePath, newContent, 'utf8');
63
+ console.log(`✓ ${path.relative(process.cwd(), filePath)}`);
64
+ return true;
65
+ }
66
+
67
+ return false;
68
+ }
69
+
70
+ // 递归处理目录
71
+ function processDirectory(dir) {
72
+ let fixedCount = 0;
73
+
74
+ const items = fs.readdirSync(dir, { withFileTypes: true });
75
+
76
+ for (const item of items) {
77
+ const itemPath = path.join(dir, item.name);
78
+
79
+ if (item.isDirectory()) {
80
+ // 跳过特定目录
81
+ if (!['node_modules', 'dist', '.git', 'coverage'].includes(item.name)) {
82
+ fixedCount += processDirectory(itemPath);
83
+ }
84
+ } else if (item.name.endsWith('.ts') && !item.name.endsWith('.d.ts')) {
85
+ if (processFile(itemPath)) {
86
+ fixedCount++;
87
+ }
88
+ }
89
+ }
90
+
91
+ return fixedCount;
92
+ }
93
+
94
+ // 主函数
95
+ function main() {
96
+ console.log('🔧 将 @/ 路径别名替换为相对路径...\n');
97
+
98
+ if (!fs.existsSync(srcDir)) {
99
+ console.error('❌ src 目录不存在!');
100
+ process.exit(1);
101
+ }
102
+
103
+ const fixedCount = processDirectory(srcDir);
104
+
105
+ console.log(`\n✅ 完成!修复了 ${fixedCount} 个文件`);
106
+ console.log('\n⚠️ 重要提示:');
107
+ console.log(' 1. 请检查修改是否正确');
108
+ console.log(' 2. 运行 npm run build 验证编译');
109
+ console.log(' 3. 提交代码更改');
110
+ }
111
+
112
+ main();