@adecore/agents-react 0.70.1 → 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.
Files changed (82) hide show
  1. package/dist/chat/ui/CodeBlock.d.ts +6 -1
  2. package/dist/chat/ui/CodeBlock.js +39 -23
  3. package/dist/chat/ui/intelligent-ui/UiReply.js +11 -2
  4. package/dist/chat/ui/intelligent-ui/key-caps.d.ts +1 -0
  5. package/dist/chat/ui/intelligent-ui/key-caps.js +45 -0
  6. package/dist/chat/ui/intelligent-ui/link-action.d.ts +9 -0
  7. package/dist/chat/ui/intelligent-ui/link-action.js +32 -0
  8. package/dist/chat/ui/intelligent-ui/node-text.js +1 -1
  9. package/dist/chat/ui/intelligent-ui/patch-clip.d.ts +4 -0
  10. package/dist/chat/ui/intelligent-ui/patch-clip.js +64 -0
  11. package/dist/chat/ui/intelligent-ui/registry.js +31 -5
  12. package/dist/chat/ui/intelligent-ui/render-context.d.ts +13 -0
  13. package/dist/chat/ui/intelligent-ui/renderers/alternatives.d.ts +6 -0
  14. package/dist/chat/ui/intelligent-ui/renderers/alternatives.js +296 -0
  15. package/dist/chat/ui/intelligent-ui/renderers/changes.d.ts +4 -0
  16. package/dist/chat/ui/intelligent-ui/renderers/changes.js +266 -0
  17. package/dist/chat/ui/intelligent-ui/renderers/chart.js +522 -371
  18. package/dist/chat/ui/intelligent-ui/renderers/content.d.ts +1 -1
  19. package/dist/chat/ui/intelligent-ui/renderers/content.js +94 -43
  20. package/dist/chat/ui/intelligent-ui/renderers/data.js +478 -245
  21. package/dist/chat/ui/intelligent-ui/renderers/diff.d.ts +4 -0
  22. package/dist/chat/ui/intelligent-ui/renderers/diff.js +427 -0
  23. package/dist/chat/ui/intelligent-ui/renderers/inputs.d.ts +1 -0
  24. package/dist/chat/ui/intelligent-ui/renderers/inputs.js +354 -110
  25. package/dist/chat/ui/intelligent-ui/renderers/keys.d.ts +3 -0
  26. package/dist/chat/ui/intelligent-ui/renderers/keys.js +60 -0
  27. package/dist/chat/ui/intelligent-ui/renderers/links.d.ts +13 -2
  28. package/dist/chat/ui/intelligent-ui/renderers/links.js +65 -85
  29. package/dist/chat/ui/intelligent-ui/renderers/meter.d.ts +4 -0
  30. package/dist/chat/ui/intelligent-ui/renderers/meter.js +371 -0
  31. package/dist/chat/ui/intelligent-ui/renderers/quote.d.ts +3 -0
  32. package/dist/chat/ui/intelligent-ui/renderers/quote.js +123 -0
  33. package/dist/chat/ui/intelligent-ui/renderers/radio.d.ts +3 -0
  34. package/dist/chat/ui/intelligent-ui/renderers/radio.js +205 -0
  35. package/dist/chat/ui/intelligent-ui/renderers/structure.d.ts +2 -0
  36. package/dist/chat/ui/intelligent-ui/renderers/structure.js +156 -45
  37. package/dist/chat/ui/intelligent-ui/renderers/text.js +365 -215
  38. package/dist/chat/ui/intelligent-ui/renderers/tree.d.ts +5 -0
  39. package/dist/chat/ui/intelligent-ui/renderers/tree.js +284 -0
  40. package/dist/chat/ui/intelligent-ui/table-data.d.ts +9 -2
  41. package/dist/chat/ui/intelligent-ui/table-data.js +68 -3
  42. package/dist/chat/ui/intelligent-ui/tones.d.ts +1 -1
  43. package/dist/chat/ui/intelligent-ui/tones.js +7 -7
  44. package/dist/chat/ui/intelligent-ui/use-ui-diffs.d.ts +4 -0
  45. package/dist/chat/ui/intelligent-ui/use-ui-diffs.js +201 -0
  46. package/dist/host/host.d.ts +2 -1
  47. package/dist/locales/en/agent-chat.d.ts +56 -0
  48. package/dist/locales/en/agent-chat.js +57 -1
  49. package/dist/locales/nl/agent-chat.d.ts +56 -0
  50. package/dist/locales/nl/agent-chat.js +57 -1
  51. package/dist/theme.css +6 -0
  52. package/package.json +9 -9
  53. package/src/chat/ui/CodeBlock.tsx +38 -18
  54. package/src/chat/ui/intelligent-ui/UiReply.tsx +13 -2
  55. package/src/chat/ui/intelligent-ui/key-caps.ts +51 -0
  56. package/src/chat/ui/intelligent-ui/link-action.ts +32 -0
  57. package/src/chat/ui/intelligent-ui/node-text.ts +1 -0
  58. package/src/chat/ui/intelligent-ui/patch-clip.ts +83 -0
  59. package/src/chat/ui/intelligent-ui/registry.ts +31 -4
  60. package/src/chat/ui/intelligent-ui/render-context.ts +21 -0
  61. package/src/chat/ui/intelligent-ui/renderers/alternatives.tsx +76 -0
  62. package/src/chat/ui/intelligent-ui/renderers/changes.tsx +97 -0
  63. package/src/chat/ui/intelligent-ui/renderers/chart.tsx +122 -46
  64. package/src/chat/ui/intelligent-ui/renderers/content.tsx +27 -7
  65. package/src/chat/ui/intelligent-ui/renderers/data.tsx +165 -52
  66. package/src/chat/ui/intelligent-ui/renderers/diff.tsx +144 -0
  67. package/src/chat/ui/intelligent-ui/renderers/inputs.tsx +111 -19
  68. package/src/chat/ui/intelligent-ui/renderers/keys.tsx +26 -0
  69. package/src/chat/ui/intelligent-ui/renderers/links.tsx +40 -24
  70. package/src/chat/ui/intelligent-ui/renderers/meter.tsx +105 -0
  71. package/src/chat/ui/intelligent-ui/renderers/quote.tsx +29 -0
  72. package/src/chat/ui/intelligent-ui/renderers/radio.tsx +130 -0
  73. package/src/chat/ui/intelligent-ui/renderers/structure.tsx +54 -7
  74. package/src/chat/ui/intelligent-ui/renderers/text.tsx +70 -36
  75. package/src/chat/ui/intelligent-ui/renderers/tree.tsx +85 -0
  76. package/src/chat/ui/intelligent-ui/table-data.ts +84 -6
  77. package/src/chat/ui/intelligent-ui/tones.ts +7 -7
  78. package/src/chat/ui/intelligent-ui/use-ui-diffs.ts +119 -0
  79. package/src/host/host.ts +4 -0
  80. package/src/locales/en/agent-chat.ts +57 -1
  81. package/src/locales/nl/agent-chat.ts +57 -1
  82. package/src/theme.css +6 -0
@@ -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
- function seriesColor(index: number): string {
43
- return `var(--chart-${index + 1})`;
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
- <span key={series.key} className="flex items-center gap-1.5">
128
- <span className="size-2 rounded-sm" style={{ backgroundColor: seriesColor(index) }} />
129
- {series.key}
130
- </span>
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
- <th key={series.key} scope="col" className={shown ? 'h-8 px-2 text-right font-medium whitespace-nowrap text-text-muted' : undefined}>
148
- {series.key}
149
- </th>
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
- <figure className="chat-ui-flat flex flex-col gap-2.5 rounded-xl bg-ui-tile p-3.5">
479
- {chart.series.length > 1 && <Legend chart={chart} />}
480
- {kind !== 'stacked' && unitApart(unit) && <p className="text-xs text-text-faint">{unit}</p>}
481
- <div ref={measure} role="img" aria-label={chartSummary(values, unit, t)} className="relative">
482
- {kind === 'hbar' || kind === 'stacked' ? (
483
- <div ref={measureRows}>{kind === 'hbar' ? <HorizontalChart chart={chart} unit={unit} /> : <StackedChart chart={chart} unit={unit} />}</div>
484
- ) : (
485
- <div style={{ height: HEIGHT }}>
486
- {width > 0 && <VerticalChart chart={chart} kind={kind} unit={unit} width={width} character={character} />}
487
- </div>
488
- )}
489
- </div>
490
- <ChartNotes
491
- chart={chart}
492
- requested={requested}
493
- cut={rowsCut || labelsCut(chart, unit, width, character)}
494
- values={values}
495
- unit={unit}
496
- context={context}
497
- nodeId={nodeId}
498
- />
499
- </figure>
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
- /* Plain text in the same measure until the node closes, so highlighting never makes it jump. */
22
- export function CodeBlockRenderer({ node }: UiRendererProps<UiProps<'CodeBlock'>>) {
23
- const { language } = node.props;
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
- {language !== undefined && language !== '' && (
28
- <div className="chat-ui-flat-inner flex px-1.5 pt-0.5 pb-1.5">
29
- <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>
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 code={uiNodeText(node).replace(/^\n|\n$/g, '')} lang={language ?? 'text'} />
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
  );