@myassis/gateway 1.0.10 → 1.0.12
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/middleware/auth.js +1 -1
- package/dist/routes/agent.js +4 -4
- package/dist/services/TaskSchedulerService.js +2 -2
- package/dist/services/TaskService.js +2 -2
- package/dist/services/agent/Agent.js +1 -1
- package/dist/services/agent/AgentManager.js +3 -3
- package/dist/services/dataService.js +2 -2
- package/dist/services/llm/LLMClient.js +1 -1
- package/dist/services/memory/MemoryManager.js +5 -5
- package/dist/services/session/Session.js +9 -9
- package/dist/services/session/SessionManager.js +1 -1
- package/dist/services/systemPrompt.js +1 -1
- package/dist/services/task/PushTokenStore.js +1 -1
- package/dist/services/task/TaskStore.js +1 -1
- package/dist/services/tools/model.js +2 -2
- package/dist/services/tools/sessionsSpawn.js +1 -1
- package/dist/services/tools/skill.js +2 -2
- package/dist/services/tools/task.js +1 -1
- package/migrations/001_create_sessions_table.sql +38 -0
- package/migrations/002_alter_message_table.sql +3 -0
- package/migrations/003_add_tool_calls_data.sql +2 -0
- package/migrations/004_add_last_summary.sql +2 -0
- package/migrations/005_add_message_model_name.sql +1 -0
- package/migrations/006_add_unread_count.sql +1 -0
- package/migrations/008_add_agents_is_current.sql +12 -0
- package/migrations/009_add_is_current.sql +1 -0
- package/migrations/010_message_tool_call.sql +4 -0
- package/migrations/011_drop_message_toolcallsdata.sql +1 -0
- package/package.json +3 -2
- package/scripts/fix-esm-imports.js +16 -5
package/dist/middleware/auth.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* 从请求头 Authorization: Bearer <token> 解码 JWT,提取 userId
|
|
4
4
|
* 同时保留原始 token 供路由转发给 Server
|
|
5
5
|
*/
|
|
6
|
-
import { authStore } from '../stores';
|
|
6
|
+
import { authStore } from '../stores/authStore.js';
|
|
7
7
|
import { getLogger } from '@myassis/shared';
|
|
8
8
|
const logger = getLogger('middleware/auth');
|
|
9
9
|
const JWT_SECRET = process.env.JWT_SECRET || 'your-secret-key-change-in-production';
|
package/dist/routes/agent.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
2
|
import { requireAuth } from '../middleware/auth.js';
|
|
3
3
|
import { runWithToken } from '../api/index.js';
|
|
4
|
-
import { getSessionManager } from '../services/session';
|
|
5
|
-
import { initAgentManager, agentManagerMap } from '../services/agent/AgentManager';
|
|
6
|
-
import { AgentStore } from '../services/agent/AgentStore';
|
|
4
|
+
import { getSessionManager } from '../services/session/index.js';
|
|
5
|
+
import { initAgentManager, agentManagerMap } from '../services/agent/AgentManager.js';
|
|
6
|
+
import { AgentStore } from '../services/agent/AgentStore.js';
|
|
7
7
|
import { getLogger } from '@myassis/shared';
|
|
8
8
|
const logger = getLogger('AgentRoutes');
|
|
9
|
-
import { sessionStore } from '../services/session/SessionStore';
|
|
9
|
+
import { sessionStore } from '../services/session/SessionStore.js';
|
|
10
10
|
const router = Router();
|
|
11
11
|
// 所有路由需要认证
|
|
12
12
|
router.use(requireAuth, (req, _res, next) => {
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { taskStore } from './task/TaskStore.js';
|
|
7
7
|
import { webSocketService } from './WebSocketService.js';
|
|
8
|
-
import { getSessionManager } from './session.js';
|
|
8
|
+
import { getSessionManager } from './session/index.js';
|
|
9
9
|
import { getLogger, getUTCTimeKey, formatUTCForLog, holidayService } from '@myassis/shared';
|
|
10
10
|
import { tasksService } from './dataService.js';
|
|
11
|
-
import { authStore } from '../stores';
|
|
11
|
+
import { authStore } from '../stores/authStore.js';
|
|
12
12
|
const logger = getLogger('TaskSchedulerService');
|
|
13
13
|
const EXPIRED_THRESHOLD = 60 * 60 * 1000; // 1小时
|
|
14
14
|
const CHECK_INTERVAL = 60 * 1000; // 1分钟
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* - platformApply === currentPlatform → 本地 SQLite 存储(localTaskService)
|
|
8
8
|
* - platformApply !== currentPlatform → 服务器 API(tasksApi)
|
|
9
9
|
*/
|
|
10
|
-
import { authStore } from '../stores';
|
|
11
|
-
import { tasksApi } from '../api';
|
|
10
|
+
import { authStore } from '../stores/index.js';
|
|
11
|
+
import { tasksApi } from '../api/index.js';
|
|
12
12
|
import { localTaskService } from './LocalTaskService.js';
|
|
13
13
|
import { getLogger } from '@myassis/shared';
|
|
14
14
|
import { getPlatform } from '@myassis/shared/dist/utils/system.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { v4 as uuidv4 } from 'uuid';
|
|
2
|
-
import { getSessionManager } from '../session/SessionManager';
|
|
2
|
+
import { getSessionManager } from '../session/SessionManager.js';
|
|
3
3
|
/**
|
|
4
4
|
* Agent - Business logic entity
|
|
5
5
|
* Represents an AI agent with independent system prompt and multiple sessions
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { v4 as uuidv4 } from 'uuid';
|
|
2
2
|
import { Agent } from './Agent.js';
|
|
3
|
-
import { getSessionManager } from '../session/SessionManager';
|
|
4
|
-
import { authStore } from '../../stores/authStore';
|
|
3
|
+
import { getSessionManager } from '../session/SessionManager.js';
|
|
4
|
+
import { authStore } from '../../stores/authStore.js';
|
|
5
5
|
import { getLogger } from '@myassis/shared';
|
|
6
|
-
import appConfig from '../../config';
|
|
6
|
+
import appConfig from '../../config/index.js';
|
|
7
7
|
const logger = getLogger('AgentManager');
|
|
8
8
|
/**
|
|
9
9
|
* AgentManager - Business logic layer
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* - /api/v1/data/* - 用户数据路由 (models, skills, tasks, settings)
|
|
8
8
|
* - /api/v1/skill-hubs/* - 技能库路由
|
|
9
9
|
*/
|
|
10
|
-
import { authApi, skillsApi, skillHubApi, modelsApi, settingsApi } from '../api';
|
|
11
|
-
import { authStore, memoryStore, persistStore } from '../stores';
|
|
10
|
+
import { authApi, skillsApi, skillHubApi, modelsApi, settingsApi } from '../api/index.js';
|
|
11
|
+
import { authStore, memoryStore, persistStore } from '../stores/index.js';
|
|
12
12
|
import { taskService } from './TaskService.js';
|
|
13
13
|
import { getLogger } from '@myassis/shared';
|
|
14
14
|
const logger = getLogger('DataService');
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { getLogger } from '@myassis/shared';
|
|
2
2
|
const logger = getLogger('MemoryManager');
|
|
3
|
-
import { toModel } from '../models';
|
|
4
|
-
import { modelsService } from '../dataService';
|
|
5
|
-
import { authStore } from '../../stores';
|
|
6
|
-
import { LLMClient } from '../llm/LLMClient';
|
|
7
|
-
import { appConfig } from '../../config';
|
|
3
|
+
import { toModel } from '../models.js';
|
|
4
|
+
import { modelsService } from '../dataService.js';
|
|
5
|
+
import { authStore } from '../../stores/index.js';
|
|
6
|
+
import { LLMClient } from '../llm/LLMClient.js';
|
|
7
|
+
import { appConfig } from '../../config/index.js';
|
|
8
8
|
const DEFAULT_CONFIG = {
|
|
9
9
|
summaryThreshold: 10,
|
|
10
10
|
enabled: true,
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { v4 as uuidv4 } from 'uuid';
|
|
2
2
|
import { getLogger } from '@myassis/shared';
|
|
3
3
|
import { SessionStore } from './SessionStore.js';
|
|
4
|
-
import { AgentStore } from '../../services/agent/AgentStore';
|
|
5
|
-
import { authStore } from '../../stores/authStore';
|
|
6
|
-
import { toModel } from '../../services/models';
|
|
7
|
-
import { executeTool, getToolDefinitions } from '../../services/tools';
|
|
8
|
-
import { getSystemPromptAsync } from '../systemPrompt';
|
|
9
|
-
import { LLMClient, parseAruments } from '../llm/LLMClient';
|
|
10
|
-
import { modelsService, settingsService } from '../../services/dataService';
|
|
11
|
-
import { MemoryManager } from '../memory/MemoryManager';
|
|
12
|
-
import { appConfig } from '../../config';
|
|
4
|
+
import { AgentStore } from '../../services/agent/AgentStore.js';
|
|
5
|
+
import { authStore } from '../../stores/authStore.js';
|
|
6
|
+
import { toModel } from '../../services/models.js';
|
|
7
|
+
import { executeTool, getToolDefinitions } from '../../services/tools/index.js';
|
|
8
|
+
import { getSystemPromptAsync } from '../systemPrompt.js';
|
|
9
|
+
import { LLMClient, parseAruments } from '../llm/LLMClient.js';
|
|
10
|
+
import { modelsService, settingsService } from '../../services/dataService.js';
|
|
11
|
+
import { MemoryManager } from '../memory/MemoryManager.js';
|
|
12
|
+
import { appConfig } from '../../config/index.js';
|
|
13
13
|
import { getSessionManager } from './SessionManager.js';
|
|
14
14
|
const logger = getLogger('Session');
|
|
15
15
|
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
@@ -2,7 +2,7 @@ import { v4 as uuidv4 } from 'uuid';
|
|
|
2
2
|
import { getLogger } from '@myassis/shared';
|
|
3
3
|
const logger = getLogger('SessionManager');
|
|
4
4
|
import { sessionStore } from './SessionStore.js';
|
|
5
|
-
import { authStore } from '../../stores/authStore';
|
|
5
|
+
import { authStore } from '../../stores/authStore.js';
|
|
6
6
|
import { Session } from './Session.js';
|
|
7
7
|
/**
|
|
8
8
|
* SessionManager - Business logic layer
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { getLogger } from '@myassis/shared';
|
|
6
6
|
const logger = getLogger('PushTokenStore');
|
|
7
|
-
import { sessionStore } from '../session/SessionStore';
|
|
7
|
+
import { sessionStore } from '../session/SessionStore.js';
|
|
8
8
|
export class PushTokenStore {
|
|
9
9
|
db;
|
|
10
10
|
constructor() {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* 操作 SQLite 数据库,与 AgentStore/SessionStore 共享同一个数据库实例
|
|
4
4
|
*/
|
|
5
5
|
import { getLogger } from '@myassis/shared';
|
|
6
|
-
import { sessionStore } from '../session/SessionStore';
|
|
6
|
+
import { sessionStore } from '../session/SessionStore.js';
|
|
7
7
|
const logger = getLogger('TaskStore');
|
|
8
8
|
function rowToTaskData(row) {
|
|
9
9
|
return {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { modelsService } from '../dataService';
|
|
2
|
-
import { authStore } from '../../stores';
|
|
1
|
+
import { modelsService } from '../dataService.js';
|
|
2
|
+
import { authStore } from '../../stores/index.js';
|
|
3
3
|
export const modelTool = {
|
|
4
4
|
name: 'model',
|
|
5
5
|
description: '模型管理工具',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { v4 as uuidv4 } from 'uuid';
|
|
2
2
|
import { getLogger } from '@myassis/shared';
|
|
3
|
-
import { getSessionManager } from '../session';
|
|
3
|
+
import { getSessionManager } from '../session/index.js';
|
|
4
4
|
const logger = getLogger('sessionsSpawn');
|
|
5
5
|
export const sessionsSpawnTool = {
|
|
6
6
|
name: 'sessions_spawn',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { skillsService, skillHubService } from '../dataService';
|
|
2
|
-
import { authStore, persistStore } from '../../stores';
|
|
1
|
+
import { skillsService, skillHubService } from '../dataService.js';
|
|
2
|
+
import { authStore, persistStore } from '../../stores/index.js';
|
|
3
3
|
import { getLogger } from '@myassis/shared';
|
|
4
4
|
const logger = getLogger('skill');
|
|
5
5
|
export const skillTool = {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
-- 创建 agents 表
|
|
2
|
+
CREATE TABLE IF NOT EXISTS agents (
|
|
3
|
+
id TEXT PRIMARY KEY,
|
|
4
|
+
user_id TEXT NOT NULL,
|
|
5
|
+
name TEXT NOT NULL,
|
|
6
|
+
description TEXT,
|
|
7
|
+
system_prompt TEXT,
|
|
8
|
+
avatar TEXT,
|
|
9
|
+
config TEXT,
|
|
10
|
+
created_at INTEGER NOT NULL,
|
|
11
|
+
updated_at INTEGER NOT NULL
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
-- 为 sessions 表添加 agent_id 外键
|
|
15
|
+
CREATE TABLE IF NOT EXISTS sessions (
|
|
16
|
+
id TEXT PRIMARY KEY,
|
|
17
|
+
user_id TEXT NOT NULL,
|
|
18
|
+
agent_id TEXT,
|
|
19
|
+
title TEXT NOT NULL,
|
|
20
|
+
select_model_id TEXT,
|
|
21
|
+
voice_state TEXT,
|
|
22
|
+
created_at INTEGER NOT NULL,
|
|
23
|
+
updated_at INTEGER NOT NULL,
|
|
24
|
+
FOREIGN KEY (agent_id) REFERENCES agents(id) ON DELETE CASCADE
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
-- 创建 messages 表的 tool_calls 列
|
|
28
|
+
CREATE TABLE IF NOT EXISTS messages (
|
|
29
|
+
id TEXT PRIMARY KEY,
|
|
30
|
+
session_id TEXT NOT NULL,
|
|
31
|
+
role TEXT NOT NULL,
|
|
32
|
+
content TEXT,
|
|
33
|
+
attachments TEXT DEFAULT '[]',
|
|
34
|
+
tool_calls TEXT DEFAULT '[]',
|
|
35
|
+
created_at INTEGER NOT NULL,
|
|
36
|
+
updated_at INTEGER NOT NULL,
|
|
37
|
+
FOREIGN KEY (session_id) REFERENCES sessions(id) ON DELETE CASCADE
|
|
38
|
+
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
alter table messages add column model_name text default null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
alter table sessions add column unread_count integer default 0 not null;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
-- Add is_current column to agents table
|
|
2
|
+
ALTER TABLE agents ADD COLUMN is_current INTEGER DEFAULT 0;
|
|
3
|
+
|
|
4
|
+
-- Set the first agent (by created_at) as current for each user
|
|
5
|
+
UPDATE agents
|
|
6
|
+
SET is_current = 1
|
|
7
|
+
WHERE id IN (
|
|
8
|
+
SELECT id FROM agents
|
|
9
|
+
GROUP BY user_id
|
|
10
|
+
ORDER BY created_at ASC
|
|
11
|
+
LIMIT 1
|
|
12
|
+
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
alter table sessions add column is_current INTEGER DEFAULT 0;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
alter table messages drop column tool_calls_data;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@myassis/gateway",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"description": "我的助手 Gateway Service - 本地 AI 网关服务,支持认证、WebSocket 实时通信和任务调度",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"dist",
|
|
13
13
|
"scripts",
|
|
14
14
|
"README.md",
|
|
15
|
-
"LICENSE"
|
|
15
|
+
"LICENSE",
|
|
16
|
+
"migrations"
|
|
16
17
|
],
|
|
17
18
|
"exports": {
|
|
18
19
|
".": {
|
|
@@ -16,14 +16,25 @@ async function addJsExtensionToImports(filePath) {
|
|
|
16
16
|
let content = await readFile(filePath, 'utf8');
|
|
17
17
|
let modified = false;
|
|
18
18
|
|
|
19
|
-
// 替换静态导入
|
|
20
|
-
content = content.replace(
|
|
19
|
+
// 替换静态导入 - 匹配各种相对路径
|
|
20
|
+
content = content.replace(/from\s+['"]([^'"\n]+)['"]/g, (match, importPath) => {
|
|
21
|
+
// 如果是 node_modules 或绝对路径,跳过
|
|
22
|
+
if (importPath.startsWith('@myassis/') || importPath.startsWith('/')) {
|
|
23
|
+
return match;
|
|
24
|
+
}
|
|
25
|
+
|
|
21
26
|
// 如果已经有扩展名,跳过
|
|
22
|
-
if (importPath.endsWith('.js') || importPath.endsWith('.json') || importPath.endsWith('.ts')) {
|
|
27
|
+
if (importPath.endsWith('.js') || importPath.endsWith('.json') || importPath.endsWith('.ts') || importPath.endsWith('.cjs') || importPath.endsWith('.mjs')) {
|
|
23
28
|
return match;
|
|
24
29
|
}
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
|
|
31
|
+
// 只处理相对路径 (./ 或 ../)
|
|
32
|
+
if (importPath.startsWith('.') || importPath.startsWith('..')) {
|
|
33
|
+
modified = true;
|
|
34
|
+
return `from '${importPath}.js'`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return match;
|
|
27
38
|
});
|
|
28
39
|
|
|
29
40
|
// 替换动态导入
|