@adecore/agents-react 0.51.0 → 0.53.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 (59) hide show
  1. package/dist/agents/AgentIcon.js +25 -17
  2. package/dist/agents/ProviderLogo.js +26 -16
  3. package/dist/agents/agent-marks.d.ts +1 -0
  4. package/dist/agents/provider-paths.d.ts +2 -1
  5. package/dist/agents/provider-paths.js +11 -2
  6. package/dist/chat/index.d.ts +2 -1
  7. package/dist/chat/index.js +2 -1
  8. package/dist/chat/logic/command-looks.d.ts +17 -5
  9. package/dist/chat/logic/command-looks.js +35 -7
  10. package/dist/chat/logic/timeline.d.ts +6 -4
  11. package/dist/chat/logic/timeline.js +32 -25
  12. package/dist/chat/logic/tool-looks.d.ts +16 -0
  13. package/dist/chat/logic/tool-looks.js +188 -0
  14. package/dist/chat/logic/tools.d.ts +5 -0
  15. package/dist/chat/logic/tools.js +17 -2
  16. package/dist/chat/ui/ShellCommand.d.ts +2 -1
  17. package/dist/chat/ui/ShellCommand.js +73 -22
  18. package/dist/chat/ui/SubagentTimeline.js +5 -2
  19. package/dist/chat/ui/Timeline.js +2 -1
  20. package/dist/chat/ui/diff/EditorEditDiff.d.ts +3 -2
  21. package/dist/chat/ui/diff/EditorEditDiff.js +93 -79
  22. package/dist/chat/ui/diff/LegacyEditDiff.d.ts +1 -1
  23. package/dist/chat/ui/diff/LegacyEditDiff.js +64 -48
  24. package/dist/chat/ui/rows/RowContainer.js +26 -23
  25. package/dist/chat/ui/rows/WorkRows.d.ts +3 -4
  26. package/dist/chat/ui/rows/WorkRows.js +592 -519
  27. package/dist/chat/ui/rows/row-rhythm.d.ts +2 -2
  28. package/dist/chat/ui/rows/row-rhythm.js +9 -6
  29. package/dist/chat/ui/thread-references.d.ts +1 -0
  30. package/dist/chat/ui/thread-references.js +4 -3
  31. package/dist/host.d.ts +28 -0
  32. package/dist/index.d.ts +1 -1
  33. package/dist/locales/en/agent-chat.d.ts +4 -0
  34. package/dist/locales/en/agent-chat.js +4 -0
  35. package/dist/locales/nl/agent-chat.d.ts +4 -0
  36. package/dist/locales/nl/agent-chat.js +4 -0
  37. package/package.json +8 -8
  38. package/src/agents/AgentIcon.tsx +2 -1
  39. package/src/agents/ProviderLogo.tsx +2 -2
  40. package/src/agents/agent-marks.ts +2 -0
  41. package/src/agents/provider-paths.ts +15 -3
  42. package/src/chat/index.ts +2 -1
  43. package/src/chat/logic/command-looks.ts +51 -10
  44. package/src/chat/logic/timeline.ts +46 -27
  45. package/src/chat/logic/tool-looks.ts +228 -0
  46. package/src/chat/logic/tools.ts +13 -2
  47. package/src/chat/ui/ShellCommand.tsx +33 -6
  48. package/src/chat/ui/SubagentTimeline.tsx +3 -2
  49. package/src/chat/ui/Timeline.tsx +2 -1
  50. package/src/chat/ui/diff/EditorEditDiff.tsx +31 -5
  51. package/src/chat/ui/diff/LegacyEditDiff.tsx +5 -3
  52. package/src/chat/ui/rows/RowContainer.tsx +4 -2
  53. package/src/chat/ui/rows/WorkRows.tsx +46 -33
  54. package/src/chat/ui/rows/row-rhythm.ts +9 -6
  55. package/src/chat/ui/thread-references.ts +5 -1
  56. package/src/host.ts +51 -0
  57. package/src/index.ts +3 -0
  58. package/src/locales/en/agent-chat.ts +4 -0
  59. package/src/locales/nl/agent-chat.ts +4 -0
@@ -0,0 +1,188 @@
1
+ import { isRecord } from './json.js';
2
+ // A value keeps this many characters of what it says.
3
+ const FOLD_LENGTH = 40;
4
+ // An ACP agent titles a call of an MCP tool with the server and the tool, each agent with a separator of its own.
5
+ const TITLE_SEPARATORS = ['__', '_', '-'];
6
+ const TOOL_NAME = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
7
+ // The name an ACP call of kind `other` gets, which is all a call of an MCP tool is where its agent marks none.
8
+ const ACP_TOOL_ROW = 'Tool';
9
+ const caches = new WeakMap();
10
+ /* The server and the tool `text` names as `<server><separator><tool>`, on the first of `servers` it starts with. */
11
+ function toolOn(text, servers, separators) {
12
+ for (const server of servers) {
13
+ for (const separator of separators) {
14
+ const prefix = `${server}${separator}`;
15
+ const tool = text.slice(prefix.length);
16
+ if (text.startsWith(prefix) && TOOL_NAME.test(tool)) {
17
+ return {
18
+ server,
19
+ tool
20
+ };
21
+ }
22
+ }
23
+ }
24
+ return null;
25
+ }
26
+ /*
27
+ * The call as its name says it, whatever its input holds: `mcp__<server>__<tool>`, `<server>/<tool>`, or the tool
28
+ * Grok's `use_tool` names in its input. Undefined where the name says nothing of a server, and null where it names
29
+ * one that is not in `servers`, which no title overrules.
30
+ */
31
+ function namedCall(name, input, servers) {
32
+ if (name.startsWith('mcp__')) {
33
+ const named = toolOn(name.slice(5), servers, ['__']);
34
+ return named === null ? null : {
35
+ ...named,
36
+ input
37
+ };
38
+ }
39
+ if (name.includes('/')) {
40
+ const named = toolOn(name, servers, ['/']);
41
+ return named === null ? null : {
42
+ ...named,
43
+ input
44
+ };
45
+ }
46
+ if (name !== ACP_TOOL_ROW || typeof input.tool_name !== 'string') {
47
+ return undefined;
48
+ }
49
+ const used = toolOn(input.tool_name, servers, ['__']);
50
+ return used === null ? null : {
51
+ ...used,
52
+ input: isRecord(input.tool_input) ? input.tool_input : {}
53
+ };
54
+ }
55
+ /*
56
+ * The call as an ACP agent that marks no server titles it, in the rows `toolRow` of `@adecore/agents` draws: a call
57
+ * of kind `other`, or a `Read` Copilot makes of a tool that only reads. A `Read` of a file is no MCP call.
58
+ */
59
+ function titledCall(name, input, servers) {
60
+ const titledRow = name === ACP_TOOL_ROW || name === 'Read' && input.file_path === undefined;
61
+ const title = typeof input.description === 'string' ? input.description : null;
62
+ const titled = !titledRow || title === null ? null : toolOn(title, servers, TITLE_SEPARATORS);
63
+ if (titled === null) {
64
+ return null;
65
+ }
66
+ // Antigravity hands the arguments over as `arguments`, Copilot beside the title.
67
+ return {
68
+ ...titled,
69
+ input: isRecord(input.arguments) ? input.arguments : Object.fromEntries(Object.entries(input).filter(([key]) => key !== 'description'))
70
+ };
71
+ }
72
+ /* A tool's answer out of the envelope Grok puts around an MCP answer, `{"type":"MCP",...,"output":{"OkayOutput":"..."}}`. */
73
+ function unwrapped(output) {
74
+ if (output === null || !output.trimStart().startsWith('{')) {
75
+ return output;
76
+ }
77
+ try {
78
+ const parsed = JSON.parse(output);
79
+ if (!isRecord(parsed) || parsed.type !== 'MCP' || !isRecord(parsed.output)) {
80
+ return output;
81
+ }
82
+ const inner = Object.values(parsed.output);
83
+ return inner.length === 1 && typeof inner[0] === 'string' ? inner[0] : output;
84
+ } catch {
85
+ return output;
86
+ }
87
+ }
88
+ /*
89
+ * The call of an MCP tool on one of `servers` that `item` is: `mcp__<server>__<tool>` (Claude Code, the API and
90
+ * an ACP agent that marks its server), `<server>/<tool>` (Codex), or an ACP call titled with the server and the
91
+ * tool (Grok's `use_tool`, Copilot, and calls of agents from before they were marked). A name that says which
92
+ * server is read before any title, over every server, the longest name first. Null for any other call.
93
+ */
94
+ export function mcpCallOf(item, servers) {
95
+ const input = isRecord(item.input) ? item.input : {};
96
+ const longestFirst = [...servers].sort((left, right) => right.length - left.length);
97
+ const named = namedCall(item.name, input, longestFirst);
98
+ const call = named === undefined ? titledCall(item.name, input, longestFirst) : named;
99
+ return call === null || call === undefined ? null : {
100
+ ...call,
101
+ output: unwrapped(item.output)
102
+ };
103
+ }
104
+ function folded(text) {
105
+ const line = text.replace(/\s+/g, ' ');
106
+ return line.length > FOLD_LENGTH ? `${line.slice(0, FOLD_LENGTH)}…` : line;
107
+ }
108
+ function scalarText(value) {
109
+ return typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean' ? String(value) : null;
110
+ }
111
+ /* The lead and the fields of a call as `field=value`, each value a word a host may name; a value that is no text reads as `{…}` or `[…]`. */
112
+ function detailOf(match, input) {
113
+ let detail = match.lead ?? '';
114
+ const words = [];
115
+ for (const field of match.fields ?? Object.keys(input)) {
116
+ const value = input[field];
117
+ if (value === undefined || value === null) {
118
+ continue;
119
+ }
120
+ detail += `${detail === '' ? '' : ' '}${field}=`;
121
+ const values = Array.isArray(value) ? value : [value];
122
+ const texts = values.map(scalarText).filter(text => text !== null);
123
+ if (texts.length < values.length) {
124
+ detail += Array.isArray(value) ? '[…]' : '{…}';
125
+ continue;
126
+ }
127
+ texts.forEach((text, index) => {
128
+ const quoted = text === '' || /[\s",]/.test(text);
129
+ detail += `${index === 0 ? '' : ','}${quoted ? '"' : ''}`;
130
+ const start = detail.length;
131
+ detail += folded(text);
132
+ words.push({
133
+ start,
134
+ end: detail.length,
135
+ text,
136
+ option: field
137
+ });
138
+ detail += quoted ? '"' : '';
139
+ });
140
+ }
141
+ return {
142
+ detail,
143
+ words
144
+ };
145
+ }
146
+ function read(item, looks) {
147
+ const call = mcpCallOf(item, looks.map(({
148
+ server
149
+ }) => server));
150
+ const look = call === null ? undefined : looks.find(({
151
+ server
152
+ }) => server === call.server);
153
+ const match = call === null || look === undefined ? null : look.describe(call.tool, call.input);
154
+ if (call === null || look === undefined || match === null) {
155
+ return null;
156
+ }
157
+ return {
158
+ look,
159
+ match,
160
+ call,
161
+ label: match.label,
162
+ group: match.group,
163
+ ...detailOf(match, call.input),
164
+ code: [],
165
+ others: [],
166
+ more: 0,
167
+ heredoc: false,
168
+ shell: false
169
+ };
170
+ }
171
+ /* The call of a look's MCP server that `item` is, read as that look's tool; null for any other call and one the look does not describe. */
172
+ export function matchToolLook(item, looks) {
173
+ if (looks === undefined || looks.length === 0) {
174
+ return null;
175
+ }
176
+ let cache = caches.get(looks);
177
+ if (cache === undefined) {
178
+ cache = new WeakMap();
179
+ caches.set(looks, cache);
180
+ }
181
+ const known = cache.get(item);
182
+ if (known !== undefined) {
183
+ return known;
184
+ }
185
+ const run = read(item, looks);
186
+ cache.set(item, run);
187
+ return run;
188
+ }
@@ -3,7 +3,12 @@ export interface FileChange {
3
3
  path: string;
4
4
  before: string;
5
5
  after: string;
6
+ fragment?: boolean;
6
7
  }
8
+ export declare function diffTexts(change: FileChange): {
9
+ before: string;
10
+ after: string;
11
+ };
7
12
  export declare function toolSummary(name: string, input: unknown): string;
8
13
  export declare function toolSummaryIsPath(name: string, input: unknown): boolean;
9
14
  export declare function shellCommand(name: string, input: unknown): string | null;
@@ -1,5 +1,18 @@
1
1
  import { isRecord } from './json.js';
2
2
  import { toolEntry } from './tool-catalog.js';
3
+ /* The texts a diff draws: a fragment ends where its edit does, not where its file ends, so it gets no "no final newline" mark. */
4
+ export function diffTexts(change) {
5
+ if (change.fragment !== true || change.before.endsWith('\n') || change.after.endsWith('\n')) {
6
+ return {
7
+ before: change.before,
8
+ after: change.after
9
+ };
10
+ }
11
+ return {
12
+ before: `${change.before}\n`,
13
+ after: `${change.after}\n`
14
+ };
15
+ }
3
16
  function str(value) {
4
17
  return typeof value === 'string' ? value : null;
5
18
  }
@@ -115,7 +128,8 @@ export function fileChanges(name, input) {
115
128
  return [{
116
129
  path,
117
130
  before: str(input.old_string) ?? '',
118
- after: str(input.new_string) ?? ''
131
+ after: str(input.new_string) ?? '',
132
+ fragment: true
119
133
  }];
120
134
  }
121
135
  if (name === 'Write') {
@@ -129,7 +143,8 @@ export function fileChanges(name, input) {
129
143
  return input.edits.filter(isRecord).map(edit => ({
130
144
  path,
131
145
  before: str(edit.old_string) ?? '',
132
- after: str(edit.new_string) ?? ''
146
+ after: str(edit.new_string) ?? '',
147
+ fragment: true
133
148
  }));
134
149
  }
135
150
  return [];
@@ -6,8 +6,9 @@ export interface NamedWord {
6
6
  readonly word: string;
7
7
  readonly name: CommandName;
8
8
  }
9
- export declare function ShellCommand({ command, code, names }: {
9
+ export declare function ShellCommand({ command, code, names, plain }: {
10
10
  command: string;
11
11
  code?: readonly EmbeddedCode[];
12
12
  names?: readonly NamedWord[];
13
+ plain?: boolean;
13
14
  }): import("react").JSX.Element;
@@ -5,6 +5,7 @@ import { EMBEDDED_CODE_LIMIT, SHELL_LANGUAGE, embeddedCode } from '../logic/embe
5
5
  import { useChatHost } from '../../host.js';
6
6
  import { useCodeTheme } from './code-theme.js';
7
7
  import { tokenStyle, useCodeHighlighter } from './highlighter.js';
8
+ import { ReferenceChip } from './ReferenceChip.js';
8
9
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
9
10
  const NO_CODE = [];
10
11
  const NO_NAMES = [];
@@ -123,50 +124,98 @@ function draw(command, runs, from, to) {
123
124
  }
124
125
  return parts;
125
126
  }
126
- /* A word as its name, in a frame so it reads as a reference; the word itself stays in the text, for a find. */
127
+ /*
128
+ * A word as its name: the `#` chip of the reference it is, else in a frame so it reads as one. The word itself
129
+ * stays in the text, for a find.
130
+ */
127
131
  function Name(t0) {
128
- const $ = _c(9);
132
+ const $ = _c(17);
129
133
  const {
130
134
  named
131
135
  } = t0;
136
+ const {
137
+ reference
138
+ } = named.name;
139
+ if (reference !== undefined) {
140
+ let t1;
141
+ if ($[0] !== named.name.name || $[1] !== reference) {
142
+ t1 = /*#__PURE__*/_jsx(ReferenceChip, {
143
+ id: reference,
144
+ lastName: named.name.name
145
+ });
146
+ $[0] = named.name.name;
147
+ $[1] = reference;
148
+ $[2] = t1;
149
+ } else {
150
+ t1 = $[2];
151
+ }
152
+ let t2;
153
+ if ($[3] !== named.word) {
154
+ t2 = /*#__PURE__*/_jsx("span", {
155
+ className: "sr-only",
156
+ children: named.word
157
+ });
158
+ $[3] = named.word;
159
+ $[4] = t2;
160
+ } else {
161
+ t2 = $[4];
162
+ }
163
+ let t3;
164
+ if ($[5] !== t1 || $[6] !== t2) {
165
+ t3 = /*#__PURE__*/_jsxs("span", {
166
+ className: "font-sans",
167
+ onClick: _temp,
168
+ children: [t1, t2]
169
+ });
170
+ $[5] = t1;
171
+ $[6] = t2;
172
+ $[7] = t3;
173
+ } else {
174
+ t3 = $[7];
175
+ }
176
+ return t3;
177
+ }
132
178
  let t1;
133
- if ($[0] !== named.word) {
179
+ if ($[8] !== named.word) {
134
180
  t1 = /*#__PURE__*/_jsx("span", {
135
181
  className: "sr-only",
136
182
  children: named.word
137
183
  });
138
- $[0] = named.word;
139
- $[1] = t1;
184
+ $[8] = named.word;
185
+ $[9] = t1;
140
186
  } else {
141
- t1 = $[1];
187
+ t1 = $[9];
142
188
  }
143
189
  let t2;
144
- if ($[2] !== named.name.icon || $[3] !== named.name.name || $[4] !== t1) {
190
+ if ($[10] !== named.name.icon || $[11] !== named.name.name || $[12] !== t1) {
145
191
  t2 = /*#__PURE__*/_jsxs("span", {
146
192
  className: "inline-flex items-center gap-1 rounded bg-surface-hover px-1 font-sans text-text ring-1 ring-border ring-inset",
147
193
  children: [named.name.icon, named.name.name, t1]
148
194
  });
149
- $[2] = named.name.icon;
150
- $[3] = named.name.name;
151
- $[4] = t1;
152
- $[5] = t2;
195
+ $[10] = named.name.icon;
196
+ $[11] = named.name.name;
197
+ $[12] = t1;
198
+ $[13] = t2;
153
199
  } else {
154
- t2 = $[5];
200
+ t2 = $[13];
155
201
  }
156
202
  let t3;
157
- if ($[6] !== named.word || $[7] !== t2) {
203
+ if ($[14] !== named.word || $[15] !== t2) {
158
204
  t3 = /*#__PURE__*/_jsx(Tooltip, {
159
205
  label: named.word,
160
206
  children: t2
161
207
  });
162
- $[6] = named.word;
163
- $[7] = t2;
164
- $[8] = t3;
208
+ $[14] = named.word;
209
+ $[15] = t2;
210
+ $[16] = t3;
165
211
  } else {
166
- t3 = $[8];
212
+ t3 = $[16];
167
213
  }
168
214
  return t3;
169
215
  }
216
+ function _temp(e) {
217
+ return e.stopPropagation();
218
+ }
170
219
  function drawNamed(command, runs, names) {
171
220
  const parts = [];
172
221
  let at = 0;
@@ -187,11 +236,13 @@ function drawNamed(command, runs, names) {
187
236
  * `python3 -c` argument, a heredoc) in its own language. Plain text until the grammars are in, which
188
237
  * changes no size; a command past the limit stays plain. `code` adds stretches whose language the
189
238
  * caller knows, and `names` draws words as the names a host gave them, both as offsets into `command`.
239
+ * `plain` draws text that is no shell source uncolored, with its names.
190
240
  */
191
241
  export function ShellCommand({
192
242
  command,
193
243
  code = NO_CODE,
194
- names = NO_NAMES
244
+ names = NO_NAMES,
245
+ plain = false
195
246
  }) {
196
247
  // The highlighter's cache fills in place; compiled, the runs it gave before its grammars loaded would stay.
197
248
  'use no memo';
@@ -203,10 +254,10 @@ export function ShellCommand({
203
254
  const highlighter = useCodeHighlighter();
204
255
  // Bumped when a load settles, so the cache is asked again.
205
256
  const [, setLoads] = useState(0);
206
- const tooLong = command.length > EMBEDDED_CODE_LIMIT;
207
- const runs = tooLong ? null : highlight(command, code, theme, highlighter);
257
+ const uncolored = plain || command.length > EMBEDDED_CODE_LIMIT;
258
+ const runs = uncolored ? null : highlight(command, code, theme, highlighter);
208
259
  useEffect(() => {
209
- if (runs !== null || tooLong) {
260
+ if (runs !== null || uncolored) {
210
261
  return;
211
262
  }
212
263
  let cancelled = false;
@@ -214,7 +265,7 @@ export function ShellCommand({
214
265
  return () => {
215
266
  cancelled = true;
216
267
  };
217
- }, [highlighter, command, code, theme, custom, runs, tooLong]);
268
+ }, [highlighter, command, code, theme, custom, runs, uncolored]);
218
269
  if (names.length > 0) {
219
270
  return /*#__PURE__*/_jsx(_Fragment, {
220
271
  children: drawNamed(command, runs, names)
@@ -45,7 +45,9 @@ export function SubagentTimeline(t0) {
45
45
  } = useTranslation("agent-chat");
46
46
  const scope = useChatScope();
47
47
  const {
48
- commandLooks
48
+ commandLooks,
49
+ toolLooks,
50
+ saidBy
49
51
  } = useChatHost();
50
52
  const {
51
53
  trail,
@@ -131,6 +133,7 @@ export function SubagentTimeline(t0) {
131
133
  expandedSubagents: subagents.ids,
132
134
  activeTurnId: null,
133
135
  commandLooks,
136
+ toolLooks,
134
137
  hideTools
135
138
  });
136
139
  let t7;
@@ -298,7 +301,7 @@ export function SubagentTimeline(t0) {
298
301
  const previous = index > 0 ? rows[index - 1] : null;
299
302
  return /*#__PURE__*/_jsx("div", {
300
303
  "data-item-id": row_0.id,
301
- className: rowRhythm(row_0, previous),
304
+ className: rowRhythm(row_0, previous, saidBy !== undefined),
302
305
  children: /*#__PURE__*/_jsx(Row, {
303
306
  row: row_0,
304
307
  chatId: chatId,
@@ -501,9 +501,10 @@ export function Timeline({
501
501
  activeTurnId,
502
502
  forkedTurns,
503
503
  commandLooks: host.commandLooks,
504
+ toolLooks: host.toolLooks,
504
505
  hideTools
505
506
  });
506
- }, [order, items, groups.ids, turns.ids, subagents.ids, activeTurnId, forkedTurns, host.commandLooks, hideTools]);
507
+ }, [order, items, groups.ids, turns.ids, subagents.ids, activeTurnId, forkedTurns, host.commandLooks, host.toolLooks, hideTools]);
507
508
  const cards = useHostThreadCards(scopeId, chatId);
508
509
  const drawsVisuals = host.visuals !== null;
509
510
  // Where the part of the thread this client holds begins, while there is a page before it.
@@ -2,9 +2,9 @@ import { type ReactNode } from 'react';
2
2
  import type { EditorEngine } from '@adecore/editor';
3
3
  import { type DiffSource } from '@adecore/editor-react';
4
4
  import { type DiffDocument } from '@adecore/merge';
5
- import type { FileChange } from '../../logic/tools.js';
5
+ import { type FileChange } from '../../logic/tools.js';
6
6
  type EngineLoader = () => Promise<EditorEngine>;
7
- export declare function EditorDocumentDiff({ document, path, loadEngine, fallback, wrap, fill, layout, maxHeight, onSource }: {
7
+ export declare function EditorDocumentDiff({ document, path, loadEngine, fallback, wrap, fill, layout, maxHeight, numbered, onSource }: {
8
8
  document: DiffDocument;
9
9
  path: string;
10
10
  loadEngine: EngineLoader;
@@ -13,6 +13,7 @@ export declare function EditorDocumentDiff({ document, path, loadEngine, fallbac
13
13
  fill?: boolean;
14
14
  layout?: 'unified' | 'split';
15
15
  maxHeight?: number;
16
+ numbered?: boolean;
16
17
  onSource?(source: DiffSource): void | (() => void);
17
18
  }): string | number | bigint | boolean | import("react").JSX.Element | Iterable<ReactNode> | Promise<string | number | bigint | boolean | Iterable<ReactNode> | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | import("react").ReactPortal | null | undefined> | null | undefined;
18
19
  export default function EditorEditDiff({ change, loadEngine, fallback, maxHeight, sourceChecked }: {