@cicctencent/agent-midway 0.1.1
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/README.md +280 -0
- package/dist/adapters/express.d.ts +8 -0
- package/dist/adapters/express.js +91 -0
- package/dist/adapters/index.d.ts +5 -0
- package/dist/adapters/index.js +21 -0
- package/dist/adapters/koa.d.ts +3 -0
- package/dist/adapters/koa.js +75 -0
- package/dist/adapters/midway.d.ts +5 -0
- package/dist/adapters/midway.js +11 -0
- package/dist/adapters/next.d.ts +12 -0
- package/dist/adapters/next.js +89 -0
- package/dist/adapters/shared.d.ts +4 -0
- package/dist/adapters/shared.js +31 -0
- package/dist/channel/dingtalk.d.ts +18 -0
- package/dist/channel/dingtalk.js +68 -0
- package/dist/channel/feishu.d.ts +20 -0
- package/dist/channel/feishu.js +96 -0
- package/dist/channel/index.d.ts +46 -0
- package/dist/channel/index.js +311 -0
- package/dist/channel/types.d.ts +77 -0
- package/dist/channel/types.js +7 -0
- package/dist/channel/wecom.d.ts +22 -0
- package/dist/channel/wecom.js +106 -0
- package/dist/component.d.ts +49 -0
- package/dist/component.js +129 -0
- package/dist/connector/calendar-adapter.d.ts +19 -0
- package/dist/connector/calendar-adapter.js +236 -0
- package/dist/connector/db-adapter.d.ts +28 -0
- package/dist/connector/db-adapter.js +193 -0
- package/dist/connector/email-adapter.d.ts +23 -0
- package/dist/connector/email-adapter.js +192 -0
- package/dist/connector/fs-adapter.d.ts +15 -0
- package/dist/connector/fs-adapter.js +199 -0
- package/dist/connector/http-adapter.d.ts +29 -0
- package/dist/connector/http-adapter.js +181 -0
- package/dist/connector/index.d.ts +24 -0
- package/dist/connector/index.js +454 -0
- package/dist/connector/mcp-adapter.d.ts +27 -0
- package/dist/connector/mcp-adapter.js +156 -0
- package/dist/connector/mq-adapter.d.ts +25 -0
- package/dist/connector/mq-adapter.js +181 -0
- package/dist/connector/types.d.ts +205 -0
- package/dist/connector/types.js +9 -0
- package/dist/controller/a2a.controller.d.ts +41 -0
- package/dist/controller/a2a.controller.js +150 -0
- package/dist/controller/agent-profile.controller.d.ts +97 -0
- package/dist/controller/agent-profile.controller.js +200 -0
- package/dist/controller/agent.controller.d.ts +199 -0
- package/dist/controller/agent.controller.js +414 -0
- package/dist/controller/application.controller.d.ts +113 -0
- package/dist/controller/application.controller.js +217 -0
- package/dist/controller/automation.controller.d.ts +113 -0
- package/dist/controller/automation.controller.js +246 -0
- package/dist/controller/channel.controller.d.ts +73 -0
- package/dist/controller/channel.controller.js +183 -0
- package/dist/controller/chat.controller.d.ts +188 -0
- package/dist/controller/chat.controller.js +375 -0
- package/dist/controller/connector.controller.d.ts +134 -0
- package/dist/controller/connector.controller.js +257 -0
- package/dist/controller/knowledge-base.controller.d.ts +157 -0
- package/dist/controller/knowledge-base.controller.js +278 -0
- package/dist/controller/mcp-server.controller.d.ts +115 -0
- package/dist/controller/mcp-server.controller.js +236 -0
- package/dist/controller/model-config.controller.d.ts +139 -0
- package/dist/controller/model-config.controller.js +274 -0
- package/dist/controller/observability.controller.d.ts +124 -0
- package/dist/controller/observability.controller.js +142 -0
- package/dist/controller/security.controller.d.ts +91 -0
- package/dist/controller/security.controller.js +172 -0
- package/dist/controller/settings.controller.d.ts +83 -0
- package/dist/controller/settings.controller.js +280 -0
- package/dist/core/ai-workstation.d.ts +17 -0
- package/dist/core/ai-workstation.js +129 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.js +20 -0
- package/dist/core/service-container.d.ts +12 -0
- package/dist/core/service-container.js +54 -0
- package/dist/core/sse.d.ts +6 -0
- package/dist/core/sse.js +56 -0
- package/dist/core/types.d.ts +72 -0
- package/dist/core/types.js +2 -0
- package/dist/dto/agent.dto.d.ts +21 -0
- package/dist/dto/agent.dto.js +79 -0
- package/dist/dto/ai-config.dto.d.ts +67 -0
- package/dist/dto/ai-config.dto.js +249 -0
- package/dist/dto/chat.dto.d.ts +40 -0
- package/dist/dto/chat.dto.js +122 -0
- package/dist/index.d.ts +101 -0
- package/dist/index.js +195 -0
- package/dist/memory/db-store.d.ts +33 -0
- package/dist/memory/db-store.js +143 -0
- package/dist/memory/index.d.ts +187 -0
- package/dist/memory/index.js +443 -0
- package/dist/model/ai-agent-profile.entity.d.ts +32 -0
- package/dist/model/ai-agent-profile.entity.js +289 -0
- package/dist/model/ai-application.entity.d.ts +20 -0
- package/dist/model/ai-application.entity.js +166 -0
- package/dist/model/ai-chat-memory.entity.d.ts +16 -0
- package/dist/model/ai-chat-memory.entity.js +123 -0
- package/dist/model/ai-chat-message.entity.d.ts +16 -0
- package/dist/model/ai-chat-message.entity.js +122 -0
- package/dist/model/ai-chat-skill.entity.d.ts +19 -0
- package/dist/model/ai-chat-skill.entity.js +155 -0
- package/dist/model/ai-chat-thread.entity.d.ts +15 -0
- package/dist/model/ai-chat-thread.entity.js +113 -0
- package/dist/model/ai-chat-workspace.entity.d.ts +17 -0
- package/dist/model/ai-chat-workspace.entity.js +136 -0
- package/dist/model/ai-kb-document.entity.d.ts +16 -0
- package/dist/model/ai-kb-document.entity.js +122 -0
- package/dist/model/ai-knowledge-base.entity.d.ts +22 -0
- package/dist/model/ai-knowledge-base.entity.js +185 -0
- package/dist/model/ai-mcp-server.entity.d.ts +23 -0
- package/dist/model/ai-mcp-server.entity.js +198 -0
- package/dist/model/ai-model-config.entity.d.ts +24 -0
- package/dist/model/ai-model-config.entity.js +200 -0
- package/dist/service/a2a.service.d.ts +142 -0
- package/dist/service/a2a.service.js +537 -0
- package/dist/service/agent-profile.service.d.ts +34 -0
- package/dist/service/agent-profile.service.js +110 -0
- package/dist/service/agent-server.service.d.ts +91 -0
- package/dist/service/agent-server.service.js +634 -0
- package/dist/service/agent-task-queue.service.d.ts +98 -0
- package/dist/service/agent-task-queue.service.js +283 -0
- package/dist/service/ai-chat.service.d.ts +103 -0
- package/dist/service/ai-chat.service.js +431 -0
- package/dist/service/ai-skill.service.d.ts +116 -0
- package/dist/service/ai-skill.service.js +457 -0
- package/dist/service/application.service.d.ts +42 -0
- package/dist/service/application.service.js +139 -0
- package/dist/service/automation.service.d.ts +37 -0
- package/dist/service/automation.service.js +196 -0
- package/dist/service/connector.service.d.ts +136 -0
- package/dist/service/connector.service.js +524 -0
- package/dist/service/knowledge-base.service.d.ts +138 -0
- package/dist/service/knowledge-base.service.js +528 -0
- package/dist/service/mcp-server.service.d.ts +39 -0
- package/dist/service/mcp-server.service.js +143 -0
- package/dist/service/model-config.service.d.ts +57 -0
- package/dist/service/model-config.service.js +168 -0
- package/dist/service/observability.service.d.ts +145 -0
- package/dist/service/observability.service.js +281 -0
- package/dist/service/openai.service.d.ts +88 -0
- package/dist/service/openai.service.js +406 -0
- package/dist/service/prompt-builder.service.d.ts +50 -0
- package/dist/service/prompt-builder.service.js +246 -0
- package/dist/tools/code-exec.tool.d.ts +37 -0
- package/dist/tools/code-exec.tool.js +162 -0
- package/dist/tools/datetime.tool.d.ts +21 -0
- package/dist/tools/datetime.tool.js +379 -0
- package/dist/tools/http-request.tool.d.ts +43 -0
- package/dist/tools/http-request.tool.js +455 -0
- package/dist/tools/registry.d.ts +71 -0
- package/dist/tools/registry.js +77 -0
- package/dist/tools/text-process.tool.d.ts +7 -0
- package/dist/tools/text-process.tool.js +366 -0
- package/dist/tools/web-search.tool.d.ts +28 -0
- package/dist/tools/web-search.tool.js +304 -0
- package/dist/types.d.ts +70 -0
- package/dist/types.js +7 -0
- package/package.json +69 -0
|
@@ -0,0 +1,193 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.DatabaseAdapter = void 0;
|
|
37
|
+
class DatabaseAdapter {
|
|
38
|
+
constructor() {
|
|
39
|
+
this.type = 'database';
|
|
40
|
+
}
|
|
41
|
+
async testConnection(config) {
|
|
42
|
+
try {
|
|
43
|
+
const tables = await this.listTables(config);
|
|
44
|
+
return {
|
|
45
|
+
success: true,
|
|
46
|
+
message: `连接成功,发现 ${tables.length} 张表`,
|
|
47
|
+
resources: tables,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
return {
|
|
52
|
+
success: false,
|
|
53
|
+
message: '连接失败',
|
|
54
|
+
error: err.message,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async discoverTools(config) {
|
|
59
|
+
const tables = await this.listTables(config);
|
|
60
|
+
const tools = [];
|
|
61
|
+
for (const table of tables) {
|
|
62
|
+
tools.push({
|
|
63
|
+
name: `db_${table}_query`,
|
|
64
|
+
description: `查询 ${table} 表数据,支持 WHERE 条件、LIMIT 限制`,
|
|
65
|
+
inputSchema: {
|
|
66
|
+
type: 'object',
|
|
67
|
+
properties: {
|
|
68
|
+
where: {
|
|
69
|
+
type: 'string',
|
|
70
|
+
description: 'WHERE 条件(不含 WHERE 关键字)',
|
|
71
|
+
},
|
|
72
|
+
limit: {
|
|
73
|
+
type: 'number',
|
|
74
|
+
description: '返回行数限制',
|
|
75
|
+
default: 100,
|
|
76
|
+
},
|
|
77
|
+
offset: {
|
|
78
|
+
type: 'number',
|
|
79
|
+
description: '偏移量',
|
|
80
|
+
default: 0,
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
tools.push({
|
|
86
|
+
name: `db_${table}_describe`,
|
|
87
|
+
description: `获取 ${table} 表结构信息(列名、类型等)`,
|
|
88
|
+
inputSchema: {
|
|
89
|
+
type: 'object',
|
|
90
|
+
properties: {},
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return tools;
|
|
95
|
+
}
|
|
96
|
+
async generateManifest(config) {
|
|
97
|
+
const tools = await this.discoverTools(config);
|
|
98
|
+
return {
|
|
99
|
+
tools,
|
|
100
|
+
metadata: {
|
|
101
|
+
dbType: config.dbType,
|
|
102
|
+
database: config.database,
|
|
103
|
+
host: config.host,
|
|
104
|
+
tableCount: tools.length / 2,
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
async generateMCPServerConfigs(config) {
|
|
109
|
+
const tools = await this.discoverTools(config);
|
|
110
|
+
return [
|
|
111
|
+
{
|
|
112
|
+
name: `db-${config.name || config.database}`,
|
|
113
|
+
transport: 'stdio',
|
|
114
|
+
command: 'node',
|
|
115
|
+
args: ['-e', `/* MCP server for ${config.database} */`],
|
|
116
|
+
env: {
|
|
117
|
+
DB_TYPE: config.dbType || 'mysql',
|
|
118
|
+
DB_HOST: config.host || '',
|
|
119
|
+
DB_PORT: String(config.port || 3306),
|
|
120
|
+
DB_NAME: config.database || '',
|
|
121
|
+
DB_USER: config.username || '',
|
|
122
|
+
DB_PASS: config.password || '',
|
|
123
|
+
},
|
|
124
|
+
tools,
|
|
125
|
+
},
|
|
126
|
+
];
|
|
127
|
+
}
|
|
128
|
+
/** 列出所有表 */
|
|
129
|
+
async listTables(config) {
|
|
130
|
+
if (config.dbType === 'mongodb') {
|
|
131
|
+
return this.listMongoCollections(config);
|
|
132
|
+
}
|
|
133
|
+
return this.listSQLTables(config);
|
|
134
|
+
}
|
|
135
|
+
/** 列出 SQL 表(MySQL / PostgreSQL) */
|
|
136
|
+
async listSQLTables(config) {
|
|
137
|
+
const { DataSource } = await Promise.resolve().then(() => __importStar(require('typeorm')));
|
|
138
|
+
const dbType = config.dbType === 'postgres' ? 'postgres' : 'mysql';
|
|
139
|
+
const ds = new DataSource({
|
|
140
|
+
type: dbType,
|
|
141
|
+
host: config.host,
|
|
142
|
+
port: config.port,
|
|
143
|
+
username: config.username,
|
|
144
|
+
password: config.password,
|
|
145
|
+
database: config.database,
|
|
146
|
+
extra: config.extraOptions,
|
|
147
|
+
synchronize: false,
|
|
148
|
+
entities: [],
|
|
149
|
+
});
|
|
150
|
+
try {
|
|
151
|
+
await ds.initialize();
|
|
152
|
+
const query = dbType === 'postgres'
|
|
153
|
+
? "SELECT tablename FROM pg_tables WHERE schemaname = 'public'"
|
|
154
|
+
: 'SHOW TABLES';
|
|
155
|
+
const result = await ds.query(query);
|
|
156
|
+
return result.map((row) => dbType === 'postgres' ? row.tablename : Object.values(row)[0]);
|
|
157
|
+
}
|
|
158
|
+
finally {
|
|
159
|
+
if (ds.isInitialized) {
|
|
160
|
+
await ds.destroy();
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/** 列出 MongoDB 集合 */
|
|
165
|
+
async listMongoCollections(config) {
|
|
166
|
+
let MongoClient;
|
|
167
|
+
try {
|
|
168
|
+
MongoClient = require('mongodb').MongoClient;
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
throw new Error('mongodb 包未安装,请运行 npm install mongodb');
|
|
172
|
+
}
|
|
173
|
+
const url = `mongodb://${config.host}:${config.port || 27017}`;
|
|
174
|
+
const client = new MongoClient(url, {
|
|
175
|
+
auth: config.username && config.password
|
|
176
|
+
? {
|
|
177
|
+
username: config.username,
|
|
178
|
+
password: config.password,
|
|
179
|
+
}
|
|
180
|
+
: undefined,
|
|
181
|
+
});
|
|
182
|
+
try {
|
|
183
|
+
await client.connect();
|
|
184
|
+
const db = client.db(config.database);
|
|
185
|
+
const collections = await db.listCollections().toArray();
|
|
186
|
+
return collections.map((c) => c.name);
|
|
187
|
+
}
|
|
188
|
+
finally {
|
|
189
|
+
await client.close();
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
exports.DatabaseAdapter = DatabaseAdapter;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 邮箱适配器
|
|
3
|
+
*
|
|
4
|
+
* 支持 IMAP(收信)+ SMTP(发信),使用动态 require 加载 imapflow。
|
|
5
|
+
* testConnection 测试 IMAP/SMTP 连接,discoverTools 生成邮件相关工具。
|
|
6
|
+
*/
|
|
7
|
+
import type { DataSourceConfig, DiscoveredTool, ConnectionTestResult, DataSourceAdapter, MCPServerConfig } from './types';
|
|
8
|
+
export declare class EmailAdapter implements DataSourceAdapter {
|
|
9
|
+
readonly type: "email";
|
|
10
|
+
testConnection(config: DataSourceConfig): Promise<ConnectionTestResult>;
|
|
11
|
+
discoverTools(config: DataSourceConfig): Promise<DiscoveredTool[]>;
|
|
12
|
+
generateManifest(config: DataSourceConfig): Promise<{
|
|
13
|
+
tools: DiscoveredTool[];
|
|
14
|
+
metadata: {
|
|
15
|
+
emailAddress: string;
|
|
16
|
+
imapHost: string;
|
|
17
|
+
smtpHost: string;
|
|
18
|
+
};
|
|
19
|
+
}>;
|
|
20
|
+
generateMCPServerConfigs(config: DataSourceConfig): Promise<MCPServerConfig[]>;
|
|
21
|
+
/** 动态加载 imapflow */
|
|
22
|
+
private loadImapFlow;
|
|
23
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EmailAdapter = void 0;
|
|
4
|
+
class EmailAdapter {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.type = 'email';
|
|
7
|
+
}
|
|
8
|
+
async testConnection(config) {
|
|
9
|
+
try {
|
|
10
|
+
const ImapFlow = await this.loadImapFlow();
|
|
11
|
+
const client = new ImapFlow({
|
|
12
|
+
host: config.imapHost,
|
|
13
|
+
port: config.imapPort || 993,
|
|
14
|
+
secure: config.useTLS !== false,
|
|
15
|
+
auth: {
|
|
16
|
+
user: config.emailAddress,
|
|
17
|
+
pass: config.password,
|
|
18
|
+
},
|
|
19
|
+
logger: false,
|
|
20
|
+
});
|
|
21
|
+
try {
|
|
22
|
+
await client.connect();
|
|
23
|
+
const lock = await client.getMailboxLock('INBOX');
|
|
24
|
+
try {
|
|
25
|
+
const count = await client.status('INBOX', {
|
|
26
|
+
messages: true,
|
|
27
|
+
});
|
|
28
|
+
return {
|
|
29
|
+
success: true,
|
|
30
|
+
message: `IMAP 连接成功,收件箱有 ${count.messages || 0} 封邮件`,
|
|
31
|
+
resources: ['INBOX'],
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
lock.release();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
await client.logout().catch(() => { });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
return {
|
|
44
|
+
success: false,
|
|
45
|
+
message: '邮箱连接失败',
|
|
46
|
+
error: err.message,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async discoverTools(config) {
|
|
51
|
+
return [
|
|
52
|
+
{
|
|
53
|
+
name: 'email_list',
|
|
54
|
+
description: `列出邮箱 ${config.emailAddress} 的邮件`,
|
|
55
|
+
inputSchema: {
|
|
56
|
+
type: 'object',
|
|
57
|
+
properties: {
|
|
58
|
+
mailbox: {
|
|
59
|
+
type: 'string',
|
|
60
|
+
description: '邮箱文件夹',
|
|
61
|
+
default: 'INBOX',
|
|
62
|
+
},
|
|
63
|
+
limit: {
|
|
64
|
+
type: 'number',
|
|
65
|
+
description: '返回邮件数',
|
|
66
|
+
default: 20,
|
|
67
|
+
},
|
|
68
|
+
search: {
|
|
69
|
+
type: 'object',
|
|
70
|
+
description: '搜索条件(from, subject, since 等)',
|
|
71
|
+
properties: {
|
|
72
|
+
from: { type: 'string' },
|
|
73
|
+
subject: { type: 'string' },
|
|
74
|
+
since: { type: 'string' },
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: 'email_read',
|
|
82
|
+
description: '读取指定邮件内容',
|
|
83
|
+
inputSchema: {
|
|
84
|
+
type: 'object',
|
|
85
|
+
properties: {
|
|
86
|
+
uid: {
|
|
87
|
+
type: 'number',
|
|
88
|
+
description: '邮件 UID',
|
|
89
|
+
},
|
|
90
|
+
mailbox: {
|
|
91
|
+
type: 'string',
|
|
92
|
+
default: 'INBOX',
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
required: ['uid'],
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
name: 'email_send',
|
|
100
|
+
description: `通过 SMTP 发送邮件(发件人: ${config.emailAddress})`,
|
|
101
|
+
inputSchema: {
|
|
102
|
+
type: 'object',
|
|
103
|
+
properties: {
|
|
104
|
+
to: {
|
|
105
|
+
type: 'string',
|
|
106
|
+
description: '收件人地址(多个用逗号分隔)',
|
|
107
|
+
},
|
|
108
|
+
subject: {
|
|
109
|
+
type: 'string',
|
|
110
|
+
description: '邮件主题',
|
|
111
|
+
},
|
|
112
|
+
body: {
|
|
113
|
+
type: 'string',
|
|
114
|
+
description: '邮件正文',
|
|
115
|
+
},
|
|
116
|
+
html: {
|
|
117
|
+
type: 'boolean',
|
|
118
|
+
description: '是否为 HTML 格式',
|
|
119
|
+
default: false,
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
required: ['to', 'subject', 'body'],
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
name: 'email_search',
|
|
127
|
+
description: '搜索邮件',
|
|
128
|
+
inputSchema: {
|
|
129
|
+
type: 'object',
|
|
130
|
+
properties: {
|
|
131
|
+
query: {
|
|
132
|
+
type: 'string',
|
|
133
|
+
description: '搜索关键词',
|
|
134
|
+
},
|
|
135
|
+
mailbox: {
|
|
136
|
+
type: 'string',
|
|
137
|
+
default: 'INBOX',
|
|
138
|
+
},
|
|
139
|
+
limit: {
|
|
140
|
+
type: 'number',
|
|
141
|
+
default: 20,
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
required: ['query'],
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
];
|
|
148
|
+
}
|
|
149
|
+
async generateManifest(config) {
|
|
150
|
+
const tools = await this.discoverTools(config);
|
|
151
|
+
return {
|
|
152
|
+
tools,
|
|
153
|
+
metadata: {
|
|
154
|
+
emailAddress: config.emailAddress,
|
|
155
|
+
imapHost: config.imapHost,
|
|
156
|
+
smtpHost: config.smtpHost,
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
async generateMCPServerConfigs(config) {
|
|
161
|
+
const tools = await this.discoverTools(config);
|
|
162
|
+
return [
|
|
163
|
+
{
|
|
164
|
+
name: `email-${config.emailAddress || 'default'}`,
|
|
165
|
+
transport: 'stdio',
|
|
166
|
+
command: 'node',
|
|
167
|
+
args: ['-e', '/* MCP server for email */'],
|
|
168
|
+
env: {
|
|
169
|
+
IMAP_HOST: config.imapHost || '',
|
|
170
|
+
IMAP_PORT: String(config.imapPort || 993),
|
|
171
|
+
SMTP_HOST: config.smtpHost || '',
|
|
172
|
+
SMTP_PORT: String(config.smtpPort || 465),
|
|
173
|
+
EMAIL_ADDRESS: config.emailAddress || '',
|
|
174
|
+
EMAIL_PASSWORD: config.password || '',
|
|
175
|
+
USE_TLS: String(config.useTLS ?? true),
|
|
176
|
+
},
|
|
177
|
+
tools,
|
|
178
|
+
},
|
|
179
|
+
];
|
|
180
|
+
}
|
|
181
|
+
/** 动态加载 imapflow */
|
|
182
|
+
async loadImapFlow() {
|
|
183
|
+
try {
|
|
184
|
+
const mod = require('imapflow');
|
|
185
|
+
return mod.ImapFlow || mod.default || mod;
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
throw new Error('imapflow 包未安装,请运行 npm install imapflow');
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
exports.EmailAdapter = EmailAdapter;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DataSourceConfig, DiscoveredTool, ConnectionTestResult, DataSourceAdapter, MCPServerConfig } from './types';
|
|
2
|
+
export declare class FileSystemAdapter implements DataSourceAdapter {
|
|
3
|
+
readonly type: "filesystem";
|
|
4
|
+
testConnection(config: DataSourceConfig): Promise<ConnectionTestResult>;
|
|
5
|
+
discoverTools(config: DataSourceConfig): Promise<DiscoveredTool[]>;
|
|
6
|
+
generateManifest(config: DataSourceConfig): Promise<{
|
|
7
|
+
tools: DiscoveredTool[];
|
|
8
|
+
metadata: {
|
|
9
|
+
rootPath: string;
|
|
10
|
+
readOnly: boolean;
|
|
11
|
+
allowedExtensions: string[];
|
|
12
|
+
};
|
|
13
|
+
}>;
|
|
14
|
+
generateMCPServerConfigs(config: DataSourceConfig): Promise<MCPServerConfig[]>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.FileSystemAdapter = void 0;
|
|
37
|
+
/**
|
|
38
|
+
* 文件系统适配器
|
|
39
|
+
*
|
|
40
|
+
* 生成 list_directory / read_file / search_files / file_info / write_file 工具。
|
|
41
|
+
* testConnection 检查根目录是否可访问。
|
|
42
|
+
*/
|
|
43
|
+
const fs = __importStar(require("fs/promises"));
|
|
44
|
+
class FileSystemAdapter {
|
|
45
|
+
constructor() {
|
|
46
|
+
this.type = 'filesystem';
|
|
47
|
+
}
|
|
48
|
+
async testConnection(config) {
|
|
49
|
+
const rootPath = config.rootPath;
|
|
50
|
+
if (!rootPath) {
|
|
51
|
+
return {
|
|
52
|
+
success: false,
|
|
53
|
+
message: '未配置根目录路径',
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
const stat = await fs.stat(rootPath);
|
|
58
|
+
if (!stat.isDirectory()) {
|
|
59
|
+
return {
|
|
60
|
+
success: false,
|
|
61
|
+
message: `${rootPath} 不是目录`,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const entries = await fs.readdir(rootPath);
|
|
65
|
+
return {
|
|
66
|
+
success: true,
|
|
67
|
+
message: `连接成功,根目录包含 ${entries.length} 个条目`,
|
|
68
|
+
resources: entries.slice(0, 50),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
return {
|
|
73
|
+
success: false,
|
|
74
|
+
message: '无法访问根目录',
|
|
75
|
+
error: err.message,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async discoverTools(config) {
|
|
80
|
+
const readOnly = config.readOnly !== false;
|
|
81
|
+
const tools = [
|
|
82
|
+
{
|
|
83
|
+
name: 'list_directory',
|
|
84
|
+
description: `列出指定目录下的文件和子目录(根目录: ${config.rootPath})`,
|
|
85
|
+
inputSchema: {
|
|
86
|
+
type: 'object',
|
|
87
|
+
properties: {
|
|
88
|
+
dirPath: {
|
|
89
|
+
type: 'string',
|
|
90
|
+
description: '相对于根目录的路径,默认为根目录',
|
|
91
|
+
default: '.',
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: 'read_file',
|
|
98
|
+
description: '读取文件内容',
|
|
99
|
+
inputSchema: {
|
|
100
|
+
type: 'object',
|
|
101
|
+
properties: {
|
|
102
|
+
filePath: {
|
|
103
|
+
type: 'string',
|
|
104
|
+
description: '相对于根目录的文件路径',
|
|
105
|
+
},
|
|
106
|
+
encoding: {
|
|
107
|
+
type: 'string',
|
|
108
|
+
description: '文件编码',
|
|
109
|
+
default: 'utf-8',
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
required: ['filePath'],
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
name: 'search_files',
|
|
117
|
+
description: '按名称模式搜索文件',
|
|
118
|
+
inputSchema: {
|
|
119
|
+
type: 'object',
|
|
120
|
+
properties: {
|
|
121
|
+
pattern: {
|
|
122
|
+
type: 'string',
|
|
123
|
+
description: '文件名匹配模式(支持 * 通配符)',
|
|
124
|
+
},
|
|
125
|
+
dirPath: {
|
|
126
|
+
type: 'string',
|
|
127
|
+
description: '搜索起始目录(相对于根目录)',
|
|
128
|
+
default: '.',
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
required: ['pattern'],
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: 'file_info',
|
|
136
|
+
description: '获取文件或目录的元信息',
|
|
137
|
+
inputSchema: {
|
|
138
|
+
type: 'object',
|
|
139
|
+
properties: {
|
|
140
|
+
filePath: {
|
|
141
|
+
type: 'string',
|
|
142
|
+
description: '相对于根目录的路径',
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
required: ['filePath'],
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
];
|
|
149
|
+
if (!readOnly) {
|
|
150
|
+
tools.push({
|
|
151
|
+
name: 'write_file',
|
|
152
|
+
description: '写入内容到文件',
|
|
153
|
+
inputSchema: {
|
|
154
|
+
type: 'object',
|
|
155
|
+
properties: {
|
|
156
|
+
filePath: {
|
|
157
|
+
type: 'string',
|
|
158
|
+
description: '相对于根目录的文件路径',
|
|
159
|
+
},
|
|
160
|
+
content: {
|
|
161
|
+
type: 'string',
|
|
162
|
+
description: '文件内容',
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
required: ['filePath', 'content'],
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
return tools;
|
|
170
|
+
}
|
|
171
|
+
async generateManifest(config) {
|
|
172
|
+
const tools = await this.discoverTools(config);
|
|
173
|
+
return {
|
|
174
|
+
tools,
|
|
175
|
+
metadata: {
|
|
176
|
+
rootPath: config.rootPath,
|
|
177
|
+
readOnly: config.readOnly,
|
|
178
|
+
allowedExtensions: config.allowedExtensions,
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
async generateMCPServerConfigs(config) {
|
|
183
|
+
const tools = await this.discoverTools(config);
|
|
184
|
+
return [
|
|
185
|
+
{
|
|
186
|
+
name: `fs-${config.name || 'default'}`,
|
|
187
|
+
transport: 'stdio',
|
|
188
|
+
command: 'node',
|
|
189
|
+
args: ['-e', '/* MCP server for filesystem */'],
|
|
190
|
+
env: {
|
|
191
|
+
FS_ROOT: config.rootPath || '',
|
|
192
|
+
FS_READ_ONLY: String(config.readOnly ?? true),
|
|
193
|
+
},
|
|
194
|
+
tools,
|
|
195
|
+
},
|
|
196
|
+
];
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
exports.FileSystemAdapter = FileSystemAdapter;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP API 适配器
|
|
3
|
+
*
|
|
4
|
+
* 支持 manual(手动定义端点)和 openapi(从 OpenAPI spec 解析)两种模式。
|
|
5
|
+
* testConnection 尝试请求 baseUrl,discoverTools 将端点转为工具定义。
|
|
6
|
+
*/
|
|
7
|
+
import type { DataSourceConfig, DiscoveredTool, ConnectionTestResult, DataSourceAdapter, MCPServerConfig } from './types';
|
|
8
|
+
export declare class HTTPAPIAdapter implements DataSourceAdapter {
|
|
9
|
+
readonly type: "http-api";
|
|
10
|
+
testConnection(config: DataSourceConfig): Promise<ConnectionTestResult>;
|
|
11
|
+
discoverTools(config: DataSourceConfig): Promise<DiscoveredTool[]>;
|
|
12
|
+
generateManifest(config: DataSourceConfig): Promise<{
|
|
13
|
+
tools: DiscoveredTool[];
|
|
14
|
+
metadata: {
|
|
15
|
+
apiMode: "manual" | "openapi";
|
|
16
|
+
serviceCount: number;
|
|
17
|
+
endpointCount: number;
|
|
18
|
+
};
|
|
19
|
+
}>;
|
|
20
|
+
generateMCPServerConfigs(config: DataSourceConfig): Promise<MCPServerConfig[]>;
|
|
21
|
+
/** 收集所有端点 */
|
|
22
|
+
private collectEndpoints;
|
|
23
|
+
/** 解析 OpenAPI spec */
|
|
24
|
+
private parseOpenAPI;
|
|
25
|
+
/** 构建请求头 */
|
|
26
|
+
private buildHeaders;
|
|
27
|
+
/** 将端点名转为合法工具名 */
|
|
28
|
+
private sanitizeToolName;
|
|
29
|
+
}
|