@adecore/agents-react 0.70.0 → 0.71.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.
- package/dist/chat/logic/fork.js +1 -0
- package/dist/chat/logic/thread-cards.js +1 -0
- package/dist/chat/logic/timeline.js +7 -0
- package/dist/chat/ui/CodeBlock.d.ts +6 -1
- package/dist/chat/ui/CodeBlock.js +39 -23
- package/dist/chat/ui/intelligent-ui/UiReply.js +11 -2
- package/dist/chat/ui/intelligent-ui/key-caps.d.ts +1 -0
- package/dist/chat/ui/intelligent-ui/key-caps.js +45 -0
- package/dist/chat/ui/intelligent-ui/link-action.d.ts +9 -0
- package/dist/chat/ui/intelligent-ui/link-action.js +32 -0
- package/dist/chat/ui/intelligent-ui/node-text.js +1 -1
- package/dist/chat/ui/intelligent-ui/patch-clip.d.ts +4 -0
- package/dist/chat/ui/intelligent-ui/patch-clip.js +64 -0
- package/dist/chat/ui/intelligent-ui/registry.js +31 -5
- package/dist/chat/ui/intelligent-ui/render-context.d.ts +13 -0
- package/dist/chat/ui/intelligent-ui/renderers/alternatives.d.ts +6 -0
- package/dist/chat/ui/intelligent-ui/renderers/alternatives.js +296 -0
- package/dist/chat/ui/intelligent-ui/renderers/changes.d.ts +4 -0
- package/dist/chat/ui/intelligent-ui/renderers/changes.js +266 -0
- package/dist/chat/ui/intelligent-ui/renderers/chart.js +522 -371
- package/dist/chat/ui/intelligent-ui/renderers/content.d.ts +1 -1
- package/dist/chat/ui/intelligent-ui/renderers/content.js +94 -43
- package/dist/chat/ui/intelligent-ui/renderers/data.js +478 -245
- package/dist/chat/ui/intelligent-ui/renderers/diff.d.ts +4 -0
- package/dist/chat/ui/intelligent-ui/renderers/diff.js +427 -0
- package/dist/chat/ui/intelligent-ui/renderers/inputs.d.ts +1 -0
- package/dist/chat/ui/intelligent-ui/renderers/inputs.js +354 -110
- package/dist/chat/ui/intelligent-ui/renderers/keys.d.ts +3 -0
- package/dist/chat/ui/intelligent-ui/renderers/keys.js +60 -0
- package/dist/chat/ui/intelligent-ui/renderers/links.d.ts +13 -2
- package/dist/chat/ui/intelligent-ui/renderers/links.js +65 -85
- package/dist/chat/ui/intelligent-ui/renderers/meter.d.ts +4 -0
- package/dist/chat/ui/intelligent-ui/renderers/meter.js +371 -0
- package/dist/chat/ui/intelligent-ui/renderers/quote.d.ts +3 -0
- package/dist/chat/ui/intelligent-ui/renderers/quote.js +123 -0
- package/dist/chat/ui/intelligent-ui/renderers/radio.d.ts +3 -0
- package/dist/chat/ui/intelligent-ui/renderers/radio.js +205 -0
- package/dist/chat/ui/intelligent-ui/renderers/structure.d.ts +2 -0
- package/dist/chat/ui/intelligent-ui/renderers/structure.js +156 -45
- package/dist/chat/ui/intelligent-ui/renderers/text.js +365 -215
- package/dist/chat/ui/intelligent-ui/renderers/tree.d.ts +5 -0
- package/dist/chat/ui/intelligent-ui/renderers/tree.js +284 -0
- package/dist/chat/ui/intelligent-ui/table-data.d.ts +9 -2
- package/dist/chat/ui/intelligent-ui/table-data.js +68 -3
- package/dist/chat/ui/intelligent-ui/tones.d.ts +1 -1
- package/dist/chat/ui/intelligent-ui/tones.js +7 -7
- package/dist/chat/ui/intelligent-ui/use-ui-diffs.d.ts +4 -0
- package/dist/chat/ui/intelligent-ui/use-ui-diffs.js +201 -0
- package/dist/chat/ui/rows/MessageRows.d.ts +4 -1
- package/dist/chat/ui/rows/MessageRows.js +92 -1
- package/dist/chat/ui/rows/Rows.js +45 -31
- package/dist/host/host.d.ts +2 -1
- package/dist/host/timeline-row.d.ts +5 -1
- package/dist/locales/en/agent-chat.d.ts +62 -0
- package/dist/locales/en/agent-chat.js +63 -1
- package/dist/locales/nl/agent-chat.d.ts +62 -0
- package/dist/locales/nl/agent-chat.js +63 -1
- package/dist/theme.css +6 -0
- package/package.json +9 -9
- package/src/chat/logic/fork.ts +1 -0
- package/src/chat/logic/thread-cards.ts +1 -0
- package/src/chat/logic/timeline.ts +4 -0
- package/src/chat/ui/CodeBlock.tsx +38 -18
- package/src/chat/ui/intelligent-ui/UiReply.tsx +13 -2
- package/src/chat/ui/intelligent-ui/key-caps.ts +51 -0
- package/src/chat/ui/intelligent-ui/link-action.ts +32 -0
- package/src/chat/ui/intelligent-ui/node-text.ts +1 -0
- package/src/chat/ui/intelligent-ui/patch-clip.ts +83 -0
- package/src/chat/ui/intelligent-ui/registry.ts +31 -4
- package/src/chat/ui/intelligent-ui/render-context.ts +21 -0
- package/src/chat/ui/intelligent-ui/renderers/alternatives.tsx +76 -0
- package/src/chat/ui/intelligent-ui/renderers/changes.tsx +97 -0
- package/src/chat/ui/intelligent-ui/renderers/chart.tsx +122 -46
- package/src/chat/ui/intelligent-ui/renderers/content.tsx +27 -7
- package/src/chat/ui/intelligent-ui/renderers/data.tsx +165 -52
- package/src/chat/ui/intelligent-ui/renderers/diff.tsx +144 -0
- package/src/chat/ui/intelligent-ui/renderers/inputs.tsx +111 -19
- package/src/chat/ui/intelligent-ui/renderers/keys.tsx +26 -0
- package/src/chat/ui/intelligent-ui/renderers/links.tsx +40 -24
- package/src/chat/ui/intelligent-ui/renderers/meter.tsx +105 -0
- package/src/chat/ui/intelligent-ui/renderers/quote.tsx +29 -0
- package/src/chat/ui/intelligent-ui/renderers/radio.tsx +130 -0
- package/src/chat/ui/intelligent-ui/renderers/structure.tsx +54 -7
- package/src/chat/ui/intelligent-ui/renderers/text.tsx +70 -36
- package/src/chat/ui/intelligent-ui/renderers/tree.tsx +85 -0
- package/src/chat/ui/intelligent-ui/table-data.ts +84 -6
- package/src/chat/ui/intelligent-ui/tones.ts +7 -7
- package/src/chat/ui/intelligent-ui/use-ui-diffs.ts +119 -0
- package/src/chat/ui/rows/MessageRows.tsx +23 -0
- package/src/chat/ui/rows/Rows.tsx +3 -0
- package/src/host/host.ts +4 -0
- package/src/host/timeline-row.ts +3 -0
- package/src/locales/en/agent-chat.ts +63 -1
- package/src/locales/nl/agent-chat.ts +63 -1
- package/src/theme.css +6 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { UiProps } from '@adecore/intelligent-ui';
|
|
2
|
+
import { FileIcon, MiddleTruncate, Tooltip } from '@adecore/ui';
|
|
3
|
+
import { formatNumber } from '@adecore/ui/format';
|
|
4
|
+
import clsx from 'clsx';
|
|
5
|
+
import type { ReactNode } from 'react';
|
|
6
|
+
import { useTranslation } from 'react-i18next';
|
|
7
|
+
import { uiLinkAction } from '../link-action';
|
|
8
|
+
import { uiChildrenOf, uiNodeLabel } from '../node-text';
|
|
9
|
+
import type { UiRendererProps } from '../render-context';
|
|
10
|
+
|
|
11
|
+
export function ChangesRenderer({ node, children }: UiRendererProps<UiProps<'Changes'>>) {
|
|
12
|
+
const { t } = useTranslation('agent-chat');
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<ul
|
|
16
|
+
aria-label={t('blocks.changes.label', { count: uiChildrenOf(node, 'Change').length })}
|
|
17
|
+
className="chat-ui-nodes chat-ui-flat flex flex-col rounded-xl bg-ui-tile p-1.5"
|
|
18
|
+
>
|
|
19
|
+
{children}
|
|
20
|
+
</ul>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/* The share of added against removed lines, drawn only; the two numbers beside it say it in words. */
|
|
25
|
+
function ChangeBar({ added, removed }: { added: number; removed: number }) {
|
|
26
|
+
const total = added + removed;
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<span aria-hidden className="flex h-1.5 w-12 shrink-0 overflow-hidden rounded-full bg-track">
|
|
30
|
+
{total > 0 && (
|
|
31
|
+
<>
|
|
32
|
+
<span className="bg-positive" style={{ width: `${(added / total) * 100}%` }} />
|
|
33
|
+
<span className="bg-status-error" style={{ width: `${(removed / total) * 100}%` }} />
|
|
34
|
+
</>
|
|
35
|
+
)}
|
|
36
|
+
</span>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/*
|
|
41
|
+
* One changed file as a row that opens its diff the way a Diff chip does, once the host says it can. Until
|
|
42
|
+
* then, and for a file it cannot open, the row is text with the reason on its path. The note stands under
|
|
43
|
+
* the row, outside the button, since its prose may hold a link of its own.
|
|
44
|
+
*/
|
|
45
|
+
export function ChangeRenderer({ node, children, context }: UiRendererProps<UiProps<'Change'>>) {
|
|
46
|
+
const { t } = useTranslation('agent-chat');
|
|
47
|
+
const { path, added, removed, state } = node.props;
|
|
48
|
+
const { open, reason } = uiLinkAction(t, { type: 'Diff', path }, context);
|
|
49
|
+
const counted = added !== undefined || removed !== undefined;
|
|
50
|
+
|
|
51
|
+
const name: ReactNode =
|
|
52
|
+
open !== null || reason === null ? (
|
|
53
|
+
<MiddleTruncate text={path} className="min-w-0 grow font-mono text-code text-text" />
|
|
54
|
+
) : (
|
|
55
|
+
<Tooltip label={reason}>
|
|
56
|
+
<span tabIndex={0} className="min-w-0 grow truncate rounded-sm font-mono text-code text-text-muted">
|
|
57
|
+
{path}
|
|
58
|
+
</span>
|
|
59
|
+
</Tooltip>
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const row = (
|
|
63
|
+
<>
|
|
64
|
+
<FileIcon path={path} size={14} className="shrink-0" />
|
|
65
|
+
{name}
|
|
66
|
+
{state !== undefined && <span className="shrink-0 text-2xs text-text-muted">{t(`blocks.changes.state.${state}`)}</span>}
|
|
67
|
+
{counted && (
|
|
68
|
+
<>
|
|
69
|
+
<span className="min-w-8 shrink-0 text-right text-2xs text-positive tabular-nums">
|
|
70
|
+
<span aria-hidden>+{formatNumber(added ?? 0)}</span>
|
|
71
|
+
<span className="sr-only">{t('blocks.changes.added', { count: added ?? 0 })}</span>
|
|
72
|
+
</span>
|
|
73
|
+
<span className="min-w-8 shrink-0 text-right text-2xs text-status-error tabular-nums">
|
|
74
|
+
<span aria-hidden>-{formatNumber(removed ?? 0)}</span>
|
|
75
|
+
<span className="sr-only">{t('blocks.changes.removed', { count: removed ?? 0 })}</span>
|
|
76
|
+
</span>
|
|
77
|
+
<ChangeBar added={added ?? 0} removed={removed ?? 0} />
|
|
78
|
+
</>
|
|
79
|
+
)}
|
|
80
|
+
</>
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const shape = 'flex min-h-8.5 w-full min-w-0 items-center gap-2.5 rounded-lg px-1.5 text-left text-xs';
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<li className="flex min-w-0 flex-col">
|
|
87
|
+
{open === null ? (
|
|
88
|
+
<div className={shape}>{row}</div>
|
|
89
|
+
) : (
|
|
90
|
+
<button type="button" className={clsx(shape, 'hover:bg-text/4')} onClick={open}>
|
|
91
|
+
{row}
|
|
92
|
+
</button>
|
|
93
|
+
)}
|
|
94
|
+
{uiNodeLabel(node) !== '' && <p className="pr-1.5 pb-1.5 pl-7.5 text-2xs wrap-break-word text-text-muted">{children}</p>}
|
|
95
|
+
</li>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { UiProps } from '@adecore/intelligent-ui';
|
|
2
|
-
import { Button, ScrollArea, SegmentBar, Tooltip, useMeasuredWidth } from '@adecore/ui';
|
|
1
|
+
import type { UiProps, UiTone } from '@adecore/intelligent-ui';
|
|
2
|
+
import { Button, Icon, ScrollArea, SegmentBar, Tooltip, useMeasuredWidth } from '@adecore/ui';
|
|
3
3
|
import { formatNumber, formatRounded } from '@adecore/ui/format';
|
|
4
4
|
import clsx from 'clsx';
|
|
5
5
|
import type { TFunction } from 'i18next';
|
|
6
|
-
import { useState } from 'react';
|
|
6
|
+
import { createContext, useContext, useState } from 'react';
|
|
7
7
|
import { useTranslation } from 'react-i18next';
|
|
8
8
|
import { useBlockLocal } from '../block-local';
|
|
9
9
|
import {
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
} from '../chart-data';
|
|
22
22
|
import { uiWithUnit } from '../node-text';
|
|
23
23
|
import type { UiRenderContext, UiRendererProps } from '../render-context';
|
|
24
|
+
import { UI_TONE_COLOR, UI_TONE_ICONS } from '../tones';
|
|
24
25
|
import { UiFallbackPart } from '../UiFallbackPart';
|
|
25
26
|
import { useTruncated } from '../use-truncated';
|
|
26
27
|
|
|
@@ -39,8 +40,20 @@ const LABEL_BAND = 56;
|
|
|
39
40
|
const DOTS_UP_TO = 30;
|
|
40
41
|
const GROW = 'transition-[scale,opacity] duration-400 ease-out motion-reduce:transition-none';
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
type ChartTones = UiProps<'Chart'>['tones'];
|
|
44
|
+
|
|
45
|
+
/* The tones a chart gives its series, by series key, for every part that colors one. */
|
|
46
|
+
const TonesContext = createContext<ChartTones>(undefined);
|
|
47
|
+
|
|
48
|
+
function seriesTone(key: string, tones: ChartTones): UiTone | undefined {
|
|
49
|
+
return tones !== undefined && Object.hasOwn(tones, key) ? tones[key] : undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/* A series wears its tone where the chart names one, and otherwise the palette color of its place. */
|
|
53
|
+
function seriesColor(index: number, key: string, tones: ChartTones): string {
|
|
54
|
+
const tone = seriesTone(key, tones);
|
|
55
|
+
|
|
56
|
+
return tone === undefined ? `var(--chart-${index + 1})` : UI_TONE_COLOR[tone];
|
|
44
57
|
}
|
|
45
58
|
|
|
46
59
|
function valueText(value: number | null, unit: string | undefined): string {
|
|
@@ -120,15 +133,29 @@ function chartSummary(values: UiChartValues, unit: string | undefined, t: TFunct
|
|
|
120
133
|
: t('blocks.chart.summary', { count: values.labels.length, label: top.label, value: valueText(top.value, unit) });
|
|
121
134
|
}
|
|
122
135
|
|
|
136
|
+
/* A series with a tone shows the tone's icon in place of its square, so the tone is never its color alone. */
|
|
123
137
|
function Legend({ chart }: { chart: UiChartData }) {
|
|
138
|
+
const tones = useContext(TonesContext);
|
|
139
|
+
|
|
124
140
|
return (
|
|
125
141
|
<div aria-hidden className="flex flex-wrap gap-x-3 gap-y-1 text-xs text-text-muted">
|
|
126
|
-
{chart.series.map((series, index) =>
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
142
|
+
{chart.series.map((series, index) => {
|
|
143
|
+
const tone = seriesTone(series.key, tones);
|
|
144
|
+
const color = seriesColor(index, series.key, tones);
|
|
145
|
+
|
|
146
|
+
return (
|
|
147
|
+
<span key={series.key} className="flex items-center gap-1.5">
|
|
148
|
+
{tone === undefined ? (
|
|
149
|
+
<span className="size-2 rounded-sm" style={{ backgroundColor: color }} />
|
|
150
|
+
) : (
|
|
151
|
+
<span className="flex" style={{ color }}>
|
|
152
|
+
<Icon icon={UI_TONE_ICONS[tone]} size={12} />
|
|
153
|
+
</span>
|
|
154
|
+
)}
|
|
155
|
+
{series.key}
|
|
156
|
+
</span>
|
|
157
|
+
);
|
|
158
|
+
})}
|
|
132
159
|
</div>
|
|
133
160
|
);
|
|
134
161
|
}
|
|
@@ -136,6 +163,7 @@ function Legend({ chart }: { chart: UiChartData }) {
|
|
|
136
163
|
/* Every number of the data, for a screen reader, and on screen once a person opens it. */
|
|
137
164
|
function ValuesTable({ values, unit, shown }: { values: UiChartValues; unit: string | undefined; shown: boolean }) {
|
|
138
165
|
const { t } = useTranslation('agent-chat');
|
|
166
|
+
const tones = useContext(TonesContext);
|
|
139
167
|
|
|
140
168
|
const table = (
|
|
141
169
|
<table className={shown ? 'w-full border-collapse text-xs tabular-nums' : undefined}>
|
|
@@ -143,11 +171,20 @@ function ValuesTable({ values, unit, shown }: { values: UiChartValues; unit: str
|
|
|
143
171
|
<thead className={shown ? 'sticky top-0 z-1 bg-surface-hover' : undefined}>
|
|
144
172
|
<tr>
|
|
145
173
|
<td />
|
|
146
|
-
{values.series.map((series) =>
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
174
|
+
{values.series.map((series) => {
|
|
175
|
+
const tone = seriesTone(series.key, tones);
|
|
176
|
+
|
|
177
|
+
return (
|
|
178
|
+
<th
|
|
179
|
+
key={series.key}
|
|
180
|
+
scope="col"
|
|
181
|
+
className={shown ? 'h-8 px-2 text-right font-medium whitespace-nowrap text-text-muted' : undefined}
|
|
182
|
+
>
|
|
183
|
+
{series.key}
|
|
184
|
+
{tone !== undefined && <span className="sr-only">, {t(`blocks.event.tone.${tone}`)}</span>}
|
|
185
|
+
</th>
|
|
186
|
+
);
|
|
187
|
+
})}
|
|
151
188
|
</tr>
|
|
152
189
|
</thead>
|
|
153
190
|
<tbody>
|
|
@@ -180,6 +217,8 @@ function ValuesTable({ values, unit, shown }: { values: UiChartValues; unit: str
|
|
|
180
217
|
}
|
|
181
218
|
|
|
182
219
|
function Readout({ chart, index, left, unit }: { chart: UiChartData; index: number; left: number; unit: string | undefined }) {
|
|
220
|
+
const tones = useContext(TonesContext);
|
|
221
|
+
|
|
183
222
|
return (
|
|
184
223
|
<div
|
|
185
224
|
aria-hidden
|
|
@@ -189,7 +228,7 @@ function Readout({ chart, index, left, unit }: { chart: UiChartData; index: numb
|
|
|
189
228
|
<span className="font-medium wrap-anywhere text-text">{chart.labels[index]}</span>
|
|
190
229
|
{chart.series.map((series, at) => (
|
|
191
230
|
<span key={series.key} className="flex items-center gap-1.5 text-text-muted tabular-nums">
|
|
192
|
-
<span className="size-2 rounded-sm" style={{ backgroundColor: seriesColor(at) }} />
|
|
231
|
+
<span className="size-2 rounded-sm" style={{ backgroundColor: seriesColor(at, series.key, tones) }} />
|
|
193
232
|
{chart.series.length > 1 && <span>{series.key}</span>}
|
|
194
233
|
<span className="text-text">{valueText(series.values[index] ?? null, unit)}</span>
|
|
195
234
|
</span>
|
|
@@ -206,12 +245,13 @@ function VerticalChart({
|
|
|
206
245
|
character
|
|
207
246
|
}: {
|
|
208
247
|
chart: UiChartData;
|
|
209
|
-
kind: 'bar' | 'line';
|
|
248
|
+
kind: 'bar' | 'line' | 'area';
|
|
210
249
|
unit: string | undefined;
|
|
211
250
|
width: number;
|
|
212
251
|
character: number;
|
|
213
252
|
}) {
|
|
214
253
|
const [hover, setHover] = useState<number | null>(null);
|
|
254
|
+
const tones = useContext(TonesContext);
|
|
215
255
|
const { low, high, ticks, tickTexts, axisWidth, band, labelEvery, labelRoom } = verticalLayout(chart, unit, width, character);
|
|
216
256
|
const plotHeight = HEIGHT - PLOT_TOP - Math.round((LABEL_ROOM * character) / UI_CHART_CHARACTER);
|
|
217
257
|
|
|
@@ -242,6 +282,28 @@ function VerticalChart({
|
|
|
242
282
|
}, [])
|
|
243
283
|
.join(' ');
|
|
244
284
|
|
|
285
|
+
// Each unbroken run of values closes on the zero line, so a gap in a series leaves a gap in its area.
|
|
286
|
+
const areas = (values: (number | null)[]): string => {
|
|
287
|
+
const shapes: string[] = [];
|
|
288
|
+
let run: string[] = [];
|
|
289
|
+
let first = 0;
|
|
290
|
+
|
|
291
|
+
values.forEach((value, index) => {
|
|
292
|
+
if (value !== null) {
|
|
293
|
+
first = run.length === 0 ? index : first;
|
|
294
|
+
run.push(`L${center(index)} ${y(value)}`);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (run.length > 0 && (value === null || index === values.length - 1)) {
|
|
298
|
+
const last = value === null ? index - 1 : index;
|
|
299
|
+
shapes.push(`M${center(first)} ${baseline} ${run.join(' ')} L${center(last)} ${baseline} Z`);
|
|
300
|
+
run = [];
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
return shapes.join(' ');
|
|
305
|
+
};
|
|
306
|
+
|
|
245
307
|
return (
|
|
246
308
|
<>
|
|
247
309
|
<svg width={width} height={HEIGHT} aria-hidden className="block overflow-visible" onPointerLeave={() => setHover(null)}>
|
|
@@ -288,7 +350,7 @@ function VerticalChart({
|
|
|
288
350
|
width={Math.max(1, Math.round(barWidth) - 1)}
|
|
289
351
|
height={Math.abs(y(value) - baseline)}
|
|
290
352
|
rx={2}
|
|
291
|
-
style={{ fill: seriesColor(at) }}
|
|
353
|
+
style={{ fill: seriesColor(at, series.key, tones) }}
|
|
292
354
|
/>
|
|
293
355
|
)
|
|
294
356
|
)
|
|
@@ -297,7 +359,8 @@ function VerticalChart({
|
|
|
297
359
|
) : (
|
|
298
360
|
<g className={clsx(GROW, 'starting:opacity-0')}>
|
|
299
361
|
{chart.series.map((series, at) => (
|
|
300
|
-
<g key={series.key} style={{ color: seriesColor(at) }}>
|
|
362
|
+
<g key={series.key} style={{ color: seriesColor(at, series.key, tones) }}>
|
|
363
|
+
{kind === 'area' && <path d={areas(series.values)} fill="currentColor" fillOpacity={0.16} stroke="none" />}
|
|
301
364
|
<path
|
|
302
365
|
d={segments(series.values)}
|
|
303
366
|
fill="none"
|
|
@@ -333,6 +396,7 @@ function VerticalChart({
|
|
|
333
396
|
|
|
334
397
|
/* A row of 24px per category, its label beside the bars, which grow from zero to either side. */
|
|
335
398
|
function HorizontalChart({ chart, unit }: { chart: UiChartData; unit: string | undefined }) {
|
|
399
|
+
const tones = useContext(TonesContext);
|
|
336
400
|
const valueUnit = unitApart(unit) ? undefined : unit;
|
|
337
401
|
const { low, high } = uiChartRange(chart.min, chart.max)!;
|
|
338
402
|
const span = high - low;
|
|
@@ -356,7 +420,7 @@ function HorizontalChart({ chart, unit }: { chart: UiChartData; unit: string | u
|
|
|
356
420
|
style={{
|
|
357
421
|
left: `${((Math.min(value, 0) - low) / span) * 100}%`,
|
|
358
422
|
width: `${(Math.abs(value) / span) * 100}%`,
|
|
359
|
-
backgroundColor: seriesColor(at)
|
|
423
|
+
backgroundColor: seriesColor(at, series.key, tones)
|
|
360
424
|
}}
|
|
361
425
|
/>
|
|
362
426
|
</span>
|
|
@@ -376,6 +440,8 @@ function HorizontalChart({ chart, unit }: { chart: UiChartData; unit: string | u
|
|
|
376
440
|
|
|
377
441
|
/* A bar per category split into its series, on one scale so the rows compare. */
|
|
378
442
|
function StackedChart({ chart, unit }: { chart: UiChartData; unit: string | undefined }) {
|
|
443
|
+
const tones = useContext(TonesContext);
|
|
444
|
+
|
|
379
445
|
return (
|
|
380
446
|
<div className="flex flex-col gap-2">
|
|
381
447
|
{chart.labels.map((label, index) => (
|
|
@@ -388,7 +454,7 @@ function StackedChart({ chart, unit }: { chart: UiChartData; unit: string | unde
|
|
|
388
454
|
range={[0, chart.max]}
|
|
389
455
|
parts={chart.series.map((series, at) => ({
|
|
390
456
|
value: series.values[index] ?? 0,
|
|
391
|
-
color: seriesColor(at),
|
|
457
|
+
color: seriesColor(at, series.key, tones),
|
|
392
458
|
label: `${series.key} ${valueText(series.values[index] ?? 0, unit)}`
|
|
393
459
|
}))}
|
|
394
460
|
/>
|
|
@@ -457,6 +523,8 @@ function DrawnChart({
|
|
|
457
523
|
requested,
|
|
458
524
|
data,
|
|
459
525
|
unit,
|
|
526
|
+
title,
|
|
527
|
+
tones,
|
|
460
528
|
context,
|
|
461
529
|
nodeId
|
|
462
530
|
}: {
|
|
@@ -464,6 +532,8 @@ function DrawnChart({
|
|
|
464
532
|
requested: ChartKind;
|
|
465
533
|
data: UiProps<'Chart'>['data'];
|
|
466
534
|
unit: string | undefined;
|
|
535
|
+
title: string | undefined;
|
|
536
|
+
tones: ChartTones;
|
|
467
537
|
context: UiRenderContext;
|
|
468
538
|
nodeId: string;
|
|
469
539
|
}) {
|
|
@@ -473,30 +543,36 @@ function DrawnChart({
|
|
|
473
543
|
const [measureRows, rowsCut] = useTruncated<HTMLDivElement>(true);
|
|
474
544
|
const values = uiChartValues(data);
|
|
475
545
|
const { kind } = chart;
|
|
546
|
+
const toned = chart.series.some((series) => seriesTone(series.key, tones) !== undefined);
|
|
476
547
|
|
|
477
548
|
return (
|
|
478
|
-
<
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
{kind
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
549
|
+
<TonesContext value={tones}>
|
|
550
|
+
<figure className="chat-ui-flat flex flex-col gap-2.5 rounded-xl bg-ui-tile p-3.5">
|
|
551
|
+
{title !== undefined && title !== '' && <figcaption className="text-xs font-medium wrap-break-word text-text">{title}</figcaption>}
|
|
552
|
+
{(chart.series.length > 1 || toned) && <Legend chart={chart} />}
|
|
553
|
+
{kind !== 'stacked' && unitApart(unit) && <p className="text-xs text-text-faint">{unit}</p>}
|
|
554
|
+
<div ref={measure} role="img" aria-label={chartSummary(values, unit, t)} className="relative">
|
|
555
|
+
{kind === 'hbar' || kind === 'stacked' ? (
|
|
556
|
+
<div ref={measureRows}>
|
|
557
|
+
{kind === 'hbar' ? <HorizontalChart chart={chart} unit={unit} /> : <StackedChart chart={chart} unit={unit} />}
|
|
558
|
+
</div>
|
|
559
|
+
) : (
|
|
560
|
+
<div style={{ height: HEIGHT }}>
|
|
561
|
+
{width > 0 && <VerticalChart chart={chart} kind={kind} unit={unit} width={width} character={character} />}
|
|
562
|
+
</div>
|
|
563
|
+
)}
|
|
564
|
+
</div>
|
|
565
|
+
<ChartNotes
|
|
566
|
+
chart={chart}
|
|
567
|
+
requested={requested}
|
|
568
|
+
cut={rowsCut || labelsCut(chart, unit, width, character)}
|
|
569
|
+
values={values}
|
|
570
|
+
unit={unit}
|
|
571
|
+
context={context}
|
|
572
|
+
nodeId={nodeId}
|
|
573
|
+
/>
|
|
574
|
+
</figure>
|
|
575
|
+
</TonesContext>
|
|
500
576
|
);
|
|
501
577
|
}
|
|
502
578
|
|
|
@@ -505,7 +581,7 @@ function DrawnChart({
|
|
|
505
581
|
* place. It grows in once, and not at all for a person who asked for less motion.
|
|
506
582
|
*/
|
|
507
583
|
export function ChartRenderer({ node, context }: UiRendererProps<UiProps<'Chart'>>) {
|
|
508
|
-
const { kind, data, unit } = node.props;
|
|
584
|
+
const { kind, data, unit, title, tones } = node.props;
|
|
509
585
|
const chart = node.complete ? uiChartData(data, kind) : null;
|
|
510
586
|
|
|
511
587
|
if (!node.complete) {
|
|
@@ -516,5 +592,5 @@ export function ChartRenderer({ node, context }: UiRendererProps<UiProps<'Chart'
|
|
|
516
592
|
return <UiFallbackPart fallback={node.fallback} problem={{ kind: 'failed' }} />;
|
|
517
593
|
}
|
|
518
594
|
|
|
519
|
-
return <DrawnChart chart={chart} requested={kind} data={data} unit={unit} context={context} nodeId={node.id} />;
|
|
595
|
+
return <DrawnChart chart={chart} requested={kind} data={data} unit={unit} title={title} tones={tones} context={context} nodeId={node.id} />;
|
|
520
596
|
}
|
|
@@ -14,23 +14,43 @@ import { ImageGroup, ImageThumb } from '../../ImageView';
|
|
|
14
14
|
import { uiChildrenOf, uiNodeLabel, uiNodeText, uiUrlDomain } from '../node-text';
|
|
15
15
|
import type { UiRendererProps } from '../render-context';
|
|
16
16
|
import { useTruncated } from '../use-truncated';
|
|
17
|
+
import { UiLinkChip } from './links';
|
|
17
18
|
|
|
18
19
|
// The number of every source by its node id, which the list counts in its own order.
|
|
19
20
|
const SourceNumbers = createContext<ReadonlyMap<string, number>>(new Map());
|
|
20
21
|
|
|
21
|
-
/*
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
/* What a file is written in, by its extension, for code that names its file and no language. */
|
|
23
|
+
function languageOfFile(path: string): string | undefined {
|
|
24
|
+
return /\.([A-Za-z\d]+)$/.exec(path)?.[1]?.toLowerCase();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/*
|
|
28
|
+
* Plain text in the same measure until the node closes, so highlighting never makes it jump. With a file
|
|
29
|
+
* the header is its chip, which opens the file at `start` once the host checked it, in place of the language.
|
|
30
|
+
*/
|
|
31
|
+
export function CodeBlockRenderer({ node, context }: UiRendererProps<UiProps<'CodeBlock'>>) {
|
|
32
|
+
const { language, file, start, highlight } = node.props;
|
|
33
|
+
const filed = file !== undefined && file !== '';
|
|
34
|
+
const labeled = language !== undefined && language !== '';
|
|
35
|
+
const lined = start !== undefined || (highlight !== undefined && highlight.length > 0);
|
|
24
36
|
|
|
25
37
|
return (
|
|
26
38
|
<div className="chat-ui-code chat-ui-flat flex flex-col rounded-xl bg-ui-tile p-1.5">
|
|
27
|
-
{
|
|
28
|
-
<div className="chat-ui-flat-inner flex px-1.5 pt-0.5 pb-1.5">
|
|
29
|
-
|
|
39
|
+
{(filed || labeled) && (
|
|
40
|
+
<div className="chat-ui-flat-inner flex min-w-0 px-1.5 pt-0.5 pb-1.5">
|
|
41
|
+
{filed ? (
|
|
42
|
+
<UiLinkChip target={{ type: 'File', path: file, line: start }} context={context} />
|
|
43
|
+
) : (
|
|
44
|
+
<span className="rounded-md bg-ui-inset px-1.5 font-mono text-2xs text-text shadow-[inset_0_0_0_1px_var(--border)]">{language}</span>
|
|
45
|
+
)}
|
|
30
46
|
</div>
|
|
31
47
|
)}
|
|
32
48
|
<CodeStreamingContext.Provider value={!node.complete}>
|
|
33
|
-
<CodeBlock
|
|
49
|
+
<CodeBlock
|
|
50
|
+
code={uiNodeText(node).replace(/^\n|\n$/g, '')}
|
|
51
|
+
lang={language ?? (filed ? languageOfFile(file) : undefined) ?? 'text'}
|
|
52
|
+
lines={lined ? { start, marked: highlight } : undefined}
|
|
53
|
+
/>
|
|
34
54
|
</CodeStreamingContext.Provider>
|
|
35
55
|
</div>
|
|
36
56
|
);
|