@ty_krystal/sei-ai 0.1.5 → 0.1.6
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 +701 -175
- package/bin/dev.cmd +3 -0
- package/bin/dev.js +5 -0
- package/bin/run.cmd +3 -0
- package/bin/run.js +5 -0
- package/dist/commands/api-docs.d.ts +20 -0
- package/dist/commands/api-docs.js +4 -5
- package/dist/commands/call.d.ts +27 -0
- package/dist/commands/call.js +12 -13
- package/dist/commands/dict/add-category.d.ts +31 -0
- package/dist/commands/dict/add-category.js +9 -10
- package/dist/commands/dict/add-item.d.ts +32 -0
- package/dist/commands/dict/add-item.js +11 -12
- package/dist/commands/dict/list.d.ts +22 -0
- package/dist/commands/dict/list.js +8 -9
- package/dist/commands/init/base-data.d.ts +26 -0
- package/dist/commands/init/base-data.js +14 -15
- package/dist/commands/query-sql.d.ts +24 -0
- package/dist/commands/query-sql.js +6 -8
- package/dist/commands/query.d.ts +21 -0
- package/dist/commands/query.js +6 -7
- package/dist/commands/relogin.d.ts +17 -0
- package/dist/commands/relogin.js +2 -3
- package/dist/commands/save.d.ts +21 -0
- package/dist/commands/save.js +6 -7
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -2
- package/oclif.manifest.json +1302 -0
- package/package.json +63 -54
- package/config.example.json +0 -33
- package/dist/README.md +0 -239
- package/dist/cli-actions.js +0 -157
- package/dist/cli-helpers.js +0 -246
- package/dist/command-base/context.js +0 -10
- package/dist/command-base/output.js +0 -6
- package/dist/command-base/payload.js +0 -33
- package/dist/command-base/sei-command.js +0 -88
- package/dist/commands/stdio.js +0 -16
- package/dist/commands/streamable-http.js +0 -29
- package/dist/config.example.json +0 -33
- package/dist/config.js +0 -82
- package/dist/constants.js +0 -48
- package/dist/env.js +0 -33
- package/dist/errors.js +0 -55
- package/dist/logger.js +0 -71
- package/dist/openapi.js +0 -261
- package/dist/permissions.js +0 -209
- package/dist/schema.js +0 -112
- package/dist/sei-client.js +0 -535
- package/dist/server.js +0 -237
- package/dist/tools.js +0 -175
- package/dist/types.js +0 -1
- package/dist/utils.js +0 -53
package/dist/cli-helpers.js
DELETED
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto';
|
|
2
|
-
import { BASE_SEED_DEFAULT_ADMIN_PASSWORD, BASE_SEED_DEFAULT_ADMIN_ROLE, BASE_SEED_DEFAULT_ADMIN_UID, BASE_SEED_DEFAULT_SYSID, DICT_DEFAULT_SYSID, DICT_FIELDS, DICT_MODULE, } from './constants.js';
|
|
3
|
-
import { SeiMcpError } from './errors.js';
|
|
4
|
-
export function buildDictQueryPayload(typeCode, keyword, size = 1000) {
|
|
5
|
-
return {
|
|
6
|
-
head: {
|
|
7
|
-
module: DICT_MODULE,
|
|
8
|
-
},
|
|
9
|
-
option: {
|
|
10
|
-
keyField: true,
|
|
11
|
-
privilege: true,
|
|
12
|
-
fields: DICT_FIELDS.join(','),
|
|
13
|
-
filter: buildDictQueryFilter(typeCode, keyword),
|
|
14
|
-
order: '_SORT ASC,_CODE ASC',
|
|
15
|
-
page: 1,
|
|
16
|
-
size,
|
|
17
|
-
},
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
export function buildDictSavePayload(row) {
|
|
21
|
-
return {
|
|
22
|
-
head: {
|
|
23
|
-
module: DICT_MODULE,
|
|
24
|
-
},
|
|
25
|
-
data: [
|
|
26
|
-
{
|
|
27
|
-
action: 'add',
|
|
28
|
-
option: {
|
|
29
|
-
keyVal: true,
|
|
30
|
-
},
|
|
31
|
-
rows: [
|
|
32
|
-
{
|
|
33
|
-
row,
|
|
34
|
-
},
|
|
35
|
-
],
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
export function buildDictCategoryRow(input) {
|
|
41
|
-
const typeCode = requiredText(input.typeCode, '字典类别');
|
|
42
|
-
const name = requiredText(input.name, '字典名称');
|
|
43
|
-
const uuid = requiredText(input.uuid || typeCode, '字典编号');
|
|
44
|
-
const code = requiredText(input.code || typeCode, '字典代码');
|
|
45
|
-
return {
|
|
46
|
-
_UUID: uuid,
|
|
47
|
-
_PID: '',
|
|
48
|
-
_SYSID: requiredText(input.sysid || DICT_DEFAULT_SYSID, '所属系统'),
|
|
49
|
-
_TYPE: typeCode,
|
|
50
|
-
_CTYPE: normalizeText(input.ctype),
|
|
51
|
-
_CODE: code,
|
|
52
|
-
_NAME: name,
|
|
53
|
-
_ENAME: normalizeText(input.ename),
|
|
54
|
-
_DICT: normalizeDictFlag(input.dictFlag),
|
|
55
|
-
_SORT: normalizeSort(input.sort),
|
|
56
|
-
_BODY: normalizeText(input.body),
|
|
57
|
-
_MEMO: normalizeText(input.memo),
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
export function buildDictItemRow(input) {
|
|
61
|
-
const typeCode = requiredText(input.typeCode, '字典类别');
|
|
62
|
-
const code = requiredText(input.code, '字典代码');
|
|
63
|
-
const name = requiredText(input.name, '字典名称');
|
|
64
|
-
const parent = requiredText(input.parent || typeCode, '父级编号');
|
|
65
|
-
const uuid = requiredText(input.uuid || `${parent}_${code}`, '字典编号');
|
|
66
|
-
return {
|
|
67
|
-
_UUID: uuid,
|
|
68
|
-
_PID: parent,
|
|
69
|
-
_SYSID: requiredText(input.sysid || DICT_DEFAULT_SYSID, '所属系统'),
|
|
70
|
-
_TYPE: typeCode,
|
|
71
|
-
_CTYPE: normalizeText(input.ctype),
|
|
72
|
-
_CODE: code,
|
|
73
|
-
_NAME: name,
|
|
74
|
-
_ENAME: normalizeText(input.ename),
|
|
75
|
-
_DICT: normalizeDictFlag(input.dictFlag),
|
|
76
|
-
_SORT: normalizeSort(input.sort),
|
|
77
|
-
_BODY: normalizeText(input.body),
|
|
78
|
-
_MEMO: normalizeText(input.memo),
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
export function buildDictTree(rows) {
|
|
82
|
-
if (!Array.isArray(rows)) {
|
|
83
|
-
return [];
|
|
84
|
-
}
|
|
85
|
-
const recordMap = new Map();
|
|
86
|
-
const childrenMap = new Map();
|
|
87
|
-
const roots = [];
|
|
88
|
-
for (const row of rows) {
|
|
89
|
-
if (!isObject(row)) {
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
const key = normalizeText(row._UUID);
|
|
93
|
-
if (!key) {
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
recordMap.set(key, { ...row });
|
|
97
|
-
}
|
|
98
|
-
for (const record of recordMap.values()) {
|
|
99
|
-
const parentId = normalizeText(record._PID);
|
|
100
|
-
if (!parentId || !recordMap.has(parentId)) {
|
|
101
|
-
roots.push(record);
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
const children = childrenMap.get(parentId) ?? [];
|
|
105
|
-
children.push(record);
|
|
106
|
-
childrenMap.set(parentId, children);
|
|
107
|
-
}
|
|
108
|
-
for (const [key, record] of recordMap.entries()) {
|
|
109
|
-
const children = childrenMap.get(key);
|
|
110
|
-
if (children && children.length > 0) {
|
|
111
|
-
record.children = children.sort(dictSortKey);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return roots.sort(dictSortKey);
|
|
115
|
-
}
|
|
116
|
-
export function buildBaseSeedSqlVars(input) {
|
|
117
|
-
const adminPassword = input.adminPassword || BASE_SEED_DEFAULT_ADMIN_PASSWORD;
|
|
118
|
-
const passwordHash = createHash('md5').update(adminPassword, 'utf8').digest('hex');
|
|
119
|
-
const adminUid = input.adminUid || BASE_SEED_DEFAULT_ADMIN_UID;
|
|
120
|
-
const adminRole = input.adminRole || BASE_SEED_DEFAULT_ADMIN_ROLE;
|
|
121
|
-
const resetSql = input.resetAdminPassword === true
|
|
122
|
-
? `UPDATE _SYS_USER\nSET _PWD = ${sqlLiteral(passwordHash)}\nWHERE _UID = ${sqlLiteral(adminUid)};`
|
|
123
|
-
: '';
|
|
124
|
-
return {
|
|
125
|
-
SYSID: sqlLiteral(input.sysid || BASE_SEED_DEFAULT_SYSID),
|
|
126
|
-
ADMIN_UID: sqlLiteral(adminUid),
|
|
127
|
-
ADMIN_NAME: sqlLiteral(input.adminName || '管理员'),
|
|
128
|
-
ADMIN_ROLE: sqlLiteral(adminRole),
|
|
129
|
-
ADMIN_ROLE_NAME: sqlLiteral(input.adminRoleName || '管理员'),
|
|
130
|
-
ADMIN_PASSWORD_MD5: sqlLiteral(passwordHash),
|
|
131
|
-
RESET_ADMIN_PASSWORD_SQL: resetSql,
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
export function renderBaseSeedSql(template, values) {
|
|
135
|
-
let rendered = template;
|
|
136
|
-
for (const [key, value] of Object.entries(values)) {
|
|
137
|
-
rendered = rendered.replaceAll(`{{${key}}}`, value);
|
|
138
|
-
}
|
|
139
|
-
const missing = [...rendered.matchAll(/\{\{[A-Z0-9_]+\}\}/g)].map((item) => item[0]);
|
|
140
|
-
if (missing.length > 0) {
|
|
141
|
-
throw new SeiMcpError(`初始化 SQL 存在未替换变量:${[...new Set(missing)].join(', ')}`, 'INVALID_PARAMS');
|
|
142
|
-
}
|
|
143
|
-
return rendered;
|
|
144
|
-
}
|
|
145
|
-
export function removeSqlCommentLines(sql) {
|
|
146
|
-
return sql
|
|
147
|
-
.split('\n')
|
|
148
|
-
.filter((line) => !line.trimStart().startsWith('--'))
|
|
149
|
-
.join('\n');
|
|
150
|
-
}
|
|
151
|
-
export function splitSqlStatements(sql) {
|
|
152
|
-
const statements = [];
|
|
153
|
-
let current = '';
|
|
154
|
-
let quote = null;
|
|
155
|
-
let escaped = false;
|
|
156
|
-
for (const char of sql) {
|
|
157
|
-
if (escaped) {
|
|
158
|
-
current += char;
|
|
159
|
-
escaped = false;
|
|
160
|
-
continue;
|
|
161
|
-
}
|
|
162
|
-
if (char === '\\' && quote !== null) {
|
|
163
|
-
current += char;
|
|
164
|
-
escaped = true;
|
|
165
|
-
continue;
|
|
166
|
-
}
|
|
167
|
-
if (quote !== null) {
|
|
168
|
-
current += char;
|
|
169
|
-
if (char === quote) {
|
|
170
|
-
quote = null;
|
|
171
|
-
}
|
|
172
|
-
continue;
|
|
173
|
-
}
|
|
174
|
-
if (char === '\'' || char === '"' || char === '`') {
|
|
175
|
-
current += char;
|
|
176
|
-
quote = char;
|
|
177
|
-
continue;
|
|
178
|
-
}
|
|
179
|
-
if (char === ';') {
|
|
180
|
-
const statement = current.trim();
|
|
181
|
-
if (statement) {
|
|
182
|
-
statements.push(statement);
|
|
183
|
-
}
|
|
184
|
-
current = '';
|
|
185
|
-
continue;
|
|
186
|
-
}
|
|
187
|
-
current += char;
|
|
188
|
-
}
|
|
189
|
-
const finalStatement = current.trim();
|
|
190
|
-
if (finalStatement) {
|
|
191
|
-
statements.push(finalStatement);
|
|
192
|
-
}
|
|
193
|
-
return statements;
|
|
194
|
-
}
|
|
195
|
-
function buildDictQueryFilter(typeCode, keyword) {
|
|
196
|
-
const filters = [];
|
|
197
|
-
const normalizedType = normalizeText(typeCode);
|
|
198
|
-
const normalizedKeyword = normalizeText(keyword);
|
|
199
|
-
if (normalizedType) {
|
|
200
|
-
filters.push({ _TYPE: { '=': normalizedType } });
|
|
201
|
-
}
|
|
202
|
-
if (normalizedKeyword) {
|
|
203
|
-
filters.push({
|
|
204
|
-
OR: [
|
|
205
|
-
{ _UUID: { '*LIKE*': normalizedKeyword } },
|
|
206
|
-
{ _TYPE: { '*LIKE*': normalizedKeyword } },
|
|
207
|
-
{ _CODE: { '*LIKE*': normalizedKeyword } },
|
|
208
|
-
{ _NAME: { '*LIKE*': normalizedKeyword } },
|
|
209
|
-
],
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
return filters;
|
|
213
|
-
}
|
|
214
|
-
function dictSortKey(a, b) {
|
|
215
|
-
const sortA = normalizeSort(typeof a._SORT === 'number' ? a._SORT : Number(a._SORT ?? 0));
|
|
216
|
-
const sortB = normalizeSort(typeof b._SORT === 'number' ? b._SORT : Number(b._SORT ?? 0));
|
|
217
|
-
if (sortA !== sortB) {
|
|
218
|
-
return sortA - sortB;
|
|
219
|
-
}
|
|
220
|
-
return normalizeText(a._CODE).localeCompare(normalizeText(b._CODE), 'zh-CN');
|
|
221
|
-
}
|
|
222
|
-
function normalizeDictFlag(value) {
|
|
223
|
-
return value === 1 ? 1 : 0;
|
|
224
|
-
}
|
|
225
|
-
function normalizeSort(value) {
|
|
226
|
-
return Number.isInteger(value) && Number(value) >= 0 ? Number(value) : 100;
|
|
227
|
-
}
|
|
228
|
-
function requiredText(value, label) {
|
|
229
|
-
const normalized = normalizeText(value);
|
|
230
|
-
if (!normalized) {
|
|
231
|
-
throw new SeiMcpError(`${label} 不能为空`, 'INVALID_PARAMS');
|
|
232
|
-
}
|
|
233
|
-
return normalized;
|
|
234
|
-
}
|
|
235
|
-
function normalizeText(value) {
|
|
236
|
-
return typeof value === 'string' ? value.trim() : '';
|
|
237
|
-
}
|
|
238
|
-
function sqlLiteral(value) {
|
|
239
|
-
if (value === null || value === undefined) {
|
|
240
|
-
return 'NULL';
|
|
241
|
-
}
|
|
242
|
-
return `'${String(value).replace(/'/g, "''")}'`;
|
|
243
|
-
}
|
|
244
|
-
function isObject(value) {
|
|
245
|
-
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
246
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { loadConfig } from '../config.js';
|
|
2
|
-
import { DEFAULT_LOG_LEVEL } from '../constants.js';
|
|
3
|
-
import { loadWorkingDirEnv } from '../env.js';
|
|
4
|
-
import { createLogger } from '../logger.js';
|
|
5
|
-
export async function loadCliContext(argv = process.argv.slice(2), env = process.env) {
|
|
6
|
-
await loadWorkingDirEnv();
|
|
7
|
-
const logger = createLogger(env.SEI_MCP_LOG_LEVEL ?? DEFAULT_LOG_LEVEL);
|
|
8
|
-
const config = await loadConfig(argv, env);
|
|
9
|
-
return { config, logger };
|
|
10
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { readFile } from 'node:fs/promises';
|
|
2
|
-
import { SeiMcpError } from '../errors.js';
|
|
3
|
-
export async function loadPayload(options) {
|
|
4
|
-
const sources = [options.stdin, options.jsonText !== undefined, options.filePath !== undefined].filter(Boolean).length;
|
|
5
|
-
if (sources > 1) {
|
|
6
|
-
throw new SeiMcpError('只能选择一种载荷来源:--json、--file 或 --stdin', 'INVALID_PARAMS');
|
|
7
|
-
}
|
|
8
|
-
if (options.jsonText !== undefined) {
|
|
9
|
-
return parseJson(options.jsonText);
|
|
10
|
-
}
|
|
11
|
-
if (options.filePath !== undefined) {
|
|
12
|
-
return parseJson(await readFile(options.filePath, 'utf8'));
|
|
13
|
-
}
|
|
14
|
-
if (options.stdin) {
|
|
15
|
-
return parseJson(await readStdin());
|
|
16
|
-
}
|
|
17
|
-
return options.fallback;
|
|
18
|
-
}
|
|
19
|
-
export function parseJson(text) {
|
|
20
|
-
try {
|
|
21
|
-
return JSON.parse(text);
|
|
22
|
-
}
|
|
23
|
-
catch (error) {
|
|
24
|
-
throw new SeiMcpError(`载荷不是合法 JSON:${error instanceof Error ? error.message : String(error)}`, 'INVALID_PARAMS');
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
async function readStdin() {
|
|
28
|
-
const chunks = [];
|
|
29
|
-
for await (const chunk of process.stdin) {
|
|
30
|
-
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
31
|
-
}
|
|
32
|
-
return Buffer.concat(chunks).toString('utf8');
|
|
33
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { Command, Flags } from '@oclif/core';
|
|
2
|
-
import { loadConfig } from '../config.js';
|
|
3
|
-
import { DEFAULT_LOG_LEVEL } from '../constants.js';
|
|
4
|
-
import { formatCliError, toErrorLogMeta } from '../errors.js';
|
|
5
|
-
import { loadWorkingDirEnv } from '../env.js';
|
|
6
|
-
import { createLogger } from '../logger.js';
|
|
7
|
-
import { createCliSeiClient, createSeiAuthSettings } from '../sei-client.js';
|
|
8
|
-
import { loadPayload } from './payload.js';
|
|
9
|
-
import { printJson, writeText } from './output.js';
|
|
10
|
-
export class SeiCommand extends Command {
|
|
11
|
-
static baseFlags = {
|
|
12
|
-
config: Flags.string({ description: '配置文件路径' }),
|
|
13
|
-
'base-url': Flags.string({ description: 'SEI 基础地址' }),
|
|
14
|
-
'ai-key': Flags.string({ description: 'AI 登录密钥' }),
|
|
15
|
-
role: Flags.string({ aliases: ['profile'], description: 'AI 登录角色' }),
|
|
16
|
-
account: Flags.string({ description: 'AI 登录账号' }),
|
|
17
|
-
'account-project': Flags.string({ description: 'AI 登录项目' }),
|
|
18
|
-
'account-checkcode': Flags.string({ description: 'AI 登录验证码' }),
|
|
19
|
-
token: Flags.string({ description: '固定 token' }),
|
|
20
|
-
timeout: Flags.integer({ description: '请求超时(毫秒)' }),
|
|
21
|
-
};
|
|
22
|
-
logger;
|
|
23
|
-
configData;
|
|
24
|
-
async init() {
|
|
25
|
-
await loadWorkingDirEnv();
|
|
26
|
-
this.logger = createLogger(process.env.SEI_MCP_LOG_LEVEL ?? DEFAULT_LOG_LEVEL);
|
|
27
|
-
this.configData = await loadConfig(this.argv, process.env);
|
|
28
|
-
await super.init();
|
|
29
|
-
}
|
|
30
|
-
async resolveConfig() {
|
|
31
|
-
return this.configData;
|
|
32
|
-
}
|
|
33
|
-
async createCliClient(options = {}) {
|
|
34
|
-
const config = await this.resolveConfig();
|
|
35
|
-
const settings = createSeiAuthSettings(config, {
|
|
36
|
-
baseUrl: options.baseUrl,
|
|
37
|
-
token: options.token,
|
|
38
|
-
aiKey: options.aiKey,
|
|
39
|
-
role: options.role,
|
|
40
|
-
account: options.account,
|
|
41
|
-
accountProject: options.accountProject,
|
|
42
|
-
accountCheckcode: options.accountCheckcode,
|
|
43
|
-
timeoutMs: options.timeoutMs,
|
|
44
|
-
});
|
|
45
|
-
return createCliSeiClient(settings, this.logger, globalThis.fetch);
|
|
46
|
-
}
|
|
47
|
-
async loadPayload(input) {
|
|
48
|
-
return loadPayload(input);
|
|
49
|
-
}
|
|
50
|
-
printJson(value) {
|
|
51
|
-
printJson(value);
|
|
52
|
-
}
|
|
53
|
-
writeText(text) {
|
|
54
|
-
writeText(text);
|
|
55
|
-
}
|
|
56
|
-
createAuthOptions(flags) {
|
|
57
|
-
return {
|
|
58
|
-
baseUrl: stringFlag(flags, 'base-url'),
|
|
59
|
-
token: stringFlag(flags, 'token'),
|
|
60
|
-
aiKey: stringFlag(flags, 'ai-key'),
|
|
61
|
-
role: stringFlag(flags, 'role') ?? stringFlag(flags, 'profile'),
|
|
62
|
-
account: stringFlag(flags, 'account'),
|
|
63
|
-
accountProject: stringFlag(flags, 'account-project'),
|
|
64
|
-
accountCheckcode: stringFlag(flags, 'account-checkcode'),
|
|
65
|
-
timeoutMs: numberFlag(flags, 'timeout'),
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
async createClientFromFlags(flags) {
|
|
69
|
-
return this.createCliClient(this.createAuthOptions(flags));
|
|
70
|
-
}
|
|
71
|
-
async catch(error) {
|
|
72
|
-
this.logger?.error('CLI command failed', {
|
|
73
|
-
argv: this.argv,
|
|
74
|
-
error: toErrorLogMeta(error),
|
|
75
|
-
});
|
|
76
|
-
process.stderr.write(`${formatCliError(error)}\n`);
|
|
77
|
-
process.exitCode = 1;
|
|
78
|
-
return undefined;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
function stringFlag(flags, name) {
|
|
82
|
-
const value = flags[name];
|
|
83
|
-
return typeof value === 'string' && value.trim() ? value.trim() : undefined;
|
|
84
|
-
}
|
|
85
|
-
function numberFlag(flags, name) {
|
|
86
|
-
const value = flags[name];
|
|
87
|
-
return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
|
|
88
|
-
}
|
package/dist/commands/stdio.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { SeiCommand } from '../command-base/sei-command.js';
|
|
2
|
-
import { createMcpServer, startStdioServer } from '../server.js';
|
|
3
|
-
import { createSeiClient } from '../sei-client.js';
|
|
4
|
-
export default class StdioCommand extends SeiCommand {
|
|
5
|
-
static summary = 'Start MCP server over stdio';
|
|
6
|
-
static description = 'Starts the SEI MCP server using stdio transport.';
|
|
7
|
-
static flags = {
|
|
8
|
-
...SeiCommand.baseFlags,
|
|
9
|
-
};
|
|
10
|
-
async run() {
|
|
11
|
-
const config = await this.resolveConfig();
|
|
12
|
-
const client = createSeiClient(config, this.logger);
|
|
13
|
-
const server = createMcpServer({ config, client, logger: this.logger });
|
|
14
|
-
await startStdioServer(server);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Flags } from '@oclif/core';
|
|
2
|
-
import { SeiCommand } from '../command-base/sei-command.js';
|
|
3
|
-
import { createMcpServer, startHttpServer } from '../server.js';
|
|
4
|
-
import { createSeiClient } from '../sei-client.js';
|
|
5
|
-
export default class StreamableHttpCommand extends SeiCommand {
|
|
6
|
-
static summary = 'Start MCP server over streamable HTTP';
|
|
7
|
-
static description = 'Starts the SEI MCP server using the streamable HTTP transport.';
|
|
8
|
-
static flags = {
|
|
9
|
-
...SeiCommand.baseFlags,
|
|
10
|
-
host: Flags.string({ default: '127.0.0.1', description: 'HTTP bind host' }),
|
|
11
|
-
port: Flags.integer({ default: 3000, description: 'HTTP bind port' }),
|
|
12
|
-
path: Flags.string({ default: '/mcp', description: 'HTTP endpoint path' }),
|
|
13
|
-
'http-json-response': Flags.boolean({ default: false, description: 'Enable JSON response mode' }),
|
|
14
|
-
};
|
|
15
|
-
async run() {
|
|
16
|
-
const { flags } = await this.parse(StreamableHttpCommand);
|
|
17
|
-
const config = await this.resolveConfig();
|
|
18
|
-
const client = createSeiClient(config, this.logger);
|
|
19
|
-
await startHttpServer(() => createMcpServer({ config, client, logger: this.logger }), {
|
|
20
|
-
command: 'serve',
|
|
21
|
-
transport: 'streamable-http',
|
|
22
|
-
host: flags.host,
|
|
23
|
-
port: flags.port,
|
|
24
|
-
path: flags.path,
|
|
25
|
-
enableJsonResponse: flags['http-json-response'],
|
|
26
|
-
cliArgs: [],
|
|
27
|
-
}, this.logger);
|
|
28
|
-
}
|
|
29
|
-
}
|
package/dist/config.example.json
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"baseUrl": "http://127.0.0.1:8081",
|
|
3
|
-
"auth": {
|
|
4
|
-
"mode": "ai-login",
|
|
5
|
-
"aiKeyEnv": "SEI_AI_LOGIN_KEY",
|
|
6
|
-
"roleEnv": "SEI_AI_LOGIN_ROLE"
|
|
7
|
-
},
|
|
8
|
-
"tools": {
|
|
9
|
-
"query": true,
|
|
10
|
-
"save": true,
|
|
11
|
-
"schema": true,
|
|
12
|
-
"querySql": false
|
|
13
|
-
},
|
|
14
|
-
"targets": {
|
|
15
|
-
"modules": {
|
|
16
|
-
"demo_order": {
|
|
17
|
-
"mainTable": "demo_order",
|
|
18
|
-
"query": {
|
|
19
|
-
"fields": ["_ID", "ORDER_NO", "STATUS", "AMOUNT"],
|
|
20
|
-
"defaultFields": ["_ID", "ORDER_NO", "STATUS"],
|
|
21
|
-
"allowAllFields": false
|
|
22
|
-
},
|
|
23
|
-
"save": {
|
|
24
|
-
"actions": ["add", "edit"],
|
|
25
|
-
"fields": ["STATUS", "MEMO"]
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
"tables": {},
|
|
30
|
-
"sources": {},
|
|
31
|
-
"views": {}
|
|
32
|
-
}
|
|
33
|
-
}
|
package/dist/config.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { readFile } from 'node:fs/promises';
|
|
2
|
-
import { DEFAULT_BASE_URL } from './constants.js';
|
|
3
|
-
import { SeiMcpError } from './errors.js';
|
|
4
|
-
import { isObject, toTrimmedString } from './utils.js';
|
|
5
|
-
export async function loadConfig(argv = process.argv.slice(2), env = process.env) {
|
|
6
|
-
const configPath = resolveArg(argv, '--config') ?? (toTrimmedString(env.SEI_AI_MCP_CONFIG) || null);
|
|
7
|
-
const fileConfig = configPath ? await readConfigFile(configPath) : {};
|
|
8
|
-
return normalizeConfig(fileConfig, env);
|
|
9
|
-
}
|
|
10
|
-
export function normalizeConfig(input = {}, env = process.env) {
|
|
11
|
-
const config = isObject(input) ? input : {};
|
|
12
|
-
const auth = isObject(config.auth) ? config.auth : {};
|
|
13
|
-
const tools = isObject(config.tools) ? config.tools : {};
|
|
14
|
-
const targets = isObject(config.targets) ? config.targets : {};
|
|
15
|
-
return {
|
|
16
|
-
baseUrl: normalizeBaseUrl(config.baseUrl, env.SEI_BASE_URL),
|
|
17
|
-
auth: {
|
|
18
|
-
mode: normalizeMode(auth.mode, env.SEI_AI_MCP_AUTH_MODE),
|
|
19
|
-
token: stringOrEnv(auth.token, env.SEI_TOKEN),
|
|
20
|
-
tokenEnv: stringOrEnv(auth.tokenEnv, env.SEI_TOKEN ? 'SEI_TOKEN' : 'SEI_TOKEN'),
|
|
21
|
-
aiKey: stringOrEnv(auth.aiKey, env.SEI_AI_LOGIN_KEY),
|
|
22
|
-
aiKeyEnv: stringOrEnv(auth.aiKeyEnv, env.SEI_AI_LOGIN_KEY ? 'SEI_AI_LOGIN_KEY' : 'SEI_AI_LOGIN_KEY'),
|
|
23
|
-
account: stringOrEnv(auth.account, env.SEI_AI_LOGIN_ACCOUNT),
|
|
24
|
-
accountEnv: stringOrEnv(auth.accountEnv, env.SEI_AI_LOGIN_ACCOUNT ? 'SEI_AI_LOGIN_ACCOUNT' : 'SEI_AI_LOGIN_ACCOUNT'),
|
|
25
|
-
role: stringOrEnv(auth.role, env.SEI_AI_LOGIN_ROLE),
|
|
26
|
-
roleEnv: stringOrEnv(auth.roleEnv, env.SEI_AI_LOGIN_ROLE ? 'SEI_AI_LOGIN_ROLE' : 'SEI_AI_LOGIN_ROLE'),
|
|
27
|
-
},
|
|
28
|
-
tools: {
|
|
29
|
-
query: tools.query !== false,
|
|
30
|
-
save: tools.save !== false,
|
|
31
|
-
schema: tools.schema !== false,
|
|
32
|
-
querySql: tools.querySql === true,
|
|
33
|
-
},
|
|
34
|
-
targets: {
|
|
35
|
-
modules: toTargetMap(targets.modules),
|
|
36
|
-
tables: toTargetMap(targets.tables),
|
|
37
|
-
sources: toTargetMap(targets.sources),
|
|
38
|
-
views: toTargetMap(targets.views),
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
async function readConfigFile(path) {
|
|
43
|
-
try {
|
|
44
|
-
const text = await readFile(path, 'utf8');
|
|
45
|
-
return JSON.parse(text);
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
throw new SeiMcpError(`无法读取配置文件: ${path}`, 'INVALID_REQUEST', {
|
|
49
|
-
path,
|
|
50
|
-
cause: error instanceof Error ? error.message : String(error),
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
function resolveArg(argv, name) {
|
|
55
|
-
const index = argv.indexOf(name);
|
|
56
|
-
if (index === -1) {
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
const next = argv[index + 1];
|
|
60
|
-
return next && !next.startsWith('-') ? next : null;
|
|
61
|
-
}
|
|
62
|
-
function normalizeBaseUrl(configValue, envValue) {
|
|
63
|
-
const raw = stringOrEnv(configValue, envValue);
|
|
64
|
-
return raw || DEFAULT_BASE_URL;
|
|
65
|
-
}
|
|
66
|
-
function normalizeMode(configValue, envValue) {
|
|
67
|
-
const raw = stringOrEnv(configValue, envValue).toLowerCase();
|
|
68
|
-
return raw === 'token' ? 'token' : 'ai-login';
|
|
69
|
-
}
|
|
70
|
-
function stringOrEnv(value, envValue) {
|
|
71
|
-
const candidate = toTrimmedString(value);
|
|
72
|
-
if (candidate) {
|
|
73
|
-
return candidate;
|
|
74
|
-
}
|
|
75
|
-
return toTrimmedString(envValue);
|
|
76
|
-
}
|
|
77
|
-
function toTargetMap(value) {
|
|
78
|
-
if (!isObject(value)) {
|
|
79
|
-
return {};
|
|
80
|
-
}
|
|
81
|
-
return Object.fromEntries(Object.entries(value).filter(([, item]) => isObject(item)));
|
|
82
|
-
}
|
package/dist/constants.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
export const PACKAGE_NAME = 'sei-ai';
|
|
2
|
-
export const BIN_NAME = 'sei-ai';
|
|
3
|
-
export const SERVER_NAME = 'sei-ai-mcp-server';
|
|
4
|
-
export const SERVER_VERSION = '0.2.0';
|
|
5
|
-
export const DEFAULT_BASE_URL = 'http://127.0.0.1:8081';
|
|
6
|
-
export const DEFAULT_AI_KEY = 'dev-ai-secret';
|
|
7
|
-
export const DEFAULT_TIMEOUT_MS = 30_000;
|
|
8
|
-
export const DEFAULT_LOG_LEVEL = 'info';
|
|
9
|
-
export const DEFAULT_QUERY_LIMIT = 20;
|
|
10
|
-
export const DEFAULT_QUERY_SQL_PAGE = 1;
|
|
11
|
-
export const DEFAULT_QUERY_SQL_SIZE = 20;
|
|
12
|
-
export const MAX_RESPONSE_TEXT = 20_000;
|
|
13
|
-
export const MAX_LOG_TEXT = 2_000;
|
|
14
|
-
export const LOGIN_PATH = '/api/sei/public/login';
|
|
15
|
-
export const ACCOUNT_CHECK_CODE_PATH = '/api/sei/public/checkCode';
|
|
16
|
-
export const QUERY_PATH = '/api/sei/data/public/query';
|
|
17
|
-
export const SAVE_PATH = '/api/sei/data/public/save';
|
|
18
|
-
export const QUERY_SQL_PATH = '/api/sei/data/querySQL';
|
|
19
|
-
export const DDL_EXECUTE_PATH = '/api/sei/mcp/ddl/execute';
|
|
20
|
-
export const OPENAPI_DOCS_PATH = '/v3/api-docs';
|
|
21
|
-
export const DICT_MODULE = 'sys_dic';
|
|
22
|
-
export const DICT_DEFAULT_SYSID = 'sys';
|
|
23
|
-
export const DICT_FIELDS = [
|
|
24
|
-
'_UUID',
|
|
25
|
-
'_PID',
|
|
26
|
-
'_SYSID',
|
|
27
|
-
'_TYPE',
|
|
28
|
-
'_CTYPE',
|
|
29
|
-
'_CODE',
|
|
30
|
-
'_NAME',
|
|
31
|
-
'_ENAME',
|
|
32
|
-
'_DICT',
|
|
33
|
-
'_SORT',
|
|
34
|
-
'_BODY',
|
|
35
|
-
'_MEMO',
|
|
36
|
-
];
|
|
37
|
-
export const BASE_SEED_DEFAULT_SYSID = 'sys';
|
|
38
|
-
export const BASE_SEED_DEFAULT_ADMIN_UID = 'admin';
|
|
39
|
-
export const BASE_SEED_DEFAULT_ADMIN_ROLE = 'admin';
|
|
40
|
-
export const BASE_SEED_DEFAULT_ADMIN_PASSWORD = '123456';
|
|
41
|
-
export const ACCOUNT_LOGIN_DEFAULT_PROJECT = 'sys';
|
|
42
|
-
export const ACCOUNT_LOGIN_DEFAULT_CHECKCODE = 'abcd';
|
|
43
|
-
export const ACCOUNT_LOGIN_DEFAULT_TYPE = 'login';
|
|
44
|
-
export const ACCOUNT_LOGIN_DEFAULT_OS = 0;
|
|
45
|
-
export const TOKEN_CACHE_DIR_NAME = 'sei-ai';
|
|
46
|
-
export const TOKEN_CACHE_FILE_PREFIX = 'token-';
|
|
47
|
-
export const TOKEN_CACHE_FILE_SUFFIX = '.json';
|
|
48
|
-
export const TOKEN_CACHE_VERSION = 1;
|
package/dist/env.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { readFile } from 'node:fs/promises';
|
|
2
|
-
import { resolve } from 'node:path';
|
|
3
|
-
import { parseEnv } from 'node:util';
|
|
4
|
-
const DEFAULT_ENV_FILES = ['.env.local', '.env'];
|
|
5
|
-
export async function loadWorkingDirEnv(cwd = process.cwd(), env = process.env) {
|
|
6
|
-
for (const fileName of DEFAULT_ENV_FILES) {
|
|
7
|
-
await loadEnvFile(resolve(cwd, fileName), env);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
async function loadEnvFile(path, env) {
|
|
11
|
-
try {
|
|
12
|
-
const text = await readFile(path, 'utf8');
|
|
13
|
-
const parsed = parseEnv(text);
|
|
14
|
-
for (const [key, value] of Object.entries(parsed)) {
|
|
15
|
-
if (env[key] === undefined) {
|
|
16
|
-
env[key] = value;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
catch (error) {
|
|
21
|
-
if (isMissingFile(error)) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
throw error;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
function isMissingFile(error) {
|
|
28
|
-
if (!error || typeof error !== 'object') {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
const withCode = error;
|
|
32
|
-
return withCode.code === 'ENOENT';
|
|
33
|
-
}
|