@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
@@ -719,11 +719,66 @@ declare const _default: {
719
719
  stat: {
720
720
  change: string;
721
721
  from: string;
722
+ trend: string;
723
+ };
724
+ node: {
725
+ status: {
726
+ running: string;
727
+ needsYou: string;
728
+ done: string;
729
+ };
730
+ };
731
+ meter: {
732
+ label: string;
733
+ reading: string;
734
+ of: string;
735
+ mark: string;
736
+ };
737
+ parts: {
738
+ label: string;
739
+ part: string;
722
740
  };
723
741
  table: {
724
742
  label: string;
725
743
  showAll: string;
726
744
  };
745
+ changes: {
746
+ label_one: string;
747
+ label_other: string;
748
+ added_one: string;
749
+ added_other: string;
750
+ removed_one: string;
751
+ removed_other: string;
752
+ state: {
753
+ added: string;
754
+ modified: string;
755
+ deleted: string;
756
+ renamed: string;
757
+ };
758
+ };
759
+ diff: {
760
+ label: string;
761
+ unchanged: string;
762
+ partial: string;
763
+ showAll: string;
764
+ unavailable: string;
765
+ };
766
+ alternatives: {
767
+ label_one: string;
768
+ label_other: string;
769
+ recommended: string;
770
+ pro: string;
771
+ con: string;
772
+ };
773
+ tree: {
774
+ label: string;
775
+ };
776
+ numberField: {
777
+ between: string;
778
+ atLeast: string;
779
+ atMost: string;
780
+ number: string;
781
+ };
727
782
  chart: {
728
783
  values: string;
729
784
  summary: string;
@@ -812,6 +867,7 @@ declare const _default: {
812
867
  'access-unavailable': string;
813
868
  'block-stale': string;
814
869
  busy: string;
870
+ 'diffs-unsupported': string;
815
871
  'link-unchecked': string;
816
872
  'link-unsupported': string;
817
873
  'links-unsupported': string;
@@ -718,12 +718,67 @@ export default {
718
718
  },
719
719
  stat: {
720
720
  change: '{{change}} from {{previous}}',
721
- from: 'from {{previous}}'
721
+ from: 'from {{previous}}',
722
+ trend: 'Trend from {{first}} to {{last}}'
723
+ },
724
+ node: {
725
+ status: {
726
+ running: 'Running',
727
+ needsYou: 'Needs you',
728
+ done: 'Done'
729
+ }
730
+ },
731
+ meter: {
732
+ label: 'Meter',
733
+ reading: '{{value}} of {{max}}',
734
+ of: 'of {{max}}',
735
+ mark: 'mark at {{mark}}'
736
+ },
737
+ parts: {
738
+ label: 'Parts of the whole',
739
+ part: '{{label}}: {{value}}, {{share}}'
722
740
  },
723
741
  table: {
724
742
  label: 'Table of {{columns}}',
725
743
  showAll: 'Show all {{total}} rows'
726
744
  },
745
+ changes: {
746
+ label_one: '{{count}} changed file',
747
+ label_other: '{{count}} changed files',
748
+ added_one: '{{count}} line added',
749
+ added_other: '{{count}} lines added',
750
+ removed_one: '{{count}} line removed',
751
+ removed_other: '{{count}} lines removed',
752
+ state: {
753
+ added: 'New',
754
+ modified: 'Changed',
755
+ deleted: 'Deleted',
756
+ renamed: 'Renamed'
757
+ }
758
+ },
759
+ diff: {
760
+ label: 'Changes in {{path}}',
761
+ unchanged: 'No changes',
762
+ partial: 'Only the first lines are shown.',
763
+ showAll: 'Open the whole diff',
764
+ unavailable: 'Could not read this diff'
765
+ },
766
+ alternatives: {
767
+ label_one: '{{count}} option',
768
+ label_other: '{{count}} options',
769
+ recommended: 'Recommended',
770
+ pro: 'For:',
771
+ con: 'Against:'
772
+ },
773
+ tree: {
774
+ label: 'Tree'
775
+ },
776
+ numberField: {
777
+ between: 'A number from {{min}} to {{max}}',
778
+ atLeast: 'A number of at least {{min}}',
779
+ atMost: 'A number of at most {{max}}',
780
+ number: 'A number'
781
+ },
727
782
  chart: {
728
783
  values: 'Values',
729
784
  summary: '{{count}} values, highest {{label}} at {{value}}',
@@ -812,6 +867,7 @@ export default {
812
867
  'access-unavailable': 'The chat that made this no longer has access.',
813
868
  'block-stale': 'This block changed since it was drawn.',
814
869
  busy: 'Too many live blocks reading.',
870
+ 'diffs-unsupported': 'The machine does not show diffs in blocks.',
815
871
  'link-unchecked': 'This link has to be checked again.',
816
872
  'link-unsupported': 'The machine cannot open this link.',
817
873
  'links-unsupported': 'The machine does not open links from blocks.',
@@ -719,11 +719,66 @@ declare const _default: {
719
719
  stat: {
720
720
  change: string;
721
721
  from: string;
722
+ trend: string;
723
+ };
724
+ node: {
725
+ status: {
726
+ running: string;
727
+ needsYou: string;
728
+ done: string;
729
+ };
730
+ };
731
+ meter: {
732
+ label: string;
733
+ reading: string;
734
+ of: string;
735
+ mark: string;
736
+ };
737
+ parts: {
738
+ label: string;
739
+ part: string;
722
740
  };
723
741
  table: {
724
742
  label: string;
725
743
  showAll: string;
726
744
  };
745
+ changes: {
746
+ label_one: string;
747
+ label_other: string;
748
+ added_one: string;
749
+ added_other: string;
750
+ removed_one: string;
751
+ removed_other: string;
752
+ state: {
753
+ added: string;
754
+ modified: string;
755
+ deleted: string;
756
+ renamed: string;
757
+ };
758
+ };
759
+ diff: {
760
+ label: string;
761
+ unchanged: string;
762
+ partial: string;
763
+ showAll: string;
764
+ unavailable: string;
765
+ };
766
+ alternatives: {
767
+ label_one: string;
768
+ label_other: string;
769
+ recommended: string;
770
+ pro: string;
771
+ con: string;
772
+ };
773
+ tree: {
774
+ label: string;
775
+ };
776
+ numberField: {
777
+ between: string;
778
+ atLeast: string;
779
+ atMost: string;
780
+ number: string;
781
+ };
727
782
  chart: {
728
783
  values: string;
729
784
  summary: string;
@@ -812,6 +867,7 @@ declare const _default: {
812
867
  'access-unavailable': string;
813
868
  'block-stale': string;
814
869
  busy: string;
870
+ 'diffs-unsupported': string;
815
871
  'link-unchecked': string;
816
872
  'link-unsupported': string;
817
873
  'links-unsupported': string;
@@ -718,12 +718,67 @@ export default {
718
718
  },
719
719
  stat: {
720
720
  change: '{{change}} vanaf {{previous}}',
721
- from: 'vanaf {{previous}}'
721
+ from: 'vanaf {{previous}}',
722
+ trend: 'Verloop van {{first}} naar {{last}}'
723
+ },
724
+ node: {
725
+ status: {
726
+ running: 'Bezig',
727
+ needsYou: 'Wacht op jou',
728
+ done: 'Klaar'
729
+ }
730
+ },
731
+ meter: {
732
+ label: 'Meter',
733
+ reading: '{{value}} van {{max}}',
734
+ of: 'van {{max}}',
735
+ mark: 'markering bij {{mark}}'
736
+ },
737
+ parts: {
738
+ label: 'Delen van het geheel',
739
+ part: '{{label}}: {{value}}, {{share}}'
722
740
  },
723
741
  table: {
724
742
  label: 'Tabel van {{columns}}',
725
743
  showAll: 'Alle {{total}} rijen tonen'
726
744
  },
745
+ changes: {
746
+ label_one: '{{count}} gewijzigd bestand',
747
+ label_other: '{{count}} gewijzigde bestanden',
748
+ added_one: '{{count}} regel toegevoegd',
749
+ added_other: '{{count}} regels toegevoegd',
750
+ removed_one: '{{count}} regel verwijderd',
751
+ removed_other: '{{count}} regels verwijderd',
752
+ state: {
753
+ added: 'Nieuw',
754
+ modified: 'Gewijzigd',
755
+ deleted: 'Verwijderd',
756
+ renamed: 'Hernoemd'
757
+ }
758
+ },
759
+ diff: {
760
+ label: 'Wijzigingen in {{path}}',
761
+ unchanged: 'Geen wijzigingen',
762
+ partial: 'Alleen de eerste regels staan hier.',
763
+ showAll: 'Hele diff openen',
764
+ unavailable: 'Kon deze diff niet lezen'
765
+ },
766
+ alternatives: {
767
+ label_one: '{{count}} optie',
768
+ label_other: '{{count}} opties',
769
+ recommended: 'Aanbevolen',
770
+ pro: 'Voor:',
771
+ con: 'Tegen:'
772
+ },
773
+ tree: {
774
+ label: 'Boom'
775
+ },
776
+ numberField: {
777
+ between: 'Een getal van {{min}} tot en met {{max}}',
778
+ atLeast: 'Een getal van minstens {{min}}',
779
+ atMost: 'Een getal van hoogstens {{max}}',
780
+ number: 'Een getal'
781
+ },
727
782
  chart: {
728
783
  values: 'Waarden',
729
784
  summary: '{{count}} waarden, hoogste {{label}} met {{value}}',
@@ -812,6 +867,7 @@ export default {
812
867
  'access-unavailable': 'De chat die dit maakte heeft geen toegang meer.',
813
868
  'block-stale': 'Dit blok is veranderd sinds het getekend werd.',
814
869
  busy: 'Er lezen te veel live blokken tegelijk.',
870
+ 'diffs-unsupported': 'De machine toont geen diffs in blokken.',
815
871
  'link-unchecked': 'Deze link moet opnieuw gecontroleerd worden.',
816
872
  'link-unsupported': 'De machine kan deze link niet openen.',
817
873
  'links-unsupported': 'De machine opent geen links uit blokken.',
package/dist/theme.css CHANGED
@@ -275,6 +275,12 @@
275
275
  .chat-ui-section-body .chat-ui-flat thead { background-color: var(--chat-ui-tile); }
276
276
  .chat-code pre { margin: 0; padding: round(0.625rem, 1px) round(0.75rem, 1px); user-select: text; background: transparent !important; font-family: var(--font-mono); font-size: var(--text-code); line-height: var(--text-code--line-height); }
277
277
  .chat-code code { font-family: inherit; }
278
+ /* Numbered or marked lines each fill the width, so a mark is a band from edge to edge: the padding moves from the block
279
+ onto its lines. A number is generated content, which a selection never copies. */
280
+ .chat-code pre[data-lined] { padding-inline: 0; }
281
+ .chat-code pre[data-lined] .line { display: inline-block; box-sizing: border-box; min-width: 100%; vertical-align: top; min-height: 1lh; padding-inline: round(0.75rem, 1px); }
282
+ .chat-code pre[data-lined] .line[data-line]::before { content: attr(data-line); display: inline-block; width: calc(var(--chat-code-digits, 1) * 1ch); margin-right: round(0.75rem, 1px); color: var(--text-faint); text-align: right; user-select: none; }
283
+ .chat-code pre[data-lined] .line[data-marked] { background: var(--accent-soft); }
278
284
  .chat-code-actions { position: absolute; top: 4px; right: 4px; border-radius: 6px; background: var(--surface-raised); color: var(--text-muted); box-shadow: 0 0 0 1px var(--border); }
279
285
  .chat-code-error { margin: 0; padding: 0 12px 10px; color: var(--status-error); font-size: var(--text-sm); }
280
286
  @media (hover: hover) and (pointer: fine) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adecore/agents-react",
3
- "version": "0.70.1",
3
+ "version": "0.71.0",
4
4
  "description": "React agent chat threads, composers, approvals, provider accounts and usage views.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -72,12 +72,12 @@
72
72
  "test:visuals": "bun --config=integration.bunfig.toml --conditions=source test ./src/chat/visual-viewport.integration.test.ts"
73
73
  },
74
74
  "dependencies": {
75
- "@adecore/agent-contracts": "0.70.1",
76
- "@adecore/editor": "0.70.1",
77
- "@adecore/editor-react": "0.70.1",
78
- "@adecore/intelligent-ui": "0.70.1",
79
- "@adecore/merge": "0.70.1",
80
- "@adecore/utils": "0.70.1",
75
+ "@adecore/agent-contracts": "0.71.0",
76
+ "@adecore/editor": "0.71.0",
77
+ "@adecore/editor-react": "0.71.0",
78
+ "@adecore/intelligent-ui": "0.71.0",
79
+ "@adecore/merge": "0.71.0",
80
+ "@adecore/utils": "0.71.0",
81
81
  "@codemirror/commands": "^6.11.1",
82
82
  "@codemirror/language": "^6.13.1",
83
83
  "@codemirror/state": "^6.7.6",
@@ -101,14 +101,14 @@
101
101
  "zustand": "^5.1.0"
102
102
  },
103
103
  "peerDependencies": {
104
- "@adecore/ui": "^0.70.1",
104
+ "@adecore/ui": "^0.71.0",
105
105
  "i18next": "^26.4.2 || ^27.0.0",
106
106
  "react": "^19.3.0",
107
107
  "react-dom": "^19.3.0",
108
108
  "react-i18next": "^17.0.15 || ^18.0.0"
109
109
  },
110
110
  "devDependencies": {
111
- "@adecore/ui": "0.70.1",
111
+ "@adecore/ui": "0.71.0",
112
112
  "@types/bun": "^1.4.4",
113
113
  "@types/react": "^19.3.0",
114
114
  "@types/react-dom": "^19.3.0",
@@ -1,7 +1,7 @@
1
1
  import { ButtonGroup, IconButton, ScrollArea } from '@adecore/ui';
2
2
  import clsx from 'clsx';
3
3
  import { Check, Copy } from 'lucide-react';
4
- import { Fragment, memo, useContext, useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
4
+ import { Fragment, memo, useContext, useEffect, useMemo, useRef, useState, type CSSProperties, type ReactNode } from 'react';
5
5
  import { useTranslation } from 'react-i18next';
6
6
  import { useChatHost } from '../../host/host';
7
7
  import { IncrementalLines, type CodeToken } from './code-lines';
@@ -12,15 +12,26 @@ import { WHOLE_FADE_CLASS } from './rehype-fade';
12
12
 
13
13
  const COPIED_MS = 1500;
14
14
 
15
- /* A line whose tokens did not change keeps its elements, so a selection in it survives the next delta. */
16
- const CodeLine = memo(function CodeLine({ tokens }: { tokens: CodeToken[] }) {
15
+ /* Which lines of a block are numbered and marked. */
16
+ export interface CodeBlockLines {
17
+ /* The number of the first line. With it every line shows its number. */
18
+ start?: number;
19
+
20
+ /* The numbers of the lines to mark, counted from `start`, or from 1 without it. */
21
+ marked?: readonly number[];
22
+ }
23
+
24
+ /* A line whose tokens did not change keeps its elements, so a selection in it survives the next delta. A line not highlighted yet is its text. */
25
+ const CodeLine = memo(function CodeLine({ tokens, number, marked }: { tokens: CodeToken[] | string; number?: number; marked?: boolean }) {
17
26
  return (
18
- <span className="line">
19
- {tokens.map((token, index) => (
20
- <span key={index} style={tokenStyle(token)}>
21
- {token.content}
22
- </span>
23
- ))}
27
+ <span className="line" data-line={number} data-marked={marked ? '' : undefined}>
28
+ {typeof tokens === 'string'
29
+ ? tokens
30
+ : tokens.map((token, index) => (
31
+ <span key={index} style={tokenStyle(token)}>
32
+ {token.content}
33
+ </span>
34
+ ))}
24
35
  </span>
25
36
  );
26
37
  });
@@ -29,9 +40,9 @@ const CodeLine = memo(function CodeLine({ tokens }: { tokens: CodeToken[] }) {
29
40
  * A fenced block, highlighted a line at a time. Until shiki and the grammar are there it holds its
30
41
  * place invisibly, so bare code never turns colored. An open fence is tokenized as it grows, and
31
42
  * closing it does not draw it again. `view` takes the place of the code, such as what the code draws,
32
- * and Copy still copies the code.
43
+ * and Copy still copies the code. `lines` numbers and marks lines; a number is never part of a selection.
33
44
  */
34
- export function CodeBlock({ code, lang, actions, view }: { code: string; lang: string; actions?: ReactNode; view?: ReactNode }) {
45
+ export function CodeBlock({ code, lang, actions, view, lines }: { code: string; lang: string; actions?: ReactNode; view?: ReactNode; lines?: CodeBlockLines }) {
35
46
  const { t } = useTranslation('agent-chat');
36
47
  const theme = useCodeTheme();
37
48
  const { custom } = useChatHost().code;
@@ -44,8 +55,8 @@ export function CodeBlock({ code, lang, actions, view }: { code: string; lang: s
44
55
  const tokenizer = highlighter.tokenizer(lang, theme);
45
56
  // Only a block that had to wait fades in; one drawn highlighted from its first frame just stands there.
46
57
  const [waited] = useState(tokenizer === null);
47
- const lines = useMemo(() => (tokenizer ? new IncrementalLines(tokenizer.tokenize) : null), [tokenizer]);
48
- const tokens = useMemo(() => lines?.update(code, !streaming) ?? null, [lines, code, streaming]);
58
+ const incremental = useMemo(() => (tokenizer ? new IncrementalLines(tokenizer.tokenize) : null), [tokenizer]);
59
+ const tokens = useMemo(() => incremental?.update(code, !streaming) ?? null, [incremental, code, streaming]);
49
60
 
50
61
  useEffect(() => {
51
62
  if (copyState !== 'copied') {
@@ -93,6 +104,10 @@ export function CodeBlock({ code, lang, actions, view }: { code: string; lang: s
93
104
  }, [highlighter, lang, theme, custom, tokenizer]);
94
105
 
95
106
  const pending = (tokenizer === null || tokens === null) && loaded !== 'failed';
107
+ // Numbered or marked code is drawn a line at a time before it is highlighted too, so a line never changes its box.
108
+ const drawn: readonly (CodeToken[] | string)[] | null = tokens ?? (lines === undefined ? null : code.split('\n'));
109
+ const first = lines?.start ?? 1;
110
+ const digits = lines?.start === undefined || drawn === null ? undefined : String(first + drawn.length - 1).length;
96
111
 
97
112
  return (
98
113
  <div className="chat-code" data-copy-state={copyState}>
@@ -102,16 +117,21 @@ export function CodeBlock({ code, lang, actions, view }: { code: string; lang: s
102
117
  render={<pre />}
103
118
  viewportClassName={clsx(pending && 'invisible', !pending && tokens !== null && waited && WHOLE_FADE_CLASS)}
104
119
  aria-hidden={pending || undefined}
105
- style={{ color: tokenizer?.fg }}
120
+ data-lined={lines === undefined ? undefined : ''}
121
+ style={{ color: tokenizer?.fg, '--chat-code-digits': digits } as CSSProperties}
106
122
  >
107
123
  <code>
108
- {tokens === null
124
+ {drawn === null
109
125
  ? code
110
- : tokens.map((line, index) => (
126
+ : drawn.map((line, index) => (
111
127
  // Lines only ever grow at the end, so the place of a line is a stable key.
112
128
  <Fragment key={index}>
113
- <CodeLine tokens={line} />
114
- {index < tokens.length - 1 && '\n'}
129
+ <CodeLine
130
+ tokens={line}
131
+ number={lines?.start === undefined ? undefined : first + index}
132
+ marked={lines?.marked?.includes(first + index)}
133
+ />
134
+ {index < drawn.length - 1 && '\n'}
115
135
  </Fragment>
116
136
  ))}
117
137
  </code>
@@ -38,6 +38,7 @@ import { UiSourceCitation } from './renderers/content';
38
38
  import { uiReplyParts } from './reply-parts';
39
39
  import { UiBlockFrame } from './UiBlockFrame';
40
40
  import { UiFallbackPart } from './UiFallbackPart';
41
+ import { useUiDiffs } from './use-ui-diffs';
41
42
  import { useUiLinks } from './use-ui-links';
42
43
  import { useUiQueries, useUiLiveValues } from './use-ui-queries';
43
44
 
@@ -68,12 +69,13 @@ const BLOCK = '$block';
68
69
  * Parents whose text is read as written: code, a short tag, and the labels of controls, whose
69
70
  * accessible name and sent text are that same string.
70
71
  */
71
- const LITERAL_PARENTS = new Set(['CodeBlock', 'Tag', 'Choice', 'Item', 'Switch', 'Slider', 'Segmented', 'Option', 'Button', 'Column']);
72
+ const LITERAL_PARENTS = new Set(['CodeBlock', 'Tag', 'Choice', 'Item', 'Switch', 'Slider', 'Segmented', 'Option', 'Button', 'Column', 'Leaf']);
72
73
 
73
74
  /* Parents that stack their children, where a run of text and inline nodes is one paragraph. */
74
75
  const PARAGRAPHS: Readonly<Record<string, string>> = {
75
76
  [BLOCK]: 'text-xs text-text',
76
77
  Tab: 'text-xs text-text',
78
+ Pane: 'text-xs text-text',
77
79
  Section: 'text-xs text-text-muted'
78
80
  };
79
81
 
@@ -279,7 +281,14 @@ function isInline(node: UiViewNode): boolean {
279
281
  return true;
280
282
  }
281
283
 
282
- return node.error === undefined && (node.type === 'Tag' || (LINKS.has(node.type) && node.children.length === 0));
284
+ if (node.error !== undefined) {
285
+ return false;
286
+ }
287
+
288
+ // An open Diff is a tile of its own, also while its host has not answered or never will.
289
+ const chip = LINKS.has(node.type) && node.children.length === 0 && !(node.type === 'Diff' && node.props.open === true);
290
+
291
+ return node.type === 'Tag' || node.type === 'Keys' || chip;
283
292
  }
284
293
 
285
294
  function isBlank(node: UiViewNode): boolean {
@@ -525,6 +534,7 @@ function UiBlockBody({
525
534
  [sources, element]
526
535
  );
527
536
 
537
+ const diff = useUiDiffs(block, state, context, queries.reads, evaluation.nodes);
528
538
  const { liveValue, liveNode } = useUiLiveValues(block, evaluation.nodes, queries.currentReadings);
529
539
  const sendChoice = host.intelligentUi?.sendChoice;
530
540
  const place = useMemo(() => placeReader(frozen, block.revision, unrecorded), [frozen, block.revision, unrecorded]);
@@ -532,6 +542,7 @@ function UiBlockBody({
532
542
  const rendering: UiRenderContext = {
533
543
  ...context,
534
544
  ...links,
545
+ diff,
535
546
  place,
536
547
  answer,
537
548
  failedChoiceId,
@@ -0,0 +1,51 @@
1
+ import { shortcut, shortcutParts } from '@adecore/ui';
2
+
3
+ /* How an agent may write a key, by its lower case, as the word a shortcut is parsed from. */
4
+ const KEY_WORDS: Readonly<Record<string, string>> = {
5
+ mod: 'Mod',
6
+ ctrl: 'Ctrl',
7
+ control: 'Ctrl',
8
+ alt: 'Alt',
9
+ option: 'Alt',
10
+ opt: 'Alt',
11
+ shift: 'Shift',
12
+ meta: 'Meta',
13
+ cmd: 'Meta',
14
+ command: 'Meta',
15
+ enter: 'Enter',
16
+ return: 'Enter',
17
+ escape: 'Escape',
18
+ esc: 'Escape',
19
+ backspace: 'Backspace',
20
+ delete: 'Delete',
21
+ del: 'Delete',
22
+ tab: 'Tab',
23
+ space: 'Space',
24
+ left: 'ArrowLeft',
25
+ right: 'ArrowRight',
26
+ up: 'ArrowUp',
27
+ down: 'ArrowDown',
28
+ arrowleft: 'ArrowLeft',
29
+ arrowright: 'ArrowRight',
30
+ arrowup: 'ArrowUp',
31
+ arrowdown: 'ArrowDown'
32
+ };
33
+
34
+ /*
35
+ * The caps of a shortcut written as `mod+K`, the way this platform prints them. Keys a shortcut cannot
36
+ * hold, such as two letters or a key it has no name for, stand as written, with only `mod` translated.
37
+ */
38
+ export function uiKeyCaps(text: string, apple: boolean): string[] {
39
+ const written = text.trim();
40
+ // A trailing `++` is the plus key itself, which a plain split would read as two empty words.
41
+ const words = (written.endsWith('++') ? [...written.slice(0, -2).split('+'), '+'] : written === '+' ? ['+'] : written.split('+'))
42
+ .map((word) => word.trim())
43
+ .filter((word) => word !== '')
44
+ .map((word) => KEY_WORDS[word.toLowerCase()] ?? (/^f\d{1,2}$/i.test(word) ? word.toUpperCase() : word));
45
+
46
+ try {
47
+ return shortcutParts(shortcut(words.join('+')), apple);
48
+ } catch {
49
+ return words.map((word) => (word === 'Mod' ? (apple ? '⌘' : 'Ctrl') : word));
50
+ }
51
+ }
@@ -0,0 +1,32 @@
1
+ import type { TFunction } from 'i18next';
2
+ import { uiReasonText } from './node-text';
3
+ import type { UiLink, UiLinkTarget, UiRenderContext } from './render-context';
4
+
5
+ export const UI_PLAIN_LINK: UiLink = { state: 'plain' };
6
+
7
+ export function uiBaseName(path: string): string {
8
+ const trimmed = path.replace(/\/+$/, '');
9
+
10
+ return trimmed.slice(trimmed.lastIndexOf('/') + 1) || path;
11
+ }
12
+
13
+ /* Why the host leaves a link as text, for its tooltip; null where no host checks links at all. */
14
+ export function uiPlainLinkReason(t: TFunction<'agent-chat'>, link: UiLink, context: UiRenderContext): string | null {
15
+ return uiReasonText(t, link.code, link.reason) ?? (context.link === undefined ? null : t('blocks.outsideProject'));
16
+ }
17
+
18
+ /*
19
+ * A link that is a whole row rather than a chip, such as a changed file: `open` once the host can open the
20
+ * target, otherwise the reason it stays text.
21
+ */
22
+ export function uiLinkAction(t: TFunction<'agent-chat'>, target: UiLinkTarget, context: UiRenderContext): { open: (() => void) | null; reason: string | null } {
23
+ const link = context.link?.(target) ?? UI_PLAIN_LINK;
24
+
25
+ if (link.state === 'plain') {
26
+ return { open: null, reason: uiPlainLinkReason(t, link, context) };
27
+ }
28
+
29
+ const { openLink } = context;
30
+
31
+ return { open: openLink === undefined ? null : () => openLink(target), reason: null };
32
+ }
@@ -84,6 +84,7 @@ const UI_REASON_CODES = new Set([
84
84
  'access-unavailable',
85
85
  'block-stale',
86
86
  'busy',
87
+ 'diffs-unsupported',
87
88
  'link-unchecked',
88
89
  'link-unsupported',
89
90
  'links-unsupported',