@myassis/gateway 1.0.1 → 1.0.2

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.
Files changed (50) hide show
  1. package/dist/api/index.js +69 -59
  2. package/dist/config/index.js +2 -2
  3. package/dist/index.js +85 -11
  4. package/dist/middleware/auth.js +9 -25
  5. package/dist/middleware/errorHandler.js +1 -1
  6. package/dist/routes/agent.js +30 -19
  7. package/dist/routes/auth.js +35 -26
  8. package/dist/routes/chat.js +1 -1
  9. package/dist/routes/models.js +11 -14
  10. package/dist/routes/service.js +3 -6
  11. package/dist/routes/settings.js +11 -9
  12. package/dist/routes/skillHub.js +10 -6
  13. package/dist/routes/skills.js +13 -10
  14. package/dist/routes/tasks.js +6 -3
  15. package/dist/routes/upload.js +5 -2
  16. package/dist/routes/version.js +4 -4
  17. package/dist/services/LocalTaskService.js +1 -1
  18. package/dist/services/NotificationService.js +1 -1
  19. package/dist/services/ServiceManager.js +12 -12
  20. package/dist/services/TaskSchedulerService.js +18 -9
  21. package/dist/services/TaskService.js +23 -20
  22. package/dist/services/WebSocketService.js +16 -6
  23. package/dist/services/agent/Agent.js +7 -7
  24. package/dist/services/agent/AgentManager.js +25 -17
  25. package/dist/services/agent/AgentStore.js +1 -1
  26. package/dist/services/dataService.js +60 -70
  27. package/dist/services/index.js +1 -1
  28. package/dist/services/llm/LLMClient.js +11 -9
  29. package/dist/services/memory/MemoryManager.js +177 -14
  30. package/dist/services/session/MigrationManager.js +1 -1
  31. package/dist/services/session/Session.js +70 -46
  32. package/dist/services/session/SessionManager.js +12 -5
  33. package/dist/services/session/SessionStore.js +1 -27
  34. package/dist/services/session/index.js +1 -1
  35. package/dist/services/systemPrompt.js +8 -4
  36. package/dist/services/task/PushTokenStore.js +1 -19
  37. package/dist/services/task/TaskStore.js +1 -20
  38. package/dist/services/tools/edit.js +122 -148
  39. package/dist/services/tools/exec.js +1 -1
  40. package/dist/services/tools/fetch.js +1 -1
  41. package/dist/services/tools/file.js +4 -9
  42. package/dist/services/tools/index.js +4 -3
  43. package/dist/services/tools/model.js +8 -6
  44. package/dist/services/tools/sessionsSpawn.js +54 -0
  45. package/dist/services/tools/skill.js +13 -12
  46. package/dist/services/tools/task.js +2 -4
  47. package/dist/stores/authStore.js +52 -66
  48. package/dist/stores/persistStore.js +37 -3
  49. package/package.json +7 -3
  50. package/scripts/postbuild.js +39 -0
@@ -7,10 +7,11 @@
7
7
  * - platformApply === currentPlatform → 本地 SQLite 存储(localTaskService)
8
8
  * - platformApply !== currentPlatform → 服务器 API(tasksApi)
9
9
  */
10
+ import { authStore } from '@/stores';
10
11
  import { tasksApi } from '../api';
11
12
  import { localTaskService } from './LocalTaskService';
12
- import { getLogger } from '@pocketclaw/shared';
13
- import { getPlatform } from '@pocketclaw/shared/dist/utils/system.js';
13
+ import { getLogger } from '@myassis/shared';
14
+ import { getPlatform } from '@myassis/shared/dist/utils/system.js';
14
15
  // 当前网关平台标识
15
16
  const CURRENT_PLATFORM = process.env.GATEWAY_PLATFORM || getPlatform();
16
17
  const logger = getLogger('TaskService');
@@ -29,7 +30,7 @@ class TaskService {
29
30
  /**
30
31
  * 创建任务(自动路由)
31
32
  */
32
- async createTask(data) {
33
+ async createTask(data, token) {
33
34
  const isLocal = isLocalTask(data.platformApply);
34
35
  logger.info('[TaskService] 创建任务', {
35
36
  title: data.title,
@@ -73,19 +74,19 @@ class TaskService {
73
74
  ? (typeof data.endTime === 'object' ? new Date(data.endTime).toISOString() : data.endTime)
74
75
  : undefined,
75
76
  platform_apply: data.platformApply,
76
- });
77
+ }, token);
77
78
  return { id: String(result.id || result), isLocal: false };
78
79
  }
79
80
  }
80
81
  /**
81
82
  * 获取任务(自动路由 - 先本地后服务器)
82
83
  */
83
- async getTask(taskId) {
84
+ async getTask(taskId, token) {
84
85
  const localTask = localTaskService.getTask(taskId);
85
86
  if (localTask)
86
87
  return localTask;
87
88
  try {
88
- const result = await tasksApi.get(taskId);
89
+ const result = await tasksApi.get(taskId, token);
89
90
  return this.transformServerTask(result);
90
91
  }
91
92
  catch (error) {
@@ -99,12 +100,14 @@ class TaskService {
99
100
  async listTasks(params) {
100
101
  const localResult = localTaskService.listTasks(params);
101
102
  let serverTasks = [];
103
+ const userId = params.userId;
104
+ const token = authStore.get(userId).accessToken;
102
105
  try {
103
106
  const serverResult = await tasksApi.list({
104
- status: params?.status,
105
- page: params?.page ? String(params.page) : undefined,
106
- pageSize: params?.pageSize ? String(params.pageSize) : undefined,
107
- });
107
+ status: params.status,
108
+ page: params.page ? String(params.page) : undefined,
109
+ pageSize: params.pageSize ? String(params.pageSize) : undefined,
110
+ }, token);
108
111
  if (Array.isArray(serverResult)) {
109
112
  serverTasks = serverResult.map(t => this.transformServerTask(t)).filter(Boolean);
110
113
  }
@@ -126,7 +129,7 @@ class TaskService {
126
129
  /**
127
130
  * 更新任务(自动路由)
128
131
  */
129
- async updateTask(taskId, data) {
132
+ async updateTask(taskId, data, token) {
130
133
  const localTask = localTaskService.getTask(taskId);
131
134
  if (localTask) {
132
135
  const result = localTaskService.updateTask(taskId, data);
@@ -151,7 +154,7 @@ class TaskService {
151
154
  ? (typeof data.endTime === 'object' ? new Date(data.endTime).toISOString() : data.endTime)
152
155
  : undefined,
153
156
  status: data.status,
154
- });
157
+ }, token);
155
158
  return true;
156
159
  }
157
160
  catch (error) {
@@ -163,14 +166,14 @@ class TaskService {
163
166
  /**
164
167
  * 删除任务(自动路由)
165
168
  */
166
- async deleteTask(taskId) {
169
+ async deleteTask(taskId, token) {
167
170
  const localTask = localTaskService.getTask(taskId);
168
171
  if (localTask) {
169
172
  return localTaskService.deleteTask(taskId);
170
173
  }
171
174
  else {
172
175
  try {
173
- await tasksApi.delete(taskId);
176
+ await tasksApi.delete(taskId, token);
174
177
  return true;
175
178
  }
176
179
  catch (error) {
@@ -182,7 +185,7 @@ class TaskService {
182
185
  /**
183
186
  * 更新任务状态
184
187
  */
185
- async updateTaskStatus(taskId, status) {
188
+ async updateTaskStatus(taskId, status, token) {
186
189
  const localTask = localTaskService.getTask(taskId);
187
190
  if (localTask) {
188
191
  await localTaskService.updateTaskStatus(taskId, status);
@@ -190,7 +193,7 @@ class TaskService {
190
193
  }
191
194
  else {
192
195
  try {
193
- await tasksApi.updateStatus(taskId, { status });
196
+ await tasksApi.updateStatus(taskId, { status }, token);
194
197
  return true;
195
198
  }
196
199
  catch (error) {
@@ -202,14 +205,14 @@ class TaskService {
202
205
  /**
203
206
  * 完成任务
204
207
  */
205
- async completeTask(taskId) {
206
- return this.updateTaskStatus(taskId, 'completed');
208
+ async completeTask(taskId, token) {
209
+ return this.updateTaskStatus(taskId, 'completed', token);
207
210
  }
208
211
  /**
209
212
  * 取消任务
210
213
  */
211
- async cancelTask(taskId) {
212
- return this.updateTaskStatus(taskId, 'cancelled');
214
+ async cancelTask(taskId, token) {
215
+ return this.updateTaskStatus(taskId, 'cancelled', token);
213
216
  }
214
217
  /**
215
218
  * 转换服务器任务格式
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import { WebSocketServer, WebSocket } from 'ws';
6
6
  import { authStore } from '../stores/index.js';
7
- import { getLogger } from '@pocketclaw/shared';
7
+ import { getLogger } from '@myassis/shared';
8
8
  const logger = getLogger('WebSocketService');
9
9
  class WebSocketService {
10
10
  wss = null;
@@ -93,13 +93,23 @@ class WebSocketService {
93
93
  }
94
94
  /**
95
95
  * 从请求中提取用户标识
96
- * Desktop 不存储 token,Gateway 直接信任连接并使用已登录用户的 ID
96
+ * 支持两种方式:
97
+ * 1. URL 查询参数 ?token=xxx(Desktop WebSocket 连接)
98
+ * 2. 直接使用 authStore 中的用户 ID
97
99
  */
98
100
  getClientKey(req) {
99
- // 直接使用 authStore 中的用户 ID(Gateway 登录后的用户)
100
- const userId = authStore.getUserId();
101
- if (userId) {
102
- return String(userId);
101
+ // 优先从 URL 查询参数中提取 token
102
+ let token = null;
103
+ const url = req.url || '';
104
+ const match = url.match(/[?&]token=([^&]+)/);
105
+ if (match) {
106
+ token = decodeURIComponent(match[1]);
107
+ }
108
+ if (token) {
109
+ const userId = authStore.getUserId(token);
110
+ if (userId) {
111
+ return String(userId);
112
+ }
103
113
  }
104
114
  return null;
105
115
  }
@@ -1,5 +1,5 @@
1
1
  import { v4 as uuidv4 } from 'uuid';
2
- import { sessionManager } from '../session/SessionManager';
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
@@ -16,7 +16,7 @@ export class Agent {
16
16
  updatedAt;
17
17
  isCurrent; // 是否是当前正在查看的 Agent
18
18
  store;
19
- constructor(data, store, agentManager) {
19
+ constructor(data, store) {
20
20
  this.id = data.id;
21
21
  this.userId = data.userId;
22
22
  this.name = data.name;
@@ -33,14 +33,14 @@ export class Agent {
33
33
  * Get all sessions under this agent
34
34
  */
35
35
  getSessions() {
36
- const allSessions = sessionManager.getUserSessions();
36
+ const allSessions = getSessionManager(this.userId).getUserSessions();
37
37
  return allSessions.filter(s => s.agentId === this.id);
38
38
  }
39
39
  /**
40
40
  * Create new session under this agent
41
41
  */
42
42
  createSession(config = {}) {
43
- const session = sessionManager.createSession({
43
+ const session = getSessionManager(this.userId).createSession({
44
44
  id: config.id || uuidv4(),
45
45
  title: config.title || '新会话',
46
46
  selectModelId: config.selectModelId,
@@ -55,7 +55,7 @@ export class Agent {
55
55
  const session = this.getSession(sessionId);
56
56
  if (!session)
57
57
  return null;
58
- return sessionManager.updateSession(sessionId, data);
58
+ return getSessionManager(this.userId).updateSession(sessionId, data);
59
59
  }
60
60
  /**
61
61
  * Delete session under this agent
@@ -64,13 +64,13 @@ export class Agent {
64
64
  const session = this.getSession(sessionId);
65
65
  if (!session)
66
66
  return false;
67
- return sessionManager.deleteSession(sessionId);
67
+ return getSessionManager(this.userId).deleteSession(sessionId);
68
68
  }
69
69
  /**
70
70
  * Get session under this agent
71
71
  */
72
72
  getSession(sessionId) {
73
- const session = sessionManager.getSession(sessionId);
73
+ const session = getSessionManager(this.userId).getSession(sessionId);
74
74
  if (session && session.agentId === this.id) {
75
75
  return session;
76
76
  }
@@ -1,8 +1,8 @@
1
1
  import { v4 as uuidv4 } from 'uuid';
2
2
  import { Agent } from './Agent';
3
- import { sessionManager } from '../session/SessionManager';
3
+ import { getSessionManager } from '../session/SessionManager';
4
4
  import { authStore } from '@/stores/authStore';
5
- import { getLogger } from '@pocketclaw/shared';
5
+ import { getLogger } from '@myassis/shared';
6
6
  import appConfig from '@/config';
7
7
  const logger = getLogger('AgentManager');
8
8
  /**
@@ -13,8 +13,10 @@ export class AgentManager {
13
13
  store;
14
14
  agents = null;
15
15
  initialized = false;
16
- constructor(store) {
16
+ userId;
17
+ constructor(store, userId) {
17
18
  this.store = store;
19
+ this.userId = userId;
18
20
  }
19
21
  /**
20
22
  * Initialize - Load all agents from database on startup
@@ -34,12 +36,12 @@ export class AgentManager {
34
36
  // Load all agents from database
35
37
  const agentDataList = this.store.findByUserId(userId);
36
38
  for (const agentData of agentDataList) {
37
- const agent = new Agent(agentData, this.store, this);
39
+ const agent = new Agent(agentData, this.store);
38
40
  this.agents.set(agent.id, agent);
39
41
  }
40
- // If no agents exist, create default "MyClaw" agent
42
+ // If no agents exist, create default "我的助手" agent
41
43
  if (this.agents.size === 0) {
42
- logger.info('No agents found, creating default "MyClaw" agent');
44
+ logger.info('No agents found, creating default "我的助手" agent');
43
45
  this.createDefaultAgent(userId);
44
46
  }
45
47
  // Ensure exactly one agent has isCurrent=true
@@ -58,11 +60,11 @@ export class AgentManager {
58
60
  * Get current user ID
59
61
  */
60
62
  getCurrentUserId() {
61
- const user = authStore.getUser();
63
+ const user = authStore.getUser(this.userId);
62
64
  return user ? String(user.id) : null;
63
65
  }
64
66
  /**
65
- * Create default "MyClaw" agent
67
+ * Create default "我的助手" agent
66
68
  */
67
69
  createDefaultAgent(userId) {
68
70
  const agentData = {
@@ -78,7 +80,7 @@ export class AgentManager {
78
80
  isCurrent: true,
79
81
  };
80
82
  this.store.insert(agentData);
81
- const agent = new Agent(agentData, this.store, this);
83
+ const agent = new Agent(agentData, this.store);
82
84
  this.agents.set(agent.id, agent);
83
85
  // Create default session
84
86
  agent.createSession({ title: '新会话' });
@@ -95,7 +97,7 @@ export class AgentManager {
95
97
  return [];
96
98
  const agentDataList = this.store.findByUserId(userId);
97
99
  return agentDataList.map(data => {
98
- const sessions = sessionManager.getUserSessions();
100
+ const sessions = getSessionManager(this.userId).getUserSessions();
99
101
  const agentSessions = sessions
100
102
  .filter(s => s.agentId === data.id)
101
103
  .map(s => ({
@@ -146,7 +148,7 @@ export class AgentManager {
146
148
  updatedAt: Date.now(),
147
149
  };
148
150
  this.store.insert(agentData);
149
- const agent = new Agent(agentData, this.store, this);
151
+ const agent = new Agent(agentData, this.store);
150
152
  this.agents.set(agent.id, agent);
151
153
  // Create default session
152
154
  agent.createSession({ title: '新会话' });
@@ -186,7 +188,7 @@ export class AgentManager {
186
188
  // Delete all sessions under this agent
187
189
  const sessions = agent.getSessions();
188
190
  for (const session of sessions) {
189
- sessionManager.deleteSession(session.id);
191
+ getSessionManager(this.userId).deleteSession(session.id);
190
192
  }
191
193
  // Delete agent
192
194
  this.store.delete(agentId);
@@ -233,12 +235,15 @@ export class AgentManager {
233
235
  * Get sessions under an agent
234
236
  */
235
237
  getAgentSessions(agentId) {
236
- const sessions = sessionManager.getUserSessions();
238
+ const sessions = getSessionManager(this.userId).getUserSessions();
237
239
  return sessions
238
240
  .filter(s => s.agentId === agentId)
239
241
  .map(s => ({
240
242
  id: s.id,
241
243
  title: s.title,
244
+ selectModelId: s.selectModelId,
245
+ isCurrent: s.isCurrent,
246
+ unreadCount: s.unreadCount,
242
247
  createdAt: s.createdAt,
243
248
  updatedAt: s.updatedAt,
244
249
  }));
@@ -258,8 +263,11 @@ export class AgentManager {
258
263
  }
259
264
  }
260
265
  // Export singleton
261
- export let agentManager;
262
- export function initAgentManager(store) {
263
- agentManager = new AgentManager(store);
264
- return agentManager;
266
+ export let agentManagerMap = new Map();
267
+ export function initAgentManager(store, userId) {
268
+ if (agentManagerMap.has(userId)) {
269
+ return agentManagerMap.get(userId);
270
+ }
271
+ agentManagerMap.set(userId, new AgentManager(store, userId));
272
+ return agentManagerMap.get(userId);
265
273
  }
@@ -1,4 +1,4 @@
1
- import { getLogger } from '@pocketclaw/shared';
1
+ import { getLogger } from '@myassis/shared';
2
2
  const logger = getLogger('AgentStore');
3
3
  /**
4
4
  * AgentStore - Data access layer
@@ -10,7 +10,7 @@
10
10
  import { authApi, skillsApi, skillHubApi, modelsApi, settingsApi } from '../api';
11
11
  import { authStore, memoryStore, persistStore } from '../stores';
12
12
  import { taskService } from './TaskService';
13
- import { getLogger } from '@pocketclaw/shared';
13
+ import { getLogger } from '@myassis/shared';
14
14
  const logger = getLogger('DataService');
15
15
  // ============ 认证服务 ============
16
16
  export const authService = {
@@ -20,7 +20,7 @@ export const authService = {
20
20
  if (response.success && response.data) {
21
21
  const expiresIn = response.data.expiresIn || 86400;
22
22
  authStore.save({
23
- token: response.data.accessToken,
23
+ accessToken: response.data.accessToken,
24
24
  refreshToken: response.data.refreshToken,
25
25
  expiresIn,
26
26
  expiresAt: Date.now() + expiresIn * 1000,
@@ -40,7 +40,7 @@ export const authService = {
40
40
  if (response.success && response.data) {
41
41
  const expiresIn = response.data.expiresIn || 86400;
42
42
  authStore.save({
43
- token: response.data.accessToken,
43
+ accessToken: response.data.accessToken,
44
44
  refreshToken: response.data.refreshToken,
45
45
  expiresIn,
46
46
  expiresAt: Date.now() + expiresIn * 1000,
@@ -50,9 +50,9 @@ export const authService = {
50
50
  return response;
51
51
  },
52
52
  // 登出
53
- logout: async () => {
53
+ logout: async (token) => {
54
54
  try {
55
- await authApi.logout();
55
+ await authApi.logout(token);
56
56
  }
57
57
  catch (e) {
58
58
  // 忽略错误
@@ -61,19 +61,15 @@ export const authService = {
61
61
  return { success: true };
62
62
  },
63
63
  // 获取当前用户
64
- me: () => authApi.me(),
64
+ me: (token) => authApi.me(token),
65
65
  // 更新资料
66
- updateProfile: (data) => authApi.updateProfile(data),
66
+ updateProfile: (data, token) => authApi.updateProfile(data, token),
67
67
  // 修改密码
68
- changePassword: (oldPassword, newPassword) => authApi.changePassword({ oldPassword, newPassword }),
68
+ changePassword: (oldPassword, newPassword, token) => authApi.changePassword({ oldPassword, newPassword }, token),
69
69
  // 删除账号
70
- deleteAccount: (password) => authApi.deleteAccount({ password }),
71
- // 获取认证状态
72
- isAuthenticated: () => authStore.isAuthenticated(),
70
+ deleteAccount: (password, token) => authApi.deleteAccount({ password }, token),
73
71
  // 获取当前用户(从内存)
74
- getUser: () => authStore.get()?.user || null,
75
- // 获取 Token
76
- getToken: () => authStore.getToken(),
72
+ getUser: (token) => authStore.get(token)?.user || null,
77
73
  // 刷新 Token
78
74
  refresh: async (refreshToken) => {
79
75
  const response = await authApi.refresh(refreshToken);
@@ -81,21 +77,15 @@ export const authService = {
81
77
  authStore.updateToken(response.accessToken, response.refreshToken);
82
78
  }
83
79
  return response;
84
- },
85
- // 检查认证(供 Desktop 使用)
86
- checkAuth: async () => {
87
- const isAuth = authStore.isAuthenticated();
88
- const user = authStore.get()?.user || null;
89
- return { success: true, authenticated: isAuth, user };
90
80
  }
91
81
  };
92
82
  // ============ 技能服务 (用户已安装的技能) ============
93
83
  export const skillsService = {
94
- list: async () => await skillsApi.list(),
95
- get: (skillId) => skillsApi.get(skillId),
96
- install: async (skillHubId) => {
84
+ list: async (token) => await skillsApi.list(token),
85
+ get: (skillId, token) => skillsApi.get(skillId, token),
86
+ install: async (skillHubId, token) => {
97
87
  // 1. 从技能库获取技能详情
98
- const hubResult = await skillHubApi.get(skillHubId);
88
+ const hubResult = await skillHubApi.get(skillHubId, token);
99
89
  if (!hubResult.success || !hubResult.data) {
100
90
  return { success: false, error: '获取技能详情失败' };
101
91
  }
@@ -110,26 +100,26 @@ export const skillsService = {
110
100
  isActive: true,
111
101
  apiKeyRequired: hub.apiKeyRequired || false,
112
102
  };
113
- const response = await skillsApi.create(skillData);
103
+ const response = await skillsApi.create(skillData, token);
114
104
  if (response.success) {
115
105
  // 3. 增加安装计数
116
- await skillHubApi.install(skillHubId);
106
+ await skillHubApi.install(skillHubId, token);
117
107
  }
118
108
  return response;
119
109
  },
120
- update: (skillId, data) => skillsApi.update(skillId, data),
121
- uninstall: async (skillId) => await skillsApi.uninstall(skillId),
122
- setApiKey: (skillId, apiKey) => {
110
+ update: (skillId, data, token) => skillsApi.update(skillId, data, token),
111
+ uninstall: async (skillId, token) => await skillsApi.uninstall(skillId, token),
112
+ setApiKey: (skillId, apiKey, token) => {
123
113
  persistStore.setSkillApiKey(skillId, apiKey);
124
114
  return { success: true };
125
115
  },
126
- getApiKey: async (skillId) => {
116
+ getApiKey: async (skillId, token) => {
127
117
  const apikey = persistStore.getSkillApiKey(skillId);
128
118
  if (!apikey) {
129
119
  // 判断是否有内置 apikey
130
- const skill = (await skillsService.get(skillId)).data;
120
+ const skill = (await skillsService.get(skillId, token)).data;
131
121
  if (skill.templateId) {
132
- const skillHub = (await skillHubService.get(skill.templateId)).data;
122
+ const skillHub = (await skillHubService.get(skill.templateId, token)).data;
133
123
  if (skillHub?.builtinApikey) {
134
124
  persistStore.setSkillApiKey(skillId, skillHub.builtinApikey);
135
125
  return { success: true, apiKey: skillHub.builtinApikey };
@@ -138,13 +128,13 @@ export const skillsService = {
138
128
  }
139
129
  return { success: true, apiKey: apikey?.apiKey };
140
130
  },
141
- rate: (skillId, score) => skillsApi.rate(skillId, { score }),
142
- parse: (content) => skillsApi.parse({ content }),
143
- create: async (data) => {
144
- const response = await skillsApi.create(data);
131
+ rate: (skillId, score, token) => skillsApi.rate(skillId, { score }, token),
132
+ parse: (content, token) => skillsApi.parse({ content }, token),
133
+ create: async (data, token) => {
134
+ const response = await skillsApi.create(data, token);
145
135
  if (response.success) {
146
136
  // 创建成功后更新技能列表缓存
147
- const listResponse = await skillsApi.list();
137
+ const listResponse = await skillsApi.list(token);
148
138
  if (listResponse.success) {
149
139
  memoryStore.set('skills', listResponse.data);
150
140
  }
@@ -154,28 +144,28 @@ export const skillsService = {
154
144
  };
155
145
  // ============ 技能库服务 (可安装的技能) ============
156
146
  export const skillHubService = {
157
- list: (params) => skillHubApi.list(params),
158
- get: (hubId) => skillHubApi.get(hubId),
159
- categories: () => skillHubApi.categories(),
160
- preinstalled: () => skillHubApi.preinstalled(),
161
- user: () => skillHubApi.user(),
162
- checkUsed: (hubId) => skillHubApi.checkUsed(hubId),
163
- rate: (hubId, rating) => skillHubApi.rate(hubId, rating),
164
- userRating: (hubId) => skillHubApi.userRating(hubId),
165
- install: (hubId) => skillHubApi.install(hubId),
166
- use: (hubId) => skillHubApi.use(hubId),
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),
167
157
  };
168
158
  // ============ 模型服务 ============
169
159
  export const modelsService = {
170
- list: () => modelsApi.list(),
171
- get: (modelId) => modelsApi.get(modelId),
172
- create: (data) => modelsApi.create(data),
173
- update: (modelId, data) => modelsApi.update(modelId, data),
174
- delete: (modelId) => modelsApi.delete(modelId),
175
- setPrimary: (modelId) => modelsApi.setPrimary(modelId),
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),
176
166
  };
177
167
  export const tasksService = {
178
- list: async (params, userId) => {
168
+ list: async (userId, params) => {
179
169
  const result = await taskService.listTasks({
180
170
  status: params?.status,
181
171
  userId,
@@ -184,13 +174,13 @@ export const tasksService = {
184
174
  });
185
175
  return { success: true, data: result.tasks, total: result.total };
186
176
  },
187
- get: async (taskId) => {
188
- const task = await taskService.getTask(taskId);
177
+ get: async (taskId, token) => {
178
+ const task = await taskService.getTask(taskId, token);
189
179
  if (!task)
190
180
  return { success: false, error: 'Task not found' };
191
181
  return { success: true, data: task };
192
182
  },
193
- create: async (data, userId) => {
183
+ create: async (data, userId, token) => {
194
184
  const uid = userId || data?.userId || 'local';
195
185
  try {
196
186
  const result = await taskService.createTask({
@@ -206,7 +196,7 @@ export const tasksService = {
206
196
  endTime: data.endTime,
207
197
  platformApply: data.platformApply,
208
198
  pushToken: data.pushToken,
209
- });
199
+ }, token);
210
200
  return { success: true, data: { id: result.id, isLocal: result.isLocal } };
211
201
  }
212
202
  catch (error) {
@@ -214,7 +204,7 @@ export const tasksService = {
214
204
  return { success: false, error: error.message };
215
205
  }
216
206
  },
217
- update: async (taskId, data) => {
207
+ update: async (taskId, data, token) => {
218
208
  try {
219
209
  const result = await taskService.updateTask(taskId, {
220
210
  title: data.title,
@@ -229,7 +219,7 @@ export const tasksService = {
229
219
  status: data.status,
230
220
  platformApply: data.platformApply,
231
221
  pushToken: data.pushToken,
232
- });
222
+ }, token);
233
223
  return { success: result };
234
224
  }
235
225
  catch (error) {
@@ -237,9 +227,9 @@ export const tasksService = {
237
227
  return { success: false, error: error.message };
238
228
  }
239
229
  },
240
- delete: async (taskId) => {
230
+ delete: async (taskId, token) => {
241
231
  try {
242
- const result = await taskService.deleteTask(taskId);
232
+ const result = await taskService.deleteTask(taskId, token);
243
233
  return { success: result };
244
234
  }
245
235
  catch (error) {
@@ -247,9 +237,9 @@ export const tasksService = {
247
237
  return { success: false, error: error.message };
248
238
  }
249
239
  },
250
- cancel: async (taskId) => {
240
+ cancel: async (taskId, token) => {
251
241
  try {
252
- const result = await taskService.cancelTask(taskId);
242
+ const result = await taskService.cancelTask(taskId, token);
253
243
  return { success: result };
254
244
  }
255
245
  catch (error) {
@@ -257,9 +247,9 @@ export const tasksService = {
257
247
  return { success: false, error: error.message };
258
248
  }
259
249
  },
260
- updateStatus: async (taskId, status) => {
250
+ updateStatus: async (taskId, status, token) => {
261
251
  try {
262
- const result = await taskService.updateTaskStatus(taskId, status);
252
+ const result = await taskService.updateTaskStatus(taskId, status, token);
263
253
  return { success: result };
264
254
  }
265
255
  catch (error) {
@@ -270,21 +260,21 @@ export const tasksService = {
270
260
  };
271
261
  // ============ 设置服务 ============
272
262
  export const settingsService = {
273
- get: async () => {
263
+ get: async (token) => {
274
264
  const settings = memoryStore.get('settings'); // 预热缓存
275
265
  if (settings) {
276
266
  return { success: true, data: settings };
277
267
  }
278
268
  else {
279
- const response = await settingsApi.get();
269
+ const response = await settingsApi.get(token);
280
270
  if (response.success) {
281
271
  memoryStore.set('settings', response.data); // 更新缓存
282
272
  }
283
273
  return response;
284
274
  }
285
275
  },
286
- update: async (data) => {
287
- const response = await settingsApi.update(data);
276
+ update: async (data, token) => {
277
+ const response = await settingsApi.update(data, token);
288
278
  if (response.success) {
289
279
  memoryStore.set('settings', response.data); // 更新缓存
290
280
  }
@@ -3,7 +3,7 @@ export { authService, skillsService, skillHubService, modelsService, settingsSer
3
3
  // Re-export tasksService from dataService (server-only tasks)
4
4
  export { tasksService } from './dataService';
5
5
  // Re-export session manager
6
- export { sessionManager } from './session';
6
+ export { getSessionManager } from './session';
7
7
  // Re-export task services
8
8
  export { taskSchedulerService } from './TaskSchedulerService';
9
9
  export { taskService } from './TaskService';