@myassis/gateway 1.0.3 → 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();
@@ -5,7 +5,7 @@
5
5
  * 使用 SQLite 数据库存储任务
6
6
  */
7
7
  import { v4 as uuidv4 } from 'uuid';
8
- import { TaskStore } from './task/TaskStore.js';
8
+ import { TaskStore } from './task/TaskStore';
9
9
  import { getLogger, sharedTaskService, formatUTCForLog } from '@myassis/shared';
10
10
  const logger = getLogger('LocalTaskService');
11
11
  class LocalTaskService {
@@ -3,9 +3,9 @@
3
3
  * 负责发送任务通知
4
4
  * 优先级:WebSocket > HMS Push (华为) / Expo Push (其他)
5
5
  */
6
- import { PushTokenStore } from './task/PushTokenStore.js';
7
- import { webSocketService } from './WebSocketService.js';
8
- import { hmsPushService } from './HMSPushService.js';
6
+ import { PushTokenStore } from './task/PushTokenStore';
7
+ import { webSocketService } from './WebSocketService';
8
+ import { hmsPushService } from './HMSPushService';
9
9
  import { getLogger } from '@myassis/shared';
10
10
  const logger = getLogger('NotificationService');
11
11
  const log = logger;
@@ -3,12 +3,12 @@
3
3
  * 基于 SQLite 数据库的任务调度
4
4
  * 每分钟检查待执行任务并发送通知
5
5
  */
6
- import { taskStore } from './task/TaskStore.js';
7
- import { webSocketService } from './WebSocketService.js';
8
- import { getSessionManager } from './session.js';
6
+ import { taskStore } from './task/TaskStore';
7
+ import { webSocketService } from './WebSocketService';
8
+ import { getSessionManager } from './session';
9
9
  import { getLogger, getUTCTimeKey, formatUTCForLog, holidayService } from '@myassis/shared';
10
- import { tasksService } from './dataService.js';
11
- import { authStore } from '@/stores';
10
+ import { tasksService } from './dataService';
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,9 +7,9 @@
7
7
  * - platformApply === currentPlatform → 本地 SQLite 存储(localTaskService)
8
8
  * - platformApply !== currentPlatform → 服务器 API(tasksApi)
9
9
  */
10
- import { authStore } from '@/stores';
11
- import { tasksApi } from '../api.js';
12
- import { localTaskService } from './LocalTaskService.js';
10
+ import { authStore } from '..\stores.js';
11
+ import { tasksApi } from '../api';
12
+ import { localTaskService } from './LocalTaskService';
13
13
  import { getLogger } from '@myassis/shared';
14
14
  import { getPlatform } from '@myassis/shared/dist/utils/system.js';
15
15
  // 当前网关平台标识
@@ -1,5 +1,5 @@
1
1
  import { v4 as uuidv4 } from 'uuid';
2
- import { getSessionManager } from '../session/SessionManager.js';
2
+ import { getSessionManager } from '../session/SessionManager';
3
3
  /**
4
4
  * Agent - Business logic entity
5
5
  * Represents an AI agent with independent system prompt and multiple sessions
@@ -1,9 +1,9 @@
1
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';
2
+ import { Agent } from './Agent';
3
+ import { getSessionManager } from '../session/SessionManager';
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
@@ -7,9 +7,9 @@
7
7
  * - /api/v1/data/* - 用户数据路由 (models, skills, tasks, settings)
8
8
  * - /api/v1/skill-hubs/* - 技能库路由
9
9
  */
10
- import { authApi, skillsApi, skillHubApi, modelsApi, settingsApi } from '../api/index.js';
11
- import { authStore, memoryStore, persistStore } from '../stores/index.js';
12
- import { taskService } from './TaskService.js';
10
+ import { authApi, skillsApi, skillHubApi, modelsApi, settingsApi } from '../api';
11
+ import { authStore, memoryStore, persistStore } from '../stores';
12
+ import { taskService } from './TaskService';
13
13
  import { getLogger } from '@myassis/shared';
14
14
  const logger = getLogger('DataService');
15
15
  // ============ 认证服务 ============
@@ -1,15 +1,15 @@
1
1
  // Re-export all services from dataService
2
- export { authService, skillsService, skillHubService, modelsService, settingsService, } from './dataService.js';
2
+ export { authService, skillsService, skillHubService, modelsService, settingsService, } from './dataService';
3
3
  // Re-export tasksService from dataService (server-only tasks)
4
- export { tasksService } from './dataService.js';
4
+ export { tasksService } from './dataService';
5
5
  // Re-export session manager
6
- export { getSessionManager } from './session.js';
6
+ export { getSessionManager } from './session';
7
7
  // Re-export task services
8
- export { taskSchedulerService } from './TaskSchedulerService.js';
9
- export { taskService } from './TaskService.js';
10
- export { localTaskService } from './LocalTaskService.js';
8
+ export { taskSchedulerService } from './TaskSchedulerService';
9
+ export { taskService } from './TaskService';
10
+ export { localTaskService } from './LocalTaskService';
11
11
  // Re-export notification and holiday services
12
- export { notificationService } from './NotificationService.js';
12
+ export { notificationService } from './NotificationService';
13
13
  // Re-export task stores
14
- export { TaskStore } from './task/TaskStore.js';
15
- export { PushTokenStore } from './task/PushTokenStore.js';
14
+ export { TaskStore } from './task/TaskStore';
15
+ export { PushTokenStore } from './task/PushTokenStore';
@@ -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');
@@ -1,10 +1,10 @@
1
1
  import { getLogger } from '@myassis/shared';
2
2
  const logger = getLogger('MemoryManager');
3
- import { toModel } from '../models.js';
4
- import { modelsService } from '../dataService.js';
5
- import { authStore } from '@/stores';
6
- import { LLMClient } from '../llm/LLMClient.js';
7
- import { appConfig } from '@/config';
3
+ import { toModel } from '../models';
4
+ import { modelsService } from '../dataService';
5
+ import { authStore } from '..\..\stores.js';
6
+ import { LLMClient } from '../llm/LLMClient';
7
+ import { appConfig } from '..\..\config.js';
8
8
  const DEFAULT_CONFIG = {
9
9
  summaryThreshold: 10,
10
10
  enabled: true,
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * 模型选择模块
3
3
  */
4
- export * from './ModelCapabilities.js';
4
+ export * from './ModelCapabilities';
@@ -1,16 +1,16 @@
1
1
  import { v4 as uuidv4 } from 'uuid';
2
2
  import { getLogger } from '@myassis/shared';
3
- import { SessionStore } from './SessionStore.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
- import { getSystemPromptAsync } from '../systemPrompt.js';
9
- import { LLMClient, parseAruments } from '../llm/LLMClient.js';
10
- import { modelsService, settingsService } from '@/services/dataService';
11
- import { MemoryManager } from '../memory/MemoryManager.js';
12
- import { appConfig } from '@/config';
13
- import { getSessionManager } from './SessionManager.js';
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';
8
+ import { getSystemPromptAsync } from '../systemPrompt';
9
+ import { LLMClient, parseAruments } from '../llm/LLMClient';
10
+ import { modelsService, settingsService } from '..\dataService.js';
11
+ import { MemoryManager } from '../memory/MemoryManager';
12
+ import { appConfig } from '..\..\config.js';
13
+ import { getSessionManager } from './SessionManager';
14
14
  const logger = getLogger('Session');
15
15
  const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
16
16
  // AgentStore 单例 - 需要通过 SessionStore 获取数据库实例
@@ -1,9 +1,9 @@
1
1
  import { v4 as uuidv4 } from 'uuid';
2
2
  import { getLogger } from '@myassis/shared';
3
3
  const logger = getLogger('SessionManager');
4
- import { sessionStore } from './SessionStore.js';
5
- import { authStore } from '@/stores/authStore';
6
- import { Session } from './Session.js';
4
+ import { sessionStore } from './SessionStore';
5
+ import { authStore } from '..\..\stores\authStore.js';
6
+ import { Session } from './Session';
7
7
  /**
8
8
  * SessionManager - Business logic layer
9
9
  * Manages sessions in memory
@@ -2,7 +2,7 @@ import Database from 'better-sqlite3';
2
2
  import path from 'path';
3
3
  import fs from 'fs';
4
4
  import { getLogger } from '@myassis/shared';
5
- import { MigrationManager } from './MigrationManager.js';
5
+ import { MigrationManager } from './MigrationManager';
6
6
  const logger = getLogger('SessionStore');
7
7
  /**
8
8
  * SessionStore - Data access layer
@@ -1,3 +1,3 @@
1
1
  // 导出 SessionManager(业务逻辑层)
2
- export { SessionManager, getSessionManager } from './SessionManager.js';
3
- export { Session } from './Session.js';
2
+ export { SessionManager, getSessionManager } from './SessionManager';
3
+ export { Session } from './Session';
@@ -1,6 +1,6 @@
1
- import { authStore } from '@/stores';
1
+ import { authStore } from '..\stores.js';
2
2
  import os from 'os';
3
- import { settingsService, skillsService } from './dataService.js';
3
+ import { settingsService, skillsService } from './dataService';
4
4
  import { getLogger } from '@myassis/shared';
5
5
  const logger = getLogger('SystemPrompt');
6
6
  // 预设的对话风格模板
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import { getLogger } from '@myassis/shared';
6
6
  const logger = getLogger('PushTokenStore');
7
- import { sessionStore } from '../session/SessionStore.js';
7
+ import { sessionStore } from '../session/SessionStore';
8
8
  export class PushTokenStore {
9
9
  db;
10
10
  constructor() {
@@ -3,7 +3,7 @@
3
3
  * 操作 SQLite 数据库,与 AgentStore/SessionStore 共享同一个数据库实例
4
4
  */
5
5
  import { getLogger } from '@myassis/shared';
6
- import { sessionStore } from '../session/SessionStore.js';
6
+ import { sessionStore } from '../session/SessionStore';
7
7
  const logger = getLogger('TaskStore');
8
8
  function rowToTaskData(row) {
9
9
  return {
@@ -1,21 +1,21 @@
1
1
  /**
2
2
  * 工具定义集合
3
3
  */
4
- export * from './types.js';
5
- import { searchTool } from './search.js';
6
- import { calculatorTool } from './calculator.js';
7
- import { screenshotTool } from './screenshot.js';
8
- import { keyboardTool } from './keyboard.js';
9
- import { mouseTool } from './mouse.js';
10
- import { fetchTool } from './fetch.js';
11
- import { skillTool } from './skill.js';
12
- import { execTool } from './exec.js';
13
- import { fileTool } from './file.js';
14
- import { taskTool } from './task.js';
15
- import { modelTool } from './model.js';
16
- import { editTool } from './edit.js';
17
- import { webFetchTool } from './webFetch.js';
18
- import { sessionsSpawnTool } from './sessionsSpawn.js';
4
+ export * from './types';
5
+ import { searchTool } from './search';
6
+ import { calculatorTool } from './calculator';
7
+ import { screenshotTool } from './screenshot';
8
+ import { keyboardTool } from './keyboard';
9
+ import { mouseTool } from './mouse';
10
+ import { fetchTool } from './fetch';
11
+ import { skillTool } from './skill';
12
+ import { execTool } from './exec';
13
+ import { fileTool } from './file';
14
+ import { taskTool } from './task';
15
+ import { modelTool } from './model';
16
+ import { editTool } from './edit';
17
+ import { webFetchTool } from './webFetch';
18
+ import { sessionsSpawnTool } from './sessionsSpawn';
19
19
  export const tools = [
20
20
  searchTool, calculatorTool, screenshotTool, keyboardTool, mouseTool,
21
21
  skillTool, execTool, taskTool, modelTool, fetchTool,
@@ -1,5 +1,5 @@
1
- import { modelsService } from '../dataService.js';
2
- import { authStore } from '@/stores';
1
+ import { modelsService } from '../dataService';
2
+ import { authStore } from '..\..\stores.js';
3
3
  export const modelTool = {
4
4
  name: 'model',
5
5
  description: '模型管理工具',
@@ -1,6 +1,6 @@
1
1
  import { v4 as uuidv4 } from 'uuid';
2
2
  import { getLogger } from '@myassis/shared';
3
- import { getSessionManager } from '../session.js';
3
+ import { getSessionManager } from '../session';
4
4
  const logger = getLogger('sessionsSpawn');
5
5
  export const sessionsSpawnTool = {
6
6
  name: 'sessions_spawn',
@@ -1,5 +1,5 @@
1
- import { skillsService, skillHubService } from '../dataService.js';
2
- import { authStore, persistStore } from '@/stores';
1
+ import { skillsService, skillHubService } from '../dataService';
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 = {
@@ -1,4 +1,4 @@
1
- import { tasksService } from '../dataService.js';
1
+ import { tasksService } from '../dataService';
2
2
  import { validPlatformApplies, getPlatform } from '@myassis/shared/dist/utils/system.js';
3
3
  export const taskTool = {
4
4
  name: 'task',
@@ -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');
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Gateway Stores 统一导出
3
3
  */
4
- export { memoryStore } from './memoryStore.js';
5
- export { persistStore } from './persistStore.js';
6
- export { authStore } from './authStore.js';
4
+ export { memoryStore } from './memoryStore';
5
+ export { persistStore } from './persistStore';
6
+ export { authStore } from './authStore';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myassis/gateway",
3
- "version": "1.0.3",
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/fix-dist-imports.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
+ * 将 @/ 路径别名转换为相对路径
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();