@webskill/sdk 0.4.0 → 0.5.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.
@@ -1,7 +1,7 @@
1
1
  import { m as WebSkillError } from "./dist-8oQRa8Xz.js";
2
2
  import { toJSONSchema, z } from "zod";
3
3
 
4
- //#region ../ui/dist/webskillCatalog-CpIg33vd.js
4
+ //#region ../ui/dist/webskillCatalog-B-IQxOKs.js
5
5
  /**
6
6
  * 最小子集 markdown → DOM:标题(#..###)、无序列表、代码块(```)、加粗、链接。
7
7
  * 全部内容经 textContent 写入,用户内容天然转义防 HTML 注入。
@@ -305,6 +305,7 @@ function validateNode(catalog, byName, node, path, issues) {
305
305
  return;
306
306
  }
307
307
  const allowed = def.children;
308
+ const singletons = /* @__PURE__ */ new Map();
308
309
  children.forEach((child, index) => {
309
310
  const childPath = `${path}.children[${index}]`;
310
311
  if (allowed !== "any" && isRecord$1(child) && typeof child["component"] === "string") {
@@ -316,6 +317,17 @@ function validateNode(catalog, byName, node, path, issues) {
316
317
  return;
317
318
  }
318
319
  }
320
+ if (isRecord$1(child) && typeof child["component"] === "string") {
321
+ const childName = child["component"];
322
+ if (byName.get(childName)?.singletonPerContainer === true) {
323
+ const seen = (singletons.get(childName) ?? 0) + 1;
324
+ singletons.set(childName, seen);
325
+ if (seen > 1) issues.push({
326
+ path: childPath,
327
+ message: `At most one "${childName}" per container; "${name}" already contains one`
328
+ });
329
+ }
330
+ }
319
331
  validateNode(catalog, byName, child, childPath, issues);
320
332
  });
321
333
  }
@@ -379,6 +391,7 @@ const DATA = [
379
391
  "Metric",
380
392
  "Table",
381
393
  "Chart",
394
+ "Timeline",
382
395
  "FileLink"
383
396
  ];
384
397
  const INPUT = [
@@ -386,6 +399,8 @@ const INPUT = [
386
399
  "Field",
387
400
  "Button"
388
401
  ];
402
+ /** Tabs 的面板与 Grid 的格子必须自成容器,否则「每容器至多一个表单」就没有落脚点 */
403
+ const PANEL = ["Card", "Stack"];
389
404
  /**
390
405
  * v3 首发 catalog:覆盖旧六类 surface(metric / chart / table / form / file / custom)的全部表达力,先窄后宽。
391
406
  * 只依赖 zod —— 不 import 任何 UI framework(21 号文档 §5.1)。
@@ -401,8 +416,13 @@ const uiCatalog = defineUiCatalog({
401
416
  "- Ask for user input with `Form` + `Field`; never describe an input in `Text`.",
402
417
  "- A `Button`'s `action` must be one of the catalog actions.",
403
418
  "- Never emit HTML, scripts or remote images.",
404
- "- Prefer `Table` for many rows, `Chart` for trends, `Metric` for a single number.",
405
- "- At most one `Form` per surface."
419
+ "- Prefer `Table` for many rows, `Chart` for trends, `Metric` for a single number,",
420
+ " `Timeline` for ordered steps and `Progress` for how far a long task has come.",
421
+ "- Match `Field.type` to the question instead of using `text` for everything:",
422
+ " `select` / `multi-select` for a fixed set of options, `date` for dates,",
423
+ " `toggle` for yes/no, `number` for quantities, `textarea` for several sentences.",
424
+ "- Group independent sections with `Tabs` or `Grid` instead of one long column.",
425
+ "- At most one `Form` per container; a `Tabs` panel and a `Grid` cell are separate containers."
406
426
  ].join("\n"),
407
427
  components: [
408
428
  {
@@ -464,6 +484,67 @@ const uiCatalog = defineUiCatalog({
464
484
  props: z.object({}),
465
485
  example: { component: "Separator" }
466
486
  },
487
+ {
488
+ name: "Tabs",
489
+ group: "layout",
490
+ description: "Switchable panels. Each child is one panel and its own form container.",
491
+ props: z.object({ labels: z.array(z.string()).min(2) }),
492
+ children: PANEL,
493
+ constraints: ["One child per label, in the same order"],
494
+ example: {
495
+ component: "Tabs",
496
+ props: { labels: ["Filters", "Export"] },
497
+ children: [{
498
+ component: "Stack",
499
+ children: [{
500
+ component: "Text",
501
+ props: { text: "Pick a date range." }
502
+ }]
503
+ }, {
504
+ component: "Stack",
505
+ children: [{
506
+ component: "Text",
507
+ props: { text: "Choose a file format." }
508
+ }]
509
+ }]
510
+ }
511
+ },
512
+ {
513
+ name: "Grid",
514
+ group: "layout",
515
+ description: "Dashboard grid. Each child is one cell and its own form container.",
516
+ props: z.object({ columns: z.union([
517
+ z.literal(2),
518
+ z.literal(3),
519
+ z.literal(4)
520
+ ]).default(2) }),
521
+ children: PANEL,
522
+ example: {
523
+ component: "Grid",
524
+ props: { columns: 2 },
525
+ children: [{
526
+ component: "Card",
527
+ props: { title: "Revenue" },
528
+ children: [{
529
+ component: "Metric",
530
+ props: {
531
+ label: "MRR",
532
+ value: "12,400"
533
+ }
534
+ }]
535
+ }, {
536
+ component: "Card",
537
+ props: { title: "Churn" },
538
+ children: [{
539
+ component: "Metric",
540
+ props: {
541
+ label: "Rate",
542
+ value: "2.1%"
543
+ }
544
+ }]
545
+ }]
546
+ }
547
+ },
467
548
  {
468
549
  name: "Heading",
469
550
  group: "content",
@@ -599,6 +680,33 @@ const uiCatalog = defineUiCatalog({
599
680
  }
600
681
  }
601
682
  },
683
+ {
684
+ name: "Timeline",
685
+ group: "data",
686
+ description: "Ordered steps or events, earliest first.",
687
+ props: z.object({ items: z.array(z.object({
688
+ title: z.string(),
689
+ time: z.string().optional(),
690
+ description: z.string().optional(),
691
+ state: z.enum([
692
+ "done",
693
+ "active",
694
+ "pending"
695
+ ]).default("pending")
696
+ })).min(1) }),
697
+ example: {
698
+ component: "Timeline",
699
+ props: { items: [{
700
+ title: "Plan",
701
+ time: "Mon",
702
+ state: "done"
703
+ }, {
704
+ title: "Build",
705
+ time: "Tue",
706
+ state: "active"
707
+ }] }
708
+ }
709
+ },
602
710
  {
603
711
  name: "FileLink",
604
712
  group: "data",
@@ -631,7 +739,8 @@ const uiCatalog = defineUiCatalog({
631
739
  cancelLabel: z.string().optional()
632
740
  }),
633
741
  children: ["Field"],
634
- constraints: ["At most one Form per surface", "Every Field name must be unique inside the Form"],
742
+ singletonPerContainer: true,
743
+ constraints: ["At most one Form per container", "Every Field name must be unique inside the Form"],
635
744
  example: {
636
745
  component: "Form",
637
746
  props: { title: "Schedule report" },
@@ -695,6 +804,27 @@ const uiCatalog = defineUiCatalog({
695
804
  }
696
805
  }
697
806
  },
807
+ {
808
+ name: "Progress",
809
+ group: "feedback",
810
+ description: "How far a long-running task has come, in percent.",
811
+ props: z.object({
812
+ label: z.string().optional(),
813
+ value: z.number().min(0).max(100),
814
+ tone: z.enum([
815
+ "neutral",
816
+ "success",
817
+ "warning"
818
+ ]).default("neutral")
819
+ }),
820
+ example: {
821
+ component: "Progress",
822
+ props: {
823
+ label: "Indexing",
824
+ value: 42
825
+ }
826
+ }
827
+ },
698
828
  {
699
829
  name: "Alert",
700
830
  group: "feedback",
@@ -763,6 +893,12 @@ const UI_CATALOG_GROUPS = {
763
893
  data: DATA,
764
894
  input: INPUT
765
895
  };
896
+ /**
897
+ * catalog 系统提示的体积上限(UTF-8 字节,FR-6.6)。
898
+ * 描述每次请求都要重发,所以上限必须是可判定的数字而不是「尽量精简」。
899
+ * 要改这个数字,先想清楚是否值得让每次请求都多付这些 token。
900
+ */
901
+ const UI_CATALOG_PROMPT_BUDGET_BYTES = 20480;
766
902
  /** A2UI 协议公共类型(与 @a2ui/web_core 的 common-types 同一套定义) */
767
903
  const A2UI_COMMON_TYPES = "https://a2ui.org/specification/v0_9/common_types.json";
768
904
  const CHILD_LIST_REF = `${A2UI_COMMON_TYPES}#/$defs/ChildList`;
@@ -896,6 +1032,7 @@ function interactionToFormModel(request) {
896
1032
  ...f.required ? { required: true } : {},
897
1033
  ...f.description ? { description: f.description } : {},
898
1034
  ...f.defaultValue !== void 0 ? { defaultValue: f.defaultValue } : {},
1035
+ ...f.suggestion ? { suggestion: f.suggestion } : {},
899
1036
  ...f.options ? { options: f.options } : {}
900
1037
  })),
901
1038
  submitLabel: "Submit",
@@ -971,6 +1108,27 @@ function collectValues(controls, container) {
971
1108
  };
972
1109
  }
973
1110
  /**
1111
+ * 采纳建议值(FR-5.9):把 `control.suggestion` 写进已渲染的控件。
1112
+ * 与 `collectValues` 共用同一套选择器与编码约定——两边分开实现的话,
1113
+ * select 的 JSON 编码值迟早会对不上。
1114
+ * @experimental
1115
+ */
1116
+ function applySuggestion(control, container) {
1117
+ if (control.suggestion === void 0) return;
1118
+ const el = container.querySelector(controlSelector(control.name));
1119
+ if (el === null) return;
1120
+ const { value } = control.suggestion;
1121
+ if (control.control === "boolean") {
1122
+ el.checked = value === true;
1123
+ return;
1124
+ }
1125
+ if (control.control === "select") {
1126
+ el.value = JSON.stringify(value);
1127
+ return;
1128
+ }
1129
+ el.value = value === void 0 || value === null ? "" : String(value);
1130
+ }
1131
+ /**
974
1132
  * 轻量 SVG 图表自绘(bar/line/pie,零依赖,三端复用单一来源)。
975
1133
  * 全部经 doc.createElementNS 构建(内容来自技能输出,不拼 innerHTML)。
976
1134
  */
@@ -1270,6 +1428,8 @@ const WEBSKILL_STYLES_CSS = `
1270
1428
  .webskill-form__error { font-size: 12px; color: #d33; display: none; }
1271
1429
  .webskill-form__control--invalid .webskill-form__error { display: block; }
1272
1430
  .webskill-form__input { padding: 6px 8px; border: 1px solid #bbb; border-radius: 4px; font-size: 14px; font-family: inherit; }
1431
+ .webskill-form__suggestion { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #666; }
1432
+ .webskill-form__suggestion-use { padding: 1px 8px; border-radius: 4px; border: 1px solid #bbb; background: #fff; cursor: pointer; font-size: 12px; }
1273
1433
  .webskill-form__actions { display: flex; gap: 8px; margin-top: 12px; }
1274
1434
  .webskill-form__button { padding: 6px 14px; border-radius: 4px; border: 1px solid #bbb; background: #fff; cursor: pointer; font-size: 14px; }
1275
1435
  .webskill-form__button--primary { background: #2563eb; border-color: #2563eb; color: #fff; }
@@ -1463,6 +1623,7 @@ var WebFormBridge = class {
1463
1623
  input.id = controlId;
1464
1624
  input.setAttribute("aria-describedby", errorId);
1465
1625
  wrapper.appendChild(input);
1626
+ if (control.suggestion !== void 0) wrapper.appendChild(this.#renderSuggestion(control, wrapper));
1466
1627
  const error = doc.createElement("div");
1467
1628
  error.className = "webskill-form__error";
1468
1629
  error.id = errorId;
@@ -1471,7 +1632,362 @@ var WebFormBridge = class {
1471
1632
  wrapper.appendChild(error);
1472
1633
  return wrapper;
1473
1634
  }
1635
+ /** 历史值以**建议**形态出现(FR-5.9):控件初始值仍为空,点「使用」才写入 */
1636
+ #renderSuggestion(control, container) {
1637
+ const doc = this.#doc;
1638
+ const row = doc.createElement("div");
1639
+ row.className = "webskill-form__suggestion";
1640
+ row.setAttribute("data-webskill-suggestion", control.name);
1641
+ const preview = doc.createElement("span");
1642
+ preview.className = "webskill-form__suggestion-value";
1643
+ preview.textContent = `Last entered: ${String(control.suggestion?.value)}`;
1644
+ row.appendChild(preview);
1645
+ const use = doc.createElement("button");
1646
+ use.type = "button";
1647
+ use.className = "webskill-form__suggestion-use";
1648
+ use.textContent = "Use";
1649
+ use.setAttribute("data-webskill-suggestion-use", control.name);
1650
+ use.addEventListener("click", () => applySuggestion(control, container));
1651
+ row.appendChild(use);
1652
+ return row;
1653
+ }
1474
1654
  };
1655
+ function fieldNamesOf(form) {
1656
+ const names = [];
1657
+ const walk = (node) => {
1658
+ const name = node.props?.["name"];
1659
+ if (node.component === "Field" && typeof name === "string") names.push(name);
1660
+ for (const child of node.children ?? []) walk(child);
1661
+ };
1662
+ walk(form);
1663
+ return names;
1664
+ }
1665
+ /**
1666
+ * 按出现序列出声明树里的每个 `Form`。
1667
+ *
1668
+ * 单表单时 action id 保持 `submit` / `cancel`,回传形状与容器级放宽前逐字节一致——
1669
+ * 向后兼容是 FR-6.3 的硬约束,不能让既有单表单卡片跟着改。
1670
+ * 多表单时每个表单拿到独立的 action id 与 `scopeId`,渲染层据此只收集本表单子树内的字段。
1671
+ */
1672
+ function collectFormScopes(spec) {
1673
+ const forms = [];
1674
+ const walk = (node) => {
1675
+ if (node.component === "Form") forms.push(node);
1676
+ for (const child of node.children ?? []) walk(child);
1677
+ };
1678
+ walk(spec);
1679
+ if (forms.length === 1) {
1680
+ const form = forms[0];
1681
+ return [{
1682
+ scopeId: form.id ?? "form",
1683
+ submitActionId: "submit",
1684
+ cancelActionId: "cancel",
1685
+ fieldNames: fieldNamesOf(form),
1686
+ form
1687
+ }];
1688
+ }
1689
+ return forms.map((form, index) => {
1690
+ const scopeId = form.id ?? `form-${index}`;
1691
+ return {
1692
+ scopeId,
1693
+ submitActionId: `${scopeId}:submit`,
1694
+ cancelActionId: `${scopeId}:cancel`,
1695
+ fieldNames: fieldNamesOf(form),
1696
+ form
1697
+ };
1698
+ });
1699
+ }
1700
+ /**
1701
+ * 多表单时字段值在渲染层的存储键。
1702
+ *
1703
+ * 跨表单重名过去不可能发生,容器级放宽后它变成合法输入:两个表单各有一个 `email`,
1704
+ * 共用一张扁平表就是后写的覆盖先写的,用户在 A 里输入会串到 B。
1705
+ * 因此多表单时按作用域限定键;单表单不加前缀,存储与草稿形状保持不变。
1706
+ */
1707
+ function qualifyFieldName(name, scopeId) {
1708
+ return scopeId === void 0 ? name : `${scopeId}.${name}`;
1709
+ }
1710
+ /**
1711
+ * 提交时回传的字段值。
1712
+ *
1713
+ * 不给 `scope` → 整张 surface 的扁平值,与容器级放宽前完全一致(FR-6.3 第 3 条)。
1714
+ * 给了 `scope` → 只取该表单子树内的字段,键回落成裸字段名,
1715
+ * 因此接收端看到的载荷形状与单表单时相同。
1716
+ */
1717
+ function collectScopedValues(values, scope) {
1718
+ if (!scope) return { ...values };
1719
+ const out = {};
1720
+ for (const name of scope.fieldNames) {
1721
+ const key = qualifyFieldName(name, scope.scopeId);
1722
+ if (key in values) out[name] = values[key];
1723
+ else if (name in values) out[name] = values[name];
1724
+ }
1725
+ return out;
1726
+ }
1727
+ /** 五类场景预设(FR-6.4)。@experimental */
1728
+ const UI_PRESETS = [
1729
+ {
1730
+ name: "charts",
1731
+ summary: "One question, one chart, with the takeaway spelled out above it.",
1732
+ guidance: [
1733
+ "Layout: `Card` → `Heading` (the takeaway, not \"Chart\") → `Chart` → optional `Text` for the caveat.",
1734
+ "Pick the chart type from the question: `line` / `area` for time, `bar` for comparison, `pie` for shares.",
1735
+ "Every series needs a name; labels and values must be the same length.",
1736
+ "Never repeat the same numbers in a `Table` right under the chart."
1737
+ ].join("\n"),
1738
+ example: {
1739
+ component: "Card",
1740
+ props: { title: "Revenue" },
1741
+ children: [
1742
+ {
1743
+ component: "Heading",
1744
+ props: {
1745
+ level: 3,
1746
+ text: "Revenue grew 27% in Q4"
1747
+ }
1748
+ },
1749
+ {
1750
+ component: "Chart",
1751
+ props: {
1752
+ type: "line",
1753
+ labels: [
1754
+ "Q1",
1755
+ "Q2",
1756
+ "Q3",
1757
+ "Q4"
1758
+ ],
1759
+ series: [{
1760
+ name: "Revenue",
1761
+ values: [
1762
+ 8,
1763
+ 9,
1764
+ 9.8,
1765
+ 12.4
1766
+ ]
1767
+ }]
1768
+ }
1769
+ },
1770
+ {
1771
+ component: "Text",
1772
+ props: {
1773
+ text: "Figures in millions, unaudited.",
1774
+ tone: "muted"
1775
+ }
1776
+ }
1777
+ ]
1778
+ }
1779
+ },
1780
+ {
1781
+ name: "cards",
1782
+ summary: "A short list of comparable items, one `Card` each.",
1783
+ guidance: [
1784
+ "Layout: `Grid` (2 or 3 columns) → one `Card` per item.",
1785
+ "Keep every card the same shape: title, one `Metric` or `Text`, at most one `Badge` for status.",
1786
+ "Use `Grid` rather than a vertical `Stack` as soon as there are three or more items.",
1787
+ "Put an action on a card only when the user can act on that single item."
1788
+ ].join("\n"),
1789
+ example: {
1790
+ component: "Grid",
1791
+ props: { columns: 2 },
1792
+ children: [{
1793
+ component: "Card",
1794
+ props: { title: "Checkout" },
1795
+ children: [{
1796
+ component: "Metric",
1797
+ props: {
1798
+ label: "Errors",
1799
+ value: 12,
1800
+ trend: "down"
1801
+ }
1802
+ }, {
1803
+ component: "Badge",
1804
+ props: {
1805
+ text: "healthy",
1806
+ tone: "success"
1807
+ }
1808
+ }]
1809
+ }, {
1810
+ component: "Card",
1811
+ props: { title: "Search" },
1812
+ children: [{
1813
+ component: "Metric",
1814
+ props: {
1815
+ label: "Errors",
1816
+ value: 143,
1817
+ trend: "up"
1818
+ }
1819
+ }, {
1820
+ component: "Badge",
1821
+ props: {
1822
+ text: "degraded",
1823
+ tone: "warning"
1824
+ }
1825
+ }]
1826
+ }]
1827
+ }
1828
+ },
1829
+ {
1830
+ name: "dashboards",
1831
+ summary: "Headline numbers first, then detail, optionally split across `Tabs`.",
1832
+ guidance: [
1833
+ "Layout: `Stack` → `Grid` of `Metric` cards → `Chart` or `Table` for the detail.",
1834
+ "Use `Tabs` when the detail splits into independent groups (filters, exports, alerts).",
1835
+ "Each `Tabs` panel and each `Grid` cell is its own form container: at most one `Form` inside.",
1836
+ "Show at most four headline metrics; anything more belongs in a `Table`."
1837
+ ].join("\n"),
1838
+ example: {
1839
+ component: "Stack",
1840
+ children: [{
1841
+ component: "Grid",
1842
+ props: { columns: 2 },
1843
+ children: [{
1844
+ component: "Card",
1845
+ props: { title: "MRR" },
1846
+ children: [{
1847
+ component: "Metric",
1848
+ props: {
1849
+ label: "This month",
1850
+ value: "12,400",
1851
+ trend: "up"
1852
+ }
1853
+ }]
1854
+ }, {
1855
+ component: "Card",
1856
+ props: { title: "Churn" },
1857
+ children: [{
1858
+ component: "Metric",
1859
+ props: {
1860
+ label: "This month",
1861
+ value: "2.1%",
1862
+ trend: "down"
1863
+ }
1864
+ }]
1865
+ }]
1866
+ }, {
1867
+ component: "Tabs",
1868
+ props: { labels: ["Trend", "Breakdown"] },
1869
+ children: [{
1870
+ component: "Stack",
1871
+ children: [{
1872
+ component: "Chart",
1873
+ props: {
1874
+ type: "bar",
1875
+ labels: ["Q3", "Q4"],
1876
+ series: [{
1877
+ name: "Revenue",
1878
+ values: [9800, 12400]
1879
+ }]
1880
+ }
1881
+ }]
1882
+ }, {
1883
+ component: "Stack",
1884
+ children: [{
1885
+ component: "Table",
1886
+ props: {
1887
+ columns: ["Region", "Revenue"],
1888
+ rows: [["EMEA", 5400], ["AMER", 7e3]]
1889
+ }
1890
+ }]
1891
+ }]
1892
+ }]
1893
+ }
1894
+ },
1895
+ {
1896
+ name: "slides",
1897
+ summary: "One idea per `Tabs` panel, headline plus at most three supporting lines.",
1898
+ guidance: [
1899
+ "Layout: `Tabs` → one `Stack` per slide, labelled with the slide title.",
1900
+ "Each slide: one `Heading` (level 2) stating the point, then a `Chart`, `Metric` or short `Markdown` list.",
1901
+ "Never put more than one idea on a slide; add a panel instead.",
1902
+ "No `Form` inside slides — a deck is for reading, not for input."
1903
+ ].join("\n"),
1904
+ example: {
1905
+ component: "Tabs",
1906
+ props: { labels: ["Where we are", "What we do next"] },
1907
+ children: [{
1908
+ component: "Stack",
1909
+ children: [{
1910
+ component: "Heading",
1911
+ props: {
1912
+ level: 2,
1913
+ text: "Revenue grew 27% in Q4"
1914
+ }
1915
+ }, {
1916
+ component: "Metric",
1917
+ props: {
1918
+ label: "Q4 revenue",
1919
+ value: "12,400",
1920
+ trend: "up"
1921
+ }
1922
+ }]
1923
+ }, {
1924
+ component: "Stack",
1925
+ children: [{
1926
+ component: "Heading",
1927
+ props: {
1928
+ level: 2,
1929
+ text: "Double down on EMEA"
1930
+ }
1931
+ }, {
1932
+ component: "Markdown",
1933
+ props: { text: "- hire two AEs\n- localise pricing" }
1934
+ }]
1935
+ }]
1936
+ }
1937
+ },
1938
+ {
1939
+ name: "reports",
1940
+ summary: "A long-form document: sections, tables and an optional `Timeline`.",
1941
+ guidance: [
1942
+ "Layout: `Stack` → `Heading` (level 2) → body → `Separator` between sections.",
1943
+ "Use `Table` for figures, `Timeline` for what happened when, `Markdown` for prose.",
1944
+ "Open with a one-paragraph summary before any detail.",
1945
+ "Attach generated files with `FileLink` at the end rather than inlining raw data."
1946
+ ].join("\n"),
1947
+ example: {
1948
+ component: "Stack",
1949
+ children: [
1950
+ {
1951
+ component: "Heading",
1952
+ props: {
1953
+ level: 2,
1954
+ text: "Q4 incident review"
1955
+ }
1956
+ },
1957
+ {
1958
+ component: "Text",
1959
+ props: { text: "Three incidents, all recovered within the hour." }
1960
+ },
1961
+ { component: "Separator" },
1962
+ {
1963
+ component: "Timeline",
1964
+ props: { items: [{
1965
+ title: "Search latency spike",
1966
+ time: "12 Nov",
1967
+ state: "done"
1968
+ }, {
1969
+ title: "Checkout timeouts",
1970
+ time: "03 Dec",
1971
+ state: "done"
1972
+ }] }
1973
+ },
1974
+ {
1975
+ component: "FileLink",
1976
+ props: {
1977
+ path: "q4-incidents.csv",
1978
+ label: "Full log",
1979
+ size: 24117
1980
+ }
1981
+ }
1982
+ ]
1983
+ }
1984
+ }
1985
+ ];
1986
+ const UI_PRESET_NAMES = UI_PRESETS.map((preset) => preset.name);
1987
+ /** Returns undefined for names outside the catalog presets. @experimental */
1988
+ function uiPreset(name) {
1989
+ return UI_PRESETS.find((preset) => preset.name === name);
1990
+ }
1475
1991
  /**
1476
1992
  * catalog 声明树 → json-render 扁平 spec。纯数据变换,不 import json-render
1477
1993
  * (`@webskill/ui` 保持环境无关)。
@@ -1518,6 +2034,7 @@ function toField(control) {
1518
2034
  ...control.required ? { required: true } : {},
1519
2035
  ...control.description ? { description: control.description } : {},
1520
2036
  ...control.defaultValue !== void 0 ? { defaultValue: control.defaultValue } : {},
2037
+ ...control.suggestion ? { suggestion: control.suggestion } : {},
1521
2038
  ...control.options ? { options: toOptions(control.options) } : {}
1522
2039
  }
1523
2040
  };
@@ -1551,6 +2068,7 @@ function interactionToUiSpec(request, labels = {}) {
1551
2068
  };
1552
2069
  }
1553
2070
  const RENDER_UI_TOOL = "render_ui";
2071
+ const DESCRIBE_UI_PRESET_TOOL = "describe_ui_preset";
1554
2072
  const defaultId = () => `ui-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
1555
2073
  /**
1556
2074
  * 工具描述只留一句指针:catalog 本体走 system 消息(C4)。
@@ -1576,8 +2094,9 @@ function isIntent(value) {
1576
2094
  * 从节点树抽出 action 能力表。能力表走事件外壳而非树内:
1577
2095
  * 树是模型可写的,nonce 放进去就等于让模型自己签发能力。
1578
2096
  * action id 取节点 id;Button 未声明 id 时退回 intent 名(同 intent 只留一条)。
2097
+ * 表单的提交/取消取自作用域表:容器级放宽后一张 surface 可能有多个表单。
1579
2098
  */
1580
- function collectActions(node, out) {
2099
+ function collectActions(node, out, scopes) {
1581
2100
  if (node.component === "Button" && isIntent(node.props?.["action"])) {
1582
2101
  const intent = node.props["action"];
1583
2102
  const id = node.id ?? intent;
@@ -1587,23 +2106,24 @@ function collectActions(node, out) {
1587
2106
  ...intent === "submit" ? { awaitResponse: true } : {}
1588
2107
  });
1589
2108
  }
1590
- if (node.component === "Form") {
1591
- if (!out.has("submit")) out.set("submit", {
1592
- id: "submit",
2109
+ const scope = scopes.get(node);
2110
+ if (scope) {
2111
+ if (!out.has(scope.submitActionId)) out.set(scope.submitActionId, {
2112
+ id: scope.submitActionId,
1593
2113
  intent: "submit",
1594
2114
  awaitResponse: true
1595
2115
  });
1596
- if (typeof node.props?.["cancelLabel"] === "string" && !out.has("cancel")) out.set("cancel", {
1597
- id: "cancel",
2116
+ if (typeof node.props?.["cancelLabel"] === "string" && !out.has(scope.cancelActionId)) out.set(scope.cancelActionId, {
2117
+ id: scope.cancelActionId,
1598
2118
  intent: "cancel"
1599
2119
  });
1600
2120
  }
1601
- for (const child of node.children ?? []) collectActions(child, out);
2121
+ for (const child of node.children ?? []) collectActions(child, out, scopes);
1602
2122
  }
1603
2123
  /** 节点树声明的 action 能力表(renderer 据此生成按钮,runtime 据此签发 nonce)。@experimental */
1604
2124
  function collectSpecActions(spec) {
1605
2125
  const actions = /* @__PURE__ */ new Map();
1606
- collectActions(spec, actions);
2126
+ collectActions(spec, actions, new Map(collectFormScopes(spec).map((scope) => [scope.form, scope])));
1607
2127
  return [...actions.values()];
1608
2128
  }
1609
2129
  /**
@@ -1613,21 +2133,63 @@ function collectSpecActions(spec) {
1613
2133
  function createUiCatalogToolSource(options = {}) {
1614
2134
  const catalog = options.catalog ?? uiCatalog;
1615
2135
  const newSurfaceId = options.newSurfaceId ?? defaultId;
2136
+ const presets = options.presets ? options.presets.flatMap((name) => uiPreset(name) ?? []) : UI_PRESETS;
2137
+ const presetChoices = presets.map((preset) => `${preset.name} — ${preset.summary}`).join("\n");
2138
+ const presetTool = () => ({
2139
+ name: DESCRIBE_UI_PRESET_TOOL,
2140
+ description: `Fetch the layout guidance for one scenario preset before calling ${RENDER_UI_TOOL}.\n${presetChoices}`,
2141
+ inputSchema: {
2142
+ type: "object",
2143
+ properties: { preset: {
2144
+ type: "string",
2145
+ enum: presets.map((preset) => preset.name)
2146
+ } },
2147
+ required: ["preset"],
2148
+ additionalProperties: false
2149
+ }
2150
+ });
2151
+ const renderTool = () => ({
2152
+ name: RENDER_UI_TOOL,
2153
+ description: RENDER_UI_DESCRIPTION,
2154
+ inputSchema: {
2155
+ type: "object",
2156
+ properties: {
2157
+ spec: catalog.toJsonSchema(),
2158
+ ...presets.length > 0 ? { preset: {
2159
+ type: "string",
2160
+ enum: presets.map((preset) => preset.name),
2161
+ description: `Scenario preset this surface follows; call ${DESCRIBE_UI_PRESET_TOOL} first for its layout guidance.`
2162
+ } } : {}
2163
+ },
2164
+ required: ["spec"],
2165
+ additionalProperties: false
2166
+ }
2167
+ });
1616
2168
  return {
1617
2169
  kind: "ui-catalog",
1618
2170
  systemPrompt: () => Promise.resolve(catalog.toPrompt()),
1619
- listToolSpecs: () => Promise.resolve([{
1620
- name: RENDER_UI_TOOL,
1621
- description: RENDER_UI_DESCRIPTION,
1622
- inputSchema: {
1623
- type: "object",
1624
- properties: { spec: catalog.toJsonSchema() },
1625
- required: ["spec"],
1626
- additionalProperties: false
2171
+ listToolSpecs: () => Promise.resolve(presets.length > 0 ? [renderTool(), presetTool()] : [renderTool()]),
2172
+ canHandle: (name) => name === "render_ui" || presets.length > 0 && name === "describe_ui_preset",
2173
+ call: (name, args) => {
2174
+ if (name === "describe_ui_preset") {
2175
+ const requested = args["preset"];
2176
+ const preset = presets.find((candidate) => candidate.name === requested);
2177
+ if (!preset) return Promise.resolve({
2178
+ ok: false,
2179
+ content: [],
2180
+ error: {
2181
+ code: "VALIDATION_FAILED",
2182
+ message: `Unknown UI preset "${String(requested)}"; available presets: ${presets.map((candidate) => candidate.name).join(", ")}`
2183
+ }
2184
+ });
2185
+ return Promise.resolve({
2186
+ ok: true,
2187
+ content: [{
2188
+ type: "text",
2189
+ text: `${preset.guidance}\n\nExample spec:\n${JSON.stringify(preset.example)}`
2190
+ }]
2191
+ });
1627
2192
  }
1628
- }]),
1629
- canHandle: (name) => name === RENDER_UI_TOOL,
1630
- call: (_name, args) => {
1631
2193
  const spec = args["spec"];
1632
2194
  const result = catalog.validate(spec);
1633
2195
  if (!result.ok) return Promise.resolve({
@@ -1728,13 +2290,14 @@ function toOpenUiSpecLang(spec, catalog = uiCatalog) {
1728
2290
  return [...lines.filter((line) => !line.startsWith(`${rootId} =`)), `root = ${lines.find((line) => line.startsWith(`${rootId} =`)).slice(rootId.length + 3)}`].join("\n");
1729
2291
  }
1730
2292
  const WEBSKILL_SURFACE_ACTION = "webskill:surface-action";
1731
- function toUiSurfaceActionDispatch(snapshot, action, value) {
2293
+ function toUiSurfaceActionDispatch(snapshot, action, value, scopeId) {
1732
2294
  return {
1733
2295
  ...snapshot.runId ? { runId: snapshot.runId } : {},
1734
2296
  surfaceId: snapshot.id,
1735
2297
  actionId: action.id,
1736
2298
  intent: action.intent,
1737
2299
  ...action.nonce ? { nonce: action.nonce } : {},
2300
+ ...scopeId ? { scopeId } : {},
1738
2301
  ...value ? { value } : {}
1739
2302
  };
1740
2303
  }
@@ -1749,6 +2312,7 @@ function fromUiSurfaceActionDispatch(value) {
1749
2312
  actionId: event["actionId"],
1750
2313
  intent: event["intent"],
1751
2314
  ...typeof event["nonce"] === "string" ? { nonce: event["nonce"] } : {},
2315
+ ...typeof event["scopeId"] === "string" ? { scopeId: event["scopeId"] } : {},
1752
2316
  ...isRecord(event["value"]) ? { value: event["value"] } : {},
1753
2317
  ...event["cancelled"] === true ? { cancelled: true } : {}
1754
2318
  };
@@ -1778,10 +2342,10 @@ function fromA2uiSurfaceAction(event) {
1778
2342
  return fromUiSurfaceActionDispatch(action.context);
1779
2343
  }
1780
2344
  /** Builds the A2UI event payload an extension host sends after a user action. @experimental */
1781
- function toA2uiSurfaceAction(snapshot, action, value) {
2345
+ function toA2uiSurfaceAction(snapshot, action, value, scopeId) {
1782
2346
  return {
1783
2347
  name: A2UI_SURFACE_ACTION,
1784
- context: toUiSurfaceActionDispatch(snapshot, action, value)
2348
+ context: toUiSurfaceActionDispatch(snapshot, action, value, scopeId)
1785
2349
  };
1786
2350
  }
1787
2351
  /** 声明树里按钮触发的事件名(宿主据 context.actionId 回传 surface action) */
@@ -1888,7 +2452,7 @@ function fromA2uiSpecAction(event) {
1888
2452
  */
1889
2453
  async function loadWebSkillLitCatalog() {
1890
2454
  try {
1891
- const { webskillLitCatalog } = await import("./webskillLitCatalog-CSTbhBe_-CYIs5BX8.js");
2455
+ const { webskillLitCatalog } = await import("./webskillLitCatalog-_mugzRHx-DiuJpCuf.js");
1892
2456
  return webskillLitCatalog();
1893
2457
  } catch (cause) {
1894
2458
  throw new WebSkillError("UI_UNAVAILABLE", "The WebSkill A2UI catalog is unavailable; install @a2ui/lit, @a2ui/web_core and lit to render catalog surfaces with A2UI", cause);
@@ -1913,4 +2477,4 @@ async function loadOpenUiPeers() {
1913
2477
  }
1914
2478
 
1915
2479
  //#endregion
1916
- export { toA2uiSpecMessages as A, a2uiComponentSchema as B, interactionToUiSpec as C, renderMiniChart as D, renderBlocks as E, toVercelToolInvocation as F, mountEchart as G, buildA2uiCatalogDefinition as H, A2UI_CHILDREN_PROP as I, renderMiniMarkdown as K, A2UI_COMMON_TYPES as L, toJsonRenderSpec as M, toOpenUiSpecLang as N, renderRenderResult as O, toUiSurfaceActionDispatch as P, UI_CATALOG_GROUPS as R, interactionToFormModel as S, loadWebSkillLitCatalog as T, chartSpecFromProps as U, a2uiComponentShapes as V, defineUiCatalog as W, ensureStyles as _, A2UI_VERSION as a, fromUiSurfaceActionDispatch as b, VERCEL_INTERACTION_TOOL_NAME as c, WEBSKILL_SURFACE_ACTION as d, WebFormBridge as f, createUiCatalogToolSource as g, collectValues as h, A2UI_SURFACE_ACTION as i, toA2uiSurfaceAction as j, shapeInteractionValue as k, VercelUiBridge as l, collectSpecActions as m, A2UI_SPEC_ACTION as n, CHART_PALETTE as o, chartToTable as p, uiCatalog as q, A2UI_SPEC_FORM_PATH as r, RENDER_UI_TOOL as s, A2UI_BASIC_CATALOG_ID as t, WEBSKILL_STYLES_CSS as u, fromA2uiSpecAction as v, loadOpenUiPeers as w, fromVercelToolResult as x, fromA2uiSurfaceAction as y, WEBSKILL_A2UI_CATALOG_ID as z };
2480
+ export { defineUiCatalog as $, loadOpenUiPeers as A, toOpenUiSpecLang as B, ensureStyles as C, fromVercelToolResult as D, fromUiSurfaceActionDispatch as E, renderRenderResult as F, A2UI_COMMON_TYPES as G, toVercelToolInvocation as H, shapeInteractionValue as I, WEBSKILL_A2UI_CATALOG_ID as J, UI_CATALOG_GROUPS as K, toA2uiSpecMessages as L, qualifyFieldName as M, renderBlocks as N, interactionToFormModel as O, renderMiniChart as P, chartSpecFromProps as Q, toA2uiSurfaceAction as R, createUiCatalogToolSource as S, fromA2uiSurfaceAction as T, uiPreset as U, toUiSurfaceActionDispatch as V, A2UI_CHILDREN_PROP as W, a2uiComponentShapes as X, a2uiComponentSchema as Y, buildA2uiCatalogDefinition as Z, chartToTable as _, A2UI_VERSION as a, collectSpecActions as b, RENDER_UI_TOOL as c, VERCEL_INTERACTION_TOOL_NAME as d, mountEchart as et, VercelUiBridge as f, applySuggestion as g, WebFormBridge as h, A2UI_SURFACE_ACTION as i, loadWebSkillLitCatalog as j, interactionToUiSpec as k, UI_PRESETS as l, WEBSKILL_SURFACE_ACTION as m, A2UI_SPEC_ACTION as n, uiCatalog as nt, CHART_PALETTE as o, WEBSKILL_STYLES_CSS as p, UI_CATALOG_PROMPT_BUDGET_BYTES as q, A2UI_SPEC_FORM_PATH as r, DESCRIBE_UI_PRESET_TOOL as s, A2UI_BASIC_CATALOG_ID as t, renderMiniMarkdown as tt, UI_PRESET_NAMES as u, collectFormScopes as v, fromA2uiSpecAction as w, collectValues as x, collectScopedValues as y, toJsonRenderSpec as z };