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
2 changes: 1 addition & 1 deletion packages/bailian-kb-dsh/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bailian-kb-dsh",
"version": "2.10.1",
"version": "2.10.2",
"description": "Bailian knowledge-base tools for DeepSeek Harness: kb_search and kb_chat over the DashScope RAG API, plus the bl CLI management skill.",
"keywords": [
"alibaba-cloud",
Expand Down
2 changes: 1 addition & 1 deletion packages/bailian-memo-dsh/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bailian-memo-dsh",
"version": "2.10.1",
"version": "2.10.2",
"description": "Bailian personal memory for DeepSeek Harness: automatic recall, silent curation, and user-controlled remember/forget.",
"keywords": [
"alibaba-cloud",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bailian-cli",
"version": "2.10.1",
"version": "2.10.2",
"description": "CLI for Aliyun Model Studio (DashScope) AI Platform.",
"keywords": [
"agent",
Expand Down
2 changes: 1 addition & 1 deletion packages/commands/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bailian-cli-commands",
"version": "2.10.1",
"version": "2.10.2",
"description": "Command library for bailian-cli products (knowledge, memory, media, …). See https://www.npmjs.com/package/bailian-cli for usage.",
"homepage": "https://bailian.console.aliyun.com/cli",
"bugs": {
Expand Down
1 change: 1 addition & 0 deletions packages/commands/src/commands/log/audit-disable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default defineTelemetryCommand({
output: ctx.output,
settings: ctx.settings,
commandPrefix: formatCommand(ctx.identity),
localize: ctx.localize,
},
"audit",
true,
Expand Down
9 changes: 5 additions & 4 deletions packages/commands/src/commands/log/audit-enable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import { LOG_SERVICE_TYPES } from "./status.ts";

export default defineTelemetryCommand({
description: {
"en-US": "Enable audit log delivery to SLS (SLR authorization → SLS instance → log switch)",
"zh-CN": "开启审计日志投递到 SLS(SLR 授权 → SLS 实例初始化 → 打开日志开关)",
"en-US": "Enable audit log delivery to SLS (SLR check → SLS instance → log switch)",
"zh-CN": "开启审计日志投递到 SLS(SLR 校验 → SLS 实例初始化 → 打开日志开关)",
},
auth: "console",
usageArgs: "[--no-wait] [flags]",
flags: LOG_NO_WAIT_FLAG,
notes: [
{
"en-US":
"Steps: 1) authorize the SLS service-linked role, 2) initialize the SLS store instance (async), 3) turn on audit log delivery for all models in the workspace.",
"Steps: 1) verify the SLS service-linked role is authorized (stops with manual-authorization guidance when missing), 2) initialize the SLS store instance (async), 3) turn on audit log delivery for all models in the workspace.",
"zh-CN":
"开启链路:1)授权 SLS 服务关联角色;2)初始化 SLS 存储实例(异步);3)为当前业务空间全部模型打开审计日志开关。",
"开启链路:1)校验 SLS 服务关联角色已授权(未授权时停止并引导手动开通);2)初始化 SLS 存储实例(异步);3)为当前业务空间全部模型打开审计日志开关。",
},
{
"en-US":
Expand All @@ -32,6 +32,7 @@ export default defineTelemetryCommand({
output: ctx.output,
settings: ctx.settings,
commandPrefix: formatCommand(ctx.identity),
localize: ctx.localize,
noWait: ctx.flags.noWait,
},
"audit",
Expand Down
1 change: 1 addition & 0 deletions packages/commands/src/commands/log/inference-disable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default defineTelemetryCommand({
output: ctx.output,
settings: ctx.settings,
commandPrefix: formatCommand(ctx.identity),
localize: ctx.localize,
},
"inference",
);
Expand Down
9 changes: 5 additions & 4 deletions packages/commands/src/commands/log/inference-enable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import { LOG_SERVICE_TYPES } from "./status.ts";

export default defineTelemetryCommand({
description: {
"en-US": "Enable inference log delivery to SLS (SLR authorization → SLS instance → log switch)",
"zh-CN": "开启推理日志投递到 SLS(SLR 授权 → SLS 实例初始化 → 打开日志开关)",
"en-US": "Enable inference log delivery to SLS (SLR check → SLS instance → log switch)",
"zh-CN": "开启推理日志投递到 SLS(SLR 校验 → SLS 实例初始化 → 打开日志开关)",
},
auth: "console",
usageArgs: "[--no-wait] [flags]",
flags: LOG_NO_WAIT_FLAG,
notes: [
{
"en-US":
"Steps: 1) authorize the SLS service-linked role, 2) initialize the SLS store instance (async), 3) turn on inference log delivery for all models in the workspace.",
"Steps: 1) verify the SLS service-linked role is authorized (stops with manual-authorization guidance when missing), 2) initialize the SLS store instance (async), 3) turn on inference log delivery for all models in the workspace.",
"zh-CN":
"开启链路:1)授权 SLS 服务关联角色;2)初始化 SLS 存储实例(异步);3)为当前业务空间全部模型打开推理日志开关。",
"开启链路:1)校验 SLS 服务关联角色已授权(未授权时停止并引导手动开通);2)初始化 SLS 存储实例(异步);3)为当前业务空间全部模型打开推理日志开关。",
},
{
"en-US":
Expand All @@ -31,6 +31,7 @@ export default defineTelemetryCommand({
output: ctx.output,
settings: ctx.settings,
commandPrefix: formatCommand(ctx.identity),
localize: ctx.localize,
noWait: ctx.flags.noWait,
};

Expand Down
20 changes: 9 additions & 11 deletions packages/commands/src/commands/log/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import {
telemetryGatewayPreview,
buildGroupSwitchReqDTO,
ensureTelemetryRegionSupported,
ensureTelemetrySlrAuthorized,
requireTelemetrySlrAuthorized,
ENABLE_GROUP_API,
DISABLE_GROUP_API,
SLR_STATUS_API,
getTelemetryGroupSwitch,
getTelemetryServiceStatus,
pollTelemetryData,
Expand Down Expand Up @@ -241,7 +242,6 @@ export const LOG_GROUP_TYPES = {

export type LogKind = keyof typeof LOG_GROUP_TYPES;

const CREATE_SLR_API = "zeldaEasy.bailian-telemetry.activate.createTelemetrySlr";
const INIT_STORE_API = "zeldaEasy.bailian-telemetry.activate.initTelemetryStoreInstance";

const WAIT_INTERVAL_MS = 3000;
Expand Down Expand Up @@ -295,13 +295,15 @@ export interface LogEnableContext {
client: Client;
settings: Settings;
commandPrefix: string;
localize: (text: LocalizedText) => string;
noWait?: boolean;
}

/**
* Enable one log delivery switch, mirroring the console flow:
* 1) authorize the SLS service-linked role, 2) initialize the SLS store
* instance when missing (async), 3) flip the telemetry group switch.
* 1) verify the SLS service-linked role is authorized (stop with guidance when
* missing), 2) initialize the SLS store instance when missing (async),
* 3) flip the telemetry group switch.
*/
export async function enableLogDelivery(
ctx: LogEnableContext,
Expand All @@ -313,7 +315,7 @@ export async function enableLogDelivery(

if (settings.dryRun) {
ctx.output.result({
apis: [CREATE_SLR_API, INIT_STORE_API, ENABLE_GROUP_API],
apis: [SLR_STATUS_API, INIT_STORE_API, ENABLE_GROUP_API],
data: { reqDTO: groupReqDTO(settings, kind) },
...telemetryGatewayPreview(settings),
});
Expand All @@ -322,12 +324,8 @@ export async function enableLogDelivery(

ensureTelemetryRegionSupported(settings);

// Step 1: SLS service-linked role.
await ensureTelemetrySlrAuthorized(client, "Log", settings.workspaceId, {
pollRetries: 5,
onProgress: (message) =>
ctx.output.progress({ "en-US": message, "zh-CN": "正在授权服务关联角色……" }),
});
// Step 1: SLS service-linked role must already be authorized; never auto-create.
await requireTelemetrySlrAuthorized(client, "Log", settings.workspaceId, ctx.localize);

// Step 2: SLS store instance (async creation, poll until Ready).
let serviceStatus = await getTelemetryServiceStatus(client, serviceType, settings.workspaceId);
Expand Down
21 changes: 8 additions & 13 deletions packages/commands/src/commands/monitor/delivery-enable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ import {
buildGroupSwitchReqDTO,
ENABLE_GROUP_API,
ensureTelemetryRegionSupported,
ensureTelemetrySlrAuthorized,
requireTelemetrySlrAuthorized,
getTelemetryGroupSwitch,
getTelemetryServiceStatus,
pollTelemetryData,
SLR_STATUS_API,
TELEMETRY_SERVICE_STATUS_API,
type TelemetryServiceStatus,
} from "../shared/telemetry.ts";

const SLR_STATUS_API = "zeldaEasy.bailian-telemetry.activate.getTelemetrySlrStatus";
const CREATE_SLR_API = "zeldaEasy.bailian-telemetry.activate.createTelemetrySlr";
const INIT_CMS_API = "zeldaEasy.bailian-telemetry.activate.initCmsService";
const INIT_STORE_API = "zeldaEasy.bailian-telemetry.activate.initTelemetryStoreInstance";
const SERVICE_TYPE = "ModelMonitor";
Expand Down Expand Up @@ -41,8 +40,8 @@ async function waitFor(
export default defineTelemetryCommand({
description: {
"en-US":
"Activate monitoring delivery: CMS SLR authorization, CMS service, and the dedicated Prometheus instance",
"zh-CN": "开通监控数据投递:CMS SLR 授权、开通 CMS 服务、创建用户独享 Prometheus 实例",
"Activate monitoring delivery: CMS SLR check, CMS service, and the dedicated Prometheus instance",
"zh-CN": "开通监控数据投递:校验 CMS SLR 授权、开通 CMS 服务、创建用户独享 Prometheus 实例",
},
auth: "console",
usageArgs: "[--no-wait] [flags]",
Expand All @@ -58,9 +57,9 @@ export default defineTelemetryCommand({
notes: [
{
"en-US":
"Steps: 1) authorize the CMS service-linked role, 2) open the CMS service (async, polled via openStatus), 3) create the dedicated Prometheus instance (async, polled until Ready), 4) turn on the monitor delivery switch for all models. Server-side throttles duplicate submissions within 30s.",
"Steps: 1) verify the CMS service-linked role is authorized (stops with manual-authorization guidance when missing), 2) open the CMS service (async, polled via openStatus), 3) create the dedicated Prometheus instance (async, polled until Ready), 4) turn on the monitor delivery switch for all models. Server-side throttles duplicate submissions within 30s.",
"zh-CN":
"开通链路:1)授权 CMS 服务关联角色;2)开通 CMS 服务(异步,以 openStatus 为准);3)创建用户独享 Prometheus 实例(异步,等待 Ready);4)为全部模型打开监控投递开关。服务端对 30 秒内的重复提交做节流。",
"开通链路:1)校验 CMS 服务关联角色已授权(未授权时停止并引导手动开通);2)开通 CMS 服务(异步,以 openStatus 为准);3)创建用户独享 Prometheus 实例(异步,等待 Ready);4)为全部模型打开监控投递开关。服务端对 30 秒内的重复提交做节流。",
},
],
exampleArgs: ["", "--no-wait", "--output json"],
Expand All @@ -72,7 +71,6 @@ export default defineTelemetryCommand({
ctx.output.result({
apis: [
SLR_STATUS_API,
CREATE_SLR_API,
TELEMETRY_SERVICE_STATUS_API,
INIT_CMS_API,
INIT_STORE_API,
Expand Down Expand Up @@ -111,11 +109,8 @@ export default defineTelemetryCommand({
return;
}

// Step 1: CMS service-linked role.
await ensureTelemetrySlrAuthorized(ctx.client, "Cms", settings.workspaceId, {
onProgress: (message) =>
ctx.output.progress({ "en-US": message, "zh-CN": "正在授权服务关联角色……" }),
});
// Step 1: CMS service-linked role must already be authorized; never auto-create.
await requireTelemetrySlrAuthorized(ctx.client, "Cms", settings.workspaceId, ctx.localize);

// Step 2: open the CMS service (only submits when still closed; poll openStatus).
if (!status.openStatus) {
Expand Down
50 changes: 23 additions & 27 deletions packages/commands/src/commands/shared/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import {
type Client,
type Command,
type FlagsDef,
type LocalizedText,
type Settings,
} from "bailian-cli-core";
import { MODEL_TELEMETRY_DOC } from "bailian-cli-runtime";
import { parseCommaList } from "./params.ts";
import { consoleWorkspaceIdentityPreview, resolveConsoleWorkspaceAgent } from "./workspace.ts";

Expand Down Expand Up @@ -331,8 +333,7 @@ export async function ensureTelemetryReady(
// Service-linked role (SLR) helpers
// ---------------------------------------------------------------------------

const SLR_STATUS_API = "zeldaEasy.bailian-telemetry.activate.getTelemetrySlrStatus";
const CREATE_SLR_API = "zeldaEasy.bailian-telemetry.activate.createTelemetrySlr";
export const SLR_STATUS_API = "zeldaEasy.bailian-telemetry.activate.getTelemetrySlrStatus";

export type TelemetrySlrType = "Log" | "Xtrace" | "Cms";

Expand All @@ -348,34 +349,29 @@ export async function getTelemetrySlrAuthorized(
}

/**
* Authorize a service-linked role when missing. The role takes effect with a
* short delay, so after submitting we poll the status API briefly; a lagging
* status is not treated as a failure (downstream APIs re-check anyway).
* Gate a delivery-enable command on the service-linked role being authorized.
* Creating an SLR grants cross-service permissions on the user's account, so
* the CLI never does it automatically: when the role is missing we stop with
* AUTH and point at the doc that walks the user through manual authorization.
*/
export async function ensureTelemetrySlrAuthorized(
export async function requireTelemetrySlrAuthorized(
client: Client,
slrType: TelemetrySlrType,
workspaceId?: string,
opts: {
pollRetries?: number;
pollIntervalMs?: number;
onProgress?: (message: string) => void;
} = {},
): Promise<boolean> {
if (await getTelemetrySlrAuthorized(client, slrType, workspaceId)) return true;

opts.onProgress?.("Authorizing the service-linked role...");
await client.console(CREATE_SLR_API, {
reqDTO: { ...(workspaceId ? { workspaceId } : {}), slrType },
});

const retries = opts.pollRetries ?? 10;
const intervalMs = opts.pollIntervalMs ?? 2000;
for (let attempt = 0; attempt < retries; attempt += 1) {
if (await getTelemetrySlrAuthorized(client, slrType, workspaceId)) return true;
await new Promise((resolve) => setTimeout(resolve, intervalMs));
}
return false;
workspaceId: string | undefined,
localize: (text: LocalizedText) => string,
): Promise<void> {
if (await getTelemetrySlrAuthorized(client, slrType, workspaceId)) return;
throw new BailianError(
localize({
"en-US": "The service-linked role (SLR) required for telemetry delivery is not authorized.",
"zh-CN": "遥测投递所需的服务关联角色(SLR)尚未授权。",
}),
ExitCode.AUTH,
localize({
"en-US": `The CLI does not create service-linked roles automatically. Follow ${MODEL_TELEMETRY_DOC} to authorize the role in the console, then retry.`,
"zh-CN": `CLI 不会自动创建服务关联角色。请参照 ${MODEL_TELEMETRY_DOC} 在控制台完成授权后重试。`,
}),
);
}

// ---------------------------------------------------------------------------
Expand Down
6 changes: 4 additions & 2 deletions packages/commands/tests/e2e/log.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,8 @@ describe("e2e: log", () => {
apis?: string[];
data?: { reqDTO?: { telemetryType?: string; resourceId?: string } };
}>(stdout);
expect(data.apis).toContain("zeldaEasy.bailian-telemetry.activate.createTelemetrySlr");
expect(data.apis).toContain("zeldaEasy.bailian-telemetry.activate.getTelemetrySlrStatus");
expect(data.apis).not.toContain("zeldaEasy.bailian-telemetry.activate.createTelemetrySlr");
expect(data.apis).toContain("zeldaEasy.bailian-telemetry.activate.initTelemetryStoreInstance");
expect(data.apis).toContain("zeldaEasy.bailian-telemetry.telemetryGroup.enableTelemetryGroup");
expect(data.data?.reqDTO?.telemetryType).toBe("AuditLog");
Expand Down Expand Up @@ -1048,7 +1049,8 @@ describe("e2e: log", () => {
apis?: string[];
data?: { reqDTO?: { telemetryType?: string; resourceId?: string } };
}>(stdout);
expect(data.apis).toContain("zeldaEasy.bailian-telemetry.activate.createTelemetrySlr");
expect(data.apis).toContain("zeldaEasy.bailian-telemetry.activate.getTelemetrySlrStatus");
expect(data.apis).not.toContain("zeldaEasy.bailian-telemetry.activate.createTelemetrySlr");
expect(data.apis).toContain("zeldaEasy.bailian-telemetry.activate.initTelemetryStoreInstance");
expect(data.apis).toContain("zeldaEasy.bailian-telemetry.telemetryGroup.enableTelemetryGroup");
expect(data.data?.reqDTO?.telemetryType).toBe("InferenceLog");
Expand Down
2 changes: 1 addition & 1 deletion packages/commands/tests/e2e/monitor.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ describe("e2e: monitor", () => {
expect(exitCode, stderr).toBe(0);
const data = parseStdoutJson<{ apis?: string[] }>(stdout);
expect(data.apis).toContain("zeldaEasy.bailian-telemetry.activate.getTelemetrySlrStatus");
expect(data.apis).toContain("zeldaEasy.bailian-telemetry.activate.createTelemetrySlr");
expect(data.apis).not.toContain("zeldaEasy.bailian-telemetry.activate.createTelemetrySlr");
expect(data.apis).toContain("zeldaEasy.bailian-telemetry.activate.getTelemetryServiceStatus");
expect(data.apis).toContain("zeldaEasy.bailian-telemetry.activate.initCmsService");
expect(data.apis).toContain("zeldaEasy.bailian-telemetry.activate.initTelemetryStoreInstance");
Expand Down
Loading
Loading