@maggioli-rd/aicore-agent-chat 1.1.1 → 1.3.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 (131) hide show
  1. package/README.md +33 -14
  2. package/dist/aicore-agent-chat.js +59 -38
  3. package/dist/aicore-agent-chat.js.map +1 -1
  4. package/dist/bundle/a2ui-C3GhjTrJ.js +113 -0
  5. package/dist/bundle/abnfDiagram-S7VZAUFO-DxkzIS8G.js +1 -0
  6. package/dist/bundle/architecture-WOLXFQ4H-BXMyXdT1.js +1 -0
  7. package/dist/bundle/architectureDiagram-YGSQEFNW-BmsDn6Ho.js +36 -0
  8. package/dist/bundle/blockDiagram-APKKGZFW-bG_MVPzT.js +140 -0
  9. package/dist/bundle/bpmnIcons-APHXDYXF-C0jbCElo.js +1 -0
  10. package/dist/bundle/c4Diagram-KJ2TOQU5-BVad-wQe.js +38 -0
  11. package/dist/bundle/chunk-2Q5K7J3B-C1jixKkw.js +1 -0
  12. package/dist/bundle/chunk-5VM5RSS4-CwNG0iBi.js +15 -0
  13. package/dist/bundle/chunk-6MUBBAK2-CeH4cZO-.js +2 -0
  14. package/dist/bundle/chunk-AXFCVDMN-D0Vqm50X.js +62 -0
  15. package/dist/bundle/chunk-BG4553SI-DUBI9JbR.js +127 -0
  16. package/dist/bundle/chunk-DQASFODM-DBWVlIjs.js +10 -0
  17. package/dist/bundle/chunk-DUW6YSOI-ChybIQ82.js +1 -0
  18. package/dist/bundle/chunk-HFQBQIA3-D2xPptW8.js +1 -0
  19. package/dist/bundle/chunk-J5ZVWO5B-DHB__t6z.js +1 -0
  20. package/dist/bundle/chunk-JWPE2WC7-DVXcaiue.js +1 -0
  21. package/dist/bundle/chunk-KQLB2F66-BRGnyo9e.js +1 -0
  22. package/dist/bundle/chunk-KS47KZWR-DV3Gxewa.js +1 -0
  23. package/dist/bundle/chunk-LEVMRMFU-BdDTT4pw.js +1 -0
  24. package/dist/bundle/chunk-M57EVK23-BRqFqW5o.js +1 -0
  25. package/dist/bundle/chunk-NGNAAXSQ-DreF1ykJ.js +214 -0
  26. package/dist/bundle/chunk-OY52VR5R-BamrP8d_.js +88 -0
  27. package/dist/bundle/chunk-QB3YPZ4I-BqUUL29j.js +213 -0
  28. package/dist/bundle/chunk-R3KSYZAL-gmtEjdKU.js +1 -0
  29. package/dist/bundle/chunk-STOXU5M4-DdqxXfKq.js +72 -0
  30. package/dist/bundle/chunk-TU62E6Q5-B4GgWjUW.js +1 -0
  31. package/dist/bundle/chunk-X4PVCEUW-BcN5Aq5G.js +1 -0
  32. package/dist/bundle/chunk-XXDRQBXY-BIvjAdC_.js +1 -0
  33. package/dist/bundle/chunk-Y2CYZVJY-DsF7k-Jl.js +1 -0
  34. package/dist/bundle/classDiagram-v2-L25IHNXF-Dw7so3mk.js +217 -0
  35. package/dist/bundle/cose-bilkent-JH36ORCC-DUvnuVrm.js +1 -0
  36. package/dist/bundle/cynefin-EF2NZ3EQ-CcVPiRLN.js +1 -0
  37. package/dist/bundle/cynefinDiagram-L36ESFBY-eO6Z3Kvn.js +62 -0
  38. package/dist/bundle/cytoscape.esm-CsT4DLSP.js +321 -0
  39. package/dist/bundle/d3-hierarchy-i5r04UUG.js +1 -0
  40. package/dist/bundle/d3-scale-BEO6F4Sh.js +1 -0
  41. package/dist/bundle/d3-scale-chromatic-DhHjp77O.js +1 -0
  42. package/dist/bundle/d3-selection-CBFxn8wf.js +1 -0
  43. package/dist/bundle/d3-shape-v1Y4qR5e.js +1 -0
  44. package/dist/bundle/dagre-SPEB5RXH-ByBZqBaT.js +4 -0
  45. package/dist/bundle/diagram-3B7GL73J-BkQkIpxz.js +200 -0
  46. package/dist/bundle/diagram-DNEMPZML-DYthXzRv.js +24 -0
  47. package/dist/bundle/diagram-L3MUGCDN-D4DIzfHH.js +41 -0
  48. package/dist/bundle/diagram-LA4NIPWU-C2P-hZD1.js +24 -0
  49. package/dist/bundle/diagram-MHCOC4E2-BwauFnTV.js +3 -0
  50. package/dist/bundle/diagram-XPFHEONP-DC_v3Llc.js +30 -0
  51. package/dist/bundle/dist-CwuaKeLF.js +1 -0
  52. package/dist/bundle/ebnfDiagram-UZSYDL2S-CmwGlC8L.js +1 -0
  53. package/dist/bundle/elk-XV6XMXQE-CTlty3p3.js +27 -0
  54. package/dist/bundle/erDiagram-EYBAPDEH-Bu6phvJH.js +99 -0
  55. package/dist/bundle/eventmodeling-K75KTNOO-B1q0nOJE.js +1 -0
  56. package/dist/bundle/flowDiagram-MALGAFMO-D9D_AzXh.js +1 -0
  57. package/dist/bundle/ganttDiagram-23REXITY-COK7rxO4.js +292 -0
  58. package/dist/bundle/gitGraph-VSP46ZUC-DS7S_jKI.js +1 -0
  59. package/dist/bundle/gitGraphDiagram-STJD7YCW-DhVK8Hqh.js +106 -0
  60. package/dist/bundle/graphlib-Bgy7WbC7.js +1 -0
  61. package/dist/bundle/info-OHQRW6UA-BjEWvFlW.js +1 -0
  62. package/dist/bundle/infoDiagram-KBXO4MBG-Dg3zWdHP.js +2 -0
  63. package/dist/bundle/ishikawaDiagram-M35NCXHK-C2g8ghrV.js +70 -0
  64. package/dist/bundle/journeyDiagram-OPLOXDXO-DMZkL-i1.js +139 -0
  65. package/dist/bundle/kanban-definition-BZKZHSQY-Dr43IiJD.js +89 -0
  66. package/dist/bundle/katex-rAoShGnF.js +257 -0
  67. package/dist/bundle/math-Cx-Q-b8s.js +262 -0
  68. package/dist/bundle/mermaid-DaDuEHir.js +43 -0
  69. package/dist/bundle/mermaid-parser.core-Bv_Zx_ZE.js +6 -0
  70. package/dist/bundle/mindmap-definition-I2QAS2VK-BXCWJ_1R.js +98 -0
  71. package/dist/bundle/packet-JDAUHWVQ-CgB2qE5t.js +1 -0
  72. package/dist/bundle/pegDiagram-FD4XPPHP-CR58gOgF.js +1 -0
  73. package/dist/bundle/pie-XZMESJXO-CvXWTfIG.js +1 -0
  74. package/dist/bundle/pieDiagram-J4AKIIQI-D0GhbNJg.js +39 -0
  75. package/dist/bundle/quadrantDiagram-XTYBLID2-BKBEdwvC.js +7 -0
  76. package/dist/bundle/radar-ABXABTNO-8V_xx_AB.js +1 -0
  77. package/dist/bundle/railroad-I3PHUGI6-Bvb0GUva.js +1 -0
  78. package/dist/bundle/railroad-abnf-LNEFI6M7-D8xGcObq.js +1 -0
  79. package/dist/bundle/railroad-ebnf-DWYD2UWJ-Ch8wBawI.js +1 -0
  80. package/dist/bundle/railroad-peg-JR7BVNR7-CGndbjed.js +1 -0
  81. package/dist/bundle/railroadDiagram-MRQ6NCDL-DvqHkO2C.js +1 -0
  82. package/dist/bundle/requirementDiagram-Y7LWUY3S-bCLAM9sl.js +84 -0
  83. package/dist/bundle/rolldown-runtime-BNaE-Ejt.js +1 -0
  84. package/dist/bundle/rough.esm-Dy-Kn_BL.js +1 -0
  85. package/dist/bundle/sankeyDiagram-WGJFYUXA-8ehuPvHQ.js +40 -0
  86. package/dist/bundle/sequenceDiagram-5NDRBG5M-Cdg1YzMw.js +169 -0
  87. package/dist/bundle/sizeCapture-INFHLROL-Ct7XApxm.js +1 -0
  88. package/dist/bundle/stateDiagram-v2-FJ4FJNEA-B69v2YYC.js +291 -0
  89. package/dist/bundle/swimlanes-UMQ2AFYF-C_qI6rnK.js +1 -0
  90. package/dist/bundle/swimlanesDiagram-OMPLPG4O-CS11qSCX.js +8 -0
  91. package/dist/bundle/timeline-definition-SEUHKTQE-BCU0-H8D.js +120 -0
  92. package/dist/bundle/treeView-D4JQ5SDB-CpjURS-c.js +1 -0
  93. package/dist/bundle/treemap-SAJKECNS-CFFTaiIN.js +1 -0
  94. package/dist/bundle/usecaseDiagram-AFA6YXN4-46V1jsea.js +476 -0
  95. package/dist/bundle/vega-eBn1AexV.js +33 -0
  96. package/dist/bundle/vennDiagram-NNMJR3RB-q4Q4x2Q6.js +34 -0
  97. package/dist/bundle/wardley-7MLQ67FV-DhnATL7b.js +1 -0
  98. package/dist/bundle/wardleyDiagram-S7YFUSEH-BHIufnZW.js +78 -0
  99. package/dist/bundle/xychartDiagram-GGNKY7IX-CxAjpN3O.js +7 -0
  100. package/dist/chunks/a2ui-BLaPxJ9N.js +961 -0
  101. package/dist/chunks/a2ui-BLaPxJ9N.js.map +1 -0
  102. package/dist/chunks/math-D5IXRTov.js +86 -0
  103. package/dist/chunks/math-D5IXRTov.js.map +1 -0
  104. package/dist/chunks/mermaid-j9RNkOnL.js +197 -0
  105. package/dist/chunks/mermaid-j9RNkOnL.js.map +1 -0
  106. package/dist/chunks/rich-C2iN_5zh.js +156 -0
  107. package/dist/chunks/rich-C2iN_5zh.js.map +1 -0
  108. package/dist/chunks/sanitize-COLQzplk.js +240 -0
  109. package/dist/chunks/sanitize-COLQzplk.js.map +1 -0
  110. package/dist/chunks/{src-DPfU5Bd2.js → src-Blgo9nVC.js} +387 -73
  111. package/dist/chunks/src-Blgo9nVC.js.map +1 -0
  112. package/dist/chunks/vega-BkX1Fjq6.js +301 -0
  113. package/dist/chunks/vega-BkX1Fjq6.js.map +1 -0
  114. package/dist/define.js +1 -1
  115. package/dist/index.js +1 -1
  116. package/dist/types/element/i18n.d.ts +21 -2
  117. package/dist/types/element/index.d.ts +11 -2
  118. package/dist/types/element/markdown.d.ts +6 -3
  119. package/dist/types/element/rich/a2ui-format.d.ts +45 -0
  120. package/dist/types/element/rich/a2ui-icons.d.ts +1 -0
  121. package/dist/types/element/rich/a2ui-views.d.ts +37 -0
  122. package/dist/types/element/rich/a2ui.d.ts +2 -0
  123. package/dist/types/element/rich/index.d.ts +66 -0
  124. package/dist/types/element/rich/math.d.ts +4 -0
  125. package/dist/types/element/rich/mermaid.d.ts +2 -0
  126. package/dist/types/element/rich/vega.d.ts +2 -0
  127. package/dist/types/element/sanitize.d.ts +34 -0
  128. package/dist/types/element/styles.d.ts +1 -1
  129. package/dist/types/jsx.d.ts +2 -0
  130. package/package.json +12 -6
  131. package/dist/chunks/src-DPfU5Bd2.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitize-COLQzplk.js","names":[],"sources":["../../src/element/sanitize.ts"],"sourcesContent":["import createDOMPurify, { type Config, type DOMPurify } from \"dompurify\";\n\n// Everything an answer puts on screen goes through here: the HTML of its\n// markdown, and what the renderers of formulas, diagrams and charts draw from\n// it. The text comes from a model, which a prompt injection can steer, so:\n// - one DOMPurify of our own, with the same hooks for every pass: links open\n// in a new tab with no opener and no referrer; nothing may load a resource\n// by itself (an image, a `url()` in an attribute or in CSS), since its URL\n// can carry the conversation out;\n// - inline styles never go in as attributes: a strict CSP (`style-src`\n// without `'unsafe-inline'`) would drop them. They are taken out while\n// sanitizing and set again through CSSOM, which `style-src` does not\n// govern, after the same `url()` check;\n// - the browser parses the HTML through our Trusted Types policy, so a host\n// that enforces Trusted Types only allows `aicore-agent-chat`.\n\ninterface Policy {\n createHTML(input: string): unknown;\n createScriptURL(input: string): unknown;\n}\n\nlet policy: Policy | null | undefined;\n\n/** The `aicore-agent-chat` Trusted Types policy. Null where the browser has\n * none, or the host's CSP refuses the name: then HTML goes in as a string. */\nexport function policyOf(): Policy | null {\n if (policy !== undefined) return policy;\n const factory = (\n globalThis as {\n trustedTypes?: {\n createPolicy(\n name: string,\n rules: {\n createHTML(input: string): string;\n createScriptURL(input: string): string;\n },\n ): Policy;\n };\n }\n ).trustedTypes;\n try {\n policy =\n factory?.createPolicy(\"aicore-agent-chat\", {\n // Only ever given to DOMPurify, to parse what it is about to clean,\n // and to `innerHTML`, with what DOMPurify returned.\n createHTML: (input) => input,\n // DOMPurify asks for it, but drops every element that loads a script.\n createScriptURL: () => \"\",\n }) ?? null;\n } catch {\n policy = null;\n }\n return policy;\n}\n\n/** Tags no answer may carry, in any pass: what loads something by itself,\n * styles, forms. */\nconst FORBID_TAGS = [\n \"img\",\n \"image\",\n \"feImage\",\n \"picture\",\n \"video\",\n \"audio\",\n \"source\",\n \"track\",\n \"iframe\",\n \"frame\",\n \"object\",\n \"embed\",\n \"link\",\n \"meta\",\n \"base\",\n \"style\",\n \"form\",\n \"input\",\n \"button\",\n \"textarea\",\n \"select\",\n];\n\n/** Attributes that load something, or send something, by themselves. */\nconst LOADING_ATTRS = new Set([\n \"src\",\n \"srcset\",\n \"poster\",\n \"background\",\n \"lowsrc\",\n \"dynsrc\",\n \"data\",\n \"ping\",\n \"action\",\n \"formaction\",\n]);\n\n/** Attributes whose value is text or a link, never CSS: a `url(` in them is\n * words, as in a link to a page about CSS. */\nconst TEXT_ATTRS = new Set([\"href\", \"xlink:href\", \"title\", \"alt\"]);\n\nconst MARKDOWN: Config = { FORBID_TAGS, FORBID_ATTR: [\"style\"] };\n\n/** What a renderer draws: HTML, SVG (with HTML labels in `foreignObject`, as\n * Mermaid writes them) and MathML (KaTeX's accessible copy of a formula). */\nconst DRAWING: Config = {\n USE_PROFILES: { html: true, svg: true, svgFilters: true, mathMl: true },\n ADD_TAGS: [\"foreignObject\", \"semantics\", \"annotation\"],\n HTML_INTEGRATION_POINTS: { foreignobject: true },\n FORBID_TAGS,\n};\n\n/** A `url()` that is not a reference inside the same document (`url(#id)`). */\nconst REMOTE_URL = /url\\(\\s*(?!['\"]?#)/i;\n/** CSS functions that load something with no `url()` around it. */\nconst REMOTE_CSS = /(?:image-set|image|cross-fade|element)\\(/i;\n\n/** The pass under way: its inline styles and `<style>` texts, taken out. */\nlet current: {\n styles: Map<Element, string>;\n sheets: string[];\n} | null = null;\n\nlet purifier: DOMPurify | null = null;\n\n/** A DOMPurify of our own: a hook on the shared instance would also change\n * how the host app sanitizes. */\nfunction purifierOf(): DOMPurify {\n if (purifier) return purifier;\n purifier = createDOMPurify(window);\n purifier.addHook(\"uponSanitizeElement\", (node, data) => {\n if (current && data.tagName === \"style\")\n current.sheets.push(node.textContent ?? \"\");\n });\n purifier.addHook(\"uponSanitizeAttribute\", (node, data) => {\n const name = data.attrName;\n const value = data.attrValue;\n if (name === \"style\") {\n if (current) current.styles.set(node, value);\n data.keepAttr = false;\n } else if (LOADING_ATTRS.has(name)) {\n data.keepAttr = false;\n } else if (\n // A drawing's presentation attributes (`fill`, `filter`, `mask`…).\n current &&\n !TEXT_ATTRS.has(name) &&\n !name.startsWith(\"aria-\") &&\n REMOTE_URL.test(value)\n ) {\n data.keepAttr = false;\n } else if (\n (name === \"href\" || name === \"xlink:href\") &&\n node.nodeName.toLowerCase() !== \"a\" &&\n !value.startsWith(\"#\")\n ) {\n data.keepAttr = false;\n }\n });\n purifier.addHook(\"afterSanitizeAttributes\", (node) => {\n if (node.nodeName.toLowerCase() === \"a\") {\n node.setAttribute(\"target\", \"_blank\");\n node.setAttribute(\"rel\", \"noopener noreferrer nofollow\");\n }\n });\n return purifier;\n}\n\n/** The Trusted Types policy DOMPurify parses with, when there is one. */\nfunction parsing(config: Config): Config {\n const trusted = policyOf();\n return trusted\n ? {\n ...config,\n TRUSTED_TYPES_POLICY: trusted as Config[\"TRUSTED_TYPES_POLICY\"],\n }\n : config;\n}\n\n/** `html` (the markdown's) sanitized, as a string. Browser only. */\nexport function sanitizeHtml(html: string): string {\n return purifierOf().sanitize(html, parsing(MARKDOWN));\n}\n\n/** `html` sanitized for `innerHTML`: through the policy when there is one. */\nexport function trustedHtml(html: string): string {\n const trusted = policyOf();\n return (trusted ? trusted.createHTML(html) : html) as string;\n}\n\n/** What a renderer drew, sanitized: a fragment ready to insert, and the CSS of\n * its `<style>` elements, which a caller adopts as a stylesheet. */\nexport function sanitizeDrawing(markup: string): {\n fragment: DocumentFragment;\n css: string;\n} {\n const pass = (current = {\n styles: new Map<Element, string>(),\n sheets: [] as string[],\n });\n try {\n const fragment = purifierOf().sanitize(markup, {\n ...parsing(DRAWING),\n RETURN_DOM_FRAGMENT: true,\n });\n // Adopted, not copied: the elements keep their identity, and so the\n // styles taken out of them.\n const owned = document.adoptNode(fragment);\n for (const [element, css] of pass.styles) setStyle(element, css);\n return { fragment: owned, css: pass.sheets.join(\"\\n\") };\n } finally {\n current = null;\n }\n}\n\n/** `node`, a drawing built with DOM calls, sanitized where it stands. */\nexport function sanitizeNode(node: Element): void {\n const pass = (current = {\n styles: new Map<Element, string>(),\n sheets: [] as string[],\n });\n try {\n purifierOf().sanitize(node, { ...parsing(DRAWING), IN_PLACE: true });\n for (const [element, css] of pass.styles) setStyle(element, css);\n } finally {\n current = null;\n }\n}\n\n/** `css` (a `style` attribute's value) set through CSSOM, without any\n * declaration that would load something. */\nexport function setStyle(element: Element, css: string): void {\n const style = (element as HTMLElement | SVGElement).style as\n CSSStyleDeclaration | undefined;\n if (!style) return;\n style.cssText = css;\n for (const name of [...style]) {\n const value = style.getPropertyValue(name);\n if (REMOTE_URL.test(value) || REMOTE_CSS.test(value))\n style.removeProperty(name);\n }\n}\n\n/** `css` as a constructable stylesheet with only style rules (nested ones\n * too), their groups (`@media`, `@supports`…) and keyframes, and no\n * declaration that would load something, wherever it sits: never an\n * `@import` or a `@font-face` from an answer. Null where the browser has\n * none. */\nexport function safeSheet(css: string): CSSStyleSheet | null {\n let sheet: CSSStyleSheet;\n try {\n sheet = new CSSStyleSheet();\n sheet.replaceSync(css);\n } catch {\n return null;\n }\n clean(sheet);\n return sheet;\n}\n\n/** The rules a drawing's stylesheet keeps, by their interface's name. */\nconst KEPT_RULES = new Set([\n \"CSSStyleRule\",\n \"CSSNestedDeclarations\",\n \"CSSMediaRule\",\n \"CSSSupportsRule\",\n \"CSSContainerRule\",\n \"CSSLayerBlockRule\",\n \"CSSKeyframesRule\",\n \"CSSKeyframeRule\",\n]);\n\ninterface RuleGroup {\n readonly cssRules: CSSRuleList;\n deleteRule(index: number): void;\n}\n\nfunction clean(group: RuleGroup): void {\n for (let i = group.cssRules.length - 1; i >= 0; i--) {\n const rule = group.cssRules[i]!;\n if (!KEPT_RULES.has(rule.constructor.name)) {\n group.deleteRule(i);\n continue;\n }\n if (\"style\" in rule) {\n const style = (rule as CSSRule & { style: CSSStyleDeclaration }).style;\n for (const name of [...style]) {\n const value = style.getPropertyValue(name);\n if (REMOTE_URL.test(value) || REMOTE_CSS.test(value))\n style.removeProperty(name);\n }\n }\n // A group, a style rule with nested ones, a keyframes rule: its rules\n // too. (Those of a keyframes rule are all kept.)\n if (\"cssRules\" in rule) clean(rule as CSSRule & RuleGroup);\n }\n}\n\n/** Adds `sheet` to the stylesheets of `root` (the element's shadow root, or\n * the document), once. */\nexport function adoptSheet(\n root: DocumentOrShadowRoot,\n sheet: CSSStyleSheet,\n): void {\n if (!root.adoptedStyleSheets.includes(sheet))\n root.adoptedStyleSheets = [...root.adoptedStyleSheets, sheet];\n}\n\n/** Removes `sheet` from the stylesheets of `root`. */\nexport function dropSheet(\n root: DocumentOrShadowRoot,\n sheet: CSSStyleSheet,\n): void {\n if (root.adoptedStyleSheets.includes(sheet))\n root.adoptedStyleSheets = root.adoptedStyleSheets.filter(\n (s) => s !== sheet,\n );\n}\n"],"mappings":"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"}
@@ -1,5 +1,6 @@
1
1
  import { T as isRecord, n as CHAT_CHANGE, o as AICORE_EVENTS, p as turnErrorText, t as AicoreChatSession } from "./core-Db3hnKpM.js";
2
- import createDOMPurify from "dompurify";
2
+ import { a as keepDrawings, o as updateInterfaces, r as enhance, t as disposeDrawings } from "./rich-C2iN_5zh.js";
3
+ import { a as sanitizeHtml, s as trustedHtml } from "./sanitize-COLQzplk.js";
3
4
  import { Marked } from "marked";
4
5
  // src/element/markdown.ts
5
6
  var ESCAPES = {
@@ -10,64 +11,83 @@ var ESCAPES = {
10
11
  "'": "&#39;"
11
12
  };
12
13
  var escapeHtml = (text) => text.replace(/[&<>"']/g, (c) => ESCAPES[c]);
14
+ var INLINE_MATH = /^(\$+)(?!\$)([\s\S]*?[^$])\1(?!\$)/;
15
+ var OPEN_MATH = /^ {0,3}(\${2,})[^$\n]*(?:\n|$)/;
16
+ var CLOSE_MATH = /^ {0,3}(\${2,})[ \t]*$/;
13
17
  var marked = new Marked({
14
18
  gfm: true,
15
19
  breaks: true,
16
20
  async: false,
21
+ extensions: [{
22
+ name: "blockMath",
23
+ level: "block",
24
+ start: (src) => /^ {0,3}\${2,}[^$\n]*$/m.exec(src)?.index,
25
+ tokenizer(src) {
26
+ const open = OPEN_MATH.exec(src);
27
+ if (!open) return void 0;
28
+ const fence = open[1].length;
29
+ const lines = src.slice(open[0].length).split("\n");
30
+ const body = [];
31
+ let raw = open[0];
32
+ for (const [index, line] of lines.entries()) {
33
+ const last = index === lines.length - 1;
34
+ raw += last ? line : `${line}\n`;
35
+ const close = CLOSE_MATH.exec(line);
36
+ if (close && close[1].length >= fence) break;
37
+ body.push(line);
38
+ }
39
+ return {
40
+ type: "blockMath",
41
+ raw,
42
+ text: body.join("\n")
43
+ };
44
+ },
45
+ renderer: (token) => `<div class="math-display">${escapeHtml(token.text)}</div>\n`
46
+ }, {
47
+ name: "inlineMath",
48
+ level: "inline",
49
+ start: (src) => {
50
+ const index = src.indexOf("$");
51
+ return index < 0 ? void 0 : index;
52
+ },
53
+ tokenizer(src) {
54
+ const match = INLINE_MATH.exec(src);
55
+ if (!match) return void 0;
56
+ let text = match[2];
57
+ if (/^[ \n]/.test(text) && /[ \n]$/.test(text) && /[^ \n]/.test(text)) text = text.slice(1, -1);
58
+ return {
59
+ type: "inlineMath",
60
+ raw: match[0],
61
+ text
62
+ };
63
+ },
64
+ renderer: (token) => `<span class="math-inline">${escapeHtml(token.text)}</span>`
65
+ }],
17
66
  renderer: {
18
67
  html: ({ text }) => escapeHtml(text),
19
- image: ({ href, text }) => `<a href="${escapeHtml(href)}">${escapeHtml(text || href)}</a>`
68
+ image: ({ href, text }) => `<a href="${escapeHtml(href)}">${escapeHtml(text || href)}</a>`,
69
+ code: ({ text, lang, raw }) => {
70
+ const language = /^\S*/.exec(lang ?? "")?.[0] ?? "";
71
+ if (language === "math") return `<div class="math-display">${escapeHtml(text)}</div>\n`;
72
+ const lines = raw.trimEnd().split("\n");
73
+ const open = /^ {0,3}(`{3,}|~{3,})/.test(lines[0] ?? "") && (lines.length < 2 || !/^ {0,3}(`{3,}|~{3,})[ \t]*$/.test(lines.at(-1)));
74
+ const code = `${escapeHtml(text.replace(/\n$/, ""))}\n`;
75
+ const attrs = language ? ` class="language-${escapeHtml(language)}"` : "";
76
+ return `<pre${open ? " data-open" : ""}><code${attrs}>${code}</code></pre>\n`;
77
+ }
20
78
  }
21
79
  });
22
- var purifier = null;
23
- /** A DOMPurify of our own: a hook on the shared instance would also change
24
- * how the host app sanitizes. */
25
- function purifierOf() {
26
- if (purifier) return purifier;
27
- purifier = createDOMPurify(window);
28
- purifier.addHook("afterSanitizeAttributes", (node) => {
29
- if (node.tagName === "A") {
30
- node.setAttribute("target", "_blank");
31
- node.setAttribute("rel", "noopener noreferrer nofollow");
32
- }
33
- });
34
- return purifier;
35
- }
36
- /** `text` (markdown) as sanitized HTML. Browser only. */
80
+ /** `text` (markdown) as sanitized HTML, formulas and fenced blocks still as
81
+ * their source. Browser only. */
37
82
  function renderMarkdown(text) {
38
- const html = marked.parse(text);
39
- return purifierOf().sanitize(html, {
40
- FORBID_TAGS: [
41
- "img",
42
- "style",
43
- "form",
44
- "input",
45
- "button",
46
- "textarea"
47
- ],
48
- FORBID_ATTR: ["style"]
49
- });
83
+ return sanitizeHtml(marked.parse(text));
50
84
  }
51
- var policy;
52
- /** A Trusted Types policy for the sanitized answer, so a host that enforces
53
- * Trusted Types (`require-trusted-types-for 'script'`) only has to allow
54
- * `trusted-types aicore-agent-chat`. Null where the browser has none, or the
55
- * host's CSP refuses the name: then the HTML goes in as a string. */
56
- function policyOf() {
57
- if (policy !== void 0) return policy;
58
- const factory = globalThis.trustedTypes;
59
- try {
60
- policy = factory?.createPolicy("aicore-agent-chat", { createHTML: (input) => input }) ?? null;
61
- } catch {
62
- policy = null;
63
- }
64
- return policy;
65
- }
66
- /** Renders `text` (markdown) into `element`, sanitized. */
67
- function setMarkdown(element, text) {
68
- const html = text ? renderMarkdown(text) : "";
69
- const trusted = policyOf();
70
- element.innerHTML = trusted ? trusted.createHTML(html) : html;
85
+ /** Renders `text` (markdown) into `element`, sanitized, then draws its
86
+ * formulas (and, with `widgets`, its diagrams, charts and interfaces). */
87
+ function setMarkdown(element, text, options) {
88
+ const kept = keepDrawings(element);
89
+ element.innerHTML = trustedHtml(text ? renderMarkdown(text) : "");
90
+ enhance(element, options, kept);
71
91
  }
72
92
  // src/element/i18n.ts
73
93
  var it = {
@@ -135,7 +155,17 @@ var it = {
135
155
  notPublished: "non pubblicato",
136
156
  conversation: "Conversazione",
137
157
  context: "Contesto del turno",
138
- none: "—"
158
+ none: "—",
159
+ a2uiPreparing: "Preparazione del modulo…",
160
+ a2uiRefused: (reason) => `Interfaccia non disegnata: ${reason}`,
161
+ a2uiInvalid: "il blocco non rispetta il catalogo",
162
+ a2uiSent: "Inviato",
163
+ a2uiDetails: "Dettagli",
164
+ a2uiTabs: "Schede",
165
+ close: "Chiudi",
166
+ a2uiAction: (action) => `Azione ${action}`,
167
+ yes: "sì",
168
+ no: "no"
139
169
  };
140
170
  var en = {
141
171
  locale: "en-GB",
@@ -202,13 +232,27 @@ var en = {
202
232
  notPublished: "not published",
203
233
  conversation: "Conversation",
204
234
  context: "Turn context",
205
- none: "—"
235
+ none: "—",
236
+ a2uiPreparing: "Preparing the form…",
237
+ a2uiRefused: (reason) => `Interface not drawn: ${reason}`,
238
+ a2uiInvalid: "the block does not follow the catalog",
239
+ a2uiSent: "Sent",
240
+ a2uiDetails: "Details",
241
+ a2uiTabs: "Tabs",
242
+ close: "Close",
243
+ a2uiAction: (action) => `Action ${action}`,
244
+ yes: "yes",
245
+ no: "no"
206
246
  };
207
- /** The built-in texts for `lang`: Italian for `it…` or no language at all,
208
- * English for any other language. */
209
- function baseStringsOf(lang) {
247
+ /** The language the element speaks for `lang`: Italian for `it…` or no
248
+ * language at all, English for any other language. */
249
+ function languageOf(lang) {
210
250
  const tag = lang?.trim().toLowerCase() ?? "";
211
- return tag === "" || tag.startsWith("it") ? it : en;
251
+ return tag === "" || tag.startsWith("it") ? "it" : "en";
252
+ }
253
+ /** The built-in texts for `lang` (see `languageOf`). */
254
+ function baseStringsOf(lang) {
255
+ return languageOf(lang) === "it" ? it : en;
212
256
  }
213
257
  /** The texts for `lang`, with the host's overrides on top. */
214
258
  function stringsOf(lang, overrides) {
@@ -241,6 +285,7 @@ var PATHS = {
241
285
  var SVG_NS = "http://www.w3.org/2000/svg";
242
286
  function icon(name) {
243
287
  const svg = document.createElementNS(SVG_NS, "svg");
288
+ svg.setAttribute("class", "icon");
244
289
  svg.setAttribute("viewBox", "0 0 24 24");
245
290
  svg.setAttribute("aria-hidden", "true");
246
291
  svg.setAttribute("focusable", "false");
@@ -250,6 +295,169 @@ function icon(name) {
250
295
  svg.append(path);
251
296
  return svg;
252
297
  }
298
+ // src/element/rich/a2ui-format.ts
299
+ var A2UI_VERSION = "v0.9.1";
300
+ var ACTION_FENCE_NAME = "a2ui-action";
301
+ var MESSAGE_KEYS = [
302
+ "createSurface",
303
+ "updateComponents",
304
+ "updateDataModel",
305
+ "deleteSurface"
306
+ ];
307
+ function isMessage(item) {
308
+ if (!isRecord(item) || typeof item.version !== "string") return false;
309
+ const keys = MESSAGE_KEYS.filter((key) => key in item);
310
+ if (keys.length !== 1) return false;
311
+ const body = item[keys[0]];
312
+ return isRecord(body) && typeof body.surfaceId === "string" && body.surfaceId !== "";
313
+ }
314
+ /** The content of a ```a2ui fence as its message list, or null when it is not
315
+ * one (not JSON, not a non-empty array, an item that is not a message). */
316
+ function parseA2uiMessages(code) {
317
+ let data;
318
+ try {
319
+ data = JSON.parse(code);
320
+ } catch {
321
+ return null;
322
+ }
323
+ if (!Array.isArray(data) || data.length === 0 || !data.every(isMessage)) return null;
324
+ return data;
325
+ }
326
+ /** The surfaces the messages create, once each, in order. */
327
+ function surfaceIdsOf(messages) {
328
+ const ids = [];
329
+ for (const message of messages) {
330
+ const created = message.createSurface;
331
+ if (isRecord(created) && typeof created.surfaceId === "string" && !ids.includes(created.surfaceId)) ids.push(created.surfaceId);
332
+ }
333
+ return ids;
334
+ }
335
+ /** The ```a2ui-action fence sent as the user's message at a click. */
336
+ function formatA2uiAction(action) {
337
+ const payload = {
338
+ name: action.name,
339
+ surfaceId: action.surfaceId,
340
+ sourceComponentId: action.sourceComponentId,
341
+ timestamp: action.timestamp || (/* @__PURE__ */ new Date()).toISOString(),
342
+ context: action.context
343
+ };
344
+ return `\`\`\`${ACTION_FENCE_NAME}\n${JSON.stringify([{
345
+ version: A2UI_VERSION,
346
+ action: payload
347
+ }])}\n\`\`\``;
348
+ }
349
+ var ACTION_FENCE = new RegExp(`^\`\`\`${ACTION_FENCE_NAME}[ \\t]*\\n([\\s\\S]*?)\\n\`\`\`$`);
350
+ /** The action a user message carries, when the message is a ```a2ui-action
351
+ * fence. */
352
+ function parseA2uiAction(content) {
353
+ const match = ACTION_FENCE.exec(content.replace(/\r\n/g, "\n").trim());
354
+ if (!match) return null;
355
+ let data;
356
+ try {
357
+ data = JSON.parse(match[1]);
358
+ } catch {
359
+ return null;
360
+ }
361
+ const first = Array.isArray(data) ? data[0] : data;
362
+ if (!isRecord(first) || !isRecord(first.action)) return null;
363
+ const action = first.action;
364
+ if (typeof action.name !== "string" || action.name === "" || typeof action.surfaceId !== "string" || action.surfaceId === "" || !isRecord(action.context)) return null;
365
+ return {
366
+ name: action.name,
367
+ surfaceId: action.surfaceId,
368
+ sourceComponentId: typeof action.sourceComponentId === "string" ? action.sourceComponentId : "",
369
+ timestamp: typeof action.timestamp === "string" ? action.timestamp : "",
370
+ context: action.context
371
+ };
372
+ }
373
+ /** A ```a2ui fence of an answer, as marked reads it: its content. */
374
+ var A2UI_FENCE = /(?:^|\n) {0,3}(`{3,})a2ui[ \t]*\n([\s\S]*?)\n {0,3}\1`*[ \t]*(?=\n|$)/g;
375
+ var created = /* @__PURE__ */ new WeakMap();
376
+ /** The surfaces the ```a2ui fences of `message` create. */
377
+ function surfacesOf(message) {
378
+ let ids = created.get(message);
379
+ if (!ids) {
380
+ ids = [];
381
+ for (const match of message.text.matchAll(A2UI_FENCE)) {
382
+ const messages = parseA2uiMessages(match[2]);
383
+ if (messages) ids.push(...surfaceIdsOf(messages));
384
+ }
385
+ created.set(message, ids);
386
+ }
387
+ return ids;
388
+ }
389
+ /** For each message, the surfaces of its interfaces the user answered later,
390
+ * each with the first answer: what they show as sent, and with which values.
391
+ * An answer (a ```a2ui-action user message) goes to the latest message
392
+ * before it that creates its surface: models reuse ids such as `form`, and a
393
+ * later form with the same id is another form. */
394
+ function answeredSurfaces(messages) {
395
+ const answered = messages.map(() => /* @__PURE__ */ new Map());
396
+ const creator = /* @__PURE__ */ new Map();
397
+ messages.forEach((message, index) => {
398
+ if (message.role === "assistant") {
399
+ for (const id of surfacesOf(message)) creator.set(id, index);
400
+ return;
401
+ }
402
+ if (message.role !== "user") return;
403
+ const action = parseA2uiAction(message.text);
404
+ const at = action ? creator.get(action.surfaceId) : void 0;
405
+ if (!action || at === void 0) return;
406
+ const sent = answered[at];
407
+ if (!sent.has(action.surfaceId)) sent.set(action.surfaceId, action);
408
+ });
409
+ return answered;
410
+ }
411
+ /** The messages that put back, in a form already sent, the values sent with
412
+ * `action`: for each entry of the button's `action.event.context` bound to an
413
+ * absolute path, an `updateDataModel` of that path with the value the action
414
+ * carries under the same key. Fields the button does not send stay as the
415
+ * block wrote them: they never left the browser. */
416
+ function sentValuesOf(messages, action) {
417
+ let source = null;
418
+ for (const message of messages) {
419
+ const update = message.updateComponents;
420
+ if (!isRecord(update) || update.surfaceId !== action.surfaceId || !Array.isArray(update.components)) continue;
421
+ for (const component of update.components) if (isRecord(component) && component.id === action.sourceComponentId) source = {
422
+ version: message.version,
423
+ component
424
+ };
425
+ }
426
+ const componentAction = source?.component.action;
427
+ const event = isRecord(componentAction) ? componentAction.event : void 0;
428
+ if (source === null || !isRecord(event) || !isRecord(event.context)) return [];
429
+ const restored = [];
430
+ for (const [key, binding] of Object.entries(event.context)) {
431
+ if (!isRecord(binding) || typeof binding.path !== "string" || !binding.path.startsWith("/") || !(key in action.context)) continue;
432
+ restored.push({
433
+ version: source.version,
434
+ updateDataModel: {
435
+ surfaceId: action.surfaceId,
436
+ path: binding.path,
437
+ value: action.context[key]
438
+ }
439
+ });
440
+ }
441
+ return restored;
442
+ }
443
+ function formatValue(value, yes, no) {
444
+ if (value === null || value === void 0) return "—";
445
+ if (typeof value === "boolean") return value ? yes : no;
446
+ if (Array.isArray(value)) return value.map((item) => formatValue(item, yes, no)).join(", ");
447
+ if (typeof value === "string") return value;
448
+ if (typeof value === "number" || typeof value === "bigint") return String(value);
449
+ if (typeof value === "function" || typeof value === "symbol") return "—";
450
+ return JSON.stringify(value);
451
+ }
452
+ /** What the user's message shows for an action: its name as words, and each
453
+ * value sent as text. */
454
+ function actionSummary(action, words) {
455
+ const name = action.name.replace(/_/g, " ").trim();
456
+ return {
457
+ label: name.charAt(0).toUpperCase() + name.slice(1),
458
+ fields: Object.entries(action.context).map(([key, value]) => [key, formatValue(value, words.yes, words.no)])
459
+ };
460
+ }
253
461
  // src/element/styles.ts
254
462
  var STYLES = `
255
463
  :host {
@@ -288,7 +496,7 @@ var STYLES = `
288
496
  :host([hidden]) { display: none; }
289
497
  *, *::before, *::after { box-sizing: border-box; }
290
498
  [hidden] { display: none !important; }
291
- svg { inline-size: 20px; block-size: 20px; flex: none; }
499
+ .icon { inline-size: 20px; block-size: 20px; flex: none; }
292
500
 
293
501
  button {
294
502
  font: inherit;
@@ -521,7 +729,9 @@ button:focus-visible, summary:focus-visible {
521
729
  .chip:not(:has(button)) { padding-inline-end: 10px; }
522
730
  .chip.error { border-color: var(--_danger); color: var(--_danger); }
523
731
  .chip .icon-button { inline-size: 22px; block-size: 22px; }
524
- .chip svg { inline-size: 16px; block-size: 16px; }
732
+ .chip .icon { inline-size: 16px; block-size: 16px; }
733
+ .action-summary { justify-content: flex-end; }
734
+ .chip.action { border-color: var(--_accent); background: var(--_accent); color: var(--_on-accent); font-weight: 600; }
525
735
 
526
736
  .message.assistant .answer { overflow-wrap: anywhere; }
527
737
  .note { margin: 0; color: var(--_muted); font-size: calc(var(--_fs) * 13 / 15); font-style: italic; }
@@ -599,6 +809,16 @@ button:focus-visible, summary:focus-visible {
599
809
  .markdown th, .markdown td { padding: 6px 10px; border: 1px solid var(--_border); text-align: start; }
600
810
  .markdown th { background: var(--_raised); }
601
811
  .markdown hr { border: 0; border-block-start: 1px solid var(--_border); }
812
+ .markdown .diagram, .markdown .chart {
813
+ display: flex;
814
+ justify-content: center;
815
+ overflow-x: auto;
816
+ margin-block: 0 0.75em;
817
+ padding: 20px;
818
+ border: 1px solid var(--_border);
819
+ border-radius: var(--_radius-sm);
820
+ background: var(--_bg);
821
+ }
602
822
 
603
823
  /* ---- composer ---------------------------------------------------------- */
604
824
 
@@ -693,7 +913,9 @@ var UPGRADED = [
693
913
  "agent",
694
914
  "tenant",
695
915
  "conversation",
696
- "developer"
916
+ "developer",
917
+ "copyAnswer",
918
+ "noDisclaimer"
697
919
  ];
698
920
  var Base = typeof HTMLElement === "undefined" ? class {} : HTMLElement;
699
921
  var sheet;
@@ -779,8 +1001,10 @@ function setRating(node, rating) {
779
1001
  *
780
1002
  * Attributes: `base-url` (AI-CORE origin), `agent`, `tenant` (the open
781
1003
  * workspace, sent as `X-Tenant`), `conversation` (to open), `lang` (`it`,
782
- * `en`; else the page's language), `developer` (requests, turn events, agent
783
- * version).
1004
+ * `en`; else the page's language). What the console's Prova chat does not
1005
+ * have is off unless the host sets its boolean attribute: `developer`
1006
+ * (requests, turn events, agent version), `copy-answer` (a copy button under
1007
+ * each answer); `no-disclaimer` hides the disclaimer, on by default.
784
1008
  * Properties: `getToken({ retry })`, `strings` (text overrides), `context`
785
1009
  * (the page's data, sent with every message), `state`.
786
1010
  * Events (bubbling, composed): `aicore-conversation`, `aicore-turn`,
@@ -793,7 +1017,9 @@ var AicoreAgentChat = class extends Base {
793
1017
  "tenant",
794
1018
  "conversation",
795
1019
  "lang",
796
- "developer"
1020
+ "developer",
1021
+ "copy-answer",
1022
+ "no-disclaimer"
797
1023
  ];
798
1024
  #getToken = null;
799
1025
  #overrides = null;
@@ -1059,6 +1285,21 @@ var AicoreAgentChat = class extends Base {
1059
1285
  set developer(value) {
1060
1286
  this.toggleAttribute("developer", Boolean(value));
1061
1287
  }
1288
+ /** A copy button under each answer (where the browser gives access to the
1289
+ * clipboard). Off by default: the console's Prova chat has none. */
1290
+ get copyAnswer() {
1291
+ return this.hasAttribute("copy-answer");
1292
+ }
1293
+ set copyAnswer(value) {
1294
+ this.toggleAttribute("copy-answer", Boolean(value));
1295
+ }
1296
+ /** Hides the disclaimer under the composer, shown by default. */
1297
+ get noDisclaimer() {
1298
+ return this.hasAttribute("no-disclaimer");
1299
+ }
1300
+ set noDisclaimer(value) {
1301
+ this.toggleAttribute("no-disclaimer", Boolean(value));
1302
+ }
1062
1303
  /** The chat's current state (read-only), or null until it is configured. */
1063
1304
  get state() {
1064
1305
  return this.#session?.state ?? null;
@@ -1313,7 +1554,7 @@ var AicoreAgentChat = class extends Base {
1313
1554
  const item = this.#session?.state.messages[Number(message)];
1314
1555
  const cited = item?.role === "assistant" ? item.sources[Number(source)] : void 0;
1315
1556
  if (!cited) return;
1316
- setMarkdown(body, cited.text ?? "");
1557
+ setMarkdown(body, cited.text ?? "", this.#rich(false));
1317
1558
  const url = safeUrl(cited.url);
1318
1559
  if (url) body.append(h("a", {
1319
1560
  text: url,
@@ -1333,6 +1574,35 @@ var AicoreAgentChat = class extends Base {
1333
1574
  session.send(text, { context: this.#context });
1334
1575
  this.#updateSend();
1335
1576
  }
1577
+ /** A click in an interface (A2UI) of an answer: its action, as the user's
1578
+ * next message, through the same door as the composer. */
1579
+ #sendAction(text) {
1580
+ const session = this.#session;
1581
+ if (!session || !this.#canSendAction()) return false;
1582
+ this.#stick = true;
1583
+ session.send(text, { context: this.#context });
1584
+ this.#updateSend();
1585
+ return true;
1586
+ }
1587
+ /** An interface's click can go: an agent, no turn running, and no file in
1588
+ * the composer, which the message would carry along. */
1589
+ #canSendAction() {
1590
+ const session = this.#session;
1591
+ const state = session?.state;
1592
+ return !!session && !!state?.agentId && !session.busy && state.uploading === 0 && state.files.length === 0;
1593
+ }
1594
+ /** What each message's interfaces can do: send while a click can go, and
1595
+ * show as sent the surfaces a later user message answered. */
1596
+ #interfaceStates(state) {
1597
+ const messages = state?.messages ?? [];
1598
+ const busy = this.#session?.busy ?? false;
1599
+ const send = this.#canSendAction() ? (text) => this.#sendAction(text) : void 0;
1600
+ return answeredSurfaces(messages).map((sent) => ({
1601
+ send,
1602
+ working: busy,
1603
+ sent
1604
+ }));
1605
+ }
1336
1606
  /** `lang` of the element, else of its closest ancestor, else of the page. */
1337
1607
  #lang() {
1338
1608
  return this.closest("[lang]")?.getAttribute("lang") ?? (typeof document === "undefined" ? null : document.documentElement.lang);
@@ -1340,6 +1610,21 @@ var AicoreAgentChat = class extends Base {
1340
1610
  #strings() {
1341
1611
  return stringsOf(this.#lang(), this.#overrides);
1342
1612
  }
1613
+ /** How markdown is drawn: formulas everywhere, and in an answer
1614
+ * (`widgets`) its diagrams, charts and interfaces. */
1615
+ #rich(widgets, live = false, state) {
1616
+ return {
1617
+ host: this,
1618
+ widgets,
1619
+ live,
1620
+ lang: languageOf(this.#lang()),
1621
+ strings: this.#strings(),
1622
+ interface: state ?? {
1623
+ working: live,
1624
+ sent: /* @__PURE__ */ new Map()
1625
+ }
1626
+ };
1627
+ }
1343
1628
  #scheduleRender(full = false) {
1344
1629
  if (full) this.#full = true;
1345
1630
  if (this.#frame) return;
@@ -1366,6 +1651,13 @@ var AicoreAgentChat = class extends Base {
1366
1651
  if (changed("agent", "agentId")) this.#renderHeader(t, state);
1367
1652
  if (changed("error")) this.#renderBanner(t, state);
1368
1653
  if (changed("messages", "loadingHistory", "agent")) this.#renderMessages(t, state, prev === null || changed("agent"));
1654
+ if (busyChanged || changed("messages", "files", "uploading", "agentId")) {
1655
+ const states = this.#interfaceStates(state);
1656
+ this.#messageNodes.forEach(({ node }, i) => {
1657
+ const current = states[i];
1658
+ if (current) updateInterfaces(node, current);
1659
+ });
1660
+ }
1369
1661
  this.#renderLive(t, state, prev === null);
1370
1662
  this.#renderEmpty(t, state);
1371
1663
  if (busyChanged || changed("files", "agentId")) this.#renderComposer(t, state, busy);
@@ -1395,6 +1687,7 @@ var AicoreAgentChat = class extends Base {
1395
1687
  ui.input.placeholder = t.placeholder;
1396
1688
  ui.input.setAttribute("aria-label", t.placeholder);
1397
1689
  ui.footnote.textContent = t.disclaimer;
1690
+ ui.footnote.hidden = !t.disclaimer || this.hasAttribute("no-disclaimer");
1398
1691
  ui.loading.textContent = t.loadingHistory;
1399
1692
  ui.developerSummary.textContent = t.developer;
1400
1693
  }
@@ -1488,6 +1781,7 @@ var AicoreAgentChat = class extends Base {
1488
1781
  ui.loading.hidden = !loading;
1489
1782
  const list = loading ? [] : state?.messages ?? [];
1490
1783
  const agentName = state?.agent?.name ?? t.agent;
1784
+ const interfaces = this.#interfaceStates(state);
1491
1785
  const nodes = list.map((message, index) => {
1492
1786
  const cached = rebuild ? void 0 : this.#messageNodes[index];
1493
1787
  if (cached?.message === message) return cached;
@@ -1500,29 +1794,48 @@ var AicoreAgentChat = class extends Base {
1500
1794
  }
1501
1795
  return {
1502
1796
  message,
1503
- node: message.role === "user" ? this.#userMessage(t, message) : this.#assistantMessage(t, message, index, agentName)
1797
+ node: message.role === "user" ? this.#userMessage(t, message) : this.#assistantMessage(t, message, index, agentName, interfaces[index])
1504
1798
  };
1505
1799
  });
1800
+ const kept = new Set(nodes.map(({ node }) => node));
1801
+ for (const { node } of this.#messageNodes) if (!kept.has(node)) disposeDrawings(node);
1506
1802
  this.#messageNodes = nodes;
1507
1803
  const shown = ui.messages.children;
1508
1804
  if (nodes.length !== shown.length || nodes.some(({ node }, i) => node !== shown[i])) ui.messages.replaceChildren(...nodes.map(({ node }) => node));
1509
1805
  }
1806
+ /** A user message's text; one that answered an interface reads as what
1807
+ * it sent (the action, and each value), never as its JSON. */
1808
+ #userText(t, text) {
1809
+ const action = parseA2uiAction(text);
1810
+ if (!action) return h("div", {
1811
+ class: "bubble",
1812
+ text
1813
+ });
1814
+ const { label, fields } = actionSummary(action, t);
1815
+ return h("ul", {
1816
+ class: "chips action-summary",
1817
+ attrs: { "aria-label": t.a2uiAction(label) }
1818
+ }, h("li", { class: "chip action" }, icon("check"), h("span", {
1819
+ class: "chip-label",
1820
+ text: label
1821
+ })), ...fields.map(([key, value]) => h("li", { class: "chip" }, h("span", { class: "chip-label" }, h("span", {
1822
+ class: "muted",
1823
+ text: `${key}: `
1824
+ }), value))));
1825
+ }
1510
1826
  #userMessage(t, message) {
1511
1827
  return h("article", {
1512
1828
  class: "message user",
1513
1829
  part: "message message-user",
1514
1830
  attrs: { "aria-label": t.you }
1515
- }, h("div", {
1516
- class: "bubble",
1517
- text: message.text
1518
- }), message.attachments.length > 0 && h("ul", { class: "chips" }, ...message.attachments.map((a) => h("li", { class: "chip" }, h("span", {
1831
+ }, this.#userText(t, message.text), message.attachments.length > 0 && h("ul", { class: "chips" }, ...message.attachments.map((a) => h("li", { class: "chip" }, h("span", {
1519
1832
  class: "chip-label",
1520
1833
  text: a.name
1521
1834
  })))));
1522
1835
  }
1523
- #assistantMessage(t, message, index, agentName) {
1836
+ #assistantMessage(t, message, index, agentName, state) {
1524
1837
  const answer = h("div", { class: "answer markdown" });
1525
- setMarkdown(answer, message.text);
1838
+ setMarkdown(answer, message.text, this.#rich(true, false, state));
1526
1839
  const article = h("article", {
1527
1840
  class: "message assistant",
1528
1841
  part: "message message-assistant",
@@ -1540,7 +1853,7 @@ var AicoreAgentChat = class extends Base {
1540
1853
  })
1541
1854
  }));
1542
1855
  if (message.sources.length > 0) article.append(this.#sources(t, message.sources, index));
1543
- const actions = h("div", { class: "actions" }, message.text && canCopy() && iconButton("copy", t.copy, {
1856
+ const actions = h("div", { class: "actions" }, message.text && this.hasAttribute("copy-answer") && canCopy() && iconButton("copy", t.copy, {
1544
1857
  "data-action": "copy",
1545
1858
  "data-index": String(index)
1546
1859
  }));
@@ -1584,6 +1897,7 @@ var AicoreAgentChat = class extends Base {
1584
1897
  ui.live.hidden = turn === null;
1585
1898
  if (!turn) {
1586
1899
  this.#liveTurn = null;
1900
+ disposeDrawings(ui.liveAnswer);
1587
1901
  ui.liveAnswer.replaceChildren();
1588
1902
  return;
1589
1903
  }
@@ -1604,7 +1918,7 @@ var AicoreAgentChat = class extends Base {
1604
1918
  if (!textChanged) return;
1605
1919
  this.#liveAt = performance.now();
1606
1920
  ui.liveAnswer.hidden = !turn.text;
1607
- setMarkdown(ui.liveAnswer, turn.text);
1921
+ setMarkdown(ui.liveAnswer, turn.text, this.#rich(true, true));
1608
1922
  }
1609
1923
  #renderEmpty(t, state) {
1610
1924
  const ui = this.#ui;
@@ -1690,6 +2004,6 @@ function defineAicoreAgentChat(tag = AICORE_AGENT_CHAT_TAG) {
1690
2004
  if (typeof customElements === "undefined" || customElements.get(tag)) return;
1691
2005
  customElements.define(tag, tag === "aicore-agent-chat" ? AicoreAgentChat : class extends AicoreAgentChat {});
1692
2006
  }
1693
- export { AicoreAgentChat as n, defineAicoreAgentChat as r, AICORE_AGENT_CHAT_TAG as t };
2007
+ export { parseA2uiMessages as a, setMarkdown as c, formatA2uiAction as i, AicoreAgentChat as n, sentValuesOf as o, defineAicoreAgentChat as r, surfaceIdsOf as s, AICORE_AGENT_CHAT_TAG as t };
1694
2008
 
1695
- //# sourceMappingURL=src-DPfU5Bd2.js.map
2009
+ //# sourceMappingURL=src-Blgo9nVC.js.map