@maggioli-rd/aicore-agent-chat 1.2.0 → 2.0.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 (146) hide show
  1. package/README.md +36 -18
  2. package/dist/aicore-agent-chat.js +164 -53
  3. package/dist/aicore-agent-chat.js.map +1 -1
  4. package/dist/bundle/a2ui-C-LAbJcp.js +87 -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/backstage-Bfl3Tyo5.js +86 -0
  9. package/dist/bundle/blockDiagram-APKKGZFW-bG_MVPzT.js +140 -0
  10. package/dist/bundle/bpmnIcons-APHXDYXF-C0jbCElo.js +1 -0
  11. package/dist/bundle/c4Diagram-KJ2TOQU5-BVad-wQe.js +38 -0
  12. package/dist/bundle/chunk-2Q5K7J3B-C1jixKkw.js +1 -0
  13. package/dist/bundle/chunk-5VM5RSS4-CwNG0iBi.js +15 -0
  14. package/dist/bundle/chunk-6MUBBAK2-CeH4cZO-.js +2 -0
  15. package/dist/bundle/chunk-AXFCVDMN-D0Vqm50X.js +62 -0
  16. package/dist/bundle/chunk-BG4553SI-DUBI9JbR.js +127 -0
  17. package/dist/bundle/chunk-DQASFODM-DBWVlIjs.js +10 -0
  18. package/dist/bundle/chunk-DUW6YSOI-ChybIQ82.js +1 -0
  19. package/dist/bundle/chunk-HFQBQIA3-D2xPptW8.js +1 -0
  20. package/dist/bundle/chunk-J5ZVWO5B-DHB__t6z.js +1 -0
  21. package/dist/bundle/chunk-JWPE2WC7-DVXcaiue.js +1 -0
  22. package/dist/bundle/chunk-KQLB2F66-BRGnyo9e.js +1 -0
  23. package/dist/bundle/chunk-KS47KZWR-DV3Gxewa.js +1 -0
  24. package/dist/bundle/chunk-LEVMRMFU-BdDTT4pw.js +1 -0
  25. package/dist/bundle/chunk-M57EVK23-BRqFqW5o.js +1 -0
  26. package/dist/bundle/chunk-NGNAAXSQ-DreF1ykJ.js +214 -0
  27. package/dist/bundle/chunk-OY52VR5R-BamrP8d_.js +88 -0
  28. package/dist/bundle/chunk-QB3YPZ4I-BqUUL29j.js +213 -0
  29. package/dist/bundle/chunk-R3KSYZAL-gmtEjdKU.js +1 -0
  30. package/dist/bundle/chunk-STOXU5M4-DdqxXfKq.js +72 -0
  31. package/dist/bundle/chunk-TU62E6Q5-B4GgWjUW.js +1 -0
  32. package/dist/bundle/chunk-X4PVCEUW-BcN5Aq5G.js +1 -0
  33. package/dist/bundle/chunk-XXDRQBXY-BIvjAdC_.js +1 -0
  34. package/dist/bundle/chunk-Y2CYZVJY-DsF7k-Jl.js +1 -0
  35. package/dist/bundle/classDiagram-v2-L25IHNXF-Dw7so3mk.js +217 -0
  36. package/dist/bundle/cose-bilkent-JH36ORCC-DUvnuVrm.js +1 -0
  37. package/dist/bundle/cynefin-EF2NZ3EQ-CcVPiRLN.js +1 -0
  38. package/dist/bundle/cynefinDiagram-L36ESFBY-eO6Z3Kvn.js +62 -0
  39. package/dist/bundle/cytoscape.esm-CsT4DLSP.js +321 -0
  40. package/dist/bundle/d3-hierarchy-i5r04UUG.js +1 -0
  41. package/dist/bundle/d3-scale-BEO6F4Sh.js +1 -0
  42. package/dist/bundle/d3-scale-chromatic-DhHjp77O.js +1 -0
  43. package/dist/bundle/d3-selection-CBFxn8wf.js +1 -0
  44. package/dist/bundle/d3-shape-v1Y4qR5e.js +1 -0
  45. package/dist/bundle/dagre-SPEB5RXH-ByBZqBaT.js +4 -0
  46. package/dist/bundle/diagram-3B7GL73J-BkQkIpxz.js +200 -0
  47. package/dist/bundle/diagram-DNEMPZML-DYthXzRv.js +24 -0
  48. package/dist/bundle/diagram-L3MUGCDN-D4DIzfHH.js +41 -0
  49. package/dist/bundle/diagram-LA4NIPWU-C2P-hZD1.js +24 -0
  50. package/dist/bundle/diagram-MHCOC4E2-BwauFnTV.js +3 -0
  51. package/dist/bundle/diagram-XPFHEONP-DC_v3Llc.js +30 -0
  52. package/dist/bundle/dist-CwuaKeLF.js +1 -0
  53. package/dist/bundle/ebnfDiagram-UZSYDL2S-CmwGlC8L.js +1 -0
  54. package/dist/bundle/elk-XV6XMXQE-CTlty3p3.js +27 -0
  55. package/dist/bundle/erDiagram-EYBAPDEH-Bu6phvJH.js +99 -0
  56. package/dist/bundle/eventmodeling-K75KTNOO-B1q0nOJE.js +1 -0
  57. package/dist/bundle/flowDiagram-MALGAFMO-D9D_AzXh.js +1 -0
  58. package/dist/bundle/ganttDiagram-23REXITY-COK7rxO4.js +292 -0
  59. package/dist/bundle/gitGraph-VSP46ZUC-DS7S_jKI.js +1 -0
  60. package/dist/bundle/gitGraphDiagram-STJD7YCW-DhVK8Hqh.js +106 -0
  61. package/dist/bundle/graphlib-Bgy7WbC7.js +1 -0
  62. package/dist/bundle/info-OHQRW6UA-BjEWvFlW.js +1 -0
  63. package/dist/bundle/infoDiagram-KBXO4MBG-Dg3zWdHP.js +2 -0
  64. package/dist/bundle/ishikawaDiagram-M35NCXHK-C2g8ghrV.js +70 -0
  65. package/dist/bundle/journeyDiagram-OPLOXDXO-DMZkL-i1.js +139 -0
  66. package/dist/bundle/kanban-definition-BZKZHSQY-Dr43IiJD.js +89 -0
  67. package/dist/bundle/katex-rAoShGnF.js +257 -0
  68. package/dist/bundle/math-Cx-Q-b8s.js +262 -0
  69. package/dist/bundle/mermaid-DaDuEHir.js +43 -0
  70. package/dist/bundle/mermaid-parser.core-Bv_Zx_ZE.js +6 -0
  71. package/dist/bundle/mindmap-definition-I2QAS2VK-BXCWJ_1R.js +98 -0
  72. package/dist/bundle/packet-JDAUHWVQ-CgB2qE5t.js +1 -0
  73. package/dist/bundle/pegDiagram-FD4XPPHP-CR58gOgF.js +1 -0
  74. package/dist/bundle/pie-XZMESJXO-CvXWTfIG.js +1 -0
  75. package/dist/bundle/pieDiagram-J4AKIIQI-D0GhbNJg.js +39 -0
  76. package/dist/bundle/quadrantDiagram-XTYBLID2-BKBEdwvC.js +7 -0
  77. package/dist/bundle/radar-ABXABTNO-8V_xx_AB.js +1 -0
  78. package/dist/bundle/railroad-I3PHUGI6-Bvb0GUva.js +1 -0
  79. package/dist/bundle/railroad-abnf-LNEFI6M7-D8xGcObq.js +1 -0
  80. package/dist/bundle/railroad-ebnf-DWYD2UWJ-Ch8wBawI.js +1 -0
  81. package/dist/bundle/railroad-peg-JR7BVNR7-CGndbjed.js +1 -0
  82. package/dist/bundle/railroadDiagram-MRQ6NCDL-DvqHkO2C.js +1 -0
  83. package/dist/bundle/requirementDiagram-Y7LWUY3S-bCLAM9sl.js +84 -0
  84. package/dist/bundle/rolldown-runtime-BNaE-Ejt.js +1 -0
  85. package/dist/bundle/rough.esm-Dy-Kn_BL.js +1 -0
  86. package/dist/bundle/sankeyDiagram-WGJFYUXA-8ehuPvHQ.js +40 -0
  87. package/dist/bundle/sequenceDiagram-5NDRBG5M-Cdg1YzMw.js +169 -0
  88. package/dist/bundle/sizeCapture-INFHLROL-Ct7XApxm.js +1 -0
  89. package/dist/bundle/stateDiagram-v2-FJ4FJNEA-B69v2YYC.js +291 -0
  90. package/dist/bundle/swimlanes-UMQ2AFYF-C_qI6rnK.js +1 -0
  91. package/dist/bundle/swimlanesDiagram-OMPLPG4O-CS11qSCX.js +8 -0
  92. package/dist/bundle/timeline-definition-SEUHKTQE-BCU0-H8D.js +120 -0
  93. package/dist/bundle/treeView-D4JQ5SDB-CpjURS-c.js +1 -0
  94. package/dist/bundle/treemap-SAJKECNS-CFFTaiIN.js +1 -0
  95. package/dist/bundle/usecaseDiagram-AFA6YXN4-46V1jsea.js +476 -0
  96. package/dist/bundle/vega-eBn1AexV.js +33 -0
  97. package/dist/bundle/vennDiagram-NNMJR3RB-q4Q4x2Q6.js +34 -0
  98. package/dist/bundle/wardley-7MLQ67FV-DhnATL7b.js +1 -0
  99. package/dist/bundle/wardleyDiagram-S7YFUSEH-BHIufnZW.js +78 -0
  100. package/dist/bundle/xychartDiagram-GGNKY7IX-CxAjpN3O.js +7 -0
  101. package/dist/chunks/a2ui-Da_YceSP.js +961 -0
  102. package/dist/chunks/a2ui-Da_YceSP.js.map +1 -0
  103. package/dist/chunks/backstage-TkKENlNl.js +1008 -0
  104. package/dist/chunks/backstage-TkKENlNl.js.map +1 -0
  105. package/dist/chunks/{core-Db3hnKpM.js → core-4PRAI1Mt.js} +60 -5
  106. package/dist/chunks/core-4PRAI1Mt.js.map +1 -0
  107. package/dist/chunks/math-D5IXRTov.js +86 -0
  108. package/dist/chunks/math-D5IXRTov.js.map +1 -0
  109. package/dist/chunks/mermaid-j9RNkOnL.js +197 -0
  110. package/dist/chunks/mermaid-j9RNkOnL.js.map +1 -0
  111. package/dist/chunks/rich-CdNA4NuG.js +156 -0
  112. package/dist/chunks/rich-CdNA4NuG.js.map +1 -0
  113. package/dist/chunks/sanitize-COLQzplk.js +240 -0
  114. package/dist/chunks/sanitize-COLQzplk.js.map +1 -0
  115. package/dist/chunks/{src-CYXMXds2.js → src-PkQozp4M.js} +725 -146
  116. package/dist/chunks/src-PkQozp4M.js.map +1 -0
  117. package/dist/chunks/vega-B07F6TI4.js +301 -0
  118. package/dist/chunks/vega-B07F6TI4.js.map +1 -0
  119. package/dist/core.js +1 -1
  120. package/dist/define.js +3 -3
  121. package/dist/index.js +3 -3
  122. package/dist/types/core/session.d.ts +31 -0
  123. package/dist/types/element/backstage/index.d.ts +10 -0
  124. package/dist/types/element/backstage/log.d.ts +13 -0
  125. package/dist/types/element/backstage/map.d.ts +12 -0
  126. package/dist/types/element/backstage/timing.d.ts +51 -0
  127. package/dist/types/element/i18n.d.ts +69 -6
  128. package/dist/types/element/icons.d.ts +3 -0
  129. package/dist/types/element/index.d.ts +15 -5
  130. package/dist/types/element/markdown.d.ts +6 -3
  131. package/dist/types/element/rich/a2ui-format.d.ts +45 -0
  132. package/dist/types/element/rich/a2ui-icons.d.ts +1 -0
  133. package/dist/types/element/rich/a2ui-views.d.ts +37 -0
  134. package/dist/types/element/rich/a2ui.d.ts +2 -0
  135. package/dist/types/element/rich/index.d.ts +72 -0
  136. package/dist/types/element/rich/math.d.ts +4 -0
  137. package/dist/types/element/rich/mermaid.d.ts +2 -0
  138. package/dist/types/element/rich/vega.d.ts +2 -0
  139. package/dist/types/element/sanitize.d.ts +34 -0
  140. package/dist/types/element/styles.d.ts +1 -1
  141. package/dist/types/element/team.d.ts +14 -0
  142. package/dist/types/index.d.ts +1 -0
  143. package/dist/types/jsx.d.ts +1 -1
  144. package/package.json +9 -3
  145. package/dist/chunks/core-Db3hnKpM.js.map +0 -1
  146. package/dist/chunks/src-CYXMXds2.js.map +0 -1
@@ -1,5 +1,6 @@
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";
1
+ import { E as isRecord, m as turnErrorText, n as CHAT_CHANGE, s as AICORE_EVENTS, t as AicoreChatSession } from "./core-4PRAI1Mt.js";
2
+ import { a as keepDrawings, o as lazy, r as enhance, s as updateInterfaces, t as disposeDrawings } from "./rich-CdNA4NuG.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
  "'": "'"
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 = {
@@ -86,8 +106,6 @@ var it = {
86
106
  deleteConversation: (title) => `Elimina «${title}»`,
87
107
  confirmDelete: (title) => `Eliminare la conversazione «${title}»?`,
88
108
  confirmDeleteShort: "Elimina?",
89
- ask: (agent) => `Chiedi a ${agent}`,
90
- askGeneric: "Come posso esserti utile?",
91
109
  noAgent: "Nessun agente indicato.",
92
110
  notConnected: "Chat non configurata.",
93
111
  placeholder: "Scrivi un messaggio",
@@ -110,7 +128,6 @@ var it = {
110
128
  interrupted: "Risposta interrotta.",
111
129
  turnFailed: "L'agente non è riuscito a rispondere.",
112
130
  trace: (id) => `Traccia ${id}`,
113
- disclaimer: "Le risposte sono generate da un'intelligenza artificiale e possono contenere errori: verifica sempre le informazioni.",
114
131
  dismiss: "Chiudi",
115
132
  you: "Tu",
116
133
  agent: "Agente",
@@ -128,14 +145,77 @@ var it = {
128
145
  retryIn: (seconds) => `Riprova tra ${seconds} s.`,
129
146
  developer: "Sviluppatore",
130
147
  requests: "Richieste",
131
- events: (tokens) => `Eventi dell'ultimo turno · ${tokens} token`,
132
148
  lastError: "Ultimo errore",
133
149
  renewed: "token rinnovato",
134
150
  publishedVersion: "Versione pubblicata",
135
151
  notPublished: "non pubblicato",
136
152
  conversation: "Conversazione",
137
153
  context: "Contesto del turno",
138
- none: "—"
154
+ none: "—",
155
+ a2uiPreparing: "Preparazione del modulo…",
156
+ a2uiRefused: (reason) => `Interfaccia non disegnata: ${reason}`,
157
+ a2uiInvalid: "il blocco non rispetta il catalogo",
158
+ a2uiSent: "Inviato",
159
+ a2uiDetails: "Dettagli",
160
+ a2uiTabs: "Schede",
161
+ close: "Chiudi",
162
+ a2uiAction: (action) => `Azione ${action}`,
163
+ yes: "sì",
164
+ no: "no",
165
+ backstage: "Dietro le quinte",
166
+ backstageToggle: "Mostra o nascondi Dietro le quinte",
167
+ backstageLog: "Registro",
168
+ backstageMap: "Mappa",
169
+ backstageViews: "Vista di Dietro le quinte",
170
+ noEvents: "Nessun evento: compaiono dopo il primo messaggio.",
171
+ turnHeader: (turn, time) => `Turno ${turn} · ${time}`,
172
+ modelWait: "in attesa del modello",
173
+ turnDone: (duration) => `Turno concluso in ${duration}`,
174
+ turnStopped: (duration) => `Turno interrotto dopo ${duration}`,
175
+ turnCanceled: "Turno interrotto",
176
+ tools: "Strumenti",
177
+ modelTime: "Attesa del modello",
178
+ modelCalls: "Chiamate al modello",
179
+ answerTime: "Risposta",
180
+ inputTokens: "Token in ingresso",
181
+ outputTokens: "Token in uscita",
182
+ fromCache: (count) => `${count} dalla cache`,
183
+ mainAgent: "Agente principale",
184
+ limitReached: (limit) => `Limite raggiunto: ${limit}`,
185
+ limitNames: {
186
+ iterazioni: "iterazioni",
187
+ timeout: "tempo",
188
+ deleghe: "deleghe"
189
+ },
190
+ limitHint: "Puoi alzarlo in Configurazione › Limiti per risposta.",
191
+ calls: "chiama",
192
+ answers: "risponde a",
193
+ expand: "Espandi",
194
+ collapse: "Comprimi",
195
+ memberKinds: {
196
+ orchestrator: "Agente principale",
197
+ subagent: "Sottoagente",
198
+ platform_agent: "Agente pubblicato",
199
+ external_a2a: "Agente esterno A2A",
200
+ extra: "Non nella versione mostrata"
201
+ },
202
+ noTurn: "Nessun turno: la mappa si accende al primo messaggio.",
203
+ turnRunning: (turn, clock) => `Turno ${turn} · ${clock}`,
204
+ turnEnded: (turn) => `Turno ${turn} · concluso`,
205
+ turnInterrupted: (turn) => `Turno ${turn} · interrotto`,
206
+ teamAtWork: (used, total) => `${used} ${used === 1 ? "membro" : "membri"} su ${total} al lavoro`,
207
+ delegations: (count) => `${count} ${count === 1 ? "delega" : "deleghe"}`,
208
+ toolCalls: (count) => `${count} ${count === 1 ? "chiamata" : "chiamate"} a strumenti`,
209
+ statusFailed: "Turno interrotto",
210
+ statusWaiting: (names) => `Attende ${names}`,
211
+ statusTool: (names) => `Usa ${names}`,
212
+ statusExternal: "Al lavoro, all’esterno",
213
+ statusWriting: "Scrive la risposta",
214
+ statusThinking: "Ragiona",
215
+ statusDoneOnce: (duration) => `Fatto in ${duration}`,
216
+ statusDoneTimes: (times, duration) => `Fatto ${times} volte · ${duration}`,
217
+ statusUnused: "Non usato in questo turno",
218
+ and: "e"
139
219
  };
140
220
  var en = {
141
221
  locale: "en-GB",
@@ -153,8 +233,6 @@ var en = {
153
233
  deleteConversation: (title) => `Delete “${title}”`,
154
234
  confirmDelete: (title) => `Delete the conversation “${title}”?`,
155
235
  confirmDeleteShort: "Delete?",
156
- ask: (agent) => `Ask ${agent}`,
157
- askGeneric: "How can I help?",
158
236
  noAgent: "No agent set.",
159
237
  notConnected: "Chat not configured.",
160
238
  placeholder: "Write a message",
@@ -177,7 +255,6 @@ var en = {
177
255
  interrupted: "Answer stopped.",
178
256
  turnFailed: "The agent could not answer.",
179
257
  trace: (id) => `Trace ${id}`,
180
- disclaimer: "Answers are generated by AI and may contain mistakes: always check the information.",
181
258
  dismiss: "Dismiss",
182
259
  you: "You",
183
260
  agent: "Agent",
@@ -195,20 +272,87 @@ var en = {
195
272
  retryIn: (seconds) => `Try again in ${seconds} s.`,
196
273
  developer: "Developer",
197
274
  requests: "Requests",
198
- events: (tokens) => `Events of the last turn · ${tokens} tokens`,
199
275
  lastError: "Last error",
200
276
  renewed: "token renewed",
201
277
  publishedVersion: "Published version",
202
278
  notPublished: "not published",
203
279
  conversation: "Conversation",
204
280
  context: "Turn context",
205
- none: "—"
281
+ none: "—",
282
+ a2uiPreparing: "Preparing the form…",
283
+ a2uiRefused: (reason) => `Interface not drawn: ${reason}`,
284
+ a2uiInvalid: "the block does not follow the catalog",
285
+ a2uiSent: "Sent",
286
+ a2uiDetails: "Details",
287
+ a2uiTabs: "Tabs",
288
+ close: "Close",
289
+ a2uiAction: (action) => `Action ${action}`,
290
+ yes: "yes",
291
+ no: "no",
292
+ backstage: "Behind the scenes",
293
+ backstageToggle: "Show or hide Behind the scenes",
294
+ backstageLog: "Log",
295
+ backstageMap: "Map",
296
+ backstageViews: "Behind the scenes view",
297
+ noEvents: "No events: they appear after the first message.",
298
+ turnHeader: (turn, time) => `Turn ${turn} · ${time}`,
299
+ modelWait: "waiting for the model",
300
+ turnDone: (duration) => `Turn ended in ${duration}`,
301
+ turnStopped: (duration) => `Turn stopped after ${duration}`,
302
+ turnCanceled: "Turn stopped",
303
+ tools: "Tools",
304
+ modelTime: "Waiting for the model",
305
+ modelCalls: "Model calls",
306
+ answerTime: "Answer",
307
+ inputTokens: "Input tokens",
308
+ outputTokens: "Output tokens",
309
+ fromCache: (count) => `${count} from cache`,
310
+ mainAgent: "Main agent",
311
+ limitReached: (limit) => `Limit reached: ${limit}`,
312
+ limitNames: {
313
+ iterazioni: "iterations",
314
+ timeout: "time",
315
+ deleghe: "delegations"
316
+ },
317
+ limitHint: "You can raise it in Configuration › Limits per answer.",
318
+ calls: "calls",
319
+ answers: "answers",
320
+ expand: "Expand",
321
+ collapse: "Collapse",
322
+ memberKinds: {
323
+ orchestrator: "Main agent",
324
+ subagent: "Subagent",
325
+ platform_agent: "Published agent",
326
+ external_a2a: "External A2A agent",
327
+ extra: "Not in the version shown"
328
+ },
329
+ noTurn: "No turn: the map lights up at the first message.",
330
+ turnRunning: (turn, clock) => `Turn ${turn} · ${clock}`,
331
+ turnEnded: (turn) => `Turn ${turn} · ended`,
332
+ turnInterrupted: (turn) => `Turn ${turn} · stopped`,
333
+ teamAtWork: (used, total) => `${used} of ${total} ${total === 1 ? "member" : "members"} at work`,
334
+ delegations: (count) => `${count} ${count === 1 ? "delegation" : "delegations"}`,
335
+ toolCalls: (count) => `${count} tool ${count === 1 ? "call" : "calls"}`,
336
+ statusFailed: "Turn stopped",
337
+ statusWaiting: (names) => `Waiting for ${names}`,
338
+ statusTool: (names) => `Using ${names}`,
339
+ statusExternal: "At work, outside",
340
+ statusWriting: "Writing the answer",
341
+ statusThinking: "Thinking",
342
+ statusDoneOnce: (duration) => `Done in ${duration}`,
343
+ statusDoneTimes: (times, duration) => `Done ${times} times · ${duration}`,
344
+ statusUnused: "Not used in this turn",
345
+ and: "and"
206
346
  };
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) {
347
+ /** The language the element speaks for `lang`: Italian for `it…` or no
348
+ * language at all, English for any other language. */
349
+ function languageOf(lang) {
210
350
  const tag = lang?.trim().toLowerCase() ?? "";
211
- return tag === "" || tag.startsWith("it") ? it : en;
351
+ return tag === "" || tag.startsWith("it") ? "it" : "en";
352
+ }
353
+ /** The built-in texts for `lang` (see `languageOf`). */
354
+ function baseStringsOf(lang) {
355
+ return languageOf(lang) === "it" ? it : en;
212
356
  }
213
357
  /** The texts for `lang`, with the host's overrides on top. */
214
358
  function stringsOf(lang, overrides) {
@@ -226,6 +370,8 @@ function stringsOf(lang, overrides) {
226
370
  // src/element/icons.ts
227
371
  var PATHS = {
228
372
  add: "M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z",
373
+ arrowUp: "M4 12l1.41 1.41L11 7.83V20h2V7.83l5.58 5.59L20 12l-8-8-8 8z",
374
+ sparkles: "M19 9l1.25-2.75L23 5l-2.75-1.25L19 1l-1.25 2.75L15 5l2.75 1.25L19 9zm-7.5.5L9 4 6.5 9.5 1 12l5.5 2.5L9 20l2.5-5.5L17 12l-5.5-2.5zM19 15l-1.25 2.75L15 19l2.75 1.25L19 23l1.25-2.75L23 19l-2.75-1.25L19 15z",
229
375
  delete: "M16 9v10H8V9h8m-1.5-6h-5l-1 1H5v2h14V4h-3.5l-1-1zM18 7H6v12c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7z",
230
376
  send: "M2.01 21 23 12 2.01 3 2 10l15 2-15 2z",
231
377
  stop: "M6 6h12v12H6z",
@@ -236,11 +382,13 @@ var PATHS = {
236
382
  thumbDown: "M15 3H6c-.83 0-1.54.5-1.84 1.22l-3.02 7.05c-.09.23-.14.47-.14.73v2c0 1.1.9 2 2 2h6.31l-.95 4.57-.03.32c0 .41.17.79.44 1.06L9.83 23l6.59-6.59c.36-.36.58-.86.58-1.41V5c0-1.1-.9-2-2-2zm0 12-4.34 4.34L12 14H3v-2l3-7h9v10zm4-12h4v12h-4z",
237
383
  close: "M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z",
238
384
  menu: "M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z",
385
+ panel: "M16 20H2V4h14v16zm2-12h4V4h-4v4zm0 12h4v-4h-4v4zm0-6h4v-4h-4v4z",
239
386
  edit: "M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z"
240
387
  };
241
388
  var SVG_NS = "http://www.w3.org/2000/svg";
242
389
  function icon(name) {
243
390
  const svg = document.createElementNS(SVG_NS, "svg");
391
+ svg.setAttribute("class", "icon");
244
392
  svg.setAttribute("viewBox", "0 0 24 24");
245
393
  svg.setAttribute("aria-hidden", "true");
246
394
  svg.setAttribute("focusable", "false");
@@ -250,6 +398,169 @@ function icon(name) {
250
398
  svg.append(path);
251
399
  return svg;
252
400
  }
401
+ // src/element/rich/a2ui-format.ts
402
+ var A2UI_VERSION = "v0.9.1";
403
+ var ACTION_FENCE_NAME = "a2ui-action";
404
+ var MESSAGE_KEYS = [
405
+ "createSurface",
406
+ "updateComponents",
407
+ "updateDataModel",
408
+ "deleteSurface"
409
+ ];
410
+ function isMessage(item) {
411
+ if (!isRecord(item) || typeof item.version !== "string") return false;
412
+ const keys = MESSAGE_KEYS.filter((key) => key in item);
413
+ if (keys.length !== 1) return false;
414
+ const body = item[keys[0]];
415
+ return isRecord(body) && typeof body.surfaceId === "string" && body.surfaceId !== "";
416
+ }
417
+ /** The content of a ```a2ui fence as its message list, or null when it is not
418
+ * one (not JSON, not a non-empty array, an item that is not a message). */
419
+ function parseA2uiMessages(code) {
420
+ let data;
421
+ try {
422
+ data = JSON.parse(code);
423
+ } catch {
424
+ return null;
425
+ }
426
+ if (!Array.isArray(data) || data.length === 0 || !data.every(isMessage)) return null;
427
+ return data;
428
+ }
429
+ /** The surfaces the messages create, once each, in order. */
430
+ function surfaceIdsOf(messages) {
431
+ const ids = [];
432
+ for (const message of messages) {
433
+ const created = message.createSurface;
434
+ if (isRecord(created) && typeof created.surfaceId === "string" && !ids.includes(created.surfaceId)) ids.push(created.surfaceId);
435
+ }
436
+ return ids;
437
+ }
438
+ /** The ```a2ui-action fence sent as the user's message at a click. */
439
+ function formatA2uiAction(action) {
440
+ const payload = {
441
+ name: action.name,
442
+ surfaceId: action.surfaceId,
443
+ sourceComponentId: action.sourceComponentId,
444
+ timestamp: action.timestamp || (/* @__PURE__ */ new Date()).toISOString(),
445
+ context: action.context
446
+ };
447
+ return `\`\`\`${ACTION_FENCE_NAME}\n${JSON.stringify([{
448
+ version: A2UI_VERSION,
449
+ action: payload
450
+ }])}\n\`\`\``;
451
+ }
452
+ var ACTION_FENCE = new RegExp(`^\`\`\`${ACTION_FENCE_NAME}[ \\t]*\\n([\\s\\S]*?)\\n\`\`\`$`);
453
+ /** The action a user message carries, when the message is a ```a2ui-action
454
+ * fence. */
455
+ function parseA2uiAction(content) {
456
+ const match = ACTION_FENCE.exec(content.replace(/\r\n/g, "\n").trim());
457
+ if (!match) return null;
458
+ let data;
459
+ try {
460
+ data = JSON.parse(match[1]);
461
+ } catch {
462
+ return null;
463
+ }
464
+ const first = Array.isArray(data) ? data[0] : data;
465
+ if (!isRecord(first) || !isRecord(first.action)) return null;
466
+ const action = first.action;
467
+ if (typeof action.name !== "string" || action.name === "" || typeof action.surfaceId !== "string" || action.surfaceId === "" || !isRecord(action.context)) return null;
468
+ return {
469
+ name: action.name,
470
+ surfaceId: action.surfaceId,
471
+ sourceComponentId: typeof action.sourceComponentId === "string" ? action.sourceComponentId : "",
472
+ timestamp: typeof action.timestamp === "string" ? action.timestamp : "",
473
+ context: action.context
474
+ };
475
+ }
476
+ /** A ```a2ui fence of an answer, as marked reads it: its content. */
477
+ var A2UI_FENCE = /(?:^|\n) {0,3}(`{3,})a2ui[ \t]*\n([\s\S]*?)\n {0,3}\1`*[ \t]*(?=\n|$)/g;
478
+ var created = /* @__PURE__ */ new WeakMap();
479
+ /** The surfaces the ```a2ui fences of `message` create. */
480
+ function surfacesOf(message) {
481
+ let ids = created.get(message);
482
+ if (!ids) {
483
+ ids = [];
484
+ for (const match of message.text.matchAll(A2UI_FENCE)) {
485
+ const messages = parseA2uiMessages(match[2]);
486
+ if (messages) ids.push(...surfaceIdsOf(messages));
487
+ }
488
+ created.set(message, ids);
489
+ }
490
+ return ids;
491
+ }
492
+ /** For each message, the surfaces of its interfaces the user answered later,
493
+ * each with the first answer: what they show as sent, and with which values.
494
+ * An answer (a ```a2ui-action user message) goes to the latest message
495
+ * before it that creates its surface: models reuse ids such as `form`, and a
496
+ * later form with the same id is another form. */
497
+ function answeredSurfaces(messages) {
498
+ const answered = messages.map(() => /* @__PURE__ */ new Map());
499
+ const creator = /* @__PURE__ */ new Map();
500
+ messages.forEach((message, index) => {
501
+ if (message.role === "assistant") {
502
+ for (const id of surfacesOf(message)) creator.set(id, index);
503
+ return;
504
+ }
505
+ if (message.role !== "user") return;
506
+ const action = parseA2uiAction(message.text);
507
+ const at = action ? creator.get(action.surfaceId) : void 0;
508
+ if (!action || at === void 0) return;
509
+ const sent = answered[at];
510
+ if (!sent.has(action.surfaceId)) sent.set(action.surfaceId, action);
511
+ });
512
+ return answered;
513
+ }
514
+ /** The messages that put back, in a form already sent, the values sent with
515
+ * `action`: for each entry of the button's `action.event.context` bound to an
516
+ * absolute path, an `updateDataModel` of that path with the value the action
517
+ * carries under the same key. Fields the button does not send stay as the
518
+ * block wrote them: they never left the browser. */
519
+ function sentValuesOf(messages, action) {
520
+ let source = null;
521
+ for (const message of messages) {
522
+ const update = message.updateComponents;
523
+ if (!isRecord(update) || update.surfaceId !== action.surfaceId || !Array.isArray(update.components)) continue;
524
+ for (const component of update.components) if (isRecord(component) && component.id === action.sourceComponentId) source = {
525
+ version: message.version,
526
+ component
527
+ };
528
+ }
529
+ const componentAction = source?.component.action;
530
+ const event = isRecord(componentAction) ? componentAction.event : void 0;
531
+ if (source === null || !isRecord(event) || !isRecord(event.context)) return [];
532
+ const restored = [];
533
+ for (const [key, binding] of Object.entries(event.context)) {
534
+ if (!isRecord(binding) || typeof binding.path !== "string" || !binding.path.startsWith("/") || !(key in action.context)) continue;
535
+ restored.push({
536
+ version: source.version,
537
+ updateDataModel: {
538
+ surfaceId: action.surfaceId,
539
+ path: binding.path,
540
+ value: action.context[key]
541
+ }
542
+ });
543
+ }
544
+ return restored;
545
+ }
546
+ function formatValue(value, yes, no) {
547
+ if (value === null || value === void 0) return "—";
548
+ if (typeof value === "boolean") return value ? yes : no;
549
+ if (Array.isArray(value)) return value.map((item) => formatValue(item, yes, no)).join(", ");
550
+ if (typeof value === "string") return value;
551
+ if (typeof value === "number" || typeof value === "bigint") return String(value);
552
+ if (typeof value === "function" || typeof value === "symbol") return "—";
553
+ return JSON.stringify(value);
554
+ }
555
+ /** What the user's message shows for an action: its name as words, and each
556
+ * value sent as text. */
557
+ function actionSummary(action, words) {
558
+ const name = action.name.replace(/_/g, " ").trim();
559
+ return {
560
+ label: name.charAt(0).toUpperCase() + name.slice(1),
561
+ fields: Object.entries(action.context).map(([key, value]) => [key, formatValue(value, words.yes, words.no)])
562
+ };
563
+ }
253
564
  // src/element/styles.ts
254
565
  var STYLES = `
255
566
  :host {
@@ -288,7 +599,7 @@ var STYLES = `
288
599
  :host([hidden]) { display: none; }
289
600
  *, *::before, *::after { box-sizing: border-box; }
290
601
  [hidden] { display: none !important; }
291
- svg { inline-size: 20px; block-size: 20px; flex: none; }
602
+ .icon { inline-size: 20px; block-size: 20px; flex: none; }
292
603
 
293
604
  button {
294
605
  font: inherit;
@@ -342,7 +653,7 @@ button:focus-visible, summary:focus-visible {
342
653
  min-block-size: 0;
343
654
  padding: 16px 12px;
344
655
  border-inline-end: 1px solid var(--_border);
345
- background: var(--_bg);
656
+ background: var(--_raised);
346
657
  }
347
658
  .main {
348
659
  display: flex;
@@ -367,6 +678,65 @@ button:focus-visible, summary:focus-visible {
367
678
  .rail-toggle { display: inline-flex; }
368
679
  }
369
680
 
681
+ /* «Dietro le quinte» (the backstage attribute): a third column on a wide host, floating
682
+ over the chat on a narrower one, as the rail does. */
683
+ .layout.backstage-open {
684
+ grid-template-columns: minmax(200px, 260px) minmax(0, 1fr) minmax(300px, 400px);
685
+ }
686
+ .backstage {
687
+ display: flex;
688
+ flex-direction: column;
689
+ min-block-size: 0;
690
+ border-inline-start: 1px solid var(--_border);
691
+ background: var(--_bg);
692
+ }
693
+ .backstage-header {
694
+ display: flex;
695
+ align-items: center;
696
+ gap: 8px;
697
+ min-block-size: 60px;
698
+ padding: 8px 12px 8px 20px;
699
+ border-block-end: 1px solid var(--_border);
700
+ }
701
+ .backstage-title { margin: 0; font-size: 1em; font-weight: 600; }
702
+ .backstage-views {
703
+ display: inline-flex;
704
+ gap: 2px;
705
+ padding: 3px;
706
+ border-radius: 999px;
707
+ background: var(--_raised);
708
+ }
709
+ .backstage-view {
710
+ padding: 4px 12px;
711
+ border-radius: 999px;
712
+ color: var(--_muted);
713
+ font-size: calc(var(--_fs) * 13 / 15);
714
+ font-weight: 600;
715
+ }
716
+ .backstage-view[aria-pressed="true"] {
717
+ background: var(--_bg);
718
+ color: var(--_fg);
719
+ box-shadow: 0 1px 2px rgb(0 0 0 / 0.08);
720
+ }
721
+ .backstage-header .icon-button { margin-inline-start: auto; }
722
+ .backstage-body { flex: 1; min-block-size: 0; overflow-y: auto; padding: 16px 20px; }
723
+ @container (max-width: 1100px) {
724
+ .layout.backstage-open {
725
+ grid-template-columns: minmax(200px, 260px) minmax(0, 1fr);
726
+ }
727
+ .backstage {
728
+ position: absolute;
729
+ inset-block: 0;
730
+ inset-inline-end: 0;
731
+ z-index: 2;
732
+ inline-size: min(400px, 90%);
733
+ box-shadow: 0 8px 24px rgb(0 0 0 / 0.18);
734
+ }
735
+ }
736
+ @container (max-width: 720px) {
737
+ .layout.backstage-open { grid-template-columns: minmax(0, 1fr); }
738
+ }
739
+
370
740
  /* ---- rail -------------------------------------------------------------- */
371
741
 
372
742
  .new-conversation {
@@ -374,6 +744,7 @@ button:focus-visible, summary:focus-visible {
374
744
  align-items: center;
375
745
  justify-content: center;
376
746
  gap: 8px;
747
+ min-block-size: 44px;
377
748
  padding: 8px 12px;
378
749
  border-radius: var(--_radius-sm);
379
750
  background: var(--_accent);
@@ -445,16 +816,17 @@ button:focus-visible, summary:focus-visible {
445
816
  display: flex;
446
817
  align-items: center;
447
818
  gap: 8px;
448
- min-block-size: 52px;
449
- padding: 8px 16px;
819
+ min-block-size: 60px;
820
+ padding: 8px 16px 8px 20px;
450
821
  border-block-end: 1px solid var(--_border);
451
822
  }
452
- .agent { display: flex; flex-direction: column; min-inline-size: 0; }
453
- .agent-name { font-weight: 600; }
454
- .agent-description {
823
+ .conversation-title {
824
+ flex: 1;
825
+ min-inline-size: 0;
826
+ margin: 0;
455
827
  overflow: hidden;
456
- color: var(--_muted);
457
- font-size: calc(var(--_fs) * 13 / 15);
828
+ font-size: calc(var(--_fs) * 17 / 15);
829
+ font-weight: 600;
458
830
  text-overflow: ellipsis;
459
831
  white-space: nowrap;
460
832
  }
@@ -479,22 +851,44 @@ button:focus-visible, summary:focus-visible {
479
851
  .thread {
480
852
  display: flex;
481
853
  flex-direction: column;
854
+ min-block-size: 100%;
482
855
  gap: 20px;
483
856
  max-inline-size: 760px;
484
857
  margin-inline: auto;
485
858
  padding: 20px 16px;
486
859
  }
860
+ /* Prova's empty conversation: in the middle, the AI's sparkles in their
861
+ circle, the agent's name, its description. */
487
862
  .empty {
488
863
  display: flex;
864
+ flex: 1;
489
865
  flex-direction: column;
490
866
  align-items: center;
491
867
  justify-content: center;
492
868
  gap: 8px;
493
- min-block-size: 40%;
494
869
  padding: 32px 16px;
495
870
  text-align: center;
496
871
  }
497
- .empty-title { margin: 0; font-size: calc(var(--_fs) * 22 / 15); font-weight: 600; }
872
+ .empty-icon {
873
+ display: inline-flex;
874
+ align-items: center;
875
+ justify-content: center;
876
+ inline-size: 48px;
877
+ block-size: 48px;
878
+ margin-block-end: 4px;
879
+ border-radius: 50%;
880
+ background: var(--_accent-soft);
881
+ color: var(--_accent-fg);
882
+ }
883
+ .empty-icon .icon { inline-size: 24px; block-size: 24px; }
884
+ .empty-title {
885
+ margin: 0;
886
+ font-size: calc(var(--_fs) * 26 / 15);
887
+ font-weight: 700;
888
+ letter-spacing: -0.01em;
889
+ line-height: 1.2;
890
+ }
891
+ .empty-detail { max-inline-size: 560px; margin: 0; }
498
892
 
499
893
  .message { display: flex; flex-direction: column; gap: 6px; }
500
894
  .message.user { align-items: flex-end; }
@@ -521,7 +915,9 @@ button:focus-visible, summary:focus-visible {
521
915
  .chip:not(:has(button)) { padding-inline-end: 10px; }
522
916
  .chip.error { border-color: var(--_danger); color: var(--_danger); }
523
917
  .chip .icon-button { inline-size: 22px; block-size: 22px; }
524
- .chip svg { inline-size: 16px; block-size: 16px; }
918
+ .chip .icon { inline-size: 16px; block-size: 16px; }
919
+ .action-summary { justify-content: flex-end; }
920
+ .chip.action { border-color: var(--_accent); background: var(--_accent); color: var(--_on-accent); font-weight: 600; }
525
921
 
526
922
  .message.assistant .answer { overflow-wrap: anywhere; }
527
923
  .note { margin: 0; color: var(--_muted); font-size: calc(var(--_fs) * 13 / 15); font-style: italic; }
@@ -599,9 +995,21 @@ button:focus-visible, summary:focus-visible {
599
995
  .markdown th, .markdown td { padding: 6px 10px; border: 1px solid var(--_border); text-align: start; }
600
996
  .markdown th { background: var(--_raised); }
601
997
  .markdown hr { border: 0; border-block-start: 1px solid var(--_border); }
998
+ .markdown .diagram, .markdown .chart {
999
+ display: flex;
1000
+ justify-content: center;
1001
+ overflow-x: auto;
1002
+ margin-block: 0 0.75em;
1003
+ padding: 20px;
1004
+ border: 1px solid var(--_border);
1005
+ border-radius: var(--_radius-sm);
1006
+ background: var(--_bg);
1007
+ }
602
1008
 
603
1009
  /* ---- composer ---------------------------------------------------------- */
604
1010
 
1011
+ /* Prova's composer: a card floating over the conversation, «+» to attach in
1012
+ a tinted square, the round send button with its arrow. */
605
1013
  .composer {
606
1014
  display: flex;
607
1015
  flex-direction: column;
@@ -609,23 +1017,32 @@ button:focus-visible, summary:focus-visible {
609
1017
  max-inline-size: 792px;
610
1018
  inline-size: 100%;
611
1019
  margin-inline: auto;
612
- padding: 8px 16px 12px;
1020
+ padding: 8px 16px 20px;
613
1021
  }
614
1022
  .box {
615
1023
  display: flex;
616
1024
  align-items: flex-end;
617
- gap: 4px;
618
- padding: 6px;
1025
+ gap: 8px;
1026
+ padding: 8px;
619
1027
  border: 1px solid var(--_border);
620
1028
  border-radius: var(--_radius);
621
1029
  background: var(--_bg);
1030
+ box-shadow: 0 2px 12px rgb(0 0 0 / 0.08);
1031
+ }
1032
+ .box .attach {
1033
+ inline-size: 40px;
1034
+ block-size: 40px;
1035
+ border-radius: var(--_radius-sm);
1036
+ background: var(--_accent-soft);
1037
+ color: var(--_accent-fg);
622
1038
  }
1039
+ .box .attach:not(:disabled):hover { background: var(--_accent-soft); color: var(--_accent-fg); filter: brightness(0.96); }
623
1040
  .box:focus-within { border-color: var(--_accent); box-shadow: 0 0 0 1px var(--_accent); }
624
1041
  textarea {
625
1042
  flex: 1;
626
- min-block-size: 32px;
1043
+ min-block-size: 40px;
627
1044
  max-block-size: 200px;
628
- padding: 5px 4px;
1045
+ padding: 9px 4px;
629
1046
  border: 0;
630
1047
  outline: none;
631
1048
  resize: none;
@@ -638,14 +1055,13 @@ textarea {
638
1055
  display: inline-flex;
639
1056
  align-items: center;
640
1057
  justify-content: center;
641
- inline-size: 36px;
642
- block-size: 36px;
1058
+ inline-size: 40px;
1059
+ block-size: 40px;
643
1060
  border-radius: var(--_radius-sm);
644
1061
  background: var(--_accent);
645
1062
  color: var(--_on-accent);
646
1063
  }
647
1064
  .send:not(:disabled):hover { background: var(--_accent-hover); }
648
- .footnote { margin: 0; color: var(--_muted); font-size: calc(var(--_fs) * 12 / 15); text-align: center; }
649
1065
 
650
1066
  /* ---- developer --------------------------------------------------------- */
651
1067
 
@@ -667,6 +1083,8 @@ textarea {
667
1083
  `;
668
1084
  // src/element/index.ts
669
1085
  var AICORE_AGENT_CHAT_TAG = "aicore-agent-chat";
1086
+ /** «Dietro le quinte»'s chunk: loaded when the panel first opens. */
1087
+ var backstage = lazy(() => import("./backstage-TkKENlNl.js"));
670
1088
  /** What AI-CORE reads from a conversation's files. */
671
1089
  var ACCEPT = ".pdf,.docx,.txt,.md,.html,.xlsx,.epub";
672
1090
  /** The client's events the element re-dispatches as they are. Its own
@@ -681,6 +1099,8 @@ var PREVIEW_CHARS = 160;
681
1099
  /** The streamed answer is re-rendered at most this often, in ms: its markdown
682
1100
  * is parsed whole each time, so every frame would grow with the answer. */
683
1101
  var LIVE_MS = 100;
1102
+ /** From this width «Dietro le quinte» is a column of its own (styles.ts). */
1103
+ var BACKSTAGE_COLUMN_PX = 1100;
684
1104
  /** How close to the bottom the transcript still follows new text, in px. */
685
1105
  var STICK_PX = 48;
686
1106
  /** How long the delete button waits for its second click, in ms. */
@@ -695,7 +1115,8 @@ var UPGRADED = [
695
1115
  "conversation",
696
1116
  "developer",
697
1117
  "copyAnswer",
698
- "noDisclaimer"
1118
+ "backstage",
1119
+ "team"
699
1120
  ];
700
1121
  var Base = typeof HTMLElement === "undefined" ? class {} : HTMLElement;
701
1122
  var sheet;
@@ -745,23 +1166,6 @@ function sourcePlace(t, source) {
745
1166
  if (source.part != null) return t.part(source.part);
746
1167
  return "";
747
1168
  }
748
- function eventLine(event, start) {
749
- const offset = start === null ? "" : `+${((event.at - start) / 1e3).toFixed(1)}s`;
750
- const fields = isRecord(event.data) ? event.data : {};
751
- let preview = typeof fields.name === "string" ? `${typeof fields.node === "string" ? `${fields.node} → ` : ""}${fields.name}` : "";
752
- if (!preview) try {
753
- preview = JSON.stringify(event.data) ?? "";
754
- } catch {
755
- preview = "";
756
- }
757
- if (preview.length > PREVIEW_CHARS) preview = `${preview.slice(0, PREVIEW_CHARS)}…`;
758
- return [
759
- offset,
760
- event.kind,
761
- event.id ? `#${event.id}` : "",
762
- preview
763
- ].filter(Boolean).join(" ");
764
- }
765
1169
  /** The user rated an answer and nothing else changed in it. */
766
1170
  function onlyRatingChanged(before, after) {
767
1171
  if (before.role !== "assistant" || after.role !== "assistant") return false;
@@ -783,8 +1187,9 @@ function setRating(node, rating) {
783
1187
  * workspace, sent as `X-Tenant`), `conversation` (to open), `lang` (`it`,
784
1188
  * `en`; else the page's language). What the console's Prova chat does not
785
1189
  * have is off unless the host sets its boolean attribute: `developer`
786
- * (requests, turn events, agent version), `copy-answer` (a copy button under
787
- * each answer); `no-disclaimer` hides the disclaimer, on by default.
1190
+ * (API, tenant, agent version, last error, requests), `copy-answer` (a copy
1191
+ * button under each answer), `backstage` («Dietro le quinte», the turns'
1192
+ * events, as the console shows them).
788
1193
  * Properties: `getToken({ retry })`, `strings` (text overrides), `context`
789
1194
  * (the page's data, sent with every message), `state`.
790
1195
  * Events (bubbling, composed): `aicore-conversation`, `aicore-turn`,
@@ -799,7 +1204,7 @@ var AicoreAgentChat = class extends Base {
799
1204
  "lang",
800
1205
  "developer",
801
1206
  "copy-answer",
802
- "no-disclaimer"
1207
+ "backstage"
803
1208
  ];
804
1209
  #getToken = null;
805
1210
  #overrides = null;
@@ -826,11 +1231,17 @@ var AicoreAgentChat = class extends Base {
826
1231
  #liveTurn = null;
827
1232
  #liveAt = 0;
828
1233
  #liveTimer = false;
829
- #eventsHeading = null;
830
1234
  #pendingAgent = false;
831
1235
  #pendingConversation = false;
832
1236
  #targetQueued = false;
833
1237
  #railOpen = false;
1238
+ /** «Dietro le quinte» shown, with `backstage`. At first, open as in Prova
1239
+ * when the element is wide enough for a third column; then as the user
1240
+ * leaves it. */
1241
+ #backstageOpen = true;
1242
+ #backstageChosen = false;
1243
+ #backstageView = "log";
1244
+ #team = null;
834
1245
  #stick = true;
835
1246
  #ui;
836
1247
  constructor() {
@@ -851,12 +1262,36 @@ var AicoreAgentChat = class extends Base {
851
1262
  }, newButton, railStatus, conversations);
852
1263
  const railToggle = iconButton("menu", "", { "data-action": "toggle-rail" });
853
1264
  railToggle.classList.add("rail-toggle");
854
- const agentName = h("span", { class: "agent-name" });
855
- const agentDescription = h("span", { class: "agent-description" });
1265
+ const title = h("h2", { class: "conversation-title" });
1266
+ const backstageToggle = iconButton("panel", "", {
1267
+ "data-action": "toggle-backstage",
1268
+ "aria-pressed": "true"
1269
+ }, "backstage-toggle");
856
1270
  const header = h("header", {
857
1271
  class: "header",
858
1272
  part: "header"
859
- }, railToggle, h("div", { class: "agent" }, agentName, agentDescription));
1273
+ }, railToggle, title, backstageToggle);
1274
+ const backstageTitle = h("h2", { class: "backstage-title" });
1275
+ const viewButton = (view) => h("button", {
1276
+ class: "backstage-view",
1277
+ attrs: {
1278
+ type: "button",
1279
+ "data-action": "backstage-view",
1280
+ "data-view": view
1281
+ }
1282
+ });
1283
+ const backstageLog = viewButton("log");
1284
+ const backstageMap = viewButton("map");
1285
+ const backstageViews = h("div", {
1286
+ class: "backstage-views",
1287
+ attrs: { role: "group" }
1288
+ }, backstageLog, backstageMap);
1289
+ const backstageClose = iconButton("close", "", { "data-action": "toggle-backstage" });
1290
+ const backstageBody = h("div", { class: "backstage-body" });
1291
+ const backstage = h("aside", {
1292
+ class: "backstage",
1293
+ part: "backstage"
1294
+ }, h("div", { class: "backstage-header" }, backstageTitle, backstageViews, backstageClose), backstageBody);
860
1295
  const bannerTitle = h("strong");
861
1296
  const bannerDetail = h("span", { class: "small" });
862
1297
  const dismiss = iconButton("close", "", { "data-action": "dismiss" });
@@ -867,7 +1302,8 @@ var AicoreAgentChat = class extends Base {
867
1302
  }, h("div", { class: "banner-text" }, bannerTitle, bannerDetail), dismiss);
868
1303
  banner.hidden = true;
869
1304
  const emptyTitle = h("p", { class: "empty-title" });
870
- const empty = h("div", { class: "empty" }, emptyTitle);
1305
+ const emptyDetail = h("p", { class: "empty-detail muted" });
1306
+ const empty = h("div", { class: "empty" }, h("span", { class: "empty-icon" }, icon("sparkles")), emptyTitle, emptyDetail);
871
1307
  const loading = h("p", { class: "status" });
872
1308
  const messages = h("div", { class: "messages" });
873
1309
  const liveAnswer = h("div", { class: "answer markdown" });
@@ -897,7 +1333,7 @@ var AicoreAgentChat = class extends Base {
897
1333
  accept: ACCEPT
898
1334
  } });
899
1335
  fileInput.hidden = true;
900
- const attach = iconButton("attach", "", { "data-action": "attach" });
1336
+ const attach = iconButton("add", "", { "data-action": "attach" }, "attach");
901
1337
  const input = h("textarea", {
902
1338
  part: "input",
903
1339
  attrs: { rows: "1" }
@@ -906,7 +1342,7 @@ var AicoreAgentChat = class extends Base {
906
1342
  class: "send",
907
1343
  part: "send",
908
1344
  attrs: { type: "submit" }
909
- }, icon("send"));
1345
+ }, icon("arrowUp"));
910
1346
  const stop = h("button", {
911
1347
  class: "send",
912
1348
  part: "stop",
@@ -915,18 +1351,17 @@ var AicoreAgentChat = class extends Base {
915
1351
  "data-action": "stop"
916
1352
  }
917
1353
  }, icon("stop"));
918
- const footnote = h("p", { class: "footnote" });
919
1354
  const composer = h("form", {
920
1355
  class: "composer",
921
1356
  part: "composer"
922
- }, files, h("div", { class: "box" }, attach, input, send, stop), footnote, fileInput);
1357
+ }, files, h("div", { class: "box" }, attach, input, send, stop), fileInput);
923
1358
  const developerSummary = h("summary");
924
1359
  const developerBody = h("div");
925
1360
  const developer = h("details", {
926
1361
  class: "developer",
927
1362
  part: "developer"
928
1363
  }, developerSummary, developerBody);
929
- const layout = h("div", { class: "layout" }, rail, h("section", { class: "main" }, header, banner, transcript, composer, developer));
1364
+ const layout = h("div", { class: "layout" }, rail, h("section", { class: "main" }, header, banner, transcript, composer, developer), backstage);
930
1365
  const shared = styleSheet();
931
1366
  if (shared) root.adoptedStyleSheets = [shared];
932
1367
  else root.append(h("style", { text: STYLES }));
@@ -938,9 +1373,16 @@ var AicoreAgentChat = class extends Base {
938
1373
  railStatus,
939
1374
  conversations,
940
1375
  railToggle,
941
- agentName,
942
- agentDescription,
1376
+ title,
943
1377
  banner,
1378
+ backstageToggle,
1379
+ backstage,
1380
+ backstageTitle,
1381
+ backstageViews,
1382
+ backstageLog,
1383
+ backstageMap,
1384
+ backstageClose,
1385
+ backstageBody,
944
1386
  bannerTitle,
945
1387
  bannerDetail,
946
1388
  dismiss,
@@ -948,6 +1390,7 @@ var AicoreAgentChat = class extends Base {
948
1390
  thread,
949
1391
  empty,
950
1392
  emptyTitle,
1393
+ emptyDetail,
951
1394
  loading,
952
1395
  messages,
953
1396
  live,
@@ -959,7 +1402,6 @@ var AicoreAgentChat = class extends Base {
959
1402
  input,
960
1403
  send,
961
1404
  stop,
962
- footnote,
963
1405
  developer,
964
1406
  developerSummary,
965
1407
  developerBody
@@ -1035,6 +1477,18 @@ var AicoreAgentChat = class extends Base {
1035
1477
  this.#contextChanged = true;
1036
1478
  this.#scheduleRender();
1037
1479
  }
1480
+ /** The agent's team, for «Dietro le quinte › Mappa» (with `backstage`):
1481
+ * the main agent and its members, as the agent's configuration has them,
1482
+ * which the user's token does not read. Without it the panel shows the
1483
+ * Registro only. */
1484
+ get team() {
1485
+ return this.#team;
1486
+ }
1487
+ set team(value) {
1488
+ this.#team = Array.isArray(value) ? value : null;
1489
+ if (!this.#team) this.#backstageView = "log";
1490
+ this.#scheduleRender(true);
1491
+ }
1038
1492
  get baseUrl() {
1039
1493
  return this.getAttribute("base-url");
1040
1494
  }
@@ -1073,12 +1527,14 @@ var AicoreAgentChat = class extends Base {
1073
1527
  set copyAnswer(value) {
1074
1528
  this.toggleAttribute("copy-answer", Boolean(value));
1075
1529
  }
1076
- /** Hides the disclaimer under the composer, shown by default. */
1077
- get noDisclaimer() {
1078
- return this.hasAttribute("no-disclaimer");
1530
+ /** «Dietro le quinte»: the side panel with the turns' events, as the
1531
+ * console's Prova shows it. Not a developer tool, but off by default: the
1532
+ * AI-CORE console sets it, other hosts do not. */
1533
+ get backstage() {
1534
+ return this.hasAttribute("backstage");
1079
1535
  }
1080
- set noDisclaimer(value) {
1081
- this.toggleAttribute("no-disclaimer", Boolean(value));
1536
+ set backstage(value) {
1537
+ this.toggleAttribute("backstage", Boolean(value));
1082
1538
  }
1083
1539
  /** The chat's current state (read-only), or null until it is configured. */
1084
1540
  get state() {
@@ -1242,6 +1698,15 @@ var AicoreAgentChat = class extends Base {
1242
1698
  case "toggle-rail":
1243
1699
  this.#railOpen = !this.#railOpen;
1244
1700
  break;
1701
+ case "backstage-view":
1702
+ this.#backstageView = target.dataset.view === "map" ? "map" : "log";
1703
+ this.#scheduleRender(true);
1704
+ break;
1705
+ case "toggle-backstage":
1706
+ this.#backstageOpen = !this.#backstageOpen;
1707
+ this.#backstageChosen = true;
1708
+ this.#scheduleRender(true);
1709
+ break;
1245
1710
  case "dismiss":
1246
1711
  session?.dismissError();
1247
1712
  break;
@@ -1334,7 +1799,7 @@ var AicoreAgentChat = class extends Base {
1334
1799
  const item = this.#session?.state.messages[Number(message)];
1335
1800
  const cited = item?.role === "assistant" ? item.sources[Number(source)] : void 0;
1336
1801
  if (!cited) return;
1337
- setMarkdown(body, cited.text ?? "");
1802
+ setMarkdown(body, cited.text ?? "", this.#rich(false));
1338
1803
  const url = safeUrl(cited.url);
1339
1804
  if (url) body.append(h("a", {
1340
1805
  text: url,
@@ -1354,6 +1819,35 @@ var AicoreAgentChat = class extends Base {
1354
1819
  session.send(text, { context: this.#context });
1355
1820
  this.#updateSend();
1356
1821
  }
1822
+ /** A click in an interface (A2UI) of an answer: its action, as the user's
1823
+ * next message, through the same door as the composer. */
1824
+ #sendAction(text) {
1825
+ const session = this.#session;
1826
+ if (!session || !this.#canSendAction()) return false;
1827
+ this.#stick = true;
1828
+ session.send(text, { context: this.#context });
1829
+ this.#updateSend();
1830
+ return true;
1831
+ }
1832
+ /** An interface's click can go: an agent, no turn running, and no file in
1833
+ * the composer, which the message would carry along. */
1834
+ #canSendAction() {
1835
+ const session = this.#session;
1836
+ const state = session?.state;
1837
+ return !!session && !!state?.agentId && !session.busy && state.uploading === 0 && state.files.length === 0;
1838
+ }
1839
+ /** What each message's interfaces can do: send while a click can go, and
1840
+ * show as sent the surfaces a later user message answered. */
1841
+ #interfaceStates(state) {
1842
+ const messages = state?.messages ?? [];
1843
+ const busy = this.#session?.busy ?? false;
1844
+ const send = this.#canSendAction() ? (text) => this.#sendAction(text) : void 0;
1845
+ return answeredSurfaces(messages).map((sent) => ({
1846
+ send,
1847
+ working: busy,
1848
+ sent
1849
+ }));
1850
+ }
1357
1851
  /** `lang` of the element, else of its closest ancestor, else of the page. */
1358
1852
  #lang() {
1359
1853
  return this.closest("[lang]")?.getAttribute("lang") ?? (typeof document === "undefined" ? null : document.documentElement.lang);
@@ -1361,6 +1855,21 @@ var AicoreAgentChat = class extends Base {
1361
1855
  #strings() {
1362
1856
  return stringsOf(this.#lang(), this.#overrides);
1363
1857
  }
1858
+ /** How markdown is drawn: formulas everywhere, and in an answer
1859
+ * (`widgets`) its diagrams, charts and interfaces. */
1860
+ #rich(widgets, live = false, state) {
1861
+ return {
1862
+ host: this,
1863
+ widgets,
1864
+ live,
1865
+ lang: languageOf(this.#lang()),
1866
+ strings: this.#strings(),
1867
+ interface: state ?? {
1868
+ working: live,
1869
+ sent: /* @__PURE__ */ new Map()
1870
+ }
1871
+ };
1872
+ }
1364
1873
  #scheduleRender(full = false) {
1365
1874
  if (full) this.#full = true;
1366
1875
  if (this.#frame) return;
@@ -1384,10 +1893,18 @@ var AicoreAgentChat = class extends Base {
1384
1893
  const changed = (...keys) => prev === null || state === null || keys.some((k) => prev[k] !== state[k]);
1385
1894
  if (prev === null) this.#renderStatic(t);
1386
1895
  if (busyChanged || changed("conversations", "activeId", "conversationsLoading", "conversationsFailed", "agentId")) this.#renderRail(t, state, busy);
1387
- if (changed("agent", "agentId")) this.#renderHeader(t, state);
1896
+ if (changed("agent", "agentId", "activeId", "conversations")) this.#renderHeader(t, state);
1388
1897
  if (changed("error")) this.#renderBanner(t, state);
1389
1898
  if (changed("messages", "loadingHistory", "agent")) this.#renderMessages(t, state, prev === null || changed("agent"));
1899
+ if (busyChanged || changed("messages", "files", "uploading", "agentId")) {
1900
+ const states = this.#interfaceStates(state);
1901
+ this.#messageNodes.forEach(({ node }, i) => {
1902
+ const current = states[i];
1903
+ if (current) updateInterfaces(node, current);
1904
+ });
1905
+ }
1390
1906
  this.#renderLive(t, state, prev === null);
1907
+ if (prev === null || changed("log", "turn")) this.#renderBackstage(t, state);
1391
1908
  this.#renderEmpty(t, state);
1392
1909
  if (busyChanged || changed("files", "agentId")) this.#renderComposer(t, state, busy);
1393
1910
  const developer = this.hasAttribute("developer");
@@ -1395,7 +1912,6 @@ var AicoreAgentChat = class extends Base {
1395
1912
  const contextChanged = this.#contextChanged;
1396
1913
  this.#contextChanged = false;
1397
1914
  if (developer && (contextChanged || changed("requests", "events", "error", "agent", "activeId"))) this.#renderDeveloper(t, state);
1398
- else if (developer && changed("tokens") && this.#eventsHeading && state) this.#eventsHeading.textContent = t.events(state.tokens);
1399
1915
  this.#ui.layout.classList.toggle("rail-open", this.#railOpen);
1400
1916
  if (this.#stick) this.#ui.transcript.scrollTop = this.#ui.transcript.scrollHeight;
1401
1917
  }
@@ -1403,20 +1919,24 @@ var AicoreAgentChat = class extends Base {
1403
1919
  const ui = this.#ui;
1404
1920
  ui.rail.setAttribute("aria-label", t.conversations);
1405
1921
  ui.newButton.replaceChildren(icon("add"), t.newConversation);
1922
+ ui.backstageTitle.textContent = t.backstage;
1923
+ ui.backstageLog.textContent = t.backstageLog;
1924
+ ui.backstageMap.textContent = t.backstageMap;
1925
+ ui.backstageViews.setAttribute("aria-label", t.backstageViews);
1406
1926
  for (const [button, label] of [
1407
1927
  [ui.railToggle, t.conversations],
1408
1928
  [ui.dismiss, t.dismiss],
1409
1929
  [ui.attach, t.attach],
1410
1930
  [ui.send, t.send],
1411
- [ui.stop, t.stop]
1931
+ [ui.stop, t.stop],
1932
+ [ui.backstageToggle, t.backstageToggle],
1933
+ [ui.backstageClose, t.backstageToggle]
1412
1934
  ]) {
1413
1935
  button.setAttribute("aria-label", label);
1414
1936
  button.title = label;
1415
1937
  }
1416
1938
  ui.input.placeholder = t.placeholder;
1417
1939
  ui.input.setAttribute("aria-label", t.placeholder);
1418
- ui.footnote.textContent = t.disclaimer;
1419
- ui.footnote.hidden = !t.disclaimer || this.hasAttribute("no-disclaimer");
1420
1940
  ui.loading.textContent = t.loadingHistory;
1421
1941
  ui.developerSummary.textContent = t.developer;
1422
1942
  }
@@ -1491,10 +2011,9 @@ var AicoreAgentChat = class extends Base {
1491
2011
  return item;
1492
2012
  }
1493
2013
  #renderHeader(t, state) {
1494
- const ui = this.#ui;
1495
- ui.agentName.textContent = state?.agent?.name ?? state?.agentId ?? t.noAgent;
1496
- ui.agentDescription.textContent = state?.agent?.description ?? "";
1497
- ui.agentDescription.hidden = !state?.agent?.description;
2014
+ const active = state?.activeId ?? null;
2015
+ const conversation = active ? state?.conversations.find((c) => c.id === active) : void 0;
2016
+ this.#ui.title.textContent = !state?.agentId ? "" : active === null ? t.newConversation : (conversation?.title ?? "") || t.untitled;
1498
2017
  }
1499
2018
  #renderBanner(t, state) {
1500
2019
  const ui = this.#ui;
@@ -1510,6 +2029,7 @@ var AicoreAgentChat = class extends Base {
1510
2029
  ui.loading.hidden = !loading;
1511
2030
  const list = loading ? [] : state?.messages ?? [];
1512
2031
  const agentName = state?.agent?.name ?? t.agent;
2032
+ const interfaces = this.#interfaceStates(state);
1513
2033
  const nodes = list.map((message, index) => {
1514
2034
  const cached = rebuild ? void 0 : this.#messageNodes[index];
1515
2035
  if (cached?.message === message) return cached;
@@ -1522,29 +2042,48 @@ var AicoreAgentChat = class extends Base {
1522
2042
  }
1523
2043
  return {
1524
2044
  message,
1525
- node: message.role === "user" ? this.#userMessage(t, message) : this.#assistantMessage(t, message, index, agentName)
2045
+ node: message.role === "user" ? this.#userMessage(t, message) : this.#assistantMessage(t, message, index, agentName, interfaces[index])
1526
2046
  };
1527
2047
  });
2048
+ const kept = new Set(nodes.map(({ node }) => node));
2049
+ for (const { node } of this.#messageNodes) if (!kept.has(node)) disposeDrawings(node);
1528
2050
  this.#messageNodes = nodes;
1529
2051
  const shown = ui.messages.children;
1530
2052
  if (nodes.length !== shown.length || nodes.some(({ node }, i) => node !== shown[i])) ui.messages.replaceChildren(...nodes.map(({ node }) => node));
1531
2053
  }
2054
+ /** A user message's text; one that answered an interface reads as what
2055
+ * it sent (the action, and each value), never as its JSON. */
2056
+ #userText(t, text) {
2057
+ const action = parseA2uiAction(text);
2058
+ if (!action) return h("div", {
2059
+ class: "bubble",
2060
+ text
2061
+ });
2062
+ const { label, fields } = actionSummary(action, t);
2063
+ return h("ul", {
2064
+ class: "chips action-summary",
2065
+ attrs: { "aria-label": t.a2uiAction(label) }
2066
+ }, h("li", { class: "chip action" }, icon("check"), h("span", {
2067
+ class: "chip-label",
2068
+ text: label
2069
+ })), ...fields.map(([key, value]) => h("li", { class: "chip" }, h("span", { class: "chip-label" }, h("span", {
2070
+ class: "muted",
2071
+ text: `${key}: `
2072
+ }), value))));
2073
+ }
1532
2074
  #userMessage(t, message) {
1533
2075
  return h("article", {
1534
2076
  class: "message user",
1535
2077
  part: "message message-user",
1536
2078
  attrs: { "aria-label": t.you }
1537
- }, h("div", {
1538
- class: "bubble",
1539
- text: message.text
1540
- }), message.attachments.length > 0 && h("ul", { class: "chips" }, ...message.attachments.map((a) => h("li", { class: "chip" }, h("span", {
2079
+ }, this.#userText(t, message.text), message.attachments.length > 0 && h("ul", { class: "chips" }, ...message.attachments.map((a) => h("li", { class: "chip" }, h("span", {
1541
2080
  class: "chip-label",
1542
2081
  text: a.name
1543
2082
  })))));
1544
2083
  }
1545
- #assistantMessage(t, message, index, agentName) {
2084
+ #assistantMessage(t, message, index, agentName, state) {
1546
2085
  const answer = h("div", { class: "answer markdown" });
1547
- setMarkdown(answer, message.text);
2086
+ setMarkdown(answer, message.text, this.#rich(true, false, state));
1548
2087
  const article = h("article", {
1549
2088
  class: "message assistant",
1550
2089
  part: "message message-assistant",
@@ -1606,6 +2145,7 @@ var AicoreAgentChat = class extends Base {
1606
2145
  ui.live.hidden = turn === null;
1607
2146
  if (!turn) {
1608
2147
  this.#liveTurn = null;
2148
+ disposeDrawings(ui.liveAnswer);
1609
2149
  ui.liveAnswer.replaceChildren();
1610
2150
  return;
1611
2151
  }
@@ -1626,14 +2166,54 @@ var AicoreAgentChat = class extends Base {
1626
2166
  if (!textChanged) return;
1627
2167
  this.#liveAt = performance.now();
1628
2168
  ui.liveAnswer.hidden = !turn.text;
1629
- setMarkdown(ui.liveAnswer, turn.text);
2169
+ setMarkdown(ui.liveAnswer, turn.text, this.#rich(true, true));
2170
+ }
2171
+ /** «Dietro le quinte», with `backstage` and while open. */
2172
+ #renderBackstage(t, state) {
2173
+ const ui = this.#ui;
2174
+ const on = this.hasAttribute("backstage");
2175
+ if (on && !this.#backstageChosen) {
2176
+ const width = this.getBoundingClientRect().width;
2177
+ this.#backstageOpen = width === 0 || width > BACKSTAGE_COLUMN_PX;
2178
+ }
2179
+ const open = on && this.#backstageOpen;
2180
+ ui.backstageToggle.hidden = !on;
2181
+ ui.backstageToggle.setAttribute("aria-pressed", String(open));
2182
+ ui.backstage.hidden = !open;
2183
+ ui.layout.classList.toggle("backstage-open", open);
2184
+ const team = this.#team;
2185
+ const view = team ? this.#backstageView : "log";
2186
+ ui.backstageMap.hidden = !team;
2187
+ ui.backstageLog.setAttribute("aria-pressed", String(view === "log"));
2188
+ ui.backstageMap.setAttribute("aria-pressed", String(view === "map"));
2189
+ if (!open || !state) return;
2190
+ const turn = state.turn;
2191
+ const input = {
2192
+ view,
2193
+ team,
2194
+ agentName: state.agent?.name ?? state.agentId ?? "",
2195
+ working: turn !== null,
2196
+ log: state.log,
2197
+ live: turn && state.turnStartedAt !== null ? {
2198
+ label: turn.activity ?? t.thinking,
2199
+ since: state.turnStartedAt
2200
+ } : null,
2201
+ strings: t,
2202
+ locale: t.locale
2203
+ };
2204
+ const ready = backstage.get();
2205
+ if (ready) ready.drawBackstage(ui.backstageBody, input);
2206
+ else backstage.load().then(() => this.#scheduleRender(true), () => void 0);
1630
2207
  }
1631
2208
  #renderEmpty(t, state) {
1632
2209
  const ui = this.#ui;
1633
2210
  const empty = state === null || !state.loadingHistory && state.messages.length === 0 && !state.turn;
1634
2211
  ui.empty.hidden = !empty;
1635
2212
  if (!empty) return;
1636
- ui.emptyTitle.textContent = state === null ? t.notConnected : !state.agentId ? t.noAgent : state.agent ? t.ask(state.agent.name) : t.askGeneric;
2213
+ ui.emptyTitle.textContent = state === null ? t.notConnected : !state.agentId ? t.noAgent : state.agent?.name ?? "";
2214
+ const detail = state?.agentId ? state.agent?.description ?? "" : "";
2215
+ ui.emptyDetail.textContent = detail;
2216
+ ui.emptyDetail.hidden = !detail;
1637
2217
  }
1638
2218
  #renderComposer(t, state, busy) {
1639
2219
  const ui = this.#ui;
@@ -1699,8 +2279,7 @@ var AicoreAgentChat = class extends Base {
1699
2279
  ["error_description", error.authDescription ?? t.none],
1700
2280
  ["X-Request-Id", error.requestId ?? t.none]
1701
2281
  ]));
1702
- this.#eventsHeading = h("h4", { text: t.events(state.tokens) });
1703
- parts.push(this.#eventsHeading, h("ol", { class: "log" }, ...[...state.events].reverse().map((e) => h("li", { text: eventLine(e, state.turnStartedAt) }))), h("h4", { text: t.requests }), h("ol", { class: "log" }, ...state.requests.map((r) => h("li", {
2282
+ parts.push(h("h4", { text: t.requests }), h("ol", { class: "log" }, ...state.requests.map((r) => h("li", {
1704
2283
  class: r.status === 0 || r.status >= 400 ? "bad" : "",
1705
2284
  text: `${r.status} ${r.method} ${r.path} · ${r.durationMs} ms` + (r.retriedWithFreshToken ? ` · ${t.renewed}` : "") + (r.requestId ? ` · ${r.requestId}` : "")
1706
2285
  }))));
@@ -1712,6 +2291,6 @@ function defineAicoreAgentChat(tag = AICORE_AGENT_CHAT_TAG) {
1712
2291
  if (typeof customElements === "undefined" || customElements.get(tag)) return;
1713
2292
  customElements.define(tag, tag === "aicore-agent-chat" ? AicoreAgentChat : class extends AicoreAgentChat {});
1714
2293
  }
1715
- export { AicoreAgentChat as n, defineAicoreAgentChat as r, AICORE_AGENT_CHAT_TAG as t };
2294
+ 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 };
1716
2295
 
1717
- //# sourceMappingURL=src-CYXMXds2.js.map
2296
+ //# sourceMappingURL=src-PkQozp4M.js.map