base-screen 0.3.0 → 0.4.0

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 (210) hide show
  1. package/dist/_internal/contracts/document/schema.d.ts +7 -0
  2. package/dist/_internal/contracts/document/schema.js +1 -1
  3. package/dist/_internal/contracts/document/validate-value-ref.js +6 -1
  4. package/dist/_internal/contracts/screen-document.schema.json +15 -3
  5. package/dist/_internal/contracts/types/diagnostics.d.ts +1 -1
  6. package/dist/_internal/contracts/types/document.d.ts +3 -1
  7. package/dist/_internal/core/blueprint/runtime-simulate.d.ts +57 -0
  8. package/dist/_internal/core/blueprint/runtime-simulate.js +177 -0
  9. package/dist/_internal/core/blueprint/runtime.d.ts +1 -0
  10. package/dist/_internal/core/blueprint/runtime.js +1 -0
  11. package/dist/_internal/core/commands/apply-collection-commands.d.ts +32 -0
  12. package/dist/_internal/core/commands/apply-collection-commands.js +174 -0
  13. package/dist/_internal/core/commands/apply.js +13 -0
  14. package/dist/_internal/core/commands/parse-command.js +12 -0
  15. package/dist/_internal/core/commands/types.d.ts +29 -1
  16. package/dist/_internal/core/data/data-candidates.d.ts +38 -0
  17. package/dist/_internal/core/data/data-candidates.js +186 -0
  18. package/dist/_internal/core/data/dataset-profile.d.ts +71 -0
  19. package/dist/_internal/core/data/dataset-profile.js +170 -0
  20. package/dist/_internal/core/data/sample-values.d.ts +25 -0
  21. package/dist/_internal/core/data/sample-values.js +45 -0
  22. package/dist/_internal/core/diff/screen-diff.js +6 -0
  23. package/dist/_internal/core/index.d.ts +7 -1
  24. package/dist/_internal/core/index.js +7 -1
  25. package/dist/_internal/core/state/state-preset.d.ts +32 -0
  26. package/dist/_internal/core/state/state-preset.js +37 -0
  27. package/dist/_internal/core/validation/layout-audit.d.ts +17 -0
  28. package/dist/_internal/core/validation/layout-audit.js +228 -0
  29. package/dist/_internal/core/validation/legibility.d.ts +9 -0
  30. package/dist/_internal/core/validation/legibility.js +33 -0
  31. package/dist/_internal/engine/browser/controllers/dataset/designer-dataset-draft-controller.d.ts +6 -1
  32. package/dist/_internal/engine/browser/controllers/designer-change-controller.d.ts +27 -0
  33. package/dist/_internal/engine/browser/dom/change/designer-change-dom.d.ts +21 -5
  34. package/dist/_internal/engine/browser/dom/dataset/designer-data-section-diff.d.ts +4 -6
  35. package/dist/_internal/engine/browser/dom/value-ref/designer-value-ref-types.d.ts +2 -0
  36. package/dist/_internal/engine/browser/viewport/designer-canvas-aids-types.d.ts +3 -3
  37. package/dist/_internal/engine/browser/viewport/designer-canvas-aids.d.ts +5 -3
  38. package/dist/_internal/engine/browser/viewport/designer-canvas-measurements.d.ts +2 -14
  39. package/dist/_internal/engine/browser/viewport/designer-guide-overlay-nodes.d.ts +2 -0
  40. package/dist/_internal/engine/browser/viewport/designer-snap-tuning.d.ts +14 -0
  41. package/dist/_internal/engine/common/operations/change/designer-change-events.d.ts +2 -0
  42. package/dist/_internal/engine/common/operations/change/designer-change-proposal.d.ts +35 -2
  43. package/dist/_internal/engine/common/operations/display/designer-target-display.d.ts +2 -2
  44. package/dist/_internal/engine/common/operations/style/designer-component-states.d.ts +7 -2
  45. package/dist/_internal/engine/common/ui-text/designer-ui-text.d.ts +42 -2
  46. package/dist/_internal/engine/{designer-blueprint-workbench-panel-CJ3iZo5v.js → designer-blueprint-workbench-panel-BWSglfAb.js} +210 -290
  47. package/dist/_internal/engine/{designer-dataset-controller-CrfOg2Ys.js → designer-dataset-controller-DdbY4ILC.js} +619 -561
  48. package/dist/_internal/engine/designer-element/api/designer-element-change.d.ts +24 -0
  49. package/dist/_internal/engine/designer-element/base-screen-designer-element.d.ts +12 -0
  50. package/dist/_internal/engine/designer-element/designer-element-public-api.d.ts +2 -1
  51. package/dist/_internal/engine/designer-element/runtime/designer-element-rendering.d.ts +1 -1
  52. package/dist/_internal/engine/designer-element/runtime/designer-element-runtime.d.ts +4 -1
  53. package/dist/_internal/engine/designer-element/runtime/designer-element-sample-data.d.ts +23 -0
  54. package/dist/_internal/engine/{designer-field-primitives-KBZuWN_D.js → designer-field-primitives-Crn464Qg.js} +44 -3
  55. package/dist/_internal/engine/{designer-left-panel-groups-dom-N2OHOWjl.js → designer-left-panel-groups-dom-DFdLWxxY.js} +2 -2
  56. package/dist/_internal/engine/{host-resource-selection-xo2mLCD4.js → host-resource-selection-CWrPLVOc.js} +2 -2
  57. package/dist/_internal/engine/index.js +4742 -4360
  58. package/dist/_internal/host-kit/index.d.ts +1 -0
  59. package/dist/_internal/host-kit/index.js +1 -0
  60. package/dist/_internal/host-kit/intent/index.d.ts +16 -0
  61. package/dist/_internal/host-kit/intent/index.js +13 -0
  62. package/dist/_internal/host-kit/intent/intent-behavior.d.ts +59 -0
  63. package/dist/_internal/host-kit/intent/intent-behavior.js +812 -0
  64. package/dist/_internal/host-kit/intent/intent-block.d.ts +59 -0
  65. package/dist/_internal/host-kit/intent/intent-block.js +359 -0
  66. package/dist/_internal/host-kit/intent/intent-catalog.d.ts +105 -0
  67. package/dist/_internal/host-kit/intent/intent-catalog.js +60 -0
  68. package/dist/_internal/host-kit/intent/intent-compile-types.d.ts +222 -0
  69. package/dist/_internal/host-kit/intent/intent-compile-types.js +10 -0
  70. package/dist/_internal/host-kit/intent/intent-compile.d.ts +35 -0
  71. package/dist/_internal/host-kit/intent/intent-compile.js +465 -0
  72. package/dist/_internal/host-kit/intent/intent-data-check.d.ts +50 -0
  73. package/dist/_internal/host-kit/intent/intent-data-check.js +163 -0
  74. package/dist/_internal/host-kit/intent/intent-data-context.d.ts +53 -0
  75. package/dist/_internal/host-kit/intent/intent-data-context.js +200 -0
  76. package/dist/_internal/host-kit/intent/intent-dataset.d.ts +52 -0
  77. package/dist/_internal/host-kit/intent/intent-dataset.js +125 -0
  78. package/dist/_internal/host-kit/intent/intent-format.d.ts +33 -0
  79. package/dist/_internal/host-kit/intent/intent-format.js +94 -0
  80. package/dist/_internal/host-kit/intent/intent-kpi-bind.d.ts +29 -0
  81. package/dist/_internal/host-kit/intent/intent-kpi-bind.js +59 -0
  82. package/dist/_internal/host-kit/intent/intent-layout.d.ts +102 -0
  83. package/dist/_internal/host-kit/intent/intent-layout.js +264 -0
  84. package/dist/_internal/host-kit/intent/intent-parse.d.ts +39 -0
  85. package/dist/_internal/host-kit/intent/intent-parse.js +930 -0
  86. package/dist/_internal/host-kit/intent/intent-prepare.d.ts +52 -0
  87. package/dist/_internal/host-kit/intent/intent-prepare.js +104 -0
  88. package/dist/_internal/host-kit/intent/intent-session.d.ts +202 -0
  89. package/dist/_internal/host-kit/intent/intent-session.js +1001 -0
  90. package/dist/_internal/host-kit/intent/intent-stream.d.ts +28 -0
  91. package/dist/_internal/host-kit/intent/intent-stream.js +183 -0
  92. package/dist/_internal/host-kit/intent/intent-style.d.ts +37 -0
  93. package/dist/_internal/host-kit/intent/intent-style.js +77 -0
  94. package/dist/_internal/host-kit/intent/intent-types.d.ts +234 -0
  95. package/dist/_internal/host-kit/intent/intent-types.js +10 -0
  96. package/dist/_internal/material/chart.js +34 -12
  97. package/dist/_internal/material/table.js +52 -21
  98. package/dist/_internal/plugin-sdk/index.d.ts +6 -0
  99. package/dist/_internal/plugin-sdk/index.js +6 -0
  100. package/dist/_internal/plugin-sdk/material-isolated-csp.d.ts +38 -0
  101. package/dist/_internal/plugin-sdk/material-isolated-csp.js +67 -0
  102. package/dist/_internal/plugin-sdk/material-isolated-runtime.d.ts +22 -0
  103. package/dist/_internal/plugin-sdk/material-isolated-runtime.js +262 -0
  104. package/dist/_internal/plugin-sdk/material-isolated.d.ts +94 -0
  105. package/dist/_internal/plugin-sdk/material-isolated.js +1024 -0
  106. package/dist/_internal/plugin-sdk/material-rendered-element.d.ts +10 -2
  107. package/dist/_internal/plugin-sdk/material-rendered-element.js +71 -7
  108. package/dist/_internal/plugin-sdk/material-spec-audit.d.ts +2 -0
  109. package/dist/_internal/plugin-sdk/material-spec-audit.js +26 -6
  110. package/dist/_internal/plugin-sdk/material-spec.d.ts +20 -0
  111. package/dist/_internal/plugin-sdk/material-spec.js +78 -3
  112. package/dist/_internal/plugin-sdk/material-template-audit.d.ts +12 -0
  113. package/dist/_internal/plugin-sdk/material-template-audit.js +302 -0
  114. package/dist/_internal/plugin-sdk/material-template-expression.d.ts +98 -0
  115. package/dist/_internal/plugin-sdk/material-template-expression.js +549 -0
  116. package/dist/_internal/plugin-sdk/material-template-render.d.ts +32 -0
  117. package/dist/_internal/plugin-sdk/material-template-render.js +579 -0
  118. package/dist/_internal/plugin-sdk/material-template.d.ts +185 -0
  119. package/dist/_internal/plugin-sdk/material-template.js +879 -0
  120. package/dist/auto-register.js +10 -10
  121. package/dist/contracts.js +5 -5
  122. package/dist/contrast-DRPezUIl.js +131 -0
  123. package/dist/contrast-DRPezUIl.js.map +1 -0
  124. package/dist/core.js +156 -136
  125. package/dist/core.js.map +1 -1
  126. package/dist/dataset-profile-Dk6xdtsM.js +261 -0
  127. package/dist/dataset-profile-Dk6xdtsM.js.map +1 -0
  128. package/dist/{designer-3Tb0EIDV.js → designer-CFOvOmLn.js} +2 -2
  129. package/dist/{designer-3Tb0EIDV.js.map → designer-CFOvOmLn.js.map} +1 -1
  130. package/dist/designer-auto-register.js +5 -5
  131. package/dist/{designer-blueprint-workbench-panel-CJ3iZo5v-BebifP4x.js → designer-blueprint-workbench-panel-BWSglfAb-ktaj6Ci9.js} +452 -531
  132. package/dist/designer-blueprint-workbench-panel-BWSglfAb-ktaj6Ci9.js.map +1 -0
  133. package/dist/{designer-dataset-controller-CrfOg2Ys-DhKUEJJe.js → designer-dataset-controller-DdbY4ILC-CMdGdGbr.js} +862 -804
  134. package/dist/designer-dataset-controller-DdbY4ILC-CMdGdGbr.js.map +1 -0
  135. package/dist/{designer-field-primitives-KBZuWN_D-B3h4jpYe.js → designer-field-primitives-Crn464Qg-Bi7q8s5J.js} +45 -4
  136. package/dist/designer-field-primitives-Crn464Qg-Bi7q8s5J.js.map +1 -0
  137. package/dist/{designer-left-panel-groups-dom-N2OHOWjl-D8CzGwbF.js → designer-left-panel-groups-dom-DFdLWxxY-BarlWMLY.js} +4 -4
  138. package/dist/{designer-left-panel-groups-dom-N2OHOWjl-D8CzGwbF.js.map → designer-left-panel-groups-dom-DFdLWxxY-BarlWMLY.js.map} +1 -1
  139. package/dist/designer.js +5 -5
  140. package/dist/{dist-6GRboBs-.js → dist-B2bW2Tru.js} +4 -4
  141. package/dist/{dist-6GRboBs-.js.map → dist-B2bW2Tru.js.map} +1 -1
  142. package/dist/{dist-BjLjFUy1.js → dist-CHK9BTXX.js} +3833 -3453
  143. package/dist/dist-CHK9BTXX.js.map +1 -0
  144. package/dist/engine.js +5 -5
  145. package/dist/{fragment-Y6YnW6wy.js → fragment-B-oP0Fru.js} +3 -3
  146. package/dist/{fragment-Y6YnW6wy.js.map → fragment-B-oP0Fru.js.map} +1 -1
  147. package/dist/host-kit.js +3963 -187
  148. package/dist/host-kit.js.map +1 -1
  149. package/dist/{host-resource-selection-xo2mLCD4-BR5XCcim.js → host-resource-selection-CWrPLVOc-DPDq3jau.js} +5 -5
  150. package/dist/{host-resource-selection-xo2mLCD4-BR5XCcim.js.map → host-resource-selection-CWrPLVOc-DPDq3jau.js.map} +1 -1
  151. package/dist/index.js +10 -10
  152. package/dist/legibility-CS28ivEz.js +12 -0
  153. package/dist/legibility-CS28ivEz.js.map +1 -0
  154. package/dist/{level-scale-BzUjE31V.js → level-scale-CwHqFEVd.js} +2 -2
  155. package/dist/{level-scale-BzUjE31V.js.map → level-scale-CwHqFEVd.js.map} +1 -1
  156. package/dist/{manager-Ch0RTu_i.js → manager-CeB4Jnr9.js} +3 -3
  157. package/dist/{manager-Ch0RTu_i.js.map → manager-CeB4Jnr9.js.map} +1 -1
  158. package/dist/{material-UbSfiuZq.js → material-DeVkzSoT.js} +2 -2
  159. package/dist/{material-UbSfiuZq.js.map → material-DeVkzSoT.js.map} +1 -1
  160. package/dist/material-auto-register.js +1 -1
  161. package/dist/material.js +2 -2
  162. package/dist/{migrate-document-D3HhCVlZ.js → migrate-document-BM888PtC.js} +2 -2
  163. package/dist/{migrate-document-D3HhCVlZ.js.map → migrate-document-BM888PtC.js.map} +1 -1
  164. package/dist/{parse-AOTE9WnD.js → parse-Ji7kE9ZT.js} +9 -4
  165. package/dist/parse-Ji7kE9ZT.js.map +1 -0
  166. package/dist/{parse-B1OD1teS.js → parse-aZat9tAS.js} +3 -3
  167. package/dist/{parse-B1OD1teS.js.map → parse-aZat9tAS.js.map} +1 -1
  168. package/dist/{parse-parts-BNrpdG5o.js → parse-parts-qzl4suzk.js} +2 -2
  169. package/dist/{parse-parts-BNrpdG5o.js.map → parse-parts-qzl4suzk.js.map} +1 -1
  170. package/dist/{plugin-DHgh9uHh.js → plugin-CstHQ5ws.js} +4 -4
  171. package/dist/{plugin-DHgh9uHh.js.map → plugin-CstHQ5ws.js.map} +1 -1
  172. package/dist/plugin-core.js +2 -2
  173. package/dist/plugin-manager.js +1 -1
  174. package/dist/plugin-package-DWifuHi1.js +4206 -0
  175. package/dist/plugin-package-DWifuHi1.js.map +1 -0
  176. package/dist/{plugin-registration-rsmb4GvS.js → plugin-registration-DTwBvnHX.js} +2 -2
  177. package/dist/{plugin-registration-rsmb4GvS.js.map → plugin-registration-DTwBvnHX.js.map} +1 -1
  178. package/dist/plugin-sdk.js +6 -6
  179. package/dist/{plugins-DGRHgREK.js → plugins-QDL0yIql.js} +2 -2
  180. package/dist/{plugins-DGRHgREK.js.map → plugins-QDL0yIql.js.map} +1 -1
  181. package/dist/plugins.js +8 -8
  182. package/dist/renderer.js +1 -1
  183. package/dist/{runtime-dispatch-BfnRDtMe.js → runtime-dispatch-C0gyIrTv.js} +2 -2
  184. package/dist/{runtime-dispatch-BfnRDtMe.js.map → runtime-dispatch-C0gyIrTv.js.map} +1 -1
  185. package/dist/runtime-simulate-aSYO9yDX.js +147 -0
  186. package/dist/runtime-simulate-aSYO9yDX.js.map +1 -0
  187. package/dist/{src-Bm7u11mN-_0u6cMEw.js → src-Bm7u11mN-Bi1hDVkh.js} +39 -39
  188. package/dist/{src-Bm7u11mN-_0u6cMEw.js.map → src-Bm7u11mN-Bi1hDVkh.js.map} +1 -1
  189. package/dist/state-preset-DtpygJOH.js +22 -0
  190. package/dist/state-preset-DtpygJOH.js.map +1 -0
  191. package/dist/{text-BNksUr5J.js → text-BSTz0pFQ.js} +87 -34
  192. package/dist/text-BSTz0pFQ.js.map +1 -0
  193. package/dist/{value-ref-BG_MV9C-.js → value-ref-XkLuckGV.js} +2 -2
  194. package/dist/{value-ref-BG_MV9C-.js.map → value-ref-XkLuckGV.js.map} +1 -1
  195. package/dist/{viewer-CrJupI8I-D9dVcNw4.js → viewer-CrJupI8I-BJiz1cvW.js} +4 -4
  196. package/dist/{viewer-CrJupI8I-D9dVcNw4.js.map → viewer-CrJupI8I-BJiz1cvW.js.map} +1 -1
  197. package/dist/viewer-auto-register.js +2 -2
  198. package/dist/viewer.js +2 -2
  199. package/dist/{viewport-CiCKeAQH.js → viewport-BNIRWjiT.js} +354 -155
  200. package/dist/viewport-BNIRWjiT.js.map +1 -0
  201. package/package.json +12 -12
  202. package/dist/designer-blueprint-workbench-panel-CJ3iZo5v-BebifP4x.js.map +0 -1
  203. package/dist/designer-dataset-controller-CrfOg2Ys-DhKUEJJe.js.map +0 -1
  204. package/dist/designer-field-primitives-KBZuWN_D-B3h4jpYe.js.map +0 -1
  205. package/dist/dist-BjLjFUy1.js.map +0 -1
  206. package/dist/parse-AOTE9WnD.js.map +0 -1
  207. package/dist/plugin-package-Dr5ro6h6.js +0 -1221
  208. package/dist/plugin-package-Dr5ro6h6.js.map +0 -1
  209. package/dist/text-BNksUr5J.js.map +0 -1
  210. package/dist/viewport-CiCKeAQH.js.map +0 -1
@@ -0,0 +1,465 @@
1
+ import { resolveScreenFontFloorPx } from '@base-screen/core';
2
+ import { compileIntentBehaviors, seedFilterTargets } from './intent-behavior.js';
3
+ import { compileBlock, tokenStyle } from './intent-block.js';
4
+ import { pickShellMaterial, pickSurfaceMaterial, pickTextMaterial, } from './intent-catalog.js';
5
+ import { deltaColor, detectIntentLanguage, formatKpiDelta, formatKpiValue, } from './intent-format.js';
6
+ import { drawBoundKpi } from './intent-kpi-bind.js';
7
+ import { FOOTER_HEIGHT, FOOTER_Y, HEIGHT, MARGIN, SUBTITLE_HEIGHT, SUBTITLE_Y, solveLayout, TITLE_HEIGHT, TITLE_Y, WIDTH, } from './intent-layout.js';
8
+ import { resolveIntentStyle } from './intent-style.js';
9
+ /** 最多 5 张指标卡(平铺写法);区域写法的上限由求解器的最小卡宽决定。 */
10
+ const FLAT_MAX_KPIS = 5;
11
+ /** 指标卡内的排版相对卡片左上角。 */
12
+ const KPI_CARD_PADDING = 20;
13
+ /**
14
+ * 目录驱动编译:模型挑组件与数据,编译器负责把它变成合法文档。
15
+ *
16
+ * 1. type 一律来自 `catalog.materials`,目录里没有的 type 只丢该块(降级告警,不整份失败);
17
+ * 2. 样式起点是物料 manifest 的 `defaultStyle`,只叠加一层设计令牌(字号 / 字重 / 文字色),
18
+ * 且仅在物料声明过该键时才写,避免把不支持的样式塞给渲染器;
19
+ * 3. 数据按物料声明的 `staticData.kind` 编——表格写 `dataValue: inline` + `dataBinding`,
20
+ * 素材写 `dataSources` 实例 + `data-source-field` 引用,文档里只留资源身份;
21
+ * 4. 几何由布局求解器(`solveLayout`)按区域序列一次算定,装不下返回 `LAYOUT_CAPACITY_EXCEEDED`。
22
+ */
23
+ export function compileScreenIntent(input) {
24
+ const { catalog, references, stream } = input;
25
+ // 流式帧只排版面;联动与状态在最终编译时一次编出(它们要指向编好的组件)。
26
+ const seeded = stream === undefined ? seedFilterTargets(input.intent, references) : undefined;
27
+ const intent = seeded?.intent ?? input.intent;
28
+ const palette = resolveIntentStyle(intent.style).palette;
29
+ const language = detectIntentLanguage(intent.title, intent.subtitle);
30
+ const sink = {
31
+ diagnostics: [],
32
+ warnings: [...(seeded?.warnings ?? [])],
33
+ dataSources: [],
34
+ };
35
+ const regions = stream === undefined ? regionsOf(intent) : regionsOfSkeleton(stream);
36
+ const solved = solveLayout(regions.map((region) => region.layout));
37
+ if (!solved.ok) {
38
+ return {
39
+ ok: false,
40
+ diagnostics: solved.issues.map((issue) => capacityDiagnostic(issue, regions)),
41
+ };
42
+ }
43
+ const components = [];
44
+ // 来源表(ADR-0112 §2.1):组件 id → IR 路径。修复回环靠它把文档诊断翻译回模型能看懂的位置。
45
+ const sources = {};
46
+ // `scope` 决定 id 与层级(按「属于 IR 的哪一处 + 在该处的第几个」),`origin` 才是写进来源表的路径:
47
+ // 丢弃坏项后下标会前移,id 仍按位置分段(流式帧之间不漂移,ADR-0112 §2.5),来源表指回模型原文。
48
+ let scope = '';
49
+ let origin = '';
50
+ const at = (path, from = path) => {
51
+ scope = path;
52
+ origin = from;
53
+ };
54
+ const used = new Set();
55
+ // 每个来源各自计数:流式落稿时某一处先到、后到,都不会让别处组件的 id 或层级漂移。
56
+ const counters = new Map();
57
+ let imageCount = 0;
58
+ const textMaterial = pickTextMaterial(catalog);
59
+ const surfaceMaterial = pickSurfaceMaterial(catalog);
60
+ const shellMaterial = pickShellMaterial(catalog);
61
+ // 当前打开的外壳:其后落的组件以它为父级(组合,ADR-0113 §2.4)。
62
+ let shellId = null;
63
+ // 需要外壳却没有可用外壳:平铺,并在产物里如实说明。
64
+ let flattened = false;
65
+ const push = (material, name, box, extra = {}) => {
66
+ const pending = extra.pending === true;
67
+ const where = scopeOf(scope);
68
+ const local = pending ? where.pendingOffset : (counters.get(scope) ?? 0);
69
+ if (!pending)
70
+ counters.set(scope, local + 1);
71
+ const id = pending ? `agent-${where.key}-pending` : `agent-${where.key}-${local}`;
72
+ sources[id] = origin;
73
+ components.push({
74
+ id,
75
+ type: material.type,
76
+ name,
77
+ parentId: extra.parentId === undefined ? shellId : extra.parentId,
78
+ position: { x: Math.round(box.x), y: Math.round(box.y) },
79
+ size: {
80
+ width: Math.max(1, Math.round(box.width)),
81
+ height: Math.max(1, Math.round(box.height)),
82
+ },
83
+ rotation: 0,
84
+ zIndex: where.layer + local,
85
+ status: { locked: false, hidden: false },
86
+ props: { ...material.defaults.props, ...extra.props },
87
+ style: legibleStyle({ ...material.defaults.style, ...extra.style }),
88
+ dataSource: null,
89
+ dataValue: extra.dataValue ?? null,
90
+ ...(extra.dataBinding === undefined ? {} : { dataBinding: extra.dataBinding }),
91
+ });
92
+ used.add(material.type);
93
+ return id;
94
+ };
95
+ /**
96
+ * 外壳:目录里的容器物料(默认样式,透明无边框),框住它所属的一组组件。
97
+ * 卡片的外观(底板、圆角)仍由里面的底板组件承担,外壳只是「整体」的把手。
98
+ */
99
+ const beginShell = (name, box) => {
100
+ if (shellMaterial === undefined) {
101
+ flattened = true;
102
+ return;
103
+ }
104
+ shellId = push(shellMaterial, name, box, { parentId: null });
105
+ };
106
+ const endShell = () => {
107
+ shellId = null;
108
+ };
109
+ const pushText = (name, value, box, token = {}, sample = false) => {
110
+ if (textMaterial === undefined || value === '')
111
+ return;
112
+ // 未指定颜色的文字用预设主文字色;否则会落回目录物料的写死默认值,整屏文字色就不随风格变了。
113
+ push(textMaterial, name, box, {
114
+ style: tokenStyle(textMaterial, { color: palette.text, ...token }),
115
+ dataValue: sample ? { kind: 'inline', value, sample: true } : { kind: 'inline', value },
116
+ });
117
+ };
118
+ /**
119
+ * 卡片底板:只给指标卡这类需要视觉承载的块用。
120
+ *
121
+ * 画布背景不铺组件——`canvas.backgroundColor` / `backgroundImage` 本身就是 canonical 配置
122
+ * (设计器「画布 › 背景填充 / 背景图片」直接改它),再铺一块 1920×1080 的矩形等于同一件事
123
+ * 做两遍:多一个挡在最底层、容易误选的假组件,导出体积也白涨。
124
+ */
125
+ const pushSurface = (name, box, style, pending = false) => {
126
+ if (surfaceMaterial === undefined)
127
+ return;
128
+ // 卡片底色来自预设;目录物料的默认填充只是兜底的占位,不能盖过风格。
129
+ push(surfaceMaterial, name, box, {
130
+ style: { fill: palette.card, ...(style ?? {}) },
131
+ ...(pending ? { pending: true } : {}),
132
+ });
133
+ };
134
+ at('title');
135
+ pushText('标题', intent.title, { x: MARGIN, y: TITLE_Y, width: 1200, height: TITLE_HEIGHT }, { fontSize: 46, fontWeight: '700' });
136
+ at('subtitle');
137
+ pushText('副标题', intent.subtitle, { x: MARGIN, y: SUBTITLE_Y, width: 1400, height: SUBTITLE_HEIGHT }, { fontSize: 20, color: palette.muted });
138
+ const cardStyle = tintedSurfaceStyle(palette.card);
139
+ const blockContext = {
140
+ catalog,
141
+ textMaterial,
142
+ push,
143
+ pushText,
144
+ references,
145
+ palette,
146
+ beginShell,
147
+ endShell,
148
+ };
149
+ const blockTarget = { sink, onAsset: () => (imageCount += 1) };
150
+ const drawBlock = (slot, box) => {
151
+ at(slot.path, slot.block?.origin ?? slot.path);
152
+ // 流式落稿时这一格还没到:画占位框,内容到了换成真内容。
153
+ if (slot.block === undefined)
154
+ pushSurface('占位', box, cardStyle, true);
155
+ else
156
+ compileBlock(slot.block, box, blockContext, blockTarget);
157
+ };
158
+ for (const [index, region] of regions.entries()) {
159
+ const placed = solved.regions[index];
160
+ if (region.kind === 'band' && placed.kind === 'band') {
161
+ region.kpis.forEach((slot, slotIndex) => {
162
+ const box = placed.boxes[slotIndex];
163
+ at(slot.path, slot.kpi?.origin ?? slot.path);
164
+ // 一张指标卡 = 一个外壳 + 底板 + 文字:整体移动、复制、删除。
165
+ beginShell('指标卡', box);
166
+ pushSurface(shellMaterial === undefined ? '指标卡' : '底板', box, cardStyle);
167
+ // 流式落稿时这一项还没到:只画外壳与底板。数值到了在同一张卡上填字,外壳与底板的 id、层级不变。
168
+ if (slot.kpi !== undefined) {
169
+ const kpi = slot.kpi;
170
+ const x = box.x + KPI_CARD_PADDING;
171
+ const width = box.width - KPI_CARD_PADDING * 2;
172
+ const bound = kpi.bind !== undefined &&
173
+ drawBoundKpi(kpi, {
174
+ label: { x, y: box.y + 18, width, height: 26 },
175
+ value: { x, y: box.y + 50, width, height: 54 },
176
+ }, { textMaterial, references, sink, palette, language, push, pushText });
177
+ // 绑不上的指标卡画占位「—」(不改几何),原因已记进 warnings。
178
+ if (!bound)
179
+ drawKpi(kpi, box, palette, input.mode, language, pushText);
180
+ }
181
+ endShell();
182
+ });
183
+ }
184
+ else if (region.kind === 'grid' && placed.kind === 'grid') {
185
+ region.blocks.forEach((slot, slotIndex) => drawBlock(slot, placed.boxes[slotIndex]));
186
+ }
187
+ else if (region.kind === 'split' && placed.kind === 'split') {
188
+ region.main.forEach((slot, slotIndex) => drawBlock(slot, placed.main[slotIndex]));
189
+ region.rail.forEach((slot, slotIndex) => drawBlock(slot, placed.rail[slotIndex]));
190
+ }
191
+ }
192
+ const modeLabel = input.mode === 'llm'
193
+ ? language === 'en'
194
+ ? 'model output'
195
+ : '模型输出'
196
+ : input.mode === 'deterministic'
197
+ ? language === 'en'
198
+ ? 'deterministic fallback · model not called'
199
+ : '确定性兜底 · 未调用模型'
200
+ : '';
201
+ // 页脚是编译器自己的内容,不属于 IR 的任何位置。
202
+ at('');
203
+ pushText('页脚', language === 'en'
204
+ ? `Generated by the sample agent${modeLabel === '' ? '' : ` · ${modeLabel}`} · component catalog from the host designer (${catalog.materials.length} materials)`
205
+ : `生成自示例智能体${modeLabel === '' ? '' : ` · ${modeLabel}`} · 组件目录来自宿主设计器(${catalog.materials.length} 种可用物料)`, { x: MARGIN, y: FOOTER_Y, width: 1600, height: FOOTER_HEIGHT }, { fontSize: FONT_FLOOR_PX, color: palette.footer });
206
+ if (flattened) {
207
+ sink.warnings.push({
208
+ severity: 'warning',
209
+ code: 'INTENT_SHELL_UNAVAILABLE',
210
+ path: '',
211
+ message: 'The catalog has no material that can hold child components, so cards and blocks were laid out flat instead of as movable groups.',
212
+ });
213
+ }
214
+ if (sink.diagnostics.length > 0)
215
+ return { ok: false, diagnostics: sink.diagnostics };
216
+ const behaviors = stream === undefined
217
+ ? compileIntentBehaviors({
218
+ intent,
219
+ catalog,
220
+ references,
221
+ capabilities: input.capabilities,
222
+ language,
223
+ components,
224
+ dataSources: sink.dataSources,
225
+ sources,
226
+ warnings: sink.warnings,
227
+ })
228
+ : undefined;
229
+ if (components.length === 0) {
230
+ return {
231
+ ok: false,
232
+ diagnostics: [
233
+ {
234
+ severity: 'error',
235
+ code: 'AGENT_CATALOG_UNUSABLE',
236
+ path: 'catalog',
237
+ message: 'The catalog has no basic material to lay out with (text / surface / asset).',
238
+ },
239
+ ],
240
+ };
241
+ }
242
+ return {
243
+ ok: true,
244
+ value: {
245
+ imageCount,
246
+ materials: [...used],
247
+ warnings: sink.warnings,
248
+ sources,
249
+ behaviors: behaviors?.behaviors ?? [],
250
+ document: {
251
+ canvas: { width: WIDTH, height: HEIGHT, backgroundColor: palette.canvas },
252
+ components,
253
+ variables: behaviors?.variables ?? [],
254
+ ...(sink.dataSources.length === 0 ? {} : { dataSources: sink.dataSources }),
255
+ blueprint: behaviors?.blueprint ?? { nodes: [], edges: [] },
256
+ },
257
+ },
258
+ };
259
+ }
260
+ // ---------------------------------------------------------------------------
261
+ // 区域:意图 / 骨架 → 编译用区域
262
+ // ---------------------------------------------------------------------------
263
+ /** 平铺写法的区域沿用 `kpis` / `blocks` 路径;区域写法按位置记 `regions[i]`。 */
264
+ function regionPath(region, position) {
265
+ return region.origin === 'kpis' || region.origin === 'blocks'
266
+ ? region.origin
267
+ : `regions[${position}]`;
268
+ }
269
+ /** 格子的位置路径:决定组件 id 与层级。 */
270
+ function slotPath(path, part, index) {
271
+ if (path === 'kpis' || path === 'blocks')
272
+ return `${path}[${index}]`;
273
+ return `${path}.${part}[${index}]`;
274
+ }
275
+ const isData = (block) => block.bind.kind === 'table' || block.bind.kind === 'dataset';
276
+ function regionsOf(intent) {
277
+ return intent.regions.map((region, position) => {
278
+ const path = regionPath(region, position);
279
+ const slots = (items, part) => items.map((block, index) => ({ path: block.ident ?? slotPath(path, part, index), block }));
280
+ if (region.kind === 'band') {
281
+ const flat = path === 'kpis';
282
+ const items = flat ? region.items.slice(0, FLAT_MAX_KPIS) : region.items;
283
+ return {
284
+ kind: 'band',
285
+ path,
286
+ origin: region.origin,
287
+ layout: { kind: 'band', count: items.length },
288
+ kpis: items.map((kpi, index) => ({ path: kpi.ident ?? slotPath(path, 'items', index), kpi })),
289
+ };
290
+ }
291
+ if (region.kind === 'grid') {
292
+ return {
293
+ kind: 'grid',
294
+ path,
295
+ origin: region.origin,
296
+ layout: {
297
+ kind: 'grid',
298
+ slots: region.blocks.map((block) => ({ span: block.span, data: isData(block) })),
299
+ },
300
+ blocks: slots(region.blocks, 'blocks'),
301
+ };
302
+ }
303
+ return {
304
+ kind: 'split',
305
+ path,
306
+ origin: region.origin,
307
+ layout: {
308
+ kind: 'split',
309
+ ratio: region.ratio,
310
+ railSide: region.railSide,
311
+ main: region.main.map((block) => ({ data: isData(block) })),
312
+ rail: region.rail.map((block) => ({ data: isData(block) })),
313
+ },
314
+ main: slots(region.main, 'main'),
315
+ rail: slots(region.rail, 'rail'),
316
+ };
317
+ });
318
+ }
319
+ function regionsOfSkeleton(frame) {
320
+ const { skeleton } = frame;
321
+ return skeleton.regions.map((region, position) => {
322
+ const path = skeletonRegionPath(skeleton, region, position);
323
+ const slots = (count, part) => Array.from({ length: count }, (_, index) => {
324
+ const where = slotPath(path, part, index);
325
+ return { path: where, block: frame.blocks[where] };
326
+ });
327
+ if (region.kind === 'band') {
328
+ const count = skeleton.flat === true ? Math.min(region.count, FLAT_MAX_KPIS) : region.count;
329
+ return {
330
+ kind: 'band',
331
+ path,
332
+ origin: path,
333
+ layout: { kind: 'band', count },
334
+ kpis: Array.from({ length: count }, (_, index) => {
335
+ const where = slotPath(path, 'items', index);
336
+ return { path: where, kpi: frame.kpis[where] };
337
+ }),
338
+ };
339
+ }
340
+ if (region.kind === 'grid') {
341
+ return {
342
+ kind: 'grid',
343
+ path,
344
+ origin: path,
345
+ layout: { kind: 'grid', slots: region.slots },
346
+ blocks: slots(region.slots.length, 'blocks'),
347
+ };
348
+ }
349
+ return {
350
+ kind: 'split',
351
+ path,
352
+ origin: path,
353
+ layout: region,
354
+ main: slots(region.main.length, 'main'),
355
+ rail: slots(region.rail.length, 'rail'),
356
+ };
357
+ });
358
+ }
359
+ function skeletonRegionPath(skeleton, region, position) {
360
+ if (skeleton.flat === true)
361
+ return region.kind === 'band' ? 'kpis' : 'blocks';
362
+ return `regions[${position}]`;
363
+ }
364
+ function capacityDiagnostic(issue, regions) {
365
+ const region = regions[issue.regionIndex];
366
+ const path = region?.origin ?? '';
367
+ const message = issue.reason === 'width'
368
+ ? `The band needs ${issue.requiredPx}px to keep every card at least 240px wide, but only ${issue.availablePx}px is available; use fewer cards.`
369
+ : `The regions need ${issue.requiredPx}px of height but only ${issue.availablePx}px is available (short by ${issue.requiredPx - issue.availablePx}px); use fewer blocks.`;
370
+ return { severity: 'error', code: 'LAYOUT_CAPACITY_EXCEEDED', path, message };
371
+ }
372
+ // ---------------------------------------------------------------------------
373
+ // 指标卡
374
+ // ---------------------------------------------------------------------------
375
+ function drawKpi(kpi, box, palette, mode, language, pushText) {
376
+ const innerWidth = box.width - KPI_CARD_PADDING * 2;
377
+ const x = box.x + KPI_CARD_PADDING;
378
+ pushText('指标名', kpi.label, { x, y: box.y + 18, width: innerWidth, height: 26 }, { fontSize: 18, color: palette.muted });
379
+ // 模型给的指标值是示例数据;兜底的占位(value 为 null)不是数,不打标记。
380
+ pushText('指标值', formatKpiValue(kpi, language), { x, y: box.y + 50, width: innerWidth, height: 54 }, { fontSize: 42, fontWeight: '700', color: palette.text }, mode === 'llm' && kpi.value !== null);
381
+ if (kpi.delta !== undefined) {
382
+ pushText('同比', formatKpiDelta(kpi, language), { x, y: box.y + 108, width: innerWidth, height: 24 }, { fontSize: 16, color: deltaColor(kpi.delta, palette) });
383
+ }
384
+ }
385
+ /**
386
+ * 指标卡的高饱和品牌色降成浅淡的品牌底。
387
+ *
388
+ * 四张纯品牌蓝卡铺在深色画布上会把整屏的视觉重量全抢走;降透明度后保留色相,
389
+ * 又退回到「卡片」的层级。只对高饱和色生效:深灰底板、浅色卡片保持原样。
390
+ */
391
+ function tintedSurfaceStyle(fill) {
392
+ const channels = fill === undefined ? null : parseHexColor(fill);
393
+ if (channels === null)
394
+ return {};
395
+ const max = Math.max(...channels);
396
+ const min = Math.min(...channels);
397
+ if (max === 0)
398
+ return {};
399
+ const lightness = (max + min) / 510;
400
+ const saturation = (max - min) / (max + min === 0 ? 1 : 255 - Math.abs(max + min - 255));
401
+ if (saturation < 0.45 || lightness > 0.6)
402
+ return {};
403
+ return { opacity: 0.3 };
404
+ }
405
+ function parseHexColor(color) {
406
+ const match = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(color.trim());
407
+ if (match === null)
408
+ return null;
409
+ const hex = match[1];
410
+ const full = hex.length === 3 ? [...hex].map((char) => char + char).join('') : hex;
411
+ return [
412
+ Number.parseInt(full.slice(0, 2), 16),
413
+ Number.parseInt(full.slice(2, 4), 16),
414
+ Number.parseInt(full.slice(4, 6), 16),
415
+ ];
416
+ }
417
+ /** 画布宽度对应的可读字号下限(core `resolveScreenFontFloorPx`,1920 宽为 16px)。 */
418
+ const FONT_FLOOR_PX = resolveScreenFontFloorPx(WIDTH);
419
+ /**
420
+ * 字号兜底到可读下限(ADR-0112 §2.2):物料默认字号是「随手拖一个」的尺度(表格 13px),
421
+ * 编进 1920 宽的大屏就低于下限。模型不写样式,修复回环也修不了它,只能由编译器抬上来。
422
+ */
423
+ function legibleStyle(style) {
424
+ const size = style.fontSize;
425
+ return typeof size === 'number' && size < FONT_FLOOR_PX
426
+ ? { ...style, fontSize: FONT_FLOOR_PX }
427
+ : style;
428
+ }
429
+ const REGION_PART_KEY = { items: 'k', blocks: 'b', main: 'm', rail: 's' };
430
+ const REGION_PART_LAYER = { items: 0, blocks: 0, main: 0, rail: 64 };
431
+ /**
432
+ * 位置路径 → id 片段与层级区间:
433
+ * - 平铺写法:`kpis[1]` → `kpi-1`(层级 10+10i)、`blocks[2]` → `block-2`(层级 100+20i);
434
+ * - 区域写法:`regions[1].blocks[2]` → `r1-b2`,层级 100 + 140r 起,格内 8 层;
435
+ * - 标题 1、副标题 2、编译器自有内容(页脚)→ `footer`,层级 1000。
436
+ * 区间互不重叠于同一屏的可见内容,所以哪一处先到都不影响别处的层级。
437
+ */
438
+ function scopeOf(path) {
439
+ if (path === 'title')
440
+ return { key: 'title', layer: 1, pendingOffset: 19 };
441
+ if (path === 'subtitle')
442
+ return { key: 'subtitle', layer: 2, pendingOffset: 19 };
443
+ if (path === '')
444
+ return { key: 'footer', layer: 1000, pendingOffset: 19 };
445
+ const flat = /^(kpis|blocks)\[(\d+)\]$/.exec(path);
446
+ if (flat !== null) {
447
+ const index = Number(flat[2]);
448
+ return flat[1] === 'kpis'
449
+ ? { key: `kpi-${index}`, layer: 10 + index * 10, pendingOffset: 19 }
450
+ : { key: `block-${index}`, layer: 100 + index * 20, pendingOffset: 19 };
451
+ }
452
+ const region = /^regions\[(\d+)\]\.(items|blocks|main|rail)\[(\d+)\]$/.exec(path);
453
+ if (region !== null) {
454
+ const part = region[2];
455
+ const r = Number(region[1]);
456
+ const index = Number(region[3]);
457
+ return {
458
+ key: `r${r}-${REGION_PART_KEY[part]}${index}`,
459
+ layer: 100 + r * 140 + REGION_PART_LAYER[part] + index * 8,
460
+ pendingOffset: 7,
461
+ };
462
+ }
463
+ return { key: path, layer: 1000, pendingOffset: 19 };
464
+ }
465
+ //# sourceMappingURL=intent-compile.js.map
@@ -0,0 +1,50 @@
1
+ import type { ScreenAbortSignal, ScreenHostDatasetPort } from '../../contracts/index.js';
2
+ import type { IntentDataContext } from './intent-data-context.js';
3
+ import type { IntentRepairIssue } from './intent-prepare.js';
4
+ /**
5
+ * 采纳前的样例验证(ADR-0114 D6 / S5):提案挂出之前,对候选文档里每个数据集实例取一次数,
6
+ * 检查绑在它上面的组件能不能显示出东西。
7
+ *
8
+ * - 结果:`(datasetId, params)` 与画像取样相同的直接用画像样本,不同的(例如模型照用户说法换了产线)
9
+ * 查询一次,各实例并行,单次超时缺省 3 秒;
10
+ * - 检查:绑定字段不在结果里 `DATA_FIELD_ABSENT`;绑定字段在结果里全为空 `DATA_FIELD_ALL_NULL`;
11
+ * 指标卡的结果多于一行 `AGENT_KPI_MULTI_ROW`。诊断路径取来源表里的模型原文路径,交给修复回环(模型可以换候选);
12
+ * - 结果为空**不进修复**(ADR-0114 §8.7 选 B):可能只是用户指定的条件下暂时没有数据(例如某条产线 0 台设备),
13
+ * 请模型「换个参数」等于替用户改掉条件,违背 D5。记进 `empty`,提案理由说明「按当前条件暂无数据」;
14
+ * - 查询本身失败(宿主报错、超时)不是模型的错,不进修复:记进 `unverified`,提案理由如实说明。
15
+ *
16
+ * 只读:不改文档、不写数据源,也不缓存结果——采纳之后运行时照常按实例取数。
17
+ */
18
+ export interface IntentDataCheckInput {
19
+ /** 候选文档(`parseScreenDocument` 之后的,或编译产物):只读组件的取值引用与绑定、文档的数据源。 */
20
+ readonly document: {
21
+ readonly components: readonly {
22
+ readonly id: string;
23
+ readonly dataValue?: unknown;
24
+ readonly dataBinding?: unknown;
25
+ }[];
26
+ readonly dataSources?: readonly unknown[];
27
+ /** 文档变量:参数引用变量的实例按变量初值验证(联动推出的筛选变量,ADR-0115)。 */
28
+ readonly variables?: readonly unknown[];
29
+ };
30
+ /** 组件 id → 模型原文路径(编译产物的 `sources`)。 */
31
+ readonly sources: Readonly<Record<string, string>>;
32
+ readonly port: ScreenHostDatasetPort;
33
+ /** 本轮的数据上下文:有它时复用画像样本,省一次查询。 */
34
+ readonly context?: IntentDataContext;
35
+ readonly signal: ScreenAbortSignal;
36
+ /** 单次查询超时,缺省 3000ms。 */
37
+ readonly timeoutMs?: number;
38
+ }
39
+ export interface IntentDataCheckResult {
40
+ /** 值得请模型修的诊断(去重,按模型原文路径)。 */
41
+ readonly issues: readonly IntentRepairIssue[];
42
+ /** 验证过的数据源实例名称(含复用画像样本的)。 */
43
+ readonly verified: readonly string[];
44
+ /** 查询失败、没能验证的数据源实例名称。 */
45
+ readonly unverified: readonly string[];
46
+ /** 查询成功但按当前条件没有数据的实例名称(也计入 `verified`):不修复,只在理由里说明。 */
47
+ readonly empty: readonly string[];
48
+ }
49
+ export declare function validateIntentData(input: IntentDataCheckInput): Promise<IntentDataCheckResult>;
50
+ //# sourceMappingURL=intent-data-check.d.ts.map
@@ -0,0 +1,163 @@
1
+ import { intentDatasetQueryKey } from './intent-data-context.js';
2
+ /** 指标卡的模型原文路径:平铺写法 `kpis[i]`,区域写法 `regions[r].items[i]`。 */
3
+ const KPI_PATH = /^(?:kpis\[\d+\]|regions\[\d+\]\.items\[\d+\])$/;
4
+ export async function validateIntentData(input) {
5
+ const instances = datasetInstances(input.document.dataSources ?? [], initialValues(input.document.variables ?? []));
6
+ const bound = new Set();
7
+ for (const component of input.document.components) {
8
+ const source = dataSourceIdOf(component.dataValue);
9
+ if (source !== undefined)
10
+ bound.add(source);
11
+ }
12
+ const targets = instances.filter((instance) => bound.has(instance.id));
13
+ if (targets.length === 0)
14
+ return { issues: [], verified: [], unverified: [], empty: [] };
15
+ const results = new Map();
16
+ const verified = [];
17
+ const unverified = [];
18
+ const empty = [];
19
+ const settled = await Promise.all(targets.map(async (instance, index) => ({
20
+ instance,
21
+ result: await resultOf(instance, index, input),
22
+ })));
23
+ for (const { instance, result } of settled) {
24
+ if (result === undefined) {
25
+ unverified.push(instance.name);
26
+ }
27
+ else {
28
+ results.set(instance.id, result);
29
+ verified.push(instance.name);
30
+ if (result.rows.length === 0)
31
+ empty.push(instance.name);
32
+ }
33
+ }
34
+ const issues = [];
35
+ const seen = new Set();
36
+ const add = (code, path) => {
37
+ const key = `${code}@${path}`;
38
+ if (seen.has(key))
39
+ return;
40
+ seen.add(key);
41
+ issues.push({ code, path });
42
+ };
43
+ for (const component of input.document.components) {
44
+ const sourceId = dataSourceIdOf(component.dataValue);
45
+ const result = sourceId === undefined ? undefined : results.get(sourceId);
46
+ if (result === undefined)
47
+ continue;
48
+ const path = input.sources[component.id] ?? '';
49
+ const fields = boundFields(component.dataBinding);
50
+ // 没有行就无从判断字段:空结果只记在 `empty` 里,不怪模型。
51
+ if (result.rows.length === 0)
52
+ continue;
53
+ const known = new Set(result.fields.map((field) => field.id));
54
+ if (fields.some((field) => !known.has(field))) {
55
+ add('DATA_FIELD_ABSENT', path);
56
+ continue;
57
+ }
58
+ if (fields.some((field) => result.rows.every((row) => isBlank(row[field])))) {
59
+ add('DATA_FIELD_ALL_NULL', path);
60
+ }
61
+ if (KPI_PATH.test(path) && result.rows.length > 1)
62
+ add('AGENT_KPI_MULTI_ROW', path);
63
+ }
64
+ return { issues, verified, unverified, empty };
65
+ }
66
+ /** 画像样本能复用就复用;否则查询一次。失败、超时、取消都返回 undefined(记为未验证)。 */
67
+ async function resultOf(instance, index, input) {
68
+ const cached = input.context?.samples.get(intentDatasetQueryKey(instance.datasetId, instance.params));
69
+ if (cached !== undefined)
70
+ return cached;
71
+ const controller = new AbortController();
72
+ const abort = () => controller.abort();
73
+ if (input.signal.aborted)
74
+ return undefined;
75
+ input.signal.addEventListener('abort', abort, { once: true });
76
+ const timer = setTimeout(abort, input.timeoutMs ?? 3000);
77
+ try {
78
+ const queried = await input.port.query({
79
+ datasetId: instance.datasetId,
80
+ dataSourceId: `agent-check-${index + 1}`,
81
+ params: { ...instance.params },
82
+ }, { signal: controller.signal });
83
+ return queried.ok && !controller.signal.aborted ? queried.value : undefined;
84
+ }
85
+ catch {
86
+ return undefined;
87
+ }
88
+ finally {
89
+ clearTimeout(timer);
90
+ }
91
+ }
92
+ /** 静态变量的初值:引用它的实例采纳后第一次取数就用这个值。 */
93
+ function initialValues(variables) {
94
+ const output = new Map();
95
+ for (const raw of variables) {
96
+ const entry = asRecord(raw);
97
+ if (entry !== null && typeof entry.id === 'string' && entry.type === 'static') {
98
+ output.set(entry.id, entry.initialValue);
99
+ }
100
+ }
101
+ return output;
102
+ }
103
+ /**
104
+ * 文档里的数据集实例。参数是常量(`inline`)或引用静态变量(按初值)的才验证——
105
+ * 引用其他变量的实例取值要到运行时才定。
106
+ */
107
+ function datasetInstances(dataSources, variables) {
108
+ const output = [];
109
+ for (const raw of dataSources) {
110
+ const entry = asRecord(raw);
111
+ const source = asRecord(entry?.source);
112
+ if (entry === null || source === null || source.kind !== 'dataset')
113
+ continue;
114
+ if (typeof entry.id !== 'string' || typeof source.datasetId !== 'string')
115
+ continue;
116
+ const params = {};
117
+ let constant = true;
118
+ for (const [name, value] of Object.entries(asRecord(entry.params) ?? {})) {
119
+ const ref = asRecord(value);
120
+ const inline = ref?.kind === 'inline'
121
+ ? ref.value
122
+ : ref?.kind === 'variable' && typeof ref.variableId === 'string'
123
+ ? variables.get(ref.variableId)
124
+ : undefined;
125
+ if (typeof inline === 'string' || typeof inline === 'number' || typeof inline === 'boolean') {
126
+ params[name] = inline;
127
+ }
128
+ else {
129
+ constant = false;
130
+ }
131
+ }
132
+ if (!constant)
133
+ continue;
134
+ output.push({
135
+ id: entry.id,
136
+ name: typeof entry.name === 'string' && entry.name !== '' ? entry.name : source.datasetId,
137
+ datasetId: source.datasetId,
138
+ params,
139
+ });
140
+ }
141
+ return output;
142
+ }
143
+ function dataSourceIdOf(value) {
144
+ const ref = asRecord(value);
145
+ return ref?.kind === 'data-source-field' && typeof ref.dataSourceId === 'string'
146
+ ? ref.dataSourceId
147
+ : undefined;
148
+ }
149
+ function boundFields(binding) {
150
+ const fields = asRecord(asRecord(binding)?.fields);
151
+ if (fields === null)
152
+ return [];
153
+ return Object.values(fields).flatMap((ids) => Array.isArray(ids) ? ids.filter((id) => typeof id === 'string') : []);
154
+ }
155
+ function isBlank(value) {
156
+ return value === null || value === undefined || value === '';
157
+ }
158
+ function asRecord(value) {
159
+ return value !== null && typeof value === 'object' && !Array.isArray(value)
160
+ ? value
161
+ : null;
162
+ }
163
+ //# sourceMappingURL=intent-data-check.js.map