@qingflow-tech/qingflow-cli 1.0.33 → 1.0.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,13 +3,13 @@
3
3
  Install:
4
4
 
5
5
  ```bash
6
- npm install @qingflow-tech/qingflow-cli@1.0.33
6
+ npm install @qingflow-tech/qingflow-cli@1.0.34
7
7
  ```
8
8
 
9
9
  Run:
10
10
 
11
11
  ```bash
12
- npx -y -p @qingflow-tech/qingflow-cli@1.0.33 qingflow
12
+ npx -y -p @qingflow-tech/qingflow-cli@1.0.34 qingflow
13
13
  ```
14
14
 
15
15
  Environment:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qingflow-tech/qingflow-cli",
3
- "version": "1.0.33",
3
+ "version": "1.0.34",
4
4
  "description": "Human-friendly Qingflow command line interface for auth, record operations, import, tasks, and stable builder flows.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/pyproject.toml CHANGED
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "qingflow-mcp"
7
- version = "1.0.33"
7
+ version = "1.0.34"
8
8
  description = "User-authenticated MCP server for Qingflow"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -10,7 +10,7 @@ description: |
10
10
 
11
11
  **硬约束(必读)**:正文各节与文末「命令速查」中的命令**只作子命令形态索引**,不覆盖 JSON 结构、`--*-file` 键名、枚举全集、执行顺序与排障细节。凡工作**偏复杂**(多步串联、大块 payload、导入全链、**Builder 搭建向**(应用/schema/流程/布局/视图/门户/报表/按钮/关联资源的配置与发布、系统列与字段 `type`)、契约型 `apply`、按 schema 组织写入 payload、任务下钻与 `task action` 等),或你判断当前任务与「关联文件」里某篇所描述的内容**需求一致、场景相同或大体同类**,都应**先 Read 对应 `reference/*.md`**,再结合 `qingflow … --help` 与 **[EXPLORATION_REPORT](./reference/QINGFLOW_CLI_EXPLORATION_REPORT.md)**。**禁止**仅凭索引、习惯或类比去补参数、臆造字段名或推断服务端行为。**最终统计结论、分析报告、趋势/排名/比例/分布等数据分析,必须转交 `qingflow-record-analysis`,统一走 `record_access -> Python/pandas`。**
12
12
 
13
- > **CLI**:当前验证包为 `@qingflow-tech/qingflow-cli`(查版本优先用 `qingflow --version`;需要 JSON 时用 `qingflow --json version`)。**搭建/创建/系统配置**:凡要**搭应用、改字段与流程、做门户与报表、走发布校验**(非单纯查列表、写记录),优先在 **「关联文件」** 中按 **[APP_DELIVERY](./reference/QINGFLOW_CLI_BUILDER_APP_DELIVERY_WORKFLOW.md)** → **[VIEWS](./reference/QINGFLOW_CLI_BUILDER_VIEWS_WORKFLOW.md)** / **[PORTAL](./reference/QINGFLOW_CLI_BUILDER_PORTAL_WORKFLOW.md)** / **[CHARTS](./reference/QINGFLOW_CLI_BUILDER_CHARTS_WORKFLOW.md)** 选读;仅成员读数速通仍可先打开 **[MEMBER_CHEATSHEET](./reference/QINGFLOW_CLI_MEMBER_CHEATSHEET.md)**。
13
+ > **CLI**:当前验证包为 `@qingflow-tech/qingflow-cli`(查版本优先用 `qingflow --version`;需要 JSON 时用 `qingflow --json version`)。**搭建/创建/系统配置**:先区分 **完整系统/应用包** 与 **单应用**。完整系统必须走 `builder package apply -> builder schema apply --apps-file`,单应用才走 `builder schema apply --app-key` 或 `--package-id --app-name --create-if-missing`;随后再按 **[APP_DELIVERY](./reference/QINGFLOW_CLI_BUILDER_APP_DELIVERY_WORKFLOW.md)** → **[VIEWS](./reference/QINGFLOW_CLI_BUILDER_VIEWS_WORKFLOW.md)** / **[PORTAL](./reference/QINGFLOW_CLI_BUILDER_PORTAL_WORKFLOW.md)** / **[CHARTS](./reference/QINGFLOW_CLI_BUILDER_CHARTS_WORKFLOW.md)** 选读。仅成员读数速通仍可先打开 **[MEMBER_CHEATSHEET](./reference/QINGFLOW_CLI_MEMBER_CHEATSHEET.md)**。
14
14
 
15
15
  ## 关联文件
16
16
 
@@ -419,7 +419,7 @@ qingflow auth logout --forget-persisted
419
419
  | **app / portal / view / chart** | `app list [--query 关键词]` → **`app get --app-key`**(`accessible_views` / `view_id`、`import_capability`)· `builder package list [--query 关键词]` → `builder package get --package-id` · `portal list` · `portal get --dash-key` · `view get --view-id`(只读视图元信息;`baseInfo` 或 `viewConfig` 只有 40002 / 40027 / 404 这类权限/缺失边界可用另一侧降级,非权限类后端错误不隐藏;解析 app 仅依赖同源 view/form 与可见应用树,不回退旧应用搜索)· `chart get --chart-id`(图表 `baseInfo` / 数据 / 配置分阶段读取;单个辅助阶段 40002 / 40027 / 404 只作为 warning,非权限类后端错误不隐藏) |
420
420
  | **record** | `record schema insert`(新建记录 insert-ready schema,仅 `--app-key`)· **`browse`/`list`/`access`:`--app-key` + `--view-id`(缺一常 CONFIG)** · `record list --query ... [--query-field FIELD_ID] [--page-size N]` 用于候选定位/样本浏览 · `record get --record-id` 读详情页首屏上下文 · `record logs --record-id` 读完整数据/流程日志 JSONL · `record insert --items-file`(单条也是 items 一行)· `schema update --record-id [--view-id]` / **`update`**(单条 `--fields-file` **或** 批量 `--items-file`/`--dry-run`,二者勿混)· `export start/direct --view-id` 仅用于明确导出文件 · **`delete`/大 schema**:先 **[FIELD_DATA_TYPES](./reference/QINGFLOW_CLI_FIELD_DATA_TYPES.md)** / **[RECORD_CREATE](./reference/QINGFLOW_CLI_RECORD_CREATE_WORKFLOW.md)** / **[RECORD_UPDATE](./reference/QINGFLOW_CLI_RECORD_UPDATE_WORKFLOW.md)**,再 `-h` |
421
421
  | **import** | `record schema import?` · `import template` → `verify` → `repair?` → `start`(**`being-enter-auditing` 必填**)→ `status`(**三者 selector 只选一**);导入权限预检的 `baseInfo` 只有 40002 / 40027 / 404 可降级为 unknown,非权限错误不能当成无导入权或继续执行;**链路与本机目录**只靠本节不够 → **[RECORD_IMPORT](./reference/QINGFLOW_CLI_RECORD_IMPORT_WORKFLOW.md)** |
422
- | **builder** | **搭建/系统化配置**:`builder contract`、`builder icon catalog`、`app resolve`、`app get`(summary / fields / layout / views / flow / charts)、`schema`/`layout`/`flow apply`、`views apply`、`button apply`、`associated-resource apply`、`portal apply`、`portal delete`、`charts apply`、`publish verify`;与普通读数/`record insert` 不是同一路径 → **[APP_DELIVERY](./reference/QINGFLOW_CLI_BUILDER_APP_DELIVERY_WORKFLOW.md)**、[ICONS](./reference/QINGFLOW_CLI_BUILDER_WORKSPACE_ICONS.md)、[VIEWS](./reference/QINGFLOW_CLI_BUILDER_VIEWS_WORKFLOW.md)、[PORTAL](./reference/QINGFLOW_CLI_BUILDER_PORTAL_WORKFLOW.md)、[CHARTS](./reference/QINGFLOW_CLI_BUILDER_CHARTS_WORKFLOW.md) |
422
+ | **builder** | **搭建/系统化配置**:先读 `builder contract`。**完整系统/应用包**:`builder package apply --config-file` → `builder schema apply --apps-file`(`--apps-file` 可为数组或 `{package_id, apps}` 对象;同批 relation 用 `target_app_ref` 或 `target_app`)→ layout/views/flow/portal/charts。**单应用**:`app resolve/get` → `schema/layout/flow/views apply`。图标可用 `icon/color`、`icon_name/icon_color`、`icon_config` 或 `icon:{name,color}`;选择字段 `options` 可用字符串数组或 `{label,value}` 对象数组。与普通读数/`record insert` 不是同一路径 → **[APP_DELIVERY](./reference/QINGFLOW_CLI_BUILDER_APP_DELIVERY_WORKFLOW.md)**、[ICONS](./reference/QINGFLOW_CLI_BUILDER_WORKSPACE_ICONS.md)、[VIEWS](./reference/QINGFLOW_CLI_BUILDER_VIEWS_WORKFLOW.md)、[PORTAL](./reference/QINGFLOW_CLI_BUILDER_PORTAL_WORKFLOW.md)、[CHARTS](./reference/QINGFLOW_CLI_BUILDER_CHARTS_WORKFLOW.md) |
423
423
  | **task**(须落盘见上文) | `task list [--task-box][--flow-status][--app-key][--query] --page --page-size`(**枚举、`--query`、与 `record` 视图口径勿混**:见上文 SOP · **[TASK_CONTEXT](./reference/QINGFLOW_CLI_TASK_CONTEXT_WORKFLOW.md)**)· **`get`/`log`/`report`/`action`**:默认只传 `task list` 返回的 **`data.items[].task_id`**;`report` 另须必选 **`--report-id`**;`action` **无 `--dry-run`** |
424
424
 
425
425
  **高发必败**:旧应用搜索入口 · **`record list`/`browse`/`access` 缺 `--view-id`** · **`task report` 缺 `--report-id`** · **`record update` 批量与单条参数混用**。
@@ -138,13 +138,14 @@ qingflow builder schema apply \
138
138
  --apps-file tmp/apps.json
139
139
  ```
140
140
 
141
- `apps.json` 是数组,每项是一个应用 schema 配置;同批应用之间的关联字段用 `target_app_ref` 指向另一个应用的 `client_key`:
141
+ `apps.json` 可以是数组,也可以是 `{ "package_id": 123, "apps": [...] }` 对象。每个 `apps[]` 是一个应用 schema 配置;同批应用之间的关联字段用 `target_app_ref` 指向另一个应用的 `client_key`,或用 `target_app` 指向另一个 `app_name`:
142
142
 
143
143
  ```json
144
144
  [
145
145
  {
146
146
  "client_key": "employee",
147
147
  "app_name": "员工花名册",
148
+ "icon": {"name": "business-personalcard", "color": "emerald"},
148
149
  "add_fields": [
149
150
  {"name": "员工名称", "type": "text", "as_data_title": true}
150
151
  ]
@@ -152,6 +153,7 @@ qingflow builder schema apply \
152
153
  {
153
154
  "client_key": "worklog",
154
155
  "app_name": "工时表",
156
+ "icon": {"name": "clock", "color": "blue"},
155
157
  "add_fields": [
156
158
  {"name": "工时标题", "type": "text", "as_data_title": true},
157
159
  {
@@ -169,7 +171,7 @@ qingflow builder schema apply \
169
171
  - 返回里看 `mode=multi_app`、`apps[].app_key`、`created_app_keys` 和 `apps[].status`。
170
172
  - 多应用 schema apply 不做事务回滚;如果部分失败,只补失败的 `apps[].row_number`,不要整批重复提交。
171
173
  - 这个模式只负责应用壳与字段;视图、按钮、关联资源、报表仍拿返回的 `app_key` 继续走各自 apply 工具。
172
- - 同批 `relation` 优先用 `target_app_ref` 指向 `client_key`;不要先分别建应用、再为了补 `target_app_key` 做第二轮字段修补。
174
+ - 同批 `relation` 优先用 `target_app_ref` 指向 `client_key`;也可用 `target_app` 指向同批 `app_name`。不要先分别建应用、再为了补 `target_app_key` 做第二轮字段修补。
173
175
 
174
176
  **`visibility` JSON**(`--visibility-file`):与包/应用通用,键见契约 `allowed_values.visibility.*`:
175
177
 
@@ -271,7 +273,7 @@ qingflow builder flow apply \
271
273
  | **`datetime`** | 同上。 |
272
274
  | **`member`** | **`name`**、**`required`**;成员选择器,无额外 scope 键(与 **department** 不同)。 |
273
275
  | **`department`** | **`department_scope`**:`mode: all \| custom`;**`custom`** 时 **`departments[]`** 须含 **`dept_id`**(可选 **`dept_name`** 辅助)、**`include_sub_departs`**。 |
274
- | **`single_select`** / **`multi_select`** | **`options` 必须是字符串数组**,如 `["A", "B"]`;不要写成对象数组、`label/value`、`name/value` 或嵌套结构;可选 **`required`**。 |
276
+ | **`single_select`** / **`multi_select`** | **`options` 可用字符串数组**,如 `["A", "B"]`,也可用对象数组如 `[{"label":"A","value":"a"}]`;工具会归一化为选项文案。可选 **`required`**。 |
275
277
  | **`phone`** / **`email`** | 标准校验类字段,**`name` + required**。 |
276
278
  | **`address`** | 地址复合字段。 |
277
279
  | **`attachment`** | 附件。 |
@@ -17,7 +17,7 @@ qingflow --json builder icon catalog
17
17
  ## 关键规则
18
18
 
19
19
  - CLI 不会根据业务名称自动猜图标。
20
- - 智能体必须自己选择业务贴合的 `icon + color`。
20
+ - 智能体必须自己选择业务贴合的图标和颜色;CLI/MCP 可接受 `icon + color`、`icon_name + icon_color`、`icon_config` 或 `icon: {name, color}`,最终都会归一化为 `icon/color`。
21
21
  - 创建应用包、应用、门户时缺少 `icon` 或 `color` 会失败。
22
22
  - 同批多应用创建时,每个新应用应使用不同 `icon`。
23
23
  - 编辑已有资源时,不传 `icon/color` 会保留现状;显式传入时仍会校验合法性。
@@ -41,7 +41,7 @@
41
41
 
42
42
  | `type` | 通常必填 | 常见可选 / 约束 |
43
43
  |--------|----------|-----------------|
44
- | 标量与选择器 | `name` + `type`(+ 业务 `required` 等) | `description`、`required`;新建应用时其中一个顶层可读字段须 `as_data_title: true`;**`single_select` / `multi_select` 的 `options` 必须是字符串数组**,如 `["A", "B"]`,不要写对象数组或 `label/value` |
44
+ | 标量与选择器 | `name` + `type`(+ 业务 `required` 等) | `description`、`required`;新建应用时其中一个顶层可读字段须 `as_data_title: true`;**`single_select` / `multi_select` 的 `options` 可用字符串数组或对象数组**,如 `["A", "B"]` 或 `[{"label":"A","value":"a"}]`,工具会归一化为选项文案 |
45
45
  | `department` | 同左 | **`department_scope`**:`mode: all \| custom`;`custom` 时 **`departments[]`**(含 `dept_id` 等) |
46
46
  | `relation` | **`target_app_key`**、**`display_field`**、**`visible_fields[]`** | **`relation_mode`**;目标应用元数据不可读时可多写 **`name`** 降级 |
47
47
  | `subtable` | **`subfields[]` 非空** | 子列递归同父级规则;更新已存在子列优先契约 **`subfield_updates`** |
@@ -58,7 +58,7 @@
58
58
  |------|----------------|------|
59
59
  | 编辑已有应用 | `--app-key`;可选 `--no-publish` | **不要**与 `--package-id`、`--create-if-missing` 同用 |
60
60
  | 包内新建应用 | `--package-id`、`--app-name`(或 title 映射)、**`--create-if-missing`**;初始 `add-fields-file` 至少包含一个 `as_data_title: true` 字段 | 创建后可得到新 **`app_key`**(以响应为准) |
61
- | 多应用一次性新建 | `--package-id`、**`--create-if-missing`**、`--apps-file` | 应用包/系统里有 2 个以上应用,或同批应用之间有 `relation` 时使用;`apps[].client_key` 可被 `target_app_ref` 引用 |
61
+ | 多应用一次性新建 | `--package-id`、**`--create-if-missing`**、`--apps-file` | 应用包/系统里有 2 个以上应用,或同批应用之间有 `relation` 时使用;`--apps-file` 可为数组或 `{package_id, apps}` 对象;`apps[].client_key` 可被 `target_app_ref` 引用,`apps[].app_name` 可被 `target_app` 引用 |
62
62
  | 仅增字段 | `--add-fields-file`(JSON 数组) | 与 **`update_fields`/`remove_fields`** 可同次组合(以契约为准) |
63
63
  | 改字段 | `--update-fields-file` | 每项 **`selector`**(`name`/`que_id`/`field_id`)+ **`set`** |
64
64
  | 删字段 | `--remove-fields-file` | 每项至少 **`name`/`que_id`/`field_id`** 之一 |
@@ -82,7 +82,7 @@
82
82
 
83
83
  **一次性新建应用**:`--package-id` + `--app-name` + `--create-if-missing` + [schema_apply_add_fields_all_types.json](./schema_apply_add_fields_all_types.json) 是当前推荐示例;它已包含唯一数据标题和可选数据封面(`q_linker` 使用 `https://httpbin.org/get`,`relation` 指向可读模板应用 `ead8ims5i401`)。
84
84
 
85
- **一次性新建多个应用**:用 `builder schema apply --package-id <TAG_ID> --create-if-missing --apps-file tmp/apps.json`;`apps[].client_key` 可被同批 relation 字段的 `target_app_ref` 引用,工具会编译成真实 `target_app_key`。这是应用包/系统搭建的默认路径,尤其适合“商机 + 订单 + 回款”“花名册 + 工时”等互相关联场景;不要为了拿 `app_key` 先逐个创建再二次补关联字段。
85
+ **一次性新建多个应用**:用 `builder schema apply --package-id <TAG_ID> --create-if-missing --apps-file tmp/apps.json`;`apps[].client_key` 可被同批 relation 字段的 `target_app_ref` 引用,`apps[].app_name` 可被 `target_app` 引用,工具会编译成真实 `target_app_key`。这是应用包/系统搭建的默认路径,尤其适合“商机 + 订单 + 回款”“花名册 + 工时”等互相关联场景;不要为了拿 `app_key` 先逐个创建再二次补关联字段。
86
86
 
87
87
  **限制(平台硬性)**:每应用 **至多一个** `relation`;`--app-key` 向已有应用追加时须 **字段名不重复**、且 **不能**在已有 relation 上再增第二个。**`example.com`** 作 `q_linker` URL 易触发 **`46031`**,本清单改用 httpbin。**读回缺 `outputs[].target_field` 的 `q_linker`** 会拖死后续 `schema apply`,须修复或删除该题。
88
88
 
@@ -2292,6 +2292,8 @@ def _normalize_field_payload(value: Any) -> Any:
2292
2292
  payload = dict(value)
2293
2293
  if "fields" in payload and "subfields" not in payload:
2294
2294
  payload["subfields"] = payload.pop("fields")
2295
+ if "options" in payload:
2296
+ payload["options"] = _normalize_field_options(payload.get("options"))
2295
2297
  raw_type = payload.get("type")
2296
2298
  if isinstance(raw_type, int):
2297
2299
  normalized_from_id = FIELD_TYPE_ID_ALIASES.get(raw_type)
@@ -2324,6 +2326,34 @@ def _normalize_field_payload(value: Any) -> Any:
2324
2326
  return payload
2325
2327
 
2326
2328
 
2329
+ def _normalize_field_options(value: Any) -> Any:
2330
+ if not isinstance(value, list):
2331
+ return value
2332
+ normalized: list[str] = []
2333
+ for item in value:
2334
+ if isinstance(item, str):
2335
+ normalized.append(item)
2336
+ continue
2337
+ if isinstance(item, (int, float, bool)):
2338
+ normalized.append(str(item))
2339
+ continue
2340
+ if isinstance(item, dict):
2341
+ label = (
2342
+ item.get("label")
2343
+ or item.get("name")
2344
+ or item.get("title")
2345
+ or item.get("value")
2346
+ or item.get("text")
2347
+ or item.get("optValue")
2348
+ or item.get("optName")
2349
+ )
2350
+ if label is not None:
2351
+ normalized.append(str(label))
2352
+ continue
2353
+ normalized.append(str(item))
2354
+ return normalized
2355
+
2356
+
2327
2357
  def _slugify_title(title: str) -> str:
2328
2358
  normalized = "".join(ch.lower() if ch.isalnum() else "_" for ch in str(title or ""))
2329
2359
  collapsed = "_".join(part for part in normalized.split("_") if part)
@@ -4,6 +4,7 @@ import argparse
4
4
 
5
5
  from ..context import CliContext
6
6
  from .common import load_list_arg, load_object_arg, raise_config_error, require_list_arg
7
+ from ..json_io import load_json_value
7
8
 
8
9
 
9
10
  def register(subparsers: argparse._SubParsersAction[argparse.ArgumentParser]) -> None:
@@ -476,26 +477,30 @@ def _handle_chart_get(args: argparse.Namespace, context: CliContext) -> dict:
476
477
 
477
478
 
478
479
  def _handle_schema_apply(args: argparse.Namespace, context: CliContext) -> dict:
479
- apps = load_list_arg(args.apps_file, option_name="--apps-file")
480
+ apps_payload = _load_apps_file_arg(args.apps_file)
481
+ apps = apps_payload["apps"]
482
+ package_id = args.package_id
483
+ if package_id is None and apps_payload.get("package_id") is not None:
484
+ package_id = int(apps_payload["package_id"])
480
485
  if args.apps_file:
481
486
  if not apps:
482
487
  raise_config_error(
483
488
  "schema apply multi-app mode requires a non-empty --apps-file.",
484
- fix_hint="Pass a JSON array with at least one app item.",
489
+ fix_hint="Pass a JSON array, or a JSON object like {\"package_id\":1001,\"apps\":[...]} with at least one app item.",
485
490
  )
486
491
  if args.app_key or args.app_name or args.app_title or args.add_fields_file or args.update_fields_file or args.remove_fields_file:
487
492
  raise_config_error(
488
493
  "schema apply multi-app mode accepts --package-id/--create-if-missing plus --apps-file only.",
489
494
  fix_hint="Use `--apps-file` for batch mode, or remove `--apps-file` and use the single-app arguments.",
490
495
  )
491
- if args.package_id is None:
496
+ if package_id is None:
492
497
  raise_config_error(
493
498
  "schema apply multi-app mode requires --package-id.",
494
- fix_hint="Pass `--package-id` and app names inside --apps-file.",
499
+ fix_hint="Pass `--package-id`, or put `package_id` at the top level of --apps-file. `package_name` alone does not create the package here; run `builder package apply` first.",
495
500
  )
496
501
  return context.builder.app_schema_apply(
497
502
  profile=args.profile,
498
- package_id=args.package_id,
503
+ package_id=package_id,
499
504
  visibility=load_object_arg(args.visibility_file, option_name="--visibility-file"),
500
505
  create_if_missing=bool(args.create_if_missing),
501
506
  publish=bool(args.publish),
@@ -537,6 +542,29 @@ def _handle_schema_apply(args: argparse.Namespace, context: CliContext) -> dict:
537
542
  )
538
543
 
539
544
 
545
+ def _load_apps_file_arg(path: str | None) -> dict[str, object]:
546
+ if not path:
547
+ return {"apps": []}
548
+ payload = load_json_value(path, option_name="--apps-file")
549
+ if isinstance(payload, list):
550
+ return {"apps": payload}
551
+ if isinstance(payload, dict):
552
+ apps = payload.get("apps")
553
+ if not isinstance(apps, list):
554
+ raise_config_error(
555
+ "--apps-file JSON object requires an apps array.",
556
+ fix_hint="Use {\"package_id\":1001,\"apps\":[...]} or pass a raw JSON array.",
557
+ )
558
+ result: dict[str, object] = {"apps": apps}
559
+ if payload.get("package_id") is not None:
560
+ result["package_id"] = payload.get("package_id")
561
+ return result
562
+ raise_config_error(
563
+ "--apps-file must be a JSON array or an object containing apps.",
564
+ fix_hint="Use [{...}] or {\"package_id\":1001,\"apps\":[...]}",
565
+ )
566
+
567
+
540
568
  def _handle_layout_apply(args: argparse.Namespace, context: CliContext) -> dict:
541
569
  return context.builder.app_layout_apply(
542
570
  profile=args.profile,
@@ -146,8 +146,11 @@ class AiBuilderTools(ToolBase):
146
146
  package_id: int | None = None,
147
147
  package_name: str | None = None,
148
148
  create_if_missing: bool = False,
149
- icon: str | None = None,
149
+ icon: str | JSONObject | None = None,
150
150
  color: str | None = None,
151
+ icon_name: str | None = None,
152
+ icon_color: str | None = None,
153
+ icon_config: JSONObject | None = None,
151
154
  visibility: JSONObject | None = None,
152
155
  items: list[dict] | None = None,
153
156
  allow_detach: bool = False,
@@ -159,6 +162,9 @@ class AiBuilderTools(ToolBase):
159
162
  create_if_missing=create_if_missing,
160
163
  icon=icon,
161
164
  color=color,
165
+ icon_name=icon_name,
166
+ icon_color=icon_color,
167
+ icon_config=icon_config,
162
168
  visibility=visibility,
163
169
  items=items or None,
164
170
  allow_detach=allow_detach,
@@ -364,8 +370,11 @@ class AiBuilderTools(ToolBase):
364
370
  package_id: int | None = None,
365
371
  app_name: str = "",
366
372
  app_title: str = "",
367
- icon: str = "",
373
+ icon: str | JSONObject = "",
368
374
  color: str = "",
375
+ icon_name: str | None = None,
376
+ icon_color: str | None = None,
377
+ icon_config: JSONObject | None = None,
369
378
  visibility: JSONObject | None = None,
370
379
  create_if_missing: bool = False,
371
380
  publish: bool = True,
@@ -423,6 +432,9 @@ class AiBuilderTools(ToolBase):
423
432
  app_title=app_title,
424
433
  icon=icon,
425
434
  color=color,
435
+ icon_name=icon_name,
436
+ icon_color=icon_color,
437
+ icon_config=icon_config,
426
438
  visibility=visibility,
427
439
  create_if_missing=create_if_missing,
428
440
  publish=publish,
@@ -733,13 +745,23 @@ class AiBuilderTools(ToolBase):
733
745
  package_id: int | None = None,
734
746
  package_name: str | None = None,
735
747
  create_if_missing: bool = False,
736
- icon: str | None = None,
748
+ icon: str | JSONObject | None = None,
737
749
  color: str | None = None,
750
+ icon_name: str | None = None,
751
+ icon_color: str | None = None,
752
+ icon_config: JSONObject | None = None,
738
753
  visibility: JSONObject | None = None,
739
754
  items: list[dict] | None = None,
740
755
  allow_detach: bool = False,
741
756
  ) -> JSONObject:
742
757
  """执行分组与包相关逻辑。"""
758
+ icon, color = _normalize_builder_icon_args(
759
+ icon=icon,
760
+ color=color,
761
+ icon_name=icon_name,
762
+ icon_color=icon_color,
763
+ icon_config=icon_config,
764
+ )
743
765
  visibility_patch = None
744
766
  if visibility is not None:
745
767
  try:
@@ -1650,8 +1672,11 @@ class AiBuilderTools(ToolBase):
1650
1672
  package_id: int | None = None,
1651
1673
  app_name: str = "",
1652
1674
  app_title: str = "",
1653
- icon: str = "",
1675
+ icon: str | JSONObject = "",
1654
1676
  color: str = "",
1677
+ icon_name: str | None = None,
1678
+ icon_color: str | None = None,
1679
+ icon_config: JSONObject | None = None,
1655
1680
  visibility: JSONObject | None = None,
1656
1681
  create_if_missing: bool = False,
1657
1682
  publish: bool = True,
@@ -1661,7 +1686,15 @@ class AiBuilderTools(ToolBase):
1661
1686
  apps: list[JSONObject] | None = None,
1662
1687
  ) -> JSONObject:
1663
1688
  """执行应用相关逻辑。"""
1689
+ icon, color = _normalize_builder_icon_args(
1690
+ icon=icon,
1691
+ color=color,
1692
+ icon_name=icon_name,
1693
+ icon_color=icon_color,
1694
+ icon_config=icon_config,
1695
+ )
1664
1696
  if apps:
1697
+ apps = [_normalize_schema_app_item(item) if isinstance(item, dict) else item for item in apps]
1665
1698
  result = self._app_schema_apply_multi(
1666
1699
  profile=profile,
1667
1700
  package_id=package_id,
@@ -1801,6 +1834,7 @@ class AiBuilderTools(ToolBase):
1801
1834
  )
1802
1835
 
1803
1836
  client_key_to_app_key: dict[str, str] = {}
1837
+ app_name_to_app_key: dict[str, str] = {}
1804
1838
  created_app_keys: list[str] = []
1805
1839
  results: list[JSONObject] = []
1806
1840
  any_write_executed = False
@@ -1864,11 +1898,14 @@ class AiBuilderTools(ToolBase):
1864
1898
  created_app_keys.append(resolved_key)
1865
1899
  if client_key:
1866
1900
  client_key_to_app_key[client_key] = resolved_key
1901
+ resolved_name = str(public_shell.get("app_name_after") or public_shell.get("app_name") or app_name or "").strip()
1902
+ if resolved_name:
1903
+ app_name_to_app_key[resolved_name] = resolved_key
1867
1904
  results.append({
1868
1905
  "index": index,
1869
1906
  "row_number": index + 1,
1870
1907
  "client_key": client_key or None,
1871
- "app_name": str(public_shell.get("app_name_after") or public_shell.get("app_name") or app_name or "").strip() or None,
1908
+ "app_name": resolved_name or None,
1872
1909
  "app_key": resolved_key,
1873
1910
  "status": "shell_ready",
1874
1911
  "created": bool(public_shell.get("created")),
@@ -1888,7 +1925,7 @@ class AiBuilderTools(ToolBase):
1888
1925
  item = deepcopy(raw_item)
1889
1926
  app_key = str(existing.get("app_key") or "").strip()
1890
1927
  try:
1891
- compiled_item = _compile_multi_app_schema_item_refs(item, client_key_to_app_key)
1928
+ compiled_item = _compile_multi_app_schema_item_refs(item, client_key_to_app_key, app_name_to_app_key)
1892
1929
  except ValueError as error:
1893
1930
  final_items.append({
1894
1931
  **{key: existing.get(key) for key in ("index", "row_number", "client_key", "app_name", "app_key", "created")},
@@ -2786,8 +2823,58 @@ def _multi_app_item_failure(index: int, item: object, error_code: str, message:
2786
2823
  }
2787
2824
 
2788
2825
 
2789
- def _compile_multi_app_schema_item_refs(item: JSONObject, client_key_to_app_key: dict[str, str]) -> JSONObject:
2826
+ def _normalize_builder_icon_args(
2827
+ *,
2828
+ icon: str | JSONObject | None,
2829
+ color: str | None,
2830
+ icon_name: str | None = None,
2831
+ icon_color: str | None = None,
2832
+ icon_config: JSONObject | None = None,
2833
+ ) -> tuple[str | None, str | None]:
2834
+ payloads: list[JSONObject] = []
2835
+ if isinstance(icon_config, dict):
2836
+ payloads.append(icon_config)
2837
+ if isinstance(icon, dict):
2838
+ payloads.append(icon)
2839
+
2840
+ normalized_icon = None if isinstance(icon, dict) else icon
2841
+ normalized_color = color
2842
+ for payload in payloads:
2843
+ normalized_icon = normalized_icon or payload.get("icon") or payload.get("icon_name") or payload.get("iconName") or payload.get("name")
2844
+ normalized_color = normalized_color or payload.get("color") or payload.get("icon_color") or payload.get("iconColor")
2845
+ normalized_icon = normalized_icon or icon_name
2846
+ normalized_color = normalized_color or icon_color
2847
+ return (
2848
+ str(normalized_icon).strip() if normalized_icon is not None else None,
2849
+ str(normalized_color).strip() if normalized_color is not None else None,
2850
+ )
2851
+
2852
+
2853
+ def _normalize_schema_app_item(item: JSONObject) -> JSONObject:
2854
+ normalized = deepcopy(item)
2855
+ icon, color = _normalize_builder_icon_args(
2856
+ icon=normalized.get("icon"),
2857
+ color=normalized.get("color"),
2858
+ icon_name=normalized.get("icon_name") or normalized.get("iconName"),
2859
+ icon_color=normalized.get("icon_color") or normalized.get("iconColor"),
2860
+ icon_config=normalized.get("icon_config") or normalized.get("iconConfig"),
2861
+ )
2862
+ if icon:
2863
+ normalized["icon"] = icon
2864
+ if color:
2865
+ normalized["color"] = color
2866
+ for key in ("icon_name", "iconName", "icon_color", "iconColor", "icon_config", "iconConfig"):
2867
+ normalized.pop(key, None)
2868
+ return normalized
2869
+
2870
+
2871
+ def _compile_multi_app_schema_item_refs(
2872
+ item: JSONObject,
2873
+ client_key_to_app_key: dict[str, str],
2874
+ app_name_to_app_key: dict[str, str] | None = None,
2875
+ ) -> JSONObject:
2790
2876
  compiled = deepcopy(item)
2877
+ app_name_to_app_key = app_name_to_app_key or {}
2791
2878
 
2792
2879
  def visit(value):
2793
2880
  if isinstance(value, list):
@@ -2807,6 +2894,13 @@ def _compile_multi_app_schema_item_refs(item: JSONObject, client_key_to_app_key:
2807
2894
  if not target_app_key:
2808
2895
  raise ValueError(f"target_app_ref '{ref_key}' did not match any apps[].client_key")
2809
2896
  payload["target_app_key"] = target_app_key
2897
+ target_app = payload.pop("target_app", None) or payload.pop("targetApp", None)
2898
+ if target_app is not None and not str(payload.get("target_app_key") or "").strip():
2899
+ target_name = str(target_app or "").strip()
2900
+ target_app_key = app_name_to_app_key.get(target_name)
2901
+ if not target_app_key:
2902
+ raise ValueError(f"target_app '{target_name}' did not match any apps[].app_name in the same call")
2903
+ payload["target_app_key"] = target_app_key
2810
2904
  return payload
2811
2905
 
2812
2906
  return visit(compiled)
@@ -2855,7 +2949,7 @@ def _contains_multi_app_target_ref(value: object) -> bool:
2855
2949
  if not isinstance(value, dict):
2856
2950
  return False
2857
2951
  for key, entry in value.items():
2858
- if key in {"target_app_ref", "targetAppRef", "target_app_client_key", "targetAppClientKey"}:
2952
+ if key in {"target_app_ref", "targetAppRef", "target_app_client_key", "targetAppClientKey", "target_app", "targetApp"}:
2859
2953
  return True
2860
2954
  if _contains_multi_app_target_ref(entry):
2861
2955
  return True
@@ -4054,13 +4148,29 @@ _BUILDER_TOOL_CONTRACTS: dict[str, JSONObject] = {
4054
4148
  },
4055
4149
  },
4056
4150
  "package_apply": {
4057
- "allowed_keys": ["package_id", "package_name", "create_if_missing", "icon", "color", "visibility", "items", "allow_detach"],
4151
+ "allowed_keys": [
4152
+ "package_id",
4153
+ "package_name",
4154
+ "create_if_missing",
4155
+ "icon",
4156
+ "color",
4157
+ "icon_name",
4158
+ "icon_color",
4159
+ "icon_config",
4160
+ "visibility",
4161
+ "items",
4162
+ "allow_detach",
4163
+ ],
4058
4164
  "aliases": {
4059
4165
  "packageId": "package_id",
4060
4166
  "packageName": "package_name",
4061
4167
  "createIfMissing": "create_if_missing",
4062
4168
  "iconName": "icon",
4063
4169
  "iconColor": "color",
4170
+ "icon_config.name": "icon",
4171
+ "icon_config.icon_name": "icon",
4172
+ "icon_config.color": "color",
4173
+ "icon_config.icon_color": "color",
4064
4174
  "allowDetach": "allow_detach",
4065
4175
  },
4066
4176
  "allowed_values": {
@@ -4072,6 +4182,7 @@ _BUILDER_TOOL_CONTRACTS: dict[str, JSONObject] = {
4072
4182
  "execution_notes": [
4073
4183
  "create or update package metadata, visibility, grouping, and ordering in one call",
4074
4184
  "creating a package requires explicit icon + color; icon=template is blocked because it is too generic",
4185
+ "icon can be passed as icon/color, icon_name/icon_color, icon_config, or icon={name,color}; all forms normalize to icon/color",
4075
4186
  "updating a package preserves existing icon/color when omitted; explicit icon/color values are still validated",
4076
4187
  "call workspace_icon_catalog_get or `qingflow --json builder icon catalog` for supported icon/color candidates",
4077
4188
  "metadata keys omitted on update are preserved",
@@ -4575,6 +4686,9 @@ _BUILDER_TOOL_CONTRACTS: dict[str, JSONObject] = {
4575
4686
  "app_title",
4576
4687
  "icon",
4577
4688
  "color",
4689
+ "icon_name",
4690
+ "icon_color",
4691
+ "icon_config",
4578
4692
  "visibility",
4579
4693
  "create_if_missing",
4580
4694
  "publish",
@@ -4587,11 +4701,15 @@ _BUILDER_TOOL_CONTRACTS: dict[str, JSONObject] = {
4587
4701
  "apps[].app_name",
4588
4702
  "apps[].icon",
4589
4703
  "apps[].color",
4704
+ "apps[].icon_name",
4705
+ "apps[].icon_color",
4706
+ "apps[].icon_config",
4590
4707
  "apps[].visibility",
4591
4708
  "apps[].add_fields",
4592
4709
  "apps[].update_fields",
4593
4710
  "apps[].remove_fields",
4594
4711
  "apps[].add_fields[].target_app_ref",
4712
+ "apps[].add_fields[].target_app",
4595
4713
  ],
4596
4714
  "aliases": {
4597
4715
  "app_title": "app_name",
@@ -4601,8 +4719,16 @@ _BUILDER_TOOL_CONTRACTS: dict[str, JSONObject] = {
4601
4719
  "apps[].appKey": "apps[].app_key",
4602
4720
  "apps[].appName": "apps[].app_name",
4603
4721
  "apps[].appTitle": "apps[].app_name",
4722
+ "apps[].iconName": "apps[].icon",
4723
+ "apps[].iconColor": "apps[].color",
4724
+ "apps[].icon_config.name": "apps[].icon",
4725
+ "apps[].icon_config.color": "apps[].color",
4604
4726
  "field.targetAppRef": "field.target_app_ref",
4605
4727
  "field.targetAppClientKey": "field.target_app_ref",
4728
+ "field.targetApp": "field.target_app",
4729
+ "field.options[].label": "field.options[]",
4730
+ "field.options[].value": "field.options[]",
4731
+ "field.options[].optValue": "field.options[]",
4606
4732
  "field.title": "field.name",
4607
4733
  "field.label": "field.name",
4608
4734
  "field.fields": "field.subfields",
@@ -4642,10 +4768,13 @@ _BUILDER_TOOL_CONTRACTS: dict[str, JSONObject] = {
4642
4768
  "create mode follows backend CreateAppBean: package add_app permission is checked on the target package; package edit_app is not required for the create precheck",
4643
4769
  "multi-app mode: pass package_id + create_if_missing + apps[]; do not mix apps with top-level app_key/app_name/add_fields/update_fields/remove_fields",
4644
4770
  "multi-app relation fields may use target_app_ref to point at another apps[].client_key; the tool creates/resolves app shells first and compiles it to target_app_key",
4771
+ "multi-app relation fields may also use target_app with another apps[].app_name; prefer target_app_ref/client_key when names may collide",
4645
4772
  "multi-app mode is not transactional; read created_app_keys and apps[].status before retrying, and retry only failed app items",
4646
4773
  "create mode defaults new app visibility to workspace/not when visibility is omitted; edit mode preserves current visibility when omitted",
4647
4774
  "create mode requires explicit icon + color; icon=template is blocked because it is too generic",
4775
+ "icon can be passed as icon/color, icon_name/icon_color, icon_config, or icon={name,color}; all forms normalize to icon/color",
4648
4776
  "multi-app create mode requires each new app item to include a distinct non-template icon and a valid color",
4777
+ "single_select and multi_select options accept strings or objects such as {label,value}; builder normalizes them to option labels before writing",
4649
4778
  "edit mode preserves existing icon/color when omitted; explicit icon/color values are still validated",
4650
4779
  "call workspace_icon_catalog_get or `qingflow --json builder icon catalog` for supported icon/color candidates",
4651
4780
  *_VISIBILITY_EXECUTION_NOTES,