@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.
- package/dist/api/index.js +27 -19
- package/dist/cli.js +10 -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,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Gateway 数据服务层
|
|
3
4
|
* 直接转发服务端数据,不做二次包装
|
|
@@ -7,19 +8,21 @@
|
|
|
7
8
|
* - /api/v1/data/* - 用户数据路由 (models, skills, tasks, settings)
|
|
8
9
|
* - /api/v1/skill-hubs/* - 技能库路由
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.settingsService = exports.tasksService = exports.modelsService = exports.skillHubService = exports.skillsService = exports.authService = void 0;
|
|
13
|
+
const index_js_1 = require("../api/index.js");
|
|
14
|
+
const index_js_2 = require("../stores/index.js");
|
|
15
|
+
const TaskService_js_1 = require("./TaskService.js");
|
|
16
|
+
const shared_1 = require("@myassis/shared");
|
|
17
|
+
const logger = (0, shared_1.getLogger)('DataService');
|
|
15
18
|
// ============ 认证服务 ============
|
|
16
|
-
|
|
19
|
+
exports.authService = {
|
|
17
20
|
// 登录
|
|
18
21
|
login: async (account, password, platform) => {
|
|
19
|
-
const response = await authApi.login({ account, password, platform });
|
|
22
|
+
const response = await index_js_1.authApi.login({ account, password, platform });
|
|
20
23
|
if (response.success && response.data) {
|
|
21
24
|
const expiresIn = response.data.expiresIn || 86400;
|
|
22
|
-
authStore.save({
|
|
25
|
+
index_js_2.authStore.save({
|
|
23
26
|
accessToken: response.data.accessToken,
|
|
24
27
|
refreshToken: response.data.refreshToken,
|
|
25
28
|
expiresIn,
|
|
@@ -31,7 +34,7 @@ export const authService = {
|
|
|
31
34
|
},
|
|
32
35
|
// 注册
|
|
33
36
|
register: async (account, password, platform) => {
|
|
34
|
-
const response = await authApi.register({
|
|
37
|
+
const response = await index_js_1.authApi.register({
|
|
35
38
|
account,
|
|
36
39
|
password,
|
|
37
40
|
nickname: account,
|
|
@@ -39,7 +42,7 @@ export const authService = {
|
|
|
39
42
|
});
|
|
40
43
|
if (response.success && response.data) {
|
|
41
44
|
const expiresIn = response.data.expiresIn || 86400;
|
|
42
|
-
authStore.save({
|
|
45
|
+
index_js_2.authStore.save({
|
|
43
46
|
accessToken: response.data.accessToken,
|
|
44
47
|
refreshToken: response.data.refreshToken,
|
|
45
48
|
expiresIn,
|
|
@@ -52,40 +55,40 @@ export const authService = {
|
|
|
52
55
|
// 登出
|
|
53
56
|
logout: async (token) => {
|
|
54
57
|
try {
|
|
55
|
-
await authApi.logout(token);
|
|
58
|
+
await index_js_1.authApi.logout(token);
|
|
56
59
|
}
|
|
57
60
|
catch (e) {
|
|
58
61
|
// 忽略错误
|
|
59
62
|
}
|
|
60
|
-
authStore.clear();
|
|
63
|
+
index_js_2.authStore.clear();
|
|
61
64
|
return { success: true };
|
|
62
65
|
},
|
|
63
66
|
// 获取当前用户
|
|
64
|
-
me: (token) => authApi.me(token),
|
|
67
|
+
me: (token) => index_js_1.authApi.me(token),
|
|
65
68
|
// 更新资料
|
|
66
|
-
updateProfile: (data, token) => authApi.updateProfile(data, token),
|
|
69
|
+
updateProfile: (data, token) => index_js_1.authApi.updateProfile(data, token),
|
|
67
70
|
// 修改密码
|
|
68
|
-
changePassword: (oldPassword, newPassword, token) => authApi.changePassword({ oldPassword, newPassword }, token),
|
|
71
|
+
changePassword: (oldPassword, newPassword, token) => index_js_1.authApi.changePassword({ oldPassword, newPassword }, token),
|
|
69
72
|
// 删除账号
|
|
70
|
-
deleteAccount: (password, token) => authApi.deleteAccount({ password }, token),
|
|
73
|
+
deleteAccount: (password, token) => index_js_1.authApi.deleteAccount({ password }, token),
|
|
71
74
|
// 获取当前用户(从内存)
|
|
72
|
-
getUser: (token) => authStore.get(token)?.user || null,
|
|
75
|
+
getUser: (token) => index_js_2.authStore.get(token)?.user || null,
|
|
73
76
|
// 刷新 Token
|
|
74
77
|
refresh: async (refreshToken) => {
|
|
75
|
-
const response = await authApi.refresh(refreshToken);
|
|
78
|
+
const response = await index_js_1.authApi.refresh(refreshToken);
|
|
76
79
|
if (response.success && response.accessToken) {
|
|
77
|
-
authStore.updateToken(response.accessToken, response.refreshToken);
|
|
80
|
+
index_js_2.authStore.updateToken(response.accessToken, response.refreshToken);
|
|
78
81
|
}
|
|
79
82
|
return response;
|
|
80
83
|
}
|
|
81
84
|
};
|
|
82
85
|
// ============ 技能服务 (用户已安装的技能) ============
|
|
83
|
-
|
|
84
|
-
list: async (token) => await skillsApi.list(token),
|
|
85
|
-
get: (skillId, token) => skillsApi.get(skillId, token),
|
|
86
|
+
exports.skillsService = {
|
|
87
|
+
list: async (token) => await index_js_1.skillsApi.list(token),
|
|
88
|
+
get: (skillId, token) => index_js_1.skillsApi.get(skillId, token),
|
|
86
89
|
install: async (skillHubId, token) => {
|
|
87
90
|
// 1. 从技能库获取技能详情
|
|
88
|
-
const hubResult = await skillHubApi.get(skillHubId, token);
|
|
91
|
+
const hubResult = await index_js_1.skillHubApi.get(skillHubId, token);
|
|
89
92
|
if (!hubResult.success || !hubResult.data) {
|
|
90
93
|
return { success: false, error: '获取技能详情失败' };
|
|
91
94
|
}
|
|
@@ -100,73 +103,73 @@ export const skillsService = {
|
|
|
100
103
|
isActive: true,
|
|
101
104
|
apiKeyRequired: hub.apiKeyRequired || false,
|
|
102
105
|
};
|
|
103
|
-
const response = await skillsApi.create(skillData, token);
|
|
106
|
+
const response = await index_js_1.skillsApi.create(skillData, token);
|
|
104
107
|
if (response.success) {
|
|
105
108
|
// 3. 增加安装计数
|
|
106
|
-
await skillHubApi.install(skillHubId, token);
|
|
109
|
+
await index_js_1.skillHubApi.install(skillHubId, token);
|
|
107
110
|
}
|
|
108
111
|
return response;
|
|
109
112
|
},
|
|
110
|
-
update: (skillId, data, token) => skillsApi.update(skillId, data, token),
|
|
111
|
-
uninstall: async (skillId, token) => await skillsApi.uninstall(skillId, token),
|
|
113
|
+
update: (skillId, data, token) => index_js_1.skillsApi.update(skillId, data, token),
|
|
114
|
+
uninstall: async (skillId, token) => await index_js_1.skillsApi.uninstall(skillId, token),
|
|
112
115
|
setApiKey: (skillId, apiKey, token) => {
|
|
113
|
-
persistStore.setSkillApiKey(skillId, apiKey);
|
|
116
|
+
index_js_2.persistStore.setSkillApiKey(skillId, apiKey);
|
|
114
117
|
return { success: true };
|
|
115
118
|
},
|
|
116
119
|
getApiKey: async (skillId, token) => {
|
|
117
|
-
const apikey = persistStore.getSkillApiKey(skillId);
|
|
120
|
+
const apikey = index_js_2.persistStore.getSkillApiKey(skillId);
|
|
118
121
|
if (!apikey) {
|
|
119
122
|
// 判断是否有内置 apikey
|
|
120
|
-
const skill = (await skillsService.get(skillId, token)).data;
|
|
123
|
+
const skill = (await exports.skillsService.get(skillId, token)).data;
|
|
121
124
|
if (skill.templateId) {
|
|
122
|
-
const skillHub = (await skillHubService.get(skill.templateId, token)).data;
|
|
125
|
+
const skillHub = (await exports.skillHubService.get(skill.templateId, token)).data;
|
|
123
126
|
if (skillHub?.builtinApikey) {
|
|
124
|
-
persistStore.setSkillApiKey(skillId, skillHub.builtinApikey);
|
|
127
|
+
index_js_2.persistStore.setSkillApiKey(skillId, skillHub.builtinApikey);
|
|
125
128
|
return { success: true, apiKey: skillHub.builtinApikey };
|
|
126
129
|
}
|
|
127
130
|
}
|
|
128
131
|
}
|
|
129
132
|
return { success: true, apiKey: apikey?.apiKey };
|
|
130
133
|
},
|
|
131
|
-
rate: (skillId, score, token) => skillsApi.rate(skillId, { score }, token),
|
|
132
|
-
parse: (content, token) => skillsApi.parse({ content }, token),
|
|
134
|
+
rate: (skillId, score, token) => index_js_1.skillsApi.rate(skillId, { score }, token),
|
|
135
|
+
parse: (content, token) => index_js_1.skillsApi.parse({ content }, token),
|
|
133
136
|
create: async (data, token) => {
|
|
134
|
-
const response = await skillsApi.create(data, token);
|
|
137
|
+
const response = await index_js_1.skillsApi.create(data, token);
|
|
135
138
|
if (response.success) {
|
|
136
139
|
// 创建成功后更新技能列表缓存
|
|
137
|
-
const listResponse = await skillsApi.list(token);
|
|
140
|
+
const listResponse = await index_js_1.skillsApi.list(token);
|
|
138
141
|
if (listResponse.success) {
|
|
139
|
-
memoryStore.set('skills', listResponse.data);
|
|
142
|
+
index_js_2.memoryStore.set('skills', listResponse.data);
|
|
140
143
|
}
|
|
141
144
|
}
|
|
142
145
|
return response;
|
|
143
146
|
},
|
|
144
147
|
};
|
|
145
148
|
// ============ 技能库服务 (可安装的技能) ============
|
|
146
|
-
|
|
147
|
-
list: (token, params) => skillHubApi.list(params, token),
|
|
148
|
-
get: (hubId, token) => skillHubApi.get(hubId, token),
|
|
149
|
-
categories: (token) => skillHubApi.categories(token),
|
|
150
|
-
preinstalled: (token) => skillHubApi.preinstalled(token),
|
|
151
|
-
user: (token) => skillHubApi.user(token),
|
|
152
|
-
checkUsed: (hubId, token) => skillHubApi.checkUsed(hubId, token),
|
|
153
|
-
rate: (hubId, rating, token) => skillHubApi.rate(hubId, rating, token),
|
|
154
|
-
userRating: (hubId, token) => skillHubApi.userRating(hubId, token),
|
|
155
|
-
install: (hubId, token) => skillHubApi.install(hubId, token),
|
|
156
|
-
use: (hubId, token) => skillHubApi.use(hubId, token),
|
|
149
|
+
exports.skillHubService = {
|
|
150
|
+
list: (token, params) => index_js_1.skillHubApi.list(params, token),
|
|
151
|
+
get: (hubId, token) => index_js_1.skillHubApi.get(hubId, token),
|
|
152
|
+
categories: (token) => index_js_1.skillHubApi.categories(token),
|
|
153
|
+
preinstalled: (token) => index_js_1.skillHubApi.preinstalled(token),
|
|
154
|
+
user: (token) => index_js_1.skillHubApi.user(token),
|
|
155
|
+
checkUsed: (hubId, token) => index_js_1.skillHubApi.checkUsed(hubId, token),
|
|
156
|
+
rate: (hubId, rating, token) => index_js_1.skillHubApi.rate(hubId, rating, token),
|
|
157
|
+
userRating: (hubId, token) => index_js_1.skillHubApi.userRating(hubId, token),
|
|
158
|
+
install: (hubId, token) => index_js_1.skillHubApi.install(hubId, token),
|
|
159
|
+
use: (hubId, token) => index_js_1.skillHubApi.use(hubId, token),
|
|
157
160
|
};
|
|
158
161
|
// ============ 模型服务 ============
|
|
159
|
-
|
|
160
|
-
list: (token) => modelsApi.list(token),
|
|
161
|
-
get: (modelId, token) => modelsApi.get(modelId, token),
|
|
162
|
-
create: (data, token) => modelsApi.create(data, token),
|
|
163
|
-
update: (modelId, data, token) => modelsApi.update(modelId, data, token),
|
|
164
|
-
delete: (modelId, token) => modelsApi.delete(modelId, token),
|
|
165
|
-
setPrimary: (modelId, token) => modelsApi.setPrimary(modelId, token),
|
|
162
|
+
exports.modelsService = {
|
|
163
|
+
list: (token) => index_js_1.modelsApi.list(token),
|
|
164
|
+
get: (modelId, token) => index_js_1.modelsApi.get(modelId, token),
|
|
165
|
+
create: (data, token) => index_js_1.modelsApi.create(data, token),
|
|
166
|
+
update: (modelId, data, token) => index_js_1.modelsApi.update(modelId, data, token),
|
|
167
|
+
delete: (modelId, token) => index_js_1.modelsApi.delete(modelId, token),
|
|
168
|
+
setPrimary: (modelId, token) => index_js_1.modelsApi.setPrimary(modelId, token),
|
|
166
169
|
};
|
|
167
|
-
|
|
170
|
+
exports.tasksService = {
|
|
168
171
|
list: async (userId, params) => {
|
|
169
|
-
const result = await taskService.listTasks({
|
|
172
|
+
const result = await TaskService_js_1.taskService.listTasks({
|
|
170
173
|
status: params?.status,
|
|
171
174
|
userId,
|
|
172
175
|
page: params?.page ? parseInt(params.page) : undefined,
|
|
@@ -175,7 +178,7 @@ export const tasksService = {
|
|
|
175
178
|
return { success: true, data: result.tasks, total: result.total };
|
|
176
179
|
},
|
|
177
180
|
get: async (taskId, token) => {
|
|
178
|
-
const task = await taskService.getTask(taskId, token);
|
|
181
|
+
const task = await TaskService_js_1.taskService.getTask(taskId, token);
|
|
179
182
|
if (!task)
|
|
180
183
|
return { success: false, error: 'Task not found' };
|
|
181
184
|
return { success: true, data: task };
|
|
@@ -183,7 +186,7 @@ export const tasksService = {
|
|
|
183
186
|
create: async (data, userId, token) => {
|
|
184
187
|
const uid = userId || data?.userId || 'local';
|
|
185
188
|
try {
|
|
186
|
-
const result = await taskService.createTask({
|
|
189
|
+
const result = await TaskService_js_1.taskService.createTask({
|
|
187
190
|
userId: uid,
|
|
188
191
|
title: data.title,
|
|
189
192
|
description: data.description,
|
|
@@ -206,7 +209,7 @@ export const tasksService = {
|
|
|
206
209
|
},
|
|
207
210
|
update: async (taskId, data, token) => {
|
|
208
211
|
try {
|
|
209
|
-
const result = await taskService.updateTask(taskId, {
|
|
212
|
+
const result = await TaskService_js_1.taskService.updateTask(taskId, {
|
|
210
213
|
title: data.title,
|
|
211
214
|
description: data.description,
|
|
212
215
|
taskType: data.taskType,
|
|
@@ -229,7 +232,7 @@ export const tasksService = {
|
|
|
229
232
|
},
|
|
230
233
|
delete: async (taskId, token) => {
|
|
231
234
|
try {
|
|
232
|
-
const result = await taskService.deleteTask(taskId, token);
|
|
235
|
+
const result = await TaskService_js_1.taskService.deleteTask(taskId, token);
|
|
233
236
|
return { success: result };
|
|
234
237
|
}
|
|
235
238
|
catch (error) {
|
|
@@ -239,7 +242,7 @@ export const tasksService = {
|
|
|
239
242
|
},
|
|
240
243
|
cancel: async (taskId, token) => {
|
|
241
244
|
try {
|
|
242
|
-
const result = await taskService.cancelTask(taskId, token);
|
|
245
|
+
const result = await TaskService_js_1.taskService.cancelTask(taskId, token);
|
|
243
246
|
return { success: result };
|
|
244
247
|
}
|
|
245
248
|
catch (error) {
|
|
@@ -249,7 +252,7 @@ export const tasksService = {
|
|
|
249
252
|
},
|
|
250
253
|
updateStatus: async (taskId, status, token) => {
|
|
251
254
|
try {
|
|
252
|
-
const result = await taskService.updateTaskStatus(taskId, status, token);
|
|
255
|
+
const result = await TaskService_js_1.taskService.updateTaskStatus(taskId, status, token);
|
|
253
256
|
return { success: result };
|
|
254
257
|
}
|
|
255
258
|
catch (error) {
|
|
@@ -259,24 +262,24 @@ export const tasksService = {
|
|
|
259
262
|
},
|
|
260
263
|
};
|
|
261
264
|
// ============ 设置服务 ============
|
|
262
|
-
|
|
265
|
+
exports.settingsService = {
|
|
263
266
|
get: async (token) => {
|
|
264
|
-
const settings = memoryStore.get('settings'); // 预热缓存
|
|
267
|
+
const settings = index_js_2.memoryStore.get('settings'); // 预热缓存
|
|
265
268
|
if (settings) {
|
|
266
269
|
return { success: true, data: settings };
|
|
267
270
|
}
|
|
268
271
|
else {
|
|
269
|
-
const response = await settingsApi.get(token);
|
|
272
|
+
const response = await index_js_1.settingsApi.get(token);
|
|
270
273
|
if (response.success) {
|
|
271
|
-
memoryStore.set('settings', response.data); // 更新缓存
|
|
274
|
+
index_js_2.memoryStore.set('settings', response.data); // 更新缓存
|
|
272
275
|
}
|
|
273
276
|
return response;
|
|
274
277
|
}
|
|
275
278
|
},
|
|
276
279
|
update: async (data, token) => {
|
|
277
|
-
const response = await settingsApi.update(data, token);
|
|
280
|
+
const response = await index_js_1.settingsApi.update(data, token);
|
|
278
281
|
if (response.success) {
|
|
279
|
-
memoryStore.set('settings', response.data); // 更新缓存
|
|
282
|
+
index_js_2.memoryStore.set('settings', response.data); // 更新缓存
|
|
280
283
|
}
|
|
281
284
|
return response;
|
|
282
285
|
},
|
package/dist/services/index.js
CHANGED
|
@@ -1,15 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PushTokenStore = exports.TaskStore = exports.notificationService = exports.localTaskService = exports.taskService = exports.taskSchedulerService = exports.getSessionManager = exports.tasksService = exports.settingsService = exports.modelsService = exports.skillHubService = exports.skillsService = exports.authService = void 0;
|
|
1
4
|
// Re-export all services from dataService
|
|
2
|
-
|
|
5
|
+
var dataService_js_1 = require("./dataService.js");
|
|
6
|
+
Object.defineProperty(exports, "authService", { enumerable: true, get: function () { return dataService_js_1.authService; } });
|
|
7
|
+
Object.defineProperty(exports, "skillsService", { enumerable: true, get: function () { return dataService_js_1.skillsService; } });
|
|
8
|
+
Object.defineProperty(exports, "skillHubService", { enumerable: true, get: function () { return dataService_js_1.skillHubService; } });
|
|
9
|
+
Object.defineProperty(exports, "modelsService", { enumerable: true, get: function () { return dataService_js_1.modelsService; } });
|
|
10
|
+
Object.defineProperty(exports, "settingsService", { enumerable: true, get: function () { return dataService_js_1.settingsService; } });
|
|
3
11
|
// Re-export tasksService from dataService (server-only tasks)
|
|
4
|
-
|
|
12
|
+
var dataService_js_2 = require("./dataService.js");
|
|
13
|
+
Object.defineProperty(exports, "tasksService", { enumerable: true, get: function () { return dataService_js_2.tasksService; } });
|
|
5
14
|
// Re-export session manager
|
|
6
|
-
|
|
15
|
+
var index_js_1 = require("./session/index.js");
|
|
16
|
+
Object.defineProperty(exports, "getSessionManager", { enumerable: true, get: function () { return index_js_1.getSessionManager; } });
|
|
7
17
|
// Re-export task services
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
18
|
+
var TaskSchedulerService_js_1 = require("./TaskSchedulerService.js");
|
|
19
|
+
Object.defineProperty(exports, "taskSchedulerService", { enumerable: true, get: function () { return TaskSchedulerService_js_1.taskSchedulerService; } });
|
|
20
|
+
var TaskService_js_1 = require("./TaskService.js");
|
|
21
|
+
Object.defineProperty(exports, "taskService", { enumerable: true, get: function () { return TaskService_js_1.taskService; } });
|
|
22
|
+
var LocalTaskService_js_1 = require("./LocalTaskService.js");
|
|
23
|
+
Object.defineProperty(exports, "localTaskService", { enumerable: true, get: function () { return LocalTaskService_js_1.localTaskService; } });
|
|
11
24
|
// Re-export notification and holiday services
|
|
12
|
-
|
|
25
|
+
var NotificationService_js_1 = require("./NotificationService.js");
|
|
26
|
+
Object.defineProperty(exports, "notificationService", { enumerable: true, get: function () { return NotificationService_js_1.notificationService; } });
|
|
13
27
|
// Re-export task stores
|
|
14
|
-
|
|
15
|
-
|
|
28
|
+
var TaskStore_js_1 = require("./task/TaskStore.js");
|
|
29
|
+
Object.defineProperty(exports, "TaskStore", { enumerable: true, get: function () { return TaskStore_js_1.TaskStore; } });
|
|
30
|
+
var PushTokenStore_js_1 = require("./task/PushTokenStore.js");
|
|
31
|
+
Object.defineProperty(exports, "PushTokenStore", { enumerable: true, get: function () { return PushTokenStore_js_1.PushTokenStore; } });
|
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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.getGlobalModelSelector = exports.parseAruments = exports.LLMClient = void 0;
|
|
7
|
+
const index_js_1 = require("../../stores/index.js");
|
|
8
|
+
const shared_1 = require("@myassis/shared");
|
|
9
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
10
|
+
const logger = (0, shared_1.getLogger)('LLMClient');
|
|
5
11
|
/**
|
|
6
12
|
* LLM 调用器类
|
|
7
13
|
* 提供 Chat 和 streamChat 两种调用方式
|
|
8
14
|
*/
|
|
9
|
-
|
|
15
|
+
class LLMClient {
|
|
10
16
|
models;
|
|
11
17
|
messages;
|
|
12
18
|
tools;
|
|
@@ -115,7 +121,7 @@ export class LLMClient {
|
|
|
115
121
|
* 构建请求
|
|
116
122
|
*/
|
|
117
123
|
async buildRequest(model, stream) {
|
|
118
|
-
const apiKey = persistStore.getModelApiKey(model.id);
|
|
124
|
+
const apiKey = index_js_1.persistStore.getModelApiKey(model.id);
|
|
119
125
|
if (!apiKey) {
|
|
120
126
|
throw new Error('No API Key');
|
|
121
127
|
}
|
|
@@ -396,7 +402,7 @@ export class LLMClient {
|
|
|
396
402
|
logger.debug('tokens', tokens);
|
|
397
403
|
if (tokens > 200000) {
|
|
398
404
|
logger.warn('message is too large and has writen to the file debug.json');
|
|
399
|
-
await
|
|
405
|
+
await promises_1.default.writeFile('debug.json', JSON.stringify(body.messages), 'utf-8');
|
|
400
406
|
throw Error('exceed max message tokens');
|
|
401
407
|
}
|
|
402
408
|
return {
|
|
@@ -630,6 +636,7 @@ export class LLMClient {
|
|
|
630
636
|
return availabilityCodes.some(code => errorStr.includes(code));
|
|
631
637
|
}
|
|
632
638
|
}
|
|
639
|
+
exports.LLMClient = LLMClient;
|
|
633
640
|
/**
|
|
634
641
|
* 模型选择器包装器(全局单例)
|
|
635
642
|
*/
|
|
@@ -709,7 +716,7 @@ class ModelSelectorWrapper {
|
|
|
709
716
|
return this.getNext() !== null;
|
|
710
717
|
}
|
|
711
718
|
}
|
|
712
|
-
|
|
719
|
+
function parseAruments(params) {
|
|
713
720
|
try {
|
|
714
721
|
return typeof params === 'string' ? JSON.parse(params) : params;
|
|
715
722
|
}
|
|
@@ -717,10 +724,11 @@ export function parseAruments(params) {
|
|
|
717
724
|
return params;
|
|
718
725
|
}
|
|
719
726
|
}
|
|
727
|
+
exports.parseAruments = parseAruments;
|
|
720
728
|
/**
|
|
721
729
|
* 全局模型选择器单例访问入口
|
|
722
730
|
* @param models 模型列表(首次初始化时必填)
|
|
723
731
|
* @param preferredModelId 首选模型ID
|
|
724
732
|
* @returns 全局唯一的模型选择器实例
|
|
725
733
|
*/
|
|
726
|
-
|
|
734
|
+
exports.getGlobalModelSelector = ModelSelectorWrapper.getInstance;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MemoryManager = void 0;
|
|
4
|
+
const shared_1 = require("@myassis/shared");
|
|
5
|
+
const logger = (0, shared_1.getLogger)('MemoryManager');
|
|
6
|
+
const models_js_1 = require("../models.js");
|
|
7
|
+
const dataService_js_1 = require("../dataService.js");
|
|
8
|
+
const index_js_1 = require("../../stores/index.js");
|
|
9
|
+
const LLMClient_js_1 = require("../llm/LLMClient.js");
|
|
10
|
+
const index_js_2 = require("../../config/index.js");
|
|
8
11
|
const DEFAULT_CONFIG = {
|
|
9
12
|
summaryThreshold: 10,
|
|
10
13
|
enabled: true,
|
|
@@ -13,7 +16,7 @@ const DEFAULT_CONFIG = {
|
|
|
13
16
|
* 记忆管理器
|
|
14
17
|
* 实现总结式记忆:当对话超过一定长度时,自动生成对话摘要
|
|
15
18
|
*/
|
|
16
|
-
|
|
19
|
+
class MemoryManager {
|
|
17
20
|
session;
|
|
18
21
|
signal;
|
|
19
22
|
config = DEFAULT_CONFIG;
|
|
@@ -50,13 +53,13 @@ export class MemoryManager {
|
|
|
50
53
|
logger.debug('hasSummary', hasSummary);
|
|
51
54
|
if (!hasSummary) {
|
|
52
55
|
// 4A. 首次摘要生成
|
|
53
|
-
const summary = await this.generateSummaryAsync(messages.slice(0, -appConfig.messageKeep), null);
|
|
56
|
+
const summary = await this.generateSummaryAsync(messages.slice(0, -index_js_2.appConfig.messageKeep), null);
|
|
54
57
|
this.session.lastMessageSummary = summary;
|
|
55
58
|
this.session.lastMessageSummaryAt = Date.now();
|
|
56
59
|
this.session.save();
|
|
57
60
|
return [
|
|
58
61
|
this.toSummaryMessage(summary, this.session.lastMessageSummaryAt, ''),
|
|
59
|
-
...messages.slice(-appConfig.messageKeep),
|
|
62
|
+
...messages.slice(-index_js_2.appConfig.messageKeep),
|
|
60
63
|
];
|
|
61
64
|
}
|
|
62
65
|
else {
|
|
@@ -73,13 +76,13 @@ export class MemoryManager {
|
|
|
73
76
|
}
|
|
74
77
|
else {
|
|
75
78
|
// 新消息超过阈值条,重新生成摘要
|
|
76
|
-
const summary = await this.generateSummaryAsync(newMessages.slice(0, -appConfig.messageKeep), this.session.lastMessageSummary);
|
|
79
|
+
const summary = await this.generateSummaryAsync(newMessages.slice(0, -index_js_2.appConfig.messageKeep), this.session.lastMessageSummary);
|
|
77
80
|
this.session.lastMessageSummary = summary;
|
|
78
81
|
this.session.lastMessageSummaryAt = Date.now();
|
|
79
82
|
this.session.save();
|
|
80
83
|
return [
|
|
81
84
|
this.toSummaryMessage(summary, this.session.lastMessageSummaryAt, ''),
|
|
82
|
-
...messages.slice(-appConfig.messageKeep),
|
|
85
|
+
...messages.slice(-index_js_2.appConfig.messageKeep),
|
|
83
86
|
];
|
|
84
87
|
}
|
|
85
88
|
}
|
|
@@ -196,8 +199,8 @@ ${conversation}
|
|
|
196
199
|
return await this.hierarchicalSummary(formattedMessages, lastSummary);
|
|
197
200
|
}
|
|
198
201
|
const summaryPrompt = this.buildSummaryPrompt(messages, lastSummary);
|
|
199
|
-
const token = authStore.get(this.session.userId).accessToken;
|
|
200
|
-
const llmClient = new LLMClient((await modelsService.list(token)).data.map((x) => toModel(x)), [{ role: 'user', content: summaryPrompt }], this.signal, []);
|
|
202
|
+
const token = index_js_1.authStore.get(this.session.userId).accessToken;
|
|
203
|
+
const llmClient = new LLMClient_js_1.LLMClient((await dataService_js_1.modelsService.list(token)).data.map((x) => (0, models_js_1.toModel)(x)), [{ role: 'user', content: summaryPrompt }], this.signal, []);
|
|
201
204
|
const response = await llmClient.Chat();
|
|
202
205
|
const content = (response.content || '').trim();
|
|
203
206
|
if (!content) {
|
|
@@ -220,8 +223,8 @@ ${conversation}
|
|
|
220
223
|
break;
|
|
221
224
|
const batch = formattedMessages.slice(i, i + BATCH_SIZE);
|
|
222
225
|
const batchPrompt = `请简洁总结以下对话片段的关键信息,特别关注:项目结构、关键决策、错误及修复。\n\n${batch.join('\n\n')}`;
|
|
223
|
-
const token = authStore.get(this.session.userId).accessToken;
|
|
224
|
-
const llmClient = new LLMClient((await modelsService.list(token)).data.map((x) => toModel(x)), [{ role: 'user', content: batchPrompt }], this.signal, []);
|
|
226
|
+
const token = index_js_1.authStore.get(this.session.userId).accessToken;
|
|
227
|
+
const llmClient = new LLMClient_js_1.LLMClient((await dataService_js_1.modelsService.list(token)).data.map((x) => (0, models_js_1.toModel)(x)), [{ role: 'user', content: batchPrompt }], this.signal, []);
|
|
225
228
|
const response = await llmClient.Chat();
|
|
226
229
|
const subContent = (response.content || '').trim();
|
|
227
230
|
if (subContent) {
|
|
@@ -237,8 +240,8 @@ ${conversation}
|
|
|
237
240
|
}
|
|
238
241
|
// 合并子摘要为最终摘要
|
|
239
242
|
const mergePrompt = this.buildMergePrompt(subSummaries, lastSummary);
|
|
240
|
-
const token = authStore.get(this.session.userId).accessToken;
|
|
241
|
-
const mergeLlmClient = new LLMClient((await modelsService.list(token)).data.map((x) => toModel(x)), [{ role: 'user', content: mergePrompt }], this.signal, []);
|
|
243
|
+
const token = index_js_1.authStore.get(this.session.userId).accessToken;
|
|
244
|
+
const mergeLlmClient = new LLMClient_js_1.LLMClient((await dataService_js_1.modelsService.list(token)).data.map((x) => (0, models_js_1.toModel)(x)), [{ role: 'user', content: mergePrompt }], this.signal, []);
|
|
242
245
|
const mergeResponse = await mergeLlmClient.Chat();
|
|
243
246
|
const mergedContent = (mergeResponse.content || '').trim();
|
|
244
247
|
return mergedContent || subSummaries.join('\n\n');
|
|
@@ -278,3 +281,4 @@ ${summaries}
|
|
|
278
281
|
【错误与修复】列出遇到的错误及解决方案,标注"⚠️"避免重复`;
|
|
279
282
|
}
|
|
280
283
|
}
|
|
284
|
+
exports.MemoryManager = MemoryManager;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* 模型能力配置
|
|
3
4
|
* 定义各模型擅长领域和优先级
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.getModelCapabilityConfig = exports.CAPABILITY_KEYWORDS = exports.MODEL_CAPABILITIES = void 0;
|
|
8
|
+
exports.MODEL_CAPABILITIES = {
|
|
6
9
|
// Anthropic 系列
|
|
7
10
|
'claude-3-5-sonnet': {
|
|
8
11
|
strengths: ['reasoning', 'coding', 'analysis', 'writing'],
|
|
@@ -77,7 +80,7 @@ export const MODEL_CAPABILITIES = {
|
|
|
77
80
|
/**
|
|
78
81
|
* 内容分析标签定义
|
|
79
82
|
*/
|
|
80
|
-
|
|
83
|
+
exports.CAPABILITY_KEYWORDS = {
|
|
81
84
|
// 编程相关
|
|
82
85
|
coding: [
|
|
83
86
|
'code', '编程', '代码', '函数', 'algorithm', 'python', 'javascript',
|
|
@@ -121,16 +124,16 @@ export const CAPABILITY_KEYWORDS = {
|
|
|
121
124
|
/**
|
|
122
125
|
* 获取模型的默认配置
|
|
123
126
|
*/
|
|
124
|
-
|
|
127
|
+
function getModelCapabilityConfig(modelId) {
|
|
125
128
|
// 尝试精确匹配
|
|
126
|
-
if (MODEL_CAPABILITIES[modelId]) {
|
|
127
|
-
return MODEL_CAPABILITIES[modelId];
|
|
129
|
+
if (exports.MODEL_CAPABILITIES[modelId]) {
|
|
130
|
+
return exports.MODEL_CAPABILITIES[modelId];
|
|
128
131
|
}
|
|
129
132
|
// 尝试前缀匹配
|
|
130
133
|
const prefix = modelId.split('-').slice(0, 2).join('-');
|
|
131
|
-
for (const key of Object.keys(MODEL_CAPABILITIES)) {
|
|
134
|
+
for (const key of Object.keys(exports.MODEL_CAPABILITIES)) {
|
|
132
135
|
if (key.startsWith(prefix)) {
|
|
133
|
-
return MODEL_CAPABILITIES[key];
|
|
136
|
+
return exports.MODEL_CAPABILITIES[key];
|
|
134
137
|
}
|
|
135
138
|
}
|
|
136
139
|
// 默认配置
|
|
@@ -139,3 +142,4 @@ export function getModelCapabilityConfig(modelId) {
|
|
|
139
142
|
priority: 5,
|
|
140
143
|
};
|
|
141
144
|
}
|
|
145
|
+
exports.getModelCapabilityConfig = getModelCapabilityConfig;
|
|
@@ -1,4 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* 模型选择模块
|
|
3
4
|
*/
|
|
4
|
-
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
__exportStar(require("./ModelCapabilities.js"), exports);
|
package/dist/services/models.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toModel = void 0;
|
|
4
|
+
function toModel(m) {
|
|
2
5
|
return {
|
|
3
6
|
id: String(m.id),
|
|
4
7
|
modelName: m.modelName,
|
|
@@ -14,3 +17,4 @@ export function toModel(m) {
|
|
|
14
17
|
isPrimary: m.isPrimary
|
|
15
18
|
};
|
|
16
19
|
}
|
|
20
|
+
exports.toModel = toModel;
|