@adecore/agents-react 0.50.6 → 0.51.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.
package/dist/host.d.ts CHANGED
@@ -226,6 +226,31 @@ export interface UiModelViewProps {
226
226
  caption: string;
227
227
  }
228
228
  export interface ChatHost {
229
+ useExpandingCommands?(): readonly {
230
+ name: string;
231
+ hint: string;
232
+ expand(args: string): Promise<string>;
233
+ }[];
234
+ renderEmptyThread?(chatId: string): ReactNode;
235
+ renderToolActions?(tool: {
236
+ name: string;
237
+ input: unknown;
238
+ output: string | null;
239
+ state: string;
240
+ }, chatId: string | undefined): ReactNode;
241
+ renderToolResult?(tool: {
242
+ name: string;
243
+ input: unknown;
244
+ output: string | null;
245
+ state: string;
246
+ }, chatId: string | undefined): ReactNode;
247
+ renderMessageActions?(message: {
248
+ chatId: string;
249
+ id: string;
250
+ kind: 'user' | 'assistant';
251
+ text: string;
252
+ }): ReactNode;
253
+ renderCodeFence?(language: string | undefined, code: string): ReactNode;
229
254
  intelligentUi?: {
230
255
  subscribe?(scopeId: string, chatId: string, changed: () => void): () => void;
231
256
  link?(scopeId: string, payload: ChatUiLinkPayload): Promise<ChatUiLinkReading>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adecore/agents-react",
3
- "version": "0.50.6",
3
+ "version": "0.51.0",
4
4
  "description": "React agent chat threads, composers, approvals, provider accounts and usage views.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -72,11 +72,11 @@
72
72
  "test:visuals": "bun --config=integration.bunfig.toml --conditions=source test ./src/chat/visual-viewport.integration.test.ts"
73
73
  },
74
74
  "dependencies": {
75
- "@adecore/agent-contracts": "0.50.6",
76
- "@adecore/editor": "0.50.6",
77
- "@adecore/editor-react": "0.50.6",
78
- "@adecore/intelligent-ui": "0.50.6",
79
- "@adecore/merge": "0.50.6",
75
+ "@adecore/agent-contracts": "0.51.0",
76
+ "@adecore/editor": "0.51.0",
77
+ "@adecore/editor-react": "0.51.0",
78
+ "@adecore/intelligent-ui": "0.51.0",
79
+ "@adecore/merge": "0.51.0",
80
80
  "@codemirror/commands": "^6.11.1",
81
81
  "@codemirror/language": "^6.13.1",
82
82
  "@codemirror/state": "^6.7.6",
@@ -100,14 +100,14 @@
100
100
  "zustand": "^5.0.16"
101
101
  },
102
102
  "peerDependencies": {
103
- "@adecore/ui": "^0.50.6",
103
+ "@adecore/ui": "^0.51.0",
104
104
  "i18next": "^26.4.2",
105
105
  "react": "^19.3.0",
106
106
  "react-dom": "^19.3.0",
107
107
  "react-i18next": "^17.0.15"
108
108
  },
109
109
  "devDependencies": {
110
- "@adecore/ui": "0.50.6",
110
+ "@adecore/ui": "0.51.0",
111
111
  "@types/bun": "^1.4.4",
112
112
  "@types/react": "^19.3.0",
113
113
  "@types/react-dom": "^19.3.0",
@@ -48,6 +48,8 @@ export interface Referable {
48
48
  /* Where it stands, outermost first; its chip draws these in front of its name. */
49
49
  trail?: readonly ReferenceStep[];
50
50
  section?: ReferenceSection;
51
+ /* What it comes down to in the prompt, for a thing from outside the project that nothing else can read. */
52
+ read?(): Promise<string>;
51
53
  }
52
54
 
53
55
  export interface Referables {
@@ -248,13 +248,14 @@ function Diagram({ code }: { code: string }) {
248
248
 
249
249
  function MarkdownCode({ className, children, plain = false }: { className?: string; children?: ReactNode; plain?: boolean }) {
250
250
  const block = useContext(BlockCodeContext);
251
+ const { renderCodeFence } = useChatHost();
251
252
  const text = String(children ?? '');
252
253
 
253
254
  if (block) {
254
255
  const lang = languageOf(className);
255
256
  const code = text.replace(/\n$/, '');
256
257
 
257
- return lang === 'mermaid' ? <Diagram code={code} /> : <CodeBlock code={code} lang={lang} />;
258
+ return renderCodeFence?.(lang, code) ?? (lang === 'mermaid' ? <Diagram code={code} /> : <CodeBlock code={code} lang={lang} />);
258
259
  }
259
260
 
260
261
  return plain ? <PlainCode text={text} /> : <InlineCode text={text} />;
@@ -320,7 +321,7 @@ const replyComponents = {
320
321
  function ReplyCode({ className, children, node }: { className?: string; children?: ReactNode } & ExtraProps) {
321
322
  const reply = useContext(ShellCodeBlockReplyContext);
322
323
  const block = useContext(BlockCodeContext);
323
- const { renderShellCodeBlock } = useChatHost();
324
+ const { renderCodeFence, renderShellCodeBlock } = useChatHost();
324
325
  const properties = node?.properties;
325
326
  const language = properties?.['data-shell-language'];
326
327
  const code = properties?.['data-shell-code'];
@@ -332,12 +333,20 @@ function ReplyCode({ className, children, node }: { className?: string; children
332
333
 
333
334
  const text = String(children ?? '');
334
335
 
335
- if (block && languageOf(className) === 'mermaid') {
336
- return <Diagram code={text.replace(/\n$/, '')} />;
337
- }
338
-
339
336
  if (block) {
340
- return <CodeBlock code={text.replace(/\n$/, '')} lang={languageOf(className)} actions={shellCodeBlockActions(reply, shell, renderShellCodeBlock)} />;
337
+ const lang = languageOf(className);
338
+ const body = text.replace(/\n$/, '');
339
+ const drawn = renderCodeFence?.(lang, body);
340
+
341
+ if (drawn !== undefined && drawn !== null) {
342
+ return drawn;
343
+ }
344
+
345
+ if (lang === 'mermaid') {
346
+ return <Diagram code={body} />;
347
+ }
348
+
349
+ return <CodeBlock code={body} lang={lang} actions={shellCodeBlockActions(reply, shell, renderShellCodeBlock)} />;
341
350
  }
342
351
 
343
352
  return <InlineCode text={text} />;
@@ -436,10 +445,16 @@ const ReplyFence = memo(function ReplyFence({
436
445
  open: boolean;
437
446
  reply?: ShellCodeBlockReply;
438
447
  }) {
439
- const { renderShellCodeBlock } = useChatHost();
448
+ const { renderCodeFence, renderShellCodeBlock } = useChatHost();
440
449
  // The class markdown gives the code, read back the way a parsed fence's is.
441
450
  const lang = languageOf(`language-${info.split(/[ \t]/, 1)[0]}`);
442
451
  const shell = reply === undefined ? null : shellFence(source);
452
+ // The host gets a fence only once it closed, so it never draws a body that is still being written.
453
+ const drawn = open ? null : renderCodeFence?.(lang, body);
454
+
455
+ if (drawn !== undefined && drawn !== null) {
456
+ return drawn;
457
+ }
443
458
 
444
459
  return (
445
460
  <CodeStreamingContext.Provider value={open}>
@@ -98,6 +98,7 @@ export function MessageActions({ chatId, row }: { chatId: string; row: MessageRo
98
98
  )}
99
99
  </ButtonGroup>
100
100
  )}
101
+ {host.renderMessageActions?.({ chatId, id: row.id, kind: row.kind, text: row.item.text })}
101
102
  <Tooltip label={formatDateTime(row.item.createdAt, TIMESTAMP_FORMAT)}>
102
103
  <time
103
104
  dateTime={new Date(row.item.createdAt).toISOString()}
@@ -97,6 +97,7 @@ function showRowAtTop(virtualizer: Virtualizer<HTMLDivElement, Element>, followR
97
97
  * and the folder it works in, so a first question can lean on all three.
98
98
  */
99
99
  function EmptyThread({ chatId }: { chatId: string }) {
100
+ const { renderEmptyThread } = useChatHost();
100
101
  const { t } = useTranslation('agent-chat');
101
102
  const info = useChatRow(chatId, (row) => row?.info ?? null);
102
103
  const model = useModelName(info?.provider, info?.selection.model ?? '');
@@ -109,6 +110,7 @@ function EmptyThread({ chatId }: { chatId: string }) {
109
110
  <EmptyState icon={info ? <AgentIcon kind={info.provider} /> : undefined} className="p-0">
110
111
  {info ? t('timeline.empty.ready', { model }) : t('timeline.empty.ask')}
111
112
  </EmptyState>
113
+ {renderEmptyThread?.(chatId)}
112
114
  {sources.length > 0 && (
113
115
  <div className="flex max-w-full flex-col items-center gap-1">
114
116
  <SectionLabel>{t('timeline.empty.canRead')}</SectionLabel>
@@ -4,6 +4,7 @@ import { ensureSyntaxTree, syntaxTree } from '@codemirror/language';
4
4
  import type { EditorState } from '@codemirror/state';
5
5
  import type { ChatSkill } from '@adecore/agent-contracts';
6
6
  import { useChatHost } from '../../../host';
7
+ import { useHostExpandingCommands } from '../../../host-hooks';
7
8
  import { useChatScope } from '../../../scope';
8
9
  import { referenceSuggestions, referenceTokens, type Referable, type Referables } from '../../chat-references';
9
10
  import type { ChatDraft } from '../../drafts';
@@ -34,6 +35,7 @@ const MENTION_RESULTS = 8;
34
35
  const REFERENCE_RESULTS = 20;
35
36
 
36
37
  /* The text of a prompt and what the person picked in it with `@`, `$` and `#`. */
38
+
37
39
  export type PromptDraft = Pick<ChatDraft, 'text' | 'mentions' | 'skills' | 'chats' | 'references' | 'referenceNames'>;
38
40
 
39
41
  export interface PromptDraftBox<D extends PromptDraft> {
@@ -47,6 +49,7 @@ export interface ComposerCommand {
47
49
  name: string;
48
50
  hint: string;
49
51
  local: boolean;
52
+ expand?(args: string): Promise<string>;
50
53
  skill: boolean;
51
54
  }
52
55
 
@@ -146,6 +149,12 @@ export function usePromptMenus<D extends PromptDraft>({
146
149
 
147
150
  const commandQuery = text.startsWith('/') && !text.includes('\n') ? text.slice(1).trim().toLowerCase() : null;
148
151
 
152
+ const expanding = useHostExpandingCommands();
153
+ const expandInto = (command: ComposerCommand): void => {
154
+ const args = text.replace(/^\/\S*\s*/, '');
155
+
156
+ void command.expand?.(args).then((expanded) => setText(expanded));
157
+ };
149
158
  const commandsOf = (query: string): ComposerCommand[] => {
150
159
  const known = new Set(skills.map((skill) => skill.name));
151
160
  const own = localCommands.map((name) => ({ name, hint: t(`composer.commands.${name}`), local: true, skill: false }));
@@ -161,7 +170,9 @@ export function usePromptMenus<D extends PromptDraft>({
161
170
  skill: known.has(name)
162
171
  }));
163
172
 
164
- return [...own, ...goal, ...cli].filter((command) => command.name.startsWith(query)).slice(0, 8);
173
+ const hosted = expanding.map((command) => ({ name: command.name, hint: command.hint, local: false, skill: false, expand: command.expand }));
174
+
175
+ return [...hosted, ...own, ...goal, ...cli].filter((command) => command.name.startsWith(query)).slice(0, 8);
165
176
  };
166
177
 
167
178
  const commands = commandQuery === null ? [] : commandsOf(commandQuery);
@@ -252,6 +263,14 @@ export function usePromptMenus<D extends PromptDraft>({
252
263
  }
253
264
 
254
265
  const result = insertReference(text, referenceQuery, item.name);
266
+
267
+ if (item.read !== undefined) {
268
+ setReferenceQuery(null);
269
+ void item.read().then((content) => setText(result.text.replace(`#${item.name}`, content)));
270
+
271
+ return;
272
+ }
273
+
255
274
  const chat = item.kind === 'chat';
256
275
 
257
276
  const add = (ids: string[]): string[] => (ids.includes(item.id) ? ids : [...ids, item.id]);
@@ -291,6 +310,12 @@ export function usePromptMenus<D extends PromptDraft>({
291
310
  const pickCommand = (command: ComposerCommand, index: number): void => {
292
311
  setMenuIndex(index);
293
312
 
313
+ if (command.expand !== undefined) {
314
+ expandInto(command);
315
+
316
+ return;
317
+ }
318
+
294
319
  if (command.skill) {
295
320
  chooseSkill(command.name);
296
321
 
@@ -303,6 +328,12 @@ export function usePromptMenus<D extends PromptDraft>({
303
328
 
304
329
  /* Tab on a command: a skill becomes its chip, any other is written out with a space for its arguments. */
305
330
  const completeCommand = (command: ComposerCommand): void => {
331
+ if (command.expand !== undefined) {
332
+ expandInto(command);
333
+
334
+ return;
335
+ }
336
+
306
337
  if (command.skill) {
307
338
  chooseSkill(command.name);
308
339
 
@@ -384,6 +384,17 @@ function ToolOutput({ tool, chatId }: { tool: ChatToolItem; chatId: string | und
384
384
 
385
385
  /* An opened call without a card: what it was asked in the foreground, what it answered muted below. With `chatId` it can ask for an output the thread keeps only the beginning of. */
386
386
  export function ToolBody({ tool, chatId }: { tool: ChatToolItem; chatId?: string | undefined }) {
387
+ const { renderToolActions, renderToolResult } = useChatHost();
388
+
389
+ return (
390
+ <>
391
+ {renderToolActions?.(tool, chatId)}
392
+ {renderToolResult?.(tool, chatId) ?? <OwnToolBody tool={tool} chatId={chatId} />}
393
+ </>
394
+ );
395
+ }
396
+
397
+ function OwnToolBody({ tool, chatId }: { tool: ChatToolItem; chatId?: string | undefined }) {
387
398
  const patches = unifiedChanges(tool);
388
399
  const changes = patches.length > 0 ? [] : fileChanges(tool.name, tool.input);
389
400
 
package/src/host-hooks.ts CHANGED
@@ -65,6 +65,16 @@ export function useHostLoginBlocked(...args: Parameters<ChatHost['useLoginBlocke
65
65
  return useChatHost().useLoginBlocked(...args);
66
66
  }
67
67
 
68
+ const NO_EXPANDING: ReturnType<NonNullable<ChatHost['useExpandingCommands']>> = [];
69
+ const noExpanding = (): ReturnType<NonNullable<ChatHost['useExpandingCommands']>> => NO_EXPANDING;
70
+
71
+ /* None where the host has no commands of its own. */
72
+ export function useHostExpandingCommands(): ReturnType<NonNullable<ChatHost['useExpandingCommands']>> {
73
+ const useExpanding = useChatHost().useExpandingCommands ?? noExpanding;
74
+
75
+ return useExpanding();
76
+ }
77
+
68
78
  const noPlatform = (): ProviderPlatform | null => null;
69
79
 
70
80
  /* Null where the host does not say, as it need not. */
package/src/host.ts CHANGED
@@ -374,6 +374,24 @@ export interface UiModelViewProps {
374
374
  * serve several scopes, so a function that is about one host of chats is told its scope id.
375
375
  */
376
376
  export interface ChatHost {
377
+ /* Commands of the host's own after `/`, which turn into the prompt instead of reaching the CLI. */
378
+ useExpandingCommands?(): readonly { name: string; hint: string; expand(args: string): Promise<string> }[];
379
+
380
+ /* Under an empty thread's own words. */
381
+ renderEmptyThread?(chatId: string): ReactNode;
382
+
383
+ /* Over a tool call's body. */
384
+ renderToolActions?(tool: { name: string; input: unknown; output: string | null; state: string }, chatId: string | undefined): ReactNode;
385
+
386
+ /* A tool call the host draws itself, under its line; null leaves it to the thread. */
387
+ renderToolResult?(tool: { name: string; input: unknown; output: string | null; state: string }, chatId: string | undefined): ReactNode;
388
+
389
+ /* Beside a message's own actions. */
390
+ renderMessageActions?(message: { chatId: string; id: string; kind: 'user' | 'assistant'; text: string }): ReactNode;
391
+
392
+ /* A fenced block the host draws itself, by its language; null leaves it to the code block. */
393
+ renderCodeFence?(language: string | undefined, code: string): ReactNode;
394
+
377
395
  intelligentUi?: {
378
396
  subscribe?(scopeId: string, chatId: string, changed: () => void): () => void;
379
397
  link?(scopeId: string, payload: ChatUiLinkPayload): Promise<ChatUiLinkReading>;