|
| 1 | +import { |
| 2 | + CONSOLE_DATASET_GROUPS_API, |
| 3 | + buildConsoleDatasetGroupsRequest, |
| 4 | + listConsoleDatasetGroups, |
| 5 | +} from "bailian-cli-core"; |
| 6 | +import { defineConsoleReadCommand, consoleReadTargetPreview } from "../shared/console-read.ts"; |
| 7 | + |
| 8 | +export default defineConsoleReadCommand({ |
| 9 | + auth: "console", |
| 10 | + description: { |
| 11 | + "en-US": "List Console dataset groups", |
| 12 | + "zh-CN": "查询 Console 数据集组列表", |
| 13 | + }, |
| 14 | + usageArgs: "[--page <n>] [--page-size <n>] [--name <name>]", |
| 15 | + flags: { |
| 16 | + page: { |
| 17 | + type: "number", |
| 18 | + valueHint: "<n>", |
| 19 | + description: { |
| 20 | + "en-US": "Page number, a positive safe integer (default: 1)", |
| 21 | + "zh-CN": "页码,正安全整数(默认:1)", |
| 22 | + }, |
| 23 | + }, |
| 24 | + pageSize: { |
| 25 | + type: "number", |
| 26 | + valueHint: "<n>", |
| 27 | + description: { |
| 28 | + "en-US": "Groups per page, a positive safe integer (default: 10)", |
| 29 | + "zh-CN": "每页组数,正安全整数(默认:10)", |
| 30 | + }, |
| 31 | + }, |
| 32 | + name: { |
| 33 | + type: "string", |
| 34 | + valueHint: "<name>", |
| 35 | + description: { |
| 36 | + "en-US": "Nonblank dataset group name for server-side filtering; trimmed before sending", |
| 37 | + "zh-CN": "用于服务端筛选的非空白数据集组名称,去除首尾空白后传递", |
| 38 | + }, |
| 39 | + }, |
| 40 | + }, |
| 41 | + exampleArgs: ["", "--page 2 --page-size 20", "--name example-dataset --dry-run"], |
| 42 | + notes: [ |
| 43 | + { |
| 44 | + "en-US": |
| 45 | + "Fetches only the requested page. records contains dataset groups; items is the server's total count for the query. All business-response fields are preserved. The API Key / file_id semantics of dataset list are unchanged.", |
| 46 | + "zh-CN": |
| 47 | + "仅获取请求的当前页。records 为数据集组列表,items 为服务端返回的查询总数。保留所有业务响应字段,不改变 dataset list 的 API Key / file_id 语义。", |
| 48 | + }, |
| 49 | + { |
| 50 | + "en-US": |
| 51 | + "Each group's datasets is only a one-version preview, not its complete version list. Pass datasetGroupId to dataset version --dataset-group-id for {result:[...]} (no completeness guarantee or pagination); use dataset version --dataset-id with a version's datasetId for details (--include-status is detail-only). Exactly one ID flag is required; they cannot be combined. fileId is not datasetId.", |
| 52 | + "zh-CN": |
| 53 | + "各组的 datasets 仅是一条版本预览,不是完整版本列表。将 datasetGroupId 传给 dataset version --dataset-group-id,返回 {result:[...]}(不保证全量,无分页);查询详情用 dataset version --dataset-id,传入版本的 datasetId,仅此模式可加 --include-status。两个 ID 参数必选一个且不能同传。fileId 不是 datasetId。", |
| 54 | + }, |
| 55 | + { |
| 56 | + "en-US": |
| 57 | + "--name is trimmed and sent to the server without local filtering. No type filter is hardcoded, but server-side scope and defaults still affect results; this is not an account-wide exhaustive listing. There is no --all option.", |
| 58 | + "zh-CN": |
| 59 | + "--name 去除首尾空白后交由服务端筛选,不做本地筛选。不硬编码类型过滤,但服务端作用域与默认条件仍影响结果,不代表整个账号的全量列表。不提供 --all 选项。", |
| 60 | + }, |
| 61 | + { |
| 62 | + "en-US": |
| 63 | + "The preview requests one import task per version, without guaranteeing the latest task or all tasks. Status codes are preserved as returned; no release, validation, or training readiness is inferred.", |
| 64 | + "zh-CN": |
| 65 | + "预览为每个版本请求一条导入任务,不保证是最新任务或涵盖全部任务。保留返回的状态原码,不据此判断发布、校验或训练就绪。", |
| 66 | + }, |
| 67 | + ], |
| 68 | + validate(flags) { |
| 69 | + if (flags.page !== undefined && (!Number.isSafeInteger(flags.page) || flags.page < 1)) { |
| 70 | + return { |
| 71 | + "en-US": "--page must be a positive safe integer.", |
| 72 | + "zh-CN": "--page 必须为正安全整数。", |
| 73 | + }; |
| 74 | + } |
| 75 | + if ( |
| 76 | + flags.pageSize !== undefined && |
| 77 | + (!Number.isSafeInteger(flags.pageSize) || flags.pageSize < 1) |
| 78 | + ) { |
| 79 | + return { |
| 80 | + "en-US": "--page-size must be a positive safe integer.", |
| 81 | + "zh-CN": "--page-size 必须为正安全整数。", |
| 82 | + }; |
| 83 | + } |
| 84 | + if (flags.name !== undefined && !flags.name.trim()) { |
| 85 | + return { |
| 86 | + "en-US": "--name must not be blank when provided.", |
| 87 | + "zh-CN": "传入的 --name 不能仅包含空白或为空。", |
| 88 | + }; |
| 89 | + } |
| 90 | + return undefined; |
| 91 | + }, |
| 92 | + async run(ctx) { |
| 93 | + const params = { |
| 94 | + page: ctx.flags.page ?? 1, |
| 95 | + pageSize: ctx.flags.pageSize ?? 10, |
| 96 | + name: ctx.flags.name?.trim(), |
| 97 | + }; |
| 98 | + if (ctx.settings.dryRun) { |
| 99 | + const preview = { |
| 100 | + action: "dataset.groups", |
| 101 | + api: CONSOLE_DATASET_GROUPS_API, |
| 102 | + data: buildConsoleDatasetGroupsRequest(params), |
| 103 | + ...consoleReadTargetPreview(ctx.settings), |
| 104 | + }; |
| 105 | + ctx.output.result(preview, { text: JSON.stringify(preview, null, 2) }); |
| 106 | + return; |
| 107 | + } |
| 108 | + const response = await listConsoleDatasetGroups(ctx.client, params); |
| 109 | + ctx.output.result(response, { text: JSON.stringify(response, null, 2) }); |
| 110 | + }, |
| 111 | +}); |
0 commit comments