Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ Once installed, just describe your task to your AI Agent — no need to assemble
| Image & video generation | "Generate an image of a cat in a spacesuit on Mars, then turn it into a video." |
| Speech recognition | "Transcribe this audio; if proper nouns are wrong, add hot words and try again." |
| Usage & quota | "Show my recent model usage, free-tier quota, and rate limits." |
| Monitoring & alerts | "Show my model call stats, failures and logs, and create an alert rule." |
| Model selection | "Recommend a model for image understanding and customer support." |
| About Bailian CLI | "Tell me what Bailian CLI can do for me, and suggest how to use it for my needs." |

Expand Down
1 change: 1 addition & 0 deletions README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ irm https://bailian.aliyun.com/cli/install.ps1 | iex
| 图片和视频生成 | “生成一张穿着太空服的猫站在火星上的图片,再把它制作成一段视频。” |
| 语音识别 | “把这段音频转写成文字,专有名词识别不准的话帮我加上热词再试。” |
| 用量与额度 | “查看最近的模型用量、免费额度和限流情况。” |
| 监控与告警 | “查看我的模型调用统计、失败明细和调用日志,并创建一条告警规则。” |
| 模型选型 | “推荐一个适合图片理解和智能客服的模型。” |
| 了解 Bailian CLI | “介绍一下 Bailian CLI 能帮我完成哪些任务,并根据我的需求推荐使用方式。” |

Expand Down
1 change: 1 addition & 0 deletions docs/agents/command-add-remove.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ packages/commands/src/index.ts
- `commands/auth/**` 可用 `ctx.authStore`,`commands/config/**` 可用 `ctx.configStore`;不要把这些持久化能力扩散到普通业务命令
- `commands/plugin/**` 可用 `ctx.commandPacks`;产品 policy 由 runtime 绑定,命令不要自行 import 产品入口
- [ ] 用户可见 Help 文案在命令文件中就近提供 `en-US` / `zh-CN`:命令 `description`、flag `description`、`notes` 和包含自然语言的 `exampleArgs`;纯命令语法示例可保留为字符串,服务端错误不翻译
- [ ] 如果命令执行不可逆的删除/销毁(远端资源删除、永久移除),必须提供 `yes` switch flag,并在 `run` 中于 `dry-run` 分支之后、任何网络调用之前调用 runtime 的 `confirmDangerousAction(summary, flags.yes ?? false)`(参考 `knowledge/*-delete.ts`);`--yes` 的 flag description 用「Skip the confirmation prompt / 跳过确认提示」,`notes` 里声明不可撤销
- [ ] `packages/commands/src/index.ts`:新增或移除对应 export
- [ ] 如果命令调用 Console Gateway,设置 `auth: "console"`;不要重复声明 console 凭证域 flags
- [ ] 如果命令不需要网络或自己管理配置/登录,设置 `auth: "none"`;不要绕过 runtime auth stage
Expand Down
70 changes: 70 additions & 0 deletions packages/cli/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,47 @@ import {
pipelineValidate,
advisorRecommend,
modelList,
modelSearch,
modelCode,
workspaceList,
quotaList,
quotaUpdate,
quotaDelete,
quotaHistory,
quotaCheck,
monitorOverview,
monitorModels,
monitorMetrics,
monitorErrors,
monitorDeliveryStatus,
monitorDeliveryEnable,
monitorDeliveryDisable,
logStatus,
logAuditList,
logAuditGet,
logAuditCount,
logAuditEnable,
logAuditDisable,
logInferenceList,
logInferenceGet,
logInferenceCount,
logInferenceEnable,
logInferenceDisable,
logTraceList,
logTraceGet,
logTraceStats,
alertMetrics,
alertTemplateList,
alertTemplateCreate,
alertTemplateUpdate,
alertTemplateDelete,
alertList,
alertCreate,
alertUpdate,
alertDelete,
alertEnable,
alertDisable,
alertHistory,
permissionList,
permissionGrant,
permissionRevoke,
Expand Down Expand Up @@ -324,12 +359,47 @@ export const commands: Record<string, AnyCommand> = {
"pipeline validate": pipelineValidate,
"advisor recommend": advisorRecommend,
"model list": modelList,
"model search": modelSearch,
"model code": modelCode,
"workspace list": workspaceList,
"quota list": quotaList,
"quota update": quotaUpdate,
"quota delete": quotaDelete,
"quota history": quotaHistory,
"quota check": quotaCheck,
"monitor overview": monitorOverview,
"monitor models": monitorModels,
"monitor metrics": monitorMetrics,
"monitor errors": monitorErrors,
"monitor delivery status": monitorDeliveryStatus,
"monitor delivery enable": monitorDeliveryEnable,
"monitor delivery disable": monitorDeliveryDisable,
"log status": logStatus,
"log audit list": logAuditList,
"log audit get": logAuditGet,
"log audit count": logAuditCount,
"log audit enable": logAuditEnable,
"log audit disable": logAuditDisable,
"log inference list": logInferenceList,
"log inference get": logInferenceGet,
"log inference count": logInferenceCount,
"log inference enable": logInferenceEnable,
"log inference disable": logInferenceDisable,
"log trace list": logTraceList,
"log trace get": logTraceGet,
"log trace stats": logTraceStats,
"alert metrics": alertMetrics,
"alert template list": alertTemplateList,
"alert template create": alertTemplateCreate,
"alert template update": alertTemplateUpdate,
"alert template delete": alertTemplateDelete,
"alert list": alertList,
"alert create": alertCreate,
"alert update": alertUpdate,
"alert delete": alertDelete,
"alert enable": alertEnable,
"alert disable": alertDisable,
"alert history": alertHistory,
"permission list": permissionList,
"permission grant": permissionGrant,
"permission revoke": permissionRevoke,
Expand Down
74 changes: 74 additions & 0 deletions packages/commands/src/commands/alert/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import {
defineCommand,
detectOutputFormat,
effectiveConsoleGatewayConfig,
unwrapResponse,
} from "bailian-cli-core";
import { emitResult } from "bailian-cli-runtime";
import {
ALERT_RULE_WRITE_FLAGS,
buildAlertRuleReqDTO,
ensureAlertReady,
validateAlertRuleFlags,
} from "./shared.ts";

const CREATE_RULE_API = "zeldaEasy.bailian-telemetry.alertRule.createAlertRule";

export default defineCommand({
description: {
"en-US": "Create a model alert rule from an alert template",
"zh-CN": "基于告警模板创建模型告警规则",
},
auth: "console",
usageArgs: "--name <name> --template-id <id> --model <model> [flags]",
flags: ALERT_RULE_WRITE_FLAGS,
notes: [
{
"en-US":
"Alert conditions come from the template; browse `alert template list` first. Notification contacts/contact groups are created in the CloudMonitor console — pass their IDs via --contact/--contact-group.",
"zh-CN":
"告警条件来自模板,请先用 `alert template list` 挑选。通知联系人/联系组需在云监控控制台创建,本命令通过 --contact/--contact-group 接收其 ID。",
},
],
exampleArgs: [
"--name high-failure-rate --template-id 123 --model qwen3.6-plus",
"--name latency --template-id 456 --model qwen3.6-plus,qwen-turbo --level ERROR --contact-group 4004200",
"--name nightly --template-id 123 --model qwen3.6-plus --notify-window 09:00-18:00 --notify-days 1,2,3,4,5 --silence 3600",
"--name test --template-id 123 --model qwen3.6-plus --dry-run",
],
validate: (flags) => validateAlertRuleFlags(flags),
async run(ctx) {
const { settings, flags } = ctx;
const format = settings.outputExplicit ? detectOutputFormat(settings.output) : "json";

const reqDTO = {
...(settings.workspaceId ? { workspaceId: settings.workspaceId } : {}),
...buildAlertRuleReqDTO(flags),
};

if (settings.dryRun) {
emitResult(
{
api: CREATE_RULE_API,
data: { reqDTO },
...effectiveConsoleGatewayConfig(settings),
},
format,
);
return;
}

await ensureAlertReady(ctx.client, settings.workspaceId, ctx.identity.binName, settings);

const raw = await ctx.client.console(CREATE_RULE_API, { reqDTO });
const resp = unwrapResponse(raw as Record<string, unknown>);
const ruleId = (resp.data ?? resp.ruleId ?? resp) as string | undefined;

if (format === "json") {
emitResult({ created: true, ruleId }, format);
return;
}

process.stdout.write(`Alert rule created${ruleId ? `: ${ruleId}` : "."}\n`);
},
});
69 changes: 69 additions & 0 deletions packages/commands/src/commands/alert/delete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { defineCommand, detectOutputFormat, effectiveConsoleGatewayConfig } from "bailian-cli-core";
import { emitResult } from "bailian-cli-runtime";
import { parseCommaList } from "../shared/params.ts";
import { ensureAlertReady } from "./shared.ts";

const DELETE_RULES_API = "zeldaEasy.bailian-telemetry.alertRule.deleteAlertRules";

export default defineCommand({
description: {
"en-US": "Delete model alert rules",
"zh-CN": "删除模型告警规则",
},
auth: "console",
risk: {
level: "high",
message: {
"en-US": "This permanently deletes the specified alert rules and cannot be undone.",
"zh-CN": "该操作会永久删除指定的告警规则,且无法撤销。",
},
},
usageArgs: "--rule-id <id>[,<id>...] [--yes]",
flags: {
ruleId: {
type: "string",
valueHint: "<id>[,<id>...]",
required: true,
description: {
"en-US": "Rule ID(s) to delete, comma-separated",
"zh-CN": "要删除的规则 ID,多个以逗号分隔",
},
},
},
exampleArgs: ["--rule-id 789", "--rule-id 789,790 --dry-run", "--rule-id 789 --yes"],
notes: [
{
"en-US": "Irreversible — the alert rules are permanently removed.",
"zh-CN": "该操作不可撤销——告警规则将被永久删除。",
},
],
async run(ctx) {
const { settings, flags } = ctx;
const format = settings.outputExplicit ? detectOutputFormat(settings.output) : "json";

const reqDTO = { ruleIds: parseCommaList(flags.ruleId) };

if (settings.dryRun) {
emitResult(
{
api: DELETE_RULES_API,
data: { reqDTO },
...effectiveConsoleGatewayConfig(settings),
},
format,
);
return;
}

await ensureAlertReady(ctx.client, settings.workspaceId, ctx.identity.binName, settings);

await ctx.client.console(DELETE_RULES_API, { reqDTO });

if (format === "json") {
emitResult({ deleted: reqDTO.ruleIds }, format);
return;
}

process.stdout.write(`Deleted ${reqDTO.ruleIds.length} alert rule(s).\n`);
},
});
59 changes: 59 additions & 0 deletions packages/commands/src/commands/alert/disable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { defineCommand, detectOutputFormat, effectiveConsoleGatewayConfig } from "bailian-cli-core";
import { emitResult } from "bailian-cli-runtime";
import { ensureAlertReady } from "./shared.ts";

const DISABLE_RULE_API = "zeldaEasy.bailian-telemetry.alertRule.disableAlertRule";

export default defineCommand({
description: {
"en-US": "Disable a model alert rule (keeps the rule, stops notifications)",
"zh-CN": "停用模型告警规则(保留规则,停止通知)",
},
auth: "console",
usageArgs: "--rule-id <id> [flags]",
flags: {
ruleId: {
type: "string",
valueHint: "<id>",
required: true,
description: {
"en-US": "Alert rule ID",
"zh-CN": "告警规则 ID",
},
},
},
exampleArgs: ["--rule-id 789", "--rule-id 789 --dry-run"],
async run(ctx) {
const { settings, flags } = ctx;
const format = settings.outputExplicit ? detectOutputFormat(settings.output) : "json";

const reqDTO = {
workspaceId: settings.workspaceId,
bizSource: "bailian",
ruleId: flags.ruleId,
};

if (settings.dryRun) {
emitResult(
{
api: DISABLE_RULE_API,
data: { reqDTO },
...effectiveConsoleGatewayConfig(settings),
},
format,
);
return;
}

await ensureAlertReady(ctx.client, settings.workspaceId, ctx.identity.binName, settings);

await ctx.client.console(DISABLE_RULE_API, { reqDTO });

if (format === "json") {
emitResult({ enabled: false, ruleId: flags.ruleId }, format);
return;
}

process.stdout.write(`Alert rule disabled: ${flags.ruleId}\n`);
},
});
57 changes: 57 additions & 0 deletions packages/commands/src/commands/alert/enable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { defineCommand, detectOutputFormat, effectiveConsoleGatewayConfig } from "bailian-cli-core";
import { emitResult } from "bailian-cli-runtime";
import { ensureAlertReady } from "./shared.ts";

export default defineCommand({
description: {
"en-US": "Enable a model alert rule",
"zh-CN": "启用模型告警规则",
},
auth: "console",
usageArgs: "--rule-id <id> [flags]",
flags: {
ruleId: {
type: "string",
valueHint: "<id>",
required: true,
description: {
"en-US": "Alert rule ID",
"zh-CN": "告警规则 ID",
},
},
},
exampleArgs: ["--rule-id 789", "--rule-id 789 --dry-run"],
async run(ctx) {
const { settings, flags } = ctx;
const format = settings.outputExplicit ? detectOutputFormat(settings.output) : "json";

const reqDTO = {
workspaceId: settings.workspaceId,
bizSource: "bailian",
ruleId: flags.ruleId,
};

if (settings.dryRun) {
emitResult(
{
api: "zeldaEasy.bailian-telemetry.alertRule.enableAlertRule",
data: { reqDTO },
...effectiveConsoleGatewayConfig(settings),
},
format,
);
return;
}

await ensureAlertReady(ctx.client, settings.workspaceId, ctx.identity.binName, settings);

await ctx.client.console("zeldaEasy.bailian-telemetry.alertRule.enableAlertRule", { reqDTO });

if (format === "json") {
emitResult({ enabled: true, ruleId: flags.ruleId }, format);
return;
}

process.stdout.write(`Alert rule enabled: ${flags.ruleId}\n`);
},
});
Loading
Loading