diff --git a/packages/bailian-kb-dsh/package.json b/packages/bailian-kb-dsh/package.json index c5711285..624c9b79 100644 --- a/packages/bailian-kb-dsh/package.json +++ b/packages/bailian-kb-dsh/package.json @@ -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", diff --git a/packages/bailian-memo-dsh/package.json b/packages/bailian-memo-dsh/package.json index 4bb8d61c..cec30c17 100644 --- a/packages/bailian-memo-dsh/package.json +++ b/packages/bailian-memo-dsh/package.json @@ -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", diff --git a/packages/cli/package.json b/packages/cli/package.json index b8e8d1fe..abafd3dc 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -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", diff --git a/packages/commands/package.json b/packages/commands/package.json index 8263b601..0c06beef 100644 --- a/packages/commands/package.json +++ b/packages/commands/package.json @@ -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": { diff --git a/packages/commands/src/commands/log/audit-disable.ts b/packages/commands/src/commands/log/audit-disable.ts index ef2d0017..94bfc2ac 100644 --- a/packages/commands/src/commands/log/audit-disable.ts +++ b/packages/commands/src/commands/log/audit-disable.ts @@ -24,6 +24,7 @@ export default defineTelemetryCommand({ output: ctx.output, settings: ctx.settings, commandPrefix: formatCommand(ctx.identity), + localize: ctx.localize, }, "audit", true, diff --git a/packages/commands/src/commands/log/audit-enable.ts b/packages/commands/src/commands/log/audit-enable.ts index a34857d2..9fc7f7d7 100644 --- a/packages/commands/src/commands/log/audit-enable.ts +++ b/packages/commands/src/commands/log/audit-enable.ts @@ -5,8 +5,8 @@ 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]", @@ -14,9 +14,9 @@ export default defineTelemetryCommand({ 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": @@ -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", diff --git a/packages/commands/src/commands/log/inference-disable.ts b/packages/commands/src/commands/log/inference-disable.ts index 8f3cc61f..ff294f64 100644 --- a/packages/commands/src/commands/log/inference-disable.ts +++ b/packages/commands/src/commands/log/inference-disable.ts @@ -24,6 +24,7 @@ export default defineTelemetryCommand({ output: ctx.output, settings: ctx.settings, commandPrefix: formatCommand(ctx.identity), + localize: ctx.localize, }, "inference", ); diff --git a/packages/commands/src/commands/log/inference-enable.ts b/packages/commands/src/commands/log/inference-enable.ts index 3dabcefe..4523bc30 100644 --- a/packages/commands/src/commands/log/inference-enable.ts +++ b/packages/commands/src/commands/log/inference-enable.ts @@ -5,8 +5,8 @@ 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]", @@ -14,9 +14,9 @@ export default defineTelemetryCommand({ 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": @@ -31,6 +31,7 @@ export default defineTelemetryCommand({ output: ctx.output, settings: ctx.settings, commandPrefix: formatCommand(ctx.identity), + localize: ctx.localize, noWait: ctx.flags.noWait, }; diff --git a/packages/commands/src/commands/log/shared.ts b/packages/commands/src/commands/log/shared.ts index 84f97e42..d7a012c2 100644 --- a/packages/commands/src/commands/log/shared.ts +++ b/packages/commands/src/commands/log/shared.ts @@ -15,9 +15,10 @@ import { telemetryGatewayPreview, buildGroupSwitchReqDTO, ensureTelemetryRegionSupported, - ensureTelemetrySlrAuthorized, + requireTelemetrySlrAuthorized, ENABLE_GROUP_API, DISABLE_GROUP_API, + SLR_STATUS_API, getTelemetryGroupSwitch, getTelemetryServiceStatus, pollTelemetryData, @@ -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; @@ -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, @@ -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), }); @@ -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); diff --git a/packages/commands/src/commands/monitor/delivery-enable.ts b/packages/commands/src/commands/monitor/delivery-enable.ts index 1b2812b8..11f39c5f 100644 --- a/packages/commands/src/commands/monitor/delivery-enable.ts +++ b/packages/commands/src/commands/monitor/delivery-enable.ts @@ -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"; @@ -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]", @@ -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"], @@ -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, @@ -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) { diff --git a/packages/commands/src/commands/shared/telemetry.ts b/packages/commands/src/commands/shared/telemetry.ts index 7b2260d3..0b6c36ef 100644 --- a/packages/commands/src/commands/shared/telemetry.ts +++ b/packages/commands/src/commands/shared/telemetry.ts @@ -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"; @@ -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"; @@ -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 { - 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 { + 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} 在控制台完成授权后重试。`, + }), + ); } // --------------------------------------------------------------------------- diff --git a/packages/commands/tests/e2e/log.e2e.test.ts b/packages/commands/tests/e2e/log.e2e.test.ts index 9d0612ba..533b35b7 100644 --- a/packages/commands/tests/e2e/log.e2e.test.ts +++ b/packages/commands/tests/e2e/log.e2e.test.ts @@ -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"); @@ -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"); diff --git a/packages/commands/tests/e2e/monitor.e2e.test.ts b/packages/commands/tests/e2e/monitor.e2e.test.ts index 2f22b82a..e4ff6e16 100644 --- a/packages/commands/tests/e2e/monitor.e2e.test.ts +++ b/packages/commands/tests/e2e/monitor.e2e.test.ts @@ -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"); diff --git a/packages/commands/tests/output/telemetry-output.test.ts b/packages/commands/tests/output/telemetry-output.test.ts index eff48ccb..5d4f0dd1 100644 --- a/packages/commands/tests/output/telemetry-output.test.ts +++ b/packages/commands/tests/output/telemetry-output.test.ts @@ -8,7 +8,7 @@ import { type AnyCommand, type LocalizedText, } from "bailian-cli-core"; -import { createOutputReporter } from "bailian-cli-runtime"; +import { createOutputReporter, MODEL_TELEMETRY_DOC } from "bailian-cli-runtime"; import * as commands from "bailian-cli-commands"; const range = { startTime: "2026-01-02T03:04:00", endTime: "2026-01-02T04:04:00" }; @@ -236,6 +236,7 @@ const cases: Scenario[] = [ ]; let failure = false; let cold = false; +let slrUnauthorized = false; let guardInference = false; let pendingFirst = false; let originEmpty = false; @@ -245,6 +246,7 @@ afterEach(() => { vi.restoreAllMocks(); failure = false; cold = false; + slrUnauthorized = false; guardInference = false; pendingFirst = false; originEmpty = false; @@ -293,7 +295,7 @@ async function invoke( }, }, }); - let authorized = !cold, + let authorized = !slrUnauthorized, ready = !cold, opened = !cold; interface FixtureClient { @@ -317,10 +319,6 @@ async function invoke( ) return { taskId: "async-task" }; if (api.includes("getTelemetrySlrStatus")) return { result: authorized }; - if (api.includes("createTelemetrySlr")) { - authorized = true; - return {}; - } if (api.includes("getTelemetryServiceStatus")) return ready ? structuredClone(service) @@ -464,6 +462,31 @@ test("audit disable still refuses while inference is enabled", async () => { expect(calls.some((call) => call.api.includes("disableTelemetryGroup"))).toBe(false); }); +test.each(["monitor delivery enable", "log audit enable", "log inference enable"])( + "%s stops with AUTH and doc guidance when the SLR is unauthorized", + async (name) => { + const base = cases.find((scenario) => scenario.name === name)!; + slrUnauthorized = true; + const result = await invoke( + { ...base, flags: { noWait: true } }, + { format: "json", quiet: true }, + ); + expect(result.exitCode).toBe(ExitCode.AUTH); + expect(result.stdout).toBe(""); + expect(result.strayOut).toBe(""); + expect(result.strayErr).toBe(""); + const error = JSON.parse(result.stderr).error; + expect(error.message).toContain("service-linked role"); + expect(error.hint).toContain(MODEL_TELEMETRY_DOC); + expect(calls.some((call) => call.api.includes("createTelemetrySlr"))).toBe(false); + expect( + calls.some((call) => + /initCmsService|initTelemetryStoreInstance|enableTelemetryGroup/.test(call.api), + ), + ).toBe(false); + }, +); + test.each(["monitor delivery enable", "log audit enable", "log inference enable"])( "ordinary text keeps cold-start progress for %s", async (name) => { @@ -476,7 +499,6 @@ test.each(["monitor delivery enable", "log audit enable", "log inference enable" expect(result.exitCode, result.stderr).toBe(0); expect(result.strayOut).toBe(""); expect(result.strayErr).toBe(""); - expect(result.stderr).toContain("Authorizing the service-linked role"); expect(result.stderr).toContain( name.startsWith("monitor") ? "CMS service" : "Initializing the SLS", ); diff --git a/packages/commands/tests/telemetry.test.ts b/packages/commands/tests/telemetry.test.ts index 03907818..9a06692b 100644 --- a/packages/commands/tests/telemetry.test.ts +++ b/packages/commands/tests/telemetry.test.ts @@ -7,7 +7,7 @@ import { type AnyCommand, type Settings, } from "bailian-cli-core"; -import { createOutputReporter } from "bailian-cli-runtime"; +import { createOutputReporter, MODEL_TELEMETRY_DOC } from "bailian-cli-runtime"; import { loadRouteCommands } from "./e2e/harness/routes.ts"; import { ALERT_ROUTES, LOG_ROUTES, MONITOR_ROUTES } from "./e2e/topic-routes.ts"; import { @@ -234,7 +234,6 @@ describe("遥测命令的空间身份与默认 JSON", () => { test("monitor 投递开通的并行预检、SLR、初始化、轮询与写入保持身份", async () => { vi.useFakeTimers(); let serviceChecks = 0; - let slrChecks = 0; mockTelemetryGateway((request) => { if (request.Api.includes("getTelemetryServiceStatus")) { serviceChecks += 1; @@ -244,10 +243,7 @@ describe("遥测命令的空间身份与默认 JSON", () => { }; } if (request.Api.includes("getTelemetryGroupStatus")) return []; - if (request.Api.includes("getTelemetrySlrStatus")) { - slrChecks += 1; - return { result: slrChecks > 1 }; - } + if (request.Api.includes("getTelemetrySlrStatus")) return { result: true }; if (request.Api.includes("initTelemetryStoreInstance") && !request.Data.reqDTO?.asyncTaskId) return { taskId: "store-task" }; return { result: true }; @@ -259,16 +255,12 @@ describe("遥测命令的空间身份与默认 JSON", () => { await vi.runAllTimersAsync(); expect(JSON.parse(await promise).activated).toBe(true); assertScopedRequests(); - for (const api of [ - "createTelemetrySlr", - "initCmsService", - "initTelemetryStoreInstance", - "enableTelemetryGroup", - ]) + for (const api of ["initCmsService", "initTelemetryStoreInstance", "enableTelemetryGroup"]) expect( requests.some((request) => request.Api.endsWith(api)), api, ).toBe(true); + expect(requests.some((request) => request.Api.includes("createTelemetrySlr"))).toBe(false); }); test("推理详情列表和原始内容回捞均使用目标身份", async () => { @@ -304,6 +296,45 @@ describe("遥测命令的空间身份与默认 JSON", () => { expect(requests.at(-1)?.Api).toContain("enableTelemetryGroup"); }); + test.each(["monitor delivery enable", "log audit enable", "log inference enable"])( + "%s SLR 未授权时停止执行并引导手动开通,不自动创建角色", + async (path) => { + mockTelemetryGateway((request) => { + if (request.Api.includes("getTelemetrySlrStatus")) return { result: false }; + if (request.Api.includes("getTelemetryServiceStatus")) + return { openStatus: true, instanceStatus: "Ready" }; + if (request.Api.includes("getTelemetryGroupStatus")) { + const telemetryType = request.Data.reqDTO?.telemetryType; + return { + list: [ + { + workspaceId, + telemetryType, + telemetryStatus: telemetryType === "AuditLog" ? "enable" : "disable", + }, + ], + }; + } + return { result: true }; + }); + await expect( + runTelemetry(telemetryCommands[path], makeTelemetryContext({}, { noWait: true })), + ).rejects.toMatchObject({ + exitCode: 3, + message: expect.stringContaining("service-linked role"), + hint: expect.stringContaining(MODEL_TELEMETRY_DOC), + }); + assertScopedRequests(); + expect(requests.some((request) => request.Api.includes("createTelemetrySlr"))).toBe(false); + expect( + requests.some((request) => + /initCmsService|initTelemetryStoreInstance|enableTelemetryGroup/.test(request.Api), + ), + ).toBe(false); + expect(stdoutChunks).toEqual([]); + }, + ); + test.each([ "alert list", "alert delete", diff --git a/packages/core/package.json b/packages/core/package.json index 1cefe217..1760c7a8 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "bailian-cli-core", - "version": "2.10.1", + "version": "2.10.2", "description": "Core SDK for bailian-cli. See https://www.npmjs.com/package/bailian-cli for usage.", "homepage": "https://bailian.console.aliyun.com/cli", "bugs": { diff --git a/packages/kscli/package.json b/packages/kscli/package.json index 99c29e6f..976eda57 100644 --- a/packages/kscli/package.json +++ b/packages/kscli/package.json @@ -1,6 +1,6 @@ { "name": "knowledge-studio-cli", - "version": "2.10.1", + "version": "2.10.2", "description": "Lightweight RAG CLI for Aliyun Model Studio — focused on knowledge-base retrieval.", "keywords": [ "alibaba-cloud", diff --git a/packages/runtime/package.json b/packages/runtime/package.json index 2a59a03f..e1092e1a 100644 --- a/packages/runtime/package.json +++ b/packages/runtime/package.json @@ -1,6 +1,6 @@ { "name": "bailian-cli-runtime", - "version": "2.10.1", + "version": "2.10.2", "description": "Runtime framework for bailian-cli (createCli, registry, args, output, pipeline). See https://www.npmjs.com/package/bailian-cli for usage.", "homepage": "https://bailian.console.aliyun.com/cli", "bugs": { diff --git a/packages/runtime/src/index.ts b/packages/runtime/src/index.ts index 6203e5f0..f10e5413 100644 --- a/packages/runtime/src/index.ts +++ b/packages/runtime/src/index.ts @@ -40,6 +40,7 @@ export { MCP_WEBSEARCH_PAGE, mcpMarketplaceDetailPage, VOICE_TTS_PAGE, + MODEL_TELEMETRY_DOC, refundConsolePage, } from "./urls.ts"; diff --git a/packages/runtime/src/urls.ts b/packages/runtime/src/urls.ts index f6286a0f..927599e1 100644 --- a/packages/runtime/src/urls.ts +++ b/packages/runtime/src/urls.ts @@ -36,6 +36,14 @@ export const MCP_WEBSEARCH_PAGE = mcpMarketplaceDetailPage("WebSearch"); /** Voice TTS experience center — browse system and custom voices. */ export const VOICE_TTS_PAGE = "https://help.aliyun.com/zh/model-studio/cosyvoice-voice-list"; +/** + * Model telemetry doc — guides users to manually authorize the service-linked + * roles (SLR) required by monitor / log delivery. The CLI only checks SLR + * status and never creates roles on the user's behalf. + */ +export const MODEL_TELEMETRY_DOC = + "https://docs.bailian.console.aliyun.com/zh/model-studio/model-telemetry"; + /** * Aliyun billing console refund (unsubscribe) page for one prepaid instance. * Unsubscribing a prepaid PTU capacity instance is a billing action that has diff --git a/skills/bailian-cli/SKILL.md b/skills/bailian-cli/SKILL.md index 7779a77c..97a37e79 100644 --- a/skills/bailian-cli/SKILL.md +++ b/skills/bailian-cli/SKILL.md @@ -1,7 +1,7 @@ --- name: bailian-cli metadata: - version: "2.10.1" + version: "2.10.2" requires: bins: ["bl"] description: >- diff --git a/skills/bailian-cli/reference/index.md b/skills/bailian-cli/reference/index.md index bff85056..7fbb0b57 100644 --- a/skills/bailian-cli/reference/index.md +++ b/skills/bailian-cli/reference/index.md @@ -69,12 +69,12 @@ Use this index for the skill-scoped quick index and global flags. | `bl flow-agent workflow save` | Console | Save a workflow canvas (replaces the current draft) | [flow-agent.md](flow-agent.md) | | `bl log audit count` | Console | Count model audit logs in a time range (useful before exporting) | [log.md](log.md) | | `bl log audit disable` | Console | Disable audit log delivery for all models in the workspace | [log.md](log.md) | -| `bl log audit enable` | Console | Enable audit log delivery to SLS (SLR authorization → SLS instance → log switch) | [log.md](log.md) | +| `bl log audit enable` | Console | Enable audit log delivery to SLS (SLR check → SLS instance → log switch) | [log.md](log.md) | | `bl log audit get` | Console | Show a single audit log entry with its raw origin record | [log.md](log.md) | | `bl log audit list` | Console | Query model audit logs (call metadata; request/response content is not recorded) | [log.md](log.md) | | `bl log inference count` | Console | Count model inference logs in a time range (useful before exporting) | [log.md](log.md) | | `bl log inference disable` | Console | Disable inference log delivery for all models in the workspace | [log.md](log.md) | -| `bl log inference enable` | Console | Enable inference log delivery to SLS (SLR authorization → SLS instance → log switch) | [log.md](log.md) | +| `bl log inference enable` | Console | Enable inference log delivery to SLS (SLR check → SLS instance → log switch) | [log.md](log.md) | | `bl log inference get` | Console | Show a single inference log entry with full request/response content | [log.md](log.md) | | `bl log inference list` | Console | Query model inference logs (requires inference log delivery; use `log inference get` for request/response content) | [log.md](log.md) | | `bl log status` | Console | Show model log delivery status (SLS authorization, audit / inference service and switches) | [log.md](log.md) | @@ -90,7 +90,7 @@ Use this index for the skill-scoped quick index and global flags. | `bl model list` | No Auth | Browse model families or show detailed model info in the Bailian model marketplace | [model.md](model.md) | | `bl model search` | No Auth | Search the model catalog by keyword, ranked by relevance | [model.md](model.md) | | `bl monitor delivery disable` | Console | Disable monitor delivery for all models in the workspace | [monitor.md](monitor.md) | -| `bl monitor delivery enable` | Console | Activate monitoring delivery: CMS SLR authorization, CMS service, and the dedicated Prometheus instance | [monitor.md](monitor.md) | +| `bl monitor delivery enable` | Console | Activate monitoring delivery: CMS SLR check, CMS service, and the dedicated Prometheus instance | [monitor.md](monitor.md) | | `bl monitor delivery status` | Console | Show monitoring delivery (Prometheus instance) status | [monitor.md](monitor.md) | | `bl monitor errors` | Console | Show failure breakdown by HTTP status code and error code | [monitor.md](monitor.md) | | `bl monitor metrics` | Console | Query time-series monitor metrics (RPM/TPM, latency percentiles, token usage) | [monitor.md](monitor.md) | diff --git a/skills/bailian-cli/reference/log.md b/skills/bailian-cli/reference/log.md index 00e031a3..74365ad1 100644 --- a/skills/bailian-cli/reference/log.md +++ b/skills/bailian-cli/reference/log.md @@ -11,12 +11,12 @@ Index: [index.md](index.md) | -------------------------- | -------------- | ------------------------------------------------------------------------------------------------------------------ | | `bl log audit count` | Console | Count model audit logs in a time range (useful before exporting) | | `bl log audit disable` | Console | Disable audit log delivery for all models in the workspace | -| `bl log audit enable` | Console | Enable audit log delivery to SLS (SLR authorization → SLS instance → log switch) | +| `bl log audit enable` | Console | Enable audit log delivery to SLS (SLR check → SLS instance → log switch) | | `bl log audit get` | Console | Show a single audit log entry with its raw origin record | | `bl log audit list` | Console | Query model audit logs (call metadata; request/response content is not recorded) | | `bl log inference count` | Console | Count model inference logs in a time range (useful before exporting) | | `bl log inference disable` | Console | Disable inference log delivery for all models in the workspace | -| `bl log inference enable` | Console | Enable inference log delivery to SLS (SLR authorization → SLS instance → log switch) | +| `bl log inference enable` | Console | Enable inference log delivery to SLS (SLR check → SLS instance → log switch) | | `bl log inference get` | Console | Show a single inference log entry with full request/response content | | `bl log inference list` | Console | Query model inference logs (requires inference log delivery; use `log inference get` for request/response content) | | `bl log status` | Console | Show model log delivery status (SLS authorization, audit / inference service and switches) | @@ -113,12 +113,12 @@ bl log audit disable --output json ### `bl log audit enable` -| Field | Value | -| ------------------ | -------------------------------------------------------------------------------- | -| **Name** | `log audit enable` | -| **Description** | Enable audit log delivery to SLS (SLR authorization → SLS instance → log switch) | -| **Authentication** | Console | -| **Usage** | `bl log audit enable [--no-wait] [flags]` | +| Field | Value | +| ------------------ | ------------------------------------------------------------------------ | +| **Name** | `log audit enable` | +| **Description** | Enable audit log delivery to SLS (SLR check → SLS instance → log switch) | +| **Authentication** | Console | +| **Usage** | `bl log audit enable [--no-wait] [flags]` | #### Flags @@ -132,7 +132,7 @@ bl log audit disable --output json #### Notes -- 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. - The audit log records call metadata only and is required before enabling the inference log. - Defaults to JSON, including when the Profile default is text. Use --output text or DASHSCOPE_OUTPUT=text to select text explicitly. - When a workspace is selected, its tenantId is resolved as switchAgent before any business request, overriding --console-switch-agent for this invocation only. Preflight, polling and follow-up requests share this identity; saved configuration is unchanged. @@ -350,12 +350,12 @@ bl log inference disable --output json ### `bl log inference enable` -| Field | Value | -| ------------------ | ------------------------------------------------------------------------------------ | -| **Name** | `log inference enable` | -| **Description** | Enable inference log delivery to SLS (SLR authorization → SLS instance → log switch) | -| **Authentication** | Console | -| **Usage** | `bl log inference enable [--no-wait] [flags]` | +| Field | Value | +| ------------------ | ---------------------------------------------------------------------------- | +| **Name** | `log inference enable` | +| **Description** | Enable inference log delivery to SLS (SLR check → SLS instance → log switch) | +| **Authentication** | Console | +| **Usage** | `bl log inference enable [--no-wait] [flags]` | #### Flags @@ -369,7 +369,7 @@ bl log inference disable --output json #### Notes -- 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. - Requires the audit log to be enabled first (`log audit enable`) — the console enforces the same rule. - Defaults to JSON, including when the Profile default is text. Use --output text or DASHSCOPE_OUTPUT=text to select text explicitly. - When a workspace is selected, its tenantId is resolved as switchAgent before any business request, overriding --console-switch-agent for this invocation only. Preflight, polling and follow-up requests share this identity; saved configuration is unchanged. diff --git a/skills/bailian-cli/reference/monitor.md b/skills/bailian-cli/reference/monitor.md index ef693af0..f99db9d7 100644 --- a/skills/bailian-cli/reference/monitor.md +++ b/skills/bailian-cli/reference/monitor.md @@ -7,15 +7,15 @@ Index: [index.md](index.md) ## Commands in this group -| Command | Authentication | Description | -| ----------------------------- | -------------- | ------------------------------------------------------------------------------------------------------- | -| `bl monitor delivery disable` | Console | Disable monitor delivery for all models in the workspace | -| `bl monitor delivery enable` | Console | Activate monitoring delivery: CMS SLR authorization, CMS service, and the dedicated Prometheus instance | -| `bl monitor delivery status` | Console | Show monitoring delivery (Prometheus instance) status | -| `bl monitor errors` | Console | Show failure breakdown by HTTP status code and error code | -| `bl monitor metrics` | Console | Query time-series monitor metrics (RPM/TPM, latency percentiles, token usage) | -| `bl monitor models` | Console | List per-model / per-API-key call statistics with server-side sort and paging | -| `bl monitor overview` | Console | Show aggregated model call statistics (calls, failures, latency, token usage) | +| Command | Authentication | Description | +| ----------------------------- | -------------- | ----------------------------------------------------------------------------------------------- | +| `bl monitor delivery disable` | Console | Disable monitor delivery for all models in the workspace | +| `bl monitor delivery enable` | Console | Activate monitoring delivery: CMS SLR check, CMS service, and the dedicated Prometheus instance | +| `bl monitor delivery status` | Console | Show monitoring delivery (Prometheus instance) status | +| `bl monitor errors` | Console | Show failure breakdown by HTTP status code and error code | +| `bl monitor metrics` | Console | Query time-series monitor metrics (RPM/TPM, latency percentiles, token usage) | +| `bl monitor models` | Console | List per-model / per-API-key call statistics with server-side sort and paging | +| `bl monitor overview` | Console | Show aggregated model call statistics (calls, failures, latency, token usage) | ## Command details @@ -59,12 +59,12 @@ bl monitor delivery disable --output json ### `bl monitor delivery enable` -| Field | Value | -| ------------------ | ------------------------------------------------------------------------------------------------------- | -| **Name** | `monitor delivery enable` | -| **Description** | Activate monitoring delivery: CMS SLR authorization, CMS service, and the dedicated Prometheus instance | -| **Authentication** | Console | -| **Usage** | `bl monitor delivery enable [--no-wait] [flags]` | +| Field | Value | +| ------------------ | ----------------------------------------------------------------------------------------------- | +| **Name** | `monitor delivery enable` | +| **Description** | Activate monitoring delivery: CMS SLR check, CMS service, and the dedicated Prometheus instance | +| **Authentication** | Console | +| **Usage** | `bl monitor delivery enable [--no-wait] [flags]` | #### Flags @@ -78,7 +78,7 @@ bl monitor delivery disable --output json #### Notes -- 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. - Defaults to JSON, including when the Profile default is text. Use --output text or DASHSCOPE_OUTPUT=text to select text explicitly. - When a workspace is selected, its tenantId is resolved as switchAgent before any business request, overriding --console-switch-agent for this invocation only. Preflight, polling and follow-up requests share this identity; saved configuration is unchanged. diff --git a/skills/bailian-finetune/SKILL.md b/skills/bailian-finetune/SKILL.md index 8cb9dd57..a94c993d 100644 --- a/skills/bailian-finetune/SKILL.md +++ b/skills/bailian-finetune/SKILL.md @@ -1,7 +1,7 @@ --- name: bailian-finetune metadata: - version: "2.10.1" + version: "2.10.2" requires: bins: ["bl"] description: >- diff --git a/skills/bailian-gen/SKILL.md b/skills/bailian-gen/SKILL.md index 7fc43822..c091e7b8 100644 --- a/skills/bailian-gen/SKILL.md +++ b/skills/bailian-gen/SKILL.md @@ -1,7 +1,7 @@ --- name: bailian-gen metadata: - version: "2.10.1" + version: "2.10.2" requires: bins: ["bl"] description: >- diff --git a/skills/bailian-knowledge/SKILL.md b/skills/bailian-knowledge/SKILL.md index e55e5c49..f34bcf50 100644 --- a/skills/bailian-knowledge/SKILL.md +++ b/skills/bailian-knowledge/SKILL.md @@ -1,7 +1,7 @@ --- name: bailian-knowledge metadata: - version: "2.10.1" + version: "2.10.2" requires: bins: ["bl"] description: >- diff --git a/skills/bailian-managed-agent/SKILL.md b/skills/bailian-managed-agent/SKILL.md index 25fbe5b2..9d9e4593 100644 --- a/skills/bailian-managed-agent/SKILL.md +++ b/skills/bailian-managed-agent/SKILL.md @@ -1,7 +1,7 @@ --- name: bailian-managed-agent metadata: - version: "2.10.1" + version: "2.10.2" requires: bins: ["bl"] description: >- diff --git a/skills/bailian-memory/SKILL.md b/skills/bailian-memory/SKILL.md index efbac953..abebdd83 100644 --- a/skills/bailian-memory/SKILL.md +++ b/skills/bailian-memory/SKILL.md @@ -1,7 +1,7 @@ --- name: bailian-memory metadata: - version: "2.10.1" + version: "2.10.2" requires: bins: ["bl"] description: >- diff --git a/skills/bailian-protocol/SKILL.md b/skills/bailian-protocol/SKILL.md index 93d746f3..06255b96 100644 --- a/skills/bailian-protocol/SKILL.md +++ b/skills/bailian-protocol/SKILL.md @@ -1,7 +1,7 @@ --- name: bailian-protocol metadata: - version: "2.10.1" + version: "2.10.2" requires: bins: ["bl"] description: >- diff --git a/skills/bailian-sandbox/SKILL.md b/skills/bailian-sandbox/SKILL.md index ccf5f71b..0d066d47 100644 --- a/skills/bailian-sandbox/SKILL.md +++ b/skills/bailian-sandbox/SKILL.md @@ -1,7 +1,7 @@ --- name: bailian-sandbox metadata: - version: "2.10.1" + version: "2.10.2" requires: bins: ["bl"] description: >- diff --git a/skills/bailian-web-search/SKILL.md b/skills/bailian-web-search/SKILL.md index d9880755..767bf2ff 100644 --- a/skills/bailian-web-search/SKILL.md +++ b/skills/bailian-web-search/SKILL.md @@ -1,7 +1,7 @@ --- name: bailian-web-search metadata: - version: "2.10.1" + version: "2.10.2" requires: bins: ["bl"] description: >-