From 29ce8990b9fe71edcc6ff29cfcb1d30b6ced513a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=A5=E9=BA=92?= Date: Thu, 13 Aug 2026 17:54:35 +0800 Subject: [PATCH] fix(runtime): accept localized Command Pack descriptions --- .../cli/tests/fixtures/command-pack/commands.mjs | 5 ++++- packages/runtime/src/command-packs/validate.ts | 14 +++++++++++++- packages/runtime/tests/command-packs.test.ts | 4 ++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/cli/tests/fixtures/command-pack/commands.mjs b/packages/cli/tests/fixtures/command-pack/commands.mjs index c6ba846..698c1b3 100644 --- a/packages/cli/tests/fixtures/command-pack/commands.mjs +++ b/packages/cli/tests/fixtures/command-pack/commands.mjs @@ -1,5 +1,8 @@ const ping = { - description: "Ping the Command Pack fixture", + description: { + "en-US": "Ping the Command Pack fixture", + "zh-CN": "调用 Command Pack 测试命令", + }, auth: "none", flags: { message: { diff --git a/packages/runtime/src/command-packs/validate.ts b/packages/runtime/src/command-packs/validate.ts index 6d231a9..79e47d4 100644 --- a/packages/runtime/src/command-packs/validate.ts +++ b/packages/runtime/src/command-packs/validate.ts @@ -5,6 +5,7 @@ import { BailianError, COMMAND_PACK_API_VERSION, ExitCode, + SUPPORTED_LANGUAGES, UsageError, formatOutput, type AnyCommand, @@ -12,6 +13,7 @@ import { type CommandPackCommand, type CommandPackMeta, type Identity, + type LocalizedText, } from "bailian-cli-core"; import { CommandRegistry } from "../registry.ts"; import { compareVersion } from "../utils/update-checker.ts"; @@ -67,12 +69,22 @@ function assertCommandPath(path: string, definition: CommandPackDefinition): voi } } +function isLocalizedText(value: unknown): value is LocalizedText { + if (typeof value === "string") return value.length > 0; + if (!value || typeof value !== "object" || Array.isArray(value)) return false; + + const localizedText = value as Record; + return SUPPORTED_LANGUAGES.every( + (language) => typeof localizedText[language] === "string" && localizedText[language].length > 0, + ); +} + function assertCommand(path: string, value: unknown): asserts value is CommandPackCommand { if (!value || typeof value !== "object") { throw new Error(`Command "${path}" must export an object.`); } const command = value as Partial>; - if (!command.description || typeof command.description !== "string") { + if (!isLocalizedText(command.description)) { throw new Error(`Command "${path}" is missing a description.`); } if (!command.auth || !AUTH_REQUIREMENTS.has(command.auth)) { diff --git a/packages/runtime/tests/command-packs.test.ts b/packages/runtime/tests/command-packs.test.ts index 6ea9dca..fe227f4 100644 --- a/packages/runtime/tests/command-packs.test.ts +++ b/packages/runtime/tests/command-packs.test.ts @@ -147,6 +147,10 @@ test("loads an API 1 Command Pack and preserves its command contract", async () ]); expect(commands["agent credential"]?.auth).toBe("apiKey"); expect(commands["agent ping"]?.auth).toBe("none"); + expect(commands["agent ping"]?.description).toEqual({ + "en-US": "Ping the Command Pack fixture", + "zh-CN": "调用 Command Pack 测试命令", + }); expect(commands["agent ping"]?.flags?.message).toMatchObject({ required: true, type: "string" }); });