@qingflow-tech/qingflow-cli 1.1.43 → 1.1.44-beta.1

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.
Files changed (77) hide show
  1. package/README.md +13 -6
  2. package/entry_point.py +1 -1
  3. package/npm/bin/qingflow.mjs +1 -2
  4. package/npm/lib/runtime.mjs +3 -7
  5. package/package.json +2 -2
  6. package/pyproject.toml +3 -4
  7. package/skills/qingflow-app-form/SKILL.md +66 -0
  8. package/skills/qingflow-app-form/agents/openai.yaml +4 -0
  9. package/skills/qingflow-cli/SKILL.md +8 -6
  10. package/skills/qingflow-cli/manifest.yaml +1 -1
  11. package/skills/qingflow-cli/reference/QINGFLOW_CLI_BUILDER_APP_DELIVERY_WORKFLOW.md +4 -4
  12. package/skills/qingflow-cli/reference/QINGFLOW_CLI_EXPLORATION_REPORT.md +1 -1
  13. package/skills/qingflow-cli/reference/QINGFLOW_CLI_FIELD_DATA_TYPES.md +1 -1
  14. package/skills/qingflow-cli/reference/QINGFLOW_CLI_SCHEMA_APPLY_FIELD_TYPES_AND_SCENARIOS.md +4 -4
  15. package/skills/qingflow-cli/reference/builder/10-build-single-app.md +5 -5
  16. package/skills/qingflow-cli/reference/builder/20-build-complete-system.md +14 -14
  17. package/skills/qingflow-cli/reference/builder/30-schema-fields.md +106 -103
  18. package/skills/qingflow-cli/reference/builder/40-layout.md +39 -31
  19. package/skills/qingflow-cli/reference/builder/README.md +9 -9
  20. package/skills/qingflow-cli/reference/builder/code-integrations/README.md +4 -2
  21. package/skills/qingflow-cli/reference/builder/code-integrations/code-block.md +2 -0
  22. package/skills/qingflow-cli/reference/builder/code-integrations/q-linker.md +2 -0
  23. package/skills/qingflow-cli/reference/builder/reference/app-delivery-sop.md +45 -38
  24. package/skills/qingflow-cli/reference/core/QINGFLOW_CLI_EXPLORATION_REPORT.md +1 -1
  25. package/skills/qingflow-cli/reference/core/QINGFLOW_CLI_FIELD_DATA_TYPES.md +1 -1
  26. package/skills/qingflow-cli/reference/examples/README.md +3 -3
  27. package/skills/qingflow-common/SKILL.md +47 -0
  28. package/skills/qingflow-common/agents/openai.yaml +4 -0
  29. package/src/qingflow_mcp/__main__.py +2 -3
  30. package/src/qingflow_mcp/app_form_compat.py +104 -0
  31. package/src/qingflow_mcp/app_form_validator.py +462 -0
  32. package/src/qingflow_mcp/builder_facade/app_form.py +4196 -0
  33. package/src/qingflow_mcp/builder_facade/app_form_schema.py +425 -0
  34. package/src/qingflow_mcp/builder_facade/schemas/app_form/manifest.json +42 -0
  35. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/complete.json +2969 -0
  36. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/address.json +392 -0
  37. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/amount.json +236 -0
  38. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/attachment.json +425 -0
  39. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/code_block.json +318 -0
  40. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/data_relation.json +580 -0
  41. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/date.json +150 -0
  42. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/datetime.json +150 -0
  43. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/department.json +345 -0
  44. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/email.json +190 -0
  45. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/link.json +190 -0
  46. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/long_text.json +190 -0
  47. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/member.json +484 -0
  48. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/multi_select.json +214 -0
  49. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/number.json +236 -0
  50. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/phone.json +199 -0
  51. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/q_linker.json +412 -0
  52. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/relation.json +454 -0
  53. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/single_choice.json +214 -0
  54. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/single_select.json +214 -0
  55. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/subtable.json +1921 -0
  56. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/fields/text.json +190 -0
  57. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/formula.json +1594 -0
  58. package/src/qingflow_mcp/builder_facade/schemas/app_form/v1alpha1/summary.json +718 -0
  59. package/src/qingflow_mcp/builder_facade/service.py +8 -4
  60. package/src/qingflow_mcp/cli/commands/builder.py +93 -28
  61. package/src/qingflow_mcp/cli/json_io.py +21 -2
  62. package/src/qingflow_mcp/cli/main.py +3 -39
  63. package/src/qingflow_mcp/public_surface.py +5 -2
  64. package/src/qingflow_mcp/response_trim.py +50 -0
  65. package/src/qingflow_mcp/server.py +24 -3
  66. package/src/qingflow_mcp/server_app_builder.py +44 -87
  67. package/src/qingflow_mcp/tools/ai_builder_tools.py +103 -100
  68. package/src/qingflow_mcp/tools/app_tools.py +46 -65
  69. package/src/qingflow_mcp/tools/record_tools.py +3 -3
  70. package/src/qingflow_mcp/version.py +2 -4
  71. package/docs/local-agent-install.md +0 -370
  72. package/skills/qingflow-mcp-setup/SKILL.md +0 -115
  73. package/skills/qingflow-mcp-setup/agents/openai.yaml +0 -4
  74. package/skills/qingflow-mcp-setup/references/claude-desktop.md +0 -34
  75. package/skills/qingflow-mcp-setup/references/environments.md +0 -62
  76. package/skills/qingflow-mcp-setup/references/generic-stdio.md +0 -32
  77. package/skills/qingflow-mcp-setup/scripts/check_local_server.sh +0 -38
@@ -0,0 +1,462 @@
1
+ from __future__ import annotations
2
+
3
+ from copy import deepcopy
4
+ import json
5
+ import re
6
+ from typing import Any, Iterable
7
+
8
+ from jsonschema import Draft202012Validator, FormatChecker
9
+
10
+ from .app_form_compat import normalize_app_form_declaration
11
+ from .builder_facade.app_form_schema import AppFormContractError, compact_schema_errors, schema_error_message
12
+
13
+
14
+ _INTEGRATION_OUTPUT_TARGET_FIELD_TYPES = {
15
+ "text",
16
+ "long_text",
17
+ "number",
18
+ "amount",
19
+ "date",
20
+ "datetime",
21
+ "single_choice",
22
+ "single_select",
23
+ "multi_select",
24
+ }
25
+ _Q_LINKER_TEMPLATE_RE = re.compile(r"\{\{(?P<key>[^{}\s]+)\}\}")
26
+ _FORMULA_IDENTIFIER_RE = re.compile(r"[A-Za-z_][A-Za-z0-9_]*")
27
+
28
+
29
+ class AppFormValidationError(ValueError):
30
+ """Raised when a declaration fails local AppForm validation."""
31
+
32
+ def __init__(self, issues: list[dict[str, str]], *, schema_version: str, api_version: str) -> None:
33
+ super().__init__("AppForm declaration is invalid")
34
+ self.issues = issues
35
+ self.schema_version = schema_version
36
+ self.api_version = api_version
37
+
38
+
39
+ def _field_type(field: dict[str, Any]) -> str:
40
+ return str(field.get("questionType") or field.get("type") or "").strip()
41
+
42
+
43
+ def _field_types(payload: dict[str, Any]) -> tuple[str, ...]:
44
+ found: set[str] = set()
45
+
46
+ def visit(field: Any) -> None:
47
+ if not isinstance(field, dict):
48
+ return
49
+ field_type = _field_type(field)
50
+ if field_type:
51
+ found.add(field_type)
52
+ for child in field.get("subfields") or []:
53
+ visit(child)
54
+
55
+ spec = payload.get("spec")
56
+ for block in spec.get("body") or [] if isinstance(spec, dict) else []:
57
+ if not isinstance(block, dict):
58
+ continue
59
+ rows = [block] if block.get("kind") == "row" else block.get("rows") or []
60
+ for row in rows:
61
+ for field in row.get("fields") or [] if isinstance(row, dict) else []:
62
+ visit(field)
63
+ return tuple(sorted(found))
64
+
65
+
66
+ def _local_schema_call(schema_version: str | None, field_type: str | None) -> dict[str, Any]:
67
+ from .builder_facade.app_form_schema import app_form_schema_registry
68
+
69
+ return {"status": "success", **app_form_schema_registry().schema(schema_version=schema_version, field_type=field_type)}
70
+
71
+
72
+ def _supported_formula_functions(schema_version: str) -> frozenset[str]:
73
+ """Load the version-pinned formula function catalogue used by local validation."""
74
+ from .builder_facade.app_form_schema import app_form_schema_registry
75
+
76
+ response = app_form_schema_registry().schema(schema_version=schema_version, schema_kind="formula")
77
+ schema = response.get("schema") if isinstance(response, dict) else None
78
+ functions = schema.get("x-qingflow-functions") if isinstance(schema, dict) else None
79
+ if not isinstance(functions, dict) or not functions:
80
+ raise RuntimeError(f"/: AppForm formula Schema has no function catalogue for {schema_version}")
81
+ return frozenset(str(name).upper() for name in functions if isinstance(name, str) and name)
82
+
83
+
84
+ def _compose(summary: dict[str, Any], details: list[dict[str, Any]]) -> dict[str, Any]:
85
+ if not details:
86
+ raise RuntimeError("at least one field Schema is required to compose AppForm validation")
87
+ schema = deepcopy(summary["schema"])
88
+ shared_defs = deepcopy(schema.get("$defs") or {})
89
+ field_branches = []
90
+ for detail in details:
91
+ detail_schema = detail["schema"]
92
+ for name, definition in (detail_schema.get("$defs") or {}).items():
93
+ existing = shared_defs.get(name)
94
+ if existing is not None and existing != definition:
95
+ raise RuntimeError(f"field Schema definition conflict: {name}")
96
+ shared_defs[name] = deepcopy(definition)
97
+ branch = {
98
+ key: deepcopy(value)
99
+ for key, value in detail_schema.items()
100
+ if key not in {"$schema", "$id", "$defs", "title"}
101
+ }
102
+ field_branches.append(branch)
103
+ shared_defs["TopField"] = {"oneOf": field_branches}
104
+ schema["$defs"] = shared_defs
105
+ schema["properties"]["spec"] = {
106
+ "$ref": "#/$defs/AppFormSpec",
107
+ "description": "Application form target state.",
108
+ }
109
+ return schema
110
+
111
+
112
+ def _pointer(parts: Iterable[Any]) -> str:
113
+ encoded = [str(item).replace("~", "~0").replace("/", "~1") for item in parts]
114
+ return "/" + "/".join(encoded) if encoded else "/"
115
+
116
+
117
+ def _formula_function_calls(expression: str) -> set[str]:
118
+ """Extract calls outside quoted string literals without parsing the full formula grammar."""
119
+ calls: set[str] = set()
120
+ index = 0
121
+ while index < len(expression):
122
+ character = expression[index]
123
+ if character in {"'", '"'}:
124
+ quote = character
125
+ index += 1
126
+ while index < len(expression):
127
+ if expression[index] == "\\":
128
+ index += 2
129
+ continue
130
+ if expression[index] == quote:
131
+ index += 1
132
+ break
133
+ index += 1
134
+ continue
135
+ match = _FORMULA_IDENTIFIER_RE.match(expression, index)
136
+ if match is None:
137
+ index += 1
138
+ continue
139
+ name = match.group(0)
140
+ cursor = match.end()
141
+ while cursor < len(expression) and expression[cursor].isspace():
142
+ cursor += 1
143
+ if cursor < len(expression) and expression[cursor] in {"(", "("}:
144
+ calls.add(name)
145
+ index = match.end()
146
+ return calls
147
+
148
+
149
+ def _iter_formula_expressions(payload: dict[str, Any]) -> Iterable[tuple[str, str]]:
150
+ spec = payload.get("spec")
151
+ body = spec.get("body") if isinstance(spec, dict) else None
152
+ if not isinstance(body, list):
153
+ return
154
+
155
+ def visit(field: Any, path: str) -> Iterable[tuple[str, str]]:
156
+ if not isinstance(field, dict):
157
+ return
158
+ if field.get("defaultType") == 3 and isinstance(field.get("defaultValue"), str):
159
+ yield f"{path}/defaultValue", field["defaultValue"]
160
+ config = field.get("config") if isinstance(field.get("config"), dict) else {}
161
+ default_value_formula = config.get("defaultValueFormula")
162
+ if isinstance(default_value_formula, str):
163
+ yield f"{path}/config/defaultValueFormula", default_value_formula
164
+ filters = config.get("filters") if isinstance(config.get("filters"), dict) else {}
165
+ if filters.get("mode") == "advanced" and isinstance(filters.get("formula"), str):
166
+ yield f"{path}/config/filters/formula", filters["formula"]
167
+ for child_index, child in enumerate(field.get("subfields") or []):
168
+ yield from visit(child, f"{path}/subfields/{child_index}")
169
+
170
+ for block_index, block in enumerate(body):
171
+ if not isinstance(block, dict):
172
+ continue
173
+ rows = [(block, f"/spec/body/{block_index}")] if block.get("kind") == "row" else [
174
+ (row, f"/spec/body/{block_index}/rows/{row_index}")
175
+ for row_index, row in enumerate(block.get("rows") or [])
176
+ ]
177
+ for row, row_path in rows:
178
+ if not isinstance(row, dict):
179
+ continue
180
+ for field_index, field in enumerate(row.get("fields") or []):
181
+ yield from visit(field, f"{row_path}/fields/{field_index}")
182
+
183
+
184
+ def _formula_errors(payload: dict[str, Any], supported_functions: frozenset[str]) -> list[tuple[str, str]]:
185
+ errors: list[tuple[str, str]] = []
186
+ for pointer, expression in _iter_formula_expressions(payload):
187
+ unknown = sorted(name for name in _formula_function_calls(expression) if name.upper() not in supported_functions)
188
+ for name in unknown:
189
+ errors.append(
190
+ (
191
+ pointer,
192
+ f"unsupported formula function '{name}'; use a function declared by builder app-form schema --schema-kind formula",
193
+ )
194
+ )
195
+ return errors
196
+
197
+
198
+ def _static_errors(payload: dict[str, Any]) -> list[tuple[str, str]]:
199
+ errors: list[tuple[str, str]] = []
200
+ spec = payload.get("spec")
201
+ body = spec.get("body") if isinstance(spec, dict) else None
202
+ if not isinstance(body, list):
203
+ return errors
204
+ top_fields: list[tuple[str, dict[str, Any]]] = []
205
+ for block_index, block in enumerate(body):
206
+ if not isinstance(block, dict):
207
+ continue
208
+ rows = [block] if block.get("kind") == "row" else block.get("rows") or []
209
+ for row_index, row in enumerate(rows):
210
+ if not isinstance(row, dict):
211
+ continue
212
+ fields = row.get("fields")
213
+ if not isinstance(fields, list):
214
+ continue
215
+ row_path = f"/spec/body/{block_index}/" + ("fields" if block.get("kind") == "row" else f"rows/{row_index}/fields")
216
+ widths = ["width" in field for field in fields if isinstance(field, dict)]
217
+ if widths and any(widths) and not all(widths):
218
+ errors.append((row_path, "width must be present on every field in the row or omitted from all"))
219
+ if widths and all(widths) and sum(field.get("width", 0) for field in fields if isinstance(field, dict)) != 100:
220
+ errors.append((row_path, "field widths must total 100"))
221
+ for field_index, field in enumerate(fields):
222
+ if isinstance(field, dict):
223
+ top_fields.append((f"{row_path}/{field_index}", field))
224
+ def resolve_local_selector(selector: Any) -> tuple[str, tuple[str, dict[str, Any]] | None]:
225
+ """Resolve against the declared body, preserving backend-dependent ID-only cases."""
226
+ if not isinstance(selector, dict):
227
+ return "schema", None
228
+ raw_que_id = selector.get("queId")
229
+ que_id = raw_que_id if isinstance(raw_que_id, int) and not isinstance(raw_que_id, bool) else None
230
+ raw_name = selector.get("name")
231
+ name = raw_name if isinstance(raw_name, str) and raw_name else ""
232
+ if raw_que_id is not None and que_id is None:
233
+ return "schema", None
234
+ if raw_name is not None and not name:
235
+ return "schema", None
236
+ if que_id is not None:
237
+ matches = [(path, field) for path, field in top_fields if field.get("queId") == que_id]
238
+ if len(matches) != 1:
239
+ return "invalid", None
240
+ declared_name = str(matches[0][1].get("name") or "")
241
+ if name and declared_name and name != declared_name:
242
+ return "invalid", None
243
+ return "resolved", matches[0]
244
+ if name:
245
+ matches = [(path, field) for path, field in top_fields if str(field.get("name") or "") == name]
246
+ if len(matches) == 1:
247
+ return "resolved", matches[0]
248
+ if len(matches) > 1:
249
+ return "invalid", None
250
+ if any(not str(field.get("name") or "") for _, field in top_fields):
251
+ return "unknown", None
252
+ return "invalid", None
253
+ return "schema", None
254
+
255
+ title_selector = spec.get("dataTitleField")
256
+ if top_fields:
257
+ if "dataTitleField" not in spec and "appKey" in payload:
258
+ pass
259
+ elif title_selector is None or resolve_local_selector(title_selector)[0] == "invalid":
260
+ errors.append(("/spec/dataTitleField", "dataTitleField must resolve to exactly one top-level field"))
261
+ elif title_selector is not None:
262
+ errors.append(("/spec/dataTitleField", "dataTitleField must be null when body is empty"))
263
+
264
+ cover_selector = spec.get("dataCoverField")
265
+ if cover_selector is not None:
266
+ cover_resolution, cover = resolve_local_selector(cover_selector)
267
+ if cover_resolution == "invalid":
268
+ errors.append(("/spec/dataCoverField", "dataCoverField must resolve to exactly one top-level field"))
269
+ elif cover_resolution == "resolved" and cover is not None and _field_type(cover[1]) != "attachment":
270
+ errors.append(("/spec/dataCoverField", "dataCoverField must select a top-level attachment field"))
271
+ names: dict[str, str] = {}
272
+ fields_by_id = {
273
+ field.get("queId"): field
274
+ for _, field in top_fields
275
+ if isinstance(field.get("queId"), int) and not isinstance(field.get("queId"), bool)
276
+ }
277
+ output_targets: dict[str, tuple[str, str]] = {}
278
+ for path, field in top_fields:
279
+ name = str(field.get("name") or "")
280
+ if name:
281
+ if name in names:
282
+ errors.append((f"{path}/name", f"duplicate top-level field name; first declared at {names[name]}"))
283
+ else:
284
+ names[name] = f"{path}/name"
285
+ field_type = _field_type(field)
286
+ if field_type == "data_relation":
287
+ config = field.get("config") if isinstance(field.get("config"), dict) else {}
288
+ filters = config.get("filters") if isinstance(config.get("filters"), dict) else {}
289
+ if filters.get("mode") == "simple":
290
+ for group_index, group in enumerate(filters.get("groups") or []):
291
+ for condition_index, condition in enumerate(group if isinstance(group, list) else []):
292
+ if not isinstance(condition, dict):
293
+ continue
294
+ operator = condition.get("operator")
295
+ operand = condition.get("operand") if isinstance(condition.get("operand"), dict) else {}
296
+ values = operand.get("values") if isinstance(operand.get("values"), list) else None
297
+ operand_path = (
298
+ f"{path}/config/filters/groups/{group_index}/{condition_index}/operand"
299
+ )
300
+ if operator in {"is_empty", "is_not_empty"}:
301
+ if operand.get("kind") != "literal" or values != []:
302
+ errors.append(
303
+ (
304
+ operand_path,
305
+ "is_empty and is_not_empty require a literal operand with values: []",
306
+ )
307
+ )
308
+ elif operand.get("kind") == "literal" and not values:
309
+ errors.append(
310
+ (
311
+ f"{operand_path}/values",
312
+ "literal operands for non-empty operators must contain at least one value",
313
+ )
314
+ )
315
+ if field_type == "q_linker":
316
+ binding_name = "qLinkerBinding"
317
+ elif field_type == "code_block":
318
+ binding_name = "codeBlockBinding"
319
+ else:
320
+ continue
321
+ binding = (field.get("config") or {}).get(binding_name) if isinstance(field.get("config"), dict) else None
322
+ if not isinstance(binding, dict):
323
+ continue
324
+ for index, item in enumerate(binding.get("inputs") or []):
325
+ if not isinstance(item, dict):
326
+ continue
327
+ selector = item.get("field") if isinstance(item.get("field"), dict) else {}
328
+ input_path = f"{path}/config/{binding_name}/inputs/{index}"
329
+ resolution, selected = resolve_local_selector(selector)
330
+ if resolution == "invalid":
331
+ errors.append((f"{input_path}/field", "input field must resolve to exactly one top-level field"))
332
+ continue
333
+ if field_type != "q_linker" or item.get("source") != "json_path":
334
+ continue
335
+ selected_name = selected[1].get("name") if selected is not None else selector.get("name")
336
+ if not selected_name and selector.get("queId") in fields_by_id:
337
+ selected_name = fields_by_id[selector["queId"]].get("name")
338
+ if selected_name and item.get("key") != selected_name:
339
+ errors.append((f"{input_path}/key", "json_path key must equal the selected field name"))
340
+
341
+ if field_type == "q_linker":
342
+ request = binding.get("request") if isinstance(binding.get("request"), dict) else {}
343
+ template_paths: dict[str, list[str]] = {}
344
+ for property_name in ("url", "jsonValue", "xmlValue"):
345
+ raw_template = request.get(property_name)
346
+ if not isinstance(raw_template, str):
347
+ continue
348
+ for match in _Q_LINKER_TEMPLATE_RE.finditer(raw_template):
349
+ template_paths.setdefault(match.group("key"), []).append(
350
+ f"{path}/config/{binding_name}/request/{property_name}"
351
+ )
352
+ input_items = [item for item in binding.get("inputs") or [] if isinstance(item, dict)]
353
+ json_path_inputs: dict[str, list[int]] = {}
354
+ for index, item in enumerate(input_items):
355
+ key = str(item.get("key") or "")
356
+ if key and item.get("source") == "json_path":
357
+ json_path_inputs.setdefault(key, []).append(index)
358
+ for key, request_paths in template_paths.items():
359
+ providers = json_path_inputs.get(key) or []
360
+ if len(providers) == 1:
361
+ continue
362
+ if not providers:
363
+ message = (
364
+ f"placeholder '{{{{{key}}}}}' requires an input with source 'json_path' and the same key; "
365
+ "query_param, header, and url_encoded inputs do not replace request templates"
366
+ )
367
+ else:
368
+ message = f"placeholder '{{{{{key}}}}}' must have exactly one json_path input"
369
+ errors.append((request_paths[0], message))
370
+ for key, indexes in json_path_inputs.items():
371
+ if key in template_paths:
372
+ continue
373
+ for index in indexes:
374
+ errors.append(
375
+ (
376
+ f"{path}/config/{binding_name}/inputs/{index}/source",
377
+ f"json_path input key '{key}' must appear as '{{{{{key}}}}}' in request.url, request.jsonValue, or request.xmlValue",
378
+ )
379
+ )
380
+
381
+ producer = name or str(field.get("queId") or field_type)
382
+ for index, item in enumerate(binding.get("outputs") or []):
383
+ if not isinstance(item, dict):
384
+ continue
385
+ selector = item.get("targetField")
386
+ target_path = f"{path}/config/{binding_name}/outputs/{index}/targetField"
387
+ resolution, selected = resolve_local_selector(selector)
388
+ if resolution == "invalid":
389
+ errors.append((target_path, "targetField must resolve to exactly one top-level field"))
390
+ continue
391
+ if resolution != "resolved" or selected is None:
392
+ continue
393
+ selected_path, target_field = selected
394
+ target_name = str(target_field.get("name") or target_field.get("queId") or "")
395
+ target_type = _field_type(target_field)
396
+ if target_type and target_type not in _INTEGRATION_OUTPUT_TARGET_FIELD_TYPES:
397
+ allowed = ", ".join(sorted(_INTEGRATION_OUTPUT_TARGET_FIELD_TYPES))
398
+ errors.append(
399
+ (
400
+ target_path,
401
+ f"output target field '{target_name}' uses unsupported questionType '{target_type}'; allowed types: {allowed}",
402
+ )
403
+ )
404
+ previous = output_targets.get(selected_path)
405
+ if previous is None:
406
+ output_targets[selected_path] = (producer, target_path)
407
+ continue
408
+ previous_producer, previous_path = previous
409
+ errors.append(
410
+ (
411
+ target_path,
412
+ f"field '{target_name}' is already targeted by output from '{previous_producer}' at {previous_path}; "
413
+ "each field can receive output from only one Q-Linker or code block relation",
414
+ )
415
+ )
416
+ return errors
417
+
418
+
419
+ def validate_declaration(
420
+ payload: dict[str, Any],
421
+ *,
422
+ schema_version: str | None = None,
423
+ schema_call: Any = _local_schema_call,
424
+ ) -> dict[str, Any]:
425
+ """Validate a complete AppForm declaration without network or write calls."""
426
+ summary = schema_call(schema_version, None)
427
+ if not isinstance(summary, dict) or summary.get("status") != "success" or not isinstance(summary.get("schema"), dict):
428
+ raise RuntimeError(f"AppForm Schema query failed: {json.dumps(summary, ensure_ascii=False)}")
429
+ pinned = str(summary.get("schemaVersion") or "")
430
+ api_version = str(summary.get("apiVersion") or "")
431
+ if schema_version and pinned != schema_version:
432
+ raise ValueError(f"/: requested schemaVersion {schema_version!r} resolved to {pinned!r}")
433
+ try:
434
+ declaration, _warnings = normalize_app_form_declaration(payload)
435
+ except AppFormContractError as error:
436
+ raise AppFormValidationError(
437
+ [{"pointer": error.path or "/", "message": error.message}],
438
+ schema_version=pinned,
439
+ api_version=api_version,
440
+ ) from error
441
+ if declaration.get("apiVersion") != api_version:
442
+ raise ValueError(f"/apiVersion: expected {api_version!r} for schemaVersion {pinned!r}")
443
+ supported_formula_functions = _supported_formula_functions(pinned)
444
+ types = _field_types(declaration)
445
+ details = [schema_call(pinned, field_type) for field_type in (types or ("text",))]
446
+ for detail in details:
447
+ if not isinstance(detail, dict) or detail.get("status") != "success" or detail.get("schemaVersion") != pinned or detail.get("apiVersion") != api_version:
448
+ raise RuntimeError("/: AppForm Schema responses mixed versions")
449
+ schema = _compose(summary, details)
450
+ Draft202012Validator.check_schema(schema)
451
+ validator = Draft202012Validator(schema, format_checker=FormatChecker())
452
+ found: dict[tuple[str, str], None] = {}
453
+ for error in compact_schema_errors(validator.iter_errors(declaration), schema):
454
+ found[(_pointer(error.absolute_path), f"{error.validator}: {schema_error_message(error)}")] = None
455
+ for pointer, message in _static_errors(declaration):
456
+ found[(pointer, message)] = None
457
+ for pointer, message in _formula_errors(declaration, supported_formula_functions):
458
+ found[(pointer, message)] = None
459
+ if found:
460
+ issues = [{"pointer": pointer, "message": message} for pointer, message in sorted(found)]
461
+ raise AppFormValidationError(issues, schema_version=pinned, api_version=api_version)
462
+ return {"valid": True, "schemaVersion": pinned, "apiVersion": api_version, "fieldTypes": list(types)}