@adecore/agents-react 0.46.3 → 0.48.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 (105) hide show
  1. package/dist/agents/accounts.d.ts +9 -1
  2. package/dist/agents/accounts.js +31 -7
  3. package/dist/chat/account-choice.d.ts +5 -4
  4. package/dist/chat/account-choice.js +47 -39
  5. package/dist/chat/index.d.ts +1 -0
  6. package/dist/chat/index.js +1 -0
  7. package/dist/chat/logic/scrubber.js +12 -0
  8. package/dist/chat/logic/timeline-copy.js +2 -0
  9. package/dist/chat/logic/timeline.d.ts +6 -1
  10. package/dist/chat/logic/timeline.js +36 -10
  11. package/dist/chat/preferences.d.ts +2 -2
  12. package/dist/chat/preferences.js +11 -5
  13. package/dist/chat/ui/AccountPill.js +9 -6
  14. package/dist/chat/ui/ChatActivity.d.ts +2 -1
  15. package/dist/chat/ui/ChatActivity.js +295 -61
  16. package/dist/chat/ui/Composer.d.ts +2 -1
  17. package/dist/chat/ui/Composer.js +492 -486
  18. package/dist/chat/ui/LimitState.js +180 -172
  19. package/dist/chat/ui/PromptEditor.js +4 -1
  20. package/dist/chat/ui/ReferenceChip.d.ts +2 -1
  21. package/dist/chat/ui/ReferenceChip.js +135 -100
  22. package/dist/chat/ui/UnifiedDiff.js +22 -19
  23. package/dist/chat/ui/composer/ComposerControls.js +1 -1
  24. package/dist/chat/ui/composer/ComposerMenu.js +17 -11
  25. package/dist/chat/ui/composer/chips.d.ts +3 -0
  26. package/dist/chat/ui/composer/chips.js +14 -10
  27. package/dist/chat/ui/composer/use-chat-controls.js +70 -67
  28. package/dist/chat/ui/diff/EditorEditDiff.d.ts +3 -1
  29. package/dist/chat/ui/diff/EditorEditDiff.js +24 -18
  30. package/dist/chat/ui/diff/EditorPatchDiff.d.ts +3 -1
  31. package/dist/chat/ui/diff/EditorPatchDiff.js +4 -2
  32. package/dist/chat/ui/diff/diff-props.d.ts +2 -0
  33. package/dist/chat/ui/reference-icons.d.ts +3 -0
  34. package/dist/chat/ui/reference-icons.js +15 -2
  35. package/dist/chat/ui/rows/MessageRows.d.ts +6 -1
  36. package/dist/chat/ui/rows/MessageRows.js +166 -10
  37. package/dist/chat/ui/rows/RowContainer.js +21 -22
  38. package/dist/chat/ui/rows/Rows.js +37 -19
  39. package/dist/chat/ui/rows/WorkflowRow.d.ts +2 -1
  40. package/dist/chat/ui/rows/WorkflowRow.js +197 -191
  41. package/dist/chat/ui/rows/row-rhythm.d.ts +1 -0
  42. package/dist/chat/ui/rows/row-rhythm.js +12 -3
  43. package/dist/chat/workflow-list.d.ts +12 -0
  44. package/dist/chat/workflow-list.js +54 -0
  45. package/dist/host-hooks.d.ts +3 -0
  46. package/dist/host-hooks.js +8 -0
  47. package/dist/host.d.ts +11 -1
  48. package/dist/index.d.ts +1 -1
  49. package/dist/locales/en/agent-chat.d.ts +9 -0
  50. package/dist/locales/en/agent-chat.js +9 -0
  51. package/dist/locales/en/agent-providers.d.ts +5 -0
  52. package/dist/locales/en/agent-providers.js +8 -3
  53. package/dist/locales/nl/agent-chat.d.ts +9 -0
  54. package/dist/locales/nl/agent-chat.js +9 -0
  55. package/dist/locales/nl/agent-providers.d.ts +5 -0
  56. package/dist/locales/nl/agent-providers.js +8 -3
  57. package/dist/providers/AccountOrderList.d.ts +10 -0
  58. package/dist/providers/AccountOrderList.js +158 -0
  59. package/dist/providers/CliDetail.js +55 -61
  60. package/dist/providers/account-actions.d.ts +1 -0
  61. package/dist/providers/account-actions.js +39 -0
  62. package/dist/providers/index.d.ts +1 -1
  63. package/dist/providers/index.js +1 -1
  64. package/dist/usage/limit-groups.js +6 -1
  65. package/package.json +8 -8
  66. package/src/agents/accounts.ts +42 -6
  67. package/src/chat/account-choice.ts +31 -10
  68. package/src/chat/index.ts +1 -0
  69. package/src/chat/logic/scrubber.ts +5 -0
  70. package/src/chat/logic/timeline-copy.ts +2 -0
  71. package/src/chat/logic/timeline.ts +33 -2
  72. package/src/chat/preferences.ts +33 -8
  73. package/src/chat/ui/AccountPill.tsx +3 -3
  74. package/src/chat/ui/ChatActivity.tsx +52 -6
  75. package/src/chat/ui/Composer.tsx +19 -3
  76. package/src/chat/ui/LimitState.tsx +4 -2
  77. package/src/chat/ui/PromptEditor.tsx +3 -1
  78. package/src/chat/ui/ReferenceChip.tsx +15 -5
  79. package/src/chat/ui/UnifiedDiff.tsx +12 -1
  80. package/src/chat/ui/composer/ComposerControls.tsx +1 -1
  81. package/src/chat/ui/composer/ComposerMenu.tsx +4 -2
  82. package/src/chat/ui/composer/chips.ts +15 -9
  83. package/src/chat/ui/composer/use-chat-controls.ts +4 -1
  84. package/src/chat/ui/diff/EditorEditDiff.tsx +9 -4
  85. package/src/chat/ui/diff/EditorPatchDiff.tsx +5 -1
  86. package/src/chat/ui/diff/diff-props.ts +3 -0
  87. package/src/chat/ui/reference-icons.ts +13 -1
  88. package/src/chat/ui/rows/MessageRows.tsx +35 -0
  89. package/src/chat/ui/rows/RowContainer.tsx +2 -2
  90. package/src/chat/ui/rows/Rows.tsx +3 -0
  91. package/src/chat/ui/rows/WorkflowRow.tsx +9 -4
  92. package/src/chat/ui/rows/row-rhythm.ts +12 -3
  93. package/src/chat/workflow-list.ts +65 -0
  94. package/src/host-hooks.ts +13 -0
  95. package/src/host.ts +23 -1
  96. package/src/index.ts +1 -0
  97. package/src/locales/en/agent-chat.ts +9 -0
  98. package/src/locales/en/agent-providers.ts +8 -3
  99. package/src/locales/nl/agent-chat.ts +9 -0
  100. package/src/locales/nl/agent-providers.ts +8 -3
  101. package/src/providers/AccountOrderList.tsx +124 -0
  102. package/src/providers/CliDetail.tsx +33 -28
  103. package/src/providers/account-actions.ts +30 -0
  104. package/src/providers/index.ts +11 -1
  105. package/src/usage/limit-groups.ts +8 -1
@@ -2,6 +2,7 @@ import { useLayoutEffect, useRef, type SetStateAction } from 'react';
2
2
  import clsx from 'clsx';
3
3
  import { Surface } from '@adecore/ui';
4
4
  import type { ChatSkill } from '@adecore/agent-contracts';
5
+ import { useChatHost } from '../../host';
5
6
  import type { Referables } from '../chat-references';
6
7
  import { ComposerInput, type ComposerInputHandle } from './ComposerInput';
7
8
  import { chipDecorations } from './composer/chips';
@@ -47,6 +48,7 @@ export function PromptEditor({
47
48
  disabled = false,
48
49
  className
49
50
  }: PromptEditorProps) {
51
+ const host = useChatHost();
50
52
  const inputRef = useRef<ComposerInputHandle>(null);
51
53
  // A pick writes twice in one event (the text, then what it picked), and the second must build on the first.
52
54
  const latest = useRef(value);
@@ -77,7 +79,7 @@ export function PromptEditor({
77
79
  label
78
80
  });
79
81
 
80
- const extensions = chipDecorations({ mentions: value.mentions, skills: value.skills, references: menus.referenceChips });
82
+ const extensions = chipDecorations({ mentions: value.mentions, skills: value.skills, references: menus.referenceChips, referenceIcon: host.ReferenceIcon });
81
83
 
82
84
  const onKeyDown = (e: KeyboardEvent): boolean => {
83
85
  if (e.isComposing) {
@@ -3,8 +3,9 @@ import clsx from 'clsx';
3
3
  import { useTranslation } from 'react-i18next';
4
4
  import { CircleOff } from 'lucide-react';
5
5
  import { Icon } from '@adecore/ui';
6
+ import { useChatHost } from '../../host';
6
7
  import { REFERENCE_GONE_TONE, REFERENCE_TONE, TOKEN_ICON, TOKEN_IN_MESSAGE } from './chips';
7
- import { REFERENCE_ICONS } from './reference-icons';
8
+ import { referenceGlyph } from './reference-icons';
8
9
  import { ReferenceLookupContext } from './reference-lookup';
9
10
 
10
11
  interface TokenChipProps extends Omit<HTMLAttributes<HTMLSpanElement>, 'children'> {
@@ -51,15 +52,24 @@ export function TokenChip({ kind, value, sigil, icon, label, tone, onOpen, class
51
52
  );
52
53
  }
53
54
 
54
- /* A view, node or chat a message points at, under the name it has now; one that went says so. */
55
- export function ReferenceChip({ id }: { id: string }) {
55
+ /*
56
+ * A view, node or chat a message points at, under the name it has now. One that went says so, under
57
+ * `lastName` when the message knows what it was called.
58
+ */
59
+ export function ReferenceChip({ id, lastName }: { id: string; lastName?: string }) {
56
60
  const { t } = useTranslation('agent-chat');
57
61
  const { items, open } = useContext(ReferenceLookupContext);
62
+ const { ReferenceIcon } = useChatHost();
58
63
  const item = items.find((candidate) => candidate.id === id);
59
64
 
60
65
  if (item === undefined) {
61
66
  return (
62
- <TokenChip kind="gone" icon={<Icon icon={CircleOff} size={14} className={TOKEN_ICON} />} label={t('references.gone')} tone={REFERENCE_GONE_TONE} />
67
+ <TokenChip
68
+ kind="gone"
69
+ icon={<Icon icon={CircleOff} size={14} className={TOKEN_ICON} />}
70
+ label={lastName || t('references.gone')}
71
+ tone={REFERENCE_GONE_TONE}
72
+ />
63
73
  );
64
74
  }
65
75
 
@@ -68,7 +78,7 @@ export function ReferenceChip({ id }: { id: string }) {
68
78
  kind="reference"
69
79
  value={item.id}
70
80
  sigil="#"
71
- icon={<Icon icon={REFERENCE_ICONS[item.kind]} size={14} className={TOKEN_ICON} />}
81
+ icon={referenceGlyph(ReferenceIcon, { id: item.id, kind: item.kind, size: 14, className: TOKEN_ICON })}
72
82
  label={item.name || t('references.untitled')}
73
83
  tone={clsx(REFERENCE_TONE, open !== null && 'hover:bg-text/12')}
74
84
  onOpen={open === null ? undefined : () => open(item.id)}
@@ -15,7 +15,17 @@ const EditorPatchDiff = lazyNamed(() => import('./diff/EditorPatchDiff'), 'defau
15
15
  export default function UnifiedDiff(props: UnifiedDiffProps) {
16
16
  const host = useChatHost();
17
17
  const { t } = useTranslation('agent-chat');
18
- const { change, contents, allowEditor = true, ignoreWhitespace = false, overflow = 'wrap', diffStyle = 'unified', fill = false, maxHeight } = props;
18
+ const {
19
+ change,
20
+ contents,
21
+ allowEditor = true,
22
+ ignoreWhitespace = false,
23
+ overflow = 'wrap',
24
+ diffStyle = 'unified',
25
+ fill = false,
26
+ maxHeight,
27
+ onSource
28
+ } = props;
19
29
  const loadEngine = host.code.editor;
20
30
  const oldText = contents?.old ?? '';
21
31
  const newText = contents?.new ?? '';
@@ -64,6 +74,7 @@ export default function UnifiedDiff(props: UnifiedDiffProps) {
64
74
  layout={diffStyle}
65
75
  loadEngine={loadEngine!}
66
76
  fallback={unavailable}
77
+ onSource={onSource}
67
78
  />
68
79
  </LazyBoundary>
69
80
  </DiffFallbackBoundary>
@@ -120,7 +120,7 @@ export function ComposerControls({
120
120
  const scope = useChatScope();
121
121
  const Slot = useChatHost().ComposerSlot;
122
122
  const providers = useProviders((row) => row.providers);
123
- const accountChoice = useAccountChoice(info.provider, info.account);
123
+ const accountChoice = useAccountChoice(info.provider, info.account, chatId);
124
124
  const fileInputRef = useRef<HTMLInputElement>(null);
125
125
  const busy = info.activeTurnId !== null;
126
126
  const model = providers.find((entry) => entry.kind === info.provider)?.models.find((entry) => entry.slug === info.selection.model);
@@ -3,7 +3,8 @@ import { useTranslation } from 'react-i18next';
3
3
  import clsx from 'clsx';
4
4
  import { SquareSlash, Zap } from 'lucide-react';
5
5
  import { FileIcon, Icon, Menu, MiddleTruncate } from '@adecore/ui';
6
- import { REFERENCE_ICONS } from '../reference-icons';
6
+ import { useChatHost } from '../../../host';
7
+ import { referenceGlyph } from '../reference-icons';
7
8
  import type { ComposerMenus as Menus } from './use-composer-menus';
8
9
  import { optionIdOf } from './menu-aria';
9
10
 
@@ -108,6 +109,7 @@ function MentionMenu({ menus, query }: { menus: Menus; query: string }) {
108
109
  /* The views, nodes and chats a `#` offers, what stands on this canvas first, each with its kind or what tells it apart. */
109
110
  function ReferenceMenu({ menus }: { menus: Menus }) {
110
111
  const { t } = useTranslation('agent-chat');
112
+ const { ReferenceIcon } = useChatHost();
111
113
  const { listId, referenceMatches } = menus;
112
114
 
113
115
  const groups = (['canvas', 'views'] as const)
@@ -126,7 +128,7 @@ function ReferenceMenu({ menus }: { menus: Menus }) {
126
128
 
127
129
  return (
128
130
  <MenuOption key={item.id} menus={menus} index={index} className="items-center" onPick={() => menus.chooseReference(item)}>
129
- <Icon icon={REFERENCE_ICONS[item.kind]} size={14} className="shrink-0 text-text-faint" />
131
+ {referenceGlyph(ReferenceIcon, { id: item.id, kind: item.kind, size: 14, className: 'shrink-0 text-text-faint' })}
130
132
  <span className="truncate text-text">{item.name}</span>
131
133
  <span className="ml-auto shrink-0 truncate pl-2 text-text-faint">
132
134
  {item.detail ?? t(`composer.references.kinds.${item.kind}`)}
@@ -1,13 +1,13 @@
1
- import { createElement } from 'react';
1
+ import type { ComponentType } from 'react';
2
2
  import { createRoot, type Root } from 'react-dom/client';
3
3
  import { syntaxTree } from '@codemirror/language';
4
4
  import { Facet, StateField, type EditorState, type Extension, type Range } from '@codemirror/state';
5
5
  import { Decoration, EditorView, WidgetType, type DecorationSet } from '@codemirror/view';
6
- import { Icon } from '@adecore/ui';
6
+ import type { ReferenceIconProps } from '../../../host';
7
7
  import type { ReferableKind } from '../../chat-references';
8
8
  import { chipRanges, type ReferenceToken } from '../../mentions';
9
9
  import { CHIP_IN_EDITOR, MENTION_TONE, REFERENCE_TONE, SKILL_TONE, TOKEN_ICON_IN_EDITOR } from '../chips';
10
- import { REFERENCE_ICONS } from '../reference-icons';
10
+ import { referenceGlyph } from '../reference-icons';
11
11
  import { codeRanges } from './editor';
12
12
 
13
13
  export interface ChipChoices {
@@ -15,6 +15,8 @@ export interface ChipChoices {
15
15
  skills: string[];
16
16
  /* Null for a kind the host no longer names, which draws the chip without its mark. */
17
17
  references?: ReadonlyArray<ReferenceToken & { kind: ReferableKind | null }>;
18
+ /* The host's mark of a reference, which the editor draws outside the host's provider. */
19
+ referenceIcon?: ComponentType<ReferenceIconProps> | null;
18
20
  }
19
21
 
20
22
  const NO_CHOICES: ChipChoices = { mentions: [], skills: [] };
@@ -28,24 +30,28 @@ const referenceMark = Decoration.mark({ class: `${REFERENCE_TONE} ${CHIP_IN_EDIT
28
30
 
29
31
  const roots = new WeakMap<HTMLElement, Root>();
30
32
 
31
- /* The kind's mark in place of the `#`, the way a sent message draws it. */
33
+ /* The reference's mark in place of the `#`, the way a sent message draws it. */
32
34
  class ReferenceIcon extends WidgetType {
35
+ readonly id: string;
33
36
  readonly kind: ReferableKind;
37
+ readonly hostIcon: ComponentType<ReferenceIconProps> | null;
34
38
 
35
- constructor(kind: ReferableKind) {
39
+ constructor(id: string, kind: ReferableKind, hostIcon: ComponentType<ReferenceIconProps> | null) {
36
40
  super();
41
+ this.id = id;
37
42
  this.kind = kind;
43
+ this.hostIcon = hostIcon;
38
44
  }
39
45
 
40
46
  override eq(other: ReferenceIcon): boolean {
41
- return other.kind === this.kind;
47
+ return other.id === this.id && other.kind === this.kind && other.hostIcon === this.hostIcon;
42
48
  }
43
49
 
44
50
  toDOM(): HTMLElement {
45
51
  const holder = document.createElement('span');
46
52
  holder.className = TOKEN_ICON_IN_EDITOR;
47
53
  const root = createRoot(holder);
48
- root.render(createElement(Icon, { icon: REFERENCE_ICONS[this.kind], size: 12 }));
54
+ root.render(referenceGlyph(this.hostIcon, { id: this.id, kind: this.kind, size: 12 }));
49
55
  roots.set(holder, root);
50
56
 
51
57
  return holder;
@@ -60,7 +66,7 @@ class ReferenceIcon extends WidgetType {
60
66
  }
61
67
 
62
68
  function chipMarks(state: EditorState): DecorationSet {
63
- const { mentions, skills, references = [] } = state.facet(choices);
69
+ const { mentions, skills, references = [], referenceIcon = null } = state.facet(choices);
64
70
  const kinds = new Map(references.map((token) => [token.id, token.kind]));
65
71
  const marks: Range<Decoration>[] = [];
66
72
 
@@ -76,7 +82,7 @@ function chipMarks(state: EditorState): DecorationSet {
76
82
  const kind = kinds.get(range.value);
77
83
 
78
84
  if (kind !== undefined && kind !== null) {
79
- marks.push(Decoration.replace({ widget: new ReferenceIcon(kind) }).range(range.from, range.from + 1));
85
+ marks.push(Decoration.replace({ widget: new ReferenceIcon(range.value, kind, referenceIcon) }).range(range.from, range.from + 1));
80
86
  }
81
87
  }
82
88
 
@@ -2,6 +2,7 @@ import { useRef, useState } from 'react';
2
2
  import { useTranslation } from 'react-i18next';
3
3
  import type { AgentKind, ChatInfo, ModelSelection, RuntimeMode } from '@adecore/agent-contracts';
4
4
  import { useChatHost } from '../../../host';
5
+ import { useHostCanReorderAccounts } from '../../../host-hooks';
5
6
  import { useChatScope } from '../../../scope';
6
7
  import { errorCode } from '../../../transport';
7
8
  import { useChatActions } from '../../actions';
@@ -21,6 +22,7 @@ export function useChatControls({ chatId, info, notice: { setNotice, showError }
21
22
  const { t } = useTranslation('agent-chat');
22
23
  const host = useChatHost();
23
24
  const scope = useChatScope();
25
+ const ordered = useHostCanReorderAccounts(scope.id);
24
26
  const actions = useChatActions();
25
27
  const configuring = useRef(false);
26
28
  const [configurationPending, setConfigurationPending] = useState(false);
@@ -52,7 +54,8 @@ export function useChatControls({ chatId, info, notice: { setNotice, showError }
52
54
  rememberChatSelection(info.provider, patch.selection);
53
55
  }
54
56
 
55
- if (patch.account) {
57
+ // On a machine that keeps an order of its accounts an account picked here is this chat's alone; new chats start on its top one.
58
+ if (patch.account && !ordered) {
56
59
  rememberChatAccount(scope.id, info.provider, patch.account);
57
60
  }
58
61
  })
@@ -3,7 +3,7 @@ import { useEffect, useState, type ReactNode } from 'react';
3
3
  import { useTranslation } from 'react-i18next';
4
4
  import { getFiletypeFromFileName } from '@pierre/diffs';
5
5
  import type { EditorEngine } from '@adecore/editor';
6
- import { DiffView } from '@adecore/editor-react';
6
+ import { DiffView, type DiffSource } from '@adecore/editor-react';
7
7
  import { diffDocument, patchOf, type DiffDocument } from '@adecore/merge';
8
8
  import type { FileChange } from '../../logic/tools';
9
9
  import { useDiffSourceTokens } from '../use-diff-source-tokens';
@@ -24,7 +24,8 @@ function ReadyDiff({
24
24
  wrap,
25
25
  fill,
26
26
  layout,
27
- maxHeight
27
+ maxHeight,
28
+ onSource
28
29
  }: {
29
30
  document: DiffDocument;
30
31
  path: string;
@@ -33,6 +34,7 @@ function ReadyDiff({
33
34
  fill: boolean;
34
35
  layout: 'unified' | 'split';
35
36
  maxHeight: number;
37
+ onSource?(source: DiffSource): void | (() => void);
36
38
  }) {
37
39
  useReviewSettled();
38
40
  const { t } = useTranslation('agent-chat');
@@ -54,6 +56,7 @@ function ReadyDiff({
54
56
  wrap={wrap}
55
57
  fill={fill}
56
58
  className="chat-diff select-text"
59
+ onSource={onSource}
57
60
  />
58
61
  );
59
62
  }
@@ -66,7 +69,8 @@ export function EditorDocumentDiff({
66
69
  wrap = true,
67
70
  fill = false,
68
71
  layout = 'unified',
69
- maxHeight = 480
72
+ maxHeight = 480,
73
+ onSource
70
74
  }: {
71
75
  document: DiffDocument;
72
76
  path: string;
@@ -76,6 +80,7 @@ export function EditorDocumentDiff({
76
80
  fill?: boolean;
77
81
  layout?: 'unified' | 'split';
78
82
  maxHeight?: number;
83
+ onSource?(source: DiffSource): void | (() => void);
79
84
  }) {
80
85
  const { t } = useTranslation('agent-chat');
81
86
  const withinLimits = canRenderEditorDiff(document);
@@ -125,7 +130,7 @@ export function EditorDocumentDiff({
125
130
  return engine === null ? (
126
131
  fallback
127
132
  ) : (
128
- <ReadyDiff document={document} path={path} engine={engine} wrap={wrap} fill={fill} layout={layout} maxHeight={maxHeight} />
133
+ <ReadyDiff document={document} path={path} engine={engine} wrap={wrap} fill={fill} layout={layout} maxHeight={maxHeight} onSource={onSource} />
129
134
  );
130
135
  }
131
136
 
@@ -1,6 +1,7 @@
1
1
  import { useMemo, type ReactNode } from 'react';
2
2
  import type { ChatFileChange } from '@adecore/agent-contracts';
3
3
  import type { EditorEngine } from '@adecore/editor';
4
+ import type { DiffSource } from '@adecore/editor-react';
4
5
  import { diffDocument, parsePatch } from '@adecore/merge';
5
6
  import type { DiffContents } from '../full-diff';
6
7
  import { diffSourceBudget, patchSourceBudget } from './diff-source-budget';
@@ -17,7 +18,8 @@ export default function EditorPatchDiff({
17
18
  maxHeight,
18
19
  layout = 'unified',
19
20
  loadEngine,
20
- fallback
21
+ fallback,
22
+ onSource
21
23
  }: {
22
24
  change: ChatFileChange;
23
25
  sourceChecked?: boolean;
@@ -29,6 +31,7 @@ export default function EditorPatchDiff({
29
31
  maxHeight?: number;
30
32
  loadEngine: () => Promise<EditorEngine>;
31
33
  fallback: ReactNode;
34
+ onSource?(source: DiffSource): void | (() => void);
32
35
  }) {
33
36
  const oldText = contents?.old;
34
37
  const newText = contents?.new;
@@ -59,6 +62,7 @@ export default function EditorPatchDiff({
59
62
  fill={fill}
60
63
  layout={layout}
61
64
  maxHeight={maxHeight}
65
+ onSource={onSource}
62
66
  />
63
67
  );
64
68
  }
@@ -1,4 +1,5 @@
1
1
  import type { ChatFileChange } from '@adecore/agent-contracts';
2
+ import type { DiffSource } from '@adecore/editor-react';
2
3
  import type { DiffContents } from '../full-diff';
3
4
 
4
5
  export interface UnifiedDiffProps {
@@ -13,4 +14,6 @@ export interface UnifiedDiffProps {
13
14
  fill?: boolean;
14
15
  /* Both whole texts the patch was made between, with which a person can unfold the lines between hunks. */
15
16
  contents?: DiffContents;
17
+ /* Runs per editor of the diff with a way to ask where its caret stands in the new file. Only the editor diff calls it; the plain fallbacks have no caret. */
18
+ onSource?(source: DiffSource): void | (() => void);
16
19
  }
@@ -1,7 +1,10 @@
1
+ import { createElement, type ComponentType, type ReactNode } from 'react';
1
2
  import { Database, FileText, Frame, Globe, MessageSquare, PenTool, Smartphone, StickyNote, Terminal, Type, Workflow, type LucideIcon } from 'lucide-react';
3
+ import { Icon } from '@adecore/ui';
4
+ import type { ReferenceIconProps } from '../../host';
2
5
  import type { ReferableKind } from '../chat-references';
3
6
 
4
- /* The mark of what a `#` points at, in the picker and on its chip. */
7
+ /* The mark of what a `#` points at, in the picker and on its chip, when the host draws none of its own. */
5
8
  export const REFERENCE_ICONS: Record<ReferableKind, LucideIcon> = {
6
9
  canvas: Frame,
7
10
  chat: MessageSquare,
@@ -15,3 +18,12 @@ export const REFERENCE_ICONS: Record<ReferableKind, LucideIcon> = {
15
18
  file: FileText,
16
19
  database: Database
17
20
  };
21
+
22
+ /* The host's mark of a reference, or the mark of its kind. */
23
+ export function referenceGlyph(HostIcon: ComponentType<ReferenceIconProps> | null | undefined, props: ReferenceIconProps): ReactNode {
24
+ if (HostIcon) {
25
+ return createElement(HostIcon, props);
26
+ }
27
+
28
+ return createElement(Icon, { icon: REFERENCE_ICONS[props.kind], size: props.size, className: props.className });
29
+ }
@@ -6,6 +6,7 @@ import type {
6
6
  ChatApprovalItem,
7
7
  ChatAttachment,
8
8
  ChatAssistantItem,
9
+ ChatNoteMessage,
9
10
  ChatQuestionItem,
10
11
  ChatThinkingItem,
11
12
  ChatUiChoiceOrigin,
@@ -186,6 +187,40 @@ export function UserRow({ chatId, item }: { chatId: string; item: ChatUserItem }
186
187
  );
187
188
  }
188
189
 
190
+ /*
191
+ * A message another node sent the chat: a bubble like a person's, under a chip that names and opens the sender,
192
+ * but on the left, since the person did not write it.
193
+ */
194
+ export function SentMessageRow({ chatId, id, message }: { chatId: string; id: string; message: ChatNoteMessage }) {
195
+ const { t } = useTranslation('agent-chat');
196
+ const [open, setOpen] = useState(false);
197
+ const long = message.text.split('\n').length > USER_FOLD_LINES || message.text.length > USER_FOLD_CHARS;
198
+ const lookup = useReferenceLookup(chatId);
199
+ useOpenForFind(id, 'text', setOpen);
200
+
201
+ return (
202
+ <ReferenceLookupContext value={lookup}>
203
+ <div data-find-item={id} className="flex flex-col items-start">
204
+ <MessageHeading>{t('rows.message.heading', { name: message.title || t('rows.message.unnamed') })}</MessageHeading>
205
+ <div className="mb-1.5 flex max-w-[80%]">
206
+ <ReferenceChip id={message.from} lastName={message.title} />
207
+ </div>
208
+ <div className="relative max-w-[80%] rounded-2xl bg-surface-hover px-3.5 py-2.5 text-sm wrap-anywhere text-text select-text">
209
+ <div data-find-field="text" className={clsx(long && !open && FOLD)}>
210
+ <MessageMarkdown text={message.text} />
211
+ </div>
212
+ {long && (
213
+ <button className="mt-1 flex items-center gap-1 text-xs text-text-muted hover:text-text" onClick={() => setOpen((o) => !o)}>
214
+ <Icon icon={ChevronDown} size={12} className={clsx('transition-transform', open && 'rotate-180')} />{' '}
215
+ {open ? t('rows.user.showLess') : t('rows.user.showAll')}
216
+ </button>
217
+ )}
218
+ </div>
219
+ </div>
220
+ </ReferenceLookupContext>
221
+ );
222
+ }
223
+
189
224
  /*
190
225
  * The choice a message answers. The label stays out of the message, which holds exactly what the agent
191
226
  * read, and out of a copied selection; a screen reader hears it between the heading and the message.
@@ -1,7 +1,7 @@
1
1
  import type { ReactNode, Ref } from 'react';
2
2
  import clsx from 'clsx';
3
3
  import type { TimelineRow } from '../../logic/timeline';
4
- import { rowPosition, rowRhythm } from './row-rhythm';
4
+ import { rowPosition, rowRhythm, saidToChat } from './row-rhythm';
5
5
 
6
6
  export interface RowContainerProps {
7
7
  row: TimelineRow;
@@ -25,7 +25,7 @@ export function RowContainer({ row, previous, index, top, ref, children }: RowCo
25
25
  wide ? 'chat-wide-content' : 'chat-column-content',
26
26
  rowRhythm(row, previous),
27
27
  // Turn gaps belong inside the measurement used by the virtualizer.
28
- row.kind === 'user' && index > 0 && 'pt-(--chat-turn-gap)'
28
+ saidToChat(row) && index > 0 && 'pt-(--chat-turn-gap)'
29
29
  )}
30
30
  style={rowPosition(row.kind, top)}
31
31
  >
@@ -12,6 +12,7 @@ import {
12
12
  NoteRow,
13
13
  QuestionHistoryRow,
14
14
  ReportRow,
15
+ SentMessageRow,
15
16
  ThinkingRow,
16
17
  UserRow
17
18
  } from './MessageRows';
@@ -108,6 +109,8 @@ export function Row({ row, chatId, toggleGroup, toggleTurn, toggleSubagent, open
108
109
  return <QuestionHistoryRow item={row.item} />;
109
110
  case 'note':
110
111
  return <NoteRow id={row.id} level={row.level} text={row.text} from={row.from} />;
112
+ case 'message':
113
+ return <SentMessageRow chatId={chatId} id={row.id} message={row.message} />;
111
114
  case 'compaction':
112
115
  return <CompactionRow preTokens={row.preTokens} />;
113
116
  case 'working':
@@ -59,17 +59,22 @@ function Counts({ counts }: { counts: WorkflowCounts }) {
59
59
  );
60
60
  }
61
61
 
62
- // Keep background progress visible after the launcher turn ends.
62
+ /*
63
+ * Keep background progress visible after the launcher turn ends. In the flyout over the composer it
64
+ * has no call to open and is no place in the thread a search jumps to.
65
+ */
63
66
  export function WorkflowRow({
64
67
  tool,
65
68
  workflow,
66
69
  chatId,
67
- onOpenAgent
70
+ onOpenAgent,
71
+ place = 'thread'
68
72
  }: {
69
73
  tool: ChatToolItem;
70
74
  workflow: ChatWorkflow;
71
75
  chatId?: string;
72
76
  onOpenAgent?(step: SubagentStep): void;
77
+ place?: 'thread' | 'flyout';
73
78
  }) {
74
79
  const host = useChatHost();
75
80
  const { t } = useTranslation('agent-chat');
@@ -82,7 +87,7 @@ export function WorkflowRow({
82
87
  const phases = workflowPhases(workflow, running);
83
88
  const counts = workflowCounts(phases);
84
89
  const description = workflowDescription(tool.input);
85
- const opens = hasToolBody(tool);
90
+ const opens = place === 'thread' && hasToolBody(tool);
86
91
  const onOpen = refused ? undefined : onOpenAgent;
87
92
  const actions = useChatActions();
88
93
 
@@ -119,7 +124,7 @@ export function WorkflowRow({
119
124
  );
120
125
 
121
126
  return (
122
- <div data-find-item={tool.id} className="mb-1">
127
+ <div data-find-item={place === 'thread' ? tool.id : undefined} className="mb-1">
123
128
  <div className="flex items-center gap-1">
124
129
  <div className="min-w-0 grow">
125
130
  {opens ? (
@@ -9,10 +9,15 @@ export const FOLLOW_THRESHOLD_PX = 40;
9
9
  * A seam where tool lines meet prose gets the block gap, and so does the row under a visual or an app's
10
10
  * card, which have no margin of their own. A question and the answer after it never take a seam.
11
11
  */
12
+ /* A person's message, or one another node sent: both are said to the chat and drawn the same way. */
13
+ export function saidToChat(row: TimelineRow): boolean {
14
+ return row.kind === 'user' || row.kind === 'message';
15
+ }
16
+
12
17
  export function rowRhythm(row: TimelineRow, previous: TimelineRow | null): string {
13
- const question = row.kind === 'user';
18
+ const question = saidToChat(row);
14
19
  const bare = previous?.kind === 'visual' || previous?.kind === 'app-card';
15
- const seam = !question && previous !== null && previous.kind !== 'user' && (isBlock(row) !== isBlock(previous) || bare);
20
+ const seam = !question && previous !== null && !saidToChat(previous) && (isBlock(row) !== isBlock(previous) || bare);
16
21
 
17
22
  return clsx(question && 'pb-(--chat-answer-gap)', seam && 'pt-(--chat-block-gap)');
18
23
  }
@@ -23,7 +28,7 @@ export function rowRhythm(row: TimelineRow, previous: TimelineRow | null): strin
23
28
  * starts halfway through a reply has no time to show.
24
29
  */
25
30
  export function replyHeader(row: TimelineRow, previous: TimelineRow | null): { at: number | null } | null {
26
- if (row.kind === 'user' || row.kind === 'turn-start') {
31
+ if (saidToChat(row) || row.kind === 'turn-start') {
27
32
  return null;
28
33
  }
29
34
 
@@ -35,6 +40,10 @@ export function replyHeader(row: TimelineRow, previous: TimelineRow | null): { a
35
40
  return { at: previous.item.createdAt };
36
41
  }
37
42
 
43
+ if (previous.kind === 'message') {
44
+ return { at: previous.createdAt };
45
+ }
46
+
38
47
  if (previous.kind === 'turn-start') {
39
48
  return { at: previous.turn.createdAt };
40
49
  }
@@ -0,0 +1,65 @@
1
+ import i18next from 'i18next';
2
+ import { activeWorkflows, type ChatItem, type ChatToolItem, type ChatWorkflow } from '@adecore/agent-contracts';
3
+ import { workflowCounts, workflowPhases } from './logic/workflow';
4
+
5
+ /* A Workflow call that reported what it runs, which is every one `activeWorkflows` keeps. */
6
+ export type WorkflowCall = ChatToolItem & { workflow: ChatWorkflow };
7
+
8
+ /* `stalled` still runs, but reported nothing for a while. */
9
+ export type WorkflowWord = 'running' | 'stalled' | 'done' | 'failed';
10
+
11
+ export interface WorkflowPill {
12
+ word: WorkflowWord;
13
+ label: string;
14
+ }
15
+
16
+ /* What the workflow pill over the composer lists (`activeWorkflows`); `order` puts the calls from before the page first. */
17
+ export function flyoutWorkflows(order: readonly string[], structure: Readonly<Record<string, ChatItem>>): WorkflowCall[] {
18
+ return activeWorkflows(
19
+ order.flatMap((id) => {
20
+ const item = structure[id];
21
+
22
+ return item === undefined ? [] : [item];
23
+ })
24
+ ).filter((tool): tool is WorkflowCall => tool.workflow !== undefined);
25
+ }
26
+
27
+ export function workflowWordOf(tool: WorkflowCall): WorkflowWord {
28
+ if (tool.state === 'running') {
29
+ return tool.workflow.stalledAt === undefined ? 'running' : 'stalled';
30
+ }
31
+
32
+ return tool.state === 'error' ? 'failed' : 'done';
33
+ }
34
+
35
+ /* What asks for a look first: one that stalled, then one at work, then one that failed. */
36
+ const PRESSING: readonly WorkflowWord[] = ['stalled', 'running', 'failed', 'done'];
37
+
38
+ /*
39
+ * One workflow names itself with how many of its agents are done, or that it stalled. Several are
40
+ * counted like the sub-agents badge: the ones still at work, and all of them once none is.
41
+ */
42
+ export function workflowPillOf(calls: readonly WorkflowCall[]): WorkflowPill {
43
+ const words = calls.map(workflowWordOf);
44
+ const word = PRESSING.find((candidate) => words.includes(candidate)) ?? 'done';
45
+
46
+ if (calls.length !== 1) {
47
+ const active = words.filter((candidate) => candidate === 'running' || candidate === 'stalled').length;
48
+
49
+ return { word, label: i18next.t('agent-chat:activity.workflows', { count: active > 0 ? active : calls.length }) };
50
+ }
51
+
52
+ const call = calls[0]!;
53
+ const name = call.workflow.name ?? i18next.t('agent-chat:activity.workflow');
54
+
55
+ if (word === 'stalled') {
56
+ return { word, label: i18next.t('agent-chat:activity.workflowStalled', { name }) };
57
+ }
58
+
59
+ const counts = workflowCounts(workflowPhases(call.workflow, word === 'running'));
60
+
61
+ return {
62
+ word,
63
+ label: counts.total === 0 ? name : i18next.t('agent-chat:activity.workflowProgress', { name, done: counts.done, total: counts.total })
64
+ };
65
+ }
package/src/host-hooks.ts CHANGED
@@ -4,6 +4,7 @@
4
4
  * hooks are called through these wrappers only. `ChatHostProvider` pins its host, so they never change.
5
5
  */
6
6
  import type { ProviderPlatform } from '@adecore/agent-contracts';
7
+ import type { AccountRule } from './agents/accounts';
7
8
  import { referablesOfChats, type Referables } from './chat/chat-references';
8
9
  import { useChatHost, type ChatHost, type CommandLook, type ComposerSendAction } from './host';
9
10
 
@@ -134,3 +135,15 @@ export function useCommandNames(
134
135
  ): ReturnType<NonNullable<CommandLook['useNames']>> {
135
136
  return look.useNames(scopeId, chatId);
136
137
  }
138
+
139
+ export function useHostCanReorderAccounts(scopeId: string): boolean {
140
+ const useCanReorder = useChatHost().useCanReorderAccounts ?? (() => true);
141
+
142
+ return useCanReorder(scopeId);
143
+ }
144
+
145
+ export function useHostAccountRule(scopeId: string, chatId: string): AccountRule | null {
146
+ const useRule = useChatHost().useAccountRule ?? (() => null);
147
+
148
+ return useRule(scopeId, chatId);
149
+ }