@ty_krystal/sei-ai 0.1.8 → 0.1.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/README.md +1 -21
- package/dist/commands/api-docs.d.ts +1 -1
- package/dist/commands/api-docs.js +1 -1
- package/dist/commands/call.d.ts +1 -1
- package/dist/commands/call.js +1 -1
- package/dist/commands/dict/add-category.d.ts +1 -1
- package/dist/commands/dict/add-category.js +1 -1
- package/dist/commands/dict/add-item.d.ts +1 -1
- package/dist/commands/dict/add-item.js +1 -1
- package/dist/commands/dict/list.d.ts +1 -1
- package/dist/commands/dict/list.js +1 -1
- package/dist/commands/init/base-data.d.ts +1 -1
- package/dist/commands/init/base-data.js +1 -1
- package/dist/commands/query-sql.d.ts +1 -1
- package/dist/commands/query-sql.js +1 -1
- package/dist/commands/query.d.ts +1 -1
- package/dist/commands/query.js +1 -1
- package/dist/commands/relogin.d.ts +1 -1
- package/dist/commands/relogin.js +1 -1
- package/dist/commands/save.d.ts +1 -1
- package/dist/commands/save.js +1 -1
- package/dist/commands.d.ts +24 -0
- package/dist/commands.js +23 -0
- package/dist/core/cli-actions.d.ts +94 -0
- package/dist/core/cli-actions.js +155 -0
- package/dist/core/cli-helpers.d.ts +39 -0
- package/dist/core/cli-helpers.js +246 -0
- package/dist/core/command-base/context.d.ts +6 -0
- package/dist/core/command-base/context.js +10 -0
- package/dist/core/command-base/output.d.ts +2 -0
- package/dist/core/command-base/output.js +6 -0
- package/dist/core/command-base/payload.d.ts +7 -0
- package/dist/core/command-base/payload.js +33 -0
- package/dist/core/command-base/sei-command.d.ts +42 -0
- package/dist/core/command-base/sei-command.js +88 -0
- package/dist/core/config.d.ts +3 -0
- package/dist/core/config.js +82 -0
- package/dist/core/constants.d.ts +35 -0
- package/dist/core/constants.js +48 -0
- package/dist/core/env.d.ts +1 -0
- package/dist/core/env.js +55 -0
- package/dist/core/errors.d.ts +10 -0
- package/dist/core/errors.js +55 -0
- package/dist/core/index.d.ts +14 -0
- package/dist/core/index.js +14 -0
- package/dist/core/logger.d.ts +2 -0
- package/dist/core/logger.js +71 -0
- package/dist/core/openapi.d.ts +2 -0
- package/dist/core/openapi.js +261 -0
- package/dist/core/sei-client.d.ts +25 -0
- package/dist/core/sei-client.js +535 -0
- package/dist/core/types.d.ts +139 -0
- package/dist/core/types.js +1 -0
- package/dist/core/utils.d.ts +12 -0
- package/dist/core/utils.js +53 -0
- package/oclif.manifest.json +376 -328
- package/package.json +14 -8
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ $ npm install -g @ty_krystal/sei-ai
|
|
|
20
20
|
$ sei-ai COMMAND
|
|
21
21
|
running command...
|
|
22
22
|
$ sei-ai (--version)
|
|
23
|
-
@ty_krystal/sei-ai/0.1.
|
|
23
|
+
@ty_krystal/sei-ai/0.1.12 linux-x64 node-v24.17.0
|
|
24
24
|
$ sei-ai --help [COMMAND]
|
|
25
25
|
USAGE
|
|
26
26
|
$ sei-ai COMMAND
|
|
@@ -82,8 +82,6 @@ DESCRIPTION
|
|
|
82
82
|
Fetches the SEI OpenAPI document and renders a markdown or JSON summary.
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
-
_See code: [src/commands/api-docs.ts](https://github.com/tanyu/sei-ai/blob/v0.1.8/src/commands/api-docs.ts)_
|
|
86
|
-
|
|
87
85
|
## `sei-ai call METHOD PATH`
|
|
88
86
|
|
|
89
87
|
Call a SEI endpoint
|
|
@@ -121,8 +119,6 @@ DESCRIPTION
|
|
|
121
119
|
Makes an authenticated request to a SEI endpoint.
|
|
122
120
|
```
|
|
123
121
|
|
|
124
|
-
_See code: [src/commands/call.ts](https://github.com/tanyu/sei-ai/blob/v0.1.8/src/commands/call.ts)_
|
|
125
|
-
|
|
126
122
|
## `sei-ai dict:add-category NAME TYPECODE`
|
|
127
123
|
|
|
128
124
|
Add a dictionary category
|
|
@@ -165,8 +161,6 @@ DESCRIPTION
|
|
|
165
161
|
Builds and saves a SEI dictionary category row.
|
|
166
162
|
```
|
|
167
163
|
|
|
168
|
-
_See code: [src/commands/dict/add-category.ts](https://github.com/tanyu/sei-ai/blob/v0.1.8/src/commands/dict/add-category.ts)_
|
|
169
|
-
|
|
170
164
|
## `sei-ai dict:add-item CODE NAME TYPECODE`
|
|
171
165
|
|
|
172
166
|
Add a dictionary item
|
|
@@ -210,8 +204,6 @@ DESCRIPTION
|
|
|
210
204
|
Builds and saves a SEI dictionary item row.
|
|
211
205
|
```
|
|
212
206
|
|
|
213
|
-
_See code: [src/commands/dict/add-item.ts](https://github.com/tanyu/sei-ai/blob/v0.1.8/src/commands/dict/add-item.ts)_
|
|
214
|
-
|
|
215
207
|
## `sei-ai dict:list`
|
|
216
208
|
|
|
217
209
|
List dictionary entries
|
|
@@ -244,8 +236,6 @@ DESCRIPTION
|
|
|
244
236
|
Queries SEI dictionary data and optionally renders the tree structure.
|
|
245
237
|
```
|
|
246
238
|
|
|
247
|
-
_See code: [src/commands/dict/list.ts](https://github.com/tanyu/sei-ai/blob/v0.1.8/src/commands/dict/list.ts)_
|
|
248
|
-
|
|
249
239
|
## `sei-ai help [COMMAND]`
|
|
250
240
|
|
|
251
241
|
Display help for sei-ai.
|
|
@@ -303,8 +293,6 @@ DESCRIPTION
|
|
|
303
293
|
Executes the base seed SQL and clears SEI caches.
|
|
304
294
|
```
|
|
305
295
|
|
|
306
|
-
_See code: [src/commands/init/base-data.ts](https://github.com/tanyu/sei-ai/blob/v0.1.8/src/commands/init/base-data.ts)_
|
|
307
|
-
|
|
308
296
|
## `sei-ai plugins`
|
|
309
297
|
|
|
310
298
|
List installed plugins.
|
|
@@ -626,8 +614,6 @@ DESCRIPTION
|
|
|
626
614
|
Sends a SEI query payload.
|
|
627
615
|
```
|
|
628
616
|
|
|
629
|
-
_See code: [src/commands/query.ts](https://github.com/tanyu/sei-ai/blob/v0.1.8/src/commands/query.ts)_
|
|
630
|
-
|
|
631
617
|
## `sei-ai query-sql SQL`
|
|
632
618
|
|
|
633
619
|
Query SEI with SQL
|
|
@@ -664,8 +650,6 @@ ALIASES
|
|
|
664
650
|
$ sei-ai sql
|
|
665
651
|
```
|
|
666
652
|
|
|
667
|
-
_See code: [src/commands/query-sql.ts](https://github.com/tanyu/sei-ai/blob/v0.1.8/src/commands/query-sql.ts)_
|
|
668
|
-
|
|
669
653
|
## `sei-ai relogin`
|
|
670
654
|
|
|
671
655
|
Refresh the login token
|
|
@@ -692,8 +676,6 @@ DESCRIPTION
|
|
|
692
676
|
Forces a fresh ai-login and prints the new token.
|
|
693
677
|
```
|
|
694
678
|
|
|
695
|
-
_See code: [src/commands/relogin.ts](https://github.com/tanyu/sei-ai/blob/v0.1.8/src/commands/relogin.ts)_
|
|
696
|
-
|
|
697
679
|
## `sei-ai save`
|
|
698
680
|
|
|
699
681
|
Save SEI data
|
|
@@ -725,8 +707,6 @@ DESCRIPTION
|
|
|
725
707
|
Sends a SEI save payload.
|
|
726
708
|
```
|
|
727
709
|
|
|
728
|
-
_See code: [src/commands/save.ts](https://github.com/tanyu/sei-ai/blob/v0.1.8/src/commands/save.ts)_
|
|
729
|
-
|
|
730
710
|
## `sei-ai sql SQL`
|
|
731
711
|
|
|
732
712
|
Query SEI with SQL
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Flags } from '@oclif/core';
|
|
2
|
-
import { runApiDocs, SeiCommand } from '
|
|
2
|
+
import { runApiDocs, SeiCommand } from '../core/index.js';
|
|
3
3
|
export default class ApiDocsCommand extends SeiCommand {
|
|
4
4
|
static description = 'Fetches the SEI OpenAPI document and renders a markdown or JSON summary.';
|
|
5
5
|
static flags = {
|
package/dist/commands/call.d.ts
CHANGED
package/dist/commands/call.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Args, Flags } from '@oclif/core';
|
|
2
|
-
import { runCall, SeiCommand } from '
|
|
2
|
+
import { runCall, SeiCommand } from '../core/index.js';
|
|
3
3
|
export default class CallCommand extends SeiCommand {
|
|
4
4
|
static args = {
|
|
5
5
|
method: Args.string({ description: 'HTTP method', required: true }),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Args, Flags } from '@oclif/core';
|
|
2
|
-
import { runDictAddCategory, SeiCommand } from '
|
|
2
|
+
import { runDictAddCategory, SeiCommand } from '../../core/index.js';
|
|
3
3
|
export default class DictAddCategoryCommand extends SeiCommand {
|
|
4
4
|
static args = {
|
|
5
5
|
name: Args.string({ description: '字典名称', required: true }),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Args, Flags } from '@oclif/core';
|
|
2
|
-
import { runDictAddItem, SeiCommand } from '
|
|
2
|
+
import { runDictAddItem, SeiCommand } from '../../core/index.js';
|
|
3
3
|
export default class DictAddItemCommand extends SeiCommand {
|
|
4
4
|
static args = {
|
|
5
5
|
code: Args.string({ description: '字典项编码', required: true }),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Flags } from '@oclif/core';
|
|
2
|
-
import { runDictList, SeiCommand } from '
|
|
2
|
+
import { runDictList, SeiCommand } from '../../core/index.js';
|
|
3
3
|
export default class DictListCommand extends SeiCommand {
|
|
4
4
|
static description = 'Queries SEI dictionary data and optionally renders the tree structure.';
|
|
5
5
|
static flags = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Flags } from '@oclif/core';
|
|
2
|
-
import { runInitBaseData, SeiCommand } from '
|
|
2
|
+
import { runInitBaseData, SeiCommand } from '../../core/index.js';
|
|
3
3
|
export default class InitBaseDataCommand extends SeiCommand {
|
|
4
4
|
static description = 'Executes the base seed SQL and clears SEI caches.';
|
|
5
5
|
static flags = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Args, Flags } from '@oclif/core';
|
|
2
|
-
import { buildQuerySqlPayload, runQuerySql, SeiCommand } from '
|
|
2
|
+
import { buildQuerySqlPayload, runQuerySql, SeiCommand } from '../core/index.js';
|
|
3
3
|
export default class QuerySqlCommand extends SeiCommand {
|
|
4
4
|
static aliases = ['sql'];
|
|
5
5
|
static args = {
|
package/dist/commands/query.d.ts
CHANGED
package/dist/commands/query.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Flags } from '@oclif/core';
|
|
2
|
-
import { runQuery, SeiCommand } from '
|
|
2
|
+
import { runQuery, SeiCommand } from '../core/index.js';
|
|
3
3
|
export default class QueryCommand extends SeiCommand {
|
|
4
4
|
static description = 'Sends a SEI query payload.';
|
|
5
5
|
static flags = {
|
package/dist/commands/relogin.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { runRelogin, SeiCommand } from '
|
|
1
|
+
import { runRelogin, SeiCommand } from '../core/index.js';
|
|
2
2
|
export default class ReloginCommand extends SeiCommand {
|
|
3
3
|
static description = 'Forces a fresh ai-login and prints the new token.';
|
|
4
4
|
static flags = {
|
package/dist/commands/save.d.ts
CHANGED
package/dist/commands/save.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Flags } from '@oclif/core';
|
|
2
|
-
import { runSave, SeiCommand } from '
|
|
2
|
+
import { runSave, SeiCommand } from '../core/index.js';
|
|
3
3
|
export default class SaveCommand extends SeiCommand {
|
|
4
4
|
static description = 'Sends a SEI save payload.';
|
|
5
5
|
static flags = {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import ApiDocsCommand from './commands/api-docs.js';
|
|
2
|
+
import CallCommand from './commands/call.js';
|
|
3
|
+
import DictAddCategoryCommand from './commands/dict/add-category.js';
|
|
4
|
+
import DictAddItemCommand from './commands/dict/add-item.js';
|
|
5
|
+
import DictListCommand from './commands/dict/list.js';
|
|
6
|
+
import InitBaseDataCommand from './commands/init/base-data.js';
|
|
7
|
+
import QuerySqlCommand from './commands/query-sql.js';
|
|
8
|
+
import QueryCommand from './commands/query.js';
|
|
9
|
+
import ReloginCommand from './commands/relogin.js';
|
|
10
|
+
import SaveCommand from './commands/save.js';
|
|
11
|
+
declare const _default: {
|
|
12
|
+
readonly 'api-docs': typeof ApiDocsCommand;
|
|
13
|
+
readonly call: typeof CallCommand;
|
|
14
|
+
readonly 'dict:add-category': typeof DictAddCategoryCommand;
|
|
15
|
+
readonly 'dict:add-item': typeof DictAddItemCommand;
|
|
16
|
+
readonly 'dict:list': typeof DictListCommand;
|
|
17
|
+
readonly 'init:base-data': typeof InitBaseDataCommand;
|
|
18
|
+
readonly query: typeof QueryCommand;
|
|
19
|
+
readonly 'query-sql': typeof QuerySqlCommand;
|
|
20
|
+
readonly relogin: typeof ReloginCommand;
|
|
21
|
+
readonly save: typeof SaveCommand;
|
|
22
|
+
readonly sql: typeof QuerySqlCommand;
|
|
23
|
+
};
|
|
24
|
+
export default _default;
|
package/dist/commands.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import ApiDocsCommand from './commands/api-docs.js';
|
|
2
|
+
import CallCommand from './commands/call.js';
|
|
3
|
+
import DictAddCategoryCommand from './commands/dict/add-category.js';
|
|
4
|
+
import DictAddItemCommand from './commands/dict/add-item.js';
|
|
5
|
+
import DictListCommand from './commands/dict/list.js';
|
|
6
|
+
import InitBaseDataCommand from './commands/init/base-data.js';
|
|
7
|
+
import QuerySqlCommand from './commands/query-sql.js';
|
|
8
|
+
import QueryCommand from './commands/query.js';
|
|
9
|
+
import ReloginCommand from './commands/relogin.js';
|
|
10
|
+
import SaveCommand from './commands/save.js';
|
|
11
|
+
export default {
|
|
12
|
+
'api-docs': ApiDocsCommand,
|
|
13
|
+
call: CallCommand,
|
|
14
|
+
'dict:add-category': DictAddCategoryCommand,
|
|
15
|
+
'dict:add-item': DictAddItemCommand,
|
|
16
|
+
'dict:list': DictListCommand,
|
|
17
|
+
'init:base-data': InitBaseDataCommand,
|
|
18
|
+
query: QueryCommand,
|
|
19
|
+
'query-sql': QuerySqlCommand,
|
|
20
|
+
relogin: ReloginCommand,
|
|
21
|
+
save: SaveCommand,
|
|
22
|
+
sql: QuerySqlCommand,
|
|
23
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
export declare function runApiDocs(options: {
|
|
2
|
+
client: {
|
|
3
|
+
readApiDocs(): Promise<unknown>;
|
|
4
|
+
};
|
|
5
|
+
keyword?: string;
|
|
6
|
+
format?: 'json' | 'markdown';
|
|
7
|
+
outputPath?: string;
|
|
8
|
+
}): Promise<void>;
|
|
9
|
+
export declare function runRelogin(options: {
|
|
10
|
+
client: {
|
|
11
|
+
relogin(): Promise<string>;
|
|
12
|
+
};
|
|
13
|
+
}): Promise<void>;
|
|
14
|
+
export declare function runCall(options: {
|
|
15
|
+
client: {
|
|
16
|
+
call(method: string, path: string, payload?: unknown, requestOptions?: Record<string, unknown>): Promise<unknown>;
|
|
17
|
+
};
|
|
18
|
+
method: string;
|
|
19
|
+
path: string;
|
|
20
|
+
payload?: unknown;
|
|
21
|
+
allowFailure?: boolean;
|
|
22
|
+
allowEmpty?: boolean;
|
|
23
|
+
skipAuth?: boolean;
|
|
24
|
+
}): Promise<void>;
|
|
25
|
+
export declare function runQuery(options: {
|
|
26
|
+
client: {
|
|
27
|
+
query(payload: unknown, requestOptions?: Record<string, unknown>): Promise<unknown>;
|
|
28
|
+
};
|
|
29
|
+
payload: unknown;
|
|
30
|
+
allowFailure?: boolean;
|
|
31
|
+
}): Promise<void>;
|
|
32
|
+
export declare function runSave(options: {
|
|
33
|
+
client: {
|
|
34
|
+
save(payload: unknown, requestOptions?: Record<string, unknown>): Promise<unknown>;
|
|
35
|
+
};
|
|
36
|
+
payload: unknown;
|
|
37
|
+
allowFailure?: boolean;
|
|
38
|
+
}): Promise<void>;
|
|
39
|
+
export declare function runQuerySql(options: {
|
|
40
|
+
client: {
|
|
41
|
+
querySql(sql: string, page?: number, size?: number, requestOptions?: Record<string, unknown>): Promise<unknown>;
|
|
42
|
+
};
|
|
43
|
+
sql: string;
|
|
44
|
+
page?: number;
|
|
45
|
+
size?: number;
|
|
46
|
+
allowFailure?: boolean;
|
|
47
|
+
}): Promise<void>;
|
|
48
|
+
export declare function runDictList(options: {
|
|
49
|
+
client: {
|
|
50
|
+
query(payload: unknown, requestOptions?: Record<string, unknown>): Promise<unknown>;
|
|
51
|
+
};
|
|
52
|
+
typeCode?: string;
|
|
53
|
+
keyword?: string;
|
|
54
|
+
size?: number;
|
|
55
|
+
flat?: boolean;
|
|
56
|
+
allowFailure?: boolean;
|
|
57
|
+
}): Promise<void>;
|
|
58
|
+
export declare function runDictAddCategory(options: {
|
|
59
|
+
client: {
|
|
60
|
+
save(payload: unknown, requestOptions?: Record<string, unknown>): Promise<unknown>;
|
|
61
|
+
};
|
|
62
|
+
typeCode: string;
|
|
63
|
+
name: string;
|
|
64
|
+
rowOptions?: Record<string, unknown>;
|
|
65
|
+
allowFailure?: boolean;
|
|
66
|
+
}): Promise<void>;
|
|
67
|
+
export declare function runDictAddItem(options: {
|
|
68
|
+
client: {
|
|
69
|
+
save(payload: unknown, requestOptions?: Record<string, unknown>): Promise<unknown>;
|
|
70
|
+
};
|
|
71
|
+
typeCode: string;
|
|
72
|
+
code: string;
|
|
73
|
+
name: string;
|
|
74
|
+
rowOptions?: Record<string, unknown>;
|
|
75
|
+
allowFailure?: boolean;
|
|
76
|
+
}): Promise<void>;
|
|
77
|
+
export declare function runInitBaseData(options: {
|
|
78
|
+
client: {
|
|
79
|
+
executeDdlStatements(statements: string[], requestOptions?: Record<string, unknown>): Promise<unknown>;
|
|
80
|
+
call(method: string, path: string, payload?: unknown, requestOptions?: Record<string, unknown>): Promise<unknown>;
|
|
81
|
+
};
|
|
82
|
+
sqlFile?: string;
|
|
83
|
+
sysid?: string;
|
|
84
|
+
adminUid?: string;
|
|
85
|
+
adminName?: string;
|
|
86
|
+
adminRole?: string;
|
|
87
|
+
adminRoleName?: string;
|
|
88
|
+
adminPassword?: string;
|
|
89
|
+
resetAdminPassword?: boolean;
|
|
90
|
+
allowFailure?: boolean;
|
|
91
|
+
}): Promise<void>;
|
|
92
|
+
export declare function writeOutput(path: string | undefined, text: string): Promise<void>;
|
|
93
|
+
export declare function resolveBaseSeedSqlPath(path: string | undefined): string;
|
|
94
|
+
export declare function formatActionError(error: unknown): string;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { BASE_SEED_DEFAULT_ADMIN_ROLE, BASE_SEED_DEFAULT_ADMIN_UID } from './constants.js';
|
|
4
|
+
import { formatCliError, SeiMcpError } from './errors.js';
|
|
5
|
+
import { buildBaseSeedSqlVars, buildDictCategoryRow, buildDictItemRow, buildDictQueryPayload, buildDictSavePayload, buildDictTree, removeSqlCommentLines, renderBaseSeedSql, splitSqlStatements, } from './cli-helpers.js';
|
|
6
|
+
import { printJson } from './command-base/output.js';
|
|
7
|
+
import { buildOpenApiDocSummary, renderOpenApiMarkdown } from './openapi.js';
|
|
8
|
+
export async function runApiDocs(options) {
|
|
9
|
+
const raw = await options.client.readApiDocs();
|
|
10
|
+
const summary = buildOpenApiDocSummary(raw, options.keyword);
|
|
11
|
+
const output = options.format === 'json' ? `${JSON.stringify(summary, null, 2)}\n` : renderOpenApiMarkdown(summary);
|
|
12
|
+
await writeOutput(options.outputPath, output);
|
|
13
|
+
}
|
|
14
|
+
export async function runRelogin(options) {
|
|
15
|
+
const token = await options.client.relogin();
|
|
16
|
+
printJson({
|
|
17
|
+
success: true,
|
|
18
|
+
code: 1,
|
|
19
|
+
message: '重新登录成功',
|
|
20
|
+
data: { token },
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export async function runCall(options) {
|
|
24
|
+
const response = await options.client.call(options.method, options.path, options.payload, {
|
|
25
|
+
allowFailure: options.allowFailure,
|
|
26
|
+
allowEmpty: options.allowEmpty,
|
|
27
|
+
skipAuth: options.skipAuth,
|
|
28
|
+
});
|
|
29
|
+
printJson(response);
|
|
30
|
+
}
|
|
31
|
+
export async function runQuery(options) {
|
|
32
|
+
const response = await options.client.query(options.payload, {
|
|
33
|
+
allowFailure: options.allowFailure,
|
|
34
|
+
});
|
|
35
|
+
printJson(response);
|
|
36
|
+
}
|
|
37
|
+
export async function runSave(options) {
|
|
38
|
+
const response = await options.client.save(options.payload, {
|
|
39
|
+
allowFailure: options.allowFailure,
|
|
40
|
+
});
|
|
41
|
+
printJson(response);
|
|
42
|
+
}
|
|
43
|
+
export async function runQuerySql(options) {
|
|
44
|
+
const response = await options.client.querySql(options.sql, options.page, options.size, {
|
|
45
|
+
allowFailure: options.allowFailure,
|
|
46
|
+
});
|
|
47
|
+
printJson(response);
|
|
48
|
+
}
|
|
49
|
+
export async function runDictList(options) {
|
|
50
|
+
const payload = buildDictQueryPayload(options.typeCode, options.keyword, options.size ?? 1000);
|
|
51
|
+
const response = await options.client.query(payload, {
|
|
52
|
+
allowFailure: options.allowFailure,
|
|
53
|
+
});
|
|
54
|
+
if (!options.flat && isObject(response) && isObject(response.data) && Array.isArray(response.data.rows)) {
|
|
55
|
+
response.data.tree = buildDictTree(response.data.rows);
|
|
56
|
+
}
|
|
57
|
+
printJson(response);
|
|
58
|
+
}
|
|
59
|
+
export async function runDictAddCategory(options) {
|
|
60
|
+
const payload = buildDictSavePayload(buildDictCategoryRow({
|
|
61
|
+
body: stringOrUndefined(options.rowOptions?.body),
|
|
62
|
+
code: stringOrUndefined(options.rowOptions?.code),
|
|
63
|
+
ctype: stringOrUndefined(options.rowOptions?.ctype),
|
|
64
|
+
dictFlag: numberOrUndefined(options.rowOptions?.dictFlag),
|
|
65
|
+
ename: stringOrUndefined(options.rowOptions?.ename),
|
|
66
|
+
memo: stringOrUndefined(options.rowOptions?.memo),
|
|
67
|
+
name: options.name,
|
|
68
|
+
sort: numberOrUndefined(options.rowOptions?.sort),
|
|
69
|
+
sysid: stringOrUndefined(options.rowOptions?.sysid),
|
|
70
|
+
typeCode: options.typeCode,
|
|
71
|
+
uuid: stringOrUndefined(options.rowOptions?.uuid),
|
|
72
|
+
}));
|
|
73
|
+
const response = await options.client.save(payload, {
|
|
74
|
+
allowFailure: options.allowFailure,
|
|
75
|
+
});
|
|
76
|
+
printJson(response);
|
|
77
|
+
}
|
|
78
|
+
export async function runDictAddItem(options) {
|
|
79
|
+
const payload = buildDictSavePayload(buildDictItemRow({
|
|
80
|
+
body: stringOrUndefined(options.rowOptions?.body),
|
|
81
|
+
code: options.code,
|
|
82
|
+
ctype: stringOrUndefined(options.rowOptions?.ctype),
|
|
83
|
+
dictFlag: numberOrUndefined(options.rowOptions?.dictFlag),
|
|
84
|
+
ename: stringOrUndefined(options.rowOptions?.ename),
|
|
85
|
+
memo: stringOrUndefined(options.rowOptions?.memo),
|
|
86
|
+
name: options.name,
|
|
87
|
+
parent: stringOrUndefined(options.rowOptions?.parent),
|
|
88
|
+
sort: numberOrUndefined(options.rowOptions?.sort),
|
|
89
|
+
sysid: stringOrUndefined(options.rowOptions?.sysid),
|
|
90
|
+
typeCode: options.typeCode,
|
|
91
|
+
uuid: stringOrUndefined(options.rowOptions?.uuid),
|
|
92
|
+
}));
|
|
93
|
+
const response = await options.client.save(payload, {
|
|
94
|
+
allowFailure: options.allowFailure,
|
|
95
|
+
});
|
|
96
|
+
printJson(response);
|
|
97
|
+
}
|
|
98
|
+
export async function runInitBaseData(options) {
|
|
99
|
+
const sqlFile = resolveBaseSeedSqlPath(options.sqlFile);
|
|
100
|
+
const template = await readFile(sqlFile, 'utf8');
|
|
101
|
+
const sql = renderBaseSeedSql(template, buildBaseSeedSqlVars({
|
|
102
|
+
adminName: options.adminName,
|
|
103
|
+
adminPassword: options.adminPassword,
|
|
104
|
+
adminRole: options.adminRole,
|
|
105
|
+
adminRoleName: options.adminRoleName,
|
|
106
|
+
adminUid: options.adminUid,
|
|
107
|
+
resetAdminPassword: options.resetAdminPassword,
|
|
108
|
+
sysid: options.sysid,
|
|
109
|
+
}));
|
|
110
|
+
const statements = splitSqlStatements(removeSqlCommentLines(sql));
|
|
111
|
+
if (statements.length === 0) {
|
|
112
|
+
throw new SeiMcpError('初始化 SQL 文件没有可执行语句', 'INVALID_PARAMS');
|
|
113
|
+
}
|
|
114
|
+
const executed = await options.client.executeDdlStatements(statements, {
|
|
115
|
+
allowFailure: options.allowFailure,
|
|
116
|
+
});
|
|
117
|
+
await options.client.call('POST', '/api/sei/data/removeAllCache', {}, { allowFailure: false }).catch(() => undefined);
|
|
118
|
+
printJson({
|
|
119
|
+
success: true,
|
|
120
|
+
code: 1,
|
|
121
|
+
message: '基础源数据初始化完成',
|
|
122
|
+
data: {
|
|
123
|
+
executed: Array.isArray(executed) ? executed.length : 0,
|
|
124
|
+
sqlFile,
|
|
125
|
+
admin: options.adminUid ?? BASE_SEED_DEFAULT_ADMIN_UID,
|
|
126
|
+
role: options.adminRole ?? BASE_SEED_DEFAULT_ADMIN_ROLE,
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
export async function writeOutput(path, text) {
|
|
131
|
+
if (!path) {
|
|
132
|
+
process.stdout.write(text);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
await writeFile(path, text, 'utf8');
|
|
136
|
+
process.stdout.write(`已写入:${path}\n`);
|
|
137
|
+
}
|
|
138
|
+
export function resolveBaseSeedSqlPath(path) {
|
|
139
|
+
if (path) {
|
|
140
|
+
return resolve(path);
|
|
141
|
+
}
|
|
142
|
+
return resolve(process.cwd(), '.codex/skills/sei-ai/scripts/init-base-data.sql');
|
|
143
|
+
}
|
|
144
|
+
export function formatActionError(error) {
|
|
145
|
+
return formatCliError(error);
|
|
146
|
+
}
|
|
147
|
+
function stringOrUndefined(value) {
|
|
148
|
+
return typeof value === 'string' && value.trim() ? value.trim() : undefined;
|
|
149
|
+
}
|
|
150
|
+
function numberOrUndefined(value) {
|
|
151
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
|
|
152
|
+
}
|
|
153
|
+
function isObject(value) {
|
|
154
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
155
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export interface DictRowInput {
|
|
2
|
+
body?: string;
|
|
3
|
+
ctype?: string;
|
|
4
|
+
dictFlag?: number;
|
|
5
|
+
ename?: string;
|
|
6
|
+
memo?: string;
|
|
7
|
+
sort?: number;
|
|
8
|
+
sysid?: string;
|
|
9
|
+
uuid?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface DictCategoryInput extends DictRowInput {
|
|
12
|
+
code?: string;
|
|
13
|
+
name: string;
|
|
14
|
+
typeCode: string;
|
|
15
|
+
}
|
|
16
|
+
export interface DictItemInput extends DictRowInput {
|
|
17
|
+
code: string;
|
|
18
|
+
name: string;
|
|
19
|
+
parent?: string;
|
|
20
|
+
typeCode: string;
|
|
21
|
+
}
|
|
22
|
+
export interface InitBaseDataInput {
|
|
23
|
+
adminName?: string;
|
|
24
|
+
adminPassword?: string;
|
|
25
|
+
adminRole?: string;
|
|
26
|
+
adminRoleName?: string;
|
|
27
|
+
adminUid?: string;
|
|
28
|
+
resetAdminPassword?: boolean;
|
|
29
|
+
sysid?: string;
|
|
30
|
+
}
|
|
31
|
+
export declare function buildDictQueryPayload(typeCode?: string, keyword?: string, size?: number): Record<string, unknown>;
|
|
32
|
+
export declare function buildDictSavePayload(row: Record<string, unknown>): Record<string, unknown>;
|
|
33
|
+
export declare function buildDictCategoryRow(input: DictCategoryInput): Record<string, unknown>;
|
|
34
|
+
export declare function buildDictItemRow(input: DictItemInput): Record<string, unknown>;
|
|
35
|
+
export declare function buildDictTree(rows: unknown): Array<Record<string, unknown>>;
|
|
36
|
+
export declare function buildBaseSeedSqlVars(input: InitBaseDataInput): Record<string, string>;
|
|
37
|
+
export declare function renderBaseSeedSql(template: string, values: Record<string, string>): string;
|
|
38
|
+
export declare function removeSqlCommentLines(sql: string): string;
|
|
39
|
+
export declare function splitSqlStatements(sql: string): string[];
|