@adecore/agents-react 0.46.3 → 0.47.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 (56) hide show
  1. package/dist/chat/index.d.ts +1 -0
  2. package/dist/chat/index.js +1 -0
  3. package/dist/chat/logic/scrubber.js +12 -0
  4. package/dist/chat/logic/timeline-copy.js +2 -0
  5. package/dist/chat/logic/timeline.d.ts +6 -1
  6. package/dist/chat/logic/timeline.js +36 -10
  7. package/dist/chat/ui/ChatActivity.d.ts +2 -1
  8. package/dist/chat/ui/ChatActivity.js +295 -61
  9. package/dist/chat/ui/Composer.d.ts +2 -1
  10. package/dist/chat/ui/Composer.js +492 -486
  11. package/dist/chat/ui/PromptEditor.js +4 -1
  12. package/dist/chat/ui/ReferenceChip.d.ts +2 -1
  13. package/dist/chat/ui/ReferenceChip.js +135 -100
  14. package/dist/chat/ui/composer/ComposerMenu.js +17 -11
  15. package/dist/chat/ui/composer/chips.d.ts +3 -0
  16. package/dist/chat/ui/composer/chips.js +14 -10
  17. package/dist/chat/ui/reference-icons.d.ts +3 -0
  18. package/dist/chat/ui/reference-icons.js +15 -2
  19. package/dist/chat/ui/rows/MessageRows.d.ts +6 -1
  20. package/dist/chat/ui/rows/MessageRows.js +166 -10
  21. package/dist/chat/ui/rows/RowContainer.js +21 -22
  22. package/dist/chat/ui/rows/Rows.js +37 -19
  23. package/dist/chat/ui/rows/WorkflowRow.d.ts +2 -1
  24. package/dist/chat/ui/rows/WorkflowRow.js +197 -191
  25. package/dist/chat/ui/rows/row-rhythm.d.ts +1 -0
  26. package/dist/chat/ui/rows/row-rhythm.js +12 -3
  27. package/dist/chat/workflow-list.d.ts +12 -0
  28. package/dist/chat/workflow-list.js +54 -0
  29. package/dist/host.d.ts +8 -1
  30. package/dist/index.d.ts +1 -1
  31. package/dist/locales/en/agent-chat.d.ts +9 -0
  32. package/dist/locales/en/agent-chat.js +9 -0
  33. package/dist/locales/nl/agent-chat.d.ts +9 -0
  34. package/dist/locales/nl/agent-chat.js +9 -0
  35. package/package.json +8 -8
  36. package/src/chat/index.ts +1 -0
  37. package/src/chat/logic/scrubber.ts +5 -0
  38. package/src/chat/logic/timeline-copy.ts +2 -0
  39. package/src/chat/logic/timeline.ts +33 -2
  40. package/src/chat/ui/ChatActivity.tsx +52 -6
  41. package/src/chat/ui/Composer.tsx +19 -3
  42. package/src/chat/ui/PromptEditor.tsx +3 -1
  43. package/src/chat/ui/ReferenceChip.tsx +15 -5
  44. package/src/chat/ui/composer/ComposerMenu.tsx +4 -2
  45. package/src/chat/ui/composer/chips.ts +15 -9
  46. package/src/chat/ui/reference-icons.ts +13 -1
  47. package/src/chat/ui/rows/MessageRows.tsx +35 -0
  48. package/src/chat/ui/rows/RowContainer.tsx +2 -2
  49. package/src/chat/ui/rows/Rows.tsx +3 -0
  50. package/src/chat/ui/rows/WorkflowRow.tsx +9 -4
  51. package/src/chat/ui/rows/row-rhythm.ts +12 -3
  52. package/src/chat/workflow-list.ts +65 -0
  53. package/src/host.ts +15 -1
  54. package/src/index.ts +1 -0
  55. package/src/locales/en/agent-chat.ts +9 -0
  56. package/src/locales/nl/agent-chat.ts +9 -0
@@ -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.ts CHANGED
@@ -23,7 +23,7 @@ import type {
23
23
  RuntimeMode
24
24
  } from '@adecore/agent-contracts';
25
25
  import { isApplePlatform } from '@adecore/ui';
26
- import type { Referables } from './chat/chat-references';
26
+ import type { ReferableKind, Referables } from './chat/chat-references';
27
27
  import type { TimelineRow } from './chat/logic/timeline';
28
28
  import type { FindReveal } from './chat/ui/find-reveal';
29
29
  import type { PromptAction } from './prompts/logic/prompts';
@@ -172,6 +172,14 @@ export interface ComposerSlotProps {
172
172
  insert(text: string): void;
173
173
  }
174
174
 
175
+ /* What an app's own mark of a `#` reference gets: what it points at, and the size and class of the mark it stands in for. */
176
+ export interface ReferenceIconProps {
177
+ id: string;
178
+ kind: ReferableKind;
179
+ size: number;
180
+ className?: string;
181
+ }
182
+
175
183
  /* What an app's own bar over the composer gets: the chat it stands on, which may be one the bar has nothing for. */
176
184
  export interface ComposerHeaderSlotProps {
177
185
  scopeId: string;
@@ -439,6 +447,12 @@ export interface ChatHost {
439
447
  useReferableChats(): ReadonlyArray<{ id: string; title: string }>;
440
448
  /* The views and nodes a message of this chat may point at with `#`, under the names they have right now. */
441
449
  useReferables?(scopeId: string, chatId: string): Referables;
450
+ /*
451
+ * The mark of a view or node a `#` points at, in the picker, the composer and a sent message, such as the icon
452
+ * a person chose for it. Drawn in the composer's editor outside this provider, so it reads no context of its
453
+ * own; left out, every reference wears the mark of its kind.
454
+ */
455
+ ReferenceIcon?: ComponentType<ReferenceIconProps> | null;
442
456
  /* Opens a view or zooms to a node a message points at; left out, a chip opens nothing. */
443
457
  openReference?(scopeId: string, id: string): void;
444
458
  /* Opens the CLI's own login for an account, somewhere the app can run a command; null offers none. */
package/src/index.ts CHANGED
@@ -10,6 +10,7 @@ export {
10
10
  type ComposerDictationProps,
11
11
  type ComposerHeaderSlotProps,
12
12
  type ComposerSlotProps,
13
+ type ReferenceIconProps,
13
14
  type ComposerSendAction,
14
15
  type ComposerSendDraft,
15
16
  type SubagentSlotProps,
@@ -120,6 +120,10 @@ export default {
120
120
  showLess: 'Show less',
121
121
  quoteGone: 'Quoted reply no longer in this chat.'
122
122
  },
123
+ message: {
124
+ heading: 'Message from {{name}}',
125
+ unnamed: 'another node'
126
+ },
123
127
  report: {
124
128
  heading: 'Report'
125
129
  },
@@ -416,6 +420,11 @@ export default {
416
420
  monitors_other: '{{count}} monitors',
417
421
  pausedUntil: 'paused until {{time}}',
418
422
  progress: '{{done}} of {{total}} sub-agents done',
423
+ workflow: 'Workflow',
424
+ workflows_one: '{{count}} workflow',
425
+ workflows_other: '{{count}} workflows',
426
+ workflowProgress: '{{name}} · {{done}}/{{total}}',
427
+ workflowStalled: '{{name}} · no progress',
419
428
  needsYou_one: '{{count}} needs you',
420
429
  needsYou_other: '{{count}} need you',
421
430
  took: {
@@ -120,6 +120,10 @@ export default {
120
120
  showLess: 'Minder tonen',
121
121
  quoteGone: 'Geciteerd antwoord staat niet meer in deze chat.'
122
122
  },
123
+ message: {
124
+ heading: 'Bericht van {{name}}',
125
+ unnamed: 'een andere node'
126
+ },
123
127
  report: {
124
128
  heading: 'Rapport'
125
129
  },
@@ -416,6 +420,11 @@ export default {
416
420
  monitors_other: '{{count}} monitors',
417
421
  pausedUntil: 'gepauzeerd tot {{time}}',
418
422
  progress: '{{done}} van {{total}} sub-agents klaar',
423
+ workflow: 'Workflow',
424
+ workflows_one: '{{count}} workflow',
425
+ workflows_other: '{{count}} workflows',
426
+ workflowProgress: '{{name}} · {{done}}/{{total}}',
427
+ workflowStalled: '{{name}} · geen voortgang',
419
428
  needsYou_one: '{{count}} vraagt aandacht',
420
429
  needsYou_other: '{{count}} vragen aandacht',
421
430
  took: {