@myassis/gateway 1.0.2 → 1.0.4

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/index.js CHANGED
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env node
2
1
  import express from 'express';
3
2
  import cors from 'cors';
4
3
  import helmet from 'helmet';
@@ -3,7 +3,7 @@
3
3
  * 从请求头 Authorization: Bearer <token> 解码 JWT,提取 userId
4
4
  * 同时保留原始 token 供路由转发给 Server
5
5
  */
6
- import { authStore } from '@/stores';
6
+ import { authStore } from '..\stores.js';
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';
5
- import { initAgentManager, agentManagerMap } from '@/services/agent/AgentManager';
6
- import { AgentStore } from '@/services/agent/AgentStore';
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';
7
7
  import { getLogger } from '@myassis/shared';
8
8
  const logger = getLogger('AgentRoutes');
9
- import { sessionStore } from '@/services/session/SessionStore';
9
+ import { sessionStore } from '..\services\session\SessionStore.js';
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';
11
+ import { authStore } from '..\stores.js';
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';
10
+ import { authStore } from '..\stores.js';
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';
4
+ import { authStore } from '..\..\stores\authStore.js';
5
5
  import { getLogger } from '@myassis/shared';
6
- import appConfig from '@/config';
6
+ import appConfig from '..\..\config.js';
7
7
  const logger = getLogger('AgentManager');
8
8
  /**
9
9
  * AgentManager - Business logic layer
@@ -1,4 +1,4 @@
1
- import { persistStore } from "@/stores";
1
+ import { persistStore } from '..\..\stores.js';
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';
5
+ import { authStore } from '..\..\stores.js';
6
6
  import { LLMClient } from '../llm/LLMClient';
7
- import { appConfig } from '@/config';
7
+ import { appConfig } from '..\..\config.js';
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 '@/services/agent/AgentStore';
5
- import { authStore } from '@/stores/authStore';
6
- import { toModel } from '@/services/models';
7
- import { executeTool, getToolDefinitions } from '@/services/tools';
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';
8
8
  import { getSystemPromptAsync } from '../systemPrompt';
9
9
  import { LLMClient, parseAruments } from '../llm/LLMClient';
10
- import { modelsService, settingsService } from '@/services/dataService';
10
+ import { modelsService, settingsService } from '..\dataService.js';
11
11
  import { MemoryManager } from '../memory/MemoryManager';
12
- import { appConfig } from '@/config';
12
+ import { appConfig } from '..\..\config.js';
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';
5
+ import { authStore } from '..\..\stores\authStore.js';
6
6
  import { Session } from './Session';
7
7
  /**
8
8
  * SessionManager - Business logic layer
@@ -1,4 +1,4 @@
1
- import { authStore } from '@/stores';
1
+ import { authStore } from '..\stores.js';
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';
2
+ import { authStore } from '..\..\stores.js';
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';
2
+ import { authStore, persistStore } from '..\..\stores.js';
3
3
  import { getLogger } from '@myassis/shared';
4
4
  const logger = getLogger('skill');
5
5
  export const skillTool = {
@@ -6,7 +6,7 @@ import fs from 'fs';
6
6
  import path from 'path';
7
7
  import os from 'os';
8
8
  import { getLogger } from '@myassis/shared';
9
- import { getSessionManager } from '@/services/session';
9
+ import { getSessionManager } from '../services/session/index.js';
10
10
  const logger = getLogger('authStore');
11
11
  // 认证数据存储文件路径(使用应用数据目录,支持 STORAGE_DIR 环境变量)
12
12
  const AUTH_STORAGE_DIR = process.env.STORAGE_DIR || path.join(os.homedir(), 'myassis-gateway-storage');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myassis/gateway",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "我的助手 Gateway Service - 本地 AI 网关服务,支持认证、WebSocket 实时通信和任务调度",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -24,7 +24,7 @@
24
24
  "dev": "tsx watch src/index.ts",
25
25
  "start": "node dist/index.js",
26
26
  "build": "tsc",
27
- "postbuild": "node scripts/postbuild.js",
27
+ "postbuild": "node scripts/fix-dist-aliases.js && node scripts/fix-dist-imports.js",
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",
@@ -43,11 +43,11 @@
43
43
  "homepage": "https://github.com/myassis/myassis#readme",
44
44
  "repository": {
45
45
  "type": "git",
46
- "url": "https://github.com/myassis/myassis.git"
46
+ "url": "git+https://github.com/myassis/myassis.git"
47
47
  },
48
48
  "dependencies": {
49
49
  "@nut-tree-fork/nut-js": "^4.2.0",
50
- "@myassis/shared": "^1.0.0",
50
+ "@myassis/shared": "latest",
51
51
  "axios": "^1.15.2",
52
52
  "bcryptjs": "^2.4.3",
53
53
  "better-sqlite3": "^12.10.0",
@@ -0,0 +1,107 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * 后处理 dist 目录,将 @/ 路径别名替换为相对路径
4
+ */
5
+
6
+ import fs from 'fs';
7
+ import path from 'path';
8
+ import { fileURLToPath } from 'url';
9
+ import { execSync } from 'child_process';
10
+
11
+ const __filename = fileURLToPath(import.meta.url);
12
+ const __dirname = path.dirname(__filename);
13
+
14
+ const distDir = path.join(__dirname, '..', 'dist');
15
+ const srcDir = path.join(__dirname, '..', 'src');
16
+
17
+ // 获取从当前文件到 @/ 模块的相对路径
18
+ function resolveAliasToRelative(filePath, aliasPath) {
19
+ // aliasPath: @/services/session
20
+ // 转换为相对于 src 的路径
21
+ const targetPath = aliasPath.replace(/^@\//, '');
22
+ const targetFullPath = path.resolve(srcDir, targetPath);
23
+
24
+ // 计算从当前 dist 文件到目标 dist 文件的相对路径
25
+ const currentDistFile = filePath; // filePath 已经在 dist 中
26
+ const targetDistPath = targetFullPath.replace(srcDir, distDir);
27
+
28
+ let relativePath = path.relative(path.dirname(currentDistFile), targetDistPath);
29
+
30
+ // 确保使用正斜杠(ES Modules 要求)
31
+ relativePath = relativePath.replace(/\\/g, '/');
32
+
33
+ // 确保以 ./ 或 ../ 开头
34
+ if (!relativePath.startsWith('.')) {
35
+ relativePath = './' + relativePath;
36
+ }
37
+
38
+ // 添加 .js 扩展名
39
+ if (!relativePath.endsWith('.js')) {
40
+ relativePath += '.js';
41
+ }
42
+
43
+ return relativePath;
44
+ }
45
+
46
+ // 处理单个文件
47
+ function processFile(filePath) {
48
+ let content = fs.readFileSync(filePath, 'utf8');
49
+ let modified = false;
50
+
51
+ // 匹配 import ... from '@/...' 或 export ... from '@/...'
52
+ const importRegex = /(import|export)\s+(.+?)\s+from\s+['"]@\/([^'"]+)['"]/g;
53
+
54
+ content = content.replace(importRegex, (match, keyword, imports, modulePath) => {
55
+ const relativePath = resolveAliasToRelative(filePath, '@/' + modulePath);
56
+ modified = true;
57
+ return `${keyword} ${imports} from '${relativePath}'`;
58
+ });
59
+
60
+ if (modified) {
61
+ fs.writeFileSync(filePath, content, 'utf8');
62
+ return true;
63
+ }
64
+
65
+ return false;
66
+ }
67
+
68
+ // 递归处理目录
69
+ function processDirectory(dir) {
70
+ let fixedCount = 0;
71
+
72
+ const items = fs.readdirSync(dir, { withFileTypes: true });
73
+
74
+ for (const item of items) {
75
+ const itemPath = path.join(dir, item.name);
76
+
77
+ if (item.isDirectory()) {
78
+ // 跳过 node_modules(如果在 dist 中)
79
+ if (item.name !== 'node_modules') {
80
+ fixedCount += processDirectory(itemPath);
81
+ }
82
+ } else if (item.name.endsWith('.js')) {
83
+ if (processFile(itemPath)) {
84
+ fixedCount++;
85
+ }
86
+ }
87
+ }
88
+
89
+ return fixedCount;
90
+ }
91
+
92
+ // 主函数
93
+ function main() {
94
+ console.log('🔧 修复 dist 目录中的 @/ 路径别名...\n');
95
+ console.log(`Dist 目录: ${distDir}\n`);
96
+
97
+ if (!fs.existsSync(distDir)) {
98
+ console.error('❌ dist 目录不存在!请先运行 tsc');
99
+ process.exit(1);
100
+ }
101
+
102
+ const fixedCount = processDirectory(distDir);
103
+
104
+ console.log(`\n✅ 完成!修复了 ${fixedCount} 个文件`);
105
+ }
106
+
107
+ main();
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * 修复 dist 目录中的 ES Module 导入
4
+ * 为所有本地导入添加 .js 扩展名
5
+ */
6
+
7
+ import fs from 'fs';
8
+ import path from 'path';
9
+ import { fileURLToPath } from 'url';
10
+
11
+ const __filename = fileURLToPath(import.meta.url);
12
+ const __dirname = path.dirname(__filename);
13
+
14
+ const distDir = path.join(__dirname, '..', 'dist');
15
+
16
+ // 递归处理所有 .js 文件
17
+ function processFile(filePath) {
18
+ let content = fs.readFileSync(filePath, 'utf8');
19
+ let modified = false;
20
+
21
+ // 匹配 import 和 export ... from 语句
22
+ // 匹配模式:from './xxx' 或 from '../xxx'(不包含协议、不为 / 开头、不包含 .js)
23
+ const importRegex = /(?:import|export)\s+(?:[\w*{}\s,]+from\s+)?['"](\.\.?\/[^'"]+)['"]/g;
24
+
25
+ let match;
26
+ while ((match = importRegex.exec(content)) !== null) {
27
+ const importPath = match[1];
28
+
29
+ // 跳过已经有扩展名的
30
+ if (importPath.endsWith('.js') || importPath.endsWith('.json') || importPath.endsWith('.ts')) {
31
+ continue;
32
+ }
33
+
34
+ // 跳过 node_modules 中的包(不包含 . 或 .. 开头的)
35
+ if (!importPath.startsWith('./') && !importPath.startsWith('../')) {
36
+ continue;
37
+ }
38
+
39
+ // 添加 .js 扩展名
40
+ const newImportPath = importPath + '.js';
41
+ content = content.replace(
42
+ new RegExp(`['"]${importPath}['"]`, 'g'),
43
+ `'${newImportPath}'`
44
+ );
45
+ modified = true;
46
+
47
+ console.log(` Fixed: ${importPath} -> ${newImportPath}`);
48
+ }
49
+
50
+ if (modified) {
51
+ fs.writeFileSync(filePath, content, 'utf8');
52
+ return true;
53
+ }
54
+
55
+ return false;
56
+ }
57
+
58
+ // 递归查找并处理所有 .js 文件
59
+ function processDirectory(dir) {
60
+ let fixedCount = 0;
61
+
62
+ const items = fs.readdirSync(dir);
63
+
64
+ items.forEach(item => {
65
+ const itemPath = path.join(dir, item);
66
+ const stat = fs.statSync(itemPath);
67
+
68
+ if (stat.isDirectory()) {
69
+ fixedCount += processDirectory(itemPath);
70
+ } else if (item.endsWith('.js')) {
71
+ if (processFile(itemPath)) {
72
+ fixedCount++;
73
+ }
74
+ }
75
+ });
76
+
77
+ return fixedCount;
78
+ }
79
+
80
+ // 主函数
81
+ function main() {
82
+ console.log('🔧 修复 dist 目录中的 ES Module 导入...');
83
+ console.log(`目录: ${distDir}\n`);
84
+
85
+ if (!fs.existsSync(distDir)) {
86
+ console.error('❌ dist 目录不存在!请先运行 npm run build');
87
+ process.exit(1);
88
+ }
89
+
90
+ const fixedCount = processDirectory(distDir);
91
+
92
+ console.log(`\n✅ 完成!修复了 ${fixedCount} 个文件`);
93
+ }
94
+
95
+ main();
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * 自动修复 ES Module 导入的扩展名
4
+ * 在 TypeScript 文件中,所有本地导入必须包含 .js 扩展名
5
+ */
6
+
7
+ import fs from 'fs';
8
+ import path from 'path';
9
+ import { fileURLToPath } from 'url';
10
+
11
+ const __filename = fileURLToPath(import.meta.url);
12
+ const __dirname = path.dirname(__filename);
13
+
14
+ // 递归查找所有 .ts 文件(排除 .d.ts)
15
+ function findTsFiles(dir) {
16
+ let results = [];
17
+ const list = fs.readdirSync(dir);
18
+
19
+ list.forEach(file => {
20
+ const filePath = path.join(dir, file);
21
+ const stat = fs.statSync(filePath);
22
+
23
+ if (stat && stat.isDirectory()) {
24
+ // 跳过 node_modules 和 dist
25
+ if (file !== 'node_modules' && file !== 'dist' && file !== '.git') {
26
+ results = results.concat(findTsFiles(filePath));
27
+ }
28
+ } else if (file.endsWith('.ts') && !file.endsWith('.d.ts')) {
29
+ results.push(filePath);
30
+ }
31
+ });
32
+
33
+ return results;
34
+ }
35
+
36
+ // 修复文件中的导入语句
37
+ function fixImports(filePath) {
38
+ let content = fs.readFileSync(filePath, 'utf8');
39
+ let modified = false;
40
+
41
+ // 匹配 import 语句中的本地文件路径(以 ./ 或 ../ 开头,且不以 .js 或 .ts 结尾)
42
+ const importRegex = /from\s+['"](\.\.?\/[^'"]+)['"]/g;
43
+
44
+ content = content.replace(importRegex, (match, importPath) => {
45
+ // 如果已经以 .js 或 .ts 结尾,跳过
46
+ if (importPath.endsWith('.js') || importPath.endsWith('.ts')) {
47
+ return match;
48
+ }
49
+
50
+ // 添加 .js 扩展名
51
+ modified = true;
52
+ return `from '${importPath}.js'`;
53
+ });
54
+
55
+ if (modified) {
56
+ fs.writeFileSync(filePath, content, 'utf8');
57
+ console.log(`✓ Fixed: ${path.relative(process.cwd(), filePath)}`);
58
+ return true;
59
+ }
60
+
61
+ return false;
62
+ }
63
+
64
+ // 主函数
65
+ function main() {
66
+ const srcDir = path.join(__dirname, '..', 'src');
67
+
68
+ console.log('🔍 查找 TypeScript 文件...');
69
+ const tsFiles = findTsFiles(srcDir);
70
+ console.log(`找到 ${tsFiles.length} 个文件\n`);
71
+
72
+ console.log('🔧 修复导入语句...');
73
+ let fixedCount = 0;
74
+
75
+ tsFiles.forEach(file => {
76
+ if (fixImports(file)) {
77
+ fixedCount++;
78
+ }
79
+ });
80
+
81
+ console.log(`\n✅ 完成!修复了 ${fixedCount} 个文件`);
82
+
83
+ if (fixedCount > 0) {
84
+ console.log('\n⚠️ 请运行以下命令验证修改:');
85
+ console.log(' npm run build');
86
+ console.log(' node dist/index.js');
87
+ }
88
+ }
89
+
90
+ main();
@@ -0,0 +1,95 @@
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, toPath) {
17
+ // toPath 例如:@/services/agent/AgentManager
18
+ // 转换为:src/services/agent/AgentManager
19
+ const targetPath = toPath.replace(/^@\//, '');
20
+ const targetFullPath = path.join(srcDir, targetPath);
21
+
22
+ // 计算相对路径
23
+ let relativePath = path.relative(path.dirname(fromFile), targetFullPath);
24
+
25
+ // 确保以 ./ 或 ../ 开头
26
+ if (!relativePath.startsWith('.')) {
27
+ relativePath = './' + relativePath;
28
+ }
29
+
30
+ return relativePath;
31
+ }
32
+
33
+ // 修复文件中的 @/ 导入
34
+ function fixFile(filePath) {
35
+ let content = fs.readFileSync(filePath, 'utf8');
36
+ let modified = false;
37
+
38
+ // 匹配 import ... from '@/...' 或 export ... from '@/...'
39
+ const importRegex = /(import|export)\s+(.+?)\s+from\s+['"]@\/([^'"]+)['"]/g;
40
+
41
+ content = content.replace(importRegex, (match, keyword, imports, modulePath) => {
42
+ const relativePath = getRelativePath(filePath, '@/' + modulePath);
43
+ // 添加 .js 扩展名
44
+ const newPath = relativePath + '.js';
45
+ modified = true;
46
+ return `${keyword} ${imports} from '${newPath}'`;
47
+ });
48
+
49
+ if (modified) {
50
+ fs.writeFileSync(filePath, content, 'utf8');
51
+ console.log(`✓ Fixed: ${path.relative(process.cwd(), filePath)}`);
52
+ return true;
53
+ }
54
+
55
+ return false;
56
+ }
57
+
58
+ // 递归处理所有 .ts 文件
59
+ function processDirectory(dir) {
60
+ let fixedCount = 0;
61
+
62
+ const items = fs.readdirSync(dir);
63
+
64
+ items.forEach(item => {
65
+ const itemPath = path.join(dir, item);
66
+ const stat = fs.statSync(itemPath);
67
+
68
+ if (stat.isDirectory()) {
69
+ // 跳过 node_modules 和 dist
70
+ if (item !== 'node_modules' && item !== 'dist' && item !== '.git') {
71
+ fixedCount += processDirectory(itemPath);
72
+ }
73
+ } else if (item.endsWith('.ts') && !item.endsWith('.d.ts')) {
74
+ if (fixFile(itemPath)) {
75
+ fixedCount++;
76
+ }
77
+ }
78
+ });
79
+
80
+ return fixedCount;
81
+ }
82
+
83
+ // 主函数
84
+ function main() {
85
+ console.log('🔧 将 @/ 路径别名转换为相对路径...\n');
86
+
87
+ const fixedCount = processDirectory(srcDir);
88
+
89
+ console.log(`\n✅ 完成!修复了 ${fixedCount} 个文件`);
90
+ console.log('\n⚠️ 请运行以下命令验证:');
91
+ console.log(' npm run build');
92
+ console.log(' node dist/index.js');
93
+ }
94
+
95
+ main();