@josephyan/qingflow-app-user-mcp 1.1.17 → 1.1.19

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 @josephyan/qingflow-app-user-mcp@1.1.17
6
+ npm install @josephyan/qingflow-app-user-mcp@1.1.19
7
7
  ```
8
8
 
9
9
  Run:
10
10
 
11
11
  ```bash
12
- npx -y -p @josephyan/qingflow-app-user-mcp@1.1.17 qingflow-app-user-mcp
12
+ npx -y -p @josephyan/qingflow-app-user-mcp@1.1.19 qingflow-app-user-mcp
13
13
  ```
14
14
 
15
15
  Environment:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@josephyan/qingflow-app-user-mcp",
3
- "version": "1.1.17",
3
+ "version": "1.1.19",
4
4
  "description": "Operational end-user MCP for Qingflow records, tasks, comments, and directory workflows.",
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.1.17"
7
+ version = "1.1.19"
8
8
  description = "User-authenticated MCP server for Qingflow"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -2260,6 +2260,22 @@ class ChartApplyRequest(StrictModel):
2260
2260
  return self
2261
2261
 
2262
2262
 
2263
+ class PortalInlineChartPatch(ChartUpsertPatch):
2264
+ app_key: str = Field(validation_alias=AliasChoices("app_key", "appKey"))
2265
+
2266
+ @model_validator(mode="before")
2267
+ @classmethod
2268
+ def normalize_inline_aliases(cls, value: Any) -> Any:
2269
+ if not isinstance(value, dict):
2270
+ return value
2271
+ payload = dict(value)
2272
+ if "chart_name" in payload and "name" not in payload:
2273
+ payload["name"] = payload.pop("chart_name")
2274
+ if "chartName" in payload and "name" not in payload:
2275
+ payload["name"] = payload.pop("chartName")
2276
+ return payload
2277
+
2278
+
2263
2279
  class PortalComponentPositionPatch(StrictModel):
2264
2280
  pc_x: int = Field(default=0, validation_alias=AliasChoices("pc_x", "pcX", "x"))
2265
2281
  pc_y: int = Field(default=0, validation_alias=AliasChoices("pc_y", "pcY", "y"))
@@ -2344,6 +2360,7 @@ class PortalSectionPatch(StrictModel):
2344
2360
  dash_style_config: dict[str, Any] | None = Field(default=None, validation_alias=AliasChoices("dash_style_config", "dashStyleConfigBO"))
2345
2361
  config: dict[str, Any] = Field(default_factory=dict)
2346
2362
  chart_ref: PortalChartRefPatch | None = None
2363
+ chart: PortalInlineChartPatch | None = Field(default=None, validation_alias=AliasChoices("chart", "inline_chart", "inlineChart", "create_chart", "createChart"))
2347
2364
  view_ref: PortalViewRefPatch | None = None
2348
2365
  text: str | None = None
2349
2366
  url: str | None = None
@@ -2362,6 +2379,14 @@ class PortalSectionPatch(StrictModel):
2362
2379
  payload["role"] = raw_role.strip().lower()
2363
2380
  if "chartRef" in payload and "chart_ref" not in payload:
2364
2381
  payload["chart_ref"] = payload.pop("chartRef")
2382
+ if "inlineChart" in payload and "chart" not in payload:
2383
+ payload["chart"] = payload.pop("inlineChart")
2384
+ if "inline_chart" in payload and "chart" not in payload:
2385
+ payload["chart"] = payload.pop("inline_chart")
2386
+ if "createChart" in payload and "chart" not in payload:
2387
+ payload["chart"] = payload.pop("createChart")
2388
+ if "create_chart" in payload and "chart" not in payload:
2389
+ payload["chart"] = payload.pop("create_chart")
2365
2390
  if "viewRef" in payload and "view_ref" not in payload:
2366
2391
  payload["view_ref"] = payload.pop("viewRef")
2367
2392
  if "dashStyleConfigBO" in payload and "dash_style_config" not in payload:
@@ -2373,8 +2398,8 @@ class PortalSectionPatch(StrictModel):
2373
2398
  supported = {"chart", "view", "grid", "filter", "text", "link"}
2374
2399
  if self.source_type not in supported:
2375
2400
  raise ValueError(f"unsupported portal source_type '{self.source_type}'")
2376
- if self.source_type == "chart" and self.chart_ref is None:
2377
- raise ValueError("chart section requires chart_ref")
2401
+ if self.source_type == "chart" and self.chart_ref is None and self.chart is None:
2402
+ raise ValueError("chart section requires chart_ref or chart")
2378
2403
  if self.source_type == "view" and self.view_ref is None:
2379
2404
  raise ValueError("view section requires view_ref")
2380
2405
  if self.source_type == "text" and self.text is None:
@@ -2662,6 +2687,14 @@ def _normalize_field_payload(value: Any) -> Any:
2662
2687
  if not isinstance(value, dict):
2663
2688
  return value
2664
2689
  payload = dict(value)
2690
+ if "data_title" in payload and "as_data_title" not in payload and "asDataTitle" not in payload:
2691
+ payload["as_data_title"] = payload.pop("data_title")
2692
+ if "dataTitle" in payload and "as_data_title" not in payload and "asDataTitle" not in payload:
2693
+ payload["as_data_title"] = payload.pop("dataTitle")
2694
+ if "data_cover" in payload and "as_data_cover" not in payload and "asDataCover" not in payload:
2695
+ payload["as_data_cover"] = payload.pop("data_cover")
2696
+ if "dataCover" in payload and "as_data_cover" not in payload and "asDataCover" not in payload:
2697
+ payload["as_data_cover"] = payload.pop("dataCover")
2665
2698
  if "fields" in payload and "subfields" not in payload:
2666
2699
  payload["subfields"] = payload.pop("fields")
2667
2700
  if "options" in payload:
@@ -3155,7 +3155,7 @@ class AiBuilderFacade:
3155
3155
  return expanded, issues, results
3156
3156
 
3157
3157
  def app_custom_buttons_apply(self, *, profile: str, request: CustomButtonsApplyRequest) -> JSONObject:
3158
- normalized_args = request.model_dump(mode="json")
3158
+ normalized_args = request.model_dump(mode="json", exclude_none=True, exclude_defaults=True)
3159
3159
  app_key = request.app_key
3160
3160
  permission_outcomes: list[PermissionCheckOutcome] = []
3161
3161
  button_write_intent = bool(request.upsert_buttons or request.patch_buttons or request.remove_buttons)
@@ -3239,7 +3239,10 @@ class AiBuilderFacade:
3239
3239
  )
3240
3240
  )
3241
3241
  upsert_buttons.extend(expanded_buttons)
3242
- normalized_args["upsert_buttons"] = [patch.model_dump(mode="json") for patch in upsert_buttons]
3242
+ normalized_args["upsert_buttons"] = [
3243
+ patch.model_dump(mode="json", exclude_none=True, exclude_defaults=True)
3244
+ for patch in upsert_buttons
3245
+ ]
3243
3246
  normalized_args["patch_results"] = patch_results
3244
3247
 
3245
3248
  compiled_add_data_configs, add_data_issues = self._compile_custom_button_semantic_add_data_configs(
@@ -10261,8 +10264,14 @@ class AiBuilderFacade:
10261
10264
  return CustomButtonsApplyRequest.model_validate(
10262
10265
  {
10263
10266
  "app_key": app_key,
10264
- "upsert_buttons": [item.model_dump(mode="json") for item in upsert_buttons],
10265
- "view_configs": [item.model_dump(mode="json") for item in view_configs],
10267
+ "upsert_buttons": [
10268
+ item.model_dump(mode="json", exclude_none=True, exclude_defaults=True)
10269
+ for item in upsert_buttons
10270
+ ],
10271
+ "view_configs": [
10272
+ item.model_dump(mode="json", exclude_none=True, exclude_defaults=True)
10273
+ for item in view_configs
10274
+ ],
10266
10275
  }
10267
10276
  ), []
10268
10277
  except Exception as error:
@@ -13018,6 +13027,7 @@ class AiBuilderFacade:
13018
13027
  draft_readback_error: JSONObject | None = None
13019
13028
  live_readback_error: JSONObject | None = None
13020
13029
  update_payload: dict[str, Any] = {}
13030
+ inline_chart_results: list[dict[str, Any]] = []
13021
13031
  try:
13022
13032
  layout_diagnostics: dict[str, Any] = _empty_portal_layout_diagnostics()
13023
13033
  if creating:
@@ -13065,10 +13075,11 @@ class AiBuilderFacade:
13065
13075
  base_payload=base_payload,
13066
13076
  )
13067
13077
  if sections_requested:
13068
- component_payload, layout_metadata = self._build_portal_components_from_sections(
13078
+ component_payload, layout_metadata, inline_chart_results = self._build_portal_components_from_sections(
13069
13079
  profile=profile,
13070
13080
  sections=request.sections,
13071
13081
  layout_preset=request.layout_preset,
13082
+ inline_chart_results=inline_chart_results,
13072
13083
  )
13073
13084
  layout_diagnostics = _portal_layout_diagnostics(request.sections, component_payload, layout_metadata=layout_metadata)
13074
13085
  update_payload["components"] = component_payload
@@ -13096,11 +13107,12 @@ class AiBuilderFacade:
13096
13107
  draft_result = {}
13097
13108
  except (QingflowApiError, RuntimeError, ValueError) as error:
13098
13109
  api_error = _coerce_api_error(error) if not isinstance(error, ValueError) else None
13099
- if write_executed:
13110
+ inline_chart_write_executed = any(bool(item.get("write_executed")) for item in inline_chart_results)
13111
+ if write_executed or inline_chart_write_executed:
13100
13112
  transport_error = _transport_error_payload(api_error) if api_error is not None else None
13101
13113
  warning = _warning(
13102
13114
  "PORTAL_WRITE_INCOMPLETE_AFTER_PARTIAL_WRITE",
13103
- "one or more portal write steps executed before a later write step failed",
13115
+ "one or more portal or inline-chart write steps executed before a later write step failed",
13104
13116
  )
13105
13117
  if transport_error is not None:
13106
13118
  for key in ("backend_code", "http_status", "request_id"):
@@ -13121,6 +13133,7 @@ class AiBuilderFacade:
13121
13133
  if api_error is not None
13122
13134
  else {"message": str(error)}
13123
13135
  ),
13136
+ **({"inline_chart_results": deepcopy(inline_chart_results)} if inline_chart_results else {}),
13124
13137
  },
13125
13138
  "request_id": api_error.request_id if api_error else None,
13126
13139
  "backend_code": api_error.backend_code if api_error else None,
@@ -13136,6 +13149,7 @@ class AiBuilderFacade:
13136
13149
  "published": False,
13137
13150
  "publish_failed": False,
13138
13151
  "write_incomplete": True,
13152
+ "inline_charts_verified": False if inline_chart_results else None,
13139
13153
  "readback_unavailable": False,
13140
13154
  "metadata_unverified": True,
13141
13155
  },
@@ -13147,6 +13161,7 @@ class AiBuilderFacade:
13147
13161
  "verified": False,
13148
13162
  "write_executed": True,
13149
13163
  "safe_to_retry": False,
13164
+ "inline_chart_results": deepcopy(inline_chart_results),
13150
13165
  })
13151
13166
  return _failed(
13152
13167
  "PORTAL_APPLY_FAILED",
@@ -13258,6 +13273,7 @@ class AiBuilderFacade:
13258
13273
  "draft": draft_meta_mismatches,
13259
13274
  "live": live_meta_mismatches,
13260
13275
  },
13276
+ **({"inline_chart_results": deepcopy(inline_chart_results)} if inline_chart_results else {}),
13261
13277
  **({"publish_error": publish_error} if publish_error is not None else {}),
13262
13278
  **({"draft_readback_error": draft_readback_error} if draft_readback_error is not None else {}),
13263
13279
  **({"live_readback_error": live_readback_error} if live_readback_error is not None else {}),
@@ -13295,6 +13311,7 @@ class AiBuilderFacade:
13295
13311
  "noop": False,
13296
13312
  "warnings": warnings,
13297
13313
  "layout_diagnostics": layout_diagnostics,
13314
+ "inline_chart_results": deepcopy(inline_chart_results),
13298
13315
  "verification": {
13299
13316
  "draft_verified": draft_verified,
13300
13317
  "draft_metadata_verified": draft_meta_verified,
@@ -13302,6 +13319,7 @@ class AiBuilderFacade:
13302
13319
  "live_metadata_verified": live_meta_verified,
13303
13320
  "published": published,
13304
13321
  "publish_failed": publish_failed,
13322
+ "inline_charts_verified": all(str(item.get("status") or "") in {"created", "updated"} and str(item.get("chart_id") or "").strip() for item in inline_chart_results),
13305
13323
  "readback_unavailable": draft_readback_error is not None or live_readback_error is not None,
13306
13324
  "metadata_unverified": draft_readback_error is not None or live_readback_error is not None,
13307
13325
  },
@@ -14055,9 +14073,11 @@ class AiBuilderFacade:
14055
14073
  profile: str,
14056
14074
  sections: list[PortalSectionPatch],
14057
14075
  layout_preset: str | None = None,
14058
- ) -> tuple[list[dict[str, Any]], list[dict[str, Any]]]:
14076
+ inline_chart_results: list[dict[str, Any]] | None = None,
14077
+ ) -> tuple[list[dict[str, Any]], list[dict[str, Any]], list[dict[str, Any]]]:
14059
14078
  resolved_components: list[dict[str, Any]] = []
14060
14079
  layout_metadata: list[dict[str, Any]] = []
14080
+ inline_chart_results = inline_chart_results if inline_chart_results is not None else []
14061
14081
  pc_x = 0
14062
14082
  pc_y = 0
14063
14083
  pc_row_height = 0
@@ -14084,11 +14104,53 @@ class AiBuilderFacade:
14084
14104
  dash_style = deepcopy(section.dash_style_config) if isinstance(section.dash_style_config, dict) else None
14085
14105
  component: dict[str, Any]
14086
14106
  if section.source_type == "chart":
14087
- resolved_chart = _resolve_chart_reference(
14088
- charts=self.charts,
14089
- profile=profile,
14090
- ref=section.chart_ref,
14091
- )
14107
+ if section.chart is not None:
14108
+ inline_chart_payload = section.chart.model_dump(mode="json", exclude={"app_key"})
14109
+ chart_request = ChartApplyRequest(
14110
+ app_key=section.chart.app_key,
14111
+ upsert_charts=[ChartUpsertPatch.model_validate(inline_chart_payload)],
14112
+ patch_charts=[],
14113
+ remove_chart_ids=[],
14114
+ reorder_chart_ids=[],
14115
+ )
14116
+ chart_apply = self.chart_apply(profile=profile, request=chart_request)
14117
+ chart_items = chart_apply.get("chart_results") if isinstance(chart_apply.get("chart_results"), list) else []
14118
+ successful_chart = next(
14119
+ (
14120
+ item
14121
+ for item in chart_items
14122
+ if isinstance(item, dict)
14123
+ and str(item.get("status") or "") in {"created", "updated"}
14124
+ and str(item.get("chart_id") or "").strip()
14125
+ ),
14126
+ None,
14127
+ )
14128
+ inline_chart_results.append({
14129
+ "title": section.title,
14130
+ "app_key": section.chart.app_key,
14131
+ "chart_name": section.chart.name,
14132
+ "chart_type": section.chart.chart_type.value,
14133
+ "status": str(successful_chart.get("status") or "") if isinstance(successful_chart, dict) else "failed",
14134
+ "chart_id": str(successful_chart.get("chart_id") or "") if isinstance(successful_chart, dict) else "",
14135
+ "chart_apply_status": chart_apply.get("status"),
14136
+ "write_executed": bool(chart_apply.get("write_executed")),
14137
+ **({"error_code": chart_apply.get("error_code")} if chart_apply.get("error_code") else {}),
14138
+ **({"message": chart_apply.get("message")} if chart_apply.get("message") else {}),
14139
+ })
14140
+ if not isinstance(successful_chart, dict):
14141
+ raise ValueError(f"inline chart '{section.chart.name}' could not be created or updated for portal section '{section.title}'")
14142
+ resolved_chart = {
14143
+ "chart_id": str(successful_chart.get("chart_id") or "").strip(),
14144
+ "chart_name": str(successful_chart.get("name") or section.chart.name).strip(),
14145
+ "app_key": section.chart.app_key,
14146
+ "chart_type": section.chart.chart_type.value,
14147
+ }
14148
+ else:
14149
+ resolved_chart = _resolve_chart_reference(
14150
+ charts=self.charts,
14151
+ profile=profile,
14152
+ ref=section.chart_ref,
14153
+ )
14092
14154
  chart_type = str(
14093
14155
  resolved_chart.get("chart_type")
14094
14156
  or _public_chart_type_from_backend(section.config.get("chartType") or section.config.get("chart_type"))
@@ -14148,7 +14210,7 @@ class AiBuilderFacade:
14148
14210
  if dash_style is not None:
14149
14211
  component["dashStyleConfigBO"] = dash_style
14150
14212
  resolved_components.append(component)
14151
- return resolved_components, layout_metadata
14213
+ return resolved_components, layout_metadata, inline_chart_results
14152
14214
 
14153
14215
  def _resolve_current_user_identity(self, *, profile: str) -> JSONObject:
14154
14216
  session_profile = self.apps.sessions.get_profile(profile)
@@ -17794,12 +17856,12 @@ def _portal_layout_diagnostics(
17794
17856
  if source_type == "chart" and role in {"metric", "metrics", "indicator", "kpi"} and not is_metric_chart:
17795
17857
  warnings.append(_warning(
17796
17858
  "PORTAL_METRIC_SECTION_CHART_TYPE_MISMATCH",
17797
- "metric portal section must reference a target/indicator chart; create the missing metric chart before assembling the portal",
17859
+ "metric portal section must reference a target/indicator chart; use inline_chart to create the missing metric chart while assembling the portal",
17798
17860
  section_index=index,
17799
17861
  title=title,
17800
17862
  role=role,
17801
17863
  chart_type=chart_type or None,
17802
- fix_hint="Use app_charts_apply with chart_type=target and metric='count(*)' or another metric expression, then reference that chart.",
17864
+ fix_hint="Use section.inline_chart with chart_type=target or indicator and a metric expression, or change role away from metric.",
17803
17865
  ))
17804
17866
  if section is not None and section.position is not None and not bool(getattr(section.position, "mobile_provided", False)):
17805
17867
  warnings.append(_warning(
@@ -17859,7 +17921,7 @@ def _append_portal_standard_count_warnings(
17859
17921
  "standard portal metric area should contain 4-6 metric cards",
17860
17922
  actual_count=metric_count,
17861
17923
  expected_count="4-6",
17862
- fix_hint="Create missing target/indicator charts first, or keep 4 metric cards in one row with pc.cols=6, pc.rows=5.",
17924
+ fix_hint="Use inline_chart for missing target/indicator metric cards, or keep 4 metric cards in one row with pc.cols=6, pc.rows=5.",
17863
17925
  ))
17864
17926
  if (bi_count or require_complete_standard) and not 2 <= bi_count <= 3:
17865
17927
  warnings.append(_warning(
@@ -214,7 +214,8 @@ def register(subparsers: argparse._SubParsersAction[argparse.ArgumentParser]) ->
214
214
  schema_apply_apply.add_argument("--visibility-file")
215
215
  schema_apply_apply.add_argument("--create-if-missing", action="store_true")
216
216
  schema_apply_apply.add_argument("--publish", action=argparse.BooleanOptionalAction, default=None)
217
- schema_apply_apply.add_argument("--apps-file", help="多应用 schema JSON 数组;每项可带 client_key/app_name/add_fields,支持 relation target_app_ref")
217
+ schema_apply_apply.add_argument("--apps-file", help="多应用 schema JSON 对象;每项可带 client_key/app_name/form,支持 relation target_app_ref")
218
+ schema_apply_apply.add_argument("--form-file", help="单应用表单结构 JSON 数组;form[].rows[][] 同时声明字段和表单分组布局")
218
219
  schema_apply_apply.add_argument("--add-fields-file", help="字段 JSON 数组;字段可用 as_data_title/as_data_cover 标记数据标题/封面")
219
220
  schema_apply_apply.add_argument("--update-fields-file", help="字段更新 JSON 数组;set 内可用 as_data_title/as_data_cover 标记数据标题/封面")
220
221
  schema_apply_apply.add_argument("--remove-fields-file")
@@ -578,10 +579,10 @@ def _handle_schema_apply(args: argparse.Namespace, context: CliContext) -> dict:
578
579
  fix_hint="Pass a JSON array, or a JSON object like {\"package_id\":1001,\"apps\":[...]} with at least one app item.",
579
580
  error_code="APPS_FILE_EMPTY",
580
581
  )
581
- 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:
582
+ if args.app_key or args.app_name or args.app_title or args.form_file or args.add_fields_file or args.update_fields_file or args.remove_fields_file:
582
583
  raise_config_error(
583
584
  "schema apply multi-app mode accepts --package-id plus --apps-file only; --create-if-missing is optional.",
584
- fix_hint="Use `--apps-file` for batch mode, or remove `--apps-file` and use the single-app arguments.",
585
+ fix_hint="Use apps[].form inside --apps-file for batch mode, or remove --apps-file and use --form-file for a single app.",
585
586
  )
586
587
  if package_id is None:
587
588
  raise_config_error(
@@ -595,6 +596,7 @@ def _handle_schema_apply(args: argparse.Namespace, context: CliContext) -> dict:
595
596
  create_if_missing=effective_create_if_missing,
596
597
  publish=effective_publish,
597
598
  apps=apps,
599
+ form=None,
598
600
  add_fields=[],
599
601
  update_fields=[],
600
602
  remove_fields=[],
@@ -631,6 +633,7 @@ def _handle_schema_apply(args: argparse.Namespace, context: CliContext) -> dict:
631
633
  visibility=load_object_arg(args.visibility_file, option_name="--visibility-file"),
632
634
  create_if_missing=bool(args.create_if_missing),
633
635
  publish=True if args.publish is None else bool(args.publish),
636
+ form=load_list_arg(args.form_file, option_name="--form-file") if args.form_file else [],
634
637
  add_fields=load_list_arg(args.add_fields_file, option_name="--add-fields-file"),
635
638
  update_fields=load_list_arg(args.update_fields_file, option_name="--update-fields-file"),
636
639
  remove_fields=load_list_arg(args.remove_fields_file, option_name="--remove-fields-file"),
@@ -428,16 +428,17 @@ def build_builder_server() -> FastMCP:
428
428
  visibility: dict | None = None,
429
429
  create_if_missing: bool | None = None,
430
430
  publish: bool = True,
431
+ form: list[dict] | None = None,
431
432
  add_fields: list[dict] | None = None,
432
433
  update_fields: list[dict] | None = None,
433
434
  remove_fields: list[dict] | None = None,
434
435
  apps: list[dict] | None = None,
435
436
  ) -> dict:
436
437
  if apps:
437
- if app_key or app_name or app_title or add_fields or update_fields or remove_fields:
438
+ if app_key or app_name or app_title or form or add_fields or update_fields or remove_fields:
438
439
  return _config_failure(
439
440
  "app_schema_apply multi-app mode accepts package_id plus apps only; create_if_missing is optional.",
440
- fix_hint="Use `apps` for batch mode, or use the single-app arguments without `apps`.",
441
+ fix_hint="Use apps[].form for batch mode, or use the single-app arguments without apps.",
441
442
  )
442
443
  if package_id is None:
443
444
  return _config_failure(
@@ -450,6 +451,7 @@ def build_builder_server() -> FastMCP:
450
451
  visibility=visibility,
451
452
  create_if_missing=True if create_if_missing is None else bool(create_if_missing),
452
453
  publish=publish,
454
+ form=None,
453
455
  add_fields=[],
454
456
  update_fields=[],
455
457
  remove_fields=[],
@@ -482,10 +484,11 @@ def build_builder_server() -> FastMCP:
482
484
  visibility=visibility,
483
485
  create_if_missing=effective_create_if_missing,
484
486
  publish=publish,
487
+ form=form or [],
485
488
  add_fields=add_fields or [],
486
489
  update_fields=update_fields or [],
487
490
  remove_fields=remove_fields or [],
488
- apps=[],
491
+ apps=None,
489
492
  )
490
493
 
491
494
  @server.tool()
@@ -220,9 +220,10 @@ class AiBuilderTools(ToolBase):
220
220
  wrapped["error"] = error
221
221
  app_results.append(wrapped)
222
222
 
223
+ partial = sum(1 for item in app_results if str(item.get("status") or "") == "partial_success")
223
224
  succeeded = sum(1 for item in app_results if str(item.get("status") or "") in {"success", "partial_success"})
224
225
  failed = len(app_results) - succeeded
225
- status = "success" if failed == 0 else "failed" if succeeded == 0 else "partial_success"
226
+ status = "failed" if succeeded == 0 else "partial_success" if failed > 0 or partial > 0 else "success"
226
227
  write_executed = any(
227
228
  isinstance(item.get("result"), dict) and bool(item["result"].get("write_executed"))
228
229
  for item in app_results
@@ -230,7 +231,7 @@ class AiBuilderTools(ToolBase):
230
231
  payload: JSONObject = {
231
232
  "status": status,
232
233
  "error_code": None if status == "success" else f"{tool_name.upper()}_BATCH_PARTIAL" if succeeded else f"{tool_name.upper()}_BATCH_FAILED",
233
- "recoverable": failed > 0,
234
+ "recoverable": failed > 0 or partial > 0,
234
235
  "message": (
235
236
  f"applied {tool_name} to {succeeded}/{len(app_results)} apps"
236
237
  if status != "success"
@@ -240,12 +241,13 @@ class AiBuilderTools(ToolBase):
240
241
  "apps": app_results,
241
242
  "errors": errors,
242
243
  "verification": {
243
- "batch_verified": failed == 0,
244
+ "batch_verified": failed == 0 and partial == 0,
244
245
  "succeeded": succeeded,
246
+ "partial": partial,
245
247
  "failed": failed,
246
248
  },
247
249
  "write_executed": write_executed,
248
- "write_succeeded": write_executed and failed == 0,
250
+ "write_succeeded": write_executed and failed == 0 and partial == 0,
249
251
  "safe_to_retry": not write_executed,
250
252
  }
251
253
  return _attach_builder_apply_envelope(tool_name, payload)
@@ -295,18 +297,20 @@ class AiBuilderTools(ToolBase):
295
297
  app_item["error"] = error
296
298
  errors.append(error)
297
299
  apps.append(app_item)
300
+ partial = sum(1 for item in apps if str(item.get("status") or "") == "partial_success")
298
301
  succeeded = sum(1 for item in apps if str(item.get("status") or "") in {"success", "partial_success"})
299
302
  failed = len(apps) - succeeded
303
+ status = "failed" if succeeded == 0 else "partial_success" if failed > 0 or partial > 0 else "success"
300
304
  return {
301
- "status": "success" if failed == 0 else "failed" if succeeded == 0 else "partial_success",
302
- "error_code": None if failed == 0 else f"{tool_name.upper()}_BATCH_PARTIAL" if succeeded else f"{tool_name.upper()}_BATCH_FAILED",
303
- "recoverable": failed > 0,
304
- "message": f"read {tool_name} for {succeeded}/{len(apps)} apps" if failed else f"read {tool_name} for {succeeded} apps",
305
+ "status": status,
306
+ "error_code": None if status == "success" else f"{tool_name.upper()}_BATCH_PARTIAL" if succeeded else f"{tool_name.upper()}_BATCH_FAILED",
307
+ "recoverable": failed > 0 or partial > 0,
308
+ "message": f"read {tool_name} for {succeeded}/{len(apps)} apps" if status != "success" else f"read {tool_name} for {succeeded} apps",
305
309
  "normalized_args": {"app_keys": normalized_keys},
306
310
  "app_keys": normalized_keys,
307
311
  "apps": apps,
308
312
  "errors": errors,
309
- "verification": {"batch_verified": failed == 0, "succeeded": succeeded, "failed": failed},
313
+ "verification": {"batch_verified": failed == 0 and partial == 0, "succeeded": succeeded, "partial": partial, "failed": failed},
310
314
  }
311
315
 
312
316
  def register(self, mcp) -> None:
@@ -577,17 +581,18 @@ class AiBuilderTools(ToolBase):
577
581
  visibility: JSONObject | None = None,
578
582
  create_if_missing: bool | None = None,
579
583
  publish: bool = True,
584
+ form: list[JSONObject] | None = None,
580
585
  add_fields: list[JSONObject] | None = None,
581
586
  update_fields: list[JSONObject] | None = None,
582
587
  remove_fields: list[JSONObject] | None = None,
583
588
  apps: list[JSONObject] | None = None,
584
589
  ) -> JSONObject:
585
590
  if apps is not None:
586
- if app_key or app_name or app_title or add_fields or update_fields or remove_fields:
591
+ if app_key or app_name or app_title or form or add_fields or update_fields or remove_fields:
587
592
  return _config_failure(
588
593
  tool_name="app_schema_apply",
589
594
  message="app_schema_apply multi-app mode accepts package_id plus apps only; create_if_missing is optional.",
590
- fix_hint="Use `apps` for batch mode, or use the single-app arguments without `apps`.",
595
+ fix_hint="Put per-app form in apps[].form when using batch mode.",
591
596
  )
592
597
  if package_id is None:
593
598
  return _config_failure(
@@ -602,6 +607,7 @@ class AiBuilderTools(ToolBase):
602
607
  create_if_missing=True if create_if_missing is None else bool(create_if_missing),
603
608
  publish=publish,
604
609
  apps=apps,
610
+ form=None,
605
611
  add_fields=[],
606
612
  update_fields=[],
607
613
  remove_fields=[],
@@ -638,10 +644,11 @@ class AiBuilderTools(ToolBase):
638
644
  visibility=visibility,
639
645
  create_if_missing=effective_create_if_missing,
640
646
  publish=publish,
647
+ form=form or [],
641
648
  add_fields=add_fields or [],
642
649
  update_fields=update_fields or [],
643
650
  remove_fields=remove_fields or [],
644
- apps=[],
651
+ apps=None,
645
652
  )
646
653
 
647
654
  @mcp.tool()
@@ -2101,6 +2108,7 @@ class AiBuilderTools(ToolBase):
2101
2108
  visibility: JSONObject | None = None,
2102
2109
  create_if_missing: bool | None = None,
2103
2110
  publish: bool = True,
2111
+ form: list[JSONObject] | None = None,
2104
2112
  add_fields: list[JSONObject],
2105
2113
  update_fields: list[JSONObject],
2106
2114
  remove_fields: list[JSONObject],
@@ -2126,6 +2134,21 @@ class AiBuilderTools(ToolBase):
2126
2134
  package_id = normalized_apps_payload.get("package_id") # type: ignore[assignment]
2127
2135
  apps = normalized_apps_payload.get("apps") # type: ignore[assignment]
2128
2136
  input_warnings = list(normalized_apps_payload.get("warnings") or [])
2137
+ normalized_apps: list[JSONObject] = []
2138
+ for index, app_item in enumerate(apps or []):
2139
+ if not isinstance(app_item, dict):
2140
+ normalized_apps.append(app_item)
2141
+ continue
2142
+ form_result = _apply_schema_form_to_payload(
2143
+ tool_name="app_schema_apply",
2144
+ payload=app_item,
2145
+ path=f"apps[{index}]",
2146
+ )
2147
+ failure = form_result.get("failure")
2148
+ if isinstance(failure, dict):
2149
+ return _attach_builder_apply_envelope("app_schema_apply", failure)
2150
+ normalized_apps.append(form_result.get("payload") or app_item)
2151
+ apps = normalized_apps
2129
2152
  result = self._app_schema_apply_multi(
2130
2153
  profile=profile,
2131
2154
  package_id=package_id,
@@ -2139,6 +2162,22 @@ class AiBuilderTools(ToolBase):
2139
2162
  result_warnings.extend(deepcopy(input_warnings))
2140
2163
  result["warnings"] = result_warnings
2141
2164
  return _attach_builder_apply_envelope("app_schema_apply", result)
2165
+ inline_form_layout_sections: list[JSONObject] = []
2166
+ if form:
2167
+ form_payload: JSONObject = {"form": form}
2168
+ if add_fields:
2169
+ form_payload["add_fields"] = add_fields
2170
+ form_result = _apply_schema_form_to_payload(
2171
+ tool_name="app_schema_apply",
2172
+ payload=form_payload,
2173
+ path="schema",
2174
+ )
2175
+ failure = form_result.get("failure")
2176
+ if isinstance(failure, dict):
2177
+ return _attach_builder_apply_envelope("app_schema_apply", failure)
2178
+ normalized_payload = form_result.get("payload") if isinstance(form_result.get("payload"), dict) else {}
2179
+ add_fields = list(normalized_payload.get("add_fields") or [])
2180
+ inline_form_layout_sections = list(form_result.get("layout_sections") or [])
2142
2181
  result = self._app_schema_apply_once(
2143
2182
  profile=profile,
2144
2183
  app_key=app_key,
@@ -2153,6 +2192,7 @@ class AiBuilderTools(ToolBase):
2153
2192
  add_fields=add_fields,
2154
2193
  update_fields=update_fields,
2155
2194
  remove_fields=remove_fields,
2195
+ inline_form_layout_sections=inline_form_layout_sections,
2156
2196
  )
2157
2197
  result = self._retry_after_self_lock_release(
2158
2198
  profile=profile,
@@ -2171,6 +2211,7 @@ class AiBuilderTools(ToolBase):
2171
2211
  add_fields=add_fields,
2172
2212
  update_fields=update_fields,
2173
2213
  remove_fields=remove_fields,
2214
+ inline_form_layout_sections=inline_form_layout_sections,
2174
2215
  ),
2175
2216
  )
2176
2217
  return _attach_builder_apply_envelope("app_schema_apply", result)
@@ -2429,6 +2470,19 @@ class AiBuilderTools(ToolBase):
2429
2470
  remove_fields = list(compiled_item.get("remove_fields") or [])
2430
2471
  if bool(existing.get("created")) and not deferred_add_fields and not update_fields and not remove_fields:
2431
2472
  shell_result = existing.get("shell_result") if isinstance(existing.get("shell_result"), dict) else {}
2473
+ layout_sections = list(compiled_item.get("_inline_form_layout_sections") or [])
2474
+ if layout_sections:
2475
+ shell_result = self._apply_inline_form_layout_after_schema(
2476
+ profile=profile,
2477
+ schema_result=shell_result,
2478
+ fallback_app_key=app_key,
2479
+ publish=publish,
2480
+ sections=layout_sections,
2481
+ )
2482
+ if _schema_apply_result_has_write(shell_result):
2483
+ any_write_executed = True
2484
+ if _schema_apply_result_may_have_write(shell_result):
2485
+ any_write_may_have_succeeded = True
2432
2486
  item_status = shell_result.get("status") if shell_result.get("status") in {"success", "partial_success"} else "failed"
2433
2487
  shell_field_diff = existing.get("shell_field_diff") if isinstance(existing.get("shell_field_diff"), dict) else {}
2434
2488
  shell_field_diff_details = existing.get("shell_field_diff_details") if isinstance(existing.get("shell_field_diff_details"), dict) else {}
@@ -2449,6 +2503,8 @@ class AiBuilderTools(ToolBase):
2449
2503
  "safe_to_retry": False,
2450
2504
  **({"next_action": shell_result.get("next_action")} if shell_result.get("next_action") else {}),
2451
2505
  **({"verification": shell_result.get("verification")} if isinstance(shell_result.get("verification"), dict) else {}),
2506
+ **({"inline_form_layout": shell_result.get("inline_form_layout")} if isinstance(shell_result.get("inline_form_layout"), dict) else {}),
2507
+ **({"inline_form_layout_result": shell_result.get("inline_form_layout_result")} if isinstance(shell_result.get("inline_form_layout_result"), dict) else {}),
2452
2508
  })
2453
2509
  continue
2454
2510
 
@@ -2468,6 +2524,15 @@ class AiBuilderTools(ToolBase):
2468
2524
  remove_fields=remove_fields,
2469
2525
  )
2470
2526
  public_result = _publicize_package_fields(field_result)
2527
+ layout_sections = list(compiled_item.get("_inline_form_layout_sections") or [])
2528
+ if layout_sections:
2529
+ public_result = self._apply_inline_form_layout_after_schema(
2530
+ profile=profile,
2531
+ schema_result=public_result,
2532
+ fallback_app_key=app_key,
2533
+ publish=publish,
2534
+ sections=layout_sections,
2535
+ )
2471
2536
  if _schema_apply_result_has_write(public_result):
2472
2537
  any_write_executed = True
2473
2538
  if _schema_apply_result_may_have_write(public_result):
@@ -2499,6 +2564,8 @@ class AiBuilderTools(ToolBase):
2499
2564
  "safe_to_retry": False,
2500
2565
  **({"next_action": public_result.get("next_action")} if public_result.get("next_action") else {}),
2501
2566
  **({"verification": public_result.get("verification")} if isinstance(public_result.get("verification"), dict) else {}),
2567
+ **({"inline_form_layout": public_result.get("inline_form_layout")} if isinstance(public_result.get("inline_form_layout"), dict) else {}),
2568
+ **({"inline_form_layout_result": public_result.get("inline_form_layout_result")} if isinstance(public_result.get("inline_form_layout_result"), dict) else {}),
2502
2569
  })
2503
2570
 
2504
2571
  pending_readback = sum(1 for item in final_items if item.get("status") == "pending_readback")
@@ -2562,6 +2629,7 @@ class AiBuilderTools(ToolBase):
2562
2629
  add_fields: list[JSONObject],
2563
2630
  update_fields: list[JSONObject],
2564
2631
  remove_fields: list[JSONObject],
2632
+ inline_form_layout_sections: list[JSONObject] | None = None,
2565
2633
  ) -> JSONObject:
2566
2634
  """执行内部辅助逻辑。"""
2567
2635
  effective_app_name = app_name or app_title
@@ -2673,7 +2741,83 @@ class AiBuilderTools(ToolBase):
2673
2741
  normalized_args=normalized_args,
2674
2742
  suggested_next_call={"tool_name": "app_schema_apply", "arguments": {"profile": profile, **normalized_args}},
2675
2743
  )
2676
- return _publicize_package_fields(result)
2744
+ public_result = _publicize_package_fields(result)
2745
+ if inline_form_layout_sections:
2746
+ public_result = self._apply_inline_form_layout_after_schema(
2747
+ profile=profile,
2748
+ schema_result=public_result,
2749
+ fallback_app_key=str(plan_args.get("app_key") or app_key),
2750
+ publish=publish,
2751
+ sections=inline_form_layout_sections,
2752
+ )
2753
+ return public_result
2754
+
2755
+ def _apply_inline_form_layout_after_schema(
2756
+ self,
2757
+ *,
2758
+ profile: str,
2759
+ schema_result: JSONObject,
2760
+ fallback_app_key: str = "",
2761
+ publish: bool,
2762
+ sections: list[JSONObject],
2763
+ ) -> JSONObject:
2764
+ result = deepcopy(schema_result)
2765
+ if not sections:
2766
+ return result
2767
+ app_key = str(result.get("app_key") or result.get("appKey") or fallback_app_key or "").strip()
2768
+ result["inline_form_layout"] = {
2769
+ "requested": True,
2770
+ "section_count": len(sections),
2771
+ "applied": False,
2772
+ }
2773
+ if result.get("status") not in {"success", "partial_success"}:
2774
+ result["inline_form_layout"]["skipped_reason"] = "schema_apply_failed"
2775
+ verification = result.get("verification") if isinstance(result.get("verification"), dict) else {}
2776
+ verification = deepcopy(verification)
2777
+ verification["inline_form_layout_verified"] = False
2778
+ result["verification"] = verification
2779
+ return result
2780
+ if not app_key:
2781
+ result["status"] = "partial_success"
2782
+ result["error_code"] = result.get("error_code") or "INLINE_FORM_LAYOUT_APP_KEY_MISSING"
2783
+ result["message"] = "schema applied but inline form layout could not run because app_key was not resolved"
2784
+ result["inline_form_layout"]["error_code"] = "INLINE_FORM_LAYOUT_APP_KEY_MISSING"
2785
+ verification = result.get("verification") if isinstance(result.get("verification"), dict) else {}
2786
+ verification = deepcopy(verification)
2787
+ verification["inline_form_layout_verified"] = False
2788
+ result["verification"] = verification
2789
+ result["safe_to_retry"] = False
2790
+ return result
2791
+ layout_result = self._app_layout_apply_once(
2792
+ profile=profile,
2793
+ app_key=app_key,
2794
+ mode="merge",
2795
+ publish=publish,
2796
+ sections=sections,
2797
+ )
2798
+ layout_ok = isinstance(layout_result, dict) and layout_result.get("status") in {"success", "partial_success"}
2799
+ result["inline_form_layout"] = {
2800
+ "requested": True,
2801
+ "section_count": len(sections),
2802
+ "app_key": app_key,
2803
+ "applied": layout_ok,
2804
+ "layout_status": layout_result.get("status") if isinstance(layout_result, dict) else "failed",
2805
+ **({"error_code": layout_result.get("error_code")} if isinstance(layout_result, dict) and layout_result.get("error_code") else {}),
2806
+ **({"message": layout_result.get("message")} if isinstance(layout_result, dict) and layout_result.get("message") else {}),
2807
+ }
2808
+ result["inline_form_layout_result"] = layout_result
2809
+ verification = result.get("verification") if isinstance(result.get("verification"), dict) else {}
2810
+ verification = deepcopy(verification)
2811
+ verification["inline_form_layout_verified"] = layout_ok
2812
+ result["verification"] = verification
2813
+ if layout_ok:
2814
+ result["write_executed"] = True
2815
+ return result
2816
+ result["status"] = "partial_success" if result.get("status") == "success" else result.get("status", "partial_success")
2817
+ result["error_code"] = result.get("error_code") or "INLINE_FORM_LAYOUT_APPLY_FAILED"
2818
+ result["message"] = "schema applied but inline form layout failed"
2819
+ result["safe_to_retry"] = False
2820
+ return result
2677
2821
 
2678
2822
  @tool_cn_name("应用布局应用")
2679
2823
  def app_layout_apply(
@@ -3556,7 +3700,12 @@ def _schema_apps_expected_shape() -> JSONObject:
3556
3700
  "app_name": "员工花名册",
3557
3701
  "icon": "business-personalcard",
3558
3702
  "color": "emerald",
3559
- "add_fields": [{"name": "员工名称", "type": "text", "as_data_title": True}],
3703
+ "form": [
3704
+ {
3705
+ "section": "基础信息",
3706
+ "rows": [[{"name": "员工名称", "type": "text", "data_title": True}]],
3707
+ }
3708
+ ],
3560
3709
  }
3561
3710
  ],
3562
3711
  }
@@ -3565,7 +3714,7 @@ def _schema_apps_expected_shape() -> JSONObject:
3565
3714
  def _schema_apps_expected_shape_json() -> str:
3566
3715
  return (
3567
3716
  '{"package_id":1001,"apps":[{"client_key":"employee","app_name":"员工花名册",'
3568
- '"icon":"business-personalcard","color":"emerald","add_fields":[{"name":"员工名称","type":"text","as_data_title":true}]}]}'
3717
+ '"icon":"business-personalcard","color":"emerald","form":[{"section":"基础信息","rows":[[{"name":"员工名称","type":"text","data_title":true}]]}]}]}'
3569
3718
  )
3570
3719
 
3571
3720
 
@@ -3650,6 +3799,163 @@ def _normalize_schema_apps_argument(*, tool_name: str, package_id: int | None, a
3650
3799
  return {"package_id": normalized_package_id, "apps": normalized_items, "warnings": warnings}
3651
3800
 
3652
3801
 
3802
+ def _normalize_schema_form_field(field: JSONObject) -> JSONObject:
3803
+ payload = deepcopy(field)
3804
+ if "data_title" in payload and "as_data_title" not in payload and "asDataTitle" not in payload:
3805
+ payload["as_data_title"] = payload.pop("data_title")
3806
+ if "dataTitle" in payload and "as_data_title" not in payload and "asDataTitle" not in payload:
3807
+ payload["as_data_title"] = payload.pop("dataTitle")
3808
+ if "data_cover" in payload and "as_data_cover" not in payload and "asDataCover" not in payload:
3809
+ payload["as_data_cover"] = payload.pop("data_cover")
3810
+ if "dataCover" in payload and "as_data_cover" not in payload and "asDataCover" not in payload:
3811
+ payload["as_data_cover"] = payload.pop("dataCover")
3812
+ return payload
3813
+
3814
+
3815
+ def _schema_form_entry_name(entry: object) -> str:
3816
+ if isinstance(entry, dict):
3817
+ for key in ("name", "title", "label", "field_name", "fieldName"):
3818
+ if entry.get(key) is not None:
3819
+ return str(entry.get(key) or "").strip()
3820
+ return ""
3821
+ if isinstance(entry, (str, int)):
3822
+ return str(entry).strip()
3823
+ return ""
3824
+
3825
+
3826
+ def _schema_form_failure(*, tool_name: str, path: str, message: str, fix_hint: str) -> JSONObject:
3827
+ return _config_failure(
3828
+ tool_name=tool_name,
3829
+ error_code="FORM_SHAPE_INVALID",
3830
+ message=message,
3831
+ fix_hint=fix_hint,
3832
+ details={
3833
+ "path": path,
3834
+ "expected_shape": {
3835
+ "form": [
3836
+ {
3837
+ "section": "基础信息",
3838
+ "rows": [
3839
+ [
3840
+ {"name": "标题", "type": "text", "data_title": True},
3841
+ {"name": "状态", "type": "single_select", "options": ["待处理", "处理中", "已完成"]},
3842
+ ]
3843
+ ],
3844
+ }
3845
+ ]
3846
+ },
3847
+ },
3848
+ )
3849
+
3850
+
3851
+ def _compile_schema_form_payload(*, tool_name: str, form: object, path: str = "form") -> JSONObject:
3852
+ if form is None:
3853
+ return {"add_fields": [], "layout_sections": []}
3854
+ if not isinstance(form, list) or not form:
3855
+ return {
3856
+ "failure": _schema_form_failure(
3857
+ tool_name=tool_name,
3858
+ path=path,
3859
+ message=f"{path} must be a non-empty list of form sections.",
3860
+ fix_hint='Use form=[{"section":"基础信息","rows":[[{"name":"标题","type":"text","data_title":true}]]}].',
3861
+ )
3862
+ }
3863
+
3864
+ add_fields: list[JSONObject] = []
3865
+ layout_sections: list[JSONObject] = []
3866
+ for section_index, section in enumerate(form):
3867
+ section_path = f"{path}[{section_index}]"
3868
+ if not isinstance(section, dict):
3869
+ return {
3870
+ "failure": _schema_form_failure(
3871
+ tool_name=tool_name,
3872
+ path=section_path,
3873
+ message=f"{section_path} must be an object.",
3874
+ fix_hint="Each form section must include section and rows.",
3875
+ )
3876
+ }
3877
+ section_title = str(section.get("section") or section.get("title") or section.get("name") or "").strip()
3878
+ rows = section.get("rows")
3879
+ if not section_title:
3880
+ return {
3881
+ "failure": _schema_form_failure(
3882
+ tool_name=tool_name,
3883
+ path=f"{section_path}.section",
3884
+ message=f"{section_path}.section is required.",
3885
+ fix_hint='Set a business section title such as "基础信息" or "生产信息".',
3886
+ )
3887
+ }
3888
+ if not isinstance(rows, list) or not rows:
3889
+ return {
3890
+ "failure": _schema_form_failure(
3891
+ tool_name=tool_name,
3892
+ path=f"{section_path}.rows",
3893
+ message=f"{section_path}.rows must be a non-empty list.",
3894
+ fix_hint="Use rows as a list of field rows; each row is a list of field objects.",
3895
+ )
3896
+ }
3897
+ layout_rows: list[list[str]] = []
3898
+ for row_index, row in enumerate(rows):
3899
+ row_path = f"{section_path}.rows[{row_index}]"
3900
+ if isinstance(row, dict):
3901
+ row_fields = row.get("fields")
3902
+ else:
3903
+ row_fields = row
3904
+ if not isinstance(row_fields, list) or not row_fields:
3905
+ return {
3906
+ "failure": _schema_form_failure(
3907
+ tool_name=tool_name,
3908
+ path=row_path,
3909
+ message=f"{row_path} must be a non-empty field list.",
3910
+ fix_hint='Use rows like [[{"name":"字段A","type":"text"},{"name":"字段B","type":"number"}]].',
3911
+ )
3912
+ }
3913
+ layout_row: list[str] = []
3914
+ for field_index, field in enumerate(row_fields):
3915
+ field_path = f"{row_path}[{field_index}]"
3916
+ field_name = _schema_form_entry_name(field)
3917
+ if not field_name:
3918
+ return {
3919
+ "failure": _schema_form_failure(
3920
+ tool_name=tool_name,
3921
+ path=field_path,
3922
+ message=f"{field_path} must include a field name.",
3923
+ fix_hint='Each new field object must include name, for example {"name":"工单编号","type":"text"}.',
3924
+ )
3925
+ }
3926
+ layout_row.append(field_name)
3927
+ if isinstance(field, dict):
3928
+ add_fields.append(_normalize_schema_form_field(field))
3929
+ layout_rows.append(layout_row)
3930
+ layout_sections.append({"title": section_title, "rows": layout_rows})
3931
+ return {"add_fields": add_fields, "layout_sections": layout_sections}
3932
+
3933
+
3934
+ def _apply_schema_form_to_payload(*, tool_name: str, payload: JSONObject, path: str) -> JSONObject:
3935
+ form = payload.get("form")
3936
+ if form is None:
3937
+ return {"payload": payload, "layout_sections": []}
3938
+ existing_add_fields = payload.get("add_fields") or payload.get("addFields")
3939
+ if isinstance(existing_add_fields, list) and existing_add_fields:
3940
+ return {
3941
+ "failure": _config_failure(
3942
+ tool_name=tool_name,
3943
+ error_code="FORM_WITH_ADD_FIELDS_CONFLICT",
3944
+ message=f"{path} cannot use form and add_fields together.",
3945
+ fix_hint="Use form as the single schema creation shape: put fields under form[].rows[][].",
3946
+ details={"path": path, "conflicting_keys": ["form", "add_fields"]},
3947
+ )
3948
+ }
3949
+ compiled = _compile_schema_form_payload(tool_name=tool_name, form=form, path=f"{path}.form")
3950
+ if isinstance(compiled.get("failure"), dict):
3951
+ return {"failure": compiled["failure"]}
3952
+ normalized = deepcopy(payload)
3953
+ normalized.pop("form", None)
3954
+ normalized["add_fields"] = compiled.get("add_fields") or []
3955
+ normalized["_inline_form_layout_sections"] = compiled.get("layout_sections") or []
3956
+ return {"payload": normalized, "layout_sections": compiled.get("layout_sections") or []}
3957
+
3958
+
3653
3959
  def _multi_app_item_app_name(item: JSONObject) -> str:
3654
3960
  return str(item.get("app_name") or item.get("appName") or item.get("appTitle") or item.get("app_title") or item.get("title") or "").strip()
3655
3961
 
@@ -3671,7 +3977,7 @@ def _field_type_for_static_validation(field: JSONObject) -> str:
3671
3977
 
3672
3978
 
3673
3979
  def _is_data_title_field(field: JSONObject) -> bool:
3674
- return bool(field.get("as_data_title") or field.get("asDataTitle"))
3980
+ return bool(field.get("as_data_title") or field.get("asDataTitle") or field.get("data_title") or field.get("dataTitle"))
3675
3981
 
3676
3982
 
3677
3983
  def _collect_multi_app_target_refs(value: object, *, path: str) -> list[JSONObject]:
@@ -6004,6 +6310,10 @@ _BUILDER_TOOL_CONTRACTS: dict[str, JSONObject] = {
6004
6310
  "field.customBtnTextStatus": "field.custom_button_text_enabled",
6005
6311
  "field.customBtnText": "field.custom_button_text",
6006
6312
  "field.subfieldUpdates": "field.subfield_updates",
6313
+ "field.data_title": "field.as_data_title",
6314
+ "field.dataTitle": "field.as_data_title",
6315
+ "field.data_cover": "field.as_data_cover",
6316
+ "field.dataCover": "field.as_data_cover",
6007
6317
  "field.asDataTitle": "field.as_data_title",
6008
6318
  "field.asDataCover": "field.as_data_cover",
6009
6319
  },
@@ -6031,7 +6341,7 @@ _BUILDER_TOOL_CONTRACTS: dict[str, JSONObject] = {
6031
6341
  "color": "emerald",
6032
6342
  "visibility": deepcopy(_VISIBILITY_WORKSPACE_EXAMPLE),
6033
6343
  "create_if_missing": True,
6034
- "add_fields": [{"name": "项目名称", "type": "text", "as_data_title": True}],
6344
+ "add_fields": [{"name": "项目名称", "type": "text", "data_title": True}],
6035
6345
  "update_fields": [],
6036
6346
  "remove_fields": [],
6037
6347
  },
@@ -6066,6 +6376,7 @@ _BUILDER_TOOL_CONTRACTS: dict[str, JSONObject] = {
6066
6376
  "visibility",
6067
6377
  "create_if_missing",
6068
6378
  "publish",
6379
+ "form",
6069
6380
  "add_fields",
6070
6381
  "update_fields",
6071
6382
  "remove_fields",
@@ -6079,6 +6390,9 @@ _BUILDER_TOOL_CONTRACTS: dict[str, JSONObject] = {
6079
6390
  "apps[].icon_color",
6080
6391
  "apps[].icon_config",
6081
6392
  "apps[].visibility",
6393
+ "apps[].form",
6394
+ "apps[].form[].section",
6395
+ "apps[].form[].rows",
6082
6396
  "apps[].add_fields",
6083
6397
  "apps[].update_fields",
6084
6398
  "apps[].remove_fields",
@@ -6123,6 +6437,10 @@ _BUILDER_TOOL_CONTRACTS: dict[str, JSONObject] = {
6123
6437
  "field.customBtnTextStatus": "field.custom_button_text_enabled",
6124
6438
  "field.customBtnText": "field.custom_button_text",
6125
6439
  "field.subfieldUpdates": "field.subfield_updates",
6440
+ "field.data_title": "field.as_data_title",
6441
+ "field.dataTitle": "field.as_data_title",
6442
+ "field.data_cover": "field.as_data_cover",
6443
+ "field.dataCover": "field.as_data_cover",
6126
6444
  "field.asDataTitle": "field.as_data_title",
6127
6445
  "field.asDataCover": "field.as_data_cover",
6128
6446
  },
@@ -6143,6 +6461,8 @@ _BUILDER_TOOL_CONTRACTS: dict[str, JSONObject] = {
6143
6461
  "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",
6144
6462
  "multi-app mode: pass package_id + apps[]; create_if_missing defaults to true for app_name items and may be set false only when every item uses app_key",
6145
6463
  "CLI --apps-file primary shape is {package_id, apps:[...]}; raw app arrays and singleton wrapper arrays are compatibility paths, not recommended examples",
6464
+ "create app schemas with form: form[].section names form sections; form[].rows[][] contains field objects; builder splits form into field creation plus form layout apply",
6465
+ "single-app CLI primary shape is --form-file; multi-app primary shape is apps[].form inside --apps-file",
6146
6466
  "multi-app mode preflights static errors before writing: duplicate client_key/app_name, missing data title on new apps, explicit create_if_missing=false with app_name items, and unresolved target_app_ref/target_app",
6147
6467
  "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",
6148
6468
  "multi-app relation fields may also use target_app with another apps[].app_name; prefer target_app_ref/client_key when names may collide",
@@ -6186,9 +6506,16 @@ _BUILDER_TOOL_CONTRACTS: dict[str, JSONObject] = {
6186
6506
  "visibility": deepcopy(_VISIBILITY_WORKSPACE_EXAMPLE),
6187
6507
  "create_if_missing": True,
6188
6508
  "publish": True,
6189
- "add_fields": [
6190
- {"name": "项目名称", "type": "text", "as_data_title": True},
6191
- {"name": "项目封面", "type": "attachment", "as_data_cover": True},
6509
+ "form": [
6510
+ {
6511
+ "section": "基础信息",
6512
+ "rows": [
6513
+ [
6514
+ {"name": "项目名称", "type": "text", "data_title": True},
6515
+ {"name": "项目封面", "type": "attachment", "data_cover": True},
6516
+ ]
6517
+ ],
6518
+ }
6192
6519
  ],
6193
6520
  "update_fields": [],
6194
6521
  "remove_fields": [],
@@ -6203,9 +6530,16 @@ _BUILDER_TOOL_CONTRACTS: dict[str, JSONObject] = {
6203
6530
  "app_name": "员工花名册",
6204
6531
  "icon": "business-personalcard",
6205
6532
  "color": "emerald",
6206
- "add_fields": [
6207
- {"name": "员工名称", "type": "text", "as_data_title": True},
6208
- {"name": "员工照片", "type": "attachment", "as_data_cover": True},
6533
+ "form": [
6534
+ {
6535
+ "section": "基础信息",
6536
+ "rows": [
6537
+ [
6538
+ {"name": "员工名称", "type": "text", "data_title": True},
6539
+ {"name": "员工照片", "type": "attachment", "data_cover": True},
6540
+ ]
6541
+ ],
6542
+ }
6209
6543
  ],
6210
6544
  },
6211
6545
  {
@@ -6213,15 +6547,22 @@ _BUILDER_TOOL_CONTRACTS: dict[str, JSONObject] = {
6213
6547
  "app_name": "工时表",
6214
6548
  "icon": "clock",
6215
6549
  "color": "blue",
6216
- "add_fields": [
6217
- {"name": "工时标题", "type": "text", "as_data_title": True},
6550
+ "form": [
6218
6551
  {
6219
- "name": "关联员工",
6220
- "type": "relation",
6221
- "target_app_ref": "employee",
6222
- "display_field": {"name": "员工名称"},
6223
- "visible_fields": [{"name": "员工名称"}],
6224
- },
6552
+ "section": "基础信息",
6553
+ "rows": [
6554
+ [{"name": "工时标题", "type": "text", "data_title": True}],
6555
+ [
6556
+ {
6557
+ "name": "关联员工",
6558
+ "type": "relation",
6559
+ "target_app_ref": "employee",
6560
+ "display_field": {"name": "员工名称"},
6561
+ "visible_fields": [{"name": "员工名称"}],
6562
+ }
6563
+ ],
6564
+ ],
6565
+ }
6225
6566
  ],
6226
6567
  },
6227
6568
  ],
@@ -7105,15 +7446,38 @@ _BUILDER_TOOL_CONTRACTS: dict[str, JSONObject] = {
7105
7446
  "name": "dash_name",
7106
7447
  "sourceType": "source_type",
7107
7448
  "chartRef": "chart_ref",
7449
+ "inlineChart": "inline_chart",
7450
+ "createChart": "inline_chart",
7108
7451
  "viewRef": "view_ref",
7109
7452
  "dashStyleConfigBO": "dash_style_config",
7110
7453
  },
7111
- "section_allowed_keys": ["title", "source_type", "role", "position", "dash_style_config", "config", "chart_ref", "view_ref", "text", "url"],
7454
+ "section_allowed_keys": [
7455
+ "title",
7456
+ "source_type",
7457
+ "role",
7458
+ "position",
7459
+ "dash_style_config",
7460
+ "config",
7461
+ "chart_ref",
7462
+ "inline_chart",
7463
+ "inline_chart.app_key",
7464
+ "inline_chart.chart_name",
7465
+ "inline_chart.chart_type",
7466
+ "inline_chart.metric",
7467
+ "inline_chart.metrics",
7468
+ "inline_chart.group_by",
7469
+ "inline_chart.where",
7470
+ "view_ref",
7471
+ "text",
7472
+ "url",
7473
+ ],
7112
7474
  "section_aliases": {
7113
7475
  "sourceType": "source_type",
7114
7476
  "zone": "role",
7115
7477
  "sectionRole": "role",
7116
7478
  "chartRef": "chart_ref",
7479
+ "inlineChart": "inline_chart",
7480
+ "createChart": "inline_chart",
7117
7481
  "viewRef": "view_ref",
7118
7482
  "dashStyleConfigBO": "dash_style_config",
7119
7483
  },
@@ -7139,6 +7503,8 @@ _BUILDER_TOOL_CONTRACTS: dict[str, JSONObject] = {
7139
7503
  "package_id is required when creating a new portal",
7140
7504
  "publish=false only guarantees draft and base-info updates; it does not claim live has changed",
7141
7505
  "chart_ref resolves by chart_id first, then exact unique chart_name",
7506
+ "inline_chart internally creates or updates an app-source QingBI report, then uses the returned chart_id for this portal section",
7507
+ "use chart_ref when an existing report already matches; use inline_chart when the portal needs a new or adjusted report",
7142
7508
  "view_ref resolves by view_key first, then exact unique view_name",
7143
7509
  "pc layout uses a 24-column grid; mobile layout uses a 6-column grid",
7144
7510
  "if unsure about layout, omit position or use layout_preset=auto/dashboard_2col/dashboard_3col",
@@ -7166,7 +7532,12 @@ _BUILDER_TOOL_CONTRACTS: dict[str, JSONObject] = {
7166
7532
  {
7167
7533
  "title": "经营概览",
7168
7534
  "source_type": "chart",
7169
- "chart_ref": {"app_key": "APP_KEY", "chart_name": "数据总量"},
7535
+ "inline_chart": {
7536
+ "app_key": "APP_KEY",
7537
+ "chart_name": "数据总量",
7538
+ "chart_type": "summary",
7539
+ "metric": {"field": "数据ID", "agg": "count"},
7540
+ },
7170
7541
  "position": {
7171
7542
  "pc": {"x": 0, "y": 0, "cols": 12, "rows": 6},
7172
7543
  "mobile": {"x": 0, "y": 0, "cols": 6, "rows": 6},