@adecore/agents-react 0.50.7 → 0.52.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 (43) hide show
  1. package/dist/chat/index.d.ts +2 -1
  2. package/dist/chat/index.js +2 -1
  3. package/dist/chat/logic/command-looks.d.ts +17 -5
  4. package/dist/chat/logic/command-looks.js +35 -7
  5. package/dist/chat/logic/timeline.d.ts +6 -4
  6. package/dist/chat/logic/timeline.js +19 -21
  7. package/dist/chat/logic/tool-looks.d.ts +16 -0
  8. package/dist/chat/logic/tool-looks.js +188 -0
  9. package/dist/chat/ui/Markdown.js +97 -103
  10. package/dist/chat/ui/ShellCommand.d.ts +2 -1
  11. package/dist/chat/ui/ShellCommand.js +73 -22
  12. package/dist/chat/ui/SubagentTimeline.js +5 -2
  13. package/dist/chat/ui/Timeline.js +2 -1
  14. package/dist/chat/ui/rows/RowContainer.js +26 -23
  15. package/dist/chat/ui/rows/WorkRows.d.ts +3 -4
  16. package/dist/chat/ui/rows/WorkRows.js +592 -519
  17. package/dist/chat/ui/rows/row-rhythm.d.ts +2 -2
  18. package/dist/chat/ui/rows/row-rhythm.js +9 -6
  19. package/dist/chat/ui/thread-references.d.ts +1 -0
  20. package/dist/chat/ui/thread-references.js +4 -3
  21. package/dist/host.d.ts +28 -0
  22. package/dist/index.d.ts +1 -1
  23. package/dist/locales/en/agent-chat.d.ts +3 -0
  24. package/dist/locales/en/agent-chat.js +3 -0
  25. package/dist/locales/nl/agent-chat.d.ts +3 -0
  26. package/dist/locales/nl/agent-chat.js +3 -0
  27. package/package.json +8 -8
  28. package/src/chat/index.ts +2 -1
  29. package/src/chat/logic/command-looks.ts +51 -10
  30. package/src/chat/logic/timeline.ts +28 -24
  31. package/src/chat/logic/tool-looks.ts +228 -0
  32. package/src/chat/ui/Markdown.tsx +21 -7
  33. package/src/chat/ui/ShellCommand.tsx +33 -6
  34. package/src/chat/ui/SubagentTimeline.tsx +3 -2
  35. package/src/chat/ui/Timeline.tsx +2 -1
  36. package/src/chat/ui/rows/RowContainer.tsx +4 -2
  37. package/src/chat/ui/rows/WorkRows.tsx +46 -33
  38. package/src/chat/ui/rows/row-rhythm.ts +9 -6
  39. package/src/chat/ui/thread-references.ts +5 -1
  40. package/src/host.ts +51 -0
  41. package/src/index.ts +3 -0
  42. package/src/locales/en/agent-chat.ts +3 -0
  43. package/src/locales/nl/agent-chat.ts +3 -0
@@ -9,7 +9,8 @@ export type { EffortStep } from './logic/effort.js';
9
9
  export { EMPTY_DRAFT, useDrafts, readDraft, writeDraft, offerDraft, type ChatDraft } from './drafts.js';
10
10
  export { stripAnsi } from './logic/ansi.js';
11
11
  export { FORKABLE_PROVIDERS, forkRefusal, summaryRefusal, lastSettledTurn, forkPointOf, forkPointLabel, type ForkShape, forkShapes, type ForkCliChoice, forkPayload, branchRefusal, type ForkPoint, type ForkWorktreeChoice } from './logic/fork.js';
12
- export { matchCommandLook, sentMessageOf, type CommandLookRun, type CommandLookWord } from './logic/command-looks.js';
12
+ export { matchCommandLook, lookRunOf, sentMessageOf, type Look, type LookRun, type CommandLookRun, type CommandLookWord } from './logic/command-looks.js';
13
+ export { mcpCallOf, matchToolLook, type McpCall, type ToolLookRun } from './logic/tool-looks.js';
13
14
  export { handbackReportOf } from './logic/handback.js';
14
15
  export { limitView, type LimitView } from './logic/limit.js';
15
16
  export type { TickKind, ScrubberTick } from './logic/scrubber.js';
@@ -8,7 +8,8 @@ export { stepEffortFromComposer } from './composer-effort.js';
8
8
  export { EMPTY_DRAFT, useDrafts, readDraft, writeDraft, offerDraft } from './drafts.js';
9
9
  export { stripAnsi } from './logic/ansi.js';
10
10
  export { FORKABLE_PROVIDERS, forkRefusal, summaryRefusal, lastSettledTurn, forkPointOf, forkPointLabel, forkShapes, forkPayload, branchRefusal } from './logic/fork.js';
11
- export { matchCommandLook, sentMessageOf } from './logic/command-looks.js';
11
+ export { matchCommandLook, lookRunOf, sentMessageOf } from './logic/command-looks.js';
12
+ export { mcpCallOf, matchToolLook } from './logic/tool-looks.js';
12
13
  export { handbackReportOf } from './logic/handback.js';
13
14
  export { limitView } from './logic/limit.js';
14
15
  export { withTimedRows, timedRowsOf } from './logic/thread-cards.js';
@@ -1,5 +1,5 @@
1
1
  import type { ChatToolItem } from '@adecore/agent-contracts';
2
- import type { CommandLook, CommandLookMatch, CommandLookSent } from '../../host.js';
2
+ import type { CommandLook, CommandLookMatch, CommandLookSent, ToolLook } from '../../host.js';
3
3
  import { type EmbeddedCode } from './embedded-code.js';
4
4
  export interface CommandLookWord {
5
5
  readonly start: number;
@@ -7,18 +7,30 @@ export interface CommandLookWord {
7
7
  readonly text: string;
8
8
  readonly option: string | null;
9
9
  }
10
- export interface CommandLookRun {
11
- readonly look: CommandLook;
12
- readonly match: CommandLookMatch;
10
+ export type Look = CommandLook | ToolLook;
11
+ export interface LookRun {
12
+ readonly look: Look;
13
+ readonly label: string;
14
+ readonly group?: {
15
+ key: string;
16
+ sentence(count: number): string;
17
+ };
13
18
  readonly detail: string;
19
+ readonly shell: boolean;
14
20
  readonly code: readonly EmbeddedCode[];
15
21
  readonly words: readonly CommandLookWord[];
16
22
  readonly others: readonly string[];
17
23
  readonly more: number;
18
24
  readonly heredoc: boolean;
25
+ }
26
+ export interface CommandLookRun extends LookRun {
27
+ readonly look: CommandLook;
28
+ readonly match: CommandLookMatch;
19
29
  readonly args: readonly string[];
20
30
  readonly heredocText: string | null;
21
31
  readonly expands: boolean;
22
32
  }
23
33
  export declare function matchCommandLook(command: string, looks: readonly CommandLook[] | undefined): CommandLookRun | null;
24
- export declare function sentMessageOf(tool: ChatToolItem, looks: readonly CommandLook[] | undefined): CommandLookSent | null;
34
+ export declare function lookRunOf(tool: ChatToolItem, commandLooks: readonly CommandLook[] | undefined, toolLooks: readonly ToolLook[] | undefined): LookRun | null;
35
+ export declare function lookKey(look: Look): string;
36
+ export declare function sentMessageOf(tool: ChatToolItem, looks: readonly CommandLook[] | undefined, toolLooks?: readonly ToolLook[]): CommandLookSent | null;
@@ -1,4 +1,5 @@
1
1
  import { EMBEDDED_CODE_LIMIT, shellCommands } from './embedded-code.js';
2
+ import { matchToolLook } from './tool-looks.js';
2
3
  import { shellCommand } from './tools.js';
3
4
  // A folded value keeps this many characters of what it says.
4
5
  const FOLD_LENGTH = 40;
@@ -160,6 +161,9 @@ function read(command, looks) {
160
161
  return {
161
162
  look: found.look,
162
163
  match: found.match,
164
+ label: found.match.label,
165
+ group: found.match.group,
166
+ shell: true,
163
167
  ...detailOf(command, found.command, found.match),
164
168
  others,
165
169
  more,
@@ -198,17 +202,41 @@ export function matchCommandLook(command, looks) {
198
202
  }
199
203
  return run;
200
204
  }
201
- /* The message a shell call sent, per its look: only for a line that is exactly that one call, whose words are all known. */
202
- export function sentMessageOf(tool, looks) {
205
+ /* The look a call runs under, a program of its shell line before an MCP server, or null for a call no look knows. */
206
+ export function lookRunOf(tool, commandLooks, toolLooks) {
207
+ const command = shellCommand(tool.name, tool.input);
208
+ return (command === null ? null : matchCommandLook(command, commandLooks)) ?? matchToolLook(tool, toolLooks);
209
+ }
210
+ /* What tells looks apart where two may share a group key: the program, or the server. */
211
+ export function lookKey(look) {
212
+ return 'program' in look ? `program:${look.program}` : `server:${look.server}`;
213
+ }
214
+ /*
215
+ * The message a call sent, per its look: for a shell line only when it is exactly that one call, whose
216
+ * words are all known; for an MCP call whenever its look reads one from it.
217
+ */
218
+ export function sentMessageOf(tool, looks, toolLooks) {
203
219
  const command = shellCommand(tool.name, tool.input);
204
220
  const run = command === null ? null : matchCommandLook(command, looks);
205
- if (run === null || run.look.sent === undefined || run.others.length > 0 || run.more > 0 || run.expands) {
221
+ if (run !== null) {
222
+ if (run.look.sent === undefined || run.others.length > 0 || run.more > 0 || run.expands) {
223
+ return null;
224
+ }
225
+ return run.look.sent({
226
+ args: run.args,
227
+ heredoc: run.heredocText,
228
+ state: tool.state,
229
+ output: tool.output
230
+ });
231
+ }
232
+ const called = matchToolLook(tool, toolLooks);
233
+ if (called === null || called.look.sent === undefined) {
206
234
  return null;
207
235
  }
208
- return run.look.sent({
209
- args: run.args,
210
- heredoc: run.heredocText,
236
+ return called.look.sent({
237
+ tool: called.call.tool,
238
+ input: called.call.input,
211
239
  state: tool.state,
212
- output: tool.output
240
+ output: called.call.output
213
241
  });
214
242
  }
@@ -1,5 +1,6 @@
1
1
  import type { ChatApprovalItem, ChatAssistantItem, ChatCheckpointDiff, ChatItem, ChatNoteMessage, ChatQuestionItem, ChatSubagentItem, ChatThinkingItem, ChatToolItem, ChatTurnItem, ChatUserItem, ChatVisual, ChatWorkflow } from '@adecore/agent-contracts';
2
- import type { CommandLook, CommandLookSent, ThreadCard } from '../../host.js';
2
+ import type { CommandLook, CommandLookSent, ThreadCard, ToolLook } from '../../host.js';
3
+ import { type Look } from './command-looks.js';
3
4
  export interface SubagentBranch {
4
5
  id: string;
5
6
  item: ChatSubagentItem;
@@ -38,7 +39,7 @@ export type TimelineRow = {
38
39
  tools: ChatToolItem[];
39
40
  summary: string;
40
41
  expanded: boolean;
41
- look?: CommandLook;
42
+ look?: Look;
42
43
  } | {
43
44
  kind: 'work-live';
44
45
  id: string;
@@ -127,11 +128,12 @@ interface TimelineOptions {
127
128
  activeTurnId: string | null;
128
129
  forkedTurns?: ReadonlySet<string>;
129
130
  commandLooks?: readonly CommandLook[];
131
+ toolLooks?: readonly ToolLook[];
130
132
  hideTools?: boolean;
131
133
  }
132
134
  export declare function isBlock(row: TimelineRow): boolean;
133
- export declare function summarizeGroup(tools: ChatToolItem[], looks?: readonly CommandLook[]): string;
134
- export declare function summarizeTurn(tools: readonly ChatToolItem[], looks?: readonly CommandLook[]): string[];
135
+ export declare function summarizeGroup(tools: ChatToolItem[], looks?: readonly CommandLook[], toolLooks?: readonly ToolLook[]): string;
136
+ export declare function summarizeTurn(tools: readonly ChatToolItem[], looks?: readonly CommandLook[], toolLooks?: readonly ToolLook[]): string[];
135
137
  export declare function agentTurnLabel(turn: ChatTurnItem): string;
136
138
  export declare function turnLabel(turn: ChatTurnItem, items?: readonly ChatItem[]): string;
137
139
  export declare function findSubagentBranch(rows: readonly TimelineRow[], toolUseId: string): {
@@ -1,11 +1,11 @@
1
1
  import i18next from 'i18next';
2
2
  import { abortedByMachine } from '@adecore/agent-contracts';
3
3
  import { formatElapsedShort } from '@adecore/ui/format';
4
- import { matchCommandLook, sentMessageOf } from './command-looks.js';
4
+ import { lookKey, lookRunOf, sentMessageOf } from './command-looks.js';
5
5
  import { isImageGeneration } from './generated-image.js';
6
6
  import { handbackReportOf } from './handback.js';
7
7
  import { toolEntry } from './tool-catalog.js';
8
- import { hasFileChanges, isFileChange, shellCommand } from './tools.js';
8
+ import { hasFileChanges, isFileChange } from './tools.js';
9
9
  const TOOL_KINDS = new Set(['work', 'work-group', 'work-live']);
10
10
  // A generated image is drawn as a tool call but reads as the turn's result, so it stays.
11
11
  function shownRows(rows, options) {
@@ -21,23 +21,22 @@ export function isBlock(row) {
21
21
  return BLOCK_KINDS.has(row.kind) || isImageRow(row);
22
22
  }
23
23
  /*
24
- * The sentence of a run of shell calls that are all runs of one look: its group's when they share a key,
25
- * else the look's own; null for any other run, which reads as shell calls.
24
+ * The sentence of a run of calls that are all runs of one look: its group's when they share a key,
25
+ * else the look's own; null for any other run, which reads as its calls.
26
26
  */
27
- function lookSummary(tools, looks) {
27
+ function lookSummary(tools, looks, toolLooks) {
28
28
  let look = null;
29
29
  let group;
30
30
  let sameKey = true;
31
31
  for (const tool of tools) {
32
- const command = shellCommand(tool.name, tool.input);
33
- const run = command === null ? null : matchCommandLook(command, looks);
32
+ const run = lookRunOf(tool, looks, toolLooks);
34
33
  if (run === null || look !== null && run.look !== look) {
35
34
  return null;
36
35
  }
37
36
  if (look === null) {
38
37
  look = run.look;
39
- group = run.match.group;
40
- } else if (run.match.group?.key !== group?.key) {
38
+ group = run.group;
39
+ } else if (run.group?.key !== group?.key) {
41
40
  sameKey = false;
42
41
  }
43
42
  }
@@ -56,8 +55,8 @@ function lookSummary(tools, looks) {
56
55
  };
57
56
  }
58
57
  /* "Read 4 files", "Ran 2 commands", "12 tool calls" when the run mixes kinds, or the sentence of a look all its calls are runs of. */
59
- export function summarizeGroup(tools, looks) {
60
- const looked = lookSummary(tools, looks);
58
+ export function summarizeGroup(tools, looks, toolLooks) {
59
+ const looked = lookSummary(tools, looks, toolLooks);
61
60
  if (looked !== null) {
62
61
  return looked.summary;
63
62
  }
@@ -98,7 +97,7 @@ function editedPath(tool) {
98
97
  * "Searched 2 patterns". Every file change reads as one sentence, and calls without a sentence of
99
98
  * their own are counted together at the end.
100
99
  */
101
- export function summarizeTurn(tools, looks) {
100
+ export function summarizeTurn(tools, looks, toolLooks) {
102
101
  // Keyed by the sentence, so its place is where the first call of that kind came.
103
102
  const counts = new Map();
104
103
  const add = (key, say, total) => {
@@ -115,10 +114,9 @@ export function summarizeTurn(tools, looks) {
115
114
  const edited = new Set();
116
115
  let other = 0;
117
116
  for (const tool of tools) {
118
- const command = shellCommand(tool.name, tool.input);
119
- const run = command === null ? null : matchCommandLook(command, looks);
120
- const group = run?.match.group;
121
- const sent = sentMessageOf(tool, looks);
117
+ const run = lookRunOf(tool, looks, toolLooks);
118
+ const group = run?.group;
119
+ const sent = sentMessageOf(tool, looks, toolLooks);
122
120
  if (sent !== null && sent.state !== 'failed') {
123
121
  add('agent-chat:group.sent', count => i18next.t('agent-chat:group.sent', {
124
122
  count
@@ -126,8 +124,8 @@ export function summarizeTurn(tools, looks) {
126
124
  } else if (sent !== null) {
127
125
  other += 1;
128
126
  } else if (run !== null && group !== undefined) {
129
- // Keyed by the program too, so two looks with a key in common keep their own sentences.
130
- add(`look:${run.look.program}:${group.key}`, group.sentence);
127
+ // Keyed by the look too, so two looks with a key in common keep their own sentences.
128
+ add(`look:${lookKey(run.look)}:${group.key}`, group.sentence);
131
129
  } else if (failedFileChange(tool)) {
132
130
  other += 1;
133
131
  } else if (isFileChange(tool.name)) {
@@ -267,7 +265,7 @@ function flushTools(buffer, rows, options) {
267
265
  const first = tools[0];
268
266
  const id = `group-${first.id}`;
269
267
  const expanded = options.expandedGroups.has(id);
270
- const looked = lookSummary(tools, options.commandLooks);
268
+ const looked = lookSummary(tools, options.commandLooks, options.toolLooks);
271
269
  rows.push(looked === null ? {
272
270
  kind: 'work-group',
273
271
  id,
@@ -304,7 +302,7 @@ function rowsForItems(items, options, children) {
304
302
  continue;
305
303
  }
306
304
  const report = handbackReportOf(item);
307
- const sent = item.kind === 'tool' ? sentMessageOf(item, options.commandLooks) : null;
305
+ const sent = item.kind === 'tool' ? sentMessageOf(item, options.commandLooks, options.toolLooks) : null;
308
306
  if (item.kind === 'tool' && sent !== null) {
309
307
  flushTools(tools, rows, options);
310
308
  rows.push({
@@ -621,7 +619,7 @@ export function deriveTimelineRows(items, options) {
621
619
  id: `fold-${turnId}`,
622
620
  turn,
623
621
  label: turnLabel(turn, chunk.items),
624
- work: summarizeTurn(tools, options.commandLooks),
622
+ work: summarizeTurn(tools, options.commandLooks, options.toolLooks),
625
623
  hiddenCount: folded,
626
624
  expanded,
627
625
  expandable
@@ -0,0 +1,16 @@
1
+ import type { ChatToolItem } from '@adecore/agent-contracts';
2
+ import type { ToolLook, ToolLookMatch } from '../../host.js';
3
+ import type { LookRun } from './command-looks.js';
4
+ export interface McpCall {
5
+ readonly server: string;
6
+ readonly tool: string;
7
+ readonly input: Readonly<Record<string, unknown>>;
8
+ readonly output: string | null;
9
+ }
10
+ export interface ToolLookRun extends LookRun {
11
+ readonly look: ToolLook;
12
+ readonly match: ToolLookMatch;
13
+ readonly call: McpCall;
14
+ }
15
+ export declare function mcpCallOf(item: Pick<ChatToolItem, 'name' | 'input' | 'output'>, servers: readonly string[]): McpCall | null;
16
+ export declare function matchToolLook(item: ChatToolItem, looks: readonly ToolLook[] | undefined): ToolLookRun | null;
@@ -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
+ }