pixelize-design-library 3.1.1 → 3.2.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 (140) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/COMPONENT-GOTCHAS.md +29 -0
  3. package/DESIGN-GUIDE.md +27 -0
  4. package/README.md +8 -8
  5. package/dist/Components/Assistant/assistantModel.d.ts +17 -0
  6. package/dist/Components/Assistant/assistantModel.js +35 -0
  7. package/dist/Components/Assistant/assistantStyles.d.ts +27 -0
  8. package/dist/Components/Assistant/assistantStyles.js +53 -0
  9. package/dist/Components/Assistant/assistantTypes.d.ts +163 -0
  10. package/dist/Components/Assistant/assistantTypes.js +2 -0
  11. package/dist/Components/Assistant/banner/AssistantStatusBanner.d.ts +3 -0
  12. package/dist/Components/Assistant/banner/AssistantStatusBanner.js +25 -0
  13. package/dist/Components/Assistant/banner/AssistantStatusBannerProps.d.ts +27 -0
  14. package/dist/Components/Assistant/banner/AssistantStatusBannerProps.js +2 -0
  15. package/dist/Components/Assistant/cards/AssistantApprovalCard.d.ts +3 -0
  16. package/dist/Components/Assistant/cards/AssistantApprovalCard.js +51 -0
  17. package/dist/Components/Assistant/cards/AssistantApprovalCardProps.d.ts +66 -0
  18. package/dist/Components/Assistant/cards/AssistantApprovalCardProps.js +2 -0
  19. package/dist/Components/Assistant/cards/AssistantProposalCard.d.ts +3 -0
  20. package/dist/Components/Assistant/cards/AssistantProposalCard.js +36 -0
  21. package/dist/Components/Assistant/cards/AssistantProposalCardProps.d.ts +56 -0
  22. package/dist/Components/Assistant/cards/AssistantProposalCardProps.js +2 -0
  23. package/dist/Components/Assistant/cards/CardShell.d.ts +31 -0
  24. package/dist/Components/Assistant/cards/CardShell.js +32 -0
  25. package/dist/Components/Assistant/composer/AssistantComposer.d.ts +3 -0
  26. package/dist/Components/Assistant/composer/AssistantComposer.js +264 -0
  27. package/dist/Components/Assistant/composer/AssistantComposerProps.d.ts +128 -0
  28. package/dist/Components/Assistant/composer/AssistantComposerProps.js +2 -0
  29. package/dist/Components/Assistant/composer/ComposerMenu.d.ts +24 -0
  30. package/dist/Components/Assistant/composer/ComposerMenu.js +38 -0
  31. package/dist/Components/Assistant/composer/composerLogic.d.ts +19 -0
  32. package/dist/Components/Assistant/composer/composerLogic.js +65 -0
  33. package/dist/Components/Assistant/context/AssistantContextBar.d.ts +3 -0
  34. package/dist/Components/Assistant/context/AssistantContextBar.js +27 -0
  35. package/dist/Components/Assistant/context/AssistantContextBarProps.d.ts +34 -0
  36. package/dist/Components/Assistant/context/AssistantContextBarProps.js +2 -0
  37. package/dist/Components/Assistant/history/AssistantHistoryList.d.ts +3 -0
  38. package/dist/Components/Assistant/history/AssistantHistoryList.js +123 -0
  39. package/dist/Components/Assistant/history/AssistantHistoryListProps.d.ts +83 -0
  40. package/dist/Components/Assistant/history/AssistantHistoryListProps.js +2 -0
  41. package/dist/Components/Assistant/history/groupConversations.d.ts +12 -0
  42. package/dist/Components/Assistant/history/groupConversations.js +55 -0
  43. package/dist/Components/Assistant/index.d.ts +16 -0
  44. package/dist/Components/Assistant/index.js +38 -0
  45. package/dist/Components/Assistant/launcher/AssistantLauncher.d.ts +3 -0
  46. package/dist/Components/Assistant/launcher/AssistantLauncher.js +45 -0
  47. package/dist/Components/Assistant/launcher/AssistantLauncherProps.d.ts +37 -0
  48. package/dist/Components/Assistant/launcher/AssistantLauncherProps.js +2 -0
  49. package/dist/Components/Assistant/markdown/AssistantMarkdown.d.ts +3 -0
  50. package/dist/Components/Assistant/markdown/AssistantMarkdown.js +146 -0
  51. package/dist/Components/Assistant/markdown/AssistantMarkdownProps.d.ts +38 -0
  52. package/dist/Components/Assistant/markdown/AssistantMarkdownProps.js +2 -0
  53. package/dist/Components/Assistant/markdown/parseMarkdown.d.ts +74 -0
  54. package/dist/Components/Assistant/markdown/parseMarkdown.js +328 -0
  55. package/dist/Components/Assistant/markdown/safeHref.d.ts +21 -0
  56. package/dist/Components/Assistant/markdown/safeHref.js +28 -0
  57. package/dist/Components/Assistant/message/AssistantMessage.d.ts +3 -0
  58. package/dist/Components/Assistant/message/AssistantMessage.js +131 -0
  59. package/dist/Components/Assistant/message/AssistantMessageProps.d.ts +83 -0
  60. package/dist/Components/Assistant/message/AssistantMessageProps.js +2 -0
  61. package/dist/Components/Assistant/message/MessageActions.d.ts +16 -0
  62. package/dist/Components/Assistant/message/MessageActions.js +23 -0
  63. package/dist/Components/Assistant/panel/AssistantPanel.d.ts +3 -0
  64. package/dist/Components/Assistant/panel/AssistantPanel.js +87 -0
  65. package/dist/Components/Assistant/panel/AssistantPanelProps.d.ts +86 -0
  66. package/dist/Components/Assistant/panel/AssistantPanelProps.js +2 -0
  67. package/dist/Components/Assistant/panel/ResizeHandle.d.ts +14 -0
  68. package/dist/Components/Assistant/panel/ResizeHandle.js +72 -0
  69. package/dist/Components/Assistant/sources/AssistantSources.d.ts +3 -0
  70. package/dist/Components/Assistant/sources/AssistantSources.js +63 -0
  71. package/dist/Components/Assistant/sources/AssistantSourcesProps.d.ts +29 -0
  72. package/dist/Components/Assistant/sources/AssistantSourcesProps.js +2 -0
  73. package/dist/Components/Assistant/steps/AssistantToolSteps.d.ts +3 -0
  74. package/dist/Components/Assistant/steps/AssistantToolSteps.js +41 -0
  75. package/dist/Components/Assistant/steps/AssistantToolStepsProps.d.ts +37 -0
  76. package/dist/Components/Assistant/steps/AssistantToolStepsProps.js +2 -0
  77. package/dist/Components/Assistant/suggestions/AssistantSuggestions.d.ts +3 -0
  78. package/dist/Components/Assistant/suggestions/AssistantSuggestions.js +18 -0
  79. package/dist/Components/Assistant/suggestions/AssistantSuggestionsProps.d.ts +15 -0
  80. package/dist/Components/Assistant/suggestions/AssistantSuggestionsProps.js +2 -0
  81. package/dist/Components/Assistant/thread/AssistantThread.d.ts +3 -0
  82. package/dist/Components/Assistant/thread/AssistantThread.js +112 -0
  83. package/dist/Components/Assistant/thread/AssistantThreadProps.d.ts +37 -0
  84. package/dist/Components/Assistant/thread/AssistantThreadProps.js +2 -0
  85. package/dist/Components/Assistant/typing/AssistantTypingIndicator.d.ts +3 -0
  86. package/dist/Components/Assistant/typing/AssistantTypingIndicator.js +33 -0
  87. package/dist/Components/Assistant/typing/AssistantTypingIndicatorProps.d.ts +9 -0
  88. package/dist/Components/Assistant/typing/AssistantTypingIndicatorProps.js +2 -0
  89. package/dist/Components/Assistant/welcome/AssistantWelcome.d.ts +3 -0
  90. package/dist/Components/Assistant/welcome/AssistantWelcome.js +30 -0
  91. package/dist/Components/Assistant/welcome/AssistantWelcomeProps.d.ts +40 -0
  92. package/dist/Components/Assistant/welcome/AssistantWelcomeProps.js +2 -0
  93. package/dist/esm/Components/Assistant/assistantModel.js +29 -0
  94. package/dist/esm/Components/Assistant/assistantStyles.js +47 -0
  95. package/dist/esm/Components/Assistant/assistantTypes.js +1 -0
  96. package/dist/esm/Components/Assistant/banner/AssistantStatusBanner.js +20 -0
  97. package/dist/esm/Components/Assistant/banner/AssistantStatusBannerProps.js +1 -0
  98. package/dist/esm/Components/Assistant/cards/AssistantApprovalCard.js +46 -0
  99. package/dist/esm/Components/Assistant/cards/AssistantApprovalCardProps.js +1 -0
  100. package/dist/esm/Components/Assistant/cards/AssistantProposalCard.js +31 -0
  101. package/dist/esm/Components/Assistant/cards/AssistantProposalCardProps.js +1 -0
  102. package/dist/esm/Components/Assistant/cards/CardShell.js +23 -0
  103. package/dist/esm/Components/Assistant/composer/AssistantComposer.js +259 -0
  104. package/dist/esm/Components/Assistant/composer/AssistantComposerProps.js +1 -0
  105. package/dist/esm/Components/Assistant/composer/ComposerMenu.js +30 -0
  106. package/dist/esm/Components/Assistant/composer/composerLogic.js +56 -0
  107. package/dist/esm/Components/Assistant/context/AssistantContextBar.js +22 -0
  108. package/dist/esm/Components/Assistant/context/AssistantContextBarProps.js +1 -0
  109. package/dist/esm/Components/Assistant/history/AssistantHistoryList.js +118 -0
  110. package/dist/esm/Components/Assistant/history/AssistantHistoryListProps.js +1 -0
  111. package/dist/esm/Components/Assistant/history/groupConversations.js +51 -0
  112. package/dist/esm/Components/Assistant/index.js +16 -0
  113. package/dist/esm/Components/Assistant/launcher/AssistantLauncher.js +40 -0
  114. package/dist/esm/Components/Assistant/launcher/AssistantLauncherProps.js +1 -0
  115. package/dist/esm/Components/Assistant/markdown/AssistantMarkdown.js +141 -0
  116. package/dist/esm/Components/Assistant/markdown/AssistantMarkdownProps.js +1 -0
  117. package/dist/esm/Components/Assistant/markdown/parseMarkdown.js +322 -0
  118. package/dist/esm/Components/Assistant/markdown/safeHref.js +23 -0
  119. package/dist/esm/Components/Assistant/message/AssistantMessage.js +126 -0
  120. package/dist/esm/Components/Assistant/message/AssistantMessageProps.js +1 -0
  121. package/dist/esm/Components/Assistant/message/MessageActions.js +16 -0
  122. package/dist/esm/Components/Assistant/panel/AssistantPanel.js +82 -0
  123. package/dist/esm/Components/Assistant/panel/AssistantPanelProps.js +1 -0
  124. package/dist/esm/Components/Assistant/panel/ResizeHandle.js +68 -0
  125. package/dist/esm/Components/Assistant/sources/AssistantSources.js +58 -0
  126. package/dist/esm/Components/Assistant/sources/AssistantSourcesProps.js +1 -0
  127. package/dist/esm/Components/Assistant/steps/AssistantToolSteps.js +36 -0
  128. package/dist/esm/Components/Assistant/steps/AssistantToolStepsProps.js +1 -0
  129. package/dist/esm/Components/Assistant/suggestions/AssistantSuggestions.js +13 -0
  130. package/dist/esm/Components/Assistant/suggestions/AssistantSuggestionsProps.js +1 -0
  131. package/dist/esm/Components/Assistant/thread/AssistantThread.js +107 -0
  132. package/dist/esm/Components/Assistant/thread/AssistantThreadProps.js +1 -0
  133. package/dist/esm/Components/Assistant/typing/AssistantTypingIndicator.js +28 -0
  134. package/dist/esm/Components/Assistant/typing/AssistantTypingIndicatorProps.js +1 -0
  135. package/dist/esm/Components/Assistant/welcome/AssistantWelcome.js +25 -0
  136. package/dist/esm/Components/Assistant/welcome/AssistantWelcomeProps.js +1 -0
  137. package/dist/esm/index.js +2 -0
  138. package/dist/index.d.ts +18 -0
  139. package/dist/index.js +20 -1
  140. package/package.json +1 -1
@@ -0,0 +1,328 @@
1
+ "use strict";
2
+ /**
3
+ * A small hand-rolled markdown parser for model output: no dependencies, no HTML, never throws.
4
+ * Ported from Mobile-Components `src/modules/markdown/parseMarkdown.ts` and extended with nesting
5
+ * (lists and quotes), images (as inert alt text), autolinks, escapes, ordered-list starts, table
6
+ * alignment and hard line breaks. Malformed input degrades to literal text; an unclosed fence swallows
7
+ * the rest of the input as code, which is what a half-streamed answer looks like.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.markdownToPlainText = exports.parseMarkdown = exports.parseInline = void 0;
11
+ const MAX_DEPTH = 6;
12
+ const HEADING_RE = /^ {0,3}(#{1,6})(?:\s+(.*?))?\s*#*\s*$/;
13
+ const FENCE_RE = /^ {0,3}(`{3,}|~{3,})\s*([^`\s]*)/;
14
+ const RULE_RE = /^ {0,3}([-*_])(?:\s*\1){2,}\s*$/;
15
+ const QUOTE_RE = /^ {0,3}>\s?(.*)$/;
16
+ const ITEM_RE = /^(\s*)([-*+]|\d{1,9}[.)])\s+(.*)$/;
17
+ const TASK_RE = /^\[([ xX])\]\s+(.*)$/;
18
+ const TABLE_DIVIDER_RE = /^\s*\|?\s*:?-+:?\s*(?:\|\s*:?-+:?\s*)*\|?\s*$/;
19
+ // Order matters: escapes and code spans win over everything; images before links. A URL may hold one
20
+ // level of balanced parentheses (Wikipedia-style).
21
+ const INLINE_RE = new RegExp([
22
+ String.raw `\\([\\\x60*_{}\[\]()#+\-.!~|>])`,
23
+ String.raw `(\x60+)([^\x60\n]|[^\x60\n][\s\S]*?[^\x60\n])\2(?!\x60)`,
24
+ String.raw `!\[([^\]\n]*)\]\(\s*((?:[^()\s]|\([^()\s]*\))*)(?:\s+"[^"\n]*")?\s*\)`,
25
+ String.raw `\[([^\]\n]+)\]\(\s*((?:[^()\s]|\([^()\s]*\))*)(?:\s+"[^"\n]*")?\s*\)`,
26
+ String.raw `<((?:https?:\/\/|mailto:)[^\s<>]+)>`,
27
+ String.raw `(https?:\/\/[^\s<>()\[\]]*[^\s<>()\[\].,;:!?'"*_~])`,
28
+ String.raw `~~(?=\S)([^~\n]+?)~~`,
29
+ String.raw `\*\*(?=\S)([^\n]+?)\*\*`,
30
+ String.raw `(?<![\w])__(?=\S)([^\n]+?)__(?![\w])`,
31
+ String.raw `\*(?=[^\s*])([^*\n]+?)\*`,
32
+ String.raw `(?<![\w])_(?=[^\s_])([^_\n]+?)_(?![\w])`,
33
+ ].join("|"), "g");
34
+ const mergeText = (nodes) => nodes.reduce((out, node) => {
35
+ const last = out[out.length - 1];
36
+ if (node.type === "text" && (last === null || last === void 0 ? void 0 : last.type) === "text") {
37
+ out[out.length - 1] = { type: "text", content: last.content + node.content };
38
+ }
39
+ else {
40
+ out.push(node);
41
+ }
42
+ return out;
43
+ }, []);
44
+ const parseSpan = (text, depth) => {
45
+ var _a, _b;
46
+ if (depth > MAX_DEPTH)
47
+ return [{ type: "text", content: text }];
48
+ const nodes = [];
49
+ const re = new RegExp(INLINE_RE.source, "g");
50
+ let last = 0;
51
+ for (let match = re.exec(text); match !== null; match = re.exec(text)) {
52
+ if (match[0].length === 0) {
53
+ re.lastIndex += 1;
54
+ continue;
55
+ }
56
+ if (match.index > last)
57
+ nodes.push({ type: "text", content: text.slice(last, match.index) });
58
+ const [, escaped, , code, imageAlt, imageSrc, linkText, linkHref, autolink, bareUrl, strike, bold, boldAlt, italic, italicAlt] = match;
59
+ const inner = (content) => parseSpan(content, depth + 1);
60
+ if (escaped !== undefined)
61
+ nodes.push({ type: "text", content: escaped });
62
+ else if (code !== undefined)
63
+ nodes.push({ type: "code", content: code.trim() || code });
64
+ else if (imageSrc !== undefined)
65
+ nodes.push({ type: "image", alt: (imageAlt !== null && imageAlt !== void 0 ? imageAlt : "").trim() });
66
+ else if (linkText !== undefined)
67
+ nodes.push({ type: "link", href: linkHref !== null && linkHref !== void 0 ? linkHref : "", children: inner(linkText) });
68
+ else if (autolink !== undefined)
69
+ nodes.push({ type: "link", href: autolink, children: [{ type: "text", content: autolink }] });
70
+ else if (bareUrl !== undefined)
71
+ nodes.push({ type: "link", href: bareUrl, children: [{ type: "text", content: bareUrl }] });
72
+ else if (strike !== undefined)
73
+ nodes.push({ type: "strike", children: inner(strike) });
74
+ else if (bold !== undefined || boldAlt !== undefined)
75
+ nodes.push({ type: "strong", children: inner((_a = bold !== null && bold !== void 0 ? bold : boldAlt) !== null && _a !== void 0 ? _a : "") });
76
+ else if (italic !== undefined || italicAlt !== undefined)
77
+ nodes.push({ type: "em", children: inner((_b = italic !== null && italic !== void 0 ? italic : italicAlt) !== null && _b !== void 0 ? _b : "") });
78
+ last = match.index + match[0].length;
79
+ }
80
+ if (last < text.length)
81
+ nodes.push({ type: "text", content: text.slice(last) });
82
+ return mergeText(nodes);
83
+ };
84
+ /** Inline markdown of one paragraph's lines; a line break between lines is kept as a `break` node. */
85
+ const parseInline = (text, depth = 0) => {
86
+ const lines = text.split("\n");
87
+ return mergeText(lines.flatMap((line, i) => {
88
+ const nodes = parseSpan(line.replace(/\\$/, "").trimEnd(), depth);
89
+ return i < lines.length - 1 ? [...nodes, { type: "break" }] : nodes;
90
+ }));
91
+ };
92
+ exports.parseInline = parseInline;
93
+ const splitCells = (line) => {
94
+ const cells = [];
95
+ let cell = "";
96
+ for (let k = 0; k < line.length; k += 1) {
97
+ const ch = line[k];
98
+ if (ch === "\\" && line[k + 1] === "|") {
99
+ cell += "|";
100
+ k += 1;
101
+ }
102
+ else if (ch === "|") {
103
+ cells.push(cell);
104
+ cell = "";
105
+ }
106
+ else {
107
+ cell += ch;
108
+ }
109
+ }
110
+ cells.push(cell);
111
+ const trimmed = line.trim();
112
+ if (trimmed.startsWith("|"))
113
+ cells.shift();
114
+ if (trimmed.endsWith("|") && !trimmed.endsWith("\\|"))
115
+ cells.pop();
116
+ return cells.map((c) => c.trim());
117
+ };
118
+ const alignOf = (cell) => {
119
+ const left = cell.startsWith(":");
120
+ const right = cell.endsWith(":");
121
+ if (left && right)
122
+ return "center";
123
+ if (right)
124
+ return "right";
125
+ if (left)
126
+ return "left";
127
+ return null;
128
+ };
129
+ const indentOf = (line) => {
130
+ var _a, _b;
131
+ const lead = (_b = (_a = /^\s*/.exec(line)) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : "";
132
+ return lead.replace(/\t/g, " ").length;
133
+ };
134
+ const dedent = (lines) => {
135
+ const widths = lines.filter((l) => l.trim() !== "").map(indentOf);
136
+ const min = widths.length ? Math.min(...widths) : 0;
137
+ return lines.map((l) => l.replace(/\t/g, " ").slice(Math.min(min, indentOf(l))));
138
+ };
139
+ const isBlockStart = (line) => FENCE_RE.test(line) || HEADING_RE.test(line) || RULE_RE.test(line) || QUOTE_RE.test(line) || ITEM_RE.test(line);
140
+ const isOrderedMarker = (marker) => /\d/.test(marker);
141
+ const parseBlocks = (lines, depth) => {
142
+ var _a, _b, _c, _d;
143
+ if (depth > MAX_DEPTH)
144
+ return [{ type: "paragraph", children: [{ type: "text", content: lines.join("\n") }] }];
145
+ const blocks = [];
146
+ let paragraph = [];
147
+ const flush = () => {
148
+ if (paragraph.length === 0)
149
+ return;
150
+ blocks.push({ type: "paragraph", children: (0, exports.parseInline)(paragraph.join("\n"), 0) });
151
+ paragraph = [];
152
+ };
153
+ let i = 0;
154
+ while (i < lines.length) {
155
+ const line = lines[i];
156
+ const fence = FENCE_RE.exec(line);
157
+ if (fence) {
158
+ flush();
159
+ const marker = fence[1];
160
+ const body = [];
161
+ i += 1;
162
+ // An unclosed fence swallows the rest rather than failing — a streaming answer looks like this.
163
+ while (i < lines.length && !(lines[i].trim().startsWith(marker[0].repeat(marker.length)) && lines[i].trim().replace(/[`~]/g, "") === "")) {
164
+ body.push(lines[i]);
165
+ i += 1;
166
+ }
167
+ i += 1;
168
+ blocks.push({ type: "code", lang: (_a = fence[2]) !== null && _a !== void 0 ? _a : "", content: body.join("\n") });
169
+ continue;
170
+ }
171
+ const heading = HEADING_RE.exec(line);
172
+ if (heading) {
173
+ flush();
174
+ blocks.push({
175
+ type: "heading",
176
+ level: heading[1].length,
177
+ children: (0, exports.parseInline)((_b = heading[2]) !== null && _b !== void 0 ? _b : "", 0),
178
+ });
179
+ i += 1;
180
+ continue;
181
+ }
182
+ if (RULE_RE.test(line)) {
183
+ flush();
184
+ blocks.push({ type: "rule" });
185
+ i += 1;
186
+ continue;
187
+ }
188
+ const divider = (_c = lines[i + 1]) !== null && _c !== void 0 ? _c : "";
189
+ if (line.includes("|") && divider.includes("|") && TABLE_DIVIDER_RE.test(divider)) {
190
+ flush();
191
+ const header = splitCells(line).map((c) => (0, exports.parseInline)(c, 0));
192
+ const align = splitCells(divider).map(alignOf);
193
+ i += 2;
194
+ const rows = [];
195
+ while (i < lines.length && lines[i].trim() !== "" && lines[i].includes("|")) {
196
+ const cells = splitCells(lines[i]).map((c) => (0, exports.parseInline)(c, 0));
197
+ rows.push(header.map((_, col) => { var _a; return (_a = cells[col]) !== null && _a !== void 0 ? _a : []; }));
198
+ i += 1;
199
+ }
200
+ blocks.push({ type: "table", align: header.map((_, col) => { var _a; return (_a = align[col]) !== null && _a !== void 0 ? _a : null; }), header, rows });
201
+ continue;
202
+ }
203
+ if (QUOTE_RE.test(line)) {
204
+ flush();
205
+ const quoted = [];
206
+ while (i < lines.length) {
207
+ const quote = QUOTE_RE.exec(lines[i]);
208
+ if (quote)
209
+ quoted.push(quote[1]);
210
+ else if (lines[i].trim() !== "" && !isBlockStart(lines[i]) && quoted.length > 0)
211
+ quoted.push(lines[i]);
212
+ else
213
+ break;
214
+ i += 1;
215
+ }
216
+ blocks.push({ type: "blockquote", blocks: parseBlocks(quoted, depth + 1) });
217
+ continue;
218
+ }
219
+ const first = ITEM_RE.exec(line);
220
+ if (first) {
221
+ flush();
222
+ const baseIndent = indentOf(first[1]);
223
+ const ordered = isOrderedMarker(first[2]);
224
+ const items = [];
225
+ while (i < lines.length) {
226
+ const item = ITEM_RE.exec(lines[i]);
227
+ if (!item || isOrderedMarker(item[2]) !== ordered || Math.abs(indentOf(item[1]) - baseIndent) > 1)
228
+ break;
229
+ const task = TASK_RE.exec(item[3]);
230
+ const text = [task ? task[2] : item[3]];
231
+ const nested = [];
232
+ i += 1;
233
+ while (i < lines.length) {
234
+ const next = lines[i];
235
+ if (next.trim() === "") {
236
+ let ahead = i;
237
+ while (ahead < lines.length && lines[ahead].trim() === "")
238
+ ahead += 1;
239
+ if (ahead < lines.length && indentOf(lines[ahead]) > baseIndent + 1) {
240
+ nested.push(...lines.slice(i, ahead));
241
+ i = ahead;
242
+ continue;
243
+ }
244
+ break;
245
+ }
246
+ if (indentOf(next) > baseIndent + 1) {
247
+ nested.push(next);
248
+ i += 1;
249
+ continue;
250
+ }
251
+ if (nested.length === 0 && !isBlockStart(next) && !next.includes("|")) {
252
+ text.push(next.trim());
253
+ i += 1;
254
+ continue;
255
+ }
256
+ break;
257
+ }
258
+ items.push({
259
+ children: (0, exports.parseInline)(text.join("\n"), 0),
260
+ checked: task ? task[1] !== " " : null,
261
+ blocks: nested.length ? parseBlocks(dedent(nested), depth + 1) : [],
262
+ });
263
+ // Blank lines between two items of the same list keep one (loose) list.
264
+ let ahead = i;
265
+ while (ahead < lines.length && lines[ahead].trim() === "")
266
+ ahead += 1;
267
+ const sibling = ITEM_RE.exec((_d = lines[ahead]) !== null && _d !== void 0 ? _d : "");
268
+ if (ahead > i && sibling && isOrderedMarker(sibling[2]) === ordered && Math.abs(indentOf(sibling[1]) - baseIndent) <= 1) {
269
+ i = ahead;
270
+ }
271
+ }
272
+ const start = ordered ? Number.parseInt(first[2], 10) : 1;
273
+ blocks.push({ type: "list", ordered, start: Number.isFinite(start) ? start : 1, items });
274
+ continue;
275
+ }
276
+ if (line.trim() === "") {
277
+ flush();
278
+ i += 1;
279
+ continue;
280
+ }
281
+ paragraph.push(line.trim());
282
+ i += 1;
283
+ }
284
+ flush();
285
+ return blocks;
286
+ };
287
+ /** Parses markdown into blocks; never throws — on an internal failure the input comes back as one paragraph. */
288
+ const parseMarkdown = (content) => {
289
+ const source = typeof content === "string" ? content : String(content !== null && content !== void 0 ? content : "");
290
+ try {
291
+ return parseBlocks(source.replace(/\r\n?/g, "\n").split("\n"), 0);
292
+ }
293
+ catch {
294
+ return [{ type: "paragraph", children: [{ type: "text", content: source }] }];
295
+ }
296
+ };
297
+ exports.parseMarkdown = parseMarkdown;
298
+ const inlineText = (nodes) => nodes
299
+ .map((n) => {
300
+ if (n.type === "text" || n.type === "code")
301
+ return n.content;
302
+ if (n.type === "break")
303
+ return " ";
304
+ if (n.type === "image")
305
+ return n.alt;
306
+ return inlineText(n.children);
307
+ })
308
+ .join("");
309
+ const blockText = (block) => {
310
+ switch (block.type) {
311
+ case "heading":
312
+ case "paragraph":
313
+ return inlineText(block.children);
314
+ case "code":
315
+ return block.content;
316
+ case "blockquote":
317
+ return block.blocks.map(blockText).join(" ");
318
+ case "list":
319
+ return block.items.map((item) => [inlineText(item.children), ...item.blocks.map(blockText)].join(" ")).join(" ");
320
+ case "table":
321
+ return [block.header, ...block.rows].map((row) => row.map(inlineText).join(" ")).join(" ");
322
+ default:
323
+ return "";
324
+ }
325
+ };
326
+ /** Markdown reduced to readable text (no markers), e.g. for a screen-reader announcement. */
327
+ const markdownToPlainText = (content) => (0, exports.parseMarkdown)(content).map(blockText).filter(Boolean).join(" ");
328
+ exports.markdownToPlainText = markdownToPlainText;
@@ -0,0 +1,21 @@
1
+ /** How a link from model output may render: an anchor (external opens a new tab) or plain text. */
2
+ export type SafeHref = {
3
+ href: string;
4
+ external: boolean;
5
+ } | null;
6
+ /**
7
+ * Decides whether a model-emitted href may become an anchor. Only `http:`, `https:`, `mailto:`, an
8
+ * app-relative path (`/…`, never `//host`) and a fragment (`#…`) pass; anything else returns null and
9
+ * the link text renders as plain text. Control characters anywhere reject the link outright.
10
+ */
11
+ export declare const resolveSafeHref: (raw: string | null | undefined) => SafeHref;
12
+ /** `target`/`rel` for an anchor built from a safe href. */
13
+ export declare const anchorAttributes: (safe: {
14
+ external: boolean;
15
+ }) => {
16
+ target: string;
17
+ rel: string;
18
+ } | {
19
+ target?: undefined;
20
+ rel?: undefined;
21
+ };
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.anchorAttributes = exports.resolveSafeHref = void 0;
4
+ // NOTE: an allowlist on the raw prefix — `java\tscript:`, `data:`, `vbscript:` and `//host` never match.
5
+ const ABSOLUTE = /^(https?:\/\/[^\s]+|mailto:[^\s]+)$/i;
6
+ const RELATIVE = /^(\/(?![/\\])[^\s]*|#[^\s]*)$/;
7
+ /**
8
+ * Decides whether a model-emitted href may become an anchor. Only `http:`, `https:`, `mailto:`, an
9
+ * app-relative path (`/…`, never `//host`) and a fragment (`#…`) pass; anything else returns null and
10
+ * the link text renders as plain text. Control characters anywhere reject the link outright.
11
+ */
12
+ const resolveSafeHref = (raw) => {
13
+ if (typeof raw !== "string")
14
+ return null;
15
+ const href = raw.trim();
16
+ // eslint-disable-next-line no-control-regex
17
+ if (!href || /[\u0000-\u001f\u007f]/.test(href))
18
+ return null;
19
+ if (ABSOLUTE.test(href))
20
+ return { href, external: /^https?:/i.test(href) };
21
+ if (RELATIVE.test(href))
22
+ return { href, external: false };
23
+ return null;
24
+ };
25
+ exports.resolveSafeHref = resolveSafeHref;
26
+ /** `target`/`rel` for an anchor built from a safe href. */
27
+ const anchorAttributes = (safe) => safe.external ? { target: "_blank", rel: "noopener noreferrer nofollow" } : {};
28
+ exports.anchorAttributes = anchorAttributes;
@@ -0,0 +1,3 @@
1
+ import type { AssistantMessageProps } from "./AssistantMessageProps";
2
+ declare const _default: import("react").MemoExoticComponent<({ message, renderers, renderPart, showMeta, feedbackReasons, actionsVisibility, onCopy, onRetry, onEdit, onFeedback, onLinkClick, onSuggestion, onSourceSelect, onProposalAction, onApprovalAction, labels, markdownLabels, "data-testid": testId, }: AssistantMessageProps) => import("react/jsx-runtime").JSX.Element>;
3
+ export default _default;
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const jsx_runtime_1 = require("react/jsx-runtime");
7
+ const react_1 = require("react");
8
+ const react_2 = require("@chakra-ui/react");
9
+ const lucide_react_1 = require("lucide-react");
10
+ const useCustomTheme_1 = require("../../../Theme/useCustomTheme");
11
+ const filledSurface_1 = require("../../../Theme/tokens/builders/filledSurface");
12
+ const borderWidths_1 = require("../../../Theme/tokens/primitives/borderWidths");
13
+ const motion_1 = require("../../../Theme/tokens/primitives/motion");
14
+ const radii_1 = require("../../../Theme/tokens/primitives/radii");
15
+ const Button_1 = __importDefault(require("../../Button/Button"));
16
+ const Tag_1 = __importDefault(require("../../Tag/Tag"));
17
+ const AssistantMarkdown_1 = __importDefault(require("../markdown/AssistantMarkdown"));
18
+ const AssistantToolSteps_1 = __importDefault(require("../steps/AssistantToolSteps"));
19
+ const AssistantProposalCard_1 = __importDefault(require("../cards/AssistantProposalCard"));
20
+ const AssistantApprovalCard_1 = __importDefault(require("../cards/AssistantApprovalCard"));
21
+ const AssistantSources_1 = __importDefault(require("../sources/AssistantSources"));
22
+ const AssistantSuggestions_1 = __importDefault(require("../suggestions/AssistantSuggestions"));
23
+ const AssistantTypingIndicator_1 = __importDefault(require("../typing/AssistantTypingIndicator"));
24
+ const assistantStyles_1 = require("../assistantStyles");
25
+ const assistantModel_1 = require("../assistantModel");
26
+ const MessageActions_1 = require("./MessageActions");
27
+ const DEFAULT_LABELS = {
28
+ user: "You said",
29
+ assistant: "Assistant said",
30
+ actions: "Message actions",
31
+ copy: "Copy",
32
+ copied: "Copied",
33
+ retry: "Retry",
34
+ edit: "Edit",
35
+ helpful: "Good response",
36
+ notHelpful: "Bad response",
37
+ feedbackReasons: "What went wrong?",
38
+ skipReason: "Skip",
39
+ typing: "Assistant is typing",
40
+ aborted: "Response stopped",
41
+ failed: "Something went wrong. Try again.",
42
+ empty: "No response received.",
43
+ result: (name) => `Received ${name} result`,
44
+ };
45
+ const REVEAL = (0, motion_1.transitionFor)(["opacity"]);
46
+ const toolSteps = (parts) => parts.map((p) => { var _a; return ({ id: p.id, label: (_a = p.label) !== null && _a !== void 0 ? _a : p.name, status: p.status, detail: p.detail }); });
47
+ /**
48
+ * One conversation message. The person's text is a right-aligned filled bubble (plain text, never
49
+ * markdown); the assistant's parts stack in a plain left column: markdown, tool steps, results, proposal
50
+ * and approval cards, sources, suggestions, notices and errors. `renderPart` overrides any part.
51
+ */
52
+ const AssistantMessage = ({ message, renderers, renderPart, showMeta = false, feedbackReasons, actionsVisibility = "hover", onCopy, onRetry, onEdit, onFeedback, onLinkClick, onSuggestion, onSourceSelect, onProposalAction, onApprovalAction, labels, markdownLabels, "data-testid": testId = "assistant-message", }) => {
53
+ var _a;
54
+ const { colors } = (0, useCustomTheme_1.useCustomTheme)();
55
+ const tokens = (0, assistantStyles_1.assistantTokens)(colors);
56
+ const text = { ...DEFAULT_LABELS, ...labels };
57
+ const [menuOpen, setMenuOpen] = (0, react_1.useState)(false);
58
+ const isUser = message.role === "user";
59
+ const status = (_a = message.status) !== null && _a !== void 0 ? _a : "complete";
60
+ const streaming = status === "streaming";
61
+ const plain = (0, assistantModel_1.messageText)(message);
62
+ const groups = (0, assistantModel_1.groupParts)(isUser ? message.parts.filter((p) => p.type !== "text") : message.parts);
63
+ const lastGroup = groups[groups.length - 1];
64
+ const caretOnText = streaming && (lastGroup === null || lastGroup === void 0 ? void 0 : lastGroup.kind) === "part" && lastGroup.part.type === "text";
65
+ const defaultPart = (part, isLast) => {
66
+ var _a;
67
+ switch (part.type) {
68
+ case "text":
69
+ return ((0, jsx_runtime_1.jsx)(AssistantMarkdown_1.default, { content: part.text, showCaret: streaming && isLast, onLinkClick: onLinkClick, labels: markdownLabels }));
70
+ case "tool":
71
+ return (0, jsx_runtime_1.jsx)(AssistantToolSteps_1.default, { steps: toolSteps([part]) });
72
+ case "result": {
73
+ const render = renderers === null || renderers === void 0 ? void 0 : renderers[(_a = part.render) !== null && _a !== void 0 ? _a : part.name];
74
+ if (render)
75
+ return render(part, message);
76
+ return ((0, jsx_runtime_1.jsx)(react_2.Text, { fontSize: "xs", color: tokens.muted, "data-testid": `${testId}-result-fallback`, children: text.result(part.name) }));
77
+ }
78
+ case "proposal":
79
+ return ((0, jsx_runtime_1.jsx)(AssistantProposalCard_1.default, { title: part.title, summary: part.summary, fields: part.fields, status: part.status, error: part.error, onPrimary: onProposalAction ? () => onProposalAction(part.id, "apply", message) : undefined, onEdit: onProposalAction ? () => onProposalAction(part.id, "edit", message) : undefined, onDismiss: onProposalAction ? () => onProposalAction(part.id, "dismiss", message) : undefined }));
80
+ case "approval":
81
+ return ((0, jsx_runtime_1.jsx)(AssistantApprovalCard_1.default, { title: part.title, summary: part.summary, changes: part.changes, risk: part.risk, status: part.status, error: part.error, undoable: part.undoable, onApprove: onApprovalAction ? () => onApprovalAction(part.id, "approve", message) : undefined, onDeny: onApprovalAction ? () => onApprovalAction(part.id, "deny", message) : undefined, onUndo: onApprovalAction ? () => onApprovalAction(part.id, "undo", message) : undefined }));
82
+ case "sources":
83
+ return (0, jsx_runtime_1.jsx)(AssistantSources_1.default, { sources: part.items, onSelect: onSourceSelect });
84
+ case "suggestions":
85
+ return onSuggestion ? ((0, jsx_runtime_1.jsx)(AssistantSuggestions_1.default, { suggestions: part.items, onSelect: onSuggestion, isDisabled: streaming })) : null;
86
+ case "notice": {
87
+ const look = (0, assistantStyles_1.assistantTone)(colors, part.tone);
88
+ return ((0, jsx_runtime_1.jsxs)(react_2.Flex, { align: "flex-start", gap: 2, fontSize: "sm", color: look.text, "data-testid": `${testId}-notice`, children: [(0, jsx_runtime_1.jsx)(react_2.Box, { as: part.tone === "warning" ? lucide_react_1.AlertTriangle : lucide_react_1.Info, "aria-hidden": "true", boxSize: 4, mt: 0.5, flexShrink: 0 }), (0, jsx_runtime_1.jsx)(react_2.Text, { children: part.text })] }));
89
+ }
90
+ case "error":
91
+ return (0, jsx_runtime_1.jsx)(ErrorBlock, { message: part.message, onRetry: part.retryable && onRetry ? () => onRetry(message) : undefined, retryLabel: text.retry });
92
+ default:
93
+ return null;
94
+ }
95
+ };
96
+ const renderOne = (part, isLast) => {
97
+ const custom = renderPart === null || renderPart === void 0 ? void 0 : renderPart(part, message);
98
+ return custom !== undefined ? custom : defaultPart(part, isLast);
99
+ };
100
+ const body = groups.map((group, i) => {
101
+ const isLast = i === groups.length - 1;
102
+ if (group.kind === "tools") {
103
+ const customs = renderPart ? group.parts.map((p) => renderPart(p, message)) : [];
104
+ if (customs.some((c) => c !== undefined)) {
105
+ return ((0, jsx_runtime_1.jsx)(react_1.Fragment, { children: group.parts.map((p, j) => ((0, jsx_runtime_1.jsx)(react_1.Fragment, { children: customs[j] !== undefined ? customs[j] : defaultPart(p, false) }, p.id))) }, group.key));
106
+ }
107
+ return (0, jsx_runtime_1.jsx)(AssistantToolSteps_1.default, { steps: toolSteps(group.parts) }, group.key);
108
+ }
109
+ return (0, jsx_runtime_1.jsx)(react_1.Fragment, { children: renderOne(group.part, isLast && caretOnText) }, group.key);
110
+ });
111
+ const hasErrorPart = message.parts.some((p) => p.type === "error");
112
+ const showTyping = !isUser && streaming && groups.length === 0;
113
+ const showActions = !streaming && Boolean(plain || onRetry || onEdit || onFeedback);
114
+ const meta = showMeta && message.meta ? [message.meta.model, message.meta.provider].filter(Boolean).join(" · ") : "";
115
+ const bubble = (0, filledSurface_1.resolveFilledSurface)(colors.primary, colors);
116
+ const hoverOnly = actionsVisibility === "hover" && !menuOpen;
117
+ return ((0, jsx_runtime_1.jsxs)(react_2.Box, { as: "article", "aria-label": isUser ? text.user : text.assistant, "aria-busy": streaming || undefined, display: "flex", flexDirection: "column", alignItems: isUser ? "flex-end" : "stretch", gap: 1, "data-testid": testId, "data-role": message.role, "data-status": status, sx: hoverOnly
118
+ ? {
119
+ "@media (hover: hover)": {
120
+ "& [data-message-actions]": { opacity: 0, transition: REVEAL },
121
+ "&:hover [data-message-actions], &:focus-within [data-message-actions]": { opacity: 1 },
122
+ },
123
+ }
124
+ : undefined, children: [isUser ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [plain ? ((0, jsx_runtime_1.jsx)(react_2.Box, { maxW: "85%", px: 3.5, py: 2, bg: bubble.fill, color: bubble.color, borderRadius: radii_1.RADIUS_ROLE.card, borderEndEndRadius: radii_1.RADIUS_ROLE.option, fontSize: "sm", lineHeight: 1.5, whiteSpace: "pre-wrap", overflowWrap: "anywhere", "data-testid": `${testId}-bubble`, children: plain })) : null, body.length ? (0, jsx_runtime_1.jsx)(react_2.Flex, { direction: "column", gap: 3, w: "100%", children: body }) : null] })) : ((0, jsx_runtime_1.jsxs)(react_2.Flex, { direction: "column", gap: 3, minW: 0, children: [showTyping ? (0, jsx_runtime_1.jsx)(AssistantTypingIndicator_1.default, { label: text.typing }) : body, status === "error" && !hasErrorPart ? ((0, jsx_runtime_1.jsx)(ErrorBlock, { message: text.failed, onRetry: onRetry ? () => onRetry(message) : undefined, retryLabel: text.retry })) : null, status === "aborted" ? ((0, jsx_runtime_1.jsx)(react_2.Text, { fontSize: "xs", color: tokens.muted, fontStyle: "italic", children: text.aborted })) : null, status === "complete" && message.parts.length === 0 ? ((0, jsx_runtime_1.jsx)(react_2.Text, { fontSize: "sm", color: tokens.muted, children: text.empty })) : null] })), showActions || meta ? ((0, jsx_runtime_1.jsxs)(react_2.Flex, { align: "center", gap: 2, minH: 6, justify: isUser ? "flex-end" : "flex-start", children: [showActions ? ((0, jsx_runtime_1.jsx)(MessageActions_1.MessageActions, { message: message, text: plain, labels: text, feedbackReasons: feedbackReasons, onCopy: onCopy, onRetry: onRetry, onEdit: onEdit, onFeedback: onFeedback, onMenuOpenChange: setMenuOpen })) : null, meta ? (0, jsx_runtime_1.jsx)(Tag_1.default, { label: meta, size: "xs", variant: "outline", colorScheme: "gray", "data-testid": `${testId}-meta` }) : null] })) : null] }));
125
+ };
126
+ const ErrorBlock = ({ message, onRetry, retryLabel }) => {
127
+ const { colors } = (0, useCustomTheme_1.useCustomTheme)();
128
+ const look = (0, assistantStyles_1.assistantTone)(colors, "error");
129
+ return ((0, jsx_runtime_1.jsxs)(react_2.Flex, { role: "alert", align: "flex-start", gap: 2, px: 3, py: 2, bg: look.bg, borderWidth: borderWidths_1.BORDER_WIDTHS.hairline, borderColor: look.border, borderRadius: radii_1.RADIUS_ROLE.control, "data-testid": "assistant-message-error", children: [(0, jsx_runtime_1.jsx)(react_2.Box, { as: lucide_react_1.AlertCircle, "aria-hidden": "true", boxSize: 4, mt: 0.5, flexShrink: 0, color: look.ink }), (0, jsx_runtime_1.jsx)(react_2.Text, { flex: "1", fontSize: "sm", color: colors.text[800], children: message }), onRetry ? (0, jsx_runtime_1.jsx)(Button_1.default, { size: "xs", variant: "outline", colorScheme: "gray", label: retryLabel, onClick: onRetry, flexShrink: 0 }) : null] }));
130
+ };
131
+ exports.default = (0, react_1.memo)(AssistantMessage);
@@ -0,0 +1,83 @@
1
+ import type { MouseEvent, ReactNode } from "react";
2
+ import type { AssistantMessageModel, AssistantPart, AssistantResultPart, AssistantSource } from "../assistantTypes";
3
+ import type { AssistantMarkdownLabels } from "../markdown/AssistantMarkdownProps";
4
+ /** Draws one `result` part; registered under the part's `render` key (or its `name`). */
5
+ export type AssistantResultRenderer = (part: AssistantResultPart, message: AssistantMessageModel) => ReactNode;
6
+ /** What a person did to a proposal card. */
7
+ export type AssistantProposalAction = "apply" | "edit" | "dismiss";
8
+ /** What a person did to an approval card. */
9
+ export type AssistantApprovalAction = "approve" | "deny" | "undo";
10
+ /** Visible and spoken text of `AssistantMessage`; omitted keys keep the English default. */
11
+ export interface AssistantMessageLabels {
12
+ /** Accessible name of a user message. Default "You said". */
13
+ user?: string;
14
+ /** Accessible name of an assistant message. Default "Assistant said". */
15
+ assistant?: string;
16
+ /** Name of the action row. Default "Message actions". */
17
+ actions?: string;
18
+ /** Default "Copy". */
19
+ copy?: string;
20
+ /** Default "Copied". */
21
+ copied?: string;
22
+ /** Default "Retry". */
23
+ retry?: string;
24
+ /** Default "Edit". */
25
+ edit?: string;
26
+ /** Default "Good response". */
27
+ helpful?: string;
28
+ /** Default "Bad response". */
29
+ notHelpful?: string;
30
+ /** Title of the reason menu. Default "What went wrong?". */
31
+ feedbackReasons?: string;
32
+ /** The reason menu's opt-out item. Default "Skip". */
33
+ skipReason?: string;
34
+ /** Spoken while the reply has no content yet. Default "Assistant is typing". */
35
+ typing?: string;
36
+ /** Line under a reply the person stopped. Default "Response stopped". */
37
+ aborted?: string;
38
+ /** Error block for a failed reply with no error part. Default "Something went wrong. Try again.". */
39
+ failed?: string;
40
+ /** Line for a finished reply with no parts. Default "No response received.". */
41
+ empty?: string;
42
+ /** Quiet line for a result with no renderer. Default "Received <name> result". */
43
+ result?: (name: string) => string;
44
+ }
45
+ /** One message: a right-aligned bubble for the person, a plain column for the assistant, with an action row. */
46
+ export interface AssistantMessageProps {
47
+ /** The message to render. */
48
+ message: AssistantMessageModel;
49
+ /** Result renderers keyed by `part.render ?? part.name`; a result with no renderer gets a quiet line. */
50
+ renderers?: Record<string, AssistantResultRenderer>;
51
+ /** Per-part override; return `undefined` to fall back to the default rendering for that part. */
52
+ renderPart?: (part: AssistantPart, message: AssistantMessageModel) => ReactNode | undefined;
53
+ /** Shows the model/provider badge from `message.meta`. */
54
+ showMeta?: boolean;
55
+ /** With `onFeedback`, thumbs-down opens a menu of these reasons. */
56
+ feedbackReasons?: string[];
57
+ /** "hover" (default) reveals the action row on hover or keyboard focus on devices that can hover; "always" keeps it visible. */
58
+ actionsVisibility?: "hover" | "always";
59
+ /** Called after the Copy button wrote the message's text to the clipboard. */
60
+ onCopy?: (text: string, message: AssistantMessageModel) => void;
61
+ /** Adds Retry to assistant messages (and to a retryable error part). */
62
+ onRetry?: (message: AssistantMessageModel) => void;
63
+ /** Adds Edit to user messages. */
64
+ onEdit?: (message: AssistantMessageModel) => void;
65
+ /** Adds thumbs to assistant messages. Pressing the active thumb again sends `null` (cleared). */
66
+ onFeedback?: (rating: "up" | "down" | null, reason: string | undefined, message: AssistantMessageModel) => void;
67
+ /** Link clicks inside the answer; see `AssistantMarkdown`. */
68
+ onLinkClick?: (href: string, event: MouseEvent<HTMLAnchorElement>) => void;
69
+ /** Picks a suggestion chip; chips render only when this is set. */
70
+ onSuggestion?: (text: string) => void;
71
+ /** Activates a source; see `AssistantSources`. */
72
+ onSourceSelect?: (source: AssistantSource, event: MouseEvent<HTMLElement>) => void;
73
+ /** Proposal card buttons; without it the cards render read-only. */
74
+ onProposalAction?: (id: string, action: AssistantProposalAction, message: AssistantMessageModel) => void;
75
+ /** Approval card buttons; without it the cards render read-only. */
76
+ onApprovalAction?: (id: string, action: AssistantApprovalAction, message: AssistantMessageModel) => void;
77
+ /** Translated message text. */
78
+ labels?: AssistantMessageLabels;
79
+ /** Passed to every `AssistantMarkdown` in the message. */
80
+ markdownLabels?: AssistantMarkdownLabels;
81
+ /** data-testid on the root; the role is in `data-role`. */
82
+ "data-testid"?: string;
83
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,16 @@
1
+ import type { AssistantMessageModel } from "../assistantTypes";
2
+ import type { AssistantMessageLabels, AssistantMessageProps } from "./AssistantMessageProps";
3
+ interface MessageActionsProps {
4
+ message: AssistantMessageModel;
5
+ text: string;
6
+ labels: Required<AssistantMessageLabels>;
7
+ feedbackReasons?: string[];
8
+ onCopy?: AssistantMessageProps["onCopy"];
9
+ onRetry?: AssistantMessageProps["onRetry"];
10
+ onEdit?: AssistantMessageProps["onEdit"];
11
+ onFeedback?: AssistantMessageProps["onFeedback"];
12
+ onMenuOpenChange: (open: boolean) => void;
13
+ }
14
+ /** Copy, retry, edit and feedback for one message; every control is a real button with a name. */
15
+ export declare const MessageActions: ({ message, text, labels, feedbackReasons, onCopy, onRetry, onEdit, onFeedback, onMenuOpenChange, }: MessageActionsProps) => import("react/jsx-runtime").JSX.Element;
16
+ export {};
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.MessageActions = void 0;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const react_1 = require("@chakra-ui/react");
9
+ const lucide_react_1 = require("lucide-react");
10
+ const CopyButton_1 = __importDefault(require("../../CopyButton/CopyButton"));
11
+ const IconButton_1 = __importDefault(require("../../IconButton/IconButton"));
12
+ const ToolTip_1 = __importDefault(require("../../ToolTip/ToolTip"));
13
+ const ACTION = { size: "xs", variant: "ghost", colorScheme: "gray" };
14
+ /** Copy, retry, edit and feedback for one message; every control is a real button with a name. */
15
+ const MessageActions = ({ message, text, labels, feedbackReasons, onCopy, onRetry, onEdit, onFeedback, onMenuOpenChange, }) => {
16
+ var _a, _b;
17
+ const isUser = message.role === "user";
18
+ const rating = (_a = message.feedback) !== null && _a !== void 0 ? _a : null;
19
+ const reasons = (_b = feedbackReasons === null || feedbackReasons === void 0 ? void 0 : feedbackReasons.filter(Boolean)) !== null && _b !== void 0 ? _b : [];
20
+ const thumbsDown = !isUser && onFeedback ? (reasons.length && rating !== "down" ? ((0, jsx_runtime_1.jsxs)(react_1.Menu, { isLazy: true, placement: "bottom-start", onOpen: () => onMenuOpenChange(true), onClose: () => onMenuOpenChange(false), children: [(0, jsx_runtime_1.jsx)(react_1.MenuButton, { as: IconButton_1.default, ...ACTION, "aria-label": labels.notHelpful, "aria-pressed": false, icon: (0, jsx_runtime_1.jsx)(lucide_react_1.ThumbsDown, { size: 14 }) }), (0, jsx_runtime_1.jsx)(react_1.Portal, { children: (0, jsx_runtime_1.jsx)(react_1.MenuList, { minW: "12rem", fontSize: "sm", children: (0, jsx_runtime_1.jsxs)(react_1.MenuGroup, { title: labels.feedbackReasons, children: [reasons.map((reason) => ((0, jsx_runtime_1.jsx)(react_1.MenuItem, { onClick: () => onFeedback("down", reason, message), children: reason }, reason))), (0, jsx_runtime_1.jsx)(react_1.MenuItem, { onClick: () => onFeedback("down", undefined, message), children: labels.skipReason })] }) }) })] })) : ((0, jsx_runtime_1.jsx)(ToolTip_1.default, { label: labels.notHelpful, children: (0, jsx_runtime_1.jsx)(IconButton_1.default, { ...ACTION, "aria-label": labels.notHelpful, "aria-pressed": rating === "down", icon: (0, jsx_runtime_1.jsx)(lucide_react_1.ThumbsDown, { size: 14, fill: rating === "down" ? "currentColor" : "none" }), onClick: () => onFeedback(rating === "down" ? null : "down", undefined, message) }) }))) : null;
21
+ return ((0, jsx_runtime_1.jsxs)(react_1.Flex, { role: "group", "aria-label": labels.actions, align: "center", gap: 0.5, "data-message-actions": "", children: [text ? ((0, jsx_runtime_1.jsx)(CopyButton_1.default, { value: text, size: "xs", iconSize: 14, tooltip: labels.copy, copiedLabel: labels.copied, onCopy: () => onCopy === null || onCopy === void 0 ? void 0 : onCopy(text, message) })) : null, isUser && onEdit ? ((0, jsx_runtime_1.jsx)(ToolTip_1.default, { label: labels.edit, children: (0, jsx_runtime_1.jsx)(IconButton_1.default, { ...ACTION, "aria-label": labels.edit, icon: (0, jsx_runtime_1.jsx)(lucide_react_1.Pencil, { size: 14 }), onClick: () => onEdit(message) }) })) : null, !isUser && onRetry ? ((0, jsx_runtime_1.jsx)(ToolTip_1.default, { label: labels.retry, children: (0, jsx_runtime_1.jsx)(IconButton_1.default, { ...ACTION, "aria-label": labels.retry, icon: (0, jsx_runtime_1.jsx)(lucide_react_1.RotateCcw, { size: 14 }), onClick: () => onRetry(message) }) })) : null, !isUser && onFeedback ? ((0, jsx_runtime_1.jsx)(ToolTip_1.default, { label: labels.helpful, children: (0, jsx_runtime_1.jsx)(IconButton_1.default, { ...ACTION, "aria-label": labels.helpful, "aria-pressed": rating === "up", icon: (0, jsx_runtime_1.jsx)(lucide_react_1.ThumbsUp, { size: 14, fill: rating === "up" ? "currentColor" : "none" }), onClick: () => onFeedback(rating === "up" ? null : "up", undefined, message) }) })) : null, thumbsDown] }));
22
+ };
23
+ exports.MessageActions = MessageActions;