@unofficialbox/box-open-elements 0.5.0 → 0.6.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 (219) hide show
  1. package/README.md +3 -3
  2. package/dist/components/collections/table.d.ts +57 -3
  3. package/dist/components/collections/table.js +339 -20
  4. package/dist/components/feedback/due-badge.d.ts +38 -0
  5. package/dist/components/feedback/due-badge.js +168 -0
  6. package/dist/components/feedback/due-types.d.ts +32 -0
  7. package/dist/components/feedback/due-types.js +91 -0
  8. package/dist/components/feedback/progress-steps.d.ts +51 -5
  9. package/dist/components/feedback/progress-steps.js +200 -22
  10. package/dist/components/feedback/stage-path.d.ts +44 -0
  11. package/dist/components/feedback/stage-path.js +235 -0
  12. package/dist/components/forms/select.d.ts +21 -0
  13. package/dist/components/forms/select.js +100 -3
  14. package/dist/components/forms/text-field.d.ts +21 -0
  15. package/dist/components/forms/text-field.js +100 -1
  16. package/dist/components/layout/nav-sidebar.d.ts +14 -0
  17. package/dist/components/layout/nav-sidebar.js +49 -0
  18. package/dist/components/layout/split-view.d.ts +14 -0
  19. package/dist/components/layout/split-view.js +80 -1
  20. package/dist/components/overlays/command-palette.d.ts +62 -0
  21. package/dist/components/overlays/command-palette.js +537 -0
  22. package/dist/components/overlays/command-types.d.ts +90 -0
  23. package/dist/components/overlays/command-types.js +259 -0
  24. package/dist/components/overlays/drawer.d.ts +18 -0
  25. package/dist/components/overlays/drawer.js +135 -9
  26. package/dist/components/overlays/shortcuts-overlay.d.ts +48 -0
  27. package/dist/components/overlays/shortcuts-overlay.js +385 -0
  28. package/dist/components/overlays/tooltip.js +1 -1
  29. package/dist/element-maps.d.ts +292 -0
  30. package/dist/element-maps.js +1 -0
  31. package/dist/entries/activity-density.d.ts +1 -0
  32. package/dist/entries/activity-density.js +1 -0
  33. package/dist/entries/agent-chat.d.ts +1 -0
  34. package/dist/entries/agent-chat.js +1 -0
  35. package/dist/entries/audit-log.d.ts +1 -0
  36. package/dist/entries/audit-log.js +1 -0
  37. package/dist/entries/command-palette.d.ts +1 -0
  38. package/dist/entries/command-palette.js +1 -0
  39. package/dist/entries/compare-view.d.ts +1 -0
  40. package/dist/entries/compare-view.js +1 -0
  41. package/dist/entries/diff-viewer.d.ts +1 -0
  42. package/dist/entries/diff-viewer.js +1 -0
  43. package/dist/entries/due-badge.d.ts +1 -0
  44. package/dist/entries/due-badge.js +1 -0
  45. package/dist/entries/form-wizard.d.ts +1 -0
  46. package/dist/entries/form-wizard.js +1 -0
  47. package/dist/entries/lineage-graph.d.ts +1 -0
  48. package/dist/entries/lineage-graph.js +1 -0
  49. package/dist/entries/notification-bell.d.ts +1 -0
  50. package/dist/entries/notification-bell.js +1 -0
  51. package/dist/entries/notification-inbox.d.ts +1 -0
  52. package/dist/entries/notification-inbox.js +1 -0
  53. package/dist/entries/provenance-strip.d.ts +1 -0
  54. package/dist/entries/provenance-strip.js +1 -0
  55. package/dist/entries/run-trace.d.ts +1 -0
  56. package/dist/entries/run-trace.js +1 -0
  57. package/dist/entries/shortcuts-overlay.d.ts +1 -0
  58. package/dist/entries/shortcuts-overlay.js +1 -0
  59. package/dist/entries/signature-ceremony.d.ts +1 -0
  60. package/dist/entries/signature-ceremony.js +1 -0
  61. package/dist/entries/stage-path.d.ts +1 -0
  62. package/dist/entries/stage-path.js +1 -0
  63. package/dist/entries/timeline.d.ts +1 -0
  64. package/dist/entries/timeline.js +1 -0
  65. package/dist/entries/version-graph.d.ts +1 -0
  66. package/dist/entries/version-graph.js +1 -0
  67. package/dist/entries/version-list.d.ts +1 -0
  68. package/dist/entries/version-list.js +1 -0
  69. package/dist/entries/wizard-summary.d.ts +1 -0
  70. package/dist/entries/wizard-summary.js +1 -0
  71. package/dist/entries/work-queue.d.ts +1 -0
  72. package/dist/entries/work-queue.js +1 -0
  73. package/dist/entries/workload-board.d.ts +1 -0
  74. package/dist/entries/workload-board.js +1 -0
  75. package/dist/index.d.ts +21 -0
  76. package/dist/index.js +21 -0
  77. package/dist/patterns/agent-chat/agent-chat.d.ts +75 -0
  78. package/dist/patterns/agent-chat/agent-chat.js +820 -0
  79. package/dist/patterns/agent-chat/controller.d.ts +27 -0
  80. package/dist/patterns/agent-chat/controller.js +182 -0
  81. package/dist/patterns/agent-chat/index.d.ts +3 -0
  82. package/dist/patterns/agent-chat/index.js +6 -0
  83. package/dist/patterns/agent-chat/types.d.ts +109 -0
  84. package/dist/patterns/agent-chat/types.js +1 -0
  85. package/dist/patterns/audit/activity-density.d.ts +68 -0
  86. package/dist/patterns/audit/activity-density.js +428 -0
  87. package/dist/patterns/audit/audit-log.d.ts +81 -0
  88. package/dist/patterns/audit/audit-log.js +794 -0
  89. package/dist/patterns/audit/index.d.ts +3 -0
  90. package/dist/patterns/audit/index.js +7 -0
  91. package/dist/patterns/audit/shared.d.ts +10 -0
  92. package/dist/patterns/audit/shared.js +50 -0
  93. package/dist/patterns/audit/types.d.ts +143 -0
  94. package/dist/patterns/audit/types.js +327 -0
  95. package/dist/patterns/content-explorer/actions/controller.js +12 -2
  96. package/dist/patterns/content-explorer/box-transport.js +117 -25
  97. package/dist/patterns/content-explorer/content-explorer.d.ts +13 -1
  98. package/dist/patterns/content-explorer/content-explorer.js +36 -3
  99. package/dist/patterns/content-explorer/contracts.d.ts +24 -1
  100. package/dist/patterns/content-explorer/contracts.js +68 -11
  101. package/dist/patterns/content-explorer/controller.d.ts +16 -1
  102. package/dist/patterns/content-explorer/controller.js +130 -4
  103. package/dist/patterns/content-explorer/navigation/controller.js +11 -9
  104. package/dist/patterns/content-explorer/types.d.ts +58 -1
  105. package/dist/patterns/content-picker/content-picker.d.ts +71 -0
  106. package/dist/patterns/content-picker/content-picker.js +747 -0
  107. package/dist/patterns/content-picker/controller.d.ts +38 -0
  108. package/dist/patterns/content-picker/controller.js +141 -0
  109. package/dist/patterns/content-picker/index.d.ts +3 -0
  110. package/dist/patterns/content-picker/index.js +6 -0
  111. package/dist/patterns/content-picker/types.d.ts +52 -0
  112. package/dist/patterns/content-picker/types.js +26 -0
  113. package/dist/patterns/content-sidebar/content-sidebar.d.ts +43 -0
  114. package/dist/patterns/content-sidebar/content-sidebar.js +293 -0
  115. package/dist/patterns/content-sidebar/index.d.ts +2 -0
  116. package/dist/patterns/content-sidebar/index.js +4 -0
  117. package/dist/patterns/content-sidebar/types.d.ts +18 -0
  118. package/dist/patterns/content-sidebar/types.js +20 -0
  119. package/dist/patterns/content-uploader/box-transport.d.ts +14 -0
  120. package/dist/patterns/content-uploader/box-transport.js +54 -0
  121. package/dist/patterns/content-uploader/content-uploader.d.ts +62 -0
  122. package/dist/patterns/content-uploader/content-uploader.js +559 -0
  123. package/dist/patterns/content-uploader/controller.d.ts +39 -0
  124. package/dist/patterns/content-uploader/controller.js +227 -0
  125. package/dist/patterns/content-uploader/index.d.ts +4 -0
  126. package/dist/patterns/content-uploader/index.js +8 -0
  127. package/dist/patterns/content-uploader/types.d.ts +120 -0
  128. package/dist/patterns/content-uploader/types.js +38 -0
  129. package/dist/patterns/diff/compare-view.d.ts +47 -0
  130. package/dist/patterns/diff/compare-view.js +276 -0
  131. package/dist/patterns/diff/diff-viewer.d.ts +42 -0
  132. package/dist/patterns/diff/diff-viewer.js +434 -0
  133. package/dist/patterns/diff/engine.d.ts +22 -0
  134. package/dist/patterns/diff/engine.js +276 -0
  135. package/dist/patterns/diff/index.d.ts +4 -0
  136. package/dist/patterns/diff/index.js +8 -0
  137. package/dist/patterns/diff/types.d.ts +69 -0
  138. package/dist/patterns/diff/types.js +24 -0
  139. package/dist/patterns/form-wizard/controller.d.ts +39 -0
  140. package/dist/patterns/form-wizard/controller.js +157 -0
  141. package/dist/patterns/form-wizard/form-wizard.d.ts +63 -0
  142. package/dist/patterns/form-wizard/form-wizard.js +468 -0
  143. package/dist/patterns/form-wizard/index.d.ts +4 -0
  144. package/dist/patterns/form-wizard/index.js +8 -0
  145. package/dist/patterns/form-wizard/types.d.ts +109 -0
  146. package/dist/patterns/form-wizard/types.js +83 -0
  147. package/dist/patterns/form-wizard/wizard-summary.d.ts +62 -0
  148. package/dist/patterns/form-wizard/wizard-summary.js +324 -0
  149. package/dist/patterns/internal/safe-href.d.ts +17 -0
  150. package/dist/patterns/internal/safe-href.js +17 -0
  151. package/dist/patterns/lineage/index.d.ts +3 -0
  152. package/dist/patterns/lineage/index.js +6 -0
  153. package/dist/patterns/lineage/lineage-graph.d.ts +30 -0
  154. package/dist/patterns/lineage/lineage-graph.js +434 -0
  155. package/dist/patterns/lineage/provenance-strip.d.ts +22 -0
  156. package/dist/patterns/lineage/provenance-strip.js +194 -0
  157. package/dist/patterns/lineage/types.d.ts +53 -0
  158. package/dist/patterns/lineage/types.js +49 -0
  159. package/dist/patterns/notifications/index.d.ts +3 -0
  160. package/dist/patterns/notifications/index.js +6 -0
  161. package/dist/patterns/notifications/notification-bell.d.ts +38 -0
  162. package/dist/patterns/notifications/notification-bell.js +198 -0
  163. package/dist/patterns/notifications/notification-inbox.d.ts +46 -0
  164. package/dist/patterns/notifications/notification-inbox.js +537 -0
  165. package/dist/patterns/notifications/types.d.ts +61 -0
  166. package/dist/patterns/notifications/types.js +108 -0
  167. package/dist/patterns/preview/annotation-inspector.d.ts +25 -6
  168. package/dist/patterns/preview/annotation-inspector.js +239 -94
  169. package/dist/patterns/preview/annotation-thread.d.ts +25 -5
  170. package/dist/patterns/preview/annotation-thread.js +233 -82
  171. package/dist/patterns/preview/annotation-toolbar.d.ts +20 -6
  172. package/dist/patterns/preview/annotation-toolbar.js +162 -96
  173. package/dist/patterns/preview/content-preview-adapter.d.ts +10 -1
  174. package/dist/patterns/preview/content-preview-adapter.js +26 -1
  175. package/dist/patterns/preview/preview-element.d.ts +15 -2
  176. package/dist/patterns/preview/preview-element.js +223 -52
  177. package/dist/patterns/preview/provider-adapter.d.ts +47 -0
  178. package/dist/patterns/preview/provider-adapter.js +17 -0
  179. package/dist/patterns/run/index.d.ts +2 -0
  180. package/dist/patterns/run/index.js +4 -0
  181. package/dist/patterns/run/run-trace.d.ts +40 -0
  182. package/dist/patterns/run/run-trace.js +441 -0
  183. package/dist/patterns/run/types.d.ts +66 -0
  184. package/dist/patterns/run/types.js +152 -0
  185. package/dist/patterns/signature/index.d.ts +2 -0
  186. package/dist/patterns/signature/index.js +4 -0
  187. package/dist/patterns/signature/signature-ceremony.d.ts +33 -0
  188. package/dist/patterns/signature/signature-ceremony.js +317 -0
  189. package/dist/patterns/signature/types.d.ts +68 -0
  190. package/dist/patterns/signature/types.js +89 -0
  191. package/dist/patterns/timeline/index.d.ts +2 -0
  192. package/dist/patterns/timeline/index.js +4 -0
  193. package/dist/patterns/timeline/timeline.d.ts +27 -0
  194. package/dist/patterns/timeline/timeline.js +430 -0
  195. package/dist/patterns/timeline/types.d.ts +36 -0
  196. package/dist/patterns/timeline/types.js +27 -0
  197. package/dist/patterns/versions/graph-layout.d.ts +43 -0
  198. package/dist/patterns/versions/graph-layout.js +159 -0
  199. package/dist/patterns/versions/index.d.ts +4 -0
  200. package/dist/patterns/versions/index.js +8 -0
  201. package/dist/patterns/versions/shared.d.ts +4 -0
  202. package/dist/patterns/versions/shared.js +13 -0
  203. package/dist/patterns/versions/types.d.ts +37 -0
  204. package/dist/patterns/versions/types.js +39 -0
  205. package/dist/patterns/versions/version-graph.d.ts +36 -0
  206. package/dist/patterns/versions/version-graph.js +438 -0
  207. package/dist/patterns/versions/version-list.d.ts +39 -0
  208. package/dist/patterns/versions/version-list.js +407 -0
  209. package/dist/patterns/work-queue/controller.d.ts +26 -0
  210. package/dist/patterns/work-queue/controller.js +150 -0
  211. package/dist/patterns/work-queue/index.d.ts +4 -0
  212. package/dist/patterns/work-queue/index.js +7 -0
  213. package/dist/patterns/work-queue/types.d.ts +128 -0
  214. package/dist/patterns/work-queue/types.js +45 -0
  215. package/dist/patterns/work-queue/work-queue.d.ts +48 -0
  216. package/dist/patterns/work-queue/work-queue.js +534 -0
  217. package/dist/patterns/work-queue/workload-board.d.ts +53 -0
  218. package/dist/patterns/work-queue/workload-board.js +608 -0
  219. package/package.json +89 -5
@@ -0,0 +1,820 @@
1
+ import { AgentChatController } from "./controller.js";
2
+ import { isSafeHref } from "../internal/safe-href.js";
3
+ import { BaseElement } from "../../core/index.js";
4
+ import { boeMotionDuration, boeMotionEasing } from "../../foundations/motion/index.js";
5
+ import { boePanel, boeRadius } from "../../foundations/geometry/index.js";
6
+ const DEFAULT_TAG_NAME = "box-agent-chat";
7
+ const escapeHtml = (value) => value
8
+ .replaceAll("&", "&")
9
+ .replaceAll("<", "&lt;")
10
+ .replaceAll(">", "&gt;")
11
+ .replaceAll('"', "&quot;")
12
+ .replaceAll("'", "&#39;");
13
+ /** Same downgrade rule as the timeline: unsafe hrefs render as buttons. */
14
+ const initialsOf = (name) => name
15
+ .split(/\s+/)
16
+ .filter(Boolean)
17
+ .slice(0, 2)
18
+ .map(part => part[0]?.toUpperCase() ?? "")
19
+ .join("");
20
+ const elementStyles = `
21
+ [hidden] {
22
+ display: none !important;
23
+ }
24
+
25
+ :host {
26
+ display: block;
27
+ color: inherit;
28
+ font: inherit;
29
+ }
30
+
31
+ section[part="panel"] {
32
+ display: grid;
33
+ gap: ${boePanel.gap};
34
+ padding: ${boePanel.padding};
35
+ border: 1px solid color-mix(in srgb, var(--boe-token-stroke-stroke, #e8e8e8) 82%, transparent);
36
+ border-radius: ${boePanel.radius};
37
+ background: ${boePanel.background};
38
+ }
39
+
40
+ [part="header"] {
41
+ display: flex;
42
+ flex-wrap: wrap;
43
+ align-items: center;
44
+ gap: 0.5rem;
45
+ }
46
+
47
+ [part="title"] {
48
+ margin: 0;
49
+ font: inherit;
50
+ font-size: 1.1rem;
51
+ font-weight: 700;
52
+ color: var(--boe-token-text-text, #1f1e1b);
53
+ }
54
+
55
+ [part="status"] {
56
+ margin-inline-start: auto;
57
+ font-size: 0.78rem;
58
+ color: var(--boe-token-text-text-secondary, #6f6f6f);
59
+ }
60
+
61
+ [part="thread"] {
62
+ list-style: none;
63
+ margin: 0;
64
+ padding: 0;
65
+ display: grid;
66
+ gap: 0.6rem;
67
+ max-block-size: 26rem;
68
+ overflow-y: auto;
69
+ }
70
+
71
+ [part="message"] {
72
+ display: grid;
73
+ gap: 0.35rem;
74
+ padding: 0.6rem 0.7rem;
75
+ border-radius: ${boeRadius.large};
76
+ border: 1px solid color-mix(in srgb, var(--boe-token-stroke-stroke, #e8e8e8) 52%, transparent);
77
+ background: var(--boe-token-surface-surface, #ffffff);
78
+ }
79
+
80
+ [part="message"][data-role="user"] {
81
+ background: var(--boe-token-surface-item-surface-selected, #f2f7fd);
82
+ margin-inline-start: 2.5rem;
83
+ }
84
+
85
+ [part="message"][data-status="error"] {
86
+ border-color: color-mix(in srgb, var(--boe-token-surface-status-surface-error, #ed3757) 40%, transparent);
87
+ }
88
+
89
+ [part="message-header"] {
90
+ display: flex;
91
+ align-items: center;
92
+ gap: 0.4rem;
93
+ }
94
+
95
+ [part="avatar"] {
96
+ display: inline-grid;
97
+ place-items: center;
98
+ inline-size: 1.5rem;
99
+ block-size: 1.5rem;
100
+ border-radius: 999px;
101
+ background: color-mix(in srgb, var(--boe-token-surface-surface-brand, #0061d5) 12%, var(--boe-token-surface-surface, #ffffff) 88%);
102
+ color: var(--boe-token-surface-surface-brand, #0061d5);
103
+ font-size: 0.65rem;
104
+ font-weight: 700;
105
+ letter-spacing: 0.04em;
106
+ }
107
+
108
+ [part="author"] {
109
+ font-weight: 700;
110
+ font-size: 0.85rem;
111
+ color: var(--boe-token-text-text, #1f1e1b);
112
+ }
113
+
114
+ [part="body"] {
115
+ margin: 0;
116
+ white-space: pre-wrap;
117
+ color: var(--boe-token-text-text, #1f1e1b);
118
+ }
119
+
120
+ [part="error"] {
121
+ margin: 0;
122
+ font-size: 0.84rem;
123
+ color: color-mix(in srgb, var(--boe-token-surface-status-surface-error, #ed3757) 74%, black 26%);
124
+ }
125
+
126
+ [part="caret"] {
127
+ display: inline-block;
128
+ inline-size: 0.5rem;
129
+ block-size: 1em;
130
+ vertical-align: text-bottom;
131
+ background: color-mix(in srgb, var(--boe-token-surface-surface-brand, #0061d5) 60%, transparent);
132
+ animation: boe-agent-caret 1s steps(2, start) infinite;
133
+ }
134
+
135
+ @keyframes boe-agent-caret {
136
+ to {
137
+ opacity: 0.15;
138
+ }
139
+ }
140
+
141
+ @media (prefers-reduced-motion: reduce) {
142
+ [part="caret"] {
143
+ animation: none;
144
+ }
145
+ }
146
+
147
+ [part="citations"] {
148
+ display: flex;
149
+ flex-wrap: wrap;
150
+ gap: 0.35rem;
151
+ }
152
+
153
+ [part="citation"] {
154
+ appearance: none;
155
+ display: inline-flex;
156
+ align-items: center;
157
+ gap: 0.3rem;
158
+ font: inherit;
159
+ font-size: 0.74rem;
160
+ font-weight: 600;
161
+ padding: 0.18rem 0.5rem;
162
+ border-radius: 999px;
163
+ border: 1px solid color-mix(in srgb, var(--boe-token-stroke-stroke, #e8e8e8) 60%, transparent);
164
+ background: var(--boe-token-surface-surface, #ffffff);
165
+ color: var(--boe-token-surface-surface-brand, #0061d5);
166
+ text-decoration: none;
167
+ cursor: pointer;
168
+ }
169
+
170
+ [part="citation"]:hover {
171
+ background: var(--boe-token-surface-surface-hover, #f4f4f4);
172
+ }
173
+
174
+ [part="citation"]:focus-visible {
175
+ outline: none;
176
+ box-shadow: 0 0 0 3px color-mix(in srgb, var(--boe-token-surface-surface-brand, #0061d5) 18%, transparent);
177
+ }
178
+
179
+ [part="proposal"] {
180
+ display: grid;
181
+ gap: 0.35rem;
182
+ padding: 0.55rem 0.6rem;
183
+ border-radius: ${boeRadius.med};
184
+ border: 1px solid color-mix(in srgb, var(--boe-token-surface-status-surface-warning, #f5b31b) 45%, transparent);
185
+ background: color-mix(in srgb, var(--boe-token-surface-status-surface-warning, #f5b31b) 8%, var(--boe-token-surface-surface, #ffffff));
186
+ }
187
+
188
+ [part="proposal"][data-decision="approved"] {
189
+ border-color: color-mix(in srgb, var(--boe-token-surface-status-surface-success, #26a27b) 45%, transparent);
190
+ background: color-mix(in srgb, var(--boe-token-surface-status-surface-success, #26a27b) 8%, var(--boe-token-surface-surface, #ffffff));
191
+ }
192
+
193
+ [part="proposal"][data-decision="rejected"] {
194
+ border-color: color-mix(in srgb, var(--boe-token-surface-status-surface-error, #ed3757) 45%, transparent);
195
+ background: color-mix(in srgb, var(--boe-token-surface-status-surface-error, #ed3757) 6%, var(--boe-token-surface-surface, #ffffff));
196
+ }
197
+
198
+ [part="proposal-title"] {
199
+ font-weight: 700;
200
+ font-size: 0.88rem;
201
+ color: var(--boe-token-text-text, #1f1e1b);
202
+ }
203
+
204
+ [part="proposal-summary"],
205
+ [part="proposal-note"] {
206
+ margin: 0;
207
+ font-size: 0.82rem;
208
+ color: var(--boe-token-text-text-secondary, #6f6f6f);
209
+ }
210
+
211
+ [part="proposal-params"] {
212
+ margin: 0;
213
+ display: grid;
214
+ grid-template-columns: auto 1fr;
215
+ gap: 0.15rem 0.5rem;
216
+ font-size: 0.8rem;
217
+ }
218
+
219
+ [part="param-label"] {
220
+ color: var(--boe-token-text-text-secondary, #6f6f6f);
221
+ }
222
+
223
+ [part="param-value"] {
224
+ margin: 0;
225
+ color: var(--boe-token-text-text, #1f1e1b);
226
+ }
227
+
228
+ [part="proposal-actions"] {
229
+ display: flex;
230
+ flex-wrap: wrap;
231
+ gap: 0.4rem;
232
+ }
233
+
234
+ [part="proposal-action"] {
235
+ appearance: none;
236
+ font: inherit;
237
+ font-size: 0.78rem;
238
+ font-weight: 600;
239
+ padding: 0.26rem 0.65rem;
240
+ border-radius: 999px;
241
+ border: 1px solid color-mix(in srgb, var(--boe-token-stroke-stroke, #e8e8e8) 60%, transparent);
242
+ background: var(--boe-token-surface-surface, #ffffff);
243
+ color: inherit;
244
+ cursor: pointer;
245
+ transition: background ${boeMotionDuration.interactive} ${boeMotionEasing.standard};
246
+ }
247
+
248
+ [part="proposal-action"]:hover {
249
+ background: var(--boe-token-surface-surface-hover, #f4f4f4);
250
+ }
251
+
252
+ [part="proposal-action"][data-action="approve"] {
253
+ border-color: color-mix(in srgb, var(--boe-token-surface-status-surface-success, #26a27b) 55%, transparent);
254
+ color: color-mix(in srgb, var(--boe-token-surface-status-surface-success, #26a27b) 62%, black 38%);
255
+ }
256
+
257
+ [part="proposal-action"][data-action="reject"] {
258
+ border-color: color-mix(in srgb, var(--boe-token-surface-status-surface-error, #ed3757) 45%, transparent);
259
+ color: color-mix(in srgb, var(--boe-token-surface-status-surface-error, #ed3757) 74%, black 26%);
260
+ }
261
+
262
+ [part="proposal-action"]:focus-visible {
263
+ outline: none;
264
+ box-shadow: 0 0 0 3px color-mix(in srgb, var(--boe-token-surface-surface-brand, #0061d5) 18%, transparent);
265
+ }
266
+
267
+ [part="decision"] {
268
+ display: inline-flex;
269
+ padding: 0.12rem 0.45rem;
270
+ border-radius: 999px;
271
+ font-size: 0.72rem;
272
+ font-weight: 700;
273
+ background: var(--boe-token-surface-item-surface-selected, #f2f7fd);
274
+ color: var(--boe-token-text-text-secondary, #6f6f6f);
275
+ }
276
+
277
+ [part="empty"] {
278
+ padding: ${boePanel.padding};
279
+ border-radius: ${boeRadius.large};
280
+ border: 1px dashed color-mix(in srgb, var(--boe-token-stroke-stroke, #e8e8e8) 70%, transparent);
281
+ color: var(--boe-token-text-text-secondary, #6f6f6f);
282
+ }
283
+
284
+ [part="composer"] {
285
+ display: grid;
286
+ gap: 0.4rem;
287
+ }
288
+
289
+ [part="input"] {
290
+ font: inherit;
291
+ font-size: 0.9rem;
292
+ padding: 0.5rem 0.6rem;
293
+ border-radius: ${boeRadius.med};
294
+ border: 1px solid color-mix(in srgb, var(--boe-token-stroke-stroke, #e8e8e8) 70%, transparent);
295
+ background: var(--boe-token-surface-surface, #ffffff);
296
+ color: inherit;
297
+ resize: vertical;
298
+ min-block-size: 3.5rem;
299
+ }
300
+
301
+ [part="input"]:focus-visible {
302
+ outline: none;
303
+ border-color: var(--boe-token-surface-surface-brand, #0061d5);
304
+ box-shadow: 0 0 0 3px color-mix(in srgb, var(--boe-token-surface-surface-brand, #0061d5) 18%, transparent);
305
+ }
306
+
307
+ [part="composer-actions"] {
308
+ display: flex;
309
+ gap: 0.4rem;
310
+ justify-content: flex-end;
311
+ }
312
+
313
+ [part="send"],
314
+ [part="stop"] {
315
+ appearance: none;
316
+ font: inherit;
317
+ font-size: 0.82rem;
318
+ font-weight: 600;
319
+ padding: 0.35rem 0.85rem;
320
+ border-radius: 999px;
321
+ border: 1px solid transparent;
322
+ cursor: pointer;
323
+ transition: background ${boeMotionDuration.interactive} ${boeMotionEasing.standard};
324
+ }
325
+
326
+ [part="send"] {
327
+ background: var(--boe-token-surface-surface-brand, #0061d5);
328
+ color: var(--boe-token-text-text-on-brand, #ffffff);
329
+ }
330
+
331
+ [part="send"]:disabled {
332
+ opacity: 0.5;
333
+ cursor: not-allowed;
334
+ }
335
+
336
+ [part="stop"] {
337
+ background: var(--boe-token-surface-surface, #ffffff);
338
+ border-color: color-mix(in srgb, var(--boe-token-stroke-stroke, #e8e8e8) 60%, transparent);
339
+ color: inherit;
340
+ }
341
+
342
+ [part="send"]:focus-visible,
343
+ [part="stop"]:focus-visible {
344
+ outline: none;
345
+ box-shadow: 0 0 0 3px color-mix(in srgb, var(--boe-token-surface-surface-brand, #0061d5) 30%, transparent);
346
+ }
347
+ `;
348
+ /**
349
+ * The agent conversation surface (opportunity 1 of the component roadmap):
350
+ * a streaming message thread over the headless `AgentChatController`, with
351
+ * the two card types that matter more than the bubbles — citation chips
352
+ * (same contract as `box-timeline` evidence, deep-linking into a preview)
353
+ * and human-in-the-loop action cards where the agent's proposed action is
354
+ * approved or rejected inline.
355
+ *
356
+ * The composer lives outside the patched thread region, so a streaming
357
+ * reply never disturbs what the user is typing.
358
+ */
359
+ export class AgentChat extends BaseElement {
360
+ static tagName = DEFAULT_TAG_NAME;
361
+ static get observedAttributes() {
362
+ return ["agent-name", "heading", "placeholder", "token"];
363
+ }
364
+ controller = null;
365
+ ownsController = false;
366
+ pendingStart = false;
367
+ unsubscribeFns = [];
368
+ transportValue = null;
369
+ threadEl;
370
+ inputEl;
371
+ sendEl;
372
+ stopEl;
373
+ statusEl;
374
+ get heading() {
375
+ return this.getAttribute("heading") ?? "Agent";
376
+ }
377
+ set heading(value) {
378
+ this.setAttribute("heading", value);
379
+ }
380
+ get token() {
381
+ return this.getAttribute("token");
382
+ }
383
+ set token(value) {
384
+ if (!value) {
385
+ this.removeAttribute("token");
386
+ return;
387
+ }
388
+ this.setAttribute("token", value);
389
+ }
390
+ /** Display name on agent bubbles. */
391
+ get agentName() {
392
+ return this.getAttribute("agent-name") ?? "Agent";
393
+ }
394
+ set agentName(value) {
395
+ this.setAttribute("agent-name", value);
396
+ }
397
+ get placeholder() {
398
+ return this.getAttribute("placeholder") ?? "Ask the agent…";
399
+ }
400
+ set placeholder(value) {
401
+ this.setAttribute("placeholder", value);
402
+ }
403
+ get transport() {
404
+ return this.transportValue;
405
+ }
406
+ set transport(value) {
407
+ this.transportValue = value;
408
+ this.scheduleStart();
409
+ }
410
+ /**
411
+ * The live session controller. Assign one to share a conversation with
412
+ * another surface; otherwise the element creates and owns its own from
413
+ * `transport` + `token`.
414
+ */
415
+ get chatController() {
416
+ return this.controller;
417
+ }
418
+ set chatController(value) {
419
+ this.adoptController(value);
420
+ }
421
+ attributeChangedCallback(name, oldValue, newValue) {
422
+ if (name === "token") {
423
+ this.scheduleStart();
424
+ }
425
+ else if (name === "agent-name") {
426
+ // A display label must never discard the conversation: keep the live
427
+ // session and just refresh what new replies will be stamped with.
428
+ if (this.controller && this.ownsController) {
429
+ this.controller.config.agentName = this.agentName;
430
+ }
431
+ if (this.isRendered) {
432
+ this.update();
433
+ }
434
+ }
435
+ super.attributeChangedCallback(name, oldValue, newValue);
436
+ }
437
+ connectedCallback() {
438
+ super.connectedCallback();
439
+ this.scheduleStart();
440
+ }
441
+ disconnectedCallback() {
442
+ this.teardownController();
443
+ }
444
+ /** Send the composer's contents (or an explicit body) as a user turn. */
445
+ async send(body) {
446
+ const text = body ?? this.inputEl?.value ?? "";
447
+ if (!text.trim()) {
448
+ return;
449
+ }
450
+ // Clear only once the controller has accepted the turn, so a refused
451
+ // send (no controller, or a disconnected session) never loses typing.
452
+ const sent = await this.controller?.send(text);
453
+ if (sent && body === undefined && this.inputEl) {
454
+ this.inputEl.value = "";
455
+ this.syncComposer();
456
+ }
457
+ }
458
+ /** Stop the in-flight generation; the partial reply is kept. */
459
+ stop() {
460
+ this.controller?.stop();
461
+ }
462
+ scheduleStart() {
463
+ if (this.pendingStart) {
464
+ return;
465
+ }
466
+ this.pendingStart = true;
467
+ queueMicrotask(() => {
468
+ this.pendingStart = false;
469
+ this.startController();
470
+ });
471
+ }
472
+ startController() {
473
+ if (!this.isConnected || (this.controller && !this.ownsController)) {
474
+ return;
475
+ }
476
+ if (!this.transportValue || !this.token) {
477
+ this.teardownController();
478
+ if (this.isRendered) {
479
+ this.update();
480
+ }
481
+ return;
482
+ }
483
+ this.teardownController();
484
+ const controller = new AgentChatController({
485
+ token: this.token,
486
+ transport: this.transportValue,
487
+ agentName: this.agentName,
488
+ });
489
+ this.controller = controller;
490
+ this.ownsController = true;
491
+ this.subscribeToController(controller);
492
+ controller.connect();
493
+ if (this.isRendered) {
494
+ this.update();
495
+ }
496
+ }
497
+ adoptController(controller) {
498
+ this.teardownController();
499
+ if (!controller) {
500
+ if (this.isRendered) {
501
+ this.update();
502
+ }
503
+ // Fall back to the documented owned session from transport + token.
504
+ this.scheduleStart();
505
+ return;
506
+ }
507
+ this.controller = controller;
508
+ this.ownsController = false;
509
+ this.subscribeToController(controller);
510
+ if (this.isRendered) {
511
+ this.update();
512
+ }
513
+ }
514
+ subscribeToController(controller) {
515
+ const events = [
516
+ ["messagesChanged", "messages-changed"],
517
+ ["streamingChanged", "streaming-changed"],
518
+ ["sendFailed", "send-failed"],
519
+ ["actionResolved", "action-resolved"],
520
+ ];
521
+ this.unsubscribeFns = events.map(([eventName, domEventName]) => controller.subscribe(eventName, payload => {
522
+ this.dispatchEvent(new CustomEvent(domEventName, {
523
+ bubbles: true,
524
+ composed: true,
525
+ detail: payload,
526
+ }));
527
+ if (this.isRendered) {
528
+ this.update();
529
+ }
530
+ }));
531
+ }
532
+ teardownController() {
533
+ for (const unsubscribe of this.unsubscribeFns) {
534
+ unsubscribe();
535
+ }
536
+ this.unsubscribeFns = [];
537
+ if (this.controller && this.ownsController) {
538
+ this.controller.disconnect();
539
+ this.controller.destroy();
540
+ }
541
+ this.controller = null;
542
+ this.ownsController = false;
543
+ }
544
+ citationHtml(messageId, citation) {
545
+ const attrs = `part="citation" data-message-id="${escapeHtml(messageId)}" data-citation-id="${escapeHtml(citation.id)}"`;
546
+ // Unsafe hrefs downgrade to buttons — the host still gets the event.
547
+ return citation.href && isSafeHref(citation.href)
548
+ ? `<a ${attrs} href="${escapeHtml(citation.href)}">${escapeHtml(citation.label)}</a>`
549
+ : `<button type="button" ${attrs}>${escapeHtml(citation.label)}</button>`;
550
+ }
551
+ proposalHtml(message) {
552
+ const canResolve = Boolean(this.controller?.config.transport.resolveAction);
553
+ return message.proposals
554
+ .map(proposal => {
555
+ const params = (proposal.params ?? [])
556
+ .map(param => `
557
+ <dt part="param-label">${escapeHtml(param.label)}</dt>
558
+ <dd part="param-value">${escapeHtml(param.value)}</dd>
559
+ `)
560
+ .join("");
561
+ const actions = canResolve && !proposal.decision
562
+ ? `
563
+ <div part="proposal-actions">
564
+ <button type="button" part="proposal-action" data-action="approve" data-proposal-id="${escapeHtml(proposal.id)}">Approve</button>
565
+ <button type="button" part="proposal-action" data-action="reject" data-proposal-id="${escapeHtml(proposal.id)}">Reject</button>
566
+ <button type="button" part="proposal-action" data-action="modify" data-proposal-id="${escapeHtml(proposal.id)}">Modify</button>
567
+ </div>
568
+ `
569
+ : "";
570
+ return `
571
+ <div part="proposal" data-proposal-id="${escapeHtml(proposal.id)}"${proposal.decision ? ` data-decision="${escapeHtml(proposal.decision)}"` : ""}>
572
+ <span part="proposal-title">${escapeHtml(proposal.title)}</span>
573
+ ${proposal.summary ? `<p part="proposal-summary">${escapeHtml(proposal.summary)}</p>` : ""}
574
+ ${params ? `<dl part="proposal-params">${params}</dl>` : ""}
575
+ ${proposal.decision ? `<span part="decision">${proposal.decision === "approved" ? "Approved" : "Rejected"}</span>` : ""}
576
+ ${proposal.note ? `<p part="proposal-note">${escapeHtml(proposal.note)}</p>` : ""}
577
+ ${actions}
578
+ </div>
579
+ `;
580
+ })
581
+ .join("");
582
+ }
583
+ messageInnerHtml(message) {
584
+ const name = message.role === "user" ? "You" : (message.actor?.name ?? this.agentName);
585
+ const initials = message.actor?.initials ?? initialsOf(name);
586
+ const citations = message.citations
587
+ .map(citation => this.citationHtml(message.id, citation))
588
+ .join("");
589
+ return `
590
+ <div part="message-header">
591
+ <span part="avatar" aria-hidden="true">${escapeHtml(initials)}</span>
592
+ <span part="author">${escapeHtml(name)}</span>
593
+ </div>
594
+ <p part="body">${escapeHtml(message.body)}${message.status === "streaming" ? `<span part="caret" aria-hidden="true"></span>` : ""}</p>
595
+ ${message.status === "error" && message.errorMessage ? `<p part="error" role="alert">${escapeHtml(message.errorMessage)}</p>` : ""}
596
+ ${citations ? `<div part="citations">${citations}</div>` : ""}
597
+ ${this.proposalHtml(message)}
598
+ `;
599
+ }
600
+ /**
601
+ * Everything about a message except its body text. While this is stable,
602
+ * a delta only rewrites one text node — so `role="log"` sees no additions
603
+ * and assistive tech does not re-announce the conversation per token.
604
+ */
605
+ messageSignature(message) {
606
+ // Every non-body field this renders must be here, or a changed label,
607
+ // title, or param would keep the old markup on the fast path.
608
+ return JSON.stringify({
609
+ status: message.status,
610
+ errorMessage: message.errorMessage ?? "",
611
+ actor: {
612
+ name: message.actor?.name ?? "",
613
+ initials: message.actor?.initials ?? "",
614
+ },
615
+ agentName: this.agentName,
616
+ citations: message.citations.map(({ id, href, label }) => ({ id, href, label })),
617
+ proposals: message.proposals.map(({ id, title, summary, params, decision, note }) => ({
618
+ id,
619
+ title,
620
+ summary,
621
+ params,
622
+ decision,
623
+ note,
624
+ })),
625
+ resolvable: Boolean(this.controller?.config.transport.resolveAction),
626
+ });
627
+ }
628
+ createMessageNode(message) {
629
+ const template = document.createElement("template");
630
+ template.innerHTML = `
631
+ <li part="message" data-message-id="${escapeHtml(message.id)}" data-role="${escapeHtml(message.role)}" data-status="${escapeHtml(message.status)}" data-signature="${escapeHtml(this.messageSignature(message))}">
632
+ ${this.messageInnerHtml(message)}
633
+ </li>
634
+ `.trim();
635
+ return template.content.firstElementChild;
636
+ }
637
+ /** The streaming hot path: one text-node write, nothing else touched. */
638
+ patchBody(node, message) {
639
+ const body = node.querySelector('[part="body"]');
640
+ if (!body) {
641
+ return;
642
+ }
643
+ const first = body.firstChild;
644
+ if (first && first.nodeType === Node.TEXT_NODE) {
645
+ if (first.textContent !== message.body) {
646
+ first.textContent = message.body;
647
+ }
648
+ return;
649
+ }
650
+ body.insertBefore(document.createTextNode(message.body), body.firstChild);
651
+ }
652
+ renderTemplate() {
653
+ if (!this.shadowRoot) {
654
+ return;
655
+ }
656
+ // The composer is part of the stable shell: a streaming reply patches
657
+ // only [part="thread"], so typing is never interrupted.
658
+ this.shadowRoot.innerHTML = `
659
+ <style>${elementStyles}</style>
660
+ <section part="panel">
661
+ <div part="header">
662
+ <h2 part="title"></h2>
663
+ <span part="status" role="status" aria-live="polite"></span>
664
+ </div>
665
+ <ol part="thread" role="log" aria-live="polite" aria-relevant="additions"></ol>
666
+ <div part="composer">
667
+ <textarea part="input" rows="2"></textarea>
668
+ <div part="composer-actions">
669
+ <button type="button" part="stop" hidden>Stop</button>
670
+ <button type="button" part="send">Send</button>
671
+ </div>
672
+ </div>
673
+ </section>
674
+ `;
675
+ this.threadEl = this.shadowRoot.querySelector('[part="thread"]');
676
+ this.inputEl = this.shadowRoot.querySelector('[part="input"]');
677
+ this.sendEl = this.shadowRoot.querySelector('[part="send"]');
678
+ this.stopEl = this.shadowRoot.querySelector('[part="stop"]');
679
+ this.statusEl = this.shadowRoot.querySelector('[part="status"]');
680
+ }
681
+ setupListeners() {
682
+ this.sendEl.addEventListener("click", () => {
683
+ void this.send();
684
+ });
685
+ this.stopEl.addEventListener("click", () => {
686
+ this.stop();
687
+ });
688
+ this.inputEl.addEventListener("keydown", event => {
689
+ // Enter sends, Shift+Enter makes a newline — the conversational default.
690
+ if (event.key === "Enter" && !event.shiftKey) {
691
+ event.preventDefault();
692
+ void this.send();
693
+ }
694
+ });
695
+ this.inputEl.addEventListener("input", () => {
696
+ this.syncComposer();
697
+ });
698
+ this.threadEl.addEventListener("click", event => {
699
+ const target = event.target;
700
+ const proposalButton = target.closest('[part="proposal-action"]');
701
+ if (proposalButton && this.threadEl.contains(proposalButton)) {
702
+ const proposalId = proposalButton.getAttribute("data-proposal-id") ?? "";
703
+ const action = proposalButton.getAttribute("data-action") ?? "";
704
+ if (action === "approve") {
705
+ void this.controller?.resolveAction(proposalId, "approved");
706
+ }
707
+ else if (action === "reject") {
708
+ void this.controller?.resolveAction(proposalId, "rejected");
709
+ }
710
+ else if (action === "modify") {
711
+ // Modifying needs the host's own editor, so this surfaces intent.
712
+ this.dispatchEvent(new CustomEvent("proposal-modify-requested", {
713
+ bubbles: true,
714
+ composed: true,
715
+ detail: { proposalId },
716
+ }));
717
+ }
718
+ return;
719
+ }
720
+ const citation = target.closest('[part="citation"]');
721
+ if (citation && this.threadEl.contains(citation)) {
722
+ const messageId = citation.getAttribute("data-message-id") ?? "";
723
+ const citationId = citation.getAttribute("data-citation-id") ?? "";
724
+ const message = this.controller?.getMessage(messageId);
725
+ const found = message?.citations.find(entry => entry.id === citationId);
726
+ if (found) {
727
+ this.dispatchEvent(new CustomEvent("citation-selected", {
728
+ bubbles: true,
729
+ composed: true,
730
+ detail: { citation: found, messageId },
731
+ }));
732
+ }
733
+ }
734
+ });
735
+ }
736
+ /** Composer affordances reflect stream state without rebuilding the input. */
737
+ syncComposer() {
738
+ const streaming = this.controller?.getState().streaming ?? false;
739
+ this.inputEl.placeholder = this.placeholder;
740
+ this.sendEl.disabled = streaming || this.inputEl.value.trim().length === 0;
741
+ this.stopEl.hidden = !streaming;
742
+ this.statusEl.textContent = streaming ? "Agent is responding…" : "";
743
+ }
744
+ update() {
745
+ if (!this.threadEl) {
746
+ return;
747
+ }
748
+ const active = this.shadowRoot?.activeElement;
749
+ const focusKey = active && this.threadEl.contains(active)
750
+ ? {
751
+ part: active.getAttribute("part") ?? "",
752
+ proposalId: active.getAttribute("data-proposal-id"),
753
+ citationId: active.getAttribute("data-citation-id"),
754
+ action: active.getAttribute("data-action"),
755
+ }
756
+ : null;
757
+ const state = this.controller?.getState() ?? null;
758
+ const messages = state?.messages ?? [];
759
+ const atBottom = this.threadEl.scrollHeight - this.threadEl.scrollTop - this.threadEl.clientHeight < 40;
760
+ this.shadowRoot.querySelector('[part="title"]').textContent = this.heading;
761
+ if (messages.length === 0) {
762
+ if (!this.threadEl.querySelector('[part="empty"]')) {
763
+ this.threadEl.innerHTML = `<li part="empty">No messages yet.</li>`;
764
+ }
765
+ this.syncComposer();
766
+ return;
767
+ }
768
+ this.threadEl.querySelector('[part="empty"]')?.remove();
769
+ // Reconcile by message id so a streaming delta touches one text node
770
+ // rather than replacing every list item.
771
+ const existing = new Map();
772
+ for (const node of Array.from(this.threadEl.children)) {
773
+ const id = node.getAttribute("data-message-id");
774
+ if (id) {
775
+ existing.set(id, node);
776
+ }
777
+ }
778
+ let previous = null;
779
+ for (const message of messages) {
780
+ let node = existing.get(message.id);
781
+ if (node) {
782
+ existing.delete(message.id);
783
+ const signature = this.messageSignature(message);
784
+ if (node.getAttribute("data-signature") === signature) {
785
+ this.patchBody(node, message);
786
+ }
787
+ else {
788
+ node.setAttribute("data-signature", signature);
789
+ node.setAttribute("data-status", message.status);
790
+ node.innerHTML = this.messageInnerHtml(message);
791
+ }
792
+ }
793
+ else {
794
+ node = this.createMessageNode(message);
795
+ }
796
+ const anchor = previous
797
+ ? previous.nextSibling
798
+ : this.threadEl.firstChild;
799
+ if (node !== anchor) {
800
+ this.threadEl.insertBefore(node, anchor);
801
+ }
802
+ previous = node;
803
+ }
804
+ for (const stale of existing.values()) {
805
+ stale.remove();
806
+ }
807
+ if (focusKey?.part) {
808
+ const target = Array.from(this.threadEl.querySelectorAll(`[part="${focusKey.part}"]`)).find(node => node.getAttribute("data-proposal-id") === focusKey.proposalId &&
809
+ node.getAttribute("data-citation-id") === focusKey.citationId &&
810
+ (!focusKey.action || node.getAttribute("data-action") === focusKey.action));
811
+ target?.focus();
812
+ }
813
+ // Follow the stream only when the reader is already at the bottom.
814
+ if (atBottom) {
815
+ this.threadEl.scrollTop = this.threadEl.scrollHeight;
816
+ }
817
+ this.syncComposer();
818
+ }
819
+ }
820
+ AgentChat.register();