@lark-apaas/miaoda-cli 0.1.3-alpha.4bf312e → 0.1.3-alpha.67da0bb
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/api/app/api.js +3 -3
- package/dist/api/app/schemas.js +43 -43
- package/dist/api/db/api.js +108 -112
- package/dist/api/db/client.js +41 -41
- package/dist/api/db/parsers.js +20 -20
- package/dist/api/db/sql-keywords.js +87 -87
- package/dist/api/deploy/api.js +5 -5
- package/dist/api/deploy/schemas.js +32 -32
- package/dist/api/file/api.js +74 -87
- package/dist/api/file/client.js +22 -22
- package/dist/api/file/detect.js +3 -3
- package/dist/api/file/parsers.js +18 -7
- package/dist/api/observability/api.js +6 -6
- package/dist/api/observability/schemas.js +14 -14
- package/dist/api/plugin/api.js +31 -31
- package/dist/cli/commands/app/index.js +12 -12
- package/dist/cli/commands/db/index.js +268 -163
- package/dist/cli/commands/deploy/index.js +28 -28
- package/dist/cli/commands/file/index.js +81 -61
- package/dist/cli/commands/observability/index.js +69 -69
- package/dist/cli/commands/plugin/index.js +27 -27
- package/dist/cli/commands/shared.js +10 -10
- package/dist/cli/handlers/app/update.js +2 -2
- package/dist/cli/handlers/db/audit.js +52 -43
- package/dist/cli/handlers/db/changelog.js +25 -12
- package/dist/cli/handlers/db/data.js +31 -30
- package/dist/cli/handlers/db/migration.js +27 -27
- package/dist/cli/handlers/db/quota.js +3 -3
- package/dist/cli/handlers/db/recovery.js +111 -82
- package/dist/cli/handlers/db/schema.js +33 -33
- package/dist/cli/handlers/db/sql.js +69 -69
- package/dist/cli/handlers/deploy/deploy.js +4 -4
- package/dist/cli/handlers/deploy/error-log.js +1 -1
- package/dist/cli/handlers/deploy/get.js +3 -3
- package/dist/cli/handlers/deploy/polling.js +11 -11
- package/dist/cli/handlers/file/cp.js +30 -30
- package/dist/cli/handlers/file/ls.js +5 -5
- package/dist/cli/handlers/file/quota.js +2 -2
- package/dist/cli/handlers/file/rm.js +24 -24
- package/dist/cli/handlers/file/sign.js +3 -3
- package/dist/cli/handlers/file/stat.js +10 -9
- package/dist/cli/handlers/observability/analytics.js +47 -47
- package/dist/cli/handlers/observability/helpers.js +2 -2
- package/dist/cli/handlers/observability/log.js +9 -9
- package/dist/cli/handlers/observability/metric.js +26 -26
- package/dist/cli/handlers/observability/trace.js +5 -5
- package/dist/cli/handlers/plugin/plugin-local.js +53 -53
- package/dist/cli/handlers/plugin/plugin.js +15 -15
- package/dist/cli/help.js +16 -16
- package/dist/main.js +12 -12
- package/dist/utils/args.js +1 -1
- package/dist/utils/colors.js +2 -2
- package/dist/utils/config.js +2 -2
- package/dist/utils/devops-error.js +9 -9
- package/dist/utils/error.js +2 -2
- package/dist/utils/git.js +4 -4
- package/dist/utils/http.js +19 -19
- package/dist/utils/output.js +47 -47
- package/dist/utils/poll.js +2 -2
- package/dist/utils/render.js +27 -27
- package/dist/utils/time.js +47 -42
- package/package.json +1 -1
|
@@ -5,30 +5,30 @@ const output_1 = require("../../utils/output");
|
|
|
5
5
|
/** LogItem 渲染契约(log search) */
|
|
6
6
|
exports.logItemSchema = {
|
|
7
7
|
columns: [
|
|
8
|
-
{ key:
|
|
8
|
+
{ key: 'timestampNs', label: 'time', format: output_1.fmt.ns('yyyy-MM-dd HH:mm:ss.SSS') },
|
|
9
9
|
{
|
|
10
|
-
key:
|
|
10
|
+
key: 'module',
|
|
11
11
|
derive: (row) => {
|
|
12
12
|
return row.attributes?.module;
|
|
13
13
|
},
|
|
14
14
|
},
|
|
15
15
|
{
|
|
16
|
-
key:
|
|
16
|
+
key: 'user-id',
|
|
17
17
|
derive: (row) => {
|
|
18
18
|
return row.attributes?.user_id;
|
|
19
19
|
},
|
|
20
20
|
},
|
|
21
|
-
{ key:
|
|
21
|
+
{ key: 'severityText', label: 'severity-text' },
|
|
22
22
|
{
|
|
23
|
-
key:
|
|
23
|
+
key: 'duration',
|
|
24
24
|
format: output_1.fmt.durationMs(),
|
|
25
25
|
derive: (row) => {
|
|
26
26
|
return row.attributes?.duration_ms;
|
|
27
27
|
},
|
|
28
28
|
},
|
|
29
|
-
{ key:
|
|
30
|
-
{ key:
|
|
31
|
-
{ key:
|
|
29
|
+
{ key: 'traceID', label: 'trace-id' },
|
|
30
|
+
{ key: 'id', label: 'log-id' },
|
|
31
|
+
{ key: 'body' },
|
|
32
32
|
],
|
|
33
33
|
strict: true,
|
|
34
34
|
};
|
|
@@ -36,23 +36,23 @@ exports.logItemSchema = {
|
|
|
36
36
|
* duration 是 client-derived(BAM 只给 start/end,没有原生 durationNs 字段)。 */
|
|
37
37
|
exports.spanSchema = {
|
|
38
38
|
columns: [
|
|
39
|
-
{ key:
|
|
40
|
-
{ key:
|
|
39
|
+
{ key: 'startTimeUnixNano', label: 'start-time', format: output_1.fmt.ns('yyyy-MM-dd HH:mm:ss.SSS') },
|
|
40
|
+
{ key: 'name', label: 'root-span' },
|
|
41
41
|
{
|
|
42
|
-
key:
|
|
42
|
+
key: 'user-id',
|
|
43
43
|
derive: (row) => {
|
|
44
44
|
return row.attributes?.user_id;
|
|
45
45
|
},
|
|
46
46
|
},
|
|
47
47
|
{
|
|
48
|
-
key:
|
|
49
|
-
label:
|
|
48
|
+
key: 'duration',
|
|
49
|
+
label: 'duration',
|
|
50
50
|
format: output_1.fmt.durationMs(),
|
|
51
51
|
derive: (row) => {
|
|
52
52
|
return row.attributes?.duration_ms;
|
|
53
53
|
},
|
|
54
54
|
},
|
|
55
|
-
{ key:
|
|
55
|
+
{ key: 'traceID', label: 'trace-id' },
|
|
56
56
|
],
|
|
57
57
|
strict: true,
|
|
58
58
|
};
|
package/dist/api/plugin/api.js
CHANGED
|
@@ -23,23 +23,23 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
|
23
23
|
// ── Plugin Version API ──
|
|
24
24
|
async function getPluginVersions(keys, latestOnly = true) {
|
|
25
25
|
const client = (0, http_1.getRuntimeHttpClient)();
|
|
26
|
-
const response = await client.post(`/api/v1/studio/innerapi/plugins/-/versions/batch_get?keys=${keys.join(
|
|
26
|
+
const response = await client.post(`/api/v1/studio/innerapi/plugins/-/versions/batch_get?keys=${keys.join(',')}&latest_only=${String(latestOnly)}`);
|
|
27
27
|
if (!response.ok) {
|
|
28
28
|
throw new error_1.HttpError(response.status, response.url, `Failed to get plugin versions: ${String(response.status)} ${response.statusText}`);
|
|
29
29
|
}
|
|
30
30
|
const result = (await response.json());
|
|
31
|
-
if (result.status_code !==
|
|
32
|
-
throw new error_1.AppError(
|
|
31
|
+
if (result.status_code !== '0') {
|
|
32
|
+
throw new error_1.AppError('INTERNAL_API_ERROR', `API error: ${result.message ?? 'unknown'}`);
|
|
33
33
|
}
|
|
34
34
|
return result.data.pluginVersions;
|
|
35
35
|
}
|
|
36
36
|
async function getPluginVersion(pluginKey, requestedVersion) {
|
|
37
|
-
const isLatest = requestedVersion ===
|
|
37
|
+
const isLatest = requestedVersion === 'latest';
|
|
38
38
|
const versions = await getPluginVersions([pluginKey], isLatest);
|
|
39
39
|
const pluginVersions = versions[pluginKey];
|
|
40
40
|
if (!pluginVersions || pluginVersions.length === 0) {
|
|
41
|
-
throw new error_1.AppError(
|
|
42
|
-
next_actions: [
|
|
41
|
+
throw new error_1.AppError('PLUGIN_NOT_FOUND', `Plugin not found: ${pluginKey}`, {
|
|
42
|
+
next_actions: ['检查包名拼写,或确认该插件已在插件市场发布'],
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
if (isLatest) {
|
|
@@ -47,7 +47,7 @@ async function getPluginVersion(pluginKey, requestedVersion) {
|
|
|
47
47
|
}
|
|
48
48
|
const targetVersion = pluginVersions.find((v) => v.version === requestedVersion);
|
|
49
49
|
if (!targetVersion) {
|
|
50
|
-
throw new error_1.AppError(
|
|
50
|
+
throw new error_1.AppError('VERSION_NOT_FOUND', `Version ${requestedVersion} not found for plugin ${pluginKey}`, { next_actions: [`可用版本:${pluginVersions.map((v) => v.version).join(', ')}`] });
|
|
51
51
|
}
|
|
52
52
|
return targetVersion;
|
|
53
53
|
}
|
|
@@ -55,8 +55,8 @@ async function getPluginVersion(pluginKey, requestedVersion) {
|
|
|
55
55
|
function parsePluginKey(key) {
|
|
56
56
|
const match = /^(@[^/]+)\/(.+)$/.exec(key);
|
|
57
57
|
if (!match) {
|
|
58
|
-
throw new error_1.AppError(
|
|
59
|
-
next_actions: [
|
|
58
|
+
throw new error_1.AppError('INVALID_PLUGIN_KEY', `Invalid plugin key format: ${key}`, {
|
|
59
|
+
next_actions: ['插件 key 必须形如 @scope/name'],
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
62
|
return { scope: match[1], name: match[2] };
|
|
@@ -91,15 +91,15 @@ async function withRetry(operation, description, maxRetries = MAX_RETRIES) {
|
|
|
91
91
|
catch (error) {
|
|
92
92
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
93
93
|
if (attempt < maxRetries) {
|
|
94
|
-
(0, logger_1.log)(
|
|
94
|
+
(0, logger_1.log)('plugin', `${description} failed, retrying (${String(attempt + 1)}/${String(maxRetries)})...`);
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
throw (lastError ??
|
|
99
|
-
new error_1.AppError(
|
|
99
|
+
new error_1.AppError('INTERNAL_RETRY_EXHAUSTED', `${description} failed after ${String(maxRetries)} retries`, { retryable: true, next_actions: ['检查网络后重试,--verbose 可查看重试日志'] }));
|
|
100
100
|
}
|
|
101
101
|
/** 插件缓存目录 */
|
|
102
|
-
const PLUGIN_CACHE_DIR =
|
|
102
|
+
const PLUGIN_CACHE_DIR = 'node_modules/.cache/miaoda-cli/plugins';
|
|
103
103
|
function getPluginCacheDir() {
|
|
104
104
|
return node_path_1.default.join(process.cwd(), PLUGIN_CACHE_DIR);
|
|
105
105
|
}
|
|
@@ -111,18 +111,18 @@ function ensureCacheDir() {
|
|
|
111
111
|
}
|
|
112
112
|
function getTempFilePath(pluginKey, version) {
|
|
113
113
|
ensureCacheDir();
|
|
114
|
-
const safeKey = pluginKey.replace(/[/@]/g,
|
|
114
|
+
const safeKey = pluginKey.replace(/[/@]/g, '_');
|
|
115
115
|
const filename = `${safeKey}@${version}.tgz`;
|
|
116
116
|
return node_path_1.default.join(getPluginCacheDir(), filename);
|
|
117
117
|
}
|
|
118
118
|
async function downloadPlugin(pluginKey, requestedVersion) {
|
|
119
119
|
const pluginInfo = await getPluginVersion(pluginKey, requestedVersion);
|
|
120
120
|
let tgzBuffer;
|
|
121
|
-
if (pluginInfo.downloadApproach ===
|
|
122
|
-
tgzBuffer = await withRetry(() => downloadFromInner(pluginKey, pluginInfo.version),
|
|
121
|
+
if (pluginInfo.downloadApproach === 'inner') {
|
|
122
|
+
tgzBuffer = await withRetry(() => downloadFromInner(pluginKey, pluginInfo.version), 'Download');
|
|
123
123
|
}
|
|
124
124
|
else {
|
|
125
|
-
tgzBuffer = await withRetry(() => downloadFromPublic(pluginInfo.downloadURL),
|
|
125
|
+
tgzBuffer = await withRetry(() => downloadFromPublic(pluginInfo.downloadURL), 'Download');
|
|
126
126
|
}
|
|
127
127
|
const tgzPath = getTempFilePath(pluginKey, pluginInfo.version);
|
|
128
128
|
node_fs_1.default.writeFileSync(tgzPath, tgzBuffer);
|
|
@@ -135,7 +135,7 @@ async function downloadPlugin(pluginKey, requestedVersion) {
|
|
|
135
135
|
// ── Cache ──
|
|
136
136
|
function getCachePath(pluginKey, version) {
|
|
137
137
|
ensureCacheDir();
|
|
138
|
-
const safeKey = pluginKey.replace(/[/@]/g,
|
|
138
|
+
const safeKey = pluginKey.replace(/[/@]/g, '_');
|
|
139
139
|
const filename = `${safeKey}@${version}.tgz`;
|
|
140
140
|
return node_path_1.default.join(getPluginCacheDir(), filename);
|
|
141
141
|
}
|
|
@@ -151,13 +151,13 @@ function listCachedPlugins() {
|
|
|
151
151
|
const files = node_fs_1.default.readdirSync(cacheDir);
|
|
152
152
|
const result = [];
|
|
153
153
|
for (const file of files) {
|
|
154
|
-
if (!file.endsWith(
|
|
154
|
+
if (!file.endsWith('.tgz'))
|
|
155
155
|
continue;
|
|
156
156
|
const match = /^(.+)@(.+)\.tgz$/.exec(file);
|
|
157
157
|
if (!match)
|
|
158
158
|
continue;
|
|
159
159
|
const [, rawName, version] = match;
|
|
160
|
-
const name = rawName.replace(/^_/,
|
|
160
|
+
const name = rawName.replace(/^_/, '@').replace(/_/, '/');
|
|
161
161
|
const filePath = node_path_1.default.join(cacheDir, file);
|
|
162
162
|
const stat = node_fs_1.default.statSync(filePath);
|
|
163
163
|
result.push({ name, version, filePath, size: stat.size, mtime: stat.mtime });
|
|
@@ -172,7 +172,7 @@ function cleanAllCache() {
|
|
|
172
172
|
const files = node_fs_1.default.readdirSync(cacheDir);
|
|
173
173
|
let count = 0;
|
|
174
174
|
for (const file of files) {
|
|
175
|
-
if (file.endsWith(
|
|
175
|
+
if (file.endsWith('.tgz')) {
|
|
176
176
|
node_fs_1.default.unlinkSync(node_path_1.default.join(cacheDir, file));
|
|
177
177
|
count++;
|
|
178
178
|
}
|
|
@@ -184,7 +184,7 @@ function cleanPluginCache(pluginKey, version) {
|
|
|
184
184
|
if (!node_fs_1.default.existsSync(cacheDir)) {
|
|
185
185
|
return 0;
|
|
186
186
|
}
|
|
187
|
-
const safeKey = pluginKey.replace(/[/@]/g,
|
|
187
|
+
const safeKey = pluginKey.replace(/[/@]/g, '_');
|
|
188
188
|
const files = node_fs_1.default.readdirSync(cacheDir);
|
|
189
189
|
let count = 0;
|
|
190
190
|
for (const file of files) {
|
|
@@ -195,7 +195,7 @@ function cleanPluginCache(pluginKey, version) {
|
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
197
|
else {
|
|
198
|
-
if (file.startsWith(`${safeKey}@`) && file.endsWith(
|
|
198
|
+
if (file.startsWith(`${safeKey}@`) && file.endsWith('.tgz')) {
|
|
199
199
|
node_fs_1.default.unlinkSync(node_path_1.default.join(cacheDir, file));
|
|
200
200
|
count++;
|
|
201
201
|
}
|
|
@@ -209,29 +209,29 @@ async function reportEvents(events) {
|
|
|
209
209
|
return true;
|
|
210
210
|
try {
|
|
211
211
|
const client = (0, http_1.getRuntimeHttpClient)();
|
|
212
|
-
const response = await client.post(
|
|
212
|
+
const response = await client.post('/api/v1/studio/innerapi/resource_events', { events });
|
|
213
213
|
if (!response.ok) {
|
|
214
|
-
(0, logger_1.log)(
|
|
214
|
+
(0, logger_1.log)('telemetry', `Failed to report events: ${String(response.status)} ${response.statusText}`);
|
|
215
215
|
return false;
|
|
216
216
|
}
|
|
217
217
|
const result = (await response.json());
|
|
218
|
-
if (result.status_code !==
|
|
219
|
-
(0, logger_1.log)(
|
|
218
|
+
if (result.status_code !== '0') {
|
|
219
|
+
(0, logger_1.log)('telemetry', `API error: ${result.message ?? 'unknown'}`);
|
|
220
220
|
return false;
|
|
221
221
|
}
|
|
222
222
|
return true;
|
|
223
223
|
}
|
|
224
224
|
catch (error) {
|
|
225
|
-
(0, logger_1.log)(
|
|
225
|
+
(0, logger_1.log)('telemetry', `Failed to report events: ${error instanceof Error ? error.message : String(error)}`);
|
|
226
226
|
return false;
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
229
|
async function reportInstallEvent(pluginKey, version) {
|
|
230
230
|
await reportEvents([
|
|
231
231
|
{
|
|
232
|
-
resourceType:
|
|
232
|
+
resourceType: 'plugin',
|
|
233
233
|
resourceKey: pluginKey,
|
|
234
|
-
eventType:
|
|
234
|
+
eventType: 'install',
|
|
235
235
|
details: { version },
|
|
236
236
|
},
|
|
237
237
|
]);
|
|
@@ -239,9 +239,9 @@ async function reportInstallEvent(pluginKey, version) {
|
|
|
239
239
|
async function reportCreateInstanceEvent(pluginKey, version) {
|
|
240
240
|
await reportEvents([
|
|
241
241
|
{
|
|
242
|
-
resourceType:
|
|
242
|
+
resourceType: 'plugin',
|
|
243
243
|
resourceKey: pluginKey,
|
|
244
|
-
eventType:
|
|
244
|
+
eventType: 'create_instance',
|
|
245
245
|
details: { version },
|
|
246
246
|
},
|
|
247
247
|
]);
|
|
@@ -4,11 +4,11 @@ exports.registerAppCommands = registerAppCommands;
|
|
|
4
4
|
const shared_1 = require("../../../cli/commands/shared");
|
|
5
5
|
const index_1 = require("../../../cli/handlers/app/index");
|
|
6
6
|
function registerAppCommands(program) {
|
|
7
|
-
const appCmd = program.command(
|
|
7
|
+
const appCmd = program.command('app').description('应用元数据管理:查看 / 修改');
|
|
8
8
|
appCmd.action(() => {
|
|
9
9
|
appCmd.outputHelp();
|
|
10
10
|
});
|
|
11
|
-
appCmd.addHelpText(
|
|
11
|
+
appCmd.addHelpText('after', `
|
|
12
12
|
作用范围
|
|
13
13
|
仅供 Agent 在妙搭沙箱内调用。
|
|
14
14
|
应用上下文:沙箱内的默认应用。
|
|
@@ -18,10 +18,10 @@ function registerAppCommands(program) {
|
|
|
18
18
|
}
|
|
19
19
|
function registerAppGet(parent) {
|
|
20
20
|
const cmd = parent
|
|
21
|
-
.command(
|
|
22
|
-
.description(
|
|
21
|
+
.command('get')
|
|
22
|
+
.description('查看应用元数据(status / type / mode / branch / 时间戳 等)')
|
|
23
23
|
.addOption((0, shared_1.appIdOption)().hideHelp())
|
|
24
|
-
.addHelpText(
|
|
24
|
+
.addHelpText('after', `
|
|
25
25
|
JSON 输出
|
|
26
26
|
{"data": {"appID": "...", "name": "...", ...}}
|
|
27
27
|
|
|
@@ -30,7 +30,7 @@ JSON 输出
|
|
|
30
30
|
$ miaoda app get --json
|
|
31
31
|
`);
|
|
32
32
|
cmd.action((0, shared_1.withHelp)(cmd, async (rawOpts) => {
|
|
33
|
-
(0, shared_1.rejectCliOverride)(cmd,
|
|
33
|
+
(0, shared_1.rejectCliOverride)(cmd, 'appId');
|
|
34
34
|
await (0, index_1.handleAppGet)({
|
|
35
35
|
appId: (0, shared_1.resolveAppId)({ appId: rawOpts.appId }),
|
|
36
36
|
});
|
|
@@ -38,12 +38,12 @@ JSON 输出
|
|
|
38
38
|
}
|
|
39
39
|
function registerAppUpdate(parent) {
|
|
40
40
|
const cmd = parent
|
|
41
|
-
.command(
|
|
42
|
-
.description(
|
|
41
|
+
.command('update')
|
|
42
|
+
.description('修改应用名称 / 描述(至少传 --name 或 --description)')
|
|
43
43
|
.addOption((0, shared_1.appIdOption)().hideHelp())
|
|
44
|
-
.option(
|
|
45
|
-
.option(
|
|
46
|
-
.addHelpText(
|
|
44
|
+
.option('--name <name>', '新应用名称')
|
|
45
|
+
.option('--description <desc>', '新应用描述')
|
|
46
|
+
.addHelpText('after', `
|
|
47
47
|
JSON 输出
|
|
48
48
|
与 'app get' 一致:{"data": {...新 meta...}}
|
|
49
49
|
|
|
@@ -52,7 +52,7 @@ JSON 输出
|
|
|
52
52
|
$ miaoda app update --description "在线商城应用"
|
|
53
53
|
`);
|
|
54
54
|
cmd.action((0, shared_1.withHelp)(cmd, async (rawOpts) => {
|
|
55
|
-
(0, shared_1.rejectCliOverride)(cmd,
|
|
55
|
+
(0, shared_1.rejectCliOverride)(cmd, 'appId');
|
|
56
56
|
await (0, index_1.handleAppUpdate)({
|
|
57
57
|
appId: (0, shared_1.resolveAppId)({ appId: rawOpts.appId }),
|
|
58
58
|
name: rawOpts.name,
|