@myassis/gateway 1.0.18 → 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.
- package/dist/api/index.js +27 -19
- package/dist/cli.js +18 -5
- package/dist/config/index.js +34 -11
- package/dist/index.js +1 -2
- package/dist/main.js +76 -71
- package/dist/middleware/auth.js +9 -5
- package/dist/middleware/errorHandler.js +9 -4
- package/dist/routes/agent.js +39 -37
- package/dist/routes/auth.js +32 -30
- package/dist/routes/chat.js +7 -5
- package/dist/routes/config.js +5 -3
- package/dist/routes/models.js +28 -23
- package/dist/routes/service.js +29 -24
- package/dist/routes/settings.js +26 -21
- package/dist/routes/skillHub.js +22 -17
- package/dist/routes/skills.js +25 -20
- package/dist/routes/tasks.js +24 -19
- package/dist/routes/upload.js +24 -17
- package/dist/routes/version.js +20 -19
- package/dist/services/HMSPushService.js +4 -1
- package/dist/services/LocalTaskService.js +12 -9
- package/dist/services/NotificationService.js +14 -11
- package/dist/services/ServiceManager.js +77 -65
- package/dist/services/TaskSchedulerService.js +33 -30
- package/dist/services/TaskService.js +27 -24
- package/dist/services/WebSocketService.js +14 -11
- package/dist/services/agent/Agent.js +13 -9
- package/dist/services/agent/AgentManager.js +32 -24
- package/dist/services/agent/AgentStore.js +7 -3
- package/dist/services/dataService.js +72 -69
- package/dist/services/index.js +25 -9
- package/dist/services/llm/LLMClient.js +17 -9
- package/dist/services/memory/MemoryManager.js +22 -18
- package/dist/services/model/ModelCapabilities.js +11 -7
- package/dist/services/model/index.js +17 -1
- package/dist/services/models.js +5 -1
- package/dist/services/session/MigrationManager.js +18 -11
- package/dist/services/session/Session.js +33 -29
- package/dist/services/session/SessionManager.js +26 -21
- package/dist/services/session/SessionStore.js +32 -25
- package/dist/services/session/index.js +8 -2
- package/dist/services/skills.js +4 -1
- package/dist/services/systemPrompt.js +23 -16
- package/dist/services/task/PushTokenStore.js +9 -5
- package/dist/services/task/TaskStore.js +10 -6
- package/dist/services/tools/calculator.js +4 -1
- package/dist/services/tools/edit.js +16 -10
- package/dist/services/tools/exec.js +25 -16
- package/dist/services/tools/fetch.js +30 -4
- package/dist/services/tools/file.js +41 -35
- package/dist/services/tools/index.js +44 -24
- package/dist/services/tools/keyboard.js +41 -38
- package/dist/services/tools/model.js +12 -9
- package/dist/services/tools/mouse.js +12 -9
- package/dist/services/tools/screenshot.js +9 -3
- package/dist/services/tools/search.js +34 -4
- package/dist/services/tools/sessionsSpawn.js +11 -8
- package/dist/services/tools/skill.js +19 -16
- package/dist/services/tools/task.js +12 -9
- package/dist/services/tools/types.js +2 -1
- package/dist/services/tools/webFetch.js +34 -4
- package/dist/stores/authStore.js +25 -19
- package/dist/stores/index.js +9 -3
- package/dist/stores/memoryStore.js +5 -2
- package/dist/stores/persistStore.js +20 -14
- package/package.json +11 -20
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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.screenshotTool = void 0;
|
|
7
|
+
const screenshot_desktop_1 = __importDefault(require("screenshot-desktop"));
|
|
8
|
+
exports.screenshotTool = {
|
|
3
9
|
name: 'screenshot',
|
|
4
10
|
description: '截取当前电脑屏幕的截图,这个操作属于危险操作,没有用户的主动允许禁止使用',
|
|
5
11
|
parameters: { type: 'object', properties: {}, required: [] },
|
|
6
12
|
handler: async () => {
|
|
7
13
|
try {
|
|
8
|
-
const imgBuffer = await
|
|
14
|
+
const imgBuffer = await (0, screenshot_desktop_1.default)({ format: 'jpeg', quality: 20 });
|
|
9
15
|
const base64 = imgBuffer.toString('base64');
|
|
10
16
|
return {
|
|
11
17
|
success: true,
|
|
@@ -1,6 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.searchTool = void 0;
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
const got_1 = __importDefault(require("got"));
|
|
32
|
+
const cheerio = __importStar(require("cheerio"));
|
|
33
|
+
exports.searchTool = {
|
|
4
34
|
name: 'search',
|
|
5
35
|
description: '执行网络搜索',
|
|
6
36
|
parameters: {
|
|
@@ -14,7 +44,7 @@ export const searchTool = {
|
|
|
14
44
|
handler: async (args) => {
|
|
15
45
|
try {
|
|
16
46
|
const { query, limit = 5 } = args;
|
|
17
|
-
const response = await
|
|
47
|
+
const response = await (0, got_1.default)(`https://cn.bing.com/search?q=${encodeURIComponent(query)}`, {
|
|
18
48
|
headers: {
|
|
19
49
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
|
|
20
50
|
'Accept-Language': 'zh-CN,zh;q=0.9',
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sessionsSpawnTool = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
5
|
+
const shared_1 = require("@myassis/shared");
|
|
6
|
+
const index_js_1 = require("../session/index.js");
|
|
7
|
+
const logger = (0, shared_1.getLogger)('sessionsSpawn');
|
|
8
|
+
exports.sessionsSpawnTool = {
|
|
6
9
|
name: 'sessions_spawn',
|
|
7
10
|
description: '派发一个子 Agent 执行独立任务,阻塞等待完成后返回结果。' +
|
|
8
11
|
'适用于需要并行处理或隔离上下文的任务。' +
|
|
@@ -25,12 +28,12 @@ export const sessionsSpawnTool = {
|
|
|
25
28
|
if (!userId) {
|
|
26
29
|
return { success: false, errorMessage: '未登录,无法创建子 Agent Session' };
|
|
27
30
|
}
|
|
28
|
-
const sessionManager = getSessionManager(userId);
|
|
31
|
+
const sessionManager = (0, index_js_1.getSessionManager)(userId);
|
|
29
32
|
// 创建子 Agent Session
|
|
30
33
|
const childSession = sessionManager.getSession(sessionId);
|
|
31
34
|
logger.info(`子 Agent Session 已创建: ${childSession.id}`);
|
|
32
|
-
const userMessageId =
|
|
33
|
-
const assistantMessageId =
|
|
35
|
+
const userMessageId = (0, uuid_1.v4)();
|
|
36
|
+
const assistantMessageId = (0, uuid_1.v4)();
|
|
34
37
|
try {
|
|
35
38
|
// 阻塞等待子 Agent 完成(res=null,不向客户端 SSE 推送)
|
|
36
39
|
const result = await childSession.streamChat(prompt, [], null, userMessageId, assistantMessageId, true);
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.skillTool = void 0;
|
|
4
|
+
const dataService_js_1 = require("../dataService.js");
|
|
5
|
+
const index_js_1 = require("../../stores/index.js");
|
|
6
|
+
const shared_1 = require("@myassis/shared");
|
|
7
|
+
const logger = (0, shared_1.getLogger)('skill');
|
|
8
|
+
exports.skillTool = {
|
|
6
9
|
name: 'skill',
|
|
7
10
|
description: '技能管理工具',
|
|
8
11
|
parameters: {
|
|
@@ -25,17 +28,17 @@ export const skillTool = {
|
|
|
25
28
|
handler: async (args, sessionId, messageId, userId) => {
|
|
26
29
|
try {
|
|
27
30
|
const { action, query, skillId, hubId, apiKey, apiBaseUrl, rating } = args;
|
|
28
|
-
const token = authStore.get(userId).accessToken;
|
|
31
|
+
const token = index_js_1.authStore.get(userId).accessToken;
|
|
29
32
|
switch (action) {
|
|
30
33
|
case 'listInstalled': {
|
|
31
|
-
const response = await skillsService.list(token);
|
|
34
|
+
const response = await dataService_js_1.skillsService.list(token);
|
|
32
35
|
if (!response.success)
|
|
33
36
|
return { success: false, errorMessage: response.error || '获取列表失败' };
|
|
34
37
|
const skills = response.data || [];
|
|
35
38
|
return { success: true, output: JSON.stringify({ total: skills.length, skills: skills.map((s) => ({ id: s.id, name: s.name, description: s.description, version: s.version, status: s.status })) }) };
|
|
36
39
|
}
|
|
37
40
|
case 'search': {
|
|
38
|
-
const response = await skillHubService.list(token, { keyword: query, pageSize: 10 });
|
|
41
|
+
const response = await dataService_js_1.skillHubService.list(token, { keyword: query, pageSize: 10 });
|
|
39
42
|
if (!response.success)
|
|
40
43
|
return { success: false, errorMessage: response.error || '搜索失败' };
|
|
41
44
|
const skills = response.data?.items || response.data || [];
|
|
@@ -45,7 +48,7 @@ export const skillTool = {
|
|
|
45
48
|
const installId = hubId || query;
|
|
46
49
|
if (!installId)
|
|
47
50
|
return { success: false, errorMessage: '安装需要提供 hubId 或 query' };
|
|
48
|
-
const response = await skillsService.install(installId, token);
|
|
51
|
+
const response = await dataService_js_1.skillsService.install(installId, token);
|
|
49
52
|
if (!response.success)
|
|
50
53
|
return { success: false, errorMessage: response.error || '安装失败' };
|
|
51
54
|
return { success: true };
|
|
@@ -53,7 +56,7 @@ export const skillTool = {
|
|
|
53
56
|
case 'uninstall': {
|
|
54
57
|
if (!skillId)
|
|
55
58
|
return { success: false, errorMessage: '卸载需要提供技能 ID' };
|
|
56
|
-
const response = await skillsService.uninstall(skillId, token);
|
|
59
|
+
const response = await dataService_js_1.skillsService.uninstall(skillId, token);
|
|
57
60
|
if (!response.success)
|
|
58
61
|
return { success: false, errorMessage: response.error || '卸载失败' };
|
|
59
62
|
return { success: true };
|
|
@@ -61,21 +64,21 @@ export const skillTool = {
|
|
|
61
64
|
case 'detail': {
|
|
62
65
|
if (!skillId)
|
|
63
66
|
return { success: false, errorMessage: '查看详情需要提供技能 ID' };
|
|
64
|
-
const response = await skillsService.get(skillId, token);
|
|
67
|
+
const response = await dataService_js_1.skillsService.get(skillId, token);
|
|
65
68
|
if (!response.success)
|
|
66
69
|
return { success: false, errorMessage: response.error || '获取详情失败' };
|
|
67
70
|
// 表明该技能已被使用
|
|
68
71
|
const detailHubId = response.data?.templateId;
|
|
69
72
|
if (detailHubId) {
|
|
70
|
-
skillHubService.use(detailHubId, token).catch((err) => logger.warn('技能使用记录失败:', err?.message));
|
|
73
|
+
dataService_js_1.skillHubService.use(detailHubId, token).catch((err) => logger.warn('技能使用记录失败:', err?.message));
|
|
71
74
|
}
|
|
72
|
-
const apikey = await skillsService.getApiKey(skillId, token);
|
|
75
|
+
const apikey = await dataService_js_1.skillsService.getApiKey(skillId, token);
|
|
73
76
|
return { success: true, output: JSON.stringify({ skill: { ...response.data, apiKey: apikey.apiKey } }) };
|
|
74
77
|
}
|
|
75
78
|
case 'setApiKey': {
|
|
76
79
|
if (!skillId || !apiKey)
|
|
77
80
|
return { success: false, errorMessage: '设置 API Key 需要提供技能 ID 和 API Key' };
|
|
78
|
-
const response = await skillsService.setApiKey(skillId, apiKey, token);
|
|
81
|
+
const response = await dataService_js_1.skillsService.setApiKey(skillId, apiKey, token);
|
|
79
82
|
if (!response)
|
|
80
83
|
return { success: false, errorMessage: '设置失败' };
|
|
81
84
|
return { success: true };
|
|
@@ -85,7 +88,7 @@ export const skillTool = {
|
|
|
85
88
|
return { success: false, errorMessage: '评分需要提供 hubId 和评分(1-5)' };
|
|
86
89
|
if (rating < 1 || rating > 5)
|
|
87
90
|
return { success: false, errorMessage: '评分必须是 1-5 之间的整数' };
|
|
88
|
-
const response = await skillHubService.rate(hubId, rating, token);
|
|
91
|
+
const response = await dataService_js_1.skillHubService.rate(hubId, rating, token);
|
|
89
92
|
if (!response.success)
|
|
90
93
|
return { success: false, errorMessage: response.error || '评分失败' };
|
|
91
94
|
return { success: true };
|
|
@@ -93,7 +96,7 @@ export const skillTool = {
|
|
|
93
96
|
case 'getApiKey': {
|
|
94
97
|
if (!skillId)
|
|
95
98
|
return { success: false, errorMessage: '获取 API Key 需要提供技能 ID' };
|
|
96
|
-
const apikey = persistStore.getSkillApiKey(skillId);
|
|
99
|
+
const apikey = index_js_1.persistStore.getSkillApiKey(skillId);
|
|
97
100
|
if (apikey)
|
|
98
101
|
return { success: true, output: JSON.stringify({ apiKey: apikey.apiKey }) };
|
|
99
102
|
return { success: false, errorMessage: '未找到 API Key' };
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.taskTool = void 0;
|
|
4
|
+
const dataService_js_1 = require("../dataService.js");
|
|
5
|
+
const system_js_1 = require("@myassis/shared/dist/utils/system.js");
|
|
6
|
+
exports.taskTool = {
|
|
4
7
|
name: 'task',
|
|
5
8
|
description: '任务管理工具',
|
|
6
9
|
parameters: {
|
|
@@ -20,7 +23,7 @@ export const taskTool = {
|
|
|
20
23
|
startTime: { type: 'string', description: '开始时间' },
|
|
21
24
|
endTime: { type: 'string', description: '结束时间' },
|
|
22
25
|
scheduledAt: { type: 'string', description: '计划执行时间' },
|
|
23
|
-
platformApply: { type: 'string', description: '适用平台', enum: validPlatformApplies, default: getPlatform() },
|
|
26
|
+
platformApply: { type: 'string', description: '适用平台', enum: system_js_1.validPlatformApplies, default: (0, system_js_1.getPlatform)() },
|
|
24
27
|
status: { type: 'string', description: '任务状态筛选', enum: ['pending', 'doing', 'done', 'cancelled'] },
|
|
25
28
|
taskId: { type: 'string', description: '任务 ID(update/delete)' },
|
|
26
29
|
newTitle: { type: 'string', description: '新标题(update)' },
|
|
@@ -56,14 +59,14 @@ export const taskTool = {
|
|
|
56
59
|
if (!userId) {
|
|
57
60
|
return { success: false, errorMessage: '未登录' };
|
|
58
61
|
}
|
|
59
|
-
createData.platformApply = platformApply || getPlatform();
|
|
60
|
-
const response = await tasksService.create(createData, String(userId));
|
|
62
|
+
createData.platformApply = platformApply || (0, system_js_1.getPlatform)();
|
|
63
|
+
const response = await dataService_js_1.tasksService.create(createData, String(userId));
|
|
61
64
|
if (!response.success)
|
|
62
65
|
return { success: false, errorMessage: response.error || '创建任务失败' };
|
|
63
66
|
return { success: true, output: JSON.stringify({ task: response.data }) };
|
|
64
67
|
}
|
|
65
68
|
case 'list': {
|
|
66
|
-
const response = await tasksService.list(userId, { status });
|
|
69
|
+
const response = await dataService_js_1.tasksService.list(userId, { status });
|
|
67
70
|
if (!response.success)
|
|
68
71
|
return { success: false, errorMessage: '获取任务列表失败' };
|
|
69
72
|
const tasks = response.data || [];
|
|
@@ -84,7 +87,7 @@ export const taskTool = {
|
|
|
84
87
|
updateData.recurrenceRule = newRecurrenceRule;
|
|
85
88
|
if (newScheduledAt !== undefined)
|
|
86
89
|
updateData.scheduledAt = newScheduledAt;
|
|
87
|
-
const response = await tasksService.update(taskId, updateData);
|
|
90
|
+
const response = await dataService_js_1.tasksService.update(taskId, updateData);
|
|
88
91
|
if (!response.success)
|
|
89
92
|
return { success: false, errorMessage: response.error || '更新任务失败' };
|
|
90
93
|
return { success: true };
|
|
@@ -92,7 +95,7 @@ export const taskTool = {
|
|
|
92
95
|
case 'delete': {
|
|
93
96
|
if (!taskId)
|
|
94
97
|
return { success: false, errorMessage: '删除任务需要提供任务 ID(taskId)' };
|
|
95
|
-
const response = await tasksService.delete(taskId);
|
|
98
|
+
const response = await dataService_js_1.tasksService.delete(taskId);
|
|
96
99
|
if (!response.success)
|
|
97
100
|
return { success: false, errorMessage: response.error || '删除任务失败' };
|
|
98
101
|
return { success: true };
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,6 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.webFetchTool = void 0;
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
const got_1 = __importDefault(require("got"));
|
|
32
|
+
const cheerio = __importStar(require("cheerio"));
|
|
33
|
+
exports.webFetchTool = {
|
|
4
34
|
name: 'webFetch',
|
|
5
35
|
description: '获取网页内容,支持 JavaScript 渲染',
|
|
6
36
|
parameters: {
|
|
@@ -14,7 +44,7 @@ export const webFetchTool = {
|
|
|
14
44
|
handler: async (args) => {
|
|
15
45
|
try {
|
|
16
46
|
const { url, query } = args;
|
|
17
|
-
const response = await
|
|
47
|
+
const response = await (0, got_1.default)(url, {
|
|
18
48
|
headers: {
|
|
19
49
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
|
|
20
50
|
},
|
package/dist/stores/authStore.js
CHANGED
|
@@ -1,30 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Gateway 认证存储模块
|
|
3
4
|
* 负责管理 Token 和用户信息的内存存储与持久化
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.authStore = void 0;
|
|
11
|
+
const fs_1 = __importDefault(require("fs"));
|
|
12
|
+
const path_1 = __importDefault(require("path"));
|
|
13
|
+
const os_1 = __importDefault(require("os"));
|
|
14
|
+
const shared_1 = require("@myassis/shared");
|
|
15
|
+
const index_js_1 = require("../services/session/index.js");
|
|
16
|
+
const logger = (0, shared_1.getLogger)('authStore');
|
|
11
17
|
// 认证数据存储文件路径(使用应用数据目录,支持 STORAGE_DIR 环境变量)
|
|
12
|
-
const AUTH_STORAGE_DIR = process.env.STORAGE_DIR ||
|
|
13
|
-
const AUTH_STORAGE_FILE =
|
|
18
|
+
const AUTH_STORAGE_DIR = process.env.STORAGE_DIR || path_1.default.join(os_1.default.homedir(), 'myassis-gateway-storage');
|
|
19
|
+
const AUTH_STORAGE_FILE = path_1.default.join(AUTH_STORAGE_DIR, 'auth', 'auth.json');
|
|
14
20
|
// 内存中的认证数据
|
|
15
21
|
let authMap = null;
|
|
16
22
|
// 确保存储目录存在
|
|
17
23
|
function ensureStorageDir() {
|
|
18
|
-
const dir =
|
|
19
|
-
if (!
|
|
20
|
-
|
|
24
|
+
const dir = path_1.default.dirname(AUTH_STORAGE_FILE);
|
|
25
|
+
if (!fs_1.default.existsSync(dir)) {
|
|
26
|
+
fs_1.default.mkdirSync(dir, { recursive: true });
|
|
21
27
|
}
|
|
22
28
|
}
|
|
23
29
|
// 从本地文件加载认证数据
|
|
24
30
|
function loadFromFile() {
|
|
25
31
|
try {
|
|
26
|
-
if (
|
|
27
|
-
const data =
|
|
32
|
+
if (fs_1.default.existsSync(AUTH_STORAGE_FILE)) {
|
|
33
|
+
const data = fs_1.default.readFileSync(AUTH_STORAGE_FILE, 'utf-8');
|
|
28
34
|
const obj = JSON.parse(data);
|
|
29
35
|
logger.debug('Auth data loaded from file');
|
|
30
36
|
return new Map(Object.entries(obj));
|
|
@@ -39,7 +45,7 @@ function loadFromFile() {
|
|
|
39
45
|
function saveAuthToFile(authMap) {
|
|
40
46
|
ensureStorageDir();
|
|
41
47
|
try {
|
|
42
|
-
|
|
48
|
+
fs_1.default.writeFileSync(AUTH_STORAGE_FILE, JSON.stringify(Object.fromEntries(authMap)), 'utf-8');
|
|
43
49
|
logger.debug('Auth data saved to file');
|
|
44
50
|
}
|
|
45
51
|
catch (error) {
|
|
@@ -49,8 +55,8 @@ function saveAuthToFile(authMap) {
|
|
|
49
55
|
// 清除本地认证文件
|
|
50
56
|
function clearAuthFile() {
|
|
51
57
|
try {
|
|
52
|
-
if (
|
|
53
|
-
|
|
58
|
+
if (fs_1.default.existsSync(AUTH_STORAGE_FILE)) {
|
|
59
|
+
fs_1.default.unlinkSync(AUTH_STORAGE_FILE);
|
|
54
60
|
logger.debug('Auth file cleared');
|
|
55
61
|
}
|
|
56
62
|
}
|
|
@@ -66,7 +72,7 @@ function clearAuth() {
|
|
|
66
72
|
/**
|
|
67
73
|
* 认证存储管理器
|
|
68
74
|
*/
|
|
69
|
-
|
|
75
|
+
exports.authStore = {
|
|
70
76
|
/**
|
|
71
77
|
* 初始化:从本地加载认证数据到内存
|
|
72
78
|
* 应在 Gateway 启动时调用
|
|
@@ -87,7 +93,7 @@ export const authStore = {
|
|
|
87
93
|
authMap.set(authData.user.id, authData);
|
|
88
94
|
saveAuthToFile(authMap);
|
|
89
95
|
// 用户登录后初始化 SessionManager
|
|
90
|
-
getSessionManager(authData.user.id).initialize();
|
|
96
|
+
(0, index_js_1.getSessionManager)(authData.user.id).initialize();
|
|
91
97
|
logger.debug('Auth saved for user:', authData.user.nickname);
|
|
92
98
|
},
|
|
93
99
|
//获取所有认证用户
|
|
@@ -161,4 +167,4 @@ export const authStore = {
|
|
|
161
167
|
}
|
|
162
168
|
},
|
|
163
169
|
};
|
|
164
|
-
|
|
170
|
+
exports.default = exports.authStore;
|
package/dist/stores/index.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Gateway Stores 统一导出
|
|
3
4
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.authStore = exports.persistStore = exports.memoryStore = void 0;
|
|
7
|
+
var memoryStore_js_1 = require("./memoryStore.js");
|
|
8
|
+
Object.defineProperty(exports, "memoryStore", { enumerable: true, get: function () { return memoryStore_js_1.memoryStore; } });
|
|
9
|
+
var persistStore_js_1 = require("./persistStore.js");
|
|
10
|
+
Object.defineProperty(exports, "persistStore", { enumerable: true, get: function () { return persistStore_js_1.persistStore; } });
|
|
11
|
+
var authStore_js_1 = require("./authStore.js");
|
|
12
|
+
Object.defineProperty(exports, "authStore", { enumerable: true, get: function () { return authStore_js_1.authStore; } });
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Gateway 内存存储模块
|
|
3
4
|
* 用于缓存用户会话、API 响应等临时数据
|
|
4
5
|
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.memoryStore = void 0;
|
|
5
8
|
// 内存缓存
|
|
6
9
|
const cache = new Map();
|
|
7
10
|
// 默认过期时间(毫秒)
|
|
@@ -22,7 +25,7 @@ setInterval(() => {
|
|
|
22
25
|
/**
|
|
23
26
|
* 内存存储管理器
|
|
24
27
|
*/
|
|
25
|
-
|
|
28
|
+
exports.memoryStore = {
|
|
26
29
|
/**
|
|
27
30
|
* 设置缓存
|
|
28
31
|
*/
|
|
@@ -188,4 +191,4 @@ export const memoryStore = {
|
|
|
188
191
|
keysToDelete.forEach(key => cache.delete(key));
|
|
189
192
|
}
|
|
190
193
|
};
|
|
191
|
-
|
|
194
|
+
exports.default = exports.memoryStore;
|
|
@@ -1,19 +1,25 @@
|
|
|
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.persistStore = void 0;
|
|
1
7
|
/**
|
|
2
8
|
* Gateway 持久化存储模块
|
|
3
9
|
* 用于存储配置、限流数据等需要持久化的数据
|
|
4
10
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const logger = getLogger('persistStore');
|
|
11
|
+
const fs_1 = __importDefault(require("fs"));
|
|
12
|
+
const os_1 = __importDefault(require("os"));
|
|
13
|
+
const path_1 = __importDefault(require("path"));
|
|
14
|
+
const shared_1 = require("@myassis/shared");
|
|
15
|
+
const logger = (0, shared_1.getLogger)('persistStore');
|
|
10
16
|
// 存储文件路径(跨平台兼容)
|
|
11
|
-
const STORAGE_DIR = process.env.STORAGE_DIR ||
|
|
12
|
-
const STORAGE_FILE =
|
|
17
|
+
const STORAGE_DIR = process.env.STORAGE_DIR || path_1.default.join(os_1.default.homedir(), 'myassis-gateway-storage');
|
|
18
|
+
const STORAGE_FILE = path_1.default.join(STORAGE_DIR, 'persist.json');
|
|
13
19
|
// 确保存储目录存在
|
|
14
20
|
function ensureStorageDir() {
|
|
15
|
-
if (!
|
|
16
|
-
|
|
21
|
+
if (!fs_1.default.existsSync(STORAGE_DIR)) {
|
|
22
|
+
fs_1.default.mkdirSync(STORAGE_DIR, { recursive: true });
|
|
17
23
|
}
|
|
18
24
|
}
|
|
19
25
|
// 读取存储文件
|
|
@@ -21,8 +27,8 @@ function readStorage() {
|
|
|
21
27
|
ensureStorageDir();
|
|
22
28
|
try {
|
|
23
29
|
logger.debug(`Reading storage from ${STORAGE_FILE}`);
|
|
24
|
-
if (
|
|
25
|
-
const data =
|
|
30
|
+
if (fs_1.default.existsSync(STORAGE_FILE)) {
|
|
31
|
+
const data = fs_1.default.readFileSync(STORAGE_FILE, 'utf-8');
|
|
26
32
|
return JSON.parse(data);
|
|
27
33
|
}
|
|
28
34
|
}
|
|
@@ -35,7 +41,7 @@ function readStorage() {
|
|
|
35
41
|
function writeStorage(data) {
|
|
36
42
|
ensureStorageDir();
|
|
37
43
|
try {
|
|
38
|
-
|
|
44
|
+
fs_1.default.writeFileSync(STORAGE_FILE, JSON.stringify(data, null, 2), 'utf-8');
|
|
39
45
|
}
|
|
40
46
|
catch (error) {
|
|
41
47
|
logger.error(`Failed to write storage: ${error}`);
|
|
@@ -44,7 +50,7 @@ function writeStorage(data) {
|
|
|
44
50
|
/**
|
|
45
51
|
* 持久化存储管理器
|
|
46
52
|
*/
|
|
47
|
-
|
|
53
|
+
exports.persistStore = {
|
|
48
54
|
/**
|
|
49
55
|
* 获取值
|
|
50
56
|
*/
|
|
@@ -348,4 +354,4 @@ export const persistStore = {
|
|
|
348
354
|
return true;
|
|
349
355
|
},
|
|
350
356
|
};
|
|
351
|
-
|
|
357
|
+
exports.default = exports.persistStore;
|
package/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@myassis/gateway",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.20",
|
|
4
4
|
"description": "我的助手 Gateway Service - 本地 AI 网关服务,支持认证、WebSocket 实时通信和任务调度",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
-
"type": "module",
|
|
7
6
|
"bin": {
|
|
8
7
|
"myassis-gateway": "dist/index.js",
|
|
9
8
|
"gateway": "dist/index.js"
|
|
@@ -17,8 +16,7 @@
|
|
|
17
16
|
],
|
|
18
17
|
"exports": {
|
|
19
18
|
".": {
|
|
20
|
-
"
|
|
21
|
-
"require": "./dist/index.cjs"
|
|
19
|
+
"require": "./dist/index.js"
|
|
22
20
|
}
|
|
23
21
|
},
|
|
24
22
|
"scripts": {
|
|
@@ -26,8 +24,8 @@
|
|
|
26
24
|
"start": "node dist/index.js",
|
|
27
25
|
"build": "tsc --skipLibCheck",
|
|
28
26
|
"postbuild": "node scripts/add-shebang.js && npx tsc-alias",
|
|
29
|
-
"pkg:win": "pkg . --targets node18-win-x64 --output myassis-gateway-win.exe",
|
|
30
|
-
"pkg:linux": "pkg . --targets node18-linux-x64 --output myassis-gateway-linux",
|
|
27
|
+
"pkg:win": "npx @yao-pkg/pkg . --targets node18-win-x64 --output myassis-gateway-win.exe",
|
|
28
|
+
"pkg:linux": "npx @yao-pkg/pkg . --targets node18-linux-x64 --output myassis-gateway-linux",
|
|
31
29
|
"pkg:all": "npm run pkg:win && npm run pkg:linux",
|
|
32
30
|
"test": "jest"
|
|
33
31
|
},
|
|
@@ -39,19 +37,13 @@
|
|
|
39
37
|
"websocket",
|
|
40
38
|
"service"
|
|
41
39
|
],
|
|
42
|
-
"author": "
|
|
43
|
-
"license": "MIT",
|
|
44
|
-
"homepage": "https://github.com/myassis/myassis#readme",
|
|
45
|
-
"repository": {
|
|
46
|
-
"type": "git",
|
|
47
|
-
"url": "git+https://github.com/myassis/myassis.git"
|
|
48
|
-
},
|
|
40
|
+
"author": "duzhengjie",
|
|
49
41
|
"dependencies": {
|
|
42
|
+
"@myassis/shared": "1.0.15",
|
|
50
43
|
"@nut-tree/nut-js": "^4.2.0",
|
|
51
|
-
"@myassis/shared": "latest",
|
|
52
44
|
"axios": "^1.15.2",
|
|
53
45
|
"bcryptjs": "^2.4.3",
|
|
54
|
-
"better-sqlite3": "^
|
|
46
|
+
"better-sqlite3": "^8.7.0",
|
|
55
47
|
"cheerio": "^1.2.0",
|
|
56
48
|
"compression": "^1.7.4",
|
|
57
49
|
"cors": "^2.8.5",
|
|
@@ -69,7 +61,6 @@
|
|
|
69
61
|
},
|
|
70
62
|
"devDependencies": {
|
|
71
63
|
"@types/bcryptjs": "^2.4.6",
|
|
72
|
-
"@types/body-parser": "^1.19.5",
|
|
73
64
|
"@types/compression": "^1.7.5",
|
|
74
65
|
"@types/cors": "^2.8.17",
|
|
75
66
|
"@types/express": "^4.17.21",
|
|
@@ -78,10 +69,10 @@
|
|
|
78
69
|
"@types/node": "^20.11.0",
|
|
79
70
|
"@types/uuid": "^9.0.8",
|
|
80
71
|
"@types/ws": "^8.5.10",
|
|
81
|
-
"pkg": "^
|
|
72
|
+
"@yao-pkg/pkg": "^6.20.0",
|
|
73
|
+
"tsc-alias": "^1.8.10",
|
|
82
74
|
"tsx": "^4.7.0",
|
|
83
|
-
"typescript": "^5.3.3"
|
|
84
|
-
"tsc-alias": "^1.8.10"
|
|
75
|
+
"typescript": "^5.3.3"
|
|
85
76
|
},
|
|
86
77
|
"pkg": {
|
|
87
78
|
"scripts": [
|
|
@@ -89,7 +80,7 @@
|
|
|
89
80
|
],
|
|
90
81
|
"assets": [
|
|
91
82
|
"dist/**/*",
|
|
92
|
-
"
|
|
83
|
+
"migrations/**/*",
|
|
93
84
|
"README*"
|
|
94
85
|
],
|
|
95
86
|
"targets": [
|