ai-world-sdk 1.3.6 → 1.5.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/dist/admin.d.ts +8 -0
- package/dist/admin.js +25 -0
- package/dist/agent-skills.d.ts +3 -0
- package/dist/agent-skills.js +16 -0
- package/dist/cli/commands/admin.d.ts +2 -0
- package/dist/cli/commands/admin.js +455 -0
- package/dist/cli/commands/auth.d.ts +2 -0
- package/dist/cli/commands/auth.js +120 -0
- package/dist/cli/commands/chrome.d.ts +2 -0
- package/dist/cli/commands/chrome.js +192 -0
- package/dist/cli/commands/config-cmd.d.ts +2 -0
- package/dist/cli/commands/config-cmd.js +80 -0
- package/dist/cli/commands/image.d.ts +2 -0
- package/dist/cli/commands/image.js +186 -0
- package/dist/cli/commands/model.d.ts +2 -0
- package/dist/cli/commands/model.js +62 -0
- package/dist/cli/commands/plugin.d.ts +2 -0
- package/dist/cli/commands/plugin.js +258 -0
- package/dist/cli/commands/resource.d.ts +2 -0
- package/dist/cli/commands/resource.js +303 -0
- package/dist/cli/commands/shared.d.ts +2 -0
- package/dist/cli/commands/shared.js +251 -0
- package/dist/cli/commands/skill.d.ts +2 -0
- package/dist/cli/commands/skill.js +213 -0
- package/dist/cli/commands/stats.d.ts +2 -0
- package/dist/cli/commands/stats.js +185 -0
- package/dist/cli/commands/text.d.ts +2 -0
- package/dist/cli/commands/text.js +104 -0
- package/dist/cli/commands/versioned.d.ts +2 -0
- package/dist/cli/commands/versioned.js +186 -0
- package/dist/cli/commands/video.d.ts +2 -0
- package/dist/cli/commands/video.js +228 -0
- package/dist/cli/config.d.ts +40 -0
- package/dist/cli/config.js +133 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +47 -0
- package/dist/cli/output.d.ts +5 -0
- package/dist/cli/output.js +82 -0
- package/dist/cli/utils.d.ts +23 -0
- package/dist/cli/utils.js +151 -0
- package/dist/config.d.ts +3 -3
- package/dist/config.js +2 -2
- package/package.json +7 -3
- package/skills/ai-world-sdk/SKILL.md +33 -1
- package/skills/ai-world-sdk/docs/cli-commands.md +191 -0
- package/skills/ai-world-sdk/docs/cli-usage.md +154 -0
package/dist/admin.d.ts
CHANGED
|
@@ -118,4 +118,12 @@ export declare class AdminClient {
|
|
|
118
118
|
deleteRow(tableName: string, primaryKey: Record<string, any>): Promise<{
|
|
119
119
|
message: string;
|
|
120
120
|
}>;
|
|
121
|
+
executeSql(data: {
|
|
122
|
+
sql: string;
|
|
123
|
+
description?: string;
|
|
124
|
+
}): Promise<any>;
|
|
125
|
+
getSqlHistory(options?: {
|
|
126
|
+
page?: number;
|
|
127
|
+
pageSize?: number;
|
|
128
|
+
}): Promise<any>;
|
|
121
129
|
}
|
package/dist/admin.js
CHANGED
|
@@ -293,5 +293,30 @@ class AdminClient {
|
|
|
293
293
|
await this.handleErrorResponse(response);
|
|
294
294
|
return (await response.json());
|
|
295
295
|
}
|
|
296
|
+
async executeSql(data) {
|
|
297
|
+
config_1.sdkConfig.ensureVersionCompatible();
|
|
298
|
+
const url = `${this.baseUrl}/api/admin/database/execute-sql`;
|
|
299
|
+
(0, log_1.logRequest)("POST", url, this.headers);
|
|
300
|
+
const response = await fetch(url, {
|
|
301
|
+
method: "POST",
|
|
302
|
+
headers: this.headers,
|
|
303
|
+
body: JSON.stringify(data),
|
|
304
|
+
});
|
|
305
|
+
if (!response.ok)
|
|
306
|
+
await this.handleErrorResponse(response);
|
|
307
|
+
return await response.json();
|
|
308
|
+
}
|
|
309
|
+
async getSqlHistory(options = {}) {
|
|
310
|
+
config_1.sdkConfig.ensureVersionCompatible();
|
|
311
|
+
const url = this.buildUrl("/api/admin/database/sql-history", {
|
|
312
|
+
page: options.page,
|
|
313
|
+
page_size: options.pageSize,
|
|
314
|
+
});
|
|
315
|
+
(0, log_1.logRequest)("GET", url, this.headers);
|
|
316
|
+
const response = await fetch(url, { headers: this.headers });
|
|
317
|
+
if (!response.ok)
|
|
318
|
+
await this.handleErrorResponse(response);
|
|
319
|
+
return await response.json();
|
|
320
|
+
}
|
|
296
321
|
}
|
|
297
322
|
exports.AdminClient = AdminClient;
|
package/dist/agent-skills.d.ts
CHANGED
package/dist/agent-skills.js
CHANGED
|
@@ -112,6 +112,22 @@ class AgentSkillClient {
|
|
|
112
112
|
(0, log_1.logResponse)(response.status, response.statusText, response.headers, result);
|
|
113
113
|
return result;
|
|
114
114
|
}
|
|
115
|
+
async getSkillMd(skillName) {
|
|
116
|
+
config_1.sdkConfig.ensureVersionCompatible();
|
|
117
|
+
const apiUrl = `${this.baseUrl}/api/agent-skills/${skillName}/skill-md`;
|
|
118
|
+
(0, log_1.debugLog)("Get agent skill SKILL.md:", { skillName });
|
|
119
|
+
(0, log_1.logRequest)("GET", apiUrl, this.headers);
|
|
120
|
+
const response = await fetch(apiUrl, {
|
|
121
|
+
method: "GET",
|
|
122
|
+
headers: this.headers,
|
|
123
|
+
});
|
|
124
|
+
if (!response.ok) {
|
|
125
|
+
await this.handleErrorResponse(response);
|
|
126
|
+
}
|
|
127
|
+
const result = (await response.json());
|
|
128
|
+
(0, log_1.logResponse)(response.status, response.statusText, response.headers, result);
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
115
131
|
/**
|
|
116
132
|
* Upload a skill (zip file)
|
|
117
133
|
* 上传 Skill
|
|
@@ -0,0 +1,455 @@
|
|
|
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.registerAdminCommands = registerAdminCommands;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const admin_1 = require("../../admin");
|
|
40
|
+
const config_1 = require("../config");
|
|
41
|
+
const output_1 = require("../output");
|
|
42
|
+
const utils_1 = require("../utils");
|
|
43
|
+
function collectOpts(cmd) {
|
|
44
|
+
const chain = [];
|
|
45
|
+
for (let c = cmd; c; c = c.parent) {
|
|
46
|
+
chain.unshift(c);
|
|
47
|
+
}
|
|
48
|
+
const o = {};
|
|
49
|
+
for (const c of chain) {
|
|
50
|
+
Object.assign(o, c.opts());
|
|
51
|
+
}
|
|
52
|
+
return o;
|
|
53
|
+
}
|
|
54
|
+
function prepareAdmin(program, cmd) {
|
|
55
|
+
const o = collectOpts(cmd);
|
|
56
|
+
const auth = (0, config_1.resolveAuth)({
|
|
57
|
+
baseUrl: o.baseUrl,
|
|
58
|
+
token: o.token,
|
|
59
|
+
pluginId: o.pluginId,
|
|
60
|
+
});
|
|
61
|
+
(0, utils_1.requireOption)(auth.token, 'token');
|
|
62
|
+
(0, utils_1.initSDK)(auth);
|
|
63
|
+
return (0, utils_1.getFormat)(program);
|
|
64
|
+
}
|
|
65
|
+
function parseJson(raw, label) {
|
|
66
|
+
try {
|
|
67
|
+
return JSON.parse(raw);
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
const err = new Error(`无效 JSON (${label})`);
|
|
71
|
+
err.code = 'VALIDATION_ERROR';
|
|
72
|
+
throw err;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function parseUserIdsList(raw) {
|
|
76
|
+
return raw
|
|
77
|
+
.split(',')
|
|
78
|
+
.map((s) => s.trim())
|
|
79
|
+
.filter(Boolean)
|
|
80
|
+
.map((s) => {
|
|
81
|
+
const n = Number(s);
|
|
82
|
+
if (!Number.isFinite(n)) {
|
|
83
|
+
const err = new Error(`无效的用户 ID: ${s}`);
|
|
84
|
+
err.code = 'VALIDATION_ERROR';
|
|
85
|
+
throw err;
|
|
86
|
+
}
|
|
87
|
+
return n;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
function registerAdminCommands(program) {
|
|
91
|
+
const admin = program.command('admin');
|
|
92
|
+
const user = admin.command('user');
|
|
93
|
+
user
|
|
94
|
+
.command('list')
|
|
95
|
+
.option('--page <n>', '页码', (v) => parseInt(v, 10))
|
|
96
|
+
.option('--page-size <n>', '每页条数', (v) => parseInt(v, 10))
|
|
97
|
+
.action(async (_opts, cmd) => {
|
|
98
|
+
const commandName = 'admin user list';
|
|
99
|
+
try {
|
|
100
|
+
const format = prepareAdmin(program, cmd);
|
|
101
|
+
const o = cmd.opts();
|
|
102
|
+
const client = new admin_1.AdminClient();
|
|
103
|
+
const result = await client.listUsers({
|
|
104
|
+
page: o.page,
|
|
105
|
+
pageSize: o.pageSize,
|
|
106
|
+
});
|
|
107
|
+
(0, output_1.output)(result, format);
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
(0, utils_1.handleError)(err, commandName);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
user
|
|
114
|
+
.command('get')
|
|
115
|
+
.argument('<userId>', '用户 ID', (v) => parseInt(v, 10))
|
|
116
|
+
.action(async (userId, _opts, cmd) => {
|
|
117
|
+
const commandName = 'admin user get';
|
|
118
|
+
try {
|
|
119
|
+
const format = prepareAdmin(program, cmd);
|
|
120
|
+
const client = new admin_1.AdminClient();
|
|
121
|
+
const result = await client.getUser(userId);
|
|
122
|
+
(0, output_1.output)(result, format);
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
(0, utils_1.handleError)(err, commandName);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
user
|
|
129
|
+
.command('activate')
|
|
130
|
+
.argument('<userId>', '用户 ID', (v) => parseInt(v, 10))
|
|
131
|
+
.action(async (userId, _opts, cmd) => {
|
|
132
|
+
const commandName = 'admin user activate';
|
|
133
|
+
try {
|
|
134
|
+
const format = prepareAdmin(program, cmd);
|
|
135
|
+
const client = new admin_1.AdminClient();
|
|
136
|
+
const result = await client.activateUser(userId);
|
|
137
|
+
(0, output_1.output)(result, format);
|
|
138
|
+
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
(0, utils_1.handleError)(err, commandName);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
user
|
|
144
|
+
.command('deactivate')
|
|
145
|
+
.argument('<userId>', '用户 ID', (v) => parseInt(v, 10))
|
|
146
|
+
.action(async (userId, _opts, cmd) => {
|
|
147
|
+
const commandName = 'admin user deactivate';
|
|
148
|
+
try {
|
|
149
|
+
const format = prepareAdmin(program, cmd);
|
|
150
|
+
const client = new admin_1.AdminClient();
|
|
151
|
+
const result = await client.deactivateUser(userId);
|
|
152
|
+
(0, output_1.output)(result, format);
|
|
153
|
+
}
|
|
154
|
+
catch (err) {
|
|
155
|
+
(0, utils_1.handleError)(err, commandName);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
user
|
|
159
|
+
.command('set-role')
|
|
160
|
+
.argument('<userId>', '用户 ID', (v) => parseInt(v, 10))
|
|
161
|
+
.requiredOption('--role-id <n>', '角色 ID', (v) => parseInt(v, 10))
|
|
162
|
+
.action(async (userId, opts, cmd) => {
|
|
163
|
+
const commandName = 'admin user set-role';
|
|
164
|
+
try {
|
|
165
|
+
const format = prepareAdmin(program, cmd);
|
|
166
|
+
const client = new admin_1.AdminClient();
|
|
167
|
+
const result = await client.setUserRole(userId, opts.roleId);
|
|
168
|
+
(0, output_1.output)(result, format);
|
|
169
|
+
}
|
|
170
|
+
catch (err) {
|
|
171
|
+
(0, utils_1.handleError)(err, commandName);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
user
|
|
175
|
+
.command('batch-role')
|
|
176
|
+
.requiredOption('--user-ids <csv>', '用户 ID,逗号分隔')
|
|
177
|
+
.requiredOption('--role-id <n>', '角色 ID', (v) => parseInt(v, 10))
|
|
178
|
+
.action(async (opts, cmd) => {
|
|
179
|
+
const commandName = 'admin user batch-role';
|
|
180
|
+
try {
|
|
181
|
+
const format = prepareAdmin(program, cmd);
|
|
182
|
+
const ids = parseUserIdsList(opts.userIds);
|
|
183
|
+
const client = new admin_1.AdminClient();
|
|
184
|
+
const result = await client.batchSetRole(ids, opts.roleId);
|
|
185
|
+
(0, output_1.output)(result, format);
|
|
186
|
+
}
|
|
187
|
+
catch (err) {
|
|
188
|
+
(0, utils_1.handleError)(err, commandName);
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
const role = admin.command('role');
|
|
192
|
+
role.command('list').action(async (_opts, cmd) => {
|
|
193
|
+
const commandName = 'admin role list';
|
|
194
|
+
try {
|
|
195
|
+
const format = prepareAdmin(program, cmd);
|
|
196
|
+
const client = new admin_1.AdminClient();
|
|
197
|
+
const result = await client.listRoles();
|
|
198
|
+
(0, output_1.output)(result, format);
|
|
199
|
+
}
|
|
200
|
+
catch (err) {
|
|
201
|
+
(0, utils_1.handleError)(err, commandName);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
role
|
|
205
|
+
.command('get')
|
|
206
|
+
.argument('<roleId>', '角色 ID', (v) => parseInt(v, 10))
|
|
207
|
+
.action(async (roleId, _opts, cmd) => {
|
|
208
|
+
const commandName = 'admin role get';
|
|
209
|
+
try {
|
|
210
|
+
const format = prepareAdmin(program, cmd);
|
|
211
|
+
const client = new admin_1.AdminClient();
|
|
212
|
+
const result = await client.getRole(roleId);
|
|
213
|
+
(0, output_1.output)(result, format);
|
|
214
|
+
}
|
|
215
|
+
catch (err) {
|
|
216
|
+
(0, utils_1.handleError)(err, commandName);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
role
|
|
220
|
+
.command('create')
|
|
221
|
+
.requiredOption('--name <name>', '角色名称')
|
|
222
|
+
.option('--permissions <json>', '权限 JSON 对象')
|
|
223
|
+
.action(async (opts, cmd) => {
|
|
224
|
+
const commandName = 'admin role create';
|
|
225
|
+
try {
|
|
226
|
+
const format = prepareAdmin(program, cmd);
|
|
227
|
+
const permissions = opts.permissions
|
|
228
|
+
? parseJson(opts.permissions, 'permissions')
|
|
229
|
+
: undefined;
|
|
230
|
+
const client = new admin_1.AdminClient();
|
|
231
|
+
const result = await client.createRole({
|
|
232
|
+
name: opts.name,
|
|
233
|
+
permissions,
|
|
234
|
+
});
|
|
235
|
+
(0, output_1.output)(result, format);
|
|
236
|
+
}
|
|
237
|
+
catch (err) {
|
|
238
|
+
(0, utils_1.handleError)(err, commandName);
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
role
|
|
242
|
+
.command('update')
|
|
243
|
+
.argument('<roleId>', '角色 ID', (v) => parseInt(v, 10))
|
|
244
|
+
.option('--name <name>', '角色名称')
|
|
245
|
+
.option('--permissions <json>', '权限 JSON 对象')
|
|
246
|
+
.action(async (roleId, opts, cmd) => {
|
|
247
|
+
const commandName = 'admin role update';
|
|
248
|
+
try {
|
|
249
|
+
const format = prepareAdmin(program, cmd);
|
|
250
|
+
const data = {};
|
|
251
|
+
if (opts.name !== undefined)
|
|
252
|
+
data.name = opts.name;
|
|
253
|
+
if (opts.permissions !== undefined) {
|
|
254
|
+
data.permissions = parseJson(opts.permissions, 'permissions');
|
|
255
|
+
}
|
|
256
|
+
const client = new admin_1.AdminClient();
|
|
257
|
+
const result = await client.updateRole(roleId, data);
|
|
258
|
+
(0, output_1.output)(result, format);
|
|
259
|
+
}
|
|
260
|
+
catch (err) {
|
|
261
|
+
(0, utils_1.handleError)(err, commandName);
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
role
|
|
265
|
+
.command('delete')
|
|
266
|
+
.argument('<roleId>', '角色 ID', (v) => parseInt(v, 10))
|
|
267
|
+
.action(async (roleId, _opts, cmd) => {
|
|
268
|
+
const commandName = 'admin role delete';
|
|
269
|
+
try {
|
|
270
|
+
const format = prepareAdmin(program, cmd);
|
|
271
|
+
const client = new admin_1.AdminClient();
|
|
272
|
+
const result = await client.deleteRole(roleId);
|
|
273
|
+
(0, output_1.output)(result, format);
|
|
274
|
+
}
|
|
275
|
+
catch (err) {
|
|
276
|
+
(0, utils_1.handleError)(err, commandName);
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
role.command('user-counts').action(async (_opts, cmd) => {
|
|
280
|
+
const commandName = 'admin role user-counts';
|
|
281
|
+
try {
|
|
282
|
+
const format = prepareAdmin(program, cmd);
|
|
283
|
+
const client = new admin_1.AdminClient();
|
|
284
|
+
const result = await client.getRoleUserCounts();
|
|
285
|
+
(0, output_1.output)(result, format);
|
|
286
|
+
}
|
|
287
|
+
catch (err) {
|
|
288
|
+
(0, utils_1.handleError)(err, commandName);
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
const db = admin.command('db');
|
|
292
|
+
db.command('tables').action(async (_opts, cmd) => {
|
|
293
|
+
const commandName = 'admin db tables';
|
|
294
|
+
try {
|
|
295
|
+
const format = prepareAdmin(program, cmd);
|
|
296
|
+
const client = new admin_1.AdminClient();
|
|
297
|
+
const result = await client.listTables();
|
|
298
|
+
(0, output_1.output)(result, format);
|
|
299
|
+
}
|
|
300
|
+
catch (err) {
|
|
301
|
+
(0, utils_1.handleError)(err, commandName);
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
db
|
|
305
|
+
.command('schema')
|
|
306
|
+
.argument('<tableName>', '表名')
|
|
307
|
+
.action(async (tableName, _opts, cmd) => {
|
|
308
|
+
const commandName = 'admin db schema';
|
|
309
|
+
try {
|
|
310
|
+
const format = prepareAdmin(program, cmd);
|
|
311
|
+
const client = new admin_1.AdminClient();
|
|
312
|
+
const result = await client.getTableSchema(tableName);
|
|
313
|
+
(0, output_1.output)(result, format);
|
|
314
|
+
}
|
|
315
|
+
catch (err) {
|
|
316
|
+
(0, utils_1.handleError)(err, commandName);
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
db
|
|
320
|
+
.command('data')
|
|
321
|
+
.argument('<tableName>', '表名')
|
|
322
|
+
.option('--page <n>', '页码', (v) => parseInt(v, 10))
|
|
323
|
+
.option('--page-size <n>', '每页条数', (v) => parseInt(v, 10))
|
|
324
|
+
.option('--search <q>', '搜索')
|
|
325
|
+
.option('--sort-by <column>', '排序列')
|
|
326
|
+
.option('--sort-order <order>', 'asc | desc')
|
|
327
|
+
.action(async (tableName, opts, cmd) => {
|
|
328
|
+
const commandName = 'admin db data';
|
|
329
|
+
try {
|
|
330
|
+
const format = prepareAdmin(program, cmd);
|
|
331
|
+
const sortOrder = opts.sortOrder;
|
|
332
|
+
if (sortOrder !== undefined &&
|
|
333
|
+
sortOrder !== 'asc' &&
|
|
334
|
+
sortOrder !== 'desc') {
|
|
335
|
+
const err = new Error('sort-order 必须是 asc 或 desc');
|
|
336
|
+
err.code = 'VALIDATION_ERROR';
|
|
337
|
+
throw err;
|
|
338
|
+
}
|
|
339
|
+
const client = new admin_1.AdminClient();
|
|
340
|
+
const result = await client.getTableData(tableName, {
|
|
341
|
+
page: opts.page,
|
|
342
|
+
pageSize: opts.pageSize,
|
|
343
|
+
search: opts.search,
|
|
344
|
+
sortBy: opts.sortBy,
|
|
345
|
+
sortOrder: sortOrder,
|
|
346
|
+
});
|
|
347
|
+
(0, output_1.output)(result, format);
|
|
348
|
+
}
|
|
349
|
+
catch (err) {
|
|
350
|
+
(0, utils_1.handleError)(err, commandName);
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
db
|
|
354
|
+
.command('insert')
|
|
355
|
+
.argument('<tableName>', '表名')
|
|
356
|
+
.requiredOption('--data <json>', '行数据 JSON')
|
|
357
|
+
.action(async (tableName, opts, cmd) => {
|
|
358
|
+
const commandName = 'admin db insert';
|
|
359
|
+
try {
|
|
360
|
+
const format = prepareAdmin(program, cmd);
|
|
361
|
+
const data = parseJson(opts.data, 'data');
|
|
362
|
+
const client = new admin_1.AdminClient();
|
|
363
|
+
const result = await client.insertRow(tableName, data);
|
|
364
|
+
(0, output_1.output)(result, format);
|
|
365
|
+
}
|
|
366
|
+
catch (err) {
|
|
367
|
+
(0, utils_1.handleError)(err, commandName);
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
db
|
|
371
|
+
.command('update')
|
|
372
|
+
.argument('<tableName>', '表名')
|
|
373
|
+
.requiredOption('--primary-key <json>', '主键 JSON')
|
|
374
|
+
.requiredOption('--data <json>', '更新字段 JSON')
|
|
375
|
+
.action(async (tableName, opts, cmd) => {
|
|
376
|
+
const commandName = 'admin db update';
|
|
377
|
+
try {
|
|
378
|
+
const format = prepareAdmin(program, cmd);
|
|
379
|
+
const primaryKey = parseJson(opts.primaryKey, 'primary-key');
|
|
380
|
+
const data = parseJson(opts.data, 'data');
|
|
381
|
+
const client = new admin_1.AdminClient();
|
|
382
|
+
const result = await client.updateRow(tableName, primaryKey, data);
|
|
383
|
+
(0, output_1.output)(result, format);
|
|
384
|
+
}
|
|
385
|
+
catch (err) {
|
|
386
|
+
(0, utils_1.handleError)(err, commandName);
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
db
|
|
390
|
+
.command('delete')
|
|
391
|
+
.argument('<tableName>', '表名')
|
|
392
|
+
.requiredOption('--primary-key <json>', '主键 JSON')
|
|
393
|
+
.action(async (tableName, opts, cmd) => {
|
|
394
|
+
const commandName = 'admin db delete';
|
|
395
|
+
try {
|
|
396
|
+
const format = prepareAdmin(program, cmd);
|
|
397
|
+
const primaryKey = parseJson(opts.primaryKey, 'primary-key');
|
|
398
|
+
const client = new admin_1.AdminClient();
|
|
399
|
+
const result = await client.deleteRow(tableName, primaryKey);
|
|
400
|
+
(0, output_1.output)(result, format);
|
|
401
|
+
}
|
|
402
|
+
catch (err) {
|
|
403
|
+
(0, utils_1.handleError)(err, commandName);
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
db
|
|
407
|
+
.command('exec-sql')
|
|
408
|
+
.option('--sql <sql>', 'SQL 语句')
|
|
409
|
+
.option('--file <path>', '从文件读取 SQL')
|
|
410
|
+
.option('--description <text>', '描述')
|
|
411
|
+
.action(async (opts, cmd) => {
|
|
412
|
+
const commandName = 'admin db exec-sql';
|
|
413
|
+
try {
|
|
414
|
+
const format = prepareAdmin(program, cmd);
|
|
415
|
+
let sql = opts.sql?.trim() ?? '';
|
|
416
|
+
if (opts.file) {
|
|
417
|
+
const abs = path.resolve(opts.file);
|
|
418
|
+
if (!fs.existsSync(abs)) {
|
|
419
|
+
throw new Error(`文件不存在: ${abs}`);
|
|
420
|
+
}
|
|
421
|
+
sql = fs.readFileSync(abs, 'utf-8').trim();
|
|
422
|
+
}
|
|
423
|
+
(0, utils_1.requireOption)(sql, 'sql');
|
|
424
|
+
const client = new admin_1.AdminClient();
|
|
425
|
+
const result = await client.executeSql({
|
|
426
|
+
sql,
|
|
427
|
+
description: opts.description,
|
|
428
|
+
});
|
|
429
|
+
(0, output_1.output)(result, format);
|
|
430
|
+
}
|
|
431
|
+
catch (err) {
|
|
432
|
+
(0, utils_1.handleError)(err, commandName);
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
db
|
|
436
|
+
.command('sql-history')
|
|
437
|
+
.option('--page <n>', '页码', (v) => parseInt(v, 10))
|
|
438
|
+
.option('--page-size <n>', '每页条数', (v) => parseInt(v, 10))
|
|
439
|
+
.action(async (_opts, cmd) => {
|
|
440
|
+
const commandName = 'admin db sql-history';
|
|
441
|
+
try {
|
|
442
|
+
const format = prepareAdmin(program, cmd);
|
|
443
|
+
const o = cmd.opts();
|
|
444
|
+
const client = new admin_1.AdminClient();
|
|
445
|
+
const result = await client.getSqlHistory({
|
|
446
|
+
page: o.page,
|
|
447
|
+
pageSize: o.pageSize,
|
|
448
|
+
});
|
|
449
|
+
(0, output_1.output)(result, format);
|
|
450
|
+
}
|
|
451
|
+
catch (err) {
|
|
452
|
+
(0, utils_1.handleError)(err, commandName);
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerAuthCommands = registerAuthCommands;
|
|
4
|
+
const auth_1 = require("../../auth");
|
|
5
|
+
const config_1 = require("../../config");
|
|
6
|
+
const login_1 = require("../../login");
|
|
7
|
+
const config_2 = require("../config");
|
|
8
|
+
const output_1 = require("../output");
|
|
9
|
+
const utils_1 = require("../utils");
|
|
10
|
+
function resetSdkAuthState() {
|
|
11
|
+
const s = config_1.sdkConfig;
|
|
12
|
+
s._authenticated = null;
|
|
13
|
+
s._authCheckPromise = null;
|
|
14
|
+
s._currentUser = null;
|
|
15
|
+
}
|
|
16
|
+
function applyRootDebug(program) {
|
|
17
|
+
const root = program.opts();
|
|
18
|
+
if (root.debug) {
|
|
19
|
+
config_1.sdkConfig.setDebug(true);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function registerAuthCommands(program) {
|
|
23
|
+
program
|
|
24
|
+
.command('login')
|
|
25
|
+
.description('登录 AI World(浏览器 OAuth 或直接设置 token)')
|
|
26
|
+
.option('--token <jwt>', '直接设置 JWT token')
|
|
27
|
+
.option('--timeout <ms>', 'OAuth 超时毫秒数', (v) => parseInt(v, 10))
|
|
28
|
+
.action(async (opts) => {
|
|
29
|
+
try {
|
|
30
|
+
applyRootDebug(program);
|
|
31
|
+
const root = program.opts();
|
|
32
|
+
const resolvedBase = (0, config_2.resolveAuth)({
|
|
33
|
+
baseUrl: root.baseUrl,
|
|
34
|
+
token: root.token,
|
|
35
|
+
pluginId: root.pluginId,
|
|
36
|
+
}).baseUrl;
|
|
37
|
+
if (opts.token) {
|
|
38
|
+
(0, config_2.setConfigValues)({ token: opts.token, 'base-url': resolvedBase });
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
const result = await (0, login_1.performLogin)({
|
|
42
|
+
baseUrl: resolvedBase,
|
|
43
|
+
timeout: opts.timeout,
|
|
44
|
+
});
|
|
45
|
+
(0, config_2.setConfigValues)({ token: result.token, 'base-url': result.baseUrl });
|
|
46
|
+
}
|
|
47
|
+
const merged = (0, config_2.resolveAuth)({
|
|
48
|
+
baseUrl: root.baseUrl,
|
|
49
|
+
pluginId: root.pluginId,
|
|
50
|
+
});
|
|
51
|
+
(0, utils_1.initSDK)(merged);
|
|
52
|
+
const pluginId = await (0, utils_1.resolvePluginIdDefault)(merged);
|
|
53
|
+
const format = (0, utils_1.getFormat)(program);
|
|
54
|
+
(0, output_1.output)({ ok: true, baseUrl: merged.baseUrl, pluginId: pluginId ?? merged.pluginId }, format);
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
(0, utils_1.handleError)(e, 'login');
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
program
|
|
61
|
+
.command('logout')
|
|
62
|
+
.description('退出登录(清除缓存 token)')
|
|
63
|
+
.action(() => {
|
|
64
|
+
try {
|
|
65
|
+
const cfg = (0, config_2.readConfig)();
|
|
66
|
+
delete cfg.token;
|
|
67
|
+
(0, config_2.writeConfig)(cfg);
|
|
68
|
+
const format = (0, utils_1.getFormat)(program);
|
|
69
|
+
(0, output_1.output)({ ok: true, loggedOut: true }, format);
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
(0, utils_1.handleError)(e, 'logout');
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
program
|
|
76
|
+
.command('me')
|
|
77
|
+
.description('查看当前用户信息')
|
|
78
|
+
.action(async () => {
|
|
79
|
+
try {
|
|
80
|
+
applyRootDebug(program);
|
|
81
|
+
const merged = (0, config_2.resolveAuth)(program.opts());
|
|
82
|
+
resetSdkAuthState();
|
|
83
|
+
(0, utils_1.initSDK)(merged);
|
|
84
|
+
const client = new auth_1.AuthClient();
|
|
85
|
+
const user = await client.getCurrentUserInfo();
|
|
86
|
+
const format = (0, utils_1.getFormat)(program);
|
|
87
|
+
(0, output_1.output)(user, format);
|
|
88
|
+
}
|
|
89
|
+
catch (e) {
|
|
90
|
+
(0, utils_1.handleError)(e, 'me');
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
program
|
|
94
|
+
.command('status')
|
|
95
|
+
.description('检查认证状态')
|
|
96
|
+
.action(async () => {
|
|
97
|
+
try {
|
|
98
|
+
applyRootDebug(program);
|
|
99
|
+
const merged = (0, config_2.resolveAuth)(program.opts());
|
|
100
|
+
resetSdkAuthState();
|
|
101
|
+
(0, utils_1.initSDK)(merged);
|
|
102
|
+
const ok = await config_1.sdkConfig.checkAuthentication();
|
|
103
|
+
const format = (0, utils_1.getFormat)(program);
|
|
104
|
+
const payload = {
|
|
105
|
+
authenticated: ok,
|
|
106
|
+
baseUrl: merged.baseUrl,
|
|
107
|
+
user: ok ? config_1.sdkConfig.getCurrentUser() : null,
|
|
108
|
+
};
|
|
109
|
+
if (format === 'table') {
|
|
110
|
+
(0, output_1.output)(payload, 'table');
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
(0, output_1.outputJSON)(payload);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
catch (e) {
|
|
117
|
+
(0, utils_1.handleError)(e, 'status');
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|